zrender-nightly 5.7.0-dev.20250620 → 5.7.0-dev.20250622

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.
Files changed (61) hide show
  1. package/README.md +1 -1
  2. package/build/prepublish.js +20 -0
  3. package/dist/zrender.js +563 -277
  4. package/dist/zrender.js.map +1 -1
  5. package/dist/zrender.min.js +1 -1
  6. package/lib/Element.d.ts +4 -0
  7. package/lib/Element.js +34 -16
  8. package/lib/Handler.js +1 -1
  9. package/lib/Storage.js +20 -20
  10. package/lib/canvas/graphic.js +1 -1
  11. package/lib/contain/text.d.ts +14 -2
  12. package/lib/contain/text.js +65 -15
  13. package/lib/core/BoundingRect.d.ts +25 -3
  14. package/lib/core/BoundingRect.js +182 -76
  15. package/lib/core/OrientedBoundingRect.d.ts +2 -2
  16. package/lib/core/OrientedBoundingRect.js +50 -34
  17. package/lib/core/PathProxy.d.ts +1 -0
  18. package/lib/core/PathProxy.js +16 -1
  19. package/lib/core/dom.d.ts +1 -0
  20. package/lib/core/dom.js +17 -0
  21. package/lib/core/env.js +15 -10
  22. package/lib/core/types.d.ts +1 -0
  23. package/lib/core/util.d.ts +1 -0
  24. package/lib/core/util.js +2 -1
  25. package/lib/graphic/Displayable.js +1 -1
  26. package/lib/graphic/Text.d.ts +4 -2
  27. package/lib/graphic/Text.js +23 -14
  28. package/lib/graphic/helper/parseText.d.ts +13 -4
  29. package/lib/graphic/helper/parseText.js +110 -54
  30. package/lib/svg-legacy/helper/ClippathManager.js +6 -6
  31. package/lib/tool/color.d.ts +3 -1
  32. package/lib/tool/color.js +6 -6
  33. package/lib/tool/parseSVG.js +11 -0
  34. package/lib/tool/path.js +7 -4
  35. package/lib/zrender.d.ts +1 -1
  36. package/lib/zrender.js +1 -1
  37. package/package.json +3 -2
  38. package/src/Element.ts +69 -16
  39. package/src/Handler.ts +1 -1
  40. package/src/Storage.ts +25 -24
  41. package/src/canvas/graphic.ts +1 -1
  42. package/src/canvas/helper.ts +1 -1
  43. package/src/contain/text.ts +103 -19
  44. package/src/core/BoundingRect.ts +308 -87
  45. package/src/core/OrientedBoundingRect.ts +86 -46
  46. package/src/core/PathProxy.ts +17 -1
  47. package/src/core/Transformable.ts +2 -0
  48. package/src/core/dom.ts +24 -0
  49. package/src/core/env.ts +31 -24
  50. package/src/core/matrix.ts +2 -1
  51. package/src/core/types.ts +2 -0
  52. package/src/core/util.ts +4 -2
  53. package/src/graphic/Displayable.ts +1 -3
  54. package/src/graphic/Group.ts +2 -0
  55. package/src/graphic/Text.ts +68 -21
  56. package/src/graphic/helper/parseText.ts +211 -83
  57. package/src/svg-legacy/helper/ClippathManager.ts +5 -5
  58. package/src/tool/color.ts +15 -11
  59. package/src/tool/parseSVG.ts +12 -1
  60. package/src/tool/path.ts +9 -4
  61. package/src/zrender.ts +1 -1
@@ -1,5 +1,5 @@
1
1
  import { __extends } from "tslib";
2
- import { parseRichText, parsePlainText } from './helper/parseText.js';
2
+ import { parseRichText, parsePlainText, calcInnerTextOverflowArea } from './helper/parseText.js';
3
3
  import TSpan from './TSpan.js';
4
4
  import { retrieve2, each, normalizeCssArray, trim, retrieve3, extend, keys, defaults } from '../core/util.js';
5
5
  import { adjustTextX, adjustTextY } from '../contain/text.js';
@@ -12,6 +12,7 @@ var DEFAULT_RICH_TEXT_COLOR = {
12
12
  fill: '#000'
13
13
  };
14
14
  var DEFAULT_STROKE_LINE_WIDTH = 2;
