@byomakase/vu-meter
Version:
A customizable peak meter using the web audio API
5 lines (4 loc) • 21.6 kB
JavaScript
(function(g,S){typeof exports=="object"&&typeof module<"u"?S(exports):typeof define=="function"&&define.amd?define(["exports"],S):(g=typeof globalThis<"u"?globalThis:g||self,S(g.vuMeter={}))})(this,function(g){"use strict";const S={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 N(t,r){return Math.log(r)/Math.log(t)}function I(t){return N(10,t)*20}function ee(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 $=3,A=1.5,F=1.5,H=2;function te(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 re(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 ne(t,r){const{dbRangeMin:e,dbRangeMax:n,dbTickSize:o,fontSize:i,borderSize:s,tickColor:u,vertical:c,scale:a,scaleOffset:f}=r,b=ee(e,n,o),d=document.createElement("div");d.style.position="relative";const l=a==="nordic";return c?(d.style.height=`calc(100% - ${i*A}px)`,d.style.width=l?`${i*3}px`:`${i*H}px`,d.style.marginTop=`${i*A}px`):(d.style.height=`${i*F}px`,d.style.width=`calc(100% - ${i*$}px)`,d.style.marginRight=`${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 T=(n-h)/(n-e)*100;return c?(y.style.top=`calc(${T}% - ${i/2}px)`,y.style.right=`${s}px`,y.style.textAlign="right"):(y.style.right=`${T}%`,y.style.transform="translateX(50%)"),y})}function ie(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*H}px)`):(s.style.height=`calc(100% - ${n*F}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 oe(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*A}px)`,c.style.width="100%",c.style.backgroundImage=`linear-gradient(to bottom, ${e.join(", ")})`):(c.style.height="100%",c.style.width=`calc(100% - ${o*$}px)`,c.style.backgroundImage=`linear-gradient(to left, ${e.join(", ")})`),u.appendChild(c),c})}var C=function(t,r){return C=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])},C(t,r)};function x(t,r){if(typeof r!="function"&&r!==null)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");C(t,r);function e(){this.constructor=t}t.prototype=r===null?Object.create(r):(e.prototype=r.prototype,new e)}function se(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 Y(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 w(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 j(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 M(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 k(t){return this instanceof k?(this.v=t,this):new k(t)}function ae(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,T){i.push([l,h,y,T])>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 k?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 ce(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 w=="function"?w(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)}}typeof SuppressedError=="function"&&SuppressedError;function p(t){return typeof t=="function"}function q(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 R=q(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 D(t,r){if(t){var e=t.indexOf(r);0<=e&&t.splice(e,1)}}var _=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=w(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 R?h.errors:[h]}var b=this._finalizers;if(b){this._finalizers=null;try{for(var d=w(b),l=d.next();!l.done;l=d.next()){var v=l.value;try{W(v)}catch(h){i=i??[],h instanceof R?i=M(M([],j(i)),j(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 R(i)}},t.prototype.add=function(r){var e;if(r&&r!==this)if(this.closed)W(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)&&D(e,r)},t.prototype.remove=function(r){var e=this._finalizers;e&&D(e,r),r instanceof t&&r._removeParent(this)},t.EMPTY=function(){var r=new t;return r.closed=!0,r}(),t}(),G=_.EMPTY;function V(t){return t instanceof _||t&&"closed"in t&&p(t.remove)&&p(t.add)&&p(t.unsubscribe)}function W(t){p(t)?t():t.unsubscribe()}var ue={Promise:void 0},le={setTimeout:function(t,r){for(var e=[],n=2;n<arguments.length;n++)e[n-2]=arguments[n];return setTimeout.apply(void 0,M([t,r],j(e)))},clearTimeout:function(t){return clearTimeout(t)},delegate:void 0};function X(t){le.setTimeout(function(){throw t})}function z(){}function P(t){t()}var B=function(t){x(r,t);function r(e){var n=t.call(this)||this;return n.isStopped=!1,e?(n.destination=e,V(e)&&e.add(n)):n.destination=de,n}return r.create=function(e,n,o){return new U(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}(_),fe=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){E(n)}},t.prototype.error=function(r){var e=this.partialObserver;if(e.error)try{e.error(r)}catch(n){E(n)}else E(r)},t.prototype.complete=function(){var r=this.partialObserver;if(r.complete)try{r.complete()}catch(e){E(e)}},t}(),U=function(t){x(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 fe(s),i}return r}(B);function E(t){X(t)}function he(t){throw t}var de={closed:!0,next:z,error:he,complete:z},L=function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"}();function pe(t){return t}function ye(t){return t.length===0?pe: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=ve(r)?r:new U(r,e,n);return P(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=J(e),new e(function(o,i){var s=new U({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[L]=function(){return this},t.prototype.pipe=function(){for(var r=[],e=0;e<arguments.length;e++)r[e]=arguments[e];return ye(r)(this)},t.prototype.toPromise=function(r){var e=this;return r=J(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 J(t){var r;return(r=t??ue.Promise)!==null&&r!==void 0?r:Promise}function be(t){return t&&p(t.next)&&p(t.error)&&p(t.complete)}function ve(t){return t&&t instanceof B||be(t)&&V(t)}function me(t){return p(t==null?void 0:t.lift)}function ge(t){return function(r){if(me(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 Se(t,r,e,n,o){return new we(t,r,e,n,o)}var we=function(t){x(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}(B),ke=q(function(t){return function(){t(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}}),O=function(t){x(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 K(this,this);return n.operator=e,n},r.prototype._throwIfClosed=function(){if(this.closed)throw new ke},r.prototype.next=function(e){var n=this;P(function(){var o,i;if(n._throwIfClosed(),!n.isStopped){n.currentObservers||(n.currentObservers=Array.from(n.observers));try{for(var s=w(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;P(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;P(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?G:(this.currentObservers=null,u.push(e),new _(function(){n.currentObservers=null,D(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 K(e,n)},r}(m),K=function(t){x(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:G},r}(O),xe=function(t){return t&&typeof t.length=="number"&&typeof t!="function"};function _e(t){return p(t==null?void 0:t.then)}function Pe(t){return p(t[L])}function Ee(t){return Symbol.asyncIterator&&p(t==null?void 0:t[Symbol.asyncIterator])}function Oe(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 Te(){return typeof Symbol!="function"||!Symbol.iterator?"@@iterator":Symbol.iterator}var Ie=Te();function $e(t){return p(t==null?void 0:t[Ie])}function Ae(t){return ae(this,arguments,function(){var e,n,o,i;return Y(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,k(e.read())];case 3:return n=s.sent(),o=n.value,i=n.done,i?[4,k(void 0)]:[3,5];case 4:return[2,s.sent()];case 5:return[4,k(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 Ce(t){return p(t==null?void 0:t.getReader)}function je(t){if(t instanceof m)return t;if(t!=null){if(Pe(t))return Me(t);if(xe(t))return Re(t);if(_e(t))return De(t);if(Ee(t))return Q(t);if($e(t))return ze(t);if(Ce(t))return Be(t)}throw Oe(t)}function Me(t){return new m(function(r){var e=t[L]();if(p(e.subscribe))return e.subscribe(r);throw new TypeError("Provided object does not correctly implement Symbol.observable")})}function Re(t){return new m(function(r){for(var e=0;e<t.length&&!r.closed;e++)r.next(t[e]);r.complete()})}function De(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,X)})}function ze(t){return new m(function(r){var e,n;try{for(var o=w(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){Ue(t,r).catch(function(e){return r.error(e)})})}function Be(t){return Q(Ae(t))}function Ue(t,r){var e,n,o,i;return se(this,void 0,void 0,function(){var s,u;return Y(this,function(c){switch(c.label){case 0:c.trys.push([0,5,6,11]),e=ce(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 Z(t){return ge(function(r,e){je(t).subscribe(Se(e,function(){return e.complete()},z)),!e.closed&&r.subscribe(e)})}class Le{constructor(r,e,n={}){this._eventSourceBreaker$=new O,this._destroyed$=new O,this.channelCount=r,this.config=Object.assign({...S},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=re(e,this.config),this.channelElements=ie(this.parent,this.config,this.channelCount),this.bars=oe(this.channelElements,this.config),this.ticks=ne(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 O,r.subscribe({next:e=>{this._eventSource$=e,this._eventSource$.pipe(Z(this._eventSourceBreaker$),Z(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=I(this.tempPeaks[i]),u=te(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(I),maxesDB:this.heldPeaks.map(I)}}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())}}g.VuMeter=Le,g.defaultConfig=S,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})});
//# sourceMappingURL=vu-meter.umd.js.map