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(s,t){if(window.__gradio_space__==null)throw new d("Must be on Spaces to share.");let e,r,n;{let c;if(typeof s=="object"&&s.url)c=s.url;else if(typeof s=="string")c=s;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 o=new File([e],n,{type:r}),a=await fetch("https://huggingface.co/uploads",{method:"POST",body:o,headers:{"Content-Type":o.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(s){s.addEventListener("click",t);async function t(e){const r=e.composedPath(),[n]=r.filter(o=>o?.tagName==="BUTTON"&&o.classList.contains("copy_code_button"));if(n){let o=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)&&o(h)}}return{destroy(){s.removeEventListener("click",t)}}}async function _(s){let t=!1;if("clipboard"in navigator)await navigator.clipboard.writeText(s),t=!0;else{const e=document.createElement("textarea");e.value=s,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=s=>{const t=Math.floor(s/3600),e=Math.floor(s%3600/60),r=Math.round(s)%60,n=`${e<10?"0":""}${e}`,o=`${r<10?"0":""}${r}`;return t>0?`${t}:${n}:${o}`:`${e}:${o}`},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 o in t.shared_props)this.shared[o]=t.shared_props[o];for(const o in t.props)this.props[o]=t.props[o];if(e)for(const o in e)this.props[o]===void 0&&(this.props[o]=e[o]);if(this.i18n=this.props.i18n,this.load_component=this.shared.load_component,!y||t.props?.__GRADIO_BROWSER_TEST__){this.dispatcher=()=>{};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 o in t.shared_props)this.shared[o]=t.shared_props[o];for(const o in t.props)this.props[o]=t.props[o];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=s=>typeof s=="number"?s+"px":s;function v(s){if(!s)return!1;const t=s.scrollHeight>s.clientHeight,e=s.scrollTop>=s.scrollHeight-s.clientHeight-1;return t&&!e}export{T as G,d as S,m as a,b,k as c,f as d,x as f,v as s,w as u};
