/*! * Popcorn v0.0.2 (https://github.com/zendamacf/popcorn) * * Licensed under the MIT License */ !function(t){var e={};function i(r){if(e[r])return e[r].exports;var n=e[r]={i:r,l:!1,exports:{}};return t[r].call(n.exports,n,n.exports,i),n.l=!0,n.exports}i.m=t,i.c=e,i.d=function(t,e,r){i.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},i.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},i.t=function(t,e){if(1&e&&(t=i(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(i.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var n in t)i.d(r,n,function(e){return t[e]}.bind(null,n));return r},i.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(e,"a",e),e},i.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},i.p="",i(i.s=20)}([function(t,e,i){"use strict";(function(t){Object.defineProperty(e,"__esModule",{value:!0});var i=Math.PI/180;var r=function(t){var e=t.indexOf("msie ");if(e>0)return parseInt(t.substring(e+5,t.indexOf(".",e)),10);if(t.indexOf("trident/")>0){var i=t.indexOf("rv:");return parseInt(t.substring(i+3,t.indexOf(".",i)),10)}var r=t.indexOf("edge/");return r>0&&parseInt(t.substring(r+5,t.indexOf(".",r)),10)};e._parseUA=function(t){var e=t.toLowerCase(),i=/(chrome)[ /]([\w.]+)/.exec(e)||/(webkit)[ /]([\w.]+)/.exec(e)||/(opera)(?:.*version|)[ /]([\w.]+)/.exec(e)||/(msie) ([\w.]+)/.exec(e)||e.indexOf("compatible")<0&&/(mozilla)(?:.*? rv:([\w.]+)|)/.exec(e)||[],n=!!t.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i),o=!!t.match(/IEMobile/i);return{browser:i[1]||"",version:i[2]||"0",isIE:r(e),mobile:n,ieMobile:o}},e.glob=void 0!==t?t:"undefined"!=typeof window?window:"undefined"!=typeof WorkerGlobalScope?self:{},e.Konva={_global:e.glob,version:"6.0.0",isBrowser:"undefined"!=typeof window&&("[object Window]"==={}.toString.call(window)||"[object global]"==={}.toString.call(window)),isUnminified:/param/.test(function(t){}.toString()),dblClickWindow:400,getAngle:function(t){return e.Konva.angleDeg?t*i:t},enableTrace:!1,_pointerEventsEnabled:!1,hitOnDragEnabled:!1,captureTouchEventsEnabled:!1,listenClickTap:!1,inDblClickWindow:!1,pixelRatio:void 0,dragDistance:3,angleDeg:!0,showWarnings:!0,dragButtons:[0,1],isDragging:function(){return e.Konva.DD.isDragging},isDragReady:function(){return!!e.Konva.DD.node},UA:e._parseUA(e.glob.navigator&&e.glob.navigator.userAgent||""),document:e.glob.document,_injectGlobal:function(t){e.glob.Konva=t},_parseUA:e._parseUA},e._NODES_REGISTRY={},e._registerNode=function(t){e._NODES_REGISTRY[t.prototype.getClassName()]=t,e.Konva[t.prototype.getClassName()]=t}}).call(this,i(17))},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=i(0),n=function(){function t(){}return t.toCollection=function(e){var i,r=new t,n=e.length;for(i=0;i0?Math.acos(t/s):-Math.acos(t/s),a.scaleX=s,a.scaleY=o/s,a.skewX=(t*r+i*n)/o,a.skewY=0}else if(0!=r||0!=n){var h=Math.sqrt(r*r+n*n);a.rotation=Math.PI/2-(n>0?Math.acos(-r/h):-Math.acos(r/h)),a.scaleX=o/h,a.scaleY=h,a.skewX=0,a.skewY=(t*r+i*n)/o}return a.rotation=e.Util._getRotation(a.rotation),a},t}();e.Transform=o;var a=Math.PI/180,s=180/Math.PI,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]},l=/rgb\((\d{1,3}),(\d{1,3}),(\d{1,3})\)/,c=[];e.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?0:t>0?1:-1},requestAnimFrame:function(t){c.push(t),1===c.length&&requestAnimationFrame((function(){var t=c;c=[],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},_simplifyArray:function(t){var i,r,n=[],o=t.length,a=e.Util;for(i=0;i>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},get:function(t,e){return void 0===t?e: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=l.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(t){return t=t||"black",e.Util._namedColorToRBA(t)||e.Util._hex3ColorToRGBA(t)||e.Util._hex6ColorToRGBA(t)||e.Util._rgbColorToRGBA(t)||e.Util._rgbaColorToRGBA(t)||e.Util._hslColorToRGBA(t)},_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(Number);return{r:e[0],g:e[1],b:e[2],a:e[3]}}},_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}},_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=(e[0],e.slice(1)),r=Number(i[0])/360,n=Number(i[1])/100,o=Number(i[2])/100,a=void 0,s=void 0,h=void 0;if(0===n)return h=255*o,{r:Math.round(h),g:Math.round(h),b:Math.round(h),a:1};for(var l=2*o-(a=o<.5?o*(1+n):o+n-o*n),c=[0,0,0],d=0;d<3;d++)(s=r+1/3*-(d-1))<0&&s++,s>1&&s--,h=6*s<1?l+6*(a-l)*s:2*s<1?a:3*s<2?l+(a-l)*(2/3-s)*6:l,c[d]=255*h;return{r:Math.round(c[0]),g:Math.round(c[1]),b:Math.round(c[2]),a:1}}},haveIntersection:function(t,e){return!(e.x>t.x+t.width||e.x+e.widtht.y+t.height||e.y+e.height1?(a=i,s=r,h=(i-n)*(i-n)+(r-o)*(r-o)):h=((a=t+c*(i-t))-n)*(a-n)+((s=e+c*(r-e))-o)*(s-o)}return[a,s,h]},_getProjectionToLine:function(t,i,r){var n=e.Util.cloneObject(t),o=Number.MAX_VALUE;return i.forEach((function(a,s){if(r||s!==i.length-1){var h=i[(s+1)%i.length],l=e.Util._getProjectionToSegment(a.x,a.y,h.x,h.y,t.x,t.y),c=l[0],d=l[1],p=l[2];pi.length){var s=i;i=t,t=s}for(n=0;n255?255:t<0?0:Math.round(t)},e.alphaComponent=function(t){return t>1?1:t<1e-4?1e-4:t},e.getNumberValidator=function(){if(r.Konva.isUnminified)return function(t,e){return n.Util._isNumber(t)||n.Util.warn(o(t)+' is a not valid value for "'+e+'" attribute. The value should be a number.'),t}},e.getNumberOrAutoValidator=function(){if(r.Konva.isUnminified)return function(t,e){return n.Util._isNumber(t)||"auto"===t||n.Util.warn(o(t)+' is a not valid value for "'+e+'" attribute. The value should be a number or "auto".'),t}},e.getStringValidator=function(){if(r.Konva.isUnminified)return function(t,e){return n.Util._isString(t)||n.Util.warn(o(t)+' is a not valid value for "'+e+'" attribute. The value should be a string.'),t}},e.getFunctionValidator=function(){if(r.Konva.isUnminified)return function(t,e){return n.Util._isFunction(t)||n.Util.warn(o(t)+' is a not valid value for "'+e+'" attribute. The value should be a function.'),t}},e.getNumberArrayValidator=function(){if(r.Konva.isUnminified)return function(t,e){return n.Util._isArray(t)?t.forEach((function(t){n.Util._isNumber(t)||n.Util.warn('"'+e+'" attribute has non numeric element '+t+". Make sure that all elements are numbers.")})):n.Util.warn(o(t)+' is a not valid value for "'+e+'" attribute. The value should be a array of numbers.'),t}},e.getBooleanValidator=function(){if(r.Konva.isUnminified)return function(t,e){return!0===t||!1===t||n.Util.warn(o(t)+' is a not valid value for "'+e+'" attribute. The value should be a boolean.'),t}},e.getComponentValidator=function(t){if(r.Konva.isUnminified)return function(e,i){return n.Util.isObject(e)||n.Util.warn(o(e)+' is a not valid value for "'+i+'" attribute. The value should be an object with properties '+t),e}}},function(t,e,i){"use strict";var r,n=this&&this.__extends||(r=function(t,e){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i])})(t,e)},function(t,e){function i(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)});Object.defineProperty(e,"__esModule",{value:!0});var o,a=i(1),s=i(2),h=i(10),l=i(3),c=i(0),d=i(14);function p(){return o||(o=a.Util.createCanvasElement().getContext("2d"))}function u(){this._clearCache("hasShadow")}function f(){this._clearCache("shadowRGBA")}function g(){this._clearCache("patternImage")}function y(){this._clearCache("linearGradient")}function v(){this._clearCache("radialGradient")}e.shapes={};var _=function(t){function i(i){for(var r,n=t.call(this,i)||this;!(r=a.Util.getRandomColor())||r in e.shapes;);return n.colorKey=r,e.shapes[r]=n,n.on("shadowColorChange.konva shadowBlurChange.konva shadowOffsetChange.konva shadowOpacityChange.konva shadowEnabledChange.konva",u),n.on("shadowColorChange.konva shadowOpacityChange.konva shadowEnabledChange.konva",f),n.on("fillPriorityChange.konva fillPatternImageChange.konva fillPatternRepeatChange.konva fillPatternScaleXChange.konva fillPatternScaleYChange.konva",g),n.on("fillPriorityChange.konva fillLinearGradientColorStopsChange.konva fillLinearGradientStartPointXChange.konva fillLinearGradientStartPointYChange.konva fillLinearGradientEndPointXChange.konva fillLinearGradientEndPointYChange.konva",y),n.on("fillPriorityChange.konva fillRadialGradientColorStopsChange.konva fillRadialGradientStartPointXChange.konva fillRadialGradientStartPointYChange.konva fillRadialGradientEndPointXChange.konva fillRadialGradientEndPointYChange.konva fillRadialGradientStartRadiusChange.konva fillRadialGradientEndRadiusChange.konva",v),n}return n(i,t),i.prototype.getContext=function(){return this.getLayer().getContext()},i.prototype.getCanvas=function(){return this.getLayer().getCanvas()},i.prototype.getSceneFunc=function(){return this.attrs.sceneFunc||this._sceneFunc},i.prototype.getHitFunc=function(){return this.attrs.hitFunc||this._hitFunc},i.prototype.hasShadow=function(){return this._getCache("hasShadow",this._hasShadow)},i.prototype._hasShadow=function(){return this.shadowEnabled()&&0!==this.shadowOpacity()&&!!(this.shadowColor()||this.shadowBlur()||this.shadowOffsetX()||this.shadowOffsetY())},i.prototype._getFillPattern=function(){return this._getCache("patternImage",this.__getFillPattern)},i.prototype.__getFillPattern=function(){if(this.fillPatternImage())return p().createPattern(this.fillPatternImage(),this.fillPatternRepeat()||"repeat")},i.prototype._getLinearGradient=function(){return this._getCache("linearGradient",this.__getLinearGradient)},i.prototype.__getLinearGradient=function(){var t=this.fillLinearGradientColorStops();if(t){for(var e=p(),i=this.fillLinearGradientStartPoint(),r=this.fillLinearGradientEndPoint(),n=e.createLinearGradient(i.x,i.y,r.x,r.y),o=0;o0},i.prototype.destroy=function(){return h.Node.prototype.destroy.call(this),delete e.shapes[this.colorKey],delete this.colorKey,this},i.prototype._useBufferCanvas=function(t){return!(t&&!this.hasShadow()||!this.perfectDrawEnabled()||1===this.getAbsoluteOpacity()||!this.hasFill()||!this.hasStroke()||!this.getStage())},i.prototype.setStrokeHitEnabled=function(t){a.Util.warn("strokeHitEnabled property is deprecated. Please use hitStrokeWidth instead."),t?this.hitStrokeWidth("auto"):this.hitStrokeWidth(0)},i.prototype.getStrokeHitEnabled=function(){return 0!==this.hitStrokeWidth()},i.prototype.getSelfRect=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}},i.prototype.getClientRect=function(t){var e=(t=t||{}).skipTransform,i=t.relativeTo,r=this.getSelfRect(),n=!t.skipStroke&&this.hasStroke()&&this.strokeWidth()||0,o=r.width+n,a=r.height+n,s=!t.skipShadow&&this.hasShadow(),h=s?this.shadowOffsetX():0,l=s?this.shadowOffsetY():0,c=o+Math.abs(h),d=a+Math.abs(l),p=s&&this.shadowBlur()||0,u=c+2*p,f=d+2*p,g=0;Math.round(n/2)!==n/2&&(g=1);var y={width:u+g,height:f+g,x:-Math.round(n/2+p)+Math.min(h,0)+r.x,y:-Math.round(n/2+p)+Math.min(l,0)+r.y};return e?y:this._transformedRect(y,i)},i.prototype.drawScene=function(t,e,i,r){var n,o,a=this.getLayer(),s=t||a.getCanvas(),h=s.getContext(),l=this._getCanvasCache(),c=this.sceneFunc(),d=this.hasShadow(),p=this.hasStroke();if(!this.isVisible()&&!i)return this;if(l)return h.save(),a._applyTransform(this,h,e),this._drawCachedSceneCanvas(h),h.restore(),this;if(!c)return this;if(h.save(),this._useBufferCanvas(i)&&!r){if((o=(n=this.getStage().bufferCanvas).getContext()).clear(),o.save(),o._applyLineJoin(this),!i)if(a)a._applyTransform(this,o,e);else{var u=this.getAbsoluteTransform(e).getMatrix();h.transform(u[0],u[1],u[2],u[3],u[4],u[5])}c.call(this,o,this),o.restore();var f=n.pixelRatio;d&&!s.hitCanvas?(h.save(),h._applyShadow(this),h._applyOpacity(this),h._applyGlobalCompositeOperation(this),h.drawImage(n._canvas,0,0,n.width/f,n.height/f),h.restore()):(h._applyOpacity(this),h._applyGlobalCompositeOperation(this),h.drawImage(n._canvas,0,0,n.width/f,n.height/f))}else{if(h._applyLineJoin(this),!i)if(a)a._applyTransform(this,h,e);else{var g=this.getAbsoluteTransform(e).getMatrix();h.transform(g[0],g[1],g[2],g[3],g[4],g[5])}d&&p&&!s.hitCanvas?(h.save(),i||(h._applyOpacity(this),h._applyGlobalCompositeOperation(this)),h._applyShadow(this),c.call(this,h,this),h.restore(),this.hasFill()&&this.shadowForStrokeEnabled()&&c.call(this,h,this)):d&&!s.hitCanvas?(h.save(),i||(h._applyOpacity(this),h._applyGlobalCompositeOperation(this)),h._applyShadow(this),c.call(this,h,this),h.restore()):(i||(h._applyOpacity(this),h._applyGlobalCompositeOperation(this)),c.call(this,h,this))}return h.restore(),this},i.prototype.drawHit=function(t,e,i){var r=this.getLayer(),n=t||r.hitCanvas,o=n&&n.getContext(),s=this.hitFunc()||this.sceneFunc(),h=this._getCanvasCache(),l=h&&h.hit;if(this.colorKey||(console.log(this),a.Util.warn("Looks like your canvas has a destroyed shape in it. Do not reuse shape after you destroyed it. See the shape in logs above. If you want to reuse shape you should call remove() instead of destroy()")),!this.shouldDrawHit()&&!i)return this;if(l)return o.save(),r._applyTransform(this,o,e),this._drawCachedHitCanvas(o),o.restore(),this;if(!s)return this;if(o.save(),o._applyLineJoin(this),!i)if(r)r._applyTransform(this,o,e);else{var c=this.getAbsoluteTransform(e).getMatrix();o.transform(c[0],c[1],c[2],c[3],c[4],c[5])}return s.call(this,o,this),o.restore(),this},i.prototype.drawHitFromCache=function(t){void 0===t&&(t=0);var e,i,r,n,o,s=this._getCanvasCache(),h=this._getCachedSceneCanvas(),l=s.hit,c=l.getContext(),d=l.getWidth(),p=l.getHeight();c.clear(),c.drawImage(h._canvas,0,0,d,p);try{for(r=(i=(e=c.getImageData(0,0,d,p)).data).length,n=a.Util._hexToRgb(this.colorKey),o=0;ot?(i[o]=n.r,i[o+1]=n.g,i[o+2]=n.b,i[o+3]=255):i[o+3]=0;c.putImageData(e,0,0)}catch(t){a.Util.error("Unable to draw hit graph from cached scene canvas. "+t.message)}return this},i.prototype.hasPointerCapture=function(t){return d.hasPointerCapture(t,this)},i.prototype.setPointerCapture=function(t){d.setPointerCapture(t,this)},i.prototype.releaseCapture=function(t){d.releaseCapture(t,this)},i}(h.Node);e.Shape=_,_.prototype._fillFunc=function(t){t.fill()},_.prototype._strokeFunc=function(t){t.stroke()},_.prototype._fillFuncHit=function(t){t.fill()},_.prototype._strokeFuncHit=function(t){t.stroke()},_.prototype._centroid=!1,_.prototype.nodeType="Shape",c._registerNode(_),s.Factory.addGetterSetter(_,"stroke",void 0,l.getStringValidator()),s.Factory.addGetterSetter(_,"strokeWidth",2,l.getNumberValidator()),s.Factory.addGetterSetter(_,"hitStrokeWidth","auto",l.getNumberOrAutoValidator()),s.Factory.addGetterSetter(_,"strokeHitEnabled",!0,l.getBooleanValidator()),s.Factory.addGetterSetter(_,"perfectDrawEnabled",!0,l.getBooleanValidator()),s.Factory.addGetterSetter(_,"shadowForStrokeEnabled",!0,l.getBooleanValidator()),s.Factory.addGetterSetter(_,"lineJoin"),s.Factory.addGetterSetter(_,"lineCap"),s.Factory.addGetterSetter(_,"sceneFunc"),s.Factory.addGetterSetter(_,"hitFunc"),s.Factory.addGetterSetter(_,"dash"),s.Factory.addGetterSetter(_,"dashOffset",0,l.getNumberValidator()),s.Factory.addGetterSetter(_,"shadowColor",void 0,l.getStringValidator()),s.Factory.addGetterSetter(_,"shadowBlur",0,l.getNumberValidator()),s.Factory.addGetterSetter(_,"shadowOpacity",1,l.getNumberValidator()),s.Factory.addComponentsGetterSetter(_,"shadowOffset",["x","y"]),s.Factory.addGetterSetter(_,"shadowOffsetX",0,l.getNumberValidator()),s.Factory.addGetterSetter(_,"shadowOffsetY",0,l.getNumberValidator()),s.Factory.addGetterSetter(_,"fillPatternImage"),s.Factory.addGetterSetter(_,"fill",void 0,l.getStringValidator()),s.Factory.addGetterSetter(_,"fillPatternX",0,l.getNumberValidator()),s.Factory.addGetterSetter(_,"fillPatternY",0,l.getNumberValidator()),s.Factory.addGetterSetter(_,"fillLinearGradientColorStops"),s.Factory.addGetterSetter(_,"strokeLinearGradientColorStops"),s.Factory.addGetterSetter(_,"fillRadialGradientStartRadius",0),s.Factory.addGetterSetter(_,"fillRadialGradientEndRadius",0),s.Factory.addGetterSetter(_,"fillRadialGradientColorStops"),s.Factory.addGetterSetter(_,"fillPatternRepeat","repeat"),s.Factory.addGetterSetter(_,"fillEnabled",!0),s.Factory.addGetterSetter(_,"strokeEnabled",!0),s.Factory.addGetterSetter(_,"shadowEnabled",!0),s.Factory.addGetterSetter(_,"dashEnabled",!0),s.Factory.addGetterSetter(_,"strokeScaleEnabled",!0),s.Factory.addGetterSetter(_,"fillPriority","color"),s.Factory.addComponentsGetterSetter(_,"fillPatternOffset",["x","y"]),s.Factory.addGetterSetter(_,"fillPatternOffsetX",0,l.getNumberValidator()),s.Factory.addGetterSetter(_,"fillPatternOffsetY",0,l.getNumberValidator()),s.Factory.addComponentsGetterSetter(_,"fillPatternScale",["x","y"]),s.Factory.addGetterSetter(_,"fillPatternScaleX",1,l.getNumberValidator()),s.Factory.addGetterSetter(_,"fillPatternScaleY",1,l.getNumberValidator()),s.Factory.addComponentsGetterSetter(_,"fillLinearGradientStartPoint",["x","y"]),s.Factory.addComponentsGetterSetter(_,"strokeLinearGradientStartPoint",["x","y"]),s.Factory.addGetterSetter(_,"fillLinearGradientStartPointX",0),s.Factory.addGetterSetter(_,"strokeLinearGradientStartPointX",0),s.Factory.addGetterSetter(_,"fillLinearGradientStartPointY",0),s.Factory.addGetterSetter(_,"strokeLinearGradientStartPointY",0),s.Factory.addComponentsGetterSetter(_,"fillLinearGradientEndPoint",["x","y"]),s.Factory.addComponentsGetterSetter(_,"strokeLinearGradientEndPoint",["x","y"]),s.Factory.addGetterSetter(_,"fillLinearGradientEndPointX",0),s.Factory.addGetterSetter(_,"strokeLinearGradientEndPointX",0),s.Factory.addGetterSetter(_,"fillLinearGradientEndPointY",0),s.Factory.addGetterSetter(_,"strokeLinearGradientEndPointY",0),s.Factory.addComponentsGetterSetter(_,"fillRadialGradientStartPoint",["x","y"]),s.Factory.addGetterSetter(_,"fillRadialGradientStartPointX",0),s.Factory.addGetterSetter(_,"fillRadialGradientStartPointY",0),s.Factory.addComponentsGetterSetter(_,"fillRadialGradientEndPoint",["x","y"]),s.Factory.addGetterSetter(_,"fillRadialGradientEndPointX",0),s.Factory.addGetterSetter(_,"fillRadialGradientEndPointY",0),s.Factory.addGetterSetter(_,"fillPatternRotation",0),s.Factory.backCompat(_,{dashArray:"dash",getDashArray:"getDash",setDashArray:"getDash",drawFunc:"sceneFunc",getDrawFunc:"getSceneFunc",setDrawFunc:"setSceneFunc",drawHitFunc:"hitFunc",getDrawHitFunc:"getHitFunc",setDrawHitFunc:"setHitFunc"}),a.Collection.mapMethods(_)},function(t,e,i){"use strict";var r,n=this&&this.__extends||(r=function(t,e){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i])})(t,e)},function(t,e){function i(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)});Object.defineProperty(e,"__esModule",{value:!0});var o,a=i(1),s=i(2),h=i(4),l=i(0),c=i(3),d=i(0),p=["fontFamily","fontSize","fontStyle","fontVariant","padding","align","verticalAlign","lineHeight","text","width","height","wrap","ellipsis","letterSpacing"],u=p.length;function f(){return o||(o=a.Util.createCanvasElement().getContext("2d"))}String.prototype.trimRight;var g=function(t){function e(e){var i=t.call(this,function(t){return(t=t||{}).fillLinearGradientColorStops||t.fillRadialGradientColorStops||t.fillPatternImage||(t.fill=t.fill||"black"),t}(e))||this;i._partialTextX=0,i._partialTextY=0;for(var r=0;r1&&(y+=n)}},e.prototype._hitFunc=function(t){var e=this.getWidth(),i=this.getHeight();t.beginPath(),t.rect(0,0,e,i),t.closePath(),t.fillStrokeShape(this)},e.prototype.setText=function(t){var e=a.Util._isString(t)?t:null==t?"":t+"";return this._setAttr("text",e),this},e.prototype.getWidth=function(){return"auto"===this.attrs.width||void 0===this.attrs.width?this.getTextWidth()+2*this.padding():this.attrs.width},e.prototype.getHeight=function(){return"auto"===this.attrs.height||void 0===this.attrs.height?this.fontSize()*this.textArr.length*this.lineHeight()+2*this.padding():this.attrs.height},e.prototype.getTextWidth=function(){return this.textWidth},e.prototype.getTextHeight=function(){return a.Util.warn("text.getTextHeight() method is deprecated. Use text.height() - for full height and text.fontSize() - for one line height."),this.textHeight},e.prototype.measureSize=function(t){var e,i=f(),r=this.fontSize();return i.save(),i.font=this._getContextFont(),e=i.measureText(t),i.restore(),{width:e.width,height:r}},e.prototype._getContextFont=function(){return l.Konva.UA.isIE?this.fontStyle()+" "+this.fontSize()+"px "+this.fontFamily():this.fontStyle()+" "+this.fontVariant()+" "+this.fontSize()+"px "+this.fontFamily()},e.prototype._addTextLine=function(t){"justify"===this.align()&&(t=t.trim());var e=this._getTextWidth(t);return this.textArr.push({text:t,width:e})},e.prototype._getTextWidth=function(t){var e=this.letterSpacing(),i=t.length;return f().measureText(t).width+(i?e*(i-1):0)},e.prototype._setTextData=function(){var t=this.text().split("\n"),e=+this.fontSize(),i=0,r=this.lineHeight()*e,n=this.attrs.width,o=this.attrs.height,a="auto"!==n&&void 0!==n,s="auto"!==o&&void 0!==o,h=this.padding(),l=n-2*h,c=o-2*h,d=0,p=this.wrap(),u="none"!==p,g="char"!==p&&u,y=this.ellipsis()&&!u;this.textArr=[],f().font=this._getContextFont();for(var v=y?this._getTextWidth("…"):0,_=0,m=t.length;_l)for(;b.length>0;){for(var S=0,w=b.length,x="",P=0;S>>1,T=b.slice(0,k+1),D=this._getTextWidth(T)+v;D<=l?(S=k+1,x=T+(y?"…":""),P=D):w=k}if(!x)break;if(g){var G,A=b[x.length];(G=(" "===A||"-"===A)&&P<=l?x.length:Math.max(x.lastIndexOf(" "),x.lastIndexOf("-"))+1)>0&&(S=G,x=x.slice(0,S),P=this._getTextWidth(x))}if(x=x.trimRight(),this._addTextLine(x),i=Math.max(i,P),d+=r,!u||s&&d+r>c)break;if((b=(b=b.slice(S)).trimLeft()).length>0&&(C=this._getTextWidth(b))<=l){this._addTextLine(b),d+=r,i=Math.max(i,C);break}}else this._addTextLine(b),d+=r,i=Math.max(i,C);if(s&&d+r>c)break}this.textHeight=e,this.textWidth=i},e.prototype.getStrokeScaleEnabled=function(){return!0},e}(h.Shape);e.Text=g,g.prototype._fillFunc=function(t){t.fillText(this._partialText,this._partialTextX,this._partialTextY)},g.prototype._strokeFunc=function(t){t.strokeText(this._partialText,this._partialTextX,this._partialTextY)},g.prototype.className="Text",g.prototype._attrsAffectingSize=["text","fontSize","padding","wrap","lineHeight"],d._registerNode(g),s.Factory.overWriteSetter(g,"width",c.getNumberOrAutoValidator()),s.Factory.overWriteSetter(g,"height",c.getNumberOrAutoValidator()),s.Factory.addGetterSetter(g,"fontFamily","Arial"),s.Factory.addGetterSetter(g,"fontSize",12,c.getNumberValidator()),s.Factory.addGetterSetter(g,"fontStyle","normal"),s.Factory.addGetterSetter(g,"fontVariant","normal"),s.Factory.addGetterSetter(g,"padding",0,c.getNumberValidator()),s.Factory.addGetterSetter(g,"align","left"),s.Factory.addGetterSetter(g,"verticalAlign","top"),s.Factory.addGetterSetter(g,"lineHeight",1,c.getNumberValidator()),s.Factory.addGetterSetter(g,"wrap","word"),s.Factory.addGetterSetter(g,"ellipsis",!1),s.Factory.addGetterSetter(g,"letterSpacing",0,c.getNumberValidator()),s.Factory.addGetterSetter(g,"text","",c.getStringValidator()),s.Factory.addGetterSetter(g,"textDecoration",""),a.Collection.mapMethods(g)},function(t,e,i){"use strict";var r,n=this&&this.__extends||(r=function(t,e){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i])})(t,e)},function(t,e){function i(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)});Object.defineProperty(e,"__esModule",{value:!0});var o=i(1),a=i(7),s=i(2),h=i(19),l=i(8),c=i(4),d=i(3),p=i(0),u=[{x:0,y:0},{x:-1,y:-1},{x:1,y:-1},{x:1,y:1},{x:-1,y:1}],f=u.length,g=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.hitCanvas=new l.HitCanvas({pixelRatio:1}),e}return n(e,t),e.prototype.setSize=function(e){var i=e.width,r=e.height;return t.prototype.setSize.call(this,{width:i,height:r}),this.hitCanvas.setSize(i,r),this},e.prototype._validateAdd=function(t){var e=t.getType();"Group"!==e&&"Shape"!==e&&o.Util.throw("You may only add groups and shapes to a layer.")},e.prototype.getIntersection=function(t,e){var i,r,n,o;if(!this.hitGraphEnabled()||!this.isVisible())return null;for(var a=1,s=!1;;){for(r=0;r0?{antialiased:!0}:{}},e.prototype.drawScene=function(t,e){var i=this.getLayer(),r=t||i&&i.getCanvas();return this._fire("beforeDraw",{node:this}),this.clearBeforeDraw()&&r.getContext().clear(),a.Container.prototype.drawScene.call(this,r,e),this._fire("draw",{node:this}),this},e.prototype.drawHit=function(t,e){var i=this.getLayer(),r=t||i&&i.hitCanvas;return i&&i.clearBeforeDraw()&&i.getHitCanvas().getContext().clear(),a.Container.prototype.drawHit.call(this,r,e),this},e.prototype.clear=function(t){return h.BaseLayer.prototype.clear.call(this,t),this.getHitCanvas().getContext().clear(t),this},e.prototype.enableHitGraph=function(){return this.hitGraphEnabled(!0),this},e.prototype.disableHitGraph=function(){return this.hitGraphEnabled(!1),this},e.prototype.toggleHitCanvas=function(){if(this.parent){var t=this.parent;!!this.hitCanvas._canvas.parentNode?t.content.removeChild(this.hitCanvas._canvas):t.content.appendChild(this.hitCanvas._canvas)}},e}(h.BaseLayer);e.Layer=g,g.prototype.nodeType="Layer",p._registerNode(g),s.Factory.addGetterSetter(g,"hitGraphEnabled",!0,d.getBooleanValidator()),o.Collection.mapMethods(g)},function(t,e,i){"use strict";var r,n=this&&this.__extends||(r=function(t,e){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i])})(t,e)},function(t,e){function i(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)});Object.defineProperty(e,"__esModule",{value:!0});var o=i(1),a=i(2),s=i(10),h=i(11),l=i(3),c=i(0),d=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.children=new o.Collection,e}return n(e,t),e.prototype.getChildren=function(t){if(!t)return this.children;var e=new o.Collection;return this.children.each((function(i){t(i)&&e.push(i)})),e},e.prototype.hasChildren=function(){return this.getChildren().length>0},e.prototype.removeChildren=function(){for(var t,e=0;e1){for(var i=0;i0?e[0]:void 0},e.prototype._generalFind=function(t,e){var i=[];return this._descendants((function(r){var n=r._isMatch(t);return n&&i.push(r),!(!n||!e)})),o.Collection.toCollection(i)},e.prototype._descendants=function(t){for(var e=0;e0&&t[0].getDepth()<=n&&s(t)}(o.getStage().getChildren()),a},t.prototype.getDepth=function(){for(var t=0,e=this.parent;e;)t++,e=e.parent;return t},t.prototype._batchTransformChanges=function(t){this._batchingTransformChange=!0,t(),this._batchingTransformChange=!1,this._needClearTransformCache&&(this._clearCache("transform"),this._clearSelfAndDescendantCache("absoluteTransform",!0)),this._needClearTransformCache=!1},t.prototype.setPosition=function(t){var e=this;return this._batchTransformChanges((function(){e.x(t.x),e.y(t.y)})),this},t.prototype.getPosition=function(){return{x:this.x(),y:this.y()}},t.prototype.getAbsolutePosition=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(),o=new r.Transform,a=this.offset();return o.m=n.slice(),o.translate(a.x,a.y),o.getTranslation()},t.prototype.setAbsolutePosition=function(t){var e,i=this._clearTransform();return this.attrs.x=i.x,this.attrs.y=i.y,delete i.x,delete i.y,this._clearCache("transform"),(e=this._getAbsoluteTransform()).invert(),e.translate(t.x,t.y),t={x:this.attrs.x+e.getTranslation().x,y:this.attrs.y+e.getTranslation().y},this._setTransform(i),this.setPosition({x:t.x,y:t.y}),this},t.prototype._setTransform=function(t){var e;for(e in t)this.attrs[e]=t[e]},t.prototype._clearTransform=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},t.prototype.move=function(t){var e=t.x,i=t.y,r=this.x(),n=this.y();return void 0!==e&&(r+=e),void 0!==i&&(n+=i),this.setPosition({x:r,y:n}),this},t.prototype._eachAncestorReverse=function(t,e){var i,r,n=[],o=this.getParent();if(e&&e._id===this._id)t(this);else{for(n.unshift(this);o&&(!e||o._id!==e._id);)n.unshift(o),o=o.parent;for(i=n.length,r=0;r0&&(this.parent.children.splice(t,1),this.parent.children.splice(t-1,0,this),this.parent._setChildrenIndices(),!0)},t.prototype.moveToBottom=function(){if(!this.parent)return r.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)},t.prototype.setZIndex=function(t){if(!this.parent)return r.Util.warn("Node has no parent. zIndex parameter is ignored."),this;(t<0||t>=this.parent.children.length)&&r.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},t.prototype.getAbsoluteOpacity=function(){return this._getCache("absoluteOpacity",this._getAbsoluteOpacity)},t.prototype._getAbsoluteOpacity=function(){var t=this.opacity(),e=this.getParent();return e&&!e._isUnderCache&&(t*=e.getAbsoluteOpacity()),t},t.prototype.moveTo=function(t){return this.getParent()!==t&&(this._remove(),t.add(this)),this},t.prototype.toObject=function(){var t,e,i,n,o={},a=this.getAttrs();for(t in o.attrs={},a)e=a[t],r.Util.isObject(e)&&!r.Util._isPlainObject(e)&&!r.Util._isArray(e)||(i="function"==typeof this[t]&&this[t],delete a[t],n=i?i.call(this):null,a[t]=e,n!==e&&(o.attrs[t]=e));return o.className=this.getClassName(),r.Util._prepareToStringify(o)},t.prototype.toJSON=function(){return JSON.stringify(this.toObject())},t.prototype.getParent=function(){return this.parent},t.prototype.findAncestors=function(t,e,i){var r=[];e&&this._isMatch(t)&&r.push(this);for(var n=this.parent;n;){if(n===i)return r;n._isMatch(t)&&r.push(n),n=n.parent}return r},t.prototype.isAncestorOf=function(t){return!1},t.prototype.findAncestor=function(t,e,i){return this.findAncestors(t,e,i)[0]},t.prototype._isMatch=function(t){if(!t)return!1;if("function"==typeof t)return t(this);var e,i,n=t.replace(/ /g,"").split(","),o=n.length;for(e=0;e=0)&&!this.isDragging()){var i=!1;s.DD._dragElements.forEach((function(t){e.isAncestorOf(t.node)&&(i=!0)})),i||this._createDragElement(t)}}))},t.prototype._dragChange=function(){this.attrs.draggable?this._listenDrag():(this._dragCleanup(),this.getStage()&&s.DD._dragElements.has(this._id)&&this.stopDrag())},t.prototype._dragCleanup=function(){this.off("mousedown.konva"),this.off("touchstart.konva")},t.create=function(t,e){return r.Util._isString(t)&&(t=JSON.parse(t)),this._createNode(t,e)},t._createNode=function(e,i){var n,o,s,h=t.prototype.getClassName.call(e),l=e.children;if(i&&(e.attrs.container=i),a._NODES_REGISTRY[h]||(r.Util.warn('Can not find a node with class name "'+h+'". Fallback to "Shape".'),h="Shape"),n=new(0,a._NODES_REGISTRY[h])(e.attrs),l)for(o=l.length,s=0;s4){for(i=(e=this.getTensionPoints()).length,r=s?0:4,s||t.quadraticCurveTo(e[0],e[1],e[2],e[3]);r-1&&e.stages.splice(r,1),this},i.prototype.getPointerPosition=function(){var t=this._pointerPositions[0]||this._changedPointerPositions[0];return t?{x:t.x,y:t.y}:(o.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)},i.prototype._getPointerById=function(t){return this._pointerPositions.find((function(e){return e.id===t}))},i.prototype.getPointersPositions=function(){return this._pointerPositions},i.prototype.getStage=function(){return this},i.prototype.getContent=function(){return this.content},i.prototype._toKonvaCanvas=function(t){var e=(t=t||{}).x||0,i=t.y||0,r=new l.SceneCanvas({width:t.width||this.width(),height:t.height||this.height(),pixelRatio:t.pixelRatio||1}),n=r.getContext()._context,o=this.children;return(e||i)&&n.translate(-1*e,-1*i),o.each((function(r){if(r.isVisible()){var o=r._toKonvaCanvas(t);n.drawImage(o._canvas,e,i,o.getWidth()/o.getPixelRatio(),o.getHeight()/o.getPixelRatio())}})),r},i.prototype.getIntersection=function(t,e){if(!t)return null;var i,r,n=this.children;for(i=n.length-1;i>=0;i--)if(r=n[i].getIntersection(t,e))return r;return null},i.prototype._resizeDOM=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.each((function(i){i.setSize({width:t,height:e}),i.draw()}))},i.prototype.add=function(e){if(arguments.length>1){for(var i=0;i5&&o.Util.warn("The stage has "+r+" 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."),e.setSize({width:this.width(),height:this.height()}),e.draw(),h.Konva.isBrowser&&this.content.appendChild(e.canvas._canvas),this},i.prototype.getParent=function(){return null},i.prototype.getLayer=function(){return null},i.prototype.hasPointerCapture=function(t){return p.hasPointerCapture(t,this)},i.prototype.setPointerCapture=function(t){p.setPointerCapture(t,this)},i.prototype.releaseCapture=function(t){p.releaseCapture(t,this)},i.prototype.getLayers=function(){return this.getChildren()},i.prototype._bindContentEvents=function(){if(h.Konva.isBrowser)for(var t=0;t=100&&e.shift()},t.prototype.reset=function(){var t=this.getCanvas().getPixelRatio();this.setTransform(1*t,0,0,1*t,0,0)},t.prototype.getCanvas=function(){return this.canvas},t.prototype.clear=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)},t.prototype._applyLineCap=function(t){var e=t.getLineCap();e&&this.setAttr("lineCap",e)},t.prototype._applyOpacity=function(t){var e=t.getAbsoluteOpacity();1!==e&&this.setAttr("globalAlpha",e)},t.prototype._applyLineJoin=function(t){var e=t.getLineJoin();e&&this.setAttr("lineJoin",e)},t.prototype.setAttr=function(t,e){this._context[t]=e},t.prototype.arc=function(t,e,i,r,n,o){this._context.arc(t,e,i,r,n,o)},t.prototype.arcTo=function(t,e,i,r,n){this._context.arcTo(t,e,i,r,n)},t.prototype.beginPath=function(){this._context.beginPath()},t.prototype.bezierCurveTo=function(t,e,i,r,n,o){this._context.bezierCurveTo(t,e,i,r,n,o)},t.prototype.clearRect=function(t,e,i,r){this._context.clearRect(t,e,i,r)},t.prototype.clip=function(){this._context.clip()},t.prototype.closePath=function(){this._context.closePath()},t.prototype.createImageData=function(t,e){var i=arguments;return 2===i.length?this._context.createImageData(t,e):1===i.length?this._context.createImageData(t):void 0},t.prototype.createLinearGradient=function(t,e,i,r){return this._context.createLinearGradient(t,e,i,r)},t.prototype.createPattern=function(t,e){return this._context.createPattern(t,e)},t.prototype.createRadialGradient=function(t,e,i,r,n,o){return this._context.createRadialGradient(t,e,i,r,n,o)},t.prototype.drawImage=function(t,e,i,r,n,o,a,s,h){var l=arguments,c=this._context;3===l.length?c.drawImage(t,e,i):5===l.length?c.drawImage(t,e,i,r,n):9===l.length&&c.drawImage(t,e,i,r,n,o,a,s,h)},t.prototype.ellipse=function(t,e,i,r,n,o,a,s){this._context.ellipse(t,e,i,r,n,o,a,s)},t.prototype.isPointInPath=function(t,e){return this._context.isPointInPath(t,e)},t.prototype.fill=function(){this._context.fill()},t.prototype.fillRect=function(t,e,i,r){this._context.fillRect(t,e,i,r)},t.prototype.strokeRect=function(t,e,i,r){this._context.strokeRect(t,e,i,r)},t.prototype.fillText=function(t,e,i){this._context.fillText(t,e,i)},t.prototype.measureText=function(t){return this._context.measureText(t)},t.prototype.getImageData=function(t,e,i,r){return this._context.getImageData(t,e,i,r)},t.prototype.lineTo=function(t,e){this._context.lineTo(t,e)},t.prototype.moveTo=function(t,e){this._context.moveTo(t,e)},t.prototype.rect=function(t,e,i,r){this._context.rect(t,e,i,r)},t.prototype.putImageData=function(t,e,i){this._context.putImageData(t,e,i)},t.prototype.quadraticCurveTo=function(t,e,i,r){this._context.quadraticCurveTo(t,e,i,r)},t.prototype.restore=function(){this._context.restore()},t.prototype.rotate=function(t){this._context.rotate(t)},t.prototype.save=function(){this._context.save()},t.prototype.scale=function(t,e){this._context.scale(t,e)},t.prototype.setLineDash=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)},t.prototype.getLineDash=function(){return this._context.getLineDash()},t.prototype.setTransform=function(t,e,i,r,n,o){this._context.setTransform(t,e,i,r,n,o)},t.prototype.stroke=function(){this._context.stroke()},t.prototype.strokeText=function(t,e,i,r){this._context.strokeText(t,e,i,r)},t.prototype.transform=function(t,e,i,r,n,o){this._context.transform(t,e,i,r,n,o)},t.prototype.translate=function(t,e){this._context.translate(t,e)},t.prototype._enableTrace=function(){var t,e,i=this,r=s.length,n=o.Util._simplifyArray,a=this.setAttr,h=function(t){var r,o=i[t];i[t]=function(){return e=n(Array.prototype.slice.call(arguments,0)),r=o.apply(i,arguments),i._trace({method:t,args:e}),r}};for(t=0;t{const e=t.target.getStage().container();this.booked||this.unavailable?e.style.cursor="not-allowed":e.style.cursor="pointer"}).on("mouseleave",t=>{t.target.getStage().container().style.cursor=""}).setAttr("seat",this)}color(){return this.isSelected?this.opts.selectedColor:this.booked?this.opts.bookedColor:this.opts.seatColor}name(){return this.isSelected?"selected":"unselected"}select(){this.booked||this.unavailable||(this.isSelected=!0,this.change())}deselect(){this.isSelected=!1,this.change()}change(){this.seatShape.find("Circle").fill(this.color()),this.seatShape.name(this.name())}get shape(){return this.seatShape}};var g=class{constructor(t){return new l(t.selectedColor,t)}};var y=class{constructor(t,e){return this.opts=e,this.halfText=6,this.width=t,this.entryWidth=this.width/4,this.entryPadding=this.entryWidth/4,this.seatWidth=this.opts.seatWidth/2+this.opts.seatMargin,this.group=new h.Group({x:20,y:this.opts.height-40,width:this.width,preventDefault:!1}),this._populateAvailable(),this._populateUnavailable(),this._populateBooked(),this._populateSelected(),this.group}_populateAvailable(){this._populateEntry(c,"Available",0)}_populateUnavailable(){this._populateEntry(p,"Unavailable",1)}_populateBooked(){this._populateEntry(u,"Booked",2)}_populateSelected(){this._populateEntry(g,"Selected",3)}_populateEntry(t,e,i){const r=this.entryWidth*i,n=new t(Object.assign({x:r+this.entryPadding},this.opts)),o=new a.Text({x:r+this.seatWidth+this.entryPadding,y:-this.halfText,fill:this.opts.textColor,text:e,preventDefault:!1});this.group.add(n).add(o)}};const v={textColor:"black",seatColor:"lightgrey",bookedColor:"red",selectedColor:"#00356D",seatWidth:30,seatMargin:15,rowLabelWidth:25},_=t=>{let e,i="";for(;t>0;)e=(t-1)%26,i=String.fromCharCode(e+65)+i,t=(t-e-1)/26;return i},m=(t,e)=>{const{y:i}=t.absolutePosition();t.absolutePosition({x:e.width()/2,y:i}),t.offsetX(t.width()/2)};window.Popcorn=class{constructor(t){if(this.opts=Object.assign(v,t||{}),!this.opts.seatList)throw"No seatlist provided.";if(this.elem=document.querySelector(this.opts.elem),null===this.elem)throw"Element not found.";var e;this.layout=(e=this.opts.seatList,[...e]),this.stage=new r.Stage({container:this.elem,width:this.opts.width,height:this.opts.height,preventDefault:!1}),this.seatWidth=this.opts.seatWidth+this.opts.seatMargin;const i=Math.min(this.layout.length,this.opts.rowWidth)*this.seatWidth+this.opts.rowLabelWidth;this.centeringOffset=(this.opts.width-i)/2,this.opts.backgroundColor&&this._populateBackground(),this._populateFrontLabel(),this._populateLayout(),this._populateLegend(i),this.stage.draw()}_populateBackground(){const t=new n.Layer({preventDefault:!1}),e=new o.Rect({x:0,y:0,width:this.opts.width,height:this.opts.height,fill:this.opts.backgroundColor,preventDefault:!1});t.add(e),this.stage.add(t)}_populateLayout(){const t=new n.Layer({preventDefault:!1}),e=this.centeringOffset+this.opts.rowLabelWidth+this.opts.seatWidth/2,i=80+this.opts.seatWidth/2,r=((t,e)=>{const i=[];for(;t.length;)i.push(t.splice(0,e));return i})(this.layout,this.opts.rowWidth);for(const[n,o]of r.entries()){const r=i+this.seatWidth*n,a=this._buildRowLabel(n+1,r);t.add(a);for(const[i,n]of o.entries())if(n.id){const o=this._buildSeat(n,e+this.seatWidth*i,r);t.add(o)}}this.stage.add(t)}_populateFrontLabel(){const t=new n.Layer({preventDefault:!1}),e=new o.Rect({y:10,stroke:this.opts.textColor,width:this.stage.width()/2,height:40,preventDefault:!1});m(e,this.stage),t.add(e);const i=new a.Text({y:20,fontSize:20,fontStyle:"bold",verticalAlign:"middle",fill:this.opts.textColor,text:"FRONT",preventDefault:!1});m(i,this.stage),t.add(i),this.stage.add(t)}_populateLegend(t){const e=new y(t,this.opts);m(e,this.stage);const i=new n.Layer({preventDefault:!1});i.add(e),this.stage.add(i)}_buildSeat(t,e,i){const r=new f(Object.assign({id:t.id,x:e,y:i,unavailable:t.unavailable,booked:t.booked},this.opts)).shape;return r.on("click tap",t=>{const e=t.target.findAncestor("Group").getAttr("seat"),i=this._getSelected();e.booked||e.unavailable||(!e.isSelected&&i.length>=this.opts.maxSeats?this._trigger("popcorn.maxseats",{total:i.length}):(e.isSelected?(e.deselect(),this._trigger("popcorn.deselectseat",{seatid:e.id,total:i.length-1})):(e.select(),this._trigger("popcorn.selectseat",{seatid:e.id,total:i.length+1})),this.redraw()))}),r}_getSelected(){return this.stage.find(".selected")}_buildRowLabel(t,e){return new a.Text({x:this.centeringOffset,y:e-this.opts.seatMargin/2,fontSize:.6*this.opts.seatWidth,fontStyle:"bold",verticalAlign:"middle",fill:this.opts.textColor,text:_(t),preventDefault:!1})}_trigger(t,e){const i=new CustomEvent(t,{detail:e||{}});this.elem.dispatchEvent(i)}on(t,e){this.elem.addEventListener(t,e)}redraw(){this.stage.draw()}destroy(){this.stage.destroy()}get selected(){return this._getSelected().map(t=>t.id())}set selected(t){this._getSelected().each(t=>{t.getAttr("seat").deselect()}),t.forEach(t=>{this.stage.find("#"+t)[0].getAttr("seat").select()}),this.redraw()}}}]);