@antv/g-lite 2.3.1 → 2.4.0

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 (48) hide show
  1. package/dist/index.esm.js +362 -867
  2. package/dist/index.esm.js.map +1 -1
  3. package/dist/index.js +361 -867
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.umd.min.js +11 -11
  6. package/dist/index.umd.min.js.map +1 -1
  7. package/package.json +1 -3
  8. package/types/Canvas.d.ts.map +1 -1
  9. package/types/components/RBushNode.d.ts +10 -0
  10. package/types/components/RBushNode.d.ts.map +1 -1
  11. package/types/css/StyleValueRegistry.d.ts.map +1 -1
  12. package/types/display-objects/DisplayObject.d.ts +1 -2
  13. package/types/display-objects/DisplayObject.d.ts.map +1 -1
  14. package/types/display-objects/Text.d.ts +5 -0
  15. package/types/display-objects/Text.d.ts.map +1 -1
  16. package/types/dom/CustomEvent.d.ts +6 -3
  17. package/types/dom/CustomEvent.d.ts.map +1 -1
  18. package/types/dom/Document.d.ts +2 -3
  19. package/types/dom/Document.d.ts.map +1 -1
  20. package/types/dom/Element.d.ts +22 -8
  21. package/types/dom/Element.d.ts.map +1 -1
  22. package/types/dom/EventTarget.d.ts +2 -2
  23. package/types/dom/EventTarget.d.ts.map +1 -1
  24. package/types/dom/MutationEvent.d.ts +3 -0
  25. package/types/dom/MutationEvent.d.ts.map +1 -1
  26. package/types/dom/MutationObserver.d.ts +19 -0
  27. package/types/dom/MutationObserver.d.ts.map +1 -0
  28. package/types/dom/index.d.ts +1 -0
  29. package/types/dom/index.d.ts.map +1 -1
  30. package/types/dom/interfaces.d.ts +0 -3
  31. package/types/dom/interfaces.d.ts.map +1 -1
  32. package/types/index.d.ts +0 -2
  33. package/types/index.d.ts.map +1 -1
  34. package/types/plugins/PrepareRendererPlugin.d.ts +5 -6
  35. package/types/plugins/PrepareRendererPlugin.d.ts.map +1 -1
  36. package/types/services/RenderingService.d.ts +4 -3
  37. package/types/services/RenderingService.d.ts.map +1 -1
  38. package/types/services/SceneGraphService.d.ts +19 -9
  39. package/types/services/SceneGraphService.d.ts.map +1 -1
  40. package/types/services/TextService.d.ts +6 -0
  41. package/types/services/TextService.d.ts.map +1 -1
  42. package/types/services/interfaces.d.ts +4 -3
  43. package/types/services/interfaces.d.ts.map +1 -1
  44. package/types/utils/LRU.d.ts +36 -0
  45. package/types/utils/LRU.d.ts.map +1 -0
  46. package/types/utils/text.d.ts +1 -1
  47. package/types/utils/text.d.ts.map +1 -1
  48. package/types/utils/transform-mat4.d.ts.map +1 -1
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  /*!
2
2
  * @antv/g-lite
3
3
  * @description A core module for rendering engine implements DOM API.
4
- * @version 2.3.1
5
- * @date 7/18/2025, 7:12:41 AM
4
+ * @version 2.4.0
5
+ * @date 10/13/2025, 7:00:43 AM
6
6
  * @author AntVis
7
7
  * @docs https://g.antv.antgroup.com/
8
8
  */
@@ -27,586 +27,6 @@ var _asyncToGenerator = require('@babel/runtime/helpers/asyncToGenerator');
27
27
  var _createForOfIteratorHelper = require('@babel/runtime/helpers/createForOfIteratorHelper');
28
28
  var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
29
29
 
