import*as i from"./svelte/svelte_internal_client.js";import{getContext as l,untrack as u}from"./svelte/svelte_svelte.js";const f="GRADIO_ROOT";class d extends Error{constructor(t){super(t),this.name="ShareError"}}async function w(o,t){if(window.__gradio_space__==null)throw new d("Must be on Spaces to share.");let e,r,n;{let c;if(typeof o=="object"&&o.url)c=o.url;else if(typeof o=="string")c=o;else throw new Error("Invalid data format for URL type");const p=await fetch(c);e=await p.blob(),r=p.headers.get("content-type")||"",n=p.headers.get("content-disposition")||""}const s=new File([e],n,{type:r}),a=await fetch("https://huggingface.co/uploads",{method:"POST",body:s,headers:{"Content-Type":s.type,"X-Requested-With":"XMLHttpRequest"}});if(!a.ok){if(a.headers.get("content-type")?.includes("application/json")){const c=await a.json();throw new d(`Upload failed: ${c.error}`)}throw new d("Upload failed.")}return await a.text()}function b(o){o.addEventListener("click",t);async function t(e){const r=e.composedPath(),[n]=r.filter(s=>s?.tagName==="BUTTON"&&s.classList.contains("copy_code_button"));if(n){let s=function(p){p.style.opacity="1",setTimeout(()=>{p.style.opacity="0"},2e3)};e.stopImmediatePropagation();const a=n.parentElement.innerText.trim(),h=Array.from(n.children)[1];await _(a)&&s(h)}}return{destroy(){o.removeEventListener("click",t)}}}async function _(o){let t=!1;if("clipboard"in navigator)await navigator.clipboard.writeText(o),t=!0;else{const e=document.createElement("textarea");e.value=o,e.style.position="absolute",e.style.left="-999999px",document.body.prepend(e),e.select();try{document.execCommand("copy"),t=!0}catch(r){console.error(r),t=!1}finally{e.remove()}}return t}const x=o=>{const t=Math.floor(o/3600),e=Math.floor(o%3600/60),r=Math.round(o)%60,n=`${e<10?"0":""}${e}`,s=`${r<10?"0":""}${r}`;return t>0?`${t}:${n}:${s}`:`${e}:${s}`},y=typeof window<"u",m=["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"];class T{load_component;#t=i.state(i.proxy({}));get shared(){return i.get(this.#t)}set shared(t){i.set(this.#t,t,!0)}#e=i.state(i.proxy({}));get props(){return i.get(this.#e)}set props(t){i.set(this.#e,t,!0)}#s=i.state(i.proxy({}));get i18n(){return i.get(this.#s)}set i18n(t){i.set(this.#s,t,!0)}dispatcher;last_update=null;shared_props=m;constructor(t,e){for(const s in t.shared_props)this.shared[s]=t.shared_props[s];for(const s in t.props)this.props[s]=t.props[s];if(e)for(const s in e)this.props[s]===void 0&&(this.props[s]=e[s]);if(this.i18n=this.props.i18n,this.load_component=this.shared.load_component,!y||t.props?.__GRADIO_BROWSER_TEST__)return;const{register:r,dispatcher:n}=l(f);r(t.shared_props.id,this.set_data.bind(this),this.get_data.bind(this)),this.dispatcher=n,i.user_effect(()=>{for(const s in t.shared_props)this.shared[s]=t.shared_props[s];for(const s in t.props)this.props[s]=t.props[s];r(t.shared_props.id,this.set_data.bind(this),this.get_data.bind(this)),u(()=>{this.shared.id=t.shared_props.id})})}dispatch(t,e){this.dispatcher(this.shared.id,t,e)}async get_data(){return i.snapshot(this.props)}update(t){this.set_data(t)}set_data(t){for(const e in t)if(this.shared_props.includes(e)){const r=e;this.shared[r]=t[r];continue}else this.props[e]=t[e]}}const k=o=>typeof o=="number"?o+"px":o;export{T as G,d as S,m as a,k as b,b as c,f as d,x as f,w as u};
