zrender-nightly 5.6.2-dev.20250624 → 5.6.2-dev.20250625

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 (50) hide show
  1. package/dist/zrender.js +491 -253
  2. package/dist/zrender.js.map +1 -1
  3. package/dist/zrender.min.js +1 -1
  4. package/lib/Element.d.ts +4 -0
  5. package/lib/Element.js +34 -16
  6. package/lib/Handler.js +1 -1
  7. package/lib/Storage.js +20 -20
  8. package/lib/contain/text.d.ts +14 -2
  9. package/lib/contain/text.js +65 -15
  10. package/lib/core/BoundingRect.d.ts +25 -3
  11. package/lib/core/BoundingRect.js +182 -76
  12. package/lib/core/OrientedBoundingRect.d.ts +2 -2
  13. package/lib/core/OrientedBoundingRect.js +50 -34
  14. package/lib/core/PathProxy.d.ts +1 -0
  15. package/lib/core/PathProxy.js +16 -1
  16. package/lib/core/types.d.ts +1 -0
  17. package/lib/core/util.d.ts +1 -0
  18. package/lib/core/util.js +1 -0
  19. package/lib/graphic/Displayable.js +1 -1
  20. package/lib/graphic/Text.d.ts +3 -2
  21. package/lib/graphic/Text.js +20 -13
  22. package/lib/graphic/helper/parseText.d.ts +11 -4
  23. package/lib/graphic/helper/parseText.js +71 -44
  24. package/lib/svg-legacy/helper/ClippathManager.js +6 -6
  25. package/lib/tool/color.d.ts +1 -1
  26. package/lib/tool/color.js +4 -4
  27. package/lib/tool/path.js +7 -4
  28. package/lib/zrender.d.ts +1 -1
  29. package/lib/zrender.js +1 -1
  30. package/package.json +3 -2
  31. package/src/Element.ts +69 -16
  32. package/src/Handler.ts +1 -1
  33. package/src/Storage.ts +25 -24
  34. package/src/canvas/helper.ts +1 -1
  35. package/src/contain/text.ts +103 -19
  36. package/src/core/BoundingRect.ts +308 -87
  37. package/src/core/OrientedBoundingRect.ts +86 -46
  38. package/src/core/PathProxy.ts +17 -1
  39. package/src/core/Transformable.ts +2 -0
  40. package/src/core/matrix.ts +2 -1
  41. package/src/core/types.ts +2 -0
  42. package/src/core/util.ts +3 -1
  43. package/src/graphic/Displayable.ts +1 -3
  44. package/src/graphic/Group.ts +2 -0
  45. package/src/graphic/Text.ts +59 -22
  46. package/src/graphic/helper/parseText.ts +151 -73
  47. package/src/svg-legacy/helper/ClippathManager.ts +5 -5
  48. package/src/tool/color.ts +13 -9
  49. package/src/tool/path.ts +9 -4
  50. package/src/zrender.ts +1 -1
@@ -365,6 +365,9 @@ export default class PathProxy {
365
365
  }
366
366
 
