import { s as snapshot } from './clone-CubQhOZi.js';
import './async-DWBXLqlH.js';
import { g as getContext } from './context-BZS6UlnY.js';
import { Y } from './2-BbOIMXxe.js';

const d="__i18n__",u=["label","info","placeholder","description","title","value"],m="GRADIO_ROOT";class h extends Error{constructor(s){super(s),this.name="ShareError";}}async function O(e,s){if(window.__gradio_space__==null)throw new h("Must be on Spaces to share.");let r,o,n;{let i;if(typeof e=="object"&&e.url)i=e.url;else if(typeof e=="string")i=e;else throw new Error("Invalid data format for URL type");const p=await fetch(i);r=await p.blob(),o=p.headers.get("content-type")||"",n=p.headers.get("content-disposition")||"";}const t=new File([r],n,{type:o}),a=await fetch("https://huggingface.co/uploads",{method:"POST",body:t,headers:{"Content-Type":t.type,"X-Requested-With":"XMLHttpRequest"}});if(!a.ok){if(a.headers.get("content-type")?.includes("application/json")){const i=await a.json();throw new h(`Upload failed: ${i.error}`)}throw new h("Upload failed.")}return await a.text()}const R=e=>{const s=Math.floor(e/3600),r=Math.floor(e%3600/60),o=Math.round(e)%60,n=`${r<10?"0":""}${r}`,t=`${o<10?"0":""}${o}`;return s>0?`${s}:${n}:${t}`:`${r}:${t}`},y=typeof window<"u",g=["elem_id","elem_classes","visible","interactive","server_fns","server","id","target","theme_mode","version","root","autoscroll","max_file_size","formatter","client","load_component","scale","min_width","theme","padding","loading_status","label","show_label","validation_error","show_progress","api_prefix","container","attached_events"];function b(e){return typeof e=="string"&&e.includes(d)}function $(e,s){const r=e.indexOf(d);if(r===-1)return e;const o=r+d.length,n=e.indexOf("}",o)+1;if(n===0)return e;try{const t=JSON.parse(e.slice(o,n));if(t?.key){const a=s(t.key),c=a!==t.key?a:t.key;return e.slice(0,r)+c+e.slice(n)}}catch{}return e}class S{load_component;shared={};props={};i18n=s=>s;translatable_props={};dispatcher;last_update=null;shared_props=g;constructor(s,r){for(const t in s.shared_props)this.shared[t]=s.shared_props[t];for(const t in s.props)this.props[t]=s.props[t];if(r)for(const t in r)this.props[t]===void 0&&(this.props[t]=r[t]);this.i18n=this.props.i18n??(t=>t);for(const t of u)this.shared[t]=this._translate_and_store("shared",t,s.shared_props[t]),this.props[t]=this._translate_and_store("props",t,s.props[t]);if(this.load_component=this.shared.load_component,!y||s.props?.__GRADIO_BROWSER_TEST__){this.dispatcher=()=>{};return}const{register:o,dispatcher:n}=getContext(m);o(s.shared_props.id,this.set_data.bind(this),this.get_data.bind(this)),this.dispatcher=n,Object.keys(this.translatable_props).length>0&&Y.subscribe(()=>{for(const[t,a]of Object.entries(this.translatable_props)){const[c,i]=t.split("."),p=this.i18n(a);c==="shared"?this.shared[i]=p:this.props[i]=p;}});}_is_i18n_managed(s,r){const o=this.translatable_props[s];return o?r===o?true:(delete this.translatable_props[s],false):false}_translate_and_store(s,r,o){if(typeof o!="string")return o;const n=this.i18n(o);return n!==o&&(this.translatable_props[`${s}.${r}`]=o),n}dispatch(s,r){this.dispatcher(this.shared.id,s,r);}async get_data(){return snapshot(this.props)}update(s){this.set_data(s);}set_data(s){for(const r in s){const o=s[r],n=b(o)?this._translate_and_store(this.shared_props.includes(r)?"shared":"props",r,o):o;if(this.shared_props.includes(r)){const t=r;this.shared[t]=n;continue}this.props[r]=n;}}}const T=e=>typeof e=="number"?e+"px":e;

export { $, O, R, S, T, d, g, h, m };
//# sourceMappingURL=utils.svelte-BHoyPsmo.js.map
