arpeggi-framer-components 0.0.21 → 0.0.23

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.umd.js CHANGED
@@ -66,5 +66,5 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
66
66
  *
67
67
  * This source code is licensed under the MIT license found in the
68
68
  * LICENSE file in the root directory of this source tree.
69
- */var so;function hl(){return so||(so=1,process.env.NODE_ENV!=="production"&&function(){typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error);var e=w,t=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function i(_){{for(var k=arguments.length,b=new Array(k>1?k-1:0),j=1;j<k;j++)b[j-1]=arguments[j];n("error",_,b)}}function n(_,k,b){{var j=t.ReactDebugCurrentFrame,q=j.getStackAddendum();q!==""&&(k+="%s",b=b.concat([q]));var F=b.map(function(Y){return String(Y)});F.unshift("Warning: "+k),Function.prototype.apply.call(console[_],console,F)}}function r(_,k){return _===k&&(_!==0||1/_===1/k)||_!==_&&k!==k}var o=typeof Object.is=="function"?Object.is:r,a=e.useState,s=e.useEffect,c=e.useLayoutEffect,p=e.useDebugValue,l=!1,u=!1;function f(_,k,b){l||e.startTransition!==void 0&&(l=!0,i("You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."));var j=k();if(!u){var q=k();o(j,q)||(i("The result of getSnapshot should be cached to avoid an infinite loop"),u=!0)}var F=a({inst:{value:j,getSnapshot:k}}),Y=F[0].inst,H=F[1];return c(function(){Y.value=j,Y.getSnapshot=k,m(Y)&&H({inst:Y})},[_,j,k]),s(function(){m(Y)&&H({inst:Y});var oe=function(){m(Y)&&H({inst:Y})};return _(oe)},[_]),p(j),j}function m(_){var k=_.getSnapshot,b=_.value;try{var j=k();return!o(b,j)}catch{return!0}}function v(_,k,b){return k()}var g=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",E=!g,x=E?v:f,O=e.useSyncExternalStore!==void 0?e.useSyncExternalStore:x;ti.useSyncExternalStore=O,typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error)}()),ti}var co;function yl(){return co||(co=1,process.env.NODE_ENV==="production"?dn.exports=gl():dn.exports=hl()),dn.exports}var lo=yl();const Ze=()=>{},Ae=Ze(),ni=Object,N=e=>e===Ae,ze=e=>typeof e=="function",Le=(e,t)=>({...e,...t}),bl=e=>ze(e.then),fn=new WeakMap;let wl=0;const It=e=>{const t=typeof e,i=e&&e.constructor,n=i==Date;let r,o;if(ni(e)===e&&!n&&i!=RegExp){if(r=fn.get(e),r)return r;if(r=++wl+"~",fn.set(e,r),i==Array){for(r="@",o=0;o<e.length;o++)r+=It(e[o])+",";fn.set(e,r)}if(i==ni){r="#";const a=ni.keys(e).sort();for(;!N(o=a.pop());)N(e[o])||(r+=o+":"+It(e[o])+",");fn.set(e,r)}}else r=n?e.toJSON():t=="symbol"?e.toString():t=="string"?JSON.stringify(e):""+e;return r},Ve=new WeakMap,ii={},mn={},ri="undefined",xn=typeof window!=ri,oi=typeof document!=ri,El=()=>xn&&typeof window.requestAnimationFrame!=ri,ai=(e,t)=>{const i=Ve.get(e);return[()=>!N(t)&&e.get(t)||ii,n=>{if(!N(t)){const r=e.get(t);t in mn||(mn[t]=r),i[5](t,Le(r,n),r||ii)}},i[6],()=>!N(t)&&t in mn?mn[t]:!N(t)&&e.get(t)||ii]};let si=!0;const Sl=()=>si,[ci,li]=xn&&window.addEventListener?[window.addEventListener.bind(window),window.removeEventListener.bind(window)]:[Ze,Ze],Rl=()=>{const e=oi&&document.visibilityState;return N(e)||e!=="hidden"},Tl=e=>(oi&&document.addEventListener("visibilitychange",e),ci("focus",e),()=>{oi&&document.removeEventListener("visibilitychange",e),li("focus",e)}),kl=e=>{const t=()=>{si=!0,e()},i=()=>{si=!1};return ci("online",t),ci("offline",i),()=>{li("online",t),li("offline",i)}},Ol={isOnline:Sl,isVisible:Rl},Cl={initFocus:Tl,initReconnect:kl},Bt=!w.useId,lt=!xn||"Deno"in window,po=e=>El()?window.requestAnimationFrame(e):setTimeout(e,1),Qe=lt?w.useEffect:w.useLayoutEffect,pi=typeof navigator<"u"&&navigator.connection,uo=!lt&&pi&&(["slow-2g","2g"].includes(pi.effectiveType)||pi.saveData),zt=e=>{if(ze(e))try{e=e()}catch{e=""}const t=e;return e=typeof e=="string"?e:(Array.isArray(e)?e.length:e)?It(e):"",[e,t]};let _l=0;const wt=()=>++_l,fo=0,mo=1,xo=2;var He={__proto__:null,ERROR_REVALIDATE_EVENT:3,FOCUS_EVENT:fo,MUTATE_EVENT:xo,RECONNECT_EVENT:mo};async function ui(...e){const[t,i,n,r]=e,o=Le({populateCache:!0,throwOnError:!0},typeof r=="boolean"?{revalidate:r}:r||{});let a=o.populateCache;const s=o.rollbackOnError;let c=o.optimisticData;const p=f=>typeof s=="function"?s(f):s!==!1,l=o.throwOnError;if(ze(i)){const f=i,m=[],v=t.keys();for(const g of v)!/^\$(inf|sub)\$/.test(g)&&f(t.get(g)._k)&&m.push(g);return Promise.all(m.map(u))}return u(i);async function u(f){const[m]=zt(f);if(!m)return;const[v,g]=ai(t,m),[E,x,O,_]=Ve.get(t),k=()=>{const ne=E[m];return(ze(o.revalidate)?o.revalidate(v().data,f):o.revalidate!==!1)&&(delete O[m],delete _[m],ne&&ne[0])?ne[0](xo).then(()=>v().data):v().data};if(e.length<3)return k();let b=n,j;const q=wt();x[m]=[q,0];const F=!N(c),Y=v(),H=Y.data,oe=Y._c,he=N(oe)?H:oe;if(F&&(c=ze(c)?c(he,H):c,g({data:c,_c:he})),ze(b))try{b=b(he)}catch(ne){j=ne}if(b&&bl(b))if(b=await b.catch(ne=>{j=ne}),q!==x[m][0]){if(j)throw j;return b}else j&&F&&p(j)&&(a=!0,g({data:he,_c:Ae}));if(a&&!j)if(ze(a)){const ne=a(b,he);g({data:ne,error:Ae,_c:Ae})}else g({data:b,error:Ae,_c:Ae});if(x[m][1]=wt(),Promise.resolve(k()).then(()=>{g({_c:Ae})}),j){if(l)throw j;return}return b}}const vo=(e,t)=>{for(const i in e)e[i][0]&&e[i][0](t)},Al=(e,t)=>{if(!Ve.has(e)){const i=Le(Cl,t),n={},r=ui.bind(Ae,e);let o=Ze;const a={},s=(l,u)=>{const f=a[l]||[];return a[l]=f,f.push(u),()=>f.splice(f.indexOf(u),1)},c=(l,u,f)=>{e.set(l,u);const m=a[l];if(m)for(const v of m)v(u,f)},p=()=>{if(!Ve.has(e)&&(Ve.set(e,[n,{},{},{},r,c,s]),!lt)){const l=i.initFocus(setTimeout.bind(Ae,vo.bind(Ae,n,fo))),u=i.initReconnect(setTimeout.bind(Ae,vo.bind(Ae,n,mo)));o=()=>{l&&l(),u&&u(),Ve.delete(e)}}};return p(),[e,r,p,o]}return[e,Ve.get(e)[4]]},Dl=(e,t,i,n,r)=>{const o=i.errorRetryCount,a=r.retryCount,s=~~((Math.random()+.5)*(1<<(a<8?a:8)))*i.errorRetryInterval;!N(o)&&a>o||setTimeout(n,s,r)},jl=(e,t)=>It(e)==It(t),[go,Fl]=Al(new Map),Pl=Le({onLoadingSlow:Ze,onSuccess:Ze,onError:Ze,onErrorRetry:Dl,onDiscarded:Ze,revalidateOnFocus:!0,revalidateOnReconnect:!0,revalidateIfStale:!0,shouldRetryOnError:!0,errorRetryInterval:uo?1e4:5e3,focusThrottleInterval:5*1e3,dedupingInterval:2*1e3,loadingTimeout:uo?5e3:3e3,compare:jl,isPaused:()=>!1,cache:go,mutate:Fl,fallback:{}},Ol),Il=(e,t)=>{const i=Le(e,t);if(t){const{use:n,fallback:r}=e,{use:o,fallback:a}=t;n&&o&&(i.use=n.concat(o)),r&&a&&(i.fallback=Le(r,a))}return i},Bl=w.createContext({}),zl="$inf$",ho=xn&&window.__SWR_DEVTOOLS_USE__,Ll=ho?window.__SWR_DEVTOOLS_USE__:[],Ml=()=>{ho&&(window.__SWR_DEVTOOLS_REACT__=w)},yo=e=>ze(e[1])?[e[0],e[1],e[2]||{}]:[e[0],null,(e[1]===null?e[2]:e[1])||{}],bo=()=>Le(Pl,w.useContext(Bl)),$l=e=>(t,i,n)=>e(t,i&&((...o)=>{const[a]=zt(t),[,,,s]=Ve.get(go);if(a.startsWith(zl))return i(...o);const c=s[a];return N(c)?i(...o):(delete s[a],c)}),n),Nl=Ll.concat($l),wo=e=>function(...i){const n=bo(),[r,o,a]=yo(i),s=Il(n,a);let c=e;const{use:p}=s,l=(p||[]).concat(Nl);for(let u=l.length;u--;)c=l[u](c);return c(r,o||s.fetcher||null,s)},Eo=(e,t,i)=>{const n=t[e]||(t[e]=[]);return n.push(i),()=>{const r=n.indexOf(i);r>=0&&(n[r]=n[n.length-1],n.pop())}},ql=(e,t)=>(...i)=>{const[n,r,o]=yo(i),a=(o.use||[]).concat(t);return e(n,r,{...o,use:a})};Ml();const So=w.use||(e=>{if(e.status==="pending")throw e;if(e.status==="fulfilled")return e.value;throw e.status==="rejected"?e.reason:(e.status="pending",e.then(t=>{e.status="fulfilled",e.value=t},t=>{e.status="rejected",e.reason=t}),e)}),di={dedupe:!0},Ul=wo((e,t,i)=>{const{cache:n,compare:r,suspense:o,fallbackData:a,revalidateOnMount:s,revalidateIfStale:c,refreshInterval:p,refreshWhenHidden:l,refreshWhenOffline:u,keepPreviousData:f}=i,[m,v,g,E]=Ve.get(n),[x,O]=zt(e),_=w.useRef(!1),k=w.useRef(!1),b=w.useRef(x),j=w.useRef(t),q=w.useRef(i),F=()=>q.current,Y=()=>F().isVisible()&&F().isOnline(),[H,oe,he,ne]=ai(n,x),V=w.useRef({}).current,pe=N(a)?i.fallback[x]:a,Re=(y,P)=>{for(const X in V){const $=X;if($==="data"){if(!r(y[$],P[$])&&(!N(y[$])||!r(G,P[$])))return!1}else if(P[$]!==y[$])return!1}return!0},Te=w.useMemo(()=>{const y=!x||!t?!1:N(s)?F().isPaused()||o?!1:N(c)?!0:c:s,P=ee=>{const Ee=Le(ee);return delete Ee._k,y?{isValidating:!0,isLoading:!0,...Ee}:Ee},X=H(),$=ne(),de=P(X),ke=X===$?de:P($);let Q=de;return[()=>{const ee=P(H());return Re(ee,Q)?(Q.data=ee.data,Q.isLoading=ee.isLoading,Q.isValidating=ee.isValidating,Q.error=ee.error,Q):(Q=ee,ee)},()=>ke]},[n,x]),ue=lo.useSyncExternalStore(w.useCallback(y=>he(x,(P,X)=>{Re(X,P)||y()}),[n,x]),Te[0],Te[1]),we=!_.current,R=m[x]&&m[x].length>0,C=ue.data,B=N(C)?pe:C,U=ue.error,z=w.useRef(B),G=f?N(C)?z.current:C:B,L=R&&!N(U)?!1:we&&!N(s)?s:F().isPaused()?!1:o?N(B)?!1:c:N(B)||c,W=!!(x&&t&&we&&L),J=N(ue.isValidating)?W:ue.isValidating,te=N(ue.isLoading)?W:ue.isLoading,M=w.useCallback(async y=>{const P=j.current;if(!x||!P||k.current||F().isPaused())return!1;let X,$,de=!0;const ke=y||{},Q=!g[x]||!ke.dedupe,ee=()=>Bt?!k.current&&x===b.current&&_.current:x===b.current,Ee={isValidating:!1,isLoading:!1},Ye=()=>{oe(Ee)},qe=()=>{const S=g[x];S&&S[1]===$&&delete g[x]},Ke={isValidating:!0};N(H().data)&&(Ke.isLoading=!0);try{if(Q&&(oe(Ke),i.loadingTimeout&&N(H().data)&&setTimeout(()=>{de&&ee()&&F().onLoadingSlow(x,i)},i.loadingTimeout),g[x]=[P(O),wt()]),[X,$]=g[x],X=await X,Q&&setTimeout(qe,i.dedupingInterval),!g[x]||g[x][1]!==$)return Q&&ee()&&F().onDiscarded(x),!1;Ee.error=Ae;const S=v[x];if(!N(S)&&($<=S[0]||$<=S[1]||S[1]===0))return Ye(),Q&&ee()&&F().onDiscarded(x),!1;const A=H().data;Ee.data=r(A,X)?A:X,Q&&ee()&&F().onSuccess(X,x,i)}catch(S){qe();const A=F(),{shouldRetryOnError:ae}=A;A.isPaused()||(Ee.error=S,Q&&ee()&&(A.onError(S,x,A),(ae===!0||ze(ae)&&ae(S))&&(!F().revalidateOnFocus||!F().revalidateOnReconnect||Y())&&A.onErrorRetry(S,x,A,me=>{const Oe=m[x];Oe&&Oe[0]&&Oe[0](He.ERROR_REVALIDATE_EVENT,me)},{retryCount:(ke.retryCount||0)+1,dedupe:!0})))}return de=!1,Ye(),!0},[x,n]),ye=w.useCallback((...y)=>ui(n,b.current,...y),[]);if(Qe(()=>{j.current=t,q.current=i,N(C)||(z.current=C)}),Qe(()=>{if(!x)return;const y=M.bind(Ae,di);let P=0;const $=Eo(x,m,(de,ke={})=>{if(de==He.FOCUS_EVENT){const Q=Date.now();F().revalidateOnFocus&&Q>P&&Y()&&(P=Q+F().focusThrottleInterval,y())}else if(de==He.RECONNECT_EVENT)F().revalidateOnReconnect&&Y()&&y();else{if(de==He.MUTATE_EVENT)return M();if(de==He.ERROR_REVALIDATE_EVENT)return M(ke)}});return k.current=!1,b.current=x,_.current=!0,oe({_k:O}),L&&(N(B)||lt?y():po(y)),()=>{k.current=!0,$()}},[x]),Qe(()=>{let y;function P(){const $=ze(p)?p(H().data):p;$&&y!==-1&&(y=setTimeout(X,$))}function X(){!H().error&&(l||F().isVisible())&&(u||F().isOnline())?M(di).then(P):P()}return P(),()=>{y&&(clearTimeout(y),y=-1)}},[p,l,u,x]),w.useDebugValue(G),o&&N(B)&&x){if(!Bt&&lt)throw new Error("Fallback data is required when using suspense in SSR.");j.current=t,q.current=i,k.current=!1;const y=E[x];if(!N(y)){const P=ye(y);So(P)}if(N(U)){const P=M(di);N(G)||(P.status="fulfilled",P.value=!0),So(P)}else throw U}return{mutate:ye,get data(){return V.data=!0,G},get error(){return V.error=!0,U},get isValidating(){return V.isValidating=!0,J},get isLoading(){return V.isLoading=!0,te}}}),Ro=w.use||(e=>{if(e.status==="pending")throw e;if(e.status==="fulfilled")return e.value;throw e.status==="rejected"?e.reason:(e.status="pending",e.then(t=>{e.status="fulfilled",e.value=t},t=>{e.status="rejected",e.reason=t}),e)}),fi={dedupe:!0},Wl=wo((e,t,i)=>{const{cache:n,compare:r,suspense:o,fallbackData:a,revalidateOnMount:s,revalidateIfStale:c,refreshInterval:p,refreshWhenHidden:l,refreshWhenOffline:u,keepPreviousData:f}=i,[m,v,g,E]=Ve.get(n),[x,O]=zt(e),_=w.useRef(!1),k=w.useRef(!1),b=w.useRef(x),j=w.useRef(t),q=w.useRef(i),F=()=>q.current,Y=()=>F().isVisible()&&F().isOnline(),[H,oe,he,ne]=ai(n,x),V=w.useRef({}).current,pe=N(a)?i.fallback[x]:a,Re=(y,P)=>{for(const X in V){const $=X;if($==="data"){if(!r(y[$],P[$])&&(!N(y[$])||!r(G,P[$])))return!1}else if(P[$]!==y[$])return!1}return!0},Te=w.useMemo(()=>{const y=!x||!t?!1:N(s)?F().isPaused()||o?!1:N(c)?!0:c:s,P=ee=>{const Ee=Le(ee);return delete Ee._k,y?{isValidating:!0,isLoading:!0,...Ee}:Ee},X=H(),$=ne(),de=P(X),ke=X===$?de:P($);let Q=de;return[()=>{const ee=P(H());return Re(ee,Q)?(Q.data=ee.data,Q.isLoading=ee.isLoading,Q.isValidating=ee.isValidating,Q.error=ee.error,Q):(Q=ee,ee)},()=>ke]},[n,x]),ue=lo.useSyncExternalStore(w.useCallback(y=>he(x,(P,X)=>{Re(X,P)||y()}),[n,x]),Te[0],Te[1]),we=!_.current,R=m[x]&&m[x].length>0,C=ue.data,B=N(C)?pe:C,U=ue.error,z=w.useRef(B),G=f?N(C)?z.current:C:B,L=R&&!N(U)?!1:we&&!N(s)?s:F().isPaused()?!1:o?N(B)?!1:c:N(B)||c,W=!!(x&&t&&we&&L),J=N(ue.isValidating)?W:ue.isValidating,te=N(ue.isLoading)?W:ue.isLoading,M=w.useCallback(async y=>{const P=j.current;if(!x||!P||k.current||F().isPaused())return!1;let X,$,de=!0;const ke=y||{},Q=!g[x]||!ke.dedupe,ee=()=>Bt?!k.current&&x===b.current&&_.current:x===b.current,Ee={isValidating:!1,isLoading:!1},Ye=()=>{oe(Ee)},qe=()=>{const S=g[x];S&&S[1]===$&&delete g[x]},Ke={isValidating:!0};N(H().data)&&(Ke.isLoading=!0);try{if(Q&&(oe(Ke),i.loadingTimeout&&N(H().data)&&setTimeout(()=>{de&&ee()&&F().onLoadingSlow(x,i)},i.loadingTimeout),g[x]=[P(O),wt()]),[X,$]=g[x],X=await X,Q&&setTimeout(qe,i.dedupingInterval),!g[x]||g[x][1]!==$)return Q&&ee()&&F().onDiscarded(x),!1;Ee.error=Ae;const S=v[x];if(!N(S)&&($<=S[0]||$<=S[1]||S[1]===0))return Ye(),Q&&ee()&&F().onDiscarded(x),!1;const A=H().data;Ee.data=r(A,X)?A:X,Q&&ee()&&F().onSuccess(X,x,i)}catch(S){qe();const A=F(),{shouldRetryOnError:ae}=A;A.isPaused()||(Ee.error=S,Q&&ee()&&(A.onError(S,x,A),(ae===!0||ze(ae)&&ae(S))&&(!F().revalidateOnFocus||!F().revalidateOnReconnect||Y())&&A.onErrorRetry(S,x,A,me=>{const Oe=m[x];Oe&&Oe[0]&&Oe[0](He.ERROR_REVALIDATE_EVENT,me)},{retryCount:(ke.retryCount||0)+1,dedupe:!0})))}return de=!1,Ye(),!0},[x,n]),ye=w.useCallback((...y)=>ui(n,b.current,...y),[]);if(Qe(()=>{j.current=t,q.current=i,N(C)||(z.current=C)}),Qe(()=>{if(!x)return;const y=M.bind(Ae,fi);let P=0;const $=Eo(x,m,(de,ke={})=>{if(de==He.FOCUS_EVENT){const Q=Date.now();F().revalidateOnFocus&&Q>P&&Y()&&(P=Q+F().focusThrottleInterval,y())}else if(de==He.RECONNECT_EVENT)F().revalidateOnReconnect&&Y()&&y();else{if(de==He.MUTATE_EVENT)return M();if(de==He.ERROR_REVALIDATE_EVENT)return M(ke)}});return k.current=!1,b.current=x,_.current=!0,oe({_k:O}),L&&(N(B)||lt?y():po(y)),()=>{k.current=!0,$()}},[x]),Qe(()=>{let y;function P(){const $=ze(p)?p(H().data):p;$&&y!==-1&&(y=setTimeout(X,$))}function X(){!H().error&&(l||F().isVisible())&&(u||F().isOnline())?M(fi).then(P):P()}return P(),()=>{y&&(clearTimeout(y),y=-1)}},[p,l,u,x]),w.useDebugValue(G),o&&N(B)&&x){if(!Bt&&lt)throw new Error("Fallback data is required when using suspense in SSR.");j.current=t,q.current=i,k.current=!1;const y=E[x];if(!N(y)){const P=ye(y);Ro(P)}if(N(U)){const P=M(fi);N(G)||(P.status="fulfilled",P.value=!0),Ro(P)}else throw U}return{mutate:ye,get data(){return V.data=!0,G},get error(){return V.error=!0,U},get isValidating(){return V.isValidating=!0,J},get isLoading(){return V.isLoading=!0,te}}}),To=Bt?e=>{e()}:w.startTransition,Vl=e=>{const[,t]=w.useState({}),i=w.useRef(!1),n=w.useRef(e),r=w.useRef({data:!1,error:!1,isValidating:!1}),o=w.useCallback(a=>{let s=!1;const c=n.current;for(const p in a){const l=p;c[l]!==a[l]&&(c[l]=a[l],r.current[l]&&(s=!0))}s&&!i.current&&t({})},[]);return Qe(()=>(i.current=!1,()=>{i.current=!0})),[n,r.current,o]},Hl=ql(Wl,()=>(e,t,i={})=>{const{mutate:n}=bo(),r=w.useRef(e),o=w.useRef(t),a=w.useRef(i),s=w.useRef(0),[c,p,l]=Vl({data:Ae,error:Ae,isMutating:!1}),u=c.current,f=w.useCallback(async(v,g)=>{const[E,x]=zt(r.current);if(!o.current)throw new Error("Can’t trigger the mutation: missing fetcher.");if(!E)throw new Error("Can’t trigger the mutation: missing key.");const O=Le(Le({populateCache:!1,throwOnError:!0},a.current),g),_=wt();s.current=_,l({isMutating:!0});try{const k=await n(E,o.current(x,{arg:v}),Le(O,{throwOnError:!0}));return s.current<=_&&(To(()=>l({data:k,isMutating:!1,error:void 0})),O.onSuccess==null||O.onSuccess.call(O,k,E,O)),k}catch(k){if(s.current<=_&&(To(()=>l({error:k,isMutating:!1})),O.onError==null||O.onError.call(O,k,E,O),O.throwOnError))throw k}},[]),m=w.useCallback(()=>{s.current=wt(),l({data:Ae,error:Ae,isMutating:!1})},[]);return Qe(()=>{r.current=e,o.current=t,a.current=i}),{trigger:f,reset:m,get data(){return p.data=!0,u.data},get error(){return p.error=!0,u.error},get isMutating(){return p.isMutating=!0,u.isMutating}}}),Gl=e=>ve.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",stroke:"currentColor",...e,children:[ve.jsx("path",{opacity:"0.15",d:"M14 8C14 11.3137 11.3137 14 8 14C4.68629 14 2 11.3137 2 8C2 4.68629 4.68629 2 8 2C11.3137 2 14 4.68629 14 8Z"}),ve.jsx("path",{d:"M14 8C14 11.3137 11.3137 14 8 14C4.68629 14 2 11.3137 2 8C2 4.68629 4.68629 2 8 2",strokeLinecap:"round"})]}),Yl=ya({"0%":{transform:"rotate(0deg)"},"100%":{transform:"rotate(360deg)"}}),Kl=$e(Gl,{animation:`${Yl} 2s linear infinite`,variants:{size:{sm:{width:"16px",height:"16px",strokeWidth:"1px"},md:{width:"24px",height:"24px",strokeWidth:"1.5px"},lg:{width:"32px",height:"32px",strokeWidth:"2px"}}}}),Jl=e=>ve.jsx("svg",{width:"15",height:"15",viewBox:"0 0 15 15",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e,children:ve.jsx("path",{d:"M6.04995 2.74998C6.04995 2.44623 5.80371 2.19998 5.49995 2.19998C5.19619 2.19998 4.94995 2.44623 4.94995 2.74998V12.25C4.94995 12.5537 5.19619 12.8 5.49995 12.8C5.80371 12.8 6.04995 12.5537 6.04995 12.25V2.74998ZM10.05 2.74998C10.05 2.44623 9.80371 2.19998 9.49995 2.19998C9.19619 2.19998 8.94995 2.44623 8.94995 2.74998V12.25C8.94995 12.5537 9.19619 12.8 9.49995 12.8C9.80371 12.8 10.05 12.5537 10.05 12.25V2.74998Z",fill:"currentColor",fillRule:"evenodd",clipRule:"evenodd"})}),Xl=({...e})=>ve.jsx("svg",{width:"15",height:"15",viewBox:"0 0 24 24",xmlns:"http://www.w3.orkllg/2000/svg",fill:"currentColor",...e,children:ve.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M5.1869 3.71487C5.42703 3.57009 5.72543 3.56159 5.9734 3.69247L20.3734 11.2925C20.6358 11.431 20.8 11.7033 20.8 12C20.8 12.2967 20.6358 12.569 20.3734 12.7075L5.9734 20.3075C5.72543 20.4384 5.42703 20.4299 5.1869 20.2851C4.94679 20.1403 4.79999 19.8803 4.79999 19.6V4.39998C4.79999 4.11959 4.94679 3.85966 5.1869 3.71487Z",fill:"currentColor"})}),Zl=e=>{if(!e)return!1;const t=e.split("?")[1];if(!t)return!1;const n=new URLSearchParams(t).get("Expires");return n?new Date(n)<new Date:!1},ko=e=>e&&e.split("?")[0],Ql=(e,t)=>ko(e)===ko(t),ep=()=>{const[e,t]=w.useState("paused"),i=()=>{if(typeof window>"u")return null;const p=new Audio;return p.addEventListener("play",()=>t("playing")),p},n=w.useMemo(i,[]),r=w.useRef(n);return{audioRef:r,state:e,setAudio:p=>new Promise(l=>{const u=r==null?void 0:r.current;u&&(u.setAttribute("src",p),t("loading"),u.addEventListener("loadedmetadata",()=>{t("paused"),l()},{once:!0}))}),play:()=>{var p,l;(p=r.current)==null||p.play(),(l=r.current)==null||l.addEventListener("ended",()=>t("paused"),{once:!0})},pause:()=>{var p;(p=r.current)==null||p.pause(),t("paused")},stop:()=>{var l;r.current&&((l=r.current)==null||l.pause(),r.current.currentTime=0),t("paused")}}},mi=w.createContext(null),Oo=e=>{var a;const t=w.useContext(mi),i=Ql((a=t.audioRef.current)==null?void 0:a.src,e),n=t.state==="loading"&&i,r=t.state==="playing"&&i;return{...t,isMySrc:i,isLoading:n,isPlaying:r,play:async()=>{var c;const s=(c=t.audioRef.current)==null?void 0:c.src;(!i||Zl(s))&&await t.setAudio(e),t.play()}}},tp=()=>w.useContext(mi),Co=({children:e})=>{const t=ep();return ve.jsx(mi.Provider,{value:t,children:e})},_o=(e,t,i)=>{const n=Oo(e),r=w.useRef(!1),o=()=>{r.current||(r.current=!0),n.isPlaying?(n.pause(),i==null||i()):(n.play(),t==null||t())};return w.useEffect(()=>()=>{n.isPlaying&&n.pause()},[]),{player:n,playPause:o}},pt=({limit:e,isTrue:t,children:i})=>{const n=[];return t!==!0?null:(No.Children.map(i,r=>{const{isTrue:o}=(r==null?void 0:r.props)||{};o===!0&&(!e||n.length<e)&&n.push(r)}),ve.jsx(ve.Fragment,{children:n}))};pt.defaultProps={limit:1,isTrue:!0},pt.If=({children:e,isTrue:t})=>e;const Ao=({children:e})=>e;Ao.defaultProps={isTrue:!0},pt.Else=Ao;const np=e=>{const t=r=>typeof r=="object"&&!(r instanceof Date)&&!(r instanceof File)&&r!==null,i=(r,o,a)=>{for(const s in o){const c=o[s];t(c)?i(`${r}[${s}]`,c,a):c!==void 0&&a.append(`${r}[${s}]`,c===null?"":c)}},n=new FormData;for(const r in e){const o=e[r];o instanceof File?n.append(r,o,o.name):o!==void 0&&(t(o)?i(r,o,n):n.append(r,o===null?"":o))}return n},ip=$e("div",{"--progress":"-100%",height:"8px",width:"100%",background:"rgba(255, 255, 255, 0.1)",borderRadius:"12px",position:"relative",overflow:"hidden"}),rp=$e("div",{height:"100%",width:"100%",background:"#ffffff",transition:"transform 0.2s ease-in-out",transform:"translateX(--progress)",borderRadius:"12px"}),op=({progress:e})=>ve.jsx(ip,{style:{"--progress":`${-100+e}%`},children:ve.jsx(rp,{})});function vn(e,t,i){for(let n=0;n<e.length;++n)t[i+n]=e.charCodeAt(n)}function gn(e,t,i){e=Math.floor(e),t[i+0]=e&255,t[i+1]=e>>8&255}function ut(e,t,i){e=Math.floor(e),t[i+0]=e&255,t[i+1]=e>>8&255,t[i+2]=e>>16&255,t[i+3]=e>>24&255}function ap(e){const t=new ArrayBuffer(4);return new Float32Array(t)[0]=e,new Uint32Array(t)[0]|0}function sp(e,t,i,n){let r=0,o=0;const a=e.length,s=e.numberOfChannels;let c,p;for(r=0;r<a;++r)for(o=0;o<s;++o)if(c=e.getChannelData(o),n===16)p=c[r]*32768,p=Math.max(-32768,Math.min(p,32767)),gn(p,t,i),i+=2;else if(n===32)p=ap(c[r]),ut(p,t,i),i+=4;else{console.log("Invalid bit depth for PCM encoding.");return}}async function cp(e,t){let i=e instanceof Blob?e:new Blob(e);const n=URL.createObjectURL(i),o=await(await fetch(n)).arrayBuffer();return await new AudioContext(t).decodeAudioData(o)}async function lp(e,t=!1){const i=e.length,n=e.numberOfChannels,r=e.sampleRate,o=t?32:16,a=o/8,s=r*n*o/8,c=n*o/8,p=i*n*a,u=44+p,f=new Uint8Array(u),m=16,v=p,g=4+(8+m)+(8+v);return vn("RIFF",f,0),ut(g,f,4),vn("WAVE",f,8),vn("fmt ",f,12),ut(m,f,16),gn(t?3:1,f,20),gn(n,f,22),ut(r,f,24),ut(s,f,28),gn(c,f,32),ut(o,f,34),vn("data",f,36),ut(v,f,40),sp(e,f,44,o),new Blob([f],{type:"audio/wave"})}async function pp(e,t=!1,i){const n=await cp(e,i);return lp(n,t)}const up=128;class dp{constructor(){bn(this,"mediaRecorder",null);bn(this,"stream",null);bn(this,"__data",null)}async checkMicrophonePermission(){var n;return!!(await((n=navigator==null?void 0:navigator.mediaDevices)==null?void 0:n.enumerateDevices())).find(r=>r.kind==="audioinput"&&!!r.label)}async startRecording(){var t;if(((t=this.mediaRecorder)==null?void 0:t.state)==="recording")return!0;try{this.stream=await navigator.mediaDevices.getUserMedia({audio:!0,video:!1}),this.mediaRecorder=new MediaRecorder(this.stream,{bitsPerSecond:up*1e3}),this.mediaRecorder.ondataavailable=i=>this.__data=i.data}catch(i){return console.error(i),!1}return this.mediaRecorder.start(),!0}stopRecording(){return new Promise(t=>{var i;if(((i=this.mediaRecorder)==null?void 0:i.state)!=="recording"){t(!0);return}this.mediaRecorder.stop(),this.mediaRecorder.onstop=()=>{var n;(n=this.stream)==null||n.getTracks().forEach(r=>r.stop()),this.mediaRecorder=null,this.stream=null,t(!0)}})}async getWavBlob(){return this.__data?await pp(this.__data):null}}const hn=new dp,xi="Recording.wav",Do=1500,fp=e=>{const[t,i]=w.useState(!1),[n,r]=w.useState(!1),[o,a]=w.useState(!1);return w.useEffect(()=>{var p;const c=async()=>{hn.checkMicrophonePermission().then(i)};return c(),(p=navigator==null?void 0:navigator.mediaDevices)==null||p.addEventListener("devicechange",c),()=>{var l;return(l=navigator==null?void 0:navigator.mediaDevices)==null?void 0:l.removeEventListener("devicechange",c)}},[]),{hasMicAccess:t,isRecording:n,hasMinTimeElapsed:o,handleClick:async()=>{if(n){if(!o)return;r(!1),a(!1),await hn.stopRecording();const p=await hn.getWavBlob();if(!p){console.log("Failed to get audio blob",p);return}const l=new File([p],xi,{type:"audio/mpeg",lastModified:Date.now()});e.onFileUpdate(l);return}const c=await hn.startRecording();r(c),setTimeout(()=>{a(!0)},Do)}}},jo=_e.create({baseURL:"https://arpeggi.io/api/v2/"}),mp=async(e,{arg:t})=>(await jo.post("/ml-inference-jobs",np({soundFile:t.file,type:"audio",voiceModelId:t.voiceModelId,metadata:{splitInstrumental:!0,isRecordedAudio:t.file.name===xi}}),{params:{type:"audio"}})).data,xp=async e=>e===null?null:(await jo.get(e)).data,vp=e=>{const t=e>0;return Ul(t?`/ml-inference-jobs/${e}`:null,xp,{refreshInterval:1e3})},gp=()=>{const[e,t]=w.useState(null),[i,n]=w.useState(0),[r,o]=w.useState(0),{data:a,isLoading:s}=vp(i),{trigger:c,isMutating:p}=Hl("/ml-inference-jobs",mp);return{file:e,setFile:t,mlijId:i,setMlijId:n,voiceModelId:r,setVoiceModelId:o,data:a,isLoading:s,handleSelectVoice:async f=>{e&&(n(0),o(f),c({file:e,voiceModelId:f},{onSuccess:m=>{console.log("created mlij",m),n(m.id)}}))},reset:()=>{t(null),n(0),o(0)},isMutating:p}},Fo=w.createContext({}),yn=()=>w.useContext(Fo),hp=({children:e})=>{const t=gp();return ve.jsx(Co,{children:ve.jsx(Fo.Provider,{value:t,children:e})})},yp=$e("button",{background:"#ffffff",borderRadius:"12px",width:"64px",height:"64px",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",border:"none",outline:"none",transition:"background 0.2s ease-in-out, transform 0.2s ease-in-out",color:"#000000","& > svg":{width:"24px",height:"24px"},"&:hover":{background:"#ffffff99",transform:"scale(1.05)"},"&:active":{background:"#ffffffcc"},"&:disabled":{background:"#ffffff99",transform:"none",cursor:"not-allowed"}}),bp=()=>{var o;const{data:e,isMutating:t}=yn(),i=(o=e==null?void 0:e.lossyOutputFile)==null?void 0:o.url,{player:n,playPause:r}=_o(i);return ve.jsx(yp,{onClick:r,disabled:n.isLoading||!i,children:ve.jsxs(pt,{children:[ve.jsx(pt.If,{isTrue:n.isLoading||(e==null?void 0:e.jobStatus)==="running"||t,children:ve.jsx(Kl,{})}),ve.jsx(pt.If,{isTrue:n.isPlaying,children:ve.jsx(Jl,{})}),ve.jsx(pt.Else,{children:ve.jsx(Xl,{})})]})})},vi=30,wp=10,Ep=()=>{const{data:e}=yn(),[t,i]=w.useState(0);return w.useEffect(()=>{if(!e)return;const n=setInterval(()=>{const r=(e==null?void 0:e.audioDurationMs)/1e3||vi,o=new Date(e==null?void 0:e.createdAt).getTime(),s=(new Date().getTime()-o)/1e3,c=Math.max(s/(vi+wp+r)*100,100);i(c)},100);return()=>clearInterval(n)},[e]),ve.jsx(op,{progress:t})},Sp=1,Rp=100*1024*1024,Tp=1,kp=({children:e})=>{const{setFile:t}=yn(),i=n=>t(n[0]);return ve.jsx(wr,{files:[],onFileAccepted:i,maxFileCount:Sp,maxSizeBytes:Rp,minSizeBytes:Tp,maxDurationS:vi,children:e})};xe.AudioFilePickerRoot=wr,xe.ConvertStep=Gs,xe.FilePicker=kp,xe.GuestConvertProvider=hp,xe.InferenceProgress=Ep,xe.MIN_RECORDING_LENGTH_MS=Do,xe.PlayButton=bp,xe.PlayerProvider=Co,xe.RECORDED_AUDIO_NAME=xi,xe.useAudioFilePickerContext=$s,xe.useGuestConvertContext=yn,xe.usePlayback=_o,xe.usePlayer=Oo,xe.usePlayerControls=tp,xe.useRecorder=fp,Object.defineProperty(xe,Symbol.toStringTag,{value:"Module"})});
69
+ */var so;function hl(){return so||(so=1,process.env.NODE_ENV!=="production"&&function(){typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error);var e=w,t=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function i(_){{for(var k=arguments.length,b=new Array(k>1?k-1:0),j=1;j<k;j++)b[j-1]=arguments[j];n("error",_,b)}}function n(_,k,b){{var j=t.ReactDebugCurrentFrame,q=j.getStackAddendum();q!==""&&(k+="%s",b=b.concat([q]));var F=b.map(function(Y){return String(Y)});F.unshift("Warning: "+k),Function.prototype.apply.call(console[_],console,F)}}function r(_,k){return _===k&&(_!==0||1/_===1/k)||_!==_&&k!==k}var o=typeof Object.is=="function"?Object.is:r,a=e.useState,s=e.useEffect,c=e.useLayoutEffect,p=e.useDebugValue,l=!1,u=!1;function f(_,k,b){l||e.startTransition!==void 0&&(l=!0,i("You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."));var j=k();if(!u){var q=k();o(j,q)||(i("The result of getSnapshot should be cached to avoid an infinite loop"),u=!0)}var F=a({inst:{value:j,getSnapshot:k}}),Y=F[0].inst,H=F[1];return c(function(){Y.value=j,Y.getSnapshot=k,m(Y)&&H({inst:Y})},[_,j,k]),s(function(){m(Y)&&H({inst:Y});var oe=function(){m(Y)&&H({inst:Y})};return _(oe)},[_]),p(j),j}function m(_){var k=_.getSnapshot,b=_.value;try{var j=k();return!o(b,j)}catch{return!0}}function v(_,k,b){return k()}var g=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",E=!g,x=E?v:f,O=e.useSyncExternalStore!==void 0?e.useSyncExternalStore:x;ti.useSyncExternalStore=O,typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error)}()),ti}var co;function yl(){return co||(co=1,process.env.NODE_ENV==="production"?dn.exports=gl():dn.exports=hl()),dn.exports}var lo=yl();const Ze=()=>{},Ae=Ze(),ni=Object,N=e=>e===Ae,ze=e=>typeof e=="function",Le=(e,t)=>({...e,...t}),bl=e=>ze(e.then),fn=new WeakMap;let wl=0;const It=e=>{const t=typeof e,i=e&&e.constructor,n=i==Date;let r,o;if(ni(e)===e&&!n&&i!=RegExp){if(r=fn.get(e),r)return r;if(r=++wl+"~",fn.set(e,r),i==Array){for(r="@",o=0;o<e.length;o++)r+=It(e[o])+",";fn.set(e,r)}if(i==ni){r="#";const a=ni.keys(e).sort();for(;!N(o=a.pop());)N(e[o])||(r+=o+":"+It(e[o])+",");fn.set(e,r)}}else r=n?e.toJSON():t=="symbol"?e.toString():t=="string"?JSON.stringify(e):""+e;return r},Ve=new WeakMap,ii={},mn={},ri="undefined",xn=typeof window!=ri,oi=typeof document!=ri,El=()=>xn&&typeof window.requestAnimationFrame!=ri,ai=(e,t)=>{const i=Ve.get(e);return[()=>!N(t)&&e.get(t)||ii,n=>{if(!N(t)){const r=e.get(t);t in mn||(mn[t]=r),i[5](t,Le(r,n),r||ii)}},i[6],()=>!N(t)&&t in mn?mn[t]:!N(t)&&e.get(t)||ii]};let si=!0;const Sl=()=>si,[ci,li]=xn&&window.addEventListener?[window.addEventListener.bind(window),window.removeEventListener.bind(window)]:[Ze,Ze],Rl=()=>{const e=oi&&document.visibilityState;return N(e)||e!=="hidden"},Tl=e=>(oi&&document.addEventListener("visibilitychange",e),ci("focus",e),()=>{oi&&document.removeEventListener("visibilitychange",e),li("focus",e)}),kl=e=>{const t=()=>{si=!0,e()},i=()=>{si=!1};return ci("online",t),ci("offline",i),()=>{li("online",t),li("offline",i)}},Ol={isOnline:Sl,isVisible:Rl},Cl={initFocus:Tl,initReconnect:kl},Bt=!w.useId,lt=!xn||"Deno"in window,po=e=>El()?window.requestAnimationFrame(e):setTimeout(e,1),Qe=lt?w.useEffect:w.useLayoutEffect,pi=typeof navigator<"u"&&navigator.connection,uo=!lt&&pi&&(["slow-2g","2g"].includes(pi.effectiveType)||pi.saveData),zt=e=>{if(ze(e))try{e=e()}catch{e=""}const t=e;return e=typeof e=="string"?e:(Array.isArray(e)?e.length:e)?It(e):"",[e,t]};let _l=0;const wt=()=>++_l,fo=0,mo=1,xo=2;var He={__proto__:null,ERROR_REVALIDATE_EVENT:3,FOCUS_EVENT:fo,MUTATE_EVENT:xo,RECONNECT_EVENT:mo};async function ui(...e){const[t,i,n,r]=e,o=Le({populateCache:!0,throwOnError:!0},typeof r=="boolean"?{revalidate:r}:r||{});let a=o.populateCache;const s=o.rollbackOnError;let c=o.optimisticData;const p=f=>typeof s=="function"?s(f):s!==!1,l=o.throwOnError;if(ze(i)){const f=i,m=[],v=t.keys();for(const g of v)!/^\$(inf|sub)\$/.test(g)&&f(t.get(g)._k)&&m.push(g);return Promise.all(m.map(u))}return u(i);async function u(f){const[m]=zt(f);if(!m)return;const[v,g]=ai(t,m),[E,x,O,_]=Ve.get(t),k=()=>{const ne=E[m];return(ze(o.revalidate)?o.revalidate(v().data,f):o.revalidate!==!1)&&(delete O[m],delete _[m],ne&&ne[0])?ne[0](xo).then(()=>v().data):v().data};if(e.length<3)return k();let b=n,j;const q=wt();x[m]=[q,0];const F=!N(c),Y=v(),H=Y.data,oe=Y._c,he=N(oe)?H:oe;if(F&&(c=ze(c)?c(he,H):c,g({data:c,_c:he})),ze(b))try{b=b(he)}catch(ne){j=ne}if(b&&bl(b))if(b=await b.catch(ne=>{j=ne}),q!==x[m][0]){if(j)throw j;return b}else j&&F&&p(j)&&(a=!0,g({data:he,_c:Ae}));if(a&&!j)if(ze(a)){const ne=a(b,he);g({data:ne,error:Ae,_c:Ae})}else g({data:b,error:Ae,_c:Ae});if(x[m][1]=wt(),Promise.resolve(k()).then(()=>{g({_c:Ae})}),j){if(l)throw j;return}return b}}const vo=(e,t)=>{for(const i in e)e[i][0]&&e[i][0](t)},Al=(e,t)=>{if(!Ve.has(e)){const i=Le(Cl,t),n={},r=ui.bind(Ae,e);let o=Ze;const a={},s=(l,u)=>{const f=a[l]||[];return a[l]=f,f.push(u),()=>f.splice(f.indexOf(u),1)},c=(l,u,f)=>{e.set(l,u);const m=a[l];if(m)for(const v of m)v(u,f)},p=()=>{if(!Ve.has(e)&&(Ve.set(e,[n,{},{},{},r,c,s]),!lt)){const l=i.initFocus(setTimeout.bind(Ae,vo.bind(Ae,n,fo))),u=i.initReconnect(setTimeout.bind(Ae,vo.bind(Ae,n,mo)));o=()=>{l&&l(),u&&u(),Ve.delete(e)}}};return p(),[e,r,p,o]}return[e,Ve.get(e)[4]]},Dl=(e,t,i,n,r)=>{const o=i.errorRetryCount,a=r.retryCount,s=~~((Math.random()+.5)*(1<<(a<8?a:8)))*i.errorRetryInterval;!N(o)&&a>o||setTimeout(n,s,r)},jl=(e,t)=>It(e)==It(t),[go,Fl]=Al(new Map),Pl=Le({onLoadingSlow:Ze,onSuccess:Ze,onError:Ze,onErrorRetry:Dl,onDiscarded:Ze,revalidateOnFocus:!0,revalidateOnReconnect:!0,revalidateIfStale:!0,shouldRetryOnError:!0,errorRetryInterval:uo?1e4:5e3,focusThrottleInterval:5*1e3,dedupingInterval:2*1e3,loadingTimeout:uo?5e3:3e3,compare:jl,isPaused:()=>!1,cache:go,mutate:Fl,fallback:{}},Ol),Il=(e,t)=>{const i=Le(e,t);if(t){const{use:n,fallback:r}=e,{use:o,fallback:a}=t;n&&o&&(i.use=n.concat(o)),r&&a&&(i.fallback=Le(r,a))}return i},Bl=w.createContext({}),zl="$inf$",ho=xn&&window.__SWR_DEVTOOLS_USE__,Ll=ho?window.__SWR_DEVTOOLS_USE__:[],Ml=()=>{ho&&(window.__SWR_DEVTOOLS_REACT__=w)},yo=e=>ze(e[1])?[e[0],e[1],e[2]||{}]:[e[0],null,(e[1]===null?e[2]:e[1])||{}],bo=()=>Le(Pl,w.useContext(Bl)),$l=e=>(t,i,n)=>e(t,i&&((...o)=>{const[a]=zt(t),[,,,s]=Ve.get(go);if(a.startsWith(zl))return i(...o);const c=s[a];return N(c)?i(...o):(delete s[a],c)}),n),Nl=Ll.concat($l),wo=e=>function(...i){const n=bo(),[r,o,a]=yo(i),s=Il(n,a);let c=e;const{use:p}=s,l=(p||[]).concat(Nl);for(let u=l.length;u--;)c=l[u](c);return c(r,o||s.fetcher||null,s)},Eo=(e,t,i)=>{const n=t[e]||(t[e]=[]);return n.push(i),()=>{const r=n.indexOf(i);r>=0&&(n[r]=n[n.length-1],n.pop())}},ql=(e,t)=>(...i)=>{const[n,r,o]=yo(i),a=(o.use||[]).concat(t);return e(n,r,{...o,use:a})};Ml();const So=w.use||(e=>{if(e.status==="pending")throw e;if(e.status==="fulfilled")return e.value;throw e.status==="rejected"?e.reason:(e.status="pending",e.then(t=>{e.status="fulfilled",e.value=t},t=>{e.status="rejected",e.reason=t}),e)}),di={dedupe:!0},Ul=wo((e,t,i)=>{const{cache:n,compare:r,suspense:o,fallbackData:a,revalidateOnMount:s,revalidateIfStale:c,refreshInterval:p,refreshWhenHidden:l,refreshWhenOffline:u,keepPreviousData:f}=i,[m,v,g,E]=Ve.get(n),[x,O]=zt(e),_=w.useRef(!1),k=w.useRef(!1),b=w.useRef(x),j=w.useRef(t),q=w.useRef(i),F=()=>q.current,Y=()=>F().isVisible()&&F().isOnline(),[H,oe,he,ne]=ai(n,x),V=w.useRef({}).current,pe=N(a)?i.fallback[x]:a,Re=(y,P)=>{for(const X in V){const $=X;if($==="data"){if(!r(y[$],P[$])&&(!N(y[$])||!r(G,P[$])))return!1}else if(P[$]!==y[$])return!1}return!0},Te=w.useMemo(()=>{const y=!x||!t?!1:N(s)?F().isPaused()||o?!1:N(c)?!0:c:s,P=ee=>{const Ee=Le(ee);return delete Ee._k,y?{isValidating:!0,isLoading:!0,...Ee}:Ee},X=H(),$=ne(),de=P(X),ke=X===$?de:P($);let Q=de;return[()=>{const ee=P(H());return Re(ee,Q)?(Q.data=ee.data,Q.isLoading=ee.isLoading,Q.isValidating=ee.isValidating,Q.error=ee.error,Q):(Q=ee,ee)},()=>ke]},[n,x]),ue=lo.useSyncExternalStore(w.useCallback(y=>he(x,(P,X)=>{Re(X,P)||y()}),[n,x]),Te[0],Te[1]),we=!_.current,R=m[x]&&m[x].length>0,C=ue.data,B=N(C)?pe:C,U=ue.error,z=w.useRef(B),G=f?N(C)?z.current:C:B,L=R&&!N(U)?!1:we&&!N(s)?s:F().isPaused()?!1:o?N(B)?!1:c:N(B)||c,W=!!(x&&t&&we&&L),J=N(ue.isValidating)?W:ue.isValidating,te=N(ue.isLoading)?W:ue.isLoading,M=w.useCallback(async y=>{const P=j.current;if(!x||!P||k.current||F().isPaused())return!1;let X,$,de=!0;const ke=y||{},Q=!g[x]||!ke.dedupe,ee=()=>Bt?!k.current&&x===b.current&&_.current:x===b.current,Ee={isValidating:!1,isLoading:!1},Ye=()=>{oe(Ee)},qe=()=>{const S=g[x];S&&S[1]===$&&delete g[x]},Ke={isValidating:!0};N(H().data)&&(Ke.isLoading=!0);try{if(Q&&(oe(Ke),i.loadingTimeout&&N(H().data)&&setTimeout(()=>{de&&ee()&&F().onLoadingSlow(x,i)},i.loadingTimeout),g[x]=[P(O),wt()]),[X,$]=g[x],X=await X,Q&&setTimeout(qe,i.dedupingInterval),!g[x]||g[x][1]!==$)return Q&&ee()&&F().onDiscarded(x),!1;Ee.error=Ae;const S=v[x];if(!N(S)&&($<=S[0]||$<=S[1]||S[1]===0))return Ye(),Q&&ee()&&F().onDiscarded(x),!1;const A=H().data;Ee.data=r(A,X)?A:X,Q&&ee()&&F().onSuccess(X,x,i)}catch(S){qe();const A=F(),{shouldRetryOnError:ae}=A;A.isPaused()||(Ee.error=S,Q&&ee()&&(A.onError(S,x,A),(ae===!0||ze(ae)&&ae(S))&&(!F().revalidateOnFocus||!F().revalidateOnReconnect||Y())&&A.onErrorRetry(S,x,A,me=>{const Oe=m[x];Oe&&Oe[0]&&Oe[0](He.ERROR_REVALIDATE_EVENT,me)},{retryCount:(ke.retryCount||0)+1,dedupe:!0})))}return de=!1,Ye(),!0},[x,n]),ye=w.useCallback((...y)=>ui(n,b.current,...y),[]);if(Qe(()=>{j.current=t,q.current=i,N(C)||(z.current=C)}),Qe(()=>{if(!x)return;const y=M.bind(Ae,di);let P=0;const $=Eo(x,m,(de,ke={})=>{if(de==He.FOCUS_EVENT){const Q=Date.now();F().revalidateOnFocus&&Q>P&&Y()&&(P=Q+F().focusThrottleInterval,y())}else if(de==He.RECONNECT_EVENT)F().revalidateOnReconnect&&Y()&&y();else{if(de==He.MUTATE_EVENT)return M();if(de==He.ERROR_REVALIDATE_EVENT)return M(ke)}});return k.current=!1,b.current=x,_.current=!0,oe({_k:O}),L&&(N(B)||lt?y():po(y)),()=>{k.current=!0,$()}},[x]),Qe(()=>{let y;function P(){const $=ze(p)?p(H().data):p;$&&y!==-1&&(y=setTimeout(X,$))}function X(){!H().error&&(l||F().isVisible())&&(u||F().isOnline())?M(di).then(P):P()}return P(),()=>{y&&(clearTimeout(y),y=-1)}},[p,l,u,x]),w.useDebugValue(G),o&&N(B)&&x){if(!Bt&&lt)throw new Error("Fallback data is required when using suspense in SSR.");j.current=t,q.current=i,k.current=!1;const y=E[x];if(!N(y)){const P=ye(y);So(P)}if(N(U)){const P=M(di);N(G)||(P.status="fulfilled",P.value=!0),So(P)}else throw U}return{mutate:ye,get data(){return V.data=!0,G},get error(){return V.error=!0,U},get isValidating(){return V.isValidating=!0,J},get isLoading(){return V.isLoading=!0,te}}}),Ro=w.use||(e=>{if(e.status==="pending")throw e;if(e.status==="fulfilled")return e.value;throw e.status==="rejected"?e.reason:(e.status="pending",e.then(t=>{e.status="fulfilled",e.value=t},t=>{e.status="rejected",e.reason=t}),e)}),fi={dedupe:!0},Wl=wo((e,t,i)=>{const{cache:n,compare:r,suspense:o,fallbackData:a,revalidateOnMount:s,revalidateIfStale:c,refreshInterval:p,refreshWhenHidden:l,refreshWhenOffline:u,keepPreviousData:f}=i,[m,v,g,E]=Ve.get(n),[x,O]=zt(e),_=w.useRef(!1),k=w.useRef(!1),b=w.useRef(x),j=w.useRef(t),q=w.useRef(i),F=()=>q.current,Y=()=>F().isVisible()&&F().isOnline(),[H,oe,he,ne]=ai(n,x),V=w.useRef({}).current,pe=N(a)?i.fallback[x]:a,Re=(y,P)=>{for(const X in V){const $=X;if($==="data"){if(!r(y[$],P[$])&&(!N(y[$])||!r(G,P[$])))return!1}else if(P[$]!==y[$])return!1}return!0},Te=w.useMemo(()=>{const y=!x||!t?!1:N(s)?F().isPaused()||o?!1:N(c)?!0:c:s,P=ee=>{const Ee=Le(ee);return delete Ee._k,y?{isValidating:!0,isLoading:!0,...Ee}:Ee},X=H(),$=ne(),de=P(X),ke=X===$?de:P($);let Q=de;return[()=>{const ee=P(H());return Re(ee,Q)?(Q.data=ee.data,Q.isLoading=ee.isLoading,Q.isValidating=ee.isValidating,Q.error=ee.error,Q):(Q=ee,ee)},()=>ke]},[n,x]),ue=lo.useSyncExternalStore(w.useCallback(y=>he(x,(P,X)=>{Re(X,P)||y()}),[n,x]),Te[0],Te[1]),we=!_.current,R=m[x]&&m[x].length>0,C=ue.data,B=N(C)?pe:C,U=ue.error,z=w.useRef(B),G=f?N(C)?z.current:C:B,L=R&&!N(U)?!1:we&&!N(s)?s:F().isPaused()?!1:o?N(B)?!1:c:N(B)||c,W=!!(x&&t&&we&&L),J=N(ue.isValidating)?W:ue.isValidating,te=N(ue.isLoading)?W:ue.isLoading,M=w.useCallback(async y=>{const P=j.current;if(!x||!P||k.current||F().isPaused())return!1;let X,$,de=!0;const ke=y||{},Q=!g[x]||!ke.dedupe,ee=()=>Bt?!k.current&&x===b.current&&_.current:x===b.current,Ee={isValidating:!1,isLoading:!1},Ye=()=>{oe(Ee)},qe=()=>{const S=g[x];S&&S[1]===$&&delete g[x]},Ke={isValidating:!0};N(H().data)&&(Ke.isLoading=!0);try{if(Q&&(oe(Ke),i.loadingTimeout&&N(H().data)&&setTimeout(()=>{de&&ee()&&F().onLoadingSlow(x,i)},i.loadingTimeout),g[x]=[P(O),wt()]),[X,$]=g[x],X=await X,Q&&setTimeout(qe,i.dedupingInterval),!g[x]||g[x][1]!==$)return Q&&ee()&&F().onDiscarded(x),!1;Ee.error=Ae;const S=v[x];if(!N(S)&&($<=S[0]||$<=S[1]||S[1]===0))return Ye(),Q&&ee()&&F().onDiscarded(x),!1;const A=H().data;Ee.data=r(A,X)?A:X,Q&&ee()&&F().onSuccess(X,x,i)}catch(S){qe();const A=F(),{shouldRetryOnError:ae}=A;A.isPaused()||(Ee.error=S,Q&&ee()&&(A.onError(S,x,A),(ae===!0||ze(ae)&&ae(S))&&(!F().revalidateOnFocus||!F().revalidateOnReconnect||Y())&&A.onErrorRetry(S,x,A,me=>{const Oe=m[x];Oe&&Oe[0]&&Oe[0](He.ERROR_REVALIDATE_EVENT,me)},{retryCount:(ke.retryCount||0)+1,dedupe:!0})))}return de=!1,Ye(),!0},[x,n]),ye=w.useCallback((...y)=>ui(n,b.current,...y),[]);if(Qe(()=>{j.current=t,q.current=i,N(C)||(z.current=C)}),Qe(()=>{if(!x)return;const y=M.bind(Ae,fi);let P=0;const $=Eo(x,m,(de,ke={})=>{if(de==He.FOCUS_EVENT){const Q=Date.now();F().revalidateOnFocus&&Q>P&&Y()&&(P=Q+F().focusThrottleInterval,y())}else if(de==He.RECONNECT_EVENT)F().revalidateOnReconnect&&Y()&&y();else{if(de==He.MUTATE_EVENT)return M();if(de==He.ERROR_REVALIDATE_EVENT)return M(ke)}});return k.current=!1,b.current=x,_.current=!0,oe({_k:O}),L&&(N(B)||lt?y():po(y)),()=>{k.current=!0,$()}},[x]),Qe(()=>{let y;function P(){const $=ze(p)?p(H().data):p;$&&y!==-1&&(y=setTimeout(X,$))}function X(){!H().error&&(l||F().isVisible())&&(u||F().isOnline())?M(fi).then(P):P()}return P(),()=>{y&&(clearTimeout(y),y=-1)}},[p,l,u,x]),w.useDebugValue(G),o&&N(B)&&x){if(!Bt&&lt)throw new Error("Fallback data is required when using suspense in SSR.");j.current=t,q.current=i,k.current=!1;const y=E[x];if(!N(y)){const P=ye(y);Ro(P)}if(N(U)){const P=M(fi);N(G)||(P.status="fulfilled",P.value=!0),Ro(P)}else throw U}return{mutate:ye,get data(){return V.data=!0,G},get error(){return V.error=!0,U},get isValidating(){return V.isValidating=!0,J},get isLoading(){return V.isLoading=!0,te}}}),To=Bt?e=>{e()}:w.startTransition,Vl=e=>{const[,t]=w.useState({}),i=w.useRef(!1),n=w.useRef(e),r=w.useRef({data:!1,error:!1,isValidating:!1}),o=w.useCallback(a=>{let s=!1;const c=n.current;for(const p in a){const l=p;c[l]!==a[l]&&(c[l]=a[l],r.current[l]&&(s=!0))}s&&!i.current&&t({})},[]);return Qe(()=>(i.current=!1,()=>{i.current=!0})),[n,r.current,o]},Hl=ql(Wl,()=>(e,t,i={})=>{const{mutate:n}=bo(),r=w.useRef(e),o=w.useRef(t),a=w.useRef(i),s=w.useRef(0),[c,p,l]=Vl({data:Ae,error:Ae,isMutating:!1}),u=c.current,f=w.useCallback(async(v,g)=>{const[E,x]=zt(r.current);if(!o.current)throw new Error("Can’t trigger the mutation: missing fetcher.");if(!E)throw new Error("Can’t trigger the mutation: missing key.");const O=Le(Le({populateCache:!1,throwOnError:!0},a.current),g),_=wt();s.current=_,l({isMutating:!0});try{const k=await n(E,o.current(x,{arg:v}),Le(O,{throwOnError:!0}));return s.current<=_&&(To(()=>l({data:k,isMutating:!1,error:void 0})),O.onSuccess==null||O.onSuccess.call(O,k,E,O)),k}catch(k){if(s.current<=_&&(To(()=>l({error:k,isMutating:!1})),O.onError==null||O.onError.call(O,k,E,O),O.throwOnError))throw k}},[]),m=w.useCallback(()=>{s.current=wt(),l({data:Ae,error:Ae,isMutating:!1})},[]);return Qe(()=>{r.current=e,o.current=t,a.current=i}),{trigger:f,reset:m,get data(){return p.data=!0,u.data},get error(){return p.error=!0,u.error},get isMutating(){return p.isMutating=!0,u.isMutating}}}),Gl=e=>ve.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",stroke:"currentColor",...e,children:[ve.jsx("path",{opacity:"0.15",d:"M14 8C14 11.3137 11.3137 14 8 14C4.68629 14 2 11.3137 2 8C2 4.68629 4.68629 2 8 2C11.3137 2 14 4.68629 14 8Z"}),ve.jsx("path",{d:"M14 8C14 11.3137 11.3137 14 8 14C4.68629 14 2 11.3137 2 8C2 4.68629 4.68629 2 8 2",strokeLinecap:"round"})]}),Yl=ya({"0%":{transform:"rotate(0deg)"},"100%":{transform:"rotate(360deg)"}}),Kl=$e(Gl,{animation:`${Yl} 2s linear infinite`,variants:{size:{sm:{width:"16px",height:"16px",strokeWidth:"1px"},md:{width:"24px",height:"24px",strokeWidth:"1.5px"},lg:{width:"32px",height:"32px",strokeWidth:"2px"}}}}),Jl=e=>ve.jsx("svg",{width:"15",height:"15",viewBox:"0 0 15 15",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e,children:ve.jsx("path",{d:"M6.04995 2.74998C6.04995 2.44623 5.80371 2.19998 5.49995 2.19998C5.19619 2.19998 4.94995 2.44623 4.94995 2.74998V12.25C4.94995 12.5537 5.19619 12.8 5.49995 12.8C5.80371 12.8 6.04995 12.5537 6.04995 12.25V2.74998ZM10.05 2.74998C10.05 2.44623 9.80371 2.19998 9.49995 2.19998C9.19619 2.19998 8.94995 2.44623 8.94995 2.74998V12.25C8.94995 12.5537 9.19619 12.8 9.49995 12.8C9.80371 12.8 10.05 12.5537 10.05 12.25V2.74998Z",fill:"currentColor",fillRule:"evenodd",clipRule:"evenodd"})}),Xl=({...e})=>ve.jsx("svg",{width:"15",height:"15",viewBox:"0 0 24 24",xmlns:"http://www.w3.orkllg/2000/svg",fill:"currentColor",...e,children:ve.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M5.1869 3.71487C5.42703 3.57009 5.72543 3.56159 5.9734 3.69247L20.3734 11.2925C20.6358 11.431 20.8 11.7033 20.8 12C20.8 12.2967 20.6358 12.569 20.3734 12.7075L5.9734 20.3075C5.72543 20.4384 5.42703 20.4299 5.1869 20.2851C4.94679 20.1403 4.79999 19.8803 4.79999 19.6V4.39998C4.79999 4.11959 4.94679 3.85966 5.1869 3.71487Z",fill:"currentColor"})}),Zl=e=>{if(!e)return!1;const t=e.split("?")[1];if(!t)return!1;const n=new URLSearchParams(t).get("Expires");return n?new Date(n)<new Date:!1},ko=e=>e&&e.split("?")[0],Ql=(e,t)=>ko(e)===ko(t),ep=()=>{const[e,t]=w.useState("paused"),i=()=>{if(typeof window>"u")return null;const p=new Audio;return p.addEventListener("play",()=>t("playing")),p},n=w.useMemo(i,[]),r=w.useRef(n);return{audioRef:r,state:e,setAudio:p=>new Promise(l=>{const u=r==null?void 0:r.current;u&&(u.setAttribute("src",p),t("loading"),u.addEventListener("loadedmetadata",()=>{t("paused"),l()},{once:!0}))}),play:()=>{var p,l;(p=r.current)==null||p.play(),(l=r.current)==null||l.addEventListener("ended",()=>t("paused"),{once:!0})},pause:()=>{var p;(p=r.current)==null||p.pause(),t("paused")},stop:()=>{var l;r.current&&((l=r.current)==null||l.pause(),r.current.currentTime=0),t("paused")}}},mi=w.createContext(null),Oo=e=>{var a;const t=w.useContext(mi),i=Ql((a=t.audioRef.current)==null?void 0:a.src,e),n=t.state==="loading"&&i,r=t.state==="playing"&&i;return{...t,isMySrc:i,isLoading:n,isPlaying:r,play:async()=>{var c;const s=(c=t.audioRef.current)==null?void 0:c.src;(!i||Zl(s))&&await t.setAudio(e),t.play()}}},tp=()=>w.useContext(mi),Co=({children:e})=>{const t=ep();return ve.jsx(mi.Provider,{value:t,children:e})},_o=(e,t,i)=>{const n=Oo(e),r=w.useRef(!1),o=()=>{r.current||(r.current=!0),n.isPlaying?(n.pause(),i==null||i()):(n.play(),t==null||t())};return w.useEffect(()=>()=>{n.isPlaying&&n.pause()},[]),{player:n,playPause:o}},pt=({limit:e,isTrue:t,children:i})=>{const n=[];return t!==!0?null:(No.Children.map(i,r=>{const{isTrue:o}=(r==null?void 0:r.props)||{};o===!0&&(!e||n.length<e)&&n.push(r)}),ve.jsx(ve.Fragment,{children:n}))};pt.defaultProps={limit:1,isTrue:!0},pt.If=({children:e,isTrue:t})=>e;const Ao=({children:e})=>e;Ao.defaultProps={isTrue:!0},pt.Else=Ao;const np=e=>{const t=r=>typeof r=="object"&&!(r instanceof Date)&&!(r instanceof File)&&r!==null,i=(r,o,a)=>{for(const s in o){const c=o[s];t(c)?i(`${r}[${s}]`,c,a):c!==void 0&&a.append(`${r}[${s}]`,c===null?"":c)}},n=new FormData;for(const r in e){const o=e[r];o instanceof File?n.append(r,o,o.name):o!==void 0&&(t(o)?i(r,o,n):n.append(r,o===null?"":o))}return n},ip=$e("div",{"--progress":"-100%",height:"8px",width:"100%",background:"rgba(255, 255, 255, 0.1)",borderRadius:"12px",position:"relative",overflow:"hidden"}),rp=$e("div",{height:"100%",width:"100%",background:"#ffffff",transition:"transform 0.2s ease-in-out",transform:"translateX(var(--progress))",borderRadius:"12px"}),op=({progress:e})=>ve.jsx(ip,{style:{"--progress":`${-100+e}%`},children:ve.jsx(rp,{})});function vn(e,t,i){for(let n=0;n<e.length;++n)t[i+n]=e.charCodeAt(n)}function gn(e,t,i){e=Math.floor(e),t[i+0]=e&255,t[i+1]=e>>8&255}function ut(e,t,i){e=Math.floor(e),t[i+0]=e&255,t[i+1]=e>>8&255,t[i+2]=e>>16&255,t[i+3]=e>>24&255}function ap(e){const t=new ArrayBuffer(4);return new Float32Array(t)[0]=e,new Uint32Array(t)[0]|0}function sp(e,t,i,n){let r=0,o=0;const a=e.length,s=e.numberOfChannels;let c,p;for(r=0;r<a;++r)for(o=0;o<s;++o)if(c=e.getChannelData(o),n===16)p=c[r]*32768,p=Math.max(-32768,Math.min(p,32767)),gn(p,t,i),i+=2;else if(n===32)p=ap(c[r]),ut(p,t,i),i+=4;else{console.log("Invalid bit depth for PCM encoding.");return}}async function cp(e,t){let i=e instanceof Blob?e:new Blob(e);const n=URL.createObjectURL(i),o=await(await fetch(n)).arrayBuffer();return await new AudioContext(t).decodeAudioData(o)}async function lp(e,t=!1){const i=e.length,n=e.numberOfChannels,r=e.sampleRate,o=t?32:16,a=o/8,s=r*n*o/8,c=n*o/8,p=i*n*a,u=44+p,f=new Uint8Array(u),m=16,v=p,g=4+(8+m)+(8+v);return vn("RIFF",f,0),ut(g,f,4),vn("WAVE",f,8),vn("fmt ",f,12),ut(m,f,16),gn(t?3:1,f,20),gn(n,f,22),ut(r,f,24),ut(s,f,28),gn(c,f,32),ut(o,f,34),vn("data",f,36),ut(v,f,40),sp(e,f,44,o),new Blob([f],{type:"audio/wave"})}async function pp(e,t=!1,i){const n=await cp(e,i);return lp(n,t)}const up=128;class dp{constructor(){bn(this,"mediaRecorder",null);bn(this,"stream",null);bn(this,"__data",null)}async checkMicrophonePermission(){var n;return!!(await((n=navigator==null?void 0:navigator.mediaDevices)==null?void 0:n.enumerateDevices())).find(r=>r.kind==="audioinput"&&!!r.label)}async startRecording(){var t;if(((t=this.mediaRecorder)==null?void 0:t.state)==="recording")return!0;try{this.stream=await navigator.mediaDevices.getUserMedia({audio:!0,video:!1}),this.mediaRecorder=new MediaRecorder(this.stream,{bitsPerSecond:up*1e3}),this.mediaRecorder.ondataavailable=i=>this.__data=i.data}catch(i){return console.error(i),!1}return this.mediaRecorder.start(),!0}stopRecording(){return new Promise(t=>{var i;if(((i=this.mediaRecorder)==null?void 0:i.state)!=="recording"){t(!0);return}this.mediaRecorder.stop(),this.mediaRecorder.onstop=()=>{var n;(n=this.stream)==null||n.getTracks().forEach(r=>r.stop()),this.mediaRecorder=null,this.stream=null,t(!0)}})}async getWavBlob(){return this.__data?await pp(this.__data):null}}const hn=new dp,xi="Recording.wav",Do=1500,fp=e=>{const[t,i]=w.useState(!1),[n,r]=w.useState(!1),[o,a]=w.useState(!1);return w.useEffect(()=>{var p;const c=async()=>{hn.checkMicrophonePermission().then(i)};return c(),(p=navigator==null?void 0:navigator.mediaDevices)==null||p.addEventListener("devicechange",c),()=>{var l;return(l=navigator==null?void 0:navigator.mediaDevices)==null?void 0:l.removeEventListener("devicechange",c)}},[]),{hasMicAccess:t,isRecording:n,hasMinTimeElapsed:o,handleClick:async()=>{if(n){if(!o)return;r(!1),a(!1),await hn.stopRecording();const p=await hn.getWavBlob();if(!p){console.log("Failed to get audio blob",p);return}const l=new File([p],xi,{type:"audio/mpeg",lastModified:Date.now()});e.onFileUpdate(l);return}const c=await hn.startRecording();r(c),setTimeout(()=>{a(!0)},Do)}}},jo=_e.create({baseURL:"https://arpeggi.io/api/v2/"}),mp=async(e,{arg:t})=>(await jo.post("/ml-inference-jobs",np({soundFile:t.file,type:"audio",voiceModelId:t.voiceModelId,metadata:{splitInstrumental:!0,isRecordedAudio:t.file.name===xi}}),{params:{type:"audio"}})).data,xp=async e=>e===null?null:(await jo.get(e)).data,vp=e=>{const t=e>0;return Ul(t?`/ml-inference-jobs/${e}`:null,xp,{refreshInterval:1e3})},gp=()=>{const[e,t]=w.useState(null),[i,n]=w.useState(0),[r,o]=w.useState(0),{data:a,isLoading:s}=vp(i),{trigger:c,isMutating:p}=Hl("/ml-inference-jobs",mp);return{file:e,setFile:t,mlijId:i,setMlijId:n,voiceModelId:r,setVoiceModelId:o,data:a,isLoading:s,handleSelectVoice:async f=>{e&&(n(0),o(f),c({file:e,voiceModelId:f},{onSuccess:m=>{console.log("created mlij",m),n(m.id)}}))},reset:()=>{t(null),n(0),o(0)},isMutating:p}},Fo=w.createContext({}),yn=()=>w.useContext(Fo),hp=({children:e})=>{const t=gp();return ve.jsx(Co,{children:ve.jsx(Fo.Provider,{value:t,children:e})})},yp=$e("button",{background:"#ffffff",borderRadius:"12px",width:"64px",height:"64px",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",border:"none",outline:"none",transition:"background 0.2s ease-in-out, transform 0.2s ease-in-out",color:"#000000","& > svg":{width:"24px",height:"24px"},"&:hover":{background:"#ffffff99",transform:"scale(1.05)"},"&:active":{background:"#ffffffcc"},"&:disabled":{background:"rgba(255, 255, 255, 0.3)",transform:"none",cursor:"not-allowed"}}),bp=()=>{var o;const{data:e,isMutating:t}=yn(),i=(o=e==null?void 0:e.lossyOutputFile)==null?void 0:o.url,{player:n,playPause:r}=_o(i);return ve.jsx(yp,{onClick:r,disabled:n.isLoading||!i,children:ve.jsxs(pt,{children:[ve.jsx(pt.If,{isTrue:n.isLoading||(e==null?void 0:e.jobStatus)==="running"||t,children:ve.jsx(Kl,{})}),ve.jsx(pt.If,{isTrue:n.isPlaying,children:ve.jsx(Jl,{})}),ve.jsx(pt.Else,{children:ve.jsx(Xl,{})})]})})},vi=30,wp=10,Ep=()=>{const{data:e}=yn(),[t,i]=w.useState(0);return w.useEffect(()=>{if(!e)return;const n=setInterval(()=>{const r=(e==null?void 0:e.audioDurationMs)/1e3||vi,o=new Date(e==null?void 0:e.createdAt).getTime(),s=(new Date().getTime()-o)/1e3,c=Math.max(s/(vi+wp+r)*100,100);i(c)},100);return()=>clearInterval(n)},[e]),ve.jsx(op,{progress:t})},Sp=1,Rp=100*1024*1024,Tp=1,kp=({children:e})=>{const{setFile:t}=yn(),i=n=>t(n[0]);return ve.jsx(wr,{files:[],onFileAccepted:i,maxFileCount:Sp,maxSizeBytes:Rp,minSizeBytes:Tp,maxDurationS:vi,children:e})};xe.AudioFilePickerRoot=wr,xe.ConvertStep=Gs,xe.FilePicker=kp,xe.GuestConvertProvider=hp,xe.InferenceProgress=Ep,xe.MIN_RECORDING_LENGTH_MS=Do,xe.PlayButton=bp,xe.PlayerProvider=Co,xe.RECORDED_AUDIO_NAME=xi,xe.useAudioFilePickerContext=$s,xe.useGuestConvertContext=yn,xe.usePlayback=_o,xe.usePlayer=Oo,xe.usePlayerControls=tp,xe.useRecorder=fp,Object.defineProperty(xe,Symbol.toStringTag,{value:"Module"})});
70
70
  //# sourceMappingURL=index.umd.js.map