From 2404368ec83f0c55cb8c1568cb36a63542a75dbc Mon Sep 17 00:00:00 2001 From: Anton Lavrenov Date: Fri, 14 Dec 2018 13:28:39 -0500 Subject: [PATCH] New `ignoreStroke` for `Konva.Transformer`, perf fixes --- CHANGELOG.md | 8 +++ konva.js | 73 +++++++++++++++++++++++----- konva.min.js | 6 +-- src/Container.js | 3 +- src/Context.js | 4 +- src/Node.js | 6 +++ src/Shape.js | 3 +- src/filters/HSL.js | 8 +-- src/shapes/Transformer.js | 33 +++++++++++-- test/unit/Node-cache-test.js | 29 +++++++++++ test/unit/shapes/Transformer-test.js | 18 +++---- 11 files changed, 156 insertions(+), 35 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bf60a103..f0141452 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,14 @@ This project adheres to [Semantic Versioning](http://semver.org/). ### Changed +* Performance fixes when cached node has many children + +### Added + +* New `ignoreStroke` for `Konva.Transformer`. Good to use when a shape has `strokeScaleEnabled = false` + +### Changed + * getKerning TextPath API is deprecated. Use "kerningFunc" instead. ## [2.5.1][2018-11-08] diff --git a/konva.js b/konva.js index 86ef0b05..435d358d 100644 --- a/konva.js +++ b/konva.js @@ -2,7 +2,7 @@ * Konva JavaScript Framework v2.5.1 * http://konvajs.github.io/ * Licensed under the MIT - * Date: Thu Nov 22 2018 + * Date: Fri Dec 14 2018 * * Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS) * Modified work Copyright (C) 2014 - present by Anton Lavrenov (Konva) @@ -2118,7 +2118,8 @@ if (shape.hasStroke()) { if (!strokeScaleEnabled) { this.save(); - this.setTransform(1, 0, 0, 1, 0, 0); + var pixelRatio = this.getCanvas().getPixelRatio(); + this.setTransform(pixelRatio, 0, 0, pixelRatio, 0, 0); } this._applyLineCap(shape); @@ -2633,6 +2634,10 @@ _clearSelfAndDescendantCache: function(attr) { this._clearCache(attr); + // skip clearing of node is cached with canvas + if (this._cache.canvas) { + return; + } if (this.children) { this.getChildren().each(function(node) { node._clearSelfAndDescendantCache(attr); @@ -2650,6 +2655,7 @@ clearCache: function() { delete this._cache.canvas; this._filterUpToDate = false; + this._clearSelfAndDescendantCache(); return this; }, /** @@ -2804,6 +2810,7 @@ * @param {Object} config * @param {Boolean} [config.skipTransform] should we apply transform to node for calculating rect? * @param {Boolean} [config.skipShadow] should we apply shadow to the node for calculating bound box? + * @param {Boolean} [config.skipStroke] should we apply stroke to the node for calculating bound box? * @param {Object} [config.relativeTo] calculate client rect relative to one of the parents * @returns {Object} rect with {x, y, width, height} properties * @example @@ -6721,7 +6728,7 @@ ); /** * get/set hsl luminance. Use with {@link Konva.Filters.HSL} filter. - * @name value + * @name luminance * @method * @memberof Konva.Node.prototype * @param {Number} value from -1 to 1 @@ -6736,7 +6743,7 @@ * @author ippo615 * @example * image.filters([Konva.Filters.HSL]); - * image.luminance(200); + * image.luminance(0.2); */ Konva.Filters.HSL = function(imageData) { @@ -6760,8 +6767,8 @@ //[ .299V-.300vsu+1.25vsw .587V-.588vsu-1.05vsw .114V+.886vsu-.203vsw ] [B] // Precompute the values in the matrix: - var vsu = v * s * Math.cos(h * Math.PI / 180), - vsw = v * s * Math.sin(h * Math.PI / 180); + var vsu = v * s * Math.cos((h * Math.PI) / 180), + vsw = v * s * Math.sin((h * Math.PI) / 180); // (result spot)(source spot) var rr = 0.299 * v + 0.701 * vsu + 0.167 * vsw, rg = 0.587 * v - 0.587 * vsu + 0.33 * vsw, @@ -8419,7 +8426,8 @@ var rect = child.getClientRect({ relativeTo: that, - skipShadow: attrs.skipShadow + skipShadow: attrs.skipShadow, + skipStroke: attrs.skipStroke }); // skip invisible children (like empty groups) @@ -8945,7 +8953,20 @@ var fillRect = this.getSelfRect(); - var strokeWidth = (this.hasStroke() && this.strokeWidth()) || 0; + var applyStroke = !attrs.skipStroke && this.hasStroke(); + var strokeWidth = (applyStroke && this.strokeWidth()) || 0; + + // var scale = { + // x: 1, + // y: 1 + // }; + // if (!this.strokeScaleEnabled()) { + // var scale = this.getAbsoluteScale(); + // // scale = { + // // x: Math.abs(scale.x) + // // } + // } + var fillAndStrokeWidth = fillRect.width + strokeWidth; var fillAndStrokeHeight = fillRect.height + strokeWidth; @@ -19521,10 +19542,12 @@ 'borderEnabledChange', 'borderStrokeChange', 'borderStrokeWidthChange', + 'borderDashChange', 'anchorStrokeChange', 'anchorStrokeWidthChange', 'anchorFillChange', - 'anchorCornerRadiusChange' + 'anchorCornerRadiusChange', + 'ignoreStrokeChange' ].join(' '); var NODE_RECT = 'nodeRect'; @@ -19578,7 +19601,7 @@ if (isMirrored) { rad *= -1; } - var angle = (Konva.Util._radToDeg(rad) % 360 + 360) % 360; + var angle = ((Konva.Util._radToDeg(rad) % 360) + 360) % 360; if ( Konva.Util._inRange(angle, 315 + 22.5, 360) || @@ -19773,7 +19796,11 @@ rotation: 0 }; } - var rect = node.getClientRect({ skipTransform: true, skipShadow: true }); + var rect = node.getClientRect({ + skipTransform: true, + skipShadow: true, + skipStroke: this.ignoreStroke() + }); var rotation = Konva.getAngle(node.rotation()); var dx = rect.x * node.scaleX() - node.offsetX() * node.scaleX(); @@ -20167,7 +20194,12 @@ if (newAttrs.rotation !== undefined) { this.getNode().rotation(newAttrs.rotation); } - var pure = node.getClientRect({ skipTransform: true, skipShadow: true }); + var pure = node.getClientRect({ + skipTransform: true, + skipShadow: true, + skipStroke: this.ignoreStroke() + }); + var padding = this.getPadding(); var scaleX = (newAttrs.width - padding * 2) / pure.width; var scaleY = (newAttrs.height - padding * 2) / pure.height; @@ -20650,6 +20682,23 @@ */ Konva.Factory.addGetterSetter(Konva.Transformer, 'centeredScaling', false); + /** + * get/set should we think about stroke while resize? Good to use when a shape has strokeScaleEnabled = false + * default is false + * @name ignoreStroke + * @method + * @memberof Konva.Transformer.prototype + * @param {Boolean} ignoreStroke + * @returns {Boolean} + * @example + * // get + * var ignoreStroke = transformer.ignoreStroke(); + * + * // set + * transformer.ignoreStroke(true); + */ + Konva.Factory.addGetterSetter(Konva.Transformer, 'ignoreStroke', false); + /** * get/set padding * @name padding diff --git a/konva.min.js b/konva.min.js index c2fad7f6..9b2d0530 100644 --- a/konva.min.js +++ b/konva.min.js @@ -2,14 +2,14 @@ * Konva JavaScript Framework v2.5.1 * http://konvajs.github.io/ * Licensed under the MIT - * Date: Thu Nov 22 2018 + * Date: Fri Dec 14 2018 * * Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS) * Modified work Copyright (C) 2014 - present by Anton Lavrenov (Konva) * * @license */ -!function(){"use strict";var e=Math.PI/180,r={version:"2.5.1",stages:[],idCounter:0,ids:{},names:{},shapes:{},listenClickTap:!1,inDblClickWindow:!1,isBrowser:"undefined"!=typeof window&&("[object Window]"==={}.toString.call(window)||"[object global]"==={}.toString.call(window)),isUnminified:/comment/.test(function(){}),enableTrace:!1,traceArrMax:100,dblClickWindow:400,pixelRatio:void 0,dragDistance:3,angleDeg:!0,showWarnings:!0,Filters:{},isDragging:function(){var t=r.DD;return!!t&&t.isDragging},isDragReady:function(){var t=r.DD;return!!t&&!!t.node},_addId:function(t,e){e&&(this.ids[e]=t)},_removeId:function(t){void 0!==t&&delete this.ids[t]},_addName:function(t,e){e&&(this.names[e]||(this.names[e]=[]),this.names[e].push(t))},_removeName:function(t,e){if(t){var i=this.names[t];if(i){for(var n=0;n>16&255,g:e>>8&255,b:255&e}},getRandomColor:function(){for(var t=(16777215*Math.random()<<0).toString(16);t.length<6;)t="0"+t;return"#"+t},get:function(t,e){return void 0===t?e:t},getRGB:function(t){var e;return t in a?{r:(e=a[t])[0],g:e[1],b:e[2]}:"#"===t[0]?this._hexToRgb(t.substring(1)):"rgb("===t.substr(0,4)?(e=r.exec(t.replace(/ /g,"")),{r:parseInt(e[1],10),g:parseInt(e[2],10),b:parseInt(e[3],10)}):{r:0,g:0,b:0}},colorToRGBA:function(t){return t=t||"black",Konva.Util._namedColorToRBA(t)||Konva.Util._hex3ColorToRGBA(t)||Konva.Util._hex6ColorToRGBA(t)||Konva.Util._rgbColorToRGBA(t)||Konva.Util._rgbaColorToRGBA(t)},_namedColorToRBA:function(t){var e=a[t.toLowerCase()];return e?{r:e[0],g:e[1],b:e[2],a:1}:null},_rgbColorToRGBA:function(t){if(0===t.indexOf("rgb(")){var e=(t=t.match(/rgb\(([^)]+)\)/)[1]).split(/ *, */).map(Number);return{r:e[0],g:e[1],b:e[2],a:1}}},_rgbaColorToRGBA:function(t){if(0===t.indexOf("rgba(")){var e=(t=t.match(/rgba\(([^)]+)\)/)[1]).split(/ *, */).map(Number);return{r:e[0],g:e[1],b:e[2],a:e[3]}}},_hex6ColorToRGBA:function(t){if("#"===t[0]&&7===t.length)return{r:parseInt(t.slice(1,3),16),g:parseInt(t.slice(3,5),16),b:parseInt(t.slice(5,7),16),a:1}},_hex3ColorToRGBA:function(t){if("#"===t[0]&&4===t.length)return{r:parseInt(t[1]+t[1],16),g:parseInt(t[2]+t[2],16),b:parseInt(t[3]+t[3],16),a:1}},_merge:function(t,e){var i=this._clone(e);for(var n in t)this._isObject(t[n])?i[n]=this._merge(t[n],i[n]):i[n]=t[n];return i},trimRight:function(t){return t.replace(/\s+$/,"")},trimLeft:function(t){return t.replace(/^\s+/,"")},haveIntersection:function(t,e){return!(e.x>t.x+t.width||e.x+e.widtht.y+t.height||e.y+e.heighte.length){var o=e;e=t,t=o}for(n=0;n=Konva.traceArrMax&&e.shift()},reset:function(){var t=this.getCanvas().getPixelRatio();this.setTransform(1*t,0,0,1*t,0,0)},getCanvas:function(){return this.canvas},clear:function(t){var e=this.getCanvas();t?this.clearRect(t.x||0,t.y||0,t.width||0,t.height||0):this.clearRect(0,0,e.getWidth()/e.pixelRatio,e.getHeight()/e.pixelRatio)},_applyLineCap:function(t){var e=t.getLineCap();e&&this.setAttr("lineCap",e)},_applyOpacity:function(t){var e=t.getAbsoluteOpacity();1!==e&&this.setAttr("globalAlpha",e)},_applyLineJoin:function(t){var e=t.getLineJoin();e&&this.setAttr("lineJoin",e)},setAttr:function(t,e){this._context[t]=e},arc:function(){var t=arguments;this._context.arc(t[0],t[1],t[2],t[3],t[4],t[5])},beginPath:function(){this._context.beginPath()},bezierCurveTo:function(){var t=arguments;this._context.bezierCurveTo(t[0],t[1],t[2],t[3],t[4],t[5])},clearRect:function(){var t=arguments;this._context.clearRect(t[0],t[1],t[2],t[3])},clip:function(){this._context.clip()},closePath:function(){this._context.closePath()},createImageData:function(){var t=arguments;return 2===t.length?this._context.createImageData(t[0],t[1]):1===t.length?this._context.createImageData(t[0]):void 0},createLinearGradient:function(){var t=arguments;return this._context.createLinearGradient(t[0],t[1],t[2],t[3])},createPattern:function(){var t=arguments;return this._context.createPattern(t[0],t[1])},createRadialGradient:function(){var t=arguments;return this._context.createRadialGradient(t[0],t[1],t[2],t[3],t[4],t[5])},drawImage:function(){var t=arguments,e=this._context;3===t.length?e.drawImage(t[0],t[1],t[2]):5===t.length?e.drawImage(t[0],t[1],t[2],t[3],t[4]):9===t.length&&e.drawImage(t[0],t[1],t[2],t[3],t[4],t[5],t[6],t[7],t[8])},isPointInPath:function(t,e){return this._context.isPointInPath(t,e)},fill:function(){this._context.fill()},fillRect:function(t,e,i,n){this._context.fillRect(t,e,i,n)},strokeRect:function(t,e,i,n){this._context.strokeRect(t,e,i,n)},fillText:function(){var t=arguments;this._context.fillText(t[0],t[1],t[2])},measureText:function(t){return this._context.measureText(t)},getImageData:function(){var t=arguments;return this._context.getImageData(t[0],t[1],t[2],t[3])},lineTo:function(){var t=arguments;this._context.lineTo(t[0],t[1])},moveTo:function(){var t=arguments;this._context.moveTo(t[0],t[1])},rect:function(){var t=arguments;this._context.rect(t[0],t[1],t[2],t[3])},putImageData:function(){var t=arguments;this._context.putImageData(t[0],t[1],t[2])},quadraticCurveTo:function(){var t=arguments;this._context.quadraticCurveTo(t[0],t[1],t[2],t[3])},restore:function(){this._context.restore()},rotate:function(){var t=arguments;this._context.rotate(t[0])},save:function(){this._context.save()},scale:function(){var t=arguments;this._context.scale(t[0],t[1])},setLineDash:function(){var t=arguments,e=this._context;this._context.setLineDash?e.setLineDash(t[0]):"mozDash"in e?e.mozDash=t[0]:"webkitLineDash"in e&&(e.webkitLineDash=t[0])},getLineDash:function(){return this._context.getLineDash()},setTransform:function(){var t=arguments;this._context.setTransform(t[0],t[1],t[2],t[3],t[4],t[5])},stroke:function(){this._context.stroke()},strokeText:function(){var t=arguments;this._context.strokeText(t[0],t[1],t[2])},transform:function(){var t=arguments;this._context.transform(t[0],t[1],t[2],t[3],t[4],t[5])},translate:function(){var t=arguments;this._context.translate(t[0],t[1])},_enableTrace:function(){var t,n,a=this,e=s.length,r=Konva.Util._simplifyArray,i=this.setAttr,o=function(t){var e,i=a[t];a[t]=function(){return n=r(Array.prototype.slice.call(arguments,0)),e=i.apply(a,arguments),a._trace({method:t,args:n}),e}};for(t=0;t>I,0!==C?(C=255/C,F[s]=(l*U>>I)*C,F[s+1]=(c*U>>I)*C,F[s+2]=(d*U>>I)*C):F[s]=F[s+1]=F[s+2]=0,l-=g,c-=f,d-=v,u-=p,g-=O.r,f-=O.g,v-=O.b,p-=O.a,r=h+((r=i+e+1)>I,0>I)*C,F[r+1]=(c*U>>I)*C,F[r+2]=(d*U>>I)*C):F[r]=F[r+1]=F[r+2]=0,l-=g,c-=f,d-=v,u-=p,g-=O.r,f-=O.g,v-=O.b,p-=O.a,r=i+((r=n+G)>16&255,g:e>>8&255,b:255&e}},getRandomColor:function(){for(var t=(16777215*Math.random()<<0).toString(16);t.length<6;)t="0"+t;return"#"+t},get:function(t,e){return void 0===t?e:t},getRGB:function(t){var e;return t in a?{r:(e=a[t])[0],g:e[1],b:e[2]}:"#"===t[0]?this._hexToRgb(t.substring(1)):"rgb("===t.substr(0,4)?(e=r.exec(t.replace(/ /g,"")),{r:parseInt(e[1],10),g:parseInt(e[2],10),b:parseInt(e[3],10)}):{r:0,g:0,b:0}},colorToRGBA:function(t){return t=t||"black",Konva.Util._namedColorToRBA(t)||Konva.Util._hex3ColorToRGBA(t)||Konva.Util._hex6ColorToRGBA(t)||Konva.Util._rgbColorToRGBA(t)||Konva.Util._rgbaColorToRGBA(t)},_namedColorToRBA:function(t){var e=a[t.toLowerCase()];return e?{r:e[0],g:e[1],b:e[2],a:1}:null},_rgbColorToRGBA:function(t){if(0===t.indexOf("rgb(")){var e=(t=t.match(/rgb\(([^)]+)\)/)[1]).split(/ *, */).map(Number);return{r:e[0],g:e[1],b:e[2],a:1}}},_rgbaColorToRGBA:function(t){if(0===t.indexOf("rgba(")){var e=(t=t.match(/rgba\(([^)]+)\)/)[1]).split(/ *, */).map(Number);return{r:e[0],g:e[1],b:e[2],a:e[3]}}},_hex6ColorToRGBA:function(t){if("#"===t[0]&&7===t.length)return{r:parseInt(t.slice(1,3),16),g:parseInt(t.slice(3,5),16),b:parseInt(t.slice(5,7),16),a:1}},_hex3ColorToRGBA:function(t){if("#"===t[0]&&4===t.length)return{r:parseInt(t[1]+t[1],16),g:parseInt(t[2]+t[2],16),b:parseInt(t[3]+t[3],16),a:1}},_merge:function(t,e){var i=this._clone(e);for(var n in t)this._isObject(t[n])?i[n]=this._merge(t[n],i[n]):i[n]=t[n];return i},trimRight:function(t){return t.replace(/\s+$/,"")},trimLeft:function(t){return t.replace(/^\s+/,"")},haveIntersection:function(t,e){return!(e.x>t.x+t.width||e.x+e.widtht.y+t.height||e.y+e.heighte.length){var o=e;e=t,t=o}for(n=0;n=Konva.traceArrMax&&e.shift()},reset:function(){var t=this.getCanvas().getPixelRatio();this.setTransform(1*t,0,0,1*t,0,0)},getCanvas:function(){return this.canvas},clear:function(t){var e=this.getCanvas();t?this.clearRect(t.x||0,t.y||0,t.width||0,t.height||0):this.clearRect(0,0,e.getWidth()/e.pixelRatio,e.getHeight()/e.pixelRatio)},_applyLineCap:function(t){var e=t.getLineCap();e&&this.setAttr("lineCap",e)},_applyOpacity:function(t){var e=t.getAbsoluteOpacity();1!==e&&this.setAttr("globalAlpha",e)},_applyLineJoin:function(t){var e=t.getLineJoin();e&&this.setAttr("lineJoin",e)},setAttr:function(t,e){this._context[t]=e},arc:function(){var t=arguments;this._context.arc(t[0],t[1],t[2],t[3],t[4],t[5])},beginPath:function(){this._context.beginPath()},bezierCurveTo:function(){var t=arguments;this._context.bezierCurveTo(t[0],t[1],t[2],t[3],t[4],t[5])},clearRect:function(){var t=arguments;this._context.clearRect(t[0],t[1],t[2],t[3])},clip:function(){this._context.clip()},closePath:function(){this._context.closePath()},createImageData:function(){var t=arguments;return 2===t.length?this._context.createImageData(t[0],t[1]):1===t.length?this._context.createImageData(t[0]):void 0},createLinearGradient:function(){var t=arguments;return this._context.createLinearGradient(t[0],t[1],t[2],t[3])},createPattern:function(){var t=arguments;return this._context.createPattern(t[0],t[1])},createRadialGradient:function(){var t=arguments;return this._context.createRadialGradient(t[0],t[1],t[2],t[3],t[4],t[5])},drawImage:function(){var t=arguments,e=this._context;3===t.length?e.drawImage(t[0],t[1],t[2]):5===t.length?e.drawImage(t[0],t[1],t[2],t[3],t[4]):9===t.length&&e.drawImage(t[0],t[1],t[2],t[3],t[4],t[5],t[6],t[7],t[8])},isPointInPath:function(t,e){return this._context.isPointInPath(t,e)},fill:function(){this._context.fill()},fillRect:function(t,e,i,n){this._context.fillRect(t,e,i,n)},strokeRect:function(t,e,i,n){this._context.strokeRect(t,e,i,n)},fillText:function(){var t=arguments;this._context.fillText(t[0],t[1],t[2])},measureText:function(t){return this._context.measureText(t)},getImageData:function(){var t=arguments;return this._context.getImageData(t[0],t[1],t[2],t[3])},lineTo:function(){var t=arguments;this._context.lineTo(t[0],t[1])},moveTo:function(){var t=arguments;this._context.moveTo(t[0],t[1])},rect:function(){var t=arguments;this._context.rect(t[0],t[1],t[2],t[3])},putImageData:function(){var t=arguments;this._context.putImageData(t[0],t[1],t[2])},quadraticCurveTo:function(){var t=arguments;this._context.quadraticCurveTo(t[0],t[1],t[2],t[3])},restore:function(){this._context.restore()},rotate:function(){var t=arguments;this._context.rotate(t[0])},save:function(){this._context.save()},scale:function(){var t=arguments;this._context.scale(t[0],t[1])},setLineDash:function(){var t=arguments,e=this._context;this._context.setLineDash?e.setLineDash(t[0]):"mozDash"in e?e.mozDash=t[0]:"webkitLineDash"in e&&(e.webkitLineDash=t[0])},getLineDash:function(){return this._context.getLineDash()},setTransform:function(){var t=arguments;this._context.setTransform(t[0],t[1],t[2],t[3],t[4],t[5])},stroke:function(){this._context.stroke()},strokeText:function(){var t=arguments;this._context.strokeText(t[0],t[1],t[2])},transform:function(){var t=arguments;this._context.transform(t[0],t[1],t[2],t[3],t[4],t[5])},translate:function(){var t=arguments;this._context.translate(t[0],t[1])},_enableTrace:function(){var t,n,a=this,e=s.length,r=Konva.Util._simplifyArray,i=this.setAttr,o=function(t){var e,i=a[t];a[t]=function(){return n=r(Array.prototype.slice.call(arguments,0)),e=i.apply(a,arguments),a._trace({method:t,args:n}),e}};for(t=0;t>I,0!==C?(C=255/C,F[s]=(l*U>>I)*C,F[s+1]=(c*U>>I)*C,F[s+2]=(d*U>>I)*C):F[s]=F[s+1]=F[s+2]=0,l-=g,c-=f,d-=v,u-=p,g-=O.r,f-=O.g,v-=O.b,p-=O.a,r=h+((r=i+e+1)>I,0>I)*C,F[r+1]=(c*U>>I)*C,F[r+2]=(d*U>>I)*C):F[r]=F[r+1]=F[r+2]=0,l-=g,c-=f,d-=v,u-=p,g-=O.r,f-=O.g,v-=O.b,p-=O.a,r=i+((r=n+G)this.duration?this.yoyo?(this._time=this.duration,this.reverse()):this.finish():t<0?this.yoyo?(this._time=0,this.play()):this.reset():(this._time=t,this.update())},getTime:function(){return this._time},setPosition:function(t){this.prevPos=this._pos,this.propFunc(t),this._pos=t},getPosition:function(t){return void 0===t&&(t=this._time),this.func(t,this.begin,this._change,this.duration)},play:function(){this.state=2,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire("onPlay")},reverse:function(){this.state=3,this._time=this.duration-this._time,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire("onReverse")},seek:function(t){this.pause(),this._time=t,this.update(),this.fire("onSeek")},reset:function(){this.pause(),this._time=0,this.update(),this.fire("onReset")},finish:function(){this.pause(),this._time=this.duration,this.update(),this.fire("onFinish")},update:function(){this.setPosition(this.getPosition(this._time))},onEnterFrame:function(){var t=this.getTimer()-this._startTime;2===this.state?this.setTime(t):3===this.state&&this.setTime(this.duration-t)},pause:function(){this.state=1,this.fire("onPause")},getTimer:function(){return(new Date).getTime()}},Konva.Tween=function(t){var e,i,n=this,a=t.node,r=a._id,o=t.easing||Konva.Easings.Linear,s=!!t.yoyo;e=void 0===t.duration?.3:0===t.duration?.001:t.duration,this.node=a,this._id=c++;var h=a.getLayer()||(a instanceof Konva.Stage?a.getLayers():null);for(i in h||Konva.Util.error("Tween constructor have `node` that is not in a layer. Please add node into layer first."),this.anim=new Konva.Animation(function(){n.tween.onEnterFrame()},h),this.tween=new d(i,function(t){n._tweenFunc(t)},o,0,1,1e3*e,s),this._addListeners(),Konva.Tween.attrs[r]||(Konva.Tween.attrs[r]={}),Konva.Tween.attrs[r][this._id]||(Konva.Tween.attrs[r][this._id]={}),Konva.Tween.tweens[r]||(Konva.Tween.tweens[r]={}),t)void 0===l[i]&&this._addAttr(i,t[i]);this.reset(),this.onFinish=t.onFinish,this.onReset=t.onReset},Konva.Tween.attrs={},Konva.Tween.tweens={},Konva.Tween.prototype={_addAttr:function(t,e){var i,n,a,r,o,s,h,l,c=this.node,d=c._id;if((a=Konva.Tween.tweens[d][t])&&delete Konva.Tween.attrs[d][a][t],i=c.getAttr(t),Konva.Util._isArray(e))if(n=[],o=Math.max(e.length,i.length),"points"===t&&e.length!==i.length&&(e.length>i.length?(h=i,i=Konva.Util._prepareArrayForTween(i,e,c.closed())):(s=e,e=Konva.Util._prepareArrayForTween(e,i,c.closed()))),0===t.indexOf("fill"))for(r=0;r>>1,F=_.slice(0,w+1),T=this._getTextWidth(F)+y;T<=l?(S=w+1,x=F+(v?"…":""),C=T):b=w}if(!x)break;if(f){var P,A=_[x.length];0<(P=(" "===A||"-"===A)&&C<=l?x.length:Math.max(x.lastIndexOf(" "),x.lastIndexOf("-"))+1)&&(S=P,x=x.slice(0,S),C=this._getTextWidth(x))}if(x=Konva.Util.trimRight(x),this._addTextLine(x),i=Math.max(i,C),d+=n,!g||s&&cthis.dataArray[i].pathLength;)t-=this.dataArray[i].pathLength,++i;if(i===n)return{x:(e=this.dataArray[i-1].points.slice(-2))[0],y:e[1]};if(t<.01)return{x:(e=this.dataArray[i].points.slice(0,2))[0],y:e[1]};var a=this.dataArray[i],r=a.points;switch(a.command){case"L":return Konva.Path.getPointOnLine(t,a.start.x,a.start.y,r[0],r[1]);case"C":return Konva.Path.getPointOnCubicBezier(t/a.pathLength,a.start.x,a.start.y,r[0],r[1],r[2],r[3],r[4],r[5]);case"Q":return Konva.Path.getPointOnQuadraticBezier(t/a.pathLength,a.start.x,a.start.y,r[0],r[1],r[2],r[3]);case"A":var o=r[0],s=r[1],h=r[2],l=r[3],c=r[4],d=r[5],u=r[6];return c+=d*t/a.pathLength,Konva.Path.getPointOnEllipticalArc(o,s,h,l,c,u)}return null}},Konva.Util.extend(Konva.Path,Konva.Shape),Konva.Path.getLineLength=function(t,e,i,n){return Math.sqrt((i-t)*(i-t)+(n-e)*(n-e))},Konva.Path.getPointOnLine=function(t,e,i,n,a,r,o){void 0===r&&(r=e),void 0===o&&(o=i);var s=(a-i)/(n-e+1e-8),h=Math.sqrt(t*t/(1+s*s));ne?v=Konva.Path.getPointOnLine(e,f.x,f.y,p.points[0],p.points[1],f.x,f.y):p=void 0;break;case"A":var o=p.points[4],s=p.points[5],h=p.points[4]+s;0===_?_=o+1e-8:ip.pathLength?1e-8:e/p.pathLength:ithis.duration?this.yoyo?(this._time=this.duration,this.reverse()):this.finish():t<0?this.yoyo?(this._time=0,this.play()):this.reset():(this._time=t,this.update())},getTime:function(){return this._time},setPosition:function(t){this.prevPos=this._pos,this.propFunc(t),this._pos=t},getPosition:function(t){return void 0===t&&(t=this._time),this.func(t,this.begin,this._change,this.duration)},play:function(){this.state=2,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire("onPlay")},reverse:function(){this.state=3,this._time=this.duration-this._time,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire("onReverse")},seek:function(t){this.pause(),this._time=t,this.update(),this.fire("onSeek")},reset:function(){this.pause(),this._time=0,this.update(),this.fire("onReset")},finish:function(){this.pause(),this._time=this.duration,this.update(),this.fire("onFinish")},update:function(){this.setPosition(this.getPosition(this._time))},onEnterFrame:function(){var t=this.getTimer()-this._startTime;2===this.state?this.setTime(t):3===this.state&&this.setTime(this.duration-t)},pause:function(){this.state=1,this.fire("onPause")},getTimer:function(){return(new Date).getTime()}},Konva.Tween=function(t){var e,i,n=this,a=t.node,r=a._id,o=t.easing||Konva.Easings.Linear,s=!!t.yoyo;e=void 0===t.duration?.3:0===t.duration?.001:t.duration,this.node=a,this._id=c++;var h=a.getLayer()||(a instanceof Konva.Stage?a.getLayers():null);for(i in h||Konva.Util.error("Tween constructor have `node` that is not in a layer. Please add node into layer first."),this.anim=new Konva.Animation(function(){n.tween.onEnterFrame()},h),this.tween=new d(i,function(t){n._tweenFunc(t)},o,0,1,1e3*e,s),this._addListeners(),Konva.Tween.attrs[r]||(Konva.Tween.attrs[r]={}),Konva.Tween.attrs[r][this._id]||(Konva.Tween.attrs[r][this._id]={}),Konva.Tween.tweens[r]||(Konva.Tween.tweens[r]={}),t)void 0===l[i]&&this._addAttr(i,t[i]);this.reset(),this.onFinish=t.onFinish,this.onReset=t.onReset},Konva.Tween.attrs={},Konva.Tween.tweens={},Konva.Tween.prototype={_addAttr:function(t,e){var i,n,a,r,o,s,h,l,c=this.node,d=c._id;if((a=Konva.Tween.tweens[d][t])&&delete Konva.Tween.attrs[d][a][t],i=c.getAttr(t),Konva.Util._isArray(e))if(n=[],o=Math.max(e.length,i.length),"points"===t&&e.length!==i.length&&(e.length>i.length?(h=i,i=Konva.Util._prepareArrayForTween(i,e,c.closed())):(s=e,e=Konva.Util._prepareArrayForTween(e,i,c.closed()))),0===t.indexOf("fill"))for(r=0;r>>1,F=_.slice(0,w+1),T=this._getTextWidth(F)+y;T<=l?(S=w+1,x=F+(v?"…":""),C=T):b=w}if(!x)break;if(f){var P,A=_[x.length];0<(P=(" "===A||"-"===A)&&C<=l?x.length:Math.max(x.lastIndexOf(" "),x.lastIndexOf("-"))+1)&&(S=P,x=x.slice(0,S),C=this._getTextWidth(x))}if(x=Konva.Util.trimRight(x),this._addTextLine(x),i=Math.max(i,C),d+=n,!g||s&&cthis.dataArray[i].pathLength;)t-=this.dataArray[i].pathLength,++i;if(i===n)return{x:(e=this.dataArray[i-1].points.slice(-2))[0],y:e[1]};if(t<.01)return{x:(e=this.dataArray[i].points.slice(0,2))[0],y:e[1]};var a=this.dataArray[i],r=a.points;switch(a.command){case"L":return Konva.Path.getPointOnLine(t,a.start.x,a.start.y,r[0],r[1]);case"C":return Konva.Path.getPointOnCubicBezier(t/a.pathLength,a.start.x,a.start.y,r[0],r[1],r[2],r[3],r[4],r[5]);case"Q":return Konva.Path.getPointOnQuadraticBezier(t/a.pathLength,a.start.x,a.start.y,r[0],r[1],r[2],r[3]);case"A":var o=r[0],s=r[1],h=r[2],l=r[3],c=r[4],d=r[5],u=r[6];return c+=d*t/a.pathLength,Konva.Path.getPointOnEllipticalArc(o,s,h,l,c,u)}return null}},Konva.Util.extend(Konva.Path,Konva.Shape),Konva.Path.getLineLength=function(t,e,i,n){return Math.sqrt((i-t)*(i-t)+(n-e)*(n-e))},Konva.Path.getPointOnLine=function(t,e,i,n,a,r,o){void 0===r&&(r=e),void 0===o&&(o=i);var s=(a-i)/(n-e+1e-8),h=Math.sqrt(t*t/(1+s*s));ne?v=Konva.Path.getPointOnLine(e,f.x,f.y,p.points[0],p.points[1],f.x,f.y):p=void 0;break;case"A":var o=p.points[4],s=p.points[5],h=p.points[4]+s;0===_?_=o+1e-8:ip.pathLength?1e-8:e/p.pathLength:i