From 738cc8b79c1fd0afd1f4b6e711e030788a57f412 Mon Sep 17 00:00:00 2001 From: Anton Lavrenov Date: Tue, 21 Aug 2018 15:56:04 +0700 Subject: [PATCH] Automatic validations for many attributes. close #436 --- CHANGELOG.md | 3 +- konva.js | 738 +++++++++++++++++++++++++----- konva.min.js | 4 +- src/Container.js | 28 +- src/Factory.js | 113 ++++- src/Node.js | 135 +++++- src/Shape.js | 126 ++++- src/Util.js | 10 +- src/filters/Blur.js | 2 +- src/filters/Brighten.js | 2 +- src/filters/Contrast.js | 2 +- src/filters/Emboss.js | 4 +- src/filters/Enhance.js | 2 +- src/filters/HSL.js | 6 +- src/filters/HSV.js | 6 +- src/filters/Kaleidoscope.js | 4 +- src/filters/Mask.js | 2 +- src/filters/Noise.js | 2 +- src/filters/Pixelate.js | 2 +- src/filters/Posterize.js | 2 +- src/filters/Threshold.js | 2 +- src/shapes/Arc.js | 21 +- src/shapes/Arrow.js | 14 +- src/shapes/Circle.js | 7 +- src/shapes/Ellipse.js | 14 +- src/shapes/Image.js | 28 +- src/shapes/Label.js | 21 +- src/shapes/Line.js | 14 +- src/shapes/Rect.js | 7 +- src/shapes/RegularPolygon.js | 14 +- src/shapes/Ring.js | 14 +- src/shapes/Sprite.js | 14 +- src/shapes/Star.js | 21 +- src/shapes/Text.js | 40 +- src/shapes/TextPath.js | 14 +- src/shapes/Transformer.js | 35 +- src/shapes/Wedge.js | 14 +- test/unit/Container-test.js | 2 +- test/unit/Node-cache-test.js | 6 +- test/unit/Node-test.js | 4 +- test/unit/shapes/TextPath-test.js | 16 +- 41 files changed, 1289 insertions(+), 226 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f4a5acf..33459c0d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,8 @@ This project adheres to [Semantic Versioning](http://semver.org/). ### Changed * Default duration for tweens and `node.to()` methods is now 300ms - +* Typescript fixes +* Automatic validations for many attributes ## [2.2.1][2018-08-10] diff --git a/konva.js b/konva.js index e6182aa6..e26c0e06 100644 --- a/konva.js +++ b/konva.js @@ -559,6 +559,7 @@ OBJECT_ARRAY = '[object Array]', OBJECT_NUMBER = '[object Number]', OBJECT_STRING = '[object String]', + OBJECT_BOOLEAN = '[object Boolean]', PI_OVER_DEG180 = Math.PI / 180, DEG180_OVER_PI = 180 / Math.PI, HASH = '#', @@ -746,6 +747,9 @@ _isString: function(obj) { return Object.prototype.toString.call(obj) === OBJECT_STRING; }, + _isBoolean: function(obj) { + return Object.prototype.toString.call(obj) === OBJECT_BOOLEAN; + }, // arrays are objects too isObject: function(val) { return val instanceof Object; @@ -2215,11 +2219,14 @@ }; }, addSetter: function(constructor, attr, validator, after) { + // if (!validator && validator !== null) { + // console.error(constructor, attr, 'has no validator.'); + // } var method = SET + Konva.Util._capitalize(attr); constructor.prototype[method] = function(val) { - if (validator) { - val = validator.call(this, val); + if (validator && val !== undefined && val !== null) { + val = validator.call(this, val, attr); } this._setAttr(attr, val); @@ -2365,6 +2372,114 @@ } return val; + }, + _formatValue: function(val) { + if (Konva.Util._isString(val)) { + return '"' + val + '"'; + } + if (Konva.Util._isNumber(val)) { + return val; + } + if (Konva.Util._isBoolean(val)) { + return val; + } + return Object.prototype.toString.call(val); + }, + getNumberValidator: function() { + return function(val, attr) { + if (!Konva.Util._isNumber(val) || isNaN(val)) { + Konva.Util.warn( + Konva.Validators._formatValue(val) + + ' is a not valid value for "' + + attr + + '" attribute. The value should be a number.' + ); + return 0; + } + return val; + }; + }, + getNumberOrAutoValidator: function() { + return function(val, attr) { + var isNumber = Konva.Util._isNumber(val) && !isNaN(val); + var isAuto = val === 'auto'; + + if (!(isNumber || isAuto)) { + Konva.Util.warn( + Konva.Validators._formatValue(val) + + ' is a not valid value for "' + + attr + + '" attribute. The value should be a number or "auto".' + ); + return 0; + } + return val; + }; + }, + getStringValidator: function() { + return function(val, attr) { + if (!Konva.Util._isString(val)) { + Konva.Util.warn( + Konva.Validators._formatValue(val) + + ' is a not valid value for "' + + attr + + '" attribute. The value should be a string.' + ); + } + return val; + }; + }, + getFunctionValidator: function() { + return function(val, attr) { + if (!Konva.Util._isFunction(val)) { + Konva.Util.warn( + Konva.Validators._formatValue(val) + + ' is a not valid value for "' + + attr + + '" attribute. The value should be a function.' + ); + } + return val; + }; + }, + getNumberArrayValidator: function() { + return function(val, attr) { + if (!Konva.Util._isArray(val)) { + Konva.Util.warn( + Konva.Validators._formatValue(val) + + ' is a not valid value for "' + + attr + + '" attribute. The value should be a array of numbers.' + ); + } else { + val.forEach(function(item) { + if (!Konva.Util._isNumber(item) || isNaN(item)) { + Konva.Util.warn( + '"' + + attr + + '" attribute has non numeric element ' + + item + + '. Make sure that all elements are numbers.' + ); + } + }); + } + return val; + }; + }, + getBooleanValidator: function() { + return function(val, attr) { + var isBool = val === true || val === false; + if (!isBool) { + Konva.Util.warn( + Konva.Validators._formatValue(val) + + ' is a not valid value for "' + + attr + + '" attribute. The value should be a boolean.' + ); + } + return val; + }; } }; })(); @@ -4439,7 +4554,12 @@ * }); */ - Konva.Factory.addGetterSetter(Konva.Node, 'x', 0); + Konva.Factory.addGetterSetter( + Konva.Node, + 'x', + 0, + Konva.Validators.getNumberValidator() + ); /** * get/set x position @@ -4456,7 +4576,12 @@ * node.x(5); */ - Konva.Factory.addGetterSetter(Konva.Node, 'y', 0); + Konva.Factory.addGetterSetter( + Konva.Node, + 'y', + 0, + Konva.Validators.getNumberValidator() + ); /** * get/set y position @@ -4476,7 +4601,8 @@ Konva.Factory.addGetterSetter( Konva.Node, 'globalCompositeOperation', - 'source-over' + 'source-over', + Konva.Validators.getStringValidator() ); /** @@ -4493,7 +4619,12 @@ * // set globalCompositeOperation * shape.globalCompositeOperation('source-in'); */ - Konva.Factory.addGetterSetter(Konva.Node, 'opacity', 1); + Konva.Factory.addGetterSetter( + Konva.Node, + 'opacity', + 1, + Konva.Validators.getNumberValidator() + ); /** * get/set opacity. Opacity values range from 0 to 1. @@ -4551,7 +4682,12 @@ * node.id('foo'); */ - Konva.Factory.addGetterSetter(Konva.Node, 'rotation', 0); + Konva.Factory.addGetterSetter( + Konva.Node, + 'rotation', + 0, + Konva.Validators.getNumberValidator() + ); /** * get/set rotation in degrees @@ -4590,7 +4726,12 @@ * }); */ - Konva.Factory.addGetterSetter(Konva.Node, 'scaleX', 1); + Konva.Factory.addGetterSetter( + Konva.Node, + 'scaleX', + 1, + Konva.Validators.getNumberValidator() + ); /** * get/set scale x @@ -4607,7 +4748,12 @@ * node.scaleX(2); */ - Konva.Factory.addGetterSetter(Konva.Node, 'scaleY', 1); + Konva.Factory.addGetterSetter( + Konva.Node, + 'scaleY', + 1, + Konva.Validators.getNumberValidator() + ); /** * get/set scale y @@ -4646,7 +4792,12 @@ * }); */ - Konva.Factory.addGetterSetter(Konva.Node, 'skewX', 0); + Konva.Factory.addGetterSetter( + Konva.Node, + 'skewX', + 0, + Konva.Validators.getNumberValidator() + ); /** * get/set skew x @@ -4663,7 +4814,12 @@ * node.skewX(3); */ - Konva.Factory.addGetterSetter(Konva.Node, 'skewY', 0); + Konva.Factory.addGetterSetter( + Konva.Node, + 'skewY', + 0, + Konva.Validators.getNumberValidator() + ); /** * get/set skew y @@ -4701,7 +4857,12 @@ * }); */ - Konva.Factory.addGetterSetter(Konva.Node, 'offsetX', 0); + Konva.Factory.addGetterSetter( + Konva.Node, + 'offsetX', + 0, + Konva.Validators.getNumberValidator() + ); /** * get/set offset x @@ -4718,7 +4879,12 @@ * node.offsetX(3); */ - Konva.Factory.addGetterSetter(Konva.Node, 'offsetY', 0); + Konva.Factory.addGetterSetter( + Konva.Node, + 'offsetY', + 0, + Konva.Validators.getNumberValidator() + ); /** * get/set offset y @@ -4735,7 +4901,11 @@ * node.offsetY(3); */ - Konva.Factory.addSetter(Konva.Node, 'dragDistance'); + Konva.Factory.addSetter( + Konva.Node, + 'dragDistance', + Konva.Validators.getNumberValidator() + ); Konva.Factory.addOverloadedGetterSetter(Konva.Node, 'dragDistance'); /** @@ -4756,7 +4926,11 @@ * Konva.dragDistance = 3; */ - Konva.Factory.addSetter(Konva.Node, 'width', 0); + Konva.Factory.addSetter( + Konva.Node, + 'width', + Konva.Validators.getNumberValidator() + ); Konva.Factory.addOverloadedGetterSetter(Konva.Node, 'width'); /** * get/set width @@ -4773,7 +4947,11 @@ * node.width(100); */ - Konva.Factory.addSetter(Konva.Node, 'height', 0); + Konva.Factory.addSetter( + Konva.Node, + 'height', + Konva.Validators.getNumberValidator() + ); Konva.Factory.addOverloadedGetterSetter(Konva.Node, 'height'); /** * get/set height @@ -4790,7 +4968,18 @@ * node.height(100); */ - Konva.Factory.addGetterSetter(Konva.Node, 'listening', 'inherit'); + Konva.Factory.addGetterSetter(Konva.Node, 'listening', 'inherit', function( + val + ) { + var isValid = val === true || val === false || val === 'inherit'; + if (!isValid) { + Konva.Util.warn( + val + + ' is a not valid value for "listening" attribute. The value may be true, false or "inherit".' + ); + } + return val; + }); /** * get/set listenig attr. If you need to determine if a node is listening or not * by taking into account its parents, use the isListening() method @@ -4833,11 +5022,14 @@ * shape.preventDefault(false); */ - Konva.Factory.addGetterSetter(Konva.Node, 'preventDefault', true); + Konva.Factory.addGetterSetter( + Konva.Node, + 'preventDefault', + true, + Konva.Validators.getBooleanValidator() + ); - Konva.Factory.addGetterSetter(Konva.Node, 'filters', undefined, function( - val - ) { + Konva.Factory.addGetterSetter(Konva.Node, 'filters', null, function(val) { this._filterUpToDate = false; return val; }); @@ -4865,7 +5057,18 @@ * ]); */ - Konva.Factory.addGetterSetter(Konva.Node, 'visible', 'inherit'); + Konva.Factory.addGetterSetter(Konva.Node, 'visible', 'inherit', function( + val + ) { + var isValid = val === true || val === false || val === 'inherit'; + if (!isValid) { + Konva.Util.warn( + val + + ' is a not valid value for "visible" attribute. The value may be true, false or "inherit".' + ); + } + return val; + }); /** * get/set visible attr. Can be "inherit", true, or false. The default is "inherit". * If you need to determine if a node is visible or not @@ -4889,7 +5092,12 @@ * node.visible('inherit'); */ - Konva.Factory.addGetterSetter(Konva.Node, 'transformsEnabled', 'all'); + Konva.Factory.addGetterSetter( + Konva.Node, + 'transformsEnabled', + 'all', + Konva.Validators.getStringValidator() + ); /** * get/set transforms that are enabled. Can be "all", "none", or "position". The default @@ -5000,7 +5208,7 @@ Konva.Node, 'brightness', 0, - null, + Konva.Validators.getNumberValidator(), Konva.Factory.afterSetFilter ); /** @@ -5882,7 +6090,7 @@ Konva.Node, 'blurRadius', 0, - null, + Konva.Validators.getNumberValidator(), Konva.Factory.afterSetFilter ); @@ -6113,7 +6321,7 @@ Konva.Node, 'threshold', 0, - null, + Konva.Validators.getNumberValidator(), Konva.Factory.afterSetFilter ); })(); @@ -6382,7 +6590,7 @@ Konva.Node, 'hue', 0, - null, + Konva.Validators.getNumberValidator(), Konva.Factory.afterSetFilter ); /** @@ -6398,7 +6606,7 @@ Konva.Node, 'saturation', 0, - null, + Konva.Validators.getNumberValidator(), Konva.Factory.afterSetFilter ); /** @@ -6414,7 +6622,7 @@ Konva.Node, 'value', 0, - null, + Konva.Validators.getNumberValidator(), Konva.Factory.afterSetFilter ); /** @@ -6433,7 +6641,7 @@ Konva.Node, 'hue', 0, - null, + Konva.Validators.getNumberValidator(), Konva.Factory.afterSetFilter ); /** @@ -6449,7 +6657,7 @@ Konva.Node, 'saturation', 0, - null, + Konva.Validators.getNumberValidator(), Konva.Factory.afterSetFilter ); /** @@ -6465,7 +6673,7 @@ Konva.Node, 'luminance', 0, - null, + Konva.Validators.getNumberValidator(), Konva.Factory.afterSetFilter ); /** @@ -6682,7 +6890,7 @@ Konva.Node, 'embossStrength', 0.5, - null, + Konva.Validators.getNumberValidator(), Konva.Factory.afterSetFilter ); /** @@ -6698,7 +6906,7 @@ Konva.Node, 'embossWhiteLevel', 0.5, - null, + Konva.Validators.getNumberValidator(), Konva.Factory.afterSetFilter ); /** @@ -6892,7 +7100,7 @@ Konva.Node, 'enhance', 0, - null, + Konva.Validators.getNumberValidator(), Konva.Factory.afterSetFilter ); })(); @@ -6931,7 +7139,7 @@ Konva.Node, 'levels', 0.5, - null, + Konva.Validators.getNumberValidator(), Konva.Factory.afterSetFilter ); @@ -6977,7 +7185,7 @@ Konva.Node, 'noise', 0.2, - null, + Konva.Validators.getNumberValidator(), Konva.Factory.afterSetFilter ); /** @@ -7098,7 +7306,7 @@ Konva.Node, 'pixelSize', 8, - null, + Konva.Validators.getNumberValidator(), Konva.Factory.afterSetFilter ); /** @@ -7143,7 +7351,7 @@ Konva.Node, 'threshold', 0.5, - null, + Konva.Validators.getNumberValidator(), Konva.Factory.afterSetFilter ); /** @@ -7535,7 +7743,7 @@ Konva.Node, 'kaleidoscopePower', 2, - null, + Konva.Validators.getNumberValidator(), Konva.Factory.afterSetFilter ); @@ -7551,7 +7759,7 @@ Konva.Node, 'kaleidoscopeAngle', 0, - null, + Konva.Validators.getNumberValidator(), Konva.Factory.afterSetFilter ); })(); @@ -7628,7 +7836,7 @@ Konva.Node, 'contrast', 0, - null, + Konva.Validators.getNumberValidator(), Konva.Factory.afterSetFilter ); })(Konva); @@ -8257,7 +8465,12 @@ * }); */ - Konva.Factory.addGetterSetter(Konva.Container, 'clipX'); + Konva.Factory.addGetterSetter( + Konva.Container, + 'clipX', + undefined, + Konva.Validators.getNumberValidator() + ); /** * get/set clip x * @name clipX @@ -8273,7 +8486,12 @@ * container.clipX(10); */ - Konva.Factory.addGetterSetter(Konva.Container, 'clipY'); + Konva.Factory.addGetterSetter( + Konva.Container, + 'clipY', + undefined, + Konva.Validators.getNumberValidator() + ); /** * get/set clip y * @name clipY @@ -8289,7 +8507,12 @@ * container.clipY(10); */ - Konva.Factory.addGetterSetter(Konva.Container, 'clipWidth'); + Konva.Factory.addGetterSetter( + Konva.Container, + 'clipWidth', + undefined, + Konva.Validators.getNumberValidator() + ); /** * get/set clip width * @name clipWidth @@ -8305,7 +8528,12 @@ * container.clipWidth(100); */ - Konva.Factory.addGetterSetter(Konva.Container, 'clipHeight'); + Konva.Factory.addGetterSetter( + Konva.Container, + 'clipHeight', + undefined, + Konva.Validators.getNumberValidator() + ); /** * get/set clip height * @name clipHeight @@ -8932,7 +9160,12 @@ Konva.Util.extend(Konva.Shape, Konva.Node); // add getters and setters - Konva.Factory.addGetterSetter(Konva.Shape, 'stroke'); + Konva.Factory.addGetterSetter( + Konva.Shape, + 'stroke', + undefined, + Konva.Validators.getStringValidator() + ); /** * get/set stroke color @@ -8958,7 +9191,12 @@ * shape.stroke('rgba(0,255,0,0.5'); */ - Konva.Factory.addGetterSetter(Konva.Shape, 'strokeWidth', 2); + Konva.Factory.addGetterSetter( + Konva.Shape, + 'strokeWidth', + 2, + Konva.Validators.getNumberValidator() + ); /** * get/set stroke width @@ -8975,7 +9213,12 @@ * shape.strokeWidth(); */ - Konva.Factory.addGetterSetter(Konva.Shape, 'strokeHitEnabled', true); + Konva.Factory.addGetterSetter( + Konva.Shape, + 'strokeHitEnabled', + true, + Konva.Validators.getBooleanValidator() + ); /** * get/set strokeHitEnabled property. Useful for performance optimization. @@ -8996,7 +9239,12 @@ * shape.strokeHitEnabled(); */ - Konva.Factory.addGetterSetter(Konva.Shape, 'perfectDrawEnabled', true); + Konva.Factory.addGetterSetter( + Konva.Shape, + 'perfectDrawEnabled', + true, + Konva.Validators.getBooleanValidator() + ); /** * get/set perfectDrawEnabled. If a shape has fill, stroke and opacity you may set `perfectDrawEnabled` to false to improve performance. @@ -9015,7 +9263,12 @@ * shape.perfectDrawEnabled(); */ - Konva.Factory.addGetterSetter(Konva.Shape, 'shadowForStrokeEnabled', true); + Konva.Factory.addGetterSetter( + Konva.Shape, + 'shadowForStrokeEnabled', + true, + Konva.Validators.getBooleanValidator() + ); /** * get/set shadowForStrokeEnabled. Useful for performance optimization. @@ -9132,7 +9385,12 @@ * line.dash([10, 20, 0.001, 20]); */ - Konva.Factory.addGetterSetter(Konva.Shape, 'dashOffset', 0); + Konva.Factory.addGetterSetter( + Konva.Shape, + 'dashOffset', + 0, + Konva.Validators.getNumberValidator() + ); /** * get/set dash offset for stroke. @@ -9147,7 +9405,12 @@ * line.dashOffset(5); */ - Konva.Factory.addGetterSetter(Konva.Shape, 'shadowColor'); + Konva.Factory.addGetterSetter( + Konva.Shape, + 'shadowColor', + undefined, + Konva.Validators.getStringValidator() + ); /** * get/set shadow color @@ -9173,7 +9436,12 @@ * shape.shadowColor('rgba(0,255,0,0.5'); */ - Konva.Factory.addGetterSetter(Konva.Shape, 'shadowBlur'); + Konva.Factory.addGetterSetter( + Konva.Shape, + 'shadowBlur', + 0, + Konva.Validators.getNumberValidator() + ); /** * get/set shadow blur @@ -9190,7 +9458,12 @@ * shape.shadowBlur(10); */ - Konva.Factory.addGetterSetter(Konva.Shape, 'shadowOpacity'); + Konva.Factory.addGetterSetter( + Konva.Shape, + 'shadowOpacity', + 1, + Konva.Validators.getNumberValidator() + ); /** * get/set shadow opacity. must be a value between 0 and 1 @@ -9232,7 +9505,12 @@ * }); */ - Konva.Factory.addGetterSetter(Konva.Shape, 'shadowOffsetX', 0); + Konva.Factory.addGetterSetter( + Konva.Shape, + 'shadowOffsetX', + 0, + Konva.Validators.getNumberValidator() + ); /** * get/set shadow offset x @@ -9249,7 +9527,12 @@ * shape.shadowOffsetX(5); */ - Konva.Factory.addGetterSetter(Konva.Shape, 'shadowOffsetY', 0); + Konva.Factory.addGetterSetter( + Konva.Shape, + 'shadowOffsetY', + 0, + Konva.Validators.getNumberValidator() + ); /** * get/set shadow offset y @@ -9287,7 +9570,12 @@ * imageObj.src = 'path/to/image/jpg'; */ - Konva.Factory.addGetterSetter(Konva.Shape, 'fill'); + Konva.Factory.addGetterSetter( + Konva.Shape, + 'fill', + undefined, + Konva.Validators.getStringValidator() + ); /** * get/set fill color @@ -9316,7 +9604,12 @@ * shape.fill(null); */ - Konva.Factory.addGetterSetter(Konva.Shape, 'fillPatternX', 0); + Konva.Factory.addGetterSetter( + Konva.Shape, + 'fillPatternX', + 0, + Konva.Validators.getNumberValidator() + ); /** * get/set fill pattern x @@ -9332,7 +9625,12 @@ * shape.fillPatternX(20); */ - Konva.Factory.addGetterSetter(Konva.Shape, 'fillPatternY', 0); + Konva.Factory.addGetterSetter( + Konva.Shape, + 'fillPatternY', + 0, + Konva.Validators.getNumberValidator() + ); /** * get/set fill pattern y @@ -9603,7 +9901,12 @@ * }); */ - Konva.Factory.addGetterSetter(Konva.Shape, 'fillPatternOffsetX', 0); + Konva.Factory.addGetterSetter( + Konva.Shape, + 'fillPatternOffsetX', + 0, + Konva.Validators.getNumberValidator() + ); /** * get/set fill pattern offset x @@ -9620,7 +9923,12 @@ * shape.fillPatternOffsetX(20); */ - Konva.Factory.addGetterSetter(Konva.Shape, 'fillPatternOffsetY', 0); + Konva.Factory.addGetterSetter( + Konva.Shape, + 'fillPatternOffsetY', + 0, + Konva.Validators.getNumberValidator() + ); /** * get/set fill pattern offset y @@ -9662,7 +9970,12 @@ * }); */ - Konva.Factory.addGetterSetter(Konva.Shape, 'fillPatternScaleX', 1); + Konva.Factory.addGetterSetter( + Konva.Shape, + 'fillPatternScaleX', + 1, + Konva.Validators.getNumberValidator() + ); /** * get/set fill pattern scale x @@ -9679,7 +9992,12 @@ * shape.fillPatternScaleX(2); */ - Konva.Factory.addGetterSetter(Konva.Shape, 'fillPatternScaleY', 1); + Konva.Factory.addGetterSetter( + Konva.Shape, + 'fillPatternScaleY', + 1, + Konva.Validators.getNumberValidator() + ); /** * get/set fill pattern scale y @@ -13228,7 +13546,12 @@ Konva.Util.extend(Konva.Rect, Konva.Shape); - Konva.Factory.addGetterSetter(Konva.Rect, 'cornerRadius', 0); + Konva.Factory.addGetterSetter( + Konva.Rect, + 'cornerRadius', + 0, + Konva.Validators.getNumberValidator() + ); /** * get/set corner radius * @name cornerRadius @@ -13384,7 +13707,12 @@ Konva.Util.extend(Konva.Circle, Konva.Shape); // add getters setters - Konva.Factory.addGetterSetter(Konva.Circle, 'radius', 0); + Konva.Factory.addGetterSetter( + Konva.Circle, + 'radius', + 0, + Konva.Validators.getNumberValidator() + ); Konva.Factory.addOverloadedGetterSetter(Konva.Circle, 'radius'); /** @@ -13571,7 +13899,12 @@ * }); */ - Konva.Factory.addGetterSetter(Konva.Ellipse, 'radiusX', 0); + Konva.Factory.addGetterSetter( + Konva.Ellipse, + 'radiusX', + 0, + Konva.Validators.getNumberValidator() + ); /** * get/set radius x * @name radiusX @@ -13587,7 +13920,12 @@ * ellipse.radiusX(200); */ - Konva.Factory.addGetterSetter(Konva.Ellipse, 'radiusY', 0); + Konva.Factory.addGetterSetter( + Konva.Ellipse, + 'radiusY', + 0, + Konva.Validators.getNumberValidator() + ); /** * get/set radius y * @name radiusY @@ -13749,7 +14087,12 @@ Konva.Util.extend(Konva.Ring, Konva.Shape); // add getters setters - Konva.Factory.addGetterSetter(Konva.Ring, 'innerRadius', 0); + Konva.Factory.addGetterSetter( + Konva.Ring, + 'innerRadius', + 0, + Konva.Validators.getNumberValidator() + ); /** * get/set innerRadius @@ -13765,7 +14108,12 @@ * // set inner radius * ring.innerRadius(20); */ - Konva.Factory.addGetter(Konva.Ring, 'outerRadius', 0); + Konva.Factory.addGetter( + Konva.Ring, + 'outerRadius', + 0, + Konva.Validators.getNumberValidator() + ); Konva.Factory.addOverloadedGetterSetter(Konva.Ring, 'outerRadius'); /** @@ -13930,7 +14278,12 @@ Konva.Util.extend(Konva.Wedge, Konva.Shape); // add getters setters - Konva.Factory.addGetterSetter(Konva.Wedge, 'radius', 0); + Konva.Factory.addGetterSetter( + Konva.Wedge, + 'radius', + 0, + Konva.Validators.getNumberValidator() + ); /** * get/set radius @@ -13947,7 +14300,12 @@ * wedge.radius(10); */ - Konva.Factory.addGetterSetter(Konva.Wedge, 'angle', 0); + Konva.Factory.addGetterSetter( + Konva.Wedge, + 'angle', + 0, + Konva.Validators.getNumberValidator() + ); /** * get/set angle in degrees @@ -14135,7 +14493,12 @@ Konva.Util.extend(Konva.Arc, Konva.Shape); // add getters setters - Konva.Factory.addGetterSetter(Konva.Arc, 'innerRadius', 0); + Konva.Factory.addGetterSetter( + Konva.Arc, + 'innerRadius', + 0, + Konva.Validators.getNumberValidator() + ); /** * get/set innerRadius @@ -14152,7 +14515,12 @@ * arc.innerRadius(20); */ - Konva.Factory.addGetterSetter(Konva.Arc, 'outerRadius', 0); + Konva.Factory.addGetterSetter( + Konva.Arc, + 'outerRadius', + 0, + Konva.Validators.getNumberValidator() + ); /** * get/set outerRadius @@ -14169,7 +14537,12 @@ * arc.outerRadius(20); */ - Konva.Factory.addGetterSetter(Konva.Arc, 'angle', 0); + Konva.Factory.addGetterSetter( + Konva.Arc, + 'angle', + 0, + Konva.Validators.getNumberValidator() + ); /** * get/set angle in degrees @@ -14433,7 +14806,12 @@ * }); */ - Konva.Factory.addGetterSetter(Konva.Image, 'cropX', 0); + Konva.Factory.addGetterSetter( + Konva.Image, + 'cropX', + 0, + Konva.Validators.getNumberValidator() + ); /** * get/set crop x * @method @@ -14449,7 +14827,12 @@ * image.cropX(20); */ - Konva.Factory.addGetterSetter(Konva.Image, 'cropY', 0); + Konva.Factory.addGetterSetter( + Konva.Image, + 'cropY', + 0, + Konva.Validators.getNumberValidator() + ); /** * get/set crop y * @name cropY @@ -14465,7 +14848,12 @@ * image.cropY(20); */ - Konva.Factory.addGetterSetter(Konva.Image, 'cropWidth', 0); + Konva.Factory.addGetterSetter( + Konva.Image, + 'cropWidth', + 0, + Konva.Validators.getNumberValidator() + ); /** * get/set crop width * @name cropWidth @@ -14481,7 +14869,12 @@ * image.cropWidth(20); */ - Konva.Factory.addGetterSetter(Konva.Image, 'cropHeight', 0); + Konva.Factory.addGetterSetter( + Konva.Image, + 'cropHeight', + 0, + Konva.Validators.getNumberValidator() + ); /** * get/set crop height * @name cropHeight @@ -15070,6 +15463,18 @@ }; Konva.Util.extend(Konva.Text, Konva.Shape); + Konva.Factory.addSetter( + Konva.Node, + 'width', + Konva.Validators.getNumberOrAutoValidator() + ); + + Konva.Factory.addSetter( + Konva.Node, + 'height', + Konva.Validators.getNumberOrAutoValidator() + ); + // add getters setters Konva.Factory.addGetterSetter(Konva.Text, 'fontFamily', 'Arial'); @@ -15088,7 +15493,12 @@ * text.fontFamily('Arial'); */ - Konva.Factory.addGetterSetter(Konva.Text, 'fontSize', 12); + Konva.Factory.addGetterSetter( + Konva.Text, + 'fontSize', + 12, + Konva.Validators.getNumberValidator() + ); /** * get/set font size in pixels @@ -15139,7 +15549,12 @@ * text.fontVariant('small-caps'); */ - Konva.Factory.addGetterSetter(Konva.Text, 'padding', 0); + Konva.Factory.addGetterSetter( + Konva.Text, + 'padding', + 0, + Konva.Validators.getNumberValidator() + ); /** * set padding @@ -15176,7 +15591,12 @@ * text.align('right'); */ - Konva.Factory.addGetterSetter(Konva.Text, 'lineHeight', 1); + Konva.Factory.addGetterSetter( + Konva.Text, + 'lineHeight', + 1, + Konva.Validators.getNumberValidator() + ); /** * get/set line height. The default is 1. @@ -15228,7 +15648,12 @@ * text.ellipsis(true); */ - Konva.Factory.addGetterSetter(Konva.Text, 'letterSpacing', 0); + Konva.Factory.addGetterSetter( + Konva.Text, + 'letterSpacing', + 0, + Konva.Validators.getNumberValidator() + ); /** * set letter spacing property. Default value is 0. @@ -15597,7 +16022,12 @@ * line.bezier(true); */ - Konva.Factory.addGetterSetter(Konva.Line, 'tension', 0); + Konva.Factory.addGetterSetter( + Konva.Line, + 'tension', + 0, + Konva.Validators.getNumberValidator() + ); /** * get/set tension @@ -15615,7 +16045,12 @@ * line.tension(3); */ - Konva.Factory.addGetterSetter(Konva.Line, 'points', []); + Konva.Factory.addGetterSetter( + Konva.Line, + 'points', + [], + Konva.Validators.getNumberArrayValidator() + ); /** * get/set points array * @name points @@ -16022,7 +16457,12 @@ * sprite.image(imageObj); */ - Konva.Factory.addGetterSetter(Konva.Sprite, 'frameIndex', 0); + Konva.Factory.addGetterSetter( + Konva.Sprite, + 'frameIndex', + 0, + Konva.Validators.getNumberValidator() + ); /** * set/set animation frame index @@ -16039,7 +16479,12 @@ * sprite.frameIndex(3); */ - Konva.Factory.addGetterSetter(Konva.Sprite, 'frameRate', 17); + Konva.Factory.addGetterSetter( + Konva.Sprite, + 'frameRate', + 17, + Konva.Validators.getNumberValidator() + ); /** * get/set frame rate in frames per second. Increase this number to make the sprite @@ -17570,7 +18015,12 @@ * @memberof Konva.TextPath.prototype */ - Konva.Factory.addGetterSetter(Konva.TextPath, 'fontSize', 12); + Konva.Factory.addGetterSetter( + Konva.TextPath, + 'fontSize', + 12, + Konva.Validators.getNumberValidator() + ); /** * set font size @@ -17616,7 +18066,12 @@ * text.align('right'); */ - Konva.Factory.addGetterSetter(Konva.TextPath, 'letterSpacing', 0); + Konva.Factory.addGetterSetter( + Konva.TextPath, + 'letterSpacing', + 0, + Konva.Validators.getNumberValidator() + ); /** * set letter spacing property. Default value is 0. @@ -17837,7 +18292,12 @@ Konva.Util.extend(Konva.RegularPolygon, Konva.Shape); // add getters setters - Konva.Factory.addGetterSetter(Konva.RegularPolygon, 'radius', 0); + Konva.Factory.addGetterSetter( + Konva.RegularPolygon, + 'radius', + 0, + Konva.Validators.getNumberValidator() + ); /** * set radius @@ -17854,7 +18314,12 @@ * @memberof Konva.RegularPolygon.prototype */ - Konva.Factory.addGetterSetter(Konva.RegularPolygon, 'sides', 0); + Konva.Factory.addGetterSetter( + Konva.RegularPolygon, + 'sides', + 0, + Konva.Validators.getNumberValidator() + ); /** * set number of sides @@ -18024,7 +18489,12 @@ Konva.Util.extend(Konva.Star, Konva.Shape); // add getters setters - Konva.Factory.addGetterSetter(Konva.Star, 'numPoints', 5); + Konva.Factory.addGetterSetter( + Konva.Star, + 'numPoints', + 5, + Konva.Validators.getNumberValidator() + ); /** * set number of points @@ -18041,7 +18511,12 @@ * @memberof Konva.Star.prototype */ - Konva.Factory.addGetterSetter(Konva.Star, 'innerRadius', 0); + Konva.Factory.addGetterSetter( + Konva.Star, + 'innerRadius', + 0, + Konva.Validators.getNumberValidator() + ); /** * set inner radius @@ -18058,7 +18533,12 @@ * @memberof Konva.Star.prototype */ - Konva.Factory.addGetterSetter(Konva.Star, 'outerRadius', 0); + Konva.Factory.addGetterSetter( + Konva.Star, + 'outerRadius', + 0, + Konva.Validators.getNumberValidator() + ); /** * set outer radius @@ -18436,7 +18916,12 @@ * @memberof Konva.Tag.prototype */ - Konva.Factory.addGetterSetter(Konva.Tag, 'pointerWidth', 0); + Konva.Factory.addGetterSetter( + Konva.Tag, + 'pointerWidth', + 0, + Konva.Validators.getNumberValidator() + ); /** * set pointer width @@ -18453,7 +18938,12 @@ * @memberof Konva.Tag.prototype */ - Konva.Factory.addGetterSetter(Konva.Tag, 'pointerHeight', 0); + Konva.Factory.addGetterSetter( + Konva.Tag, + 'pointerHeight', + 0, + Konva.Validators.getNumberValidator() + ); /** * set pointer height @@ -18470,7 +18960,12 @@ * @memberof Konva.Tag.prototype */ - Konva.Factory.addGetterSetter(Konva.Tag, 'cornerRadius', 0); + Konva.Factory.addGetterSetter( + Konva.Tag, + 'cornerRadius', + 0, + Konva.Validators.getNumberValidator() + ); /** * set corner radius @@ -18686,7 +19181,12 @@ * line.pointerLength(15); */ - Konva.Factory.addGetterSetter(Konva.Arrow, 'pointerLength', 10); + Konva.Factory.addGetterSetter( + Konva.Arrow, + 'pointerLength', + 10, + Konva.Validators.getNumberValidator() + ); /** * get/set pointerWidth * @name pointerWidth @@ -18703,7 +19203,12 @@ * line.pointerWidth(15); */ - Konva.Factory.addGetterSetter(Konva.Arrow, 'pointerWidth', 10); + Konva.Factory.addGetterSetter( + Konva.Arrow, + 'pointerWidth', + 10, + Konva.Validators.getNumberValidator() + ); /** * get/set pointerAtBeginning * @name pointerAtBeginning @@ -19597,7 +20102,12 @@ * // set * transformer.anchorSize(20) */ - Konva.Factory.addGetterSetter(Konva.Transformer, 'anchorSize', 10); + Konva.Factory.addGetterSetter( + Konva.Transformer, + 'anchorSize', + 10, + Konva.Validators.getNumberValidator() + ); /** * get/set ability to rotate. @@ -19645,7 +20155,12 @@ * // set * transformer.rotateAnchorOffset(100); */ - Konva.Factory.addGetterSetter(Konva.Transformer, 'rotateAnchorOffset', 50); + Konva.Factory.addGetterSetter( + Konva.Transformer, + 'rotateAnchorOffset', + 50, + Konva.Validators.getNumberValidator() + ); /** * get/set visibility of border @@ -19697,7 +20212,12 @@ * // set * transformer.anchorStrokeWidth(3); */ - Konva.Factory.addGetterSetter(Konva.Transformer, 'anchorStrokeWidth', 1); + Konva.Factory.addGetterSetter( + Konva.Transformer, + 'anchorStrokeWidth', + 1, + Konva.Validators.getNumberValidator() + ); /** * get/set anchor fill color @@ -19749,7 +20269,12 @@ * // set * transformer.borderStrokeWidth(3); */ - Konva.Factory.addGetterSetter(Konva.Transformer, 'borderStrokeWidth', 1); + Konva.Factory.addGetterSetter( + Konva.Transformer, + 'borderStrokeWidth', + 1, + Konva.Validators.getNumberValidator() + ); /** * get/set border dash array @@ -19797,7 +20322,12 @@ * // set * transformer.padding(10); */ - Konva.Factory.addGetterSetter(Konva.Transformer, 'padding', 0); + Konva.Factory.addGetterSetter( + Konva.Transformer, + 'padding', + 0, + Konva.Validators.getNumberValidator() + ); Konva.Factory.addOverloadedGetterSetter(Konva.Transformer, 'node'); diff --git a/konva.min.js b/konva.min.js index 502c1971..47c22677 100644 --- a/konva.min.js +++ b/konva.min.js @@ -9,7 +9,7 @@ * * @license */ -!function(){"use strict";var e=Math.PI/180,r={version:"2.2.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)),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 n=this.names[t];if(n){for(var i=0;i>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 n=this._clone(e);for(var i in t)this._isObject(t[i])?n[i]=this._merge(t[i],n[i]):n[i]=t[i];return n},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(i=0;i=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,n,i){this._context.fillRect(t,e,n,i)},strokeRect:function(t,e,n,i){this._context.strokeRect(t,e,n,i)},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,i,a=this,e=s.length,r=Konva.Util._simplifyArray,n=this.setAttr,o=function(t){var e,n=a[t];a[t]=function(){return i=r(Array.prototype.slice.call(arguments,0)),e=n.apply(a,arguments),a._trace({method:t,args:i}),e}};for(t=0;t>E,0!==b?(b=255/b,F[s]=(c*U>>E)*b,F[s+1]=(l*U>>E)*b,F[s+2]=(d*U>>E)*b):F[s]=F[s+1]=F[s+2]=0,c-=f,l-=g,d-=v,u-=p,f-=I.r,g-=I.g,v-=I.b,p-=I.a,r=h+((r=n+e+1)>E,0>E)*b,F[r+1]=(l*U>>E)*b,F[r+2]=(d*U>>E)*b):F[r]=F[r+1]=F[r+2]=0,c-=f,l-=g,d-=v,u-=p,f-=I.r,g-=I.g,v-=I.b,p-=I.a,r=n+((r=i+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},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>U,0!==C?(C=255/C,F[s]=(l*I>>U)*C,F[s+1]=(c*I>>U)*C,F[s+2]=(d*I>>U)*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)>U,0>U)*C,F[r+1]=(c*I>>U)*C,F[r+2]=(d*I>>U)*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,n,i=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=l++;var h=a.getLayer()||(a instanceof Konva.Stage?a.getLayers():null);for(n 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(){i.tween.onEnterFrame()},h),this.tween=new d(n,function(t){i._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===c[n]&&this._addAttr(n,t[n]);this.reset(),this.onFinish=t.onFinish,this.onReset=t.onReset},Konva.Tween.attrs={},Konva.Tween.tweens={},Konva.Tween.prototype={_addAttr:function(t,e){var n,i,a,r,o,s,h,c=this.node,l=c._id;if((a=Konva.Tween.tweens[l][t])&&delete Konva.Tween.attrs[l][a][t],n=c.getAttr(t),Konva.Util._isArray(e))for(i=[],o=Math.max(e.length,n.length),"points"===t&&e.length!==n.length&&(e.length>n.length?(h=n,n=Konva.Util._prepareArrayForTween(n,e,c.closed())):(s=e,e=Konva.Util._prepareArrayForTween(e,n,c.closed()))),r=0;r>>1,F=_.slice(0,w+1),T=this._getTextWidth(F)+y;T<=c?(K=w+1,C=F+(v?"…":""),b=T):x=w}if(!C)break;if(g){var P,A=_[C.length];0<(P=(" "===A||"-"===A)&&b<=c?C.length:Math.max(C.lastIndexOf(" "),C.lastIndexOf("-"))+1)&&(K=P,C=C.slice(0,K),b=this._getTextWidth(C))}if(this._addTextLine(C),n=Math.max(n,b),d+=i,!f||s&&le?v=Konva.Path.getPointOnLine(e,g.x,g.y,p.points[0],p.points[1],g.x,g.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:np.pathLength?1e-8:e/p.pathLength:nthis.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=this.node,c=l._id;if((a=Konva.Tween.tweens[c][t])&&delete Konva.Tween.attrs[c][a][t],i=l.getAttr(t),Konva.Util._isArray(e))for(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,l.closed())):(s=e,e=Konva.Util._prepareArrayForTween(e,i,l.closed()))),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(this._addTextLine(x),i=Math.max(i,C),d+=n,!g||s&&ce?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