UNPKG

konva

Version:

<p align="center"> <img src="https://raw.githubusercontent.com/konvajs/konvajs.github.io/master/apple-touch-icon-180x180.png" alt="Konva logo" height="180" /> </p>

12 lines 157 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).Konva=e()}(this,function(){"use strict"; /* * Konva JavaScript Framework v3.3.3 * http://konvajs.org/ * Licensed under the MIT * Date: Fri Jun 07 2019 * * Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS) * Modified work Copyright (C) 2014 - present by Anton Lavrenov (Konva) * * @license */var e=Math.PI/180;var t=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),r=!!t.match(/IEMobile/i);return{browser:i[1]||"",version:i[2]||"0",isIE: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)}(e),mobile:n,ieMobile:r}},n="undefined"!=typeof global?global:"undefined"!=typeof window?window:"undefined"!=typeof WorkerGlobalScope?self:{},O={_global:n,version:"3.3.3",isBrowser:"undefined"!=typeof window&&("[object Window]"==={}.toString.call(window)||"[object global]"==={}.toString.call(window)),isUnminified:/param/.test(function(t){}.toString()),dblClickWindow:400,getAngle:function(t){return O.angleDeg?t*e:t},enableTrace:!1,_pointerEventsEnabled:!1,listenClickTap:!1,inDblClickWindow:!1,pixelRatio:void 0,dragDistance:3,angleDeg:!0,showWarnings:!0,dragButtons:[0,1],isDragging:function(){return O.DD.isDragging},isDragReady:function(){return!!O.DD.node},UA:t(n.navigator&&n.navigator.userAgent||""),document:n.document,_injectGlobal:function(t){n.Konva=t},_parseUA:t},h={},i=function(t){h[t.prototype.getClassName()]=t,O[t.prototype.getClassName()]=t},o=function(){function r(){}return r.toCollection=function(t){var e,i=new r,n=t.length;for(e=0;e<n;e++)i.push(t[e]);return i},r._mapMethod=function(n){r.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}},r.mapMethods=function(t){var e=t.prototype;for(var i in e)r._mapMethod(i)},r}();o.prototype=[],o.prototype.each=function(t){for(var e=0;e<this.length;e++)t(this[e],e)},o.prototype.toArray=function(){var t,e=[],i=this.length;for(t=0;t<i;t++)e.push(this[t]);return e};var c=function(){function t(t){void 0===t&&(t=[1,0,0,1,0,0]),this.m=t&&t.slice()||[1,0,0,1,0,0]}return t.prototype.copy=function(){return new t(this.m)},t.prototype.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]}},t.prototype.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},t.prototype.scale=function(t,e){return this.m[0]*=t,this.m[1]*=t,this.m[2]*=e,this.m[3]*=e,this},t.prototype.rotate=function(t){var e=Math.cos(t),i=Math.sin(t),n=this.m[0]*e+this.m[2]*i,r=this.m[1]*e+this.m[3]*i,o=this.m[0]*-i+this.m[2]*e,a=this.m[1]*-i+this.m[3]*e;return this.m[0]=n,this.m[1]=r,this.m[2]=o,this.m[3]=a,this},t.prototype.getTranslation=function(){return{x:this.m[4],y:this.m[5]}},t.prototype.skew=function(t,e){var i=this.m[0]+this.m[2]*e,n=this.m[1]+this.m[3]*e,r=this.m[2]+this.m[0]*t,o=this.m[3]+this.m[1]*t;return this.m[0]=i,this.m[1]=n,this.m[2]=r,this.m[3]=o,this},t.prototype.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],r=this.m[1]*t.m[2]+this.m[3]*t.m[3],o=this.m[0]*t.m[4]+this.m[2]*t.m[5]+this.m[4],a=this.m[1]*t.m[4]+this.m[3]*t.m[5]+this.m[5];return this.m[0]=e,this.m[1]=i,this.m[2]=n,this.m[3]=r,this.m[4]=o,this.m[5]=a,this},t.prototype.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,r=this.m[0]*t,o=t*(this.m[2]*this.m[5]-this.m[3]*this.m[4]),a=t*(this.m[1]*this.m[4]-this.m[0]*this.m[5]);return this.m[0]=e,this.m[1]=i,this.m[2]=n,this.m[3]=r,this.m[4]=o,this.m[5]=a,this},t.prototype.getMatrix=function(){return this.m},t.prototype.setAbsolutePosition=function(t,e){var i=this.m[0],n=this.m[1],r=this.m[2],o=this.m[3],a=this.m[4],s=(i*(e-this.m[5])-n*(t-a))/(i*o-n*r),h=(t-a-r*s)/i;return this.translate(h,s)},t}(),r=Math.PI/180,a=180/Math.PI,s="Konva error: ",l={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]},d=/rgb\((\d{1,3}),(\d{1,3}),(\d{1,3})\)/,p=[],D={_isElement:function(t){return!(!t||1!=t.nodeType)},_isFunction:function(t){return!!(t&&t.constructor&&t.call&&t.apply)},_isPlainObject:function(t){return!!t&&t.constructor===Object},_isArray:function(t){return"[object Array]"===Object.prototype.toString.call(t)},_isNumber:function(t){return"[object Number]"===Object.prototype.toString.call(t)&&!isNaN(t)&&isFinite(t)},_isString:function(t){return"[object String]"===Object.prototype.toString.call(t)},_isBoolean:function(t){return"[object Boolean]"===Object.prototype.toString.call(t)},isObject:function(t){return t instanceof Object},isValidSelector:function(t){if("string"!=typeof t)return!1;var e=t[0];return"#"===e||"."===e||e===e.toUpperCase()},_sign:function(t){return 0===t?0:0<t?1:-1},requestAnimFrame:function(t){p.push(t),1===p.length&&requestAnimationFrame(function(){var t=p;p=[],t.forEach(function(t){t()})})},createCanvasElement:function(){var t=document.createElement("canvas");try{t.style=t.style||{}}catch(t){}return t},createImageElement:function(){return document.createElement("img")},_isInDocument:function(t){for(;t=t.parentNode;)if(t==document)return!0;return!1},_simplifyArray:function(t){var e,i,n=[],r=t.length,o=D;for(e=0;e<r;e++)i=t[e],o._isNumber(i)?i=Math.round(1e3*i)/1e3:o._isString(i)||(i=i.toString()),n.push(i);return n},_urlToImage:function(t,e){var i=new n.Image;i.onload=function(){e(i)},i.src=t},_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 l?{r:(e=l[t])[0],g:e[1],b:e[2]}:"#"===t[0]?this._hexToRgb(t.substring(1)):"rgb("===t.substr(0,4)?(e=d.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",D._namedColorToRBA(t)||D._hex3ColorToRGBA(t)||D._hex6ColorToRGBA(t)||D._rgbColorToRGBA(t)||D._rgbaColorToRGBA(t)},_namedColorToRBA:function(t){var e=l[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}},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._isPlainObject(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*r},_radToDeg:function(t){return t*a},_capitalize:function(t){return t.charAt(0).toUpperCase()+t.slice(1)},throw:function(t){throw new Error(s+t)},error:function(t){console.error(s+t)},warn:function(t){O.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 r in t.prototype=new i,n)n.hasOwnProperty(r)&&(t.prototype[r]=n[r]);t.__super__=e.prototype,t.super=e},_getControlPoints:function(t,e,i,n,r,o,a){var s=Math.sqrt(Math.pow(i-t,2)+Math.pow(n-e,2)),h=Math.sqrt(Math.pow(r-i,2)+Math.pow(o-n,2)),l=a*s/(s+h),c=a*h/(s+h);return[i-l*(r-t),n-l*(o-e),i+c*(r-t),n+c*(o-e)]},_expandPoints:function(t,e){var i,n,r=t.length,o=[];for(i=2;i<r-2;i+=2)n=D._getControlPoints(t[i-2],t[i-1],t[i],t[i+1],t[i+2],t[i+3],e),o.push(n[0]),o.push(n[1]),o.push(t[i]),o.push(t[i+1]),o.push(n[2]),o.push(n[3]);return o},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,r,o){var a,s,h,l=(t-i)*(t-i)+(e-n)*(e-n);if(0==l)a=t,s=e,h=(r-i)*(r-i)+(o-n)*(o-n);else{var c=((r-t)*(i-t)+(o-e)*(n-e))/l;h=c<0?((a=t)-r)*(t-r)+((s=e)-o)*(e-o):1<c?((a=i)-r)*(i-r)+((s=n)-o)*(n-o):((a=t+c*(i-t))-r)*(a-r)+((s=e+c*(n-e))-o)*(s-o)}return[a,s,h]},_getProjectionToLine:function(s,h,l){var c=D.cloneObject(s),d=Number.MAX_VALUE;return h.forEach(function(t,e){if(l||e!==h.length-1){var i=h[(e+1)%h.length],n=D._getProjectionToSegment(t.x,t.y,i.x,i.y,s.x,s.y),r=n[0],o=n[1],a=n[2];a<d&&(c.x=r,c.y=o,d=a)}}),c},_prepareArrayForTween:function(t,e,i){var n,r=[],o=[];if(t.length>e.length){var a=e;e=t,t=a}for(n=0;n<t.length;n+=2)r.push({x:t[n],y:t[n+1]});for(n=0;n<e.length;n+=2)o.push({x:e[n],y:e[n+1]});var s=[];return o.forEach(function(t){var e=D._getProjectionToLine(t,r,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||D._isElement(t[i])){if(!e.configurable)return null;delete t[i]}else if(null===D._prepareToStringify(t[i])){if(!e.configurable)return null;delete t[i]}return delete t.visitedByCircularReferenceRemoval,t},_assign:function(t,e){for(var i in e)t[i]=e[i];return t}};function u(t){return D._isString(t)?'"'+t+'"':"[object Number]"===Object.prototype.toString.call(t)?t:D._isBoolean(t)?t:Object.prototype.toString.call(t)}function f(t){return 255<t?255:t<0?0:Math.round(t)}function g(){if(O.isUnminified)return function(t,e){return D._isNumber(t)||D.warn(u(t)+' is a not valid value for "'+e+'" attribute. The value should be a number.'),t}}function v(){if(O.isUnminified)return function(t,e){return D._isNumber(t)||"auto"===t||D.warn(u(t)+' is a not valid value for "'+e+'" attribute. The value should be a number or "auto".'),t}}function y(){if(O.isUnminified)return function(t,e){return D._isString(t)||D.warn(u(t)+' is a not valid value for "'+e+'" attribute. The value should be a string.'),t}}function m(){if(O.isUnminified)return function(t,e){return!0===t||!1===t||D.warn(u(t)+' is a not valid value for "'+e+'" attribute. The value should be a boolean.'),t}}var _="get",S="set",b={addGetterSetter:function(t,e,i,n,r){this.addGetter(t,e,i),this.addSetter(t,e,n,r),this.addOverloadedGetterSetter(t,e)},addGetter:function(t,e,i){var n=_+D._capitalize(e);t.prototype[n]=t.prototype[n]||function(){var t=this.attrs[e];return void 0===t?i:t}},addSetter:function(t,e,i,n){var r=S+D._capitalize(e);t.prototype[r]||b.overWriteSetter(t,e,i,n)},overWriteSetter:function(t,e,i,n){var r=S+D._capitalize(e);t.prototype[r]=function(t){return i&&null!=t&&(t=i.call(this,t,e)),this._setAttr(e,t),n&&n.call(this),this}},addComponentsGetterSetter:function(t,n,e,r,o){var i,a,s=e.length,h=D._capitalize,l=_+h(n),c=S+h(n);t.prototype[l]=function(){var t={};for(i=0;i<s;i++)t[a=e[i]]=this.getAttr(n+h(a));return t};var d=function(i){if(O.isUnminified)return function(t,e){return D.isObject(t)||D.warn(u(t)+' is a not valid value for "'+e+'" attribute. The value should be an object with properties '+i),t}}(e);t.prototype[c]=function(t){var e,i=this.attrs[n];for(e in r&&(t=r.call(this,t)),d&&d.call(this,t,n),t)t.hasOwnProperty(e)&&this._setAttr(n+h(e),t[e]);return this._fireChangeEvent(n,i,t),o&&o.call(this),this},this.addOverloadedGetterSetter(t,n)},addOverloadedGetterSetter:function(t,e){var i=D._capitalize(e),n=S+i,r=_+i;t.prototype[e]=function(){return arguments.length?(this[n](arguments[0]),this):this[r]()}},addDeprecatedGetterSetter:function(t,e,i,n){D.error("Adding deprecated "+e);var r=_+D._capitalize(e),o=e+" property is deprecated and will be removed soon. Look at Konva change log for more information.";t.prototype[r]=function(){D.error(o);var t=this.attrs[e];return void 0===t?i:t},this.addSetter(t,e,n,function(){D.error(o)}),this.addOverloadedGetterSetter(t,e)},backCompat:function(a,t){D.each(t,function(t,e){var i=a.prototype[e],n=_+D._capitalize(t),r=S+D._capitalize(t);function o(){i.apply(this,arguments),D.error('"'+t+'" method is deprecated and will be removed soon. Use ""'+e+'" instead.')}a.prototype[t]=o,a.prototype[n]=o,a.prototype[r]=o})},afterSetFilter:function(){this._filterUpToDate=!1}},x=function(t,e){return(x=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i])})(t,e)};function w(t,e){function i(){this.constructor=t}x(t,e),t.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)}var C=["arc","arcTo","beginPath","bezierCurveTo","clearRect","clip","closePath","createLinearGradient","createPattern","createRadialGradient","drawImage","ellipse","fill","fillText","getImageData","createImageData","lineTo","moveTo","putImageData","quadraticCurveTo","rect","restore","rotate","save","scale","setLineDash","setTransform","stroke","strokeText","transform","translate"],k=function(){function t(t){this.canvas=t,this._context=t._canvas.getContext("2d"),O.enableTrace&&(this.traceArr=[],this._enableTrace())}return t.prototype.fillShape=function(t){t.getFillEnabled()&&this._fill(t)},t.prototype._fill=function(t){},t.prototype.strokeShape=function(t){t.getStrokeEnabled()&&this._stroke(t)},t.prototype._stroke=function(t){},t.prototype.fillStrokeShape=function(t){t.getFillEnabled()&&this._fill(t),t.getStrokeEnabled()&&this._stroke(t)},t.prototype.getTrace=function(t){var e,i,n,r,o=this.traceArr,a=o.length,s="";for(e=0;e<a;e++)(n=(i=o[e]).method)?(r=i.args,s+=n,t?s+="()":D._isArray(r[0])?s+="(["+r.join(",")+"])":s+="("+r.join(",")+")"):(s+=i.property,t||(s+="="+i.val)),s+=";";return s},t.prototype.clearTrace=function(){this.traceArr=[]},t.prototype._trace=function(t){var e=this.traceArr;e.push(t),100<=e.length&&e.shift()},t.prototype.reset=function(){var t=this.getCanvas().getPixelRatio();this.setTransform(1*t,0,0,1*t,0,0)},t.prototype.getCanvas=function(){return this.canvas},t.prototype.clear=function(t){var e=this.getCanvas();t?this.clearRect(t.x||0,t.y||0,t.width||0,t.height||0):this.clearRect(0,0,e.getWidth()/e.pixelRatio,e.getHeight()/e.pixelRatio)},t.prototype._applyLineCap=function(t){var e=t.getLineCap();e&&this.setAttr("lineCap",e)},t.prototype._applyOpacity=function(t){var e=t.getAbsoluteOpacity();1!==e&&this.setAttr("globalAlpha",e)},t.prototype._applyLineJoin=function(t){var e=t.getLineJoin();e&&this.setAttr("lineJoin",e)},t.prototype.setAttr=function(t,e){this._context[t]=e},t.prototype.arc=function(t,e,i,n,r,o){this._context.arc(t,e,i,n,r,o)},t.prototype.arcTo=function(t,e,i,n,r,o){this._context.arc(t,e,i,n,r,o)},t.prototype.beginPath=function(){this._context.beginPath()},t.prototype.bezierCurveTo=function(t,e,i,n,r,o){this._context.bezierCurveTo(t,e,i,n,r,o)},t.prototype.clearRect=function(t,e,i,n){this._context.clearRect(t,e,i,n)},t.prototype.clip=function(){this._context.clip()},t.prototype.closePath=function(){this._context.closePath()},t.prototype.createImageData=function(t,e){var i=arguments;return 2===i.length?this._context.createImageData(t,e):1===i.length?this._context.createImageData(t):void 0},t.prototype.createLinearGradient=function(t,e,i,n){return this._context.createLinearGradient(t,e,i,n)},t.prototype.createPattern=function(t,e){return this._context.createPattern(t,e)},t.prototype.createRadialGradient=function(t,e,i,n,r,o){return this._context.createRadialGradient(t,e,i,n,r,o)},t.prototype.drawImage=function(t,e,i,n,r,o,a,s,h){var l=arguments,c=this._context;3===l.length?c.drawImage(t,e,i):5===l.length?c.drawImage(t,e,i,n,r):9===l.length&&c.drawImage(t,e,i,n,r,o,a,s,h)},t.prototype.ellipse=function(t,e,i,n,r,o,a,s){this._context.ellipse(t,e,i,n,r,o,a,s)},t.prototype.isPointInPath=function(t,e){return this._context.isPointInPath(t,e)},t.prototype.fill=function(){this._context.fill()},t.prototype.fillRect=function(t,e,i,n){this._context.fillRect(t,e,i,n)},t.prototype.strokeRect=function(t,e,i,n){this._context.strokeRect(t,e,i,n)},t.prototype.fillText=function(t,e,i){this._context.fillText(t,e,i)},t.prototype.measureText=function(t){return this._context.measureText(t)},t.prototype.getImageData=function(t,e,i,n){return this._context.getImageData(t,e,i,n)},t.prototype.lineTo=function(t,e){this._context.lineTo(t,e)},t.prototype.moveTo=function(t,e){this._context.moveTo(t,e)},t.prototype.rect=function(t,e,i,n){this._context.rect(t,e,i,n)},t.prototype.putImageData=function(t,e,i){this._context.putImageData(t,e,i)},t.prototype.quadraticCurveTo=function(t,e,i,n){this._context.quadraticCurveTo(t,e,i,n)},t.prototype.restore=function(){this._context.restore()},t.prototype.rotate=function(t){this._context.rotate(t)},t.prototype.save=function(){this._context.save()},t.prototype.scale=function(t,e){this._context.scale(t,e)},t.prototype.setLineDash=function(t){this._context.setLineDash?this._context.setLineDash(t):"mozDash"in this._context?this._context.mozDash=t:"webkitLineDash"in this._context&&(this._context.webkitLineDash=t)},t.prototype.getLineDash=function(){return this._context.getLineDash()},t.prototype.setTransform=function(t,e,i,n,r,o){this._context.setTransform(t,e,i,n,r,o)},t.prototype.stroke=function(){this._context.stroke()},t.prototype.strokeText=function(t,e,i,n){this._context.strokeText(t,e,i,n)},t.prototype.transform=function(t,e,i,n,r,o){this._context.transform(t,e,i,n,r,o)},t.prototype.translate=function(t,e){this._context.translate(t,e)},t.prototype._enableTrace=function(){var t,n,r=this,e=C.length,o=D._simplifyArray,i=this.setAttr,a=function(t){var e,i=r[t];r[t]=function(){return n=o(Array.prototype.slice.call(arguments,0)),e=i.apply(r,arguments),r._trace({method:t,args:n}),e}};for(t=0;t<e;t++)a(C[t]);r.setAttr=function(){i.apply(r,arguments);var t=arguments[0],e=arguments[1];"shadowOffsetX"!==t&&"shadowOffsetY"!==t&&"shadowBlur"!==t||(e/=this.canvas.getPixelRatio()),r._trace({property:t,val:e})}},t.prototype._applyGlobalCompositeOperation=function(t){var e=t.getGlobalCompositeOperation();"source-over"!==e&&this.setAttr("globalCompositeOperation",e)},t}();["fillStyle","strokeStyle","shadowColor","shadowBlur","shadowOffsetX","shadowOffsetY","lineCap","lineDashOffset","lineJoin","lineWidth","miterLimit","font","textAlign","textBaseline","globalAlpha","globalCompositeOperation","imageSmoothingEnabled"].forEach(function(e){Object.defineProperty(k.prototype,e,{get:function(){return this._context[e]},set:function(t){this._context[e]=t}})});var P,T=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return w(e,t),e.prototype._fillColor=function(t){var e=t.fill();this.setAttr("fillStyle",e),t._fillFunc(this)},e.prototype._fillPattern=function(t){var e=t.getFillPatternX(),i=t.getFillPatternY(),n=t.getFillPatternScaleX(),r=t.getFillPatternScaleY(),o=O.getAngle(t.getFillPatternRotation()),a=t.getFillPatternOffsetX(),s=t.getFillPatternOffsetY();(e||i)&&this.translate(e||0,i||0),o&&this.rotate(o),(n||r)&&this.scale(n,r),(a||s)&&this.translate(-1*a,-1*s),this.setAttr("fillStyle",t._getFillPattern()),t._fillFunc(this)},e.prototype._fillLinearGradient=function(t){var e=t._getLinearGradient();e&&(this.setAttr("fillStyle",e),t._fillFunc(this))},e.prototype._fillRadialGradient=function(t){var e=t._getRadialGradient();e&&(this.setAttr("fillStyle",e),t._fillFunc(this))},e.prototype._fill=function(t){var e=t.fill(),i=t.getFillPriority();if(e&&"color"===i)this._fillColor(t);else{var n=t.getFillPatternImage();if(n&&"pattern"===i)this._fillPattern(t);else{var r=t.getFillLinearGradientColorStops();if(r&&"linear-gradient"===i)this._fillLinearGradient(t);else{var o=t.getFillRadialGradientColorStops();o&&"radial-gradient"===i?this._fillRadialGradient(t):e?this._fillColor(t):n?this._fillPattern(t):r?this._fillLinearGradient(t):o&&this._fillRadialGradient(t)}}}},e.prototype._strokeLinearGradient=function(t){var e=t.getStrokeLinearGradientStartPoint(),i=t.getStrokeLinearGradientEndPoint(),n=t.getStrokeLinearGradientColorStops(),r=this.createLinearGradient(e.x,e.y,i.x,i.y);if(n){for(var o=0;o<n.length;o+=2)r.addColorStop(n[o],n[o+1]);this.setAttr("strokeStyle",r)}},e.prototype._stroke=function(t){var e=t.dash(),i=t.getStrokeScaleEnabled();if(t.hasStroke()){if(!i){this.save();var n=this.getCanvas().getPixelRatio();this.setTransform(n,0,0,n,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()}},e.prototype._applyShadow=function(t){var e=D,i=e.get(t.getShadowRGBA(),"black"),n=e.get(t.getShadowBlur(),5),r=e.get(t.getShadowOffset(),{x:0,y:0}),o=t.getAbsoluteScale(),a=this.canvas.getPixelRatio(),s=o.x*a,h=o.y*a;this.setAttr("shadowColor",i),this.setAttr("shadowBlur",n*Math.min(Math.abs(s),Math.abs(h))),this.setAttr("shadowOffsetX",r.x*s),this.setAttr("shadowOffsetY",r.y*h)},e}(k),M=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return w(e,t),e.prototype._fill=function(t){this.save(),this.setAttr("fillStyle",t.colorKey),t._fillFuncHit(this),this.restore()},e.prototype._stroke=function(t){if(t.hasStroke()&&t.hitStrokeWidth()){var e=t.getStrokeScaleEnabled();if(!e){this.save();var i=this.getCanvas().getPixelRatio();this.setTransform(i,0,0,i,0,0)}this._applyLineCap(t);var n=t.hitStrokeWidth(),r="auto"===n?t.strokeWidth():n;this.setAttr("lineWidth",r),this.setAttr("strokeStyle",t.colorKey),t._strokeFuncHit(this),e||this.restore()}},e}(k);var A=function(){function t(t){this.pixelRatio=1,this.width=0,this.height=0,this.isCache=!1;var e=(t||{}).pixelRatio||O.pixelRatio||function(){if(P)return P;var t=D.createCanvasElement().getContext("2d");return P=(O._global.devicePixelRatio||1)/(t.webkitBackingStorePixelRatio||t.mozBackingStorePixelRatio||t.msBackingStorePixelRatio||t.oBackingStorePixelRatio||t.backingStorePixelRatio||1)}();this.pixelRatio=e,this._canvas=D.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"}return t.prototype.getContext=function(){return this.context},t.prototype.getPixelRatio=function(){return this.pixelRatio},t.prototype.setPixelRatio=function(t){var e=this.pixelRatio;this.pixelRatio=t,this.setSize(this.getWidth()/e,this.getHeight()/e)},t.prototype.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)},t.prototype.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)},t.prototype.getWidth=function(){return this.width},t.prototype.getHeight=function(){return this.height},t.prototype.setSize=function(t,e){this.setWidth(t),this.setHeight(e)},t.prototype.toDataURL=function(t,e){try{return this._canvas.toDataURL(t,e)}catch(t){try{return this._canvas.toDataURL()}catch(t){return D.error("Unable to get data URL. "+t.message),""}}},t}();b.addGetterSetter(A,"pixelRatio",void 0,g());var G=function(i){function t(t){void 0===t&&(t={width:0,height:0});var e=i.call(this,t)||this;return e.context=new T(e),e.setSize(t.width,t.height),e}return w(t,i),t}(A),R=function(i){function t(t){void 0===t&&(t={width:0,height:0});var e=i.call(this,t)||this;return e.hitCanvas=!0,e.context=new M(e),e.setSize(t.width,t.height),e}return w(t,i),t}(A),L=n.performance&&n.performance.now?function(){return n.performance.now()}:function(){return(new Date).getTime()},I=function(){function n(t,e){this.id=n.animIdCounter++,this.frame={time:0,timeDiff:0,lastTime:L(),frameRate:0},this.func=t,this.setLayers(e)}return n.prototype.setLayers=function(t){var e=[];return e=t?0<t.length?t:[t]:[],this.layers=e,this},n.prototype.getLayers=function(){return this.layers},n.prototype.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},n.prototype.isRunning=function(){var t,e=n.animations,i=e.length;for(t=0;t<i;t++)if(e[t].id===this.id)return!0;return!1},n.prototype.start=function(){return this.stop(),this.frame.timeDiff=0,this.frame.lastTime=L(),n._addAnimation(this),this},n.prototype.stop=function(){return n._removeAnimation(this),this},n.prototype._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._addAnimation=function(t){this.animations.push(t),this._handleAnimation()},n._removeAnimation=function(t){var e,i=t.id,n=this.animations,r=n.length;for(e=0;e<r;e++)if(n[e].id===i){this.animations.splice(e,1);break}},n._runFrames=function(){var t,e,i,n,r,o,a,s,h={},l=this.animations;for(n=0;n<l.length;n++)if(e=(t=l[n]).layers,i=t.func,t._updateFrameObject(L()),o=e.length,!i||!1!==i.call(t,t.frame))for(r=0;r<o;r++)void 0!==(a=e[r])._id&&(h[a._id]=a);for(s in h)h.hasOwnProperty(s)&&h[s].draw()},n._animationLoop=function(){var t=n;t.animations.length?(t._runFrames(),requestAnimationFrame(t._animationLoop)):t.animRunning=!1},n._handleAnimation=function(){this.animRunning||(this.animRunning=!0,requestAnimationFrame(this._animationLoop))},n.animations=[],n.animIdCounter=0,n.animRunning=!1,n}(),E={startPointerPos:{x:0,y:0},anim:new I(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=E.node;if(e){if(!E.isDragging){var i=e.getStage().getPointerPosition();i||(e.getStage().setPointersPositions(t),i=e.getStage().getPointerPosition());var n=e.dragDistance();if(Math.max(Math.abs(i.x-E.startPointerPos.x),Math.abs(i.y-E.startPointerPos.y))<n)return}if(e.getStage().setPointersPositions(t),!E.isDragging&&(E.isDragging=!0,e.fire("dragstart",{type:"dragstart",target:e,evt:t},!0),!e.isDragging()))return;e._setDragPosition(t),e.fire("dragmove",{type:"dragmove",target:e,evt:t},!0)}},_endDragBefore:function(t){var e=E.node;if(e){E.anim.stop(),E.isDragging&&(E.isDragging=!1,E.justDragged=!0,O.listenClickTap=!1,t&&(t.dragEndNode=e)),E.node=null;var i=e.getLayer()||e instanceof O.Stage&&e;i&&i.draw()}},_endDragAfter:function(t){var e=(t=t||{}).dragEndNode;t&&e&&e.fire("dragend",{type:"dragend",target:e,evt:t},!0)}};O.isBrowser&&(window.addEventListener("mouseup",E._endDragBefore,!0),window.addEventListener("touchend",E._endDragBefore,!0),window.addEventListener("mousemove",E._drag),window.addEventListener("touchmove",E._drag),window.addEventListener("mouseup",E._endDragAfter,!1),window.addEventListener("touchend",E._endDragAfter,!1));var F={},z={},B=function(t,e){t&&F[t]===e&&delete F[t]},W=function(t,e){if(t){var i=z[t];if(i){for(var n=0;n<i.length;n++){i[n]._id===e&&i.splice(n,1)}0===i.length&&delete z[t]}}},N="absoluteOpacity",H="absoluteTransform",Y="absoluteScale",X="canvas",j="listening",U="mouseenter",q="mouseleave",V="transform",K="visible",Q=["id"],J=["xChange.konva","yChange.konva","scaleXChange.konva","scaleYChange.konva","skewXChange.konva","skewYChange.konva","rotationChange.konva","offsetXChange.konva","offsetYChange.konva","transformsEnabledChange.konva"].join(" "),Z=["scaleXChange.konva","scaleYChange.konva"].join(" "),$=new o,tt=1,et=function(){function s(t){var e=this;this._id=tt++,this.eventListeners={},this.attrs={},this.index=0,this.parent=null,this._cache=new Map,this._lastPos=null,this._filterUpToDate=!1,this._isUnderCache=!1,this.children=$,this.setAttrs(t),this.on(J,function(){e._clearCache(V),e._clearSelfAndDescendantCache(H)}),this.on(Z,function(){e._clearSelfAndDescendantCache(Y)}),this.on("visibleChange.konva",function(){e._clearSelfAndDescendantCache(K)}),this.on("listeningChange.konva",function(){e._clearSelfAndDescendantCache(j)}),this.on("opacityChange.konva",function(){e._clearSelfAndDescendantCache(N)})}return s.prototype.hasChildren=function(){return!1},s.prototype.getChildren=function(){return $},s.prototype._clearCache=function(t){t?this._cache.delete(t):this._cache.clear()},s.prototype._getCache=function(t,e){var i=this._cache.get(t);return void 0===i&&(i=e.call(this),this._cache.set(t,i)),i},s.prototype._getCanvasCache=function(){return this._cache.get(X)},s.prototype._clearSelfAndDescendantCache=function(e){this._clearCache(e),this._getCanvasCache()||this.children&&this.children.each(function(t){t._clearSelfAndDescendantCache(e)})},s.prototype.clearCache=function(){return this._cache.delete(X),this._clearSelfAndDescendantCache(),this},s.prototype.cache=function(t){var e=t||{},i={};void 0!==e.x&&void 0!==e.y&&void 0!==e.width&&void 0!==e.height||(i=this.getClientRect({skipTransform:!0,relativeTo:this.getParent()}));var n=e.width||i.width,r=e.height||i.height,o=e.pixelRatio,a=void 0===e.x?i.x:e.x,s=void 0===e.y?i.y:e.y,h=e.offset||0,l=e.drawBorder||!1;if(n&&r){a-=h,s-=h;var c=new G({pixelRatio:o,width:n+=2*h,height:r+=2*h}),d=new G({pixelRatio:o,width:n,height:r}),p=new R({pixelRatio:1,width:n,height:r}),u=c.getContext(),f=p.getContext();return p.isCache=!0,this._cache.delete("canvas"),(this._filterUpToDate=!1)===e.imageSmoothingEnabled&&(c.getContext()._context.imageSmoothingEnabled=!1,d.getContext()._context.imageSmoothingEnabled=!1,p.getContext()._context.imageSmoothingEnabled=!1),u.save(),f.save(),u.translate(-a,-s),f.translate(-a,-s),this._isUnderCache=!0,this._clearSelfAndDescendantCache(N),this._clearSelfAndDescendantCache(Y),this.drawScene(c,this,!0),this.drawHit(p,this,!0),this._isUnderCache=!1,u.restore(),f.restore(),l&&(u.save(),u.beginPath(),u.rect(0,0,n,r),u.closePath(),u.setAttr("strokeStyle","red"),u.setAttr("lineWidth",5),u.stroke(),u.restore()),this._cache.set(X,{scene:c,filter:d,hit:p,x:a,y:s}),this}D.error("Can not cache the node. Width or height of the node equals 0. Caching is skipped.")},s.prototype.getClientRect=function(t){throw new Error('abstract "getClientRect" method call')},s.prototype._transformedRect=function(t,e){var i,n,r,o,a=[{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 a.forEach(function(t){var e=s.point(t);void 0===i&&(i=r=e.x,n=o=e.y),i=Math.min(i,e.x),n=Math.min(n,e.y),r=Math.max(r,e.x),o=Math.max(o,e.y)}),{x:i,y:n,width:r-i,height:o-n}},s.prototype._drawCachedSceneCanvas=function(t){t.save(),t._applyOpacity(this),t._applyGlobalCompositeOperation(this);var e=this._getCanvasCache();t.translate(e.x,e.y);var i=this._getCachedSceneCanvas(),n=i.pixelRatio;t.drawImage(i._canvas,0,0,i.width/n,i.height/n),t.restore()},s.prototype._drawCachedHitCanvas=function(t){var e=this._getCanvasCache(),i=e.hit;t.save(),t._applyGlobalCompositeOperation(this),t.translate(e.x,e.y),t.drawImage(i._canvas,0,0),t.restore()},s.prototype._getCachedSceneCanvas=function(){var t,e,i,n,r=this.filters(),o=this._getCanvasCache(),a=o.scene,s=o.filter,h=s.getContext();if(r){if(!this._filterUpToDate){var l=a.pixelRatio;try{for(t=r.length,h.clear(),h.drawImage(a._canvas,0,0,a.getWidth()/l,a.getHeight()/l),e=h.getImageData(0,0,s.getWidth(),s.getHeight()),i=0;i<t;i++)"function"==typeof(n=r[i])?(n.call(this,e),h.putImageData(e,0,0)):D.error("Filter should be type of function, but got "+typeof n+" insted. Please check correct filters")}catch(t){D.error("Unable to apply filter. "+t.message)}this._filterUpToDate=!0}return s}return a},s.prototype.on=function(t,e){if(3===arguments.length)return this._delegate.apply(this,arguments);var i,n,r,o,a=t.split(" "),s=a.length;for(i=0;i<s;i++)r=(n=a[i].split("."))[0],o=n[1]||"",this.eventListeners[r]||(this.eventListeners[r]=[]),this.eventListeners[r].push({name:o,handler:e});return this},s.prototype.off=function(t,e){var i,n,r,o,a,s=(t||"").split(" "),h=s.length;if(!t)for(n in this.eventListeners)this._off(n);for(i=0;i<h;i++)if(o=(r=s[i].split("."))[0],a=r[1],o)this.eventListeners[o]&&this._off(o,a,e);else for(n in this.eventListeners)this._off(n,a,e);return this},s.prototype.dispatchEvent=function(t){var e={target:this,type:t.type,evt:t};return this.fire(t.type,e),this},s.prototype.addEventListener=function(t,e){return this.on(t,function(t){e.call(this,t.evt)}),this},s.prototype.removeEventListener=function(t){return this.off(t),this},s.prototype._delegate=function(t,n,r){var o=this;this.on(t,function(t){for(var e=t.target.findAncestors(n,!0,o),i=0;i<e.length;i++)(t=D.cloneObject(t)).currentTarget=e[i],r.call(e[i],t)})},s.prototype.remove=function(){return E.node&&E.node===this&&this.stopDrag(),this._remove(),this},s.prototype._remove=function(){this._clearSelfAndDescendantCache("stage"),this._clearSelfAndDescendantCache(H),this._clearSelfAndDescendantCache(K),this._clearSelfAndDescendantCache(j),this._clearSelfAndDescendantCache(N);var t=this.getParent();t&&t.children&&(t.children.splice(this.index,1),t._setChildrenIndices(),this.parent=null)},s.prototype.destroy=function(){B(this.id(),this);for(var t=(this.name()||"").split(/\s/g),e=0;e<t.length;e++){var i=t[e];W(i,this._id)}return this.remove(),this},s.prototype.getAttr=function(t){var e="get"+D._capitalize(t);return D._isFunction(this[e])?this[e]():this.attrs[t]},s.prototype.getAncestors=function(){for(var t=this.getParent(),e=new o;t;)e.push(t),t=t.getParent();return e},s.prototype.getAttrs=function(){return this.attrs||{}},s.prototype.setAttrs=function(t){var e,i;if(!t)return this;for(e in t)"children"!==e&&(i="set"+D._capitalize(e),D._isFunction(this[i])?this[i](t[e]):this._setAttr(e,t[e]));return this},s.prototype.isListening=function(){return this._getCache(j,this._isListening)},s.prototype._isListening=function(){var t=this.listening(),e=this.getParent();return"inherit"===t?!e||e.isListening():t},s.prototype.isVisible=function(){return this._getCache(K,this._isVisible)},s.prototype._isVisible=function(t){var e=this.visible(),i=this.getParent();return"inherit"===e?!i||i===t||i._isVisible(t):e},s.prototype.shouldDrawHit=function(){var t=this.getLayer();return!t&&this.isListening()&&this.isVisible()||t&&t.hitGraphEnabled()&&this.isListening()&&this.isVisible()},s.prototype.show=function(){return this.visible(!0),this},s.prototype.hide=function(){return this.visible(!1),this},s.prototype.getZIndex=function(){return this.index||0},s.prototype.getAbsoluteZIndex=function(){var i,n,r,o,a=this.getDepth(),s=this,h=0;return"Stage"!==s.nodeType&&function t(e){for(i=[],n=e.length,r=0;r<n;r++)o=e[r],h++,"Shape"!==o.nodeType&&(i=i.concat(o.getChildren().toArray())),o._id===s._id&&(r=n);0<i.length&&i[0].getDepth()<=a&&t(i)}(s.getStage().getChildren()),h},s.prototype.getDepth=function(){for(var t=0,e=this.parent;e;)t++,e=e.parent;return t},s.prototype.setPosition=function(t){return this.x(t.x),this.y(t.y),this},s.prototype.getPosition=function(){return{x:this.x(),y:this.y()}},s.prototype.getAbsolutePosition=function(t){var e=this.getAbsoluteTransform(t).getMatrix(),i=new c,n=this.offset();return i.m=e.slice(),i.translate(n.x,n.y),i.getTranslation()},s.prototype.setAbsolutePosition=function(t){var e,i=this._clearTransform();return this.attrs.x=i.x,this.attrs.y=i.y,delete i.x,delete i.y,(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},s.prototype._setTransform=function(t){var e;for(e in t)this.attrs[e]=t[e];this._clearCache(V),this._clearSelfAndDescendantCache(H)},s.prototype._clearTransform=function(){var t={x:this.x(),y:this.y(),rotation:this.rotation(),scaleX:this.scaleX(),scaleY:this.scaleY(),offsetX:this.offsetX(),offsetY:this.offsetY(),skewX:this.skewX(),skewY:this.skewY()};return this.attrs.x=0,this.attrs.y=0,this.attrs.rotation=0,this.attrs.scaleX=1,this.attrs.scaleY=1,this.attrs.offsetX=0,this.attrs.offsetY=0,this.attrs.skewX=0,this.attrs.skewY=0,this._clearCache(V),this._clearSelfAndDescendantCache(H),t},s.prototype.move=function(t){var e=t.x,i=t.y,n=this.x(),r=this.y();return void 0!==e&&(n+=e),void 0!==i&&(r+=i),this.setPosition({x:n,y:r}),this},s.prototype._eachAncestorReverse=function(t,e){var i,n,r=[],o=this.getParent();if(e&&e._id===this._id)t(this);else{for(r.unshift(this);o&&(!e||o._id!==e._id);)r.unshift(o),o=o.parent;for(i=r.length,n=0;n<i;n++)t(r[n])}},s.prototype.rotate=function(t){return this.rotation(this.rotation()+t),this},s.prototype.moveToTop=function(){if(!this.parent)return D.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},s.prototype.moveUp=function(){if(!this.parent)return D.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)},s.prototype.moveDown=function(){if(!this.parent)return D.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)},s.prototype.moveToBottom=function(){if(!this.parent)return D.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)},s.prototype.setZIndex=function(t){if(!this.parent)return D.warn("Node has no parent. zIndex parameter is ignored."),this;(t<0||t>=this.parent.children.length)&&D.warn("Unexpected value "+t+" for zIndex property. zIndex is just index of a node in children of its parent. Expected value is from 0 to "+(this.parent.children.length-1)+".");var e=this.index;return this.parent.children.splice(e,1),this.parent.children.splice(t,0,this),this.parent._setChildrenIndices(),this},s.prototype.getAbsoluteOpacity=function(){return this._getCache(N,this._getAbsoluteOpacity)},s.prototype._getAbsoluteOpacity=function(){var t=this.opacity(),e=this.getParent();return e&&!e._isUnderCache&&(t*=e.getAbsoluteOpacity()),t},s.prototype.moveTo=function(t){return this.getParent()!==t&&(this._remove(),t.add(this)),this},s.prototype.toObject=function(){var t,e,i,n={},r=this.getAttrs();for(t in n.attrs={},r)e=r[t],D.isObject(e)&&!D._isPlainObject(e)&&!D._isArray(e)||(i="function"==typeof this[t]&&this[t],delete r[t],(i?i.call(this):null)!==(r[t]=e)&&(n.attrs[t]=e));return n.className=this.getClassName(),D._prepareToStringify(n)},s.prototype.toJSON=function(){return JSON.stringify(this.toObject())},s.prototype.getParent=function(){return this.parent},s.prototype.findAncestors=function(t,e,i){var n=[];e&&this._isMatch(t)&&n.push(this);for(var r=this.parent;r;){if(r===i)return n;r._isMatch(t)&&n.push(r),r=r.parent}return n},s.prototype.isAncestorOf=function(t){return!1},s.prototype.findAncestor=function(t,e,i){return this.findAncestors(t,e,i)[0]},s.prototype._isMatch=function(t){if(!t)return!1;if("function"==typeof t)return t(this);var e,i,n=t.replace(/ /g,"").split(","),r=n.length;for(e=0;e<r;e++)if(i=n[e],D.isValidSelector(i)||(D.warn('Selector "'+i+'" is invalid. Allowed selectors examples are "#foo", ".bar" or "Group".'),D.warn('If you have a custom shape with such className, please change it to start with upper letter like "Triangle".'),D.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(this.className===t||this.nodeType===t)return!0;return!1},s.prototype.getLayer=function(){var t=this.getParent();return t?t.getLayer():null},s.prototype.getStage=function(){return this._getCache("stage",this._getStage)},s.prototype._getStage=function(){var t=this.getParent();return t?t.getStage():void 0},s.prototype.fire=function(t,e,i){return(e=e||{}).target=e.target||this,i?this._fireAndBubble(t,e):this._fire(t,e),this},s.prototype.getAbsoluteTransform=function(t){return t?this._getAbsoluteTransform(t):this._getCache(H,this._getAbsoluteTransform)},s.prototype._getAbsoluteTransform=function(t){var i=new c;return this._eachAncestorReverse(function(t){var e=t.getTransformsEnabled();"all"===e?i.multiply(t.getTransform()):"position"===e&&i.translate(t.getX()-t.getOffsetX(),t.getY()-t.getOffsetY())},t),i},s.prototype.getAbsoluteScale=function(t){return t?this._getAbsoluteScale(t):this._getCache(Y,this._getAbsoluteScale)},s.prototype._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}},s.prototype.getTransform=function(){return this._getCache(V,this._getTransform)},s.prototype._getTransform=function(){var t=new c,e=this.x(),i=this.y(),n=O.getAngle(this.rotation()),r=this.scaleX(),o=this.scaleY(),a=this.skewX(),s=this.skewY(),h=this.offsetX(),l=this.offsetY();return 0===e&&0===i||t.translate(e,i),0!==n&&t.rotate(n),0===a&&0===s||t.skew(a,s),1===r&&1===o||t.scale(r,o),0===h&&0===l||t.translate(-1*h,-1*l),t},s.prototype.clone=function(t){var e,i,n,r,o,a=D.cloneObject(this.attrs);for(var s in Q){delete a[Q[s]]}for(e in t)a[e]=t[e];var h=new this.constructor(a);for(e in this.eventListeners)for(n=(i=this.eventListeners[e]).length,r=0;r<n;r++)(o=i[r]).name.indexOf("konva")<0&&(h.eventListeners[e]||(h.eventListeners[e]=[]),h.eventListeners[e].push(o));return h},s.prototype._toKonvaCanvas=function(t){t=t||{};var e=this.getClientRect(),i=this.getStage(),n=void 0!==t.x?t.x:e.x,r=void 0!==t.y?t.y:e.y,o=t.pixelRatio||1,a=new G({width:t.width||e.width||(i?i.getWidth():0),height:t.height||e.height||(i?i.getHeight():0),pixelRatio:o}),s=a.getContext();return s.save(),(n||r)&&s.translate(-1*n,-1*r),this.drawScene(a),s.restore(),a},s.prototype.toCanvas=function(t){return this._toKonvaCanvas(t)._canvas},s.prototype.toDataURL=function(t){var e=(t=t||{}).mimeType||null,i=t.quality||null,n=this._toKonvaCanvas(t).toDataURL(e,i);return t.callback&&t.callback(n),n},s.prototype.toImage=function(t){if(!t||!t.callback)throw"callback required for toImage method config argument";var e=t.callback;delete t.callback,D._urlToImage(this.toDataURL(t),function(t){e(t)})},s.prototype.setSize=function(t){return this.width(t.width),this.height(t.height),this},s.prototype.getSize=function(){return{width:this.width(),height:this.height()}},s.prototype.getClassName=function(){return this.className||this.nodeType},s.prototype.getType=function(){return this.nodeType},s.prototype.getDragDistance=function(){return void 0!==this.attrs.dragDistance?this.attrs.dragDistance:this.parent?this.parent.getDragDistance():O.dragDistance},s.prototype._off=function(t,e,i){var n,r,o,a=this.eventListeners[t];for(n=0;n<a.length;n++)if(r=a[n].name,o=a[n].handler,!("konva"===r&&"konva"!==e||e&&r!==e||i&&i!==o)){if(a.splice(n,1),0===a.length){delete this.eventListeners[t];break}n--}},s.prototype._fireChangeEvent=function(t,e,i){this._fire(t+"Change",{oldVal:e,newVal:i})},s.prototype.setId=function(t){var e=this.id();return B(e,this),function(t,e){e&&(F[e]=t)}(this,t),this._setAttr("id",t),this},s.prototype.setName=function(t){var e,i,n,r,o=(this.name()||"").split(/\s/g),a=(t||"").split(/\s/g);for(i=0;i<o.length;i++)e=o[i],-1===a.indexOf(e)&&e&&W(e,this._id);for(i=0;i<a.length;i++)e=a[i],-1===o.indexOf(e)&&e&&(n=this,(r=e)&&(z[r]||(z[r]=[]),z[r].push(n)));return this._setAttr("name",t),this},s.prototype.addName=function(t){if(!this.hasName(t)){var e=this.name(),i=e?e+" "+t:t;this.setName(i)}return this},s.prototype.hasName=function(t){if(!t)return!1;var e=this.name();return!!e&&-1!==(e||"").split(/\s/g).indexOf(t)},s.prototype.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},s.prototype.setAttr=function(t,e){var i=this["set"+D._capitalize(t)];return D._isFunction(i)?i.call(this,e):this._setAttr(t,e),this},s.prototype._setAttr=function(t,e){var i=this.attrs[t];(i!==e||D.isObject(e))&&(null==e?delete this.attrs[t]:this.attrs[t]=e,this._fireChangeEvent(t,i,e))},s.prototype._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))},s.prototype._fireAndBubble=function(t,e,i){if(e&&"Shape"===this.nodeType&&(e.target=this),!((t===U||t===q)&&(i&&(this===i||this.isAncestorOf&&this.isAncestorOf(i))||"Stage"===this.nodeType&&!i))){this._fire(t,e);var n=(t===U||t===q)&&i&&i.isAncestorOf&&i.isAncestorOf(this)&&!i.isAncestorOf(this.parent);(e&&!e.cancelBubble||!e)&&this.parent&&this.parent.isListening()&&!n&&(i&&i.parent?this._fireAndBubble.call(this.parent,t,e,i.parent):this._fireAndBubble.call(this.parent,t,e))}},s.prototype._fire=function(t,e){var i,n=this.eventListeners[t];if(n)for((e=e||{}).currentTarget=this,e.type=t,i=0;i<n.length;i++)n[i].handler.call(this,e)},s.prototype.draw=function(){return this.drawScene(),this.drawHit(),this},s.prototype.startDrag=function(){var t=this.getStage(),e=this.getLayer(),i=t.getPointerPosition(),n=this.getAbsolutePosition();i&&(E.node&&E.node.stopDrag(),E.node=this,E.startPointerPos=i,E.offset.x=i.x-n.x,E.offset.y=i.y-n.y,E.anim.setLayers(e||this.getLayers()),E.anim.start(),this._setDragPosition())},s.prototype._setDragPosition=function(t){var e=this.getStage().getPointerPosition(),i=this.dragBoundFunc();if(e){var n={x:e.x-E.offset.x,y:e.y-E.offset.y};void 0!==i&&(n=i.call(this,n,t)),this.setAbsolutePosition(n),this._lastPos&&this._lastPos.x===n.x&&this._lastPos.y===n.y||(E.anim.dirty=!0),this._lastPos=n}},s.prototype.stopDrag=function(){var t={};E._endDragBefore(t),E._end