arpeggi-framer-components 0.0.12 → 0.0.13
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.es.js +6 -1
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
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 ta;function ul(){return ta||(ta=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,b=new Array(k>1?k-1:0),j=1;j<k;j++)b[j-1]=arguments[j];n("error",A,b)}}function n(A,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[A],console,F)}}function r(A,k){return A===k&&(A!==0||1/A===1/k)||A!==A&&k!==k}var a=typeof Object.is=="function"?Object.is:r,o=e.useState,s=e.useEffect,c=e.useLayoutEffect,p=e.useDebugValue,l=!1,u=!1;function f(A,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();a(j,q)||(i("The result of getSnapshot should be cached to avoid an infinite loop"),u=!0)}var F=o({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})},[A,j,k]),s(function(){m(Y)&&H({inst:Y});var ae=function(){m(Y)&&H({inst:Y})};return A(ae)},[A]),p(j),j}function m(A){var k=A.getSnapshot,b=A.value;try{var j=k();return!a(b,j)}catch{return!0}}function v(A,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;Qn.useSyncExternalStore=O,typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error)}()),Qn}var na;function dl(){return na||(na=1,process.env.NODE_ENV==="production"?un.exports=pl():un.exports=ul()),un.exports}var ia=dl();const Je=()=>{},Ae=Je(),ei=Object,N=e=>e===Ae,Be=e=>typeof e=="function",ze=(e,t)=>({...e,...t}),fl=e=>Be(e.then),dn=new WeakMap;let ml=0;const Pt=e=>{const t=typeof e,i=e&&e.constructor,n=i==Date;let r,a;if(ei(e)===e&&!n&&i!=RegExp){if(r=dn.get(e),r)return r;if(r=++ml+"~",dn.set(e,r),i==Array){for(r="@",a=0;a<e.length;a++)r+=Pt(e[a])+",";dn.set(e,r)}if(i==ei){r="#";const o=ei.keys(e).sort();for(;!N(a=o.pop());)N(e[a])||(r+=a+":"+Pt(e[a])+",");dn.set(e,r)}}else r=n?e.toJSON():t=="symbol"?e.toString():t=="string"?JSON.stringify(e):""+e;return r},Ue=new WeakMap,ti={},fn={},ni="undefined",mn=typeof window!=ni,ii=typeof document!=ni,xl=()=>mn&&typeof window.requestAnimationFrame!=ni,ri=(e,t)=>{const i=Ue.get(e);return[()=>!N(t)&&e.get(t)||ti,n=>{if(!N(t)){const r=e.get(t);t in fn||(fn[t]=r),i[5](t,ze(r,n),r||ti)}},i[6],()=>!N(t)&&t in fn?fn[t]:!N(t)&&e.get(t)||ti]};let ai=!0;const vl=()=>ai,[oi,si]=mn&&window.addEventListener?[window.addEventListener.bind(window),window.removeEventListener.bind(window)]:[Je,Je],gl=()=>{const e=ii&&document.visibilityState;return N(e)||e!=="hidden"},hl=e=>(ii&&document.addEventListener("visibilitychange",e),oi("focus",e),()=>{ii&&document.removeEventListener("visibilitychange",e),si("focus",e)}),yl=e=>{const t=()=>{ai=!0,e()},i=()=>{ai=!1};return oi("online",t),oi("offline",i),()=>{si("online",t),si("offline",i)}},bl={isOnline:vl,isVisible:gl},wl={initFocus:hl,initReconnect:yl},It=!w.useId,pt=!mn||"Deno"in window,ra=e=>xl()?window.requestAnimationFrame(e):setTimeout(e,1),Xe=pt?w.useEffect:w.useLayoutEffect,ci=typeof navigator<"u"&&navigator.connection,aa=!pt&&ci&&(["slow-2g","2g"].includes(ci.effectiveType)||ci.saveData),Bt=e=>{if(Be(e))try{e=e()}catch{e=""}const t=e;return e=typeof e=="string"?e:(Array.isArray(e)?e.length:e)?Pt(e):"",[e,t]};let El=0;const bt=()=>++El,oa=0,sa=1,ca=2;var We={__proto__:null,ERROR_REVALIDATE_EVENT:3,FOCUS_EVENT:oa,MUTATE_EVENT:ca,RECONNECT_EVENT:sa};async function li(...e){const[t,i,n,r]=e,a=ze({populateCache:!0,throwOnError:!0},typeof r=="boolean"?{revalidate:r}:r||{});let o=a.populateCache;const s=a.rollbackOnError;let c=a.optimisticData;const p=f=>typeof s=="function"?s(f):s!==!1,l=a.throwOnError;if(Be(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]=Bt(f);if(!m)return;const[v,g]=ri(t,m),[E,x,O,A]=Ue.get(t),k=()=>{const ne=E[m];return(Be(a.revalidate)?a.revalidate(v().data,f):a.revalidate!==!1)&&(delete O[m],delete A[m],ne&&ne[0])?ne[0](ca).then(()=>v().data):v().data};if(e.length<3)return k();let b=n,j;const q=bt();x[m]=[q,0];const F=!N(c),Y=v(),H=Y.data,ae=Y._c,ve=N(ae)?H:ae;if(F&&(c=Be(c)?c(ve,H):c,g({data:c,_c:ve})),Be(b))try{b=b(ve)}catch(ne){j=ne}if(b&&fl(b))if(b=await b.catch(ne=>{j=ne}),q!==x[m][0]){if(j)throw j;return b}else j&&F&&p(j)&&(o=!0,g({data:ve,_c:Ae}));if(o&&!j)if(Be(o)){const ne=o(b,ve);g({data:ne,error:Ae,_c:Ae})}else g({data:b,error:Ae,_c:Ae});if(x[m][1]=bt(),Promise.resolve(k()).then(()=>{g({_c:Ae})}),j){if(l)throw j;return}return b}}const la=(e,t)=>{for(const i in e)e[i][0]&&e[i][0](t)},Sl=(e,t)=>{if(!Ue.has(e)){const i=ze(wl,t),n={},r=li.bind(Ae,e);let a=Je;const o={},s=(l,u)=>{const f=o[l]||[];return o[l]=f,f.push(u),()=>f.splice(f.indexOf(u),1)},c=(l,u,f)=>{e.set(l,u);const m=o[l];if(m)for(const v of m)v(u,f)},p=()=>{if(!Ue.has(e)&&(Ue.set(e,[n,{},{},{},r,c,s]),!pt)){const l=i.initFocus(setTimeout.bind(Ae,la.bind(Ae,n,oa))),u=i.initReconnect(setTimeout.bind(Ae,la.bind(Ae,n,sa)));a=()=>{l&&l(),u&&u(),Ue.delete(e)}}};return p(),[e,r,p,a]}return[e,Ue.get(e)[4]]},Rl=(e,t,i,n,r)=>{const a=i.errorRetryCount,o=r.retryCount,s=~~((Math.random()+.5)*(1<<(o<8?o:8)))*i.errorRetryInterval;!N(a)&&o>a||setTimeout(n,s,r)},Tl=(e,t)=>Pt(e)==Pt(t),[pa,kl]=Sl(new Map),Ol=ze({onLoadingSlow:Je,onSuccess:Je,onError:Je,onErrorRetry:Rl,onDiscarded:Je,revalidateOnFocus:!0,revalidateOnReconnect:!0,revalidateIfStale:!0,shouldRetryOnError:!0,errorRetryInterval:aa?1e4:5e3,focusThrottleInterval:5*1e3,dedupingInterval:2*1e3,loadingTimeout:aa?5e3:3e3,compare:Tl,isPaused:()=>!1,cache:pa,mutate:kl,fallback:{}},bl),_l=(e,t)=>{const i=ze(e,t);if(t){const{use:n,fallback:r}=e,{use:a,fallback:o}=t;n&&a&&(i.use=n.concat(a)),r&&o&&(i.fallback=ze(r,o))}return i},Al=w.createContext({}),Cl="$inf$",ua=mn&&window.__SWR_DEVTOOLS_USE__,Dl=ua?window.__SWR_DEVTOOLS_USE__:[],jl=()=>{ua&&(window.__SWR_DEVTOOLS_REACT__=w)},da=e=>Be(e[1])?[e[0],e[1],e[2]||{}]:[e[0],null,(e[1]===null?e[2]:e[1])||{}],fa=()=>ze(Ol,w.useContext(Al)),Fl=e=>(t,i,n)=>e(t,i&&((...a)=>{const[o]=Bt(t),[,,,s]=Ue.get(pa);if(o.startsWith(Cl))return i(...a);const c=s[o];return N(c)?i(...a):(delete s[o],c)}),n),Pl=Dl.concat(Fl),ma=e=>function(...i){const n=fa(),[r,a,o]=da(i),s=_l(n,o);let c=e;const{use:p}=s,l=(p||[]).concat(Pl);for(let u=l.length;u--;)c=l[u](c);return c(r,a||s.fetcher||null,s)},xa=(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())}},Il=(e,t)=>(...i)=>{const[n,r,a]=da(i),o=(a.use||[]).concat(t);return e(n,r,{...a,use:o})};jl();const va=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)}),pi={dedupe:!0},Bl=ma((e,t,i)=>{const{cache:n,compare:r,suspense:a,fallbackData:o,revalidateOnMount:s,revalidateIfStale:c,refreshInterval:p,refreshWhenHidden:l,refreshWhenOffline:u,keepPreviousData:f}=i,[m,v,g,E]=Ue.get(n),[x,O]=Bt(e),A=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,ae,ve,ne]=ri(n,x),V=w.useRef({}).current,pe=N(o)?i.fallback[x]:o,Se=(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},Re=w.useMemo(()=>{const y=!x||!t?!1:N(s)?F().isPaused()||a?!1:N(c)?!0:c:s,P=ee=>{const be=ze(ee);return delete be._k,y?{isValidating:!0,isLoading:!0,...be}:be},X=H(),$=ne(),de=P(X),Te=X===$?de:P($);let Q=de;return[()=>{const ee=P(H());return Se(ee,Q)?(Q.data=ee.data,Q.isLoading=ee.isLoading,Q.isValidating=ee.isValidating,Q.error=ee.error,Q):(Q=ee,ee)},()=>Te]},[n,x]),ue=ia.useSyncExternalStore(w.useCallback(y=>ve(x,(P,X)=>{Se(X,P)||y()}),[n,x]),Re[0],Re[1]),ye=!A.current,R=m[x]&&m[x].length>0,_=ue.data,B=N(_)?pe:_,U=ue.error,z=w.useRef(B),G=f?N(_)?z.current:_:B,L=R&&!N(U)?!1:ye&&!N(s)?s:F().isPaused()?!1:a?N(B)?!1:c:N(B)||c,W=!!(x&&t&&ye&&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 Te=y||{},Q=!g[x]||!Te.dedupe,ee=()=>It?!k.current&&x===b.current&&A.current:x===b.current,be={isValidating:!1,isLoading:!1},He=()=>{ae(be)},$e=()=>{const S=g[x];S&&S[1]===$&&delete g[x]},Ge={isValidating:!0};N(H().data)&&(Ge.isLoading=!0);try{if(Q&&(ae(Ge),i.loadingTimeout&&N(H().data)&&setTimeout(()=>{de&&ee()&&F().onLoadingSlow(x,i)},i.loadingTimeout),g[x]=[P(O),bt()]),[X,$]=g[x],X=await X,Q&&setTimeout($e,i.dedupingInterval),!g[x]||g[x][1]!==$)return Q&&ee()&&F().onDiscarded(x),!1;be.error=Ae;const S=v[x];if(!N(S)&&($<=S[0]||$<=S[1]||S[1]===0))return He(),Q&&ee()&&F().onDiscarded(x),!1;const C=H().data;be.data=r(C,X)?C:X,Q&&ee()&&F().onSuccess(X,x,i)}catch(S){$e();const C=F(),{shouldRetryOnError:oe}=C;C.isPaused()||(be.error=S,Q&&ee()&&(C.onError(S,x,C),(oe===!0||Be(oe)&&oe(S))&&(!F().revalidateOnFocus||!F().revalidateOnReconnect||Y())&&C.onErrorRetry(S,x,C,me=>{const ke=m[x];ke&&ke[0]&&ke[0](We.ERROR_REVALIDATE_EVENT,me)},{retryCount:(Te.retryCount||0)+1,dedupe:!0})))}return de=!1,He(),!0},[x,n]),ge=w.useCallback((...y)=>li(n,b.current,...y),[]);if(Xe(()=>{j.current=t,q.current=i,N(_)||(z.current=_)}),Xe(()=>{if(!x)return;const y=M.bind(Ae,pi);let P=0;const $=xa(x,m,(de,Te={})=>{if(de==We.FOCUS_EVENT){const Q=Date.now();F().revalidateOnFocus&&Q>P&&Y()&&(P=Q+F().focusThrottleInterval,y())}else if(de==We.RECONNECT_EVENT)F().revalidateOnReconnect&&Y()&&y();else{if(de==We.MUTATE_EVENT)return M();if(de==We.ERROR_REVALIDATE_EVENT)return M(Te)}});return k.current=!1,b.current=x,A.current=!0,ae({_k:O}),L&&(N(B)||pt?y():ra(y)),()=>{k.current=!0,$()}},[x]),Xe(()=>{let y;function P(){const $=Be(p)?p(H().data):p;$&&y!==-1&&(y=setTimeout(X,$))}function X(){!H().error&&(l||F().isVisible())&&(u||F().isOnline())?M(pi).then(P):P()}return P(),()=>{y&&(clearTimeout(y),y=-1)}},[p,l,u,x]),w.useDebugValue(G),a&&N(B)&&x){if(!It&&pt)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=ge(y);va(P)}if(N(U)){const P=M(pi);N(G)||(P.status="fulfilled",P.value=!0),va(P)}else throw U}return{mutate:ge,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}}}),ga=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)}),ui={dedupe:!0},zl=ma((e,t,i)=>{const{cache:n,compare:r,suspense:a,fallbackData:o,revalidateOnMount:s,revalidateIfStale:c,refreshInterval:p,refreshWhenHidden:l,refreshWhenOffline:u,keepPreviousData:f}=i,[m,v,g,E]=Ue.get(n),[x,O]=Bt(e),A=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,ae,ve,ne]=ri(n,x),V=w.useRef({}).current,pe=N(o)?i.fallback[x]:o,Se=(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},Re=w.useMemo(()=>{const y=!x||!t?!1:N(s)?F().isPaused()||a?!1:N(c)?!0:c:s,P=ee=>{const be=ze(ee);return delete be._k,y?{isValidating:!0,isLoading:!0,...be}:be},X=H(),$=ne(),de=P(X),Te=X===$?de:P($);let Q=de;return[()=>{const ee=P(H());return Se(ee,Q)?(Q.data=ee.data,Q.isLoading=ee.isLoading,Q.isValidating=ee.isValidating,Q.error=ee.error,Q):(Q=ee,ee)},()=>Te]},[n,x]),ue=ia.useSyncExternalStore(w.useCallback(y=>ve(x,(P,X)=>{Se(X,P)||y()}),[n,x]),Re[0],Re[1]),ye=!A.current,R=m[x]&&m[x].length>0,_=ue.data,B=N(_)?pe:_,U=ue.error,z=w.useRef(B),G=f?N(_)?z.current:_:B,L=R&&!N(U)?!1:ye&&!N(s)?s:F().isPaused()?!1:a?N(B)?!1:c:N(B)||c,W=!!(x&&t&&ye&&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 Te=y||{},Q=!g[x]||!Te.dedupe,ee=()=>It?!k.current&&x===b.current&&A.current:x===b.current,be={isValidating:!1,isLoading:!1},He=()=>{ae(be)},$e=()=>{const S=g[x];S&&S[1]===$&&delete g[x]},Ge={isValidating:!0};N(H().data)&&(Ge.isLoading=!0);try{if(Q&&(ae(Ge),i.loadingTimeout&&N(H().data)&&setTimeout(()=>{de&&ee()&&F().onLoadingSlow(x,i)},i.loadingTimeout),g[x]=[P(O),bt()]),[X,$]=g[x],X=await X,Q&&setTimeout($e,i.dedupingInterval),!g[x]||g[x][1]!==$)return Q&&ee()&&F().onDiscarded(x),!1;be.error=Ae;const S=v[x];if(!N(S)&&($<=S[0]||$<=S[1]||S[1]===0))return He(),Q&&ee()&&F().onDiscarded(x),!1;const C=H().data;be.data=r(C,X)?C:X,Q&&ee()&&F().onSuccess(X,x,i)}catch(S){$e();const C=F(),{shouldRetryOnError:oe}=C;C.isPaused()||(be.error=S,Q&&ee()&&(C.onError(S,x,C),(oe===!0||Be(oe)&&oe(S))&&(!F().revalidateOnFocus||!F().revalidateOnReconnect||Y())&&C.onErrorRetry(S,x,C,me=>{const ke=m[x];ke&&ke[0]&&ke[0](We.ERROR_REVALIDATE_EVENT,me)},{retryCount:(Te.retryCount||0)+1,dedupe:!0})))}return de=!1,He(),!0},[x,n]),ge=w.useCallback((...y)=>li(n,b.current,...y),[]);if(Xe(()=>{j.current=t,q.current=i,N(_)||(z.current=_)}),Xe(()=>{if(!x)return;const y=M.bind(Ae,ui);let P=0;const $=xa(x,m,(de,Te={})=>{if(de==We.FOCUS_EVENT){const Q=Date.now();F().revalidateOnFocus&&Q>P&&Y()&&(P=Q+F().focusThrottleInterval,y())}else if(de==We.RECONNECT_EVENT)F().revalidateOnReconnect&&Y()&&y();else{if(de==We.MUTATE_EVENT)return M();if(de==We.ERROR_REVALIDATE_EVENT)return M(Te)}});return k.current=!1,b.current=x,A.current=!0,ae({_k:O}),L&&(N(B)||pt?y():ra(y)),()=>{k.current=!0,$()}},[x]),Xe(()=>{let y;function P(){const $=Be(p)?p(H().data):p;$&&y!==-1&&(y=setTimeout(X,$))}function X(){!H().error&&(l||F().isVisible())&&(u||F().isOnline())?M(ui).then(P):P()}return P(),()=>{y&&(clearTimeout(y),y=-1)}},[p,l,u,x]),w.useDebugValue(G),a&&N(B)&&x){if(!It&&pt)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=ge(y);ga(P)}if(N(U)){const P=M(ui);N(G)||(P.status="fulfilled",P.value=!0),ga(P)}else throw U}return{mutate:ge,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}}}),ha=It?e=>{e()}:w.startTransition,Ll=e=>{const[,t]=w.useState({}),i=w.useRef(!1),n=w.useRef(e),r=w.useRef({data:!1,error:!1,isValidating:!1}),a=w.useCallback(o=>{let s=!1;const c=n.current;for(const p in o){const l=p;c[l]!==o[l]&&(c[l]=o[l],r.current[l]&&(s=!0))}s&&!i.current&&t({})},[]);return Xe(()=>(i.current=!1,()=>{i.current=!0})),[n,r.current,a]},Ml=Il(zl,()=>(e,t,i={})=>{const{mutate:n}=fa(),r=w.useRef(e),a=w.useRef(t),o=w.useRef(i),s=w.useRef(0),[c,p,l]=Ll({data:Ae,error:Ae,isMutating:!1}),u=c.current,f=w.useCallback(async(v,g)=>{const[E,x]=Bt(r.current);if(!a.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=ze(ze({populateCache:!1,throwOnError:!0},o.current),g),A=bt();s.current=A,l({isMutating:!0});try{const k=await n(E,a.current(x,{arg:v}),ze(O,{throwOnError:!0}));return s.current<=A&&(ha(()=>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&&(ha(()=>l({error:k,isMutating:!1})),O.onError==null||O.onError.call(O,k,E,O),O.throwOnError))throw k}},[]),m=w.useCallback(()=>{s.current=bt(),l({data:Ae,error:Ae,isMutating:!1})},[]);return Xe(()=>{r.current=e,a.current=t,o.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}}}),$l=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},ya=e=>e&&e.split("?")[0],Nl=(e,t)=>ya(e)===ya(t),ql=()=>{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")}}},di=w.createContext(null),ba=e=>{var o;const t=w.useContext(di),i=Nl((o=t.audioRef.current)==null?void 0:o.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||$l(s))&&await t.setAudio(e),t.play()}}},Ul=()=>w.useContext(di),wa=({children:e})=>{const t=ql();return et.jsx(di.Provider,{value:t,children:e})},Wl=(e,t,i)=>{const n=ba(e),r=w.useRef(!1),a=()=>{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:a}},Vl=e=>{const t=r=>typeof r=="object"&&!(r instanceof Date)&&!(r instanceof File)&&r!==null,i=(r,a,o)=>{for(const s in a){const c=a[s];t(c)?i(`${r}[${s}]`,c,o):c!==void 0&&o.append(`${r}[${s}]`,c===null?"":c)}},n=new FormData;for(const r in e){const a=e[r];a instanceof File?n.append(r,a,a.name):a!==void 0&&(t(a)?i(r,a,n):n.append(r,a===null?"":a))}return n};function xn(e,t,i){for(let n=0;n<e.length;++n)t[i+n]=e.charCodeAt(n)}function vn(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 Hl(e){const t=new ArrayBuffer(4);return new Float32Array(t)[0]=e,new Uint32Array(t)[0]|0}function Gl(e,t,i,n){let r=0,a=0;const o=e.length,s=e.numberOfChannels;let c,p;for(r=0;r<o;++r)for(a=0;a<s;++a)if(c=e.getChannelData(a),n===16)p=c[r]*32768,p=Math.max(-32768,Math.min(p,32767)),vn(p,t,i),i+=2;else if(n===32)p=Hl(c[r]),ut(p,t,i),i+=4;else{console.log("Invalid bit depth for PCM encoding.");return}}async function Yl(e,t){let i=e instanceof Blob?e:new Blob(e);const n=URL.createObjectURL(i),a=await(await fetch(n)).arrayBuffer();return await new AudioContext(t).decodeAudioData(a)}async function Kl(e,t=!1){const i=e.length,n=e.numberOfChannels,r=e.sampleRate,a=t?32:16,o=a/8,s=r*n*a/8,c=n*a/8,p=i*n*o,u=44+p,f=new Uint8Array(u),m=16,v=p,g=4+(8+m)+(8+v);return xn("RIFF",f,0),ut(g,f,4),xn("WAVE",f,8),xn("fmt ",f,12),ut(m,f,16),vn(t?3:1,f,20),vn(n,f,22),ut(r,f,24),ut(s,f,28),vn(c,f,32),ut(a,f,34),xn("data",f,36),ut(v,f,40),Gl(e,f,44,a),new Blob([f],{type:"audio/wave"})}async function Jl(e,t=!1,i){const n=await Yl(e,i);return Kl(n,t)}const Xl=128;class Zl{constructor(){hn(this,"mediaRecorder",null);hn(this,"stream",null);hn(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:Xl*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 Jl(this.__data):null}}const gn=new Zl,fi="Recording.wav",Ea=1500,Ql=e=>{const[t,i]=w.useState(!1),[n,r]=w.useState(!1),[a,o]=w.useState(!1);return w.useEffect(()=>{var p;const c=async()=>{gn.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:a,handleClick:async()=>{if(n){if(!a)return;r(!1),o(!1),await gn.stopRecording();const p=await gn.getWavBlob();if(!p){console.log("Failed to get audio blob",p);return}const l=new File([p],fi,{type:"audio/mpeg",lastModified:Date.now()});e.onFileUpdate(l);return}const c=await gn.startRecording();r(c),setTimeout(()=>{o(!0)},Ea)}}},Sa=_e.create({baseURL:"https://arpeggi.io/api/v2/"}),ep=async(e,{arg:t})=>(await Sa.post("/ml-inference-jobs",Vl({soundFile:t.file,type:"audio",voiceModelId:t.voiceModelId,metadata:{isRecordedAudio:t.file.name===fi}}))).data,tp=async e=>e===null?null:(await Sa.get(e)).data,np=e=>{const t=e>0;return Bl(t?`/ml-inference-jobs/${e}`:null,tp,{refreshInterval:1e3})},ip=()=>{const[e,t]=w.useState(null),[i,n]=w.useState(0),[r,a]=w.useState(0),{data:o,isLoading:s}=np(i),{trigger:c,isMutating:p}=Ml("/ml-inference-jobs",ep);return{file:e,setFile:t,mlijId:i,setMlijId:n,voiceModelId:r,setVoiceModelId:a,data:o,isLoading:s,handleSelectVoice:async f=>{e&&(a(f),c({file:e,voiceModelId:f},{onSuccess:m=>{console.log("created mlij",m),n(m.id)}}))},reset:()=>{t(null),n(0),a(0)},isMutating:p}},Ra=w.createContext({}),Ta=()=>w.useContext(Ra),rp=({children:e})=>{const t=ip();return et.jsx(wa,{children:et.jsx(Ra.Provider,{value:t,children:e})})},ap=1,op=100*1024*1024,sp=1,cp=100,lp=({children:e})=>{const{setFile:t}=Ta(),i=n=>t(n[0]);return et.jsx(xr,{files:[],onFileAccepted:i,maxFileCount:ap,maxSizeBytes:op,minSizeBytes:sp,maxDurationS:cp,children:e})};we.AudioFilePickerRoot=xr,we.ConvertStep=$s,we.FilePicker=lp,we.GuestConvertProvider=rp,we.MIN_RECORDING_LENGTH_MS=Ea,we.PlayerProvider=wa,we.RECORDED_AUDIO_NAME=fi,we.useAudioFilePickerContext=Fs,we.useGuestConvertContext=Ta,we.usePlayback=Wl,we.usePlayer=ba,we.usePlayerControls=Ul,we.useRecorder=Ql,Object.defineProperty(we,Symbol.toStringTag,{value:"Module"})});
|
69
|
+
*/var ta;function ul(){return ta||(ta=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,b=new Array(k>1?k-1:0),j=1;j<k;j++)b[j-1]=arguments[j];n("error",A,b)}}function n(A,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[A],console,F)}}function r(A,k){return A===k&&(A!==0||1/A===1/k)||A!==A&&k!==k}var a=typeof Object.is=="function"?Object.is:r,o=e.useState,s=e.useEffect,c=e.useLayoutEffect,p=e.useDebugValue,l=!1,u=!1;function f(A,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();a(j,q)||(i("The result of getSnapshot should be cached to avoid an infinite loop"),u=!0)}var F=o({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})},[A,j,k]),s(function(){m(Y)&&H({inst:Y});var ae=function(){m(Y)&&H({inst:Y})};return A(ae)},[A]),p(j),j}function m(A){var k=A.getSnapshot,b=A.value;try{var j=k();return!a(b,j)}catch{return!0}}function v(A,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;Qn.useSyncExternalStore=O,typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error)}()),Qn}var na;function dl(){return na||(na=1,process.env.NODE_ENV==="production"?un.exports=pl():un.exports=ul()),un.exports}var ia=dl();const Je=()=>{},Ae=Je(),ei=Object,N=e=>e===Ae,Be=e=>typeof e=="function",ze=(e,t)=>({...e,...t}),fl=e=>Be(e.then),dn=new WeakMap;let ml=0;const Pt=e=>{const t=typeof e,i=e&&e.constructor,n=i==Date;let r,a;if(ei(e)===e&&!n&&i!=RegExp){if(r=dn.get(e),r)return r;if(r=++ml+"~",dn.set(e,r),i==Array){for(r="@",a=0;a<e.length;a++)r+=Pt(e[a])+",";dn.set(e,r)}if(i==ei){r="#";const o=ei.keys(e).sort();for(;!N(a=o.pop());)N(e[a])||(r+=a+":"+Pt(e[a])+",");dn.set(e,r)}}else r=n?e.toJSON():t=="symbol"?e.toString():t=="string"?JSON.stringify(e):""+e;return r},Ue=new WeakMap,ti={},fn={},ni="undefined",mn=typeof window!=ni,ii=typeof document!=ni,xl=()=>mn&&typeof window.requestAnimationFrame!=ni,ri=(e,t)=>{const i=Ue.get(e);return[()=>!N(t)&&e.get(t)||ti,n=>{if(!N(t)){const r=e.get(t);t in fn||(fn[t]=r),i[5](t,ze(r,n),r||ti)}},i[6],()=>!N(t)&&t in fn?fn[t]:!N(t)&&e.get(t)||ti]};let ai=!0;const vl=()=>ai,[oi,si]=mn&&window.addEventListener?[window.addEventListener.bind(window),window.removeEventListener.bind(window)]:[Je,Je],gl=()=>{const e=ii&&document.visibilityState;return N(e)||e!=="hidden"},hl=e=>(ii&&document.addEventListener("visibilitychange",e),oi("focus",e),()=>{ii&&document.removeEventListener("visibilitychange",e),si("focus",e)}),yl=e=>{const t=()=>{ai=!0,e()},i=()=>{ai=!1};return oi("online",t),oi("offline",i),()=>{si("online",t),si("offline",i)}},bl={isOnline:vl,isVisible:gl},wl={initFocus:hl,initReconnect:yl},It=!w.useId,pt=!mn||"Deno"in window,ra=e=>xl()?window.requestAnimationFrame(e):setTimeout(e,1),Xe=pt?w.useEffect:w.useLayoutEffect,ci=typeof navigator<"u"&&navigator.connection,aa=!pt&&ci&&(["slow-2g","2g"].includes(ci.effectiveType)||ci.saveData),Bt=e=>{if(Be(e))try{e=e()}catch{e=""}const t=e;return e=typeof e=="string"?e:(Array.isArray(e)?e.length:e)?Pt(e):"",[e,t]};let El=0;const bt=()=>++El,oa=0,sa=1,ca=2;var We={__proto__:null,ERROR_REVALIDATE_EVENT:3,FOCUS_EVENT:oa,MUTATE_EVENT:ca,RECONNECT_EVENT:sa};async function li(...e){const[t,i,n,r]=e,a=ze({populateCache:!0,throwOnError:!0},typeof r=="boolean"?{revalidate:r}:r||{});let o=a.populateCache;const s=a.rollbackOnError;let c=a.optimisticData;const p=f=>typeof s=="function"?s(f):s!==!1,l=a.throwOnError;if(Be(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]=Bt(f);if(!m)return;const[v,g]=ri(t,m),[E,x,O,A]=Ue.get(t),k=()=>{const ne=E[m];return(Be(a.revalidate)?a.revalidate(v().data,f):a.revalidate!==!1)&&(delete O[m],delete A[m],ne&&ne[0])?ne[0](ca).then(()=>v().data):v().data};if(e.length<3)return k();let b=n,j;const q=bt();x[m]=[q,0];const F=!N(c),Y=v(),H=Y.data,ae=Y._c,ve=N(ae)?H:ae;if(F&&(c=Be(c)?c(ve,H):c,g({data:c,_c:ve})),Be(b))try{b=b(ve)}catch(ne){j=ne}if(b&&fl(b))if(b=await b.catch(ne=>{j=ne}),q!==x[m][0]){if(j)throw j;return b}else j&&F&&p(j)&&(o=!0,g({data:ve,_c:Ae}));if(o&&!j)if(Be(o)){const ne=o(b,ve);g({data:ne,error:Ae,_c:Ae})}else g({data:b,error:Ae,_c:Ae});if(x[m][1]=bt(),Promise.resolve(k()).then(()=>{g({_c:Ae})}),j){if(l)throw j;return}return b}}const la=(e,t)=>{for(const i in e)e[i][0]&&e[i][0](t)},Sl=(e,t)=>{if(!Ue.has(e)){const i=ze(wl,t),n={},r=li.bind(Ae,e);let a=Je;const o={},s=(l,u)=>{const f=o[l]||[];return o[l]=f,f.push(u),()=>f.splice(f.indexOf(u),1)},c=(l,u,f)=>{e.set(l,u);const m=o[l];if(m)for(const v of m)v(u,f)},p=()=>{if(!Ue.has(e)&&(Ue.set(e,[n,{},{},{},r,c,s]),!pt)){const l=i.initFocus(setTimeout.bind(Ae,la.bind(Ae,n,oa))),u=i.initReconnect(setTimeout.bind(Ae,la.bind(Ae,n,sa)));a=()=>{l&&l(),u&&u(),Ue.delete(e)}}};return p(),[e,r,p,a]}return[e,Ue.get(e)[4]]},Rl=(e,t,i,n,r)=>{const a=i.errorRetryCount,o=r.retryCount,s=~~((Math.random()+.5)*(1<<(o<8?o:8)))*i.errorRetryInterval;!N(a)&&o>a||setTimeout(n,s,r)},Tl=(e,t)=>Pt(e)==Pt(t),[pa,kl]=Sl(new Map),Ol=ze({onLoadingSlow:Je,onSuccess:Je,onError:Je,onErrorRetry:Rl,onDiscarded:Je,revalidateOnFocus:!0,revalidateOnReconnect:!0,revalidateIfStale:!0,shouldRetryOnError:!0,errorRetryInterval:aa?1e4:5e3,focusThrottleInterval:5*1e3,dedupingInterval:2*1e3,loadingTimeout:aa?5e3:3e3,compare:Tl,isPaused:()=>!1,cache:pa,mutate:kl,fallback:{}},bl),_l=(e,t)=>{const i=ze(e,t);if(t){const{use:n,fallback:r}=e,{use:a,fallback:o}=t;n&&a&&(i.use=n.concat(a)),r&&o&&(i.fallback=ze(r,o))}return i},Al=w.createContext({}),Cl="$inf$",ua=mn&&window.__SWR_DEVTOOLS_USE__,Dl=ua?window.__SWR_DEVTOOLS_USE__:[],jl=()=>{ua&&(window.__SWR_DEVTOOLS_REACT__=w)},da=e=>Be(e[1])?[e[0],e[1],e[2]||{}]:[e[0],null,(e[1]===null?e[2]:e[1])||{}],fa=()=>ze(Ol,w.useContext(Al)),Fl=e=>(t,i,n)=>e(t,i&&((...a)=>{const[o]=Bt(t),[,,,s]=Ue.get(pa);if(o.startsWith(Cl))return i(...a);const c=s[o];return N(c)?i(...a):(delete s[o],c)}),n),Pl=Dl.concat(Fl),ma=e=>function(...i){const n=fa(),[r,a,o]=da(i),s=_l(n,o);let c=e;const{use:p}=s,l=(p||[]).concat(Pl);for(let u=l.length;u--;)c=l[u](c);return c(r,a||s.fetcher||null,s)},xa=(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())}},Il=(e,t)=>(...i)=>{const[n,r,a]=da(i),o=(a.use||[]).concat(t);return e(n,r,{...a,use:o})};jl();const va=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)}),pi={dedupe:!0},Bl=ma((e,t,i)=>{const{cache:n,compare:r,suspense:a,fallbackData:o,revalidateOnMount:s,revalidateIfStale:c,refreshInterval:p,refreshWhenHidden:l,refreshWhenOffline:u,keepPreviousData:f}=i,[m,v,g,E]=Ue.get(n),[x,O]=Bt(e),A=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,ae,ve,ne]=ri(n,x),V=w.useRef({}).current,pe=N(o)?i.fallback[x]:o,Se=(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},Re=w.useMemo(()=>{const y=!x||!t?!1:N(s)?F().isPaused()||a?!1:N(c)?!0:c:s,P=ee=>{const be=ze(ee);return delete be._k,y?{isValidating:!0,isLoading:!0,...be}:be},X=H(),$=ne(),de=P(X),Te=X===$?de:P($);let Q=de;return[()=>{const ee=P(H());return Se(ee,Q)?(Q.data=ee.data,Q.isLoading=ee.isLoading,Q.isValidating=ee.isValidating,Q.error=ee.error,Q):(Q=ee,ee)},()=>Te]},[n,x]),ue=ia.useSyncExternalStore(w.useCallback(y=>ve(x,(P,X)=>{Se(X,P)||y()}),[n,x]),Re[0],Re[1]),ye=!A.current,R=m[x]&&m[x].length>0,_=ue.data,B=N(_)?pe:_,U=ue.error,z=w.useRef(B),G=f?N(_)?z.current:_:B,L=R&&!N(U)?!1:ye&&!N(s)?s:F().isPaused()?!1:a?N(B)?!1:c:N(B)||c,W=!!(x&&t&&ye&&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 Te=y||{},Q=!g[x]||!Te.dedupe,ee=()=>It?!k.current&&x===b.current&&A.current:x===b.current,be={isValidating:!1,isLoading:!1},He=()=>{ae(be)},$e=()=>{const S=g[x];S&&S[1]===$&&delete g[x]},Ge={isValidating:!0};N(H().data)&&(Ge.isLoading=!0);try{if(Q&&(ae(Ge),i.loadingTimeout&&N(H().data)&&setTimeout(()=>{de&&ee()&&F().onLoadingSlow(x,i)},i.loadingTimeout),g[x]=[P(O),bt()]),[X,$]=g[x],X=await X,Q&&setTimeout($e,i.dedupingInterval),!g[x]||g[x][1]!==$)return Q&&ee()&&F().onDiscarded(x),!1;be.error=Ae;const S=v[x];if(!N(S)&&($<=S[0]||$<=S[1]||S[1]===0))return He(),Q&&ee()&&F().onDiscarded(x),!1;const C=H().data;be.data=r(C,X)?C:X,Q&&ee()&&F().onSuccess(X,x,i)}catch(S){$e();const C=F(),{shouldRetryOnError:oe}=C;C.isPaused()||(be.error=S,Q&&ee()&&(C.onError(S,x,C),(oe===!0||Be(oe)&&oe(S))&&(!F().revalidateOnFocus||!F().revalidateOnReconnect||Y())&&C.onErrorRetry(S,x,C,me=>{const ke=m[x];ke&&ke[0]&&ke[0](We.ERROR_REVALIDATE_EVENT,me)},{retryCount:(Te.retryCount||0)+1,dedupe:!0})))}return de=!1,He(),!0},[x,n]),ge=w.useCallback((...y)=>li(n,b.current,...y),[]);if(Xe(()=>{j.current=t,q.current=i,N(_)||(z.current=_)}),Xe(()=>{if(!x)return;const y=M.bind(Ae,pi);let P=0;const $=xa(x,m,(de,Te={})=>{if(de==We.FOCUS_EVENT){const Q=Date.now();F().revalidateOnFocus&&Q>P&&Y()&&(P=Q+F().focusThrottleInterval,y())}else if(de==We.RECONNECT_EVENT)F().revalidateOnReconnect&&Y()&&y();else{if(de==We.MUTATE_EVENT)return M();if(de==We.ERROR_REVALIDATE_EVENT)return M(Te)}});return k.current=!1,b.current=x,A.current=!0,ae({_k:O}),L&&(N(B)||pt?y():ra(y)),()=>{k.current=!0,$()}},[x]),Xe(()=>{let y;function P(){const $=Be(p)?p(H().data):p;$&&y!==-1&&(y=setTimeout(X,$))}function X(){!H().error&&(l||F().isVisible())&&(u||F().isOnline())?M(pi).then(P):P()}return P(),()=>{y&&(clearTimeout(y),y=-1)}},[p,l,u,x]),w.useDebugValue(G),a&&N(B)&&x){if(!It&&pt)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=ge(y);va(P)}if(N(U)){const P=M(pi);N(G)||(P.status="fulfilled",P.value=!0),va(P)}else throw U}return{mutate:ge,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}}}),ga=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)}),ui={dedupe:!0},zl=ma((e,t,i)=>{const{cache:n,compare:r,suspense:a,fallbackData:o,revalidateOnMount:s,revalidateIfStale:c,refreshInterval:p,refreshWhenHidden:l,refreshWhenOffline:u,keepPreviousData:f}=i,[m,v,g,E]=Ue.get(n),[x,O]=Bt(e),A=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,ae,ve,ne]=ri(n,x),V=w.useRef({}).current,pe=N(o)?i.fallback[x]:o,Se=(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},Re=w.useMemo(()=>{const y=!x||!t?!1:N(s)?F().isPaused()||a?!1:N(c)?!0:c:s,P=ee=>{const be=ze(ee);return delete be._k,y?{isValidating:!0,isLoading:!0,...be}:be},X=H(),$=ne(),de=P(X),Te=X===$?de:P($);let Q=de;return[()=>{const ee=P(H());return Se(ee,Q)?(Q.data=ee.data,Q.isLoading=ee.isLoading,Q.isValidating=ee.isValidating,Q.error=ee.error,Q):(Q=ee,ee)},()=>Te]},[n,x]),ue=ia.useSyncExternalStore(w.useCallback(y=>ve(x,(P,X)=>{Se(X,P)||y()}),[n,x]),Re[0],Re[1]),ye=!A.current,R=m[x]&&m[x].length>0,_=ue.data,B=N(_)?pe:_,U=ue.error,z=w.useRef(B),G=f?N(_)?z.current:_:B,L=R&&!N(U)?!1:ye&&!N(s)?s:F().isPaused()?!1:a?N(B)?!1:c:N(B)||c,W=!!(x&&t&&ye&&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 Te=y||{},Q=!g[x]||!Te.dedupe,ee=()=>It?!k.current&&x===b.current&&A.current:x===b.current,be={isValidating:!1,isLoading:!1},He=()=>{ae(be)},$e=()=>{const S=g[x];S&&S[1]===$&&delete g[x]},Ge={isValidating:!0};N(H().data)&&(Ge.isLoading=!0);try{if(Q&&(ae(Ge),i.loadingTimeout&&N(H().data)&&setTimeout(()=>{de&&ee()&&F().onLoadingSlow(x,i)},i.loadingTimeout),g[x]=[P(O),bt()]),[X,$]=g[x],X=await X,Q&&setTimeout($e,i.dedupingInterval),!g[x]||g[x][1]!==$)return Q&&ee()&&F().onDiscarded(x),!1;be.error=Ae;const S=v[x];if(!N(S)&&($<=S[0]||$<=S[1]||S[1]===0))return He(),Q&&ee()&&F().onDiscarded(x),!1;const C=H().data;be.data=r(C,X)?C:X,Q&&ee()&&F().onSuccess(X,x,i)}catch(S){$e();const C=F(),{shouldRetryOnError:oe}=C;C.isPaused()||(be.error=S,Q&&ee()&&(C.onError(S,x,C),(oe===!0||Be(oe)&&oe(S))&&(!F().revalidateOnFocus||!F().revalidateOnReconnect||Y())&&C.onErrorRetry(S,x,C,me=>{const ke=m[x];ke&&ke[0]&&ke[0](We.ERROR_REVALIDATE_EVENT,me)},{retryCount:(Te.retryCount||0)+1,dedupe:!0})))}return de=!1,He(),!0},[x,n]),ge=w.useCallback((...y)=>li(n,b.current,...y),[]);if(Xe(()=>{j.current=t,q.current=i,N(_)||(z.current=_)}),Xe(()=>{if(!x)return;const y=M.bind(Ae,ui);let P=0;const $=xa(x,m,(de,Te={})=>{if(de==We.FOCUS_EVENT){const Q=Date.now();F().revalidateOnFocus&&Q>P&&Y()&&(P=Q+F().focusThrottleInterval,y())}else if(de==We.RECONNECT_EVENT)F().revalidateOnReconnect&&Y()&&y();else{if(de==We.MUTATE_EVENT)return M();if(de==We.ERROR_REVALIDATE_EVENT)return M(Te)}});return k.current=!1,b.current=x,A.current=!0,ae({_k:O}),L&&(N(B)||pt?y():ra(y)),()=>{k.current=!0,$()}},[x]),Xe(()=>{let y;function P(){const $=Be(p)?p(H().data):p;$&&y!==-1&&(y=setTimeout(X,$))}function X(){!H().error&&(l||F().isVisible())&&(u||F().isOnline())?M(ui).then(P):P()}return P(),()=>{y&&(clearTimeout(y),y=-1)}},[p,l,u,x]),w.useDebugValue(G),a&&N(B)&&x){if(!It&&pt)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=ge(y);ga(P)}if(N(U)){const P=M(ui);N(G)||(P.status="fulfilled",P.value=!0),ga(P)}else throw U}return{mutate:ge,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}}}),ha=It?e=>{e()}:w.startTransition,Ll=e=>{const[,t]=w.useState({}),i=w.useRef(!1),n=w.useRef(e),r=w.useRef({data:!1,error:!1,isValidating:!1}),a=w.useCallback(o=>{let s=!1;const c=n.current;for(const p in o){const l=p;c[l]!==o[l]&&(c[l]=o[l],r.current[l]&&(s=!0))}s&&!i.current&&t({})},[]);return Xe(()=>(i.current=!1,()=>{i.current=!0})),[n,r.current,a]},Ml=Il(zl,()=>(e,t,i={})=>{const{mutate:n}=fa(),r=w.useRef(e),a=w.useRef(t),o=w.useRef(i),s=w.useRef(0),[c,p,l]=Ll({data:Ae,error:Ae,isMutating:!1}),u=c.current,f=w.useCallback(async(v,g)=>{const[E,x]=Bt(r.current);if(!a.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=ze(ze({populateCache:!1,throwOnError:!0},o.current),g),A=bt();s.current=A,l({isMutating:!0});try{const k=await n(E,a.current(x,{arg:v}),ze(O,{throwOnError:!0}));return s.current<=A&&(ha(()=>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&&(ha(()=>l({error:k,isMutating:!1})),O.onError==null||O.onError.call(O,k,E,O),O.throwOnError))throw k}},[]),m=w.useCallback(()=>{s.current=bt(),l({data:Ae,error:Ae,isMutating:!1})},[]);return Xe(()=>{r.current=e,a.current=t,o.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}}}),$l=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},ya=e=>e&&e.split("?")[0],Nl=(e,t)=>ya(e)===ya(t),ql=()=>{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")}}},di=w.createContext(null),ba=e=>{var o;const t=w.useContext(di),i=Nl((o=t.audioRef.current)==null?void 0:o.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||$l(s))&&await t.setAudio(e),t.play()}}},Ul=()=>w.useContext(di),wa=({children:e})=>{const t=ql();return et.jsx(di.Provider,{value:t,children:e})},Wl=(e,t,i)=>{const n=ba(e),r=w.useRef(!1),a=()=>{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:a}},Vl=e=>{const t=r=>typeof r=="object"&&!(r instanceof Date)&&!(r instanceof File)&&r!==null,i=(r,a,o)=>{for(const s in a){const c=a[s];t(c)?i(`${r}[${s}]`,c,o):c!==void 0&&o.append(`${r}[${s}]`,c===null?"":c)}},n=new FormData;for(const r in e){const a=e[r];a instanceof File?n.append(r,a,a.name):a!==void 0&&(t(a)?i(r,a,n):n.append(r,a===null?"":a))}return n};function xn(e,t,i){for(let n=0;n<e.length;++n)t[i+n]=e.charCodeAt(n)}function vn(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 Hl(e){const t=new ArrayBuffer(4);return new Float32Array(t)[0]=e,new Uint32Array(t)[0]|0}function Gl(e,t,i,n){let r=0,a=0;const o=e.length,s=e.numberOfChannels;let c,p;for(r=0;r<o;++r)for(a=0;a<s;++a)if(c=e.getChannelData(a),n===16)p=c[r]*32768,p=Math.max(-32768,Math.min(p,32767)),vn(p,t,i),i+=2;else if(n===32)p=Hl(c[r]),ut(p,t,i),i+=4;else{console.log("Invalid bit depth for PCM encoding.");return}}async function Yl(e,t){let i=e instanceof Blob?e:new Blob(e);const n=URL.createObjectURL(i),a=await(await fetch(n)).arrayBuffer();return await new AudioContext(t).decodeAudioData(a)}async function Kl(e,t=!1){const i=e.length,n=e.numberOfChannels,r=e.sampleRate,a=t?32:16,o=a/8,s=r*n*a/8,c=n*a/8,p=i*n*o,u=44+p,f=new Uint8Array(u),m=16,v=p,g=4+(8+m)+(8+v);return xn("RIFF",f,0),ut(g,f,4),xn("WAVE",f,8),xn("fmt ",f,12),ut(m,f,16),vn(t?3:1,f,20),vn(n,f,22),ut(r,f,24),ut(s,f,28),vn(c,f,32),ut(a,f,34),xn("data",f,36),ut(v,f,40),Gl(e,f,44,a),new Blob([f],{type:"audio/wave"})}async function Jl(e,t=!1,i){const n=await Yl(e,i);return Kl(n,t)}const Xl=128;class Zl{constructor(){hn(this,"mediaRecorder",null);hn(this,"stream",null);hn(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:Xl*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 Jl(this.__data):null}}const gn=new Zl,fi="Recording.wav",Ea=1500,Ql=e=>{const[t,i]=w.useState(!1),[n,r]=w.useState(!1),[a,o]=w.useState(!1);return w.useEffect(()=>{var p;const c=async()=>{gn.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:a,handleClick:async()=>{if(n){if(!a)return;r(!1),o(!1),await gn.stopRecording();const p=await gn.getWavBlob();if(!p){console.log("Failed to get audio blob",p);return}const l=new File([p],fi,{type:"audio/mpeg",lastModified:Date.now()});e.onFileUpdate(l);return}const c=await gn.startRecording();r(c),setTimeout(()=>{o(!0)},Ea)}}},Sa=_e.create({baseURL:"https://arpeggi.io/api/v2/"}),ep=async(e,{arg:t})=>(await Sa.post("/ml-inference-jobs",Vl({soundFile:t.file,type:"audio",voiceModelId:t.voiceModelId,metadata:{isRecordedAudio:t.file.name===fi}}),{params:{type:"audio"}})).data,tp=async e=>e===null?null:(await Sa.get(e)).data,np=e=>{const t=e>0;return Bl(t?`/ml-inference-jobs/${e}`:null,tp,{refreshInterval:1e3})},ip=()=>{const[e,t]=w.useState(null),[i,n]=w.useState(0),[r,a]=w.useState(0),{data:o,isLoading:s}=np(i),{trigger:c,isMutating:p}=Ml("/ml-inference-jobs",ep);return{file:e,setFile:t,mlijId:i,setMlijId:n,voiceModelId:r,setVoiceModelId:a,data:o,isLoading:s,handleSelectVoice:async f=>{e&&(a(f),c({file:e,voiceModelId:f},{onSuccess:m=>{console.log("created mlij",m),n(m.id)}}))},reset:()=>{t(null),n(0),a(0)},isMutating:p}},Ra=w.createContext({}),Ta=()=>w.useContext(Ra),rp=({children:e})=>{const t=ip();return et.jsx(wa,{children:et.jsx(Ra.Provider,{value:t,children:e})})},ap=1,op=100*1024*1024,sp=1,cp=100,lp=({children:e})=>{const{setFile:t}=Ta(),i=n=>t(n[0]);return et.jsx(xr,{files:[],onFileAccepted:i,maxFileCount:ap,maxSizeBytes:op,minSizeBytes:sp,maxDurationS:cp,children:e})};we.AudioFilePickerRoot=xr,we.ConvertStep=$s,we.FilePicker=lp,we.GuestConvertProvider=rp,we.MIN_RECORDING_LENGTH_MS=Ea,we.PlayerProvider=wa,we.RECORDED_AUDIO_NAME=fi,we.useAudioFilePickerContext=Fs,we.useGuestConvertContext=Ta,we.usePlayback=Wl,we.usePlayer=ba,we.usePlayerControls=Ul,we.useRecorder=Ql,Object.defineProperty(we,Symbol.toStringTag,{value:"Module"})});
|
70
70
|
//# sourceMappingURL=index.umd.js.map
|