30
- var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
31
-
32
- var rbush = {exports: {}};
33
-
34
- (function (module, exports) {
35
- (function (global, factory) {
36
- module.exports = factory() ;
37
- }(commonjsGlobal, function () {
38
- function quickselect(arr, k, left, right, compare) {
39
- quickselectStep(arr, k, left || 0, right || (arr.length - 1), compare || defaultCompare);
40
- }
41
-
42
- function quickselectStep(arr, k, left, right, compare) {
43
-
44
- while (right > left) {
45
- if (right - left > 600) {
46
- var n = right - left + 1;
47
- var m = k - left + 1;
48
- var z = Math.log(n);
49
- var s = 0.5 * Math.exp(2 * z / 3);
50
- var sd = 0.5 * Math.sqrt(z * s * (n - s) / n) * (m - n / 2 < 0 ? -1 : 1);
51
- var newLeft = Math.max(left, Math.floor(k - m * s / n + sd));
52
- var newRight = Math.min(right, Math.floor(k + (n - m) * s / n + sd));
53
- quickselectStep(arr, k, newLeft, newRight, compare);
54
- }
55
-
56
- var t = arr[k];
57
- var i = left;
58
- var j = right;
59
-
60
- swap(arr, left, k);
61
- if (compare(arr[right], t) > 0) { swap(arr, left, right); }
62
-
63
- while (i < j) {
64
- swap(arr, i, j);
65
- i++;
66
- j--;
67
- while (compare(arr[i], t) < 0) { i++; }
68
- while (compare(arr[j], t) > 0) { j--; }
69
- }
70
-
71
- if (compare(arr[left], t) === 0) { swap(arr, left, j); }
72
- else {
73
- j++;
74
- swap(arr, j, right);
75
- }
76
-
77
- if (j <= k) { left = j + 1; }
78
- if (k <= j) { right = j - 1; }
79
- }
80
- }
81
-
82
- function swap(arr, i, j) {
83
- var tmp = arr[i];
84
- arr[i] = arr[j];
85
- arr[j] = tmp;
86
- }
87
-
88
- function defaultCompare(a, b) {
89
- return a < b ? -1 : a > b ? 1 : 0;
90
- }
91
-
92
- var RBush = function RBush(maxEntries) {
93
- if ( maxEntries === void 0 ) maxEntries = 9;
94
-
95
- // max entries in a node is 9 by default; min node fill is 40% for best performance
96
- this._maxEntries = Math.max(4, maxEntries);
97
- this._minEntries = Math.max(2, Math.ceil(this._maxEntries * 0.4));
98
- this.clear();
99
- };
100
-
101
- RBush.prototype.all = function all () {
102
- return this._all(this.data, []);
103
- };
104
-
105
- RBush.prototype.search = function search (bbox) {
106
- var node = this.data;
107
- var result = [];
108
-
109
- if (!intersects(bbox, node)) { return result; }
110
-
111
- var toBBox = this.toBBox;
112
- var nodesToSearch = [];
113
-
114
- while (node) {
115
- for (var i = 0; i < node.children.length; i++) {
116
- var child = node.children[i];
117
- var childBBox = node.leaf ? toBBox(child) : child;
118
-
119
- if (intersects(bbox, childBBox)) {
120
- if (node.leaf) { result.push(child); }
121
- else if (contains(bbox, childBBox)) { this._all(child, result); }
122
- else { nodesToSearch.push(child); }
123
- }
124
- }
125
- node = nodesToSearch.pop();
126
- }
127
-
128
- return result;
129
- };
130
-
131
- RBush.prototype.collides = function collides (bbox) {
132
- var node = this.data;
133
-
134
- if (!intersects(bbox, node)) { return false; }
135
-
136
- var nodesToSearch = [];
137
- while (node) {
138
- for (var i = 0; i < node.children.length; i++) {
139
- var child = node.children[i];
140
- var childBBox = node.leaf ? this.toBBox(child) : child;
141
-
142
- if (intersects(bbox, childBBox)) {
143
- if (node.leaf || contains(bbox, childBBox)) { return true; }
144
- nodesToSearch.push(child);
145
- }
146
- }
147
- node = nodesToSearch.pop();
148
- }
149
-
150
- return false;
151
- };
152
-
153
- RBush.prototype.load = function load (data) {
154
- if (!(data && data.length)) { return this; }
155
-
156
- if (data.length < this._minEntries) {
157
- for (var i = 0; i < data.length; i++) {
158
- this.insert(data[i]);
159
- }
160
- return this;
161
- }
162
-
163
- // recursively build the tree with the given data from scratch using OMT algorithm
164
- var node = this._build(data.slice(), 0, data.length - 1, 0);
165
-
166
- if (!this.data.children.length) {
167
- // save as is if tree is empty
168
- this.data = node;
169
-
170
- } else if (this.data.height === node.height) {
171
- // split root if trees have the same height
172
- this._splitRoot(this.data, node);
173
-
174
- } else {
175
- if (this.data.height < node.height) {
176
- // swap trees if inserted one is bigger
177
- var tmpNode = this.data;
178
- this.data = node;
179
- node = tmpNode;
180
- }
181
-
182
- // insert the small tree into the large tree at appropriate level
183
- this._insert(node, this.data.height - node.height - 1, true);
184
- }
185
-
186
- return this;
187
- };
188
-
189
- RBush.prototype.insert = function insert (item) {
190
- if (item) { this._insert(item, this.data.height - 1); }
191
- return this;
192
- };
193
-
194
- RBush.prototype.clear = function clear () {
195
- this.data = createNode([]);
196
- return this;
197
- };
198
-
199
- RBush.prototype.remove = function remove (item, equalsFn) {
200
- if (!item) { return this; }
201
-
202
- var node = this.data;
203
- var bbox = this.toBBox(item);
204
- var path = [];
205
- var indexes = [];
206
- var i, parent, goingUp;
207
-
208
- // depth-first iterative tree traversal
209
- while (node || path.length) {
210
-
211
- if (!node) { // go up
212
- node = path.pop();
213
- parent = path[path.length - 1];
214
- i = indexes.pop();
215
- goingUp = true;
216
- }
217
-
218
- if (node.leaf) { // check current node
219
- var index = findItem(item, node.children, equalsFn);
220
-
221
- if (index !== -1) {
222
- // item found, remove the item and condense tree upwards
223
- node.children.splice(index, 1);
224
- path.push(node);
225
- this._condense(path);
226
- return this;
227
- }
228
- }
229
-
230
- if (!goingUp && !node.leaf && contains(node, bbox)) { // go down
231
- path.push(node);
232
- indexes.push(i);
233
- i = 0;
234
- parent = node;
235
- node = node.children[0];
236
-
237
- } else if (parent) { // go right
238
- i++;
239
- node = parent.children[i];
240
- goingUp = false;
241
-
242
- } else { node = null; } // nothing found
243
- }
244
-
245
- return this;
246
- };
247
-
248
- RBush.prototype.toBBox = function toBBox (item) { return item; };
249
-
250
- RBush.prototype.compareMinX = function compareMinX (a, b) { return a.minX - b.minX; };
251
- RBush.prototype.compareMinY = function compareMinY (a, b) { return a.minY - b.minY; };
252
-
253
- RBush.prototype.toJSON = function toJSON () { return this.data; };
254
-
255
- RBush.prototype.fromJSON = function fromJSON (data) {
256
- this.data = data;
257
- return this;
258
- };
259
-
260
- RBush.prototype._all = function _all (node, result) {
261
- var nodesToSearch = [];
262
- while (node) {
263
- if (node.leaf) { result.push.apply(result, node.children); }
264
- else { nodesToSearch.push.apply(nodesToSearch, node.children); }
265
-
266
- node = nodesToSearch.pop();
267
- }
268
- return result;
269
- };
270
-
271
- RBush.prototype._build = function _build (items, left, right, height) {
272
-
273
- var N = right - left + 1;
274
- var M = this._maxEntries;
275
- var node;
276
-
277
- if (N <= M) {
278
- // reached leaf level; return leaf
279
- node = createNode(items.slice(left, right + 1));
280
- calcBBox(node, this.toBBox);
281
- return node;
282
- }
283
-
284
- if (!height) {
285
- // target height of the bulk-loaded tree
286
- height = Math.ceil(Math.log(N) / Math.log(M));
287
-
288
- // target number of root entries to maximize storage utilization
289
- M = Math.ceil(N / Math.pow(M, height - 1));
290
- }
291
-
292
- node = createNode([]);
293
- node.leaf = false;
294
- node.height = height;
295
-
296
- // split the items into M mostly square tiles
297
-
298
- var N2 = Math.ceil(N / M);
299
- var N1 = N2 * Math.ceil(Math.sqrt(M));
300
-
301
- multiSelect(items, left, right, N1, this.compareMinX);
302
-
303
- for (var i = left; i <= right; i += N1) {
304
-
305
- var right2 = Math.min(i + N1 - 1, right);
306
-
307
- multiSelect(items, i, right2, N2, this.compareMinY);
308
-
309
- for (var j = i; j <= right2; j += N2) {
310
-
311
- var right3 = Math.min(j + N2 - 1, right2);
312
-
313
- // pack each entry recursively
314
- node.children.push(this._build(items, j, right3, height - 1));
315
- }
316
- }
317
-
318
- calcBBox(node, this.toBBox);
319
-
320
- return node;
321
- };
322
-
323
- RBush.prototype._chooseSubtree = function _chooseSubtree (bbox, node, level, path) {
324
- while (true) {
325
- path.push(node);
326
-
327
- if (node.leaf || path.length - 1 === level) { break; }
328
-
329
- var minArea = Infinity;
330
- var minEnlargement = Infinity;
331
- var targetNode = (void 0);
332
-
333
- for (var i = 0; i < node.children.length; i++) {
334
- var child = node.children[i];
335
- var area = bboxArea(child);
336
- var enlargement = enlargedArea(bbox, child) - area;
337
-
338
- // choose entry with the least area enlargement
339
- if (enlargement < minEnlargement) {
340
- minEnlargement = enlargement;
341
- minArea = area < minArea ? area : minArea;
342
- targetNode = child;
343
-
344
- } else if (enlargement === minEnlargement) {
345
- // otherwise choose one with the smallest area
346
- if (area < minArea) {
347
- minArea = area;
348
- targetNode = child;
349
- }
350
- }
351
- }
352
-
353
- node = targetNode || node.children[0];
354
- }
355
-
356
- return node;
357
- };
358
-
359
- RBush.prototype._insert = function _insert (item, level, isNode) {
360
- var bbox = isNode ? item : this.toBBox(item);
361
- var insertPath = [];
362
-
363
- // find the best node for accommodating the item, saving all nodes along the path too
364
- var node = this._chooseSubtree(bbox, this.data, level, insertPath);
365
-
366
- // put the item into the node
367
- node.children.push(item);
368
- extend(node, bbox);
369
-
370
- // split on node overflow; propagate upwards if necessary
371
- while (level >= 0) {
372
- if (insertPath[level].children.length > this._maxEntries) {
373
- this._split(insertPath, level);
374
- level--;
375
- } else { break; }
376
- }
377
-
378
- // adjust bboxes along the insertion path
379
- this._adjustParentBBoxes(bbox, insertPath, level);
380
- };
381
-
382
- // split overflowed node into two
383
- RBush.prototype._split = function _split (insertPath, level) {
384
- var node = insertPath[level];
385
- var M = node.children.length;
386
- var m = this._minEntries;
387
-
388
- this._chooseSplitAxis(node, m, M);
389
-
390
- var splitIndex = this._chooseSplitIndex(node, m, M);
391
-
392
- var newNode = createNode(node.children.splice(splitIndex, node.children.length - splitIndex));
393
- newNode.height = node.height;
394
- newNode.leaf = node.leaf;
395
-
396
- calcBBox(node, this.toBBox);
397
- calcBBox(newNode, this.toBBox);
398
-
399
- if (level) { insertPath[level - 1].children.push(newNode); }
400
- else { this._splitRoot(node, newNode); }
401
- };
402
-
403
- RBush.prototype._splitRoot = function _splitRoot (node, newNode) {
404
- // split root node
405
- this.data = createNode([node, newNode]);
406
- this.data.height = node.height + 1;
407
- this.data.leaf = false;
408
- calcBBox(this.data, this.toBBox);
409
- };
410
-
411
- RBush.prototype._chooseSplitIndex = function _chooseSplitIndex (node, m, M) {
412
- var index;
413
- var minOverlap = Infinity;
414
- var minArea = Infinity;
415
-
416
- for (var i = m; i <= M - m; i++) {
417
- var bbox1 = distBBox(node, 0, i, this.toBBox);
418
- var bbox2 = distBBox(node, i, M, this.toBBox);
419
-
420
- var overlap = intersectionArea(bbox1, bbox2);
421
- var area = bboxArea(bbox1) + bboxArea(bbox2);
422
-
423
- // choose distribution with minimum overlap
424
- if (overlap < minOverlap) {
425
- minOverlap = overlap;
426
- index = i;
427
-
428
- minArea = area < minArea ? area : minArea;
429
-
430
- } else if (overlap === minOverlap) {
431
- // otherwise choose distribution with minimum area
432
- if (area < minArea) {
433
- minArea = area;
434
- index = i;
435
- }
436
- }
437
- }
438
-
439
- return index || M - m;
440
- };
441
-
442
- // sorts node children by the best axis for split
443
- RBush.prototype._chooseSplitAxis = function _chooseSplitAxis (node, m, M) {
444
- var compareMinX = node.leaf ? this.compareMinX : compareNodeMinX;
445
- var compareMinY = node.leaf ? this.compareMinY : compareNodeMinY;
446
- var xMargin = this._allDistMargin(node, m, M, compareMinX);
447
- var yMargin = this._allDistMargin(node, m, M, compareMinY);
448
-
449
- // if total distributions margin value is minimal for x, sort by minX,
450
- // otherwise it's already sorted by minY
451
- if (xMargin < yMargin) { node.children.sort(compareMinX); }
452
- };
453
-
454
- // total margin of all possible split distributions where each node is at least m full
455
- RBush.prototype._allDistMargin = function _allDistMargin (node, m, M, compare) {
456
- node.children.sort(compare);
457
-
458
- var toBBox = this.toBBox;
459
- var leftBBox = distBBox(node, 0, m, toBBox);
460
- var rightBBox = distBBox(node, M - m, M, toBBox);
461
- var margin = bboxMargin(leftBBox) + bboxMargin(rightBBox);
462
-
463
- for (var i = m; i < M - m; i++) {
464
- var child = node.children[i];
465
- extend(leftBBox, node.leaf ? toBBox(child) : child);
466
- margin += bboxMargin(leftBBox);
467
- }
468
-
469
- for (var i$1 = M - m - 1; i$1 >= m; i$1--) {
470
- var child$1 = node.children[i$1];
471
- extend(rightBBox, node.leaf ? toBBox(child$1) : child$1);
472
- margin += bboxMargin(rightBBox);
473
- }
474
-
475
- return margin;
476
- };
477
-
478
- RBush.prototype._adjustParentBBoxes = function _adjustParentBBoxes (bbox, path, level) {
479
- // adjust bboxes along the given tree path
480
- for (var i = level; i >= 0; i--) {
481
- extend(path[i], bbox);
482
- }
483
- };
484
-
485
- RBush.prototype._condense = function _condense (path) {
486
- // go through the path, removing empty nodes and updating bboxes
487
- for (var i = path.length - 1, siblings = (void 0); i >= 0; i--) {
488
- if (path[i].children.length === 0) {
489
- if (i > 0) {
490
- siblings = path[i - 1].children;
491
- siblings.splice(siblings.indexOf(path[i]), 1);
492
-
493
- } else { this.clear(); }
494
-
495
- } else { calcBBox(path[i], this.toBBox); }
496
- }
497
- };
498
-
499
- function findItem(item, items, equalsFn) {
500
- if (!equalsFn) { return items.indexOf(item); }
501
-
502
- for (var i = 0; i < items.length; i++) {
503
- if (equalsFn(item, items[i])) { return i; }
504
- }
505
- return -1;
506
- }
507
-
508
- // calculate node's bbox from bboxes of its children
509
- function calcBBox(node, toBBox) {
510
- distBBox(node, 0, node.children.length, toBBox, node);
511
- }
512
-
513
- // min bounding rectangle of node children from k to p-1
514
- function distBBox(node, k, p, toBBox, destNode) {
515
- if (!destNode) { destNode = createNode(null); }
516
- destNode.minX = Infinity;
517
- destNode.minY = Infinity;
518
- destNode.maxX = -Infinity;
519
- destNode.maxY = -Infinity;
520
-
521
- for (var i = k; i < p; i++) {
522
- var child = node.children[i];
523
- extend(destNode, node.leaf ? toBBox(child) : child);
524
- }
525
-
526
- return destNode;
527
- }
528
-
529
- function extend(a, b) {
530
- a.minX = Math.min(a.minX, b.minX);
531
- a.minY = Math.min(a.minY, b.minY);
532
- a.maxX = Math.max(a.maxX, b.maxX);
533
- a.maxY = Math.max(a.maxY, b.maxY);
534
- return a;
535
- }
536
-
537
- function compareNodeMinX(a, b) { return a.minX - b.minX; }
538
- function compareNodeMinY(a, b) { return a.minY - b.minY; }
539
-
540
- function bboxArea(a) { return (a.maxX - a.minX) * (a.maxY - a.minY); }
541
- function bboxMargin(a) { return (a.maxX - a.minX) + (a.maxY - a.minY); }
542
-
543
- function enlargedArea(a, b) {
544
- return (Math.max(b.maxX, a.maxX) - Math.min(b.minX, a.minX)) *
545
- (Math.max(b.maxY, a.maxY) - Math.min(b.minY, a.minY));
546
- }
547
-
548
- function intersectionArea(a, b) {
549
- var minX = Math.max(a.minX, b.minX);
550
- var minY = Math.max(a.minY, b.minY);
551
- var maxX = Math.min(a.maxX, b.maxX);
552
- var maxY = Math.min(a.maxY, b.maxY);
553
-
554
- return Math.max(0, maxX - minX) *
555
- Math.max(0, maxY - minY);
556
- }
557
-
558
- function contains(a, b) {
559
- return a.minX <= b.minX &&
560
- a.minY <= b.minY &&
561
- b.maxX <= a.maxX &&
562
- b.maxY <= a.maxY;
563
- }
564
-
565
- function intersects(a, b) {
566
- return b.minX <= a.maxX &&
567
- b.minY <= a.maxY &&
568
- b.maxX >= a.minX &&
569
- b.maxY >= a.minY;
570
- }
571
-
572
- function createNode(children) {
573
- return {
574
- children: children,
575
- height: 1,
576
- leaf: true,
577
- minX: Infinity,
578
- minY: Infinity,
579
- maxX: -Infinity,
580
- maxY: -Infinity
581
- };
582
- }
583
-
584
- // sort an array so that items come in groups of n unsorted items, with groups sorted between each other;
585
- // combines selection algorithm with binary divide & conquer approach
586
-
587
- function multiSelect(arr, left, right, n, compare) {
588
- var stack = [left, right];
589
-
590
- while (stack.length) {
591
- right = stack.pop();
592
- left = stack.pop();
593
-
594
- if (right - left <= n) { continue; }
595
-
596
- var mid = left + Math.ceil((right - left) / n / 2) * n;
597
- quickselect(arr, mid, left, right, compare);
598
-
599
- stack.push(left, mid, mid, right);
600
- }
601
- }
602
-
603
- return RBush;
604
-
605
- }));
606
- }(rbush));
607
-
608
- var RBush = rbush.exports;
609
-
610
30
  var Shape = /*#__PURE__*/function (Shape) {
611
31
  Shape["GROUP"] = "g";
612
32
  Shape["FRAGMENT"] = "fragment";
@@ -7083,7 +6503,6 @@ var DefaultStyleValueRegistry = /*#__PURE__*/function () {
7083
6503
  this.runtime.CSSPropertySyntaxFactory[PropertySyntax.TRANSFORM_ORIGIN].postProcessor(object);
7084
6504
  }
7085
6505
  if (needUpdateGeometry) {
7086
- object.geometry.dirty = true;
7087
6506
  object.dirty(true, true);
7088
6507
  if (!options.forceUpdateGeometry) {
7089
6508
  this.runtime.sceneGraphService.dirtyToRoot(object);
@@ -7893,9 +7312,9 @@ var AsyncSeriesWaterfallHook = /*#__PURE__*/function () {
7893
7312
  return (_this$callbacks = this.callbacks)[0].apply(_this$callbacks, _args);
7894
7313
  case 1:
7895
7314
  result = _context.sent;
7896
- i = 0;
7315
+ i = 1;
7897
7316
  case 2:
7898
- if (!(i < this.callbacks.length - 1)) {
7317
+ if (!(i < this.callbacks.length)) {
7899
7318
  _context.next = 5;
7900
7319
  break;
7901
7320
  }
@@ -7974,7 +7393,7 @@ var SyncWaterfallHook = /*#__PURE__*/function () {
7974
7393
  var argsArr = arguments;
7975
7394
  /* eslint-disable-next-line prefer-spread */
7976
7395
  var result = this.callbacks[0].apply(undefined, argsArr);
7977
- for (var i = 0; i < this.callbacks.length - 1; i++) {
7396
+ for (var i = 1; i < this.callbacks.length; i++) {
7978
7397
  var callback = this.callbacks[i];
7979
7398
  // @ts-ignore
7980
7399
  result = callback(result);
@@ -7988,7 +7407,7 @@ var SyncWaterfallHook = /*#__PURE__*/function () {
7988
7407
 
7989
7408
  var genericFontFamilies = ['serif', 'sans-serif', 'monospace', 'cursive', 'fantasy', 'system-ui'];
7990
7409
  var stringRegExp = /([\"\'])[^\'\"]+\1/;
7991
- function toFontString(attributes) {
7410
+ function getFontAttr(attributes) {
7992
7411
  var _attributes$fontSize = attributes.fontSize,
7993
7412
  fontSize = _attributes$fontSize === void 0 ? 16 : _attributes$fontSize,
7994
7413
  _attributes$fontFamil = attributes.fontFamily,
@@ -7999,6 +7418,21 @@ function toFontString(attributes) {
7999
7418
  fontVariant = _attributes$fontVaria === void 0 ? 'normal' : _attributes$fontVaria,
8000
7419
  _attributes$fontWeigh = attributes.fontWeight,
8001
7420
  fontWeight = _attributes$fontWeigh === void 0 ? 'normal' : _attributes$fontWeigh;
7421
+ return {
7422
+ fontSize: fontSize,
7423
+ fontFamily: fontFamily,
7424
+ fontStyle: fontStyle,
7425
+ fontVariant: fontVariant,
7426
+ fontWeight: fontWeight
7427
+ };
7428
+ }
7429
+ var toFontString = memoize(function toFontStringRaw(attributes) {
7430
+ var _getFontAttr = getFontAttr(attributes),
7431
+ fontSize = _getFontAttr.fontSize,
7432
+ fontFamily = _getFontAttr.fontFamily,
7433
+ fontStyle = _getFontAttr.fontStyle,
7434
+ fontVariant = _getFontAttr.fontVariant,
7435
+ fontWeight = _getFontAttr.fontWeight;
8002
7436
 
8003
7437
  // build canvas api font setting from individual components. Convert a numeric this.fontSize to px
8004
7438
  // const fontSizeString: string = isNumber(fontSize) ? `${fontSize}px` : fontSize.toString();
@@ -8017,8 +7451,27 @@ function toFontString(attributes) {
8017
7451
  fontFamilies[i] = _fontFamily;
8018
7452
  }
8019
7453
  return "".concat(fontStyle, " ").concat(fontVariant, " ").concat(fontWeight, " ").concat(fontSizeString, " ").concat(fontFamilies.join(','));
8020
- }
7454
+ }, function (attributes) {
7455
+ var _getFontAttr2 = getFontAttr(attributes),
7456
+ fontSize = _getFontAttr2.fontSize,
7457
+ fontFamily = _getFontAttr2.fontFamily,
7458
+ fontStyle = _getFontAttr2.fontStyle,
7459
+ fontVariant = _getFontAttr2.fontVariant,
7460
+ fontWeight = _getFontAttr2.fontWeight;
7461
+ return "".concat(fontStyle, "_").concat(fontVariant, "_").concat(fontWeight, "_").concat(fontSize, "_").concat(fontFamily);
7462
+ });
8021
7463
 
7464
+ /**
7465
+ * Minimum scaling limit
7466
+ *
7467
+ * When `scale` is 0, the matrix will become an irreversible matrix,
7468
+ * and `NaN` will appear during matrix calculation and decomposition,
7469
+ * causing exceptions
7470
+ */
7471
+ var MIN_SCALE = 0.000001;
7472
+ var clampScale = function clampScale(item) {
7473
+ return Math.max(item, MIN_SCALE);
7474
+ };
8022
7475
  function createSkewMatrix(skewMatrix, skewX, skewY) {
8023
7476
  // Create an identity matrix
8024
7477
  glMatrix.mat4.identity(skewMatrix);
@@ -8032,19 +7485,29 @@ var $mat4_1 = glMatrix.mat4.create();
8032
7485
  var $mat4_2 = glMatrix.mat4.create();
8033
7486
  var parser = {
8034
7487
  scale: function scale(d) {
8035
- glMatrix.mat4.fromScaling($mat4_1, [d[0].value, d[1].value, 1]);
7488
+ glMatrix.mat4.fromScaling($mat4_1, [d[0].value, d[1].value, 1].map(function (item) {
7489
+ return clampScale(item);
7490
+ }));
8036
7491
  },
8037
7492
  scaleX: function scaleX(d) {
8038
- glMatrix.mat4.fromScaling($mat4_1, [d[0].value, 1, 1]);
7493
+ glMatrix.mat4.fromScaling($mat4_1, [d[0].value, 1, 1].map(function (item) {
7494
+ return clampScale(item);
7495
+ }));
8039
7496
  },
8040
7497
  scaleY: function scaleY(d) {
8041
- glMatrix.mat4.fromScaling($mat4_1, [1, d[0].value, 1]);
7498
+ glMatrix.mat4.fromScaling($mat4_1, [1, d[0].value, 1].map(function (item) {
7499
+ return clampScale(item);
7500
+ }));
8042
7501
  },
8043
7502
  scaleZ: function scaleZ(d) {
8044
- glMatrix.mat4.fromScaling($mat4_1, [1, 1, d[0].value]);
7503
+ glMatrix.mat4.fromScaling($mat4_1, [1, 1, d[0].value].map(function (item) {
7504
+ return clampScale(item);
7505
+ }));
8045
7506
  },
8046
7507
  scale3d: function scale3d(d) {
8047
- glMatrix.mat4.fromScaling($mat4_1, [d[0].value, d[1].value, d[2].value]);
7508
+ glMatrix.mat4.fromScaling($mat4_1, [d[0].value, d[1].value, d[2].value].map(function (item) {
7509
+ return clampScale(item);
7510
+ }));
8048
7511
  },
8049
7512
  translate: function translate(d) {
8050
7513
  glMatrix.mat4.fromTranslation($mat4_1, [d[0].value, d[1].value, 0]);
@@ -9016,7 +8479,8 @@ var FederatedWheelEvent = /*#__PURE__*/function (_FederatedMouseEvent) {
9016
8479
  }(FederatedMouseEvent);
9017
8480
 
9018
8481
  /**
9019
- * @see https://developer.mozilla.org/en-US/docs/Web/Events/Creating_and_triggering_events
8482
+ * @link https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent
8483
+ * @link https://developer.mozilla.org/en-US/docs/Web/Events/Creating_and_triggering_events
9020
8484
  *
9021
8485
  * @example
9022
8486
  const event = new CustomEvent('build', { detail: { prop1: 'xx' } });
@@ -9028,15 +8492,15 @@ var FederatedWheelEvent = /*#__PURE__*/function (_FederatedMouseEvent) {
9028
8492
  circle.dispatchEvent(event);
9029
8493
  */
9030
8494
  var CustomEvent = /*#__PURE__*/function (_FederatedEvent) {
9031
- function CustomEvent(eventName, object) {
8495
+ function CustomEvent(eventName, options) {
9032
8496
  var _this;
9033
8497
  _classCallCheck(this, CustomEvent);
9034
8498
  _this = _callSuper(this, CustomEvent, [null]);
9035
8499
  _this.type = eventName;
9036
- _this.detail = object;
8500
+ _this.detail = options === null || options === void 0 ? void 0 : options.detail;
9037
8501
 
9038
8502
  // compatible with G 3.0
9039
- Object.assign(_this, object);
8503
+ Object.assign(_this, options);
9040
8504
  return _this;
9041
8505
  }
9042
8506
  _inherits(CustomEvent, _FederatedEvent);
@@ -9046,7 +8510,7 @@ var CustomEvent = /*#__PURE__*/function (_FederatedEvent) {
9046
8510
  /**
9047
8511
  * Objects that can receive events and may have listeners for them.
9048
8512
  * eg. Element, Canvas, DisplayObject
9049
- * @see https://developer.mozilla.org/en-US/docs/Web/API/EventTarget
8513
+ * @docs https://developer.mozilla.org/en-US/docs/Web/API/EventTarget
9050
8514
  */
9051
8515
  var EventTarget = /*#__PURE__*/function () {
9052
8516
  function EventTarget() {
@@ -9130,7 +8594,9 @@ var EventTarget = /*#__PURE__*/function () {
9130
8594
  }, {
9131
8595
  key: "emit",
9132
8596
  value: function emit(eventName, object) {
9133
- this.dispatchEvent(new CustomEvent(eventName, object));
8597
+ this.dispatchEvent(new CustomEvent(eventName, {
8598
+ detail: object
8599
+ }));
9134
8600
  }
9135
8601
  }, {
9136
8602
  key: "dispatchEventToSelf",
@@ -10547,14 +10013,15 @@ var RenderingService = /*#__PURE__*/function () {
10547
10013
  }
10548
10014
  }, {
10549
10015
  key: "render",
10550
- value: function render(canvasConfig, frame, rerenderCallback) {
10016
+ value: function render(canvas, frame, rerenderCallback) {
10551
10017
  var _this2 = this;
10018
+ var canvasConfig = canvas.getConfig();
10019
+ var renderingContext = this.context.renderingContext;
10552
10020
  this.stats.total = 0;
10553
10021
  this.stats.rendered = 0;
10554
10022
  this.zIndexCounter = 0;
10555
- var renderingContext = this.context.renderingContext;
10556
10023
  this.globalRuntime.sceneGraphService.syncHierarchy(renderingContext.root);
10557
- this.globalRuntime.sceneGraphService.triggerPendingEvents();
10024
+ this.globalRuntime.sceneGraphService.notifyMutationObservers(canvas);
10558
10025
  if (renderingContext.renderReasons.size && this.inited) {
10559
10026
  // @ts-ignore
10560
10027
  renderingContext.dirtyRectangleRenderingDisabled = this.disableDirtyRectangleRendering();
@@ -10666,11 +10133,11 @@ var RenderingService = /*#__PURE__*/function () {
10666
10133
  value: function destroy() {
10667
10134
  this.inited = false;
10668
10135
  this.hooks.destroy.call();
10669
- this.globalRuntime.sceneGraphService.clearPendingEvents();
10136
+ this.globalRuntime.sceneGraphService.clearMutationObserverData();
10670
10137
  }
10671
10138
  }, {
10672
- key: "dirtify",
10673
- value: function dirtify() {
10139
+ key: "dirty",
10140
+ value: function dirty() {
10674
10141
  // need re-render
10675
10142
  this.context.renderingContext.renderReasons.add(RenderReason.DISPLAY_OBJECT_CHANGED);
10676
10143
  }
@@ -10872,6 +10339,9 @@ var ElementEvent = /*#__PURE__*/function (ElementEvent) {
10872
10339
 
10873
10340
  // #region Canvas
10874
10341
 
10342
+ /**
10343
+ * @deprecated https://developer.chrome.com/blog/mutation-events-deprecation
10344
+ */
10875
10345
  var MutationEvent = /*#__PURE__*/function (_FederatedEvent) {
10876
10346
  function MutationEvent(typeArg, relatedNode, prevValue, newValue, attrName, attrChange, prevParsedValue, newParsedValue) {
10877
10347
  var _this;
@@ -10923,9 +10393,6 @@ var $setPosition_ParentInvertMatrix = glMatrix.mat4.create();
10923
10393
  var $setEulerAngles_InvParentRot = glMatrix.quat.create();
10924
10394
  var $rotateLocal = glMatrix.quat.create();
10925
10395
  var $rotate_ParentInvertRotation = glMatrix.quat.create();
10926
- var $triggerPendingEvents_detail = {
10927
- affectChildren: true
10928
- };
10929
10396
 
10930
10397
  /**
10931
10398
  * update transform in scene graph
@@ -10935,9 +10402,7 @@ var $triggerPendingEvents_detail = {
10935
10402
  var DefaultSceneGraphService = /*#__PURE__*/function () {
10936
10403
  function DefaultSceneGraphService(runtime) {
10937
10404
  _classCallCheck(this, DefaultSceneGraphService);
10938
- // target -> affectChildren
10939
- this.pendingEvents = new Map();
10940
- this.boundsChangedEvent = new CustomEvent(ElementEvent.BOUNDS_CHANGED);
10405
+ this.mutationsMap = new Map();
10941
10406
  this.displayObjectDependencyMap = new WeakMap();
10942
10407
  this.runtime = runtime;
10943
10408
  }
@@ -10996,7 +10461,7 @@ var DefaultSceneGraphService = /*#__PURE__*/function () {
10996
10461
  }
10997
10462
  if (isAttachToFragment) return;
10998
10463
  if (isChildFragment) {
10999
- this.dirtifyFragment(child);
10464
+ this.dirtyFragment(child);
11000
10465
  } else {
11001
10466
  var transform = child.transformable;
11002
10467
  if (transform) {
@@ -11424,22 +10889,12 @@ var DefaultSceneGraphService = /*#__PURE__*/function () {
11424
10889
 
11425
10890
  // #endregion transform
11426
10891
  // #region bbox ----------------------------------------------------------------
11427
- }, {
11428
- key: "getTransformedGeometryBounds",
11429
- value: function getTransformedGeometryBounds(element) {
11430
- var render = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
11431
- var existedAABB = arguments.length > 2 ? arguments[2] : undefined;
11432
- var bounds = this.getGeometryBounds(element, render);
11433
- if (!AABB.isEmpty(bounds)) {
11434
- var aabb = existedAABB || new AABB();
11435
- aabb.setFromTransformedAABB(bounds, this.getWorldTransform(element));
11436
- return aabb;
11437
- }
11438
- return null;
11439
- }
11440
10892
 
11441
10893
  /**
11442
- * won't account for children
10894
+ * Get the geometry bounds of the element itself, excluding children.
10895
+ *
10896
+ * @param element - The element to get geometry bounds for
10897
+ * @param render - If true, returns render bounds (including strokes, etc.); otherwise returns content bounds
11443
10898
  */
11444
10899
  }, {
11445
10900
  key: "getGeometryBounds",
@@ -11455,6 +10910,27 @@ var DefaultSceneGraphService = /*#__PURE__*/function () {
11455
10910
  return bounds || new AABB();
11456
10911
  }
11457
10912
 
10913
+ /**
10914
+ * Get the geometry bounds of the element itself in world space, excluding children.
10915
+ *
10916
+ * @param element - The element to get transformed geometry bounds for
10917
+ * @param render - If true, returns render bounds (including strokes, etc.); otherwise returns content bounds
10918
+ * @param existedAABB - Optional existing AABB to reuse
10919
+ */
10920
+ }, {
10921
+ key: "getTransformedGeometryBounds",
10922
+ value: function getTransformedGeometryBounds(element) {
10923
+ var render = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
10924
+ var existedAABB = arguments.length > 2 ? arguments[2] : undefined;
10925
+ var bounds = this.getGeometryBounds(element, render);
10926
+ if (!AABB.isEmpty(bounds)) {
10927
+ var aabb = existedAABB || new AABB();
10928
+ aabb.setFromTransformedAABB(bounds, this.getWorldTransform(element));
10929
+ return aabb;
10930
+ }
10931
+ return null;
10932
+ }
10933
+
11458
10934
  /**
11459
10935
  * account for children in world space
11460
10936
  */
@@ -11655,12 +11131,12 @@ var DefaultSceneGraphService = /*#__PURE__*/function () {
11655
11131
  }, {
11656
11132
  key: "dirtyWorldTransform",
11657
11133
  value: function dirtyWorldTransform(element, transform) {
11658
- this.dirtifyWorldInternal(element, transform);
11134
+ this.dirtyWorldInternal(element, transform);
11659
11135
  this.dirtyToRoot(element, true);
11660
11136
  }
11661
11137
  }, {
11662
- key: "dirtifyWorldInternal",
11663
- value: function dirtifyWorldInternal(element, transform) {
11138
+ key: "dirtyWorldInternal",
11139
+ value: function dirtyWorldInternal(element, transform) {
11664
11140
  var _element$ownerDocumen3,
11665
11141
  _this2 = this;
11666
11142
  var enableAttributeUpdateOptimization = ((_element$ownerDocumen3 = element.ownerDocument) === null || _element$ownerDocumen3 === void 0 || (_element$ownerDocumen3 = _element$ownerDocumen3.defaultView) === null || _element$ownerDocumen3 === void 0 || (_element$ownerDocumen3 = _element$ownerDocumen3.getConfig()) === null || _element$ownerDocumen3 === void 0 || (_element$ownerDocumen3 = _element$ownerDocumen3.future) === null || _element$ownerDocumen3 === void 0 ? void 0 : _element$ownerDocumen3.experimentalAttributeUpdateOptimization) === true;
@@ -11670,7 +11146,7 @@ var DefaultSceneGraphService = /*#__PURE__*/function () {
11670
11146
  if (!enableAttributeUpdateOptimization) {
11671
11147
  element.childNodes.forEach(function (child) {
11672
11148
  var childTransform = child.transformable;
11673
- _this2.dirtifyWorldInternal(child, childTransform);
11149
+ _this2.dirtyWorldInternal(child, childTransform);
11674
11150
  });
11675
11151
  }
11676
11152
  }
@@ -11698,11 +11174,25 @@ var DefaultSceneGraphService = /*#__PURE__*/function () {
11698
11174
  });
11699
11175
  }
11700
11176
  this.informDependentDisplayObjects(element);
11701
- this.pendingEvents.set(element, affectChildren);
11177
+ var mutation = this.mutationsMap.get(element);
11178
+ if (!mutation) {
11179
+ mutation = {
11180
+ type: 'attributes',
11181
+ target: element,
11182
+ _boundsChangeData: {
11183
+ affectChildren: affectChildren
11184
+ }
11185
+ };
11186
+ this.mutationsMap.set(element, mutation);
11187
+ } else {
11188
+ mutation._boundsChangeData = {
11189
+ affectChildren: mutation._boundsChangeData.affectChildren || affectChildren
11190
+ };
11191
+ }
11702
11192
  }
11703
11193
  }, {
11704
- key: "dirtifyFragment",
11705
- value: function dirtifyFragment(element) {
11194
+ key: "dirtyFragment",
11195
+ value: function dirtyFragment(element) {
11706
11196
  var _dirty3, _ref7;
11707
11197
  var transform = element.transformable;
11708
11198
  if (transform) {
@@ -11712,65 +11202,22 @@ var DefaultSceneGraphService = /*#__PURE__*/function () {
11712
11202
  (_dirty3 = (_ref7 = element).dirty) === null || _dirty3 === void 0 || _dirty3.call(_ref7, true, true);
11713
11203
  var length = element.childNodes.length;
11714
11204
  for (var i = 0; i < length; i++) {
11715
- this.dirtifyFragment(element.childNodes[i]);
11716
- }
11717
- if (element.nodeName === Shape.FRAGMENT) {
11718
- this.pendingEvents.set(element, false);
11205
+ this.dirtyFragment(element.childNodes[i]);
11719
11206
  }
11720
11207
  }
11721
11208
  }, {
11722
- key: "triggerPendingEvents",
11723
- value: function triggerPendingEvents() {
11724
- var _this3 = this;
11725
- var triggered = new Set();
11726
- var enableCancelEventPropagation;
11727
- var enableAttributeUpdateOptimization;
11728
- var trigger = function trigger(element, detail) {
11729
- if (!element.isConnected || triggered.has(element) || element.nodeName === Shape.FRAGMENT) {
11730
- return;
11731
- }
11732
- _this3.boundsChangedEvent.detail = detail;
11733
- _this3.boundsChangedEvent.target = element;
11734
- if (element.isMutationObserved) {
11735
- element.dispatchEvent(_this3.boundsChangedEvent);
11736
- } else {
11737
- if (enableCancelEventPropagation === undefined) {
11738
- var _element$ownerDocumen5;
11739
- enableCancelEventPropagation = ((_element$ownerDocumen5 = element.ownerDocument.defaultView) === null || _element$ownerDocumen5 === void 0 || (_element$ownerDocumen5 = _element$ownerDocumen5.getConfig()) === null || _element$ownerDocumen5 === void 0 || (_element$ownerDocumen5 = _element$ownerDocumen5.future) === null || _element$ownerDocumen5 === void 0 ? void 0 : _element$ownerDocumen5.experimentalCancelEventPropagation) === true;
11740
- }
11741
- element.ownerDocument.defaultView.dispatchEvent(_this3.boundsChangedEvent, true, enableCancelEventPropagation);
11742
- }
11743
- triggered.add(element);
11744
- };
11745
- this.pendingEvents.forEach(function (affectChildren, element) {
11746
- if (element.nodeName === Shape.FRAGMENT) {
11747
- return;
11748
- }
11749
- if (enableAttributeUpdateOptimization === undefined) {
11750
- var _element$ownerDocumen6;
11751
- enableAttributeUpdateOptimization = ((_element$ownerDocumen6 = element.ownerDocument) === null || _element$ownerDocumen6 === void 0 || (_element$ownerDocumen6 = _element$ownerDocumen6.defaultView) === null || _element$ownerDocumen6 === void 0 || (_element$ownerDocumen6 = _element$ownerDocumen6.getConfig()) === null || _element$ownerDocumen6 === void 0 || (_element$ownerDocumen6 = _element$ownerDocumen6.future) === null || _element$ownerDocumen6 === void 0 ? void 0 : _element$ownerDocumen6.experimentalAttributeUpdateOptimization) === true;
11752
- }
11753
- $triggerPendingEvents_detail.affectChildren = affectChildren;
11754
- if (enableAttributeUpdateOptimization) {
11755
- trigger(element, $triggerPendingEvents_detail);
11756
- } else {
11757
- // eslint-disable-next-line no-lonely-if
11758
- if (affectChildren) {
11759
- element.forEach(function (e) {
11760
- trigger(e, $triggerPendingEvents_detail);
11761
- });
11762
- } else {
11763
- trigger(element, $triggerPendingEvents_detail);
11764
- }
11765
- }
11209
+ key: "notifyMutationObservers",
11210
+ value: function notifyMutationObservers(canvas) {
11211
+ var event = new CustomEvent(ElementEvent.BOUNDS_CHANGED, {
11212
+ detail: Array.from(this.mutationsMap.values())
11766
11213
  });
11767
- triggered.clear();
11768
- this.clearPendingEvents();
11214
+ canvas.dispatchEvent(event, true, true);
11215
+ this.clearMutationObserverData();
11769
11216
  }
11770
11217
  }, {
11771
- key: "clearPendingEvents",
11772
- value: function clearPendingEvents() {
11773
- this.pendingEvents.clear();
11218
+ key: "clearMutationObserverData",
11219
+ value: function clearMutationObserverData() {
11220
+ this.mutationsMap.clear();
11774
11221
  }
11775
11222
  }, {
11776
11223
  key: "updateDisplayObjectDependency",
@@ -11799,7 +11246,7 @@ var DefaultSceneGraphService = /*#__PURE__*/function () {
11799
11246
  key: "informDependentDisplayObjects",
11800
11247
  value: function informDependentDisplayObjects(object) {
11801
11248
  var _object$ownerDocument,
11802
- _this4 = this;
11249
+ _this3 = this;
11803
11250
  var dependencyMap = this.displayObjectDependencyMap.get(object);
11804
11251
  if (!dependencyMap) {
11805
11252
  return;
@@ -11807,11 +11254,11 @@ var DefaultSceneGraphService = /*#__PURE__*/function () {
11807
11254
  var enableCancelEventPropagation = (_object$ownerDocument = object.ownerDocument) === null || _object$ownerDocument === void 0 || (_object$ownerDocument = _object$ownerDocument.defaultView) === null || _object$ownerDocument === void 0 || (_object$ownerDocument = _object$ownerDocument.getConfig()) === null || _object$ownerDocument === void 0 || (_object$ownerDocument = _object$ownerDocument.future) === null || _object$ownerDocument === void 0 ? void 0 : _object$ownerDocument.experimentalCancelEventPropagation;
11808
11255
  Object.keys(dependencyMap).forEach(function (name) {
11809
11256
  dependencyMap[name].forEach(function (target) {
11810
- _this4.dirtyToRoot(target, true);
11811
- target.dispatchEvent(new MutationEvent(ElementEvent.ATTR_MODIFIED, target, _this4, _this4, name, MutationEvent.MODIFICATION, _this4, _this4), enableCancelEventPropagation, enableCancelEventPropagation);
11257
+ _this3.dirtyToRoot(target, true);
11258
+ target.dispatchEvent(new MutationEvent(ElementEvent.ATTR_MODIFIED, target, _this3, _this3, name, MutationEvent.MODIFICATION, _this3, _this3), enableCancelEventPropagation, enableCancelEventPropagation);
11812
11259
  if (target.isCustomElement && target.isConnected) {
11813
11260
  if (target.attributeChangedCallback) {
11814
- target.attributeChangedCallback(name, _this4, _this4);
11261
+ target.attributeChangedCallback(name, _this3, _this3);
11815
11262
  }
11816
11263
  }
11817
11264
  });
@@ -11820,6 +11267,94 @@ var DefaultSceneGraphService = /*#__PURE__*/function () {
11820
11267
  }]);
11821
11268
  }();
11822
11269
 
11270
+ /**
11271
+ * A classic LRU (Least Recently Used) cache implementation.
11272
+ * It evicts the least recently used item when the cache is full.
11273
+ *
11274
+ * It uses a Map for O(1) key-based access
11275
+ * to maintain the usage order of items.
11276
+ *
11277
+ * 通过利用 JavaScript 内置 Map 的特性(按插入顺序迭代),我们不再需要手动维护一个双向链表
11278
+ */
11279
+ var LRU = /*#__PURE__*/function () {
11280
+ function LRU(capacity) {
11281
+ _classCallCheck(this, LRU);
11282
+ if (capacity <= 0) {
11283
+ throw new Error('LRU capacity must be a positive number.');
11284
+ }
11285
+ this.capacity = capacity;
11286
+ // Using a Map directly simplifies the implementation significantly.
11287
+ // A Map in modern JS engines iterates in insertion order, which is exactly what we need.
11288
+ this.cache = new Map();
11289
+ }
11290
+
11291
+ /**
11292
+ * Retrieves an item from the cache. Marks the item as recently used.
11293
+ * @param key The key of the item to retrieve.
11294
+ * @returns The value of the item, or undefined if not found.
11295
+ */
11296
+ return _createClass(LRU, [{
11297
+ key: "get",
11298
+ value: function get(key) {
11299
+ if (!this.cache.has(key)) {
11300
+ return undefined;
11301
+ }
11302
+
11303
+ // Get the value.
11304
+ var value = this.cache.get(key);
11305
+
11306
+ // Mark as recently used by deleting and re-setting the key.
11307
+ // This moves the key to the end of the Map's internal order.
11308
+ this.cache["delete"](key);
11309
+ this.cache.set(key, value);
11310
+ return value;
11311
+ }
11312
+
11313
+ /**
11314
+ * Adds or updates an item in the cache. Marks the item as recently used.
11315
+ * If the cache is full, it removes the least recently used item.
11316
+ * @param key The key of the item.
11317
+ * @param value The value of the item.
11318
+ */
11319
+ }, {
11320
+ key: "put",
11321
+ value: function put(key, value) {
11322
+ // If the key already exists, delete it first to ensure it's moved to the end.
11323
+ if (this.cache.has(key)) {
11324
+ this.cache["delete"](key);
11325
+ }
11326
+
11327
+ // Add the new item. It will be the most recently used.
11328
+ this.cache.set(key, value);
11329
+
11330
+ // Check if the cache has exceeded its capacity.
11331
+ if (this.cache.size > this.capacity) {
11332
+ // Evict the least recently used item, which is the first one in the Map's iteration order.
11333
+ var leastRecentlyUsedKey = this.cache.keys().next().value;
11334
+ this.cache["delete"](leastRecentlyUsedKey);
11335
+ }
11336
+ }
11337
+
11338
+ /**
11339
+ * Returns the current number of items in the cache.
11340
+ */
11341
+ }, {
11342
+ key: "len",
11343
+ value: function len() {
11344
+ return this.cache.size;
11345
+ }
11346
+
11347
+ /**
11348
+ * Clears all items from the cache.
11349
+ */
11350
+ }, {
11351
+ key: "clear",
11352
+ value: function clear() {
11353
+ this.cache.clear();
11354
+ }
11355
+ }]);
11356
+ }();
11357
+
11823
11358
  var TEXT_METRICS = {
11824
11359
  MetricsString: '|ÉqÅ',
11825
11360
  BaselineSymbol: 'M',
@@ -11906,10 +11441,16 @@ var TextService = /*#__PURE__*/function () {
11906
11441
  return next;
11907
11442
  };
11908
11443
  this.runtime = runtime;
11444
+ this.charWidthCache = new LRU(100);
11909
11445
  }
11910
11446
  return _createClass(TextService, [{
11911
11447
  key: "measureFont",
11912
11448
  value:
11449
+ /**
11450
+ * A global cache for character widths, keyed by font string.
11451
+ * e.g. { '16px Arial': { 'a': 8, 'b': 9 } }
11452
+ */
11453
+
11913
11454
  /**
11914
11455
  * Calculates the ascent, descent and fontSize of a given font-style.
11915
11456
  */
@@ -12131,9 +11672,19 @@ var TextService = /*#__PURE__*/function () {
12131
11672
  var currentLineWidth = 0;
12132
11673
  // @see https://github.com/antvis/G/issues/1932
12133
11674
  var prevLineLastCharIndex = -1;
12134
- var cache = {};
12135
- var calcWidth = function calcWidth(txt) {
12136
- return _this2.getFromCache(txt, letterSpacing, cache, context);
11675
+
11676
+ // --- 优化核心 ---
11677
+ // 1. 获取或创建当前字体对应的字符缓存
11678
+ var font = toFontString(parsedStyle);
11679
+ var charCache = this.charWidthCache.get(font);
11680
+ if (!charCache) {
11681
+ charCache = new LRU(500);
11682
+ this.charWidthCache.put(font, charCache);
11683
+ }
11684
+
11685
+ // 2. calcWidth 现在直接使用持久化的 charCache
11686
+ var calcWidth = function calcWidth(_char2) {
11687
+ return _this2.getFromCache(_char2, letterSpacing, charCache, context);
12137
11688
  };
12138
11689
  var ellipsisWidth = calcWidth(ellipsis);
12139
11690
 
@@ -12179,11 +11730,11 @@ var TextService = /*#__PURE__*/function () {
12179
11730
  lines[lineIndex] = result.lineTxt + ellipsis;
12180
11731
  }
12181
11732
  for (var i = 0; i < chars.length; i++) {
12182
- var _char2 = chars[i];
11733
+ var _char3 = chars[i];
12183
11734
  var prevChar = chars[i - 1];
12184
11735
  var nextChar = chars[i + 1];
12185
- var charWidth = calcWidth(_char2);
12186
- if (this.isNewline(_char2)) {
11736
+ var charWidth = calcWidth(_char3);
11737
+ if (this.isNewline(_char3)) {
12187
11738
  // exceed maxLines, break immediately
12188
11739
  if (currentLineIndex + 1 >= maxLines) {
12189
11740
  if (i < chars.length - 1) {
@@ -12213,10 +11764,10 @@ var TextService = /*#__PURE__*/function () {
12213
11764
  break;
12214
11765
  }
12215
11766
  i = result.txtLastCharIndex + 1;
12216
- _char2 = chars[i];
11767
+ _char3 = chars[i];
12217
11768
  prevChar = chars[i - 1];
12218
11769
  nextChar = chars[i + 1];
12219
- charWidth = calcWidth(_char2);
11770
+ charWidth = calcWidth(_char3);
12220
11771
  }
12221
11772
  if (currentLineIndex + 1 >= maxLines) {
12222
11773
  appendEllipsis(currentLineIndex, i - 1);
@@ -12227,38 +11778,38 @@ var TextService = /*#__PURE__*/function () {
12227
11778
  currentLineIndex += 1;
12228
11779
  currentLineWidth = 0;
12229
11780
  lines[currentLineIndex] = '';
12230
- if (this.isBreakingSpace(_char2)) {
11781
+ if (this.isBreakingSpace(_char3)) {
12231
11782
  continue;
12232
11783
  }
12233
- if (!this.canBreakInLastChar(_char2)) {
11784
+ if (!this.canBreakInLastChar(_char3)) {
12234
11785
  lines = this.trimToBreakable(lines);
12235
11786
  currentLineWidth = this.sumTextWidthByCache(lines[currentLineIndex] || '', calcWidth);
12236
11787
  }
12237
- if (this.shouldBreakByKinsokuShorui(_char2, nextChar)) {
11788
+ if (this.shouldBreakByKinsokuShorui(_char3, nextChar)) {
12238
11789
  lines = this.trimByKinsokuShorui(lines);
12239
11790
  currentLineWidth += calcWidth(prevChar || '');
12240
11791
  }
12241
11792
  }
12242
11793
  currentLineWidth += charWidth;
12243
- lines[currentLineIndex] += _char2;
11794
+ lines[currentLineIndex] += _char3;
12244
11795
  }
12245
11796
  return lines.join('\n');
12246
11797
  }
12247
11798
  }, {
12248
11799
  key: "isBreakingSpace",
12249
- value: function isBreakingSpace(_char3) {
12250
- if (typeof _char3 !== 'string') {
11800
+ value: function isBreakingSpace(_char4) {
11801
+ if (typeof _char4 !== 'string') {
12251
11802
  return false;
12252
11803
  }
12253
- return TEXT_METRICS.BreakingSpaces.indexOf(_char3.charCodeAt(0)) >= 0;
11804
+ return TEXT_METRICS.BreakingSpaces.indexOf(_char4.charCodeAt(0)) >= 0;
12254
11805
  }
12255
11806
  }, {
12256
11807
  key: "isNewline",
12257
- value: function isNewline(_char4) {
12258
- if (typeof _char4 !== 'string') {
11808
+ value: function isNewline(_char5) {
11809
+ if (typeof _char5 !== 'string') {
12259
11810
  return false;
12260
11811
  }
12261
- return TEXT_METRICS.Newlines.indexOf(_char4.charCodeAt(0)) >= 0;
11812
+ return TEXT_METRICS.Newlines.indexOf(_char5.charCodeAt(0)) >= 0;
12262
11813
  }
12263
11814
  }, {
12264
11815
  key: "trimToBreakable",
@@ -12277,8 +11828,8 @@ var TextService = /*#__PURE__*/function () {
12277
11828
  }
12278
11829
  }, {
12279
11830
  key: "canBreakInLastChar",
12280
- value: function canBreakInLastChar(_char5) {
12281
- if (_char5 && LATIN_REGEX.test(_char5)) return false;
11831
+ value: function canBreakInLastChar(_char6) {
11832
+ if (_char6 && LATIN_REGEX.test(_char6)) return false;
12282
11833
  return true;
12283
11834
  }
12284
11835
  }, {
@@ -12299,15 +11850,21 @@ var TextService = /*#__PURE__*/function () {
12299
11850
  }, {
12300
11851
  key: "getFromCache",
12301
11852
  value: function getFromCache(key, letterSpacing, cache, context) {
12302
- var width = cache[key];
11853
+ var width = cache.get(key);
12303
11854
  if (typeof width !== 'number') {
12304
11855
  var spacing = key.length * letterSpacing;
12305
11856
  var metrics = context.measureText(key);
12306
11857
  width = metrics.width + spacing;
12307
- cache[key] = width;
11858
+ cache.put(key, width);
12308
11859
  }
12309
11860
  return width;
12310
11861
  }
11862
+ }, {
11863
+ key: "clearCache",
11864
+ value: function clearCache() {
11865
+ this.fontMetricsCache = {};
11866
+ this.charWidthCache.clear();
11867
+ }
12311
11868
  }]);
12312
11869
  }();
12313
11870
 
@@ -12426,6 +11983,10 @@ var Element = /*#__PURE__*/function (_Node) {
12426
11983
  dirtyChildren: [],
12427
11984
  dirtyReason: undefined
12428
11985
  };
11986
+ /**
11987
+ * @deprecated Legacy property for RBush spatial indexing.
11988
+ * Will be removed in future versions.
11989
+ */
12429
11990
  _this.rBushNode = {
12430
11991
  aabb: undefined
12431
11992
  };
@@ -12481,16 +12042,23 @@ var Element = /*#__PURE__*/function (_Node) {
12481
12042
  key: "dirty",
12482
12043
  value:
12483
12044
  /**
12484
- * @param flag - default `true`, whether the object needs to be updated
12485
- * @param updateShape - default `false`, whether the bounding box of the object is updated
12045
+ * Marks the element as dirty, indicating it needs re-rendering or relayout.
12046
+ *
12047
+ * @param styleFlag - Whether to update style state (default: true).
12048
+ * When true, sets `renderable.dirty` to true.
12049
+ * @param layoutFlag - Optional. When provided, updates layout-related dirty flags:
12050
+ * - `renderable.boundsDirty`
12051
+ * - `renderable.renderBoundsDirty`
12052
+ * - `geometry.dirty`
12486
12053
  */
12487
12054
  function dirty() {
12488
- var flag = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
12489
- var updateShape = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
12490
- this.renderable.dirty = flag;
12491
- if (updateShape) {
12492
- this.renderable.boundsDirty = flag;
12493
- this.renderable.renderBoundsDirty = flag;
12055
+ var styleFlag = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
12056
+ var layoutFlag = arguments.length > 1 ? arguments[1] : undefined;
12057
+ this.renderable.dirty = styleFlag;
12058
+ if (layoutFlag !== undefined) {
12059
+ this.renderable.boundsDirty = layoutFlag;
12060
+ this.renderable.renderBoundsDirty = layoutFlag;
12061
+ this.geometry.dirty = layoutFlag;
12494
12062
  }
12495
12063
  }
12496
12064
  }, {
@@ -12884,12 +12452,18 @@ var Element = /*#__PURE__*/function (_Node) {
12884
12452
  }, {
12885
12453
  key: "getGeometryBounds",
12886
12454
  value: function getGeometryBounds() {
12887
- return runtime.sceneGraphService.getGeometryBounds(this);
12455
+ var render = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
12456
+ return runtime.sceneGraphService.getGeometryBounds(this, render);
12888
12457
  }
12458
+
12459
+ /**
12460
+ * get geometry bounds in world space, not accounting for children
12461
+ */
12889
12462
  }, {
12890
- key: "getRenderBounds",
12891
- value: function getRenderBounds() {
12892
- return runtime.sceneGraphService.getBounds(this, true);
12463
+ key: "getTransformedGeometryBounds",
12464
+ value: function getTransformedGeometryBounds() {
12465
+ var render = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
12466
+ return runtime.sceneGraphService.getTransformedGeometryBounds(this, render);
12893
12467
  }
12894
12468
 
12895
12469
  /**
@@ -12900,6 +12474,11 @@ var Element = /*#__PURE__*/function (_Node) {
12900
12474
  value: function getBounds() {
12901
12475
  return runtime.sceneGraphService.getBounds(this);
12902
12476
  }
12477
+ }, {
12478
+ key: "getRenderBounds",
12479
+ value: function getRenderBounds() {
12480
+ return runtime.sceneGraphService.getBounds(this, true);
12481
+ }
12903
12482
 
12904
12483
  /**
12905
12484
  * get bounds in local space, account for children
@@ -13001,7 +12580,7 @@ var Element = /*#__PURE__*/function (_Node) {
13001
12580
  */
13002
12581
  }, {
13003
12582
  key: "setAttribute",
13004
- value: function setAttribute(attributeName, value, force, memoize) {
12583
+ value: function setAttribute(attributeName, value) {
13005
12584
  this.attributes[attributeName] = value;
13006
12585
  }
13007
12586
  }, {
@@ -13235,9 +12814,6 @@ var DisplayObject = /*#__PURE__*/function (_Element) {
13235
12814
 
13236
12815
  // redraw at next frame
13237
12816
  this.dirty();
13238
-
13239
- // return;
13240
-
13241
12817
  var newParsedValue = this.parsedStyle[name];
13242
12818
  if (this.isConnected) {
13243
12819
  attrModifiedEvent.relatedNode = this;
@@ -14804,7 +14380,7 @@ var Text = /*#__PURE__*/function (_DisplayObject) {
14804
14380
  }
14805
14381
  }]);
14806
14382
  }(DisplayObject);
14807
- Text.PARSED_STYLE_LIST = new Set([].concat(_toConsumableArray(DisplayObject.PARSED_STYLE_LIST), ['x', 'y', 'z', 'isBillboard', 'billboardRotation', 'isSizeAttenuation', 'text', 'textAlign', 'textBaseline', 'fontStyle', 'fontSize', 'fontFamily', 'fontWeight', 'fontVariant', 'lineHeight', 'letterSpacing', 'leading', 'wordWrap', 'wordWrapWidth', 'maxLines', 'textOverflow', 'isOverflowing', 'textPath', 'textDecorationLine', 'textDecorationColor', 'textDecorationStyle', 'textPathSide', 'textPathStartOffset', 'metrics', 'dx', 'dy']));
14383
+ Text.PARSED_STYLE_LIST = new Set([].concat(_toConsumableArray(DisplayObject.PARSED_STYLE_LIST), ['x', 'y', 'z', 'isBillboard', 'billboardRotation', 'isSizeAttenuation', 'text', 'textAlign', 'textBaseline', 'fontStyle', 'fontSize', 'fontFamily', 'fontWeight', 'fontVariant', 'lineHeight', 'letterSpacing', 'leading', 'wordWrap', 'wordWrapWidth', 'maxLines', 'textOverflow', 'isOverflowing', 'textPath', 'textDecorationLine', 'textDecorationColor', 'textDecorationStyle', 'textDecorationThickness', 'textPathSide', 'textPathStartOffset', 'metrics', 'dx', 'dy']));
14808
14384
 
14809
14385
  /**
14810
14386
  * canvas.customElements
@@ -15066,32 +14642,47 @@ var Document = /*#__PURE__*/function (_Node) {
15066
14642
  }
15067
14643
 
15068
14644
  /**
15069
- * Picking 2D graphics with RBush based on BBox, fast but inaccurate.
14645
+ * Picking 2D graphics by traversing elements and checking bounding boxes.
15070
14646
  */
15071
14647
  }, {
15072
14648
  key: "elementsFromBBox",
15073
14649
  value: function elementsFromBBox(minX, minY, maxX, maxY) {
15074
- var rBush = this.defaultView.context.rBushRoot;
15075
- var rBushNodes = rBush.search({
15076
- minX: minX,
15077
- minY: minY,
15078
- maxX: maxX,
15079
- maxY: maxY
15080
- });
15081
14650
  var hitTestList = [];
15082
- rBushNodes.forEach(function (_ref2) {
15083
- var displayObject = _ref2.displayObject;
15084
- var _displayObject$parsed = displayObject.parsedStyle.pointerEvents,
15085
- pointerEvents = _displayObject$parsed === void 0 ? 'auto' : _displayObject$parsed;
15086
14651
 
15087
- // account for `visibility`
14652
+ // Traverse all elements in the document
14653
+ var _traverse = function traverse(node) {
14654
+ if (!node.isInteractive() || node.isCulled()) {
14655
+ return;
14656
+ }
14657
+ var _node$parsedStyle$poi = node.parsedStyle.pointerEvents,
14658
+ pointerEvents = _node$parsedStyle$poi === void 0 ? 'auto' : _node$parsedStyle$poi;
14659
+
14660
+ // Account for `visibility`
15088
14661
  // @see https://developer.mozilla.org/en-US/docs/Web/CSS/pointer-events
15089
14662
  var isVisibilityAffected = ['auto', 'visiblepainted', 'visiblefill', 'visiblestroke', 'visible'].includes(pointerEvents);
15090
- if ((!isVisibilityAffected || isVisibilityAffected && displayObject.isVisible()) && !displayObject.isCulled() && displayObject.isInteractive()) {
15091
- hitTestList.push(displayObject);
14663
+ if (!isVisibilityAffected || node.isVisible()) {
14664
+ var bounds = node.getTransformedGeometryBounds(true);
14665
+ if (bounds && !AABB.isEmpty(bounds)) {
14666
+ if (bounds.max[0] >= minX && bounds.min[0] <= maxX && bounds.max[1] >= minY && bounds.min[1] <= maxY) {
14667
+ hitTestList.push(node);
14668
+ }
14669
+ }
15092
14670
  }
15093
- });
15094
- // find group with max z-index
14671
+
14672
+ // Traverse children if it's a container
14673
+ if (node.childNodes) {
14674
+ node.childNodes.forEach(function (child) {
14675
+ if (child instanceof DisplayObject) {
14676
+ _traverse(child);
14677
+ }
14678
+ });
14679
+ }
14680
+ };
14681
+
14682
+ // Start traversal from documentElement
14683
+ _traverse(this.documentElement);
14684
+
14685
+ // Sort by render order (z-index)
15095
14686
  hitTestList.sort(function (a, b) {
15096
14687
  return b.sortable.renderOrder - a.sortable.renderOrder;
15097
14688
  });
@@ -15823,32 +15414,34 @@ var FrustumCullingStrategy = /*#__PURE__*/function () {
15823
15414
  }]);
15824
15415
  }();
15825
15416
 
15417
+ /**
15418
+ * PrepareRendererPlugin handles rendering preparation tasks
15419
+ * Simplified implementation focused on core rendering needs
15420
+ */
15826
15421
  var PrepareRendererPlugin = /*#__PURE__*/function () {
15827
15422
  function PrepareRendererPlugin() {
15828
15423
  _classCallCheck(this, PrepareRendererPlugin);
15829
- this.syncTasks = new Map();
15424
+ this.mutationRecords = [];
15830
15425
  this.isFirstTimeRendering = true;
15831
- this.syncing = false;
15832
15426
  this.isFirstTimeRenderingFinished = false;
15833
15427
  }
15834
15428
  return _createClass(PrepareRendererPlugin, [{
15835
15429
  key: "apply",
15836
15430
  value: function apply(context) {
15837
15431
  var _this = this,
15838
- _runtime$globalThis$r,
15839
- _config$future;
15840
- var config = context.config,
15841
- renderingService = context.renderingService,
15842
- renderingContext = context.renderingContext,
15843
- rBushRoot = context.rBushRoot;
15432
+ _runtime$globalThis$r;
15433
+ var renderingService = context.renderingService,
15434
+ renderingContext = context.renderingContext;
15844
15435
  var canvas = renderingContext.root.ownerDocument.defaultView;
15845
- this.rBush = rBushRoot;
15846
15436
  var handleAttributeChanged = function handleAttributeChanged(e) {
15847
- renderingService.dirtify();
15437
+ renderingService.dirty();
15848
15438
  };
15849
15439
  var handleBoundsChanged = function handleBoundsChanged(e) {
15850
- _this.syncTasks.set(e.target, e.detail.affectChildren);
15851
- renderingService.dirtify();
15440
+ var _this$mutationRecords;
15441
+ var records = e.detail;
15442
+ // Store mutation records for potential future processing
15443
+ (_this$mutationRecords = _this.mutationRecords).push.apply(_this$mutationRecords, _toConsumableArray(records));
15444
+ renderingService.dirty();
15852
15445
  };
15853
15446
  var handleMounted = function handleMounted(e) {
15854
15447
  var object = e.target;
@@ -15858,13 +15451,10 @@ var PrepareRendererPlugin = /*#__PURE__*/function () {
15858
15451
  };
15859
15452
  var handleUnmounted = function handleUnmounted(e) {
15860
15453
  var object = e.target;
15861
- var rBushNode = object.rBushNode;
15862
- if (rBushNode !== null && rBushNode !== void 0 && rBushNode.aabb) {
15863
- _this.rBush.remove(rBushNode.aabb);
15864
- }
15865
- _this.syncTasks["delete"](object);
15454
+
15455
+ // No spatial index cleanup needed
15866
15456
  runtime.sceneGraphService.dirtyToRoot(object);
15867
- renderingService.dirtify();
15457
+ renderingService.dirty();
15868
15458
  };
15869
15459
  renderingService.hooks.init.tap(PrepareRendererPlugin.tag, function () {
15870
15460
  canvas.addEventListener(ElementEvent.MOUNTED, handleMounted);
@@ -15877,109 +15467,20 @@ var PrepareRendererPlugin = /*#__PURE__*/function () {
15877
15467
  canvas.removeEventListener(ElementEvent.UNMOUNTED, handleUnmounted);
15878
15468
  canvas.removeEventListener(ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
15879
15469
  canvas.removeEventListener(ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
15880
- _this.syncTasks.clear();
15470
+ _this.mutationRecords = [];
15881
15471
  });
15882
15472
  var ric = (_runtime$globalThis$r = runtime.globalThis.requestIdleCallback) !== null && _runtime$globalThis$r !== void 0 ? _runtime$globalThis$r : raf.bind(runtime.globalThis);
15883
- var enableRICSyncRTree = ((_config$future = config.future) === null || _config$future === void 0 ? void 0 : _config$future.experimentalRICSyncRTree) === true;
15884
15473
  renderingService.hooks.endFrame.tap(PrepareRendererPlugin.tag, function () {
15885
15474
  if (_this.isFirstTimeRendering) {
15886
15475
  _this.isFirstTimeRendering = false;
15887
- _this.syncing = true;
15888
15476
  ric(function () {
15889
- _this.syncRTree(true);
15890
15477
  _this.isFirstTimeRenderingFinished = true;
15891
15478
  });
15892
- } else if (enableRICSyncRTree && runtime.globalThis.requestIdleCallback && runtime.globalThis.cancelIdleCallback) {
15893
- runtime.globalThis.cancelIdleCallback(_this.ricSyncRTreeId);
15894
- _this.ricSyncRTreeId = runtime.globalThis.requestIdleCallback(function () {
15895
- return _this.syncRTree();
15896
- });
15897
- } else {
15898
- _this.syncRTree();
15899
- }
15900
- });
15901
- }
15902
- }, {
15903
- key: "syncNode",
15904
- value: function syncNode(node) {
15905
- var force = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
15906
- if (!node.isConnected) return;
15907
- var rBushNode = node.rBushNode;
15908
-
15909
- // clear dirty node
15910
- if (rBushNode.aabb) this.rBush.remove(rBushNode.aabb);
15911
- var renderBounds = node.getRenderBounds();
15912
- if (renderBounds) {
15913
- var renderable = node.renderable;
15914
- if (force) {
15915
- if (!renderable.dirtyRenderBounds) {
15916
- renderable.dirtyRenderBounds = new AABB();
15917
- }
15918
- // save last dirty aabb
15919
- renderable.dirtyRenderBounds.update(renderBounds.center, renderBounds.halfExtents);
15920
- }
15921
- var _renderBounds$getMin = renderBounds.getMin(),
15922
- _renderBounds$getMin2 = _slicedToArray(_renderBounds$getMin, 2),
15923
- minX = _renderBounds$getMin2[0],
15924
- minY = _renderBounds$getMin2[1];
15925
- var _renderBounds$getMax = renderBounds.getMax(),
15926
- _renderBounds$getMax2 = _slicedToArray(_renderBounds$getMax, 2),
15927
- maxX = _renderBounds$getMax2[0],
15928
- maxY = _renderBounds$getMax2[1];
15929
- if (!rBushNode.aabb) {
15930
- rBushNode.aabb = {};
15931
- }
15932
- rBushNode.aabb.displayObject = node;
15933
- rBushNode.aabb.minX = minX;
15934
- rBushNode.aabb.minY = minY;
15935
- rBushNode.aabb.maxX = maxX;
15936
- rBushNode.aabb.maxY = maxY;
15937
- }
15938
- if (rBushNode.aabb) {
15939
- // TODO: NaN occurs when width/height of Rect is 0
15940
- if (!isNaN(rBushNode.aabb.maxX) && !isNaN(rBushNode.aabb.maxX) && !isNaN(rBushNode.aabb.minX) && !isNaN(rBushNode.aabb.minY)) {
15941
- return rBushNode.aabb;
15942
- }
15943
- }
15944
- }
15945
- }, {
15946
- key: "syncRTree",
15947
- value: function syncRTree() {
15948
- var _this2 = this;
15949
- var force = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
15950
- if (!force && (this.syncing || this.syncTasks.size === 0)) {
15951
- return;
15952
- }
15953
- this.syncing = true;
15954
-
15955
- // bounds changed, need re-inserting its children
15956
- var bulk = [];
15957
- var synced = new Set();
15958
- var sync = function sync(node) {
15959
- if (!synced.has(node) && node.renderable) {
15960
- var aabb = _this2.syncNode(node, force);
15961
- if (aabb) {
15962
- bulk.push(aabb);
15963
- synced.add(node);
15964
- }
15965
- }
15966
- };
15967
- this.syncTasks.forEach(function (affectChildren, node) {
15968
- if (affectChildren) {
15969
- node.forEach(sync);
15970
15479
  }
15971
- var parent = node;
15972
- while (parent) {
15973
- sync(parent);
15974
- parent = parent.parentElement;
15975
- }
15976
- });
15977
15480
 
15978
- // use bulk inserting, which is ~2-3 times faster
15979
- // @see https://github.com/mourner/rbush#bulk-inserting-data
15980
- this.rBush.load(bulk);
15981
- bulk.length = 0;
15982
- this.syncing = false;
15481
+ // Clear mutation records after each frame
15482
+ _this.mutationRecords = [];
15483
+ });
15983
15484
  }
15984
15485
  }]);
15985
15486
  }();
@@ -16278,10 +15779,7 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
16278
15779
  this.getContextService().destroy();
16279
15780
 
16280
15781
  // clear root after render service destroyed
16281
- if (this.context.rBushRoot) {
16282
- // clear rbush
16283
- this.context.rBushRoot.clear();
16284
- }
15782
+
16285
15783
  if (!skipTriggerEvent) {
16286
15784
  this.dispatchEvent(new CustomEvent(CanvasEvent.AFTER_DESTROY), enableCancelEventPropagation, enableCancelEventPropagation);
16287
15785
  }
@@ -16300,6 +15798,7 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
16300
15798
  clearEventRetain(insertedEvent);
16301
15799
  clearEventRetain(removedEvent);
16302
15800
  clearEventRetain(destroyEvent);
15801
+ runtime.textService.clearCache();
16303
15802
  }
16304
15803
 
16305
15804
  /**
@@ -16380,7 +15879,6 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
16380
15879
  value: function render(frame) {
16381
15880
  var _this$getConfig$futur2,
16382
15881
  _this4 = this;
16383
- // console.log('render ----------------------');
16384
15882
  if (frame) {
16385
15883
  beforeRenderEvent.detail = frame;
16386
15884
  afterRenderEvent.detail = frame;
@@ -16388,7 +15886,7 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
16388
15886
  var enableCancelEventPropagation = ((_this$getConfig$futur2 = this.getConfig().future) === null || _this$getConfig$futur2 === void 0 ? void 0 : _this$getConfig$futur2.experimentalCancelEventPropagation) === true;
16389
15887
  this.dispatchEvent(beforeRenderEvent, enableCancelEventPropagation, enableCancelEventPropagation);
16390
15888
  var renderingService = this.getRenderingService();
16391
- renderingService.render(this.getConfig(), frame, function () {
15889
+ renderingService.render(this, frame, function () {
16392
15890
  // trigger actual rerender event
16393
15891
  // @see https://github.com/antvis/G/issues/1268
16394
15892
  _this4.dispatchEvent(rerenderEvent, enableCancelEventPropagation, enableCancelEventPropagation);
@@ -16418,9 +15916,6 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
16418
15916
  this.inited = false;
16419
15917
  this.readyPromise = undefined;
16420
15918
 
16421
- // FIXME: should re-create here?
16422
- this.context.rBushRoot = new RBush();
16423
-
16424
15919
  // reset rendering plugins
16425
15920
  this.context.renderingPlugins = [];
16426
15921
  this.context.renderingPlugins.push(new EventPlugin(), new PrepareRendererPlugin(),
@@ -16708,7 +16203,6 @@ exports.Polygon = Polygon;
16708
16203
  exports.Polyline = Polyline;
16709
16204
  exports.PolylineUpdater = PolylineUpdater;
16710
16205
  exports.PropertySyntax = PropertySyntax;
16711
- exports.RBush = RBush;
16712
16206
  exports.Rect = Rect;
16713
16207
  exports.RectUpdater = RectUpdater;
16714
16208
  exports.Rectangle = Rectangle;