import{a as g,c as S}from"./vendor-react-BBazpZul.js";import"./vendor-utils-BveVE6Uf.js";var w={exports:{}},_={};/**
 * @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 v;function R(){if(v)return _;v=1;var t=S,a=Symbol.for("react.element"),d=Symbol.for("react.fragment"),h=Object.prototype.hasOwnProperty,s=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,l={key:!0,ref:!0,__self:!0,__source:!0};function f(e,r,u){var o,c={},n=null,m=null;u!==void 0&&(n=""+u),r.key!==void 0&&(n=""+r.key),r.ref!==void 0&&(m=r.ref);for(o in r)h.call(r,o)&&!l.hasOwnProperty(o)&&(c[o]=r[o]);if(e&&e.defaultProps)for(o in r=e.defaultProps,r)c[o]===void 0&&(c[o]=r[o]);return{$$typeof:a,type:e,key:n,ref:m,props:c,_owner:s.current}}return _.Fragment=d,_.jsx=f,_.jsxs=f,_}w.exports=R();var E=w.exports;const O=(t,a,d,h)=>{let s=a/(d+h),l=Math.floor(t.length/s);s>t.length&&(s=t.length,l=1);const f=[];for(let e=0;e<s;e++){let r=0;for(let u=0;u<l&&e*l+u<t.length;u++)r+=t[e*l+u];f.push(r/l)}return f},C=(t,a,d,h,s,l)=>{const f=a.height/2,e=a.getContext("2d");e&&(e.clearRect(0,0,a.width,a.height),s!=="transparent"&&(e.fillStyle=s,e.fillRect(0,0,a.width,a.height)),t.forEach((r,u)=>{e.fillStyle=l;const o=u*(d+h),c=f-r/2,n=d,m=r||1;e.beginPath(),e.roundRect(o,c,n,m,50),e.fill()}))},T=({mediaRecorder:t,width:a="100%",height:d="100%",barWidth:h=2,gap:s=1,backgroundColor:l="transparent",barColor:f="rgb(160, 198, 255)",fftSize:e=1024,maxDecibels:r=-10,minDecibels:u=-90,smoothingTimeConstant:o=.4})=>{const[c]=g.useState(()=>new AudioContext),[n,m]=g.useState(),y=g.useRef(null);g.useEffect(()=>{if(!t.stream)return;const i=c.createAnalyser();m(i),i.fftSize=e,i.minDecibels=u,i.maxDecibels=r,i.smoothingTimeConstant=o,c.createMediaStreamSource(t.stream).connect(i)},[t.stream]),g.useEffect(()=>{(n??t.state==="recording")&&p()},[n,t.state]);const p=g.useCallback(()=>{if(!n)return;const i=new Uint8Array(n==null?void 0:n.frequencyBinCount);t.state==="recording"?(n==null||n.getByteFrequencyData(i),b(i),requestAnimationFrame(p)):t.state==="paused"?b(i):t.state==="inactive"&&c.state!=="closed"&&c.close()},[n]),b=i=>{if(!y.current)return;const x=O(i,y.current.width,h,s);C(x,y.current,h,s,l,f)};return E.jsx("canvas",{ref:y,width:a,height:d,style:{aspectRatio:"unset"}})};export{T as LiveAudioVisualizer};
