forked from konvajs/konva
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkonva.min.js
31 lines (31 loc) · 90.5 KB
/
konva.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*
* Konva JavaScript Framework v1.2.2
* http://konvajs.github.io/
* Licensed under the MIT or GPL Version 2 licenses.
* Date: Tue Dec 20 2016
*
* Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS)
* Modified work Copyright (C) 2014 - 2015 by Anton Lavrenov (Konva)
*
* @license
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
!function(t){"use strict";var e=Math.PI/180,n={version:"1.2.2",stages:[],idCounter:0,ids:{},names:{},shapes:{},listenClickTap:!1,inDblClickWindow:!1,enableTrace:!1,traceArrMax:100,dblClickWindow:400,pixelRatio:void 0,dragDistance:0,angleDeg:!0,showWarnings:!0,Filters:{},isDragging:function(){var t=n.DD;return!!t&&t.isDragging},isDragReady:function(){var t=n.DD;return!!t&&!!t.node},_addId:function(t,e){void 0!==e&&(this.ids[e]=t)},_removeId:function(t){void 0!==t&&delete this.ids[t]},_addName:function(t,e){e&&(this.names[e]||(this.names[e]=[]),this.names[e].push(t))},_removeName:function(t,e){if(t){var n=this.names[t];if(n){for(var i=0;i<n.length;i++){var a=n[i];a._id===e&&n.splice(i,1)}0===n.length&&delete this.names[t]}}},getAngle:function(t){return this.angleDeg?t*e:t},_detectIE:function(t){var e=t.indexOf("msie ");if(e>0)return parseInt(t.substring(e+5,t.indexOf(".",e)),10);var n=t.indexOf("trident/");if(n>0){var i=t.indexOf("rv:");return parseInt(t.substring(i+3,t.indexOf(".",i)),10)}var a=t.indexOf("edge/");return a>0&&parseInt(t.substring(a+5,t.indexOf(".",a)),10)},_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)||[],a=!!t.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i),r=!!t.match(/IEMobile/i);return{browser:i[1]||"",version:i[2]||"0",isIE:n._detectIE(e),mobile:a,ieMobile:r}},UA:void 0},i="undefined"!=typeof t?t:"undefined"!=typeof window?window:"undefined"!=typeof WorkerGlobalScope?self:{};if(n.UA=n._parseUA(i.navigator&&i.navigator.userAgent||""),i.Konva&&console.error("Konva instance is already exist in current eviroment. Please use only one instance."),i.Konva=n,n.global=i,"object"==typeof exports){if(i.window&&i.window.document)n.document=i.window.document,n.window=i.window;else{var a=require("canvas"),r=require("jsdom").jsdom;n.window=r("<!DOCTYPE html><html><head></head><body></body></html>").defaultView,n.document=n.window.document,n.window.Image=a.Image,n._nodeCanvas=a}return void(module.exports=n)}"function"==typeof define&&define.amd&&define(function(){return n}),n.document=document,n.window=window}("undefined"!=typeof global?global:window),function(){"use strict";Konva.Collection=function(){var t=[].slice.call(arguments),e=t.length,n=0;for(this.length=e;n<e;n++)this[n]=t[n];return this},Konva.Collection.prototype=[],Konva.Collection.prototype.each=function(t){for(var e=0;e<this.length;e++)t(this[e],e)},Konva.Collection.prototype.toArray=function(){var t,e=[],n=this.length;for(t=0;t<n;t++)e.push(this[t]);return e},Konva.Collection.toCollection=function(t){var e,n=new Konva.Collection,i=t.length;for(e=0;e<i;e++)n.push(t[e]);return n},Konva.Collection._mapMethod=function(t){Konva.Collection.prototype[t]=function(){var e,n=this.length,i=[].slice.call(arguments);for(e=0;e<n;e++)this[e][t].apply(this[e],i);return this}},Konva.Collection.mapMethods=function(t){var e=t.prototype;for(var n in e)Konva.Collection._mapMethod(n)},Konva.Transform=function(t){this.m=t&&t.slice()||[1,0,0,1,0,0]},Konva.Transform.prototype={copy:function(){return new Konva.Transform(this.m)},point: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]}},translate: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},scale:function(t,e){return this.m[0]*=t,this.m[1]*=t,this.m[2]*=e,this.m[3]*=e,this},rotate:function(t){var e=Math.cos(t),n=Math.sin(t),i=this.m[0]*e+this.m[2]*n,a=this.m[1]*e+this.m[3]*n,r=this.m[0]*-n+this.m[2]*e,o=this.m[1]*-n+this.m[3]*e;return this.m[0]=i,this.m[1]=a,this.m[2]=r,this.m[3]=o,this},getTranslation:function(){return{x:this.m[4],y:this.m[5]}},skew:function(t,e){var n=this.m[0]+this.m[2]*e,i=this.m[1]+this.m[3]*e,a=this.m[2]+this.m[0]*t,r=this.m[3]+this.m[1]*t;return this.m[0]=n,this.m[1]=i,this.m[2]=a,this.m[3]=r,this},multiply:function(t){var e=this.m[0]*t.m[0]+this.m[2]*t.m[1],n=this.m[1]*t.m[0]+this.m[3]*t.m[1],i=this.m[0]*t.m[2]+this.m[2]*t.m[3],a=this.m[1]*t.m[2]+this.m[3]*t.m[3],r=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]=n,this.m[2]=i,this.m[3]=a,this.m[4]=r,this.m[5]=o,this},invert:function(){var t=1/(this.m[0]*this.m[3]-this.m[1]*this.m[2]),e=this.m[3]*t,n=-this.m[1]*t,i=-this.m[2]*t,a=this.m[0]*t,r=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]=n,this.m[2]=i,this.m[3]=a,this.m[4]=r,this.m[5]=o,this},getMatrix:function(){return this.m},setAbsolutePosition:function(t,e){var n=this.m[0],i=this.m[1],a=this.m[2],r=this.m[3],o=this.m[4],s=this.m[5],h=(n*(e-s)-i*(t-o))/(n*r-i*a),c=(t-o-a*h)/n;return this.translate(c,h)}};var t="2d",e="[object Array]",n="[object Number]",i="[object String]",a=Math.PI/180,r=180/Math.PI,o="#",s="",h="0",c="Konva warning: ",l="Konva error: ",d="rgb(",u={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]},f=/rgb\((\d{1,3}),(\d{1,3}),(\d{1,3})\)/;Konva.Util={_isElement:function(t){return!(!t||1!=t.nodeType)},_isFunction:function(t){return!!(t&&t.constructor&&t.call&&t.apply)},_isObject:function(t){return!!t&&t.constructor===Object},_isArray:function(t){return Object.prototype.toString.call(t)===e},_isNumber:function(t){return Object.prototype.toString.call(t)===n},_isString:function(t){return Object.prototype.toString.call(t)===i},_throttle:function(t,e,n){var i,a,r,o=null,s=0,h=n||{},c=function(){s=h.leading===!1?0:(new Date).getTime(),o=null,r=t.apply(i,a),i=a=null};return function(){var n=(new Date).getTime();s||h.leading!==!1||(s=n);var l=e-(n-s);return i=this,a=arguments,l<=0?(clearTimeout(o),o=null,s=n,r=t.apply(i,a),i=a=null):o||h.trailing===!1||(o=setTimeout(c,l)),r}},_hasMethods:function(t){var e,n=[];for(e in t)t.hasOwnProperty(e)&&this._isFunction(t[e])&&n.push(e);return n.length>0},isValidSelector:function(t){if("string"!=typeof t)return!1;var e=t[0];return"#"===e||"."===e||e===e.toUpperCase()},createCanvasElement:function(){var t=Konva.document.createElement("canvas");try{t.style=t.style||{}}catch(t){}return t},isBrowser:function(){return"object"!=typeof exports},_isInDocument:function(t){for(;t=t.parentNode;)if(t==Konva.document)return!0;return!1},_simplifyArray:function(t){var e,n,i=[],a=t.length,r=Konva.Util;for(e=0;e<a;e++)n=t[e],r._isNumber(n)?n=Math.round(1e3*n)/1e3:r._isString(n)||(n=n.toString()),i.push(n);return i},_getImage:function(e,n){var i,a;if(e)if(this._isElement(e))n(e);else if(this._isString(e))i=new Konva.window.Image,i.onload=function(){n(i)},i.src=e;else if(e.data){a=Konva.Util.createCanvasElement(),a.width=e.width,a.height=e.height;var r=a.getContext(t);r.putImageData(e,0,0),this._getImage(a.toDataURL(),n)}else n(null);else n(null)},_getRGBAString:function(t){var e=t.red||0,n=t.green||0,i=t.blue||0,a=t.alpha||1;return["rgba(",e,",",n,",",i,",",a,")"].join(s)},_rgbToHex:function(t,e,n){return((1<<24)+(t<<16)+(e<<8)+n).toString(16).slice(1)},_hexToRgb:function(t){t=t.replace(o,s);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=h+t;return o+t},get:function(t,e){return void 0===t?e:t},getRGB:function(t){var e;return t in u?(e=u[t],{r:e[0],g:e[1],b:e[2]}):t[0]===o?this._hexToRgb(t.substring(1)):t.substr(0,4)===d?(e=f.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",Konva.Util._namedColorToRBA(t)||Konva.Util._hex3ColorToRGBA(t)||Konva.Util._hex6ColorToRGBA(t)||Konva.Util._rgbColorToRGBA(t)||Konva.Util._rgbaColorToRGBA(t)},_namedColorToRBA:function(t){var e=u[t.toLowerCase()];return e?{r:e[0],g:e[1],b:e[2],a:1}:null},_rgbColorToRGBA:function(t){if(0===t.indexOf("rgb(")){t=t.match(/rgb\(([^)]+)\)/)[1];var e=t.split(/ *, */).map(Number);return{r:e[0],g:e[1],b:e[2],a:1}}},_rgbaColorToRGBA:function(t){if(0===t.indexOf("rgba(")){t=t.match(/rgba\(([^)]+)\)/)[1];var e=t.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}},_merge:function(t,e){var n=this._clone(e);for(var i in t)this._isObject(t[i])?n[i]=this._merge(t[i],n[i]):n[i]=t[i];return n},cloneObject:function(t){var e={};for(var n in t)this._isObject(t[n])?e[n]=this.cloneObject(t[n]):this._isArray(t[n])?e[n]=this.cloneArray(t[n]):e[n]=t[n];return e},cloneArray:function(t){return t.slice(0)},_degToRad:function(t){return t*a},_radToDeg:function(t){return t*r},_capitalize:function(t){return t.charAt(0).toUpperCase()+t.slice(1)},throw:function(t){throw new Error(l+t)},error:function(t){console.error(l+t)},warn:function(t){Konva.global.console&&console.warn&&Konva.showWarnings&&console.warn(c+t)},extend:function(t,e){function n(){this.constructor=t}n.prototype=e.prototype;var i=t.prototype;t.prototype=new n;for(var a in i)i.hasOwnProperty(a)&&(t.prototype[a]=i[a]);t.__super__=e.prototype,t.super=e},addMethods:function(t,e){var n;for(n in e)t.prototype[n]=e[n]},_getControlPoints:function(t,e,n,i,a,r,o){var s=Math.sqrt(Math.pow(n-t,2)+Math.pow(i-e,2)),h=Math.sqrt(Math.pow(a-n,2)+Math.pow(r-i,2)),c=o*s/(s+h),l=o*h/(s+h),d=n-c*(a-t),u=i-c*(r-e),f=n+l*(a-t),v=i+l*(r-e);return[d,u,f,v]},_expandPoints:function(t,e){var n,i,a=t.length,r=[];for(n=2;n<a-2;n+=2)i=Konva.Util._getControlPoints(t[n-2],t[n-1],t[n],t[n+1],t[n+2],t[n+3],e),r.push(i[0]),r.push(i[1]),r.push(t[n]),r.push(t[n+1]),r.push(i[2]),r.push(i[3]);return r},_removeLastLetter:function(t){return t.substring(0,t.length-1)},each:function(t,e){for(var n in t)e(n,t[n])},_getProjectionToSegment:function(t,e,n,i,a,r){var o,s,h,c=(t-n)*(t-n)+(e-i)*(e-i);if(0==c)o=t,s=e,h=(a-n)*(a-n)+(r-i)*(r-i);else{var l=((a-t)*(n-t)+(r-e)*(i-e))/c;l<0?(o=t,s=e,h=(t-a)*(t-a)+(e-r)*(e-r)):l>1?(o=n,s=i,h=(n-a)*(n-a)+(i-r)*(i-r)):(o=t+l*(n-t),s=e+l*(i-e),h=(o-a)*(o-a)+(s-r)*(s-r))}return[o,s,h]},_getProjectionToLine:function(t,e,n){var i=Konva.Util.cloneObject(t),a=Number.MAX_VALUE;return e.forEach(function(r,o){if(n||o!==e.length-1){var s=e[(o+1)%e.length],h=Konva.Util._getProjectionToSegment(r.x,r.y,s.x,s.y,t.x,t.y),c=h[0],l=h[1],d=h[2];d<a&&(i.x=c,i.y=l,a=d)}}),i},_prepareArrayForTween:function(t,e,n){var i,a=[],r=[];if(t.length>e.length){var o=e;e=t,t=o}for(i=0;i<t.length;i+=2)a.push({x:t[i],y:t[i+1]});for(i=0;i<e.length;i+=2)r.push({x:e[i],y:e[i+1]});var s=[];return r.forEach(function(t){var e=Konva.Util._getProjectionToLine(t,a,n);s.push(e.x),s.push(e.y)}),s},_prepareToStringify:function(t){var e;t.visitedByCircularReferenceRemoval=!0;for(var n in t)if(t.hasOwnProperty(n)&&t[n]&&"object"==typeof t[n])if(e=Object.getOwnPropertyDescriptor(t,n),t[n].visitedByCircularReferenceRemoval||Konva.Util._isElement(t[n])){if(!e.configurable)return null;delete t[n]}else if(null===Konva.Util._prepareToStringify(t[n])){if(!e.configurable)return null;delete t[n]}return delete t.visitedByCircularReferenceRemoval,t}}}(),function(){"use strict";var t=Konva.Util.createCanvasElement(),e=t.getContext("2d"),n=function(){var t=Konva.window.devicePixelRatio||1,n=e.webkitBackingStorePixelRatio||e.mozBackingStorePixelRatio||e.msBackingStorePixelRatio||e.oBackingStorePixelRatio||e.backingStorePixelRatio||1;return t/n}();Konva.Canvas=function(t){this.init(t)},Konva.Canvas.prototype={init:function(t){var e=t||{},i=e.pixelRatio||Konva.pixelRatio||n;this.pixelRatio=i,this._canvas=Konva.Util.createCanvasElement(),this._canvas.style.padding=0,this._canvas.style.margin=0,this._canvas.style.border=0,this._canvas.style.background="transparent",this._canvas.style.position="absolute",this._canvas.style.top=0,this._canvas.style.left=0},getContext:function(){return this.context},getPixelRatio:function(){return this.pixelRatio},setPixelRatio:function(t){var e=this.pixelRatio;this.pixelRatio=t,this.setSize(this.getWidth()/e,this.getHeight()/e)},setWidth:function(t){this.width=this._canvas.width=t*this.pixelRatio,this._canvas.style.width=t+"px";var e=this.pixelRatio,n=this.getContext()._context;n.scale(e,e)},setHeight:function(t){this.height=this._canvas.height=t*this.pixelRatio,this._canvas.style.height=t+"px";var e=this.pixelRatio,n=this.getContext()._context;n.scale(e,e)},getWidth:function(){return this.width},getHeight:function(){return this.height},setSize:function(t,e){this.setWidth(t),this.setHeight(e)},toDataURL:function(t,e){try{return this._canvas.toDataURL(t,e)}catch(t){try{return this._canvas.toDataURL()}catch(t){return Konva.Util.warn("Unable to get data URL. "+t.message),""}}}},Konva.SceneCanvas=function(t){var e=t||{},n=e.width||0,i=e.height||0;Konva.Canvas.call(this,e),this.context=new Konva.SceneContext(this),this.setSize(n,i)},Konva.Util.extend(Konva.SceneCanvas,Konva.Canvas),Konva.HitCanvas=function(t){var e=t||{},n=e.width||0,i=e.height||0;Konva.Canvas.call(this,e),this.context=new Konva.HitContext(this),this.setSize(n,i),this.hitCanvas=!0},Konva.Util.extend(Konva.HitCanvas,Konva.Canvas)}(),function(){"use strict";var t=",",e="(",n=")",i="([",a="])",r=";",o="()",s="=",h=["arc","arcTo","beginPath","bezierCurveTo","clearRect","clip","closePath","createLinearGradient","createPattern","createRadialGradient","drawImage","fill","fillText","getImageData","createImageData","lineTo","moveTo","putImageData","quadraticCurveTo","rect","restore","rotate","save","scale","setLineDash","setTransform","stroke","strokeText","transform","translate"],c=["fillStyle","strokeStyle","shadowColor","shadowBlur","shadowOffsetX","shadowOffsetY","lineCap","lineJoin","lineWidth","miterLimit","font","textAlign","textBaseline","globalAlpha","globalCompositeOperation"];Konva.Context=function(t){this.init(t)},Konva.Context.prototype={init:function(t){this.canvas=t,this._context=t._canvas.getContext("2d"),Konva.enableTrace&&(this.traceArr=[],this._enableTrace())},fillShape:function(t){t.getFillEnabled()&&this._fill(t)},strokeShape:function(t){t.getStrokeEnabled()&&this._stroke(t)},fillStrokeShape:function(t){var e=t.getFillEnabled();e&&this._fill(t),t.getStrokeEnabled()&&this._stroke(t)},getTrace:function(h){var c,l,d,u,f=this.traceArr,v=f.length,g="";for(c=0;c<v;c++)l=f[c],d=l.method,d?(u=l.args,g+=d,g+=h?o:Konva.Util._isArray(u[0])?i+u.join(t)+a:e+u.join(t)+n):(g+=l.property,h||(g+=s+l.val)),g+=r;return g},clearTrace:function(){this.traceArr=[]},_trace:function(t){var e,n=this.traceArr;n.push(t),e=n.length,e>=Konva.traceArrMax&&n.shift()},reset:function(){var t=this.getCanvas().getPixelRatio();this.setTransform(1*t,0,0,1*t,0,0)},getCanvas:function(){return this.canvas},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)},_applyLineCap:function(t){var e=t.getLineCap();e&&this.setAttr("lineCap",e)},_applyOpacity:function(t){var e=t.getAbsoluteOpacity();1!==e&&this.setAttr("globalAlpha",e)},_applyLineJoin:function(t){var e=t.getLineJoin();e&&this.setAttr("lineJoin",e)},setAttr:function(t,e){this._context[t]=e},arc:function(){var t=arguments;this._context.arc(t[0],t[1],t[2],t[3],t[4],t[5])},beginPath:function(){this._context.beginPath()},bezierCurveTo:function(){var t=arguments;this._context.bezierCurveTo(t[0],t[1],t[2],t[3],t[4],t[5])},clearRect:function(){var t=arguments;this._context.clearRect(t[0],t[1],t[2],t[3])},clip:function(){this._context.clip()},closePath:function(){this._context.closePath()},createImageData:function(){var t=arguments;return 2===t.length?this._context.createImageData(t[0],t[1]):1===t.length?this._context.createImageData(t[0]):void 0},createLinearGradient:function(){var t=arguments;return this._context.createLinearGradient(t[0],t[1],t[2],t[3])},createPattern:function(){var t=arguments;return this._context.createPattern(t[0],t[1])},createRadialGradient:function(){var t=arguments;return this._context.createRadialGradient(t[0],t[1],t[2],t[3],t[4],t[5])},drawImage:function(){var t=arguments,e=this._context;3===t.length?e.drawImage(t[0],t[1],t[2]):5===t.length?e.drawImage(t[0],t[1],t[2],t[3],t[4]):9===t.length&&e.drawImage(t[0],t[1],t[2],t[3],t[4],t[5],t[6],t[7],t[8])},isPointInPath:function(t,e){return this._context.isPointInPath(t,e)},fill:function(){this._context.fill()},fillRect:function(t,e,n,i){this._context.fillRect(t,e,n,i)},strokeRect:function(t,e,n,i){this._context.strokeRect(t,e,n,i)},fillText:function(){var t=arguments;this._context.fillText(t[0],t[1],t[2])},measureText:function(t){return this._context.measureText(t)},getImageData:function(){var t=arguments;return this._context.getImageData(t[0],t[1],t[2],t[3])},lineTo:function(){var t=arguments;this._context.lineTo(t[0],t[1])},moveTo:function(){var t=arguments;this._context.moveTo(t[0],t[1])},rect:function(){var t=arguments;this._context.rect(t[0],t[1],t[2],t[3])},putImageData:function(){var t=arguments;this._context.putImageData(t[0],t[1],t[2])},quadraticCurveTo:function(){var t=arguments;this._context.quadraticCurveTo(t[0],t[1],t[2],t[3])},restore:function(){this._context.restore()},rotate:function(){var t=arguments;this._context.rotate(t[0])},save:function(){this._context.save()},scale:function(){var t=arguments;this._context.scale(t[0],t[1])},setLineDash:function(){var t=arguments,e=this._context;this._context.setLineDash?e.setLineDash(t[0]):"mozDash"in e?e.mozDash=t[0]:"webkitLineDash"in e&&(e.webkitLineDash=t[0])},getLineDash:function(){return this._context.getLineDash()},setTransform:function(){var t=arguments;this._context.setTransform(t[0],t[1],t[2],t[3],t[4],t[5])},stroke:function(){this._context.stroke()},strokeText:function(){var t=arguments;this._context.strokeText(t[0],t[1],t[2])},transform:function(){var t=arguments;this._context.transform(t[0],t[1],t[2],t[3],t[4],t[5])},translate:function(){var t=arguments;this._context.translate(t[0],t[1])},_enableTrace:function(){var t,e,n=this,i=h.length,a=Konva.Util._simplifyArray,r=this.setAttr,o=function(t){var i,r=n[t];n[t]=function(){return e=a(Array.prototype.slice.call(arguments,0)),i=r.apply(n,arguments),n._trace({method:t,args:e}),i}};for(t=0;t<i;t++)o(h[t]);n.setAttr=function(){r.apply(n,arguments);var t=arguments[0],e=arguments[1];"shadowOffsetX"!==t&&"shadowOffsetY"!==t&&"shadowBlur"!==t||(e/=this.canvas.getPixelRatio()),n._trace({property:t,val:e})}}},c.forEach(function(t){Object.defineProperty(Konva.Context.prototype,t,{get:function(){return this._context[t]},set:function(e){this._context[t]=e}})}),Konva.SceneContext=function(t){Konva.Context.call(this,t)},Konva.SceneContext.prototype={_fillColor:function(t){var e=t.fill();this.setAttr("fillStyle",e),t._fillFunc(this)},_fillPattern:function(t){var e=t.getFillPatternX(),n=t.getFillPatternY(),i=t.getFillPatternScale(),a=Konva.getAngle(t.getFillPatternRotation()),r=t.getFillPatternOffset();(e||n)&&this.translate(e||0,n||0),a&&this.rotate(a),i&&this.scale(i.x,i.y),r&&this.translate(-1*r.x,-1*r.y),this.setAttr("fillStyle",this.createPattern(t.getFillPatternImage(),t.getFillPatternRepeat()||"repeat")),this.fill()},_fillLinearGradient:function(t){var e=t.getFillLinearGradientStartPoint(),n=t.getFillLinearGradientEndPoint(),i=t.getFillLinearGradientColorStops(),a=this.createLinearGradient(e.x,e.y,n.x,n.y);if(i){for(var r=0;r<i.length;r+=2)a.addColorStop(i[r],i[r+1]);this.setAttr("fillStyle",a),t._fillFunc(this)}},_fillRadialGradient:function(t){for(var e=t.getFillRadialGradientStartPoint(),n=t.getFillRadialGradientEndPoint(),i=t.getFillRadialGradientStartRadius(),a=t.getFillRadialGradientEndRadius(),r=t.getFillRadialGradientColorStops(),o=this.createRadialGradient(e.x,e.y,i,n.x,n.y,a),s=0;s<r.length;s+=2)o.addColorStop(r[s],r[s+1]);this.setAttr("fillStyle",o),this.fill()},_fill:function(t){var e=t.fill(),n=t.getFillPatternImage(),i=t.getFillLinearGradientColorStops(),a=t.getFillRadialGradientColorStops(),r=t.getFillPriority();e&&"color"===r?this._fillColor(t):n&&"pattern"===r?this._fillPattern(t):i&&"linear-gradient"===r?this._fillLinearGradient(t):a&&"radial-gradient"===r?this._fillRadialGradient(t):e?this._fillColor(t):n?this._fillPattern(t):i?this._fillLinearGradient(t):a&&this._fillRadialGradient(t)},_stroke:function(t){var e=t.dash(),n=t.getStrokeScaleEnabled()||t instanceof Konva.Text;t.hasStroke()&&(n||(this.save(),this.setTransform(1,0,0,1,0,0)),this._applyLineCap(t),e&&t.dashEnabled()&&this.setLineDash(e),this.setAttr("lineWidth",t.strokeWidth()),this.setAttr("strokeStyle",t.stroke()),t.getShadowForStrokeEnabled()||this.setAttr("shadowColor","rgba(0,0,0,0)"),t._strokeFunc(this),n||this.restore())},_applyShadow:function(t){var e=Konva.Util,n=e.get(t.getShadowRGBA(),"black"),i=e.get(t.getShadowBlur(),5),a=e.get(t.getShadowOffset(),{x:0,y:0}),r=t.getAbsoluteScale(),o=this.canvas.getPixelRatio(),s=r.x*o,h=r.y*o;this.setAttr("shadowColor",n),this.setAttr("shadowBlur",i*o*Math.min(s,h)),this.setAttr("shadowOffsetX",a.x*s),this.setAttr("shadowOffsetY",a.y*h)}},Konva.Util.extend(Konva.SceneContext,Konva.Context),Konva.HitContext=function(t){Konva.Context.call(this,t)},Konva.HitContext.prototype={_fill:function(t){this.save(),this.setAttr("fillStyle",t.colorKey),t._fillFuncHit(this),this.restore()},_stroke:function(t){if(t.hasStroke()&&t.strokeHitEnabled()){var e=t.getStrokeScaleEnabled()||t instanceof Konva.Text;e||(this.save(),this.setTransform(1,0,0,1,0,0)),this._applyLineCap(t),this.setAttr("lineWidth",t.strokeWidth()),this.setAttr("strokeStyle",t.colorKey),t._strokeFuncHit(this),e||this.restore()}}},Konva.Util.extend(Konva.HitContext,Konva.Context)}(),function(){"use strict";var t="get",e="set";Konva.Factory={addGetterSetter:function(t,e,n,i,a){this.addGetter(t,e,n),this.addSetter(t,e,i,a),this.addOverloadedGetterSetter(t,e)},addGetter:function(e,n,i){var a=t+Konva.Util._capitalize(n);e.prototype[a]=function(){var t=this.attrs[n];return void 0===t?i:t}},addSetter:function(t,n,i,a){var r=e+Konva.Util._capitalize(n);t.prototype[r]=function(t){return i&&(t=i.call(this,t)),this._setAttr(n,t),a&&a.call(this),this}},addComponentsGetterSetter:function(n,i,a,r,o){var s,h,c=a.length,l=Konva.Util._capitalize,d=t+l(i),u=e+l(i);n.prototype[d]=function(){var t={};for(s=0;s<c;s++)h=a[s],t[h]=this.getAttr(i+l(h));return t},n.prototype[u]=function(t){var e,n=this.attrs[i];r&&(t=r.call(this,t));for(e in t)t.hasOwnProperty(e)&&this._setAttr(i+l(e),t[e]);return this._fireChangeEvent(i,n,t),o&&o.call(this),this},this.addOverloadedGetterSetter(n,i)},addOverloadedGetterSetter:function(n,i){var a=Konva.Util._capitalize(i),r=e+a,o=t+a;n.prototype[i]=function(){return arguments.length?(this[r](arguments[0]),this):this[o]()}},addDeprecatedGetterSetter:function(e,n,i,a){var r=t+Konva.Util._capitalize(n),o=n+" property is deprecated and will be removed soon. Look at Konva change log for more information.";e.prototype[r]=function(){Konva.Util.error(o);var t=this.attrs[n];return void 0===t?i:t},this.addSetter(e,n,a,function(){Konva.Util.error(o)}),this.addOverloadedGetterSetter(e,n)},backCompat:function(t,e){Konva.Util.each(e,function(e,n){var i=t.prototype[n];t.prototype[e]=function(){i.apply(this,arguments),Konva.Util.error(e+" method is deprecated and will be removed soon. Use "+n+" instead")}})},afterSetFilter:function(){this._filterUpToDate=!1}},Konva.Validators={RGBComponent:function(t){return t>255?255:t<0?0:Math.round(t)},alphaComponent:function(t){return t>1?1:t<1e-4?1e-4:t}}}(),function(t){"use strict";var e="absoluteOpacity",n="absoluteTransform",i="absoluteScale",a="Change",r="children",o=".",s="",h="get",c="id",l="konva",d="listening",u="mouseenter",f="mouseleave",v="name",g="set",p="Shape",m=" ",_="stage",y="transform",C="Stage",S="visible",w=["id"],K=["xChange.konva","yChange.konva","scaleXChange.konva","scaleYChange.konva","skewXChange.konva","skewYChange.konva","rotationChange.konva","offsetXChange.konva","offsetYChange.konva","transformsEnabledChange.konva"].join(m),b=["scaleXChange.konva","scaleYChange.konva"].join(m);t.Node=function(t){this._init(t)},t.Util.addMethods(t.Node,{_init:function(a){var r=this;this._id=t.idCounter++,this.eventListeners={},this.attrs={},this._cache={},this._filterUpToDate=!1,this._isUnderCache=!1,this.setAttrs(a),this.on(K,function(){this._clearCache(y),r._clearSelfAndDescendantCache(n)}),this.on(b,function(){r._clearSelfAndDescendantCache(i)}),this.on("visibleChange.konva",function(){r._clearSelfAndDescendantCache(S)}),this.on("listeningChange.konva",function(){r._clearSelfAndDescendantCache(d)}),this.on("opacityChange.konva",function(){r._clearSelfAndDescendantCache(e)})},_clearCache:function(t){t?delete this._cache[t]:this._cache={}},_getCache:function(t,e){var n=this._cache[t];return void 0===n&&(this._cache[t]=e.call(this)),this._cache[t]},_clearSelfAndDescendantCache:function(t){this._clearCache(t),this.children&&this.getChildren().each(function(e){e._clearSelfAndDescendantCache(t)})},clearCache:function(){return delete this._cache.canvas,this._filterUpToDate=!1,this},cache:function(n){var a=n||{},r=this.getClientRect(!0),o=a.width||r.width,s=a.height||r.height,h=a.pixelRatio,c=a.x||r.x,l=a.y||r.y,d=a.offset||0,u=a.drawBorder||!1;if(!o||!s)throw new Error("Width or height of caching configuration equals 0.");o+=2*d,s+=2*d,c-=d,l-=d;var f=new t.SceneCanvas({pixelRatio:h,width:o,height:s}),v=new t.SceneCanvas({pixelRatio:h,width:o,height:s}),g=new t.HitCanvas({pixelRatio:1,width:o,height:s}),p=f.getContext(),m=g.getContext();return g.isCache=!0,this.clearCache(),p.save(),m.save(),p.translate(-c,-l),m.translate(-c,-l),this._isUnderCache=!0,this._clearSelfAndDescendantCache(e),this._clearSelfAndDescendantCache(i),this.drawScene(f,this,!0),this.drawHit(g,this,!0),this._isUnderCache=!1,p.restore(),m.restore(),u&&(p.save(),p.beginPath(),p.rect(0,0,o,s),p.closePath(),p.setAttr("strokeStyle","red"),p.setAttr("lineWidth",5),p.stroke(),p.restore()),this._cache.canvas={scene:f,filter:v,hit:g,x:c,y:l},this},getClientRect:function(){throw new Error('abstract "getClientRect" method call')},_transformedRect:function(t){var e,n,i,a,r=[{x:t.x,y:t.y},{x:t.x+t.width,y:t.y},{x:t.x+t.width,y:t.y+t.height},{x:t.x,y:t.y+t.height}],o=this.getTransform();return r.forEach(function(t){var r=o.point(t);void 0===e&&(e=i=r.x,n=a=r.y),e=Math.min(e,r.x),n=Math.min(n,r.y),i=Math.max(i,r.x),a=Math.max(a,r.y)}),{x:e,y:n,width:i-e,height:a-n}},_drawCachedSceneCanvas:function(t){t.save(),t._applyOpacity(this),t.translate(this._cache.canvas.x,this._cache.canvas.y);var e=this._getCachedSceneCanvas(),n=e.pixelRatio;t.drawImage(e._canvas,0,0,e.width/n,e.height/n),t.restore()},_drawCachedHitCanvas:function(t){var e=this._cache.canvas,n=e.hit;t.save(),t.translate(this._cache.canvas.x,this._cache.canvas.y),t.drawImage(n._canvas,0,0),t.restore()},_getCachedSceneCanvas:function(){var e,n,i,a,r=this.filters(),o=this._cache.canvas,s=o.scene,h=o.filter,c=h.getContext();if(r){if(!this._filterUpToDate){var l=s.pixelRatio;try{for(e=r.length,c.clear(),c.drawImage(s._canvas,0,0,s.getWidth()/l,s.getHeight()/l),n=c.getImageData(0,0,h.getWidth(),h.getHeight()),i=0;i<e;i++)a=r[i],"function"==typeof a?(a.call(this,n),c.putImageData(n,0,0)):t.Util.error("Filter should be type of function, but got "+typeof a+" insted. Please check correct filters")}catch(e){t.Util.error("Unable to apply filter. "+e.message)}this._filterUpToDate=!0}return h}return s},on:function(t,e){if(3===arguments.length)return this._delegate.apply(this,arguments);var n,i,a,r,h,c=t.split(m),l=c.length;for(n=0;n<l;n++)i=c[n],a=i.split(o),r=a[0],h=a[1]||s,this.eventListeners[r]||(this.eventListeners[r]=[]),this.eventListeners[r].push({name:h,handler:e});return this},off:function(t){var e,n,i,a,r,s,h=(t||"").split(m),c=h.length;if(!t)for(n in this.eventListeners)this._off(n);for(e=0;e<c;e++)if(i=h[e],a=i.split(o),r=a[0],s=a[1],r)this.eventListeners[r]&&this._off(r,s);else for(n in this.eventListeners)this._off(n,s);return this},dispatchEvent:function(t){var e={target:this,type:t.type,evt:t};return this.fire(t.type,e),this},addEventListener:function(t,e){return this.on(t,function(t){e.call(this,t.evt)}),this},removeEventListener:function(t){return this.off(t),this},_delegate:function(e,n,i){var a=this;this.on(e,function(e){for(var r=e.target.findAncestors(n,!0,a),o=0;o<r.length;o++)e=t.Util.cloneObject(e),e.currentTarget=r[o],i.call(r[o],e)})},remove:function(){var t=this.getParent();return t&&t.children&&(t.children.splice(this.index,1),
t._setChildrenIndices(),delete this.parent),this._clearSelfAndDescendantCache(_),this._clearSelfAndDescendantCache(n),this._clearSelfAndDescendantCache(S),this._clearSelfAndDescendantCache(d),this._clearSelfAndDescendantCache(e),this},destroy:function(){return t._removeId(this.getId()),t._removeName(this.getName(),this._id),this.remove(),this},getAttr:function(e){var n=h+t.Util._capitalize(e);return t.Util._isFunction(this[n])?this[n]():this.attrs[e]},getAncestors:function(){for(var e=this.getParent(),n=new t.Collection;e;)n.push(e),e=e.getParent();return n},getAttrs:function(){return this.attrs||{}},setAttrs:function(e){var n,i;if(!e)return this;for(n in e)n!==r&&(i=g+t.Util._capitalize(n),t.Util._isFunction(this[i])?this[i](e[n]):this._setAttr(n,e[n]));return this},isListening:function(){return this._getCache(d,this._isListening)},_isListening:function(){var t=this.getListening(),e=this.getParent();return"inherit"===t?!e||e.isListening():t},isVisible:function(){return this._getCache(S,this._isVisible)},_isVisible:function(){var t=this.getVisible(),e=this.getParent();return"inherit"===t?!e||e.isVisible():t},shouldDrawHit:function(t){var e=this.getLayer();return t&&t.isCache||e&&e.hitGraphEnabled()&&this.isListening()&&this.isVisible()},show:function(){return this.setVisible(!0),this},hide:function(){return this.setVisible(!1),this},getZIndex:function(){return this.index||0},getAbsoluteZIndex:function(){function t(h){for(e=[],n=h.length,i=0;i<n;i++)a=h[i],s++,a.nodeType!==p&&(e=e.concat(a.getChildren().toArray())),a._id===o._id&&(i=n);e.length>0&&e[0].getDepth()<=r&&t(e)}var e,n,i,a,r=this.getDepth(),o=this,s=0;return o.nodeType!==C&&t(o.getStage().getChildren()),s},getDepth:function(){for(var t=0,e=this.parent;e;)t++,e=e.parent;return t},setPosition:function(t){return this.setX(t.x),this.setY(t.y),this},getPosition:function(){return{x:this.getX(),y:this.getY()}},getAbsolutePosition:function(e){var n=this.getAbsoluteTransform(e).getMatrix(),i=new t.Transform,a=this.offset();return i.m=n.slice(),i.translate(a.x,a.y),i.getTranslation()},setAbsolutePosition:function(t){var e,n=this._clearTransform();return this.attrs.x=n.x,this.attrs.y=n.y,delete n.x,delete n.y,e=this.getAbsoluteTransform(),e.invert(),e.translate(t.x,t.y),t={x:this.attrs.x+e.getTranslation().x,y:this.attrs.y+e.getTranslation().y},this.setPosition({x:t.x,y:t.y}),this._setTransform(n),this},_setTransform:function(t){var e;for(e in t)this.attrs[e]=t[e];this._clearCache(y),this._clearSelfAndDescendantCache(n)},_clearTransform:function(){var t={x:this.getX(),y:this.getY(),rotation:this.getRotation(),scaleX:this.getScaleX(),scaleY:this.getScaleY(),offsetX:this.getOffsetX(),offsetY:this.getOffsetY(),skewX:this.getSkewX(),skewY:this.getSkewY()};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,this._clearCache(y),this._clearSelfAndDescendantCache(n),t},move:function(t){var e=t.x,n=t.y,i=this.getX(),a=this.getY();return void 0!==e&&(i+=e),void 0!==n&&(a+=n),this.setPosition({x:i,y:a}),this},_eachAncestorReverse:function(t,e){var n,i,a=[],r=this.getParent();if(e&&e._id===this._id)return t(this),!0;for(a.unshift(this);r&&(!e||r._id!==e._id);)a.unshift(r),r=r.parent;for(n=a.length,i=0;i<n;i++)t(a[i])},rotate:function(t){return this.setRotation(this.getRotation()+t),this},moveToTop:function(){if(!this.parent)return t.Util.warn("Node has no parent. moveToTop function is ignored."),!1;var e=this.index;return this.parent.children.splice(e,1),this.parent.children.push(this),this.parent._setChildrenIndices(),!0},moveUp:function(){if(!this.parent)return t.Util.warn("Node has no parent. moveUp function is ignored."),!1;var e=this.index,n=this.parent.getChildren().length;return e<n-1&&(this.parent.children.splice(e,1),this.parent.children.splice(e+1,0,this),this.parent._setChildrenIndices(),!0)},moveDown:function(){if(!this.parent)return t.Util.warn("Node has no parent. moveDown function is ignored."),!1;var e=this.index;return e>0&&(this.parent.children.splice(e,1),this.parent.children.splice(e-1,0,this),this.parent._setChildrenIndices(),!0)},moveToBottom:function(){if(!this.parent)return t.Util.warn("Node has no parent. moveToBottom function is ignored."),!1;var e=this.index;return e>0&&(this.parent.children.splice(e,1),this.parent.children.unshift(this),this.parent._setChildrenIndices(),!0)},setZIndex:function(e){if(!this.parent)return t.Util.warn("Node has no parent. zIndex parameter is ignored."),!1;var n=this.index;return this.parent.children.splice(n,1),this.parent.children.splice(e,0,this),this.parent._setChildrenIndices(),this},getAbsoluteOpacity:function(){return this._getCache(e,this._getAbsoluteOpacity)},_getAbsoluteOpacity:function(){var t=this.getOpacity(),e=this.getParent();return e&&!e._isUnderCache&&(t*=this.getParent().getAbsoluteOpacity()),t},moveTo:function(t){return this.getParent()!==t&&((this.__originalRemove||this.remove).call(this),t.add(this)),this},toObject:function(){var e,n,i,a,r={},o=this.getAttrs();r.attrs={};for(e in o)n=o[e],i=this[e],delete o[e],a=i?i.call(this):null,o[e]=n,a!==n&&(r.attrs[e]=n);return r.className=this.getClassName(),t.Util._prepareToStringify(r)},toJSON:function(){return JSON.stringify(this.toObject())},getParent:function(){return this.parent},findAncestors:function(t,e,n){var i=[];e&&this._isMatch(t)&&i.push(this);for(var a=this.parent;a;){if(a===n)return i;a._isMatch(t)&&i.push(a),a=a.parent}return i},findAncestor:function(t,e,n){return this.findAncestors(t,e,n)[0]},_isMatch:function(e){if(!e)return!1;var n,i,a=e.replace(/ /g,"").split(","),r=a.length;for(n=0;n<r;n++)if(i=a[n],t.Util.isValidSelector(i)||(t.Util.warn('Selector "'+i+'" is invalid. Allowed selectors examples are "#foo", ".bar" or "Group".'),t.Util.warn('If you have a custom shape with such className, please change it to start with upper letter like "Triangle".'),t.Util.warn("Konva is awesome, right?")),"#"===i.charAt(0)){if(this.id()===i.slice(1))return!0}else if("."===i.charAt(0)){if(this.hasName(i.slice(1)))return!0}else if(0!==this._get(i).length)return!0;return!1},getLayer:function(){var t=this.getParent();return t?t.getLayer():null},getStage:function(){return this._getCache(_,this._getStage)},_getStage:function(){var t=this.getParent();return t?t.getStage():void 0},fire:function(t,e,n){return e=e||{},e.target=e.target||this,n?this._fireAndBubble(t,e):this._fire(t,e),this},getAbsoluteTransform:function(t){return t?this._getAbsoluteTransform(t):this._getCache(n,this._getAbsoluteTransform)},_getAbsoluteTransform:function(e){var n,i,a=new t.Transform;return this._eachAncestorReverse(function(t){n=t.transformsEnabled(),i=t.getTransform(),"all"===n?a.multiply(i):"position"===n&&a.translate(t.x(),t.y())},e),a},getAbsoluteScale:function(t){return t?this._getAbsoluteTransform(t):this._getCache(i,this._getAbsoluteScale)},_getAbsoluteScale:function(t){for(var e=this;e;)e._isUnderCache&&(t=e),e=e.getParent();var n=1,i=1;return this._eachAncestorReverse(function(t){n*=t.scaleX(),i*=t.scaleY()},t),{x:n,y:i}},getTransform:function(){return this._getCache(y,this._getTransform)},_getTransform:function(){var e=new t.Transform,n=this.getX(),i=this.getY(),a=t.getAngle(this.getRotation()),r=this.getScaleX(),o=this.getScaleY(),s=this.getSkewX(),h=this.getSkewY(),c=this.getOffsetX(),l=this.getOffsetY();return 0===n&&0===i||e.translate(n,i),0!==a&&e.rotate(a),0===s&&0===h||e.skew(s,h),1===r&&1===o||e.scale(r,o),0===c&&0===l||e.translate(-1*c,-1*l),e},clone:function(e){var n,i,a,r,o,s=t.Util.cloneObject(this.attrs);for(var h in w){var c=w[h];delete s[c]}for(n in e)s[n]=e[n];var d=new this.constructor(s);for(n in this.eventListeners)for(i=this.eventListeners[n],a=i.length,r=0;r<a;r++)o=i[r],o.name.indexOf(l)<0&&(d.eventListeners[n]||(d.eventListeners[n]=[]),d.eventListeners[n].push(o));return d},_toKonvaCanvas:function(e){e=e||{};var n=this.getStage(),i=e.x||0,a=e.y||0,r=e.pixelRatio||1,o=new t.SceneCanvas({width:e.width||this.getWidth()||(n?n.getWidth():0),height:e.height||this.getHeight()||(n?n.getHeight():0),pixelRatio:r}),s=o.getContext();return s.save(),(i||a)&&s.translate(-1*i,-1*a),this.drawScene(o),s.restore(),o},toCanvas:function(t){return this._toKonvaCanvas(t)._canvas},toDataURL:function(t){t=t||{};var e=t.mimeType||null,n=t.quality||null;return this._toKonvaCanvas(t).toDataURL(e,n)},toImage:function(e){if(!e||!e.callback)throw"callback required for toImage method config argument";t.Util._getImage(this.toDataURL(e),function(t){e.callback(t)})},setSize:function(t){return this.setWidth(t.width),this.setHeight(t.height),this},getSize:function(){return{width:this.getWidth(),height:this.getHeight()}},getWidth:function(){return this.attrs.width||0},getHeight:function(){return this.attrs.height||0},getClassName:function(){return this.className||this.nodeType},getType:function(){return this.nodeType},getDragDistance:function(){return void 0!==this.attrs.dragDistance?this.attrs.dragDistance:this.parent?this.parent.getDragDistance():t.dragDistance},_get:function(t){return this.className===t||this.nodeType===t?[this]:[]},_off:function(t,e){var n,i,a=this.eventListeners[t];for(n=0;n<a.length;n++)if(i=a[n].name,!("konva"===i&&"konva"!==e||e&&i!==e)){if(a.splice(n,1),0===a.length){delete this.eventListeners[t];break}n--}},_fireChangeEvent:function(t,e,n){this._fire(t+a,{oldVal:e,newVal:n})},setId:function(e){var n=this.getId();return t._removeId(n),t._addId(this,e),this._setAttr(c,e),this},setName:function(e){var n,i,a=(this.getName()||"").split(/\s/g),r=(e||"").split(/\s/g);for(i=0;i<a.length;i++)n=a[i],r.indexOf(n)===-1&&n&&t._removeName(n,this._id);for(i=0;i<r.length;i++)n=r[i],a.indexOf(n)===-1&&n&&t._addName(this,n);return this._setAttr(v,e),this},addName:function(t){if(!this.hasName(t)){var e=this.name(),n=e?e+" "+t:t;this.setName(n)}return this},hasName:function(t){var e=(this.name()||"").split(/\s/g);return e.indexOf(t)!==-1},removeName:function(t){var e=(this.name()||"").split(/\s/g),n=e.indexOf(t);return n!==-1&&(e.splice(n,1),this.setName(e.join(" "))),this},setAttr:function(e,n){var i=g+t.Util._capitalize(e),a=this[i];return t.Util._isFunction(a)?a.call(this,n):this._setAttr(e,n),this},_setAttr:function(t,e){var n;n=this.attrs[t],n!==e&&(void 0===e||null===e?delete this.attrs[t]:this.attrs[t]=e,this._fireChangeEvent(t,n,e))},_setComponentAttr:function(t,e,n){var i;void 0!==n&&(i=this.attrs[t],i||(this.attrs[t]=this.getAttr(t)),this.attrs[t][e]=n,this._fireChangeEvent(t,i,n))},_fireAndBubble:function(t,e,n){var i=!0;if(e&&this.nodeType===p&&(e.target=this),t===u&&n&&(this._id===n._id||this.isAncestorOf&&this.isAncestorOf(n))?i=!1:t===f&&n&&(this._id===n._id||this.isAncestorOf&&this.isAncestorOf(n))&&(i=!1),i){this._fire(t,e);var a=(t===u||t===f)&&n&&n.isAncestorOf&&n.isAncestorOf(this)&&!n.isAncestorOf(this.parent);(e&&!e.cancelBubble||!e)&&this.parent&&this.parent.isListening()&&!a&&(n&&n.parent?this._fireAndBubble.call(this.parent,t,e,n.parent):this._fireAndBubble.call(this.parent,t,e))}},_fire:function(t,e){var n,i=this.eventListeners[t];if(e=e||{},e.currentTarget=this,e.type=t,i)for(n=0;n<i.length;n++)i[n].handler.call(this,e)},draw:function(){return this.drawScene(),this.drawHit(),this}}),t.Node.create=function(e,n){return t.Util._isString(e)&&(e=JSON.parse(e)),this._createNode(e,n)},t.Node._createNode=function(e,n){var i,a,r,o=t.Node.prototype.getClassName.call(e),s=e.children;if(n&&(e.attrs.container=n),i=new t[o](e.attrs),s)for(a=s.length,r=0;r<a;r++)i.add(this._createNode(s[r]));return i},t.Factory.addOverloadedGetterSetter(t.Node,"position"),t.Factory.addGetterSetter(t.Node,"x",0),t.Factory.addGetterSetter(t.Node,"y",0),t.Factory.addGetterSetter(t.Node,"opacity",1),t.Factory.addGetter(t.Node,"name"),t.Factory.addOverloadedGetterSetter(t.Node,"name"),t.Factory.addGetter(t.Node,"id"),t.Factory.addOverloadedGetterSetter(t.Node,"id"),t.Factory.addGetterSetter(t.Node,"rotation",0),t.Factory.addComponentsGetterSetter(t.Node,"scale",["x","y"]),t.Factory.addGetterSetter(t.Node,"scaleX",1),t.Factory.addGetterSetter(t.Node,"scaleY",1),t.Factory.addComponentsGetterSetter(t.Node,"skew",["x","y"]),t.Factory.addGetterSetter(t.Node,"skewX",0),t.Factory.addGetterSetter(t.Node,"skewY",0),t.Factory.addComponentsGetterSetter(t.Node,"offset",["x","y"]),t.Factory.addGetterSetter(t.Node,"offsetX",0),t.Factory.addGetterSetter(t.Node,"offsetY",0),t.Factory.addSetter(t.Node,"dragDistance"),t.Factory.addOverloadedGetterSetter(t.Node,"dragDistance"),t.Factory.addSetter(t.Node,"width",0),t.Factory.addOverloadedGetterSetter(t.Node,"width"),t.Factory.addSetter(t.Node,"height",0),t.Factory.addOverloadedGetterSetter(t.Node,"height"),t.Factory.addGetterSetter(t.Node,"listening","inherit"),t.Factory.addGetterSetter(t.Node,"preventDefault",!0),t.Factory.addGetterSetter(t.Node,"filters",void 0,function(t){return this._filterUpToDate=!1,t}),t.Factory.addGetterSetter(t.Node,"visible","inherit"),t.Factory.addGetterSetter(t.Node,"transformsEnabled","all"),t.Factory.addOverloadedGetterSetter(t.Node,"size"),t.Factory.backCompat(t.Node,{rotateDeg:"rotate",setRotationDeg:"setRotation",getRotationDeg:"getRotation"}),t.Collection.mapMethods(t.Node)}(Konva),function(){"use strict";Konva.Container=function(t){this.__init(t)},Konva.Util.addMethods(Konva.Container,{__init:function(t){this.children=new Konva.Collection,Konva.Node.call(this,t)},getChildren:function(t){if(!t)return this.children;var e=new Konva.Collection;return this.children.each(function(n){t(n)&&e.push(n)}),e},hasChildren:function(){return this.getChildren().length>0},removeChildren:function(){for(var t,e=Konva.Collection.toCollection(this.children),n=0;n<e.length;n++)t=e[n],delete t.parent,t.index=0,t.remove();return e=null,this.children=new Konva.Collection,this},destroyChildren:function(){for(var t,e=Konva.Collection.toCollection(this.children),n=0;n<e.length;n++)t=e[n],delete t.parent,t.index=0,t.destroy();return e=null,this.children=new Konva.Collection,this},add:function(t){if(arguments.length>1){for(var e=0;e<arguments.length;e++)this.add(arguments[e]);return this}if(t.getParent())return t.moveTo(this),this;var n=this.children;return this._validateAdd(t),t.index=n.length,t.parent=this,n.push(t),this._fire("add",{child:t}),Konva.DD&&t.isDragging()&&Konva.DD.anim.setLayers(t.getLayer()),this},destroy:function(){return this.hasChildren()&&this.destroyChildren(),Konva.Node.prototype.destroy.call(this),this},find:function(t){var e,n,i,a,r,o,s,h=[],c=t.replace(/ /g,"").split(","),l=c.length;for(e=0;e<l;e++)if(i=c[e],Konva.Util.isValidSelector(i)||(Konva.Util.warn('Selector "'+i+'" is invalid. Allowed selectors examples are "#foo", ".bar" or "Group".'),Konva.Util.warn('If you have a custom shape with such className, please change it to start with upper letter like "Triangle".'),Konva.Util.warn("Konva is awesome, right?")),"#"===i.charAt(0))r=this._getNodeById(i.slice(1)),r&&h.push(r);else if("."===i.charAt(0))a=this._getNodesByName(i.slice(1)),h=h.concat(a);else for(o=this.getChildren(),s=o.length,n=0;n<s;n++)h=h.concat(o[n]._get(i));return Konva.Collection.toCollection(h)},findOne:function(t){return this.find(t)[0]},_getNodeById:function(t){var e=Konva.ids[t];return void 0!==e&&this.isAncestorOf(e)?e:null},_getNodesByName:function(t){var e=Konva.names[t]||[];return this._getDescendants(e)},_get:function(t){for(var e=Konva.Node.prototype._get.call(this,t),n=this.getChildren(),i=n.length,a=0;a<i;a++)e=e.concat(n[a]._get(t));return e},toObject:function(){var t=Konva.Node.prototype.toObject.call(this);t.children=[];for(var e=this.getChildren(),n=e.length,i=0;i<n;i++){var a=e[i];t.children.push(a.toObject())}return t},_getDescendants:function(t){for(var e=[],n=t.length,i=0;i<n;i++){var a=t[i];this.isAncestorOf(a)&&e.push(a)}return e},isAncestorOf:function(t){for(var e=t.getParent();e;){if(e._id===this._id)return!0;e=e.getParent()}return!1},clone:function(t){var e=Konva.Node.prototype.clone.call(this,t);return this.getChildren().each(function(t){e.add(t.clone())}),e},getAllIntersections:function(t){var e=[];return this.find("Shape").each(function(n){n.isVisible()&&n.intersects(t)&&e.push(n)}),e},_setChildrenIndices:function(){this.children.each(function(t,e){t.index=e})},drawScene:function(t,e,n){var i=this.getLayer(),a=t||i&&i.getCanvas(),r=a&&a.getContext(),o=this._cache.canvas,s=o&&o.scene;return this.isVisible()&&(!n&&s?(r.save(),i._applyTransform(this,r,e),this._drawCachedSceneCanvas(r),r.restore()):this._drawChildren(a,"drawScene",e,!1,n)),this},drawHit:function(t,e,n){var i=this.getLayer(),a=t||i&&i.hitCanvas,r=a&&a.getContext(),o=this._cache.canvas,s=o&&o.hit;return this.shouldDrawHit(a)&&(i&&i.clearHitCache(),!n&&s?(r.save(),i._applyTransform(this,r,e),this._drawCachedHitCanvas(r),r.restore()):this._drawChildren(a,"drawHit",e)),this},_drawChildren:function(t,e,n,i,a){var r,o,s=this.getLayer(),h=t&&t.getContext(),c=this.getClipWidth(),l=this.getClipHeight(),d=this.getClipFunc(),u=c&&l||d;if(u&&s){h.save();var f=this.getAbsoluteTransform(n),v=f.getMatrix();h.transform(v[0],v[1],v[2],v[3],v[4],v[5]),h.beginPath(),d?d.call(this,h,this):(r=this.getClipX(),o=this.getClipY(),h.rect(r,o,c,l)),h.clip(),v=f.copy().invert().getMatrix(),h.transform(v[0],v[1],v[2],v[3],v[4],v[5])}this.children.each(function(r){r[e](t,n,i,a)}),u&&h.restore()},shouldDrawHit:function(t){var e=this.getLayer(),n=Konva.DD,i=n&&Konva.isDragging()&&Konva.DD.anim.getLayers().indexOf(e)!==-1;return t&&t.isCache||e&&e.hitGraphEnabled()&&this.isVisible()&&!i},getClientRect:function(t){var e,n,i,a,r={x:0,y:0,width:0,height:0};return this.children.each(function(t){var r=t.getClientRect();void 0===e?(e=r.x,n=r.y,i=r.x+r.width,a=r.y+r.height):(e=Math.min(e,r.x),n=Math.min(n,r.y),i=Math.max(i,r.x+r.width),a=Math.max(a,r.y+r.height))}),0!==this.children.length&&(r={x:e,y:n,width:i-e,height:a-n}),t?r:this._transformedRect(r)}}),Konva.Util.extend(Konva.Container,Konva.Node),Konva.Container.prototype.get=Konva.Container.prototype.find,Konva.Factory.addComponentsGetterSetter(Konva.Container,"clip",["x","y","width","height"]),Konva.Factory.addGetterSetter(Konva.Container,"clipX"),Konva.Factory.addGetterSetter(Konva.Container,"clipY"),Konva.Factory.addGetterSetter(Konva.Container,"clipWidth"),Konva.Factory.addGetterSetter(Konva.Container,"clipHeight"),Konva.Factory.addGetterSetter(Konva.Container,"clipFunc"),Konva.Collection.mapMethods(Konva.Container)}(),function(t){"use strict";function e(t){t.fill()}function n(t){t.stroke()}function i(t){t.fill()}function a(t){t.stroke()}function r(){this._clearCache(s)}function o(){this._clearCache(h)}var s="hasShadow",h="shadowRGBA";t.Shape=function(t){this.__init(t)},t.Util.addMethods(t.Shape,{__init:function(s){this.nodeType="Shape",this._fillFunc=e,this._strokeFunc=n,this._fillFuncHit=i,this._strokeFuncHit=a;for(var h,c=t.shapes;;)if(h=t.Util.getRandomColor(),h&&!(h in c))break;this.colorKey=h,c[h]=this,t.Node.call(this,s),this.on("shadowColorChange.konva shadowBlurChange.konva shadowOffsetChange.konva shadowOpacityChange.konva shadowEnabledChange.konva",r),this.on("shadowColorChange.konva shadowOpacityChange.konva shadowEnabledChange.konva",o)},hasChildren:function(){return!1},getChildren:function(){return[]},getContext:function(){return this.getLayer().getContext()},getCanvas:function(){return this.getLayer().getCanvas()},hasShadow:function(){return this._getCache(s,this._hasShadow)},_hasShadow:function(){return this.getShadowEnabled()&&0!==this.getShadowOpacity()&&!!(this.getShadowColor()||this.getShadowBlur()||this.getShadowOffsetX()||this.getShadowOffsetY())},getShadowRGBA:function(){return this._getCache(h,this._getShadowRGBA)},_getShadowRGBA:function(){if(this.hasShadow()){var e=t.Util.colorToRGBA(this.shadowColor());return"rgba("+e.r+","+e.g+","+e.b+","+e.a*(this.getShadowOpacity()||1)+")"}},hasFill:function(){return!!(this.getFill()||this.getFillPatternImage()||this.getFillLinearGradientColorStops()||this.getFillRadialGradientColorStops())},hasStroke:function(){return this.strokeEnabled()&&!!this.stroke()},intersects:function(t){var e,n=this.getStage(),i=n.bufferHitCanvas;return i.getContext().clear(),this.drawScene(i),e=i.context.getImageData(Math.round(t.x),Math.round(t.y),1,1).data,e[3]>0},destroy:function(){return t.Node.prototype.destroy.call(this),delete t.shapes[this.colorKey],this},_useBufferCanvas:function(t){return!t&&this.perfectDrawEnabled()&&1!==this.getAbsoluteOpacity()&&this.hasFill()&&this.hasStroke()&&this.getStage()||this.perfectDrawEnabled()&&this.hasShadow()&&1!==this.getAbsoluteOpacity()&&this.hasFill()&&this.hasStroke()&&this.getStage()},getSelfRect:function(){var t=this.getSize();return{x:this._centroid?Math.round(-t.width/2):0,y:this._centroid?Math.round(-t.height/2):0,width:t.width,height:t.height}},getClientRect:function(t){var e=this.getSelfRect(),n=this.hasStroke()&&this.strokeWidth()||0,i=e.width+n,a=e.height+n,r=this.hasShadow()?this.shadowOffsetX():0,o=this.hasShadow()?this.shadowOffsetY():0,s=i+Math.abs(r),h=a+Math.abs(o),c=this.hasShadow()&&this.shadowBlur()||0,l=s+2*c,d=h+2*c,u=0;Math.round(n/2)!==n/2&&(u=1);var f={width:l+u,height:d+u,x:-Math.round(n/2+c)+Math.min(r,0)+e.x,y:-Math.round(n/2+c)+Math.min(o,0)+e.y};return t?f:this._transformedRect(f)},drawScene:function(t,e,n,i){var a,r,o,s=this.getLayer(),h=t||s.getCanvas(),c=h.getContext(),l=this._cache.canvas,d=this.sceneFunc(),u=this.hasShadow(),f=this.hasStroke();if(!this.isVisible())return this;if(l)return c.save(),s._applyTransform(this,c,e),this._drawCachedSceneCanvas(c),c.restore(),this;if(!d)return this;if(c.save(),this._useBufferCanvas(n)&&!i){if(a=this.getStage(),r=a.bufferCanvas,o=r.getContext(),o.clear(),o.save(),o._applyLineJoin(this),!n)if(s)s._applyTransform(this,o,e);else{var v=this.getAbsoluteTransform(e).getMatrix();c.transform(v[0],v[1],v[2],v[3],v[4],v[5])}d.call(this,o),o.restore();var g=r.pixelRatio;u&&!h.hitCanvas?(c.save(),c._applyShadow(this),c._applyOpacity(this),c.drawImage(r._canvas,0,0,r.width/g,r.height/g),c.restore()):(c._applyOpacity(this),c.drawImage(r._canvas,0,0,r.width/g,r.height/g))}else{if(c._applyLineJoin(this),!n)if(s)s._applyTransform(this,c,e);else{var p=this.getAbsoluteTransform(e).getMatrix();c.transform(p[0],p[1],p[2],p[3],p[4],p[5])}u&&f&&!h.hitCanvas?(c.save(),n||c._applyOpacity(this),c._applyShadow(this),d.call(this,c),c.restore(),this.hasFill()&&this.getShadowForStrokeEnabled()&&d.call(this,c)):u&&!h.hitCanvas?(c.save(),n||c._applyOpacity(this),c._applyShadow(this),d.call(this,c),c.restore()):(n||c._applyOpacity(this),d.call(this,c))}return c.restore(),this},drawHit:function(t,e,n){var i=this.getLayer(),a=t||i.hitCanvas,r=a.getContext(),o=this.hitFunc()||this.sceneFunc(),s=this._cache.canvas,h=s&&s.hit;if(!this.shouldDrawHit(a))return this;if(i&&i.clearHitCache(),h)return r.save(),i._applyTransform(this,r,e),this._drawCachedHitCanvas(r),r.restore(),this;if(!o)return this;if(r.save(),r._applyLineJoin(this),!n)if(i)i._applyTransform(this,r,e);else{var c=this.getAbsoluteTransform(e).getMatrix();r.transform(c[0],c[1],c[2],c[3],c[4],c[5])}return o.call(this,r),r.restore(),this},drawHitFromCache:function(e){var n,i,a,r,o,s,h=e||0,c=this._cache.canvas,l=this._getCachedSceneCanvas(),d=c.hit,u=d.getContext(),f=d.getWidth(),v=d.getHeight();u.clear(),u.drawImage(l._canvas,0,0,f,v);try{for(n=u.getImageData(0,0,f,v),i=n.data,a=i.length,r=t.Util._hexToRgb(this.colorKey),o=0;o<a;o+=4)s=i[o+3],s>h?(i[o]=r.r,i[o+1]=r.g,i[o+2]=r.b,i[o+3]=255):i[o+3]=0;u.putImageData(n,0,0)}catch(e){t.Util.error("Unable to draw hit graph from cached scene canvas. "+e.message)}return this}}),t.Util.extend(t.Shape,t.Node),t.Factory.addGetterSetter(t.Shape,"stroke"),t.Factory.addDeprecatedGetterSetter(t.Shape,"strokeRed",0,t.Validators.RGBComponent),t.Factory.addDeprecatedGetterSetter(t.Shape,"strokeGreen",0,t.Validators.RGBComponent),t.Factory.addDeprecatedGetterSetter(t.Shape,"strokeBlue",0,t.Validators.RGBComponent),t.Factory.addDeprecatedGetterSetter(t.Shape,"strokeAlpha",1,t.Validators.alphaComponent),t.Factory.addGetterSetter(t.Shape,"strokeWidth",2),t.Factory.addGetterSetter(t.Shape,"strokeHitEnabled",!0),t.Factory.addGetterSetter(t.Shape,"perfectDrawEnabled",!0),t.Factory.addGetterSetter(t.Shape,"shadowForStrokeEnabled",!0),t.Factory.addGetterSetter(t.Shape,"lineJoin"),t.Factory.addGetterSetter(t.Shape,"lineCap"),t.Factory.addGetterSetter(t.Shape,"sceneFunc"),t.Factory.addGetterSetter(t.Shape,"hitFunc"),t.Factory.addGetterSetter(t.Shape,"dash"),t.Factory.addGetterSetter(t.Shape,"shadowColor"),t.Factory.addDeprecatedGetterSetter(t.Shape,"shadowRed",0,t.Validators.RGBComponent),t.Factory.addDeprecatedGetterSetter(t.Shape,"shadowGreen",0,t.Validators.RGBComponent),t.Factory.addDeprecatedGetterSetter(t.Shape,"shadowBlue",0,t.Validators.RGBComponent),t.Factory.addDeprecatedGetterSetter(t.Shape,"shadowAlpha",1,t.Validators.alphaComponent),t.Factory.addGetterSetter(t.Shape,"shadowBlur"),t.Factory.addGetterSetter(t.Shape,"shadowOpacity"),t.Factory.addComponentsGetterSetter(t.Shape,"shadowOffset",["x","y"]),t.Factory.addGetterSetter(t.Shape,"shadowOffsetX",0),t.Factory.addGetterSetter(t.Shape,"shadowOffsetY",0),t.Factory.addGetterSetter(t.Shape,"fillPatternImage"),t.Factory.addGetterSetter(t.Shape,"fill"),t.Factory.addDeprecatedGetterSetter(t.Shape,"fillRed",0,t.Validators.RGBComponent),t.Factory.addDeprecatedGetterSetter(t.Shape,"fillGreen",0,t.Validators.RGBComponent),t.Factory.addDeprecatedGetterSetter(t.Shape,"fillBlue",0,t.Validators.RGBComponent),t.Factory.addDeprecatedGetterSetter(t.Shape,"fillAlpha",1,t.Validators.alphaComponent),t.Factory.addGetterSetter(t.Shape,"fillPatternX",0),t.Factory.addGetterSetter(t.Shape,"fillPatternY",0),t.Factory.addGetterSetter(t.Shape,"fillLinearGradientColorStops"),t.Factory.addGetterSetter(t.Shape,"fillRadialGradientStartRadius",0),t.Factory.addGetterSetter(t.Shape,"fillRadialGradientEndRadius",0),t.Factory.addGetterSetter(t.Shape,"fillRadialGradientColorStops"),t.Factory.addGetterSetter(t.Shape,"fillPatternRepeat","repeat"),t.Factory.addGetterSetter(t.Shape,"fillEnabled",!0),t.Factory.addGetterSetter(t.Shape,"strokeEnabled",!0),t.Factory.addGetterSetter(t.Shape,"shadowEnabled",!0),t.Factory.addGetterSetter(t.Shape,"dashEnabled",!0),t.Factory.addGetterSetter(t.Shape,"strokeScaleEnabled",!0),t.Factory.addGetterSetter(t.Shape,"fillPriority","color"),t.Factory.addComponentsGetterSetter(t.Shape,"fillPatternOffset",["x","y"]),t.Factory.addGetterSetter(t.Shape,"fillPatternOffsetX",0),t.Factory.addGetterSetter(t.Shape,"fillPatternOffsetY",0),t.Factory.addComponentsGetterSetter(t.Shape,"fillPatternScale",["x","y"]),t.Factory.addGetterSetter(t.Shape,"fillPatternScaleX",1),t.Factory.addGetterSetter(t.Shape,"fillPatternScaleY",1),t.Factory.addComponentsGetterSetter(t.Shape,"fillLinearGradientStartPoint",["x","y"]),t.Factory.addGetterSetter(t.Shape,"fillLinearGradientStartPointX",0),t.Factory.addGetterSetter(t.Shape,"fillLinearGradientStartPointY",0),t.Factory.addComponentsGetterSetter(t.Shape,"fillLinearGradientEndPoint",["x","y"]),t.Factory.addGetterSetter(t.Shape,"fillLinearGradientEndPointX",0),t.Factory.addGetterSetter(t.Shape,"fillLinearGradientEndPointY",0),t.Factory.addComponentsGetterSetter(t.Shape,"fillRadialGradientStartPoint",["x","y"]),t.Factory.addGetterSetter(t.Shape,"fillRadialGradientStartPointX",0),t.Factory.addGetterSetter(t.Shape,"fillRadialGradientStartPointY",0),t.Factory.addComponentsGetterSetter(t.Shape,"fillRadialGradientEndPoint",["x","y"]),t.Factory.addGetterSetter(t.Shape,"fillRadialGradientEndPointX",0),t.Factory.addGetterSetter(t.Shape,"fillRadialGradientEndPointY",0),t.Factory.addGetterSetter(t.Shape,"fillPatternRotation",0),t.Factory.backCompat(t.Shape,{dashArray:"dash",getDashArray:"getDash",setDashArray:"getDash",drawFunc:"sceneFunc",getDrawFunc:"getSceneFunc",setDrawFunc:"setSceneFunc",drawHitFunc:"hitFunc",getDrawHitFunc:"getHitFunc",setDrawHitFunc:"setHitFunc"}),t.Collection.mapMethods(t.Shape)}(Konva),function(){"use strict";function t(t,e){t.content.addEventListener(e,function(n){t[B+e](n)},!1)}var e="Stage",n="string",i="px",a="mouseout",r="mouseleave",o="mouseover",s="mouseenter",h="mousemove",c="mousedown",l="mouseup",d="contextmenu",u="click",f="dblclick",v="touchstart",g="touchend",p="tap",m="dbltap",_="touchmove",y="DOMMouseScroll",C="mousewheel",S="wheel",w="contentMouseout",K="contentMouseover",b="contentMousemove",x="contentMousedown",D="contentMouseup",A="contentContextmenu",F="contentClick",T="contentDblclick",k="contentTouchstart",P="contentTouchend",G="contentDbltap",R="contentTap",L="contentTouchmove",O="contentWheel",U="div",I="relative",M="konvajs-content",N=" ",B="_",E="container",H="",W=[c,h,l,a,v,_,g,o,y,C,S,d],Y=W.length;Konva.Stage=function(t){this.___init(t)},Konva.Util.addMethods(Konva.Stage,{___init:function(t){this.nodeType=e,Konva.Container.call(this,t),this._id=Konva.idCounter++,this._buildDOM(),this._bindContentEvents(),this._enableNestedTransforms=!1,Konva.stages.push(this)},_validateAdd:function(t){"Layer"!==t.getType()&&Konva.Util.throw("You may only add layers to the stage.")},setContainer:function(t){if(typeof t===n){if("."===t.charAt(0)){var e=t.slice(1);t=Konva.document.getElementsByClassName(e)[0]}else{var i;i="#"!==t.charAt(0)?t:t.slice(1),t=Konva.document.getElementById(i)}if(!t)throw"Can not find container in document with id "+i}return this._setAttr(E,t),this},shouldDrawHit:function(){return!0},draw:function(){return Konva.Node.prototype.draw.call(this),this},setHeight:function(t){return Konva.Node.prototype.setHeight.call(this,t),this._resizeDOM(),this},setWidth:function(t){return Konva.Node.prototype.setWidth.call(this,t),this._resizeDOM(),this},clear:function(){var t,e=this.children,n=e.length;for(t=0;t<n;t++)e[t].clear();return this},clone:function(t){return t||(t={}),t.container=Konva.document.createElement(U),Konva.Container.prototype.clone.call(this,t)},destroy:function(){var t=this.content;Konva.Container.prototype.destroy.call(this),t&&Konva.Util._isInDocument(t)&&this.getContainer().removeChild(t);var e=Konva.stages.indexOf(this);return e>-1&&Konva.stages.splice(e,1),this},getPointerPosition:function(){return this.pointerPos},getStage:function(){return this},getContent:function(){return this.content},toDataURL:function(t){t=t||{};var e=t.mimeType||null,n=t.quality||null,i=t.x||0,a=t.y||0,r=new Konva.SceneCanvas({width:t.width||this.getWidth(),height:t.height||this.getHeight(),pixelRatio:t.pixelRatio}),o=r.getContext()._context,s=this.children;(i||a)&&o.translate(-1*i,-1*a),s.each(function(t){var e=t.getCanvas().getWidth(),n=t.getCanvas().getHeight(),i=t.getCanvas().getPixelRatio();o.drawImage(t.getCanvas()._canvas,0,0,e/i,n/i)});var h=r.toDataURL(e,n);return t.callback&&t.callback(h),h},toImage:function(t){var e=t.callback;t.callback=function(t){Konva.Util._getImage(t,function(t){e(t)})},this.toDataURL(t)},getIntersection:function(t,e){var n,i,a=this.getChildren(),r=a.length,o=r-1;for(n=o;n>=0;n--)if(i=a[n].getIntersection(t,e))return i;return null},_resizeDOM:function(){if(this.content){var t,e,n=this.getWidth(),a=this.getHeight(),r=this.getChildren(),o=r.length;for(this.content.style.width=n+i,this.content.style.height=a+i,this.bufferCanvas.setSize(n,a),this.bufferHitCanvas.setSize(n,a),t=0;t<o;t++)e=r[t],e.setSize(n,a),e.batchDraw()}},add:function(t){if(arguments.length>1){for(var e=0;e<arguments.length;e++)this.add(arguments[e]);return this}return Konva.Container.prototype.add.call(this,t),t._setCanvasSize(this.width(),this.height()),t.draw(),this.content.appendChild(t.canvas._canvas),this},getParent:function(){return null},getLayer:function(){return null},getLayers:function(){return this.getChildren()},_bindContentEvents:function(){for(var e=0;e<Y;e++)t(this,W[e])},_mouseover:function(t){Konva.UA.mobile||(this._setPointerPosition(t),this._fire(K,{evt:t}))},_mouseout:function(t){if(!Konva.UA.mobile){this._setPointerPosition(t);var e=this.targetShape;e&&!Konva.isDragging()&&(e._fireAndBubble(a,{
evt:t}),e._fireAndBubble(r,{evt:t}),this.targetShape=null),this.pointerPos=void 0,this._fire(w,{evt:t})}},_mousemove:function(t){if(Konva.UA.ieMobile)return this._touchmove(t);if(("undefined"!=typeof t.movementX||"undefined"!=typeof t.movementY)&&0===t.movementY&&0===t.movementX)return null;if(Konva.UA.mobile)return null;this._setPointerPosition(t);var e;Konva.isDragging()||(e=this.getIntersection(this.getPointerPosition()),e&&e.isListening()?Konva.isDragging()||this.targetShape&&this.targetShape._id===e._id?e._fireAndBubble(h,{evt:t}):(this.targetShape&&(this.targetShape._fireAndBubble(a,{evt:t},e),this.targetShape._fireAndBubble(r,{evt:t},e)),e._fireAndBubble(o,{evt:t},this.targetShape),e._fireAndBubble(s,{evt:t},this.targetShape),this.targetShape=e):this.targetShape&&!Konva.isDragging()&&(this.targetShape._fireAndBubble(a,{evt:t}),this.targetShape._fireAndBubble(r,{evt:t}),this.targetShape=null),this._fire(b,{evt:t})),t.preventDefault&&t.preventDefault()},_mousedown:function(t){if(Konva.UA.ieMobile)return this._touchstart(t);if(!Konva.UA.mobile){this._setPointerPosition(t);var e=this.getIntersection(this.getPointerPosition());Konva.listenClickTap=!0,e&&e.isListening()&&(this.clickStartShape=e,e._fireAndBubble(c,{evt:t})),this._fire(x,{evt:t})}t.preventDefault&&t.preventDefault()},_mouseup:function(t){if(Konva.UA.ieMobile)return this._touchend(t);if(!Konva.UA.mobile){this._setPointerPosition(t);var e=this.getIntersection(this.getPointerPosition()),n=this.clickStartShape,i=!1,a=Konva.DD;Konva.inDblClickWindow?(i=!0,Konva.inDblClickWindow=!1):a&&a.justDragged?a&&(a.justDragged=!1):Konva.inDblClickWindow=!0,setTimeout(function(){Konva.inDblClickWindow=!1},Konva.dblClickWindow),e&&e.isListening()&&(e._fireAndBubble(l,{evt:t}),Konva.listenClickTap&&n&&n._id===e._id&&(e._fireAndBubble(u,{evt:t}),i&&e._fireAndBubble(f,{evt:t}))),this._fire(D,{evt:t}),Konva.listenClickTap&&(this._fire(F,{evt:t}),i&&this._fire(T,{evt:t})),Konva.listenClickTap=!1}t.preventDefault&&t.preventDefault()},_contextmenu:function(t){this._fire(A,{evt:t})},_touchstart:function(t){this._setPointerPosition(t);var e=this.getIntersection(this.getPointerPosition());Konva.listenClickTap=!0,e&&e.isListening()&&(this.tapStartShape=e,e._fireAndBubble(v,{evt:t}),e.isListening()&&e.preventDefault()&&t.preventDefault&&t.preventDefault()),this._fire(k,{evt:t})},_touchend:function(t){this._setPointerPosition(t);var e=this.getIntersection(this.getPointerPosition()),n=!1;Konva.inDblClickWindow?(n=!0,Konva.inDblClickWindow=!1):Konva.inDblClickWindow=!0,setTimeout(function(){Konva.inDblClickWindow=!1},Konva.dblClickWindow),e&&e.isListening()&&(e._fireAndBubble(g,{evt:t}),Konva.listenClickTap&&this.tapStartShape&&e._id===this.tapStartShape._id&&(e._fireAndBubble(p,{evt:t}),n&&e._fireAndBubble(m,{evt:t})),e.isListening()&&e.preventDefault()&&t.preventDefault&&t.preventDefault()),this._fire(P,{evt:t}),Konva.listenClickTap&&(this._fire(R,{evt:t}),n&&this._fire(G,{evt:t})),Konva.listenClickTap=!1},_touchmove:function(t){this._setPointerPosition(t);var e,n=Konva.DD;Konva.isDragging()||(e=this.getIntersection(this.getPointerPosition()),e&&e.isListening()&&(e._fireAndBubble(_,{evt:t}),e.isListening()&&e.preventDefault()&&t.preventDefault&&t.preventDefault()),this._fire(L,{evt:t})),n&&Konva.isDragging()&&Konva.DD.node.preventDefault()&&t.preventDefault()},_DOMMouseScroll:function(t){this._mousewheel(t)},_mousewheel:function(t){this._setPointerPosition(t);var e=this.getIntersection(this.getPointerPosition());e&&e.isListening()&&e._fireAndBubble(S,{evt:t}),this._fire(O,{evt:t})},_wheel:function(t){this._mousewheel(t)},_setPointerPosition:function(t){var e=this._getContentPosition(),n=null,i=null;if(t=t?t:window.event,void 0!==t.touches){if(t.touches.length>0){var a=t.touches[0];n=a.clientX-e.left,i=a.clientY-e.top}}else n=t.clientX-e.left,i=t.clientY-e.top;null!==n&&null!==i&&(this.pointerPos={x:n,y:i})},_getContentPosition:function(){var t=this.content.getBoundingClientRect?this.content.getBoundingClientRect():{top:0,left:0};return{top:t.top,left:t.left}},_buildDOM:function(){var t=this.getContainer();if(!t){if(Konva.Util.isBrowser())throw"Stage has no container. A container is required.";t=Konva.document.createElement(U)}t.innerHTML=H,this.content=Konva.document.createElement(U),this.content.style.position=I,this.content.className=M,this.content.setAttribute("role","presentation"),t.appendChild(this.content),this.bufferCanvas=new Konva.SceneCanvas,this.bufferHitCanvas=new Konva.HitCanvas({pixelRatio:1}),this._resizeDOM()},_onContent:function(t,e){var n,i,a=t.split(N),r=a.length;for(n=0;n<r;n++)i=a[n],this.content.addEventListener(i,e,!1)},cache:function(){Konva.Util.warn("Cache function is not allowed for stage. You may use cache only for layers, groups and shapes.")},clearCache:function(){}}),Konva.Util.extend(Konva.Stage,Konva.Container),Konva.Factory.addGetter(Konva.Stage,"container"),Konva.Factory.addOverloadedGetterSetter(Konva.Stage,"container")}(),function(){"use strict";Konva.BaseLayer=function(t){this.___init(t)},Konva.Util.addMethods(Konva.BaseLayer,{___init:function(t){this.nodeType="Layer",Konva.Container.call(this,t)},createPNGStream:function(){return this.canvas._canvas.createPNGStream()},getCanvas:function(){return this.canvas},getHitCanvas:function(){return this.hitCanvas},getContext:function(){return this.getCanvas().getContext()},clear:function(t){return this.getContext().clear(t),this},clearHitCache:function(){this._hitImageData=void 0},setZIndex:function(t){Konva.Node.prototype.setZIndex.call(this,t);var e=this.getStage();return e&&(e.content.removeChild(this.getCanvas()._canvas),t<e.getChildren().length-1?e.content.insertBefore(this.getCanvas()._canvas,e.getChildren()[t+1].getCanvas()._canvas):e.content.appendChild(this.getCanvas()._canvas)),this},moveToTop:function(){Konva.Node.prototype.moveToTop.call(this);var t=this.getStage();return t&&(t.content.removeChild(this.getCanvas()._canvas),t.content.appendChild(this.getCanvas()._canvas)),this},moveUp:function(){var t=Konva.Node.prototype.moveUp.call(this);if(!t)return this;var e=this.getStage();return e?(e.content.removeChild(this.getCanvas()._canvas),this.index<e.getChildren().length-1?e.content.insertBefore(this.getCanvas()._canvas,e.getChildren()[this.index+1].getCanvas()._canvas):e.content.appendChild(this.getCanvas()._canvas),this):this},moveDown:function(){if(Konva.Node.prototype.moveDown.call(this)){var t=this.getStage();if(t){var e=t.getChildren();t.content.removeChild(this.getCanvas()._canvas),t.content.insertBefore(this.getCanvas()._canvas,e[this.index+1].getCanvas()._canvas)}}return this},moveToBottom:function(){if(Konva.Node.prototype.moveToBottom.call(this)){var t=this.getStage();if(t){var e=t.getChildren();t.content.removeChild(this.getCanvas()._canvas),t.content.insertBefore(this.getCanvas()._canvas,e[1].getCanvas()._canvas)}}return this},getLayer:function(){return this},remove:function(){var t=this.getCanvas()._canvas;return Konva.Node.prototype.remove.call(this),t&&t.parentNode&&Konva.Util._isInDocument(t)&&t.parentNode.removeChild(t),this},getStage:function(){return this.parent},setSize:function(t,e){return this.canvas.setSize(t,e),this},getWidth:function(){if(this.parent)return this.parent.getWidth()},setWidth:function(){Konva.Util.warn('Can not change width of layer. Use "stage.width(value)" function instead.')},getHeight:function(){if(this.parent)return this.parent.getHeight()},setHeight:function(){Konva.Util.warn('Can not change height of layer. Use "stage.height(value)" function instead.')},_applyTransform:function(t,e,n){var i=t.getAbsoluteTransform(n).getMatrix();e.transform(i[0],i[1],i[2],i[3],i[4],i[5])}}),Konva.Util.extend(Konva.BaseLayer,Konva.Container),Konva.Factory.addGetterSetter(Konva.BaseLayer,"clearBeforeDraw",!0),Konva.Collection.mapMethods(Konva.BaseLayer)}(),function(){"use strict";var t="#",e="beforeDraw",n="draw",i=[{x:0,y:0},{x:-1,y:0},{x:-1,y:-1},{x:0,y:-1},{x:1,y:-1},{x:1,y:0},{x:1,y:1},{x:0,y:1},{x:-1,y:1}],a=i.length;Konva.Layer=function(t){this.____init(t)},Konva.Util.addMethods(Konva.Layer,{____init:function(t){this.nodeType="Layer",this.canvas=new Konva.SceneCanvas,this.hitCanvas=new Konva.HitCanvas({pixelRatio:1}),Konva.BaseLayer.call(this,t)},_setCanvasSize:function(t,e){this.canvas.setSize(t,e),this.hitCanvas.setSize(t,e)},_validateAdd:function(t){var e=t.getType();"Group"!==e&&"Shape"!==e&&Konva.Util.throw("You may only add groups and shapes to a layer.")},getIntersection:function(t,e){var n,r,o,s;if(!this.hitGraphEnabled()||!this.isVisible())return null;for(var h=1,c=!1;;){for(r=0;r<a;r++){if(o=i[r],n=this._getIntersection({x:t.x+o.x*h,y:t.y+o.y*h}),s=n.shape,s&&e)return s.findAncestor(e,!0);if(s)return s;if(c=!!n.antialiased,!n.antialiased)break}if(!c)return null;h+=1}},_getImageData:function(t,e){var n=this.hitCanvas.width||1,i=this.hitCanvas.height||1,a=Math.round(e)*n+Math.round(t);return this._hitImageData||(this._hitImageData=this.hitCanvas.context.getImageData(0,0,n,i)),[this._hitImageData.data[4*a+0],this._hitImageData.data[4*a+1],this._hitImageData.data[4*a+2],this._hitImageData.data[4*a+3]]},_getIntersection:function(e){var n,i,a=this.hitCanvas.pixelRatio,r=this.hitCanvas.context.getImageData(Math.round(e.x*a),Math.round(e.y*a),1,1).data,o=r[3];return 255===o?(n=Konva.Util._rgbToHex(r[0],r[1],r[2]),i=Konva.shapes[t+n],i?{shape:i}:{antialiased:!0}):o>0?{antialiased:!0}:{}},drawScene:function(t,i){var a=this.getLayer(),r=t||a&&a.getCanvas();return this._fire(e,{node:this}),this.getClearBeforeDraw()&&r.getContext().clear(),Konva.Container.prototype.drawScene.call(this,r,i),this._fire(n,{node:this}),this},drawHit:function(t,e){var n=this.getLayer(),i=t||n&&n.hitCanvas;return n&&n.getClearBeforeDraw()&&n.getHitCanvas().getContext().clear(),Konva.Container.prototype.drawHit.call(this,i,e),this.imageData=null,this},clear:function(t){return Konva.BaseLayer.prototype.clear.call(this,t),this.getHitCanvas().getContext().clear(t),this.imageData=null,this},setVisible:function(t){return Konva.Node.prototype.setVisible.call(this,t),t?(this.getCanvas()._canvas.style.display="block",this.hitCanvas._canvas.style.display="block"):(this.getCanvas()._canvas.style.display="none",this.hitCanvas._canvas.style.display="none"),this},enableHitGraph:function(){return this.setHitGraphEnabled(!0),this},disableHitGraph:function(){return this.setHitGraphEnabled(!1),this},setSize:function(t,e){return Konva.BaseLayer.prototype.setSize.call(this,t,e),this.hitCanvas.setSize(t,e),this}}),Konva.Util.extend(Konva.Layer,Konva.BaseLayer),Konva.Factory.addGetterSetter(Konva.Layer,"hitGraphEnabled",!0),Konva.Collection.mapMethods(Konva.Layer)}(),function(){"use strict";Konva.FastLayer=function(t){this.____init(t)},Konva.Util.addMethods(Konva.FastLayer,{____init:function(t){this.nodeType="Layer",this.canvas=new Konva.SceneCanvas,Konva.BaseLayer.call(this,t)},_validateAdd:function(t){var e=t.getType();"Shape"!==e&&Konva.Util.throw("You may only add shapes to a fast layer.")},_setCanvasSize:function(t,e){this.canvas.setSize(t,e)},hitGraphEnabled:function(){return!1},getIntersection:function(){return null},drawScene:function(t){var e=this.getLayer(),n=t||e&&e.getCanvas();return this.getClearBeforeDraw()&&n.getContext().clear(),Konva.Container.prototype.drawScene.call(this,n),this},draw:function(){return this.drawScene(),this},setVisible:function(t){return Konva.Node.prototype.setVisible.call(this,t),t?this.getCanvas()._canvas.style.display="block":this.getCanvas()._canvas.style.display="none",this}}),Konva.Util.extend(Konva.FastLayer,Konva.BaseLayer),Konva.Collection.mapMethods(Konva.FastLayer)}(),function(){"use strict";Konva.Group=function(t){this.___init(t)},Konva.Util.addMethods(Konva.Group,{___init:function(t){this.nodeType="Group",Konva.Container.call(this,t)},_validateAdd:function(t){var e=t.getType();"Group"!==e&&"Shape"!==e&&Konva.Util.throw("You may only add groups and shapes to groups.")}}),Konva.Util.extend(Konva.Group,Konva.Container),Konva.Collection.mapMethods(Konva.Group)}(),function(t){"use strict";function e(t){setTimeout(t,1e3/60)}function n(){return a.apply(t.global,arguments)}var i=function(){return t.global.performance&&t.global.performance.now?function(){return t.global.performance.now()}:function(){return(new Date).getTime()}}(),a=function(){return t.global.requestAnimationFrame||t.global.webkitRequestAnimationFrame||t.global.mozRequestAnimationFrame||t.global.oRequestAnimationFrame||t.global.msRequestAnimationFrame||e}();t.Animation=function(e,n){var a=t.Animation;this.func=e,this.setLayers(n),this.id=a.animIdCounter++,this.frame={time:0,timeDiff:0,lastTime:i()}},t.Animation.prototype={setLayers:function(t){var e=[];return e=t?t.length>0?t:[t]:[],this.layers=e,this},getLayers:function(){return this.layers},addLayer:function(t){var e,n=this.layers,i=n.length;for(e=0;e<i;e++)if(n[e]._id===t._id)return!1;return this.layers.push(t),!0},isRunning:function(){var e,n=t.Animation,i=n.animations,a=i.length;for(e=0;e<a;e++)if(i[e].id===this.id)return!0;return!1},start:function(){var e=t.Animation;return this.stop(),this.frame.timeDiff=0,this.frame.lastTime=i(),e._addAnimation(this),this},stop:function(){return t.Animation._removeAnimation(this),this},_updateFrameObject:function(t){this.frame.timeDiff=t-this.frame.lastTime,this.frame.lastTime=t,this.frame.time+=this.frame.timeDiff,this.frame.frameRate=1e3/this.frame.timeDiff}},t.Animation.animations=[],t.Animation.animIdCounter=0,t.Animation.animRunning=!1,t.Animation._addAnimation=function(t){this.animations.push(t),this._handleAnimation()},t.Animation._removeAnimation=function(t){var e,n=t.id,i=this.animations,a=i.length;for(e=0;e<a;e++)if(i[e].id===n){this.animations.splice(e,1);break}},t.Animation._runFrames=function(){var t,e,n,a,r,o,s,h,c,l={},d=this.animations;for(a=0;a<d.length;a++)if(t=d[a],e=t.layers,n=t.func,t._updateFrameObject(i()),o=e.length,c=!n||n.call(t,t.frame)!==!1)for(r=0;r<o;r++)s=e[r],void 0!==s._id&&(l[s._id]=s);for(h in l)l.hasOwnProperty(h)&&l[h].draw()},t.Animation._animationLoop=function(){var e=t.Animation;e.animations.length?(e._runFrames(),n(e._animationLoop)):e.animRunning=!1},t.Animation._handleAnimation=function(){this.animRunning||(this.animRunning=!0,n(this._animationLoop))},t.BaseLayer.prototype.batchDraw=function(){var e=this,n=t.Animation;return this.batchAnim||(this.batchAnim=new n(function(){e.batchAnim.stop()},this)),this.lastBatchDrawTime=i(),this.batchAnim.isRunning()||this.batchAnim.start(),this},t.Stage.prototype.batchDraw=function(){return this.getChildren().each(function(t){t.batchDraw()}),this}}(Konva),function(){"use strict";var t={node:1,duration:1,easing:1,onFinish:1,yoyo:1},e=1,n=2,i=3,a=0,r=["fill","stroke","shadowColor"],o=function(t,e,n,i,a,r,o){this.prop=t,this.propFunc=e,this.begin=i,this._pos=i,this.duration=r,this._change=0,this.prevPos=0,this.yoyo=o,this._time=0,this._position=0,this._startTime=0,this._finish=0,this.func=n,this._change=a-this.begin,this.pause()};o.prototype={fire:function(t){var e=this[t];e&&e()},setTime:function(t){t>this.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())},getTime:function(){return this._time},setPosition:function(t){this.prevPos=this._pos,this.propFunc(t),this._pos=t},getPosition:function(t){return void 0===t&&(t=this._time),this.func(t,this.begin,this._change,this.duration)},play:function(){this.state=n,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire("onPlay")},reverse:function(){this.state=i,this._time=this.duration-this._time,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire("onReverse")},seek:function(t){this.pause(),this._time=t,this.update(),this.fire("onSeek")},reset:function(){this.pause(),this._time=0,this.update(),this.fire("onReset")},finish:function(){this.pause(),this._time=this.duration,this.update(),this.fire("onFinish")},update:function(){this.setPosition(this.getPosition(this._time))},onEnterFrame:function(){var t=this.getTimer()-this._startTime;this.state===n?this.setTime(t):this.state===i&&this.setTime(this.duration-t)},pause:function(){this.state=e,this.fire("onPause")},getTimer:function(){return(new Date).getTime()}},Konva.Tween=function(e){var n,i,r=this,s=e.node,h=s._id,c=e.easing||Konva.Easings.Linear,l=!!e.yoyo;n="undefined"==typeof e.duration?1:0===e.duration?.001:e.duration,this.node=s,this._id=a++;var d=s.getLayer()||(s instanceof Konva.Stage?s.getLayers():null);d||Konva.Util.error("Tween constructor have `node` that is not in a layer. Please add node into layer first."),this.anim=new Konva.Animation(function(){r.tween.onEnterFrame()},d),this.tween=new o(i,function(t){r._tweenFunc(t)},c,0,1,1e3*n,l),this._addListeners(),Konva.Tween.attrs[h]||(Konva.Tween.attrs[h]={}),Konva.Tween.attrs[h][this._id]||(Konva.Tween.attrs[h][this._id]={}),Konva.Tween.tweens[h]||(Konva.Tween.tweens[h]={});for(i in e)void 0===t[i]&&this._addAttr(i,e[i]);this.reset(),this.onFinish=e.onFinish,this.onReset=e.onReset},Konva.Tween.attrs={},Konva.Tween.tweens={},Konva.Tween.prototype={_addAttr:function(t,e){var n,i,a,o,s,h,c,l=this.node,d=l._id;if(a=Konva.Tween.tweens[d][t],a&&delete Konva.Tween.attrs[d][a][t],n=l.getAttr(t),Konva.Util._isArray(e))for(i=[],s=Math.max(e.length,n.length),"points"===t&&e.length!==n.length&&(e.length>n.length?(c=n,n=Konva.Util._prepareArrayForTween(n,e,l.closed())):(h=e,e=Konva.Util._prepareArrayForTween(e,n,l.closed()))),o=0;o<s;o++)i.push(e[o]-n[o]);else if(r.indexOf(t)!==-1){n=Konva.Util.colorToRGBA(n);var u=Konva.Util.colorToRGBA(e);i={r:u.r-n.r,g:u.g-n.g,b:u.b-n.b,a:u.a-n.a}}else i=e-n;Konva.Tween.attrs[d][this._id][t]={start:n,diff:i,end:e,trueEnd:h,trueStart:c},Konva.Tween.tweens[d][t]=this._id},_tweenFunc:function(t){var e,n,i,a,o,s,h,c,l=this.node,d=Konva.Tween.attrs[l._id][this._id];for(e in d){if(n=d[e],i=n.start,a=n.diff,c=n.end,Konva.Util._isArray(i))for(o=[],h=Math.max(i.length,c.length),s=0;s<h;s++)o.push((i[s]||0)+a[s]*t);else o=r.indexOf(e)!==-1?"rgba("+Math.round(i.r+a.r*t)+","+Math.round(i.g+a.g*t)+","+Math.round(i.b+a.b*t)+","+(i.a+a.a*t)+")":i+a*t;l.setAttr(e,o)}},_addListeners:function(){var t=this;this.tween.onPlay=function(){t.anim.start()},this.tween.onReverse=function(){t.anim.start()},this.tween.onPause=function(){t.anim.stop()},this.tween.onFinish=function(){var e=t.node,n=Konva.Tween.attrs[e._id][t._id];n.points&&n.points.trueEnd&&e.points(n.points.trueEnd),t.onFinish&&t.onFinish.call(t)},this.tween.onReset=function(){var e=t.node,n=Konva.Tween.attrs[e._id][t._id];n.points&&n.points.trueStart&&e.points(n.points.trueStart),t.onReset&&t.onReset()}},play:function(){return this.tween.play(),this},reverse:function(){return this.tween.reverse(),this},reset:function(){return this.tween.reset(),this},seek:function(t){return this.tween.seek(1e3*t),this},pause:function(){return this.tween.pause(),this},finish:function(){return this.tween.finish(),this},destroy:function(){var t,e=this.node._id,n=this._id,i=Konva.Tween.tweens[e];this.pause();for(t in i)delete Konva.Tween.tweens[e][t];delete Konva.Tween.attrs[e][n]}},Konva.Node.prototype.to=function(t){var e=t.onFinish;t.node=this,t.onFinish=function(){this.destroy(),e&&e()};var n=new Konva.Tween(t);n.play()},Konva.Easings={BackEaseIn:function(t,e,n,i){var a=1.70158;return n*(t/=i)*t*((a+1)*t-a)+e},BackEaseOut:function(t,e,n,i){var a=1.70158;return n*((t=t/i-1)*t*((a+1)*t+a)+1)+e},BackEaseInOut:function(t,e,n,i){var a=1.70158;return(t/=i/2)<1?n/2*(t*t*(((a*=1.525)+1)*t-a))+e:n/2*((t-=2)*t*(((a*=1.525)+1)*t+a)+2)+e},ElasticEaseIn:function(t,e,n,i,a,r){var o=0;return 0===t?e:1===(t/=i)?e+n:(r||(r=.3*i),!a||a<Math.abs(n)?(a=n,o=r/4):o=r/(2*Math.PI)*Math.asin(n/a),-(a*Math.pow(2,10*(t-=1))*Math.sin((t*i-o)*(2*Math.PI)/r))+e)},ElasticEaseOut:function(t,e,n,i,a,r){var o=0;return 0===t?e:1===(t/=i)?e+n:(r||(r=.3*i),!a||a<Math.abs(n)?(a=n,o=r/4):o=r/(2*Math.PI)*Math.asin(n/a),a*Math.pow(2,-10*t)*Math.sin((t*i-o)*(2*Math.PI)/r)+n+e)},ElasticEaseInOut:function(t,e,n,i,a,r){var o=0;return 0===t?e:2===(t/=i/2)?e+n:(r||(r=i*(.3*1.5)),!a||a<Math.abs(n)?(a=n,o=r/4):o=r/(2*Math.PI)*Math.asin(n/a),t<1?-.5*(a*Math.pow(2,10*(t-=1))*Math.sin((t*i-o)*(2*Math.PI)/r))+e:a*Math.pow(2,-10*(t-=1))*Math.sin((t*i-o)*(2*Math.PI)/r)*.5+n+e)},BounceEaseOut:function(t,e,n,i){return(t/=i)<1/2.75?n*(7.5625*t*t)+e:t<2/2.75?n*(7.5625*(t-=1.5/2.75)*t+.75)+e:t<2.5/2.75?n*(7.5625*(t-=2.25/2.75)*t+.9375)+e:n*(7.5625*(t-=2.625/2.75)*t+.984375)+e},BounceEaseIn:function(t,e,n,i){return n-Konva.Easings.BounceEaseOut(i-t,0,n,i)+e},BounceEaseInOut:function(t,e,n,i){return t<i/2?.5*Konva.Easings.BounceEaseIn(2*t,0,n,i)+e:.5*Konva.Easings.BounceEaseOut(2*t-i,0,n,i)+.5*n+e},EaseIn:function(t,e,n,i){return n*(t/=i)*t+e},EaseOut:function(t,e,n,i){return-n*(t/=i)*(t-2)+e},EaseInOut:function(t,e,n,i){return(t/=i/2)<1?n/2*t*t+e:-n/2*(--t*(t-2)-1)+e},StrongEaseIn:function(t,e,n,i){return n*(t/=i)*t*t*t*t+e},StrongEaseOut:function(t,e,n,i){return n*((t=t/i-1)*t*t*t*t+1)+e},StrongEaseInOut:function(t,e,n,i){return(t/=i/2)<1?n/2*t*t*t*t*t+e:n/2*((t-=2)*t*t*t*t+2)+e},Linear:function(t,e,n,i){return n*t/i+e}}}(),function(){"use strict";Konva.DD={anim:new Konva.Animation(function(){var t=this.dirty;return this.dirty=!1,t}),isDragging:!1,justDragged:!1,offset:{x:0,y:0},node:null,_drag:function(t){var e=Konva.DD,n=e.node;if(n){if(!e.isDragging){var i=n.getStage().getPointerPosition(),a=n.dragDistance(),r=Math.max(Math.abs(i.x-e.startPointerPos.x),Math.abs(i.y-e.startPointerPos.y));if(r<a)return}n.getStage()._setPointerPosition(t),n._setDragPosition(t),e.isDragging||(e.isDragging=!0,n.fire("dragstart",{type:"dragstart",target:n,evt:t},!0)),n.fire("dragmove",{type:"dragmove",target:n,evt:t},!0)}},_endDragBefore:function(t){var e,n=Konva.DD,i=n.node;i&&(e=i.getLayer(),n.anim.stop(),n.isDragging&&(n.isDragging=!1,n.justDragged=!0,Konva.listenClickTap=!1,t&&(t.dragEndNode=i)),delete n.node,(i.getLayer()||e||i instanceof Konva.Stage)&&(e||i).draw())},_endDragAfter:function(t){t=t||{};var e=t.dragEndNode;t&&e&&e.fire("dragend",{type:"dragend",target:e,evt:t},!0)}},Konva.Node.prototype.startDrag=function(){var t=Konva.DD,e=this.getStage(),n=this.getLayer(),i=e.getPointerPosition(),a=this.getAbsolutePosition();i&&(t.node&&t.node.stopDrag(),t.node=this,t.startPointerPos=i,t.offset.x=i.x-a.x,t.offset.y=i.y-a.y,t.anim.setLayers(n||this.getLayers()),t.anim.start(),this._setDragPosition())},Konva.Node.prototype._setDragPosition=function(t){var e=Konva.DD,n=this.getStage().getPointerPosition(),i=this.getDragBoundFunc();if(n){var a={x:n.x-e.offset.x,y:n.y-e.offset.y};void 0!==i&&(a=i.call(this,a,t)),this.setAbsolutePosition(a),this._lastPos&&this._lastPos.x===a.x&&this._lastPos.y===a.y||(e.anim.dirty=!0),this._lastPos=a}},Konva.Node.prototype.stopDrag=function(){var t=Konva.DD,e={};t._endDragBefore(e),t._endDragAfter(e)},Konva.Node.prototype.setDraggable=function(t){this._setAttr("draggable",t),this._dragChange()};var t=Konva.Node.prototype.remove;Konva.Node.prototype.__originalRemove=t,Konva.Node.prototype.remove=function(){var e=Konva.DD;e.node&&e.node._id===this._id&&this.stopDrag(),t.call(this)},Konva.Node.prototype.isDragging=function(){var t=Konva.DD;return!(!t.node||t.node._id!==this._id||!t.isDragging)},Konva.Node.prototype._listenDrag=function(){var t=this;this._dragCleanup(),"Stage"===this.getClassName()?this.on("contentMousedown.konva contentTouchstart.konva",function(e){Konva.DD.node||t.startDrag(e)}):this.on("mousedown.konva touchstart.konva",function(e){1!==e.evt.button&&2!==e.evt.button&&(Konva.DD.node||t.startDrag(e))})},Konva.Node.prototype._dragChange=function(){if(this.attrs.draggable)this._listenDrag();else{this._dragCleanup();var t=this.getStage(),e=Konva.DD;t&&e.node&&e.node._id===this._id&&e.node.stopDrag()}},Konva.Node.prototype._dragCleanup=function(){"Stage"===this.getClassName()?(this.off("contentMousedown.konva"),this.off("contentTouchstart.konva")):(this.off("mousedown.konva"),this.off("touchstart.konva"))},Konva.Factory.addGetterSetter(Konva.Node,"dragBoundFunc"),Konva.Factory.addGetter(Konva.Node,"draggable",!1),Konva.Factory.addOverloadedGetterSetter(Konva.Node,"draggable");var e=Konva.document.documentElement;e.addEventListener("mouseup",Konva.DD._endDragBefore,!0),e.addEventListener("touchend",Konva.DD._endDragBefore,!0),e.addEventListener("mousemove",Konva.DD._drag),e.addEventListener("touchmove",Konva.DD._drag),e.addEventListener("mouseup",Konva.DD._endDragAfter,!1),e.addEventListener("touchend",Konva.DD._endDragAfter,!1)}(),function(){"use strict";Konva.Rect=function(t){this.___init(t)},Konva.Rect.prototype={___init:function(t){Konva.Shape.call(this,t),this.className="Rect",this.sceneFunc(this._sceneFunc)},_sceneFunc:function(t){var e=this.getCornerRadius(),n=this.getWidth(),i=this.getHeight();t.beginPath(),e?(e=Math.min(e,n/2,i/2),t.moveTo(e,0),t.lineTo(n-e,0),t.arc(n-e,e,e,3*Math.PI/2,0,!1),t.lineTo(n,i-e),t.arc(n-e,i-e,e,0,Math.PI/2,!1),t.lineTo(e,i),t.arc(e,i-e,e,Math.PI/2,Math.PI,!1),t.lineTo(0,e),t.arc(e,e,e,Math.PI,3*Math.PI/2,!1)):t.rect(0,0,n,i),t.closePath(),t.fillStrokeShape(this)}},Konva.Util.extend(Konva.Rect,Konva.Shape),Konva.Factory.addGetterSetter(Konva.Rect,"cornerRadius",0),Konva.Collection.mapMethods(Konva.Rect)}(),function(){"use strict";var t=2*Math.PI-1e-4,e="Circle";Konva.Circle=function(t){this.___init(t)},Konva.Circle.prototype={_centroid:!0,___init:function(t){Konva.Shape.call(this,t),this.className=e,this.sceneFunc(this._sceneFunc)},_sceneFunc:function(e){e.beginPath(),e.arc(0,0,this.getRadius(),0,t,!1),e.closePath(),e.fillStrokeShape(this)},getWidth:function(){return 2*this.getRadius()},getHeight:function(){return 2*this.getRadius()},setWidth:function(t){Konva.Node.prototype.setWidth.call(this,t),this.radius()!==t/2&&this.setRadius(t/2)},setHeight:function(t){Konva.Node.prototype.setHeight.call(this,t),this.radius()!==t/2&&this.setRadius(t/2)}},Konva.Util.extend(Konva.Circle,Konva.Shape),Konva.Factory.addGetterSetter(Konva.Circle,"radius",0),Konva.Factory.addOverloadedGetterSetter(Konva.Circle,"radius"),Konva.Collection.mapMethods(Konva.Circle)}(),function(){"use strict";Konva.Arc=function(t){this.___init(t)},Konva.Arc.prototype={_centroid:!0,___init:function(t){Konva.Shape.call(this,t),this.className="Arc",this.sceneFunc(this._sceneFunc)},_sceneFunc:function(t){var e=Konva.getAngle(this.angle()),n=this.clockwise();t.beginPath(),t.arc(0,0,this.getOuterRadius(),0,e,n),t.arc(0,0,this.getInnerRadius(),e,0,!n),t.closePath(),t.fillStrokeShape(this)},getWidth:function(){return 2*this.getOuterRadius()},getHeight:function(){return 2*this.getOuterRadius()},setWidth:function(t){Konva.Node.prototype.setWidth.call(this,t),this.getOuterRadius()!==t/2&&this.setOuterRadius(t/2)},setHeight:function(t){Konva.Node.prototype.setHeight.call(this,t),this.getOuterRadius()!==t/2&&this.setOuterRadius(t/2)}},Konva.Util.extend(Konva.Arc,Konva.Shape),Konva.Factory.addGetterSetter(Konva.Arc,"innerRadius",0),Konva.Factory.addGetterSetter(Konva.Arc,"outerRadius",0),Konva.Factory.addGetterSetter(Konva.Arc,"angle",0),Konva.Factory.addGetterSetter(Konva.Arc,"clockwise",!1),Konva.Collection.mapMethods(Konva.Arc)}();