arpeggi-framer-components 0.0.36 → 0.0.37

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 po;function kl(){return po||(po=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(A){{for(var k=arguments.length,v=new Array(k>1?k-1:0),C=1;C<k;C++)v[C-1]=arguments[C];n("error",A,v)}}function n(A,k,v){{var C=t.ReactDebugCurrentFrame,L=C.getStackAddendum();L!==""&&(k+="%s",v=v.concat([L]));var j=v.map(function(G){return String(G)});j.unshift("Warning: "+k),Function.prototype.apply.call(console[A],console,j)}}function r(A,k){return A===k&&(A!==0||1/A===1/k)||A!==A&&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(A,k,v){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 C=k();if(!u){var L=k();o(C,L)||(i("The result of getSnapshot should be cached to avoid an infinite loop"),u=!0)}var j=a({inst:{value:C,getSnapshot:k}}),G=j[0].inst,Y=j[1];return c(function(){G.value=C,G.getSnapshot=k,x(G)&&Y({inst:G})},[A,C,k]),s(function(){x(G)&&Y({inst:G});var re=function(){x(G)&&Y({inst:G})};return A(re)},[A]),p(C),C}function x(A){var k=A.getSnapshot,v=A.value;try{var C=k();return!o(v,C)}catch{return!0}}function h(A,k,v){return k()}var g=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",E=!g,m=E?h:f,O=e.useSyncExternalStore!==void 0?e.useSyncExternalStore:m;ri.useSyncExternalStore=O,typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error)}()),ri}var uo;function Ol(){return uo||(uo=1,process.env.NODE_ENV==="production"?mn.exports=Tl():mn.exports=kl()),mn.exports}var fo=Ol();const et=()=>{},Ae=et(),oi=Object,V=e=>e===Ae,ze=e=>typeof e=="function",Me=(e,t)=>({...e,...t}),Cl=e=>ze(e.then),xn=new WeakMap;let _l=0;const Bt=e=>{const t=typeof e,i=e&&e.constructor,n=i==Date;let r,o;if(oi(e)===e&&!n&&i!=RegExp){if(r=xn.get(e),r)return r;if(r=++_l+"~",xn.set(e,r),i==Array){for(r="@",o=0;o<e.length;o++)r+=Bt(e[o])+",";xn.set(e,r)}if(i==oi){r="#";const a=oi.keys(e).sort();for(;!V(o=a.pop());)V(e[o])||(r+=o+":"+Bt(e[o])+",");xn.set(e,r)}}else r=n?e.toJSON():t=="symbol"?e.toString():t=="string"?JSON.stringify(e):""+e;return r},He=new WeakMap,ai={},vn={},si="undefined",gn=typeof window!=si,ci=typeof document!=si,Al=()=>gn&&typeof window.requestAnimationFrame!=si,li=(e,t)=>{const i=He.get(e);return[()=>!V(t)&&e.get(t)||ai,n=>{if(!V(t)){const r=e.get(t);t in vn||(vn[t]=r),i[5](t,Me(r,n),r||ai)}},i[6],()=>!V(t)&&t in vn?vn[t]:!V(t)&&e.get(t)||ai]};let pi=!0;const jl=()=>pi,[ui,di]=gn&&window.addEventListener?[window.addEventListener.bind(window),window.removeEventListener.bind(window)]:[et,et],Dl=()=>{const e=ci&&document.visibilityState;return V(e)||e!=="hidden"},Fl=e=>(ci&&document.addEventListener("visibilitychange",e),ui("focus",e),()=>{ci&&document.removeEventListener("visibilitychange",e),di("focus",e)}),Pl=e=>{const t=()=>{pi=!0,e()},i=()=>{pi=!1};return ui("online",t),ui("offline",i),()=>{di("online",t),di("offline",i)}},Il={isOnline:jl,isVisible:Dl},Bl={initFocus:Fl,initReconnect:Pl},Lt=!w.useId,dt=!gn||"Deno"in window,mo=e=>Al()?window.requestAnimationFrame(e):setTimeout(e,1),tt=dt?w.useEffect:w.useLayoutEffect,fi=typeof navigator<"u"&&navigator.connection,xo=!dt&&fi&&(["slow-2g","2g"].includes(fi.effectiveType)||fi.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)?Bt(e):"",[e,t]};let Ll=0;const Et=()=>++Ll,vo=0,go=1,ho=2;var Ge={__proto__:null,ERROR_REVALIDATE_EVENT:3,FOCUS_EVENT:vo,MUTATE_EVENT:ho,RECONNECT_EVENT:go};async function mi(...e){const[t,i,n,r]=e,o=Me({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,x=[],h=t.keys();for(const g of h)!/^\$(inf|sub)\$/.test(g)&&f(t.get(g)._k)&&x.push(g);return Promise.all(x.map(u))}return u(i);async function u(f){const[x]=zt(f);if(!x)return;const[h,g]=li(t,x),[E,m,O,A]=He.get(t),k=()=>{const Z=E[x];return(ze(o.revalidate)?o.revalidate(h().data,f):o.revalidate!==!1)&&(delete O[x],delete A[x],Z&&Z[0])?Z[0](ho).then(()=>h().data):h().data};if(e.length<3)return k();let v=n,C;const L=Et();m[x]=[L,0];const j=!V(c),G=h(),Y=G.data,re=G._c,oe=V(re)?Y:re;if(j&&(c=ze(c)?c(oe,Y):c,g({data:c,_c:oe})),ze(v))try{v=v(oe)}catch(Z){C=Z}if(v&&Cl(v))if(v=await v.catch(Z=>{C=Z}),L!==m[x][0]){if(C)throw C;return v}else C&&j&&p(C)&&(a=!0,g({data:oe,_c:Ae}));if(a&&!C)if(ze(a)){const Z=a(v,oe);g({data:Z,error:Ae,_c:Ae})}else g({data:v,error:Ae,_c:Ae});if(m[x][1]=Et(),Promise.resolve(k()).then(()=>{g({_c:Ae})}),C){if(l)throw C;return}return v}}const yo=(e,t)=>{for(const i in e)e[i][0]&&e[i][0](t)},zl=(e,t)=>{if(!He.has(e)){const i=Me(Bl,t),n={},r=mi.bind(Ae,e);let o=et;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 x=a[l];if(x)for(const h of x)h(u,f)},p=()=>{if(!He.has(e)&&(He.set(e,[n,{},{},{},r,c,s]),!dt)){const l=i.initFocus(setTimeout.bind(Ae,yo.bind(Ae,n,vo))),u=i.initReconnect(setTimeout.bind(Ae,yo.bind(Ae,n,go)));o=()=>{l&&l(),u&&u(),He.delete(e)}}};return p(),[e,r,p,o]}return[e,He.get(e)[4]]},Ml=(e,t,i,n,r)=>{const o=i.errorRetryCount,a=r.retryCount,s=~~((Math.random()+.5)*(1<<(a<8?a:8)))*i.errorRetryInterval;!V(o)&&a>o||setTimeout(n,s,r)},$l=(e,t)=>Bt(e)==Bt(t),[bo,Nl]=zl(new Map),ql=Me({onLoadingSlow:et,onSuccess:et,onError:et,onErrorRetry:Ml,onDiscarded:et,revalidateOnFocus:!0,revalidateOnReconnect:!0,revalidateIfStale:!0,shouldRetryOnError:!0,errorRetryInterval:xo?1e4:5e3,focusThrottleInterval:5*1e3,dedupingInterval:2*1e3,loadingTimeout:xo?5e3:3e3,compare:$l,isPaused:()=>!1,cache:bo,mutate:Nl,fallback:{}},Il),Wl=(e,t)=>{const i=Me(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=Me(r,a))}return i},Ul=w.createContext({}),Vl="$inf$",wo=gn&&window.__SWR_DEVTOOLS_USE__,Hl=wo?window.__SWR_DEVTOOLS_USE__:[],Gl=()=>{wo&&(window.__SWR_DEVTOOLS_REACT__=w)},Eo=e=>ze(e[1])?[e[0],e[1],e[2]||{}]:[e[0],null,(e[1]===null?e[2]:e[1])||{}],So=()=>Me(ql,w.useContext(Ul)),Yl=e=>(t,i,n)=>e(t,i&&((...o)=>{const[a]=zt(t),[,,,s]=He.get(bo);if(a.startsWith(Vl))return i(...o);const c=s[a];return V(c)?i(...o):(delete s[a],c)}),n),Kl=Hl.concat(Yl),Ro=e=>function(...i){const n=So(),[r,o,a]=Eo(i),s=Wl(n,a);let c=e;const{use:p}=s,l=(p||[]).concat(Kl);for(let u=l.length;u--;)c=l[u](c);return c(r,o||s.fetcher||null,s)},To=(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())}},Jl=(e,t)=>(...i)=>{const[n,r,o]=Eo(i),a=(o.use||[]).concat(t);return e(n,r,{...o,use:a})};Gl();const ko=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)}),xi={dedupe:!0},Xl=Ro((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,[x,h,g,E]=He.get(n),[m,O]=zt(e),A=w.useRef(!1),k=w.useRef(!1),v=w.useRef(m),C=w.useRef(t),L=w.useRef(i),j=()=>L.current,G=()=>j().isVisible()&&j().isOnline(),[Y,re,oe,Z]=li(n,m),W=w.useRef({}).current,le=V(a)?i.fallback[m]:a,xe=(b,I)=>{for(const Q in W){const U=Q;if(U==="data"){if(!r(b[U],I[U])&&(!V(b[U])||!r(K,I[U])))return!1}else if(I[U]!==b[U])return!1}return!0},we=w.useMemo(()=>{const b=!m||!t?!1:V(s)?j().isPaused()||o?!1:V(c)?!0:c:s,I=ie=>{const Re=Me(ie);return delete Re._k,b?{isValidating:!0,isLoading:!0,...Re}:Re},Q=Y(),U=Z(),ve=I(Q),ke=Q===U?ve:I(U);let ne=ve;return[()=>{const ie=I(Y());return xe(ie,ne)?(ne.data=ie.data,ne.isLoading=ie.isLoading,ne.isValidating=ie.isValidating,ne.error=ie.error,ne):(ne=ie,ie)},()=>ke]},[n,m]),ce=fo.useSyncExternalStore(w.useCallback(b=>oe(m,(I,Q)=>{xe(Q,I)||b()}),[n,m]),we[0],we[1]),he=!A.current,R=x[m]&&x[m].length>0,_=ce.data,z=V(_)?le:_,q=ce.error,$=w.useRef(z),K=f?V(_)?$.current:_:z,M=R&&!V(q)?!1:he&&!V(s)?s:j().isPaused()?!1:o?V(z)?!1:c:V(z)||c,P=!!(m&&t&&he&&M),H=V(ce.isValidating)?P:ce.isValidating,J=V(ce.isLoading)?P:ce.isLoading,N=w.useCallback(async b=>{const I=C.current;if(!m||!I||k.current||j().isPaused())return!1;let Q,U,ve=!0;const ke=b||{},ne=!g[m]||!ke.dedupe,ie=()=>Lt?!k.current&&m===v.current&&A.current:m===v.current,Re={isValidating:!1,isLoading:!1},Ke=()=>{re(Re)},We=()=>{const S=g[m];S&&S[1]===U&&delete g[m]},Je={isValidating:!0};V(Y().data)&&(Je.isLoading=!0);try{if(ne&&(re(Je),i.loadingTimeout&&V(Y().data)&&setTimeout(()=>{ve&&ie()&&j().onLoadingSlow(m,i)},i.loadingTimeout),g[m]=[I(O),Et()]),[Q,U]=g[m],Q=await Q,ne&&setTimeout(We,i.dedupingInterval),!g[m]||g[m][1]!==U)return ne&&ie()&&j().onDiscarded(m),!1;Re.error=Ae;const S=h[m];if(!V(S)&&(U<=S[0]||U<=S[1]||S[1]===0))return Ke(),ne&&ie()&&j().onDiscarded(m),!1;const D=Y().data;Re.data=r(D,Q)?D:Q,ne&&ie()&&j().onSuccess(Q,m,i)}catch(S){We();const D=j(),{shouldRetryOnError:pe}=D;D.isPaused()||(Re.error=S,ne&&ie()&&(D.onError(S,m,D),(pe===!0||ze(pe)&&pe(S))&&(!j().revalidateOnFocus||!j().revalidateOnReconnect||G())&&D.onErrorRetry(S,m,D,ye=>{const Oe=x[m];Oe&&Oe[0]&&Oe[0](Ge.ERROR_REVALIDATE_EVENT,ye)},{retryCount:(ke.retryCount||0)+1,dedupe:!0})))}return ve=!1,Ke(),!0},[m,n]),Ee=w.useCallback((...b)=>mi(n,v.current,...b),[]);if(tt(()=>{C.current=t,L.current=i,V(_)||($.current=_)}),tt(()=>{if(!m)return;const b=N.bind(Ae,xi);let I=0;const U=To(m,x,(ve,ke={})=>{if(ve==Ge.FOCUS_EVENT){const ne=Date.now();j().revalidateOnFocus&&ne>I&&G()&&(I=ne+j().focusThrottleInterval,b())}else if(ve==Ge.RECONNECT_EVENT)j().revalidateOnReconnect&&G()&&b();else{if(ve==Ge.MUTATE_EVENT)return N();if(ve==Ge.ERROR_REVALIDATE_EVENT)return N(ke)}});return k.current=!1,v.current=m,A.current=!0,re({_k:O}),M&&(V(z)||dt?b():mo(b)),()=>{k.current=!0,U()}},[m]),tt(()=>{let b;function I(){const U=ze(p)?p(Y().data):p;U&&b!==-1&&(b=setTimeout(Q,U))}function Q(){!Y().error&&(l||j().isVisible())&&(u||j().isOnline())?N(xi).then(I):I()}return I(),()=>{b&&(clearTimeout(b),b=-1)}},[p,l,u,m]),w.useDebugValue(K),o&&V(z)&&m){if(!Lt&&dt)throw new Error("Fallback data is required when using suspense in SSR.");C.current=t,L.current=i,k.current=!1;const b=E[m];if(!V(b)){const I=Ee(b);ko(I)}if(V(q)){const I=N(xi);V(K)||(I.status="fulfilled",I.value=!0),ko(I)}else throw q}return{mutate:Ee,get data(){return W.data=!0,K},get error(){return W.error=!0,q},get isValidating(){return W.isValidating=!0,H},get isLoading(){return W.isLoading=!0,J}}}),Oo=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)}),vi={dedupe:!0},Zl=Ro((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,[x,h,g,E]=He.get(n),[m,O]=zt(e),A=w.useRef(!1),k=w.useRef(!1),v=w.useRef(m),C=w.useRef(t),L=w.useRef(i),j=()=>L.current,G=()=>j().isVisible()&&j().isOnline(),[Y,re,oe,Z]=li(n,m),W=w.useRef({}).current,le=V(a)?i.fallback[m]:a,xe=(b,I)=>{for(const Q in W){const U=Q;if(U==="data"){if(!r(b[U],I[U])&&(!V(b[U])||!r(K,I[U])))return!1}else if(I[U]!==b[U])return!1}return!0},we=w.useMemo(()=>{const b=!m||!t?!1:V(s)?j().isPaused()||o?!1:V(c)?!0:c:s,I=ie=>{const Re=Me(ie);return delete Re._k,b?{isValidating:!0,isLoading:!0,...Re}:Re},Q=Y(),U=Z(),ve=I(Q),ke=Q===U?ve:I(U);let ne=ve;return[()=>{const ie=I(Y());return xe(ie,ne)?(ne.data=ie.data,ne.isLoading=ie.isLoading,ne.isValidating=ie.isValidating,ne.error=ie.error,ne):(ne=ie,ie)},()=>ke]},[n,m]),ce=fo.useSyncExternalStore(w.useCallback(b=>oe(m,(I,Q)=>{xe(Q,I)||b()}),[n,m]),we[0],we[1]),he=!A.current,R=x[m]&&x[m].length>0,_=ce.data,z=V(_)?le:_,q=ce.error,$=w.useRef(z),K=f?V(_)?$.current:_:z,M=R&&!V(q)?!1:he&&!V(s)?s:j().isPaused()?!1:o?V(z)?!1:c:V(z)||c,P=!!(m&&t&&he&&M),H=V(ce.isValidating)?P:ce.isValidating,J=V(ce.isLoading)?P:ce.isLoading,N=w.useCallback(async b=>{const I=C.current;if(!m||!I||k.current||j().isPaused())return!1;let Q,U,ve=!0;const ke=b||{},ne=!g[m]||!ke.dedupe,ie=()=>Lt?!k.current&&m===v.current&&A.current:m===v.current,Re={isValidating:!1,isLoading:!1},Ke=()=>{re(Re)},We=()=>{const S=g[m];S&&S[1]===U&&delete g[m]},Je={isValidating:!0};V(Y().data)&&(Je.isLoading=!0);try{if(ne&&(re(Je),i.loadingTimeout&&V(Y().data)&&setTimeout(()=>{ve&&ie()&&j().onLoadingSlow(m,i)},i.loadingTimeout),g[m]=[I(O),Et()]),[Q,U]=g[m],Q=await Q,ne&&setTimeout(We,i.dedupingInterval),!g[m]||g[m][1]!==U)return ne&&ie()&&j().onDiscarded(m),!1;Re.error=Ae;const S=h[m];if(!V(S)&&(U<=S[0]||U<=S[1]||S[1]===0))return Ke(),ne&&ie()&&j().onDiscarded(m),!1;const D=Y().data;Re.data=r(D,Q)?D:Q,ne&&ie()&&j().onSuccess(Q,m,i)}catch(S){We();const D=j(),{shouldRetryOnError:pe}=D;D.isPaused()||(Re.error=S,ne&&ie()&&(D.onError(S,m,D),(pe===!0||ze(pe)&&pe(S))&&(!j().revalidateOnFocus||!j().revalidateOnReconnect||G())&&D.onErrorRetry(S,m,D,ye=>{const Oe=x[m];Oe&&Oe[0]&&Oe[0](Ge.ERROR_REVALIDATE_EVENT,ye)},{retryCount:(ke.retryCount||0)+1,dedupe:!0})))}return ve=!1,Ke(),!0},[m,n]),Ee=w.useCallback((...b)=>mi(n,v.current,...b),[]);if(tt(()=>{C.current=t,L.current=i,V(_)||($.current=_)}),tt(()=>{if(!m)return;const b=N.bind(Ae,vi);let I=0;const U=To(m,x,(ve,ke={})=>{if(ve==Ge.FOCUS_EVENT){const ne=Date.now();j().revalidateOnFocus&&ne>I&&G()&&(I=ne+j().focusThrottleInterval,b())}else if(ve==Ge.RECONNECT_EVENT)j().revalidateOnReconnect&&G()&&b();else{if(ve==Ge.MUTATE_EVENT)return N();if(ve==Ge.ERROR_REVALIDATE_EVENT)return N(ke)}});return k.current=!1,v.current=m,A.current=!0,re({_k:O}),M&&(V(z)||dt?b():mo(b)),()=>{k.current=!0,U()}},[m]),tt(()=>{let b;function I(){const U=ze(p)?p(Y().data):p;U&&b!==-1&&(b=setTimeout(Q,U))}function Q(){!Y().error&&(l||j().isVisible())&&(u||j().isOnline())?N(vi).then(I):I()}return I(),()=>{b&&(clearTimeout(b),b=-1)}},[p,l,u,m]),w.useDebugValue(K),o&&V(z)&&m){if(!Lt&&dt)throw new Error("Fallback data is required when using suspense in SSR.");C.current=t,L.current=i,k.current=!1;const b=E[m];if(!V(b)){const I=Ee(b);Oo(I)}if(V(q)){const I=N(vi);V(K)||(I.status="fulfilled",I.value=!0),Oo(I)}else throw q}return{mutate:Ee,get data(){return W.data=!0,K},get error(){return W.error=!0,q},get isValidating(){return W.isValidating=!0,H},get isLoading(){return W.isLoading=!0,J}}}),Co=Lt?e=>{e()}:w.startTransition,Ql=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 tt(()=>(i.current=!1,()=>{i.current=!0})),[n,r.current,o]},ep=Jl(Zl,()=>(e,t,i={})=>{const{mutate:n}=So(),r=w.useRef(e),o=w.useRef(t),a=w.useRef(i),s=w.useRef(0),[c,p,l]=Ql({data:Ae,error:Ae,isMutating:!1}),u=c.current,f=w.useCallback(async(h,g)=>{const[E,m]=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=Me(Me({populateCache:!1,throwOnError:!0},a.current),g),A=Et();s.current=A,l({isMutating:!0});try{const k=await n(E,o.current(m,{arg:h}),Me(O,{throwOnError:!0}));return s.current<=A&&(Co(()=>l({data:k,isMutating:!1,error:void 0})),O.onSuccess==null||O.onSuccess.call(O,k,E,O)),k}catch(k){if(s.current<=A&&(Co(()=>l({error:k,isMutating:!1})),O.onError==null||O.onError.call(O,k,E,O),O.throwOnError))throw k}},[]),x=w.useCallback(()=>{s.current=Et(),l({data:Ae,error:Ae,isMutating:!1})},[]);return tt(()=>{r.current=e,o.current=t,a.current=i}),{trigger:f,reset:x,get data(){return p.data=!0,u.data},get error(){return p.error=!0,u.error},get isMutating(){return p.isMutating=!0,u.isMutating}}}),tp=e=>ee.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",stroke:"currentColor",...e,children:[ee.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"}),ee.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"})]}),np=Oa({"0%":{transform:"rotate(0deg)"},"100%":{transform:"rotate(360deg)"}}),ip=Le(tp,{animation:`${np} 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"}}}}),rp=e=>ee.jsx("svg",{width:"15",height:"15",viewBox:"0 0 15 15",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e,children:ee.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"})}),op=({...e})=>ee.jsx("svg",{width:"15",height:"15",viewBox:"0 0 24 24",xmlns:"http://www.w3.orkllg/2000/svg",fill:"currentColor",...e,children:ee.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"})}),ap=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},_o=e=>e&&e.split("?")[0],sp=(e,t)=>_o(e)===_o(t),cp=()=>{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")}}},gi=w.createContext(null),Ao=e=>{var a;const t=w.useContext(gi),i=sp((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||ap(s))&&await t.setAudio(e),t.play()}}},lp=()=>w.useContext(gi),jo=({children:e})=>{const t=cp();return ee.jsx(gi.Provider,{value:t,children:e})},Do=(e,t,i)=>{const n=Ao(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}},qe=({limit:e,isTrue:t,children:i})=>{const n=[];return t!==!0?null:(Vo.Children.map(i,r=>{const{isTrue:o}=(r==null?void 0:r.props)||{};o===!0&&(!e||n.length<e)&&n.push(r)}),ee.jsx(ee.Fragment,{children:n}))};qe.defaultProps={limit:1,isTrue:!0},qe.If=({children:e,isTrue:t})=>e;const Fo=({children:e})=>e;Fo.defaultProps={isTrue:!0},qe.Else=Fo;const pp=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},up=Le("div",{"--progress":"-100%",height:"4px",width:"100%",background:"rgba(255, 255, 255, 0.1)",borderRadius:"12px",position:"relative",overflow:"hidden"}),dp=Le("div",{height:"100%",width:"100%",background:"#ffffff",transform:"translateX(var(--progress))",borderRadius:"12px"}),nt={Root:up,Bar:dp};function hn(e,t,i){for(let n=0;n<e.length;++n)t[i+n]=e.charCodeAt(n)}function yn(e,t,i){e=Math.floor(e),t[i+0]=e&255,t[i+1]=e>>8&255}function ft(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 fp(e){const t=new ArrayBuffer(4);return new Float32Array(t)[0]=e,new Uint32Array(t)[0]|0}function mp(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)),yn(p,t,i),i+=2;else if(n===32)p=fp(c[r]),ft(p,t,i),i+=4;else{console.log("Invalid bit depth for PCM encoding.");return}}async function xp(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 vp(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),x=16,h=p,g=4+(8+x)+(8+h);return hn("RIFF",f,0),ft(g,f,4),hn("WAVE",f,8),hn("fmt ",f,12),ft(x,f,16),yn(t?3:1,f,20),yn(n,f,22),ft(r,f,24),ft(s,f,28),yn(c,f,32),ft(o,f,34),hn("data",f,36),ft(h,f,40),mp(e,f,44,o),new Blob([f],{type:"audio/wave"})}async function gp(e,t=!1,i){const n=await xp(e,i);return vp(n,t)}const hp=128;class yp{constructor(){En(this,"mediaRecorder",null);En(this,"stream",null);En(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:hp*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 gp(this.__data):null}}const bn=new yp,hi="Recording.wav",Po=1500,bp=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()=>{bn.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 bn.stopRecording();const p=await bn.getWavBlob();if(!p){console.log("Failed to get audio blob",p);return}const l=new File([p],hi,{type:"audio/mpeg",lastModified:Date.now()});e.onFileUpdate(l);return}const c=await bn.startRecording();r(c),setTimeout(()=>{a(!0)},Po)}}},Io=_e.create({baseURL:"https://arpeggi.io/api/v2/"}),wp=async(e,{arg:t})=>(await Io.post("/ml-inference-jobs",pp({soundFile:t.file,type:"audio",voiceModelId:t.voiceModelId,metadata:{isRecordedAudio:t.file.name===hi}}),{params:{type:"audio"}})).data,Ep=async e=>e===null?null:(await Io.get(e)).data,Sp=e=>{const t=e>0;return Xl(t?`/ml-inference-jobs/${e}`:null,Ep,{refreshInterval:1e3})},Rp=()=>{const[e,t]=w.useState(null),[i,n]=w.useState(0),[r,o]=w.useState(0),{data:a,isLoading:s}=Sp(i),{trigger:c,isMutating:p}=ep("/ml-inference-jobs",wp);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:x=>{console.log("created mlij",x),n(x.id)}}))},reset:()=>{t(null),n(0),o(0)},isMutating:p}},Bo=w.createContext({}),wn=()=>w.useContext(Bo),Tp=({children:e})=>{const t=Rp();return ee.jsx(jo,{children:ee.jsx(Bo.Provider,{value:t,children:e})})},kp=Le("button",{background:"#ffffff",flexShrink:0,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"}}),Op=Le("div",{fontSize:"11px",lineHeight:"14px",fontFamily:'"General Sans Medium", "General Sans Medium Placeholder", sans-serif',color:"rgba(255, 255, 255, 0.5)",fontWeight:400}),Cp=e=>{var c;const{data:t,isMutating:i}=wn(),n=(c=t==null?void 0:t.lossyOutputFile)==null?void 0:c.url,{player:r,playPause:o}=Do(n),a=w.useRef(null),s=w.useRef();return w.useEffect(()=>{if(!r.isPlaying)return()=>{cancelAnimationFrame(s.current)};const p=()=>{var u;const l=r.audioRef.current.currentTime/r.audioRef.current.duration;(u=a.current)==null||u.style.setProperty("--progress",`${-100+l*100}%`),s.current=requestAnimationFrame(p)};return s.current=requestAnimationFrame(p),()=>{cancelAnimationFrame(s.current)}},[r.isPlaying,r.audioRef]),ee.jsxs(Qe,{row:!0,align:"center",flex:"1",gap:"16",...e,children:[ee.jsx(kp,{onClick:o,disabled:r.isLoading||!n,children:ee.jsxs(qe,{children:[ee.jsx(qe.If,{isTrue:r.isLoading||(t==null?void 0:t.jobStatus)==="running"||i,children:ee.jsx(ip,{})}),ee.jsx(qe.If,{isTrue:r.isPlaying,children:ee.jsx(rp,{})}),ee.jsx(qe.Else,{children:ee.jsx(op,{})})]})}),ee.jsxs(Qe,{flex:"1",column:!0,gap:"8",children:[ee.jsx(Op,{children:ee.jsxs(qe,{children:[ee.jsx(qe.If,{isTrue:(t==null?void 0:t.jobStatus)==="running",children:"Converting audio"}),ee.jsx(qe.If,{isTrue:i,children:"Uploading audio"}),ee.jsx(qe.Else,{children:"Converted audio"})]})}),ee.jsx(nt.Root,{ref:a,children:ee.jsx(nt.Bar,{})})]})]})},_p=30,Lo=e=>{const t=w.useRef(),i=w.useRef(null);return w.useEffect(()=>{let n=0;return t.current=setInterval(()=>{var o;n+=e;let r=Math.round(Math.atan(n)/(Math.PI/2)*100*1e3)/1e3;(o=i.current)==null||o.style.setProperty("--progress",`${-100+r}%`)},50),()=>clearInterval(t.current)},[]),i},Ap=()=>{const e=Lo(.1);return ee.jsx(nt.Root,{ref:e,children:ee.jsx(nt.Bar,{})})},jp=()=>ee.jsx(nt.Root,{children:ee.jsx(nt.Bar,{})}),Dp=()=>ee.jsx(nt.Root,{style:{"--progress":"0%"},children:ee.jsx(nt.Bar,{})}),Fp=()=>{const{data:e}=wn();return e?e.jobStatus==="success"?ee.jsx(Dp,{}):ee.jsx(Ap,{},e==null?void 0:e.id):ee.jsx(jp,{})},Pp=1,Ip=100*1024*1024,Bp=1,Lp=({children:e})=>{const{setFile:t}=wn(),i=n=>t(n[0]);return ee.jsx(Rr,{files:[],onFileAccepted:i,maxFileCount:Pp,maxSizeBytes:Ip,minSizeBytes:Bp,maxDurationS:_p,children:e})};me.AudioFilePickerRoot=Rr,me.ConvertStep=tc,me.FilePicker=Lp,me.GuestConvertProvider=Tp,me.InferenceProgress=Fp,me.MIN_RECORDING_LENGTH_MS=Po,me.PlayButton=Cp,me.PlayerProvider=jo,me.RECORDED_AUDIO_NAME=hi,me.useAudioFilePickerContext=Ys,me.useFakeProgress=Lo,me.useGuestConvertContext=wn,me.useMediaQuery=Ko,me.usePlayback=Do,me.usePlayer=Ao,me.usePlayerControls=lp,me.useRecorder=bp,Object.defineProperty(me,Symbol.toStringTag,{value:"Module"})});
69
+ */var po;function kl(){return po||(po=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(A){{for(var k=arguments.length,v=new Array(k>1?k-1:0),C=1;C<k;C++)v[C-1]=arguments[C];n("error",A,v)}}function n(A,k,v){{var C=t.ReactDebugCurrentFrame,L=C.getStackAddendum();L!==""&&(k+="%s",v=v.concat([L]));var j=v.map(function(G){return String(G)});j.unshift("Warning: "+k),Function.prototype.apply.call(console[A],console,j)}}function r(A,k){return A===k&&(A!==0||1/A===1/k)||A!==A&&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(A,k,v){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 C=k();if(!u){var L=k();o(C,L)||(i("The result of getSnapshot should be cached to avoid an infinite loop"),u=!0)}var j=a({inst:{value:C,getSnapshot:k}}),G=j[0].inst,Y=j[1];return c(function(){G.value=C,G.getSnapshot=k,x(G)&&Y({inst:G})},[A,C,k]),s(function(){x(G)&&Y({inst:G});var re=function(){x(G)&&Y({inst:G})};return A(re)},[A]),p(C),C}function x(A){var k=A.getSnapshot,v=A.value;try{var C=k();return!o(v,C)}catch{return!0}}function h(A,k,v){return k()}var g=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",E=!g,m=E?h:f,O=e.useSyncExternalStore!==void 0?e.useSyncExternalStore:m;ri.useSyncExternalStore=O,typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error)}()),ri}var uo;function Ol(){return uo||(uo=1,process.env.NODE_ENV==="production"?mn.exports=Tl():mn.exports=kl()),mn.exports}var fo=Ol();const et=()=>{},Ae=et(),oi=Object,V=e=>e===Ae,ze=e=>typeof e=="function",Me=(e,t)=>({...e,...t}),Cl=e=>ze(e.then),xn=new WeakMap;let _l=0;const Bt=e=>{const t=typeof e,i=e&&e.constructor,n=i==Date;let r,o;if(oi(e)===e&&!n&&i!=RegExp){if(r=xn.get(e),r)return r;if(r=++_l+"~",xn.set(e,r),i==Array){for(r="@",o=0;o<e.length;o++)r+=Bt(e[o])+",";xn.set(e,r)}if(i==oi){r="#";const a=oi.keys(e).sort();for(;!V(o=a.pop());)V(e[o])||(r+=o+":"+Bt(e[o])+",");xn.set(e,r)}}else r=n?e.toJSON():t=="symbol"?e.toString():t=="string"?JSON.stringify(e):""+e;return r},He=new WeakMap,ai={},vn={},si="undefined",gn=typeof window!=si,ci=typeof document!=si,Al=()=>gn&&typeof window.requestAnimationFrame!=si,li=(e,t)=>{const i=He.get(e);return[()=>!V(t)&&e.get(t)||ai,n=>{if(!V(t)){const r=e.get(t);t in vn||(vn[t]=r),i[5](t,Me(r,n),r||ai)}},i[6],()=>!V(t)&&t in vn?vn[t]:!V(t)&&e.get(t)||ai]};let pi=!0;const jl=()=>pi,[ui,di]=gn&&window.addEventListener?[window.addEventListener.bind(window),window.removeEventListener.bind(window)]:[et,et],Dl=()=>{const e=ci&&document.visibilityState;return V(e)||e!=="hidden"},Fl=e=>(ci&&document.addEventListener("visibilitychange",e),ui("focus",e),()=>{ci&&document.removeEventListener("visibilitychange",e),di("focus",e)}),Pl=e=>{const t=()=>{pi=!0,e()},i=()=>{pi=!1};return ui("online",t),ui("offline",i),()=>{di("online",t),di("offline",i)}},Il={isOnline:jl,isVisible:Dl},Bl={initFocus:Fl,initReconnect:Pl},Lt=!w.useId,dt=!gn||"Deno"in window,mo=e=>Al()?window.requestAnimationFrame(e):setTimeout(e,1),tt=dt?w.useEffect:w.useLayoutEffect,fi=typeof navigator<"u"&&navigator.connection,xo=!dt&&fi&&(["slow-2g","2g"].includes(fi.effectiveType)||fi.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)?Bt(e):"",[e,t]};let Ll=0;const Et=()=>++Ll,vo=0,go=1,ho=2;var Ge={__proto__:null,ERROR_REVALIDATE_EVENT:3,FOCUS_EVENT:vo,MUTATE_EVENT:ho,RECONNECT_EVENT:go};async function mi(...e){const[t,i,n,r]=e,o=Me({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,x=[],h=t.keys();for(const g of h)!/^\$(inf|sub)\$/.test(g)&&f(t.get(g)._k)&&x.push(g);return Promise.all(x.map(u))}return u(i);async function u(f){const[x]=zt(f);if(!x)return;const[h,g]=li(t,x),[E,m,O,A]=He.get(t),k=()=>{const Z=E[x];return(ze(o.revalidate)?o.revalidate(h().data,f):o.revalidate!==!1)&&(delete O[x],delete A[x],Z&&Z[0])?Z[0](ho).then(()=>h().data):h().data};if(e.length<3)return k();let v=n,C;const L=Et();m[x]=[L,0];const j=!V(c),G=h(),Y=G.data,re=G._c,oe=V(re)?Y:re;if(j&&(c=ze(c)?c(oe,Y):c,g({data:c,_c:oe})),ze(v))try{v=v(oe)}catch(Z){C=Z}if(v&&Cl(v))if(v=await v.catch(Z=>{C=Z}),L!==m[x][0]){if(C)throw C;return v}else C&&j&&p(C)&&(a=!0,g({data:oe,_c:Ae}));if(a&&!C)if(ze(a)){const Z=a(v,oe);g({data:Z,error:Ae,_c:Ae})}else g({data:v,error:Ae,_c:Ae});if(m[x][1]=Et(),Promise.resolve(k()).then(()=>{g({_c:Ae})}),C){if(l)throw C;return}return v}}const yo=(e,t)=>{for(const i in e)e[i][0]&&e[i][0](t)},zl=(e,t)=>{if(!He.has(e)){const i=Me(Bl,t),n={},r=mi.bind(Ae,e);let o=et;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 x=a[l];if(x)for(const h of x)h(u,f)},p=()=>{if(!He.has(e)&&(He.set(e,[n,{},{},{},r,c,s]),!dt)){const l=i.initFocus(setTimeout.bind(Ae,yo.bind(Ae,n,vo))),u=i.initReconnect(setTimeout.bind(Ae,yo.bind(Ae,n,go)));o=()=>{l&&l(),u&&u(),He.delete(e)}}};return p(),[e,r,p,o]}return[e,He.get(e)[4]]},Ml=(e,t,i,n,r)=>{const o=i.errorRetryCount,a=r.retryCount,s=~~((Math.random()+.5)*(1<<(a<8?a:8)))*i.errorRetryInterval;!V(o)&&a>o||setTimeout(n,s,r)},$l=(e,t)=>Bt(e)==Bt(t),[bo,Nl]=zl(new Map),ql=Me({onLoadingSlow:et,onSuccess:et,onError:et,onErrorRetry:Ml,onDiscarded:et,revalidateOnFocus:!0,revalidateOnReconnect:!0,revalidateIfStale:!0,shouldRetryOnError:!0,errorRetryInterval:xo?1e4:5e3,focusThrottleInterval:5*1e3,dedupingInterval:2*1e3,loadingTimeout:xo?5e3:3e3,compare:$l,isPaused:()=>!1,cache:bo,mutate:Nl,fallback:{}},Il),Wl=(e,t)=>{const i=Me(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=Me(r,a))}return i},Ul=w.createContext({}),Vl="$inf$",wo=gn&&window.__SWR_DEVTOOLS_USE__,Hl=wo?window.__SWR_DEVTOOLS_USE__:[],Gl=()=>{wo&&(window.__SWR_DEVTOOLS_REACT__=w)},Eo=e=>ze(e[1])?[e[0],e[1],e[2]||{}]:[e[0],null,(e[1]===null?e[2]:e[1])||{}],So=()=>Me(ql,w.useContext(Ul)),Yl=e=>(t,i,n)=>e(t,i&&((...o)=>{const[a]=zt(t),[,,,s]=He.get(bo);if(a.startsWith(Vl))return i(...o);const c=s[a];return V(c)?i(...o):(delete s[a],c)}),n),Kl=Hl.concat(Yl),Ro=e=>function(...i){const n=So(),[r,o,a]=Eo(i),s=Wl(n,a);let c=e;const{use:p}=s,l=(p||[]).concat(Kl);for(let u=l.length;u--;)c=l[u](c);return c(r,o||s.fetcher||null,s)},To=(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())}},Jl=(e,t)=>(...i)=>{const[n,r,o]=Eo(i),a=(o.use||[]).concat(t);return e(n,r,{...o,use:a})};Gl();const ko=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)}),xi={dedupe:!0},Xl=Ro((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,[x,h,g,E]=He.get(n),[m,O]=zt(e),A=w.useRef(!1),k=w.useRef(!1),v=w.useRef(m),C=w.useRef(t),L=w.useRef(i),j=()=>L.current,G=()=>j().isVisible()&&j().isOnline(),[Y,re,oe,Z]=li(n,m),W=w.useRef({}).current,le=V(a)?i.fallback[m]:a,xe=(b,I)=>{for(const Q in W){const U=Q;if(U==="data"){if(!r(b[U],I[U])&&(!V(b[U])||!r(K,I[U])))return!1}else if(I[U]!==b[U])return!1}return!0},we=w.useMemo(()=>{const b=!m||!t?!1:V(s)?j().isPaused()||o?!1:V(c)?!0:c:s,I=ie=>{const Re=Me(ie);return delete Re._k,b?{isValidating:!0,isLoading:!0,...Re}:Re},Q=Y(),U=Z(),ve=I(Q),ke=Q===U?ve:I(U);let ne=ve;return[()=>{const ie=I(Y());return xe(ie,ne)?(ne.data=ie.data,ne.isLoading=ie.isLoading,ne.isValidating=ie.isValidating,ne.error=ie.error,ne):(ne=ie,ie)},()=>ke]},[n,m]),ce=fo.useSyncExternalStore(w.useCallback(b=>oe(m,(I,Q)=>{xe(Q,I)||b()}),[n,m]),we[0],we[1]),he=!A.current,R=x[m]&&x[m].length>0,_=ce.data,z=V(_)?le:_,q=ce.error,$=w.useRef(z),K=f?V(_)?$.current:_:z,M=R&&!V(q)?!1:he&&!V(s)?s:j().isPaused()?!1:o?V(z)?!1:c:V(z)||c,P=!!(m&&t&&he&&M),H=V(ce.isValidating)?P:ce.isValidating,J=V(ce.isLoading)?P:ce.isLoading,N=w.useCallback(async b=>{const I=C.current;if(!m||!I||k.current||j().isPaused())return!1;let Q,U,ve=!0;const ke=b||{},ne=!g[m]||!ke.dedupe,ie=()=>Lt?!k.current&&m===v.current&&A.current:m===v.current,Re={isValidating:!1,isLoading:!1},Ke=()=>{re(Re)},We=()=>{const S=g[m];S&&S[1]===U&&delete g[m]},Je={isValidating:!0};V(Y().data)&&(Je.isLoading=!0);try{if(ne&&(re(Je),i.loadingTimeout&&V(Y().data)&&setTimeout(()=>{ve&&ie()&&j().onLoadingSlow(m,i)},i.loadingTimeout),g[m]=[I(O),Et()]),[Q,U]=g[m],Q=await Q,ne&&setTimeout(We,i.dedupingInterval),!g[m]||g[m][1]!==U)return ne&&ie()&&j().onDiscarded(m),!1;Re.error=Ae;const S=h[m];if(!V(S)&&(U<=S[0]||U<=S[1]||S[1]===0))return Ke(),ne&&ie()&&j().onDiscarded(m),!1;const D=Y().data;Re.data=r(D,Q)?D:Q,ne&&ie()&&j().onSuccess(Q,m,i)}catch(S){We();const D=j(),{shouldRetryOnError:pe}=D;D.isPaused()||(Re.error=S,ne&&ie()&&(D.onError(S,m,D),(pe===!0||ze(pe)&&pe(S))&&(!j().revalidateOnFocus||!j().revalidateOnReconnect||G())&&D.onErrorRetry(S,m,D,ye=>{const Oe=x[m];Oe&&Oe[0]&&Oe[0](Ge.ERROR_REVALIDATE_EVENT,ye)},{retryCount:(ke.retryCount||0)+1,dedupe:!0})))}return ve=!1,Ke(),!0},[m,n]),Ee=w.useCallback((...b)=>mi(n,v.current,...b),[]);if(tt(()=>{C.current=t,L.current=i,V(_)||($.current=_)}),tt(()=>{if(!m)return;const b=N.bind(Ae,xi);let I=0;const U=To(m,x,(ve,ke={})=>{if(ve==Ge.FOCUS_EVENT){const ne=Date.now();j().revalidateOnFocus&&ne>I&&G()&&(I=ne+j().focusThrottleInterval,b())}else if(ve==Ge.RECONNECT_EVENT)j().revalidateOnReconnect&&G()&&b();else{if(ve==Ge.MUTATE_EVENT)return N();if(ve==Ge.ERROR_REVALIDATE_EVENT)return N(ke)}});return k.current=!1,v.current=m,A.current=!0,re({_k:O}),M&&(V(z)||dt?b():mo(b)),()=>{k.current=!0,U()}},[m]),tt(()=>{let b;function I(){const U=ze(p)?p(Y().data):p;U&&b!==-1&&(b=setTimeout(Q,U))}function Q(){!Y().error&&(l||j().isVisible())&&(u||j().isOnline())?N(xi).then(I):I()}return I(),()=>{b&&(clearTimeout(b),b=-1)}},[p,l,u,m]),w.useDebugValue(K),o&&V(z)&&m){if(!Lt&&dt)throw new Error("Fallback data is required when using suspense in SSR.");C.current=t,L.current=i,k.current=!1;const b=E[m];if(!V(b)){const I=Ee(b);ko(I)}if(V(q)){const I=N(xi);V(K)||(I.status="fulfilled",I.value=!0),ko(I)}else throw q}return{mutate:Ee,get data(){return W.data=!0,K},get error(){return W.error=!0,q},get isValidating(){return W.isValidating=!0,H},get isLoading(){return W.isLoading=!0,J}}}),Oo=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)}),vi={dedupe:!0},Zl=Ro((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,[x,h,g,E]=He.get(n),[m,O]=zt(e),A=w.useRef(!1),k=w.useRef(!1),v=w.useRef(m),C=w.useRef(t),L=w.useRef(i),j=()=>L.current,G=()=>j().isVisible()&&j().isOnline(),[Y,re,oe,Z]=li(n,m),W=w.useRef({}).current,le=V(a)?i.fallback[m]:a,xe=(b,I)=>{for(const Q in W){const U=Q;if(U==="data"){if(!r(b[U],I[U])&&(!V(b[U])||!r(K,I[U])))return!1}else if(I[U]!==b[U])return!1}return!0},we=w.useMemo(()=>{const b=!m||!t?!1:V(s)?j().isPaused()||o?!1:V(c)?!0:c:s,I=ie=>{const Re=Me(ie);return delete Re._k,b?{isValidating:!0,isLoading:!0,...Re}:Re},Q=Y(),U=Z(),ve=I(Q),ke=Q===U?ve:I(U);let ne=ve;return[()=>{const ie=I(Y());return xe(ie,ne)?(ne.data=ie.data,ne.isLoading=ie.isLoading,ne.isValidating=ie.isValidating,ne.error=ie.error,ne):(ne=ie,ie)},()=>ke]},[n,m]),ce=fo.useSyncExternalStore(w.useCallback(b=>oe(m,(I,Q)=>{xe(Q,I)||b()}),[n,m]),we[0],we[1]),he=!A.current,R=x[m]&&x[m].length>0,_=ce.data,z=V(_)?le:_,q=ce.error,$=w.useRef(z),K=f?V(_)?$.current:_:z,M=R&&!V(q)?!1:he&&!V(s)?s:j().isPaused()?!1:o?V(z)?!1:c:V(z)||c,P=!!(m&&t&&he&&M),H=V(ce.isValidating)?P:ce.isValidating,J=V(ce.isLoading)?P:ce.isLoading,N=w.useCallback(async b=>{const I=C.current;if(!m||!I||k.current||j().isPaused())return!1;let Q,U,ve=!0;const ke=b||{},ne=!g[m]||!ke.dedupe,ie=()=>Lt?!k.current&&m===v.current&&A.current:m===v.current,Re={isValidating:!1,isLoading:!1},Ke=()=>{re(Re)},We=()=>{const S=g[m];S&&S[1]===U&&delete g[m]},Je={isValidating:!0};V(Y().data)&&(Je.isLoading=!0);try{if(ne&&(re(Je),i.loadingTimeout&&V(Y().data)&&setTimeout(()=>{ve&&ie()&&j().onLoadingSlow(m,i)},i.loadingTimeout),g[m]=[I(O),Et()]),[Q,U]=g[m],Q=await Q,ne&&setTimeout(We,i.dedupingInterval),!g[m]||g[m][1]!==U)return ne&&ie()&&j().onDiscarded(m),!1;Re.error=Ae;const S=h[m];if(!V(S)&&(U<=S[0]||U<=S[1]||S[1]===0))return Ke(),ne&&ie()&&j().onDiscarded(m),!1;const D=Y().data;Re.data=r(D,Q)?D:Q,ne&&ie()&&j().onSuccess(Q,m,i)}catch(S){We();const D=j(),{shouldRetryOnError:pe}=D;D.isPaused()||(Re.error=S,ne&&ie()&&(D.onError(S,m,D),(pe===!0||ze(pe)&&pe(S))&&(!j().revalidateOnFocus||!j().revalidateOnReconnect||G())&&D.onErrorRetry(S,m,D,ye=>{const Oe=x[m];Oe&&Oe[0]&&Oe[0](Ge.ERROR_REVALIDATE_EVENT,ye)},{retryCount:(ke.retryCount||0)+1,dedupe:!0})))}return ve=!1,Ke(),!0},[m,n]),Ee=w.useCallback((...b)=>mi(n,v.current,...b),[]);if(tt(()=>{C.current=t,L.current=i,V(_)||($.current=_)}),tt(()=>{if(!m)return;const b=N.bind(Ae,vi);let I=0;const U=To(m,x,(ve,ke={})=>{if(ve==Ge.FOCUS_EVENT){const ne=Date.now();j().revalidateOnFocus&&ne>I&&G()&&(I=ne+j().focusThrottleInterval,b())}else if(ve==Ge.RECONNECT_EVENT)j().revalidateOnReconnect&&G()&&b();else{if(ve==Ge.MUTATE_EVENT)return N();if(ve==Ge.ERROR_REVALIDATE_EVENT)return N(ke)}});return k.current=!1,v.current=m,A.current=!0,re({_k:O}),M&&(V(z)||dt?b():mo(b)),()=>{k.current=!0,U()}},[m]),tt(()=>{let b;function I(){const U=ze(p)?p(Y().data):p;U&&b!==-1&&(b=setTimeout(Q,U))}function Q(){!Y().error&&(l||j().isVisible())&&(u||j().isOnline())?N(vi).then(I):I()}return I(),()=>{b&&(clearTimeout(b),b=-1)}},[p,l,u,m]),w.useDebugValue(K),o&&V(z)&&m){if(!Lt&&dt)throw new Error("Fallback data is required when using suspense in SSR.");C.current=t,L.current=i,k.current=!1;const b=E[m];if(!V(b)){const I=Ee(b);Oo(I)}if(V(q)){const I=N(vi);V(K)||(I.status="fulfilled",I.value=!0),Oo(I)}else throw q}return{mutate:Ee,get data(){return W.data=!0,K},get error(){return W.error=!0,q},get isValidating(){return W.isValidating=!0,H},get isLoading(){return W.isLoading=!0,J}}}),Co=Lt?e=>{e()}:w.startTransition,Ql=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 tt(()=>(i.current=!1,()=>{i.current=!0})),[n,r.current,o]},ep=Jl(Zl,()=>(e,t,i={})=>{const{mutate:n}=So(),r=w.useRef(e),o=w.useRef(t),a=w.useRef(i),s=w.useRef(0),[c,p,l]=Ql({data:Ae,error:Ae,isMutating:!1}),u=c.current,f=w.useCallback(async(h,g)=>{const[E,m]=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=Me(Me({populateCache:!1,throwOnError:!0},a.current),g),A=Et();s.current=A,l({isMutating:!0});try{const k=await n(E,o.current(m,{arg:h}),Me(O,{throwOnError:!0}));return s.current<=A&&(Co(()=>l({data:k,isMutating:!1,error:void 0})),O.onSuccess==null||O.onSuccess.call(O,k,E,O)),k}catch(k){if(s.current<=A&&(Co(()=>l({error:k,isMutating:!1})),O.onError==null||O.onError.call(O,k,E,O),O.throwOnError))throw k}},[]),x=w.useCallback(()=>{s.current=Et(),l({data:Ae,error:Ae,isMutating:!1})},[]);return tt(()=>{r.current=e,o.current=t,a.current=i}),{trigger:f,reset:x,get data(){return p.data=!0,u.data},get error(){return p.error=!0,u.error},get isMutating(){return p.isMutating=!0,u.isMutating}}}),tp=e=>ee.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",stroke:"currentColor",...e,children:[ee.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"}),ee.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"})]}),np=Oa({"0%":{transform:"rotate(0deg)"},"100%":{transform:"rotate(360deg)"}}),ip=Le(tp,{animation:`${np} 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"}}}}),rp=e=>ee.jsx("svg",{width:"15",height:"15",viewBox:"0 0 15 15",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e,children:ee.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"})}),op=({...e})=>ee.jsx("svg",{width:"15",height:"15",viewBox:"0 0 24 24",xmlns:"http://www.w3.orkllg/2000/svg",fill:"currentColor",...e,children:ee.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"})}),ap=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},_o=e=>e&&e.split("?")[0],sp=(e,t)=>_o(e)===_o(t),cp=()=>{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")}}},gi=w.createContext(null),Ao=e=>{var a;const t=w.useContext(gi),i=sp((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||ap(s))&&await t.setAudio(e),t.play()}}},lp=()=>w.useContext(gi),jo=({children:e})=>{const t=cp();return ee.jsx(gi.Provider,{value:t,children:e})},Do=(e,t,i)=>{const n=Ao(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}},qe=({limit:e,isTrue:t,children:i})=>{const n=[];return t!==!0?null:(Vo.Children.map(i,r=>{const{isTrue:o}=(r==null?void 0:r.props)||{};o===!0&&(!e||n.length<e)&&n.push(r)}),ee.jsx(ee.Fragment,{children:n}))};qe.defaultProps={limit:1,isTrue:!0},qe.If=({children:e,isTrue:t})=>e;const Fo=({children:e})=>e;Fo.defaultProps={isTrue:!0},qe.Else=Fo;const pp=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},up=Le("div",{"--progress":"-100%",height:"4px",width:"100%",background:"rgba(255, 255, 255, 0.1)",borderRadius:"12px",position:"relative",overflow:"hidden"}),dp=Le("div",{height:"100%",width:"100%",background:"#ffffff",transform:"translateX(var(--progress))",borderRadius:"12px"}),nt={Root:up,Bar:dp};function hn(e,t,i){for(let n=0;n<e.length;++n)t[i+n]=e.charCodeAt(n)}function yn(e,t,i){e=Math.floor(e),t[i+0]=e&255,t[i+1]=e>>8&255}function ft(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 fp(e){const t=new ArrayBuffer(4);return new Float32Array(t)[0]=e,new Uint32Array(t)[0]|0}function mp(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)),yn(p,t,i),i+=2;else if(n===32)p=fp(c[r]),ft(p,t,i),i+=4;else{console.log("Invalid bit depth for PCM encoding.");return}}async function xp(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 vp(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),x=16,h=p,g=4+(8+x)+(8+h);return hn("RIFF",f,0),ft(g,f,4),hn("WAVE",f,8),hn("fmt ",f,12),ft(x,f,16),yn(t?3:1,f,20),yn(n,f,22),ft(r,f,24),ft(s,f,28),yn(c,f,32),ft(o,f,34),hn("data",f,36),ft(h,f,40),mp(e,f,44,o),new Blob([f],{type:"audio/wave"})}async function gp(e,t=!1,i){const n=await xp(e,i);return vp(n,t)}const hp=128;class yp{constructor(){En(this,"mediaRecorder",null);En(this,"stream",null);En(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:hp*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 gp(this.__data):null}}const bn=new yp,hi="Recording.wav",Po=1500,bp=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()=>{bn.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 bn.stopRecording();const p=await bn.getWavBlob();if(!p){console.log("Failed to get audio blob",p);return}const l=new File([p],hi,{type:"audio/mpeg",lastModified:Date.now()});e.onFileUpdate(l);return}const c=await bn.startRecording();r(c),setTimeout(()=>{a(!0)},Po)}}},Io=_e.create({baseURL:"https://arpeggi.io/api/v2/"}),wp=async(e,{arg:t})=>(await Io.post("/ml-inference-jobs",pp({soundFile:t.file,type:"audio",voiceModelId:t.voiceModelId,metadata:{isRecordedAudio:t.file.name===hi}}),{params:{type:"audio"}})).data,Ep=async e=>e===null?null:(await Io.get(e)).data,Sp=e=>{const t=e>0;return Xl(t?`/ml-inference-jobs/${e}`:null,Ep,{refreshInterval:1e3})},Rp=()=>{const[e,t]=w.useState(null),[i,n]=w.useState(0),[r,o]=w.useState(0),{data:a,isLoading:s}=Sp(i),{trigger:c,isMutating:p}=ep("/ml-inference-jobs",wp);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:x=>{console.log("created mlij",x),n(x.id)}}))},reset:()=>{t(null),n(0),o(0)},isMutating:p}},Bo=w.createContext({}),wn=()=>w.useContext(Bo),Tp=({children:e})=>{const t=Rp();return ee.jsx(jo,{children:ee.jsx(Bo.Provider,{value:t,children:e})})},kp=Le("button",{background:"#ffffff",flexShrink:0,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"}}),Op=Le("div",{fontSize:"11px",lineHeight:"14px",fontFamily:'"General Sans Medium", "General Sans Medium Placeholder", sans-serif',color:"#ffffff",letterSpacing:"2.2px",fontWeight:400}),Cp=e=>{var c;const{data:t,isMutating:i}=wn(),n=(c=t==null?void 0:t.lossyOutputFile)==null?void 0:c.url,{player:r,playPause:o}=Do(n),a=w.useRef(null),s=w.useRef();return w.useEffect(()=>{if(!r.isPlaying)return()=>{cancelAnimationFrame(s.current)};const p=()=>{var u;const l=r.audioRef.current.currentTime/r.audioRef.current.duration;(u=a.current)==null||u.style.setProperty("--progress",`${-100+l*100}%`),s.current=requestAnimationFrame(p)};return s.current=requestAnimationFrame(p),()=>{cancelAnimationFrame(s.current)}},[r.isPlaying,r.audioRef]),ee.jsxs(Qe,{row:!0,align:"center",flex:"1",gap:"16",...e,children:[ee.jsx(kp,{onClick:o,disabled:r.isLoading||!n,children:ee.jsxs(qe,{children:[ee.jsx(qe.If,{isTrue:r.isLoading||(t==null?void 0:t.jobStatus)==="running"||i,children:ee.jsx(ip,{})}),ee.jsx(qe.If,{isTrue:r.isPlaying,children:ee.jsx(rp,{})}),ee.jsx(qe.Else,{children:ee.jsx(op,{})})]})}),ee.jsxs(Qe,{flex:"1",column:!0,gap:"12",children:[ee.jsx(Op,{children:ee.jsxs(qe,{children:[ee.jsx(qe.If,{isTrue:(t==null?void 0:t.jobStatus)==="running",children:"Converting audio"}),ee.jsx(qe.If,{isTrue:i,children:"Uploading audio"}),ee.jsx(qe.Else,{children:"Converted audio"})]})}),ee.jsx(nt.Root,{ref:a,children:ee.jsx(nt.Bar,{})})]})]})},_p=30,Lo=e=>{const t=w.useRef(),i=w.useRef(null);return w.useEffect(()=>{let n=0;return t.current=setInterval(()=>{var o;n+=e;let r=Math.round(Math.atan(n)/(Math.PI/2)*100*1e3)/1e3;(o=i.current)==null||o.style.setProperty("--progress",`${-100+r}%`)},50),()=>clearInterval(t.current)},[]),i},Ap=()=>{const e=Lo(.1);return ee.jsx(nt.Root,{ref:e,children:ee.jsx(nt.Bar,{})})},jp=()=>ee.jsx(nt.Root,{children:ee.jsx(nt.Bar,{})}),Dp=()=>ee.jsx(nt.Root,{style:{"--progress":"0%"},children:ee.jsx(nt.Bar,{})}),Fp=()=>{const{data:e}=wn();return e?e.jobStatus==="success"?ee.jsx(Dp,{}):ee.jsx(Ap,{},e==null?void 0:e.id):ee.jsx(jp,{})},Pp=1,Ip=100*1024*1024,Bp=1,Lp=({children:e})=>{const{setFile:t}=wn(),i=n=>t(n[0]);return ee.jsx(Rr,{files:[],onFileAccepted:i,maxFileCount:Pp,maxSizeBytes:Ip,minSizeBytes:Bp,maxDurationS:_p,children:e})};me.AudioFilePickerRoot=Rr,me.ConvertStep=tc,me.FilePicker=Lp,me.GuestConvertProvider=Tp,me.InferenceProgress=Fp,me.MIN_RECORDING_LENGTH_MS=Po,me.PlayButton=Cp,me.PlayerProvider=jo,me.RECORDED_AUDIO_NAME=hi,me.useAudioFilePickerContext=Ys,me.useFakeProgress=Lo,me.useGuestConvertContext=wn,me.useMediaQuery=Ko,me.usePlayback=Do,me.usePlayer=Ao,me.usePlayerControls=lp,me.useRecorder=bp,Object.defineProperty(me,Symbol.toStringTag,{value:"Module"})});
70
70
  //# sourceMappingURL=index.umd.js.map