(function(A,u){typeof exports=="object"&&typeof module<"u"?u(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],u):(A=typeof globalThis<"u"?globalThis:A||self,u(A["re-audio"]={},A.React))})(this,function(A,u){"use strict";var ue={exports:{}},N={};/** * @license React * react-jsx-runtime.production.min.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */var xe;function ze(){if(xe)return N;xe=1;var a=u,p=Symbol.for("react.element"),g=Symbol.for("react.fragment"),f=Object.prototype.hasOwnProperty,C=a.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,_={key:!0,ref:!0,__self:!0,__source:!0};function O(k,h,d){var i,m={},T=null,j=null;d!==void 0&&(T=""+d),h.key!==void 0&&(T=""+h.key),h.ref!==void 0&&(j=h.ref);for(i in h)f.call(h,i)&&!_.hasOwnProperty(i)&&(m[i]=h[i]);if(k&&k.defaultProps)for(i in h=k.defaultProps,h)m[i]===void 0&&(m[i]=h[i]);return{$$typeof:p,type:k,key:T,ref:j,props:m,_owner:C.current}}return N.Fragment=g,N.jsx=O,N.jsxs=O,N}var B={};/** * @license React * react-jsx-runtime.development.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */var we;function Je(){return we||(we=1,process.env.NODE_ENV!=="production"&&function(){var a=u,p=Symbol.for("react.element"),g=Symbol.for("react.portal"),f=Symbol.for("react.fragment"),C=Symbol.for("react.strict_mode"),_=Symbol.for("react.profiler"),O=Symbol.for("react.provider"),k=Symbol.for("react.context"),h=Symbol.for("react.forward_ref"),d=Symbol.for("react.suspense"),i=Symbol.for("react.suspense_list"),m=Symbol.for("react.memo"),T=Symbol.for("react.lazy"),j=Symbol.for("react.offscreen"),z=Symbol.iterator,W="@@iterator";function Y(e){if(e===null||typeof e!="object")return null;var r=z&&e[z]||e[W];return typeof r=="function"?r:null}var F=a.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function E(e){{for(var r=arguments.length,t=new Array(r>1?r-1:0),o=1;o=1&&R>=0&&s[b]!==x[R];)R--;for(;b>=1&&R>=0;b--,R--)if(s[b]!==x[R]){if(b!==1||R!==1)do if(b--,R--,R<0||s[b]!==x[R]){var S=` `+s[b].replace(" at new "," at ");return e.displayName&&S.includes("")&&(S=S.replace("",e.displayName)),typeof e=="function"&&ne.set(e,S),S}while(b>=1&&R>=0);break}}}finally{be=!1,he.current=y,$e(),Error.prepareStackTrace=v}var V=e?e.displayName||e.name:"",L=V?te(V):"";return typeof e=="function"&&ne.set(e,L),L}function rr(e,r,t){return Se(e,!1)}function tr(e){var r=e.prototype;return!!(r&&r.isReactComponent)}function ae(e,r,t){if(e==null)return"";if(typeof e=="function")return Se(e,tr(e));if(typeof e=="string")return te(e);switch(e){case d:return te("Suspense");case i:return te("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case h:return rr(e.render);case m:return ae(e.type,r,t);case T:{var o=e,v=o._payload,y=o._init;try{return ae(y(v),r,t)}catch{}}}return""}var G=Object.prototype.hasOwnProperty,Ae={},je=F.ReactDebugCurrentFrame;function oe(e){if(e){var r=e._owner,t=ae(e.type,e._source,r?r.type:null);je.setExtraStackFrame(t)}else je.setExtraStackFrame(null)}function nr(e,r,t,o,v){{var y=Function.call.bind(G);for(var c in e)if(y(e,c)){var s=void 0;try{if(typeof e[c]!="function"){var x=Error((o||"React class")+": "+t+" type `"+c+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[c]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw x.name="Invariant Violation",x}s=e[c](r,c,o,t,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(b){s=b}s&&!(s instanceof Error)&&(oe(v),E("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",o||"React class",t,c,typeof s),oe(null)),s instanceof Error&&!(s.message in Ae)&&(Ae[s.message]=!0,oe(v),E("Failed %s type: %s",t,s.message),oe(null))}}}var ar=Array.isArray;function Re(e){return ar(e)}function or(e){{var r=typeof Symbol=="function"&&Symbol.toStringTag,t=r&&e[Symbol.toStringTag]||e.constructor.name||"Object";return t}}function ur(e){try{return Ie(e),!1}catch{return!0}}function Ie(e){return""+e}function Fe(e){if(ur(e))return E("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",or(e)),Ie(e)}var X=F.ReactCurrentOwner,ir={key:!0,ref:!0,__self:!0,__source:!0},De,Me,Ee;Ee={};function sr(e){if(G.call(e,"ref")){var r=Object.getOwnPropertyDescriptor(e,"ref").get;if(r&&r.isReactWarning)return!1}return e.ref!==void 0}function cr(e){if(G.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function lr(e,r){if(typeof e.ref=="string"&&X.current&&r&&X.current.stateNode!==r){var t=P(X.current.type);Ee[t]||(E('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref',P(X.current.type),e.ref),Ee[t]=!0)}}function fr(e,r){{var t=function(){De||(De=!0,E("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"key",{get:t,configurable:!0})}}function dr(e,r){{var t=function(){Me||(Me=!0,E("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"ref",{get:t,configurable:!0})}}var vr=function(e,r,t,o,v,y,c){var s={$$typeof:p,type:e,key:r,ref:t,props:c,_owner:y};return s._store={},Object.defineProperty(s._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(s,"_self",{configurable:!1,enumerable:!1,writable:!1,value:o}),Object.defineProperty(s,"_source",{configurable:!1,enumerable:!1,writable:!1,value:v}),Object.freeze&&(Object.freeze(s.props),Object.freeze(s)),s};function pr(e,r,t,o,v){{var y,c={},s=null,x=null;t!==void 0&&(Fe(t),s=""+t),cr(r)&&(Fe(r.key),s=""+r.key),sr(r)&&(x=r.ref,lr(r,v));for(y in r)G.call(r,y)&&!ir.hasOwnProperty(y)&&(c[y]=r[y]);if(e&&e.defaultProps){var b=e.defaultProps;for(y in b)c[y]===void 0&&(c[y]=b[y])}if(s||x){var R=typeof e=="function"?e.displayName||e.name||"Unknown":e;s&&fr(c,R),x&&dr(c,R)}return vr(e,s,x,v,o,X.current,c)}}var _e=F.ReactCurrentOwner,Le=F.ReactDebugCurrentFrame;function U(e){if(e){var r=e._owner,t=ae(e.type,e._source,r?r.type:null);Le.setExtraStackFrame(t)}else Le.setExtraStackFrame(null)}var ke;ke=!1;function Te(e){return typeof e=="object"&&e!==null&&e.$$typeof===p}function We(){{if(_e.current){var e=P(_e.current.type);if(e)return` Check the render method of \``+e+"`."}return""}}function yr(e){return""}var Ye={};function mr(e){{var r=We();if(!r){var t=typeof e=="string"?e:e.displayName||e.name;t&&(r=` Check the top-level render call using <`+t+">.")}return r}}function Ue(e,r){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var t=mr(r);if(Ye[t])return;Ye[t]=!0;var o="";e&&e._owner&&e._owner!==_e.current&&(o=" It was passed a child from "+P(e._owner.type)+"."),U(e),E('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',t,o),U(null)}}function Ve(e,r){{if(typeof e!="object")return;if(Re(e))for(var t=0;t",s=" Did you accidentally export a JSX literal instead of a component?"):b=typeof e,E("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",b,s)}var R=pr(e,r,t,v,y);if(R==null)return R;if(c){var S=r.children;if(S!==void 0)if(o)if(Re(S)){for(var V=0;V0?"{key: someKey, "+w.join(": ..., ")+": ...}":"{key: someKey}";if(!Ne[L+Ce]){var kr=w.length>0?"{"+w.join(": ..., ")+": ...}":"{}";E(`A props object containing a "key" prop is being spread into JSX: let props = %s; <%s {...props} /> React keys must be passed directly to JSX without using spread: let props = %s; <%s key={someKey} {...props} />`,Ce,L,kr,L),Ne[L+Ce]=!0}}return e===f?gr(R):hr(R),R}}function br(e,r,t){return Be(e,r,t,!0)}function Rr(e,r,t){return Be(e,r,t,!1)}var Er=Rr,_r=br;B.Fragment=f,B.jsx=Er,B.jsxs=_r}()),B}process.env.NODE_ENV==="production"?ue.exports=ze():ue.exports=Je();var Z=ue.exports;const ie=a=>[null,void 0].includes(a),Ke=a=>{const p=Math.floor(a/3600),g=Math.floor((a-p*3600)/60),f=Math.floor(a-p*3600-g*60),C=[g,f].map(_=>_.toString().padStart(2,"0"));return p!==0&&C.unshift(p),C.join(":")},He=(a=0)=>{const p=Array.from({length:a},(g,f)=>f);if(a===0)return p;for(let g=p.length-1;g>0;g--){const f=Math.floor(Math.random()*(g+1));[p[g],p[f]]=[p[f],p[g]]}return p},Oe=u.createContext(null),Ge=(a,p)=>{if(typeof p=="string")switch(p){case"play":return{...a,playing:!0};case"pause":return{...a,playing:!1};case"play/pause":return{...a,playing:!a.playing};case"muted":return{...a,muted:!a.muted};case"shuffle":return{...a,shuffle:!a.shuffle}}const{type:g,payload:f}=p;switch(g){case"track":return{...a,trackIndex:f};case"loading":return{...a,loading:f};case"repeat":return{...a,repeat:f};case"volume":return{...a,volume:Math.trunc(f*100)};case"duration":return{...a,duration:f,timeLeft:f};case"time":return{...a,currentTime:f,timeLeft:a.duration-f};case"playbackRate":return{...a,playbackRate:f}}},Xe={playing:!1,loading:!1,duration:0,timeLeft:0,currentTime:0,muted:!1,shuffle:!0,repeat:"playlist",volume:100,playbackRate:1,trackIndex:0},Ze=({playlist:a,defaultMuted:p,defaultShuffle:g,defaultVolume:f,defaultPlaybackRate:C,defaultRepeat:_="playlist",defaultTrackIndex:O=0,startMargin:k=5,children:h})=>{const[d,i]=u.useReducer(Ge,{...Xe,muted:!!p,repeat:_,shuffle:!!g,trackIndex:O%a.length}),m=u.useRef(null),T=a[d.trackIndex],j=a.length,z=u.useRef(!0),W=u.useMemo(()=>He(a.length),[a,d.shuffle]),Y=u.useMemo(()=>W.indexOf(d.trackIndex),[W,d.trackIndex]),F=u.useCallback(()=>{d.repeat==="playlist"&&K()},[a,d.shuffle,d.trackIndex]),E=u.useCallback(n=>{const l=n.currentTarget;i({type:"time",payload:l.currentTime})},[]),ce=u.useCallback(n=>{const l=n.currentTarget;i({type:"volume",payload:l.volume})},[]),le=u.useCallback(n=>{const l=n.currentTarget;i({type:"duration",payload:l.duration}),i({type:"volume",payload:l.volume})},[]),fe=u.useCallback(()=>{var n;return(n=m.current)==null?void 0:n.play()},[]),de=u.useCallback(()=>{var n;return(n=m.current)==null?void 0:n.pause()},[]),ve=u.useCallback(()=>{const n=m.current;n&&(n.paused?n.play():n.pause())},[]),pe=u.useCallback(()=>i("muted"),[]),Q=u.useCallback(n=>i({type:"repeat",payload:n}),[]),ye=u.useCallback(()=>i("shuffle"),[]),q=u.useCallback(n=>{const l=m.current;l&&(n=Math.min(Math.max(0,n),100),l.volume=n/100)},[]),J=u.useCallback(n=>{const l=m.current;l&&(l.playbackRate=n,i({type:"playbackRate",payload:n}))},[]),P=u.useCallback(n=>{const l=m.current;l&&(n=Math.min(Math.max(0,n),l.duration),l.currentTime=n)},[]),I=u.useCallback((n=5)=>{const l=m.current;l&&(n=Math.abs(n),l.currentTime=Math.min(l.currentTime+n,l.duration))},[]),D=u.useCallback((n=5)=>{const l=m.current;l&&(n=Math.abs(n),l.currentTime=Math.max(0,l.currentTime-n))},[]),K=u.useCallback(()=>{if(d.shuffle){const M=Y===j-1?0:Y+1;i({type:"track",payload:W[M]});return}const n=d.trackIndex,l=n===j-1?0:n+1;i({type:"track",payload:l})},[a,d.shuffle,d.trackIndex]),$=u.useCallback(()=>{const n=m.current,l=typeof k=="boolean"?5:k;if(n&&k!==!1&&n.currentTime>l){n.currentTime=0;return}if(d.shuffle){const me=Y===0?j-1:Y-1;i({type:"track",payload:W[me]});return}const M=d.trackIndex,re=M===0?j-1:M-1;i({type:"track",payload:re})},[a,d.shuffle,d.trackIndex]),ee=u.useCallback(n=>i({type:"track",payload:n}),[]),H={...d,play:fe,pause:de,togglePlay:ve,toggleMuted:pe,toggleShuffle:ye,setRepeat:Q,setVolume:q,setCurrentTime:P,setPlaybackRate:J,forwardTrack:I,rewindTrack:D,nextTrack:K,prevTrack:$,playTrack:ee,playlist:a,audioRef:m,currentTrack:T};return u.useEffect(()=>{ie(f)||q(f),ie(C)||J(C)},[]),u.useEffect(()=>{const n=m.current;if(n){if(z.current){z.current=!1;return}"userActivation"in navigator&&navigator.userActivation.hasBeenActive&&n.play()}},[d.trackIndex]),Z.jsxs(Oe.Provider,{value:H,children:[Z.jsxs("audio",{ref:m,muted:d.muted,loop:d.repeat==="track",onEnded:F,onPlay:i.bind(null,"play"),onPause:i.bind(null,"pause"),onTimeUpdate:E,onVolumeChange:ce,onLoadedMetadata:le,onCanPlay:i.bind(null,{type:"loading",payload:!1}),onWaiting:i.bind(null,{type:"loading",payload:!0}),onLoadStart:i.bind(null,{type:"loading",payload:!0}),children:[T!==null&&Z.jsx("source",{src:T.src,type:T.type}),(T==null?void 0:T.fallbacks)&&T.fallbacks.map(n=>Z.jsx("source",{src:n.src,type:n.type},n.src))]},d.trackIndex),typeof h=="function"?h(H):h]})},se=()=>{const a=u.useContext(Oe);if(ie(a))throw new Error("useAudio must be used within an Audio component");return a},Qe=a=>({getFrequencyData:()=>Array.from({length:a},()=>0)}),Pe=(a=64)=>{const{audioRef:p,playing:g,trackIndex:f}=se(),C=u.useRef(Qe(a)),_=u.useRef(!1),O=u.useCallback(()=>{const k=p.current;if(!k)return;const h=new(AudioContext||webkitAudioContext),d=h.createMediaElementSource(k),i=h.createAnalyser();d.connect(i),i.connect(h.destination),i.fftSize=a*2,_.current=!0;const m=new Uint8Array(i.frequencyBinCount);return C.current={getFrequencyData:()=>(i.getByteFrequencyData(m),[...m])},()=>{d.disconnect(),i.disconnect(),h.close()}},[]);return u.useEffect(()=>{if(_.current)return O()},[f]),u.useEffect(()=>{if(!_.current&&"userActivation"in navigator&&navigator.userActivation.hasBeenActive)return O()},[g]),C},qe=(a=64)=>{const p=Pe(a),{playing:g}=se(),[f,C]=u.useState(p.current.getFrequencyData());return u.useEffect(()=>{let _;const O=()=>{const k=p.current.getFrequencyData();C(k),_=requestAnimationFrame(O)};return g&&O(),()=>{_!==void 0&&cancelAnimationFrame(_)}},[g]),f};A.Audio=Ze,A.formatTime=Ke,A.useAudio=se,A.useVisualizer=Pe,A.useVisualizerFrame=qe,Object.defineProperty(A,Symbol.toStringTag,{value:"Module"})});