@byomakase/vu-meter
Version:
A customizable peak meter using the web audio API
5 lines (4 loc) • 21.3 kB
JavaScript
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Y={vertical:!1,borderSize:2,fontSize:9,backgroundColor:"black",tickColor:"#ddd",labelColor:"#ddd",gradient:["red 1%","#ff0 16%","lime 45%","#080 100%"],dbRangeMin:-48,dbRangeMax:0,dbTickSize:6,maskTransition:"0.1s",peakHoldDuration:0,scale:"default",scaleOffset:0};function Z(t,r){return Math.log(r)/Math.log(t)}function O(t){return Z(10,t)*20}function N(t,r,e){const n=[];for(let o=Math.floor(t)+1;o<=r;o+=1)o%e===0&&n.push(o);return n}const I=3,$=1.5,q=1.5,G=2;function ee(t,r,e,n){let o=Math.floor((e-t)*100/(e-r));return o>100&&(o=100),o<0&&(o=0),n?`inset(${o}% 0 0)`:`inset(0 ${o}% 0 0)`}function te(t,r){const{backgroundColor:e,borderSize:n,vertical:o}=r,i=document.createElement("div");return i.style.backgroundColor=e,i.style.boxSizing="border-box",i.style.height="100%",i.style.padding=`${n}px`,o&&(i.style.display="flex",i.style.flexDirection="row-reverse"),t.appendChild(i),i}function re(t,r){const{dbRangeMin:e,dbRangeMax:n,dbTickSize:o,fontSize:i,borderSize:s,tickColor:u,vertical:c,scale:a,scaleOffset:f}=r,b=N(e,n,o),d=document.createElement("div");d.style.position="relative";const l=a==="nordic";return c?(d.style.height=`calc(100% - ${i*$}px)`,d.style.width=l?`${i*3}px`:`${i*G}px`,d.style.marginTop=`${i*$}px`):(d.style.height=`${i*q}px`,d.style.width=`calc(100% - ${i*I}px)`,d.style.marginRight=`${i*I}px`),t.appendChild(d),b.map(h=>{const y=document.createElement("div");d.appendChild(y),y.style.position="absolute",y.style.color=l&&h+f>=6?"red":u,y.style.fontSize=`${i}px`,y.textContent=l&&h===-9?"TEST":(h+f).toString();const k=(n-h)/(n-e)*100;return c?(y.style.top=`calc(${k}% - ${i/2}px)`,y.style.right=`${s}px`,y.style.textAlign="right"):(y.style.right=`${k}%`,y.style.transform="translateX(50%)"),y})}function ne(t,r,e){const{fontSize:n,vertical:o,borderSize:i}=r,s=document.createElement("div");s.style.display="flex",s.style.justifyContent="space-between",o?(s.style.height="100%",s.style.width=`calc(100% - ${n*G}px)`):(s.style.height=`calc(100% - ${n*q}px)`,s.style.width="100%",s.style.flexDirection="column"),t.appendChild(s);const u=(e-1)*i;return Array.from(Array(e).keys()).map(()=>{const a=document.createElement("div");return o?(a.style.height="100%",a.style.width=`calc((100% - ${u}px) / ${e})`):(a.style.display="flex",a.style.height=`calc((100% - ${u}px) / ${e})`,a.style.width="100%",a.style.flexDirection="row-reverse"),s.appendChild(a),a})}function ie(t,r){const{gradient:e,vertical:n,fontSize:o,maskTransition:i}=r;return t.map(u=>{const c=document.createElement("div");return c.style.transition=`clip-path ${i}`,n?(c.style.height=`calc(100% - ${o*$}px)`,c.style.width="100%",c.style.backgroundImage=`linear-gradient(to bottom, ${e.join(", ")})`):(c.style.height="100%",c.style.width=`calc(100% - ${o*I}px)`,c.style.backgroundImage=`linear-gradient(to left, ${e.join(", ")})`),u.appendChild(c),c})}var A=function(t,r){return A=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,n){e.__proto__=n}||function(e,n){for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])},A(t,r)};function w(t,r){if(typeof r!="function"&&r!==null)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");A(t,r);function e(){this.constructor=t}t.prototype=r===null?Object.create(r):(e.prototype=r.prototype,new e)}function oe(t,r,e,n){function o(i){return i instanceof e?i:new e(function(s){s(i)})}return new(e||(e=Promise))(function(i,s){function u(f){try{a(n.next(f))}catch(b){s(b)}}function c(f){try{a(n.throw(f))}catch(b){s(b)}}function a(f){f.done?i(f.value):o(f.value).then(u,c)}a((n=n.apply(t,r||[])).next())})}function V(t,r){var e={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},n,o,i,s=Object.create((typeof Iterator=="function"?Iterator:Object).prototype);return s.next=u(0),s.throw=u(1),s.return=u(2),typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function u(a){return function(f){return c([a,f])}}function c(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(e=0)),e;)try{if(n=1,o&&(i=a[0]&2?o.return:a[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,a[1])).done)return i;switch(o=0,i&&(a=[a[0]&2,i.value]),a[0]){case 0:case 1:i=a;break;case 4:return e.label++,{value:a[1],done:!1};case 5:e.label++,o=a[1],a=[0];continue;case 7:a=e.ops.pop(),e.trys.pop();continue;default:if(i=e.trys,!(i=i.length>0&&i[i.length-1])&&(a[0]===6||a[0]===2)){e=0;continue}if(a[0]===3&&(!i||a[1]>i[0]&&a[1]<i[3])){e.label=a[1];break}if(a[0]===6&&e.label<i[1]){e.label=i[1],i=a;break}if(i&&e.label<i[2]){e.label=i[2],e.ops.push(a);break}i[2]&&e.ops.pop(),e.trys.pop();continue}a=r.call(t,e)}catch(f){a=[6,f],o=0}finally{n=i=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}}function S(t){var r=typeof Symbol=="function"&&Symbol.iterator,e=r&&t[r],n=0;if(e)return e.call(t);if(t&&typeof t.length=="number")return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw new TypeError(r?"Object is not iterable.":"Symbol.iterator is not defined.")}function C(t,r){var e=typeof Symbol=="function"&&t[Symbol.iterator];if(!e)return t;var n=e.call(t),o,i=[],s;try{for(;(r===void 0||r-- >0)&&!(o=n.next()).done;)i.push(o.value)}catch(u){s={error:u}}finally{try{o&&!o.done&&(e=n.return)&&e.call(n)}finally{if(s)throw s.error}}return i}function j(t,r,e){if(e||arguments.length===2)for(var n=0,o=r.length,i;n<o;n++)(i||!(n in r))&&(i||(i=Array.prototype.slice.call(r,0,n)),i[n]=r[n]);return t.concat(i||Array.prototype.slice.call(r))}function g(t){return this instanceof g?(this.v=t,this):new g(t)}function se(t,r,e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=e.apply(t,r||[]),o,i=[];return o=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),u("next"),u("throw"),u("return",s),o[Symbol.asyncIterator]=function(){return this},o;function s(l){return function(v){return Promise.resolve(v).then(l,b)}}function u(l,v){n[l]&&(o[l]=function(h){return new Promise(function(y,k){i.push([l,h,y,k])>1||c(l,h)})},v&&(o[l]=v(o[l])))}function c(l,v){try{a(n[l](v))}catch(h){d(i[0][3],h)}}function a(l){l.value instanceof g?Promise.resolve(l.value.v).then(f,b):d(i[0][2],l)}function f(l){c("next",l)}function b(l){c("throw",l)}function d(l,v){l(v),i.shift(),i.length&&c(i[0][0],i[0][1])}}function ae(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r=t[Symbol.asyncIterator],e;return r?r.call(t):(t=typeof S=="function"?S(t):t[Symbol.iterator](),e={},n("next"),n("throw"),n("return"),e[Symbol.asyncIterator]=function(){return this},e);function n(i){e[i]=t[i]&&function(s){return new Promise(function(u,c){s=t[i](s),o(u,c,s.done,s.value)})}}function o(i,s,u,c){Promise.resolve(c).then(function(a){i({value:a,done:u})},s)}}function p(t){return typeof t=="function"}function W(t){var r=function(n){Error.call(n),n.stack=new Error().stack},e=t(r);return e.prototype=Object.create(Error.prototype),e.prototype.constructor=e,e}var T=W(function(t){return function(e){t(this),this.message=e?e.length+` errors occurred during unsubscription:
`+e.map(function(n,o){return o+1+") "+n.toString()}).join(`
`):"",this.name="UnsubscriptionError",this.errors=e}});function M(t,r){if(t){var e=t.indexOf(r);0<=e&&t.splice(e,1)}}var E=function(){function t(r){this.initialTeardown=r,this.closed=!1,this._parentage=null,this._finalizers=null}return t.prototype.unsubscribe=function(){var r,e,n,o,i;if(!this.closed){this.closed=!0;var s=this._parentage;if(s)if(this._parentage=null,Array.isArray(s))try{for(var u=S(s),c=u.next();!c.done;c=u.next()){var a=c.value;a.remove(this)}}catch(h){r={error:h}}finally{try{c&&!c.done&&(e=u.return)&&e.call(u)}finally{if(r)throw r.error}}else s.remove(this);var f=this.initialTeardown;if(p(f))try{f()}catch(h){i=h instanceof T?h.errors:[h]}var b=this._finalizers;if(b){this._finalizers=null;try{for(var d=S(b),l=d.next();!l.done;l=d.next()){var v=l.value;try{U(v)}catch(h){i=i??[],h instanceof T?i=j(j([],C(i)),C(h.errors)):i.push(h)}}}catch(h){n={error:h}}finally{try{l&&!l.done&&(o=d.return)&&o.call(d)}finally{if(n)throw n.error}}}if(i)throw new T(i)}},t.prototype.add=function(r){var e;if(r&&r!==this)if(this.closed)U(r);else{if(r instanceof t){if(r.closed||r._hasParent(this))return;r._addParent(this)}(this._finalizers=(e=this._finalizers)!==null&&e!==void 0?e:[]).push(r)}},t.prototype._hasParent=function(r){var e=this._parentage;return e===r||Array.isArray(e)&&e.includes(r)},t.prototype._addParent=function(r){var e=this._parentage;this._parentage=Array.isArray(e)?(e.push(r),e):e?[e,r]:r},t.prototype._removeParent=function(r){var e=this._parentage;e===r?this._parentage=null:Array.isArray(e)&&M(e,r)},t.prototype.remove=function(r){var e=this._finalizers;e&&M(e,r),r instanceof t&&r._removeParent(this)},t.EMPTY=function(){var r=new t;return r.closed=!0,r}(),t}(),X=E.EMPTY;function J(t){return t instanceof E||t&&"closed"in t&&p(t.remove)&&p(t.add)&&p(t.unsubscribe)}function U(t){p(t)?t():t.unsubscribe()}var ce={Promise:void 0},ue={setTimeout:function(t,r){for(var e=[],n=2;n<arguments.length;n++)e[n-2]=arguments[n];return setTimeout.apply(void 0,j([t,r],C(e)))},clearTimeout:function(t){return clearTimeout(t)},delegate:void 0};function K(t){ue.setTimeout(function(){throw t})}function R(){}function _(t){t()}var z=function(t){w(r,t);function r(e){var n=t.call(this)||this;return n.isStopped=!1,e?(n.destination=e,J(e)&&e.add(n)):n.destination=he,n}return r.create=function(e,n,o){return new D(e,n,o)},r.prototype.next=function(e){this.isStopped||this._next(e)},r.prototype.error=function(e){this.isStopped||(this.isStopped=!0,this._error(e))},r.prototype.complete=function(){this.isStopped||(this.isStopped=!0,this._complete())},r.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,t.prototype.unsubscribe.call(this),this.destination=null)},r.prototype._next=function(e){this.destination.next(e)},r.prototype._error=function(e){try{this.destination.error(e)}finally{this.unsubscribe()}},r.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},r}(E),le=function(){function t(r){this.partialObserver=r}return t.prototype.next=function(r){var e=this.partialObserver;if(e.next)try{e.next(r)}catch(n){x(n)}},t.prototype.error=function(r){var e=this.partialObserver;if(e.error)try{e.error(r)}catch(n){x(n)}else x(r)},t.prototype.complete=function(){var r=this.partialObserver;if(r.complete)try{r.complete()}catch(e){x(e)}},t}(),D=function(t){w(r,t);function r(e,n,o){var i=t.call(this)||this,s;return p(e)||!e?s={next:e??void 0,error:n??void 0,complete:o??void 0}:s=e,i.destination=new le(s),i}return r}(z);function x(t){K(t)}function fe(t){throw t}var he={closed:!0,next:R,error:fe,complete:R},B=function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"}();function de(t){return t}function pe(t){return t.length===0?de:t.length===1?t[0]:function(e){return t.reduce(function(n,o){return o(n)},e)}}var m=function(){function t(r){r&&(this._subscribe=r)}return t.prototype.lift=function(r){var e=new t;return e.source=this,e.operator=r,e},t.prototype.subscribe=function(r,e,n){var o=this,i=be(r)?r:new D(r,e,n);return _(function(){var s=o,u=s.operator,c=s.source;i.add(u?u.call(i,c):c?o._subscribe(i):o._trySubscribe(i))}),i},t.prototype._trySubscribe=function(r){try{return this._subscribe(r)}catch(e){r.error(e)}},t.prototype.forEach=function(r,e){var n=this;return e=L(e),new e(function(o,i){var s=new D({next:function(u){try{r(u)}catch(c){i(c),s.unsubscribe()}},error:i,complete:o});n.subscribe(s)})},t.prototype._subscribe=function(r){var e;return(e=this.source)===null||e===void 0?void 0:e.subscribe(r)},t.prototype[B]=function(){return this},t.prototype.pipe=function(){for(var r=[],e=0;e<arguments.length;e++)r[e]=arguments[e];return pe(r)(this)},t.prototype.toPromise=function(r){var e=this;return r=L(r),new r(function(n,o){var i;e.subscribe(function(s){return i=s},function(s){return o(s)},function(){return n(i)})})},t.create=function(r){return new t(r)},t}();function L(t){var r;return(r=t??ce.Promise)!==null&&r!==void 0?r:Promise}function ye(t){return t&&p(t.next)&&p(t.error)&&p(t.complete)}function be(t){return t&&t instanceof z||ye(t)&&J(t)}function ve(t){return p(t==null?void 0:t.lift)}function me(t){return function(r){if(ve(r))return r.lift(function(e){try{return t(e,this)}catch(n){this.error(n)}});throw new TypeError("Unable to lift unknown Observable type")}}function ge(t,r,e,n,o){return new Se(t,r,e,n,o)}var Se=function(t){w(r,t);function r(e,n,o,i,s,u){var c=t.call(this,e)||this;return c.onFinalize=s,c.shouldUnsubscribe=u,c._next=n?function(a){try{n(a)}catch(f){e.error(f)}}:t.prototype._next,c._error=i?function(a){try{i(a)}catch(f){e.error(f)}finally{this.unsubscribe()}}:t.prototype._error,c._complete=o?function(){try{o()}catch(a){e.error(a)}finally{this.unsubscribe()}}:t.prototype._complete,c}return r.prototype.unsubscribe=function(){var e;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var n=this.closed;t.prototype.unsubscribe.call(this),!n&&((e=this.onFinalize)===null||e===void 0||e.call(this))}},r}(z),we=W(function(t){return function(){t(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}}),P=function(t){w(r,t);function r(){var e=t.call(this)||this;return e.closed=!1,e.currentObservers=null,e.observers=[],e.isStopped=!1,e.hasError=!1,e.thrownError=null,e}return r.prototype.lift=function(e){var n=new F(this,this);return n.operator=e,n},r.prototype._throwIfClosed=function(){if(this.closed)throw new we},r.prototype.next=function(e){var n=this;_(function(){var o,i;if(n._throwIfClosed(),!n.isStopped){n.currentObservers||(n.currentObservers=Array.from(n.observers));try{for(var s=S(n.currentObservers),u=s.next();!u.done;u=s.next()){var c=u.value;c.next(e)}}catch(a){o={error:a}}finally{try{u&&!u.done&&(i=s.return)&&i.call(s)}finally{if(o)throw o.error}}}})},r.prototype.error=function(e){var n=this;_(function(){if(n._throwIfClosed(),!n.isStopped){n.hasError=n.isStopped=!0,n.thrownError=e;for(var o=n.observers;o.length;)o.shift().error(e)}})},r.prototype.complete=function(){var e=this;_(function(){if(e._throwIfClosed(),!e.isStopped){e.isStopped=!0;for(var n=e.observers;n.length;)n.shift().complete()}})},r.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=this.currentObservers=null},Object.defineProperty(r.prototype,"observed",{get:function(){var e;return((e=this.observers)===null||e===void 0?void 0:e.length)>0},enumerable:!1,configurable:!0}),r.prototype._trySubscribe=function(e){return this._throwIfClosed(),t.prototype._trySubscribe.call(this,e)},r.prototype._subscribe=function(e){return this._throwIfClosed(),this._checkFinalizedStatuses(e),this._innerSubscribe(e)},r.prototype._innerSubscribe=function(e){var n=this,o=this,i=o.hasError,s=o.isStopped,u=o.observers;return i||s?X:(this.currentObservers=null,u.push(e),new E(function(){n.currentObservers=null,M(u,e)}))},r.prototype._checkFinalizedStatuses=function(e){var n=this,o=n.hasError,i=n.thrownError,s=n.isStopped;o?e.error(i):s&&e.complete()},r.prototype.asObservable=function(){var e=new m;return e.source=this,e},r.create=function(e,n){return new F(e,n)},r}(m),F=function(t){w(r,t);function r(e,n){var o=t.call(this)||this;return o.destination=e,o.source=n,o}return r.prototype.next=function(e){var n,o;(o=(n=this.destination)===null||n===void 0?void 0:n.next)===null||o===void 0||o.call(n,e)},r.prototype.error=function(e){var n,o;(o=(n=this.destination)===null||n===void 0?void 0:n.error)===null||o===void 0||o.call(n,e)},r.prototype.complete=function(){var e,n;(n=(e=this.destination)===null||e===void 0?void 0:e.complete)===null||n===void 0||n.call(e)},r.prototype._subscribe=function(e){var n,o;return(o=(n=this.source)===null||n===void 0?void 0:n.subscribe(e))!==null&&o!==void 0?o:X},r}(P),ke=function(t){return t&&typeof t.length=="number"&&typeof t!="function"};function xe(t){return p(t==null?void 0:t.then)}function _e(t){return p(t[B])}function Pe(t){return Symbol.asyncIterator&&p(t==null?void 0:t[Symbol.asyncIterator])}function Ee(t){return new TypeError("You provided "+(t!==null&&typeof t=="object"?"an invalid object":"'"+t+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}function Oe(){return typeof Symbol!="function"||!Symbol.iterator?"@@iterator":Symbol.iterator}var Te=Oe();function Ie(t){return p(t==null?void 0:t[Te])}function $e(t){return se(this,arguments,function(){var e,n,o,i;return V(this,function(s){switch(s.label){case 0:e=t.getReader(),s.label=1;case 1:s.trys.push([1,,9,10]),s.label=2;case 2:return[4,g(e.read())];case 3:return n=s.sent(),o=n.value,i=n.done,i?[4,g(void 0)]:[3,5];case 4:return[2,s.sent()];case 5:return[4,g(o)];case 6:return[4,s.sent()];case 7:return s.sent(),[3,2];case 8:return[3,10];case 9:return e.releaseLock(),[7];case 10:return[2]}})})}function Ae(t){return p(t==null?void 0:t.getReader)}function Ce(t){if(t instanceof m)return t;if(t!=null){if(_e(t))return je(t);if(ke(t))return Me(t);if(xe(t))return Re(t);if(Pe(t))return Q(t);if(Ie(t))return De(t);if(Ae(t))return ze(t)}throw Ee(t)}function je(t){return new m(function(r){var e=t[B]();if(p(e.subscribe))return e.subscribe(r);throw new TypeError("Provided object does not correctly implement Symbol.observable")})}function Me(t){return new m(function(r){for(var e=0;e<t.length&&!r.closed;e++)r.next(t[e]);r.complete()})}function Re(t){return new m(function(r){t.then(function(e){r.closed||(r.next(e),r.complete())},function(e){return r.error(e)}).then(null,K)})}function De(t){return new m(function(r){var e,n;try{for(var o=S(t),i=o.next();!i.done;i=o.next()){var s=i.value;if(r.next(s),r.closed)return}}catch(u){e={error:u}}finally{try{i&&!i.done&&(n=o.return)&&n.call(o)}finally{if(e)throw e.error}}r.complete()})}function Q(t){return new m(function(r){Be(t,r).catch(function(e){return r.error(e)})})}function ze(t){return Q($e(t))}function Be(t,r){var e,n,o,i;return oe(this,void 0,void 0,function(){var s,u;return V(this,function(c){switch(c.label){case 0:c.trys.push([0,5,6,11]),e=ae(t),c.label=1;case 1:return[4,e.next()];case 2:if(n=c.sent(),!!n.done)return[3,4];if(s=n.value,r.next(s),r.closed)return[2];c.label=3;case 3:return[3,1];case 4:return[3,11];case 5:return u=c.sent(),o={error:u},[3,11];case 6:return c.trys.push([6,,9,10]),n&&!n.done&&(i=e.return)?[4,i.call(e)]:[3,8];case 7:c.sent(),c.label=8;case 8:return[3,10];case 9:if(o)throw o.error;return[7];case 10:return[7];case 11:return r.complete(),[2]}})})}function H(t){return me(function(r,e){Ce(t).subscribe(ge(e,function(){return e.complete()},R)),!e.closed&&r.subscribe(e)})}class Ue{constructor(r,e,n={}){this._eventSourceBreaker$=new P,this._destroyed$=new P,this.channelCount=r,this.config=Object.assign({...Y},n),this.config.scale==="nordic"&&(this.config.scaleOffset=9,this.config.dbTickSize=3,this.config.dbRangeMin=-46,this.config.dbRangeMax=3),this.tempPeaks=new Array(this.channelCount).fill(0),this.heldPeaks=new Array(this.channelCount).fill(0),this.peakHoldTimeouts=new Array(this.channelCount).fill(0),e&&(this.parent=te(e,this.config),this.channelElements=ne(this.parent,this.config,this.channelCount),this.bars=ie(this.channelElements,this.config),this.ticks=re(this.parent,this.config),this.parent.addEventListener("click",this.clearPeaks.bind(this)),this.paintMeter())}attachSource(r){return this._eventSourceBreaker$.next(),this._eventSourceBreaker$.complete(),this._eventSourceBreaker$=new P,r.subscribe({next:e=>{this._eventSource$=e,this._eventSource$.pipe(H(this._eventSourceBreaker$),H(this._destroyed$)).subscribe({next:n=>{this.handlePeakProcessorMessageEvent(n)}})}}),this}handlePeakProcessorMessageEvent(r){if(r.data.type==="message"&&console.log(r.data.message),r.data.type==="peaks"){const{peaks:e}=r.data;for(let n=0;n<this.tempPeaks.length;n+=1)e.length>n?this.tempPeaks[n]=e[n]:this.tempPeaks[n]=0;e.length<this.channelCount&&this.tempPeaks.fill(0,e.length);for(let n=0;n<e.length;n+=1)e[n]>this.heldPeaks[n]&&(this.heldPeaks[n]=e[n],this.peakHoldTimeouts[n]&&clearTimeout(this.peakHoldTimeouts[n]),this.config.peakHoldDuration&&(this.peakHoldTimeouts[n]=window.setTimeout(()=>{this.clearPeak(n)},this.config.peakHoldDuration)))}}paintMeter(){const{dbRangeMin:r,dbRangeMax:e,vertical:n}=this.config;this.bars&&this.bars.forEach((o,i)=>{const s=O(this.tempPeaks[i]),u=ee(s,r,e,n);o.style.clipPath=u}),this.animationRequestId=window.requestAnimationFrame(this.paintMeter.bind(this))}clearPeak(r){this.heldPeaks[r]=this.tempPeaks[r]}clearPeaks(){for(let r=0;r<this.heldPeaks.length;r+=1)this.clearPeak(r)}getPeaks(){return{current:this.tempPeaks,maxes:this.heldPeaks,currentDB:this.tempPeaks.map(O),maxesDB:this.heldPeaks.map(O)}}destroy(){this._eventSourceBreaker$.next(),this._eventSourceBreaker$.complete(),this._destroyed$.next(),this._destroyed$.complete(),this.parent&&(this.parent.removeEventListener("click",this.clearPeaks.bind(this)),this.animationRequestId!==void 0&&window.cancelAnimationFrame(this.animationRequestId),this.parent.remove())}}exports.VuMeter=Ue;exports.defaultConfig=Y;
//# sourceMappingURL=vu-meter.cjs.js.map