import{e as qe}from"./index-C7PS0jJm.js";/* empty css */const{SvelteComponent:Ie,append:z,attr:T,detach:fe,element:U,flush:M,init:Ne,insert:de,noop:re,safe_not_equal:Me,set_data:j,set_style:Y,space:Z,text:q,toggle_class:se}=window.__gradio__svelte__internal,{onMount:je,createEventDispatcher:Je,onDestroy:Re}=window.__gradio__svelte__internal;function ae(t){let e,l,n,r,d=I(t[2])+"",o,_,u,s,a=t[2].orig_name+"",h;return{c(){e=U("div"),l=U("span"),n=U("div"),r=U("progress"),o=q(d),u=Z(),s=U("span"),h=q(a),Y(r,"visibility","hidden"),Y(r,"height","0"),Y(r,"width","0"),r.value=_=I(t[2]),T(r,"max","100"),T(r,"class","svelte-1vsfomn"),T(n,"class","progress-bar svelte-1vsfomn"),T(s,"class","file-name svelte-1vsfomn"),T(e,"class","file svelte-1vsfomn")},m(c,p){de(c,e,p),z(e,l),z(l,n),z(n,r),z(r,o),z(e,u),z(e,s),z(s,h)},p(c,p){p&4&&d!==(d=I(c[2])+"")&&j(o,d),p&4&&_!==(_=I(c[2]))&&(r.value=_),p&4&&a!==(a=c[2].orig_name+"")&&j(h,a)},d(c){c&&fe(e)}}}function Be(t){let e,l,n,r=t[0].length+"",d,o,_=t[0].length>1?"files":"file",u,s,a,h=t[2]&&ae(t);return{c(){e=U("div"),l=U("span"),n=q("Uploading "),d=q(r),o=Z(),u=q(_),s=q("..."),a=Z(),h&&h.c(),T(l,"class","uploading svelte-1vsfomn"),T(e,"class","wrap svelte-1vsfomn"),se(e,"progress",t[1])},m(c,p){de(c,e,p),z(e,l),z(l,n),z(l,d),z(l,o),z(l,u),z(l,s),z(e,a),h&&h.m(e,null)},p(c,[p]){p&1&&r!==(r=c[0].length+"")&&j(d,r),p&1&&_!==(_=c[0].length>1?"files":"file")&&j(u,_),c[2]?h?h.p(c,p):(h=ae(c),h.c(),h.m(e,null)):h&&(h.d(1),h=null),p&2&&se(e,"progress",c[1])},i:re,o:re,d(c){c&&fe(e),h&&h.d()}}}function I(t){return t.progress*100/(t.size||0)||0}function Ge(t){let e=0;return t.forEach(l=>{e+=I(l)}),document.documentElement.style.setProperty("--upload-progress-width",(e/t.length).toFixed(2)+"%"),e/t.length}function He(t,e,l){let{upload_id:n}=e,{root:r}=e,{files:d}=e,{stream_handler:o}=e,_,u=!1,s,a,h=d.map(g=>({...g,progress:0}));const c=Je();function p(g,f){l(0,h=h.map(m=>(m.orig_name===g&&(m.progress+=f),m)))}return je(async()=>{if(_=await o(new URL(`${r}/gradio_api/upload_progress?upload_id=${n}`)),_==null)throw new Error("Event source is not defined");_.onmessage=async function(g){const f=JSON.parse(g.data);u||l(1,u=!0),f.msg==="done"?(_?.close(),c("done")):(l(7,s=f),p(f.orig_name,f.chunk_size))}}),Re(()=>{(_!=null||_!=null)&&_.close()}),t.$$set=g=>{"upload_id"in g&&l(3,n=g.upload_id),"root"in g&&l(4,r=g.root),"files"in g&&l(5,d=g.files),"stream_handler"in g&&l(6,o=g.stream_handler)},t.$$.update=()=>{t.$$.dirty&1&&Ge(h),t.$$.dirty&129&&l(2,a=s||h[0])},[h,u,a,n,r,d,o,s]}class Ke extends Ie{constructor(e){super(),Ne(this,e,He,Be,Me,{upload_id:3,root:4,files:5,stream_handler:6})}get upload_id(){return this.$$.ctx[3]}set upload_id(e){this.$$set({upload_id:e}),M()}get root(){return this.$$.ctx[4]}set root(e){this.$$set({root:e}),M()}get files(){return this.$$.ctx[5]}set files(e){this.$$set({files:e}),M()}get stream_handler(){return this.$$.ctx[6]}set stream_handler(e){this.$$set({stream_handler:e}),M()}}const{SvelteComponent:Qe,append:oe,attr:y,binding_callbacks:Ve,bubble:E,check_outros:_e,create_component:Xe,create_slot:he,destroy_component:Ye,detach:R,element:x,empty:ge,flush:k,get_all_dirty_from_scope:ce,get_slot_changes:me,group_outros:be,init:Ze,insert:B,listen:W,mount_component:xe,prevent_default:D,run_all:$e,safe_not_equal:et,set_style:J,space:tt,stop_propagation:S,toggle_class:w,transition_in:P,transition_out:L,update_slot_base:pe}=window.__gradio__svelte__internal,{createEventDispatcher:lt,tick:it,getContext:_t}=window.__gradio__svelte__internal;function nt(t){let e,l,n,r,d,o,_,u,s,a,h,c;const p=t[30].default,g=he(p,t,t[29],null);return{c(){e=x("button"),g&&g.c(),l=tt(),n=x("input"),y(n,"aria-label","File upload"),y(n,"data-testid","file-upload"),y(n,"type","file"),y(n,"accept",r=t[19]||void 0),n.multiple=d=t[6]==="multiple"||void 0,y(n,"webkitdirectory",o=t[6]==="directory"||void 0),y(n,"mozdirectory",_=t[6]==="directory"||void 0),y(n,"class","svelte-1b742ao"),y(e,"tabindex",u=t[9]?-1:0),y(e,"aria-label",s=t[14]||"Click to upload or drop files"),y(e,"aria-dropeffect","copy"),y(e,"class","svelte-1b742ao"),w(e,"hidden",t[9]),w(e,"center",t[4]),w(e,"boundedheight",t[3]),w(e,"flex",t[5]),w(e,"disable_click",t[7]),w(e,"icon-mode",t[12]),J(e,"height",t[12]?"":t[13]?typeof t[13]=="number"?t[13]+"px":t[13]:"100%")},m(f,m){B(f,e,m),g&&g.m(e,null),oe(e,l),oe(e,n),t[38](n),a=!0,h||(c=[W(n,"change",t[21]),W(e,"drag",S(D(t[31]))),W(e,"dragstart",S(D(t[32]))),W(e,"dragend",S(D(t[33]))),W(e,"dragover",S(D(t[34]))),W(e,"dragenter",S(D(t[35]))),W(e,"dragleave",S(D(t[36]))),W(e,"drop",S(D(t[37]))),W(e,"click",t[16]),W(e,"drop",t[22]),W(e,"dragenter",t[20]),W(e,"dragleave",t[20])],h=!0)},p(f,m){g&&g.p&&(!a||m[0]&536870912)&&pe(g,p,f,f[29],a?me(p,f[29],m,null):ce(f[29]),null),(!a||m[0]&524288&&r!==(r=f[19]||void 0))&&y(n,"accept",r),(!a||m[0]&64&&d!==(d=f[6]==="multiple"||void 0))&&(n.multiple=d),(!a||m[0]&64&&o!==(o=f[6]==="directory"||void 0))&&y(n,"webkitdirectory",o),(!a||m[0]&64&&_!==(_=f[6]==="directory"||void 0))&&y(n,"mozdirectory",_),(!a||m[0]&512&&u!==(u=f[9]?-1:0))&&y(e,"tabindex",u),(!a||m[0]&16384&&s!==(s=f[14]||"Click to upload or drop files"))&&y(e,"aria-label",s),(!a||m[0]&512)&&w(e,"hidden",f[9]),(!a||m[0]&16)&&w(e,"center",f[4]),(!a||m[0]&8)&&w(e,"boundedheight",f[3]),(!a||m[0]&32)&&w(e,"flex",f[5]),(!a||m[0]&128)&&w(e,"disable_click",f[7]),(!a||m[0]&4096)&&w(e,"icon-mode",f[12]),m[0]&12288&&J(e,"height",f[12]?"":f[13]?typeof f[13]=="number"?f[13]+"px":f[13]:"100%")},i(f){a||(P(g,f),a=!0)},o(f){L(g,f),a=!1},d(f){f&&R(e),g&&g.d(f),t[38](null),h=!1,$e(c)}}}function rt(t){let e,l,n=!t[9]&&ue(t);return{c(){n&&n.c(),e=ge()},m(r,d){n&&n.m(r,d),B(r,e,d),l=!0},p(r,d){r[9]?n&&(be(),L(n,1,1,()=>{n=null}),_e()):n?(n.p(r,d),d[0]&512&&P(n,1)):(n=ue(r),n.c(),P(n,1),n.m(e.parentNode,e))},i(r){l||(P(n),l=!0)},o(r){L(n),l=!1},d(r){r&&R(e),n&&n.d(r)}}}function st(t){let e,l,n,r,d,o;const _=t[30].default,u=he(_,t,t[29],null);return{c(){e=x("button"),u&&u.c(),y(e,"tabindex",l=t[9]?-1:0),y(e,"aria-label",n=t[14]||"Paste from clipboard"),y(e,"class","svelte-1b742ao"),w(e,"hidden",t[9]),w(e,"center",t[4]),w(e,"boundedheight",t[3]),w(e,"flex",t[5]),w(e,"icon-mode",t[12]),J(e,"height",t[12]?"":t[13]?typeof t[13]=="number"?t[13]+"px":t[13]:"100%")},m(s,a){B(s,e,a),u&&u.m(e,null),r=!0,d||(o=W(e,"click",t[15]),d=!0)},p(s,a){u&&u.p&&(!r||a[0]&536870912)&&pe(u,_,s,s[29],r?me(_,s[29],a,null):ce(s[29]),null),(!r||a[0]&512&&l!==(l=s[9]?-1:0))&&y(e,"tabindex",l),(!r||a[0]&16384&&n!==(n=s[14]||"Paste from clipboard"))&&y(e,"aria-label",n),(!r||a[0]&512)&&w(e,"hidden",s[9]),(!r||a[0]&16)&&w(e,"center",s[4]),(!r||a[0]&8)&&w(e,"boundedheight",s[3]),(!r||a[0]&32)&&w(e,"flex",s[5]),(!r||a[0]&4096)&&w(e,"icon-mode",s[12]),a[0]&12288&&J(e,"height",s[12]?"":s[13]?typeof s[13]=="number"?s[13]+"px":s[13]:"100%")},i(s){r||(P(u,s),r=!0)},o(s){L(u,s),r=!1},d(s){s&&R(e),u&&u.d(s),d=!1,o()}}}function ue(t){let e,l;return e=new Ke({props:{root:t[8],upload_id:t[17],files:t[18],stream_handler:t[11]}}),{c(){Xe(e.$$.fragment)},m(n,r){xe(e,n,r),l=!0},p(n,r){const d={};r[0]&256&&(d.root=n[8]),r[0]&131072&&(d.upload_id=n[17]),r[0]&262144&&(d.files=n[18]),r[0]&2048&&(d.stream_handler=n[11]),e.$set(d)},i(n){l||(P(e.$$.fragment,n),l=!0)},o(n){L(e.$$.fragment,n),l=!1},d(n){Ye(e,n)}}}function at(t){let e,l,n,r;const d=[st,rt,nt],o=[];function _(u,s){return u[0]==="clipboard"?0:u[1]&&u[10]?1:2}return e=_(t),l=o[e]=d[e](t),{c(){l.c(),n=ge()},m(u,s){o[e].m(u,s),B(u,n,s),r=!0},p(u,s){let a=e;e=_(u),e===a?o[e].p(u,s):(be(),L(o[a],1,1,()=>{o[a]=null}),_e(),l=o[e],l?l.p(u,s):(l=o[e]=d[e](u),l.c()),P(l,1),l.m(n.parentNode,n))},i(u){r||(P(l),r=!0)},o(u){L(l),r=!1},d(u){u&&R(n),o[e].d(u)}}}function ot(t,e,l){if(!t||t==="*"||t==="file/*"||Array.isArray(t)&&t.some(r=>r==="*"||r==="file/*"))return!0;let n;if(typeof t=="string")n=t.split(",").map(r=>r.trim());else if(Array.isArray(t))n=t;else return!1;return n.includes(e)||n.some(r=>{const[d]=r.split("/").map(o=>o.trim());return r.endsWith("/*")&&l.startsWith(d+"/")})}function ut(t,e,l){let n,{$$slots:r={},$$scope:d}=e,{filetype:o=null}=e,{dragging:_=!1}=e,{boundedheight:u=!0}=e,{center:s=!0}=e,{flex:a=!0}=e,{file_count:h="single"}=e,{disable_click:c=!1}=e,{root:p}=e,{hidden:g=!1}=e,{format:f="file"}=e,{uploading:m=!1}=e,{hidden_upload:C=null}=e,{show_progress:$=!0}=e,{max_file_size:G=null}=e,{upload:H}=e,{stream_handler:ee}=e,{icon_upload:te=!1}=e,{height:le=void 0}=e,{aria_label:ie=void 0}=e,K,Q,O,ne=null;const we=()=>{if(typeof navigator<"u"){const i=navigator.userAgent.toLowerCase();return i.indexOf("iphone")>-1||i.indexOf("ipad")>-1}return!1},F=lt(),ye=["image","video","audio","text","file"],V=i=>n&&i.startsWith(".")?(ne=!0,i):n&&i.includes("file/*")?"*":i.startsWith(".")||i.endsWith("/*")?i:ye.includes(i)?i+"/*":"."+i;function ke(){l(23,_=!_)}function ve(){navigator.clipboard.read().then(async i=>{for(let b=0;bA.startsWith("image/"));if(v){i[b].getType(v).then(async A=>{const X=new File([A],`clipboard.${v.replace("image/","")}`);await N([X])});break}}})}function Ae(){c||C&&(l(2,C.value="",C),C.click())}async function ze(i){await it(),l(17,K=Math.random().toString(36).substring(2,15)),l(1,m=!0);try{const b=await H(i,p,K,G??1/0);return F("load",h==="single"?b?.[0]:b),l(1,m=!1),b||[]}catch(b){return F("error",b.message),l(1,m=!1),[]}}async function N(i){if(!i.length)return;let b=i.map(v=>new File([v],v instanceof File?v.name:"file",{type:v.type}));return n&&ne&&(b=b.filter(v=>We(v)?!0:(F("error",`Invalid file type: ${v.name}. Only ${o} allowed.`),!1)),b.length===0)?[]:(l(18,Q=await qe(b)),await ze(Q))}function We(i){return o?(Array.isArray(o)?o:[o]).some(v=>{const A=V(v);if(A.startsWith("."))return i.name.toLowerCase().endsWith(A.toLowerCase());if(A==="*")return!0;if(A.endsWith("/*")){const[X]=A.split("/");return i.type.startsWith(X+"/")}return i.type===A}):!0}async function Ce(i){const b=i.target;if(b.files)if(f!="blob")await N(Array.from(b.files));else{if(h==="single"){F("load",b.files[0]);return}F("load",b.files)}}async function Fe(i){if(l(23,_=!1),!i.dataTransfer?.files)return;const b=Array.from(i.dataTransfer.files).filter(v=>{const A="."+v.name.split(".").pop();return A&&ot(O,A,v.type)||(A&&Array.isArray(o)?o.includes(A):A===o)?!0:(F("error",`Invalid file type only ${o} allowed.`),!1)});if(f!="blob")await N(b);else{if(h==="single"){F("load",b[0]);return}F("load",b)}}function Pe(i){E.call(this,t,i)}function Ee(i){E.call(this,t,i)}function De(i){E.call(this,t,i)}function Se(i){E.call(this,t,i)}function Te(i){E.call(this,t,i)}function Ue(i){E.call(this,t,i)}function Le(i){E.call(this,t,i)}function Oe(i){Ve[i?"unshift":"push"](()=>{C=i,l(2,C)})}return t.$$set=i=>{"filetype"in i&&l(0,o=i.filetype),"dragging"in i&&l(23,_=i.dragging),"boundedheight"in i&&l(3,u=i.boundedheight),"center"in i&&l(4,s=i.center),"flex"in i&&l(5,a=i.flex),"file_count"in i&&l(6,h=i.file_count),"disable_click"in i&&l(7,c=i.disable_click),"root"in i&&l(8,p=i.root),"hidden"in i&&l(9,g=i.hidden),"format"in i&&l(24,f=i.format),"uploading"in i&&l(1,m=i.uploading),"hidden_upload"in i&&l(2,C=i.hidden_upload),"show_progress"in i&&l(10,$=i.show_progress),"max_file_size"in i&&l(25,G=i.max_file_size),"upload"in i&&l(26,H=i.upload),"stream_handler"in i&&l(11,ee=i.stream_handler),"icon_upload"in i&&l(12,te=i.icon_upload),"height"in i&&l(13,le=i.height),"aria_label"in i&&l(14,ie=i.aria_label),"$$scope"in i&&l(29,d=i.$$scope)},t.$$.update=()=>{t.$$.dirty[0]&268435457&&(o==null?l(19,O=null):typeof o=="string"?l(19,O=V(o)):n&&o.includes("file/*")?l(19,O="*"):(l(0,o=o.map(V)),l(19,O=o.join(", "))))},l(28,n=we()),[o,m,C,u,s,a,h,c,p,g,$,ee,te,le,ie,ve,Ae,K,Q,O,ke,Ce,Fe,_,f,G,H,N,n,d,r,Pe,Ee,De,Se,Te,Ue,Le,Oe]}class ht extends Qe{constructor(e){super(),Ze(this,e,ut,at,et,{filetype:0,dragging:23,boundedheight:3,center:4,flex:5,file_count:6,disable_click:7,root:8,hidden:9,format:24,uploading:1,hidden_upload:2,show_progress:10,max_file_size:25,upload:26,stream_handler:11,icon_upload:12,height:13,aria_label:14,paste_clipboard:15,open_file_upload:16,load_files:27},null,[-1,-1])}get filetype(){return this.$$.ctx[0]}set filetype(e){this.$$set({filetype:e}),k()}get dragging(){return this.$$.ctx[23]}set dragging(e){this.$$set({dragging:e}),k()}get boundedheight(){return this.$$.ctx[3]}set boundedheight(e){this.$$set({boundedheight:e}),k()}get center(){return this.$$.ctx[4]}set center(e){this.$$set({center:e}),k()}get flex(){return this.$$.ctx[5]}set flex(e){this.$$set({flex:e}),k()}get file_count(){return this.$$.ctx[6]}set file_count(e){this.$$set({file_count:e}),k()}get disable_click(){return this.$$.ctx[7]}set disable_click(e){this.$$set({disable_click:e}),k()}get root(){return this.$$.ctx[8]}set root(e){this.$$set({root:e}),k()}get hidden(){return this.$$.ctx[9]}set hidden(e){this.$$set({hidden:e}),k()}get format(){return this.$$.ctx[24]}set format(e){this.$$set({format:e}),k()}get uploading(){return this.$$.ctx[1]}set uploading(e){this.$$set({uploading:e}),k()}get hidden_upload(){return this.$$.ctx[2]}set hidden_upload(e){this.$$set({hidden_upload:e}),k()}get show_progress(){return this.$$.ctx[10]}set show_progress(e){this.$$set({show_progress:e}),k()}get max_file_size(){return this.$$.ctx[25]}set max_file_size(e){this.$$set({max_file_size:e}),k()}get upload(){return this.$$.ctx[26]}set upload(e){this.$$set({upload:e}),k()}get stream_handler(){return this.$$.ctx[11]}set stream_handler(e){this.$$set({stream_handler:e}),k()}get icon_upload(){return this.$$.ctx[12]}set icon_upload(e){this.$$set({icon_upload:e}),k()}get height(){return this.$$.ctx[13]}set height(e){this.$$set({height:e}),k()}get aria_label(){return this.$$.ctx[14]}set aria_label(e){this.$$set({aria_label:e}),k()}get paste_clipboard(){return this.$$.ctx[15]}get open_file_upload(){return this.$$.ctx[16]}get load_files(){return this.$$.ctx[27]}}export{ht as U}; //# sourceMappingURL=Upload-DeO6qHmq.js.map