367
367
  setData(data: Float32Array | number[]) {
368
+ if (!this._saveData) {
369
+ return;
370
+ }
368
371
 
369
372
  const len = data.length;
370
373
 
@@ -380,6 +383,9 @@ export default class PathProxy {
380
383
  }
381
384
 
382
385
  appendPath(path: PathProxy | PathProxy[]) {
386
+ if (!this._saveData) {
387
+ return;
388
+ }
383
389
  if (!(path instanceof Array)) {
384
390
  path = [path];
385
391
  }
@@ -389,8 +395,14 @@ export default class PathProxy {
389
395
  for (let i = 0; i < len; i++) {
390
396
  appendSize += path[i].len();
391
397
  }
392
- if (hasTypedArray && (this.data instanceof Float32Array)) {
398
+ const oldData = this.data;
399
+ if (hasTypedArray && (oldData instanceof Float32Array || !oldData)) {
393
400
  this.data = new Float32Array(offset + appendSize);
401
+ if (offset > 0 && oldData) {
402
+ for (let k = 0; k < offset; k++) {
403
+ this.data[k] = oldData[k];
404
+ }
405
+ }
394
406
  }
395
407
  for (let i = 0; i < len; i++) {
396
408
  const appendPathData = path[i].data;
@@ -970,6 +982,10 @@ export default class PathProxy {
970
982
  return newProxy;
971
983
  }
972
984
 
985
+ canSave(): boolean {
986
+ return !!this._saveData;
987
+ }
988
+
973
989
  private static initDefaultProps = (function () {
974
990
  const proto = PathProxy.prototype;
975
991
  proto._saveData = true;
@@ -27,6 +27,8 @@ class Transformable {
27
27
  skewX: number
28
28
  skewY: number
29
29
 
30
+ // Suppose positive y is towards screen-bottom and positive x is towards screen-right;
31
+ // positive rotation means rotating anticlockwise. (opposite to CSS transform rotate)
30
32
  rotation: number
31
33
 
32
34
  /**
@@ -77,7 +77,8 @@ export function translate(out: MatrixArray, a: MatrixArray, v: VectorArray): Mat
77
77
  }
78
78
 
79
79
  /**
80
- * 旋转变换
80
+ * Suppose positive y is towards screen-bottom and positive x is towards screen-right;
81
+ * positive rotation means rotating anticlockwise. (opposite to CSS transform rotate)
81
82
  */
82
83
  export function rotate(
83
84
  out: MatrixArray,
package/src/core/types.ts CHANGED
@@ -11,6 +11,8 @@ export type ArrayLike<T> = {
11
11
  length: number
12
12
  }
13
13
 
14
+ export type NullUndefined = null | undefined;
15
+
14
16
  export type ImageLike = HTMLImageElement | HTMLCanvasElement | HTMLVideoElement
15
17
 
16
18
  // subset of CanvasTextBaseline
package/src/core/util.ts CHANGED
@@ -819,4 +819,6 @@ export function hasOwn(own: object, prop: string): boolean {
819
819
 
820
820
  export function noop() {}
821
821
 
822
- export const RADIAN_TO_DEGREE = 180 / Math.PI;
822
+ export const RADIAN_TO_DEGREE = 180 / Math.PI;
823
+
824
+ export const EPSILON = Number.EPSILON || Math.pow(2, -52);
@@ -154,8 +154,6 @@ class Displayable<Props extends DisplayableProps = DisplayableProps> extends Ele
154
154
  // TODO use WeakMap?
155
155
 
156
156
  // Shapes for cascade clipping.
157
- // Can only be `null`/`undefined` or an non-empty array, MUST NOT be an empty array.
158
- // because it is easy to only using null to check whether clipPaths changed.
159
157
  __clipPaths?: Path[]
160
158
 
161
159
  // FOR CANVAS PAINTER
@@ -223,7 +221,7 @@ class Displayable<Props extends DisplayableProps = DisplayableProps> extends Ele
223
221
  return false;
224
222
  }
225
223
 
226
- if (considerClipPath && this.__clipPaths) {
224
+ if (considerClipPath && this.__clipPaths && this.__clipPaths.length) {
227
225
  for (let i = 0; i < this.__clipPaths.length; ++i) {
228
226
  if (this.__clipPaths[i].isZeroArea()) {
229
227
  return false;
@@ -256,6 +256,8 @@ class Group extends Element<GroupProps> {
256
256
 
257
257
  getBoundingRect(includeChildren?: Element[]): BoundingRect {
258
258
  // TODO Caching
259
+ // FIXME: if no child or all ignored, the returned boundingRect (0, 0, 0, 0)
260
+ // is not a correct bounding rect in some scenarios, such as rect union and intersection detection.
259
261
  const tmpRect = new BoundingRect(0, 0, 0, 0);
260
262
  const children = includeChildren || this._children;
261
263
  const tmpMat: MatrixArray = [];
@@ -1,9 +1,13 @@
1
1
  /**
2
2
  * RichText is a container that manages complex text label.
3
- * It will parse text string and create sub displayble elements respectively.
3
+ * It will parse text string and create sub displayable elements respectively.
4
4
  */
5
- import { TextAlign, TextVerticalAlign, ImageLike, Dictionary, MapToType, FontWeight, FontStyle } from '../core/types';
6
- import { parseRichText, parsePlainText } from './helper/parseText';
5
+ import {
6
+ TextAlign, TextVerticalAlign, ImageLike, Dictionary, MapToType, FontWeight, FontStyle, NullUndefined
7
+ } from '../core/types';
8
+ import {
9
+ parseRichText, parsePlainText, CalcInnerTextOverflowAreaOut, calcInnerTextOverflowArea
10
+ } from './helper/parseText';
7
11
  import TSpan, { TSpanStyleProps } from './TSpan';
8
12
  import { retrieve2, each, normalizeCssArray, trim, retrieve3, extend, keys, defaults } from '../core/util';
9
13
  import { adjustTextX, adjustTextY } from '../contain/text';
@@ -41,7 +45,7 @@ export interface TextStylePropsPart {
41
45
  strokeOpacity?: number
42
46
  /**
43
47
  * textStroke may be set as some color as a default
44
- * value in upper applicaion, where the default value
48
+ * value in upper application, where the default value
45
49
  * of lineWidth should be 0 to make sure that
46
50
  * user can choose to do not use text stroke.
47
51
  */
@@ -92,6 +96,7 @@ export interface TextStylePropsPart {
92
96
  /**
93
97
  * Width of text block. Not include padding
94
98
  * Used for background, truncate, wrap
99
+ * If string - be 'auto'.
95
100
  */
96
101
  width?: number | string
97
102
  /**
@@ -100,7 +105,7 @@ export interface TextStylePropsPart {
100
105
  */
101
106
  height?: number
102
107
  /**
103
- * Reserved for special functinality, like 'hr'.
108
+ * Reserved for special functionality, like 'hr'.
104
109
  */
105
110
  tag?: string
106
111
 
@@ -121,7 +126,7 @@ export interface TextStylePropsPart {
121
126
  /**
122
127
  * Margin of label. Used when layouting the label.
123
128
  */
124
- margin?: number
129
+ margin?: number | number[]
125
130
 
126
131
  borderColor?: string
127
132
  borderWidth?: number
@@ -148,6 +153,10 @@ export interface TextStyleProps extends TextStylePropsPart {
148
153
 
149
154
  text?: string
150
155
 
156
+ /**
157
+ * The outer rect (including padding) is placed based on x/y.
158
+ * By default 0.
159
+ */
151
160
  x?: number
152
161
  y?: number
153
162
 
@@ -155,6 +164,7 @@ export interface TextStyleProps extends TextStylePropsPart {
155
164
  * Only support number in the top block.
156
165
  */
157
166
  width?: number
167
+
158
168
  /**
159
169
  * Text styles for rich text.
160
170
  */
@@ -204,6 +214,9 @@ export type TextState = Pick<TextProps, DisplayableStatePropNames> & ElementComm
204
214
 
205
215
  export type DefaultTextStyle = Pick<TextStyleProps, 'fill' | 'stroke' | 'align' | 'verticalAlign'> & {
206
216
  autoStroke?: boolean
217
+ // In text local coord.
218
+ // Exist if and only if `ElementTextConfig['autoOverflowArea']: true`
219
+ overflowRect?: BoundingRect | NullUndefined
207
220
  };
208
221
 
209
222
  const DEFAULT_RICH_TEXT_COLOR = {
@@ -211,6 +224,8 @@ const DEFAULT_RICH_TEXT_COLOR = {
211
224
  };
212
225
  const DEFAULT_STROKE_LINE_WIDTH = 2;
213
226
 
227
+ const tmpCITOverflowAreaOut = {} as CalcInnerTextOverflowAreaOut;
228
+
214
229
  // const DEFAULT_TEXT_STYLE: TextStyleProps = {
215
230
  // x: 0,
216
231
  // y: 0,
@@ -270,7 +285,7 @@ class ZRText extends Displayable<TextProps> implements GroupLike {
270
285
 
271
286
  /**
272
287
  * Will use this to calculate transform matrix
273
- * instead of Element itseelf if it's give.
288
+ * instead of Element itself if it's give.
274
289
  * Not exposed to developers
275
290
  */
276
291
  innerTransformable: Transformable
@@ -489,8 +504,25 @@ class ZRText extends Displayable<TextProps> implements GroupLike {
489
504
  const textFont = style.font || DEFAULT_FONT;
490
505
  const textPadding = style.padding as number[];
491
506
 
507
+ const defaultStyle = this._defaultStyle;
508
+ let baseX = style.x || 0;
509
+ let baseY = style.y || 0;
510
+ const textAlign = style.align || defaultStyle.align || 'left';
511
+ const verticalAlign = style.verticalAlign || defaultStyle.verticalAlign || 'top';
512
+
513
+ calcInnerTextOverflowArea(
514
+ tmpCITOverflowAreaOut, defaultStyle.overflowRect, baseX, baseY, textAlign, verticalAlign
515
+ );
516
+ baseX = tmpCITOverflowAreaOut.baseX;
517
+ baseY = tmpCITOverflowAreaOut.baseY;
518
+
492
519
  const text = getStyleText(style);
493
- const contentBlock = parsePlainText(text, style);
520
+ const contentBlock = parsePlainText(
521
+ text,
522
+ style,
523
+ tmpCITOverflowAreaOut.outerWidth,
524
+ tmpCITOverflowAreaOut.outerHeight
525
+ );
494
526
  const needDrawBg = needDrawBackground(style);
495
527
  const bgColorDrawn = !!(style.backgroundColor);
496
528
 
@@ -501,15 +533,8 @@ class ZRText extends Displayable<TextProps> implements GroupLike {
501
533
  const textLines = contentBlock.lines;
502
534
  const lineHeight = contentBlock.lineHeight;
503
535
 
504
- const defaultStyle = this._defaultStyle;
505
-
506
536
  this.isTruncated = !!contentBlock.isTruncated;
507
537
 
508
- const baseX = style.x || 0;
509
- const baseY = style.y || 0;
510
- const textAlign = style.align || defaultStyle.align || 'left';
511
- const verticalAlign = style.verticalAlign || defaultStyle.verticalAlign || 'top';
512
-
513
538
  let textX = baseX;
514
539
  let textY = adjustTextY(baseY, contentBlock.contentHeight, verticalAlign);
515
540
 
@@ -627,22 +652,34 @@ class ZRText extends Displayable<TextProps> implements GroupLike {
627
652
 
628
653
  private _updateRichTexts() {
629
654
  const style = this.style;
655
+ const defaultStyle = this._defaultStyle;
656
+
657
+ const textAlign = style.align || defaultStyle.align;
658
+ const verticalAlign = style.verticalAlign || defaultStyle.verticalAlign;
659
+ let baseX = style.x || 0;
660
+ let baseY = style.y || 0;
661
+
662
+ calcInnerTextOverflowArea(
663
+ tmpCITOverflowAreaOut, defaultStyle.overflowRect, baseX, baseY, textAlign, verticalAlign
664
+ );
665
+ baseX = tmpCITOverflowAreaOut.baseX;
666
+ baseY = tmpCITOverflowAreaOut.baseY;
630
667
 
631
668
  // TODO Only parse when text changed?
632
669
  const text = getStyleText(style);
633
- const contentBlock = parseRichText(text, style);
670
+ const contentBlock = parseRichText(
671
+ text,
672
+ style,
673
+ tmpCITOverflowAreaOut.outerWidth,
674
+ tmpCITOverflowAreaOut.outerHeight,
675
+ textAlign
676
+ );
634
677
 
635
678
  const contentWidth = contentBlock.width;
636
679
  const outerWidth = contentBlock.outerWidth;
637
680
  const outerHeight = contentBlock.outerHeight;
638
681
  const textPadding = style.padding as number[];
639
682
 
640
- const baseX = style.x || 0;
641
- const baseY = style.y || 0;
642
- const defaultStyle = this._defaultStyle;
643
- const textAlign = style.align || defaultStyle.align;
644
- const verticalAlign = style.verticalAlign || defaultStyle.verticalAlign;
645
-
646
683
  this.isTruncated = !!contentBlock.isTruncated;
647
684
 
648
685
  const boxX = adjustTextX(baseX, outerWidth, textAlign);