diff --git a/konva.js b/konva.js index 68c8fb4a..121b6eb3 100644 --- a/konva.js +++ b/konva.js @@ -8,7 +8,7 @@ * Konva JavaScript Framework v3.0.0-3 * http://konvajs.org/ * Licensed under the MIT - * Date: Sat Feb 23 2019 + * Date: Sun Feb 24 2019 * * Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS) * Modified work Copyright (C) 2014 - present by Anton Lavrenov (Konva) @@ -977,6 +977,121 @@ } }; + function _formatValue(val) { + if (Util._isString(val)) { + return '"' + val + '"'; + } + if (Object.prototype.toString.call(val) === '[object Number]') { + return val; + } + if (Util._isBoolean(val)) { + return val; + } + return Object.prototype.toString.call(val); + } + function RGBComponent(val) { + if (val > 255) { + return 255; + } + else if (val < 0) { + return 0; + } + return Math.round(val); + } + function getNumberValidator() { + if (isUnminified) { + return function (val, attr) { + if (!Util._isNumber(val)) { + Util.warn(_formatValue(val) + + ' is a not valid value for "' + + attr + + '" attribute. The value should be a number.'); + } + return val; + }; + } + } + function getNumberOrAutoValidator() { + if (isUnminified) { + return function (val, attr) { + var isNumber = Util._isNumber(val); + var isAuto = val === 'auto'; + if (!(isNumber || isAuto)) { + Util.warn(_formatValue(val) + + ' is a not valid value for "' + + attr + + '" attribute. The value should be a number or "auto".'); + } + return val; + }; + } + } + function getStringValidator() { + if (isUnminified) { + return function (val, attr) { + if (!Util._isString(val)) { + Util.warn(_formatValue(val) + + ' is a not valid value for "' + + attr + + '" attribute. The value should be a string.'); + } + return val; + }; + } + } + function getNumberArrayValidator() { + if (isUnminified) { + return function (val, attr) { + if (!Util._isArray(val)) { + Util.warn(_formatValue(val) + + ' is a not valid value for "' + + attr + + '" attribute. The value should be a array of numbers.'); + } + else { + val.forEach(function (item) { + if (!Util._isNumber(item)) { + Util.warn('"' + + attr + + '" attribute has non numeric element ' + + item + + '. Make sure that all elements are numbers.'); + } + }); + } + return val; + }; + } + } + function getBooleanValidator() { + if (isUnminified) { + return function (val, attr) { + var isBool = val === true || val === false; + if (!isBool) { + Util.warn(_formatValue(val) + + ' is a not valid value for "' + + attr + + '" attribute. The value should be a boolean.'); + } + return val; + }; + } + } + function getComponentValidator(components) { + if (isUnminified) { + return function (val, attr) { + if (!Util.isObject(val)) { + Util.warn(_formatValue(val) + + ' is a not valid value for "' + + attr + + '" attribute. The value should be an object with properties ' + + components); + } + return val; + }; + } + } + var GET = 'get', SET = 'set'; var Factory = { addGetterSetter: function (constructor, attr, def, validator, after) { @@ -1023,7 +1138,7 @@ } return ret; }; - var basicValidator = Validators.getComponentValidator(components); + var basicValidator = getComponentValidator(components); // setter constructor.prototype[setter] = function (val) { var oldVal = this.attrs[attr], key; @@ -1095,148 +1210,6 @@ afterSetFilter: function () { this._filterUpToDate = false; } - }; - var Validators = { - /** - * @return {number} - */ - RGBComponent: function (val) { - if (val > 255) { - return 255; - } - else if (val < 0) { - return 0; - } - return Math.round(val); - }, - alphaComponent: function (val) { - if (val > 1) { - return 1; - } - else if (val < 0.0001) { - // chrome does not honor alpha values of 0 - return 0.0001; - } - return val; - }, - _formatValue: function (val) { - if (Util._isString(val)) { - return '"' + val + '"'; - } - if (Object.prototype.toString.call(val) === '[object Number]') { - return val; - } - if (Util._isBoolean(val)) { - return val; - } - return Object.prototype.toString.call(val); - }, - getNumberValidator: function () { - if (isUnminified) { - return function (val, attr) { - if (!Util._isNumber(val)) { - Util.warn(Validators._formatValue(val) + - ' is a not valid value for "' + - attr + - '" attribute. The value should be a number.'); - } - return val; - }; - } - }, - getNumberOrAutoValidator: function () { - if (isUnminified) { - return function (val, attr) { - var isNumber = Util._isNumber(val); - var isAuto = val === 'auto'; - if (!(isNumber || isAuto)) { - Util.warn(Validators._formatValue(val) + - ' is a not valid value for "' + - attr + - '" attribute. The value should be a number or "auto".'); - } - return val; - }; - } - }, - getStringValidator: function () { - if (isUnminified) { - return function (val, attr) { - if (!Util._isString(val)) { - Util.warn(Validators._formatValue(val) + - ' is a not valid value for "' + - attr + - '" attribute. The value should be a string.'); - } - return val; - }; - } - }, - getFunctionValidator: function () { - if (isUnminified) { - return function (val, attr) { - if (!Util._isFunction(val)) { - Util.warn(Validators._formatValue(val) + - ' is a not valid value for "' + - attr + - '" attribute. The value should be a function.'); - } - return val; - }; - } - }, - getNumberArrayValidator: function () { - if (isUnminified) { - return function (val, attr) { - if (!Util._isArray(val)) { - Util.warn(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 (!Util._isNumber(item)) { - Util.warn('"' + - attr + - '" attribute has non numeric element ' + - item + - '. Make sure that all elements are numbers.'); - } - }); - } - return val; - }; - } - }, - getBooleanValidator: function () { - if (isUnminified) { - return function (val, attr) { - var isBool = val === true || val === false; - if (!isBool) { - Util.warn(Validators._formatValue(val) + - ' is a not valid value for "' + - attr + - '" attribute. The value should be a boolean.'); - } - return val; - }; - } - }, - getComponentValidator: function (components) { - if (isUnminified) { - return function (val, attr) { - if (!Util.isObject(val)) { - Util.warn(Validators._formatValue(val) + - ' is a not valid value for "' + - attr + - '" attribute. The value should be an object with properties ' + - components); - } - return val; - }; - } - } }; /*! ***************************************************************************** @@ -1982,7 +1955,7 @@ * // set * canvas.pixelRatio(100); */ - Factory.addGetterSetter(Canvas, 'pixelRatio', undefined, Validators.getNumberValidator()); + Factory.addGetterSetter(Canvas, 'pixelRatio', undefined, getNumberValidator()); var SceneCanvas = /** @class */ (function (_super) { __extends(SceneCanvas, _super); function SceneCanvas(config) { @@ -4363,7 +4336,7 @@ * y: 10 * }); */ - Factory.addGetterSetter(Node, 'x', 0, Validators.getNumberValidator()); + Factory.addGetterSetter(Node, 'x', 0, getNumberValidator()); /** * get/set x position * @name Konva.Node#x @@ -4377,7 +4350,7 @@ * // set x * node.x(5); */ - Factory.addGetterSetter(Node, 'y', 0, Validators.getNumberValidator()); + Factory.addGetterSetter(Node, 'y', 0, getNumberValidator()); /** * get/set y position * @name Konva.Node#y @@ -4391,7 +4364,7 @@ * // set y * node.y(5); */ - Factory.addGetterSetter(Node, 'globalCompositeOperation', 'source-over', Validators.getStringValidator()); + Factory.addGetterSetter(Node, 'globalCompositeOperation', 'source-over', getStringValidator()); /** * get/set globalCompositeOperation of a shape * @name Konva.Node#globalCompositeOperation @@ -4405,7 +4378,7 @@ * // set globalCompositeOperation * shape.globalCompositeOperation('source-in'); */ - Factory.addGetterSetter(Node, 'opacity', 1, Validators.getNumberValidator()); + Factory.addGetterSetter(Node, 'opacity', 1, getNumberValidator()); /** * get/set opacity. Opacity values range from 0 to 1. * A node with an opacity of 0 is fully transparent, and a node @@ -4421,7 +4394,7 @@ * // set opacity * node.opacity(0.5); */ - Factory.addGetterSetter(Node, 'name', '', Validators.getStringValidator()); + Factory.addGetterSetter(Node, 'name', '', getStringValidator()); /** * get/set name * @name Konva.Node#name @@ -4438,7 +4411,7 @@ * // also node may have multiple names (as css classes) * node.name('foo bar'); */ - Factory.addGetterSetter(Node, 'id', '', Validators.getStringValidator()); + Factory.addGetterSetter(Node, 'id', '', getStringValidator()); /** * get/set id. Id is global for whole page. * @name Konva.Node#id @@ -4452,7 +4425,7 @@ * // set id * node.id('foo'); */ - Factory.addGetterSetter(Node, 'rotation', 0, Validators.getNumberValidator()); + Factory.addGetterSetter(Node, 'rotation', 0, getNumberValidator()); /** * get/set rotation in degrees * @name Konva.Node#rotation @@ -4485,7 +4458,7 @@ * y: 3 * }); */ - Factory.addGetterSetter(Node, 'scaleX', 1, Validators.getNumberValidator()); + Factory.addGetterSetter(Node, 'scaleX', 1, getNumberValidator()); /** * get/set scale x * @name Konva.Node#scaleX @@ -4499,7 +4472,7 @@ * // set scale x * node.scaleX(2); */ - Factory.addGetterSetter(Node, 'scaleY', 1, Validators.getNumberValidator()); + Factory.addGetterSetter(Node, 'scaleY', 1, getNumberValidator()); /** * get/set scale y * @name Konva.Node#scaleY @@ -4532,7 +4505,7 @@ * y: 10 * }); */ - Factory.addGetterSetter(Node, 'skewX', 0, Validators.getNumberValidator()); + Factory.addGetterSetter(Node, 'skewX', 0, getNumberValidator()); /** * get/set skew x * @name Konva.Node#skewX @@ -4546,7 +4519,7 @@ * // set skew x * node.skewX(3); */ - Factory.addGetterSetter(Node, 'skewY', 0, Validators.getNumberValidator()); + Factory.addGetterSetter(Node, 'skewY', 0, getNumberValidator()); /** * get/set skew y * @name Konva.Node#skewY @@ -4578,7 +4551,7 @@ * y: 10 * }); */ - Factory.addGetterSetter(Node, 'offsetX', 0, Validators.getNumberValidator()); + Factory.addGetterSetter(Node, 'offsetX', 0, getNumberValidator()); /** * get/set offset x * @name Konva.Node#offsetX @@ -4592,7 +4565,7 @@ * // set offset x * node.offsetX(3); */ - Factory.addGetterSetter(Node, 'offsetY', 0, Validators.getNumberValidator()); + Factory.addGetterSetter(Node, 'offsetY', 0, getNumberValidator()); /** * get/set offset y * @name Konva.Node#offsetY @@ -4606,7 +4579,7 @@ * // set offset y * node.offsetY(3); */ - Factory.addGetterSetter(Node, 'dragDistance', null, Validators.getNumberValidator()); + Factory.addGetterSetter(Node, 'dragDistance', null, getNumberValidator()); /** * get/set drag distance * @name Konva.Node#dragDistance @@ -4623,7 +4596,7 @@ * // or set globally * Konva.dragDistance = 3; */ - Factory.addGetterSetter(Node, 'width', 0, Validators.getNumberValidator()); + Factory.addGetterSetter(Node, 'width', 0, getNumberValidator()); /** * get/set width * @name Konva.Node#width @@ -4637,7 +4610,7 @@ * // set width * node.width(100); */ - Factory.addGetterSetter(Node, 'height', 0, Validators.getNumberValidator()); + Factory.addGetterSetter(Node, 'height', 0, getNumberValidator()); /** * get/set height * @name Konva.Node#height @@ -4697,7 +4670,7 @@ * // set preventDefault * shape.preventDefault(false); */ - Factory.addGetterSetter(Node, 'preventDefault', true, Validators.getBooleanValidator()); + Factory.addGetterSetter(Node, 'preventDefault', true, getBooleanValidator()); Factory.addGetterSetter(Node, 'filters', null, function (val) { this._filterUpToDate = false; return val; @@ -4753,7 +4726,7 @@ * // make visible according to the parent * node.visible('inherit'); */ - Factory.addGetterSetter(Node, 'transformsEnabled', 'all', Validators.getStringValidator()); + Factory.addGetterSetter(Node, 'transformsEnabled', 'all', getStringValidator()); /** * get/set transforms that are enabled. Can be "all", "none", or "position". The default * is "all" @@ -4827,7 +4800,7 @@ * // disable drag and drop * node.draggable(false); */ - Factory.addGetterSetter(Node, 'draggable', false, Validators.getBooleanValidator()); + Factory.addGetterSetter(Node, 'draggable', false, getBooleanValidator()); Factory.backCompat(Node, { rotateDeg: 'rotate', setRotationDeg: 'setRotation', @@ -5299,9 +5272,7 @@ }; Container.prototype.shouldDrawHit = function (canvas) { var layer = this.getLayer(); - var layerUnderDrag = DD.isDragging && - DD.anim.getLayers() - .indexOf(layer) !== -1; + var layerUnderDrag = DD.isDragging && DD.anim.getLayers().indexOf(layer) !== -1; return ((canvas && canvas.isCache) || (layer && layer.hitGraphEnabled() && this.isVisible() && !layerUnderDrag)); }; @@ -5407,7 +5378,7 @@ * height: 20 * }); */ - Factory.addGetterSetter(Container, 'clipX', undefined, Validators.getNumberValidator()); + Factory.addGetterSetter(Container, 'clipX', undefined, getNumberValidator()); /** * get/set clip x * @name Konva.Container#clipX @@ -5421,7 +5392,7 @@ * // set clip x * container.clipX(10); */ - Factory.addGetterSetter(Container, 'clipY', undefined, Validators.getNumberValidator()); + Factory.addGetterSetter(Container, 'clipY', undefined, getNumberValidator()); /** * get/set clip y * @name Konva.Container#clipY @@ -5435,7 +5406,7 @@ * // set clip y * container.clipY(10); */ - Factory.addGetterSetter(Container, 'clipWidth', undefined, Validators.getNumberValidator()); + Factory.addGetterSetter(Container, 'clipWidth', undefined, getNumberValidator()); /** * get/set clip width * @name Konva.Container#clipWidth @@ -5449,7 +5420,7 @@ * // set clip width * container.clipWidth(100); */ - Factory.addGetterSetter(Container, 'clipHeight', undefined, Validators.getNumberValidator()); + Factory.addGetterSetter(Container, 'clipHeight', undefined, getNumberValidator()); /** * get/set clip height * @name Konva.Container#clipHeight @@ -7031,7 +7002,7 @@ Shape.prototype._centroid = false; Shape.prototype.nodeType = 'Shape'; // add getters and setters - Factory.addGetterSetter(Shape, 'stroke', undefined, Validators.getStringValidator()); + Factory.addGetterSetter(Shape, 'stroke', undefined, getStringValidator()); /** * get/set stroke color * @name Konva.Shape#stroke @@ -7054,7 +7025,7 @@ * // set stroke color with rgba and make it 50% opaque * shape.stroke('rgba(0,255,0,0.5'); */ - Factory.addGetterSetter(Shape, 'strokeWidth', 2, Validators.getNumberValidator()); + Factory.addGetterSetter(Shape, 'strokeWidth', 2, getNumberValidator()); /** * get/set stroke width * @name Konva.Shape#strokeWidth @@ -7068,7 +7039,7 @@ * // set stroke width * shape.strokeWidth(); */ - Factory.addGetterSetter(Shape, 'strokeHitEnabled', true, Validators.getBooleanValidator()); + Factory.addGetterSetter(Shape, 'strokeHitEnabled', true, getBooleanValidator()); /** * get/set strokeHitEnabled property. Useful for performance optimization. * You may set `shape.strokeHitEnabled(false)`. In this case stroke will be no draw on hit canvas, so hit area @@ -7086,7 +7057,7 @@ * // set strokeHitEnabled * shape.strokeHitEnabled(); */ - Factory.addGetterSetter(Shape, 'perfectDrawEnabled', true, Validators.getBooleanValidator()); + Factory.addGetterSetter(Shape, 'perfectDrawEnabled', true, getBooleanValidator()); /** * get/set perfectDrawEnabled. If a shape has fill, stroke and opacity you may set `perfectDrawEnabled` to false to improve performance. * See http://konvajs.org/docs/performance/Disable_Perfect_Draw.html for more information. @@ -7102,7 +7073,7 @@ * // set perfectDrawEnabled * shape.perfectDrawEnabled(); */ - Factory.addGetterSetter(Shape, 'shadowForStrokeEnabled', true, Validators.getBooleanValidator()); + Factory.addGetterSetter(Shape, 'shadowForStrokeEnabled', true, getBooleanValidator()); /** * get/set shadowForStrokeEnabled. Useful for performance optimization. * You may set `shape.shadowForStrokeEnabled(false)`. In this case stroke will no effect shadow. @@ -7205,7 +7176,7 @@ * // a radius of 5px and are 20px apart * line.dash([10, 20, 0.001, 20]); */ - Factory.addGetterSetter(Shape, 'dashOffset', 0, Validators.getNumberValidator()); + Factory.addGetterSetter(Shape, 'dashOffset', 0, getNumberValidator()); /** * get/set dash offset for stroke. * @name Konva.Shape#dash @@ -7217,7 +7188,7 @@ * line.dash([10, 5]); * line.dashOffset(5); */ - Factory.addGetterSetter(Shape, 'shadowColor', undefined, Validators.getStringValidator()); + Factory.addGetterSetter(Shape, 'shadowColor', undefined, getStringValidator()); /** * get/set shadow color * @name Konva.Shape#shadowColor @@ -7240,7 +7211,7 @@ * // set shadow color with rgba and make it 50% opaque * shape.shadowColor('rgba(0,255,0,0.5'); */ - Factory.addGetterSetter(Shape, 'shadowBlur', 0, Validators.getNumberValidator()); + Factory.addGetterSetter(Shape, 'shadowBlur', 0, getNumberValidator()); /** * get/set shadow blur * @name Konva.Shape#shadowBlur @@ -7254,7 +7225,7 @@ * // set shadow blur * shape.shadowBlur(10); */ - Factory.addGetterSetter(Shape, 'shadowOpacity', 1, Validators.getNumberValidator()); + Factory.addGetterSetter(Shape, 'shadowOpacity', 1, getNumberValidator()); /** * get/set shadow opacity. must be a value between 0 and 1 * @name Konva.Shape#shadowOpacity @@ -7287,7 +7258,7 @@ * y: 10 * }); */ - Factory.addGetterSetter(Shape, 'shadowOffsetX', 0, Validators.getNumberValidator()); + Factory.addGetterSetter(Shape, 'shadowOffsetX', 0, getNumberValidator()); /** * get/set shadow offset x * @name Konva.Shape#shadowOffsetX @@ -7301,7 +7272,7 @@ * // set shadow offset x * shape.shadowOffsetX(5); */ - Factory.addGetterSetter(Shape, 'shadowOffsetY', 0, Validators.getNumberValidator()); + Factory.addGetterSetter(Shape, 'shadowOffsetY', 0, getNumberValidator()); /** * get/set shadow offset y * @name Konva.Shape#shadowOffsetY @@ -7333,7 +7304,7 @@ * }; * imageObj.src = 'path/to/image/jpg'; */ - Factory.addGetterSetter(Shape, 'fill', undefined, Validators.getStringValidator()); + Factory.addGetterSetter(Shape, 'fill', undefined, getStringValidator()); /** * get/set fill color * @name Konva.Shape#fill @@ -7359,7 +7330,7 @@ * // shape without fill * shape.fill(null); */ - Factory.addGetterSetter(Shape, 'fillPatternX', 0, Validators.getNumberValidator()); + Factory.addGetterSetter(Shape, 'fillPatternX', 0, getNumberValidator()); /** * get/set fill pattern x * @name Konva.Shape#fillPatternX @@ -7372,7 +7343,7 @@ * // set fill pattern x * shape.fillPatternX(20); */ - Factory.addGetterSetter(Shape, 'fillPatternY', 0, Validators.getNumberValidator()); + Factory.addGetterSetter(Shape, 'fillPatternY', 0, getNumberValidator()); /** * get/set fill pattern y * @name Konva.Shape#fillPatternY @@ -7594,7 +7565,7 @@ * y: 10 * }); */ - Factory.addGetterSetter(Shape, 'fillPatternOffsetX', 0, Validators.getNumberValidator()); + Factory.addGetterSetter(Shape, 'fillPatternOffsetX', 0, getNumberValidator()); /** * get/set fill pattern offset x * @name Konva.Shape#fillPatternOffsetX @@ -7608,7 +7579,7 @@ * // set fill pattern offset x * shape.fillPatternOffsetX(20); */ - Factory.addGetterSetter(Shape, 'fillPatternOffsetY', 0, Validators.getNumberValidator()); + Factory.addGetterSetter(Shape, 'fillPatternOffsetY', 0, getNumberValidator()); /** * get/set fill pattern offset y * @name Konva.Shape#fillPatternOffsetY @@ -7641,7 +7612,7 @@ * y: 2 * }); */ - Factory.addGetterSetter(Shape, 'fillPatternScaleX', 1, Validators.getNumberValidator()); + Factory.addGetterSetter(Shape, 'fillPatternScaleX', 1, getNumberValidator()); /** * get/set fill pattern scale x * @name Konva.Shape#fillPatternScaleX @@ -7655,7 +7626,7 @@ * // set fill pattern scale x * shape.fillPatternScaleX(2); */ - Factory.addGetterSetter(Shape, 'fillPatternScaleY', 1, Validators.getNumberValidator()); + Factory.addGetterSetter(Shape, 'fillPatternScaleY', 1, getNumberValidator()); /** * get/set fill pattern scale y * @name Konva.Shape#fillPatternScaleY @@ -8231,7 +8202,7 @@ }; return Layer; }(BaseLayer)); - Factory.addGetterSetter(Layer, 'hitGraphEnabled', true, Validators.getBooleanValidator()); + Factory.addGetterSetter(Layer, 'hitGraphEnabled', true, getBooleanValidator()); /** * get/set hitGraphEnabled flag. Disabling the hit graph will greatly increase * draw performance because the hit graph will not be redrawn each time the layer is @@ -9178,7 +9149,7 @@ Arc.prototype.className = 'Arc'; Arc.prototype._attrsAffectingSize = ['innerRadius', 'outerRadius']; // add getters setters - Factory.addGetterSetter(Arc, 'innerRadius', 0, Validators.getNumberValidator()); + Factory.addGetterSetter(Arc, 'innerRadius', 0, getNumberValidator()); /** * get/set innerRadius * @name Konva.Arc#innerRadius @@ -9192,7 +9163,7 @@ * // set inner radius * arc.innerRadius(20); */ - Factory.addGetterSetter(Arc, 'outerRadius', 0, Validators.getNumberValidator()); + Factory.addGetterSetter(Arc, 'outerRadius', 0, getNumberValidator()); /** * get/set outerRadius * @name Konva.Arc#outerRadius @@ -9206,7 +9177,7 @@ * // set outer radius * arc.outerRadius(20); */ - Factory.addGetterSetter(Arc, 'angle', 0, Validators.getNumberValidator()); + Factory.addGetterSetter(Arc, 'angle', 0, getNumberValidator()); /** * get/set angle in degrees * @name Konva.Arc#angle @@ -9220,7 +9191,7 @@ * // set angle * arc.angle(20); */ - Factory.addGetterSetter(Arc, 'clockwise', false); + Factory.addGetterSetter(Arc, 'clockwise', false, getBooleanValidator()); /** * get/set clockwise flag * @name Konva.Arc#clockwise @@ -9484,7 +9455,7 @@ * // set whether the line is a bezier * line.bezier(true); */ - Factory.addGetterSetter(Line, 'tension', 0, Validators.getNumberValidator()); + Factory.addGetterSetter(Line, 'tension', 0, getNumberValidator()); /** * get/set tension * @name Konva.Line#tension @@ -9498,7 +9469,7 @@ * // set tension * line.tension(3); */ - Factory.addGetterSetter(Line, 'points', [], Validators.getNumberArrayValidator()); + Factory.addGetterSetter(Line, 'points', [], getNumberArrayValidator()); /** * get/set points array. Points is a flat array [x1, y1, x2, y2]. It is flat for performance reasons. * @name Konva.Line#points @@ -9695,7 +9666,7 @@ * // set length * line.pointerLength(15); */ - Factory.addGetterSetter(Arrow, 'pointerLength', 10, Validators.getNumberValidator()); + Factory.addGetterSetter(Arrow, 'pointerLength', 10, getNumberValidator()); /** * get/set pointerWidth * @name Konva.Arrow#pointerWidth @@ -9710,7 +9681,7 @@ * // set width * line.pointerWidth(15); */ - Factory.addGetterSetter(Arrow, 'pointerWidth', 10, Validators.getNumberValidator()); + Factory.addGetterSetter(Arrow, 'pointerWidth', 10, getNumberValidator()); /** * get/set pointerAtBeginning * @name Konva.Arrow#pointerAtBeginning @@ -9859,7 +9830,7 @@ * // set radius * circle.radius(10); */ - Factory.addGetterSetter(Circle, 'radius', 0, Validators.getNumberValidator()); + Factory.addGetterSetter(Circle, 'radius', 0, getNumberValidator()); Collection.mapMethods(Circle); /** @@ -10002,7 +9973,7 @@ * y: 100 * }); */ - Factory.addGetterSetter(Ellipse, 'radiusX', 0, Validators.getNumberValidator()); + Factory.addGetterSetter(Ellipse, 'radiusX', 0, getNumberValidator()); /** * get/set radius x * @name Konva.Ellipse#radiusX @@ -10016,7 +9987,7 @@ * // set radius x * ellipse.radiusX(200); */ - Factory.addGetterSetter(Ellipse, 'radiusY', 0, Validators.getNumberValidator()); + Factory.addGetterSetter(Ellipse, 'radiusY', 0, getNumberValidator()); /** * get/set radius y * @name Konva.Ellipse#radiusY @@ -10245,7 +10216,7 @@ * height: 20 * }); */ - Factory.addGetterSetter(Image, 'cropX', 0, Validators.getNumberValidator()); + Factory.addGetterSetter(Image, 'cropX', 0, getNumberValidator()); /** * get/set crop x * @method @@ -10259,7 +10230,7 @@ * // set crop x * image.cropX(20); */ - Factory.addGetterSetter(Image, 'cropY', 0, Validators.getNumberValidator()); + Factory.addGetterSetter(Image, 'cropY', 0, getNumberValidator()); /** * get/set crop y * @name Konva.Image#cropY @@ -10273,7 +10244,7 @@ * // set crop y * image.cropY(20); */ - Factory.addGetterSetter(Image, 'cropWidth', 0, Validators.getNumberValidator()); + Factory.addGetterSetter(Image, 'cropWidth', 0, getNumberValidator()); /** * get/set crop width * @name Konva.Image#cropWidth @@ -10287,7 +10258,7 @@ * // set crop width * image.cropWidth(20); */ - Factory.addGetterSetter(Image, 'cropHeight', 0, Validators.getNumberValidator()); + Factory.addGetterSetter(Image, 'cropHeight', 0, getNumberValidator()); /** * get/set crop height * @name Konva.Image#cropHeight @@ -10582,7 +10553,7 @@ * @example * tag.pointerWidth(20); */ - Factory.addGetterSetter(Tag, 'pointerWidth', 0, Validators.getNumberValidator()); + Factory.addGetterSetter(Tag, 'pointerWidth', 0, getNumberValidator()); /** * get/set pointer height * @method @@ -10592,7 +10563,7 @@ * @example * tag.pointerHeight(20); */ - Factory.addGetterSetter(Tag, 'pointerHeight', 0, Validators.getNumberValidator()); + Factory.addGetterSetter(Tag, 'pointerHeight', 0, getNumberValidator()); /** * get/set cornerRadius * @name Konva.Tag#cornerRadius @@ -10602,7 +10573,7 @@ * @example * tag.cornerRadius(20); */ - Factory.addGetterSetter(Tag, 'cornerRadius', 0, Validators.getNumberValidator()); + Factory.addGetterSetter(Tag, 'cornerRadius', 0, getNumberValidator()); Collection.mapMethods(Tag); /** @@ -11508,7 +11479,7 @@ * // set corner radius * rect.cornerRadius(10); */ - Factory.addGetterSetter(Rect, 'cornerRadius', 0, Validators.getNumberValidator()); + Factory.addGetterSetter(Rect, 'cornerRadius', 0, getNumberValidator()); Collection.mapMethods(Rect); /** @@ -11648,7 +11619,7 @@ * // set radius * shape.radius(10); */ - Factory.addGetterSetter(RegularPolygon, 'radius', 0, Validators.getNumberValidator()); + Factory.addGetterSetter(RegularPolygon, 'radius', 0, getNumberValidator()); /** * get/set sides * @method @@ -11662,7 +11633,7 @@ * // set sides * shape.sides(10); */ - Factory.addGetterSetter(RegularPolygon, 'sides', 0, Validators.getNumberValidator()); + Factory.addGetterSetter(RegularPolygon, 'sides', 0, getNumberValidator()); Collection.mapMethods(RegularPolygon); var PIx2 = Math.PI * 2; @@ -11798,7 +11769,7 @@ * // set inner radius * ring.innerRadius(20); */ - Factory.addGetterSetter(Ring, 'innerRadius', 0, Validators.getNumberValidator()); + Factory.addGetterSetter(Ring, 'innerRadius', 0, getNumberValidator()); /** * get/set outerRadius * @name Konva.Ring#outerRadius @@ -11812,7 +11783,7 @@ * // set outer radius * ring.outerRadius(20); */ - Factory.addGetterSetter(Ring, 'outerRadius', 0, Validators.getNumberValidator()); + Factory.addGetterSetter(Ring, 'outerRadius', 0, getNumberValidator()); Collection.mapMethods(Ring); /** @@ -12144,7 +12115,7 @@ * // set image * sprite.image(imageObj); */ - Factory.addGetterSetter(Sprite, 'frameIndex', 0, Validators.getNumberValidator()); + Factory.addGetterSetter(Sprite, 'frameIndex', 0, getNumberValidator()); /** * set/set animation frame index * @name Konva.Sprite#frameIndex @@ -12158,7 +12129,7 @@ * // set animation frame index * sprite.frameIndex(3); */ - Factory.addGetterSetter(Sprite, 'frameRate', 17, Validators.getNumberValidator()); + Factory.addGetterSetter(Sprite, 'frameRate', 17, getNumberValidator()); /** * get/set frame rate in frames per second. Increase this number to make the sprite * animation run faster, and decrease the number to make the sprite animation run slower @@ -12321,7 +12292,7 @@ * // set inner radius * ring.numPoints(20); */ - Factory.addGetterSetter(Star, 'numPoints', 5, Validators.getNumberValidator()); + Factory.addGetterSetter(Star, 'numPoints', 5, getNumberValidator()); /** * get/set innerRadius * @name Konva.Ring#innerRadius @@ -12335,7 +12306,7 @@ * // set inner radius * ring.innerRadius(20); */ - Factory.addGetterSetter(Star, 'innerRadius', 0, Validators.getNumberValidator()); + Factory.addGetterSetter(Star, 'innerRadius', 0, getNumberValidator()); /** * get/set outerRadius * @name Konva.Ring#outerRadius @@ -12349,7 +12320,7 @@ * // set inner radius * ring.outerRadius(20); */ - Factory.addGetterSetter(Star, 'outerRadius', 0, Validators.getNumberValidator()); + Factory.addGetterSetter(Star, 'outerRadius', 0, getNumberValidator()); Collection.mapMethods(Star); // constants @@ -12839,7 +12810,7 @@ * text.width('auto'); * text.width() // will return calculated width, and not "auto" */ - Factory.overWriteSetter(Text, 'width', Validators.getNumberOrAutoValidator()); + Factory.overWriteSetter(Text, 'width', getNumberOrAutoValidator()); /** * get/set the height of the text area, which takes into account multi-line text, line heights, and padding. * @name Konva.Text#height @@ -12857,7 +12828,7 @@ * text.height('auto'); * text.height() // will return calculated height, and not "auto" */ - Factory.overWriteSetter(Text, 'height', Validators.getNumberOrAutoValidator()); + Factory.overWriteSetter(Text, 'height', getNumberOrAutoValidator()); /** * get/set font family * @name Konva.Text#fontFamily @@ -12885,7 +12856,7 @@ * // set font size to 22px * text.fontSize(22); */ - Factory.addGetterSetter(Text, 'fontSize', 12, Validators.getNumberValidator()); + Factory.addGetterSetter(Text, 'fontSize', 12, getNumberValidator()); /** * get/set font style. Can be 'normal', 'italic', or 'bold'. 'normal' is the default. * @name Konva.Text#fontStyle @@ -12927,7 +12898,7 @@ * // set padding to 10 pixels * text.padding(10); */ - Factory.addGetterSetter(Text, 'padding', 0, Validators.getNumberValidator()); + Factory.addGetterSetter(Text, 'padding', 0, getNumberValidator()); /** * get/set horizontal align of text. Can be 'left', 'center', 'right' or 'justify' * @name Konva.Text#align @@ -12972,7 +12943,7 @@ * // set the line height * text.lineHeight(2); */ - Factory.addGetterSetter(Text, 'lineHeight', 1, Validators.getNumberValidator()); + Factory.addGetterSetter(Text, 'lineHeight', 1, getNumberValidator()); /** * get/set wrap. Can be "word", "char", or "none". Default is "word". * In "word" wrapping any word still can be wrapped if it can't be placed in the required width @@ -13010,7 +12981,7 @@ * @method * @param {Number} letterSpacing */ - Factory.addGetterSetter(Text, 'letterSpacing', 0, Validators.getNumberValidator()); + Factory.addGetterSetter(Text, 'letterSpacing', 0, getNumberValidator()); /** * get/set text * @name Konva.Text#text @@ -13024,7 +12995,7 @@ * // set text * text.text('Hello world!'); */ - Factory.addGetterSetter(Text, 'text', '', Validators.getStringValidator()); + Factory.addGetterSetter(Text, 'text', '', getStringValidator()); /** * get/set text decoration of a text. Possible values are 'underline', 'line-through' or combination of these values separated by space * @name Konva.Text#textDecoration @@ -13559,7 +13530,7 @@ * // set font size to 22px * shape.fontSize(22); */ - Factory.addGetterSetter(TextPath, 'fontSize', 12, Validators.getNumberValidator()); + Factory.addGetterSetter(TextPath, 'fontSize', 12, getNumberValidator()); /** * get/set font style. Can be 'normal', 'italic', or 'bold'. 'normal' is the default. * @name Konva.TextPath#fontStyle @@ -13604,7 +13575,7 @@ * // set the line height * shape.letterSpacing(2); */ - Factory.addGetterSetter(TextPath, 'letterSpacing', 0, Validators.getNumberValidator()); + Factory.addGetterSetter(TextPath, 'letterSpacing', 0, getNumberValidator()); /** * get/set text baselineg. The default is 'middle'. Can be 'top', 'bottom', 'middle', 'alphabetic', 'hanging' * @name Konva.TextPath#textBaseline @@ -14441,7 +14412,7 @@ * // set * transformer.anchorSize(20) */ - Factory.addGetterSetter(Transformer, 'anchorSize', 10, Validators.getNumberValidator()); + Factory.addGetterSetter(Transformer, 'anchorSize', 10, getNumberValidator()); /** * get/set ability to rotate. * @name Konva.Transformer#rotateEnabled @@ -14483,7 +14454,7 @@ * // set * transformer.rotateAnchorOffset(100); */ - Factory.addGetterSetter(Transformer, 'rotateAnchorOffset', 50, Validators.getNumberValidator()); + Factory.addGetterSetter(Transformer, 'rotateAnchorOffset', 50, getNumberValidator()); /** * get/set visibility of border * @name Konva.Transformer#borderEnabled @@ -14525,7 +14496,7 @@ * // set * transformer.anchorStrokeWidth(3); */ - Factory.addGetterSetter(Transformer, 'anchorStrokeWidth', 1, Validators.getNumberValidator()); + Factory.addGetterSetter(Transformer, 'anchorStrokeWidth', 1, getNumberValidator()); /** * get/set anchor fill color * @name Konva.Transformer#anchorFill @@ -14553,7 +14524,7 @@ * // set * transformer.anchorCornerRadius(3); */ - Factory.addGetterSetter(Transformer, 'anchorCornerRadius', 0, Validators.getNumberValidator()); + Factory.addGetterSetter(Transformer, 'anchorCornerRadius', 0, getNumberValidator()); /** * get/set border stroke color * @name Konva.Transformer#borderStroke @@ -14581,7 +14552,7 @@ * // set * transformer.borderStrokeWidth(3); */ - Factory.addGetterSetter(Transformer, 'borderStrokeWidth', 1, Validators.getNumberValidator()); + Factory.addGetterSetter(Transformer, 'borderStrokeWidth', 1, getNumberValidator()); /** * get/set border dash array * @name Konva.Transformer#borderDash @@ -14652,7 +14623,7 @@ * // set * transformer.padding(10); */ - Factory.addGetterSetter(Transformer, 'padding', 0, Validators.getNumberValidator()); + Factory.addGetterSetter(Transformer, 'padding', 0, getNumberValidator()); /** * get/set attached node of the Transformer. Transformer will adapt to its size and listen to its events * @method @@ -14825,7 +14796,7 @@ * // set radius * wedge.radius(10); */ - Factory.addGetterSetter(Wedge, 'radius', 0, Validators.getNumberValidator()); + Factory.addGetterSetter(Wedge, 'radius', 0, getNumberValidator()); /** * get/set angle in degrees * @name Konva.Wedge#angle @@ -14839,7 +14810,7 @@ * // set angle * wedge.angle(20); */ - Factory.addGetterSetter(Wedge, 'angle', 0, Validators.getNumberValidator()); + Factory.addGetterSetter(Wedge, 'angle', 0, getNumberValidator()); /** * get/set clockwise flag * @name Konva.Wedge#clockwise @@ -15612,7 +15583,7 @@ filterGaussBlurRGBA(imageData, radius); } }; - Factory.addGetterSetter(Node, 'blurRadius', 0, Validators.getNumberValidator(), Factory.afterSetFilter); + Factory.addGetterSetter(Node, 'blurRadius', 0, getNumberValidator(), Factory.afterSetFilter); /** * get/set blur radius. Use with {@link Konva.Filters.Blur} filter * @name Konva.Node#blurRadius @@ -15642,7 +15613,7 @@ data[i + 2] += brightness; } }; - Factory.addGetterSetter(Node, 'brightness', 0, Validators.getNumberValidator(), Factory.afterSetFilter); + Factory.addGetterSetter(Node, 'brightness', 0, getNumberValidator(), Factory.afterSetFilter); /** * get/set filter brightness. The brightness is a number between -1 and 1.  Positive values * brighten the pixels and negative values darken them. Use with {@link Konva.Filters.Brighten} filter. @@ -15704,7 +15675,7 @@ * @param {Number} contrast value between -100 and 100 * @returns {Number} */ - Factory.addGetterSetter(Node, 'contrast', 0, Validators.getNumberValidator(), Factory.afterSetFilter); + Factory.addGetterSetter(Node, 'contrast', 0, getNumberValidator(), Factory.afterSetFilter); /** * Emboss Filter. @@ -15820,7 +15791,7 @@ } while (--x); } while (--y); }; - Factory.addGetterSetter(Node, 'embossStrength', 0.5, Validators.getNumberValidator(), Factory.afterSetFilter); + Factory.addGetterSetter(Node, 'embossStrength', 0.5, getNumberValidator(), Factory.afterSetFilter); /** * get/set emboss strength. Use with {@link Konva.Filters.Emboss} filter. * @name Konva.Node#embossStrength @@ -15828,7 +15799,7 @@ * @param {Number} level between 0 and 1. Default is 0.5 * @returns {Number} */ - Factory.addGetterSetter(Node, 'embossWhiteLevel', 0.5, Validators.getNumberValidator(), Factory.afterSetFilter); + Factory.addGetterSetter(Node, 'embossWhiteLevel', 0.5, getNumberValidator(), Factory.afterSetFilter); /** * get/set emboss white level. Use with {@link Konva.Filters.Emboss} filter. * @name Konva.Node#embossWhiteLevel @@ -15967,7 +15938,7 @@ * @param {Float} amount * @returns {Float} */ - Factory.addGetterSetter(Node, 'enhance', 0, Validators.getNumberValidator(), Factory.afterSetFilter); + Factory.addGetterSetter(Node, 'enhance', 0, getNumberValidator(), Factory.afterSetFilter); /** * Grayscale Filter @@ -15991,7 +15962,7 @@ } }; - Factory.addGetterSetter(Node, 'hue', 0, Validators.getNumberValidator(), Factory.afterSetFilter); + Factory.addGetterSetter(Node, 'hue', 0, getNumberValidator(), Factory.afterSetFilter); /** * get/set hsv hue in degrees. Use with {@link Konva.Filters.HSV} or {@link Konva.Filters.HSL} filter. * @name Konva.Node#hue @@ -15999,7 +15970,7 @@ * @param {Number} hue value between 0 and 359 * @returns {Number} */ - Factory.addGetterSetter(Node, 'saturation', 0, Validators.getNumberValidator(), Factory.afterSetFilter); + Factory.addGetterSetter(Node, 'saturation', 0, getNumberValidator(), Factory.afterSetFilter); /** * get/set hsv saturation. Use with {@link Konva.Filters.HSV} or {@link Konva.Filters.HSL} filter. * @name Konva.Node#saturation @@ -16007,7 +15978,7 @@ * @param {Number} saturation 0 is no change, -1.0 halves the saturation, 1.0 doubles, etc.. * @returns {Number} */ - Factory.addGetterSetter(Node, 'luminance', 0, Validators.getNumberValidator(), Factory.afterSetFilter); + Factory.addGetterSetter(Node, 'luminance', 0, getNumberValidator(), Factory.afterSetFilter); /** * get/set hsl luminance. Use with {@link Konva.Filters.HSL} filter. * @name Konva.Node#luminance @@ -16097,7 +16068,7 @@ data[i + 3] = a; // alpha } }; - Factory.addGetterSetter(Node, 'hue', 0, Validators.getNumberValidator(), Factory.afterSetFilter); + Factory.addGetterSetter(Node, 'hue', 0, getNumberValidator(), Factory.afterSetFilter); /** * get/set hsv hue in degrees. Use with {@link Konva.Filters.HSV} or {@link Konva.Filters.HSL} filter. * @name Konva.Node#hue @@ -16105,7 +16076,7 @@ * @param {Number} hue value between 0 and 359 * @returns {Number} */ - Factory.addGetterSetter(Node, 'saturation', 0, Validators.getNumberValidator(), Factory.afterSetFilter); + Factory.addGetterSetter(Node, 'saturation', 0, getNumberValidator(), Factory.afterSetFilter); /** * get/set hsv saturation. Use with {@link Konva.Filters.HSV} or {@link Konva.Filters.HSL} filter. * @name Konva.Node#saturation @@ -16113,7 +16084,7 @@ * @param {Number} saturation 0 is no change, -1.0 halves the saturation, 1.0 doubles, etc.. * @returns {Number} */ - Factory.addGetterSetter(Node, 'value', 0, Validators.getNumberValidator(), Factory.afterSetFilter); + Factory.addGetterSetter(Node, 'value', 0, getNumberValidator(), Factory.afterSetFilter); /** * get/set hsv value. Use with {@link Konva.Filters.HSV} filter. * @name Konva.Node#value @@ -16345,7 +16316,7 @@ * @param {Integer} power of kaleidoscope * @returns {Integer} */ - Factory.addGetterSetter(Node, 'kaleidoscopePower', 2, Validators.getNumberValidator(), Factory.afterSetFilter); + Factory.addGetterSetter(Node, 'kaleidoscopePower', 2, getNumberValidator(), Factory.afterSetFilter); /** * get/set kaleidoscope angle. Use with {@link Konva.Filters.Kaleidoscope} filter. * @name Konva.Node#kaleidoscopeAngle @@ -16353,7 +16324,7 @@ * @param {Integer} degrees * @returns {Integer} */ - Factory.addGetterSetter(Node, 'kaleidoscopeAngle', 0, Validators.getNumberValidator(), Factory.afterSetFilter); + Factory.addGetterSetter(Node, 'kaleidoscopeAngle', 0, getNumberValidator(), Factory.afterSetFilter); function pixelAt(idata, x, y) { var idx = (y * idata.width + x) * 4; @@ -16509,7 +16480,7 @@ } return imageData; }; - Factory.addGetterSetter(Node, 'threshold', 0, Validators.getNumberValidator(), Factory.afterSetFilter); + Factory.addGetterSetter(Node, 'threshold', 0, getNumberValidator(), Factory.afterSetFilter); /** * Noise Filter. Randomly adds or substracts to the color channels @@ -16531,7 +16502,7 @@ data[i + 2] += half - 2 * half * Math.random(); } }; - Factory.addGetterSetter(Node, 'noise', 0.2, Validators.getNumberValidator(), Factory.afterSetFilter); + Factory.addGetterSetter(Node, 'noise', 0.2, getNumberValidator(), Factory.afterSetFilter); /** * get/set noise amount. Must be a value between 0 and 1. Use with {@link Konva.Filters.Noise} filter. * @name Konva.Node#noise @@ -16617,7 +16588,7 @@ } } }; - Factory.addGetterSetter(Node, 'pixelSize', 8, Validators.getNumberValidator(), Factory.afterSetFilter); + Factory.addGetterSetter(Node, 'pixelSize', 8, getNumberValidator(), Factory.afterSetFilter); /** * get/set pixel size. Use with {@link Konva.Filters.Pixelate} filter. * @name Konva.Node#pixelSize @@ -16647,7 +16618,7 @@ data[i] = Math.floor(data[i] / scale) * scale; } }; - Factory.addGetterSetter(Node, 'levels', 0.5, Validators.getNumberValidator(), Factory.afterSetFilter); + Factory.addGetterSetter(Node, 'levels', 0.5, getNumberValidator(), Factory.afterSetFilter); /** * get/set levels. Must be a number between 0 and 1. Use with {@link Konva.Filters.Posterize} filter. * @name Konva.Node#levels @@ -16720,7 +16691,7 @@ * @param {Integer} green value between 0 and 255 * @returns {Integer} */ - Factory.addGetterSetter(Node, 'blue', 0, Validators.RGBComponent, Factory.afterSetFilter); + Factory.addGetterSetter(Node, 'blue', 0, RGBComponent, Factory.afterSetFilter); /** * get/set filter blue value. Use with {@link Konva.Filters.RGB} filter. * @name blue @@ -16793,7 +16764,7 @@ * @param {Integer} green value between 0 and 255 * @returns {Integer} */ - Factory.addGetterSetter(Node, 'blue', 0, Validators.RGBComponent, Factory.afterSetFilter); + Factory.addGetterSetter(Node, 'blue', 0, RGBComponent, Factory.afterSetFilter); /** * get/set filter blue value. Use with {@link Konva.Filters.RGBA} filter. * @name blue @@ -16904,7 +16875,7 @@ data[i] = data[i] < level ? 0 : 255; } }; - Factory.addGetterSetter(Node, 'threshold', 0.5, Validators.getNumberValidator(), Factory.afterSetFilter); + Factory.addGetterSetter(Node, 'threshold', 0.5, getNumberValidator(), Factory.afterSetFilter); /** * get/set threshold. Must be a value between 0 and 1. Use with {@link Konva.Filters.Threshold} or {@link Konva.Filters.Mask} filter. * @name threshold diff --git a/konva.min.js b/konva.min.js index 0b9ec460..694527da 100644 --- a/konva.min.js +++ b/konva.min.js @@ -3,10 +3,10 @@ * Konva JavaScript Framework v3.0.0-3 * http://konvajs.org/ * Licensed under the MIT - * Date: Sat Feb 23 2019 + * Date: Sun Feb 24 2019 * * Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS) * Modified work Copyright (C) 2014 - present by Anton Lavrenov (Konva) * * @license - */var e=Math.PI/180,n="undefined"!=typeof window&&("[object Window]"==={}.toString.call(window)||"[object global]"==={}.toString.call(window)),t=/comment/.test(function(){}.toString()),L=function(t){return O().angleDeg?t*e:t},i=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)||[],r=!!t.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i),n=!!t.match(/IEMobile/i);return{browser:i[1]||"",version:i[2]||"0",isIE:function(t){var e=t.indexOf("msie ");if(0>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 u?{r:(e=u[t])[0],g:e[1],b:e[2]}:"#"===t[0]?this._hexToRgb(t.substring(1)):"rgb("===t.substr(0,4)?(e=p.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",D._namedColorToRBA(t)||D._hex3ColorToRGBA(t)||D._hex6ColorToRGBA(t)||D._rgbColorToRGBA(t)||D._rgbaColorToRGBA(t)},_namedColorToRBA:function(t){var e=u[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}},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(r=0;r=this.parent.children.length)&&D.warn("Unexpected value "+t+" for zIndex property. zIndex is just index of a node in children of its parent. Expected value is from 0 to "+(this.parent.children.length-1)+".");var e=this.index;return this.parent.children.splice(e,1),this.parent.children.splice(t,0,this),this.parent._setChildrenIndices(),this},s.prototype.getAbsoluteOpacity=function(){return this._getCache(B,this._getAbsoluteOpacity)},s.prototype._getAbsoluteOpacity=function(){var t=this.opacity(),e=this.getParent();return e&&!e._isUnderCache&&(t*=this.getParent().getAbsoluteOpacity()),t},s.prototype.moveTo=function(t){return this.getParent()!==t&&(this._remove(),t.add(this)),this},s.prototype.toObject=function(){var t,e,i,r={},n=this.getAttrs();for(t in r.attrs={},n)e=n[t],D.isObject(e)&&!D._isPlainObject(e)&&!D._isArray(e)||(i="function"==typeof this[t]&&this[t],delete n[t],(i?i.call(this):null)!==(n[t]=e)&&(r.attrs[t]=e));return r.className=this.getClassName(),D._prepareToStringify(r)},s.prototype.toJSON=function(){return JSON.stringify(this.toObject())},s.prototype.getParent=function(){return this.parent},s.prototype.findAncestors=function(t,e,i){var r=[];e&&this._isMatch(t)&&r.push(this);for(var n=this.parent;n;){if(n===i)return r;n._isMatch(t)&&r.push(n),n=n.parent}return r},s.prototype.isAncestorOf=function(t){return!1},s.prototype.findAncestor=function(t,e,i){return this.findAncestors(t,e,i)[0]},s.prototype._isMatch=function(t){if(!t)return!1;var e,i,r=t.replace(/ /g,"").split(","),n=r.length;for(e=0;ethis.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())},t.prototype.getTime=function(){return this._time},t.prototype.setPosition=function(t){this.prevPos=this._pos,this.propFunc(t),this._pos=t},t.prototype.getPosition=function(t){return void 0===t&&(t=this._time),this.func(t,this.begin,this._change,this.duration)},t.prototype.play=function(){this.state=2,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire("onPlay")},t.prototype.reverse=function(){this.state=3,this._time=this.duration-this._time,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire("onReverse")},t.prototype.seek=function(t){this.pause(),this._time=t,this.update(),this.fire("onSeek")},t.prototype.reset=function(){this.pause(),this._time=0,this.update(),this.fire("onReset")},t.prototype.finish=function(){this.pause(),this._time=this.duration,this.update(),this.fire("onFinish")},t.prototype.update=function(){this.setPosition(this.getPosition(this._time))},t.prototype.onEnterFrame=function(){var t=this.getTimer()-this._startTime;2===this.state?this.setTime(t):3===this.state&&this.setTime(this.duration-t)},t.prototype.pause=function(){this.state=1,this.fire("onPause")},t.prototype.getTimer=function(){return(new Date).getTime()},t}(),Yt=function(){function p(t){var e,i,r=this,n=t.node,a=n._id,o=t.easing||Xt.Linear,s=!!t.yoyo;e=void 0===t.duration?.3:0===t.duration?.001:t.duration,this.node=n,this._id=zt++;var h=n.getLayer()||(n instanceof O().Stage?n.getLayers():null);for(i in h||D.error("Tween constructor have `node` that is not in a layer. Please add node into layer first."),this.anim=new G(function(){r.tween.onEnterFrame()},h),this.tween=new Wt(i,function(t){r._tweenFunc(t)},o,0,1,1e3*e,s),this._addListeners(),p.attrs[a]||(p.attrs[a]={}),p.attrs[a][this._id]||(p.attrs[a][this._id]={}),p.tweens[a]||(p.tweens[a]={}),t)void 0===Vt[i]&&this._addAttr(i,t[i]);this.reset(),this.onFinish=t.onFinish,this.onReset=t.onReset}return p.prototype._addAttr=function(t,e){var i,r,n,a,o,s,h,l,d=this.node,c=d._id;if((n=p.tweens[c][t])&&delete p.attrs[c][n][t],i=d.getAttr(t),D._isArray(e))if(r=[],o=Math.max(e.length,i.length),"points"===t&&e.length!==i.length&&(e.length>i.length?(h=i,i=D._prepareArrayForTween(i,e,d.closed())):(s=e,e=D._prepareArrayForTween(e,i,d.closed()))),0===t.indexOf("fill"))for(a=0;athis.dataArray[i].pathLength;)t-=this.dataArray[i].pathLength,++i;if(i===r)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 n=this.dataArray[i],a=n.points;switch(n.command){case"L":return p.getPointOnLine(t,n.start.x,n.start.y,a[0],a[1]);case"C":return p.getPointOnCubicBezier(t/n.pathLength,n.start.x,n.start.y,a[0],a[1],a[2],a[3],a[4],a[5]);case"Q":return p.getPointOnQuadraticBezier(t/n.pathLength,n.start.x,n.start.y,a[0],a[1],a[2],a[3]);case"A":var o=a[0],s=a[1],h=a[2],l=a[3],d=a[4],c=a[5],u=a[6];return d+=c*t/n.pathLength,p.getPointOnEllipticalArc(o,s,h,l,d,u)}return null},p.getLineLength=function(t,e,i,r){return Math.sqrt((i-t)*(i-t)+(r-e)*(r-e))},p.getPointOnLine=function(t,e,i,r,n,a,o){void 0===a&&(a=e),void 0===o&&(o=i);var s=(n-i)/(r-e+1e-8),h=Math.sqrt(t*t/(1+s*s));r>>1,P=_.slice(0,k+1),T=this._getTextWidth(P)+v;T<=l?(S=k+1,w=P+(g?"…":""),C=T):x=k}if(!w)break;if(f){var M,A=_[w.length];0<(M=(" "===A||"-"===A)&&C<=l?w.length:Math.max(w.lastIndexOf(" "),w.lastIndexOf("-"))+1)&&(S=M,w=w.slice(0,S),C=this._getTextWidth(w))}if(w=w.trimRight(),this._addTextLine(w),i=Math.max(i,C),c+=r,!p||s&&de?g=ae.getPointOnLine(e,f.x,f.y,v.points[0],v.points[1],f.x,f.y):v=void 0;break;case"A":var o=v.points[4],s=v.points[5],h=v.points[4]+s;0===m?m=o+1e-8:iv.pathLength?1e-8:e/v.pathLength:i>V,0!==C?(C=255/C,P[s]=(l*B>>V)*C,P[s+1]=(d*B>>V)*C,P[s+2]=(c*B>>V)*C):P[s]=P[s+1]=P[s+2]=0,l-=p,d-=f,c-=g,u-=v,p-=F.r,f-=F.g,g-=F.b,v-=F.a,a=h+((a=i+e+1)>V,0>V)*C,P[a+1]=(d*B>>V)*C,P[a+2]=(c*B>>V)*C):P[a]=P[a+1]=P[a+2]=0,l-=p,d-=f,c-=g,u-=v,p-=F.r,f-=F.g,g-=F.b,v-=F.a,a=i+((a=r+L)>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 d?{r:(e=d[t])[0],g:e[1],b:e[2]}:"#"===t[0]?this._hexToRgb(t.substring(1)):"rgb("===t.substr(0,4)?(e=u.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",D._namedColorToRBA(t)||D._hex3ColorToRGBA(t)||D._hex6ColorToRGBA(t)||D._rgbColorToRGBA(t)||D._rgbaColorToRGBA(t)},_namedColorToRBA:function(t){var e=d[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}},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=this.parent.children.length)&&D.warn("Unexpected value "+t+" for zIndex property. zIndex is just index of a node in children of its parent. Expected value is from 0 to "+(this.parent.children.length-1)+".");var e=this.index;return this.parent.children.splice(e,1),this.parent.children.splice(t,0,this),this.parent._setChildrenIndices(),this},s.prototype.getAbsoluteOpacity=function(){return this._getCache(X,this._getAbsoluteOpacity)},s.prototype._getAbsoluteOpacity=function(){var t=this.opacity(),e=this.getParent();return e&&!e._isUnderCache&&(t*=this.getParent().getAbsoluteOpacity()),t},s.prototype.moveTo=function(t){return this.getParent()!==t&&(this._remove(),t.add(this)),this},s.prototype.toObject=function(){var t,e,i,n={},r=this.getAttrs();for(t in n.attrs={},r)e=r[t],D.isObject(e)&&!D._isPlainObject(e)&&!D._isArray(e)||(i="function"==typeof this[t]&&this[t],delete r[t],(i?i.call(this):null)!==(r[t]=e)&&(n.attrs[t]=e));return n.className=this.getClassName(),D._prepareToStringify(n)},s.prototype.toJSON=function(){return JSON.stringify(this.toObject())},s.prototype.getParent=function(){return this.parent},s.prototype.findAncestors=function(t,e,i){var n=[];e&&this._isMatch(t)&&n.push(this);for(var r=this.parent;r;){if(r===i)return n;r._isMatch(t)&&n.push(r),r=r.parent}return n},s.prototype.isAncestorOf=function(t){return!1},s.prototype.findAncestor=function(t,e,i){return this.findAncestors(t,e,i)[0]},s.prototype._isMatch=function(t){if(!t)return!1;var e,i,n=t.replace(/ /g,"").split(","),r=n.length;for(e=0;ethis.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())},t.prototype.getTime=function(){return this._time},t.prototype.setPosition=function(t){this.prevPos=this._pos,this.propFunc(t),this._pos=t},t.prototype.getPosition=function(t){return void 0===t&&(t=this._time),this.func(t,this.begin,this._change,this.duration)},t.prototype.play=function(){this.state=2,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire("onPlay")},t.prototype.reverse=function(){this.state=3,this._time=this.duration-this._time,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire("onReverse")},t.prototype.seek=function(t){this.pause(),this._time=t,this.update(),this.fire("onSeek")},t.prototype.reset=function(){this.pause(),this._time=0,this.update(),this.fire("onReset")},t.prototype.finish=function(){this.pause(),this._time=this.duration,this.update(),this.fire("onFinish")},t.prototype.update=function(){this.setPosition(this.getPosition(this._time))},t.prototype.onEnterFrame=function(){var t=this.getTimer()-this._startTime;2===this.state?this.setTime(t):3===this.state&&this.setTime(this.duration-t)},t.prototype.pause=function(){this.state=1,this.fire("onPause")},t.prototype.getTimer=function(){return(new Date).getTime()},t}(),Kt=function(){function u(t){var e,i,n=this,r=t.node,a=r._id,o=t.easing||Qt.Linear,s=!!t.yoyo;e=void 0===t.duration?.3:0===t.duration?.001:t.duration,this.node=r,this._id=Ut++;var h=r.getLayer()||(r instanceof O().Stage?r.getLayers():null);for(i in h||D.error("Tween constructor have `node` that is not in a layer. Please add node into layer first."),this.anim=new z(function(){n.tween.onEnterFrame()},h),this.tween=new Vt(i,function(t){n._tweenFunc(t)},o,0,1,1e3*e,s),this._addListeners(),u.attrs[a]||(u.attrs[a]={}),u.attrs[a][this._id]||(u.attrs[a][this._id]={}),u.tweens[a]||(u.tweens[a]={}),t)void 0===jt[i]&&this._addAttr(i,t[i]);this.reset(),this.onFinish=t.onFinish,this.onReset=t.onReset}return u.prototype._addAttr=function(t,e){var i,n,r,a,o,s,h,l,c=this.node,d=c._id;if((r=u.tweens[d][t])&&delete u.attrs[d][r][t],i=c.getAttr(t),D._isArray(e))if(n=[],o=Math.max(e.length,i.length),"points"===t&&e.length!==i.length&&(e.length>i.length?(h=i,i=D._prepareArrayForTween(i,e,c.closed())):(s=e,e=D._prepareArrayForTween(e,i,c.closed()))),0===t.indexOf("fill"))for(a=0;athis.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 r=this.dataArray[i],a=r.points;switch(r.command){case"L":return u.getPointOnLine(t,r.start.x,r.start.y,a[0],a[1]);case"C":return u.getPointOnCubicBezier(t/r.pathLength,r.start.x,r.start.y,a[0],a[1],a[2],a[3],a[4],a[5]);case"Q":return u.getPointOnQuadraticBezier(t/r.pathLength,r.start.x,r.start.y,a[0],a[1],a[2],a[3]);case"A":var o=a[0],s=a[1],h=a[2],l=a[3],c=a[4],d=a[5],p=a[6];return c+=d*t/r.pathLength,u.getPointOnEllipticalArc(o,s,h,l,c,p)}return null},u.getLineLength=function(t,e,i,n){return Math.sqrt((i-t)*(i-t)+(n-e)*(n-e))},u.getPointOnLine=function(t,e,i,n,r,a,o){void 0===a&&(a=e),void 0===o&&(o=i);var s=(r-i)/(n-e+1e-8),h=Math.sqrt(t*t/(1+s*s));n>>1,P=_.slice(0,k+1),T=this._getTextWidth(P)+v;T<=l?(b=k+1,w=P+(g?"…":""),C=T):x=k}if(!w)break;if(f){var M,G=_[w.length];0<(M=(" "===G||"-"===G)&&C<=l?w.length:Math.max(w.lastIndexOf(" "),w.lastIndexOf("-"))+1)&&(b=M,w=w.slice(0,b),C=this._getTextWidth(w))}if(w=w.trimRight(),this._addTextLine(w),i=Math.max(i,C),d+=n,!u||s&&ce?g=ce.getPointOnLine(e,f.x,f.y,v.points[0],v.points[1],f.x,f.y):v=void 0;break;case"A":var o=v.points[4],s=v.points[5],h=v.points[4]+s;0===m?m=o+1e-8:iv.pathLength?1e-8:e/v.pathLength:i>N,0!==C?(C=255/C,P[s]=(l*B>>N)*C,P[s+1]=(c*B>>N)*C,P[s+2]=(d*B>>N)*C):P[s]=P[s+1]=P[s+2]=0,l-=u,c-=f,d-=g,p-=v,u-=E.r,f-=E.g,g-=E.b,v-=E.a,a=h+((a=i+e+1)>N,0>N)*C,P[a+1]=(c*B>>N)*C,P[a+2]=(d*B>>N)*C):P[a]=P[a+1]=P[a+2]=0,l-=u,c-=f,d-=g,p-=v,u-=E.r,f-=E.g,g-=E.b,v-=E.a,a=i+((a=n+L) 255) { - return 255; - } else if (val < 0) { - return 0; - } - return Math.round(val); - }, - alphaComponent(val) { - if (val > 1) { - return 1; - } else if (val < 0.0001) { - // chrome does not honor alpha values of 0 - return 0.0001; - } - - return val; - }, - _formatValue(val) { - if (Util._isString(val)) { - return '"' + val + '"'; - } - if (Object.prototype.toString.call(val) === '[object Number]') { - return val; - } - if (Util._isBoolean(val)) { - return val; - } - return Object.prototype.toString.call(val); - }, - getNumberValidator() { - if (isUnminified) { - return function(val, attr) { - if (!Util._isNumber(val)) { - Util.warn( - Validators._formatValue(val) + - ' is a not valid value for "' + - attr + - '" attribute. The value should be a number.' - ); - } - return val; - }; - } - }, - getNumberOrAutoValidator() { - if (isUnminified) { - return function(val, attr) { - var isNumber = Util._isNumber(val); - var isAuto = val === 'auto'; - - if (!(isNumber || isAuto)) { - Util.warn( - Validators._formatValue(val) + - ' is a not valid value for "' + - attr + - '" attribute. The value should be a number or "auto".' - ); - } - return val; - }; - } - }, - getStringValidator() { - if (isUnminified) { - return function(val, attr) { - if (!Util._isString(val)) { - Util.warn( - Validators._formatValue(val) + - ' is a not valid value for "' + - attr + - '" attribute. The value should be a string.' - ); - } - return val; - }; - } - }, - getFunctionValidator() { - if (isUnminified) { - return function(val, attr) { - if (!Util._isFunction(val)) { - Util.warn( - Validators._formatValue(val) + - ' is a not valid value for "' + - attr + - '" attribute. The value should be a function.' - ); - } - return val; - }; - } - }, - getNumberArrayValidator() { - if (isUnminified) { - return function(val, attr) { - if (!Util._isArray(val)) { - Util.warn( - 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 (!Util._isNumber(item)) { - Util.warn( - '"' + - attr + - '" attribute has non numeric element ' + - item + - '. Make sure that all elements are numbers.' - ); - } - }); - } - return val; - }; - } - }, - getBooleanValidator() { - if (isUnminified) { - return function(val, attr) { - var isBool = val === true || val === false; - if (!isBool) { - Util.warn( - Validators._formatValue(val) + - ' is a not valid value for "' + - attr + - '" attribute. The value should be a boolean.' - ); - } - return val; - }; - } - }, - getComponentValidator(components) { - if (isUnminified) { - return function(val, attr) { - if (!Util.isObject(val)) { - Util.warn( - Validators._formatValue(val) + - ' is a not valid value for "' + - attr + - '" attribute. The value should be an object with properties ' + - components - ); - } - return val; - }; - } - } -}; diff --git a/src/Group.ts b/src/Group.ts index bfc135fb..465134a7 100644 --- a/src/Group.ts +++ b/src/Group.ts @@ -1,6 +1,6 @@ import { Util, Collection } from './Util'; -import { Factory, Validators } from './Factory'; import { Container } from './Container'; + /** * Group constructor. Groups are used to contain shapes or other groups. * @constructor diff --git a/src/Layer.ts b/src/Layer.ts index f2bebad2..d91abae4 100644 --- a/src/Layer.ts +++ b/src/Layer.ts @@ -1,9 +1,10 @@ import { Util, Collection } from './Util'; import { Container } from './Container'; -import { Factory, Validators } from './Factory'; +import { Factory } from './Factory'; import { BaseLayer } from './BaseLayer'; import { HitCanvas } from './Canvas'; import { shapes } from './Shape'; +import { getBooleanValidator } from './Validators'; import { GetSet } from './types'; @@ -233,12 +234,7 @@ export class Layer extends BaseLayer { hitGraphEnabled: GetSet; } -Factory.addGetterSetter( - Layer, - 'hitGraphEnabled', - true, - Validators.getBooleanValidator() -); +Factory.addGetterSetter(Layer, 'hitGraphEnabled', true, getBooleanValidator()); /** * get/set hitGraphEnabled flag. Disabling the hit graph will greatly increase * draw performance because the hit graph will not be redrawn each time the layer is diff --git a/src/Node.ts b/src/Node.ts index 5d77cd43..4f018023 100644 --- a/src/Node.ts +++ b/src/Node.ts @@ -1,10 +1,15 @@ import { Util, Collection, Transform, RectConf, Point } from './Util'; -import { Factory, Validators } from './Factory'; +import { Factory } from './Factory'; import { SceneCanvas, HitCanvas } from './Canvas'; import { getGlobalKonva } from './Global'; import { Container } from './Container'; import { GetSet, Vector2d } from './types'; import { DD } from './DragAndDrop'; +import { + getNumberValidator, + getStringValidator, + getBooleanValidator +} from './Validators'; export const ids = {}; export const names = {}; @@ -2412,7 +2417,7 @@ Factory.addGetterSetter(Node, 'position'); * }); */ -Factory.addGetterSetter(Node, 'x', 0, Validators.getNumberValidator()); +Factory.addGetterSetter(Node, 'x', 0, getNumberValidator()); /** * get/set x position @@ -2428,7 +2433,7 @@ Factory.addGetterSetter(Node, 'x', 0, Validators.getNumberValidator()); * node.x(5); */ -Factory.addGetterSetter(Node, 'y', 0, Validators.getNumberValidator()); +Factory.addGetterSetter(Node, 'y', 0, getNumberValidator()); /** * get/set y position @@ -2448,7 +2453,7 @@ Factory.addGetterSetter( Node, 'globalCompositeOperation', 'source-over', - Validators.getStringValidator() + getStringValidator() ); /** @@ -2464,7 +2469,7 @@ Factory.addGetterSetter( * // set globalCompositeOperation * shape.globalCompositeOperation('source-in'); */ -Factory.addGetterSetter(Node, 'opacity', 1, Validators.getNumberValidator()); +Factory.addGetterSetter(Node, 'opacity', 1, getNumberValidator()); /** * get/set opacity. Opacity values range from 0 to 1. @@ -2482,7 +2487,7 @@ Factory.addGetterSetter(Node, 'opacity', 1, Validators.getNumberValidator()); * node.opacity(0.5); */ -Factory.addGetterSetter(Node, 'name', '', Validators.getStringValidator()); +Factory.addGetterSetter(Node, 'name', '', getStringValidator()); /** * get/set name @@ -2501,7 +2506,7 @@ Factory.addGetterSetter(Node, 'name', '', Validators.getStringValidator()); * node.name('foo bar'); */ -Factory.addGetterSetter(Node, 'id', '', Validators.getStringValidator()); +Factory.addGetterSetter(Node, 'id', '', getStringValidator()); /** * get/set id. Id is global for whole page. @@ -2517,7 +2522,7 @@ Factory.addGetterSetter(Node, 'id', '', Validators.getStringValidator()); * node.id('foo'); */ -Factory.addGetterSetter(Node, 'rotation', 0, Validators.getNumberValidator()); +Factory.addGetterSetter(Node, 'rotation', 0, getNumberValidator()); /** * get/set rotation in degrees @@ -2554,7 +2559,7 @@ Factory.addComponentsGetterSetter(Node, 'scale', ['x', 'y']); * }); */ -Factory.addGetterSetter(Node, 'scaleX', 1, Validators.getNumberValidator()); +Factory.addGetterSetter(Node, 'scaleX', 1, getNumberValidator()); /** * get/set scale x @@ -2570,7 +2575,7 @@ Factory.addGetterSetter(Node, 'scaleX', 1, Validators.getNumberValidator()); * node.scaleX(2); */ -Factory.addGetterSetter(Node, 'scaleY', 1, Validators.getNumberValidator()); +Factory.addGetterSetter(Node, 'scaleY', 1, getNumberValidator()); /** * get/set scale y @@ -2607,7 +2612,7 @@ Factory.addComponentsGetterSetter(Node, 'skew', ['x', 'y']); * }); */ -Factory.addGetterSetter(Node, 'skewX', 0, Validators.getNumberValidator()); +Factory.addGetterSetter(Node, 'skewX', 0, getNumberValidator()); /** * get/set skew x @@ -2623,7 +2628,7 @@ Factory.addGetterSetter(Node, 'skewX', 0, Validators.getNumberValidator()); * node.skewX(3); */ -Factory.addGetterSetter(Node, 'skewY', 0, Validators.getNumberValidator()); +Factory.addGetterSetter(Node, 'skewY', 0, getNumberValidator()); /** * get/set skew y @@ -2659,7 +2664,7 @@ Factory.addComponentsGetterSetter(Node, 'offset', ['x', 'y']); * }); */ -Factory.addGetterSetter(Node, 'offsetX', 0, Validators.getNumberValidator()); +Factory.addGetterSetter(Node, 'offsetX', 0, getNumberValidator()); /** * get/set offset x @@ -2675,7 +2680,7 @@ Factory.addGetterSetter(Node, 'offsetX', 0, Validators.getNumberValidator()); * node.offsetX(3); */ -Factory.addGetterSetter(Node, 'offsetY', 0, Validators.getNumberValidator()); +Factory.addGetterSetter(Node, 'offsetY', 0, getNumberValidator()); /** * get/set offset y @@ -2691,12 +2696,7 @@ Factory.addGetterSetter(Node, 'offsetY', 0, Validators.getNumberValidator()); * node.offsetY(3); */ -Factory.addGetterSetter( - Node, - 'dragDistance', - null, - Validators.getNumberValidator() -); +Factory.addGetterSetter(Node, 'dragDistance', null, getNumberValidator()); /** * get/set drag distance @@ -2715,7 +2715,7 @@ Factory.addGetterSetter( * Konva.dragDistance = 3; */ -Factory.addGetterSetter(Node, 'width', 0, Validators.getNumberValidator()); +Factory.addGetterSetter(Node, 'width', 0, getNumberValidator()); /** * get/set width * @name Konva.Node#width @@ -2730,7 +2730,7 @@ Factory.addGetterSetter(Node, 'width', 0, Validators.getNumberValidator()); * node.width(100); */ -Factory.addGetterSetter(Node, 'height', 0, Validators.getNumberValidator()); +Factory.addGetterSetter(Node, 'height', 0, getNumberValidator()); /** * get/set height * @name Konva.Node#height @@ -2795,12 +2795,7 @@ Factory.addGetterSetter(Node, 'listening', 'inherit', function(val) { * shape.preventDefault(false); */ -Factory.addGetterSetter( - Node, - 'preventDefault', - true, - Validators.getBooleanValidator() -); +Factory.addGetterSetter(Node, 'preventDefault', true, getBooleanValidator()); Factory.addGetterSetter(Node, 'filters', null, function(val) { this._filterUpToDate = false; @@ -2861,12 +2856,7 @@ Factory.addGetterSetter(Node, 'visible', 'inherit', function(val) { * node.visible('inherit'); */ -Factory.addGetterSetter( - Node, - 'transformsEnabled', - 'all', - Validators.getStringValidator() -); +Factory.addGetterSetter(Node, 'transformsEnabled', 'all', getStringValidator()); /** * get/set transforms that are enabled. Can be "all", "none", or "position". The default @@ -2944,12 +2934,7 @@ Factory.addGetterSetter(Node, 'dragBoundFunc'); * // disable drag and drop * node.draggable(false); */ -Factory.addGetterSetter( - Node, - 'draggable', - false, - Validators.getBooleanValidator() -); +Factory.addGetterSetter(Node, 'draggable', false, getBooleanValidator()); Factory.backCompat(Node, { rotateDeg: 'rotate', diff --git a/src/Shape.ts b/src/Shape.ts index 388bad96..35f9013b 100644 --- a/src/Shape.ts +++ b/src/Shape.ts @@ -1,6 +1,11 @@ import { Util, Collection } from './Util'; -import { Factory, Validators } from './Factory'; +import { Factory } from './Factory'; import { Node } from './Node'; +import { + getNumberValidator, + getStringValidator, + getBooleanValidator +} from './Validators'; import { GetSet, Vector2d } from './types'; import { Context } from './Context'; @@ -699,12 +704,7 @@ Shape.prototype._centroid = false; Shape.prototype.nodeType = 'Shape'; // add getters and setters -Factory.addGetterSetter( - Shape, - 'stroke', - undefined, - Validators.getStringValidator() -); +Factory.addGetterSetter(Shape, 'stroke', undefined, getStringValidator()); /** * get/set stroke color @@ -729,12 +729,7 @@ Factory.addGetterSetter( * shape.stroke('rgba(0,255,0,0.5'); */ -Factory.addGetterSetter( - Shape, - 'strokeWidth', - 2, - Validators.getNumberValidator() -); +Factory.addGetterSetter(Shape, 'strokeWidth', 2, getNumberValidator()); /** * get/set stroke width @@ -750,12 +745,7 @@ Factory.addGetterSetter( * shape.strokeWidth(); */ -Factory.addGetterSetter( - Shape, - 'strokeHitEnabled', - true, - Validators.getBooleanValidator() -); +Factory.addGetterSetter(Shape, 'strokeHitEnabled', true, getBooleanValidator()); /** * get/set strokeHitEnabled property. Useful for performance optimization. @@ -779,7 +769,7 @@ Factory.addGetterSetter( Shape, 'perfectDrawEnabled', true, - Validators.getBooleanValidator() + getBooleanValidator() ); /** @@ -802,7 +792,7 @@ Factory.addGetterSetter( Shape, 'shadowForStrokeEnabled', true, - Validators.getBooleanValidator() + getBooleanValidator() ); /** @@ -918,12 +908,7 @@ Factory.addGetterSetter(Shape, 'dash'); * line.dash([10, 20, 0.001, 20]); */ -Factory.addGetterSetter( - Shape, - 'dashOffset', - 0, - Validators.getNumberValidator() -); +Factory.addGetterSetter(Shape, 'dashOffset', 0, getNumberValidator()); /** * get/set dash offset for stroke. @@ -937,12 +922,7 @@ Factory.addGetterSetter( * line.dashOffset(5); */ -Factory.addGetterSetter( - Shape, - 'shadowColor', - undefined, - Validators.getStringValidator() -); +Factory.addGetterSetter(Shape, 'shadowColor', undefined, getStringValidator()); /** * get/set shadow color @@ -967,12 +947,7 @@ Factory.addGetterSetter( * shape.shadowColor('rgba(0,255,0,0.5'); */ -Factory.addGetterSetter( - Shape, - 'shadowBlur', - 0, - Validators.getNumberValidator() -); +Factory.addGetterSetter(Shape, 'shadowBlur', 0, getNumberValidator()); /** * get/set shadow blur @@ -988,12 +963,7 @@ Factory.addGetterSetter( * shape.shadowBlur(10); */ -Factory.addGetterSetter( - Shape, - 'shadowOpacity', - 1, - Validators.getNumberValidator() -); +Factory.addGetterSetter(Shape, 'shadowOpacity', 1, getNumberValidator()); /** * get/set shadow opacity. must be a value between 0 and 1 @@ -1030,12 +1000,7 @@ Factory.addComponentsGetterSetter(Shape, 'shadowOffset', ['x', 'y']); * }); */ -Factory.addGetterSetter( - Shape, - 'shadowOffsetX', - 0, - Validators.getNumberValidator() -); +Factory.addGetterSetter(Shape, 'shadowOffsetX', 0, getNumberValidator()); /** * get/set shadow offset x @@ -1051,12 +1016,7 @@ Factory.addGetterSetter( * shape.shadowOffsetX(5); */ -Factory.addGetterSetter( - Shape, - 'shadowOffsetY', - 0, - Validators.getNumberValidator() -); +Factory.addGetterSetter(Shape, 'shadowOffsetY', 0, getNumberValidator()); /** * get/set shadow offset y @@ -1092,12 +1052,7 @@ Factory.addGetterSetter(Shape, 'fillPatternImage'); * imageObj.src = 'path/to/image/jpg'; */ -Factory.addGetterSetter( - Shape, - 'fill', - undefined, - Validators.getStringValidator() -); +Factory.addGetterSetter(Shape, 'fill', undefined, getStringValidator()); /** * get/set fill color @@ -1125,12 +1080,7 @@ Factory.addGetterSetter( * shape.fill(null); */ -Factory.addGetterSetter( - Shape, - 'fillPatternX', - 0, - Validators.getNumberValidator() -); +Factory.addGetterSetter(Shape, 'fillPatternX', 0, getNumberValidator()); /** * get/set fill pattern x @@ -1145,12 +1095,7 @@ Factory.addGetterSetter( * shape.fillPatternX(20); */ -Factory.addGetterSetter( - Shape, - 'fillPatternY', - 0, - Validators.getNumberValidator() -); +Factory.addGetterSetter(Shape, 'fillPatternY', 0, getNumberValidator()); /** * get/set fill pattern y @@ -1400,12 +1345,7 @@ Factory.addComponentsGetterSetter(Shape, 'fillPatternOffset', ['x', 'y']); * }); */ -Factory.addGetterSetter( - Shape, - 'fillPatternOffsetX', - 0, - Validators.getNumberValidator() -); +Factory.addGetterSetter(Shape, 'fillPatternOffsetX', 0, getNumberValidator()); /** * get/set fill pattern offset x @@ -1421,12 +1361,7 @@ Factory.addGetterSetter( * shape.fillPatternOffsetX(20); */ -Factory.addGetterSetter( - Shape, - 'fillPatternOffsetY', - 0, - Validators.getNumberValidator() -); +Factory.addGetterSetter(Shape, 'fillPatternOffsetY', 0, getNumberValidator()); /** * get/set fill pattern offset y @@ -1463,12 +1398,7 @@ Factory.addComponentsGetterSetter(Shape, 'fillPatternScale', ['x', 'y']); * }); */ -Factory.addGetterSetter( - Shape, - 'fillPatternScaleX', - 1, - Validators.getNumberValidator() -); +Factory.addGetterSetter(Shape, 'fillPatternScaleX', 1, getNumberValidator()); /** * get/set fill pattern scale x @@ -1484,12 +1414,7 @@ Factory.addGetterSetter( * shape.fillPatternScaleX(2); */ -Factory.addGetterSetter( - Shape, - 'fillPatternScaleY', - 1, - Validators.getNumberValidator() -); +Factory.addGetterSetter(Shape, 'fillPatternScaleY', 1, getNumberValidator()); /** * get/set fill pattern scale y diff --git a/src/Validators.ts b/src/Validators.ts new file mode 100644 index 00000000..24390f4c --- /dev/null +++ b/src/Validators.ts @@ -0,0 +1,157 @@ +import { isUnminified } from './Global'; +import { Util } from './Util'; + +function _formatValue(val) { + if (Util._isString(val)) { + return '"' + val + '"'; + } + if (Object.prototype.toString.call(val) === '[object Number]') { + return val; + } + if (Util._isBoolean(val)) { + return val; + } + return Object.prototype.toString.call(val); +} + +export function RGBComponent(val) { + if (val > 255) { + return 255; + } else if (val < 0) { + return 0; + } + return Math.round(val); +} +export function alphaComponent(val) { + if (val > 1) { + return 1; + } else if (val < 0.0001) { + // chrome does not honor alpha values of 0 + return 0.0001; + } + + return val; +} + +export function getNumberValidator() { + if (isUnminified) { + return function(val, attr) { + if (!Util._isNumber(val)) { + Util.warn( + _formatValue(val) + + ' is a not valid value for "' + + attr + + '" attribute. The value should be a number.' + ); + } + return val; + }; + } +} +export function getNumberOrAutoValidator() { + if (isUnminified) { + return function(val, attr) { + var isNumber = Util._isNumber(val); + var isAuto = val === 'auto'; + + if (!(isNumber || isAuto)) { + Util.warn( + _formatValue(val) + + ' is a not valid value for "' + + attr + + '" attribute. The value should be a number or "auto".' + ); + } + return val; + }; + } +} +export function getStringValidator() { + if (isUnminified) { + return function(val, attr) { + if (!Util._isString(val)) { + Util.warn( + _formatValue(val) + + ' is a not valid value for "' + + attr + + '" attribute. The value should be a string.' + ); + } + return val; + }; + } +} +export function getFunctionValidator() { + if (isUnminified) { + return function(val, attr) { + if (!Util._isFunction(val)) { + Util.warn( + _formatValue(val) + + ' is a not valid value for "' + + attr + + '" attribute. The value should be a function.' + ); + } + return val; + }; + } +} +export function getNumberArrayValidator() { + if (isUnminified) { + return function(val, attr) { + if (!Util._isArray(val)) { + Util.warn( + _formatValue(val) + + ' is a not valid value for "' + + attr + + '" attribute. The value should be a array of numbers.' + ); + } else { + val.forEach(function(item) { + if (!Util._isNumber(item)) { + Util.warn( + '"' + + attr + + '" attribute has non numeric element ' + + item + + '. Make sure that all elements are numbers.' + ); + } + }); + } + return val; + }; + } +} +export function getBooleanValidator() { + if (isUnminified) { + return function(val, attr) { + var isBool = val === true || val === false; + if (!isBool) { + Util.warn( + _formatValue(val) + + ' is a not valid value for "' + + attr + + '" attribute. The value should be a boolean.' + ); + } + return val; + }; + } +} +export function getComponentValidator(components) { + if (isUnminified) { + return function(val, attr) { + if (!Util.isObject(val)) { + Util.warn( + _formatValue(val) + + ' is a not valid value for "' + + attr + + '" attribute. The value should be an object with properties ' + + components + ); + } + return val; + }; + } +} diff --git a/src/filters/Blur.ts b/src/filters/Blur.ts index f773e287..c7fbd2c0 100644 --- a/src/filters/Blur.ts +++ b/src/filters/Blur.ts @@ -1,5 +1,6 @@ -import { Factory, Validators } from '../Factory'; +import { Factory } from '../Factory'; import { Node } from '../Node'; +import { getNumberValidator } from '../Validators'; /* the Gauss filter master repo: https://github.com/pavelpower/kineticjsGaussFilter @@ -838,7 +839,7 @@ Factory.addGetterSetter( Node, 'blurRadius', 0, - Validators.getNumberValidator(), + getNumberValidator(), Factory.afterSetFilter ); diff --git a/src/filters/Brighten.ts b/src/filters/Brighten.ts index 51d45cee..619f8f1a 100644 --- a/src/filters/Brighten.ts +++ b/src/filters/Brighten.ts @@ -1,5 +1,6 @@ -import { Factory, Validators } from '../Factory'; +import { Factory } from '../Factory'; import { Node, Filter } from '../Node'; +import { getNumberValidator } from '../Validators'; /** * Brighten Filter. @@ -31,7 +32,7 @@ Factory.addGetterSetter( Node, 'brightness', 0, - Validators.getNumberValidator(), + getNumberValidator(), Factory.afterSetFilter ); /** diff --git a/src/filters/Contrast.ts b/src/filters/Contrast.ts index 5474805c..43253e96 100644 --- a/src/filters/Contrast.ts +++ b/src/filters/Contrast.ts @@ -1,5 +1,6 @@ -import { Factory, Validators } from '../Factory'; +import { Factory } from '../Factory'; import { Node } from '../Node'; +import { getNumberValidator } from '../Validators'; /** * Contrast Filter. * @function @@ -69,6 +70,6 @@ Factory.addGetterSetter( Node, 'contrast', 0, - Validators.getNumberValidator(), + getNumberValidator(), Factory.afterSetFilter ); diff --git a/src/filters/Emboss.ts b/src/filters/Emboss.ts index 347ad96e..fb5ae1df 100644 --- a/src/filters/Emboss.ts +++ b/src/filters/Emboss.ts @@ -1,6 +1,7 @@ -import { Factory, Validators } from '../Factory'; +import { Factory } from '../Factory'; import { Node } from '../Node'; import { Util } from '../Util'; +import { getNumberValidator } from '../Validators'; /** * Emboss Filter. * Pixastic Lib - Emboss filter - v0.1.0 @@ -143,7 +144,7 @@ Factory.addGetterSetter( Node, 'embossStrength', 0.5, - Validators.getNumberValidator(), + getNumberValidator(), Factory.afterSetFilter ); /** @@ -158,7 +159,7 @@ Factory.addGetterSetter( Node, 'embossWhiteLevel', 0.5, - Validators.getNumberValidator(), + getNumberValidator(), Factory.afterSetFilter ); /** diff --git a/src/filters/Enhance.ts b/src/filters/Enhance.ts index dacddadd..b7822c51 100644 --- a/src/filters/Enhance.ts +++ b/src/filters/Enhance.ts @@ -1,5 +1,7 @@ -import { Factory, Validators } from '../Factory'; +import { Factory } from '../Factory'; import { Node } from '../Node'; +import { getNumberValidator } from '../Validators'; + function remap(fromValue, fromMin, fromMax, toMin, toMax) { // Compute the range of the data var fromRange = fromMax - fromMin, @@ -145,6 +147,6 @@ Factory.addGetterSetter( Node, 'enhance', 0, - Validators.getNumberValidator(), + getNumberValidator(), Factory.afterSetFilter ); diff --git a/src/filters/HSL.ts b/src/filters/HSL.ts index cebc011a..e15b326e 100644 --- a/src/filters/HSL.ts +++ b/src/filters/HSL.ts @@ -1,10 +1,12 @@ -import { Factory, Validators } from '../Factory'; +import { Factory } from '../Factory'; import { Node } from '../Node'; +import { getNumberValidator } from '../Validators'; + Factory.addGetterSetter( Node, 'hue', 0, - Validators.getNumberValidator(), + getNumberValidator(), Factory.afterSetFilter ); /** @@ -19,7 +21,7 @@ Factory.addGetterSetter( Node, 'saturation', 0, - Validators.getNumberValidator(), + getNumberValidator(), Factory.afterSetFilter ); /** @@ -34,7 +36,7 @@ Factory.addGetterSetter( Node, 'luminance', 0, - Validators.getNumberValidator(), + getNumberValidator(), Factory.afterSetFilter ); /** diff --git a/src/filters/HSV.ts b/src/filters/HSV.ts index 20715717..08bb202b 100644 --- a/src/filters/HSV.ts +++ b/src/filters/HSV.ts @@ -1,5 +1,7 @@ -import { Factory, Validators } from '../Factory'; +import { Factory } from '../Factory'; import { Node } from '../Node'; +import { getNumberValidator } from '../Validators'; + /** * HSV Filter. Adjusts the hue, saturation and value * @function @@ -64,7 +66,7 @@ Factory.addGetterSetter( Node, 'hue', 0, - Validators.getNumberValidator(), + getNumberValidator(), Factory.afterSetFilter ); /** @@ -79,7 +81,7 @@ Factory.addGetterSetter( Node, 'saturation', 0, - Validators.getNumberValidator(), + getNumberValidator(), Factory.afterSetFilter ); /** @@ -94,7 +96,7 @@ Factory.addGetterSetter( Node, 'value', 0, - Validators.getNumberValidator(), + getNumberValidator(), Factory.afterSetFilter ); /** diff --git a/src/filters/Kaleidoscope.ts b/src/filters/Kaleidoscope.ts index e110beba..b55c0dc5 100644 --- a/src/filters/Kaleidoscope.ts +++ b/src/filters/Kaleidoscope.ts @@ -1,6 +1,8 @@ -import { Factory, Validators } from '../Factory'; +import { Factory } from '../Factory'; import { Node } from '../Node'; import { Util } from '../Util'; +import { getNumberValidator } from '../Validators'; + /* * ToPolar Filter. Converts image data to polar coordinates. Performs * w*h*4 pixel reads and w*h pixel writes. The r axis is placed along @@ -274,7 +276,7 @@ Factory.addGetterSetter( Node, 'kaleidoscopePower', 2, - Validators.getNumberValidator(), + getNumberValidator(), Factory.afterSetFilter ); @@ -289,6 +291,6 @@ Factory.addGetterSetter( Node, 'kaleidoscopeAngle', 0, - Validators.getNumberValidator(), + getNumberValidator(), Factory.afterSetFilter ); diff --git a/src/filters/Mask.ts b/src/filters/Mask.ts index 5eac4c3a..3b71b163 100644 --- a/src/filters/Mask.ts +++ b/src/filters/Mask.ts @@ -1,5 +1,6 @@ -import { Factory, Validators } from '../Factory'; +import { Factory } from '../Factory'; import { Node } from '../Node'; +import { getNumberValidator } from '../Validators'; function pixelAt(idata, x, y) { var idx = (y * idata.width + x) * 4; @@ -203,6 +204,6 @@ Factory.addGetterSetter( Node, 'threshold', 0, - Validators.getNumberValidator(), + getNumberValidator(), Factory.afterSetFilter ); diff --git a/src/filters/Noise.ts b/src/filters/Noise.ts index 220dfd22..56e8f368 100644 --- a/src/filters/Noise.ts +++ b/src/filters/Noise.ts @@ -1,5 +1,7 @@ -import { Factory, Validators } from '../Factory'; +import { Factory } from '../Factory'; import { Node } from '../Node'; +import { getNumberValidator } from '../Validators'; + /** * Noise Filter. Randomly adds or substracts to the color channels * @function @@ -30,7 +32,7 @@ Factory.addGetterSetter( Node, 'noise', 0.2, - Validators.getNumberValidator(), + getNumberValidator(), Factory.afterSetFilter ); /** diff --git a/src/filters/Pixelate.ts b/src/filters/Pixelate.ts index 42eef672..6d251152 100644 --- a/src/filters/Pixelate.ts +++ b/src/filters/Pixelate.ts @@ -1,7 +1,9 @@ /*eslint-disable max-depth */ -import { Factory, Validators } from '../Factory'; +import { Factory } from '../Factory'; import { Util } from '../Util'; import { Node } from '../Node'; +import { getNumberValidator } from '../Validators'; + /** * Pixelate Filter. Averages groups of pixels and redraws * them as larger pixels @@ -107,7 +109,7 @@ Factory.addGetterSetter( Node, 'pixelSize', 8, - Validators.getNumberValidator(), + getNumberValidator(), Factory.afterSetFilter ); /** diff --git a/src/filters/Posterize.ts b/src/filters/Posterize.ts index 12860b3e..0eb7449e 100644 --- a/src/filters/Posterize.ts +++ b/src/filters/Posterize.ts @@ -1,5 +1,6 @@ -import { Factory, Validators } from '../Factory'; +import { Factory } from '../Factory'; import { Node } from '../Node'; +import { getNumberValidator } from '../Validators'; /** * Posterize Filter. Adjusts the channels so that there are no more * than n different values for that channel. This is also applied @@ -32,7 +33,7 @@ Factory.addGetterSetter( Node, 'levels', 0.5, - Validators.getNumberValidator(), + getNumberValidator(), Factory.afterSetFilter ); diff --git a/src/filters/RGB.ts b/src/filters/RGB.ts index 4c7df0a9..03c78c38 100644 --- a/src/filters/RGB.ts +++ b/src/filters/RGB.ts @@ -1,5 +1,7 @@ -import { Factory, Validators } from '../Factory'; +import { Factory } from '../Factory'; import { Node } from '../Node'; +import { RGBComponent } from '../Validators'; + /** * RGB Filter * @function @@ -71,13 +73,7 @@ Factory.addGetterSetter(Node, 'green', 0, function(val) { * @returns {Integer} */ -Factory.addGetterSetter( - Node, - 'blue', - 0, - Validators.RGBComponent, - Factory.afterSetFilter -); +Factory.addGetterSetter(Node, 'blue', 0, RGBComponent, Factory.afterSetFilter); /** * get/set filter blue value. Use with {@link Konva.Filters.RGB} filter. * @name blue diff --git a/src/filters/RGBA.ts b/src/filters/RGBA.ts index a429b3c4..b9a5ff97 100644 --- a/src/filters/RGBA.ts +++ b/src/filters/RGBA.ts @@ -1,5 +1,7 @@ -import { Factory, Validators } from '../Factory'; +import { Factory } from '../Factory'; import { Node } from '../Node'; +import { RGBComponent } from '../Validators'; + /** * RGBA Filter * @function @@ -72,13 +74,7 @@ Factory.addGetterSetter(Node, 'green', 0, function(val) { * @returns {Integer} */ -Factory.addGetterSetter( - Node, - 'blue', - 0, - Validators.RGBComponent, - Factory.afterSetFilter -); +Factory.addGetterSetter(Node, 'blue', 0, RGBComponent, Factory.afterSetFilter); /** * get/set filter blue value. Use with {@link Konva.Filters.RGBA} filter. * @name blue diff --git a/src/filters/Threshold.ts b/src/filters/Threshold.ts index 7598e6a8..1be363bc 100644 --- a/src/filters/Threshold.ts +++ b/src/filters/Threshold.ts @@ -1,5 +1,6 @@ -import { Factory, Validators } from '../Factory'; +import { Factory } from '../Factory'; import { Node } from '../Node'; +import { getNumberValidator } from '../Validators'; /** * Threshold Filter. Pushes any value above the mid point to * the max and any value below the mid point to the min. @@ -30,7 +31,7 @@ Factory.addGetterSetter( Node, 'threshold', 0.5, - Validators.getNumberValidator(), + getNumberValidator(), Factory.afterSetFilter ); /** diff --git a/src/shapes/Arc.ts b/src/shapes/Arc.ts index f01bae11..06083a99 100644 --- a/src/shapes/Arc.ts +++ b/src/shapes/Arc.ts @@ -1,9 +1,9 @@ -import { Util, Collection } from '../Util'; -import { Factory, Validators } from '../Factory'; -import { Node } from '../Node'; +import { Collection } from '../Util'; +import { Factory } from '../Factory'; import { Shape } from '../Shape'; import { getAngle } from '../Global'; import { GetSet } from '../types'; +import { getNumberValidator, getBooleanValidator } from '../Validators'; /** * Arc constructor @@ -64,7 +64,7 @@ Arc.prototype.className = 'Arc'; Arc.prototype._attrsAffectingSize = ['innerRadius', 'outerRadius']; // add getters setters -Factory.addGetterSetter(Arc, 'innerRadius', 0, Validators.getNumberValidator()); +Factory.addGetterSetter(Arc, 'innerRadius', 0, getNumberValidator()); /** * get/set innerRadius @@ -80,7 +80,7 @@ Factory.addGetterSetter(Arc, 'innerRadius', 0, Validators.getNumberValidator()); * arc.innerRadius(20); */ -Factory.addGetterSetter(Arc, 'outerRadius', 0, Validators.getNumberValidator()); +Factory.addGetterSetter(Arc, 'outerRadius', 0, getNumberValidator()); /** * get/set outerRadius @@ -96,7 +96,7 @@ Factory.addGetterSetter(Arc, 'outerRadius', 0, Validators.getNumberValidator()); * arc.outerRadius(20); */ -Factory.addGetterSetter(Arc, 'angle', 0, Validators.getNumberValidator()); +Factory.addGetterSetter(Arc, 'angle', 0, getNumberValidator()); /** * get/set angle in degrees @@ -112,7 +112,7 @@ Factory.addGetterSetter(Arc, 'angle', 0, Validators.getNumberValidator()); * arc.angle(20); */ -Factory.addGetterSetter(Arc, 'clockwise', false); +Factory.addGetterSetter(Arc, 'clockwise', false, getBooleanValidator()); /** * get/set clockwise flag diff --git a/src/shapes/Arrow.ts b/src/shapes/Arrow.ts index f64564f8..745aa001 100644 --- a/src/shapes/Arrow.ts +++ b/src/shapes/Arrow.ts @@ -1,7 +1,8 @@ -import { Util, Collection } from '../Util'; -import { Factory, Validators } from '../Factory'; +import { Collection } from '../Util'; +import { Factory } from '../Factory'; import { Line } from './Line'; import { GetSet } from '../types'; +import { getNumberValidator } from '../Validators'; /** * Arrow constructor @@ -122,12 +123,7 @@ Arrow.prototype.className = 'Arrow'; * line.pointerLength(15); */ -Factory.addGetterSetter( - Arrow, - 'pointerLength', - 10, - Validators.getNumberValidator() -); +Factory.addGetterSetter(Arrow, 'pointerLength', 10, getNumberValidator()); /** * get/set pointerWidth * @name Konva.Arrow#pointerWidth @@ -143,12 +139,7 @@ Factory.addGetterSetter( * line.pointerWidth(15); */ -Factory.addGetterSetter( - Arrow, - 'pointerWidth', - 10, - Validators.getNumberValidator() -); +Factory.addGetterSetter(Arrow, 'pointerWidth', 10, getNumberValidator()); /** * get/set pointerAtBeginning * @name Konva.Arrow#pointerAtBeginning diff --git a/src/shapes/Circle.ts b/src/shapes/Circle.ts index 22b62beb..f33a6a33 100644 --- a/src/shapes/Circle.ts +++ b/src/shapes/Circle.ts @@ -1,8 +1,8 @@ -import { Util, Collection } from '../Util'; -import { Factory, Validators } from '../Factory'; -import { Node } from '../Node'; +import { Collection } from '../Util'; +import { Factory } from '../Factory'; import { Shape } from '../Shape'; import { GetSet } from '../types'; +import { getNumberValidator } from '../Validators'; /** * Circle constructor @@ -66,6 +66,6 @@ Circle.prototype._attrsAffectingSize = ['radius']; * // set radius * circle.radius(10); */ -Factory.addGetterSetter(Circle, 'radius', 0, Validators.getNumberValidator()); +Factory.addGetterSetter(Circle, 'radius', 0, getNumberValidator()); Collection.mapMethods(Circle); diff --git a/src/shapes/Ellipse.ts b/src/shapes/Ellipse.ts index 6857e458..6b97bcf3 100644 --- a/src/shapes/Ellipse.ts +++ b/src/shapes/Ellipse.ts @@ -1,7 +1,7 @@ -import { Util, Collection } from '../Util'; -import { Factory, Validators } from '../Factory'; -import { Node } from '../Node'; +import { Collection } from '../Util'; +import { Factory } from '../Factory'; import { Shape } from '../Shape'; +import { getNumberValidator } from '../Validators'; import { GetSet, Vector2d } from '../types'; @@ -81,7 +81,7 @@ Factory.addComponentsGetterSetter(Ellipse, 'radius', ['x', 'y']); * }); */ -Factory.addGetterSetter(Ellipse, 'radiusX', 0, Validators.getNumberValidator()); +Factory.addGetterSetter(Ellipse, 'radiusX', 0, getNumberValidator()); /** * get/set radius x * @name Konva.Ellipse#radiusX @@ -96,7 +96,7 @@ Factory.addGetterSetter(Ellipse, 'radiusX', 0, Validators.getNumberValidator()); * ellipse.radiusX(200); */ -Factory.addGetterSetter(Ellipse, 'radiusY', 0, Validators.getNumberValidator()); +Factory.addGetterSetter(Ellipse, 'radiusY', 0, getNumberValidator()); /** * get/set radius y * @name Konva.Ellipse#radiusY diff --git a/src/shapes/Image.ts b/src/shapes/Image.ts index 24a0bb3f..b559fff6 100644 --- a/src/shapes/Image.ts +++ b/src/shapes/Image.ts @@ -1,7 +1,7 @@ import { Util, Collection } from '../Util'; -import { Factory, Validators } from '../Factory'; -import { Node } from '../Node'; +import { Factory } from '../Factory'; import { Shape } from '../Shape'; +import { getNumberValidator } from '../Validators'; import { GetSet, IRect } from '../types'; @@ -170,7 +170,7 @@ Factory.addComponentsGetterSetter(Image, 'crop', ['x', 'y', 'width', 'height']); * }); */ -Factory.addGetterSetter(Image, 'cropX', 0, Validators.getNumberValidator()); +Factory.addGetterSetter(Image, 'cropX', 0, getNumberValidator()); /** * get/set crop x * @method @@ -185,7 +185,7 @@ Factory.addGetterSetter(Image, 'cropX', 0, Validators.getNumberValidator()); * image.cropX(20); */ -Factory.addGetterSetter(Image, 'cropY', 0, Validators.getNumberValidator()); +Factory.addGetterSetter(Image, 'cropY', 0, getNumberValidator()); /** * get/set crop y * @name Konva.Image#cropY @@ -200,7 +200,7 @@ Factory.addGetterSetter(Image, 'cropY', 0, Validators.getNumberValidator()); * image.cropY(20); */ -Factory.addGetterSetter(Image, 'cropWidth', 0, Validators.getNumberValidator()); +Factory.addGetterSetter(Image, 'cropWidth', 0, getNumberValidator()); /** * get/set crop width * @name Konva.Image#cropWidth @@ -215,12 +215,7 @@ Factory.addGetterSetter(Image, 'cropWidth', 0, Validators.getNumberValidator()); * image.cropWidth(20); */ -Factory.addGetterSetter( - Image, - 'cropHeight', - 0, - Validators.getNumberValidator() -); +Factory.addGetterSetter(Image, 'cropHeight', 0, getNumberValidator()); /** * get/set crop height * @name Konva.Image#cropHeight diff --git a/src/shapes/Label.ts b/src/shapes/Label.ts index 93dc0c0d..dbb2c879 100644 --- a/src/shapes/Label.ts +++ b/src/shapes/Label.ts @@ -1,7 +1,8 @@ -import { Util, Collection } from '../Util'; -import { Factory, Validators } from '../Factory'; +import { Collection } from '../Util'; +import { Factory } from '../Factory'; import { Shape } from '../Shape'; import { Group } from '../Group'; +import { getNumberValidator } from '../Validators'; import { GetSet } from '../types'; @@ -333,12 +334,7 @@ Factory.addGetterSetter(Tag, 'pointerDirection', NONE); * @example * tag.pointerWidth(20); */ -Factory.addGetterSetter( - Tag, - 'pointerWidth', - 0, - Validators.getNumberValidator() -); +Factory.addGetterSetter(Tag, 'pointerWidth', 0, getNumberValidator()); /** * get/set pointer height @@ -350,12 +346,7 @@ Factory.addGetterSetter( * tag.pointerHeight(20); */ -Factory.addGetterSetter( - Tag, - 'pointerHeight', - 0, - Validators.getNumberValidator() -); +Factory.addGetterSetter(Tag, 'pointerHeight', 0, getNumberValidator()); /** * get/set cornerRadius @@ -367,11 +358,6 @@ Factory.addGetterSetter( * tag.cornerRadius(20); */ -Factory.addGetterSetter( - Tag, - 'cornerRadius', - 0, - Validators.getNumberValidator() -); +Factory.addGetterSetter(Tag, 'cornerRadius', 0, getNumberValidator()); Collection.mapMethods(Tag); diff --git a/src/shapes/Line.ts b/src/shapes/Line.ts index 7549b062..848196ac 100644 --- a/src/shapes/Line.ts +++ b/src/shapes/Line.ts @@ -1,6 +1,7 @@ import { Util, Collection } from '../Util'; -import { Factory, Validators } from '../Factory'; +import { Factory } from '../Factory'; import { Shape } from '../Shape'; +import { getNumberValidator, getNumberArrayValidator } from '../Validators'; import { GetSet } from '../types'; @@ -245,7 +246,7 @@ Factory.addGetterSetter(Line, 'bezier', false); * line.bezier(true); */ -Factory.addGetterSetter(Line, 'tension', 0, Validators.getNumberValidator()); +Factory.addGetterSetter(Line, 'tension', 0, getNumberValidator()); /** * get/set tension @@ -261,12 +262,7 @@ Factory.addGetterSetter(Line, 'tension', 0, Validators.getNumberValidator()); * line.tension(3); */ -Factory.addGetterSetter( - Line, - 'points', - [], - Validators.getNumberArrayValidator() -); +Factory.addGetterSetter(Line, 'points', [], getNumberArrayValidator()); /** * get/set points array. Points is a flat array [x1, y1, x2, y2]. It is flat for performance reasons. * @name Konva.Line#points diff --git a/src/shapes/Rect.ts b/src/shapes/Rect.ts index a7c071dd..7a373bf5 100644 --- a/src/shapes/Rect.ts +++ b/src/shapes/Rect.ts @@ -1,6 +1,7 @@ -import { Util, Collection } from '../Util'; -import { Factory, Validators } from '../Factory'; +import { Collection } from '../Util'; +import { Factory } from '../Factory'; import { Shape } from '../Shape'; +import { getNumberValidator } from '../Validators'; import { GetSet } from '../types'; @@ -96,11 +97,6 @@ Rect.prototype.className = 'Rect'; * // set corner radius * rect.cornerRadius(10); */ -Factory.addGetterSetter( - Rect, - 'cornerRadius', - 0, - Validators.getNumberValidator() -); +Factory.addGetterSetter(Rect, 'cornerRadius', 0, getNumberValidator()); Collection.mapMethods(Rect); diff --git a/src/shapes/RegularPolygon.ts b/src/shapes/RegularPolygon.ts index 2c43a071..8e5f7d25 100644 --- a/src/shapes/RegularPolygon.ts +++ b/src/shapes/RegularPolygon.ts @@ -1,7 +1,8 @@ import { Collection } from '../Util'; -import { Factory, Validators } from '../Factory'; +import { Factory } from '../Factory'; import { Shape } from '../Shape'; import { GetSet } from '../types'; +import { getNumberValidator } from '../Validators'; /** * RegularPolygon constructor. Examples include triangles, squares, pentagons, hexagons, etc. @@ -77,12 +78,7 @@ RegularPolygon.prototype._attrsAffectingSize = ['radius']; * // set radius * shape.radius(10); */ -Factory.addGetterSetter( - RegularPolygon, - 'radius', - 0, - Validators.getNumberValidator() -); +Factory.addGetterSetter(RegularPolygon, 'radius', 0, getNumberValidator()); /** * get/set sides @@ -97,11 +93,6 @@ Factory.addGetterSetter( * // set sides * shape.sides(10); */ -Factory.addGetterSetter( - RegularPolygon, - 'sides', - 0, - Validators.getNumberValidator() -); +Factory.addGetterSetter(RegularPolygon, 'sides', 0, getNumberValidator()); Collection.mapMethods(RegularPolygon); diff --git a/src/shapes/Ring.ts b/src/shapes/Ring.ts index 217cbfa1..ea85363b 100644 --- a/src/shapes/Ring.ts +++ b/src/shapes/Ring.ts @@ -1,7 +1,8 @@ import { Collection } from '../Util'; -import { Factory, Validators } from '../Factory'; +import { Factory } from '../Factory'; import { Shape } from '../Shape'; import { GetSet } from '../types'; +import { getNumberValidator } from '../Validators'; var PIx2 = Math.PI * 2; /** @@ -68,12 +69,7 @@ Ring.prototype._attrsAffectingSize = ['innerRadius', 'outerRadius']; * ring.innerRadius(20); */ -Factory.addGetterSetter( - Ring, - 'innerRadius', - 0, - Validators.getNumberValidator() -); +Factory.addGetterSetter(Ring, 'innerRadius', 0, getNumberValidator()); /** * get/set outerRadius @@ -88,11 +84,6 @@ Factory.addGetterSetter( * // set outer radius * ring.outerRadius(20); */ -Factory.addGetterSetter( - Ring, - 'outerRadius', - 0, - Validators.getNumberValidator() -); +Factory.addGetterSetter(Ring, 'outerRadius', 0, getNumberValidator()); Collection.mapMethods(Ring); diff --git a/src/shapes/Sprite.ts b/src/shapes/Sprite.ts index d11772be..39ad2683 100644 --- a/src/shapes/Sprite.ts +++ b/src/shapes/Sprite.ts @@ -1,7 +1,8 @@ -import { Util, Collection } from '../Util'; -import { Factory, Validators } from '../Factory'; +import { Collection } from '../Util'; +import { Factory } from '../Factory'; import { Shape } from '../Shape'; import { Animation } from '../Animation'; +import { getNumberValidator } from '../Validators'; import { GetSet } from '../types'; @@ -316,12 +317,7 @@ Factory.addGetterSetter(Sprite, 'image'); * sprite.image(imageObj); */ -Factory.addGetterSetter( - Sprite, - 'frameIndex', - 0, - Validators.getNumberValidator() -); +Factory.addGetterSetter(Sprite, 'frameIndex', 0, getNumberValidator()); /** * set/set animation frame index @@ -337,12 +333,7 @@ Factory.addGetterSetter( * sprite.frameIndex(3); */ -Factory.addGetterSetter( - Sprite, - 'frameRate', - 17, - Validators.getNumberValidator() -); +Factory.addGetterSetter(Sprite, 'frameRate', 17, getNumberValidator()); /** * get/set frame rate in frames per second. Increase this number to make the sprite diff --git a/src/shapes/Star.ts b/src/shapes/Star.ts index f17ad85b..d966bed3 100644 --- a/src/shapes/Star.ts +++ b/src/shapes/Star.ts @@ -1,7 +1,7 @@ -import { Util, Collection } from '../Util'; -import { Factory, Validators } from '../Factory'; -import { Node } from '../Node'; +import { Collection } from '../Util'; +import { Factory } from '../Factory'; import { Shape } from '../Shape'; +import { getNumberValidator } from '../Validators'; import { GetSet } from '../types'; @@ -82,7 +82,7 @@ Star.prototype._attrsAffectingSize = ['innerRadius', 'outerRadius']; * // set inner radius * ring.numPoints(20); */ -Factory.addGetterSetter(Star, 'numPoints', 5, Validators.getNumberValidator()); +Factory.addGetterSetter(Star, 'numPoints', 5, getNumberValidator()); /** * get/set innerRadius @@ -97,12 +97,7 @@ Factory.addGetterSetter(Star, 'numPoints', 5, Validators.getNumberValidator()); * // set inner radius * ring.innerRadius(20); */ -Factory.addGetterSetter( - Star, - 'innerRadius', - 0, - Validators.getNumberValidator() -); +Factory.addGetterSetter(Star, 'innerRadius', 0, getNumberValidator()); /** * get/set outerRadius @@ -118,11 +113,6 @@ Factory.addGetterSetter( * ring.outerRadius(20); */ -Factory.addGetterSetter( - Star, - 'outerRadius', - 0, - Validators.getNumberValidator() -); +Factory.addGetterSetter(Star, 'outerRadius', 0, getNumberValidator()); Collection.mapMethods(Star); diff --git a/src/shapes/Text.ts b/src/shapes/Text.ts index fc4bc9e6..8d49f9a8 100644 --- a/src/shapes/Text.ts +++ b/src/shapes/Text.ts @@ -1,7 +1,12 @@ import { Util, Collection } from '../Util'; -import { Factory, Validators } from '../Factory'; +import { Factory } from '../Factory'; import { Shape } from '../Shape'; import { UA } from '../Global'; +import { + getNumberValidator, + getStringValidator, + getNumberOrAutoValidator +} from '../Validators'; import { GetSet } from '../types'; @@ -543,7 +548,7 @@ Text.prototype._attrsAffectingSize = [ * text.width('auto'); * text.width() // will return calculated width, and not "auto" */ -Factory.overWriteSetter(Text, 'width', Validators.getNumberOrAutoValidator()); +Factory.overWriteSetter(Text, 'width', getNumberOrAutoValidator()); /** * get/set the height of the text area, which takes into account multi-line text, line heights, and padding. @@ -563,7 +568,7 @@ Factory.overWriteSetter(Text, 'width', Validators.getNumberOrAutoValidator()); * text.height() // will return calculated height, and not "auto" */ -Factory.overWriteSetter(Text, 'height', Validators.getNumberOrAutoValidator()); +Factory.overWriteSetter(Text, 'height', getNumberOrAutoValidator()); /** * get/set font family @@ -593,7 +598,7 @@ Factory.addGetterSetter(Text, 'fontFamily', 'Arial'); * // set font size to 22px * text.fontSize(22); */ -Factory.addGetterSetter(Text, 'fontSize', 12, Validators.getNumberValidator()); +Factory.addGetterSetter(Text, 'fontSize', 12, getNumberValidator()); /** * get/set font style. Can be 'normal', 'italic', or 'bold'. 'normal' is the default. @@ -641,7 +646,7 @@ Factory.addGetterSetter(Text, 'fontVariant', NORMAL); * text.padding(10); */ -Factory.addGetterSetter(Text, 'padding', 0, Validators.getNumberValidator()); +Factory.addGetterSetter(Text, 'padding', 0, getNumberValidator()); /** * get/set horizontal align of text. Can be 'left', 'center', 'right' or 'justify' @@ -692,7 +697,7 @@ Factory.addGetterSetter(Text, 'verticalAlign', TOP); * text.lineHeight(2); */ -Factory.addGetterSetter(Text, 'lineHeight', 1, Validators.getNumberValidator()); +Factory.addGetterSetter(Text, 'lineHeight', 1, getNumberValidator()); /** * get/set wrap. Can be "word", "char", or "none". Default is "word". @@ -736,12 +741,7 @@ Factory.addGetterSetter(Text, 'ellipsis', false); * @param {Number} letterSpacing */ -Factory.addGetterSetter( - Text, - 'letterSpacing', - 0, - Validators.getNumberValidator() -); +Factory.addGetterSetter(Text, 'letterSpacing', 0, getNumberValidator()); /** * get/set text @@ -757,7 +757,7 @@ Factory.addGetterSetter( * text.text('Hello world!'); */ -Factory.addGetterSetter(Text, 'text', '', Validators.getStringValidator()); +Factory.addGetterSetter(Text, 'text', '', getStringValidator()); /** * get/set text decoration of a text. Possible values are 'underline', 'line-through' or combination of these values separated by space diff --git a/src/shapes/TextPath.ts b/src/shapes/TextPath.ts index 1e13cb55..9578ae01 100644 --- a/src/shapes/TextPath.ts +++ b/src/shapes/TextPath.ts @@ -1,8 +1,9 @@ import { Util, Collection } from '../Util'; -import { Factory, Validators } from '../Factory'; +import { Factory } from '../Factory'; import { Shape } from '../Shape'; import { Path } from './Path'; import { Text } from './Text'; +import { getNumberValidator } from '../Validators'; import { GetSet, Vector2d } from '../types'; @@ -585,12 +586,7 @@ Factory.addGetterSetter(TextPath, 'fontFamily', 'Arial'); * shape.fontSize(22); */ -Factory.addGetterSetter( - TextPath, - 'fontSize', - 12, - Validators.getNumberValidator() -); +Factory.addGetterSetter(TextPath, 'fontSize', 12, getNumberValidator()); /** * get/set font style. Can be 'normal', 'italic', or 'bold'. 'normal' is the default. @@ -640,12 +636,7 @@ Factory.addGetterSetter(TextPath, 'align', 'left'); * shape.letterSpacing(2); */ -Factory.addGetterSetter( - TextPath, - 'letterSpacing', - 0, - Validators.getNumberValidator() -); +Factory.addGetterSetter(TextPath, 'letterSpacing', 0, getNumberValidator()); /** * get/set text baselineg. The default is 'middle'. Can be 'top', 'bottom', 'middle', 'alphabetic', 'hanging' diff --git a/src/shapes/Transformer.ts b/src/shapes/Transformer.ts index 8d404f55..374ca74e 100644 --- a/src/shapes/Transformer.ts +++ b/src/shapes/Transformer.ts @@ -1,10 +1,11 @@ import { Util, Collection } from '../Util'; -import { Factory, Validators } from '../Factory'; +import { Factory } from '../Factory'; import { Node } from '../Node'; import { Shape } from '../Shape'; import { Rect } from './Rect'; import { Group } from '../Group'; import { getAngle, getGlobalKonva } from '../Global'; +import { getNumberValidator } from '../Validators'; import { GetSet, IRect } from '../types'; @@ -894,12 +895,7 @@ Factory.addGetterSetter(Transformer, 'resizeEnabled', true); * // set * transformer.anchorSize(20) */ -Factory.addGetterSetter( - Transformer, - 'anchorSize', - 10, - Validators.getNumberValidator() -); +Factory.addGetterSetter(Transformer, 'anchorSize', 10, getNumberValidator()); /** * get/set ability to rotate. @@ -948,7 +944,7 @@ Factory.addGetterSetter( Transformer, 'rotateAnchorOffset', 50, - Validators.getNumberValidator() + getNumberValidator() ); /** @@ -998,7 +994,7 @@ Factory.addGetterSetter( Transformer, 'anchorStrokeWidth', 1, - Validators.getNumberValidator() + getNumberValidator() ); /** @@ -1033,7 +1029,7 @@ Factory.addGetterSetter( Transformer, 'anchorCornerRadius', 0, - Validators.getNumberValidator() + getNumberValidator() ); /** @@ -1068,7 +1064,7 @@ Factory.addGetterSetter( Transformer, 'borderStrokeWidth', 1, - Validators.getNumberValidator() + getNumberValidator() ); /** @@ -1145,12 +1141,7 @@ Factory.addGetterSetter(Transformer, 'ignoreStroke', false); * // set * transformer.padding(10); */ -Factory.addGetterSetter( - Transformer, - 'padding', - 0, - Validators.getNumberValidator() -); +Factory.addGetterSetter(Transformer, 'padding', 0, getNumberValidator()); /** * get/set attached node of the Transformer. Transformer will adapt to its size and listen to its events diff --git a/src/shapes/Wedge.ts b/src/shapes/Wedge.ts index 06408b71..96a6df30 100644 --- a/src/shapes/Wedge.ts +++ b/src/shapes/Wedge.ts @@ -1,8 +1,8 @@ -import { Util, Collection } from '../Util'; -import { Factory, Validators } from '../Factory'; -import { Node } from '../Node'; +import { Collection } from '../Util'; +import { Factory } from '../Factory'; import { Shape } from '../Shape'; import { getAngle } from '../Global'; +import { getNumberValidator } from '../Validators'; import { GetSet } from '../types'; @@ -78,7 +78,7 @@ Wedge.prototype._attrsAffectingSize = ['radius']; * // set radius * wedge.radius(10); */ -Factory.addGetterSetter(Wedge, 'radius', 0, Validators.getNumberValidator()); +Factory.addGetterSetter(Wedge, 'radius', 0, getNumberValidator()); /** * get/set angle in degrees @@ -93,7 +93,7 @@ Factory.addGetterSetter(Wedge, 'radius', 0, Validators.getNumberValidator()); * // set angle * wedge.angle(20); */ -Factory.addGetterSetter(Wedge, 'angle', 0, Validators.getNumberValidator()); +Factory.addGetterSetter(Wedge, 'angle', 0, getNumberValidator()); /** * get/set clockwise flag