fix fail on empty config

This commit is contained in:
Anton Lavrenov 2018-02-22 09:17:08 +08:00
parent 9a46ca6176
commit 739be29ea0
3 changed files with 307 additions and 307 deletions

306
konva.js
View File

@ -2,7 +2,7 @@
* Konva JavaScript Framework v1.7.6 * Konva JavaScript Framework v1.7.6
* http://konvajs.github.io/ * http://konvajs.github.io/
* Licensed under the MIT * Licensed under the MIT
* Date: Sun Feb 18 2018 * Date: Thu Feb 22 2018
* *
* Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS) * Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS)
* Modified work Copyright (C) 2014 - present by Anton Lavrenov (Konva) * Modified work Copyright (C) 2014 - present by Anton Lavrenov (Konva)
@ -16586,20 +16586,20 @@
NORMAL = 'normal'; NORMAL = 'normal';
/** /**
* Path constructor. * Path constructor.
* @author Jason Follas * @author Jason Follas
* @constructor * @constructor
* @memberof Konva * @memberof Konva
* @augments Konva.Shape * @augments Konva.Shape
* @param {Object} config * @param {Object} config
* @param {String} [config.fontFamily] default is Calibri * @param {String} [config.fontFamily] default is Calibri
* @param {Number} [config.fontSize] default is 12 * @param {Number} [config.fontSize] default is 12
* @param {String} [config.fontStyle] can be normal, bold, or italic. Default is normal * @param {String} [config.fontStyle] can be normal, bold, or italic. Default is normal
* @param {String} [config.fontVariant] can be normal or small-caps. Default is normal * @param {String} [config.fontVariant] can be normal or small-caps. Default is normal
* @param {String} config.text * @param {String} config.text
* @param {String} config.data SVG data string * @param {String} config.data SVG data string
* @param {Function} config.getKerning a getter for kerning values for the specified characters * @param {Function} config.getKerning a getter for kerning values for the specified characters
* @param {String} [config.fill] fill color * @param {String} [config.fill] fill color
* @param {Image} [config.fillPatternImage] fill pattern image * @param {Image} [config.fillPatternImage] fill pattern image
* @param {Number} [config.fillPatternX] * @param {Number} [config.fillPatternX]
* @param {Number} [config.fillPatternY] * @param {Number} [config.fillPatternY]
@ -16650,7 +16650,7 @@
* @param {Boolean} [config.shadowEnabled] flag which enables or disables the shadow. The default value is true * @param {Boolean} [config.shadowEnabled] flag which enables or disables the shadow. The default value is true
* @param {Array} [config.dash] * @param {Array} [config.dash]
* @param {Boolean} [config.dashEnabled] flag which enables or disables the dashArray. The default value is true * @param {Boolean} [config.dashEnabled] flag which enables or disables the dashArray. The default value is true
* @param {Number} [config.x] * @param {Number} [config.x]
* @param {Number} [config.y] * @param {Number} [config.y]
* @param {Number} [config.width] * @param {Number} [config.width]
* @param {Number} [config.height] * @param {Number} [config.height]
@ -16670,33 +16670,33 @@
* the entire stage by dragging any portion of the stage * the entire stage by dragging any portion of the stage
* @param {Number} [config.dragDistance] * @param {Number} [config.dragDistance]
* @param {Function} [config.dragBoundFunc] * @param {Function} [config.dragBoundFunc]
* @example * @example
* var kerningPairs = { * var kerningPairs = {
* 'A': { * 'A': {
* ' ': -0.05517578125, * ' ': -0.05517578125,
* 'T': -0.07421875, * 'T': -0.07421875,
* 'V': -0.07421875, * 'V': -0.07421875,
* }, * },
* 'V': { * 'V': {
* ',': -0.091796875, * ',': -0.091796875,
* ":": -0.037109375, * ":": -0.037109375,
* ";": -0.037109375, * ";": -0.037109375,
* "A": -0.07421875, * "A": -0.07421875,
* } * }
* } * }
* var textpath = new Konva.TextPath({ * var textpath = new Konva.TextPath({
* x: 100, * x: 100,
* y: 50, * y: 50,
* fill: '#333', * fill: '#333',
* fontSize: '24', * fontSize: '24',
* fontFamily: 'Arial', * fontFamily: 'Arial',
* text: 'All the world\'s a stage, and all the men and women merely players.', * text: 'All the world\'s a stage, and all the men and women merely players.',
* data: 'M10,10 C0,0 10,150 100,100 S300,150 400,50', * data: 'M10,10 C0,0 10,150 100,100 S300,150 400,50',
* getKerning: function(leftChar, rightChar) { * getKerning: function(leftChar, rightChar) {
* return kerningPairs.hasOwnProperty(leftChar) ? pairs[leftChar][rightChar] || 0 : 0 * return kerningPairs.hasOwnProperty(leftChar) ? pairs[leftChar][rightChar] || 0 : 0
* } * }
* }); * });
*/ */
Konva.TextPath = function(config) { Konva.TextPath = function(config) {
this.___init(config); this.___init(config);
}; };
@ -16713,7 +16713,7 @@
var that = this; var that = this;
this.dummyCanvas = Konva.Util.createCanvasElement(); this.dummyCanvas = Konva.Util.createCanvasElement();
this.dataArray = []; this.dataArray = [];
this.getKerning = config.getKerning; this.getKerning = config && config.getKerning;
// call super constructor // call super constructor
Konva.Shape.call(this, config); Konva.Shape.call(this, config);
@ -16811,27 +16811,27 @@
context.stroke(); context.stroke();
}, },
/** /**
* get text width in pixels * get text width in pixels
* @method * @method
* @memberof Konva.TextPath.prototype * @memberof Konva.TextPath.prototype
*/ */
getTextWidth: function() { getTextWidth: function() {
return this.textWidth; return this.textWidth;
}, },
/** /**
* get text height in pixels * get text height in pixels
* @method * @method
* @memberof Konva.TextPath.prototype * @memberof Konva.TextPath.prototype
*/ */
getTextHeight: function() { getTextHeight: function() {
return this.textHeight; return this.textHeight;
}, },
/** /**
* set text * set text
* @method * @method
* @memberof Konva.TextPath.prototype * @memberof Konva.TextPath.prototype
* @param {String} text * @param {String} text
*/ */
setText: function(text) { setText: function(text) {
Konva.Text.prototype.setText.call(this, text); Konva.Text.prototype.setText.call(this, text);
}, },
@ -17100,11 +17100,11 @@
var kern = 0; var kern = 0;
if (this.getKerning) { if (this.getKerning) {
try { try {
// getKerning is a user provided getter. Make sure it never breaks our logic // getKerning is a user provided getter. Make sure it never breaks our logic
kern = this.getKerning(charArr[i - 1], charArr[i]) * this.fontSize(); kern =
} this.getKerning(charArr[i - 1], charArr[i]) * this.fontSize();
catch(e) { } catch (e) {
kern = 0; kern = 0;
} }
} }
@ -17174,136 +17174,136 @@
Konva.Factory.addGetterSetter(Konva.TextPath, 'fontFamily', 'Arial'); Konva.Factory.addGetterSetter(Konva.TextPath, 'fontFamily', 'Arial');
/** /**
* set font family * set font family
* @name setFontFamily * @name setFontFamily
* @method * @method
* @memberof Konva.TextPath.prototype * @memberof Konva.TextPath.prototype
* @param {String} fontFamily * @param {String} fontFamily
*/ */
/** /**
* get font family * get font family
* @name getFontFamily * @name getFontFamily
* @method * @method
* @memberof Konva.TextPath.prototype * @memberof Konva.TextPath.prototype
*/ */
Konva.Factory.addGetterSetter(Konva.TextPath, 'fontSize', 12); Konva.Factory.addGetterSetter(Konva.TextPath, 'fontSize', 12);
/** /**
* set font size * set font size
* @name setFontSize * @name setFontSize
* @method * @method
* @memberof Konva.TextPath.prototype * @memberof Konva.TextPath.prototype
* @param {int} fontSize * @param {int} fontSize
*/ */
/** /**
* get font size * get font size
* @name getFontSize * @name getFontSize
* @method * @method
* @memberof Konva.TextPath.prototype * @memberof Konva.TextPath.prototype
*/ */
Konva.Factory.addGetterSetter(Konva.TextPath, 'fontStyle', NORMAL); Konva.Factory.addGetterSetter(Konva.TextPath, 'fontStyle', NORMAL);
/** /**
* set font style. Can be 'normal', 'italic', or 'bold'. 'normal' is the default. * set font style. Can be 'normal', 'italic', or 'bold'. 'normal' is the default.
* @name setFontStyle * @name setFontStyle
* @method * @method
* @memberof Konva.TextPath.prototype * @memberof Konva.TextPath.prototype
* @param {String} fontStyle * @param {String} fontStyle
*/ */
Konva.Factory.addGetterSetter(Konva.TextPath, 'align', 'left'); Konva.Factory.addGetterSetter(Konva.TextPath, 'align', 'left');
/** /**
* get/set horizontal align of text. Can be 'left', 'center', 'right' or 'justify' * get/set horizontal align of text. Can be 'left', 'center', 'right' or 'justify'
* @name align * @name align
* @method * @method
* @memberof Konva.Text.prototype * @memberof Konva.Text.prototype
* @param {String} align * @param {String} align
* @returns {String} * @returns {String}
* @example * @example
* // get text align * // get text align
* var align = text.align(); * var align = text.align();
* *
* // center text * // center text
* text.align('center'); * text.align('center');
* *
* // align text to right * // align text to right
* text.align('right'); * text.align('right');
*/ */
Konva.Factory.addGetterSetter(Konva.TextPath, 'letterSpacing', 0); Konva.Factory.addGetterSetter(Konva.TextPath, 'letterSpacing', 0);
/** /**
* set letter spacing property. Default value is 0. * set letter spacing property. Default value is 0.
* @name letterSpacing * @name letterSpacing
* @method * @method
* @memberof Konva.TextPath.prototype * @memberof Konva.TextPath.prototype
* @param {Number} letterSpacing * @param {Number} letterSpacing
*/ */
Konva.Factory.addGetterSetter(Konva.TextPath, 'textBaseline', 'middle'); Konva.Factory.addGetterSetter(Konva.TextPath, 'textBaseline', 'middle');
/** /**
* set textBaseline property. Default value is 'middle'. * set textBaseline property. Default value is 'middle'.
* Can be 'top', 'bottom', 'middle', 'alphabetic', 'hanging' * Can be 'top', 'bottom', 'middle', 'alphabetic', 'hanging'
* @name textBaseline * @name textBaseline
* @method * @method
* @memberof Konva.TextPath.prototype * @memberof Konva.TextPath.prototype
* @param {Number} textBaseline * @param {Number} textBaseline
*/ */
/** /**
* get font style * get font style
* @name getFontStyle * @name getFontStyle
* @method * @method
* @memberof Konva.TextPath.prototype * @memberof Konva.TextPath.prototype
*/ */
Konva.Factory.addGetterSetter(Konva.TextPath, 'fontVariant', NORMAL); Konva.Factory.addGetterSetter(Konva.TextPath, 'fontVariant', NORMAL);
/** /**
* set font variant. Can be 'normal' or 'small-caps'. 'normal' is the default. * set font variant. Can be 'normal' or 'small-caps'. 'normal' is the default.
* @name setFontVariant * @name setFontVariant
* @method * @method
* @memberof Konva.TextPath.prototype * @memberof Konva.TextPath.prototype
* @param {String} fontVariant * @param {String} fontVariant
*/ */
/** /**
* @get font variant * @get font variant
* @name getFontVariant * @name getFontVariant
* @method * @method
* @memberof Konva.TextPath.prototype * @memberof Konva.TextPath.prototype
*/ */
Konva.Factory.addGetter(Konva.TextPath, 'text', EMPTY_STRING); Konva.Factory.addGetter(Konva.TextPath, 'text', EMPTY_STRING);
/** /**
* get text * get text
* @name getText * @name getText
* @method * @method
* @memberof Konva.TextPath.prototype * @memberof Konva.TextPath.prototype
*/ */
Konva.Factory.addGetterSetter(Konva.TextPath, 'textDecoration', null); Konva.Factory.addGetterSetter(Konva.TextPath, 'textDecoration', null);
/** /**
* get/set text decoration of a text. Can be '' or 'underline' * get/set text decoration of a text. Can be '' or 'underline'
* @name textDecoration * @name textDecoration
* @method * @method
* @memberof Konva.Text.prototype * @memberof Konva.Text.prototype
* @param {String} textDecoration * @param {String} textDecoration
* @returns {String} * @returns {String}
* @example * @example
* // get text decoration * // get text decoration
* var textDecoration = text.textDecoration(); * var textDecoration = text.textDecoration();
* *
* // center text * // center text
* text.textDecoration('underline'); * text.textDecoration('underline');
*/ */
Konva.Collection.mapMethods(Konva.TextPath); Konva.Collection.mapMethods(Konva.TextPath);
})(); })();

