import { s as snapshot } from './clone-Yk88IHKV.js';
import { J } from './2-EyCg4N-O.js';

const d="__i18n__",f=["label","info","placeholder","description","title","value"];class c extends Error{constructor(e){super(e),this.name="ShareError";}}async function b(s,e){if(window.__gradio_space__==null)throw new c("Must be on Spaces to share.");let r,t,o;{let p;if(typeof s=="object"&&s.url)p=s.url;else if(typeof s=="string")p=s;else throw new Error("Invalid data format for URL type");const h=await fetch(p);r=await h.blob(),t=h.headers.get("content-type")||"",o=h.headers.get("content-disposition")||"";}const n=new File([r],o,{type:t}),a=await fetch("https://huggingface.co/uploads",{method:"POST",body:n,headers:{"Content-Type":n.type,"X-Requested-With":"XMLHttpRequest"}});if(!a.ok){if(a.headers.get("content-type")?.includes("application/json")){const p=await a.json();throw new c(`Upload failed: ${p.error}`)}throw new c("Upload failed.")}return await a.text()}const w=s=>{const e=Math.floor(s/3600),r=Math.floor(s%3600/60),t=Math.round(s)%60,o=`${r<10?"0":""}${r}`,n=`${t<10?"0":""}${t}`;return e>0?`${e}:${o}:${n}`:`${r}:${n}`},u=["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","register_component","dispatcher"];function m(s){return typeof s=="string"&&s.includes(d)}function k(s,e){const r=s.indexOf(d);if(r===-1)return s;const t=r+d.length,o=s.indexOf("}",t)+1;if(o===0)return s;try{const n=JSON.parse(s.slice(t,o));if(n?.key){const a=e(n.key),i=a!==n.key?a:n.key;return s.slice(0,r)+i+s.slice(o)}}catch{}return s}class ${load_component;shared={};props={};i18n=e=>e;translatable_props={};dispatcher;last_update=null;shared_props=u;mounted=false;old_value;register_component;constructor(e,r){for(const t in e.shared_props)this.shared[t]=e.shared_props[t];for(const t in e.props)this.props[t]=e.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 f)this.shared[t]=this._translate_and_store("shared",t,e.shared_props[t]),this.props[t]=this._translate_and_store("props",t,e.props[t]);this.load_component=this.shared.load_component,this.register_component=this.shared.register_component||(()=>{}),this.dispatcher=this.shared.dispatcher||(()=>{}),this.register_component(e.shared_props.id,this.set_data.bind(this),this.get_data.bind(this)),Object.keys(this.translatable_props).length>0&&J.subscribe(()=>{for(const[t,o]of Object.entries(this.translatable_props)){const[n,a]=t.split("."),i=this.i18n(o);n==="shared"?this.shared[a]=i:this.props[a]=i;}});}_is_i18n_managed(e,r){const t=this.translatable_props[e];return t?r===t?true:(delete this.translatable_props[e],false):false}_translate_and_store(e,r,t){if(typeof t!="string")return t;const o=this.i18n(t);return o!==t&&(this.translatable_props[`${e}.${r}`]=t),o}dispatch(e,r){this.dispatcher(this.shared.id,e,r);}async get_data(){return snapshot(this.props)}update(e){this.set_data(e);}set_data(e){for(const r in e){const t=e[r],o=m(t)?this._translate_and_store(this.shared_props.includes(r)?"shared":"props",r,t):t;if(this.shared_props.includes(r)){const n=r;this.shared[n]=o;continue}this.props[r]=o;}}watch_for_change(){}}const x=s=>typeof s=="number"?s+"px":s;

export { $, b, c, d, k, u, w, x };
//# sourceMappingURL=utils.svelte-C798QV9b.js.map
