zrender-nightly 5.6.1-dev.20241121 → 5.6.1-dev.20241123
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/zrender.js +38 -12
- package/dist/zrender.js.map +1 -1
- package/dist/zrender.min.js +1 -1
- package/lib/graphic/Text.d.ts +1 -0
- package/lib/graphic/Text.js +2 -0
- package/lib/graphic/helper/parseText.d.ts +2 -0
- package/lib/graphic/helper/parseText.js +39 -10
- package/lib/zrender.d.ts +1 -1
- package/lib/zrender.js +1 -1
- package/package.json +1 -1
- package/src/graphic/Text.ts +10 -0
- package/src/graphic/helper/parseText.ts +61 -11
- package/src/zrender.ts +1 -1
package/lib/graphic/Text.d.ts
CHANGED
@@ -90,6 +90,7 @@ declare class ZRText extends Displayable<TextProps> implements GroupLike {
|
|
90
90
|
style: TextStyleProps;
|
91
91
|
overlap: 'hidden' | 'show' | 'blur';
|
92
92
|
innerTransformable: Transformable;
|
93
|
+
isTruncated: boolean;
|
93
94
|
private _children;
|
94
95
|
private _childCursor;
|
95
96
|
private _defaultStyle;
|
package/lib/graphic/Text.js
CHANGED
@@ -195,6 +195,7 @@ var ZRText = (function (_super) {
|
|
195
195
|
var textLines = contentBlock.lines;
|
196
196
|
var lineHeight = contentBlock.lineHeight;
|
197
197
|
var defaultStyle = this._defaultStyle;
|
198
|
+
this.isTruncated = !!contentBlock.isTruncated;
|
198
199
|
var baseX = style.x || 0;
|
199
200
|
var baseY = style.y || 0;
|
200
201
|
var textAlign = style.align || defaultStyle.align || 'left';
|
@@ -278,6 +279,7 @@ var ZRText = (function (_super) {
|
|
278
279
|
var defaultStyle = this._defaultStyle;
|
279
280
|
var textAlign = style.align || defaultStyle.align;
|
280
281
|
var verticalAlign = style.verticalAlign || defaultStyle.verticalAlign;
|
282
|
+
this.isTruncated = !!contentBlock.isTruncated;
|
281
283
|
var boxX = adjustTextX(baseX, outerWidth, textAlign);
|
282
284
|
var boxY = adjustTextY(baseY, outerHeight, verticalAlign);
|
283
285
|
var xLeft = boxX;
|
@@ -17,6 +17,7 @@ export interface PlainTextContentBlock {
|
|
17
17
|
outerWidth: number;
|
18
18
|
outerHeight: number;
|
19
19
|
lines: string[];
|
20
|
+
isTruncated: boolean;
|
20
21
|
}
|
21
22
|
export declare function parsePlainText(text: string, style?: TextStyleProps): PlainTextContentBlock;
|
22
23
|
declare class RichTextToken {
|
@@ -49,6 +50,7 @@ export declare class RichTextContentBlock {
|
|
49
50
|
outerWidth: number;
|
50
51
|
outerHeight: number;
|
51
52
|
lines: RichTextLine[];
|
53
|
+
isTruncated: boolean;
|
52
54
|
}
|
53
55
|
export declare function parseRichText(text: string, style: TextStyleProps): RichTextContentBlock;
|
54
56
|
export {};
|
@@ -3,15 +3,27 @@ import { extend, retrieve2, retrieve3, reduce } from '../../core/util.js';
|
|
3
3
|
import { getLineHeight, getWidth, parsePercent } from '../../contain/text.js';
|
4
4
|
var STYLE_REG = /\{([a-zA-Z0-9_]+)\|([^}]*)\}/g;
|
5
5
|
export function truncateText(text, containerWidth, font, ellipsis, options) {
|
6
|
+
var out = {};
|
7
|
+
truncateText2(out, text, containerWidth, font, ellipsis, options);
|
8
|
+
return out.text;
|
9
|
+
}
|
10
|
+
function truncateText2(out, text, containerWidth, font, ellipsis, options) {
|
6
11
|
if (!containerWidth) {
|
7
|
-
|
12
|
+
out.text = '';
|
13
|
+
out.isTruncated = false;
|
14
|
+
return;
|
8
15
|
}
|
9
16
|
var textLines = (text + '').split('\n');
|
10
17
|
options = prepareTruncateOptions(containerWidth, font, ellipsis, options);
|
18
|
+
var isTruncated = false;
|
19
|
+
var truncateOut = {};
|
11
20
|
for (var i = 0, len = textLines.length; i < len; i++) {
|
12
|
-
|
21
|
+
truncateSingleLine(truncateOut, textLines[i], options);
|
22
|
+
textLines[i] = truncateOut.textLine;
|
23
|
+
isTruncated = isTruncated || truncateOut.isTruncated;
|
13
24
|
}
|
14
|
-
|
25
|
+
out.text = textLines.join('\n');
|
26
|
+
out.isTruncated = isTruncated;
|
15
27
|
}
|
16
28
|
function prepareTruncateOptions(containerWidth, font, ellipsis, options) {
|
17
29
|
options = options || {};
|
@@ -39,16 +51,20 @@ function prepareTruncateOptions(containerWidth, font, ellipsis, options) {
|
|
39
51
|
preparedOpts.containerWidth = containerWidth;
|
40
52
|
return preparedOpts;
|
41
53
|
}
|
42
|
-
function truncateSingleLine(textLine, options) {
|
54
|
+
function truncateSingleLine(out, textLine, options) {
|
43
55
|
var containerWidth = options.containerWidth;
|
44
56
|
var font = options.font;
|
45
57
|
var contentWidth = options.contentWidth;
|
46
58
|
if (!containerWidth) {
|
47
|
-
|
59
|
+
out.textLine = '';
|
60
|
+
out.isTruncated = false;
|
61
|
+
return;
|
48
62
|
}
|
49
63
|
var lineWidth = getWidth(textLine, font);
|
50
64
|
if (lineWidth <= containerWidth) {
|
51
|
-
|
65
|
+
out.textLine = textLine;
|
66
|
+
out.isTruncated = false;
|
67
|
+
return;
|
52
68
|
}
|
53
69
|
for (var j = 0;; j++) {
|
54
70
|
if (lineWidth <= contentWidth || j >= options.maxIterations) {
|
@@ -66,7 +82,8 @@ function truncateSingleLine(textLine, options) {
|
|
66
82
|
if (textLine === '') {
|
67
83
|
textLine = options.placeholder;
|
68
84
|
}
|
69
|
-
|
85
|
+
out.textLine = textLine;
|
86
|
+
out.isTruncated = true;
|
70
87
|
}
|
71
88
|
function estimateLength(text, contentWidth, ascCharWidth, cnCharWidth) {
|
72
89
|
var width = 0;
|
@@ -87,6 +104,7 @@ export function parsePlainText(text, style) {
|
|
87
104
|
var lineHeight = retrieve2(style.lineHeight, calculatedLineHeight);
|
88
105
|
var bgColorDrawn = !!(style.backgroundColor);
|
89
106
|
var truncateLineOverflow = style.lineOverflow === 'truncate';
|
107
|
+
var isTruncated = false;
|
90
108
|
var width = style.width;
|
91
109
|
var lines;
|
92
110
|
if (width != null && (overflow === 'break' || overflow === 'breakAll')) {
|
@@ -99,6 +117,7 @@ export function parsePlainText(text, style) {
|
|
99
117
|
var height = retrieve2(style.height, contentHeight);
|
100
118
|
if (contentHeight > height && truncateLineOverflow) {
|
101
119
|
var lineCount = Math.floor(height / lineHeight);
|
120
|
+
isTruncated = isTruncated || (lines.length > lineCount);
|
102
121
|
lines = lines.slice(0, lineCount);
|
103
122
|
}
|
104
123
|
if (text && truncate && width != null) {
|
@@ -106,8 +125,11 @@ export function parsePlainText(text, style) {
|
|
106
125
|
minChar: style.truncateMinChar,
|
107
126
|
placeholder: style.placeholder
|
108
127
|
});
|
128
|
+
var singleOut = {};
|
109
129
|
for (var i = 0; i < lines.length; i++) {
|
110
|
-
|
130
|
+
truncateSingleLine(singleOut, lines[i], options);
|
131
|
+
lines[i] = singleOut.textLine;
|
132
|
+
isTruncated = isTruncated || singleOut.isTruncated;
|
111
133
|
}
|
112
134
|
}
|
113
135
|
var outerHeight = height;
|
@@ -136,7 +158,8 @@ export function parsePlainText(text, style) {
|
|
136
158
|
calculatedLineHeight: calculatedLineHeight,
|
137
159
|
contentWidth: contentWidth,
|
138
160
|
contentHeight: contentHeight,
|
139
|
-
width: width
|
161
|
+
width: width,
|
162
|
+
isTruncated: isTruncated
|
140
163
|
};
|
141
164
|
}
|
142
165
|
var RichTextToken = (function () {
|
@@ -162,6 +185,7 @@ var RichTextContentBlock = (function () {
|
|
162
185
|
this.outerWidth = 0;
|
163
186
|
this.outerHeight = 0;
|
164
187
|
this.lines = [];
|
188
|
+
this.isTruncated = false;
|
165
189
|
}
|
166
190
|
return RichTextContentBlock;
|
167
191
|
}());
|
@@ -197,6 +221,7 @@ export function parseRichText(text, style) {
|
|
197
221
|
var stlPadding = style.padding;
|
198
222
|
var truncate = overflow === 'truncate';
|
199
223
|
var truncateLine = style.lineOverflow === 'truncate';
|
224
|
+
var tmpTruncateOut = {};
|
200
225
|
function finishLine(line, lineWidth, lineHeight) {
|
201
226
|
line.width = lineWidth;
|
202
227
|
line.lineHeight = lineHeight;
|
@@ -222,6 +247,7 @@ export function parseRichText(text, style) {
|
|
222
247
|
token.align = tokenStyle && tokenStyle.align || style.align;
|
223
248
|
token.verticalAlign = tokenStyle && tokenStyle.verticalAlign || 'middle';
|
224
249
|
if (truncateLine && topHeight != null && calculatedHeight + token.lineHeight > topHeight) {
|
250
|
+
var originalLength = contentBlock.lines.length;
|
225
251
|
if (j > 0) {
|
226
252
|
line.tokens = line.tokens.slice(0, j);
|
227
253
|
finishLine(line, lineWidth, lineHeight);
|
@@ -230,6 +256,7 @@ export function parseRichText(text, style) {
|
|
230
256
|
else {
|
231
257
|
contentBlock.lines = contentBlock.lines.slice(0, i);
|
232
258
|
}
|
259
|
+
contentBlock.isTruncated = contentBlock.isTruncated || (contentBlock.lines.length < originalLength);
|
233
260
|
break outer;
|
234
261
|
}
|
235
262
|
var styleTokenWidth = tokenStyle.width;
|
@@ -258,7 +285,9 @@ export function parseRichText(text, style) {
|
|
258
285
|
token.width = token.contentWidth = 0;
|
259
286
|
}
|
260
287
|
else {
|
261
|
-
|
288
|
+
truncateText2(tmpTruncateOut, token.text, remainTruncWidth - paddingH, font, style.ellipsis, { minChar: style.truncateMinChar });
|
289
|
+
token.text = tmpTruncateOut.text;
|
290
|
+
contentBlock.isTruncated = contentBlock.isTruncated || tmpTruncateOut.isTruncated;
|
262
291
|
token.width = token.contentWidth = getWidth(token.text, font);
|
263
292
|
}
|
264
293
|
}
|
package/lib/zrender.d.ts
CHANGED
@@ -90,7 +90,7 @@ export declare type ElementSSRData = zrUtil.HashMap<unknown>;
|
|
90
90
|
export declare type ElementSSRDataGetter<T> = (el: Element) => zrUtil.HashMap<T>;
|
91
91
|
export declare function getElementSSRData(el: Element): ElementSSRData;
|
92
92
|
export declare function registerSSRDataGetter<T>(getter: ElementSSRDataGetter<T>): void;
|
93
|
-
export declare const version = "5.6.1-dev.
|
93
|
+
export declare const version = "5.6.1-dev.20241123";
|
94
94
|
export interface ZRenderType extends ZRender {
|
95
95
|
}
|
96
96
|
export {};
|
package/lib/zrender.js
CHANGED
package/package.json
CHANGED
package/src/graphic/Text.ts
CHANGED
@@ -275,6 +275,12 @@ class ZRText extends Displayable<TextProps> implements GroupLike {
|
|
275
275
|
*/
|
276
276
|
innerTransformable: Transformable
|
277
277
|
|
278
|
+
// Be `true` if and only if the result text is modified due to overflow, due to
|
279
|
+
// settings on either `overflow` or `lineOverflow`. Based on this the caller can
|
280
|
+
// take some action like showing the original text in a particular tip.
|
281
|
+
// Only take effect after rendering. So do not visit it before it.
|
282
|
+
isTruncated: boolean
|
283
|
+
|
278
284
|
private _children: (ZRImage | Rect | TSpan)[] = []
|
279
285
|
|
280
286
|
private _childCursor: 0
|
@@ -497,6 +503,8 @@ class ZRText extends Displayable<TextProps> implements GroupLike {
|
|
497
503
|
|
498
504
|
const defaultStyle = this._defaultStyle;
|
499
505
|
|
506
|
+
this.isTruncated = !!contentBlock.isTruncated;
|
507
|
+
|
500
508
|
const baseX = style.x || 0;
|
501
509
|
const baseY = style.y || 0;
|
502
510
|
const textAlign = style.align || defaultStyle.align || 'left';
|
@@ -635,6 +643,8 @@ class ZRText extends Displayable<TextProps> implements GroupLike {
|
|
635
643
|
const textAlign = style.align || defaultStyle.align;
|
636
644
|
const verticalAlign = style.verticalAlign || defaultStyle.verticalAlign;
|
637
645
|
|
646
|
+
this.isTruncated = !!contentBlock.isTruncated;
|
647
|
+
|
638
648
|
const boxX = adjustTextX(baseX, outerWidth, textAlign);
|
639
649
|
const boxY = adjustTextY(baseY, outerHeight, verticalAlign);
|
640
650
|
let xLeft = boxX;
|
@@ -44,8 +44,25 @@ export function truncateText(
|
|
44
44
|
ellipsis?: string,
|
45
45
|
options?: InnerTruncateOption
|
46
46
|
): string {
|
47
|
+
const out = {} as Parameters<typeof truncateText2>[0];
|
48
|
+
truncateText2(out, text, containerWidth, font, ellipsis, options);
|
49
|
+
return out.text;
|
50
|
+
}
|
51
|
+
|
52
|
+
// PENDING: not sure whether `truncateText` is used outside zrender, since it has an `export`
|
53
|
+
// specifier. So keep it and perform the interface modification in `truncateText2`.
|
54
|
+
function truncateText2(
|
55
|
+
out: {text: string, isTruncated: boolean},
|
56
|
+
text: string,
|
57
|
+
containerWidth: number,
|
58
|
+
font: string,
|
59
|
+
ellipsis?: string,
|
60
|
+
options?: InnerTruncateOption
|
61
|
+
): void {
|
47
62
|
if (!containerWidth) {
|
48
|
-
|
63
|
+
out.text = '';
|
64
|
+
out.isTruncated = false;
|
65
|
+
return;
|
49
66
|
}
|
50
67
|
|
51
68
|
const textLines = (text + '').split('\n');
|
@@ -53,11 +70,16 @@ export function truncateText(
|
|
53
70
|
|
54
71
|
// FIXME
|
55
72
|
// It is not appropriate that every line has '...' when truncate multiple lines.
|
73
|
+
let isTruncated = false;
|
74
|
+
const truncateOut = {} as Parameters<typeof truncateSingleLine>[0];
|
56
75
|
for (let i = 0, len = textLines.length; i < len; i++) {
|
57
|
-
|
76
|
+
truncateSingleLine(truncateOut, textLines[i], options as InnerPreparedTruncateOption);
|
77
|
+
textLines[i] = truncateOut.textLine;
|
78
|
+
isTruncated = isTruncated || truncateOut.isTruncated;
|
58
79
|
}
|
59
80
|
|
60
|
-
|
81
|
+
out.text = textLines.join('\n');
|
82
|
+
out.isTruncated = isTruncated;
|
61
83
|
}
|
62
84
|
|
63
85
|
function prepareTruncateOptions(
|
@@ -104,19 +126,27 @@ function prepareTruncateOptions(
|
|
104
126
|
return preparedOpts;
|
105
127
|
}
|
106
128
|
|
107
|
-
function truncateSingleLine(
|
129
|
+
function truncateSingleLine(
|
130
|
+
out: {textLine: string, isTruncated: boolean},
|
131
|
+
textLine: string,
|
132
|
+
options: InnerPreparedTruncateOption
|
133
|
+
): void {
|
108
134
|
const containerWidth = options.containerWidth;
|
109
135
|
const font = options.font;
|
110
136
|
const contentWidth = options.contentWidth;
|
111
137
|
|
112
138
|
if (!containerWidth) {
|
113
|
-
|
139
|
+
out.textLine = '';
|
140
|
+
out.isTruncated = false;
|
141
|
+
return;
|
114
142
|
}
|
115
143
|
|
116
144
|
let lineWidth = getWidth(textLine, font);
|
117
145
|
|
118
146
|
if (lineWidth <= containerWidth) {
|
119
|
-
|
147
|
+
out.textLine = textLine;
|
148
|
+
out.isTruncated = false;
|
149
|
+
return;
|
120
150
|
}
|
121
151
|
|
122
152
|
for (let j = 0; ; j++) {
|
@@ -139,7 +169,8 @@ function truncateSingleLine(textLine: string, options: InnerPreparedTruncateOpti
|
|
139
169
|
textLine = options.placeholder;
|
140
170
|
}
|
141
171
|
|
142
|
-
|
172
|
+
out.textLine = textLine;
|
173
|
+
out.isTruncated = true;
|
143
174
|
}
|
144
175
|
|
145
176
|
function estimateLength(
|
@@ -174,6 +205,10 @@ export interface PlainTextContentBlock {
|
|
174
205
|
outerHeight: number
|
175
206
|
|
176
207
|
lines: string[]
|
208
|
+
|
209
|
+
// Be `true` if and only if the result text is modified due to overflow, due to
|
210
|
+
// settings on either `overflow` or `lineOverflow`
|
211
|
+
isTruncated: boolean
|
177
212
|
}
|
178
213
|
|
179
214
|
export function parsePlainText(
|
@@ -192,6 +227,7 @@ export function parsePlainText(
|
|
192
227
|
const bgColorDrawn = !!(style.backgroundColor);
|
193
228
|
|
194
229
|
const truncateLineOverflow = style.lineOverflow === 'truncate';
|
230
|
+
let isTruncated = false;
|
195
231
|
|
196
232
|
let width = style.width;
|
197
233
|
let lines: string[];
|
@@ -210,6 +246,7 @@ export function parsePlainText(
|
|
210
246
|
if (contentHeight > height && truncateLineOverflow) {
|
211
247
|
const lineCount = Math.floor(height / lineHeight);
|
212
248
|
|
249
|
+
isTruncated = isTruncated || (lines.length > lineCount);
|
213
250
|
lines = lines.slice(0, lineCount);
|
214
251
|
|
215
252
|
// TODO If show ellipse for line truncate
|
@@ -228,8 +265,11 @@ export function parsePlainText(
|
|
228
265
|
placeholder: style.placeholder
|
229
266
|
});
|
230
267
|
// Having every line has '...' when truncate multiple lines.
|
268
|
+
const singleOut = {} as Parameters<typeof truncateSingleLine>[0];
|
231
269
|
for (let i = 0; i < lines.length; i++) {
|
232
|
-
|
270
|
+
truncateSingleLine(singleOut, lines[i], options);
|
271
|
+
lines[i] = singleOut.textLine;
|
272
|
+
isTruncated = isTruncated || singleOut.isTruncated;
|
233
273
|
}
|
234
274
|
}
|
235
275
|
|
@@ -265,7 +305,8 @@ export function parsePlainText(
|
|
265
305
|
calculatedLineHeight: calculatedLineHeight,
|
266
306
|
contentWidth: contentWidth,
|
267
307
|
contentHeight: contentHeight,
|
268
|
-
width: width
|
308
|
+
width: width,
|
309
|
+
isTruncated: isTruncated
|
269
310
|
};
|
270
311
|
}
|
271
312
|
|
@@ -314,6 +355,9 @@ export class RichTextContentBlock {
|
|
314
355
|
outerWidth: number = 0
|
315
356
|
outerHeight: number = 0
|
316
357
|
lines: RichTextLine[] = []
|
358
|
+
// Be `true` if and only if the result text is modified due to overflow, due to
|
359
|
+
// settings on either `overflow` or `lineOverflow`
|
360
|
+
isTruncated: boolean = false
|
317
361
|
}
|
318
362
|
|
319
363
|
type WrapInfo = {
|
@@ -326,7 +370,7 @@ type WrapInfo = {
|
|
326
370
|
* Also consider 'bbbb{a|xxx\nzzz}xxxx\naaaa'.
|
327
371
|
* If styleName is undefined, it is plain text.
|
328
372
|
*/
|
329
|
-
export function parseRichText(text: string, style: TextStyleProps) {
|
373
|
+
export function parseRichText(text: string, style: TextStyleProps): RichTextContentBlock {
|
330
374
|
const contentBlock = new RichTextContentBlock();
|
331
375
|
|
332
376
|
text != null && (text += '');
|
@@ -366,6 +410,7 @@ export function parseRichText(text: string, style: TextStyleProps) {
|
|
366
410
|
|
367
411
|
const truncate = overflow === 'truncate';
|
368
412
|
const truncateLine = style.lineOverflow === 'truncate';
|
413
|
+
const tmpTruncateOut = {} as Parameters<typeof truncateText2>[0];
|
369
414
|
|
370
415
|
// let prevToken: RichTextToken;
|
371
416
|
|
@@ -412,6 +457,7 @@ export function parseRichText(text: string, style: TextStyleProps) {
|
|
412
457
|
if (truncateLine && topHeight != null && calculatedHeight + token.lineHeight > topHeight) {
|
413
458
|
// TODO Add ellipsis on the previous token.
|
414
459
|
// prevToken.text =
|
460
|
+
const originalLength = contentBlock.lines.length;
|
415
461
|
if (j > 0) {
|
416
462
|
line.tokens = line.tokens.slice(0, j);
|
417
463
|
finishLine(line, lineWidth, lineHeight);
|
@@ -420,6 +466,7 @@ export function parseRichText(text: string, style: TextStyleProps) {
|
|
420
466
|
else {
|
421
467
|
contentBlock.lines = contentBlock.lines.slice(0, i);
|
422
468
|
}
|
469
|
+
contentBlock.isTruncated = contentBlock.isTruncated || (contentBlock.lines.length < originalLength);
|
423
470
|
break outer;
|
424
471
|
}
|
425
472
|
|
@@ -461,10 +508,13 @@ export function parseRichText(text: string, style: TextStyleProps) {
|
|
461
508
|
token.width = token.contentWidth = 0;
|
462
509
|
}
|
463
510
|
else {
|
464
|
-
|
511
|
+
truncateText2(
|
512
|
+
tmpTruncateOut,
|
465
513
|
token.text, remainTruncWidth - paddingH, font, style.ellipsis,
|
466
514
|
{minChar: style.truncateMinChar}
|
467
515
|
);
|
516
|
+
token.text = tmpTruncateOut.text;
|
517
|
+
contentBlock.isTruncated = contentBlock.isTruncated || tmpTruncateOut.isTruncated;
|
468
518
|
token.width = token.contentWidth = getWidth(token.text, font);
|
469
519
|
}
|
470
520
|
}
|
package/src/zrender.ts
CHANGED
@@ -556,7 +556,7 @@ export function registerSSRDataGetter<T>(getter: ElementSSRDataGetter<T>) {
|
|
556
556
|
/**
|
557
557
|
* @type {string}
|
558
558
|
*/
|
559
|
-
export const version = '5.6.1-dev.
|
559
|
+
export const version = '5.6.1-dev.20241123';
|
560
560
|
|
561
561
|
|
562
562
|
export interface ZRenderType extends ZRender {};
|