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
@@ -2,14 +2,22 @@ import * as matrix from './matrix.js';
2
2
  import Point from './Point.js';
3
3
  var mathMin = Math.min;
4
4
  var mathMax = Math.max;
5
+ var mathAbs = Math.abs;
6
+ var XY = ['x', 'y'];
7
+ var WH = ['width', 'height'];
5
8
  var lt = new Point();
6
9
  var rb = new Point();
7
10
  var lb = new Point();
8
11
  var rt = new Point();
9
- var minTv = new Point();
10
- var maxTv = new Point();
12
+ var _intersectCtx = createIntersectContext();
13
+ var _minTv = _intersectCtx.minTv;
14
+ var _maxTv = _intersectCtx.maxTv;
15
+ var _lenMinMax = [0, 0];
11
16
  var BoundingRect = (function () {
12
17
  function BoundingRect(x, y, width, height) {
18
+ BoundingRect.set(this, x, y, width, height);
19
+ }
20
+ BoundingRect.set = function (target, x, y, width, height) {
13
21
  if (width < 0) {
14
22
  x = x + width;
15
23
  width = -width;
@@ -18,11 +26,12 @@ var BoundingRect = (function () {
18
26
  y = y + height;
19
27
  height = -height;
20
28
  }
21
- this.x = x;
22
- this.y = y;
23
- this.width = width;
24
- this.height = height;
25
- }
29
+ target.x = x;
30
+ target.y = y;
31
+ target.width = width;
32
+ target.height = height;
33
+ return target;
34
+ };
26
35
  BoundingRect.prototype.union = function (other) {
27
36
  var x = mathMin(other.x, this.x);
28
37
  var y = mathMin(other.y, this.y);
@@ -54,89 +63,64 @@ var BoundingRect = (function () {
54
63
  matrix.translate(m, m, [b.x, b.y]);
55
64
  return m;
56
65
  };
57
- BoundingRect.prototype.intersect = function (b, mtv) {
58
- if (!b) {
66
+ BoundingRect.prototype.intersect = function (b, mtv, opt) {
67
+ return BoundingRect.intersect(this, b, mtv, opt);
68
+ };
69
+ BoundingRect.intersect = function (a, b, mtv, opt) {
70
+ if (mtv) {
71
+ Point.set(mtv, 0, 0);
72
+ }
73
+ var outIntersectRect = opt && opt.outIntersectRect || null;
74
+ var clamp = opt && opt.clamp;
75
+ if (outIntersectRect) {
76
+ outIntersectRect.x = outIntersectRect.y = outIntersectRect.width = outIntersectRect.height = NaN;
77
+ }
78
+ if (!a || !b) {
59
79
  return false;
60
80
  }
81
+ if (!(a instanceof BoundingRect)) {
82
+ a = BoundingRect.set(_tmpIntersectA, a.x, a.y, a.width, a.height);
83
+ }
61
84
  if (!(b instanceof BoundingRect)) {
62
- b = BoundingRect.create(b);
85
+ b = BoundingRect.set(_tmpIntersectB, b.x, b.y, b.width, b.height);
86
+ }
87
+ var useMTV = !!mtv;
88
+ _intersectCtx.reset(opt, useMTV);
89
+ var touchThreshold = _intersectCtx.touchThreshold;
90
+ var ax0 = a.x + touchThreshold;
91
+ var ax1 = a.x + a.width - touchThreshold;
92
+ var ay0 = a.y + touchThreshold;
93
+ var ay1 = a.y + a.height - touchThreshold;
94
+ var bx0 = b.x + touchThreshold;
95
+ var bx1 = b.x + b.width - touchThreshold;
96
+ var by0 = b.y + touchThreshold;
97
+ var by1 = b.y + b.height - touchThreshold;
98
+ if (ax0 > ax1 || ay0 > ay1 || bx0 > bx1 || by0 > by1) {
99
+ return false;
63
100
  }
64
- var a = this;
65
- var ax0 = a.x;
66
- var ax1 = a.x + a.width;
67
- var ay0 = a.y;
68
- var ay1 = a.y + a.height;
69
- var bx0 = b.x;
70
- var bx1 = b.x + b.width;
71
- var by0 = b.y;
72
- var by1 = b.y + b.height;
73
101
  var overlap = !(ax1 < bx0 || bx1 < ax0 || ay1 < by0 || by1 < ay0);
74
- if (mtv) {
75
- var dMin = Infinity;
76
- var dMax = 0;
77
- var d0 = Math.abs(ax1 - bx0);
78
- var d1 = Math.abs(bx1 - ax0);
79
- var d2 = Math.abs(ay1 - by0);
80
- var d3 = Math.abs(by1 - ay0);
81
- var dx = Math.min(d0, d1);
82
- var dy = Math.min(d2, d3);
83
- if (ax1 < bx0 || bx1 < ax0) {
84
- if (dx > dMax) {
85
- dMax = dx;
86
- if (d0 < d1) {
87
- Point.set(maxTv, -d0, 0);
88
- }
89
- else {
90
- Point.set(maxTv, d1, 0);
91
- }
92
- }
93
- }
94
- else {
95
- if (dx < dMin) {
96
- dMin = dx;
97
- if (d0 < d1) {
98
- Point.set(minTv, d0, 0);
99
- }
100
- else {
101
- Point.set(minTv, -d1, 0);
102
- }
103
- }
102
+ if (useMTV || outIntersectRect) {
103
+ _lenMinMax[0] = Infinity;
104
+ _lenMinMax[1] = 0;
105
+ intersectOneDim(ax0, ax1, bx0, bx1, 0, useMTV, outIntersectRect, clamp);
106
+ intersectOneDim(ay0, ay1, by0, by1, 1, useMTV, outIntersectRect, clamp);
107
+ if (useMTV) {
108
+ Point.copy(mtv, overlap
109
+ ? (_intersectCtx.useDir ? _intersectCtx.dirMinTv : _minTv)
110
+ : _maxTv);
104
111
  }
105
- if (ay1 < by0 || by1 < ay0) {
106
- if (dy > dMax) {
107
- dMax = dy;
108
- if (d2 < d3) {
109
- Point.set(maxTv, 0, -d2);
110
- }
111
- else {
112
- Point.set(maxTv, 0, d3);
113
- }
114
- }
115
- }
116
- else {
117
- if (dx < dMin) {
118
- dMin = dx;
119
- if (d2 < d3) {
120
- Point.set(minTv, 0, d2);
121
- }
122
- else {
123
- Point.set(minTv, 0, -d3);
124
- }
125
- }
126
- }
127
- }
128
- if (mtv) {
129
- Point.copy(mtv, overlap ? minTv : maxTv);
130
112
  }
131
113
  return overlap;
132
114
  };
133
- BoundingRect.prototype.contain = function (x, y) {
134
- var rect = this;
115
+ BoundingRect.contain = function (rect, x, y) {
135
116
  return x >= rect.x
136
117
  && x <= (rect.x + rect.width)
137
118
  && y >= rect.y
138
119
  && y <= (rect.y + rect.height);
139
120
  };
121
+ BoundingRect.prototype.contain = function (x, y) {
122
+ return BoundingRect.contain(this, x, y);
123
+ };
140
124
  BoundingRect.prototype.clone = function () {
141
125
  return new BoundingRect(this.x, this.y, this.width, this.height);
142
126
  };
@@ -168,6 +152,7 @@ var BoundingRect = (function () {
168
152
  target.y = source.y;
169
153
  target.width = source.width;
170
154
  target.height = source.height;
155
+ return target;
171
156
  };
172
157
  BoundingRect.applyTransform = function (target, source, m) {
173
158
  if (!m) {
@@ -212,4 +197,125 @@ var BoundingRect = (function () {
212
197
  };
213
198
  return BoundingRect;
214
199
  }());
200
+ var _tmpIntersectA = new BoundingRect(0, 0, 0, 0);
201
+ var _tmpIntersectB = new BoundingRect(0, 0, 0, 0);
202
+ function intersectOneDim(a0, a1, b0, b1, updateDimIdx, useMTV, outIntersectRect, clamp) {
203
+ var d0 = mathAbs(a1 - b0);
204
+ var d1 = mathAbs(b1 - a0);
205
+ var d01min = mathMin(d0, d1);
206
+ var updateDim = XY[updateDimIdx];
207
+ var zeroDim = XY[1 - updateDimIdx];
208
+ var wh = WH[updateDimIdx];
209
+ if (a1 < b0 || b1 < a0) {
210
+ if (d0 < d1) {
211
+ if (useMTV) {
212
+ _maxTv[updateDim] = -d0;
213
+ }
214
+ if (clamp) {
215
+ outIntersectRect[updateDim] = a1;
216
+ outIntersectRect[wh] = 0;
217
+ }
218
+ }
219
+ else {
220
+ if (useMTV) {
221
+ _maxTv[updateDim] = d1;
222
+ }
223
+ if (clamp) {
224
+ outIntersectRect[updateDim] = a0;
225
+ outIntersectRect[wh] = 0;
226
+ }
227
+ }
228
+ }
229
+ else {
230
+ if (outIntersectRect) {
231
+ outIntersectRect[updateDim] = mathMax(a0, b0);
232
+ outIntersectRect[wh] = mathMin(a1, b1) - outIntersectRect[updateDim];
233
+ }
234
+ if (useMTV) {
235
+ if (d01min < _lenMinMax[0] || _intersectCtx.useDir) {
236
+ _lenMinMax[0] = mathMin(d01min, _lenMinMax[0]);
237
+ if (d0 < d1 || !_intersectCtx.bidirectional) {
238
+ _minTv[updateDim] = d0;
239
+ _minTv[zeroDim] = 0;
240
+ if (_intersectCtx.useDir) {
241
+ _intersectCtx.calcDirMTV();
242
+ }
243
+ }
244
+ if (d0 >= d1 || !_intersectCtx.bidirectional) {
245
+ _minTv[updateDim] = -d1;
246
+ _minTv[zeroDim] = 0;
247
+ if (_intersectCtx.useDir) {
248
+ _intersectCtx.calcDirMTV();
249
+ }
250
+ }
251
+ }
252
+ }
253
+ }
254
+ }
255
+ export function createIntersectContext() {
256
+ var _direction = 0;
257
+ var _dirCheckVec = new Point();
258
+ var _dirTmp = new Point();
259
+ var _ctx = {
260
+ minTv: new Point(),
261
+ maxTv: new Point(),
262
+ useDir: false,
263
+ dirMinTv: new Point(),
264
+ touchThreshold: 0,
265
+ bidirectional: true,
266
+ negativeSize: false,
267
+ reset: function (opt, useMTV) {
268
+ _ctx.touchThreshold = 0;
269
+ if (opt && opt.touchThreshold != null) {
270
+ _ctx.touchThreshold = mathMax(0, opt.touchThreshold);
271
+ }
272
+ _ctx.negativeSize = false;
273
+ if (!useMTV) {
274
+ return;
275
+ }
276
+ _ctx.minTv.set(Infinity, Infinity);
277
+ _ctx.maxTv.set(0, 0);
278
+ _ctx.useDir = false;
279
+ if (opt && opt.direction != null) {
280
+ _ctx.useDir = true;
281
+ _ctx.dirMinTv.copy(_ctx.minTv);
282
+ _dirTmp.copy(_ctx.minTv);
283
+ _direction = opt.direction;
284
+ _ctx.bidirectional = opt.bidirectional == null || !!opt.bidirectional;
285
+ if (!_ctx.bidirectional) {
286
+ _dirCheckVec.set(Math.cos(_direction), Math.sin(_direction));
287
+ }
288
+ }
289
+ },
290
+ calcDirMTV: function () {
291
+ var minTv = _ctx.minTv;
292
+ var dirMinTv = _ctx.dirMinTv;
293
+ var squareMag = minTv.y * minTv.y + minTv.x * minTv.x;
294
+ var dirSin = Math.sin(_direction);
295
+ var dirCos = Math.cos(_direction);
296
+ var dotProd = dirSin * minTv.y + dirCos * minTv.x;
297
+ if (nearZero(dotProd)) {
298
+ if (nearZero(minTv.x) && nearZero(minTv.y)) {
299
+ dirMinTv.set(0, 0);
300
+ }
301
+ return;
302
+ }
303
+ _dirTmp.x = squareMag * dirCos / dotProd;
304
+ _dirTmp.y = squareMag * dirSin / dotProd;
305
+ if (nearZero(_dirTmp.x) && nearZero(_dirTmp.y)) {
306
+ dirMinTv.set(0, 0);
307
+ return;
308
+ }
309
+ if ((_ctx.bidirectional
310
+ || _dirCheckVec.dot(_dirTmp) > 0)
311
+ && _dirTmp.len() < dirMinTv.len()) {
312
+ dirMinTv.copy(_dirTmp);
313
+ }
314
+ }
315
+ };
316
+ function nearZero(val) {
317
+ return mathAbs(val) < 1e-10;
318
+ }
319
+ return _ctx;
320
+ }
215
321
  export default BoundingRect;
@@ -1,5 +1,5 @@
1
1
  import { PointLike } from './Point';
2
- import BoundingRect from './BoundingRect';
2
+ import BoundingRect, { BoundingRectIntersectOpt } from './BoundingRect';
3
3
  import { MatrixArray } from './matrix';
4
4
  declare class OrientedBoundingRect {
5
5
  private _corners;
@@ -7,7 +7,7 @@ declare class OrientedBoundingRect {
7
7
  private _origin;
8
8
  constructor(rect?: BoundingRect, transform?: MatrixArray);
9
9
  fromBoundingRect(rect: BoundingRect, transform?: MatrixArray): void;
10
- intersect(other: OrientedBoundingRect, mtv?: PointLike): boolean;
10
+ intersect(other: OrientedBoundingRect, mtv?: PointLike, opt?: BoundingRectIntersectOpt): boolean;
11
11
  private _intersectCheckOneSide;
12
12
  private _getProjMinMaxOnAxis;
13
13
  }
@@ -1,8 +1,13 @@
1
1
  import Point from './Point.js';
2
- var extent = [0, 0];
3
- var extent2 = [0, 0];
4
- var minTv = new Point();
5
- var maxTv = new Point();
2
+ import { createIntersectContext } from './BoundingRect.js';
3
+ var mathMin = Math.min;
4
+ var mathMax = Math.max;
5
+ var mathAbs = Math.abs;
6
+ var _extent = [0, 0];
7
+ var _extent2 = [0, 0];
8
+ var _intersectCtx = createIntersectContext();
9
+ var _minTv = _intersectCtx.minTv;
10
+ var _maxTv = _intersectCtx.maxTv;
6
11
  var OrientedBoundingRect = (function () {
7
12
  function OrientedBoundingRect(rect, transform) {
8
13
  this._corners = [];
@@ -42,59 +47,69 @@ var OrientedBoundingRect = (function () {
42
47
  this._origin[i] = axes[i].dot(corners[0]);
43
48
  }
44
49
  };
45
- OrientedBoundingRect.prototype.intersect = function (other, mtv) {
50
+ OrientedBoundingRect.prototype.intersect = function (other, mtv, opt) {
46
51
  var overlapped = true;
47
52
  var noMtv = !mtv;
48
- minTv.set(Infinity, Infinity);
49
- maxTv.set(0, 0);
50
- if (!this._intersectCheckOneSide(this, other, minTv, maxTv, noMtv, 1)) {
53
+ if (mtv) {
54
+ Point.set(mtv, 0, 0);
55
+ }
56
+ _intersectCtx.reset(opt, !noMtv);
57
+ if (!this._intersectCheckOneSide(this, other, noMtv, 1)) {
51
58
  overlapped = false;
52
59
  if (noMtv) {
53
60
  return overlapped;
54
61
  }
55
62
  }
56
- if (!this._intersectCheckOneSide(other, this, minTv, maxTv, noMtv, -1)) {
63
+ if (!this._intersectCheckOneSide(other, this, noMtv, -1)) {
57
64
  overlapped = false;
58
65
  if (noMtv) {
59
66
  return overlapped;
60
67
  }
61
68
  }
62
- if (!noMtv) {
63
- Point.copy(mtv, overlapped ? minTv : maxTv);
69
+ if (!noMtv && !_intersectCtx.negativeSize) {
70
+ Point.copy(mtv, overlapped
71
+ ? (_intersectCtx.useDir ? _intersectCtx.dirMinTv : _minTv)
72
+ : _maxTv);
64
73
  }
65
74
  return overlapped;
66
75
  };
67
- OrientedBoundingRect.prototype._intersectCheckOneSide = function (self, other, minTv, maxTv, noMtv, inverse) {
76
+ OrientedBoundingRect.prototype._intersectCheckOneSide = function (self, other, noMtv, inverse) {
68
77
  var overlapped = true;
69
78
  for (var i = 0; i < 2; i++) {
70
- var axis = this._axes[i];
71
- this._getProjMinMaxOnAxis(i, self._corners, extent);
72
- this._getProjMinMaxOnAxis(i, other._corners, extent2);
73
- if (extent[1] < extent2[0] || extent[0] > extent2[1]) {
79
+ var axis = self._axes[i];
80
+ self._getProjMinMaxOnAxis(i, self._corners, _extent);
81
+ self._getProjMinMaxOnAxis(i, other._corners, _extent2);
82
+ if (_intersectCtx.negativeSize || _extent[1] < _extent2[0] || _extent[0] > _extent2[1]) {
74
83
  overlapped = false;
75
- if (noMtv) {
84
+ if (_intersectCtx.negativeSize || noMtv) {
76
85
  return overlapped;
77
86
  }
78
- var dist0 = Math.abs(extent2[0] - extent[1]);
79
- var dist1 = Math.abs(extent[0] - extent2[1]);
80
- if (Math.min(dist0, dist1) > maxTv.len()) {
87
+ var dist0 = mathAbs(_extent2[0] - _extent[1]);
88
+ var dist1 = mathAbs(_extent[0] - _extent2[1]);
89
+ if (mathMin(dist0, dist1) > _maxTv.len()) {
81
90
  if (dist0 < dist1) {
82
- Point.scale(maxTv, axis, -dist0 * inverse);
91
+ Point.scale(_maxTv, axis, -dist0 * inverse);
83
92
  }
84
93
  else {
85
- Point.scale(maxTv, axis, dist1 * inverse);
94
+ Point.scale(_maxTv, axis, dist1 * inverse);
86
95
  }
87
96
  }
88
97
  }
89
- else if (minTv) {
90
- var dist0 = Math.abs(extent2[0] - extent[1]);
91
- var dist1 = Math.abs(extent[0] - extent2[1]);
92
- if (Math.min(dist0, dist1) < minTv.len()) {
93
- if (dist0 < dist1) {
94
- Point.scale(minTv, axis, dist0 * inverse);
98
+ else if (!noMtv) {
99
+ var dist0 = mathAbs(_extent2[0] - _extent[1]);
100
+ var dist1 = mathAbs(_extent[0] - _extent2[1]);
101
+ if (_intersectCtx.useDir || mathMin(dist0, dist1) < _minTv.len()) {
102
+ if (dist0 < dist1 || !_intersectCtx.bidirectional) {
103
+ Point.scale(_minTv, axis, dist0 * inverse);
104
+ if (_intersectCtx.useDir) {
105
+ _intersectCtx.calcDirMTV();
106
+ }
95
107
  }
96
- else {
97
- Point.scale(minTv, axis, -dist1 * inverse);
108
+ if (dist0 >= dist1 || !_intersectCtx.bidirectional) {
109
+ Point.scale(_minTv, axis, -dist1 * inverse);
110
+ if (_intersectCtx.useDir) {
111
+ _intersectCtx.calcDirMTV();
112
+ }
98
113
  }
99
114
  }
100
115
  }
@@ -109,11 +124,12 @@ var OrientedBoundingRect = (function () {
109
124
  var max = proj;
110
125
  for (var i = 1; i < corners.length; i++) {
111
126
  var proj_1 = corners[i].dot(axis) + origin[dim];
112
- min = Math.min(proj_1, min);
113
- max = Math.max(proj_1, max);
127
+ min = mathMin(proj_1, min);
128
+ max = mathMax(proj_1, max);
114
129
  }
115
- out[0] = min;
116
- out[1] = max;
130
+ out[0] = min + _intersectCtx.touchThreshold;
131
+ out[1] = max - _intersectCtx.touchThreshold;
132
+ _intersectCtx.negativeSize = out[1] < out[0];
117
133
  };
118
134
  return OrientedBoundingRect;
119
135
  }());
@@ -60,6 +60,7 @@ export default class PathProxy {
60
60
  private _calculateLength;
61
61
  rebuildPath(ctx: PathRebuilder, percent: number): void;
62
62
  clone(): PathProxy;
63
+ canSave(): boolean;
63
64
  private static initDefaultProps;
64
65
  }
65
66
  export interface PathRebuilder {
@@ -211,6 +211,9 @@ var PathProxy = (function () {
211
211
  return this._len;
212
212
  };
213
213
  PathProxy.prototype.setData = function (data) {
214
+ if (!this._saveData) {
215
+ return;
216
+ }
214
217
  var len = data.length;
215
218
  if (!(this.data && this.data.length === len) && hasTypedArray) {
216
219
  this.data = new Float32Array(len);
@@ -221,6 +224,9 @@ var PathProxy = (function () {
221
224
  this._len = len;
222
225
  };
223
226
  PathProxy.prototype.appendPath = function (path) {
227
+ if (!this._saveData) {
228
+ return;
229
+ }
224
230
  if (!(path instanceof Array)) {
225
231
  path = [path];
226
232
  }
@@ -230,8 +236,14 @@ var PathProxy = (function () {
230
236
  for (var i = 0; i < len; i++) {
231
237
  appendSize += path[i].len();
232
238
  }
233
- if (hasTypedArray && (this.data instanceof Float32Array)) {
239
+ var oldData = this.data;
240
+ if (hasTypedArray && (oldData instanceof Float32Array || !oldData)) {
234
241
  this.data = new Float32Array(offset + appendSize);
242
+ if (offset > 0 && oldData) {
243
+ for (var k = 0; k < offset; k++) {
244
+ this.data[k] = oldData[k];
245
+ }
246
+ }
235
247
  }
236
248
  for (var i = 0; i < len; i++) {
237
249
  var appendPathData = path[i].data;
@@ -683,6 +695,9 @@ var PathProxy = (function () {
683
695
  newProxy._len = this._len;
684
696
  return newProxy;
685
697
  };
698
+ PathProxy.prototype.canSave = function () {
699
+ return !!this._saveData;
700
+ };
686
701
  PathProxy.CMD = CMD;
687
702
  PathProxy.initDefaultProps = (function () {
688
703
  var proto = PathProxy.prototype;
@@ -5,6 +5,7 @@ export declare type ArrayLike<T> = {
5
5
  [key: number]: T;
6
6
  length: number;
7
7
  };
8
+ export declare type NullUndefined = null | undefined;
8
9
  export declare type ImageLike = HTMLImageElement | HTMLCanvasElement | HTMLVideoElement;
9
10
  export declare type TextVerticalAlign = 'top' | 'middle' | 'bottom';
10
11
  export declare type TextAlign = 'left' | 'center' | 'right';
@@ -97,3 +97,4 @@ export declare function disableUserSelect(dom: HTMLElement): void;
97
97
  export declare function hasOwn(own: object, prop: string): boolean;
98
98
  export declare function noop(): void;
99
99
  export declare const RADIAN_TO_DEGREE: number;
100
+ export declare const EPSILON: number;
package/lib/core/util.js CHANGED
@@ -540,3 +540,4 @@ export function hasOwn(own, prop) {
540
540
  }
541
541
  export function noop() { }
542
542
  export var RADIAN_TO_DEGREE = 180 / Math.PI;
543
+ export var EPSILON = Number.EPSILON || Math.pow(2, -52);
@@ -58,7 +58,7 @@ var Displayable = (function (_super) {
58
58
  || (m && !m[0] && !m[3])) {
59
59
  return false;
60
60
  }
61
- if (considerClipPath && this.__clipPaths) {
61
+ if (considerClipPath && this.__clipPaths && this.__clipPaths.length) {
62
62
  for (var i = 0; i < this.__clipPaths.length; ++i) {
63
63
  if (this.__clipPaths[i].isZeroArea()) {
64
64
  return false;
@@ -1,4 +1,4 @@
1
- import { TextAlign, TextVerticalAlign, ImageLike, Dictionary, MapToType, FontWeight, FontStyle } from '../core/types';
1
+ import { TextAlign, TextVerticalAlign, ImageLike, Dictionary, MapToType, FontWeight, FontStyle, NullUndefined } from '../core/types';
2
2
  import TSpan from './TSpan';
3
3
  import ZRImage from './Image';
4
4
  import Rect from './shape/Rect';
@@ -43,7 +43,7 @@ export interface TextStylePropsPart {
43
43
  image: ImageLike | string;
44
44
  };
45
45
  padding?: number | number[];
46
- margin?: number;
46
+ margin?: number | number[];
47
47
  borderColor?: string;
48
48
  borderWidth?: number;
49
49
  borderRadius?: number | number[];
@@ -75,6 +75,7 @@ export interface TextProps extends DisplayableProps {
75
75
  export declare type TextState = Pick<TextProps, DisplayableStatePropNames> & ElementCommonState;
76
76
  export declare type DefaultTextStyle = Pick<TextStyleProps, 'fill' | 'stroke' | 'align' | 'verticalAlign'> & {
77
77
  autoStroke?: boolean;
78
+ overflowRect?: BoundingRect | NullUndefined;
78
79
  };
79
80
  export declare const DEFAULT_TEXT_ANIMATION_PROPS: MapToType<TextProps, boolean>;
80
81
  interface ZRText {
@@ -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,12 +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
206
  this.isTruncated = !!contentBlock.isTruncated;
199
- var baseX = style.x || 0;
200
- var baseY = style.y || 0;
201
- var textAlign = style.align || defaultStyle.align || 'left';
202
- var verticalAlign = style.verticalAlign || defaultStyle.verticalAlign || 'top';
203
207
  var textX = baseX;
204
208
  var textY = adjustTextY(baseY, contentBlock.contentHeight, verticalAlign);
205
209
  if (needDrawBg || textPadding) {
@@ -268,17 +272,20 @@ var ZRText = (function (_super) {
268
272
  };
269
273
  ZRText.prototype._updateRichTexts = function () {
270
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;
271
283
  var text = getStyleText(style);
272
- var contentBlock = parseRichText(text, style);
284
+ var contentBlock = parseRichText(text, style, tmpCITOverflowAreaOut.outerWidth, tmpCITOverflowAreaOut.outerHeight, textAlign);
273
285
  var contentWidth = contentBlock.width;
274
286
  var outerWidth = contentBlock.outerWidth;
275
287
  var outerHeight = contentBlock.outerHeight;
276
288
  var textPadding = style.padding;
277
- var baseX = style.x || 0;
278
- var baseY = style.y || 0;
279
- var defaultStyle = this._defaultStyle;
280
- var textAlign = style.align || defaultStyle.align;
281
- var verticalAlign = style.verticalAlign || defaultStyle.verticalAlign;
282
289
  this.isTruncated = !!contentBlock.isTruncated;
283
290
  var boxX = adjustTextX(baseX, outerWidth, textAlign);
284
291
  var boxY = adjustTextY(baseY, outerHeight, verticalAlign);
@@ -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;
@@ -19,7 +19,7 @@ export interface PlainTextContentBlock {
19
19
  lines: string[];
20
20
  isTruncated: boolean;
21
21
  }
22
- 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;
23
23
  declare class RichTextToken {
24
24
  styleName: string;
25
25
  text: string;
@@ -52,5 +52,12 @@ export declare class RichTextContentBlock {
52
52
  lines: RichTextLine[];
53
53
  isTruncated: boolean;
54
54
  }
55
- 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
+ };
56
63
  export {};