text: var app=function(){"use strict";function t(){}const e=t=>t;function n(t,e){for(const n in e)t[n]=e[n];return t}function i(t){return t()}function s(){return Object.create(null)}function r(t){t.forEach(i)}function o(t){return"function"==typeof t}function a(t,e){return t!=t?e==e:t!==e||t&&"object"==typeof t||"function"==typeof t}function c(e,...n){if(null==e)return t;const i=e.subscribe(...n);return i.unsubscribe?()=>i.unsubscribe():i}function l(t){let e;return c(t,(t=>e=t))(),e}function h(t,e,n){t.$$.on_destroy.push(c(e,n))}function u(t,e,n,i){if(t){const s=d(t,e,n,i);return t[0](s)}}function d(t,e,i,s){return t[1]&&s?n(i.ctx.slice(),t[1](s(e))):i.ctx}function f(t,e,n,i,s,r,o){const a=function(t,e,n,i){if(t[2]&&i){const s=t[2](i(n));if(void 0===e.dirty)return s;if("object"==typeof s){const t=[],n=Math.max(e.dirty.length,s.length);for(let i=0;i<n;i+=1)t[i]=e.dirty[i]|s[i];return t}return e.dirty|s}return e.dirty}(e,i,s,r);if(a){const s=d(e,n,i,o);t.p(s,a)}}function p(t){const e={};for(const n in t)"$"!==n[0]&&(e[n]=t[n]);return e}function m(t,e){const n={};e=new Set(e);for(const i in t)e.has(i)||"$"===i[0]||(n[i]=t[i]);return n}function g(e){return e&&o(e.destroy)?e.destroy:t}const v="undefined"!=typeof window;let _=v?()=>window.performance.now():()=>Date.now(),y=v?t=>requestAnimationFrame(t):t;const b=new Set;function x(t){b.forEach((e=>{e.c(t)||(b.delete(e),e.f())})),0!==b.size&&y(x)}function C(t){let e;return 0===b.size&&y(x),{promise:new Promise((n=>{b.add(e={c:t,f:n})})),abort(){b.delete(e)}}}function w(t,e){t.appendChild(e)}function S(t,e,n){t.insertBefore(e,n||null)}function T(t){t.parentNode.removeChild(t)}function M(t,e){for(let n=0;n<t.length;n+=1)t[n]&&t[n].d(e)}function A(t){return document.createElement(t)}function O(t){return document.createElementNS("http://www.w3.org/2000/svg",t)}function E(t){return document.createTextNode(t)}function k(){return E(" ")}function P(){return E("")}function I(t,e,n,i){return t.addEventListener(e,n,i),()=>t.removeEventListener(e,n,i)}function D(t,e,n){null==n?t.removeAttribute(e):t.getAttribute(e)!==n&&t.setAttribute(e,n)}function R(t,e){const n=Object.getOwnPropertyDescriptors(t.__proto__);for(const i in e)null==e[i]?t.removeAttribute(i):"style"===i?t.style.cssText=e[i]:"__value"===i?t.value=t[i]=e[i]:n[i]&&n[i].set?t[i]=e[i]:D(t,i,e[i])}function j(t,e){for(const n in e)D(t,n,e[n])}function $(t,e,n){t.setAttributeNS("http://www.w3.org/1999/xlink",e,n)}function L(t,e){e=""+e,t.wholeText!==e&&(t.data=e)}function F(t,e){t.value=null==e?"":e}function N(t,e,n,i){t.style.setProperty(e,n,i?"important":"")}function B(t,e){for(let n=0;n<t.options.length;n+=1){const i=t.options[n];if(i.__value===e)return void(i.selected=!0)}}function V(t){const e=t.querySelector(":checked")||t.options[0];return e&&e.__value}let W;function H(){if(void 0===W){W=!1;try{"undefined"!=typeof window&&window.parent&&window.parent.document}catch(t){W=!0}}return W}function G(t,e,n){t.classList[n?"add":"remove"](e)}const z=new Set;let Y,X=0;function U(t,e,n,i,s,r,o,a=0){const c=16.666/i;let l="{\n";for(let t=0;t<=1;t+=c){const i=e+(n-e)*r(t);l+=100*t+`%{${o(i,1-i)}}\n`}const h=l+`100% {${o(n,1-n)}}\n}`,u=`__svelte_${function(t){let e=5381,n=t.length;for(;n--;)e=(e<<5)-e^t.charCodeAt(n);return e>>>0}(h)}_${a}`,d=t.ownerDocument;z.add(d);const f=d.__svelte_stylesheet||(d.__svelte_stylesheet=d.head.appendChild(A("style")).sheet),p=d.__svelte_rules||(d.__svelte_rules={});p[u]||(p[u]=!0,f.insertRule(`@keyframes ${u} ${h}`,f.cssRules.length));const m=t.style.animation||"";return t.style.animation=`${m?`${m}, `:""}${u} ${i}ms linear ${s}ms 1 both`,X+=1,u}function q(t,e){const n=(t.style.animation||"").split(", "),i=n.filter(e?t=>t.indexOf(e)<0:t=>-1===t.indexOf("__svelte")),s=n.length-i.length;s&&(t.style.animation=i.join(", "),X-=s,X||y((()=>{X||(z.forEach((t=>{const e=t.__svelte_stylesheet;let n=e.cssRules.length;for(;n--;)e.deleteRule(n);t.__svelte_rules={}})),z.clear())})))}function K(n,i,s,r){if(!i)return t;const o=n.getBoundingClientRect();if(i.left===o.left&&i.right===o.right&&i.top===o.top&&i.bottom===o.bottom)return t;const{delay:a=0,duration:c=300,easing:l=e,start:h=_()+a,end:u=h+c,tick:d=t,css:f}=s(n,{from:i,to:o},r);let p,m=!0,g=!1;function v(){f&&q(n,p),m=!1}return C((t=>{if(!g&&t>=h&&(g=!0),g&&t>=u&&(d(1,0),v()),!m)return!1;if(g){const e=0+1*l((t-h)/c);d(e,1-e)}return!0})),f&&(p=U(n,0,1,c,a,l,f)),a||(g=!0),d(0,1),v}function Z(t){const e=getComputedStyle(t);if("absolute"!==e.position&&"fixed"!==e.position){const{width:n,height:i}=e,s=t.getBoundingClientRect();t.style.position="absolute",t.style.width=n,t.style.height=i,Q(t,s)}}function Q(t,e){const n=t.getBoundingClientRect();if(e.left!==n.left||e.top!==n.top){const i=getComputedStyle(t),s="none"===i.transform?"":i.transform;t.style.transform=`${s} translate(${e.left-n.left}px, ${e.top-n.top}px)`}}function J(t){Y=t}function tt(){if(!Y)throw new Error("Function called outside component initialization");return Y}function et(t,e){const n=t.$$.callbacks[e.type];n&&n.slice().forEach((t=>t(e)))}const nt=[],it=[],st=[],rt=[],ot=Promise.resolve();let at=!1;function ct(t){st.push(t)}function lt(t){rt.push(t)}let ht=!1;const ut=new Set;function dt(){if(!ht){ht=!0;do{for(let t=0;t<nt.length;t+=1){const e=nt[t];J(e),ft(e.$$)}for(J(null),nt.length=0;it.length;)it.pop()();for(let t=0;t<st.length;t+=1){const e=st[t];ut.has(e)||(ut.add(e),e())}st.length=0}while(nt.length);for(;rt.length;)rt.pop()();at=!1,ht=!1,ut.clear()}}function ft(t){if(null!==t.fragment){t.update(),r(t.before_update);const e=t.dirty;t.dirty=[-1],t.fragment&&t.fragment.p(t.ctx,e),t.after_update.forEach(ct)}}let pt;function mt(){return pt||(pt=Promise.resolve(),pt.then((()=>{pt=null}))),pt}function gt(t,e,n){t.dispatchEvent(function(t,e){const n=document.createEvent("CustomEvent");return n.initCustomEvent(t,!1,!1,e),n}(`${e?"intro":"outro"}${n}`))}const vt=new Set;let _t;function yt(){_t={r:0,c:[],p:_t}}function bt(){_t.r||r(_t.c),_t=_t.p}function xt(t,e){t&&t.i&&(vt.delete(t),t.i(e))}function Ct(t,e,n,i){if(t&&t.o){if(vt.has(t))return;vt.add(t),_t.c.push((()=>{vt.delete(t),i&&(n&&t.d(1),i())})),t.o(e)}}const wt={duration:0};function St(n,i,s){let r,a,c=i(n,s),l=!1,h=0;function u(){r&&q(n,r)}function d(){const{delay:i=0,duration:s=300,easing:o=e,tick:d=t,css:f}=c||wt;f&&(r=U(n,0,1,s,i,o,f,h++)),d(0,1);const p=_()+i,m=p+s;a&&a.abort(),l=!0,ct((()=>gt(n,!0,"start"))),a=C((t=>{if(l){if(t>=m)return d(1,0),gt(n,!0,"end"),u(),l=!1;if(t>=p){const e=o((t-p)/s);d(e,1-e)}}return l}))}let f=!1;return{start(){f||(q(n),o(c)?(c=c(),mt().then(d)):d())},invalidate(){f=!1},end(){l&&(u(),l=!1)}}}function Tt(n,i,s){let a,c=i(n,s),l=!0;const h=_t;function u(){const{delay:i=0,duration:s=300,easing:o=e,tick:u=t,css:d}=c||wt;d&&(a=U(n,1,0,s,i,o,d));const f=_()+i,p=f+s;ct((()=>gt(n,!1,"start"))),C((t=>{if(l){if(t>=p)return u(0,1),gt(n,!1,"end"),--h.r||r(h.c),!1;if(t>=f){const e=o((t-f)/s);u(1-e,e)}}return l}))}return h.r+=1,o(c)?mt().then((()=>{c=c(),u()})):u(),{end(t){t&&c.tick&&c.tick(1,0),l&&(a&&q(n,a),l=!1)}}}function Mt(n,i,s,a){let c=i(n,s),l=a?0:1,h=null,u=null,d=null;function f(){d&&q(n,d)}function p(t,e){const n=t.b-l;return e*=Math.abs(n),{a:l,b:t.b,d:n,duration:e,start:t.start,end:t.start+e,group:t.group}}function m(i){const{delay:s=0,duration:o=300,easing:a=e,tick:m=t,css:g}=c||wt,v={start:_()+s,b:i};i||(v.group=_t,_t.r+=1),h||u?u=v:(g&&(f(),d=U(n,l,i,o,s,a,g)),i&&m(0,1),h=p(v,o),ct((()=>gt(n,i,"start"))),C((t=>{if(u&&t>u.start&&(h=p(u,o),u=null,gt(n,h.b,"start"),g&&(f(),d=U(n,l,h.b,h.duration,0,a,c.css))),h)if(t>=h.end)m(l=h.b,1-l),gt(n,h.b,"end"),u||(h.b?f():--h.group.r||r(h.group.c)),h=null;else if(t>=h.start){const e=t-h.start;l=h.a+h.d*a(e/h.duration),m(l,1-l)}return!(!h&&!u)})))}return{run(t){o(c)?mt().then((()=>{c=c(),m(t)})):m(t)},end(){f(),h=u=null}}}function At(t,e){t.f(),function(t,e){Ct(t,1,1,(()=>{e.delete(t.key)}))}(t,e)}function Ot(t,e,n,i,s,r,o,a,c,l,h,u){let d=t.length,f=r.length,p=d;const m={};for(;p--;)m[t[p].key]=p;const g=[],v=new Map,_=new Map;for(p=f;p--;){const t=u(s,r,p),a=n(t);let c=o.get(a);c?i&&c.p(t,e):(c=l(a,t),c.c()),v.set(a,g[p]=c),a in m&&_.set(a,Math.abs(p-m[a]))}const y=new Set,b=new Set;function x(t){xt(t,1),t.m(a,h),o.set(t.key,t),h=t.first,f--}for(;d&&f;){const e=g[f-1],n=t[d-1],i=e.key,s=n.key;e===n?(h=e.first,d--,f--):v.has(s)?!o.has(i)||y.has(i)?x(e):b.has(s)?d--:_.get(i)>_.get(s)?(b.add(i),x(e)):(y.add(s),d--):(c(n,o),d--)}for(;d--;){const e=t[d];v.has(e.key)||c(e,o)}for(;f;)x(g[f-1]);return g}function Et(t,e){const n={},i={},s={$$scope:1};let r=t.length;for(;r--;){const o=t[r],a=e[r];if(a){for(const t in o)t in a||(i[t]=1);for(const t in a)s[t]||(n[t]=a[t],s[t]=1);t[r]=a}else for(const t in o)s[t]=1}for(const t in i)t in n||(n[t]=void 0);return n}function kt(t,e,n){const i=t.$$.props[e];void 0!==i&&(t.$$.bound[i]=n,n(t.$$.ctx[i]))}function Pt(t){t&&t.c()}function It(t,e,n,s){const{fragment:a,on_mount:c,on_destroy:l,after_update:h}=t.$$;a&&a.m(e,n),s||ct((()=>{const e=c.map(i).filter(o);l?l.push(...e):r(e),t.$$.on_mount=[]})),h.forEach(ct)}function Dt(t,e){const n=t.$$;null!==n.fragment&&(r(n.on_destroy),n.fragment&&n.fragment.d(e),n.on_destroy=n.fragment=null,n.ctx=[])}function Rt(t,e){-1===t.$$.dirty[0]&&(nt.push(t),at||(at=!0,ot.then(dt)),t.$$.dirty.fill(0)),t.$$.dirty[e/31|0]|=1<<e%31}function jt(e,n,i,o,a,c,l=[-1]){const h=Y;J(e);const u=e.$$={fragment:null,ctx:null,props:c,update:t,not_equal:a,bound:s(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(h?h.$$.context:n.context||[]),callbacks:s(),dirty:l,skip_bound:!1};let d=!1;if(u.ctx=i?i(e,n.props||{},((t,n,...i)=>{const s=i.length?i[0]:n;return u.ctx&&a(u.ctx[t],u.ctx[t]=s)&&(!u.skip_bound&&u.bound[t]&&u.bound[t](s),d&&Rt(e,t)),n})):[],u.update(),d=!0,r(u.before_update),u.fragment=!!o&&o(u.ctx),n.target){if(n.hydrate){const t=function(t){return Array.from(t.childNodes)}(n.target);u.fragment&&u.fragment.l(t),t.forEach(T)}else u.fragment&&u.fragment.c();n.intro&&xt(e.$$.fragment),It(e,n.target,n.anchor,n.customElement),dt()}J(h)}class $t{$destroy(){Dt(this,1),this.$destroy=t}$on(t,e){const n=this.$$.callbacks[t]||(this.$$.callbacks[t]=[]);return n.push(e),()=>{const t=n.indexOf(e);-1!==t&&n.splice(t,1)}}$set(t){var e;this.$$set&&(e=t,0!==Object.keys(e).length)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}var Lt="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function Ft(t){if(t.__esModule)return t;var e=Object.defineProperty({},"__esModule",{value:!0});return Object.keys(t).forEach((function(n){var i=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,i.get?i:{enumerable:!0,get:function(){return t[n]}})})),e}function Nt(t){var e={exports:{}};return t(e,e.exports),e.exports}var Bt=Nt((function(t){!function(e){function n(){if(n.prototype._singleton)throw new Error("WebMidi is a singleton, it cannot be instantiated directly.");(n.prototype._singleton=this)._inputs=[],this._outputs=[],this._userHandlers={},this._stateChangeQueue=[],this._processingStateChange=!1,this._midiInterfaceEvents=["connected","disconnected"],this._nrpnBuffer=[[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]],this._nrpnEventsEnabled=!0,this._nrpnTypes=["entry","increment","decrement"],this._notes=["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"],this._semitones={C:0,D:2,E:4,F:5,G:7,A:9,B:11},Object.defineProperties(this,{MIDI_SYSTEM_MESSAGES:{value:{sysex:240,timecode:241,songposition:242,songselect:243,tuningrequest:246,sysexend:247,clock:248,start:250,continue:251,stop:252,activesensing:254,reset:255,midimessage:0,unknownsystemmessage:-1},writable:!1,enumerable:!0,configurable:!1},MIDI_CHANNEL_MESSAGES:{value:{noteoff:8,noteon:9,keyaftertouch:10,controlchange:11,channelmode:11,nrpn:11,programchange:12,channelaftertouch:13,pitchbend:14},writable:!1,enumerable:!0,configurable:!1},MIDI_REGISTERED_PARAMETER:{value:{pitchbendrange:[0,0],channelfinetuning:[0,1],channelcoarsetuning:[0,2],tuningprogram:[0,3],tuningbank:[0,4],modulationrange:[0,5],azimuthangle:[61,0],elevationangle:[61,1],gain:[61,2],distanceratio:[61,3],maximumdistance:[61,4],maximumdistancegain:[61,5],referencedistanceratio:[61,6],panspreadangle:[61,7],rollangle:[61,8]},writable:!1,enumerable:!0,configurable:!1},MIDI_CONTROL_CHANGE_MESSAGES:{value:{bankselectcoarse:0,modulationwheelcoarse:1,breathcontrollercoarse:2,footcontrollercoarse:4,portamentotimecoarse:5,dataentrycoarse:6,volumecoarse:7,balancecoarse:8,pancoarse:10,expressioncoarse:11,effectcontrol1coarse:12,effectcontrol2coarse:13,generalpurposeslider1:16,generalpurposeslider2:17,generalpurposeslider3:18,generalpurposeslider4:19,bankselectfine:32,modulationwheelfine:33,breathcontrollerfine:34,footcontrollerfine:36,portamentotimefine:37,dataentryfine:38,volumefine:39,balancefine:40,panfine:42,expressionfine:43,effectcontrol1fine:44,effectcontrol2fine:45,holdpedal:64,portamento:65,sustenutopedal:66,softpedal:67,legatopedal:68,hold2pedal:69,soundvariation:70,resonance:71,soundreleasetime:72,soundattacktime:73,brightness:74,soundcontrol6:75,soundcontrol7:76,soundcontrol8:77,soundcontrol9:78,soundcontrol10:79,generalpurposebutton1:80,generalpurposebutton2:81,generalpurposebutton3:82,generalpurposebutton4:83,reverblevel:91,tremololevel:92,choruslevel:93,celestelevel:94,phaserlevel:95,databuttonincrement:96,databuttondecrement:97,nonregisteredparametercoarse:98,nonregisteredparameterfine:99,registeredparametercoarse:100,registeredparameterfine:101},writable:!1,enumerable:!0,configurable:!1},MIDI_NRPN_MESSAGES:{value:{entrymsb:6,entrylsb:38,increment:96,decrement:97,paramlsb:98,parammsb:99,nullactiveparameter:127},writable:!1,enumerable:!0,configurable:!1},MIDI_CHANNEL_MODE_MESSAGES:{value:{allsoundoff:120,resetallcontrollers:121,localcontrol:122,allnotesoff:123,omnimodeoff:124,omnimodeon:125,monomodeon:126,polymodeon:127},writable:!1,enumerable:!0,configurable:!1},octaveOffset:{value:0,writable:!0,enumerable:!0,configurable:!1}}),Object.defineProperties(this,{supported:{enumerable:!0,get:function(){return"requestMIDIAccess"in navigator}},enabled:{enumerable:!0,get:function(){return void 0!==this.interface}.bind(this)},inputs:{enumerable:!0,get:function(){return this._inputs}.bind(this)},outputs:{enumerable:!0,get:function(){return this._outputs}.bind(this)},sysexEnabled:{enumerable:!0,get:function(){return!(!this.interface||!this.interface.sysexEnabled)}.bind(this)},nrpnEventsEnabled:{enumerable:!0,get:function(){return!!this._nrpnEventsEnabled}.bind(this),set:function(t){return this._nrpnEventsEnabled=t,this._nrpnEventsEnabled}},nrpnTypes:{enumerable:!0,get:function(){return this._nrpnTypes}.bind(this)},time:{enumerable:!0,get:function(){return performance.now()}}})}var i=new n;function s(t){var e=this;this._userHandlers={channel:{},system:{}},this._midiInput=t,Object.defineProperties(this,{connection:{enumerable:!0,get:function(){return e._midiInput.connection}},id:{enumerable:!0,get:function(){return e._midiInput.id}},manufacturer:{enumerable:!0,get:function(){return e._midiInput.manufacturer}},name:{enumerable:!0,get:function(){return e._midiInput.name}},state:{enumerable:!0,get:function(){return e._midiInput.state}},type:{enumerable:!0,get:function(){return e._midiInput.type}}}),this._initializeUserHandlers(),this._midiInput.onmidimessage=this._onMidiMessage.bind(this)}function r(t){var e=this;this._midiOutput=t,Object.defineProperties(this,{connection:{enumerable:!0,get:function(){return e._midiOutput.connection}},id:{enumerable:!0,get:function(){return e._midiOutput.id}},manufacturer:{enumerable:!0,get:function(){return e._midiOutput.manufacturer}},name:{enumerable:!0,get:function(){return e._midiOutput.name}},state:{enumerable:!0,get:function(){return e._midiOutput.state}},type:{enumerable:!0,get:function(){return e._midiOutput.type}}})}n.prototype.enable=function(t,e){this.enabled||(this.supported?navigator.requestMIDIAccess({sysex:e}).then(function(e){var n,i=[],s=[];this.interface=e,this._resetInterfaceUserHandlers(),this.interface.onstatechange=function(t){i.push(t)};for(var r=e.inputs.values(),o=r.next();o&&!o.done;o=r.next())s.push(o.value.open());for(var a=e.outputs.values(),c=a.next();c&&!c.done;c=a.next())s.push(c.value.open());function l(){clearTimeout(n),this._updateInputsAndOutputs(),this.interface.onstatechange=this._onInterfaceStateChange.bind(this),"function"==typeof t&&t.call(this),i.forEach(function(t){this._onInterfaceStateChange(t)}.bind(this))}n=setTimeout(l.bind(this),200),Promise&&Promise.all(s).catch((function(t){})).then(l.bind(this))}.bind(this),function(e){"function"==typeof t&&t.call(this,e)}.bind(this)):"function"==typeof t&&t(new Error("The Web MIDI API is not supported by your browser.")))},n.prototype.disable=function(){if(!this.supported)throw new Error("The Web MIDI API is not supported by your browser.");this.enabled&&(this.removeListener(),this.inputs.forEach((function(t){t.removeListener()}))),this.interface&&(this.interface.onstatechange=void 0),this.interface=void 0,this._inputs=[],this._outputs=[],this._nrpnEventsEnabled=!0,this._resetInterfaceUserHandlers()},n.prototype.addListener=function(t,e){if(!this.enabled)throw new Error("WebMidi must be enabled before adding event listeners.");if("function"!=typeof e)throw new TypeError("The 'listener' parameter must be a function.");if(!(0<=this._midiInterfaceEvents.indexOf(t)))throw new TypeError("The specified event type is not supported.");return this._userHandlers[t].push(e),this},n.prototype.hasListener=function(t,e){if(!this.enabled)throw new Error("WebMidi must be enabled before checking event listeners.");if("function"!=typeof e)throw new TypeError("The 'listener' parameter must be a function.");if(!(0<=this._midiInterfaceEvents.indexOf(t)))throw new TypeError("The specified event type is not supported.");for(var n=0;n<this._userHandlers[t].length;n++)if(this._userHandlers[t][n]===e)return!0;return!1},n.prototype.removeListener=function(t,e){if(!this.enabled)throw new Error("WebMidi must be enabled before removing event listeners.");if(void 0!==e&&"function"!=typeof e)throw new TypeError("The 'listener' parameter must be a function.");if(0<=this._midiInterfaceEvents.indexOf(t))if(e)for(var n=0;n<this._userHandlers[t].length;n++)this._userHandlers[t][n]===e&&this._userHandlers[t].splice(n,1);else this._userHandlers[t]=[];else{if(void 0!==t)throw new TypeError("The specified event type is not supported.");this._resetInterfaceUserHandlers()}return this},n.prototype.toMIDIChannels=function(t){var e;if("all"===t||void 0===t)e=["all"];else{if("none"===t)return[];e=Array.isArray(t)?t:[t]}return-1<e.indexOf("all")&&(e=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]),e.map((function(t){return parseInt(t)})).filter((function(t){return 1<=t&&t<=16}))},n.prototype.getInputById=function(t){if(!this.enabled)throw new Error("WebMidi is not enabled.");t=String(t);for(var e=0;e<this.inputs.length;e++)if(this.inputs[e].id===t)return this.inputs[e];return!1},n.prototype.getOutputById=function(t){if(!this.enabled)throw new Error("WebMidi is not enabled.");t=String(t);for(var e=0;e<this.outputs.length;e++)if(this.outputs[e].id===t)return this.outputs[e];return!1},n.prototype.getInputByName=function(t){if(!this.enabled)throw new Error("WebMidi is not enabled.");for(var e=0;e<this.inputs.length;e++)if(~this.inputs[e].name.indexOf(t))return this.inputs[e];return!1},n.prototype.getOctave=function(t){if(null!=t&&0<=t&&t<=127)return Math.floor(Math.floor(t)/12-1)+Math.floor(i.octaveOffset)},n.prototype.getOutputByName=function(t){if(!this.enabled)throw new Error("WebMidi is not enabled.");for(var e=0;e<this.outputs.length;e++)if(~this.outputs[e].name.indexOf(t))return this.outputs[e];return!1},n.prototype.guessNoteNumber=function(t){var e=!1;if(t&&t.toFixed&&0<=t&&t<=127?e=Math.round(t):0<=parseInt(t)&&parseInt(t)<=127?e=parseInt(t):("string"==typeof t||t instanceof String)&&(e=this.noteNameToNumber(t)),!1===e)throw new Error("Invalid input value ("+t+").");return e},n.prototype.noteNameToNumber=function(t){"string"!=typeof t&&(t="");var e=t.match(/([CDEFGAB])(#{0,2}|b{0,2})(-?\d+)/i);if(!e)throw new RangeError("Invalid note name.");var n=i._semitones[e[1].toUpperCase()],s=12*(parseInt(e[3])+1-Math.floor(i.octaveOffset))+n;if(-1<e[2].toLowerCase().indexOf("b")?s-=e[2].length:-1<e[2].toLowerCase().indexOf("#")&&(s+=e[2].length),s<0||127<s)throw new RangeError("Invalid note name or note outside valid range.");return s},n.prototype._updateInputsAndOutputs=function(){this._updateInputs(),this._updateOutputs()},n.prototype._updateInputs=function(){for(var t=0;t<this._inputs.length;t++){for(var e=!0,n=this.interface.inputs.values(),i=n.next();i&&!i.done;i=n.next())if(this._inputs[t]._midiInput===i.value){e=!1;break}e&&this._inputs.splice(t,1)}this.interface&&this.interface.inputs.forEach(function(t){for(var e=!0,n=0;n<this._inputs.length;n++)this._inputs[n]._midiInput===t&&(e=!1);e&&this._inputs.push(new s(t))}.bind(this))},n.prototype._updateOutputs=function(){for(var t=0;t<this._outputs.length;t++){for(var e=!0,n=this.interface.outputs.values(),i=n.next();i&&!i.done;i=n.next())if(this._outputs[t]._midiOutput===i.value){e=!1;break}e&&this._outputs.splice(t,1)}this.interface&&this.interface.outputs.forEach(function(t){for(var e=!0,n=0;n<this._outputs.length;n++)this._outputs[n]._midiOutput===t&&(e=!1);e&&this._outputs.push(new r(t))}.bind(this))},n.prototype._onInterfaceStateChange=function(t){this._updateInputsAndOutputs();var e={timestamp:t.timeStamp,type:t.port.state};this.interface&&"connected"===t.port.state?"output"===t.port.type?e.port=this.getOutputById(t.port.id):"input"===t.port.type&&(e.port=this.getInputById(t.port.id)):e.port={connection:"closed",id:t.port.id,manufacturer:t.port.manufacturer,name:t.port.name,state:t.port.state,type:t.port.type},this._userHandlers[t.port.state].forEach((function(t){t(e)}))},n.prototype._resetInterfaceUserHandlers=function(){for(var t=0;t<this._midiInterfaceEvents.length;t++)this._userHandlers[this._midiInterfaceEvents[t]]=[]},s.prototype.on=s.prototype.addListener=function(t,e,n){var s=this;if(void 0===e&&(e="all"),Array.isArray(e)||(e=[e]),e.forEach((function(t){if("all"!==t&&!(1<=t&&t<=16))throw new RangeError("The 'channel' parameter is invalid.")})),"function"!=typeof n)throw new TypeError("The 'listener' parameter must be a function.");if(void 0!==i.MIDI_SYSTEM_MESSAGES[t])this._userHandlers.system[t]||(this._userHandlers.system[t]=[]),this._userHandlers.system[t].push(n);else{if(void 0===i.MIDI_CHANNEL_MESSAGES[t])throw new TypeError("The specified event type is not supported.");if(-1<e.indexOf("all")){e=[];for(var r=1;r<=16;r++)e.push(r)}this._userHandlers.channel[t]||(this._userHandlers.channel[t]=[]),e.forEach((function(e){s._userHandlers.channel[t][e]||(s._userHandlers.channel[t][e]=[]),s._userHandlers.channel[t][e].push(n)}))}return this},s.prototype.hasListener=function(t,e,n){var s=this;if("function"!=typeof n)throw new TypeError("The 'listener' parameter must be a function.");if(void 0===e&&(e="all"),e.constructor!==Array&&(e=[e]),void 0!==i.MIDI_SYSTEM_MESSAGES[t]){for(var r=0;r<this._userHandlers.system[t].length;r++)if(this._userHandlers.system[t][r]===n)return!0}else if(void 0!==i.MIDI_CHANNEL_MESSAGES[t]){if(-1<e.indexOf("all")){e=[];for(var o=1;o<=16;o++)e.push(o)}return!!this._userHandlers.channel[t]&&e.every((function(e){var i=s._userHandlers.channel[t][e];return i&&-1<i.indexOf(n)}))}return!1},s.prototype.removeListener=function(t,e,n){var s=this;if(void 0!==n&&"function"!=typeof n)throw new TypeError("The 'listener' parameter must be a function.");if(void 0===e&&(e="all"),e.constructor!==Array&&(e=[e]),void 0!==i.MIDI_SYSTEM_MESSAGES[t])if(void 0===n)this._userHandlers.system[t]=[];else for(var r=0;r<this._userHandlers.system[t].length;r++)this._userHandlers.system[t][r]===n&&this._userHandlers.system[t].splice(r,1);else if(void 0!==i.MIDI_CHANNEL_MESSAGES[t]){if(-1<e.indexOf("all")){e=[];for(var o=1;o<=16;o++)e.push(o)}if(!this._userHandlers.channel[t])return this;e.forEach((function(e){var i=s._userHandlers.channel[t][e];if(i)if(void 0===n)s._userHandlers.channel[t][e]=[];else for(var r=0;r<i.length;r++)i[r]===n&&i.splice(r,1)}))}else{if(void 0!==t)throw new TypeError("The specified event type is not supported.");this._initializeUserHandlers()}return this},s.prototype._initializeUserHandlers=function(){for(var t in i.MIDI_CHANNEL_MESSAGES)Object.prototype.hasOwnProperty.call(i.MIDI_CHANNEL_MESSAGES,t)&&(this._userHandlers.channel[t]={});for(var e in i.MIDI_SYSTEM_MESSAGES)Object.prototype.hasOwnProperty.call(i.MIDI_SYSTEM_MESSAGES,e)&&(this._userHandlers.system[e]=[])},s.prototype._onMidiMessage=function(t){if(0<this._userHandlers.system.midimessage.length){var e={target:this,data:t.data,timestamp:t.timeStamp,type:"midimessage"};this._userHandlers.system.midimessage.forEach((function(t){t(e)}))}t.data[0]<240?(this._parseChannelEvent(t),this._parseNrpnEvent(t)):t.data[0]<=255&&this._parseSystemEvent(t)},s.prototype._parseNrpnEvent=function(t){var e,n,s=t.data[0]>>4,r=15&t.data[0],o=1+r;if(1<t.data.length&&(e=t.data[1],n=2<t.data.length?t.data[2]:void 0),i.nrpnEventsEnabled&&s===i.MIDI_CHANNEL_MESSAGES.controlchange&&(e>=i.MIDI_NRPN_MESSAGES.increment&&e<=i.MIDI_NRPN_MESSAGES.parammsb||e===i.MIDI_NRPN_MESSAGES.entrymsb||e===i.MIDI_NRPN_MESSAGES.entrylsb)){var a={target:this,type:"controlchange",data:t.data,timestamp:t.timeStamp,channel:o,controller:{number:e,name:this.getCcNameByNumber(e)},value:n};if(a.controller.number===i.MIDI_NRPN_MESSAGES.parammsb&&a.value!=i.MIDI_NRPN_MESSAGES.nullactiveparameter)i._nrpnBuffer[r]=[],i._nrpnBuffer[r][0]=a;else if(1===i._nrpnBuffer[r].length&&a.controller.number===i.MIDI_NRPN_MESSAGES.paramlsb)i._nrpnBuffer[r].push(a);else if(2!==i._nrpnBuffer[r].length||a.controller.number!==i.MIDI_NRPN_MESSAGES.increment&&a.controller.number!==i.MIDI_NRPN_MESSAGES.decrement&&a.controller.number!==i.MIDI_NRPN_MESSAGES.entrymsb)if(3===i._nrpnBuffer[r].length&&i._nrpnBuffer[r][2].number===i.MIDI_NRPN_MESSAGES.entrymsb&&a.controller.number===i.MIDI_NRPN_MESSAGES.entrylsb)i._nrpnBuffer[r].push(a);else if(3<=i._nrpnBuffer[r].length&&i._nrpnBuffer[r].length<=4&&a.controller.number===i.MIDI_NRPN_MESSAGES.parammsb&&a.value===i.MIDI_NRPN_MESSAGES.nullactiveparameter)i._nrpnBuffer[r].push(a);else if(4<=i._nrpnBuffer[r].length&&i._nrpnBuffer[r].length<=5&&a.controller.number===i.MIDI_NRPN_MESSAGES.paramlsb&&a.value===i.MIDI_NRPN_MESSAGES.nullactiveparameter){i._nrpnBuffer[r].push(a);var c=[];i._nrpnBuffer[r].forEach((function(t){c.push(t.data)}));var l=i._nrpnBuffer[r][0].value<<7|i._nrpnBuffer[r][1].value,h=i._nrpnBuffer[r][2].value;6===i._nrpnBuffer[r].length&&(h=i._nrpnBuffer[r][2].value<<7|i._nrpnBuffer[r][3].value);var u="";switch(i._nrpnBuffer[r][2].controller.number){case i.MIDI_NRPN_MESSAGES.entrymsb:u=i._nrpnTypes[0];break;case i.MIDI_NRPN_MESSAGES.increment:u=i._nrpnTypes[1];break;case i.MIDI_NRPN_MESSAGES.decrement:u=i._nrpnTypes[2];break;default:throw new Error("The NPRN type was unidentifiable.")}var d={timestamp:a.timestamp,channel:a.channel,type:"nrpn",data:c,controller:{number:l,type:u,name:"Non-Registered Parameter "+l},value:h};i._nrpnBuffer[r]=[],this._userHandlers.channel[d.type]&&this._userHandlers.channel[d.type][d.channel]&&this._userHandlers.channel[d.type][d.channel].forEach((function(t){t(d)}))}else i._nrpnBuffer[r]=[];else i._nrpnBuffer[r].push(a)}},s.prototype._parseChannelEvent=function(t){var e,n,s=t.data[0]>>4,r=1+(15&t.data[0]);1<t.data.length&&(e=t.data[1],n=2<t.data.length?t.data[2]:void 0);var o={target:this,data:t.data,timestamp:t.timeStamp,channel:r};s===i.MIDI_CHANNEL_MESSAGES.noteoff||s===i.MIDI_CHANNEL_MESSAGES.noteon&&0===n?(o.type="noteoff",o.note={number:e,name:i._notes[e%12],octave:i.getOctave(e)},o.velocity=n/127,o.rawVelocity=n):s===i.MIDI_CHANNEL_MESSAGES.noteon?(o.type="noteon",o.note={number:e,name:i._notes[e%12],octave:i.getOctave(e)},o.velocity=n/127,o.rawVelocity=n):s===i.MIDI_CHANNEL_MESSAGES.keyaftertouch?(o.type="keyaftertouch",o.note={number:e,name:i._notes[e%12],octave:i.getOctave(e)},o.value=n/127):s===i.MIDI_CHANNEL_MESSAGES.controlchange&&0<=e&&e<=119?(o.type="controlchange",o.controller={number:e,name:this.getCcNameByNumber(e)},o.value=n):s===i.MIDI_CHANNEL_MESSAGES.channelmode&&120<=e&&e<=127?(o.type="channelmode",o.controller={number:e,name:this.getChannelModeByNumber(e)},o.value=n):s===i.MIDI_CHANNEL_MESSAGES.programchange?(o.type="programchange",o.value=e):s===i.MIDI_CHANNEL_MESSAGES.channelaftertouch?(o.type="channelaftertouch",o.value=e/127):s===i.MIDI_CHANNEL_MESSAGES.pitchbend?(o.type="pitchbend",o.value=((n<<7)+e-8192)/8192):o.type="unknownchannelmessage",this._userHandlers.channel[o.type]&&this._userHandlers.channel[o.type][r]&&this._userHandlers.channel[o.type][r].forEach((function(t){t(o)}))},s.prototype.getCcNameByNumber=function(t){if(!(0<=(t=Math.floor(t))&&t<=119))throw new RangeError("The control change number must be between 0 and 119.");for(var e in i.MIDI_CONTROL_CHANGE_MESSAGES)if(Object.prototype.hasOwnProperty.call(i.MIDI_CONTROL_CHANGE_MESSAGES,e)&&t===i.MIDI_CONTROL_CHANGE_MESSAGES[e])return e},s.prototype.getChannelModeByNumber=function(t){if(!(120<=(t=Math.floor(t))&&status<=127))throw new RangeError("The control change number must be between 120 and 127.");for(var e in i.MIDI_CHANNEL_MODE_MESSAGES)if(Object.prototype.hasOwnProperty.call(i.MIDI_CHANNEL_MODE_MESSAGES,e)&&t===i.MIDI_CHANNEL_MODE_MESSAGES[e])return e},s.prototype._parseSystemEvent=function(t){var e=t.data[0],n={target:this,data:t.data,timestamp:t.timeStamp};e===i.MIDI_SYSTEM_MESSAGES.sysex?n.type="sysex":e===i.MIDI_SYSTEM_MESSAGES.timecode?n.type="timecode":e===i.MIDI_SYSTEM_MESSAGES.songposition?n.type="songposition":e===i.MIDI_SYSTEM_MESSAGES.songselect?(n.type="songselect",n.song=t.data[1]):e===i.MIDI_SYSTEM_MESSAGES.tuningrequest?n.type="tuningrequest":e===i.MIDI_SYSTEM_MESSAGES.clock?n.type="clock":e===i.MIDI_SYSTEM_MESSAGES.start?n.type="start":e===i.MIDI_SYSTEM_MESSAGES.continue?n.type="continue":e===i.MIDI_SYSTEM_MESSAGES.stop?n.type="stop":e===i.MIDI_SYSTEM_MESSAGES.activesensing?n.type="activesensing":e===i.MIDI_SYSTEM_MESSAGES.reset?n.type="reset":n.type="unknownsystemmessage",this._userHandlers.system[n.type]&&this._userHandlers.system[n.type].forEach((function(t){t(n)}))},r.prototype.send=function(t,e,n){if(!(128<=t&&t<=255))throw new RangeError("The status byte must be an integer between 128 (0x80) and 255 (0xFF).");void 0===e&&(e=[]),Array.isArray(e)||(e=[e]);var i=[];return e.forEach((function(t){var e=Math.floor(t);if(!(0<=e&&e<=255))throw new RangeError("Data bytes must be integers between 0 (0x00) and 255 (0xFF).");i.push(e)})),this._midiOutput.send([t].concat(i),parseFloat(n)||0),this},r.prototype.sendSysex=function(t,e,n){if(!i.sysexEnabled)throw new Error("Sysex message support must first be activated.");return n=n||{},t=[].concat(t),e.forEach((function(t){if(t<0||127<t)throw new RangeError("The data bytes of a sysex message must be integers between 0 (0x00) and 127 (0x7F).")})),e=t.concat(e,i.MIDI_SYSTEM_MESSAGES.sysexend),this.send(i.MIDI_SYSTEM_MESSAGES.sysex,e,this._parseTimeParameter(n.time)),this},r.prototype.sendTimecodeQuarterFrame=function(t,e){return e=e||{},this.send(i.MIDI_SYSTEM_MESSAGES.timecode,t,this._parseTimeParameter(e.time)),this},r.prototype.sendSongPosition=function(t,e){e=e||{};var n=(t=Math.floor(t)||0)>>7&127,s=127&t;return this.send(i.MIDI_SYSTEM_MESSAGES.songposition,[n,s],this._parseTimeParameter(e.time)),this},r.prototype.sendSongSelect=function(t,e){if(e=e||{},!(0<=(t=Math.floor(t))&&t<=127))throw new RangeError("The song number must be between 0 and 127.");return this.send(i.MIDI_SYSTEM_MESSAGES.songselect,[t],this._parseTimeParameter(e.time)),this},r.prototype.sendTuningRequest=function(t){return t=t||{},this.send(i.MIDI_SYSTEM_MESSAGES.tuningrequest,void 0,this._parseTimeParameter(t.time)),this},r.prototype.sendClock=function(t){return t=t||{},this.send(i.MIDI_SYSTEM_MESSAGES.clock,void 0,this._parseTimeParameter(t.time)),this},r.prototype.sendStart=function(t){return t=t||{},this.send(i.MIDI_SYSTEM_MESSAGES.start,void 0,this._parseTimeParameter(t.time)),this},r.prototype.sendContinue=function(t){return t=t||{},this.send(i.MIDI_SYSTEM_MESSAGES.continue,void 0,this._parseTimeParameter(t.time)),this},r.prototype.sendStop=function(t){return t=t||{},this.send(i.MIDI_SYSTEM_MESSAGES.stop,void 0,this._parseTimeParameter(t.time)),this},r.prototype.sendActiveSensing=function(t){return t=t||{},this.send(i.MIDI_SYSTEM_MESSAGES.activesensing,[],this._parseTimeParameter(t.time)),this},r.prototype.sendReset=function(t){return t=t||{},this.send(i.MIDI_SYSTEM_MESSAGES.reset,void 0,this._parseTimeParameter(t.time)),this},r.prototype.stopNote=function(t,e,n){if("all"===t)return this.sendChannelMode("allnotesoff",0,e,n);var s=64;return(n=n||{}).rawVelocity?!isNaN(n.velocity)&&0<=n.velocity&&n.velocity<=127&&(s=n.velocity):!isNaN(n.velocity)&&0<=n.velocity&&n.velocity<=1&&(s=127*n.velocity),this._convertNoteToArray(t).forEach(function(t){i.toMIDIChannels(e).forEach(function(e){this.send((i.MIDI_CHANNEL_MESSAGES.noteoff<<4)+(e-1),[t,Math.round(s)],this._parseTimeParameter(n.time))}.bind(this))}.bind(this)),this},r.prototype.playNote=function(t,e,n){var s,r=64;if((n=n||{}).rawVelocity?!isNaN(n.velocity)&&0<=n.velocity&&n.velocity<=127&&(r=n.velocity):!isNaN(n.velocity)&&0<=n.velocity&&n.velocity<=1&&(r=127*n.velocity),s=this._parseTimeParameter(n.time),this._convertNoteToArray(t).forEach(function(t){i.toMIDIChannels(e).forEach(function(e){this.send((i.MIDI_CHANNEL_MESSAGES.noteon<<4)+(e-1),[t,Math.round(r)],s)}.bind(this))}.bind(this)),!isNaN(n.duration)){n.duration<=0&&(n.duration=0);var o=64;n.rawVelocity?!isNaN(n.release)&&0<=n.release&&n.release<=127&&(o=n.release):!isNaN(n.release)&&0<=n.release&&n.release<=1&&(o=127*n.release),this._convertNoteToArray(t).forEach(function(t){i.toMIDIChannels(e).forEach(function(e){this.send((i.MIDI_CHANNEL_MESSAGES.noteoff<<4)+(e-1),[t,Math.round(o)],(s||i.time)+n.duration)}.bind(this))}.bind(this))}return this},r.prototype.sendKeyAftertouch=function(t,e,n,s){var r=this;if(s=s||{},e<1||16<e)throw new RangeError("The channel must be between 1 and 16.");(isNaN(n)||n<0||1<n)&&(n=.5);var o=Math.round(127*n);return this._convertNoteToArray(t).forEach((function(t){i.toMIDIChannels(e).forEach((function(e){r.send((i.MIDI_CHANNEL_MESSAGES.keyaftertouch<<4)+(e-1),[t,o],r._parseTimeParameter(s.time))}))})),this},r.prototype.sendControlChange=function(t,e,n,s){if(s=s||{},"string"==typeof t){if(void 0===(t=i.MIDI_CONTROL_CHANGE_MESSAGES[t]))throw new TypeError("Invalid controller name.")}else if(!(0<=(t=Math.floor(t))&&t<=119))throw new RangeError("Controller numbers must be between 0 and 119.");if(!(0<=(e=Math.floor(e)||0)&&e<=127))throw new RangeError("Controller value must be between 0 and 127.");return i.toMIDIChannels(n).forEach(function(n){this.send((i.MIDI_CHANNEL_MESSAGES.controlchange<<4)+(n-1),[t,e],this._parseTimeParameter(s.time))}.bind(this)),this},r.prototype._selectRegisteredParameter=function(t,e,n){var s=this;if(t[0]=Math.floor(t[0]),!(0<=t[0]&&t[0]<=127))throw new RangeError("The control65 value must be between 0 and 127");if(t[1]=Math.floor(t[1]),!(0<=t[1]&&t[1]<=127))throw new RangeError("The control64 value must be between 0 and 127");return i.toMIDIChannels(e).forEach((function(){s.sendControlChange(101,t[0],e,{time:n}),s.sendControlChange(100,t[1],e,{time:n})})),this},r.prototype._selectNonRegisteredParameter=function(t,e,n){var s=this;if(t[0]=Math.floor(t[0]),!(0<=t[0]&&t[0]<=127))throw new RangeError("The control63 value must be between 0 and 127");if(t[1]=Math.floor(t[1]),!(0<=t[1]&&t[1]<=127))throw new RangeError("The control62 value must be between 0 and 127");return i.toMIDIChannels(e).forEach((function(){s.sendControlChange(99,t[0],e,{time:n}),s.sendControlChange(98,t[1],e,{time:n})})),this},r.prototype._setCurrentRegisteredParameter=function(t,e,n){var s=this;if((t=[].concat(t))[0]=Math.floor(t[0]),!(0<=t[0]&&t[0]<=127))throw new RangeError("The msb value must be between 0 and 127");return i.toMIDIChannels(e).forEach((function(){s.sendControlChange(6,t[0],e,{time:n})})),t[1]=Math.floor(t[1]),0<=t[1]&&t[1]<=127&&i.toMIDIChannels(e).forEach((function(){s.sendControlChange(38,t[1],e,{time:n})})),this},r.prototype._deselectRegisteredParameter=function(t,e){var n=this;return i.toMIDIChannels(t).forEach((function(){n.sendControlChange(101,127,t,{time:e}),n.sendControlChange(100,127,t,{time:e})})),this},r.prototype.setRegisteredParameter=function(t,e,n,s){var r=this;if(s=s||{},!Array.isArray(t)){if(!i.MIDI_REGISTERED_PARAMETER[t])throw new Error("The specified parameter is not available.");t=i.MIDI_REGISTERED_PARAMETER[t]}return i.toMIDIChannels(n).forEach((function(){r._selectRegisteredParameter(t,n,s.time),r._setCurrentRegisteredParameter(e,n,s.time),r._deselectRegisteredParameter(n,s.time)})),this},r.prototype.setNonRegisteredParameter=function(t,e,n,s){var r=this;if(s=s||{},!(0<=t[0]&&t[0]<=127&&0<=t[1]&&t[1]<=127))throw new Error("Position 0 and 1 of the 2-position parameter array must both be between 0 and 127.");return e=[].concat(e),i.toMIDIChannels(n).forEach((function(){r._selectNonRegisteredParameter(t,n,s.time),r._setCurrentRegisteredParameter(e,n,s.time),r._deselectRegisteredParameter(n,s.time)})),this},r.prototype.incrementRegisteredParameter=function(t,e,n){var s=this;if(n=n||{},!Array.isArray(t)){if(!i.MIDI_REGISTERED_PARAMETER[t])throw new Error("The specified parameter is not available.");t=i.MIDI_REGISTERED_PARAMETER[t]}return i.toMIDIChannels(e).forEach((function(){s._selectRegisteredParameter(t,e,n.time),s.sendControlChange(96,0,e,{time:n.time}),s._deselectRegisteredParameter(e,n.time)})),this},r.prototype.decrementRegisteredParameter=function(t,e,n){if(n=n||{},!Array.isArray(t)){if(!i.MIDI_REGISTERED_PARAMETER[t])throw new TypeError("The specified parameter is not available.");t=i.MIDI_REGISTERED_PARAMETER[t]}return i.toMIDIChannels(e).forEach(function(){this._selectRegisteredParameter(t,e,n.time),this.sendControlChange(97,0,e,{time:n.time}),this._deselectRegisteredParameter(e,n.time)}.bind(this)),this},r.prototype.setPitchBendRange=function(t,e,n,s){var r=this;if(s=s||{},!(0<=(t=Math.floor(t)||0)&&t<=127))throw new RangeError("The semitones value must be between 0 and 127");if(!(0<=(e=Math.floor(e)||0)&&e<=127))throw new RangeError("The cents value must be between 0 and 127");return i.toMIDIChannels(n).forEach((function(){r.setRegisteredParameter("pitchbendrange",[t,e],n,{time:s.time})})),this},r.prototype.setModulationRange=function(t,e,n,s){var r=this;if(s=s||{},!(0<=(t=Math.floor(t)||0)&&t<=127))throw new RangeError("The semitones value must be between 0 and 127");if(!(0<=(e=Math.floor(e)||0)&&e<=127))throw new RangeError("The cents value must be between 0 and 127");return i.toMIDIChannels(n).forEach((function(){r.setRegisteredParameter("modulationrange",[t,e],n,{time:s.time})})),this},r.prototype.setMasterTuning=function(t,e,n){var s=this;if(n=n||{},(t=parseFloat(t)||0)<=-65||64<=t)throw new RangeError("The value must be a decimal number larger than -65 and smaller than 64.");var r=Math.floor(t)+64,o=t-Math.floor(t),a=(o=Math.round((o+1)/2*16383))>>7&127,c=127&o;return i.toMIDIChannels(e).forEach((function(){s.setRegisteredParameter("channelcoarsetuning",r,e,{time:n.time}),s.setRegisteredParameter("channelfinetuning",[a,c],e,{time:n.time})})),this},r.prototype.setTuningProgram=function(t,e,n){var s=this;if(n=n||{},!(0<=(t=Math.floor(t))&&t<=127))throw new RangeError("The program value must be between 0 and 127");return i.toMIDIChannels(e).forEach((function(){s.setRegisteredParameter("tuningprogram",t,e,{time:n.time})})),this},r.prototype.setTuningBank=function(t,e,n){var s=this;if(n=n||{},!(0<=(t=Math.floor(t)||0)&&t<=127))throw new RangeError("The bank value must be between 0 and 127");return i.toMIDIChannels(e).forEach((function(){s.setRegisteredParameter("tuningbank",t,e,{time:n.time})})),this},r.prototype.sendChannelMode=function(t,e,n,s){if(s=s||{},"string"==typeof t){if(!(t=i.MIDI_CHANNEL_MODE_MESSAGES[t]))throw new TypeError("Invalid channel mode message name.")}else if(!(120<=(t=Math.floor(t))&&t<=127))throw new RangeError("Channel mode numerical identifiers must be between 120 and 127.");if((e=Math.floor(e)||0)<0||127<e)throw new RangeError("Value must be an integer between 0 and 127.");return i.toMIDIChannels(n).forEach(function(n){this.send((i.MIDI_CHANNEL_MESSAGES.channelmode<<4)+(n-1),[t,e],this._parseTimeParameter(s.time))}.bind(this)),this},r.prototype.sendProgramChange=function(t,e,n){var s=this;if(n=n||{},t=Math.floor(t),isNaN(t)||t<0||127<t)throw new RangeError("Program numbers must be between 0 and 127.");return i.toMIDIChannels(e).forEach((function(e){s.send((i.MIDI_CHANNEL_MESSAGES.programchange<<4)+(e-1),[t],s._parseTimeParameter(n.time))})),this},r.prototype.sendChannelAftertouch=function(t,e,n){var s=this;n=n||{},t=parseFloat(t),(isNaN(t)||t<0||1<t)&&(t=.5);var r=Math.round(127*t);return i.toMIDIChannels(e).forEach((function(t){s.send((i.MIDI_CHANNEL_MESSAGES.channelaftertouch<<4)+(t-1),[r],s._parseTimeParameter(n.time))})),this},r.prototype.sendPitchBend=function(t,e,n){var s=this;if(n=n||{},isNaN(t)||t<-1||1<t)throw new RangeError("Pitch bend value must be between -1 and 1.");var r=Math.round((t+1)/2*16383),o=r>>7&127,a=127&r;return i.toMIDIChannels(e).forEach((function(t){s.send((i.MIDI_CHANNEL_MESSAGES.pitchbend<<4)+(t-1),[a,o],s._parseTimeParameter(n.time))})),this},r.prototype._parseTimeParameter=function(t){var e,n=parseFloat(t);return"string"==typeof t&&"+"===t.substring(0,1)?n&&0<n&&(e=i.time+n):n>i.time&&(e=n),e},r.prototype._convertNoteToArray=function(t){var e=[];return Array.isArray(t)||(t=[t]),t.forEach((function(t){e.push(i.guessNoteNumber(t))})),e},t.exports?t.exports=i:e.WebMidi||(e.WebMidi=i)}(Lt)}));function Vt(){const t=tt();return e=>{const n=Object.keys(t.$$.callbacks),i=[];return n.forEach((n=>i.push(I(e,n,(e=>et(t,e)))))),{destroy:()=>{i.forEach((t=>t()))}}}}const Wt=t=>({}),Ht=t=>({}),Gt=t=>({}),zt=t=>({}),Yt=t=>({}),Xt=t=>({});function Ut(t){let e,i,s,r,o,a,c=t[1]&&function(t){let e,n;const i=t[6].left,s=u(i,t,t[5],Xt);return{c(){e=A("div"),s&&s.c(),D(e,"class","nav-left")},m(t,i){S(t,e,i),s&&s.m(e,null),n=!0},p(t,e){s&&s.p&&(!n||32&e)&&f(s,i,t,t[5],e,Yt,Xt)},i(t){n||(xt(s,t),n=!0)},o(t){Ct(s,t),n=!1},d(t){t&&T(e),s&&s.d(t)}}}(t),l=t[2]&&function(t){let e,n;const i=t[6].center,s=u(i,t,t[5],zt);return{c(){e=A("div"),s&&s.c(),D(e,"class","nav-center")},m(t,i){S(t,e,i),s&&s.m(e,null),n=!0},p(t,e){s&&s.p&&(!n||32&e)&&f(s,i,t,t[5],e,Gt,zt)},i(t){n||(xt(s,t),n=!0)},o(t){Ct(s,t),n=!1},d(t){t&&T(e),s&&s.d(t)}}}(t),h=t[3]&&function(t){let e,n;const i=t[6].right,s=u(i,t,t[5],Ht);return{c(){e=A("div"),s&&s.c(),D(e,"class","nav-right")},m(t,i){S(t,e,i),s&&s.m(e,null),n=!0},p(t,e){s&&s.p&&(!n||32&e)&&f(s,i,t,t[5],e,Wt,Ht)},i(t){n||(xt(s,t),n=!0)},o(t){Ct(s,t),n=!1},d(t){t&&T(e),s&&s.d(t)}}}(t),d=[t[4]],p={};for(let t=0;t<d.length;t+=1)p=n(p,d[t]);return{c(){e=A("nav"),c&&c.c(),i=k(),l&&l.c(),s=k(),h&&h.c(),R(e,p),G(e,"nav",1),G(e,"svelte-a8gbht",!0)},m(n,u){S(n,e,u),c&&c.m(e,null),w(e,i),l&&l.m(e,null),w(e,s),h&&h.m(e,null),r=!0,o||(a=g(t[0].call(null,e)),o=!0)},p(t,[n]){t[1]&&c.p(t,n),t[2]&&l.p(t,n),t[3]&&h.p(t,n),R(e,p=Et(d,[16&n&&t[4]])),G(e,"nav",1),G(e,"svelte-a8gbht",!0)},i(t){r||(xt(c),xt(l),xt(h),r=!0)},o(t){Ct(c),Ct(l),Ct(h),r=!1},d(t){t&&T(e),c&&c.d(),l&&l.d(),h&&h.d(),o=!1,a()}}}function qt(t,e,i){const s=[];let r=m(e,s),{$$slots:o={},$$scope:a}=e;const c=Vt();let l=e.$$slots&&void 0!==e.$$slots.left,h=e.$$slots&&void 0!==e.$$slots.center,u=e.$$slots&&void 0!==e.$$slots.right;return t.$$set=t=>{i(7,e=n(n({},e),p(t))),i(4,r=m(e,s)),"$$scope"in t&&i(5,a=t.$$scope)},e=p(e),[c,l,h,u,r,a,o]}class Kt extends $t{constructor(t){super(),jt(this,t,qt,Ut,a,{})}}function Zt(t){let e,i,s,r;const o=t[4].default,a=u(o,t,t[3],null);let c=[t[2]],l={};for(let t=0;t<c.length;t+=1)l=n(l,c[t]);return{c(){e=A("div"),a&&a.c(),R(e,l),G(e,"row",1),G(e,"reverse",t[0])},m(n,o){S(n,e,o),a&&a.m(e,null),i=!0,s||(r=g(t[1].call(null,e)),s=!0)},p(t,[n]){a&&a.p&&(!i||8&n)&&f(a,o,t,t[3],n,null,null),R(e,l=Et(c,[4&n&&t[2]])),G(e,"row",1),G(e,"reverse",t[0])},i(t){i||(xt(a,t),i=!0)},o(t){Ct(a,t),i=!1},d(t){t&&T(e),a&&a.d(t),s=!1,r()}}}function Qt(t,e,i){const s=["reverse"];let r=m(e,s),{$$slots:o={},$$scope:a}=e,{reverse:c=!1}=e;const l=Vt();return t.$$set=t=>{e=n(n({},e),p(t)),i(2,r=m(e,s)),"reverse"in t&&i(0,c=t.reverse),"$$scope"in t&&i(3,a=t.$$scope)},[c,l,r,a,o]}class Jt extends $t{constructor(t){super(),jt(this,t,Qt,Zt,a,{reverse:0})}}function te(t){let e,i,s,r;const o=t[7].default,a=u(o,t,t[6],null);let c=[t[2],{class:t[0]}],l={};for(let t=0;t<c.length;t+=1)l=n(l,c[t]);return{c(){e=A("div"),a&&a.c(),R(e,l)},m(n,o){S(n,e,o),a&&a.m(e,null),i=!0,s||(r=g(t[1].call(null,e)),s=!0)},p(t,[n]){a&&a.p&&(!i||64&n)&&f(a,o,t,t[6],n,null,null),R(e,l=Et(c,[4&n&&t[2],(!i||1&n)&&{class:t[0]}]))},i(t){i||(xt(a,t),i=!0)},o(t){Ct(a,t),i=!1},d(t){t&&T(e),a&&a.d(t),s=!1,r()}}}function ee(t,e,i){let s;const r=["size","sizeMD","sizeLG"];let o=m(e,r),{$$slots:a={},$$scope:c}=e,{size:l=!1}=e,{sizeMD:h=!1}=e,{sizeLG:u=!1}=e;const d=Vt();function f(t,e,n){let i=[];return!l||l<1||l>12?i.push("col"):l>=1&&l<=12&&i.push(`col-${l}`),h&&h>=1&&h<=12&&i.push(`col-${h}-md`),u&&u>=1&&u<=12&&i.push(`col-${u}-lg`),i.join(" ")}return t.$$set=t=>{e=n(n({},e),p(t)),i(2,o=m(e,r)),"size"in t&&i(3,l=t.size),"sizeMD"in t&&i(4,h=t.sizeMD),"sizeLG"in t&&i(5,u=t.sizeLG),"$$scope"in t&&i(6,c=t.$$scope)},t.$$.update=()=>{i(0,s=o.hasOwnProperty("class")?o.class+" "+f():f())},[s,d,o,l,h,u,c,a]}class ne extends $t{constructor(t){super(),jt(this,t,ee,te,a,{size:3,sizeMD:4,sizeLG:5})}}const ie=t=>({}),se=t=>({}),re=t=>({}),oe=t=>({});function ae(t){let e,i,s,r,o,a,c=t[1]&&function(t){let e,n;const i=t[5].header,s=u(i,t,t[4],oe);return{c(){e=A("header"),s&&s.c()},m(t,i){S(t,e,i),s&&s.m(e,null),n=!0},p(t,e){s&&s.p&&(!n||16&e)&&f(s,i,t,t[4],e,re,oe)},i(t){n||(xt(s,t),n=!0)},o(t){Ct(s,t),n=!1},d(t){t&&T(e),s&&s.d(t)}}}(t);const l=t[5].default,h=u(l,t,t[4],null);let d=t[2]&&function(t){let e,n;const i=t[5].footer,s=u(i,t,t[4],se);return{c(){e=A("footer"),s&&s.c()},m(t,i){S(t,e,i),s&&s.m(e,null),n=!0},p(t,e){s&&s.p&&(!n||16&e)&&f(s,i,t,t[4],e,ie,se)},i(t){n||(xt(s,t),n=!0)},o(t){Ct(s,t),n=!1},d(t){t&&T(e),s&&s.d(t)}}}(t),p=[t[3]],m={};for(let t=0;t<p.length;t+=1)m=n(m,p[t]);return{c(){e=A("div"),c&&c.c(),i=k(),h&&h.c(),s=k(),d&&d.c(),R(e,m),G(e,"card",1)},m(n,l){S(n,e,l),c&&c.m(e,null),w(e,i),h&&h.m(e,null),w(e,s),d&&d.m(e,null),r=!0,o||(a=g(t[0].call(null,e)),o=!0)},p(t,[n]){t[1]&&c.p(t,n),h&&h.p&&(!r||16&n)&&f(h,l,t,t[4],n,null,null),t[2]&&d.p(t,n),R(e,m=Et(p,[8&n&&t[3]])),G(e,"card",1)},i(t){r||(xt(c),xt(h,t),xt(d),r=!0)},o(t){Ct(c),Ct(h,t),Ct(d),r=!1},d(t){t&&T(e),c&&c.d(),h&&h.d(t),d&&d.d(),o=!1,a()}}}function ce(t,e,i){const s=[];let r=m(e,s),{$$slots:o={},$$scope:a}=e;const c=Vt();let l=e.$$slots&&void 0!==e.$$slots.header,h=e.$$slots&&void 0!==e.$$slots.footer;return t.$$set=t=>{i(6,e=n(n({},e),p(t))),i(3,r=m(e,s)),"$$scope"in t&&i(4,a=t.$$scope)},e=p(e),[c,l,h,r,a,o]}class le extends $t{constructor(t){super(),jt(this,t,ce,ae,a,{})}}function he(t){let e,i,s;function r(t,e){return!1!==t[0]?pe:fe}let o=r(t),a=o(t),c=[{viewBox:"0 0 24 24"},{style:t[6]},t[9]],l={};for(let t=0;t<c.length;t+=1)l=n(l,c[t]);return{c(){e=O("svg"),a.c(),j(e,l),G(e,"svelte-1q4wean",!0)},m(n,r){S(n,e,r),a.m(e,null),i||(s=g(t[8].call(null,e)),i=!0)},p(t,n){o===(o=r(t))&&a?a.p(t,n):(a.d(1),a=o(t),a&&(a.c(),a.m(e,null))),j(e,l=Et(c,[{viewBox:"0 0 24 24"},64&n&&{style:t[6]},512&n&&t[9]])),G(e,"svelte-1q4wean",!0)},d(t){t&&T(e),a.d(),i=!1,s()}}}function ue(t){let e,i,s,r,o=[{viewBox:"0 0 24 24"},{style:t[6]},t[9]],a={};for(let t=0;t<o.length;t+=1)a=n(a,o[t]);return{c(){e=O("svg"),i=O("use"),$(i,"xlink:href",t[2]),D(i,"style",t[7]),D(i,"class","svelte-1q4wean"),G(i,"spinCW",t[4]),G(i,"spinCCW",t[5]),j(e,a),G(e,"svelte-1q4wean",!0)},m(n,o){S(n,e,o),w(e,i),s||(r=g(t[8].call(null,e)),s=!0)},p(t,n){4&n&&$(i,"xlink:href",t[2]),128&n&&D(i,"style",t[7]),16&n&&G(i,"spinCW",t[4]),32&n&&G(i,"spinCCW",t[5]),j(e,a=Et(o,[{viewBox:"0 0 24 24"},64&n&&{style:t[6]},512&n&&t[9]])),G(e,"svelte-1q4wean",!0)},d(t){t&&T(e),s=!1,r()}}}function de(t){let e,i,s,r,o,a=[{style:t[6]},t[9]],c={};for(let t=0;t<a.length;t+=1)c=n(c,a[t]);return{c(){e=A("span"),i=A("img"),i.src!==(s=t[3])&&D(i,"src",s),D(i,"alt",""),D(i,"width","100%"),D(i,"height","100%"),D(i,"style",t[7]),D(i,"class","svelte-1q4wean"),G(i,"spinCW",t[4]),G(i,"spinCCW",t[5]),R(e,c),G(e,"svelte-1q4wean",!0)},m(n,s){S(n,e,s),w(e,i),r||(o=g(t[8].call(null,e)),r=!0)},p(t,n){8&n&&i.src!==(s=t[3])&&D(i,"src",s),128&n&&D(i,"style",t[7]),16&n&&G(i,"spinCW",t[4]),32&n&&G(i,"spinCCW",t[5]),R(e,c=Et(a,[64&n&&{style:t[6]},512&n&&t[9]])),G(e,"svelte-1q4wean",!0)},d(t){t&&T(e),r=!1,o()}}}function fe(t){let e;return{c(){e=O("path"),D(e,"d",t[1])},m(t,n){S(t,e,n)},p(t,n){2&n&&D(e,"d",t[1])},d(t){t&&T(e)}}}function pe(t){let e,n;return{c(){e=O("g"),n=O("path"),D(n,"d",t[1]),D(e,"style",t[7]),D(e,"class","svelte-1q4wean"),G(e,"spinCW",t[4]),G(e,"spinCCW",t[5])},m(t,i){S(t,e,i),w(e,n)},p(t,i){2&i&&D(n,"d",t[1]),128&i&&D(e,"style",t[7]),16&i&&G(e,"spinCW",t[4]),32&i&&G(e,"spinCCW",t[5])},d(t){t&&T(e)}}}function me(e){let n;function i(t,e){return t[3]?de:t[2]?ue:he}let s=i(e),r=s(e);return{c(){r.c(),n=P()},m(t,e){r.m(t,e),S(t,n,e)},p(t,[e]){s===(s=i(t))&&r?r.p(t,e):(r.d(1),r=s(t),r&&(r.c(),r.m(n.parentNode,n)))},i:t,o:t,d(t){r.d(t),t&&T(n)}}}function ge(t,e,i){let s,r,o,a,c,l;const h=["src","size","color","flipH","flipV","rotate","spin"];let u=m(e,h);const d=Vt();let{src:f=null}=e,{size:g=1}=e,{color:v=null}=e,{flipH:_=null}=e,{flipV:y=null}=e,{rotate:b=0}=e,{spin:x=!1}=e,C=!1,w=!1,S=!1;Number(g)&&(g=Number(g));return t.$$set=t=>{e=n(n({},e),p(t)),i(9,u=m(e,h)),"src"in t&&i(11,f=t.src),"size"in t&&i(10,g=t.size),"color"in t&&i(12,v=t.color),"flipH"in t&&i(13,_=t.flipH),"flipV"in t&&i(14,y=t.flipV),"rotate"in t&&i(15,b=t.rotate),"spin"in t&&i(0,x=t.spin)},t.$$.update=()=>{2048&t.$$.dirty&&(f&&f.toLowerCase().trim().endsWith(".svg")?(i(3,S=f),i(1,C=i(2,w=!1))):f&&f.toLowerCase().trim().includes(".svg#")?(i(2,w=f),i(3,S=i(1,C=!1))):f&&(i(1,C=f),i(3,S=i(2,w=!1)))),1&t.$$.dirty&&i(16,s="boolean"!=typeof x&&x<0),1&t.$$.dirty&&i(17,r=Math.abs(!0===x?2:x)),65537&t.$$.dirty&&i(4,o=!!x&&!s),65537&t.$$.dirty&&i(5,a=!!x&&s),62464&t.$$.dirty&&i(6,c=(()=>{const t=[],e=[];if(null!==g){const t="string"==typeof g?g:1.5*g+"rem";e.push(["width",t]),e.push(["height",t])}return e.push(["fill",null!==v?v:"currentColor"]),_&&t.push("scaleX(-1)"),y&&t.push("scaleY(-1)"),0!=b&&t.push(`rotate(${b}deg)`),t.length>0&&(e.push(["transform",t.join(" ")]),e.push(["transform-origin","center"])),e.reduce(((t,e)=>`${t} ${e[0]}:${e[1]};`),"")})()),131073&t.$$.dirty&&i(7,l=x?`animation-duration: ${r}s`:void 0)},[x,C,w,S,o,a,c,l,d,u,g,f,v,_,y,b,s,r]}class ve extends $t{constructor(t){super(),jt(this,t,ge,me,a,{src:11,size:10,color:12,flipH:13,flipV:14,rotate:15,spin:0})}}function _e(t){let e,i,s,a,c,l,h,u,d,f,p,m=(!0!==t[11]?t[11]:"")+"",v=t[9]&&be(t),_=t[10]&&xe(t),y=[t[17]],b={};for(let t=0;t<y.length;t+=1)b=n(b,y[t]);return h=new le({props:{style:"z-index:1",$$slots:{default:[Ce]},$$scope:{ctx:t}}}),{c(){e=A("details"),i=A("summary"),v&&v.c(),s=k(),a=E(m),c=k(),_&&_.c(),l=k(),Pt(h.$$.fragment),R(i,b),G(i,"button",1),G(i,"outline",t[1]),G(i,"primary",t[2]),G(i,"secondary",t[3]),G(i,"dark",t[4]),G(i,"error",t[5]),G(i,"success",t[6]),G(i,"clear",t[7]),G(i,"loading",t[8]),G(i,"icon",t[14]),G(i,"icon-only",t[15]),G(i,"svelte-1o5ccdl",!0),D(e,"class","dropdown")},m(n,r){S(n,e,r),w(e,i),v&&v.m(i,null),w(i,s),w(i,a),w(i,c),_&&_.m(i,null),w(e,l),It(h,e,null),e.open=t[0],d=!0,f||(p=[g(t[16].call(null,i)),I(e,"toggle",t[19]),g(u=Me.call(null,e,t[12]))],f=!0)},p(t,n){t[9]?v?(v.p(t,n),512&n&&xt(v,1)):(v=be(t),v.c(),xt(v,1),v.m(i,s)):v&&(yt(),Ct(v,1,1,(()=>{v=null})),bt()),(!d||2048&n)&&m!==(m=(!0!==t[11]?t[11]:"")+"")&&L(a,m),t[10]?_?(_.p(t,n),1024&n&&xt(_,1)):(_=xe(t),_.c(),xt(_,1),_.m(i,null)):_&&(yt(),Ct(_,1,1,(()=>{_=null})),bt()),R(i,b=Et(y,[131072&n&&t[17]])),G(i,"button",1),G(i,"outline",t[1]),G(i,"primary",t[2]),G(i,"secondary",t[3]),G(i,"dark",t[4]),G(i,"error",t[5]),G(i,"success",t[6]),G(i,"clear",t[7]),G(i,"loading",t[8]),G(i,"icon",t[14]),G(i,"icon-only",t[15]),G(i,"svelte-1o5ccdl",!0);const r={};1048576&n&&(r.$$scope={dirty:n,ctx:t}),h.$set(r),1&n&&(e.open=t[0]),u&&o(u.update)&&4096&n&&u.update.call(null,t[12])},i(t){d||(xt(v),xt(_),xt(h.$$.fragment,t),d=!0)},o(t){Ct(v),Ct(_),Ct(h.$$.fragment,t),d=!1},d(t){t&&T(e),v&&v.d(),_&&_.d(),Dt(h),f=!1,r(p)}}}function ye(t){let e,i,s,r,o,a,c,l=t[9]&&we(t);const h=t[18].default,d=u(h,t,t[20],null);let p=t[10]&&Se(t),m=[t[17],{type:r=t[13]?"submit":"button"}],v={};for(let t=0;t<m.length;t+=1)v=n(v,m[t]);return{c(){e=A("button"),l&&l.c(),i=k(),d&&d.c(),s=k(),p&&p.c(),R(e,v),G(e,"button",1),G(e,"outline",t[1]),G(e,"primary",t[2]),G(e,"secondary",t[3]),G(e,"dark",t[4]),G(e,"error",t[5]),G(e,"success",t[6]),G(e,"clear",t[7]),G(e,"loading",t[8]),G(e,"icon",t[14]),G(e,"icon-only",t[15]),G(e,"svelte-1o5ccdl",!0)},m(n,r){S(n,e,r),l&&l.m(e,null),w(e,i),d&&d.m(e,null),w(e,s),p&&p.m(e,null),o=!0,a||(c=g(t[16].call(null,e)),a=!0)},p(t,n){t[9]?l?(l.p(t,n),512&n&&xt(l,1)):(l=we(t),l.c(),xt(l,1),l.m(e,i)):l&&(yt(),Ct(l,1,1,(()=>{l=null})),bt()),d&&d.p&&(!o||1048576&n)&&f(d,h,t,t[20],n,null,null),t[10]?p?(p.p(t,n),1024&n&&xt(p,1)):(p=Se(t),p.c(),xt(p,1),p.m(e,null)):p&&(yt(),Ct(p,1,1,(()=>{p=null})),bt()),R(e,v=Et(m,[131072&n&&t[17],(!o||8192&n&&r!==(r=t[13]?"submit":"button"))&&{type:r}])),G(e,"button",1),G(e,"outline",t[1]),G(e,"primary",t[2]),G(e,"secondary",t[3]),G(e,"dark",t[4]),G(e,"error",t[5]),G(e,"success",t[6]),G(e,"clear",t[7]),G(e,"loading",t[8]),G(e,"icon",t[14]),G(e,"icon-only",t[15]),G(e,"svelte-1o5ccdl",!0)},i(t){o||(xt(l),xt(d,t),xt(p),o=!0)},o(t){Ct(l),Ct(d,t),Ct(p),o=!1},d(t){t&&T(e),l&&l.d(),d&&d.d(t),p&&p.d(),a=!1,c()}}}function be(t){let e,n,i;return n=new ve({props:{src:t[9],size:"24px"}}),{c(){e=A("span"),Pt(n.$$.fragment),D(e,"class","lefticon svelte-1o5ccdl")},m(t,s){S(t,e,s),It(n,e,null),i=!0},p(t,e){const i={};512&e&&(i.src=t[9]),n.$set(i)},i(t){i||(xt(n.$$.fragment,t),i=!0)},o(t){Ct(n.$$.fragment,t),i=!1},d(t){t&&T(e),Dt(n)}}}function xe(t){let e,n,i;return n=new ve({props:{src:t[10],size:"24px"}}),{c(){e=A("span"),Pt(n.$$.fragment),D(e,"class","righticon svelte-1o5ccdl")},m(t,s){S(t,e,s),It(n,e,null),i=!0},p(t,e){const i={};1024&e&&(i.src=t[10]),n.$set(i)},i(t){i||(xt(n.$$.fragment,t),i=!0)},o(t){Ct(n.$$.fragment,t),i=!1},d(t){t&&T(e),Dt(n)}}}function Ce(t){let e;const n=t[18].default,i=u(n,t,t[20],null);return{c(){i&&i.c()},m(t,n){i&&i.m(t,n),e=!0},p(t,s){i&&i.p&&(!e||1048576&s)&&f(i,n,t,t[20],s,null,null)},i(t){e||(xt(i,t),e=!0)},o(t){Ct(i,t),e=!1},d(t){i&&i.d(t)}}}function we(t){let e,n,i;return n=new ve({props:{src:t[9],size:"24px"}}),{c(){e=A("span"),Pt(n.$$.fragment),D(e,"class","lefticon svelte-1o5ccdl")},m(t,s){S(t,e,s),It(n,e,null),i=!0},p(t,e){const i={};512&e&&(i.src=t[9]),n.$set(i)},i(t){i||(xt(n.$$.fragment,t),i=!0)},o(t){Ct(n.$$.fragment,t),i=!1},d(t){t&&T(e),Dt(n)}}}function Se(t){let e,n,i;return n=new ve({props:{src:t[10],size:"24px"}}),{c(){e=A("span"),Pt(n.$$.fragment),D(e,"class","righticon svelte-1o5ccdl")},m(t,s){S(t,e,s),It(n,e,null),i=!0},p(t,e){const i={};1024&e&&(i.src=t[10]),n.$set(i)},i(t){i||(xt(n.$$.fragment,t),i=!0)},o(t){Ct(n.$$.fragment,t),i=!1},d(t){t&&T(e),Dt(n)}}}function Te(t){let e,n,i,s;const r=[ye,_e],o=[];function a(t,e){return!1===t[11]?0:1}return e=a(t),n=o[e]=r[e](t),{c(){n.c(),i=P()},m(t,n){o[e].m(t,n),S(t,i,n),s=!0},p(t,[s]){let c=e;e=a(t),e===c?o[e].p(t,s):(yt(),Ct(o[c],1,1,(()=>{o[c]=null})),bt(),n=o[e],n?n.p(t,s):(n=o[e]=r[e](t),n.c()),xt(n,1),n.m(i.parentNode,i))},i(t){s||(xt(n),s=!0)},o(t){Ct(n),s=!1},d(t){o[e].d(t),t&&T(i)}}}function Me(t,e){let n=e,i=t.getElementsByTagName("summary")[0];const s=()=>{t.open&&(t.open=!1)},r=t=>{t.stopPropagation()},o=e=>{e.stopPropagation(),n&&(t.open=!1)};return t.addEventListener("click",o),i.addEventListener("click",r),window.addEventListener("click",s),{update:t=>n=t,destroy:()=>{window.removeEventListener("click",s),t.removeEventListener("click",o),i.removeEventListener("click",r)}}}function Ae(t,e,i){let s,r;const o=["outline","primary","secondary","dark","error","success","clear","loading","icon","iconRight","dropdown","open","autoclose","submit"];let a=m(e,o),{$$slots:c={},$$scope:l}=e,{outline:h=null}=e,{primary:u=null}=e,{secondary:d=null}=e,{dark:f=null}=e,{error:g=null}=e,{success:v=null}=e,{clear:_=null}=e,{loading:y=null}=e,{icon:b=null}=e,{iconRight:x=null}=e,{dropdown:C=!1}=e,{open:w=!1}=e,{autoclose:S=!1}=e,{submit:T=!1}=e;const M=Vt(),A=e.$$slots&&void 0!==e.$$slots;return t.$$set=t=>{i(22,e=n(n({},e),p(t))),i(17,a=m(e,o)),"outline"in t&&i(1,h=t.outline),"primary"in t&&i(2,u=t.primary),"secondary"in t&&i(3,d=t.secondary),"dark"in t&&i(4,f=t.dark),"error"in t&&i(5,g=t.error),"success"in t&&i(6,v=t.success),"clear"in t&&i(7,_=t.clear),"loading"in t&&i(8,y=t.loading),"icon"in t&&i(9,b=t.icon),"iconRight"in t&&i(10,x=t.iconRight),"dropdown"in t&&i(11,C=t.dropdown),"open"in t&&i(0,w=t.open),"autoclose"in t&&i(12,S=t.autoclose),"submit"in t&&i(13,T=t.submit),"$$scope"in t&&i(20,l=t.$$scope)},t.$$.update=()=>{1536&t.$$.dirty&&i(14,s=(null!==b||null!==x)&&A),2560&t.$$.dirty&&i(15,r=C?null!==b&&!0===C:null!==b&&!A)},e=p(e),[w,h,u,d,f,g,v,_,y,b,x,C,S,T,s,r,M,a,c,function(){w=this.open,i(0,w)},l]}class Oe extends $t{constructor(t){super(),jt(this,t,Ae,Te,a,{outline:1,primary:2,secondary:3,dark:4,error:5,success:6,clear:7,loading:8,icon:9,iconRight:10,dropdown:11,open:0,autoclose:12,submit:13})}}const Ee=[];function ke(e,n=t){let i;const s=[];function r(t){if(a(e,t)&&(e=t,i)){const t=!Ee.length;for(let t=0;t<s.length;t+=1){const n=s[t];n[1](),Ee.push(n,e)}if(t){for(let t=0;t<Ee.length;t+=2)Ee[t][0](Ee[t+1]);Ee.length=0}}}return{set:r,update:function(t){r(t(e))},subscribe:function(o,a=t){const c=[o,a];return s.push(c),1===s.length&&(i=n(r)||t),o(e),()=>{const t=s.indexOf(c);-1!==t&&s.splice(t,1),0===s.length&&(i(),i=null)}}}}function Pe(e,n,i){const s=!Array.isArray(e),a=s?[e]:e,l=n.length<2;return function(t,e){return{subscribe:ke(t,e).subscribe}}(i,(e=>{let i=!1;const h=[];let u=0,d=t;const f=()=>{if(u)return;d();const i=n(s?h[0]:h,e);l?e(i):d=o(i)?i:t},p=a.map(((t,e)=>c(t,(t=>{h[e]=t,u&=~(1<<e),i&&f()}),(()=>{u|=1<<e}))));return i=!0,f(),function(){r(p),d()}}))}function Ie(t){let e,i,s,r;const o=t[5].default,a=u(o,t,t[4],null);let c=[t[3]],l={};for(let t=0;t<c.length;t+=1)l=n(l,c[t]);return{c(){e=A("span"),a&&a.c(),R(e,l),G(e,"tag",1),G(e,"is-small",t[0]),G(e,"is-large",t[1])},m(n,o){S(n,e,o),a&&a.m(e,null),i=!0,s||(r=g(t[2].call(null,e)),s=!0)},p(t,[n]){a&&a.p&&(!i||16&n)&&f(a,o,t,t[4],n,null,null),R(e,l=Et(c,[8&n&&t[3]])),G(e,"tag",1),G(e,"is-small",t[0]),G(e,"is-large",t[1])},i(t){i||(xt(a,t),i=!0)},o(t){Ct(a,t),i=!1},d(t){t&&T(e),a&&a.d(t),s=!1,r()}}}function De(t,e,i){const s=["small","large"];let r=m(e,s),{$$slots:o={},$$scope:a}=e,{small:c=!1}=e,{large:l=!1}=e;const h=Vt();return t.$$set=t=>{e=n(n({},e),p(t)),i(3,r=m(e,s)),"small"in t&&i(0,c=t.small),"large"in t&&i(1,l=t.large),"$$scope"in t&&i(4,a=t.$$scope)},[c,l,h,r,a,o]}class Re extends $t{constructor(t){super(),jt(this,t,De,Ie,a,{small:0,large:1})}}function je(t){let e,n;return{c(){e=A("label"),n=E(t[1])},m(t,i){S(t,e,i),w(e,n)},p(t,e){2&e&&L(n,t[1])},d(t){t&&T(e)}}}function $e(e){let n;return{c(){n=A("p"),n.textContent=" ",D(n,"class","message svelte-3n5xjn")},m(t,e){S(t,n,e)},p:t,d(t){t&&T(n)}}}function Le(t){let e,n;return{c(){e=A("p"),n=E(t[5]),D(e,"class","message svelte-3n5xjn"),G(e,"text-error",t[2]),G(e,"text-success",t[3])},m(t,i){S(t,e,i),w(e,n)},p(t,i){32&i&&L(n,t[5]),4&i&&G(e,"text-error",t[2]),8&i&&G(e,"text-success",t[3])},d(t){t&&T(e)}}}function Fe(t){let e,i,s,r,o,a,c,l=t[1]&&je(t);const h=t[9].default,d=u(h,t,t[8],null);function p(t,e){return t[5]?Le:$e}let m=p(t),v=m(t),_=[t[7]],y={};for(let t=0;t<_.length;t+=1)y=n(y,_[t]);return{c(){e=A("div"),l&&l.c(),i=k(),s=A("p"),d&&d.c(),r=k(),v.c(),D(s,"class","svelte-3n5xjn"),G(s,"grouped",t[0]),G(s,"gapless",t[4]),R(e,y),G(e,"nomessage",!t[5]),G(e,"svelte-3n5xjn",!0)},m(n,h){S(n,e,h),l&&l.m(e,null),w(e,i),w(e,s),d&&d.m(s,null),w(e,r),v.m(e,null),o=!0,a||(c=g(t[6].call(null,e)),a=!0)},p(t,[n]){t[1]?l?l.p(t,n):(l=je(t),l.c(),l.m(e,i)):l&&(l.d(1),l=null),d&&d.p&&(!o||256&n)&&f(d,h,t,t[8],n,null,null),1&n&&G(s,"grouped",t[0]),16&n&&G(s,"gapless",t[4]),m===(m=p(t))&&v?v.p(t,n):(v.d(1),v=m(t),v&&(v.c(),v.m(e,null))),R(e,y=Et(_,[128&n&&t[7]])),G(e,"nomessage",!t[5]),G(e,"svelte-3n5xjn",!0)},i(t){o||(xt(d,t),o=!0)},o(t){Ct(d,t),o=!1},d(t){t&&T(e),l&&l.d(),d&&d.d(t),v.d(),a=!1,c()}}}function Ne(t,e,i){const s=["label","error","success","grouped","gapless"];let r=m(e,s),{$$slots:o={},$$scope:a}=e,{label:c=!1}=e,{error:l=!1}=e,{success:h=!1}=e,{grouped:u=!1}=e,{gapless:d=!1}=e;const f=Vt(),g=ke("");let v=!1;var _,y;return _="field:state",y=g,tt().$$.context.set(_,y),t.$$set=t=>{e=n(n({},e),p(t)),i(7,r=m(e,s)),"label"in t&&i(1,c=t.label),"error"in t&&i(2,l=t.error),"success"in t&&i(3,h=t.success),"grouped"in t&&i(0,u=t.grouped),"gapless"in t&&i(4,d=t.gapless),"$$scope"in t&&i(8,a=t.$$scope)},t.$$.update=()=>{16&t.$$.dirty&&d&&i(0,u=!0),12&t.$$.dirty&&("string"==typeof l?(g.set("error"),i(5,v=l)):"string"==typeof h?(g.set("success"),i(5,v=h)):(g.set(""),i(5,v=!1)))},[u,c,l,h,d,v,f,r,a,o]}class Be extends $t{constructor(t){super(),jt(this,t,Ne,Fe,a,{label:1,error:2,success:3,grouped:0,gapless:4})}}function Ve(t){const e=t-1;return e*e*e+1}function We(t,{delay:n=0,duration:i=400,easing:s=e}={}){const r=+getComputedStyle(t).opacity;return{delay:n,duration:i,easing:s,css:t=>"opacity: "+t*r}}function He(t,{delay:e=0,duration:n=400,easing:i=Ve,x:s=0,y:r=0,opacity:o=0}={}){const a=getComputedStyle(t),c=+a.opacity,l="none"===a.transform?"":a.transform,h=c*(1-o);return{delay:e,duration:n,easing:i,css:(t,e)=>`\n\t\t\ttransform: ${l} translate(${(1-t)*s}px, ${(1-t)*r}px);\n\t\t\topacity: ${c-h*e}`}}function Ge(t){let e,i,s,o,a,c,l,h;const d=t[4].default,p=u(d,t,t[3],null);let m=[t[2]],v={};for(let t=0;t<m.length;t+=1)v=n(v,m[t]);return{c(){e=A("div"),i=A("div"),s=k(),o=A("div"),p&&p.c(),D(i,"class","background svelte-4lwi8h"),R(o,v),G(o,"modal",1),G(o,"svelte-4lwi8h",!0),D(e,"class","container svelte-4lwi8h")},m(n,r){S(n,e,r),w(e,i),w(e,s),w(e,o),p&&p.m(o,null),c=!0,l||(h=[I(i,"click",t[5]),g(t[1].call(null,o))],l=!0)},p(t,e){p&&p.p&&(!c||8&e)&&f(p,d,t,t[3],e,null,null),R(o,v=Et(m,[4&e&&t[2]])),G(o,"modal",1),G(o,"svelte-4lwi8h",!0)},i(t){c||(xt(p,t),ct((()=>{a||(a=Mt(e,We,{duration:200},!0)),a.run(1)})),c=!0)},o(t){Ct(p,t),a||(a=Mt(e,We,{duration:200},!1)),a.run(0),c=!1},d(t){t&&T(e),p&&p.d(t),t&&a&&a.end(),l=!1,r(h)}}}function ze(t){let e,n,i=t[0]&&Ge(t);return{c(){i&&i.c(),e=P()},m(t,s){i&&i.m(t,s),S(t,e,s),n=!0},p(t,[n]){t[0]?i?(i.p(t,n),1&n&&xt(i,1)):(i=Ge(t),i.c(),xt(i,1),i.m(e.parentNode,e)):i&&(yt(),Ct(i,1,1,(()=>{i=null})),bt())},i(t){n||(xt(i),n=!0)},o(t){Ct(i),n=!1},d(t){i&&i.d(t),t&&T(e)}}}function Ye(t,e,i){const s=["open"];let r=m(e,s),{$$slots:o={},$$scope:a}=e,{open:c=!1}=e;const l=Vt();return t.$$set=t=>{e=n(n({},e),p(t)),i(2,r=m(e,s)),"open"in t&&i(0,c=t.open),"$$scope"in t&&i(3,a=t.$$scope)},[c,l,r,a,o,t=>i(0,c=!1)]}class Xe extends $t{constructor(t){super(),jt(this,t,Ye,ze,a,{open:0})}}const Ue=(t,e)=>Array(Math.abs(e)+1).join(t);function qe(t){return null!==t&&"object"==typeof t&&"string"==typeof t.name}function Ke(t){return null!==t&&"object"==typeof t&&"number"==typeof t.step&&"number"==typeof t.alt}const Ze=[0,2,4,-1,1,3,5],Qe=Ze.map((t=>Math.floor(7*t/12)));function Je(t){const{step:e,alt:n,oct:i,dir:s=1}=t,r=Ze[e]+7*n;if(void 0===i)return[s*r];return[s*r,s*(i-Qe[e]-4*n)]}const tn=[3,0,4,1,5,2,6];function en(t){const[e,n,i]=t,s=tn[function(t){const e=(t+1)%7;return e<0?7+e:e}(e)],r=Math.floor((e+1)/7);if(void 0===n)return{step:s,alt:r,dir:i};return{step:s,alt:r,oct:n+4*r+Qe[s],dir:i}}const nn={empty:!0,name:"",pc:"",acc:""},sn=new Map,rn=t=>t<0?Ue("b",-t):Ue("#",t),on=t=>"b"===t[0]?-t.length:t.length;function an(t){const e=sn.get(t);if(e)return e;const n="string"==typeof t?function(t){const e=ln(t);if(""===e[0]||""!==e[3])return nn;const n=e[0],i=e[1],s=e[2],r=(n.charCodeAt(0)+3)%7,o=on(i),a=s.length?+s:void 0,c=Je({step:r,alt:o,oct:a}),l=n+i+s,h=n+i,u=(hn[r]+o+120)%12,d=void 0===a?(m=hn[r]+o,g=12,(m%g+g)%g-1188):hn[r]+o+12*(a+1),f=d>=0&&d<=127?d:null,p=void 0===a?null:440*Math.pow(2,(d-69)/12);var m,g;return{empty:!1,acc:i,alt:o,chroma:u,coord:c,freq:p,height:d,letter:n,midi:f,name:l,oct:a,pc:h,step:r}}(t):Ke(t)?an(function(t){const{step:e,alt:n,oct:i}=t,s=(t=>"CDEFGAB".charAt(t))(e);if(!s)return"";const r=s+rn(n);return i||0===i?r+i:r}(t)):qe(t)?an(t.name):nn;return sn.set(t,n),n}const cn=/^([a-gA-G]?)(#{1,}|b{1,}|x{1,}|)(-?\d*)\s*(.*)$/;function ln(t){const e=cn.exec(t);return[e[1].toUpperCase(),e[2].replace(/x/g,"##"),e[3],e[4]]}const hn=[0,2,4,5,7,9,11];const un={empty:!0,name:"",acc:""},dn=new RegExp("^([-+]?\\d+)(d{1,4}|m|M|P|A{1,4})|(AA|A|P|M|m|d|dd)([-+]?\\d+)$");const fn={};function pn(t){return"string"==typeof t?fn[t]||(fn[t]=function(t){const e=function(t){const e=dn.exec(`${t}`);return null===e?["",""]:e[1]?[e[1],e[2]]:[e[4],e[3]]}(t);if(""===e[0])return un;const n=+e[0],i=e[1],s=(Math.abs(n)-1)%7,r=gn[s];if("M"===r&&"P"===i)return un;const o="M"===r?"majorable":"perfectable",a=""+n+i,c=n<0?-1:1,l=8===n||-8===n?n:c*(s+1),h=function(t,e){return"M"===e&&"majorable"===t||"P"===e&&"perfectable"===t?0:"m"===e&&"majorable"===t?-1:/^A+$/.test(e)?e.length:/^d+$/.test(e)?-1*("perfectable"===t?e.length:e.length+1):0}(o,i),u=Math.floor((Math.abs(n)-1)/7),d=c*(mn[s]+h+12*u),f=(c*(mn[s]+h)%12+12)%12,p=Je({step:s,alt:h,oct:u,dir:c});return{empty:!1,name:a,num:n,q:i,step:s,alt:h,dir:c,type:o,simple:l,semitones:d,chroma:f,coord:p,oct:u}}(t)):Ke(t)?pn(function(t){const{step:e,alt:n,oct:i=0,dir:s}=t;if(!s)return"";return(s<0?"-":"")+(e+1+7*i)+function(t,e){return 0===e?"majorable"===t?"M":"P":-1===e&&"majorable"===t?"m":e>0?Ue("A",e):Ue("d","perfectable"===t?e:e+1)}("M"===gn[e]?"majorable":"perfectable",n)}(t)):qe(t)?pn(t.name):un}const mn=[0,2,4,5,7,9,11],gn="PMMPPMM";function vn(t,e){const n=an(t),i=pn(e);if(n.empty||i.empty)return"";const s=n.coord,r=i.coord;return function(t){return an(en(t))}(1===s.length?[s[0]+r[0]]:[s[0]+r[0],s[1]+r[1]]).name}function _n(t,e){const n=an(t),i=an(e);if(n.empty||i.empty)return"";const s=n.coord,r=i.coord,o=r[0]-s[0];return function(t){const[e,n=0]=t;return pn(en(7*e+12*n<0?[-e,-n,-1]:[e,n,1]))}([o,2===s.length&&2===r.length?r[1]-s[1]:-Math.floor(7*o/12)]).name}function yn(t,e){const n=e.length,i=(t%n+n)%n;return e.slice(i,n).concat(e.slice(0,i))}const bn={empty:!0,name:"",setNum:0,chroma:"000000000000",normalized:"000000000000",intervals:[]},xn=t=>Number(t).toString(2),Cn=t=>parseInt(t,2),wn=/^[01]{12}$/;function Sn(t){return wn.test(t)}const Tn={[bn.chroma]:bn};function Mn(t){const e=Sn(t)?t:"number"==typeof(n=t)&&n>=0&&n<=4095?xn(t):Array.isArray(t)?function(t){if(0===t.length)return bn.chroma;let e;const n=[0,0,0,0,0,0,0,0,0,0,0,0];for(let i=0;i<t.length;i++)e=an(t[i]),e.empty&&(e=pn(t[i])),e.empty||(n[e.chroma]=1);return n.join("")}(t):(t=>t&&Sn(t.chroma))(t)?t.chroma:bn.chroma;var n;return Tn[e]=Tn[e]||function(t){const e=Cn(t),n=function(t){const e=t.split("");return e.map(((t,n)=>yn(n,e).join("")))}(t).map(Cn).filter((t=>t>=2048)).sort()[0],i=xn(n),s=On(t);return{empty:!1,name:"",setNum:e,chroma:t,normalized:i,intervals:s}}(e)}const An=["1P","2m","2M","3m","3M","4P","5d","5P","6m","6M","7m","7M"];function On(t){const e=[];for(let n=0;n<12;n++)"1"===t.charAt(n)&&e.push(An[n]);return e}function En(t,e=!0){const n=Mn(t).chroma.split("");return n.map(((t,i)=>{const s=yn(i,n);return e&&"0"===s[0]?null:s.join("")})).filter((t=>0===t||t))}function kn(t){const e=Mn(t).setNum;return t=>{const n=Mn(t).setNum;return e&&e!==n&&(n&e)===n}}const Pn={...bn,name:"",quality:"Unknown",intervals:[],aliases:[]};let In=[],Dn={};function Rn(){return In.slice()}function jn(t,e,n){const i=function(t){const e=e=>-1!==t.indexOf(e);return e("5A")?"Augmented":e("3M")?"Major":e("5d")?"Diminished":e("3m")?"Minor":"Unknown"}(t),s={...Mn(t),name:n||"",quality:i,intervals:t,aliases:e};In.push(s),s.name&&(Dn[s.name]=s),Dn[s.setNum]=s,Dn[s.chroma]=s,s.aliases.forEach((t=>function(t,e){Dn[e]=t}(s,t)))}[["1P 3M 5P","major","M ^ "],["1P 3M 5P 7M","major seventh","maj7 Δ ma7 M7 Maj7 ^7"],["1P 3M 5P 7M 9M","major ninth","maj9 Δ9 ^9"],["1P 3M 5P 7M 9M 13M","major thirteenth","maj13 Maj13 ^13"],["1P 3M 5P 6M","sixth","6 add6 add13 M6"],["1P 3M 5P 6M 9M","sixth/ninth","6/9 69 M69"],["1P 3M 6m 7M","major seventh flat sixth","M7b6 ^7b6"],["1P 3M 5P 7M 11A","major seventh sharp eleventh","maj#4 Δ#4 Δ#11 M7#11 ^7#11 maj7#11"],["1P 3m 5P","minor","m min -"],["1P 3m 5P 7m","minor seventh","m7 min7 mi7 -7"],["1P 3m 5P 7M","minor/major seventh","m/ma7 m/maj7 mM7 mMaj7 m/M7 -Δ7 mΔ -^7"],["1P 3m 5P 6M","minor sixth","m6 -6"],["1P 3m 5P 7m 9M","minor ninth","m9 -9"],["1P 3m 5P 7M 9M","minor/major ninth","mM9 mMaj9 -^9"],["1P 3m 5P 7m 9M 11P","minor eleventh","m11 -11"],["1P 3m 5P 7m 9M 13M","minor thirteenth","m13 -13"],["1P 3m 5d","diminished","dim ° o"],["1P 3m 5d 7d","diminished seventh","dim7 °7 o7"],["1P 3m 5d 7m","half-diminished","m7b5 ø -7b5 h7 h"],["1P 3M 5P 7m","dominant seventh","7 dom"],["1P 3M 5P 7m 9M","dominant ninth","9"],["1P 3M 5P 7m 9M 13M","dominant thirteenth","13"],["1P 3M 5P 7m 11A","lydian dominant seventh","7#11 7#4"],["1P 3M 5P 7m 9m","dominant flat ninth","7b9"],["1P 3M 5P 7m 9A","dominant sharp ninth","7#9"],["1P 3M 7m 9m","altered","alt7"],["1P 4P 5P","suspended fourth","sus4 sus"],["1P 2M 5P","suspended second","sus2"],["1P 4P 5P 7m","suspended fourth seventh","7sus4 7sus"],["1P 5P 7m 9M 11P","eleventh","11"],["1P 4P 5P 7m 9m","suspended fourth flat ninth","b9sus phryg 7b9sus 7b9sus4"],["1P 5P","fifth","5"],["1P 3M 5A","augmented","aug + +5 ^#5"],["1P 3m 5A","minor augmented","m#5 -#5 m+"],["1P 3M 5A 7M","augmented seventh","maj7#5 maj7+5 +maj7 ^7#5"],["1P 3M 5P 7M 9M 11A","major sharp eleventh (lydian)","maj9#11 Δ9#11 ^9#11"],["1P 2M 4P 5P","","sus24 sus4add9"],["1P 3M 5A 7M 9M","","maj9#5 Maj9#5"],["1P 3M 5A 7m","","7#5 +7 7+ 7aug aug7"],["1P 3M 5A 7m 9A","","7#5#9 7#9#5 7alt"],["1P 3M 5A 7m 9M","","9#5 9+"],["1P 3M 5A 7m 9M 11A","","9#5#11"],["1P 3M 5A 7m 9m","","7#5b9 7b9#5"],["1P 3M 5A 7m 9m 11A","","7#5b9#11"],["1P 3M 5A 9A","","+add#9"],["1P 3M 5A 9M","","M#5add9 +add9"],["1P 3M 5P 6M 11A","","M6#11 M6b5 6#11 6b5"],["1P 3M 5P 6M 7M 9M","","M7add13"],["1P 3M 5P 6M 9M 11A","","69#11"],["1P 3m 5P 6M 9M","","m69 -69"],["1P 3M 5P 6m 7m","","7b6"],["1P 3M 5P 7M 9A 11A","","maj7#9#11"],["1P 3M 5P 7M 9M 11A 13M","","M13#11 maj13#11 M13+4 M13#4"],["1P 3M 5P 7M 9m","","M7b9"],["1P 3M 5P 7m 11A 13m","","7#11b13 7b5b13"],["1P 3M 5P 7m 13M","","7add6 67 7add13"],["1P 3M 5P 7m 9A 11A","","7#9#11 7b5#9 7#9b5"],["1P 3M 5P 7m 9A 11A 13M","","13#9#11"],["1P 3M 5P 7m 9A 11A 13m","","7#9#11b13"],["1P 3M 5P 7m 9A 13M","","13#9"],["1P 3M 5P 7m 9A 13m","","7#9b13"],["1P 3M 5P 7m 9M 11A","","9#11 9+4 9#4"],["1P 3M 5P 7m 9M 11A 13M","","13#11 13+4 13#4"],["1P 3M 5P 7m 9M 11A 13m","","9#11b13 9b5b13"],["1P 3M 5P 7m 9m 11A","","7b9#11 7b5b9 7b9b5"],["1P 3M 5P 7m 9m 11A 13M","","13b9#11"],["1P 3M 5P 7m 9m 11A 13m","","7b9b13#11 7b9#11b13 7b5b9b13"],["1P 3M 5P 7m 9m 13M","","13b9"],["1P 3M 5P 7m 9m 13m","","7b9b13"],["1P 3M 5P 7m 9m 9A","","7b9#9"],["1P 3M 5P 9M","","Madd9 2 add9 add2"],["1P 3M 5P 9m","","Maddb9"],["1P 3M 5d","","Mb5"],["1P 3M 5d 6M 7m 9M","","13b5"],["1P 3M 5d 7M","","M7b5"],["1P 3M 5d 7M 9M","","M9b5"],["1P 3M 5d 7m","","7b5"],["1P 3M 5d 7m 9M","","9b5"],["1P 3M 7m","","7no5"],["1P 3M 7m 13m","","7b13"],["1P 3M 7m 9M","","9no5"],["1P 3M 7m 9M 13M","","13no5"],["1P 3M 7m 9M 13m","","9b13"],["1P 3m 4P 5P","","madd4"],["1P 3m 5P 6m 7M","","mMaj7b6"],["1P 3m 5P 6m 7M 9M","","mMaj9b6"],["1P 3m 5P 7m 11P","","m7add11 m7add4"],["1P 3m 5P 9M","","madd9"],["1P 3m 5d 6M 7M","","o7M7"],["1P 3m 5d 7M","","oM7"],["1P 3m 6m 7M","","mb6M7"],["1P 3m 6m 7m","","m7#5"],["1P 3m 6m 7m 9M","","m9#5"],["1P 3m 5A 7m 9M 11P","","m11A"],["1P 3m 6m 9m","","mb6b9"],["1P 2M 3m 5d 7m","","m9b5"],["1P 4P 5A 7M","","M7#5sus4"],["1P 4P 5A 7M 9M","","M9#5sus4"],["1P 4P 5A 7m","","7#5sus4"],["1P 4P 5P 7M","","M7sus4"],["1P 4P 5P 7M 9M","","M9sus4"],["1P 4P 5P 7m 9M","","9sus4 9sus"],["1P 4P 5P 7m 9M 13M","","13sus4 13sus"],["1P 4P 5P 7m 9m 13m","","7sus4b9b13 7b9b13sus4"],["1P 4P 7m 10m","","4 quartal"],["1P 5P 7m 9m 11P","","11b9"]].forEach((([t,e,n])=>jn(t.split(" "),n.split(" "),e))),In.sort(((t,e)=>t.setNum-e.setNum));function $n(t){const e=t.map((t=>an(t).pc)).filter((t=>t));if(0===an.length)return[];return function(t,e){const n=t[0],i=an(n).chroma,s=(t=>{const e=t.reduce(((t,e)=>{const n=an(e).chroma;return void 0!==n&&(t[n]=t[n]||an(e).name),t}),{});return t=>e[t]})(t),r=En(t,!1),o=[];return r.forEach(((t,r)=>{Rn().filter((e=>e.chroma===t)).forEach((t=>{const a=t.aliases[0],c=s(r);r!==i?o.push({weight:.5*e,name:`${c}${a}/${n}`}):o.push({weight:1*e,name:`${c}${a}`})}))})),o}(e,1).filter((t=>t.weight)).sort(((t,e)=>e.weight-t.weight)).map((t=>t.name))}const Ln={...bn,intervals:[],aliases:[]};let Fn=[],Nn={};function Bn(){return Fn.slice()}function Vn(t,e,n=[]){const i={...Mn(t),name:e,intervals:t,aliases:n};return Fn.push(i),Nn[i.name]=i,Nn[i.setNum]=i,Nn[i.chroma]=i,i.aliases.forEach((t=>function(t,e){Nn[e]=t}(i,t))),i}[["1P 2M 3M 5P 6M","major pentatonic","pentatonic"],["1P 3M 4P 5P 7M","ionian pentatonic"],["1P 3M 4P 5P 7m","mixolydian pentatonic","indian"],["1P 2M 4P 5P 6M","ritusen"],["1P 2M 4P 5P 7m","egyptian"],["1P 3M 4P 5d 7m","neopolitan major pentatonic"],["1P 3m 4P 5P 6m","vietnamese 1"],["1P 2m 3m 5P 6m","pelog"],["1P 2m 4P 5P 6m","kumoijoshi"],["1P 2M 3m 5P 6m","hirajoshi"],["1P 2m 4P 5d 7m","iwato"],["1P 2m 4P 5P 7m","in-sen"],["1P 3M 4A 5P 7M","lydian pentatonic","chinese"],["1P 3m 4P 6m 7m","malkos raga"],["1P 3m 4P 5d 7m","locrian pentatonic","minor seven flat five pentatonic"],["1P 3m 4P 5P 7m","minor pentatonic","vietnamese 2"],["1P 3m 4P 5P 6M","minor six pentatonic"],["1P 2M 3m 5P 6M","flat three pentatonic","kumoi"],["1P 2M 3M 5P 6m","flat six pentatonic"],["1P 2m 3M 5P 6M","scriabin"],["1P 3M 5d 6m 7m","whole tone pentatonic"],["1P 3M 4A 5A 7M","lydian #5P pentatonic"],["1P 3M 4A 5P 7m","lydian dominant pentatonic"],["1P 3m 4P 5P 7M","minor #7M pentatonic"],["1P 3m 4d 5d 7m","super locrian pentatonic"],["1P 2M 3m 4P 5P 7M","minor hexatonic"],["1P 2A 3M 5P 5A 7M","augmented"],["1P 2M 3m 3M 5P 6M","major blues"],["1P 2M 4P 5P 6M 7m","piongio"],["1P 2m 3M 4A 6M 7m","prometheus neopolitan"],["1P 2M 3M 4A 6M 7m","prometheus"],["1P 2m 3M 5d 6m 7m","mystery #1"],["1P 2m 3M 4P 5A 6M","six tone symmetric"],["1P 2M 3M 4A 5A 7m","whole tone","messiaen's mode #1"],["1P 2m 4P 4A 5P 7M","messiaen's mode #5"],["1P 3m 4P 5d 5P 7m","minor blues","blues"],["1P 2M 3M 4P 5d 6m 7m","locrian major","arabian"],["1P 2m 3M 4A 5P 6m 7M","double harmonic lydian"],["1P 2M 3m 4P 5P 6m 7M","harmonic minor"],["1P 2m 3m 4d 5d 6m 7m","altered","super locrian","diminished whole tone","pomeroy"],["1P 2M 3m 4P 5d 6m 7m","locrian #2","half-diminished","aeolian b5"],["1P 2M 3M 4P 5P 6m 7m","mixolydian b6","melodic minor fifth mode","hindu"],["1P 2M 3M 4A 5P 6M 7m","lydian dominant","lydian b7","overtone"],["1P 2M 3M 4A 5P 6M 7M","lydian"],["1P 2M 3M 4A 5A 6M 7M","lydian augmented"],["1P 2m 3m 4P 5P 6M 7m","dorian b2","phrygian #6","melodic minor second mode"],["1P 2M 3m 4P 5P 6M 7M","melodic minor"],["1P 2m 3m 4P 5d 6m 7m","locrian"],["1P 2m 3m 4d 5d 6m 7d","ultralocrian","superlocrian bb7","·superlocrian diminished"],["1P 2m 3m 4P 5d 6M 7m","locrian 6","locrian natural 6","locrian sharp 6"],["1P 2A 3M 4P 5P 5A 7M","augmented heptatonic"],["1P 2M 3m 5d 5P 6M 7m","romanian minor"],["1P 2M 3m 4A 5P 6M 7m","dorian #4"],["1P 2M 3m 4A 5P 6M 7M","lydian diminished"],["1P 2m 3m 4P 5P 6m 7m","phrygian"],["1P 2M 3M 4A 5A 7m 7M","leading whole tone"],["1P 2M 3M 4A 5P 6m 7m","lydian minor"],["1P 2m 3M 4P 5P 6m 7m","phrygian dominant","spanish","phrygian major"],["1P 2m 3m 4P 5P 6m 7M","balinese"],["1P 2m 3m 4P 5P 6M 7M","neopolitan major"],["1P 2M 3m 4P 5P 6m 7m","aeolian","minor"],["1P 2M 3M 4P 5P 6m 7M","harmonic major"],["1P 2m 3M 4P 5P 6m 7M","double harmonic major","gypsy"],["1P 2M 3m 4P 5P 6M 7m","dorian"],["1P 2M 3m 4A 5P 6m 7M","hungarian minor"],["1P 2A 3M 4A 5P 6M 7m","hungarian major"],["1P 2m 3M 4P 5d 6M 7m","oriental"],["1P 2m 3m 3M 4A 5P 7m","flamenco"],["1P 2m 3m 4A 5P 6m 7M","todi raga"],["1P 2M 3M 4P 5P 6M 7m","mixolydian","dominant"],["1P 2m 3M 4P 5d 6m 7M","persian"],["1P 2M 3M 4P 5P 6M 7M","major","ionian"],["1P 2m 3M 5d 6m 7m 7M","enigmatic"],["1P 2M 3M 4P 5A 6M 7M","major augmented","major #5","ionian augmented","ionian #5"],["1P 2A 3M 4A 5P 6M 7M","lydian #9"],["1P 2m 2M 4P 4A 5P 6m 7M","messiaen's mode #4"],["1P 2m 3M 4P 4A 5P 6m 7M","purvi raga"],["1P 2m 3m 3M 4P 5P 6m 7m","spanish heptatonic"],["1P 2M 3M 4P 5P 6M 7m 7M","bebop"],["1P 2M 3m 3M 4P 5P 6M 7m","bebop minor"],["1P 2M 3M 4P 5P 5A 6M 7M","bebop major"],["1P 2m 3m 4P 5d 5P 6m 7m","bebop locrian"],["1P 2M 3m 4P 5P 6m 7m 7M","minor bebop"],["1P 2M 3m 4P 5d 6m 6M 7M","diminished","whole-half diminished"],["1P 2M 3M 4P 5d 5P 6M 7M","ichikosucho"],["1P 2M 3m 4P 5P 6m 6M 7M","minor six diminished"],["1P 2m 3m 3M 4A 5P 6M 7m","half-whole diminished","dominant diminished","messiaen's mode #2"],["1P 3m 3M 4P 5P 6M 7m 7M","kafi raga"],["1P 2M 3M 4P 4A 5A 6A 7M","messiaen's mode #6"],["1P 2M 3m 3M 4P 5d 5P 6M 7m","composite blues"],["1P 2M 3m 3M 4A 5P 6m 7m 7M","messiaen's mode #3"],["1P 2m 2M 3m 4P 4A 5P 6m 6M 7M","messiaen's mode #7"],["1P 2m 2M 3m 3M 4P 5d 5P 6m 6M 7m 7M","chromatic"]].forEach((([t,e,...n])=>Vn(t.split(" "),e,n)));const Wn={empty:!0,name:"",symbol:"",root:"",rootDegree:0,type:"",tonic:null,setNum:NaN,quality:"Unknown",chroma:"",normalized:"",aliases:[],notes:[],intervals:[]},Hn=/^(6|64|7|9|11|13)$/;function Gn(t){const[e,n,i,s]=ln(t);return""===e?["",t]:"A"===e&&"ug"===s?["","aug"]:s||"4"!==i&&"5"!==i?Hn.test(i)?[e+n,i+s]:[e+n+i,s]:[e+n,i]}function zn(t){if(""===t)return Wn;if(Array.isArray(t)&&2===t.length)return Yn(t[1],t[0]);{const[e,n]=Gn(t),i=Yn(n,e);return i.empty?Yn(t):i}}function Yn(t,e,n){const i=function(t){return Dn[t]||Pn}(t),s=an(e||""),r=an(n||"");if(i.empty||e&&s.empty||n&&r.empty)return Wn;const o=_n(s.pc,r.pc),a=i.intervals.indexOf(o)+1;if(!r.empty&&!a)return Wn;const c=Array.from(i.intervals);for(let t=1;t<a;t++){const t=c[0][0],e=c[0][1],n=parseInt(t,10)+7;c.push(`${n}${e}`),c.shift()}const l=s.empty?[]:c.map((t=>vn(s,t)));t=-1!==i.aliases.indexOf(t)?t:i.aliases[0];const h=`${s.empty?"":s.pc}${t}${r.empty||a<=1?"":"/"+r.pc}`,u=`${e?s.pc+" ":""}${i.name}${a>1&&n?" over "+r.pc:""}`;return{...i,name:u,symbol:h,type:i.name,root:r.name,intervals:c,rootDegree:a,tonic:s.name,notes:l}}const Xn="C C# D D# E F F# G G# A A# B".split(" "),Un="C Db D Eb E F Gb G Ab A Bb B".split(" ");const qn=t=>t.name,Kn=an,Zn=(t,e)=>t.height-e.height;function Qn(t,e){return e=e||Zn,(n=t,n.map(an).filter((t=>!t.empty))).sort(e).map(qn);var n}function Jn(t,e){const n=Kn(t);if(n.empty)return"";const i=Kn(e||function(t,e={}){if(isNaN(t)||t===-1/0||t===1/0)return"";t=Math.round(t);const n=(!0===e.sharps?Xn:Un)[t%12];return e.pitchClass?n:n+(Math.floor(t/12)-1)}(n.midi||n.chroma,{sharps:n.alt<0,pitchClass:!0}));if(i.empty||i.chroma!==n.chroma)return"";if(void 0===n.oct)return i.pc;const s=n.chroma-n.alt,r=i.chroma-i.alt,o=s>11||r<0?-1:s<0||r>11?1:0,a=n.oct+o;return i.pc+a}const ti={empty:!0,name:"",chordType:""},ei={};function ni(t){return"string"==typeof t?ei[t]||(ei[t]=function(t){const[e,n,i,s]=(r=t,ii.exec(r)||["","","",""]);var r;if(!i)return ti;const o=i.toUpperCase(),a=si.indexOf(o),c=on(n),l=1;return{empty:!1,name:e,roman:i,interval:pn({step:a,alt:c,dir:l}).name,acc:n,chordType:s,alt:c,step:a,major:i===o,oct:0,dir:l}}(t)):"number"==typeof t?ni(si[t]||""):Ke(t)?ni(rn((e=t).alt)+si[e.step]):qe(t)?ni(t.name):ti;var e}const ii=/^(#{1,}|b{1,}|x{1,}|)(IV|I{1,3}|VI{0,2}|iv|i{1,3}|vi{0,2})([^IViv]*)$/;const si="I II III IV V VI VII".split(" ");Object.freeze([]);const ri=[[0,2773,0,"ionian","","Maj7","major"],[1,2902,2,"dorian","m","m7"],[2,3418,4,"phrygian","m","m7"],[3,2741,-1,"lydian","","Maj7"],[4,2774,1,"mixolydian","","7"],[5,2906,3,"aeolian","m","m7","minor"],[6,3434,5,"locrian","dim","m7b5"]],oi={...bn,name:"",alt:0,modeNum:NaN,triad:"",seventh:"",aliases:[]},ai=ri.map((function(t){const[e,n,i,s,r,o,a]=t,c=a?[a]:[],l=Number(n).toString(2);return{empty:!1,intervals:On(l),modeNum:e,chroma:l,normalized:l,name:s,setNum:n,alt:i,triad:r,seventh:o,aliases:c}})),ci={};function li(t){return"string"==typeof t?ci[t.toLowerCase()]||oi:t&&t.name?li(t.name):oi}function hi(t){return(e,n)=>{const i=li(e);if(i.empty)return[];const s=yn(i.modeNum,t),r=i.intervals.map((t=>vn(n,t)));return s.map(((t,e)=>r[e]+t))}}ai.forEach((t=>{ci[t.name]=t,t.aliases.forEach((e=>{ci[e]=t}))})),hi(ri.map((t=>t[4]))),hi(ri.map((t=>t[5])));var ui={fromRomanNumerals:function(t,e){return e.map(ni).map((e=>vn(t,pn(e))+e.chordType))},toRomanNumerals:function(t,e){return e.map((e=>{const[n,i]=Gn(e);return ni(pn(_n(t,n))).name+i}))}};const di={empty:!0,name:"",type:"",tonic:null,setNum:NaN,chroma:"",normalized:"",aliases:[],notes:[],intervals:[]};function fi(t){if("string"!=typeof t)return["",""];const e=t.indexOf(" "),n=an(t.substring(0,e));if(n.empty){const e=an(t);return e.empty?["",t]:[e.name,""]}const i=t.substring(n.name.length+1);return[n.name,i.length?i:""]}const pi=function(){return Fn.map((t=>t.name))};function mi(t){const e=Array.isArray(t)?t:fi(t),n=an(e[0]).name,i=function(t){return Nn[t]||Ln}(e[1]);if(i.empty)return di;const s=i.name,r=n?i.intervals.map((t=>vn(n,t))):[],o=n?n+" "+s:s;return{...i,name:o,type:s,tonic:n,notes:r}}var gi,vi,_i;function yi(t){const e=t.map((t=>an(t).pc)).filter((t=>t)),n=e[0],i=function(t){return Qn(t,Zn).filter(((t,e,n)=>0===e||t!==n[e-1]))}(e);return yn(i.indexOf(n),i)}var bi={get:mi,names:pi,extended:function(t){const e=function(t){const e=Mn(t).setNum;return t=>{const n=Mn(t).setNum;return e&&e!==n&&(n|e)===n}}(mi(t).chroma);return Bn().filter((t=>e(t.chroma))).map((t=>t.name))},modeNames:function(t){const e=mi(t);if(e.empty)return[];const n=e.tonic?e.notes:e.intervals;return En(e.chroma).map(((t,e)=>{const i=mi(t).name;return i?[n[e],i]:["",""]})).filter((t=>t[0]))},reduced:function(t){const e=kn(mi(t).chroma);return Bn().filter((t=>e(t.chroma))).map((t=>t.name))},scaleChords:function(t){const e=kn(mi(t).chroma);return Rn().filter((t=>e(t.chroma))).map((t=>t.aliases[0]))},scaleNotes:yi,tokenize:fi,rangeOf:function(t){const e=function(t){const e=Array.isArray(t)?yi(t):mi(t).notes,n=e.map((t=>an(t).chroma));return t=>{const i="number"==typeof t?t:an(t).height;if(void 0===i)return;const s=i%12,r=Math.floor(i/12)-1,o=n.indexOf(s);return-1!==o?e[o]+r:void 0}}(t);return(t,n)=>{const i=an(t).height,s=an(n).height;return void 0===i||void 0===s?[]:function(t,e){return t<e?function(t,e){const n=[];for(;e--;n[e]=e+t);return n}(t,e-t+1):function(t,e){const n=[];for(;e--;n[e]=t-e);return n}(t,t-e+1)}(i,s).map(e).filter((t=>t))}},scale:(gi="Scale.scale",vi="Scale.get",_i=mi,function(...t){return console.warn(`${gi} is deprecated. Use ${vi}.`),_i.apply(this,t)})};class xi{constructor(t,e){this.chord=t,this.notes=[...e]}equals(t){const e=new Set(this.notes.map((t=>t.midi))),n=new Set(t.notes.map((t=>t.midi)));if(e.size!==n.size)return!1;for(let t of e)if(!n.has(t))return!1;return!0}static fromChord(t,e){if(t.empty)throw new Error("Invalid chord");const n=t.intervals.map((n=>vn(`${t.tonic}${e}`,n))).map((t=>an(t)));return new xi(t,n)}static fromChordType(t,e,n){return xi.fromChord(Yn(t.name||t.aliases[0],e),n)}static fromNotes(t){let e=t.map((t=>t.pc));for(let n=0;n<e.length;n++){let n=$n(e);for(const e of n){let n=zn(e);if(!n.empty&&"minor augmented"!==n.type)return new xi(n,t)}const i=e.shift();e.push(i)}return null}static fromProgression(t,e,n){let i;try{i=ui.fromRomanNumerals(e,t)}catch(t){throw new Error("Invalid chord progression: unable to parse chord progression")}if(i.length<2)throw new Error("Invalid chord progression: must have at least 2 chords");const s=[];for(const t of i)s.push(xi.fromChord(zn(t),n));return s}}const Ci=t=>({}),wi=t=>({});function Si(t){let e,n,i,s,r,o,a,c,l=t[0].chord.name+"",h=t[0].chord.symbol+"";const d=t[3].action,p=u(d,t,t[2],wi);return{c(){e=A("div"),n=E(l),i=E(" ("),s=E(h),r=E(")\n    "),p&&p.c(),D(e,"class","item svelte-lgn3xm"),G(e,"active",t[1])},m(l,h){S(l,e,h),w(e,n),w(e,i),w(e,s),w(e,r),p&&p.m(e,null),o=!0,a||(c=I(e,"click",t[4]),a=!0)},p(t,[i]){(!o||1&i)&&l!==(l=t[0].chord.name+"")&&L(n,l),(!o||1&i)&&h!==(h=t[0].chord.symbol+"")&&L(s,h),p&&p.p&&(!o||4&i)&&f(p,d,t,t[2],i,Ci,wi),2&i&&G(e,"active",t[1])},i(t){o||(xt(p,t),o=!0)},o(t){Ct(p,t),o=!1},d(t){t&&T(e),p&&p.d(t),a=!1,c()}}}function Ti(t,e,n){let{$$slots:i={},$$scope:s}=e,{chord:r}=e,{active:o=!1}=e;return t.$$set=t=>{"chord"in t&&n(0,r=t.chord),"active"in t&&n(1,o=t.active),"$$scope"in t&&n(2,s=t.$$scope)},[r,o,s,i,function(e){et(t,e)}]}class Mi extends $t{constructor(t){super(),jt(this,t,Ti,Si,a,{chord:0,active:1})}}var Ai="M19,4H15.5L14.5,3H9.5L8.5,4H5V6H19M6,19A2,2 0 0,0 8,21H16A2,2 0 0,0 18,19V7H6V19Z",Oi="M19,13H13V19H11V13H5V11H11V5H13V11H19V13Z";function Ei(t,e,n={}){const i=getComputedStyle(t),s="none"===i.transform?"":i.transform,r=e.from.width/t.clientWidth,a=e.from.height/t.clientHeight,c=(e.from.left-e.to.left)/r,l=(e.from.top-e.to.top)/a,h=Math.sqrt(c*c+l*l),{delay:u=0,duration:d=(t=>120*Math.sqrt(t)),easing:f=Ve}=n;return{delay:u,duration:o(d)?d(h):d,easing:f,css:(t,e)=>`transform: ${s} translate(${e*c}px, ${e*l}px);`}}const ki=ke(null);function Pi(t){return Array.isArray?Array.isArray(t):"[object Array]"===Fi(t)}function Ii(t){return"string"==typeof t}function Di(t){return"number"==typeof t}function Ri(t){return!0===t||!1===t||function(t){return ji(t)&&null!==t}(t)&&"[object Boolean]"==Fi(t)}function ji(t){return"object"==typeof t}function $i(t){return null!=t}function Li(t){return!t.trim().length}function Fi(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":Object.prototype.toString.call(t)}const Ni=Object.prototype.hasOwnProperty;class Bi{constructor(t){this._keys=[],this._keyMap={};let e=0;t.forEach((t=>{let n=Vi(t);e+=n.weight,this._keys.push(n),this._keyMap[n.id]=n,e+=n.weight})),this._keys.forEach((t=>{t.weight/=e}))}get(t){return this._keyMap[t]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}}function Vi(t){let e=null,n=null,i=null,s=1;if(Ii(t)||Pi(t))i=t,e=Wi(t),n=Hi(t);else{if(!Ni.call(t,"name"))throw new Error((t=>`Missing ${t} property in key`)("name"));const r=t.name;if(i=r,Ni.call(t,"weight")&&(s=t.weight,s<=0))throw new Error((t=>`Property 'weight' in key '${t}' must be a positive integer`)(r));e=Wi(r),n=Hi(r)}return{path:e,id:n,weight:s,src:i}}function Wi(t){return Pi(t)?t:t.split(".")}function Hi(t){return Pi(t)?t.join("."):t}var Gi={isCaseSensitive:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:(t,e)=>t.score===e.score?t.idx<e.idx?-1:1:t.score<e.score?-1:1,includeMatches:!1,findAllMatches:!1,minMatchCharLength:1,location:0,threshold:.6,distance:100,...{useExtendedSearch:!1,getFn:function(t,e){let n=[],i=!1;const s=(t,e,r)=>{if($i(t))if(e[r]){const o=t[e[r]];if(!$i(o))return;if(r===e.length-1&&(Ii(o)||Di(o)||Ri(o)))n.push(function(t){return null==t?"":function(t){if("string"==typeof t)return t;let e=t+"";return"0"==e&&1/t==-1/0?"-0":e}(t)}(o));else if(Pi(o)){i=!0;for(let t=0,n=o.length;t<n;t+=1)s(o[t],e,r+1)}else e.length&&s(o,e,r+1)}else n.push(t)};return s(t,Ii(e)?e.split("."):e,0),i?n:n[0]},ignoreLocation:!1,ignoreFieldNorm:!1}};const zi=/[^ ]+/g;class Yi{constructor({getFn:t=Gi.getFn}={}){this.norm=function(t=3){const e=new Map,n=Math.pow(10,t);return{get(t){const i=t.match(zi).length;if(e.has(i))return e.get(i);const s=1/Math.sqrt(i),r=parseFloat(Math.round(s*n)/n);return e.set(i,r),r},clear(){e.clear()}}}(3),this.getFn=t,this.isCreated=!1,this.setIndexRecords()}setSources(t=[]){this.docs=t}setIndexRecords(t=[]){this.records=t}setKeys(t=[]){this.keys=t,this._keysMap={},t.forEach(((t,e)=>{this._keysMap[t.id]=e}))}create(){!this.isCreated&&this.docs.length&&(this.isCreated=!0,Ii(this.docs[0])?this.docs.forEach(((t,e)=>{this._addString(t,e)})):this.docs.forEach(((t,e)=>{this._addObject(t,e)})),this.norm.clear())}add(t){const e=this.size();Ii(t)?this._addString(t,e):this._addObject(t,e)}removeAt(t){this.records.splice(t,1);for(let e=t,n=this.size();e<n;e+=1)this.records[e].i-=1}getValueForItemAtKeyId(t,e){return t[this._keysMap[e]]}size(){return this.records.length}_addString(t,e){if(!$i(t)||Li(t))return;let n={v:t,i:e,n:this.norm.get(t)};this.records.push(n)}_addObject(t,e){let n={i:e,$:{}};this.keys.forEach(((e,i)=>{let s=this.getFn(t,e.path);if($i(s))if(Pi(s)){let t=[];const e=[{nestedArrIndex:-1,value:s}];for(;e.length;){const{nestedArrIndex:n,value:i}=e.pop();if($i(i))if(Ii(i)&&!Li(i)){let e={v:i,i:n,n:this.norm.get(i)};t.push(e)}else Pi(i)&&i.forEach(((t,n)=>{e.push({nestedArrIndex:n,value:t})}))}n.$[i]=t}else if(!Li(s)){let t={v:s,n:this.norm.get(s)};n.$[i]=t}})),this.records.push(n)}toJSON(){return{keys:this.keys,records:this.records}}}function Xi(t,e,{getFn:n=Gi.getFn}={}){const i=new Yi({getFn:n});return i.setKeys(t.map(Vi)),i.setSources(e),i.create(),i}function Ui(t,{errors:e=0,currentLocation:n=0,expectedLocation:i=0,distance:s=Gi.distance,ignoreLocation:r=Gi.ignoreLocation}={}){const o=e/t.length;if(r)return o;const a=Math.abs(i-n);return s?o+a/s:a?1:o}const qi=32;function Ki(t,e,n,{location:i=Gi.location,distance:s=Gi.distance,threshold:r=Gi.threshold,findAllMatches:o=Gi.findAllMatches,minMatchCharLength:a=Gi.minMatchCharLength,includeMatches:c=Gi.includeMatches,ignoreLocation:l=Gi.ignoreLocation}={}){if(e.length>qi)throw new Error(`Pattern length exceeds max of ${qi}.`);const h=e.length,u=t.length,d=Math.max(0,Math.min(i,u));let f=r,p=d;const m=a>1||c,g=m?Array(u):[];let v;for(;(v=t.indexOf(e,p))>-1;){let t=Ui(e,{currentLocation:v,expectedLocation:d,distance:s,ignoreLocation:l});if(f=Math.min(t,f),p=v+h,m){let t=0;for(;t<h;)g[v+t]=1,t+=1}}p=-1;let _=[],y=1,b=h+u;const x=1<<h-1;for(let i=0;i<h;i+=1){let r=0,a=b;for(;r<a;){Ui(e,{errors:i,currentLocation:d+a,expectedLocation:d,distance:s,ignoreLocation:l})<=f?r=a:b=a,a=Math.floor((b-r)/2+r)}b=a;let c=Math.max(1,d-a+1),v=o?u:Math.min(d+a,u)+h,C=Array(v+2);C[v+1]=(1<<i)-1;for(let r=v;r>=c;r-=1){let o=r-1,a=n[t.charAt(o)];if(m&&(g[o]=+!!a),C[r]=(C[r+1]<<1|1)&a,i&&(C[r]|=(_[r+1]|_[r])<<1|1|_[r+1]),C[r]&x&&(y=Ui(e,{errors:i,currentLocation:o,expectedLocation:d,distance:s,ignoreLocation:l}),y<=f)){if(f=y,p=o,p<=d)break;c=Math.max(1,2*d-p)}}if(Ui(e,{errors:i+1,currentLocation:d,expectedLocation:d,distance:s,ignoreLocation:l})>f)break;_=C}const C={isMatch:p>=0,score:Math.max(.001,y)};if(m){const t=function(t=[],e=Gi.minMatchCharLength){let n=[],i=-1,s=-1,r=0;for(let o=t.length;r<o;r+=1){let o=t[r];o&&-1===i?i=r:o||-1===i||(s=r-1,s-i+1>=e&&n.push([i,s]),i=-1)}return t[r-1]&&r-i>=e&&n.push([i,r-1]),n}(g,a);t.length?c&&(C.indices=t):C.isMatch=!1}return C}function Zi(t){let e={};for(let n=0,i=t.length;n<i;n+=1){const s=t.charAt(n);e[s]=(e[s]||0)|1<<i-n-1}return e}class Qi{constructor(t,{location:e=Gi.location,threshold:n=Gi.threshold,distance:i=Gi.distance,includeMatches:s=Gi.includeMatches,findAllMatches:r=Gi.findAllMatches,minMatchCharLength:o=Gi.minMatchCharLength,isCaseSensitive:a=Gi.isCaseSensitive,ignoreLocation:c=Gi.ignoreLocation}={}){if(this.options={location:e,threshold:n,distance:i,includeMatches:s,findAllMatches:r,minMatchCharLength:o,isCaseSensitive:a,ignoreLocation:c},this.pattern=a?t:t.toLowerCase(),this.chunks=[],!this.pattern.length)return;const l=(t,e)=>{this.chunks.push({pattern:t,alphabet:Zi(t),startIndex:e})},h=this.pattern.length;if(h>qi){let t=0;const e=h%qi,n=h-e;for(;t<n;)l(this.pattern.substr(t,qi),t),t+=qi;if(e){const t=h-qi;l(this.pattern.substr(t),t)}}else l(this.pattern,0)}searchIn(t){const{isCaseSensitive:e,includeMatches:n}=this.options;if(e||(t=t.toLowerCase()),this.pattern===t){let e={isMatch:!0,score:0};return n&&(e.indices=[[0,t.length-1]]),e}const{location:i,distance:s,threshold:r,findAllMatches:o,minMatchCharLength:a,ignoreLocation:c}=this.options;let l=[],h=0,u=!1;this.chunks.forEach((({pattern:e,alphabet:d,startIndex:f})=>{const{isMatch:p,score:m,indices:g}=Ki(t,e,d,{location:i+f,distance:s,threshold:r,findAllMatches:o,minMatchCharLength:a,includeMatches:n,ignoreLocation:c});p&&(u=!0),h+=m,p&&g&&(l=[...l,...g])}));let d={isMatch:u,score:u?h/this.chunks.length:1};return u&&n&&(d.indices=l),d}}class Ji{constructor(t){this.pattern=t}static isMultiMatch(t){return ts(t,this.multiRegex)}static isSingleMatch(t){return ts(t,this.singleRegex)}search(){}}function ts(t,e){const n=t.match(e);return n?n[1]:null}class es extends Ji{constructor(t,{location:e=Gi.location,threshold:n=Gi.threshold,distance:i=Gi.distance,includeMatches:s=Gi.includeMatches,findAllMatches:r=Gi.findAllMatches,minMatchCharLength:o=Gi.minMatchCharLength,isCaseSensitive:a=Gi.isCaseSensitive,ignoreLocation:c=Gi.ignoreLocation}={}){super(t),this._bitapSearch=new Qi(t,{location:e,threshold:n,distance:i,includeMatches:s,findAllMatches:r,minMatchCharLength:o,isCaseSensitive:a,ignoreLocation:c})}static get type(){return"fuzzy"}static get multiRegex(){return/^"(.*)"$/}static get singleRegex(){return/^(.*)$/}search(t){return this._bitapSearch.searchIn(t)}}class ns extends Ji{constructor(t){super(t)}static get type(){return"include"}static get multiRegex(){return/^'"(.*)"$/}static get singleRegex(){return/^'(.*)$/}search(t){let e,n=0;const i=[],s=this.pattern.length;for(;(e=t.indexOf(this.pattern,n))>-1;)n=e+s,i.push([e,n-1]);const r=!!i.length;return{isMatch:r,score:r?0:1,indices:i}}}const is=[class extends Ji{constructor(t){super(t)}static get type(){return"exact"}static get multiRegex(){return/^="(.*)"$/}static get singleRegex(){return/^=(.*)$/}search(t){const e=t===this.pattern;return{isMatch:e,score:e?0:1,indices:[0,this.pattern.length-1]}}},ns,class extends Ji{constructor(t){super(t)}static get type(){return"prefix-exact"}static get multiRegex(){return/^\^"(.*)"$/}static get singleRegex(){return/^\^(.*)$/}search(t){const e=t.startsWith(this.pattern);return{isMatch:e,score:e?0:1,indices:[0,this.pattern.length-1]}}},class extends Ji{constructor(t){super(t)}static get type(){return"inverse-prefix-exact"}static get multiRegex(){return/^!\^"(.*)"$/}static get singleRegex(){return/^!\^(.*)$/}search(t){const e=!t.startsWith(this.pattern);return{isMatch:e,score:e?0:1,indices:[0,t.length-1]}}},class extends Ji{constructor(t){super(t)}static get type(){return"inverse-suffix-exact"}static get multiRegex(){return/^!"(.*)"\$$/}static get singleRegex(){return/^!(.*)\$$/}search(t){const e=!t.endsWith(this.pattern);return{isMatch:e,score:e?0:1,indices:[0,t.length-1]}}},class extends Ji{constructor(t){super(t)}static get type(){return"suffix-exact"}static get multiRegex(){return/^"(.*)"\$$/}static get singleRegex(){return/^(.*)\$$/}search(t){const e=t.endsWith(this.pattern);return{isMatch:e,score:e?0:1,indices:[t.length-this.pattern.length,t.length-1]}}},class extends Ji{constructor(t){super(t)}static get type(){return"inverse-exact"}static get multiRegex(){return/^!"(.*)"$/}static get singleRegex(){return/^!(.*)$/}search(t){const e=-1===t.indexOf(this.pattern);return{isMatch:e,score:e?0:1,indices:[0,t.length-1]}}},es],ss=is.length,rs=/ +(?=([^\"]*\"[^\"]*\")*[^\"]*$)/;const os=new Set([es.type,ns.type]);class as{constructor(t,{isCaseSensitive:e=Gi.isCaseSensitive,includeMatches:n=Gi.includeMatches,minMatchCharLength:i=Gi.minMatchCharLength,ignoreLocation:s=Gi.ignoreLocation,findAllMatches:r=Gi.findAllMatches,location:o=Gi.location,threshold:a=Gi.threshold,distance:c=Gi.distance}={}){this.query=null,this.options={isCaseSensitive:e,includeMatches:n,minMatchCharLength:i,findAllMatches:r,ignoreLocation:s,location:o,threshold:a,distance:c},this.pattern=e?t:t.toLowerCase(),this.query=function(t,e={}){return t.split("|").map((t=>{let n=t.trim().split(rs).filter((t=>t&&!!t.trim())),i=[];for(let t=0,s=n.length;t<s;t+=1){const s=n[t];let r=!1,o=-1;for(;!r&&++o<ss;){const t=is[o];let n=t.isMultiMatch(s);n&&(i.push(new t(n,e)),r=!0)}if(!r)for(o=-1;++o<ss;){const t=is[o];let n=t.isSingleMatch(s);if(n){i.push(new t(n,e));break}}}return i}))}(this.pattern,this.options)}static condition(t,e){return e.useExtendedSearch}searchIn(t){const e=this.query;if(!e)return{isMatch:!1,score:1};const{includeMatches:n,isCaseSensitive:i}=this.options;t=i?t:t.toLowerCase();let s=0,r=[],o=0;for(let i=0,a=e.length;i<a;i+=1){const a=e[i];r.length=0,s=0;for(let e=0,i=a.length;e<i;e+=1){const i=a[e],{isMatch:c,indices:l,score:h}=i.search(t);if(!c){o=0,s=0,r.length=0;break}if(s+=1,o+=h,n){const t=i.constructor.type;os.has(t)?r=[...r,...l]:r.push(l)}}if(s){let t={isMatch:!0,score:o/s};return n&&(t.indices=r),t}}return{isMatch:!1,score:1}}}const cs=[];function ls(t,e){for(let n=0,i=cs.length;n<i;n+=1){let i=cs[n];if(i.condition(t,e))return new i(t,e)}return new Qi(t,e)}const hs="$and",us="$or",ds="$path",fs="$val",ps=t=>!(!t[hs]&&!t[us]),ms=t=>({[hs]:Object.keys(t).map((e=>({[e]:t[e]})))});function gs(t,e,{auto:n=!0}={}){const i=t=>{let s=Object.keys(t);const r=(t=>!!t[ds])(t);if(!r&&s.length>1&&!ps(t))return i(ms(t));if((t=>!Pi(t)&&ji(t)&&!ps(t))(t)){const i=r?t[ds]:s[0],o=r?t[fs]:t[i];if(!Ii(o))throw new Error((t=>`Invalid value for key ${t}`)(i));const a={keyId:Hi(i),pattern:o};return n&&(a.searcher=ls(o,e)),a}let o={children:[],operator:s[0]};return s.forEach((e=>{const n=t[e];Pi(n)&&n.forEach((t=>{o.children.push(i(t))}))})),o};return ps(t)||(t=ms(t)),i(t)}function vs(t,e){const n=t.matches;e.matches=[],$i(n)&&n.forEach((t=>{if(!$i(t.indices)||!t.indices.length)return;const{indices:n,value:i}=t;let s={indices:n,value:i};t.key&&(s.key=t.key.src),t.idx>-1&&(s.refIndex=t.idx),e.matches.push(s)}))}function _s(t,e){e.score=t.score}class ys{constructor(t,e={},n){this.options={...Gi,...e},this.options.useExtendedSearch,this._keyStore=new Bi(this.options.keys),this.setCollection(t,n)}setCollection(t,e){if(this._docs=t,e&&!(e instanceof Yi))throw new Error("Incorrect 'index' type");this._myIndex=e||Xi(this.options.keys,this._docs,{getFn:this.options.getFn})}add(t){$i(t)&&(this._docs.push(t),this._myIndex.add(t))}remove(t=(()=>!1)){const e=[];for(let n=0,i=this._docs.length;n<i;n+=1){const s=this._docs[n];t(s,n)&&(this.removeAt(n),n-=1,i-=1,e.push(s))}return e}removeAt(t){this._docs.splice(t,1),this._myIndex.removeAt(t)}getIndex(){return this._myIndex}search(t,{limit:e=-1}={}){const{includeMatches:n,includeScore:i,shouldSort:s,sortFn:r,ignoreFieldNorm:o}=this.options;let a=Ii(t)?Ii(this._docs[0])?this._searchStringList(t):this._searchObjectList(t):this._searchLogical(t);return function(t,{ignoreFieldNorm:e=Gi.ignoreFieldNorm}){t.forEach((t=>{let n=1;t.matches.forEach((({key:t,norm:i,score:s})=>{const r=t?t.weight:null;n*=Math.pow(0===s&&r?Number.EPSILON:s,(r||1)*(e?1:i))})),t.score=n}))}(a,{ignoreFieldNorm:o}),s&&a.sort(r),Di(e)&&e>-1&&(a=a.slice(0,e)),function(t,e,{includeMatches:n=Gi.includeMatches,includeScore:i=Gi.includeScore}={}){const s=[];return n&&s.push(vs),i&&s.push(_s),t.map((t=>{const{idx:n}=t,i={item:e[n],refIndex:n};return s.length&&s.forEach((e=>{e(t,i)})),i}))}(a,this._docs,{includeMatches:n,includeScore:i})}_searchStringList(t){const e=ls(t,this.options),{records:n}=this._myIndex,i=[];return n.forEach((({v:t,i:n,n:s})=>{if(!$i(t))return;const{isMatch:r,score:o,indices:a}=e.searchIn(t);r&&i.push({item:t,idx:n,matches:[{score:o,value:t,norm:s,indices:a}]})})),i}_searchLogical(t){const e=gs(t,this.options),n=(t,e,i)=>{if(!t.children){const{keyId:n,searcher:s}=t,r=this._findMatches({key:this._keyStore.get(n),value:this._myIndex.getValueForItemAtKeyId(e,n),searcher:s});return r&&r.length?[{idx:i,item:e,matches:r}]:[]}switch(t.operator){case hs:{const s=[];for(let r=0,o=t.children.length;r<o;r+=1){const o=t.children[r],a=n(o,e,i);if(!a.length)return[];s.push(...a)}return s}case us:{const s=[];for(let r=0,o=t.children.length;r<o;r+=1){const o=t.children[r],a=n(o,e,i);if(a.length){s.push(...a);break}}return s}}},i=this._myIndex.records,s={},r=[];return i.forEach((({$:t,i:i})=>{if($i(t)){let o=n(e,t,i);o.length&&(s[i]||(s[i]={idx:i,item:t,matches:[]},r.push(s[i])),o.forEach((({matches:t})=>{s[i].matches.push(...t)})))}})),r}_searchObjectList(t){const e=ls(t,this.options),{keys:n,records:i}=this._myIndex,s=[];return i.forEach((({$:t,i:i})=>{if(!$i(t))return;let r=[];n.forEach(((n,i)=>{r.push(...this._findMatches({key:n,value:t[i],searcher:e}))})),r.length&&s.push({idx:i,item:t,matches:r})})),s}_findMatches({key:t,value:e,searcher:n}){if(!$i(e))return[];let i=[];if(Pi(e))e.forEach((({v:e,i:s,n:r})=>{if(!$i(e))return;const{isMatch:o,score:a,indices:c}=n.searchIn(e);o&&i.push({score:a,key:t,value:e,idx:s,norm:r,indices:c})}));else{const{v:s,n:r}=e,{isMatch:o,score:a,indices:c}=n.searchIn(s);o&&i.push({score:a,key:t,value:s,norm:r,indices:c})}return i}}ys.version="6.4.6",ys.createIndex=Xi,ys.parseIndex=function(t,{getFn:e=Gi.getFn}={}){const{keys:n,records:i}=t,s=new Yi({getFn:e});return s.setKeys(n),s.setIndexRecords(i),s},ys.config=Gi,ys.parseQuery=gs,function(...t){cs.push(...t)}(as);const bs="14.7.77";var xs=Nt((function(t){t.exports=function(t){if(Array.isArray(t))return t},t.exports.default=t.exports,t.exports.__esModule=!0})),Cs=Nt((function(t){t.exports=function(t,e){var n=t&&("undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"]);if(null!=n){var i,s,r=[],o=!0,a=!1;try{for(n=n.call(t);!(o=(i=n.next()).done)&&(r.push(i.value),!e||r.length!==e);o=!0);}catch(t){a=!0,s=t}finally{try{o||null==n.return||n.return()}finally{if(a)throw s}}return r}},t.exports.default=t.exports,t.exports.__esModule=!0})),ws=Nt((function(t){t.exports=function(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,i=new Array(e);n<e;n++)i[n]=t[n];return i},t.exports.default=t.exports,t.exports.__esModule=!0})),Ss=Nt((function(t){t.exports=function(t,e){if(t){if("string"==typeof t)return ws(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?ws(t,e):void 0}},t.exports.default=t.exports,t.exports.__esModule=!0})),Ts=Nt((function(t){t.exports=function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")},t.exports.default=t.exports,t.exports.__esModule=!0})),Ms=Nt((function(t){t.exports=function(t,e){return xs(t)||Cs(t,e)||Ss(t,e)||Ts()},t.exports.default=t.exports,t.exports.__esModule=!0})),As=Nt((function(t){t.exports=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},t.exports.default=t.exports,t.exports.__esModule=!0})),Os=Nt((function(t){function e(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}t.exports=function(t,n,i){return n&&e(t.prototype,n),i&&e(t,i),t},t.exports.default=t.exports,t.exports.__esModule=!0})),Es=Nt((function(t,e){!function(t,e,n,i){function s(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var r=s(e),o=s(n),a=s(i),c=function(t,e,n){return{endTime:e,insertTime:n,type:"exponentialRampToValue",value:t}},l=function(t,e,n){return{endTime:e,insertTime:n,type:"linearRampToValue",value:t}},h=function(t,e){return{startTime:e,type:"setValue",value:t}},u=function(t,e,n){return{duration:n,startTime:e,type:"setValueCurve",values:t}},d=function(t,e,n){var i=n.startTime,s=n.target,r=n.timeConstant;return s+(e-s)*Math.exp((i-t)/r)},f=function(t){return"exponentialRampToValue"===t.type},p=function(t){return"linearRampToValue"===t.type},m=function(t){return f(t)||p(t)},g=function(t){return"setValue"===t.type},v=function(t){return"setValueCurve"===t.type},_=function t(e,n,i,s){var r=e[n];return void 0===r?s:m(r)||g(r)?r.value:v(r)?r.values[r.values.length-1]:d(i,t(e,n-1,r.startTime,s),r)},y=function(t,e,n,i,s){return void 0===n?[i.insertTime,s]:m(n)?[n.endTime,n.value]:g(n)?[n.startTime,n.value]:v(n)?[n.startTime+n.duration,n.values[n.values.length-1]]:[n.startTime,_(t,e-1,n.startTime,s)]},b=function(t){return"cancelAndHold"===t.type},x=function(t){return"cancelScheduledValues"===t.type},C=function(t){return b(t)||x(t)?t.cancelTime:f(t)||p(t)?t.endTime:t.startTime},w=function(t,e,n,i){var s=i.endTime,r=i.value;return n===r?r:0<n&&0<r||n<0&&r<0?n*Math.pow(r/n,(t-e)/(s-e)):0},S=function(t,e,n,i){return n+(t-e)/(i.endTime-e)*(i.value-n)},T=function(t,e){var n=Math.floor(e),i=Math.ceil(e);return n===i?t[n]:(1-(e-n))*t[n]+(1-(i-e))*t[i]},M=function(t,e){var n=e.duration,i=e.startTime,s=e.values,r=(t-i)/n*(s.length-1);return T(s,r)},A=function(t){return"setTarget"===t.type},O=function(){function t(e){o.default(this,t),this._automationEvents=[],this._currenTime=0,this._defaultValue=e}return a.default(t,[{key:Symbol.iterator,value:function(){return this._automationEvents[Symbol.iterator]()}},{key:"add",value:function(t){var e=C(t);if(b(t)||x(t)){var n=this._automationEvents.findIndex((function(n){return x(t)&&v(n)?n.startTime+n.duration>=e:C(n)>=e})),i=this._automationEvents[n];if(-1!==n&&(this._automationEvents=this._automationEvents.slice(0,n)),b(t)){var s=this._automationEvents[this._automationEvents.length-1];if(void 0!==i&&m(i)){if(A(s))throw new Error("The internal list is malformed.");var r=v(s)?s.startTime+s.duration:C(s),o=v(s)?s.values[s.values.length-1]:s.value,a=f(i)?w(e,r,o,i):S(e,r,o,i),d=f(i)?c(a,e,this._currenTime):l(a,e,this._currenTime);this._automationEvents.push(d)}void 0!==s&&A(s)&&this._automationEvents.push(h(this.getValue(e),e)),void 0!==s&&v(s)&&s.startTime+s.duration>e&&(this._automationEvents[this._automationEvents.length-1]=u(new Float32Array([6,7]),s.startTime,e-s.startTime))}}else{var g=this._automationEvents.findIndex((function(t){return C(t)>e})),_=-1===g?this._automationEvents[this._automationEvents.length-1]:this._automationEvents[g-1];if(void 0!==_&&v(_)&&C(_)+_.duration>e)return!1;var y=f(t)?c(t.value,t.endTime,this._currenTime):p(t)?l(t.value,e,this._currenTime):t;if(-1===g)this._automationEvents.push(y);else{if(v(t)&&e+t.duration>C(this._automationEvents[g]))return!1;this._automationEvents.splice(g,0,y)}}return!0}},{key:"flush",value:function(t){var e=this._automationEvents.findIndex((function(e){return C(e)>t}));if(e>1){var n=this._automationEvents.slice(e-1),i=n[0];A(i)&&n.unshift(h(_(this._automationEvents,e-2,i.startTime,this._defaultValue),i.startTime)),this._automationEvents=n}}},{key:"getValue",value:function(t){if(0===this._automationEvents.length)return this._defaultValue;var e=this._automationEvents.findIndex((function(e){return C(e)>t})),n=this._automationEvents[e],i=(-1===e?this._automationEvents.length:e)-1,s=this._automationEvents[i];if(void 0!==s&&A(s)&&(void 0===n||!m(n)||n.insertTime>t))return d(t,_(this._automationEvents,i-1,s.startTime,this._defaultValue),s);if(void 0!==s&&g(s)&&(void 0===n||!m(n)))return s.value;if(void 0!==s&&v(s)&&(void 0===n||!m(n)||s.startTime+s.duration>t))return t<s.startTime+s.duration?M(t,s):s.values[s.values.length-1];if(void 0!==s&&m(s)&&(void 0===n||!m(n)))return s.value;if(void 0!==n&&f(n)){var o=y(this._automationEvents,i,s,n,this._defaultValue),a=r.default(o,2),c=a[0],l=a[1];return w(t,c,l,n)}if(void 0!==n&&p(n)){var h=y(this._automationEvents,i,s,n,this._defaultValue),u=r.default(h,2),b=u[0],x=u[1];return S(t,b,x,n)}return this._defaultValue}}]),t}(),E=function(t){return{cancelTime:t,type:"cancelAndHold"}},k=function(t){return{cancelTime:t,type:"cancelScheduledValues"}},P=function(t,e){return{endTime:e,type:"exponentialRampToValue",value:t}},I=function(t,e){return{endTime:e,type:"linearRampToValue",value:t}},D=function(t,e,n){return{startTime:e,target:t,timeConstant:n,type:"setTarget"}};t.AutomationEventList=O,t.createCancelAndHoldAutomationEvent=E,t.createCancelScheduledValuesAutomationEvent=k,t.createExponentialRampToValueAutomationEvent=P,t.createLinearRampToValueAutomationEvent=I,t.createSetTargetAutomationEvent=D,t.createSetValueAutomationEvent=h,t.createSetValueCurveAutomationEvent=u,Object.defineProperty(t,"__esModule",{value:!0})}(e,Ms,As,Os)}));const ks=new WeakSet,Ps=new WeakMap,Is=new WeakMap,Ds=new WeakMap,Rs=new WeakMap,js=new WeakMap,$s=new WeakMap,Ls=new WeakMap,Fs=new WeakMap,Ns=new WeakMap,Bs={construct:()=>Bs},Vs=/^import(?:(?:[\s]+[\w]+|(?:[\s]+[\w]+[\s]*,)?[\s]*\{[\s]*[\w]+(?:[\s]+as[\s]+[\w]+)?(?:[\s]*,[\s]*[\w]+(?:[\s]+as[\s]+[\w]+)?)*[\s]*}|(?:[\s]+[\w]+[\s]*,)?[\s]*\*[\s]+as[\s]+[\w]+)[\s]+from)?(?:[\s]*)("([^"\\]|\\.)+"|'([^'\\]|\\.)+')(?:[\s]*);?/,Ws=(t,e)=>{const n=[];let i=t.replace(/^[\s]+/,""),s=i.match(Vs);for(;null!==s;){const t=s[1].slice(1,-1),r=s[0].replace(/([\s]+)?;?$/,"").replace(t,new URL(t,e).toString());n.push(r),i=i.slice(s[0].length).replace(/^[\s]+/,""),s=i.match(Vs)}return[n.join(";"),i]},Hs=t=>{if(void 0!==t&&!Array.isArray(t))throw new TypeError("The parameterDescriptors property of given value for processorCtor is not an array.")},Gs=t=>{if(!(t=>{try{new new Proxy(t,Bs)}catch{return!1}return!0})(t))throw new TypeError("The given value for processorCtor should be a constructor.");if(null===t.prototype||"object"!=typeof t.prototype)throw new TypeError("The given value for processorCtor should have a prototype.")},zs=(t,e)=>{const n=t.get(e);if(void 0===n)throw new Error("A value with the given key could not be found.");return n},Ys=(t,e)=>{const n=Array.from(t).filter(e);if(n.length>1)throw Error("More than one element was found.");if(0===n.length)throw Error("No element was found.");const[i]=n;return t.delete(i),i},Xs=(t,e,n,i)=>{const s=zs(t,e),r=Ys(s,(t=>t[0]===n&&t[1]===i));return 0===s.size&&t.delete(e),r},Us=t=>zs($s,t),qs=t=>{if(ks.has(t))throw new Error("The AudioNode is already stored.");ks.add(t),Us(t).forEach((t=>t(!0)))},Ks=t=>"port"in t,Zs=t=>{if(!ks.has(t))throw new Error("The AudioNode is not stored.");ks.delete(t),Us(t).forEach((t=>t(!1)))},Qs=(t,e)=>{!Ks(t)&&e.every((t=>0===t.size))&&Zs(t)},Js={channelCount:2,channelCountMode:"max",channelInterpretation:"speakers",fftSize:2048,maxDecibels:-30,minDecibels:-100,smoothingTimeConstant:.8},tr=(t,e)=>t.context===e,er=t=>{try{t.copyToChannel(new Float32Array(1),0,-1)}catch{return!1}return!0},nr=()=>new DOMException("","IndexSizeError"),ir=t=>{var e;t.getChannelData=(e=t.getChannelData,n=>{try{return e.call(t,n)}catch(t){if(12===t.code)throw nr();throw t}})},sr={numberOfChannels:1},rr=-34028234663852886e22,or=-rr,ar=t=>ks.has(t),cr={buffer:null,channelCount:2,channelCountMode:"max",channelInterpretation:"speakers",loop:!1,loopEnd:0,loopStart:0,playbackRate:1},lr=t=>zs(Ps,t),hr=t=>zs(Ds,t),ur=(t,e)=>{const{activeInputs:n}=lr(t);n.forEach((n=>n.forEach((([n])=>{e.includes(t)||ur(n,[...e,t])}))));const i=(t=>"playbackRate"in t)(t)?[t.playbackRate]:Ks(t)?Array.from(t.parameters.values()):(t=>"frequency"in t&&"gain"in t)(t)?[t.Q,t.detune,t.frequency,t.gain]:(t=>"offset"in t)(t)?[t.offset]:(t=>!("frequency"in t)&&"gain"in t)(t)?[t.gain]:(t=>"detune"in t&&"frequency"in t)(t)?[t.detune,t.frequency]:(t=>"pan"in t)(t)?[t.pan]:[];for(const t of i){const n=hr(t);void 0!==n&&n.activeInputs.forEach((([t])=>ur(t,e)))}ar(t)&&Zs(t)},dr=t=>{ur(t.destination,[])},fr=t=>"context"in t,pr=t=>fr(t[0]),mr=(t,e,n,i)=>{for(const e of t)if(n(e)){if(i)return!1;throw Error("The set contains at least one similar element.")}return t.add(e),!0},gr=(t,e,[n,i],s)=>{mr(t,[e,n,i],(t=>t[0]===e&&t[1]===n),s)},vr=(t,[e,n,i],s)=>{const r=t.get(e);void 0===r?t.set(e,new Set([[n,i]])):mr(r,[n,i],(t=>t[0]===n),s)},_r=t=>"inputs"in t,yr=(t,e,n,i)=>{if(_r(e)){const s=e.inputs[i];return t.connect(s,n,0),[s,n,0]}return t.connect(e,n,i),[e,n,i]},br=(t,e,n)=>{for(const i of t)if(i[0]===e&&i[1]===n)return t.delete(i),i;return null},xr=(t,e)=>{if(!Us(t).delete(e))throw new Error("Missing the expected event listener.")},Cr=(t,e,n)=>{const i=zs(t,e),s=Ys(i,(t=>t[0]===n));return 0===i.size&&t.delete(e),s},wr=(t,e,n,i)=>{_r(e)?t.disconnect(e.inputs[i],n,0):t.disconnect(e,n,i)},Sr=t=>zs(Is,t),Tr=t=>zs(Rs,t),Mr=t=>Ls.has(t),Ar=t=>!ks.has(t),Or=t=>new Promise((e=>{const n=t.createScriptProcessor(256,1,1),i=t.createGain(),s=t.createBuffer(1,2,44100),r=s.getChannelData(0);r[0]=1,r[1]=1;const o=t.createBufferSource();o.buffer=s,o.loop=!0,o.connect(n).connect(t.destination),o.connect(i),o.disconnect(i),n.onaudioprocess=i=>{const s=i.inputBuffer.getChannelData(0);Array.prototype.some.call(s,(t=>1===t))?e(!0):e(!1),o.stop(),n.onaudioprocess=null,o.disconnect(n),n.disconnect(t.destination)},o.start()})),Er=(t,e)=>{const n=new Map;for(const e of t)for(const t of e){const e=n.get(t);n.set(t,void 0===e?1:e+1)}n.forEach(((t,n)=>e(n,t)))},kr=t=>"context"in t,Pr=(t,e,n,i)=>{const{activeInputs:s,passiveInputs:r}=hr(e),{outputs:o}=lr(t),a=Us(t),c=o=>{const a=Sr(t),c=Tr(e);if(o){const e=Cr(r,t,n);gr(s,t,e,!1),i||Mr(t)||a.connect(c,n)}else{const e=((t,e,n)=>Ys(t,(t=>t[0]===e&&t[1]===n)))(s,t,n);vr(r,e,!1),i||Mr(t)||a.disconnect(c,n)}};return!!mr(o,[e,n],(t=>t[0]===e&&t[1]===n),!0)&&(a.add(c),ar(t)?gr(s,t,[n,c],!0):vr(r,[t,n,c],!0),!0)},Ir=(t,e,n,i,s)=>{const[r,o]=((t,e,n,i)=>{const{activeInputs:s,passiveInputs:r}=lr(e),o=br(s[i],t,n);if(null===o)return[Xs(r,t,n,i)[2],!1];return[o[2],!0]})(t,n,i,s);if(null!==r&&(xr(t,r),!o||e||Mr(t)||wr(Sr(t),Sr(n),i,s)),ar(n)){const{activeInputs:t}=lr(n);Qs(n,t)}},Dr=(t,e,n,i)=>{const[s,r]=((t,e,n)=>{const{activeInputs:i,passiveInputs:s}=hr(e),r=br(i,t,n);if(null===r)return[Cr(s,t,n)[1],!1];return[r[2],!0]})(t,n,i);null!==s&&(xr(t,s),!r||e||Mr(t)||Sr(t).disconnect(Tr(n),i))};class Rr{constructor(t){this._map=new Map(t)}get size(){return this._map.size}entries(){return this._map.entries()}forEach(t,e=null){return this._map.forEach(((n,i)=>t.call(e,n,i,this)))}get(t){return this._map.get(t)}has(t){return this._map.has(t)}keys(){return this._map.keys()}values(){return this._map.values()}}const jr={channelCount:2,channelCountMode:"explicit",channelInterpretation:"speakers",numberOfInputs:1,numberOfOutputs:1,parameterData:{},processorOptions:{}};function $r(t,e,n,i,s){if("function"==typeof t.copyFromChannel)0===e[n].byteLength&&(e[n]=new Float32Array(128)),t.copyFromChannel(e[n],i,s);else{const r=t.getChannelData(i);if(0===e[n].byteLength)e[n]=r.slice(s,s+128);else{const t=new Float32Array(r.buffer,s*Float32Array.BYTES_PER_ELEMENT,128);e[n].set(t)}}}const Lr=(t,e,n,i,s)=>{"function"==typeof t.copyToChannel?0!==e[n].byteLength&&t.copyToChannel(e[n],i,s):0!==e[n].byteLength&&t.getChannelData(i).set(e[n],s)},Fr=(t,e)=>{const n=[];for(let i=0;i<t;i+=1){const t=[],s="number"==typeof e?e:e[i];for(let e=0;e<s;e+=1)t.push(new Float32Array(128));n.push(t)}return n},Nr=async(t,e,n,i,s,r,o)=>{const a=null===e?128*Math.ceil(t.context.length/128):e.length,c=i.channelCount*i.numberOfInputs,l=s.reduce(((t,e)=>t+e),0),h=0===l?null:n.createBuffer(l,a,n.sampleRate);if(void 0===r)throw new Error("Missing the processor constructor.");const u=lr(t),d=await((t,e)=>{const n=zs(Ns,t),i=Sr(e);return zs(n,i)})(n,t),f=Fr(i.numberOfInputs,i.channelCount),p=Fr(i.numberOfOutputs,s),m=Array.from(t.parameters.keys()).reduce(((t,e)=>({...t,[e]:new Float32Array(128)})),{});for(let l=0;l<a;l+=128){if(i.numberOfInputs>0&&null!==e)for(let t=0;t<i.numberOfInputs;t+=1)for(let n=0;n<i.channelCount;n+=1)$r(e,f[t],n,n,l);void 0!==r.parameterDescriptors&&null!==e&&r.parameterDescriptors.forEach((({name:t},n)=>{$r(e,m,t,c+n,l)}));for(let t=0;t<i.numberOfInputs;t+=1)for(let e=0;e<s[t];e+=1)0===p[t][e].byteLength&&(p[t][e]=new Float32Array(128));try{const t=f.map(((t,e)=>0===u.activeInputs[e].size?[]:t)),e=o(l/n.sampleRate,n.sampleRate,(()=>d.process(t,p,m)));if(null!==h)for(let t=0,e=0;t<i.numberOfOutputs;t+=1){for(let n=0;n<s[t];n+=1)Lr(h,p[t],n,e+n,l);e+=s[t]}if(!e)break}catch(e){t.dispatchEvent(new ErrorEvent("processorerror",{colno:e.colno,filename:e.filename,lineno:e.lineno,message:e.message}));break}}return h},Br={Q:1,channelCount:2,channelCountMode:"max",channelInterpretation:"speakers",detune:0,frequency:350,gain:0,type:"lowpass"},Vr={channelCount:1,channelCountMode:"explicit",channelInterpretation:"speakers",numberOfInputs:6},Wr={channelCount:6,channelCountMode:"explicit",channelInterpretation:"discrete",numberOfOutputs:6},Hr={channelCount:2,channelCountMode:"max",channelInterpretation:"speakers",offset:1},Gr={buffer:null,channelCount:2,channelCountMode:"clamped-max",channelInterpretation:"speakers",disableNormalization:!1},zr=t=>{const{port1:e,port2:n}=new MessageChannel;return new Promise((i=>{n.onmessage=()=>{e.close(),n.close(),i()},e.postMessage(t,[t])}))},Yr={channelCount:2,channelCountMode:"max",channelInterpretation:"speakers",delayTime:0,maxDelayTime:1},Xr=(t,e,n)=>{const i=e[n];if(void 0===i)throw t();return i},Ur={attack:.003,channelCount:2,channelCountMode:"clamped-max",channelInterpretation:"speakers",knee:30,ratio:12,release:.25,threshold:-24},qr={channelCount:2,channelCountMode:"max",channelInterpretation:"speakers",gain:1},Kr=()=>new DOMException("","InvalidStateError"),Zr=()=>new DOMException("","InvalidAccessError"),Qr={channelCount:2,channelCountMode:"max",channelInterpretation:"speakers"},Jr=(t,e,n,i,s,r,o,a,c,l,h)=>{const u=l.length;let d=a;for(let a=0;a<u;a+=1){let u=n[0]*l[a];for(let e=1;e<s;e+=1){const i=d-e&c-1;u+=n[e]*r[i],u-=t[e]*o[i]}for(let t=s;t<i;t+=1)u+=n[t]*r[d-t&c-1];for(let n=s;n<e;n+=1)u-=t[n]*o[d-n&c-1];r[d]=l[a],o[d]=u,d=d+1&c-1,h[a]=u}return d},to={channelCount:2,channelCountMode:"explicit",channelInterpretation:"speakers"},eo=t=>{const e=new Uint32Array([1179011410,40,1163280727,544501094,16,131073,44100,176400,1048580,1635017060,4,0]);try{const n=t.decodeAudioData(e.buffer,(()=>{}));return void 0!==n&&(n.catch((()=>{})),!0)}catch{}return!1},no=(t,e,n)=>{const i=e[n];void 0!==i&&i!==t[n]&&(t[n]=i)},io=(t,e)=>{no(t,e,"channelCount"),no(t,e,"channelCountMode"),no(t,e,"channelInterpretation")},so=t=>"function"==typeof t.getFloatTimeDomainData,ro=(t,e,n)=>{const i=e[n];void 0!==i&&i!==t[n].value&&(t[n].value=i)},oo=t=>{t.start=(e=>(n=0,i=0,s)=>{if("number"==typeof s&&s<0||i<0||n<0)throw new RangeError("The parameters can't be negative.");e.call(t,n,i,s)})(t.start)},ao=t=>{var e;t.stop=(e=t.stop,(n=0)=>{if(n<0)throw new RangeError("The parameter can't be negative.");e.call(t,n)})},co=(t,e)=>null===t?512:Math.max(512,Math.min(16384,Math.pow(2,Math.round(Math.log2(t*e))))),lo=async(t,e)=>new t(await(t=>new Promise(((e,n)=>{const{port1:i,port2:s}=new MessageChannel;i.onmessage=({data:t})=>{i.close(),s.close(),e(t)},i.onmessageerror=({data:t})=>{i.close(),s.close(),n(t)},s.postMessage(t)})))(e)),ho=(t,e)=>{const n=t.createBiquadFilter();return io(n,e),ro(n,e,"Q"),ro(n,e,"detune"),ro(n,e,"frequency"),ro(n,e,"gain"),no(n,e,"type"),n},uo=(t,e)=>{const n=t.createChannelSplitter(e.numberOfOutputs);return io(n,e),(t=>{const e=t.numberOfOutputs;Object.defineProperty(t,"channelCount",{get:()=>e,set:t=>{if(t!==e)throw Kr()}}),Object.defineProperty(t,"channelCountMode",{get:()=>"explicit",set:t=>{if("explicit"!==t)throw Kr()}}),Object.defineProperty(t,"channelInterpretation",{get:()=>"discrete",set:t=>{if("discrete"!==t)throw Kr()}})})(n),n},fo=(t,e)=>(t.connect=e.connect.bind(e),t.disconnect=e.disconnect.bind(e),t),po=(t,e)=>{const n=t.createDelay(e.maxDelayTime);return io(n,e),ro(n,e,"delayTime"),n},mo=(t,e)=>{const n=t.createGain();return io(n,e),ro(n,e,"gain"),n};function go(t,e){const n=e[0]*e[0]+e[1]*e[1];return[(t[0]*e[0]+t[1]*e[1])/n,(t[1]*e[0]-t[0]*e[1])/n]}function vo(t,e){let n=[0,0];for(let r=t.length-1;r>=0;r-=1)s=e,n=[(i=n)[0]*s[0]-i[1]*s[1],i[0]*s[1]+i[1]*s[0]],n[0]+=t[r];var i,s;return n}const _o=(t,e,n,i)=>t.createScriptProcessor(e,n,i),yo=()=>new DOMException("","NotSupportedError"),bo={numberOfChannels:1},xo={channelCount:2,channelCountMode:"max",channelInterpretation:"speakers",detune:0,frequency:440,periodicWave:void 0,type:"sine"},Co={channelCount:2,channelCountMode:"clamped-max",channelInterpretation:"speakers",coneInnerAngle:360,coneOuterAngle:360,coneOuterGain:0,distanceModel:"inverse",maxDistance:1e4,orientationX:1,orientationY:0,orientationZ:0,panningModel:"equalpower",positionX:0,positionY:0,positionZ:0,refDistance:1,rolloffFactor:1},wo={disableNormalization:!1},So={channelCount:2,channelCountMode:"explicit",channelInterpretation:"speakers",pan:0},To={channelCount:2,channelCountMode:"max",channelInterpretation:"speakers",curve:null,oversample:"none"},Mo=t=>{if(null===t)return!1;const e=t.length;return e%2!=0?0!==t[Math.floor(e/2)]:t[e/2-1]+t[e/2]!==0},Ao=(t,e,n,i)=>{let s=Object.getPrototypeOf(t);for(;!s.hasOwnProperty(e);)s=Object.getPrototypeOf(s);const{get:r,set:o}=Object.getOwnPropertyDescriptor(s,e);Object.defineProperty(t,e,{get:n(r),set:i(o)})},Oo=(t,e,n)=>{try{t.setValueAtTime(e,n)}catch(i){if(9!==i.code)throw i;Oo(t,e,n+1e-7)}},Eo=t=>{const e=t.createOscillator();try{e.start(-1)}catch(t){return t instanceof RangeError}return!1},ko=t=>{const e=t.createBuffer(1,1,44100),n=t.createBufferSource();n.buffer=e,n.start(),n.stop();try{return n.stop(),!0}catch{return!1}},Po=t=>{const e=t.createOscillator();try{e.stop(-1)}catch(t){return t instanceof RangeError}return!1},Io=(t,e)=>{const n=e.createGain();t.connect(n);const i=(e=>()=>{e.call(t,n),t.removeEventListener("ended",i)})(t.disconnect);t.addEventListener("ended",i),fo(t,n),t.stop=(e=>{let i=!1;return(s=0)=>{if(i)try{e.call(t,s)}catch{n.gain.setValueAtTime(0,s)}else e.call(t,s),i=!0}})(t.stop)},Do=(t,e)=>n=>{const i={value:t};return Object.defineProperties(n,{currentTarget:i,target:i}),"function"==typeof e?e.call(t,n):e.handleEvent.call(t,n)},Ro=(t=>(e,n,[i,s,r],o)=>{t(e[s],[n,i,r],(t=>t[0]===n&&t[1]===i),o)})(mr),jo=(t=>(e,n,[i,s,r],o)=>{const a=e.get(i);void 0===a?e.set(i,new Set([[s,n,r]])):t(a,[s,n,r],(t=>t[0]===s&&t[1]===n),o)})(mr),$o=(t=>(e,n,i,s)=>t(e[s],(t=>t[0]===n&&t[1]===i)))(Ys),Lo=new WeakMap,Fo=(t=>e=>{var n;return null!==(n=t.get(e))&&void 0!==n?n:0})(Lo),No=(Bo=new Map,Vo=new WeakMap,(t,e)=>{const n=Vo.get(t);if(void 0!==n)return n;const i=Bo.get(t);if(void 0!==i)return i;try{const n=e();return n instanceof Promise?(Bo.set(t,n),n.catch((()=>!1)).then((e=>(Bo.delete(t),Vo.set(t,e),e)))):(Vo.set(t,n),n)}catch{return Vo.set(t,!1),!1}});var Bo,Vo;const Wo="undefined"==typeof window?null:window,Ho=((t,e)=>(n,i)=>{const s=n.createAnalyser();if(io(s,i),!(i.maxDecibels>i.minDecibels))throw e();return no(s,i,"fftSize"),no(s,i,"maxDecibels"),no(s,i,"minDecibels"),no(s,i,"smoothingTimeConstant"),t(so,(()=>so(s)))||(t=>{t.getFloatTimeDomainData=e=>{const n=new Uint8Array(e.length);t.getByteTimeDomainData(n);const i=Math.max(n.length,t.fftSize);for(let t=0;t<i;t+=1)e[t]=.0078125*(n[t]-128);return e}})(s),s})(No,nr),Go=(t=>e=>{const n=t(e);if(null===n.renderer)throw new Error("Missing the renderer of the given AudioNode in the audio graph.");return n.renderer})(lr),zo=((t,e,n)=>async(i,s,r,o)=>{const a=t(i),c=[...o,i];await Promise.all(a.activeInputs.map(((t,o)=>Array.from(t).filter((([t])=>!c.includes(t))).map((async([t,a])=>{const l=e(t),h=await l.render(t,s,c),u=i.context.destination;n(t)||i===u&&n(i)||h.connect(r,a,o)})))).reduce(((t,e)=>[...t,...e]),[]))})(lr,Go,Mr),Yo=((t,e,n)=>()=>{const i=new WeakMap;return{render(s,r,o){const a=i.get(r);return void 0!==a?Promise.resolve(a):(async(s,r,o)=>{let a=e(s);if(!tr(a,r)){const e={channelCount:a.channelCount,channelCountMode:a.channelCountMode,channelInterpretation:a.channelInterpretation,fftSize:a.fftSize,maxDecibels:a.maxDecibels,minDecibels:a.minDecibels,smoothingTimeConstant:a.smoothingTimeConstant};a=t(r,e)}return i.set(r,a),await n(s,r,a,o),a})(s,r,o)}}})(Ho,Sr,zo),Xo=(Uo=js,t=>{const e=Uo.get(t);if(void 0===e)throw Kr();return e});var Uo;const qo=(t=>null===t?null:t.hasOwnProperty("OfflineAudioContext")?t.OfflineAudioContext:t.hasOwnProperty("webkitOfflineAudioContext")?t.webkitOfflineAudioContext:null)(Wo),Ko=(t=>e=>null!==t&&e instanceof t)(qo),Zo=new WeakMap,Qo=(t=>class{constructor(t){this._nativeEventTarget=t,this._listeners=new WeakMap}addEventListener(e,n,i){if(null!==n){let s=this._listeners.get(n);void 0===s&&(s=t(this,n),"function"==typeof n&&this._listeners.set(n,s)),this._nativeEventTarget.addEventListener(e,s,i)}}dispatchEvent(t){return this._nativeEventTarget.dispatchEvent(t)}removeEventListener(t,e,n){const i=null===e?void 0:this._listeners.get(e);this._nativeEventTarget.removeEventListener(t,void 0===i?null:i,n)}})(Do),Jo=(t=>null===t?null:t.hasOwnProperty("AudioContext")?t.AudioContext:t.hasOwnProperty("webkitAudioContext")?t.webkitAudioContext:null)(Wo),ta=(t=>e=>null!==t&&e instanceof t)(Jo),ea=(t=>e=>null!==t&&"function"==typeof t.AudioNode&&e instanceof t.AudioNode)(Wo),na=(t=>e=>null!==t&&"function"==typeof t.AudioParam&&e instanceof t.AudioParam)(Wo),ia=((t,e,n,i,s,r,o,a,c,l,h,u,d,f,p)=>class extends l{constructor(e,i,s,r){super(s),this._context=e,this._nativeAudioNode=s;const o=h(e);u(o)&&!0!==n(Or,(()=>Or(o)))&&(t=>{const e=new Map;t.connect=(t=>(n,i=0,s=0)=>{const r=kr(n)?t(n,i,s):t(n,i),o=e.get(n);return void 0===o?e.set(n,[{input:s,output:i}]):o.every((t=>t.input!==s||t.output!==i))&&o.push({input:s,output:i}),r})(t.connect.bind(t)),t.disconnect=(n=>(i,s,r)=>{if(n.apply(t),void 0===i)e.clear();else if("number"==typeof i)for(const[t,n]of e){const s=n.filter((t=>t.output!==i));0===s.length?e.delete(t):e.set(t,s)}else if(e.has(i))if(void 0===s)e.delete(i);else{const t=e.get(i);if(void 0!==t){const n=t.filter((t=>t.output!==s&&(t.input!==r||void 0===r)));0===n.length?e.delete(i):e.set(i,n)}}for(const[n,i]of e)i.forEach((e=>{kr(n)?t.connect(n,e.output,e.input):t.connect(n,e.output)}))})(t.disconnect)})(s),Is.set(this,s),$s.set(this,new Set),"closed"!==e.state&&i&&qs(this),t(this,r,s)}get channelCount(){return this._nativeAudioNode.channelCount}set channelCount(t){this._nativeAudioNode.channelCount=t}get channelCountMode(){return this._nativeAudioNode.channelCountMode}set channelCountMode(t){this._nativeAudioNode.channelCountMode=t}get channelInterpretation(){return this._nativeAudioNode.channelInterpretation}set channelInterpretation(t){this._nativeAudioNode.channelInterpretation=t}get context(){return this._context}get numberOfInputs(){return this._nativeAudioNode.numberOfInputs}get numberOfOutputs(){return this._nativeAudioNode.numberOfOutputs}connect(t,n=0,a=0){if(n<0||n>=this._nativeAudioNode.numberOfOutputs)throw s();const l=h(this._context),u=p(l);if(d(t)||f(t))throw r();if(fr(t)){const s=Sr(t);try{const e=yr(this._nativeAudioNode,s,n,a),i=Ar(this);(u||i)&&this._nativeAudioNode.disconnect(...e),"closed"!==this.context.state&&!i&&Ar(t)&&qs(t)}catch(t){if(12===t.code)throw r();throw t}if(e(this,t,n,a,u)){const e=c([this],t);Er(e,i(u))}return t}const m=Tr(t);if("playbackRate"===m.name&&1024===m.maxValue)throw o();try{this._nativeAudioNode.connect(m,n),(u||Ar(this))&&this._nativeAudioNode.disconnect(m,n)}catch(t){if(12===t.code)throw r();throw t}if(Pr(this,t,n,u)){const e=c([this],t);Er(e,i(u))}}disconnect(t,e,n){let i;const o=h(this._context),l=p(o);if(void 0===t)i=((t,e)=>{const n=lr(t),i=[];for(const s of n.outputs)pr(s)?Ir(t,e,...s):Dr(t,e,...s),i.push(s[0]);return n.outputs.clear(),i})(this,l);else if("number"==typeof t){if(t<0||t>=this.numberOfOutputs)throw s();i=((t,e,n)=>{const i=lr(t),s=[];for(const r of i.outputs)r[1]===n&&(pr(r)?Ir(t,e,...r):Dr(t,e,...r),s.push(r[0]),i.outputs.delete(r));return s})(this,l,t)}else{if(void 0!==e&&(e<0||e>=this.numberOfOutputs))throw s();if(fr(t)&&void 0!==n&&(n<0||n>=t.numberOfInputs))throw s();if(i=((t,e,n,i,s)=>{const r=lr(t);return Array.from(r.outputs).filter((t=>!(t[0]!==n||void 0!==i&&t[1]!==i||void 0!==s&&t[2]!==s))).map((n=>(pr(n)?Ir(t,e,...n):Dr(t,e,...n),r.outputs.delete(n),n[0])))})(this,l,t,e,n),0===i.length)throw r()}for(const t of i){const e=c([this],t);Er(e,a)}}})((sa=Ps,(t,e,n)=>{const i=[];for(let t=0;t<n.numberOfInputs;t+=1)i.push(new Set);sa.set(t,{activeInputs:i,outputs:new Set,passiveInputs:new WeakMap,renderer:e})}),((t,e,n,i,s,r,o,a,c,l,h,u,d)=>{const f=new WeakMap;return(p,m,g,v,_)=>{const{activeInputs:y,passiveInputs:b}=r(m),{outputs:x}=r(p),C=a(p),w=r=>{const a=c(m),l=c(p);if(r){const e=Xs(b,p,g,v);t(y,p,e,!1),_||u(p)||n(l,a,g,v),d(m)&&qs(m)}else{const t=i(y,p,g,v);e(b,v,t,!1),_||u(p)||s(l,a,g,v);const n=o(m);if(0===n)h(m)&&Qs(m,y);else{const t=f.get(m);void 0!==t&&clearTimeout(t),f.set(m,setTimeout((()=>{h(m)&&Qs(m,y)}),1e3*n))}}};return!!l(x,[m,g,v],(t=>t[0]===m&&t[1]===g&&t[2]===v),!0)&&(C.add(w),h(p)?t(y,p,[g,v,w],!0):e(b,v,[p,g,w],!0),!0)}})(Ro,jo,yr,$o,wr,lr,Fo,Us,Sr,mr,ar,Mr,Ar),No,((t,e,n,i,s,r)=>o=>(a,c)=>{const l=t.get(a);if(void 0===l){if(!o&&r(a)){const t=i(a),{outputs:r}=n(a);for(const n of r)if(pr(n)){const s=i(n[0]);e(t,s,n[1],n[2])}else{const e=s(n[0]);t.disconnect(e,n[1])}}t.set(a,c)}else t.set(a,l+c)})(Ls,wr,lr,Sr,Tr,ar),nr,Zr,yo,((t,e,n,i,s,r,o,a)=>(c,l)=>{const h=e.get(c);if(void 0===h)throw new Error("Missing the expected cycle count.");const u=r(c.context),d=a(u);if(h===l){if(e.delete(c),!d&&o(c)){const e=i(c),{outputs:r}=n(c);for(const n of r)if(pr(n)){const s=i(n[0]);t(e,s,n[1],n[2])}else{const t=s(n[0]);e.connect(t,n[1])}}}else e.set(c,h-l)})(yr,Ls,lr,Sr,Tr,Xo,ar,Ko),((t,e,n)=>function i(s,r){const o=fr(r)?r:n(t,r);if((t=>"delayTime"in t)(o))return[];if(s[0]===o)return[s];if(s.includes(o))return[];const{outputs:a}=e(o);return Array.from(a).map((t=>i([...s,o],t[0]))).reduce(((t,e)=>t.concat(e)),[])})(Zo,lr,zs),Qo,Xo,ta,ea,na,Ko);var sa;const ra=((t,e,n,i,s,r)=>class extends t{constructor(t,n){const o=s(t),a={...Js,...n},c=i(o,a);super(t,!1,c,r(o)?e():null),this._nativeAnalyserNode=c}get fftSize(){return this._nativeAnalyserNode.fftSize}set fftSize(t){this._nativeAnalyserNode.fftSize=t}get frequencyBinCount(){return this._nativeAnalyserNode.frequencyBinCount}get maxDecibels(){return this._nativeAnalyserNode.maxDecibels}set maxDecibels(t){const e=this._nativeAnalyserNode.maxDecibels;if(this._nativeAnalyserNode.maxDecibels=t,!(t>this._nativeAnalyserNode.minDecibels))throw this._nativeAnalyserNode.maxDecibels=e,n()}get minDecibels(){return this._nativeAnalyserNode.minDecibels}set minDecibels(t){const e=this._nativeAnalyserNode.minDecibels;if(this._nativeAnalyserNode.minDecibels=t,!(this._nativeAnalyserNode.maxDecibels>t))throw this._nativeAnalyserNode.minDecibels=e,n()}get smoothingTimeConstant(){return this._nativeAnalyserNode.smoothingTimeConstant}set smoothingTimeConstant(t){this._nativeAnalyserNode.smoothingTimeConstant=t}getByteFrequencyData(t){this._nativeAnalyserNode.getByteFrequencyData(t)}getByteTimeDomainData(t){this._nativeAnalyserNode.getByteTimeDomainData(t)}getFloatFrequencyData(t){this._nativeAnalyserNode.getFloatFrequencyData(t)}getFloatTimeDomainData(t){this._nativeAnalyserNode.getFloatTimeDomainData(t)}})(ia,Yo,nr,Ho,Xo,Ko),oa=new WeakSet,aa=(t=>null===t?null:t.hasOwnProperty("AudioBuffer")?t.AudioBuffer:null)(Wo),ca=(la=new Uint32Array(1),t=>(la[0]=t,la[0]));var la;const ha=((t,e)=>n=>{n.copyFromChannel=(i,s,r=0)=>{const o=t(r),a=t(s);if(a>=n.numberOfChannels)throw e();const c=n.length,l=n.getChannelData(a),h=i.length;for(let t=o<0?-o:0;t+o<c&&t<h;t+=1)i[t]=l[t+o]},n.copyToChannel=(i,s,r=0)=>{const o=t(r),a=t(s);if(a>=n.numberOfChannels)throw e();const c=n.length,l=n.getChannelData(a),h=i.length;for(let t=o<0?-o:0;t+o<c&&t<h;t+=1)l[t+o]=i[t]}})(ca,nr),ua=(t=>e=>{e.copyFromChannel=(n=>(i,s,r=0)=>{const o=t(r),a=t(s);if(o<e.length)return n.call(e,i,a,o)})(e.copyFromChannel),e.copyToChannel=(n=>(i,s,r=0)=>{const o=t(r),a=t(s);if(o<e.length)return n.call(e,i,a,o)})(e.copyToChannel)})(ca),da=((t,e,n,i,s,r,o,a)=>{let c=null;return class l{constructor(l){if(null===s)throw new Error("Missing the native OfflineAudioContext constructor.");const{length:h,numberOfChannels:u,sampleRate:d}={...sr,...l};null===c&&(c=new s(1,1,44100));const f=null!==i&&e(r,r)?new i({length:h,numberOfChannels:u,sampleRate:d}):c.createBuffer(u,h,d);if(0===f.numberOfChannels)throw n();return"function"!=typeof f.copyFromChannel?(o(f),ir(f)):e(er,(()=>er(f)))||a(f),t.add(f),f}static[Symbol.hasInstance](e){return null!==e&&"object"==typeof e&&Object.getPrototypeOf(e)===l.prototype||t.has(e)}}})(oa,No,yo,aa,qo,(t=>()=>{if(null===t)return!1;try{new t({length:1,sampleRate:44100})}catch{return!1}return!0})(aa),ha,ua),fa=(t=>(e,n)=>{const i=t(e,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"discrete",gain:0});n.connect(i).connect(e.destination);const s=()=>{n.removeEventListener("ended",s),n.disconnect(i),i.disconnect()};n.addEventListener("ended",s)})(mo),pa=((t,e,n)=>async(i,s,r,o)=>{const a=e(i);await Promise.all(Array.from(a.activeInputs).map((async([e,i])=>{const a=t(e),c=await a.render(e,s,o);n(e)||c.connect(r,i)})))})(Go,hr,Mr),ma=(t=>(e,n,i,s)=>t(n,e,i,s))(pa),ga=((t,e,n,i,s,r,o,a,c,l,h)=>(u,d)=>{const f=u.createBufferSource();return io(f,d),ro(f,d,"playbackRate"),no(f,d,"buffer"),no(f,d,"loop"),no(f,d,"loopEnd"),no(f,d,"loopStart"),e(n,(()=>n(u)))||(t=>{t.start=(e=>{let n=!1;return(i=0,s=0,r)=>{if(n)throw Kr();e.call(t,i,s,r),n=!0}})(t.start)})(f),e(i,(()=>i(u)))||c(f),e(s,(()=>s(u)))||l(f,u),e(r,(()=>r(u)))||oo(f),e(o,(()=>o(u)))||h(f,u),e(a,(()=>a(u)))||ao(f),t(u,f),f})(fa,No,(t=>{const e=t.createBufferSource();e.start();try{e.start()}catch{return!0}return!1}),(t=>{const e=t.createBufferSource(),n=t.createBuffer(1,1,44100);e.buffer=n;try{e.start(0,1)}catch{return!1}return!0}),(t=>{const e=t.createBufferSource();e.start();try{e.stop()}catch{return!1}return!0}),Eo,ko,Po,(t=>{t.start=(e=>(n=0,i=0,s)=>{const r=t.buffer,o=null===r?i:Math.min(r.duration,i);null!==r&&o>r.duration-.5/t.context.sampleRate?e.call(t,n,0,0):e.call(t,n,o,s)})(t.start)}),(t=>(e,n)=>{const i=n.createBuffer(1,1,44100);null===e.buffer&&(e.buffer=i),t(e,"buffer",(t=>()=>{const n=t.call(e);return n===i?null:n}),(t=>n=>t.call(e,null===n?i:n)))})(Ao),Io),va=((t,e)=>(n,i,s,r)=>(t(i).replay(s),e(i,n,s,r)))((t=>e=>{const n=t(e);if(null===n.renderer)throw new Error("Missing the renderer of the given AudioParam in the audio graph.");return n.renderer})(hr),pa),_a=((t,e,n,i,s)=>()=>{const r=new WeakMap;let o=null,a=null;return{set start(t){o=t},set stop(t){a=t},render(c,l,h){const u=r.get(l);return void 0!==u?Promise.resolve(u):(async(c,l,h)=>{let u=n(c);const d=tr(u,l);if(!d){const t={buffer:u.buffer,channelCount:u.channelCount,channelCountMode:u.channelCountMode,channelInterpretation:u.channelInterpretation,loop:u.loop,loopEnd:u.loopEnd,loopStart:u.loopStart,playbackRate:u.playbackRate.value};u=e(l,t),null!==o&&u.start(...o),null!==a&&u.stop(a)}return r.set(l,u),d?await t(l,c.playbackRate,u.playbackRate,h):await i(l,c.playbackRate,u.playbackRate,h),await s(c,l,u,h),u})(c,l,h)}}})(ma,ga,Sr,va,zo),ya=((t,e,n,i,s,r,o,a,c,l,h,u,d)=>(f,p,m,g=null,v=null)=>{const _=new Es.AutomationEventList(m.defaultValue),y=p?i(_):null,b={get defaultValue(){return m.defaultValue},get maxValue(){return null===g?m.maxValue:g},get minValue(){return null===v?m.minValue:v},get value(){return m.value},set value(t){m.value=t,b.setValueAtTime(t,f.context.currentTime)},cancelAndHoldAtTime(t){if("function"==typeof m.cancelAndHoldAtTime)null===y&&_.flush(f.context.currentTime),_.add(s(t)),m.cancelAndHoldAtTime(t);else{const e=Array.from(_).pop();null===y&&_.flush(f.context.currentTime),_.add(s(t));const n=Array.from(_).pop();m.cancelScheduledValues(t),e!==n&&void 0!==n&&("exponentialRampToValue"===n.type?m.exponentialRampToValueAtTime(n.value,n.endTime):"linearRampToValue"===n.type?m.linearRampToValueAtTime(n.value,n.endTime):"setValue"===n.type?m.setValueAtTime(n.value,n.startTime):"setValueCurve"===n.type&&m.setValueCurveAtTime(n.values,n.startTime,n.duration))}return b},cancelScheduledValues:t=>(null===y&&_.flush(f.context.currentTime),_.add(r(t)),m.cancelScheduledValues(t),b),exponentialRampToValueAtTime(t,e){if(0===t)throw new RangeError;if(!Number.isFinite(e)||e<0)throw new RangeError;return null===y&&_.flush(f.context.currentTime),_.add(o(t,e)),m.exponentialRampToValueAtTime(t,e),b},linearRampToValueAtTime:(t,e)=>(null===y&&_.flush(f.context.currentTime),_.add(a(t,e)),m.linearRampToValueAtTime(t,e),b),setTargetAtTime:(t,e,n)=>(null===y&&_.flush(f.context.currentTime),_.add(c(t,e,n)),m.setTargetAtTime(t,e,n),b),setValueAtTime:(t,e)=>(null===y&&_.flush(f.context.currentTime),_.add(l(t,e)),m.setValueAtTime(t,e),b),setValueCurveAtTime(t,e,n){const i=t instanceof Float32Array?t:new Float32Array(t);if(null!==u&&"webkitAudioContext"===u.name){const t=e+n,s=f.context.sampleRate,r=Math.ceil(e*s),o=Math.floor(t*s),a=o-r,c=new Float32Array(a);for(let t=0;t<a;t+=1){const o=(i.length-1)/n*((r+t)/s-e),a=Math.floor(o),l=Math.ceil(o);c[t]=a===l?i[a]:(1-(o-a))*i[a]+(1-(l-o))*i[l]}null===y&&_.flush(f.context.currentTime),_.add(h(c,e,n)),m.setValueCurveAtTime(c,e,n);const l=o/s;l<t&&d(b,c[c.length-1],l),d(b,i[i.length-1],t)}else null===y&&_.flush(f.context.currentTime),_.add(h(i,e,n)),m.setValueCurveAtTime(i,e,n);return b}};return n.set(b,m),e.set(b,f),t(b,y),b})((ba=Ds,(t,e)=>{ba.set(t,{activeInputs:new Set,passiveInputs:new WeakMap,renderer:e})}),Zo,Rs,(t=>({replay(e){for(const n of t)if("exponentialRampToValue"===n.type){const{endTime:t,value:i}=n;e.exponentialRampToValueAtTime(i,t)}else if("linearRampToValue"===n.type){const{endTime:t,value:i}=n;e.linearRampToValueAtTime(i,t)}else if("setTarget"===n.type){const{startTime:t,target:i,timeConstant:s}=n;e.setTargetAtTime(i,t,s)}else if("setValue"===n.type){const{startTime:t,value:i}=n;e.setValueAtTime(i,t)}else{if("setValueCurve"!==n.type)throw new Error("Can't apply an unknown automation.");{const{duration:t,startTime:i,values:s}=n;e.setValueCurveAtTime(s,i,t)}}}})),Es.createCancelAndHoldAutomationEvent,Es.createCancelScheduledValuesAutomationEvent,Es.createExponentialRampToValueAutomationEvent,Es.createLinearRampToValueAutomationEvent,Es.createSetTargetAutomationEvent,Es.createSetValueAutomationEvent,Es.createSetValueCurveAutomationEvent,Jo,Oo);var ba;const xa=((t,e,n,i,s,r,o,a)=>class extends t{constructor(t,i){const a=r(t),c={...cr,...i},l=s(a,c),h=o(a),u=h?e():null;super(t,!1,l,u),this._audioBufferSourceNodeRenderer=u,this._isBufferNullified=!1,this._isBufferSet=null!==c.buffer,this._nativeAudioBufferSourceNode=l,this._onended=null,this._playbackRate=n(this,h,l.playbackRate,or,rr)}get buffer(){return this._isBufferNullified?null:this._nativeAudioBufferSourceNode.buffer}set buffer(t){if(this._nativeAudioBufferSourceNode.buffer=t,null!==t){if(this._isBufferSet)throw i();this._isBufferSet=!0}}get loop(){return this._nativeAudioBufferSourceNode.loop}set loop(t){this._nativeAudioBufferSourceNode.loop=t}get loopEnd(){return this._nativeAudioBufferSourceNode.loopEnd}set loopEnd(t){this._nativeAudioBufferSourceNode.loopEnd=t}get loopStart(){return this._nativeAudioBufferSourceNode.loopStart}set loopStart(t){this._nativeAudioBufferSourceNode.loopStart=t}get onended(){return this._onended}set onended(t){const e="function"==typeof t?a(this,t):null;this._nativeAudioBufferSourceNode.onended=e;const n=this._nativeAudioBufferSourceNode.onended;this._onended=null!==n&&n===e?t:n}get playbackRate(){return this._playbackRate}start(t=0,e=0,n){if(this._nativeAudioBufferSourceNode.start(t,e,n),null!==this._audioBufferSourceNodeRenderer&&(this._audioBufferSourceNodeRenderer.start=void 0===n?[t,e]:[t,e,n]),"closed"!==this.context.state){qs(this);const t=()=>{this._nativeAudioBufferSourceNode.removeEventListener("ended",t),ar(this)&&Zs(this)};this._nativeAudioBufferSourceNode.addEventListener("ended",t)}}stop(t=0){this._nativeAudioBufferSourceNode.stop(t),null!==this._audioBufferSourceNodeRenderer&&(this._audioBufferSourceNodeRenderer.stop=t)}})(ia,_a,ya,Kr,ga,Xo,Ko,Do),Ca=((t,e,n,i,s,r,o,a)=>class extends t{constructor(t,n){const i=r(t),c=o(i),l=s(i,n,c);super(t,!1,l,c?e(a):null),this._isNodeOfNativeOfflineAudioContext=c,this._nativeAudioDestinationNode=l}get channelCount(){return this._nativeAudioDestinationNode.channelCount}set channelCount(t){if(this._isNodeOfNativeOfflineAudioContext)throw i();if(t>this._nativeAudioDestinationNode.maxChannelCount)throw n();this._nativeAudioDestinationNode.channelCount=t}get channelCountMode(){return this._nativeAudioDestinationNode.channelCountMode}set channelCountMode(t){if(this._isNodeOfNativeOfflineAudioContext)throw i();this._nativeAudioDestinationNode.channelCountMode=t}get maxChannelCount(){return this._nativeAudioDestinationNode.maxChannelCount}})(ia,(t=>{let e=null;return{render:(n,i,s)=>(null===e&&(e=(async(e,n,i)=>{const s=n.destination;return await t(e,n,s,i),s})(n,i,s)),e)}}),nr,Kr,((t,e)=>(n,i,s)=>{const r=n.destination;if(r.channelCount!==i)try{r.channelCount=i}catch{}s&&"explicit"!==r.channelCountMode&&(r.channelCountMode="explicit"),0===r.maxChannelCount&&Object.defineProperty(r,"maxChannelCount",{value:i});const o=t(n,{channelCount:i,channelCountMode:r.channelCountMode,channelInterpretation:r.channelInterpretation,gain:1});return e(o,"channelCount",(t=>()=>t.call(o)),(t=>e=>{t.call(o,e);try{r.channelCount=e}catch(t){if(e>r.maxChannelCount)throw t}})),e(o,"channelCountMode",(t=>()=>t.call(o)),(t=>e=>{t.call(o,e),r.channelCountMode=e})),e(o,"channelInterpretation",(t=>()=>t.call(o)),(t=>e=>{t.call(o,e),r.channelInterpretation=e})),Object.defineProperty(o,"maxChannelCount",{get:()=>r.maxChannelCount}),o.connect(r),o})(mo,Ao),Xo,Ko,zo),wa=((t,e,n,i,s)=>()=>{const r=new WeakMap;return{render(o,a,c){const l=r.get(a);return void 0!==l?Promise.resolve(l):(async(o,a,c)=>{let l=n(o);const h=tr(l,a);if(!h){const t={Q:l.Q.value,channelCount:l.channelCount,channelCountMode:l.channelCountMode,channelInterpretation:l.channelInterpretation,detune:l.detune.value,frequency:l.frequency.value,gain:l.gain.value,type:l.type};l=e(a,t)}return r.set(a,l),h?(await t(a,o.Q,l.Q,c),await t(a,o.detune,l.detune,c),await t(a,o.frequency,l.frequency,c),await t(a,o.gain,l.gain,c)):(await i(a,o.Q,l.Q,c),await i(a,o.detune,l.detune,c),await i(a,o.frequency,l.frequency,c),await i(a,o.gain,l.gain,c)),await s(o,a,l,c),l})(o,a,c)}}})(ma,ho,Sr,va,zo),Sa=(t=>(e,n)=>t.set(e,n))(Lo),Ta=((t,e,n,i,s,r,o,a)=>class extends t{constructor(t,i){const c=r(t),l={...Br,...i},h=s(c,l),u=o(c);super(t,!1,h,u?n():null),this._Q=e(this,u,h.Q,or,rr),this._detune=e(this,u,h.detune,1200*Math.log2(or),-1200*Math.log2(or)),this._frequency=e(this,u,h.frequency,t.sampleRate/2,0),this._gain=e(this,u,h.gain,40*Math.log10(or),rr),this._nativeBiquadFilterNode=h,a(this,1)}get detune(){return this._detune}get frequency(){return this._frequency}get gain(){return this._gain}get Q(){return this._Q}get type(){return this._nativeBiquadFilterNode.type}set type(t){this._nativeBiquadFilterNode.type=t}getFrequencyResponse(t,e,n){try{this._nativeBiquadFilterNode.getFrequencyResponse(t,e,n)}catch(t){if(11===t.code)throw i();throw t}if(t.length!==e.length||e.length!==n.length)throw i()}})(ia,ya,wa,Zr,ho,Xo,Ko,Sa),Ma=((t,e)=>(n,i,s)=>{const r=new Set;return n.connect=(s=>(o,a=0,c=0)=>{const l=0===r.size;if(e(o))return s.call(n,o,a,c),t(r,[o,a,c],(t=>t[0]===o&&t[1]===a&&t[2]===c),!0),l&&i(),o;s.call(n,o,a),t(r,[o,a],(t=>t[0]===o&&t[1]===a),!0),l&&i()})(n.connect),n.disconnect=(t=>(i,o,a)=>{const c=r.size>0;if(void 0===i)t.apply(n),r.clear();else if("number"==typeof i){t.call(n,i);for(const t of r)t[1]===i&&r.delete(t)}else{e(i)?t.call(n,i,o,a):t.call(n,i,o);for(const t of r)t[0]!==i||void 0!==o&&t[1]!==o||void 0!==a&&t[2]!==a||r.delete(t)}const l=0===r.size;c&&l&&s()})(n.disconnect),n})(mr,ea),Aa=((t,e)=>(n,i)=>{const s=n.createChannelMerger(i.numberOfInputs);return null!==t&&"webkitAudioContext"===t.name&&e(n,s),io(s,i),s})(Jo,((t,e)=>(n,i)=>{i.channelCount=1,i.channelCountMode="explicit",Object.defineProperty(i,"channelCount",{get:()=>1,set:()=>{throw t()}}),Object.defineProperty(i,"channelCountMode",{get:()=>"explicit",set:()=>{throw t()}});const s=n.createBufferSource();e(i,(()=>{const t=i.numberOfInputs;for(let e=0;e<t;e+=1)s.connect(i,0,e)}),(()=>s.disconnect(i)))})(Kr,Ma)),Oa=((t,e,n,i,s)=>class extends t{constructor(t,r){const o=i(t),a={...Vr,...r};super(t,!1,n(o,a),s(o)?e():null)}})(ia,((t,e,n)=>()=>{const i=new WeakMap;return{render(s,r,o){const a=i.get(r);return void 0!==a?Promise.resolve(a):(async(s,r,o)=>{let a=e(s);if(!tr(a,r)){const e={channelCount:a.channelCount,channelCountMode:a.channelCountMode,channelInterpretation:a.channelInterpretation,numberOfInputs:a.numberOfInputs};a=t(r,e)}return i.set(r,a),await n(s,r,a,o),a})(s,r,o)}}})(Aa,Sr,zo),Aa,Xo,Ko),Ea=((t,e,n,i,s,r)=>class extends t{constructor(t,o){const a=i(t),c=r({...Wr,...o});super(t,!1,n(a,c),s(a)?e():null)}})(ia,((t,e,n)=>()=>{const i=new WeakMap;return{render(s,r,o){const a=i.get(r);return void 0!==a?Promise.resolve(a):(async(s,r,o)=>{let a=e(s);if(!tr(a,r)){const e={channelCount:a.channelCount,channelCountMode:a.channelCountMode,channelInterpretation:a.channelInterpretation,numberOfOutputs:a.numberOfOutputs};a=t(r,e)}return i.set(r,a),await n(s,r,a,o),a})(s,r,o)}}})(uo,Sr,zo),uo,Xo,Ko,(t=>({...t,channelCount:t.numberOfOutputs}))),ka=((t,e,n,i)=>(s,{offset:r,...o})=>{const a=s.createBuffer(1,2,44100),c=e(s,{buffer:null,channelCount:2,channelCountMode:"max",channelInterpretation:"speakers",loop:!1,loopEnd:0,loopStart:0,playbackRate:1}),l=n(s,{...o,gain:r}),h=a.getChannelData(0);h[0]=1,h[1]=1,c.buffer=a,c.loop=!0;const u={get bufferSize(){},get channelCount(){return l.channelCount},set channelCount(t){l.channelCount=t},get channelCountMode(){return l.channelCountMode},set channelCountMode(t){l.channelCountMode=t},get channelInterpretation(){return l.channelInterpretation},set channelInterpretation(t){l.channelInterpretation=t},get context(){return l.context},get inputs(){return[]},get numberOfInputs(){return c.numberOfInputs},get numberOfOutputs(){return l.numberOfOutputs},get offset(){return l.gain},get onended(){return c.onended},set onended(t){c.onended=t},addEventListener:(...t)=>c.addEventListener(t[0],t[1],t[2]),dispatchEvent:(...t)=>c.dispatchEvent(t[0]),removeEventListener:(...t)=>c.removeEventListener(t[0],t[1],t[2]),start(t=0){c.start.call(c,t)},stop(t=0){c.stop.call(c,t)}};return t(s,c),i(fo(u,l),(()=>c.connect(l)),(()=>c.disconnect(l)))})(fa,ga,mo,Ma),Pa=((t,e,n,i,s)=>(r,o)=>{if(void 0===r.createConstantSource)return n(r,o);const a=r.createConstantSource();return io(a,o),ro(a,o,"offset"),e(i,(()=>i(r)))||oo(a),e(s,(()=>s(r)))||ao(a),t(r,a),a})(fa,No,ka,Eo,Po),Ia=((t,e,n,i,s,r,o)=>class extends t{constructor(t,o){const a=s(t),c={...Hr,...o},l=i(a,c),h=r(a),u=h?n():null;super(t,!1,l,u),this._constantSourceNodeRenderer=u,this._nativeConstantSourceNode=l,this._offset=e(this,h,l.offset,or,rr),this._onended=null}get offset(){return this._offset}get onended(){return this._onended}set onended(t){const e="function"==typeof t?o(this,t):null;this._nativeConstantSourceNode.onended=e;const n=this._nativeConstantSourceNode.onended;this._onended=null!==n&&n===e?t:n}start(t=0){if(this._nativeConstantSourceNode.start(t),null!==this._constantSourceNodeRenderer&&(this._constantSourceNodeRenderer.start=t),"closed"!==this.context.state){qs(this);const t=()=>{this._nativeConstantSourceNode.removeEventListener("ended",t),ar(this)&&Zs(this)};this._nativeConstantSourceNode.addEventListener("ended",t)}}stop(t=0){this._nativeConstantSourceNode.stop(t),null!==this._constantSourceNodeRenderer&&(this._constantSourceNodeRenderer.stop=t)}})(ia,ya,((t,e,n,i,s)=>()=>{const r=new WeakMap;let o=null,a=null;return{set start(t){o=t},set stop(t){a=t},render(c,l,h){const u=r.get(l);return void 0!==u?Promise.resolve(u):(async(c,l,h)=>{let u=n(c);const d=tr(u,l);if(!d){const t={channelCount:u.channelCount,channelCountMode:u.channelCountMode,channelInterpretation:u.channelInterpretation,offset:u.offset.value};u=e(l,t),null!==o&&u.start(o),null!==a&&u.stop(a)}return r.set(l,u),d?await t(l,c.offset,u.offset,h):await i(l,c.offset,u.offset,h),await s(c,l,u,h),u})(c,l,h)}}})(ma,Pa,Sr,va,zo),Pa,Xo,Ko,Do),Da=((t,e)=>(n,i)=>{const s=n.createConvolver();if(io(s,i),i.disableNormalization===s.normalize&&(s.normalize=!i.disableNormalization),no(s,i,"buffer"),i.channelCount>2)throw t();if(e(s,"channelCount",(t=>()=>t.call(s)),(e=>n=>{if(n>2)throw t();return e.call(s,n)})),"max"===i.channelCountMode)throw t();return e(s,"channelCountMode",(t=>()=>t.call(s)),(e=>n=>{if("max"===n)throw t();return e.call(s,n)})),s})(yo,Ao),Ra=((t,e,n,i,s,r)=>class extends t{constructor(t,o){const a=i(t),c={...Gr,...o},l=n(a,c);super(t,!1,l,s(a)?e():null),this._isBufferNullified=!1,this._nativeConvolverNode=l,null!==c.buffer&&r(this,c.buffer.duration)}get buffer(){return this._isBufferNullified?null:this._nativeConvolverNode.buffer}set buffer(t){if(this._nativeConvolverNode.buffer=t,null===t&&null!==this._nativeConvolverNode.buffer){const t=this._nativeConvolverNode.context;this._nativeConvolverNode.buffer=t.createBuffer(1,1,44100),this._isBufferNullified=!0,r(this,0)}else this._isBufferNullified=!1,r(this,null===this._nativeConvolverNode.buffer?0:this._nativeConvolverNode.buffer.duration)}get normalize(){return this._nativeConvolverNode.normalize}set normalize(t){this._nativeConvolverNode.normalize=t}})(ia,((t,e,n)=>()=>{const i=new WeakMap;return{render(s,r,o){const a=i.get(r);return void 0!==a?Promise.resolve(a):(async(s,r,o)=>{let a=e(s);if(!tr(a,r)){const e={buffer:a.buffer,channelCount:a.channelCount,channelCountMode:a.channelCountMode,channelInterpretation:a.channelInterpretation,disableNormalization:!a.normalize};a=t(r,e)}return i.set(r,a),_r(a)?await n(s,r,a.inputs[0],o):await n(s,r,a,o),a})(s,r,o)}}})(Da,Sr,zo),Da,Xo,Ko,Sa),ja=((t,e,n,i,s,r,o)=>class extends t{constructor(t,a){const c=s(t),l={...Yr,...a},h=i(c,l),u=r(c);super(t,!1,h,u?n(l.maxDelayTime):null),this._delayTime=e(this,u,h.delayTime),o(this,l.maxDelayTime)}get delayTime(){return this._delayTime}})(ia,ya,((t,e,n,i,s)=>r=>{const o=new WeakMap;return{render(a,c,l){const h=o.get(c);return void 0!==h?Promise.resolve(h):(async(a,c,l)=>{let h=n(a);const u=tr(h,c);if(!u){const t={channelCount:h.channelCount,channelCountMode:h.channelCountMode,channelInterpretation:h.channelInterpretation,delayTime:h.delayTime.value,maxDelayTime:r};h=e(c,t)}return o.set(c,h),u?await t(c,a.delayTime,h.delayTime,l):await i(c,a.delayTime,h.delayTime,l),await s(a,c,h,l),h})(a,c,l)}}})(ma,po,Sr,va,zo),po,Xo,Ko,Sa),$a=(t=>(e,n)=>{const i=e.createDynamicsCompressor();if(io(i,n),n.channelCount>2)throw t();if("max"===n.channelCountMode)throw t();return ro(i,n,"attack"),ro(i,n,"knee"),ro(i,n,"ratio"),ro(i,n,"release"),ro(i,n,"threshold"),i})(yo),La=((t,e,n,i,s,r,o,a)=>class extends t{constructor(t,s){const c=r(t),l={...Ur,...s},h=i(c,l),u=o(c);super(t,!1,h,u?n():null),this._attack=e(this,u,h.attack),this._knee=e(this,u,h.knee),this._nativeDynamicsCompressorNode=h,this._ratio=e(this,u,h.ratio),this._release=e(this,u,h.release),this._threshold=e(this,u,h.threshold),a(this,.006)}get attack(){return this._attack}get channelCount(){return this._nativeDynamicsCompressorNode.channelCount}set channelCount(t){const e=this._nativeDynamicsCompressorNode.channelCount;if(this._nativeDynamicsCompressorNode.channelCount=t,t>2)throw this._nativeDynamicsCompressorNode.channelCount=e,s()}get channelCountMode(){return this._nativeDynamicsCompressorNode.channelCountMode}set channelCountMode(t){const e=this._nativeDynamicsCompressorNode.channelCountMode;if(this._nativeDynamicsCompressorNode.channelCountMode=t,"max"===t)throw this._nativeDynamicsCompressorNode.channelCountMode=e,s()}get knee(){return this._knee}get ratio(){return this._ratio}get reduction(){return"number"==typeof this._nativeDynamicsCompressorNode.reduction.value?this._nativeDynamicsCompressorNode.reduction.value:this._nativeDynamicsCompressorNode.reduction}get release(){return this._release}get threshold(){return this._threshold}})(ia,ya,((t,e,n,i,s)=>()=>{const r=new WeakMap;return{render(o,a,c){const l=r.get(a);return void 0!==l?Promise.resolve(l):(async(o,a,c)=>{let l=n(o);const h=tr(l,a);if(!h){const t={attack:l.attack.value,channelCount:l.channelCount,channelCountMode:l.channelCountMode,channelInterpretation:l.channelInterpretation,knee:l.knee.value,ratio:l.ratio.value,release:l.release.value,threshold:l.threshold.value};l=e(a,t)}return r.set(a,l),h?(await t(a,o.attack,l.attack,c),await t(a,o.knee,l.knee,c),await t(a,o.ratio,l.ratio,c),await t(a,o.release,l.release,c),await t(a,o.threshold,l.threshold,c)):(await i(a,o.attack,l.attack,c),await i(a,o.knee,l.knee,c),await i(a,o.ratio,l.ratio,c),await i(a,o.release,l.release,c),await i(a,o.threshold,l.threshold,c)),await s(o,a,l,c),l})(o,a,c)}}})(ma,$a,Sr,va,zo),$a,yo,Xo,Ko,Sa),Fa=((t,e,n,i,s,r)=>class extends t{constructor(t,o){const a=s(t),c={...qr,...o},l=i(a,c),h=r(a);super(t,!1,l,h?n():null),this._gain=e(this,h,l.gain,or,rr)}get gain(){return this._gain}})(ia,ya,((t,e,n,i,s)=>()=>{const r=new WeakMap;return{render(o,a,c){const l=r.get(a);return void 0!==l?Promise.resolve(l):(async(o,a,c)=>{let l=n(o);const h=tr(l,a);if(!h){const t={channelCount:l.channelCount,channelCountMode:l.channelCountMode,channelInterpretation:l.channelInterpretation,gain:l.gain.value};l=e(a,t)}return r.set(a,l),h?await t(a,o.gain,l.gain,c):await i(a,o.gain,l.gain,c),await s(o,a,l,c),l})(o,a,c)}}})(ma,mo,Sr,va,zo),mo,Xo,Ko),Na=((t,e,n,i)=>(s,r,{channelCount:o,channelCountMode:a,channelInterpretation:c,feedback:l,feedforward:h})=>{const u=co(r,s.sampleRate),d=l instanceof Float64Array?l:new Float64Array(l),f=h instanceof Float64Array?h:new Float64Array(h),p=d.length,m=f.length,g=Math.min(p,m);if(0===p||p>20)throw i();if(0===d[0])throw e();if(0===m||m>20)throw i();if(0===f[0])throw e();if(1!==d[0]){for(let t=0;t<m;t+=1)f[t]/=d[0];for(let t=1;t<p;t+=1)d[t]/=d[0]}const v=n(s,u,o,o);v.channelCount=o,v.channelCountMode=a,v.channelInterpretation=c;const _=[],y=[],b=[];for(let t=0;t<o;t+=1){_.push(0);const t=new Float32Array(32),e=new Float32Array(32);t.fill(0),e.fill(0),y.push(t),b.push(e)}v.onaudioprocess=t=>{const e=t.inputBuffer,n=t.outputBuffer,i=e.numberOfChannels;for(let t=0;t<i;t+=1){const i=e.getChannelData(t),s=n.getChannelData(t);_[t]=Jr(d,p,f,m,g,y[t],b[t],_[t],32,i,s)}};const x=s.sampleRate/2;return fo({get bufferSize(){return u},get channelCount(){return v.channelCount},set channelCount(t){v.channelCount=t},get channelCountMode(){return v.channelCountMode},set channelCountMode(t){v.channelCountMode=t},get channelInterpretation(){return v.channelInterpretation},set channelInterpretation(t){v.channelInterpretation=t},get context(){return v.context},get inputs(){return[v]},get numberOfInputs(){return v.numberOfInputs},get numberOfOutputs(){return v.numberOfOutputs},addEventListener:(...t)=>v.addEventListener(t[0],t[1],t[2]),dispatchEvent:(...t)=>v.dispatchEvent(t[0]),getFrequencyResponse(e,n,i){if(e.length!==n.length||n.length!==i.length)throw t();const s=e.length;for(let t=0;t<s;t+=1){const s=-Math.PI*(e[t]/x),r=[Math.cos(s),Math.sin(s)],o=go(vo(f,r),vo(d,r));n[t]=Math.sqrt(o[0]*o[0]+o[1]*o[1]),i[t]=Math.atan2(o[1],o[0])}},removeEventListener:(...t)=>v.removeEventListener(t[0],t[1],t[2])},v)})(Zr,Kr,_o,yo),Ba=((t,e,n,i)=>s=>t(eo,(()=>eo(s)))?Promise.resolve(t(i,i)).then((t=>{if(!t){const t=n(s,512,0,1);s.oncomplete=()=>{t.onaudioprocess=null,t.disconnect()},t.onaudioprocess=()=>s.currentTime,t.connect(s.destination)}return s.startRendering()})):new Promise((t=>{const n=e(s,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"discrete",gain:0});s.oncomplete=e=>{n.disconnect(),t(e.renderedBuffer)},n.connect(s.destination),s.startRendering()})))(No,mo,_o,((t,e)=>()=>{if(null===e)return Promise.resolve(!1);const n=new e(1,1,44100),i=t(n,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"discrete",gain:0});return new Promise((t=>{n.oncomplete=()=>{i.disconnect(),t(0!==n.currentTime)},n.startRendering()}))})(mo,qo)),Va=((t,e,n,i,s)=>(r,o)=>{const a=new WeakMap;let c=null;const l=async(l,h,u)=>{let d=null,f=e(l);const p=tr(f,h);if(void 0===h.createIIRFilter?d=t(h,{buffer:null,channelCount:2,channelCountMode:"max",channelInterpretation:"speakers",loop:!1,loopEnd:0,loopStart:0,playbackRate:1}):p||(f=h.createIIRFilter(o,r)),a.set(h,null===d?f:d),null!==d){if(null===c){if(null===n)throw new Error("Missing the native OfflineAudioContext constructor.");const t=new n(l.context.destination.channelCount,l.context.length,h.sampleRate);c=(async()=>{await i(l,t,t.destination,u);return((t,e,n,i)=>{const s=n instanceof Float64Array?n:new Float64Array(n),r=i instanceof Float64Array?i:new Float64Array(i),o=s.length,a=r.length,c=Math.min(o,a);if(1!==s[0]){for(let t=0;t<o;t+=1)r[t]/=s[0];for(let t=1;t<a;t+=1)s[t]/=s[0]}const l=new Float32Array(32),h=new Float32Array(32),u=e.createBuffer(t.numberOfChannels,t.length,t.sampleRate),d=t.numberOfChannels;for(let e=0;e<d;e+=1){const n=t.getChannelData(e),i=u.getChannelData(e);l.fill(0),h.fill(0),Jr(s,o,r,a,c,l,h,0,32,n,i)}return u})(await s(t),h,r,o)})()}const t=await c;return d.buffer=t,d.start(0),d}return await i(l,h,f,u),f};return{render(t,e,n){const i=a.get(e);return void 0!==i?Promise.resolve(i):l(t,e,n)}}})(ga,Sr,qo,zo,Ba),Wa=((t,e,n,i,s,r)=>class extends t{constructor(t,o){const a=i(t),c=s(a),l={...Qr,...o},h=e(a,c?null:t.baseLatency,l);super(t,!1,h,c?n(l.feedback,l.feedforward):null),(t=>{var e;t.getFrequencyResponse=(e=t.getFrequencyResponse,(n,i,s)=>{if(n.length!==i.length||i.length!==s.length)throw Zr();return e.call(t,n,i,s)})})(h),this._nativeIIRFilterNode=h,r(this,1)}getFrequencyResponse(t,e,n){return this._nativeIIRFilterNode.getFrequencyResponse(t,e,n)}})(ia,(t=>(e,n,i)=>{if(void 0===e.createIIRFilter)return t(e,n,i);const s=e.createIIRFilter(i.feedforward,i.feedback);return io(s,i),s})(Na),Va,Xo,Ko,Sa),Ha=((t,e,n,i,s)=>(r,o)=>{const a=o.listener,{forwardX:c,forwardY:l,forwardZ:h,positionX:u,positionY:d,positionZ:f,upX:p,upY:m,upZ:g}=void 0===a.forwardX?(()=>{const c=e(o,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"speakers",numberOfInputs:9}),l=s(o),h=i(o,256,9,0),u=(e,i)=>{const s=n(o,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"discrete",offset:i});return s.connect(c,0,e),s.start(),Object.defineProperty(s.offset,"defaultValue",{get:()=>i}),t({context:r},l,s.offset,or,rr)};let d=[0,0,-1,0,1,0],f=[0,0,0];return h.onaudioprocess=({inputBuffer:t})=>{const e=[t.getChannelData(0)[0],t.getChannelData(1)[0],t.getChannelData(2)[0],t.getChannelData(3)[0],t.getChannelData(4)[0],t.getChannelData(5)[0]];e.some(((t,e)=>t!==d[e]))&&(a.setOrientation(...e),d=e);const n=[t.getChannelData(6)[0],t.getChannelData(7)[0],t.getChannelData(8)[0]];n.some(((t,e)=>t!==f[e]))&&(a.setPosition(...n),f=n)},c.connect(h),{forwardX:u(0,0),forwardY:u(1,0),forwardZ:u(2,-1),positionX:u(6,0),positionY:u(7,0),positionZ:u(8,0),upX:u(3,0),upY:u(4,1),upZ:u(5,0)}})():a;return{get forwardX(){return c},get forwardY(){return l},get forwardZ(){return h},get positionX(){return u},get positionY(){return d},get positionZ(){return f},get upX(){return p},get upY(){return m},get upZ(){return g}}})(ya,Aa,Pa,_o,Ko),Ga=new WeakMap,za=((t,e,n,i,s,r)=>class extends n{constructor(n,r){super(n),this._nativeContext=n,js.set(this,n),i(n)&&s.set(n,new Set),this._destination=new t(this,r),this._listener=e(this,n),this._onstatechange=null}get currentTime(){return this._nativeContext.currentTime}get destination(){return this._destination}get listener(){return this._listener}get onstatechange(){return this._onstatechange}set onstatechange(t){const e="function"==typeof t?r(this,t):null;this._nativeContext.onstatechange=e;const n=this._nativeContext.onstatechange;this._onstatechange=null!==n&&n===e?t:n}get sampleRate(){return this._nativeContext.sampleRate}get state(){return this._nativeContext.state}})(Ca,Ha,Qo,Ko,Ga,Do),Ya=((t,e,n,i,s,r)=>(o,a)=>{const c=o.createOscillator();return io(c,a),ro(c,a,"detune"),ro(c,a,"frequency"),void 0!==a.periodicWave?c.setPeriodicWave(a.periodicWave):no(c,a,"type"),e(n,(()=>n(o)))||oo(c),e(i,(()=>i(o)))||r(c,o),e(s,(()=>s(o)))||ao(c),t(o,c),c})(fa,No,Eo,ko,Po,Io),Xa=((t,e,n,i,s)=>()=>{const r=new WeakMap;let o=null,a=null,c=null;return{set periodicWave(t){o=t},set start(t){a=t},set stop(t){c=t},render(l,h,u){const d=r.get(h);return void 0!==d?Promise.resolve(d):(async(l,h,u)=>{let d=n(l);const f=tr(d,h);if(!f){const t={channelCount:d.channelCount,channelCountMode:d.channelCountMode,channelInterpretation:d.channelInterpretation,detune:d.detune.value,frequency:d.frequency.value,periodicWave:null===o?void 0:o,type:d.type};d=e(h,t),null!==a&&d.start(a),null!==c&&d.stop(c)}return r.set(h,d),f?(await t(h,l.detune,d.detune,u),await t(h,l.frequency,d.frequency,u)):(await i(h,l.detune,d.detune,u),await i(h,l.frequency,d.frequency,u)),await s(l,h,d,u),d})(l,h,u)}}})(ma,Ya,Sr,va,zo),Ua=((t,e,n,i,s,r,o)=>class extends t{constructor(t,o){const a=s(t),c={...xo,...o},l=n(a,c),h=r(a),u=h?i():null,d=t.sampleRate/2;super(t,!1,l,u),this._detune=e(this,h,l.detune,153600,-153600),this._frequency=e(this,h,l.frequency,d,-d),this._nativeOscillatorNode=l,this._onended=null,this._oscillatorNodeRenderer=u,null!==this._oscillatorNodeRenderer&&void 0!==c.periodicWave&&(this._oscillatorNodeRenderer.periodicWave=c.periodicWave)}get detune(){return this._detune}get frequency(){return this._frequency}get onended(){return this._onended}set onended(t){const e="function"==typeof t?o(this,t):null;this._nativeOscillatorNode.onended=e;const n=this._nativeOscillatorNode.onended;this._onended=null!==n&&n===e?t:n}get type(){return this._nativeOscillatorNode.type}set type(t){this._nativeOscillatorNode.type=t,null!==this._oscillatorNodeRenderer&&(this._oscillatorNodeRenderer.periodicWave=null)}setPeriodicWave(t){this._nativeOscillatorNode.setPeriodicWave(t),null!==this._oscillatorNodeRenderer&&(this._oscillatorNodeRenderer.periodicWave=t)}start(t=0){if(this._nativeOscillatorNode.start(t),null!==this._oscillatorNodeRenderer&&(this._oscillatorNodeRenderer.start=t),"closed"!==this.context.state){qs(this);const t=()=>{this._nativeOscillatorNode.removeEventListener("ended",t),ar(this)&&Zs(this)};this._nativeOscillatorNode.addEventListener("ended",t)}}stop(t=0){this._nativeOscillatorNode.stop(t),null!==this._oscillatorNodeRenderer&&(this._oscillatorNodeRenderer.stop=t)}})(ia,ya,Ya,Xa,Xo,Ko,Do),qa=(t=>(e,n)=>{const i=t(e,{buffer:null,channelCount:2,channelCountMode:"max",channelInterpretation:"speakers",loop:!1,loopEnd:0,loopStart:0,playbackRate:1}),s=e.createBuffer(1,2,44100);return i.buffer=s,i.loop=!0,i.connect(n),i.start(),()=>{i.stop(),i.disconnect(n)}})(ga),Ka=((t,e,n,i,s)=>(r,{curve:o,oversample:a,...c})=>{const l=r.createWaveShaper(),h=r.createWaveShaper();io(l,c),io(h,c);const u=n(r,{...c,gain:1}),d=n(r,{...c,gain:-1}),f=n(r,{...c,gain:1}),p=n(r,{...c,gain:-1});let m=null,g=!1,v=null;const _={get bufferSize(){},get channelCount(){return l.channelCount},set channelCount(t){u.channelCount=t,d.channelCount=t,l.channelCount=t,f.channelCount=t,h.channelCount=t,p.channelCount=t},get channelCountMode(){return l.channelCountMode},set channelCountMode(t){u.channelCountMode=t,d.channelCountMode=t,l.channelCountMode=t,f.channelCountMode=t,h.channelCountMode=t,p.channelCountMode=t},get channelInterpretation(){return l.channelInterpretation},set channelInterpretation(t){u.channelInterpretation=t,d.channelInterpretation=t,l.channelInterpretation=t,f.channelInterpretation=t,h.channelInterpretation=t,p.channelInterpretation=t},get context(){return l.context},get curve(){return v},set curve(n){if(null!==n&&n.length<2)throw e();if(null===n)l.curve=n,h.curve=n;else{const t=n.length,e=new Float32Array(t+2-t%2),i=new Float32Array(t+2-t%2);e[0]=n[0],i[0]=-n[t-1];const s=Math.ceil((t+1)/2),r=(t+1)/2-1;for(let o=1;o<s;o+=1){const a=o/s*r,c=Math.floor(a),l=Math.ceil(a);e[o]=c===l?n[c]:(1-(a-c))*n[c]+(1-(l-a))*n[l],i[o]=c===l?-n[t-1-c]:-(1-(a-c))*n[t-1-c]-(1-(l-a))*n[t-1-l]}e[s]=t%2==1?n[s-1]:(n[s-2]+n[s-1])/2,l.curve=e,h.curve=i}v=n,g&&(i(v)&&null===m?m=t(r,u):null!==m&&(m(),m=null))},get inputs(){return[u]},get numberOfInputs(){return l.numberOfInputs},get numberOfOutputs(){return l.numberOfOutputs},get oversample(){return l.oversample},set oversample(t){l.oversample=t,h.oversample=t},addEventListener:(...t)=>u.addEventListener(t[0],t[1],t[2]),dispatchEvent:(...t)=>u.dispatchEvent(t[0]),removeEventListener:(...t)=>u.removeEventListener(t[0],t[1],t[2])};null!==o&&(_.curve=o instanceof Float32Array?o:new Float32Array(o)),a!==_.oversample&&(_.oversample=a);return s(fo(_,f),(()=>{u.connect(l).connect(f),u.connect(d).connect(h).connect(p).connect(f),g=!0,i(v)&&(m=t(r,u))}),(()=>{u.disconnect(l),l.disconnect(f),u.disconnect(d),d.disconnect(h),h.disconnect(p),p.disconnect(f),g=!1,null!==m&&(m(),m=null)}))})(qa,Kr,mo,Mo,Ma),Za=((t,e,n,i,s,r,o)=>(a,c)=>{const l=a.createWaveShaper();if(null!==r&&"webkitAudioContext"===r.name&&void 0===a.createGain().gain.automationRate)return n(a,c);io(l,c);const h=null===c.curve||c.curve instanceof Float32Array?c.curve:new Float32Array(c.curve);if(null!==h&&h.length<2)throw e();no(l,{curve:h},"curve"),no(l,c,"oversample");let u=null,d=!1;o(l,"curve",(t=>()=>t.call(l)),(e=>n=>(e.call(l,n),d&&(i(n)&&null===u?u=t(a,l):i(n)||null===u||(u(),u=null)),n)));return s(l,(()=>{d=!0,i(l.curve)&&(u=t(a,l))}),(()=>{d=!1,null!==u&&(u(),u=null)}))})(qa,Kr,Ka,Mo,Ma,Jo,Ao),Qa=(t=>(e,n)=>{const i=e.createPanner();return void 0===i.orientationX?t(e,n):(io(i,n),ro(i,n,"orientationX"),ro(i,n,"orientationY"),ro(i,n,"orientationZ"),ro(i,n,"positionX"),ro(i,n,"positionY"),ro(i,n,"positionZ"),no(i,n,"coneInnerAngle"),no(i,n,"coneOuterAngle"),no(i,n,"coneOuterGain"),no(i,n,"distanceModel"),no(i,n,"maxDistance"),no(i,n,"panningModel"),no(i,n,"refDistance"),no(i,n,"rolloffFactor"),i)})(((t,e,n,i,s,r,o,a,c)=>(l,{coneInnerAngle:h,coneOuterAngle:u,coneOuterGain:d,distanceModel:f,maxDistance:p,orientationX:m,orientationY:g,orientationZ:v,panningModel:_,positionX:y,positionY:b,positionZ:x,refDistance:C,rolloffFactor:w,...S})=>{const T=l.createPanner();if(S.channelCount>2)throw o();if("max"===S.channelCountMode)throw o();io(T,S);const M={channelCount:1,channelCountMode:"explicit",channelInterpretation:"discrete"},A=n(l,{...M,channelInterpretation:"speakers",numberOfInputs:6}),O=i(l,{...S,gain:1}),E=i(l,{...M,gain:1}),k=i(l,{...M,gain:0}),P=i(l,{...M,gain:0}),I=i(l,{...M,gain:0}),D=i(l,{...M,gain:0}),R=i(l,{...M,gain:0}),j=s(l,256,6,1),$=r(l,{...M,curve:new Float32Array([1,1]),oversample:"none"});let L=[m,g,v],F=[y,b,x];j.onaudioprocess=({inputBuffer:t})=>{const e=[t.getChannelData(0)[0],t.getChannelData(1)[0],t.getChannelData(2)[0]];e.some(((t,e)=>t!==L[e]))&&(T.setOrientation(...e),L=e);const n=[t.getChannelData(3)[0],t.getChannelData(4)[0],t.getChannelData(5)[0]];n.some(((t,e)=>t!==F[e]))&&(T.setPosition(...n),F=n)},Object.defineProperty(k.gain,"defaultValue",{get:()=>0}),Object.defineProperty(P.gain,"defaultValue",{get:()=>0}),Object.defineProperty(I.gain,"defaultValue",{get:()=>0}),Object.defineProperty(D.gain,"defaultValue",{get:()=>0}),Object.defineProperty(R.gain,"defaultValue",{get:()=>0});const N={get bufferSize(){},get channelCount(){return T.channelCount},set channelCount(t){if(t>2)throw o();O.channelCount=t,T.channelCount=t},get channelCountMode(){return T.channelCountMode},set channelCountMode(t){if("max"===t)throw o();O.channelCountMode=t,T.channelCountMode=t},get channelInterpretation(){return T.channelInterpretation},set channelInterpretation(t){O.channelInterpretation=t,T.channelInterpretation=t},get coneInnerAngle(){return T.coneInnerAngle},set coneInnerAngle(t){T.coneInnerAngle=t},get coneOuterAngle(){return T.coneOuterAngle},set coneOuterAngle(t){T.coneOuterAngle=t},get coneOuterGain(){return T.coneOuterGain},set coneOuterGain(t){if(t<0||t>1)throw e();T.coneOuterGain=t},get context(){return T.context},get distanceModel(){return T.distanceModel},set distanceModel(t){T.distanceModel=t},get inputs(){return[O]},get maxDistance(){return T.maxDistance},set maxDistance(t){if(t<0)throw new RangeError;T.maxDistance=t},get numberOfInputs(){return T.numberOfInputs},get numberOfOutputs(){return T.numberOfOutputs},get orientationX(){return E.gain},get orientationY(){return k.gain},get orientationZ(){return P.gain},get panningModel(){return T.panningModel},set panningModel(t){T.panningModel=t},get positionX(){return I.gain},get positionY(){return D.gain},get positionZ(){return R.gain},get refDistance(){return T.refDistance},set refDistance(t){if(t<0)throw new RangeError;T.refDistance=t},get rolloffFactor(){return T.rolloffFactor},set rolloffFactor(t){if(t<0)throw new RangeError;T.rolloffFactor=t},addEventListener:(...t)=>O.addEventListener(t[0],t[1],t[2]),dispatchEvent:(...t)=>O.dispatchEvent(t[0]),removeEventListener:(...t)=>O.removeEventListener(t[0],t[1],t[2])};h!==N.coneInnerAngle&&(N.coneInnerAngle=h),u!==N.coneOuterAngle&&(N.coneOuterAngle=u),d!==N.coneOuterGain&&(N.coneOuterGain=d),f!==N.distanceModel&&(N.distanceModel=f),p!==N.maxDistance&&(N.maxDistance=p),m!==N.orientationX.value&&(N.orientationX.value=m),g!==N.orientationY.value&&(N.orientationY.value=g),v!==N.orientationZ.value&&(N.orientationZ.value=v),_!==N.panningModel&&(N.panningModel=_),y!==N.positionX.value&&(N.positionX.value=y),b!==N.positionY.value&&(N.positionY.value=b),x!==N.positionZ.value&&(N.positionZ.value=x),C!==N.refDistance&&(N.refDistance=C),w!==N.rolloffFactor&&(N.rolloffFactor=w),1===L[0]&&0===L[1]&&0===L[2]||T.setOrientation(...L),0===F[0]&&0===F[1]&&0===F[2]||T.setPosition(...F);return c(fo(N,T),(()=>{O.connect(T),t(O,$,0,0),$.connect(E).connect(A,0,0),$.connect(k).connect(A,0,1),$.connect(P).connect(A,0,2),$.connect(I).connect(A,0,3),$.connect(D).connect(A,0,4),$.connect(R).connect(A,0,5),A.connect(j).connect(l.destination)}),(()=>{O.disconnect(T),a(O,$,0,0),$.disconnect(E),E.disconnect(A),$.disconnect(k),k.disconnect(A),$.disconnect(P),P.disconnect(A),$.disconnect(I),I.disconnect(A),$.disconnect(D),D.disconnect(A),$.disconnect(R),R.disconnect(A),A.disconnect(j),j.disconnect(l.destination)}))})(yr,Kr,Aa,mo,_o,Za,yo,wr,Ma)),Ja=((t,e,n,i,s,r,o,a,c,l)=>()=>{const h=new WeakMap;let u=null;return{render(d,f,p){const m=h.get(f);return void 0!==m?Promise.resolve(m):(async(d,f,p)=>{let m=null,g=r(d);const v={channelCount:g.channelCount,channelCountMode:g.channelCountMode,channelInterpretation:g.channelInterpretation},_={...v,coneInnerAngle:g.coneInnerAngle,coneOuterAngle:g.coneOuterAngle,coneOuterGain:g.coneOuterGain,distanceModel:g.distanceModel,maxDistance:g.maxDistance,panningModel:g.panningModel,refDistance:g.refDistance,rolloffFactor:g.rolloffFactor},y=tr(g,f);if("bufferSize"in g)m=i(f,{...v,gain:1});else if(!y){const t={..._,orientationX:g.orientationX.value,orientationY:g.orientationY.value,orientationZ:g.orientationZ.value,positionX:g.positionX.value,positionY:g.positionY.value,positionZ:g.positionZ.value};g=s(f,t)}if(h.set(f,null===m?g:m),null!==m){if(null===u){if(null===o)throw new Error("Missing the native OfflineAudioContext constructor.");const t=new o(6,d.context.length,f.sampleRate),i=e(t,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"speakers",numberOfInputs:6});i.connect(t.destination),u=(async()=>{const e=await Promise.all([d.orientationX,d.orientationY,d.orientationZ,d.positionX,d.positionY,d.positionZ].map((async(e,i)=>{const s=n(t,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"discrete",offset:0===i?1:0});return await a(t,e,s.offset,p),s})));for(let t=0;t<6;t+=1)e[t].connect(i,0,t),e[t].start(0);return l(t)})()}const t=await u,r=i(f,{...v,gain:1});await c(d,f,r,p);const h=[];for(let e=0;e<t.numberOfChannels;e+=1)h.push(t.getChannelData(e));let g=[h[0][0],h[1][0],h[2][0]],y=[h[3][0],h[4][0],h[5][0]],b=i(f,{...v,gain:1}),x=s(f,{..._,orientationX:g[0],orientationY:g[1],orientationZ:g[2],positionX:y[0],positionY:y[1],positionZ:y[2]});r.connect(b).connect(x.inputs[0]),x.connect(m);for(let e=128;e<t.length;e+=128){const t=[h[0][e],h[1][e],h[2][e]],n=[h[3][e],h[4][e],h[5][e]];if(t.some(((t,e)=>t!==g[e]))||n.some(((t,e)=>t!==y[e]))){g=t,y=n;const o=e/f.sampleRate;b.gain.setValueAtTime(0,o),b=i(f,{...v,gain:0}),x=s(f,{..._,orientationX:g[0],orientationY:g[1],orientationZ:g[2],positionX:y[0],positionY:y[1],positionZ:y[2]}),b.gain.setValueAtTime(1,o),r.connect(b).connect(x.inputs[0]),x.connect(m)}}return m}return y?(await t(f,d.orientationX,g.orientationX,p),await t(f,d.orientationY,g.orientationY,p),await t(f,d.orientationZ,g.orientationZ,p),await t(f,d.positionX,g.positionX,p),await t(f,d.positionY,g.positionY,p),await t(f,d.positionZ,g.positionZ,p)):(await a(f,d.orientationX,g.orientationX,p),await a(f,d.orientationY,g.orientationY,p),await a(f,d.orientationZ,g.orientationZ,p),await a(f,d.positionX,g.positionX,p),await a(f,d.positionY,g.positionY,p),await a(f,d.positionZ,g.positionZ,p)),_r(g)?await c(d,f,g.inputs[0],p):await c(d,f,g,p),g})(d,f,p)}}})(ma,Aa,Pa,mo,Qa,Sr,qo,va,zo,Ba),tc=((t,e,n,i,s,r,o)=>class extends t{constructor(t,a){const c=s(t),l={...Co,...a},h=n(c,l),u=r(c);super(t,!1,h,u?i():null),this._nativePannerNode=h,this._orientationX=e(this,u,h.orientationX,or,rr),this._orientationY=e(this,u,h.orientationY,or,rr),this._orientationZ=e(this,u,h.orientationZ,or,rr),this._positionX=e(this,u,h.positionX,or,rr),this._positionY=e(this,u,h.positionY,or,rr),this._positionZ=e(this,u,h.positionZ,or,rr),o(this,1)}get coneInnerAngle(){return this._nativePannerNode.coneInnerAngle}set coneInnerAngle(t){this._nativePannerNode.coneInnerAngle=t}get coneOuterAngle(){return this._nativePannerNode.coneOuterAngle}set coneOuterAngle(t){this._nativePannerNode.coneOuterAngle=t}get coneOuterGain(){return this._nativePannerNode.coneOuterGain}set coneOuterGain(t){this._nativePannerNode.coneOuterGain=t}get distanceModel(){return this._nativePannerNode.distanceModel}set distanceModel(t){this._nativePannerNode.distanceModel=t}get maxDistance(){return this._nativePannerNode.maxDistance}set maxDistance(t){this._nativePannerNode.maxDistance=t}get orientationX(){return this._orientationX}get orientationY(){return this._orientationY}get orientationZ(){return this._orientationZ}get panningModel(){return this._nativePannerNode.panningModel}set panningModel(t){this._nativePannerNode.panningModel=t}get positionX(){return this._positionX}get positionY(){return this._positionY}get positionZ(){return this._positionZ}get refDistance(){return this._nativePannerNode.refDistance}set refDistance(t){this._nativePannerNode.refDistance=t}get rolloffFactor(){return this._nativePannerNode.rolloffFactor}set rolloffFactor(t){this._nativePannerNode.rolloffFactor=t}})(ia,ya,Qa,Ja,Xo,Ko,Sa),ec=((t,e,n,i)=>class s{constructor(s,r){const o=e(s),a=i({...wo,...r}),c=t(o,a);return n.add(c),c}static[Symbol.hasInstance](t){return null!==t&&"object"==typeof t&&Object.getPrototypeOf(t)===s.prototype||n.has(t)}})((t=>(e,{disableNormalization:n,imag:i,real:s})=>{const r=i instanceof Float32Array?i:new Float32Array(i),o=s instanceof Float32Array?s:new Float32Array(s),a=e.createPeriodicWave(o,r,{disableNormalization:n});if(Array.from(i).length<2)throw t();return a})(nr),Xo,new WeakSet,(t=>{const{imag:e,real:n}=t;return void 0===e?void 0===n?{...t,imag:[0,0],real:[0,0]}:{...t,imag:Array.from(n,(()=>0)),real:n}:void 0===n?{...t,imag:e,real:Array.from(e,(()=>0))}:{...t,imag:e,real:n}})),nc=((t,e)=>(n,i)=>{const s=i.channelCountMode;if("clamped-max"===s)throw e();if(void 0===n.createStereoPanner)return t(n,i);const r=n.createStereoPanner();return io(r,i),ro(r,i,"pan"),Object.defineProperty(r,"channelCountMode",{get:()=>s,set:t=>{if(t!==s)throw e()}}),r})(((t,e,n,i,s,r)=>{const o=16385,a=new Float32Array([1,1]),c=Math.PI/2,l={channelCount:1,channelCountMode:"explicit",channelInterpretation:"discrete"},h={...l,oversample:"none"},u=(t,r,u,d,f)=>{if(1===r)return((t,e,s,r)=>{const u=new Float32Array(o),d=new Float32Array(o);for(let t=0;t<o;t+=1){const e=t/16384*c;u[t]=Math.cos(e),d[t]=Math.sin(e)}const f=n(t,{...l,gain:0}),p=i(t,{...h,curve:u}),m=i(t,{...h,curve:a}),g=n(t,{...l,gain:0}),v=i(t,{...h,curve:d});return{connectGraph(){e.connect(f),e.connect(void 0===m.inputs?m:m.inputs[0]),e.connect(g),m.connect(s),s.connect(void 0===p.inputs?p:p.inputs[0]),s.connect(void 0===v.inputs?v:v.inputs[0]),p.connect(f.gain),v.connect(g.gain),f.connect(r,0,0),g.connect(r,0,1)},disconnectGraph(){e.disconnect(f),e.disconnect(void 0===m.inputs?m:m.inputs[0]),e.disconnect(g),m.disconnect(s),s.disconnect(void 0===p.inputs?p:p.inputs[0]),s.disconnect(void 0===v.inputs?v:v.inputs[0]),p.disconnect(f.gain),v.disconnect(g.gain),f.disconnect(r,0,0),g.disconnect(r,0,1)}}})(t,u,d,f);if(2===r)return((t,s,r,u)=>{const d=new Float32Array(o),f=new Float32Array(o),p=new Float32Array(o),m=new Float32Array(o),g=Math.floor(8192.5);for(let t=0;t<o;t+=1)if(t>g){const e=(t-g)/(16384-g)*c;d[t]=Math.cos(e),f[t]=Math.sin(e),p[t]=0,m[t]=1}else{const e=t/(16384-g)*c;d[t]=1,f[t]=0,p[t]=Math.cos(e),m[t]=Math.sin(e)}const v=e(t,{channelCount:2,channelCountMode:"explicit",channelInterpretation:"discrete",numberOfOutputs:2}),_=n(t,{...l,gain:0}),y=i(t,{...h,curve:d}),b=n(t,{...l,gain:0}),x=i(t,{...h,curve:f}),C=i(t,{...h,curve:a}),w=n(t,{...l,gain:0}),S=i(t,{...h,curve:p}),T=n(t,{...l,gain:0}),M=i(t,{...h,curve:m});return{connectGraph(){s.connect(v),s.connect(void 0===C.inputs?C:C.inputs[0]),v.connect(_,0),v.connect(b,0),v.connect(w,1),v.connect(T,1),C.connect(r),r.connect(void 0===y.inputs?y:y.inputs[0]),r.connect(void 0===x.inputs?x:x.inputs[0]),r.connect(void 0===S.inputs?S:S.inputs[0]),r.connect(void 0===M.inputs?M:M.inputs[0]),y.connect(_.gain),x.connect(b.gain),S.connect(w.gain),M.connect(T.gain),_.connect(u,0,0),w.connect(u,0,0),b.connect(u,0,1),T.connect(u,0,1)},disconnectGraph(){s.disconnect(v),s.disconnect(void 0===C.inputs?C:C.inputs[0]),v.disconnect(_,0),v.disconnect(b,0),v.disconnect(w,1),v.disconnect(T,1),C.disconnect(r),r.disconnect(void 0===y.inputs?y:y.inputs[0]),r.disconnect(void 0===x.inputs?x:x.inputs[0]),r.disconnect(void 0===S.inputs?S:S.inputs[0]),r.disconnect(void 0===M.inputs?M:M.inputs[0]),y.disconnect(_.gain),x.disconnect(b.gain),S.disconnect(w.gain),M.disconnect(T.gain),_.disconnect(u,0,0),w.disconnect(u,0,0),b.disconnect(u,0,1),T.disconnect(u,0,1)}}})(t,u,d,f);throw s()};return(e,{channelCount:i,channelCountMode:o,pan:a,...c})=>{if("max"===o)throw s();const l=t(e,{...c,channelCount:1,channelCountMode:o,numberOfInputs:2}),h=n(e,{...c,channelCount:i,channelCountMode:o,gain:1}),d=n(e,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"discrete",gain:a});let{connectGraph:f,disconnectGraph:p}=u(e,i,h,d,l);Object.defineProperty(d.gain,"defaultValue",{get:()=>0}),Object.defineProperty(d.gain,"maxValue",{get:()=>1}),Object.defineProperty(d.gain,"minValue",{get:()=>-1});const m={get bufferSize(){},get channelCount(){return h.channelCount},set channelCount(t){h.channelCount!==t&&(g&&p(),({connectGraph:f,disconnectGraph:p}=u(e,t,h,d,l)),g&&f()),h.channelCount=t},get channelCountMode(){return h.channelCountMode},set channelCountMode(t){if("clamped-max"===t||"max"===t)throw s();h.channelCountMode=t},get channelInterpretation(){return h.channelInterpretation},set channelInterpretation(t){h.channelInterpretation=t},get context(){return h.context},get inputs(){return[h]},get numberOfInputs(){return h.numberOfInputs},get numberOfOutputs(){return h.numberOfOutputs},get pan(){return d.gain},addEventListener:(...t)=>h.addEventListener(t[0],t[1],t[2]),dispatchEvent:(...t)=>h.dispatchEvent(t[0]),removeEventListener:(...t)=>h.removeEventListener(t[0],t[1],t[2])};let g=!1;return r(fo(m,l),(()=>{f(),g=!0}),(()=>{p(),g=!1}))}})(Aa,uo,mo,Za,yo,Ma),yo),ic=((t,e,n,i,s)=>()=>{const r=new WeakMap;return{render(o,a,c){const l=r.get(a);return void 0!==l?Promise.resolve(l):(async(o,a,c)=>{let l=n(o);const h=tr(l,a);if(!h){const t={channelCount:l.channelCount,channelCountMode:l.channelCountMode,channelInterpretation:l.channelInterpretation,pan:l.pan.value};l=e(a,t)}return r.set(a,l),h?await t(a,o.pan,l.pan,c):await i(a,o.pan,l.pan,c),_r(l)?await s(o,a,l.inputs[0],c):await s(o,a,l,c),l})(o,a,c)}}})(ma,nc,Sr,va,zo),sc=((t,e,n,i,s,r)=>class extends t{constructor(t,o){const a=s(t),c={...So,...o},l=n(a,c),h=r(a);super(t,!1,l,h?i():null),this._pan=e(this,h,l.pan)}get pan(){return this._pan}})(ia,ya,nc,ic,Xo,Ko),rc=((t,e,n)=>()=>{const i=new WeakMap;return{render(s,r,o){const a=i.get(r);return void 0!==a?Promise.resolve(a):(async(s,r,o)=>{let a=e(s);if(!tr(a,r)){const e={channelCount:a.channelCount,channelCountMode:a.channelCountMode,channelInterpretation:a.channelInterpretation,curve:a.curve,oversample:a.oversample};a=t(r,e)}return i.set(r,a),_r(a)?await n(s,r,a.inputs[0],o):await n(s,r,a,o),a})(s,r,o)}}})(Za,Sr,zo),oc=((t,e,n,i,s,r,o)=>class extends t{constructor(t,e){const a=s(t),c={...To,...e},l=n(a,c);super(t,!0,l,r(a)?i():null),this._isCurveNullified=!1,this._nativeWaveShaperNode=l,o(this,1)}get curve(){return this._isCurveNullified?null:this._nativeWaveShaperNode.curve}set curve(t){if(null===t)this._isCurveNullified=!0,this._nativeWaveShaperNode.curve=new Float32Array([0,0]);else{if(t.length<2)throw e();this._isCurveNullified=!1,this._nativeWaveShaperNode.curve=t}}get oversample(){return this._nativeWaveShaperNode.oversample}set oversample(t){this._nativeWaveShaperNode.oversample=t}})(ia,Kr,Za,rc,Xo,Ko,Sa),ac=(t=>null!==t&&t.isSecureContext)(Wo),cc=(t=>(e,n,i)=>{Object.defineProperties(t,{currentFrame:{configurable:!0,get:()=>Math.round(e*n)},currentTime:{configurable:!0,get:()=>e}});try{return i()}finally{null!==t&&(delete t.currentFrame,delete t.currentTime)}})(Wo),lc=new WeakMap,hc=((t,e)=>n=>{let i=t.get(n);if(void 0!==i)return i;if(null===e)throw new Error("Missing the native OfflineAudioContext constructor.");return i=new e(1,1,44100),t.set(n,i),i})(lc,qo),uc=(t=>null===t?null:t.hasOwnProperty("AudioWorkletNode")?t.AudioWorkletNode:null)(Wo),dc=ac?((t,e,n,i,s,r,o,a,c,l,h,u)=>(d,f,p={credentials:"omit"})=>{const m=r(d);if(void 0!==m.audioWorklet)return Promise.all([s(f),Promise.resolve(t(h,h))]).then((([[t,e],n])=>{const[i,s]=Ws(t,e),r=new Blob([`${i};((AudioWorkletProcessor,registerProcessor)=>{${s}\n})(${n?"AudioWorkletProcessor":"class extends AudioWorkletProcessor {__b=new WeakSet();constructor(){super();(p=>p.postMessage=(q=>(m,t)=>q.call(p,m,t?t.filter(u=>!this.__b.has(u)):t))(p.postMessage))(this.port)}}"},(n,p)=>registerProcessor(n,class extends p{${n?"":"__c = (a) => a.forEach(e=>this.__b.add(e.buffer));"}process(i,o,p){${n?"":"i.forEach(this.__c);o.forEach(this.__c);this.__c(Object.values(p));"}return super.process(i.map(j=>j.some(k=>k.length===0)?[]:j),o,p)}}));registerProcessor('__sac',class extends AudioWorkletProcessor{process(){return !1}})`],{type:"application/javascript; charset=utf-8"}),c=URL.createObjectURL(r);return m.audioWorklet.addModule(c,p).then((()=>{if(a(m))return m;const t=o(m);return t.audioWorklet.addModule(c,p).then((()=>t))})).then((t=>{try{new AudioWorkletNode(t,"__sac")}catch{throw new SyntaxError}})).finally((()=>URL.revokeObjectURL(c)))}));const g=l.get(d);if(void 0!==g&&g.has(f))return Promise.resolve();const v=c.get(d);if(void 0!==v){const t=v.get(f);if(void 0!==t)return t}const _=s(f).then((([t,e])=>{const[i,s]=Ws(t,e);return n(`${i};((a,b)=>{(a[b]=a[b]||[]).push((AudioWorkletProcessor,global,registerProcessor,sampleRate,self,window)=>{${s}\n})})(window,'_AWGS')`)})).then((()=>{const t=u._AWGS.pop();if(void 0===t)throw new SyntaxError;i(m.currentTime,m.sampleRate,(()=>t(class{},void 0,((t,n)=>{if(""===t.trim())throw e();const i=Fs.get(m);if(void 0!==i){if(i.has(t))throw e();Gs(n),Hs(n.parameterDescriptors),i.set(t,n)}else Gs(n),Hs(n.parameterDescriptors),Fs.set(m,new Map([[t,n]]))}),m.sampleRate,void 0,void 0)))}));return void 0===v?c.set(d,new Map([[f,_]])):v.set(f,_),_.then((()=>{const t=l.get(d);void 0===t?l.set(d,new Set([f])):t.add(f)})).finally((()=>{const t=c.get(d);void 0!==t&&t.delete(f)})),_})(No,yo,(t=>e=>new Promise(((n,i)=>{if(null===t)return void i(new SyntaxError);const s=t.document.head;if(null===s)i(new SyntaxError);else{const r=t.document.createElement("script"),o=new Blob([e],{type:"application/javascript"}),a=URL.createObjectURL(o),c=t.onerror,l=()=>{t.onerror=c,URL.revokeObjectURL(a)};t.onerror=(e,n,s,r,o)=>n===a||n===t.location.href&&1===s&&1===r?(l(),i(o),!1):null!==c?c(e,n,s,r,o):void 0,r.onerror=()=>{l(),i(new SyntaxError)},r.onload=()=>{l(),n()},r.src=a,r.type="module",s.appendChild(r)}})))(Wo),cc,(t=>async e=>{try{const t=await fetch(e);if(t.ok)return[await t.text(),t.url]}catch{}throw t()})((()=>new DOMException("","AbortError"))),Xo,hc,Ko,new WeakMap,new WeakMap,((t,e)=>async()=>{if(null===t)return!0;if(null===e)return!1;const n=new Blob(['class A extends AudioWorkletProcessor{process(i){this.port.postMessage(i,[i[0][0].buffer])}}registerProcessor("a",A)'],{type:"application/javascript; charset=utf-8"}),i=new e(1,128,44100),s=URL.createObjectURL(n);let r=!1,o=!1;try{await i.audioWorklet.addModule(s);const e=new t(i,"a",{numberOfOutputs:0}),n=i.createOscillator();e.port.onmessage=()=>r=!0,e.onprocessorerror=()=>o=!0,n.connect(e),n.start(0),await i.startRendering()}catch{}finally{URL.revokeObjectURL(s)}return r&&!o})(uc,qo),Wo):void 0,fc=((t,e)=>n=>t(n)||e(n))(ta,Ko),pc=((t,e,n,i,s,r,o,a,c,l,h,u,d,f,p,m,g,v,_,y)=>class extends p{constructor(e,n){super(e,n),this._nativeContext=e,this._audioWorklet=void 0===t?void 0:{addModule:(e,n)=>t(this,e,n)}}get audioWorklet(){return this._audioWorklet}createAnalyser(){return new e(this)}createBiquadFilter(){return new s(this)}createBuffer(t,e,i){return new n({length:e,numberOfChannels:t,sampleRate:i})}createBufferSource(){return new i(this)}createChannelMerger(t=6){return new r(this,{numberOfInputs:t})}createChannelSplitter(t=6){return new o(this,{numberOfOutputs:t})}createConstantSource(){return new a(this)}createConvolver(){return new c(this)}createDelay(t=1){return new h(this,{maxDelayTime:t})}createDynamicsCompressor(){return new u(this)}createGain(){return new d(this)}createIIRFilter(t,e){return new f(this,{feedback:e,feedforward:t})}createOscillator(){return new m(this)}createPanner(){return new g(this)}createPeriodicWave(t,e,n={disableNormalization:!1}){return new v(this,{...n,imag:e,real:t})}createStereoPanner(){return new _(this)}createWaveShaper(){return new y(this)}decodeAudioData(t,e,n){return l(this._nativeContext,t).then((t=>("function"==typeof e&&e(t),t)),(t=>{throw"function"==typeof n&&n(t),t}))}})(dc,ra,da,xa,Ta,Oa,Ea,Ia,Ra,((t,e,n,i,s,r,o,a,c,l,h)=>(u,d)=>{const f=o(u)?u:r(u);if(s.has(d)){const t=n();return Promise.reject(t)}try{s.add(d)}catch{}return e(c,(()=>c(f)))?f.decodeAudioData(d).then((n=>(zr(d).catch((()=>{})),e(a,(()=>a(n)))||h(n),t.add(n),n))):new Promise(((e,n)=>{const s=async()=>{try{await zr(d)}catch{}},r=t=>{n(t),s()};try{f.decodeAudioData(d,(n=>{"function"!=typeof n.copyFromChannel&&(l(n),ir(n)),t.add(n),s().then((()=>e(n)))}),(t=>{r(null===t?i():t)}))}catch(t){r(t)}}))})(oa,No,(()=>new DOMException("","DataCloneError")),(()=>new DOMException("","EncodingError")),new WeakSet,Xo,fc,er,eo,ha,ua),ja,La,Fa,Wa,za,Ua,tc,ec,sc,oc),mc=((t,e,n,i)=>class extends t{constructor(t,s){const r=n(t),o=e(r,s);if(i(r))throw TypeError();super(t,!0,o,null),this._nativeMediaElementAudioSourceNode=o}get mediaElement(){return this._nativeMediaElementAudioSourceNode.mediaElement}})(ia,((t,e)=>t.createMediaElementSource(e.mediaElement)),Xo,Ko),gc=((t,e,n,i)=>class extends t{constructor(t,s){const r=n(t);if(i(r))throw new TypeError;const o={...to,...s},a=e(r,o);super(t,!1,a,null),this._nativeMediaStreamAudioDestinationNode=a}get stream(){return this._nativeMediaStreamAudioDestinationNode.stream}})(ia,((t,e)=>{const n=t.createMediaStreamDestination();return io(n,e),1===n.numberOfOutputs&&Object.defineProperty(n,"numberOfOutputs",{get:()=>0}),n}),Xo,Ko),vc=((t,e,n,i)=>class extends t{constructor(t,s){const r=n(t),o=e(r,s);if(i(r))throw new TypeError;super(t,!0,o,null),this._nativeMediaStreamAudioSourceNode=o}get mediaStream(){return this._nativeMediaStreamAudioSourceNode.mediaStream}})(ia,((t,{mediaStream:e})=>{const n=e.getAudioTracks();n.sort(((t,e)=>t.id<e.id?-1:t.id>e.id?1:0));const i=n.slice(0,1),s=t.createMediaStreamSource(new MediaStream(i));return Object.defineProperty(s,"mediaStream",{value:e}),s}),Xo,Ko),_c=((t,e,n)=>class extends t{constructor(t,i){const s=n(t);super(t,!0,e(s,i),null)}})(ia,((t,e)=>(n,{mediaStreamTrack:i})=>{if("function"==typeof n.createMediaStreamTrackSource)return n.createMediaStreamTrackSource(i);const s=new MediaStream([i]),r=n.createMediaStreamSource(s);if("audio"!==i.kind)throw t();if(e(n))throw new TypeError;return r})(Kr,Ko),Xo),yc=((t,e,n,i,s,r,o,a,c)=>class extends t{constructor(t={}){if(null===c)throw new Error("Missing the native AudioContext constructor.");let e;try{e=new c(t)}catch(t){if(12===t.code&&"sampleRate is not in range"===t.message)throw n();throw t}if(null===e)throw i();if(!(t=>void 0===t||"number"==typeof t||"string"==typeof t&&("balanced"===t||"interactive"===t||"playback"===t))(t.latencyHint))throw new TypeError(`The provided value '${t.latencyHint}' is not a valid enum value of type AudioContextLatencyCategory.`);if(void 0!==t.sampleRate&&e.sampleRate!==t.sampleRate)throw n();super(e,2);const{latencyHint:s}=t,{sampleRate:r}=e;if(this._baseLatency="number"==typeof e.baseLatency?e.baseLatency:"balanced"===s?512/r:"interactive"===s||void 0===s?256/r:"playback"===s?1024/r:128*Math.max(2,Math.min(128,Math.round(s*r/128)))/r,this._nativeAudioContext=e,"webkitAudioContext"===c.name?(this._nativeGainNode=e.createGain(),this._nativeOscillatorNode=e.createOscillator(),this._nativeGainNode.gain.value=1e-37,this._nativeOscillatorNode.connect(this._nativeGainNode).connect(e.destination),this._nativeOscillatorNode.start()):(this._nativeGainNode=null,this._nativeOscillatorNode=null),this._state=null,"running"===e.state){this._state="suspended";const t=()=>{"suspended"===this._state&&(this._state=null),e.removeEventListener("statechange",t)};e.addEventListener("statechange",t)}}get baseLatency(){return this._baseLatency}get state(){return null!==this._state?this._state:this._nativeAudioContext.state}close(){return"closed"===this.state?this._nativeAudioContext.close().then((()=>{throw e()})):("suspended"===this._state&&(this._state=null),this._nativeAudioContext.close().then((()=>{null!==this._nativeGainNode&&null!==this._nativeOscillatorNode&&(this._nativeOscillatorNode.stop(),this._nativeGainNode.disconnect(),this._nativeOscillatorNode.disconnect()),dr(this)})))}createMediaElementSource(t){return new s(this,{mediaElement:t})}createMediaStreamDestination(){return new r(this)}createMediaStreamSource(t){return new o(this,{mediaStream:t})}createMediaStreamTrackSource(t){return new a(this,{mediaStreamTrack:t})}resume(){return"suspended"===this._state?new Promise(((t,e)=>{const n=()=>{this._nativeAudioContext.removeEventListener("statechange",n),"running"===this._nativeAudioContext.state?t():this.resume().then(t,e)};this._nativeAudioContext.addEventListener("statechange",n)})):this._nativeAudioContext.resume().catch((t=>{if(void 0===t||15===t.code)throw e();throw t}))}suspend(){return this._nativeAudioContext.suspend().catch((t=>{if(void 0===t)throw e();throw t}))}})(pc,Kr,yo,(()=>new DOMException("","UnknownError")),mc,gc,vc,_c,Jo),bc=(t=>e=>{const n=t.get(e);if(void 0===n)throw new Error("The context has no set of AudioWorkletNodes.");return n})(Ga),xc=(t=>(e,n)=>{t(e).add(n)})(bc),Cc=(t=>(e,n,i=0,s=0)=>{const r=e[i];if(void 0===r)throw t();return kr(n)?r.connect(n,0,s):r.connect(n,0)})(nr),wc=(t=>(e,n)=>{t(e).delete(n)})(bc),Sc=(t=>(e,n,i,s=0)=>void 0===n?e.forEach((t=>t.disconnect())):"number"==typeof n?Xr(t,e,n).disconnect():kr(n)?void 0===i?e.forEach((t=>t.disconnect(n))):void 0===s?Xr(t,e,i).disconnect(n,0):Xr(t,e,i).disconnect(n,0,s):void 0===i?e.forEach((t=>t.disconnect(n))):Xr(t,e,i).disconnect(n,0))(nr),Tc=new WeakMap,Mc=((t,e)=>n=>e(t,n))(Tc,zs),Ac=((t,e,n,i,s,r,o,a,c,l,h,u,d)=>(f,p,m,g)=>{if(0===g.numberOfInputs&&0===g.numberOfOutputs)throw c();const v=Array.isArray(g.outputChannelCount)?g.outputChannelCount:Array.from(g.outputChannelCount);if(v.some((t=>t<1)))throw c();if(v.length!==g.numberOfOutputs)throw e();if("explicit"!==g.channelCountMode)throw c();const _=g.channelCount*g.numberOfInputs,y=v.reduce(((t,e)=>t+e),0),b=void 0===m.parameterDescriptors?0:m.parameterDescriptors.length;if(_+b>6||y>6)throw c();const x=new MessageChannel,C=[],w=[];for(let t=0;t<g.numberOfInputs;t+=1)C.push(o(f,{channelCount:g.channelCount,channelCountMode:g.channelCountMode,channelInterpretation:g.channelInterpretation,gain:1})),w.push(s(f,{channelCount:g.channelCount,channelCountMode:"explicit",channelInterpretation:"discrete",numberOfOutputs:g.channelCount}));const S=[];if(void 0!==m.parameterDescriptors)for(const{defaultValue:t,maxValue:e,minValue:n,name:i}of m.parameterDescriptors){const s=r(f,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"discrete",offset:void 0!==g.parameterData[i]?g.parameterData[i]:void 0===t?0:t});Object.defineProperties(s.offset,{defaultValue:{get:()=>void 0===t?0:t},maxValue:{get:()=>void 0===e?or:e},minValue:{get:()=>void 0===n?rr:n}}),S.push(s)}const T=i(f,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"speakers",numberOfInputs:Math.max(1,_+b)}),M=co(p,f.sampleRate),A=a(f,M,_+b,Math.max(1,y)),O=s(f,{channelCount:Math.max(1,y),channelCountMode:"explicit",channelInterpretation:"discrete",numberOfOutputs:Math.max(1,y)}),E=[];for(let t=0;t<g.numberOfOutputs;t+=1)E.push(i(f,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"speakers",numberOfInputs:v[t]}));for(let t=0;t<g.numberOfInputs;t+=1){C[t].connect(w[t]);for(let e=0;e<g.channelCount;e+=1)w[t].connect(T,e,t*g.channelCount+e)}const k=new Rr(void 0===m.parameterDescriptors?[]:m.parameterDescriptors.map((({name:t},e)=>{const n=S[e];return n.connect(T,0,_+e),n.start(0),[t,n.offset]})));T.connect(A);let P=g.channelInterpretation,I=null;const D=0===g.numberOfOutputs?[A]:E,R={get bufferSize(){return M},get channelCount(){return g.channelCount},set channelCount(t){throw n()},get channelCountMode(){return g.channelCountMode},set channelCountMode(t){throw n()},get channelInterpretation(){return P},set channelInterpretation(t){for(const e of C)e.channelInterpretation=t;P=t},get context(){return A.context},get inputs(){return C},get numberOfInputs(){return g.numberOfInputs},get numberOfOutputs(){return g.numberOfOutputs},get onprocessorerror(){return I},set onprocessorerror(t){"function"==typeof I&&R.removeEventListener("processorerror",I),I="function"==typeof t?t:null,"function"==typeof I&&R.addEventListener("processorerror",I)},get parameters(){return k},get port(){return x.port2},addEventListener:(...t)=>A.addEventListener(t[0],t[1],t[2]),connect:t.bind(null,D),disconnect:l.bind(null,D),dispatchEvent:(...t)=>A.dispatchEvent(t[0]),removeEventListener:(...t)=>A.removeEventListener(t[0],t[1],t[2])},j=new Map;var $,L;x.port1.addEventListener=($=x.port1.addEventListener,(...t)=>{if("message"===t[0]){const e="function"==typeof t[1]?t[1]:"object"==typeof t[1]&&null!==t[1]&&"function"==typeof t[1].handleEvent?t[1].handleEvent:null;if(null!==e){const n=j.get(t[1]);void 0!==n?t[1]=n:(t[1]=t=>{h(f.currentTime,f.sampleRate,(()=>e(t)))},j.set(e,t[1]))}}return $.call(x.port1,t[0],t[1],t[2])}),x.port1.removeEventListener=(L=x.port1.removeEventListener,(...t)=>{if("message"===t[0]){const e=j.get(t[1]);void 0!==e&&(j.delete(t[1]),t[1]=e)}return L.call(x.port1,t[0],t[1],t[2])});let F=null;Object.defineProperty(x.port1,"onmessage",{get:()=>F,set:t=>{"function"==typeof F&&x.port1.removeEventListener("message",F),F="function"==typeof t?t:null,"function"==typeof F&&(x.port1.addEventListener("message",F),x.port1.start())}}),m.prototype.port=x.port1;let N=null;((t,e,n,i)=>{let s=Ns.get(t);void 0===s&&(s=new WeakMap,Ns.set(t,s));const r=lo(n,i);return s.set(e,r),r})(f,R,m,g).then((t=>N=t));const B=Fr(g.numberOfInputs,g.channelCount),V=Fr(g.numberOfOutputs,v),W=void 0===m.parameterDescriptors?[]:m.parameterDescriptors.reduce(((t,{name:e})=>({...t,[e]:new Float32Array(128)})),{});let H=!0;const G=()=>{g.numberOfOutputs>0&&A.disconnect(O);for(let t=0,e=0;t<g.numberOfOutputs;t+=1){const n=E[t];for(let i=0;i<v[t];i+=1)O.disconnect(n,e+i,i);e+=v[t]}},z=new Map;A.onaudioprocess=({inputBuffer:t,outputBuffer:e})=>{if(null!==N){const n=u(R);for(let i=0;i<M;i+=128){for(let e=0;e<g.numberOfInputs;e+=1)for(let n=0;n<g.channelCount;n+=1)$r(t,B[e],n,n,i);void 0!==m.parameterDescriptors&&m.parameterDescriptors.forEach((({name:e},n)=>{$r(t,W,e,_+n,i)}));for(let t=0;t<g.numberOfInputs;t+=1)for(let e=0;e<v[t];e+=1)0===V[t][e].byteLength&&(V[t][e]=new Float32Array(128));try{const t=B.map(((t,e)=>{if(n[e].size>0)return z.set(e,M/128),t;const i=z.get(e);return void 0===i?[]:(t.every((t=>t.every((t=>0===t))))&&(1===i?z.delete(e):z.set(e,i-1)),t)})),s=h(f.currentTime+i/f.sampleRate,f.sampleRate,(()=>N.process(t,V,W)));H=s;for(let t=0,n=0;t<g.numberOfOutputs;t+=1){for(let s=0;s<v[t];s+=1)Lr(e,V[t],s,n+s,i);n+=v[t]}}catch(t){H=!1,R.dispatchEvent(new ErrorEvent("processorerror",{colno:t.colno,filename:t.filename,lineno:t.lineno,message:t.message}))}if(!H){for(let t=0;t<g.numberOfInputs;t+=1){C[t].disconnect(w[t]);for(let e=0;e<g.channelCount;e+=1)w[i].disconnect(T,e,t*g.channelCount+e)}if(void 0!==m.parameterDescriptors){const t=m.parameterDescriptors.length;for(let e=0;e<t;e+=1){const t=S[e];t.disconnect(T,0,_+e),t.stop()}}T.disconnect(A),A.onaudioprocess=null,Y?G():q();break}}}};let Y=!1;const X=o(f,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"discrete",gain:0}),U=()=>A.connect(X).connect(f.destination),q=()=>{A.disconnect(X),X.disconnect()};return U(),d(R,(()=>{if(H){q(),g.numberOfOutputs>0&&A.connect(O);for(let t=0,e=0;t<g.numberOfOutputs;t+=1){const n=E[t];for(let i=0;i<v[t];i+=1)O.connect(n,e+i,i);e+=v[t]}}Y=!0}),(()=>{H&&(U(),G()),Y=!1}))})(Cc,nr,Kr,Aa,uo,Pa,mo,_o,yo,Sc,cc,Mc,Ma),Oc=((t,e,n,i,s)=>(r,o,a,c,l,h)=>{if(null!==a)try{const e=new a(r,c,h),i=new Map;let o=null;if(Object.defineProperties(e,{channelCount:{get:()=>h.channelCount,set:()=>{throw t()}},channelCountMode:{get:()=>"explicit",set:()=>{throw t()}},onprocessorerror:{get:()=>o,set:t=>{"function"==typeof o&&e.removeEventListener("processorerror",o),o="function"==typeof t?t:null,"function"==typeof o&&e.addEventListener("processorerror",o)}}}),e.addEventListener=(d=e.addEventListener,(...t)=>{if("processorerror"===t[0]){const e="function"==typeof t[1]?t[1]:"object"==typeof t[1]&&null!==t[1]&&"function"==typeof t[1].handleEvent?t[1].handleEvent:null;if(null!==e){const n=i.get(t[1]);void 0!==n?t[1]=n:(t[1]=n=>{"error"===n.type?(Object.defineProperties(n,{type:{value:"processorerror"}}),e(n)):e(new ErrorEvent(t[0],{...n}))},i.set(e,t[1]))}}return d.call(e,"error",t[1],t[2]),d.call(e,...t)}),e.removeEventListener=(u=e.removeEventListener,(...t)=>{if("processorerror"===t[0]){const e=i.get(t[1]);void 0!==e&&(i.delete(t[1]),t[1]=e)}return u.call(e,"error",t[1],t[2]),u.call(e,t[0],t[1],t[2])}),0!==h.numberOfOutputs){const t=n(r,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"discrete",gain:0});e.connect(t).connect(r.destination);return s(e,(()=>t.disconnect()),(()=>t.connect(r.destination)))}return e}catch(t){if(11===t.code)throw i();throw t}var u,d;if(void 0===l)throw i();return(t=>{const{port1:e}=new MessageChannel;try{e.postMessage(t)}finally{e.close()}})(h),e(r,o,l,h)})(Kr,Ac,mo,yo,Ma),Ec=((t,e,n,i,s,r,o,a,c,l,h,u,d,f,p,m)=>(g,v,_)=>{const y=new WeakMap;let b=null;return{render(x,C,w){a(C,x);const S=y.get(C);return void 0!==S?Promise.resolve(S):(async(a,x,C)=>{let w=h(a),S=null;const T=tr(w,x),M=Array.isArray(v.outputChannelCount)?v.outputChannelCount:Array.from(v.outputChannelCount);if(null===u){const t=M.reduce(((t,e)=>t+e),0),n=s(x,{channelCount:Math.max(1,t),channelCountMode:"explicit",channelInterpretation:"discrete",numberOfOutputs:Math.max(1,t)}),r=[];for(let t=0;t<a.numberOfOutputs;t+=1)r.push(i(x,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"speakers",numberOfInputs:M[t]}));const l=o(x,{channelCount:v.channelCount,channelCountMode:v.channelCountMode,channelInterpretation:v.channelInterpretation,gain:1});l.connect=e.bind(null,r),l.disconnect=c.bind(null,r),S=[n,r,l]}else T||(w=new u(x,g));if(y.set(x,null===S?w:S[2]),null!==S){if(null===b){if(void 0===_)throw new Error("Missing the processor constructor.");if(null===d)throw new Error("Missing the native OfflineAudioContext constructor.");const t=a.channelCount*a.numberOfInputs,e=void 0===_.parameterDescriptors?0:_.parameterDescriptors.length,n=t+e,c=async()=>{const c=new d(n,128*Math.ceil(a.context.length/128),x.sampleRate),l=[],h=[];for(let t=0;t<v.numberOfInputs;t+=1)l.push(o(c,{channelCount:v.channelCount,channelCountMode:v.channelCountMode,channelInterpretation:v.channelInterpretation,gain:1})),h.push(s(c,{channelCount:v.channelCount,channelCountMode:"explicit",channelInterpretation:"discrete",numberOfOutputs:v.channelCount}));const u=await Promise.all(Array.from(a.parameters.values()).map((async t=>{const e=r(c,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"discrete",offset:t.value});return await f(c,t,e.offset,C),e}))),g=i(c,{channelCount:1,channelCountMode:"explicit",channelInterpretation:"speakers",numberOfInputs:Math.max(1,t+e)});for(let t=0;t<v.numberOfInputs;t+=1){l[t].connect(h[t]);for(let e=0;e<v.channelCount;e+=1)h[t].connect(g,e,t*v.channelCount+e)}for(const[e,n]of u.entries())n.connect(g,0,t+e),n.start(0);return g.connect(c.destination),await Promise.all(l.map((t=>p(a,c,t,C)))),m(c)};b=Nr(a,0===n?null:await c(),x,v,M,_,l)}const t=await b,e=n(x,{buffer:null,channelCount:2,channelCountMode:"max",channelInterpretation:"speakers",loop:!1,loopEnd:0,loopStart:0,playbackRate:1}),[c,h,u]=S;null!==t&&(e.buffer=t,e.start(0)),e.connect(c);for(let t=0,e=0;t<a.numberOfOutputs;t+=1){const n=h[t];for(let i=0;i<M[t];i+=1)c.connect(n,e+i,i);e+=M[t]}return u}if(T)for(const[e,n]of a.parameters.entries())await t(x,n,w.parameters.get(e),C);else for(const[t,e]of a.parameters.entries())await f(x,e,w.parameters.get(t),C);return await p(a,x,w,C),w})(x,C,w)}}})(ma,Cc,ga,Aa,uo,Pa,mo,wc,Sc,cc,Sr,uc,qo,va,zo,Ba),kc=(t=>e=>t.get(e))(lc),Pc=(t=>(e,n)=>{t.set(e,n)})(Tc),Ic=ac?((t,e,n,i,s,r,o,a,c,l,h,u,d,f)=>class extends e{constructor(e,f,p){var m;const g=a(e),v=c(g),_=h({...jr,...p});d(_);const y=Fs.get(g),b=null==y?void 0:y.get(f),x=v||"closed"!==g.state?g:null!==(m=o(g))&&void 0!==m?m:g,C=s(x,v?null:e.baseLatency,l,f,b,_);super(e,!0,C,v?i(f,_,b):null);const w=[];C.parameters.forEach(((t,e)=>{const i=n(this,v,t);w.push([e,i])})),this._nativeAudioWorkletNode=C,this._onprocessorerror=null,this._parameters=new Rr(w),v&&t(g,this);const{activeInputs:S}=r(this);u(C,S)}get onprocessorerror(){return this._onprocessorerror}set onprocessorerror(t){const e="function"==typeof t?f(this,t):null;this._nativeAudioWorkletNode.onprocessorerror=e;const n=this._nativeAudioWorkletNode.onprocessorerror;this._onprocessorerror=null!==n&&n===e?t:n}get parameters(){return null===this._parameters?this._nativeAudioWorkletNode.parameters:this._parameters}get port(){return this._nativeAudioWorkletNode.port}})(xc,ia,ya,Ec,Oc,lr,kc,Xo,Ko,uc,(t=>({...t,outputChannelCount:void 0!==t.outputChannelCount?t.outputChannelCount:1===t.numberOfInputs&&1===t.numberOfOutputs?[t.channelCount]:Array.from({length:t.numberOfOutputs},(()=>1))})),Pc,(t=>{const{port1:e,port2:n}=new MessageChannel;try{e.postMessage(t)}finally{e.close(),n.close()}}),Do):void 0,Dc=((t,e)=>(n,i,s)=>{if(null===e)throw new Error("Missing the native OfflineAudioContext constructor.");try{return new e(n,i,s)}catch(e){if("SyntaxError"===e.name)throw t();throw e}})(yo,qo),Rc=((t,e,n,i,s,r,o,a)=>{const c=[];return(l,h)=>n(l).render(l,h,c).then((()=>Promise.all(Array.from(i(h)).map((t=>n(t).render(t,h,c)))))).then((()=>s(h))).then((n=>("function"!=typeof n.copyFromChannel?(o(n),ir(n)):e(r,(()=>r(n)))||a(n),t.add(n),n)))})(oa,No,Go,bc,Ba,er,ha,ua),jc=((t,e,n,i,s)=>class extends t{constructor(t,n,s){let r;if("number"==typeof t&&void 0!==n&&void 0!==s)r={length:n,numberOfChannels:t,sampleRate:s};else{if("object"!=typeof t)throw new Error("The given parameters are not valid.");r=t}const{length:o,numberOfChannels:a,sampleRate:c}={...bo,...r},l=i(a,o,c);e(eo,(()=>eo(l)))||l.addEventListener("statechange",(()=>{let t=0;const e=n=>{"running"===this._state&&(t>0?(l.removeEventListener("statechange",e),n.stopImmediatePropagation(),this._waitForThePromiseToSettle(n)):t+=1)};return e})()),super(l,a),this._length=o,this._nativeOfflineAudioContext=l,this._state=null}get length(){return void 0===this._nativeOfflineAudioContext.length?this._length:this._nativeOfflineAudioContext.length}get state(){return null===this._state?this._nativeOfflineAudioContext.state:this._state}startRendering(){return"running"===this._state?Promise.reject(n()):(this._state="running",s(this.destination,this._nativeOfflineAudioContext).finally((()=>{this._state=null,dr(this)})))}_waitForThePromiseToSettle(t){null===this._state?this._nativeOfflineAudioContext.dispatchEvent(t):setTimeout((()=>this._waitForThePromiseToSettle(t)))}})(pc,No,Kr,Dc,Rc),$c=((t,e)=>n=>{const i=t.get(n);return e(i)||e(n)})(js,ta),Lc=((t,e)=>n=>t.has(n)||e(n))(Is,ea),Fc=((t,e)=>n=>t.has(n)||e(n))(Rs,na),Nc=((t,e)=>n=>{const i=t.get(n);return e(i)||e(n)})(js,Ko);function Bc(t,e){if(!t)throw new Error(e)}function Vc(t,e,n=1/0){if(!(e<=t&&t<=n))throw new RangeError(`Value must be within [${e}, ${n}], got: ${t}`)}function Wc(t){t.isOffline||"running"===t.state||Gc('The AudioContext is "suspended". Invoke Tone.start() from a user action to start the audio.')}let Hc=console;function Gc(...t){Hc.warn(...t)}function zc(t){return void 0===t}function Yc(t){return!zc(t)}function Xc(t){return"number"==typeof t}function Uc(t){return"[object Object]"===Object.prototype.toString.call(t)&&t.constructor===Object}function qc(t){return Array.isArray(t)}function Kc(t){return"string"==typeof t}function Zc(t){return Kc(t)&&/^([a-g]{1}(?:b|#|x|bb)?)(-?[0-9]+)/i.test(t)}const Qc="object"==typeof self?self:null,Jc=Qc&&(Qc.hasOwnProperty("AudioContext")||Qc.hasOwnProperty("webkitAudioContext"));
  /*! *****************************************************************************
      Copyright (c) Microsoft Corporation.
  
      Permission to use, copy, modify, and/or distribute this software for any
      purpose with or without fee is hereby granted.
  
      THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
      REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
      AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
      INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
      LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
      OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
      PERFORMANCE OF THIS SOFTWARE.
      ***************************************************************************** */
  function tl(t,e,n,i){var s,r=arguments.length,o=r<3?e:null===i?i=Object.getOwnPropertyDescriptor(e,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,n,i);else for(var a=t.length-1;a>=0;a--)(s=t[a])&&(o=(r<3?s(o):r>3?s(e,n,o):s(e,n))||o);return r>3&&o&&Object.defineProperty(e,n,o),o}function el(t,e,n,i){return new(n||(n=Promise))((function(s,r){function o(t){try{c(i.next(t))}catch(t){r(t)}}function a(t){try{c(i.throw(t))}catch(t){r(t)}}function c(t){var e;t.done?s(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(o,a)}c((i=i.apply(t,e||[])).next())}))}class nl{constructor(t,e,n){this._callback=t,this._type=e,this._updateInterval=n,this._createClock()}_createWorker(){const t=new Blob([`\n\t\t\t// the initial timeout time\n\t\t\tlet timeoutTime =  ${(1e3*this._updateInterval).toFixed(1)};\n\t\t\t// onmessage callback\n\t\t\tself.onmessage = function(msg){\n\t\t\t\ttimeoutTime = parseInt(msg.data);\n\t\t\t};\n\t\t\t// the tick function which posts a message\n\t\t\t// and schedules a new tick\n\t\t\tfunction tick(){\n\t\t\t\tsetTimeout(tick, timeoutTime);\n\t\t\t\tself.postMessage('tick');\n\t\t\t}\n\t\t\t// call tick initially\n\t\t\ttick();\n\t\t\t`],{type:"text/javascript"}),e=URL.createObjectURL(t),n=new Worker(e);n.onmessage=this._callback.bind(this),this._worker=n}_createTimeout(){this._timeout=setTimeout((()=>{this._createTimeout(),this._callback()}),1e3*this._updateInterval)}_createClock(){if("worker"===this._type)try{this._createWorker()}catch(t){this._type="timeout",this._createClock()}else"timeout"===this._type&&this._createTimeout()}_disposeClock(){this._timeout&&(clearTimeout(this._timeout),this._timeout=0),this._worker&&(this._worker.terminate(),this._worker.onmessage=null)}get updateInterval(){return this._updateInterval}set updateInterval(t){this._updateInterval=Math.max(t,128/44100),"worker"===this._type&&this._worker.postMessage(Math.max(1e3*t,1))}get type(){return this._type}set type(t){this._disposeClock(),this._type=t,this._createClock()}dispose(){this._disposeClock()}}function il(t){return Fc(t)}function sl(t){return Lc(t)}function rl(t){return Nc(t)}function ol(t){return $c(t)}function al(t){return t instanceof AudioBuffer}function cl(t,e){return"value"===t||il(e)||sl(e)||al(e)}function ll(t,...e){if(!e.length)return t;const n=e.shift();if(Uc(t)&&Uc(n))for(const e in n)cl(e,n[e])?t[e]=n[e]:Uc(n[e])?(t[e]||Object.assign(t,{[e]:{}}),ll(t[e],n[e])):Object.assign(t,{[e]:n[e]});return ll(t,...e)}function hl(t,e,n=[],i){const s={},r=Array.from(e);if(Uc(r[0])&&i&&!Reflect.has(r[0],i)){Object.keys(r[0]).some((e=>Reflect.has(t,e)))||(ll(s,{[i]:r[0]}),n.splice(n.indexOf(i),1),r.shift())}if(1===r.length&&Uc(r[0]))ll(s,r[0]);else for(let t=0;t<n.length;t++)Yc(r[t])&&(s[n[t]]=r[t]);return ll(t,s)}function ul(t,e){return zc(t)?e:t}function dl(t,e){return e.forEach((e=>{Reflect.has(t,e)&&delete t[e]})),t}
  /**
       * Tone.js
       * @author Yotam Mann
       * @license http://opensource.org/licenses/MIT MIT License
       * @copyright 2014-2019 Yotam Mann
       */class fl{constructor(){this.debug=!1,this._wasDisposed=!1}static getDefaults(){return{}}log(...t){(this.debug||Qc&&this.toString()===Qc.TONE_DEBUG_CLASS)&&function(...t){Hc.log(...t)}(this,...t)}dispose(){return this._wasDisposed=!0,this}get disposed(){return this._wasDisposed}toString(){return this.name}}fl.version=bs;const pl=1e-6;function ml(t,e){return t>e+pl}function gl(t,e){return ml(t,e)||_l(t,e)}function vl(t,e){return t+pl<e}function _l(t,e){return Math.abs(t-e)<pl}class yl extends fl{constructor(){super(),this.name="Timeline",this._timeline=[];const t=hl(yl.getDefaults(),arguments,["memory"]);this.memory=t.memory,this.increasing=t.increasing}static getDefaults(){return{memory:1/0,increasing:!1}}get length(){return this._timeline.length}add(t){if(Bc(Reflect.has(t,"time"),"Timeline: events must have a time attribute"),t.time=t.time.valueOf(),this.increasing&&this.length){const e=this._timeline[this.length-1];Bc(gl(t.time,e.time),"The time must be greater than or equal to the last scheduled time"),this._timeline.push(t)}else{const e=this._search(t.time);this._timeline.splice(e+1,0,t)}if(this.length>this.memory){const t=this.length-this.memory;this._timeline.splice(0,t)}return this}remove(t){const e=this._timeline.indexOf(t);return-1!==e&&this._timeline.splice(e,1),this}get(t,e="time"){const n=this._search(t,e);return-1!==n?this._timeline[n]:null}peek(){return this._timeline[0]}shift(){return this._timeline.shift()}getAfter(t,e="time"){const n=this._search(t,e);return n+1<this._timeline.length?this._timeline[n+1]:null}getBefore(t){const e=this._timeline.length;if(e>0&&this._timeline[e-1].time<t)return this._timeline[e-1];const n=this._search(t);return n-1>=0?this._timeline[n-1]:null}cancel(t){if(this._timeline.length>1){let e=this._search(t);if(e>=0)if(_l(this._timeline[e].time,t)){for(let n=e;n>=0&&_l(this._timeline[n].time,t);n--)e=n;this._timeline=this._timeline.slice(0,e)}else this._timeline=this._timeline.slice(0,e+1);else this._timeline=[]}else 1===this._timeline.length&&gl(this._timeline[0].time,t)&&(this._timeline=[]);return this}cancelBefore(t){const e=this._search(t);return e>=0&&(this._timeline=this._timeline.slice(e+1)),this}previousEvent(t){const e=this._timeline.indexOf(t);return e>0?this._timeline[e-1]:null}_search(t,e="time"){if(0===this._timeline.length)return-1;let n=0;const i=this._timeline.length;let s=i;if(i>0&&this._timeline[i-1][e]<=t)return i-1;for(;n<s;){let i=Math.floor(n+(s-n)/2);const r=this._timeline[i],o=this._timeline[i+1];if(_l(r[e],t)){for(let n=i;n<this._timeline.length;n++){if(!_l(this._timeline[n][e],t))break;i=n}return i}if(vl(r[e],t)&&ml(o[e],t))return i;ml(r[e],t)?s=i:n=i+1}return-1}_iterate(t,e=0,n=this._timeline.length-1){this._timeline.slice(e,n+1).forEach(t)}forEach(t){return this._iterate(t),this}forEachBefore(t,e){const n=this._search(t);return-1!==n&&this._iterate(e,0,n),this}forEachAfter(t,e){const n=this._search(t);return this._iterate(e,n+1),this}forEachBetween(t,e,n){let i=this._search(t),s=this._search(e);return-1!==i&&-1!==s?(this._timeline[i].time!==t&&(i+=1),this._timeline[s].time===e&&(s-=1),this._iterate(n,i,s)):-1===i&&this._iterate(n,0,s),this}forEachFrom(t,e){let n=this._search(t);for(;n>=0&&this._timeline[n].time>=t;)n--;return this._iterate(e,n+1),this}forEachAtTime(t,e){const n=this._search(t);if(-1!==n&&_l(this._timeline[n].time,t)){let i=n;for(let e=n;e>=0&&_l(this._timeline[e].time,t);e--)i=e;this._iterate((t=>{e(t)}),i,n)}return this}dispose(){return super.dispose(),this._timeline=[],this}}const bl=[];function xl(t){bl.push(t)}const Cl=[];function wl(t){Cl.push(t)}class Sl extends fl{constructor(){super(...arguments),this.name="Emitter"}on(t,e){return t.split(/\W+/).forEach((t=>{zc(this._events)&&(this._events={}),this._events.hasOwnProperty(t)||(this._events[t]=[]),this._events[t].push(e)})),this}once(t,e){const n=(...i)=>{e(...i),this.off(t,n)};return this.on(t,n),this}off(t,e){return t.split(/\W+/).forEach((n=>{if(zc(this._events)&&(this._events={}),this._events.hasOwnProperty(t))if(zc(e))this._events[t]=[];else{const n=this._events[t];for(let t=n.length-1;t>=0;t--)n[t]===e&&n.splice(t,1)}})),this}emit(t,...e){if(this._events&&this._events.hasOwnProperty(t)){const n=this._events[t].slice(0);for(let t=0,i=n.length;t<i;t++)n[t].apply(this,e)}return this}static mixin(t){["on","once","off","emit"].forEach((e=>{const n=Object.getOwnPropertyDescriptor(Sl.prototype,e);Object.defineProperty(t.prototype,e,n)}))}dispose(){return super.dispose(),this._events=void 0,this}}class Tl extends Sl{constructor(){super(...arguments),this.isOffline=!1}toJSON(){return{}}}class Ml extends Tl{constructor(){super(),this.name="Context",this._constants=new Map,this._timeouts=new yl,this._timeoutIds=0,this._initialized=!1,this.isOffline=!1,this._workletModules=new Map;const t=hl(Ml.getDefaults(),arguments,["context"]);t.context?this._context=t.context:this._context=function(t){return new yc(t)}({latencyHint:t.latencyHint}),this._ticker=new nl(this.emit.bind(this,"tick"),t.clockSource,t.updateInterval),this.on("tick",this._timeoutLoop.bind(this)),this._context.onstatechange=()=>{this.emit("statechange",this.state)},this._setLatencyHint(t.latencyHint),this.lookAhead=t.lookAhead}static getDefaults(){return{clockSource:"worker",latencyHint:"interactive",lookAhead:.1,updateInterval:.05}}initialize(){var t;return this._initialized||(t=this,bl.forEach((e=>e(t))),this._initialized=!0),this}createAnalyser(){return this._context.createAnalyser()}createOscillator(){return this._context.createOscillator()}createBufferSource(){return this._context.createBufferSource()}createBiquadFilter(){return this._context.createBiquadFilter()}createBuffer(t,e,n){return this._context.createBuffer(t,e,n)}createChannelMerger(t){return this._context.createChannelMerger(t)}createChannelSplitter(t){return this._context.createChannelSplitter(t)}createConstantSource(){return this._context.createConstantSource()}createConvolver(){return this._context.createConvolver()}createDelay(t){return this._context.createDelay(t)}createDynamicsCompressor(){return this._context.createDynamicsCompressor()}createGain(){return this._context.createGain()}createIIRFilter(t,e){return this._context.createIIRFilter(t,e)}createPanner(){return this._context.createPanner()}createPeriodicWave(t,e,n){return this._context.createPeriodicWave(t,e,n)}createStereoPanner(){return this._context.createStereoPanner()}createWaveShaper(){return this._context.createWaveShaper()}createMediaStreamSource(t){Bc(ol(this._context),"Not available if OfflineAudioContext");return this._context.createMediaStreamSource(t)}createMediaElementSource(t){Bc(ol(this._context),"Not available if OfflineAudioContext");return this._context.createMediaElementSource(t)}createMediaStreamDestination(){Bc(ol(this._context),"Not available if OfflineAudioContext");return this._context.createMediaStreamDestination()}decodeAudioData(t){return this._context.decodeAudioData(t)}get currentTime(){return this._context.currentTime}get state(){return this._context.state}get sampleRate(){return this._context.sampleRate}get listener(){return this.initialize(),this._listener}set listener(t){Bc(!this._initialized,"The listener cannot be set after initialization."),this._listener=t}get transport(){return this.initialize(),this._transport}set transport(t){Bc(!this._initialized,"The transport cannot be set after initialization."),this._transport=t}get draw(){return this.initialize(),this._draw}set draw(t){Bc(!this._initialized,"Draw cannot be set after initialization."),this._draw=t}get destination(){return this.initialize(),this._destination}set destination(t){Bc(!this._initialized,"The destination cannot be set after initialization."),this._destination=t}createAudioWorkletNode(t,e){return function(t,e,n){return Bc(Yc(Ic),"This node only works in a secure context (https or localhost)"),new Ic(t,e,n)}(this.rawContext,t,e)}addAudioWorkletModule(t,e){return el(this,void 0,void 0,(function*(){Bc(Yc(this.rawContext.audioWorklet),"AudioWorkletNode is only available in a secure context (https or localhost)"),this._workletModules.has(e)||this._workletModules.set(e,this.rawContext.audioWorklet.addModule(t)),yield this._workletModules.get(e)}))}workletsAreReady(){return el(this,void 0,void 0,(function*(){const t=[];this._workletModules.forEach((e=>t.push(e))),yield Promise.all(t)}))}get updateInterval(){return this._ticker.updateInterval}set updateInterval(t){this._ticker.updateInterval=t}get clockSource(){return this._ticker.type}set clockSource(t){this._ticker.type=t}get latencyHint(){return this._latencyHint}_setLatencyHint(t){let e=0;if(this._latencyHint=t,Kc(t))switch(t){case"interactive":e=.1;break;case"playback":e=.5;break;case"balanced":e=.25}this.lookAhead=e,this.updateInterval=e/2}get rawContext(){return this._context}now(){return this._context.currentTime+this.lookAhead}immediate(){return this._context.currentTime}resume(){return ol(this._context)?this._context.resume():Promise.resolve()}close(){return el(this,void 0,void 0,(function*(){var t;ol(this._context)&&(yield this._context.close()),this._initialized&&(t=this,Cl.forEach((e=>e(t))))}))}getConstant(t){if(this._constants.has(t))return this._constants.get(t);{const e=this._context.createBuffer(1,128,this._context.sampleRate),n=e.getChannelData(0);for(let e=0;e<n.length;e++)n[e]=t;const i=this._context.createBufferSource();return i.channelCount=1,i.channelCountMode="explicit",i.buffer=e,i.loop=!0,i.start(0),this._constants.set(t,i),i}}dispose(){return super.dispose(),this._ticker.dispose(),this._timeouts.dispose(),Object.keys(this._constants).map((t=>this._constants[t].disconnect())),this}_timeoutLoop(){const t=this.now();let e=this._timeouts.peek();for(;this._timeouts.length&&e&&e.time<=t;)e.callback(),this._timeouts.shift(),e=this._timeouts.peek()}setTimeout(t,e){this._timeoutIds++;const n=this.now();return this._timeouts.add({callback:t,id:this._timeoutIds,time:n+e}),this._timeoutIds}clearTimeout(t){return this._timeouts.forEach((e=>{e.id===t&&this._timeouts.remove(e)})),this}clearInterval(t){return this.clearTimeout(t)}setInterval(t,e){const n=++this._timeoutIds,i=()=>{const s=this.now();this._timeouts.add({callback:()=>{t(),i()},id:n,time:s+e})};return i(),n}}function Al(t,e){qc(e)?e.forEach((e=>Al(t,e))):Object.defineProperty(t,e,{enumerable:!0,writable:!1})}function Ol(t,e){qc(e)?e.forEach((e=>Ol(t,e))):Object.defineProperty(t,e,{writable:!0})}const El=()=>{};class kl extends fl{constructor(){super(),this.name="ToneAudioBuffer",this.onload=El;const t=hl(kl.getDefaults(),arguments,["url","onload","onerror"]);this.reverse=t.reverse,this.onload=t.onload,t.url&&al(t.url)||t.url instanceof kl?this.set(t.url):Kc(t.url)&&this.load(t.url).catch(t.onerror)}static getDefaults(){return{onerror:El,onload:El,reverse:!1}}get sampleRate(){return this._buffer?this._buffer.sampleRate:Rl().sampleRate}set(t){return t instanceof kl?t.loaded?this._buffer=t.get():t.onload=()=>{this.set(t),this.onload(this)}:this._buffer=t,this._reversed&&this._reverse(),this}get(){return this._buffer}load(t){return el(this,void 0,void 0,(function*(){const e=kl.load(t).then((t=>{this.set(t),this.onload(this)}));kl.downloads.push(e);try{yield e}finally{const t=kl.downloads.indexOf(e);kl.downloads.splice(t,1)}return this}))}dispose(){return super.dispose(),this._buffer=void 0,this}fromArray(t){const e=qc(t)&&t[0].length>0,n=e?t.length:1,i=e?t[0].length:t.length,s=Rl(),r=s.createBuffer(n,i,s.sampleRate),o=e||1!==n?t:[t];for(let t=0;t<n;t++)r.copyToChannel(o[t],t);return this._buffer=r,this}toMono(t){if(Xc(t))this.fromArray(this.toArray(t));else{let t=new Float32Array(this.length);const e=this.numberOfChannels;for(let n=0;n<e;n++){const e=this.toArray(n);for(let n=0;n<e.length;n++)t[n]+=e[n]}t=t.map((t=>t/e)),this.fromArray(t)}return this}toArray(t){if(Xc(t))return this.getChannelData(t);if(1===this.numberOfChannels)return this.toArray(0);{const t=[];for(let e=0;e<this.numberOfChannels;e++)t[e]=this.getChannelData(e);return t}}getChannelData(t){return this._buffer?this._buffer.getChannelData(t):new Float32Array(0)}slice(t,e=this.duration){const n=Math.floor(t*this.sampleRate),i=Math.floor(e*this.sampleRate);Bc(n<i,"The start time must be less than the end time");const s=i-n,r=Rl().createBuffer(this.numberOfChannels,s,this.sampleRate);for(let t=0;t<this.numberOfChannels;t++)r.copyToChannel(this.getChannelData(t).subarray(n,i),t);return new kl(r)}_reverse(){if(this.loaded)for(let t=0;t<this.numberOfChannels;t++)this.getChannelData(t).reverse();return this}get loaded(){return this.length>0}get duration(){return this._buffer?this._buffer.duration:0}get length(){return this._buffer?this._buffer.length:0}get numberOfChannels(){return this._buffer?this._buffer.numberOfChannels:0}get reverse(){return this._reversed}set reverse(t){this._reversed!==t&&(this._reversed=t,this._reverse())}static fromArray(t){return(new kl).fromArray(t)}static fromUrl(t){return el(this,void 0,void 0,(function*(){const e=new kl;return yield e.load(t)}))}static load(t){return el(this,void 0,void 0,(function*(){const e=t.match(/\[([^\]\[]+\|.+)\]$/);if(e){const n=e[1].split("|");let i=n[0];for(const t of n)if(kl.supportsType(t)){i=t;break}t=t.replace(e[0],i)}const n=""===kl.baseUrl||kl.baseUrl.endsWith("/")?kl.baseUrl:kl.baseUrl+"/",i=yield fetch(n+t);if(!i.ok)throw new Error(`could not load url: ${t}`);const s=yield i.arrayBuffer();return yield Rl().decodeAudioData(s)}))}static supportsType(t){const e=t.split("."),n=e[e.length-1];return""!==document.createElement("audio").canPlayType("audio/"+n)}static loaded(){return el(this,void 0,void 0,(function*(){for(yield Promise.resolve();kl.downloads.length;)yield kl.downloads[0]}))}}kl.baseUrl="",kl.downloads=[];class Pl extends Ml{constructor(){var t,e,n;super({clockSource:"offline",context:rl(arguments[0])?arguments[0]:(t=arguments[0],e=arguments[1]*arguments[2],n=arguments[2],new jc(t,e,n)),lookAhead:0,updateInterval:rl(arguments[0])?128/arguments[0].sampleRate:128/arguments[2]}),this.name="OfflineContext",this._currentTime=0,this.isOffline=!0,this._duration=rl(arguments[0])?arguments[0].length/arguments[0].sampleRate:arguments[1]}now(){return this._currentTime}get currentTime(){return this._currentTime}_renderClock(t){return el(this,void 0,void 0,(function*(){let e=0;for(;this._duration-this._currentTime>=0;){this.emit("tick"),this._currentTime+=128/this.sampleRate,e++;const n=Math.floor(this.sampleRate/128);t&&e%n==0&&(yield new Promise((t=>setTimeout(t,1))))}}))}render(t=!0){return el(this,void 0,void 0,(function*(){yield this.workletsAreReady(),yield this._renderClock(t);const e=yield this._context.startRendering();return new kl(e)}))}close(){return Promise.resolve()}}const Il=new class extends Tl{constructor(){super(...arguments),this.lookAhead=0,this.latencyHint=0,this.isOffline=!1}createAnalyser(){return{}}createOscillator(){return{}}createBufferSource(){return{}}createBiquadFilter(){return{}}createBuffer(t,e,n){return{}}createChannelMerger(t){return{}}createChannelSplitter(t){return{}}createConstantSource(){return{}}createConvolver(){return{}}createDelay(t){return{}}createDynamicsCompressor(){return{}}createGain(){return{}}createIIRFilter(t,e){return{}}createPanner(){return{}}createPeriodicWave(t,e,n){return{}}createStereoPanner(){return{}}createWaveShaper(){return{}}createMediaStreamSource(t){return{}}createMediaElementSource(t){return{}}createMediaStreamDestination(){return{}}decodeAudioData(t){return Promise.resolve({})}createAudioWorkletNode(t,e){return{}}get rawContext(){return{}}addAudioWorkletModule(t,e){return el(this,void 0,void 0,(function*(){return Promise.resolve()}))}resume(){return Promise.resolve()}setTimeout(t,e){return 0}clearTimeout(t){return this}setInterval(t,e){return 0}clearInterval(t){return this}getConstant(t){return{}}get currentTime(){return 0}get state(){return{}}get sampleRate(){return 0}get listener(){return{}}get transport(){return{}}get draw(){return{}}set draw(t){}get destination(){return{}}set destination(t){}now(){return 0}immediate(){return 0}};let Dl=Il;function Rl(){var t;return Dl===Il&&Jc&&(t=new Ml,Dl=ol(t)?new Ml(t):rl(t)?new Pl(t):t),Dl}if(Qc&&!Qc.TONE_SILENCE_LOGGING){const t=` * Tone.js ${"v"}14.7.77 * `;console.log(`%c${t}`,"background: #000; color: #fff")}function jl(t){return Math.pow(2,t/12)}let $l=440;function Ll(t){return Math.round(Fl(t))}function Fl(t){return 69+12*Math.log2(t/$l)}function Nl(t){return $l*Math.pow(2,(t-69)/12)}class Bl extends fl{constructor(t,e,n){super(),this.defaultUnits="s",this._val=e,this._units=n,this.context=t,this._expressions=this._getExpressions()}_getExpressions(){return{hz:{method:t=>this._frequencyToUnits(parseFloat(t)),regexp:/^(\d+(?:\.\d+)?)hz$/i},i:{method:t=>this._ticksToUnits(parseInt(t,10)),regexp:/^(\d+)i$/i},m:{method:t=>this._beatsToUnits(parseInt(t,10)*this._getTimeSignature()),regexp:/^(\d+)m$/i},n:{method:(t,e)=>{const n=parseInt(t,10),i="."===e?1.5:1;return 1===n?this._beatsToUnits(this._getTimeSignature())*i:this._beatsToUnits(4/n)*i},regexp:/^(\d+)n(\.?)$/i},number:{method:t=>this._expressions[this.defaultUnits].method.call(this,t),regexp:/^(\d+(?:\.\d+)?)$/},s:{method:t=>this._secondsToUnits(parseFloat(t)),regexp:/^(\d+(?:\.\d+)?)s$/},samples:{method:t=>parseInt(t,10)/this.context.sampleRate,regexp:/^(\d+)samples$/},t:{method:t=>{const e=parseInt(t,10);return this._beatsToUnits(8/(3*Math.floor(e)))},regexp:/^(\d+)t$/i},tr:{method:(t,e,n)=>{let i=0;return t&&"0"!==t&&(i+=this._beatsToUnits(this._getTimeSignature()*parseFloat(t))),e&&"0"!==e&&(i+=this._beatsToUnits(parseFloat(e))),n&&"0"!==n&&(i+=this._beatsToUnits(parseFloat(n)/4)),i},regexp:/^(\d+(?:\.\d+)?):(\d+(?:\.\d+)?):?(\d+(?:\.\d+)?)?$/}}}valueOf(){if(this._val instanceof Bl&&this.fromType(this._val),zc(this._val))return this._noArg();if(Kc(this._val)&&zc(this._units)){for(const t in this._expressions)if(this._expressions[t].regexp.test(this._val.trim())){this._units=t;break}}else if(Uc(this._val)){let t=0;for(const e in this._val)if(Yc(this._val[e])){const n=this._val[e];t+=new this.constructor(this.context,e).valueOf()*n}return t}if(Yc(this._units)){const t=this._expressions[this._units],e=this._val.toString().trim().match(t.regexp);return e?t.method.apply(this,e.slice(1)):t.method.call(this,this._val)}return Kc(this._val)?parseFloat(this._val):this._val}_frequencyToUnits(t){return 1/t}_beatsToUnits(t){return 60/this._getBpm()*t}_secondsToUnits(t){return t}_ticksToUnits(t){return t*this._beatsToUnits(1)/this._getPPQ()}_noArg(){return this._now()}_getBpm(){return this.context.transport.bpm.value}_getTimeSignature(){return this.context.transport.timeSignature}_getPPQ(){return this.context.transport.PPQ}fromType(t){switch(this._units=void 0,this.defaultUnits){case"s":this._val=t.toSeconds();break;case"i":this._val=t.toTicks();break;case"hz":this._val=t.toFrequency();break;case"midi":this._val=t.toMidi()}return this}toFrequency(){return 1/this.toSeconds()}toSamples(){return this.toSeconds()*this.context.sampleRate}toMilliseconds(){return 1e3*this.toSeconds()}}class Vl extends Bl{constructor(){super(...arguments),this.name="TimeClass"}_getExpressions(){return Object.assign(super._getExpressions(),{now:{method:t=>this._now()+new this.constructor(this.context,t).valueOf(),regexp:/^\+(.+)/},quantize:{method:t=>{const e=new Vl(this.context,t).valueOf();return this._secondsToUnits(this.context.transport.nextSubdivision(e))},regexp:/^@(.+)/}})}quantize(t,e=1){const n=new this.constructor(this.context,t).valueOf(),i=this.valueOf();return i+(Math.round(i/n)*n-i)*e}toNotation(){const t=this.toSeconds(),e=["1m"];for(let t=1;t<9;t++){const n=Math.pow(2,t);e.push(n+"n."),e.push(n+"n"),e.push(n+"t")}e.push("0");let n=e[0],i=new Vl(this.context,e[0]).toSeconds();return e.forEach((e=>{const s=new Vl(this.context,e).toSeconds();Math.abs(s-t)<Math.abs(i-t)&&(n=e,i=s)})),n}toBarsBeatsSixteenths(){const t=this._beatsToUnits(1);let e=this.valueOf()/t;e=parseFloat(e.toFixed(4));const n=Math.floor(e/this._getTimeSignature());let i=e%1*4;e=Math.floor(e)%this._getTimeSignature();const s=i.toString();s.length>3&&(i=parseFloat(parseFloat(s).toFixed(3)));return[n,e,i].join(":")}toTicks(){const t=this._beatsToUnits(1),e=this.valueOf()/t;return Math.round(e*this._getPPQ())}toSeconds(){return this.valueOf()}toMidi(){return Ll(this.toFrequency())}_now(){return this.context.now()}}class Wl extends Vl{constructor(){super(...arguments),this.name="Frequency",this.defaultUnits="hz"}static get A4(){return $l}static set A4(t){!function(t){$l=t}(t)}_getExpressions(){return Object.assign({},super._getExpressions(),{midi:{regexp:/^(\d+(?:\.\d+)?midi)/,method(t){return"midi"===this.defaultUnits?t:Wl.mtof(t)}},note:{regexp:/^([a-g]{1}(?:b|#|x|bb)?)(-?[0-9]+)/i,method(t,e){const n=Hl[t.toLowerCase()]+12*(parseInt(e,10)+1);return"midi"===this.defaultUnits?n:Wl.mtof(n)}},tr:{regexp:/^(\d+(?:\.\d+)?):(\d+(?:\.\d+)?):?(\d+(?:\.\d+)?)?/,method(t,e,n){let i=1;return t&&"0"!==t&&(i*=this._beatsToUnits(this._getTimeSignature()*parseFloat(t))),e&&"0"!==e&&(i*=this._beatsToUnits(parseFloat(e))),n&&"0"!==n&&(i*=this._beatsToUnits(parseFloat(n)/4)),i}}})}transpose(t){return new Wl(this.context,this.valueOf()*jl(t))}harmonize(t){return t.map((t=>this.transpose(t)))}toMidi(){return Ll(this.valueOf())}toNote(){const t=this.toFrequency(),e=Math.log2(t/Wl.A4);let n=Math.round(12*e)+57;const i=Math.floor(n/12);i<0&&(n+=-12*i);return Gl[n%12]+i.toString()}toSeconds(){return 1/super.toSeconds()}toTicks(){const t=this._beatsToUnits(1),e=this.valueOf()/t;return Math.floor(e*this._getPPQ())}_noArg(){return 0}_frequencyToUnits(t){return t}_ticksToUnits(t){return 1/(60*t/(this._getBpm()*this._getPPQ()))}_beatsToUnits(t){return 1/super._beatsToUnits(t)}_secondsToUnits(t){return 1/t}static mtof(t){return Nl(t)}static ftom(t){return Ll(t)}}const Hl={cbb:-2,cb:-1,c:0,"c#":1,cx:2,dbb:0,db:1,d:2,"d#":3,dx:4,ebb:2,eb:3,e:4,"e#":5,ex:6,fbb:3,fb:4,f:5,"f#":6,fx:7,gbb:5,gb:6,g:7,"g#":8,gx:9,abb:7,ab:8,a:9,"a#":10,ax:11,bbb:9,bb:10,b:11,"b#":12,bx:13},Gl=["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"];class zl extends Vl{constructor(){super(...arguments),this.name="TransportTime"}_now(){return this.context.transport.seconds}}class Yl extends fl{constructor(){super();const t=hl(Yl.getDefaults(),arguments,["context"]);this.defaultContext?this.context=this.defaultContext:this.context=t.context}static getDefaults(){return{context:Rl()}}now(){return this.context.currentTime+this.context.lookAhead}immediate(){return this.context.currentTime}get sampleTime(){return 1/this.context.sampleRate}get blockTime(){return 128/this.context.sampleRate}toSeconds(t){return new Vl(this.context,t).toSeconds()}toFrequency(t){return new Wl(this.context,t).toFrequency()}toTicks(t){return new zl(this.context,t).toTicks()}_getPartialProperties(t){const e=this.get();return Object.keys(e).forEach((n=>{zc(t[n])&&delete e[n]})),e}get(){const t=function(t){return t.constructor.getDefaults()}(this);return Object.keys(t).forEach((e=>{if(Reflect.has(this,e)){const n=this[e];Yc(n)&&Yc(n.value)&&Yc(n.setValueAtTime)?t[e]=n.value:n instanceof Yl?t[e]=n._getPartialProperties(t[e]):qc(n)||Xc(n)||Kc(n)||"boolean"==typeof n?t[e]=n:delete t[e]}})),t}set(t){return Object.keys(t).forEach((e=>{Reflect.has(this,e)&&Yc(this[e])&&(this[e]&&Yc(this[e].value)&&Yc(this[e].setValueAtTime)?this[e].value!==t[e]&&(this[e].value=t[e]):this[e]instanceof Yl?this[e].set(t[e]):this[e]=t[e])})),this}}class Xl extends yl{constructor(t="stopped"){super(),this.name="StateTimeline",this._initial=t,this.setStateAtTime(this._initial,0)}getValueAtTime(t){const e=this.get(t);return null!==e?e.state:this._initial}setStateAtTime(t,e,n){return Vc(e,0),this.add(Object.assign({},n,{state:t,time:e})),this}getLastState(t,e){for(let n=this._search(e);n>=0;n--){const e=this._timeline[n];if(e.state===t)return e}}getNextState(t,e){const n=this._search(e);if(-1!==n)for(let e=n;e<this._timeline.length;e++){const n=this._timeline[e];if(n.state===t)return n}}}class Ul extends Yl{constructor(){super(hl(Ul.getDefaults(),arguments,["param","units","convert"])),this.name="Param",this.overridden=!1,this._minOutput=1e-7;const t=hl(Ul.getDefaults(),arguments,["param","units","convert"]);for(Bc(Yc(t.param)&&(il(t.param)||t.param instanceof Ul),"param must be an AudioParam");!il(t.param);)t.param=t.param._param;this._swappable=!!Yc(t.swappable)&&t.swappable,this._swappable?(this.input=this.context.createGain(),this._param=t.param,this.input.connect(this._param)):this._param=this.input=t.param,this._events=new yl(1e3),this._initialValue=this._param.defaultValue,this.units=t.units,this.convert=t.convert,this._minValue=t.minValue,this._maxValue=t.maxValue,Yc(t.value)&&t.value!==this._toType(this._initialValue)&&this.setValueAtTime(t.value,0)}static getDefaults(){return Object.assign(Yl.getDefaults(),{convert:!0,units:"number"})}get value(){const t=this.now();return this.getValueAtTime(t)}set value(t){this.cancelScheduledValues(this.now()),this.setValueAtTime(t,this.now())}get minValue(){return Yc(this._minValue)?this._minValue:"time"===this.units||"frequency"===this.units||"normalRange"===this.units||"positive"===this.units||"transportTime"===this.units||"ticks"===this.units||"bpm"===this.units||"hertz"===this.units||"samples"===this.units?0:"audioRange"===this.units?-1:"decibels"===this.units?-1/0:this._param.minValue}get maxValue(){return Yc(this._maxValue)?this._maxValue:"normalRange"===this.units||"audioRange"===this.units?1:this._param.maxValue}_is(t,e){return this.units===e}_assertRange(t){return Yc(this.maxValue)&&Yc(this.minValue)&&Vc(t,this._fromType(this.minValue),this._fromType(this.maxValue)),t}_fromType(t){return this.convert&&!this.overridden?this._is(t,"time")?this.toSeconds(t):this._is(t,"decibels")?(e=t,Math.pow(10,e/20)):this._is(t,"frequency")?this.toFrequency(t):t:this.overridden?0:t;var e}_toType(t){return this.convert&&"decibels"===this.units?(e=t,Math.log(e)/Math.LN10*20):t;var e}setValueAtTime(t,e){const n=this.toSeconds(e),i=this._fromType(t);return Bc(isFinite(i)&&isFinite(n),`Invalid argument(s) to setValueAtTime: ${JSON.stringify(t)}, ${JSON.stringify(e)}`),this._assertRange(i),this.log(this.units,"setValueAtTime",t,n),this._events.add({time:n,type:"setValueAtTime",value:i}),this._param.setValueAtTime(i,n),this}getValueAtTime(t){const e=Math.max(this.toSeconds(t),0),n=this._events.getAfter(e),i=this._events.get(e);let s=this._initialValue;if(null===i)s=this._initialValue;else if("setTargetAtTime"!==i.type||null!==n&&"setValueAtTime"!==n.type)if(null===n)s=i.value;else if("linearRampToValueAtTime"===n.type||"exponentialRampToValueAtTime"===n.type){let t=i.value;if("setTargetAtTime"===i.type){const e=this._events.getBefore(i.time);t=null===e?this._initialValue:e.value}s="linearRampToValueAtTime"===n.type?this._linearInterpolate(i.time,t,n.time,n.value,e):this._exponentialInterpolate(i.time,t,n.time,n.value,e)}else s=i.value;else{const t=this._events.getBefore(i.time);let n;n=null===t?this._initialValue:t.value,"setTargetAtTime"===i.type&&(s=this._exponentialApproach(i.time,n,i.value,i.constant,e))}return this._toType(s)}setRampPoint(t){t=this.toSeconds(t);let e=this.getValueAtTime(t);return this.cancelAndHoldAtTime(t),0===this._fromType(e)&&(e=this._toType(this._minOutput)),this.setValueAtTime(e,t),this}linearRampToValueAtTime(t,e){const n=this._fromType(t),i=this.toSeconds(e);return Bc(isFinite(n)&&isFinite(i),`Invalid argument(s) to linearRampToValueAtTime: ${JSON.stringify(t)}, ${JSON.stringify(e)}`),this._assertRange(n),this._events.add({time:i,type:"linearRampToValueAtTime",value:n}),this.log(this.units,"linearRampToValueAtTime",t,i),this._param.linearRampToValueAtTime(n,i),this}exponentialRampToValueAtTime(t,e){let n=this._fromType(t);n=_l(n,0)?this._minOutput:n,this._assertRange(n);const i=this.toSeconds(e);return Bc(isFinite(n)&&isFinite(i),`Invalid argument(s) to exponentialRampToValueAtTime: ${JSON.stringify(t)}, ${JSON.stringify(e)}`),this._events.add({time:i,type:"exponentialRampToValueAtTime",value:n}),this.log(this.units,"exponentialRampToValueAtTime",t,i),this._param.exponentialRampToValueAtTime(n,i),this}exponentialRampTo(t,e,n){return n=this.toSeconds(n),this.setRampPoint(n),this.exponentialRampToValueAtTime(t,n+this.toSeconds(e)),this}linearRampTo(t,e,n){return n=this.toSeconds(n),this.setRampPoint(n),this.linearRampToValueAtTime(t,n+this.toSeconds(e)),this}targetRampTo(t,e,n){return n=this.toSeconds(n),this.setRampPoint(n),this.exponentialApproachValueAtTime(t,n,e),this}exponentialApproachValueAtTime(t,e,n){e=this.toSeconds(e),n=this.toSeconds(n);const i=Math.log(n+1)/Math.log(200);return this.setTargetAtTime(t,e,i),this.cancelAndHoldAtTime(e+.9*n),this.linearRampToValueAtTime(t,e+n),this}setTargetAtTime(t,e,n){const i=this._fromType(t);Bc(isFinite(n)&&n>0,"timeConstant must be a number greater than 0");const s=this.toSeconds(e);return this._assertRange(i),Bc(isFinite(i)&&isFinite(s),`Invalid argument(s) to setTargetAtTime: ${JSON.stringify(t)}, ${JSON.stringify(e)}`),this._events.add({constant:n,time:s,type:"setTargetAtTime",value:i}),this.log(this.units,"setTargetAtTime",t,s,n),this._param.setTargetAtTime(i,s,n),this}setValueCurveAtTime(t,e,n,i=1){n=this.toSeconds(n),e=this.toSeconds(e);const s=this._fromType(t[0])*i;this.setValueAtTime(this._toType(s),e);const r=n/(t.length-1);for(let n=1;n<t.length;n++){const s=this._fromType(t[n])*i;this.linearRampToValueAtTime(this._toType(s),e+n*r)}return this}cancelScheduledValues(t){const e=this.toSeconds(t);return Bc(isFinite(e),`Invalid argument to cancelScheduledValues: ${JSON.stringify(t)}`),this._events.cancel(e),this._param.cancelScheduledValues(e),this.log(this.units,"cancelScheduledValues",e),this}cancelAndHoldAtTime(t){const e=this.toSeconds(t),n=this._fromType(this.getValueAtTime(e));Bc(isFinite(e),`Invalid argument to cancelAndHoldAtTime: ${JSON.stringify(t)}`),this.log(this.units,"cancelAndHoldAtTime",e,"value="+n);const i=this._events.get(e),s=this._events.getAfter(e);return i&&_l(i.time,e)?s?(this._param.cancelScheduledValues(s.time),this._events.cancel(s.time)):(this._param.cancelAndHoldAtTime(e),this._events.cancel(e+this.sampleTime)):s&&(this._param.cancelScheduledValues(s.time),this._events.cancel(s.time),"linearRampToValueAtTime"===s.type?this.linearRampToValueAtTime(this._toType(n),e):"exponentialRampToValueAtTime"===s.type&&this.exponentialRampToValueAtTime(this._toType(n),e)),this._events.add({time:e,type:"setValueAtTime",value:n}),this._param.setValueAtTime(n,e),this}rampTo(t,e=.1,n){return"frequency"===this.units||"bpm"===this.units||"decibels"===this.units?this.exponentialRampTo(t,e,n):this.linearRampTo(t,e,n),this}apply(t){const e=this.context.currentTime;t.setValueAtTime(this.getValueAtTime(e),e);const n=this._events.get(e);if(n&&"setTargetAtTime"===n.type){const i=this._events.getAfter(n.time),s=i?i.time:e+2,r=(s-e)/10;for(let n=e;n<s;n+=r)t.linearRampToValueAtTime(this.getValueAtTime(n),n)}return this._events.forEachAfter(this.context.currentTime,(e=>{"cancelScheduledValues"===e.type?t.cancelScheduledValues(e.time):"setTargetAtTime"===e.type?t.setTargetAtTime(e.value,e.time,e.constant):t[e.type](e.value,e.time)})),this}setParam(t){Bc(this._swappable,"The Param must be assigned as 'swappable' in the constructor");const e=this.input;return e.disconnect(this._param),this.apply(t),this._param=t,e.connect(this._param),this}dispose(){return super.dispose(),this._events.dispose(),this}get defaultValue(){return this._toType(this._param.defaultValue)}_exponentialApproach(t,e,n,i,s){return n+(e-n)*Math.exp(-(s-t)/i)}_linearInterpolate(t,e,n,i,s){return e+(s-t)/(n-t)*(i-e)}_exponentialInterpolate(t,e,n,i,s){return e*Math.pow(i/e,(s-t)/(n-t))}}class ql extends Yl{constructor(){super(...arguments),this.name="ToneAudioNode",this._internalChannels=[]}get numberOfInputs(){return Yc(this.input)?il(this.input)||this.input instanceof Ul?1:this.input.numberOfInputs:0}get numberOfOutputs(){return Yc(this.output)?this.output.numberOfOutputs:0}_isAudioNode(t){return Yc(t)&&(t instanceof ql||sl(t))}_getInternalNodes(){const t=this._internalChannels.slice(0);return this._isAudioNode(this.input)&&t.push(this.input),this._isAudioNode(this.output)&&this.input!==this.output&&t.push(this.output),t}_setChannelProperties(t){this._getInternalNodes().forEach((e=>{e.channelCount=t.channelCount,e.channelCountMode=t.channelCountMode,e.channelInterpretation=t.channelInterpretation}))}_getChannelProperties(){const t=this._getInternalNodes();Bc(t.length>0,"ToneAudioNode does not have any internal nodes");const e=t[0];return{channelCount:e.channelCount,channelCountMode:e.channelCountMode,channelInterpretation:e.channelInterpretation}}get channelCount(){return this._getChannelProperties().channelCount}set channelCount(t){const e=this._getChannelProperties();this._setChannelProperties(Object.assign(e,{channelCount:t}))}get channelCountMode(){return this._getChannelProperties().channelCountMode}set channelCountMode(t){const e=this._getChannelProperties();this._setChannelProperties(Object.assign(e,{channelCountMode:t}))}get channelInterpretation(){return this._getChannelProperties().channelInterpretation}set channelInterpretation(t){const e=this._getChannelProperties();this._setChannelProperties(Object.assign(e,{channelInterpretation:t}))}connect(t,e=0,n=0){return Zl(this,t,e,n),this}toDestination(){return this.connect(this.context.destination),this}toMaster(){return Gc("toMaster() has been renamed toDestination()"),this.toDestination()}disconnect(t,e=0,n=0){return function(t,e,n=0,i=0){if(Yc(e))for(;e instanceof ql;)e=e.input;for(;!sl(t);)Yc(t.output)&&(t=t.output);il(e)?t.disconnect(e,n):sl(e)?t.disconnect(e,n,i):t.disconnect()}(this,t,e,n),this}chain(...t){return Kl(this,...t),this}fan(...t){return t.forEach((t=>this.connect(t))),this}dispose(){return super.dispose(),Yc(this.input)&&(this.input instanceof ql?this.input.dispose():sl(this.input)&&this.input.disconnect()),Yc(this.output)&&(this.output instanceof ql?this.output.dispose():sl(this.output)&&this.output.disconnect()),this._internalChannels=[],this}}function Kl(...t){const e=t.shift();t.reduce(((t,e)=>(t instanceof ql?t.connect(e):sl(t)&&Zl(t,e),e)),e)}function Zl(t,e,n=0,i=0){for(Bc(Yc(t),"Cannot connect from undefined node"),Bc(Yc(e),"Cannot connect to undefined node"),(e instanceof ql||sl(e))&&Bc(e.numberOfInputs>0,"Cannot connect to node with no inputs"),Bc(t.numberOfOutputs>0,"Cannot connect from node with no outputs");e instanceof ql||e instanceof Ul;)Yc(e.input)&&(e=e.input);for(;t instanceof ql;)Yc(t.output)&&(t=t.output);il(e)?t.connect(e,n):t.connect(e,n,i)}class Ql extends ql{constructor(){super(hl(Ql.getDefaults(),arguments,["gain","units"])),this.name="Gain",this._gainNode=this.context.createGain(),this.input=this._gainNode,this.output=this._gainNode;const t=hl(Ql.getDefaults(),arguments,["gain","units"]);this.gain=new Ul({context:this.context,convert:t.convert,param:this._gainNode.gain,units:t.units,value:t.gain,minValue:t.minValue,maxValue:t.maxValue}),Al(this,"gain")}static getDefaults(){return Object.assign(ql.getDefaults(),{convert:!0,gain:1,units:"gain"})}dispose(){return super.dispose(),this._gainNode.disconnect(),this.gain.dispose(),this}}class Jl extends ql{constructor(t){super(t),this.onended=El,this._startTime=-1,this._stopTime=-1,this._timeout=-1,this.output=new Ql({context:this.context,gain:0}),this._gainNode=this.output,this.getStateAtTime=function(t){const e=this.toSeconds(t);return-1!==this._startTime&&e>=this._startTime&&(-1===this._stopTime||e<=this._stopTime)?"started":"stopped"},this._fadeIn=t.fadeIn,this._fadeOut=t.fadeOut,this._curve=t.curve,this.onended=t.onended}static getDefaults(){return Object.assign(ql.getDefaults(),{curve:"linear",fadeIn:0,fadeOut:0,onended:El})}_startGain(t,e=1){Bc(-1===this._startTime,"Source cannot be started more than once");const n=this.toSeconds(this._fadeIn);return this._startTime=t+n,this._startTime=Math.max(this._startTime,this.context.currentTime),n>0?(this._gainNode.gain.setValueAtTime(0,t),"linear"===this._curve?this._gainNode.gain.linearRampToValueAtTime(e,t+n):this._gainNode.gain.exponentialApproachValueAtTime(e,t,n)):this._gainNode.gain.setValueAtTime(e,t),this}stop(t){return this.log("stop",t),this._stopGain(this.toSeconds(t)),this}_stopGain(t){Bc(-1!==this._startTime,"'start' must be called before 'stop'"),this.cancelStop();const e=this.toSeconds(this._fadeOut);return this._stopTime=this.toSeconds(t)+e,this._stopTime=Math.max(this._stopTime,this.context.currentTime),e>0?"linear"===this._curve?this._gainNode.gain.linearRampTo(0,e,t):this._gainNode.gain.targetRampTo(0,e,t):(this._gainNode.gain.cancelAndHoldAtTime(t),this._gainNode.gain.setValueAtTime(0,t)),this.context.clearTimeout(this._timeout),this._timeout=this.context.setTimeout((()=>{const t="exponential"===this._curve?2*e:0;this._stopSource(this.now()+t),this._onended()}),this._stopTime-this.context.currentTime),this}_onended(){if(this.onended!==El&&(this.onended(this),this.onended=El,!this.context.isOffline)){const t=()=>this.dispose();void 0!==window.requestIdleCallback?window.requestIdleCallback(t):setTimeout(t,1e3)}}get state(){return this.getStateAtTime(this.now())}cancelStop(){return this.log("cancelStop"),Bc(-1!==this._startTime,"Source is not started"),this._gainNode.gain.cancelScheduledValues(this._startTime+this.sampleTime),this.context.clearTimeout(this._timeout),this._stopTime=-1,this}dispose(){return super.dispose(),this._gainNode.disconnect(),this}}class th extends Jl{constructor(){super(hl(th.getDefaults(),arguments,["offset"])),this.name="ToneConstantSource",this._source=this.context.createConstantSource();const t=hl(th.getDefaults(),arguments,["offset"]);Zl(this._source,this._gainNode),this.offset=new Ul({context:this.context,convert:t.convert,param:this._source.offset,units:t.units,value:t.offset,minValue:t.minValue,maxValue:t.maxValue})}static getDefaults(){return Object.assign(Jl.getDefaults(),{convert:!0,offset:1,units:"number"})}start(t){const e=this.toSeconds(t);return this.log("start",e),this._startGain(e),this._source.start(e),this}_stopSource(t){this._source.stop(t)}dispose(){return super.dispose(),"started"===this.state&&this.stop(),this._source.disconnect(),this.offset.dispose(),this}}class eh extends ql{constructor(){super(hl(eh.getDefaults(),arguments,["value","units"])),this.name="Signal",this.override=!0;const t=hl(eh.getDefaults(),arguments,["value","units"]);this.output=this._constantSource=new th({context:this.context,convert:t.convert,offset:t.value,units:t.units,minValue:t.minValue,maxValue:t.maxValue}),this._constantSource.start(0),this.input=this._param=this._constantSource.offset}static getDefaults(){return Object.assign(ql.getDefaults(),{convert:!0,units:"number",value:0})}connect(t,e=0,n=0){return nh(this,t,e,n),this}dispose(){return super.dispose(),this._param.dispose(),this._constantSource.dispose(),this}setValueAtTime(t,e){return this._param.setValueAtTime(t,e),this}getValueAtTime(t){return this._param.getValueAtTime(t)}setRampPoint(t){return this._param.setRampPoint(t),this}linearRampToValueAtTime(t,e){return this._param.linearRampToValueAtTime(t,e),this}exponentialRampToValueAtTime(t,e){return this._param.exponentialRampToValueAtTime(t,e),this}exponentialRampTo(t,e,n){return this._param.exponentialRampTo(t,e,n),this}linearRampTo(t,e,n){return this._param.linearRampTo(t,e,n),this}targetRampTo(t,e,n){return this._param.targetRampTo(t,e,n),this}exponentialApproachValueAtTime(t,e,n){return this._param.exponentialApproachValueAtTime(t,e,n),this}setTargetAtTime(t,e,n){return this._param.setTargetAtTime(t,e,n),this}setValueCurveAtTime(t,e,n,i){return this._param.setValueCurveAtTime(t,e,n,i),this}cancelScheduledValues(t){return this._param.cancelScheduledValues(t),this}cancelAndHoldAtTime(t){return this._param.cancelAndHoldAtTime(t),this}rampTo(t,e,n){return this._param.rampTo(t,e,n),this}get value(){return this._param.value}set value(t){this._param.value=t}get convert(){return this._param.convert}set convert(t){this._param.convert=t}get units(){return this._param.units}get overridden(){return this._param.overridden}set overridden(t){this._param.overridden=t}get maxValue(){return this._param.maxValue}get minValue(){return this._param.minValue}apply(t){return this._param.apply(t),this}}function nh(t,e,n,i){(e instanceof Ul||il(e)||e instanceof eh&&e.override)&&(e.cancelScheduledValues(0),e.setValueAtTime(0,0),e instanceof eh&&(e.overridden=!0)),Zl(t,e,n,i)}class ih extends Ul{constructor(){super(hl(ih.getDefaults(),arguments,["value"])),this.name="TickParam",this._events=new yl(1/0),this._multiplier=1;const t=hl(ih.getDefaults(),arguments,["value"]);this._multiplier=t.multiplier,this._events.cancel(0),this._events.add({ticks:0,time:0,type:"setValueAtTime",value:this._fromType(t.value)}),this.setValueAtTime(t.value,0)}static getDefaults(){return Object.assign(Ul.getDefaults(),{multiplier:1,units:"hertz",value:1})}setTargetAtTime(t,e,n){e=this.toSeconds(e),this.setRampPoint(e);const i=this._fromType(t),s=this._events.get(e),r=Math.round(Math.max(1/n,1));for(let t=0;t<=r;t++){const r=n*t+e,o=this._exponentialApproach(s.time,s.value,i,n,r);this.linearRampToValueAtTime(this._toType(o),r)}return this}setValueAtTime(t,e){const n=this.toSeconds(e);super.setValueAtTime(t,e);const i=this._events.get(n),s=this._events.previousEvent(i),r=this._getTicksUntilEvent(s,n);return i.ticks=Math.max(r,0),this}linearRampToValueAtTime(t,e){const n=this.toSeconds(e);super.linearRampToValueAtTime(t,e);const i=this._events.get(n),s=this._events.previousEvent(i),r=this._getTicksUntilEvent(s,n);return i.ticks=Math.max(r,0),this}exponentialRampToValueAtTime(t,e){e=this.toSeconds(e);const n=this._fromType(t),i=this._events.get(e),s=Math.round(Math.max(10*(e-i.time),1)),r=(e-i.time)/s;for(let t=0;t<=s;t++){const s=r*t+i.time,o=this._exponentialInterpolate(i.time,i.value,e,n,s);this.linearRampToValueAtTime(this._toType(o),s)}return this}_getTicksUntilEvent(t,e){if(null===t)t={ticks:0,time:0,type:"setValueAtTime",value:0};else if(zc(t.ticks)){const e=this._events.previousEvent(t);t.ticks=this._getTicksUntilEvent(e,t.time)}const n=this._fromType(this.getValueAtTime(t.time));let i=this._fromType(this.getValueAtTime(e));const s=this._events.get(e);return s&&s.time===e&&"setValueAtTime"===s.type&&(i=this._fromType(this.getValueAtTime(e-this.sampleTime))),.5*(e-t.time)*(n+i)+t.ticks}getTicksAtTime(t){const e=this.toSeconds(t),n=this._events.get(e);return Math.max(this._getTicksUntilEvent(n,e),0)}getDurationOfTicks(t,e){const n=this.toSeconds(e),i=this.getTicksAtTime(e);return this.getTimeOfTick(i+t)-n}getTimeOfTick(t){const e=this._events.get(t,"ticks"),n=this._events.getAfter(t,"ticks");if(e&&e.ticks===t)return e.time;if(e&&n&&"linearRampToValueAtTime"===n.type&&e.value!==n.value){const i=this._fromType(this.getValueAtTime(e.time)),s=(this._fromType(this.getValueAtTime(n.time))-i)/(n.time-e.time),r=Math.sqrt(Math.pow(i,2)-2*s*(e.ticks-t)),o=(-i+r)/s,a=(-i-r)/s;return(o>0?o:a)+e.time}return e?0===e.value?1/0:e.time+(t-e.ticks)/e.value:t/this._initialValue}ticksToTime(t,e){return this.getDurationOfTicks(t,e)}timeToTicks(t,e){const n=this.toSeconds(e),i=this.toSeconds(t),s=this.getTicksAtTime(n);return this.getTicksAtTime(n+i)-s}_fromType(t){return"bpm"===this.units&&this.multiplier?1/(60/t/this.multiplier):super._fromType(t)}_toType(t){return"bpm"===this.units&&this.multiplier?t/this.multiplier*60:super._toType(t)}get multiplier(){return this._multiplier}set multiplier(t){const e=this.value;this._multiplier=t,this.cancelScheduledValues(0),this.setValueAtTime(e,0)}}class sh extends eh{constructor(){super(hl(sh.getDefaults(),arguments,["value"])),this.name="TickSignal";const t=hl(sh.getDefaults(),arguments,["value"]);this.input=this._param=new ih({context:this.context,convert:t.convert,multiplier:t.multiplier,param:this._constantSource.offset,units:t.units,value:t.value})}static getDefaults(){return Object.assign(eh.getDefaults(),{multiplier:1,units:"hertz",value:1})}ticksToTime(t,e){return this._param.ticksToTime(t,e)}timeToTicks(t,e){return this._param.timeToTicks(t,e)}getTimeOfTick(t){return this._param.getTimeOfTick(t)}getDurationOfTicks(t,e){return this._param.getDurationOfTicks(t,e)}getTicksAtTime(t){return this._param.getTicksAtTime(t)}get multiplier(){return this._param.multiplier}set multiplier(t){this._param.multiplier=t}dispose(){return super.dispose(),this._param.dispose(),this}}class rh extends Yl{constructor(){super(hl(rh.getDefaults(),arguments,["frequency"])),this.name="TickSource",this._state=new Xl,this._tickOffset=new yl;const t=hl(rh.getDefaults(),arguments,["frequency"]);this.frequency=new sh({context:this.context,units:t.units,value:t.frequency}),Al(this,"frequency"),this._state.setStateAtTime("stopped",0),this.setTicksAtTime(0,0)}static getDefaults(){return Object.assign({frequency:1,units:"hertz"},Yl.getDefaults())}get state(){return this.getStateAtTime(this.now())}start(t,e){const n=this.toSeconds(t);return"started"!==this._state.getValueAtTime(n)&&(this._state.setStateAtTime("started",n),Yc(e)&&this.setTicksAtTime(e,n)),this}stop(t){const e=this.toSeconds(t);if("stopped"===this._state.getValueAtTime(e)){const t=this._state.get(e);t&&t.time>0&&(this._tickOffset.cancel(t.time),this._state.cancel(t.time))}return this._state.cancel(e),this._state.setStateAtTime("stopped",e),this.setTicksAtTime(0,e),this}pause(t){const e=this.toSeconds(t);return"started"===this._state.getValueAtTime(e)&&this._state.setStateAtTime("paused",e),this}cancel(t){return t=this.toSeconds(t),this._state.cancel(t),this._tickOffset.cancel(t),this}getTicksAtTime(t){const e=this.toSeconds(t),n=this._state.getLastState("stopped",e),i={state:"paused",time:e};this._state.add(i);let s=n,r=0;return this._state.forEachBetween(n.time,e+this.sampleTime,(t=>{let e=s.time;const n=this._tickOffset.get(t.time);n&&n.time>=s.time&&(r=n.ticks,e=n.time),"started"===s.state&&"started"!==t.state&&(r+=this.frequency.getTicksAtTime(t.time)-this.frequency.getTicksAtTime(e)),s=t})),this._state.remove(i),r}get ticks(){return this.getTicksAtTime(this.now())}set ticks(t){this.setTicksAtTime(t,this.now())}get seconds(){return this.getSecondsAtTime(this.now())}set seconds(t){const e=this.now(),n=this.frequency.timeToTicks(t,e);this.setTicksAtTime(n,e)}getSecondsAtTime(t){t=this.toSeconds(t);const e=this._state.getLastState("stopped",t),n={state:"paused",time:t};this._state.add(n);let i=e,s=0;return this._state.forEachBetween(e.time,t+this.sampleTime,(t=>{let e=i.time;const n=this._tickOffset.get(t.time);n&&n.time>=i.time&&(s=n.seconds,e=n.time),"started"===i.state&&"started"!==t.state&&(s+=t.time-e),i=t})),this._state.remove(n),s}setTicksAtTime(t,e){return e=this.toSeconds(e),this._tickOffset.cancel(e),this._tickOffset.add({seconds:this.frequency.getDurationOfTicks(t,e),ticks:t,time:e}),this}getStateAtTime(t){return t=this.toSeconds(t),this._state.getValueAtTime(t)}getTimeOfTick(t,e=this.now()){const n=this._tickOffset.get(e),i=this._state.get(e),s=Math.max(n.time,i.time),r=this.frequency.getTicksAtTime(s)+t-n.ticks;return this.frequency.getTimeOfTick(r)}forEachTickBetween(t,e,n){let i=this._state.get(t);this._state.forEachBetween(t,e,(e=>{i&&"started"===i.state&&"started"!==e.state&&this.forEachTickBetween(Math.max(i.time,t),e.time-this.sampleTime,n),i=e}));let s=null;if(i&&"started"===i.state){const r=Math.max(i.time,t),o=this.frequency.getTicksAtTime(r),a=o-this.frequency.getTicksAtTime(i.time);let c=Math.ceil(a)-a;c=_l(c,1)?0:c;let l=this.frequency.getTimeOfTick(o+c);for(;l<e;){try{n(l,Math.round(this.getTicksAtTime(l)))}catch(t){s=t;break}l+=this.frequency.getDurationOfTicks(1,l)}}if(s)throw s;return this}dispose(){return super.dispose(),this._state.dispose(),this._tickOffset.dispose(),this.frequency.dispose(),this}}class oh extends Yl{constructor(){super(hl(oh.getDefaults(),arguments,["callback","frequency"])),this.name="Clock",this.callback=El,this._lastUpdate=0,this._state=new Xl("stopped"),this._boundLoop=this._loop.bind(this);const t=hl(oh.getDefaults(),arguments,["callback","frequency"]);this.callback=t.callback,this._tickSource=new rh({context:this.context,frequency:t.frequency,units:t.units}),this._lastUpdate=0,this.frequency=this._tickSource.frequency,Al(this,"frequency"),this._state.setStateAtTime("stopped",0),this.context.on("tick",this._boundLoop)}static getDefaults(){return Object.assign(Yl.getDefaults(),{callback:El,frequency:1,units:"hertz"})}get state(){return this._state.getValueAtTime(this.now())}start(t,e){Wc(this.context);const n=this.toSeconds(t);return this.log("start",n),"started"!==this._state.getValueAtTime(n)&&(this._state.setStateAtTime("started",n),this._tickSource.start(n,e),n<this._lastUpdate&&this.emit("start",n,e)),this}stop(t){const e=this.toSeconds(t);return this.log("stop",e),this._state.cancel(e),this._state.setStateAtTime("stopped",e),this._tickSource.stop(e),e<this._lastUpdate&&this.emit("stop",e),this}pause(t){const e=this.toSeconds(t);return"started"===this._state.getValueAtTime(e)&&(this._state.setStateAtTime("paused",e),this._tickSource.pause(e),e<this._lastUpdate&&this.emit("pause",e)),this}get ticks(){return Math.ceil(this.getTicksAtTime(this.now()))}set ticks(t){this._tickSource.ticks=t}get seconds(){return this._tickSource.seconds}set seconds(t){this._tickSource.seconds=t}getSecondsAtTime(t){return this._tickSource.getSecondsAtTime(t)}setTicksAtTime(t,e){return this._tickSource.setTicksAtTime(t,e),this}getTimeOfTick(t,e=this.now()){return this._tickSource.getTimeOfTick(t,e)}getTicksAtTime(t){return this._tickSource.getTicksAtTime(t)}nextTickTime(t,e){const n=this.toSeconds(e),i=this.getTicksAtTime(n);return this._tickSource.getTimeOfTick(i+t,n)}_loop(){const t=this._lastUpdate,e=this.now();this._lastUpdate=e,this.log("loop",t,e),t!==e&&(this._state.forEachBetween(t,e,(t=>{switch(t.state){case"started":const e=this._tickSource.getTicksAtTime(t.time);this.emit("start",t.time,e);break;case"stopped":0!==t.time&&this.emit("stop",t.time);break;case"paused":this.emit("pause",t.time)}})),this._tickSource.forEachTickBetween(t,e,((t,e)=>{this.callback(t,e)})))}getStateAtTime(t){const e=this.toSeconds(t);return this._state.getValueAtTime(e)}dispose(){return super.dispose(),this.context.off("tick",this._boundLoop),this._tickSource.dispose(),this._state.dispose(),this}}Sl.mixin(oh);class ah extends fl{constructor(){super(),this.name="ToneAudioBuffers",this._buffers=new Map,this._loadingCount=0;const t=hl(ah.getDefaults(),arguments,["urls","onload","baseUrl"],"urls");this.baseUrl=t.baseUrl,Object.keys(t.urls).forEach((e=>{this._loadingCount++;const n=t.urls[e];this.add(e,n,this._bufferLoaded.bind(this,t.onload),t.onerror)}))}static getDefaults(){return{baseUrl:"",onerror:El,onload:El,urls:{}}}has(t){return this._buffers.has(t.toString())}get(t){return Bc(this.has(t),`ToneAudioBuffers has no buffer named: ${t}`),this._buffers.get(t.toString())}_bufferLoaded(t){this._loadingCount--,0===this._loadingCount&&t&&t()}get loaded(){return Array.from(this._buffers).every((([t,e])=>e.loaded))}add(t,e,n=El,i=El){return Kc(e)?this._buffers.set(t.toString(),new kl(this.baseUrl+e,n,i)):this._buffers.set(t.toString(),new kl(e,n,i)),this}dispose(){return super.dispose(),this._buffers.forEach((t=>t.dispose())),this._buffers.clear(),this}}class ch extends Wl{constructor(){super(...arguments),this.name="MidiClass",this.defaultUnits="midi"}_frequencyToUnits(t){return Ll(super._frequencyToUnits(t))}_ticksToUnits(t){return Ll(super._ticksToUnits(t))}_beatsToUnits(t){return Ll(super._beatsToUnits(t))}_secondsToUnits(t){return Ll(super._secondsToUnits(t))}toMidi(){return this.valueOf()}toFrequency(){return Nl(this.toMidi())}transpose(t){return new ch(this.context,this.toMidi()+t)}}function lh(t,e){return new ch(Rl(),t,e)}class hh extends zl{constructor(){super(...arguments),this.name="Ticks",this.defaultUnits="i"}_now(){return this.context.transport.ticks}_beatsToUnits(t){return this._getPPQ()*t}_secondsToUnits(t){return Math.floor(t/(60/this._getBpm())*this._getPPQ())}_ticksToUnits(t){return t}toTicks(){return this.valueOf()}toSeconds(){return this.valueOf()/this._getPPQ()*(60/this._getBpm())}}class uh extends Yl{constructor(){super(...arguments),this.name="Draw",this.expiration=.25,this.anticipation=.008,this._events=new yl,this._boundDrawLoop=this._drawLoop.bind(this),this._animationFrame=-1}schedule(t,e){return this._events.add({callback:t,time:this.toSeconds(e)}),1===this._events.length&&(this._animationFrame=requestAnimationFrame(this._boundDrawLoop)),this}cancel(t){return this._events.cancel(this.toSeconds(t)),this}_drawLoop(){const t=this.context.currentTime;for(;this._events.length&&this._events.peek().time-this.anticipation<=t;){const e=this._events.shift();e&&t-e.time<=this.expiration&&e.callback()}this._events.length>0&&(this._animationFrame=requestAnimationFrame(this._boundDrawLoop))}dispose(){return super.dispose(),this._events.dispose(),cancelAnimationFrame(this._animationFrame),this}}xl((t=>{t.draw=new uh({context:t})})),wl((t=>{t.draw.dispose()}));class dh extends fl{constructor(){super(...arguments),this.name="IntervalTimeline",this._root=null,this._length=0}add(t){Bc(Yc(t.time),"Events must have a time property"),Bc(Yc(t.duration),"Events must have a duration parameter"),t.time=t.time.valueOf();let e=new fh(t.time,t.time+t.duration,t);for(null===this._root?this._root=e:this._root.insert(e),this._length++;null!==e;)e.updateHeight(),e.updateMax(),this._rebalance(e),e=e.parent;return this}remove(t){if(null!==this._root){const e=[];this._root.search(t.time,e);for(const n of e)if(n.event===t){this._removeNode(n),this._length--;break}}return this}get length(){return this._length}cancel(t){return this.forEachFrom(t,(t=>this.remove(t))),this}_setRoot(t){this._root=t,null!==this._root&&(this._root.parent=null)}_replaceNodeInParent(t,e){null!==t.parent?(t.isLeftChild()?t.parent.left=e:t.parent.right=e,this._rebalance(t.parent)):this._setRoot(e)}_removeNode(t){if(null===t.left&&null===t.right)this._replaceNodeInParent(t,null);else if(null===t.right)this._replaceNodeInParent(t,t.left);else if(null===t.left)this._replaceNodeInParent(t,t.right);else{let e,n=null;if(t.getBalance()>0)if(null===t.left.right)e=t.left,e.right=t.right,n=e;else{for(e=t.left.right;null!==e.right;)e=e.right;e.parent&&(e.parent.right=e.left,n=e.parent,e.left=t.left,e.right=t.right)}else if(null===t.right.left)e=t.right,e.left=t.left,n=e;else{for(e=t.right.left;null!==e.left;)e=e.left;e.parent&&(e.parent.left=e.right,n=e.parent,e.left=t.left,e.right=t.right)}null!==t.parent?t.isLeftChild()?t.parent.left=e:t.parent.right=e:this._setRoot(e),n&&this._rebalance(n)}t.dispose()}_rotateLeft(t){const e=t.parent,n=t.isLeftChild(),i=t.right;i&&(t.right=i.left,i.left=t),null!==e?n?e.left=i:e.right=i:this._setRoot(i)}_rotateRight(t){const e=t.parent,n=t.isLeftChild(),i=t.left;i&&(t.left=i.right,i.right=t),null!==e?n?e.left=i:e.right=i:this._setRoot(i)}_rebalance(t){const e=t.getBalance();e>1&&t.left?t.left.getBalance()<0?this._rotateLeft(t.left):this._rotateRight(t):e<-1&&t.right&&(t.right.getBalance()>0?this._rotateRight(t.right):this._rotateLeft(t))}get(t){if(null!==this._root){const e=[];if(this._root.search(t,e),e.length>0){let t=e[0];for(let n=1;n<e.length;n++)e[n].low>t.low&&(t=e[n]);return t.event}}return null}forEach(t){if(null!==this._root){const e=[];this._root.traverse((t=>e.push(t))),e.forEach((e=>{e.event&&t(e.event)}))}return this}forEachAtTime(t,e){if(null!==this._root){const n=[];this._root.search(t,n),n.forEach((t=>{t.event&&e(t.event)}))}return this}forEachFrom(t,e){if(null!==this._root){const n=[];this._root.searchAfter(t,n),n.forEach((t=>{t.event&&e(t.event)}))}return this}dispose(){return super.dispose(),null!==this._root&&this._root.traverse((t=>t.dispose())),this._root=null,this}}class fh{constructor(t,e,n){this._left=null,this._right=null,this.parent=null,this.height=0,this.event=n,this.low=t,this.high=e,this.max=this.high}insert(t){t.low<=this.low?null===this.left?this.left=t:this.left.insert(t):null===this.right?this.right=t:this.right.insert(t)}search(t,e){t>this.max||(null!==this.left&&this.left.search(t,e),this.low<=t&&this.high>t&&e.push(this),this.low>t||null!==this.right&&this.right.search(t,e))}searchAfter(t,e){this.low>=t&&(e.push(this),null!==this.left&&this.left.searchAfter(t,e)),null!==this.right&&this.right.searchAfter(t,e)}traverse(t){t(this),null!==this.left&&this.left.traverse(t),null!==this.right&&this.right.traverse(t)}updateHeight(){null!==this.left&&null!==this.right?this.height=Math.max(this.left.height,this.right.height)+1:null!==this.right?this.height=this.right.height+1:null!==this.left?this.height=this.left.height+1:this.height=0}updateMax(){this.max=this.high,null!==this.left&&(this.max=Math.max(this.max,this.left.max)),null!==this.right&&(this.max=Math.max(this.max,this.right.max))}getBalance(){let t=0;return null!==this.left&&null!==this.right?t=this.left.height-this.right.height:null!==this.left?t=this.left.height+1:null!==this.right&&(t=-(this.right.height+1)),t}isLeftChild(){return null!==this.parent&&this.parent.left===this}get left(){return this._left}set left(t){this._left=t,null!==t&&(t.parent=this),this.updateHeight(),this.updateMax()}get right(){return this._right}set right(t){this._right=t,null!==t&&(t.parent=this),this.updateHeight(),this.updateMax()}dispose(){this.parent=null,this._left=null,this._right=null,this.event=null}}class ph extends ql{constructor(){super(hl(ph.getDefaults(),arguments,["volume"])),this.name="Volume";const t=hl(ph.getDefaults(),arguments,["volume"]);this.input=this.output=new Ql({context:this.context,gain:t.volume,units:"decibels"}),this.volume=this.output.gain,Al(this,"volume"),this._unmutedVolume=t.volume,this.mute=t.mute}static getDefaults(){return Object.assign(ql.getDefaults(),{mute:!1,volume:0})}get mute(){return this.volume.value===-1/0}set mute(t){!this.mute&&t?(this._unmutedVolume=this.volume.value,this.volume.value=-1/0):this.mute&&!t&&(this.volume.value=this._unmutedVolume)}dispose(){return super.dispose(),this.input.dispose(),this.volume.dispose(),this}}class mh extends ql{constructor(){super(hl(mh.getDefaults(),arguments)),this.name="Destination",this.input=new ph({context:this.context}),this.output=new Ql({context:this.context}),this.volume=this.input.volume;const t=hl(mh.getDefaults(),arguments);Kl(this.input,this.output,this.context.rawContext.destination),this.mute=t.mute,this._internalChannels=[this.input,this.context.rawContext.destination,this.output]}static getDefaults(){return Object.assign(ql.getDefaults(),{mute:!1,volume:0})}get mute(){return this.input.mute}set mute(t){this.input.mute=t}chain(...t){return this.input.disconnect(),t.unshift(this.input),t.push(this.output),Kl(...t),this}get maxChannelCount(){return this.context.rawContext.destination.maxChannelCount}dispose(){return super.dispose(),this.volume.dispose(),this}}xl((t=>{t.destination=new mh({context:t})})),wl((t=>{t.destination.dispose()}));class gh extends fl{constructor(t){super(),this.name="TimelineValue",this._timeline=new yl({memory:10}),this._initialValue=t}set(t,e){return this._timeline.add({value:t,time:e}),this}get(t){const e=this._timeline.get(t);return e?e.value:this._initialValue}}class vh{constructor(t,e){this.id=vh._eventId++;const n=Object.assign(vh.getDefaults(),e);this.transport=t,this.callback=n.callback,this._once=n.once,this.time=n.time}static getDefaults(){return{callback:El,once:!1,time:0}}invoke(t){this.callback&&(this.callback(t),this._once&&this.transport.clear(this.id))}dispose(){return this.callback=void 0,this}}vh._eventId=0;class _h extends vh{constructor(t,e){super(t,e),this._currentId=-1,this._nextId=-1,this._nextTick=this.time,this._boundRestart=this._restart.bind(this);const n=Object.assign(_h.getDefaults(),e);this.duration=new hh(t.context,n.duration).valueOf(),this._interval=new hh(t.context,n.interval).valueOf(),this._nextTick=n.time,this.transport.on("start",this._boundRestart),this.transport.on("loopStart",this._boundRestart),this.context=this.transport.context,this._restart()}static getDefaults(){return Object.assign({},vh.getDefaults(),{duration:1/0,interval:1,once:!1})}invoke(t){this._createEvents(t),super.invoke(t)}_createEvents(t){const e=this.transport.getTicksAtTime(t);e>=this.time&&e>=this._nextTick&&this._nextTick+this._interval<this.time+this.duration&&(this._nextTick+=this._interval,this._currentId=this._nextId,this._nextId=this.transport.scheduleOnce(this.invoke.bind(this),new hh(this.context,this._nextTick).toSeconds()))}_restart(t){this.transport.clear(this._currentId),this.transport.clear(this._nextId),this._nextTick=this.time;const e=this.transport.getTicksAtTime(t);e>this.time&&(this._nextTick=this.time+Math.ceil((e-this.time)/this._interval)*this._interval),this._currentId=this.transport.scheduleOnce(this.invoke.bind(this),new hh(this.context,this._nextTick).toSeconds()),this._nextTick+=this._interval,this._nextId=this.transport.scheduleOnce(this.invoke.bind(this),new hh(this.context,this._nextTick).toSeconds())}dispose(){return super.dispose(),this.transport.clear(this._currentId),this.transport.clear(this._nextId),this.transport.off("start",this._boundRestart),this.transport.off("loopStart",this._boundRestart),this}}class yh extends Yl{constructor(){super(hl(yh.getDefaults(),arguments)),this.name="Transport",this._loop=new gh(!1),this._loopStart=0,this._loopEnd=0,this._scheduledEvents={},this._timeline=new yl,this._repeatedEvents=new dh,this._syncedSignals=[],this._swingAmount=0;const t=hl(yh.getDefaults(),arguments);this._ppq=t.ppq,this._clock=new oh({callback:this._processTick.bind(this),context:this.context,frequency:0,units:"bpm"}),this._bindClockEvents(),this.bpm=this._clock.frequency,this._clock.frequency.multiplier=t.ppq,this.bpm.setValueAtTime(t.bpm,0),Al(this,"bpm"),this._timeSignature=t.timeSignature,this._swingTicks=t.ppq/2}static getDefaults(){return Object.assign(Yl.getDefaults(),{bpm:120,loopEnd:"4m",loopStart:0,ppq:192,swing:0,swingSubdivision:"8n",timeSignature:4})}_processTick(t,e){if(this._loop.get(t)&&e>=this._loopEnd&&(this.emit("loopEnd",t),this._clock.setTicksAtTime(this._loopStart,t),e=this._loopStart,this.emit("loopStart",t,this._clock.getSecondsAtTime(t)),this.emit("loop",t)),this._swingAmount>0&&e%this._ppq!=0&&e%(2*this._swingTicks)!=0){const n=e%(2*this._swingTicks)/(2*this._swingTicks),i=Math.sin(n*Math.PI)*this._swingAmount;t+=new hh(this.context,2*this._swingTicks/3).toSeconds()*i}this._timeline.forEachAtTime(e,(e=>e.invoke(t)))}schedule(t,e){const n=new vh(this,{callback:t,time:new zl(this.context,e).toTicks()});return this._addEvent(n,this._timeline)}scheduleRepeat(t,e,n,i=1/0){const s=new _h(this,{callback:t,duration:new Vl(this.context,i).toTicks(),interval:new Vl(this.context,e).toTicks(),time:new zl(this.context,n).toTicks()});return this._addEvent(s,this._repeatedEvents)}scheduleOnce(t,e){const n=new vh(this,{callback:t,once:!0,time:new zl(this.context,e).toTicks()});return this._addEvent(n,this._timeline)}clear(t){if(this._scheduledEvents.hasOwnProperty(t)){const e=this._scheduledEvents[t.toString()];e.timeline.remove(e.event),e.event.dispose(),delete this._scheduledEvents[t.toString()]}return this}_addEvent(t,e){return this._scheduledEvents[t.id.toString()]={event:t,timeline:e},e.add(t),t.id}cancel(t=0){const e=this.toTicks(t);return this._timeline.forEachFrom(e,(t=>this.clear(t.id))),this._repeatedEvents.forEachFrom(e,(t=>this.clear(t.id))),this}_bindClockEvents(){this._clock.on("start",((t,e)=>{e=new hh(this.context,e).toSeconds(),this.emit("start",t,e)})),this._clock.on("stop",(t=>{this.emit("stop",t)})),this._clock.on("pause",(t=>{this.emit("pause",t)}))}get state(){return this._clock.getStateAtTime(this.now())}start(t,e){let n;return Yc(e)&&(n=this.toTicks(e)),this._clock.start(t,n),this}stop(t){return this._clock.stop(t),this}pause(t){return this._clock.pause(t),this}toggle(t){return t=this.toSeconds(t),"started"!==this._clock.getStateAtTime(t)?this.start(t):this.stop(t),this}get timeSignature(){return this._timeSignature}set timeSignature(t){qc(t)&&(t=t[0]/t[1]*4),this._timeSignature=t}get loopStart(){return new Vl(this.context,this._loopStart,"i").toSeconds()}set loopStart(t){this._loopStart=this.toTicks(t)}get loopEnd(){return new Vl(this.context,this._loopEnd,"i").toSeconds()}set loopEnd(t){this._loopEnd=this.toTicks(t)}get loop(){return this._loop.get(this.now())}set loop(t){this._loop.set(t,this.now())}setLoopPoints(t,e){return this.loopStart=t,this.loopEnd=e,this}get swing(){return this._swingAmount}set swing(t){this._swingAmount=t}get swingSubdivision(){return new hh(this.context,this._swingTicks).toNotation()}set swingSubdivision(t){this._swingTicks=this.toTicks(t)}get position(){const t=this.now(),e=this._clock.getTicksAtTime(t);return new hh(this.context,e).toBarsBeatsSixteenths()}set position(t){const e=this.toTicks(t);this.ticks=e}get seconds(){return this._clock.seconds}set seconds(t){const e=this.now(),n=this._clock.frequency.timeToTicks(t,e);this.ticks=n}get progress(){if(this.loop){const t=this.now();return(this._clock.getTicksAtTime(t)-this._loopStart)/(this._loopEnd-this._loopStart)}return 0}get ticks(){return this._clock.ticks}set ticks(t){if(this._clock.ticks!==t){const e=this.now();if("started"===this.state){const n=this._clock.getTicksAtTime(e),i=e+this._clock.frequency.getDurationOfTicks(Math.ceil(n)-n,e);this.emit("stop",i),this._clock.setTicksAtTime(t,i),this.emit("start",i,this._clock.getSecondsAtTime(i))}else this._clock.setTicksAtTime(t,e)}}getTicksAtTime(t){return Math.round(this._clock.getTicksAtTime(t))}getSecondsAtTime(t){return this._clock.getSecondsAtTime(t)}get PPQ(){return this._clock.frequency.multiplier}set PPQ(t){this._clock.frequency.multiplier=t}nextSubdivision(t){if(t=this.toTicks(t),"started"!==this.state)return 0;{const e=this.now(),n=t-this.getTicksAtTime(e)%t;return this._clock.nextTickTime(n,e)}}syncSignal(t,e){if(!e){const n=this.now();if(0!==t.getValueAtTime(n)){const i=1/(60/this.bpm.getValueAtTime(n)/this.PPQ);e=t.getValueAtTime(n)/i}else e=0}const n=new Ql(e);return this.bpm.connect(n),n.connect(t._param),this._syncedSignals.push({initial:t.value,ratio:n,signal:t}),t.value=0,this}unsyncSignal(t){for(let e=this._syncedSignals.length-1;e>=0;e--){const n=this._syncedSignals[e];n.signal===t&&(n.ratio.dispose(),n.signal.value=n.initial,this._syncedSignals.splice(e,1))}return this}dispose(){return super.dispose(),this._clock.dispose(),Ol(this,"bpm"),this._timeline.dispose(),this._repeatedEvents.dispose(),this}}Sl.mixin(yh),xl((t=>{t.transport=new yh({context:t})})),wl((t=>{t.transport.dispose()}));class bh extends ql{constructor(t){super(t),this.input=void 0,this._state=new Xl("stopped"),this._synced=!1,this._scheduled=[],this._syncedStart=El,this._syncedStop=El,this._state.memory=100,this._state.increasing=!0,this._volume=this.output=new ph({context:this.context,mute:t.mute,volume:t.volume}),this.volume=this._volume.volume,Al(this,"volume"),this.onstop=t.onstop}static getDefaults(){return Object.assign(ql.getDefaults(),{mute:!1,onstop:El,volume:0})}get state(){return this._synced?"started"===this.context.transport.state?this._state.getValueAtTime(this.context.transport.seconds):"stopped":this._state.getValueAtTime(this.now())}get mute(){return this._volume.mute}set mute(t){this._volume.mute=t}_clampToCurrentTime(t){return this._synced?t:Math.max(t,this.context.currentTime)}start(t,e,n){let i=zc(t)&&this._synced?this.context.transport.seconds:this.toSeconds(t);if(i=this._clampToCurrentTime(i),this._synced||"started"!==this._state.getValueAtTime(i))if(this.log("start",i),this._state.setStateAtTime("started",i),this._synced){const t=this._state.get(i);t&&(t.offset=this.toSeconds(ul(e,0)),t.duration=n?this.toSeconds(n):void 0);const s=this.context.transport.schedule((t=>{this._start(t,e,n)}),i);this._scheduled.push(s),"started"===this.context.transport.state&&this.context.transport.getSecondsAtTime(this.immediate())>i&&this._syncedStart(this.now(),this.context.transport.seconds)}else Wc(this.context),this._start(i,e,n);else Bc(ml(i,this._state.get(i).time),"Start time must be strictly greater than previous start time"),this._state.cancel(i),this._state.setStateAtTime("started",i),this.log("restart",i),this.restart(i,e,n);return this}stop(t){let e=zc(t)&&this._synced?this.context.transport.seconds:this.toSeconds(t);if(e=this._clampToCurrentTime(e),"started"===this._state.getValueAtTime(e)||Yc(this._state.getNextState("started",e))){if(this.log("stop",e),this._synced){const t=this.context.transport.schedule(this._stop.bind(this),e);this._scheduled.push(t)}else this._stop(e);this._state.cancel(e),this._state.setStateAtTime("stopped",e)}return this}restart(t,e,n){return t=this.toSeconds(t),"started"===this._state.getValueAtTime(t)&&(this._state.cancel(t),this._restart(t,e,n)),this}sync(){return this._synced||(this._synced=!0,this._syncedStart=(t,e)=>{if(e>0){const n=this._state.get(e);if(n&&"started"===n.state&&n.time!==e){const i=e-this.toSeconds(n.time);let s;n.duration&&(s=this.toSeconds(n.duration)-i),this._start(t,this.toSeconds(n.offset)+i,s)}}},this._syncedStop=t=>{const e=this.context.transport.getSecondsAtTime(Math.max(t-this.sampleTime,0));"started"===this._state.getValueAtTime(e)&&this._stop(t)},this.context.transport.on("start",this._syncedStart),this.context.transport.on("loopStart",this._syncedStart),this.context.transport.on("stop",this._syncedStop),this.context.transport.on("pause",this._syncedStop),this.context.transport.on("loopEnd",this._syncedStop)),this}unsync(){return this._synced&&(this.context.transport.off("stop",this._syncedStop),this.context.transport.off("pause",this._syncedStop),this.context.transport.off("loopEnd",this._syncedStop),this.context.transport.off("start",this._syncedStart),this.context.transport.off("loopStart",this._syncedStart)),this._synced=!1,this._scheduled.forEach((t=>this.context.transport.clear(t))),this._scheduled=[],this._state.cancel(0),this._stop(0),this}dispose(){return super.dispose(),this.onstop=El,this.unsync(),this._volume.dispose(),this._state.dispose(),this}}class xh extends Jl{constructor(){super(hl(xh.getDefaults(),arguments,["url","onload"])),this.name="ToneBufferSource",this._source=this.context.createBufferSource(),this._internalChannels=[this._source],this._sourceStarted=!1,this._sourceStopped=!1;const t=hl(xh.getDefaults(),arguments,["url","onload"]);Zl(this._source,this._gainNode),this._source.onended=()=>this._stopSource(),this.playbackRate=new Ul({context:this.context,param:this._source.playbackRate,units:"positive",value:t.playbackRate}),this.loop=t.loop,this.loopStart=t.loopStart,this.loopEnd=t.loopEnd,this._buffer=new kl(t.url,t.onload,t.onerror),this._internalChannels.push(this._source)}static getDefaults(){return Object.assign(Jl.getDefaults(),{url:new kl,loop:!1,loopEnd:0,loopStart:0,onload:El,onerror:El,playbackRate:1})}get fadeIn(){return this._fadeIn}set fadeIn(t){this._fadeIn=t}get fadeOut(){return this._fadeOut}set fadeOut(t){this._fadeOut=t}get curve(){return this._curve}set curve(t){this._curve=t}start(t,e,n,i=1){Bc(this.buffer.loaded,"buffer is either not set or not loaded");const s=this.toSeconds(t);this._startGain(s,i),e=this.loop?ul(e,this.loopStart):ul(e,0);let r=Math.max(this.toSeconds(e),0);if(this.loop){const t=this.toSeconds(this.loopEnd)||this.buffer.duration,e=this.toSeconds(this.loopStart),n=t-e;gl(r,t)&&(r=(r-e)%n+e),_l(r,this.buffer.duration)&&(r=0)}if(this._source.buffer=this.buffer.get(),this._source.loopEnd=this.toSeconds(this.loopEnd)||this.buffer.duration,vl(r,this.buffer.duration)&&(this._sourceStarted=!0,this._source.start(s,r)),Yc(n)){let t=this.toSeconds(n);t=Math.max(t,0),this.stop(s+t)}return this}_stopSource(t){!this._sourceStopped&&this._sourceStarted&&(this._sourceStopped=!0,this._source.stop(this.toSeconds(t)),this._onended())}get loopStart(){return this._source.loopStart}set loopStart(t){this._source.loopStart=this.toSeconds(t)}get loopEnd(){return this._source.loopEnd}set loopEnd(t){this._source.loopEnd=this.toSeconds(t)}get buffer(){return this._buffer}set buffer(t){this._buffer.set(t)}get loop(){return this._source.loop}set loop(t){this._source.loop=t,this._sourceStarted&&this.cancelStop()}dispose(){return super.dispose(),this._source.onended=null,this._source.disconnect(),this._buffer.dispose(),this.playbackRate.dispose(),this}}class Ch extends bh{constructor(){super(hl(Ch.getDefaults(),arguments,["type"])),this.name="Noise",this._source=null;const t=hl(Ch.getDefaults(),arguments,["type"]);this._playbackRate=t.playbackRate,this.type=t.type,this._fadeIn=t.fadeIn,this._fadeOut=t.fadeOut}static getDefaults(){return Object.assign(bh.getDefaults(),{fadeIn:0,fadeOut:0,playbackRate:1,type:"white"})}get type(){return this._type}set type(t){if(Bc(t in Th,"Noise: invalid type: "+t),this._type!==t&&(this._type=t,"started"===this.state)){const t=this.now();this._stop(t),this._start(t)}}get playbackRate(){return this._playbackRate}set playbackRate(t){this._playbackRate=t,this._source&&(this._source.playbackRate.value=t)}_start(t){const e=Th[this._type];this._source=new xh({url:e,context:this.context,fadeIn:this._fadeIn,fadeOut:this._fadeOut,loop:!0,onended:()=>this.onstop(this),playbackRate:this._playbackRate}).connect(this.output),this._source.start(this.toSeconds(t),Math.random()*(e.duration-.001))}_stop(t){this._source&&(this._source.stop(this.toSeconds(t)),this._source=null)}get fadeIn(){return this._fadeIn}set fadeIn(t){this._fadeIn=t,this._source&&(this._source.fadeIn=this._fadeIn)}get fadeOut(){return this._fadeOut}set fadeOut(t){this._fadeOut=t,this._source&&(this._source.fadeOut=this._fadeOut)}_restart(t){this._stop(t),this._start(t)}dispose(){return super.dispose(),this._source&&this._source.disconnect(),this}}const wh=220500,Sh={brown:null,pink:null,white:null},Th={get brown(){if(!Sh.brown){const t=[];for(let e=0;e<2;e++){const n=new Float32Array(wh);t[e]=n;let i=0;for(let t=0;t<wh;t++){const e=2*Math.random()-1;n[t]=(i+.02*e)/1.02,i=n[t],n[t]*=3.5}}Sh.brown=(new kl).fromArray(t)}return Sh.brown},get pink(){if(!Sh.pink){const t=[];for(let e=0;e<2;e++){const n=new Float32Array(wh);let i,s,r,o,a,c,l;t[e]=n,i=s=r=o=a=c=l=0;for(let t=0;t<wh;t++){const e=2*Math.random()-1;i=.99886*i+.0555179*e,s=.99332*s+.0750759*e,r=.969*r+.153852*e,o=.8665*o+.3104856*e,a=.55*a+.5329522*e,c=-.7616*c-.016898*e,n[t]=i+s+r+o+a+c+l+.5362*e,n[t]*=.11,l=.115926*e}}Sh.pink=(new kl).fromArray(t)}return Sh.pink},get white(){if(!Sh.white){const t=[];for(let e=0;e<2;e++){const n=new Float32Array(wh);t[e]=n;for(let t=0;t<wh;t++)n[t]=2*Math.random()-1}Sh.white=(new kl).fromArray(t)}return Sh.white}};function Mh(t,e){return el(this,void 0,void 0,(function*(){const n=e/t.context.sampleRate,i=new Pl(1,n,t.context.sampleRate);new t.constructor(Object.assign(t.get(),{frequency:2/n,detune:0,context:i})).toDestination().start(0);return(yield i.render()).getChannelData(0)}))}class Ah extends Jl{constructor(){super(hl(Ah.getDefaults(),arguments,["frequency","type"])),this.name="ToneOscillatorNode",this._oscillator=this.context.createOscillator(),this._internalChannels=[this._oscillator];const t=hl(Ah.getDefaults(),arguments,["frequency","type"]);Zl(this._oscillator,this._gainNode),this.type=t.type,this.frequency=new Ul({context:this.context,param:this._oscillator.frequency,units:"frequency",value:t.frequency}),this.detune=new Ul({context:this.context,param:this._oscillator.detune,units:"cents",value:t.detune}),Al(this,["frequency","detune"])}static getDefaults(){return Object.assign(Jl.getDefaults(),{detune:0,frequency:440,type:"sine"})}start(t){const e=this.toSeconds(t);return this.log("start",e),this._startGain(e),this._oscillator.start(e),this}_stopSource(t){this._oscillator.stop(t)}setPeriodicWave(t){return this._oscillator.setPeriodicWave(t),this}get type(){return this._oscillator.type}set type(t){this._oscillator.type=t}dispose(){return super.dispose(),"started"===this.state&&this.stop(),this._oscillator.disconnect(),this.frequency.dispose(),this.detune.dispose(),this}}class Oh extends bh{constructor(){super(hl(Oh.getDefaults(),arguments,["frequency","type"])),this.name="Oscillator",this._oscillator=null;const t=hl(Oh.getDefaults(),arguments,["frequency","type"]);this.frequency=new eh({context:this.context,units:"frequency",value:t.frequency}),Al(this,"frequency"),this.detune=new eh({context:this.context,units:"cents",value:t.detune}),Al(this,"detune"),this._partials=t.partials,this._partialCount=t.partialCount,this._type=t.type,t.partialCount&&"custom"!==t.type&&(this._type=this.baseType+t.partialCount.toString()),this.phase=t.phase}static getDefaults(){return Object.assign(bh.getDefaults(),{detune:0,frequency:440,partialCount:0,partials:[],phase:0,type:"sine"})}_start(t){const e=this.toSeconds(t),n=new Ah({context:this.context,onended:()=>this.onstop(this)});this._oscillator=n,this._wave?this._oscillator.setPeriodicWave(this._wave):this._oscillator.type=this._type,this._oscillator.connect(this.output),this.frequency.connect(this._oscillator.frequency),this.detune.connect(this._oscillator.detune),this._oscillator.start(e)}_stop(t){const e=this.toSeconds(t);this._oscillator&&this._oscillator.stop(e)}_restart(t){const e=this.toSeconds(t);return this.log("restart",e),this._oscillator&&this._oscillator.cancelStop(),this._state.cancel(e),this}syncFrequency(){return this.context.transport.syncSignal(this.frequency),this}unsyncFrequency(){return this.context.transport.unsyncSignal(this.frequency),this}_getCachedPeriodicWave(){if("custom"===this._type){return Oh._periodicWaveCache.find((t=>{return t.phase===this._phase&&(e=t.partials,n=this._partials,e.length===n.length&&e.every(((t,e)=>n[e]===t)));var e,n}))}{const t=Oh._periodicWaveCache.find((t=>t.type===this._type&&t.phase===this._phase));return this._partialCount=t?t.partialCount:this._partialCount,t}}get type(){return this._type}set type(t){this._type=t;const e=-1!==["sine","square","sawtooth","triangle"].indexOf(t);if(0===this._phase&&e)this._wave=void 0,this._partialCount=0,null!==this._oscillator&&(this._oscillator.type=t);else{const e=this._getCachedPeriodicWave();if(Yc(e)){const{partials:t,wave:n}=e;this._wave=n,this._partials=t,null!==this._oscillator&&this._oscillator.setPeriodicWave(this._wave)}else{const[e,n]=this._getRealImaginary(t,this._phase),i=this.context.createPeriodicWave(e,n);this._wave=i,null!==this._oscillator&&this._oscillator.setPeriodicWave(this._wave),Oh._periodicWaveCache.push({imag:n,partialCount:this._partialCount,partials:this._partials,phase:this._phase,real:e,type:this._type,wave:this._wave}),Oh._periodicWaveCache.length>100&&Oh._periodicWaveCache.shift()}}}get baseType(){return this._type.replace(this.partialCount.toString(),"")}set baseType(t){this.partialCount&&"custom"!==this._type&&"custom"!==t?this.type=t+this.partialCount:this.type=t}get partialCount(){return this._partialCount}set partialCount(t){Vc(t,0);let e=this._type;const n=/^(sine|triangle|square|sawtooth)(\d+)$/.exec(this._type);if(n&&(e=n[1]),"custom"!==this._type)this.type=0===t?e:e+t.toString();else{const e=new Float32Array(t);this._partials.forEach(((t,n)=>e[n]=t)),this._partials=Array.from(e),this.type=this._type}}_getRealImaginary(t,e){let n=2048;const i=new Float32Array(n),s=new Float32Array(n);let r=1;if("custom"===t){if(r=this._partials.length+1,this._partialCount=this._partials.length,n=r,0===this._partials.length)return[i,s]}else{const e=/^(sine|triangle|square|sawtooth)(\d+)$/.exec(t);e?(r=parseInt(e[2],10)+1,this._partialCount=parseInt(e[2],10),t=e[1],r=Math.max(r,2),n=r):this._partialCount=0,this._partials=[]}for(let o=1;o<n;++o){const n=2/(o*Math.PI);let a;switch(t){case"sine":a=o<=r?1:0,this._partials[o-1]=a;break;case"square":a=1&o?2*n:0,this._partials[o-1]=a;break;case"sawtooth":a=n*(1&o?1:-1),this._partials[o-1]=a;break;case"triangle":a=1&o?n*n*2*(o-1>>1&1?-1:1):0,this._partials[o-1]=a;break;case"custom":a=this._partials[o-1];break;default:throw new TypeError("Oscillator: invalid type: "+t)}0!==a?(i[o]=-a*Math.sin(e*o),s[o]=a*Math.cos(e*o)):(i[o]=0,s[o]=0)}return[i,s]}_inverseFFT(t,e,n){let i=0;const s=t.length;for(let r=0;r<s;r++)i+=t[r]*Math.cos(r*n)+e[r]*Math.sin(r*n);return i}getInitialValue(){const[t,e]=this._getRealImaginary(this._type,0);let n=0;const i=2*Math.PI;for(let s=0;s<32;s++)n=Math.max(this._inverseFFT(t,e,s/32*i),n);return s=-this._inverseFFT(t,e,this._phase)/n,r=-1,o=1,Math.max(Math.min(s,o),r);var s,r,o}get partials(){return this._partials.slice(0,this.partialCount)}set partials(t){this._partials=t,this._partialCount=this._partials.length,t.length&&(this.type="custom")}get phase(){return this._phase*(180/Math.PI)}set phase(t){this._phase=t*Math.PI/180,this.type=this._type}asArray(t=1024){return el(this,void 0,void 0,(function*(){return Mh(this,t)}))}dispose(){return super.dispose(),null!==this._oscillator&&this._oscillator.dispose(),this._wave=void 0,this.frequency.dispose(),this.detune.dispose(),this}}Oh._periodicWaveCache=[];class Eh extends ql{constructor(){super(Object.assign(hl(Eh.getDefaults(),arguments,["context"])))}connect(t,e=0,n=0){return nh(this,t,e,n),this}}class kh extends Eh{constructor(){super(Object.assign(hl(kh.getDefaults(),arguments,["mapping","length"]))),this.name="WaveShaper",this._shaper=this.context.createWaveShaper(),this.input=this._shaper,this.output=this._shaper;const t=hl(kh.getDefaults(),arguments,["mapping","length"]);qc(t.mapping)||t.mapping instanceof Float32Array?this.curve=Float32Array.from(t.mapping):"function"==typeof t.mapping&&this.setMap(t.mapping,t.length)}static getDefaults(){return Object.assign(eh.getDefaults(),{length:1024})}setMap(t,e=1024){const n=new Float32Array(e);for(let i=0,s=e;i<s;i++){const e=i/(s-1)*2-1;n[i]=t(e,i)}return this.curve=n,this}get curve(){return this._shaper.curve}set curve(t){this._shaper.curve=t}get oversample(){return this._shaper.oversample}set oversample(t){Bc(["none","2x","4x"].some((e=>e.includes(t))),"oversampling must be either 'none', '2x', or '4x'"),this._shaper.oversample=t}dispose(){return super.dispose(),this._shaper.disconnect(),this}}class Ph extends Eh{constructor(){super(...arguments),this.name="AudioToGain",this._norm=new kh({context:this.context,mapping:t=>(t+1)/2}),this.input=this._norm,this.output=this._norm}dispose(){return super.dispose(),this._norm.dispose(),this}}class Ih extends eh{constructor(){super(Object.assign(hl(Ih.getDefaults(),arguments,["value"]))),this.name="Multiply",this.override=!1;const t=hl(Ih.getDefaults(),arguments,["value"]);this._mult=this.input=this.output=new Ql({context:this.context,minValue:t.minValue,maxValue:t.maxValue}),this.factor=this._param=this._mult.gain,this.factor.setValueAtTime(t.value,0)}static getDefaults(){return Object.assign(eh.getDefaults(),{value:0})}dispose(){return super.dispose(),this._mult.dispose(),this}}class Dh extends bh{constructor(){super(hl(Dh.getDefaults(),arguments,["frequency","type","modulationType"])),this.name="AMOscillator",this._modulationScale=new Ph({context:this.context}),this._modulationNode=new Ql({context:this.context});const t=hl(Dh.getDefaults(),arguments,["frequency","type","modulationType"]);this._carrier=new Oh({context:this.context,detune:t.detune,frequency:t.frequency,onstop:()=>this.onstop(this),phase:t.phase,type:t.type}),this.frequency=this._carrier.frequency,this.detune=this._carrier.detune,this._modulator=new Oh({context:this.context,phase:t.phase,type:t.modulationType}),this.harmonicity=new Ih({context:this.context,units:"positive",value:t.harmonicity}),this.frequency.chain(this.harmonicity,this._modulator.frequency),this._modulator.chain(this._modulationScale,this._modulationNode.gain),this._carrier.chain(this._modulationNode,this.output),Al(this,["frequency","detune","harmonicity"])}static getDefaults(){return Object.assign(Oh.getDefaults(),{harmonicity:1,modulationType:"square"})}_start(t){this._modulator.start(t),this._carrier.start(t)}_stop(t){this._modulator.stop(t),this._carrier.stop(t)}_restart(t){this._modulator.restart(t),this._carrier.restart(t)}get type(){return this._carrier.type}set type(t){this._carrier.type=t}get baseType(){return this._carrier.baseType}set baseType(t){this._carrier.baseType=t}get partialCount(){return this._carrier.partialCount}set partialCount(t){this._carrier.partialCount=t}get modulationType(){return this._modulator.type}set modulationType(t){this._modulator.type=t}get phase(){return this._carrier.phase}set phase(t){this._carrier.phase=t,this._modulator.phase=t}get partials(){return this._carrier.partials}set partials(t){this._carrier.partials=t}asArray(t=1024){return el(this,void 0,void 0,(function*(){return Mh(this,t)}))}dispose(){return super.dispose(),this.frequency.dispose(),this.detune.dispose(),this.harmonicity.dispose(),this._carrier.dispose(),this._modulator.dispose(),this._modulationNode.dispose(),this._modulationScale.dispose(),this}}class Rh extends bh{constructor(){super(hl(Rh.getDefaults(),arguments,["frequency","type","modulationType"])),this.name="FMOscillator",this._modulationNode=new Ql({context:this.context,gain:0});const t=hl(Rh.getDefaults(),arguments,["frequency","type","modulationType"]);this._carrier=new Oh({context:this.context,detune:t.detune,frequency:0,onstop:()=>this.onstop(this),phase:t.phase,type:t.type}),this.detune=this._carrier.detune,this.frequency=new eh({context:this.context,units:"frequency",value:t.frequency}),this._modulator=new Oh({context:this.context,phase:t.phase,type:t.modulationType}),this.harmonicity=new Ih({context:this.context,units:"positive",value:t.harmonicity}),this.modulationIndex=new Ih({context:this.context,units:"positive",value:t.modulationIndex}),this.frequency.connect(this._carrier.frequency),this.frequency.chain(this.harmonicity,this._modulator.frequency),this.frequency.chain(this.modulationIndex,this._modulationNode),this._modulator.connect(this._modulationNode.gain),this._modulationNode.connect(this._carrier.frequency),this._carrier.connect(this.output),this.detune.connect(this._modulator.detune),Al(this,["modulationIndex","frequency","detune","harmonicity"])}static getDefaults(){return Object.assign(Oh.getDefaults(),{harmonicity:1,modulationIndex:2,modulationType:"square"})}_start(t){this._modulator.start(t),this._carrier.start(t)}_stop(t){this._modulator.stop(t),this._carrier.stop(t)}_restart(t){return this._modulator.restart(t),this._carrier.restart(t),this}get type(){return this._carrier.type}set type(t){this._carrier.type=t}get baseType(){return this._carrier.baseType}set baseType(t){this._carrier.baseType=t}get partialCount(){return this._carrier.partialCount}set partialCount(t){this._carrier.partialCount=t}get modulationType(){return this._modulator.type}set modulationType(t){this._modulator.type=t}get phase(){return this._carrier.phase}set phase(t){this._carrier.phase=t,this._modulator.phase=t}get partials(){return this._carrier.partials}set partials(t){this._carrier.partials=t}asArray(t=1024){return el(this,void 0,void 0,(function*(){return Mh(this,t)}))}dispose(){return super.dispose(),this.frequency.dispose(),this.harmonicity.dispose(),this._carrier.dispose(),this._modulator.dispose(),this._modulationNode.dispose(),this.modulationIndex.dispose(),this}}class jh extends bh{constructor(){super(hl(jh.getDefaults(),arguments,["frequency","width"])),this.name="PulseOscillator",this._widthGate=new Ql({context:this.context,gain:0}),this._thresh=new kh({context:this.context,mapping:t=>t<=0?-1:1});const t=hl(jh.getDefaults(),arguments,["frequency","width"]);this.width=new eh({context:this.context,units:"audioRange",value:t.width}),this._triangle=new Oh({context:this.context,detune:t.detune,frequency:t.frequency,onstop:()=>this.onstop(this),phase:t.phase,type:"triangle"}),this.frequency=this._triangle.frequency,this.detune=this._triangle.detune,this._triangle.chain(this._thresh,this.output),this.width.chain(this._widthGate,this._thresh),Al(this,["width","frequency","detune"])}static getDefaults(){return Object.assign(bh.getDefaults(),{detune:0,frequency:440,phase:0,type:"pulse",width:.2})}_start(t){t=this.toSeconds(t),this._triangle.start(t),this._widthGate.gain.setValueAtTime(1,t)}_stop(t){t=this.toSeconds(t),this._triangle.stop(t),this._widthGate.gain.cancelScheduledValues(t),this._widthGate.gain.setValueAtTime(0,t)}_restart(t){this._triangle.restart(t),this._widthGate.gain.cancelScheduledValues(t),this._widthGate.gain.setValueAtTime(1,t)}get phase(){return this._triangle.phase}set phase(t){this._triangle.phase=t}get type(){return"pulse"}get baseType(){return"pulse"}get partials(){return[]}get partialCount(){return 0}set carrierType(t){this._triangle.type=t}asArray(t=1024){return el(this,void 0,void 0,(function*(){return Mh(this,t)}))}dispose(){return super.dispose(),this._triangle.dispose(),this.width.dispose(),this._widthGate.dispose(),this._thresh.dispose(),this}}class $h extends bh{constructor(){super(hl($h.getDefaults(),arguments,["frequency","type","spread"])),this.name="FatOscillator",this._oscillators=[];const t=hl($h.getDefaults(),arguments,["frequency","type","spread"]);this.frequency=new eh({context:this.context,units:"frequency",value:t.frequency}),this.detune=new eh({context:this.context,units:"cents",value:t.detune}),this._spread=t.spread,this._type=t.type,this._phase=t.phase,this._partials=t.partials,this._partialCount=t.partialCount,this.count=t.count,Al(this,["frequency","detune"])}static getDefaults(){return Object.assign(Oh.getDefaults(),{count:3,spread:20,type:"sawtooth"})}_start(t){t=this.toSeconds(t),this._forEach((e=>e.start(t)))}_stop(t){t=this.toSeconds(t),this._forEach((e=>e.stop(t)))}_restart(t){this._forEach((e=>e.restart(t)))}_forEach(t){for(let e=0;e<this._oscillators.length;e++)t(this._oscillators[e],e)}get type(){return this._type}set type(t){this._type=t,this._forEach((e=>e.type=t))}get spread(){return this._spread}set spread(t){if(this._spread=t,this._oscillators.length>1){const e=-t/2,n=t/(this._oscillators.length-1);this._forEach(((t,i)=>t.detune.value=e+n*i))}}get count(){return this._oscillators.length}set count(t){if(Vc(t,1),this._oscillators.length!==t){this._forEach((t=>t.dispose())),this._oscillators=[];for(let e=0;e<t;e++){const n=new Oh({context:this.context,volume:-6-1.1*t,type:this._type,phase:this._phase+e/t*360,partialCount:this._partialCount,onstop:0===e?()=>this.onstop(this):El});"custom"===this.type&&(n.partials=this._partials),this.frequency.connect(n.frequency),this.detune.connect(n.detune),n.detune.overridden=!1,n.connect(this.output),this._oscillators[e]=n}this.spread=this._spread,"started"===this.state&&this._forEach((t=>t.start()))}}get phase(){return this._phase}set phase(t){this._phase=t,this._forEach(((t,e)=>t.phase=this._phase+e/this.count*360))}get baseType(){return this._oscillators[0].baseType}set baseType(t){this._forEach((e=>e.baseType=t)),this._type=this._oscillators[0].type}get partials(){return this._oscillators[0].partials}set partials(t){this._partials=t,this._partialCount=this._partials.length,t.length&&(this._type="custom",this._forEach((e=>e.partials=t)))}get partialCount(){return this._oscillators[0].partialCount}set partialCount(t){this._partialCount=t,this._forEach((e=>e.partialCount=t)),this._type=this._oscillators[0].type}asArray(t=1024){return el(this,void 0,void 0,(function*(){return Mh(this,t)}))}dispose(){return super.dispose(),this.frequency.dispose(),this.detune.dispose(),this._forEach((t=>t.dispose())),this}}class Lh extends bh{constructor(){super(hl(Lh.getDefaults(),arguments,["frequency","modulationFrequency"])),this.name="PWMOscillator",this.sourceType="pwm",this._scale=new Ih({context:this.context,value:2});const t=hl(Lh.getDefaults(),arguments,["frequency","modulationFrequency"]);this._pulse=new jh({context:this.context,frequency:t.modulationFrequency}),this._pulse.carrierType="sine",this.modulationFrequency=this._pulse.frequency,this._modulator=new Oh({context:this.context,detune:t.detune,frequency:t.frequency,onstop:()=>this.onstop(this),phase:t.phase}),this.frequency=this._modulator.frequency,this.detune=this._modulator.detune,this._modulator.chain(this._scale,this._pulse.width),this._pulse.connect(this.output),Al(this,["modulationFrequency","frequency","detune"])}static getDefaults(){return Object.assign(bh.getDefaults(),{detune:0,frequency:440,modulationFrequency:.4,phase:0,type:"pwm"})}_start(t){t=this.toSeconds(t),this._modulator.start(t),this._pulse.start(t)}_stop(t){t=this.toSeconds(t),this._modulator.stop(t),this._pulse.stop(t)}_restart(t){this._modulator.restart(t),this._pulse.restart(t)}get type(){return"pwm"}get baseType(){return"pwm"}get partials(){return[]}get partialCount(){return 0}get phase(){return this._modulator.phase}set phase(t){this._modulator.phase=t}asArray(t=1024){return el(this,void 0,void 0,(function*(){return Mh(this,t)}))}dispose(){return super.dispose(),this._pulse.dispose(),this._scale.dispose(),this._modulator.dispose(),this}}const Fh={am:Dh,fat:$h,fm:Rh,oscillator:Oh,pulse:jh,pwm:Lh};class Nh extends bh{constructor(){super(hl(Nh.getDefaults(),arguments,["frequency","type"])),this.name="OmniOscillator";const t=hl(Nh.getDefaults(),arguments,["frequency","type"]);this.frequency=new eh({context:this.context,units:"frequency",value:t.frequency}),this.detune=new eh({context:this.context,units:"cents",value:t.detune}),Al(this,["frequency","detune"]),this.set(t)}static getDefaults(){return Object.assign(Oh.getDefaults(),Rh.getDefaults(),Dh.getDefaults(),$h.getDefaults(),jh.getDefaults(),Lh.getDefaults())}_start(t){this._oscillator.start(t)}_stop(t){this._oscillator.stop(t)}_restart(t){return this._oscillator.restart(t),this}get type(){let t="";return["am","fm","fat"].some((t=>this._sourceType===t))&&(t=this._sourceType),t+this._oscillator.type}set type(t){"fm"===t.substr(0,2)?(this._createNewOscillator("fm"),this._oscillator=this._oscillator,this._oscillator.type=t.substr(2)):"am"===t.substr(0,2)?(this._createNewOscillator("am"),this._oscillator=this._oscillator,this._oscillator.type=t.substr(2)):"fat"===t.substr(0,3)?(this._createNewOscillator("fat"),this._oscillator=this._oscillator,this._oscillator.type=t.substr(3)):"pwm"===t?(this._createNewOscillator("pwm"),this._oscillator=this._oscillator):"pulse"===t?this._createNewOscillator("pulse"):(this._createNewOscillator("oscillator"),this._oscillator=this._oscillator,this._oscillator.type=t)}get partials(){return this._oscillator.partials}set partials(t){this._getOscType(this._oscillator,"pulse")||this._getOscType(this._oscillator,"pwm")||(this._oscillator.partials=t)}get partialCount(){return this._oscillator.partialCount}set partialCount(t){this._getOscType(this._oscillator,"pulse")||this._getOscType(this._oscillator,"pwm")||(this._oscillator.partialCount=t)}set(t){return Reflect.has(t,"type")&&t.type&&(this.type=t.type),super.set(t),this}_createNewOscillator(t){if(t!==this._sourceType){this._sourceType=t;const e=Fh[t],n=this.now();if(this._oscillator){const t=this._oscillator;t.stop(n),this.context.setTimeout((()=>t.dispose()),this.blockTime)}this._oscillator=new e({context:this.context}),this.frequency.connect(this._oscillator.frequency),this.detune.connect(this._oscillator.detune),this._oscillator.connect(this.output),this._oscillator.onstop=()=>this.onstop(this),"started"===this.state&&this._oscillator.start(n)}}get phase(){return this._oscillator.phase}set phase(t){this._oscillator.phase=t}get sourceType(){return this._sourceType}set sourceType(t){let e="sine";"pwm"!==this._oscillator.type&&"pulse"!==this._oscillator.type&&(e=this._oscillator.type),"fm"===t?this.type="fm"+e:"am"===t?this.type="am"+e:"fat"===t?this.type="fat"+e:"oscillator"===t?this.type=e:"pulse"===t?this.type="pulse":"pwm"===t&&(this.type="pwm")}_getOscType(t,e){return t instanceof Fh[e]}get baseType(){return this._oscillator.baseType}set baseType(t){this._getOscType(this._oscillator,"pulse")||this._getOscType(this._oscillator,"pwm")||"pulse"===t||"pwm"===t||(this._oscillator.baseType=t)}get width(){return this._getOscType(this._oscillator,"pulse")?this._oscillator.width:void 0}get count(){return this._getOscType(this._oscillator,"fat")?this._oscillator.count:void 0}set count(t){this._getOscType(this._oscillator,"fat")&&Xc(t)&&(this._oscillator.count=t)}get spread(){return this._getOscType(this._oscillator,"fat")?this._oscillator.spread:void 0}set spread(t){this._getOscType(this._oscillator,"fat")&&Xc(t)&&(this._oscillator.spread=t)}get modulationType(){return this._getOscType(this._oscillator,"fm")||this._getOscType(this._oscillator,"am")?this._oscillator.modulationType:void 0}set modulationType(t){(this._getOscType(this._oscillator,"fm")||this._getOscType(this._oscillator,"am"))&&Kc(t)&&(this._oscillator.modulationType=t)}get modulationIndex(){return this._getOscType(this._oscillator,"fm")?this._oscillator.modulationIndex:void 0}get harmonicity(){return this._getOscType(this._oscillator,"fm")||this._getOscType(this._oscillator,"am")?this._oscillator.harmonicity:void 0}get modulationFrequency(){return this._getOscType(this._oscillator,"pwm")?this._oscillator.modulationFrequency:void 0}asArray(t=1024){return el(this,void 0,void 0,(function*(){return Mh(this,t)}))}dispose(){return super.dispose(),this.detune.dispose(),this.frequency.dispose(),this._oscillator.dispose(),this}}function Bh(t,e=1/0){const n=new WeakMap;return function(i,s){Reflect.defineProperty(i,s,{configurable:!0,enumerable:!0,get:function(){return n.get(this)},set:function(i){Vc(i,t,e),n.set(this,i)}})}}function Vh(t,e=1/0){const n=new WeakMap;return function(i,s){Reflect.defineProperty(i,s,{configurable:!0,enumerable:!0,get:function(){return n.get(this)},set:function(i){Vc(this.toSeconds(i),t,e),n.set(this,i)}})}}class Wh extends bh{constructor(){super(hl(Wh.getDefaults(),arguments,["url","onload"])),this.name="Player",this._activeSources=new Set;const t=hl(Wh.getDefaults(),arguments,["url","onload"]);this._buffer=new kl({onload:this._onload.bind(this,t.onload),onerror:t.onerror,reverse:t.reverse,url:t.url}),this.autostart=t.autostart,this._loop=t.loop,this._loopStart=t.loopStart,this._loopEnd=t.loopEnd,this._playbackRate=t.playbackRate,this.fadeIn=t.fadeIn,this.fadeOut=t.fadeOut}static getDefaults(){return Object.assign(bh.getDefaults(),{autostart:!1,fadeIn:0,fadeOut:0,loop:!1,loopEnd:0,loopStart:0,onload:El,onerror:El,playbackRate:1,reverse:!1})}load(t){return el(this,void 0,void 0,(function*(){return yield this._buffer.load(t),this._onload(),this}))}_onload(t=El){t(),this.autostart&&this.start()}_onSourceEnd(t){this.onstop(this),this._activeSources.delete(t),0!==this._activeSources.size||this._synced||"started"!==this._state.getValueAtTime(this.now())||(this._state.cancel(this.now()),this._state.setStateAtTime("stopped",this.now()))}start(t,e,n){return super.start(t,e,n),this}_start(t,e,n){e=this._loop?ul(e,this._loopStart):ul(e,0);const i=this.toSeconds(e),s=n;n=ul(n,Math.max(this._buffer.duration-i,0));let r=this.toSeconds(n);r/=this._playbackRate,t=this.toSeconds(t);const o=new xh({url:this._buffer,context:this.context,fadeIn:this.fadeIn,fadeOut:this.fadeOut,loop:this._loop,loopEnd:this._loopEnd,loopStart:this._loopStart,onended:this._onSourceEnd.bind(this),playbackRate:this._playbackRate}).connect(this.output);this._loop||this._synced||(this._state.cancel(t+r),this._state.setStateAtTime("stopped",t+r,{implicitEnd:!0})),this._activeSources.add(o),this._loop&&zc(s)?o.start(t,i):o.start(t,i,r-this.toSeconds(this.fadeOut))}_stop(t){const e=this.toSeconds(t);this._activeSources.forEach((t=>t.stop(e)))}restart(t,e,n){return super.restart(t,e,n),this}_restart(t,e,n){this._stop(t),this._start(t,e,n)}seek(t,e){const n=this.toSeconds(e);if("started"===this._state.getValueAtTime(n)){const e=this.toSeconds(t);this._stop(n),this._start(n,e)}return this}setLoopPoints(t,e){return this.loopStart=t,this.loopEnd=e,this}get loopStart(){return this._loopStart}set loopStart(t){this._loopStart=t,this.buffer.loaded&&Vc(this.toSeconds(t),0,this.buffer.duration),this._activeSources.forEach((e=>{e.loopStart=t}))}get loopEnd(){return this._loopEnd}set loopEnd(t){this._loopEnd=t,this.buffer.loaded&&Vc(this.toSeconds(t),0,this.buffer.duration),this._activeSources.forEach((e=>{e.loopEnd=t}))}get buffer(){return this._buffer}set buffer(t){this._buffer.set(t)}get loop(){return this._loop}set loop(t){if(this._loop!==t&&(this._loop=t,this._activeSources.forEach((e=>{e.loop=t})),t)){const t=this._state.getNextState("stopped",this.now());t&&this._state.cancel(t.time)}}get playbackRate(){return this._playbackRate}set playbackRate(t){this._playbackRate=t;const e=this.now(),n=this._state.getNextState("stopped",e);n&&n.implicitEnd&&(this._state.cancel(n.time),this._activeSources.forEach((t=>t.cancelStop()))),this._activeSources.forEach((n=>{n.playbackRate.setValueAtTime(t,e)}))}get reverse(){return this._buffer.reverse}set reverse(t){this._buffer.reverse=t}get loaded(){return this._buffer.loaded}dispose(){return super.dispose(),this._activeSources.forEach((t=>t.dispose())),this._activeSources.clear(),this._buffer.dispose(),this}}tl([Vh(0)],Wh.prototype,"fadeIn",void 0),tl([Vh(0)],Wh.prototype,"fadeOut",void 0);class Hh extends ql{constructor(){super(hl(Hh.getDefaults(),arguments,["attack","decay","sustain","release"])),this.name="Envelope",this._sig=new eh({context:this.context,value:0}),this.output=this._sig,this.input=void 0;const t=hl(Hh.getDefaults(),arguments,["attack","decay","sustain","release"]);this.attack=t.attack,this.decay=t.decay,this.sustain=t.sustain,this.release=t.release,this.attackCurve=t.attackCurve,this.releaseCurve=t.releaseCurve,this.decayCurve=t.decayCurve}static getDefaults(){return Object.assign(ql.getDefaults(),{attack:.01,attackCurve:"linear",decay:.1,decayCurve:"exponential",release:1,releaseCurve:"exponential",sustain:.5})}get value(){return this.getValueAtTime(this.now())}_getCurve(t,e){if(Kc(t))return t;{let n;for(n in Gh)if(Gh[n][e]===t)return n;return t}}_setCurve(t,e,n){if(Kc(n)&&Reflect.has(Gh,n)){const i=Gh[n];Uc(i)?"_decayCurve"!==t&&(this[t]=i[e]):this[t]=i}else{if(!qc(n)||"_decayCurve"===t)throw new Error("Envelope: invalid curve: "+n);this[t]=n}}get attackCurve(){return this._getCurve(this._attackCurve,"In")}set attackCurve(t){this._setCurve("_attackCurve","In",t)}get releaseCurve(){return this._getCurve(this._releaseCurve,"Out")}set releaseCurve(t){this._setCurve("_releaseCurve","Out",t)}get decayCurve(){return this._decayCurve}set decayCurve(t){Bc(["linear","exponential"].some((e=>e===t)),`Invalid envelope curve: ${t}`),this._decayCurve=t}triggerAttack(t,e=1){this.log("triggerAttack",t,e),t=this.toSeconds(t);let n=this.toSeconds(this.attack);const i=this.toSeconds(this.decay),s=this.getValueAtTime(t);if(s>0){n=(1-s)/(1/n)}if(n<this.sampleTime)this._sig.cancelScheduledValues(t),this._sig.setValueAtTime(e,t);else if("linear"===this._attackCurve)this._sig.linearRampTo(e,n,t);else if("exponential"===this._attackCurve)this._sig.targetRampTo(e,n,t);else{this._sig.cancelAndHoldAtTime(t);let i=this._attackCurve;for(let t=1;t<i.length;t++)if(i[t-1]<=s&&s<=i[t]){i=this._attackCurve.slice(t),i[0]=s;break}this._sig.setValueCurveAtTime(i,t,n,e)}if(i&&this.sustain<1){const s=e*this.sustain,r=t+n;this.log("decay",r),"linear"===this._decayCurve?this._sig.linearRampToValueAtTime(s,i+r):this._sig.exponentialApproachValueAtTime(s,r,i)}return this}triggerRelease(t){this.log("triggerRelease",t),t=this.toSeconds(t);const e=this.getValueAtTime(t);if(e>0){const n=this.toSeconds(this.release);n<this.sampleTime?this._sig.setValueAtTime(0,t):"linear"===this._releaseCurve?this._sig.linearRampTo(0,n,t):"exponential"===this._releaseCurve?this._sig.targetRampTo(0,n,t):(Bc(qc(this._releaseCurve),"releaseCurve must be either 'linear', 'exponential' or an array"),this._sig.cancelAndHoldAtTime(t),this._sig.setValueCurveAtTime(this._releaseCurve,t,n,e))}return this}getValueAtTime(t){return this._sig.getValueAtTime(t)}triggerAttackRelease(t,e,n=1){return e=this.toSeconds(e),this.triggerAttack(e,n),this.triggerRelease(e+this.toSeconds(t)),this}cancel(t){return this._sig.cancelScheduledValues(this.toSeconds(t)),this}connect(t,e=0,n=0){return nh(this,t,e,n),this}asArray(t=1024){return el(this,void 0,void 0,(function*(){const e=t/this.context.sampleRate,n=new Pl(1,e,this.context.sampleRate),i=this.toSeconds(this.attack)+this.toSeconds(this.decay),s=i+this.toSeconds(this.release),r=.1*s,o=s+r,a=new this.constructor(Object.assign(this.get(),{attack:e*this.toSeconds(this.attack)/o,decay:e*this.toSeconds(this.decay)/o,release:e*this.toSeconds(this.release)/o,context:n}));a._sig.toDestination(),a.triggerAttackRelease(e*(i+r)/o,0);return(yield n.render()).getChannelData(0)}))}dispose(){return super.dispose(),this._sig.dispose(),this}}tl([Vh(0)],Hh.prototype,"attack",void 0),tl([Vh(0)],Hh.prototype,"decay",void 0),tl([Bh(0,1)],Hh.prototype,"sustain",void 0),tl([Vh(0)],Hh.prototype,"release",void 0);const Gh=(()=>{const t=128;let e,n;const i=[];for(e=0;e<t;e++)i[e]=Math.sin(e/127*(Math.PI/2));const s=[];for(e=0;e<127;e++){n=e/127;const t=Math.sin(n*(2*Math.PI)*6.4-Math.PI/2)+1;s[e]=t/10+.83*n}s[127]=1;const r=[];for(e=0;e<t;e++)r[e]=Math.ceil(e/127*5)/5;const o=[];for(e=0;e<t;e++)n=e/127,o[e]=.5*(1-Math.cos(Math.PI*n));const a=[];for(e=0;e<t;e++){n=e/127;const t=4*Math.pow(n,3)+.2,i=Math.cos(t*Math.PI*2*n);a[e]=Math.abs(i*(1-n))}function c(t){const e=new Array(t.length);for(let n=0;n<t.length;n++)e[n]=1-t[n];return e}return{bounce:{In:c(a),Out:a},cosine:{In:i,Out:(l=i,l.slice(0).reverse())},exponential:"exponential",linear:"linear",ripple:{In:s,Out:c(s)},sine:{In:o,Out:c(o)},step:{In:r,Out:c(r)}};var l})();class zh extends ql{constructor(){super(hl(zh.getDefaults(),arguments)),this._scheduledEvents=[],this._synced=!1,this._original_triggerAttack=this.triggerAttack,this._original_triggerRelease=this.triggerRelease;const t=hl(zh.getDefaults(),arguments);this._volume=this.output=new ph({context:this.context,volume:t.volume}),this.volume=this._volume.volume,Al(this,"volume")}static getDefaults(){return Object.assign(ql.getDefaults(),{volume:0})}sync(){return this._syncState()&&(this._syncMethod("triggerAttack",1),this._syncMethod("triggerRelease",0)),this}_syncState(){let t=!1;return this._synced||(this._synced=!0,t=!0),t}_syncMethod(t,e){const n=this["_original_"+t]=this[t];this[t]=(...t)=>{const i=t[e],s=this.context.transport.schedule((i=>{t[e]=i,n.apply(this,t)}),i);this._scheduledEvents.push(s)}}unsync(){return this._scheduledEvents.forEach((t=>this.context.transport.clear(t))),this._scheduledEvents=[],this._synced&&(this._synced=!1,this.triggerAttack=this._original_triggerAttack,this.triggerRelease=this._original_triggerRelease),this}triggerAttackRelease(t,e,n,i){const s=this.toSeconds(n),r=this.toSeconds(e);return this.triggerAttack(t,s,i),this.triggerRelease(s+r),this}dispose(){return super.dispose(),this._volume.dispose(),this.unsync(),this._scheduledEvents=[],this}}class Yh extends zh{constructor(){super(hl(Yh.getDefaults(),arguments));const t=hl(Yh.getDefaults(),arguments);this.portamento=t.portamento,this.onsilence=t.onsilence}static getDefaults(){return Object.assign(zh.getDefaults(),{detune:0,onsilence:El,portamento:0})}triggerAttack(t,e,n=1){this.log("triggerAttack",t,e,n);const i=this.toSeconds(e);return this._triggerEnvelopeAttack(i,n),this.setNote(t,i),this}triggerRelease(t){this.log("triggerRelease",t);const e=this.toSeconds(t);return this._triggerEnvelopeRelease(e),this}setNote(t,e){const n=this.toSeconds(e),i=t instanceof Wl?t.toFrequency():t;if(this.portamento>0&&this.getLevelAtTime(n)>.05){const t=this.toSeconds(this.portamento);this.frequency.exponentialRampTo(i,t,n)}else this.frequency.setValueAtTime(i,n);return this}}tl([Vh(0)],Yh.prototype,"portamento",void 0);class Xh extends Hh{constructor(){super(hl(Xh.getDefaults(),arguments,["attack","decay","sustain","release"])),this.name="AmplitudeEnvelope",this._gainNode=new Ql({context:this.context,gain:0}),this.output=this._gainNode,this.input=this._gainNode,this._sig.connect(this._gainNode.gain),this.output=this._gainNode,this.input=this._gainNode}dispose(){return super.dispose(),this._gainNode.dispose(),this}}class Uh extends Yh{constructor(){super(hl(Uh.getDefaults(),arguments)),this.name="Synth";const t=hl(Uh.getDefaults(),arguments);this.oscillator=new Nh(Object.assign({context:this.context,detune:t.detune,onstop:()=>this.onsilence(this)},t.oscillator)),this.frequency=this.oscillator.frequency,this.detune=this.oscillator.detune,this.envelope=new Xh(Object.assign({context:this.context},t.envelope)),this.oscillator.chain(this.envelope,this.output),Al(this,["oscillator","frequency","detune","envelope"])}static getDefaults(){return Object.assign(Yh.getDefaults(),{envelope:Object.assign(dl(Hh.getDefaults(),Object.keys(ql.getDefaults())),{attack:.005,decay:.1,release:1,sustain:.3}),oscillator:Object.assign(dl(Nh.getDefaults(),[...Object.keys(bh.getDefaults()),"frequency","detune"]),{type:"triangle"})})}_triggerEnvelopeAttack(t,e){if(this.envelope.triggerAttack(t,e),this.oscillator.start(t),0===this.envelope.sustain){const e=this.toSeconds(this.envelope.attack),n=this.toSeconds(this.envelope.decay);this.oscillator.stop(t+e+n)}}_triggerEnvelopeRelease(t){this.envelope.triggerRelease(t),this.oscillator.stop(t+this.toSeconds(this.envelope.release))}getLevelAtTime(t){return t=this.toSeconds(t),this.envelope.getValueAtTime(t)}dispose(){return super.dispose(),this.oscillator.dispose(),this.envelope.dispose(),this}}class qh extends Yh{constructor(){super(hl(qh.getDefaults(),arguments)),this.name="ModulationSynth";const t=hl(qh.getDefaults(),arguments);this._carrier=new Uh({context:this.context,oscillator:t.oscillator,envelope:t.envelope,onsilence:()=>this.onsilence(this),volume:-10}),this._modulator=new Uh({context:this.context,oscillator:t.modulation,envelope:t.modulationEnvelope,volume:-10}),this.oscillator=this._carrier.oscillator,this.envelope=this._carrier.envelope,this.modulation=this._modulator.oscillator,this.modulationEnvelope=this._modulator.envelope,this.frequency=new eh({context:this.context,units:"frequency"}),this.detune=new eh({context:this.context,value:t.detune,units:"cents"}),this.harmonicity=new Ih({context:this.context,value:t.harmonicity,minValue:0}),this._modulationNode=new Ql({context:this.context,gain:0}),Al(this,["frequency","harmonicity","oscillator","envelope","modulation","modulationEnvelope","detune"])}static getDefaults(){return Object.assign(Yh.getDefaults(),{harmonicity:3,oscillator:Object.assign(dl(Nh.getDefaults(),[...Object.keys(bh.getDefaults()),"frequency","detune"]),{type:"sine"}),envelope:Object.assign(dl(Hh.getDefaults(),Object.keys(ql.getDefaults())),{attack:.01,decay:.01,sustain:1,release:.5}),modulation:Object.assign(dl(Nh.getDefaults(),[...Object.keys(bh.getDefaults()),"frequency","detune"]),{type:"square"}),modulationEnvelope:Object.assign(dl(Hh.getDefaults(),Object.keys(ql.getDefaults())),{attack:.5,decay:0,sustain:1,release:.5})})}_triggerEnvelopeAttack(t,e){this._carrier._triggerEnvelopeAttack(t,e),this._modulator._triggerEnvelopeAttack(t,e)}_triggerEnvelopeRelease(t){return this._carrier._triggerEnvelopeRelease(t),this._modulator._triggerEnvelopeRelease(t),this}getLevelAtTime(t){return t=this.toSeconds(t),this.envelope.getValueAtTime(t)}dispose(){return super.dispose(),this._carrier.dispose(),this._modulator.dispose(),this.frequency.dispose(),this.detune.dispose(),this.harmonicity.dispose(),this._modulationNode.dispose(),this}}class Kh extends qh{constructor(){super(hl(Kh.getDefaults(),arguments)),this.name="AMSynth",this._modulationScale=new Ph({context:this.context}),this.frequency.connect(this._carrier.frequency),this.frequency.chain(this.harmonicity,this._modulator.frequency),this.detune.fan(this._carrier.detune,this._modulator.detune),this._modulator.chain(this._modulationScale,this._modulationNode.gain),this._carrier.chain(this._modulationNode,this.output)}dispose(){return super.dispose(),this._modulationScale.dispose(),this}}class Zh extends qh{constructor(){super(hl(Zh.getDefaults(),arguments)),this.name="FMSynth";const t=hl(Zh.getDefaults(),arguments);this.modulationIndex=new Ih({context:this.context,value:t.modulationIndex}),this.frequency.connect(this._carrier.frequency),this.frequency.chain(this.harmonicity,this._modulator.frequency),this.frequency.chain(this.modulationIndex,this._modulationNode),this.detune.fan(this._carrier.detune,this._modulator.detune),this._modulator.connect(this._modulationNode.gain),this._modulationNode.connect(this._carrier.frequency),this._carrier.connect(this.output)}static getDefaults(){return Object.assign(qh.getDefaults(),{modulationIndex:10})}dispose(){return super.dispose(),this.modulationIndex.dispose(),this}}class Qh extends Uh{constructor(){super(hl(Qh.getDefaults(),arguments)),this.name="MembraneSynth",this.portamento=0;const t=hl(Qh.getDefaults(),arguments);this.pitchDecay=t.pitchDecay,this.octaves=t.octaves,Al(this,["oscillator","envelope"])}static getDefaults(){return ll(Yh.getDefaults(),Uh.getDefaults(),{envelope:{attack:.001,attackCurve:"exponential",decay:.4,release:1.4,sustain:.01},octaves:10,oscillator:{type:"sine"},pitchDecay:.05})}setNote(t,e){const n=this.toSeconds(e),i=this.toFrequency(t instanceof Wl?t.toFrequency():t),s=i*this.octaves;return this.oscillator.frequency.setValueAtTime(s,n),this.oscillator.frequency.exponentialRampToValueAtTime(i,n+this.toSeconds(this.pitchDecay)),this}dispose(){return super.dispose(),this}}tl([Bh(0)],Qh.prototype,"octaves",void 0),tl([Vh(0)],Qh.prototype,"pitchDecay",void 0);class Jh extends zh{constructor(){super(hl(Jh.getDefaults(),arguments)),this.name="NoiseSynth";const t=hl(Jh.getDefaults(),arguments);this.noise=new Ch(Object.assign({context:this.context},t.noise)),this.envelope=new Xh(Object.assign({context:this.context},t.envelope)),this.noise.chain(this.envelope,this.output)}static getDefaults(){return Object.assign(zh.getDefaults(),{envelope:Object.assign(dl(Hh.getDefaults(),Object.keys(ql.getDefaults())),{decay:.1,sustain:0}),noise:Object.assign(dl(Ch.getDefaults(),Object.keys(bh.getDefaults())),{type:"white"})})}triggerAttack(t,e=1){return t=this.toSeconds(t),this.envelope.triggerAttack(t,e),this.noise.start(t),0===this.envelope.sustain&&this.noise.stop(t+this.toSeconds(this.envelope.attack)+this.toSeconds(this.envelope.decay)),this}triggerRelease(t){return t=this.toSeconds(t),this.envelope.triggerRelease(t),this.noise.stop(t+this.toSeconds(this.envelope.release)),this}sync(){return this._syncState()&&(this._syncMethod("triggerAttack",0),this._syncMethod("triggerRelease",0)),this}triggerAttackRelease(t,e,n=1){return e=this.toSeconds(e),t=this.toSeconds(t),this.triggerAttack(e,n),this.triggerRelease(e+t),this}dispose(){return super.dispose(),this.noise.dispose(),this.envelope.dispose(),this}}const tu=new Set;function eu(t){tu.add(t)}function nu(t,e){const n=`registerProcessor("${t}", ${e})`;tu.add(n)}eu('\n\t/**\n\t * The base AudioWorkletProcessor for use in Tone.js. Works with the [[ToneAudioWorklet]]. \n\t */\n\tclass ToneAudioWorkletProcessor extends AudioWorkletProcessor {\n\n\t\tconstructor(options) {\n\t\t\t\n\t\t\tsuper(options);\n\t\t\t/**\n\t\t\t * If the processor was disposed or not. Keep alive until it\'s disposed.\n\t\t\t */\n\t\t\tthis.disposed = false;\n\t\t   \t/** \n\t\t\t * The number of samples in the processing block\n\t\t\t */\n\t\t\tthis.blockSize = 128;\n\t\t\t/**\n\t\t\t * the sample rate\n\t\t\t */\n\t\t\tthis.sampleRate = sampleRate;\n\n\t\t\tthis.port.onmessage = (event) => {\n\t\t\t\t// when it receives a dispose \n\t\t\t\tif (event.data === "dispose") {\n\t\t\t\t\tthis.disposed = true;\n\t\t\t\t}\n\t\t\t};\n\t\t}\n\t}\n');eu("\n\t/**\n\t * Abstract class for a single input/output processor. \n\t * has a 'generate' function which processes one sample at a time\n\t */\n\tclass SingleIOProcessor extends ToneAudioWorkletProcessor {\n\n\t\tconstructor(options) {\n\t\t\tsuper(Object.assign(options, {\n\t\t\t\tnumberOfInputs: 1,\n\t\t\t\tnumberOfOutputs: 1\n\t\t\t}));\n\t\t\t/**\n\t\t\t * Holds the name of the parameter and a single value of that\n\t\t\t * parameter at the current sample\n\t\t\t * @type { [name: string]: number }\n\t\t\t */\n\t\t\tthis.params = {}\n\t\t}\n\n\t\t/**\n\t\t * Generate an output sample from the input sample and parameters\n\t\t * @abstract\n\t\t * @param input number\n\t\t * @param channel number\n\t\t * @param parameters { [name: string]: number }\n\t\t * @returns number\n\t\t */\n\t\tgenerate(){}\n\n\t\t/**\n\t\t * Update the private params object with the \n\t\t * values of the parameters at the given index\n\t\t * @param parameters { [name: string]: Float32Array },\n\t\t * @param index number\n\t\t */\n\t\tupdateParams(parameters, index) {\n\t\t\tfor (const paramName in parameters) {\n\t\t\t\tconst param = parameters[paramName];\n\t\t\t\tif (param.length > 1) {\n\t\t\t\t\tthis.params[paramName] = parameters[paramName][index];\n\t\t\t\t} else {\n\t\t\t\t\tthis.params[paramName] = parameters[paramName][0];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * Process a single frame of the audio\n\t\t * @param inputs Float32Array[][]\n\t\t * @param outputs Float32Array[][]\n\t\t */\n\t\tprocess(inputs, outputs, parameters) {\n\t\t\tconst input = inputs[0];\n\t\t\tconst output = outputs[0];\n\t\t\t// get the parameter values\n\t\t\tconst channelCount = Math.max(input && input.length || 0, output.length);\n\t\t\tfor (let sample = 0; sample < this.blockSize; sample++) {\n\t\t\t\tthis.updateParams(parameters, sample);\n\t\t\t\tfor (let channel = 0; channel < channelCount; channel++) {\n\t\t\t\t\tconst inputSample = input && input.length ? input[channel][sample] : 0;\n\t\t\t\t\toutput[channel][sample] = this.generate(inputSample, channel, this.params);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn !this.disposed;\n\t\t}\n\t};\n");eu("\n\t/**\n\t * A multichannel buffer for use within an AudioWorkletProcessor as a delay line\n\t */\n\tclass DelayLine {\n\t\t\n\t\tconstructor(size, channels) {\n\t\t\tthis.buffer = [];\n\t\t\tthis.writeHead = []\n\t\t\tthis.size = size;\n\n\t\t\t// create the empty channels\n\t\t\tfor (let i = 0; i < channels; i++) {\n\t\t\t\tthis.buffer[i] = new Float32Array(this.size);\n\t\t\t\tthis.writeHead[i] = 0;\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * Push a value onto the end\n\t\t * @param channel number\n\t\t * @param value number\n\t\t */\n\t\tpush(channel, value) {\n\t\t\tthis.writeHead[channel] += 1;\n\t\t\tif (this.writeHead[channel] > this.size) {\n\t\t\t\tthis.writeHead[channel] = 0;\n\t\t\t}\n\t\t\tthis.buffer[channel][this.writeHead[channel]] = value;\n\t\t}\n\n\t\t/**\n\t\t * Get the recorded value of the channel given the delay\n\t\t * @param channel number\n\t\t * @param delay number delay samples\n\t\t */\n\t\tget(channel, delay) {\n\t\t\tlet readHead = this.writeHead[channel] - Math.floor(delay);\n\t\t\tif (readHead < 0) {\n\t\t\t\treadHead += this.size;\n\t\t\t}\n\t\t\treturn this.buffer[channel][readHead];\n\t\t}\n\t}\n");nu("feedback-comb-filter",'\n\tclass FeedbackCombFilterWorklet extends SingleIOProcessor {\n\n\t\tconstructor(options) {\n\t\t\tsuper(options);\n\t\t\tthis.delayLine = new DelayLine(this.sampleRate, options.channelCount || 2);\n\t\t}\n\n\t\tstatic get parameterDescriptors() {\n\t\t\treturn [{\n\t\t\t\tname: "delayTime",\n\t\t\t\tdefaultValue: 0.1,\n\t\t\t\tminValue: 0,\n\t\t\t\tmaxValue: 1,\n\t\t\t\tautomationRate: "k-rate"\n\t\t\t}, {\n\t\t\t\tname: "feedback",\n\t\t\t\tdefaultValue: 0.5,\n\t\t\t\tminValue: 0,\n\t\t\t\tmaxValue: 0.9999,\n\t\t\t\tautomationRate: "k-rate"\n\t\t\t}];\n\t\t}\n\n\t\tgenerate(input, channel, parameters) {\n\t\t\tconst delayedSample = this.delayLine.get(channel, parameters.delayTime * this.sampleRate);\n\t\t\tthis.delayLine.push(channel, input + delayedSample * parameters.feedback);\n\t\t\treturn delayedSample;\n\t\t}\n\t}\n');class iu extends zh{constructor(){super(hl(iu.getDefaults(),arguments,["voice","options"])),this.name="PolySynth",this._availableVoices=[],this._activeVoices=[],this._voices=[],this._gcTimeout=-1,this._averageActiveVoices=0;const t=hl(iu.getDefaults(),arguments,["voice","options"]);Bc(!Xc(t.voice),"DEPRECATED: The polyphony count is no longer the first argument.");const e=t.voice.getDefaults();this.options=Object.assign(e,t.options),this.voice=t.voice,this.maxPolyphony=t.maxPolyphony,this._dummyVoice=this._getNextAvailableVoice();const n=this._voices.indexOf(this._dummyVoice);this._voices.splice(n,1),this._gcTimeout=this.context.setInterval(this._collectGarbage.bind(this),1)}static getDefaults(){return Object.assign(zh.getDefaults(),{maxPolyphony:32,options:{},voice:Uh})}get activeVoices(){return this._activeVoices.length}_makeVoiceAvailable(t){this._availableVoices.push(t);const e=this._activeVoices.findIndex((e=>e.voice===t));this._activeVoices.splice(e,1)}_getNextAvailableVoice(){if(this._availableVoices.length)return this._availableVoices.shift();if(this._voices.length<this.maxPolyphony){const t=new this.voice(Object.assign(this.options,{context:this.context,onsilence:this._makeVoiceAvailable.bind(this)}));return t.connect(this.output),this._voices.push(t),t}Gc("Max polyphony exceeded. Note dropped.")}_collectGarbage(){if(this._averageActiveVoices=Math.max(.95*this._averageActiveVoices,this.activeVoices),this._availableVoices.length&&this._voices.length>Math.ceil(this._averageActiveVoices+1)){const t=this._availableVoices.shift(),e=this._voices.indexOf(t);this._voices.splice(e,1),this.context.isOffline||t.dispose()}}_triggerAttack(t,e,n){t.forEach((t=>{const i=new ch(this.context,t).toMidi(),s=this._getNextAvailableVoice();s&&(s.triggerAttack(t,e,n),this._activeVoices.push({midi:i,voice:s,released:!1}),this.log("triggerAttack",t,e))}))}_triggerRelease(t,e){t.forEach((t=>{const n=new ch(this.context,t).toMidi(),i=this._activeVoices.find((({midi:t,released:e})=>t===n&&!e));i&&(i.voice.triggerRelease(e),i.released=!0,this.log("triggerRelease",t,e))}))}_scheduleEvent(t,e,n,i){Bc(!this.disposed,"Synth was already disposed"),n<=this.now()?"attack"===t?this._triggerAttack(e,n,i):this._triggerRelease(e,n):this.context.setTimeout((()=>{this._scheduleEvent(t,e,n,i)}),n-this.now())}triggerAttack(t,e,n){Array.isArray(t)||(t=[t]);const i=this.toSeconds(e);return this._scheduleEvent("attack",t,i,n),this}triggerRelease(t,e){Array.isArray(t)||(t=[t]);const n=this.toSeconds(e);return this._scheduleEvent("release",t,n),this}triggerAttackRelease(t,e,n,i){const s=this.toSeconds(n);if(this.triggerAttack(t,s,i),qc(e)){Bc(qc(t),"If the duration is an array, the notes must also be an array"),t=t;for(let n=0;n<t.length;n++){const i=e[Math.min(n,e.length-1)],r=this.toSeconds(i);Bc(r>0,"The duration must be greater than 0"),this.triggerRelease(t[n],s+r)}}else{const n=this.toSeconds(e);Bc(n>0,"The duration must be greater than 0"),this.triggerRelease(t,s+n)}return this}sync(){return this._syncState()&&(this._syncMethod("triggerAttack",1),this._syncMethod("triggerRelease",1)),this}set(t){const e=dl(t,["onsilence","context"]);return this.options=ll(this.options,e),this._voices.forEach((t=>t.set(e))),this._dummyVoice.set(e),this}get(){return this._dummyVoice.get()}releaseAll(t){const e=this.toSeconds(t);return this._activeVoices.forEach((({voice:t})=>{t.triggerRelease(e)})),this}dispose(){return super.dispose(),this._dummyVoice.dispose(),this._voices.forEach((t=>t.dispose())),this._activeVoices=[],this._availableVoices=[],this.context.clearInterval(this._gcTimeout),this}}class su extends zh{constructor(){super(hl(su.getDefaults(),arguments,["urls","onload","baseUrl"],"urls")),this.name="Sampler",this._activeSources=new Map;const t=hl(su.getDefaults(),arguments,["urls","onload","baseUrl"],"urls"),e={};Object.keys(t.urls).forEach((n=>{const i=parseInt(n,10);if(Bc(Zc(n)||Xc(i)&&isFinite(i),`url key is neither a note or midi pitch: ${n}`),Zc(n)){const i=new Wl(this.context,n).toMidi();e[i]=t.urls[n]}else Xc(i)&&isFinite(i)&&(e[i]=t.urls[i])})),this._buffers=new ah({urls:e,onload:t.onload,baseUrl:t.baseUrl,onerror:t.onerror}),this.attack=t.attack,this.release=t.release,this.curve=t.curve,this._buffers.loaded&&Promise.resolve().then(t.onload)}static getDefaults(){return Object.assign(zh.getDefaults(),{attack:0,baseUrl:"",curve:"exponential",onload:El,onerror:El,release:.1,urls:{}})}_findClosest(t){let e=0;for(;e<96;){if(this._buffers.has(t+e))return-e;if(this._buffers.has(t-e))return e;e++}throw new Error(`No available buffers for note: ${t}`)}triggerAttack(t,e,n=1){return this.log("triggerAttack",t,e,n),Array.isArray(t)||(t=[t]),t.forEach((t=>{const i=Fl(new Wl(this.context,t).toFrequency()),s=Math.round(i),r=i-s,o=this._findClosest(s),a=s-o,c=this._buffers.get(a),l=jl(o+r),h=new xh({url:c,context:this.context,curve:this.curve,fadeIn:this.attack,fadeOut:this.release,playbackRate:l}).connect(this.output);h.start(e,0,c.duration/l,n),qc(this._activeSources.get(s))||this._activeSources.set(s,[]),this._activeSources.get(s).push(h),h.onended=()=>{if(this._activeSources&&this._activeSources.has(s)){const t=this._activeSources.get(s),e=t.indexOf(h);-1!==e&&t.splice(e,1)}}})),this}triggerRelease(t,e){return this.log("triggerRelease",t,e),Array.isArray(t)||(t=[t]),t.forEach((t=>{const n=new Wl(this.context,t).toMidi();if(this._activeSources.has(n)&&this._activeSources.get(n).length){const t=this._activeSources.get(n);e=this.toSeconds(e),t.forEach((t=>{t.stop(e)})),this._activeSources.set(n,[])}})),this}releaseAll(t){const e=this.toSeconds(t);return this._activeSources.forEach((t=>{for(;t.length;){t.shift().stop(e)}})),this}sync(){return this._syncState()&&(this._syncMethod("triggerAttack",1),this._syncMethod("triggerRelease",1)),this}triggerAttackRelease(t,e,n,i=1){const s=this.toSeconds(n);return this.triggerAttack(t,s,i),qc(e)?(Bc(qc(t),"notes must be an array when duration is array"),t.forEach(((t,n)=>{const i=e[Math.min(n,e.length-1)];this.triggerRelease(t,s+this.toSeconds(i))}))):this.triggerRelease(t,s+this.toSeconds(e)),this}add(t,e,n){if(Bc(Zc(t)||isFinite(t),`note must be a pitch or midi: ${t}`),Zc(t)){const i=new Wl(this.context,t).toMidi();this._buffers.add(i,e,n)}else this._buffers.add(t,e,n);return this}get loaded(){return this._buffers.loaded}dispose(){return super.dispose(),this._buffers.dispose(),this._activeSources.forEach((t=>{t.forEach((t=>t.dispose()))})),this._activeSources.clear(),this}}tl([Vh(0)],su.prototype,"attack",void 0),tl([Vh(0)],su.prototype,"release",void 0);nu("bit-crusher","\n\tclass BitCrusherWorklet extends SingleIOProcessor {\n\n\t\tstatic get parameterDescriptors() {\n\t\t\treturn [{\n\t\t\t\tname: \"bits\",\n\t\t\t\tdefaultValue: 12,\n\t\t\t\tminValue: 1,\n\t\t\t\tmaxValue: 16,\n\t\t\t\tautomationRate: 'k-rate'\n\t\t\t}];\n\t\t}\n\n\t\tgenerate(input, _channel, parameters) {\n\t\t\tconst step = Math.pow(0.5, parameters.bits - 1);\n\t\t\tconst val = step * Math.floor(input / step + 0.5);\n\t\t\treturn val;\n\t\t}\n\t}\n");class ru extends ql{constructor(){super(...arguments),this.name="Listener",this.positionX=new Ul({context:this.context,param:this.context.rawContext.listener.positionX}),this.positionY=new Ul({context:this.context,param:this.context.rawContext.listener.positionY}),this.positionZ=new Ul({context:this.context,param:this.context.rawContext.listener.positionZ}),this.forwardX=new Ul({context:this.context,param:this.context.rawContext.listener.forwardX}),this.forwardY=new Ul({context:this.context,param:this.context.rawContext.listener.forwardY}),this.forwardZ=new Ul({context:this.context,param:this.context.rawContext.listener.forwardZ}),this.upX=new Ul({context:this.context,param:this.context.rawContext.listener.upX}),this.upY=new Ul({context:this.context,param:this.context.rawContext.listener.upY}),this.upZ=new Ul({context:this.context,param:this.context.rawContext.listener.upZ})}static getDefaults(){return Object.assign(ql.getDefaults(),{positionX:0,positionY:0,positionZ:0,forwardX:0,forwardY:0,forwardZ:-1,upX:0,upY:1,upZ:0})}dispose(){return super.dispose(),this.positionX.dispose(),this.positionY.dispose(),this.positionZ.dispose(),this.forwardX.dispose(),this.forwardY.dispose(),this.forwardZ.dispose(),this.upX.dispose(),this.upY.dispose(),this.upZ.dispose(),this}}xl((t=>{t.listener=new ru({context:t})})),wl((t=>{t.listener.dispose()})),Rl().transport,Rl().destination,Rl().destination,Rl().listener,Rl().draw,Rl();class ou{constructor(){}}class au extends ou{constructor(t){super(),this.initialized=ke(!1),Dl.resume().then((()=>{this.synth=new iu(t).toDestination(),this.initialized.set(!0)}))}down(t,e){this.synth&&this.synth.triggerAttack(t.name.toString())}up(t){this.synth&&this.synth.triggerRelease(t.name.toString())}}class cu extends au{constructor(){super(Uh)}static getInstance(){return new cu}static getMeta(){return{id:"basic",label:"Basic"}}}class lu extends au{constructor(){super(Zh)}static getInstance(){return new lu}static getMeta(){return{id:"fm",label:"FM"}}}class hu extends au{constructor(){super(Kh)}static getInstance(){return new hu}static getMeta(){return{id:"am",label:"AM"}}}class uu{constructor(t){this.root=t}}const du=["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"],fu=[1,2,3,4,5,6],pu=Math.max(...fu),mu=Math.min(...fu);function gu(t,e){return e.indexOf(t)===e.length-1?e[0]:e[e.indexOf(t)+1]}function vu(t,e){return 0===e.indexOf(t)?e[e.length-1]:e[e.indexOf(t)-1]}class _u extends uu{constructor(t,e){super(t),this.layout=e}generate(t){let e={},n=t.offset,i=du.indexOf(this.root.pc),s=this.root.oct,r=[];for(let o=0;o<t.rows;o++){let a=[];if(0===o)for(let r=0;r<t.columns;r++)e[n]=an(`${du[i]}${s}`),a.push(e[n]),i===du.length-1?(i=0,s++):i++,n++;else for(let i=0;i<t.columns;i++){const t=r[o-1][i];let s;"3rds"===this.layout||"4ths"===this.layout&&(s=an(vn(t.name,"4P"))),"b"===s.acc&&(s=an(Jn(s.name))),e[n]=s,a.push(e[n]),n++}r.push(a)}return e}}class yu extends _u{constructor(t){super(t,"4ths")}static getInstance(t){return new yu(t)}static getMeta(){return{id:"ableton4ths",label:"4ths chromatic"}}}class bu extends uu{constructor(t){super(t)}static getInstance(t){return new bu(t)}static getMeta(){return{id:"sequential",label:"sequential"}}generate(t){let e={},n=t.offset,i=du.indexOf(this.root.pc),s=this.root.oct;for(let r=0;r<t.rows;r++)for(let r=0;r<t.columns;r++)e[n]=an(`${du[i]}${s}`),i===du.length-1?(i=0,s++):i++,n++;return e}}function xu(t){return Math.min(1,Math.max(0,t.velocity/127))}class Cu{constructor(t,e){this.note=ke(null),this.highlightedState=!1,this.pressedState=!1,this.hoveredState=!1,this.controller=t,this.padNumber=e,this.pressed=Pe([this.controller.notesPressed,this.note],(([t,e])=>t.includes(e))),this.highlighted=Pe([this.controller.notesHighlighted,this.note],(([t,e])=>t.includes(e))),this.hovered=Pe([this.controller.notesHovered,this.note],(([t,e])=>t.includes(e))),this.pressed.subscribe((t=>{this.pressedState=t,this.draw()})),this.highlighted.subscribe((t=>{this.highlightedState=t,this.draw()})),this.hovered.subscribe((t=>{this.hoveredState=t,this.draw()}))}getNote(){return this.noteState}get padNoteColor(){return this.controller.noteColors[this.noteState.noteNumber]||this.controller.noteColors.default}setNote(t){this.noteState=t,this.note.set(t),this.draw()}draw(){if(this.controller.output)if(this.pressedState)this.controller.output.playNote(this.padNumber,"all",{velocity:xu(this.controller.pressedColor)});else if(this.hoveredState)this.controller.output.playNote(this.padNumber,"all",{velocity:xu(this.controller.hoverColor)});else if(this.highlightedState)this.controller.output.playNote(this.padNumber,"all",{velocity:xu(this.controller.highlightColor)});else{const t=this.padNoteColor;t&&"number"==typeof t.velocity?this.controller.output.playNote(this.padNumber,"all",{velocity:xu(t)}):this.controller.output.stopNote(this.padNumber,"all")}}}class wu{constructor(t,e){this.stateState="on",this.state=ke(this.stateState);const{controlNumber:n,controlType:i,initialColor:s,fireAllEvents:r}=e;this.controller=t,this.controlNumber=n,this.controlType=i,this.overrideColor=s,this.fireAllEvents=r}getColor(){return this.overrideColor||this.controller.controlColors[this.stateState]}setColor(t){this.overrideColor=t,this.draw()}setStateOn(){this.setState("on")}setStateOff(){this.setState("off")}setState(t){this.stateState=t,this.state.set(this.stateState),this.draw()}draw(){this.getColor()?this.controller.output&&this.controller.output.sendControlChange(this.controlNumber,this.getColor().velocity):console.warn(`No color for controller state "${this.state}"`)}}function Su(t){let e,n,i=t[1].noteNumber+"";return{c(){e=A("div"),n=E(i),D(e,"class","note-number svelte-1icudze")},m(t,i){S(t,e,i),w(e,n)},p(t,e){2&e&&i!==(i=t[1].noteNumber+"")&&L(n,i)},d(t){t&&T(e)}}}function Tu(e){let n,i,s,o,a,c,l,h,u,d=e[1].name.toString()+"",f=e[1].noteNumber&&Su(e);return{c(){n=A("div"),i=A("span"),s=k(),o=A("span"),a=A("div"),c=E(d),l=k(),f&&f.c(),D(i,"class","back svelte-1icudze"),D(a,"class","note svelte-1icudze"),D(o,"class","front svelte-1icudze"),D(n,"class","pad svelte-1icudze"),N(n,"--noteColor",e[2]),N(n,"--noteBackgroundColor",e[3]),G(n,"pressed",e[4]),G(n,"highlighted",e[5]),G(n,"hovered",e[6]),G(n,"rootNote",1===e[1].noteNumber),G(n,"scaleNote",e[1].noteNumber>=1)},m(t,r){S(t,n,r),w(n,i),w(n,s),w(n,o),w(o,a),w(a,c),w(o,l),f&&f.m(o,null),h||(u=[I(n,"mousedown",e[14]),I(n,"mouseup",e[15]),I(n,"mouseover",e[16]),I(n,"mouseout",e[17])],h=!0)},p(t,[e]){2&e&&d!==(d=t[1].name.toString()+"")&&L(c,d),t[1].noteNumber?f?f.p(t,e):(f=Su(t),f.c(),f.m(o,null)):f&&(f.d(1),f=null),4&e&&N(n,"--noteColor",t[2]),8&e&&N(n,"--noteBackgroundColor",t[3]),16&e&&G(n,"pressed",t[4]),32&e&&G(n,"highlighted",t[5]),64&e&&G(n,"hovered",t[6]),2&e&&G(n,"rootNote",1===t[1].noteNumber),2&e&&G(n,"scaleNote",t[1].noteNumber>=1)},i:t,o:t,d(t){t&&T(n),f&&f.d(),h=!1,r(u)}}}function Mu(t,e,n){let i,s,r,o,a,c;var l,u;let{pad:d}=e;const f=d.controller,{note:p,pressed:m,highlighted:g,hovered:v}=d;h(t,p,(t=>n(1,r=t))),h(t,m,(t=>n(4,o=t))),h(t,g,(t=>n(5,a=t))),h(t,v,(t=>n(6,c=t)));return t.$$set=t=>{"pad"in t&&n(0,d=t.pad)},t.$$.update=()=>{4099&t.$$.dirty&&n(2,i=r&&((null===n(12,l=d.padNoteColor)||void 0===l?void 0:l.foreground)||"rgb(0,0,0)")),8195&t.$$.dirty&&n(3,s=r&&((null===n(13,u=d.padNoteColor)||void 0===u?void 0:u.background)||"rgb(200,200,200)"))},[d,r,i,s,o,a,c,f,p,m,g,v,l,u,()=>f.noteOn(d.getNote(),1),()=>f.noteOff(d.getNote()),t=>{t.buttons&&f.noteOn(d.getNote(),1),f.hoverNoteOn(d.getNote())},t=>{t.buttons&&f.noteOff(d.getNote()),f.hoverNoteOff(d.getNote())}]}class Au extends $t{constructor(t){super(),jt(this,t,Mu,Tu,a,{pad:0})}}const Ou=960,Eu=160;class ku{constructor(t){t.width=Ou,t.height=Eu,this.context=t.getContext("2d"),this.worker=new Worker("./worker.js")}get isDrawing(){return this._isDrawing}async initialize(){await this.initializeUSB(),await this.initializePython();try{await this.callWorkerAsync("drawBlackFrame")}catch(t){throw new Error(`Error sending test frame: ${t.message}`)}}async initializePython(){await this.callWorkerAsync("initializePython",{python:"# Adapted from https://github.com/ffont/push2-python/blob/884a3f06fdf4d78d0e99afc9a7cf6623bb7622d1/push2_python/display.py\n\nimport numpy\n\n# Push 2 Display\nDISPLAY_N_LINES = 160\nDISPLAY_LINE_PIXELS = 960\nDISPLAY_PIXEL_BYTES = 2  # bytes\nDISPLAY_LINE_FILLER_BYTES = 128\nDISPLAY_LINE_SIZE = DISPLAY_LINE_PIXELS * \\\n    DISPLAY_PIXEL_BYTES + DISPLAY_LINE_FILLER_BYTES\nDISPLAY_N_LINES_PER_BUFFER = 8\nDISPLAY_BUFFER_SIZE = DISPLAY_LINE_SIZE * DISPLAY_N_LINES_PER_BUFFER\nDISPLAY_FRAME_XOR_PATTERN = [0xE7F3, 0xE7FF] * (\n    ((DISPLAY_LINE_PIXELS + (DISPLAY_LINE_FILLER_BYTES // 2)) * DISPLAY_N_LINES) // 2)\nFRAME_FORMAT_BGR565 = 'bgr565'\nFRAME_FORMAT_RGB = 'rgb'\nFRAME_FORMAT_IMAGEDATA = 'imagedata'\n\nNP_DISPLAY_FRAME_XOR_PATTERN = numpy.array(DISPLAY_FRAME_XOR_PATTERN, dtype=numpy.uint16)  # Numpy array version of the constant\n\n# Display code\ndef imagedata_to_bgr565(imagedata):\n    array = imagedata.to_py()\n    numpy_array = numpy.asarray(array)\n    numpy_array = numpy.delete(numpy_array, slice(3, None, 4)) # Remove A values (every 4th value)\n    numpy_array = numpy_array.reshape((DISPLAY_N_LINES,DISPLAY_LINE_PIXELS,3)) # Reshape to 960x160x3 \n    return rgb_to_bgr565(numpy_array) # Convert format\n\n# Non-vectorized function for converting from rgb to bgr565\ndef rgb_to_bgr565(rgb_frame):\n    # rgb_frame *= 255\n    rgb_frame_r = rgb_frame[:, :, 0].astype(numpy.uint16)\n    rgb_frame_g = rgb_frame[:, :, 1].astype(numpy.uint16)\n    rgb_frame_b = rgb_frame[:, :, 2].astype(numpy.uint16)\n    frame_r_filtered = numpy.bitwise_and(rgb_frame_r, int('0000000011111000', 2))\n    frame_r_shifted = numpy.right_shift(frame_r_filtered, 3)\n    frame_g_filtered = numpy.bitwise_and(rgb_frame_g, int('0000000011111100', 2))\n    frame_g_shifted = numpy.left_shift(frame_g_filtered, 3)\n    frame_b_filtered = numpy.bitwise_and(rgb_frame_b, int('0000000011111000', 2))\n    frame_b_shifted = numpy.left_shift(frame_b_filtered, 8)\n    combined = frame_r_shifted + frame_g_shifted + frame_b_shifted  # Combine all channels\n    return combined.transpose()\n\n\ndef prepare_frame(frame, input_format=FRAME_FORMAT_BGR565):\n    \"\"\"Prepare the given image frame to be shown in the Push2's display.\n    Depending on the input_format argument, \"frame\" must be a numpy array with the following characteristics:\n\n    * for FRAME_FORMAT_BGR565: numpy array of shape 910x160 and of uint16. Each uint16 element specifies rgb\n        color with the following bit position meaning: [b4 b3 b2 b1 b0 g5 g4 g3 g2 g1 g0 r4 r3 r2 r1 r0].\n\n    * for FRAME_FORMAT_RGB: numpy array of shape 910x160x3 with the third dimension representing rgb colors\n        with separate float values for rgb channels (float values in range [0.0, 1.0]).\n    \n    * for FRAME_FORMAT_IMAGEDATA: numpy array with 910 * 160 * 4 items\n        with separate int values for rgba channels (int values in range [0, 255]).\n\n    Preferred format is brg565 as it requires no conversion before sending to Push2. Using brg565 is also very fast\n    as color conversion is required but numpy handles it pretty well. You should be able to get frame rates higher than\n    30 fps, depending on the speed of your computer. However, using the rgb format (FRAME_FORMAT_RGB) will result in very \n    long frame preparation times that can take seconds. This can be highgly optimized so it is as fast as the other formats\n    but currently the library does not handle this format as nively. All numpy array elements are expected to be big endian.\n    In addition to format conversion (if needed), \"prepare_frame\" prepares the frame to be sent to push by adding\n    filler bytes and performing bitwise XOR as decribed in the Push2 specification.\n    See https://github.com/Ableton/push-interface/blob/master/doc/AbletonPush2MIDIDisplayInterface.asc#326-allocating-libusb-transfers\n    \"\"\"\n\n    assert input_format in [FRAME_FORMAT_BGR565, FRAME_FORMAT_RGB, FRAME_FORMAT_IMAGEDATA], 'Invalid frame format'\n\n    if input_format == FRAME_FORMAT_RGB:\n        # If format is rgb, do conversion before the rest as frame must be reshaped\n        # from (w, h, 3) to (w, h)\n        frame = rgb_to_bgr565(frame)\n    elif input_format == FRAME_FORMAT_IMAGEDATA:\n        frame = imagedata_to_bgr565(frame)\n\n    assert type(frame) == numpy.ndarray\n    assert frame.dtype == numpy.dtype('uint16')\n    assert frame.shape[0] == DISPLAY_LINE_PIXELS, 'Wrong number of pixels in line ({0})'.format(\n        frame.shape[0])\n    assert frame.shape[1] == DISPLAY_N_LINES, 'Wrong number of lines in frame ({0})'.format(\n        frame.shape[1])\n\n    width = DISPLAY_LINE_PIXELS + DISPLAY_LINE_FILLER_BYTES // 2\n    height = DISPLAY_N_LINES\n    prepared_frame = numpy.zeros(shape=(width, height), dtype=numpy.uint16)\n    prepared_frame[0:frame.shape[0], 0:frame.shape[1]] = frame\n    prepared_frame = prepared_frame.transpose().flatten()\n    if input_format == FRAME_FORMAT_BGR565:\n        pass  # Nothing to do as this is already the requested format\n    elif input_format == FRAME_FORMAT_RGB:\n        pass  # Nothing as conversion was done before\n    prepared_frame = prepared_frame.byteswap()  # Change to little endian\n    prepared_frame = numpy.bitwise_xor(prepared_frame, NP_DISPLAY_FRAME_XOR_PATTERN)\n\n    return prepared_frame.byteswap().tobytes()\n\n\ndef prepare_black_frame():\n    return prepare_frame(numpy.zeros((DISPLAY_LINE_PIXELS, DISPLAY_N_LINES), dtype=numpy.uint16))"})}async initializeUSB(){try{this.device=await navigator.usb.requestDevice({filters:[{vendorId:10626,productId:6503}]}),await this.callWorkerAsync("initializeUSB",{vendorId:this.device.vendorId,productId:this.device.productId})}catch(t){throw new Error(`USB connection error: ${t.message}`)}}async drawLoop(){for(;this._isDrawing;){const t=this.context.getImageData(0,0,Ou,Eu);await this.callWorkerAsync("drawFrame",{frame:t.data})}await this.callWorkerAsync("drawBlackFrame")}start(){this._isDrawing=!0,this.drawLoop()}stop(){this._isDrawing=!1}dispose(){this.stop(),(async()=>{await this.device.releaseInterface(0),await this.device.close()})()}callWorker(t,e,n){this.worker.onerror=n,this.worker.onmessage=t=>{const i=t.data;i.success?e(i.returnValue):n(i.error)},this.worker.postMessage(t)}async callWorkerAsync(t,e){return new Promise(((n,i)=>{this.callWorker({...e,action:t},n,i)}))}}var Pu=Ft(Object.freeze({__proto__:null,default:{}})),Iu=Nt((function(t,e){
  /*! Fabric.js Copyright 2008-2015, Printio (Juriy Zaytsev, Maxim Chernyak) */
  var n,i,s,r,o,a,c,l,h,u,d,f,p,m,g,v=v||{version:"4.5.0"};if(e.fabric=v,"undefined"!=typeof document&&"undefined"!=typeof window)document instanceof("undefined"!=typeof HTMLDocument?HTMLDocument:Document)?v.document=document:v.document=document.implementation.createHTMLDocument(""),v.window=window;else{var _=new Pu.JSDOM(decodeURIComponent("%3C!DOCTYPE%20html%3E%3Chtml%3E%3Chead%3E%3C%2Fhead%3E%3Cbody%3E%3C%2Fbody%3E%3C%2Fhtml%3E"),{features:{FetchExternalResources:["img"]},resources:"usable"}).window;v.document=_.document,v.jsdomImplForWrapper=Pu.implForWrapper,v.nodeCanvas=Pu.Canvas,v.window=_,DOMParser=v.window.DOMParser}function y(t,e){var n=t.canvas,i=e.targetCanvas,s=i.getContext("2d");s.translate(0,i.height),s.scale(1,-1);var r=n.height-i.height;s.drawImage(n,0,r,i.width,i.height,0,0,i.width,i.height)}function b(t,e){var n=e.targetCanvas.getContext("2d"),i=e.destinationWidth,s=e.destinationHeight,r=i*s*4,o=new Uint8Array(this.imageBuffer,0,r),a=new Uint8ClampedArray(this.imageBuffer,0,r);t.readPixels(0,0,i,s,t.RGBA,t.UNSIGNED_BYTE,o);var c=new ImageData(a,i,s);n.putImageData(c,0,0)}v.isTouchSupported="ontouchstart"in v.window||"ontouchstart"in v.document||v.window&&v.window.navigator&&v.window.navigator.maxTouchPoints>0,v.isLikelyNode="undefined"!=typeof Buffer&&"undefined"==typeof window,v.SHARED_ATTRIBUTES=["display","transform","fill","fill-opacity","fill-rule","opacity","stroke","stroke-dasharray","stroke-linecap","stroke-dashoffset","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke-width","id","paint-order","vector-effect","instantiated_by_use","clip-path"],v.DPI=96,v.reNum="(?:[-+]?(?:\\d+|\\d*\\.\\d+)(?:[eE][-+]?\\d+)?)",v.commaWsp="(?:\\s+,?\\s*|,\\s*)",v.rePathCommand=/([-+]?((\d+\.\d+)|((\d+)|(\.\d+)))(?:[eE][-+]?\d+)?)/gi,v.reNonWord=/[ \n\.,;!\?\-]/,v.fontPaths={},v.iMatrix=[1,0,0,1,0,0],v.svgNS="http://www.w3.org/2000/svg",v.perfLimitSizeTotal=2097152,v.maxCacheSideLimit=4096,v.minCacheSideLimit=256,v.charWidthsCache={},v.textureSize=2048,v.disableStyleCopyPaste=!1,v.enableGLFiltering=!0,v.devicePixelRatio=v.window.devicePixelRatio||v.window.webkitDevicePixelRatio||v.window.mozDevicePixelRatio||1,v.browserShadowBlurConstant=1,v.arcToSegmentsCache={},v.boundsOfCurveCache={},v.cachesBoundsOfCurve=!0,v.forceGLPutImageData=!1,v.initFilterBackend=function(){return v.enableGLFiltering&&v.isWebglSupported&&v.isWebglSupported(v.textureSize)?(console.log("max texture size: "+v.maxTextureSize),new v.WebglFilterBackend({tileSize:v.textureSize})):v.Canvas2dFilterBackend?new v.Canvas2dFilterBackend:void 0},"undefined"!=typeof document&&"undefined"!=typeof window&&(window.fabric=v),function(){function t(t,e){if(this.__eventListeners[t]){var n=this.__eventListeners[t];e?n[n.indexOf(e)]=!1:v.util.array.fill(n,!1)}}v.Observable={fire:function(t,e){if(!this.__eventListeners)return this;var n=this.__eventListeners[t];if(!n)return this;for(var i=0,s=n.length;i<s;i++)n[i]&&n[i].call(this,e||{});return this.__eventListeners[t]=n.filter((function(t){return!1!==t})),this},on:function(t,e){if(this.__eventListeners||(this.__eventListeners={}),1===arguments.length)for(var n in t)this.on(n,t[n]);else this.__eventListeners[t]||(this.__eventListeners[t]=[]),this.__eventListeners[t].push(e);return this},off:function(e,n){if(!this.__eventListeners)return this;if(0===arguments.length)for(e in this.__eventListeners)t.call(this,e);else if(1===arguments.length&&"object"==typeof arguments[0])for(var i in e)t.call(this,i,e[i]);else t.call(this,e,n);return this}}}(),v.Collection={_objects:[],add:function(){if(this._objects.push.apply(this._objects,arguments),this._onObjectAdded)for(var t=0,e=arguments.length;t<e;t++)this._onObjectAdded(arguments[t]);return this.renderOnAddRemove&&this.requestRenderAll(),this},insertAt:function(t,e,n){var i=this._objects;return n?i[e]=t:i.splice(e,0,t),this._onObjectAdded&&this._onObjectAdded(t),this.renderOnAddRemove&&this.requestRenderAll(),this},remove:function(){for(var t,e=this._objects,n=!1,i=0,s=arguments.length;i<s;i++)-1!==(t=e.indexOf(arguments[i]))&&(n=!0,e.splice(t,1),this._onObjectRemoved&&this._onObjectRemoved(arguments[i]));return this.renderOnAddRemove&&n&&this.requestRenderAll(),this},forEachObject:function(t,e){for(var n=this.getObjects(),i=0,s=n.length;i<s;i++)t.call(e,n[i],i,n);return this},getObjects:function(t){return void 0===t?this._objects.concat():this._objects.filter((function(e){return e.type===t}))},item:function(t){return this._objects[t]},isEmpty:function(){return 0===this._objects.length},size:function(){return this._objects.length},contains:function(t){return this._objects.indexOf(t)>-1},complexity:function(){return this._objects.reduce((function(t,e){return t+=e.complexity?e.complexity():0}),0)}},v.CommonMethods={_setOptions:function(t){for(var e in t)this.set(e,t[e])},_initGradient:function(t,e){!t||!t.colorStops||t instanceof v.Gradient||this.set(e,new v.Gradient(t))},_initPattern:function(t,e,n){!t||!t.source||t instanceof v.Pattern?n&&n():this.set(e,new v.Pattern(t,n))},_setObject:function(t){for(var e in t)this._set(e,t[e])},set:function(t,e){return"object"==typeof t?this._setObject(t):this._set(t,e),this},_set:function(t,e){this[t]=e},toggle:function(t){var e=this.get(t);return"boolean"==typeof e&&this.set(t,!e),this},get:function(t){return this[t]}},function(t){var e=Math.sqrt,n=Math.atan2,i=Math.pow,s=Math.PI/180,r=Math.PI/2;v.util={cos:function(t){if(0===t)return 1;switch(t<0&&(t=-t),t/r){case 1:case 3:return 0;case 2:return-1}return Math.cos(t)},sin:function(t){if(0===t)return 0;var e=1;switch(t<0&&(e=-1),t/r){case 1:return e;case 2:return 0;case 3:return-e}return Math.sin(t)},removeFromArray:function(t,e){var n=t.indexOf(e);return-1!==n&&t.splice(n,1),t},getRandomInt:function(t,e){return Math.floor(Math.random()*(e-t+1))+t},degreesToRadians:function(t){return t*s},radiansToDegrees:function(t){return t/s},rotatePoint:function(t,e,n){t.subtractEquals(e);var i=v.util.rotateVector(t,n);return new v.Point(i.x,i.y).addEquals(e)},rotateVector:function(t,e){var n=v.util.sin(e),i=v.util.cos(e);return{x:t.x*i-t.y*n,y:t.x*n+t.y*i}},transformPoint:function(t,e,n){return n?new v.Point(e[0]*t.x+e[2]*t.y,e[1]*t.x+e[3]*t.y):new v.Point(e[0]*t.x+e[2]*t.y+e[4],e[1]*t.x+e[3]*t.y+e[5])},makeBoundingBoxFromPoints:function(t,e){if(e)for(var n=0;n<t.length;n++)t[n]=v.util.transformPoint(t[n],e);var i=[t[0].x,t[1].x,t[2].x,t[3].x],s=v.util.array.min(i),r=v.util.array.max(i)-s,o=[t[0].y,t[1].y,t[2].y,t[3].y],a=v.util.array.min(o);return{left:s,top:a,width:r,height:v.util.array.max(o)-a}},invertTransform:function(t){var e=1/(t[0]*t[3]-t[1]*t[2]),n=[e*t[3],-e*t[1],-e*t[2],e*t[0]],i=v.util.transformPoint({x:t[4],y:t[5]},n,!0);return n[4]=-i.x,n[5]=-i.y,n},toFixed:function(t,e){return parseFloat(Number(t).toFixed(e))},parseUnit:function(t,e){var n=/\D{0,2}$/.exec(t),i=parseFloat(t);switch(e||(e=v.Text.DEFAULT_SVG_FONT_SIZE),n[0]){case"mm":return i*v.DPI/25.4;case"cm":return i*v.DPI/2.54;case"in":return i*v.DPI;case"pt":return i*v.DPI/72;case"pc":return i*v.DPI/72*12;case"em":return i*e;default:return i}},falseFunction:function(){return!1},getKlass:function(t,e){return t=v.util.string.camelize(t.charAt(0).toUpperCase()+t.slice(1)),v.util.resolveNamespace(e)[t]},getSvgAttributes:function(t){var e=["instantiated_by_use","style","id","class"];switch(t){case"linearGradient":e=e.concat(["x1","y1","x2","y2","gradientUnits","gradientTransform"]);break;case"radialGradient":e=e.concat(["gradientUnits","gradientTransform","cx","cy","r","fx","fy","fr"]);break;case"stop":e=e.concat(["offset","stop-color","stop-opacity"])}return e},resolveNamespace:function(e){if(!e)return v;var n,i=e.split("."),s=i.length,r=t||v.window;for(n=0;n<s;++n)r=r[i[n]];return r},loadImage:function(t,e,n,i){if(t){var s=v.util.createImage(),r=function(){e&&e.call(n,s,!1),s=s.onload=s.onerror=null};s.onload=r,s.onerror=function(){v.log("Error loading "+s.src),e&&e.call(n,null,!0),s=s.onload=s.onerror=null},0!==t.indexOf("data")&&null!=i&&(s.crossOrigin=i),"data:image/svg"===t.substring(0,14)&&(s.onload=null,v.util.loadImageInDom(s,r)),s.src=t}else e&&e.call(n,t)},loadImageInDom:function(t,e){var n=v.document.createElement("div");n.style.width=n.style.height="1px",n.style.left=n.style.top="-100%",n.style.position="absolute",n.appendChild(t),v.document.querySelector("body").appendChild(n),t.onload=function(){e(),n.parentNode.removeChild(n),n=null}},enlivenObjects:function(t,e,n,i){var s=[],r=0,o=(t=t||[]).length;function a(){++r===o&&e&&e(s.filter((function(t){return t})))}o?t.forEach((function(t,e){t&&t.type?v.util.getKlass(t.type,n).fromObject(t,(function(n,r){r||(s[e]=n),i&&i(t,n,r),a()})):a()})):e&&e(s)},enlivenPatterns:function(t,e){function n(){++s===r&&e&&e(i)}var i=[],s=0,r=(t=t||[]).length;r?t.forEach((function(t,e){t&&t.source?new v.Pattern(t,(function(t){i[e]=t,n()})):(i[e]=t,n())})):e&&e(i)},groupSVGElements:function(t,e,n){var i;return t&&1===t.length?t[0]:(e&&(e.width&&e.height?e.centerPoint={x:e.width/2,y:e.height/2}:(delete e.width,delete e.height)),i=new v.Group(t,e),void 0!==n&&(i.sourcePath=n),i)},populateWithProperties:function(t,e,n){if(n&&"[object Array]"===Object.prototype.toString.call(n))for(var i=0,s=n.length;i<s;i++)n[i]in t&&(e[n[i]]=t[n[i]])},drawDashedLine:function(t,i,s,r,o,a){var c=r-i,l=o-s,h=e(c*c+l*l),u=n(l,c),d=a.length,f=0,p=!0;for(t.save(),t.translate(i,s),t.moveTo(0,0),t.rotate(u),i=0;h>i;)(i+=a[f++%d])>h&&(i=h),t[p?"lineTo":"moveTo"](i,0),p=!p;t.restore()},createCanvasElement:function(){return v.document.createElement("canvas")},copyCanvasElement:function(t){var e=v.util.createCanvasElement();return e.width=t.width,e.height=t.height,e.getContext("2d").drawImage(t,0,0),e},toDataURL:function(t,e,n){return t.toDataURL("image/"+e,n)},createImage:function(){return v.document.createElement("img")},multiplyTransformMatrices:function(t,e,n){return[t[0]*e[0]+t[2]*e[1],t[1]*e[0]+t[3]*e[1],t[0]*e[2]+t[2]*e[3],t[1]*e[2]+t[3]*e[3],n?0:t[0]*e[4]+t[2]*e[5]+t[4],n?0:t[1]*e[4]+t[3]*e[5]+t[5]]},qrDecompose:function(t){var r=n(t[1],t[0]),o=i(t[0],2)+i(t[1],2),a=e(o),c=(t[0]*t[3]-t[2]*t[1])/a,l=n(t[0]*t[2]+t[1]*t[3],o);return{angle:r/s,scaleX:a,scaleY:c,skewX:l/s,skewY:0,translateX:t[4],translateY:t[5]}},calcRotateMatrix:function(t){if(!t.angle)return v.iMatrix.concat();var e=v.util.degreesToRadians(t.angle),n=v.util.cos(e),i=v.util.sin(e);return[n,i,-i,n,0,0]},calcDimensionsMatrix:function(t){var e=void 0===t.scaleX?1:t.scaleX,n=void 0===t.scaleY?1:t.scaleY,i=[t.flipX?-e:e,0,0,t.flipY?-n:n,0,0],s=v.util.multiplyTransformMatrices,r=v.util.degreesToRadians;return t.skewX&&(i=s(i,[1,0,Math.tan(r(t.skewX)),1],!0)),t.skewY&&(i=s(i,[1,Math.tan(r(t.skewY)),0,1],!0)),i},composeMatrix:function(t){var e=[1,0,0,1,t.translateX||0,t.translateY||0],n=v.util.multiplyTransformMatrices;return t.angle&&(e=n(e,v.util.calcRotateMatrix(t))),(1!==t.scaleX||1!==t.scaleY||t.skewX||t.skewY||t.flipX||t.flipY)&&(e=n(e,v.util.calcDimensionsMatrix(t))),e},resetObjectTransform:function(t){t.scaleX=1,t.scaleY=1,t.skewX=0,t.skewY=0,t.flipX=!1,t.flipY=!1,t.rotate(0)},saveObjectTransform:function(t){return{scaleX:t.scaleX,scaleY:t.scaleY,skewX:t.skewX,skewY:t.skewY,angle:t.angle,left:t.left,flipX:t.flipX,flipY:t.flipY,top:t.top}},isTransparent:function(t,e,n,i){i>0&&(e>i?e-=i:e=0,n>i?n-=i:n=0);var s,r=!0,o=t.getImageData(e,n,2*i||1,2*i||1),a=o.data.length;for(s=3;s<a&&!1!==(r=o.data[s]<=0);s+=4);return o=null,r},parsePreserveAspectRatioAttribute:function(t){var e,n="meet",i=t.split(" ");return i&&i.length&&("meet"!==(n=i.pop())&&"slice"!==n?(e=n,n="meet"):i.length&&(e=i.pop())),{meetOrSlice:n,alignX:"none"!==e?e.slice(1,4):"none",alignY:"none"!==e?e.slice(5,8):"none"}},clearFabricFontCache:function(t){(t=(t||"").toLowerCase())?v.charWidthsCache[t]&&delete v.charWidthsCache[t]:v.charWidthsCache={}},limitDimsByArea:function(t,e){var n=Math.sqrt(e*t),i=Math.floor(e/n);return{x:Math.floor(n),y:i}},capValue:function(t,e,n){return Math.max(t,Math.min(e,n))},findScaleToFit:function(t,e){return Math.min(e.width/t.width,e.height/t.height)},findScaleToCover:function(t,e){return Math.max(e.width/t.width,e.height/t.height)},matrixToSVG:function(t){return"matrix("+t.map((function(t){return v.util.toFixed(t,v.Object.NUM_FRACTION_DIGITS)})).join(" ")+")"},removeTransformFromObject:function(t,e){var n=v.util.invertTransform(e),i=v.util.multiplyTransformMatrices(n,t.calcOwnMatrix());v.util.applyTransformToObject(t,i)},addTransformToObject:function(t,e){v.util.applyTransformToObject(t,v.util.multiplyTransformMatrices(e,t.calcOwnMatrix()))},applyTransformToObject:function(t,e){var n=v.util.qrDecompose(e),i=new v.Point(n.translateX,n.translateY);t.flipX=!1,t.flipY=!1,t.set("scaleX",n.scaleX),t.set("scaleY",n.scaleY),t.skewX=n.skewX,t.skewY=n.skewY,t.angle=n.angle,t.setPositionByOrigin(i,"center","center")},sizeAfterTransform:function(t,e,n){var i=t/2,s=e/2,r=[{x:-i,y:-s},{x:i,y:-s},{x:-i,y:s},{x:i,y:s}],o=v.util.calcDimensionsMatrix(n),a=v.util.makeBoundingBoxFromPoints(r,o);return{x:a.width,y:a.height}}}}(e),function(){var t=Array.prototype.join,e={m:2,l:2,h:1,v:1,c:6,s:4,q:4,t:2,a:7},n={m:"l",M:"L"};function i(t,e,n,i,s,r,o,a,c,l,h){var u=v.util.cos(t),d=v.util.sin(t),f=v.util.cos(e),p=v.util.sin(e),m=n*s*f-i*r*p+o,g=i*s*f+n*r*p+a;return["C",l+c*(-n*s*d-i*r*u),h+c*(-i*s*d+n*r*u),m+c*(n*s*p+i*r*f),g+c*(i*s*p-n*r*f),m,g]}function s(t,e,n,s,o,a,c){var l=Math.PI,h=c*l/180,u=v.util.sin(h),d=v.util.cos(h),f=0,p=0,m=-d*t*.5-u*e*.5,g=-d*e*.5+u*t*.5,_=(n=Math.abs(n))*n,y=(s=Math.abs(s))*s,b=g*g,x=m*m,C=_*y-_*b-y*x,w=0;if(C<0){var S=Math.sqrt(1-C/(_*y));n*=S,s*=S}else w=(o===a?-1:1)*Math.sqrt(C/(_*b+y*x));var T=w*n*g/s,M=-w*s*m/n,A=d*T-u*M+.5*t,O=u*T+d*M+.5*e,E=r(1,0,(m-T)/n,(g-M)/s),k=r((m-T)/n,(g-M)/s,(-m-T)/n,(-g-M)/s);0===a&&k>0?k-=2*l:1===a&&k<0&&(k+=2*l);for(var P=Math.ceil(Math.abs(k/l*2)),I=[],D=k/P,R=8/3*Math.sin(D/4)*Math.sin(D/4)/Math.sin(D/2),j=E+D,$=0;$<P;$++)I[$]=i(E,j,d,u,n,s,A,O,R,f,p),f=I[$][5],p=I[$][6],E=j,j+=D;return I}function r(t,e,n,i){var s=Math.atan2(e,t),r=Math.atan2(i,n);return r>=s?r-s:2*Math.PI-(s-r)}function o(e,n,i,s,r,o,a,c){var l;if(v.cachesBoundsOfCurve&&(l=t.call(arguments),v.boundsOfCurveCache[l]))return v.boundsOfCurveCache[l];var h,u,d,f,p,m,g,_,y=Math.sqrt,b=Math.min,x=Math.max,C=Math.abs,w=[],S=[[],[]];u=6*e-12*i+6*r,h=-3*e+9*i-9*r+3*a,d=3*i-3*e;for(var T=0;T<2;++T)if(T>0&&(u=6*n-12*s+6*o,h=-3*n+9*s-9*o+3*c,d=3*s-3*n),C(h)<1e-12){if(C(u)<1e-12)continue;0<(f=-d/u)&&f<1&&w.push(f)}else(g=u*u-4*d*h)<0||(0<(p=(-u+(_=y(g)))/(2*h))&&p<1&&w.push(p),0<(m=(-u-_)/(2*h))&&m<1&&w.push(m));for(var M,A,O,E=w.length,k=E;E--;)M=(O=1-(f=w[E]))*O*O*e+3*O*O*f*i+3*O*f*f*r+f*f*f*a,S[0][E]=M,A=O*O*O*n+3*O*O*f*s+3*O*f*f*o+f*f*f*c,S[1][E]=A;S[0][k]=e,S[1][k]=n,S[0][k+1]=a,S[1][k+1]=c;var P=[{x:b.apply(null,S[0]),y:b.apply(null,S[1])},{x:x.apply(null,S[0]),y:x.apply(null,S[1])}];return v.cachesBoundsOfCurve&&(v.boundsOfCurveCache[l]=P),P}function a(t,e,n){for(var i=n[1],r=n[2],o=n[3],a=n[4],c=n[5],l=s(n[6]-t,n[7]-e,i,r,a,c,o),h=0,u=l.length;h<u;h++)l[h][1]+=t,l[h][2]+=e,l[h][3]+=t,l[h][4]+=e,l[h][5]+=t,l[h][6]+=e;return l}function c(t,e,n,i){return Math.sqrt((n-t)*(n-t)+(i-e)*(i-e))}function l(t,e,n,i,s,r,o,a){return function(c){var l,h=(l=c)*l*l,u=function(t){return 3*t*t*(1-t)}(c),d=function(t){return 3*t*(1-t)*(1-t)}(c),f=function(t){return(1-t)*(1-t)*(1-t)}(c);return{x:o*h+s*u+n*d+t*f,y:a*h+r*u+i*d+e*f}}}function h(t,e,n,i,s,r,o,a){return function(c){var l=1-c,h=3*l*l*(n-t)+6*l*c*(s-n)+3*c*c*(o-s),u=3*l*l*(i-e)+6*l*c*(r-i)+3*c*c*(a-r);return Math.atan2(u,h)}}function u(t,e,n,i,s,r){return function(o){var a,c=(a=o)*a,l=function(t){return 2*t*(1-t)}(o),h=function(t){return(1-t)*(1-t)}(o);return{x:s*c+n*l+t*h,y:r*c+i*l+e*h}}}function d(t,e,n,i,s,r){return function(o){var a=1-o,c=2*a*(n-t)+2*o*(s-n),l=2*a*(i-e)+2*o*(r-i);return Math.atan2(l,c)}}function f(t,e,n){var i,s,r={x:e,y:n},o=0;for(s=.01;s<=1;s+=.01)i=t(s),o+=c(r.x,r.y,i.x,i.y),r=i;return o}function p(t,e){for(var n,i,s,r=0,o=0,a=t.iterator,l={x:t.x,y:t.y},h=.01,u=t.angleFinder;o<e&&r<=1&&h>1e-4;)n=a(r),s=r,(i=c(l.x,l.y,n.x,n.y))+o>e?r-=h/=2:(l=n,r+=h,o+=i);return n.angle=u(s),n}function m(t){for(var e,n,i,s,r=0,o=t.length,a=0,p=0,m=0,g=0,v=[],_=0;_<o;_++){switch(i={x:a,y:p,command:(e=t[_])[0]},e[0]){case"M":i.length=0,m=a=e[1],g=p=e[2];break;case"L":i.length=c(a,p,e[1],e[2]),a=e[1],p=e[2];break;case"C":n=l(a,p,e[1],e[2],e[3],e[4],e[5],e[6]),s=h(a,p,e[1],e[2],e[3],e[4],e[5],e[6]),i.iterator=n,i.angleFinder=s,i.length=f(n,a,p),a=e[5],p=e[6];break;case"Q":n=u(a,p,e[1],e[2],e[3],e[4]),s=d(a,p,e[1],e[2],e[3],e[4]),i.iterator=n,i.angleFinder=s,i.length=f(n,a,p),a=e[3],p=e[4];break;case"Z":case"z":i.destX=m,i.destY=g,i.length=c(a,p,m,g),a=m,p=g}r+=i.length,v.push(i)}return v.push({length:r,x:a,y:p}),v}v.util.parsePath=function(t){var i,s,r,o,a,c=[],l=[],h=v.rePathCommand,u="[-+]?(?:\\d*\\.\\d+|\\d+\\.?)(?:[eE][-+]?\\d+)?\\s*",d="("+u+")"+v.commaWsp,f="([01])"+v.commaWsp+"?",p=new RegExp(d+"?"+d+"?"+d+f+f+d+"?("+u+")","g");if(!t||!t.match)return c;for(var m,g=0,_=(a=t.match(/[mzlhvcsqta][^mzlhvcsqta]*/gi)).length;g<_;g++){o=(i=a[g]).slice(1).trim(),l.length=0;var y=i.charAt(0);if(m=[y],"a"===y.toLowerCase())for(var b;b=p.exec(o);)for(var x=1;x<b.length;x++)l.push(b[x]);else for(;r=h.exec(o);)l.push(r[0]);x=0;for(var C=l.length;x<C;x++)s=parseFloat(l[x]),isNaN(s)||m.push(s);var w=e[y.toLowerCase()],S=n[y]||y;if(m.length-1>w)for(var T=1,M=m.length;T<M;T+=w)c.push([y].concat(m.slice(T,T+w))),y=S;else c.push(m)}return c},v.util.makePathSimpler=function(t){var e,n,i,s,r,o,c=0,l=0,h=t.length,u=0,d=0,f=[];for(n=0;n<h;++n){switch(i=!1,(e=t[n].slice(0))[0]){case"l":e[0]="L",e[1]+=c,e[2]+=l;case"L":c=e[1],l=e[2];break;case"h":e[1]+=c;case"H":e[0]="L",e[2]=l,c=e[1];break;case"v":e[1]+=l;case"V":e[0]="L",l=e[1],e[1]=c,e[2]=l;break;case"m":e[0]="M",e[1]+=c,e[2]+=l;case"M":c=e[1],l=e[2],u=e[1],d=e[2];break;case"c":e[0]="C",e[1]+=c,e[2]+=l,e[3]+=c,e[4]+=l,e[5]+=c,e[6]+=l;case"C":r=e[3],o=e[4],c=e[5],l=e[6];break;case"s":e[0]="S",e[1]+=c,e[2]+=l,e[3]+=c,e[4]+=l;case"S":"C"===s?(r=2*c-r,o=2*l-o):(r=c,o=l),c=e[3],l=e[4],e[0]="C",e[5]=e[3],e[6]=e[4],e[3]=e[1],e[4]=e[2],e[1]=r,e[2]=o,r=e[3],o=e[4];break;case"q":e[0]="Q",e[1]+=c,e[2]+=l,e[3]+=c,e[4]+=l;case"Q":r=e[1],o=e[2],c=e[3],l=e[4];break;case"t":e[0]="T",e[1]+=c,e[2]+=l;case"T":"Q"===s?(r=2*c-r,o=2*l-o):(r=c,o=l),e[0]="Q",c=e[1],l=e[2],e[1]=r,e[2]=o,e[3]=c,e[4]=l;break;case"a":e[0]="A",e[6]+=c,e[7]+=l;case"A":i=!0,f=f.concat(a(c,l,e)),c=e[6],l=e[7];break;case"z":case"Z":c=u,l=d}i||f.push(e),s=e[0]}return f},v.util.getPathSegmentsInfo=m,v.util.fromArcToBeziers=a,v.util.fromArcToBeizers=a,v.util.getBoundsOfCurve=o,v.util.getPointOnPath=function(t,e,n){n||(n=m(t));for(var i=0;e-n[i].length>0&&i<n.length-2;)e-=n[i].length,i++;var s,r=n[i],o=e/r.length,a=r.command,c=t[i];switch(a){case"M":return{x:r.x,y:r.y,angle:0};case"Z":case"z":return(s=new v.Point(r.x,r.y).lerp(new v.Point(r.destX,r.destY),o)).angle=Math.atan2(r.destY-r.y,r.destX-r.x),s;case"L":return(s=new v.Point(r.x,r.y).lerp(new v.Point(c[1],c[2]),o)).angle=Math.atan2(c[2]-r.y,c[1]-r.x),s;case"C":case"Q":return p(r,e)}},v.util.getBoundsOfArc=function(t,e,n,i,r,a,c,l,h){for(var u,d=0,f=0,p=[],m=s(l-t,h-e,n,i,a,c,r),g=0,v=m.length;g<v;g++)u=o(d,f,m[g][1],m[g][2],m[g][3],m[g][4],m[g][5],m[g][6]),p.push({x:u[0].x+t,y:u[0].y+e}),p.push({x:u[1].x+t,y:u[1].y+e}),d=m[g][5],f=m[g][6];return p},v.util.drawArc=function(t,e,n,i){a(e,n,i=i.slice(0).unshift("X")).forEach((function(e){t.bezierCurveTo.apply(t,e.slice(1))}))}}(),function(){var t=Array.prototype.slice;function e(t,e,n){if(t&&0!==t.length){var i=t.length-1,s=e?t[i][e]:t[i];if(e)for(;i--;)n(t[i][e],s)&&(s=t[i][e]);else for(;i--;)n(t[i],s)&&(s=t[i]);return s}}v.util.array={fill:function(t,e){for(var n=t.length;n--;)t[n]=e;return t},invoke:function(e,n){for(var i=t.call(arguments,2),s=[],r=0,o=e.length;r<o;r++)s[r]=i.length?e[r][n].apply(e[r],i):e[r][n].call(e[r]);return s},min:function(t,n){return e(t,n,(function(t,e){return t<e}))},max:function(t,n){return e(t,n,(function(t,e){return t>=e}))}}}(),function(){function t(e,n,i){if(i)if(!v.isLikelyNode&&n instanceof Element)e=n;else if(n instanceof Array){e=[];for(var s=0,r=n.length;s<r;s++)e[s]=t({},n[s],i)}else if(n&&"object"==typeof n)for(var o in n)"canvas"===o||"group"===o?e[o]=null:n.hasOwnProperty(o)&&(e[o]=t({},n[o],i));else e=n;else for(var o in n)e[o]=n[o];return e}v.util.object={extend:t,clone:function(e,n){return t({},e,n)}},v.util.object.extend(v.util,v.Observable)}(),function(){function t(t,e){var n=t.charCodeAt(e);if(isNaN(n))return"";if(n<55296||n>57343)return t.charAt(e);if(55296<=n&&n<=56319){if(t.length<=e+1)throw"High surrogate without following low surrogate";var i=t.charCodeAt(e+1);if(56320>i||i>57343)throw"High surrogate without following low surrogate";return t.charAt(e)+t.charAt(e+1)}if(0===e)throw"Low surrogate without preceding high surrogate";var s=t.charCodeAt(e-1);if(55296>s||s>56319)throw"Low surrogate without preceding high surrogate";return!1}v.util.string={camelize:function(t){return t.replace(/-+(.)?/g,(function(t,e){return e?e.toUpperCase():""}))},capitalize:function(t,e){return t.charAt(0).toUpperCase()+(e?t.slice(1):t.slice(1).toLowerCase())},escapeXml:function(t){return t.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/'/g,"&apos;").replace(/</g,"&lt;").replace(/>/g,"&gt;")},graphemeSplit:function(e){var n,i=0,s=[];for(i=0;i<e.length;i++)!1!==(n=t(e,i))&&s.push(n);return s}}}(),function(){var t=Array.prototype.slice,e=function(){},n=function(){for(var t in{toString:1})if("toString"===t)return!1;return!0}(),i=function(t,e,i){for(var s in e)s in t.prototype&&"function"==typeof t.prototype[s]&&(e[s]+"").indexOf("callSuper")>-1?t.prototype[s]=function(t){return function(){var n=this.constructor.superclass;this.constructor.superclass=i;var s=e[t].apply(this,arguments);if(this.constructor.superclass=n,"initialize"!==t)return s}}(s):t.prototype[s]=e[s],n&&(e.toString!==Object.prototype.toString&&(t.prototype.toString=e.toString),e.valueOf!==Object.prototype.valueOf&&(t.prototype.valueOf=e.valueOf))};function s(){}function r(e){for(var n=null,i=this;i.constructor.superclass;){var s=i.constructor.superclass.prototype[e];if(i[e]!==s){n=s;break}i=i.constructor.superclass.prototype}return n?arguments.length>1?n.apply(this,t.call(arguments,1)):n.call(this):console.log("tried to callSuper "+e+", method not found in prototype chain",this)}v.util.createClass=function(){var n=null,o=t.call(arguments,0);function a(){this.initialize.apply(this,arguments)}"function"==typeof o[0]&&(n=o.shift()),a.superclass=n,a.subclasses=[],n&&(s.prototype=n.prototype,a.prototype=new s,n.subclasses.push(a));for(var c=0,l=o.length;c<l;c++)i(a,o[c],n);return a.prototype.initialize||(a.prototype.initialize=e),a.prototype.constructor=a,a.prototype.callSuper=r,a}}(),n=!!v.document.createElement("div").attachEvent,i=["touchstart","touchmove","touchend"],v.util.addListener=function(t,e,i,s){t&&t.addEventListener(e,i,!n&&s)},v.util.removeListener=function(t,e,i,s){t&&t.removeEventListener(e,i,!n&&s)},v.util.getPointer=function(t){var e=t.target,n=v.util.getScrollLeftTop(e),i=function(t){var e=t.changedTouches;return e&&e[0]?e[0]:t}(t);return{x:i.clientX+n.left,y:i.clientY+n.top}},v.util.isTouchEvent=function(t){return i.indexOf(t.type)>-1||"touch"===t.pointerType},s=v.document.createElement("div"),r="string"==typeof s.style.opacity,o="string"==typeof s.style.filter,a=/alpha\s*\(\s*opacity\s*=\s*([^\)]+)\)/,c=function(t){return t},r?c=function(t,e){return t.style.opacity=e,t}:o&&(c=function(t,e){var n=t.style;return t.currentStyle&&!t.currentStyle.hasLayout&&(n.zoom=1),a.test(n.filter)?(e=e>=.9999?"":"alpha(opacity="+100*e+")",n.filter=n.filter.replace(a,e)):n.filter+=" alpha(opacity="+100*e+")",t}),v.util.setStyle=function(t,e){var n=t.style;if(!n)return t;if("string"==typeof e)return t.style.cssText+=";"+e,e.indexOf("opacity")>-1?c(t,e.match(/opacity:\s*(\d?\.?\d*)/)[1]):t;for(var i in e)"opacity"===i?c(t,e[i]):n["float"===i||"cssFloat"===i?void 0===n.styleFloat?"cssFloat":"styleFloat":i]=e[i];return t},function(){var t=Array.prototype.slice;var e,n,i,s,r=function(e){return t.call(e,0)};try{e=r(v.document.childNodes)instanceof Array}catch(t){}function o(t,e){var n=v.document.createElement(t);for(var i in e)"class"===i?n.className=e[i]:"for"===i?n.htmlFor=e[i]:n.setAttribute(i,e[i]);return n}function a(t){for(var e=0,n=0,i=v.document.documentElement,s=v.document.body||{scrollLeft:0,scrollTop:0};t&&(t.parentNode||t.host)&&((t=t.parentNode||t.host)===v.document?(e=s.scrollLeft||i.scrollLeft||0,n=s.scrollTop||i.scrollTop||0):(e+=t.scrollLeft||0,n+=t.scrollTop||0),1!==t.nodeType||"fixed"!==t.style.position););return{left:e,top:n}}e||(r=function(t){for(var e=new Array(t.length),n=t.length;n--;)e[n]=t[n];return e}),n=v.document.defaultView&&v.document.defaultView.getComputedStyle?function(t,e){var n=v.document.defaultView.getComputedStyle(t,null);return n?n[e]:void 0}:function(t,e){var n=t.style[e];return!n&&t.currentStyle&&(n=t.currentStyle[e]),n},i=v.document.documentElement.style,s="userSelect"in i?"userSelect":"MozUserSelect"in i?"MozUserSelect":"WebkitUserSelect"in i?"WebkitUserSelect":"KhtmlUserSelect"in i?"KhtmlUserSelect":"",v.util.makeElementUnselectable=function(t){return void 0!==t.onselectstart&&(t.onselectstart=v.util.falseFunction),s?t.style[s]="none":"string"==typeof t.unselectable&&(t.unselectable="on"),t},v.util.makeElementSelectable=function(t){return void 0!==t.onselectstart&&(t.onselectstart=null),s?t.style[s]="":"string"==typeof t.unselectable&&(t.unselectable=""),t},v.util.setImageSmoothing=function(t,e){t.imageSmoothingEnabled=t.imageSmoothingEnabled||t.webkitImageSmoothingEnabled||t.mozImageSmoothingEnabled||t.msImageSmoothingEnabled||t.oImageSmoothingEnabled,t.imageSmoothingEnabled=e},v.util.getById=function(t){return"string"==typeof t?v.document.getElementById(t):t},v.util.toArray=r,v.util.addClass=function(t,e){t&&-1===(" "+t.className+" ").indexOf(" "+e+" ")&&(t.className+=(t.className?" ":"")+e)},v.util.makeElement=o,v.util.wrapElement=function(t,e,n){return"string"==typeof e&&(e=o(e,n)),t.parentNode&&t.parentNode.replaceChild(e,t),e.appendChild(t),e},v.util.getScrollLeftTop=a,v.util.getElementOffset=function(t){var e,i,s=t&&t.ownerDocument,r={left:0,top:0},o={left:0,top:0},c={borderLeftWidth:"left",borderTopWidth:"top",paddingLeft:"left",paddingTop:"top"};if(!s)return o;for(var l in c)o[c[l]]+=parseInt(n(t,l),10)||0;return e=s.documentElement,void 0!==t.getBoundingClientRect&&(r=t.getBoundingClientRect()),i=a(t),{left:r.left+i.left-(e.clientLeft||0)+o.left,top:r.top+i.top-(e.clientTop||0)+o.top}},v.util.getNodeCanvas=function(t){var e=v.jsdomImplForWrapper(t);return e._canvas||e._image},v.util.cleanUpJsdomNode=function(t){if(v.isLikelyNode){var e=v.jsdomImplForWrapper(t);e&&(e._image=null,e._canvas=null,e._currentSrc=null,e._attributes=null,e._classList=null)}}}(),function(){function t(){}v.util.request=function(e,n){n||(n={});var i=n.method?n.method.toUpperCase():"GET",s=n.onComplete||function(){},r=new v.window.XMLHttpRequest,o=n.body||n.parameters;return r.onreadystatechange=function(){4===r.readyState&&(s(r),r.onreadystatechange=t)},"GET"===i&&(o=null,"string"==typeof n.parameters&&(e=function(t,e){return t+(/\?/.test(t)?"&":"?")+e}(e,n.parameters))),r.open(i,e,!0),"POST"!==i&&"PUT"!==i||r.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),r.send(o),r}}(),v.log=console.log,v.warn=console.warn,function(){function t(){return!1}function e(t,e,n,i){return-n*Math.cos(t/i*(Math.PI/2))+n+e}var n=v.window.requestAnimationFrame||v.window.webkitRequestAnimationFrame||v.window.mozRequestAnimationFrame||v.window.oRequestAnimationFrame||v.window.msRequestAnimationFrame||function(t){return v.window.setTimeout(t,1e3/60)},i=v.window.cancelAnimationFrame||v.window.clearTimeout;function s(){return n.apply(v.window,arguments)}v.util.animate=function(n){s((function(i){n||(n={});var r,o=i||+new Date,a=n.duration||500,c=o+a,l=n.onChange||t,h=n.abort||t,u=n.onComplete||t,d=n.easing||e,f="startValue"in n?n.startValue:0,p="endValue"in n?n.endValue:100,m=n.byValue||p-f;n.onStart&&n.onStart(),function t(e){var n=(r=e||+new Date)>c?a:r-o,i=n/a,g=d(n,f,m,a),v=Math.abs((g-f)/m);if(!h())return r>c?(l(p,1,1),void u(p,1,1)):(l(g,v,i),void s(t));u(p,1,1)}(o)}))},v.util.requestAnimFrame=s,v.util.cancelAnimFrame=function(){return i.apply(v.window,arguments)}}(),function(){function t(t,e,n){var i="rgba("+parseInt(t[0]+n*(e[0]-t[0]),10)+","+parseInt(t[1]+n*(e[1]-t[1]),10)+","+parseInt(t[2]+n*(e[2]-t[2]),10);return i+=","+(t&&e?parseFloat(t[3]+n*(e[3]-t[3])):1),i+=")"}v.util.animateColor=function(e,n,i,s){var r=new v.Color(e).getSource(),o=new v.Color(n).getSource(),a=s.onComplete,c=s.onChange;s=s||{},v.util.animate(v.util.object.extend(s,{duration:i||500,startValue:r,endValue:o,byValue:o,easing:function(e,n,i,r){return t(n,i,s.colorEasing?s.colorEasing(e,r):1-Math.cos(e/r*(Math.PI/2)))},onComplete:function(e,n,i){if(a)return a(t(o,o,0),n,i)},onChange:function(e,n,i){if(c){if(Array.isArray(e))return c(t(e,e,0),n,i);c(e,n,i)}}}))}}(),function(){function t(t,e,n,i){return t<Math.abs(e)?(t=e,i=n/4):i=0===e&&0===t?n/(2*Math.PI)*Math.asin(1):n/(2*Math.PI)*Math.asin(e/t),{a:t,c:e,p:n,s:i}}function e(t,e,n){return t.a*Math.pow(2,10*(e-=1))*Math.sin((e*n-t.s)*(2*Math.PI)/t.p)}function n(t,e,n,s){return n-i(s-t,0,n,s)+e}function i(t,e,n,i){return(t/=i)<1/2.75?n*(7.5625*t*t)+e:t<2/2.75?n*(7.5625*(t-=1.5/2.75)*t+.75)+e:t<2.5/2.75?n*(7.5625*(t-=2.25/2.75)*t+.9375)+e:n*(7.5625*(t-=2.625/2.75)*t+.984375)+e}v.util.ease={easeInQuad:function(t,e,n,i){return n*(t/=i)*t+e},easeOutQuad:function(t,e,n,i){return-n*(t/=i)*(t-2)+e},easeInOutQuad:function(t,e,n,i){return(t/=i/2)<1?n/2*t*t+e:-n/2*(--t*(t-2)-1)+e},easeInCubic:function(t,e,n,i){return n*(t/=i)*t*t+e},easeOutCubic:function(t,e,n,i){return n*((t=t/i-1)*t*t+1)+e},easeInOutCubic:function(t,e,n,i){return(t/=i/2)<1?n/2*t*t*t+e:n/2*((t-=2)*t*t+2)+e},easeInQuart:function(t,e,n,i){return n*(t/=i)*t*t*t+e},easeOutQuart:function(t,e,n,i){return-n*((t=t/i-1)*t*t*t-1)+e},easeInOutQuart:function(t,e,n,i){return(t/=i/2)<1?n/2*t*t*t*t+e:-n/2*((t-=2)*t*t*t-2)+e},easeInQuint:function(t,e,n,i){return n*(t/=i)*t*t*t*t+e},easeOutQuint:function(t,e,n,i){return n*((t=t/i-1)*t*t*t*t+1)+e},easeInOutQuint:function(t,e,n,i){return(t/=i/2)<1?n/2*t*t*t*t*t+e:n/2*((t-=2)*t*t*t*t+2)+e},easeInSine:function(t,e,n,i){return-n*Math.cos(t/i*(Math.PI/2))+n+e},easeOutSine:function(t,e,n,i){return n*Math.sin(t/i*(Math.PI/2))+e},easeInOutSine:function(t,e,n,i){return-n/2*(Math.cos(Math.PI*t/i)-1)+e},easeInExpo:function(t,e,n,i){return 0===t?e:n*Math.pow(2,10*(t/i-1))+e},easeOutExpo:function(t,e,n,i){return t===i?e+n:n*(1-Math.pow(2,-10*t/i))+e},easeInOutExpo:function(t,e,n,i){return 0===t?e:t===i?e+n:(t/=i/2)<1?n/2*Math.pow(2,10*(t-1))+e:n/2*(2-Math.pow(2,-10*--t))+e},easeInCirc:function(t,e,n,i){return-n*(Math.sqrt(1-(t/=i)*t)-1)+e},easeOutCirc:function(t,e,n,i){return n*Math.sqrt(1-(t=t/i-1)*t)+e},easeInOutCirc:function(t,e,n,i){return(t/=i/2)<1?-n/2*(Math.sqrt(1-t*t)-1)+e:n/2*(Math.sqrt(1-(t-=2)*t)+1)+e},easeInElastic:function(n,i,s,r){var o=0;return 0===n?i:1===(n/=r)?i+s:(o||(o=.3*r),-e(t(s,s,o,1.70158),n,r)+i)},easeOutElastic:function(e,n,i,s){var r=0;if(0===e)return n;if(1===(e/=s))return n+i;r||(r=.3*s);var o=t(i,i,r,1.70158);return o.a*Math.pow(2,-10*e)*Math.sin((e*s-o.s)*(2*Math.PI)/o.p)+o.c+n},easeInOutElastic:function(n,i,s,r){var o=0;if(0===n)return i;if(2===(n/=r/2))return i+s;o||(o=r*(.3*1.5));var a=t(s,s,o,1.70158);return n<1?-.5*e(a,n,r)+i:a.a*Math.pow(2,-10*(n-=1))*Math.sin((n*r-a.s)*(2*Math.PI)/a.p)*.5+a.c+i},easeInBack:function(t,e,n,i,s){return void 0===s&&(s=1.70158),n*(t/=i)*t*((s+1)*t-s)+e},easeOutBack:function(t,e,n,i,s){return void 0===s&&(s=1.70158),n*((t=t/i-1)*t*((s+1)*t+s)+1)+e},easeInOutBack:function(t,e,n,i,s){return void 0===s&&(s=1.70158),(t/=i/2)<1?n/2*(t*t*((1+(s*=1.525))*t-s))+e:n/2*((t-=2)*t*((1+(s*=1.525))*t+s)+2)+e},easeInBounce:n,easeOutBounce:i,easeInOutBounce:function(t,e,s,r){return t<r/2?.5*n(2*t,0,s,r)+e:.5*i(2*t-r,0,s,r)+.5*s+e}}}(),function(t){var e=t.fabric||(t.fabric={}),n=e.util.object.extend,i=e.util.object.clone,s=e.util.toFixed,r=e.util.parseUnit,o=e.util.multiplyTransformMatrices,a={cx:"left",x:"left",r:"radius",cy:"top",y:"top",display:"visible",visibility:"visible",transform:"transformMatrix","fill-opacity":"fillOpacity","fill-rule":"fillRule","font-family":"fontFamily","font-size":"fontSize","font-style":"fontStyle","font-weight":"fontWeight","letter-spacing":"charSpacing","paint-order":"paintFirst","stroke-dasharray":"strokeDashArray","stroke-dashoffset":"strokeDashOffset","stroke-linecap":"strokeLineCap","stroke-linejoin":"strokeLineJoin","stroke-miterlimit":"strokeMiterLimit","stroke-opacity":"strokeOpacity","stroke-width":"strokeWidth","text-decoration":"textDecoration","text-anchor":"textAnchor",opacity:"opacity","clip-path":"clipPath","clip-rule":"clipRule","vector-effect":"strokeUniform","image-rendering":"imageSmoothing"},c={stroke:"strokeOpacity",fill:"fillOpacity"},l="font-size",h="clip-path";function u(t){return t in a?a[t]:t}function d(t,n,i,s){var a,c="[object Array]"===Object.prototype.toString.call(n);if("fill"!==t&&"stroke"!==t||"none"!==n){if("strokeUniform"===t)return"non-scaling-stroke"===n;if("strokeDashArray"===t)n="none"===n?null:n.replace(/,/g," ").split(/\s+/).map(parseFloat);else if("transformMatrix"===t)n=i&&i.transformMatrix?o(i.transformMatrix,e.parseTransformAttribute(n)):e.parseTransformAttribute(n);else if("visible"===t)n="none"!==n&&"hidden"!==n,i&&!1===i.visible&&(n=!1);else if("opacity"===t)n=parseFloat(n),i&&void 0!==i.opacity&&(n*=i.opacity);else if("textAnchor"===t)n="start"===n?"left":"end"===n?"right":"center";else if("charSpacing"===t)a=r(n,s)/s*1e3;else if("paintFirst"===t){var l=n.indexOf("fill"),h=n.indexOf("stroke");n="fill";(l>-1&&h>-1&&h<l||-1===l&&h>-1)&&(n="stroke")}else{if("href"===t||"xlink:href"===t||"font"===t)return n;if("imageSmoothing"===t)return"optimizeQuality"===n;a=c?n.map(r):r(n,s)}}else n="";return!c&&isNaN(a)?n:a}function f(t){return new RegExp("^("+t.join("|")+")\\b","i")}function p(t,e){var n,i,s,r,o=[];for(s=0,r=e.length;s<r;s++)n=e[s],i=t.getElementsByTagName(n),o=o.concat(Array.prototype.slice.call(i));return o}function m(t,e){var n,i=!0;return(n=g(t,e.pop()))&&e.length&&(i=function(t,e){var n,i=!0;for(;t.parentNode&&1===t.parentNode.nodeType&&e.length;)i&&(n=e.pop()),i=g(t=t.parentNode,n);return 0===e.length}(t,e)),n&&i&&0===e.length}function g(t,e){var n,i,s=t.nodeName,r=t.getAttribute("class"),o=t.getAttribute("id");if(n=new RegExp("^"+s,"i"),e=e.replace(n,""),o&&e.length&&(n=new RegExp("#"+o+"(?![a-zA-Z\\-]+)","i"),e=e.replace(n,"")),r&&e.length)for(i=(r=r.split(" ")).length;i--;)n=new RegExp("\\."+r[i]+"(?![a-zA-Z\\-]+)","i"),e=e.replace(n,"");return 0===e.length}function v(t,e){var n;if(t.getElementById&&(n=t.getElementById(e)),n)return n;var i,s,r,o=t.getElementsByTagName("*");for(s=0,r=o.length;s<r;s++)if(e===(i=o[s]).getAttribute("id"))return i}e.svgValidTagNamesRegEx=f(["path","circle","polygon","polyline","ellipse","rect","line","image","text"]),e.svgViewBoxElementsRegEx=f(["symbol","image","marker","pattern","view","svg"]),e.svgInvalidAncestorsRegEx=f(["pattern","defs","symbol","metadata","clipPath","mask","desc"]),e.svgValidParentsRegEx=f(["symbol","g","a","svg","clipPath","defs"]),e.cssRules={},e.gradientDefs={},e.clipPaths={},e.parseTransformAttribute=function(){function t(t,n,i){t[i]=Math.tan(e.util.degreesToRadians(n[0]))}var n=e.iMatrix,i=e.reNum,s=e.commaWsp,r="(?:"+("(?:(matrix)\\s*\\(\\s*("+i+")"+s+"("+i+")"+s+"("+i+")"+s+"("+i+")"+s+"("+i+")"+s+"("+i+")\\s*\\))")+"|"+("(?:(translate)\\s*\\(\\s*("+i+")(?:"+s+"("+i+"))?\\s*\\))")+"|"+("(?:(scale)\\s*\\(\\s*("+i+")(?:"+s+"("+i+"))?\\s*\\))")+"|"+("(?:(rotate)\\s*\\(\\s*("+i+")(?:"+s+"("+i+")"+s+"("+i+"))?\\s*\\))")+"|"+("(?:(skewX)\\s*\\(\\s*("+i+")\\s*\\))")+"|"+("(?:(skewY)\\s*\\(\\s*("+i+")\\s*\\))")+")",o=new RegExp("^\\s*(?:"+("(?:"+r+"(?:"+s+"*"+r+")*)")+"?)\\s*$"),a=new RegExp(r,"g");return function(i){var s=n.concat(),c=[];if(!i||i&&!o.test(i))return s;i.replace(a,(function(i){var o=new RegExp(r).exec(i).filter((function(t){return!!t})),a=o[1],l=o.slice(2).map(parseFloat);switch(a){case"translate":!function(t,e){t[4]=e[0],2===e.length&&(t[5]=e[1])}(s,l);break;case"rotate":l[0]=e.util.degreesToRadians(l[0]),function(t,n){var i=e.util.cos(n[0]),s=e.util.sin(n[0]),r=0,o=0;3===n.length&&(r=n[1],o=n[2]),t[0]=i,t[1]=s,t[2]=-s,t[3]=i,t[4]=r-(i*r-s*o),t[5]=o-(s*r+i*o)}(s,l);break;case"scale":!function(t,e){var n=e[0],i=2===e.length?e[1]:e[0];t[0]=n,t[3]=i}(s,l);break;case"skewX":t(s,l,2);break;case"skewY":t(s,l,1);break;case"matrix":s=l}c.push(s.concat()),s=n.concat()}));for(var l=c[0];c.length>1;)c.shift(),l=e.util.multiplyTransformMatrices(l,c[0]);return l}}();var _=new RegExp("^\\s*("+e.reNum+"+)\\s*,?\\s*("+e.reNum+"+)\\s*,?\\s*("+e.reNum+"+)\\s*,?\\s*("+e.reNum+"+)\\s*$");function y(t){if(e.svgViewBoxElementsRegEx.test(t.nodeName)){var n,i,s,o,a,c,l=t.getAttribute("viewBox"),h=1,u=1,d=t.getAttribute("width"),f=t.getAttribute("height"),p=t.getAttribute("x")||0,m=t.getAttribute("y")||0,g=t.getAttribute("preserveAspectRatio")||"",v=!l||!(l=l.match(_)),y=!d||!f||"100%"===d||"100%"===f,b=v&&y,x={},C="",w=0,S=0;if(x.width=0,x.height=0,x.toBeParsed=b,v&&(p||m)&&t.parentNode&&"#document"!==t.parentNode.nodeName&&(C=" translate("+r(p)+" "+r(m)+") ",a=(t.getAttribute("transform")||"")+C,t.setAttribute("transform",a),t.removeAttribute("x"),t.removeAttribute("y")),b)return x;if(v)return x.width=r(d),x.height=r(f),x;if(n=-parseFloat(l[1]),i=-parseFloat(l[2]),s=parseFloat(l[3]),o=parseFloat(l[4]),x.minX=n,x.minY=i,x.viewBoxWidth=s,x.viewBoxHeight=o,y?(x.width=s,x.height=o):(x.width=r(d),x.height=r(f),h=x.width/s,u=x.height/o),"none"!==(g=e.util.parsePreserveAspectRatioAttribute(g)).alignX&&("meet"===g.meetOrSlice&&(u=h=h>u?u:h),"slice"===g.meetOrSlice&&(u=h=h>u?h:u),w=x.width-s*h,S=x.height-o*h,"Mid"===g.alignX&&(w/=2),"Mid"===g.alignY&&(S/=2),"Min"===g.alignX&&(w=0),"Min"===g.alignY&&(S=0)),1===h&&1===u&&0===n&&0===i&&0===p&&0===m)return x;if((p||m)&&"#document"!==t.parentNode.nodeName&&(C=" translate("+r(p)+" "+r(m)+") "),a=C+" matrix("+h+" 0 0 "+u+" "+(n*h+w)+" "+(i*u+S)+") ","svg"===t.nodeName){for(c=t.ownerDocument.createElementNS(e.svgNS,"g");t.firstChild;)c.appendChild(t.firstChild);t.appendChild(c)}else(c=t).removeAttribute("x"),c.removeAttribute("y"),a=c.getAttribute("transform")+a;return c.setAttribute("transform",a),x}}function b(t,e){var n="xlink:href",i=v(t,e.getAttribute(n).substr(1));if(i&&i.getAttribute(n)&&b(t,i),["gradientTransform","x1","x2","y1","y2","gradientUnits","cx","cy","r","fx","fy"].forEach((function(t){i&&!e.hasAttribute(t)&&i.hasAttribute(t)&&e.setAttribute(t,i.getAttribute(t))})),!e.children.length)for(var s=i.cloneNode(!0);s.firstChild;)e.appendChild(s.firstChild);e.removeAttribute(n)}e.parseSVGDocument=function(t,n,s,r){if(t){!function(t){for(var n=p(t,["use","svg:use"]),i=0;n.length&&i<n.length;){var s=n[i],r=s.getAttribute("xlink:href")||s.getAttribute("href");if(null===r)return;var o,a,c,l,h=r.substr(1),u=s.getAttribute("x")||0,d=s.getAttribute("y")||0,f=v(t,h).cloneNode(!0),m=(f.getAttribute("transform")||"")+" translate("+u+", "+d+")",g=n.length,_=e.svgNS;if(y(f),/^svg$/i.test(f.nodeName)){var b=f.ownerDocument.createElementNS(_,"g");for(a=0,l=(c=f.attributes).length;a<l;a++)o=c.item(a),b.setAttributeNS(_,o.nodeName,o.nodeValue);for(;f.firstChild;)b.appendChild(f.firstChild);f=b}for(a=0,l=(c=s.attributes).length;a<l;a++)"x"!==(o=c.item(a)).nodeName&&"y"!==o.nodeName&&"xlink:href"!==o.nodeName&&"href"!==o.nodeName&&("transform"===o.nodeName?m=o.nodeValue+" "+m:f.setAttribute(o.nodeName,o.nodeValue));f.setAttribute("transform",m),f.setAttribute("instantiated_by_use","1"),f.removeAttribute("id"),s.parentNode.replaceChild(f,s),n.length===g&&i++}}(t);var o,a,c=e.Object.__uid++,l=y(t),h=e.util.toArray(t.getElementsByTagName("*"));if(l.crossOrigin=r&&r.crossOrigin,l.svgUid=c,0===h.length&&e.isLikelyNode){var u=[];for(o=0,a=(h=t.selectNodes('//*[name(.)!="svg"]')).length;o<a;o++)u[o]=h[o];h=u}var d=h.filter((function(t){return y(t),e.svgValidTagNamesRegEx.test(t.nodeName.replace("svg:",""))&&!function(t,e){for(;t&&(t=t.parentNode);)if(t.nodeName&&e.test(t.nodeName.replace("svg:",""))&&!t.getAttribute("instantiated_by_use"))return!0;return!1}(t,e.svgInvalidAncestorsRegEx)}));if(!d||d&&!d.length)n&&n([],{});else{var f={};h.filter((function(t){return"clipPath"===t.nodeName.replace("svg:","")})).forEach((function(t){var n=t.getAttribute("id");f[n]=e.util.toArray(t.getElementsByTagName("*")).filter((function(t){return e.svgValidTagNamesRegEx.test(t.nodeName.replace("svg:",""))}))})),e.gradientDefs[c]=e.getGradientDefs(t),e.cssRules[c]=e.getCSSRules(t),e.clipPaths[c]=f,e.parseElements(d,(function(t,i){n&&(n(t,l,i,h),delete e.gradientDefs[c],delete e.cssRules[c],delete e.clipPaths[c])}),i(l),s,r)}}};var x=new RegExp("(normal|italic)?\\s*(normal|small-caps)?\\s*(normal|bold|bolder|lighter|100|200|300|400|500|600|700|800|900)?\\s*("+e.reNum+"(?:px|cm|mm|em|pt|pc|in)*)(?:\\/(normal|"+e.reNum+"))?\\s+(.*)");n(e,{parseFontDeclaration:function(t,e){var n=t.match(x);if(n){var i=n[1],s=n[3],o=n[4],a=n[5],c=n[6];i&&(e.fontStyle=i),s&&(e.fontWeight=isNaN(parseFloat(s))?s:parseFloat(s)),o&&(e.fontSize=r(o)),c&&(e.fontFamily=c),a&&(e.lineHeight="normal"===a?1:a)}},getGradientDefs:function(t){var e,n=p(t,["linearGradient","radialGradient","svg:linearGradient","svg:radialGradient"]),i=0,s={};for(i=n.length;i--;)(e=n[i]).getAttribute("xlink:href")&&b(t,e),s[e.getAttribute("id")]=e;return s},parseAttributes:function(t,i,o){if(t){var a,f,p,g={};void 0===o&&(o=t.getAttribute("svgUid")),t.parentNode&&e.svgValidParentsRegEx.test(t.parentNode.nodeName)&&(g=e.parseAttributes(t.parentNode,i,o));var v=i.reduce((function(e,n){return(a=t.getAttribute(n))&&(e[n]=a),e}),{}),_=n(function(t,n){var i={};for(var s in e.cssRules[n])if(m(t,s.split(" ")))for(var r in e.cssRules[n][s])i[r]=e.cssRules[n][s][r];return i}(t,o),e.parseStyleAttribute(t));v=n(v,_),_[h]&&t.setAttribute(h,_[h]),f=p=g.fontSize||e.Text.DEFAULT_SVG_FONT_SIZE,v[l]&&(v[l]=f=r(v[l],p));var y,b,x={};for(var C in v)b=d(y=u(C),v[C],g,f),x[y]=b;x&&x.font&&e.parseFontDeclaration(x.font,x);var w=n(g,x);return e.svgValidParentsRegEx.test(t.nodeName)?w:function(t){for(var n in c)if(void 0!==t[c[n]]&&""!==t[n]){if(void 0===t[n]){if(!e.Object.prototype[n])continue;t[n]=e.Object.prototype[n]}if(0!==t[n].indexOf("url(")){var i=new e.Color(t[n]);t[n]=i.setAlpha(s(i.getAlpha()*t[c[n]],2)).toRgba()}}return t}(w)}},parseElements:function(t,n,i,s,r){new e.ElementsParser(t,n,i,s,r).parse()},parseStyleAttribute:function(t){var e={},n=t.getAttribute("style");return n?("string"==typeof n?function(t,e){var n,i;t.replace(/;\s*$/,"").split(";").forEach((function(t){var s=t.split(":");n=s[0].trim().toLowerCase(),i=s[1].trim(),e[n]=i}))}(n,e):function(t,e){var n,i;for(var s in t)void 0!==t[s]&&(n=s.toLowerCase(),i=t[s],e[n]=i)}(n,e),e):e},parsePointsAttribute:function(t){if(!t)return null;var e,n,i=[];for(e=0,n=(t=(t=t.replace(/,/g," ").trim()).split(/\s+/)).length;e<n;e+=2)i.push({x:parseFloat(t[e]),y:parseFloat(t[e+1])});return i},getCSSRules:function(t){var n,i,s=t.getElementsByTagName("style"),r={};for(n=0,i=s.length;n<i;n++){var o=s[n].textContent;""!==(o=o.replace(/\/\*[\s\S]*?\*\//g,"")).trim()&&o.match(/[^{]*\{[\s\S]*?\}/g).map((function(t){return t.trim()})).forEach((function(t){var s=t.match(/([\s\S]*?)\s*\{([^}]*)\}/),o={},a=s[2].trim().replace(/;$/,"").split(/\s*;\s*/);for(n=0,i=a.length;n<i;n++){var c=a[n].split(/\s*:\s*/),l=c[0],h=c[1];o[l]=h}(t=s[1]).split(",").forEach((function(t){""!==(t=t.replace(/^svg/i,"").trim())&&(r[t]?e.util.object.extend(r[t],o):r[t]=e.util.object.clone(o))}))}))}return r},loadSVGFromURL:function(t,n,i,s){t=t.replace(/^\n\s*/,"").trim(),new e.util.request(t,{method:"get",onComplete:function(t){var r=t.responseXML;if(!r||!r.documentElement)return n&&n(null),!1;e.parseSVGDocument(r.documentElement,(function(t,e,i,s){n&&n(t,e,i,s)}),i,s)}})},loadSVGFromString:function(t,n,i,s){var r=(new e.window.DOMParser).parseFromString(t.trim(),"text/xml");e.parseSVGDocument(r.documentElement,(function(t,e,i,s){n(t,e,i,s)}),i,s)}})}(e),v.ElementsParser=function(t,e,n,i,s,r){this.elements=t,this.callback=e,this.options=n,this.reviver=i,this.svgUid=n&&n.svgUid||0,this.parsingOptions=s,this.regexUrl=/^url\(['"]?#([^'"]+)['"]?\)/g,this.doc=r},(l=v.ElementsParser.prototype).parse=function(){this.instances=new Array(this.elements.length),this.numElements=this.elements.length,this.createObjects()},l.createObjects=function(){var t=this;this.elements.forEach((function(e,n){e.setAttribute("svgUid",t.svgUid),t.createObject(e,n)}))},l.findTag=function(t){return v[v.util.string.capitalize(t.tagName.replace("svg:",""))]},l.createObject=function(t,e){var n=this.findTag(t);if(n&&n.fromElement)try{n.fromElement(t,this.createCallback(e,t),this.options)}catch(t){v.log(t)}else this.checkIfDone()},l.createCallback=function(t,e){var n=this;return function(i){var s;n.resolveGradient(i,e,"fill"),n.resolveGradient(i,e,"stroke"),i instanceof v.Image&&i._originalElement&&(s=i.parsePreserveAspectRatioAttribute(e)),i._removeTransformMatrix(s),n.resolveClipPath(i,e),n.reviver&&n.reviver(e,i),n.instances[t]=i,n.checkIfDone()}},l.extractPropertyDefinition=function(t,e,n){var i=t[e],s=this.regexUrl;if(s.test(i)){s.lastIndex=0;var r=s.exec(i)[1];return s.lastIndex=0,v[n][this.svgUid][r]}},l.resolveGradient=function(t,e,n){var i=this.extractPropertyDefinition(t,n,"gradientDefs");if(i){var s=e.getAttribute(n+"-opacity"),r=v.Gradient.fromElement(i,t,s,this.options);t.set(n,r)}},l.createClipPathCallback=function(t,e){return function(t){t._removeTransformMatrix(),t.fillRule=t.clipRule,e.push(t)}},l.resolveClipPath=function(t,e){var n,i,s,r,o=this.extractPropertyDefinition(t,"clipPath","clipPaths");if(o){s=[],i=v.util.invertTransform(t.calcTransformMatrix());for(var a=o[0].parentNode,c=e;c.parentNode&&c.getAttribute("clip-path")!==t.clipPath;)c=c.parentNode;c.parentNode.appendChild(a);for(var l=0;l<o.length;l++)n=o[l],this.findTag(n).fromElement(n,this.createClipPathCallback(t,s),this.options);o=1===s.length?s[0]:new v.Group(s),r=v.util.multiplyTransformMatrices(i,o.calcTransformMatrix()),o.clipPath&&this.resolveClipPath(o,c);var h=v.util.qrDecompose(r);o.flipX=!1,o.flipY=!1,o.set("scaleX",h.scaleX),o.set("scaleY",h.scaleY),o.angle=h.angle,o.skewX=h.skewX,o.skewY=0,o.setPositionByOrigin({x:h.translateX,y:h.translateY},"center","center"),t.clipPath=o}else delete t.clipPath},l.checkIfDone=function(){0==--this.numElements&&(this.instances=this.instances.filter((function(t){return null!=t})),this.callback(this.instances,this.elements))},function(t){var e=t.fabric||(t.fabric={});function n(t,e){this.x=t,this.y=e}e.Point?e.warn("fabric.Point is already defined"):(e.Point=n,n.prototype={type:"point",constructor:n,add:function(t){return new n(this.x+t.x,this.y+t.y)},addEquals:function(t){return this.x+=t.x,this.y+=t.y,this},scalarAdd:function(t){return new n(this.x+t,this.y+t)},scalarAddEquals:function(t){return this.x+=t,this.y+=t,this},subtract:function(t){return new n(this.x-t.x,this.y-t.y)},subtractEquals:function(t){return this.x-=t.x,this.y-=t.y,this},scalarSubtract:function(t){return new n(this.x-t,this.y-t)},scalarSubtractEquals:function(t){return this.x-=t,this.y-=t,this},multiply:function(t){return new n(this.x*t,this.y*t)},multiplyEquals:function(t){return this.x*=t,this.y*=t,this},divide:function(t){return new n(this.x/t,this.y/t)},divideEquals:function(t){return this.x/=t,this.y/=t,this},eq:function(t){return this.x===t.x&&this.y===t.y},lt:function(t){return this.x<t.x&&this.y<t.y},lte:function(t){return this.x<=t.x&&this.y<=t.y},gt:function(t){return this.x>t.x&&this.y>t.y},gte:function(t){return this.x>=t.x&&this.y>=t.y},lerp:function(t,e){return void 0===e&&(e=.5),e=Math.max(Math.min(1,e),0),new n(this.x+(t.x-this.x)*e,this.y+(t.y-this.y)*e)},distanceFrom:function(t){var e=this.x-t.x,n=this.y-t.y;return Math.sqrt(e*e+n*n)},midPointFrom:function(t){return this.lerp(t)},min:function(t){return new n(Math.min(this.x,t.x),Math.min(this.y,t.y))},max:function(t){return new n(Math.max(this.x,t.x),Math.max(this.y,t.y))},toString:function(){return this.x+","+this.y},setXY:function(t,e){return this.x=t,this.y=e,this},setX:function(t){return this.x=t,this},setY:function(t){return this.y=t,this},setFromPoint:function(t){return this.x=t.x,this.y=t.y,this},swap:function(t){var e=this.x,n=this.y;this.x=t.x,this.y=t.y,t.x=e,t.y=n},clone:function(){return new n(this.x,this.y)}})}(e),function(t){var e=t.fabric||(t.fabric={});function n(t){this.status=t,this.points=[]}e.Intersection?e.warn("fabric.Intersection is already defined"):(e.Intersection=n,e.Intersection.prototype={constructor:n,appendPoint:function(t){return this.points.push(t),this},appendPoints:function(t){return this.points=this.points.concat(t),this}},e.Intersection.intersectLineLine=function(t,i,s,r){var o,a=(r.x-s.x)*(t.y-s.y)-(r.y-s.y)*(t.x-s.x),c=(i.x-t.x)*(t.y-s.y)-(i.y-t.y)*(t.x-s.x),l=(r.y-s.y)*(i.x-t.x)-(r.x-s.x)*(i.y-t.y);if(0!==l){var h=a/l,u=c/l;0<=h&&h<=1&&0<=u&&u<=1?(o=new n("Intersection")).appendPoint(new e.Point(t.x+h*(i.x-t.x),t.y+h*(i.y-t.y))):o=new n}else o=new n(0===a||0===c?"Coincident":"Parallel");return o},e.Intersection.intersectLinePolygon=function(t,e,i){var s,r,o,a,c=new n,l=i.length;for(a=0;a<l;a++)s=i[a],r=i[(a+1)%l],o=n.intersectLineLine(t,e,s,r),c.appendPoints(o.points);return c.points.length>0&&(c.status="Intersection"),c},e.Intersection.intersectPolygonPolygon=function(t,e){var i,s=new n,r=t.length;for(i=0;i<r;i++){var o=t[i],a=t[(i+1)%r],c=n.intersectLinePolygon(o,a,e);s.appendPoints(c.points)}return s.points.length>0&&(s.status="Intersection"),s},e.Intersection.intersectPolygonRectangle=function(t,i,s){var r=i.min(s),o=i.max(s),a=new e.Point(o.x,r.y),c=new e.Point(r.x,o.y),l=n.intersectLinePolygon(r,a,t),h=n.intersectLinePolygon(a,o,t),u=n.intersectLinePolygon(o,c,t),d=n.intersectLinePolygon(c,r,t),f=new n;return f.appendPoints(l.points),f.appendPoints(h.points),f.appendPoints(u.points),f.appendPoints(d.points),f.points.length>0&&(f.status="Intersection"),f})}(e),function(t){var e=t.fabric||(t.fabric={});function n(t){t?this._tryParsingColor(t):this.setSource([0,0,0,1])}function i(t,e,n){return n<0&&(n+=1),n>1&&(n-=1),n<1/6?t+6*(e-t)*n:n<.5?e:n<2/3?t+(e-t)*(2/3-n)*6:t}e.Color?e.warn("fabric.Color is already defined."):(e.Color=n,e.Color.prototype={_tryParsingColor:function(t){var e;t in n.colorNameMap&&(t=n.colorNameMap[t]),"transparent"===t&&(e=[255,255,255,0]),e||(e=n.sourceFromHex(t)),e||(e=n.sourceFromRgb(t)),e||(e=n.sourceFromHsl(t)),e||(e=[0,0,0,1]),e&&this.setSource(e)},_rgbToHsl:function(t,n,i){t/=255,n/=255,i/=255;var s,r,o,a=e.util.array.max([t,n,i]),c=e.util.array.min([t,n,i]);if(o=(a+c)/2,a===c)s=r=0;else{var l=a-c;switch(r=o>.5?l/(2-a-c):l/(a+c),a){case t:s=(n-i)/l+(n<i?6:0);break;case n:s=(i-t)/l+2;break;case i:s=(t-n)/l+4}s/=6}return[Math.round(360*s),Math.round(100*r),Math.round(100*o)]},getSource:function(){return this._source},setSource:function(t){this._source=t},toRgb:function(){var t=this.getSource();return"rgb("+t[0]+","+t[1]+","+t[2]+")"},toRgba:function(){var t=this.getSource();return"rgba("+t[0]+","+t[1]+","+t[2]+","+t[3]+")"},toHsl:function(){var t=this.getSource(),e=this._rgbToHsl(t[0],t[1],t[2]);return"hsl("+e[0]+","+e[1]+"%,"+e[2]+"%)"},toHsla:function(){var t=this.getSource(),e=this._rgbToHsl(t[0],t[1],t[2]);return"hsla("+e[0]+","+e[1]+"%,"+e[2]+"%,"+t[3]+")"},toHex:function(){var t,e,n,i=this.getSource();return t=1===(t=i[0].toString(16)).length?"0"+t:t,e=1===(e=i[1].toString(16)).length?"0"+e:e,n=1===(n=i[2].toString(16)).length?"0"+n:n,t.toUpperCase()+e.toUpperCase()+n.toUpperCase()},toHexa:function(){var t,e=this.getSource();return t=1===(t=(t=Math.round(255*e[3])).toString(16)).length?"0"+t:t,this.toHex()+t.toUpperCase()},getAlpha:function(){return this.getSource()[3]},setAlpha:function(t){var e=this.getSource();return e[3]=t,this.setSource(e),this},toGrayscale:function(){var t=this.getSource(),e=parseInt((.3*t[0]+.59*t[1]+.11*t[2]).toFixed(0),10),n=t[3];return this.setSource([e,e,e,n]),this},toBlackWhite:function(t){var e=this.getSource(),n=(.3*e[0]+.59*e[1]+.11*e[2]).toFixed(0),i=e[3];return t=t||127,n=Number(n)<Number(t)?0:255,this.setSource([n,n,n,i]),this},overlayWith:function(t){t instanceof n||(t=new n(t));var e,i=[],s=this.getAlpha(),r=this.getSource(),o=t.getSource();for(e=0;e<3;e++)i.push(Math.round(.5*r[e]+.5*o[e]));return i[3]=s,this.setSource(i),this}},e.Color.reRGBa=/^rgba?\(\s*(\d{1,3}(?:\.\d+)?\%?)\s*,\s*(\d{1,3}(?:\.\d+)?\%?)\s*,\s*(\d{1,3}(?:\.\d+)?\%?)\s*(?:\s*,\s*((?:\d*\.?\d+)?)\s*)?\)$/i,e.Color.reHSLa=/^hsla?\(\s*(\d{1,3})\s*,\s*(\d{1,3}\%)\s*,\s*(\d{1,3}\%)\s*(?:\s*,\s*(\d+(?:\.\d+)?)\s*)?\)$/i,e.Color.reHex=/^#?([0-9a-f]{8}|[0-9a-f]{6}|[0-9a-f]{4}|[0-9a-f]{3})$/i,e.Color.colorNameMap={aliceblue:"#F0F8FF",antiquewhite:"#FAEBD7",aqua:"#00FFFF",aquamarine:"#7FFFD4",azure:"#F0FFFF",beige:"#F5F5DC",bisque:"#FFE4C4",black:"#000000",blanchedalmond:"#FFEBCD",blue:"#0000FF",blueviolet:"#8A2BE2",brown:"#A52A2A",burlywood:"#DEB887",cadetblue:"#5F9EA0",chartreuse:"#7FFF00",chocolate:"#D2691E",coral:"#FF7F50",cornflowerblue:"#6495ED",cornsilk:"#FFF8DC",crimson:"#DC143C",cyan:"#00FFFF",darkblue:"#00008B",darkcyan:"#008B8B",darkgoldenrod:"#B8860B",darkgray:"#A9A9A9",darkgrey:"#A9A9A9",darkgreen:"#006400",darkkhaki:"#BDB76B",darkmagenta:"#8B008B",darkolivegreen:"#556B2F",darkorange:"#FF8C00",darkorchid:"#9932CC",darkred:"#8B0000",darksalmon:"#E9967A",darkseagreen:"#8FBC8F",darkslateblue:"#483D8B",darkslategray:"#2F4F4F",darkslategrey:"#2F4F4F",darkturquoise:"#00CED1",darkviolet:"#9400D3",deeppink:"#FF1493",deepskyblue:"#00BFFF",dimgray:"#696969",dimgrey:"#696969",dodgerblue:"#1E90FF",firebrick:"#B22222",floralwhite:"#FFFAF0",forestgreen:"#228B22",fuchsia:"#FF00FF",gainsboro:"#DCDCDC",ghostwhite:"#F8F8FF",gold:"#FFD700",goldenrod:"#DAA520",gray:"#808080",grey:"#808080",green:"#008000",greenyellow:"#ADFF2F",honeydew:"#F0FFF0",hotpink:"#FF69B4",indianred:"#CD5C5C",indigo:"#4B0082",ivory:"#FFFFF0",khaki:"#F0E68C",lavender:"#E6E6FA",lavenderblush:"#FFF0F5",lawngreen:"#7CFC00",lemonchiffon:"#FFFACD",lightblue:"#ADD8E6",lightcoral:"#F08080",lightcyan:"#E0FFFF",lightgoldenrodyellow:"#FAFAD2",lightgray:"#D3D3D3",lightgrey:"#D3D3D3",lightgreen:"#90EE90",lightpink:"#FFB6C1",lightsalmon:"#FFA07A",lightseagreen:"#20B2AA",lightskyblue:"#87CEFA",lightslategray:"#778899",lightslategrey:"#778899",lightsteelblue:"#B0C4DE",lightyellow:"#FFFFE0",lime:"#00FF00",limegreen:"#32CD32",linen:"#FAF0E6",magenta:"#FF00FF",maroon:"#800000",mediumaquamarine:"#66CDAA",mediumblue:"#0000CD",mediumorchid:"#BA55D3",mediumpurple:"#9370DB",mediumseagreen:"#3CB371",mediumslateblue:"#7B68EE",mediumspringgreen:"#00FA9A",mediumturquoise:"#48D1CC",mediumvioletred:"#C71585",midnightblue:"#191970",mintcream:"#F5FFFA",mistyrose:"#FFE4E1",moccasin:"#FFE4B5",navajowhite:"#FFDEAD",navy:"#000080",oldlace:"#FDF5E6",olive:"#808000",olivedrab:"#6B8E23",orange:"#FFA500",orangered:"#FF4500",orchid:"#DA70D6",palegoldenrod:"#EEE8AA",palegreen:"#98FB98",paleturquoise:"#AFEEEE",palevioletred:"#DB7093",papayawhip:"#FFEFD5",peachpuff:"#FFDAB9",peru:"#CD853F",pink:"#FFC0CB",plum:"#DDA0DD",powderblue:"#B0E0E6",purple:"#800080",rebeccapurple:"#663399",red:"#FF0000",rosybrown:"#BC8F8F",royalblue:"#4169E1",saddlebrown:"#8B4513",salmon:"#FA8072",sandybrown:"#F4A460",seagreen:"#2E8B57",seashell:"#FFF5EE",sienna:"#A0522D",silver:"#C0C0C0",skyblue:"#87CEEB",slateblue:"#6A5ACD",slategray:"#708090",slategrey:"#708090",snow:"#FFFAFA",springgreen:"#00FF7F",steelblue:"#4682B4",tan:"#D2B48C",teal:"#008080",thistle:"#D8BFD8",tomato:"#FF6347",turquoise:"#40E0D0",violet:"#EE82EE",wheat:"#F5DEB3",white:"#FFFFFF",whitesmoke:"#F5F5F5",yellow:"#FFFF00",yellowgreen:"#9ACD32"},e.Color.fromRgb=function(t){return n.fromSource(n.sourceFromRgb(t))},e.Color.sourceFromRgb=function(t){var e=t.match(n.reRGBa);if(e){var i=parseInt(e[1],10)/(/%$/.test(e[1])?100:1)*(/%$/.test(e[1])?255:1),s=parseInt(e[2],10)/(/%$/.test(e[2])?100:1)*(/%$/.test(e[2])?255:1),r=parseInt(e[3],10)/(/%$/.test(e[3])?100:1)*(/%$/.test(e[3])?255:1);return[parseInt(i,10),parseInt(s,10),parseInt(r,10),e[4]?parseFloat(e[4]):1]}},e.Color.fromRgba=n.fromRgb,e.Color.fromHsl=function(t){return n.fromSource(n.sourceFromHsl(t))},e.Color.sourceFromHsl=function(t){var e=t.match(n.reHSLa);if(e){var s,r,o,a=(parseFloat(e[1])%360+360)%360/360,c=parseFloat(e[2])/(/%$/.test(e[2])?100:1),l=parseFloat(e[3])/(/%$/.test(e[3])?100:1);if(0===c)s=r=o=l;else{var h=l<=.5?l*(c+1):l+c-l*c,u=2*l-h;s=i(u,h,a+1/3),r=i(u,h,a),o=i(u,h,a-1/3)}return[Math.round(255*s),Math.round(255*r),Math.round(255*o),e[4]?parseFloat(e[4]):1]}},e.Color.fromHsla=n.fromHsl,e.Color.fromHex=function(t){return n.fromSource(n.sourceFromHex(t))},e.Color.sourceFromHex=function(t){if(t.match(n.reHex)){var e=t.slice(t.indexOf("#")+1),i=3===e.length||4===e.length,s=8===e.length||4===e.length,r=i?e.charAt(0)+e.charAt(0):e.substring(0,2),o=i?e.charAt(1)+e.charAt(1):e.substring(2,4),a=i?e.charAt(2)+e.charAt(2):e.substring(4,6),c=s?i?e.charAt(3)+e.charAt(3):e.substring(6,8):"FF";return[parseInt(r,16),parseInt(o,16),parseInt(a,16),parseFloat((parseInt(c,16)/255).toFixed(2))]}},e.Color.fromSource=function(t){var e=new n;return e.setSource(t),e})}(e),function(t){var e=t.fabric||(t.fabric={}),n=["e","se","s","sw","w","nw","n","ne","e"],i=["ns","nesw","ew","nwse"],s={},r="left",o="top",a="right",c="bottom",l="center",h={top:c,bottom:o,left:a,right:r,center:l},u=e.util.radiansToDegrees,d=Math.sign||function(t){return(t>0)-(t<0)||+t};function f(t,e){var n=t.angle+u(Math.atan2(e.y,e.x))+360;return Math.round(n%360/45)}function p(t,n){var i=n.transform.target,s=i.canvas,r=e.util.object.clone(n);r.target=i,s&&s.fire("object:"+t,r),i.fire(t,n)}function m(t,e){var n=e.canvas,i=t[n.uniScaleKey];return n.uniformScaling&&!i||!n.uniformScaling&&i}function g(t){return t.originX===l&&t.originY===l}function v(t,e,n){var i=t.lockScalingX,s=t.lockScalingY;return!(!i||!s)||(!(e||!i&&!s||!n)||(!(!i||"x"!==e)||!(!s||"y"!==e)))}function _(t,e,n,i){return{e:t,transform:e,pointer:{x:n,y:i}}}function y(t){return function(e,n,i,s){var r=n.target,o=r.getCenterPoint(),a=r.translateToOriginPoint(o,n.originX,n.originY),c=t(e,n,i,s);return r.setPositionByOrigin(a,n.originX,n.originY),c}}function b(t,e){return function(n,i,s,r){var o=e(n,i,s,r);return o&&p(t,_(n,i,s,r)),o}}function x(t,n,i,s,r){var o=t.target,a=o.controls[t.corner],c=o.canvas.getZoom(),l=o.padding/c,h=o.toLocalPoint(new e.Point(s,r),n,i);return h.x>=l&&(h.x-=l),h.x<=-l&&(h.x+=l),h.y>=l&&(h.y-=l),h.y<=l&&(h.y+=l),h.x-=a.offsetX,h.y-=a.offsetY,h}function C(t){return t.flipX!==t.flipY}function w(t,e,n,i,s){if(0!==t[e]){var r=s/t._getTransformedDimensions()[i]*t[n];t.set(n,r)}}function S(t,e,n,i){var s,l=e.target,h=l._getTransformedDimensions(0,l.skewY),d=x(e,e.originX,e.originY,n,i),f=Math.abs(2*d.x)-h.x,p=l.skewX;f<2?s=0:(s=u(Math.atan2(f/l.scaleX,h.y/l.scaleY)),e.originX===r&&e.originY===c&&(s=-s),e.originX===a&&e.originY===o&&(s=-s),C(l)&&(s=-s));var m=p!==s;if(m){var g=l._getTransformedDimensions().y;l.set("skewX",s),w(l,"skewY","scaleY","y",g)}return m}function T(t,e,n,i){var s,l=e.target,h=l._getTransformedDimensions(l.skewX,0),d=x(e,e.originX,e.originY,n,i),f=Math.abs(2*d.y)-h.y,p=l.skewY;f<2?s=0:(s=u(Math.atan2(f/l.scaleY,h.x/l.scaleX)),e.originX===r&&e.originY===c&&(s=-s),e.originX===a&&e.originY===o&&(s=-s),C(l)&&(s=-s));var m=p!==s;if(m){var g=l._getTransformedDimensions().x;l.set("skewY",s),w(l,"skewX","scaleX","x",g)}return m}function M(t,e,n,i,s){s=s||{};var r,o,a,c,l,u,f=e.target,p=f.lockScalingX,_=f.lockScalingY,y=s.by,b=m(t,f),C=v(f,y,b),w=e.gestureScale;if(C)return!1;if(w)o=e.scaleX*w,a=e.scaleY*w;else{if(r=x(e,e.originX,e.originY,n,i),l="y"!==y?d(r.x):1,u="x"!==y?d(r.y):1,e.signX||(e.signX=l),e.signY||(e.signY=u),f.lockScalingFlip&&(e.signX!==l||e.signY!==u))return!1;if(c=f._getTransformedDimensions(),b&&!y){var S=Math.abs(r.x)+Math.abs(r.y),T=e.original,M=S/(Math.abs(c.x*T.scaleX/f.scaleX)+Math.abs(c.y*T.scaleY/f.scaleY));o=T.scaleX*M,a=T.scaleY*M}else o=Math.abs(r.x*f.scaleX/c.x),a=Math.abs(r.y*f.scaleY/c.y);g(e)&&(o*=2,a*=2),e.signX!==l&&"y"!==y&&(e.originX=h[e.originX],o*=-1,e.signX=l),e.signY!==u&&"x"!==y&&(e.originY=h[e.originY],a*=-1,e.signY=u)}var A=f.scaleX,O=f.scaleY;return y?("x"===y&&f.set("scaleX",o),"y"===y&&f.set("scaleY",a)):(!p&&f.set("scaleX",o),!_&&f.set("scaleY",a)),A!==f.scaleX||O!==f.scaleY}s.scaleCursorStyleHandler=function(t,e,i){var s=m(t,i),r="";if(0!==e.x&&0===e.y?r="x":0===e.x&&0!==e.y&&(r="y"),v(i,r,s))return"not-allowed";var o=f(i,e);return n[o]+"-resize"},s.skewCursorStyleHandler=function(t,e,n){var s="not-allowed";if(0!==e.x&&n.lockSkewingY)return s;if(0!==e.y&&n.lockSkewingX)return s;var r=f(n,e)%4;return i[r]+"-resize"},s.scaleSkewCursorStyleHandler=function(t,e,n){return t[n.canvas.altActionKey]?s.skewCursorStyleHandler(t,e,n):s.scaleCursorStyleHandler(t,e,n)},s.rotationWithSnapping=b("rotating",y((function(t,e,n,i){var s=e,r=s.target,o=r.translateToOriginPoint(r.getCenterPoint(),s.originX,s.originY);if(r.lockRotation)return!1;var a,c=Math.atan2(s.ey-o.y,s.ex-o.x),l=Math.atan2(i-o.y,n-o.x),h=u(l-c+s.theta);if(r.snapAngle>0){var d=r.snapAngle,f=r.snapThreshold||d,p=Math.ceil(h/d)*d,m=Math.floor(h/d)*d;Math.abs(h-m)<f?h=m:Math.abs(h-p)<f&&(h=p)}return h<0&&(h=360+h),h%=360,a=r.angle!==h,r.angle=h,a}))),s.scalingEqually=b("scaling",y((function(t,e,n,i){return M(t,e,n,i)}))),s.scalingX=b("scaling",y((function(t,e,n,i){return M(t,e,n,i,{by:"x"})}))),s.scalingY=b("scaling",y((function(t,e,n,i){return M(t,e,n,i,{by:"y"})}))),s.scalingYOrSkewingX=function(t,e,n,i){return t[e.target.canvas.altActionKey]?s.skewHandlerX(t,e,n,i):s.scalingY(t,e,n,i)},s.scalingXOrSkewingY=function(t,e,n,i){return t[e.target.canvas.altActionKey]?s.skewHandlerY(t,e,n,i):s.scalingX(t,e,n,i)},s.changeWidth=b("resizing",y((function(t,e,n,i){var s=e.target,r=x(e,e.originX,e.originY,n,i),o=s.strokeWidth/(s.strokeUniform?s.scaleX:1),a=g(e)?2:1,c=s.width,l=Math.abs(r.x*a/s.scaleX)-o;return s.set("width",Math.max(l,0)),c!==l}))),s.skewHandlerX=function(t,e,n,i){var s,c=e.target,h=c.skewX,u=e.originY;return!c.lockSkewingX&&(0===h?s=x(e,l,l,n,i).x>0?r:a:(h>0&&(s=u===o?r:a),h<0&&(s=u===o?a:r),C(c)&&(s=s===r?a:r)),e.originX=s,b("skewing",y(S))(t,e,n,i))},s.skewHandlerY=function(t,e,n,i){var s,a=e.target,h=a.skewY,u=e.originX;return!a.lockSkewingY&&(0===h?s=x(e,l,l,n,i).y>0?o:c:(h>0&&(s=u===r?o:c),h<0&&(s=u===r?c:o),C(a)&&(s=s===o?c:o)),e.originY=s,b("skewing",y(T))(t,e,n,i))},s.dragHandler=function(t,e,n,i){var s=e.target,r=n-e.offsetX,o=i-e.offsetY,a=!s.get("lockMovementX")&&s.left!==r,c=!s.get("lockMovementY")&&s.top!==o;return a&&s.set("left",r),c&&s.set("top",o),(a||c)&&p("moving",_(t,e,n,i)),a||c},s.scaleOrSkewActionName=function(t,e,n){var i=t[n.canvas.altActionKey];return 0===e.x?i?"skewX":"scaleY":0===e.y?i?"skewY":"scaleX":void 0},s.rotationStyleHandler=function(t,e,n){return n.lockRotation?"not-allowed":e.cursorStyle},s.fireEvent=p,s.wrapWithFixedAnchor=y,s.wrapWithFireEvent=b,s.getLocalPoint=x,e.controlsUtils=s}(e),function(t){var e=t.fabric||(t.fabric={}),n=e.util.degreesToRadians,i=e.controlsUtils;i.renderCircleControl=function(t,e,n,i,s){i=i||{};var r,o=this.sizeX||i.cornerSize||s.cornerSize,a=this.sizeY||i.cornerSize||s.cornerSize,c=void 0!==i.transparentCorners?i.transparentCorners:s.transparentCorners,l=c?"stroke":"fill",h=!c&&(i.cornerStrokeColor||s.cornerStrokeColor),u=e,d=n;t.save(),t.fillStyle=i.cornerColor||s.cornerColor,t.strokeStyle=i.cornerStrokeColor||s.cornerStrokeColor,o>a?(r=o,t.scale(1,a/o),d=n*o/a):a>o?(r=a,t.scale(o/a,1),u=e*a/o):r=o,t.lineWidth=1,t.beginPath(),t.arc(u,d,r/2,0,2*Math.PI,!1),t[l](),h&&t.stroke(),t.restore()},i.renderSquareControl=function(t,e,i,s,r){s=s||{};var o=this.sizeX||s.cornerSize||r.cornerSize,a=this.sizeY||s.cornerSize||r.cornerSize,c=void 0!==s.transparentCorners?s.transparentCorners:r.transparentCorners,l=c?"stroke":"fill",h=!c&&(s.cornerStrokeColor||r.cornerStrokeColor),u=o/2,d=a/2;t.save(),t.fillStyle=s.cornerColor||r.cornerColor,t.strokeStyle=s.cornerStrokeColor||r.cornerStrokeColor,t.lineWidth=1,t.translate(e,i),t.rotate(n(r.angle)),t[l+"Rect"](-u,-d,o,a),h&&t.strokeRect(-u,-d,o,a),t.restore()}}(e),function(t){var e=t.fabric||(t.fabric={});e.Control=function(t){for(var e in t)this[e]=t[e]},e.Control.prototype={visible:!0,actionName:"scale",angle:0,x:0,y:0,offsetX:0,offsetY:0,sizeX:null,sizeY:null,touchSizeX:null,touchSizeY:null,cursorStyle:"crosshair",withConnection:!1,actionHandler:function(){},mouseDownHandler:function(){},mouseUpHandler:function(){},getActionHandler:function(){return this.actionHandler},getMouseDownHandler:function(){return this.mouseDownHandler},getMouseUpHandler:function(){return this.mouseUpHandler},cursorStyleHandler:function(t,e){return e.cursorStyle},getActionName:function(t,e){return e.actionName},getVisibility:function(t,e){var n=t._controlsVisibility;return n&&void 0!==n[e]?n[e]:this.visible},setVisibility:function(t){this.visible=t},positionHandler:function(t,n){return e.util.transformPoint({x:this.x*t.x+this.offsetX,y:this.y*t.y+this.offsetY},n)},calcCornerCoords:function(t,n,i,s,r){var o,a,c,l,h=r?this.touchSizeX:this.sizeX,u=r?this.touchSizeY:this.sizeY;if(h&&u&&h!==u){var d=Math.atan2(u,h),f=Math.sqrt(h*h+u*u)/2,p=d-e.util.degreesToRadians(t),m=Math.PI/2-d-e.util.degreesToRadians(t);o=f*e.util.cos(p),a=f*e.util.sin(p),c=f*e.util.cos(m),l=f*e.util.sin(m)}else{f=.7071067812*(h&&u?h:n);p=e.util.degreesToRadians(45-t);o=c=f*e.util.cos(p),a=l=f*e.util.sin(p)}return{tl:{x:i-l,y:s-c},tr:{x:i+o,y:s-a},bl:{x:i-o,y:s+a},br:{x:i+l,y:s+c}}},render:function(t,n,i,s,r){switch((s=s||{}).cornerStyle||r.cornerStyle){case"circle":e.controlsUtils.renderCircleControl.call(this,t,n,i,s,r);break;default:e.controlsUtils.renderSquareControl.call(this,t,n,i,s,r)}}}}(e),function(){function t(t,e){var n,i,s,r,o=t.getAttribute("style"),a=t.getAttribute("offset")||0;if(a=(a=parseFloat(a)/(/%$/.test(a)?100:1))<0?0:a>1?1:a,o){var c=o.split(/\s*;\s*/);for(""===c[c.length-1]&&c.pop(),r=c.length;r--;){var l=c[r].split(/\s*:\s*/),h=l[0].trim(),u=l[1].trim();"stop-color"===h?n=u:"stop-opacity"===h&&(s=u)}}return n||(n=t.getAttribute("stop-color")||"rgb(0,0,0)"),s||(s=t.getAttribute("stop-opacity")),i=(n=new v.Color(n)).getAlpha(),s=isNaN(parseFloat(s))?1:parseFloat(s),s*=i*e,{offset:a,color:n.toRgb(),opacity:s}}var e=v.util.object.clone;v.Gradient=v.util.createClass({offsetX:0,offsetY:0,gradientTransform:null,gradientUnits:"pixels",type:"linear",initialize:function(t){t||(t={}),t.coords||(t.coords={});var e,n=this;Object.keys(t).forEach((function(e){n[e]=t[e]})),this.id?this.id+="_"+v.Object.__uid++:this.id=v.Object.__uid++,e={x1:t.coords.x1||0,y1:t.coords.y1||0,x2:t.coords.x2||0,y2:t.coords.y2||0},"radial"===this.type&&(e.r1=t.coords.r1||0,e.r2=t.coords.r2||0),this.coords=e,this.colorStops=t.colorStops.slice()},addColorStop:function(t){for(var e in t){var n=new v.Color(t[e]);this.colorStops.push({offset:parseFloat(e),color:n.toRgb(),opacity:n.getAlpha()})}return this},toObject:function(t){var e={type:this.type,coords:this.coords,colorStops:this.colorStops,offsetX:this.offsetX,offsetY:this.offsetY,gradientUnits:this.gradientUnits,gradientTransform:this.gradientTransform?this.gradientTransform.concat():this.gradientTransform};return v.util.populateWithProperties(this,e,t),e},toSVG:function(t,n){var i,s,r,o,a=e(this.coords,!0),c=(n=n||{},e(this.colorStops,!0)),l=a.r1>a.r2,h=this.gradientTransform?this.gradientTransform.concat():v.iMatrix.concat(),u=-this.offsetX,d=-this.offsetY,f=!!n.additionalTransform,p="pixels"===this.gradientUnits?"userSpaceOnUse":"objectBoundingBox";if(c.sort((function(t,e){return t.offset-e.offset})),"objectBoundingBox"===p?(u/=t.width,d/=t.height):(u+=t.width/2,d+=t.height/2),"path"===t.type&&"percentage"!==this.gradientUnits&&(u-=t.pathOffset.x,d-=t.pathOffset.y),h[4]-=u,h[5]-=d,o='id="SVGID_'+this.id+'" gradientUnits="'+p+'"',o+=' gradientTransform="'+(f?n.additionalTransform+" ":"")+v.util.matrixToSVG(h)+'" ',"linear"===this.type?r=["<linearGradient ",o,' x1="',a.x1,'" y1="',a.y1,'" x2="',a.x2,'" y2="',a.y2,'">\n']:"radial"===this.type&&(r=["<radialGradient ",o,' cx="',l?a.x1:a.x2,'" cy="',l?a.y1:a.y2,'" r="',l?a.r1:a.r2,'" fx="',l?a.x2:a.x1,'" fy="',l?a.y2:a.y1,'">\n']),"radial"===this.type){if(l)for((c=c.concat()).reverse(),i=0,s=c.length;i<s;i++)c[i].offset=1-c[i].offset;var m=Math.min(a.r1,a.r2);if(m>0){var g=m/Math.max(a.r1,a.r2);for(i=0,s=c.length;i<s;i++)c[i].offset+=g*(1-c[i].offset)}}for(i=0,s=c.length;i<s;i++){var _=c[i];r.push("<stop ",'offset="',100*_.offset+"%",'" style="stop-color:',_.color,void 0!==_.opacity?";stop-opacity: "+_.opacity:";",'"/>\n')}return r.push("linear"===this.type?"</linearGradient>\n":"</radialGradient>\n"),r.join("")},toLive:function(t){var e,n,i,s=v.util.object.clone(this.coords);if(this.type){for("linear"===this.type?e=t.createLinearGradient(s.x1,s.y1,s.x2,s.y2):"radial"===this.type&&(e=t.createRadialGradient(s.x1,s.y1,s.r1,s.x2,s.y2,s.r2)),n=0,i=this.colorStops.length;n<i;n++){var r=this.colorStops[n].color,o=this.colorStops[n].opacity,a=this.colorStops[n].offset;void 0!==o&&(r=new v.Color(r).setAlpha(o).toRgba()),e.addColorStop(a,r)}return e}}}),v.util.object.extend(v.Gradient,{fromElement:function(e,n,i,s){var r=parseFloat(i)/(/%$/.test(i)?100:1);r=r<0?0:r>1?1:r,isNaN(r)&&(r=1);var o,a,c,l,h=e.getElementsByTagName("stop"),u="userSpaceOnUse"===e.getAttribute("gradientUnits")?"pixels":"percentage",d=e.getAttribute("gradientTransform")||"",f=[],p=0,m=0;for("linearGradient"===e.nodeName||"LINEARGRADIENT"===e.nodeName?(o="linear",a=function(t){return{x1:t.getAttribute("x1")||0,y1:t.getAttribute("y1")||0,x2:t.getAttribute("x2")||"100%",y2:t.getAttribute("y2")||0}}(e)):(o="radial",a=function(t){return{x1:t.getAttribute("fx")||t.getAttribute("cx")||"50%",y1:t.getAttribute("fy")||t.getAttribute("cy")||"50%",r1:0,x2:t.getAttribute("cx")||"50%",y2:t.getAttribute("cy")||"50%",r2:t.getAttribute("r")||"50%"}}(e)),c=h.length;c--;)f.push(t(h[c],r));return l=v.parseTransformAttribute(d),function(t,e,n,i){var s,r;Object.keys(e).forEach((function(t){"Infinity"===(s=e[t])?r=1:"-Infinity"===s?r=0:(r=parseFloat(e[t],10),"string"==typeof s&&/^(\d+\.\d+)%|(\d+)%$/.test(s)&&(r*=.01,"pixels"===i&&("x1"!==t&&"x2"!==t&&"r2"!==t||(r*=n.viewBoxWidth||n.width),"y1"!==t&&"y2"!==t||(r*=n.viewBoxHeight||n.height)))),e[t]=r}))}(0,a,s,u),"pixels"===u&&(p=-n.left,m=-n.top),new v.Gradient({id:e.getAttribute("id"),type:o,coords:a,colorStops:f,gradientUnits:u,gradientTransform:l,offsetX:p,offsetY:m})}})}(),h=v.util.toFixed,v.Pattern=v.util.createClass({repeat:"repeat",offsetX:0,offsetY:0,crossOrigin:"",patternTransform:null,initialize:function(t,e){if(t||(t={}),this.id=v.Object.__uid++,this.setOptions(t),!t.source||t.source&&"string"!=typeof t.source)e&&e(this);else{var n=this;this.source=v.util.createImage(),v.util.loadImage(t.source,(function(t,i){n.source=t,e&&e(n,i)}),null,this.crossOrigin)}},toObject:function(t){var e,n,i=v.Object.NUM_FRACTION_DIGITS;return"string"==typeof this.source.src?e=this.source.src:"object"==typeof this.source&&this.source.toDataURL&&(e=this.source.toDataURL()),n={type:"pattern",source:e,repeat:this.repeat,crossOrigin:this.crossOrigin,offsetX:h(this.offsetX,i),offsetY:h(this.offsetY,i),patternTransform:this.patternTransform?this.patternTransform.concat():null},v.util.populateWithProperties(this,n,t),n},toSVG:function(t){var e="function"==typeof this.source?this.source():this.source,n=e.width/t.width,i=e.height/t.height,s=this.offsetX/t.width,r=this.offsetY/t.height,o="";return"repeat-x"!==this.repeat&&"no-repeat"!==this.repeat||(i=1,r&&(i+=Math.abs(r))),"repeat-y"!==this.repeat&&"no-repeat"!==this.repeat||(n=1,s&&(n+=Math.abs(s))),e.src?o=e.src:e.toDataURL&&(o=e.toDataURL()),'<pattern id="SVGID_'+this.id+'" x="'+s+'" y="'+r+'" width="'+n+'" height="'+i+'">\n<image x="0" y="0" width="'+e.width+'" height="'+e.height+'" xlink:href="'+o+'"></image>\n</pattern>\n'},setOptions:function(t){for(var e in t)this[e]=t[e]},toLive:function(t){var e=this.source;if(!e)return"";if(void 0!==e.src){if(!e.complete)return"";if(0===e.naturalWidth||0===e.naturalHeight)return""}return t.createPattern(e,this.repeat)}}),function(t){var e=t.fabric||(t.fabric={}),n=e.util.toFixed;e.Shadow?e.warn("fabric.Shadow is already defined."):(e.Shadow=e.util.createClass({color:"rgb(0,0,0)",blur:0,offsetX:0,offsetY:0,affectStroke:!1,includeDefaultValues:!0,nonScaling:!1,initialize:function(t){for(var n in"string"==typeof t&&(t=this._parseShadow(t)),t)this[n]=t[n];this.id=e.Object.__uid++},_parseShadow:function(t){var n=t.trim(),i=e.Shadow.reOffsetsAndBlur.exec(n)||[];return{color:(n.replace(e.Shadow.reOffsetsAndBlur,"")||"rgb(0,0,0)").trim(),offsetX:parseFloat(i[1],10)||0,offsetY:parseFloat(i[2],10)||0,blur:parseFloat(i[3],10)||0}},toString:function(){return[this.offsetX,this.offsetY,this.blur,this.color].join("px ")},toSVG:function(t){var i=40,s=40,r=e.Object.NUM_FRACTION_DIGITS,o=e.util.rotateVector({x:this.offsetX,y:this.offsetY},e.util.degreesToRadians(-t.angle)),a=new e.Color(this.color);return t.width&&t.height&&(i=100*n((Math.abs(o.x)+this.blur)/t.width,r)+20,s=100*n((Math.abs(o.y)+this.blur)/t.height,r)+20),t.flipX&&(o.x*=-1),t.flipY&&(o.y*=-1),'<filter id="SVGID_'+this.id+'" y="-'+s+'%" height="'+(100+2*s)+'%" x="-'+i+'%" width="'+(100+2*i)+'%" >\n\t<feGaussianBlur in="SourceAlpha" stdDeviation="'+n(this.blur?this.blur/2:0,r)+'"></feGaussianBlur>\n\t<feOffset dx="'+n(o.x,r)+'" dy="'+n(o.y,r)+'" result="oBlur" ></feOffset>\n\t<feFlood flood-color="'+a.toRgb()+'" flood-opacity="'+a.getAlpha()+'"/>\n\t<feComposite in2="oBlur" operator="in" />\n\t<feMerge>\n\t\t<feMergeNode></feMergeNode>\n\t\t<feMergeNode in="SourceGraphic"></feMergeNode>\n\t</feMerge>\n</filter>\n'},toObject:function(){if(this.includeDefaultValues)return{color:this.color,blur:this.blur,offsetX:this.offsetX,offsetY:this.offsetY,affectStroke:this.affectStroke,nonScaling:this.nonScaling};var t={},n=e.Shadow.prototype;return["color","blur","offsetX","offsetY","affectStroke","nonScaling"].forEach((function(e){this[e]!==n[e]&&(t[e]=this[e])}),this),t}}),e.Shadow.reOffsetsAndBlur=/(?:\s|^)(-?\d+(?:\.\d*)?(?:px)?(?:\s?|$))?(-?\d+(?:\.\d*)?(?:px)?(?:\s?|$))?(\d+(?:\.\d*)?(?:px)?)?(?:\s?|$)(?:$|\s)/)}(e),function(){if(v.StaticCanvas)v.warn("fabric.StaticCanvas is already defined.");else{var t=v.util.object.extend,e=v.util.getElementOffset,n=v.util.removeFromArray,i=v.util.toFixed,s=v.util.transformPoint,r=v.util.invertTransform,o=v.util.getNodeCanvas,a=v.util.createCanvasElement,c=new Error("Could not initialize `canvas` element");v.StaticCanvas=v.util.createClass(v.CommonMethods,{initialize:function(t,e){e||(e={}),this.renderAndResetBound=this.renderAndReset.bind(this),this.requestRenderAllBound=this.requestRenderAll.bind(this),this._initStatic(t,e)},backgroundColor:"",backgroundImage:null,overlayColor:"",overlayImage:null,includeDefaultValues:!0,stateful:!1,renderOnAddRemove:!0,controlsAboveOverlay:!1,allowTouchScrolling:!1,imageSmoothingEnabled:!0,viewportTransform:v.iMatrix.concat(),backgroundVpt:!0,overlayVpt:!0,enableRetinaScaling:!0,vptCoords:{},skipOffscreen:!0,clipPath:void 0,_initStatic:function(t,e){var n=this.requestRenderAllBound;this._objects=[],this._createLowerCanvas(t),this._initOptions(e),this.interactive||this._initRetinaScaling(),e.overlayImage&&this.setOverlayImage(e.overlayImage,n),e.backgroundImage&&this.setBackgroundImage(e.backgroundImage,n),e.backgroundColor&&this.setBackgroundColor(e.backgroundColor,n),e.overlayColor&&this.setOverlayColor(e.overlayColor,n),this.calcOffset()},_isRetinaScaling:function(){return 1!==v.devicePixelRatio&&this.enableRetinaScaling},getRetinaScaling:function(){return this._isRetinaScaling()?v.devicePixelRatio:1},_initRetinaScaling:function(){if(this._isRetinaScaling()){var t=v.devicePixelRatio;this.__initRetinaScaling(t,this.lowerCanvasEl,this.contextContainer),this.upperCanvasEl&&this.__initRetinaScaling(t,this.upperCanvasEl,this.contextTop)}},__initRetinaScaling:function(t,e,n){e.setAttribute("width",this.width*t),e.setAttribute("height",this.height*t),n.scale(t,t)},calcOffset:function(){return this._offset=e(this.lowerCanvasEl),this},setOverlayImage:function(t,e,n){return this.__setBgOverlayImage("overlayImage",t,e,n)},setBackgroundImage:function(t,e,n){return this.__setBgOverlayImage("backgroundImage",t,e,n)},setOverlayColor:function(t,e){return this.__setBgOverlayColor("overlayColor",t,e)},setBackgroundColor:function(t,e){return this.__setBgOverlayColor("backgroundColor",t,e)},__setBgOverlayImage:function(t,e,n,i){return"string"==typeof e?v.util.loadImage(e,(function(e,s){if(e){var r=new v.Image(e,i);this[t]=r,r.canvas=this}n&&n(e,s)}),this,i&&i.crossOrigin):(i&&e.setOptions(i),this[t]=e,e&&(e.canvas=this),n&&n(e,!1)),this},__setBgOverlayColor:function(t,e,n){return this[t]=e,this._initGradient(e,t),this._initPattern(e,t,n),this},_createCanvasElement:function(){var t=a();if(!t)throw c;if(t.style||(t.style={}),void 0===t.getContext)throw c;return t},_initOptions:function(t){var e=this.lowerCanvasEl;this._setOptions(t),this.width=this.width||parseInt(e.width,10)||0,this.height=this.height||parseInt(e.height,10)||0,this.lowerCanvasEl.style&&(e.width=this.width,e.height=this.height,e.style.width=this.width+"px",e.style.height=this.height+"px",this.viewportTransform=this.viewportTransform.slice())},_createLowerCanvas:function(t){t&&t.getContext?this.lowerCanvasEl=t:this.lowerCanvasEl=v.util.getById(t)||this._createCanvasElement(),v.util.addClass(this.lowerCanvasEl,"lower-canvas"),this.interactive&&this._applyCanvasStyle(this.lowerCanvasEl),this.contextContainer=this.lowerCanvasEl.getContext("2d")},getWidth:function(){return this.width},getHeight:function(){return this.height},setWidth:function(t,e){return this.setDimensions({width:t},e)},setHeight:function(t,e){return this.setDimensions({height:t},e)},setDimensions:function(t,e){var n;for(var i in e=e||{},t)n=t[i],e.cssOnly||(this._setBackstoreDimension(i,t[i]),n+="px",this.hasLostContext=!0),e.backstoreOnly||this._setCssDimension(i,n);return this._isCurrentlyDrawing&&this.freeDrawingBrush&&this.freeDrawingBrush._setBrushStyles(),this._initRetinaScaling(),this.calcOffset(),e.cssOnly||this.requestRenderAll(),this},_setBackstoreDimension:function(t,e){return this.lowerCanvasEl[t]=e,this.upperCanvasEl&&(this.upperCanvasEl[t]=e),this.cacheCanvasEl&&(this.cacheCanvasEl[t]=e),this[t]=e,this},_setCssDimension:function(t,e){return this.lowerCanvasEl.style[t]=e,this.upperCanvasEl&&(this.upperCanvasEl.style[t]=e),this.wrapperEl&&(this.wrapperEl.style[t]=e),this},getZoom:function(){return this.viewportTransform[0]},setViewportTransform:function(t){var e,n,i,s=this._activeObject,r=this.backgroundImage,o=this.overlayImage;for(this.viewportTransform=t,n=0,i=this._objects.length;n<i;n++)(e=this._objects[n]).group||e.setCoords(!0);return s&&s.setCoords(),r&&r.setCoords(!0),o&&o.setCoords(!0),this.calcViewportBoundaries(),this.renderOnAddRemove&&this.requestRenderAll(),this},zoomToPoint:function(t,e){var n=t,i=this.viewportTransform.slice(0);t=s(t,r(this.viewportTransform)),i[0]=e,i[3]=e;var o=s(t,i);return i[4]+=n.x-o.x,i[5]+=n.y-o.y,this.setViewportTransform(i)},setZoom:function(t){return this.zoomToPoint(new v.Point(0,0),t),this},absolutePan:function(t){var e=this.viewportTransform.slice(0);return e[4]=-t.x,e[5]=-t.y,this.setViewportTransform(e)},relativePan:function(t){return this.absolutePan(new v.Point(-t.x-this.viewportTransform[4],-t.y-this.viewportTransform[5]))},getElement:function(){return this.lowerCanvasEl},_onObjectAdded:function(t){this.stateful&&t.setupState(),t._set("canvas",this),t.setCoords(),this.fire("object:added",{target:t}),t.fire("added")},_onObjectRemoved:function(t){this.fire("object:removed",{target:t}),t.fire("removed"),delete t.canvas},clearContext:function(t){return t.clearRect(0,0,this.width,this.height),this},getContext:function(){return this.contextContainer},clear:function(){return this._objects.length=0,this.backgroundImage=null,this.overlayImage=null,this.backgroundColor="",this.overlayColor="",this._hasITextHandlers&&(this.off("mouse:up",this._mouseUpITextHandler),this._iTextInstances=null,this._hasITextHandlers=!1),this.clearContext(this.contextContainer),this.fire("canvas:cleared"),this.renderOnAddRemove&&this.requestRenderAll(),this},renderAll:function(){var t=this.contextContainer;return this.renderCanvas(t,this._objects),this},renderAndReset:function(){this.isRendering=0,this.renderAll()},requestRenderAll:function(){return this.isRendering||(this.isRendering=v.util.requestAnimFrame(this.renderAndResetBound)),this},calcViewportBoundaries:function(){var t={},e=this.width,n=this.height,i=r(this.viewportTransform);return t.tl=s({x:0,y:0},i),t.br=s({x:e,y:n},i),t.tr=new v.Point(t.br.x,t.tl.y),t.bl=new v.Point(t.tl.x,t.br.y),this.vptCoords=t,t},cancelRequestedRender:function(){this.isRendering&&(v.util.cancelAnimFrame(this.isRendering),this.isRendering=0)},renderCanvas:function(t,e){var n=this.viewportTransform,i=this.clipPath;this.cancelRequestedRender(),this.calcViewportBoundaries(),this.clearContext(t),v.util.setImageSmoothing(t,this.imageSmoothingEnabled),this.fire("before:render",{ctx:t}),this._renderBackground(t),t.save(),t.transform(n[0],n[1],n[2],n[3],n[4],n[5]),this._renderObjects(t,e),t.restore(),!this.controlsAboveOverlay&&this.interactive&&this.drawControls(t),i&&(i.canvas=this,i.shouldCache(),i._transformDone=!0,i.renderCache({forClipping:!0}),this.drawClipPathOnCanvas(t)),this._renderOverlay(t),this.controlsAboveOverlay&&this.interactive&&this.drawControls(t),this.fire("after:render",{ctx:t})},drawClipPathOnCanvas:function(t){var e=this.viewportTransform,n=this.clipPath;t.save(),t.transform(e[0],e[1],e[2],e[3],e[4],e[5]),t.globalCompositeOperation="destination-in",n.transform(t),t.scale(1/n.zoomX,1/n.zoomY),t.drawImage(n._cacheCanvas,-n.cacheTranslationX,-n.cacheTranslationY),t.restore()},_renderObjects:function(t,e){var n,i;for(n=0,i=e.length;n<i;++n)e[n]&&e[n].render(t)},_renderBackgroundOrOverlay:function(t,e){var n=this[e+"Color"],i=this[e+"Image"],s=this.viewportTransform,r=this[e+"Vpt"];if(n||i){if(n){t.save(),t.beginPath(),t.moveTo(0,0),t.lineTo(this.width,0),t.lineTo(this.width,this.height),t.lineTo(0,this.height),t.closePath(),t.fillStyle=n.toLive?n.toLive(t,this):n,r&&t.transform(s[0],s[1],s[2],s[3],s[4],s[5]),t.transform(1,0,0,1,n.offsetX||0,n.offsetY||0);var o=n.gradientTransform||n.patternTransform;o&&t.transform(o[0],o[1],o[2],o[3],o[4],o[5]),t.fill(),t.restore()}i&&(t.save(),r&&t.transform(s[0],s[1],s[2],s[3],s[4],s[5]),i.render(t),t.restore())}},_renderBackground:function(t){this._renderBackgroundOrOverlay(t,"background")},_renderOverlay:function(t){this._renderBackgroundOrOverlay(t,"overlay")},getCenter:function(){return{top:this.height/2,left:this.width/2}},centerObjectH:function(t){return this._centerObject(t,new v.Point(this.getCenter().left,t.getCenterPoint().y))},centerObjectV:function(t){return this._centerObject(t,new v.Point(t.getCenterPoint().x,this.getCenter().top))},centerObject:function(t){var e=this.getCenter();return this._centerObject(t,new v.Point(e.left,e.top))},viewportCenterObject:function(t){var e=this.getVpCenter();return this._centerObject(t,e)},viewportCenterObjectH:function(t){var e=this.getVpCenter();return this._centerObject(t,new v.Point(e.x,t.getCenterPoint().y)),this},viewportCenterObjectV:function(t){var e=this.getVpCenter();return this._centerObject(t,new v.Point(t.getCenterPoint().x,e.y))},getVpCenter:function(){var t=this.getCenter(),e=r(this.viewportTransform);return s({x:t.left,y:t.top},e)},_centerObject:function(t,e){return t.setPositionByOrigin(e,"center","center"),t.setCoords(),this.renderOnAddRemove&&this.requestRenderAll(),this},toDatalessJSON:function(t){return this.toDatalessObject(t)},toObject:function(t){return this._toObjectMethod("toObject",t)},toDatalessObject:function(t){return this._toObjectMethod("toDatalessObject",t)},_toObjectMethod:function(e,n){var i=this.clipPath,s={version:v.version,objects:this._toObjects(e,n)};return i&&(s.clipPath=this._toObject(this.clipPath,e,n)),t(s,this.__serializeBgOverlay(e,n)),v.util.populateWithProperties(this,s,n),s},_toObjects:function(t,e){return this._objects.filter((function(t){return!t.excludeFromExport})).map((function(n){return this._toObject(n,t,e)}),this)},_toObject:function(t,e,n){var i;this.includeDefaultValues||(i=t.includeDefaultValues,t.includeDefaultValues=!1);var s=t[e](n);return this.includeDefaultValues||(t.includeDefaultValues=i),s},__serializeBgOverlay:function(t,e){var n={},i=this.backgroundImage,s=this.overlayImage;return this.backgroundColor&&(n.background=this.backgroundColor.toObject?this.backgroundColor.toObject(e):this.backgroundColor),this.overlayColor&&(n.overlay=this.overlayColor.toObject?this.overlayColor.toObject(e):this.overlayColor),i&&!i.excludeFromExport&&(n.backgroundImage=this._toObject(i,t,e)),s&&!s.excludeFromExport&&(n.overlayImage=this._toObject(s,t,e)),n},svgViewportTransformation:!0,toSVG:function(t,e){t||(t={}),t.reviver=e;var n=[];return this._setSVGPreamble(n,t),this._setSVGHeader(n,t),this.clipPath&&n.push('<g clip-path="url(#'+this.clipPath.clipPathId+')" >\n'),this._setSVGBgOverlayColor(n,"background"),this._setSVGBgOverlayImage(n,"backgroundImage",e),this._setSVGObjects(n,e),this.clipPath&&n.push("</g>\n"),this._setSVGBgOverlayColor(n,"overlay"),this._setSVGBgOverlayImage(n,"overlayImage",e),n.push("</svg>"),n.join("")},_setSVGPreamble:function(t,e){e.suppressPreamble||t.push('<?xml version="1.0" encoding="',e.encoding||"UTF-8",'" standalone="no" ?>\n','<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" ','"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n')},_setSVGHeader:function(t,e){var n,s=e.width||this.width,r=e.height||this.height,o='viewBox="0 0 '+this.width+" "+this.height+'" ',a=v.Object.NUM_FRACTION_DIGITS;e.viewBox?o='viewBox="'+e.viewBox.x+" "+e.viewBox.y+" "+e.viewBox.width+" "+e.viewBox.height+'" ':this.svgViewportTransformation&&(n=this.viewportTransform,o='viewBox="'+i(-n[4]/n[0],a)+" "+i(-n[5]/n[3],a)+" "+i(this.width/n[0],a)+" "+i(this.height/n[3],a)+'" '),t.push("<svg ",'xmlns="http://www.w3.org/2000/svg" ','xmlns:xlink="http://www.w3.org/1999/xlink" ','version="1.1" ','width="',s,'" ','height="',r,'" ',o,'xml:space="preserve">\n',"<desc>Created with Fabric.js ",v.version,"</desc>\n","<defs>\n",this.createSVGFontFacesMarkup(),this.createSVGRefElementsMarkup(),this.createSVGClipPathMarkup(e),"</defs>\n")},createSVGClipPathMarkup:function(t){var e=this.clipPath;return e?(e.clipPathId="CLIPPATH_"+v.Object.__uid++,'<clipPath id="'+e.clipPathId+'" >\n'+this.clipPath.toClipPathSVG(t.reviver)+"</clipPath>\n"):""},createSVGRefElementsMarkup:function(){var t=this;return["background","overlay"].map((function(e){var n=t[e+"Color"];if(n&&n.toLive){var i=t[e+"Vpt"],s=t.viewportTransform,r={width:t.width/(i?s[0]:1),height:t.height/(i?s[3]:1)};return n.toSVG(r,{additionalTransform:i?v.util.matrixToSVG(s):""})}})).join("")},createSVGFontFacesMarkup:function(){var t,e,n,i,s,r,o,a,c="",l={},h=v.fontPaths,u=[];for(this._objects.forEach((function t(e){u.push(e),e._objects&&e._objects.forEach(t)})),o=0,a=u.length;o<a;o++)if(e=(t=u[o]).fontFamily,-1!==t.type.indexOf("text")&&!l[e]&&h[e]&&(l[e]=!0,t.styles))for(s in n=t.styles)for(r in i=n[s])!l[e=i[r].fontFamily]&&h[e]&&(l[e]=!0);for(var d in l)c+=["\t\t@font-face {\n","\t\t\tfont-family: '",d,"';\n","\t\t\tsrc: url('",h[d],"');\n","\t\t}\n"].join("");return c&&(c=['\t<style type="text/css">',"<![CDATA[\n",c,"]]>","</style>\n"].join("")),c},_setSVGObjects:function(t,e){var n,i,s,r=this._objects;for(i=0,s=r.length;i<s;i++)(n=r[i]).excludeFromExport||this._setSVGObject(t,n,e)},_setSVGObject:function(t,e,n){t.push(e.toSVG(n))},_setSVGBgOverlayImage:function(t,e,n){this[e]&&!this[e].excludeFromExport&&this[e].toSVG&&t.push(this[e].toSVG(n))},_setSVGBgOverlayColor:function(t,e){var n=this[e+"Color"],i=this.viewportTransform,s=this.width,r=this.height;if(n)if(n.toLive){var o=n.repeat,a=v.util.invertTransform(i),c=this[e+"Vpt"]?v.util.matrixToSVG(a):"";t.push('<rect transform="'+c+" translate(",s/2,",",r/2,')"',' x="',n.offsetX-s/2,'" y="',n.offsetY-r/2,'" ','width="',"repeat-y"===o||"no-repeat"===o?n.source.width:s,'" height="',"repeat-x"===o||"no-repeat"===o?n.source.height:r,'" fill="url(#SVGID_'+n.id+')"',"></rect>\n")}else t.push('<rect x="0" y="0" width="100%" height="100%" ','fill="',n,'"',"></rect>\n")},sendToBack:function(t){if(!t)return this;var e,i,s,r=this._activeObject;if(t===r&&"activeSelection"===t.type)for(e=(s=r._objects).length;e--;)i=s[e],n(this._objects,i),this._objects.unshift(i);else n(this._objects,t),this._objects.unshift(t);return this.renderOnAddRemove&&this.requestRenderAll(),this},bringToFront:function(t){if(!t)return this;var e,i,s,r=this._activeObject;if(t===r&&"activeSelection"===t.type)for(s=r._objects,e=0;e<s.length;e++)i=s[e],n(this._objects,i),this._objects.push(i);else n(this._objects,t),this._objects.push(t);return this.renderOnAddRemove&&this.requestRenderAll(),this},sendBackwards:function(t,e){if(!t)return this;var i,s,r,o,a,c=this._activeObject,l=0;if(t===c&&"activeSelection"===t.type)for(a=c._objects,i=0;i<a.length;i++)s=a[i],(r=this._objects.indexOf(s))>0+l&&(o=r-1,n(this._objects,s),this._objects.splice(o,0,s)),l++;else 0!==(r=this._objects.indexOf(t))&&(o=this._findNewLowerIndex(t,r,e),n(this._objects,t),this._objects.splice(o,0,t));return this.renderOnAddRemove&&this.requestRenderAll(),this},_findNewLowerIndex:function(t,e,n){var i,s;if(n)for(i=e,s=e-1;s>=0;--s){if(t.intersectsWithObject(this._objects[s])||t.isContainedWithinObject(this._objects[s])||this._objects[s].isContainedWithinObject(t)){i=s;break}}else i=e-1;return i},bringForward:function(t,e){if(!t)return this;var i,s,r,o,a,c=this._activeObject,l=0;if(t===c&&"activeSelection"===t.type)for(i=(a=c._objects).length;i--;)s=a[i],(r=this._objects.indexOf(s))<this._objects.length-1-l&&(o=r+1,n(this._objects,s),this._objects.splice(o,0,s)),l++;else(r=this._objects.indexOf(t))!==this._objects.length-1&&(o=this._findNewUpperIndex(t,r,e),n(this._objects,t),this._objects.splice(o,0,t));return this.renderOnAddRemove&&this.requestRenderAll(),this},_findNewUpperIndex:function(t,e,n){var i,s,r;if(n)for(i=e,s=e+1,r=this._objects.length;s<r;++s){if(t.intersectsWithObject(this._objects[s])||t.isContainedWithinObject(this._objects[s])||this._objects[s].isContainedWithinObject(t)){i=s;break}}else i=e+1;return i},moveTo:function(t,e){return n(this._objects,t),this._objects.splice(e,0,t),this.renderOnAddRemove&&this.requestRenderAll()},dispose:function(){return this.isRendering&&(v.util.cancelAnimFrame(this.isRendering),this.isRendering=0),this.forEachObject((function(t){t.dispose&&t.dispose()})),this._objects=[],this.backgroundImage&&this.backgroundImage.dispose&&this.backgroundImage.dispose(),this.backgroundImage=null,this.overlayImage&&this.overlayImage.dispose&&this.overlayImage.dispose(),this.overlayImage=null,this._iTextInstances=null,this.contextContainer=null,v.util.cleanUpJsdomNode(this.lowerCanvasEl),this.lowerCanvasEl=void 0,this},toString:function(){return"#<fabric.Canvas ("+this.complexity()+"): { objects: "+this._objects.length+" }>"}}),t(v.StaticCanvas.prototype,v.Observable),t(v.StaticCanvas.prototype,v.Collection),t(v.StaticCanvas.prototype,v.DataURLExporter),t(v.StaticCanvas,{EMPTY_JSON:'{"objects": [], "background": "white"}',supports:function(t){var e=a();if(!e||!e.getContext)return null;var n=e.getContext("2d");if(!n)return null;switch(t){case"setLineDash":return void 0!==n.setLineDash;default:return null}}}),v.StaticCanvas.prototype.toJSON=v.StaticCanvas.prototype.toObject,v.isLikelyNode&&(v.StaticCanvas.prototype.createPNGStream=function(){var t=o(this.lowerCanvasEl);return t&&t.createPNGStream()},v.StaticCanvas.prototype.createJPEGStream=function(t){var e=o(this.lowerCanvasEl);return e&&e.createJPEGStream(t)})}}(),v.BaseBrush=v.util.createClass({color:"rgb(0, 0, 0)",width:1,shadow:null,strokeLineCap:"round",strokeLineJoin:"round",strokeMiterLimit:10,strokeDashArray:null,limitedToCanvasSize:!1,_setBrushStyles:function(){var t=this.canvas.contextTop;t.strokeStyle=this.color,t.lineWidth=this.width,t.lineCap=this.strokeLineCap,t.miterLimit=this.strokeMiterLimit,t.lineJoin=this.strokeLineJoin,v.StaticCanvas.supports("setLineDash")&&t.setLineDash(this.strokeDashArray||[])},_saveAndTransform:function(t){var e=this.canvas.viewportTransform;t.save(),t.transform(e[0],e[1],e[2],e[3],e[4],e[5])},_setShadow:function(){if(this.shadow){var t=this.canvas,e=this.shadow,n=t.contextTop,i=t.getZoom();t&&t._isRetinaScaling()&&(i*=v.devicePixelRatio),n.shadowColor=e.color,n.shadowBlur=e.blur*i,n.shadowOffsetX=e.offsetX*i,n.shadowOffsetY=e.offsetY*i}},needsFullRender:function(){return new v.Color(this.color).getAlpha()<1||!!this.shadow},_resetShadow:function(){var t=this.canvas.contextTop;t.shadowColor="",t.shadowBlur=t.shadowOffsetX=t.shadowOffsetY=0},_isOutSideCanvas:function(t){return t.x<0||t.x>this.canvas.getWidth()||t.y<0||t.y>this.canvas.getHeight()}}),v.PencilBrush=v.util.createClass(v.BaseBrush,{decimate:.4,initialize:function(t){this.canvas=t,this._points=[]},_drawSegment:function(t,e,n){var i=e.midPointFrom(n);return t.quadraticCurveTo(e.x,e.y,i.x,i.y),i},onMouseDown:function(t,e){this.canvas._isMainEvent(e.e)&&(this._prepareForDrawing(t),this._captureDrawingPath(t),this._render())},onMouseMove:function(t,e){if(this.canvas._isMainEvent(e.e)&&(!0!==this.limitedToCanvasSize||!this._isOutSideCanvas(t))&&this._captureDrawingPath(t)&&this._points.length>1)if(this.needsFullRender())this.canvas.clearContext(this.canvas.contextTop),this._render();else{var n=this._points,i=n.length,s=this.canvas.contextTop;this._saveAndTransform(s),this.oldEnd&&(s.beginPath(),s.moveTo(this.oldEnd.x,this.oldEnd.y)),this.oldEnd=this._drawSegment(s,n[i-2],n[i-1],!0),s.stroke(),s.restore()}},onMouseUp:function(t){return!this.canvas._isMainEvent(t.e)||(this.oldEnd=void 0,this._finalizeAndAddPath(),!1)},_prepareForDrawing:function(t){var e=new v.Point(t.x,t.y);this._reset(),this._addPoint(e),this.canvas.contextTop.moveTo(e.x,e.y)},_addPoint:function(t){return!(this._points.length>1&&t.eq(this._points[this._points.length-1])||(this._points.push(t),0))},_reset:function(){this._points=[],this._setBrushStyles(),this._setShadow()},_captureDrawingPath:function(t){var e=new v.Point(t.x,t.y);return this._addPoint(e)},_render:function(){var t,e,n=this.canvas.contextTop,i=this._points[0],s=this._points[1];if(this._saveAndTransform(n),n.beginPath(),2===this._points.length&&i.x===s.x&&i.y===s.y){var r=this.width/1e3;i=new v.Point(i.x,i.y),s=new v.Point(s.x,s.y),i.x-=r,s.x+=r}for(n.moveTo(i.x,i.y),t=1,e=this._points.length;t<e;t++)this._drawSegment(n,i,s),i=this._points[t],s=this._points[t+1];n.lineTo(i.x,i.y),n.stroke(),n.restore()},convertPointsToSVGPath:function(t){var e,n=[],i=this.width/1e3,s=new v.Point(t[0].x,t[0].y),r=new v.Point(t[1].x,t[1].y),o=t.length,a=1,c=0,l=o>2;for(l&&(a=t[2].x<r.x?-1:t[2].x===r.x?0:1,c=t[2].y<r.y?-1:t[2].y===r.y?0:1),n.push("M ",s.x-a*i," ",s.y-c*i," "),e=1;e<o;e++){if(!s.eq(r)){var h=s.midPointFrom(r);n.push("Q ",s.x," ",s.y," ",h.x," ",h.y," ")}s=t[e],e+1<t.length&&(r=t[e+1])}return l&&(a=s.x>t[e-2].x?1:s.x===t[e-2].x?0:-1,c=s.y>t[e-2].y?1:s.y===t[e-2].y?0:-1),n.push("L ",s.x+a*i," ",s.y+c*i),n},createPath:function(t){var e=new v.Path(t,{fill:null,stroke:this.color,strokeWidth:this.width,strokeLineCap:this.strokeLineCap,strokeMiterLimit:this.strokeMiterLimit,strokeLineJoin:this.strokeLineJoin,strokeDashArray:this.strokeDashArray});return this.shadow&&(this.shadow.affectStroke=!0,e.shadow=new v.Shadow(this.shadow)),e},decimatePoints:function(t,e){if(t.length<=2)return t;var n,i=this.canvas.getZoom(),s=Math.pow(e/i,2),r=t.length-1,o=t[0],a=[o];for(n=1;n<r-1;n++)Math.pow(o.x-t[n].x,2)+Math.pow(o.y-t[n].y,2)>=s&&(o=t[n],a.push(o));return a.push(t[r]),a},_finalizeAndAddPath:function(){this.canvas.contextTop.closePath(),this.decimate&&(this._points=this.decimatePoints(this._points,this.decimate));var t=this.convertPointsToSVGPath(this._points).join("");if("M 0 0 Q 0 0 0 0 L 0 0"!==t){var e=this.createPath(t);this.canvas.clearContext(this.canvas.contextTop),this.canvas.fire("before:path:created",{path:e}),this.canvas.add(e),this.canvas.requestRenderAll(),e.setCoords(),this._resetShadow(),this.canvas.fire("path:created",{path:e})}else this.canvas.requestRenderAll()}}),v.CircleBrush=v.util.createClass(v.BaseBrush,{width:10,initialize:function(t){this.canvas=t,this.points=[]},drawDot:function(t){var e=this.addPoint(t),n=this.canvas.contextTop;this._saveAndTransform(n),this.dot(n,e),n.restore()},dot:function(t,e){t.fillStyle=e.fill,t.beginPath(),t.arc(e.x,e.y,e.radius,0,2*Math.PI,!1),t.closePath(),t.fill()},onMouseDown:function(t){this.points.length=0,this.canvas.clearContext(this.canvas.contextTop),this._setShadow(),this.drawDot(t)},_render:function(){var t,e,n=this.canvas.contextTop,i=this.points;for(this._saveAndTransform(n),t=0,e=i.length;t<e;t++)this.dot(n,i[t]);n.restore()},onMouseMove:function(t){!0===this.limitedToCanvasSize&&this._isOutSideCanvas(t)||(this.needsFullRender()?(this.canvas.clearContext(this.canvas.contextTop),this.addPoint(t),this._render()):this.drawDot(t))},onMouseUp:function(){var t,e,n=this.canvas.renderOnAddRemove;this.canvas.renderOnAddRemove=!1;var i=[];for(t=0,e=this.points.length;t<e;t++){var s=this.points[t],r=new v.Circle({radius:s.radius,left:s.x,top:s.y,originX:"center",originY:"center",fill:s.fill});this.shadow&&(r.shadow=new v.Shadow(this.shadow)),i.push(r)}var o=new v.Group(i);o.canvas=this.canvas,this.canvas.fire("before:path:created",{path:o}),this.canvas.add(o),this.canvas.fire("path:created",{path:o}),this.canvas.clearContext(this.canvas.contextTop),this._resetShadow(),this.canvas.renderOnAddRemove=n,this.canvas.requestRenderAll()},addPoint:function(t){var e=new v.Point(t.x,t.y),n=v.util.getRandomInt(Math.max(0,this.width-20),this.width+20)/2,i=new v.Color(this.color).setAlpha(v.util.getRandomInt(0,100)/100).toRgba();return e.radius=n,e.fill=i,this.points.push(e),e}}),v.SprayBrush=v.util.createClass(v.BaseBrush,{width:10,density:20,dotWidth:1,dotWidthVariance:1,randomOpacity:!1,optimizeOverlapping:!0,initialize:function(t){this.canvas=t,this.sprayChunks=[]},onMouseDown:function(t){this.sprayChunks.length=0,this.canvas.clearContext(this.canvas.contextTop),this._setShadow(),this.addSprayChunk(t),this.render(this.sprayChunkPoints)},onMouseMove:function(t){!0===this.limitedToCanvasSize&&this._isOutSideCanvas(t)||(this.addSprayChunk(t),this.render(this.sprayChunkPoints))},onMouseUp:function(){var t=this.canvas.renderOnAddRemove;this.canvas.renderOnAddRemove=!1;for(var e=[],n=0,i=this.sprayChunks.length;n<i;n++)for(var s=this.sprayChunks[n],r=0,o=s.length;r<o;r++){var a=new v.Rect({width:s[r].width,height:s[r].width,left:s[r].x+1,top:s[r].y+1,originX:"center",originY:"center",fill:this.color});e.push(a)}this.optimizeOverlapping&&(e=this._getOptimizedRects(e));var c=new v.Group(e);this.shadow&&c.set("shadow",new v.Shadow(this.shadow)),this.canvas.fire("before:path:created",{path:c}),this.canvas.add(c),this.canvas.fire("path:created",{path:c}),this.canvas.clearContext(this.canvas.contextTop),this._resetShadow(),this.canvas.renderOnAddRemove=t,this.canvas.requestRenderAll()},_getOptimizedRects:function(t){var e,n,i,s={};for(n=0,i=t.length;n<i;n++)s[e=t[n].left+""+t[n].top]||(s[e]=t[n]);var r=[];for(e in s)r.push(s[e]);return r},render:function(t){var e,n,i=this.canvas.contextTop;for(i.fillStyle=this.color,this._saveAndTransform(i),e=0,n=t.length;e<n;e++){var s=t[e];void 0!==s.opacity&&(i.globalAlpha=s.opacity),i.fillRect(s.x,s.y,s.width,s.width)}i.restore()},_render:function(){var t,e,n=this.canvas.contextTop;for(n.fillStyle=this.color,this._saveAndTransform(n),t=0,e=this.sprayChunks.length;t<e;t++)this.render(this.sprayChunks[t]);n.restore()},addSprayChunk:function(t){this.sprayChunkPoints=[];var e,n,i,s,r=this.width/2;for(s=0;s<this.density;s++){e=v.util.getRandomInt(t.x-r,t.x+r),n=v.util.getRandomInt(t.y-r,t.y+r),i=this.dotWidthVariance?v.util.getRandomInt(Math.max(1,this.dotWidth-this.dotWidthVariance),this.dotWidth+this.dotWidthVariance):this.dotWidth;var o=new v.Point(e,n);o.width=i,this.randomOpacity&&(o.opacity=v.util.getRandomInt(0,100)/100),this.sprayChunkPoints.push(o)}this.sprayChunks.push(this.sprayChunkPoints)}}),v.PatternBrush=v.util.createClass(v.PencilBrush,{getPatternSrc:function(){var t=v.util.createCanvasElement(),e=t.getContext("2d");return t.width=t.height=25,e.fillStyle=this.color,e.beginPath(),e.arc(10,10,10,0,2*Math.PI,!1),e.closePath(),e.fill(),t},getPatternSrcFunction:function(){return String(this.getPatternSrc).replace("this.color",'"'+this.color+'"')},getPattern:function(){return this.canvas.contextTop.createPattern(this.source||this.getPatternSrc(),"repeat")},_setBrushStyles:function(){this.callSuper("_setBrushStyles"),this.canvas.contextTop.strokeStyle=this.getPattern()},createPath:function(t){var e=this.callSuper("createPath",t),n=e._getLeftTopCoords().scalarAdd(e.strokeWidth/2);return e.stroke=new v.Pattern({source:this.source||this.getPatternSrcFunction(),offsetX:-n.x,offsetY:-n.y}),e}}),function(){var t=v.util.getPointer,e=v.util.degreesToRadians,n=Math.abs,i=v.StaticCanvas.supports("setLineDash"),s=v.util.isTouchEvent,r=.5;for(var o in v.Canvas=v.util.createClass(v.StaticCanvas,{initialize:function(t,e){e||(e={}),this.renderAndResetBound=this.renderAndReset.bind(this),this.requestRenderAllBound=this.requestRenderAll.bind(this),this._initStatic(t,e),this._initInteractive(),this._createCacheCanvas()},uniformScaling:!0,uniScaleKey:"shiftKey",centeredScaling:!1,centeredRotation:!1,centeredKey:"altKey",altActionKey:"shiftKey",interactive:!0,selection:!0,selectionKey:"shiftKey",altSelectionKey:null,selectionColor:"rgba(100, 100, 255, 0.3)",selectionDashArray:[],selectionBorderColor:"rgba(255, 255, 255, 0.3)",selectionLineWidth:1,selectionFullyContained:!1,hoverCursor:"move",moveCursor:"move",defaultCursor:"default",freeDrawingCursor:"crosshair",rotationCursor:"crosshair",notAllowedCursor:"not-allowed",containerClass:"canvas-container",perPixelTargetFind:!1,targetFindTolerance:0,skipTargetFind:!1,isDrawingMode:!1,preserveObjectStacking:!1,snapAngle:0,snapThreshold:null,stopContextMenu:!1,fireRightClick:!1,fireMiddleClick:!1,targets:[],_hoveredTarget:null,_hoveredTargets:[],_initInteractive:function(){this._currentTransform=null,this._groupSelector=null,this._initWrapperElement(),this._createUpperCanvas(),this._initEventListeners(),this._initRetinaScaling(),this.freeDrawingBrush=v.PencilBrush&&new v.PencilBrush(this),this.calcOffset()},_chooseObjectsToRender:function(){var t,e,n,i=this.getActiveObjects();if(i.length>0&&!this.preserveObjectStacking){e=[],n=[];for(var s=0,r=this._objects.length;s<r;s++)t=this._objects[s],-1===i.indexOf(t)?e.push(t):n.push(t);i.length>1&&(this._activeObject._objects=n),e.push.apply(e,n)}else e=this._objects;return e},renderAll:function(){!this.contextTopDirty||this._groupSelector||this.isDrawingMode||(this.clearContext(this.contextTop),this.contextTopDirty=!1),this.hasLostContext&&this.renderTopLayer(this.contextTop);var t=this.contextContainer;return this.renderCanvas(t,this._chooseObjectsToRender()),this},renderTopLayer:function(t){t.save(),this.isDrawingMode&&this._isCurrentlyDrawing&&(this.freeDrawingBrush&&this.freeDrawingBrush._render(),this.contextTopDirty=!0),this.selection&&this._groupSelector&&(this._drawSelection(t),this.contextTopDirty=!0),t.restore()},renderTop:function(){var t=this.contextTop;return this.clearContext(t),this.renderTopLayer(t),this.fire("after:render"),this},_normalizePointer:function(t,e){var n=t.calcTransformMatrix(),i=v.util.invertTransform(n),s=this.restorePointerVpt(e);return v.util.transformPoint(s,i)},isTargetTransparent:function(t,e,n){if(t.shouldCache()&&t._cacheCanvas&&t!==this._activeObject){var i=this._normalizePointer(t,{x:e,y:n}),s=Math.max(t.cacheTranslationX+i.x*t.zoomX,0),r=Math.max(t.cacheTranslationY+i.y*t.zoomY,0);return v.util.isTransparent(t._cacheContext,Math.round(s),Math.round(r),this.targetFindTolerance)}var o=this.contextCache,a=t.selectionBackgroundColor,c=this.viewportTransform;return t.selectionBackgroundColor="",this.clearContext(o),o.save(),o.transform(c[0],c[1],c[2],c[3],c[4],c[5]),t.render(o),o.restore(),t.selectionBackgroundColor=a,v.util.isTransparent(o,e,n,this.targetFindTolerance)},_isSelectionKeyPressed:function(t){return"[object Array]"===Object.prototype.toString.call(this.selectionKey)?!!this.selectionKey.find((function(e){return!0===t[e]})):t[this.selectionKey]},_shouldClearSelection:function(t,e){var n=this.getActiveObjects(),i=this._activeObject;return!e||e&&i&&n.length>1&&-1===n.indexOf(e)&&i!==e&&!this._isSelectionKeyPressed(t)||e&&!e.evented||e&&!e.selectable&&i&&i!==e},_shouldCenterTransform:function(t,e,n){var i;if(t)return"scale"===e||"scaleX"===e||"scaleY"===e||"resizing"===e?i=this.centeredScaling||t.centeredScaling:"rotate"===e&&(i=this.centeredRotation||t.centeredRotation),i?!n:n},_getOriginFromCorner:function(t,e){var n={x:t.originX,y:t.originY};return"ml"===e||"tl"===e||"bl"===e?n.x="right":"mr"!==e&&"tr"!==e&&"br"!==e||(n.x="left"),"tl"===e||"mt"===e||"tr"===e?n.y="bottom":"bl"!==e&&"mb"!==e&&"br"!==e||(n.y="top"),n},_getActionFromCorner:function(t,e,n,i){if(!e||!t)return"drag";var s=i.controls[e];return s.getActionName(n,s,i)},_setupCurrentTransform:function(t,n,i){if(n){var s=this.getPointer(t),r=n.__corner,o=n.controls[r],a=i&&r?o.getActionHandler(t,n,o):v.controlsUtils.dragHandler,c=this._getActionFromCorner(i,r,t,n),l=this._getOriginFromCorner(n,r),h=t[this.centeredKey],u={target:n,action:c,actionHandler:a,corner:r,scaleX:n.scaleX,scaleY:n.scaleY,skewX:n.skewX,skewY:n.skewY,offsetX:s.x-n.left,offsetY:s.y-n.top,originX:l.x,originY:l.y,ex:s.x,ey:s.y,lastX:s.x,lastY:s.y,theta:e(n.angle),width:n.width*n.scaleX,shiftKey:t.shiftKey,altKey:h,original:v.util.saveObjectTransform(n)};this._shouldCenterTransform(n,c,h)&&(u.originX="center",u.originY="center"),u.original.originX=l.x,u.original.originY=l.y,this._currentTransform=u,this._beforeTransform(t)}},setCursor:function(t){this.upperCanvasEl.style.cursor=t},_drawSelection:function(t){var e=this._groupSelector,s=e.left,o=e.top,a=n(s),c=n(o);if(this.selectionColor&&(t.fillStyle=this.selectionColor,t.fillRect(e.ex-(s>0?0:-s),e.ey-(o>0?0:-o),a,c)),this.selectionLineWidth&&this.selectionBorderColor)if(t.lineWidth=this.selectionLineWidth,t.strokeStyle=this.selectionBorderColor,this.selectionDashArray.length>1&&!i){var l=e.ex+r-(s>0?0:a),h=e.ey+r-(o>0?0:c);t.beginPath(),v.util.drawDashedLine(t,l,h,l+a,h,this.selectionDashArray),v.util.drawDashedLine(t,l,h+c-1,l+a,h+c-1,this.selectionDashArray),v.util.drawDashedLine(t,l,h,l,h+c,this.selectionDashArray),v.util.drawDashedLine(t,l+a-1,h,l+a-1,h+c,this.selectionDashArray),t.closePath(),t.stroke()}else v.Object.prototype._setLineDash.call(this,t,this.selectionDashArray),t.strokeRect(e.ex+r-(s>0?0:a),e.ey+r-(o>0?0:c),a,c)},findTarget:function(t,e){if(!this.skipTargetFind){var n,i,r=this.getPointer(t,!0),o=this._activeObject,a=this.getActiveObjects(),c=s(t),l=a.length>1&&!e||1===a.length;if(this.targets=[],l&&o._findTargetCorner(r,c))return o;if(a.length>1&&!e&&o===this._searchPossibleTargets([o],r))return o;if(1===a.length&&o===this._searchPossibleTargets([o],r)){if(!this.preserveObjectStacking)return o;n=o,i=this.targets,this.targets=[]}var h=this._searchPossibleTargets(this._objects,r);return t[this.altSelectionKey]&&h&&n&&h!==n&&(h=n,this.targets=i),h}},_checkTarget:function(t,e,n){if(e&&e.visible&&e.evented&&e.containsPoint(t)){if(!this.perPixelTargetFind&&!e.perPixelTargetFind||e.isEditing)return!0;if(!this.isTargetTransparent(e,n.x,n.y))return!0}},_searchPossibleTargets:function(t,e){for(var n,i,s=t.length;s--;){var r=t[s],o=r.group?this._normalizePointer(r.group,e):e;if(this._checkTarget(o,r,e)){(n=t[s]).subTargetCheck&&n instanceof v.Group&&(i=this._searchPossibleTargets(n._objects,e))&&this.targets.push(i);break}}return n},restorePointerVpt:function(t){return v.util.transformPoint(t,v.util.invertTransform(this.viewportTransform))},getPointer:function(e,n){if(this._absolutePointer&&!n)return this._absolutePointer;if(this._pointer&&n)return this._pointer;var i,s=t(e),r=this.upperCanvasEl,o=r.getBoundingClientRect(),a=o.width||0,c=o.height||0;a&&c||("top"in o&&"bottom"in o&&(c=Math.abs(o.top-o.bottom)),"right"in o&&"left"in o&&(a=Math.abs(o.right-o.left))),this.calcOffset(),s.x=s.x-this._offset.left,s.y=s.y-this._offset.top,n||(s=this.restorePointerVpt(s));var l=this.getRetinaScaling();return 1!==l&&(s.x/=l,s.y/=l),i=0===a||0===c?{width:1,height:1}:{width:r.width/a,height:r.height/c},{x:s.x*i.width,y:s.y*i.height}},_createUpperCanvas:function(){var t=this.lowerCanvasEl.className.replace(/\s*lower-canvas\s*/,""),e=this.lowerCanvasEl,n=this.upperCanvasEl;n?n.className="":(n=this._createCanvasElement(),this.upperCanvasEl=n),v.util.addClass(n,"upper-canvas "+t),this.wrapperEl.appendChild(n),this._copyCanvasStyle(e,n),this._applyCanvasStyle(n),this.contextTop=n.getContext("2d")},_createCacheCanvas:function(){this.cacheCanvasEl=this._createCanvasElement(),this.cacheCanvasEl.setAttribute("width",this.width),this.cacheCanvasEl.setAttribute("height",this.height),this.contextCache=this.cacheCanvasEl.getContext("2d")},_initWrapperElement:function(){this.wrapperEl=v.util.wrapElement(this.lowerCanvasEl,"div",{class:this.containerClass}),v.util.setStyle(this.wrapperEl,{width:this.width+"px",height:this.height+"px",position:"relative"}),v.util.makeElementUnselectable(this.wrapperEl)},_applyCanvasStyle:function(t){var e=this.width||t.width,n=this.height||t.height;v.util.setStyle(t,{position:"absolute",width:e+"px",height:n+"px",left:0,top:0,"touch-action":this.allowTouchScrolling?"manipulation":"none","-ms-touch-action":this.allowTouchScrolling?"manipulation":"none"}),t.width=e,t.height=n,v.util.makeElementUnselectable(t)},_copyCanvasStyle:function(t,e){e.style.cssText=t.style.cssText},getSelectionContext:function(){return this.contextTop},getSelectionElement:function(){return this.upperCanvasEl},getActiveObject:function(){return this._activeObject},getActiveObjects:function(){var t=this._activeObject;return t?"activeSelection"===t.type&&t._objects?t._objects.slice(0):[t]:[]},_onObjectRemoved:function(t){t===this._activeObject&&(this.fire("before:selection:cleared",{target:t}),this._discardActiveObject(),this.fire("selection:cleared",{target:t}),t.fire("deselected")),t===this._hoveredTarget&&(this._hoveredTarget=null,this._hoveredTargets=[]),this.callSuper("_onObjectRemoved",t)},_fireSelectionEvents:function(t,e){var n=!1,i=this.getActiveObjects(),s=[],r=[];t.forEach((function(t){-1===i.indexOf(t)&&(n=!0,t.fire("deselected",{e:e,target:t}),r.push(t))})),i.forEach((function(i){-1===t.indexOf(i)&&(n=!0,i.fire("selected",{e:e,target:i}),s.push(i))})),t.length>0&&i.length>0?n&&this.fire("selection:updated",{e:e,selected:s,deselected:r,updated:s[0]||r[0],target:this._activeObject}):i.length>0?this.fire("selection:created",{e:e,selected:s,target:this._activeObject}):t.length>0&&this.fire("selection:cleared",{e:e,deselected:r})},setActiveObject:function(t,e){var n=this.getActiveObjects();return this._setActiveObject(t,e),this._fireSelectionEvents(n,e),this},_setActiveObject:function(t,e){return this._activeObject!==t&&(!!this._discardActiveObject(e,t)&&(!t.onSelect({e:e})&&(this._activeObject=t,!0)))},_discardActiveObject:function(t,e){var n=this._activeObject;if(n){if(n.onDeselect({e:t,object:e}))return!1;this._activeObject=null}return!0},discardActiveObject:function(t){var e=this.getActiveObjects(),n=this.getActiveObject();return e.length&&this.fire("before:selection:cleared",{target:n,e:t}),this._discardActiveObject(t),this._fireSelectionEvents(e,t),this},dispose:function(){var t=this.wrapperEl;return this.removeListeners(),t.removeChild(this.upperCanvasEl),t.removeChild(this.lowerCanvasEl),this.contextCache=null,this.contextTop=null,["upperCanvasEl","cacheCanvasEl"].forEach(function(t){v.util.cleanUpJsdomNode(this[t]),this[t]=void 0}.bind(this)),t.parentNode&&t.parentNode.replaceChild(this.lowerCanvasEl,this.wrapperEl),delete this.wrapperEl,v.StaticCanvas.prototype.dispose.call(this),this},clear:function(){return this.discardActiveObject(),this.clearContext(this.contextTop),this.callSuper("clear")},drawControls:function(t){var e=this._activeObject;e&&e._renderControls(t)},_toObject:function(t,e,n){var i=this._realizeGroupTransformOnObject(t),s=this.callSuper("_toObject",t,e,n);return this._unwindGroupTransformOnObject(t,i),s},_realizeGroupTransformOnObject:function(t){if(t.group&&"activeSelection"===t.group.type&&this._activeObject===t.group){var e={};return["angle","flipX","flipY","left","scaleX","scaleY","skewX","skewY","top"].forEach((function(n){e[n]=t[n]})),v.util.addTransformToObject(t,this._activeObject.calcOwnMatrix()),e}return null},_unwindGroupTransformOnObject:function(t,e){e&&t.set(e)},_setSVGObject:function(t,e,n){var i=this._realizeGroupTransformOnObject(e);this.callSuper("_setSVGObject",t,e,n),this._unwindGroupTransformOnObject(e,i)},setViewportTransform:function(t){this.renderOnAddRemove&&this._activeObject&&this._activeObject.isEditing&&this._activeObject.clearContextTop(),v.StaticCanvas.prototype.setViewportTransform.call(this,t)}}),v.StaticCanvas)"prototype"!==o&&(v.Canvas[o]=v.StaticCanvas[o])}(),function(){var t=v.util.addListener,e=v.util.removeListener,n={passive:!1};function i(t,e){return t.button&&t.button===e-1}v.util.object.extend(v.Canvas.prototype,{mainTouchId:null,_initEventListeners:function(){this.removeListeners(),this._bindEvents(),this.addOrRemove(t,"add")},_getEventPrefix:function(){return this.enablePointerEvents?"pointer":"mouse"},addOrRemove:function(t,e){var i=this.upperCanvasEl,s=this._getEventPrefix();t(v.window,"resize",this._onResize),t(i,s+"down",this._onMouseDown),t(i,s+"move",this._onMouseMove,n),t(i,s+"out",this._onMouseOut),t(i,s+"enter",this._onMouseEnter),t(i,"wheel",this._onMouseWheel),t(i,"contextmenu",this._onContextMenu),t(i,"dblclick",this._onDoubleClick),t(i,"dragover",this._onDragOver),t(i,"dragenter",this._onDragEnter),t(i,"dragleave",this._onDragLeave),t(i,"drop",this._onDrop),this.enablePointerEvents||t(i,"touchstart",this._onTouchStart,n),"undefined"!=typeof eventjs&&e in eventjs&&(eventjs[e](i,"gesture",this._onGesture),eventjs[e](i,"drag",this._onDrag),eventjs[e](i,"orientation",this._onOrientationChange),eventjs[e](i,"shake",this._onShake),eventjs[e](i,"longpress",this._onLongPress))},removeListeners:function(){this.addOrRemove(e,"remove");var t=this._getEventPrefix();e(v.document,t+"up",this._onMouseUp),e(v.document,"touchend",this._onTouchEnd,n),e(v.document,t+"move",this._onMouseMove,n),e(v.document,"touchmove",this._onMouseMove,n)},_bindEvents:function(){this.eventsBound||(this._onMouseDown=this._onMouseDown.bind(this),this._onTouchStart=this._onTouchStart.bind(this),this._onMouseMove=this._onMouseMove.bind(this),this._onMouseUp=this._onMouseUp.bind(this),this._onTouchEnd=this._onTouchEnd.bind(this),this._onResize=this._onResize.bind(this),this._onGesture=this._onGesture.bind(this),this._onDrag=this._onDrag.bind(this),this._onShake=this._onShake.bind(this),this._onLongPress=this._onLongPress.bind(this),this._onOrientationChange=this._onOrientationChange.bind(this),this._onMouseWheel=this._onMouseWheel.bind(this),this._onMouseOut=this._onMouseOut.bind(this),this._onMouseEnter=this._onMouseEnter.bind(this),this._onContextMenu=this._onContextMenu.bind(this),this._onDoubleClick=this._onDoubleClick.bind(this),this._onDragOver=this._onDragOver.bind(this),this._onDragEnter=this._simpleEventHandler.bind(this,"dragenter"),this._onDragLeave=this._simpleEventHandler.bind(this,"dragleave"),this._onDrop=this._simpleEventHandler.bind(this,"drop"),this.eventsBound=!0)},_onGesture:function(t,e){this.__onTransformGesture&&this.__onTransformGesture(t,e)},_onDrag:function(t,e){this.__onDrag&&this.__onDrag(t,e)},_onMouseWheel:function(t){this.__onMouseWheel(t)},_onMouseOut:function(t){var e=this._hoveredTarget;this.fire("mouse:out",{target:e,e:t}),this._hoveredTarget=null,e&&e.fire("mouseout",{e:t});var n=this;this._hoveredTargets.forEach((function(i){n.fire("mouse:out",{target:e,e:t}),i&&e.fire("mouseout",{e:t})})),this._hoveredTargets=[],this._iTextInstances&&this._iTextInstances.forEach((function(t){t.isEditing&&t.hiddenTextarea.focus()}))},_onMouseEnter:function(t){this._currentTransform||this.findTarget(t)||(this.fire("mouse:over",{target:null,e:t}),this._hoveredTarget=null,this._hoveredTargets=[])},_onOrientationChange:function(t,e){this.__onOrientationChange&&this.__onOrientationChange(t,e)},_onShake:function(t,e){this.__onShake&&this.__onShake(t,e)},_onLongPress:function(t,e){this.__onLongPress&&this.__onLongPress(t,e)},_onDragOver:function(t){t.preventDefault();var e=this._simpleEventHandler("dragover",t);this._fireEnterLeaveEvents(e,t)},_onContextMenu:function(t){return this.stopContextMenu&&(t.stopPropagation(),t.preventDefault()),!1},_onDoubleClick:function(t){this._cacheTransformEventData(t),this._handleEvent(t,"dblclick"),this._resetTransformEventData(t)},getPointerId:function(t){var e=t.changedTouches;return e?e[0]&&e[0].identifier:this.enablePointerEvents?t.pointerId:-1},_isMainEvent:function(t){return!0===t.isPrimary||!1!==t.isPrimary&&("touchend"===t.type&&0===t.touches.length||(!t.changedTouches||t.changedTouches[0].identifier===this.mainTouchId))},_onTouchStart:function(i){i.preventDefault(),null===this.mainTouchId&&(this.mainTouchId=this.getPointerId(i)),this.__onMouseDown(i),this._resetTransformEventData();var s=this.upperCanvasEl,r=this._getEventPrefix();t(v.document,"touchend",this._onTouchEnd,n),t(v.document,"touchmove",this._onMouseMove,n),e(s,r+"down",this._onMouseDown)},_onMouseDown:function(i){this.__onMouseDown(i),this._resetTransformEventData();var s=this.upperCanvasEl,r=this._getEventPrefix();e(s,r+"move",this._onMouseMove,n),t(v.document,r+"up",this._onMouseUp),t(v.document,r+"move",this._onMouseMove,n)},_onTouchEnd:function(i){if(!(i.touches.length>0)){this.__onMouseUp(i),this._resetTransformEventData(),this.mainTouchId=null;var s=this._getEventPrefix();e(v.document,"touchend",this._onTouchEnd,n),e(v.document,"touchmove",this._onMouseMove,n);var r=this;this._willAddMouseDown&&clearTimeout(this._willAddMouseDown),this._willAddMouseDown=setTimeout((function(){t(r.upperCanvasEl,s+"down",r._onMouseDown),r._willAddMouseDown=0}),400)}},_onMouseUp:function(i){this.__onMouseUp(i),this._resetTransformEventData();var s=this.upperCanvasEl,r=this._getEventPrefix();this._isMainEvent(i)&&(e(v.document,r+"up",this._onMouseUp),e(v.document,r+"move",this._onMouseMove,n),t(s,r+"move",this._onMouseMove,n))},_onMouseMove:function(t){!this.allowTouchScrolling&&t.preventDefault&&t.preventDefault(),this.__onMouseMove(t)},_onResize:function(){this.calcOffset()},_shouldRender:function(t){var e=this._activeObject;return!!(!!e!=!!t||e&&t&&e!==t)||(e&&e.isEditing,!1)},__onMouseUp:function(t){var e,n=this._currentTransform,s=this._groupSelector,r=!1,o=!s||0===s.left&&0===s.top;if(this._cacheTransformEventData(t),e=this._target,this._handleEvent(t,"up:before"),i(t,3))this.fireRightClick&&this._handleEvent(t,"up",3,o);else{if(i(t,2))return this.fireMiddleClick&&this._handleEvent(t,"up",2,o),void this._resetTransformEventData();if(this.isDrawingMode&&this._isCurrentlyDrawing)this._onMouseUpInDrawingMode(t);else if(this._isMainEvent(t)){if(n&&(this._finalizeCurrentTransform(t),r=n.actionPerformed),!o){var a=e===this._activeObject;this._maybeGroupObjects(t),r||(r=this._shouldRender(e)||!a&&e===this._activeObject)}if(e){if(e.selectable&&e!==this._activeObject&&"up"===e.activeOn)this.setActiveObject(e,t),r=!0;else{var c=e._findTargetCorner(this.getPointer(t,!0),v.util.isTouchEvent(t)),l=e.controls[c],h=l&&l.getMouseUpHandler(t,e,l);if(h){var u=this.getPointer(t);h(t,n,u.x,u.y)}}e.isMoving=!1}this._setCursorFromEvent(t,e),this._handleEvent(t,"up",1,o),this._groupSelector=null,this._currentTransform=null,e&&(e.__corner=0),r?this.requestRenderAll():o||this.renderTop()}}},_simpleEventHandler:function(t,e){var n=this.findTarget(e),i=this.targets,s={e:e,target:n,subTargets:i};if(this.fire(t,s),n&&n.fire(t,s),!i)return n;for(var r=0;r<i.length;r++)i[r].fire(t,s);return n},_handleEvent:function(t,e,n,i){var s=this._target,r=this.targets||[],o={e:t,target:s,subTargets:r,button:n||1,isClick:i||!1,pointer:this._pointer,absolutePointer:this._absolutePointer,transform:this._currentTransform};"up"===e&&(o.currentTarget=this.findTarget(t),o.currentSubTargets=this.targets),this.fire("mouse:"+e,o),s&&s.fire("mouse"+e,o);for(var a=0;a<r.length;a++)r[a].fire("mouse"+e,o)},_finalizeCurrentTransform:function(t){var e,n=this._currentTransform,i=n.target,s={e:t,target:i,transform:n,action:n.action};i._scaling&&(i._scaling=!1),i.setCoords(),(n.actionPerformed||this.stateful&&i.hasStateChanged())&&(n.actionPerformed&&(e=this._addEventOptions(s,n),this._fire(e,s)),this._fire("modified",s))},_addEventOptions:function(t,e){var n,i;switch(e.action){case"scaleX":n="scaled",i="x";break;case"scaleY":n="scaled",i="y";break;case"skewX":n="skewed",i="x";break;case"skewY":n="skewed",i="y";break;case"scale":n="scaled",i="equally";break;case"rotate":n="rotated";break;case"drag":n="moved"}return t.by=i,n},_onMouseDownInDrawingMode:function(t){this._isCurrentlyDrawing=!0,this.getActiveObject()&&this.discardActiveObject(t).requestRenderAll();var e=this.getPointer(t);this.freeDrawingBrush.onMouseDown(e,{e:t,pointer:e}),this._handleEvent(t,"down")},_onMouseMoveInDrawingMode:function(t){if(this._isCurrentlyDrawing){var e=this.getPointer(t);this.freeDrawingBrush.onMouseMove(e,{e:t,pointer:e})}this.setCursor(this.freeDrawingCursor),this._handleEvent(t,"move")},_onMouseUpInDrawingMode:function(t){var e=this.getPointer(t);this._isCurrentlyDrawing=this.freeDrawingBrush.onMouseUp({e:t,pointer:e}),this._handleEvent(t,"up")},__onMouseDown:function(t){this._cacheTransformEventData(t),this._handleEvent(t,"down:before");var e=this._target;if(i(t,3))this.fireRightClick&&this._handleEvent(t,"down",3);else if(i(t,2))this.fireMiddleClick&&this._handleEvent(t,"down",2);else if(this.isDrawingMode)this._onMouseDownInDrawingMode(t);else if(this._isMainEvent(t)&&!this._currentTransform){var n=this._pointer;this._previousPointer=n;var s=this._shouldRender(e),r=this._shouldGroup(t,e);if(this._shouldClearSelection(t,e)?this.discardActiveObject(t):r&&(this._handleGrouping(t,e),e=this._activeObject),!this.selection||e&&(e.selectable||e.isEditing||e===this._activeObject)||(this._groupSelector={ex:n.x,ey:n.y,top:0,left:0}),e){var o=e===this._activeObject;e.selectable&&"down"===e.activeOn&&this.setActiveObject(e,t);var a=e._findTargetCorner(this.getPointer(t,!0),v.util.isTouchEvent(t));if(e.__corner=a,e===this._activeObject&&(a||!r)){this._setupCurrentTransform(t,e,o);var c=e.controls[a],l=(n=this.getPointer(t),c&&c.getMouseDownHandler(t,e,c));l&&l(t,this._currentTransform,n.x,n.y)}}this._handleEvent(t,"down"),(s||r)&&this.requestRenderAll()}},_resetTransformEventData:function(){this._target=null,this._pointer=null,this._absolutePointer=null},_cacheTransformEventData:function(t){this._resetTransformEventData(),this._pointer=this.getPointer(t,!0),this._absolutePointer=this.restorePointerVpt(this._pointer),this._target=this._currentTransform?this._currentTransform.target:this.findTarget(t)||null},_beforeTransform:function(t){var e=this._currentTransform;this.stateful&&e.target.saveState(),this.fire("before:transform",{e:t,transform:e})},__onMouseMove:function(t){var e,n;if(this._handleEvent(t,"move:before"),this._cacheTransformEventData(t),this.isDrawingMode)this._onMouseMoveInDrawingMode(t);else if(this._isMainEvent(t)){var i=this._groupSelector;i?(n=this._pointer,i.left=n.x-i.ex,i.top=n.y-i.ey,this.renderTop()):this._currentTransform?this._transformObject(t):(e=this.findTarget(t)||null,this._setCursorFromEvent(t,e),this._fireOverOutEvents(e,t)),this._handleEvent(t,"move"),this._resetTransformEventData()}},_fireOverOutEvents:function(t,e){var n=this._hoveredTarget,i=this._hoveredTargets,s=this.targets,r=Math.max(i.length,s.length);this.fireSyntheticInOutEvents(t,e,{oldTarget:n,evtOut:"mouseout",canvasEvtOut:"mouse:out",evtIn:"mouseover",canvasEvtIn:"mouse:over"});for(var o=0;o<r;o++)this.fireSyntheticInOutEvents(s[o],e,{oldTarget:i[o],evtOut:"mouseout",evtIn:"mouseover"});this._hoveredTarget=t,this._hoveredTargets=this.targets.concat()},_fireEnterLeaveEvents:function(t,e){var n=this._draggedoverTarget,i=this._hoveredTargets,s=this.targets,r=Math.max(i.length,s.length);this.fireSyntheticInOutEvents(t,e,{oldTarget:n,evtOut:"dragleave",evtIn:"dragenter"});for(var o=0;o<r;o++)this.fireSyntheticInOutEvents(s[o],e,{oldTarget:i[o],evtOut:"dragleave",evtIn:"dragenter"});this._draggedoverTarget=t},fireSyntheticInOutEvents:function(t,e,n){var i,s,r,o=n.oldTarget,a=o!==t,c=n.canvasEvtIn,l=n.canvasEvtOut;a&&(i={e:e,target:t,previousTarget:o},s={e:e,target:o,nextTarget:t}),r=t&&a,o&&a&&(l&&this.fire(l,s),o.fire(n.evtOut,s)),r&&(c&&this.fire(c,i),t.fire(n.evtIn,i))},__onMouseWheel:function(t){this._cacheTransformEventData(t),this._handleEvent(t,"wheel"),this._resetTransformEventData()},_transformObject:function(t){var e=this.getPointer(t),n=this._currentTransform;n.reset=!1,n.shiftKey=t.shiftKey,n.altKey=t[this.centeredKey],this._performTransformAction(t,n,e),n.actionPerformed&&this.requestRenderAll()},_performTransformAction:function(t,e,n){var i=n.x,s=n.y,r=e.action,o=!1,a=e.actionHandler;a&&(o=a(t,e,i,s)),"drag"===r&&o&&(e.target.isMoving=!0,this.setCursor(e.target.moveCursor||this.moveCursor)),e.actionPerformed=e.actionPerformed||o},_fire:v.controlsUtils.fireEvent,_setCursorFromEvent:function(t,e){if(!e)return this.setCursor(this.defaultCursor),!1;var n=e.hoverCursor||this.hoverCursor,i=this._activeObject&&"activeSelection"===this._activeObject.type?this._activeObject:null,s=(!i||!i.contains(e))&&e._findTargetCorner(this.getPointer(t,!0));s?this.setCursor(this.getCornerCursor(s,e,t)):(e.subTargetCheck&&this.targets.concat().reverse().map((function(t){n=t.hoverCursor||n})),this.setCursor(n))},getCornerCursor:function(t,e,n){var i=e.controls[t];return i.cursorStyleHandler(n,i,e)}})}(),u=Math.min,d=Math.max,v.util.object.extend(v.Canvas.prototype,{_shouldGroup:function(t,e){var n=this._activeObject;return n&&this._isSelectionKeyPressed(t)&&e&&e.selectable&&this.selection&&(n!==e||"activeSelection"===n.type)&&!e.onSelect({e:t})},_handleGrouping:function(t,e){var n=this._activeObject;n.__corner||(e!==n||(e=this.findTarget(t,!0))&&e.selectable)&&(n&&"activeSelection"===n.type?this._updateActiveSelection(e,t):this._createActiveSelection(e,t))},_updateActiveSelection:function(t,e){var n=this._activeObject,i=n._objects.slice(0);n.contains(t)?(n.removeWithUpdate(t),this._hoveredTarget=t,this._hoveredTargets=this.targets.concat(),1===n.size()&&this._setActiveObject(n.item(0),e)):(n.addWithUpdate(t),this._hoveredTarget=n,this._hoveredTargets=this.targets.concat()),this._fireSelectionEvents(i,e)},_createActiveSelection:function(t,e){var n=this.getActiveObjects(),i=this._createGroup(t);this._hoveredTarget=i,this._setActiveObject(i,e),this._fireSelectionEvents(n,e)},_createGroup:function(t){var e=this._objects,n=e.indexOf(this._activeObject)<e.indexOf(t)?[this._activeObject,t]:[t,this._activeObject];return this._activeObject.isEditing&&this._activeObject.exitEditing(),new v.ActiveSelection(n,{canvas:this})},_groupSelectedObjects:function(t){var e,n=this._collectObjects(t);1===n.length?this.setActiveObject(n[0],t):n.length>1&&(e=new v.ActiveSelection(n.reverse(),{canvas:this}),this.setActiveObject(e,t))},_collectObjects:function(t){for(var e,n=[],i=this._groupSelector.ex,s=this._groupSelector.ey,r=i+this._groupSelector.left,o=s+this._groupSelector.top,a=new v.Point(u(i,r),u(s,o)),c=new v.Point(d(i,r),d(s,o)),l=!this.selectionFullyContained,h=i===r&&s===o,f=this._objects.length;f--&&!((e=this._objects[f])&&e.selectable&&e.visible&&(l&&e.intersectsWithRect(a,c)||e.isContainedWithinRect(a,c)||l&&e.containsPoint(a)||l&&e.containsPoint(c))&&(n.push(e),h)););return n.length>1&&(n=n.filter((function(e){return!e.onSelect({e:t})}))),n},_maybeGroupObjects:function(t){this.selection&&this._groupSelector&&this._groupSelectedObjects(t),this.setCursor(this.defaultCursor),this._groupSelector=null}}),v.util.object.extend(v.StaticCanvas.prototype,{toDataURL:function(t){t||(t={});var e=t.format||"png",n=t.quality||1,i=(t.multiplier||1)*(t.enableRetinaScaling?this.getRetinaScaling():1),s=this.toCanvasElement(i,t);return v.util.toDataURL(s,e,n)},toCanvasElement:function(t,e){t=t||1;var n=((e=e||{}).width||this.width)*t,i=(e.height||this.height)*t,s=this.getZoom(),r=this.width,o=this.height,a=s*t,c=this.viewportTransform,l=(c[4]-(e.left||0))*t,h=(c[5]-(e.top||0))*t,u=this.interactive,d=[a,0,0,a,l,h],f=this.enableRetinaScaling,p=v.util.createCanvasElement(),m=this.contextTop;return p.width=n,p.height=i,this.contextTop=null,this.enableRetinaScaling=!1,this.interactive=!1,this.viewportTransform=d,this.width=n,this.height=i,this.calcViewportBoundaries(),this.renderCanvas(p.getContext("2d"),this._objects),this.viewportTransform=c,this.width=r,this.height=o,this.calcViewportBoundaries(),this.interactive=u,this.enableRetinaScaling=f,this.contextTop=m,p}}),v.util.object.extend(v.StaticCanvas.prototype,{loadFromJSON:function(t,e,n){if(t){var i="string"==typeof t?JSON.parse(t):v.util.object.clone(t),s=this,r=i.clipPath,o=this.renderOnAddRemove;return this.renderOnAddRemove=!1,delete i.clipPath,this._enlivenObjects(i.objects,(function(t){s.clear(),s._setBgOverlay(i,(function(){r?s._enlivenObjects([r],(function(n){s.clipPath=n[0],s.__setupCanvas.call(s,i,t,o,e)})):s.__setupCanvas.call(s,i,t,o,e)}))}),n),this}},__setupCanvas:function(t,e,n,i){var s=this;e.forEach((function(t,e){s.insertAt(t,e)})),this.renderOnAddRemove=n,delete t.objects,delete t.backgroundImage,delete t.overlayImage,delete t.background,delete t.overlay,this._setOptions(t),this.renderAll(),i&&i()},_setBgOverlay:function(t,e){var n={backgroundColor:!1,overlayColor:!1,backgroundImage:!1,overlayImage:!1};if(t.backgroundImage||t.overlayImage||t.background||t.overlay){var i=function(){n.backgroundImage&&n.overlayImage&&n.backgroundColor&&n.overlayColor&&e&&e()};this.__setBgOverlay("backgroundImage",t.backgroundImage,n,i),this.__setBgOverlay("overlayImage",t.overlayImage,n,i),this.__setBgOverlay("backgroundColor",t.background,n,i),this.__setBgOverlay("overlayColor",t.overlay,n,i)}else e&&e()},__setBgOverlay:function(t,e,n,i){var s=this;if(!e)return n[t]=!0,void(i&&i());"backgroundImage"===t||"overlayImage"===t?v.util.enlivenObjects([e],(function(e){s[t]=e[0],n[t]=!0,i&&i()})):this["set"+v.util.string.capitalize(t,!0)](e,(function(){n[t]=!0,i&&i()}))},_enlivenObjects:function(t,e,n){t&&0!==t.length?v.util.enlivenObjects(t,(function(t){e&&e(t)}),null,n):e&&e([])},_toDataURL:function(t,e){this.clone((function(n){e(n.toDataURL(t))}))},_toDataURLWithMultiplier:function(t,e,n){this.clone((function(i){n(i.toDataURLWithMultiplier(t,e))}))},clone:function(t,e){var n=JSON.stringify(this.toJSON(e));this.cloneWithoutData((function(e){e.loadFromJSON(n,(function(){t&&t(e)}))}))},cloneWithoutData:function(t){var e=v.util.createCanvasElement();e.width=this.width,e.height=this.height;var n=new v.Canvas(e);this.backgroundImage?(n.setBackgroundImage(this.backgroundImage.src,(function(){n.renderAll(),t&&t(n)})),n.backgroundImageOpacity=this.backgroundImageOpacity,n.backgroundImageStretch=this.backgroundImageStretch):t&&t(n)}}),function(t){var e=t.fabric||(t.fabric={}),n=e.util.object.extend,i=e.util.object.clone,s=e.util.toFixed,r=e.util.string.capitalize,o=e.util.degreesToRadians,a=e.StaticCanvas.supports("setLineDash"),c=!e.isLikelyNode;e.Object||(e.Object=e.util.createClass(e.CommonMethods,{type:"object",originX:"left",originY:"top",top:0,left:0,width:0,height:0,scaleX:1,scaleY:1,flipX:!1,flipY:!1,opacity:1,angle:0,skewX:0,skewY:0,cornerSize:13,touchCornerSize:24,transparentCorners:!0,hoverCursor:null,moveCursor:null,padding:0,borderColor:"rgb(178,204,255)",borderDashArray:null,cornerColor:"rgb(178,204,255)",cornerStrokeColor:null,cornerStyle:"rect",cornerDashArray:null,centeredScaling:!1,centeredRotation:!0,fill:"rgb(0,0,0)",fillRule:"nonzero",globalCompositeOperation:"source-over",backgroundColor:"",selectionBackgroundColor:"",stroke:null,strokeWidth:1,strokeDashArray:null,strokeDashOffset:0,strokeLineCap:"butt",strokeLineJoin:"miter",strokeMiterLimit:4,shadow:null,borderOpacityWhenMoving:.4,borderScaleFactor:1,minScaleLimit:0,selectable:!0,evented:!0,visible:!0,hasControls:!0,hasBorders:!0,perPixelTargetFind:!1,includeDefaultValues:!0,lockMovementX:!1,lockMovementY:!1,lockRotation:!1,lockScalingX:!1,lockScalingY:!1,lockSkewingX:!1,lockSkewingY:!1,lockScalingFlip:!1,excludeFromExport:!1,objectCaching:c,statefullCache:!1,noScaleCache:!0,strokeUniform:!1,dirty:!0,__corner:0,paintFirst:"fill",activeOn:"down",stateProperties:"top left width height scaleX scaleY flipX flipY originX originY transformMatrix stroke strokeWidth strokeDashArray strokeLineCap strokeDashOffset strokeLineJoin strokeMiterLimit angle opacity fill globalCompositeOperation shadow visible backgroundColor skewX skewY fillRule paintFirst clipPath strokeUniform".split(" "),cacheProperties:"fill stroke strokeWidth strokeDashArray width height paintFirst strokeUniform strokeLineCap strokeDashOffset strokeLineJoin strokeMiterLimit backgroundColor clipPath".split(" "),colorProperties:"fill stroke backgroundColor".split(" "),clipPath:void 0,inverted:!1,absolutePositioned:!1,initialize:function(t){t&&this.setOptions(t)},_createCacheCanvas:function(){this._cacheProperties={},this._cacheCanvas=e.util.createCanvasElement(),this._cacheContext=this._cacheCanvas.getContext("2d"),this._updateCacheCanvas(),this.dirty=!0},_limitCacheSize:function(t){var n=e.perfLimitSizeTotal,i=t.width,s=t.height,r=e.maxCacheSideLimit,o=e.minCacheSideLimit;if(i<=r&&s<=r&&i*s<=n)return i<o&&(t.width=o),s<o&&(t.height=o),t;var a=i/s,c=e.util.limitDimsByArea(a,n),l=e.util.capValue,h=l(o,c.x,r),u=l(o,c.y,r);return i>h&&(t.zoomX/=i/h,t.width=h,t.capped=!0),s>u&&(t.zoomY/=s/u,t.height=u,t.capped=!0),t},_getCacheCanvasDimensions:function(){var t=this.getTotalObjectScaling(),e=this._getTransformedDimensions(0,0),n=e.x*t.scaleX/this.scaleX,i=e.y*t.scaleY/this.scaleY;return{width:n+2,height:i+2,zoomX:t.scaleX,zoomY:t.scaleY,x:n,y:i}},_updateCacheCanvas:function(){var t=this.canvas;if(this.noScaleCache&&t&&t._currentTransform){var n=t._currentTransform.target,i=t._currentTransform.action;if(this===n&&i.slice&&"scale"===i.slice(0,5))return!1}var s,r,o=this._cacheCanvas,a=this._limitCacheSize(this._getCacheCanvasDimensions()),c=e.minCacheSideLimit,l=a.width,h=a.height,u=a.zoomX,d=a.zoomY,f=l!==this.cacheWidth||h!==this.cacheHeight,p=this.zoomX!==u||this.zoomY!==d,m=f||p,g=0,v=0,_=!1;if(f){var y=this._cacheCanvas.width,b=this._cacheCanvas.height,x=l>y||h>b;_=x||(l<.9*y||h<.9*b)&&y>c&&b>c,x&&!a.capped&&(l>c||h>c)&&(g=.1*l,v=.1*h)}return!!m&&(_?(o.width=Math.ceil(l+g),o.height=Math.ceil(h+v)):(this._cacheContext.setTransform(1,0,0,1,0,0),this._cacheContext.clearRect(0,0,o.width,o.height)),s=a.x/2,r=a.y/2,this.cacheTranslationX=Math.round(o.width/2-s)+s,this.cacheTranslationY=Math.round(o.height/2-r)+r,this.cacheWidth=l,this.cacheHeight=h,this._cacheContext.translate(this.cacheTranslationX,this.cacheTranslationY),this._cacheContext.scale(u,d),this.zoomX=u,this.zoomY=d,!0)},setOptions:function(t){this._setOptions(t),this._initGradient(t.fill,"fill"),this._initGradient(t.stroke,"stroke"),this._initPattern(t.fill,"fill"),this._initPattern(t.stroke,"stroke")},transform:function(t){var e=this.group&&!this.group._transformDone||this.group&&this.canvas&&t===this.canvas.contextTop,n=this.calcTransformMatrix(!e);t.transform(n[0],n[1],n[2],n[3],n[4],n[5])},toObject:function(t){var n=e.Object.NUM_FRACTION_DIGITS,i={type:this.type,version:e.version,originX:this.originX,originY:this.originY,left:s(this.left,n),top:s(this.top,n),width:s(this.width,n),height:s(this.height,n),fill:this.fill&&this.fill.toObject?this.fill.toObject():this.fill,stroke:this.stroke&&this.stroke.toObject?this.stroke.toObject():this.stroke,strokeWidth:s(this.strokeWidth,n),strokeDashArray:this.strokeDashArray?this.strokeDashArray.concat():this.strokeDashArray,strokeLineCap:this.strokeLineCap,strokeDashOffset:this.strokeDashOffset,strokeLineJoin:this.strokeLineJoin,strokeUniform:this.strokeUniform,strokeMiterLimit:s(this.strokeMiterLimit,n),scaleX:s(this.scaleX,n),scaleY:s(this.scaleY,n),angle:s(this.angle,n),flipX:this.flipX,flipY:this.flipY,opacity:s(this.opacity,n),shadow:this.shadow&&this.shadow.toObject?this.shadow.toObject():this.shadow,visible:this.visible,backgroundColor:this.backgroundColor,fillRule:this.fillRule,paintFirst:this.paintFirst,globalCompositeOperation:this.globalCompositeOperation,skewX:s(this.skewX,n),skewY:s(this.skewY,n)};return this.clipPath&&(i.clipPath=this.clipPath.toObject(t),i.clipPath.inverted=this.clipPath.inverted,i.clipPath.absolutePositioned=this.clipPath.absolutePositioned),e.util.populateWithProperties(this,i,t),this.includeDefaultValues||(i=this._removeDefaultValues(i)),i},toDatalessObject:function(t){return this.toObject(t)},_removeDefaultValues:function(t){var n=e.util.getKlass(t.type).prototype;return n.stateProperties.forEach((function(e){"left"!==e&&"top"!==e&&(t[e]===n[e]&&delete t[e],"[object Array]"===Object.prototype.toString.call(t[e])&&"[object Array]"===Object.prototype.toString.call(n[e])&&0===t[e].length&&0===n[e].length&&delete t[e])})),t},toString:function(){return"#<fabric."+r(this.type)+">"},getObjectScaling:function(){var t=e.util.qrDecompose(this.calcTransformMatrix());return{scaleX:Math.abs(t.scaleX),scaleY:Math.abs(t.scaleY)}},getTotalObjectScaling:function(){var t=this.getObjectScaling(),e=t.scaleX,n=t.scaleY;if(this.canvas){var i=this.canvas.getZoom(),s=this.canvas.getRetinaScaling();e*=i*s,n*=i*s}return{scaleX:e,scaleY:n}},getObjectOpacity:function(){var t=this.opacity;return this.group&&(t*=this.group.getObjectOpacity()),t},_set:function(t,n){var i="scaleX"===t||"scaleY"===t,s=this[t]!==n,r=!1;return i&&(n=this._constrainScale(n)),"scaleX"===t&&n<0?(this.flipX=!this.flipX,n*=-1):"scaleY"===t&&n<0?(this.flipY=!this.flipY,n*=-1):"shadow"!==t||!n||n instanceof e.Shadow?"dirty"===t&&this.group&&this.group.set("dirty",n):n=new e.Shadow(n),this[t]=n,s&&(r=this.group&&this.group.isOnACache(),this.cacheProperties.indexOf(t)>-1?(this.dirty=!0,r&&this.group.set("dirty",!0)):r&&this.stateProperties.indexOf(t)>-1&&this.group.set("dirty",!0)),this},setOnGroup:function(){},getViewportTransform:function(){return this.canvas&&this.canvas.viewportTransform?this.canvas.viewportTransform:e.iMatrix.concat()},isNotVisible:function(){return 0===this.opacity||!this.width&&!this.height&&0===this.strokeWidth||!this.visible},render:function(t){this.isNotVisible()||this.canvas&&this.canvas.skipOffscreen&&!this.group&&!this.isOnScreen()||(t.save(),this._setupCompositeOperation(t),this.drawSelectionBackground(t),this.transform(t),this._setOpacity(t),this._setShadow(t,this),this.shouldCache()?(this.renderCache(),this.drawCacheOnCanvas(t)):(this._removeCacheCanvas(),this.dirty=!1,this.drawObject(t),this.objectCaching&&this.statefullCache&&this.saveState({propertySet:"cacheProperties"})),t.restore())},renderCache:function(t){t=t||{},this._cacheCanvas||this._createCacheCanvas(),this.isCacheDirty()&&(this.statefullCache&&this.saveState({propertySet:"cacheProperties"}),this.drawObject(this._cacheContext,t.forClipping),this.dirty=!1)},_removeCacheCanvas:function(){this._cacheCanvas=null,this.cacheWidth=0,this.cacheHeight=0},hasStroke:function(){return this.stroke&&"transparent"!==this.stroke&&0!==this.strokeWidth},hasFill:function(){return this.fill&&"transparent"!==this.fill},needsItsOwnCache:function(){return!("stroke"!==this.paintFirst||!this.hasFill()||!this.hasStroke()||"object"!=typeof this.shadow)||!!this.clipPath},shouldCache:function(){return this.ownCaching=this.needsItsOwnCache()||this.objectCaching&&(!this.group||!this.group.isOnACache()),this.ownCaching},willDrawShadow:function(){return!!this.shadow&&(0!==this.shadow.offsetX||0!==this.shadow.offsetY)},drawClipPathOnCache:function(t){var n=this.clipPath;if(t.save(),n.inverted?t.globalCompositeOperation="destination-out":t.globalCompositeOperation="destination-in",n.absolutePositioned){var i=e.util.invertTransform(this.calcTransformMatrix());t.transform(i[0],i[1],i[2],i[3],i[4],i[5])}n.transform(t),t.scale(1/n.zoomX,1/n.zoomY),t.drawImage(n._cacheCanvas,-n.cacheTranslationX,-n.cacheTranslationY),t.restore()},drawObject:function(t,e){var n=this.fill,i=this.stroke;e?(this.fill="black",this.stroke="",this._setClippingProperties(t)):this._renderBackground(t),this._render(t),this._drawClipPath(t),this.fill=n,this.stroke=i},_drawClipPath:function(t){var e=this.clipPath;e&&(e.canvas=this.canvas,e.shouldCache(),e._transformDone=!0,e.renderCache({forClipping:!0}),this.drawClipPathOnCache(t))},drawCacheOnCanvas:function(t){t.scale(1/this.zoomX,1/this.zoomY),t.drawImage(this._cacheCanvas,-this.cacheTranslationX,-this.cacheTranslationY)},isCacheDirty:function(t){if(this.isNotVisible())return!1;if(this._cacheCanvas&&!t&&this._updateCacheCanvas())return!0;if(this.dirty||this.clipPath&&this.clipPath.absolutePositioned||this.statefullCache&&this.hasStateChanged("cacheProperties")){if(this._cacheCanvas&&!t){var e=this.cacheWidth/this.zoomX,n=this.cacheHeight/this.zoomY;this._cacheContext.clearRect(-e/2,-n/2,e,n)}return!0}return!1},_renderBackground:function(t){if(this.backgroundColor){var e=this._getNonTransformedDimensions();t.fillStyle=this.backgroundColor,t.fillRect(-e.x/2,-e.y/2,e.x,e.y),this._removeShadow(t)}},_setOpacity:function(t){this.group&&!this.group._transformDone?t.globalAlpha=this.getObjectOpacity():t.globalAlpha*=this.opacity},_setStrokeStyles:function(t,e){var n=e.stroke;n&&(t.lineWidth=e.strokeWidth,t.lineCap=e.strokeLineCap,t.lineDashOffset=e.strokeDashOffset,t.lineJoin=e.strokeLineJoin,t.miterLimit=e.strokeMiterLimit,n.toLive?"percentage"===n.gradientUnits||n.gradientTrasnform||n.patternTransform?this._applyPatternForTransformedGradient(t,n):(t.strokeStyle=n.toLive(t,this),this._applyPatternGradientTransform(t,n)):t.strokeStyle=e.stroke)},_setFillStyles:function(t,e){var n=e.fill;n&&(n.toLive?(t.fillStyle=n.toLive(t,this),this._applyPatternGradientTransform(t,e.fill)):t.fillStyle=n)},_setClippingProperties:function(t){t.globalAlpha=1,t.strokeStyle="transparent",t.fillStyle="#000000"},_setLineDash:function(t,e,n){e&&0!==e.length&&(1&e.length&&e.push.apply(e,e),a?t.setLineDash(e):n&&n(t))},_renderControls:function(t,n){var i,s,r,a=this.getViewportTransform(),c=this.calcTransformMatrix();s=void 0!==(n=n||{}).hasBorders?n.hasBorders:this.hasBorders,r=void 0!==n.hasControls?n.hasControls:this.hasControls,c=e.util.multiplyTransformMatrices(a,c),i=e.util.qrDecompose(c),t.save(),t.translate(i.translateX,i.translateY),t.lineWidth=1*this.borderScaleFactor,this.group||(t.globalAlpha=this.isMoving?this.borderOpacityWhenMoving:1),n.forActiveSelection?(t.rotate(o(i.angle)),s&&this.drawBordersInGroup(t,i,n)):(t.rotate(o(this.angle)),s&&this.drawBorders(t,n)),r&&this.drawControls(t,n),t.restore()},_setShadow:function(t){if(this.shadow){var n,i=this.shadow,s=this.canvas,r=s&&s.viewportTransform[0]||1,o=s&&s.viewportTransform[3]||1;n=i.nonScaling?{scaleX:1,scaleY:1}:this.getObjectScaling(),s&&s._isRetinaScaling()&&(r*=e.devicePixelRatio,o*=e.devicePixelRatio),t.shadowColor=i.color,t.shadowBlur=i.blur*e.browserShadowBlurConstant*(r+o)*(n.scaleX+n.scaleY)/4,t.shadowOffsetX=i.offsetX*r*n.scaleX,t.shadowOffsetY=i.offsetY*o*n.scaleY}},_removeShadow:function(t){this.shadow&&(t.shadowColor="",t.shadowBlur=t.shadowOffsetX=t.shadowOffsetY=0)},_applyPatternGradientTransform:function(t,e){if(!e||!e.toLive)return{offsetX:0,offsetY:0};var n=e.gradientTransform||e.patternTransform,i=-this.width/2+e.offsetX||0,s=-this.height/2+e.offsetY||0;return"percentage"===e.gradientUnits?t.transform(this.width,0,0,this.height,i,s):t.transform(1,0,0,1,i,s),n&&t.transform(n[0],n[1],n[2],n[3],n[4],n[5]),{offsetX:i,offsetY:s}},_renderPaintInOrder:function(t){"stroke"===this.paintFirst?(this._renderStroke(t),this._renderFill(t)):(this._renderFill(t),this._renderStroke(t))},_render:function(){},_renderFill:function(t){this.fill&&(t.save(),this._setFillStyles(t,this),"evenodd"===this.fillRule?t.fill("evenodd"):t.fill(),t.restore())},_renderStroke:function(t){if(this.stroke&&0!==this.strokeWidth){if(this.shadow&&!this.shadow.affectStroke&&this._removeShadow(t),t.save(),this.strokeUniform&&this.group){var e=this.getObjectScaling();t.scale(1/e.scaleX,1/e.scaleY)}else this.strokeUniform&&t.scale(1/this.scaleX,1/this.scaleY);this._setLineDash(t,this.strokeDashArray,this._renderDashedStroke),this._setStrokeStyles(t,this),t.stroke(),t.restore()}},_applyPatternForTransformedGradient:function(t,n){var i,s=this._limitCacheSize(this._getCacheCanvasDimensions()),r=e.util.createCanvasElement(),o=this.canvas.getRetinaScaling(),a=s.x/this.scaleX/o,c=s.y/this.scaleY/o;r.width=a,r.height=c,(i=r.getContext("2d")).beginPath(),i.moveTo(0,0),i.lineTo(a,0),i.lineTo(a,c),i.lineTo(0,c),i.closePath(),i.translate(a/2,c/2),i.scale(s.zoomX/this.scaleX/o,s.zoomY/this.scaleY/o),this._applyPatternGradientTransform(i,n),i.fillStyle=n.toLive(t),i.fill(),t.translate(-this.width/2-this.strokeWidth/2,-this.height/2-this.strokeWidth/2),t.scale(o*this.scaleX/s.zoomX,o*this.scaleY/s.zoomY),t.strokeStyle=i.createPattern(r,"no-repeat")},_findCenterFromElement:function(){return{x:this.left+this.width/2,y:this.top+this.height/2}},_assignTransformMatrixProps:function(){if(this.transformMatrix){var t=e.util.qrDecompose(this.transformMatrix);this.flipX=!1,this.flipY=!1,this.set("scaleX",t.scaleX),this.set("scaleY",t.scaleY),this.angle=t.angle,this.skewX=t.skewX,this.skewY=0}},_removeTransformMatrix:function(t){var n=this._findCenterFromElement();this.transformMatrix&&(this._assignTransformMatrixProps(),n=e.util.transformPoint(n,this.transformMatrix)),this.transformMatrix=null,t&&(this.scaleX*=t.scaleX,this.scaleY*=t.scaleY,this.cropX=t.cropX,this.cropY=t.cropY,n.x+=t.offsetLeft,n.y+=t.offsetTop,this.width=t.width,this.height=t.height),this.setPositionByOrigin(n,"center","center")},clone:function(t,n){var i=this.toObject(n);this.constructor.fromObject?this.constructor.fromObject(i,t):e.Object._fromObject("Object",i,t)},cloneAsImage:function(t,n){var i=this.toCanvasElement(n);return t&&t(new e.Image(i)),this},toCanvasElement:function(t){t||(t={});var n=e.util,i=n.saveObjectTransform(this),s=this.group,r=this.shadow,o=Math.abs,a=(t.multiplier||1)*(t.enableRetinaScaling?e.devicePixelRatio:1);delete this.group,t.withoutTransform&&n.resetObjectTransform(this),t.withoutShadow&&(this.shadow=null);var c,l,h,u,d=e.util.createCanvasElement(),f=this.getBoundingRect(!0,!0),p=this.shadow,m={x:0,y:0};p&&(l=p.blur,c=p.nonScaling?{scaleX:1,scaleY:1}:this.getObjectScaling(),m.x=2*Math.round(o(p.offsetX)+l)*o(c.scaleX),m.y=2*Math.round(o(p.offsetY)+l)*o(c.scaleY)),h=f.width+m.x,u=f.height+m.y,d.width=Math.ceil(h),d.height=Math.ceil(u);var g=new e.StaticCanvas(d,{enableRetinaScaling:!1,renderOnAddRemove:!1,skipOffscreen:!1});"jpeg"===t.format&&(g.backgroundColor="#fff"),this.setPositionByOrigin(new e.Point(g.width/2,g.height/2),"center","center");var v=this.canvas;g.add(this);var _=g.toCanvasElement(a||1,t);return this.shadow=r,this.set("canvas",v),s&&(this.group=s),this.set(i).setCoords(),g._objects=[],g.dispose(),g=null,_},toDataURL:function(t){return t||(t={}),e.util.toDataURL(this.toCanvasElement(t),t.format||"png",t.quality||1)},isType:function(t){return this.type===t},complexity:function(){return 1},toJSON:function(t){return this.toObject(t)},rotate:function(t){var e=("center"!==this.originX||"center"!==this.originY)&&this.centeredRotation;return e&&this._setOriginToCenter(),this.set("angle",t),e&&this._resetOrigin(),this},centerH:function(){return this.canvas&&this.canvas.centerObjectH(this),this},viewportCenterH:function(){return this.canvas&&this.canvas.viewportCenterObjectH(this),this},centerV:function(){return this.canvas&&this.canvas.centerObjectV(this),this},viewportCenterV:function(){return this.canvas&&this.canvas.viewportCenterObjectV(this),this},center:function(){return this.canvas&&this.canvas.centerObject(this),this},viewportCenter:function(){return this.canvas&&this.canvas.viewportCenterObject(this),this},getLocalPointer:function(t,n){n=n||this.canvas.getPointer(t);var i=new e.Point(n.x,n.y),s=this._getLeftTopCoords();return this.angle&&(i=e.util.rotatePoint(i,s,o(-this.angle))),{x:i.x-s.x,y:i.y-s.y}},_setupCompositeOperation:function(t){this.globalCompositeOperation&&(t.globalCompositeOperation=this.globalCompositeOperation)}}),e.util.createAccessors&&e.util.createAccessors(e.Object),n(e.Object.prototype,e.Observable),e.Object.NUM_FRACTION_DIGITS=2,e.Object._fromObject=function(t,n,s,r){var o=e[t];n=i(n,!0),e.util.enlivenPatterns([n.fill,n.stroke],(function(t){void 0!==t[0]&&(n.fill=t[0]),void 0!==t[1]&&(n.stroke=t[1]),e.util.enlivenObjects([n.clipPath],(function(t){n.clipPath=t[0];var e=r?new o(n[r],n):new o(n);s&&s(e)}))}))},e.Object.__uid=0)}(e),f=v.util.degreesToRadians,p={left:-.5,center:0,right:.5},m={top:-.5,center:0,bottom:.5},v.util.object.extend(v.Object.prototype,{translateToGivenOrigin:function(t,e,n,i,s){var r,o,a,c=t.x,l=t.y;return"string"==typeof e?e=p[e]:e-=.5,"string"==typeof i?i=p[i]:i-=.5,"string"==typeof n?n=m[n]:n-=.5,"string"==typeof s?s=m[s]:s-=.5,o=s-n,((r=i-e)||o)&&(a=this._getTransformedDimensions(),c=t.x+r*a.x,l=t.y+o*a.y),new v.Point(c,l)},translateToCenterPoint:function(t,e,n){var i=this.translateToGivenOrigin(t,e,n,"center","center");return this.angle?v.util.rotatePoint(i,t,f(this.angle)):i},translateToOriginPoint:function(t,e,n){var i=this.translateToGivenOrigin(t,"center","center",e,n);return this.angle?v.util.rotatePoint(i,t,f(this.angle)):i},getCenterPoint:function(){var t=new v.Point(this.left,this.top);return this.translateToCenterPoint(t,this.originX,this.originY)},getPointByOrigin:function(t,e){var n=this.getCenterPoint();return this.translateToOriginPoint(n,t,e)},toLocalPoint:function(t,e,n){var i,s,r=this.getCenterPoint();return i=void 0!==e&&void 0!==n?this.translateToGivenOrigin(r,"center","center",e,n):new v.Point(this.left,this.top),s=new v.Point(t.x,t.y),this.angle&&(s=v.util.rotatePoint(s,r,-f(this.angle))),s.subtractEquals(i)},setPositionByOrigin:function(t,e,n){var i=this.translateToCenterPoint(t,e,n),s=this.translateToOriginPoint(i,this.originX,this.originY);this.set("left",s.x),this.set("top",s.y)},adjustPosition:function(t){var e,n,i=f(this.angle),s=this.getScaledWidth(),r=v.util.cos(i)*s,o=v.util.sin(i)*s;e="string"==typeof this.originX?p[this.originX]:this.originX-.5,n="string"==typeof t?p[t]:t-.5,this.left+=r*(n-e),this.top+=o*(n-e),this.setCoords(),this.originX=t},_setOriginToCenter:function(){this._originalOriginX=this.originX,this._originalOriginY=this.originY;var t=this.getCenterPoint();this.originX="center",this.originY="center",this.left=t.x,this.top=t.y},_resetOrigin:function(){var t=this.translateToOriginPoint(this.getCenterPoint(),this._originalOriginX,this._originalOriginY);this.originX=this._originalOriginX,this.originY=this._originalOriginY,this.left=t.x,this.top=t.y,this._originalOriginX=null,this._originalOriginY=null},_getLeftTopCoords:function(){return this.translateToOriginPoint(this.getCenterPoint(),"left","top")}}),function(){var t=v.util,e=t.degreesToRadians,n=t.multiplyTransformMatrices,i=t.transformPoint;t.object.extend(v.Object.prototype,{oCoords:null,aCoords:null,lineCoords:null,ownMatrixCache:null,matrixCache:null,controls:{},_getCoords:function(t,e){return e?t?this.calcACoords():this.calcLineCoords():(this.aCoords&&this.lineCoords||this.setCoords(!0),t?this.aCoords:this.lineCoords)},getCoords:function(t,e){return n=this._getCoords(t,e),[new v.Point(n.tl.x,n.tl.y),new v.Point(n.tr.x,n.tr.y),new v.Point(n.br.x,n.br.y),new v.Point(n.bl.x,n.bl.y)];var n},intersectsWithRect:function(t,e,n,i){var s=this.getCoords(n,i);return"Intersection"===v.Intersection.intersectPolygonRectangle(s,t,e).status},intersectsWithObject:function(t,e,n){return"Intersection"===v.Intersection.intersectPolygonPolygon(this.getCoords(e,n),t.getCoords(e,n)).status||t.isContainedWithinObject(this,e,n)||this.isContainedWithinObject(t,e,n)},isContainedWithinObject:function(t,e,n){for(var i=this.getCoords(e,n),s=e?t.aCoords:t.lineCoords,r=0,o=t._getImageLines(s);r<4;r++)if(!t.containsPoint(i[r],o))return!1;return!0},isContainedWithinRect:function(t,e,n,i){var s=this.getBoundingRect(n,i);return s.left>=t.x&&s.left+s.width<=e.x&&s.top>=t.y&&s.top+s.height<=e.y},containsPoint:function(t,e,n,i){var s=this._getCoords(n,i),r=(e=e||this._getImageLines(s),this._findCrossPoints(t,e));return 0!==r&&r%2==1},isOnScreen:function(t){if(!this.canvas)return!1;var e=this.canvas.vptCoords.tl,n=this.canvas.vptCoords.br;return!!this.getCoords(!0,t).some((function(t){return t.x<=n.x&&t.x>=e.x&&t.y<=n.y&&t.y>=e.y}))||(!!this.intersectsWithRect(e,n,!0,t)||this._containsCenterOfCanvas(e,n,t))},_containsCenterOfCanvas:function(t,e,n){var i={x:(t.x+e.x)/2,y:(t.y+e.y)/2};return!!this.containsPoint(i,null,!0,n)},isPartiallyOnScreen:function(t){if(!this.canvas)return!1;var e=this.canvas.vptCoords.tl,n=this.canvas.vptCoords.br;return!!this.intersectsWithRect(e,n,!0,t)||this.getCoords(!0,t).every((function(t){return(t.x>=n.x||t.x<=e.x)&&(t.y>=n.y||t.y<=e.y)}))&&this._containsCenterOfCanvas(e,n,t)},_getImageLines:function(t){return{topline:{o:t.tl,d:t.tr},rightline:{o:t.tr,d:t.br},bottomline:{o:t.br,d:t.bl},leftline:{o:t.bl,d:t.tl}}},_findCrossPoints:function(t,e){var n,i,s,r=0;for(var o in e)if(!((s=e[o]).o.y<t.y&&s.d.y<t.y||s.o.y>=t.y&&s.d.y>=t.y||(s.o.x===s.d.x&&s.o.x>=t.x?i=s.o.x:(0,n=(s.d.y-s.o.y)/(s.d.x-s.o.x),i=-(t.y-0*t.x-(s.o.y-n*s.o.x))/(0-n)),i>=t.x&&(r+=1),2!==r)))break;return r},getBoundingRect:function(e,n){var i=this.getCoords(e,n);return t.makeBoundingBoxFromPoints(i)},getScaledWidth:function(){return this._getTransformedDimensions().x},getScaledHeight:function(){return this._getTransformedDimensions().y},_constrainScale:function(t){return Math.abs(t)<this.minScaleLimit?t<0?-this.minScaleLimit:this.minScaleLimit:0===t?1e-4:t},scale:function(t){return this._set("scaleX",t),this._set("scaleY",t),this.setCoords()},scaleToWidth:function(t,e){var n=this.getBoundingRect(e).width/this.getScaledWidth();return this.scale(t/this.width/n)},scaleToHeight:function(t,e){var n=this.getBoundingRect(e).height/this.getScaledHeight();return this.scale(t/this.height/n)},calcCoords:function(t){return t?this.calcACoords():this.calcOCoords()},calcLineCoords:function(){var n=this.getViewportTransform(),s=this.padding,r=e(this.angle),o=t.cos(r)*s,a=t.sin(r)*s,c=o+a,l=o-a,h=this.calcACoords(),u={tl:i(h.tl,n),tr:i(h.tr,n),bl:i(h.bl,n),br:i(h.br,n)};return s&&(u.tl.x-=l,u.tl.y-=c,u.tr.x+=c,u.tr.y-=l,u.bl.x-=c,u.bl.y+=l,u.br.x+=l,u.br.y+=c),u},calcOCoords:function(){var t=this._calcRotateMatrix(),e=this._calcTranslateMatrix(),i=this.getViewportTransform(),s=n(i,e),r=n(s,t),o=(r=n(r,[1/i[0],0,0,1/i[3],0,0]),this._calculateCurrentDimensions()),a={};return this.forEachControl((function(t,e,n){a[e]=t.positionHandler(o,r,n)})),a},calcACoords:function(){var t=this._calcRotateMatrix(),e=this._calcTranslateMatrix(),s=n(e,t),r=this._getTransformedDimensions(),o=r.x/2,a=r.y/2;return{tl:i({x:-o,y:-a},s),tr:i({x:o,y:-a},s),bl:i({x:-o,y:a},s),br:i({x:o,y:a},s)}},setCoords:function(t){return this.aCoords=this.calcACoords(),this.lineCoords=this.group?this.aCoords:this.calcLineCoords(),t||(this.oCoords=this.calcOCoords(),this._setCornerCoords&&this._setCornerCoords()),this},_calcRotateMatrix:function(){return t.calcRotateMatrix(this)},_calcTranslateMatrix:function(){var t=this.getCenterPoint();return[1,0,0,1,t.x,t.y]},transformMatrixKey:function(t){var e="_",n="";return!t&&this.group&&(n=this.group.transformMatrixKey(t)+e),n+this.top+e+this.left+e+this.scaleX+e+this.scaleY+e+this.skewX+e+this.skewY+e+this.angle+e+this.originX+e+this.originY+e+this.width+e+this.height+e+this.strokeWidth+this.flipX+this.flipY},calcTransformMatrix:function(t){var e=this.calcOwnMatrix();if(t||!this.group)return e;var i=this.transformMatrixKey(t),s=this.matrixCache||(this.matrixCache={});return s.key===i?s.value:(this.group&&(e=n(this.group.calcTransformMatrix(!1),e)),s.key=i,s.value=e,e)},calcOwnMatrix:function(){var e=this.transformMatrixKey(!0),n=this.ownMatrixCache||(this.ownMatrixCache={});if(n.key===e)return n.value;var i=this._calcTranslateMatrix(),s={angle:this.angle,translateX:i[4],translateY:i[5],scaleX:this.scaleX,scaleY:this.scaleY,skewX:this.skewX,skewY:this.skewY,flipX:this.flipX,flipY:this.flipY};return n.key=e,n.value=t.composeMatrix(s),n.value},_calcDimensionsTransformMatrix:function(e,n,i){return t.calcDimensionsMatrix({skewX:e,skewY:n,scaleX:this.scaleX*(i&&this.flipX?-1:1),scaleY:this.scaleY*(i&&this.flipY?-1:1)})},_getNonTransformedDimensions:function(){var t=this.strokeWidth;return{x:this.width+t,y:this.height+t}},_getTransformedDimensions:function(e,n){void 0===e&&(e=this.skewX),void 0===n&&(n=this.skewY);var i,s,r=this._getNonTransformedDimensions(),o=0===e&&0===n;if(this.strokeUniform?(i=this.width,s=this.height):(i=r.x,s=r.y),o)return this._finalizeDimensions(i*this.scaleX,s*this.scaleY);var a=t.sizeAfterTransform(i,s,{scaleX:this.scaleX,scaleY:this.scaleY,skewX:e,skewY:n});return this._finalizeDimensions(a.x,a.y)},_finalizeDimensions:function(t,e){return this.strokeUniform?{x:t+this.strokeWidth,y:e+this.strokeWidth}:{x:t,y:e}},_calculateCurrentDimensions:function(){var t=this.getViewportTransform(),e=this._getTransformedDimensions();return i(e,t,!0).scalarAdd(2*this.padding)}})}(),v.util.object.extend(v.Object.prototype,{sendToBack:function(){return this.group?v.StaticCanvas.prototype.sendToBack.call(this.group,this):this.canvas&&this.canvas.sendToBack(this),this},bringToFront:function(){return this.group?v.StaticCanvas.prototype.bringToFront.call(this.group,this):this.canvas&&this.canvas.bringToFront(this),this},sendBackwards:function(t){return this.group?v.StaticCanvas.prototype.sendBackwards.call(this.group,this,t):this.canvas&&this.canvas.sendBackwards(this,t),this},bringForward:function(t){return this.group?v.StaticCanvas.prototype.bringForward.call(this.group,this,t):this.canvas&&this.canvas.bringForward(this,t),this},moveTo:function(t){return this.group&&"activeSelection"!==this.group.type?v.StaticCanvas.prototype.moveTo.call(this.group,this,t):this.canvas&&this.canvas.moveTo(this,t),this}}),function(){function t(t,e){if(e){if(e.toLive)return t+": url(#SVGID_"+e.id+"); ";var n=new v.Color(e),i=t+": "+n.toRgb()+"; ",s=n.getAlpha();return 1!==s&&(i+=t+"-opacity: "+s.toString()+"; "),i}return t+": none; "}var e=v.util.toFixed;v.util.object.extend(v.Object.prototype,{getSvgStyles:function(e){var n=this.fillRule?this.fillRule:"nonzero",i=this.strokeWidth?this.strokeWidth:"0",s=this.strokeDashArray?this.strokeDashArray.join(" "):"none",r=this.strokeDashOffset?this.strokeDashOffset:"0",o=this.strokeLineCap?this.strokeLineCap:"butt",a=this.strokeLineJoin?this.strokeLineJoin:"miter",c=this.strokeMiterLimit?this.strokeMiterLimit:"4",l=void 0!==this.opacity?this.opacity:"1",h=this.visible?"":" visibility: hidden;",u=e?"":this.getSvgFilter(),d=t("fill",this.fill);return[t("stroke",this.stroke),"stroke-width: ",i,"; ","stroke-dasharray: ",s,"; ","stroke-linecap: ",o,"; ","stroke-dashoffset: ",r,"; ","stroke-linejoin: ",a,"; ","stroke-miterlimit: ",c,"; ",d,"fill-rule: ",n,"; ","opacity: ",l,";",u,h].join("")},getSvgSpanStyles:function(e,n){var i="; ",s=e.fontFamily?"font-family: "+(-1===e.fontFamily.indexOf("'")&&-1===e.fontFamily.indexOf('"')?"'"+e.fontFamily+"'":e.fontFamily)+i:"",r=e.strokeWidth?"stroke-width: "+e.strokeWidth+i:"",o=(s=s,e.fontSize?"font-size: "+e.fontSize+"px"+i:""),a=e.fontStyle?"font-style: "+e.fontStyle+i:"",c=e.fontWeight?"font-weight: "+e.fontWeight+i:"",l=e.fill?t("fill",e.fill):"",h=e.stroke?t("stroke",e.stroke):"",u=this.getSvgTextDecoration(e);return u&&(u="text-decoration: "+u+i),[h,r,s,o,a,c,u,l,e.deltaY?"baseline-shift: "+-e.deltaY+"; ":"",n?"white-space: pre; ":""].join("")},getSvgTextDecoration:function(t){return["overline","underline","line-through"].filter((function(e){return t[e.replace("-","")]})).join(" ")},getSvgFilter:function(){return this.shadow?"filter: url(#SVGID_"+this.shadow.id+");":""},getSvgCommons:function(){return[this.id?'id="'+this.id+'" ':"",this.clipPath?'clip-path="url(#'+this.clipPath.clipPathId+')" ':""].join("")},getSvgTransform:function(t,e){var n=t?this.calcTransformMatrix():this.calcOwnMatrix();return'transform="'+v.util.matrixToSVG(n)+(e||"")+'" '},_setSVGBg:function(t){if(this.backgroundColor){var n=v.Object.NUM_FRACTION_DIGITS;t.push("\t\t<rect ",this._getFillAttributes(this.backgroundColor),' x="',e(-this.width/2,n),'" y="',e(-this.height/2,n),'" width="',e(this.width,n),'" height="',e(this.height,n),'"></rect>\n')}},toSVG:function(t){return this._createBaseSVGMarkup(this._toSVG(t),{reviver:t})},toClipPathSVG:function(t){return"\t"+this._createBaseClipPathSVGMarkup(this._toSVG(t),{reviver:t})},_createBaseClipPathSVGMarkup:function(t,e){var n=(e=e||{}).reviver,i=e.additionalTransform||"",s=[this.getSvgTransform(!0,i),this.getSvgCommons()].join(""),r=t.indexOf("COMMON_PARTS");return t[r]=s,n?n(t.join("")):t.join("")},_createBaseSVGMarkup:function(t,e){var n,i,s=(e=e||{}).noStyle,r=e.reviver,o=s?"":'style="'+this.getSvgStyles()+'" ',a=e.withShadow?'style="'+this.getSvgFilter()+'" ':"",c=this.clipPath,l=this.strokeUniform?'vector-effect="non-scaling-stroke" ':"",h=c&&c.absolutePositioned,u=this.stroke,d=this.fill,f=this.shadow,p=[],m=t.indexOf("COMMON_PARTS"),g=e.additionalTransform;return c&&(c.clipPathId="CLIPPATH_"+v.Object.__uid++,i='<clipPath id="'+c.clipPathId+'" >\n'+c.toClipPathSVG(r)+"</clipPath>\n"),h&&p.push("<g ",a,this.getSvgCommons()," >\n"),p.push("<g ",this.getSvgTransform(!1),h?"":a+this.getSvgCommons()," >\n"),n=[o,l,s?"":this.addPaintOrder()," ",g?'transform="'+g+'" ':""].join(""),t[m]=n,d&&d.toLive&&p.push(d.toSVG(this)),u&&u.toLive&&p.push(u.toSVG(this)),f&&p.push(f.toSVG(this)),c&&p.push(i),p.push(t.join("")),p.push("</g>\n"),h&&p.push("</g>\n"),r?r(p.join("")):p.join("")},addPaintOrder:function(){return"fill"!==this.paintFirst?' paint-order="'+this.paintFirst+'" ':""}})}(),function(){var t=v.util.object.extend,e="stateProperties";function n(e,n,i){var s={};i.forEach((function(t){s[t]=e[t]})),t(e[n],s,!0)}function i(t,e,n){if(t===e)return!0;if(Array.isArray(t)){if(!Array.isArray(e)||t.length!==e.length)return!1;for(var s=0,r=t.length;s<r;s++)if(!i(t[s],e[s]))return!1;return!0}if(t&&"object"==typeof t){var o,a=Object.keys(t);if(!e||"object"!=typeof e||!n&&a.length!==Object.keys(e).length)return!1;for(s=0,r=a.length;s<r;s++)if("canvas"!==(o=a[s])&&"group"!==o&&!i(t[o],e[o]))return!1;return!0}}v.util.object.extend(v.Object.prototype,{hasStateChanged:function(t){var n="_"+(t=t||e);return Object.keys(this[n]).length<this[t].length||!i(this[n],this,!0)},saveState:function(t){var i=t&&t.propertySet||e,s="_"+i;return this[s]?(n(this,s,this[i]),t&&t.stateProperties&&n(this,s,t.stateProperties),this):this.setupState(t)},setupState:function(t){var n=(t=t||{}).propertySet||e;return t.propertySet=n,this["_"+n]={},this.saveState(t),this}})}(),function(){var t=v.util.degreesToRadians;v.util.object.extend(v.Object.prototype,{_findTargetCorner:function(t,e){if(!this.hasControls||this.group||!this.canvas||this.canvas._activeObject!==this)return!1;var n,i,s,r=t.x,o=t.y,a=Object.keys(this.oCoords),c=a.length-1;for(this.__corner=0;c>=0;c--)if(s=a[c],this.isControlVisible(s)&&(i=this._getImageLines(e?this.oCoords[s].touchCorner:this.oCoords[s].corner),0!==(n=this._findCrossPoints({x:r,y:o},i))&&n%2==1))return this.__corner=s,s;return!1},forEachControl:function(t){for(var e in this.controls)t(this.controls[e],e,this)},_setCornerCoords:function(){var t=this.oCoords;for(var e in t){var n=this.controls[e];t[e].corner=n.calcCornerCoords(this.angle,this.cornerSize,t[e].x,t[e].y,!1),t[e].touchCorner=n.calcCornerCoords(this.angle,this.touchCornerSize,t[e].x,t[e].y,!0)}},drawSelectionBackground:function(e){if(!this.selectionBackgroundColor||this.canvas&&!this.canvas.interactive||this.canvas&&this.canvas._activeObject!==this)return this;e.save();var n=this.getCenterPoint(),i=this._calculateCurrentDimensions(),s=this.canvas.viewportTransform;return e.translate(n.x,n.y),e.scale(1/s[0],1/s[3]),e.rotate(t(this.angle)),e.fillStyle=this.selectionBackgroundColor,e.fillRect(-i.x/2,-i.y/2,i.x,i.y),e.restore(),this},drawBorders:function(t,e){e=e||{};var n=this._calculateCurrentDimensions(),i=this.borderScaleFactor,s=n.x+i,r=n.y+i,o=void 0!==e.hasControls?e.hasControls:this.hasControls,a=!1;return t.save(),t.strokeStyle=e.borderColor||this.borderColor,this._setLineDash(t,e.borderDashArray||this.borderDashArray,null),t.strokeRect(-s/2,-r/2,s,r),o&&(t.beginPath(),this.forEachControl((function(e,n,i){e.withConnection&&e.getVisibility(i,n)&&(a=!0,t.moveTo(e.x*s,e.y*r),t.lineTo(e.x*s+e.offsetX,e.y*r+e.offsetY))})),a&&t.stroke()),t.restore(),this},drawBordersInGroup:function(t,e,n){n=n||{};var i=v.util.sizeAfterTransform(this.width,this.height,e),s=this.strokeWidth,r=this.strokeUniform,o=this.borderScaleFactor,a=i.x+s*(r?this.canvas.getZoom():e.scaleX)+o,c=i.y+s*(r?this.canvas.getZoom():e.scaleY)+o;return t.save(),this._setLineDash(t,n.borderDashArray||this.borderDashArray,null),t.strokeStyle=n.borderColor||this.borderColor,t.strokeRect(-a/2,-c/2,a,c),t.restore(),this},drawControls:function(t,e){return e=e||{},t.save(),t.setTransform(this.canvas.getRetinaScaling(),0,0,this.canvas.getRetinaScaling(),0,0),t.strokeStyle=t.fillStyle=e.cornerColor||this.cornerColor,this.transparentCorners||(t.strokeStyle=e.cornerStrokeColor||this.cornerStrokeColor),this._setLineDash(t,e.cornerDashArray||this.cornerDashArray,null),this.setCoords(),this.forEachControl((function(n,i,s){n.getVisibility(s,i)&&n.render(t,s.oCoords[i].x,s.oCoords[i].y,e,s)})),t.restore(),this},isControlVisible:function(t){return this.controls[t]&&this.controls[t].getVisibility(this,t)},setControlVisible:function(t,e){return this._controlsVisibility||(this._controlsVisibility={}),this._controlsVisibility[t]=e,this},setControlsVisibility:function(t){for(var e in t||(t={}),t)this.setControlVisible(e,t[e]);return this},onDeselect:function(){},onSelect:function(){}})}(),v.util.object.extend(v.StaticCanvas.prototype,{FX_DURATION:500,fxCenterObjectH:function(t,e){var n=function(){},i=(e=e||{}).onComplete||n,s=e.onChange||n,r=this;return v.util.animate({startValue:t.left,endValue:this.getCenter().left,duration:this.FX_DURATION,onChange:function(e){t.set("left",e),r.requestRenderAll(),s()},onComplete:function(){t.setCoords(),i()}}),this},fxCenterObjectV:function(t,e){var n=function(){},i=(e=e||{}).onComplete||n,s=e.onChange||n,r=this;return v.util.animate({startValue:t.top,endValue:this.getCenter().top,duration:this.FX_DURATION,onChange:function(e){t.set("top",e),r.requestRenderAll(),s()},onComplete:function(){t.setCoords(),i()}}),this},fxRemove:function(t,e){var n=function(){},i=(e=e||{}).onComplete||n,s=e.onChange||n,r=this;return v.util.animate({startValue:t.opacity,endValue:0,duration:this.FX_DURATION,onChange:function(e){t.set("opacity",e),r.requestRenderAll(),s()},onComplete:function(){r.remove(t),i()}}),this}}),v.util.object.extend(v.Object.prototype,{animate:function(){if(arguments[0]&&"object"==typeof arguments[0]){var t,e,n=[];for(t in arguments[0])n.push(t);for(var i=0,s=n.length;i<s;i++)t=n[i],e=i!==s-1,this._animate(t,arguments[0][t],arguments[1],e)}else this._animate.apply(this,arguments);return this},_animate:function(t,e,n,i){var s,r=this;e=e.toString(),n=n?v.util.object.clone(n):{},~t.indexOf(".")&&(s=t.split("."));var o=r.colorProperties.indexOf(t)>-1||s&&r.colorProperties.indexOf(s[1])>-1,a=s?this.get(s[0])[s[1]]:this.get(t);"from"in n||(n.from=a),o||(e=~e.indexOf("=")?a+parseFloat(e.replace("=","")):parseFloat(e));var c={startValue:n.from,endValue:e,byValue:n.by,easing:n.easing,duration:n.duration,abort:n.abort&&function(){return n.abort.call(r)},onChange:function(e,o,a){s?r[s[0]][s[1]]=e:r.set(t,e),i||n.onChange&&n.onChange(e,o,a)},onComplete:function(t,e,s){i||(r.setCoords(),n.onComplete&&n.onComplete(t,e,s))}};o?v.util.animateColor(c.startValue,c.endValue,c.duration,c):v.util.animate(c)}}),function(t){var e=t.fabric||(t.fabric={}),n=e.util.object.extend,i=e.util.object.clone,s={x1:1,x2:1,y1:1,y2:1},r=e.StaticCanvas.supports("setLineDash");function o(t,e){var n=t.origin,i=t.axis1,s=t.axis2,r=t.dimension,o=e.nearest,a=e.center,c=e.farthest;return function(){switch(this.get(n)){case o:return Math.min(this.get(i),this.get(s));case a:return Math.min(this.get(i),this.get(s))+.5*this.get(r);case c:return Math.max(this.get(i),this.get(s))}}}e.Line?e.warn("fabric.Line is already defined"):(e.Line=e.util.createClass(e.Object,{type:"line",x1:0,y1:0,x2:0,y2:0,cacheProperties:e.Object.prototype.cacheProperties.concat("x1","x2","y1","y2"),initialize:function(t,e){t||(t=[0,0,0,0]),this.callSuper("initialize",e),this.set("x1",t[0]),this.set("y1",t[1]),this.set("x2",t[2]),this.set("y2",t[3]),this._setWidthHeight(e)},_setWidthHeight:function(t){t||(t={}),this.width=Math.abs(this.x2-this.x1),this.height=Math.abs(this.y2-this.y1),this.left="left"in t?t.left:this._getLeftToOriginX(),this.top="top"in t?t.top:this._getTopToOriginY()},_set:function(t,e){return this.callSuper("_set",t,e),void 0!==s[t]&&this._setWidthHeight(),this},_getLeftToOriginX:o({origin:"originX",axis1:"x1",axis2:"x2",dimension:"width"},{nearest:"left",center:"center",farthest:"right"}),_getTopToOriginY:o({origin:"originY",axis1:"y1",axis2:"y2",dimension:"height"},{nearest:"top",center:"center",farthest:"bottom"}),_render:function(t){if(t.beginPath(),!this.strokeDashArray||this.strokeDashArray&&r){var e=this.calcLinePoints();t.moveTo(e.x1,e.y1),t.lineTo(e.x2,e.y2)}t.lineWidth=this.strokeWidth;var n=t.strokeStyle;t.strokeStyle=this.stroke||t.fillStyle,this.stroke&&this._renderStroke(t),t.strokeStyle=n},_renderDashedStroke:function(t){var n=this.calcLinePoints();t.beginPath(),e.util.drawDashedLine(t,n.x1,n.y1,n.x2,n.y2,this.strokeDashArray),t.closePath()},_findCenterFromElement:function(){return{x:(this.x1+this.x2)/2,y:(this.y1+this.y2)/2}},toObject:function(t){return n(this.callSuper("toObject",t),this.calcLinePoints())},_getNonTransformedDimensions:function(){var t=this.callSuper("_getNonTransformedDimensions");return"butt"===this.strokeLineCap&&(0===this.width&&(t.y-=this.strokeWidth),0===this.height&&(t.x-=this.strokeWidth)),t},calcLinePoints:function(){var t=this.x1<=this.x2?-1:1,e=this.y1<=this.y2?-1:1,n=t*this.width*.5,i=e*this.height*.5;return{x1:n,x2:t*this.width*-.5,y1:i,y2:e*this.height*-.5}},_toSVG:function(){var t=this.calcLinePoints();return["<line ","COMMON_PARTS",'x1="',t.x1,'" y1="',t.y1,'" x2="',t.x2,'" y2="',t.y2,'" />\n']}}),e.Line.ATTRIBUTE_NAMES=e.SHARED_ATTRIBUTES.concat("x1 y1 x2 y2".split(" ")),e.Line.fromElement=function(t,i,s){s=s||{};var r=e.parseAttributes(t,e.Line.ATTRIBUTE_NAMES),o=[r.x1||0,r.y1||0,r.x2||0,r.y2||0];i(new e.Line(o,n(r,s)))},e.Line.fromObject=function(t,n){var s=i(t,!0);s.points=[t.x1,t.y1,t.x2,t.y2],e.Object._fromObject("Line",s,(function(t){delete t.points,n&&n(t)}),"points")})}(e),function(t){var e=t.fabric||(t.fabric={}),n=Math.PI;e.Circle?e.warn("fabric.Circle is already defined."):(e.Circle=e.util.createClass(e.Object,{type:"circle",radius:0,startAngle:0,endAngle:2*n,cacheProperties:e.Object.prototype.cacheProperties.concat("radius","startAngle","endAngle"),_set:function(t,e){return this.callSuper("_set",t,e),"radius"===t&&this.setRadius(e),this},toObject:function(t){return this.callSuper("toObject",["radius","startAngle","endAngle"].concat(t))},_toSVG:function(){var t,i=(this.endAngle-this.startAngle)%(2*n);if(0===i)t=["<circle ","COMMON_PARTS",'cx="0" cy="0" ','r="',this.radius,'" />\n'];else{var s=e.util.cos(this.startAngle)*this.radius,r=e.util.sin(this.startAngle)*this.radius,o=e.util.cos(this.endAngle)*this.radius,a=e.util.sin(this.endAngle)*this.radius,c=i>n?"1":"0";t=['<path d="M '+s+" "+r," A "+this.radius+" "+this.radius," 0 ",+c+" 1"," "+o+" "+a,'" ',"COMMON_PARTS"," />\n"]}return t},_render:function(t){t.beginPath(),t.arc(0,0,this.radius,this.startAngle,this.endAngle,!1),this._renderPaintInOrder(t)},getRadiusX:function(){return this.get("radius")*this.get("scaleX")},getRadiusY:function(){return this.get("radius")*this.get("scaleY")},setRadius:function(t){return this.radius=t,this.set("width",2*t).set("height",2*t)}}),e.Circle.ATTRIBUTE_NAMES=e.SHARED_ATTRIBUTES.concat("cx cy r".split(" ")),e.Circle.fromElement=function(t,n){var i,s=e.parseAttributes(t,e.Circle.ATTRIBUTE_NAMES);if(!("radius"in(i=s)&&i.radius>=0))throw new Error("value of `r` attribute is required and can not be negative");s.left=(s.left||0)-s.radius,s.top=(s.top||0)-s.radius,n(new e.Circle(s))},e.Circle.fromObject=function(t,n){return e.Object._fromObject("Circle",t,n)})}(e),function(t){var e=t.fabric||(t.fabric={});e.Triangle?e.warn("fabric.Triangle is already defined"):(e.Triangle=e.util.createClass(e.Object,{type:"triangle",width:100,height:100,_render:function(t){var e=this.width/2,n=this.height/2;t.beginPath(),t.moveTo(-e,n),t.lineTo(0,-n),t.lineTo(e,n),t.closePath(),this._renderPaintInOrder(t)},_renderDashedStroke:function(t){var n=this.width/2,i=this.height/2;t.beginPath(),e.util.drawDashedLine(t,-n,i,0,-i,this.strokeDashArray),e.util.drawDashedLine(t,0,-i,n,i,this.strokeDashArray),e.util.drawDashedLine(t,n,i,-n,i,this.strokeDashArray),t.closePath()},_toSVG:function(){var t=this.width/2,e=this.height/2;return["<polygon ","COMMON_PARTS",'points="',[-t+" "+e,"0 "+-e,t+" "+e].join(","),'" />']}}),e.Triangle.fromObject=function(t,n){return e.Object._fromObject("Triangle",t,n)})}(e),function(t){var e=t.fabric||(t.fabric={}),n=2*Math.PI;e.Ellipse?e.warn("fabric.Ellipse is already defined."):(e.Ellipse=e.util.createClass(e.Object,{type:"ellipse",rx:0,ry:0,cacheProperties:e.Object.prototype.cacheProperties.concat("rx","ry"),initialize:function(t){this.callSuper("initialize",t),this.set("rx",t&&t.rx||0),this.set("ry",t&&t.ry||0)},_set:function(t,e){switch(this.callSuper("_set",t,e),t){case"rx":this.rx=e,this.set("width",2*e);break;case"ry":this.ry=e,this.set("height",2*e)}return this},getRx:function(){return this.get("rx")*this.get("scaleX")},getRy:function(){return this.get("ry")*this.get("scaleY")},toObject:function(t){return this.callSuper("toObject",["rx","ry"].concat(t))},_toSVG:function(){return["<ellipse ","COMMON_PARTS",'cx="0" cy="0" ','rx="',this.rx,'" ry="',this.ry,'" />\n']},_render:function(t){t.beginPath(),t.save(),t.transform(1,0,0,this.ry/this.rx,0,0),t.arc(0,0,this.rx,0,n,!1),t.restore(),this._renderPaintInOrder(t)}}),e.Ellipse.ATTRIBUTE_NAMES=e.SHARED_ATTRIBUTES.concat("cx cy rx ry".split(" ")),e.Ellipse.fromElement=function(t,n){var i=e.parseAttributes(t,e.Ellipse.ATTRIBUTE_NAMES);i.left=(i.left||0)-i.rx,i.top=(i.top||0)-i.ry,n(new e.Ellipse(i))},e.Ellipse.fromObject=function(t,n){return e.Object._fromObject("Ellipse",t,n)})}(e),function(t){var e=t.fabric||(t.fabric={}),n=e.util.object.extend;e.Rect?e.warn("fabric.Rect is already defined"):(e.Rect=e.util.createClass(e.Object,{stateProperties:e.Object.prototype.stateProperties.concat("rx","ry"),type:"rect",rx:0,ry:0,cacheProperties:e.Object.prototype.cacheProperties.concat("rx","ry"),initialize:function(t){this.callSuper("initialize",t),this._initRxRy()},_initRxRy:function(){this.rx&&!this.ry?this.ry=this.rx:this.ry&&!this.rx&&(this.rx=this.ry)},_render:function(t){var e=this.rx?Math.min(this.rx,this.width/2):0,n=this.ry?Math.min(this.ry,this.height/2):0,i=this.width,s=this.height,r=-this.width/2,o=-this.height/2,a=0!==e||0!==n,c=.4477152502;t.beginPath(),t.moveTo(r+e,o),t.lineTo(r+i-e,o),a&&t.bezierCurveTo(r+i-c*e,o,r+i,o+c*n,r+i,o+n),t.lineTo(r+i,o+s-n),a&&t.bezierCurveTo(r+i,o+s-c*n,r+i-c*e,o+s,r+i-e,o+s),t.lineTo(r+e,o+s),a&&t.bezierCurveTo(r+c*e,o+s,r,o+s-c*n,r,o+s-n),t.lineTo(r,o+n),a&&t.bezierCurveTo(r,o+c*n,r+c*e,o,r+e,o),t.closePath(),this._renderPaintInOrder(t)},_renderDashedStroke:function(t){var n=-this.width/2,i=-this.height/2,s=this.width,r=this.height;t.beginPath(),e.util.drawDashedLine(t,n,i,n+s,i,this.strokeDashArray),e.util.drawDashedLine(t,n+s,i,n+s,i+r,this.strokeDashArray),e.util.drawDashedLine(t,n+s,i+r,n,i+r,this.strokeDashArray),e.util.drawDashedLine(t,n,i+r,n,i,this.strokeDashArray),t.closePath()},toObject:function(t){return this.callSuper("toObject",["rx","ry"].concat(t))},_toSVG:function(){return["<rect ","COMMON_PARTS",'x="',-this.width/2,'" y="',-this.height/2,'" rx="',this.rx,'" ry="',this.ry,'" width="',this.width,'" height="',this.height,'" />\n']}}),e.Rect.ATTRIBUTE_NAMES=e.SHARED_ATTRIBUTES.concat("x y rx ry width height".split(" ")),e.Rect.fromElement=function(t,i,s){if(!t)return i(null);s=s||{};var r=e.parseAttributes(t,e.Rect.ATTRIBUTE_NAMES);r.left=r.left||0,r.top=r.top||0,r.height=r.height||0,r.width=r.width||0;var o=new e.Rect(n(s?e.util.object.clone(s):{},r));o.visible=o.visible&&o.width>0&&o.height>0,i(o)},e.Rect.fromObject=function(t,n){return e.Object._fromObject("Rect",t,n)})}(e),function(t){var e=t.fabric||(t.fabric={}),n=e.util.object.extend,i=e.util.array.min,s=e.util.array.max,r=e.util.toFixed;e.Polyline?e.warn("fabric.Polyline is already defined"):(e.Polyline=e.util.createClass(e.Object,{type:"polyline",points:null,cacheProperties:e.Object.prototype.cacheProperties.concat("points"),initialize:function(t,e){e=e||{},this.points=t||[],this.callSuper("initialize",e),this._setPositionDimensions(e)},_setPositionDimensions:function(t){var e,n=this._calcDimensions(t);this.width=n.width,this.height=n.height,t.fromSVG||(e=this.translateToGivenOrigin({x:n.left-this.strokeWidth/2,y:n.top-this.strokeWidth/2},"left","top",this.originX,this.originY)),void 0===t.left&&(this.left=t.fromSVG?n.left:e.x),void 0===t.top&&(this.top=t.fromSVG?n.top:e.y),this.pathOffset={x:n.left+this.width/2,y:n.top+this.height/2}},_calcDimensions:function(){var t=this.points,e=i(t,"x")||0,n=i(t,"y")||0;return{left:e,top:n,width:(s(t,"x")||0)-e,height:(s(t,"y")||0)-n}},toObject:function(t){return n(this.callSuper("toObject",t),{points:this.points.concat()})},_toSVG:function(){for(var t=[],n=this.pathOffset.x,i=this.pathOffset.y,s=e.Object.NUM_FRACTION_DIGITS,o=0,a=this.points.length;o<a;o++)t.push(r(this.points[o].x-n,s),",",r(this.points[o].y-i,s)," ");return["<"+this.type+" ","COMMON_PARTS",'points="',t.join(""),'" />\n']},commonRender:function(t){var e,n=this.points.length,i=this.pathOffset.x,s=this.pathOffset.y;if(!n||isNaN(this.points[n-1].y))return!1;t.beginPath(),t.moveTo(this.points[0].x-i,this.points[0].y-s);for(var r=0;r<n;r++)e=this.points[r],t.lineTo(e.x-i,e.y-s);return!0},_render:function(t){this.commonRender(t)&&this._renderPaintInOrder(t)},_renderDashedStroke:function(t){var n,i;t.beginPath();for(var s=0,r=this.points.length;s<r;s++)n=this.points[s],i=this.points[s+1]||n,e.util.drawDashedLine(t,n.x,n.y,i.x,i.y,this.strokeDashArray)},complexity:function(){return this.get("points").length}}),e.Polyline.ATTRIBUTE_NAMES=e.SHARED_ATTRIBUTES.concat(),e.Polyline.fromElementGenerator=function(t){return function(i,s,r){if(!i)return s(null);r||(r={});var o=e.parsePointsAttribute(i.getAttribute("points")),a=e.parseAttributes(i,e[t].ATTRIBUTE_NAMES);a.fromSVG=!0,s(new e[t](o,n(a,r)))}},e.Polyline.fromElement=e.Polyline.fromElementGenerator("Polyline"),e.Polyline.fromObject=function(t,n){return e.Object._fromObject("Polyline",t,n,"points")})}(e),function(t){var e=t.fabric||(t.fabric={});e.Polygon?e.warn("fabric.Polygon is already defined"):(e.Polygon=e.util.createClass(e.Polyline,{type:"polygon",_render:function(t){this.commonRender(t)&&(t.closePath(),this._renderPaintInOrder(t))},_renderDashedStroke:function(t){this.callSuper("_renderDashedStroke",t),t.closePath()}}),e.Polygon.ATTRIBUTE_NAMES=e.SHARED_ATTRIBUTES.concat(),e.Polygon.fromElement=e.Polyline.fromElementGenerator("Polygon"),e.Polygon.fromObject=function(t,n){return e.Object._fromObject("Polygon",t,n,"points")})}(e),function(t){var e=t.fabric||(t.fabric={}),n=e.util.array.min,i=e.util.array.max,s=e.util.object.extend,r=Object.prototype.toString,o=e.util.toFixed;e.Path?e.warn("fabric.Path is already defined"):(e.Path=e.util.createClass(e.Object,{type:"path",path:null,cacheProperties:e.Object.prototype.cacheProperties.concat("path","fillRule"),stateProperties:e.Object.prototype.stateProperties.concat("path"),initialize:function(t,n){n=n||{},this.callSuper("initialize",n),t||(t=[]);var i="[object Array]"===r.call(t);this.path=i?e.util.makePathSimpler(t):e.util.makePathSimpler(e.util.parsePath(t)),this.path&&e.Polyline.prototype._setPositionDimensions.call(this,n)},_renderPathCommands:function(t){var e,n=0,i=0,s=0,r=0,o=0,a=0,c=-this.pathOffset.x,l=-this.pathOffset.y;t.beginPath();for(var h=0,u=this.path.length;h<u;++h)switch((e=this.path[h])[0]){case"L":s=e[1],r=e[2],t.lineTo(s+c,r+l);break;case"M":n=s=e[1],i=r=e[2],t.moveTo(s+c,r+l);break;case"C":s=e[5],r=e[6],o=e[3],a=e[4],t.bezierCurveTo(e[1]+c,e[2]+l,o+c,a+l,s+c,r+l);break;case"Q":t.quadraticCurveTo(e[1]+c,e[2]+l,e[3]+c,e[4]+l),s=e[3],r=e[4],o=e[1],a=e[2];break;case"z":case"Z":s=n,r=i,t.closePath()}},_render:function(t){this._renderPathCommands(t),this._renderPaintInOrder(t)},toString:function(){return"#<fabric.Path ("+this.complexity()+'): { "top": '+this.top+', "left": '+this.left+" }>"},toObject:function(t){return s(this.callSuper("toObject",t),{path:this.path.map((function(t){return t.slice()}))})},toDatalessObject:function(t){var e=this.toObject(["sourcePath"].concat(t));return e.sourcePath&&delete e.path,e},_toSVG:function(){return["<path ","COMMON_PARTS",'d="',this.path.map((function(t){return t.join(" ")})).join(" "),'" stroke-linecap="round" ',"/>\n"]},_getOffsetTransform:function(){var t=e.Object.NUM_FRACTION_DIGITS;return" translate("+o(-this.pathOffset.x,t)+", "+o(-this.pathOffset.y,t)+")"},toClipPathSVG:function(t){var e=this._getOffsetTransform();return"\t"+this._createBaseClipPathSVGMarkup(this._toSVG(),{reviver:t,additionalTransform:e})},toSVG:function(t){var e=this._getOffsetTransform();return this._createBaseSVGMarkup(this._toSVG(),{reviver:t,additionalTransform:e})},complexity:function(){return this.path.length},_calcDimensions:function(){for(var t,s,r=[],o=[],a=0,c=0,l=0,h=0,u=0,d=this.path.length;u<d;++u){switch((t=this.path[u])[0]){case"L":l=t[1],h=t[2],s=[];break;case"M":a=l=t[1],c=h=t[2],s=[];break;case"C":s=e.util.getBoundsOfCurve(l,h,t[1],t[2],t[3],t[4],t[5],t[6]),l=t[5],h=t[6];break;case"Q":s=e.util.getBoundsOfCurve(l,h,t[1],t[2],t[1],t[2],t[3],t[4]),l=t[3],h=t[4];break;case"z":case"Z":l=a,h=c}s.forEach((function(t){r.push(t.x),o.push(t.y)})),r.push(l),o.push(h)}var f=n(r)||0,p=n(o)||0;return{left:f,top:p,width:(i(r)||0)-f,height:(i(o)||0)-p}}}),e.Path.fromObject=function(t,n){if("string"==typeof t.sourcePath){var i=t.sourcePath;e.loadSVGFromURL(i,(function(e){var i=e[0];i.setOptions(t),n&&n(i)}))}else e.Object._fromObject("Path",t,n,"path")},e.Path.ATTRIBUTE_NAMES=e.SHARED_ATTRIBUTES.concat(["d"]),e.Path.fromElement=function(t,n,i){var r=e.parseAttributes(t,e.Path.ATTRIBUTE_NAMES);r.fromSVG=!0,n(new e.Path(r.d,s(r,i)))})}(e),function(t){var e=t.fabric||(t.fabric={}),n=e.util.array.min,i=e.util.array.max;e.Group||(e.Group=e.util.createClass(e.Object,e.Collection,{type:"group",strokeWidth:0,subTargetCheck:!1,cacheProperties:[],useSetOnGroup:!1,initialize:function(t,e,n){e=e||{},this._objects=[],n&&this.callSuper("initialize",e),this._objects=t||[];for(var i=this._objects.length;i--;)this._objects[i].group=this;if(n)this._updateObjectsACoords();else{var s=e&&e.centerPoint;void 0!==e.originX&&(this.originX=e.originX),void 0!==e.originY&&(this.originY=e.originY),s||this._calcBounds(),this._updateObjectsCoords(s),delete e.centerPoint,this.callSuper("initialize",e)}this.setCoords()},_updateObjectsACoords:function(){for(var t=this._objects.length;t--;)this._objects[t].setCoords(true)},_updateObjectsCoords:function(t){t=t||this.getCenterPoint();for(var e=this._objects.length;e--;)this._updateObjectCoords(this._objects[e],t)},_updateObjectCoords:function(t,e){var n=t.left,i=t.top;t.set({left:n-e.x,top:i-e.y}),t.group=this,t.setCoords(!0)},toString:function(){return"#<fabric.Group: ("+this.complexity()+")>"},addWithUpdate:function(t){var n=!!this.group;return this._restoreObjectsState(),e.util.resetObjectTransform(this),t&&(n&&e.util.removeTransformFromObject(t,this.group.calcTransformMatrix()),this._objects.push(t),t.group=this,t._set("canvas",this.canvas)),this._calcBounds(),this._updateObjectsCoords(),this.dirty=!0,n?this.group.addWithUpdate():this.setCoords(),this},removeWithUpdate:function(t){return this._restoreObjectsState(),e.util.resetObjectTransform(this),this.remove(t),this._calcBounds(),this._updateObjectsCoords(),this.setCoords(),this.dirty=!0,this},_onObjectAdded:function(t){this.dirty=!0,t.group=this,t._set("canvas",this.canvas)},_onObjectRemoved:function(t){this.dirty=!0,delete t.group},_set:function(t,n){var i=this._objects.length;if(this.useSetOnGroup)for(;i--;)this._objects[i].setOnGroup(t,n);if("canvas"===t)for(;i--;)this._objects[i]._set(t,n);e.Object.prototype._set.call(this,t,n)},toObject:function(t){var n=this.includeDefaultValues,i=this._objects.map((function(e){var i=e.includeDefaultValues;e.includeDefaultValues=n;var s=e.toObject(t);return e.includeDefaultValues=i,s})),s=e.Object.prototype.toObject.call(this,t);return s.objects=i,s},toDatalessObject:function(t){var n,i=this.sourcePath;if(i)n=i;else{var s=this.includeDefaultValues;n=this._objects.map((function(e){var n=e.includeDefaultValues;e.includeDefaultValues=s;var i=e.toDatalessObject(t);return e.includeDefaultValues=n,i}))}var r=e.Object.prototype.toDatalessObject.call(this,t);return r.objects=n,r},render:function(t){this._transformDone=!0,this.callSuper("render",t),this._transformDone=!1},shouldCache:function(){var t=e.Object.prototype.shouldCache.call(this);if(t)for(var n=0,i=this._objects.length;n<i;n++)if(this._objects[n].willDrawShadow())return this.ownCaching=!1,!1;return t},willDrawShadow:function(){if(e.Object.prototype.willDrawShadow.call(this))return!0;for(var t=0,n=this._objects.length;t<n;t++)if(this._objects[t].willDrawShadow())return!0;return!1},isOnACache:function(){return this.ownCaching||this.group&&this.group.isOnACache()},drawObject:function(t){for(var e=0,n=this._objects.length;e<n;e++)this._objects[e].render(t);this._drawClipPath(t)},isCacheDirty:function(t){if(this.callSuper("isCacheDirty",t))return!0;if(!this.statefullCache)return!1;for(var e=0,n=this._objects.length;e<n;e++)if(this._objects[e].isCacheDirty(!0)){if(this._cacheCanvas){var i=this.cacheWidth/this.zoomX,s=this.cacheHeight/this.zoomY;this._cacheContext.clearRect(-i/2,-s/2,i,s)}return!0}return!1},_restoreObjectsState:function(){var t=this.calcOwnMatrix();return this._objects.forEach((function(n){e.util.addTransformToObject(n,t),delete n.group,n.setCoords()})),this},realizeTransform:function(t,n){return e.util.addTransformToObject(t,n),t},destroy:function(){return this._objects.forEach((function(t){t.set("dirty",!0)})),this._restoreObjectsState()},toActiveSelection:function(){if(this.canvas){var t=this._objects,n=this.canvas;this._objects=[];var i=this.toObject();delete i.objects;var s=new e.ActiveSelection([]);return s.set(i),s.type="activeSelection",n.remove(this),t.forEach((function(t){t.group=s,t.dirty=!0,n.add(t)})),s.canvas=n,s._objects=t,n._activeObject=s,s.setCoords(),s}},ungroupOnCanvas:function(){return this._restoreObjectsState()},setObjectsCoords:function(){return this.forEachObject((function(t){t.setCoords(true)})),this},_calcBounds:function(t){for(var e,n,i,s,r=[],o=[],a=["tr","br","bl","tl"],c=0,l=this._objects.length,h=a.length;c<l;++c){for(i=(e=this._objects[c]).calcACoords(),s=0;s<h;s++)n=a[s],r.push(i[n].x),o.push(i[n].y);e.aCoords=i}this._getBounds(r,o,t)},_getBounds:function(t,s,r){var o=new e.Point(n(t),n(s)),a=new e.Point(i(t),i(s)),c=o.y||0,l=o.x||0,h=a.x-o.x||0,u=a.y-o.y||0;this.width=h,this.height=u,r||this.setPositionByOrigin({x:l,y:c},"left","top")},_toSVG:function(t){for(var e=["<g ","COMMON_PARTS"," >\n"],n=0,i=this._objects.length;n<i;n++)e.push("\t\t",this._objects[n].toSVG(t));return e.push("</g>\n"),e},getSvgStyles:function(){var t=void 0!==this.opacity&&1!==this.opacity?"opacity: "+this.opacity+";":"",e=this.visible?"":" visibility: hidden;";return[t,this.getSvgFilter(),e].join("")},toClipPathSVG:function(t){for(var e=[],n=0,i=this._objects.length;n<i;n++)e.push("\t",this._objects[n].toClipPathSVG(t));return this._createBaseClipPathSVGMarkup(e,{reviver:t})}}),e.Group.fromObject=function(t,n){var i=t.objects,s=e.util.object.clone(t,!0);delete s.objects,"string"!=typeof i?e.util.enlivenObjects(i,(function(i){e.util.enlivenObjects([t.clipPath],(function(s){var r=e.util.object.clone(t,!0);r.clipPath=s[0],delete r.objects,n&&n(new e.Group(i,r,!0))}))})):e.loadSVGFromURL(i,(function(r){var o=e.util.groupSVGElements(r,t,i);o.set(s),n&&n(o)}))})}(e),function(t){var e=t.fabric||(t.fabric={});e.ActiveSelection||(e.ActiveSelection=e.util.createClass(e.Group,{type:"activeSelection",initialize:function(t,n){n=n||{},this._objects=t||[];for(var i=this._objects.length;i--;)this._objects[i].group=this;n.originX&&(this.originX=n.originX),n.originY&&(this.originY=n.originY),this._calcBounds(),this._updateObjectsCoords(),e.Object.prototype.initialize.call(this,n),this.setCoords()},toGroup:function(){var t=this._objects.concat();this._objects=[];var n=e.Object.prototype.toObject.call(this),i=new e.Group([]);if(delete n.type,i.set(n),t.forEach((function(t){t.canvas.remove(t),t.group=i})),i._objects=t,!this.canvas)return i;var s=this.canvas;return s.add(i),s._activeObject=i,i.setCoords(),i},onDeselect:function(){return this.destroy(),!1},toString:function(){return"#<fabric.ActiveSelection: ("+this.complexity()+")>"},shouldCache:function(){return!1},isOnACache:function(){return!1},_renderControls:function(t,e,n){t.save(),t.globalAlpha=this.isMoving?this.borderOpacityWhenMoving:1,this.callSuper("_renderControls",t,e),void 0===(n=n||{}).hasControls&&(n.hasControls=!1),n.forActiveSelection=!0;for(var i=0,s=this._objects.length;i<s;i++)this._objects[i]._renderControls(t,n);t.restore()}}),e.ActiveSelection.fromObject=function(t,n){e.util.enlivenObjects(t.objects,(function(i){delete t.objects,n&&n(new e.ActiveSelection(i,t,!0))}))})}(e),function(t){var e=v.util.object.extend;t.fabric||(t.fabric={}),t.fabric.Image?v.warn("fabric.Image is already defined."):(v.Image=v.util.createClass(v.Object,{type:"image",strokeWidth:0,srcFromAttribute:!1,_lastScaleX:1,_lastScaleY:1,_filterScalingX:1,_filterScalingY:1,minimumScaleTrigger:.5,stateProperties:v.Object.prototype.stateProperties.concat("cropX","cropY"),cacheProperties:v.Object.prototype.cacheProperties.concat("cropX","cropY"),cacheKey:"",cropX:0,cropY:0,imageSmoothing:!0,initialize:function(t,e){e||(e={}),this.filters=[],this.cacheKey="texture"+v.Object.__uid++,this.callSuper("initialize",e),this._initElement(t,e)},getElement:function(){return this._element||{}},setElement:function(t,e){return this.removeTexture(this.cacheKey),this.removeTexture(this.cacheKey+"_filtered"),this._element=t,this._originalElement=t,this._initConfig(e),0!==this.filters.length&&this.applyFilters(),this.resizeFilter&&this.applyResizeFilters(),this},removeTexture:function(t){var e=v.filterBackend;e&&e.evictCachesForKey&&e.evictCachesForKey(t)},dispose:function(){this.removeTexture(this.cacheKey),this.removeTexture(this.cacheKey+"_filtered"),this._cacheContext=void 0,["_originalElement","_element","_filteredEl","_cacheCanvas"].forEach(function(t){v.util.cleanUpJsdomNode(this[t]),this[t]=void 0}.bind(this))},getCrossOrigin:function(){return this._originalElement&&(this._originalElement.crossOrigin||null)},getOriginalSize:function(){var t=this.getElement();return{width:t.naturalWidth||t.width,height:t.naturalHeight||t.height}},_stroke:function(t){if(this.stroke&&0!==this.strokeWidth){var e=this.width/2,n=this.height/2;t.beginPath(),t.moveTo(-e,-n),t.lineTo(e,-n),t.lineTo(e,n),t.lineTo(-e,n),t.lineTo(-e,-n),t.closePath()}},_renderDashedStroke:function(t){var e=-this.width/2,n=-this.height/2,i=this.width,s=this.height;t.save(),this._setStrokeStyles(t,this),t.beginPath(),v.util.drawDashedLine(t,e,n,e+i,n,this.strokeDashArray),v.util.drawDashedLine(t,e+i,n,e+i,n+s,this.strokeDashArray),v.util.drawDashedLine(t,e+i,n+s,e,n+s,this.strokeDashArray),v.util.drawDashedLine(t,e,n+s,e,n,this.strokeDashArray),t.closePath(),t.restore()},toObject:function(t){var n=[];this.filters.forEach((function(t){t&&n.push(t.toObject())}));var i=e(this.callSuper("toObject",["cropX","cropY"].concat(t)),{src:this.getSrc(),crossOrigin:this.getCrossOrigin(),filters:n});return this.resizeFilter&&(i.resizeFilter=this.resizeFilter.toObject()),i},hasCrop:function(){return this.cropX||this.cropY||this.width<this._element.width||this.height<this._element.height},_toSVG:function(){var t,e=[],n=[],i=this._element,s=-this.width/2,r=-this.height/2,o="",a="";if(!i)return[];if(this.hasCrop()){var c=v.Object.__uid++;e.push('<clipPath id="imageCrop_'+c+'">\n','\t<rect x="'+s+'" y="'+r+'" width="'+this.width+'" height="'+this.height+'" />\n',"</clipPath>\n"),o=' clip-path="url(#imageCrop_'+c+')" '}if(this.imageSmoothing||(a='" image-rendering="optimizeSpeed'),n.push("\t<image ","COMMON_PARTS",'xlink:href="',this.getSvgSrc(!0),'" x="',s-this.cropX,'" y="',r-this.cropY,'" width="',i.width||i.naturalWidth,'" height="',i.height||i.height,a,'"',o,"></image>\n"),this.stroke||this.strokeDashArray){var l=this.fill;this.fill=null,t=["\t<rect ",'x="',s,'" y="',r,'" width="',this.width,'" height="',this.height,'" style="',this.getSvgStyles(),'"/>\n'],this.fill=l}return e="fill"!==this.paintFirst?e.concat(t,n):e.concat(n,t)},getSrc:function(t){var e=t?this._element:this._originalElement;return e?e.toDataURL?e.toDataURL():this.srcFromAttribute?e.getAttribute("src"):e.src:this.src||""},setSrc:function(t,e,n){return v.util.loadImage(t,(function(t,i){this.setElement(t,n),this._setWidthHeight(),e&&e(this,i)}),this,n&&n.crossOrigin),this},toString:function(){return'#<fabric.Image: { src: "'+this.getSrc()+'" }>'},applyResizeFilters:function(){var t=this.resizeFilter,e=this.minimumScaleTrigger,n=this.getTotalObjectScaling(),i=n.scaleX,s=n.scaleY,r=this._filteredEl||this._originalElement;if(this.group&&this.set("dirty",!0),!t||i>e&&s>e)return this._element=r,this._filterScalingX=1,this._filterScalingY=1,this._lastScaleX=i,void(this._lastScaleY=s);v.filterBackend||(v.filterBackend=v.initFilterBackend());var o=v.util.createCanvasElement(),a=this._filteredEl?this.cacheKey+"_filtered":this.cacheKey,c=r.width,l=r.height;o.width=c,o.height=l,this._element=o,this._lastScaleX=t.scaleX=i,this._lastScaleY=t.scaleY=s,v.filterBackend.applyFilters([t],r,c,l,this._element,a),this._filterScalingX=o.width/this._originalElement.width,this._filterScalingY=o.height/this._originalElement.height},applyFilters:function(t){if(t=(t=t||this.filters||[]).filter((function(t){return t&&!t.isNeutralState()})),this.set("dirty",!0),this.removeTexture(this.cacheKey+"_filtered"),0===t.length)return this._element=this._originalElement,this._filteredEl=null,this._filterScalingX=1,this._filterScalingY=1,this;var e=this._originalElement,n=e.naturalWidth||e.width,i=e.naturalHeight||e.height;if(this._element===this._originalElement){var s=v.util.createCanvasElement();s.width=n,s.height=i,this._element=s,this._filteredEl=s}else this._element=this._filteredEl,this._filteredEl.getContext("2d").clearRect(0,0,n,i),this._lastScaleX=1,this._lastScaleY=1;return v.filterBackend||(v.filterBackend=v.initFilterBackend()),v.filterBackend.applyFilters(t,this._originalElement,n,i,this._element,this.cacheKey),this._originalElement.width===this._element.width&&this._originalElement.height===this._element.height||(this._filterScalingX=this._element.width/this._originalElement.width,this._filterScalingY=this._element.height/this._originalElement.height),this},_render:function(t){v.util.setImageSmoothing(t,this.imageSmoothing),!0!==this.isMoving&&this.resizeFilter&&this._needsResize()&&this.applyResizeFilters(),this._stroke(t),this._renderPaintInOrder(t)},drawCacheOnCanvas:function(t){v.util.setImageSmoothing(t,this.imageSmoothing),v.Object.prototype.drawCacheOnCanvas.call(this,t)},shouldCache:function(){return this.needsItsOwnCache()},_renderFill:function(t){var e=this._element;if(e){var n=this._filterScalingX,i=this._filterScalingY,s=this.width,r=this.height,o=Math.min,a=Math.max,c=a(this.cropX,0),l=a(this.cropY,0),h=e.naturalWidth||e.width,u=e.naturalHeight||e.height,d=c*n,f=l*i,p=o(s*n,h-d),m=o(r*i,u-f),g=-s/2,v=-r/2,_=o(s,h/n-c),y=o(r,u/i-l);e&&t.drawImage(e,d,f,p,m,g,v,_,y)}},_needsResize:function(){var t=this.getTotalObjectScaling();return t.scaleX!==this._lastScaleX||t.scaleY!==this._lastScaleY},_resetWidthHeight:function(){this.set(this.getOriginalSize())},_initElement:function(t,e){this.setElement(v.util.getById(t),e),v.util.addClass(this.getElement(),v.Image.CSS_CANVAS)},_initConfig:function(t){t||(t={}),this.setOptions(t),this._setWidthHeight(t)},_initFilters:function(t,e){t&&t.length?v.util.enlivenObjects(t,(function(t){e&&e(t)}),"fabric.Image.filters"):e&&e()},_setWidthHeight:function(t){t||(t={});var e=this.getElement();this.width=t.width||e.naturalWidth||e.width||0,this.height=t.height||e.naturalHeight||e.height||0},parsePreserveAspectRatioAttribute:function(){var t,e=v.util.parsePreserveAspectRatioAttribute(this.preserveAspectRatio||""),n=this._element.width,i=this._element.height,s=1,r=1,o=0,a=0,c=0,l=0,h=this.width,u=this.height,d={width:h,height:u};return!e||"none"===e.alignX&&"none"===e.alignY?(s=h/n,r=u/i):("meet"===e.meetOrSlice&&(t=(h-n*(s=r=v.util.findScaleToFit(this._element,d)))/2,"Min"===e.alignX&&(o=-t),"Max"===e.alignX&&(o=t),t=(u-i*r)/2,"Min"===e.alignY&&(a=-t),"Max"===e.alignY&&(a=t)),"slice"===e.meetOrSlice&&(t=n-h/(s=r=v.util.findScaleToCover(this._element,d)),"Mid"===e.alignX&&(c=t/2),"Max"===e.alignX&&(c=t),t=i-u/r,"Mid"===e.alignY&&(l=t/2),"Max"===e.alignY&&(l=t),n=h/s,i=u/r)),{width:n,height:i,scaleX:s,scaleY:r,offsetLeft:o,offsetTop:a,cropX:c,cropY:l}}}),v.Image.CSS_CANVAS="canvas-img",v.Image.prototype.getSvgSrc=v.Image.prototype.getSrc,v.Image.fromObject=function(t,e){var n=v.util.object.clone(t);v.util.loadImage(n.src,(function(t,i){i?e&&e(null,!0):v.Image.prototype._initFilters.call(n,n.filters,(function(i){n.filters=i||[],v.Image.prototype._initFilters.call(n,[n.resizeFilter],(function(i){n.resizeFilter=i[0],v.util.enlivenObjects([n.clipPath],(function(i){n.clipPath=i[0];var s=new v.Image(t,n);e(s,!1)}))}))}))}),null,n.crossOrigin)},v.Image.fromURL=function(t,e,n){v.util.loadImage(t,(function(t,i){e&&e(new v.Image(t,n),i)}),null,n&&n.crossOrigin)},v.Image.ATTRIBUTE_NAMES=v.SHARED_ATTRIBUTES.concat("x y width height preserveAspectRatio xlink:href crossOrigin image-rendering".split(" ")),v.Image.fromElement=function(t,n,i){var s=v.parseAttributes(t,v.Image.ATTRIBUTE_NAMES);v.Image.fromURL(s["xlink:href"],n,e(i?v.util.object.clone(i):{},s))})}(e),v.util.object.extend(v.Object.prototype,{_getAngleValueForStraighten:function(){var t=this.angle%360;return t>0?90*Math.round((t-1)/90):90*Math.round(t/90)},straighten:function(){return this.rotate(this._getAngleValueForStraighten()),this},fxStraighten:function(t){var e=function(){},n=(t=t||{}).onComplete||e,i=t.onChange||e,s=this;return v.util.animate({startValue:this.get("angle"),endValue:this._getAngleValueForStraighten(),duration:this.FX_DURATION,onChange:function(t){s.rotate(t),i()},onComplete:function(){s.setCoords(),n()}}),this}}),v.util.object.extend(v.StaticCanvas.prototype,{straightenObject:function(t){return t.straighten(),this.requestRenderAll(),this},fxStraightenObject:function(t){return t.fxStraighten({onChange:this.requestRenderAllBound}),this}}),function(){function t(t,e){var n="precision "+e+" float;\nvoid main(){}",i=t.createShader(t.FRAGMENT_SHADER);return t.shaderSource(i,n),t.compileShader(i),!!t.getShaderParameter(i,t.COMPILE_STATUS)}function e(t){t&&t.tileSize&&(this.tileSize=t.tileSize),this.setupGLContext(this.tileSize,this.tileSize),this.captureGPUInfo()}v.isWebglSupported=function(e){if(v.isLikelyNode)return!1;e=e||v.WebglFilterBackend.prototype.tileSize;var n=document.createElement("canvas"),i=n.getContext("webgl")||n.getContext("experimental-webgl"),s=!1;if(i){v.maxTextureSize=i.getParameter(i.MAX_TEXTURE_SIZE),s=v.maxTextureSize>=e;for(var r=["highp","mediump","lowp"],o=0;o<3;o++)if(t(i,r[o])){v.webGlPrecision=r[o];break}}return this.isSupported=s,s},v.WebglFilterBackend=e,e.prototype={tileSize:2048,resources:{},setupGLContext:function(t,e){this.dispose(),this.createWebGLCanvas(t,e),this.aPosition=new Float32Array([0,0,0,1,1,0,1,1]),this.chooseFastestCopyGLTo2DMethod(t,e)},chooseFastestCopyGLTo2DMethod:function(t,e){var n,i=void 0!==window.performance;try{new ImageData(1,1),n=!0}catch(t){n=!1}var s="undefined"!=typeof ArrayBuffer,r="undefined"!=typeof Uint8ClampedArray;if(i&&n&&s&&r){var o=v.util.createCanvasElement(),a=new ArrayBuffer(t*e*4);if(v.forceGLPutImageData)return this.imageBuffer=a,void(this.copyGLTo2D=b);var c,l,h={imageBuffer:a,destinationWidth:t,destinationHeight:e,targetCanvas:o};o.width=t,o.height=e,c=window.performance.now(),y.call(h,this.gl,h),l=window.performance.now()-c,c=window.performance.now(),b.call(h,this.gl,h),l>window.performance.now()-c?(this.imageBuffer=a,this.copyGLTo2D=b):this.copyGLTo2D=y}},createWebGLCanvas:function(t,e){var n=v.util.createCanvasElement();n.width=t,n.height=e;var i={alpha:!0,premultipliedAlpha:!1,depth:!1,stencil:!1,antialias:!1},s=n.getContext("webgl",i);s||(s=n.getContext("experimental-webgl",i)),s&&(s.clearColor(0,0,0,0),this.canvas=n,this.gl=s)},applyFilters:function(t,e,n,i,s,r){var o,a=this.gl;r&&(o=this.getCachedTexture(r,e));var c={originalWidth:e.width||e.originalWidth,originalHeight:e.height||e.originalHeight,sourceWidth:n,sourceHeight:i,destinationWidth:n,destinationHeight:i,context:a,sourceTexture:this.createTexture(a,n,i,!o&&e),targetTexture:this.createTexture(a,n,i),originalTexture:o||this.createTexture(a,n,i,!o&&e),passes:t.length,webgl:!0,aPosition:this.aPosition,programCache:this.programCache,pass:0,filterBackend:this,targetCanvas:s},l=a.createFramebuffer();return a.bindFramebuffer(a.FRAMEBUFFER,l),t.forEach((function(t){t&&t.applyTo(c)})),function(t){var e=t.targetCanvas,n=e.width,i=e.height,s=t.destinationWidth,r=t.destinationHeight;n===s&&i===r||(e.width=s,e.height=r)}(c),this.copyGLTo2D(a,c),a.bindTexture(a.TEXTURE_2D,null),a.deleteTexture(c.sourceTexture),a.deleteTexture(c.targetTexture),a.deleteFramebuffer(l),s.getContext("2d").setTransform(1,0,0,1,0,0),c},dispose:function(){this.canvas&&(this.canvas=null,this.gl=null),this.clearWebGLCaches()},clearWebGLCaches:function(){this.programCache={},this.textureCache={}},createTexture:function(t,e,n,i){var s=t.createTexture();return t.bindTexture(t.TEXTURE_2D,s),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),i?t.texImage2D(t.TEXTURE_2D,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,i):t.texImage2D(t.TEXTURE_2D,0,t.RGBA,e,n,0,t.RGBA,t.UNSIGNED_BYTE,null),s},getCachedTexture:function(t,e){if(this.textureCache[t])return this.textureCache[t];var n=this.createTexture(this.gl,e.width,e.height,e);return this.textureCache[t]=n,n},evictCachesForKey:function(t){this.textureCache[t]&&(this.gl.deleteTexture(this.textureCache[t]),delete this.textureCache[t])},copyGLTo2D:y,captureGPUInfo:function(){if(this.gpuInfo)return this.gpuInfo;var t=this.gl,e={renderer:"",vendor:""};if(!t)return e;var n=t.getExtension("WEBGL_debug_renderer_info");if(n){var i=t.getParameter(n.UNMASKED_RENDERER_WEBGL),s=t.getParameter(n.UNMASKED_VENDOR_WEBGL);i&&(e.renderer=i.toLowerCase()),s&&(e.vendor=s.toLowerCase())}return this.gpuInfo=e,e}}}(),function(){var t=function(){};function e(){}v.Canvas2dFilterBackend=e,e.prototype={evictCachesForKey:t,dispose:t,clearWebGLCaches:t,resources:{},applyFilters:function(t,e,n,i,s){var r=s.getContext("2d");r.drawImage(e,0,0,n,i);var o={sourceWidth:n,sourceHeight:i,imageData:r.getImageData(0,0,n,i),originalEl:e,originalImageData:r.getImageData(0,0,n,i),canvasEl:s,ctx:r,filterBackend:this};return t.forEach((function(t){t.applyTo(o)})),o.imageData.width===n&&o.imageData.height===i||(s.width=o.imageData.width,s.height=o.imageData.height),r.putImageData(o.imageData,0,0),o}}}(),v.Image=v.Image||{},v.Image.filters=v.Image.filters||{},v.Image.filters.BaseFilter=v.util.createClass({type:"BaseFilter",vertexSource:"attribute vec2 aPosition;\nvarying vec2 vTexCoord;\nvoid main() {\nvTexCoord = aPosition;\ngl_Position = vec4(aPosition * 2.0 - 1.0, 0.0, 1.0);\n}",fragmentSource:"precision highp float;\nvarying vec2 vTexCoord;\nuniform sampler2D uTexture;\nvoid main() {\ngl_FragColor = texture2D(uTexture, vTexCoord);\n}",initialize:function(t){t&&this.setOptions(t)},setOptions:function(t){for(var e in t)this[e]=t[e]},createProgram:function(t,e,n){e=e||this.fragmentSource,n=n||this.vertexSource,"highp"!==v.webGlPrecision&&(e=e.replace(/precision highp float/g,"precision "+v.webGlPrecision+" float"));var i=t.createShader(t.VERTEX_SHADER);if(t.shaderSource(i,n),t.compileShader(i),!t.getShaderParameter(i,t.COMPILE_STATUS))throw new Error("Vertex shader compile error for "+this.type+": "+t.getShaderInfoLog(i));var s=t.createShader(t.FRAGMENT_SHADER);if(t.shaderSource(s,e),t.compileShader(s),!t.getShaderParameter(s,t.COMPILE_STATUS))throw new Error("Fragment shader compile error for "+this.type+": "+t.getShaderInfoLog(s));var r=t.createProgram();if(t.attachShader(r,i),t.attachShader(r,s),t.linkProgram(r),!t.getProgramParameter(r,t.LINK_STATUS))throw new Error('Shader link error for "${this.type}" '+t.getProgramInfoLog(r));var o=this.getAttributeLocations(t,r),a=this.getUniformLocations(t,r)||{};return a.uStepW=t.getUniformLocation(r,"uStepW"),a.uStepH=t.getUniformLocation(r,"uStepH"),{program:r,attributeLocations:o,uniformLocations:a}},getAttributeLocations:function(t,e){return{aPosition:t.getAttribLocation(e,"aPosition")}},getUniformLocations:function(){return{}},sendAttributeData:function(t,e,n){var i=e.aPosition,s=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,s),t.enableVertexAttribArray(i),t.vertexAttribPointer(i,2,t.FLOAT,!1,0,0),t.bufferData(t.ARRAY_BUFFER,n,t.STATIC_DRAW)},_setupFrameBuffer:function(t){var e,n,i=t.context;t.passes>1?(e=t.destinationWidth,n=t.destinationHeight,t.sourceWidth===e&&t.sourceHeight===n||(i.deleteTexture(t.targetTexture),t.targetTexture=t.filterBackend.createTexture(i,e,n)),i.framebufferTexture2D(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0,i.TEXTURE_2D,t.targetTexture,0)):(i.bindFramebuffer(i.FRAMEBUFFER,null),i.finish())},_swapTextures:function(t){t.passes--,t.pass++;var e=t.targetTexture;t.targetTexture=t.sourceTexture,t.sourceTexture=e},isNeutralState:function(){var t=this.mainParameter,e=v.Image.filters[this.type].prototype;if(t){if(Array.isArray(e[t])){for(var n=e[t].length;n--;)if(this[t][n]!==e[t][n])return!1;return!0}return e[t]===this[t]}return!1},applyTo:function(t){t.webgl?(this._setupFrameBuffer(t),this.applyToWebGL(t),this._swapTextures(t)):this.applyTo2d(t)},retrieveShader:function(t){return t.programCache.hasOwnProperty(this.type)||(t.programCache[this.type]=this.createProgram(t.context)),t.programCache[this.type]},applyToWebGL:function(t){var e=t.context,n=this.retrieveShader(t);0===t.pass&&t.originalTexture?e.bindTexture(e.TEXTURE_2D,t.originalTexture):e.bindTexture(e.TEXTURE_2D,t.sourceTexture),e.useProgram(n.program),this.sendAttributeData(e,n.attributeLocations,t.aPosition),e.uniform1f(n.uniformLocations.uStepW,1/t.sourceWidth),e.uniform1f(n.uniformLocations.uStepH,1/t.sourceHeight),this.sendUniformData(e,n.uniformLocations),e.viewport(0,0,t.destinationWidth,t.destinationHeight),e.drawArrays(e.TRIANGLE_STRIP,0,4)},bindAdditionalTexture:function(t,e,n){t.activeTexture(n),t.bindTexture(t.TEXTURE_2D,e),t.activeTexture(t.TEXTURE0)},unbindAdditionalTexture:function(t,e){t.activeTexture(e),t.bindTexture(t.TEXTURE_2D,null),t.activeTexture(t.TEXTURE0)},getMainParameter:function(){return this[this.mainParameter]},setMainParameter:function(t){this[this.mainParameter]=t},sendUniformData:function(){},createHelpLayer:function(t){if(!t.helpLayer){var e=document.createElement("canvas");e.width=t.sourceWidth,e.height=t.sourceHeight,t.helpLayer=e}},toObject:function(){var t={type:this.type},e=this.mainParameter;return e&&(t[e]=this[e]),t},toJSON:function(){return this.toObject()}}),v.Image.filters.BaseFilter.fromObject=function(t,e){var n=new v.Image.filters[t.type](t);return e&&e(n),n},function(t){var e=t.fabric||(t.fabric={}),n=e.Image.filters,i=e.util.createClass;n.ColorMatrix=i(n.BaseFilter,{type:"ColorMatrix",fragmentSource:"precision highp float;\nuniform sampler2D uTexture;\nvarying vec2 vTexCoord;\nuniform mat4 uColorMatrix;\nuniform vec4 uConstants;\nvoid main() {\nvec4 color = texture2D(uTexture, vTexCoord);\ncolor *= uColorMatrix;\ncolor += uConstants;\ngl_FragColor = color;\n}",matrix:[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0],mainParameter:"matrix",colorsOnly:!0,initialize:function(t){this.callSuper("initialize",t),this.matrix=this.matrix.slice(0)},applyTo2d:function(t){var e,n,i,s,r,o=t.imageData.data,a=o.length,c=this.matrix,l=this.colorsOnly;for(r=0;r<a;r+=4)e=o[r],n=o[r+1],i=o[r+2],l?(o[r]=e*c[0]+n*c[1]+i*c[2]+255*c[4],o[r+1]=e*c[5]+n*c[6]+i*c[7]+255*c[9],o[r+2]=e*c[10]+n*c[11]+i*c[12]+255*c[14]):(s=o[r+3],o[r]=e*c[0]+n*c[1]+i*c[2]+s*c[3]+255*c[4],o[r+1]=e*c[5]+n*c[6]+i*c[7]+s*c[8]+255*c[9],o[r+2]=e*c[10]+n*c[11]+i*c[12]+s*c[13]+255*c[14],o[r+3]=e*c[15]+n*c[16]+i*c[17]+s*c[18]+255*c[19])},getUniformLocations:function(t,e){return{uColorMatrix:t.getUniformLocation(e,"uColorMatrix"),uConstants:t.getUniformLocation(e,"uConstants")}},sendUniformData:function(t,e){var n=this.matrix,i=[n[0],n[1],n[2],n[3],n[5],n[6],n[7],n[8],n[10],n[11],n[12],n[13],n[15],n[16],n[17],n[18]],s=[n[4],n[9],n[14],n[19]];t.uniformMatrix4fv(e.uColorMatrix,!1,i),t.uniform4fv(e.uConstants,s)}}),e.Image.filters.ColorMatrix.fromObject=e.Image.filters.BaseFilter.fromObject}(e),function(t){var e=t.fabric||(t.fabric={}),n=e.Image.filters,i=e.util.createClass;n.Brightness=i(n.BaseFilter,{type:"Brightness",fragmentSource:"precision highp float;\nuniform sampler2D uTexture;\nuniform float uBrightness;\nvarying vec2 vTexCoord;\nvoid main() {\nvec4 color = texture2D(uTexture, vTexCoord);\ncolor.rgb += uBrightness;\ngl_FragColor = color;\n}",brightness:0,mainParameter:"brightness",applyTo2d:function(t){if(0!==this.brightness){var e,n=t.imageData.data,i=n.length,s=Math.round(255*this.brightness);for(e=0;e<i;e+=4)n[e]=n[e]+s,n[e+1]=n[e+1]+s,n[e+2]=n[e+2]+s}},getUniformLocations:function(t,e){return{uBrightness:t.getUniformLocation(e,"uBrightness")}},sendUniformData:function(t,e){t.uniform1f(e.uBrightness,this.brightness)}}),e.Image.filters.Brightness.fromObject=e.Image.filters.BaseFilter.fromObject}(e),function(t){var e=t.fabric||(t.fabric={}),n=e.util.object.extend,i=e.Image.filters,s=e.util.createClass;i.Convolute=s(i.BaseFilter,{type:"Convolute",opaque:!1,matrix:[0,0,0,0,1,0,0,0,0],fragmentSource:{Convolute_3_1:"precision highp float;\nuniform sampler2D uTexture;\nuniform float uMatrix[9];\nuniform float uStepW;\nuniform float uStepH;\nvarying vec2 vTexCoord;\nvoid main() {\nvec4 color = vec4(0, 0, 0, 0);\nfor (float h = 0.0; h < 3.0; h+=1.0) {\nfor (float w = 0.0; w < 3.0; w+=1.0) {\nvec2 matrixPos = vec2(uStepW * (w - 1), uStepH * (h - 1));\ncolor += texture2D(uTexture, vTexCoord + matrixPos) * uMatrix[int(h * 3.0 + w)];\n}\n}\ngl_FragColor = color;\n}",Convolute_3_0:"precision highp float;\nuniform sampler2D uTexture;\nuniform float uMatrix[9];\nuniform float uStepW;\nuniform float uStepH;\nvarying vec2 vTexCoord;\nvoid main() {\nvec4 color = vec4(0, 0, 0, 1);\nfor (float h = 0.0; h < 3.0; h+=1.0) {\nfor (float w = 0.0; w < 3.0; w+=1.0) {\nvec2 matrixPos = vec2(uStepW * (w - 1.0), uStepH * (h - 1.0));\ncolor.rgb += texture2D(uTexture, vTexCoord + matrixPos).rgb * uMatrix[int(h * 3.0 + w)];\n}\n}\nfloat alpha = texture2D(uTexture, vTexCoord).a;\ngl_FragColor = color;\ngl_FragColor.a = alpha;\n}",Convolute_5_1:"precision highp float;\nuniform sampler2D uTexture;\nuniform float uMatrix[25];\nuniform float uStepW;\nuniform float uStepH;\nvarying vec2 vTexCoord;\nvoid main() {\nvec4 color = vec4(0, 0, 0, 0);\nfor (float h = 0.0; h < 5.0; h+=1.0) {\nfor (float w = 0.0; w < 5.0; w+=1.0) {\nvec2 matrixPos = vec2(uStepW * (w - 2.0), uStepH * (h - 2.0));\ncolor += texture2D(uTexture, vTexCoord + matrixPos) * uMatrix[int(h * 5.0 + w)];\n}\n}\ngl_FragColor = color;\n}",Convolute_5_0:"precision highp float;\nuniform sampler2D uTexture;\nuniform float uMatrix[25];\nuniform float uStepW;\nuniform float uStepH;\nvarying vec2 vTexCoord;\nvoid main() {\nvec4 color = vec4(0, 0, 0, 1);\nfor (float h = 0.0; h < 5.0; h+=1.0) {\nfor (float w = 0.0; w < 5.0; w+=1.0) {\nvec2 matrixPos = vec2(uStepW * (w - 2.0), uStepH * (h - 2.0));\ncolor.rgb += texture2D(uTexture, vTexCoord + matrixPos).rgb * uMatrix[int(h * 5.0 + w)];\n}\n}\nfloat alpha = texture2D(uTexture, vTexCoord).a;\ngl_FragColor = color;\ngl_FragColor.a = alpha;\n}",Convolute_7_1:"precision highp float;\nuniform sampler2D uTexture;\nuniform float uMatrix[49];\nuniform float uStepW;\nuniform float uStepH;\nvarying vec2 vTexCoord;\nvoid main() {\nvec4 color = vec4(0, 0, 0, 0);\nfor (float h = 0.0; h < 7.0; h+=1.0) {\nfor (float w = 0.0; w < 7.0; w+=1.0) {\nvec2 matrixPos = vec2(uStepW * (w - 3.0), uStepH * (h - 3.0));\ncolor += texture2D(uTexture, vTexCoord + matrixPos) * uMatrix[int(h * 7.0 + w)];\n}\n}\ngl_FragColor = color;\n}",Convolute_7_0:"precision highp float;\nuniform sampler2D uTexture;\nuniform float uMatrix[49];\nuniform float uStepW;\nuniform float uStepH;\nvarying vec2 vTexCoord;\nvoid main() {\nvec4 color = vec4(0, 0, 0, 1);\nfor (float h = 0.0; h < 7.0; h+=1.0) {\nfor (float w = 0.0; w < 7.0; w+=1.0) {\nvec2 matrixPos = vec2(uStepW * (w - 3.0), uStepH * (h - 3.0));\ncolor.rgb += texture2D(uTexture, vTexCoord + matrixPos).rgb * uMatrix[int(h * 7.0 + w)];\n}\n}\nfloat alpha = texture2D(uTexture, vTexCoord).a;\ngl_FragColor = color;\ngl_FragColor.a = alpha;\n}",Convolute_9_1:"precision highp float;\nuniform sampler2D uTexture;\nuniform float uMatrix[81];\nuniform float uStepW;\nuniform float uStepH;\nvarying vec2 vTexCoord;\nvoid main() {\nvec4 color = vec4(0, 0, 0, 0);\nfor (float h = 0.0; h < 9.0; h+=1.0) {\nfor (float w = 0.0; w < 9.0; w+=1.0) {\nvec2 matrixPos = vec2(uStepW * (w - 4.0), uStepH * (h - 4.0));\ncolor += texture2D(uTexture, vTexCoord + matrixPos) * uMatrix[int(h * 9.0 + w)];\n}\n}\ngl_FragColor = color;\n}",Convolute_9_0:"precision highp float;\nuniform sampler2D uTexture;\nuniform float uMatrix[81];\nuniform float uStepW;\nuniform float uStepH;\nvarying vec2 vTexCoord;\nvoid main() {\nvec4 color = vec4(0, 0, 0, 1);\nfor (float h = 0.0; h < 9.0; h+=1.0) {\nfor (float w = 0.0; w < 9.0; w+=1.0) {\nvec2 matrixPos = vec2(uStepW * (w - 4.0), uStepH * (h - 4.0));\ncolor.rgb += texture2D(uTexture, vTexCoord + matrixPos).rgb * uMatrix[int(h * 9.0 + w)];\n}\n}\nfloat alpha = texture2D(uTexture, vTexCoord).a;\ngl_FragColor = color;\ngl_FragColor.a = alpha;\n}"},retrieveShader:function(t){var e=Math.sqrt(this.matrix.length),n=this.type+"_"+e+"_"+(this.opaque?1:0),i=this.fragmentSource[n];return t.programCache.hasOwnProperty(n)||(t.programCache[n]=this.createProgram(t.context,i)),t.programCache[n]},applyTo2d:function(t){var e,n,i,s,r,o,a,c,l,h,u,d,f,p=t.imageData,m=p.data,g=this.matrix,v=Math.round(Math.sqrt(g.length)),_=Math.floor(v/2),y=p.width,b=p.height,x=t.ctx.createImageData(y,b),C=x.data,w=this.opaque?1:0;for(u=0;u<b;u++)for(h=0;h<y;h++){for(r=4*(u*y+h),e=0,n=0,i=0,s=0,f=0;f<v;f++)for(d=0;d<v;d++)o=h+d-_,(a=u+f-_)<0||a>=b||o<0||o>=y||(c=4*(a*y+o),l=g[f*v+d],e+=m[c]*l,n+=m[c+1]*l,i+=m[c+2]*l,w||(s+=m[c+3]*l));C[r]=e,C[r+1]=n,C[r+2]=i,C[r+3]=w?m[r+3]:s}t.imageData=x},getUniformLocations:function(t,e){return{uMatrix:t.getUniformLocation(e,"uMatrix"),uOpaque:t.getUniformLocation(e,"uOpaque"),uHalfSize:t.getUniformLocation(e,"uHalfSize"),uSize:t.getUniformLocation(e,"uSize")}},sendUniformData:function(t,e){t.uniform1fv(e.uMatrix,this.matrix)},toObject:function(){return n(this.callSuper("toObject"),{opaque:this.opaque,matrix:this.matrix})}}),e.Image.filters.Convolute.fromObject=e.Image.filters.BaseFilter.fromObject}(e),function(t){var e=t.fabric||(t.fabric={}),n=e.Image.filters,i=e.util.createClass;n.Grayscale=i(n.BaseFilter,{type:"Grayscale",fragmentSource:{average:"precision highp float;\nuniform sampler2D uTexture;\nvarying vec2 vTexCoord;\nvoid main() {\nvec4 color = texture2D(uTexture, vTexCoord);\nfloat average = (color.r + color.b + color.g) / 3.0;\ngl_FragColor = vec4(average, average, average, color.a);\n}",lightness:"precision highp float;\nuniform sampler2D uTexture;\nuniform int uMode;\nvarying vec2 vTexCoord;\nvoid main() {\nvec4 col = texture2D(uTexture, vTexCoord);\nfloat average = (max(max(col.r, col.g),col.b) + min(min(col.r, col.g),col.b)) / 2.0;\ngl_FragColor = vec4(average, average, average, col.a);\n}",luminosity:"precision highp float;\nuniform sampler2D uTexture;\nuniform int uMode;\nvarying vec2 vTexCoord;\nvoid main() {\nvec4 col = texture2D(uTexture, vTexCoord);\nfloat average = 0.21 * col.r + 0.72 * col.g + 0.07 * col.b;\ngl_FragColor = vec4(average, average, average, col.a);\n}"},mode:"average",mainParameter:"mode",applyTo2d:function(t){var e,n,i=t.imageData.data,s=i.length,r=this.mode;for(e=0;e<s;e+=4)"average"===r?n=(i[e]+i[e+1]+i[e+2])/3:"lightness"===r?n=(Math.min(i[e],i[e+1],i[e+2])+Math.max(i[e],i[e+1],i[e+2]))/2:"luminosity"===r&&(n=.21*i[e]+.72*i[e+1]+.07*i[e+2]),i[e]=n,i[e+1]=n,i[e+2]=n},retrieveShader:function(t){var e=this.type+"_"+this.mode;if(!t.programCache.hasOwnProperty(e)){var n=this.fragmentSource[this.mode];t.programCache[e]=this.createProgram(t.context,n)}return t.programCache[e]},getUniformLocations:function(t,e){return{uMode:t.getUniformLocation(e,"uMode")}},sendUniformData:function(t,e){t.uniform1i(e.uMode,1)},isNeutralState:function(){return!1}}),e.Image.filters.Grayscale.fromObject=e.Image.filters.BaseFilter.fromObject}(e),function(t){var e=t.fabric||(t.fabric={}),n=e.Image.filters,i=e.util.createClass;n.Invert=i(n.BaseFilter,{type:"Invert",fragmentSource:"precision highp float;\nuniform sampler2D uTexture;\nuniform int uInvert;\nvarying vec2 vTexCoord;\nvoid main() {\nvec4 color = texture2D(uTexture, vTexCoord);\nif (uInvert == 1) {\ngl_FragColor = vec4(1.0 - color.r,1.0 -color.g,1.0 -color.b,color.a);\n} else {\ngl_FragColor = color;\n}\n}",invert:!0,mainParameter:"invert",applyTo2d:function(t){var e,n=t.imageData.data,i=n.length;for(e=0;e<i;e+=4)n[e]=255-n[e],n[e+1]=255-n[e+1],n[e+2]=255-n[e+2]},isNeutralState:function(){return!this.invert},getUniformLocations:function(t,e){return{uInvert:t.getUniformLocation(e,"uInvert")}},sendUniformData:function(t,e){t.uniform1i(e.uInvert,this.invert)}}),e.Image.filters.Invert.fromObject=e.Image.filters.BaseFilter.fromObject}(e),function(t){var e=t.fabric||(t.fabric={}),n=e.util.object.extend,i=e.Image.filters,s=e.util.createClass;i.Noise=s(i.BaseFilter,{type:"Noise",fragmentSource:"precision highp float;\nuniform sampler2D uTexture;\nuniform float uStepH;\nuniform float uNoise;\nuniform float uSeed;\nvarying vec2 vTexCoord;\nfloat rand(vec2 co, float seed, float vScale) {\nreturn fract(sin(dot(co.xy * vScale ,vec2(12.9898 , 78.233))) * 43758.5453 * (seed + 0.01) / 2.0);\n}\nvoid main() {\nvec4 color = texture2D(uTexture, vTexCoord);\ncolor.rgb += (0.5 - rand(vTexCoord, uSeed, 0.1 / uStepH)) * uNoise;\ngl_FragColor = color;\n}",mainParameter:"noise",noise:0,applyTo2d:function(t){if(0!==this.noise){var e,n,i=t.imageData.data,s=i.length,r=this.noise;for(e=0,s=i.length;e<s;e+=4)n=(.5-Math.random())*r,i[e]+=n,i[e+1]+=n,i[e+2]+=n}},getUniformLocations:function(t,e){return{uNoise:t.getUniformLocation(e,"uNoise"),uSeed:t.getUniformLocation(e,"uSeed")}},sendUniformData:function(t,e){t.uniform1f(e.uNoise,this.noise/255),t.uniform1f(e.uSeed,Math.random())},toObject:function(){return n(this.callSuper("toObject"),{noise:this.noise})}}),e.Image.filters.Noise.fromObject=e.Image.filters.BaseFilter.fromObject}(e),function(t){var e=t.fabric||(t.fabric={}),n=e.Image.filters,i=e.util.createClass;n.Pixelate=i(n.BaseFilter,{type:"Pixelate",blocksize:4,mainParameter:"blocksize",fragmentSource:"precision highp float;\nuniform sampler2D uTexture;\nuniform float uBlocksize;\nuniform float uStepW;\nuniform float uStepH;\nvarying vec2 vTexCoord;\nvoid main() {\nfloat blockW = uBlocksize * uStepW;\nfloat blockH = uBlocksize * uStepW;\nint posX = int(vTexCoord.x / blockW);\nint posY = int(vTexCoord.y / blockH);\nfloat fposX = float(posX);\nfloat fposY = float(posY);\nvec2 squareCoords = vec2(fposX * blockW, fposY * blockH);\nvec4 color = texture2D(uTexture, squareCoords);\ngl_FragColor = color;\n}",applyTo2d:function(t){var e,n,i,s,r,o,a,c,l,h,u,d=t.imageData,f=d.data,p=d.height,m=d.width;for(n=0;n<p;n+=this.blocksize)for(i=0;i<m;i+=this.blocksize)for(s=f[e=4*n*m+4*i],r=f[e+1],o=f[e+2],a=f[e+3],h=Math.min(n+this.blocksize,p),u=Math.min(i+this.blocksize,m),c=n;c<h;c++)for(l=i;l<u;l++)f[e=4*c*m+4*l]=s,f[e+1]=r,f[e+2]=o,f[e+3]=a},isNeutralState:function(){return 1===this.blocksize},getUniformLocations:function(t,e){return{uBlocksize:t.getUniformLocation(e,"uBlocksize"),uStepW:t.getUniformLocation(e,"uStepW"),uStepH:t.getUniformLocation(e,"uStepH")}},sendUniformData:function(t,e){t.uniform1f(e.uBlocksize,this.blocksize)}}),e.Image.filters.Pixelate.fromObject=e.Image.filters.BaseFilter.fromObject}(e),function(t){var e=t.fabric||(t.fabric={}),n=e.util.object.extend,i=e.Image.filters,s=e.util.createClass;i.RemoveColor=s(i.BaseFilter,{type:"RemoveColor",color:"#FFFFFF",fragmentSource:"precision highp float;\nuniform sampler2D uTexture;\nuniform vec4 uLow;\nuniform vec4 uHigh;\nvarying vec2 vTexCoord;\nvoid main() {\ngl_FragColor = texture2D(uTexture, vTexCoord);\nif(all(greaterThan(gl_FragColor.rgb,uLow.rgb)) && all(greaterThan(uHigh.rgb,gl_FragColor.rgb))) {\ngl_FragColor.a = 0.0;\n}\n}",distance:.02,useAlpha:!1,applyTo2d:function(t){var n,i,s,r,o=t.imageData.data,a=255*this.distance,c=new e.Color(this.color).getSource(),l=[c[0]-a,c[1]-a,c[2]-a],h=[c[0]+a,c[1]+a,c[2]+a];for(n=0;n<o.length;n+=4)i=o[n],s=o[n+1],r=o[n+2],i>l[0]&&s>l[1]&&r>l[2]&&i<h[0]&&s<h[1]&&r<h[2]&&(o[n+3]=0)},getUniformLocations:function(t,e){return{uLow:t.getUniformLocation(e,"uLow"),uHigh:t.getUniformLocation(e,"uHigh")}},sendUniformData:function(t,n){var i=new e.Color(this.color).getSource(),s=parseFloat(this.distance),r=[0+i[0]/255-s,0+i[1]/255-s,0+i[2]/255-s,1],o=[i[0]/255+s,i[1]/255+s,i[2]/255+s,1];t.uniform4fv(n.uLow,r),t.uniform4fv(n.uHigh,o)},toObject:function(){return n(this.callSuper("toObject"),{color:this.color,distance:this.distance})}}),e.Image.filters.RemoveColor.fromObject=e.Image.filters.BaseFilter.fromObject}(e),function(t){var e=t.fabric||(t.fabric={}),n=e.Image.filters,i=e.util.createClass,s={Brownie:[.5997,.34553,-.27082,0,.186,-.0377,.86095,.15059,0,-.1449,.24113,-.07441,.44972,0,-.02965,0,0,0,1,0],Vintage:[.62793,.32021,-.03965,0,.03784,.02578,.64411,.03259,0,.02926,.0466,-.08512,.52416,0,.02023,0,0,0,1,0],Kodachrome:[1.12855,-.39673,-.03992,0,.24991,-.16404,1.08352,-.05498,0,.09698,-.16786,-.56034,1.60148,0,.13972,0,0,0,1,0],Technicolor:[1.91252,-.85453,-.09155,0,.04624,-.30878,1.76589,-.10601,0,-.27589,-.2311,-.75018,1.84759,0,.12137,0,0,0,1,0],Polaroid:[1.438,-.062,-.062,0,0,-.122,1.378,-.122,0,0,-.016,-.016,1.483,0,0,0,0,0,1,0],Sepia:[.393,.769,.189,0,0,.349,.686,.168,0,0,.272,.534,.131,0,0,0,0,0,1,0],BlackWhite:[1.5,1.5,1.5,0,-1,1.5,1.5,1.5,0,-1,1.5,1.5,1.5,0,-1,0,0,0,1,0]};for(var r in s)n[r]=i(n.ColorMatrix,{type:r,matrix:s[r],mainParameter:!1,colorsOnly:!0}),e.Image.filters[r].fromObject=e.Image.filters.BaseFilter.fromObject}(e),function(t){var e=t.fabric,n=e.Image.filters,i=e.util.createClass;n.BlendColor=i(n.BaseFilter,{type:"BlendColor",color:"#F95C63",mode:"multiply",alpha:1,fragmentSource:{multiply:"gl_FragColor.rgb *= uColor.rgb;\n",screen:"gl_FragColor.rgb = 1.0 - (1.0 - gl_FragColor.rgb) * (1.0 - uColor.rgb);\n",add:"gl_FragColor.rgb += uColor.rgb;\n",diff:"gl_FragColor.rgb = abs(gl_FragColor.rgb - uColor.rgb);\n",subtract:"gl_FragColor.rgb -= uColor.rgb;\n",lighten:"gl_FragColor.rgb = max(gl_FragColor.rgb, uColor.rgb);\n",darken:"gl_FragColor.rgb = min(gl_FragColor.rgb, uColor.rgb);\n",exclusion:"gl_FragColor.rgb += uColor.rgb - 2.0 * (uColor.rgb * gl_FragColor.rgb);\n",overlay:"if (uColor.r < 0.5) {\ngl_FragColor.r *= 2.0 * uColor.r;\n} else {\ngl_FragColor.r = 1.0 - 2.0 * (1.0 - gl_FragColor.r) * (1.0 - uColor.r);\n}\nif (uColor.g < 0.5) {\ngl_FragColor.g *= 2.0 * uColor.g;\n} else {\ngl_FragColor.g = 1.0 - 2.0 * (1.0 - gl_FragColor.g) * (1.0 - uColor.g);\n}\nif (uColor.b < 0.5) {\ngl_FragColor.b *= 2.0 * uColor.b;\n} else {\ngl_FragColor.b = 1.0 - 2.0 * (1.0 - gl_FragColor.b) * (1.0 - uColor.b);\n}\n",tint:"gl_FragColor.rgb *= (1.0 - uColor.a);\ngl_FragColor.rgb += uColor.rgb;\n"},buildSource:function(t){return"precision highp float;\nuniform sampler2D uTexture;\nuniform vec4 uColor;\nvarying vec2 vTexCoord;\nvoid main() {\nvec4 color = texture2D(uTexture, vTexCoord);\ngl_FragColor = color;\nif (color.a > 0.0) {\n"+this.fragmentSource[t]+"}\n}"},retrieveShader:function(t){var e,n=this.type+"_"+this.mode;return t.programCache.hasOwnProperty(n)||(e=this.buildSource(this.mode),t.programCache[n]=this.createProgram(t.context,e)),t.programCache[n]},applyTo2d:function(t){var n,i,s,r,o,a,c,l=t.imageData.data,h=l.length,u=1-this.alpha;n=(c=new e.Color(this.color).getSource())[0]*this.alpha,i=c[1]*this.alpha,s=c[2]*this.alpha;for(var d=0;d<h;d+=4)switch(r=l[d],o=l[d+1],a=l[d+2],this.mode){case"multiply":l[d]=r*n/255,l[d+1]=o*i/255,l[d+2]=a*s/255;break;case"screen":l[d]=255-(255-r)*(255-n)/255,l[d+1]=255-(255-o)*(255-i)/255,l[d+2]=255-(255-a)*(255-s)/255;break;case"add":l[d]=r+n,l[d+1]=o+i,l[d+2]=a+s;break;case"diff":case"difference":l[d]=Math.abs(r-n),l[d+1]=Math.abs(o-i),l[d+2]=Math.abs(a-s);break;case"subtract":l[d]=r-n,l[d+1]=o-i,l[d+2]=a-s;break;case"darken":l[d]=Math.min(r,n),l[d+1]=Math.min(o,i),l[d+2]=Math.min(a,s);break;case"lighten":l[d]=Math.max(r,n),l[d+1]=Math.max(o,i),l[d+2]=Math.max(a,s);break;case"overlay":l[d]=n<128?2*r*n/255:255-2*(255-r)*(255-n)/255,l[d+1]=i<128?2*o*i/255:255-2*(255-o)*(255-i)/255,l[d+2]=s<128?2*a*s/255:255-2*(255-a)*(255-s)/255;break;case"exclusion":l[d]=n+r-2*n*r/255,l[d+1]=i+o-2*i*o/255,l[d+2]=s+a-2*s*a/255;break;case"tint":l[d]=n+r*u,l[d+1]=i+o*u,l[d+2]=s+a*u}},getUniformLocations:function(t,e){return{uColor:t.getUniformLocation(e,"uColor")}},sendUniformData:function(t,n){var i=new e.Color(this.color).getSource();i[0]=this.alpha*i[0]/255,i[1]=this.alpha*i[1]/255,i[2]=this.alpha*i[2]/255,i[3]=this.alpha,t.uniform4fv(n.uColor,i)},toObject:function(){return{type:this.type,color:this.color,mode:this.mode,alpha:this.alpha}}}),e.Image.filters.BlendColor.fromObject=e.Image.filters.BaseFilter.fromObject}(e),function(t){var e=t.fabric,n=e.Image.filters,i=e.util.createClass;n.BlendImage=i(n.BaseFilter,{type:"BlendImage",image:null,mode:"multiply",alpha:1,vertexSource:"attribute vec2 aPosition;\nvarying vec2 vTexCoord;\nvarying vec2 vTexCoord2;\nuniform mat3 uTransformMatrix;\nvoid main() {\nvTexCoord = aPosition;\nvTexCoord2 = (uTransformMatrix * vec3(aPosition, 1.0)).xy;\ngl_Position = vec4(aPosition * 2.0 - 1.0, 0.0, 1.0);\n}",fragmentSource:{multiply:"precision highp float;\nuniform sampler2D uTexture;\nuniform sampler2D uImage;\nuniform vec4 uColor;\nvarying vec2 vTexCoord;\nvarying vec2 vTexCoord2;\nvoid main() {\nvec4 color = texture2D(uTexture, vTexCoord);\nvec4 color2 = texture2D(uImage, vTexCoord2);\ncolor.rgba *= color2.rgba;\ngl_FragColor = color;\n}",mask:"precision highp float;\nuniform sampler2D uTexture;\nuniform sampler2D uImage;\nuniform vec4 uColor;\nvarying vec2 vTexCoord;\nvarying vec2 vTexCoord2;\nvoid main() {\nvec4 color = texture2D(uTexture, vTexCoord);\nvec4 color2 = texture2D(uImage, vTexCoord2);\ncolor.a = color2.a;\ngl_FragColor = color;\n}"},retrieveShader:function(t){var e=this.type+"_"+this.mode,n=this.fragmentSource[this.mode];return t.programCache.hasOwnProperty(e)||(t.programCache[e]=this.createProgram(t.context,n)),t.programCache[e]},applyToWebGL:function(t){var e=t.context,n=this.createTexture(t.filterBackend,this.image);this.bindAdditionalTexture(e,n,e.TEXTURE1),this.callSuper("applyToWebGL",t),this.unbindAdditionalTexture(e,e.TEXTURE1)},createTexture:function(t,e){return t.getCachedTexture(e.cacheKey,e._element)},calculateMatrix:function(){var t=this.image,e=t._element.width,n=t._element.height;return[1/t.scaleX,0,0,0,1/t.scaleY,0,-t.left/e,-t.top/n,1]},applyTo2d:function(t){var n,i,s,r,o,a,c,l,h,u,d,f=t.imageData,p=t.filterBackend.resources,m=f.data,g=m.length,v=f.width,_=f.height,y=this.image;p.blendImage||(p.blendImage=e.util.createCanvasElement()),u=(h=p.blendImage).getContext("2d"),h.width!==v||h.height!==_?(h.width=v,h.height=_):u.clearRect(0,0,v,_),u.setTransform(y.scaleX,0,0,y.scaleY,y.left,y.top),u.drawImage(y._element,0,0,v,_),d=u.getImageData(0,0,v,_).data;for(var b=0;b<g;b+=4)switch(o=m[b],a=m[b+1],c=m[b+2],l=m[b+3],n=d[b],i=d[b+1],s=d[b+2],r=d[b+3],this.mode){case"multiply":m[b]=o*n/255,m[b+1]=a*i/255,m[b+2]=c*s/255,m[b+3]=l*r/255;break;case"mask":m[b+3]=r}},getUniformLocations:function(t,e){return{uTransformMatrix:t.getUniformLocation(e,"uTransformMatrix"),uImage:t.getUniformLocation(e,"uImage")}},sendUniformData:function(t,e){var n=this.calculateMatrix();t.uniform1i(e.uImage,1),t.uniformMatrix3fv(e.uTransformMatrix,!1,n)},toObject:function(){return{type:this.type,image:this.image&&this.image.toObject(),mode:this.mode,alpha:this.alpha}}}),e.Image.filters.BlendImage.fromObject=function(t,n){e.Image.fromObject(t.image,(function(i){var s=e.util.object.clone(t);s.image=i,n(new e.Image.filters.BlendImage(s))}))}}(e),function(t){var e=t.fabric||(t.fabric={}),n=Math.pow,i=Math.floor,s=Math.sqrt,r=Math.abs,o=Math.round,a=Math.sin,c=Math.ceil,l=e.Image.filters,h=e.util.createClass;l.Resize=h(l.BaseFilter,{type:"Resize",resizeType:"hermite",scaleX:1,scaleY:1,lanczosLobes:3,getUniformLocations:function(t,e){return{uDelta:t.getUniformLocation(e,"uDelta"),uTaps:t.getUniformLocation(e,"uTaps")}},sendUniformData:function(t,e){t.uniform2fv(e.uDelta,this.horizontal?[1/this.width,0]:[0,1/this.height]),t.uniform1fv(e.uTaps,this.taps)},retrieveShader:function(t){var e=this.getFilterWindow(),n=this.type+"_"+e;if(!t.programCache.hasOwnProperty(n)){var i=this.generateShader(e);t.programCache[n]=this.createProgram(t.context,i)}return t.programCache[n]},getFilterWindow:function(){var t=this.tempScale;return Math.ceil(this.lanczosLobes/t)},getTaps:function(){for(var t=this.lanczosCreate(this.lanczosLobes),e=this.tempScale,n=this.getFilterWindow(),i=new Array(n),s=1;s<=n;s++)i[s-1]=t(s*e);return i},generateShader:function(t){for(var e=new Array(t),n=this.fragmentSourceTOP,i=1;i<=t;i++)e[i-1]=i+".0 * uDelta";return n+="uniform float uTaps["+t+"];\n",n+="void main() {\n",n+="  vec4 color = texture2D(uTexture, vTexCoord);\n",n+="  float sum = 1.0;\n",e.forEach((function(t,e){n+="  color += texture2D(uTexture, vTexCoord + "+t+") * uTaps["+e+"];\n",n+="  color += texture2D(uTexture, vTexCoord - "+t+") * uTaps["+e+"];\n",n+="  sum += 2.0 * uTaps["+e+"];\n"})),n+="  gl_FragColor = color / sum;\n",n+="}"},fragmentSourceTOP:"precision highp float;\nuniform sampler2D uTexture;\nuniform vec2 uDelta;\nvarying vec2 vTexCoord;\n",applyTo:function(t){t.webgl?(t.passes++,this.width=t.sourceWidth,this.horizontal=!0,this.dW=Math.round(this.width*this.scaleX),this.dH=t.sourceHeight,this.tempScale=this.dW/this.width,this.taps=this.getTaps(),t.destinationWidth=this.dW,this._setupFrameBuffer(t),this.applyToWebGL(t),this._swapTextures(t),t.sourceWidth=t.destinationWidth,this.height=t.sourceHeight,this.horizontal=!1,this.dH=Math.round(this.height*this.scaleY),this.tempScale=this.dH/this.height,this.taps=this.getTaps(),t.destinationHeight=this.dH,this._setupFrameBuffer(t),this.applyToWebGL(t),this._swapTextures(t),t.sourceHeight=t.destinationHeight):this.applyTo2d(t)},isNeutralState:function(){return 1===this.scaleX&&1===this.scaleY},lanczosCreate:function(t){return function(e){if(e>=t||e<=-t)return 0;if(e<1.1920929e-7&&e>-1.1920929e-7)return 1;var n=(e*=Math.PI)/t;return a(e)/e*a(n)/n}},applyTo2d:function(t){var e=t.imageData,n=this.scaleX,i=this.scaleY;this.rcpScaleX=1/n,this.rcpScaleY=1/i;var s,r=e.width,a=e.height,c=o(r*n),l=o(a*i);"sliceHack"===this.resizeType?s=this.sliceByTwo(t,r,a,c,l):"hermite"===this.resizeType?s=this.hermiteFastResize(t,r,a,c,l):"bilinear"===this.resizeType?s=this.bilinearFiltering(t,r,a,c,l):"lanczos"===this.resizeType&&(s=this.lanczosResize(t,r,a,c,l)),t.imageData=s},sliceByTwo:function(t,n,s,r,o){var a,c,l=t.imageData,h=.5,u=!1,d=!1,f=n*h,p=s*h,m=e.filterBackend.resources,g=0,v=0,_=n,y=0;for(m.sliceByTwo||(m.sliceByTwo=document.createElement("canvas")),((a=m.sliceByTwo).width<1.5*n||a.height<s)&&(a.width=1.5*n,a.height=s),(c=a.getContext("2d")).clearRect(0,0,1.5*n,s),c.putImageData(l,0,0),r=i(r),o=i(o);!u||!d;)n=f,s=p,r<i(f*h)?f=i(f*h):(f=r,u=!0),o<i(p*h)?p=i(p*h):(p=o,d=!0),c.drawImage(a,g,v,n,s,_,y,f,p),g=_,v=y,y+=p;return c.getImageData(g,v,r,o)},lanczosResize:function(t,e,o,a,l){var h=t.imageData.data,u=t.ctx.createImageData(a,l),d=u.data,f=this.lanczosCreate(this.lanczosLobes),p=this.rcpScaleX,m=this.rcpScaleY,g=2/this.rcpScaleX,v=2/this.rcpScaleY,_=c(p*this.lanczosLobes/2),y=c(m*this.lanczosLobes/2),b={},x={},C={};return function t(c){var w,S,T,M,A,O,E,k,P,I,D;for(x.x=(c+.5)*p,C.x=i(x.x),w=0;w<l;w++){for(x.y=(w+.5)*m,C.y=i(x.y),A=0,O=0,E=0,k=0,P=0,S=C.x-_;S<=C.x+_;S++)if(!(S<0||S>=e)){I=i(1e3*r(S-x.x)),b[I]||(b[I]={});for(var R=C.y-y;R<=C.y+y;R++)R<0||R>=o||(D=i(1e3*r(R-x.y)),b[I][D]||(b[I][D]=f(s(n(I*g,2)+n(D*v,2))/1e3)),(T=b[I][D])>0&&(A+=T,O+=T*h[M=4*(R*e+S)],E+=T*h[M+1],k+=T*h[M+2],P+=T*h[M+3]))}d[M=4*(w*a+c)]=O/A,d[M+1]=E/A,d[M+2]=k/A,d[M+3]=P/A}return++c<a?t(c):u}(0)},bilinearFiltering:function(t,e,n,s,r){var o,a,c,l,h,u,d,f,p,m=0,g=this.rcpScaleX,v=this.rcpScaleY,_=4*(e-1),y=t.imageData.data,b=t.ctx.createImageData(s,r),x=b.data;for(c=0;c<r;c++)for(l=0;l<s;l++)for(h=g*l-(o=i(g*l)),u=v*c-(a=i(v*c)),p=4*(a*e+o),d=0;d<4;d++)f=y[p+d]*(1-h)*(1-u)+y[p+4+d]*h*(1-u)+y[p+_+d]*u*(1-h)+y[p+_+4+d]*h*u,x[m++]=f;return b},hermiteFastResize:function(t,e,n,o,a){for(var l=this.rcpScaleX,h=this.rcpScaleY,u=c(l/2),d=c(h/2),f=t.imageData.data,p=t.ctx.createImageData(o,a),m=p.data,g=0;g<a;g++)for(var v=0;v<o;v++){for(var _=4*(v+g*o),y=0,b=0,x=0,C=0,w=0,S=0,T=0,M=(g+.5)*h,A=i(g*h);A<(g+1)*h;A++)for(var O=r(M-(A+.5))/d,E=(v+.5)*l,k=O*O,P=i(v*l);P<(v+1)*l;P++){var I=r(E-(P+.5))/u,D=s(k+I*I);D>1&&D<-1||(y=2*D*D*D-3*D*D+1)>0&&(T+=y*f[(I=4*(P+A*e))+3],x+=y,f[I+3]<255&&(y=y*f[I+3]/250),C+=y*f[I],w+=y*f[I+1],S+=y*f[I+2],b+=y)}m[_]=C/b,m[_+1]=w/b,m[_+2]=S/b,m[_+3]=T/x}return p},toObject:function(){return{type:this.type,scaleX:this.scaleX,scaleY:this.scaleY,resizeType:this.resizeType,lanczosLobes:this.lanczosLobes}}}),e.Image.filters.Resize.fromObject=e.Image.filters.BaseFilter.fromObject}(e),function(t){var e=t.fabric||(t.fabric={}),n=e.Image.filters,i=e.util.createClass;n.Contrast=i(n.BaseFilter,{type:"Contrast",fragmentSource:"precision highp float;\nuniform sampler2D uTexture;\nuniform float uContrast;\nvarying vec2 vTexCoord;\nvoid main() {\nvec4 color = texture2D(uTexture, vTexCoord);\nfloat contrastF = 1.015 * (uContrast + 1.0) / (1.0 * (1.015 - uContrast));\ncolor.rgb = contrastF * (color.rgb - 0.5) + 0.5;\ngl_FragColor = color;\n}",contrast:0,mainParameter:"contrast",applyTo2d:function(t){if(0!==this.contrast){var e,n=t.imageData.data,i=n.length,s=Math.floor(255*this.contrast),r=259*(s+255)/(255*(259-s));for(e=0;e<i;e+=4)n[e]=r*(n[e]-128)+128,n[e+1]=r*(n[e+1]-128)+128,n[e+2]=r*(n[e+2]-128)+128}},getUniformLocations:function(t,e){return{uContrast:t.getUniformLocation(e,"uContrast")}},sendUniformData:function(t,e){t.uniform1f(e.uContrast,this.contrast)}}),e.Image.filters.Contrast.fromObject=e.Image.filters.BaseFilter.fromObject}(e),function(t){var e=t.fabric||(t.fabric={}),n=e.Image.filters,i=e.util.createClass;n.Saturation=i(n.BaseFilter,{type:"Saturation",fragmentSource:"precision highp float;\nuniform sampler2D uTexture;\nuniform float uSaturation;\nvarying vec2 vTexCoord;\nvoid main() {\nvec4 color = texture2D(uTexture, vTexCoord);\nfloat rgMax = max(color.r, color.g);\nfloat rgbMax = max(rgMax, color.b);\ncolor.r += rgbMax != color.r ? (rgbMax - color.r) * uSaturation : 0.00;\ncolor.g += rgbMax != color.g ? (rgbMax - color.g) * uSaturation : 0.00;\ncolor.b += rgbMax != color.b ? (rgbMax - color.b) * uSaturation : 0.00;\ngl_FragColor = color;\n}",saturation:0,mainParameter:"saturation",applyTo2d:function(t){if(0!==this.saturation){var e,n,i=t.imageData.data,s=i.length,r=-this.saturation;for(e=0;e<s;e+=4)n=Math.max(i[e],i[e+1],i[e+2]),i[e]+=n!==i[e]?(n-i[e])*r:0,i[e+1]+=n!==i[e+1]?(n-i[e+1])*r:0,i[e+2]+=n!==i[e+2]?(n-i[e+2])*r:0}},getUniformLocations:function(t,e){return{uSaturation:t.getUniformLocation(e,"uSaturation")}},sendUniformData:function(t,e){t.uniform1f(e.uSaturation,-this.saturation)}}),e.Image.filters.Saturation.fromObject=e.Image.filters.BaseFilter.fromObject}(e),function(t){var e=t.fabric||(t.fabric={}),n=e.Image.filters,i=e.util.createClass;n.Blur=i(n.BaseFilter,{type:"Blur",fragmentSource:"precision highp float;\nuniform sampler2D uTexture;\nuniform vec2 uDelta;\nvarying vec2 vTexCoord;\nconst float nSamples = 15.0;\nvec3 v3offset = vec3(12.9898, 78.233, 151.7182);\nfloat random(vec3 scale) {\nreturn fract(sin(dot(gl_FragCoord.xyz, scale)) * 43758.5453);\n}\nvoid main() {\nvec4 color = vec4(0.0);\nfloat total = 0.0;\nfloat offset = random(v3offset);\nfor (float t = -nSamples; t <= nSamples; t++) {\nfloat percent = (t + offset - 0.5) / nSamples;\nfloat weight = 1.0 - abs(percent);\ncolor += texture2D(uTexture, vTexCoord + uDelta * percent) * weight;\ntotal += weight;\n}\ngl_FragColor = color / total;\n}",blur:0,mainParameter:"blur",applyTo:function(t){t.webgl?(this.aspectRatio=t.sourceWidth/t.sourceHeight,t.passes++,this._setupFrameBuffer(t),this.horizontal=!0,this.applyToWebGL(t),this._swapTextures(t),this._setupFrameBuffer(t),this.horizontal=!1,this.applyToWebGL(t),this._swapTextures(t)):this.applyTo2d(t)},applyTo2d:function(t){t.imageData=this.simpleBlur(t)},simpleBlur:function(t){var n,i,s=t.filterBackend.resources,r=t.imageData.width,o=t.imageData.height;s.blurLayer1||(s.blurLayer1=e.util.createCanvasElement(),s.blurLayer2=e.util.createCanvasElement()),n=s.blurLayer1,i=s.blurLayer2,n.width===r&&n.height===o||(i.width=n.width=r,i.height=n.height=o);var a,c,l,h,u=n.getContext("2d"),d=i.getContext("2d"),f=15,p=.06*this.blur*.5;for(u.putImageData(t.imageData,0,0),d.clearRect(0,0,r,o),h=-15;h<=f;h++)l=p*(c=h/f)*r+(a=(Math.random()-.5)/4),d.globalAlpha=1-Math.abs(c),d.drawImage(n,l,a),u.drawImage(i,0,0),d.globalAlpha=1,d.clearRect(0,0,i.width,i.height);for(h=-15;h<=f;h++)l=p*(c=h/f)*o+(a=(Math.random()-.5)/4),d.globalAlpha=1-Math.abs(c),d.drawImage(n,a,l),u.drawImage(i,0,0),d.globalAlpha=1,d.clearRect(0,0,i.width,i.height);t.ctx.drawImage(n,0,0);var m=t.ctx.getImageData(0,0,n.width,n.height);return u.globalAlpha=1,u.clearRect(0,0,n.width,n.height),m},getUniformLocations:function(t,e){return{delta:t.getUniformLocation(e,"uDelta")}},sendUniformData:function(t,e){var n=this.chooseRightDelta();t.uniform2fv(e.delta,n)},chooseRightDelta:function(){var t,e=1,n=[0,0];return this.horizontal?this.aspectRatio>1&&(e=1/this.aspectRatio):this.aspectRatio<1&&(e=this.aspectRatio),t=e*this.blur*.12,this.horizontal?n[0]=t:n[1]=t,n}}),n.Blur.fromObject=e.Image.filters.BaseFilter.fromObject}(e),function(t){var e=t.fabric||(t.fabric={}),n=e.Image.filters,i=e.util.createClass;n.Gamma=i(n.BaseFilter,{type:"Gamma",fragmentSource:"precision highp float;\nuniform sampler2D uTexture;\nuniform vec3 uGamma;\nvarying vec2 vTexCoord;\nvoid main() {\nvec4 color = texture2D(uTexture, vTexCoord);\nvec3 correction = (1.0 / uGamma);\ncolor.r = pow(color.r, correction.r);\ncolor.g = pow(color.g, correction.g);\ncolor.b = pow(color.b, correction.b);\ngl_FragColor = color;\ngl_FragColor.rgb *= color.a;\n}",gamma:[1,1,1],mainParameter:"gamma",initialize:function(t){this.gamma=[1,1,1],n.BaseFilter.prototype.initialize.call(this,t)},applyTo2d:function(t){var e,n=t.imageData.data,i=this.gamma,s=n.length,r=1/i[0],o=1/i[1],a=1/i[2];for(this.rVals||(this.rVals=new Uint8Array(256),this.gVals=new Uint8Array(256),this.bVals=new Uint8Array(256)),e=0,s=256;e<s;e++)this.rVals[e]=255*Math.pow(e/255,r),this.gVals[e]=255*Math.pow(e/255,o),this.bVals[e]=255*Math.pow(e/255,a);for(e=0,s=n.length;e<s;e+=4)n[e]=this.rVals[n[e]],n[e+1]=this.gVals[n[e+1]],n[e+2]=this.bVals[n[e+2]]},getUniformLocations:function(t,e){return{uGamma:t.getUniformLocation(e,"uGamma")}},sendUniformData:function(t,e){t.uniform3fv(e.uGamma,this.gamma)}}),e.Image.filters.Gamma.fromObject=e.Image.filters.BaseFilter.fromObject}(e),function(t){var e=t.fabric||(t.fabric={}),n=e.Image.filters,i=e.util.createClass;n.Composed=i(n.BaseFilter,{type:"Composed",subFilters:[],initialize:function(t){this.callSuper("initialize",t),this.subFilters=this.subFilters.slice(0)},applyTo:function(t){t.passes+=this.subFilters.length-1,this.subFilters.forEach((function(e){e.applyTo(t)}))},toObject:function(){return e.util.object.extend(this.callSuper("toObject"),{subFilters:this.subFilters.map((function(t){return t.toObject()}))})},isNeutralState:function(){return!this.subFilters.some((function(t){return!t.isNeutralState()}))}}),e.Image.filters.Composed.fromObject=function(t,n){var i=(t.subFilters||[]).map((function(t){return new e.Image.filters[t.type](t)})),s=new e.Image.filters.Composed({subFilters:i});return n&&n(s),s}}(e),function(t){var e=t.fabric||(t.fabric={}),n=e.Image.filters,i=e.util.createClass;n.HueRotation=i(n.ColorMatrix,{type:"HueRotation",rotation:0,mainParameter:"rotation",calculateMatrix:function(){var t=this.rotation*Math.PI,n=e.util.cos(t),i=e.util.sin(t),s=1/3,r=Math.sqrt(s)*i,o=1-n;this.matrix=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0],this.matrix[0]=n+o/3,this.matrix[1]=s*o-r,this.matrix[2]=s*o+r,this.matrix[5]=s*o+r,this.matrix[6]=n+s*o,this.matrix[7]=s*o-r,this.matrix[10]=s*o-r,this.matrix[11]=s*o+r,this.matrix[12]=n+s*o},isNeutralState:function(t){return this.calculateMatrix(),n.BaseFilter.prototype.isNeutralState.call(this,t)},applyTo:function(t){this.calculateMatrix(),n.BaseFilter.prototype.applyTo.call(this,t)}}),e.Image.filters.HueRotation.fromObject=e.Image.filters.BaseFilter.fromObject}(e),function(t){var e=t.fabric||(t.fabric={}),n=e.util.object.clone;if(e.Text)e.warn("fabric.Text is already defined");else{var i="fontFamily fontWeight fontSize text underline overline linethrough textAlign fontStyle lineHeight textBackgroundColor charSpacing styles path".split(" ");e.Text=e.util.createClass(e.Object,{_dimensionAffectingProps:["fontSize","fontWeight","fontFamily","fontStyle","lineHeight","text","charSpacing","textAlign","styles","path"],_reNewline:/\r?\n/,_reSpacesAndTabs:/[ \t\r]/g,_reSpaceAndTab:/[ \t\r]/,_reWords:/\S+/g,type:"text",fontSize:40,fontWeight:"normal",fontFamily:"Times New Roman",underline:!1,overline:!1,linethrough:!1,textAlign:"left",fontStyle:"normal",lineHeight:1.16,superscript:{size:.6,baseline:-.35},subscript:{size:.6,baseline:.11},textBackgroundColor:"",stateProperties:e.Object.prototype.stateProperties.concat(i),cacheProperties:e.Object.prototype.cacheProperties.concat(i),stroke:null,shadow:null,path:null,_fontSizeFraction:.222,offsets:{underline:.1,linethrough:-.315,overline:-.88},_fontSizeMult:1.13,charSpacing:0,styles:null,_measuringContext:null,deltaY:0,direction:"ltr",_styleProperties:["stroke","strokeWidth","fill","fontFamily","fontSize","fontWeight","fontStyle","underline","overline","linethrough","deltaY","textBackgroundColor"],__charBounds:[],CACHE_FONT_SIZE:400,MIN_TEXT_WIDTH:2,initialize:function(t,e){this.styles=e&&e.styles||{},this.text=t,this.__skipDimension=!0,this.callSuper("initialize",e),this.path&&this.setPathInfo(),this.__skipDimension=!1,this.initDimensions(),this.setCoords(),this.setupState({propertySet:"_dimensionAffectingProps"})},setPathInfo:function(){var t=this.path;t&&(t.segmentsInfo=e.util.getPathSegmentsInfo(t.path))},getMeasuringContext:function(){return e._measuringContext||(e._measuringContext=this.canvas&&this.canvas.contextCache||e.util.createCanvasElement().getContext("2d")),e._measuringContext},_splitText:function(){var t=this._splitTextIntoLines(this.text);return this.textLines=t.lines,this._textLines=t.graphemeLines,this._unwrappedTextLines=t._unwrappedLines,this._text=t.graphemeText,t},initDimensions:function(){this.__skipDimension||(this._splitText(),this._clearCache(),this.path?(this.width=this.path.width,this.height=this.path.height):(this.width=this.calcTextWidth()||this.cursorWidth||this.MIN_TEXT_WIDTH,this.height=this.calcTextHeight()),-1!==this.textAlign.indexOf("justify")&&this.enlargeSpaces(),this.saveState({propertySet:"_dimensionAffectingProps"}))},enlargeSpaces:function(){for(var t,e,n,i,s,r,o,a=0,c=this._textLines.length;a<c;a++)if(("justify"===this.textAlign||a!==c-1&&!this.isEndOfWrapping(a))&&(i=0,s=this._textLines[a],(e=this.getLineWidth(a))<this.width&&(o=this.textLines[a].match(this._reSpacesAndTabs)))){n=o.length,t=(this.width-e)/n;for(var l=0,h=s.length;l<=h;l++)r=this.__charBounds[a][l],this._reSpaceAndTab.test(s[l])?(r.width+=t,r.kernedWidth+=t,r.left+=i,i+=t):r.left+=i}},isEndOfWrapping:function(t){return t===this._textLines.length-1},missingNewlineOffset:function(){return 1},toString:function(){return"#<fabric.Text ("+this.complexity()+'): { "text": "'+this.text+'", "fontFamily": "'+this.fontFamily+'" }>'},_getCacheCanvasDimensions:function(){var t=this.callSuper("_getCacheCanvasDimensions"),e=this.fontSize;return t.width+=e*t.zoomX,t.height+=e*t.zoomY,t},_render:function(t){this._setTextStyles(t),this._renderTextLinesBackground(t),this._renderTextDecoration(t,"underline"),this._renderText(t),this._renderTextDecoration(t,"overline"),this._renderTextDecoration(t,"linethrough")},_renderText:function(t){"stroke"===this.paintFirst?(this._renderTextStroke(t),this._renderTextFill(t)):(this._renderTextFill(t),this._renderTextStroke(t))},_setTextStyles:function(t,e,n){t.textBaseline="alphabetic",t.font=this._getFontDeclaration(e,n)},calcTextWidth:function(){for(var t=this.getLineWidth(0),e=1,n=this._textLines.length;e<n;e++){var i=this.getLineWidth(e);i>t&&(t=i)}return t},_renderTextLine:function(t,e,n,i,s,r){this._renderChars(t,e,n,i,s,r)},_renderTextLinesBackground:function(t){if(this.textBackgroundColor||this.styleHas("textBackgroundColor")){for(var e,n,i,s,r,o,a,c=t.fillStyle,l=this._getLeftOffset(),h=this._getTopOffset(),u=0,d=0,f=this.path,p=0,m=this._textLines.length;p<m;p++)if(e=this.getHeightOfLine(p),this.textBackgroundColor||this.styleHas("textBackgroundColor",p)){i=this._textLines[p],n=this._getLineLeftOffset(p),d=0,u=0,s=this.getValueOfPropertyAt(p,0,"textBackgroundColor");for(var g=0,v=i.length;g<v;g++)r=this.__charBounds[p][g],o=this.getValueOfPropertyAt(p,g,"textBackgroundColor"),f?(t.save(),t.translate(r.renderLeft,r.renderTop),t.rotate(r.angle),t.fillStyle=o,o&&t.fillRect(-r.width/2,-e/this.lineHeight*(1-this._fontSizeFraction),r.width,e/this.lineHeight),t.restore()):o!==s?(a=l+n+u,"rtl"===this.direction&&(a=this.width-a-d),t.fillStyle=s,s&&t.fillRect(a,h,d,e/this.lineHeight),u=r.left,d=r.width,s=o):d+=r.kernedWidth;o&&!f&&(a=l+n+u,"rtl"===this.direction&&(a=this.width-a-d),t.fillStyle=o,t.fillRect(a,h,d,e/this.lineHeight)),h+=e}else h+=e;t.fillStyle=c,this._removeShadow(t)}},getFontCache:function(t){var n=t.fontFamily.toLowerCase();e.charWidthsCache[n]||(e.charWidthsCache[n]={});var i=e.charWidthsCache[n],s=t.fontStyle.toLowerCase()+"_"+(t.fontWeight+"").toLowerCase();return i[s]||(i[s]={}),i[s]},_measureChar:function(t,e,n,i){var s,r,o,a,c=this.getFontCache(e),l=n+t,h=this._getFontDeclaration(e)===this._getFontDeclaration(i),u=e.fontSize/this.CACHE_FONT_SIZE;if(n&&void 0!==c[n]&&(o=c[n]),void 0!==c[t]&&(a=s=c[t]),h&&void 0!==c[l]&&(a=(r=c[l])-o),void 0===s||void 0===o||void 0===r){var d=this.getMeasuringContext();this._setTextStyles(d,e,!0)}return void 0===s&&(a=s=d.measureText(t).width,c[t]=s),void 0===o&&h&&n&&(o=d.measureText(n).width,c[n]=o),h&&void 0===r&&(r=d.measureText(l).width,c[l]=r,a=r-o),{width:s*u,kernedWidth:a*u}},getHeightOfChar:function(t,e){return this.getValueOfPropertyAt(t,e,"fontSize")},measureLine:function(t){var e=this._measureLine(t);return 0!==this.charSpacing&&(e.width-=this._getWidthOfCharSpacing()),e.width<0&&(e.width=0),e},_measureLine:function(t){var n,i,s,r,o,a,c=0,l=this._textLines[t],h=new Array(l.length),u=0,d=this.path;for(this.__charBounds[t]=h,d&&(o=e.util.getPointOnPath(d.path,0,d.segmentsInfo),a=d.segmentsInfo[d.segmentsInfo.length-1].length,o.x+=d.pathOffset.x,o.y+=d.pathOffset.y),n=0;n<l.length;n++)i=l[n],r=this._getGraphemeBox(i,t,n,s),d&&(u>a&&(u%=a),this._setGraphemeOnPath(u,r,o)),h[n]=r,c+=r.kernedWidth,u+=r.kernedWidth,s=i;return h[n]={left:r?r.left+r.width:0,width:0,kernedWidth:0,height:this.fontSize},{width:c,numOfSpaces:0}},_setGraphemeOnPath:function(t,n,i){var s=t+n.kernedWidth/2,r=this.path,o=e.util.getPointOnPath(r.path,s,r.segmentsInfo);n.renderLeft=o.x-i.x,n.renderTop=o.y-i.y,n.angle=o.angle},_getGraphemeBox:function(t,e,n,i,s){var r,o=this.getCompleteStyleDeclaration(e,n),a=i?this.getCompleteStyleDeclaration(e,n-1):{},c=this._measureChar(t,o,i,a),l=c.kernedWidth,h=c.width;0!==this.charSpacing&&(h+=r=this._getWidthOfCharSpacing(),l+=r);var u={width:h,left:0,height:o.fontSize,kernedWidth:l,deltaY:o.deltaY};if(n>0&&!s){var d=this.__charBounds[e][n-1];u.left=d.left+d.width+c.kernedWidth-c.width}return u},getHeightOfLine:function(t){if(this.__lineHeights[t])return this.__lineHeights[t];for(var e=this._textLines[t],n=this.getHeightOfChar(t,0),i=1,s=e.length;i<s;i++)n=Math.max(this.getHeightOfChar(t,i),n);return this.__lineHeights[t]=n*this.lineHeight*this._fontSizeMult},calcTextHeight:function(){for(var t,e=0,n=0,i=this._textLines.length;n<i;n++)t=this.getHeightOfLine(n),e+=n===i-1?t/this.lineHeight:t;return e},_getLeftOffset:function(){return"ltr"===this.direction?-this.width/2:this.width/2},_getTopOffset:function(){return-this.height/2},_renderTextCommon:function(t,e){t.save();for(var n=0,i=this._getLeftOffset(),s=this._getTopOffset(),r=0,o=this._textLines.length;r<o;r++){var a=this.getHeightOfLine(r),c=a/this.lineHeight,l=this._getLineLeftOffset(r);this._renderTextLine(e,t,this._textLines[r],i+l,s+n+c,r),n+=a}t.restore()},_renderTextFill:function(t){(this.fill||this.styleHas("fill"))&&this._renderTextCommon(t,"fillText")},_renderTextStroke:function(t){(this.stroke&&0!==this.strokeWidth||!this.isEmptyStyles())&&(this.shadow&&!this.shadow.affectStroke&&this._removeShadow(t),t.save(),this._setLineDash(t,this.strokeDashArray),t.beginPath(),this._renderTextCommon(t,"strokeText"),t.closePath(),t.restore())},_renderChars:function(t,e,n,i,s,r){var o,a,c,l,h,u=this.getHeightOfLine(r),d=-1!==this.textAlign.indexOf("justify"),f="",p=0,m=this.path,g=!d&&0===this.charSpacing&&this.isEmptyStyles(r)&&!m,v="ltr"===this.direction,_="ltr"===this.direction?1:-1;if(e.save(),s-=u*this._fontSizeFraction/this.lineHeight,g)return e.canvas.setAttribute("dir",v?"ltr":"rtl"),e.direction=v?"ltr":"rtl",this._renderChar(t,e,r,0,n.join(""),i,s,u),void e.restore();for(var y=0,b=n.length-1;y<=b;y++)l=y===b||this.charSpacing||m,f+=n[y],c=this.__charBounds[r][y],0===p?(i+=_*(c.kernedWidth-c.width),p+=c.width):p+=c.kernedWidth,d&&!l&&this._reSpaceAndTab.test(n[y])&&(l=!0),l||(o=o||this.getCompleteStyleDeclaration(r,y),a=this.getCompleteStyleDeclaration(r,y+1),l=this._hasStyleChanged(o,a)),l&&(m?(e.save(),e.translate(c.renderLeft,c.renderTop),e.rotate(c.angle),this._renderChar(t,e,r,y,f,-p/2,0,u),e.restore()):(h=i,e.canvas.setAttribute("dir",v?"ltr":"rtl"),e.direction=v?"ltr":"rtl",this._renderChar(t,e,r,y,f,h,s,u)),f="",o=a,i+=_*p,p=0);e.restore()},_applyPatternGradientTransformText:function(t){var n,i=e.util.createCanvasElement(),s=this.width+this.strokeWidth,r=this.height+this.strokeWidth;return i.width=s,i.height=r,(n=i.getContext("2d")).beginPath(),n.moveTo(0,0),n.lineTo(s,0),n.lineTo(s,r),n.lineTo(0,r),n.closePath(),n.translate(s/2,r/2),n.fillStyle=t.toLive(n),this._applyPatternGradientTransform(n,t),n.fill(),n.createPattern(i,"no-repeat")},handleFiller:function(t,e,n){var i,s;return n.toLive?"percentage"===n.gradientUnits||n.gradientTrasnform||n.patternTransform?(i=-this.width/2,s=-this.height/2,t.translate(i,s),t[e]=this._applyPatternGradientTransformText(n),{offsetX:i,offsetY:s}):(t[e]=n.toLive(t,this),this._applyPatternGradientTransform(t,n)):(t[e]=n,{offsetX:0,offsetY:0})},_setStrokeStyles:function(t,e){return t.lineWidth=e.strokeWidth,t.lineCap=this.strokeLineCap,t.lineDashOffset=this.strokeDashOffset,t.lineJoin=this.strokeLineJoin,t.miterLimit=this.strokeMiterLimit,this.handleFiller(t,"strokeStyle",e.stroke)},_setFillStyles:function(t,e){return this.handleFiller(t,"fillStyle",e.fill)},_renderChar:function(t,e,n,i,s,r,o){var a,c,l=this._getStyleDeclaration(n,i),h=this.getCompleteStyleDeclaration(n,i),u="fillText"===t&&h.fill,d="strokeText"===t&&h.stroke&&h.strokeWidth;(d||u)&&(e.save(),u&&(a=this._setFillStyles(e,h)),d&&(c=this._setStrokeStyles(e,h)),e.font=this._getFontDeclaration(h),l&&l.textBackgroundColor&&this._removeShadow(e),l&&l.deltaY&&(o+=l.deltaY),u&&e.fillText(s,r-a.offsetX,o-a.offsetY),d&&e.strokeText(s,r-c.offsetX,o-c.offsetY),e.restore())},setSuperscript:function(t,e){return this._setScript(t,e,this.superscript)},setSubscript:function(t,e){return this._setScript(t,e,this.subscript)},_setScript:function(t,e,n){var i=this.get2DCursorLocation(t,!0),s=this.getValueOfPropertyAt(i.lineIndex,i.charIndex,"fontSize"),r=this.getValueOfPropertyAt(i.lineIndex,i.charIndex,"deltaY"),o={fontSize:s*n.size,deltaY:r+s*n.baseline};return this.setSelectionStyles(o,t,e),this},_hasStyleChanged:function(t,e){return t.fill!==e.fill||t.stroke!==e.stroke||t.strokeWidth!==e.strokeWidth||t.fontSize!==e.fontSize||t.fontFamily!==e.fontFamily||t.fontWeight!==e.fontWeight||t.fontStyle!==e.fontStyle||t.deltaY!==e.deltaY},_hasStyleChangedForSvg:function(t,e){return this._hasStyleChanged(t,e)||t.overline!==e.overline||t.underline!==e.underline||t.linethrough!==e.linethrough},_getLineLeftOffset:function(t){var e=this.getLineWidth(t),n=this.width-e,i=this.textAlign,s=this.direction,r=0,o=this.isEndOfWrapping(t);return"justify"===i||"justify-center"===i&&!o||"justify-right"===i&&!o||"justify-left"===i&&!o?0:("center"===i&&(r=n/2),"right"===i&&(r=n),"justify-center"===i&&(r=n/2),"justify-right"===i&&(r=n),"rtl"===s&&(r-=n),r)},_clearCache:function(){this.__lineWidths=[],this.__lineHeights=[],this.__charBounds=[]},_shouldClearDimensionCache:function(){var t=this._forceClearCache;return t||(t=this.hasStateChanged("_dimensionAffectingProps")),t&&(this.dirty=!0,this._forceClearCache=!1),t},getLineWidth:function(t){return this.__lineWidths[t]?this.__lineWidths[t]:(e=""===this._textLines[t]?0:this.measureLine(t).width,this.__lineWidths[t]=e,e);var e},_getWidthOfCharSpacing:function(){return 0!==this.charSpacing?this.fontSize*this.charSpacing/1e3:0},getValueOfPropertyAt:function(t,e,n){var i=this._getStyleDeclaration(t,e);return i&&void 0!==i[n]?i[n]:this[n]},_renderTextDecoration:function(t,e){if(this[e]||this.styleHas(e)){for(var n,i,s,r,o,a,c,l,h,u,d,f,p,m,g,v,_=this._getLeftOffset(),y=this._getTopOffset(),b=this.path,x=this._getWidthOfCharSpacing(),C=0,w=this._textLines.length;C<w;C++)if(n=this.getHeightOfLine(C),this[e]||this.styleHas(e,C)){c=this._textLines[C],m=n/this.lineHeight,r=this._getLineLeftOffset(C),u=0,d=0,l=this.getValueOfPropertyAt(C,0,e),v=this.getValueOfPropertyAt(C,0,"fill"),h=y+m*(1-this._fontSizeFraction),i=this.getHeightOfChar(C,0),o=this.getValueOfPropertyAt(C,0,"deltaY");for(var S=0,T=c.length;S<T;S++)if(f=this.__charBounds[C][S],p=this.getValueOfPropertyAt(C,S,e),g=this.getValueOfPropertyAt(C,S,"fill"),s=this.getHeightOfChar(C,S),a=this.getValueOfPropertyAt(C,S,"deltaY"),b&&p&&g)t.save(),t.fillStyle=v,t.translate(f.renderLeft,f.renderTop),t.rotate(f.angle),t.fillRect(-f.kernedWidth/2,this.offsets[e]*s+a,f.kernedWidth,this.fontSize/15),t.restore();else if((p!==l||g!==v||s!==i||a!==o)&&d>0){var M=_+r+u;"rtl"===this.direction&&(M=this.width-M-d),l&&v&&(t.fillStyle=v,t.fillRect(M,h+this.offsets[e]*i+o,d,this.fontSize/15)),u=f.left,d=f.width,l=p,v=g,i=s,o=a}else d+=f.kernedWidth;t.fillStyle=g,p&&g&&t.fillRect(_+r+u,h+this.offsets[e]*i+o,d-x,this.fontSize/15),y+=n}else y+=n;this._removeShadow(t)}},_getFontDeclaration:function(t,n){var i=t||this,s=this.fontFamily,r=e.Text.genericFonts.indexOf(s.toLowerCase())>-1,o=void 0===s||s.indexOf("'")>-1||s.indexOf(",")>-1||s.indexOf('"')>-1||r?i.fontFamily:'"'+i.fontFamily+'"';return[e.isLikelyNode?i.fontWeight:i.fontStyle,e.isLikelyNode?i.fontStyle:i.fontWeight,n?this.CACHE_FONT_SIZE+"px":i.fontSize+"px",o].join(" ")},render:function(t){this.visible&&(this.canvas&&this.canvas.skipOffscreen&&!this.group&&!this.isOnScreen()||(this._shouldClearDimensionCache()&&this.initDimensions(),this.callSuper("render",t)))},_splitTextIntoLines:function(t){for(var n=t.split(this._reNewline),i=new Array(n.length),s=["\n"],r=[],o=0;o<n.length;o++)i[o]=e.util.string.graphemeSplit(n[o]),r=r.concat(i[o],s);return r.pop(),{_unwrappedLines:i,lines:n,graphemeText:r,graphemeLines:i}},toObject:function(t){var e=["text","fontSize","fontWeight","fontFamily","fontStyle","lineHeight","underline","overline","linethrough","textAlign","textBackgroundColor","charSpacing","path","direction"].concat(t),i=this.callSuper("toObject",e);return i.styles=n(this.styles,!0),i.path=this.path&&this.path.toObject(),i},set:function(t,e){this.callSuper("set",t,e);var n=!1,i=!1;if("object"==typeof t)for(var s in t)"path"===s&&this.setPathInfo(),n=n||-1!==this._dimensionAffectingProps.indexOf(s),i=i||"path"===s;else n=-1!==this._dimensionAffectingProps.indexOf(t),i="path"===t;return i&&this.setPathInfo(),n&&(this.initDimensions(),this.setCoords()),this},complexity:function(){return 1}}),e.Text.ATTRIBUTE_NAMES=e.SHARED_ATTRIBUTES.concat("x y dx dy font-family font-style font-weight font-size letter-spacing text-decoration text-anchor".split(" ")),e.Text.DEFAULT_SVG_FONT_SIZE=16,e.Text.fromElement=function(t,i,s){if(!t)return i(null);var r=e.parseAttributes(t,e.Text.ATTRIBUTE_NAMES),o=r.textAnchor||"left";if((s=e.util.object.extend(s?n(s):{},r)).top=s.top||0,s.left=s.left||0,r.textDecoration){var a=r.textDecoration;-1!==a.indexOf("underline")&&(s.underline=!0),-1!==a.indexOf("overline")&&(s.overline=!0),-1!==a.indexOf("line-through")&&(s.linethrough=!0),delete s.textDecoration}"dx"in r&&(s.left+=r.dx),"dy"in r&&(s.top+=r.dy),"fontSize"in s||(s.fontSize=e.Text.DEFAULT_SVG_FONT_SIZE);var c="";"textContent"in t?c=t.textContent:"firstChild"in t&&null!==t.firstChild&&"data"in t.firstChild&&null!==t.firstChild.data&&(c=t.firstChild.data),c=c.replace(/^\s+|\s+$|\n+/g,"").replace(/\s+/g," ");var l=s.strokeWidth;s.strokeWidth=0;var h=new e.Text(c,s),u=h.getScaledHeight()/h.height,d=((h.height+h.strokeWidth)*h.lineHeight-h.height)*u,f=h.getScaledHeight()+d,p=0;"center"===o&&(p=h.getScaledWidth()/2),"right"===o&&(p=h.getScaledWidth()),h.set({left:h.left-p,top:h.top-(f-h.fontSize*(.07+h._fontSizeFraction))/h.lineHeight,strokeWidth:void 0!==l?l:1}),i(h)},e.Text.fromObject=function(t,i){var s=n(t),r=t.path;return delete s.path,e.Object._fromObject("Text",s,(function(t){r?e.Object._fromObject("Path",r,(function(e){t.set("path",e),i(t)}),"path"):i(t)}),"text")},e.Text.genericFonts=["sans-serif","serif","cursive","fantasy","monospace"],e.util.createAccessors&&e.util.createAccessors(e.Text)}}(e),v.util.object.extend(v.Text.prototype,{isEmptyStyles:function(t){if(!this.styles)return!0;if(void 0!==t&&!this.styles[t])return!0;var e=void 0===t?this.styles:{line:this.styles[t]};for(var n in e)for(var i in e[n])for(var s in e[n][i])return!1;return!0},styleHas:function(t,e){if(!this.styles||!t||""===t)return!1;if(void 0!==e&&!this.styles[e])return!1;var n=void 0===e?this.styles:{0:this.styles[e]};for(var i in n)for(var s in n[i])if(void 0!==n[i][s][t])return!0;return!1},cleanStyle:function(t){if(!this.styles||!t||""===t)return!1;var e,n,i=this.styles,s=0,r=!0,o=0;for(var a in i){for(var c in e=0,i[a]){var l;s++,(l=i[a][c]).hasOwnProperty(t)?(n?l[t]!==n&&(r=!1):n=l[t],l[t]===this[t]&&delete l[t]):r=!1,0!==Object.keys(l).length?e++:delete i[a][c]}0===e&&delete i[a]}for(var h=0;h<this._textLines.length;h++)o+=this._textLines[h].length;r&&s===o&&(this[t]=n,this.removeStyle(t))},removeStyle:function(t){if(this.styles&&t&&""!==t){var e,n,i,s=this.styles;for(n in s){for(i in e=s[n])delete e[i][t],0===Object.keys(e[i]).length&&delete e[i];0===Object.keys(e).length&&delete s[n]}}},_extendStyles:function(t,e){var n=this.get2DCursorLocation(t);this._getLineStyle(n.lineIndex)||this._setLineStyle(n.lineIndex),this._getStyleDeclaration(n.lineIndex,n.charIndex)||this._setStyleDeclaration(n.lineIndex,n.charIndex,{}),v.util.object.extend(this._getStyleDeclaration(n.lineIndex,n.charIndex),e)},get2DCursorLocation:function(t,e){void 0===t&&(t=this.selectionStart);for(var n=e?this._unwrappedTextLines:this._textLines,i=n.length,s=0;s<i;s++){if(t<=n[s].length)return{lineIndex:s,charIndex:t};t-=n[s].length+this.missingNewlineOffset(s)}return{lineIndex:s-1,charIndex:n[s-1].length<t?n[s-1].length:t}},getSelectionStyles:function(t,e,n){void 0===t&&(t=this.selectionStart||0),void 0===e&&(e=this.selectionEnd||t);for(var i=[],s=t;s<e;s++)i.push(this.getStyleAtPosition(s,n));return i},getStyleAtPosition:function(t,e){var n=this.get2DCursorLocation(t);return(e?this.getCompleteStyleDeclaration(n.lineIndex,n.charIndex):this._getStyleDeclaration(n.lineIndex,n.charIndex))||{}},setSelectionStyles:function(t,e,n){void 0===e&&(e=this.selectionStart||0),void 0===n&&(n=this.selectionEnd||e);for(var i=e;i<n;i++)this._extendStyles(i,t);return this._forceClearCache=!0,this},_getStyleDeclaration:function(t,e){var n=this.styles&&this.styles[t];return n?n[e]:null},getCompleteStyleDeclaration:function(t,e){for(var n,i=this._getStyleDeclaration(t,e)||{},s={},r=0;r<this._styleProperties.length;r++)s[n=this._styleProperties[r]]=void 0===i[n]?this[n]:i[n];return s},_setStyleDeclaration:function(t,e,n){this.styles[t][e]=n},_deleteStyleDeclaration:function(t,e){delete this.styles[t][e]},_getLineStyle:function(t){return!!this.styles[t]},_setLineStyle:function(t){this.styles[t]={}},_deleteLineStyle:function(t){delete this.styles[t]}}),function(){function t(t){t.textDecoration&&(t.textDecoration.indexOf("underline")>-1&&(t.underline=!0),t.textDecoration.indexOf("line-through")>-1&&(t.linethrough=!0),t.textDecoration.indexOf("overline")>-1&&(t.overline=!0),delete t.textDecoration)}v.IText=v.util.createClass(v.Text,v.Observable,{type:"i-text",selectionStart:0,selectionEnd:0,selectionColor:"rgba(17,119,255,0.3)",isEditing:!1,editable:!0,editingBorderColor:"rgba(102,153,255,0.25)",cursorWidth:2,cursorColor:"",cursorDelay:1e3,cursorDuration:600,caching:!0,_reSpace:/\s|\n/,_currentCursorOpacity:0,_selectionDirection:null,_abortCursorAnimation:!1,__widthOfSpace:[],inCompositionMode:!1,initialize:function(t,e){this.callSuper("initialize",t,e),this.initBehavior()},setSelectionStart:function(t){t=Math.max(t,0),this._updateAndFire("selectionStart",t)},setSelectionEnd:function(t){t=Math.min(t,this.text.length),this._updateAndFire("selectionEnd",t)},_updateAndFire:function(t,e){this[t]!==e&&(this._fireSelectionChanged(),this[t]=e),this._updateTextarea()},_fireSelectionChanged:function(){this.fire("selection:changed"),this.canvas&&this.canvas.fire("text:selection:changed",{target:this})},initDimensions:function(){this.isEditing&&this.initDelayedCursor(),this.clearContextTop(),this.callSuper("initDimensions")},render:function(t){this.clearContextTop(),this.callSuper("render",t),this.cursorOffsetCache={},this.renderCursorOrSelection()},_render:function(t){this.callSuper("_render",t)},clearContextTop:function(t){if(this.isEditing&&this.canvas&&this.canvas.contextTop){var e=this.canvas.contextTop,n=this.canvas.viewportTransform;e.save(),e.transform(n[0],n[1],n[2],n[3],n[4],n[5]),this.transform(e),this._clearTextArea(e),t||e.restore()}},renderCursorOrSelection:function(){if(this.isEditing&&this.canvas&&this.canvas.contextTop){var t=this._getCursorBoundaries(),e=this.canvas.contextTop;this.clearContextTop(!0),this.selectionStart===this.selectionEnd?this.renderCursor(t,e):this.renderSelection(t,e),e.restore()}},_clearTextArea:function(t){var e=this.width+4,n=this.height+4;t.clearRect(-e/2,-n/2,e,n)},_getCursorBoundaries:function(t){void 0===t&&(t=this.selectionStart);var e=this._getLeftOffset(),n=this._getTopOffset(),i=this._getCursorBoundariesOffsets(t);return{left:e,top:n,leftOffset:i.left,topOffset:i.top}},_getCursorBoundariesOffsets:function(t){if(this.cursorOffsetCache&&"top"in this.cursorOffsetCache)return this.cursorOffsetCache;var e,n,i,s,r=0,o=0,a=this.get2DCursorLocation(t);i=a.charIndex,n=a.lineIndex;for(var c=0;c<n;c++)r+=this.getHeightOfLine(c);e=this._getLineLeftOffset(n);var l=this.__charBounds[n][i];return l&&(o=l.left),0!==this.charSpacing&&i===this._textLines[n].length&&(o-=this._getWidthOfCharSpacing()),s={top:r,left:e+(o>0?o:0)},"rtl"===this.direction&&(s.left*=-1),this.cursorOffsetCache=s,this.cursorOffsetCache},renderCursor:function(t,e){var n=this.get2DCursorLocation(),i=n.lineIndex,s=n.charIndex>0?n.charIndex-1:0,r=this.getValueOfPropertyAt(i,s,"fontSize"),o=this.scaleX*this.canvas.getZoom(),a=this.cursorWidth/o,c=t.topOffset,l=this.getValueOfPropertyAt(i,s,"deltaY");c+=(1-this._fontSizeFraction)*this.getHeightOfLine(i)/this.lineHeight-r*(1-this._fontSizeFraction),this.inCompositionMode&&this.renderSelection(t,e),e.fillStyle=this.cursorColor||this.getValueOfPropertyAt(i,s,"fill"),e.globalAlpha=this.__isMousedown?1:this._currentCursorOpacity,e.fillRect(t.left+t.leftOffset-a/2,c+t.top+l,a,r)},renderSelection:function(t,e){for(var n=this.inCompositionMode?this.hiddenTextarea.selectionStart:this.selectionStart,i=this.inCompositionMode?this.hiddenTextarea.selectionEnd:this.selectionEnd,s=-1!==this.textAlign.indexOf("justify"),r=this.get2DCursorLocation(n),o=this.get2DCursorLocation(i),a=r.lineIndex,c=o.lineIndex,l=r.charIndex<0?0:r.charIndex,h=o.charIndex<0?0:o.charIndex,u=a;u<=c;u++){var d,f=this._getLineLeftOffset(u)||0,p=this.getHeightOfLine(u),m=0,g=0;if(u===a&&(m=this.__charBounds[a][l].left),u>=a&&u<c)g=s&&!this.isEndOfWrapping(u)?this.width:this.getLineWidth(u)||5;else if(u===c)if(0===h)g=this.__charBounds[c][h].left;else{var v=this._getWidthOfCharSpacing();g=this.__charBounds[c][h-1].left+this.__charBounds[c][h-1].width-v}d=p,(this.lineHeight<1||u===c&&this.lineHeight>1)&&(p/=this.lineHeight);var _=t.left+f+m,y=g-m,b=p,x=0;this.inCompositionMode?(e.fillStyle=this.compositionColor||"black",b=1,x=p):e.fillStyle=this.selectionColor,"rtl"===this.direction&&(_=this.width-_-y),e.fillRect(_,t.top+t.topOffset+x,y,b),t.topOffset+=d}},getCurrentCharFontSize:function(){var t=this._getCurrentCharIndex();return this.getValueOfPropertyAt(t.l,t.c,"fontSize")},getCurrentCharColor:function(){var t=this._getCurrentCharIndex();return this.getValueOfPropertyAt(t.l,t.c,"fill")},_getCurrentCharIndex:function(){var t=this.get2DCursorLocation(this.selectionStart,!0),e=t.charIndex>0?t.charIndex-1:0;return{l:t.lineIndex,c:e}}}),v.IText.fromObject=function(e,n){if(t(e),e.styles)for(var i in e.styles)for(var s in e.styles[i])t(e.styles[i][s]);v.Object._fromObject("IText",e,n,"text")}}(),g=v.util.object.clone,v.util.object.extend(v.IText.prototype,{initBehavior:function(){this.initAddedHandler(),this.initRemovedHandler(),this.initCursorSelectionHandlers(),this.initDoubleClickSimulation(),this.mouseMoveHandler=this.mouseMoveHandler.bind(this)},onDeselect:function(){this.isEditing&&this.exitEditing(),this.selected=!1},initAddedHandler:function(){var t=this;this.on("added",(function(){var e=t.canvas;e&&(e._hasITextHandlers||(e._hasITextHandlers=!0,t._initCanvasHandlers(e)),e._iTextInstances=e._iTextInstances||[],e._iTextInstances.push(t))}))},initRemovedHandler:function(){var t=this;this.on("removed",(function(){var e=t.canvas;e&&(e._iTextInstances=e._iTextInstances||[],v.util.removeFromArray(e._iTextInstances,t),0===e._iTextInstances.length&&(e._hasITextHandlers=!1,t._removeCanvasHandlers(e)))}))},_initCanvasHandlers:function(t){t._mouseUpITextHandler=function(){t._iTextInstances&&t._iTextInstances.forEach((function(t){t.__isMousedown=!1}))},t.on("mouse:up",t._mouseUpITextHandler)},_removeCanvasHandlers:function(t){t.off("mouse:up",t._mouseUpITextHandler)},_tick:function(){this._currentTickState=this._animateCursor(this,1,this.cursorDuration,"_onTickComplete")},_animateCursor:function(t,e,n,i){var s;return s={isAborted:!1,abort:function(){this.isAborted=!0}},t.animate("_currentCursorOpacity",e,{duration:n,onComplete:function(){s.isAborted||t[i]()},onChange:function(){t.canvas&&t.selectionStart===t.selectionEnd&&t.renderCursorOrSelection()},abort:function(){return s.isAborted}}),s},_onTickComplete:function(){var t=this;this._cursorTimeout1&&clearTimeout(this._cursorTimeout1),this._cursorTimeout1=setTimeout((function(){t._currentTickCompleteState=t._animateCursor(t,0,this.cursorDuration/2,"_tick")}),100)},initDelayedCursor:function(t){var e=this,n=t?0:this.cursorDelay;this.abortCursorAnimation(),this._currentCursorOpacity=1,this._cursorTimeout2=setTimeout((function(){e._tick()}),n)},abortCursorAnimation:function(){var t=this._currentTickState||this._currentTickCompleteState,e=this.canvas;this._currentTickState&&this._currentTickState.abort(),this._currentTickCompleteState&&this._currentTickCompleteState.abort(),clearTimeout(this._cursorTimeout1),clearTimeout(this._cursorTimeout2),this._currentCursorOpacity=0,t&&e&&e.clearContext(e.contextTop||e.contextContainer)},selectAll:function(){return this.selectionStart=0,this.selectionEnd=this._text.length,this._fireSelectionChanged(),this._updateTextarea(),this},getSelectedText:function(){return this._text.slice(this.selectionStart,this.selectionEnd).join("")},findWordBoundaryLeft:function(t){var e=0,n=t-1;if(this._reSpace.test(this._text[n]))for(;this._reSpace.test(this._text[n]);)e++,n--;for(;/\S/.test(this._text[n])&&n>-1;)e++,n--;return t-e},findWordBoundaryRight:function(t){var e=0,n=t;if(this._reSpace.test(this._text[n]))for(;this._reSpace.test(this._text[n]);)e++,n++;for(;/\S/.test(this._text[n])&&n<this._text.length;)e++,n++;return t+e},findLineBoundaryLeft:function(t){for(var e=0,n=t-1;!/\n/.test(this._text[n])&&n>-1;)e++,n--;return t-e},findLineBoundaryRight:function(t){for(var e=0,n=t;!/\n/.test(this._text[n])&&n<this._text.length;)e++,n++;return t+e},searchWordBoundary:function(t,e){for(var n=this._text,i=this._reSpace.test(n[t])?t-1:t,s=n[i],r=v.reNonWord;!r.test(s)&&i>0&&i<n.length;)s=n[i+=e];return r.test(s)&&(i+=1===e?0:1),i},selectWord:function(t){t=t||this.selectionStart;var e=this.searchWordBoundary(t,-1),n=this.searchWordBoundary(t,1);this.selectionStart=e,this.selectionEnd=n,this._fireSelectionChanged(),this._updateTextarea(),this.renderCursorOrSelection()},selectLine:function(t){t=t||this.selectionStart;var e=this.findLineBoundaryLeft(t),n=this.findLineBoundaryRight(t);return this.selectionStart=e,this.selectionEnd=n,this._fireSelectionChanged(),this._updateTextarea(),this},enterEditing:function(t){if(!this.isEditing&&this.editable)return this.canvas&&(this.canvas.calcOffset(),this.exitEditingOnOthers(this.canvas)),this.isEditing=!0,this.initHiddenTextarea(t),this.hiddenTextarea.focus(),this.hiddenTextarea.value=this.text,this._updateTextarea(),this._saveEditingProps(),this._setEditingProps(),this._textBeforeEdit=this.text,this._tick(),this.fire("editing:entered"),this._fireSelectionChanged(),this.canvas?(this.canvas.fire("text:editing:entered",{target:this}),this.initMouseMoveHandler(),this.canvas.requestRenderAll(),this):this},exitEditingOnOthers:function(t){t._iTextInstances&&t._iTextInstances.forEach((function(t){t.selected=!1,t.isEditing&&t.exitEditing()}))},initMouseMoveHandler:function(){this.canvas.on("mouse:move",this.mouseMoveHandler)},mouseMoveHandler:function(t){if(this.__isMousedown&&this.isEditing){var e=this.getSelectionStartFromPointer(t.e),n=this.selectionStart,i=this.selectionEnd;(e===this.__selectionStartOnMouseDown&&n!==i||n!==e&&i!==e)&&(e>this.__selectionStartOnMouseDown?(this.selectionStart=this.__selectionStartOnMouseDown,this.selectionEnd=e):(this.selectionStart=e,this.selectionEnd=this.__selectionStartOnMouseDown),this.selectionStart===n&&this.selectionEnd===i||(this.restartCursorIfNeeded(),this._fireSelectionChanged(),this._updateTextarea(),this.renderCursorOrSelection()))}},_setEditingProps:function(){this.hoverCursor="text",this.canvas&&(this.canvas.defaultCursor=this.canvas.moveCursor="text"),this.borderColor=this.editingBorderColor,this.hasControls=this.selectable=!1,this.lockMovementX=this.lockMovementY=!0},fromStringToGraphemeSelection:function(t,e,n){var i=n.slice(0,t),s=v.util.string.graphemeSplit(i).length;if(t===e)return{selectionStart:s,selectionEnd:s};var r=n.slice(t,e);return{selectionStart:s,selectionEnd:s+v.util.string.graphemeSplit(r).length}},fromGraphemeToStringSelection:function(t,e,n){var i=n.slice(0,t).join("").length;return t===e?{selectionStart:i,selectionEnd:i}:{selectionStart:i,selectionEnd:i+n.slice(t,e).join("").length}},_updateTextarea:function(){if(this.cursorOffsetCache={},this.hiddenTextarea){if(!this.inCompositionMode){var t=this.fromGraphemeToStringSelection(this.selectionStart,this.selectionEnd,this._text);this.hiddenTextarea.selectionStart=t.selectionStart,this.hiddenTextarea.selectionEnd=t.selectionEnd}this.updateTextareaPosition()}},updateFromTextArea:function(){if(this.hiddenTextarea){this.cursorOffsetCache={},this.text=this.hiddenTextarea.value,this._shouldClearDimensionCache()&&(this.initDimensions(),this.setCoords());var t=this.fromStringToGraphemeSelection(this.hiddenTextarea.selectionStart,this.hiddenTextarea.selectionEnd,this.hiddenTextarea.value);this.selectionEnd=this.selectionStart=t.selectionEnd,this.inCompositionMode||(this.selectionStart=t.selectionStart),this.updateTextareaPosition()}},updateTextareaPosition:function(){if(this.selectionStart===this.selectionEnd){var t=this._calcTextareaPosition();this.hiddenTextarea.style.left=t.left,this.hiddenTextarea.style.top=t.top}},_calcTextareaPosition:function(){if(!this.canvas)return{x:1,y:1};var t=this.inCompositionMode?this.compositionStart:this.selectionStart,e=this._getCursorBoundaries(t),n=this.get2DCursorLocation(t),i=n.lineIndex,s=n.charIndex,r=this.getValueOfPropertyAt(i,s,"fontSize")*this.lineHeight,o=e.leftOffset,a=this.calcTransformMatrix(),c={x:e.left+o,y:e.top+e.topOffset+r},l=this.canvas.getRetinaScaling(),h=this.canvas.upperCanvasEl,u=h.width/l,d=h.height/l,f=u-r,p=d-r,m=h.clientWidth/u,g=h.clientHeight/d;return c=v.util.transformPoint(c,a),(c=v.util.transformPoint(c,this.canvas.viewportTransform)).x*=m,c.y*=g,c.x<0&&(c.x=0),c.x>f&&(c.x=f),c.y<0&&(c.y=0),c.y>p&&(c.y=p),c.x+=this.canvas._offset.left,c.y+=this.canvas._offset.top,{left:c.x+"px",top:c.y+"px",fontSize:r+"px",charHeight:r}},_saveEditingProps:function(){this._savedProps={hasControls:this.hasControls,borderColor:this.borderColor,lockMovementX:this.lockMovementX,lockMovementY:this.lockMovementY,hoverCursor:this.hoverCursor,selectable:this.selectable,defaultCursor:this.canvas&&this.canvas.defaultCursor,moveCursor:this.canvas&&this.canvas.moveCursor}},_restoreEditingProps:function(){this._savedProps&&(this.hoverCursor=this._savedProps.hoverCursor,this.hasControls=this._savedProps.hasControls,this.borderColor=this._savedProps.borderColor,this.selectable=this._savedProps.selectable,this.lockMovementX=this._savedProps.lockMovementX,this.lockMovementY=this._savedProps.lockMovementY,this.canvas&&(this.canvas.defaultCursor=this._savedProps.defaultCursor,this.canvas.moveCursor=this._savedProps.moveCursor))},exitEditing:function(){var t=this._textBeforeEdit!==this.text,e=this.hiddenTextarea;return this.selected=!1,this.isEditing=!1,this.selectionEnd=this.selectionStart,e&&(e.blur&&e.blur(),e.parentNode&&e.parentNode.removeChild(e)),this.hiddenTextarea=null,this.abortCursorAnimation(),this._restoreEditingProps(),this._currentCursorOpacity=0,this._shouldClearDimensionCache()&&(this.initDimensions(),this.setCoords()),this.fire("editing:exited"),t&&this.fire("modified"),this.canvas&&(this.canvas.off("mouse:move",this.mouseMoveHandler),this.canvas.fire("text:editing:exited",{target:this}),t&&this.canvas.fire("object:modified",{target:this})),this},_removeExtraneousStyles:function(){for(var t in this.styles)this._textLines[t]||delete this.styles[t]},removeStyleFromTo:function(t,e){var n,i,s=this.get2DCursorLocation(t,!0),r=this.get2DCursorLocation(e,!0),o=s.lineIndex,a=s.charIndex,c=r.lineIndex,l=r.charIndex;if(o!==c){if(this.styles[o])for(n=a;n<this._unwrappedTextLines[o].length;n++)delete this.styles[o][n];if(this.styles[c])for(n=l;n<this._unwrappedTextLines[c].length;n++)(i=this.styles[c][n])&&(this.styles[o]||(this.styles[o]={}),this.styles[o][a+n-l]=i);for(n=o+1;n<=c;n++)delete this.styles[n];this.shiftLineStyles(c,o-c)}else if(this.styles[o]){i=this.styles[o];var h,u,d=l-a;for(n=a;n<l;n++)delete i[n];for(u in this.styles[o])(h=parseInt(u,10))>=l&&(i[h-d]=i[u],delete i[u])}},shiftLineStyles:function(t,e){var n=g(this.styles);for(var i in this.styles){var s=parseInt(i,10);s>t&&(this.styles[s+e]=n[s],n[s-e]||delete this.styles[s])}},restartCursorIfNeeded:function(){this._currentTickState&&!this._currentTickState.isAborted&&this._currentTickCompleteState&&!this._currentTickCompleteState.isAborted||this.initDelayedCursor()},insertNewlineStyleObject:function(t,e,n,i){var s,r={},o=!1,a=this._unwrappedTextLines[t].length===e;for(var c in n||(n=1),this.shiftLineStyles(t,n),this.styles[t]&&(s=this.styles[t][0===e?e:e-1]),this.styles[t]){var l=parseInt(c,10);l>=e&&(o=!0,r[l-e]=this.styles[t][c],a&&0===e||delete this.styles[t][c])}var h=!1;for(o&&!a&&(this.styles[t+n]=r,h=!0),h&&n--;n>0;)i&&i[n-1]?this.styles[t+n]={0:g(i[n-1])}:s?this.styles[t+n]={0:g(s)}:delete this.styles[t+n],n--;this._forceClearCache=!0},insertCharStyleObject:function(t,e,n,i){this.styles||(this.styles={});var s=this.styles[t],r=s?g(s):{};for(var o in n||(n=1),r){var a=parseInt(o,10);a>=e&&(s[a+n]=r[a],r[a-n]||delete s[a])}if(this._forceClearCache=!0,i)for(;n--;)Object.keys(i[n]).length&&(this.styles[t]||(this.styles[t]={}),this.styles[t][e+n]=g(i[n]));else if(s)for(var c=s[e?e-1:1];c&&n--;)this.styles[t][e+n]=g(c)},insertNewStyleBlock:function(t,e,n){for(var i=this.get2DCursorLocation(e,!0),s=[0],r=0,o=0;o<t.length;o++)"\n"===t[o]?s[++r]=0:s[r]++;for(s[0]>0&&(this.insertCharStyleObject(i.lineIndex,i.charIndex,s[0],n),n=n&&n.slice(s[0]+1)),r&&this.insertNewlineStyleObject(i.lineIndex,i.charIndex+s[0],r),o=1;o<r;o++)s[o]>0?this.insertCharStyleObject(i.lineIndex+o,0,s[o],n):n&&(this.styles[i.lineIndex+o][0]=n[0]),n=n&&n.slice(s[o]+1);s[o]>0&&this.insertCharStyleObject(i.lineIndex+o,0,s[o],n)},setSelectionStartEndWithShift:function(t,e,n){n<=t?(e===t?this._selectionDirection="left":"right"===this._selectionDirection&&(this._selectionDirection="left",this.selectionEnd=t),this.selectionStart=n):n>t&&n<e?"right"===this._selectionDirection?this.selectionEnd=n:this.selectionStart=n:(e===t?this._selectionDirection="right":"left"===this._selectionDirection&&(this._selectionDirection="right",this.selectionStart=e),this.selectionEnd=n)},setSelectionInBoundaries:function(){var t=this.text.length;this.selectionStart>t?this.selectionStart=t:this.selectionStart<0&&(this.selectionStart=0),this.selectionEnd>t?this.selectionEnd=t:this.selectionEnd<0&&(this.selectionEnd=0)}}),v.util.object.extend(v.IText.prototype,{initDoubleClickSimulation:function(){this.__lastClickTime=+new Date,this.__lastLastClickTime=+new Date,this.__lastPointer={},this.on("mousedown",this.onMouseDown)},onMouseDown:function(t){if(this.canvas){this.__newClickTime=+new Date;var e=t.pointer;this.isTripleClick(e)&&(this.fire("tripleclick",t),this._stopEvent(t.e)),this.__lastLastClickTime=this.__lastClickTime,this.__lastClickTime=this.__newClickTime,this.__lastPointer=e,this.__lastIsEditing=this.isEditing,this.__lastSelected=this.selected}},isTripleClick:function(t){return this.__newClickTime-this.__lastClickTime<500&&this.__lastClickTime-this.__lastLastClickTime<500&&this.__lastPointer.x===t.x&&this.__lastPointer.y===t.y},_stopEvent:function(t){t.preventDefault&&t.preventDefault(),t.stopPropagation&&t.stopPropagation()},initCursorSelectionHandlers:function(){this.initMousedownHandler(),this.initMouseupHandler(),this.initClicks()},doubleClickHandler:function(t){this.isEditing&&this.selectWord(this.getSelectionStartFromPointer(t.e))},tripleClickHandler:function(t){this.isEditing&&this.selectLine(this.getSelectionStartFromPointer(t.e))},initClicks:function(){this.on("mousedblclick",this.doubleClickHandler),this.on("tripleclick",this.tripleClickHandler)},_mouseDownHandler:function(t){!this.canvas||!this.editable||t.e.button&&1!==t.e.button||(this.__isMousedown=!0,this.selected&&(this.inCompositionMode=!1,this.setCursorByClick(t.e)),this.isEditing&&(this.__selectionStartOnMouseDown=this.selectionStart,this.selectionStart===this.selectionEnd&&this.abortCursorAnimation(),this.renderCursorOrSelection()))},_mouseDownHandlerBefore:function(t){!this.canvas||!this.editable||t.e.button&&1!==t.e.button||(this.selected=this===this.canvas._activeObject)},initMousedownHandler:function(){this.on("mousedown",this._mouseDownHandler),this.on("mousedown:before",this._mouseDownHandlerBefore)},initMouseupHandler:function(){this.on("mouseup",this.mouseUpHandler)},mouseUpHandler:function(t){if(this.__isMousedown=!1,!(!this.editable||this.group||t.transform&&t.transform.actionPerformed||t.e.button&&1!==t.e.button)){if(this.canvas){var e=this.canvas._activeObject;if(e&&e!==this)return}this.__lastSelected&&!this.__corner?(this.selected=!1,this.__lastSelected=!1,this.enterEditing(t.e),this.selectionStart===this.selectionEnd?this.initDelayedCursor(!0):this.renderCursorOrSelection()):this.selected=!0}},setCursorByClick:function(t){var e=this.getSelectionStartFromPointer(t),n=this.selectionStart,i=this.selectionEnd;t.shiftKey?this.setSelectionStartEndWithShift(n,i,e):(this.selectionStart=e,this.selectionEnd=e),this.isEditing&&(this._fireSelectionChanged(),this._updateTextarea())},getSelectionStartFromPointer:function(t){for(var e,n=this.getLocalPointer(t),i=0,s=0,r=0,o=0,a=0,c=0,l=this._textLines.length;c<l&&r<=n.y;c++)r+=this.getHeightOfLine(c)*this.scaleY,a=c,c>0&&(o+=this._textLines[c-1].length+this.missingNewlineOffset(c-1));s=this._getLineLeftOffset(a)*this.scaleX,e=this._textLines[a],"rtl"===this.direction&&(n.x=this.width*this.scaleX-n.x+s);for(var h=0,u=e.length;h<u&&(i=s,(s+=this.__charBounds[a][h].kernedWidth*this.scaleX)<=n.x);h++)o++;return this._getNewSelectionStartFromOffset(n,i,s,o,u)},_getNewSelectionStartFromOffset:function(t,e,n,i,s){var r=t.x-e,o=n-t.x,a=i+(o>r||o<0?0:1);return this.flipX&&(a=s-a),a>this._text.length&&(a=this._text.length),a}}),v.util.object.extend(v.IText.prototype,{initHiddenTextarea:function(){this.hiddenTextarea=v.document.createElement("textarea"),this.hiddenTextarea.setAttribute("autocapitalize","off"),this.hiddenTextarea.setAttribute("autocorrect","off"),this.hiddenTextarea.setAttribute("autocomplete","off"),this.hiddenTextarea.setAttribute("spellcheck","false"),this.hiddenTextarea.setAttribute("data-fabric-hiddentextarea",""),this.hiddenTextarea.setAttribute("wrap","off");var t=this._calcTextareaPosition();this.hiddenTextarea.style.cssText="position: absolute; top: "+t.top+"; left: "+t.left+"; z-index: -999; opacity: 0; width: 1px; height: 1px; font-size: 1px; paddingｰtop: "+t.fontSize+";",v.document.body.appendChild(this.hiddenTextarea),v.util.addListener(this.hiddenTextarea,"keydown",this.onKeyDown.bind(this)),v.util.addListener(this.hiddenTextarea,"keyup",this.onKeyUp.bind(this)),v.util.addListener(this.hiddenTextarea,"input",this.onInput.bind(this)),v.util.addListener(this.hiddenTextarea,"copy",this.copy.bind(this)),v.util.addListener(this.hiddenTextarea,"cut",this.copy.bind(this)),v.util.addListener(this.hiddenTextarea,"paste",this.paste.bind(this)),v.util.addListener(this.hiddenTextarea,"compositionstart",this.onCompositionStart.bind(this)),v.util.addListener(this.hiddenTextarea,"compositionupdate",this.onCompositionUpdate.bind(this)),v.util.addListener(this.hiddenTextarea,"compositionend",this.onCompositionEnd.bind(this)),!this._clickHandlerInitialized&&this.canvas&&(v.util.addListener(this.canvas.upperCanvasEl,"click",this.onClick.bind(this)),this._clickHandlerInitialized=!0)},keysMap:{9:"exitEditing",27:"exitEditing",33:"moveCursorUp",34:"moveCursorDown",35:"moveCursorRight",36:"moveCursorLeft",37:"moveCursorLeft",38:"moveCursorUp",39:"moveCursorRight",40:"moveCursorDown"},keysMapRtl:{9:"exitEditing",27:"exitEditing",33:"moveCursorUp",34:"moveCursorDown",35:"moveCursorLeft",36:"moveCursorRight",37:"moveCursorRight",38:"moveCursorUp",39:"moveCursorLeft",40:"moveCursorDown"},ctrlKeysMapUp:{67:"copy",88:"cut"},ctrlKeysMapDown:{65:"selectAll"},onClick:function(){this.hiddenTextarea&&this.hiddenTextarea.focus()},onKeyDown:function(t){if(this.isEditing){var e="rtl"===this.direction?this.keysMapRtl:this.keysMap;if(t.keyCode in e)this[e[t.keyCode]](t);else{if(!(t.keyCode in this.ctrlKeysMapDown)||!t.ctrlKey&&!t.metaKey)return;this[this.ctrlKeysMapDown[t.keyCode]](t)}t.stopImmediatePropagation(),t.preventDefault(),t.keyCode>=33&&t.keyCode<=40?(this.inCompositionMode=!1,this.clearContextTop(),this.renderCursorOrSelection()):this.canvas&&this.canvas.requestRenderAll()}},onKeyUp:function(t){!this.isEditing||this._copyDone||this.inCompositionMode?this._copyDone=!1:t.keyCode in this.ctrlKeysMapUp&&(t.ctrlKey||t.metaKey)&&(this[this.ctrlKeysMapUp[t.keyCode]](t),t.stopImmediatePropagation(),t.preventDefault(),this.canvas&&this.canvas.requestRenderAll())},onInput:function(t){var e=this.fromPaste;if(this.fromPaste=!1,t&&t.stopPropagation(),this.isEditing){var n,i,s,r,o,a=this._splitTextIntoLines(this.hiddenTextarea.value).graphemeText,c=this._text.length,l=a.length,h=l-c,u=this.selectionStart,d=this.selectionEnd,f=u!==d;if(""===this.hiddenTextarea.value)return this.styles={},this.updateFromTextArea(),this.fire("changed"),void(this.canvas&&(this.canvas.fire("text:changed",{target:this}),this.canvas.requestRenderAll()));var p=this.fromStringToGraphemeSelection(this.hiddenTextarea.selectionStart,this.hiddenTextarea.selectionEnd,this.hiddenTextarea.value),m=u>p.selectionStart;f?(n=this._text.slice(u,d),h+=d-u):l<c&&(n=m?this._text.slice(d+h,d):this._text.slice(u,u-h)),i=a.slice(p.selectionEnd-h,p.selectionEnd),n&&n.length&&(i.length&&(s=this.getSelectionStyles(u,u+1,!1),s=i.map((function(){return s[0]}))),f?(r=u,o=d):m?(r=d-n.length,o=d):(r=d,o=d+n.length),this.removeStyleFromTo(r,o)),i.length&&(e&&i.join("")===v.copiedText&&!v.disableStyleCopyPaste&&(s=v.copiedTextStyle),this.insertNewStyleBlock(i,u,s)),this.updateFromTextArea(),this.fire("changed"),this.canvas&&(this.canvas.fire("text:changed",{target:this}),this.canvas.requestRenderAll())}},onCompositionStart:function(){this.inCompositionMode=!0},onCompositionEnd:function(){this.inCompositionMode=!1},onCompositionUpdate:function(t){this.compositionStart=t.target.selectionStart,this.compositionEnd=t.target.selectionEnd,this.updateTextareaPosition()},copy:function(){this.selectionStart!==this.selectionEnd&&(v.copiedText=this.getSelectedText(),v.disableStyleCopyPaste?v.copiedTextStyle=null:v.copiedTextStyle=this.getSelectionStyles(this.selectionStart,this.selectionEnd,!0),this._copyDone=!0)},paste:function(){this.fromPaste=!0},_getClipboardData:function(t){return t&&t.clipboardData||v.window.clipboardData},_getWidthBeforeCursor:function(t,e){var n,i=this._getLineLeftOffset(t);return e>0&&(i+=(n=this.__charBounds[t][e-1]).left+n.width),i},getDownCursorOffset:function(t,e){var n=this._getSelectionForOffset(t,e),i=this.get2DCursorLocation(n),s=i.lineIndex;if(s===this._textLines.length-1||t.metaKey||34===t.keyCode)return this._text.length-n;var r=i.charIndex,o=this._getWidthBeforeCursor(s,r),a=this._getIndexOnLine(s+1,o);return this._textLines[s].slice(r).length+a+1+this.missingNewlineOffset(s)},_getSelectionForOffset:function(t,e){return t.shiftKey&&this.selectionStart!==this.selectionEnd&&e?this.selectionEnd:this.selectionStart},getUpCursorOffset:function(t,e){var n=this._getSelectionForOffset(t,e),i=this.get2DCursorLocation(n),s=i.lineIndex;if(0===s||t.metaKey||33===t.keyCode)return-n;var r=i.charIndex,o=this._getWidthBeforeCursor(s,r),a=this._getIndexOnLine(s-1,o),c=this._textLines[s].slice(0,r),l=this.missingNewlineOffset(s-1);return-this._textLines[s-1].length+a-c.length+(1-l)},_getIndexOnLine:function(t,e){for(var n,i,s=this._textLines[t],r=this._getLineLeftOffset(t),o=0,a=0,c=s.length;a<c;a++)if((r+=n=this.__charBounds[t][a].width)>e){i=!0;var l=r-n,h=r,u=Math.abs(l-e);o=Math.abs(h-e)<u?a:a-1;break}return i||(o=s.length-1),o},moveCursorDown:function(t){this.selectionStart>=this._text.length&&this.selectionEnd>=this._text.length||this._moveCursorUpOrDown("Down",t)},moveCursorUp:function(t){0===this.selectionStart&&0===this.selectionEnd||this._moveCursorUpOrDown("Up",t)},_moveCursorUpOrDown:function(t,e){var n=this["get"+t+"CursorOffset"](e,"right"===this._selectionDirection);e.shiftKey?this.moveCursorWithShift(n):this.moveCursorWithoutShift(n),0!==n&&(this.setSelectionInBoundaries(),this.abortCursorAnimation(),this._currentCursorOpacity=1,this.initDelayedCursor(),this._fireSelectionChanged(),this._updateTextarea())},moveCursorWithShift:function(t){var e="left"===this._selectionDirection?this.selectionStart+t:this.selectionEnd+t;return this.setSelectionStartEndWithShift(this.selectionStart,this.selectionEnd,e),0!==t},moveCursorWithoutShift:function(t){return t<0?(this.selectionStart+=t,this.selectionEnd=this.selectionStart):(this.selectionEnd+=t,this.selectionStart=this.selectionEnd),0!==t},moveCursorLeft:function(t){0===this.selectionStart&&0===this.selectionEnd||this._moveCursorLeftOrRight("Left",t)},_move:function(t,e,n){var i;if(t.altKey)i=this["findWordBoundary"+n](this[e]);else{if(!t.metaKey&&35!==t.keyCode&&36!==t.keyCode)return this[e]+="Left"===n?-1:1,!0;i=this["findLineBoundary"+n](this[e])}if(void 0!==typeof i&&this[e]!==i)return this[e]=i,!0},_moveLeft:function(t,e){return this._move(t,e,"Left")},_moveRight:function(t,e){return this._move(t,e,"Right")},moveCursorLeftWithoutShift:function(t){var e=!0;return this._selectionDirection="left",this.selectionEnd===this.selectionStart&&0!==this.selectionStart&&(e=this._moveLeft(t,"selectionStart")),this.selectionEnd=this.selectionStart,e},moveCursorLeftWithShift:function(t){return"right"===this._selectionDirection&&this.selectionStart!==this.selectionEnd?this._moveLeft(t,"selectionEnd"):0!==this.selectionStart?(this._selectionDirection="left",this._moveLeft(t,"selectionStart")):void 0},moveCursorRight:function(t){this.selectionStart>=this._text.length&&this.selectionEnd>=this._text.length||this._moveCursorLeftOrRight("Right",t)},_moveCursorLeftOrRight:function(t,e){var n="moveCursor"+t+"With";this._currentCursorOpacity=1,e.shiftKey?n+="Shift":n+="outShift",this[n](e)&&(this.abortCursorAnimation(),this.initDelayedCursor(),this._fireSelectionChanged(),this._updateTextarea())},moveCursorRightWithShift:function(t){return"left"===this._selectionDirection&&this.selectionStart!==this.selectionEnd?this._moveRight(t,"selectionStart"):this.selectionEnd!==this._text.length?(this._selectionDirection="right",this._moveRight(t,"selectionEnd")):void 0},moveCursorRightWithoutShift:function(t){var e=!0;return this._selectionDirection="right",this.selectionStart===this.selectionEnd?(e=this._moveRight(t,"selectionStart"),this.selectionEnd=this.selectionStart):this.selectionStart=this.selectionEnd,e},removeChars:function(t,e){void 0===e&&(e=t+1),this.removeStyleFromTo(t,e),this._text.splice(t,e-t),this.text=this._text.join(""),this.set("dirty",!0),this._shouldClearDimensionCache()&&(this.initDimensions(),this.setCoords()),this._removeExtraneousStyles()},insertChars:function(t,e,n,i){void 0===i&&(i=n),i>n&&this.removeStyleFromTo(n,i);var s=v.util.string.graphemeSplit(t);this.insertNewStyleBlock(s,n,e),this._text=[].concat(this._text.slice(0,n),s,this._text.slice(i)),this.text=this._text.join(""),this.set("dirty",!0),this._shouldClearDimensionCache()&&(this.initDimensions(),this.setCoords()),this._removeExtraneousStyles()}}),function(){var t=v.util.toFixed,e=/  +/g;v.util.object.extend(v.Text.prototype,{_toSVG:function(){var t=this._getSVGLeftTopOffsets(),e=this._getSVGTextAndBg(t.textTop,t.textLeft);return this._wrapSVGTextAndBg(e)},toSVG:function(t){return this._createBaseSVGMarkup(this._toSVG(),{reviver:t,noStyle:!0,withShadow:!0})},_getSVGLeftTopOffsets:function(){return{textLeft:-this.width/2,textTop:-this.height/2,lineTop:this.getHeightOfLine(0)}},_wrapSVGTextAndBg:function(t){var e=this.getSvgTextDecoration(this);return[t.textBgRects.join(""),'\t\t<text xml:space="preserve" ',this.fontFamily?'font-family="'+this.fontFamily.replace(/"/g,"'")+'" ':"",this.fontSize?'font-size="'+this.fontSize+'" ':"",this.fontStyle?'font-style="'+this.fontStyle+'" ':"",this.fontWeight?'font-weight="'+this.fontWeight+'" ':"",e?'text-decoration="'+e+'" ':"",'style="',this.getSvgStyles(!0),'"',this.addPaintOrder()," >",t.textSpans.join(""),"</text>\n"]},_getSVGTextAndBg:function(t,e){var n,i=[],s=[],r=t;this._setSVGBg(s);for(var o=0,a=this._textLines.length;o<a;o++)n=this._getLineLeftOffset(o),(this.textBackgroundColor||this.styleHas("textBackgroundColor",o))&&this._setSVGTextLineBg(s,o,e+n,r),this._setSVGTextLineText(i,o,e+n,r),r+=this.getHeightOfLine(o);return{textSpans:i,textBgRects:s}},_createTextCharSpan:function(n,i,s,r){var o=n!==n.trim()||n.match(e),a=this.getSvgSpanStyles(i,o),c=a?'style="'+a+'"':"",l=i.deltaY,h="",u=v.Object.NUM_FRACTION_DIGITS;return l&&(h=' dy="'+t(l,u)+'" '),['<tspan x="',t(s,u),'" y="',t(r,u),'" ',h,c,">",v.util.string.escapeXml(n),"</tspan>"].join("")},_setSVGTextLineText:function(t,e,n,i){var s,r,o,a,c,l=this.getHeightOfLine(e),h=-1!==this.textAlign.indexOf("justify"),u="",d=0,f=this._textLines[e];i+=l*(1-this._fontSizeFraction)/this.lineHeight;for(var p=0,m=f.length-1;p<=m;p++)c=p===m||this.charSpacing,u+=f[p],o=this.__charBounds[e][p],0===d?(n+=o.kernedWidth-o.width,d+=o.width):d+=o.kernedWidth,h&&!c&&this._reSpaceAndTab.test(f[p])&&(c=!0),c||(s=s||this.getCompleteStyleDeclaration(e,p),r=this.getCompleteStyleDeclaration(e,p+1),c=this._hasStyleChangedForSvg(s,r)),c&&(a=this._getStyleDeclaration(e,p)||{},t.push(this._createTextCharSpan(u,a,n,i)),u="",s=r,n+=d,d=0)},_pushTextBgRect:function(e,n,i,s,r,o){var a=v.Object.NUM_FRACTION_DIGITS;e.push("\t\t<rect ",this._getFillAttributes(n),' x="',t(i,a),'" y="',t(s,a),'" width="',t(r,a),'" height="',t(o,a),'"></rect>\n')},_setSVGTextLineBg:function(t,e,n,i){for(var s,r,o=this._textLines[e],a=this.getHeightOfLine(e)/this.lineHeight,c=0,l=0,h=this.getValueOfPropertyAt(e,0,"textBackgroundColor"),u=0,d=o.length;u<d;u++)s=this.__charBounds[e][u],(r=this.getValueOfPropertyAt(e,u,"textBackgroundColor"))!==h?(h&&this._pushTextBgRect(t,h,n+l,i,c,a),l=s.left,c=s.width,h=r):c+=s.kernedWidth;r&&this._pushTextBgRect(t,r,n+l,i,c,a)},_getFillAttributes:function(t){var e=t&&"string"==typeof t?new v.Color(t):"";return e&&e.getSource()&&1!==e.getAlpha()?'opacity="'+e.getAlpha()+'" fill="'+e.setAlpha(1).toRgb()+'"':'fill="'+t+'"'},_getSVGLineTopOffset:function(t){for(var e,n=0,i=0;i<t;i++)n+=this.getHeightOfLine(i);return e=this.getHeightOfLine(i),{lineTop:n,offset:(this._fontSizeMult-this._fontSizeFraction)*e/(this.lineHeight*this._fontSizeMult)}},getSvgStyles:function(t){return v.Object.prototype.getSvgStyles.call(this,t)+" white-space: pre;"}})}(),function(t){var e=t.fabric||(t.fabric={});e.Textbox=e.util.createClass(e.IText,e.Observable,{type:"textbox",minWidth:20,dynamicMinWidth:2,__cachedLines:null,lockScalingFlip:!0,noScaleCache:!1,_dimensionAffectingProps:e.Text.prototype._dimensionAffectingProps.concat("width"),_wordJoiners:/[ \t\r]/,splitByGrapheme:!1,initDimensions:function(){this.__skipDimension||(this.isEditing&&this.initDelayedCursor(),this.clearContextTop(),this._clearCache(),this.dynamicMinWidth=0,this._styleMap=this._generateStyleMap(this._splitText()),this.dynamicMinWidth>this.width&&this._set("width",this.dynamicMinWidth),-1!==this.textAlign.indexOf("justify")&&this.enlargeSpaces(),this.height=this.calcTextHeight(),this.saveState({propertySet:"_dimensionAffectingProps"}))},_generateStyleMap:function(t){for(var e=0,n=0,i=0,s={},r=0;r<t.graphemeLines.length;r++)"\n"===t.graphemeText[i]&&r>0?(n=0,i++,e++):!this.splitByGrapheme&&this._reSpaceAndTab.test(t.graphemeText[i])&&r>0&&(n++,i++),s[r]={line:e,offset:n},i+=t.graphemeLines[r].length,n+=t.graphemeLines[r].length;return s},styleHas:function(t,n){if(this._styleMap&&!this.isWrapping){var i=this._styleMap[n];i&&(n=i.line)}return e.Text.prototype.styleHas.call(this,t,n)},isEmptyStyles:function(t){if(!this.styles)return!0;var e,n,i=0,s=!1,r=this._styleMap[t],o=this._styleMap[t+1];for(var a in r&&(t=r.line,i=r.offset),o&&(s=o.line===t,e=o.offset),n=void 0===t?this.styles:{line:this.styles[t]})for(var c in n[a])if(c>=i&&(!s||c<e))for(var l in n[a][c])return!1;return!0},_getStyleDeclaration:function(t,e){if(this._styleMap&&!this.isWrapping){var n=this._styleMap[t];if(!n)return null;t=n.line,e=n.offset+e}return this.callSuper("_getStyleDeclaration",t,e)},_setStyleDeclaration:function(t,e,n){var i=this._styleMap[t];t=i.line,e=i.offset+e,this.styles[t][e]=n},_deleteStyleDeclaration:function(t,e){var n=this._styleMap[t];t=n.line,e=n.offset+e,delete this.styles[t][e]},_getLineStyle:function(t){var e=this._styleMap[t];return!!this.styles[e.line]},_setLineStyle:function(t){var e=this._styleMap[t];this.styles[e.line]={}},_wrapText:function(t,e){var n,i=[];for(this.isWrapping=!0,n=0;n<t.length;n++)i=i.concat(this._wrapLine(t[n],n,e));return this.isWrapping=!1,i},_measureWord:function(t,e,n){var i,s=0;n=n||0;for(var r=0,o=t.length;r<o;r++){s+=this._getGraphemeBox(t[r],e,r+n,i,true).kernedWidth,i=t[r]}return s},_wrapLine:function(t,n,i,s){var r=0,o=this.splitByGrapheme,a=[],c=[],l=o?e.util.string.graphemeSplit(t):t.split(this._wordJoiners),h="",u=0,d=o?"":" ",f=0,p=0,m=0,g=!0,v=this._getWidthOfCharSpacing();s=s||0;0===l.length&&l.push([]),i-=s;for(var _=0;_<l.length;_++)h=o?l[_]:e.util.string.graphemeSplit(l[_]),f=this._measureWord(h,n,u),u+=h.length,(r+=p+f-v)>i&&!g?(a.push(c),c=[],r=f,g=!0):r+=v,g||o||c.push(d),c=c.concat(h),p=o?0:this._measureWord([d],n,u),u++,g=!1,f>m&&(m=f);return _&&a.push(c),m+s>this.dynamicMinWidth&&(this.dynamicMinWidth=m-v+s),a},isEndOfWrapping:function(t){return!this._styleMap[t+1]||this._styleMap[t+1].line!==this._styleMap[t].line},missingNewlineOffset:function(t){return this.splitByGrapheme?this.isEndOfWrapping(t)?1:0:1},_splitTextIntoLines:function(t){for(var n=e.Text.prototype._splitTextIntoLines.call(this,t),i=this._wrapText(n.lines,this.width),s=new Array(i.length),r=0;r<i.length;r++)s[r]=i[r].join("");return n.lines=s,n.graphemeLines=i,n},getMinWidth:function(){return Math.max(this.minWidth,this.dynamicMinWidth)},_removeExtraneousStyles:function(){var t={};for(var e in this._styleMap)this._textLines[e]&&(t[this._styleMap[e].line]=1);for(var e in this.styles)t[e]||delete this.styles[e]},toObject:function(t){return this.callSuper("toObject",["minWidth","splitByGrapheme"].concat(t))}}),e.Textbox.fromObject=function(t,n){return e.Object._fromObject("Textbox",t,n,"text")}}(e),function(){var t=v.controlsUtils,e=t.scaleSkewCursorStyleHandler,n=t.scaleCursorStyleHandler,i=t.scalingEqually,s=t.scalingYOrSkewingX,r=t.scalingXOrSkewingY,o=t.scaleOrSkewActionName,a=v.Object.prototype.controls;if(a.ml=new v.Control({x:-.5,y:0,cursorStyleHandler:e,actionHandler:r,getActionName:o}),a.mr=new v.Control({x:.5,y:0,cursorStyleHandler:e,actionHandler:r,getActionName:o}),a.mb=new v.Control({x:0,y:.5,cursorStyleHandler:e,actionHandler:s,getActionName:o}),a.mt=new v.Control({x:0,y:-.5,cursorStyleHandler:e,actionHandler:s,getActionName:o}),a.tl=new v.Control({x:-.5,y:-.5,cursorStyleHandler:n,actionHandler:i}),a.tr=new v.Control({x:.5,y:-.5,cursorStyleHandler:n,actionHandler:i}),a.bl=new v.Control({x:-.5,y:.5,cursorStyleHandler:n,actionHandler:i}),a.br=new v.Control({x:.5,y:.5,cursorStyleHandler:n,actionHandler:i}),a.mtr=new v.Control({x:0,y:-.5,actionHandler:t.rotationWithSnapping,cursorStyleHandler:t.rotationStyleHandler,offsetY:-40,withConnection:!0,actionName:"rotate"}),v.Textbox){var c=v.Textbox.prototype.controls={};c.mtr=a.mtr,c.tr=a.tr,c.br=a.br,c.tl=a.tl,c.bl=a.bl,c.mt=a.mt,c.mb=a.mb,c.mr=new v.Control({x:.5,y:0,actionHandler:t.changeWidth,cursorStyleHandler:e,actionName:"resizing"}),c.ml=new v.Control({x:-.5,y:0,actionHandler:t.changeWidth,cursorStyleHandler:e,actionName:"resizing"})}}()}));const Du=mu,Ru="#fff",ju="#000",$u="rgba(0,0,0,0.5)",Lu="#444";class Fu{constructor(t,e,n,i,s,r){this.notesPressedPrevious=[],this.notesHighlightedPrevious=[],this.notesHoveredPrevious=[],this.objectKeys={},this.display=t,this.top=e,this.left=n,this.width=i,this.height=s,this.fontSize=r,this.whiteKeyWidth=i/52,this.whiteKeyHeight=s,this.blackKeyWidth=this.whiteKeyWidth/3*2,this.blackKeyHeight=this.whiteKeyHeight/3*2}getBoundaryKeys(){const t=Object.values(this.display.controller.getPadNotes()),e=Object.values(this.objectKeys),n=t[0].name,i=t[t.length-1].name;return{minKey:this.objectKeys[n]||e[0],maxKey:this.objectKeys[i]||e[e.length-1]}}createKeyboard(){let t=Du,e=du.indexOf("A"),n=0;const i=[],s=[],r=[];for(;n<52;){const o=an(`${du[e]}${t}`);if(0===o.alt){const t=this.left+n*this.whiteKeyWidth,e=new Iu.fabric.Rect({left:t,top:this.top,width:this.whiteKeyWidth,height:this.whiteKeyHeight,fill:Ru,stroke:Lu,data:{type:"white",pressed:!1,highlighted:!1,hovered:!1}});this.objectKeys[o.name]=e,i.push(e),r.push(new Iu.fabric.Textbox(o.name,{left:t,top:this.top+this.whiteKeyHeight-(this.fontSize+this.fontSize/6),width:this.whiteKeyWidth,textAlign:"center",fontSize:this.fontSize,fill:"#ff0000"})),n++}else{const t=this.left+n*this.whiteKeyWidth-this.blackKeyWidth/2,e=new Iu.fabric.Rect({left:t,top:this.top,width:this.blackKeyWidth,height:this.blackKeyHeight,fill:ju,stroke:Lu,data:{type:"black",pressed:!1,highlighted:!1,hovered:!1}});this.objectKeys[o.name]=e,s.push(e)}e<du.length-1?e++:(e=0,t++)}const{minKey:o,maxKey:a}=this.getBoundaryKeys();this.objectMinBoundary=new Iu.fabric.Rect({left:this.left,top:this.top,width:o.left-this.left,height:this.height,fill:$u}),this.objectMaxBoundary=new Iu.fabric.Rect({left:a.left+a.width,top:this.top,width:this.width-a.left,height:this.height,fill:$u}),this.display.canvas.add(...i,...s,...r,this.objectMinBoundary,this.objectMaxBoundary),this.bindEvents()}bindEvents(){this.display.controller.addEventListener("layoutChange",(()=>{const{minKey:t,maxKey:e}=this.getBoundaryKeys(),n={duration:250,onChange:this.display.canvas.renderAll.bind(this.display.canvas)};this.objectMinBoundary.animate("width",t.left-this.left,n),this.objectMaxBoundary.animate("left",e.left+e.width,n),this.objectMaxBoundary.animate("width",this.width-e.left,n),this.draw()})),this.display.controller.notesPressed.subscribe((t=>{let e=this.notesPressedPrevious.filter((e=>!t.includes(e)));this.setKeyData(e,{pressed:!1}),this.setKeyData(t,{pressed:!0}),this.draw(),this.notesPressedPrevious=[...t]})),this.display.controller.notesHighlighted.subscribe((t=>{let e=this.notesHighlightedPrevious.filter((e=>!t.includes(e)));this.setKeyData(e,{highlighted:!1}),this.setKeyData(t,{highlighted:!0}),this.draw(),this.notesHighlightedPrevious=[...t]})),this.display.controller.notesHovered.subscribe((t=>{let e=this.notesHoveredPrevious.filter((e=>!t.includes(e)));this.setKeyData(e,{hovered:!1}),this.setKeyData(t,{hovered:!0}),this.draw(),this.notesHoveredPrevious=[...t]}))}setKeyData(t,e){for(const n of t){const t=this.objectKeys[n.name];t&&(t.dirty=!0,t.data={...t.data,...e})}}setAllKeyData(t){for(const e of Object.values(this.objectKeys))e.dirty=!0,e.data={...e.data,...t}}draw(){for(const t of Object.values(this.objectKeys))if(t.dirty){const e=t.data;e.pressed?t.fill=this.display.controller.pressedColor.background:e.hovered?t.fill=this.display.controller.hoverColor.background:e.highlighted?t.fill=this.display.controller.highlightColor.background:t.fill="white"===e.type?Ru:ju}this.display.canvas.renderAll()}}const Nu="none",Bu="#666";class Vu extends Iu.fabric.Group{constructor(t,e,n,i){const s=new Iu.fabric.Rect({fill:"#000",stroke:"#444",originX:"center",originY:"center",width:120*(i||1),height:20}),r=new Iu.fabric.Text(t,{fill:"#FFF",fontSize:14,originX:"center",originY:"center"});super([s,r],{top:"top"===e?0:139,left:120*n}),this.objectRect=s,this.objectLabel=r}get label(){return this.objectLabel.get("text")}setLabel(t){this.objectLabel.set("text",t)}setLabelAnimate(t,e){const n="down"===e?10:-10;this.objectLabel.animate("top",n,{duration:250,onChange:this.canvas?.renderAll.bind(this.canvas),onComplete:()=>{this.setLabel(t),this.objectLabel.set("top",-n),this.objectLabel.animate("top",0,{duration:250,onChange:this.canvas?.renderAll.bind(this.canvas),easing:Iu.fabric.util.ease.easeInOutQuint})},easing:Iu.fabric.util.ease.easeInOutQuint})}}class Wu extends Vu{constructor(t,e,n,i,s){super(t,e,i,s),this.objectRect.set("fill",n.getColor().background),this.objectLabel.set("fill",n.getColor().foreground),n.state.subscribe((()=>{this.objectRect.set("fill",n.getColor().background),this.objectLabel.set("fill",n.getColor().foreground),this.canvas?.renderAll()}))}}class Hu{constructor(t,e){this.objectSynthButtons=[],this.controller=t,this.htmlCanvas=e,this.canvas=new Iu.fabric.StaticCanvas(this.htmlCanvas,{width:Ou,height:Eu,backgroundColor:"#191919"}),this.driver=new ku(this.htmlCanvas),this.createObjects(),this.keyboard=new Fu(this,20,1,958,64,12),this.keyboard.createKeyboard()}static getInstance(t,e){return Hu.instance||(Hu.instance=new Hu(t,e)),Hu.instance}async initialize(){await this.driver.initialize(),this.driver.start(),this.canvas.remove(this.objectTextPrompt)}createObjects(){this.objectTextPrompt=new Iu.fabric.Text("Click to enable Push 2 display",{left:12,top:56,fill:"#fff"}),this.objectTextChord=new Iu.fabric.Text(Nu,{left:8,top:92,fill:Bu}),this.canvas.add(this.objectTextChord),this.objectRootLetterLabel=new Vu(l(Td),"top",0,.5),this.canvas.add(this.objectRootLetterLabel),this.objectRootOctaveLabel=new Vu(String(l(Md)),"top",.5,.5),this.objectRootOctaveLabel.data={rootOctave:Md},this.canvas.add(this.objectRootOctaveLabel),this.objectScaleNameLabel=new Vu(l(Sd),"top",1,2),this.canvas.add(this.objectScaleNameLabel),this.objectLayoutGeneratorConfigurationLabel=new Vu(l(Cd).getMeta().label,"top",3,2),this.canvas.add(this.objectLayoutGeneratorConfigurationLabel);for(let t=0;t<8;t++)if(yd[t]){const e=new Wu(yd[t].getMeta().label,"bottom",this.controller.getControl(`synth${t}`),t);this.objectSynthButtons.push(e),this.canvas.add(e)}this.bindEvents()}bindEvents(){ki.subscribe((t=>{this.objectTextChord.set("text",t?.chord.name||Nu),this.objectTextChord.set("fill",t?this.controller.pressedColor.background:Bu),this.canvas.renderAll()})),Td.subscribe((t=>{this.objectRootLetterLabel.setLabelAnimate(t,"down")})),Md.subscribe((t=>{this.objectRootOctaveLabel.data?.rootOctave<t?this.objectRootOctaveLabel.setLabelAnimate(String(t),"up"):this.objectRootOctaveLabel.setLabelAnimate(String(t),"down"),this.objectRootOctaveLabel.data.rootOctave=t})),Sd.subscribe((t=>{this.objectScaleNameLabel.setLabelAnimate(t,"down")})),Cd.subscribe((t=>{this.objectLayoutGeneratorConfigurationLabel.setLabelAnimate(t.getMeta().label,"down")}))}}function Gu(t,e,n){const i=t.slice();return i[7]=e[n],i}function zu(t,e,n){const i=t.slice();return i[10]=e[n],i}function Yu(t){let e,n;return e=new Au({props:{pad:t[0].pads[t[10]]}}),e.$on("u",t[6]),{c(){Pt(e.$$.fragment)},m(t,i){It(e,t,i),n=!0},p(t,n){const i={};9&n&&(i.pad=t[0].pads[t[10]]),e.$set(i)},i(t){n||(xt(e.$$.fragment,t),n=!0)},o(t){Ct(e.$$.fragment,t),n=!1},d(t){Dt(e,t)}}}function Xu(t){let e,n,i,s=t[7],r=[];for(let e=0;e<s.length;e+=1)r[e]=Yu(zu(t,s,e));const o=t=>Ct(r[t],1,1,(()=>{r[t]=null}));return{c(){e=A("div");for(let t=0;t<r.length;t+=1)r[t].c();n=k()},m(t,s){S(t,e,s);for(let t=0;t<r.length;t+=1)r[t].m(e,null);w(e,n),i=!0},p(t,i){if(9&i){let a;for(s=t[7],a=0;a<s.length;a+=1){const o=zu(t,s,a);r[a]?(r[a].p(o,i),xt(r[a],1)):(r[a]=Yu(o),r[a].c(),xt(r[a],1),r[a].m(e,n))}for(yt(),a=s.length;a<r.length;a+=1)o(a);bt()}},i(t){if(!i){for(let t=0;t<s.length;t+=1)xt(r[t]);i=!0}},o(t){r=r.filter(Boolean);for(let t=0;t<r.length;t+=1)Ct(r[t]);i=!1},d(t){t&&T(e),M(r,t)}}}function Uu(t){let e,n,i,s,r,o,a,c,l,h,u,d,f,p,m=t[3],g=[];for(let e=0;e<m.length;e+=1)g[e]=Xu(Gu(t,m,e));const v=t=>Ct(g[t],1,1,(()=>{g[t]=null}));return{c(){e=A("div"),n=A("div"),i=O("svg"),s=O("defs"),r=O("linearGradient"),o=O("stop"),a=O("stop"),c=O("polygon"),l=k(),h=A("canvas"),u=k();for(let t=0;t<g.length;t+=1)g[t].c();D(o,"offset","0%"),N(o,"stop-color","rgb(255,255,255)"),N(o,"stop-opacity","0.1"),D(a,"offset","75%"),N(a,"stop-color","rgb(255,255,255)"),N(a,"stop-opacity","0.01"),D(r,"id","glare"),D(r,"x1","0%"),D(r,"y1","0%"),D(r,"x2","0%"),D(r,"y2","100%"),D(c,"points","-480,0 1440,0 1440,160"),N(c,"fill","url(#glare)"),D(i,"height",Ou),D(i,"width",Eu),D(i,"viewBox","0 0 960 160"),D(i,"class","polygon svelte-1cagql9"),D(h,"class","svelte-1cagql9"),D(n,"class","display svelte-1cagql9"),D(e,"class","push2 svelte-1cagql9"),N(e,"--pressedColor",t[0].pressedColor.foreground),N(e,"--pressedBackgroundColor",t[0].pressedColor.background),N(e,"--highlightedColor",t[0].highlightColor.foreground),N(e,"--highlightedBackgroundColor",t[0].highlightColor.background),N(e,"--hoverColor",t[0].hoverColor.foreground),N(e,"--hoverBackgroundColor",t[0].hoverColor.background)},m(m,v){S(m,e,v),w(e,n),w(n,i),w(i,s),w(s,r),w(r,o),w(r,a),w(i,c),w(n,l),w(n,h),t[4](h),w(e,u);for(let t=0;t<g.length;t+=1)g[t].m(e,null);d=!0,f||(p=I(n,"click",t[5]),f=!0)},p(t,[n]){if(9&n){let i;for(m=t[3],i=0;i<m.length;i+=1){const s=Gu(t,m,i);g[i]?(g[i].p(s,n),xt(g[i],1)):(g[i]=Xu(s),g[i].c(),xt(g[i],1),g[i].m(e,null))}for(yt(),i=m.length;i<g.length;i+=1)v(i);bt()}(!d||1&n)&&N(e,"--pressedColor",t[0].pressedColor.foreground),(!d||1&n)&&N(e,"--pressedBackgroundColor",t[0].pressedColor.background),(!d||1&n)&&N(e,"--highlightedColor",t[0].highlightColor.foreground),(!d||1&n)&&N(e,"--highlightedBackgroundColor",t[0].highlightColor.background),(!d||1&n)&&N(e,"--hoverColor",t[0].hoverColor.foreground),(!d||1&n)&&N(e,"--hoverBackgroundColor",t[0].hoverColor.background)},i(t){if(!d){for(let t=0;t<m.length;t+=1)xt(g[t]);d=!0}},o(t){g=g.filter(Boolean);for(let t=0;t<g.length;t+=1)Ct(g[t]);d=!1},d(n){n&&T(e),t[4](null),M(g,n),f=!1,p()}}}function qu(t,e,n){let i,s,r,{controller:o}=e;return t.$$set=t=>{"controller"in t&&n(0,o=t.controller)},t.$$.update=()=>{1&t.$$.dirty&&n(3,i=o.getLayout()),3&t.$$.dirty&&o&&s&&n(2,r=Hu.getInstance(o,s))},[o,s,r,i,function(t){it[t?"unshift":"push"]((()=>{s=t,n(1,s)}))},()=>r.initialize(),function(e){et(t,e)}]}class Ku extends $t{constructor(t){super(),jt(this,t,qu,Uu,a,{controller:0})}}const Zu=[20,21,22,23,24,25,26,27];class Qu extends class{constructor(t,e,n,i){this.notesPressedState=[],this.notesPressed=ke([]),this.notesHighlightedState=[],this.notesHighlighted=ke([]),this.notesHoveredState=[],this.notesHovered=ke([]),this.pads={},this.controls={},this.rows=t,this.columns=e,this.offset=n,this.eventTarget=document.createTextNode(null),this.addEventListener=this.eventTarget.addEventListener.bind(this.eventTarget),this.removeEventListener=this.eventTarget.removeEventListener.bind(this.eventTarget),this.dispatchEvent=this.eventTarget.dispatchEvent.bind(this.eventTarget),this.bindControlEvents();for(let i=0;i<t*e;i++){const t=i+n;this.pads[t]=new Cu(this,t)}for(const t of i)this.controls[t.controlNumber]=new wu(this,t)}get padCount(){return this.rows*this.columns}getPadsByNote(t){return Object.values(this.pads).filter((e=>e.getNote()===t))}getPadByIndex(t){return this.pads[this.offset+t]}getPadNotes(){return Object.values(this.pads).map((t=>t.getNote()))}getLayout(){let t=[],e=this.offset;for(let n=0;n<this.rows;n++){let n=[];for(let t=0;t<this.columns;t++)n.push(e),e++;t=[n,...t]}return t}setLayoutGenerator(t,e){this.scaleName=e;const n=t.generate(this),i=mi(`${t.root.pc}0 ${this.scaleName}`).notes.map((t=>{const e=an(t).pc;return du.includes(e)?e:an(Jn(t)).pc}));for(let t=0;t<this.padCount;t++){const e=t+this.offset,s=n[e];s.noteNumber=i.indexOf(s.pc)+1,this.pads[e].setNote(s)}this.draw(),this.dispatchEvent(new CustomEvent("layoutChange"))}noteOn(t,e){this.notesPressedState.includes(t)||(this.notesPressedState.push(t),this.notesPressed.set(this.notesPressedState),this.synth.down(t,e))}noteOff(t){this.notesPressedState.includes(t)&&(this.notesPressedState.splice(this.notesPressedState.indexOf(t),1),this.notesPressed.set(this.notesPressedState),this.synth.up(t))}hoverNoteOn(t){this.notesHoveredState.includes(t)||(this.notesHoveredState.push(t),this.notesHovered.set(this.notesHoveredState))}hoverNoteOff(t){this.notesHoveredState.includes(t)&&(this.notesHoveredState.splice(this.notesHoveredState.indexOf(t),1),this.notesHovered.set(this.notesHoveredState))}highlightNotes(t){this.notesHighlightedState=t,this.notesHighlighted.set(this.notesHighlightedState)}highlightClear(){this.notesHighlightedState=[],this.notesHighlighted.set(this.notesHighlightedState)}getControl(t){return Object.values(this.controls).find((e=>e.controlType===t))}bindControlEvents(){this.addEventListener("rootLetter",(()=>{Td.update((t=>gu(t,du)))})),this.addEventListener("rootOctave",(()=>Md.update((t=>gu(t,fu))))),this.addEventListener("rootOctaveUp",(()=>Md.update((t=>t<pu?t+1:t)))),this.addEventListener("rootOctaveDown",(()=>Md.update((t=>t>mu?t-1:t)))),Md.subscribe((t=>{for(const t of this.notesPressedState)this.noteOff(t);this.notesHoveredState=[],this.notesPressed.set(this.notesPressedState);const e=this.getControl("rootOctaveUp"),n=this.getControl("rootOctaveDown");e&&n&&(t===pu?e.setStateOff():e.setStateOn(),t===mu?n.setStateOff():n.setStateOn())})),this.addEventListener("scaleName",(()=>{Sd.update((t=>gu(t,wd)))})),this.addEventListener("layoutGeneratorConfiguration",(()=>{Cd.update((t=>gu(t,xd)))})),this.addEventListener("synthConfiguration",(()=>{bd.update((t=>gu(t,yd)))}))}draw(){for(const t of Object.values(this.pads))t.draw();for(const t of Object.values(this.controls))t.draw()}setDevices(t,e){this.input&&this.input.removeListener(),this.input=Bt.getInputById(t),this.output=Bt.getOutputById(e),this.input&&this.output&&(this.input.addListener("noteon","all",(t=>{const e=this.pads[t.note.number];e&&this.noteOn(e.getNote(),t.velocity)})),this.input.addListener("noteoff","all",(t=>{const e=this.pads[t.note.number];e&&this.noteOff(e.getNote())})),this.input.addListener("controlchange","all",(t=>{const e=this.controls[t.controller.number];e?(e.fireAllEvents||t.value>0)&&this.dispatchEvent(new CustomEvent(e.controlType,{detail:{event:t,control:e}})):console.warn("Control not bound",t)}))),this.draw()}setSynth(t){this.synth=t}destroy(){this.input&&this.input.removeListener()}}{constructor(){super(8,8,36,[{controlNumber:50,controlType:"rootLetter"},{controlNumber:55,controlType:"rootOctaveUp"},{controlNumber:54,controlType:"rootOctaveDown"},{controlNumber:58,controlType:"scaleName"},{controlNumber:31,controlType:"layoutGeneratorConfiguration"},...Zu.map(((t,e)=>({controlNumber:t,controlType:`synth${e}`})))]),this.colors={OFF:{background:null,foreground:null,velocity:null},RED:{background:"#FF0000",foreground:"#000",velocity:127},GREEN:{background:"#00FF00",foreground:"#000",velocity:126},BLUE:{background:"#0000FF",foreground:"#FFF",velocity:125},YELLOW:{background:"yellow",foreground:"#000",velocity:8},WHITE:{background:"#FFF",foreground:"#000",velocity:122},PINK:{background:"#FF0080",foreground:"#FFF",velocity:25}},this.controlColors={on:this.colors.WHITE,off:this.colors.OFF,active:this.colors.RED},this.noteColors={default:this.colors.WHITE,0:this.colors.OFF,1:this.colors.RED,3:this.colors.YELLOW},this.pressedColor=this.colors.GREEN,this.highlightColor=this.colors.BLUE,this.hoverColor=this.colors.PINK,bd.subscribe((t=>this.drawControlsSynthConfiguration(t)));for(let t=0;t<Zu.length;t++)this.addEventListener(`synth${t}`,(()=>{yd[t]&&bd.set(yd[t])}))}static getInstance(){return new Qu}static getMeta(){return{id:"Push2",label:"Ableton Push 2",component:Ku}}setDevices(t,e){super.setDevices(t,e),this.drawControlsSynthConfiguration(l(bd))}drawControlsSynthConfiguration(t){for(let e=0;e<Zu.length;e++){const n=Zu[e];yd[e]?yd[e]===t?this.controls[n].setState("active"):this.controls[n].setStateOn():this.controls[n].setStateOff()}}}var Ju=function(t,e,n,i){return new(n||(n=Promise))((function(s,r){function o(t){try{c(i.next(t))}catch(t){r(t)}}function a(t){try{c(i.throw(t))}catch(t){r(t)}}function c(t){var e;t.done?s(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(o,a)}c((i=i.apply(t,e||[])).next())}))};class td extends ql{constructor(t){super(t),this.name="PianoComponent",this.input=void 0,this.output=new ph({context:this.context}),this._enabled=!1,this.volume=this.output.volume,this._loaded=!1,this.volume.value=t.volume,this._enabled=t.enabled,this.samples=t.samples}get loaded(){return this._loaded}load(){return Ju(this,void 0,void 0,(function*(){if(!this._enabled)return Promise.resolve();yield this._internalLoad(),this._loaded=!0}))}}function ed(t){var e,n;return(e=t,n="midi",new Wl(Rl(),e,n)).toNote()}function nd(t,e){return Math.random()*(e-t)+t}const id={1:[8],2:[6,12],3:[1,7,15],4:[1,5,10,15],5:[1,4,8,12,16],6:[1,3,7,10,13,16],7:[1,3,6,9,11,13,16],8:[1,3,5,7,9,11,13,16],9:[1,3,5,7,9,11,13,15,16],10:[1,2,3,5,7,9,11,13,15,16],11:[1,2,3,5,7,9,11,13,14,15,16],12:[1,2,3,4,5,7,9,11,13,14,15,16],13:[1,2,3,4,5,7,9,11,12,13,14,15,16],14:[1,2,3,4,5,6,7,9,11,12,13,14,15,16],15:[1,2,3,4,5,6,7,9,10,11,12,13,14,15,16],16:[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]},sd=[21,24,27,30,33,36,39,42,45,48,51,54,57,60,63,66,69,72,75,78,81,84,87,90,93,96,99,102,105,108];const rd=[21,24,27,30,33,36,39,42,45,48,51,54,57,60,63,66,69,72,75,78,81,84,87];class od extends td{constructor(t){super(t),this._urls={};const e=(n=t.minNote,i=t.maxNote,rd.filter((t=>n<=t&&t<=i)));var n,i;for(const t of e)this._urls[t]=`harmS${ed(t).replace("#","s")}.[mp3|ogg]`}triggerAttack(t,e,n){this._enabled&&function(t){return rd[0]<=t&&t<=rd[rd.length-1]}(t)&&this._sampler.triggerAttack(lh(t).toNote(),e,n*nd(.5,1))}_internalLoad(){return new Promise((t=>{this._sampler=new su({baseUrl:this.samples,onload:t,urls:this._urls}).connect(this.output)}))}}class ad extends td{constructor(t){super(t),this._urls={};for(let e=t.minNote;e<=t.maxNote;e++)this._urls[e]=`rel${e-20}.[mp3|ogg]`}_internalLoad(){return new Promise((t=>{this._buffers=new ah(this._urls,t,this.samples)}))}start(t,e,n){if(this._enabled&&this._buffers.has(t)){new xh({url:this._buffers.get(t),context:this.context}).connect(this.output).start(e,0,void 0,.015*n*nd(.5,1))}}}class cd extends td{constructor(t){super(t),this._downTime=1/0,this._currentSound=null,this._downTime=1/0}_internalLoad(){return new Promise((t=>{this._buffers=new ah({down1:"pedalD1.mp3",down2:"pedalD2.mp3",up1:"pedalU1.mp3",up2:"pedalU2.mp3"},t,this.samples)}))}_squash(t){this._currentSound&&"stopped"!==this._currentSound.state&&this._currentSound.stop(t),this._currentSound=null}_playSample(t,e){this._enabled&&(this._currentSound=new xh({url:this._buffers.get(`${e}${Math.random()>.5?1:2}`),context:this.context,curve:"exponential",fadeIn:.05,fadeOut:.1}).connect(this.output),this._currentSound.start(t,nd(0,.01),void 0,.1*nd(.5,1)))}down(t){this._squash(t),this._downTime=t,this._playSample(t,"down")}up(t){this._squash(t),this._downTime=1/0,this._playSample(t,"up")}isDown(t){return t>this._downTime}}class ld extends ql{constructor(t){super(t),this.name="PianoString",this._urls={},t.notes.forEach((e=>{return this._urls[e]=(n=e,i=t.velocity,`${ed(n).replace("#","s")}v${i}.[mp3|ogg]`);var n,i})),this.samples=t.samples}load(){return new Promise((t=>{this._sampler=this.output=new su({attack:0,baseUrl:this.samples,curve:"exponential",onload:t,release:.4,urls:this._urls,volume:3})}))}triggerAttack(t,e,n){this._sampler.triggerAttack(t,e,n)}triggerRelease(t,e){this._sampler.triggerRelease(t,e)}}var hd=function(t,e,n,i){return new(n||(n=Promise))((function(s,r){function o(t){try{c(i.next(t))}catch(t){r(t)}}function a(t){try{c(i.throw(t))}catch(t){r(t)}}function c(t){var e;t.done?s(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(o,a)}c((i=i.apply(t,e||[])).next())}))};class ud extends td{constructor(t){super(t);const e=(n=t.minNote,i=t.maxNote,sd.filter((t=>n<=t&&t<=i)));var n,i;const s=id[t.velocities].slice();this._strings=s.map((n=>new ld(Object.assign(t,{notes:e,velocity:n})))),this._activeNotes=new Map}scale(t,e,n,i,s){return(t-e)/(n-e)*(s-i)+i}triggerAttack(t,e,n){const i=this.scale(n,0,1,-.5,this._strings.length-.51),s=Math.max(Math.round(i),0);let r=1+i-s;1===this._strings.length&&(r=n);const o=this._strings[s];this._activeNotes.has(t)&&this.triggerRelease(t,e),this._activeNotes.set(t,o),o.triggerAttack(lh(t).toNote(),e,r)}triggerRelease(t,e){this._activeNotes.has(t)&&(this._activeNotes.get(t).triggerRelease(lh(t).toNote(),e),this._activeNotes.delete(t))}_internalLoad(){return hd(this,void 0,void 0,(function*(){yield Promise.all(this._strings.map((t=>hd(this,void 0,void 0,(function*(){yield t.load(),t.connect(this.output)})))))}))}}var dd=function(t,e,n,i){return new(n||(n=Promise))((function(s,r){function o(t){try{c(i.next(t))}catch(t){r(t)}}function a(t){try{c(i.throw(t))}catch(t){r(t)}}function c(t){var e;t.done?s(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(o,a)}c((i=i.apply(t,e||[])).next())}))};class fd extends ql{constructor(){super(hl(fd.getDefaults(),arguments)),this.name="Piano",this.input=void 0,this.output=new Ql({context:this.context}),this._heldNotes=new Map,this._loaded=!1;const t=hl(fd.getDefaults(),arguments);t.url.endsWith("/")||(t.url+="/"),this.maxPolyphony=t.maxPolyphony,this._heldNotes=new Map,this._sustainedNotes=new Map,this._strings=new ud(Object.assign({},t,{enabled:!0,samples:t.url,volume:t.volume.strings})).connect(this.output),this.strings=this._strings.volume,this._pedal=new cd(Object.assign({},t,{enabled:t.pedal,samples:t.url,volume:t.volume.pedal})).connect(this.output),this.pedal=this._pedal.volume,this._keybed=new ad(Object.assign({},t,{enabled:t.release,samples:t.url,volume:t.volume.keybed})).connect(this.output),this.keybed=this._keybed.volume,this._harmonics=new od(Object.assign({},t,{enabled:t.release,samples:t.url,volume:t.volume.harmonics})).connect(this.output),this.harmonics=this._harmonics.volume}static getDefaults(){return Object.assign(ql.getDefaults(),{maxNote:108,minNote:21,pedal:!0,release:!1,url:"https://tambien.github.io/Piano/audio/",velocities:1,maxPolyphony:32,volume:{harmonics:0,keybed:0,pedal:0,strings:0}})}load(){return dd(this,void 0,void 0,(function*(){yield Promise.all([this._strings.load(),this._pedal.load(),this._keybed.load(),this._harmonics.load()]),this._loaded=!0}))}get loaded(){return this._loaded}pedalDown({time:t=this.immediate()}={}){return this.loaded&&(t=this.toSeconds(t),this._pedal.isDown(t)||this._pedal.down(t)),this}pedalUp({time:t=this.immediate()}={}){if(this.loaded){const e=this.toSeconds(t);this._pedal.isDown(e)&&(this._pedal.up(e),this._sustainedNotes.forEach(((t,n)=>{this._heldNotes.has(n)||this._strings.triggerRelease(n,e)})),this._sustainedNotes.clear())}return this}keyDown({note:t,midi:e,time:n=this.immediate(),velocity:i=.8}){return this.loaded&&this.maxPolyphony>this._heldNotes.size+this._sustainedNotes.size?(n=this.toSeconds(n),Kc(t)&&(e=Math.round(lh(t).toMidi())),this._heldNotes.has(e)||(this._heldNotes.set(e,{time:n,velocity:i}),this._strings.triggerAttack(e,n,i))):console.warn("samples not loaded"),this}keyUp({note:t,midi:e,time:n=this.immediate(),velocity:i=.8}){if(this.loaded&&(n=this.toSeconds(n),Kc(t)&&(e=Math.round(lh(t).toMidi())),this._heldNotes.has(e))){const t=this._heldNotes.get(e);this._heldNotes.delete(e);let s=3/Math.pow(Math.max(n-t.time,.1),.7)*t.velocity*i;s=Math.max(s,.4),s=Math.min(s,4),this._pedal.isDown(n)?this._sustainedNotes.has(e)||this._sustainedNotes.set(e,n):(this._strings.triggerRelease(e,n),this._harmonics.triggerAttack(e,n,s)),this._keybed.start(e,n,i)}return this}stopAll(){return this.pedalUp(),this._heldNotes.forEach(((t,e)=>{this.keyUp({midi:e})})),this}}class pd extends ou{constructor(){super(),this.initialized=ke(!1);const t=new fd({velocities:5});t.toDestination(),t.load().then((()=>{this.piano=t,this.initialized.set(!0)}))}static getInstance(){return new pd}static getMeta(){return{id:"piano",label:"Piano"}}down(t,e){this.piano&&this.piano.keyDown({note:t.name.toString(),velocity:e})}up(t){this.piano&&this.piano.keyUp({note:t.name.toString()})}}const md=ke(null),gd=ke(null);const vd=[Qu],_d=ke(vd[0]),yd=[cu,lu,hu,class extends au{constructor(){super(Jh)}static getInstance(){return new hu}static getMeta(){return{id:"noise",label:"Noise"}}},pd],bd=ke(yd[0]),xd=[yu,bu],Cd=ke(xd[0]),wd=bi.names().sort(),Sd=ke("major"),Td=ke("C"),Md=ke(2);function Ad(t,e,n){const i=t.slice();return i[24]=e[n],i}function Od(t,e,n){const i=t.slice();return i[27]=e[n],i}function Ed(t,e,n){const i=t.slice();return i[30]=e[n],i}function kd(t,e,n){const i=t.slice();return i[33]=e[n],i}function Pd(e){let n,i,s,r=e[33]+"";return{c(){n=A("option"),i=E(r),s=k(),n.__value=e[33],n.value=n.__value},m(t,e){S(t,n,e),w(n,i),w(n,s)},p:t,d(t){t&&T(n)}}}function Id(e){let n,i,s,r=e[30]+"";return{c(){n=A("option"),i=E(r),s=k(),n.__value=e[30],n.value=n.__value},m(t,e){S(t,n,e),w(n,i),w(n,s)},p:t,d(t){t&&T(n)}}}function Dd(t){let e,n,i,s,o,a,c,l,h,u=du,d=[];for(let e=0;e<u.length;e+=1)d[e]=Pd(kd(t,u,e));let f=fu,p=[];for(let e=0;e<f.length;e+=1)p[e]=Id(Ed(t,f,e));return{c(){e=A("select"),n=A("option"),i=E("Current ");for(let t=0;t<d.length;t+=1)d[t].c();s=k(),o=A("select"),a=A("option"),c=E("Auto ");for(let t=0;t<p.length;t+=1)p[t].c();n.__value=void 0,n.value=n.__value,void 0===t[6]&&ct((()=>t[12].call(e))),a.__value=void 0,a.value=a.__value,void 0===t[7]&&ct((()=>t[13].call(o)))},m(r,u){S(r,e,u),w(e,n),w(n,i);for(let t=0;t<d.length;t+=1)d[t].m(e,null);B(e,t[6]),S(r,s,u),S(r,o,u),w(o,a),w(a,c);for(let t=0;t<p.length;t+=1)p[t].m(o,null);B(o,t[7]),l||(h=[I(e,"change",t[12]),I(o,"change",t[13])],l=!0)},p(t,n){if(0&n){let i;for(u=du,i=0;i<u.length;i+=1){const s=kd(t,u,i);d[i]?d[i].p(s,n):(d[i]=Pd(s),d[i].c(),d[i].m(e,null))}for(;i<d.length;i+=1)d[i].d(1);d.length=u.length}if(64&n[0]&&B(e,t[6]),0&n){let e;for(f=fu,e=0;e<f.length;e+=1){const i=Ed(t,f,e);p[e]?p[e].p(i,n):(p[e]=Id(i),p[e].c(),p[e].m(o,null))}for(;e<p.length;e+=1)p[e].d(1);p.length=f.length}128&n[0]&&B(o,t[7])},d(t){t&&T(e),M(d,t),t&&T(s),t&&T(o),M(p,t),l=!1,r(h)}}}function Rd(e){let n,i,s,r=e[27]+"";return{c(){n=A("option"),i=E(r),s=k(),n.__value=e[27],n.value=n.__value},m(t,e){S(t,n,e),w(n,i),w(n,s)},p:t,d(t){t&&T(n)}}}function jd(t){let e,n,i,s,o,a,c=t[8],l=[];for(let e=0;e<c.length;e+=1)l[e]=Rd(Od(t,c,e));return{c(){e=A("input"),n=k(),i=A("select"),s=A("option"),s.textContent="Any ";for(let t=0;t<l.length;t+=1)l[t].c();D(e,"autocomplete","off"),D(e,"autocapitalize","off"),s.__value=null,s.value=s.__value,void 0===t[3]&&ct((()=>t[17].call(i)))},m(r,c){S(r,e,c),F(e,t[2]),t[15](e),S(r,n,c),S(r,i,c),w(i,s);for(let t=0;t<l.length;t+=1)l[t].m(i,null);B(i,t[3]),o||(a=[I(e,"input",t[14]),I(e,"keypress",t[16]),I(i,"change",t[17])],o=!0)},p(t,n){if(4&n[0]&&e.value!==t[2]&&F(e,t[2]),256&n[0]){let e;for(c=t[8],e=0;e<c.length;e+=1){const s=Od(t,c,e);l[e]?l[e].p(s,n):(l[e]=Rd(s),l[e].c(),l[e].m(i,null))}for(;e<l.length;e+=1)l[e].d(1);l.length=c.length}264&n[0]&&B(i,t[3])},d(s){s&&T(e),t[15](null),s&&T(n),s&&T(i),M(l,s),o=!1,r(a)}}}function $d(t){let e,n=t[24].quality+"";return{c(){e=E(n)},m(t,n){S(t,e,n)},p(t,i){32&i[0]&&n!==(n=t[24].quality+"")&&L(e,n)},d(t){t&&T(e)}}}function Ld(t){let e,n,i,s,r,o,a,c,l,h,u,d=t[24].fullName+"";return o=new Re({props:{small:!0,$$slots:{default:[$d]},$$scope:{ctx:t}}}),l=new Oe({props:{primary:!0,title:"Add to chord playlist",icon:Oi}}),l.$on("click",(function(){return t[18](t[24])})),{c(){e=A("tr"),n=A("td"),i=E(d),s=k(),r=A("td"),Pt(o.$$.fragment),a=k(),c=A("td"),Pt(l.$$.fragment),h=k(),D(c,"class","buttonColumn svelte-agvkw1")},m(t,d){S(t,e,d),w(e,n),w(n,i),w(e,s),w(e,r),It(o,r,null),w(e,a),w(e,c),It(l,c,null),w(e,h),u=!0},p(e,n){t=e,(!u||32&n[0])&&d!==(d=t[24].fullName+"")&&L(i,d);const s={};32&n[0]|32&n[1]&&(s.$$scope={dirty:n,ctx:t}),o.$set(s)},i(t){u||(xt(o.$$.fragment,t),xt(l.$$.fragment,t),u=!0)},o(t){Ct(o.$$.fragment,t),Ct(l.$$.fragment,t),u=!1},d(t){t&&T(e),Dt(o),Dt(l)}}}function Fd(t){let e,n,i,s,r,o,a,c,l,h,u,d,f,p,m,g,v,_,y,b,x,C;r=new Be({props:{label:"Tonic/octave",grouped:!0,$$slots:{default:[Dd]},$$scope:{ctx:t}}}),h=new Be({props:{label:"Name/quality",grouped:!0,$$slots:{default:[jd]},$$scope:{ctx:t}}});let O=t[5],E=[];for(let e=0;e<O.length;e+=1)E[e]=Ld(Ad(t,O,e));const P=t=>Ct(E[t],1,1,(()=>{E[t]=null}));return{c(){e=A("div"),n=A("fieldset"),i=A("legend"),i.textContent="Parameters",s=k(),Pt(r.$$.fragment),o=k(),a=A("fieldset"),c=A("legend"),c.textContent="Search",l=k(),Pt(h.$$.fragment),u=k(),d=A("div"),f=A("table"),p=A("thead"),m=A("tr"),g=A("th"),g.textContent="Name",v=k(),_=A("th"),_.textContent="Quality",y=k(),b=A("th"),b.textContent=" ",x=k();for(let t=0;t<E.length;t+=1)E[t].c();D(n,"class","svelte-agvkw1"),D(a,"class","svelte-agvkw1"),D(e,"class","formContainer svelte-agvkw1"),D(g,"class","svelte-agvkw1"),D(_,"class","svelte-agvkw1"),D(b,"class","svelte-agvkw1"),D(f,"class","striped"),D(d,"class","tableContainer svelte-agvkw1")},m(T,M){S(T,e,M),w(e,n),w(n,i),w(n,s),It(r,n,null),w(e,o),w(e,a),w(a,c),w(a,l),It(h,a,null),S(T,u,M),S(T,d,M),w(d,f),w(f,p),w(p,m),w(m,g),w(m,v),w(m,_),w(m,y),w(m,b),w(f,x);for(let t=0;t<E.length;t+=1)E[t].m(f,null);t[19](d),C=!0},p(t,e){const n={};192&e[0]|32&e[1]&&(n.$$scope={dirty:e,ctx:t}),r.$set(n);const i={};if(47&e[0]|32&e[1]&&(i.$$scope={dirty:e,ctx:t}),h.$set(i),544&e[0]){let n;for(O=t[5],n=0;n<O.length;n+=1){const i=Ad(t,O,n);E[n]?(E[n].p(i,e),xt(E[n],1)):(E[n]=Ld(i),E[n].c(),xt(E[n],1),E[n].m(f,null))}for(yt(),n=O.length;n<E.length;n+=1)P(n);bt()}},i(t){if(!C){xt(r.$$.fragment,t),xt(h.$$.fragment,t);for(let t=0;t<O.length;t+=1)xt(E[t]);C=!0}},o(t){Ct(r.$$.fragment,t),Ct(h.$$.fragment,t),E=E.filter(Boolean);for(let t=0;t<E.length;t+=1)Ct(E[t]);C=!1},d(n){n&&T(e),Dt(r),Dt(h),n&&T(u),n&&T(d),M(E,n),t[19](null)}}}function Nd(t){let e;return{c(){e=A("h4"),e.textContent="Chords",D(e,"slot","header")},m(t,n){S(t,e,n)},d(t){t&&T(e)}}}function Bd(t){let e;return{c(){e=E("Close")},m(t,n){S(t,e,n)},d(t){t&&T(e)}}}function Vd(t){let e,n,i;return n=new Oe({props:{clear:!0,$$slots:{default:[Bd]},$$scope:{ctx:t}}}),n.$on("click",t[11]),{c(){e=A("div"),Pt(n.$$.fragment),D(e,"slot","footer"),D(e,"class","is-right")},m(t,s){S(t,e,s),It(n,e,null),i=!0},p(t,e){const i={};32&e[1]&&(i.$$scope={dirty:e,ctx:t}),n.$set(i)},i(t){i||(xt(n.$$.fragment,t),i=!0)},o(t){Ct(n.$$.fragment,t),i=!1},d(t){t&&T(e),Dt(n)}}}function Wd(t){let e,n;return e=new le({props:{style:"display: flex; flex-direction: column;",$$slots:{footer:[Vd],header:[Nd],default:[Fd]},$$scope:{ctx:t}}}),{c(){Pt(e.$$.fragment)},m(t,i){It(e,t,i),n=!0},p(t,n){const i={};255&n[0]|32&n[1]&&(i.$$scope={dirty:n,ctx:t}),e.$set(i)},i(t){n||(xt(e.$$.fragment,t),n=!0)},o(t){Ct(e.$$.fragment,t),n=!1},d(t){Dt(e,t)}}}function Hd(t){let e,n,i;function s(e){t[20](e)}let r={style:"width: 80vw; height: 80vh; max-width: 800px;",$$slots:{default:[Wd]},$$scope:{ctx:t}};return void 0!==t[0]&&(r.open=t[0]),e=new Xe({props:r}),it.push((()=>kt(e,"open",s))),{c(){Pt(e.$$.fragment)},m(t,n){It(e,t,n),i=!0},p(t,i){const s={};255&i[0]|32&i[1]&&(s.$$scope={dirty:i,ctx:t}),!n&&1&i[0]&&(n=!0,s.open=t[0],lt((()=>n=!1))),e.$set(s)},i(t){i||(xt(e.$$.fragment,t),i=!0)},o(t){Ct(e.$$.fragment,t),i=!1},d(t){Dt(e,t)}}}function Gd(t,e,n){let i,s;h(t,Td,(t=>n(21,i=t))),h(t,Md,(t=>n(22,s=t)));const r=Rn().map((t=>Object.assign(Object.assign({},t),{fullName:t.name?`${t.name} (${t.aliases.join(", ")})`:t.aliases.join(", ")}))),o=[...new Set(r.map((t=>t.quality)))];let a,c,l,u,d,{open:f}=e,{addToChordPlaylist:p}=e,m="",g=null;function v(t){{const e=xi.fromChordType(t,a||i,c||s+1);p(e)}}return t.$$set=t=>{"open"in t&&n(0,f=t.open),"addToChordPlaylist"in t&&n(10,p=t.addToChordPlaylist)},t.$$.update=()=>{if(60&t.$$.dirty[0]){if(n(5,d=r),g&&n(5,d=d.filter((t=>t.quality===g))),m&&m.length){const t=new ys(d,{keys:[{name:"name",weight:.4},{name:"aliases",weight:.6}]});n(5,d=t.search(m).map((t=>t.item)))}u&&n(4,u.scrollTop=0,u)}3&t.$$.dirty[0]&&f&&(null==l||l.focus())},[f,l,m,g,u,d,a,c,o,v,p,()=>{n(0,f=!1)},function(){a=V(this),n(6,a)},function(){c=V(this),n(7,c)},function(){m=this.value,n(2,m)},function(t){it[t?"unshift":"push"]((()=>{l=t,n(1,l)}))},t=>{"Enter"===t.key&&(t.preventDefault(),d[0]&&(n(0,f=!1),v(d[0])))},function(){g=V(this),n(3,g),n(8,o)},t=>v(t),function(t){it[t?"unshift":"push"]((()=>{u=t,n(4,u),n(3,g),n(5,d),n(2,m)}))},function(t){f=t,n(0,f)}]}class zd extends $t{constructor(t){super(),jt(this,t,Gd,Hd,a,{open:0,addToChordPlaylist:10},[-1,-1])}}const Yd=[{name:"Test progression",progression:["IMaj7","IIm7","V7"]},{name:"ii-V-I progression",progression:["ii","V","I"]},{name:"I-IV-V-I progression",progression:["I","IV","V","I"]},{name:"I-ii-V-I progression",progression:["I","ii","V","I"]},{name:"I-vi-IV-V progression",progression:["I","vi","IV","V"]},{name:"I-vi-ii-V progression",progression:["I","vi","ii","V"]},{name:"I-IV-vi-V progression",progression:["I","IV","vi","V"]},{name:"I-V-vi-IV progression",progression:["I","V","vi","IV"]}];function Xd(t,e,n){const i=t.slice();return i[22]=e[n],i}function Ud(t,e,n){const i=t.slice();return i[25]=e[n],i}function qd(t,e,n){const i=t.slice();return i[28]=e[n],i}function Kd(e){let n,i,s,r=e[28]+"";return{c(){n=A("option"),i=E(r),s=k(),n.__value=e[28],n.value=n.__value},m(t,e){S(t,n,e),w(n,i),w(n,s)},p:t,d(t){t&&T(n)}}}function Zd(e){let n,i,s,r=e[25]+"";return{c(){n=A("option"),i=E(r),s=k(),n.__value=e[25],n.value=n.__value},m(t,e){S(t,n,e),w(n,i),w(n,s)},p:t,d(t){t&&T(n)}}}function Qd(t){let e,n,i,s,o,a,c,l,h,u=du,d=[];for(let e=0;e<u.length;e+=1)d[e]=Kd(qd(t,u,e));let f=fu,p=[];for(let e=0;e<f.length;e+=1)p[e]=Zd(Ud(t,f,e));return{c(){e=A("select"),n=A("option"),i=E("Current ");for(let t=0;t<d.length;t+=1)d[t].c();s=k(),o=A("select"),a=A("option"),c=E("Auto ");for(let t=0;t<p.length;t+=1)p[t].c();n.__value=void 0,n.value=n.__value,void 0===t[5]&&ct((()=>t[11].call(e))),a.__value=void 0,a.value=a.__value,void 0===t[6]&&ct((()=>t[12].call(o)))},m(r,u){S(r,e,u),w(e,n),w(n,i);for(let t=0;t<d.length;t+=1)d[t].m(e,null);B(e,t[5]),S(r,s,u),S(r,o,u),w(o,a),w(a,c);for(let t=0;t<p.length;t+=1)p[t].m(o,null);B(o,t[6]),l||(h=[I(e,"change",t[11]),I(o,"change",t[12])],l=!0)},p(t,n){if(0&n){let i;for(u=du,i=0;i<u.length;i+=1){const s=qd(t,u,i);d[i]?d[i].p(s,n):(d[i]=Kd(s),d[i].c(),d[i].m(e,null))}for(;i<d.length;i+=1)d[i].d(1);d.length=u.length}if(32&n[0]&&B(e,t[5]),0&n){let e;for(f=fu,e=0;e<f.length;e+=1){const i=Ud(t,f,e);p[e]?p[e].p(i,n):(p[e]=Zd(i),p[e].c(),p[e].m(o,null))}for(;e<p.length;e+=1)p[e].d(1);p.length=f.length}64&n[0]&&B(o,t[6])},d(t){t&&T(e),M(d,t),t&&T(s),t&&T(o),M(p,t),l=!1,r(h)}}}function Jd(t){let e,n,i;return{c(){e=A("input"),D(e,"autocomplete","off"),D(e,"autocapitalize","off")},m(s,r){S(s,e,r),F(e,t[2]),t[14](e),n||(i=[I(e,"input",t[13]),I(e,"keypress",t[15])],n=!0)},p(t,n){4&n[0]&&e.value!==t[2]&&F(e,t[2])},d(s){s&&T(e),t[14](null),n=!1,r(i)}}}function tf(t){let e;return{c(){e=E("Custom")},m(t,n){S(t,e,n)},d(t){t&&T(e)}}}function ef(t){let e,n,i,s,r,o,a,c,l=t[22].name+"";return o=new Oe({props:{primary:!0,title:"Add to chord playlist",icon:Oi}}),o.$on("click",(function(){return t[17](t[22])})),{c(){e=A("tr"),n=A("td"),i=E(l),s=k(),r=A("td"),Pt(o.$$.fragment),a=k(),D(r,"class","buttonColumn svelte-agvkw1")},m(t,l){S(t,e,l),w(e,n),w(n,i),w(e,s),w(e,r),It(o,r,null),w(e,a),c=!0},p(e,n){t=e,(!c||16&n[0])&&l!==(l=t[22].name+"")&&L(i,l)},i(t){c||(xt(o.$$.fragment,t),c=!0)},o(t){Ct(o.$$.fragment,t),c=!1},d(t){t&&T(e),Dt(o)}}}function nf(t){let e,n,i,s,r,o,a,c,l,h,u,d,f,p,m,g,v,_,y,b,x;r=new Be({props:{label:"Tonic/octave",grouped:!0,$$slots:{default:[Qd]},$$scope:{ctx:t}}}),h=new Be({props:{label:"Name",$$slots:{default:[Jd]},$$scope:{ctx:t}}}),y=new Oe({props:{primary:!0,outline:!0,icon:Oi,$$slots:{default:[tf]},$$scope:{ctx:t}}}),y.$on("click",t[16]);let C=t[4],O=[];for(let e=0;e<C.length;e+=1)O[e]=ef(Xd(t,C,e));const E=t=>Ct(O[t],1,1,(()=>{O[t]=null}));return{c(){e=A("div"),n=A("fieldset"),i=A("legend"),i.textContent="Parameters",s=k(),Pt(r.$$.fragment),o=k(),a=A("fieldset"),c=A("legend"),c.textContent="Search",l=k(),Pt(h.$$.fragment),u=k(),d=A("div"),f=A("table"),p=A("thead"),m=A("tr"),g=A("th"),g.textContent="Name",v=k(),_=A("th"),Pt(y.$$.fragment),b=k();for(let t=0;t<O.length;t+=1)O[t].c();D(n,"class","svelte-agvkw1"),D(a,"class","svelte-agvkw1"),D(e,"class","formContainer svelte-agvkw1"),D(g,"class","svelte-agvkw1"),D(_,"class","buttonColumn svelte-agvkw1"),D(f,"class","striped"),D(d,"class","tableContainer svelte-agvkw1")},m(C,T){S(C,e,T),w(e,n),w(n,i),w(n,s),It(r,n,null),w(e,o),w(e,a),w(a,c),w(a,l),It(h,a,null),S(C,u,T),S(C,d,T),w(d,f),w(f,p),w(p,m),w(m,g),w(m,v),w(m,_),It(y,_,null),w(f,b);for(let t=0;t<O.length;t+=1)O[t].m(f,null);t[18](d),x=!0},p(t,e){const n={};96&e[0]|1&e[1]&&(n.$$scope={dirty:e,ctx:t}),r.$set(n);const i={};23&e[0]|1&e[1]&&(i.$$scope={dirty:e,ctx:t}),h.$set(i);const s={};if(1&e[1]&&(s.$$scope={dirty:e,ctx:t}),y.$set(s),144&e[0]){let n;for(C=t[4],n=0;n<C.length;n+=1){const i=Xd(t,C,n);O[n]?(O[n].p(i,e),xt(O[n],1)):(O[n]=ef(i),O[n].c(),xt(O[n],1),O[n].m(f,null))}for(yt(),n=C.length;n<O.length;n+=1)E(n);bt()}},i(t){if(!x){xt(r.$$.fragment,t),xt(h.$$.fragment,t),xt(y.$$.fragment,t);for(let t=0;t<C.length;t+=1)xt(O[t]);x=!0}},o(t){Ct(r.$$.fragment,t),Ct(h.$$.fragment,t),Ct(y.$$.fragment,t),O=O.filter(Boolean);for(let t=0;t<O.length;t+=1)Ct(O[t]);x=!1},d(n){n&&T(e),Dt(r),Dt(h),n&&T(u),n&&T(d),Dt(y),M(O,n),t[18](null)}}}function sf(t){let e;return{c(){e=A("h4"),e.textContent="Chord progressions",D(e,"slot","header")},m(t,n){S(t,e,n)},d(t){t&&T(e)}}}function rf(t){let e;return{c(){e=E("Close")},m(t,n){S(t,e,n)},d(t){t&&T(e)}}}function of(t){let e,n,i;return n=new Oe({props:{clear:!0,$$slots:{default:[rf]},$$scope:{ctx:t}}}),n.$on("click",t[10]),{c(){e=A("div"),Pt(n.$$.fragment),D(e,"slot","footer"),D(e,"class","is-right")},m(t,s){S(t,e,s),It(n,e,null),i=!0},p(t,e){const i={};1&e[1]&&(i.$$scope={dirty:e,ctx:t}),n.$set(i)},i(t){i||(xt(n.$$.fragment,t),i=!0)},o(t){Ct(n.$$.fragment,t),i=!1},d(t){t&&T(e),Dt(n)}}}function af(t){let e,n;return e=new le({props:{style:"display: flex; flex-direction: column;",$$slots:{footer:[of],header:[sf],default:[nf]},$$scope:{ctx:t}}}),{c(){Pt(e.$$.fragment)},m(t,i){It(e,t,i),n=!0},p(t,n){const i={};127&n[0]|1&n[1]&&(i.$$scope={dirty:n,ctx:t}),e.$set(i)},i(t){n||(xt(e.$$.fragment,t),n=!0)},o(t){Ct(e.$$.fragment,t),n=!1},d(t){Dt(e,t)}}}function cf(t){let e,n,i;function s(e){t[19](e)}let r={style:"width: 80vw; height: 80vh; max-width: 800px;",$$slots:{default:[af]},$$scope:{ctx:t}};return void 0!==t[0]&&(r.open=t[0]),e=new Xe({props:r}),it.push((()=>kt(e,"open",s))),{c(){Pt(e.$$.fragment)},m(t,n){It(e,t,n),i=!0},p(t,i){const s={};127&i[0]|1&i[1]&&(s.$$scope={dirty:i,ctx:t}),!n&&1&i[0]&&(n=!0,s.open=t[0],lt((()=>n=!1))),e.$set(s)},i(t){i||(xt(e.$$.fragment,t),i=!0)},o(t){Ct(e.$$.fragment,t),i=!1},d(t){Dt(e,t)}}}function lf(t,e,n){let i,s;h(t,Td,(t=>n(20,i=t))),h(t,Md,(t=>n(21,s=t)));let r,o,a,c,l,{open:u}=e,{addToChordPlaylist:d}=e,f="";function p(t){const e=xi.fromProgression(t,r||i,o||s+1);d(...e)}function m(){const t=window.prompt("Enter chord progression in interval notation:").split(/[\s-]/);try{p(t),n(0,u=!1)}catch(t){window.alert(t.message)}}return t.$$set=t=>{"open"in t&&n(0,u=t.open),"addToChordPlaylist"in t&&n(9,d=t.addToChordPlaylist)},t.$$.update=()=>{if(28&t.$$.dirty[0]){if(n(4,l=Yd),f&&f.length){const t=new ys(l,{keys:["name"]});n(4,l=t.search(f).map((t=>t.item)))}c&&n(3,c.scrollTop=0,c)}3&t.$$.dirty[0]&&u&&(null==a||a.focus())},[u,a,f,c,l,r,o,p,m,d,()=>{n(0,u=!1)},function(){r=V(this),n(5,r)},function(){o=V(this),n(6,o)},function(){f=this.value,n(2,f)},function(t){it[t?"unshift":"push"]((()=>{a=t,n(1,a)}))},t=>{"Enter"===t.key&&(t.preventDefault(),l[0]&&(n(0,u=!1),p(l[0].progression)))},()=>m(),t=>p(t.progression),function(t){it[t?"unshift":"push"]((()=>{c=t,n(3,c),n(2,f),n(4,l)}))},function(t){u=t,n(0,u)}]}class hf extends $t{constructor(t){super(),jt(this,t,lf,cf,a,{open:0,addToChordPlaylist:9},[-1,-1])}}function uf(t,e,n){const i=t.slice();return i[29]=e[n],i[31]=n,i}function df(t,e,n){const i=t.slice();return i[29]=e[n],i[31]=n,i}function ff(t){let e;return{c(){e=E("Chords")},m(t,n){S(t,e,n)},d(t){t&&T(e)}}}function pf(t){let e;return{c(){e=E("Chord progressions")},m(t,n){S(t,e,n)},d(t){t&&T(e)}}}function mf(t){let e;return{c(){e=E("Clear")},m(t,n){S(t,e,n)},d(t){t&&T(e)}}}function gf(t){let e,n,i,s,r,o;return e=new Oe({props:{icon:"M16,9H13V14.5A2.5,2.5 0 0,1 10.5,17A2.5,2.5 0 0,1 8,14.5A2.5,2.5 0 0,1 10.5,12C11.07,12 11.58,12.19 12,12.5V7H16M19,3H5A2,2 0 0,0 3,5V19A2,2 0 0,0 5,21H19A2,2 0 0,0 21,19V5A2,2 0 0,0 19,3Z",$$slots:{default:[ff]},$$scope:{ctx:t}}}),e.$on("click",t[19]),i=new Oe({props:{icon:"M4,6H2V20A2,2 0 0,0 4,22H18V20H4M18,7H15V12.5A2.5,2.5 0 0,1 12.5,15A2.5,2.5 0 0,1 10,12.5A2.5,2.5 0 0,1 12.5,10C13.07,10 13.58,10.19 14,10.5V5H18M20,2H8A2,2 0 0,0 6,4V16A2,2 0 0,0 8,18H20A2,2 0 0,0 22,16V4A2,2 0 0,0 20,2Z",$$slots:{default:[pf]},$$scope:{ctx:t}}}),i.$on("click",t[20]),r=new Oe({props:{error:!0,icon:Ai,$$slots:{default:[mf]},$$scope:{ctx:t}}}),r.$on("click",t[21]),{c(){Pt(e.$$.fragment),n=k(),Pt(i.$$.fragment),s=k(),Pt(r.$$.fragment)},m(t,a){It(e,t,a),S(t,n,a),It(i,t,a),S(t,s,a),It(r,t,a),o=!0},p(t,n){const s={};4&n[1]&&(s.$$scope={dirty:n,ctx:t}),e.$set(s);const o={};4&n[1]&&(o.$$scope={dirty:n,ctx:t}),i.$set(o);const a={};4&n[1]&&(a.$$scope={dirty:n,ctx:t}),r.$set(a)},i(t){o||(xt(e.$$.fragment,t),xt(i.$$.fragment,t),xt(r.$$.fragment,t),o=!0)},o(t){Ct(e.$$.fragment,t),Ct(i.$$.fragment,t),Ct(r.$$.fragment,t),o=!1},d(t){Dt(e,t),t&&T(n),Dt(i,t),t&&T(s),Dt(r,t)}}}function vf(t){let e;return{c(){e=A("h4"),e.textContent="Chord history",D(e,"class","svelte-1p5h6tj")},m(t,n){S(t,e,n)},d(t){t&&T(e)}}}function _f(t){let e;return{c(){e=A("h4"),e.textContent="Chord playlist",D(e,"class","svelte-1p5h6tj")},m(t,n){S(t,e,n)},d(t){t&&T(e)}}}function yf(t){let e,n,i,s;return e=new ne({props:{$$slots:{default:[vf]},$$scope:{ctx:t}}}),i=new ne({props:{$$slots:{default:[_f]},$$scope:{ctx:t}}}),{c(){Pt(e.$$.fragment),n=k(),Pt(i.$$.fragment)},m(t,r){It(e,t,r),S(t,n,r),It(i,t,r),s=!0},p(t,n){const s={};4&n[1]&&(s.$$scope={dirty:n,ctx:t}),e.$set(s);const r={};4&n[1]&&(r.$$scope={dirty:n,ctx:t}),i.$set(r)},i(t){s||(xt(e.$$.fragment,t),xt(i.$$.fragment,t),s=!0)},o(t){Ct(e.$$.fragment,t),Ct(i.$$.fragment,t),s=!1},d(t){Dt(e,t),t&&T(n),Dt(i,t)}}}function bf(t){let e;return{c(){e=A("div"),e.textContent="empty",D(e,"class","text-grey")},m(t,n){S(t,e,n)},d(t){t&&T(e)}}}function xf(t){let e,n,i,s,r;function o(...e){return t[22](t[29],...e)}return n=new ve({props:{src:"M4,11V13H16L10.5,18.5L11.92,19.92L19.84,12L11.92,4.08L10.5,5.5L16,11H4Z",size:"24px"}}),{c(){e=A("button"),Pt(n.$$.fragment),D(e,"slot","action")},m(t,a){S(t,e,a),It(n,e,null),i=!0,s||(r=I(e,"click",o),s=!0)},p(e,n){t=e},i(t){i||(xt(n.$$.fragment,t),i=!0)},o(t){Ct(n.$$.fragment,t),i=!1},d(t){t&&T(e),Dt(n),s=!1,r()}}}function Cf(e,n){let i,s,r,o,a,c,l,h=t;return s=new Mi({props:{chord:n[29],$$slots:{action:[xf]},$$scope:{ctx:n}}}),s.$on("click",(function(...t){return n[23](n[29],...t)})),{key:e,first:null,c(){i=A("div"),Pt(s.$$.fragment),r=k(),this.first=i},m(t,e){S(t,i,e),It(s,i,null),w(i,r),l=!0},p(t,e){n=t;const i={};8&e[0]&&(i.chord=n[29]),8&e[0]|4&e[1]&&(i.$$scope={dirty:e,ctx:n}),s.$set(i)},r(){c=i.getBoundingClientRect()},f(){Z(i),h(),Q(i,c)},a(){h(),h=K(i,c,Ei,{})},i(t){l||(xt(s.$$.fragment,t),ct((()=>{a&&a.end(1),o||(o=St(i,We,{})),o.start()})),l=!0)},o(t){Ct(s.$$.fragment,t),o&&o.invalidate(),a=Tt(i,He,{x:100}),l=!1},d(t){t&&T(i),Dt(s),t&&a&&a.end()}}}function wf(t){let e,n,i,s=[],r=new Map,o=0===t[3].length&&bf(),a=t[3];const c=t=>t[31];for(let e=0;e<a.length;e+=1){let n=df(t,a,e),i=c(n);r.set(i,s[e]=Cf(i,n))}return{c(){o&&o.c(),e=k();for(let t=0;t<s.length;t+=1)s[t].c();n=P()},m(t,r){o&&o.m(t,r),S(t,e,r);for(let e=0;e<s.length;e+=1)s[e].m(t,r);S(t,n,r),i=!0},p(t,i){if(0===t[3].length?o||(o=bf(),o.c(),o.m(e.parentNode,e)):o&&(o.d(1),o=null),2184&i[0]){a=t[3],yt();for(let t=0;t<s.length;t+=1)s[t].r();s=Ot(s,i,c,1,t,a,r,n.parentNode,At,Cf,n,df);for(let t=0;t<s.length;t+=1)s[t].a();bt()}},i(t){if(!i){for(let t=0;t<a.length;t+=1)xt(s[t]);i=!0}},o(t){for(let t=0;t<s.length;t+=1)Ct(s[t]);i=!1},d(t){o&&o.d(t),t&&T(e);for(let e=0;e<s.length;e+=1)s[e].d(t);t&&T(n)}}}function Sf(t){let e;return{c(){e=A("div"),e.textContent="empty",D(e,"class","text-grey")},m(t,n){S(t,e,n)},d(t){t&&T(e)}}}function Tf(t){let e,n,i,s,r;function o(...e){return t[24](t[31],...e)}return n=new ve({props:{src:Ai,size:"24px"}}),{c(){e=A("button"),Pt(n.$$.fragment),D(e,"slot","action")},m(t,a){S(t,e,a),It(n,e,null),i=!0,s||(r=I(e,"click",o),s=!0)},p(e,n){t=e},i(t){i||(xt(n.$$.fragment,t),i=!0)},o(t){Ct(n.$$.fragment,t),i=!1},d(t){t&&T(e),Dt(n),s=!1,r()}}}function Mf(e,n){let i,s,r,o,a,c,l,h,u=t;return s=new Mi({props:{chord:n[29],active:n[31]===n[1],$$slots:{action:[Tf]},$$scope:{ctx:n}}}),s.$on("click",(function(){return n[25](n[31])})),{key:e,first:null,c(){i=A("div"),Pt(s.$$.fragment),r=k(),D(i,"id",o=`chordPlaylistItem-${n[31]}`),this.first=i},m(t,e){S(t,i,e),It(s,i,null),w(i,r),h=!0},p(t,e){n=t;const r={};4&e[0]&&(r.chord=n[29]),6&e[0]&&(r.active=n[31]===n[1]),4&e[0]|4&e[1]&&(r.$$scope={dirty:e,ctx:n}),s.$set(r),(!h||4&e[0]&&o!==(o=`chordPlaylistItem-${n[31]}`))&&D(i,"id",o)},r(){l=i.getBoundingClientRect()},f(){Z(i),u(),Q(i,l)},a(){u(),u=K(i,l,Ei,{})},i(t){h||(xt(s.$$.fragment,t),ct((()=>{c&&c.end(1),a||(a=St(i,We,{})),a.start()})),h=!0)},o(t){Ct(s.$$.fragment,t),a&&a.invalidate(),c=Tt(i,He,{x:100}),h=!1},d(t){t&&T(i),Dt(s),t&&c&&c.end()}}}function Af(t){let e,n,i,s=[],r=new Map,o=0===t[2].length&&Sf(),a=t[2];const c=t=>t[29];for(let e=0;e<a.length;e+=1){let n=uf(t,a,e),i=c(n);r.set(i,s[e]=Mf(i,n))}return{c(){o&&o.c(),e=k();for(let t=0;t<s.length;t+=1)s[t].c();n=P()},m(t,r){o&&o.m(t,r),S(t,e,r);for(let e=0;e<s.length;e+=1)s[e].m(t,r);S(t,n,r),i=!0},p(t,i){if(0===t[2].length?o||(o=Sf(),o.c(),o.m(e.parentNode,e)):o&&(o.d(1),o=null),1286&i[0]){a=t[2],yt();for(let t=0;t<s.length;t+=1)s[t].r();s=Ot(s,i,c,1,t,a,r,n.parentNode,At,Mf,n,uf);for(let t=0;t<s.length;t+=1)s[t].a();bt()}},i(t){if(!i){for(let t=0;t<a.length;t+=1)xt(s[t]);i=!0}},o(t){for(let t=0;t<s.length;t+=1)Ct(s[t]);i=!1},d(t){o&&o.d(t),t&&T(e);for(let e=0;e<s.length;e+=1)s[e].d(t);t&&T(n)}}}function Of(t){let e,n,i,s;return e=new ne({props:{$$slots:{default:[wf]},$$scope:{ctx:t}}}),i=new ne({props:{$$slots:{default:[Af]},$$scope:{ctx:t}}}),{c(){Pt(e.$$.fragment),n=k(),Pt(i.$$.fragment)},m(t,r){It(e,t,r),S(t,n,r),It(i,t,r),s=!0},p(t,n){const s={};8&n[0]|4&n[1]&&(s.$$scope={dirty:n,ctx:t}),e.$set(s);const r={};6&n[0]|4&n[1]&&(r.$$scope={dirty:n,ctx:t}),i.$set(r)},i(t){s||(xt(e.$$.fragment,t),xt(i.$$.fragment,t),s=!0)},o(t){Ct(e.$$.fragment,t),Ct(i.$$.fragment,t),s=!1},d(t){Dt(e,t),t&&T(n),Dt(i,t)}}}function Ef(t){let e,n,i,s,r,o,a,c,l,h,u,d,f,p,m,g,v,_,y,b,x=(t[0]?.chord.name||"none")+"";function C(e){t[16](e)}let M={addToChordPlaylist:t[15]};function O(e){t[18](e)}void 0!==t[4]&&(M.open=t[4]),n=new zd({props:M}),it.push((()=>kt(n,"open",C)));let P={addToChordPlaylist:t[17]};return void 0!==t[5]&&(P.open=t[5]),r=new hf({props:P}),it.push((()=>kt(r,"open",O))),p=new Be({props:{gapless:!0,$$slots:{default:[gf]},$$scope:{ctx:t}}}),g=new Jt({props:{$$slots:{default:[yf]},$$scope:{ctx:t}}}),y=new Jt({props:{$$slots:{default:[Of]},$$scope:{ctx:t}}}),{c(){e=A("div"),Pt(n.$$.fragment),s=k(),Pt(r.$$.fragment),a=k(),c=A("div"),l=A("h2"),h=E("Chord: "),u=E(x),d=k(),f=A("div"),Pt(p.$$.fragment),m=k(),Pt(g.$$.fragment),v=k(),_=A("div"),Pt(y.$$.fragment),D(l,"class","svelte-1p5h6tj"),D(c,"class","chord svelte-1p5h6tj"),D(f,"class","toolbar svelte-1p5h6tj"),D(_,"class","chordContainerRow svelte-1p5h6tj"),D(e,"class","chordContainerWrapper svelte-1p5h6tj")},m(t,i){S(t,e,i),It(n,e,null),w(e,s),It(r,e,null),w(e,a),w(e,c),w(c,l),w(l,h),w(l,u),w(e,d),w(e,f),It(p,f,null),w(e,m),It(g,e,null),w(e,v),w(e,_),It(y,_,null),b=!0},p(t,e){const s={};!i&&16&e[0]&&(i=!0,s.open=t[4],lt((()=>i=!1))),n.$set(s);const a={};!o&&32&e[0]&&(o=!0,a.open=t[5],lt((()=>o=!1))),r.$set(a),(!b||1&e[0])&&x!==(x=(t[0]?.chord.name||"none")+"")&&L(u,x);const c={};48&e[0]|4&e[1]&&(c.$$scope={dirty:e,ctx:t}),p.$set(c);const l={};4&e[1]&&(l.$$scope={dirty:e,ctx:t}),g.$set(l);const h={};14&e[0]|4&e[1]&&(h.$$scope={dirty:e,ctx:t}),y.$set(h)},i(t){b||(xt(n.$$.fragment,t),xt(r.$$.fragment,t),xt(p.$$.fragment,t),xt(g.$$.fragment,t),xt(y.$$.fragment,t),b=!0)},o(t){Ct(n.$$.fragment,t),Ct(r.$$.fragment,t),Ct(p.$$.fragment,t),Ct(g.$$.fragment,t),Ct(y.$$.fragment,t),b=!1},d(t){t&&T(e),Dt(n),Dt(r),Dt(p),Dt(g),Dt(y)}}}function kf(t,e,n){let i;var s;let{controller:r}=e;const{notesPressed:o}=r;let a;h(t,o,(t=>n(14,i=t)));let c=0,l=null;function u(t){l&&clearTimeout(l),t&&(l=setTimeout((()=>{0!==p.length&&t.equals(p[0])||(p.splice(0,0,t),n(3,p=p.slice(0,6)),l=null)}),250))}let d,f,p=[],m=[];function g(...t){for(const e of t)m.push(e);n(2,m),y(0)}function v(t){n(1,c=0),m.splice(t,1),n(2,m),y(0)}function _(){n(1,c=0),n(2,m=[]),y(0)}function y(t){var e;n(1,c=t),null===(e=document.getElementById(`chordPlaylistItem-${t}`))||void 0===e||e.scrollIntoView({block:"end",behavior:"smooth"}),r.highlightClear(),m[c]&&b(m[c])}function b(t){r.highlightClear(),r.highlightNotes(t.notes)}return t.$$set=t=>{"controller"in t&&n(12,r=t.controller)},t.$$.update=()=>{24583&t.$$.dirty[0]&&(n(0,a=i.length>1?xi.fromNotes(i):null),ki.set(a),a?(u(a),m.length&&(null===n(13,s=m[c])||void 0===s?void 0:s.equals(a))&&(c===m.length-1?y(0):y(c+1))):u())},[a,c,m,p,d,f,o,g,v,_,y,b,r,s,i,(...t)=>g(...t),function(t){d=t,n(4,d)},(...t)=>g(...t),function(t){f=t,n(5,f)},()=>{n(4,d=!0)},()=>{n(5,f=!0)},()=>_(),(t,e)=>{e.stopPropagation(),g(t)},(t,e)=>{e.stopPropagation(),b(t)},(t,e)=>{e.stopPropagation(),v(t)},t=>y(t)]}class Pf extends $t{constructor(t){super(),jt(this,t,kf,Ef,a,{controller:12},[-1,-1])}}function If(e){let n,i;return{c:t,m(t,s){n||(i=I(window,"keydown",e[0]),n=!0)},p:t,i:t,o:t,d(t){n=!1,i()}}}function Df(t){return[function(t){"ArrowUp"===t.key?(t.preventDefault(),Md.update((t=>gu(t,fu)))):"ArrowDown"===t.key?(t.preventDefault(),Md.update((t=>vu(t,fu)))):"ArrowRight"===t.key?(t.preventDefault(),Td.update((t=>gu(t,du)))):"ArrowLeft"===t.key&&(t.preventDefault(),Td.update((t=>vu(t,du))))}]}class Rf extends $t{constructor(t){super(),jt(this,t,Df,If,a,{})}}function jf(t,e,n){const i=t.slice();return i[13]=e[n],i}function $f(t,e,n){const i=t.slice();return i[16]=e[n],i}function Lf(t,e,n){const i=t.slice();return i[19]=e[n],i}function Ff(t,e,n){const i=t.slice();return i[10]=e[n],i}function Nf(t){let e;return{c(){e=E("Settings")},m(t,n){S(t,e,n)},d(t){t&&T(e)}}}function Bf(t){let e,n;return e=new Oe({props:{slot:"left",icon:"M12,15.5A3.5,3.5 0 0,1 8.5,12A3.5,3.5 0 0,1 12,8.5A3.5,3.5 0 0,1 15.5,12A3.5,3.5 0 0,1 12,15.5M19.43,12.97C19.47,12.65 19.5,12.33 19.5,12C19.5,11.67 19.47,11.34 19.43,11L21.54,9.37C21.73,9.22 21.78,8.95 21.66,8.73L19.66,5.27C19.54,5.05 19.27,4.96 19.05,5.05L16.56,6.05C16.04,5.66 15.5,5.32 14.87,5.07L14.5,2.42C14.46,2.18 14.25,2 14,2H10C9.75,2 9.54,2.18 9.5,2.42L9.13,5.07C8.5,5.32 7.96,5.66 7.44,6.05L4.95,5.05C4.73,4.96 4.46,5.05 4.34,5.27L2.34,8.73C2.21,8.95 2.27,9.22 2.46,9.37L4.57,11C4.53,11.34 4.5,11.67 4.5,12C4.5,12.33 4.53,12.65 4.57,12.97L2.46,14.63C2.27,14.78 2.21,15.05 2.34,15.27L4.34,18.73C4.46,18.95 4.73,19.03 4.95,18.95L7.44,17.94C7.96,18.34 8.5,18.68 9.13,18.93L9.5,21.58C9.54,21.82 9.75,22 10,22H14C14.25,22 14.46,21.82 14.5,21.58L14.87,18.93C15.5,18.67 16.04,18.34 16.56,17.94L19.05,18.95C19.27,19.03 19.54,18.95 19.66,18.73L21.66,15.27C21.78,15.05 21.73,14.78 21.54,14.63L19.43,12.97Z",$$slots:{default:[Nf]},$$scope:{ctx:t}}}),e.$on("click",t[9]),{c(){Pt(e.$$.fragment)},m(t,i){It(e,t,i),n=!0},p(t,n){const i={};4194304&n&&(i.$$scope={dirty:n,ctx:t}),e.$set(i)},i(t){n||(xt(e.$$.fragment,t),n=!0)},o(t){Ct(e.$$.fragment,t),n=!1},d(t){Dt(e,t)}}}function Vf(e){let n,i,s,r=e[19]+"";return{c(){n=A("option"),i=E(r),s=k(),n.__value=e[19],n.value=n.__value},m(t,e){S(t,n,e),w(n,i),w(n,s)},p:t,d(t){t&&T(n)}}}function Wf(e){let n,i,s,r=e[16]+"";return{c(){n=A("option"),i=E(r),s=k(),n.__value=e[16],n.value=n.__value},m(t,e){S(t,n,e),w(n,i),w(n,s)},p:t,d(t){t&&T(n)}}}function Hf(e){let n,i,s,r=e[13]+"";return{c(){n=A("option"),i=E(r),s=k(),n.__value=e[13],n.value=n.__value},m(t,e){S(t,n,e),w(n,i),w(n,s)},p:t,d(t){t&&T(n)}}}function Gf(t){let e,n,i,s,o,a,c,l,h=du,u=[];for(let e=0;e<h.length;e+=1)u[e]=Vf(Lf(t,h,e));let d=fu,f=[];for(let e=0;e<d.length;e+=1)f[e]=Wf($f(t,d,e));let p=wd,m=[];for(let e=0;e<p.length;e+=1)m[e]=Hf(jf(t,p,e));return{c(){e=A("div"),n=A("select");for(let t=0;t<u.length;t+=1)u[t].c();i=k(),s=A("select");for(let t=0;t<f.length;t+=1)f[t].c();o=k(),a=A("select");for(let t=0;t<m.length;t+=1)m[t].c();D(n,"title","Root"),N(n,"width","64px"),void 0===t[2]&&ct((()=>t[6].call(n))),D(s,"title","Octave"),N(s,"width","64px"),void 0===t[3]&&ct((()=>t[7].call(s))),D(a,"title","Scale"),N(a,"width","240px"),void 0===t[4]&&ct((()=>t[8].call(a))),D(e,"slot","center"),D(e,"class","nav-input-container")},m(r,h){S(r,e,h),w(e,n);for(let t=0;t<u.length;t+=1)u[t].m(n,null);B(n,t[2]),w(e,i),w(e,s);for(let t=0;t<f.length;t+=1)f[t].m(s,null);B(s,t[3]),w(e,o),w(e,a);for(let t=0;t<m.length;t+=1)m[t].m(a,null);B(a,t[4]),c||(l=[I(n,"change",t[6]),I(s,"change",t[7]),I(a,"change",t[8])],c=!0)},p(t,e){if(0&e){let i;for(h=du,i=0;i<h.length;i+=1){const s=Lf(t,h,i);u[i]?u[i].p(s,e):(u[i]=Vf(s),u[i].c(),u[i].m(n,null))}for(;i<u.length;i+=1)u[i].d(1);u.length=h.length}if(4&e&&B(n,t[2]),0&e){let n;for(d=fu,n=0;n<d.length;n+=1){const i=$f(t,d,n);f[n]?f[n].p(i,e):(f[n]=Wf(i),f[n].c(),f[n].m(s,null))}for(;n<f.length;n+=1)f[n].d(1);f.length=d.length}if(8&e&&B(s,t[3]),0&e){let n;for(p=wd,n=0;n<p.length;n+=1){const i=jf(t,p,n);m[n]?m[n].p(i,e):(m[n]=Hf(i),m[n].c(),m[n].m(a,null))}for(;n<m.length;n+=1)m[n].d(1);m.length=p.length}16&e&&B(a,t[4])},d(t){t&&T(e),M(u,t),M(f,t),M(m,t),c=!1,r(l)}}}function zf(e){let n,i,s,r=e[10].getMeta().label+"";return{c(){n=A("option"),i=E(r),s=k(),n.__value=e[10],n.value=n.__value},m(t,e){S(t,n,e),w(n,i),w(n,s)},p:t,d(t){t&&T(n)}}}function Yf(t){let e,n,i,s,r=xd,o=[];for(let e=0;e<r.length;e+=1)o[e]=zf(Ff(t,r,e));return{c(){e=A("div"),n=A("select");for(let t=0;t<o.length;t+=1)o[t].c();D(n,"title","Layout"),N(n,"width","240px"),void 0===t[1]&&ct((()=>t[5].call(n))),D(e,"slot","right"),D(e,"class","nav-input-container")},m(r,a){S(r,e,a),w(e,n);for(let t=0;t<o.length;t+=1)o[t].m(n,null);B(n,t[1]),i||(s=I(n,"change",t[5]),i=!0)},p(t,e){if(0&e){let i;for(r=xd,i=0;i<r.length;i+=1){const s=Ff(t,r,i);o[i]?o[i].p(s,e):(o[i]=zf(s),o[i].c(),o[i].m(n,null))}for(;i<o.length;i+=1)o[i].d(1);o.length=r.length}2&e&&B(n,t[1])},d(t){t&&T(e),M(o,t),i=!1,s()}}}function Xf(t){let e,n;return e=new Kt({props:{$$slots:{right:[Yf],center:[Gf],left:[Bf]},$$scope:{ctx:t}}}),{c(){Pt(e.$$.fragment)},m(t,i){It(e,t,i),n=!0},p(t,[n]){const i={};4194335&n&&(i.$$scope={dirty:n,ctx:t}),e.$set(i)},i(t){n||(xt(e.$$.fragment,t),n=!0)},o(t){Ct(e.$$.fragment,t),n=!1},d(t){Dt(e,t)}}}function Uf(t,e,n){let i,s,r,o;h(t,Cd,(t=>n(1,i=t))),h(t,Td,(t=>n(2,s=t))),h(t,Md,(t=>n(3,r=t))),h(t,Sd,(t=>n(4,o=t)));let{configModalOpen:a}=e;return t.$$set=t=>{"configModalOpen"in t&&n(0,a=t.configModalOpen)},[a,i,s,r,o,function(){i=V(this),Cd.set(i)},function(){s=V(this),Td.set(s)},function(){r=V(this),Md.set(r)},function(){o=V(this),Sd.set(o)},()=>n(0,a=!0)]}class qf extends $t{constructor(t){super(),jt(this,t,Uf,Xf,a,{configModalOpen:0})}}function Kf(t,e,n){const i=t.slice();return i[4]=e[n],i}function Zf(t){let e,n,i,s,r=t[4].name+"";return{c(){e=A("option"),n=E(r),i=k(),e.__value=s=t[4].id,e.value=e.__value},m(t,s){S(t,e,s),w(e,n),w(e,i)},p(t,i){2&i&&r!==(r=t[4].name+"")&&L(n,r),2&i&&s!==(s=t[4].id)&&(e.__value=s,e.value=e.__value)},d(t){t&&T(e)}}}function Qf(e){let n,i,s,r,o=e[1],a=[];for(let t=0;t<o.length;t+=1)a[t]=Zf(Kf(e,o,t));return{c(){n=A("select"),i=A("option"),i.textContent="None";for(let t=0;t<a.length;t+=1)a[t].c();i.__value=null,i.value=i.__value,void 0===e[0]&&ct((()=>e[3].call(n)))},m(t,o){S(t,n,o),w(n,i);for(let t=0;t<a.length;t+=1)a[t].m(n,null);B(n,e[0]),s||(r=I(n,"change",e[3]),s=!0)},p(t,[e]){if(2&e){let i;for(o=t[1],i=0;i<o.length;i+=1){const s=Kf(t,o,i);a[i]?a[i].p(s,e):(a[i]=Zf(s),a[i].c(),a[i].m(n,null))}for(;i<a.length;i+=1)a[i].d(1);a.length=o.length}3&e&&B(n,t[0])},i:t,o:t,d(t){t&&T(n),M(a,t),s=!1,r()}}}function Jf(t,e,n){let{type:i}=e,{value:s=null}=e,r="input"===i?Bt.inputs:Bt.outputs;return Bt.addListener("connected",(()=>{n(1,r="input"===i?Bt.inputs:Bt.outputs)})),Bt.addListener("disconnected",(()=>{n(1,r="input"===i?Bt.inputs:Bt.outputs),r.find((t=>t.id===s))||n(0,s=null)})),t.$$set=t=>{"type"in t&&n(2,i=t.type),"value"in t&&n(0,s=t.value)},[s,r,i,function(){s=V(this),n(0,s),n(1,r)}]}class tp extends $t{constructor(t){super(),jt(this,t,Jf,Qf,a,{type:2,value:0})}}function ep(t,e,n){const i=t.slice();return i[19]=e[n],i}function np(t,e,n){const i=t.slice();return i[22]=e[n],i}function ip(t,e,n){const i=t.slice();return i[25]=e[n],i}function sp(t,e,n){const i=t.slice();return i[28]=e[n],i}function rp(t,e,n){const i=t.slice();return i[28]=e[n],i}function op(t,e,n){const i=t.slice();return i[28]=e[n],i}function ap(t){let e,n,i,s,r,o;function a(e){t[10](e)}let c={type:"input"};function l(e){t[11](e)}void 0!==t[1]&&(c.value=t[1]),e=new tp({props:c}),it.push((()=>kt(e,"value",a)));let h={type:"output"};return void 0!==t[2]&&(h.value=t[2]),s=new tp({props:h}),it.push((()=>kt(s,"value",l))),{c(){Pt(e.$$.fragment),i=k(),Pt(s.$$.fragment)},m(t,n){It(e,t,n),S(t,i,n),It(s,t,n),o=!0},p(t,i){const o={};!n&&2&i[0]&&(n=!0,o.value=t[1],lt((()=>n=!1))),e.$set(o);const a={};!r&&4&i[0]&&(r=!0,a.value=t[2],lt((()=>r=!1))),s.$set(a)},i(t){o||(xt(e.$$.fragment,t),xt(s.$$.fragment,t),o=!0)},o(t){Ct(e.$$.fragment,t),Ct(s.$$.fragment,t),o=!1},d(t){Dt(e,t),t&&T(i),Dt(s,t)}}}function cp(e){let n,i,s,r=e[28].getMeta().label+"";return{c(){n=A("option"),i=E(r),s=k(),n.__value=e[28],n.value=n.__value},m(t,e){S(t,n,e),w(n,i),w(n,s)},p:t,d(t){t&&T(n)}}}function lp(t){let e,n,i,s=vd,r=[];for(let e=0;e<s.length;e+=1)r[e]=cp(op(t,s,e));return{c(){e=A("select");for(let t=0;t<r.length;t+=1)r[t].c();void 0===t[3]&&ct((()=>t[12].call(e)))},m(s,o){S(s,e,o);for(let t=0;t<r.length;t+=1)r[t].m(e,null);B(e,t[3]),n||(i=I(e,"change",t[12]),n=!0)},p(t,n){if(0&n){let i;for(s=vd,i=0;i<s.length;i+=1){const o=op(t,s,i);r[i]?r[i].p(o,n):(r[i]=cp(o),r[i].c(),r[i].m(e,null))}for(;i<r.length;i+=1)r[i].d(1);r.length=s.length}8&n[0]&&B(e,t[3])},d(t){t&&T(e),M(r,t),n=!1,i()}}}function hp(e){let n,i,s,r=e[28].getMeta().label+"";return{c(){n=A("option"),i=E(r),s=k(),n.__value=e[28],n.value=n.__value},m(t,e){S(t,n,e),w(n,i),w(n,s)},p:t,d(t){t&&T(n)}}}function up(t){let e,n,i,s=yd,r=[];for(let e=0;e<s.length;e+=1)r[e]=hp(rp(t,s,e));return{c(){e=A("select");for(let t=0;t<r.length;t+=1)r[t].c();void 0===t[4]&&ct((()=>t[13].call(e)))},m(s,o){S(s,e,o);for(let t=0;t<r.length;t+=1)r[t].m(e,null);B(e,t[4]),n||(i=I(e,"change",t[13]),n=!0)},p(t,n){if(0&n){let i;for(s=yd,i=0;i<s.length;i+=1){const o=rp(t,s,i);r[i]?r[i].p(o,n):(r[i]=hp(o),r[i].c(),r[i].m(e,null))}for(;i<r.length;i+=1)r[i].d(1);r.length=s.length}16&n[0]&&B(e,t[4])},d(t){t&&T(e),M(r,t),n=!1,i()}}}function dp(e){let n,i,s,r=e[28].getMeta().label+"";return{c(){n=A("option"),i=E(r),s=k(),n.__value=e[28],n.value=n.__value},m(t,e){S(t,n,e),w(n,i),w(n,s)},p:t,d(t){t&&T(n)}}}function fp(t){let e,n,i,s=xd,r=[];for(let e=0;e<s.length;e+=1)r[e]=dp(sp(t,s,e));return{c(){e=A("select");for(let t=0;t<r.length;t+=1)r[t].c();void 0===t[5]&&ct((()=>t[14].call(e)))},m(s,o){S(s,e,o);for(let t=0;t<r.length;t+=1)r[t].m(e,null);B(e,t[5]),n||(i=I(e,"change",t[14]),n=!0)},p(t,n){if(0&n){let i;for(s=xd,i=0;i<s.length;i+=1){const o=sp(t,s,i);r[i]?r[i].p(o,n):(r[i]=dp(o),r[i].c(),r[i].m(e,null))}for(;i<r.length;i+=1)r[i].d(1);r.length=s.length}32&n[0]&&B(e,t[5])},d(t){t&&T(e),M(r,t),n=!1,i()}}}function pp(e){let n,i,s,r=e[25]+"";return{c(){n=A("option"),i=E(r),s=k(),n.__value=e[25],n.value=n.__value},m(t,e){S(t,n,e),w(n,i),w(n,s)},p:t,d(t){t&&T(n)}}}function mp(e){let n,i,s,r=e[22]+"";return{c(){n=A("option"),i=E(r),s=k(),n.__value=e[22],n.value=n.__value},m(t,e){S(t,n,e),w(n,i),w(n,s)},p:t,d(t){t&&T(n)}}}function gp(t){let e,n,i,s,o,a=du,c=[];for(let e=0;e<a.length;e+=1)c[e]=pp(ip(t,a,e));let l=fu,h=[];for(let e=0;e<l.length;e+=1)h[e]=mp(np(t,l,e));return{c(){e=A("select");for(let t=0;t<c.length;t+=1)c[t].c();n=k(),i=A("select");for(let t=0;t<h.length;t+=1)h[t].c();void 0===t[6]&&ct((()=>t[15].call(e))),void 0===t[7]&&ct((()=>t[16].call(i)))},m(r,a){S(r,e,a);for(let t=0;t<c.length;t+=1)c[t].m(e,null);B(e,t[6]),S(r,n,a),S(r,i,a);for(let t=0;t<h.length;t+=1)h[t].m(i,null);B(i,t[7]),s||(o=[I(e,"change",t[15]),I(i,"change",t[16])],s=!0)},p(t,n){if(0&n){let i;for(a=du,i=0;i<a.length;i+=1){const s=ip(t,a,i);c[i]?c[i].p(s,n):(c[i]=pp(s),c[i].c(),c[i].m(e,null))}for(;i<c.length;i+=1)c[i].d(1);c.length=a.length}if(64&n[0]&&B(e,t[6]),0&n){let e;for(l=fu,e=0;e<l.length;e+=1){const s=np(t,l,e);h[e]?h[e].p(s,n):(h[e]=mp(s),h[e].c(),h[e].m(i,null))}for(;e<h.length;e+=1)h[e].d(1);h.length=l.length}128&n[0]&&B(i,t[7])},d(t){t&&T(e),M(c,t),t&&T(n),t&&T(i),M(h,t),s=!1,r(o)}}}function vp(e){let n,i,s,r=e[19]+"";return{c(){n=A("option"),i=E(r),s=k(),n.__value=e[19],n.value=n.__value},m(t,e){S(t,n,e),w(n,i),w(n,s)},p:t,d(t){t&&T(n)}}}function _p(t){let e,n,i,s=wd,r=[];for(let e=0;e<s.length;e+=1)r[e]=vp(ep(t,s,e));return{c(){e=A("select");for(let t=0;t<r.length;t+=1)r[t].c();void 0===t[8]&&ct((()=>t[17].call(e)))},m(s,o){S(s,e,o);for(let t=0;t<r.length;t+=1)r[t].m(e,null);B(e,t[8]),n||(i=I(e,"change",t[17]),n=!0)},p(t,n){if(0&n){let i;for(s=wd,i=0;i<s.length;i+=1){const o=ep(t,s,i);r[i]?r[i].p(o,n):(r[i]=vp(o),r[i].c(),r[i].m(e,null))}for(;i<r.length;i+=1)r[i].d(1);r.length=s.length}256&n[0]&&B(e,t[8])},d(t){t&&T(e),M(r,t),n=!1,i()}}}function yp(t){let e;return{c(){e=E("← →")},m(t,n){S(t,e,n)},d(t){t&&T(e)}}}function bp(t){let e;return{c(){e=E("↑ ↓")},m(t,n){S(t,e,n)},d(t){t&&T(e)}}}function xp(t){let e,n,i,s,r,o,a,c,l,h,u,d,f,p,m,g,v,_,y,b,x,C,M,O,P,I,R,j,$,L,F,B;return r=new Be({props:{label:"Input/Output",grouped:!0,$$slots:{default:[ap]},$$scope:{ctx:t}}}),a=new Be({props:{label:"Controller model",$$slots:{default:[lp]},$$scope:{ctx:t}}}),p=new Be({props:{label:"Synth",$$slots:{default:[up]},$$scope:{ctx:t}}}),y=new Be({props:{label:"Layout",$$slots:{default:[fp]},$$scope:{ctx:t}}}),x=new Be({props:{label:"Root/octave",grouped:!0,$$slots:{default:[gp]},$$scope:{ctx:t}}}),M=new Be({props:{label:"Scale",$$slots:{default:[_p]},$$scope:{ctx:t}}}),j=new Re({props:{$$slots:{default:[yp]},$$scope:{ctx:t}}}),L=new Re({props:{$$slots:{default:[bp]},$$scope:{ctx:t}}}),{c(){e=A("div"),n=A("fieldset"),i=A("legend"),i.textContent="Controller",s=k(),Pt(r.$$.fragment),o=k(),Pt(a.$$.fragment),c=k(),l=A("div"),l.innerHTML="<strong>Note: </strong>click on the virtual display to\n                    enable the display driver",h=k(),u=A("fieldset"),d=A("legend"),d.textContent="Audio",f=k(),Pt(p.$$.fragment),m=k(),g=A("fieldset"),v=A("legend"),v.textContent="Layout",_=k(),Pt(y.$$.fragment),b=k(),Pt(x.$$.fragment),C=k(),Pt(M.$$.fragment),O=k(),P=A("div"),I=A("strong"),I.textContent="Shortcuts:",R=k(),Pt(j.$$.fragment),$=E(" root note\n                    "),Pt(L.$$.fragment),F=E(" octave"),D(l,"class","text-grey"),N(l,"margin-bottom","0.5rem"),D(n,"class","svelte-wfenhb"),D(u,"class","svelte-wfenhb"),D(P,"class","text-grey"),N(P,"margin-bottom","0.5rem"),D(g,"class","svelte-wfenhb"),D(e,"class","formContainer svelte-wfenhb")},m(t,T){S(t,e,T),w(e,n),w(n,i),w(n,s),It(r,n,null),w(n,o),It(a,n,null),w(n,c),w(n,l),w(e,h),w(e,u),w(u,d),w(u,f),It(p,u,null),w(e,m),w(e,g),w(g,v),w(g,_),It(y,g,null),w(g,b),It(x,g,null),w(g,C),It(M,g,null),w(g,O),w(g,P),w(P,I),w(P,R),It(j,P,null),w(P,$),It(L,P,null),w(P,F),B=!0},p(t,e){const n={};6&e[0]|16&e[1]&&(n.$$scope={dirty:e,ctx:t}),r.$set(n);const i={};8&e[0]|16&e[1]&&(i.$$scope={dirty:e,ctx:t}),a.$set(i);const s={};16&e[0]|16&e[1]&&(s.$$scope={dirty:e,ctx:t}),p.$set(s);const o={};32&e[0]|16&e[1]&&(o.$$scope={dirty:e,ctx:t}),y.$set(o);const c={};192&e[0]|16&e[1]&&(c.$$scope={dirty:e,ctx:t}),x.$set(c);const l={};256&e[0]|16&e[1]&&(l.$$scope={dirty:e,ctx:t}),M.$set(l);const h={};16&e[1]&&(h.$$scope={dirty:e,ctx:t}),j.$set(h);const u={};16&e[1]&&(u.$$scope={dirty:e,ctx:t}),L.$set(u)},i(t){B||(xt(r.$$.fragment,t),xt(a.$$.fragment,t),xt(p.$$.fragment,t),xt(y.$$.fragment,t),xt(x.$$.fragment,t),xt(M.$$.fragment,t),xt(j.$$.fragment,t),xt(L.$$.fragment,t),B=!0)},o(t){Ct(r.$$.fragment,t),Ct(a.$$.fragment,t),Ct(p.$$.fragment,t),Ct(y.$$.fragment,t),Ct(x.$$.fragment,t),Ct(M.$$.fragment,t),Ct(j.$$.fragment,t),Ct(L.$$.fragment,t),B=!1},d(t){t&&T(e),Dt(r),Dt(a),Dt(p),Dt(y),Dt(x),Dt(M),Dt(j),Dt(L)}}}function Cp(t){let e;return{c(){e=A("h4"),e.textContent="Settings",D(e,"slot","header")},m(t,n){S(t,e,n)},d(t){t&&T(e)}}}function wp(t){let e;return{c(){e=E("Close")},m(t,n){S(t,e,n)},d(t){t&&T(e)}}}function Sp(t){let e,n,i;return n=new Oe({props:{clear:!0,$$slots:{default:[wp]},$$scope:{ctx:t}}}),n.$on("click",t[9]),{c(){e=A("div"),Pt(n.$$.fragment),D(e,"slot","footer"),D(e,"class","is-right")},m(t,s){S(t,e,s),It(n,e,null),i=!0},p(t,e){const i={};16&e[1]&&(i.$$scope={dirty:e,ctx:t}),n.$set(i)},i(t){i||(xt(n.$$.fragment,t),i=!0)},o(t){Ct(n.$$.fragment,t),i=!1},d(t){t&&T(e),Dt(n)}}}function Tp(t){let e,n;return e=new le({props:{$$slots:{footer:[Sp],header:[Cp],default:[xp]},$$scope:{ctx:t}}}),{c(){Pt(e.$$.fragment)},m(t,i){It(e,t,i),n=!0},p(t,n){const i={};511&n[0]|16&n[1]&&(i.$$scope={dirty:n,ctx:t}),e.$set(i)},i(t){n||(xt(e.$$.fragment,t),n=!0)},o(t){Ct(e.$$.fragment,t),n=!1},d(t){Dt(e,t)}}}function Mp(t){let e,n,i;function s(e){t[18](e)}let r={$$slots:{default:[Tp]},$$scope:{ctx:t}};return void 0!==t[0]&&(r.open=t[0]),e=new Xe({props:r}),it.push((()=>kt(e,"open",s))),{c(){Pt(e.$$.fragment)},m(t,n){It(e,t,n),i=!0},p(t,i){const s={};511&i[0]|16&i[1]&&(s.$$scope={dirty:i,ctx:t}),!n&&1&i[0]&&(n=!0,s.open=t[0],lt((()=>n=!1))),e.$set(s)},i(t){i||(xt(e.$$.fragment,t),i=!0)},o(t){Ct(e.$$.fragment,t),i=!1},d(t){Dt(e,t)}}}function Ap(t,e,n){let i,s,r,o,a,c,l,u;h(t,md,(t=>n(1,i=t))),h(t,gd,(t=>n(2,s=t))),h(t,_d,(t=>n(3,r=t))),h(t,bd,(t=>n(4,o=t))),h(t,Cd,(t=>n(5,a=t))),h(t,Td,(t=>n(6,c=t))),h(t,Md,(t=>n(7,l=t))),h(t,Sd,(t=>n(8,u=t)));let{open:d}=e;return t.$$set=t=>{"open"in t&&n(0,d=t.open)},[d,i,s,r,o,a,c,l,u,()=>{n(0,d=!1)},function(t){i=t,md.set(i)},function(t){s=t,gd.set(s)},function(){r=V(this),_d.set(r)},function(){o=V(this),bd.set(o)},function(){a=V(this),Cd.set(a)},function(){c=V(this),Td.set(c)},function(){l=V(this),Md.set(l)},function(){u=V(this),Sd.set(u)},function(t){d=t,n(0,d)}]}class Op extends $t{constructor(t){super(),jt(this,t,Ap,Mp,a,{open:0},[-1,-1])}}function Ep(t){let e,n;return e=new Pf({props:{controller:t[0]}}),{c(){Pt(e.$$.fragment)},m(t,i){It(e,t,i),n=!0},p(t,n){const i={};1&n&&(i.controller=t[0]),e.$set(i)},i(t){n||(xt(e.$$.fragment,t),n=!0)},o(t){Ct(e.$$.fragment,t),n=!1},d(t){Dt(e,t)}}}function kp(t){let e,n,i,s,r,o,a,c,l,h,u,d,f,p,m,g,v,_,y,b,x;function C(e){t[14](e)}let M={};function E(e){t[15](e)}void 0!==t[4]&&(M.open=t[4]),n=new Op({props:M}),it.push((()=>kt(n,"open",C))),r=new Rf({});let P={};void 0!==t[4]&&(P.configModalOpen=t[4]),a=new qf({props:P}),it.push((()=>kt(a,"configModalOpen",E)));var R=t[2].getMeta().component;function j(t){return{props:{controller:t[0]}}}return R&&(g=new R(j(t))),b=new le({props:{$$slots:{default:[Ep]},$$scope:{ctx:t}}}),{c(){e=A("div"),Pt(n.$$.fragment),s=k(),Pt(r.$$.fragment),o=k(),Pt(a.$$.fragment),l=k(),h=A("main"),u=O("svg"),d=O("polygon"),p=k(),m=A("div"),g&&Pt(g.$$.fragment),_=k(),y=A("div"),Pt(b.$$.fragment),D(d,"points",f="0,0 0,250 "+1.25*(t[1]||0)+",250"),N(d,"fill","var(--melon)"),D(u,"height","250"),D(u,"width",t[1]),D(u,"class","polygon svelte-tmfajg"),D(m,"class","controller-container svelte-tmfajg"),N(m,"font-size",t[3]+"rem"),ct((()=>t[16].call(m))),D(y,"class","ui-container svelte-tmfajg"),D(h,"class","svelte-tmfajg"),D(e,"class","app")},m(i,c){S(i,e,c),It(n,e,null),w(e,s),It(r,e,null),w(e,o),It(a,e,null),w(e,l),w(e,h),w(h,u),w(u,d),w(h,p),w(h,m),g&&It(g,m,null),v=function(t,e){"static"===getComputedStyle(t).position&&(t.style.position="relative");const n=A("iframe");n.setAttribute("style","display: block; position: absolute; top: 0; left: 0; width: 100%; height: 100%; overflow: hidden; border: 0; opacity: 0; pointer-events: none; z-index: -1;"),n.setAttribute("aria-hidden","true"),n.tabIndex=-1;const i=H();let s;return i?(n.src="data:text/html,<script>onresize=function(){parent.postMessage(0,'*')}<\/script>",s=I(window,"message",(t=>{t.source===n.contentWindow&&e()}))):(n.src="about:blank",n.onload=()=>{s=I(n.contentWindow,"resize",e)}),w(t,n),()=>{(i||s&&n.contentWindow)&&s(),T(n)}}(m,t[16].bind(m)),w(h,_),w(h,y),It(b,y,null),x=!0},p(t,[e]){const s={};!i&&16&e&&(i=!0,s.open=t[4],lt((()=>i=!1))),n.$set(s);const r={};!c&&16&e&&(c=!0,r.configModalOpen=t[4],lt((()=>c=!1))),a.$set(r),(!x||2&e&&f!==(f="0,0 0,250 "+1.25*(t[1]||0)+",250"))&&D(d,"points",f),(!x||2&e)&&D(u,"width",t[1]);const o={};if(1&e&&(o.controller=t[0]),R!==(R=t[2].getMeta().component)){if(g){yt();const t=g;Ct(t.$$.fragment,1,0,(()=>{Dt(t,1)})),bt()}R?(g=new R(j(t)),Pt(g.$$.fragment),xt(g.$$.fragment,1),It(g,m,null)):g=null}else R&&g.$set(o);(!x||8&e)&&N(m,"font-size",t[3]+"rem");const l={};131073&e&&(l.$$scope={dirty:e,ctx:t}),b.$set(l)},i(t){x||(xt(n.$$.fragment,t),xt(r.$$.fragment,t),xt(a.$$.fragment,t),g&&xt(g.$$.fragment,t),xt(b.$$.fragment,t),x=!0)},o(t){Ct(n.$$.fragment,t),Ct(r.$$.fragment,t),Ct(a.$$.fragment,t),g&&Ct(g.$$.fragment,t),Ct(b.$$.fragment,t),x=!1},d(t){t&&T(e),Dt(n),Dt(r),Dt(a),g&&Dt(g),v(),Dt(b)}}}function Pp(t,e,n){let i,s,r,o,a,c,l,u,d,f,p,m,g;h(t,_d,(t=>n(2,i=t))),h(t,Cd,(t=>n(7,s=t))),h(t,Td,(t=>n(8,r=t))),h(t,Md,(t=>n(9,o=t))),h(t,Sd,(t=>n(10,a=t))),h(t,md,(t=>n(11,c=t))),h(t,gd,(t=>n(12,l=t))),h(t,bd,(t=>n(13,u=t)));let v=!1;return t.$$.update=()=>{2&t.$$.dirty&&n(3,g=1.5*m/640),5&t.$$.dirty&&(i?n(0,d=i.getInstance()):d&&(d.destroy(),n(0,d=null))),1985&t.$$.dirty&&(n(6,p=s.getInstance(an(`${r}${o}`))),d&&d.setLayoutGenerator(p,a)),6145&t.$$.dirty&&d&&d.setDevices(c,l),8225&t.$$.dirty&&(n(5,f=u.getInstance()),d&&d.setSynth(f))},[d,m,i,g,v,f,p,s,r,o,a,c,l,u,function(t){v=t,n(4,v)},function(t){v=t,n(4,v)},function(){m=this.clientWidth,n(1,m)}]}class Ip extends $t{constructor(t){super(),jt(this,t,Pp,kp,a,{})}}function Dp(e){let n;return{c(){n=E("Loading...")},m(t,e){S(t,n,e)},i:t,o:t,d(t){t&&T(n)}}}function Rp(t){let e,n;return e=new Ip({}),{c(){Pt(e.$$.fragment)},m(t,i){It(e,t,i),n=!0},i(t){n||(xt(e.$$.fragment,t),n=!0)},o(t){Ct(e.$$.fragment,t),n=!1},d(t){Dt(e,t)}}}function jp(t){let e,n,i,s;const r=[Rp,Dp],o=[];function a(t,e){return t[0]?0:1}return n=a(t),i=o[n]=r[n](t),{c(){e=A("main"),i.c()},m(t,i){S(t,e,i),o[n].m(e,null),s=!0},p(t,[s]){let c=n;n=a(t),n!==c&&(yt(),Ct(o[c],1,1,(()=>{o[c]=null})),bt(),i=o[n],i||(i=o[n]=r[n](t),i.c()),xt(i,1),i.m(e,null))},i(t){s||(xt(i),s=!0)},o(t){Ct(i),s=!1},d(t){t&&T(e),o[n].d()}}}function $p(t,e,n){let i;return function(t){tt().$$.on_mount.push(t)}((()=>{Bt.enable((t=>{t?alert(`WebMidi could not be enabled: ${t.message}`):(!function(){const t=localStorage.getItem("inputId"),e=localStorage.getItem("outputId");Bt.inputs.find((e=>e.id===t))&&md.set(t),Bt.outputs.find((t=>t.id===e))&&gd.set(e),md.subscribe((t=>localStorage.setItem("inputId",t))),gd.subscribe((t=>localStorage.setItem("outputId",t)))}(),n(0,i=!0))}))})),[i]}return new class extends $t{constructor(t){super(),jt(this,t,$p,jp,a,{})}}({target:document.body})}();
  //# sourceMappingURL=bundle.js.map
  