forked from konvajs/konva
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkonva.min.js
26 lines (26 loc) · 148 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
/*
* Konva JavaScript Framework v1.7.6
* http://konvajs.github.io/
* Licensed under the MIT
* Date: Sat Mar 10 2018
*
* Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS)
* Modified work Copyright (C) 2014 - present by Anton Lavrenov (Konva)
*
* @license
*/
!function(){"use strict";var e=Math.PI/180,r={version:"1.7.6",stages:[],idCounter:0,ids:{},names:{},shapes:{},listenClickTap:!1,inDblClickWindow:!1,isBrowser:"undefined"!=typeof window&&("[object Window]"==={}.toString.call(window)||"[object global]"==={}.toString.call(window)),enableTrace:!1,traceArrMax:100,dblClickWindow:400,pixelRatio:void 0,dragDistance:3,angleDeg:!0,showWarnings:!0,Filters:{},isDragging:function(){var t=r.DD;return!!t&&t.isDragging},isDragReady:function(){var t=r.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 i=this.names[t];if(i){for(var n=0;n<i.length;n++){i[n]._id===e&&i.splice(n,1)}0===i.length&&delete this.names[t]}}},getAngle:function(t){return this.angleDeg?t*e:t},_detectIE:function(t){var e=t.indexOf("msie ");if(0<e)return parseInt(t.substring(e+5,t.indexOf(".",e)),10);if(0<t.indexOf("trident/")){var i=t.indexOf("rv:");return parseInt(t.substring(i+3,t.indexOf(".",i)),10)}var n=t.indexOf("edge/");return 0<n&&parseInt(t.substring(n+5,t.indexOf(".",n)),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)||[],n=!!t.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i),a=!!t.match(/IEMobile/i);return{browser:i[1]||"",version:i[2]||"0",isIE:r._detectIE(e),mobile:n,ieMobile:a}},UA:void 0},t="undefined"!=typeof global?global:"undefined"!=typeof window?window:"undefined"!=typeof WorkerGlobalScope?self:{};r.UA=r._parseUA(t.navigator&&t.navigator.userAgent||""),t.Konva&&console.error("Konva instance is already exist in current eviroment. Please use only one instance."),(t.Konva=r).global=t,r.window=t,r.document=t.document,"object"==typeof exports?module.exports=r:"function"==typeof define&&define.amd&&define(function(){return r})}(),function(){"use strict";Konva.Collection=function(){var t=[].slice.call(arguments),e=t.length,i=0;for(this.length=e;i<e;i++)this[i]=t[i];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=[],i=this.length;for(t=0;t<i;t++)e.push(this[t]);return e},Konva.Collection.toCollection=function(t){var e,i=new Konva.Collection,n=t.length;for(e=0;e<n;e++)i.push(t[e]);return i},Konva.Collection._mapMethod=function(n){Konva.Collection.prototype[n]=function(){var t,e=this.length,i=[].slice.call(arguments);for(t=0;t<e;t++)this[t][n].apply(this[t],i);return this}},Konva.Collection.mapMethods=function(t){var e=t.prototype;for(var i in e)Konva.Collection._mapMethod(i)},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),i=Math.sin(t),n=this.m[0]*e+this.m[2]*i,a=this.m[1]*e+this.m[3]*i,r=this.m[0]*-i+this.m[2]*e,o=this.m[1]*-i+this.m[3]*e;return this.m[0]=n,this.m[1]=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 i=this.m[0]+this.m[2]*e,n=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]=i,this.m[1]=n,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],i=this.m[1]*t.m[0]+this.m[3]*t.m[1],n=this.m[0]*t.m[2]+this.m[2]*t.m[3],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]=i,this.m[2]=n,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,i=-this.m[1]*t,n=-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]=i,this.m[2]=n,this.m[3]=a,this.m[4]=r,this.m[5]=o,this},getMatrix:function(){return this.m},setAbsolutePosition:function(t,e){var i=this.m[0],n=this.m[1],a=this.m[2],r=this.m[3],o=this.m[4],s=(i*(e-this.m[5])-n*(t-o))/(i*r-n*a),h=(t-o-a*s)/i;return this.translate(h,s)}};var e=Math.PI/180,i=180/Math.PI,n="Konva error: ",a={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]},r=/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 Array]"===Object.prototype.toString.call(t)},_isNumber:function(t){return"[object Number]"===Object.prototype.toString.call(t)},_isString:function(t){return"[object String]"===Object.prototype.toString.call(t)},isValidSelector:function(t){if("string"!=typeof t)return!1;var e=t[0];return"#"===e||"."===e||e===e.toUpperCase()},createCanvasElement:function(){var t=Konva.isBrowser?Konva.document.createElement("canvas"):new Konva._nodeCanvas;try{t.style=t.style||{}}catch(t){}return t},_isInDocument:function(t){for(;t=t.parentNode;)if(t==Konva.document)return!0;return!1},_simplifyArray:function(t){var e,i,n=[],a=t.length,r=Konva.Util;for(e=0;e<a;e++)i=t[e],r._isNumber(i)?i=Math.round(1e3*i)/1e3:r._isString(i)||(i=i.toString()),n.push(i);return n},_getImage:function(t,e){var i,n;if(t)if(this._isElement(t))e(t);else if(this._isString(t))(i=new Konva.window.Image).onload=function(){e(i)},i.src=t;else if(t.data){(n=Konva.Util.createCanvasElement()).width=t.width,n.height=t.height,n.getContext("2d").putImageData(t,0,0),this._getImage(n.toDataURL(),e)}else e(null);else e(null)},_getRGBAString:function(t){return["rgba(",t.red||0,",",t.green||0,",",t.blue||0,",",t.alpha||1,")"].join("")},_rgbToHex:function(t,e,i){return((1<<24)+(t<<16)+(e<<8)+i).toString(16).slice(1)},_hexToRgb:function(t){t=t.replace("#","");var e=parseInt(t,16);return{r:e>>16&255,g:e>>8&255,b:255&e}},getRandomColor:function(){for(var t=(16777215*Math.random()<<0).toString(16);t.length<6;)t="0"+t;return"#"+t},get:function(t,e){return void 0===t?e:t},getRGB:function(t){var e;return t in a?{r:(e=a[t])[0],g:e[1],b:e[2]}:"#"===t[0]?this._hexToRgb(t.substring(1)):"rgb("===t.substr(0,4)?(e=r.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=a[t.toLowerCase()];return e?{r:e[0],g:e[1],b:e[2],a:1}:null},_rgbColorToRGBA:function(t){if(0===t.indexOf("rgb(")){var e=(t=t.match(/rgb\(([^)]+)\)/)[1]).split(/ *, */).map(Number);return{r:e[0],g:e[1],b:e[2],a:1}}},_rgbaColorToRGBA:function(t){if(0===t.indexOf("rgba(")){var e=(t=t.match(/rgba\(([^)]+)\)/)[1]).split(/ *, */).map(Number);return{r:e[0],g:e[1],b:e[2],a:e[3]}}},_hex6ColorToRGBA:function(t){if("#"===t[0]&&7===t.length)return{r:parseInt(t.slice(1,3),16),g:parseInt(t.slice(3,5),16),b:parseInt(t.slice(5,7),16),a:1}},_hex3ColorToRGBA:function(t){if("#"===t[0]&&4===t.length)return{r:parseInt(t[1]+t[1],16),g:parseInt(t[2]+t[2],16),b:parseInt(t[3]+t[3],16),a:1}},_merge:function(t,e){var i=this._clone(e);for(var n in t)this._isObject(t[n])?i[n]=this._merge(t[n],i[n]):i[n]=t[n];return i},haveIntersection:function(t,e){return!(e.x>t.x+t.width||e.x+e.width<t.x||e.y>t.y+t.height||e.y+e.height<t.y)},cloneObject:function(t){var e={};for(var i in t)this._isObject(t[i])?e[i]=this.cloneObject(t[i]):this._isArray(t[i])?e[i]=this.cloneArray(t[i]):e[i]=t[i];return e},cloneArray:function(t){return t.slice(0)},_degToRad:function(t){return t*e},_radToDeg:function(t){return t*i},_capitalize:function(t){return t.charAt(0).toUpperCase()+t.slice(1)},throw:function(t){throw new Error(n+t)},error:function(t){console.error(n+t)},warn:function(t){Konva.global.console&&console.warn&&Konva.showWarnings&&console.warn("Konva warning: "+t)},extend:function(t,e){function i(){this.constructor=t}i.prototype=e.prototype;var n=t.prototype;for(var a in t.prototype=new i,n)n.hasOwnProperty(a)&&(t.prototype[a]=n[a]);t.__super__=e.prototype,t.super=e},addMethods:function(t,e){var i;for(i in e)t.prototype[i]=e[i]},_getControlPoints:function(t,e,i,n,a,r,o){var s=Math.sqrt(Math.pow(i-t,2)+Math.pow(n-e,2)),h=Math.sqrt(Math.pow(a-i,2)+Math.pow(r-n,2)),c=o*s/(s+h),l=o*h/(s+h);return[i-c*(a-t),n-c*(r-e),i+l*(a-t),n+l*(r-e)]},_expandPoints:function(t,e){var i,n,a=t.length,r=[];for(i=2;i<a-2;i+=2)n=Konva.Util._getControlPoints(t[i-2],t[i-1],t[i],t[i+1],t[i+2],t[i+3],e),r.push(n[0]),r.push(n[1]),r.push(t[i]),r.push(t[i+1]),r.push(n[2]),r.push(n[3]);return r},_removeLastLetter:function(t){return t.substring(0,t.length-1)},each:function(t,e){for(var i in t)e(i,t[i])},_inRange:function(t,e,i){return e<=t&&t<i},_getProjectionToSegment:function(t,e,i,n,a,r){var o,s,h,c=(t-i)*(t-i)+(e-n)*(e-n);if(0==c)o=t,s=e,h=(a-i)*(a-i)+(r-n)*(r-n);else{var l=((a-t)*(i-t)+(r-e)*(n-e))/c;h=l<0?((o=t)-a)*(t-a)+((s=e)-r)*(e-r):1<l?((o=i)-a)*(i-a)+((s=n)-r)*(n-r):((o=t+l*(i-t))-a)*(o-a)+((s=e+l*(n-e))-r)*(s-r)}return[o,s,h]},_getProjectionToLine:function(s,h,c){var l=Konva.Util.cloneObject(s),d=Number.MAX_VALUE;return h.forEach(function(t,e){if(c||e!==h.length-1){var i=h[(e+1)%h.length],n=Konva.Util._getProjectionToSegment(t.x,t.y,i.x,i.y,s.x,s.y),a=n[0],r=n[1],o=n[2];o<d&&(l.x=a,l.y=r,d=o)}}),l},_prepareArrayForTween:function(t,e,i){var n,a=[],r=[];if(t.length>e.length){var o=e;e=t,t=o}for(n=0;n<t.length;n+=2)a.push({x:t[n],y:t[n+1]});for(n=0;n<e.length;n+=2)r.push({x:e[n],y:e[n+1]});var s=[];return r.forEach(function(t){var e=Konva.Util._getProjectionToLine(t,a,i);s.push(e.x),s.push(e.y)}),s},_prepareToStringify:function(t){var e;for(var i in t.visitedByCircularReferenceRemoval=!0,t)if(t.hasOwnProperty(i)&&t[i]&&"object"==typeof t[i])if(e=Object.getOwnPropertyDescriptor(t,i),t[i].visitedByCircularReferenceRemoval||Konva.Util._isElement(t[i])){if(!e.configurable)return null;delete t[i]}else if(null===Konva.Util._prepareToStringify(t[i])){if(!e.configurable)return null;delete t[i]}return delete t.visitedByCircularReferenceRemoval,t}}}(),function(){"use strict";var i;Konva.Canvas=function(t){this.init(t)},Konva.Canvas.prototype={init:function(t){var e=(t||{}).pixelRatio||Konva.pixelRatio||function(){if(i)return i;var t=Konva.Util.createCanvasElement().getContext("2d");return i=(Konva.window.devicePixelRatio||1)/(t.webkitBackingStorePixelRatio||t.mozBackingStorePixelRatio||t.msBackingStorePixelRatio||t.oBackingStorePixelRatio||t.backingStorePixelRatio||1)}();this.pixelRatio=e,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;this.getContext()._context.scale(e,e)},setHeight:function(t){this.height=this._canvas.height=t*this.pixelRatio,this._canvas.style.height=t+"px";var e=this.pixelRatio;this.getContext()._context.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||{},i=e.width||0,n=e.height||0;Konva.Canvas.call(this,e),this.context=new Konva.SceneContext(this),this.setSize(i,n)},Konva.Util.extend(Konva.SceneCanvas,Konva.Canvas),Konva.HitCanvas=function(t){var e=t||{},i=e.width||0,n=e.height||0;Konva.Canvas.call(this,e),this.context=new Konva.HitContext(this),this.setSize(i,n),this.hitCanvas=!0},Konva.Util.extend(Konva.HitCanvas,Konva.Canvas)}(),function(){"use strict";var s=["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"];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){t.getFillEnabled()&&this._fill(t),t.getStrokeEnabled()&&this._stroke(t)},getTrace:function(t){var e,i,n,a,r=this.traceArr,o=r.length,s="";for(e=0;e<o;e++)(n=(i=r[e]).method)?(a=i.args,s+=n,t?s+="()":Konva.Util._isArray(a[0])?s+="(["+a.join(",")+"])":s+="("+a.join(",")+")"):(s+=i.property,t||(s+="="+i.val)),s+=";";return s},clearTrace:function(){this.traceArr=[]},_trace:function(t){var e=this.traceArr;e.push(t),e.length>=Konva.traceArrMax&&e.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,i,n){this._context.fillRect(t,e,i,n)},strokeRect:function(t,e,i,n){this._context.strokeRect(t,e,i,n)},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,n,a=this,e=s.length,r=Konva.Util._simplifyArray,i=this.setAttr,o=function(t){var e,i=a[t];a[t]=function(){return n=r(Array.prototype.slice.call(arguments,0)),e=i.apply(a,arguments),a._trace({method:t,args:n}),e}};for(t=0;t<e;t++)o(s[t]);a.setAttr=function(){i.apply(a,arguments);var t=arguments[0],e=arguments[1];"shadowOffsetX"!==t&&"shadowOffsetY"!==t&&"shadowBlur"!==t||(e/=this.canvas.getPixelRatio()),a._trace({property:t,val:e})}}},["fillStyle","strokeStyle","shadowColor","shadowBlur","shadowOffsetX","shadowOffsetY","lineCap","lineDashOffset","lineJoin","lineWidth","miterLimit","font","textAlign","textBaseline","globalAlpha","globalCompositeOperation"].forEach(function(e){Object.defineProperty(Konva.Context.prototype,e,{get:function(){return this._context[e]},set:function(t){this._context[e]=t}})}),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(),i=t.getFillPatternY(),n=t.getFillPatternScale(),a=Konva.getAngle(t.getFillPatternRotation()),r=t.getFillPatternOffset();(e||i)&&this.translate(e||0,i||0),a&&this.rotate(a),n&&this.scale(n.x,n.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(),i=t.getFillLinearGradientEndPoint(),n=t.getFillLinearGradientColorStops(),a=this.createLinearGradient(e.x,e.y,i.x,i.y);if(n){for(var r=0;r<n.length;r+=2)a.addColorStop(n[r],n[r+1]);this.setAttr("fillStyle",a),t._fillFunc(this)}},_fillRadialGradient:function(t){for(var e=t.getFillRadialGradientStartPoint(),i=t.getFillRadialGradientEndPoint(),n=t.getFillRadialGradientStartRadius(),a=t.getFillRadialGradientEndRadius(),r=t.getFillRadialGradientColorStops(),o=this.createRadialGradient(e.x,e.y,n,i.x,i.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(),i=t.getFillPatternImage(),n=t.getFillLinearGradientColorStops(),a=t.getFillRadialGradientColorStops(),r=t.getFillPriority();e&&"color"===r?this._fillColor(t):i&&"pattern"===r?this._fillPattern(t):n&&"linear-gradient"===r?this._fillLinearGradient(t):a&&"radial-gradient"===r?this._fillRadialGradient(t):e?this._fillColor(t):i?this._fillPattern(t):n?this._fillLinearGradient(t):a&&this._fillRadialGradient(t)},_strokeLinearGradient:function(t){var e=t.getStrokeLinearGradientStartPoint(),i=t.getStrokeLinearGradientEndPoint(),n=t.getStrokeLinearGradientColorStops(),a=this.createLinearGradient(e.x,e.y,i.x,i.y);if(n){for(var r=0;r<n.length;r+=2)a.addColorStop(n[r],n[r+1]);this.setAttr("strokeStyle",a)}},_stroke:function(t){var e=t.dash(),i=t.getStrokeScaleEnabled()||t instanceof Konva.Text;t.hasStroke()&&(i||(this.save(),this.setTransform(1,0,0,1,0,0)),this._applyLineCap(t),e&&t.dashEnabled()&&(this.setLineDash(e),this.setAttr("lineDashOffset",t.dashOffset())),this.setAttr("lineWidth",t.strokeWidth()),t.getShadowForStrokeEnabled()||this.setAttr("shadowColor","rgba(0,0,0,0)"),t.getStrokeLinearGradientColorStops()?this._strokeLinearGradient(t):this.setAttr("strokeStyle",t.stroke()),t._strokeFunc(this),i||this.restore())},_applyShadow:function(t){var e=Konva.Util,i=e.get(t.getShadowRGBA(),"black"),n=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",i),this.setAttr("shadowBlur",n*o*Math.min(Math.abs(s),Math.abs(h))),this.setAttr("shadowOffsetX",a.x*s),this.setAttr("shadowOffsetY",a.y*h)},_applyGlobalCompositeOperation:function(t){var e=t.getGlobalCompositeOperation();"source-over"!==e&&this.setAttr("globalCompositeOperation",e)}},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 d="get";Konva.Factory={addGetterSetter:function(t,e,i,n,a){this.addGetter(t,e,i),this.addSetter(t,e,n,a),this.addOverloadedGetterSetter(t,e)},addGetter:function(t,e,i){var n=d+Konva.Util._capitalize(e);t.prototype[n]=function(){var t=this.attrs[e];return void 0===t?i:t}},addSetter:function(t,e,i,n){var a="set"+Konva.Util._capitalize(e);t.prototype[a]=function(t){return i&&(t=i.call(this,t)),this._setAttr(e,t),n&&n.call(this),this}},addComponentsGetterSetter:function(t,n,e,a,r){var i,o,s=e.length,h=Konva.Util._capitalize,c=d+h(n),l="set"+h(n);t.prototype[c]=function(){var t={};for(i=0;i<s;i++)t[o=e[i]]=this.getAttr(n+h(o));return t},t.prototype[l]=function(t){var e,i=this.attrs[n];for(e in a&&(t=a.call(this,t)),t)t.hasOwnProperty(e)&&this._setAttr(n+h(e),t[e]);return this._fireChangeEvent(n,i,t),r&&r.call(this),this},this.addOverloadedGetterSetter(t,n)},addOverloadedGetterSetter:function(t,e){var i=Konva.Util._capitalize(e),n="set"+i,a=d+i;t.prototype[e]=function(){return arguments.length?(this[n](arguments[0]),this):this[a]()}},addDeprecatedGetterSetter:function(t,e,i,n){Konva.Util.error("Adding deprecated "+e);var a=d+Konva.Util._capitalize(e),r=e+" property is deprecated and will be removed soon. Look at Konva change log for more information.";t.prototype[a]=function(){Konva.Util.error(r);var t=this.attrs[e];return void 0===t?i:t},this.addSetter(t,e,n,function(){Konva.Util.error(r)}),this.addOverloadedGetterSetter(t,e)},backCompat:function(n,t){Konva.Util.each(t,function(t,e){var i=n.prototype[e];n.prototype[t]=function(){i.apply(this,arguments),Konva.Util.error(t+" method is deprecated and will be removed soon. Use "+e+" instead")}})},afterSetFilter:function(){this._filterUpToDate=!1}},Konva.Validators={RGBComponent:function(t){return 255<t?255:t<0?0:Math.round(t)},alphaComponent:function(t){return 1<t?1:t<1e-4?1e-4:t}}}(),function(v){"use strict";var p="absoluteOpacity",i="absoluteTransform",m="absoluteScale",n="listening",r="mouseenter",o="mouseleave",c="Shape",a="transform",s="visible",l=["id"],h=["xChange.konva","yChange.konva","scaleXChange.konva","scaleYChange.konva","skewXChange.konva","skewYChange.konva","rotationChange.konva","offsetXChange.konva","offsetYChange.konva","transformsEnabledChange.konva"].join(" "),d=["scaleXChange.konva","scaleYChange.konva"].join(" ");v.Node=function(t){this._init(t)},v.Util.addMethods(v.Node,{_init:function(t){var e=this;this._id=v.idCounter++,this.eventListeners={},this.attrs={},this._cache={},this._filterUpToDate=!1,this._isUnderCache=!1,this.setAttrs(t),this.on(h,function(){this._clearCache(a),e._clearSelfAndDescendantCache(i)}),this.on(d,function(){e._clearSelfAndDescendantCache(m)}),this.on("visibleChange.konva",function(){e._clearSelfAndDescendantCache(s)}),this.on("listeningChange.konva",function(){e._clearSelfAndDescendantCache(n)}),this.on("opacityChange.konva",function(){e._clearSelfAndDescendantCache(p)})},_clearCache:function(t){t?delete this._cache[t]:this._cache={}},_getCache:function(t,e){return void 0===this._cache[t]&&(this._cache[t]=e.call(this)),this._cache[t]},_clearSelfAndDescendantCache:function(e){this._clearCache(e),this.children&&this.getChildren().each(function(t){t._clearSelfAndDescendantCache(e)})},clearCache:function(){return delete this._cache.canvas,this._filterUpToDate=!1,this},cache:function(t){var e=t||{},i=this.getClientRect({skipTransform:!0,relativeTo:this.getParent()}),n=e.width||i.width,a=e.height||i.height,r=e.pixelRatio,o=e.x||i.x,s=e.y||i.y,h=e.offset||0,c=e.drawBorder||!1;if(n&&a){n+=2*h,a+=2*h,o-=h,s-=h;var l=new v.SceneCanvas({pixelRatio:r,width:n,height:a}),d=new v.SceneCanvas({pixelRatio:r,width:n,height:a}),u=new v.HitCanvas({pixelRatio:1,width:n,height:a}),f=l.getContext(),g=u.getContext();return u.isCache=!0,this.clearCache(),f.save(),g.save(),f.translate(-o,-s),g.translate(-o,-s),this._isUnderCache=!0,this._clearSelfAndDescendantCache(p),this._clearSelfAndDescendantCache(m),this.drawScene(l,this,!0),this.drawHit(u,this,!0),this._isUnderCache=!1,f.restore(),g.restore(),c&&(f.save(),f.beginPath(),f.rect(0,0,n,a),f.closePath(),f.setAttr("strokeStyle","red"),f.setAttr("lineWidth",5),f.stroke(),f.restore()),this._cache.canvas={scene:l,filter:d,hit:u,x:o,y:s},this}setTimeout(function(){v.Util.throw("Width or height of caching configuration equals 0. Caching is ignored.")})},getClientRect:function(){throw new Error('abstract "getClientRect" method call')},_transformedRect:function(t,e){var i,n,a,r,o=[{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}],s=this.getAbsoluteTransform(e);return o.forEach(function(t){var e=s.point(t);void 0===i&&(i=a=e.x,n=r=e.y),i=Math.min(i,e.x),n=Math.min(n,e.y),a=Math.max(a,e.x),r=Math.max(r,e.y)}),{x:i,y:n,width:a-i,height:r-n}},_drawCachedSceneCanvas:function(t){t.save(),t._applyOpacity(this),t._applyGlobalCompositeOperation(this),t.translate(this._cache.canvas.x,this._cache.canvas.y);var e=this._getCachedSceneCanvas(),i=e.pixelRatio;t.drawImage(e._canvas,0,0,e.width/i,e.height/i),t.restore()},_drawCachedHitCanvas:function(t){var e=this._cache.canvas.hit;t.save(),t.translate(this._cache.canvas.x,this._cache.canvas.y),t.drawImage(e._canvas,0,0),t.restore()},_getCachedSceneCanvas:function(){var t,e,i,n,a=this.filters(),r=this._cache.canvas,o=r.scene,s=r.filter,h=s.getContext();if(a){if(!this._filterUpToDate){var c=o.pixelRatio;try{for(t=a.length,h.clear(),h.drawImage(o._canvas,0,0,o.getWidth()/c,o.getHeight()/c),e=h.getImageData(0,0,s.getWidth(),s.getHeight()),i=0;i<t;i++)"function"==typeof(n=a[i])?(n.call(this,e),h.putImageData(e,0,0)):v.Util.error("Filter should be type of function, but got "+typeof n+" insted. Please check correct filters")}catch(t){v.Util.error("Unable to apply filter. "+t.message)}this._filterUpToDate=!0}return s}return o},on:function(t,e){if(3===arguments.length)return this._delegate.apply(this,arguments);var i,n,a,r,o=t.split(" "),s=o.length;for(i=0;i<s;i++)a=(n=o[i].split("."))[0],r=n[1]||"",this.eventListeners[a]||(this.eventListeners[a]=[]),this.eventListeners[a].push({name:r,handler:e});return this},off:function(t,e){var i,n,a,r,o,s=(t||"").split(" "),h=s.length;if(!t)for(n in this.eventListeners)this._off(n);for(i=0;i<h;i++)if(r=(a=s[i].split("."))[0],o=a[1],r)this.eventListeners[r]&&this._off(r,o,e);else for(n in this.eventListeners)this._off(n,o,e);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(t,n,a){var r=this;this.on(t,function(t){for(var e=t.target.findAncestors(n,!0,r),i=0;i<e.length;i++)(t=v.Util.cloneObject(t)).currentTarget=e[i],a.call(e[i],t)})},remove:function(){var t=this.getParent();return t&&t.children&&(t.children.splice(this.index,1),t._setChildrenIndices(),delete this.parent),this._clearSelfAndDescendantCache("stage"),this._clearSelfAndDescendantCache(i),this._clearSelfAndDescendantCache(s),this._clearSelfAndDescendantCache(n),this._clearSelfAndDescendantCache(p),this},destroy:function(){v._removeId(this.getId());for(var t=(this.getName()||"").split(/\s/g),e=0;e<t.length;e++){var i=t[e];v._removeName(i,this._id)}return this.remove(),this},getAttr:function(t){var e="get"+v.Util._capitalize(t);return v.Util._isFunction(this[e])?this[e]():this.attrs[t]},getAncestors:function(){for(var t=this.getParent(),e=new v.Collection;t;)e.push(t),t=t.getParent();return e},getAttrs:function(){return this.attrs||{}},setAttrs:function(t){var e,i;if(!t)return this;for(e in t)"children"!==e&&(i="set"+v.Util._capitalize(e),v.Util._isFunction(this[i])?this[i](t[e]):this._setAttr(e,t[e]));return this},isListening:function(){return this._getCache(n,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(){var i,n,a,r,o=this.getDepth(),s=this,h=0;return"Stage"!==s.nodeType&&function t(e){for(i=[],n=e.length,a=0;a<n;a++)r=e[a],h++,r.nodeType!==c&&(i=i.concat(r.getChildren().toArray())),r._id===s._id&&(a=n);0<i.length&&i[0].getDepth()<=o&&t(i)}(s.getStage().getChildren()),h},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(t){var e=this.getAbsoluteTransform(t).getMatrix(),i=new v.Transform,n=this.offset();return i.m=e.slice(),i.translate(n.x,n.y),i.getTranslation()},setAbsolutePosition:function(t){var e,i=this._clearTransform();return this.attrs.x=i.x,this.attrs.y=i.y,delete i.x,delete i.y,(e=this.getAbsoluteTransform()).invert(),e.translate(t.x,t.y),t={x:this.attrs.x+e.getTranslation().x,y:this.attrs.y+e.getTranslation().y},this.setPosition({x:t.x,y:t.y}),this._setTransform(i),this},_setTransform:function(t){var e;for(e in t)this.attrs[e]=t[e];this._clearCache(a),this._clearSelfAndDescendantCache(i)},_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(a),this._clearSelfAndDescendantCache(i),t},move:function(t){var e=t.x,i=t.y,n=this.getX(),a=this.getY();return void 0!==e&&(n+=e),void 0!==i&&(a+=i),this.setPosition({x:n,y:a}),this},_eachAncestorReverse:function(t,e){var i,n,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(i=a.length,n=0;n<i;n++)t(a[n])},rotate:function(t){return this.setRotation(this.getRotation()+t),this},moveToTop:function(){if(!this.parent)return v.Util.warn("Node has no parent. moveToTop function is ignored."),!1;var t=this.index;return this.parent.children.splice(t,1),this.parent.children.push(this),this.parent._setChildrenIndices(),!0},moveUp:function(){if(!this.parent)return v.Util.warn("Node has no parent. moveUp function is ignored."),!1;var t=this.index;return t<this.parent.getChildren().length-1&&(this.parent.children.splice(t,1),this.parent.children.splice(t+1,0,this),this.parent._setChildrenIndices(),!0)},moveDown:function(){if(!this.parent)return v.Util.warn("Node has no parent. moveDown function is ignored."),!1;var t=this.index;return 0<t&&(this.parent.children.splice(t,1),this.parent.children.splice(t-1,0,this),this.parent._setChildrenIndices(),!0)},moveToBottom:function(){if(!this.parent)return v.Util.warn("Node has no parent. moveToBottom function is ignored."),!1;var t=this.index;return 0<t&&(this.parent.children.splice(t,1),this.parent.children.unshift(this),this.parent._setChildrenIndices(),!0)},setZIndex:function(t){if(!this.parent)return v.Util.warn("Node has no parent. zIndex parameter is ignored."),!1;var e=this.index;return this.parent.children.splice(e,1),this.parent.children.splice(t,0,this),this.parent._setChildrenIndices(),this},getAbsoluteOpacity:function(){return this._getCache(p,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 t,e,i,n={},a=this.getAttrs();for(t in n.attrs={},a)e=a[t],i=this[t],delete a[t],(i?i.call(this):null)!==(a[t]=e)&&(n.attrs[t]=e);return n.className=this.getClassName(),v.Util._prepareToStringify(n)},toJSON:function(){return JSON.stringify(this.toObject())},getParent:function(){return this.parent},findAncestors:function(t,e,i){var n=[];e&&this._isMatch(t)&&n.push(this);for(var a=this.parent;a;){if(a===i)return n;a._isMatch(t)&&n.push(a),a=a.parent}return n},findAncestor:function(t,e,i){return this.findAncestors(t,e,i)[0]},_isMatch:function(t){if(!t)return!1;var e,i,n=t.replace(/ /g,"").split(","),a=n.length;for(e=0;e<a;e++)if(i=n[e],v.Util.isValidSelector(i)||(v.Util.warn('Selector "'+i+'" is invalid. Allowed selectors examples are "#foo", ".bar" or "Group".'),v.Util.warn('If you have a custom shape with such className, please change it to start with upper letter like "Triangle".'),v.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("stage",this._getStage)},_getStage:function(){var t=this.getParent();return t?t.getStage():void 0},fire:function(t,e,i){return(e=e||{}).target=e.target||this,i?this._fireAndBubble(t,e):this._fire(t,e),this},getAbsoluteTransform:function(t){return t?this._getAbsoluteTransform(t):this._getCache(i,this._getAbsoluteTransform)},_getAbsoluteTransform:function(t){var e,i,n=new v.Transform;return this._eachAncestorReverse(function(t){e=t.transformsEnabled(),i=t.getTransform(),"all"===e?n.multiply(i):"position"===e&&n.translate(t.x(),t.y())},t),n},getAbsoluteScale:function(t){return t?this._getAbsoluteScale(t):this._getCache(m,this._getAbsoluteScale)},_getAbsoluteScale:function(t){for(var e=this;e;)e._isUnderCache&&(t=e),e=e.getParent();var i=1,n=1;return this._eachAncestorReverse(function(t){i*=t.scaleX(),n*=t.scaleY()},t),{x:i,y:n}},getTransform:function(){return this._getCache(a,this._getTransform)},_getTransform:function(){var t=new v.Transform,e=this.getX(),i=this.getY(),n=v.getAngle(this.getRotation()),a=this.getScaleX(),r=this.getScaleY(),o=this.getSkewX(),s=this.getSkewY(),h=this.getOffsetX(),c=this.getOffsetY();return 0===e&&0===i||t.translate(e,i),0!==n&&t.rotate(n),0===o&&0===s||t.skew(o,s),1===a&&1===r||t.scale(a,r),0===h&&0===c||t.translate(-1*h,-1*c),t},clone:function(t){var e,i,n,a,r,o=v.Util.cloneObject(this.attrs);for(var s in l){delete o[l[s]]}for(e in t)o[e]=t[e];var h=new this.constructor(o);for(e in this.eventListeners)for(n=(i=this.eventListeners[e]).length,a=0;a<n;a++)(r=i[a]).name.indexOf("konva")<0&&(h.eventListeners[e]||(h.eventListeners[e]=[]),h.eventListeners[e].push(r));return h},_toKonvaCanvas:function(t){t=t||{};var e=this.getStage(),i=t.x||0,n=t.y||0,a=t.pixelRatio||1,r=new v.SceneCanvas({width:t.width||this.getWidth()||(e?e.getWidth():0),height:t.height||this.getHeight()||(e?e.getHeight():0),pixelRatio:a}),o=r.getContext();return o.save(),(i||n)&&o.translate(-1*i,-1*n),this.drawScene(r),o.restore(),r},toCanvas:function(t){return this._toKonvaCanvas(t)._canvas},toDataURL:function(t){var e=(t=t||{}).mimeType||null,i=t.quality||null;return this._toKonvaCanvas(t).toDataURL(e,i)},toImage:function(e){if(!e||!e.callback)throw"callback required for toImage method config argument";v.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():v.dragDistance},_get:function(t){return this.className===t||this.nodeType===t?[this]:[]},_off:function(t,e,i){var n,a,r,o=this.eventListeners[t];for(n=0;n<o.length;n++)if(a=o[n].name,r=o[n].handler,!("konva"===a&&"konva"!==e||e&&a!==e||i&&i!==r)){if(o.splice(n,1),0===o.length){delete this.eventListeners[t];break}n--}},_fireChangeEvent:function(t,e,i){this._fire(t+"Change",{oldVal:e,newVal:i})},setId:function(t){var e=this.getId();return v._removeId(e),v._addId(this,t),this._setAttr("id",t),this},setName:function(t){var e,i,n=(this.getName()||"").split(/\s/g),a=(t||"").split(/\s/g);for(i=0;i<n.length;i++)e=n[i],-1===a.indexOf(e)&&e&&v._removeName(e,this._id);for(i=0;i<a.length;i++)e=a[i],-1===n.indexOf(e)&&e&&v._addName(this,e);return this._setAttr("name",t),this},addName:function(t){if(!this.hasName(t)){var e=this.name(),i=e?e+" "+t:t;this.setName(i)}return this},hasName:function(t){return-1!==(this.name()||"").split(/\s/g).indexOf(t)},removeName:function(t){var e=(this.name()||"").split(/\s/g),i=e.indexOf(t);return-1!==i&&(e.splice(i,1),this.setName(e.join(" "))),this},setAttr:function(t,e){var i=this["set"+v.Util._capitalize(t)];return v.Util._isFunction(i)?i.call(this,e):this._setAttr(t,e),this},_setAttr:function(t,e){var i;(i=this.attrs[t])!==e&&(null==e?delete this.attrs[t]:this.attrs[t]=e,this._fireChangeEvent(t,i,e))},_setComponentAttr:function(t,e,i){var n;void 0!==i&&((n=this.attrs[t])||(this.attrs[t]=this.getAttr(t)),this.attrs[t][e]=i,this._fireChangeEvent(t,n,i))},_fireAndBubble:function(t,e,i){var n=!0;if(e&&this.nodeType===c&&(e.target=this),t===r&&i&&(this._id===i._id||this.isAncestorOf&&this.isAncestorOf(i))?n=!1:t===o&&i&&(this._id===i._id||this.isAncestorOf&&this.isAncestorOf(i))&&(n=!1),n){this._fire(t,e);var a=(t===r||t===o)&&i&&i.isAncestorOf&&i.isAncestorOf(this)&&!i.isAncestorOf(this.parent);(e&&!e.cancelBubble||!e)&&this.parent&&this.parent.isListening()&&!a&&(i&&i.parent?this._fireAndBubble.call(this.parent,t,e,i.parent):this._fireAndBubble.call(this.parent,t,e))}},_fire:function(t,e){var i,n=this.eventListeners[t];if((e=e||{}).currentTarget=this,e.type=t,n)for(i=0;i<n.length;i++)n[i].handler.call(this,e)},draw:function(){return this.drawScene(),this.drawHit(),this}}),v.Node.create=function(t,e){return v.Util._isString(t)&&(t=JSON.parse(t)),this._createNode(t,e)},v.Node._createNode=function(t,e){var i,n,a,r=v.Node.prototype.getClassName.call(t),o=t.children;if(e&&(t.attrs.container=e),i=new v[r](t.attrs),o)for(n=o.length,a=0;a<n;a++)i.add(this._createNode(o[a]));return i},v.Factory.addOverloadedGetterSetter(v.Node,"position"),v.Factory.addGetterSetter(v.Node,"x",0),v.Factory.addGetterSetter(v.Node,"y",0),v.Factory.addGetterSetter(v.Node,"globalCompositeOperation","source-over"),v.Factory.addGetterSetter(v.Node,"opacity",1),v.Factory.addGetter(v.Node,"name"),v.Factory.addOverloadedGetterSetter(v.Node,"name"),v.Factory.addGetter(v.Node,"id"),v.Factory.addOverloadedGetterSetter(v.Node,"id"),v.Factory.addGetterSetter(v.Node,"rotation",0),v.Factory.addComponentsGetterSetter(v.Node,"scale",["x","y"]),v.Factory.addGetterSetter(v.Node,"scaleX",1),v.Factory.addGetterSetter(v.Node,"scaleY",1),v.Factory.addComponentsGetterSetter(v.Node,"skew",["x","y"]),v.Factory.addGetterSetter(v.Node,"skewX",0),v.Factory.addGetterSetter(v.Node,"skewY",0),v.Factory.addComponentsGetterSetter(v.Node,"offset",["x","y"]),v.Factory.addGetterSetter(v.Node,"offsetX",0),v.Factory.addGetterSetter(v.Node,"offsetY",0),v.Factory.addSetter(v.Node,"dragDistance"),v.Factory.addOverloadedGetterSetter(v.Node,"dragDistance"),v.Factory.addSetter(v.Node,"width",0),v.Factory.addOverloadedGetterSetter(v.Node,"width"),v.Factory.addSetter(v.Node,"height",0),v.Factory.addOverloadedGetterSetter(v.Node,"height"),v.Factory.addGetterSetter(v.Node,"listening","inherit"),v.Factory.addGetterSetter(v.Node,"preventDefault",!0),v.Factory.addGetterSetter(v.Node,"filters",void 0,function(t){return this._filterUpToDate=!1,t}),v.Factory.addGetterSetter(v.Node,"visible","inherit"),v.Factory.addGetterSetter(v.Node,"transformsEnabled","all"),v.Factory.addOverloadedGetterSetter(v.Node,"size"),v.Factory.backCompat(v.Node,{rotateDeg:"rotate",setRotationDeg:"setRotation",getRotationDeg:"getRotation"}),v.Collection.mapMethods(v.Node)}(Konva),function(){"use strict";Konva.Filters.Grayscale=function(t){var e,i,n=t.data,a=n.length;for(e=0;e<a;e+=4)i=.34*n[e]+.5*n[e+1]+.16*n[e+2],n[e]=i,n[e+1]=i,n[e+2]=i}}(),function(t){"use strict";t.Filters.Brighten=function(t){var e,i=255*this.brightness(),n=t.data,a=n.length;for(e=0;e<a;e+=4)n[e]+=i,n[e+1]+=i,n[e+2]+=i},t.Factory.addGetterSetter(t.Node,"brightness",0,null,t.Factory.afterSetFilter)}(Konva),function(){"use strict";Konva.Filters.Invert=function(t){var e,i=t.data,n=i.length;for(e=0;e<n;e+=4)i[e]=255-i[e],i[e+1]=255-i[e+1],i[e+2]=255-i[e+2]}}(),function(t){"use strict";function z(){this.r=0,this.g=0,this.b=0,this.a=0,this.next=null}var B=[512,512,456,512,328,456,335,512,405,328,271,456,388,335,292,512,454,405,364,328,298,271,496,456,420,388,360,335,312,292,273,512,482,454,428,405,383,364,345,328,312,298,284,271,259,496,475,456,437,420,404,388,374,360,347,335,323,312,302,292,282,273,265,512,497,482,468,454,441,428,417,405,394,383,373,364,354,345,337,328,320,312,305,298,291,284,278,271,265,259,507,496,485,475,465,456,446,437,428,420,412,404,396,388,381,374,367,360,354,347,341,335,329,323,318,312,307,302,297,292,287,282,278,273,269,265,261,512,505,497,489,482,475,468,461,454,447,441,435,428,422,417,411,405,399,394,389,383,378,373,368,364,359,354,350,345,341,337,332,328,324,320,316,312,309,305,301,298,294,291,287,284,281,278,274,271,268,265,262,259,257,507,501,496,491,485,480,475,470,465,460,456,451,446,442,437,433,428,424,420,416,412,408,404,400,396,392,388,385,381,377,374,370,367,363,360,357,354,350,347,344,341,338,335,332,329,326,323,320,318,315,312,310,307,304,302,299,297,294,292,289,287,285,282,280,278,275,273,271,269,267,265,263,261,259],H=[9,11,12,13,13,14,14,15,15,15,15,16,16,16,16,17,17,17,17,17,17,17,18,18,18,18,18,18,18,18,18,19,19,19,19,19,19,19,19,19,19,19,19,19,19,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24];t.Filters.Blur=function(t){var e=Math.round(this.blurRadius());0<e&&function(t,e){var i,n,a,r,o,s,h,c,l,d,u,f,g,v,p,m,y,_,S,K,x,C,b,w,F=t.data,T=t.width,P=t.height,A=e+e+1,M=T-1,k=P-1,G=e+1,R=G*(G+1)/2,D=new z,L=null,O=D,I=null,N=null,U=B[e],E=H[e];for(a=1;a<A;a++)O=O.next=new z,a===G&&(L=O);for(O.next=D,h=s=0,n=0;n<P;n++){for(m=y=_=S=c=l=d=u=0,f=G*(K=F[s]),g=G*(x=F[s+1]),v=G*(C=F[s+2]),p=G*(b=F[s+3]),c+=R*K,l+=R*x,d+=R*C,u+=R*b,O=D,a=0;a<G;a++)O.r=K,O.g=x,O.b=C,O.a=b,O=O.next;for(a=1;a<G;a++)r=s+((M<a?M:a)<<2),c+=(O.r=K=F[r])*(w=G-a),l+=(O.g=x=F[r+1])*w,d+=(O.b=C=F[r+2])*w,u+=(O.a=b=F[r+3])*w,m+=K,y+=x,_+=C,S+=b,O=O.next;for(I=D,N=L,i=0;i<T;i++)F[s+3]=b=u*U>>E,0!==b?(b=255/b,F[s]=(c*U>>E)*b,F[s+1]=(l*U>>E)*b,F[s+2]=(d*U>>E)*b):F[s]=F[s+1]=F[s+2]=0,c-=f,l-=g,d-=v,u-=p,f-=I.r,g-=I.g,v-=I.b,p-=I.a,r=h+((r=i+e+1)<M?r:M)<<2,c+=m+=I.r=F[r],l+=y+=I.g=F[r+1],d+=_+=I.b=F[r+2],u+=S+=I.a=F[r+3],I=I.next,f+=K=N.r,g+=x=N.g,v+=C=N.b,p+=b=N.a,m-=K,y-=x,_-=C,S-=b,N=N.next,s+=4;h+=T}for(i=0;i<T;i++){for(y=_=S=m=l=d=u=c=0,f=G*(K=F[s=i<<2]),g=G*(x=F[s+1]),v=G*(C=F[s+2]),p=G*(b=F[s+3]),c+=R*K,l+=R*x,d+=R*C,u+=R*b,O=D,a=0;a<G;a++)O.r=K,O.g=x,O.b=C,O.a=b,O=O.next;for(o=T,a=1;a<=e;a++)s=o+i<<2,c+=(O.r=K=F[s])*(w=G-a),l+=(O.g=x=F[s+1])*w,d+=(O.b=C=F[s+2])*w,u+=(O.a=b=F[s+3])*w,m+=K,y+=x,_+=C,S+=b,O=O.next,a<k&&(o+=T);for(s=i,I=D,N=L,n=0;n<P;n++)F[3+(r=s<<2)]=b=u*U>>E,0<b?(b=255/b,F[r]=(c*U>>E)*b,F[r+1]=(l*U>>E)*b,F[r+2]=(d*U>>E)*b):F[r]=F[r+1]=F[r+2]=0,c-=f,l-=g,d-=v,u-=p,f-=I.r,g-=I.g,v-=I.b,p-=I.a,r=i+((r=n+G)<k?r:k)*T<<2,c+=m+=I.r=F[r],l+=y+=I.g=F[r+1],d+=_+=I.b=F[r+2],u+=S+=I.a=F[r+3],I=I.next,f+=K=N.r,g+=x=N.g,v+=C=N.b,p+=b=N.a,m-=K,y-=x,_-=C,S-=b,N=N.next,s+=T}}(t,e)},t.Factory.addGetterSetter(t.Node,"blurRadius",0,null,t.Factory.afterSetFilter)}(Konva),function(){"use strict";function d(t,e,i){var n=4*(i*t.width+e),a=[];return a.push(t.data[n++],t.data[n++],t.data[n++],t.data[n++]),a}function u(t,e){return Math.sqrt(Math.pow(t[0]-e[0],2)+Math.pow(t[1]-e[1],2)+Math.pow(t[2]-e[2],2))}Konva.Filters.Mask=function(t){var e=function(t,e){var i=d(t,0,0),n=d(t,t.width-1,0),a=d(t,0,t.height-1),r=d(t,t.width-1,t.height-1),o=e||10;if(u(i,n)<o&&u(n,r)<o&&u(r,a)<o&&u(a,i)<o){for(var s=function(t){for(var e=[0,0,0],i=0;i<t.length;i++)e[0]+=t[i][0],e[1]+=t[i][1],e[2]+=t[i][2];return e[0]/=t.length,e[1]/=t.length,e[2]/=t.length,e}([n,i,r,a]),h=[],c=0;c<t.width*t.height;c++){var l=u(s,[t.data[4*c],t.data[4*c+1],t.data[4*c+2]]);h[c]=l<o?0:255}return h}}(t,this.threshold());return e&&function(t,e){for(var i=0;i<t.width*t.height;i++)t.data[4*i+3]=e[i]}(t,e=function(t,e,i){for(var n=[1/9,1/9,1/9,1/9,1/9,1/9,1/9,1/9,1/9],a=Math.round(Math.sqrt(n.length)),r=Math.floor(a/2),o=[],s=0;s<i;s++)for(var h=0;h<e;h++){for(var c=s*e+h,l=0,d=0;d<a;d++)for(var u=0;u<a;u++){var f=s+d-r,g=h+u-r;if(0<=f&&f<i&&0<=g&&g<e){var v=n[d*a+u];l+=t[f*e+g]*v}}o[c]=l}return o}(e=function(t,e,i){for(var n=[1,1,1,1,1,1,1,1,1],a=Math.round(Math.sqrt(n.length)),r=Math.floor(a/2),o=[],s=0;s<i;s++)for(var h=0;h<e;h++){for(var c=s*e+h,l=0,d=0;d<a;d++)for(var u=0;u<a;u++){var f=s+d-r,g=h+u-r;if(0<=f&&f<i&&0<=g&&g<e){var v=n[d*a+u];l+=t[f*e+g]*v}}o[c]=1020<=l?255:0}return o}(e=function(t,e,i){for(var n=[1,1,1,1,0,1,1,1,1],a=Math.round(Math.sqrt(n.length)),r=Math.floor(a/2),o=[],s=0;s<i;s++)for(var h=0;h<e;h++){for(var c=s*e+h,l=0,d=0;d<a;d++)for(var u=0;u<a;u++){var f=s+d-r,g=h+u-r;if(0<=f&&f<i&&0<=g&&g<e){var v=n[d*a+u];l+=t[f*e+g]*v}}o[c]=2040===l?255:0}return o}(e,t.width,t.height),t.width,t.height),t.width,t.height)),t},Konva.Factory.addGetterSetter(Konva.Node,"threshold",0,null,Konva.Factory.afterSetFilter)}(),function(){"use strict";Konva.Filters.RGB=function(t){var e,i,n=t.data,a=n.length,r=this.red(),o=this.green(),s=this.blue();for(e=0;e<a;e+=4)i=(.34*n[e]+.5*n[e+1]+.16*n[e+2])/255,n[e]=i*r,n[e+1]=i*o,n[e+2]=i*s,n[e+3]=n[e+3]},Konva.Factory.addGetterSetter(Konva.Node,"red",0,function(t){return this._filterUpToDate=!1,255<t?255:t<0?0:Math.round(t)}),Konva.Factory.addGetterSetter(Konva.Node,"green",0,function(t){return this._filterUpToDate=!1,255<t?255:t<0?0:Math.round(t)}),Konva.Factory.addGetterSetter(Konva.Node,"blue",0,Konva.Validators.RGBComponent,Konva.Factory.afterSetFilter)}(),function(){"use strict";Konva.Filters.RGBA=function(t){var e,i,n=t.data,a=n.length,r=this.red(),o=this.green(),s=this.blue(),h=this.alpha();for(e=0;e<a;e+=4)i=1-h,n[e]=r*h+n[e]*i,n[e+1]=o*h+n[e+1]*i,n[e+2]=s*h+n[e+2]*i},Konva.Factory.addGetterSetter(Konva.Node,"red",0,function(t){return this._filterUpToDate=!1,255<t?255:t<0?0:Math.round(t)}),Konva.Factory.addGetterSetter(Konva.Node,"green",0,function(t){return this._filterUpToDate=!1,255<t?255:t<0?0:Math.round(t)}),Konva.Factory.addGetterSetter(Konva.Node,"blue",0,Konva.Validators.RGBComponent,Konva.Factory.afterSetFilter),Konva.Factory.addGetterSetter(Konva.Node,"alpha",1,function(t){return this._filterUpToDate=!1,1<t?1:t<0?0:t})}(),function(){"use strict";Konva.Filters.HSV=function(t){var e,i,n,a,r,o=t.data,s=o.length,h=Math.pow(2,this.value()),c=Math.pow(2,this.saturation()),l=Math.abs(this.hue()+360)%360,d=h*c*Math.cos(l*Math.PI/180),u=h*c*Math.sin(l*Math.PI/180),f=.299*h+.701*d+.167*u,g=.587*h-.587*d+.33*u,v=.114*h-.114*d-.497*u,p=.299*h-.299*d-.328*u,m=.587*h+.413*d+.035*u,y=.114*h-.114*d+.293*u,_=.299*h-.3*d+1.25*u,S=.587*h-.586*d-1.05*u,K=.114*h+.886*d-.2*u;for(e=0;e<s;e+=4)i=o[e+0],n=o[e+1],a=o[e+2],r=o[e+3],o[e+0]=f*i+g*n+v*a,o[e+1]=p*i+m*n+y*a,o[e+2]=_*i+S*n+K*a,o[e+3]=r},Konva.Factory.addGetterSetter(Konva.Node,"hue",0,null,Konva.Factory.afterSetFilter),Konva.Factory.addGetterSetter(Konva.Node,"saturation",0,null,Konva.Factory.afterSetFilter),Konva.Factory.addGetterSetter(Konva.Node,"value",0,null,Konva.Factory.afterSetFilter)}(),function(){"use strict";Konva.Factory.addGetterSetter(Konva.Node,"hue",0,null,Konva.Factory.afterSetFilter),Konva.Factory.addGetterSetter(Konva.Node,"saturation",0,null,Konva.Factory.afterSetFilter),Konva.Factory.addGetterSetter(Konva.Node,"luminance",0,null,Konva.Factory.afterSetFilter),Konva.Filters.HSL=function(t){var e,i,n,a,r,o=t.data,s=o.length,h=Math.pow(2,this.saturation()),c=Math.abs(this.hue()+360)%360,l=127*this.luminance(),d=1*h*Math.cos(c*Math.PI/180),u=1*h*Math.sin(c*Math.PI/180),f=.299+.701*d+.167*u,g=.587-.587*d+.33*u,v=.114-.114*d-.497*u,p=.299-.299*d-.328*u,m=.587+.413*d+.035*u,y=.114-.114*d+.293*u,_=.299-.3*d+1.25*u,S=.587-.586*d-1.05*u,K=.114+.886*d-.2*u;for(e=0;e<s;e+=4)i=o[e+0],n=o[e+1],a=o[e+2],r=o[e+3],o[e+0]=f*i+g*n+v*a+l,o[e+1]=p*i+m*n+y*a+l,o[e+2]=_*i+S*n+K*a+l,o[e+3]=r}}(),function(){"use strict";Konva.Filters.Emboss=function(t){var e=10*this.embossStrength(),i=255*this.embossWhiteLevel(),n=this.embossDirection(),a=this.embossBlend(),r=0,o=0,s=t.data,h=t.width,c=t.height,l=4*h,d=c;switch(n){case"top-left":o=r=-1;break;case"top":r=-1,o=0;break;case"top-right":r=-1,o=1;break;case"right":r=0,o=1;break;case"bottom-right":o=r=1;break;case"bottom":r=1,o=0;break;case"bottom-left":o=-(r=1);break;case"left":r=0,o=-1;break;default:Konva.Util.error("Unknown emboss direction: "+n)}do{var u=(d-1)*l,f=r;d+f<1&&(f=0),c<d+f&&(f=0);var g=(d-1+f)*h*4,v=h;do{var p=u+4*(v-1),m=o;v+m<1&&(m=0),h<v+m&&(m=0);var y=g+4*(v-1+m),_=s[p]-s[y],S=s[p+1]-s[y+1],K=s[p+2]-s[y+2],x=_,C=0<x?x:-x;if(C<(0<S?S:-S)&&(x=S),C<(0<K?K:-K)&&(x=K),x*=e,a){var b=s[p]+x,w=s[p+1]+x,F=s[p+2]+x;s[p]=255<b?255:b<0?0:b,s[p+1]=255<w?255:w<0?0:w,s[p+2]=255<F?255:F<0?0:F}else{var T=i-x;T<0?T=0:255<T&&(T=255),s[p]=s[p+1]=s[p+2]=T}}while(--v)}while(--d)},Konva.Factory.addGetterSetter(Konva.Node,"embossStrength",.5,null,Konva.Factory.afterSetFilter),Konva.Factory.addGetterSetter(Konva.Node,"embossWhiteLevel",.5,null,Konva.Factory.afterSetFilter),Konva.Factory.addGetterSetter(Konva.Node,"embossDirection","top-left",null,Konva.Factory.afterSetFilter),Konva.Factory.addGetterSetter(Konva.Node,"embossBlend",!1,null,Konva.Factory.afterSetFilter)}(),function(){"use strict";function C(t,e,i,n,a){var r=i-e,o=a-n;return 0===r?n+o/2:0===o?n:o*((t-e)/r)+n}Konva.Filters.Enhance=function(t){var e,i,n,a,r=t.data,o=r.length,s=r[0],h=s,c=r[1],l=c,d=r[2],u=d,f=this.enhance();if(0!==f){for(a=0;a<o;a+=4)(e=r[a+0])<s?s=e:h<e&&(h=e),(i=r[a+1])<c?c=i:l<i&&(l=i),(n=r[a+2])<d?d=n:u<n&&(u=n);var g,v,p,m,y,_,S,K,x;for(h===s&&(h=255,s=0),l===c&&(l=255,c=0),u===d&&(u=255,d=0),0<f?(v=h+f*(255-h),p=s-f*(s-0),y=l+f*(255-l),_=c-f*(c-0),K=u+f*(255-u),x=d-f*(d-0)):(v=h+f*(h-(g=.5*(h+s))),p=s+f*(s-g),y=l+f*(l-(m=.5*(l+c))),_=c+f*(c-m),K=u+f*(u-(S=.5*(u+d))),x=d+f*(d-S)),a=0;a<o;a+=4)r[a+0]=C(r[a+0],s,h,p,v),r[a+1]=C(r[a+1],c,l,_,y),r[a+2]=C(r[a+2],d,u,x,K)}},Konva.Factory.addGetterSetter(Konva.Node,"enhance",0,null,Konva.Factory.afterSetFilter)}(),function(){"use strict";Konva.Filters.Posterize=function(t){var e,i=Math.round(254*this.levels())+1,n=t.data,a=n.length,r=255/i;for(e=0;e<a;e+=1)n[e]=Math.floor(n[e]/r)*r},Konva.Factory.addGetterSetter(Konva.Node,"levels",.5,null,Konva.Factory.afterSetFilter)}(),function(){"use strict";Konva.Filters.Noise=function(t){var e,i=255*this.noise(),n=t.data,a=n.length,r=i/2;for(e=0;e<a;e+=4)n[e+0]+=r-2*r*Math.random(),n[e+1]+=r-2*r*Math.random(),n[e+2]+=r-2*r*Math.random()},Konva.Factory.addGetterSetter(Konva.Node,"noise",.2,null,Konva.Factory.afterSetFilter)}(),function(){"use strict";Konva.Filters.Pixelate=function(t){var e,i,n,a,r,o,s,h,c,l,d,u,f,g,v=Math.ceil(this.pixelSize()),p=t.width,m=t.height,y=Math.ceil(p/v),_=Math.ceil(m/v);if(t=t.data,v<=0)Konva.Util.error("pixelSize value can not be <= 0");else for(u=0;u<y;u+=1)for(f=0;f<_;f+=1){for(c=(h=u*v)+v,d=(l=f*v)+v,g=s=o=r=a=0,e=h;e<c;e+=1)if(!(p<=e))for(i=l;i<d;i+=1)m<=i||(a+=t[(n=4*(p*i+e))+0],r+=t[n+1],o+=t[n+2],s+=t[n+3],g+=1);for(a/=g,r/=g,o/=g,s/=g,e=h;e<c;e+=1)if(!(p<=e))for(i=l;i<d;i+=1)m<=i||(t[(n=4*(p*i+e))+0]=a,t[n+1]=r,t[n+2]=o,t[n+3]=s)}},Konva.Factory.addGetterSetter(Konva.Node,"pixelSize",8,null,Konva.Factory.afterSetFilter)}(),function(){"use strict";Konva.Filters.Threshold=function(t){var e,i=255*this.threshold(),n=t.data,a=n.length;for(e=0;e<a;e+=1)n[e]=n[e]<i?0:255},Konva.Factory.addGetterSetter(Konva.Node,"threshold",.5,null,Konva.Factory.afterSetFilter)}(),function(){"use strict";
/**
* Sepia Filter
* Based on: Pixastic Lib - Sepia filter - v0.1.0
* Copyright (c) 2008 Jacob Seidelin, [email protected], http://blog.nihilogic.dk/
* @function
* @name Sepia
* @memberof Konva.Filters
* @param {Object} imageData
* @author Jacob Seidelin <[email protected]>
* @license MPL v1.1 [http://www.pixastic.com/lib/license.txt]
* @example
* node.cache();
* node.filters([Konva.Filters.Sepia]);
*/Konva.Filters.Sepia=function(t){var e,i,n,a,r,o,s,h,c,l=t.data,d=t.width,u=t.height,f=4*d;do{for(e=(u-1)*f,i=d;s=.393*(a=l[n=e+4*(i-1)])+.769*(r=l[n+1])+.189*(o=l[n+2]),h=.349*a+.686*r+.168*o,c=.272*a+.534*r+.131*o,l[n]=255<s?255:s,l[n+1]=255<h?255:h,l[n+2]=255<c?255:c,l[n+3]=l[n+3],--i;);}while(--u)}}(),function(){"use strict";Konva.Filters.Solarize=function(t){var e=t.data,i=t.width,n=4*i,a=t.height;do{var r=(a-1)*n,o=i;do{var s=r+4*(o-1),h=e[s],c=e[s+1],l=e[s+2];127<h&&(h=255-h),127<c&&(c=255-c),127<l&&(l=255-l),e[s]=h,e[s+1]=c,e[s+2]=l}while(--o)}while(--a)}}(),function(){"use strict";Konva.Filters.Kaleidoscope=function(t){var e,i,n,a,r,o,s,h,c,l=t.width,d=t.height,u=Math.round(this.kaleidoscopePower()),f=Math.round(this.kaleidoscopeAngle()),g=Math.floor(l*(f%360)/360);if(!(u<1)){var v=Konva.Util.createCanvasElement();v.width=l,v.height=d;var p=v.getContext("2d").getImageData(0,0,l,d);!function(t,e,i){var n,a,r,o,s=t.data,h=e.data,c=t.width,l=t.height,d=i.polarCenterX||c/2,u=i.polarCenterY||l/2,f=0,g=0,v=0,p=0,m=Math.sqrt(d*d+u*u);a=c-d,r=l-u,m=m<(o=Math.sqrt(a*a+r*r))?o:m;var y,_,S,K,x=l,C=c,b=360/C*Math.PI/180;for(_=0;_<C;_+=1)for(S=Math.sin(_*b),K=Math.cos(_*b),y=0;y<x;y+=1)a=Math.floor(d+m*y/x*K),f=s[0+(n=4*((r=Math.floor(u+m*y/x*S))*c+a))],g=s[n+1],v=s[n+2],p=s[n+3],h[0+(n=4*(_+y*c))]=f,h[n+1]=g,h[n+2]=v,h[n+3]=p}(t,p,{polarCenterX:l/2,polarCenterY:d/2});for(var m=l/Math.pow(2,u);m<=8;)m*=2,u-=1;var y=m=Math.ceil(m),_=0,S=y,K=1;for(l<g+m&&(_=y,S=0,K=-1),i=0;i<d;i+=1)for(e=_;e!==S;e+=K)h=4*(l*i+Math.round(e+g)%l),a=p.data[h+0],r=p.data[h+1],o=p.data[h+2],s=p.data[h+3],c=4*(l*i+e),p.data[c+0]=a,p.data[c+1]=r,p.data[c+2]=o,p.data[c+3]=s;for(i=0;i<d;i+=1)for(y=Math.floor(m),n=0;n<u;n+=1){for(e=0;e<y+1;e+=1)h=4*(l*i+e),a=p.data[h+0],r=p.data[h+1],o=p.data[h+2],s=p.data[h+3],c=4*(l*i+2*y-e-1),p.data[c+0]=a,p.data[c+1]=r,p.data[c+2]=o,p.data[c+3]=s;y*=2}!function(t,e,i){var n,a,r,o,s,h,c=t.data,l=e.data,d=t.width,u=t.height,f=i.polarCenterX||d/2,g=i.polarCenterY||u/2,v=0,p=0,m=0,y=0,_=Math.sqrt(f*f+g*g);a=d-f,r=u-g,_=_<(h=Math.sqrt(a*a+r*r))?h:_;var S,K,x,C=u,b=d,w=i.polarRotation||0;for(a=0;a<d;a+=1)for(r=0;r<u;r+=1)o=a-f,s=r-g,S=Math.sqrt(o*o+s*s)*C/_,K=(K=(180*Math.atan2(s,o)/Math.PI+360+w)%360)*b/360,x=Math.floor(K),v=c[0+(n=4*(Math.floor(S)*d+x))],p=c[n+1],m=c[n+2],y=c[n+3],l[0+(n=4*(r*d+a))]=v,l[n+1]=p,l[n+2]=m,l[n+3]=y}(p,t,{polarRotation:0})}},Konva.Factory.addGetterSetter(Konva.Node,"kaleidoscopePower",2,null,Konva.Factory.afterSetFilter),Konva.Factory.addGetterSetter(Konva.Node,"kaleidoscopeAngle",0,null,Konva.Factory.afterSetFilter)}(),function(t){"use strict";t.Filters.Contrast=function(t){var e,i=Math.pow((parseInt(this.contrast())+100)/100,2),n=t.data,a=n.length,r=150,o=150,s=150;for(e=0;e<a;e+=4)r=n[e],o=n[e+1],s=n[e+2],r/=255,r-=.5,r*=i,r+=.5,o/=255,o-=.5,o*=i,o+=.5,s/=255,s-=.5,s*=i,s+=.5,r=(r*=255)<0?0:255<r?255:r,o=(o*=255)<0?0:255<o?255:o,s=(s*=255)<0?0:255<s?255:s,n[e]=r,n[e+1]=o,n[e+2]=s},t.Factory.addGetterSetter(t.Node,"contrast",0,null,t.Factory.afterSetFilter)}(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(e){if(!e)return this.children;var i=new Konva.Collection;return this.children.each(function(t){e(t)&&i.push(t)}),i},hasChildren:function(){return 0<this.getChildren().length},removeChildren:function(){for(var t,e=Konva.Collection.toCollection(this.children),i=0;i<e.length;i++)delete(t=e[i]).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),i=0;i<e.length;i++)delete(t=e[i]).parent,t.index=0,t.destroy();return e=null,this.children=new Konva.Collection,this},add:function(t){if(1<arguments.length){for(var e=0;e<arguments.length;e++)this.add(arguments[e]);return this}if(t.getParent())return t.moveTo(this),this;var i=this.children;return this._validateAdd(t),t.index=i.length,t.parent=this,i.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,i,n,a,r,o,s,h=[],c=t.replace(/ /g,"").split(","),l=c.length;for(e=0;e<l;e++)if(n=c[e],Konva.Util.isValidSelector(n)||(Konva.Util.warn('Selector "'+n+'" 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?")),"#"===n.charAt(0))(r=this._getNodeById(n.slice(1)))&&h.push(r);else if("."===n.charAt(0))a=this._getNodesByName(n.slice(1)),h=h.concat(a);else for(s=(o=this.getChildren()).length,i=0;i<s;i++)h=h.concat(o[i]._get(n));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),i=this.getChildren(),n=i.length,a=0;a<n;a++)e=e.concat(i[a]._get(t));return e},toObject:function(){var t=Konva.Node.prototype.toObject.call(this);t.children=[];for(var e=this.getChildren(),i=e.length,n=0;n<i;n++){var a=e[n];t.children.push(a.toObject())}return t},_getDescendants:function(t){for(var e=[],i=t.length,n=0;n<i;n++){var a=t[n];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(e){var i=[];return this.find("Shape").each(function(t){t.isVisible()&&t.intersects(e)&&i.push(t)}),i},_setChildrenIndices:function(){this.children.each(function(t,e){t.index=e})},drawScene:function(t,e,i){var n=this.getLayer(),a=t||n&&n.getCanvas(),r=a&&a.getContext(),o=this._cache.canvas,s=o&&o.scene;return this.isVisible()&&(!i&&s?(r.save(),n._applyTransform(this,r,e),this._drawCachedSceneCanvas(r),r.restore()):this._drawChildren(a,"drawScene",e,!1,i)),this},drawHit:function(t,e,i){var n=this.getLayer(),a=t||n&&n.hitCanvas,r=a&&a.getContext(),o=this._cache.canvas,s=o&&o.hit;return this.shouldDrawHit(a)&&(n&&n.clearHitCache(),!i&&s?(r.save(),n._applyTransform(this,r,e),this._drawCachedHitCanvas(r),r.restore()):this._drawChildren(a,"drawHit",e)),this},_drawChildren:function(e,i,n,a,r){var t,o,s=this.getLayer(),h=e&&e.getContext(),c=this.getClipWidth(),l=this.getClipHeight(),d=this.getClipFunc(),u=c&&l||d;if(u&&s){h.save();var f=this.getAbsoluteTransform(n),g=f.getMatrix();h.transform(g[0],g[1],g[2],g[3],g[4],g[5]),h.beginPath(),d?d.call(this,h,this):(t=this.getClipX(),o=this.getClipY(),h.rect(t,o,c,l)),h.clip(),g=f.copy().invert().getMatrix(),h.transform(g[0],g[1],g[2],g[3],g[4],g[5])}this.children.each(function(t){t[i](e,n,a,r)}),u&&h.restore()},shouldDrawHit:function(t){var e=this.getLayer(),i=Konva.DD&&Konva.isDragging()&&-1!==Konva.DD.anim.getLayers().indexOf(e);return t&&t.isCache||e&&e.hitGraphEnabled()&&this.isVisible()&&!i},getClientRect:function(t){var i,n,a,r,e=(t=t||{}).skipTransform,o=t.relativeTo,s={x:0,y:0,width:0,height:0},h=this;return this.children.each(function(t){if(t.isVisible()){var e=t.getClientRect({relativeTo:h});void 0===i?(i=e.x,n=e.y,a=e.x+e.width,r=e.y+e.height):(i=Math.min(i,e.x),n=Math.min(n,e.y),a=Math.max(a,e.x+e.width),r=Math.max(r,e.y+e.height))}}),0!==this.children.length&&(s={x:i,y:n,width:a-i,height:r-n}),e?s:this._transformedRect(s,o)}}),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(f){"use strict";var t="hasShadow",e="shadowRGBA";function n(t){t.fill()}function a(t){t.stroke()}function r(t){t.fill()}function o(t){t.stroke()}function s(){this._clearCache(t)}function h(){this._clearCache(e)}f.Shape=function(t){this.__init(t)},f.Util.addMethods(f.Shape,{__init:function(t){this.nodeType="Shape",this._fillFunc=n,this._strokeFunc=a,this._fillFuncHit=r,this._strokeFuncHit=o;for(var e,i=f.shapes;!(e=f.Util.getRandomColor())||e in i;);i[this.colorKey=e]=this,f.Node.call(this,t),this.on("shadowColorChange.konva shadowBlurChange.konva shadowOffsetChange.konva shadowOpacityChange.konva shadowEnabledChange.konva",s),this.on("shadowColorChange.konva shadowOpacityChange.konva shadowEnabledChange.konva",h)},hasChildren:function(){return!1},getChildren:function(){return[]},getContext:function(){return this.getLayer().getContext()},getCanvas:function(){return this.getLayer().getCanvas()},hasShadow:function(){return this._getCache(t,this._hasShadow)},_hasShadow:function(){return this.getShadowEnabled()&&0!==this.getShadowOpacity()&&!!(this.getShadowColor()||this.getShadowBlur()||this.getShadowOffsetX()||this.getShadowOffsetY())},getShadowRGBA:function(){return this._getCache(e,this._getShadowRGBA)},_getShadowRGBA:function(){if(this.hasShadow()){var t=f.Util.colorToRGBA(this.shadowColor());return"rgba("+t.r+","+t.g+","+t.b+","+t.a*(this.getShadowOpacity()||1)+")"}},hasFill:function(){return!!(this.getFill()||this.getFillPatternImage()||this.getFillLinearGradientColorStops()||this.getFillRadialGradientColorStops())},hasStroke:function(){return this.strokeEnabled()&&!(!this.stroke()&&!this.getStrokeLinearGradientColorStops())},intersects:function(t){var e=this.getStage().bufferHitCanvas;return e.getContext().clear(),this.drawHit(e),0<e.context.getImageData(Math.round(t.x),Math.round(t.y),1,1).data[3]},destroy:function(){return f.Node.prototype.destroy.call(this),delete f.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=(t=t||{}).skipTransform,i=t.relativeTo,n=this.getSelfRect(),a=this.hasStroke()&&this.strokeWidth()||0,r=n.width+a,o=n.height+a,s=this.hasShadow()?this.shadowOffsetX():0,h=this.hasShadow()?this.shadowOffsetY():0,c=r+Math.abs(s),l=o+Math.abs(h),d=this.hasShadow()&&this.shadowBlur()||0,u=c+2*d,f=l+2*d,g=0;Math.round(a/2)!==a/2&&(g=1);var v={width:u+g,height:f+g,x:-Math.round(a/2+d)+Math.min(s,0)+n.x,y:-Math.round(a/2+d)+Math.min(h,0)+n.y};return e?v:this._transformedRect(v,i)},drawScene:function(t,e,i,n){var a,r,o=this.getLayer(),s=t||o.getCanvas(),h=s.getContext(),c=this._cache.canvas,l=this.sceneFunc(),d=this.hasShadow(),u=this.hasStroke();if(!this.isVisible())return this;if(c)return h.save(),o._applyTransform(this,h,e),this._drawCachedSceneCanvas(h),h.restore(),this;if(!l)return this;if(h.save(),this._useBufferCanvas(i)&&!n){if((r=(a=this.getStage().bufferCanvas).getContext()).clear(),r.save(),r._applyLineJoin(this),!i)if(o)o._applyTransform(this,r,e);else{var f=this.getAbsoluteTransform(e).getMatrix();h.transform(f[0],f[1],f[2],f[3],f[4],f[5])}l.call(this,r),r.restore();var g=a.pixelRatio;d&&!s.hitCanvas?(h.save(),h._applyShadow(this),h._applyOpacity(this),h._applyGlobalCompositeOperation(this),h.drawImage(a._canvas,0,0,a.width/g,a.height/g),h.restore()):(h._applyOpacity(this),h._applyGlobalCompositeOperation(this),h.drawImage(a._canvas,0,0,a.width/g,a.height/g))}else{if(h._applyLineJoin(this),!i)if(o)o._applyTransform(this,h,e);else{var v=this.getAbsoluteTransform(e).getMatrix();h.transform(v[0],v[1],v[2],v[3],v[4],v[5])}d&&u&&!s.hitCanvas?(h.save(),i||(h._applyOpacity(this),h._applyGlobalCompositeOperation(this)),h._applyShadow(this),l.call(this,h),h.restore(),this.hasFill()&&this.getShadowForStrokeEnabled()&&l.call(this,h)):d&&!s.hitCanvas?(h.save(),i||(h._applyOpacity(this),h._applyGlobalCompositeOperation(this)),h._applyShadow(this),l.call(this,h),h.restore()):(i||(h._applyOpacity(this),h._applyGlobalCompositeOperation(this)),l.call(this,h))}return h.restore(),this},drawHit:function(t,e,i){var n=this.getLayer(),a=t||n.hitCanvas,r=a.getContext(),o=this.hitFunc()||this.sceneFunc(),s=this._cache.canvas,h=s&&s.hit;if(!this.shouldDrawHit(a))return this;if(n&&n.clearHitCache(),h)return r.save(),n._applyTransform(this,r,e),this._drawCachedHitCanvas(r),r.restore(),this;if(!o)return this;if(r.save(),r._applyLineJoin(this),!i)if(n)n._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(t){var e,i,n,a,r,o=t||0,s=this._cache.canvas,h=this._getCachedSceneCanvas(),c=s.hit,l=c.getContext(),d=c.getWidth(),u=c.getHeight();l.clear(),l.drawImage(h._canvas,0,0,d,u);try{for(n=(i=(e=l.getImageData(0,0,d,u)).data).length,a=f.Util._hexToRgb(this.colorKey),r=0;r<n;r+=4)o<i[r+3]?(i[r]=a.r,i[r+1]=a.g,i[r+2]=a.b,i[r+3]=255):i[r+3]=0;l.putImageData(e,0,0)}catch(t){f.Util.error("Unable to draw hit graph from cached scene canvas. "+t.message)}return this}}),f.Util.extend(f.Shape,f.Node),f.Factory.addGetterSetter(f.Shape,"stroke"),f.Factory.addGetterSetter(f.Shape,"strokeWidth",2),f.Factory.addGetterSetter(f.Shape,"strokeHitEnabled",!0),f.Factory.addGetterSetter(f.Shape,"perfectDrawEnabled",!0),f.Factory.addGetterSetter(f.Shape,"shadowForStrokeEnabled",!0),f.Factory.addGetterSetter(f.Shape,"lineJoin"),f.Factory.addGetterSetter(f.Shape,"lineCap"),f.Factory.addGetterSetter(f.Shape,"sceneFunc"),f.Factory.addGetterSetter(f.Shape,"hitFunc"),f.Factory.addGetterSetter(f.Shape,"dash"),f.Factory.addGetterSetter(f.Shape,"dashOffset",0),f.Factory.addGetterSetter(f.Shape,"shadowColor"),f.Factory.addGetterSetter(f.Shape,"shadowBlur"),f.Factory.addGetterSetter(f.Shape,"shadowOpacity"),f.Factory.addComponentsGetterSetter(f.Shape,"shadowOffset",["x","y"]),f.Factory.addGetterSetter(f.Shape,"shadowOffsetX",0),f.Factory.addGetterSetter(f.Shape,"shadowOffsetY",0),f.Factory.addGetterSetter(f.Shape,"fillPatternImage"),f.Factory.addGetterSetter(f.Shape,"fill"),f.Factory.addGetterSetter(f.Shape,"fillPatternX",0),f.Factory.addGetterSetter(f.Shape,"fillPatternY",0),f.Factory.addGetterSetter(f.Shape,"fillLinearGradientColorStops"),f.Factory.addGetterSetter(f.Shape,"strokeLinearGradientColorStops"),f.Factory.addGetterSetter(f.Shape,"fillRadialGradientStartRadius",0),f.Factory.addGetterSetter(f.Shape,"fillRadialGradientEndRadius",0),f.Factory.addGetterSetter(f.Shape,"fillRadialGradientColorStops"),f.Factory.addGetterSetter(f.Shape,"fillPatternRepeat","repeat"),f.Factory.addGetterSetter(f.Shape,"fillEnabled",!0),f.Factory.addGetterSetter(f.Shape,"strokeEnabled",!0),f.Factory.addGetterSetter(f.Shape,"shadowEnabled",!0),f.Factory.addGetterSetter(f.Shape,"dashEnabled",!0),f.Factory.addGetterSetter(f.Shape,"strokeScaleEnabled",!0),f.Factory.addGetterSetter(f.Shape,"fillPriority","color"),f.Factory.addComponentsGetterSetter(f.Shape,"fillPatternOffset",["x","y"]),f.Factory.addGetterSetter(f.Shape,"fillPatternOffsetX",0),f.Factory.addGetterSetter(f.Shape,"fillPatternOffsetY",0),f.Factory.addComponentsGetterSetter(f.Shape,"fillPatternScale",["x","y"]),f.Factory.addGetterSetter(f.Shape,"fillPatternScaleX",1),f.Factory.addGetterSetter(f.Shape,"fillPatternScaleY",1),f.Factory.addComponentsGetterSetter(f.Shape,"fillLinearGradientStartPoint",["x","y"]),f.Factory.addComponentsGetterSetter(f.Shape,"strokeLinearGradientStartPoint",["x","y"]),f.Factory.addGetterSetter(f.Shape,"fillLinearGradientStartPointX",0),f.Factory.addGetterSetter(f.Shape,"strokeLinearGradientStartPointX",0),f.Factory.addGetterSetter(f.Shape,"fillLinearGradientStartPointY",0),f.Factory.addGetterSetter(f.Shape,"strokeLinearGradientStartPointY",0),f.Factory.addComponentsGetterSetter(f.Shape,"fillLinearGradientEndPoint",["x","y"]),f.Factory.addComponentsGetterSetter(f.Shape,"strokeLinearGradientEndPoint",["x","y"]),f.Factory.addGetterSetter(f.Shape,"fillLinearGradientEndPointX",0),f.Factory.addGetterSetter(f.Shape,"strokeLinearGradientEndPointX",0),f.Factory.addGetterSetter(f.Shape,"fillLinearGradientEndPointY",0),f.Factory.addGetterSetter(f.Shape,"strokeLinearGradientEndPointY",0),f.Factory.addComponentsGetterSetter(f.Shape,"fillRadialGradientStartPoint",["x","y"]),f.Factory.addGetterSetter(f.Shape,"fillRadialGradientStartPointX",0),f.Factory.addGetterSetter(f.Shape,"fillRadialGradientStartPointY",0),f.Factory.addComponentsGetterSetter(f.Shape,"fillRadialGradientEndPoint",["x","y"]),f.Factory.addGetterSetter(f.Shape,"fillRadialGradientEndPointX",0),f.Factory.addGetterSetter(f.Shape,"fillRadialGradientEndPointY",0),f.Factory.addGetterSetter(f.Shape,"fillPatternRotation",0),f.Factory.backCompat(f.Shape,{dashArray:"dash",getDashArray:"getDash",setDashArray:"getDash",drawFunc:"sceneFunc",getDrawFunc:"getSceneFunc",setDrawFunc:"setSceneFunc",drawHitFunc:"hitFunc",getDrawHitFunc:"getHitFunc",setDrawHitFunc:"setHitFunc"}),f.Collection.mapMethods(f.Shape)}(Konva),function(){"use strict";var i="mouseout",n="mouseleave",a="mouseover",r="mousemove",o="mousedown",s="mouseup",h="dblclick",c="touchstart",l="touchend",d="touchmove",u="_",e=[o,r,s,i,c,d,l,a,"wheel","contextmenu"],f=e.length;function g(e,i){e.content.addEventListener(i,function(t){e[u+i](t)},!1)}Konva.Stage=function(t){this.___init(t)},Konva.Util.addMethods(Konva.Stage,{___init:function(t){this.nodeType="Stage",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("string"==typeof t){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("container",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,i=e.length;for(t=0;t<i;t++)e[t].clear();return this},clone:function(t){return t||(t={}),t.container=Konva.document.createElement("div"),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-1<e&&Konva.stages.splice(e,1),this},getPointerPosition:function(){return this.pointerPos},getStage:function(){return this},getContent:function(){return this.content},toDataURL:function(t){var e=(t=t||{}).mimeType||null,i=t.quality||null,n=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;(n||a)&&o.translate(-1*n,-1*a),s.each(function(t){var e=t.getCanvas().getWidth(),i=t.getCanvas().getHeight(),n=t.getCanvas().getPixelRatio();o.drawImage(t.getCanvas()._canvas,0,0,e/n,i/n)});var h=r.toDataURL(e,i);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 i,n,a=this.getChildren();for(i=a.length-1;0<=i;i--)if(n=a[i].getIntersection(t,e))return n;return null},_resizeDOM:function(){if(this.content){var t,e,i=this.getWidth(),n=this.getHeight(),a=this.getChildren(),r=a.length;for(this.content.style.width=i+"px",this.content.style.height=n+"px",this.bufferCanvas.setSize(i,n),this.bufferHitCanvas.setSize(i,n),t=0;t<r;t++)(e=a[t]).setSize(i,n),e.draw()}},add:function(t){if(1<arguments.length){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(),Konva.isBrowser&&this.content.appendChild(t.canvas._canvas),this},getParent:function(){return null},getLayer:function(){return null},getLayers:function(){return this.getChildren()},_bindContentEvents:function(){if(Konva.isBrowser)for(var t=0;t<f;t++)g(this,e[t])},_mouseover:function(t){Konva.UA.mobile||(this._setPointerPosition(t),this._fire("contentMouseover",{evt:t}))},_mouseout:function(t){if(!Konva.UA.mobile){this._setPointerPosition(t);var e=this.targetShape;e&&!Konva.isDragging()&&(e._fireAndBubble(i,{evt:t}),e._fireAndBubble(n,{evt:t}),this.targetShape=null),this.pointerPos=void 0,this._fire("contentMouseout",{evt:t})}},_mousemove:function(t){return Konva.UA.ieMobile?this._touchmove(t):void 0===t.movementX&&void 0===t.movementY||0!==t.movementY||0!==t.movementX?Konva.UA.mobile?null:(this._setPointerPosition(t),Konva.isDragging()||((e=this.getIntersection(this.getPointerPosition()))&&e.isListening()?Konva.isDragging()||this.targetShape&&this.targetShape._id===e._id?e._fireAndBubble(r,{evt:t}):(this.targetShape&&(this.targetShape._fireAndBubble(i,{evt:t},e),this.targetShape._fireAndBubble(n,{evt:t},e)),e._fireAndBubble(a,{evt:t},this.targetShape),e._fireAndBubble("mouseenter",{evt:t},this.targetShape),this.targetShape=e):(this.targetShape&&!Konva.isDragging()&&(this.targetShape._fireAndBubble(i,{evt:t}),this.targetShape._fireAndBubble(n,{evt:t}),this.targetShape=null),this._fire(r,{evt:t,target:this,currentTarget:this})),this._fire("contentMousemove",{evt:t})),void(t.cancelable&&t.preventDefault())):null;var e},_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)._fireAndBubble(o,{evt:t}):this._fire(o,{evt:t,target:this,currentTarget:this}),this._fire("contentMousedown",{evt:t})}t.cancelable&&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()),i=this.clickStartShape,n=this.clickEndShape,a=!1,r=Konva.DD;Konva.inDblClickWindow?(a=!0,Konva.inDblClickWindow=!1):r&&r.justDragged?r&&(r.justDragged=!1):Konva.inDblClickWindow=!0,setTimeout(function(){Konva.inDblClickWindow=!1},Konva.dblClickWindow),e&&e.isListening()?((this.clickEndShape=e)._fireAndBubble(s,{evt:t}),Konva.listenClickTap&&i&&i._id===e._id&&(e._fireAndBubble("click",{evt:t}),a&&n&&n._id===e._id&&e._fireAndBubble(h,{evt:t}))):(this._fire(s,{evt:t,target:this,currentTarget:this}),this._fire("click",{evt:t,target:this,currentTarget:this}),a&&this._fire(h,{evt:t,target:this,currentTarget:this})),this._fire("contentMouseup",{evt:t}),Konva.listenClickTap&&(this._fire("contentClick",{evt:t}),a&&this._fire("contentDblclick",{evt:t})),Konva.listenClickTap=!1}t.cancelable&&t.preventDefault()},_contextmenu:function(t){this._fire("contentContextmenu",{evt:t})},_touchstart:function(t){this._setPointerPosition(t);var e=this.getIntersection(this.getPointerPosition());Konva.listenClickTap=!0,e&&e.isListening()?((this.tapStartShape=e)._fireAndBubble(c,{evt:t}),e.isListening()&&e.preventDefault()&&t.cancelable&&t.preventDefault()):this._fire(c,{evt:t,target:this,currentTarget:this}),this._fire("contentTouchstart",{evt:t})},_touchend:function(t){this._setPointerPosition(t);var e=this.getIntersection(this.getPointerPosition()),i=!1;Konva.inDblClickWindow?(i=!0,Konva.inDblClickWindow=!1):Konva.inDblClickWindow=!0,setTimeout(function(){Konva.inDblClickWindow=!1},Konva.dblClickWindow),e&&e.isListening()?(e._fireAndBubble(l,{evt:t}),Konva.listenClickTap&&this.tapStartShape&&e._id===this.tapStartShape._id&&(e._fireAndBubble("tap",{evt:t}),i&&e._fireAndBubble("dbltap",{evt:t})),e.isListening()&&e.preventDefault()&&t.cancelable&&t.preventDefault()):(this._fire(l,{evt:t,target:this,currentTarget:this}),this._fire("tap",{evt:t,target:this,currentTarget:this}),i&&this._fire("dbltap",{evt:t,target:this,currentTarget:this})),this._fire("contentTouchend",{evt:t}),Konva.listenClickTap&&(this._fire("contentTap",{evt:t}),i&&this._fire("contentDbltap",{evt:t})),Konva.listenClickTap=!1},_touchmove:function(t){this._setPointerPosition(t);var e,i=Konva.DD;Konva.isDragging()||((e=this.getIntersection(this.getPointerPosition()))&&e.isListening()?(e._fireAndBubble(d,{evt:t}),e.isListening()&&e.preventDefault()&&t.cancelable&&t.preventDefault()):this._fire(d,{evt:t,target:this,currentTarget:this}),this._fire("contentTouchmove",{evt:t})),i&&Konva.isDragging()&&Konva.DD.node.preventDefault()&&t.cancelable&&t.preventDefault()},_wheel:function(t){this._setPointerPosition(t);var e=this.getIntersection(this.getPointerPosition());e&&e.isListening()&&e._fireAndBubble("wheel",{evt:t}),this._fire("contentWheel",{evt:t})},_setPointerPosition:function(t){var e=this._getContentPosition(),i=null,n=null;if(void 0!==(t=t||window.event).touches){if(0<t.touches.length){var a=t.touches[0];i=a.clientX-e.left,n=a.clientY-e.top}}else i=t.clientX-e.left,n=t.clientY-e.top;null!==i&&null!==n&&(this.pointerPos={x:i,y:n})},_getContentPosition:function(){var t=this.content.getBoundingClientRect?this.content.getBoundingClientRect():{top:0,left:0};return{top:t.top,left:t.left}},_buildDOM:function(){if(this.bufferCanvas=new Konva.SceneCanvas,this.bufferHitCanvas=new Konva.HitCanvas({pixelRatio:1}),Konva.isBrowser){var t=this.getContainer();if(!t)throw"Stage has no container. A container is required.";t.innerHTML="",this.content=Konva.document.createElement("div"),this.content.style.position="relative",this.content.className="konvajs-content",this.content.setAttribute("role","presentation"),t.appendChild(this.content),this._resizeDOM()}},_onContent:function(t,e){var i,n,a=t.split(" "),r=a.length;for(i=0;i<r;i++)n=a[i],this.content.addEventListener(n,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(i){"use strict";i.BaseLayer=function(t){this.___init(t)},i.Util.addMethods(i.BaseLayer,{___init:function(t){this.nodeType="Layer",i.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){i.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(){i.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(){if(!i.Node.prototype.moveUp.call(this))return this;var t=this.getStage();return t&&(t.content.removeChild(this.getCanvas()._canvas),this.index<t.getChildren().length-1?t.content.insertBefore(this.getCanvas()._canvas,t.getChildren()[this.index+1].getCanvas()._canvas):t.content.appendChild(this.getCanvas()._canvas)),this},moveDown:function(){if(i.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(i.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 i.Node.prototype.remove.call(this),t&&t.parentNode&&i.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(){i.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(){i.Util.warn('Can not change height of layer. Use "stage.height(value)" function instead.')},_applyTransform:function(t,e,i){var n=t.getAbsoluteTransform(i).getMatrix();e.transform(n[0],n[1],n[2],n[3],n[4],n[5])}}),i.Util.extend(i.BaseLayer,i.Container),i.Factory.addGetterSetter(i.BaseLayer,"clearBeforeDraw",!0),i.Collection.mapMethods(i.BaseLayer)}(Konva),function(){"use strict";var h=[{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}],c=h.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 i,n,a,r;if(!this.hitGraphEnabled()||!this.isVisible())return null;for(var o=1,s=!1;;){for(n=0;n<c;n++){if(a=h[n],(r=(i=this._getIntersection({x:t.x+a.x*o,y:t.y+a.y*o})).shape)&&e)return r.findAncestor(e,!0);if(r)return r;if(s=!!i.antialiased,!i.antialiased)break}if(!s)return null;o+=1}},_getImageData:function(t,e){var i=this.hitCanvas.width||1,n=this.hitCanvas.height||1,a=Math.round(e)*i+Math.round(t);return this._hitImageData||(this._hitImageData=this.hitCanvas.context.getImageData(0,0,i,n)),[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(t){var e,i,n=this.hitCanvas.pixelRatio,a=this.hitCanvas.context.getImageData(Math.round(t.x*n),Math.round(t.y*n),1,1).data,r=a[3];return 255===r?(e=Konva.Util._rgbToHex(a[0],a[1],a[2]),(i=Konva.shapes["#"+e])?{shape:i}:{antialiased:!0}):0<r?{antialiased:!0}:{}},drawScene:function(t,e){var i=this.getLayer(),n=t||i&&i.getCanvas();return this._fire("beforeDraw",{node:this}),this.getClearBeforeDraw()&&n.getContext().clear(),Konva.Container.prototype.drawScene.call(this,n,e),this._fire("draw",{node:this}),this},drawHit:function(t,e){var i=this.getLayer(),n=t||i&&i.hitCanvas;return i&&i.getClearBeforeDraw()&&i.getHitCanvas().getContext().clear(),Konva.Container.prototype.drawHit.call(this,n,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){"Shape"!==t.getType()&&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(),i=t||e&&e.getCanvas();return this.getClearBeforeDraw()&&i.getContext().clear(),Konva.Container.prototype.drawScene.call(this,i),this},draw:function(){return this.drawScene(),this},setVisible:function(t){return Konva.Node.prototype.setVisible.call(this,t),this.getCanvas()._canvas.style.display=t?"block":"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(n){"use strict";var l=n.global.performance&&n.global.performance.now?function(){return n.global.performance.now()}:function(){return(new Date).getTime()};function t(t){setTimeout(t,1e3/60)}var e=n.global.requestAnimationFrame||n.global.webkitRequestAnimationFrame||n.global.mozRequestAnimationFrame||n.global.oRequestAnimationFrame||n.global.msRequestAnimationFrame||t;function i(){return e.apply(n.global,arguments)}n.Animation=function(t,e){var i=n.Animation;this.func=t,this.setLayers(e),this.id=i.animIdCounter++,this.frame={time:0,timeDiff:0,lastTime:l()}},n.Animation.prototype={setLayers:function(t){var e=[];return e=t?0<t.length?t:[t]:[],this.layers=e,this},getLayers:function(){return this.layers},addLayer:function(t){var e,i=this.layers,n=i.length;for(e=0;e<n;e++)if(i[e]._id===t._id)return!1;return this.layers.push(t),!0},isRunning:function(){var t,e=n.Animation.animations,i=e.length;for(t=0;t<i;t++)if(e[t].id===this.id)return!0;return!1},start:function(){var t=n.Animation;return this.stop(),this.frame.timeDiff=0,this.frame.lastTime=l(),t._addAnimation(this),this},stop:function(){return n.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}},n.Animation.animations=[],n.Animation.animIdCounter=0,n.Animation.animRunning=!1,n.Animation._addAnimation=function(t){this.animations.push(t),this._handleAnimation()},n.Animation._removeAnimation=function(t){var e,i=t.id,n=this.animations,a=n.length;for(e=0;e<a;e++)if(n[e].id===i){this.animations.splice(e,1);break}},n.Animation._runFrames=function(){var t,e,i,n,a,r,o,s,h={},c=this.animations;for(n=0;n<c.length;n++)if(e=(t=c[n]).layers,i=t.func,t._updateFrameObject(l()),r=e.length,!i||!1!==i.call(t,t.frame))for(a=0;a<r;a++)void 0!==(o=e[a])._id&&(h[o._id]=o);for(s in h)h.hasOwnProperty(s)&&h[s].draw()},n.Animation._animationLoop=function(){var t=n.Animation;t.animations.length?(t._runFrames(),i(t._animationLoop)):t.animRunning=!1},n.Animation._handleAnimation=function(){this.animRunning||(this.animRunning=!0,i(this._animationLoop))},n.BaseLayer.prototype.batchDraw=function(){var t=this,e=n.Animation;return this.batchAnim||(this.batchAnim=new e(function(){t.batchAnim.stop()},this)),this.batchAnim.isRunning()||this.batchAnim.start(),this},n.Stage.prototype.batchDraw=function(){return this.getChildren().each(function(t){t.batchDraw()}),this}}(Konva),function(){"use strict";var c={node:1,duration:1,easing:1,onFinish:1,yoyo:1},l=0,u=["fill","stroke","shadowColor"],d=function(t,e,i,n,a,r,o){this.prop=t,this.propFunc=e,this.begin=n,this._pos=n,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=i,this._change=a-this.begin,this.pause()};d.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=2,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire("onPlay")},reverse:function(){this.state=3,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;2===this.state?this.setTime(t):3===this.state&&this.setTime(this.duration-t)},pause:function(){this.state=1,this.fire("onPause")},getTimer:function(){return(new Date).getTime()}},Konva.Tween=function(t){var e,i,n=this,a=t.node,r=a._id,o=t.easing||Konva.Easings.Linear,s=!!t.yoyo;e=void 0===t.duration?1:0===t.duration?.001:t.duration,this.node=a,this._id=l++;var h=a.getLayer()||(a instanceof Konva.Stage?a.getLayers():null);for(i in h||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(){n.tween.onEnterFrame()},h),this.tween=new d(i,function(t){n._tweenFunc(t)},o,0,1,1e3*e,s),this._addListeners(),Konva.Tween.attrs[r]||(Konva.Tween.attrs[r]={}),Konva.Tween.attrs[r][this._id]||(Konva.Tween.attrs[r][this._id]={}),Konva.Tween.tweens[r]||(Konva.Tween.tweens[r]={}),t)void 0===c[i]&&this._addAttr(i,t[i]);this.reset(),this.onFinish=t.onFinish,this.onReset=t.onReset},Konva.Tween.attrs={},Konva.Tween.tweens={},Konva.Tween.prototype={_addAttr:function(t,e){var i,n,a,r,o,s,h,c=this.node,l=c._id;if((a=Konva.Tween.tweens[l][t])&&delete Konva.Tween.attrs[l][a][t],i=c.getAttr(t),Konva.Util._isArray(e))for(n=[],o=Math.max(e.length,i.length),"points"===t&&e.length!==i.length&&(e.length>i.length?(h=i,i=Konva.Util._prepareArrayForTween(i,e,c.closed())):(s=e,e=Konva.Util._prepareArrayForTween(e,i,c.closed()))),r=0;r<o;r++)n.push(e[r]-i[r]);else if(-1!==u.indexOf(t)){i=Konva.Util.colorToRGBA(i);var d=Konva.Util.colorToRGBA(e);n={r:d.r-i.r,g:d.g-i.g,b:d.b-i.b,a:d.a-i.a}}else n=e-i;Konva.Tween.attrs[l][this._id][t]={start:i,diff:n,end:e,trueEnd:s,trueStart:h},Konva.Tween.tweens[l][t]=this._id},_tweenFunc:function(t){var e,i,n,a,r,o,s,h,c=this.node,l=Konva.Tween.attrs[c._id][this._id];for(e in l){if(n=(i=l[e]).start,a=i.diff,h=i.end,Konva.Util._isArray(n))for(r=[],s=Math.max(n.length,h.length),o=0;o<s;o++)r.push((n[o]||0)+a[o]*t);else r=-1!==u.indexOf(e)?"rgba("+Math.round(n.r+a.r*t)+","+Math.round(n.g+a.g*t)+","+Math.round(n.b+a.b*t)+","+(n.a+a.a*t)+")":n+a*t;c.setAttr(e,r)}},_addListeners:function(){var i=this;this.tween.onPlay=function(){i.anim.start()},this.tween.onReverse=function(){i.anim.start()},this.tween.onPause=function(){i.anim.stop()},this.tween.onFinish=function(){var t=i.node,e=Konva.Tween.attrs[t._id][i._id];e.points&&e.points.trueEnd&&t.points(e.points.trueEnd),i.onFinish&&i.onFinish.call(i)},this.tween.onReset=function(){var t=i.node,e=Konva.Tween.attrs[t._id][i._id];e.points&&e.points.trueStart&&t.points(e.points.trueStart),i.onReset&&i.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,i=this._id,n=Konva.Tween.tweens[e];for(t in this.pause(),n)delete Konva.Tween.tweens[e][t];delete Konva.Tween.attrs[e][i]}},Konva.Node.prototype.to=function(t){var e=t.onFinish;t.node=this,t.onFinish=function(){this.destroy(),e&&e()},new Konva.Tween(t).play()},Konva.Easings={BackEaseIn:function(t,e,i,n){return i*(t/=n)*t*(2.70158*t-1.70158)+e},BackEaseOut:function(t,e,i,n){return i*((t=t/n-1)*t*(2.70158*t+1.70158)+1)+e},BackEaseInOut:function(t,e,i,n){var a=1.70158;return(t/=n/2)<1?i/2*(t*t*((1+(a*=1.525))*t-a))+e:i/2*((t-=2)*t*((1+(a*=1.525))*t+a)+2)+e},ElasticEaseIn:function(t,e,i,n,a,r){var o=0;return 0===t?e:1==(t/=n)?e+i:(r||(r=.3*n),!a||a<Math.abs(i)?(a=i,o=r/4):o=r/(2*Math.PI)*Math.asin(i/a),-a*Math.pow(2,10*(t-=1))*Math.sin((t*n-o)*(2*Math.PI)/r)+e)},ElasticEaseOut:function(t,e,i,n,a,r){var o=0;return 0===t?e:1==(t/=n)?e+i:(r||(r=.3*n),!a||a<Math.abs(i)?(a=i,o=r/4):o=r/(2*Math.PI)*Math.asin(i/a),a*Math.pow(2,-10*t)*Math.sin((t*n-o)*(2*Math.PI)/r)+i+e)},ElasticEaseInOut:function(t,e,i,n,a,r){var o=0;return 0===t?e:2==(t/=n/2)?e+i:(r||(r=n*(.3*1.5)),!a||a<Math.abs(i)?(a=i,o=r/4):o=r/(2*Math.PI)*Math.asin(i/a),t<1?a*Math.pow(2,10*(t-=1))*Math.sin((t*n-o)*(2*Math.PI)/r)*-.5+e:a*Math.pow(2,-10*(t-=1))*Math.sin((t*n-o)*(2*Math.PI)/r)*.5+i+e)},BounceEaseOut:function(t,e,i,n){return(t/=n)<1/2.75?i*(7.5625*t*t)+e:t<2/2.75?i*(7.5625*(t-=1.5/2.75)*t+.75)+e:t<2.5/2.75?i*(7.5625*(t-=2.25/2.75)*t+.9375)+e:i*(7.5625*(t-=2.625/2.75)*t+.984375)+e},BounceEaseIn:function(t,e,i,n){return i-Konva.Easings.BounceEaseOut(n-t,0,i,n)+e},BounceEaseInOut:function(t,e,i,n){return t<n/2?.5*Konva.Easings.BounceEaseIn(2*t,0,i,n)+e:.5*Konva.Easings.BounceEaseOut(2*t-n,0,i,n)+.5*i+e},EaseIn:function(t,e,i,n){return i*(t/=n)*t+e},EaseOut:function(t,e,i,n){return-i*(t/=n)*(t-2)+e},EaseInOut:function(t,e,i,n){return(t/=n/2)<1?i/2*t*t+e:-i/2*(--t*(t-2)-1)+e},StrongEaseIn:function(t,e,i,n){return i*(t/=n)*t*t*t*t+e},StrongEaseOut:function(t,e,i,n){return i*((t=t/n-1)*t*t*t*t+1)+e},StrongEaseInOut:function(t,e,i,n){return(t/=n/2)<1?i/2*t*t*t*t*t+e:i/2*((t-=2)*t*t*t*t+2)+e},Linear:function(t,e,i,n){return i*t/n+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,i=e.node;if(i){if(!e.isDragging){var n=i.getStage().getPointerPosition();n||(i.getStage()._setPointerPosition(t),n=i.getStage().getPointerPosition());var a=i.dragDistance();if(Math.max(Math.abs(n.x-e.startPointerPos.x),Math.abs(n.y-e.startPointerPos.y))<a)return}i.getStage()._setPointerPosition(t),i._setDragPosition(t),e.isDragging||(e.isDragging=!0,i.fire("dragstart",{type:"dragstart",target:i,evt:t},!0)),i.fire("dragmove",{type:"dragmove",target:i,evt:t},!0)}},_endDragBefore:function(t){var e,i=Konva.DD,n=i.node;n&&(e=n.getLayer(),i.anim.stop(),i.isDragging&&(i.isDragging=!1,i.justDragged=!0,Konva.listenClickTap=!1,t&&(t.dragEndNode=n)),delete i.node,(n.getLayer()||e||n instanceof Konva.Stage)&&(e||n).draw())},_endDragAfter:function(t){var e=(t=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(),i=this.getLayer(),n=e.getPointerPosition(),a=this.getAbsolutePosition();n&&(t.node&&t.node.stopDrag(),t.node=this,t.startPointerPos=n,t.offset.x=n.x-a.x,t.offset.y=n.y-a.y,t.anim.setLayers(i||this.getLayers()),t.anim.start(),this._setDragPosition())},Konva.Node.prototype._setDragPosition=function(t){var e=Konva.DD,i=this.getStage().getPointerPosition(),n=this.getDragBoundFunc();if(i){var a={x:i.x-e.offset.x,y:i.y-e.offset.y};void 0!==n&&(a=n.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 e=Konva.Node.prototype.remove;if(Konva.Node.prototype.__originalRemove=e,Konva.Node.prototype.remove=function(){var t=Konva.DD;t.node&&t.node._id===this._id&&this.stopDrag(),e.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 e=this;this._dragCleanup(),"Stage"===this.getClassName()?this.on("contentMousedown.konva contentTouchstart.konva",function(t){Konva.DD.node||e.startDrag(t)}):this.on("mousedown.konva touchstart.konva",function(t){1!==t.evt.button&&2!==t.evt.button&&(Konva.DD.node||e.startDrag(t))})},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"),Konva.isBrowser){var t=Konva.document.documentElement;t.addEventListener("mouseup",Konva.DD._endDragBefore,!0),t.addEventListener("touchend",Konva.DD._endDragBefore,!0),t.addEventListener("mousemove",Konva.DD._drag),t.addEventListener("touchmove",Konva.DD._drag),t.addEventListener("mouseup",Konva.DD._endDragAfter,!1),t.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(),i=this.getWidth(),n=this.getHeight();t.beginPath(),e?(e=Math.min(e,i/2,n/2),t.moveTo(e,0),t.lineTo(i-e,0),t.arc(i-e,e,e,3*Math.PI/2,0,!1),t.lineTo(i,n-e),t.arc(i-e,n-e,e,0,Math.PI/2,!1),t.lineTo(e,n),t.arc(e,n-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,i,n),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(e){"use strict";var i=2*Math.PI-1e-4;e.Circle=function(t){this.___init(t)},e.Circle.prototype={_centroid:!0,___init:function(t){e.Shape.call(this,t),this.className="Circle",this.sceneFunc(this._sceneFunc)},_sceneFunc:function(t){t.beginPath(),t.arc(0,0,this.getRadius(),0,i,!1),t.closePath(),t.fillStrokeShape(this)},getWidth:function(){return 2*this.getRadius()},getHeight:function(){return 2*this.getRadius()},setWidth:function(t){e.Node.prototype.setWidth.call(this,t),this.radius()!==t/2&&this.setRadius(t/2)},setHeight:function(t){e.Node.prototype.setHeight.call(this,t),this.radius()!==t/2&&this.setRadius(t/2)}},e.Util.extend(e.Circle,e.Shape),e.Factory.addGetterSetter(e.Circle,"radius",0),e.Factory.addOverloadedGetterSetter(e.Circle,"radius"),e.Collection.mapMethods(e.Circle)}(Konva),function(){"use strict";var n=2*Math.PI-1e-4;Konva.Ellipse=function(t){this.___init(t)},Konva.Ellipse.prototype={_centroid:!0,___init:function(t){Konva.Shape.call(this,t),this.className="Ellipse",this.sceneFunc(this._sceneFunc)},_sceneFunc:function(t){var e=this.getRadiusX(),i=this.getRadiusY();t.beginPath(),t.save(),e!==i&&t.scale(1,i/e),t.arc(0,0,e,0,n,!1),t.restore(),t.closePath(),t.fillStrokeShape(this)},getWidth:function(){return 2*this.getRadiusX()},getHeight:function(){return 2*this.getRadiusY()},setWidth:function(t){Konva.Node.prototype.setWidth.call(this,t),this.setRadius({x:t/2})},setHeight:function(t){Konva.Node.prototype.setHeight.call(this,t),this.setRadius({y:t/2})}},Konva.Util.extend(Konva.Ellipse,Konva.Shape),Konva.Factory.addComponentsGetterSetter(Konva.Ellipse,"radius",["x","y"]),Konva.Factory.addGetterSetter(Konva.Ellipse,"radiusX",0),Konva.Factory.addGetterSetter(Konva.Ellipse,"radiusY",0),Konva.Collection.mapMethods(Konva.Ellipse)}(),function(){"use strict";var e=2*Math.PI-1e-4;Konva.Ring=function(t){this.___init(t)},Konva.Ring.prototype={_centroid:!0,___init:function(t){Konva.Shape.call(this,t),this.className="Ring",this.sceneFunc(this._sceneFunc)},_sceneFunc:function(t){t.beginPath(),t.arc(0,0,this.getInnerRadius(),0,e,!1),t.moveTo(this.getOuterRadius(),0),t.arc(0,0,this.getOuterRadius(),e,0,!0),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.outerRadius()!==t/2&&this.setOuterRadius(t/2)},setHeight:function(t){Konva.Node.prototype.setHeight.call(this,t),this.outerRadius()!==t/2&&this.setOuterRadius(t/2)},setOuterRadius:function(t){this._setAttr("outerRadius",t),this.setWidth(2*t),this.setHeight(2*t)}},Konva.Util.extend(Konva.Ring,Konva.Shape),Konva.Factory.addGetterSetter(Konva.Ring,"innerRadius",0),Konva.Factory.addGetter(Konva.Ring,"outerRadius",0),Konva.Factory.addOverloadedGetterSetter(Konva.Ring,"outerRadius"),Konva.Collection.mapMethods(Konva.Ring)}(),function(){"use strict";Konva.Wedge=function(t){this.___init(t)},Konva.Wedge.prototype={_centroid:!0,___init:function(t){Konva.Shape.call(this,t),this.className="Wedge",this.sceneFunc(this._sceneFunc)},_sceneFunc:function(t){t.beginPath(),t.arc(0,0,this.getRadius(),0,Konva.getAngle(this.getAngle()),this.getClockwise()),t.lineTo(0,0),t.closePath(),t.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.Wedge,Konva.Shape),Konva.Factory.addGetterSetter(Konva.Wedge,"radius",0),Konva.Factory.addGetterSetter(Konva.Wedge,"angle",0),Konva.Factory.addGetterSetter(Konva.Wedge,"clockwise",!1),Konva.Factory.backCompat(Konva.Wedge,{angleDeg:"angle",getAngleDeg:"getAngle",setAngleDeg:"setAngle"}),Konva.Collection.mapMethods(Konva.Wedge)}(),function(n){"use strict";n.Arc=function(t){this.___init(t)},n.Arc.prototype={_centroid:!0,___init:function(t){n.Shape.call(this,t),this.className="Arc",this.sceneFunc(this._sceneFunc)},_sceneFunc:function(t){var e=n.getAngle(this.angle()),i=this.clockwise();t.beginPath(),t.arc(0,0,this.getOuterRadius(),0,e,i),t.arc(0,0,this.getInnerRadius(),e,0,!i),t.closePath(),t.fillStrokeShape(this)},getWidth:function(){return 2*this.getOuterRadius()},getHeight:function(){return 2*this.getOuterRadius()},setWidth:function(t){n.Node.prototype.setWidth.call(this,t),this.getOuterRadius()!==t/2&&this.setOuterRadius(t/2)},setHeight:function(t){n.Node.prototype.setHeight.call(this,t),this.getOuterRadius()!==t/2&&this.setOuterRadius(t/2)}},n.Util.extend(n.Arc,n.Shape),n.Factory.addGetterSetter(n.Arc,"innerRadius",0),n.Factory.addGetterSetter(n.Arc,"outerRadius",0),n.Factory.addGetterSetter(n.Arc,"angle",0),n.Factory.addGetterSetter(n.Arc,"clockwise",!1),n.Collection.mapMethods(n.Arc)}(Konva),function(){"use strict";Konva.Image=function(t){this.___init(t)},Konva.Image.prototype={___init:function(t){Konva.Shape.call(this,t),this.className="Image",this.sceneFunc(this._sceneFunc),this.hitFunc(this._hitFunc)},_useBufferCanvas:function(){return(this.hasShadow()||1!==this.getAbsoluteOpacity())&&this.hasStroke()&&this.getStage()},_sceneFunc:function(t){var e,i,n,a=this.getWidth(),r=this.getHeight(),o=this.getImage();o&&(e=this.getCropWidth(),i=this.getCropHeight(),n=e&&i?[o,this.getCropX(),this.getCropY(),e,i,0,0,a,r]:[o,0,0,a,r]),(this.hasFill()||this.hasStroke())&&(t.beginPath(),t.rect(0,0,a,r),t.closePath(),t.fillStrokeShape(this)),o&&t.drawImage.apply(t,n)},_hitFunc:function(t){var e=this.getWidth(),i=this.getHeight();t.beginPath(),t.rect(0,0,e,i),t.closePath(),t.fillStrokeShape(this)},getWidth:function(){var t=this.getImage();return this.attrs.width||(t?t.width:0)},getHeight:function(){var t=this.getImage();return this.attrs.height||(t?t.height:0)}},Konva.Util.extend(Konva.Image,Konva.Shape),Konva.Factory.addGetterSetter(Konva.Image,"image"),Konva.Factory.addComponentsGetterSetter(Konva.Image,"crop",["x","y","width","height"]),Konva.Factory.addGetterSetter(Konva.Image,"cropX",0),Konva.Factory.addGetterSetter(Konva.Image,"cropY",0),Konva.Factory.addGetterSetter(Konva.Image,"cropWidth",0),Konva.Factory.addGetterSetter(Konva.Image,"cropHeight",0),Konva.Collection.mapMethods(Konva.Image),Konva.Image.fromURL=function(t,e){var i=new Image;i.onload=function(){var t=new Konva.Image({image:i});e(t)},i.src=t}}(),function(){"use strict";var t,A="auto",C="justify",e="2d",i=["fontFamily","fontSize","fontStyle","fontVariant","padding","align","lineHeight","text","width","height","wrap","ellipsis","letterSpacing","resizeToFitX","resizeToFitY","resizeToFitMaxRatio","verticalAlign"],n=i.length;function M(){return t||(t=Konva.Util.createCanvasElement().getContext(e))}function a(t){t.fillText(this.partialText,0,0)}function r(t){t.strokeText(this.partialText,0,0)}Konva.Text=function(t){this.___init(t)},Konva.Text.prototype={___init:function(t){(t=t||{}).fillLinearGradientColorStops||t.fillRadialGradientColorStops||(t.fill=t.fill||"black"),Konva.Shape.call(this,t),this._fillFunc=a,this._strokeFunc=r,this.className="Text",this.resizeToFitX=t.resizeToFitX,this.resizeToFitY=t.resizeToFitY,this.resizeToFitMaxRatio=t.resizeToFitMaxRatio||4,this.verticalAlign=t.verticalAlign,this.resizeToFitX&&this.resizeToFitY&&this.wrap("none");for(var e=0;e<n;e++)this.on(i[e]+"Change.konva",this._setTextData);this._setTextData(),this.sceneFunc(this._sceneFunc),this.hitFunc(this._hitFunc)},_sceneFunc:function(t){var e,i=this.getPadding(),n=this.getTextHeight(),a=this.getLineHeight()*n,r=this.textArr,o=r.length,s=this.getAlign(),h=this.getVerticalAlign(),c=0,l=1,d=1,u=this.getWidth(),f=this.getLetterSpacing(),g=this.textDecoration(),v=this.fill(),p=this.fontSize();for(t.setAttr("font",this._getContextFont()),t.setAttr("textBaseline","middle"),t.setAttr("textAlign","left"),t.save(),this.resizeToFitX&&(l=(u-2*i)/r[0].width)>this.resizeToFitX&&(l=this.resizeToFitX),this.resizeToFitY&&(d=(this.getHeight()-2*i)/(o*a))>this.resizeToFitY&&(d=this.resizeToFitY),d<l?l/d>this.resizeToFitMaxRatio&&(l=d*this.resizeToFitMaxRatio):d/l>this.resizeToFitMaxRatio&&(d=l*this.resizeToFitMaxRatio),"middle"===h?c=(this.getHeight()-o*a*d-2*i)/2:"bottom"===h&&(c=this.getHeight()-o*a*d-2*i),i?(t.translate(i,0),t.translate(0,c+i+n/2)):t.translate(0,c+n/2),e=0;e<o;e++){var m=r[e],y=m.text,_=m.width;if(t.save(),1===l&&1===d||(t.translate(0,-n/2),t.scale(l,d),t.translate(0,n/2)),"right"===s?t.translate((u-_*l-2*i)/l,0):"center"===s&&t.translate((u-_*l-2*i)/l/2,0),-1!==g.indexOf("underline")&&(t.save(),t.beginPath(),t.moveTo(0,Math.round(a/2)),t.lineTo(Math.round(s===C&&e!==o-1?u-2*i:_),Math.round(a/2)),t.lineWidth=p/15,t.strokeStyle=v,t.stroke(),t.restore()),-1!==g.indexOf("line-through")&&(t.save(),t.beginPath(),t.moveTo(0,0),t.lineTo(Math.round(s===C&&e!==o-1?u-2*i:_),0),t.lineWidth=p/15,t.strokeStyle=v,t.stroke(),t.restore()),0!==f||s===C)for(var S=y.split(" ").length-1,K=0;K<y.length;K++){var x=y[K];" "===x&&e!==o-1&&s===C&&t.translate(Math.floor((u-_-2*i)/S),0),this.partialText=x,t.fillStrokeShape(this),t.translate(Math.round(this._getTextSize(x).width)+f,0)}else this.partialText=y,t.fillStrokeShape(this);t.restore(),t.translate(0,a*d)}t.restore()},_hitFunc:function(t){var e=this.getWidth(),i=this.getHeight();t.beginPath(),t.rect(0,0,e,i),t.closePath(),t.fillStrokeShape(this)},setText:function(t){var e=Konva.Util._isString(t)?t:(t||"").toString();return this._setAttr("text",e),this},getWidth:function(){return this.attrs.width===A||void 0===this.attrs.width?this.getTextWidth()+2*this.getPadding():this.attrs.width},getHeight:function(){return this.attrs.height===A||void 0===this.attrs.height?this.getTextHeight()*this.textArr.length*this.getLineHeight()+2*this.getPadding():this.attrs.height},getTextWidth:function(){return this.textWidth},getTextHeight:function(){return this.textHeight},_getTextSize:function(t){var e,i=M(),n=this.getFontSize();return i.save(),i.font=this._getContextFont(),e=i.measureText(t),i.restore(),{width:e.width,height:parseInt(n,10)}},_getContextFont:function(){return Konva.UA.isIE?this.getFontStyle()+" "+this.getFontSize()+"px "+this.getFontFamily():this.getFontStyle()+" "+this.getFontVariant()+" "+this.getFontSize()+"px "+this.getFontFamily()},_addTextLine:function(t){this.align()===C&&(t=t.trim());var e=this._getTextWidth(t);return this.textArr.push({text:t,width:e})},_getTextWidth:function(t){var e=this.getLetterSpacing(),i=t.length;return M().measureText(t).width+(i?e*(i-1):0)},_setTextData:function(){var t=this.getText().split("\n"),e=+this.getFontSize(),i=0,n=this.getLineHeight()*e,a=this.attrs.width,r=this.attrs.height,o=a!==A,s=r!==A,h=this.getPadding(),c=a-2*h,l=r-2*h,d=0,u=this.getWrap(),f="none"!==u,g="char"!==u&&f,v=this.getEllipsis()&&!f;this.textArr=[],M().save(),M().font=this._getContextFont();for(var p=0,m=t.length;p<m;++p){var y=t[p],_=v?this._getTextWidth("…"):0,S=this._getTextWidth(y);if(o&&c<S&&!this.resizeToFitX)for(;0<y.length;){for(var K=0,x=y.length,C="",b=0;K<x;){var w=K+x>>>1,F=y.slice(0,w+1),T=this._getTextWidth(F)+_;T<=c?(K=w+1,C=F+(v?"…":""),b=T):x=w}if(!C)break;if(g){var P=Math.max(C.lastIndexOf(" "),C.lastIndexOf("-"))+1;0<P&&(K=P,C=C.slice(0,K),b=this._getTextWidth(C))}if(this._addTextLine(C),i=Math.max(i,b),d+=n,!f||s&&l<d+n)break;if(0<(y=y.slice(K)).length&&(S=this._getTextWidth(y))<=c){this._addTextLine(y),d+=n,i=Math.max(i,S);break}}else this._addTextLine(y),d+=n,i=Math.max(i,S);if(s&&l<d+n&&!this.resizeToFitY)break}M().restore(),this.textHeight=e,this.textWidth=i}},Konva.Util.extend(Konva.Text,Konva.Shape),Konva.Factory.addGetterSetter(Konva.Text,"fontFamily","Arial"),Konva.Factory.addGetterSetter(Konva.Text,"fontSize",12),Konva.Factory.addGetterSetter(Konva.Text,"fontStyle","normal"),Konva.Factory.addGetterSetter(Konva.Text,"fontVariant","normal"),Konva.Factory.addGetterSetter(Konva.Text,"padding",0),Konva.Factory.addGetterSetter(Konva.Text,"align","left"),Konva.Factory.addGetterSetter(Konva.Text,"verticalAlign","top"),Konva.Factory.addGetterSetter(Konva.Text,"lineHeight",1),Konva.Factory.addGetterSetter(Konva.Text,"wrap","word"),Konva.Factory.addGetterSetter(Konva.Text,"ellipsis",!1),Konva.Factory.addGetterSetter(Konva.Text,"letterSpacing",0),Konva.Factory.addGetter(Konva.Text,"text",""),Konva.Factory.addOverloadedGetterSetter(Konva.Text,"text"),Konva.Factory.addGetterSetter(Konva.Text,"textDecoration",""),Konva.Collection.mapMethods(Konva.Text)}(),function(){"use strict";Konva.Line=function(t){this.___init(t)},Konva.Line.prototype={___init:function(t){Konva.Shape.call(this,t),this.className="Line",this.on("pointsChange.konva tensionChange.konva closedChange.konva bezierChange.konva",function(){this._clearCache("tensionPoints")}),this.sceneFunc(this._sceneFunc)},_sceneFunc:function(t){var e,i,n,a=this.getPoints(),r=a.length,o=this.getTension(),s=this.getClosed(),h=this.getBezier();if(r){if(t.beginPath(),t.moveTo(a[0],a[1]),0!==o&&4<r){for(i=(e=this.getTensionPoints()).length,n=s?0:4,s||t.quadraticCurveTo(e[0],e[1],e[2],e[3]);n<i-2;)t.bezierCurveTo(e[n++],e[n++],e[n++],e[n++],e[n++],e[n++]);s||t.quadraticCurveTo(e[i-2],e[i-1],a[r-2],a[r-1])}else if(h)for(n=2;n<r;)t.bezierCurveTo(a[n++],a[n++],a[n++],a[n++],a[n++],a[n++]);else for(n=2;n<r;n+=2)t.lineTo(a[n],a[n+1]);s?(t.closePath(),t.fillStrokeShape(this)):t.strokeShape(this)}},getTensionPoints:function(){return this._getCache("tensionPoints",this._getTensionPoints)},_getTensionPoints:function(){return this.getClosed()?this._getTensionPointsClosed():Konva.Util._expandPoints(this.getPoints(),this.getTension())},_getTensionPointsClosed:function(){var t=this.getPoints(),e=t.length,i=this.getTension(),n=Konva.Util,a=n._getControlPoints(t[e-2],t[e-1],t[0],t[1],t[2],t[3],i),r=n._getControlPoints(t[e-4],t[e-3],t[e-2],t[e-1],t[0],t[1],i),o=Konva.Util._expandPoints(t,i);return[a[2],a[3]].concat(o).concat([r[0],r[1],t[e-2],t[e-1],r[2],r[3],a[0],a[1],t[0],t[1]])},getWidth:function(){return this.getSelfRect().width},getHeight:function(){return this.getSelfRect().height},getSelfRect:function(){for(var t,e,i,n=(t=0!==this.getTension()?this._getTensionPoints():this.getPoints())[0],a=t[0],r=t[1],o=t[1],s=0;s<t.length/2;s++)e=t[2*s],i=t[2*s+1],n=Math.min(n,e),a=Math.max(a,e),r=Math.min(r,i),o=Math.max(o,i);return{x:Math.round(n),y:Math.round(r),width:Math.round(a-n),height:Math.round(o-r)}}},Konva.Util.extend(Konva.Line,Konva.Shape),Konva.Factory.addGetterSetter(Konva.Line,"closed",!1),Konva.Factory.addGetterSetter(Konva.Line,"bezier",!1),Konva.Factory.addGetterSetter(Konva.Line,"tension",0),Konva.Factory.addGetterSetter(Konva.Line,"points",[]),Konva.Collection.mapMethods(Konva.Line)}(),function(){"use strict";Konva.Sprite=function(t){this.___init(t)},Konva.Sprite.prototype={___init:function(t){Konva.Shape.call(this,t),this.className="Sprite",this._updated=!0;var e=this;this.anim=new Konva.Animation(function(){var t=e._updated;return e._updated=!1,t}),this.on("animationChange.konva",function(){this.frameIndex(0)}),this.on("frameIndexChange.konva",function(){this._updated=!0}),this.on("frameRateChange.konva",function(){this.anim.isRunning()&&(clearInterval(this.interval),this._setInterval())}),this.sceneFunc(this._sceneFunc),this.hitFunc(this._hitFunc)},_sceneFunc:function(t){var e=this.getAnimation(),i=this.frameIndex(),n=4*i,a=this.getAnimations()[e],r=this.frameOffsets(),o=a[n+0],s=a[n+1],h=a[n+2],c=a[n+3],l=this.getImage();if((this.hasFill()||this.hasStroke())&&(t.beginPath(),t.rect(0,0,h,c),t.closePath(),t.fillStrokeShape(this)),l)if(r){var d=r[e],u=2*i;t.drawImage(l,o,s,h,c,d[u+0],d[u+1],h,c)}else t.drawImage(l,o,s,h,c,0,0,h,c)},_hitFunc:function(t){var e=this.getAnimation(),i=this.frameIndex(),n=4*i,a=this.getAnimations()[e],r=this.frameOffsets(),o=a[n+2],s=a[n+3];if(t.beginPath(),r){var h=r[e],c=2*i;t.rect(h[c+0],h[c+1],o,s)}else t.rect(0,0,o,s);t.closePath(),t.fillShape(this)},_useBufferCanvas:function(){return(this.hasShadow()||1!==this.getAbsoluteOpacity())&&this.hasStroke()},_setInterval:function(){var t=this;this.interval=setInterval(function(){t._updateIndex()},1e3/this.getFrameRate())},start:function(){var t=this.getLayer();this.anim.setLayers(t),this._setInterval(),this.anim.start()},stop:function(){this.anim.stop(),clearInterval(this.interval)},isRunning:function(){return this.anim.isRunning()},_updateIndex:function(){var t=this.frameIndex(),e=this.getAnimation();t<this.getAnimations()[e].length/4-1?this.frameIndex(t+1):this.frameIndex(0)}},Konva.Util.extend(Konva.Sprite,Konva.Shape),Konva.Factory.addGetterSetter(Konva.Sprite,"animation"),Konva.Factory.addGetterSetter(Konva.Sprite,"animations"),Konva.Factory.addGetterSetter(Konva.Sprite,"frameOffsets"),Konva.Factory.addGetterSetter(Konva.Sprite,"image"),Konva.Factory.addGetterSetter(Konva.Sprite,"frameIndex",0),Konva.Factory.addGetterSetter(Konva.Sprite,"frameRate",17),Konva.Factory.backCompat(Konva.Sprite,{index:"frameIndex",getIndex:"getFrameIndex",setIndex:"setFrameIndex"}),Konva.Collection.mapMethods(Konva.Sprite)}(),function(){"use strict";Konva.Path=function(t){this.___init(t)},Konva.Path.prototype={___init:function(t){this.dataArray=[];var e=this;Konva.Shape.call(this,t),this.className="Path",this.dataArray=Konva.Path.parsePathData(this.getData()),this.on("dataChange.konva",function(){e.dataArray=Konva.Path.parsePathData(this.getData())}),this.sceneFunc(this._sceneFunc)},_sceneFunc:function(t){var e=this.dataArray;t.beginPath();for(var i=0;i<e.length;i++){var n=e[i].command,a=e[i].points;switch(n){case"L":t.lineTo(a[0],a[1]);break;case"M":t.moveTo(a[0],a[1]);break;case"C":t.bezierCurveTo(a[0],a[1],a[2],a[3],a[4],a[5]);break;case"Q":t.quadraticCurveTo(a[0],a[1],a[2],a[3]);break;case"A":var r=a[0],o=a[1],s=a[2],h=a[3],c=a[4],l=a[5],d=a[6],u=a[7],f=h<s?s:h,g=h<s?1:s/h,v=h<s?h/s:1;t.translate(r,o),t.rotate(d),t.scale(g,v),t.arc(0,0,f,c,c+l,1-u),t.scale(1/g,1/v),t.rotate(-d),t.translate(-r,-o);break;case"z":t.closePath()}}t.fillStrokeShape(this)},getSelfRect:function(){var e=[];this.dataArray.forEach(function(t){e=e.concat(t.points)});for(var t,i,n=e[0],a=e[0],r=e[1],o=e[1],s=0;s<e.length/2;s++)t=e[2*s],i=e[2*s+1],n=Math.min(n,t),a=Math.max(a,t),r=Math.min(r,i),o=Math.max(o,i);return{x:Math.round(n),y:Math.round(r),width:Math.round(a-n),height:Math.round(o-r)}}},Konva.Util.extend(Konva.Path,Konva.Shape),Konva.Path.getLineLength=function(t,e,i,n){return Math.sqrt((i-t)*(i-t)+(n-e)*(n-e))},Konva.Path.getPointOnLine=function(t,e,i,n,a,r,o){void 0===r&&(r=e),void 0===o&&(o=i);var s=(a-i)/(n-e+1e-8),h=Math.sqrt(t*t/(1+s*s));n<e&&(h*=-1);var c,l=s*h;if(n===e)c={x:r,y:o+l};else if((o-i)/(r-e+1e-8)===s)c={x:r+h,y:o+l};else{var d,u,f=this.getLineLength(e,i,n,a);if(f<1e-8)return;var g=(r-e)*(n-e)+(o-i)*(a-i);d=e+(g/=f*f)*(n-e),u=i+g*(a-i);var v=this.getLineLength(r,o,d,u),p=Math.sqrt(t*t-v*v);h=Math.sqrt(p*p/(1+s*s)),n<e&&(h*=-1),c={x:d+h,y:u+(l=s*h)}}return c},Konva.Path.getPointOnCubicBezier=function(t,e,i,n,a,r,o,s,h){function c(t){return t*t*t}function l(t){return 3*t*t*(1-t)}function d(t){return 3*t*(1-t)*(1-t)}function u(t){return(1-t)*(1-t)*(1-t)}return{x:s*c(t)+r*l(t)+n*d(t)+e*u(t),y:h*c(t)+o*l(t)+a*d(t)+i*u(t)}},Konva.Path.getPointOnQuadraticBezier=function(t,e,i,n,a,r,o){function s(t){return t*t}function h(t){return 2*t*(1-t)}function c(t){return(1-t)*(1-t)}return{x:r*s(t)+n*h(t)+e*c(t),y:o*s(t)+a*h(t)+i*c(t)}},Konva.Path.getPointOnEllipticalArc=function(t,e,i,n,a,r){var o=Math.cos(r),s=Math.sin(r),h=i*Math.cos(a),c=n*Math.sin(a);return{x:t+(h*o-c*s),y:e+(h*s+c*o)}},Konva.Path.parsePathData=function(t){if(!t)return[];var e=t,i=["m","M","l","L","v","V","h","H","z","Z","c","C","q","Q","t","T","s","S","a","A"];e=e.replace(new RegExp(" ","g"),",");for(var n=0;n<i.length;n++)e=e.replace(new RegExp(i[n],"g"),"|"+i[n]);var a,r=e.split("|"),o=[],s=[],h=0,c=0,l=/([-+]?((\d+\.\d+)|((\d+)|(\.\d+)))(?:e[-+]?\d+)?)/gi;for(n=1;n<r.length;n++){var d=r[n],u=d.charAt(0);for(d=d.slice(1),s.length=0;a=l.exec(d);)s.push(a[0]);for(var f=[],g=0,v=s.length;g<v;g++){var p=parseFloat(s[g]);isNaN(p)||f.push(p)}for(;0<f.length&&!isNaN(f[0]);){var m,y,_,S,K,x,C,b,w,F,T=null,P=[],A=h,M=c;switch(u){case"l":h+=f.shift(),c+=f.shift(),T="L",P.push(h,c);break;case"L":h=f.shift(),c=f.shift(),P.push(h,c);break;case"m":var k=f.shift(),G=f.shift();if(h+=k,c+=G,T="M",2<o.length&&"z"===o[o.length-1].command)for(var R=o.length-2;0<=R;R--)if("M"===o[R].command){h=o[R].points[0]+k,c=o[R].points[1]+G;break}P.push(h,c),u="l";break;case"M":h=f.shift(),c=f.shift(),T="M",P.push(h,c),u="L";break;case"h":h+=f.shift(),T="L",P.push(h,c);break;case"H":h=f.shift(),T="L",P.push(h,c);break;case"v":c+=f.shift(),T="L",P.push(h,c);break;case"V":c=f.shift(),T="L",P.push(h,c);break;case"C":P.push(f.shift(),f.shift(),f.shift(),f.shift()),h=f.shift(),c=f.shift(),P.push(h,c);break;case"c":P.push(h+f.shift(),c+f.shift(),h+f.shift(),c+f.shift()),h+=f.shift(),c+=f.shift(),T="C",P.push(h,c);break;case"S":y=h,_=c,"C"===(m=o[o.length-1]).command&&(y=h+(h-m.points[2]),_=c+(c-m.points[3])),P.push(y,_,f.shift(),f.shift()),h=f.shift(),c=f.shift(),T="C",P.push(h,c);break;case"s":y=h,_=c,"C"===(m=o[o.length-1]).command&&(y=h+(h-m.points[2]),_=c+(c-m.points[3])),P.push(y,_,h+f.shift(),c+f.shift()),h+=f.shift(),c+=f.shift(),T="C",P.push(h,c);break;case"Q":P.push(f.shift(),f.shift()),h=f.shift(),c=f.shift(),P.push(h,c);break;case"q":P.push(h+f.shift(),c+f.shift()),h+=f.shift(),c+=f.shift(),T="Q",P.push(h,c);break;case"T":y=h,_=c,"Q"===(m=o[o.length-1]).command&&(y=h+(h-m.points[0]),_=c+(c-m.points[1])),h=f.shift(),c=f.shift(),T="Q",P.push(y,_,h,c);break;case"t":y=h,_=c,"Q"===(m=o[o.length-1]).command&&(y=h+(h-m.points[0]),_=c+(c-m.points[1])),h+=f.shift(),c+=f.shift(),T="Q",P.push(y,_,h,c);break;case"A":S=f.shift(),K=f.shift(),x=f.shift(),C=f.shift(),b=f.shift(),w=h,F=c,h=f.shift(),c=f.shift(),T="A",P=this.convertEndpointToCenterParameterization(w,F,h,c,C,b,S,K,x);break;case"a":S=f.shift(),K=f.shift(),x=f.shift(),C=f.shift(),b=f.shift(),w=h,F=c,h+=f.shift(),c+=f.shift(),T="A",P=this.convertEndpointToCenterParameterization(w,F,h,c,C,b,S,K,x)}o.push({command:T||u,points:P,start:{x:A,y:M},pathLength:this.calcLength(A,M,T||u,P)})}"z"!==u&&"Z"!==u||o.push({command:"z",points:[],start:void 0,pathLength:0})}return o},Konva.Path.calcLength=function(t,e,i,n){var a,r,o,s,h=Konva.Path;switch(i){case"L":return h.getLineLength(t,e,n[0],n[1]);case"C":for(a=0,r=h.getPointOnCubicBezier(0,t,e,n[0],n[1],n[2],n[3],n[4],n[5]),s=.01;s<=1;s+=.01)o=h.getPointOnCubicBezier(s,t,e,n[0],n[1],n[2],n[3],n[4],n[5]),a+=h.getLineLength(r.x,r.y,o.x,o.y),r=o;return a;case"Q":for(a=0,r=h.getPointOnQuadraticBezier(0,t,e,n[0],n[1],n[2],n[3]),s=.01;s<=1;s+=.01)o=h.getPointOnQuadraticBezier(s,t,e,n[0],n[1],n[2],n[3]),a+=h.getLineLength(r.x,r.y,o.x,o.y),r=o;return a;case"A":a=0;var c=n[4],l=n[5],d=n[4]+l,u=Math.PI/180;if(Math.abs(c-d)<u&&(u=Math.abs(c-d)),r=h.getPointOnEllipticalArc(n[0],n[1],n[2],n[3],c,0),l<0)for(s=c-u;d<s;s-=u)o=h.getPointOnEllipticalArc(n[0],n[1],n[2],n[3],s,0),a+=h.getLineLength(r.x,r.y,o.x,o.y),r=o;else for(s=c+u;s<d;s+=u)o=h.getPointOnEllipticalArc(n[0],n[1],n[2],n[3],s,0),a+=h.getLineLength(r.x,r.y,o.x,o.y),r=o;return o=h.getPointOnEllipticalArc(n[0],n[1],n[2],n[3],d,0),a+=h.getLineLength(r.x,r.y,o.x,o.y)}return 0},Konva.Path.convertEndpointToCenterParameterization=function(t,e,i,n,a,r,o,s,h){var c=h*(Math.PI/180),l=Math.cos(c)*(t-i)/2+Math.sin(c)*(e-n)/2,d=-1*Math.sin(c)*(t-i)/2+Math.cos(c)*(e-n)/2,u=l*l/(o*o)+d*d/(s*s);1<u&&(o*=Math.sqrt(u),s*=Math.sqrt(u));var f=Math.sqrt((o*o*(s*s)-o*o*(d*d)-s*s*(l*l))/(o*o*(d*d)+s*s*(l*l)));a===r&&(f*=-1),isNaN(f)&&(f=0);var g=f*o*d/s,v=f*-s*l/o,p=(t+i)/2+Math.cos(c)*g-Math.sin(c)*v,m=(e+n)/2+Math.sin(c)*g+Math.cos(c)*v,y=function(t){return Math.sqrt(t[0]*t[0]+t[1]*t[1])},_=function(t,e){return(t[0]*e[0]+t[1]*e[1])/(y(t)*y(e))},S=function(t,e){return(t[0]*e[1]<t[1]*e[0]?-1:1)*Math.acos(_(t,e))},K=S([1,0],[(l-g)/o,(d-v)/s]),x=[(l-g)/o,(d-v)/s],C=[(-1*l-g)/o,(-1*d-v)/s],b=S(x,C);return _(x,C)<=-1&&(b=Math.PI),1<=_(x,C)&&(b=0),0===r&&0<b&&(b-=2*Math.PI),1===r&&b<0&&(b+=2*Math.PI),[p,m,o,s,K,b,c,r]},Konva.Factory.addGetterSetter(Konva.Path,"data"),Konva.Collection.mapMethods(Konva.Path)}(),function(){"use strict";function i(t){t.fillText(this.partialText,0,0)}function n(t){t.strokeText(this.partialText,0,0)}Konva.TextPath=function(t){this.___init(t)},Konva.TextPath.prototype={___init:function(t){var e=this;this.dummyCanvas=Konva.Util.createCanvasElement(),this.dataArray=[],this.getKerning=t&&t.getKerning,Konva.Shape.call(this,t),this._fillFunc=i,this._strokeFunc=n,this._fillFuncHit=i,this._strokeFuncHit=n,this.className="TextPath",this.dataArray=Konva.Path.parsePathData(this.attrs.data),this.on("dataChange.konva",function(){e.dataArray=Konva.Path.parsePathData(this.attrs.data),e._setTextData()}),this.on("textChange.konva alignChange.konva letterSpacingChange.konva",e._setTextData),e._setTextData(),this.sceneFunc(this._sceneFunc),this.hitFunc(this._hitFunc)},_sceneFunc:function(t){t.setAttr("font",this._getContextFont()),t.setAttr("textBaseline",this.getTextBaseline()),t.setAttr("textAlign","left"),t.save();var e=this.textDecoration(),i=this.fill(),n=this.fontSize(),a=this.glyphInfo;"underline"===e&&t.beginPath();for(var r=0;r<a.length;r++){t.save();var o=a[r].p0;t.translate(o.x,o.y),t.rotate(a[r].rotation),this.partialText=a[r].text,t.fillStrokeShape(this),"underline"===e&&(0===r&&t.moveTo(0,n/2+1),t.lineTo(n,n/2+1)),t.restore()}"underline"===e&&(t.strokeStyle=i,t.lineWidth=n/20,t.stroke()),t.restore()},_hitFunc:function(t){t.beginPath();var e=this.glyphInfo;if(1<=e.length){var i=e[0].p0;t.moveTo(i.x,i.y)}for(var n=0;n<e.length;n++){var a=e[n].p1;t.lineTo(a.x,a.y)}t.setAttr("lineWidth",this.getFontSize()),t.setAttr("strokeStyle",this.colorKey),t.stroke()},getTextWidth:function(){return this.textWidth},getTextHeight:function(){return this.textHeight},setText:function(t){Konva.Text.prototype.setText.call(this,t)},_getTextSize:function(t){var e=this.dummyCanvas.getContext("2d");e.save(),e.font=this._getContextFont();var i=e.measureText(t);return e.restore(),{width:i.width,height:parseInt(this.attrs.fontSize,10)}},_setTextData:function(){var c=this,t=this._getTextSize(this.attrs.text),l=this.getLetterSpacing(),d=this.align();this.textWidth=t.width,this.textHeight=t.height;var u=Math.max(this.textWidth+((this.attrs.text||"").length-1)*l,0);this.glyphInfo=[];for(var f=0,e=0;e<c.dataArray.length;e++)0<c.dataArray[e].pathLength&&(f+=c.dataArray[e].pathLength);var i=0;"center"===d&&(i=Math.max(0,f/2-u/2)),"right"===d&&(i=Math.max(0,f-u));for(var g,v,p,n=this.getText().split(""),m=this.getText().split(" ").length-1,a=-1,y=0,_=function(){y=0;for(var t=c.dataArray,e=a+1;e<t.length;e++){if(0<t[e].pathLength)return t[a=e];"M"===t[e].command&&(g={x:t[e].points[0],y:t[e].points[1]})}return{}},r=function(t){var e=c._getTextSize(t).width+l;" "===t&&"justify"===d&&(e+=(f-u)/m);var i=0,n=0;for(v=void 0;.01<Math.abs(e-i)/e&&n<25;){n++;for(var a=i;void 0===p;)(p=_())&&a+p.pathLength<e&&(a+=p.pathLength,p=void 0);if(p==={}||void 0===g)return;var r=!1;switch(p.command){case"L":Konva.Path.getLineLength(g.x,g.y,p.points[0],p.points[1])>e?v=Konva.Path.getPointOnLine(e,g.x,g.y,p.points[0],p.points[1],g.x,g.y):p=void 0;break;case"A":var o=p.points[4],s=p.points[5],h=p.points[4]+s;0===y?y=o+1e-8:i<e?y+=Math.PI/180*s/Math.abs(s):y-=Math.PI/360*s/Math.abs(s),(s<0&&y<h||0<=s&&h<y)&&(y=h,r=!0),v=Konva.Path.getPointOnEllipticalArc(p.points[0],p.points[1],p.points[2],p.points[3],y,p.points[6]);break;case"C":0===y?y=e>p.pathLength?1e-8:e/p.pathLength:i<e?y+=(e-i)/p.pathLength:y-=(i-e)/p.pathLength,1<y&&(y=1,r=!0),v=Konva.Path.getPointOnCubicBezier(y,p.start.x,p.start.y,p.points[0],p.points[1],p.points[2],p.points[3],p.points[4],p.points[5]);break;case"Q":0===y?y=e/p.pathLength:i<e?y+=(e-i)/p.pathLength:y-=(i-e)/p.pathLength,1<y&&(y=1,r=!0),v=Konva.Path.getPointOnQuadraticBezier(y,p.start.x,p.start.y,p.points[0],p.points[1],p.points[2],p.points[3])}void 0!==v&&(i=Konva.Path.getLineLength(g.x,g.y,v.x,v.y)),r&&(r=!1,p=void 0)}},o=c._getTextSize("C").width+l,s=0;s<i/o&&(r("C"),void 0!==g&&void 0!==v);s++)g=v;for(var h=0;h<n.length&&(r(n[h]),void 0!==g&&void 0!==v);h++){var S=Konva.Path.getLineLength(g.x,g.y,v.x,v.y),K=0;if(this.getKerning)try{K=this.getKerning(n[h-1],n[h])*this.fontSize()}catch(t){K=0}g.x+=K,v.x+=K,this.textWidth+=K;var x=Konva.Path.getPointOnLine(K+S/2,g.x,g.y,v.x,v.y),C=Math.atan2(v.y-g.y,v.x-g.x);this.glyphInfo.push({transposeX:x.x,transposeY:x.y,text:n[h],rotation:C,p0:g,p1:v}),g=v}},getSelfRect:function(){var e=[];this.glyphInfo.forEach(function(t){e.push(t.p0.x),e.push(t.p0.y),e.push(t.p1.x),e.push(t.p1.y)});for(var t,i,n=e[0],a=e[0],r=e[0],o=e[0],s=0;s<e.length/2;s++)t=e[2*s],i=e[2*s+1],n=Math.min(n,t),a=Math.max(a,t),r=Math.min(r,i),o=Math.max(o,i);var h=this.fontSize();return{x:Math.round(n)-h/2,y:Math.round(r)-h/2,width:Math.round(a-n)+h,height:Math.round(o-r)+h}}},Konva.TextPath.prototype._getContextFont=Konva.Text.prototype._getContextFont,Konva.Util.extend(Konva.TextPath,Konva.Shape),Konva.Factory.addGetterSetter(Konva.TextPath,"fontFamily","Arial"),Konva.Factory.addGetterSetter(Konva.TextPath,"fontSize",12),Konva.Factory.addGetterSetter(Konva.TextPath,"fontStyle","normal"),Konva.Factory.addGetterSetter(Konva.TextPath,"align","left"),Konva.Factory.addGetterSetter(Konva.TextPath,"letterSpacing",0),Konva.Factory.addGetterSetter(Konva.TextPath,"textBaseline","middle"),Konva.Factory.addGetterSetter(Konva.TextPath,"fontVariant","normal"),Konva.Factory.addGetter(Konva.TextPath,"text",""),Konva.Factory.addGetterSetter(Konva.TextPath,"textDecoration",null),Konva.Collection.mapMethods(Konva.TextPath)}(),function(){"use strict";Konva.RegularPolygon=function(t){this.___init(t)},Konva.RegularPolygon.prototype={_centroid:!0,___init:function(t){Konva.Shape.call(this,t),this.className="RegularPolygon",this.sceneFunc(this._sceneFunc)},_sceneFunc:function(t){var e,i,n,a=this.attrs.sides,r=this.attrs.radius;for(t.beginPath(),t.moveTo(0,0-r),e=1;e<a;e++)i=r*Math.sin(2*e*Math.PI/a),n=-1*r*Math.cos(2*e*Math.PI/a),t.lineTo(i,n);t.closePath(),t.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.RegularPolygon,Konva.Shape),Konva.Factory.addGetterSetter(Konva.RegularPolygon,"radius",0),Konva.Factory.addGetterSetter(Konva.RegularPolygon,"sides",0),Konva.Collection.mapMethods(Konva.RegularPolygon)}(),function(){"use strict";Konva.Star=function(t){this.___init(t)},Konva.Star.prototype={_centroid:!0,___init:function(t){Konva.Shape.call(this,t),this.className="Star",this.sceneFunc(this._sceneFunc)},_sceneFunc:function(t){var e=this.innerRadius(),i=this.outerRadius(),n=this.numPoints();t.beginPath(),t.moveTo(0,0-i);for(var a=1;a<2*n;a++){var r=a%2==0?i:e,o=r*Math.sin(a*Math.PI/n),s=-1*r*Math.cos(a*Math.PI/n);t.lineTo(o,s)}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.outerRadius()!==t/2&&this.setOuterRadius(t/2)},setHeight:function(t){Konva.Node.prototype.setHeight.call(this,t),this.outerRadius()!==t/2&&this.setOuterRadius(t/2)}},Konva.Util.extend(Konva.Star,Konva.Shape),Konva.Factory.addGetterSetter(Konva.Star,"numPoints",5),Konva.Factory.addGetterSetter(Konva.Star,"innerRadius",0),Konva.Factory.addGetterSetter(Konva.Star,"outerRadius",0),Konva.Collection.mapMethods(Konva.Star)}(),function(){"use strict";var a=["fontFamily","fontSize","fontStyle","padding","lineHeight","text","width"],c="right",l="down",d="left",r=a.length;Konva.Label=function(t){this.____init(t)},Konva.Label.prototype={____init:function(t){var e=this;Konva.Group.call(this,t),this.className="Label",this.on("add.konva",function(t){e._addListeners(t.child),e._sync()})},getText:function(){return this.find("Text")[0]},getTag:function(){return this.find("Tag")[0]},_addListeners:function(t){var e,i=this,n=function(){i._sync()};for(e=0;e<r;e++)t.on(a[e]+"Change.konva",n)},getWidth:function(){return this.getText().getWidth()},getHeight:function(){return this.getText().getHeight()},_sync:function(){var t,e,i,n,a,r,o,s=this.getText(),h=this.getTag();if(s&&h){switch(t=s.getWidth(),e=s.getHeight(),i=h.getPointerDirection(),n=h.getPointerWidth(),o=h.getPointerHeight(),r=a=0,i){case"up":a=t/2,r=-1*o;break;case c:a=t+n,r=e/2;break;case l:a=t/2,r=e+o;break;case d:a=-1*n,r=e/2}h.setAttrs({x:-1*a,y:-1*r,width:t,height:e}),s.setAttrs({x:-1*a,y:-1*r})}}},Konva.Util.extend(Konva.Label,Konva.Group),Konva.Collection.mapMethods(Konva.Label),Konva.Tag=function(t){this.___init(t)},Konva.Tag.prototype={___init:function(t){Konva.Shape.call(this,t),this.className="Tag",this.sceneFunc(this._sceneFunc)},_sceneFunc:function(t){var e=this.getWidth(),i=this.getHeight(),n=this.getPointerDirection(),a=this.getPointerWidth(),r=this.getPointerHeight(),o=Math.min(this.getCornerRadius(),e/2,i/2);t.beginPath(),o?t.moveTo(o,0):t.moveTo(0,0),"up"===n&&(t.lineTo((e-a)/2,0),t.lineTo(e/2,-1*r),t.lineTo((e+a)/2,0)),o?(t.lineTo(e-o,0),t.arc(e-o,o,o,3*Math.PI/2,0,!1)):t.lineTo(e,0),n===c&&(t.lineTo(e,(i-r)/2),t.lineTo(e+a,i/2),t.lineTo(e,(i+r)/2)),o?(t.lineTo(e,i-o),t.arc(e-o,i-o,o,0,Math.PI/2,!1)):t.lineTo(e,i),n===l&&(t.lineTo((e+a)/2,i),t.lineTo(e/2,i+r),t.lineTo((e-a)/2,i)),o?(t.lineTo(o,i),t.arc(o,i-o,o,Math.PI/2,Math.PI,!1)):t.lineTo(0,i),n===d&&(t.lineTo(0,(i+r)/2),t.lineTo(-1*a,i/2),t.lineTo(0,(i-r)/2)),o&&(t.lineTo(0,o),t.arc(o,o,o,Math.PI,3*Math.PI/2,!1)),t.closePath(),t.fillStrokeShape(this)},getSelfRect:function(){var t=0,e=0,i=this.getPointerWidth(),n=this.getPointerHeight(),a=this.pointerDirection(),r=this.getWidth(),o=this.getHeight();return"up"===a?(e-=n,o+=n):a===l?o+=n:a===d?(t-=1.5*i,r+=i):a===c&&(r+=1.5*i),{x:t,y:e,width:r,height:o}}},Konva.Util.extend(Konva.Tag,Konva.Shape),Konva.Factory.addGetterSetter(Konva.Tag,"pointerDirection","none"),Konva.Factory.addGetterSetter(Konva.Tag,"pointerWidth",0),Konva.Factory.addGetterSetter(Konva.Tag,"pointerHeight",0),Konva.Factory.addGetterSetter(Konva.Tag,"cornerRadius",0),Konva.Collection.mapMethods(Konva.Tag)}(),function(c){"use strict";c.Arrow=function(t){this.____init(t)},c.Arrow.prototype={____init:function(t){c.Line.call(this,t),this.className="Arrow"},_sceneFunc:function(t){c.Line.prototype._sceneFunc.apply(this,arguments);var e=2*Math.PI,i=this.points(),n=i.length,a=i[n-2]-i[n-4],r=i[n-1]-i[n-3],o=(Math.atan2(r,a)+e)%e,s=this.pointerLength(),h=this.pointerWidth();t.save(),t.beginPath(),t.translate(i[n-2],i[n-1]),t.rotate(o),t.moveTo(0,0),t.lineTo(-s,h/2),t.lineTo(-s,-h/2),t.closePath(),t.restore(),this.pointerAtBeginning()&&(t.save(),t.translate(i[0],i[1]),a=i[2]-i[0],r=i[3]-i[1],t.rotate((Math.atan2(-r,-a)+e)%e),t.moveTo(0,0),t.lineTo(-s,h/2),t.lineTo(-s,-h/2),t.closePath(),t.restore()),t.fillStrokeShape(this)}},c.Util.extend(c.Arrow,c.Line),c.Factory.addGetterSetter(c.Arrow,"pointerLength",10),c.Factory.addGetterSetter(c.Arrow,"pointerWidth",10),c.Factory.addGetterSetter(c.Arrow,"pointerAtBeginning",!1),c.Collection.mapMethods(c.Arrow)}(Konva),function(x){"use strict";var e=["resizeEnabledChange","rotateHandlerOffsetChange"].join(" "),i=["xChange.resizer","yChange.resizer","widthChange.resizer","heightChange.resizer","scaleXChange.resizer","scaleYChange.resizer","skewXChange.resizer","skewYChange.resizer","rotationChange.resizer","offsetXChange.resizer","offsetYChange.resizer","transformsEnabledChange.resizer"].join(" ");x.Transformer=function(t){this.____init(t)};var n=["top-left","top-center","top-right","middle-right","middle-left","bottom-left","bottom-center","bottom-right"],a=!1;x.Transformer.prototype={_centroid:!1,____init:function(t){x.Group.call(this,t),this.className="Transformer",this._createElements(),this.handleMouseMove=this.handleMouseMove.bind(this),this.handleMouseUp=this.handleMouseUp.bind(this),this.update=this.update.bind(this),this.on(e,this.update),a||(x.Util.warn("Konva.Transformer is currently experimental and may have bugs. Please report any issues to GitHub repo."),a=!0)},attachTo:function(t){this.node()&&this.detach(),this.setNode(t),t.on("dragmove.resizer",this.update),t.on(i,this.update),this.update()},detach:function(){this.getNode().off(".resizer")},_getNodeRect:function(){var t=this.getNode(),e=t.getClientRect({skipTransform:!0}),i=x.getAngle(t.rotation()),n=e.x*t.scaleX()-t.offsetX(),a=e.y*t.scaleY()-t.offsetY();return{x:t.x()+n*Math.cos(i)+a*Math.sin(-i),y:t.y()+a*Math.cos(i)+n*Math.sin(i),width:e.width*t.scaleX(),height:e.height*t.scaleY(),rotation:t.rotation()}},getX:function(){return this._getNodeRect().x},getY:function(){return this._getNodeRect().y},getRotation:function(){return this._getNodeRect().rotation},getWidth:function(){return this._getNodeRect().width},getHeight:function(){return this._getNodeRect().height},_createElements:function(){this._createBack(),n.forEach(function(t){this._createAnchor(t)}.bind(this)),this._createAnchor("rotater")},_createAnchor:function(o){var s=new x.Rect({stroke:"rgb(0, 161, 255)",fill:"white",strokeWidth:1,name:o,width:10,height:10,offsetX:5,offsetY:5,draggable:!0,dragDistance:0}),e=this;s.on("mousedown touchstart",function(t){e.handleResizerMouseDown(t)}),s.on("mouseenter",function(){var t,e,i,n=this.getLayer(),a=x.getAngle(this.getParent().rotation()),r=(e=a,"rotater"===(t=o)?"crosshair":(i=((i="top-left"===t||"bottom-right"===t?-45:"top-right"===t||"bottom-left"===t?45:"top-center"===t||"bottom-center"===t?0:"middle-left"===t||"middle-right"===t?90:0)+x.Util._radToDeg(e)+360)%360,x.Util._inRange(i,337.5,360)||x.Util._inRange(i,0,22.5)?"ns-resize":x.Util._inRange(i,22.5,67.5)?"nesw-resize":x.Util._inRange(i,67.5,112.5)?"ew-resize":x.Util._inRange(i,112.5,157.5)?"nwse-resize":x.Util._inRange(i,157.5,202.5)?"ns-resize":x.Util._inRange(i,202.5,247.5)?"nesw-resize":x.Util._inRange(i,247.5,292.5)?"ew-resize":x.Util._inRange(i,292.5,337.5)?"nwse-resize":"pointer"));s.getStage().getContainer().style.cursor=r,this.fill("lightgrey"),n.batchDraw()}),s.on("mouseout",function(){var t=this.getLayer();t&&(s.getStage().getContainer().style.cursor="",this.fill("white"),t.batchDraw())}),this.add(s)},_createBack:function(){var t=new x.Shape({stroke:"rgb(0, 161, 255)",name:"back",width:0,height:0,listening:!1,sceneFunc:function(t){t.beginPath(),t.rect(0,0,this.width(),this.height()),t.moveTo(this.width()/2,0),this.getParent().rotateEnabled()&&t.lineTo(this.width()/2,-this.getParent().rotateHandlerOffset()),t.fillStrokeShape(this)}});this.add(t)},handleResizerMouseDown:function(t){this.movingResizer=t.target.name();var e=this._getNodeRect(),i=e.width,n=e.height,a=Math.sqrt(Math.pow(i,2)+Math.pow(n,2));this.sin=n/a,this.cos=i/a,window.addEventListener("mousemove",this.handleMouseMove),window.addEventListener("touchmove",this.handleMouseMove),window.addEventListener("mouseup",this.handleMouseUp),window.addEventListener("touchend",this.handleMouseUp),this._transforming=!0,this.fire("transformstart"),this.getNode().fire("transformstart")},handleMouseMove:function(t){var e,i,n,a=this.findOne("."+this.movingResizer),r=a.getStage().getContent().getBoundingClientRect(),o=r.left,s=r.top,h={x:(void 0!==t.clientX?t.clientX:t.touches[0].clientX)-o,y:(void 0!==t.clientX?t.clientY:t.touches[0].clientY)-s};if(a.setAbsolutePosition(h),"top-left"===this.movingResizer)e=(n=Math.sqrt(Math.pow(this.findOne(".bottom-right").x()-a.x(),2)+Math.pow(this.findOne(".bottom-right").y()-a.y(),2)))*this.cos,i=n*this.sin,this.findOne(".top-left").x(this.findOne(".bottom-right").x()-e),this.findOne(".top-left").y(this.findOne(".bottom-right").y()-i);else if("top-center"===this.movingResizer)this.findOne(".top-left").y(a.y());else if("top-right"===this.movingResizer){e=(n=Math.sqrt(Math.pow(this.findOne(".bottom-left").x()-a.x(),2)+Math.pow(this.findOne(".bottom-left").y()-a.y(),2)))*this.cos,i=n*this.sin,this.findOne(".top-right").x(e),this.findOne(".top-right").y(this.findOne(".bottom-left").y()-i);var c=a.position();this.findOne(".top-left").y(c.y),this.findOne(".bottom-right").x(c.x)}else if("middle-left"===this.movingResizer)this.findOne(".top-left").x(a.x());else if("middle-right"===this.movingResizer)this.findOne(".bottom-right").x(a.x());else if("bottom-left"===this.movingResizer)e=(n=Math.sqrt(Math.pow(this.findOne(".top-right").x()-a.x(),2)+Math.pow(this.findOne(".top-right").y()-a.y(),2)))*this.cos,i=n*this.sin,this.findOne(".bottom-left").x(this.findOne(".top-right").x()-e),this.findOne(".bottom-left").y(i),c=a.position(),this.findOne(".top-left").x(c.x),this.findOne(".bottom-right").y(c.y);else if("bottom-center"===this.movingResizer)this.findOne(".bottom-right").y(a.y());else if("bottom-right"===this.movingResizer)e=(n=Math.sqrt(Math.pow(this.findOne(".bottom-right").x(),2)+Math.pow(this.findOne(".bottom-right").y(),2)))*this.cos,i=n*this.sin,this.findOne(".bottom-right").x(e),this.findOne(".bottom-right").y(i);else if("rotater"===this.movingResizer){var l=this._getNodeRect();e=a.x()-l.width/2,i=-a.y()+l.height/2;for(var d=Math.atan2(-i,e)+Math.PI/2,u=x.getAngle(this.rotation()),f=x.Util._radToDeg(u)+x.Util._radToDeg(d),g=x.getAngle(this.getNode().rotation()),v=x.Util._degToRad(f),p=this.rotationSnaps(),m=0;m<p.length;m++){var y=x.getAngle(p[m]);Math.abs(y-x.Util._degToRad(f))%(2*Math.PI)<.1&&(f=x.Util._radToDeg(y),v=x.Util._degToRad(f))}this._fitNodeInto(Object.assign(l,{rotation:x.angleDeg?f:x.Util._degToRad(f),x:l.x+l.width/2*(Math.cos(g)-Math.cos(v))+l.height/2*(Math.sin(-g)-Math.sin(-v)),y:l.y+l.height/2*(Math.cos(g)-Math.cos(v))+l.width/2*(Math.sin(g)-Math.sin(v)),width:l.width,height:l.height}))}else console.error(new Error("Wrong position argument of selection resizer: ",this.movingResizer));if("rotater"!==this.movingResizer){var _=this.findOne(".top-left").getAbsolutePosition(this.getParent());e=_.x,i=_.y;var S=this.findOne(".bottom-right").x()-this.findOne(".top-left").x(),K=this.findOne(".bottom-right").y()-this.findOne(".top-left").y();this._fitNodeInto({x:e+this.offsetX(),y:i+this.offsetY(),width:S,height:K})}},handleMouseUp:function(){this._removeEvents()},_removeEvents:function(){this._transforming&&(this._transforming=!1,window.removeEventListener("mousemove",this.handleMouseMove),window.removeEventListener("touchmove",this.handleMouseMove),window.removeEventListener("mouseup",this.handleMouseUp),window.removeEventListener("touchend",this.handleMouseUp),this.fire("transformend"),this.getNode().fire("transformend"))},_fitNodeInto:function(t){this._settings=!0;var e=this.getNode();void 0!==t.rotation&&this.getNode().rotation(t.rotation);var i=e.getClientRect({skipTransform:!0}),n=t.width/i.width,a=t.height/i.height,r=x.getAngle(e.getRotation()),o=i.x*n,s=i.y*a;this.getNode().setAttrs({scaleX:n,scaleY:a,x:t.x-(o*Math.cos(r)+s*Math.sin(-r)),y:t.y-(s*Math.cos(r)+o*Math.sin(r))}),this._settings=!1,this.fire("transform"),this.getNode().fire("transform"),this.update(),this.getLayer().batchDraw()},update:function(){var t=this._getNodeRect(),e=t.x,i=t.y,n=t.width,a=t.height;this.x(e),this.y(i),this.rotation(t.rotation);var r=this.enabledResizers(),o=this.resizeEnabled();this.findOne(".top-left").setAttrs({x:0,y:0,visible:o&&0<=r.indexOf("top-left")}),this.findOne(".top-center").setAttrs({x:n/2,y:0,visible:o&&0<=r.indexOf("top-center")}),this.findOne(".top-right").setAttrs({x:n,y:0,visible:o&&0<=r.indexOf("top-right")}),this.findOne(".middle-left").setAttrs({x:0,y:a/2,visible:o&&0<=r.indexOf("middle-left")}),this.findOne(".middle-right").setAttrs({x:n,y:a/2,visible:o&&0<=r.indexOf("middle-right")}),this.findOne(".bottom-left").setAttrs({x:0,y:a,visible:o&&0<=r.indexOf("bottom-left")}),this.findOne(".bottom-center").setAttrs({x:n/2,y:a,visible:o&&0<=r.indexOf("bottom-center")}),this.findOne(".bottom-right").setAttrs({x:n,y:a,visible:o&&0<=r.indexOf("bottom-right")}),this.findOne(".rotater").setAttrs({x:n/2,y:-this.rotateHandlerOffset(),visible:this.rotateEnabled()}),this.findOne(".back").setAttrs({width:n,height:a,visible:this.lineEnabled()})},destroy:function(){x.Group.prototype.destroy.call(this),this.getNode().off(".resizer"),this._removeEvents()}},x.Util.extend(x.Transformer,x.Group),x.Factory.addGetterSetter(x.Transformer,"enabledResizers",n),x.Factory.addGetterSetter(x.Transformer,"enabledResizers",n,function(t){return t instanceof Array||x.Util.warn("enabledResizers value should be an array"),t instanceof Array&&t.forEach(function(t){-1===n.indexOf(t)&&x.Util.warn("Unknown resizer name: "+t+". Available names are: "+n.join(", "))}),t||[]}),x.Factory.addGetterSetter(x.Transformer,"resizeEnabled",!0),x.Factory.addGetterSetter(x.Transformer,"rotateEnabled",!0),x.Factory.addGetterSetter(x.Transformer,"rotationSnaps",[]),x.Factory.addGetterSetter(x.Transformer,"rotateHandlerOffset",50),x.Factory.addGetterSetter(x.Transformer,"lineEnabled",!0),x.Factory.addGetterSetter(x.Transformer,"node"),x.Collection.mapMethods(x.Transformer)}(Konva);