konva 8.3.9 → 8.3.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -58,6 +58,7 @@ exports.DD = {
58
58
  });
59
59
  },
60
60
  _endDragBefore(evt) {
61
+ const drawNodes = [];
61
62
  exports.DD._dragElements.forEach((elem) => {
62
63
  const { node } = elem;
63
64
  const stage = node.getStage();
@@ -77,10 +78,13 @@ exports.DD = {
77
78
  }
78
79
  const drawNode = elem.node.getLayer() ||
79
80
  (elem.node instanceof Global_1.Konva['Stage'] && elem.node);
80
- if (drawNode) {
81
- drawNode.batchDraw();
81
+ if (drawNode && drawNodes.indexOf(drawNode) === -1) {
82
+ drawNodes.push(drawNode);
82
83
  }
83
84
  });
85
+ drawNodes.forEach((drawNode) => {
86
+ drawNode.draw();
87
+ });
84
88
  },
85
89
  _endDragAfter(evt) {
86
90
  exports.DD._dragElements.forEach((elem, key) => {
package/cmj/Factory.d.ts CHANGED
@@ -3,7 +3,7 @@ export declare const Factory: {
3
3
  addGetter(constructor: any, attr: any, def?: any): void;
4
4
  addSetter(constructor: any, attr: any, validator?: any, after?: any): void;
5
5
  overWriteSetter(constructor: any, attr: any, validator?: any, after?: any): void;
6
- addComponentsGetterSetter(constructor: any, attr: any, components: any, validator?: any, after?: any): void;
6
+ addComponentsGetterSetter(constructor: any, attr: string, components: Array<string>, validator?: Function, after?: Function): void;
7
7
  addOverloadedGetterSetter(constructor: any, attr: any): void;
8
8
  addDeprecatedGetterSetter(constructor: any, attr: any, def: any, validator: any): void;
9
9
  backCompat(constructor: any, methods: any): void;
package/cmj/Factory.js CHANGED
@@ -63,6 +63,11 @@ exports.Factory = {
63
63
  }
64
64
  this._setAttr(attr + capitalize(key), val[key]);
65
65
  }
66
+ if (!val) {
67
+ components.forEach((component) => {
68
+ this._setAttr(attr + capitalize(component), undefined);
69
+ });
70
+ }
66
71
  this._fireChangeEvent(attr, oldVal, val);
67
72
  if (after) {
68
73
  after.call(this);
package/cmj/Global.js CHANGED
@@ -16,7 +16,7 @@ exports.glob = typeof global !== 'undefined'
16
16
  : {};
17
17
  exports.Konva = {
18
18
  _global: exports.glob,
19
- version: '8.3.9',
19
+ version: '8.3.12',
20
20
  isBrowser: detectBrowser(),
21
21
  isUnminified: /param/.test(function (param) { }.toString()),
22
22
  dblClickWindow: 400,
package/cmj/Node.d.ts CHANGED
@@ -179,7 +179,7 @@ export declare abstract class Node<Config extends NodeConfig = NodeConfig> {
179
179
  getParent(): Container<Node<NodeConfig>>;
180
180
  findAncestors(selector: string, includeSelf?: boolean, stopNode?: Node): Node<NodeConfig>[];
181
181
  isAncestorOf(node: Node): boolean;
182
- findAncestor(selector?: string, includeSelf?: boolean, stopNode?: Container): any;
182
+ findAncestor(selector?: string, includeSelf?: boolean, stopNode?: Container): Node<NodeConfig>;
183
183
  _isMatch(selector: string | Function): any;
184
184
  getLayer(): Layer | null;
185
185
  getStage(): Stage | null;
@@ -216,7 +216,17 @@ export declare abstract class Node<Config extends NodeConfig = NodeConfig> {
216
216
  mimeType?: string;
217
217
  quality?: number;
218
218
  callback?: (img: HTMLImageElement) => void;
219
- }): void;
219
+ }): Promise<unknown>;
220
+ toBlob(config?: {
221
+ x?: number;
222
+ y?: number;
223
+ width?: number;
224
+ height?: number;
225
+ pixelRatio?: number;
226
+ mimeType?: string;
227
+ quality?: number;
228
+ callback?: (blob: Blob) => void;
229
+ }): Promise<unknown>;
220
230
  setSize(size: any): this;
221
231
  getSize(): {
222
232
  width: number;
@@ -293,7 +303,7 @@ export declare abstract class Node<Config extends NodeConfig = NodeConfig> {
293
303
  opacity: GetSet<number, this>;
294
304
  rotation: GetSet<number, this>;
295
305
  zIndex: GetSet<number, this>;
296
- scale: GetSet<Vector2d, this>;
306
+ scale: GetSet<Vector2d | undefined, this>;
297
307
  scaleX: GetSet<number, this>;
298
308
  scaleY: GetSet<number, this>;
299
309
  skew: GetSet<Vector2d, this>;
package/cmj/Node.js CHANGED
@@ -967,13 +967,35 @@ class Node {
967
967
  return url;
968
968
  }
969
969
  toImage(config) {
970
- if (!config || !config.callback) {
971
- throw 'callback required for toImage method config argument';
972
- }
973
- var callback = config.callback;
974
- delete config.callback;
975
- Util_1.Util._urlToImage(this.toDataURL(config), function (img) {
976
- callback(img);
970
+ return new Promise((resolve, reject) => {
971
+ try {
972
+ const callback = config === null || config === void 0 ? void 0 : config.callback;
973
+ if (callback)
974
+ delete config.callback;
975
+ Util_1.Util._urlToImage(this.toDataURL(config), function (img) {
976
+ resolve(img);
977
+ callback === null || callback === void 0 ? void 0 : callback(img);
978
+ });
979
+ }
980
+ catch (err) {
981
+ reject(err);
982
+ }
983
+ });
984
+ }
985
+ toBlob(config) {
986
+ return new Promise((resolve, reject) => {
987
+ try {
988
+ const callback = config === null || config === void 0 ? void 0 : config.callback;
989
+ if (callback)
990
+ delete config.callback;
991
+ this.toCanvas(config).toBlob((blob) => {
992
+ resolve(blob);
993
+ callback === null || callback === void 0 ? void 0 : callback(blob);
994
+ });
995
+ }
996
+ catch (err) {
997
+ reject(err);
998
+ }
977
999
  });
978
1000
  }
979
1001
  setSize(size) {
package/cmj/Stage.js CHANGED
@@ -546,7 +546,7 @@ class Stage extends Container_1.Container {
546
546
  });
547
547
  }
548
548
  Global_1.Konva['_' + eventType + 'ListenClick'] = false;
549
- if (evt.cancelable) {
549
+ if (evt.cancelable && eventType !== 'touch') {
550
550
  evt.preventDefault();
551
551
  }
552
552
  }
package/cmj/Validators.js CHANGED
@@ -131,6 +131,10 @@ exports.getFunctionValidator = getFunctionValidator;
131
131
  function getNumberArrayValidator() {
132
132
  if (Global_1.Konva.isUnminified) {
133
133
  return function (val, attr) {
134
+ const TypedArray = Int8Array ? Object.getPrototypeOf(Int8Array) : null;
135
+ if (TypedArray && val instanceof TypedArray) {
136
+ return val;
137
+ }
134
138
  if (!Util_1.Util._isArray(val)) {
135
139
  Util_1.Util.warn(_formatValue(val) +
136
140
  ' is a not valid value for "' +
@@ -171,6 +175,9 @@ exports.getBooleanValidator = getBooleanValidator;
171
175
  function getComponentValidator(components) {
172
176
  if (Global_1.Konva.isUnminified) {
173
177
  return function (val, attr) {
178
+ if (val === undefined || val === null) {
179
+ return val;
180
+ }
174
181
  if (!Util_1.Util.isObject(val)) {
175
182
  Util_1.Util.warn(_formatValue(val) +
176
183
  ' is a not valid value for "' +
@@ -15,6 +15,9 @@ var ATTR_CHANGE_LIST = [
15
15
  'text',
16
16
  'width',
17
17
  'height',
18
+ 'pointerDirection',
19
+ 'pointerWidth',
20
+ 'pointerHeight',
18
21
  ], CHANGE_KONVA = 'Change.konva', NONE = 'none', UP = 'up', RIGHT = 'right', DOWN = 'down', LEFT = 'left', attrChangeListLen = ATTR_CHANGE_LIST.length;
19
22
  class Label extends Group_1.Group {
20
23
  constructor(config) {
@@ -97,7 +100,11 @@ class Tag extends Shape_1.Shape {
97
100
  let bottomLeft = 0;
98
101
  let bottomRight = 0;
99
102
  if (typeof cornerRadius === 'number') {
100
- topLeft = topRight = bottomLeft = bottomRight = Math.min(cornerRadius, width / 2, height / 2);
103
+ topLeft =
104
+ topRight =
105
+ bottomLeft =
106
+ bottomRight =
107
+ Math.min(cornerRadius, width / 2, height / 2);
101
108
  }
102
109
  else {
103
110
  topLeft = Math.min(cornerRadius[0] || 0, width / 2, height / 2);
@@ -2,7 +2,7 @@ import { Shape, ShapeConfig } from '../Shape';
2
2
  import { GetSet } from '../types';
3
3
  import { Context } from '../Context';
4
4
  export interface LineConfig extends ShapeConfig {
5
- points?: number[];
5
+ points?: number[] | Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array;
6
6
  tension?: number;
7
7
  closed?: boolean;
8
8
  bezier?: boolean;
@@ -43,6 +43,8 @@ export declare class Text extends Shape<TextConfig> {
43
43
  _addTextLine(line: any): number;
44
44
  _getTextWidth(text: any): any;
45
45
  _setTextData(): void;
46
+ _shouldHandleEllipsis(currentHeightPx: number): boolean;
47
+ _tryToAddEllipsisToLastLine(): void;
46
48
  getStrokeScaleEnabled(): boolean;
47
49
  fontFamily: GetSet<string, this>;
48
50
  fontSize: GetSet<number, this>;
@@ -278,19 +278,9 @@ class Text extends Shape_1.Shape {
278
278
  this._addTextLine(match);
279
279
  textWidth = Math.max(textWidth, matchWidth);
280
280
  currentHeightPx += lineHeightPx;
281
- if (!shouldWrap ||
282
- (fixedHeight && currentHeightPx + lineHeightPx > maxHeightPx)) {
283
- var lastLine = this.textArr[this.textArr.length - 1];
284
- if (lastLine) {
285
- if (shouldAddEllipsis) {
286
- var haveSpace = this._getTextWidth(lastLine.text + ELLIPSIS) < maxWidth;
287
- if (!haveSpace) {
288
- lastLine.text = lastLine.text.slice(0, lastLine.text.length - 3);
289
- }
290
- this.textArr.splice(this.textArr.length - 1, 1);
291
- this._addTextLine(lastLine.text + ELLIPSIS);
292
- }
293
- }
281
+ var shouldHandleEllipsis = this._shouldHandleEllipsis(currentHeightPx);
282
+ if (shouldHandleEllipsis) {
283
+ this._tryToAddEllipsisToLastLine();
294
284
  break;
295
285
  }
296
286
  line = line.slice(low);
@@ -314,6 +304,9 @@ class Text extends Shape_1.Shape {
314
304
  this._addTextLine(line);
315
305
  currentHeightPx += lineHeightPx;
316
306
  textWidth = Math.max(textWidth, lineWidth);
307
+ if (this._shouldHandleEllipsis(currentHeightPx) && i < max - 1) {
308
+ this._tryToAddEllipsisToLastLine();
309
+ }
317
310
  }
318
311
  if (fixedHeight && currentHeightPx + lineHeightPx > maxHeightPx) {
319
312
  break;
@@ -325,6 +318,26 @@ class Text extends Shape_1.Shape {
325
318
  this.textHeight = fontSize;
326
319
  this.textWidth = textWidth;
327
320
  }
321
+ _shouldHandleEllipsis(currentHeightPx) {
322
+ var fontSize = +this.fontSize(), lineHeightPx = this.lineHeight() * fontSize, height = this.attrs.height, fixedHeight = height !== AUTO && height !== undefined, padding = this.padding(), maxHeightPx = height - padding * 2, wrap = this.wrap(), shouldWrap = wrap !== NONE;
323
+ return (!shouldWrap ||
324
+ (fixedHeight && currentHeightPx + lineHeightPx > maxHeightPx));
325
+ }
326
+ _tryToAddEllipsisToLastLine() {
327
+ var width = this.attrs.width, fixedWidth = width !== AUTO && width !== undefined, padding = this.padding(), maxWidth = width - padding * 2, shouldAddEllipsis = this.ellipsis();
328
+ var lastLine = this.textArr[this.textArr.length - 1];
329
+ if (!lastLine || !shouldAddEllipsis) {
330
+ return;
331
+ }
332
+ if (fixedWidth) {
333
+ var haveSpace = this._getTextWidth(lastLine.text + ELLIPSIS) < maxWidth;
334
+ if (!haveSpace) {
335
+ lastLine.text = lastLine.text.slice(0, lastLine.text.length - 3);
336
+ }
337
+ }
338
+ this.textArr.splice(this.textArr.length - 1, 1);
339
+ this._addTextLine(lastLine.text + ELLIPSIS);
340
+ }
328
341
  getStrokeScaleEnabled() {
329
342
  return true;
330
343
  }
@@ -167,7 +167,7 @@ class TextPath extends Shape_1.Shape {
167
167
  pathCmd = undefined;
168
168
  }
169
169
  }
170
- if (pathCmd === {} || p0 === undefined) {
170
+ if (Object.keys(pathCmd).length === 0 || p0 === undefined) {
171
171
  return undefined;
172
172
  }
173
173
  var needNewSegment = false;
@@ -86,6 +86,7 @@ export declare class Transformer extends Group {
86
86
  stopTransform(): void;
87
87
  destroy(): this;
88
88
  toObject(): any;
89
+ getClientRect(): IRect;
89
90
  nodes: GetSet<Node[], this>;
90
91
  enabledAnchors: GetSet<string[], this>;
91
92
  rotationSnaps: GetSet<number[], this>;
@@ -899,6 +899,14 @@ class Transformer extends Group_1.Group {
899
899
  toObject() {
900
900
  return Node_1.Node.prototype.toObject.call(this);
901
901
  }
902
+ getClientRect() {
903
+ if (this.nodes().length > 0) {
904
+ return super.getClientRect();
905
+ }
906
+ else {
907
+ return { x: 0, y: 0, width: 0, height: 0 };
908
+ }
909
+ }
902
910
  }
903
911
  exports.Transformer = Transformer;
904
912
  function validateAnchors(val) {
package/konva.js CHANGED
@@ -5,10 +5,10 @@
5
5
  })(this, (function () { 'use strict';
6
6
 
7
7
  /*
8
- * Konva JavaScript Framework v8.3.9
8
+ * Konva JavaScript Framework v8.3.12
9
9
  * http://konvajs.org/
10
10
  * Licensed under the MIT
11
- * Date: Mon May 30 2022
11
+ * Date: Mon Aug 29 2022
12
12
  *
13
13
  * Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS)
14
14
  * Modified work Copyright (C) 2014 - present by Anton Lavrenov (Konva)
@@ -35,7 +35,7 @@
35
35
  : {};
36
36
  const Konva$2 = {
37
37
  _global: glob,
38
- version: '8.3.9',
38
+ version: '8.3.12',
39
39
  isBrowser: detectBrowser(),
40
40
  isUnminified: /param/.test(function (param) { }.toString()),
41
41
  dblClickWindow: 400,
@@ -1171,6 +1171,12 @@
1171
1171
  function getNumberArrayValidator() {
1172
1172
  if (Konva$2.isUnminified) {
1173
1173
  return function (val, attr) {
1174
+ // Retrieve TypedArray constructor as found in MDN (if TypedArray is available)
1175
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray#description
1176
+ const TypedArray = Int8Array ? Object.getPrototypeOf(Int8Array) : null;
1177
+ if (TypedArray && val instanceof TypedArray) {
1178
+ return val;
1179
+ }
1174
1180
  if (!Util._isArray(val)) {
1175
1181
  Util.warn(_formatValue(val) +
1176
1182
  ' is a not valid value for "' +
@@ -1209,6 +1215,10 @@
1209
1215
  function getComponentValidator(components) {
1210
1216
  if (Konva$2.isUnminified) {
1211
1217
  return function (val, attr) {
1218
+ // ignore validation on undefined value, because it will reset to defalt
1219
+ if (val === undefined || val === null) {
1220
+ return val;
1221
+ }
1212
1222
  if (!Util.isObject(val)) {
1213
1223
  Util.warn(_formatValue(val) +
1214
1224
  ' is a not valid value for "' +
@@ -1283,6 +1293,11 @@
1283
1293
  }
1284
1294
  this._setAttr(attr + capitalize(key), val[key]);
1285
1295
  }
1296
+ if (!val) {
1297
+ components.forEach((component) => {
1298
+ this._setAttr(attr + capitalize(component), undefined);
1299
+ });
1300
+ }
1286
1301
  this._fireChangeEvent(attr, oldVal, val);
1287
1302
  if (after) {
1288
1303
  after.call(this);
@@ -2342,6 +2357,7 @@
2342
2357
  // dragBefore and dragAfter allows us to set correct order of events
2343
2358
  // setup all in dragbefore, and stop dragging only after pointerup triggered.
2344
2359
  _endDragBefore(evt) {
2360
+ const drawNodes = [];
2345
2361
  DD._dragElements.forEach((elem) => {
2346
2362
  const { node } = elem;
2347
2363
  // we need to find pointer relative to that node
@@ -2364,10 +2380,16 @@
2364
2380
  }
2365
2381
  const drawNode = elem.node.getLayer() ||
2366
2382
  (elem.node instanceof Konva$2['Stage'] && elem.node);
2367
- if (drawNode) {
2368
- drawNode.batchDraw();
2383
+ if (drawNode && drawNodes.indexOf(drawNode) === -1) {
2384
+ drawNodes.push(drawNode);
2369
2385
  }
2370
2386
  });
2387
+ // draw in a sync way
2388
+ // because mousemove event may trigger BEFORE batch draw is called
2389
+ // but as we have not hit canvas updated yet, it will trigger incorrect mouseover/mouseout events
2390
+ drawNodes.forEach((drawNode) => {
2391
+ drawNode.draw();
2392
+ });
2371
2393
  },
2372
2394
  _endDragAfter(evt) {
2373
2395
  DD._dragElements.forEach((elem, key) => {
@@ -4037,12 +4059,13 @@
4037
4059
  }
4038
4060
  /**
4039
4061
  * converts node into an image. Since the toImage
4040
- * method is asynchronous, a callback is required. toImage is most commonly used
4062
+ * method is asynchronous, the resulting image can only be retrieved from the config callback
4063
+ * or the returned Promise. toImage is most commonly used
4041
4064
  * to cache complex drawings as an image so that they don't have to constantly be redrawn
4042
4065
  * @method
4043
4066
  * @name Konva.Node#toImage
4044
4067
  * @param {Object} config
4045
- * @param {Function} config.callback function executed when the composite has completed
4068
+ * @param {Function} [config.callback] function executed when the composite has completed
4046
4069
  * @param {String} [config.mimeType] can be "image/png" or "image/jpeg".
4047
4070
  * "image/png" is the default
4048
4071
  * @param {Number} [config.x] x position of canvas section
@@ -4057,6 +4080,7 @@
4057
4080
  * or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
4058
4081
  * If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.
4059
4082
  * @param {Boolean} [config.imageSmoothingEnabled] set this to false if you want to disable imageSmoothing
4083
+ * @return {Promise<Image>}
4060
4084
  * @example
4061
4085
  * var image = node.toImage({
4062
4086
  * callback(img) {
@@ -4065,13 +4089,56 @@
4065
4089
  * });
4066
4090
  */
4067
4091
  toImage(config) {
4068
- if (!config || !config.callback) {
4069
- throw 'callback required for toImage method config argument';
4070
- }
4071
- var callback = config.callback;
4072
- delete config.callback;
4073
- Util._urlToImage(this.toDataURL(config), function (img) {
4074
- callback(img);
4092
+ return new Promise((resolve, reject) => {
4093
+ try {
4094
+ const callback = config === null || config === void 0 ? void 0 : config.callback;
4095
+ if (callback)
4096
+ delete config.callback;
4097
+ Util._urlToImage(this.toDataURL(config), function (img) {
4098
+ resolve(img);
4099
+ callback === null || callback === void 0 ? void 0 : callback(img);
4100
+ });
4101
+ }
4102
+ catch (err) {
4103
+ reject(err);
4104
+ }
4105
+ });
4106
+ }
4107
+ /**
4108
+ * Converts node into a blob. Since the toBlob method is asynchronous,
4109
+ * the resulting blob can only be retrieved from the config callback
4110
+ * or the returned Promise.
4111
+ * @method
4112
+ * @name Konva.Node#toBlob
4113
+ * @param {Object} config
4114
+ * @param {Function} [config.callback] function executed when the composite has completed
4115
+ * @param {Number} [config.x] x position of canvas section
4116
+ * @param {Number} [config.y] y position of canvas section
4117
+ * @param {Number} [config.width] width of canvas section
4118
+ * @param {Number} [config.height] height of canvas section
4119
+ * @param {Number} [config.pixelRatio] pixelRatio of output canvas. Default is 1.
4120
+ * You can use that property to increase quality of the image, for example for super hight quality exports
4121
+ * or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
4122
+ * If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.
4123
+ * @param {Boolean} [config.imageSmoothingEnabled] set this to false if you want to disable imageSmoothing
4124
+ * @example
4125
+ * var blob = await node.toBlob({});
4126
+ * @returns {Promise<Blob>}
4127
+ */
4128
+ toBlob(config) {
4129
+ return new Promise((resolve, reject) => {
4130
+ try {
4131
+ const callback = config === null || config === void 0 ? void 0 : config.callback;
4132
+ if (callback)
4133
+ delete config.callback;
4134
+ this.toCanvas(config).toBlob((blob) => {
4135
+ resolve(blob);
4136
+ callback === null || callback === void 0 ? void 0 : callback(blob);
4137
+ });
4138
+ }
4139
+ catch (err) {
4140
+ reject(err);
4141
+ }
4075
4142
  });
4076
4143
  }
4077
4144
  setSize(size) {
@@ -6324,7 +6391,10 @@
6324
6391
  Konva$2['_' + eventType + 'ListenClick'] = false;
6325
6392
  // always call preventDefault for desktop events because some browsers
6326
6393
  // try to drag and drop the canvas element
6327
- if (evt.cancelable) {
6394
+ // TODO: are we sure we need to prevent default at all?
6395
+ // do not call this function on mobile because it prevent "click" event on all parent containers
6396
+ // but apps may listen to it.
6397
+ if (evt.cancelable && eventType !== 'touch') {
6328
6398
  evt.preventDefault();
6329
6399
  }
6330
6400
  }
@@ -11808,6 +11878,9 @@
11808
11878
  'text',
11809
11879
  'width',
11810
11880
  'height',
11881
+ 'pointerDirection',
11882
+ 'pointerWidth',
11883
+ 'pointerHeight',
11811
11884
  ], CHANGE_KONVA$1 = 'Change.konva', NONE$1 = 'none', UP = 'up', RIGHT$1 = 'right', DOWN = 'down', LEFT$1 = 'left',
11812
11885
  // cached variables
11813
11886
  attrChangeListLen$1 = ATTR_CHANGE_LIST$2.length;
@@ -11975,7 +12048,11 @@
11975
12048
  let bottomLeft = 0;
11976
12049
  let bottomRight = 0;
11977
12050
  if (typeof cornerRadius === 'number') {
11978
- topLeft = topRight = bottomLeft = bottomRight = Math.min(cornerRadius, width / 2, height / 2);
12051
+ topLeft =
12052
+ topRight =
12053
+ bottomLeft =
12054
+ bottomRight =
12055
+ Math.min(cornerRadius, width / 2, height / 2);
11979
12056
  }
11980
12057
  else {
11981
12058
  topLeft = Math.min(cornerRadius[0] || 0, width / 2, height / 2);
@@ -13530,19 +13607,9 @@
13530
13607
  this._addTextLine(match);
13531
13608
  textWidth = Math.max(textWidth, matchWidth);
13532
13609
  currentHeightPx += lineHeightPx;
13533
- if (!shouldWrap ||
13534
- (fixedHeight && currentHeightPx + lineHeightPx > maxHeightPx)) {
13535
- var lastLine = this.textArr[this.textArr.length - 1];
13536
- if (lastLine) {
13537
- if (shouldAddEllipsis) {
13538
- var haveSpace = this._getTextWidth(lastLine.text + ELLIPSIS) < maxWidth;
13539
- if (!haveSpace) {
13540
- lastLine.text = lastLine.text.slice(0, lastLine.text.length - 3);
13541
- }
13542
- this.textArr.splice(this.textArr.length - 1, 1);
13543
- this._addTextLine(lastLine.text + ELLIPSIS);
13544
- }
13545
- }
13610
+ var shouldHandleEllipsis = this._shouldHandleEllipsis(currentHeightPx);
13611
+ if (shouldHandleEllipsis) {
13612
+ this._tryToAddEllipsisToLastLine();
13546
13613
  /*
13547
13614
  * stop wrapping if wrapping is disabled or if adding
13548
13615
  * one more line would overflow the fixed height
@@ -13574,6 +13641,9 @@
13574
13641
  this._addTextLine(line);
13575
13642
  currentHeightPx += lineHeightPx;
13576
13643
  textWidth = Math.max(textWidth, lineWidth);
13644
+ if (this._shouldHandleEllipsis(currentHeightPx) && i < max - 1) {
13645
+ this._tryToAddEllipsisToLastLine();
13646
+ }
13577
13647
  }
13578
13648
  // if element height is fixed, abort if adding one more line would overflow
13579
13649
  if (fixedHeight && currentHeightPx + lineHeightPx > maxHeightPx) {
@@ -13590,6 +13660,33 @@
13590
13660
  // }
13591
13661
  this.textWidth = textWidth;
13592
13662
  }
13663
+ /**
13664
+ * whether to handle ellipsis, there are two cases:
13665
+ * 1. the current line is the last line
13666
+ * 2. wrap is NONE
13667
+ * @param {Number} currentHeightPx
13668
+ * @returns
13669
+ */
13670
+ _shouldHandleEllipsis(currentHeightPx) {
13671
+ var fontSize = +this.fontSize(), lineHeightPx = this.lineHeight() * fontSize, height = this.attrs.height, fixedHeight = height !== AUTO && height !== undefined, padding = this.padding(), maxHeightPx = height - padding * 2, wrap = this.wrap(), shouldWrap = wrap !== NONE;
13672
+ return (!shouldWrap ||
13673
+ (fixedHeight && currentHeightPx + lineHeightPx > maxHeightPx));
13674
+ }
13675
+ _tryToAddEllipsisToLastLine() {
13676
+ var width = this.attrs.width, fixedWidth = width !== AUTO && width !== undefined, padding = this.padding(), maxWidth = width - padding * 2, shouldAddEllipsis = this.ellipsis();
13677
+ var lastLine = this.textArr[this.textArr.length - 1];
13678
+ if (!lastLine || !shouldAddEllipsis) {
13679
+ return;
13680
+ }
13681
+ if (fixedWidth) {
13682
+ var haveSpace = this._getTextWidth(lastLine.text + ELLIPSIS) < maxWidth;
13683
+ if (!haveSpace) {
13684
+ lastLine.text = lastLine.text.slice(0, lastLine.text.length - 3);
13685
+ }
13686
+ }
13687
+ this.textArr.splice(this.textArr.length - 1, 1);
13688
+ this._addTextLine(lastLine.text + ELLIPSIS);
13689
+ }
13593
13690
  // for text we can't disable stroke scaling
13594
13691
  // if we do, the result will be unexpected
13595
13692
  getStrokeScaleEnabled() {
@@ -14131,7 +14228,7 @@
14131
14228
  pathCmd = undefined;
14132
14229
  }
14133
14230
  }
14134
- if (pathCmd === {} || p0 === undefined) {
14231
+ if (Object.keys(pathCmd).length === 0 || p0 === undefined) {
14135
14232
  return undefined;
14136
14233
  }
14137
14234
  var needNewSegment = false;
@@ -15494,6 +15591,16 @@
15494
15591
  toObject() {
15495
15592
  return Node.prototype.toObject.call(this);
15496
15593
  }
15594
+ getClientRect() {
15595
+ if (this.nodes().length > 0) {
15596
+ return super.getClientRect();
15597
+ }
15598
+ else {
15599
+ // if we are detached return zero size
15600
+ // so it will be skipped in calculations
15601
+ return { x: 0, y: 0, width: 0, height: 0 };
15602
+ }
15603
+ }
15497
15604
  }
15498
15605
  function validateAnchors(val) {
15499
15606
  if (!(val instanceof Array)) {