konva 8.3.8 → 8.3.11
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.
- package/cmj/DragAndDrop.js +6 -2
- package/cmj/Global.js +1 -1
- package/cmj/Group.d.ts +3 -1
- package/cmj/Node.d.ts +11 -1
- package/cmj/Node.js +29 -7
- package/cmj/Stage.js +1 -1
- package/cmj/index-types.d.ts +1 -0
- package/cmj/shapes/Label.js +8 -1
- package/cmj/shapes/Text.d.ts +2 -0
- package/cmj/shapes/Text.js +26 -13
- package/cmj/shapes/Transformer.d.ts +6 -0
- package/cmj/shapes/Transformer.js +3 -0
- package/konva.js +116 -29
- package/konva.min.js +3 -3
- package/lib/DragAndDrop.js +6 -2
- package/lib/Global.js +1 -1
- package/lib/Group.d.ts +3 -1
- package/lib/Node.d.ts +11 -1
- package/lib/Node.js +29 -7
- package/lib/Stage.js +1 -1
- package/lib/index-types.d.ts +1 -0
- package/lib/shapes/Label.js +8 -1
- package/lib/shapes/Text.d.ts +2 -0
- package/lib/shapes/Text.js +26 -13
- package/lib/shapes/Transformer.d.ts +6 -0
- package/lib/shapes/Transformer.js +3 -0
- package/package.json +6 -6
package/cmj/DragAndDrop.js
CHANGED
|
@@ -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
|
-
|
|
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/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.
|
|
19
|
+
version: '8.3.11',
|
|
20
20
|
isBrowser: detectBrowser(),
|
|
21
21
|
isUnminified: /param/.test(function (param) { }.toString()),
|
|
22
22
|
dblClickWindow: 400,
|
package/cmj/Group.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { Container } from './Container';
|
|
1
|
+
import { Container, ContainerConfig } from './Container';
|
|
2
2
|
import { Node } from './Node';
|
|
3
3
|
import { Shape } from './Shape';
|
|
4
|
+
export interface GroupConfig extends ContainerConfig {
|
|
5
|
+
}
|
|
4
6
|
export declare class Group extends Container<Group | Shape> {
|
|
5
7
|
_validateAdd(child: Node): void;
|
|
6
8
|
}
|
package/cmj/Node.d.ts
CHANGED
|
@@ -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
|
-
}):
|
|
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;
|
package/cmj/Node.js
CHANGED
|
@@ -967,13 +967,35 @@ class Node {
|
|
|
967
967
|
return url;
|
|
968
968
|
}
|
|
969
969
|
toImage(config) {
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
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
package/cmj/index-types.d.ts
CHANGED
package/cmj/shapes/Label.js
CHANGED
|
@@ -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 =
|
|
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);
|
package/cmj/shapes/Text.d.ts
CHANGED
|
@@ -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>;
|
package/cmj/shapes/Text.js
CHANGED
|
@@ -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
|
-
|
|
282
|
-
|
|
283
|
-
|
|
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)) {
|
|
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
|
}
|
|
@@ -86,6 +86,12 @@ export declare class Transformer extends Group {
|
|
|
86
86
|
stopTransform(): void;
|
|
87
87
|
destroy(): this;
|
|
88
88
|
toObject(): any;
|
|
89
|
+
getClientRect(): {
|
|
90
|
+
x: number;
|
|
91
|
+
y: number;
|
|
92
|
+
width: number;
|
|
93
|
+
height: number;
|
|
94
|
+
};
|
|
89
95
|
nodes: GetSet<Node[], this>;
|
|
90
96
|
enabledAnchors: GetSet<string[], this>;
|
|
91
97
|
rotationSnaps: GetSet<number[], this>;
|
|
@@ -899,6 +899,9 @@ class Transformer extends Group_1.Group {
|
|
|
899
899
|
toObject() {
|
|
900
900
|
return Node_1.Node.prototype.toObject.call(this);
|
|
901
901
|
}
|
|
902
|
+
getClientRect() {
|
|
903
|
+
return { x: 0, y: 0, width: 0, height: 0 };
|
|
904
|
+
}
|
|
902
905
|
}
|
|
903
906
|
exports.Transformer = Transformer;
|
|
904
907
|
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.
|
|
8
|
+
* Konva JavaScript Framework v8.3.11
|
|
9
9
|
* http://konvajs.org/
|
|
10
10
|
* Licensed under the MIT
|
|
11
|
-
* Date:
|
|
11
|
+
* Date: Fri Aug 05 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.
|
|
38
|
+
version: '8.3.11',
|
|
39
39
|
isBrowser: detectBrowser(),
|
|
40
40
|
isUnminified: /param/.test(function (param) { }.toString()),
|
|
41
41
|
dblClickWindow: 400,
|
|
@@ -2342,6 +2342,7 @@
|
|
|
2342
2342
|
// dragBefore and dragAfter allows us to set correct order of events
|
|
2343
2343
|
// setup all in dragbefore, and stop dragging only after pointerup triggered.
|
|
2344
2344
|
_endDragBefore(evt) {
|
|
2345
|
+
const drawNodes = [];
|
|
2345
2346
|
DD._dragElements.forEach((elem) => {
|
|
2346
2347
|
const { node } = elem;
|
|
2347
2348
|
// we need to find pointer relative to that node
|
|
@@ -2364,10 +2365,16 @@
|
|
|
2364
2365
|
}
|
|
2365
2366
|
const drawNode = elem.node.getLayer() ||
|
|
2366
2367
|
(elem.node instanceof Konva$2['Stage'] && elem.node);
|
|
2367
|
-
if (drawNode) {
|
|
2368
|
-
|
|
2368
|
+
if (drawNode && drawNodes.indexOf(drawNode) === -1) {
|
|
2369
|
+
drawNodes.push(drawNode);
|
|
2369
2370
|
}
|
|
2370
2371
|
});
|
|
2372
|
+
// draw in a sync way
|
|
2373
|
+
// because mousemove event may trigger BEFORE batch draw is called
|
|
2374
|
+
// but as we have not hit canvas updated yet, it will trigger incorrect mouseover/mouseout events
|
|
2375
|
+
drawNodes.forEach((drawNode) => {
|
|
2376
|
+
drawNode.draw();
|
|
2377
|
+
});
|
|
2371
2378
|
},
|
|
2372
2379
|
_endDragAfter(evt) {
|
|
2373
2380
|
DD._dragElements.forEach((elem, key) => {
|
|
@@ -4037,12 +4044,13 @@
|
|
|
4037
4044
|
}
|
|
4038
4045
|
/**
|
|
4039
4046
|
* converts node into an image. Since the toImage
|
|
4040
|
-
* method is asynchronous,
|
|
4047
|
+
* method is asynchronous, the resulting image can only be retrieved from the config callback
|
|
4048
|
+
* or the returned Promise. toImage is most commonly used
|
|
4041
4049
|
* to cache complex drawings as an image so that they don't have to constantly be redrawn
|
|
4042
4050
|
* @method
|
|
4043
4051
|
* @name Konva.Node#toImage
|
|
4044
4052
|
* @param {Object} config
|
|
4045
|
-
* @param {Function} config.callback function executed when the composite has completed
|
|
4053
|
+
* @param {Function} [config.callback] function executed when the composite has completed
|
|
4046
4054
|
* @param {String} [config.mimeType] can be "image/png" or "image/jpeg".
|
|
4047
4055
|
* "image/png" is the default
|
|
4048
4056
|
* @param {Number} [config.x] x position of canvas section
|
|
@@ -4057,6 +4065,7 @@
|
|
|
4057
4065
|
* or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
|
|
4058
4066
|
* If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.
|
|
4059
4067
|
* @param {Boolean} [config.imageSmoothingEnabled] set this to false if you want to disable imageSmoothing
|
|
4068
|
+
* @return {Promise<Image>}
|
|
4060
4069
|
* @example
|
|
4061
4070
|
* var image = node.toImage({
|
|
4062
4071
|
* callback(img) {
|
|
@@ -4065,13 +4074,56 @@
|
|
|
4065
4074
|
* });
|
|
4066
4075
|
*/
|
|
4067
4076
|
toImage(config) {
|
|
4068
|
-
|
|
4069
|
-
|
|
4070
|
-
|
|
4071
|
-
|
|
4072
|
-
|
|
4073
|
-
|
|
4074
|
-
|
|
4077
|
+
return new Promise((resolve, reject) => {
|
|
4078
|
+
try {
|
|
4079
|
+
const callback = config === null || config === void 0 ? void 0 : config.callback;
|
|
4080
|
+
if (callback)
|
|
4081
|
+
delete config.callback;
|
|
4082
|
+
Util._urlToImage(this.toDataURL(config), function (img) {
|
|
4083
|
+
resolve(img);
|
|
4084
|
+
callback === null || callback === void 0 ? void 0 : callback(img);
|
|
4085
|
+
});
|
|
4086
|
+
}
|
|
4087
|
+
catch (err) {
|
|
4088
|
+
reject(err);
|
|
4089
|
+
}
|
|
4090
|
+
});
|
|
4091
|
+
}
|
|
4092
|
+
/**
|
|
4093
|
+
* Converts node into a blob. Since the toBlob method is asynchronous,
|
|
4094
|
+
* the resulting blob can only be retrieved from the config callback
|
|
4095
|
+
* or the returned Promise.
|
|
4096
|
+
* @method
|
|
4097
|
+
* @name Konva.Node#toBlob
|
|
4098
|
+
* @param {Object} config
|
|
4099
|
+
* @param {Function} [config.callback] function executed when the composite has completed
|
|
4100
|
+
* @param {Number} [config.x] x position of canvas section
|
|
4101
|
+
* @param {Number} [config.y] y position of canvas section
|
|
4102
|
+
* @param {Number} [config.width] width of canvas section
|
|
4103
|
+
* @param {Number} [config.height] height of canvas section
|
|
4104
|
+
* @param {Number} [config.pixelRatio] pixelRatio of output canvas. Default is 1.
|
|
4105
|
+
* You can use that property to increase quality of the image, for example for super hight quality exports
|
|
4106
|
+
* or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
|
|
4107
|
+
* If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.
|
|
4108
|
+
* @param {Boolean} [config.imageSmoothingEnabled] set this to false if you want to disable imageSmoothing
|
|
4109
|
+
* @example
|
|
4110
|
+
* var blob = await node.toBlob({});
|
|
4111
|
+
* @returns {Promise<Blob>}
|
|
4112
|
+
*/
|
|
4113
|
+
toBlob(config) {
|
|
4114
|
+
return new Promise((resolve, reject) => {
|
|
4115
|
+
try {
|
|
4116
|
+
const callback = config === null || config === void 0 ? void 0 : config.callback;
|
|
4117
|
+
if (callback)
|
|
4118
|
+
delete config.callback;
|
|
4119
|
+
this.toCanvas(config).toBlob(blob => {
|
|
4120
|
+
resolve(blob);
|
|
4121
|
+
callback === null || callback === void 0 ? void 0 : callback(blob);
|
|
4122
|
+
});
|
|
4123
|
+
}
|
|
4124
|
+
catch (err) {
|
|
4125
|
+
reject(err);
|
|
4126
|
+
}
|
|
4075
4127
|
});
|
|
4076
4128
|
}
|
|
4077
4129
|
setSize(size) {
|
|
@@ -6324,7 +6376,10 @@
|
|
|
6324
6376
|
Konva$2['_' + eventType + 'ListenClick'] = false;
|
|
6325
6377
|
// always call preventDefault for desktop events because some browsers
|
|
6326
6378
|
// try to drag and drop the canvas element
|
|
6327
|
-
|
|
6379
|
+
// TODO: are we sure we need to prevent default at all?
|
|
6380
|
+
// do not call this function on mobile because it prevent "click" event on all parent containers
|
|
6381
|
+
// but apps may listen to it.
|
|
6382
|
+
if (evt.cancelable && eventType !== 'touch') {
|
|
6328
6383
|
evt.preventDefault();
|
|
6329
6384
|
}
|
|
6330
6385
|
}
|
|
@@ -11808,6 +11863,9 @@
|
|
|
11808
11863
|
'text',
|
|
11809
11864
|
'width',
|
|
11810
11865
|
'height',
|
|
11866
|
+
'pointerDirection',
|
|
11867
|
+
'pointerWidth',
|
|
11868
|
+
'pointerHeight',
|
|
11811
11869
|
], CHANGE_KONVA$1 = 'Change.konva', NONE$1 = 'none', UP = 'up', RIGHT$1 = 'right', DOWN = 'down', LEFT$1 = 'left',
|
|
11812
11870
|
// cached variables
|
|
11813
11871
|
attrChangeListLen$1 = ATTR_CHANGE_LIST$2.length;
|
|
@@ -11975,7 +12033,11 @@
|
|
|
11975
12033
|
let bottomLeft = 0;
|
|
11976
12034
|
let bottomRight = 0;
|
|
11977
12035
|
if (typeof cornerRadius === 'number') {
|
|
11978
|
-
topLeft =
|
|
12036
|
+
topLeft =
|
|
12037
|
+
topRight =
|
|
12038
|
+
bottomLeft =
|
|
12039
|
+
bottomRight =
|
|
12040
|
+
Math.min(cornerRadius, width / 2, height / 2);
|
|
11979
12041
|
}
|
|
11980
12042
|
else {
|
|
11981
12043
|
topLeft = Math.min(cornerRadius[0] || 0, width / 2, height / 2);
|
|
@@ -13530,19 +13592,9 @@
|
|
|
13530
13592
|
this._addTextLine(match);
|
|
13531
13593
|
textWidth = Math.max(textWidth, matchWidth);
|
|
13532
13594
|
currentHeightPx += lineHeightPx;
|
|
13533
|
-
|
|
13534
|
-
|
|
13535
|
-
|
|
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
|
-
}
|
|
13595
|
+
var shouldHandleEllipsis = this._shouldHandleEllipsis(currentHeightPx);
|
|
13596
|
+
if (shouldHandleEllipsis) {
|
|
13597
|
+
this._tryToAddEllipsisToLastLine();
|
|
13546
13598
|
/*
|
|
13547
13599
|
* stop wrapping if wrapping is disabled or if adding
|
|
13548
13600
|
* one more line would overflow the fixed height
|
|
@@ -13574,6 +13626,9 @@
|
|
|
13574
13626
|
this._addTextLine(line);
|
|
13575
13627
|
currentHeightPx += lineHeightPx;
|
|
13576
13628
|
textWidth = Math.max(textWidth, lineWidth);
|
|
13629
|
+
if (this._shouldHandleEllipsis(currentHeightPx)) {
|
|
13630
|
+
this._tryToAddEllipsisToLastLine();
|
|
13631
|
+
}
|
|
13577
13632
|
}
|
|
13578
13633
|
// if element height is fixed, abort if adding one more line would overflow
|
|
13579
13634
|
if (fixedHeight && currentHeightPx + lineHeightPx > maxHeightPx) {
|
|
@@ -13590,6 +13645,33 @@
|
|
|
13590
13645
|
// }
|
|
13591
13646
|
this.textWidth = textWidth;
|
|
13592
13647
|
}
|
|
13648
|
+
/**
|
|
13649
|
+
* whether to handle ellipsis, there are two cases:
|
|
13650
|
+
* 1. the current line is the last line
|
|
13651
|
+
* 2. wrap is NONE
|
|
13652
|
+
* @param {Number} currentHeightPx
|
|
13653
|
+
* @returns
|
|
13654
|
+
*/
|
|
13655
|
+
_shouldHandleEllipsis(currentHeightPx) {
|
|
13656
|
+
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;
|
|
13657
|
+
return (!shouldWrap ||
|
|
13658
|
+
(fixedHeight && currentHeightPx + lineHeightPx > maxHeightPx));
|
|
13659
|
+
}
|
|
13660
|
+
_tryToAddEllipsisToLastLine() {
|
|
13661
|
+
var width = this.attrs.width, fixedWidth = width !== AUTO && width !== undefined, padding = this.padding(), maxWidth = width - padding * 2, shouldAddEllipsis = this.ellipsis();
|
|
13662
|
+
var lastLine = this.textArr[this.textArr.length - 1];
|
|
13663
|
+
if (!lastLine || !shouldAddEllipsis) {
|
|
13664
|
+
return;
|
|
13665
|
+
}
|
|
13666
|
+
if (fixedWidth) {
|
|
13667
|
+
var haveSpace = this._getTextWidth(lastLine.text + ELLIPSIS) < maxWidth;
|
|
13668
|
+
if (!haveSpace) {
|
|
13669
|
+
lastLine.text = lastLine.text.slice(0, lastLine.text.length - 3);
|
|
13670
|
+
}
|
|
13671
|
+
}
|
|
13672
|
+
this.textArr.splice(this.textArr.length - 1, 1);
|
|
13673
|
+
this._addTextLine(lastLine.text + ELLIPSIS);
|
|
13674
|
+
}
|
|
13593
13675
|
// for text we can't disable stroke scaling
|
|
13594
13676
|
// if we do, the result will be unexpected
|
|
13595
13677
|
getStrokeScaleEnabled() {
|
|
@@ -15494,6 +15576,11 @@
|
|
|
15494
15576
|
toObject() {
|
|
15495
15577
|
return Node.prototype.toObject.call(this);
|
|
15496
15578
|
}
|
|
15579
|
+
getClientRect() {
|
|
15580
|
+
// return zero size
|
|
15581
|
+
// so it will be skipped in calculations
|
|
15582
|
+
return { x: 0, y: 0, width: 0, height: 0 };
|
|
15583
|
+
}
|
|
15497
15584
|
}
|
|
15498
15585
|
function validateAnchors(val) {
|
|
15499
15586
|
if (!(val instanceof Array)) {
|