konva/konva.min.js

46 lines
129 KiB
JavaScript
Raw Normal View History

2015-04-07 16:03:08 +08:00
/*
* Konva JavaScript Framework v0.9.5
* http://konvajs.github.io/
* Licensed under the MIT or GPL Version 2 licenses.
* Date: Thu Apr 16 2015
2015-04-07 16:03:08 +08:00
*
* Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS)
* Modified work Copyright (C) 2014 - 2015 by Anton Lavrenov (Konva)
*
* @license
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
2015-04-14 11:50:09 +08:00
var Konva={};!function(t){var e=Math.PI/180;Konva={version:"0.9.5",stages:[],idCounter:0,ids:{},names:{},shapes:{},listenClickTap:!1,inDblClickWindow:!1,enableTrace:!1,traceArrMax:100,dblClickWindow:400,pixelRatio:void 0,dragDistance:0,angleDeg:!0,showWarnings:!0,Filters:{},isDragging:function(){var t=Konva.DD;return t?t.isDragging:!1},isDragReady:function(){var t=Konva.DD;return t?!!t.node:!1},_addId:function(t,e){void 0!==e&&(this.ids[e]=t)},_removeId:function(t){void 0!==t&&delete this.ids[t]},_addName:function(t,e){e&&(this.names[e]||(this.names[e]=[]),this.names[e].push(t))},_removeName:function(t,e){if(void 0!==t){var n=this.names[t];if(void 0!==n){for(var a=0;a<n.length;a++){var i=n[a];i._id===e&&n.splice(a,1)}0===n.length&&delete this.names[t]}}},getAngle:function(t){return this.angleDeg?t*e:t},_parseUA:function(t){var e=t.toLowerCase(),n=/(chrome)[ \/]([\w.]+)/.exec(e)||/(webkit)[ \/]([\w.]+)/.exec(e)||/(opera)(?:.*version|)[ \/]([\w.]+)/.exec(e)||/(msie) ([\w.]+)/.exec(e)||e.indexOf("compatible")<0&&/(mozilla)(?:.*? rv:([\w.]+)|)/.exec(e)||[],a=!!t.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i),i=!!t.match(/IEMobile/i);return{browser:n[1]||"",version:n[2]||"0",mobile:a,ieMobile:i}},UA:void 0},Konva.UA=Konva._parseUA(t.navigator&&t.navigator.userAgent||"")}(this),function(t,e){if("object"==typeof exports){var n=e();if(global.window&&global.window.document)Konva.document=global.window.document,Konva.window=global.window;else{var a=require("canvas"),i=require("jsdom").jsdom;Konva.document=i("<!DOCTYPE html><html><head></head><body></body></html>"),Konva.window=Konva.document.parentWindow,Konva.window.Image=a.Image,Konva._nodeCanvas=a}return Konva.root=t,void(module.exports=n)}"function"==typeof define&&define.amd&&define(e),Konva.document=document,Konva.window=window,Konva.root=t}(this,function(){return Konva}),function(){Konva.Collection=function(){var t=[].slice.call(arguments),e=t.length,n=0;for(this.length=e;e>n;n++)this[n]=t[n];return this},Konva.Collection.prototype=[],Konva.Collection.prototype.each=function(t){for(var e=0;e<this.length;e++)t(this[e],e)},Konva.Collection.prototype.toArray=function(){var t,e=[],n=this.length;for(t=0;n>t;t++)e.push(this[t]);return e},Konva.Collection.toCollection=function(t){var e,n=new Konva.Collection,a=t.length;for(e=0;a>e;e++)n.push(t[e]);return n},Konva.Collection._mapMethod=function(t){Konva.Collection.prototype[t]=function(){var e,n=this.length,a=[].slice.call(arguments);for(e=0;n>e;e++)this[e][t].apply(this[e],a);return this}},Konva.Collection.mapMethods=function(t){var e=t.prototype;for(var n in e)Konva.Collection._mapMethod(n)},Konva.Transform=function(t){this.m=t&&t.slice()||[1,0,0,1,0,0]},Konva.Transform.prototype={copy:function(){return new Konva.Transform(this.m)},point:function(t){var e=this.m;return{x:e[0]*t.x+e[2]*t.y+e[4],y:e[1]*t.x+e[3]*t.y+e[5]}},translate:function(t,e){return this.m[4]+=this.m[0]*t+this.m[2]*e,this.m[5]+=this.m[1]*t+this.m[3]*e,this},scale:function(t,e){return this.m[0]*=t,this.m[1]*=t,this.m[2]*=e,this.m[3]*=e,this},rotate:function(t){var e=Math.cos(t),n=Math.sin(t),a=this.m[0]*e+this.m[2]*n,i=this.m[1]*e+this.m[3]*n,o=this.m[0]*-n+this.m[2]*e,r=this.m[1]*-n+this.m[3]*e;return this.m[0]=a,this.m[1]=i,this.m[2]=o,this.m[3]=r,this},getTranslation:function(){return{x:this.m[4],y:this.m[5]}},skew:function(t,e){var n=this.m[0]+this.m[2]*e,a=this.m[1]+this.m[3]*e,i=this.m[2]+this.m[0]*t,o=this.m[3]+this.m[1]*t;return this.m[0]=n,this.m[1]=a,this.m[2]=i,this.m[3]=o,this},multiply:function(t){var e=this.m[0]*t.m[0]+this.m[2]*t.m[1],n=this.m[1]*t.m[0]+this.m[3]*t.m[1],a=this.m[0]*t.m[2]+this.m[2]*t.m[3],i=this.m[1]*t.m[2]+this.m[3]*t.m[3],o=this.m[0]*t.m[4]+this.m[2]*t.m[5]+this.m[4],r=this.m[1]*t.m[4]+this.m[3]*t.m[5]+this.m[5];return this.m[0]=e,this.m[1]=n,this.m[2]=a,this.m[3]=i,this.m[4]=o,this.m[5]=r,this},invert:function(){var t=1/(this.m[0]*this.m[3]-this.m[1]*this.m[2]),e=this.m[3]*t,n=-this.m[1]*t,a=-this.m[2]*t,i=this.m[0]*t,o=t*(this.m[2]*this.m[5]-this.m[3]*this.m[4]),r=t*(this.m[1]*this.m[4]-this.m[0]*this.m[5]);
return void 0!==e&&(a+=e),void 0!==n&&(i+=n),this.setPosition({x:a,y:i}),this},_eachAncestorReverse:function(t,e){var n,a,i=[],o=this.getParent();if(e&&e._id===this._id)return t(this),!0;for(i.unshift(this);o&&(!e||o._id!==e._id);)i.unshift(o),o=o.parent;for(n=i.length,a=0;n>a;a++)t(i[a])},rotate:function(t){return this.setRotation(this.getRotation()+t),this},moveToTop:function(){if(!this.parent)return void Konva.Util.warn("Node has no parent. moveToTop function is ignored.");var t=this.index;return this.parent.children.splice(t,1),this.parent.children.push(this),this.parent._setChildrenIndices(),!0},moveUp:function(){if(!this.parent)return void Konva.Util.warn("Node has no parent. moveUp function is ignored.");var t=this.index,e=this.parent.getChildren().length;return e-1>t?(this.parent.children.splice(t,1),this.parent.children.splice(t+1,0,this),this.parent._setChildrenIndices(),!0):!1},moveDown:function(){if(!this.parent)return void Konva.Util.warn("Node has no parent. moveDown function is ignored.");var t=this.index;return t>0?(this.parent.children.splice(t,1),this.parent.children.splice(t-1,0,this),this.parent._setChildrenIndices(),!0):!1},moveToBottom:function(){if(!this.parent)return void Konva.Util.warn("Node has no parent. moveToBottom function is ignored.");var t=this.index;return t>0?(this.parent.children.splice(t,1),this.parent.children.unshift(this),this.parent._setChildrenIndices(),!0):!1},setZIndex:function(t){if(!this.parent)return void Konva.Util.warn("Node has no parent. zIndex parameter is ignored.");var e=this.index;return this.parent.children.splice(e,1),this.parent.children.splice(t,0,this),this.parent._setChildrenIndices(),this},getAbsoluteOpacity:function(){return this._getCache(t,this._getAbsoluteOpacity)},_getAbsoluteOpacity:function(){var t=this.getOpacity();return this.getParent()&&(t*=this.getParent().getAbsoluteOpacity()),t},moveTo:function(t){return this.getParent()!==t&&(this.remove(),t.add(this)),this},toObject:function(){var t,e,n,a,i={},o=this.getAttrs();i.attrs={};for(t in o)e=o[t],Konva.Util._isFunction(e)||Konva.Util._isElement(e)||Konva.Util._isObject(e)||Konva.Util._hasMethods(e)||(n=this[t],delete o[t],a=n?n.call(this):null,o[t]=e,a!==e&&(i.attrs[t]=e));return i.className=this.getClassName(),i},toJSON:function(){return JSON.stringify(this.toObject())},getParent:function(){return this.parent},getLayer:function(){var t=this.getParent();return t?t.getLayer():null},getStage:function(){return this._getCache(p,this._getStage)},_getStage:function(){var t=this.getParent();return t?t.getStage():void 0},fire:function(t,e,n){return n?this._fireAndBubble(t,e||{}):this._fire(t,e||{}),this},getAbsoluteTransform:function(t){return t?this._getAbsoluteTransform(t):this._getCache(e,this._getAbsoluteTransform)},_getAbsoluteTransform:function(t){var e,n,a=new Konva.Transform;return this._eachAncestorReverse(function(t){e=t.transformsEnabled(),n=t.getTransform(),"all"===e?a.multiply(n):"position"===e&&a.translate(t.x(),t.y())},t),a},getTransform:function(){return this._getCache(K,this._getTransform)},_getTransform:function(){var t=new Konva.Transform,e=this.getX(),n=this.getY(),a=Konva.getAngle(this.getRotation()),i=this.getScaleX(),o=this.getScaleY(),r=this.getSkewX(),s=this.getSkewY(),h=this.getOffsetX(),c=this.getOffsetY();return(0!==e||0!==n)&&t.translate(e,n),0!==a&&t.rotate(a),(0!==r||0!==s)&&t.skew(r,s),(1!==i||1!==o)&&t.scale(i,o),(0!==h||0!==c)&&t.translate(-1*h,-1*c),t},clone:function(t){var e,n,a,i,o,r=this.getClassName(),s=Konva.Util.cloneObject(this.attrs);for(var c in y){var l=y[c];delete s[l]}for(e in t)s[e]=t[e];var d=new Konva[r](s);for(e in this.eventListeners)for(n=this.eventListeners[e],a=n.length,i=0;a>i;i++)o=n[i],o.name.indexOf(h)<0&&(d.eventListeners[e]||(d.eventListeners[e]=[]),d.eventListeners[e].push(o));return d},toDataURL:function(t){t=t||{};var e=t.mimeType||null,n=t.quality||null,a=this.getStage(),i=t.x||0,o=t.y||0,r=new Konva.SceneCanvas({width:t.width||this.getWidth()||(a?a.getWidth():0),height:t.height||this.getHeight()||(a?a.getHeight():0),pixelRatio:1}),s=r.getCont
2015-04-07 16:03:08 +08:00
* Sepia Filter
* Based on: Pixastic Lib - Sepia filter - v0.1.0
* Copyright (c) 2008 Jacob Seidelin, jseidelin@nihilogic.dk, http://blog.nihilogic.dk/
* @function
* @name Sepia
* @memberof Konva.Filters
* @param {Object} imageData
* @author Jacob Seidelin <jseidelin@nihilogic.dk>
* @license MPL v1.1 [http://www.pixastic.com/lib/license.txt]
* @example
* node.cache();
* node.filters([Konva.Filters.Sepia]);
*/
2015-04-14 11:50:09 +08:00
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;n<e.length;n++)t=e[n],delete t.parent,t.index=0,t.hasChildren()&&t.removeChildren(),t.remove();return e=null,this.children=new Konva.Collection,this},destroyChildren:function(){for(var t,e=Konva.Collection.toCollection(this.children),n=0;n<e.length;n++)t=e[n],delete t.parent,t.index=0,t.destroy();return e=null,this.children=new Konva.Collection,this},add:function(t){if(arguments.length>1){for(var e=0;e<arguments.length;e++)this.add(arguments[e]);return this}if(t.getParent())return t.moveTo(this),this;var n=this.children;return this._validateAdd(t),t.index=n.length,t.parent=this,n.push(t),this._fire("add",{child:t}),t.isDragging()&&Konva.DD.anim.setLayers(t.getLayer()),this},destroy:function(){this.hasChildren()&&this.destroyChildren(),Konva.Node.prototype.destroy.call(this)},find:function(t){var e,n,a,i,o,r,s,h=[],c=t.replace(/ /g,"").split(","),l=c.length;for(e=0;l>e;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 fo
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;i<d.length;i++)if(t=d[i],e=t.layers,n=t.func,t._updateFrameObject(a()),r=e.length,c=n?n.call(t,t.frame)!==!1:!0)for(o=0;r>o;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.g
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)<v&&(v=Math.abs(c-d)),o=h.getPointOnEllipticalArc(a[0],a[1],a[2],a[3],c,0),0>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]<t[1]*e[0]?-1:1)*Math.acos(_(t,e))},S=y([1,0],[(l-f)/r,(d-g)/s]),C=[(l-f)/r,(d-g)/s],x=[(-1*l-f)/r,(-1*d-g)/s],w=y(C,x);return _(C,x)<=-1&&(w=Math.PI),_(C,x)>=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","l