4
konva.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -5,48 +5,48 @@
NORMAL = 'normal'; NORMAL = 'normal';
/** /**
* Path constructor. * Path constructor.
* @author Jason Follas * @author Jason Follas
* @constructor * @constructor
* @memberof Konva * @memberof Konva
* @augments Konva.Shape * @augments Konva.Shape
* @param {Object} config * @param {Object} config
* @param {String} [config.fontFamily] default is Calibri * @param {String} [config.fontFamily] default is Calibri
* @param {Number} [config.fontSize] default is 12 * @param {Number} [config.fontSize] default is 12
* @param {String} [config.fontStyle] can be normal, bold, or italic. Default is normal * @param {String} [config.fontStyle] can be normal, bold, or italic. Default is normal
* @param {String} [config.fontVariant] can be normal or small-caps. Default is normal * @param {String} [config.fontVariant] can be normal or small-caps. Default is normal
* @param {String} config.text * @param {String} config.text
* @param {String} config.data SVG data string * @param {String} config.data SVG data string
* @param {Function} config.getKerning a getter for kerning values for the specified characters * @param {Function} config.getKerning a getter for kerning values for the specified characters
* @@shapeParams * @@shapeParams
* @@nodeParams * @@nodeParams
* @example * @example
* var kerningPairs = { * var kerningPairs = {
* 'A': { * 'A': {
* ' ': -0.05517578125, * ' ': -0.05517578125,
* 'T': -0.07421875, * 'T': -0.07421875,
* 'V': -0.07421875, * 'V': -0.07421875,
* }, * },
* 'V': { * 'V': {
* ',': -0.091796875, * ',': -0.091796875,
* ":": -0.037109375, * ":": -0.037109375,
* ";": -0.037109375, * ";": -0.037109375,
* "A": -0.07421875, * "A": -0.07421875,
* } * }
* } * }
* var textpath = new Konva.TextPath({ * var textpath = new Konva.TextPath({
* x: 100, * x: 100,
* y: 50, * y: 50,
* fill: '#333', * fill: '#333',
* fontSize: '24', * fontSize: '24',
* fontFamily: 'Arial', * fontFamily: 'Arial',
* text: 'All the world\'s a stage, and all the men and women merely players.', * text: 'All the world\'s a stage, and all the men and women merely players.',
* data: 'M10,10 C0,0 10,150 100,100 S300,150 400,50', * data: 'M10,10 C0,0 10,150 100,100 S300,150 400,50',
* getKerning: function(leftChar, rightChar) { * getKerning: function(leftChar, rightChar) {
* return kerningPairs.hasOwnProperty(leftChar) ? pairs[leftChar][rightChar] || 0 : 0 * return kerningPairs.hasOwnProperty(leftChar) ? pairs[leftChar][rightChar] || 0 : 0
* } * }
* }); * });
*/ */
Konva.TextPath = function(config) { Konva.TextPath = function(config) {
this.___init(config); this.___init(config);
}; };
@ -63,7 +63,7 @@
var that = this; var that = this;
this.dummyCanvas = Konva.Util.createCanvasElement(); this.dummyCanvas = Konva.Util.createCanvasElement();
this.dataArray = []; this.dataArray = [];
this.getKerning = config.getKerning; this.getKerning = config && config.getKerning;
// call super constructor // call super constructor
Konva.Shape.call(this, config); Konva.Shape.call(this, config);
@ -161,27 +161,27 @@
context.stroke(); context.stroke();
}, },
/** /**
* get text width in pixels * get text width in pixels
* @method * @method
* @memberof Konva.TextPath.prototype * @memberof Konva.TextPath.prototype
*/ */
getTextWidth: function() { getTextWidth: function() {
return this.textWidth; return this.textWidth;
}, },
/** /**
* get text height in pixels * get text height in pixels
* @method * @method
* @memberof Konva.TextPath.prototype * @memberof Konva.TextPath.prototype
*/ */
getTextHeight: function() { getTextHeight: function() {
return this.textHeight; return this.textHeight;
}, },
/** /**
* set text * set text
* @method * @method
* @memberof Konva.TextPath.prototype * @memberof Konva.TextPath.prototype
* @param {String} text * @param {String} text
*/ */
setText: function(text) { setText: function(text) {
Konva.Text.prototype.setText.call(this, text); Konva.Text.prototype.setText.call(this, text);
}, },
@ -450,11 +450,11 @@
var kern = 0; var kern = 0;
if (this.getKerning) { if (this.getKerning) {
try { try {
// getKerning is a user provided getter. Make sure it never breaks our logic // getKerning is a user provided getter. Make sure it never breaks our logic
kern = this.getKerning(charArr[i - 1], charArr[i]) * this.fontSize(); kern =
} this.getKerning(charArr[i - 1], charArr[i]) * this.fontSize();
catch(e) { } catch (e) {
kern = 0; kern = 0;
} }
} }
@ -524,136 +524,136 @@
Konva.Factory.addGetterSetter(Konva.TextPath, 'fontFamily', 'Arial'); Konva.Factory.addGetterSetter(Konva.TextPath, 'fontFamily', 'Arial');
/** /**
* set font family * set font family
* @name setFontFamily * @name setFontFamily
* @method * @method
* @memberof Konva.TextPath.prototype * @memberof Konva.TextPath.prototype
* @param {String} fontFamily * @param {String} fontFamily
*/ */
/** /**
* get font family * get font family
* @name getFontFamily * @name getFontFamily
* @method * @method
* @memberof Konva.TextPath.prototype * @memberof Konva.TextPath.prototype
*/ */
Konva.Factory.addGetterSetter(Konva.TextPath, 'fontSize', 12); Konva.Factory.addGetterSetter(Konva.TextPath, 'fontSize', 12);
/** /**
* set font size * set font size
* @name setFontSize * @name setFontSize
* @method * @method
* @memberof Konva.TextPath.prototype * @memberof Konva.TextPath.prototype
* @param {int} fontSize * @param {int} fontSize
*/ */
/** /**
* get font size * get font size
* @name getFontSize * @name getFontSize
* @method * @method
* @memberof Konva.TextPath.prototype * @memberof Konva.TextPath.prototype
*/ */
Konva.Factory.addGetterSetter(Konva.TextPath, 'fontStyle', NORMAL); Konva.Factory.addGetterSetter(Konva.TextPath, 'fontStyle', NORMAL);
/** /**
* set font style. Can be 'normal', 'italic', or 'bold'. 'normal' is the default. * set font style. Can be 'normal', 'italic', or 'bold'. 'normal' is the default.
* @name setFontStyle * @name setFontStyle
* @method * @method
* @memberof Konva.TextPath.prototype * @memberof Konva.TextPath.prototype
* @param {String} fontStyle * @param {String} fontStyle
*/ */
Konva.Factory.addGetterSetter(Konva.TextPath, 'align', 'left'); Konva.Factory.addGetterSetter(Konva.TextPath, 'align', 'left');
/** /**
* get/set horizontal align of text. Can be 'left', 'center', 'right' or 'justify' * get/set horizontal align of text. Can be 'left', 'center', 'right' or 'justify'
* @name align * @name align
* @method * @method
* @memberof Konva.Text.prototype * @memberof Konva.Text.prototype
* @param {String} align * @param {String} align
* @returns {String} * @returns {String}
* @example * @example
* // get text align * // get text align
* var align = text.align(); * var align = text.align();
* *
* // center text * // center text
* text.align('center'); * text.align('center');
* *
* // align text to right * // align text to right
* text.align('right'); * text.align('right');
*/ */
Konva.Factory.addGetterSetter(Konva.TextPath, 'letterSpacing', 0); Konva.Factory.addGetterSetter(Konva.TextPath, 'letterSpacing', 0);
/** /**
* set letter spacing property. Default value is 0. * set letter spacing property. Default value is 0.
* @name letterSpacing * @name letterSpacing
* @method * @method
* @memberof Konva.TextPath.prototype * @memberof Konva.TextPath.prototype
* @param {Number} letterSpacing * @param {Number} letterSpacing
*/ */
Konva.Factory.addGetterSetter(Konva.TextPath, 'textBaseline', 'middle'); Konva.Factory.addGetterSetter(Konva.TextPath, 'textBaseline', 'middle');
/** /**
* set textBaseline property. Default value is 'middle'. * set textBaseline property. Default value is 'middle'.
* Can be 'top', 'bottom', 'middle', 'alphabetic', 'hanging' * Can be 'top', 'bottom', 'middle', 'alphabetic', 'hanging'
* @name textBaseline * @name textBaseline
* @method * @method
* @memberof Konva.TextPath.prototype * @memberof Konva.TextPath.prototype
* @param {Number} textBaseline * @param {Number} textBaseline
*/ */
/** /**
* get font style * get font style
* @name getFontStyle * @name getFontStyle
* @method * @method
* @memberof Konva.TextPath.prototype * @memberof Konva.TextPath.prototype
*/ */
Konva.Factory.addGetterSetter(Konva.TextPath, 'fontVariant', NORMAL); Konva.Factory.addGetterSetter(Konva.TextPath, 'fontVariant', NORMAL);
/** /**
* set font variant. Can be 'normal' or 'small-caps'. 'normal' is the default. * set font variant. Can be 'normal' or 'small-caps'. 'normal' is the default.
* @name setFontVariant * @name setFontVariant
* @method * @method
* @memberof Konva.TextPath.prototype * @memberof Konva.TextPath.prototype
* @param {String} fontVariant * @param {String} fontVariant
*/ */
/** /**
* @get font variant * @get font variant
* @name getFontVariant * @name getFontVariant
* @method * @method
* @memberof Konva.TextPath.prototype * @memberof Konva.TextPath.prototype
*/ */
Konva.Factory.addGetter(Konva.TextPath, 'text', EMPTY_STRING); Konva.Factory.addGetter(Konva.TextPath, 'text', EMPTY_STRING);
/** /**
* get text * get text
* @name getText * @name getText
* @method * @method
* @memberof Konva.TextPath.prototype * @memberof Konva.TextPath.prototype
*/ */
Konva.Factory.addGetterSetter(Konva.TextPath, 'textDecoration', null); Konva.Factory.addGetterSetter(Konva.TextPath, 'textDecoration', null);
/** /**
* get/set text decoration of a text. Can be '' or 'underline' * get/set text decoration of a text. Can be '' or 'underline'
* @name textDecoration * @name textDecoration
* @method * @method
* @memberof Konva.Text.prototype * @memberof Konva.Text.prototype
* @param {String} textDecoration * @param {String} textDecoration
* @returns {String} * @returns {String}
* @example * @example
* // get text decoration * // get text decoration
* var textDecoration = text.textDecoration(); * var textDecoration = text.textDecoration();
* *
* // center text * // center text
* text.textDecoration('underline'); * text.textDecoration('underline');
*/ */
Konva.Collection.mapMethods(Konva.TextPath); Konva.Collection.mapMethods(Konva.TextPath);
})(); })();