15
+ var tmpCITOverflowAreaOut = {};
15
16
  export var DEFAULT_TEXT_ANIMATION_PROPS = {
16
17
  style: defaults({
17
18
  fill: true,
@@ -185,8 +186,16 @@ var ZRText = (function (_super) {
185
186
  var style = this.style;
186
187
  var textFont = style.font || DEFAULT_FONT;
187
188
  var textPadding = style.padding;
189
+ var defaultStyle = this._defaultStyle;
190
+ var baseX = style.x || 0;
191
+ var baseY = style.y || 0;
192
+ var textAlign = style.align || defaultStyle.align || 'left';
193
+ var verticalAlign = style.verticalAlign || defaultStyle.verticalAlign || 'top';
194
+ calcInnerTextOverflowArea(tmpCITOverflowAreaOut, defaultStyle.overflowRect, baseX, baseY, textAlign, verticalAlign);
195
+ baseX = tmpCITOverflowAreaOut.baseX;
196
+ baseY = tmpCITOverflowAreaOut.baseY;
188
197
  var text = getStyleText(style);
189
- var contentBlock = parsePlainText(text, style);
198
+ var contentBlock = parsePlainText(text, style, tmpCITOverflowAreaOut.outerWidth, tmpCITOverflowAreaOut.outerHeight);
190
199
  var needDrawBg = needDrawBackground(style);
191
200
  var bgColorDrawn = !!(style.backgroundColor);
192
201
  var outerHeight = contentBlock.outerHeight;
@@ -194,11 +203,7 @@ var ZRText = (function (_super) {
194
203
  var contentWidth = contentBlock.contentWidth;
195
204
  var textLines = contentBlock.lines;
196
205
  var lineHeight = contentBlock.lineHeight;
197
- var defaultStyle = this._defaultStyle;
198
- var baseX = style.x || 0;
199
- var baseY = style.y || 0;
200
- var textAlign = style.align || defaultStyle.align || 'left';
201
- var verticalAlign = style.verticalAlign || defaultStyle.verticalAlign || 'top';
206
+ this.isTruncated = !!contentBlock.isTruncated;
202
207
  var textX = baseX;
203
208
  var textY = adjustTextY(baseY, contentBlock.contentHeight, verticalAlign);
204
209
  if (needDrawBg || textPadding) {
@@ -261,23 +266,27 @@ var ZRText = (function (_super) {
261
266
  setSeparateFont(subElStyle, style);
262
267
  textY += lineHeight;
263
268
  if (fixedBoundingRect) {
264
- el.setBoundingRect(new BoundingRect(adjustTextX(subElStyle.x, style.width, subElStyle.textAlign), adjustTextY(subElStyle.y, calculatedLineHeight, subElStyle.textBaseline), contentWidth, calculatedLineHeight));
269
+ el.setBoundingRect(new BoundingRect(adjustTextX(subElStyle.x, contentWidth, subElStyle.textAlign), adjustTextY(subElStyle.y, calculatedLineHeight, subElStyle.textBaseline), contentWidth, calculatedLineHeight));
265
270
  }
266
271
  }
267
272
  };
268
273
  ZRText.prototype._updateRichTexts = function () {
269
274
  var style = this.style;
275
+ var defaultStyle = this._defaultStyle;
276
+ var textAlign = style.align || defaultStyle.align;
277
+ var verticalAlign = style.verticalAlign || defaultStyle.verticalAlign;
278
+ var baseX = style.x || 0;
279
+ var baseY = style.y || 0;
280
+ calcInnerTextOverflowArea(tmpCITOverflowAreaOut, defaultStyle.overflowRect, baseX, baseY, textAlign, verticalAlign);
281
+ baseX = tmpCITOverflowAreaOut.baseX;
282
+ baseY = tmpCITOverflowAreaOut.baseY;
270
283
  var text = getStyleText(style);
271
- var contentBlock = parseRichText(text, style);
284
+ var contentBlock = parseRichText(text, style, tmpCITOverflowAreaOut.outerWidth, tmpCITOverflowAreaOut.outerHeight, textAlign);
272
285
  var contentWidth = contentBlock.width;
273
286
  var outerWidth = contentBlock.outerWidth;
274
287
  var outerHeight = contentBlock.outerHeight;
275
288
  var textPadding = style.padding;
276
- var baseX = style.x || 0;
277
- var baseY = style.y || 0;
278
- var defaultStyle = this._defaultStyle;
279
- var textAlign = style.align || defaultStyle.align;
280
- var verticalAlign = style.verticalAlign || defaultStyle.verticalAlign;
289
+ this.isTruncated = !!contentBlock.isTruncated;
281
290
  var boxX = adjustTextX(baseX, outerWidth, textAlign);
282
291
  var boxY = adjustTextY(baseY, outerHeight, verticalAlign);
283
292
  var xLeft = boxX;
@@ -1,5 +1,5 @@
1
- import { TextAlign, TextVerticalAlign } from '../../core/types';
2
- import { TextStyleProps } from '../Text';
1
+ import { TextAlign, TextVerticalAlign, NullUndefined } from '../../core/types';
2
+ import { DefaultTextStyle, TextStyleProps } from '../Text';
3
3
  interface InnerTruncateOption {
4
4
  maxIteration?: number;
5
5
  minChar?: number;
@@ -17,8 +17,9 @@ export interface PlainTextContentBlock {
17
17
  outerWidth: number;
18
18
  outerHeight: number;
19
19
  lines: string[];
20
+ isTruncated: boolean;
20
21
  }
21
- export declare function parsePlainText(text: string, style?: TextStyleProps): PlainTextContentBlock;
22
+ export declare function parsePlainText(text: string, style: Omit<TextStyleProps, 'align' | 'verticalAlign'>, defaultOuterWidth: number | NullUndefined, defaultOuterHeight: number | NullUndefined): PlainTextContentBlock;
22
23
  declare class RichTextToken {
23
24
  styleName: string;
24
25
  text: string;
@@ -49,6 +50,14 @@ export declare class RichTextContentBlock {
49
50
  outerWidth: number;
50
51
  outerHeight: number;
51
52
  lines: RichTextLine[];
53
+ isTruncated: boolean;
52
54
  }
53
- export declare function parseRichText(text: string, style: TextStyleProps): RichTextContentBlock;
55
+ export declare function parseRichText(text: string, style: Omit<TextStyleProps, 'align' | 'verticalAlign'>, defaultOuterWidth: number | NullUndefined, defaultOuterHeight: number | NullUndefined, topTextAlign: TextAlign): RichTextContentBlock;
56
+ export declare function calcInnerTextOverflowArea(out: CalcInnerTextOverflowAreaOut, overflowRect: DefaultTextStyle['overflowRect'], baseX: number, baseY: number, textAlign: TextAlign, textVerticalAlign: TextVerticalAlign): void;
57
+ export declare type CalcInnerTextOverflowAreaOut = {
58
+ baseX: number;
59
+ baseY: number;
60
+ outerWidth: number | NullUndefined;
61
+ outerHeight: number | NullUndefined;
62
+ };
54
63
  export {};
@@ -1,33 +1,45 @@
1
1
  import * as imageHelper from '../helper/image.js';
2
- import { extend, retrieve2, retrieve3, reduce } from '../../core/util.js';
3
- import { getLineHeight, getWidth, parsePercent } from '../../contain/text.js';
2
+ import { extend, retrieve2, retrieve3, reduce, } from '../../core/util.js';
3
+ import { adjustTextX, adjustTextY, ensureFontMeasureInfo, getLineHeight, measureCharWidth, measureWidth, parsePercent, } from '../../contain/text.js';
4
+ import BoundingRect from '../../core/BoundingRect.js';
4
5
  var STYLE_REG = /\{([a-zA-Z0-9_]+)\|([^}]*)\}/g;
5
6
  export function truncateText(text, containerWidth, font, ellipsis, options) {
7
+ var out = {};
8
+ truncateText2(out, text, containerWidth, font, ellipsis, options);
9
+ return out.text;
10
+ }
11
+ function truncateText2(out, text, containerWidth, font, ellipsis, options) {
6
12
  if (!containerWidth) {
7
- return '';
13
+ out.text = '';
14
+ out.isTruncated = false;
15
+ return;
8
16
  }
9
17
  var textLines = (text + '').split('\n');
10
18
  options = prepareTruncateOptions(containerWidth, font, ellipsis, options);
19
+ var isTruncated = false;
20
+ var truncateOut = {};
11
21
  for (var i = 0, len = textLines.length; i < len; i++) {
12
- textLines[i] = truncateSingleLine(textLines[i], options);
22
+ truncateSingleLine(truncateOut, textLines[i], options);
23
+ textLines[i] = truncateOut.textLine;
24
+ isTruncated = isTruncated || truncateOut.isTruncated;
13
25
  }
14
- return textLines.join('\n');
26
+ out.text = textLines.join('\n');
27
+ out.isTruncated = isTruncated;
15
28
  }
16
29
  function prepareTruncateOptions(containerWidth, font, ellipsis, options) {
17
30
  options = options || {};
18
31
  var preparedOpts = extend({}, options);
19
- preparedOpts.font = font;
20
32
  ellipsis = retrieve2(ellipsis, '...');
21
33
  preparedOpts.maxIterations = retrieve2(options.maxIterations, 2);
22
34
  var minChar = preparedOpts.minChar = retrieve2(options.minChar, 0);
23
- preparedOpts.cnCharWidth = getWidth('国', font);
24
- var ascCharWidth = preparedOpts.ascCharWidth = getWidth('a', font);
35
+ var fontMeasureInfo = preparedOpts.fontMeasureInfo = ensureFontMeasureInfo(font);
36
+ var ascCharWidth = fontMeasureInfo.asciiCharWidth;
25
37
  preparedOpts.placeholder = retrieve2(options.placeholder, '');
26
38
  var contentWidth = containerWidth = Math.max(0, containerWidth - 1);
27
39
  for (var i = 0; i < minChar && contentWidth >= ascCharWidth; i++) {
28
40
  contentWidth -= ascCharWidth;
29
41
  }
30
- var ellipsisWidth = getWidth(ellipsis, font);
42
+ var ellipsisWidth = measureWidth(fontMeasureInfo, ellipsis);
31
43
  if (ellipsisWidth > contentWidth) {
32
44
  ellipsis = '';
33
45
  ellipsisWidth = 0;
@@ -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
- var font = options.font;
45
56
  var contentWidth = options.contentWidth;
57
+ var fontMeasureInfo = options.fontMeasureInfo;
46
58
  if (!containerWidth) {
47
- return '';
59
+ out.textLine = '';
60
+ out.isTruncated = false;
61
+ return;
48
62
  }
49
- var lineWidth = getWidth(textLine, font);
63
+ var lineWidth = measureWidth(fontMeasureInfo, textLine);
50
64
  if (lineWidth <= containerWidth) {
51
- return textLine;
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) {
@@ -56,38 +72,47 @@ function truncateSingleLine(textLine, options) {
56
72
  break;
57
73
  }
58
74
  var subLength = j === 0
59
- ? estimateLength(textLine, contentWidth, options.ascCharWidth, options.cnCharWidth)
75
+ ? estimateLength(textLine, contentWidth, fontMeasureInfo)
60
76
  : lineWidth > 0
61
77
  ? Math.floor(textLine.length * contentWidth / lineWidth)
62
78
  : 0;
63
79
  textLine = textLine.substr(0, subLength);
64
- lineWidth = getWidth(textLine, font);
80
+ lineWidth = measureWidth(fontMeasureInfo, textLine);
65
81
  }
66
82
  if (textLine === '') {
67
83
  textLine = options.placeholder;
68
84
  }
69
- return textLine;
85
+ out.textLine = textLine;
86
+ out.isTruncated = true;
70
87
  }
71
- function estimateLength(text, contentWidth, ascCharWidth, cnCharWidth) {
88
+ function estimateLength(text, contentWidth, fontMeasureInfo) {
72
89
  var width = 0;
73
90
  var i = 0;
74
91
  for (var len = text.length; i < len && width < contentWidth; i++) {
75
- var charCode = text.charCodeAt(i);
76
- width += (0 <= charCode && charCode <= 127) ? ascCharWidth : cnCharWidth;
92
+ width += measureCharWidth(fontMeasureInfo, text.charCodeAt(i));
77
93
  }
78
94
  return i;
79
95
  }
80
- export function parsePlainText(text, style) {
96
+ export function parsePlainText(text, style, defaultOuterWidth, defaultOuterHeight) {
81
97
  text != null && (text += '');
82
98
  var overflow = style.overflow;
83
99
  var padding = style.padding;
100
+ var paddingH = padding ? padding[1] + padding[3] : 0;
101
+ var paddingV = padding ? padding[0] + padding[2] : 0;
84
102
  var font = style.font;
85
103
  var truncate = overflow === 'truncate';
86
104
  var calculatedLineHeight = getLineHeight(font);
87
105
  var lineHeight = retrieve2(style.lineHeight, calculatedLineHeight);
88
- var bgColorDrawn = !!(style.backgroundColor);
89
106
  var truncateLineOverflow = style.lineOverflow === 'truncate';
107
+ var isTruncated = false;
90
108
  var width = style.width;
109
+ if (width == null && defaultOuterWidth != null) {
110
+ width = defaultOuterWidth - paddingH;
111
+ }
112
+ var height = style.height;
113
+ if (height == null && defaultOuterHeight != null) {
114
+ height = defaultOuterHeight - paddingV;
115
+ }
91
116
  var lines;
92
117
  if (width != null && (overflow === 'break' || overflow === 'breakAll')) {
93
118
  lines = text ? wrapText(text, style.font, width, overflow === 'breakAll', 0).lines : [];
@@ -96,37 +121,39 @@ export function parsePlainText(text, style) {
96
121
  lines = text ? text.split('\n') : [];
97
122
  }
98
123
  var contentHeight = lines.length * lineHeight;
99
- var height = retrieve2(style.height, contentHeight);
124
+ if (height == null) {
125
+ height = contentHeight;
126
+ }
100
127
  if (contentHeight > height && truncateLineOverflow) {
101
128
  var lineCount = Math.floor(height / lineHeight);
129
+ isTruncated = isTruncated || (lines.length > lineCount);
102
130
  lines = lines.slice(0, lineCount);
131
+ contentHeight = lines.length * lineHeight;
103
132
  }
104
133
  if (text && truncate && width != null) {
105
134
  var options = prepareTruncateOptions(width, font, style.ellipsis, {
106
135
  minChar: style.truncateMinChar,
107
136
  placeholder: style.placeholder
108
137
  });
138
+ var singleOut = {};
109
139
  for (var i = 0; i < lines.length; i++) {
110
- lines[i] = truncateSingleLine(lines[i], options);
140
+ truncateSingleLine(singleOut, lines[i], options);
141
+ lines[i] = singleOut.textLine;
142
+ isTruncated = isTruncated || singleOut.isTruncated;
111
143
  }
112
144
  }
113
145
  var outerHeight = height;
114
146
  var contentWidth = 0;
147
+ var fontMeasureInfo = ensureFontMeasureInfo(font);
115
148
  for (var i = 0; i < lines.length; i++) {
116
- contentWidth = Math.max(getWidth(lines[i], font), contentWidth);
149
+ contentWidth = Math.max(measureWidth(fontMeasureInfo, lines[i]), contentWidth);
117
150
  }
118
151
  if (width == null) {
119
152
  width = contentWidth;
120
153
  }
121
- var outerWidth = contentWidth;
122
- if (padding) {
123
- outerHeight += padding[0] + padding[2];
124
- outerWidth += padding[1] + padding[3];
125
- width += padding[1] + padding[3];
126
- }
127
- if (bgColorDrawn) {
128
- outerWidth = width;
129
- }
154
+ var outerWidth = width;
155
+ outerHeight += paddingV;
156
+ outerWidth += paddingH;
130
157
  return {
131
158
  lines: lines,
132
159
  height: height,
@@ -136,7 +163,8 @@ export function parsePlainText(text, style) {
136
163
  calculatedLineHeight: calculatedLineHeight,
137
164
  contentWidth: contentWidth,
138
165
  contentHeight: contentHeight,
139
- width: width
166
+ width: width,
167
+ isTruncated: isTruncated
140
168
  };
141
169
  }
142
170
  var RichTextToken = (function () {
@@ -162,18 +190,28 @@ var RichTextContentBlock = (function () {
162
190
  this.outerWidth = 0;
163
191
  this.outerHeight = 0;
164
192
  this.lines = [];
193
+ this.isTruncated = false;
165
194
  }
166
195
  return RichTextContentBlock;
167
196
  }());
168
197
  export { RichTextContentBlock };
169
- export function parseRichText(text, style) {
198
+ export function parseRichText(text, style, defaultOuterWidth, defaultOuterHeight, topTextAlign) {
170
199
  var contentBlock = new RichTextContentBlock();
171
200
  text != null && (text += '');
172
201
  if (!text) {
173
202
  return contentBlock;
174
203
  }
204
+ var stlPadding = style.padding;
205
+ var stlPaddingH = stlPadding ? stlPadding[1] + stlPadding[3] : 0;
206
+ var stlPaddingV = stlPadding ? stlPadding[0] + stlPadding[2] : 0;
175
207
  var topWidth = style.width;
208
+ if (topWidth == null && defaultOuterWidth != null) {
209
+ topWidth = defaultOuterWidth - stlPaddingH;
210
+ }
176
211
  var topHeight = style.height;
212
+ if (topHeight == null && defaultOuterHeight != null) {
213
+ topHeight = defaultOuterHeight - stlPaddingV;
214
+ }
177
215
  var overflow = style.overflow;
178
216
  var wrapInfo = (overflow === 'break' || overflow === 'breakAll') && topWidth != null
179
217
  ? { width: topWidth, accumWidth: 0, breakAll: overflow === 'breakAll' }
@@ -194,9 +232,9 @@ export function parseRichText(text, style) {
194
232
  var pendingList = [];
195
233
  var calculatedHeight = 0;
196
234
  var calculatedWidth = 0;
197
- var stlPadding = style.padding;
198
235
  var truncate = overflow === 'truncate';
199
236
  var truncateLine = style.lineOverflow === 'truncate';
237
+ var tmpTruncateOut = {};
200
238
  function finishLine(line, lineWidth, lineHeight) {
201
239
  line.width = lineWidth;
202
240
  line.lineHeight = lineHeight;
@@ -219,9 +257,10 @@ export function parseRichText(text, style) {
219
257
  textPadding && (tokenHeight += textPadding[0] + textPadding[2]);
220
258
  token.height = tokenHeight;
221
259
  token.lineHeight = retrieve3(tokenStyle.lineHeight, style.lineHeight, tokenHeight);
222
- token.align = tokenStyle && tokenStyle.align || style.align;
260
+ token.align = tokenStyle && tokenStyle.align || topTextAlign;
223
261
  token.verticalAlign = tokenStyle && tokenStyle.verticalAlign || 'middle';
224
262
  if (truncateLine && topHeight != null && calculatedHeight + token.lineHeight > topHeight) {
263
+ var originalLength = contentBlock.lines.length;
225
264
  if (j > 0) {
226
265
  line.tokens = line.tokens.slice(0, j);
227
266
  finishLine(line, lineWidth, lineHeight);
@@ -230,6 +269,7 @@ export function parseRichText(text, style) {
230
269
  else {
231
270
  contentBlock.lines = contentBlock.lines.slice(0, i);
232
271
  }
272
+ contentBlock.isTruncated = contentBlock.isTruncated || (contentBlock.lines.length < originalLength);
233
273
  break outer;
234
274
  }
235
275
  var styleTokenWidth = tokenStyle.width;
@@ -237,7 +277,7 @@ export function parseRichText(text, style) {
237
277
  if (typeof styleTokenWidth === 'string' && styleTokenWidth.charAt(styleTokenWidth.length - 1) === '%') {
238
278
  token.percentWidth = styleTokenWidth;
239
279
  pendingList.push(token);
240
- token.contentWidth = getWidth(token.text, font);
280
+ token.contentWidth = measureWidth(ensureFontMeasureInfo(font), token.text);
241
281
  }
242
282
  else {
243
283
  if (tokenWidthNotSpecified) {
@@ -258,12 +298,14 @@ export function parseRichText(text, style) {
258
298
  token.width = token.contentWidth = 0;
259
299
  }
260
300
  else {
261
- token.text = truncateText(token.text, remainTruncWidth - paddingH, font, style.ellipsis, { minChar: style.truncateMinChar });
262
- token.width = token.contentWidth = getWidth(token.text, font);
301
+ truncateText2(tmpTruncateOut, token.text, remainTruncWidth - paddingH, font, style.ellipsis, { minChar: style.truncateMinChar });
302
+ token.text = tmpTruncateOut.text;
303
+ contentBlock.isTruncated = contentBlock.isTruncated || tmpTruncateOut.isTruncated;
304
+ token.width = token.contentWidth = measureWidth(ensureFontMeasureInfo(font), token.text);
263
305
  }
264
306
  }
265
307
  else {
266
- token.contentWidth = getWidth(token.text, font);
308
+ token.contentWidth = measureWidth(ensureFontMeasureInfo(font), token.text);
267
309
  }
268
310
  }
269
311
  token.width += paddingH;
@@ -276,10 +318,8 @@ export function parseRichText(text, style) {
276
318
  contentBlock.outerHeight = contentBlock.height = retrieve2(topHeight, calculatedHeight);
277
319
  contentBlock.contentHeight = calculatedHeight;
278
320
  contentBlock.contentWidth = calculatedWidth;
279
- if (stlPadding) {
280
- contentBlock.outerWidth += stlPadding[1] + stlPadding[3];
281
- contentBlock.outerHeight += stlPadding[0] + stlPadding[2];
282
- }
321
+ contentBlock.outerWidth += stlPaddingH;
322
+ contentBlock.outerHeight += stlPaddingV;
283
323
  for (var i = 0; i < pendingList.length; i++) {
284
324
  var token = pendingList[i];
285
325
  var percentWidth = token.percentWidth;
@@ -315,9 +355,10 @@ function pushTokens(block, str, style, wrapInfo, styleName) {
315
355
  strLines = res.lines;
316
356
  }
317
357
  }
318
- else {
358
+ if (!strLines) {
319
359
  strLines = str.split('\n');
320
360
  }
361
+ var fontMeasureInfo = ensureFontMeasureInfo(font);
321
362
  for (var i = 0; i < strLines.length; i++) {
322
363
  var text = strLines[i];
323
364
  var token = new RichTextToken();
@@ -330,7 +371,7 @@ function pushTokens(block, str, style, wrapInfo, styleName) {
330
371
  else {
331
372
  token.width = linesWidths
332
373
  ? linesWidths[i]
333
- : getWidth(text, font);
374
+ : measureWidth(fontMeasureInfo, text);
334
375
  }
335
376
  if (!i && !newLine) {
336
377
  var tokens = (lines[lines.length - 1] || (lines[0] = new RichTextLine())).tokens;
@@ -371,6 +412,7 @@ function wrapText(text, font, lineWidth, isBreakAll, lastAccumWidth) {
371
412
  var currentWord = '';
372
413
  var currentWordWidth = 0;
373
414
  var accumWidth = 0;
415
+ var fontMeasureInfo = ensureFontMeasureInfo(font);
374
416
  for (var i = 0; i < text.length; i++) {
375
417
  var ch = text.charAt(i);
376
418
  if (ch === '\n') {
@@ -386,7 +428,7 @@ function wrapText(text, font, lineWidth, isBreakAll, lastAccumWidth) {
386
428
  accumWidth = 0;
387
429
  continue;
388
430
  }
389
- var chWidth = getWidth(ch, font);
431
+ var chWidth = measureCharWidth(fontMeasureInfo, ch.charCodeAt(0));
390
432
  var inWord = isBreakAll ? false : !isWordBreakChar(ch);
391
433
  if (!lines.length
392
434
  ? lastAccumWidth + accumWidth + chWidth > lineWidth
@@ -446,11 +488,6 @@ function wrapText(text, font, lineWidth, isBreakAll, lastAccumWidth) {
446
488
  line += ch;
447
489
  }
448
490
  }
449
- if (!lines.length && !line) {
450
- line = text;
451
- currentWord = '';
452
- currentWordWidth = 0;
453
- }
454
491
  if (currentWord) {
455
492
  line += currentWord;
456
493
  }
@@ -467,3 +504,22 @@ function wrapText(text, font, lineWidth, isBreakAll, lastAccumWidth) {
467
504
  linesWidths: linesWidths
468
505
  };
469
506
  }
507
+ export function calcInnerTextOverflowArea(out, overflowRect, baseX, baseY, textAlign, textVerticalAlign) {
508
+ out.baseX = baseX;
509
+ out.baseY = baseY;
510
+ out.outerWidth = out.outerHeight = null;
511
+ if (!overflowRect) {
512
+ return;
513
+ }
514
+ var textWidth = overflowRect.width * 2;
515
+ var textHeight = overflowRect.height * 2;
516
+ BoundingRect.set(tmpCITCTextRect, adjustTextX(baseX, textWidth, textAlign), adjustTextY(baseY, textHeight, textVerticalAlign), textWidth, textHeight);
517
+ BoundingRect.intersect(overflowRect, tmpCITCTextRect, null, tmpCITCIntersectRectOpt);
518
+ var outIntersectRect = tmpCITCIntersectRectOpt.outIntersectRect;
519
+ out.outerWidth = outIntersectRect.width;
520
+ out.outerHeight = outIntersectRect.height;
521
+ out.baseX = adjustTextX(outIntersectRect.x, outIntersectRect.width, textAlign, true);
522
+ out.baseY = adjustTextY(outIntersectRect.y, outIntersectRect.height, textVerticalAlign, true);
523
+ }
524
+ var tmpCITCTextRect = new BoundingRect(0, 0, 0, 0);
525
+ var tmpCITCIntersectRectOpt = { outIntersectRect: {}, clamp: true };
@@ -1,6 +1,5 @@
1
1
  import { __extends } from "tslib";
2
2
  import Definable from './Definable.js';
3
- import * as zrUtil from '../../core/util.js';
4
3
  import { path } from '../graphic.js';
5
4
  import { isClipPathChanged } from '../../canvas/helper.js';
6
5
  import { getClipPathsKey, getIdURL } from '../../svg/helper.js';
@@ -89,13 +88,14 @@ var ClippathManager = (function (_super) {
89
88
  };
90
89
  ;
91
90
  ClippathManager.prototype.markUsed = function (displayable) {
92
- var _this = this;
93
- if (displayable.__clipPaths) {
94
- zrUtil.each(displayable.__clipPaths, function (clipPath) {
91
+ var clipPaths = displayable.__clipPaths;
92
+ if (clipPaths) {
93
+ for (var idx = 0; idx < clipPaths.length; idx++) {
94
+ var clipPath = clipPaths[idx];
95
95
  if (clipPath._dom) {
96
- _super.prototype.markDomUsed.call(_this, clipPath._dom);
96
+ _super.prototype.markDomUsed.call(this, clipPath._dom);
97
97
  }
98
- });
98
+ }
99
99
  }
100
100
  };
101
101
  ;
@@ -1,4 +1,6 @@
1
1
  import { GradientObject } from '../graphic/Gradient';
2
+ export declare function parseCssInt(val: string | number): number;
3
+ export declare function parseCssFloat(val: string | number): number;
2
4
  export declare function parse(colorStr: string, rgbaArr?: number[]): number[];
3
5
  export declare function lift(color: string, level: number): string;
4
6
  export declare function toHex(color: string): string;
@@ -13,7 +15,7 @@ declare type LerpFullOutput = {
13
15
  export declare function lerp(normalizedValue: number, colors: string[], fullOutput: boolean): LerpFullOutput;
14
16
  export declare function lerp(normalizedValue: number, colors: string[]): string;
15
17
  export declare const mapToColor: typeof lerp;
16
- export declare function modifyHSL(color: string, h?: number, s?: number, l?: number): string;
18
+ export declare function modifyHSL(color: string, h?: number | ((h: number) => number), s?: number | string | ((s: number) => number), l?: number | string | ((l: number) => number)): string;
17
19
  export declare function modifyAlpha(color: string, alpha?: number): string;
18
20
  export declare function stringify(arrColor: number[], type: string): string;
19
21
  export declare function lum(color: string, backgroundLum: number): number;
package/lib/tool/color.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import LRU from '../core/LRU.js';
2
- import { extend, isGradientObject, isString, map } from '../core/util.js';
2
+ import { extend, isFunction, isGradientObject, isString, map } from '../core/util.js';
3
3
  var kCSSColorTable = {
4
4
  'transparent': [0, 0, 0, 0], 'aliceblue': [240, 248, 255, 1],
5
5
  'antiquewhite': [250, 235, 215, 1], 'aqua': [0, 255, 255, 1],
@@ -87,14 +87,14 @@ function clampCssAngle(i) {
87
87
  function clampCssFloat(f) {
88
88
  return f < 0 ? 0 : f > 1 ? 1 : f;
89
89
  }
90
- function parseCssInt(val) {
90
+ export function parseCssInt(val) {
91
91
  var str = val;
92
92
  if (str.length && str.charAt(str.length - 1) === '%') {
93
93
  return clampCssByte(parseFloat(str) / 100 * 255);
94
94
  }
95
95
  return clampCssByte(parseInt(str, 10));
96
96
  }
97
- function parseCssFloat(val) {
97
+ export function parseCssFloat(val) {
98
98
  var str = val;
99
99
  if (str.length && str.charAt(str.length - 1) === '%') {
100
100
  return clampCssFloat(parseFloat(str) / 100);
@@ -370,9 +370,9 @@ export function modifyHSL(color, h, s, l) {
370
370
  var colorArr = parse(color);
371
371
  if (color) {
372
372
  colorArr = rgba2hsla(colorArr);
373
- h != null && (colorArr[0] = clampCssAngle(h));
374
- s != null && (colorArr[1] = parseCssFloat(s));
375
- l != null && (colorArr[2] = parseCssFloat(l));
373
+ h != null && (colorArr[0] = clampCssAngle(isFunction(h) ? h(colorArr[0]) : h));
374
+ s != null && (colorArr[1] = parseCssFloat(isFunction(s) ? s(colorArr[1]) : s));
375
+ l != null && (colorArr[2] = parseCssFloat(isFunction(l) ? l(colorArr[2]) : l));
376
376
  return stringify(hsla2rgba(colorArr), 'rgba');
377
377
  }
378
378
  }
@@ -13,6 +13,7 @@ import LinearGradient from '../graphic/LinearGradient.js';
13
13
  import RadialGradient from '../graphic/RadialGradient.js';
14
14
  import TSpan from '../graphic/TSpan.js';
15
15
  import { parseXML } from './parseXML.js';
16
+ import * as colorTool from './color.js';
16
17
  ;
17
18
  var nodeParsers;
18
19
  var INHERITABLE_STYLE_ATTRIBUTES_MAP = {
@@ -399,6 +400,16 @@ function parseGradientColorStops(xmlNode, gradient) {
399
400
  var stopColor = styleVals.stopColor
400
401
  || stop.getAttribute('stop-color')
401
402
  || '#000000';
403
+ var stopOpacity = styleVals.stopOpacity
404
+ || stop.getAttribute('stop-opacity');
405
+ if (stopOpacity) {
406
+ var rgba = colorTool.parse(stopColor);
407
+ var stopColorOpacity = rgba && rgba[3];
408
+ if (stopColorOpacity) {
409
+ rgba[3] *= colorTool.parseCssFloat(stopOpacity);
410
+ stopColor = colorTool.stringify(rgba, 'rgba');
411
+ }
412
+ }
402
413
  gradient.colorStops.push({
403
414
  offset: offset,
404
415
  color: stopColor
package/lib/tool/path.js CHANGED
@@ -290,16 +290,19 @@ function createPathOptions(str, opts) {
290
290
  var pathProxy = createPathProxyFromString(str);
291
291
  var innerOpts = extend({}, opts);
292
292
  innerOpts.buildPath = function (path) {
293
- if (isPathProxy(path)) {
294
- path.setData(pathProxy.data);
293
+ var beProxy = isPathProxy(path);
294
+ if (beProxy && path.canSave()) {
295
+ path.appendPath(pathProxy);
295
296
  var ctx = path.getContext();
296
297
  if (ctx) {
297
298
  path.rebuildPath(ctx, 1);
298
299
  }
299
300
  }
300
301
  else {
301
- var ctx = path;
302
- pathProxy.rebuildPath(ctx, 1);
302
+ var ctx = beProxy ? path.getContext() : path;
303
+ if (ctx) {
304
+ pathProxy.rebuildPath(ctx, 1);
305
+ }
303
306
  }
304
307
  };
305
308
  innerOpts.applyTransform = function (m) {
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.7.0-dev.20250620";
93
+ export declare const version = "5.7.0-dev.20250622";
94
94
  export interface ZRenderType extends ZRender {
95
95
  }
96
96
  export {};
package/lib/zrender.js CHANGED
@@ -324,5 +324,5 @@ export function getElementSSRData(el) {
324
324
  export function registerSSRDataGetter(getter) {
325
325
  ssrDataGetter = getter;
326
326
  }
327
- export var version = '5.7.0-dev.20250620';
327
+ export var version = '5.7.0-dev.20250622';
328
328
  ;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zrender-nightly",
3
- "version": "5.7.0-dev.20250620",
3
+ "version": "5.7.0-dev.20250622",
4
4
  "description": "A lightweight graphic library providing 2d draw for Apache ECharts",
5
5
  "keywords": [
6
6
  "canvas",
@@ -25,7 +25,8 @@
25
25
  "watch:bundle": "node build/build.js --watch",
26
26
  "watch:lib": "npx tsc-watch -m ES2015 --outDir lib --synchronousWatchDirectory --onSuccess \"node build/processLib.js\"",
27
27
  "test": "npx jest --config test/ut/jest.config.js",
28
- "lint": "npx eslint src/**/*.ts"
28
+ "lint": "npx eslint src/**/*.ts",
29
+ "checktype": "tsc --noEmit"
29
30
  },
30
31
  "license": "BSD-3-Clause",
31
32
  "types": "index.d.ts",