!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).peaks=e()}(this,(function(){"use strict";var t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function e(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var i={exports:{}};!function(t){var e=Object.prototype.hasOwnProperty,i="~";function n(){}function r(t,e,i){this.fn=t,this.context=e,this.once=i||!1}function a(t,e,n,a,o){if("function"!=typeof n)throw new TypeError("The listener must be a function");var s=new r(n,a||t,o),h=i?i+e:e;return t._events[h]?t._events[h].fn?t._events[h]=[t._events[h],s]:t._events[h].push(s):(t._events[h]=s,t._eventsCount++),t}function o(t,e){0==--t._eventsCount?t._events=new n:delete t._events[e]}function s(){this._events=new n,this._eventsCount=0}Object.create&&(n.prototype=Object.create(null),(new n).__proto__||(i=!1)),s.prototype.eventNames=function(){var t,n,r=[];if(0===this._eventsCount)return r;for(n in t=this._events)e.call(t,n)&&r.push(i?n.slice(1):n);return Object.getOwnPropertySymbols?r.concat(Object.getOwnPropertySymbols(t)):r},s.prototype.listeners=function(t){var e=i?i+t:t,n=this._events[e];if(!n)return[];if(n.fn)return[n.fn];for(var r=0,a=n.length,o=new Array(a);rt.length)&&(e=t.length);for(var i=0,n=Array(e);i0&&void 0!==arguments[0]?arguments[0]:[1,0,0,1,0,0];s(this,e),this.dirty=!1,this.m=t&&t.slice()||[1,0,0,1,0,0]}return l(e,[{key:"reset",value:function(){this.m[0]=1,this.m[1]=0,this.m[2]=0,this.m[3]=1,this.m[4]=0,this.m[5]=0}},{key:"copy",value:function(){return new e(this.m)}},{key:"copyInto",value:function(t){t.m[0]=this.m[0],t.m[1]=this.m[1],t.m[2]=this.m[2],t.m[3]=this.m[3],t.m[4]=this.m[4],t.m[5]=this.m[5]}},{key:"point",value:function(t){var e=this.m;return{x:e[0]*t.x+e[2]*t.y+e[4],y:e[1]*t.x+e[3]*t.y+e[5]}}},{key:"translate",value:function(t,e){return this.m[4]+=this.m[0]*t+this.m[2]*e,this.m[5]+=this.m[1]*t+this.m[3]*e,this}},{key:"scale",value:function(t,e){return this.m[0]*=t,this.m[1]*=t,this.m[2]*=e,this.m[3]*=e,this}},{key:"rotate",value:function(t){var e=Math.cos(t),i=Math.sin(t),n=this.m[0]*e+this.m[2]*i,r=this.m[1]*e+this.m[3]*i,a=this.m[0]*-i+this.m[2]*e,o=this.m[1]*-i+this.m[3]*e;return this.m[0]=n,this.m[1]=r,this.m[2]=a,this.m[3]=o,this}},{key:"getTranslation",value:function(){return{x:this.m[4],y:this.m[5]}}},{key:"skew",value:function(t,e){var i=this.m[0]+this.m[2]*e,n=this.m[1]+this.m[3]*e,r=this.m[2]+this.m[0]*t,a=this.m[3]+this.m[1]*t;return this.m[0]=i,this.m[1]=n,this.m[2]=r,this.m[3]=a,this}},{key:"multiply",value:function(t){var e=this.m[0]*t.m[0]+this.m[2]*t.m[1],i=this.m[1]*t.m[0]+this.m[3]*t.m[1],n=this.m[0]*t.m[2]+this.m[2]*t.m[3],r=this.m[1]*t.m[2]+this.m[3]*t.m[3],a=this.m[0]*t.m[4]+this.m[2]*t.m[5]+this.m[4],o=this.m[1]*t.m[4]+this.m[3]*t.m[5]+this.m[5];return this.m[0]=e,this.m[1]=i,this.m[2]=n,this.m[3]=r,this.m[4]=a,this.m[5]=o,this}},{key:"invert",value:function(){var t=1/(this.m[0]*this.m[3]-this.m[1]*this.m[2]),e=this.m[3]*t,i=-this.m[1]*t,n=-this.m[2]*t,r=this.m[0]*t,a=t*(this.m[2]*this.m[5]-this.m[3]*this.m[4]),o=t*(this.m[1]*this.m[4]-this.m[0]*this.m[5]);return this.m[0]=e,this.m[1]=i,this.m[2]=n,this.m[3]=r,this.m[4]=a,this.m[5]=o,this}},{key:"getMatrix",value:function(){return this.m}},{key:"decompose",value:function(){var e=this.m[0],i=this.m[1],n=this.m[2],r=this.m[3],a=e*r-i*n,o={x:this.m[4],y:this.m[5],rotation:0,scaleX:0,scaleY:0,skewX:0,skewY:0};if(0!=e||0!=i){var s=Math.sqrt(e*e+i*i);o.rotation=i>0?Math.acos(e/s):-Math.acos(e/s),o.scaleX=s,o.scaleY=a/s,o.skewX=(e*n+i*r)/a,o.skewY=0}else if(0!=n||0!=r){var h=Math.sqrt(n*n+r*r);o.rotation=Math.PI/2-(r>0?Math.acos(-n/h):-Math.acos(n/h)),o.scaleX=a/h,o.scaleY=h,o.skewX=0,o.skewY=(e*n+i*r)/a}return o.rotation=t.Util._getRotation(o.rotation),o}}])}();t.Transform=i;var n=Math.PI/180,r=180/Math.PI,o="Konva error: ",h={aliceblue:[240,248,255],antiquewhite:[250,235,215],aqua:[0,255,255],aquamarine:[127,255,212],azure:[240,255,255],beige:[245,245,220],bisque:[255,228,196],black:[0,0,0],blanchedalmond:[255,235,205],blue:[0,0,255],blueviolet:[138,43,226],brown:[165,42,42],burlywood:[222,184,135],cadetblue:[95,158,160],chartreuse:[127,255,0],chocolate:[210,105,30],coral:[255,127,80],cornflowerblue:[100,149,237],cornsilk:[255,248,220],crimson:[220,20,60],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgoldenrod:[184,132,11],darkgray:[169,169,169],darkgreen:[0,100,0],darkgrey:[169,169,169],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkseagreen:[143,188,143],darkslateblue:[72,61,139],darkslategray:[47,79,79],darkslategrey:[47,79,79],darkturquoise:[0,206,209],darkviolet:[148,0,211],deeppink:[255,20,147],deepskyblue:[0,191,255],dimgray:[105,105,105],dimgrey:[105,105,105],dodgerblue:[30,144,255],firebrick:[178,34,34],floralwhite:[255,255,240],forestgreen:[34,139,34],fuchsia:[255,0,255],gainsboro:[220,220,220],ghostwhite:[248,248,255],gold:[255,215,0],goldenrod:[218,165,32],gray:[128,128,128],green:[0,128,0],greenyellow:[173,255,47],grey:[128,128,128],honeydew:[240,255,240],hotpink:[255,105,180],indianred:[205,92,92],indigo:[75,0,130],ivory:[255,255,240],khaki:[240,230,140],lavender:[230,230,250],lavenderblush:[255,240,245],lawngreen:[124,252,0],lemonchiffon:[255,250,205],lightblue:[173,216,230],lightcoral:[240,128,128],lightcyan:[224,255,255],lightgoldenrodyellow:[250,250,210],lightgray:[211,211,211],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightsalmon:[255,160,122],lightseagreen:[32,178,170],lightskyblue:[135,206,250],lightslategray:[119,136,153],lightslategrey:[119,136,153],lightsteelblue:[176,196,222],lightyellow:[255,255,224],lime:[0,255,0],limegreen:[50,205,50],linen:[250,240,230],magenta:[255,0,255],maroon:[128,0,0],mediumaquamarine:[102,205,170],mediumblue:[0,0,205],mediumorchid:[186,85,211],mediumpurple:[147,112,219],mediumseagreen:[60,179,113],mediumslateblue:[123,104,238],mediumspringgreen:[0,250,154],mediumturquoise:[72,209,204],mediumvioletred:[199,21,133],midnightblue:[25,25,112],mintcream:[245,255,250],mistyrose:[255,228,225],moccasin:[255,228,181],navajowhite:[255,222,173],navy:[0,0,128],oldlace:[253,245,230],olive:[128,128,0],olivedrab:[107,142,35],orange:[255,165,0],orangered:[255,69,0],orchid:[218,112,214],palegoldenrod:[238,232,170],palegreen:[152,251,152],paleturquoise:[175,238,238],palevioletred:[219,112,147],papayawhip:[255,239,213],peachpuff:[255,218,185],peru:[205,133,63],pink:[255,192,203],plum:[221,160,203],powderblue:[176,224,230],purple:[128,0,128],rebeccapurple:[102,51,153],red:[255,0,0],rosybrown:[188,143,143],royalblue:[65,105,225],saddlebrown:[139,69,19],salmon:[250,128,114],sandybrown:[244,164,96],seagreen:[46,139,87],seashell:[255,245,238],sienna:[160,82,45],silver:[192,192,192],skyblue:[135,206,235],slateblue:[106,90,205],slategray:[119,128,144],slategrey:[119,128,144],snow:[255,255,250],springgreen:[0,255,127],steelblue:[70,130,180],tan:[210,180,140],teal:[0,128,128],thistle:[216,191,216],transparent:[255,255,255,0],tomato:[255,99,71],turquoise:[64,224,208],violet:[238,130,238],wheat:[245,222,179],white:[255,255,255],whitesmoke:[245,245,245],yellow:[255,255,0],yellowgreen:[154,205,5]},u=/rgb\((\d{1,3}),(\d{1,3}),(\d{1,3})\)/,d=[],c="undefined"!=typeof requestAnimationFrame&&requestAnimationFrame||function(t){setTimeout(t,60)};t.Util={_isElement:function(t){return!(!t||1!=t.nodeType)},_isFunction:function(t){return!!(t&&t.constructor&&t.call&&t.apply)},_isPlainObject:function(t){return!!t&&t.constructor===Object},_isArray:function(t){return"[object Array]"===Object.prototype.toString.call(t)},_isNumber:function(t){return"[object Number]"===Object.prototype.toString.call(t)&&!isNaN(t)&&isFinite(t)},_isString:function(t){return"[object String]"===Object.prototype.toString.call(t)},_isBoolean:function(t){return"[object Boolean]"===Object.prototype.toString.call(t)},isObject:function(t){return t instanceof Object},isValidSelector:function(t){if("string"!=typeof t)return!1;var e=t[0];return"#"===e||"."===e||e===e.toUpperCase()},_sign:function(t){return 0===t||t>0?1:-1},requestAnimFrame:function(t){d.push(t),1===d.length&&c((function(){var t=d;d=[],t.forEach((function(t){t()}))}))},createCanvasElement:function(){var t=document.createElement("canvas");try{t.style=t.style||{}}catch(t){}return t},createImageElement:function(){return document.createElement("img")},_isInDocument:function(t){for(;t=t.parentNode;)if(t==document)return!0;return!1},_urlToImage:function(e,i){var n=t.Util.createImageElement();n.onload=function(){i(n)},n.src=e},_rgbToHex:function(t,e,i){return((1<<24)+(t<<16)+(e<<8)+i).toString(16).slice(1)},_hexToRgb:function(t){t=t.replace("#","");var e=parseInt(t,16);return{r:e>>16&255,g:e>>8&255,b:255&e}},getRandomColor:function(){for(var t=(16777215*Math.random()<<0).toString(16);t.length<6;)t="0"+t;return"#"+t},getRGB:function(t){var e;return t in h?{r:(e=h[t])[0],g:e[1],b:e[2]}:"#"===t[0]?this._hexToRgb(t.substring(1)):"rgb("===t.substr(0,4)?(e=u.exec(t.replace(/ /g,"")),{r:parseInt(e[1],10),g:parseInt(e[2],10),b:parseInt(e[3],10)}):{r:0,g:0,b:0}},colorToRGBA:function(e){return e=e||"black",t.Util._namedColorToRBA(e)||t.Util._hex3ColorToRGBA(e)||t.Util._hex4ColorToRGBA(e)||t.Util._hex6ColorToRGBA(e)||t.Util._hex8ColorToRGBA(e)||t.Util._rgbColorToRGBA(e)||t.Util._rgbaColorToRGBA(e)||t.Util._hslColorToRGBA(e)},_namedColorToRBA:function(t){var e=h[t.toLowerCase()];return e?{r:e[0],g:e[1],b:e[2],a:1}:null},_rgbColorToRGBA:function(t){if(0===t.indexOf("rgb(")){var e=(t=t.match(/rgb\(([^)]+)\)/)[1]).split(/ *, */).map(Number);return{r:e[0],g:e[1],b:e[2],a:1}}},_rgbaColorToRGBA:function(t){if(0===t.indexOf("rgba(")){var e=(t=t.match(/rgba\(([^)]+)\)/)[1]).split(/ *, */).map((function(t,e){return"%"===t.slice(-1)?3===e?parseInt(t)/100:parseInt(t)/100*255:Number(t)}));return{r:e[0],g:e[1],b:e[2],a:e[3]}}},_hex8ColorToRGBA:function(t){if("#"===t[0]&&9===t.length)return{r:parseInt(t.slice(1,3),16),g:parseInt(t.slice(3,5),16),b:parseInt(t.slice(5,7),16),a:parseInt(t.slice(7,9),16)/255}},_hex6ColorToRGBA:function(t){if("#"===t[0]&&7===t.length)return{r:parseInt(t.slice(1,3),16),g:parseInt(t.slice(3,5),16),b:parseInt(t.slice(5,7),16),a:1}},_hex4ColorToRGBA:function(t){if("#"===t[0]&&5===t.length)return{r:parseInt(t[1]+t[1],16),g:parseInt(t[2]+t[2],16),b:parseInt(t[3]+t[3],16),a:parseInt(t[4]+t[4],16)/255}},_hex3ColorToRGBA:function(t){if("#"===t[0]&&4===t.length)return{r:parseInt(t[1]+t[1],16),g:parseInt(t[2]+t[2],16),b:parseInt(t[3]+t[3],16),a:1}},_hslColorToRGBA:function(t){if(/hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.test(t)){var e=/hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.exec(t),i=a(g=e)||f(g)||S(g)||_();i[0];var n,r,o,s=i.slice(1),h=Number(s[0])/360,l=Number(s[1])/100,u=Number(s[2])/100;if(0===l)return o=255*u,{r:Math.round(o),g:Math.round(o),b:Math.round(o),a:1};for(var d=2*u-(n=u<.5?u*(1+l):u+l-u*l),c=[0,0,0],p=0;p<3;p++)(r=h+1/3*-(p-1))<0&&r++,r>1&&r--,o=6*r<1?d+6*(n-d)*r:2*r<1?n:3*r<2?d+(n-d)*(2/3-r)*6:d,c[p]=255*o;return{r:Math.round(c[0]),g:Math.round(c[1]),b:Math.round(c[2]),a:1}}var g},haveIntersection:function(t,e){return!(e.x>t.x+t.width||e.x+e.widtht.y+t.height||e.y+e.height1?(o=i,s=n,h=(i-r)*(i-r)+(n-a)*(n-a)):h=((o=t+u*(i-t))-r)*(o-r)+((s=e+u*(n-e))-a)*(s-a)}return[o,s,h]},_getProjectionToLine:function(e,i,n){var r=t.Util.cloneObject(e),a=Number.MAX_VALUE;return i.forEach((function(o,s){if(n||s!==i.length-1){var h=i[(s+1)%i.length],l=t.Util._getProjectionToSegment(o.x,o.y,h.x,h.y,e.x,e.y),u=l[0],d=l[1],c=l[2];ci.length){var s=i;i=e,e=s}for(r=0;r255?255:t<0?0:Math.round(t)},M.alphaComponent=function(t){return t>1?1:t<1e-4?1e-4:t},M.getNumberValidator=function(){if(E.Konva.isUnminified)return function(t,e){return L.Util._isNumber(t)||L.Util.warn(F(t)+' is a not valid value for "'+e+'" attribute. The value should be a number.'),t}},M.getNumberOrArrayOfNumbersValidator=function(t){if(E.Konva.isUnminified)return function(e,i){var n=L.Util._isNumber(e),r=L.Util._isArray(e)&&e.length==t;return n||r||L.Util.warn(F(e)+' is a not valid value for "'+i+'" attribute. The value should be a number or Array('+t+")"),e}},M.getNumberOrAutoValidator=function(){if(E.Konva.isUnminified)return function(t,e){return L.Util._isNumber(t)||"auto"===t||L.Util.warn(F(t)+' is a not valid value for "'+e+'" attribute. The value should be a number or "auto".'),t}},M.getStringValidator=function(){if(E.Konva.isUnminified)return function(t,e){return L.Util._isString(t)||L.Util.warn(F(t)+' is a not valid value for "'+e+'" attribute. The value should be a string.'),t}},M.getStringOrGradientValidator=function(){if(E.Konva.isUnminified)return function(t,e){var i=L.Util._isString(t),n="[object CanvasGradient]"===Object.prototype.toString.call(t)||t&&t.addColorStop;return i||n||L.Util.warn(F(t)+' is a not valid value for "'+e+'" attribute. The value should be a string or a native gradient.'),t}},M.getFunctionValidator=function(){if(E.Konva.isUnminified)return function(t,e){return L.Util._isFunction(t)||L.Util.warn(F(t)+' is a not valid value for "'+e+'" attribute. The value should be a function.'),t}},M.getNumberArrayValidator=function(){if(E.Konva.isUnminified)return function(t,e){var i=Int8Array?Object.getPrototypeOf(Int8Array):null;return i&&t instanceof i||(L.Util._isArray(t)?t.forEach((function(t){L.Util._isNumber(t)||L.Util.warn('"'+e+'" attribute has non numeric element '+t+". Make sure that all elements are numbers.")})):L.Util.warn(F(t)+' is a not valid value for "'+e+'" attribute. The value should be a array of numbers.')),t}},M.getBooleanValidator=function(){if(E.Konva.isUnminified)return function(t,e){return!0===t||!1===t||L.Util.warn(F(t)+' is a not valid value for "'+e+'" attribute. The value should be a boolean.'),t}},M.getComponentValidator=function(t){if(E.Konva.isUnminified)return function(e,i){return null==e||L.Util.isObject(e)||L.Util.warn(F(e)+' is a not valid value for "'+i+'" attribute. The value should be an object with properties '+t),e}},function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.Factory=void 0;var e=P,i=M,n="get",r="set";t.Factory={addGetterSetter:function(e,i,n,r,a){t.Factory.addGetter(e,i,n),t.Factory.addSetter(e,i,r,a),t.Factory.addOverloadedGetterSetter(e,i)},addGetter:function(t,i,r){var a=n+e.Util._capitalize(i);t.prototype[a]=t.prototype[a]||function(){var t=this.attrs[i];return void 0===t?r:t}},addSetter:function(i,n,a,o){var s=r+e.Util._capitalize(n);i.prototype[s]||t.Factory.overWriteSetter(i,n,a,o)},overWriteSetter:function(t,i,n,a){var o=r+e.Util._capitalize(i);t.prototype[o]=function(t){return n&&null!=t&&(t=n.call(this,t,i)),this._setAttr(i,t),a&&a.call(this),this}},addComponentsGetterSetter:function(a,o,s,h,l){var u,d,c=s.length,p=e.Util._capitalize,g=n+p(o),f=r+p(o);a.prototype[g]=function(){var t={};for(u=0;u=100&&e.shift()}},{key:"reset",value:function(){var t=this.getCanvas().getPixelRatio();this.setTransform(1*t,0,0,1*t,0,0)}},{key:"getCanvas",value:function(){return this.canvas}},{key:"clear",value:function(t){var e=this.getCanvas();t?this.clearRect(t.x||0,t.y||0,t.width||0,t.height||0):this.clearRect(0,0,e.getWidth()/e.pixelRatio,e.getHeight()/e.pixelRatio)}},{key:"_applyLineCap",value:function(t){var e=t.attrs.lineCap;e&&this.setAttr("lineCap",e)}},{key:"_applyOpacity",value:function(t){var e=t.getAbsoluteOpacity();1!==e&&this.setAttr("globalAlpha",e)}},{key:"_applyLineJoin",value:function(t){var e=t.attrs.lineJoin;e&&this.setAttr("lineJoin",e)}},{key:"setAttr",value:function(t,e){this._context[t]=e}},{key:"arc",value:function(t,e,i,n,r,a){this._context.arc(t,e,i,n,r,a)}},{key:"arcTo",value:function(t,e,i,n,r){this._context.arcTo(t,e,i,n,r)}},{key:"beginPath",value:function(){this._context.beginPath()}},{key:"bezierCurveTo",value:function(t,e,i,n,r,a){this._context.bezierCurveTo(t,e,i,n,r,a)}},{key:"clearRect",value:function(t,e,i,n){this._context.clearRect(t,e,i,n)}},{key:"clip",value:function(){this._context.clip()}},{key:"closePath",value:function(){this._context.closePath()}},{key:"createImageData",value:function(t,e){var i=arguments;return 2===i.length?this._context.createImageData(t,e):1===i.length?this._context.createImageData(t):void 0}},{key:"createLinearGradient",value:function(t,e,i,n){return this._context.createLinearGradient(t,e,i,n)}},{key:"createPattern",value:function(t,e){return this._context.createPattern(t,e)}},{key:"createRadialGradient",value:function(t,e,i,n,r,a){return this._context.createRadialGradient(t,e,i,n,r,a)}},{key:"drawImage",value:function(t,e,i,n,r,a,o,s,h){var l=arguments,u=this._context;3===l.length?u.drawImage(t,e,i):5===l.length?u.drawImage(t,e,i,n,r):9===l.length&&u.drawImage(t,e,i,n,r,a,o,s,h)}},{key:"ellipse",value:function(t,e,i,n,r,a,o,s){this._context.ellipse(t,e,i,n,r,a,o,s)}},{key:"isPointInPath",value:function(t,e,i,n){return i?this._context.isPointInPath(i,t,e,n):this._context.isPointInPath(t,e,n)}},{key:"fill",value:function(t){t?this._context.fill(t):this._context.fill()}},{key:"fillRect",value:function(t,e,i,n){this._context.fillRect(t,e,i,n)}},{key:"strokeRect",value:function(t,e,i,n){this._context.strokeRect(t,e,i,n)}},{key:"fillText",value:function(t,e,i,n){n?this._context.fillText(t,e,i,n):this._context.fillText(t,e,i)}},{key:"measureText",value:function(t){return this._context.measureText(t)}},{key:"getImageData",value:function(t,e,i,n){return this._context.getImageData(t,e,i,n)}},{key:"lineTo",value:function(t,e){this._context.lineTo(t,e)}},{key:"moveTo",value:function(t,e){this._context.moveTo(t,e)}},{key:"rect",value:function(t,e,i,n){this._context.rect(t,e,i,n)}},{key:"putImageData",value:function(t,e,i){this._context.putImageData(t,e,i)}},{key:"quadraticCurveTo",value:function(t,e,i,n){this._context.quadraticCurveTo(t,e,i,n)}},{key:"restore",value:function(){this._context.restore()}},{key:"rotate",value:function(t){this._context.rotate(t)}},{key:"save",value:function(){this._context.save()}},{key:"scale",value:function(t,e){this._context.scale(t,e)}},{key:"setLineDash",value:function(t){this._context.setLineDash?this._context.setLineDash(t):"mozDash"in this._context?this._context.mozDash=t:"webkitLineDash"in this._context&&(this._context.webkitLineDash=t)}},{key:"getLineDash",value:function(){return this._context.getLineDash()}},{key:"setTransform",value:function(t,e,i,n,r,a){this._context.setTransform(t,e,i,n,r,a)}},{key:"stroke",value:function(t){t?this._context.stroke(t):this._context.stroke()}},{key:"strokeText",value:function(t,e,i,n){this._context.strokeText(t,e,i,n)}},{key:"transform",value:function(t,e,i,n,r,a){this._context.transform(t,e,i,n,r,a)}},{key:"translate",value:function(t,e){this._context.translate(t,e)}},{key:"_enableTrace",value:function(){var t,e,i=this,n=B.length,r=this.setAttr,a=function(t){var n,r=i[t];i[t]=function(){return e=function(t){var e,i,n=[],r=t.length,a=O.Util;for(e=0;e1&&void 0!==arguments[1]?arguments[1]:{}).willReadFrequently,r=void 0!==n&&n;return s(this,e),(i=o(this,e,[t]))._context=t._canvas.getContext("2d",{willReadFrequently:r}),i}return p(e,t),l(e,[{key:"_fillColor",value:function(t){var e=t.fill();this.setAttr("fillStyle",e),t._fillFunc(this)}},{key:"_fillPattern",value:function(t){this.setAttr("fillStyle",t._getFillPattern()),t._fillFunc(this)}},{key:"_fillLinearGradient",value:function(t){var e=t._getLinearGradient();e&&(this.setAttr("fillStyle",e),t._fillFunc(this))}},{key:"_fillRadialGradient",value:function(t){var e=t._getRadialGradient();e&&(this.setAttr("fillStyle",e),t._fillFunc(this))}},{key:"_fill",value:function(t){var e=t.fill(),i=t.getFillPriority();if(e&&"color"===i)this._fillColor(t);else{var n=t.getFillPatternImage();if(n&&"pattern"===i)this._fillPattern(t);else{var r=t.getFillLinearGradientColorStops();if(r&&"linear-gradient"===i)this._fillLinearGradient(t);else{var a=t.getFillRadialGradientColorStops();a&&"radial-gradient"===i?this._fillRadialGradient(t):e?this._fillColor(t):n?this._fillPattern(t):r?this._fillLinearGradient(t):a&&this._fillRadialGradient(t)}}}}},{key:"_strokeLinearGradient",value:function(t){var e=t.getStrokeLinearGradientStartPoint(),i=t.getStrokeLinearGradientEndPoint(),n=t.getStrokeLinearGradientColorStops(),r=this.createLinearGradient(e.x,e.y,i.x,i.y);if(n){for(var a=0;a0&&void 0!==arguments[0]?arguments[0]:{width:0,height:0,willReadFrequently:!1};return s(this,e),(t=o(this,e,[i])).context=new N.SceneContext(t,{willReadFrequently:i.willReadFrequently}),t.setSize(i.width,i.height),t}return p(e,t),l(e)}(j);W.SceneCanvas=q;var J=function(t){function e(){var t,i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{width:0,height:0};return s(this,e),(t=o(this,e,[i])).hitCanvas=!0,t.context=new N.HitContext(t),t.setSize(i.width,i.height),t}return p(e,t),l(e)}(j);W.HitCanvas=J;var Q={};!function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.DD=void 0;var e=A,i=P;t.DD={get isDragging(){var e=!1;return t.DD._dragElements.forEach((function(t){"dragging"===t.dragStatus&&(e=!0)})),e},justDragged:!1,get node(){var e;return t.DD._dragElements.forEach((function(t){e=t.node})),e},_dragElements:new Map,_drag:function(e){var n=[];t.DD._dragElements.forEach((function(t,r){var a=t.node,o=a.getStage();o.setPointersPositions(e),void 0===t.pointerId&&(t.pointerId=i.Util._getFirstPointerId(e));var s=o._changedPointerPositions.find((function(e){return e.id===t.pointerId}));if(s){if("dragging"!==t.dragStatus){var h=a.dragDistance();if(Math.max(Math.abs(s.x-t.startPointerPos.x),Math.abs(s.y-t.startPointerPos.y))1&&void 0!==arguments[1]&&arguments[1];if(t)return this._isVisible(t)&&this._isListening(t);var i=this.getLayer(),n=!1;nt.DD._dragElements.forEach((function(t){"dragging"===t.dragStatus&&("Stage"===t.node.nodeType||t.node.getLayer()===i)&&(n=!0)}));var r=!e&&!it.Konva.hitOnDragEnabled&&n;return this.isListening()&&this.isVisible()&&!r}},{key:"show",value:function(){return this.visible(!0),this}},{key:"hide",value:function(){return this.visible(!1),this}},{key:"getZIndex",value:function(){return this.index||0}},{key:"getAbsoluteZIndex",value:function(){var t,e,i,n,r=this.getDepth(),a=this,o=0;return"Stage"!==a.nodeType&&function s(h){for(t=[],e=h.length,i=0;i0&&t[0].getDepth()<=r&&s(t)}(a.getStage().getChildren()),o}},{key:"getDepth",value:function(){for(var t=0,e=this.parent;e;)t++,e=e.parent;return t}},{key:"_batchTransformChanges",value:function(t){this._batchingTransformChange=!0,t(),this._batchingTransformChange=!1,this._needClearTransformCache&&(this._clearCache(_t),this._clearSelfAndDescendantCache(st)),this._needClearTransformCache=!1}},{key:"setPosition",value:function(t){var e=this;return this._batchTransformChanges((function(){e.x(t.x),e.y(t.y)})),this}},{key:"getPosition",value:function(){return{x:this.x(),y:this.y()}}},{key:"getRelativePointerPosition",value:function(){if(!this.getStage())return null;var t=this.getStage().getPointerPosition();if(!t)return null;var e=this.getAbsoluteTransform().copy();return e.invert(),e.point(t)}},{key:"getAbsolutePosition",value:function(t){for(var e=!1,i=this.parent;i;){if(i.isCached()){e=!0;break}i=i.parent}e&&!t&&(t=!0);var n=this.getAbsoluteTransform(t).getMatrix(),r=new $.Transform,a=this.offset();return r.m=n.slice(),r.translate(a.x,a.y),r.getTranslation()}},{key:"setAbsolutePosition",value:function(t){var e=this._clearTransform();this.attrs.x=e.x,this.attrs.y=e.y,delete e.x,delete e.y,this._clearCache(_t);var i=this._getAbsoluteTransform().copy();return i.invert(),i.translate(t.x,t.y),t={x:this.attrs.x+i.getTranslation().x,y:this.attrs.y+i.getTranslation().y},this._setTransform(e),this.setPosition({x:t.x,y:t.y}),this._clearCache(_t),this._clearSelfAndDescendantCache(st),this}},{key:"_setTransform",value:function(t){var e;for(e in t)this.attrs[e]=t[e]}},{key:"_clearTransform",value:function(){var t={x:this.x(),y:this.y(),rotation:this.rotation(),scaleX:this.scaleX(),scaleY:this.scaleY(),offsetX:this.offsetX(),offsetY:this.offsetY(),skewX:this.skewX(),skewY:this.skewY()};return this.attrs.x=0,this.attrs.y=0,this.attrs.rotation=0,this.attrs.scaleX=1,this.attrs.scaleY=1,this.attrs.offsetX=0,this.attrs.offsetY=0,this.attrs.skewX=0,this.attrs.skewY=0,t}},{key:"move",value:function(t){var e=t.x,i=t.y,n=this.x(),r=this.y();return void 0!==e&&(n+=e),void 0!==i&&(r+=i),this.setPosition({x:n,y:r}),this}},{key:"_eachAncestorReverse",value:function(t,e){var i,n,r=[],a=this.getParent();if(!e||e._id!==this._id){for(r.unshift(this);a&&(!e||a._id!==e._id);)r.unshift(a),a=a.parent;for(i=r.length,n=0;n0&&(this.parent.children.splice(t,1),this.parent.children.splice(t-1,0,this),this.parent._setChildrenIndices(),!0)}},{key:"moveToBottom",value:function(){if(!this.parent)return $.Util.warn("Node has no parent. moveToBottom function is ignored."),!1;var t=this.index;return t>0&&(this.parent.children.splice(t,1),this.parent.children.unshift(this),this.parent._setChildrenIndices(),!0)}},{key:"setZIndex",value:function(t){if(!this.parent)return $.Util.warn("Node has no parent. zIndex parameter is ignored."),this;(t<0||t>=this.parent.children.length)&&$.Util.warn("Unexpected value "+t+" for zIndex property. zIndex is just index of a node in children of its parent. Expected value is from 0 to "+(this.parent.children.length-1)+".");var e=this.index;return this.parent.children.splice(e,1),this.parent.children.splice(t,0,this),this.parent._setChildrenIndices(),this}},{key:"getAbsoluteOpacity",value:function(){return this._getCache(at,this._getAbsoluteOpacity)}},{key:"_getAbsoluteOpacity",value:function(){var t=this.opacity(),e=this.getParent();return e&&!e._isUnderCache&&(t*=e.getAbsoluteOpacity()),t}},{key:"moveTo",value:function(t){return this.getParent()!==t&&(this._remove(),t.add(this)),this}},{key:"toObject",value:function(){var t,e,i,n,r={},a=this.getAttrs();for(t in r.attrs={},a)e=a[t],$.Util.isObject(e)&&!$.Util._isPlainObject(e)&&!$.Util._isArray(e)||(i="function"==typeof this[t]&&this[t],delete a[t],n=i?i.call(this):null,a[t]=e,n!==e&&(r.attrs[t]=e));return r.className=this.getClassName(),$.Util._prepareToStringify(r)}},{key:"toJSON",value:function(){return JSON.stringify(this.toObject())}},{key:"getParent",value:function(){return this.parent}},{key:"findAncestors",value:function(t,e,i){var n=[];e&&this._isMatch(t)&&n.push(this);for(var r=this.parent;r;){if(r===i)return n;r._isMatch(t)&&n.push(r),r=r.parent}return n}},{key:"isAncestorOf",value:function(t){return!1}},{key:"findAncestor",value:function(t,e,i){return this.findAncestors(t,e,i)[0]}},{key:"_isMatch",value:function(t){if(!t)return!1;if("function"==typeof t)return t(this);var e,i,n=t.replace(/ /g,"").split(","),r=n.length;for(e=0;e1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0;return e.target=e.target||this,i?this._fireAndBubble(t,e):this._fire(t,e),this}},{key:"getAbsoluteTransform",value:function(t){return t?this._getAbsoluteTransform(t):this._getCache(st,this._getAbsoluteTransform)}},{key:"_getAbsoluteTransform",value:function(t){var e;if(t)return e=new $.Transform,this._eachAncestorReverse((function(t){var i=t.transformsEnabled();"all"===i?e.multiply(t.getTransform()):"position"===i&&e.translate(t.x()-t.offsetX(),t.y()-t.offsetY())}),t),e;e=this._cache.get(st)||new $.Transform,this.parent?this.parent.getAbsoluteTransform().copyInto(e):e.reset();var i=this.transformsEnabled();if("all"===i)e.multiply(this.getTransform());else if("position"===i){var n=this.attrs.x||0,r=this.attrs.y||0,a=this.attrs.offsetX||0,o=this.attrs.offsetY||0;e.translate(n-a,r-o)}return e.dirty=!1,e}},{key:"getAbsoluteScale",value:function(t){for(var e=this;e;)e._isUnderCache&&(t=e),e=e.getParent();var i=this.getAbsoluteTransform(t).decompose();return{x:i.scaleX,y:i.scaleY}}},{key:"getAbsoluteRotation",value:function(){return this.getAbsoluteTransform().decompose().rotation}},{key:"getTransform",value:function(){return this._getCache(_t,this._getTransform)}},{key:"_getTransform",value:function(){var t,e,i=this._cache.get(_t)||new $.Transform;i.reset();var n=this.x(),r=this.y(),a=it.Konva.getAngle(this.rotation()),o=null!==(t=this.attrs.scaleX)&&void 0!==t?t:1,s=null!==(e=this.attrs.scaleY)&&void 0!==e?e:1,h=this.attrs.skewX||0,l=this.attrs.skewY||0,u=this.attrs.offsetX||0,d=this.attrs.offsetY||0;return 0===n&&0===r||i.translate(n,r),0!==a&&i.rotate(a),0===h&&0===l||i.skew(h,l),1===o&&1===s||i.scale(o,s),0===u&&0===d||i.translate(-1*u,-1*d),i.dirty=!1,i}},{key:"clone",value:function(t){var e,i,n,r,a,o=$.Util.cloneObject(this.attrs);for(e in t)o[e]=t[e];var s=new this.constructor(o);for(e in this.eventListeners)for(n=(i=this.eventListeners[e]).length,r=0;r1&&void 0!==arguments[1])||arguments[1];nt.DD._dragElements.has(this._id)||this._createDragElement(t),nt.DD._dragElements.get(this._id).dragStatus="dragging",this.fire("dragstart",{type:"dragstart",target:this,evt:t&&t.evt},e)}},{key:"_setDragPosition",value:function(t,e){var i=this.getStage()._getPointerById(e.pointerId);if(i){var n={x:i.x-e.offset.x,y:i.y-e.offset.y},r=this.dragBoundFunc();if(void 0!==r){var a=r.call(this,n,t);a?n=a:$.Util.warn("dragBoundFunc did not return any value. That is unexpected behavior. You must return new absolute position from dragBoundFunc.")}this._lastPos&&this._lastPos.x===n.x&&this._lastPos.y===n.y||(this.setAbsolutePosition(n),this._requestDraw()),this._lastPos=n}}},{key:"stopDrag",value:function(t){var e=nt.DD._dragElements.get(this._id);e&&(e.dragStatus="stopped"),nt.DD._endDragBefore(t),nt.DD._endDragAfter(t)}},{key:"setDraggable",value:function(t){this._setAttr("draggable",t),this._dragChange()}},{key:"isDragging",value:function(){var t=nt.DD._dragElements.get(this._id);return!!t&&"dragging"===t.dragStatus}},{key:"_listenDrag",value:function(){this._dragCleanup(),this.on("mousedown.konva touchstart.konva",(function(t){var e=this;if((!(void 0!==t.evt.button)||it.Konva.dragButtons.indexOf(t.evt.button)>=0)&&!this.isDragging()){var i=!1;nt.DD._dragElements.forEach((function(t){e.isAncestorOf(t.node)&&(i=!0)})),i||this._createDragElement(t)}}))}},{key:"_dragChange",value:function(){if(this.attrs.draggable)this._listenDrag();else{if(this._dragCleanup(),!this.getStage())return;var t=nt.DD._dragElements.get(this._id),e=t&&"dragging"===t.dragStatus,i=t&&"ready"===t.dragStatus;e?this.stopDrag():i&&nt.DD._dragElements.delete(this._id)}}},{key:"_dragCleanup",value:function(){this.off("mousedown.konva"),this.off("touchstart.konva")}},{key:"isClientRectOnScreen",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{x:0,y:0},e=this.getStage();if(!e)return!1;var i={x:-t.x,y:-t.y,width:e.width()+2*t.x,height:e.height()+2*t.y};return $.Util.haveIntersection(i,this.getClientRect())}}],[{key:"create",value:function(t,e){return $.Util._isString(t)&&(t=JSON.parse(t)),this._createNode(t,e)}},{key:"_createNode",value:function(e,i){var n,r,a,o=t.prototype.getClassName.call(e),s=e.children;if(i&&(e.attrs.container=i),it.Konva[o]||($.Util.warn('Can not find a node with class name "'+o+'". Fallback to "Shape".'),o="Shape"),n=new(0,it.Konva[o])(e.attrs),s)for(r=s.length,a=0;a0}},{key:"removeChildren",value:function(){return this.getChildren().forEach((function(t){t.parent=null,t.index=0,t.remove()})),this.children=[],this._requestDraw(),this}},{key:"destroyChildren",value:function(){return this.getChildren().forEach((function(t){t.parent=null,t.index=0,t.destroy()})),this.children=[],this._requestDraw(),this}},{key:"add",value:function(){if(0===arguments.length)return this;if(arguments.length>1){for(var t=0;t0?e[0]:void 0}},{key:"_generalFind",value:function(t,e){var i=[];return this._descendants((function(n){var r=n._isMatch(t);return r&&i.push(n),!(!r||!e)})),i}},{key:"_descendants",value:function(t){var e,i=function(t,e){var i="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!i){if(Array.isArray(t)||(i=S(t))||e){i&&(t=i);var n=0,r=function(){};return{s:r,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,o=!0,s=!1;return{s:function(){i=i.call(t)},n:function(){var t=i.next();return o=t.done,t},e:function(t){s=!0,a=t},f:function(){try{o||null==i.return||i.return()}finally{if(s)throw a}}}}(this.getChildren());try{for(i.s();!(e=i.n()).done;){var n=e.value;if(t(n))return!0;if(n.hasChildren()&&n._descendants(t))return!0}}catch(t){i.e(t)}finally{i.f()}return!1}},{key:"toObject",value:function(){var t=Ct.Node.prototype.toObject.call(this);return t.children=[],this.getChildren().forEach((function(e){t.children.push(e.toObject())})),t}},{key:"isAncestorOf",value:function(t){for(var e=t.getParent();e;){if(e._id===this._id)return!0;e=e.getParent()}return!1}},{key:"clone",value:function(t){var e=Ct.Node.prototype.clone.call(this,t);return this.getChildren().forEach((function(t){e.add(t.clone())})),e}},{key:"getAllIntersections",value:function(t){var e=[];return this.find("Shape").forEach((function(i){i.isVisible()&&i.intersects(t)&&e.push(i)})),e}},{key:"_clearSelfAndDescendantCache",value:function(t){var i;y(e,"_clearSelfAndDescendantCache",this)([t]),this.isCached()||null===(i=this.children)||void 0===i||i.forEach((function(e){e._clearSelfAndDescendantCache(t)}))}},{key:"_setChildrenIndices",value:function(){var t;null===(t=this.children)||void 0===t||t.forEach((function(t,e){t.index=e})),this._requestDraw()}},{key:"drawScene",value:function(t,e){var i=this.getLayer(),n=t||i&&i.getCanvas(),r=n&&n.getContext(),a=this._getCanvasCache(),o=a&&a.scene,s=n&&n.isCache;if(!this.isVisible()&&!s)return this;if(o){r.save();var h=this.getAbsoluteTransform(e).getMatrix();r.transform(h[0],h[1],h[2],h[3],h[4],h[5]),this._drawCachedSceneCanvas(r),r.restore()}else this._drawChildren("drawScene",n,e);return this}},{key:"drawHit",value:function(t,e){if(!this.shouldDrawHit(e))return this;var i=this.getLayer(),n=t||i&&i.hitCanvas,r=n&&n.getContext(),a=this._getCanvasCache();if(a&&a.hit){r.save();var o=this.getAbsoluteTransform(e).getMatrix();r.transform(o[0],o[1],o[2],o[3],o[4],o[5]),this._drawCachedHitCanvas(r),r.restore()}else this._drawChildren("drawHit",n,e);return this}},{key:"_drawChildren",value:function(t,e,i){var n,r=e&&e.getContext(),a=this.clipWidth(),o=this.clipHeight(),s=this.clipFunc(),h=a&&o||s,l=i===this;if(h){r.save();var u=this.getAbsoluteTransform(i),d=u.getMatrix();if(r.transform(d[0],d[1],d[2],d[3],d[4],d[5]),r.beginPath(),s)s.call(this,r,this);else{var c=this.clipX(),p=this.clipY();r.rect(c,p,a,o)}r.clip(),d=u.copy().invert().getMatrix(),r.transform(d[0],d[1],d[2],d[3],d[4],d[5])}var g=!l&&"source-over"!==this.globalCompositeOperation()&&"drawScene"===t;g&&(r.save(),r._applyGlobalCompositeOperation(this)),null===(n=this.children)||void 0===n||n.forEach((function(n){n[t](e,i)})),g&&r.restore(),h&&r.restore()}},{key:"getClientRect",value:function(t){var e,i,n,r,a,o=(t=t||{}).skipTransform,s=t.relativeTo,h={x:1/0,y:1/0,width:0,height:0},l=this;null===(e=this.children)||void 0===e||e.forEach((function(e){if(e.visible()){var o=e.getClientRect({relativeTo:l,skipShadow:t.skipShadow,skipStroke:t.skipStroke});0===o.width&&0===o.height||(void 0===i?(i=o.x,n=o.y,r=o.x+o.width,a=o.y+o.height):(i=Math.min(i,o.x),n=Math.min(n,o.y),r=Math.max(r,o.x+o.width),a=Math.max(a,o.y+o.height)))}}));for(var u=this.find("Shape"),d=!1,c=0;c=0?"pointer":t.indexOf("touch")>=0?"touch":"mouse"},z=function(t){var e=X(t);return"pointer"===e?r.Konva.pointerEventsEnabled&&U.pointer:"touch"===e?U.touch:"mouse"===e?U.mouse:void 0};function N(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return(t.clipFunc||t.clipWidth||t.clipHeight)&&e.Util.warn("Stage does not support clipping. Please use clip for Layers or Groups."),t}t.stages=[];var Z=function(i){function u(e){var i;return s(this,u),(i=o(this,u,[N(e)]))._pointerPositions=[],i._changedPointerPositions=[],i._buildDOM(),i._bindContentEvents(),t.stages.push(i),i.on("widthChange.konva heightChange.konva",i._resizeDOM),i.on("visibleChange.konva",i._checkVisibility),i.on("clipWidthChange.konva clipHeightChange.konva clipFuncChange.konva",(function(){N(i.attrs)})),i._checkVisibility(),i}return p(u,i),l(u,[{key:"_validateAdd",value:function(t){var i="Layer"===t.getType(),n="FastLayer"===t.getType();i||n||e.Util.throw("You may only add layers to the stage.")}},{key:"_checkVisibility",value:function(){if(this.content){var t=this.visible()?"":"none";this.content.style.display=t}}},{key:"setContainer",value:function(t){if("string"===k(t)){if("."===t.charAt(0)){var e=t.slice(1);t=document.getElementsByClassName(e)[0]}else{var i;i="#"!==t.charAt(0)?t:t.slice(1),t=document.getElementById(i)}if(!t)throw"Can not find container in document with id "+i}return this._setAttr("container",t),this.content&&(this.content.parentElement&&this.content.parentElement.removeChild(this.content),t.appendChild(this.content)),this}},{key:"shouldDrawHit",value:function(){return!0}},{key:"clear",value:function(){var t,e=this.children,i=e.length;for(t=0;t-1&&t.stages.splice(n,1),e.Util.releaseCanvas(this.bufferCanvas._canvas,this.bufferHitCanvas._canvas),this}},{key:"getPointerPosition",value:function(){var t=this._pointerPositions[0]||this._changedPointerPositions[0];return t?{x:t.x,y:t.y}:(e.Util.warn("Pointer position is missing and not registered by the stage. Looks like it is outside of the stage container. You can set it manually from event: stage.setPointersPositions(event);"),null)}},{key:"_getPointerById",value:function(t){return this._pointerPositions.find((function(e){return e.id===t}))}},{key:"getPointersPositions",value:function(){return this._pointerPositions}},{key:"getStage",value:function(){return this}},{key:"getContent",value:function(){return this.content}},{key:"_toKonvaCanvas",value:function(t){(t=t||{}).x=t.x||0,t.y=t.y||0,t.width=t.width||this.width(),t.height=t.height||this.height();var e=new a.SceneCanvas({width:t.width,height:t.height,pixelRatio:t.pixelRatio||1}),i=e.getContext()._context,n=this.children;return(t.x||t.y)&&i.translate(-1*t.x,-1*t.y),n.forEach((function(e){if(e.isVisible()){var n=e._toKonvaCanvas(t);i.drawImage(n._canvas,t.x,t.y,n.getWidth()/n.getPixelRatio(),n.getHeight()/n.getPixelRatio())}})),e}},{key:"getIntersection",value:function(t){if(!t)return null;var e,i=this.children;for(e=i.length-1;e>=0;e--){var n=i[e].getIntersection(t);if(n)return n}return null}},{key:"_resizeDOM",value:function(){var t=this.width(),e=this.height();this.content&&(this.content.style.width=t+"px",this.content.style.height=e+"px"),this.bufferCanvas.setSize(t,e),this.bufferHitCanvas.setSize(t,e),this.children.forEach((function(i){i.setSize({width:t,height:e}),i.draw()}))}},{key:"add",value:function(t){for(var i=arguments.length,n=new Array(i>1?i-1:0),a=1;a1){for(var o=0;o5&&e.Util.warn("The stage has "+s+" layers. Recommended maximum number of layers is 3-5. Adding more layers into the stage may drop the performance. Rethink your tree structure, you can use Konva.Group."),t.setSize({width:this.width(),height:this.height()}),t.draw(),r.Konva.isBrowser&&this.content.appendChild(t.canvas._canvas),this}},{key:"getParent",value:function(){return null}},{key:"getLayer",value:function(){return null}},{key:"hasPointerCapture",value:function(t){return c.hasPointerCapture(t,this)}},{key:"setPointerCapture",value:function(t){c.setPointerCapture(t,this)}},{key:"releaseCapture",value:function(t){c.releaseCapture(t,this)}},{key:"getLayers",value:function(){return this.children}},{key:"_bindContentEvents",value:function(){var t=this;r.Konva.isBrowser&&H.forEach((function(e){var i=v(e,2),n=i[0],r=i[1];t.content.addEventListener(n,(function(e){t[r](e)}),{passive:!1})}))}},{key:"_pointerenter",value:function(t){this.setPointersPositions(t);var e=z(t.type);this._fire(e.pointerenter,{evt:t,target:this,currentTarget:this})}},{key:"_pointerover",value:function(t){this.setPointersPositions(t);var e=z(t.type);this._fire(e.pointerover,{evt:t,target:this,currentTarget:this})}},{key:"_getTargetShape",value:function(t){var e=this[t+"targetShape"];return e&&!e.getStage()&&(e=null),e}},{key:"_pointerleave",value:function(t){var e=z(t.type),i=X(t.type);if(e){this.setPointersPositions(t);var n=this._getTargetShape(i),a=!h.DD.isDragging||r.Konva.hitOnDragEnabled;n&&a?(n._fireAndBubble(e.pointerout,{evt:t}),n._fireAndBubble(e.pointerleave,{evt:t}),this._fire(e.pointerleave,{evt:t,target:this,currentTarget:this}),this[i+"targetShape"]=null):a&&(this._fire(e.pointerleave,{evt:t,target:this,currentTarget:this}),this._fire(e.pointerout,{evt:t,target:this,currentTarget:this})),this.pointerPos=void 0,this._pointerPositions=[]}}},{key:"_pointerdown",value:function(t){var e=this,i=z(t.type),n=X(t.type);if(i){this.setPointersPositions(t);var a=!1;this._changedPointerPositions.forEach((function(o){var s=e.getIntersection(o);if(h.DD.justDragged=!1,r.Konva["_"+n+"ListenClick"]=!0,s&&s.isListening()){r.Konva.capturePointerEventsEnabled&&s.setPointerCapture(o.id),e[n+"ClickStartShape"]=s,s._fireAndBubble(i.pointerdown,{evt:t,pointerId:o.id}),a=!0;var l=t.type.indexOf("touch")>=0;s.preventDefault()&&t.cancelable&&l&&t.preventDefault()}})),a||this._fire(i.pointerdown,{evt:t,target:this,currentTarget:this,pointerId:this._pointerPositions[0].id})}}},{key:"_pointermove",value:function(t){var e=this,i=z(t.type),n=X(t.type);if(i&&(h.DD.isDragging&&h.DD.node.preventDefault()&&t.cancelable&&t.preventDefault(),this.setPointersPositions(t),!h.DD.isDragging||r.Konva.hitOnDragEnabled)){var a={},o=!1,s=this._getTargetShape(n);this._changedPointerPositions.forEach((function(r){var h=c.getCapturedShape(r.id)||e.getIntersection(r),l=r.id,u={evt:t,pointerId:l},d=s!==h;if(d&&s&&(s._fireAndBubble(i.pointerout,Object.assign({},u),h),s._fireAndBubble(i.pointerleave,Object.assign({},u),h)),h){if(a[h._id])return;a[h._id]=!0}h&&h.isListening()?(o=!0,d&&(h._fireAndBubble(i.pointerover,Object.assign({},u),s),h._fireAndBubble(i.pointerenter,Object.assign({},u),s),e[n+"targetShape"]=h),h._fireAndBubble(i.pointermove,Object.assign({},u))):s&&(e._fire(i.pointerover,{evt:t,target:e,currentTarget:e,pointerId:l}),e[n+"targetShape"]=null)})),o||this._fire(i.pointermove,{evt:t,target:this,currentTarget:this,pointerId:this._changedPointerPositions[0].id})}}},{key:"_pointerup",value:function(t){var e=this,i=z(t.type),n=X(t.type);if(i){this.setPointersPositions(t);var a=this[n+"ClickStartShape"],o=this[n+"ClickEndShape"],s={},l=!1;this._changedPointerPositions.forEach((function(u){var d=c.getCapturedShape(u.id)||e.getIntersection(u);if(d){if(d.releaseCapture(u.id),s[d._id])return;s[d._id]=!0}var p=u.id,g={evt:t,pointerId:p},f=!1;r.Konva["_"+n+"InDblClickWindow"]?(f=!0,clearTimeout(e[n+"DblTimeout"])):h.DD.justDragged||(r.Konva["_"+n+"InDblClickWindow"]=!0,clearTimeout(e[n+"DblTimeout"])),e[n+"DblTimeout"]=setTimeout((function(){r.Konva["_"+n+"InDblClickWindow"]=!1}),r.Konva.dblClickWindow),d&&d.isListening()?(l=!0,e[n+"ClickEndShape"]=d,d._fireAndBubble(i.pointerup,Object.assign({},g)),r.Konva["_"+n+"ListenClick"]&&a&&a===d&&(d._fireAndBubble(i.pointerclick,Object.assign({},g)),f&&o&&o===d&&d._fireAndBubble(i.pointerdblclick,Object.assign({},g)))):(e[n+"ClickEndShape"]=null,r.Konva["_"+n+"ListenClick"]&&e._fire(i.pointerclick,{evt:t,target:e,currentTarget:e,pointerId:p}),f&&e._fire(i.pointerdblclick,{evt:t,target:e,currentTarget:e,pointerId:p}))})),l||this._fire(i.pointerup,{evt:t,target:this,currentTarget:this,pointerId:this._changedPointerPositions[0].id}),r.Konva["_"+n+"ListenClick"]=!1,t.cancelable&&"touch"!==n&&t.preventDefault()}}},{key:"_contextmenu",value:function(t){this.setPointersPositions(t);var e=this.getIntersection(this.getPointerPosition());e&&e.isListening()?e._fireAndBubble(F,{evt:t}):this._fire(F,{evt:t,target:this,currentTarget:this})}},{key:"_wheel",value:function(t){this.setPointersPositions(t);var e=this.getIntersection(this.getPointerPosition());e&&e.isListening()?e._fireAndBubble(V,{evt:t}):this._fire(V,{evt:t,target:this,currentTarget:this})}},{key:"_pointercancel",value:function(t){this.setPointersPositions(t);var e=c.getCapturedShape(t.pointerId)||this.getIntersection(this.getPointerPosition());e&&e._fireAndBubble(x,c.createEvent(t)),c.releaseCapture(t.pointerId)}},{key:"_lostpointercapture",value:function(t){c.releaseCapture(t.pointerId)}},{key:"setPointersPositions",value:function(t){var i=this,n=this._getContentPosition(),r=null,a=null;void 0!==(t=t||window.event).touches?(this._pointerPositions=[],this._changedPointerPositions=[],Array.prototype.forEach.call(t.touches,(function(t){i._pointerPositions.push({id:t.identifier,x:(t.clientX-n.left)/n.scaleX,y:(t.clientY-n.top)/n.scaleY})})),Array.prototype.forEach.call(t.changedTouches||t.touches,(function(t){i._changedPointerPositions.push({id:t.identifier,x:(t.clientX-n.left)/n.scaleX,y:(t.clientY-n.top)/n.scaleY})}))):(r=(t.clientX-n.left)/n.scaleX,a=(t.clientY-n.top)/n.scaleY,this.pointerPos={x:r,y:a},this._pointerPositions=[{x:r,y:a,id:e.Util._getFirstPointerId(t)}],this._changedPointerPositions=[{x:r,y:a,id:e.Util._getFirstPointerId(t)}])}},{key:"_setPointerPosition",value:function(t){e.Util.warn('Method _setPointerPosition is deprecated. Use "stage.setPointersPositions(event)" instead.'),this.setPointersPositions(t)}},{key:"_getContentPosition",value:function(){if(!this.content||!this.content.getBoundingClientRect)return{top:0,left:0,scaleX:1,scaleY:1};var t=this.content.getBoundingClientRect();return{top:t.top,left:t.left,scaleX:t.width/this.content.clientWidth||1,scaleY:t.height/this.content.clientHeight||1}}},{key:"_buildDOM",value:function(){if(this.bufferCanvas=new a.SceneCanvas({width:this.width(),height:this.height()}),this.bufferHitCanvas=new a.HitCanvas({pixelRatio:1,width:this.width(),height:this.height()}),r.Konva.isBrowser){var t=this.container();if(!t)throw"Stage has no container. A container is required.";t.innerHTML="",this.content=document.createElement("div"),this.content.style.position="relative",this.content.style.userSelect="none",this.content.className="konvajs-content",this.content.setAttribute("role","presentation"),t.appendChild(this.content),this._resizeDOM()}}},{key:"cache",value:function(){return e.Util.warn("Cache function is not allowed for stage. You may use cache only for layers, groups and shapes."),this}},{key:"clearCache",value:function(){return this}},{key:"batchDraw",value:function(){return this.getChildren().forEach((function(t){t.batchDraw()})),this}}])}(n.Container);t.Stage=Z,Z.prototype.nodeType="Stage",(0,d._registerNode)(Z),i.Factory.addGetterSetter(Z,"container")}(At);var Ft={},Wt={};!function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.Shape=t.shapes=void 0;var e,i=A,n=P,r=D,a=I,h=M,u=A,d=Pt,c="hasShadow",g="shadowRGBA",f="patternImage",_="linearGradient",m="radialGradient";function v(){return e||(e=n.Util.createCanvasElement().getContext("2d"))}t.shapes={};var y=function(e){function r(e){var i,a;for(s(this,r),i=o(this,r,[e]);!(a=n.Util.getRandomColor())||a in t.shapes;);return i.colorKey=a,t.shapes[a]=i,i}return p(r,e),l(r,[{key:"getContext",value:function(){return n.Util.warn("shape.getContext() method is deprecated. Please do not use it."),this.getLayer().getContext()}},{key:"getCanvas",value:function(){return n.Util.warn("shape.getCanvas() method is deprecated. Please do not use it."),this.getLayer().getCanvas()}},{key:"getSceneFunc",value:function(){return this.attrs.sceneFunc||this._sceneFunc}},{key:"getHitFunc",value:function(){return this.attrs.hitFunc||this._hitFunc}},{key:"hasShadow",value:function(){return this._getCache(c,this._hasShadow)}},{key:"_hasShadow",value:function(){return this.shadowEnabled()&&0!==this.shadowOpacity()&&!!(this.shadowColor()||this.shadowBlur()||this.shadowOffsetX()||this.shadowOffsetY())}},{key:"_getFillPattern",value:function(){return this._getCache(f,this.__getFillPattern)}},{key:"__getFillPattern",value:function(){if(this.fillPatternImage()){var t=v().createPattern(this.fillPatternImage(),this.fillPatternRepeat()||"repeat");if(t&&t.setTransform){var e=new n.Transform;e.translate(this.fillPatternX(),this.fillPatternY()),e.rotate(i.Konva.getAngle(this.fillPatternRotation())),e.scale(this.fillPatternScaleX(),this.fillPatternScaleY()),e.translate(-1*this.fillPatternOffsetX(),-1*this.fillPatternOffsetY());var r=e.getMatrix(),a="undefined"==typeof DOMMatrix?{a:r[0],b:r[1],c:r[2],d:r[3],e:r[4],f:r[5]}:new DOMMatrix(r);t.setTransform(a)}return t}}},{key:"_getLinearGradient",value:function(){return this._getCache(_,this.__getLinearGradient)}},{key:"__getLinearGradient",value:function(){var t=this.fillLinearGradientColorStops();if(t){for(var e=v(),i=this.fillLinearGradientStartPoint(),n=this.fillLinearGradientEndPoint(),r=e.createLinearGradient(i.x,i.y,n.x,n.y),a=0;a0}},{key:"destroy",value:function(){return a.Node.prototype.destroy.call(this),delete t.shapes[this.colorKey],delete this.colorKey,this}},{key:"_useBufferCanvas",value:function(t){var e;if(!this.getStage())return!1;if(!(null===(e=this.attrs.perfectDrawEnabled)||void 0===e||e))return!1;var i=t||this.hasFill(),n=this.hasStroke(),r=1!==this.getAbsoluteOpacity();if(i&&n&&r)return!0;var a=this.hasShadow(),o=this.shadowForStrokeEnabled();return!!(i&&n&&a&&o)}},{key:"setStrokeHitEnabled",value:function(t){n.Util.warn("strokeHitEnabled property is deprecated. Please use hitStrokeWidth instead."),t?this.hitStrokeWidth("auto"):this.hitStrokeWidth(0)}},{key:"getStrokeHitEnabled",value:function(){return 0!==this.hitStrokeWidth()}},{key:"getSelfRect",value:function(){var t=this.size();return{x:this._centroid?-t.width/2:0,y:this._centroid?-t.height/2:0,width:t.width,height:t.height}}},{key:"getClientRect",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=t.skipTransform,i=t.relativeTo,n=this.getSelfRect(),r=!t.skipStroke&&this.hasStroke()&&this.strokeWidth()||0,a=n.width+r,o=n.height+r,s=!t.skipShadow&&this.hasShadow(),h=s?this.shadowOffsetX():0,l=s?this.shadowOffsetY():0,u=a+Math.abs(h),d=o+Math.abs(l),c=s&&this.shadowBlur()||0,p={width:u+2*c,height:d+2*c,x:-(r/2+c)+Math.min(h,0)+n.x,y:-(r/2+c)+Math.min(l,0)+n.y};return e?p:this._transformedRect(p,i)}},{key:"drawScene",value:function(t,e){var i,n,r=this.getLayer(),a=t||r.getCanvas(),o=a.getContext(),s=this._getCanvasCache(),h=this.getSceneFunc(),l=this.hasShadow(),u=a.isCache,d=e===this;if(!this.isVisible()&&!d)return this;if(s){o.save();var c=this.getAbsoluteTransform(e).getMatrix();return o.transform(c[0],c[1],c[2],c[3],c[4],c[5]),this._drawCachedSceneCanvas(o),o.restore(),this}if(!h)return this;if(o.save(),this._useBufferCanvas()&&!u){(n=(i=this.getStage().bufferCanvas).getContext()).clear(),n.save(),n._applyLineJoin(this);var p=this.getAbsoluteTransform(e).getMatrix();n.transform(p[0],p[1],p[2],p[3],p[4],p[5]),h.call(this,n,this),n.restore();var g=i.pixelRatio;l&&o._applyShadow(this),o._applyOpacity(this),o._applyGlobalCompositeOperation(this),o.drawImage(i._canvas,0,0,i.width/g,i.height/g)}else{if(o._applyLineJoin(this),!d){p=this.getAbsoluteTransform(e).getMatrix();o.transform(p[0],p[1],p[2],p[3],p[4],p[5]),o._applyOpacity(this),o._applyGlobalCompositeOperation(this)}l&&o._applyShadow(this),h.call(this,o,this)}return o.restore(),this}},{key:"drawHit",value:function(t,e){var i=arguments.length>2&&void 0!==arguments[2]&&arguments[2];if(!this.shouldDrawHit(e,i))return this;var r=this.getLayer(),a=t||r.hitCanvas,o=a&&a.getContext(),s=this.hitFunc()||this.sceneFunc(),h=this._getCanvasCache(),l=h&&h.hit;if(this.colorKey||n.Util.warn("Looks like your canvas has a destroyed shape in it. Do not reuse shape after you destroyed it. If you want to reuse shape you should call remove() instead of destroy()"),l){o.save();var u=this.getAbsoluteTransform(e).getMatrix();return o.transform(u[0],u[1],u[2],u[3],u[4],u[5]),this._drawCachedHitCanvas(o),o.restore(),this}if(!s)return this;if(o.save(),o._applyLineJoin(this),!(this===e)){var d=this.getAbsoluteTransform(e).getMatrix();o.transform(d[0],d[1],d[2],d[3],d[4],d[5])}return s.call(this,o,this),o.restore(),this}},{key:"drawHitFromCache",value:function(){var t,e,i,r,a,o=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,s=this._getCanvasCache(),h=this._getCachedSceneCanvas(),l=s.hit,u=l.getContext(),d=l.getWidth(),c=l.getHeight();u.clear(),u.drawImage(h._canvas,0,0,d,c);try{for(i=(e=(t=u.getImageData(0,0,d,c)).data).length,r=n.Util._hexToRgb(this.colorKey),a=0;ao?(e[a]=r.r,e[a+1]=r.g,e[a+2]=r.b,e[a+3]=255):e[a+3]=0;u.putImageData(t,0,0)}catch(t){n.Util.error("Unable to draw hit graph from cached scene canvas. "+t.message)}return this}},{key:"hasPointerCapture",value:function(t){return d.hasPointerCapture(t,this)}},{key:"setPointerCapture",value:function(t){d.setPointerCapture(t,this)}},{key:"releaseCapture",value:function(t){d.releaseCapture(t,this)}}])}(a.Node);t.Shape=y,y.prototype._fillFunc=function(t){t.fill()},y.prototype._strokeFunc=function(t){t.stroke()},y.prototype._fillFuncHit=function(t){t.fill()},y.prototype._strokeFuncHit=function(t){t.stroke()},y.prototype._centroid=!1,y.prototype.nodeType="Shape",(0,u._registerNode)(y),y.prototype.eventListeners={},y.prototype.on.call(y.prototype,"shadowColorChange.konva shadowBlurChange.konva shadowOffsetChange.konva shadowOpacityChange.konva shadowEnabledChange.konva",(function(){this._clearCache(c)})),y.prototype.on.call(y.prototype,"shadowColorChange.konva shadowOpacityChange.konva shadowEnabledChange.konva",(function(){this._clearCache(g)})),y.prototype.on.call(y.prototype,"fillPriorityChange.konva fillPatternImageChange.konva fillPatternRepeatChange.konva fillPatternScaleXChange.konva fillPatternScaleYChange.konva fillPatternOffsetXChange.konva fillPatternOffsetYChange.konva fillPatternXChange.konva fillPatternYChange.konva fillPatternRotationChange.konva",(function(){this._clearCache(f)})),y.prototype.on.call(y.prototype,"fillPriorityChange.konva fillLinearGradientColorStopsChange.konva fillLinearGradientStartPointXChange.konva fillLinearGradientStartPointYChange.konva fillLinearGradientEndPointXChange.konva fillLinearGradientEndPointYChange.konva",(function(){this._clearCache(_)})),y.prototype.on.call(y.prototype,"fillPriorityChange.konva fillRadialGradientColorStopsChange.konva fillRadialGradientStartPointXChange.konva fillRadialGradientStartPointYChange.konva fillRadialGradientEndPointXChange.konva fillRadialGradientEndPointYChange.konva fillRadialGradientStartRadiusChange.konva fillRadialGradientEndRadiusChange.konva",(function(){this._clearCache(m)})),r.Factory.addGetterSetter(y,"stroke",void 0,(0,h.getStringOrGradientValidator)()),r.Factory.addGetterSetter(y,"strokeWidth",2,(0,h.getNumberValidator)()),r.Factory.addGetterSetter(y,"fillAfterStrokeEnabled",!1),r.Factory.addGetterSetter(y,"hitStrokeWidth","auto",(0,h.getNumberOrAutoValidator)()),r.Factory.addGetterSetter(y,"strokeHitEnabled",!0,(0,h.getBooleanValidator)()),r.Factory.addGetterSetter(y,"perfectDrawEnabled",!0,(0,h.getBooleanValidator)()),r.Factory.addGetterSetter(y,"shadowForStrokeEnabled",!0,(0,h.getBooleanValidator)()),r.Factory.addGetterSetter(y,"lineJoin"),r.Factory.addGetterSetter(y,"lineCap"),r.Factory.addGetterSetter(y,"sceneFunc"),r.Factory.addGetterSetter(y,"hitFunc"),r.Factory.addGetterSetter(y,"dash"),r.Factory.addGetterSetter(y,"dashOffset",0,(0,h.getNumberValidator)()),r.Factory.addGetterSetter(y,"shadowColor",void 0,(0,h.getStringValidator)()),r.Factory.addGetterSetter(y,"shadowBlur",0,(0,h.getNumberValidator)()),r.Factory.addGetterSetter(y,"shadowOpacity",1,(0,h.getNumberValidator)()),r.Factory.addComponentsGetterSetter(y,"shadowOffset",["x","y"]),r.Factory.addGetterSetter(y,"shadowOffsetX",0,(0,h.getNumberValidator)()),r.Factory.addGetterSetter(y,"shadowOffsetY",0,(0,h.getNumberValidator)()),r.Factory.addGetterSetter(y,"fillPatternImage"),r.Factory.addGetterSetter(y,"fill",void 0,(0,h.getStringOrGradientValidator)()),r.Factory.addGetterSetter(y,"fillPatternX",0,(0,h.getNumberValidator)()),r.Factory.addGetterSetter(y,"fillPatternY",0,(0,h.getNumberValidator)()),r.Factory.addGetterSetter(y,"fillLinearGradientColorStops"),r.Factory.addGetterSetter(y,"strokeLinearGradientColorStops"),r.Factory.addGetterSetter(y,"fillRadialGradientStartRadius",0),r.Factory.addGetterSetter(y,"fillRadialGradientEndRadius",0),r.Factory.addGetterSetter(y,"fillRadialGradientColorStops"),r.Factory.addGetterSetter(y,"fillPatternRepeat","repeat"),r.Factory.addGetterSetter(y,"fillEnabled",!0),r.Factory.addGetterSetter(y,"strokeEnabled",!0),r.Factory.addGetterSetter(y,"shadowEnabled",!0),r.Factory.addGetterSetter(y,"dashEnabled",!0),r.Factory.addGetterSetter(y,"strokeScaleEnabled",!0),r.Factory.addGetterSetter(y,"fillPriority","color"),r.Factory.addComponentsGetterSetter(y,"fillPatternOffset",["x","y"]),r.Factory.addGetterSetter(y,"fillPatternOffsetX",0,(0,h.getNumberValidator)()),r.Factory.addGetterSetter(y,"fillPatternOffsetY",0,(0,h.getNumberValidator)()),r.Factory.addComponentsGetterSetter(y,"fillPatternScale",["x","y"]),r.Factory.addGetterSetter(y,"fillPatternScaleX",1,(0,h.getNumberValidator)()),r.Factory.addGetterSetter(y,"fillPatternScaleY",1,(0,h.getNumberValidator)()),r.Factory.addComponentsGetterSetter(y,"fillLinearGradientStartPoint",["x","y"]),r.Factory.addComponentsGetterSetter(y,"strokeLinearGradientStartPoint",["x","y"]),r.Factory.addGetterSetter(y,"fillLinearGradientStartPointX",0),r.Factory.addGetterSetter(y,"strokeLinearGradientStartPointX",0),r.Factory.addGetterSetter(y,"fillLinearGradientStartPointY",0),r.Factory.addGetterSetter(y,"strokeLinearGradientStartPointY",0),r.Factory.addComponentsGetterSetter(y,"fillLinearGradientEndPoint",["x","y"]),r.Factory.addComponentsGetterSetter(y,"strokeLinearGradientEndPoint",["x","y"]),r.Factory.addGetterSetter(y,"fillLinearGradientEndPointX",0),r.Factory.addGetterSetter(y,"strokeLinearGradientEndPointX",0),r.Factory.addGetterSetter(y,"fillLinearGradientEndPointY",0),r.Factory.addGetterSetter(y,"strokeLinearGradientEndPointY",0),r.Factory.addComponentsGetterSetter(y,"fillRadialGradientStartPoint",["x","y"]),r.Factory.addGetterSetter(y,"fillRadialGradientStartPointX",0),r.Factory.addGetterSetter(y,"fillRadialGradientStartPointY",0),r.Factory.addComponentsGetterSetter(y,"fillRadialGradientEndPoint",["x","y"]),r.Factory.addGetterSetter(y,"fillRadialGradientEndPointX",0),r.Factory.addGetterSetter(y,"fillRadialGradientEndPointY",0),r.Factory.addGetterSetter(y,"fillPatternRotation",0),r.Factory.backCompat(y,{dashArray:"dash",getDashArray:"getDash",setDashArray:"getDash",drawFunc:"sceneFunc",getDrawFunc:"getSceneFunc",setDrawFunc:"setSceneFunc",drawHitFunc:"hitFunc",getDrawHitFunc:"getHitFunc",setDrawHitFunc:"setHitFunc"})}(Wt),Object.defineProperty(Ft,"__esModule",{value:!0}),Ft.Layer=void 0;var Gt=P,Ot=kt,Rt=I,Bt=D,Vt=W,Ht=M,Ut=Wt,Xt=A,zt=[{x:0,y:0},{x:-1,y:-1},{x:1,y:-1},{x:1,y:1},{x:-1,y:1}],Nt=zt.length,Zt=function(t){function e(t){var i;return s(this,e),(i=o(this,e,[t])).canvas=new Vt.SceneCanvas,i.hitCanvas=new Vt.HitCanvas({pixelRatio:1}),i._waitingForDraw=!1,i.on("visibleChange.konva",i._checkVisibility),i._checkVisibility(),i.on("imageSmoothingEnabledChange.konva",i._setSmoothEnabled),i._setSmoothEnabled(),i}return p(e,t),l(e,[{key:"createPNGStream",value:function(){return this.canvas._canvas.createPNGStream()}},{key:"getCanvas",value:function(){return this.canvas}},{key:"getNativeCanvasElement",value:function(){return this.canvas._canvas}},{key:"getHitCanvas",value:function(){return this.hitCanvas}},{key:"getContext",value:function(){return this.getCanvas().getContext()}},{key:"clear",value:function(t){return this.getContext().clear(t),this.getHitCanvas().getContext().clear(t),this}},{key:"setZIndex",value:function(t){y(e,"setZIndex",this)([t]);var i=this.getStage();return i&&i.content&&(i.content.removeChild(this.getNativeCanvasElement()),t0?{antialiased:!0}:{}}},{key:"drawScene",value:function(t,e){var i=this.getLayer(),n=t||i&&i.getCanvas();return this._fire("beforeDraw",{node:this}),this.clearBeforeDraw()&&n.getContext().clear(),Ot.Container.prototype.drawScene.call(this,n,e),this._fire("draw",{node:this}),this}},{key:"drawHit",value:function(t,e){var i=this.getLayer(),n=t||i&&i.hitCanvas;return i&&i.clearBeforeDraw()&&i.getHitCanvas().getContext().clear(),Ot.Container.prototype.drawHit.call(this,n,e),this}},{key:"enableHitGraph",value:function(){return this.hitGraphEnabled(!0),this}},{key:"disableHitGraph",value:function(){return this.hitGraphEnabled(!1),this}},{key:"setHitGraphEnabled",value:function(t){Gt.Util.warn("hitGraphEnabled method is deprecated. Please use layer.listening() instead."),this.listening(t)}},{key:"getHitGraphEnabled",value:function(t){return Gt.Util.warn("hitGraphEnabled method is deprecated. Please use layer.listening() instead."),this.listening()}},{key:"toggleHitCanvas",value:function(){if(this.parent&&this.parent.content){var t=this.parent;!!this.hitCanvas._canvas.parentNode?t.content.removeChild(this.hitCanvas._canvas):t.content.appendChild(this.hitCanvas._canvas)}}},{key:"destroy",value:function(){return Gt.Util.releaseCanvas(this.getNativeCanvasElement(),this.getHitCanvas()._canvas),y(e,"destroy",this)([])}}])}(Ot.Container);Ft.Layer=Zt,Zt.prototype.nodeType="Layer",(0,Xt._registerNode)(Zt),Bt.Factory.addGetterSetter(Zt,"imageSmoothingEnabled",!0),Bt.Factory.addGetterSetter(Zt,"clearBeforeDraw",!0),Bt.Factory.addGetterSetter(Zt,"hitGraphEnabled",!0,(0,Ht.getBooleanValidator)());var Yt={};Object.defineProperty(Yt,"__esModule",{value:!0}),Yt.FastLayer=void 0;var Kt=P,jt=A,qt=function(t){function e(t){var i;return s(this,e),(i=o(this,e,[t])).listening(!1),Kt.Util.warn('Konva.Fast layer is deprecated. Please use "new Konva.Layer({ listening: false })" instead.'),i}return p(e,t),l(e)}(Ft.Layer);Yt.FastLayer=qt,qt.prototype.nodeType="FastLayer",(0,jt._registerNode)(qt);var Jt={};Object.defineProperty(Jt,"__esModule",{value:!0}),Jt.Group=void 0;var Qt=P,$t=A,te=function(t){function e(){return s(this,e),o(this,e,arguments)}return p(e,t),l(e,[{key:"_validateAdd",value:function(t){var e=t.getType();"Group"!==e&&"Shape"!==e&&Qt.Util.throw("You may only add groups and shapes to groups.")}}])}(kt.Container);Jt.Group=te,te.prototype.nodeType="Group",(0,$t._registerNode)(te);var ee={};Object.defineProperty(ee,"__esModule",{value:!0});var ie=ee.Animation=void 0,ne=A,re=P,ae=ne.glob.performance&&ne.glob.performance.now?function(){return ne.glob.performance.now()}:function(){return(new Date).getTime()},oe=function(){function t(e,i){s(this,t),this.id=t.animIdCounter++,this.frame={time:0,timeDiff:0,lastTime:ae(),frameRate:0},this.func=e,this.setLayers(i)}return l(t,[{key:"setLayers",value:function(t){var e=[];return e=t?t.length>0?t:[t]:[],this.layers=e,this}},{key:"getLayers",value:function(){return this.layers}},{key:"addLayer",value:function(t){var e,i=this.layers,n=i.length;for(e=0;ethis.duration?this.yoyo?(this._time=this.duration,this.reverse()):this.finish():t<0?this.yoyo?(this._time=0,this.play()):this.reset():(this._time=t,this.update())}},{key:"getTime",value:function(){return this._time}},{key:"setPosition",value:function(t){this.prevPos=this._pos,this.propFunc(t),this._pos=t}},{key:"getPosition",value:function(t){return void 0===t&&(t=this._time),this.func(t,this.begin,this._change,this.duration)}},{key:"play",value:function(){this.state=2,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire("onPlay")}},{key:"reverse",value:function(){this.state=3,this._time=this.duration-this._time,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire("onReverse")}},{key:"seek",value:function(t){this.pause(),this._time=t,this.update(),this.fire("onSeek")}},{key:"reset",value:function(){this.pause(),this._time=0,this.update(),this.fire("onReset")}},{key:"finish",value:function(){this.pause(),this._time=this.duration,this.update(),this.fire("onFinish")}},{key:"update",value:function(){this.setPosition(this.getPosition(this._time)),this.fire("onUpdate")}},{key:"onEnterFrame",value:function(){var t=this.getTimer()-this._startTime;2===this.state?this.setTime(t):3===this.state&&this.setTime(this.duration-t)}},{key:"pause",value:function(){this.state=1,this.fire("onPause")}},{key:"getTimer",value:function(){return(new Date).getTime()}}])}(),d=function(){function n(h){s(this,n);var l,d,c=this,p=h.node,g=p._id,f=h.easing||t.Easings.Linear,_=!!h.yoyo;l=void 0===h.duration?.3:0===h.duration?.001:h.duration,this.node=p,this._id=o++;var m=p.getLayer()||(p instanceof r.Konva.Stage?p.getLayers():null);for(d in m||e.Util.error("Tween constructor have `node` that is not in a layer. Please add node into layer first."),this.anim=new i.Animation((function(){c.tween.onEnterFrame()}),m),this.tween=new u(d,(function(t){c._tweenFunc(t)}),f,0,1,1e3*l,_),this._addListeners(),n.attrs[g]||(n.attrs[g]={}),n.attrs[g][this._id]||(n.attrs[g][this._id]={}),n.tweens[g]||(n.tweens[g]={}),h)void 0===a[d]&&this._addAttr(d,h[d]);this.reset(),this.onFinish=h.onFinish,this.onReset=h.onReset,this.onUpdate=h.onUpdate}return l(n,[{key:"_addAttr",value:function(t,i){var r,a,o,s,l,u,d,c,p=this.node,g=p._id;if((o=n.tweens[g][t])&&delete n.attrs[g][o][t],r=p.getAttr(t),e.Util._isArray(i))if(a=[],l=Math.max(i.length,r.length),"points"===t&&i.length!==r.length&&(i.length>r.length?(d=r,r=e.Util._prepareArrayForTween(r,i,p.closed())):(u=i,i=e.Util._prepareArrayForTween(i,r,p.closed()))),0===t.indexOf("fill"))for(s=0;s0&&i.push(o),i.push(a%60),i.push(r%60);for(var s=0;s0&&(i+="."+le(n,e)),i}function de(t,e,i){return ti?i:t}function ce(t,e){return Object.prototype.hasOwnProperty.call(t,e)}function pe(t,e){for(var i in e)ce(e,i)&&(t[i]=e[i]);return t}function ge(t){return"number"==typeof t}function fe(t){return"number"==typeof t&&Number.isFinite(t)}function _e(t){return null!==t&&"object"===k(t)&&!Array.isArray(t)}function me(t){return"string"==typeof t}function ve(t){return null==t}function ye(t){return!0===t||!1===t}function be(t){return t instanceof HTMLElement}function we(t){return _e(t)&&ce(t,"linearGradientStart")&&ce(t,"linearGradientEnd")&&ce(t,"linearGradientColorStops")&&ge(t.linearGradientStart)&&ge(t.linearGradientEnd)&&function(t){return Array.isArray(t)}(t.linearGradientColorStops)&&2===t.linearGradientColorStops.length}function ke(t){for(;null!==t.parent;){if(t.parent instanceof he.Layer)return t;t=t.parent}return null}var Se=/HeadlessChrome/.test(navigator.userAgent);var Ce=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame,xe=window.cancelAnimationFrame||window.mozCancelAnimationFrame||window.webkitCancelAnimationFrame||window.msCancelAnimationFrame,Te={forward:{},reverse:{}};Te.forward[C.POINT]=0,Te.forward[C.SEGMENT_START]=1,Te.forward[C.SEGMENT_END]=2,Te.reverse[C.POINT]=0,Te.reverse[C.SEGMENT_START]=2,Te.reverse[C.SEGMENT_END]=1;var Ae={0:"points.enter",1:"segments.enter",2:"segments.exit"},Pe={};function Ie(t,e){switch(e.type){case C.POINT:return t.points.getPoint(e.id);case C.SEGMENT_START:case C.SEGMENT_END:return t.segments.getSegment(e.id);default:throw new Error("getPointOrSegment: id not found?")}}function De(t){this._cues=[],this._peaks=t,this._previousTime=-1,this._updateCues=this._updateCues.bind(this),this._onPlaying=this._onPlaying.bind(this),this._onSeeked=this._onSeeked.bind(this),this._onTimeUpdate=this._onTimeUpdate.bind(this),this._onAnimationFrame=this._onAnimationFrame.bind(this),this._rAFHandle=null,this._activeSegments={},this._attachEventHandlers()}function Me(t){return function(e){return e.id===t}}Pe[0]="point",Pe[1]="segment",Pe[2]="segment",De.prototype._updateCues=function(){var t=this,e=t._peaks.points.getPoints(),i=t._peaks.segments.getSegments();t._cues.length=0,e.forEach((function(e){t._cues.push(new C(e.time,C.POINT,e.id))})),i.forEach((function(e){t._cues.push(new C(e.startTime,C.SEGMENT_START,e.id)),t._cues.push(new C(e.endTime,C.SEGMENT_END,e.id))})),t._cues.sort(C.sorter);var n=t._peaks.player.getCurrentTime();t._updateActiveSegments(n)},De.prototype._onUpdate=function(t,e){var i,n,r,a=t>e;a?(i=0,n=this._cues.length,r=1):(i=this._cues.length-1,n=-1,r=-1);for(var o=i;a?on;o+=r){var s=this._cues[o];if(a?s.time>e:s.timet:s.time=t&&this.time=e.startTime&&t0?function(i){return i.startTime===t&&i.endTime===e}:function(e){return e.startTime===t},this._removeSegments(i)},Ue.prototype.removeAll=function(){this._segments=[],this._segmentsById={},this._segmentsByPid={},this._peaks.emit("segments.remove_all")},Ue.prototype.setInserting=function(t){this._isInserting=t},Ue.prototype.isInserting=function(){return this._isInserting};var Xe=["OBJECT","TEXTAREA","INPUT","SELECT","OPTION"],ze=[32,9,37,39];function Ne(t){this.eventEmitter=t,this._handleKeyEvent=this._handleKeyEvent.bind(this),document.addEventListener("keydown",this._handleKeyEvent),document.addEventListener("keypress",this._handleKeyEvent),document.addEventListener("keyup",this._handleKeyEvent)}function Ze(t){this._mediaElement=t}function Ye(t,e){this._eventEmitter=t,this._mediaElement=e,this._playerCanPlayHandler=this._playerCanPlayHandler.bind(this),this._playerErrorHandler=this._playerErrorHandler.bind(this)}function Ke(t){var e=function(t){for(var e=[],i=t;i;)Object.getOwnPropertyNames(i).forEach((function(t){e.push(t)})),i=Object.getPrototypeOf(i);return e}(t);["init","destroy","play","pause","isPlaying","isSeeking","getCurrentTime","getDuration","seek"].forEach((function(i){if(!e.includes(i))throw new TypeError("Peaks.init(): Player method "+i+" is undefined");if("function"!=typeof t[i])throw new TypeError("Peaks.init(): Player method "+i+" is not a function")}))}function je(t,e){this._peaks=t,this._playingSegment=!1,this._segment=null,this._loop=!1,this._playSegmentTimerCallback=this._playSegmentTimerCallback.bind(this),Ke(e),this._adapter=e}Ne.prototype._handleKeyEvent=function(t){if(-1===Xe.indexOf(t.target.nodeName))if(ze.indexOf(t.type)>-1&&t.preventDefault(),"keydown"===t.type||"keypress"===t.type)switch(t.keyCode){case 32:this.eventEmitter.emit("keyboard.space");break;case 9:this.eventEmitter.emit("keyboard.tab")}else if("keyup"===t.type)switch(t.keyCode){case 37:t.shiftKey?this.eventEmitter.emit("keyboard.shift_left"):this.eventEmitter.emit("keyboard.left");break;case 39:t.shiftKey?this.eventEmitter.emit("keyboard.shift_right"):this.eventEmitter.emit("keyboard.right")}},Ne.prototype.destroy=function(){document.removeEventListener("keydown",this._handleKeyEvent),document.removeEventListener("keypress",this._handleKeyEvent),document.removeEventListener("keyup",this._handleKeyEvent)},Ze.prototype._addMediaListener=function(t,e){this._listeners.push({type:t,callback:e}),this._mediaElement.addEventListener(t,e)},Ze.prototype.init=function(t){var e,i=this;return i._eventEmitter=t,i._listeners=[],i._duration=i.getDuration(),i._addMediaListener("timeupdate",(function(){i._eventEmitter.emit("player.timeupdate",i.getCurrentTime())})),i._addMediaListener("playing",(function(){i._eventEmitter.emit("player.playing",i.getCurrentTime())})),i._addMediaListener("pause",(function(){i._eventEmitter.emit("player.pause",i.getCurrentTime())})),i._addMediaListener("ended",(function(){i._eventEmitter.emit("player.ended")})),i._addMediaListener("seeked",(function(){i._eventEmitter.emit("player.seeked",i.getCurrentTime())})),i._addMediaListener("canplay",(function(){i._eventEmitter.emit("player.canplay")})),i._addMediaListener("error",(function(t){i._eventEmitter.emit("player.error",t.target.error)})),i._interval=null,(e=i._mediaElement).src||e.querySelector("source")?i._mediaElement.error&&i._mediaElement.error.code===MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED?Promise.reject(i._mediaElement.error):new Promise((function(t,e){function n(r){i._mediaElement.removeEventListener("loadedmetadata",n),i._mediaElement.removeEventListener("error",n),"loadedmetadata"===r.type?t():e(r.target.error)}i._mediaElement.readyState===HTMLMediaElement.HAVE_NOTHING?(i._mediaElement.addEventListener("loadedmetadata",n),i._mediaElement.addEventListener("error",n),i._mediaElement.load()):t()})):Promise.resolve()},Ze.prototype.destroy=function(){for(var t=0;t=this._segment.endTime){if(!this._loop)return this.pause(),this._peaks.emit("player.ended"),void(this._playingSegment=!1);this.seek(this._segment.startTime)}window.requestAnimationFrame(this._playSegmentTimerCallback)}else this._playingSegment=!1},je.prototype._setSource=function(t){return this._adapter.setSource(t)};var qe={};Object.defineProperty(qe,"__esModule",{value:!0});var Je=qe.Line=void 0,Qe=D,$e=M,ti=A;function ei(t,e,i,n,r,a,o){var s=Math.sqrt(Math.pow(i-t,2)+Math.pow(n-e,2)),h=Math.sqrt(Math.pow(r-i,2)+Math.pow(a-n,2)),l=o*s/(s+h),u=o*h/(s+h);return[i-l*(r-t),n-l*(a-e),i+u*(r-t),n+u*(a-e)]}function ii(t,e){var i,n,r=t.length,a=[];for(i=2;i4){for(i=(e=this.getTensionPoints()).length,n=s?0:4,s||t.quadraticCurveTo(e[0],e[1],e[2],e[3]);n1&&(_+=o)}}}},{key:"_hitFunc",value:function(t){var e=this.getWidth(),i=this.getHeight();t.beginPath(),t.rect(0,0,e,i),t.closePath(),t.fillStrokeShape(this)}},{key:"setText",value:function(t){var e=pi.Util._isString(t)?t:null==t?"":t+"";return this._setAttr("text",e),this}},{key:"getWidth",value:function(){return this.attrs.width===bi||void 0===this.attrs.width?this.getTextWidth()+2*this.padding():this.attrs.width}},{key:"getHeight",value:function(){return this.attrs.height===bi||void 0===this.attrs.height?this.fontSize()*this.textArr.length*this.lineHeight()+2*this.padding():this.attrs.height}},{key:"getTextWidth",value:function(){return this.textWidth}},{key:"getTextHeight",value:function(){return pi.Util.warn("text.getTextHeight() method is deprecated. Use text.height() - for full height and text.fontSize() - for one line height."),this.textHeight}},{key:"measureSize",value:function(t){var e,i=Ii(),n=this.fontSize();return i.save(),i.font=this._getContextFont(),e=i.measureText(t),i.restore(),{width:e.width,height:n}}},{key:"_getContextFont",value:function(){return this.fontStyle()+xi+this.fontVariant()+xi+(this.fontSize()+"px ")+this.fontFamily().split(",").map((function(t){var e=(t=t.trim()).indexOf(" ")>=0,i=t.indexOf('"')>=0||t.indexOf("'")>=0;return e&&!i&&(t='"'.concat(t,'"')),t})).join(", ")}},{key:"_addTextLine",value:function(t){this.align()===wi&&(t=t.trim());var e=this._getTextWidth(t);return this.textArr.push({text:t,width:e,lastInParagraph:!1})}},{key:"_getTextWidth",value:function(t){var e=this.letterSpacing(),i=t.length;return Ii().measureText(t).width+(i?e*(i-1):0)}},{key:"_setTextData",value:function(){var t=this.text().split("\n"),e=+this.fontSize(),i=0,n=this.lineHeight()*e,r=this.attrs.width,a=this.attrs.height,o=r!==bi&&void 0!==r,s=a!==bi&&void 0!==a,h=this.padding(),l=r-2*h,u=a-2*h,d=0,c=this.wrap(),p="char"!==c&&c!==Ti,g=this.ellipsis();this.textArr=[],Ii().font=this._getContextFont();for(var f=g?this._getTextWidth("…"):0,_=0,m=t.length;_l)for(;v.length>0;){for(var b=0,w=v.length,k="",S=0;b>>1,x=v.slice(0,C+1),T=this._getTextWidth(x)+f;T<=l?(b=C+1,k=x,S=T):w=C}if(!k)break;if(p){var A,P=v[k.length];(A=(P===xi||"-"===P)&&S<=l?k.length:Math.max(k.lastIndexOf(xi),k.lastIndexOf("-"))+1)>0&&(b=A,k=k.slice(0,b),S=this._getTextWidth(k))}if(k=k.trimRight(),this._addTextLine(k),i=Math.max(i,S),d+=n,this._shouldHandleEllipsis(d)){this._tryToAddEllipsisToLastLine();break}if((v=(v=v.slice(b)).trimLeft()).length>0&&(y=this._getTextWidth(v))<=l){this._addTextLine(v),d+=n,i=Math.max(i,y);break}}else this._addTextLine(v),d+=n,i=Math.max(i,y),this._shouldHandleEllipsis(d)&&_u)break}this.textHeight=e,this.textWidth=i}},{key:"_shouldHandleEllipsis",value:function(t){var e=+this.fontSize(),i=this.lineHeight()*e,n=this.attrs.height,r=n!==bi&&void 0!==n,a=n-2*this.padding();return!(this.wrap()!==Ti)||r&&t+i>a}},{key:"_tryToAddEllipsisToLastLine",value:function(){var t=this.attrs.width,e=t!==bi&&void 0!==t,i=t-2*this.padding(),n=this.ellipsis(),r=this.textArr[this.textArr.length-1];if(r&&n){if(e)this._getTextWidth(r.text+"…")=5,this._useAnimation)this._player.isPlaying()&&!this._playheadLineAnimation&&this._start();else if(this._playheadLineAnimation){var e=this._player.getCurrentTime();this.stop(e)}},Vi.prototype.fitToView=function(){var t=this._view.getHeight();this._playheadLine.points([.5,0,.5,t]),this._playheadText&&this._playheadText.y(12)},Vi.prototype._createPlayhead=function(){this._playheadLine=new Je({stroke:this._playheadColor,strokeWidth:this._playheadWidth}),this._playheadGroup=new he.Group({x:0,y:0}),this._playheadGroup.add(this._playheadLine),this._playheadLayer.add(this._playheadGroup)},Vi.prototype._createPlayheadText=function(){var t=this,e=t._player.getCurrentTime(),i=t._view.formatTime(e);t._playheadText=new ci({x:0,y:0,padding:t._playheadPadding,text:i,fontSize:t._playheadFontSize,fontFamily:t._playheadFontFamily,fontStyle:t._playheadFontStyle,fill:t._playheadTextColor,align:"right",sceneFunc:function(e,i){var n=i.width(),r=i.height()+2*t._playheadPadding;e.fillStyle=t._playheadBackgroundColor,e.fillRect(0,-t._playheadPadding,n,r),i._sceneFunc(e)}}),t._playheadGroup.add(t._playheadText)},Vi.prototype.updatePlayheadTime=function(t){this._syncPlayhead(t),this._player.isPlaying()&&this._start()},Vi.prototype._syncPlayhead=function(t){var e=this._view.timeToPixels(t),i=this._view.getFrameOffset(),n=this._view.getWidth(),r=e>=i&&e<=i+n;if(this._playheadPixel=e,r){var a=this._playheadPixel-i;if(this._playheadVisible||(this._playheadVisible=!0,this._playheadGroup.show()),this._playheadGroup.setX(a),this._playheadText){var o=this._view.formatTime(t),s=this._playheadText.width();this._playheadText.setText(o),s+a>n-2?this._playheadText.setX(-s):s+as&&(r=s),r>e.length-1&&(r=e.length-1);for(var h=e.channels,l=0,u=Math.floor(o/h),d=0;d=n;s--)h=e.max_sample(s),l=s-i+.5,u=a+Xi.scaleY(h,o,d)+1,t.lineTo(l,u);t.closePath(),t.fillShape(this._shape)},Xi.prototype.addToLayer=function(t){t.add(this._shape)},Xi.prototype.destroy=function(){this._shape.destroy(),this._shape=null},Xi.prototype.on=function(t,e){this._shape.on(t,e)},Xi.prototype.off=function(t,e){this._shape.off(t,e)},Xi.scaleY=function(t,e,i){var n=-(e-1)*(t*i+128)/255+(e-1);return de(Math.floor(n),0,e-1)};var zi="sans-serif",Ni="normal";function Zi(t,e,i,n){this._segment=t,this._peaks=e,this._layer=i,this._view=n,this._label=null,this._startMarker=null,this._endMarker=null,this._color=t.color,this._borderColor=t.borderColor,this._draggable=this._segment.editable&&this._view.isSegmentDraggingEnabled(),this._dragging=!1;var r=n.getViewOptions().segmentOptions;this._overlayOffset=r.overlayOffset,r.overlay||(this._waveformShape=new Xi({color:t.color,view:n,segment:t})),this._onMouseEnter=this._onMouseEnter.bind(this),this._onMouseLeave=this._onMouseLeave.bind(this),this._onMouseDown=this._onMouseDown.bind(this),this._onMouseUp=this._onMouseUp.bind(this),this._dragBoundFunc=this._dragBoundFunc.bind(this),this._onSegmentDragStart=this._onSegmentDragStart.bind(this),this._onSegmentDragMove=this._onSegmentDragMove.bind(this),this._onSegmentDragEnd=this._onSegmentDragEnd.bind(this),this._onSegmentMarkerDragStart=this._onSegmentMarkerDragStart.bind(this),this._onSegmentMarkerDragMove=this._onSegmentMarkerDragMove.bind(this),this._onSegmentMarkerDragEnd=this._onSegmentMarkerDragEnd.bind(this),this._segmentMarkerDragBoundFunc=this._segmentMarkerDragBoundFunc.bind(this),this._label=this._peaks.options.createSegmentLabel({segment:t,view:this._view.getName(),layer:this._layer,fontFamily:this._peaks.options.fontFamily,fontSize:this._peaks.options.fontSize,fontStyle:this._peaks.options.fontStyle}),this._label&&this._label.hide();var a,o,s,h,l,u=this._view.timeToPixelOffset(this._segment.startTime),d=this._view.timeToPixelOffset(this._segment.endTime),c=de(0,this._view.getHeight()-2*this._overlayOffset);this._overlay=new he.Group({name:"segment-overlay",segment:this._segment,x:u,y:0,width:d-u,height:this._view.getHeight(),clipX:0,clipY:this._overlayOffset,clipWidth:d-u,clipHeight:c,draggable:this._draggable,dragBoundFunc:this._dragBoundFunc}),r.overlay&&(a=this._borderColor||r.overlayBorderColor,o=r.overlayBorderWidth,s=this._color||r.overlayColor,h=r.overlayOpacity,l=r.overlayCornerRadius),this._overlayRect=new he.Rect({x:0,y:this._overlayOffset,width:d-u,stroke:a,strokeWidth:o,height:c,fill:s,opacity:h,cornerRadius:l}),this._overlay.add(this._overlayRect),r.overlay&&(this._overlayText=new he.Text({x:0,y:this._overlayOffset,text:this._segment.labelText,fontFamily:r.overlayFontFamily,fontSize:r.overlayFontSize,fontStyle:r.overlayFontStyle,fill:r.overlayLabelColor,listening:!1,align:r.overlayLabelAlign,width:d-u,verticalAlign:r.overlayLabelVerticalAlign,height:c,padding:r.overlayLabelPadding}),this._overlay.add(this._overlayText)),this._overlay.on("mouseenter",this._onMouseEnter),this._overlay.on("mouseleave",this._onMouseLeave),this._overlay.on("mousedown",this._onMouseDown),this._overlay.on("mouseup",this._onMouseUp),this._draggable&&(this._overlay.on("dragstart",this._onSegmentDragStart),this._overlay.on("dragmove",this._onSegmentDragMove),this._overlay.on("dragend",this._onSegmentDragEnd)),this._createMarkers()}function Yi(t){return new Hi(t)}function Ki(t){return t.endTime-t.startTime}function ji(t,e,i){this._peaks=t,this._view=e,this._allowEditing=i,this._segmentShapes={},this._layer=new he.Layer,this._onSegmentsUpdate=this._onSegmentsUpdate.bind(this),this._onSegmentsAdd=this._onSegmentsAdd.bind(this),this._onSegmentsRemove=this._onSegmentsRemove.bind(this),this._onSegmentsRemoveAll=this._onSegmentsRemoveAll.bind(this),this._onSegmentsDragged=this._onSegmentsDragged.bind(this),this._peaks.on("segments.update",this._onSegmentsUpdate),this._peaks.on("segments.add",this._onSegmentsAdd),this._peaks.on("segments.remove",this._onSegmentsRemove),this._peaks.on("segments.remove_all",this._onSegmentsRemoveAll),this._peaks.on("segments.dragged",this._onSegmentsDragged)}function qi(t,e){var i=this;i._axisGridlineColor=e.axisGridlineColor,i._axisLabelColor=e.axisLabelColor,i._showAxisLabels=e.showAxisLabels,i._axisTopMarkerHeight=e.axisTopMarkerHeight,i._axisBottomMarkerHeight=e.axisBottomMarkerHeight,e.formatAxisTime?i._formatAxisTime=e.formatAxisTime:i._formatAxisTime=function(t){return ue(t,0)},i._axisLabelFont=qi._buildFontString(e.fontFamily,e.fontSize,e.fontStyle),i._axisShape=new he.Shape({sceneFunc:function(e){i._drawAxis(e,t)}})}function Ji(t,e,i,n){var r=this;r._container=e,r._peaks=i,r._options=i.options,r._viewOptions=n,r._originalWaveformData=t,r._data=t,r._frameOffset=0,r._width=e.clientWidth,r._height=e.clientHeight,r._amplitudeScale=1,r._waveformColor=r._viewOptions.waveformColor,r._playedWaveformColor=r._viewOptions.playedWaveformColor,r._timeLabelPrecision=r._viewOptions.timeLabelPrecision,r._viewOptions.formatPlayheadTime?r._formatPlayheadTime=r._viewOptions.formatPlayheadTime:r._formatPlayheadTime=function(t){return ue(t,r._timeLabelPrecision)},r._enableSeek=!0,r.initWaveform(),he.showWarnings=!1,r._stage=new he.Stage({container:e,width:r._width,height:r._height}),r._createWaveform(),r._viewOptions.enableSegments&&(r._segmentsLayer=new ji(i,r,r._viewOptions.enableEditing),r._segmentsLayer.addToStage(r._stage)),r._viewOptions.enablePoints&&(r._pointsLayer=new Bi(i,r,r._viewOptions.enableEditing),r._pointsLayer.addToStage(r._stage)),r.initHighlightLayer(),r._createAxisLabels(),r._playheadLayer=new Vi(r._peaks.player,r,r._viewOptions),r._playheadLayer.addToStage(r._stage),r._onClick=r._onClick.bind(r),r._onDblClick=r._onDblClick.bind(r),r._onContextMenu=r._onContextMenu.bind(r),r._stage.on("click",r._onClick),r._stage.on("dblclick",r._onDblClick),r._stage.on("contextmenu",r._onContextMenu)}function Qi(t,e){this._stage=t,this._handlers=e,this._dragging=!1,this._mouseDown=this._mouseDown.bind(this),this._mouseUp=this._mouseUp.bind(this),this._mouseMove=this._mouseMove.bind(this),this._stage.on("mousedown",this._mouseDown),this._stage.on("touchstart",this._mouseDown),this._lastMouseClientX=null}function $i(t,e){this._peaks=t,this._view=e,this._onMouseDown=this._onMouseDown.bind(this),this._onMouseMove=this._onMouseMove.bind(this),this._mouseDragHandler=new Qi(e._stage,{onMouseDown:this._onMouseDown,onMouseMove:this._onMouseMove})}function tn(t,e,i){var n=this;Ji.call(n,t,e,i,i.options.overview),n._onTimeUpdate=n._onTimeUpdate.bind(n),n._onPlaying=n._onPlaying.bind(n),n._onPause=n._onPause.bind(n),n._onZoomviewDisplaying=n._onZoomviewDisplaying.bind(n),i.on("player.timeupdate",n._onTimeUpdate),i.on("player.playing",n._onPlaying),i.on("player.pause",n._onPause),i.on("zoomview.displaying",n._onZoomviewDisplaying);var r=n._peaks.player.getCurrentTime();n._playheadLayer.updatePlayheadTime(r),n._mouseDragHandler=new $i(i,n)}function en(t,e){this._peaks=t,this._view=e,this._onMouseDown=this._onMouseDown.bind(this),this._onMouseMove=this._onMouseMove.bind(this),this._onMouseUp=this._onMouseUp.bind(this),this._mouseDragHandler=new Qi(e._stage,{onMouseDown:this._onMouseDown,onMouseMove:this._onMouseMove,onMouseUp:this._onMouseUp})}function nn(t,e){this._peaks=t,this._view=e,this._onMouseDown=this._onMouseDown.bind(this),this._onMouseMove=this._onMouseMove.bind(this),this._onMouseUp=this._onMouseUp.bind(this),this._mouseDragHandler=new Qi(e._stage,{onMouseDown:this._onMouseDown,onMouseMove:this._onMouseMove,onMouseUp:this._onMouseUp})}function rn(t,e,i){var n=this;Ji.call(n,t,e,i,i.options.zoomview),n._onTimeUpdate=n._onTimeUpdate.bind(n),n._onPlaying=n._onPlaying.bind(n),n._onPause=n._onPause.bind(n),n._onKeyboardLeft=n._onKeyboardLeft.bind(n),n._onKeyboardRight=n._onKeyboardRight.bind(n),n._onKeyboardShiftLeft=n._onKeyboardShiftLeft.bind(n),n._onKeyboardShiftRight=n._onKeyboardShiftRight.bind(n),n._peaks.on("player.timeupdate",n._onTimeUpdate),n._peaks.on("player.playing",n._onPlaying),n._peaks.on("player.pause",n._onPause),n._peaks.on("keyboard.left",n._onKeyboardLeft),n._peaks.on("keyboard.right",n._onKeyboardRight),n._peaks.on("keyboard.shift_left",n._onKeyboardShiftLeft),n._peaks.on("keyboard.shift_right",n._onKeyboardShiftRight),n._autoScroll=n._viewOptions.autoScroll,n._autoScrollOffset=n._viewOptions.autoScrollOffset,n._enableSegmentDragging=!1,n._segmentDragMode="overlap",n._minSegmentDragWidth=0,n._insertSegmentShape=null,n._playheadClickTolerance=n._viewOptions.playheadClickTolerance,n._zoomLevelAuto=!1,n._zoomLevelSeconds=null;var r=n._peaks.player.getCurrentTime();n._syncPlayhead(r),n._mouseDragHandler=new nn(i,n),n._onWheel=n._onWheel.bind(n),n._onWheelCaptureVerticalScroll=n._onWheelCaptureVerticalScroll.bind(n),n.setWheelMode(n._viewOptions.wheelMode),n._peaks.emit("zoomview.displaying",0,n.getEndTime())}function an(t,e,i){this._waveformData=t,this._container=e,this._peaks=i,this._options=i.options.scrollbar,this._zoomview=i.views.getView("zoomview"),this._dragBoundFunc=this._dragBoundFunc.bind(this),this._onScrollboxDragStart=this._onScrollboxDragStart.bind(this),this._onScrollboxDragMove=this._onScrollboxDragMove.bind(this),this._onScrollboxDragEnd=this._onScrollboxDragEnd.bind(this),this._onZoomviewDisplaying=this._onZoomviewDisplaying.bind(this),this._onScrollbarClick=this._onScrollbarClick.bind(this),i.on("zoomview.displaying",this._onZoomviewDisplaying),this._width=e.clientWidth,this._height=e.clientHeight,this._stage=new he.Stage({container:e,width:this._width,height:this._height}),this._layer=new he.Layer,this._stage.on("click",this._onScrollbarClick),this._stage.add(this._layer),this._color=this._options.color,this._scrollboxX=0,this._minScrollboxWidth=this._options.minWidth,this._offsetY=0,this._scrollbox=new he.Group({draggable:!0,dragBoundFunc:this._dragBoundFunc}),this._scrollboxRect=new ai({x:this._scrollboxX,y:this._offsetY,width:0,height:this._height,fill:this._color}),this._scrollbox.add(this._scrollboxRect),this._setScrollboxWidth(),this._scrollbox.on("dragstart",this._onScrollboxDragStart),this._scrollbox.on("dragmove",this._onScrollboxDragMove),this._scrollbox.on("dragend",this._onScrollboxDragEnd),this._layer.add(this._scrollbox),this._layer.draw()}function on(t){this._peaks=t,this._overview=null,this._zoomview=null,this._scrollbar=null}function sn(t,e){this._peaks=t,this._zoomLevels=e,this._zoomLevelIndex=0}function hn(t,e){this._waveformData=t,this._channelIndex=e}Zi.prototype._createMarkers=function(){var t=this._layer.isEditingEnabled()&&this._segment.editable,e=this._view.getViewOptions().segmentOptions,i=e.markers?this._peaks.options.createSegmentMarker:Yi,n=i({segment:this._segment,editable:t,startMarker:!0,color:e.startMarkerColor,fontFamily:this._peaks.options.fontFamily||zi,fontSize:this._peaks.options.fontSize||10,fontStyle:this._peaks.options.fontStyle||Ni,layer:this._layer,view:this._view.getName(),segmentOptions:this._view.getViewOptions().segmentOptions});n&&(this._startMarker=new Ui({segment:this._segment,segmentShape:this,editable:t,startMarker:!0,marker:n,onDragStart:this._onSegmentMarkerDragStart,onDragMove:this._onSegmentMarkerDragMove,onDragEnd:this._onSegmentMarkerDragEnd,dragBoundFunc:this._segmentMarkerDragBoundFunc}));var r=i({segment:this._segment,editable:t,startMarker:!1,color:e.endMarkerColor,fontFamily:this._peaks.options.fontFamily||zi,fontSize:this._peaks.options.fontSize||10,fontStyle:this._peaks.options.fontStyle||Ni,layer:this._layer,view:this._view.getName(),segmentOptions:this._view.getViewOptions().segmentOptions});r&&(this._endMarker=new Ui({segment:this._segment,segmentShape:this,editable:t,startMarker:!1,marker:r,onDragStart:this._onSegmentMarkerDragStart,onDragMove:this._onSegmentMarkerDragMove,onDragEnd:this._onSegmentMarkerDragEnd,dragBoundFunc:this._segmentMarkerDragBoundFunc}))},Zi.prototype._dragBoundFunc=function(t){return{x:t.x,y:0}},Zi.prototype.update=function(t){var e,i=this._view.timeToPixelOffset(this._segment.startTime),n=this._view.timeToPixelOffset(this._segment.endTime),r=n-i;(e=this.getStartMarker())&&(e.setX(i-e.getWidth()),t&&e.update(t)),(e=this.getEndMarker())&&(e.setX(n),t&&e.update(t)),this._color=this._segment.color,this._borderColor=this._segment.bordercolor,this._overlayText&&this._overlayText.text(this._segment.labelText),this._view.getViewOptions().segmentOptions.overlay?(this._color&&this._overlayRect.fill(this._color),this._borderColor&&this._overlayRect.stroke(this._borderColor)):this._waveformShape.setWaveformColor(this._segment.color),this._dragging||this._overlay&&(this._overlay.setAttrs({x:i,width:r,clipWidth:r<1?1:r}),this._overlayRect.setAttrs({x:0,width:r}),this._overlayText&&this._overlayText.setAttrs({width:r}))},Zi.prototype.getSegment=function(){return this._segment},Zi.prototype.getStartMarker=function(){return this._startMarker},Zi.prototype.getEndMarker=function(){return this._endMarker},Zi.prototype.addToLayer=function(t){this._waveformShape&&this._waveformShape.addToLayer(t),this._label&&t.add(this._label),this._overlay&&t.add(this._overlay),this._startMarker&&this._startMarker.addToLayer(t),this._endMarker&&this._endMarker.addToLayer(t)},Zi.prototype.isDragging=function(){return this._dragging},Zi.prototype._onMouseEnter=function(t){this._label&&(this._label.moveToTop(),this._label.show()),this._peaks.emit("segments.mouseenter",{segment:this._segment,evt:t.evt})},Zi.prototype._onMouseLeave=function(t){this._label&&this._label.hide(),this._peaks.emit("segments.mouseleave",{segment:this._segment,evt:t.evt})},Zi.prototype._onMouseDown=function(t){this._peaks.emit("segments.mousedown",{segment:this._segment,evt:t.evt})},Zi.prototype._onMouseUp=function(t){this._peaks.emit("segments.mouseup",{segment:this._segment,evt:t.evt})},Zi.prototype.segmentClicked=function(t,e){this._moveToTop(),this._peaks.emit("segments."+t,e)},Zi.prototype._moveToTop=function(){this._overlay.moveToTop(),this._layer.moveSegmentMarkersToTop()},Zi.prototype.enableSegmentDragging=function(t){this._segment.editable&&(!this._draggable&&t?(this._overlay.on("dragstart",this._onSegmentDragStart),this._overlay.on("dragmove",this._onSegmentDragMove),this._overlay.on("dragend",this._onSegmentDragEnd)):this._draggable&&!t&&(this._overlay.off("dragstart",this._onSegmentDragStart),this._overlay.off("dragmove",this._onSegmentDragMove),this._overlay.off("dragend",this._onSegmentDragEnd)),this._overlay.draggable(t),this._draggable=t)},Zi.prototype._setPreviousAndNextSegments=function(){"overlap"!==this._view.getSegmentDragMode()?(this._nextSegment=this._peaks.segments.findNextSegment(this._segment),this._previousSegment=this._peaks.segments.findPreviousSegment(this._segment)):(this._nextSegment=null,this._previousSegment=null)},Zi.prototype._onSegmentDragStart=function(t){this._setPreviousAndNextSegments(),this._dragging=!0,this._dragStartX=this._overlay.getX(),this._dragStartTime=this._segment.startTime,this._dragEndTime=this._segment.endTime,this._peaks.emit("segments.dragstart",{segment:this._segment,marker:!1,startMarker:!1,evt:t.evt})},Zi.prototype._onSegmentDragMove=function(t){var e,i=this._overlay.getX()-this._dragStartX,n=this._view.pixelsToTime(i),r=this._dragStartTime+n,a=this._dragEndTime+n,o=this._segment.endTime-this._segment.startTime,s=this._view.getMinSegmentDragWidth(),h=this._view.pixelsToTime(s),l=!1,u=!1;if(r<0&&(r=0,a=o,this._overlay.setX(this._view.timeToPixelOffset(r))),this._previousSegment){var d=this._view.timeToPixelOffset(this._previousSegment.endTime);if(rthis._nextSegment.startTime)if("no-overlap"===(e=this._view.getSegmentDragMode())||"compress"===e&&!this._nextSegment.editable)r=(a=this._nextSegment.startTime)-o,this._overlay.setX(g-this._overlay.getWidth());else if("compress"===e){var f=a,_=this._nextSegment.endTime-h;f>_&&(f=_,g=this._view.timeToPixelOffset(f),this._overlay.setX(g-this._overlay.getWidth()),r=(a=f)-o),this._nextSegment.update({startTime:f}),u=!0}}this._segment._setStartTime(r),this._segment._setEndTime(a),this._peaks.emit("segments.dragged",{segment:this._segment,marker:!1,startMarker:!1,evt:t.evt}),l?this._peaks.emit("segments.dragged",{segment:this._previousSegment,marker:!1,startMarker:!1,evt:t.evt}):u&&this._peaks.emit("segments.dragged",{segment:this._nextSegment,marker:!1,startMarker:!1,evt:t.evt})},Zi.prototype._onSegmentDragEnd=function(t){this._dragging=!1,this._peaks.emit("segments.dragend",{segment:this._segment,marker:!1,startMarker:!1,evt:t.evt})},Zi.prototype.moveMarkersToTop=function(){this._startMarker&&this._startMarker.moveToTop(),this._endMarker&&this._endMarker.moveToTop()},Zi.prototype.startDrag=function(){this._endMarker&&this._endMarker.startDrag()},Zi.prototype.stopDrag=function(){this._endMarker&&this._endMarker.stopDrag()},Zi.prototype._onSegmentMarkerDragStart=function(t,e){this._setPreviousAndNextSegments(),this._moveToTop(),this._startMarkerX=this._startMarker.getX(),this._endMarkerX=this._endMarker.getX(),this._peaks.emit("segments.dragstart",{segment:this._segment,marker:!0,startMarker:t.isStartMarker(),evt:e.evt})},Zi.prototype._onSegmentMarkerDragMove=function(t,e){t.isStartMarker()?(this._segmentStartMarkerDragMove(t,e),t.update({startTime:this._segment.startTime})):(this._segmentEndMarkerDragMove(t,e),t.update({endTime:this._segment.endTime}))},Zi.prototype._segmentStartMarkerDragMove=function(t,e){var i=this._view.getWidth(),n=this._startMarker.getX(),r=this._endMarker.getX(),a=this._view.pixelsToTime(50),o=this._view.getMinSegmentDragWidth(),s=this._endMarker.getX()-o;s>i&&(s=i);var h,l=!1,u=!1;if(this._previousSegment&&(l=(h=this._view.timeToPixelOffset(this._previousSegment.endTime))>=0),n>s)t.setX(s),this._overlay.clipWidth(s-r),0===o&&s0?this._segment._setEndTime(this._segment.startTime):this._segment._setEndTime(this._view.pixelOffsetToTime(s));else if(this._nextSegment&&l){var d=this._view.getSegmentDragMode(),c="no-overlap"===d||"compress"===d&&!this._nextSegment.editable,p="compress"===d&&this._nextSegment.editable;if(r>=h){if(c)t.setX(h),this._overlay.clipWidth(h-n),this._segment._setEndTime(this._nextSegment.startTime);else if(p){var g=Ki(this._nextSegment);gf&&(r=f),t.setX(r),this._overlay.clipWidth(r-n),this._segment._setEndTime(this._view.pixelOffsetToTime(r)),this._nextSegment.update({startTime:this._view.pixelOffsetToTime(r)}),u=!0}}else r>i&&(r=i),t.setX(r),this._overlay.clipWidth(r-n),this._segment._setEndTime(this._view.pixelOffsetToTime(r))}else r>i&&(r=i),t.setX(r),this._overlay.clipWidth(r-n),this._segment._setEndTime(this._view.pixelOffsetToTime(r));this._peaks.emit("segments.dragged",{segment:this._segment,marker:!0,startMarker:!1,evt:e.evt}),u&&this._peaks.emit("segments.dragged",{segment:this._nextSegment,marker:!0,startMarker:!0,evt:e.evt})},Zi.prototype._onSegmentMarkerDragEnd=function(t,e){this._nextSegment=null,this._previousSegment=null;var i=t.isStartMarker();this._peaks.emit("segments.dragend",{segment:this._segment,marker:!0,startMarker:i,evt:e.evt})},Zi.prototype._segmentMarkerDragBoundFunc=function(t,e){return{x:e.x,y:t.getAbsolutePosition().y}},Zi.prototype.fitToView=function(){if(this._startMarker&&this._startMarker.fitToView(),this._endMarker&&this._endMarker.fitToView(),this._overlay){var t=this._view.getHeight(),e=de(0,t-2*this._overlayOffset);this._overlay.setAttrs({y:0,height:t,clipY:this._overlayOffset,clipHeight:e}),this._overlayRect.setAttrs({y:this._overlayOffset,height:e}),this._overlayText&&this._overlayText.setAttrs({y:this._overlayOffset,height:e})}},Zi.prototype.destroy=function(){this._waveformShape&&this._waveformShape.destroy(),this._label&&this._label.destroy(),this._startMarker&&this._startMarker.destroy(),this._endMarker&&this._endMarker.destroy(),this._overlay&&this._overlay.destroy()},ji.prototype.addToStage=function(t){t.add(this._layer)},ji.prototype.enableEditing=function(t){this._allowEditing=t},ji.prototype.isEditingEnabled=function(){return this._allowEditing},ji.prototype.enableSegmentDragging=function(t){for(var e in this._segmentShapes)ce(this._segmentShapes,e)&&this._segmentShapes[e].enableSegmentDragging(t)},ji.prototype.getSegmentShape=function(t){return this._segmentShapes[t.pid]},ji.prototype.formatTime=function(t){return this._view.formatTime(t)},ji.prototype._onSegmentsUpdate=function(t,e){var i=this._view.getStartTime(),n=this._view.getEndTime(),r=this.getSegmentShape(t),a=t.isVisible(i,n);r&&!a?r.isDragging()||this._removeSegment(t):!r&&a?r=this._updateSegment(t):r&&a&&r.update(e)},ji.prototype._onSegmentsAdd=function(t){var e=this,i=e._view.getStartTime(),n=e._view.getEndTime();t.segments.forEach((function(t){t.isVisible(i,n)&&e._addSegmentShape(t).update()})),this.moveSegmentMarkersToTop()},ji.prototype._onSegmentsRemove=function(t){var e=this;t.segments.forEach((function(t){e._removeSegment(t)}))},ji.prototype._onSegmentsRemoveAll=function(){this._layer.removeChildren(),this._segmentShapes={}},ji.prototype._onSegmentsDragged=function(t){this._updateSegment(t.segment)},ji.prototype._createSegmentShape=function(t){return new Zi(t,this._peaks,this,this._view)},ji.prototype._addSegmentShape=function(t){var e=this._createSegmentShape(t);return e.addToLayer(this._layer),this._segmentShapes[t.pid]=e,e},ji.prototype.updateSegments=function(t,e){this._peaks.segments.find(t,e).forEach(this._updateSegment.bind(this)),this._removeInvisibleSegments(t,e)},ji.prototype._updateSegment=function(t){var e=this.getSegmentShape(t);e||(e=this._addSegmentShape(t)),e.update()},ji.prototype._removeInvisibleSegments=function(t,e){for(var i in this._segmentShapes)if(ce(this._segmentShapes,i)){var n=this._segmentShapes[i].getSegment();n.isVisible(t,e)||this._removeSegment(n)}},ji.prototype._removeSegment=function(t){var e=this._segmentShapes[t.pid];e&&(e.destroy(),delete this._segmentShapes[t.pid])},ji.prototype.moveSegmentMarkersToTop=function(){for(var t in this._segmentShapes)ce(this._segmentShapes,t)&&this._segmentShapes[t].moveMarkersToTop()},ji.prototype.setVisible=function(t){this._layer.setVisible(t)},ji.prototype.segmentClicked=function(t,e){var i=this._segmentShapes[e.segment.pid];i&&i.segmentClicked(t,e)},ji.prototype.destroy=function(){this._peaks.off("segments.update",this._onSegmentsUpdate),this._peaks.off("segments.add",this._onSegmentsAdd),this._peaks.off("segments.remove",this._onSegmentsRemove),this._peaks.off("segments.remove_all",this._onSegmentsRemoveAll),this._peaks.off("segments.dragged",this._onSegmentsDragged)},ji.prototype.fitToView=function(){for(var t in this._segmentShapes){if(ce(this._segmentShapes,t))this._segmentShapes[t].fitToView()}},ji.prototype.draw=function(){this._layer.draw()},ji.prototype.getHeight=function(){return this._layer.getHeight()},qi._buildFontString=function(t,e,i){return e||(e=11),t||(t="sans-serif"),i||(i="normal"),i+" "+e+"px "+t},qi.prototype.addToLayer=function(t){t.add(this._axisShape)},qi.prototype.showAxisLabels=function(t,e){this._showAxisLabels=t,e&&(ce(e,"topMarkerHeight")&&(this._axisTopMarkerHeight=e.topMarkerHeight),ce(e,"bottomMarkerHeight")&&(this._axisBottomMarkerHeight=e.bottomMarkerHeight))},qi.prototype._getAxisLabelScale=function(t){for(var e,i=1,n=[1,2,5,10,20,30],r=0;;){if(e=i*n[r],!(t.timeToPixels(e)<60))break;++r===n.length&&(i*=60,r=0)}return e},qi.prototype._drawAxis=function(t,e){var i=e.getStartTime(),n=this._getAxisLabelScale(e),r=function(t,e){if(0===e)return 0;var i=1;return t<0&&(i=-1,t=-t),i*((Math.ceil(t)+e-1)/e|0)*e}(i,n),a=r-i,o=e.timeToPixels(a);t.setAttr("strokeStyle",this._axisGridlineColor),t.setAttr("lineWidth",1),t.setAttr("font",this._axisLabelFont),t.setAttr("fillStyle",this._axisLabelColor),t.setAttr("textAlign","left"),t.setAttr("textBaseline","bottom");for(var s=e.getWidth(),h=e.getHeight(),l=r;;){var u=o+e.timeToPixels(l-r);if(u>=s)break;if(this._axisTopMarkerHeight>0&&(t.beginPath(),t.moveTo(u+.5,0),t.lineTo(u+.5,0+this._axisTopMarkerHeight),t.stroke()),this._axisBottomMarkerHeight&&(t.beginPath(),t.moveTo(u+.5,h),t.lineTo(u+.5,h-this._axisBottomMarkerHeight),t.stroke()),this._showAxisLabels){var d=this._formatAxisTime(l),c=u-t.measureText(d).width/2,p=h-1-this._axisBottomMarkerHeight;c>=0&&t.fillText(d,c,p)}l+=n}},Ji.prototype.getViewOptions=function(){return this._viewOptions},Ji.prototype.getWaveformData=function(){return this._data},Ji.prototype.setWaveformData=function(t){this._data=t},Ji.prototype.timeToPixels=function(t){return Math.floor(t*this._data.sample_rate/this._data.scale)},Ji.prototype.pixelsToTime=function(t){return t*this._data.scale/this._data.sample_rate},Ji.prototype.pixelOffsetToTime=function(t){return(this._frameOffset+t)*this._data.scale/this._data.sample_rate},Ji.prototype.timeToPixelOffset=function(t){return Math.floor(t*this._data.sample_rate/this._data.scale)-this._frameOffset},Ji.prototype.getFrameOffset=function(){return this._frameOffset},Ji.prototype.getWidth=function(){return this._width},Ji.prototype.getHeight=function(){return this._height},Ji.prototype.getStartTime=function(){return this.pixelOffsetToTime(0)},Ji.prototype.getEndTime=function(){return this.pixelOffsetToTime(this._width)},Ji.prototype._getDuration=function(){return this._peaks.player.getDuration()},Ji.prototype._createWaveform=function(){this._waveformLayer=new he.Layer({listening:!1}),this._createWaveformShapes(),this._stage.add(this._waveformLayer)},Ji.prototype._createWaveformShapes=function(){if(this._waveformShape||(this._waveformShape=new Xi({color:this._waveformColor,view:this}),this._waveformShape.addToLayer(this._waveformLayer)),this._playedWaveformColor&&!this._playedWaveformShape){var t=this._peaks.player.getCurrentTime();this._playedSegment={startTime:0,endTime:t},this._unplayedSegment={startTime:t,endTime:this._getDuration()},this._waveformShape.setSegment(this._unplayedSegment),this._playedWaveformShape=new Xi({color:this._playedWaveformColor,view:this,segment:this._playedSegment}),this._playedWaveformShape.addToLayer(this._waveformLayer)}},Ji.prototype.setWaveformColor=function(t){this._waveformColor=t,this._waveformShape.setWaveformColor(t)},Ji.prototype.setPlayedWaveformColor=function(t){this._playedWaveformColor=t,t?(this._playedWaveformShape||this._createWaveformShapes(),this._playedWaveformShape.setWaveformColor(t)):this._playedWaveformShape&&this._destroyPlayedWaveformShape()},Ji.prototype._destroyPlayedWaveformShape=function(){this._waveformShape.setSegment(null),this._playedWaveformShape.destroy(),this._playedWaveformShape=null,this._playedSegment=null,this._unplayedSegment=null},Ji.prototype._createAxisLabels=function(){this._axisLayer=new he.Layer({listening:!1}),this._axis=new qi(this,this._viewOptions),this._axis.addToLayer(this._axisLayer),this._stage.add(this._axisLayer)},Ji.prototype.showAxisLabels=function(t,e){this._axis.showAxisLabels(t,e),this._axisLayer.draw()},Ji.prototype.showPlayheadTime=function(t){this._playheadLayer.showPlayheadTime(t)},Ji.prototype.setTimeLabelPrecision=function(t){this._timeLabelPrecision=t,this._playheadLayer.updatePlayheadText()},Ji.prototype.formatTime=function(t){return this._formatPlayheadTime(t)},Ji.prototype.setAmplitudeScale=function(t){if(!ge(t)||("number"!=typeof(e=t)||e!=e||e===1/0||e===-1/0))throw new Error("view.setAmplitudeScale(): Scale must be a valid number");var e;this._amplitudeScale=t,this.drawWaveformLayer(),this._segmentsLayer&&this._segmentsLayer.draw()},Ji.prototype.getAmplitudeScale=function(){return this._amplitudeScale},Ji.prototype.enableSeek=function(t){this._enableSeek=t},Ji.prototype.isSeekEnabled=function(){return this._enableSeek},Ji.prototype._onClick=function(t){this._clickHandler(t,"click")},Ji.prototype._onDblClick=function(t){this._clickHandler(t,"dblclick")},Ji.prototype._onContextMenu=function(t){this._clickHandler(t,"contextmenu")},Ji.prototype._clickHandler=function(t,e){var i=!0;if(t.target!==this._stage){var n=ke(t.target);if(n)if("point-marker"===n.attrs.name){var r=n.getAttr("point");r&&this._peaks.emit("points."+e,{point:r,evt:t.evt,preventViewEvent:function(){i=!1}})}else if("segment-overlay"===n.attrs.name){var a=n.getAttr("segment");if(a){var o={segment:a,evt:t.evt,preventViewEvent:function(){i=!1}};this._segmentsLayer&&this._segmentsLayer.segmentClicked(e,o)}}}if(i){var s=t.evt.layerX,h=this.pixelOffsetToTime(s),l=this.getName();this._peaks.emit(l+"."+e,{time:h,evt:t.evt})}},Ji.prototype.updatePlayheadTime=function(t){this._playheadLayer.updatePlayheadTime(t)},Ji.prototype.playheadPosChanged=function(t){this._playedWaveformShape&&(this._playedSegment.endTime=t,this._unplayedSegment.startTime=t,this.drawWaveformLayer())},Ji.prototype.drawWaveformLayer=function(){this._waveformLayer.draw()},Ji.prototype.enableMarkerEditing=function(t){this._segmentsLayer&&this._segmentsLayer.enableEditing(t),this._pointsLayer&&this._pointsLayer.enableEditing(t)},Ji.prototype.fitToContainer=function(){if(0!==this._container.clientWidth||0!==this._container.clientHeight){var t=!1;this._container.clientWidth!==this._width&&(this._width=this._container.clientWidth,this._stage.setWidth(this._width),t=this.containerWidthChange()),this._container.clientHeight!==this._height&&(this._height=this._container.clientHeight,this._stage.height(this._height),this._waveformShape.fitToView(),this._playheadLayer.fitToView(),this._segmentsLayer&&this._segmentsLayer.fitToView(),this._pointsLayer&&this._pointsLayer.fitToView(),this.containerHeightChange()),t&&this.updateWaveform(this._frameOffset)}},Ji.prototype.destroy=function(){this._playheadLayer.destroy(),this._segmentsLayer&&this._segmentsLayer.destroy(),this._pointsLayer&&this._pointsLayer.destroy(),this._stage&&(this._stage.destroy(),this._stage=null)},Qi.prototype._mouseDown=function(t){var e=null;if("mousedown"!==t.type||0===t.evt.button){var i=ke(t.target);if(i){if("point-marker"===i.attrs.name||"segment-marker"===i.attrs.name)return;"segment-overlay"===i.attrs.name&&(e=i)}if(this._lastMouseClientX=Math.floor("touchstart"===t.type?t.evt.touches[0].clientX:t.evt.clientX),this._handlers.onMouseDown){var n=this._getMousePosX(this._lastMouseClientX);this._handlers.onMouseDown(n,e)}window.addEventListener("mousemove",this._mouseMove,{capture:!1,passive:!0}),window.addEventListener("touchmove",this._mouseMove,{capture:!1,passive:!0}),window.addEventListener("mouseup",this._mouseUp,{capture:!1,passive:!0}),window.addEventListener("touchend",this._mouseUp,{capture:!1,passive:!0}),window.addEventListener("blur",this._mouseUp,{capture:!1,passive:!0})}},Qi.prototype._mouseMove=function(t){var e=Math.floor("touchmove"===t.type?t.changedTouches[0].clientX:t.clientX);if(e!==this._lastMouseClientX&&(this._lastMouseClientX=e,this._dragging=!0,this._handlers.onMouseMove)){var i=this._getMousePosX(e);this._handlers.onMouseMove(i)}},Qi.prototype._mouseUp=function(t){var e;if("touchend"===t.type?(e=Math.floor(t.changedTouches[0].clientX),t.cancelable&&t.preventDefault()):e=Math.floor(t.clientX),this._handlers.onMouseUp){var i=this._getMousePosX(e);this._handlers.onMouseUp(i)}window.removeEventListener("mousemove",this._mouseMove,{capture:!1}),window.removeEventListener("touchmove",this._mouseMove,{capture:!1}),window.removeEventListener("mouseup",this._mouseUp,{capture:!1}),window.removeEventListener("touchend",this._mouseUp,{capture:!1}),window.removeEventListener("blur",this._mouseUp,{capture:!1}),this._dragging=!1},Qi.prototype._getMousePosX=function(t){return t-this._stage.getContainer().getBoundingClientRect().left},Qi.prototype.isDragging=function(){return this._dragging},Qi.prototype.destroy=function(){this._stage.off("mousedown",this._mouseDown),this._stage.off("touchstart",this._mouseDown)},$i.prototype._onMouseDown=function(t){this._seek(t)},$i.prototype._onMouseMove=function(t){this._seek(t)},$i.prototype._seek=function(t){if(this._view.isSeekEnabled()){t=de(t,0,this._width);var e=this._view.pixelsToTime(t),i=this._peaks.player.getDuration();e>i&&(e=i),this._view.updatePlayheadTime(e),this._peaks.player.seek(e)}},$i.prototype.destroy=function(){this._mouseDragHandler.destroy()},tn.prototype=Object.create(Ji.prototype),tn.prototype.initWaveform=function(){0!==this._width&&this._resampleAndSetWaveformData(this._originalWaveformData,this._width)},tn.prototype.initHighlightLayer=function(){this._highlightLayer=new Oi(this,this._viewOptions),this._highlightLayer.addToStage(this._stage)},tn.prototype.isSegmentDraggingEnabled=function(){return!1},tn.prototype.getName=function(){return"overview"},tn.prototype._onTimeUpdate=function(t){this._playheadLayer.updatePlayheadTime(t)},tn.prototype._onPlaying=function(t){this._playheadLayer.updatePlayheadTime(t)},tn.prototype._onPause=function(t){this._playheadLayer.stop(t)},tn.prototype._onZoomviewDisplaying=function(t,e){this.showHighlight(t,e)},tn.prototype.showHighlight=function(t,e){this._highlightLayer.showHighlight(t,e)},tn.prototype.setWaveformData=function(t){this._originalWaveformData=t,0!==this._width?this._resampleAndSetWaveformData(t,this._width):this._data=t,this.updateWaveform()},tn.prototype._resampleAndSetWaveformData=function(t,e){try{return this._data=t.resample({width:e}),!0}catch(e){return this._data=t,!1}},tn.prototype.removeHighlightRect=function(){this._highlightLayer.removeHighlight()},tn.prototype.updateWaveform=function(){this._waveformLayer.draw(),this._axisLayer.draw();var t=this._peaks.player.getCurrentTime();this._playheadLayer.updatePlayheadTime(t),this._highlightLayer.updateHighlight();var e=this.pixelsToTime(this._width);this._pointsLayer&&this._pointsLayer.updatePoints(0,e),this._segmentsLayer&&this._segmentsLayer.updateSegments(0,e)},tn.prototype.containerWidthChange=function(){return this._resampleAndSetWaveformData(this._originalWaveformData,this._width)},tn.prototype.containerHeightChange=function(){this._highlightLayer.fitToView()},tn.prototype.destroy=function(){this._peaks.off("player.playing",this._onPlaying),this._peaks.off("player.pause",this._onPause),this._peaks.off("player.timeupdate",this._onTimeUpdate),this._peaks.off("zoomview.displaying",this._onZoomviewDisplaying),this._mouseDragHandler.destroy(),Ji.prototype.destroy.call(this)},en.prototype.isDragging=function(){return this._mouseDragHandler.isDragging()},en.prototype._reset=function(){this._insertSegment=null,this._insertSegmentShape=null,this._segmentIsDraggable=!1,this._peaks.segments.setInserting(!1)},en.prototype._onMouseDown=function(t,e){if(this._reset(),this._segment=e,this._segment){if("overlap"!==this._view.getSegmentDragMode())return;this._segmentIsDraggable=this._segment.draggable(),this._segment.draggable(!1)}var i=this._view.pixelsToTime(t+this._view.getFrameOffset());this._peaks.segments.setInserting(!0),this._insertSegment=this._peaks.segments.add({startTime:i,endTime:i,editable:!0}),this._insertSegmentShape=this._view._segmentsLayer.getSegmentShape(this._insertSegment),this._insertSegmentShape&&(this._insertSegmentShape.moveMarkersToTop(),this._insertSegmentShape.startDrag())},en.prototype._onMouseMove=function(){},en.prototype._onMouseUp=function(){this._insertSegment&&(this._insertSegmentShape&&(this._insertSegmentShape.stopDrag(),this._insertSegmentShape=null),this._segment&&this._segmentIsDraggable&&this._segment.draggable(!0),this._peaks.emit("segments.insert",{segment:this._insertSegment}),this._peaks.segments.setInserting(!1))},en.prototype.destroy=function(){this._mouseDragHandler.destroy()},nn.prototype.isDragging=function(){return this._mouseDragHandler.isDragging()},nn.prototype._onMouseDown=function(t,e){this._seeking=!1,e&&!e.attrs.draggable?this._segment=null:this._segment=e;var i=this._view.getPlayheadOffset();if(this._view.isSeekEnabled()&&Math.abs(t-i)<=this._view.getPlayheadClickTolerance()&&(this._seeking=!0,this._segment&&(this._segmentIsDraggable=this._segment.draggable(),this._segment.draggable(!1))),this._seeking){t=de(t,0,this._view.getWidth());var n=this._view.pixelsToTime(t+this._view.getFrameOffset());this._seek(n)}else this._initialFrameOffset=this._view.getFrameOffset(),this._mouseDownX=t},nn.prototype._onMouseMove=function(t){if(!this._segment||this._seeking)if(this._seeking){t=de(t,0,this._view.getWidth());var e=this._view.pixelsToTime(t+this._view.getFrameOffset());this._seek(e)}else if(!this._view.isAutoZoom()){var i=this._mouseDownX-t,n=this._initialFrameOffset+i;n!==this._initialFrameOffset&&this._view.updateWaveform(n)}},nn.prototype._onMouseUp=function(){if(!this._seeking&&this._view._enableSeek&&!this._mouseDragHandler.isDragging()){var t=this._view.pixelOffsetToTime(this._mouseDownX);this._seek(t)}this._segment&&this._seeking&&this._segmentIsDraggable&&this._segment.draggable(!0)},nn.prototype._seek=function(t){var e=this._peaks.player.getDuration();t>e&&(t=e),this._view.updatePlayheadTime(t),this._peaks.player.seek(t)},nn.prototype.destroy=function(){this._mouseDragHandler.destroy()},rn.prototype=Object.create(Ji.prototype),rn.prototype.initWaveform=function(){this._enableWaveformCache=this._options.waveformCache,this._initWaveformCache();var t=this._peaks.zoom.getZoomLevel();this._resampleData({scale:t})},rn.prototype._initWaveformCache=function(){this._enableWaveformCache&&(this._waveformData=new Map,this._waveformData.set(this._originalWaveformData.scale,this._originalWaveformData),this._waveformScales=[this._originalWaveformData.scale])},rn.prototype.initHighlightLayer=function(){},rn.prototype.setWheelMode=function(t,e){if(e||(e={}),(t!==this._wheelMode||e.captureVerticalScroll!==this._captureVerticalScroll)&&(this._stage.off("wheel"),this._wheelMode=t,this._captureVerticalScroll=e.captureVerticalScroll,"scroll"===t))e.captureVerticalScroll?this._stage.on("wheel",this._onWheelCaptureVerticalScroll):this._stage.on("wheel",this._onWheel)},rn.prototype._onWheel=function(t){var e,i=t.evt;if(i.shiftKey)if(0!==i.deltaY)e=i.deltaY;else{if(0===i.deltaX)return;e=i.deltaX}else{if(Math.abs(i.deltaX)=this._frameOffset+this._width-this._autoScrollOffset||e=0&&a=this._zoomLevels.length&&(t=this._zoomLevels.length-1),t<0&&(t=0),e||t!==this._zoomLevelIndex){this._zoomLevelIndex=t;var i=this._peaks.views.getView("zoomview");i&&i.setZoom({scale:this._zoomLevels[t]})}},sn.prototype.getZoom=function(){return this._zoomLevelIndex},sn.prototype.getZoomLevel=function(){return this._zoomLevels[this._zoomLevelIndex]},hn.prototype.min_sample=function(t){var e=2*(t*this._waveformData.channels+this._channelIndex);return this._waveformData._at(e)},hn.prototype.max_sample=function(t){var e=2*(t*this._waveformData.channels+this._channelIndex)+1;return this._waveformData._at(e)},hn.prototype.set_min_sample=function(t,e){var i=2*(t*this._waveformData.channels+this._channelIndex);return this._waveformData._set_at(i,e)},hn.prototype.set_max_sample=function(t,e){var i=2*(t*this._waveformData.channels+this._channelIndex)+1;return this._waveformData._set_at(i,e)},hn.prototype.min_array=function(){for(var t=this._waveformData.length,e=[],i=0;i0&&i++,i}(o,n),p=8===t.bits?1:2,g=new ArrayBuffer(d+2*c*p*l),f=new DataView(g),_=0,m=d,v=new Array(l),y=new Array(l);for(e=0;ey[0]&&(y[0]=k,y[0]>w&&(y[0]=w))}else for(e=0;ey[e]&&(y[e]=k,y[e]>w&&(y[e]=w));if(++_===n){for(e=0;e0)for(e=0;e0?(this._min[a]=this._inputData.channel(a).min_sample(this._input_index),this._max[a]=this._inputData.channel(a).max_sample(this._input_index)):(this._min[a]=0,this._max[a]=0);this._min_value=8===this._inputData.bits?-128:-32768,this._max_value=8===this._inputData.bits?127:32767,this._where=0,this._prev_where=0,this._stop=0,this._last_input_index=0}vn.create=function(t){return new vn(t)},vn.createFromAudio=function(t,e){var i=function(t){return{scale:t.scale||yn,bits:t.bits||bn,amplitude_scale:t.amplitude_scale||wn,split_channels:t.split_channels||kn,disable_worker:t.disable_worker||Sn}}(t);if(t.audio_context&&t.array_buffer)return function(t,e,i,n){function r(t){t||(t=new DOMException("EncodingError")),n(t),n=function(){}}var a=t.decodeAudioData(e,(function(t){Cn(t,i,n)}),r);a&&a.catch(r)}(t.audio_context,t.array_buffer,i,e);if(t.audio_buffer)return Cn(t.audio_buffer,i,e);throw new TypeError("WaveformData.createFromAudio(): Pass either an AudioContext and ArrayBuffer, or an AudioBuffer object")},xn.prototype.sample_at_pixel=function(t){return Math.floor(t*this._output_samples_per_pixel)},xn.prototype.next=function(){for(var t,e,i,n=0,r=this._inputData.channels;this._input_index0)for(i=0;ithis._input_buffer_size&&(this._stop=this._input_buffer_size);this._input_indexthis._max[i]&&(this._max[i]=e);this._input_index++}n++}if(this._input_indexthis.length&&(e=this.length),i>this.length&&(i=this.length),e>i&&(e=i);var n=i-e,r=8===this.bits?1:2,a=24+2*n*this.channels*r,o=new ArrayBuffer(a),s=new DataView(o);s.setInt32(0,2,!0),s.setUint32(4,8===this.bits,!0),s.setInt32(8,this.sample_rate,!0),s.setInt32(12,this.scale,!0),s.setInt32(16,n,!0),s.setInt32(20,this.channels,!0);for(var h=0;h=0&&t=t[i])return!1;e=t[i]}return!0}(this.options.zoomLevels)?void(this._logger=this.options.logger):new Error("Peaks.init(): The zoomLevels array must be sorted in ascending order"):new TypeError("Peaks.init(): The zoomLevels option should be an array"))},In.prototype.setSource=function(t,e){var i=this;i.player._setSource(t).then((function(){t.zoomLevels||(t.zoomLevels=i.options.zoomLevels),i._waveformBuilder=new An(i),i._waveformBuilder.init(t,(function(n,r){n?e(n):(i._waveformBuilder=null,i._waveformData=r,["overview","zoomview"].forEach((function(t){var e=i.views.getView(t);e&&e.setWaveformData(r)})),i.zoom.setZoomLevels(t.zoomLevels),e())}))})).catch((function(t){e(t)}))},In.prototype.getWaveformData=function(){return this._waveformData},In.prototype.destroy=function(){this._waveformBuilder&&this._waveformBuilder.abort(),this._keyboardHandler&&this._keyboardHandler.destroy(),this.views&&this.views.destroy(),this.player&&this.player.destroy(),this._cueEmitter&&this._cueEmitter.destroy()},In})); //# sourceMappingURL=peaks.min.js.map