From 41c10555bc5f3d0f932e6d6ff7b05bd93353b905 Mon Sep 17 00:00:00 2001 From: lavrton Date: Thu, 16 Apr 2015 09:43:21 +0700 Subject: [PATCH] fix bug for wrong `getClientRect` calculation. close #50 --- CHANGELOG.md | 1 + konva.js | 49 ++++++++++++++++-------------------- konva.min.js | 6 ++--- src/Container.js | 16 +++++++++--- test/unit/Node-cache-test.js | 35 ++++++++++++++++++++++++++ 5 files changed, 72 insertions(+), 35 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d3b7d3d1..c5b08412 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - HDPI support for desktop - Fix bug when filters are not correct for HDPI - Fix bug when hit area is not correct for HDPI +- Fix bug for incorrect `getClientRect` calculation ### Changed - context wrapper is more capable with native context. diff --git a/konva.js b/konva.js index d71982ef..73a2d234 100644 --- a/konva.js +++ b/konva.js @@ -6585,10 +6585,18 @@ var Konva = {}; var minX, minY, maxX, maxY; this.children.each(function(child) { var rect = child.getClientRect(); - minX = Math.min(minX, rect.x) || rect.x; - minY = Math.min(minY, rect.y) || rect.y; - maxX = Math.max(maxX, rect.x + rect.width) || (rect.x + rect.width); - maxY = Math.max(maxY, rect.y + rect.height) || (rect.y + rect.height); + if (minX === undefined) { // initial value for first child + minX = rect.x; + minY = rect.y; + maxX = rect.x + rect.width; + maxY = rect.y + rect.height; + } else { + minX = Math.min(minX, rect.x); + minY = Math.min(minY, rect.y); + maxX = Math.max(maxX, rect.x + rect.width); + maxY = Math.max(maxY, rect.y + rect.height); + } + }); var rect = { @@ -7170,48 +7178,33 @@ var Konva = {}; var threshold = alphaThreshold || 0, cachedCanvas = this._cache.canvas, sceneCanvas = this._getCachedSceneCanvas(), - sceneContext = sceneCanvas.getContext(), hitCanvas = cachedCanvas.hit, hitContext = hitCanvas.getContext(), - width = sceneCanvas.getWidth(), - height = sceneCanvas.getHeight(), - sceneImageData, sceneData, hitImageData, hitData, len, rgbColorKey, i, alpha; + hitWidth = hitCanvas.getWidth(), + hitHeight = hitCanvas.getHeight(), + hitImageData, hitData, len, rgbColorKey, i, alpha; hitContext.clear(); - var ratio = sceneCanvas.pixelRatio; - var hitWidth = Math.floor(width / ratio); - var hitHeight = Math.floor(height / ratio); + hitContext.drawImage(sceneCanvas._canvas, 0, 0, hitWidth, hitHeight); try { - // if pixelRatio > 1 we need to redraw scene canvas into temp canvas - // with pixelRatio = 1 to have the same dimension as hitCanvas - if (ratio !== 1) { - var tempCanvas = new Konva.SceneCanvas({ - width : hitWidth, - height : hitHeight, - pixelRatio : 1 - }); - tempCanvas.getContext().drawImage(sceneCanvas._canvas, 0, 0, hitWidth, hitHeight); - sceneImageData = tempCanvas.getContext().getImageData(0, 0, hitWidth, hitHeight); - sceneData = sceneImageData.data; - } else { - sceneImageData = sceneContext.getImageData(0, 0, width, height); - sceneData = sceneImageData.data; - } hitImageData = hitContext.getImageData(0, 0, hitWidth, hitHeight); hitData = hitImageData.data; - len = sceneData.length; + len = hitData.length; rgbColorKey = Konva.Util._hexToRgb(this.colorKey); // replace non transparent pixels with color key for(i = 0; i < len; i += 4) { - alpha = sceneData[i + 3]; + alpha = hitData[i + 3]; if (alpha > threshold) { hitData[i] = rgbColorKey.r; hitData[i + 1] = rgbColorKey.g; hitData[i + 2] = rgbColorKey.b; hitData[i + 3] = 255; } + else { + hitData[i + 3] = 0; + } } hitContext.putImageData(hitImageData, 0, 0); } diff --git a/konva.min.js b/konva.min.js index 6797de05..520ef98f 100644 --- a/konva.min.js +++ b/konva.min.js @@ -41,6 +41,6 @@ return void 0!==e&&(a+=e),void 0!==n&&(i+=n),this.setPosition({x:a,y:i}),this},_ * node.cache(); * node.filters([Konva.Filters.Sepia]); */ -Konva.Filters.Sepia=function(t){var e,n,a,i,o,r,s,h,c,l=t.data,d=t.width,v=t.height,u=4*d;do{e=(v-1)*u,n=d;do a=e+4*(n-1),i=l[a],o=l[a+1],r=l[a+2],s=.393*i+.769*o+.189*r,h=.349*i+.686*o+.168*r,c=.272*i+.534*o+.131*r,l[a]=s>255?255:s,l[a+1]=h>255?255:h,l[a+2]=c>255?255:c,l[a+3]=l[a+3];while(--n)}while(--v)}}(),function(){Konva.Filters.Solarize=function(t){var e=t.data,n=t.width,a=t.height,i=4*n,o=a;do{var r=(o-1)*i,s=n;do{var h=r+4*(s-1),c=e[h],l=e[h+1],d=e[h+2];c>127&&(c=255-c),l>127&&(l=255-l),d>127&&(d=255-d),e[h]=c,e[h+1]=l,e[h+2]=d}while(--s)}while(--o)}}(),function(){var t=function(t,e,n){var a,i,o,r,s=t.data,h=e.data,c=t.width,l=t.height,d=n.polarCenterX||c/2,v=n.polarCenterY||l/2,u=0,f=0,g=0,p=0,K=Math.sqrt(d*d+v*v);i=c-d,o=l-v,r=Math.sqrt(i*i+o*o),K=r>K?r:K;var m,_,y,S,C=l,x=c,w=360/x*Math.PI/180;for(_=0;x>_;_+=1)for(y=Math.sin(_*w),S=Math.cos(_*w),m=0;C>m;m+=1)i=Math.floor(d+K*m/C*S),o=Math.floor(v+K*m/C*y),a=4*(o*c+i),u=s[a+0],f=s[a+1],g=s[a+2],p=s[a+3],a=4*(_+m*c),h[a+0]=u,h[a+1]=f,h[a+2]=g,h[a+3]=p},e=function(t,e,n){var a,i,o,r,s,h,c=t.data,l=e.data,d=t.width,v=t.height,u=n.polarCenterX||d/2,f=n.polarCenterY||v/2,g=0,p=0,K=0,m=0,_=Math.sqrt(u*u+f*f);i=d-u,o=v-f,h=Math.sqrt(i*i+o*o),_=h>_?h:_;var y,S,C,x,w=v,b=d,F=n.polarRotation||0;for(i=0;d>i;i+=1)for(o=0;v>o;o+=1)r=i-u,s=o-f,y=Math.sqrt(r*r+s*s)*w/_,S=(180*Math.atan2(s,r)/Math.PI+360+F)%360,S=S*b/360,C=Math.floor(S),x=Math.floor(y),a=4*(x*d+C),g=c[a+0],p=c[a+1],K=c[a+2],m=c[a+3],a=4*(o*d+i),l[a+0]=g,l[a+1]=p,l[a+2]=K,l[a+3]=m},n=Konva.Util.createCanvasElement();Konva.Filters.Kaleidoscope=function(a){var i,o,r,s,h,c,l,d,v,u,f=a.width,g=a.height,p=Math.round(this.kaleidoscopePower()),K=Math.round(this.kaleidoscopeAngle()),m=Math.floor(f*(K%360)/360);if(!(1>p)){n.width=f,n.height=g;var _=n.getContext("2d").getImageData(0,0,f,g);t(a,_,{polarCenterX:f/2,polarCenterY:g/2});for(var y=f/Math.pow(2,p);8>=y;)y=2*y,p-=1;y=Math.ceil(y);var S=y,C=0,x=S,w=1;for(m+y>f&&(C=S,x=0,w=-1),o=0;g>o;o+=1)for(i=C;i!==x;i+=w)r=Math.round(i+m)%f,v=4*(f*o+r),h=_.data[v+0],c=_.data[v+1],l=_.data[v+2],d=_.data[v+3],u=4*(f*o+i),_.data[u+0]=h,_.data[u+1]=c,_.data[u+2]=l,_.data[u+3]=d;for(o=0;g>o;o+=1)for(S=Math.floor(y),s=0;p>s;s+=1){for(i=0;S+1>i;i+=1)v=4*(f*o+i),h=_.data[v+0],c=_.data[v+1],l=_.data[v+2],d=_.data[v+3],u=4*(f*o+2*S-i-1),_.data[u+0]=h,_.data[u+1]=c,_.data[u+2]=l,_.data[u+3]=d;S*=2}e(_,a,{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(){Konva.Container=function(t){this.__init(t)},Konva.Util.addMethods(Konva.Container,{__init:function(t){this.children=new Konva.Collection,Konva.Node.call(this,t)},getChildren:function(t){if(t){var e=new Konva.Collection;return this.children.each(function(n){t(n)&&e.push(n)}),e}return this.children},hasChildren:function(){return this.getChildren().length>0},removeChildren:function(){for(var t,e=Konva.Collection.toCollection(this.children),n=0;n1){for(var e=0;ee;e++)if(a=c[e],"#"===a.charAt(0))o=this._getNodeById(a.slice(1)),o&&h.push(o);else if("."===a.charAt(0))i=this._getNodesByName(a.slice(1)),h=h.concat(i);else for(r=this.getChildren(),s=r.length,n=0;s>n;n++)h=h.concat(r[n]._get(a));return Konva.Collection.toCollection(h)},findOne:function(t){return this.find(t)[0]},_getNodeById:function(t){var e=Konva.ids[t];return void 0!==e&&this.isAncestorOf(e)?e:null},_getNodesByName:function(t){var e=Konva.names[t]||[];return this._getDescendants(e)},_get:function(t){for(var e=Konva.Node.prototype._get.call(this,t),n=this.getChildren(),a=n.length,i=0;a>i;i++)e=e.concat(n[i]._get(t));return e},toObject:function(){var t=Konva.Node.prototype.toObject.call(this);t.children=[];for(var e=this.getChildren(),n=e.length,a=0;n>a;a++){var i=e[a];t.children.push(i.toObject())}return t},_getDescendants:function(t){for(var e=[],n=t.length,a=0;n>a;a++){var i=t[a];this.isAncestorOf(i)&&e.push(i)}return e},isAncestorOf:function(t){for(var e=t.getParent();e;){if(e._id===this._id)return!0;e=e.getParent()}return!1},clone:function(t){var e=Konva.Node.prototype.clone.call(this,t);return this.getChildren().each(function(t){e.add(t.clone())}),e},getAllIntersections:function(t){var e=[];return this.find("Shape").each(function(n){n.isVisible()&&n.intersects(t)&&e.push(n)}),e},_setChildrenIndices:function(){this.children.each(function(t,e){t.index=e})},drawScene:function(t,e,n){var a=this.getLayer(),i=t||a&&a.getCanvas(),o=i&&i.getContext(),r=this._cache.canvas,s=r&&r.scene;return this.isVisible()&&(!n&&s?(o.save(),a._applyTransform(this,o,e),this._drawCachedSceneCanvas(o),o.restore()):this._drawChildren(i,"drawScene",e)),this},drawHit:function(t,e,n){var a=this.getLayer(),i=t||a&&a.hitCanvas,o=i&&i.getContext(),r=this._cache.canvas,s=r&&r.hit;return this.shouldDrawHit(i)&&(a&&a.clearHitCache(),!n&&s?(o.save(),a._applyTransform(this,o,e),this._drawCachedHitCanvas(o),o.restore()):this._drawChildren(i,"drawHit",e)),this},_drawChildren:function(t,e,n){var a,i,o=this.getLayer(),r=t&&t.getContext(),s=this.getClipWidth(),h=this.getClipHeight(),c=s&&h;c&&o&&(a=this.getClipX(),i=this.getClipY(),r.save(),o._applyTransform(this,r),r.beginPath(),r.rect(a,i,s,h),r.clip(),r.reset()),this.children.each(function(a){a[e](t,n)}),c&&r.restore()},shouldDrawHit:function(t){var e=this.getLayer(),n=Konva.DD,a=n&&Konva.isDragging()&&-1!==Konva.DD.anim.getLayers().indexOf(e);return t&&t.isCache||e&&e.hitGraphEnabled()&&this.isVisible()&&!a},getClientRect:function(t){var e,n,a,i;this.children.each(function(t){var o=t.getClientRect();e=Math.min(e,o.x)||o.x,n=Math.min(n,o.y)||o.y,a=Math.max(a,o.x+o.width)||o.x+o.width,i=Math.max(i,o.y+o.height)||o.y+o.height});var o={x:e,y:n,width:a-e,height:i-n};return t?o:this._transformedRect(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.Collection.mapMethods(Konva.Container)}(),function(){function t(t){t.fill()}function e(t){t.stroke()}function n(t){t.fill()}function a(t){t.stroke()}function i(){this._clearCache(r)}function o(){this._clearCache(s)}var r="hasShadow",s="shadowRGBA";Konva.Shape=function(t){this.__init(t)},Konva.Util.addMethods(Konva.Shape,{__init:function(r){this.nodeType="Shape",this._fillFunc=t,this._strokeFunc=e,this._fillFuncHit=n,this._strokeFuncHit=a;for(var s,h=Konva.shapes;;)if(s=Konva.Util.getRandomColor(),s&&!(s in h))break;this.colorKey=s,h[s]=this,Konva.Node.call(this,r),this.on("shadowColorChange.konva shadowBlurChange.konva shadowOffsetChange.konva shadowOpacityChange.konva shadowEnabledChange.konva",i),this.on("shadowColorChange.konva shadowOpacityChange.konva shadowEnabledChange.konva",o)},hasChildren:function(){return!1},getChildren:function(){return[]},getContext:function(){return this.getLayer().getContext()},getCanvas:function(){return this.getLayer().getCanvas()},hasShadow:function(){return this._getCache(r,this._hasShadow)},_hasShadow:function(){return this.getShadowEnabled()&&0!==this.getShadowOpacity()&&!!(this.getShadowColor()||this.getShadowBlur()||this.getShadowOffsetX()||this.getShadowOffsetY())},getShadowRGBA:function(){return this._getCache(s,this._getShadowRGBA)},_getShadowRGBA:function(){if(this.hasShadow()){var t=Konva.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.stroke()||this.strokeRed()||this.strokeGreen()||this.strokeBlue())},intersects:function(t){var e,n=this.getStage(),a=n.bufferHitCanvas;return a.getContext().clear(),this.drawScene(a),e=a.context.getImageData(Math.round(t.x),Math.round(t.y),1,1).data,e[3]>0},destroy:function(){Konva.Node.prototype.destroy.call(this),delete Konva.shapes[this.colorKey]},_useBufferCanvas:function(t){return!t&&this.perfectDrawEnabled()&&1!==this.getAbsoluteOpacity()&&this.hasFill()&&this.hasStroke()&&this.getStage()||this.perfectDrawEnabled()&&this.hasShadow()&&1!==this.getAbsoluteOpacity()&&this.hasFill()&&this.hasStroke()&&this.getStage()},getSelfRect:function(){var t=this.getSize();return{x:this._centroid?Math.round(-t.width/2):0,y:this._centroid?Math.round(-t.height/2):0,width:t.width,height:t.height}},getClientRect:function(t){var e=this.getSelfRect(),n=this.hasStroke()&&this.strokeWidth()||0,a=e.width+n,i=e.height+n,o=this.shadowOffsetX(),r=this.shadowOffsetY(),s=a+Math.abs(o),h=i+Math.abs(r),c=this.hasShadow()&&this.shadowBlur()||0,l=s+2*c,d=h+2*c,v=0;Math.round(n/2)!==n/2&&(v=1);var u={width:l+v,height:d+v,x:-Math.round(n/2+c)+Math.min(o,0)+e.x,y:-Math.round(n/2+c)+Math.min(r,0)+e.y};return t?u:this._transformedRect(u)},drawScene:function(t,e,n){var a,i,o,r=this.getLayer(),s=t||r.getCanvas(),h=s.getContext(),c=this._cache.canvas,l=this.sceneFunc(),d=this.hasShadow(),v=this.hasStroke();if(this.isVisible())if(c)h.save(),r._applyTransform(this,h,e),this._drawCachedSceneCanvas(h),h.restore();else if(l){if(h.save(),this._useBufferCanvas(n)){if(a=this.getStage(),i=a.bufferCanvas,o=i.getContext(),o.clear(),o.save(),o._applyLineJoin(this),!n)if(r)r._applyTransform(this,o,e);else{var u=this.getAbsoluteTransform(e).getMatrix();h.transform(u[0],u[1],u[2],u[3],u[4],u[5])}l.call(this,o),o.restore(),d&&!s.hitCanvas?(h.save(),h._applyShadow(this),h._applyOpacity(this),h.drawImage(i._canvas,0,0),h.restore()):(h._applyOpacity(this),h.drawImage(i._canvas,0,0))}else{if(h._applyLineJoin(this),!n)if(r)r._applyTransform(this,h,e);else{var f=this.getAbsoluteTransform(e).getMatrix();h.transform(f[0],f[1],f[2],f[3],f[4],f[5])}d&&v&&!s.hitCanvas?(h.save(),n||h._applyOpacity(this),h._applyShadow(this),l.call(this,h),h.restore(),this.hasFill()&&this.getShadowForStrokeEnabled()&&l.call(this,h)):d&&!s.hitCanvas?(h.save(),n||h._applyOpacity(this),h._applyShadow(this),l.call(this,h),h.restore()):(n||h._applyOpacity(this),l.call(this,h))}h.restore()}return this},drawHit:function(t,e,n){var a=this.getLayer(),i=t||a.hitCanvas,o=i.getContext(),r=this.hitFunc()||this.sceneFunc(),s=this._cache.canvas,h=s&&s.hit;if(this.shouldDrawHit(i))if(a&&a.clearHitCache(),h)o.save(),a._applyTransform(this,o,e),this._drawCachedHitCanvas(o),o.restore();else if(r){if(o.save(),o._applyLineJoin(this),!n)if(a)a._applyTransform(this,o,e);else{var c=this.getAbsoluteTransform(e).getMatrix();o.transform(c[0],c[1],c[2],c[3],c[4],c[5])}r.call(this,o),o.restore()}return this},drawHitFromCache:function(t){var e,n,a,i,o,r,s,h,c=t||0,l=this._cache.canvas,d=this._getCachedSceneCanvas(),v=d.getContext(),u=l.hit,f=u.getContext(),g=d.getWidth(),p=d.getHeight();f.clear();var K=d.pixelRatio,m=Math.floor(g/K),_=Math.floor(p/K);try{if(1!==K){var y=new Konva.SceneCanvas({width:m,height:_,pixelRatio:1});y.getContext().drawImage(d._canvas,0,0,m,_),e=y.getContext().getImageData(0,0,m,_),n=e.data}else e=v.getImageData(0,0,g,p),n=e.data;for(a=f.getImageData(0,0,m,_),i=a.data,o=n.length,r=Konva.Util._hexToRgb(this.colorKey),s=0;o>s;s+=4)h=n[s+3],h>c&&(i[s]=r.r,i[s+1]=r.g,i[s+2]=r.b,i[s+3]=255);f.putImageData(a,0,0)}catch(S){Konva.Util.error("Unable to draw hit graph from cached scene canvas. "+S.message)}return this}}),Konva.Util.extend(Konva.Shape,Konva.Node),Konva.Factory.addGetterSetter(Konva.Shape,"stroke"),Konva.Factory.addGetterSetter(Konva.Shape,"strokeRed",0,Konva.Validators.RGBComponent),Konva.Factory.addGetterSetter(Konva.Shape,"strokeGreen",0,Konva.Validators.RGBComponent),Konva.Factory.addGetterSetter(Konva.Shape,"strokeBlue",0,Konva.Validators.RGBComponent),Konva.Factory.addGetterSetter(Konva.Shape,"strokeAlpha",1,Konva.Validators.alphaComponent),Konva.Factory.addGetterSetter(Konva.Shape,"strokeWidth",2),Konva.Factory.addGetterSetter(Konva.Shape,"strokeHitEnabled",!0),Konva.Factory.addGetterSetter(Konva.Shape,"perfectDrawEnabled",!0),Konva.Factory.addGetterSetter(Konva.Shape,"shadowForStrokeEnabled",!0),Konva.Factory.addGetterSetter(Konva.Shape,"lineJoin"),Konva.Factory.addGetterSetter(Konva.Shape,"lineCap"),Konva.Factory.addGetterSetter(Konva.Shape,"sceneFunc"),Konva.Factory.addGetterSetter(Konva.Shape,"hitFunc"),Konva.Factory.addGetterSetter(Konva.Shape,"dash"),Konva.Factory.addGetterSetter(Konva.Shape,"shadowColor"),Konva.Factory.addGetterSetter(Konva.Shape,"shadowRed",0,Konva.Validators.RGBComponent),Konva.Factory.addGetterSetter(Konva.Shape,"shadowGreen",0,Konva.Validators.RGBComponent),Konva.Factory.addGetterSetter(Konva.Shape,"shadowBlue",0,Konva.Validators.RGBComponent),Konva.Factory.addGetterSetter(Konva.Shape,"shadowAlpha",1,Konva.Validators.alphaComponent),Konva.Factory.addGetterSetter(Konva.Shape,"shadowBlur"),Konva.Factory.addGetterSetter(Konva.Shape,"shadowOpacity"),Konva.Factory.addComponentsGetterSetter(Konva.Shape,"shadowOffset",["x","y"]),Konva.Factory.addGetterSetter(Konva.Shape,"shadowOffsetX",0),Konva.Factory.addGetterSetter(Konva.Shape,"shadowOffsetY",0),Konva.Factory.addGetterSetter(Konva.Shape,"fillPatternImage"),Konva.Factory.addGetterSetter(Konva.Shape,"fill"),Konva.Factory.addGetterSetter(Konva.Shape,"fillRed",0,Konva.Validators.RGBComponent),Konva.Factory.addGetterSetter(Konva.Shape,"fillGreen",0,Konva.Validators.RGBComponent),Konva.Factory.addGetterSetter(Konva.Shape,"fillBlue",0,Konva.Validators.RGBComponent),Konva.Factory.addGetterSetter(Konva.Shape,"fillAlpha",1,Konva.Validators.alphaComponent),Konva.Factory.addGetterSetter(Konva.Shape,"fillPatternX",0),Konva.Factory.addGetterSetter(Konva.Shape,"fillPatternY",0),Konva.Factory.addGetterSetter(Konva.Shape,"fillLinearGradientColorStops"),Konva.Factory.addGetterSetter(Konva.Shape,"fillRadialGradientStartRadius",0),Konva.Factory.addGetterSetter(Konva.Shape,"fillRadialGradientEndRadius",0),Konva.Factory.addGetterSetter(Konva.Shape,"fillRadialGradientColorStops"),Konva.Factory.addGetterSetter(Konva.Shape,"fillPatternRepeat","repeat"),Konva.Factory.addGetterSetter(Konva.Shape,"fillEnabled",!0),Konva.Factory.addGetterSetter(Konva.Shape,"strokeEnabled",!0),Konva.Factory.addGetterSetter(Konva.Shape,"shadowEnabled",!0),Konva.Factory.addGetterSetter(Konva.Shape,"dashEnabled",!0),Konva.Factory.addGetterSetter(Konva.Shape,"strokeScaleEnabled",!0),Konva.Factory.addGetterSetter(Konva.Shape,"fillPriority","color"),Konva.Factory.addComponentsGetterSetter(Konva.Shape,"fillPatternOffset",["x","y"]),Konva.Factory.addGetterSetter(Konva.Shape,"fillPatternOffsetX",0),Konva.Factory.addGetterSetter(Konva.Shape,"fillPatternOffsetY",0),Konva.Factory.addComponentsGetterSetter(Konva.Shape,"fillPatternScale",["x","y"]),Konva.Factory.addGetterSetter(Konva.Shape,"fillPatternScaleX",1),Konva.Factory.addGetterSetter(Konva.Shape,"fillPatternScaleY",1),Konva.Factory.addComponentsGetterSetter(Konva.Shape,"fillLinearGradientStartPoint",["x","y"]),Konva.Factory.addGetterSetter(Konva.Shape,"fillLinearGradientStartPointX",0),Konva.Factory.addGetterSetter(Konva.Shape,"fillLinearGradientStartPointY",0),Konva.Factory.addComponentsGetterSetter(Konva.Shape,"fillLinearGradientEndPoint",["x","y"]),Konva.Factory.addGetterSetter(Konva.Shape,"fillLinearGradientEndPointX",0),Konva.Factory.addGetterSetter(Konva.Shape,"fillLinearGradientEndPointY",0),Konva.Factory.addComponentsGetterSetter(Konva.Shape,"fillRadialGradientStartPoint",["x","y"]),Konva.Factory.addGetterSetter(Konva.Shape,"fillRadialGradientStartPointX",0),Konva.Factory.addGetterSetter(Konva.Shape,"fillRadialGradientStartPointY",0),Konva.Factory.addComponentsGetterSetter(Konva.Shape,"fillRadialGradientEndPoint",["x","y"]),Konva.Factory.addGetterSetter(Konva.Shape,"fillRadialGradientEndPointX",0),Konva.Factory.addGetterSetter(Konva.Shape,"fillRadialGradientEndPointY",0),Konva.Factory.addGetterSetter(Konva.Shape,"fillPatternRotation",0),Konva.Factory.backCompat(Konva.Shape,{dashArray:"dash",getDashArray:"getDash",setDashArray:"getDash",drawFunc:"sceneFunc",getDrawFunc:"getSceneFunc",setDrawFunc:"setSceneFunc",drawHitFunc:"hitFunc",getDrawHitFunc:"getHitFunc",setDrawHitFunc:"setHitFunc"}),Konva.Collection.mapMethods(Konva.Shape)}(),function(){function t(t,e){t.content.addEventListener(e,function(n){t[I+e](n)},!1)}var e="Stage",n="string",a="px",i="mouseout",o="mouseleave",r="mouseover",s="mouseenter",h="mousemove",c="mousedown",l="mouseup",d="click",v="dblclick",u="touchstart",f="touchend",g="tap",p="dbltap",K="touchmove",m="DOMMouseScroll",_="mousewheel",y="wheel",S="contentMouseout",C="contentMouseover",x="contentMousemove",w="contentMousedown",b="contentMouseup",F="contentClick",T="contentDblclick",P="contentTouchstart",A="contentTouchend",k="contentDbltap",M="contentTouchmove",G="div",D="relative",R="konvajs-content",L=" ",I="_",N="container",O="",B=[c,h,l,i,u,K,f,r,m,_,y],U=B.length;Konva.Stage=function(t){this.___init(t)},Konva.Util.addMethods(Konva.Stage,{___init:function(t){this.nodeType=e,Konva.Container.call(this,t),this._id=Konva.idCounter++,this._buildDOM(),this._bindContentEvents(),this._enableNestedTransforms=!1,Konva.stages.push(this)},_validateAdd:function(t){"Layer"!==t.getType()&&Konva.Util.error("You may only add layers to the stage.")},setContainer:function(t){if(typeof t===n){var e=t;if(t=Konva.document.getElementById(t),!t)throw"Can not find container in document with id "+e}return this._setAttr(N,t),this},shouldDrawHit:function(){return!0},draw:function(){return Konva.Node.prototype.draw.call(this),this},setHeight:function(t){return Konva.Node.prototype.setHeight.call(this,t),this._resizeDOM(),this},setWidth:function(t){return Konva.Node.prototype.setWidth.call(this,t),this._resizeDOM(),this},clear:function(){var t,e=this.children,n=e.length;for(t=0;n>t;t++)e[t].clear();return this},clone:function(t){return t||(t={}),t.container=Konva.document.createElement(G),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);e>-1&&Konva.stages.splice(e,1)},getPointerPosition:function(){return this.pointerPos},getStage:function(){return this},getContent:function(){return this.content},toDataURL:function(t){function e(i){var o=h[i],c=o.toDataURL(),l=new Konva.window.Image;l.onload=function(){s.drawImage(l,0,0),i=0;e--)if(n=a[e].getIntersection(t))return n;return null},_resizeDOM:function(){if(this.content){var t,e,n=this.getWidth(),i=this.getHeight(),o=this.getChildren(),r=o.length;for(this.content.style.width=n+a,this.content.style.height=i+a,this.bufferCanvas.setSize(n,i),this.bufferHitCanvas.setSize(n,i),t=0;r>t;t++)e=o[t],e.setSize(n,i),e.draw()}},add:function(t){if(!(arguments.length>1))return Konva.Container.prototype.add.call(this,t),t._setCanvasSize(this.width(),this.height()),t.draw(),this.content.appendChild(t.canvas._canvas),this;for(var e=0;ee;e++)t(this,B[e])},_mouseover:function(t){Konva.UA.mobile||(this._setPointerPosition(t),this._fire(C,{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(o,{evt:t}),this.targetShape=null),this.pointerPos=void 0,this._fire(S,{evt:t})}},_mousemove:function(t){if(Konva.UA.ieMobile)return this._touchmove(t);if(("undefined"==typeof t.webkitMovementX&&"undefined"==typeof t.webkitMovementY||0!==t.webkitMovementY||0!==t.webkitMovementX)&&!Konva.UA.mobile){this._setPointerPosition(t);var e,n=Konva.DD;Konva.isDragging()||(e=this.getIntersection(this.getPointerPosition()),e&&e.isListening()?Konva.isDragging()||this.targetShape&&this.targetShape._id===e._id?e._fireAndBubble(h,{evt:t}):(this.targetShape&&(this.targetShape._fireAndBubble(i,{evt:t},e),this.targetShape._fireAndBubble(o,{evt:t},e)),e._fireAndBubble(r,{evt:t},this.targetShape),e._fireAndBubble(s,{evt:t},this.targetShape),this.targetShape=e):this.targetShape&&!Konva.isDragging()&&(this.targetShape._fireAndBubble(i,{evt:t}),this.targetShape._fireAndBubble(o,{evt:t}),this.targetShape=null),this._fire(x,{evt:t})),n&&n._drag(t),t.preventDefault&&t.preventDefault()}},_mousedown:function(t){if(Konva.UA.ieMobile)return this._touchstart(t);if(!Konva.UA.mobile){this._setPointerPosition(t);var e=this.getIntersection(this.getPointerPosition());Konva.listenClickTap=!0,e&&e.isListening()&&(this.clickStartShape=e,e._fireAndBubble(c,{evt:t})),this._fire(w,{evt:t})}t.preventDefault&&t.preventDefault()},_mouseup:function(t){if(Konva.UA.ieMobile)return this._touchend(t);if(!Konva.UA.mobile){this._setPointerPosition(t);var e=this.getIntersection(this.getPointerPosition()),n=this.clickStartShape,a=!1,i=Konva.DD;Konva.inDblClickWindow?(a=!0,Konva.inDblClickWindow=!1):i&&i.justDragged?i&&(i.justDragged=!1):Konva.inDblClickWindow=!0,setTimeout(function(){Konva.inDblClickWindow=!1},Konva.dblClickWindow),e&&e.isListening()&&(e._fireAndBubble(l,{evt:t}),Konva.listenClickTap&&n&&n._id===e._id&&(e._fireAndBubble(d,{evt:t}),a&&e._fireAndBubble(v,{evt:t}))),this._fire(b,{evt:t}),Konva.listenClickTap&&(this._fire(F,{evt:t}),a&&this._fire(T,{evt:t})),Konva.listenClickTap=!1}t.preventDefault&&t.preventDefault()},_touchstart:function(t){this._setPointerPosition(t);var e=this.getIntersection(this.getPointerPosition());Konva.listenClickTap=!0,e&&e.isListening()&&(this.tapStartShape=e,e._fireAndBubble(u,{evt:t}),e.isListening()&&t.preventDefault&&t.preventDefault()),this._fire(P,{evt:t})},_touchend:function(t){this._setPointerPosition(t);var e=this.getIntersection(this.getPointerPosition()),n=!1;Konva.inDblClickWindow?(n=!0,Konva.inDblClickWindow=!1):Konva.inDblClickWindow=!0,setTimeout(function(){Konva.inDblClickWindow=!1},Konva.dblClickWindow),e&&e.isListening()&&(e._fireAndBubble(f,{evt:t}),Konva.listenClickTap&&e._id===this.tapStartShape._id&&(e._fireAndBubble(g,{evt:t}),n&&e._fireAndBubble(p,{evt:t})),e.isListening()&&t.preventDefault&&t.preventDefault()),Konva.listenClickTap&&(this._fire(A,{evt:t}),n&&this._fire(k,{evt:t})),Konva.listenClickTap=!1},_touchmove:function(t){this._setPointerPosition(t);var e,n=Konva.DD;Konva.isDragging()||(e=this.getIntersection(this.getPointerPosition()),e&&e.isListening()&&(e._fireAndBubble(K,{evt:t}),e.isListening()&&t.preventDefault&&t.preventDefault()),this._fire(M,{evt:t})),n&&(n._drag(t),Konva.isDragging()&&t.preventDefault())},_DOMMouseScroll:function(t){this._mousewheel(t)},_mousewheel:function(t){this._setPointerPosition(t);var e=this.getIntersection(this.getPointerPosition());e&&e.isListening()&&e._fireAndBubble(_,{evt:t})},_wheel:function(t){this._mousewheel(t)},_setPointerPosition:function(t){var e,n=this._getContentPosition(),a=t.offsetX,i=t.clientX,o=null,r=null;t=t?t:window.event,void 0!==t.touches?t.touches.length>0&&(e=t.touches[0],o=e.clientX-n.left,r=e.clientY-n.top):void 0!==a?(o=a,r=t.offsetY):"mozilla"===Konva.UA.browser?(o=t.layerX||t.clientX-n.left,r=t.layerY||t.clientY-n.top):void 0!==i&&n&&(o=i-n.left,r=t.clientY-n.top),null!==o&&null!==r&&(this.pointerPos={x:o,y:r})},_getContentPosition:function(){var t=this.content.getBoundingClientRect?this.content.getBoundingClientRect():{top:0,left:0};return{top:t.top,left:t.left}},_buildDOM:function(){var t=this.getContainer();if(!t){if(Konva.Util.isBrowser())throw"Stage has no container. A container is required.";t=Konva.document.createElement(G)}t.innerHTML=O,this.content=Konva.document.createElement(G),this.content.style.position=D,this.content.className=R,this.content.setAttribute("role","presentation"),t.appendChild(this.content),this.bufferCanvas=new Konva.SceneCanvas({pixelRatio:1}),this.bufferHitCanvas=new Konva.HitCanvas,this._resizeDOM()},_onContent:function(t,e){var n,a,i=t.split(L),o=i.length;for(n=0;o>n;n++)a=i[n],this.content.addEventListener(a,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(){Konva.BaseLayer=function(t){this.___init(t)},Konva.Util.addMethods(Konva.BaseLayer,{___init:function(t){this.nodeType="Layer",Konva.Container.call(this,t)},createPNGStream:function(){return this.canvas._canvas.createPNGStream()},getCanvas:function(){return this.canvas},getHitCanvas:function(){return this.hitCanvas},getContext:function(){return this.getCanvas().getContext()},clear:function(t){return this.getContext().clear(t),this},clearHitCache:function(){this._hitImageData=void 0},setZIndex:function(t){Konva.Node.prototype.setZIndex.call(this,t);var e=this.getStage();return e&&(e.content.removeChild(this.getCanvas()._canvas),tn;n++){if(o=a[n],e=this._getIntersection({x:t.x+o.x*s,y:t.y+o.y*s}),r=e.shape)return r;if(h=!!e.antialiased,!e.antialiased)break}if(!h)return;s+=1}},_getImageData:function(t,e){var n=this.hitCanvas.width||1,a=this.hitCanvas.height||1,i=Math.round(e)*n+Math.round(t);return this._hitImageData||(this._hitImageData=this.hitCanvas.context.getImageData(0,0,n,a)),[this._hitImageData.data[4*i+0],this._hitImageData.data[4*i+1],this._hitImageData.data[4*i+2],this._hitImageData.data[4*i+3]]},_getIntersection:function(e){var n,a,i=this.hitCanvas.pixelRatio,o=this.hitCanvas.context.getImageData(Math.round(e.x*i),Math.round(e.y*i),1,1).data,r=o[3];return 255===r?(n=Konva.Util._rgbToHex(o[0],o[1],o[2]),a=Konva.shapes[t+n],a?{shape:a}:{antialiased:!0}):r>0?{antialiased:!0}:{}},drawScene:function(t,a){var i=this.getLayer(),o=t||i&&i.getCanvas();return this._fire(e,{node:this}),this.getClearBeforeDraw()&&o.getContext().clear(),Konva.Container.prototype.drawScene.call(this,o,a),this._fire(n,{node:this}),this},_applyTransform:function(t,e,n){var a=t.getAbsoluteTransform(n).getMatrix();e.transform(a[0],a[1],a[2],a[3],a[4],a[5])},drawHit:function(t,e){var n=this.getLayer(),a=t||n&&n.hitCanvas;return n&&n.getClearBeforeDraw()&&n.getHitCanvas().getContext().clear(),Konva.Container.prototype.drawHit.call(this,a,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){Konva.BaseLayer.prototype.setSize.call(this,t,e),this.hitCanvas.setSize(t,e)}}),Konva.Util.extend(Konva.Layer,Konva.BaseLayer),Konva.Factory.addGetterSetter(Konva.Layer,"hitGraphEnabled",!0),Konva.Collection.mapMethods(Konva.Layer)}(),function(){Konva.FastLayer=function(t){this.____init(t)},Konva.Util.addMethods(Konva.FastLayer,{____init:function(t){this.nodeType="Layer",this.canvas=new Konva.SceneCanvas,Konva.BaseLayer.call(this,t)},_validateAdd:function(t){var e=t.getType();"Shape"!==e&&Konva.Util.error("You may only add shapes to a fast layer.")},_setCanvasSize:function(t,e){this.canvas.setSize(t,e)},hitGraphEnabled:function(){return!1},getIntersection:function(){return null},drawScene:function(t){var e=this.getLayer(),n=t||e&&e.getCanvas(); -return this.getClearBeforeDraw()&&n.getContext().clear(),Konva.Container.prototype.drawScene.call(this,n),this},_applyTransform:function(t,e,n){if(!n||n._id!==this._id){var a=t.getTransform().getMatrix();e.transform(a[0],a[1],a[2],a[3],a[4],a[5])}},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(){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.error("You may only add groups and shapes to groups.")}}),Konva.Util.extend(Konva.Group,Konva.Container),Konva.Collection.mapMethods(Konva.Group)}(),function(){function t(t){setTimeout(t,1e3/60)}function e(){return i.apply(Konva.root,arguments)}var n=500,a=function(){return Konva.root.performance&&Konva.root.performance.now?function(){return Konva.root.performance.now()}:function(){return(new Date).getTime()}}(),i=function(){return Konva.root.requestAnimationFrame||Konva.root.webkitRequestAnimationFrame||Konva.root.mozRequestAnimationFrame||Konva.root.oRequestAnimationFrame||Konva.root.msRequestAnimationFrame||t}();Konva.Animation=function(t,e){var n=Konva.Animation;this.func=t,this.setLayers(e),this.id=n.animIdCounter++,this.frame={time:0,timeDiff:0,lastTime:a()}},Konva.Animation.prototype={setLayers:function(t){var e=[];e=t?t.length>0?t:[t]:[],this.layers=e},getLayers:function(){return this.layers},addLayer:function(t){var e,n,a=this.layers;if(a){for(e=a.length,n=0;e>n;n++)if(a[n]._id===t._id)return!1}else this.layers=[];return this.layers.push(t),!0},isRunning:function(){var t,e=Konva.Animation,n=e.animations,a=n.length;for(t=0;a>t;t++)if(n[t].id===this.id)return!0;return!1},start:function(){var t=Konva.Animation;this.stop(),this.frame.timeDiff=0,this.frame.lastTime=a(),t._addAnimation(this)},stop:function(){Konva.Animation._removeAnimation(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}},Konva.Animation.animations=[],Konva.Animation.animIdCounter=0,Konva.Animation.animRunning=!1,Konva.Animation._addAnimation=function(t){this.animations.push(t),this._handleAnimation()},Konva.Animation._removeAnimation=function(t){var e,n=t.id,a=this.animations,i=a.length;for(e=0;i>e;e++)if(a[e].id===n){this.animations.splice(e,1);break}},Konva.Animation._runFrames=function(){var t,e,n,i,o,r,s,h,c,l={},d=this.animations;for(i=0;io;o++)s=e[o],void 0!==s._id&&(l[s._id]=s);for(h in l)l[h].draw()},Konva.Animation._animationLoop=function(){var t=Konva.Animation;t.animations.length?(e(t._animationLoop),t._runFrames()):t.animRunning=!1},Konva.Animation._handleAnimation=function(){var t=this;this.animRunning||(this.animRunning=!0,t._animationLoop())};var o=Konva.Node.prototype.moveTo;Konva.Node.prototype.moveTo=function(t){o.call(this,t)},Konva.BaseLayer.prototype.batchDraw=function(){var t=this,e=Konva.Animation;this.batchAnim||(this.batchAnim=new e(function(){t.lastBatchDrawTime&&a()-t.lastBatchDrawTime>n&&t.batchAnim.stop()},this)),this.lastBatchDrawTime=a(),this.batchAnim.isRunning()||(this.draw(),this.batchAnim.start())},Konva.Stage.prototype.batchDraw=function(){this.getChildren().each(function(t){t.batchDraw()})}}(this),function(){var t={node:1,duration:1,easing:1,onFinish:1,yoyo:1},e=1,n=2,a=3,i=0,o=["fill","stroke","shadowColor"];Konva.Tween=function(e){var n,a,o=this,s=e.node,h=s._id,c=e.easing||Konva.Easings.Linear,l=!!e.yoyo;n="undefined"==typeof e.duration?1:0===e.duration?.001:e.duration,this.node=s,this._id=i++,this.anim=new Konva.Animation(function(){o.tween.onEnterFrame()},s.getLayer()||(s instanceof Konva.Stage?s.getLayers():null)),this.tween=new r(a,function(t){o._tweenFunc(t)},c,0,1,1e3*n,l),this._addListeners(),Konva.Tween.attrs[h]||(Konva.Tween.attrs[h]={}),Konva.Tween.attrs[h][this._id]||(Konva.Tween.attrs[h][this._id]={}),Konva.Tween.tweens[h]||(Konva.Tween.tweens[h]={});for(a in e)void 0===t[a]&&this._addAttr(a,e[a]);this.reset(),this.onFinish=e.onFinish,this.onReset=e.onReset},Konva.Tween.attrs={},Konva.Tween.tweens={},Konva.Tween.prototype={_addAttr:function(t,e){var n,a,i,r,s,h=this.node,c=h._id;if(i=Konva.Tween.tweens[c][t],i&&delete Konva.Tween.attrs[c][i][t],n=h.getAttr(t),Konva.Util._isArray(e))for(a=[],s=e.length,r=0;s>r;r++)a.push(e[r]-n[r]);else if(-1!==o.indexOf(t)){n=Konva.Util.colorToRGBA(n);var l=Konva.Util.colorToRGBA(e);a={r:l.r-n.r,g:l.g-n.g,b:l.b-n.b,a:l.a-n.a}}else a=e-n;Konva.Tween.attrs[c][this._id][t]={start:n,diff:a},Konva.Tween.tweens[c][t]=this._id},_tweenFunc:function(t){var e,n,a,i,r,s,h,c=this.node,l=Konva.Tween.attrs[c._id][this._id];for(e in l){if(n=l[e],a=n.start,i=n.diff,Konva.Util._isArray(a))for(r=[],h=a.length,s=0;h>s;s++)r.push(a[s]+i[s]*t);else r=-1!==o.indexOf(e)?"rgba("+Math.round(a.r+i.r*t)+","+Math.round(a.g+i.g*t)+","+Math.round(a.b+i.b*t)+","+Math.round(a.a+i.a*t)+")":a+i*t;c.setAttr(e,r)}},_addListeners:function(){var t=this;this.tween.onPlay=function(){t.anim.start()},this.tween.onReverse=function(){t.anim.start()},this.tween.onPause=function(){t.anim.stop()},this.tween.onFinish=function(){t.onFinish&&t.onFinish()},this.tween.onReset=function(){t.onReset&&t.onReset()}},play:function(){return this.tween.play(),this},reverse:function(){return this.tween.reverse(),this},reset:function(){return this.tween.reset(),this},seek:function(t){return this.tween.seek(1e3*t),this},pause:function(){return this.tween.pause(),this},finish:function(){return this.tween.finish(),this},destroy:function(){var t,e=this.node._id,n=this._id,a=Konva.Tween.tweens[e];this.pause();for(t in a)delete Konva.Tween.tweens[e][t];delete Konva.Tween.attrs[e][n]}},Konva.Node.prototype.to=function(t){var e=t.onFinish;t.node=this,t.onFinish=function(){n.destroy(),e&&e()};var n=new Konva.Tween(t);n.play()};var r=function(t,e,n,a,i,o,r){this.prop=t,this.propFunc=e,this.begin=a,this._pos=a,this.duration=o,this._change=0,this.prevPos=0,this.yoyo=r,this._time=0,this._position=0,this._startTime=0,this._finish=0,this.func=n,this._change=i-this.begin,this.pause()};r.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():0>t?this.yoyo?(this._time=0,this.play()):this.reset():(this._time=t,this.update())},getTime:function(){return this._time},setPosition:function(t){this.prevPos=this._pos,this.propFunc(t),this._pos=t},getPosition:function(t){return void 0===t&&(t=this._time),this.func(t,this.begin,this._change,this.duration)},play:function(){this.state=n,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire("onPlay")},reverse:function(){this.state=a,this._time=this.duration-this._time,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire("onReverse")},seek:function(t){this.pause(),this._time=t,this.update(),this.fire("onSeek")},reset:function(){this.pause(),this._time=0,this.update(),this.fire("onReset")},finish:function(){this.pause(),this._time=this.duration,this.update(),this.fire("onFinish")},update:function(){this.setPosition(this.getPosition(this._time))},onEnterFrame:function(){var t=this.getTimer()-this._startTime;this.state===n?this.setTime(t):this.state===a&&this.setTime(this.duration-t)},pause:function(){this.state=e,this.fire("onPause")},getTimer:function(){return(new Date).getTime()}},Konva.Easings={BackEaseIn:function(t,e,n,a){var i=1.70158;return n*(t/=a)*t*((i+1)*t-i)+e},BackEaseOut:function(t,e,n,a){var i=1.70158;return n*((t=t/a-1)*t*((i+1)*t+i)+1)+e},BackEaseInOut:function(t,e,n,a){var i=1.70158;return(t/=a/2)<1?n/2*t*t*(((i*=1.525)+1)*t-i)+e:n/2*((t-=2)*t*(((i*=1.525)+1)*t+i)+2)+e},ElasticEaseIn:function(t,e,n,a,i,o){var r=0;return 0===t?e:1==(t/=a)?e+n:(o||(o=.3*a),!i||it?-.5*i*Math.pow(2,10*(t-=1))*Math.sin(2*(t*a-r)*Math.PI/o)+e:i*Math.pow(2,-10*(t-=1))*Math.sin(2*(t*a-r)*Math.PI/o)*.5+n+e)},BounceEaseOut:function(t,e,n,a){return(t/=a)<1/2.75?7.5625*n*t*t+e:2/2.75>t?n*(7.5625*(t-=1.5/2.75)*t+.75)+e:2.5/2.75>t?n*(7.5625*(t-=2.25/2.75)*t+.9375)+e:n*(7.5625*(t-=2.625/2.75)*t+.984375)+e},BounceEaseIn:function(t,e,n,a){return n-Konva.Easings.BounceEaseOut(a-t,0,n,a)+e},BounceEaseInOut:function(t,e,n,a){return a/2>t?.5*Konva.Easings.BounceEaseIn(2*t,0,n,a)+e:.5*Konva.Easings.BounceEaseOut(2*t-a,0,n,a)+.5*n+e},EaseIn:function(t,e,n,a){return n*(t/=a)*t+e},EaseOut:function(t,e,n,a){return-n*(t/=a)*(t-2)+e},EaseInOut:function(t,e,n,a){return(t/=a/2)<1?n/2*t*t+e:-n/2*(--t*(t-2)-1)+e},StrongEaseIn:function(t,e,n,a){return n*(t/=a)*t*t*t*t+e},StrongEaseOut:function(t,e,n,a){return n*((t=t/a-1)*t*t*t*t+1)+e},StrongEaseInOut:function(t,e,n,a){return(t/=a/2)<1?n/2*t*t*t*t*t+e:n/2*((t-=2)*t*t*t*t+2)+e},Linear:function(t,e,n,a){return n*t/a+e}}}(),function(){Konva.DD={anim:new Konva.Animation(function(){var t=this.dirty;return this.dirty=!1,t}),isDragging:!1,justDragged:!1,offset:{x:0,y:0},node:null,_drag:function(t){var e=Konva.DD,n=e.node;if(n){if(!e.isDragging){var a=n.getStage().getPointerPosition(),i=n.dragDistance(),o=Math.max(Math.abs(a.x-e.startPointerPos.x),Math.abs(a.y-e.startPointerPos.y));if(i>o)return}n._setDragPosition(t),e.isDragging||(e.isDragging=!0,n.fire("dragstart",{type:"dragstart",target:n,evt:t},!0)),n.fire("dragmove",{type:"dragmove",target:n,evt:t},!0)}},_endDragBefore:function(t){var e,n,a=Konva.DD,i=a.node;i&&(e=i.nodeType,n=i.getLayer(),a.anim.stop(),a.isDragging&&(a.isDragging=!1,a.justDragged=!0,Konva.listenClickTap=!1,t&&(t.dragEndNode=i)),delete a.node,(n||i).draw())},_endDragAfter:function(t){t=t||{};var e=t.dragEndNode;t&&e&&e.fire("dragend",{type:"dragend",target:e,evt:t},!0)}},Konva.Node.prototype.startDrag=function(){var t=Konva.DD,e=this.getStage(),n=this.getLayer(),a=e.getPointerPosition(),i=this.getAbsolutePosition();a&&(t.node&&t.node.stopDrag(),t.node=this,t.startPointerPos=a,t.offset.x=a.x-i.x,t.offset.y=a.y-i.y,t.anim.setLayers(n||this.getLayers()),t.anim.start(),this._setDragPosition())},Konva.Node.prototype._setDragPosition=function(t){var e=Konva.DD,n=this.getStage().getPointerPosition(),a=this.getDragBoundFunc();if(n){var i={x:n.x-e.offset.x,y:n.y-e.offset.y};void 0!==a&&(i=a.call(this,i,t)),this.setAbsolutePosition(i),this._lastPos&&this._lastPos.x===i.x&&this._lastPos.y===i.y||(e.anim.dirty=!0),this._lastPos=i}},Konva.Node.prototype.stopDrag=function(){var t=Konva.DD,e={};t._endDragBefore(e),t._endDragAfter(e)},Konva.Node.prototype.setDraggable=function(t){this._setAttr("draggable",t),this._dragChange()};var t=Konva.Node.prototype.destroy;Konva.Node.prototype.destroy=function(){var e=Konva.DD;e.node&&e.node._id===this._id&&this.stopDrag(),t.call(this)},Konva.Node.prototype.isDragging=function(){var t=Konva.DD;return!(!t.node||t.node._id!==this._id||!t.isDragging)},Konva.Node.prototype._listenDrag=function(){var t=this;this._dragCleanup(),"Stage"===this.getClassName()?this.on("contentMousedown.konva contentTouchstart.konva",function(e){Konva.DD.node||t.startDrag(e)}):this.on("mousedown.konva touchstart.konva",function(e){1!==e.evt.button&&2!==e.evt.button&&(Konva.DD.node||t.startDrag(e))})},Konva.Node.prototype._dragChange=function(){if(this.attrs.draggable)this._listenDrag();else{this._dragCleanup();var t=this.getStage(),e=Konva.DD;t&&e.node&&e.node._id===this._id&&e.node.stopDrag()}},Konva.Node.prototype._dragCleanup=function(){"Stage"===this.getClassName()?(this.off("contentMousedown.konva"),this.off("contentTouchstart.konva")):(this.off("mousedown.konva"),this.off("touchstart.konva"))},Konva.Factory.addGetterSetter(Konva.Node,"dragBoundFunc"),Konva.Factory.addGetter(Konva.Node,"draggable",!1),Konva.Factory.addOverloadedGetterSetter(Konva.Node,"draggable");var e=Konva.document.documentElement;e.addEventListener("mouseup",Konva.DD._endDragBefore,!0),e.addEventListener("touchend",Konva.DD._endDragBefore,!0),e.addEventListener("mouseup",Konva.DD._endDragAfter,!1),e.addEventListener("touchend",Konva.DD._endDragAfter,!1)}(),function(){Konva.Rect=function(t){this.___init(t)},Konva.Rect.prototype={___init:function(t){Konva.Shape.call(this,t),this.className="Rect",this.sceneFunc(this._sceneFunc)},_sceneFunc:function(t){var e=this.getCornerRadius(),n=this.getWidth(),a=this.getHeight();t.beginPath(),e?(e=Math.min(e,n/2,a/2),t.moveTo(e,0),t.lineTo(n-e,0),t.arc(n-e,e,e,3*Math.PI/2,0,!1),t.lineTo(n,a-e),t.arc(n-e,a-e,e,0,Math.PI/2,!1),t.lineTo(e,a),t.arc(e,a-e,e,Math.PI/2,Math.PI,!1),t.lineTo(0,e),t.arc(e,e,e,Math.PI,3*Math.PI/2,!1)):t.rect(0,0,n,a),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(){var t=2*Math.PI-1e-4,e="Circle";Konva.Circle=function(t){this.___init(t)},Konva.Circle.prototype={_centroid:!0,___init:function(t){Konva.Shape.call(this,t),this.className=e,this.sceneFunc(this._sceneFunc)},_sceneFunc:function(e){e.beginPath(),e.arc(0,0,this.getRadius(),0,t,!1),e.closePath(),e.fillStrokeShape(this)},getWidth:function(){return 2*this.getRadius()},getHeight:function(){return 2*this.getRadius()},setWidth:function(t){Konva.Node.prototype.setWidth.call(this,t),this.radius()!==t/2&&this.setRadius(t/2)},setHeight:function(t){Konva.Node.prototype.setHeight.call(this,t),this.radius()!==t/2&&this.setRadius(t/2)}},Konva.Util.extend(Konva.Circle,Konva.Shape),Konva.Factory.addGetterSetter(Konva.Circle,"radius",0),Konva.Factory.addOverloadedGetterSetter(Konva.Circle,"radius"),Konva.Collection.mapMethods(Konva.Circle)}(),function(){var t=2*Math.PI-1e-4,e="Ellipse";Konva.Ellipse=function(t){this.___init(t)},Konva.Ellipse.prototype={_centroid:!0,___init:function(t){Konva.Shape.call(this,t),this.className=e,this.sceneFunc(this._sceneFunc)},_sceneFunc:function(e){var n=this.getRadiusX(),a=this.getRadiusY();e.beginPath(),e.save(),n!==a&&e.scale(1,a/n),e.arc(0,0,n,0,t,!1),e.restore(),e.closePath(),e.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(){var t=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(e){e.beginPath(),e.arc(0,0,this.getInnerRadius(),0,t,!1),e.moveTo(this.getOuterRadius(),0),e.arc(0,0,this.getOuterRadius(),t,0,!0),e.closePath(),e.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(){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(){Konva.Arc=function(t){this.___init(t)},Konva.Arc.prototype={_centroid:!0,___init:function(t){Konva.Shape.call(this,t),this.className="Arc",this.sceneFunc(this._sceneFunc)},_sceneFunc:function(t){var e=Konva.getAngle(this.angle()),n=this.clockwise();t.beginPath(),t.arc(0,0,this.getOuterRadius(),0,e,n),t.arc(0,0,this.getInnerRadius(),e,0,!n),t.closePath(),t.fillStrokeShape(this)},getWidth:function(){return 2*this.getOuterRadius()},getHeight:function(){return 2*this.getOuterRadius()},setWidth:function(t){Konva.Node.prototype.setWidth.call(this,t),this.getOuterRadius()!==t/2&&this.setOuterRadius(t/2)},setHeight:function(t){Konva.Node.prototype.setHeight.call(this,t),this.getOuterRadius()!==t/2&&this.setOuterRadius(t/2)}},Konva.Util.extend(Konva.Arc,Konva.Shape),Konva.Factory.addGetterSetter(Konva.Arc,"innerRadius",0),Konva.Factory.addGetterSetter(Konva.Arc,"outerRadius",0),Konva.Factory.addGetterSetter(Konva.Arc,"angle",0),Konva.Factory.addGetterSetter(Konva.Arc,"clockwise",!1),Konva.Collection.mapMethods(Konva.Arc)}(),function(){var t="Image";Konva.Image=function(t){this.___init(t)},Konva.Image.prototype={___init:function(e){Konva.Shape.call(this,e),this.className=t,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,n,a,i=this.getWidth(),o=this.getHeight(),r=this.getImage();r&&(e=this.getCropWidth(),n=this.getCropHeight(),a=e&&n?[r,this.getCropX(),this.getCropY(),e,n,0,0,i,o]:[r,0,0,i,o]),(this.hasFill()||this.hasStroke())&&(t.beginPath(),t.rect(0,0,i,o),t.closePath(),t.fillStrokeShape(this)),r&&t.drawImage.apply(t,a)},_hitFunc:function(t){var e=this.getWidth(),n=this.getHeight();t.beginPath(),t.rect(0,0,e,n),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)}(),function(){function t(t){t.fillText(this.partialText,0,0)}function e(t){t.strokeText(this.partialText,0,0)}var n="auto",a="center",i="Change.konva",o="2d",r="-",s="",h="left",c="text",l="Text",d="middle",v="normal",u="px ",f=" ",g="right",p="word",K="char",m="none",_=["fontFamily","fontSize","fontStyle","fontVariant","padding","align","lineHeight","text","width","height","wrap"],y=_.length,S=Konva.Util.createCanvasElement().getContext(o);Konva.Text=function(t){this.___init(t)},Konva.Text.prototype={___init:function(a){a=a||{},a.fill=a.fill||"black",void 0===a.width&&(a.width=n),void 0===a.height&&(a.height=n),Konva.Shape.call(this,a),this._fillFunc=t,this._strokeFunc=e,this.className=l;for(var o=0;y>o;o++)this.on(_[o]+i,this._setTextData);this._setTextData(),this.sceneFunc(this._sceneFunc),this.hitFunc(this._hitFunc)},_sceneFunc:function(t){var e,n=this.getPadding(),i=this.getTextHeight(),o=this.getLineHeight()*i,r=this.textArr,s=r.length,c=this.getWidth();for(t.setAttr("font",this._getContextFont()),t.setAttr("textBaseline",d),t.setAttr("textAlign",h),t.save(),n?(t.translate(n,0),t.translate(0,n+i/2)):t.translate(0,i/2),e=0;s>e;e++){var l=r[e],v=l.text,u=l.width;t.save(),this.getAlign()===g?t.translate(c-u-2*n,0):this.getAlign()===a&&t.translate((c-u-2*n)/2,0),this.partialText=v,t.fillStrokeShape(this),t.restore(),t.translate(0,o)}t.restore()},_hitFunc:function(t){var e=this.getWidth(),n=this.getHeight();t.beginPath(),t.rect(0,0,e,n),t.closePath(),t.fillStrokeShape(this)},setText:function(t){var e=Konva.Util._isString(t)?t:t.toString();return this._setAttr(c,e),this},getWidth:function(){return this.attrs.width===n?this.getTextWidth()+2*this.getPadding():this.attrs.width},getHeight:function(){return this.attrs.height===n?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,n=S,a=this.getFontSize();return n.save(),n.font=this._getContextFont(),e=n.measureText(t),n.restore(),{width:e.width,height:parseInt(a,10)}},_getContextFont:function(){return this.getFontStyle()+f+this.getFontVariant()+f+this.getFontSize()+u+this.getFontFamily()},_addTextLine:function(t,e){return this.textArr.push({text:t,width:e})},_getTextWidth:function(t){return S.measureText(t).width},_setTextData:function(){var t=this.getText().split("\n"),e=+this.getFontSize(),a=0,i=this.getLineHeight()*e,o=this.attrs.width,s=this.attrs.height,h=o!==n,c=s!==n,l=this.getPadding(),d=o-2*l,v=s-2*l,u=0,g=this.getWrap(),p=g!==m,_=g!==K&&p;this.textArr=[],S.save(),S.font=this._getContextFont();for(var y=0,C=t.length;C>y;++y){var x=t[y],w=this._getTextWidth(x);if(h&&w>d)for(;x.length>0;){for(var b=0,F=x.length,T="",P=0;F>b;){var A=b+F>>>1,k=x.slice(0,A+1),M=this._getTextWidth(k);d>=M?(b=A+1,T=k,P=M):F=A}if(!T)break;if(_){var G=Math.max(T.lastIndexOf(f),T.lastIndexOf(r))+1;G>0&&(b=G,T=T.slice(0,b),P=this._getTextWidth(T))}if(this._addTextLine(T,P),a=Math.max(a,P),u+=i,!p||c&&u+i>v)break;if(x=x.slice(b),x.length>0&&(w=this._getTextWidth(x),d>=w)){this._addTextLine(x,w),u+=i,a=Math.max(a,w);break}}else this._addTextLine(x,w),u+=i,a=Math.max(a,w);if(c&&u+i>v)break}S.restore(),this.textHeight=e,this.textWidth=a}},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",v),Konva.Factory.addGetterSetter(Konva.Text,"fontVariant",v),Konva.Factory.addGetterSetter(Konva.Text,"padding",0),Konva.Factory.addGetterSetter(Konva.Text,"align",h),Konva.Factory.addGetterSetter(Konva.Text,"lineHeight",1),Konva.Factory.addGetterSetter(Konva.Text,"wrap",p),Konva.Factory.addGetter(Konva.Text,"text",s),Konva.Factory.addOverloadedGetterSetter(Konva.Text,"text"),Konva.Collection.mapMethods(Konva.Text)}(),function(){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",function(){this._clearCache("tensionPoints")}),this.sceneFunc(this._sceneFunc)},_sceneFunc:function(t){var e,n,a,i=this.getPoints(),o=i.length,r=this.getTension(),s=this.getClosed();if(o){if(t.beginPath(),t.moveTo(i[0],i[1]),0!==r&&o>4){for(e=this.getTensionPoints(),n=e.length,a=s?0:4,s||t.quadraticCurveTo(e[0],e[1],e[2],e[3]);n-2>a;)t.bezierCurveTo(e[a++],e[a++],e[a++],e[a++],e[a++],e[a++]);s||t.quadraticCurveTo(e[n-2],e[n-1],i[o-2],i[o-1])}else for(a=2;o>a;a+=2)t.lineTo(i[a],i[a+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,n=this.getTension(),a=Konva.Util,i=a._getControlPoints(t[e-2],t[e-1],t[0],t[1],t[2],t[3],n),o=a._getControlPoints(t[e-4],t[e-3],t[e-2],t[e-1],t[0],t[1],n),r=Konva.Util._expandPoints(t,n),s=[i[2],i[3]].concat(r).concat([o[0],o[1],t[e-2],t[e-1],o[2],o[3],i[0],i[1],t[0],t[1]]);return s},getWidth:function(){return this.getSelfRect().width},getHeight:function(){return this.getSelfRect().height},getSelfRect:function(){var t;t=0!==this.getTension()?this._getTensionPoints():this.getPoints();for(var e,n,a=t[0],i=t[0],o=t[0],r=t[0],s=0;st?t+1: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(){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,n=!1;t.beginPath();for(var a=0;ac?h:c,g=h>c?1:h/c,p=h>c?c/h:1;t.translate(r,s),t.rotate(v),t.scale(g,p),t.arc(0,0,f,l,l+d,1-u),t.scale(1/g,1/p),t.rotate(-v),t.translate(-r,-s);break;case"z":t.closePath(),n=!0}}n?t.fillStrokeShape(this):t.strokeShape(this)},getSelfRect:function(){var t=[];this.dataArray.forEach(function(e){t=t.concat(e.points)});for(var e,n,a=t[0],i=t[0],o=t[0],r=t[0],s=0;sa&&(h*=-1);var c,l=s*h;if(a===e)c={x:o,y:r+l};else if((r-n)/(o-e+1e-8)===s)c={x:o+h,y:r+l};else{var d,v,u=this.getLineLength(e,n,a,i);if(1e-8>u)return void 0;var f=(o-e)*(a-e)+(r-n)*(i-n);f/=u*u,d=e+f*(a-e),v=n+f*(i-n);var g=this.getLineLength(o,r,d,v),p=Math.sqrt(t*t-g*g);h=Math.sqrt(p*p/(1+s*s)),e>a&&(h*=-1),l=s*h,c={x:d+h,y:v+l}}return c},Konva.Path.getPointOnCubicBezier=function(t,e,n,a,i,o,r,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 v(t){return(1-t)*(1-t)*(1-t)}var u=s*c(t)+o*l(t)+a*d(t)+e*v(t),f=h*c(t)+r*l(t)+i*d(t)+n*v(t);return{x:u,y:f}},Konva.Path.getPointOnQuadraticBezier=function(t,e,n,a,i,o,r){function s(t){return t*t}function h(t){return 2*t*(1-t)}function c(t){return(1-t)*(1-t)}var l=o*s(t)+a*h(t)+e*c(t),d=r*s(t)+i*h(t)+n*c(t);return{x:l,y:d}},Konva.Path.getPointOnEllipticalArc=function(t,e,n,a,i,o){var r=Math.cos(o),s=Math.sin(o),h={x:n*Math.cos(i),y:a*Math.sin(i)};return{x:t+(h.x*r-h.y*s),y:e+(h.x*s+h.y*r)}},Konva.Path.parsePathData=function(t){if(!t)return[];var e=t,n=["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 a=0;a0&&""===l[0]&&l.shift();for(var d=0;d0&&!isNaN(l[0]);){var v,u,f,g,p,K,m,_,y,S,C=null,x=[],w=r,b=s;switch(c){case"l":r+=l.shift(),s+=l.shift(),C="L",x.push(r,s);break;case"L":r=l.shift(),s=l.shift(),x.push(r,s);break;case"m":var F=l.shift(),T=l.shift();if(r+=F,s+=T,C="M",o.length>2&&"z"===o[o.length-1].command)for(var P=o.length-2;P>=0;P--)if("M"===o[P].command){r=o[P].points[0]+F,s=o[P].points[1]+T;break}x.push(r,s),c="l";break;case"M":r=l.shift(),s=l.shift(),C="M",x.push(r,s),c="L";break;case"h":r+=l.shift(),C="L",x.push(r,s);break;case"H":r=l.shift(),C="L",x.push(r,s);break;case"v":s+=l.shift(),C="L",x.push(r,s);break;case"V":s=l.shift(),C="L",x.push(r,s);break;case"C":x.push(l.shift(),l.shift(),l.shift(),l.shift()),r=l.shift(),s=l.shift(),x.push(r,s);break;case"c":x.push(r+l.shift(),s+l.shift(),r+l.shift(),s+l.shift()),r+=l.shift(),s+=l.shift(),C="C",x.push(r,s); -break;case"S":u=r,f=s,v=o[o.length-1],"C"===v.command&&(u=r+(r-v.points[2]),f=s+(s-v.points[3])),x.push(u,f,l.shift(),l.shift()),r=l.shift(),s=l.shift(),C="C",x.push(r,s);break;case"s":u=r,f=s,v=o[o.length-1],"C"===v.command&&(u=r+(r-v.points[2]),f=s+(s-v.points[3])),x.push(u,f,r+l.shift(),s+l.shift()),r+=l.shift(),s+=l.shift(),C="C",x.push(r,s);break;case"Q":x.push(l.shift(),l.shift()),r=l.shift(),s=l.shift(),x.push(r,s);break;case"q":x.push(r+l.shift(),s+l.shift()),r+=l.shift(),s+=l.shift(),C="Q",x.push(r,s);break;case"T":u=r,f=s,v=o[o.length-1],"Q"===v.command&&(u=r+(r-v.points[0]),f=s+(s-v.points[1])),r=l.shift(),s=l.shift(),C="Q",x.push(u,f,r,s);break;case"t":u=r,f=s,v=o[o.length-1],"Q"===v.command&&(u=r+(r-v.points[0]),f=s+(s-v.points[1])),r+=l.shift(),s+=l.shift(),C="Q",x.push(u,f,r,s);break;case"A":g=l.shift(),p=l.shift(),K=l.shift(),m=l.shift(),_=l.shift(),y=r,S=s,r=l.shift(),s=l.shift(),C="A",x=this.convertEndpointToCenterParameterization(y,S,r,s,m,_,g,p,K);break;case"a":g=l.shift(),p=l.shift(),K=l.shift(),m=l.shift(),_=l.shift(),y=r,S=s,r+=l.shift(),s+=l.shift(),C="A",x=this.convertEndpointToCenterParameterization(y,S,r,s,m,_,g,p,K)}o.push({command:C||c,points:x,start:{x:w,y:b},pathLength:this.calcLength(w,b,C||c,x)})}("z"===c||"Z"===c)&&o.push({command:"z",points:[],start:void 0,pathLength:0})}return o},Konva.Path.calcLength=function(t,e,n,a){var i,o,r,s,h=Konva.Path;switch(n){case"L":return h.getLineLength(t,e,a[0],a[1]);case"C":for(i=0,o=h.getPointOnCubicBezier(0,t,e,a[0],a[1],a[2],a[3],a[4],a[5]),s=.01;1>=s;s+=.01)r=h.getPointOnCubicBezier(s,t,e,a[0],a[1],a[2],a[3],a[4],a[5]),i+=h.getLineLength(o.x,o.y,r.x,r.y),o=r;return i;case"Q":for(i=0,o=h.getPointOnQuadraticBezier(0,t,e,a[0],a[1],a[2],a[3]),s=.01;1>=s;s+=.01)r=h.getPointOnQuadraticBezier(s,t,e,a[0],a[1],a[2],a[3]),i+=h.getLineLength(o.x,o.y,r.x,r.y),o=r;return i;case"A":i=0;var c=a[4],l=a[5],d=a[4]+l,v=Math.PI/180;if(Math.abs(c-d)l)for(s=c-v;s>d;s-=v)r=h.getPointOnEllipticalArc(a[0],a[1],a[2],a[3],s,0),i+=h.getLineLength(o.x,o.y,r.x,r.y),o=r;else for(s=c+v;d>s;s+=v)r=h.getPointOnEllipticalArc(a[0],a[1],a[2],a[3],s,0),i+=h.getLineLength(o.x,o.y,r.x,r.y),o=r;return r=h.getPointOnEllipticalArc(a[0],a[1],a[2],a[3],d,0),i+=h.getLineLength(o.x,o.y,r.x,r.y)}return 0},Konva.Path.convertEndpointToCenterParameterization=function(t,e,n,a,i,o,r,s,h){var c=h*(Math.PI/180),l=Math.cos(c)*(t-n)/2+Math.sin(c)*(e-a)/2,d=-1*Math.sin(c)*(t-n)/2+Math.cos(c)*(e-a)/2,v=l*l/(r*r)+d*d/(s*s);v>1&&(r*=Math.sqrt(v),s*=Math.sqrt(v));var u=Math.sqrt((r*r*s*s-r*r*d*d-s*s*l*l)/(r*r*d*d+s*s*l*l));i===o&&(u*=-1),isNaN(u)&&(u=0);var f=u*r*d/s,g=u*-s*l/r,p=(t+n)/2+Math.cos(c)*f-Math.sin(c)*g,K=(e+a)/2+Math.sin(c)*f+Math.cos(c)*g,m=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])/(m(t)*m(e))},y=function(t,e){return(t[0]*e[1]=1&&(w=0),0===o&&w>0&&(w-=2*Math.PI),1===o&&0>w&&(w+=2*Math.PI),[p,K,r,s,S,w,c,o]},Konva.Factory.addGetterSetter(Konva.Path,"data"),Konva.Collection.mapMethods(Konva.Path)}(),function(){function t(t){t.fillText(this.partialText,0,0)}function e(t){t.strokeText(this.partialText,0,0)}var n="",a="normal";Konva.TextPath=function(t){this.___init(t)},Konva.TextPath.prototype={___init:function(n){var a=this;this.dummyCanvas=Konva.Util.createCanvasElement(),this.dataArray=[],Konva.Shape.call(this,n),this._fillFunc=t,this._strokeFunc=e,this._fillFuncHit=t,this._strokeFuncHit=e,this.className="TextPath",this.dataArray=Konva.Path.parsePathData(this.attrs.data),this.on("dataChange.konva",function(){a.dataArray=Konva.Path.parsePathData(this.attrs.data)}),this.on("textChange.konva textStroke.konva textStrokeWidth.konva",a._setTextData),a._setTextData(),this.sceneFunc(this._sceneFunc)},_sceneFunc:function(t){t.setAttr("font",this._getContextFont()),t.setAttr("textBaseline","middle"),t.setAttr("textAlign","left"),t.save();for(var e=this.glyphInfo,n=0;n0)return r=a,e[a];"M"==e[a].command&&(n={x:e[a].points[0],y:e[a].points[1]})}return{}},c=function(e){var o=t._getTextSize(e).width,r=0,c=0;for(a=void 0;Math.abs(o-r)/o>.01&&25>c;){c++;for(var l=r;void 0===i;)i=h(),i&&l+i.pathLengtho?a=Konva.Path.getPointOnLine(o,n.x,n.y,i.points[0],i.points[1],n.x,n.y):i=void 0;break;case"A":var v=i.points[4],u=i.points[5],f=i.points[4]+u;0===s?s=v+1e-8:o>r?s+=Math.PI/180*u/Math.abs(u):s-=Math.PI/360*u/Math.abs(u),(0>u&&f>s||u>=0&&s>f)&&(s=f,d=!0),a=Konva.Path.getPointOnEllipticalArc(i.points[0],i.points[1],i.points[2],i.points[3],s,i.points[6]);break;case"C":0===s?s=o>i.pathLength?1e-8:o/i.pathLength:o>r?s+=(o-r)/i.pathLength:s-=(r-o)/i.pathLength,s>1&&(s=1,d=!0),a=Konva.Path.getPointOnCubicBezier(s,i.start.x,i.start.y,i.points[0],i.points[1],i.points[2],i.points[3],i.points[4],i.points[5]);break;case"Q":0===s?s=o/i.pathLength:o>r?s+=(o-r)/i.pathLength:s-=(r-o)/i.pathLength,s>1&&(s=1,d=!0),a=Konva.Path.getPointOnQuadraticBezier(s,i.start.x,i.start.y,i.points[0],i.points[1],i.points[2],i.points[3])}void 0!==a&&(r=Konva.Path.getLineLength(n.x,n.y,a.x,a.y)),d&&(d=!1,i=void 0)}},l=0;le;e++)n=o*Math.sin(2*e*Math.PI/i),a=-1*o*Math.cos(2*e*Math.PI/i),t.lineTo(n,a);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(){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(),n=this.outerRadius(),a=this.numPoints();t.beginPath(),t.moveTo(0,0-n);for(var i=1;2*a>i;i++){var o=i%2===0?n:e,r=o*Math.sin(i*Math.PI/a),s=-1*o*Math.cos(i*Math.PI/a);t.lineTo(r,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(){var t=["fontFamily","fontSize","fontStyle","padding","lineHeight","text"],e="Change.konva",n="none",a="up",i="right",o="down",r="left",s="Label",h=t.length;Konva.Label=function(t){this.____init(t)},Konva.Label.prototype={____init:function(t){var e=this;Konva.Group.call(this,t),this.className=s,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(n){var a,i=this,o=function(){i._sync()};for(a=0;h>a;a++)n.on(t[a]+e,o)},getWidth:function(){return this.getText().getWidth()},getHeight:function(){return this.getText().getHeight()},_sync:function(){var t,e,n,s,h,c,l,d=this.getText(),v=this.getTag();if(d&&v){switch(t=d.getWidth(),e=d.getHeight(),n=v.getPointerDirection(),s=v.getPointerWidth(),l=v.getPointerHeight(),h=0,c=0,n){case a:h=t/2,c=-1*l;break;case i:h=t+s,c=e/2;break;case o:h=t/2,c=e+l;break;case r:h=-1*s,c=e/2}v.setAttrs({x:-1*h,y:-1*c,width:t,height:e}),d.setAttrs({x:-1*h,y:-1*c})}}},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(),n=this.getHeight(),s=this.getPointerDirection(),h=this.getPointerWidth(),c=this.getPointerHeight(),l=this.getCornerRadius();t.beginPath(),t.moveTo(0,0),s===a&&(t.lineTo((e-h)/2,0),t.lineTo(e/2,-1*c),t.lineTo((e+h)/2,0)),l?(t.lineTo(e-l,0),t.arc(e-l,l,l,3*Math.PI/2,0,!1)):t.lineTo(e,0),s===i&&(t.lineTo(e,(n-c)/2),t.lineTo(e+h,n/2),t.lineTo(e,(n+c)/2)),l?(t.lineTo(e,n-l),t.arc(e-l,n-l,l,0,Math.PI/2,!1)):t.lineTo(e,n),s===o&&(t.lineTo((e+h)/2,n),t.lineTo(e/2,n+c),t.lineTo((e-h)/2,n)),l?(t.lineTo(l,n),t.arc(l,n-l,l,Math.PI/2,Math.PI,!1)):t.lineTo(0,n),s===r&&(t.lineTo(0,(n+c)/2),t.lineTo(-1*h,n/2),t.lineTo(0,(n-c)/2)),l&&(t.lineTo(0,l),t.arc(l,l,l,Math.PI,3*Math.PI/2,!1)),t.closePath(),t.fillStrokeShape(this)},getSelfRect:function(){var t=0,e=0,n=this.getPointerWidth(),s=this.getPointerHeight(),h=this.pointerDirection(),c=this.getWidth(),l=this.getHeight();return h===a?(e-=s,l+=s):h===o?l+=s:h===r?(t-=1.5*n,c+=n):h===i&&(c+=1.5*n),{x:t,y:e,width:c,height:l}}},Konva.Util.extend(Konva.Tag,Konva.Shape),Konva.Factory.addGetterSetter(Konva.Tag,"pointerDirection",n),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(){Konva.Arrow=function(t){this.____init(t)},Konva.Arrow.prototype={____init:function(t){Konva.Line.call(this,t),this.className="Arrow"},_sceneFunc:function(t){var e=2*Math.PI,n=this.points(),a=n.length,i=n[a-2]-n[a-4],o=n[a-1]-n[a-3],r=(Math.atan2(o,i)+e)%e,s=this.pointerLength(),h=this.pointerWidth();t.save(),t.beginPath(),t.translate(n[a-2],n[a-1]),t.rotate(r),t.moveTo(0,0),t.lineTo(-s,h/2),t.lineTo(-s,-h/2),t.closePath(),t.restore(),this.pointerAtBeginning()&&(t.save(),t.translate(n[0],n[1]),i=n[2]-n[0],o=n[3]-n[1],t.rotate((Math.atan2(-o,-i)+e)%e),t.moveTo(0,0),t.lineTo(-10,6),t.lineTo(-10,-6),t.closePath(),t.restore()),t.fillStrokeShape(this),Konva.Line.prototype._sceneFunc.apply(this,arguments)}},Konva.Util.extend(Konva.Arrow,Konva.Line),Konva.Factory.addGetterSetter(Konva.Arrow,"pointerLength",10),Konva.Factory.addGetterSetter(Konva.Arrow,"pointerWidth",10),Konva.Factory.addGetterSetter(Konva.Arrow,"pointerAtBeginning",!1),Konva.Collection.mapMethods(Konva.Arrow)}(); \ No newline at end of file +Konva.Filters.Sepia=function(t){var e,n,a,i,o,r,s,h,c,l=t.data,d=t.width,v=t.height,u=4*d;do{e=(v-1)*u,n=d;do a=e+4*(n-1),i=l[a],o=l[a+1],r=l[a+2],s=.393*i+.769*o+.189*r,h=.349*i+.686*o+.168*r,c=.272*i+.534*o+.131*r,l[a]=s>255?255:s,l[a+1]=h>255?255:h,l[a+2]=c>255?255:c,l[a+3]=l[a+3];while(--n)}while(--v)}}(),function(){Konva.Filters.Solarize=function(t){var e=t.data,n=t.width,a=t.height,i=4*n,o=a;do{var r=(o-1)*i,s=n;do{var h=r+4*(s-1),c=e[h],l=e[h+1],d=e[h+2];c>127&&(c=255-c),l>127&&(l=255-l),d>127&&(d=255-d),e[h]=c,e[h+1]=l,e[h+2]=d}while(--s)}while(--o)}}(),function(){var t=function(t,e,n){var a,i,o,r,s=t.data,h=e.data,c=t.width,l=t.height,d=n.polarCenterX||c/2,v=n.polarCenterY||l/2,u=0,f=0,g=0,p=0,K=Math.sqrt(d*d+v*v);i=c-d,o=l-v,r=Math.sqrt(i*i+o*o),K=r>K?r:K;var m,_,y,S,C=l,x=c,w=360/x*Math.PI/180;for(_=0;x>_;_+=1)for(y=Math.sin(_*w),S=Math.cos(_*w),m=0;C>m;m+=1)i=Math.floor(d+K*m/C*S),o=Math.floor(v+K*m/C*y),a=4*(o*c+i),u=s[a+0],f=s[a+1],g=s[a+2],p=s[a+3],a=4*(_+m*c),h[a+0]=u,h[a+1]=f,h[a+2]=g,h[a+3]=p},e=function(t,e,n){var a,i,o,r,s,h,c=t.data,l=e.data,d=t.width,v=t.height,u=n.polarCenterX||d/2,f=n.polarCenterY||v/2,g=0,p=0,K=0,m=0,_=Math.sqrt(u*u+f*f);i=d-u,o=v-f,h=Math.sqrt(i*i+o*o),_=h>_?h:_;var y,S,C,x,w=v,b=d,F=n.polarRotation||0;for(i=0;d>i;i+=1)for(o=0;v>o;o+=1)r=i-u,s=o-f,y=Math.sqrt(r*r+s*s)*w/_,S=(180*Math.atan2(s,r)/Math.PI+360+F)%360,S=S*b/360,C=Math.floor(S),x=Math.floor(y),a=4*(x*d+C),g=c[a+0],p=c[a+1],K=c[a+2],m=c[a+3],a=4*(o*d+i),l[a+0]=g,l[a+1]=p,l[a+2]=K,l[a+3]=m},n=Konva.Util.createCanvasElement();Konva.Filters.Kaleidoscope=function(a){var i,o,r,s,h,c,l,d,v,u,f=a.width,g=a.height,p=Math.round(this.kaleidoscopePower()),K=Math.round(this.kaleidoscopeAngle()),m=Math.floor(f*(K%360)/360);if(!(1>p)){n.width=f,n.height=g;var _=n.getContext("2d").getImageData(0,0,f,g);t(a,_,{polarCenterX:f/2,polarCenterY:g/2});for(var y=f/Math.pow(2,p);8>=y;)y=2*y,p-=1;y=Math.ceil(y);var S=y,C=0,x=S,w=1;for(m+y>f&&(C=S,x=0,w=-1),o=0;g>o;o+=1)for(i=C;i!==x;i+=w)r=Math.round(i+m)%f,v=4*(f*o+r),h=_.data[v+0],c=_.data[v+1],l=_.data[v+2],d=_.data[v+3],u=4*(f*o+i),_.data[u+0]=h,_.data[u+1]=c,_.data[u+2]=l,_.data[u+3]=d;for(o=0;g>o;o+=1)for(S=Math.floor(y),s=0;p>s;s+=1){for(i=0;S+1>i;i+=1)v=4*(f*o+i),h=_.data[v+0],c=_.data[v+1],l=_.data[v+2],d=_.data[v+3],u=4*(f*o+2*S-i-1),_.data[u+0]=h,_.data[u+1]=c,_.data[u+2]=l,_.data[u+3]=d;S*=2}e(_,a,{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(){Konva.Container=function(t){this.__init(t)},Konva.Util.addMethods(Konva.Container,{__init:function(t){this.children=new Konva.Collection,Konva.Node.call(this,t)},getChildren:function(t){if(t){var e=new Konva.Collection;return this.children.each(function(n){t(n)&&e.push(n)}),e}return this.children},hasChildren:function(){return this.getChildren().length>0},removeChildren:function(){for(var t,e=Konva.Collection.toCollection(this.children),n=0;n1){for(var e=0;ee;e++)if(a=c[e],"#"===a.charAt(0))o=this._getNodeById(a.slice(1)),o&&h.push(o);else if("."===a.charAt(0))i=this._getNodesByName(a.slice(1)),h=h.concat(i);else for(r=this.getChildren(),s=r.length,n=0;s>n;n++)h=h.concat(r[n]._get(a));return Konva.Collection.toCollection(h)},findOne:function(t){return this.find(t)[0]},_getNodeById:function(t){var e=Konva.ids[t];return void 0!==e&&this.isAncestorOf(e)?e:null},_getNodesByName:function(t){var e=Konva.names[t]||[];return this._getDescendants(e)},_get:function(t){for(var e=Konva.Node.prototype._get.call(this,t),n=this.getChildren(),a=n.length,i=0;a>i;i++)e=e.concat(n[i]._get(t));return e},toObject:function(){var t=Konva.Node.prototype.toObject.call(this);t.children=[];for(var e=this.getChildren(),n=e.length,a=0;n>a;a++){var i=e[a];t.children.push(i.toObject())}return t},_getDescendants:function(t){for(var e=[],n=t.length,a=0;n>a;a++){var i=t[a];this.isAncestorOf(i)&&e.push(i)}return e},isAncestorOf:function(t){for(var e=t.getParent();e;){if(e._id===this._id)return!0;e=e.getParent()}return!1},clone:function(t){var e=Konva.Node.prototype.clone.call(this,t);return this.getChildren().each(function(t){e.add(t.clone())}),e},getAllIntersections:function(t){var e=[];return this.find("Shape").each(function(n){n.isVisible()&&n.intersects(t)&&e.push(n)}),e},_setChildrenIndices:function(){this.children.each(function(t,e){t.index=e})},drawScene:function(t,e,n){var a=this.getLayer(),i=t||a&&a.getCanvas(),o=i&&i.getContext(),r=this._cache.canvas,s=r&&r.scene;return this.isVisible()&&(!n&&s?(o.save(),a._applyTransform(this,o,e),this._drawCachedSceneCanvas(o),o.restore()):this._drawChildren(i,"drawScene",e)),this},drawHit:function(t,e,n){var a=this.getLayer(),i=t||a&&a.hitCanvas,o=i&&i.getContext(),r=this._cache.canvas,s=r&&r.hit;return this.shouldDrawHit(i)&&(a&&a.clearHitCache(),!n&&s?(o.save(),a._applyTransform(this,o,e),this._drawCachedHitCanvas(o),o.restore()):this._drawChildren(i,"drawHit",e)),this},_drawChildren:function(t,e,n){var a,i,o=this.getLayer(),r=t&&t.getContext(),s=this.getClipWidth(),h=this.getClipHeight(),c=s&&h;c&&o&&(a=this.getClipX(),i=this.getClipY(),r.save(),o._applyTransform(this,r),r.beginPath(),r.rect(a,i,s,h),r.clip(),r.reset()),this.children.each(function(a){a[e](t,n)}),c&&r.restore()},shouldDrawHit:function(t){var e=this.getLayer(),n=Konva.DD,a=n&&Konva.isDragging()&&-1!==Konva.DD.anim.getLayers().indexOf(e);return t&&t.isCache||e&&e.hitGraphEnabled()&&this.isVisible()&&!a},getClientRect:function(t){var e,n,a,i;this.children.each(function(t){var o=t.getClientRect();void 0===e?(e=o.x,n=o.y,a=o.x+o.width,i=o.y+o.height):(e=Math.min(e,o.x),n=Math.min(n,o.y),a=Math.max(a,o.x+o.width),i=Math.max(i,o.y+o.height))});var o={x:e,y:n,width:a-e,height:i-n};return t?o:this._transformedRect(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.Collection.mapMethods(Konva.Container)}(),function(){function t(t){t.fill()}function e(t){t.stroke()}function n(t){t.fill()}function a(t){t.stroke()}function i(){this._clearCache(r)}function o(){this._clearCache(s)}var r="hasShadow",s="shadowRGBA";Konva.Shape=function(t){this.__init(t)},Konva.Util.addMethods(Konva.Shape,{__init:function(r){this.nodeType="Shape",this._fillFunc=t,this._strokeFunc=e,this._fillFuncHit=n,this._strokeFuncHit=a;for(var s,h=Konva.shapes;;)if(s=Konva.Util.getRandomColor(),s&&!(s in h))break;this.colorKey=s,h[s]=this,Konva.Node.call(this,r),this.on("shadowColorChange.konva shadowBlurChange.konva shadowOffsetChange.konva shadowOpacityChange.konva shadowEnabledChange.konva",i),this.on("shadowColorChange.konva shadowOpacityChange.konva shadowEnabledChange.konva",o)},hasChildren:function(){return!1},getChildren:function(){return[]},getContext:function(){return this.getLayer().getContext()},getCanvas:function(){return this.getLayer().getCanvas()},hasShadow:function(){return this._getCache(r,this._hasShadow)},_hasShadow:function(){return this.getShadowEnabled()&&0!==this.getShadowOpacity()&&!!(this.getShadowColor()||this.getShadowBlur()||this.getShadowOffsetX()||this.getShadowOffsetY())},getShadowRGBA:function(){return this._getCache(s,this._getShadowRGBA)},_getShadowRGBA:function(){if(this.hasShadow()){var t=Konva.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.stroke()||this.strokeRed()||this.strokeGreen()||this.strokeBlue())},intersects:function(t){var e,n=this.getStage(),a=n.bufferHitCanvas;return a.getContext().clear(),this.drawScene(a),e=a.context.getImageData(Math.round(t.x),Math.round(t.y),1,1).data,e[3]>0},destroy:function(){Konva.Node.prototype.destroy.call(this),delete Konva.shapes[this.colorKey]},_useBufferCanvas:function(t){return!t&&this.perfectDrawEnabled()&&1!==this.getAbsoluteOpacity()&&this.hasFill()&&this.hasStroke()&&this.getStage()||this.perfectDrawEnabled()&&this.hasShadow()&&1!==this.getAbsoluteOpacity()&&this.hasFill()&&this.hasStroke()&&this.getStage()},getSelfRect:function(){var t=this.getSize();return{x:this._centroid?Math.round(-t.width/2):0,y:this._centroid?Math.round(-t.height/2):0,width:t.width,height:t.height}},getClientRect:function(t){var e=this.getSelfRect(),n=this.hasStroke()&&this.strokeWidth()||0,a=e.width+n,i=e.height+n,o=this.shadowOffsetX(),r=this.shadowOffsetY(),s=a+Math.abs(o),h=i+Math.abs(r),c=this.hasShadow()&&this.shadowBlur()||0,l=s+2*c,d=h+2*c,v=0;Math.round(n/2)!==n/2&&(v=1);var u={width:l+v,height:d+v,x:-Math.round(n/2+c)+Math.min(o,0)+e.x,y:-Math.round(n/2+c)+Math.min(r,0)+e.y};return t?u:this._transformedRect(u)},drawScene:function(t,e,n){var a,i,o,r=this.getLayer(),s=t||r.getCanvas(),h=s.getContext(),c=this._cache.canvas,l=this.sceneFunc(),d=this.hasShadow(),v=this.hasStroke();if(this.isVisible())if(c)h.save(),r._applyTransform(this,h,e),this._drawCachedSceneCanvas(h),h.restore();else if(l){if(h.save(),this._useBufferCanvas(n)){if(a=this.getStage(),i=a.bufferCanvas,o=i.getContext(),o.clear(),o.save(),o._applyLineJoin(this),!n)if(r)r._applyTransform(this,o,e);else{var u=this.getAbsoluteTransform(e).getMatrix();h.transform(u[0],u[1],u[2],u[3],u[4],u[5])}l.call(this,o),o.restore(),d&&!s.hitCanvas?(h.save(),h._applyShadow(this),h._applyOpacity(this),h.drawImage(i._canvas,0,0),h.restore()):(h._applyOpacity(this),h.drawImage(i._canvas,0,0))}else{if(h._applyLineJoin(this),!n)if(r)r._applyTransform(this,h,e);else{var f=this.getAbsoluteTransform(e).getMatrix();h.transform(f[0],f[1],f[2],f[3],f[4],f[5])}d&&v&&!s.hitCanvas?(h.save(),n||h._applyOpacity(this),h._applyShadow(this),l.call(this,h),h.restore(),this.hasFill()&&this.getShadowForStrokeEnabled()&&l.call(this,h)):d&&!s.hitCanvas?(h.save(),n||h._applyOpacity(this),h._applyShadow(this),l.call(this,h),h.restore()):(n||h._applyOpacity(this),l.call(this,h))}h.restore()}return this},drawHit:function(t,e,n){var a=this.getLayer(),i=t||a.hitCanvas,o=i.getContext(),r=this.hitFunc()||this.sceneFunc(),s=this._cache.canvas,h=s&&s.hit;if(this.shouldDrawHit(i))if(a&&a.clearHitCache(),h)o.save(),a._applyTransform(this,o,e),this._drawCachedHitCanvas(o),o.restore();else if(r){if(o.save(),o._applyLineJoin(this),!n)if(a)a._applyTransform(this,o,e);else{var c=this.getAbsoluteTransform(e).getMatrix();o.transform(c[0],c[1],c[2],c[3],c[4],c[5])}r.call(this,o),o.restore()}return this},drawHitFromCache:function(t){var e,n,a,i,o,r,s=t||0,h=this._cache.canvas,c=this._getCachedSceneCanvas(),l=h.hit,d=l.getContext(),v=l.getWidth(),u=l.getHeight();d.clear(),d.drawImage(c._canvas,0,0,v,u);try{for(e=d.getImageData(0,0,v,u),n=e.data,a=n.length,i=Konva.Util._hexToRgb(this.colorKey),o=0;a>o;o+=4)r=n[o+3],r>s?(n[o]=i.r,n[o+1]=i.g,n[o+2]=i.b,n[o+3]=255):n[o+3]=0;d.putImageData(e,0,0)}catch(f){Konva.Util.error("Unable to draw hit graph from cached scene canvas. "+f.message)}return this}}),Konva.Util.extend(Konva.Shape,Konva.Node),Konva.Factory.addGetterSetter(Konva.Shape,"stroke"),Konva.Factory.addGetterSetter(Konva.Shape,"strokeRed",0,Konva.Validators.RGBComponent),Konva.Factory.addGetterSetter(Konva.Shape,"strokeGreen",0,Konva.Validators.RGBComponent),Konva.Factory.addGetterSetter(Konva.Shape,"strokeBlue",0,Konva.Validators.RGBComponent),Konva.Factory.addGetterSetter(Konva.Shape,"strokeAlpha",1,Konva.Validators.alphaComponent),Konva.Factory.addGetterSetter(Konva.Shape,"strokeWidth",2),Konva.Factory.addGetterSetter(Konva.Shape,"strokeHitEnabled",!0),Konva.Factory.addGetterSetter(Konva.Shape,"perfectDrawEnabled",!0),Konva.Factory.addGetterSetter(Konva.Shape,"shadowForStrokeEnabled",!0),Konva.Factory.addGetterSetter(Konva.Shape,"lineJoin"),Konva.Factory.addGetterSetter(Konva.Shape,"lineCap"),Konva.Factory.addGetterSetter(Konva.Shape,"sceneFunc"),Konva.Factory.addGetterSetter(Konva.Shape,"hitFunc"),Konva.Factory.addGetterSetter(Konva.Shape,"dash"),Konva.Factory.addGetterSetter(Konva.Shape,"shadowColor"),Konva.Factory.addGetterSetter(Konva.Shape,"shadowRed",0,Konva.Validators.RGBComponent),Konva.Factory.addGetterSetter(Konva.Shape,"shadowGreen",0,Konva.Validators.RGBComponent),Konva.Factory.addGetterSetter(Konva.Shape,"shadowBlue",0,Konva.Validators.RGBComponent),Konva.Factory.addGetterSetter(Konva.Shape,"shadowAlpha",1,Konva.Validators.alphaComponent),Konva.Factory.addGetterSetter(Konva.Shape,"shadowBlur"),Konva.Factory.addGetterSetter(Konva.Shape,"shadowOpacity"),Konva.Factory.addComponentsGetterSetter(Konva.Shape,"shadowOffset",["x","y"]),Konva.Factory.addGetterSetter(Konva.Shape,"shadowOffsetX",0),Konva.Factory.addGetterSetter(Konva.Shape,"shadowOffsetY",0),Konva.Factory.addGetterSetter(Konva.Shape,"fillPatternImage"),Konva.Factory.addGetterSetter(Konva.Shape,"fill"),Konva.Factory.addGetterSetter(Konva.Shape,"fillRed",0,Konva.Validators.RGBComponent),Konva.Factory.addGetterSetter(Konva.Shape,"fillGreen",0,Konva.Validators.RGBComponent),Konva.Factory.addGetterSetter(Konva.Shape,"fillBlue",0,Konva.Validators.RGBComponent),Konva.Factory.addGetterSetter(Konva.Shape,"fillAlpha",1,Konva.Validators.alphaComponent),Konva.Factory.addGetterSetter(Konva.Shape,"fillPatternX",0),Konva.Factory.addGetterSetter(Konva.Shape,"fillPatternY",0),Konva.Factory.addGetterSetter(Konva.Shape,"fillLinearGradientColorStops"),Konva.Factory.addGetterSetter(Konva.Shape,"fillRadialGradientStartRadius",0),Konva.Factory.addGetterSetter(Konva.Shape,"fillRadialGradientEndRadius",0),Konva.Factory.addGetterSetter(Konva.Shape,"fillRadialGradientColorStops"),Konva.Factory.addGetterSetter(Konva.Shape,"fillPatternRepeat","repeat"),Konva.Factory.addGetterSetter(Konva.Shape,"fillEnabled",!0),Konva.Factory.addGetterSetter(Konva.Shape,"strokeEnabled",!0),Konva.Factory.addGetterSetter(Konva.Shape,"shadowEnabled",!0),Konva.Factory.addGetterSetter(Konva.Shape,"dashEnabled",!0),Konva.Factory.addGetterSetter(Konva.Shape,"strokeScaleEnabled",!0),Konva.Factory.addGetterSetter(Konva.Shape,"fillPriority","color"),Konva.Factory.addComponentsGetterSetter(Konva.Shape,"fillPatternOffset",["x","y"]),Konva.Factory.addGetterSetter(Konva.Shape,"fillPatternOffsetX",0),Konva.Factory.addGetterSetter(Konva.Shape,"fillPatternOffsetY",0),Konva.Factory.addComponentsGetterSetter(Konva.Shape,"fillPatternScale",["x","y"]),Konva.Factory.addGetterSetter(Konva.Shape,"fillPatternScaleX",1),Konva.Factory.addGetterSetter(Konva.Shape,"fillPatternScaleY",1),Konva.Factory.addComponentsGetterSetter(Konva.Shape,"fillLinearGradientStartPoint",["x","y"]),Konva.Factory.addGetterSetter(Konva.Shape,"fillLinearGradientStartPointX",0),Konva.Factory.addGetterSetter(Konva.Shape,"fillLinearGradientStartPointY",0),Konva.Factory.addComponentsGetterSetter(Konva.Shape,"fillLinearGradientEndPoint",["x","y"]),Konva.Factory.addGetterSetter(Konva.Shape,"fillLinearGradientEndPointX",0),Konva.Factory.addGetterSetter(Konva.Shape,"fillLinearGradientEndPointY",0),Konva.Factory.addComponentsGetterSetter(Konva.Shape,"fillRadialGradientStartPoint",["x","y"]),Konva.Factory.addGetterSetter(Konva.Shape,"fillRadialGradientStartPointX",0),Konva.Factory.addGetterSetter(Konva.Shape,"fillRadialGradientStartPointY",0),Konva.Factory.addComponentsGetterSetter(Konva.Shape,"fillRadialGradientEndPoint",["x","y"]),Konva.Factory.addGetterSetter(Konva.Shape,"fillRadialGradientEndPointX",0),Konva.Factory.addGetterSetter(Konva.Shape,"fillRadialGradientEndPointY",0),Konva.Factory.addGetterSetter(Konva.Shape,"fillPatternRotation",0),Konva.Factory.backCompat(Konva.Shape,{dashArray:"dash",getDashArray:"getDash",setDashArray:"getDash",drawFunc:"sceneFunc",getDrawFunc:"getSceneFunc",setDrawFunc:"setSceneFunc",drawHitFunc:"hitFunc",getDrawHitFunc:"getHitFunc",setDrawHitFunc:"setHitFunc"}),Konva.Collection.mapMethods(Konva.Shape)}(),function(){function t(t,e){t.content.addEventListener(e,function(n){t[I+e](n)},!1)}var e="Stage",n="string",a="px",i="mouseout",o="mouseleave",r="mouseover",s="mouseenter",h="mousemove",c="mousedown",l="mouseup",d="click",v="dblclick",u="touchstart",f="touchend",g="tap",p="dbltap",K="touchmove",m="DOMMouseScroll",_="mousewheel",y="wheel",S="contentMouseout",C="contentMouseover",x="contentMousemove",w="contentMousedown",b="contentMouseup",F="contentClick",T="contentDblclick",P="contentTouchstart",A="contentTouchend",k="contentDbltap",M="contentTouchmove",G="div",D="relative",R="konvajs-content",L=" ",I="_",N="container",O="",B=[c,h,l,i,u,K,f,r,m,_,y],U=B.length;Konva.Stage=function(t){this.___init(t)},Konva.Util.addMethods(Konva.Stage,{___init:function(t){this.nodeType=e,Konva.Container.call(this,t),this._id=Konva.idCounter++,this._buildDOM(),this._bindContentEvents(),this._enableNestedTransforms=!1,Konva.stages.push(this)},_validateAdd:function(t){"Layer"!==t.getType()&&Konva.Util.error("You may only add layers to the stage.")},setContainer:function(t){if(typeof t===n){var e=t;if(t=Konva.document.getElementById(t),!t)throw"Can not find container in document with id "+e}return this._setAttr(N,t),this},shouldDrawHit:function(){return!0},draw:function(){return Konva.Node.prototype.draw.call(this),this},setHeight:function(t){return Konva.Node.prototype.setHeight.call(this,t),this._resizeDOM(),this},setWidth:function(t){return Konva.Node.prototype.setWidth.call(this,t),this._resizeDOM(),this},clear:function(){var t,e=this.children,n=e.length;for(t=0;n>t;t++)e[t].clear();return this},clone:function(t){return t||(t={}),t.container=Konva.document.createElement(G),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);e>-1&&Konva.stages.splice(e,1)},getPointerPosition:function(){return this.pointerPos},getStage:function(){return this},getContent:function(){return this.content},toDataURL:function(t){function e(i){var o=h[i],c=o.toDataURL(),l=new Konva.window.Image;l.onload=function(){s.drawImage(l,0,0),i=0;e--)if(n=a[e].getIntersection(t))return n;return null},_resizeDOM:function(){if(this.content){var t,e,n=this.getWidth(),i=this.getHeight(),o=this.getChildren(),r=o.length;for(this.content.style.width=n+a,this.content.style.height=i+a,this.bufferCanvas.setSize(n,i),this.bufferHitCanvas.setSize(n,i),t=0;r>t;t++)e=o[t],e.setSize(n,i),e.draw()}},add:function(t){if(!(arguments.length>1))return Konva.Container.prototype.add.call(this,t),t._setCanvasSize(this.width(),this.height()),t.draw(),this.content.appendChild(t.canvas._canvas),this;for(var e=0;ee;e++)t(this,B[e])},_mouseover:function(t){Konva.UA.mobile||(this._setPointerPosition(t),this._fire(C,{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(o,{evt:t}),this.targetShape=null),this.pointerPos=void 0,this._fire(S,{evt:t})}},_mousemove:function(t){if(Konva.UA.ieMobile)return this._touchmove(t);if(("undefined"==typeof t.webkitMovementX&&"undefined"==typeof t.webkitMovementY||0!==t.webkitMovementY||0!==t.webkitMovementX)&&!Konva.UA.mobile){this._setPointerPosition(t);var e,n=Konva.DD;Konva.isDragging()||(e=this.getIntersection(this.getPointerPosition()),e&&e.isListening()?Konva.isDragging()||this.targetShape&&this.targetShape._id===e._id?e._fireAndBubble(h,{evt:t}):(this.targetShape&&(this.targetShape._fireAndBubble(i,{evt:t},e),this.targetShape._fireAndBubble(o,{evt:t},e)),e._fireAndBubble(r,{evt:t},this.targetShape),e._fireAndBubble(s,{evt:t},this.targetShape),this.targetShape=e):this.targetShape&&!Konva.isDragging()&&(this.targetShape._fireAndBubble(i,{evt:t}),this.targetShape._fireAndBubble(o,{evt:t}),this.targetShape=null),this._fire(x,{evt:t})),n&&n._drag(t),t.preventDefault&&t.preventDefault()}},_mousedown:function(t){if(Konva.UA.ieMobile)return this._touchstart(t);if(!Konva.UA.mobile){this._setPointerPosition(t);var e=this.getIntersection(this.getPointerPosition());Konva.listenClickTap=!0,e&&e.isListening()&&(this.clickStartShape=e,e._fireAndBubble(c,{evt:t})),this._fire(w,{evt:t})}t.preventDefault&&t.preventDefault()},_mouseup:function(t){if(Konva.UA.ieMobile)return this._touchend(t);if(!Konva.UA.mobile){this._setPointerPosition(t);var e=this.getIntersection(this.getPointerPosition()),n=this.clickStartShape,a=!1,i=Konva.DD;Konva.inDblClickWindow?(a=!0,Konva.inDblClickWindow=!1):i&&i.justDragged?i&&(i.justDragged=!1):Konva.inDblClickWindow=!0,setTimeout(function(){Konva.inDblClickWindow=!1},Konva.dblClickWindow),e&&e.isListening()&&(e._fireAndBubble(l,{evt:t}),Konva.listenClickTap&&n&&n._id===e._id&&(e._fireAndBubble(d,{evt:t}),a&&e._fireAndBubble(v,{evt:t}))),this._fire(b,{evt:t}),Konva.listenClickTap&&(this._fire(F,{evt:t}),a&&this._fire(T,{evt:t})),Konva.listenClickTap=!1}t.preventDefault&&t.preventDefault()},_touchstart:function(t){this._setPointerPosition(t);var e=this.getIntersection(this.getPointerPosition());Konva.listenClickTap=!0,e&&e.isListening()&&(this.tapStartShape=e,e._fireAndBubble(u,{evt:t}),e.isListening()&&t.preventDefault&&t.preventDefault()),this._fire(P,{evt:t})},_touchend:function(t){this._setPointerPosition(t);var e=this.getIntersection(this.getPointerPosition()),n=!1;Konva.inDblClickWindow?(n=!0,Konva.inDblClickWindow=!1):Konva.inDblClickWindow=!0,setTimeout(function(){Konva.inDblClickWindow=!1},Konva.dblClickWindow),e&&e.isListening()&&(e._fireAndBubble(f,{evt:t}),Konva.listenClickTap&&e._id===this.tapStartShape._id&&(e._fireAndBubble(g,{evt:t}),n&&e._fireAndBubble(p,{evt:t})),e.isListening()&&t.preventDefault&&t.preventDefault()),Konva.listenClickTap&&(this._fire(A,{evt:t}),n&&this._fire(k,{evt:t})),Konva.listenClickTap=!1},_touchmove:function(t){this._setPointerPosition(t);var e,n=Konva.DD;Konva.isDragging()||(e=this.getIntersection(this.getPointerPosition()),e&&e.isListening()&&(e._fireAndBubble(K,{evt:t}),e.isListening()&&t.preventDefault&&t.preventDefault()),this._fire(M,{evt:t})),n&&(n._drag(t),Konva.isDragging()&&t.preventDefault())},_DOMMouseScroll:function(t){this._mousewheel(t)},_mousewheel:function(t){this._setPointerPosition(t);var e=this.getIntersection(this.getPointerPosition());e&&e.isListening()&&e._fireAndBubble(_,{evt:t})},_wheel:function(t){this._mousewheel(t)},_setPointerPosition:function(t){var e,n=this._getContentPosition(),a=t.offsetX,i=t.clientX,o=null,r=null;t=t?t:window.event,void 0!==t.touches?t.touches.length>0&&(e=t.touches[0],o=e.clientX-n.left,r=e.clientY-n.top):void 0!==a?(o=a,r=t.offsetY):"mozilla"===Konva.UA.browser?(o=t.layerX||t.clientX-n.left,r=t.layerY||t.clientY-n.top):void 0!==i&&n&&(o=i-n.left,r=t.clientY-n.top),null!==o&&null!==r&&(this.pointerPos={x:o,y:r})},_getContentPosition:function(){var t=this.content.getBoundingClientRect?this.content.getBoundingClientRect():{top:0,left:0};return{top:t.top,left:t.left}},_buildDOM:function(){var t=this.getContainer();if(!t){if(Konva.Util.isBrowser())throw"Stage has no container. A container is required.";t=Konva.document.createElement(G)}t.innerHTML=O,this.content=Konva.document.createElement(G),this.content.style.position=D,this.content.className=R,this.content.setAttribute("role","presentation"),t.appendChild(this.content),this.bufferCanvas=new Konva.SceneCanvas({pixelRatio:1}),this.bufferHitCanvas=new Konva.HitCanvas,this._resizeDOM()},_onContent:function(t,e){var n,a,i=t.split(L),o=i.length;for(n=0;o>n;n++)a=i[n],this.content.addEventListener(a,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(){Konva.BaseLayer=function(t){this.___init(t)},Konva.Util.addMethods(Konva.BaseLayer,{___init:function(t){this.nodeType="Layer",Konva.Container.call(this,t)},createPNGStream:function(){return this.canvas._canvas.createPNGStream()},getCanvas:function(){return this.canvas},getHitCanvas:function(){return this.hitCanvas},getContext:function(){return this.getCanvas().getContext()},clear:function(t){return this.getContext().clear(t),this},clearHitCache:function(){this._hitImageData=void 0},setZIndex:function(t){Konva.Node.prototype.setZIndex.call(this,t);var e=this.getStage();return e&&(e.content.removeChild(this.getCanvas()._canvas),tn;n++){if(o=a[n],e=this._getIntersection({x:t.x+o.x*s,y:t.y+o.y*s}),r=e.shape)return r;if(h=!!e.antialiased,!e.antialiased)break}if(!h)return;s+=1}},_getImageData:function(t,e){var n=this.hitCanvas.width||1,a=this.hitCanvas.height||1,i=Math.round(e)*n+Math.round(t);return this._hitImageData||(this._hitImageData=this.hitCanvas.context.getImageData(0,0,n,a)),[this._hitImageData.data[4*i+0],this._hitImageData.data[4*i+1],this._hitImageData.data[4*i+2],this._hitImageData.data[4*i+3]]},_getIntersection:function(e){var n,a,i=this.hitCanvas.pixelRatio,o=this.hitCanvas.context.getImageData(Math.round(e.x*i),Math.round(e.y*i),1,1).data,r=o[3];return 255===r?(n=Konva.Util._rgbToHex(o[0],o[1],o[2]),a=Konva.shapes[t+n],a?{shape:a}:{antialiased:!0}):r>0?{antialiased:!0}:{}},drawScene:function(t,a){var i=this.getLayer(),o=t||i&&i.getCanvas();return this._fire(e,{node:this}),this.getClearBeforeDraw()&&o.getContext().clear(),Konva.Container.prototype.drawScene.call(this,o,a),this._fire(n,{node:this}),this},_applyTransform:function(t,e,n){var a=t.getAbsoluteTransform(n).getMatrix();e.transform(a[0],a[1],a[2],a[3],a[4],a[5])},drawHit:function(t,e){var n=this.getLayer(),a=t||n&&n.hitCanvas;return n&&n.getClearBeforeDraw()&&n.getHitCanvas().getContext().clear(),Konva.Container.prototype.drawHit.call(this,a,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){Konva.BaseLayer.prototype.setSize.call(this,t,e),this.hitCanvas.setSize(t,e)}}),Konva.Util.extend(Konva.Layer,Konva.BaseLayer),Konva.Factory.addGetterSetter(Konva.Layer,"hitGraphEnabled",!0),Konva.Collection.mapMethods(Konva.Layer)}(),function(){Konva.FastLayer=function(t){this.____init(t)},Konva.Util.addMethods(Konva.FastLayer,{____init:function(t){this.nodeType="Layer",this.canvas=new Konva.SceneCanvas,Konva.BaseLayer.call(this,t)},_validateAdd:function(t){var e=t.getType();"Shape"!==e&&Konva.Util.error("You may only add shapes to a fast layer.")},_setCanvasSize:function(t,e){this.canvas.setSize(t,e)},hitGraphEnabled:function(){return!1},getIntersection:function(){return null},drawScene:function(t){var e=this.getLayer(),n=t||e&&e.getCanvas();return this.getClearBeforeDraw()&&n.getContext().clear(),Konva.Container.prototype.drawScene.call(this,n),this},_applyTransform:function(t,e,n){if(!n||n._id!==this._id){var a=t.getTransform().getMatrix(); +e.transform(a[0],a[1],a[2],a[3],a[4],a[5])}},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(){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.error("You may only add groups and shapes to groups.")}}),Konva.Util.extend(Konva.Group,Konva.Container),Konva.Collection.mapMethods(Konva.Group)}(),function(){function t(t){setTimeout(t,1e3/60)}function e(){return i.apply(Konva.root,arguments)}var n=500,a=function(){return Konva.root.performance&&Konva.root.performance.now?function(){return Konva.root.performance.now()}:function(){return(new Date).getTime()}}(),i=function(){return Konva.root.requestAnimationFrame||Konva.root.webkitRequestAnimationFrame||Konva.root.mozRequestAnimationFrame||Konva.root.oRequestAnimationFrame||Konva.root.msRequestAnimationFrame||t}();Konva.Animation=function(t,e){var n=Konva.Animation;this.func=t,this.setLayers(e),this.id=n.animIdCounter++,this.frame={time:0,timeDiff:0,lastTime:a()}},Konva.Animation.prototype={setLayers:function(t){var e=[];e=t?t.length>0?t:[t]:[],this.layers=e},getLayers:function(){return this.layers},addLayer:function(t){var e,n,a=this.layers;if(a){for(e=a.length,n=0;e>n;n++)if(a[n]._id===t._id)return!1}else this.layers=[];return this.layers.push(t),!0},isRunning:function(){var t,e=Konva.Animation,n=e.animations,a=n.length;for(t=0;a>t;t++)if(n[t].id===this.id)return!0;return!1},start:function(){var t=Konva.Animation;this.stop(),this.frame.timeDiff=0,this.frame.lastTime=a(),t._addAnimation(this)},stop:function(){Konva.Animation._removeAnimation(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}},Konva.Animation.animations=[],Konva.Animation.animIdCounter=0,Konva.Animation.animRunning=!1,Konva.Animation._addAnimation=function(t){this.animations.push(t),this._handleAnimation()},Konva.Animation._removeAnimation=function(t){var e,n=t.id,a=this.animations,i=a.length;for(e=0;i>e;e++)if(a[e].id===n){this.animations.splice(e,1);break}},Konva.Animation._runFrames=function(){var t,e,n,i,o,r,s,h,c,l={},d=this.animations;for(i=0;io;o++)s=e[o],void 0!==s._id&&(l[s._id]=s);for(h in l)l[h].draw()},Konva.Animation._animationLoop=function(){var t=Konva.Animation;t.animations.length?(e(t._animationLoop),t._runFrames()):t.animRunning=!1},Konva.Animation._handleAnimation=function(){var t=this;this.animRunning||(this.animRunning=!0,t._animationLoop())};var o=Konva.Node.prototype.moveTo;Konva.Node.prototype.moveTo=function(t){o.call(this,t)},Konva.BaseLayer.prototype.batchDraw=function(){var t=this,e=Konva.Animation;this.batchAnim||(this.batchAnim=new e(function(){t.lastBatchDrawTime&&a()-t.lastBatchDrawTime>n&&t.batchAnim.stop()},this)),this.lastBatchDrawTime=a(),this.batchAnim.isRunning()||(this.draw(),this.batchAnim.start())},Konva.Stage.prototype.batchDraw=function(){this.getChildren().each(function(t){t.batchDraw()})}}(this),function(){var t={node:1,duration:1,easing:1,onFinish:1,yoyo:1},e=1,n=2,a=3,i=0,o=["fill","stroke","shadowColor"];Konva.Tween=function(e){var n,a,o=this,s=e.node,h=s._id,c=e.easing||Konva.Easings.Linear,l=!!e.yoyo;n="undefined"==typeof e.duration?1:0===e.duration?.001:e.duration,this.node=s,this._id=i++,this.anim=new Konva.Animation(function(){o.tween.onEnterFrame()},s.getLayer()||(s instanceof Konva.Stage?s.getLayers():null)),this.tween=new r(a,function(t){o._tweenFunc(t)},c,0,1,1e3*n,l),this._addListeners(),Konva.Tween.attrs[h]||(Konva.Tween.attrs[h]={}),Konva.Tween.attrs[h][this._id]||(Konva.Tween.attrs[h][this._id]={}),Konva.Tween.tweens[h]||(Konva.Tween.tweens[h]={});for(a in e)void 0===t[a]&&this._addAttr(a,e[a]);this.reset(),this.onFinish=e.onFinish,this.onReset=e.onReset},Konva.Tween.attrs={},Konva.Tween.tweens={},Konva.Tween.prototype={_addAttr:function(t,e){var n,a,i,r,s,h=this.node,c=h._id;if(i=Konva.Tween.tweens[c][t],i&&delete Konva.Tween.attrs[c][i][t],n=h.getAttr(t),Konva.Util._isArray(e))for(a=[],s=e.length,r=0;s>r;r++)a.push(e[r]-n[r]);else if(-1!==o.indexOf(t)){n=Konva.Util.colorToRGBA(n);var l=Konva.Util.colorToRGBA(e);a={r:l.r-n.r,g:l.g-n.g,b:l.b-n.b,a:l.a-n.a}}else a=e-n;Konva.Tween.attrs[c][this._id][t]={start:n,diff:a},Konva.Tween.tweens[c][t]=this._id},_tweenFunc:function(t){var e,n,a,i,r,s,h,c=this.node,l=Konva.Tween.attrs[c._id][this._id];for(e in l){if(n=l[e],a=n.start,i=n.diff,Konva.Util._isArray(a))for(r=[],h=a.length,s=0;h>s;s++)r.push(a[s]+i[s]*t);else r=-1!==o.indexOf(e)?"rgba("+Math.round(a.r+i.r*t)+","+Math.round(a.g+i.g*t)+","+Math.round(a.b+i.b*t)+","+Math.round(a.a+i.a*t)+")":a+i*t;c.setAttr(e,r)}},_addListeners:function(){var t=this;this.tween.onPlay=function(){t.anim.start()},this.tween.onReverse=function(){t.anim.start()},this.tween.onPause=function(){t.anim.stop()},this.tween.onFinish=function(){t.onFinish&&t.onFinish()},this.tween.onReset=function(){t.onReset&&t.onReset()}},play:function(){return this.tween.play(),this},reverse:function(){return this.tween.reverse(),this},reset:function(){return this.tween.reset(),this},seek:function(t){return this.tween.seek(1e3*t),this},pause:function(){return this.tween.pause(),this},finish:function(){return this.tween.finish(),this},destroy:function(){var t,e=this.node._id,n=this._id,a=Konva.Tween.tweens[e];this.pause();for(t in a)delete Konva.Tween.tweens[e][t];delete Konva.Tween.attrs[e][n]}},Konva.Node.prototype.to=function(t){var e=t.onFinish;t.node=this,t.onFinish=function(){n.destroy(),e&&e()};var n=new Konva.Tween(t);n.play()};var r=function(t,e,n,a,i,o,r){this.prop=t,this.propFunc=e,this.begin=a,this._pos=a,this.duration=o,this._change=0,this.prevPos=0,this.yoyo=r,this._time=0,this._position=0,this._startTime=0,this._finish=0,this.func=n,this._change=i-this.begin,this.pause()};r.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():0>t?this.yoyo?(this._time=0,this.play()):this.reset():(this._time=t,this.update())},getTime:function(){return this._time},setPosition:function(t){this.prevPos=this._pos,this.propFunc(t),this._pos=t},getPosition:function(t){return void 0===t&&(t=this._time),this.func(t,this.begin,this._change,this.duration)},play:function(){this.state=n,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire("onPlay")},reverse:function(){this.state=a,this._time=this.duration-this._time,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire("onReverse")},seek:function(t){this.pause(),this._time=t,this.update(),this.fire("onSeek")},reset:function(){this.pause(),this._time=0,this.update(),this.fire("onReset")},finish:function(){this.pause(),this._time=this.duration,this.update(),this.fire("onFinish")},update:function(){this.setPosition(this.getPosition(this._time))},onEnterFrame:function(){var t=this.getTimer()-this._startTime;this.state===n?this.setTime(t):this.state===a&&this.setTime(this.duration-t)},pause:function(){this.state=e,this.fire("onPause")},getTimer:function(){return(new Date).getTime()}},Konva.Easings={BackEaseIn:function(t,e,n,a){var i=1.70158;return n*(t/=a)*t*((i+1)*t-i)+e},BackEaseOut:function(t,e,n,a){var i=1.70158;return n*((t=t/a-1)*t*((i+1)*t+i)+1)+e},BackEaseInOut:function(t,e,n,a){var i=1.70158;return(t/=a/2)<1?n/2*t*t*(((i*=1.525)+1)*t-i)+e:n/2*((t-=2)*t*(((i*=1.525)+1)*t+i)+2)+e},ElasticEaseIn:function(t,e,n,a,i,o){var r=0;return 0===t?e:1==(t/=a)?e+n:(o||(o=.3*a),!i||it?-.5*i*Math.pow(2,10*(t-=1))*Math.sin(2*(t*a-r)*Math.PI/o)+e:i*Math.pow(2,-10*(t-=1))*Math.sin(2*(t*a-r)*Math.PI/o)*.5+n+e)},BounceEaseOut:function(t,e,n,a){return(t/=a)<1/2.75?7.5625*n*t*t+e:2/2.75>t?n*(7.5625*(t-=1.5/2.75)*t+.75)+e:2.5/2.75>t?n*(7.5625*(t-=2.25/2.75)*t+.9375)+e:n*(7.5625*(t-=2.625/2.75)*t+.984375)+e},BounceEaseIn:function(t,e,n,a){return n-Konva.Easings.BounceEaseOut(a-t,0,n,a)+e},BounceEaseInOut:function(t,e,n,a){return a/2>t?.5*Konva.Easings.BounceEaseIn(2*t,0,n,a)+e:.5*Konva.Easings.BounceEaseOut(2*t-a,0,n,a)+.5*n+e},EaseIn:function(t,e,n,a){return n*(t/=a)*t+e},EaseOut:function(t,e,n,a){return-n*(t/=a)*(t-2)+e},EaseInOut:function(t,e,n,a){return(t/=a/2)<1?n/2*t*t+e:-n/2*(--t*(t-2)-1)+e},StrongEaseIn:function(t,e,n,a){return n*(t/=a)*t*t*t*t+e},StrongEaseOut:function(t,e,n,a){return n*((t=t/a-1)*t*t*t*t+1)+e},StrongEaseInOut:function(t,e,n,a){return(t/=a/2)<1?n/2*t*t*t*t*t+e:n/2*((t-=2)*t*t*t*t+2)+e},Linear:function(t,e,n,a){return n*t/a+e}}}(),function(){Konva.DD={anim:new Konva.Animation(function(){var t=this.dirty;return this.dirty=!1,t}),isDragging:!1,justDragged:!1,offset:{x:0,y:0},node:null,_drag:function(t){var e=Konva.DD,n=e.node;if(n){if(!e.isDragging){var a=n.getStage().getPointerPosition(),i=n.dragDistance(),o=Math.max(Math.abs(a.x-e.startPointerPos.x),Math.abs(a.y-e.startPointerPos.y));if(i>o)return}n._setDragPosition(t),e.isDragging||(e.isDragging=!0,n.fire("dragstart",{type:"dragstart",target:n,evt:t},!0)),n.fire("dragmove",{type:"dragmove",target:n,evt:t},!0)}},_endDragBefore:function(t){var e,n,a=Konva.DD,i=a.node;i&&(e=i.nodeType,n=i.getLayer(),a.anim.stop(),a.isDragging&&(a.isDragging=!1,a.justDragged=!0,Konva.listenClickTap=!1,t&&(t.dragEndNode=i)),delete a.node,(n||i).draw())},_endDragAfter:function(t){t=t||{};var e=t.dragEndNode;t&&e&&e.fire("dragend",{type:"dragend",target:e,evt:t},!0)}},Konva.Node.prototype.startDrag=function(){var t=Konva.DD,e=this.getStage(),n=this.getLayer(),a=e.getPointerPosition(),i=this.getAbsolutePosition();a&&(t.node&&t.node.stopDrag(),t.node=this,t.startPointerPos=a,t.offset.x=a.x-i.x,t.offset.y=a.y-i.y,t.anim.setLayers(n||this.getLayers()),t.anim.start(),this._setDragPosition())},Konva.Node.prototype._setDragPosition=function(t){var e=Konva.DD,n=this.getStage().getPointerPosition(),a=this.getDragBoundFunc();if(n){var i={x:n.x-e.offset.x,y:n.y-e.offset.y};void 0!==a&&(i=a.call(this,i,t)),this.setAbsolutePosition(i),this._lastPos&&this._lastPos.x===i.x&&this._lastPos.y===i.y||(e.anim.dirty=!0),this._lastPos=i}},Konva.Node.prototype.stopDrag=function(){var t=Konva.DD,e={};t._endDragBefore(e),t._endDragAfter(e)},Konva.Node.prototype.setDraggable=function(t){this._setAttr("draggable",t),this._dragChange()};var t=Konva.Node.prototype.destroy;Konva.Node.prototype.destroy=function(){var e=Konva.DD;e.node&&e.node._id===this._id&&this.stopDrag(),t.call(this)},Konva.Node.prototype.isDragging=function(){var t=Konva.DD;return!(!t.node||t.node._id!==this._id||!t.isDragging)},Konva.Node.prototype._listenDrag=function(){var t=this;this._dragCleanup(),"Stage"===this.getClassName()?this.on("contentMousedown.konva contentTouchstart.konva",function(e){Konva.DD.node||t.startDrag(e)}):this.on("mousedown.konva touchstart.konva",function(e){1!==e.evt.button&&2!==e.evt.button&&(Konva.DD.node||t.startDrag(e))})},Konva.Node.prototype._dragChange=function(){if(this.attrs.draggable)this._listenDrag();else{this._dragCleanup();var t=this.getStage(),e=Konva.DD;t&&e.node&&e.node._id===this._id&&e.node.stopDrag()}},Konva.Node.prototype._dragCleanup=function(){"Stage"===this.getClassName()?(this.off("contentMousedown.konva"),this.off("contentTouchstart.konva")):(this.off("mousedown.konva"),this.off("touchstart.konva"))},Konva.Factory.addGetterSetter(Konva.Node,"dragBoundFunc"),Konva.Factory.addGetter(Konva.Node,"draggable",!1),Konva.Factory.addOverloadedGetterSetter(Konva.Node,"draggable");var e=Konva.document.documentElement;e.addEventListener("mouseup",Konva.DD._endDragBefore,!0),e.addEventListener("touchend",Konva.DD._endDragBefore,!0),e.addEventListener("mouseup",Konva.DD._endDragAfter,!1),e.addEventListener("touchend",Konva.DD._endDragAfter,!1)}(),function(){Konva.Rect=function(t){this.___init(t)},Konva.Rect.prototype={___init:function(t){Konva.Shape.call(this,t),this.className="Rect",this.sceneFunc(this._sceneFunc)},_sceneFunc:function(t){var e=this.getCornerRadius(),n=this.getWidth(),a=this.getHeight();t.beginPath(),e?(e=Math.min(e,n/2,a/2),t.moveTo(e,0),t.lineTo(n-e,0),t.arc(n-e,e,e,3*Math.PI/2,0,!1),t.lineTo(n,a-e),t.arc(n-e,a-e,e,0,Math.PI/2,!1),t.lineTo(e,a),t.arc(e,a-e,e,Math.PI/2,Math.PI,!1),t.lineTo(0,e),t.arc(e,e,e,Math.PI,3*Math.PI/2,!1)):t.rect(0,0,n,a),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(){var t=2*Math.PI-1e-4,e="Circle";Konva.Circle=function(t){this.___init(t)},Konva.Circle.prototype={_centroid:!0,___init:function(t){Konva.Shape.call(this,t),this.className=e,this.sceneFunc(this._sceneFunc)},_sceneFunc:function(e){e.beginPath(),e.arc(0,0,this.getRadius(),0,t,!1),e.closePath(),e.fillStrokeShape(this)},getWidth:function(){return 2*this.getRadius()},getHeight:function(){return 2*this.getRadius()},setWidth:function(t){Konva.Node.prototype.setWidth.call(this,t),this.radius()!==t/2&&this.setRadius(t/2)},setHeight:function(t){Konva.Node.prototype.setHeight.call(this,t),this.radius()!==t/2&&this.setRadius(t/2)}},Konva.Util.extend(Konva.Circle,Konva.Shape),Konva.Factory.addGetterSetter(Konva.Circle,"radius",0),Konva.Factory.addOverloadedGetterSetter(Konva.Circle,"radius"),Konva.Collection.mapMethods(Konva.Circle)}(),function(){var t=2*Math.PI-1e-4,e="Ellipse";Konva.Ellipse=function(t){this.___init(t)},Konva.Ellipse.prototype={_centroid:!0,___init:function(t){Konva.Shape.call(this,t),this.className=e,this.sceneFunc(this._sceneFunc)},_sceneFunc:function(e){var n=this.getRadiusX(),a=this.getRadiusY();e.beginPath(),e.save(),n!==a&&e.scale(1,a/n),e.arc(0,0,n,0,t,!1),e.restore(),e.closePath(),e.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(){var t=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(e){e.beginPath(),e.arc(0,0,this.getInnerRadius(),0,t,!1),e.moveTo(this.getOuterRadius(),0),e.arc(0,0,this.getOuterRadius(),t,0,!0),e.closePath(),e.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(){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(){Konva.Arc=function(t){this.___init(t)},Konva.Arc.prototype={_centroid:!0,___init:function(t){Konva.Shape.call(this,t),this.className="Arc",this.sceneFunc(this._sceneFunc)},_sceneFunc:function(t){var e=Konva.getAngle(this.angle()),n=this.clockwise();t.beginPath(),t.arc(0,0,this.getOuterRadius(),0,e,n),t.arc(0,0,this.getInnerRadius(),e,0,!n),t.closePath(),t.fillStrokeShape(this)},getWidth:function(){return 2*this.getOuterRadius()},getHeight:function(){return 2*this.getOuterRadius()},setWidth:function(t){Konva.Node.prototype.setWidth.call(this,t),this.getOuterRadius()!==t/2&&this.setOuterRadius(t/2)},setHeight:function(t){Konva.Node.prototype.setHeight.call(this,t),this.getOuterRadius()!==t/2&&this.setOuterRadius(t/2)}},Konva.Util.extend(Konva.Arc,Konva.Shape),Konva.Factory.addGetterSetter(Konva.Arc,"innerRadius",0),Konva.Factory.addGetterSetter(Konva.Arc,"outerRadius",0),Konva.Factory.addGetterSetter(Konva.Arc,"angle",0),Konva.Factory.addGetterSetter(Konva.Arc,"clockwise",!1),Konva.Collection.mapMethods(Konva.Arc)}(),function(){var t="Image";Konva.Image=function(t){this.___init(t)},Konva.Image.prototype={___init:function(e){Konva.Shape.call(this,e),this.className=t,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,n,a,i=this.getWidth(),o=this.getHeight(),r=this.getImage();r&&(e=this.getCropWidth(),n=this.getCropHeight(),a=e&&n?[r,this.getCropX(),this.getCropY(),e,n,0,0,i,o]:[r,0,0,i,o]),(this.hasFill()||this.hasStroke())&&(t.beginPath(),t.rect(0,0,i,o),t.closePath(),t.fillStrokeShape(this)),r&&t.drawImage.apply(t,a)},_hitFunc:function(t){var e=this.getWidth(),n=this.getHeight();t.beginPath(),t.rect(0,0,e,n),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)}(),function(){function t(t){t.fillText(this.partialText,0,0)}function e(t){t.strokeText(this.partialText,0,0)}var n="auto",a="center",i="Change.konva",o="2d",r="-",s="",h="left",c="text",l="Text",d="middle",v="normal",u="px ",f=" ",g="right",p="word",K="char",m="none",_=["fontFamily","fontSize","fontStyle","fontVariant","padding","align","lineHeight","text","width","height","wrap"],y=_.length,S=Konva.Util.createCanvasElement().getContext(o);Konva.Text=function(t){this.___init(t)},Konva.Text.prototype={___init:function(a){a=a||{},a.fill=a.fill||"black",void 0===a.width&&(a.width=n),void 0===a.height&&(a.height=n),Konva.Shape.call(this,a),this._fillFunc=t,this._strokeFunc=e,this.className=l;for(var o=0;y>o;o++)this.on(_[o]+i,this._setTextData);this._setTextData(),this.sceneFunc(this._sceneFunc),this.hitFunc(this._hitFunc)},_sceneFunc:function(t){var e,n=this.getPadding(),i=this.getTextHeight(),o=this.getLineHeight()*i,r=this.textArr,s=r.length,c=this.getWidth();for(t.setAttr("font",this._getContextFont()),t.setAttr("textBaseline",d),t.setAttr("textAlign",h),t.save(),n?(t.translate(n,0),t.translate(0,n+i/2)):t.translate(0,i/2),e=0;s>e;e++){var l=r[e],v=l.text,u=l.width;t.save(),this.getAlign()===g?t.translate(c-u-2*n,0):this.getAlign()===a&&t.translate((c-u-2*n)/2,0),this.partialText=v,t.fillStrokeShape(this),t.restore(),t.translate(0,o)}t.restore()},_hitFunc:function(t){var e=this.getWidth(),n=this.getHeight();t.beginPath(),t.rect(0,0,e,n),t.closePath(),t.fillStrokeShape(this)},setText:function(t){var e=Konva.Util._isString(t)?t:t.toString();return this._setAttr(c,e),this},getWidth:function(){return this.attrs.width===n?this.getTextWidth()+2*this.getPadding():this.attrs.width},getHeight:function(){return this.attrs.height===n?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,n=S,a=this.getFontSize();return n.save(),n.font=this._getContextFont(),e=n.measureText(t),n.restore(),{width:e.width,height:parseInt(a,10)}},_getContextFont:function(){return this.getFontStyle()+f+this.getFontVariant()+f+this.getFontSize()+u+this.getFontFamily()},_addTextLine:function(t,e){return this.textArr.push({text:t,width:e})},_getTextWidth:function(t){return S.measureText(t).width},_setTextData:function(){var t=this.getText().split("\n"),e=+this.getFontSize(),a=0,i=this.getLineHeight()*e,o=this.attrs.width,s=this.attrs.height,h=o!==n,c=s!==n,l=this.getPadding(),d=o-2*l,v=s-2*l,u=0,g=this.getWrap(),p=g!==m,_=g!==K&&p;this.textArr=[],S.save(),S.font=this._getContextFont();for(var y=0,C=t.length;C>y;++y){var x=t[y],w=this._getTextWidth(x);if(h&&w>d)for(;x.length>0;){for(var b=0,F=x.length,T="",P=0;F>b;){var A=b+F>>>1,k=x.slice(0,A+1),M=this._getTextWidth(k);d>=M?(b=A+1,T=k,P=M):F=A}if(!T)break;if(_){var G=Math.max(T.lastIndexOf(f),T.lastIndexOf(r))+1;G>0&&(b=G,T=T.slice(0,b),P=this._getTextWidth(T))}if(this._addTextLine(T,P),a=Math.max(a,P),u+=i,!p||c&&u+i>v)break;if(x=x.slice(b),x.length>0&&(w=this._getTextWidth(x),d>=w)){this._addTextLine(x,w),u+=i,a=Math.max(a,w);break}}else this._addTextLine(x,w),u+=i,a=Math.max(a,w);if(c&&u+i>v)break}S.restore(),this.textHeight=e,this.textWidth=a}},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",v),Konva.Factory.addGetterSetter(Konva.Text,"fontVariant",v),Konva.Factory.addGetterSetter(Konva.Text,"padding",0),Konva.Factory.addGetterSetter(Konva.Text,"align",h),Konva.Factory.addGetterSetter(Konva.Text,"lineHeight",1),Konva.Factory.addGetterSetter(Konva.Text,"wrap",p),Konva.Factory.addGetter(Konva.Text,"text",s),Konva.Factory.addOverloadedGetterSetter(Konva.Text,"text"),Konva.Collection.mapMethods(Konva.Text)}(),function(){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",function(){this._clearCache("tensionPoints")}),this.sceneFunc(this._sceneFunc)},_sceneFunc:function(t){var e,n,a,i=this.getPoints(),o=i.length,r=this.getTension(),s=this.getClosed();if(o){if(t.beginPath(),t.moveTo(i[0],i[1]),0!==r&&o>4){for(e=this.getTensionPoints(),n=e.length,a=s?0:4,s||t.quadraticCurveTo(e[0],e[1],e[2],e[3]);n-2>a;)t.bezierCurveTo(e[a++],e[a++],e[a++],e[a++],e[a++],e[a++]);s||t.quadraticCurveTo(e[n-2],e[n-1],i[o-2],i[o-1])}else for(a=2;o>a;a+=2)t.lineTo(i[a],i[a+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,n=this.getTension(),a=Konva.Util,i=a._getControlPoints(t[e-2],t[e-1],t[0],t[1],t[2],t[3],n),o=a._getControlPoints(t[e-4],t[e-3],t[e-2],t[e-1],t[0],t[1],n),r=Konva.Util._expandPoints(t,n),s=[i[2],i[3]].concat(r).concat([o[0],o[1],t[e-2],t[e-1],o[2],o[3],i[0],i[1],t[0],t[1]]);return s},getWidth:function(){return this.getSelfRect().width},getHeight:function(){return this.getSelfRect().height},getSelfRect:function(){var t;t=0!==this.getTension()?this._getTensionPoints():this.getPoints();for(var e,n,a=t[0],i=t[0],o=t[0],r=t[0],s=0;st?t+1: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(){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,n=!1;t.beginPath();for(var a=0;ac?h:c,g=h>c?1:h/c,p=h>c?c/h:1;t.translate(r,s),t.rotate(v),t.scale(g,p),t.arc(0,0,f,l,l+d,1-u),t.scale(1/g,1/p),t.rotate(-v),t.translate(-r,-s);break;case"z":t.closePath(),n=!0}}n?t.fillStrokeShape(this):t.strokeShape(this)},getSelfRect:function(){var t=[];this.dataArray.forEach(function(e){t=t.concat(e.points)});for(var e,n,a=t[0],i=t[0],o=t[0],r=t[0],s=0;sa&&(h*=-1);var c,l=s*h;if(a===e)c={x:o,y:r+l};else if((r-n)/(o-e+1e-8)===s)c={x:o+h,y:r+l};else{var d,v,u=this.getLineLength(e,n,a,i);if(1e-8>u)return void 0;var f=(o-e)*(a-e)+(r-n)*(i-n);f/=u*u,d=e+f*(a-e),v=n+f*(i-n);var g=this.getLineLength(o,r,d,v),p=Math.sqrt(t*t-g*g);h=Math.sqrt(p*p/(1+s*s)),e>a&&(h*=-1),l=s*h,c={x:d+h,y:v+l}}return c},Konva.Path.getPointOnCubicBezier=function(t,e,n,a,i,o,r,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 v(t){return(1-t)*(1-t)*(1-t)}var u=s*c(t)+o*l(t)+a*d(t)+e*v(t),f=h*c(t)+r*l(t)+i*d(t)+n*v(t);return{x:u,y:f}},Konva.Path.getPointOnQuadraticBezier=function(t,e,n,a,i,o,r){function s(t){return t*t}function h(t){return 2*t*(1-t)}function c(t){return(1-t)*(1-t)}var l=o*s(t)+a*h(t)+e*c(t),d=r*s(t)+i*h(t)+n*c(t);return{x:l,y:d}},Konva.Path.getPointOnEllipticalArc=function(t,e,n,a,i,o){var r=Math.cos(o),s=Math.sin(o),h={x:n*Math.cos(i),y:a*Math.sin(i)};return{x:t+(h.x*r-h.y*s),y:e+(h.x*s+h.y*r)}},Konva.Path.parsePathData=function(t){if(!t)return[];var e=t,n=["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 a=0;a0&&""===l[0]&&l.shift();for(var d=0;d0&&!isNaN(l[0]);){var v,u,f,g,p,K,m,_,y,S,C=null,x=[],w=r,b=s;switch(c){case"l":r+=l.shift(),s+=l.shift(),C="L",x.push(r,s);break;case"L":r=l.shift(),s=l.shift(),x.push(r,s);break;case"m":var F=l.shift(),T=l.shift();if(r+=F,s+=T,C="M",o.length>2&&"z"===o[o.length-1].command)for(var P=o.length-2;P>=0;P--)if("M"===o[P].command){r=o[P].points[0]+F,s=o[P].points[1]+T;break}x.push(r,s),c="l";break;case"M":r=l.shift(),s=l.shift(),C="M",x.push(r,s),c="L";break;case"h":r+=l.shift(),C="L",x.push(r,s);break;case"H":r=l.shift(),C="L",x.push(r,s);break;case"v":s+=l.shift(),C="L",x.push(r,s);break;case"V":s=l.shift(),C="L",x.push(r,s);break;case"C":x.push(l.shift(),l.shift(),l.shift(),l.shift()),r=l.shift(),s=l.shift(),x.push(r,s);break;case"c":x.push(r+l.shift(),s+l.shift(),r+l.shift(),s+l.shift()),r+=l.shift(),s+=l.shift(),C="C",x.push(r,s);break;case"S":u=r,f=s,v=o[o.length-1],"C"===v.command&&(u=r+(r-v.points[2]),f=s+(s-v.points[3])),x.push(u,f,l.shift(),l.shift()),r=l.shift(),s=l.shift(),C="C",x.push(r,s); +break;case"s":u=r,f=s,v=o[o.length-1],"C"===v.command&&(u=r+(r-v.points[2]),f=s+(s-v.points[3])),x.push(u,f,r+l.shift(),s+l.shift()),r+=l.shift(),s+=l.shift(),C="C",x.push(r,s);break;case"Q":x.push(l.shift(),l.shift()),r=l.shift(),s=l.shift(),x.push(r,s);break;case"q":x.push(r+l.shift(),s+l.shift()),r+=l.shift(),s+=l.shift(),C="Q",x.push(r,s);break;case"T":u=r,f=s,v=o[o.length-1],"Q"===v.command&&(u=r+(r-v.points[0]),f=s+(s-v.points[1])),r=l.shift(),s=l.shift(),C="Q",x.push(u,f,r,s);break;case"t":u=r,f=s,v=o[o.length-1],"Q"===v.command&&(u=r+(r-v.points[0]),f=s+(s-v.points[1])),r+=l.shift(),s+=l.shift(),C="Q",x.push(u,f,r,s);break;case"A":g=l.shift(),p=l.shift(),K=l.shift(),m=l.shift(),_=l.shift(),y=r,S=s,r=l.shift(),s=l.shift(),C="A",x=this.convertEndpointToCenterParameterization(y,S,r,s,m,_,g,p,K);break;case"a":g=l.shift(),p=l.shift(),K=l.shift(),m=l.shift(),_=l.shift(),y=r,S=s,r+=l.shift(),s+=l.shift(),C="A",x=this.convertEndpointToCenterParameterization(y,S,r,s,m,_,g,p,K)}o.push({command:C||c,points:x,start:{x:w,y:b},pathLength:this.calcLength(w,b,C||c,x)})}("z"===c||"Z"===c)&&o.push({command:"z",points:[],start:void 0,pathLength:0})}return o},Konva.Path.calcLength=function(t,e,n,a){var i,o,r,s,h=Konva.Path;switch(n){case"L":return h.getLineLength(t,e,a[0],a[1]);case"C":for(i=0,o=h.getPointOnCubicBezier(0,t,e,a[0],a[1],a[2],a[3],a[4],a[5]),s=.01;1>=s;s+=.01)r=h.getPointOnCubicBezier(s,t,e,a[0],a[1],a[2],a[3],a[4],a[5]),i+=h.getLineLength(o.x,o.y,r.x,r.y),o=r;return i;case"Q":for(i=0,o=h.getPointOnQuadraticBezier(0,t,e,a[0],a[1],a[2],a[3]),s=.01;1>=s;s+=.01)r=h.getPointOnQuadraticBezier(s,t,e,a[0],a[1],a[2],a[3]),i+=h.getLineLength(o.x,o.y,r.x,r.y),o=r;return i;case"A":i=0;var c=a[4],l=a[5],d=a[4]+l,v=Math.PI/180;if(Math.abs(c-d)l)for(s=c-v;s>d;s-=v)r=h.getPointOnEllipticalArc(a[0],a[1],a[2],a[3],s,0),i+=h.getLineLength(o.x,o.y,r.x,r.y),o=r;else for(s=c+v;d>s;s+=v)r=h.getPointOnEllipticalArc(a[0],a[1],a[2],a[3],s,0),i+=h.getLineLength(o.x,o.y,r.x,r.y),o=r;return r=h.getPointOnEllipticalArc(a[0],a[1],a[2],a[3],d,0),i+=h.getLineLength(o.x,o.y,r.x,r.y)}return 0},Konva.Path.convertEndpointToCenterParameterization=function(t,e,n,a,i,o,r,s,h){var c=h*(Math.PI/180),l=Math.cos(c)*(t-n)/2+Math.sin(c)*(e-a)/2,d=-1*Math.sin(c)*(t-n)/2+Math.cos(c)*(e-a)/2,v=l*l/(r*r)+d*d/(s*s);v>1&&(r*=Math.sqrt(v),s*=Math.sqrt(v));var u=Math.sqrt((r*r*s*s-r*r*d*d-s*s*l*l)/(r*r*d*d+s*s*l*l));i===o&&(u*=-1),isNaN(u)&&(u=0);var f=u*r*d/s,g=u*-s*l/r,p=(t+n)/2+Math.cos(c)*f-Math.sin(c)*g,K=(e+a)/2+Math.sin(c)*f+Math.cos(c)*g,m=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])/(m(t)*m(e))},y=function(t,e){return(t[0]*e[1]=1&&(w=0),0===o&&w>0&&(w-=2*Math.PI),1===o&&0>w&&(w+=2*Math.PI),[p,K,r,s,S,w,c,o]},Konva.Factory.addGetterSetter(Konva.Path,"data"),Konva.Collection.mapMethods(Konva.Path)}(),function(){function t(t){t.fillText(this.partialText,0,0)}function e(t){t.strokeText(this.partialText,0,0)}var n="",a="normal";Konva.TextPath=function(t){this.___init(t)},Konva.TextPath.prototype={___init:function(n){var a=this;this.dummyCanvas=Konva.Util.createCanvasElement(),this.dataArray=[],Konva.Shape.call(this,n),this._fillFunc=t,this._strokeFunc=e,this._fillFuncHit=t,this._strokeFuncHit=e,this.className="TextPath",this.dataArray=Konva.Path.parsePathData(this.attrs.data),this.on("dataChange.konva",function(){a.dataArray=Konva.Path.parsePathData(this.attrs.data)}),this.on("textChange.konva textStroke.konva textStrokeWidth.konva",a._setTextData),a._setTextData(),this.sceneFunc(this._sceneFunc)},_sceneFunc:function(t){t.setAttr("font",this._getContextFont()),t.setAttr("textBaseline","middle"),t.setAttr("textAlign","left"),t.save();for(var e=this.glyphInfo,n=0;n0)return r=a,e[a];"M"==e[a].command&&(n={x:e[a].points[0],y:e[a].points[1]})}return{}},c=function(e){var o=t._getTextSize(e).width,r=0,c=0;for(a=void 0;Math.abs(o-r)/o>.01&&25>c;){c++;for(var l=r;void 0===i;)i=h(),i&&l+i.pathLengtho?a=Konva.Path.getPointOnLine(o,n.x,n.y,i.points[0],i.points[1],n.x,n.y):i=void 0;break;case"A":var v=i.points[4],u=i.points[5],f=i.points[4]+u;0===s?s=v+1e-8:o>r?s+=Math.PI/180*u/Math.abs(u):s-=Math.PI/360*u/Math.abs(u),(0>u&&f>s||u>=0&&s>f)&&(s=f,d=!0),a=Konva.Path.getPointOnEllipticalArc(i.points[0],i.points[1],i.points[2],i.points[3],s,i.points[6]);break;case"C":0===s?s=o>i.pathLength?1e-8:o/i.pathLength:o>r?s+=(o-r)/i.pathLength:s-=(r-o)/i.pathLength,s>1&&(s=1,d=!0),a=Konva.Path.getPointOnCubicBezier(s,i.start.x,i.start.y,i.points[0],i.points[1],i.points[2],i.points[3],i.points[4],i.points[5]);break;case"Q":0===s?s=o/i.pathLength:o>r?s+=(o-r)/i.pathLength:s-=(r-o)/i.pathLength,s>1&&(s=1,d=!0),a=Konva.Path.getPointOnQuadraticBezier(s,i.start.x,i.start.y,i.points[0],i.points[1],i.points[2],i.points[3])}void 0!==a&&(r=Konva.Path.getLineLength(n.x,n.y,a.x,a.y)),d&&(d=!1,i=void 0)}},l=0;le;e++)n=o*Math.sin(2*e*Math.PI/i),a=-1*o*Math.cos(2*e*Math.PI/i),t.lineTo(n,a);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(){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(),n=this.outerRadius(),a=this.numPoints();t.beginPath(),t.moveTo(0,0-n);for(var i=1;2*a>i;i++){var o=i%2===0?n:e,r=o*Math.sin(i*Math.PI/a),s=-1*o*Math.cos(i*Math.PI/a);t.lineTo(r,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(){var t=["fontFamily","fontSize","fontStyle","padding","lineHeight","text"],e="Change.konva",n="none",a="up",i="right",o="down",r="left",s="Label",h=t.length;Konva.Label=function(t){this.____init(t)},Konva.Label.prototype={____init:function(t){var e=this;Konva.Group.call(this,t),this.className=s,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(n){var a,i=this,o=function(){i._sync()};for(a=0;h>a;a++)n.on(t[a]+e,o)},getWidth:function(){return this.getText().getWidth()},getHeight:function(){return this.getText().getHeight()},_sync:function(){var t,e,n,s,h,c,l,d=this.getText(),v=this.getTag();if(d&&v){switch(t=d.getWidth(),e=d.getHeight(),n=v.getPointerDirection(),s=v.getPointerWidth(),l=v.getPointerHeight(),h=0,c=0,n){case a:h=t/2,c=-1*l;break;case i:h=t+s,c=e/2;break;case o:h=t/2,c=e+l;break;case r:h=-1*s,c=e/2}v.setAttrs({x:-1*h,y:-1*c,width:t,height:e}),d.setAttrs({x:-1*h,y:-1*c})}}},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(),n=this.getHeight(),s=this.getPointerDirection(),h=this.getPointerWidth(),c=this.getPointerHeight(),l=this.getCornerRadius();t.beginPath(),t.moveTo(0,0),s===a&&(t.lineTo((e-h)/2,0),t.lineTo(e/2,-1*c),t.lineTo((e+h)/2,0)),l?(t.lineTo(e-l,0),t.arc(e-l,l,l,3*Math.PI/2,0,!1)):t.lineTo(e,0),s===i&&(t.lineTo(e,(n-c)/2),t.lineTo(e+h,n/2),t.lineTo(e,(n+c)/2)),l?(t.lineTo(e,n-l),t.arc(e-l,n-l,l,0,Math.PI/2,!1)):t.lineTo(e,n),s===o&&(t.lineTo((e+h)/2,n),t.lineTo(e/2,n+c),t.lineTo((e-h)/2,n)),l?(t.lineTo(l,n),t.arc(l,n-l,l,Math.PI/2,Math.PI,!1)):t.lineTo(0,n),s===r&&(t.lineTo(0,(n+c)/2),t.lineTo(-1*h,n/2),t.lineTo(0,(n-c)/2)),l&&(t.lineTo(0,l),t.arc(l,l,l,Math.PI,3*Math.PI/2,!1)),t.closePath(),t.fillStrokeShape(this)},getSelfRect:function(){var t=0,e=0,n=this.getPointerWidth(),s=this.getPointerHeight(),h=this.pointerDirection(),c=this.getWidth(),l=this.getHeight();return h===a?(e-=s,l+=s):h===o?l+=s:h===r?(t-=1.5*n,c+=n):h===i&&(c+=1.5*n),{x:t,y:e,width:c,height:l}}},Konva.Util.extend(Konva.Tag,Konva.Shape),Konva.Factory.addGetterSetter(Konva.Tag,"pointerDirection",n),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(){Konva.Arrow=function(t){this.____init(t)},Konva.Arrow.prototype={____init:function(t){Konva.Line.call(this,t),this.className="Arrow"},_sceneFunc:function(t){var e=2*Math.PI,n=this.points(),a=n.length,i=n[a-2]-n[a-4],o=n[a-1]-n[a-3],r=(Math.atan2(o,i)+e)%e,s=this.pointerLength(),h=this.pointerWidth();t.save(),t.beginPath(),t.translate(n[a-2],n[a-1]),t.rotate(r),t.moveTo(0,0),t.lineTo(-s,h/2),t.lineTo(-s,-h/2),t.closePath(),t.restore(),this.pointerAtBeginning()&&(t.save(),t.translate(n[0],n[1]),i=n[2]-n[0],o=n[3]-n[1],t.rotate((Math.atan2(-o,-i)+e)%e),t.moveTo(0,0),t.lineTo(-10,6),t.lineTo(-10,-6),t.closePath(),t.restore()),t.fillStrokeShape(this),Konva.Line.prototype._sceneFunc.apply(this,arguments)}},Konva.Util.extend(Konva.Arrow,Konva.Line),Konva.Factory.addGetterSetter(Konva.Arrow,"pointerLength",10),Konva.Factory.addGetterSetter(Konva.Arrow,"pointerWidth",10),Konva.Factory.addGetterSetter(Konva.Arrow,"pointerAtBeginning",!1),Konva.Collection.mapMethods(Konva.Arrow)}(); \ No newline at end of file diff --git a/src/Container.js b/src/Container.js index 153f915f..1b5ce601 100644 --- a/src/Container.js +++ b/src/Container.js @@ -399,10 +399,18 @@ var minX, minY, maxX, maxY; this.children.each(function(child) { var rect = child.getClientRect(); - minX = Math.min(minX, rect.x) || rect.x; - minY = Math.min(minY, rect.y) || rect.y; - maxX = Math.max(maxX, rect.x + rect.width) || (rect.x + rect.width); - maxY = Math.max(maxY, rect.y + rect.height) || (rect.y + rect.height); + if (minX === undefined) { // initial value for first child + minX = rect.x; + minY = rect.y; + maxX = rect.x + rect.width; + maxY = rect.y + rect.height; + } else { + minX = Math.min(minX, rect.x); + minY = Math.min(minY, rect.y); + maxX = Math.max(maxX, rect.x + rect.width); + maxY = Math.max(maxY, rect.y + rect.height); + } + }); var rect = { diff --git a/test/unit/Node-cache-test.js b/test/unit/Node-cache-test.js index a3c83275..2c5ce94e 100644 --- a/test/unit/Node-cache-test.js +++ b/test/unit/Node-cache-test.js @@ -480,6 +480,41 @@ suite('Caching', function() { compareLayerAndCanvas(layer, canvas, 150); }); + test('cache group with rectangle and text', function() { + var stage = addStage(); + + var layer = new Konva.Layer(); + + var button = new Konva.Group({ + width: 100, + height: 50, + draggable: true + }); + + var face = new Konva.Rect({ + fill: 'red', + x: 0, y: 0, + width: 100, + height: 50 + }); + + var text = new Konva.Text({ + text: 'Wrong button', + x: 15, + y: 20 + }); + + button.add(face); + button.add(text); + + button.cache(); + + layer.add(button); + stage.add(layer); + + cloneAndCompareLayer(layer, 100); + }); + test('cache layer with several shape with transform', function() { var stage = addStage();