konva/konva.min.js

46 lines
138 KiB
JavaScript
Raw Normal View History

2015-04-07 16:03:08 +08:00
/*
2017-02-08 00:42:30 +08:00
* Konva JavaScript Framework v1.4.0
2015-04-07 16:03:08 +08:00
* http://konvajs.github.io/
* Licensed under the MIT or GPL Version 2 licenses.
* Date: Fri Feb 24 2017
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.
*/
2017-02-08 00:42:30 +08:00
!function(t){"use strict";var e=Math.PI/180,n={version:"1.4.0",stages:[],idCounter:0,ids:{},names:{},shapes:{},listenClickTap:!1,inDblClickWindow:!1,enableTrace:!1,traceArrMax:100,dblClickWindow:400,pixelRatio:void 0,dragDistance:0,angleDeg:!0,showWarnings:!0,Filters:{},isDragging:function(){var t=n.DD;return!!t&&t.isDragging},isDragReady:function(){var t=n.DD;return!!t&&!!t.node},_addId:function(t,e){void 0!==e&&(this.ids[e]=t)},_removeId:function(t){void 0!==t&&delete this.ids[t]},_addName:function(t,e){e&&(this.names[e]||(this.names[e]=[]),this.names[e].push(t))},_removeName:function(t,e){if(t){var n=this.names[t];if(n){for(var i=0;i<n.length;i++){var a=n[i];a._id===e&&n.splice(i,1)}0===n.length&&delete this.names[t]}}},getAngle:function(t){return this.angleDeg?t*e:t},_detectIE:function(t){var e=t.indexOf("msie ");if(e>0)return parseInt(t.substring(e+5,t.indexOf(".",e)),10);var n=t.indexOf("trident/");if(n>0){var i=t.indexOf("rv:");return parseInt(t.substring(i+3,t.indexOf(".",i)),10)}var a=t.indexOf("edge/");return a>0&&parseInt(t.substring(a+5,t.indexOf(".",a)),10)},_parseUA:function(t){var e=t.toLowerCase(),i=/(chrome)[ \/]([\w.]+)/.exec(e)||/(webkit)[ \/]([\w.]+)/.exec(e)||/(opera)(?:.*version|)[ \/]([\w.]+)/.exec(e)||/(msie) ([\w.]+)/.exec(e)||e.indexOf("compatible")<0&&/(mozilla)(?:.*? rv:([\w.]+)|)/.exec(e)||[],a=!!t.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i),r=!!t.match(/IEMobile/i);return{browser:i[1]||"",version:i[2]||"0",isIE:n._detectIE(e),mobile:a,ieMobile:r}},UA:void 0},i="undefined"!=typeof t?t:"undefined"!=typeof window?window:"undefined"!=typeof WorkerGlobalScope?self:{};if(n.UA=n._parseUA(i.navigator&&i.navigator.userAgent||""),i.Konva&&console.error("Konva instance is already exist in current eviroment. Please use only one instance."),i.Konva=n,n.global=i,"object"==typeof exports){if(i.window&&i.window.document)n.document=i.window.document,n.window=i.window;else{var a=require("canvas"),r=require("jsdom").jsdom;n.window=r("<!DOCTYPE html><html><head></head><body></body></html>").defaultView,n.document=n.window.document,n.window.Image=a.Image,n._nodeCanvas=a}return void(module.exports=n)}"function"==typeof define&&define.amd&&define(function(){return n}),n.document=document,n.window=window}("undefined"!=typeof global?global:window),function(){"use strict";Konva.Collection=function(){var t=[].slice.call(arguments),e=t.length,n=0;for(this.length=e;n<e;n++)this[n]=t[n];return this},Konva.Collection.prototype=[],Konva.Collection.prototype.each=function(t){for(var e=0;e<this.length;e++)t(this[e],e)},Konva.Collection.prototype.toArray=function(){var t,e=[],n=this.length;for(t=0;t<n;t++)e.push(this[t]);return e},Konva.Collection.toCollection=function(t){var e,n=new Konva.Collection,i=t.length;for(e=0;e<i;e++)n.push(t[e]);return n},Konva.Collection._mapMethod=function(t){Konva.Collection.prototype[t]=function(){var e,n=this.length,i=[].slice.call(arguments);for(e=0;e<n;e++)this[e][t].apply(this[e],i);return this}},Konva.Collection.mapMethods=function(t){var e=t.prototype;for(var n in e)Konva.Collection._mapMethod(n)},Konva.Transform=function(t){this.m=t&&t.slice()||[1,0,0,1,0,0]},Konva.Transform.prototype={copy:function(){return new Konva.Transform(this.m)},point:function(t){var e=this.m;return{x:e[0]*t.x+e[2]*t.y+e[4],y:e[1]*t.x+e[3]*t.y+e[5]}},translate:function(t,e){return this.m[4]+=this.m[0]*t+this.m[2]*e,this.m[5]+=this.m[1]*t+this.m[3]*e,this},scale:function(t,e){return this.m[0]*=t,this.m[1]*=t,this.m[2]*=e,this.m[3]*=e,this},rotate:function(t){var e=Math.cos(t),n=Math.sin(t),i=this.m[0]*e+this.m[2]*n,a=this.m[1]*e+this.m[3]*n,r=this.m[0]*-n+this.m[2]*e,o=this.m[1]*-n+this.m[3]*e;return this.m[0]=i,this.m[1]=a,this.m[2]=r,this.m[3]=o,this},getTranslation:function(){return{x:this.m[4],y:this.m[5]}},skew:function(t,e){var n=this.m[0]+this.m[2]*e,i=this.m[1]+this.m[3]*e,a=this.m[2]+this.m[0]*t,r=this.m[3]+this.m[1]*t;return this.m[0]=n,this.m[1]=i,this.m[2]=a,this.m[3]=r,this},multiply:function(t){var e=this.m[0]*t.m[0]+this.m[2]*t.m[1],n=this.m[1]*t.m[0]+this.m[3]*t.m[1],i=this.m
2017-01-10 21:27:32 +08:00
t._setChildrenIndices(),delete this.parent),this._clearSelfAndDescendantCache(_),this._clearSelfAndDescendantCache(n),this._clearSelfAndDescendantCache(S),this._clearSelfAndDescendantCache(d),this._clearSelfAndDescendantCache(e),this},destroy:function(){t._removeId(this.getId());for(var e=(this.getName()||"").split(/\s/g),n=0;n<e.length;n++){var i=e[n];t._removeName(i,this._id)}return this.remove(),this},getAttr:function(e){var n=h+t.Util._capitalize(e);return t.Util._isFunction(this[n])?this[n]():this.attrs[e]},getAncestors:function(){for(var e=this.getParent(),n=new t.Collection;e;)n.push(e),e=e.getParent();return n},getAttrs:function(){return this.attrs||{}},setAttrs:function(e){var n,i;if(!e)return this;for(n in e)n!==r&&(i=g+t.Util._capitalize(n),t.Util._isFunction(this[i])?this[i](e[n]):this._setAttr(n,e[n]));return this},isListening:function(){return this._getCache(d,this._isListening)},_isListening:function(){var t=this.getListening(),e=this.getParent();return"inherit"===t?!e||e.isListening():t},isVisible:function(){return this._getCache(S,this._isVisible)},_isVisible:function(){var t=this.getVisible(),e=this.getParent();return"inherit"===t?!e||e.isVisible():t},shouldDrawHit:function(t){var e=this.getLayer();return t&&t.isCache||e&&e.hitGraphEnabled()&&this.isListening()&&this.isVisible()},show:function(){return this.setVisible(!0),this},hide:function(){return this.setVisible(!1),this},getZIndex:function(){return this.index||0},getAbsoluteZIndex:function(){function t(h){for(e=[],n=h.length,i=0;i<n;i++)a=h[i],s++,a.nodeType!==p&&(e=e.concat(a.getChildren().toArray())),a._id===o._id&&(i=n);e.length>0&&e[0].getDepth()<=r&&t(e)}var e,n,i,a,r=this.getDepth(),o=this,s=0;return o.nodeType!==K&&t(o.getStage().getChildren()),s},getDepth:function(){for(var t=0,e=this.parent;e;)t++,e=e.parent;return t},setPosition:function(t){return this.setX(t.x),this.setY(t.y),this},getPosition:function(){return{x:this.getX(),y:this.getY()}},getAbsolutePosition:function(e){var n=this.getAbsoluteTransform(e).getMatrix(),i=new t.Transform,a=this.offset();return i.m=n.slice(),i.translate(a.x,a.y),i.getTranslation()},setAbsolutePosition:function(t){var e,n=this._clearTransform();return this.attrs.x=n.x,this.attrs.y=n.y,delete n.x,delete n.y,e=this.getAbsoluteTransform(),e.invert(),e.translate(t.x,t.y),t={x:this.attrs.x+e.getTranslation().x,y:this.attrs.y+e.getTranslation().y},this.setPosition({x:t.x,y:t.y}),this._setTransform(n),this},_setTransform:function(t){var e;for(e in t)this.attrs[e]=t[e];this._clearCache(y),this._clearSelfAndDescendantCache(n)},_clearTransform:function(){var t={x:this.getX(),y:this.getY(),rotation:this.getRotation(),scaleX:this.getScaleX(),scaleY:this.getScaleY(),offsetX:this.getOffsetX(),offsetY:this.getOffsetY(),skewX:this.getSkewX(),skewY:this.getSkewY()};return this.attrs.x=0,this.attrs.y=0,this.attrs.rotation=0,this.attrs.scaleX=1,this.attrs.scaleY=1,this.attrs.offsetX=0,this.attrs.offsetY=0,this.attrs.skewX=0,this.attrs.skewY=0,this._clearCache(y),this._clearSelfAndDescendantCache(n),t},move:function(t){var e=t.x,n=t.y,i=this.getX(),a=this.getY();return void 0!==e&&(i+=e),void 0!==n&&(a+=n),this.setPosition({x:i,y:a}),this},_eachAncestorReverse:function(t,e){var n,i,a=[],r=this.getParent();if(e&&e._id===this._id)return t(this),!0;for(a.unshift(this);r&&(!e||r._id!==e._id);)a.unshift(r),r=r.parent;for(n=a.length,i=0;i<n;i++)t(a[i])},rotate:function(t){return this.setRotation(this.getRotation()+t),this},moveToTop:function(){if(!this.parent)return t.Util.warn("Node has no parent. moveToTop function is ignored."),!1;var e=this.index;return this.parent.children.splice(e,1),this.parent.children.push(this),this.parent._setChildrenIndices(),!0},moveUp:function(){if(!this.parent)return t.Util.warn("Node has no parent. moveUp function is ignored."),!1;var e=this.index,n=this.parent.getChildren().length;return e<n-1&&(this.parent.children.splice(e,1),this.parent.children.splice(e+1,0,this),this.parent._setChildrenIndices(),!0)},moveDown:function(){if(!this.parent)return t.Util.warn("Node has no parent. moveDown function i
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]);
*/
2017-02-08 00:37:01 +08:00
Konva.Filters.Sepia=function(t){var e,n,i,a,r,o,s,h,c,l=t.data,d=t.width,u=t.height,v=4*d;do{e=(u-1)*v,n=d;do i=e+4*(n-1),a=l[i],r=l[i+1],o=l[i+2],s=.393*a+.769*r+.189*o,h=.349*a+.686*r+.168*o,c=.272*a+.534*r+.131*o,l[i]=s>255?255:s,l[i+1]=h>255?255:h,l[i+2]=c>255?255:c,l[i+3]=l[i+3];while(--n)}while(--u)}}(),function(){"use strict";Konva.Filters.Solarize=function(t){var e=t.data,n=t.width,i=t.height,a=4*n,r=i;do{var o=(r-1)*a,s=n;do{var h=o+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(--r)}}(),function(){"use strict";var t=function(t,e,n){var i,a,r,o,s=t.data,h=e.data,c=t.width,l=t.height,d=n.polarCenterX||c/2,u=n.polarCenterY||l/2,v=0,f=0,g=0,p=0,m=Math.sqrt(d*d+u*u);a=c-d,r=l-u,o=Math.sqrt(a*a+r*r),m=o>m?o:m;var _,y,K,S,x=l,C=c,w=360/C*Math.PI/180;for(y=0;y<C;y+=1)for(K=Math.sin(y*w),S=Math.cos(y*w),_=0;_<x;_+=1)a=Math.floor(d+m*_/x*S),r=Math.floor(u+m*_/x*K),i=4*(r*c+a),v=s[i+0],f=s[i+1],g=s[i+2],p=s[i+3],i=4*(y+_*c),h[i+0]=v,h[i+1]=f,h[i+2]=g,h[i+3]=p},e=function(t,e,n){var i,a,r,o,s,h,c=t.data,l=e.data,d=t.width,u=t.height,v=n.polarCenterX||d/2,f=n.polarCenterY||u/2,g=0,p=0,m=0,_=0,y=Math.sqrt(v*v+f*f);a=d-v,r=u-f,h=Math.sqrt(a*a+r*r),y=h>y?h:y;var K,S,x,C,w=u,b=d,F=n.polarRotation||0;for(a=0;a<d;a+=1)for(r=0;r<u;r+=1)o=a-v,s=r-f,K=Math.sqrt(o*o+s*s)*w/y,S=(180*Math.atan2(s,o)/Math.PI+360+F)%360,S=S*b/360,x=Math.floor(S),C=Math.floor(K),i=4*(C*d+x),g=c[i+0],p=c[i+1],m=c[i+2],_=c[i+3],i=4*(r*d+a),l[i+0]=g,l[i+1]=p,l[i+2]=m,l[i+3]=_},n=Konva.Util.createCanvasElement();Konva.Filters.Kaleidoscope=function(i){var a,r,o,s,h,c,l,d,u,v,f=i.width,g=i.height,p=Math.round(this.kaleidoscopePower()),m=Math.round(this.kaleidoscopeAngle()),_=Math.floor(f*(m%360)/360);if(!(p<1)){n.width=f,n.height=g;var y=n.getContext("2d").getImageData(0,0,f,g);t(i,y,{polarCenterX:f/2,polarCenterY:g/2});for(var K=f/Math.pow(2,p);K<=8;)K=2*K,p-=1;K=Math.ceil(K);var S=K,x=0,C=S,w=1;for(_+K>f&&(x=S,C=0,w=-1),r=0;r<g;r+=1)for(a=x;a!==C;a+=w)o=Math.round(a+_)%f,u=4*(f*r+o),h=y.data[u+0],c=y.data[u+1],l=y.data[u+2],d=y.data[u+3],v=4*(f*r+a),y.data[v+0]=h,y.data[v+1]=c,y.data[v+2]=l,y.data[v+3]=d;for(r=0;r<g;r+=1)for(S=Math.floor(K),s=0;s<p;s+=1){for(a=0;a<S+1;a+=1)u=4*(f*r+a),h=y.data[u+0],c=y.data[u+1],l=y.data[u+2],d=y.data[u+3],v=4*(f*r+2*S-a-1),y.data[v+0]=h,y.data[v+1]=c,y.data[v+2]=l,y.data[v+3]=d;S*=2}e(y,i,{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(){"use strict";Konva.Container=function(t){this.__init(t)},Konva.Util.addMethods(Konva.Container,{__init:function(t){this.children=new Konva.Collection,Konva.Node.call(this,t)},getChildren:function(t){if(!t)return this.children;var e=new Konva.Collection;return this.children.each(function(n){t(n)&&e.push(n)}),e},hasChildren:function(){return this.getChildren().length>0},removeChildren:function(){for(var t,e=Konva.Collection.toCollection(this.children),n=0;n<e.length;n++)t=e[n],delete t.parent,t.index=0,t.remove();return e=null,this.children=new Konva.Collection,this},destroyChildren:function(){for(var t,e=Konva.Collection.toCollection(this.children),n=0;n<e.length;n++)t=e[n],delete t.parent,t.index=0,t.destroy();return e=null,this.children=new Konva.Collection,this},add:function(t){if(arguments.length>1){for(var e=0;e<arguments.length;e++)this.add(arguments[e]);return this}if(t.getParent())return t.moveTo(this),this;var n=this.children;return this._validateAdd(t),t.index=n.length,t.parent=this,n.push(t),this._fire("add",{child:t}),Konva.DD&&t.isDragging()&&Konva.DD.anim.setLayers(t.getLayer()),this},destroy:function(){return this.hasChildren()&&this.destroyChildren(),Konva.Node.prototype.destroy.call(this),this},find:function(t){var e,n,i,a,r,o,s,h=[],c=t.replace(/ /g,"").split(","),l=c.length;for(e=0;e<l;e++)if(i=c[e],Konva.Util.isValidSelector(i)||(Konva.Util.warn('Selector "'+i+'" is invalid. Allowed selectors examples are "#foo", ".b
2017-02-07 22:32:14 +08:00
Konva.Collection.mapMethods(Konva.Layer)}(),function(){"use strict";Konva.FastLayer=function(t){this.____init(t)},Konva.Util.addMethods(Konva.FastLayer,{____init:function(t){this.nodeType="Layer",this.canvas=new Konva.SceneCanvas,Konva.BaseLayer.call(this,t)},_validateAdd:function(t){var e=t.getType();"Shape"!==e&&Konva.Util.throw("You may only add shapes to a fast layer.")},_setCanvasSize:function(t,e){this.canvas.setSize(t,e)},hitGraphEnabled:function(){return!1},getIntersection:function(){return null},drawScene:function(t){var e=this.getLayer(),n=t||e&&e.getCanvas();return this.getClearBeforeDraw()&&n.getContext().clear(),Konva.Container.prototype.drawScene.call(this,n),this},draw:function(){return this.drawScene(),this},setVisible:function(t){return Konva.Node.prototype.setVisible.call(this,t),t?this.getCanvas()._canvas.style.display="block":this.getCanvas()._canvas.style.display="none",this}}),Konva.Util.extend(Konva.FastLayer,Konva.BaseLayer),Konva.Collection.mapMethods(Konva.FastLayer)}(),function(){"use strict";Konva.Group=function(t){this.___init(t)},Konva.Util.addMethods(Konva.Group,{___init:function(t){this.nodeType="Group",Konva.Container.call(this,t)},_validateAdd:function(t){var e=t.getType();"Group"!==e&&"Shape"!==e&&Konva.Util.throw("You may only add groups and shapes to groups.")}}),Konva.Util.extend(Konva.Group,Konva.Container),Konva.Collection.mapMethods(Konva.Group)}(),function(t){"use strict";function e(t){setTimeout(t,1e3/60)}function n(){return a.apply(t.global,arguments)}var i=function(){return t.global.performance&&t.global.performance.now?function(){return t.global.performance.now()}:function(){return(new Date).getTime()}}(),a=function(){return t.global.requestAnimationFrame||t.global.webkitRequestAnimationFrame||t.global.mozRequestAnimationFrame||t.global.oRequestAnimationFrame||t.global.msRequestAnimationFrame||e}();t.Animation=function(e,n){var a=t.Animation;this.func=e,this.setLayers(n),this.id=a.animIdCounter++,this.frame={time:0,timeDiff:0,lastTime:i()}},t.Animation.prototype={setLayers:function(t){var e=[];return e=t?t.length>0?t:[t]:[],this.layers=e,this},getLayers:function(){return this.layers},addLayer:function(t){var e,n=this.layers,i=n.length;for(e=0;e<i;e++)if(n[e]._id===t._id)return!1;return this.layers.push(t),!0},isRunning:function(){var e,n=t.Animation,i=n.animations,a=i.length;for(e=0;e<a;e++)if(i[e].id===this.id)return!0;return!1},start:function(){var e=t.Animation;return this.stop(),this.frame.timeDiff=0,this.frame.lastTime=i(),e._addAnimation(this),this},stop:function(){return t.Animation._removeAnimation(this),this},_updateFrameObject:function(t){this.frame.timeDiff=t-this.frame.lastTime,this.frame.lastTime=t,this.frame.time+=this.frame.timeDiff,this.frame.frameRate=1e3/this.frame.timeDiff}},t.Animation.animations=[],t.Animation.animIdCounter=0,t.Animation.animRunning=!1,t.Animation._addAnimation=function(t){this.animations.push(t),this._handleAnimation()},t.Animation._removeAnimation=function(t){var e,n=t.id,i=this.animations,a=i.length;for(e=0;e<a;e++)if(i[e].id===n){this.animations.splice(e,1);break}},t.Animation._runFrames=function(){var t,e,n,a,r,o,s,h,c,l={},d=this.animations;for(a=0;a<d.length;a++)if(t=d[a],e=t.layers,n=t.func,t._updateFrameObject(i()),o=e.length,c=!n||n.call(t,t.frame)!==!1)for(r=0;r<o;r++)s=e[r],void 0!==s._id&&(l[s._id]=s);for(h in l)l.hasOwnProperty(h)&&l[h].draw()},t.Animation._animationLoop=function(){var e=t.Animation;e.animations.length?(e._runFrames(),n(e._animationLoop)):e.animRunning=!1},t.Animation._handleAnimation=function(){this.animRunning||(this.animRunning=!0,n(this._animationLoop))},t.BaseLayer.prototype.batchDraw=function(){var e=this,n=t.Animation;return this.batchAnim||(this.batchAnim=new n(function(){e.batchAnim.stop()},this)),this.lastBatchDrawTime=i(),this.batchAnim.isRunning()||this.batchAnim.start(),this},t.Stage.prototype.batchDraw=function(){return this.getChildren().each(function(t){t.batchDraw()}),this}}(Konva),function(){"use strict";var t={node:1,duration:1,easing:1,onFinish:1,yoyo:1},e=1,n=2,i=3,a=0,r=["fill","stroke
return Math.sqrt((n-t)*(n-t)+(i-e)*(i-e))},Konva.Path.getPointOnLine=function(t,e,n,i,a,r,o){void 0===r&&(r=e),void 0===o&&(o=n);var s=(a-n)/(i-e+1e-8),h=Math.sqrt(t*t/(1+s*s));i<e&&(h*=-1);var c,l=s*h;if(i===e)c={x:r,y:o+l};else if((o-n)/(r-e+1e-8)===s)c={x:r+h,y:o+l};else{var d,u,v=this.getLineLength(e,n,i,a);if(v<1e-8)return;var f=(r-e)*(i-e)+(o-n)*(a-n);f/=v*v,d=e+f*(i-e),u=n+f*(a-n);var g=this.getLineLength(r,o,d,u),p=Math.sqrt(t*t-g*g);h=Math.sqrt(p*p/(1+s*s)),i<e&&(h*=-1),l=s*h,c={x:d+h,y:u+l}}return c},Konva.Path.getPointOnCubicBezier=function(t,e,n,i,a,r,o,s,h){function c(t){return t*t*t}function l(t){return 3*t*t*(1-t)}function d(t){return 3*t*(1-t)*(1-t)}function u(t){return(1-t)*(1-t)*(1-t)}var v=s*c(t)+r*l(t)+i*d(t)+e*u(t),f=h*c(t)+o*l(t)+a*d(t)+n*u(t);return{x:v,y:f}},Konva.Path.getPointOnQuadraticBezier=function(t,e,n,i,a,r,o){function s(t){return t*t}function h(t){return 2*t*(1-t)}function c(t){return(1-t)*(1-t)}var l=r*s(t)+i*h(t)+e*c(t),d=o*s(t)+a*h(t)+n*c(t);return{x:l,y:d}},Konva.Path.getPointOnEllipticalArc=function(t,e,n,i,a,r){var o=Math.cos(r),s=Math.sin(r),h={x:n*Math.cos(a),y:i*Math.sin(a)};return{x:t+(h.x*o-h.y*s),y:e+(h.x*s+h.y*o)}},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 i=0;i<n.length;i++)e=e.replace(new RegExp(n[i],"g"),"|"+n[i]);var a=e.split("|"),r=[],o=0,s=0;for(i=1;i<a.length;i++){var h=a[i],c=h.charAt(0);h=h.slice(1),h=h.replace(new RegExp(",-","g"),"-"),h=h.replace(new RegExp("-","g"),",-"),h=h.replace(new RegExp("e,-","g"),"e-");var l=h.split(",");l.length>0&&""===l[0]&&l.shift();for(var d=0;d<l.length;d++)l[d]=parseFloat(l[d]);for(;l.length>0&&!isNaN(l[0]);){var u,v,f,g,p,m,_,y,K,S,x=null,C=[],w=o,b=s;switch(c){case"l":o+=l.shift(),s+=l.shift(),x="L",C.push(o,s);break;case"L":o=l.shift(),s=l.shift(),C.push(o,s);break;case"m":var F=l.shift(),T=l.shift();if(o+=F,s+=T,x="M",r.length>2&&"z"===r[r.length-1].command)for(var P=r.length-2;P>=0;P--)if("M"===r[P].command){o=r[P].points[0]+F,s=r[P].points[1]+T;break}C.push(o,s),c="l";break;case"M":o=l.shift(),s=l.shift(),x="M",C.push(o,s),c="L";break;case"h":o+=l.shift(),x="L",C.push(o,s);break;case"H":o=l.shift(),x="L",C.push(o,s);break;case"v":s+=l.shift(),x="L",C.push(o,s);break;case"V":s=l.shift(),x="L",C.push(o,s);break;case"C":C.push(l.shift(),l.shift(),l.shift(),l.shift()),o=l.shift(),s=l.shift(),C.push(o,s);break;case"c":C.push(o+l.shift(),s+l.shift(),o+l.shift(),s+l.shift()),o+=l.shift(),s+=l.shift(),x="C",C.push(o,s);break;case"S":v=o,f=s,u=r[r.length-1],"C"===u.command&&(v=o+(o-u.points[2]),f=s+(s-u.points[3])),C.push(v,f,l.shift(),l.shift()),o=l.shift(),s=l.shift(),x="C",C.push(o,s);break;case"s":v=o,f=s,u=r[r.length-1],"C"===u.command&&(v=o+(o-u.points[2]),f=s+(s-u.points[3])),C.push(v,f,o+l.shift(),s+l.shift()),o+=l.shift(),s+=l.shift(),x="C",C.push(o,s);break;case"Q":C.push(l.shift(),l.shift()),o=l.shift(),s=l.shift(),C.push(o,s);break;case"q":C.push(o+l.shift(),s+l.shift()),o+=l.shift(),s+=l.shift(),x="Q",C.push(o,s);break;case"T":v=o,f=s,u=r[r.length-1],"Q"===u.command&&(v=o+(o-u.points[0]),f=s+(s-u.points[1])),o=l.shift(),s=l.shift(),x="Q",C.push(v,f,o,s);break;case"t":v=o,f=s,u=r[r.length-1],"Q"===u.command&&(v=o+(o-u.points[0]),f=s+(s-u.points[1])),o+=l.shift(),s+=l.shift(),x="Q",C.push(v,f,o,s);break;case"A":g=l.shift(),p=l.shift(),m=l.shift(),_=l.shift(),y=l.shift(),K=o,S=s,o=l.shift(),s=l.shift(),x="A",C=this.convertEndpointToCenterParameterization(K,S,o,s,_,y,g,p,m);break;case"a":g=l.shift(),p=l.shift(),m=l.shift(),_=l.shift(),y=l.shift(),K=o,S=s,o+=l.shift(),s+=l.shift(),x="A",C=this.convertEndpointToCenterParameterization(K,S,o,s,_,y,g,p,m)}r.push({command:x||c,points:C,start:{x:w,y:b},pathLength:this.calcLength(w,b,x||c,C)})}"z"!==c&&"Z"!==c||r.push({command:"z",points:[],start:void 0,pathLength:0})}return r},Konva.Path.calcLength=function(t,e,n,i){var a,r,o,s,h=Konva.Path;switch(n){case"L":return h.getLineLength(t,e,i[0],i[1]);case"C":for(a=0,r=h.getPointOnCubicBezier(