@antv/g-lite 2.3.1 → 2.3.3-beta.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 (33) hide show
  1. package/dist/index.esm.js +222 -612
  2. package/dist/index.esm.js.map +1 -1
  3. package/dist/index.js +221 -612
  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 +11 -11
  8. package/types/Canvas.d.ts.map +1 -1
  9. package/types/css/cssom/CSSMathOperator.d.ts +12 -0
  10. package/types/css/cssom/CSSMathOperator.d.ts.map +1 -0
  11. package/types/css/cssom/CSSNumericSumValue.d.ts +8 -0
  12. package/types/css/cssom/CSSNumericSumValue.d.ts.map +1 -0
  13. package/types/css/interfaces.d.ts +1 -0
  14. package/types/css/interfaces.d.ts.map +1 -1
  15. package/types/css/properties/CSSPropertyLocalPosition.d.ts +14 -0
  16. package/types/css/properties/CSSPropertyLocalPosition.d.ts.map +1 -0
  17. package/types/css/properties/CSSPropertyTextDecorationThickness.d.ts +8 -0
  18. package/types/css/properties/CSSPropertyTextDecorationThickness.d.ts.map +1 -0
  19. package/types/display-objects/DisplayObject.d.ts +8 -0
  20. package/types/display-objects/DisplayObject.d.ts.map +1 -1
  21. package/types/dom/MutationObserver.d.ts +19 -0
  22. package/types/dom/MutationObserver.d.ts.map +1 -0
  23. package/types/plugins/MutationObserver.d.ts +49 -0
  24. package/types/plugins/MutationObserver.d.ts.map +1 -0
  25. package/types/services/TextService.d.ts +6 -0
  26. package/types/services/TextService.d.ts.map +1 -1
  27. package/types/utils/LRU.d.ts +36 -0
  28. package/types/utils/LRU.d.ts.map +1 -0
  29. package/types/utils/string.d.ts +6 -0
  30. package/types/utils/string.d.ts.map +1 -0
  31. package/types/utils/text.d.ts +1 -1
  32. package/types/utils/text.d.ts.map +1 -1
  33. package/types/utils/transform-mat4.d.ts.map +1 -1
package/dist/index.esm.js CHANGED
@@ -1,11 +1,13 @@
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.3.2
5
+ * @date 2025/12/2 19:44:23
6
6
  * @author AntVis
7
7
  * @docs https://g.antv.antgroup.com/
8
8
  */
9
+ import RBush from 'rbush/rbush.js';
10
+ export { default as RBush } from 'rbush/rbush.js';
9
11
  import _objectSpread from '@babel/runtime/helpers/objectSpread2';
10
12
  import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
11
13
  import _createClass from '@babel/runtime/helpers/createClass';
@@ -25,586 +27,6 @@ import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
25
27
  import _createForOfIteratorHelper from '@babel/runtime/helpers/createForOfIteratorHelper';
26
28
  import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
27
29
 
28
- var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
29
-
30
- var rbush = {exports: {}};
31
-
32
- (function (module, exports) {
33
- (function (global, factory) {
34
- module.exports = factory() ;
35
- }(commonjsGlobal, function () {
36
- function quickselect(arr, k, left, right, compare) {
37
- quickselectStep(arr, k, left || 0, right || (arr.length - 1), compare || defaultCompare);
38
- }
39
-
40
- function quickselectStep(arr, k, left, right, compare) {
41
-
42
- while (right > left) {
43
- if (right - left > 600) {
44
- var n = right - left + 1;
45
- var m = k - left + 1;
46
- var z = Math.log(n);
47
- var s = 0.5 * Math.exp(2 * z / 3);
48
- var sd = 0.5 * Math.sqrt(z * s * (n - s) / n) * (m - n / 2 < 0 ? -1 : 1);
49
- var newLeft = Math.max(left, Math.floor(k - m * s / n + sd));
50
- var newRight = Math.min(right, Math.floor(k + (n - m) * s / n + sd));
51
- quickselectStep(arr, k, newLeft, newRight, compare);
52
- }
53
-
54
- var t = arr[k];
55
- var i = left;
56
- var j = right;
57
-
58
- swap(arr, left, k);
59
- if (compare(arr[right], t) > 0) { swap(arr, left, right); }
60
-
61
- while (i < j) {
62
- swap(arr, i, j);
63
- i++;
64
- j--;
65
- while (compare(arr[i], t) < 0) { i++; }
66
- while (compare(arr[j], t) > 0) { j--; }
67
- }
68
-
69
- if (compare(arr[left], t) === 0) { swap(arr, left, j); }
70
- else {
71
- j++;
72
- swap(arr, j, right);
73
- }
74
-
75
- if (j <= k) { left = j + 1; }
76
- if (k <= j) { right = j - 1; }
77
- }
78
- }
79
-
80
- function swap(arr, i, j) {
81
- var tmp = arr[i];
82
- arr[i] = arr[j];
83
- arr[j] = tmp;
84
- }
85
-
86
- function defaultCompare(a, b) {
87
- return a < b ? -1 : a > b ? 1 : 0;
88
- }
89
-
90
- var RBush = function RBush(maxEntries) {
91
- if ( maxEntries === void 0 ) maxEntries = 9;
92
-
93
- // max entries in a node is 9 by default; min node fill is 40% for best performance
94
- this._maxEntries = Math.max(4, maxEntries);
95
- this._minEntries = Math.max(2, Math.ceil(this._maxEntries * 0.4));
96
- this.clear();
97
- };
98
-
99
- RBush.prototype.all = function all () {
100
- return this._all(this.data, []);
101
- };
102
-
103
- RBush.prototype.search = function search (bbox) {
104
- var node = this.data;
105
- var result = [];
106
-
107
- if (!intersects(bbox, node)) { return result; }
108
-
109
- var toBBox = this.toBBox;
110
- var nodesToSearch = [];
111
-
112
- while (node) {
113
- for (var i = 0; i < node.children.length; i++) {
114
- var child = node.children[i];
115
- var childBBox = node.leaf ? toBBox(child) : child;
116
-
117
- if (intersects(bbox, childBBox)) {
118
- if (node.leaf) { result.push(child); }
119
- else if (contains(bbox, childBBox)) { this._all(child, result); }
120
- else { nodesToSearch.push(child); }
121
- }
122
- }
123
- node = nodesToSearch.pop();
124
- }
125
-
126
- return result;
127
- };
128
-
129
- RBush.prototype.collides = function collides (bbox) {
130
- var node = this.data;
131
-
132
- if (!intersects(bbox, node)) { return false; }
133
-
134
- var nodesToSearch = [];
135
- while (node) {
136
- for (var i = 0; i < node.children.length; i++) {
137
- var child = node.children[i];
138
- var childBBox = node.leaf ? this.toBBox(child) : child;
139
-
140
- if (intersects(bbox, childBBox)) {
141
- if (node.leaf || contains(bbox, childBBox)) { return true; }
142
- nodesToSearch.push(child);
143
- }
144
- }
145
- node = nodesToSearch.pop();
146
- }
147
-
148
- return false;
149
- };
150
-
151
- RBush.prototype.load = function load (data) {
152
- if (!(data && data.length)) { return this; }
153
-
154
- if (data.length < this._minEntries) {
155
- for (var i = 0; i < data.length; i++) {
156
- this.insert(data[i]);
157
- }
158
- return this;
159
- }
160
-
161
- // recursively build the tree with the given data from scratch using OMT algorithm
162
- var node = this._build(data.slice(), 0, data.length - 1, 0);
163
-
164
- if (!this.data.children.length) {
165
- // save as is if tree is empty
166
- this.data = node;
167
-
168
- } else if (this.data.height === node.height) {
169
- // split root if trees have the same height
170
- this._splitRoot(this.data, node);
171
-
172
- } else {
173
- if (this.data.height < node.height) {
174
- // swap trees if inserted one is bigger
175
- var tmpNode = this.data;
176
- this.data = node;
177
- node = tmpNode;
178
- }
179
-
180
- // insert the small tree into the large tree at appropriate level
181
- this._insert(node, this.data.height - node.height - 1, true);
182
- }
183
-
184
- return this;
185
- };
186
-
187
- RBush.prototype.insert = function insert (item) {
188
- if (item) { this._insert(item, this.data.height - 1); }
189
- return this;
190
- };
191
-
192
- RBush.prototype.clear = function clear () {
193
- this.data = createNode([]);
194
- return this;
195
- };
196
-
197
- RBush.prototype.remove = function remove (item, equalsFn) {
198
- if (!item) { return this; }
199
-
200
- var node = this.data;
201
- var bbox = this.toBBox(item);
202
- var path = [];
203
- var indexes = [];
204
- var i, parent, goingUp;
205
-
206
- // depth-first iterative tree traversal
207
- while (node || path.length) {
208
-
209
- if (!node) { // go up
210
- node = path.pop();
211
- parent = path[path.length - 1];
212
- i = indexes.pop();
213
- goingUp = true;
214
- }
215
-
216
- if (node.leaf) { // check current node
217
- var index = findItem(item, node.children, equalsFn);
218
-
219
- if (index !== -1) {
220
- // item found, remove the item and condense tree upwards
221
- node.children.splice(index, 1);
222
- path.push(node);
223
- this._condense(path);
224
- return this;
225
- }
226
- }
227
-
228
- if (!goingUp && !node.leaf && contains(node, bbox)) { // go down
229
- path.push(node);
230
- indexes.push(i);
231
- i = 0;
232
- parent = node;
233
- node = node.children[0];
234
-
235
- } else if (parent) { // go right
236
- i++;
237
- node = parent.children[i];
238
- goingUp = false;
239
-
240
- } else { node = null; } // nothing found
241
- }
242
-
243
- return this;
244
- };
245
-
246
- RBush.prototype.toBBox = function toBBox (item) { return item; };
247
-
248
- RBush.prototype.compareMinX = function compareMinX (a, b) { return a.minX - b.minX; };
249
- RBush.prototype.compareMinY = function compareMinY (a, b) { return a.minY - b.minY; };
250
-
251
- RBush.prototype.toJSON = function toJSON () { return this.data; };
252
-
253
- RBush.prototype.fromJSON = function fromJSON (data) {
254
- this.data = data;
255
- return this;
256
- };
257
-
258
- RBush.prototype._all = function _all (node, result) {
259
- var nodesToSearch = [];
260
- while (node) {
261
- if (node.leaf) { result.push.apply(result, node.children); }
262
- else { nodesToSearch.push.apply(nodesToSearch, node.children); }
263
-
264
- node = nodesToSearch.pop();
265
- }
266
- return result;
267
- };
268
-
269
- RBush.prototype._build = function _build (items, left, right, height) {
270
-
271
- var N = right - left + 1;
272
- var M = this._maxEntries;
273
- var node;
274
-
275
- if (N <= M) {
276
- // reached leaf level; return leaf
277
- node = createNode(items.slice(left, right + 1));
278
- calcBBox(node, this.toBBox);
279
- return node;
280
- }
281
-
282
- if (!height) {
283
- // target height of the bulk-loaded tree
284
- height = Math.ceil(Math.log(N) / Math.log(M));
285
-
286
- // target number of root entries to maximize storage utilization
287
- M = Math.ceil(N / Math.pow(M, height - 1));
288
- }
289
-
290
- node = createNode([]);
291
- node.leaf = false;
292
- node.height = height;
293
-
294
- // split the items into M mostly square tiles
295
-
296
- var N2 = Math.ceil(N / M);
297
- var N1 = N2 * Math.ceil(Math.sqrt(M));
298
-
299
- multiSelect(items, left, right, N1, this.compareMinX);
300
-
301
- for (var i = left; i <= right; i += N1) {
302
-
303
- var right2 = Math.min(i + N1 - 1, right);
304
-
305
- multiSelect(items, i, right2, N2, this.compareMinY);
306
-
307
- for (var j = i; j <= right2; j += N2) {
308
-
309
- var right3 = Math.min(j + N2 - 1, right2);
310
-
311
- // pack each entry recursively
312
- node.children.push(this._build(items, j, right3, height - 1));
313
- }
314
- }
315
-
316
- calcBBox(node, this.toBBox);
317
-
318
- return node;
319
- };
320
-
321
- RBush.prototype._chooseSubtree = function _chooseSubtree (bbox, node, level, path) {
322
- while (true) {
323
- path.push(node);
324
-
325
- if (node.leaf || path.length - 1 === level) { break; }
326
-
327
- var minArea = Infinity;
328
- var minEnlargement = Infinity;
329
- var targetNode = (void 0);
330
-
331
- for (var i = 0; i < node.children.length; i++) {
332
- var child = node.children[i];
333
- var area = bboxArea(child);
334
- var enlargement = enlargedArea(bbox, child) - area;
335
-
336
- // choose entry with the least area enlargement
337
- if (enlargement < minEnlargement) {
338
- minEnlargement = enlargement;
339
- minArea = area < minArea ? area : minArea;
340
- targetNode = child;
341
-
342
- } else if (enlargement === minEnlargement) {
343
- // otherwise choose one with the smallest area
344
- if (area < minArea) {
345
- minArea = area;
346
- targetNode = child;
347
- }
348
- }
349
- }
350
-
351
- node = targetNode || node.children[0];
352
- }
353
-
354
- return node;
355
- };
356
-
357
- RBush.prototype._insert = function _insert (item, level, isNode) {
358
- var bbox = isNode ? item : this.toBBox(item);
359
- var insertPath = [];
360
-
361
- // find the best node for accommodating the item, saving all nodes along the path too
362
- var node = this._chooseSubtree(bbox, this.data, level, insertPath);
363
-
364
- // put the item into the node
365
- node.children.push(item);
366
- extend(node, bbox);
367
-
368
- // split on node overflow; propagate upwards if necessary
369
- while (level >= 0) {
370
- if (insertPath[level].children.length > this._maxEntries) {
371
- this._split(insertPath, level);
372
- level--;
373
- } else { break; }
374
- }
375
-
376
- // adjust bboxes along the insertion path
377
- this._adjustParentBBoxes(bbox, insertPath, level);
378
- };
379
-
380
- // split overflowed node into two
381
- RBush.prototype._split = function _split (insertPath, level) {
382
- var node = insertPath[level];
383
- var M = node.children.length;
384
- var m = this._minEntries;
385
-
386
- this._chooseSplitAxis(node, m, M);
387
-
388
- var splitIndex = this._chooseSplitIndex(node, m, M);
389
-
390
- var newNode = createNode(node.children.splice(splitIndex, node.children.length - splitIndex));
391
- newNode.height = node.height;
392
- newNode.leaf = node.leaf;
393
-
394
- calcBBox(node, this.toBBox);
395
- calcBBox(newNode, this.toBBox);
396
-
397
- if (level) { insertPath[level - 1].children.push(newNode); }
398
- else { this._splitRoot(node, newNode); }
399
- };
400
-
401
- RBush.prototype._splitRoot = function _splitRoot (node, newNode) {
402
- // split root node
403
- this.data = createNode([node, newNode]);
404
- this.data.height = node.height + 1;
405
- this.data.leaf = false;
406
- calcBBox(this.data, this.toBBox);
407
- };
408
-
409
- RBush.prototype._chooseSplitIndex = function _chooseSplitIndex (node, m, M) {
410
- var index;
411
- var minOverlap = Infinity;
412
- var minArea = Infinity;
413
-
414
- for (var i = m; i <= M - m; i++) {
415
- var bbox1 = distBBox(node, 0, i, this.toBBox);
416
- var bbox2 = distBBox(node, i, M, this.toBBox);
417
-
418
- var overlap = intersectionArea(bbox1, bbox2);
419
- var area = bboxArea(bbox1) + bboxArea(bbox2);
420
-
421
- // choose distribution with minimum overlap
422
- if (overlap < minOverlap) {
423
- minOverlap = overlap;
424
- index = i;
425
-
426
- minArea = area < minArea ? area : minArea;
427
-
428
- } else if (overlap === minOverlap) {
429
- // otherwise choose distribution with minimum area
430
- if (area < minArea) {
431
- minArea = area;
432
- index = i;
433
- }
434
- }
435
- }
436
-
437
- return index || M - m;
438
- };
439
-
440
- // sorts node children by the best axis for split
441
- RBush.prototype._chooseSplitAxis = function _chooseSplitAxis (node, m, M) {
442
- var compareMinX = node.leaf ? this.compareMinX : compareNodeMinX;
443
- var compareMinY = node.leaf ? this.compareMinY : compareNodeMinY;
444
- var xMargin = this._allDistMargin(node, m, M, compareMinX);
445
- var yMargin = this._allDistMargin(node, m, M, compareMinY);
446
-
447
- // if total distributions margin value is minimal for x, sort by minX,
448
- // otherwise it's already sorted by minY
449
- if (xMargin < yMargin) { node.children.sort(compareMinX); }
450
- };
451
-
452
- // total margin of all possible split distributions where each node is at least m full
453
- RBush.prototype._allDistMargin = function _allDistMargin (node, m, M, compare) {
454
- node.children.sort(compare);
455
-
456
- var toBBox = this.toBBox;
457
- var leftBBox = distBBox(node, 0, m, toBBox);
458
- var rightBBox = distBBox(node, M - m, M, toBBox);
459
- var margin = bboxMargin(leftBBox) + bboxMargin(rightBBox);
460
-
461
- for (var i = m; i < M - m; i++) {
462
- var child = node.children[i];
463
- extend(leftBBox, node.leaf ? toBBox(child) : child);
464
- margin += bboxMargin(leftBBox);
465
- }
466
-
467
- for (var i$1 = M - m - 1; i$1 >= m; i$1--) {
468
- var child$1 = node.children[i$1];
469
- extend(rightBBox, node.leaf ? toBBox(child$1) : child$1);
470
- margin += bboxMargin(rightBBox);
471
- }
472
-
473
- return margin;
474
- };
475
-
476
- RBush.prototype._adjustParentBBoxes = function _adjustParentBBoxes (bbox, path, level) {
477
- // adjust bboxes along the given tree path
478
- for (var i = level; i >= 0; i--) {
479
- extend(path[i], bbox);
480
- }
481
- };
482
-
483
- RBush.prototype._condense = function _condense (path) {
484
- // go through the path, removing empty nodes and updating bboxes
485
- for (var i = path.length - 1, siblings = (void 0); i >= 0; i--) {
486
- if (path[i].children.length === 0) {
487
- if (i > 0) {
488
- siblings = path[i - 1].children;
489
- siblings.splice(siblings.indexOf(path[i]), 1);
490
-
491
- } else { this.clear(); }
492
-
493
- } else { calcBBox(path[i], this.toBBox); }
494
- }
495
- };
496
-
497
- function findItem(item, items, equalsFn) {
498
- if (!equalsFn) { return items.indexOf(item); }
499
-
500
- for (var i = 0; i < items.length; i++) {
501
- if (equalsFn(item, items[i])) { return i; }
502
- }
503
- return -1;
504
- }
505
-
506
- // calculate node's bbox from bboxes of its children
507
- function calcBBox(node, toBBox) {
508
- distBBox(node, 0, node.children.length, toBBox, node);
509
- }
510
-
511
- // min bounding rectangle of node children from k to p-1
512
- function distBBox(node, k, p, toBBox, destNode) {
513
- if (!destNode) { destNode = createNode(null); }
514
- destNode.minX = Infinity;
515
- destNode.minY = Infinity;
516
- destNode.maxX = -Infinity;
517
- destNode.maxY = -Infinity;
518
-
519
- for (var i = k; i < p; i++) {
520
- var child = node.children[i];
521
- extend(destNode, node.leaf ? toBBox(child) : child);
522
- }
523
-
524
- return destNode;
525
- }
526
-
527
- function extend(a, b) {
528
- a.minX = Math.min(a.minX, b.minX);
529
- a.minY = Math.min(a.minY, b.minY);
530
- a.maxX = Math.max(a.maxX, b.maxX);
531
- a.maxY = Math.max(a.maxY, b.maxY);
532
- return a;
533
- }
534
-
535
- function compareNodeMinX(a, b) { return a.minX - b.minX; }
536
- function compareNodeMinY(a, b) { return a.minY - b.minY; }
537
-
538
- function bboxArea(a) { return (a.maxX - a.minX) * (a.maxY - a.minY); }
539
- function bboxMargin(a) { return (a.maxX - a.minX) + (a.maxY - a.minY); }
540
-
541
- function enlargedArea(a, b) {
542
- return (Math.max(b.maxX, a.maxX) - Math.min(b.minX, a.minX)) *
543
- (Math.max(b.maxY, a.maxY) - Math.min(b.minY, a.minY));
544
- }
545
-
546
- function intersectionArea(a, b) {
547
- var minX = Math.max(a.minX, b.minX);
548
- var minY = Math.max(a.minY, b.minY);
549
- var maxX = Math.min(a.maxX, b.maxX);
550
- var maxY = Math.min(a.maxY, b.maxY);
551
-
552
- return Math.max(0, maxX - minX) *
553
- Math.max(0, maxY - minY);
554
- }
555
-
556
- function contains(a, b) {
557
- return a.minX <= b.minX &&
558
- a.minY <= b.minY &&
559
- b.maxX <= a.maxX &&
560
- b.maxY <= a.maxY;
561
- }
562
-
563
- function intersects(a, b) {
564
- return b.minX <= a.maxX &&
565
- b.minY <= a.maxY &&
566
- b.maxX >= a.minX &&
567
- b.maxY >= a.minY;
568
- }
569
-
570
- function createNode(children) {
571
- return {
572
- children: children,
573
- height: 1,
574
- leaf: true,
575
- minX: Infinity,
576
- minY: Infinity,
577
- maxX: -Infinity,
578
- maxY: -Infinity
579
- };
580
- }
581
-
582
- // sort an array so that items come in groups of n unsorted items, with groups sorted between each other;
583
- // combines selection algorithm with binary divide & conquer approach
584
-
585
- function multiSelect(arr, left, right, n, compare) {
586
- var stack = [left, right];
587
-
588
- while (stack.length) {
589
- right = stack.pop();
590
- left = stack.pop();
591
-
592
- if (right - left <= n) { continue; }
593
-
594
- var mid = left + Math.ceil((right - left) / n / 2) * n;
595
- quickselect(arr, mid, left, right, compare);
596
-
597
- stack.push(left, mid, mid, right);
598
- }
599
- }
600
-
601
- return RBush;
602
-
603
- }));
604
- }(rbush));
605
-
606
- var RBush = rbush.exports;
607
-
608
30
  var Shape = /*#__PURE__*/function (Shape) {
609
31
  Shape["GROUP"] = "g";
610
32
  Shape["FRAGMENT"] = "fragment";
@@ -7986,7 +7408,7 @@ var SyncWaterfallHook = /*#__PURE__*/function () {
7986
7408
 
7987
7409
  var genericFontFamilies = ['serif', 'sans-serif', 'monospace', 'cursive', 'fantasy', 'system-ui'];
7988
7410
  var stringRegExp = /([\"\'])[^\'\"]+\1/;
7989
- function toFontString(attributes) {
7411
+ function getFontAttr(attributes) {
7990
7412
  var _attributes$fontSize = attributes.fontSize,
7991
7413
  fontSize = _attributes$fontSize === void 0 ? 16 : _attributes$fontSize,
7992
7414
  _attributes$fontFamil = attributes.fontFamily,
@@ -7997,6 +7419,21 @@ function toFontString(attributes) {
7997
7419
  fontVariant = _attributes$fontVaria === void 0 ? 'normal' : _attributes$fontVaria,
7998
7420
  _attributes$fontWeigh = attributes.fontWeight,
7999
7421
  fontWeight = _attributes$fontWeigh === void 0 ? 'normal' : _attributes$fontWeigh;
7422
+ return {
7423
+ fontSize: fontSize,
7424
+ fontFamily: fontFamily,
7425
+ fontStyle: fontStyle,
7426
+ fontVariant: fontVariant,
7427
+ fontWeight: fontWeight
7428
+ };
7429
+ }
7430
+ var toFontString = memoize(function toFontStringRaw(attributes) {
7431
+ var _getFontAttr = getFontAttr(attributes),
7432
+ fontSize = _getFontAttr.fontSize,
7433
+ fontFamily = _getFontAttr.fontFamily,
7434
+ fontStyle = _getFontAttr.fontStyle,
7435
+ fontVariant = _getFontAttr.fontVariant,
7436
+ fontWeight = _getFontAttr.fontWeight;
8000
7437
 
8001
7438
  // build canvas api font setting from individual components. Convert a numeric this.fontSize to px
8002
7439
  // const fontSizeString: string = isNumber(fontSize) ? `${fontSize}px` : fontSize.toString();
@@ -8015,8 +7452,27 @@ function toFontString(attributes) {
8015
7452
  fontFamilies[i] = _fontFamily;
8016
7453
  }
8017
7454
  return "".concat(fontStyle, " ").concat(fontVariant, " ").concat(fontWeight, " ").concat(fontSizeString, " ").concat(fontFamilies.join(','));
8018
- }
7455
+ }, function (attributes) {
7456
+ var _getFontAttr2 = getFontAttr(attributes),
7457
+ fontSize = _getFontAttr2.fontSize,
7458
+ fontFamily = _getFontAttr2.fontFamily,
7459
+ fontStyle = _getFontAttr2.fontStyle,
7460
+ fontVariant = _getFontAttr2.fontVariant,
7461
+ fontWeight = _getFontAttr2.fontWeight;
7462
+ return "".concat(fontStyle, "_").concat(fontVariant, "_").concat(fontWeight, "_").concat(fontSize, "_").concat(fontFamily);
7463
+ });
8019
7464
 
7465
+ /**
7466
+ * Minimum scaling limit
7467
+ *
7468
+ * When `scale` is 0, the matrix will become an irreversible matrix,
7469
+ * and `NaN` will appear during matrix calculation and decomposition,
7470
+ * causing exceptions
7471
+ */
7472
+ var MIN_SCALE = 0.000001;
7473
+ var clampScale = function clampScale(item) {
7474
+ return Math.max(item, MIN_SCALE);
7475
+ };
8020
7476
  function createSkewMatrix(skewMatrix, skewX, skewY) {
8021
7477
  // Create an identity matrix
8022
7478
  mat4.identity(skewMatrix);
@@ -8030,19 +7486,29 @@ var $mat4_1 = mat4.create();
8030
7486
  var $mat4_2 = mat4.create();
8031
7487
  var parser = {
8032
7488
  scale: function scale(d) {
8033
- mat4.fromScaling($mat4_1, [d[0].value, d[1].value, 1]);
7489
+ mat4.fromScaling($mat4_1, [d[0].value, d[1].value, 1].map(function (item) {
7490
+ return clampScale(item);
7491
+ }));
8034
7492
  },
8035
7493
  scaleX: function scaleX(d) {
8036
- mat4.fromScaling($mat4_1, [d[0].value, 1, 1]);
7494
+ mat4.fromScaling($mat4_1, [d[0].value, 1, 1].map(function (item) {
7495
+ return clampScale(item);
7496
+ }));
8037
7497
  },
8038
7498
  scaleY: function scaleY(d) {
8039
- mat4.fromScaling($mat4_1, [1, d[0].value, 1]);
7499
+ mat4.fromScaling($mat4_1, [1, d[0].value, 1].map(function (item) {
7500
+ return clampScale(item);
7501
+ }));
8040
7502
  },
8041
7503
  scaleZ: function scaleZ(d) {
8042
- mat4.fromScaling($mat4_1, [1, 1, d[0].value]);
7504
+ mat4.fromScaling($mat4_1, [1, 1, d[0].value].map(function (item) {
7505
+ return clampScale(item);
7506
+ }));
8043
7507
  },
8044
7508
  scale3d: function scale3d(d) {
8045
- mat4.fromScaling($mat4_1, [d[0].value, d[1].value, d[2].value]);
7509
+ mat4.fromScaling($mat4_1, [d[0].value, d[1].value, d[2].value].map(function (item) {
7510
+ return clampScale(item);
7511
+ }));
8046
7512
  },
8047
7513
  translate: function translate(d) {
8048
7514
  mat4.fromTranslation($mat4_1, [d[0].value, d[1].value, 0]);
@@ -11818,6 +11284,94 @@ var DefaultSceneGraphService = /*#__PURE__*/function () {
11818
11284
  }]);
11819
11285
  }();
11820
11286
 
11287
+ /**
11288
+ * A classic LRU (Least Recently Used) cache implementation.
11289
+ * It evicts the least recently used item when the cache is full.
11290
+ *
11291
+ * It uses a Map for O(1) key-based access
11292
+ * to maintain the usage order of items.
11293
+ *
11294
+ * 通过利用 JavaScript 内置 Map 的特性(按插入顺序迭代),我们不再需要手动维护一个双向链表
11295
+ */
11296
+ var LRU = /*#__PURE__*/function () {
11297
+ function LRU(capacity) {
11298
+ _classCallCheck(this, LRU);
11299
+ if (capacity <= 0) {
11300
+ throw new Error('LRU capacity must be a positive number.');
11301
+ }
11302
+ this.capacity = capacity;
11303
+ // Using a Map directly simplifies the implementation significantly.
11304
+ // A Map in modern JS engines iterates in insertion order, which is exactly what we need.
11305
+ this.cache = new Map();
11306
+ }
11307
+
11308
+ /**
11309
+ * Retrieves an item from the cache. Marks the item as recently used.
11310
+ * @param key The key of the item to retrieve.
11311
+ * @returns The value of the item, or undefined if not found.
11312
+ */
11313
+ return _createClass(LRU, [{
11314
+ key: "get",
11315
+ value: function get(key) {
11316
+ if (!this.cache.has(key)) {
11317
+ return undefined;
11318
+ }
11319
+
11320
+ // Get the value.
11321
+ var value = this.cache.get(key);
11322
+
11323
+ // Mark as recently used by deleting and re-setting the key.
11324
+ // This moves the key to the end of the Map's internal order.
11325
+ this.cache["delete"](key);
11326
+ this.cache.set(key, value);
11327
+ return value;
11328
+ }
11329
+
11330
+ /**
11331
+ * Adds or updates an item in the cache. Marks the item as recently used.
11332
+ * If the cache is full, it removes the least recently used item.
11333
+ * @param key The key of the item.
11334
+ * @param value The value of the item.
11335
+ */
11336
+ }, {
11337
+ key: "put",
11338
+ value: function put(key, value) {
11339
+ // If the key already exists, delete it first to ensure it's moved to the end.
11340
+ if (this.cache.has(key)) {
11341
+ this.cache["delete"](key);
11342
+ }
11343
+
11344
+ // Add the new item. It will be the most recently used.
11345
+ this.cache.set(key, value);
11346
+
11347
+ // Check if the cache has exceeded its capacity.
11348
+ if (this.cache.size > this.capacity) {
11349
+ // Evict the least recently used item, which is the first one in the Map's iteration order.
11350
+ var leastRecentlyUsedKey = this.cache.keys().next().value;
11351
+ this.cache["delete"](leastRecentlyUsedKey);
11352
+ }
11353
+ }
11354
+
11355
+ /**
11356
+ * Returns the current number of items in the cache.
11357
+ */
11358
+ }, {
11359
+ key: "len",
11360
+ value: function len() {
11361
+ return this.cache.size;
11362
+ }
11363
+
11364
+ /**
11365
+ * Clears all items from the cache.
11366
+ */
11367
+ }, {
11368
+ key: "clear",
11369
+ value: function clear() {
11370
+ this.cache.clear();
11371
+ }
11372
+ }]);
11373
+ }();
11374
+
11821
11375
  var TEXT_METRICS = {
11822
11376
  MetricsString: '|ÉqÅ',
11823
11377
  BaselineSymbol: 'M',
@@ -11904,10 +11458,16 @@ var TextService = /*#__PURE__*/function () {
11904
11458
  return next;
11905
11459
  };
11906
11460
  this.runtime = runtime;
11461
+ this.charWidthCache = new LRU(100);
11907
11462
  }
11908
11463
  return _createClass(TextService, [{
11909
11464
  key: "measureFont",
11910
11465
  value:
11466
+ /**
11467
+ * A global cache for character widths, keyed by font string.
11468
+ * e.g. { '16px Arial': { 'a': 8, 'b': 9 } }
11469
+ */
11470
+
11911
11471
  /**
11912
11472
  * Calculates the ascent, descent and fontSize of a given font-style.
11913
11473
  */
@@ -12129,9 +11689,19 @@ var TextService = /*#__PURE__*/function () {
12129
11689
  var currentLineWidth = 0;
12130
11690
  // @see https://github.com/antvis/G/issues/1932
12131
11691
  var prevLineLastCharIndex = -1;
12132
- var cache = {};
12133
- var calcWidth = function calcWidth(txt) {
12134
- return _this2.getFromCache(txt, letterSpacing, cache, context);
11692
+
11693
+ // --- 优化核心 ---
11694
+ // 1. 获取或创建当前字体对应的字符缓存
11695
+ var font = toFontString(parsedStyle);
11696
+ var charCache = this.charWidthCache.get(font);
11697
+ if (!charCache) {
11698
+ charCache = new LRU(500);
11699
+ this.charWidthCache.put(font, charCache);
11700
+ }
11701
+
11702
+ // 2. calcWidth 现在直接使用持久化的 charCache
11703
+ var calcWidth = function calcWidth(_char2) {
11704
+ return _this2.getFromCache(_char2, letterSpacing, charCache, context);
12135
11705
  };
12136
11706
  var ellipsisWidth = calcWidth(ellipsis);
12137
11707
 
@@ -12177,11 +11747,11 @@ var TextService = /*#__PURE__*/function () {
12177
11747
  lines[lineIndex] = result.lineTxt + ellipsis;
12178
11748
  }
12179
11749
  for (var i = 0; i < chars.length; i++) {
12180
- var _char2 = chars[i];
11750
+ var _char3 = chars[i];
12181
11751
  var prevChar = chars[i - 1];
12182
11752
  var nextChar = chars[i + 1];
12183
- var charWidth = calcWidth(_char2);
12184
- if (this.isNewline(_char2)) {
11753
+ var charWidth = calcWidth(_char3);
11754
+ if (this.isNewline(_char3)) {
12185
11755
  // exceed maxLines, break immediately
12186
11756
  if (currentLineIndex + 1 >= maxLines) {
12187
11757
  if (i < chars.length - 1) {
@@ -12211,10 +11781,10 @@ var TextService = /*#__PURE__*/function () {
12211
11781
  break;
12212
11782
  }
12213
11783
  i = result.txtLastCharIndex + 1;
12214
- _char2 = chars[i];
11784
+ _char3 = chars[i];
12215
11785
  prevChar = chars[i - 1];
12216
11786
  nextChar = chars[i + 1];
12217
- charWidth = calcWidth(_char2);
11787
+ charWidth = calcWidth(_char3);
12218
11788
  }
12219
11789
  if (currentLineIndex + 1 >= maxLines) {
12220
11790
  appendEllipsis(currentLineIndex, i - 1);
@@ -12225,38 +11795,38 @@ var TextService = /*#__PURE__*/function () {
12225
11795
  currentLineIndex += 1;
12226
11796
  currentLineWidth = 0;
12227
11797
  lines[currentLineIndex] = '';
12228
- if (this.isBreakingSpace(_char2)) {
11798
+ if (this.isBreakingSpace(_char3)) {
12229
11799
  continue;
12230
11800
  }
12231
- if (!this.canBreakInLastChar(_char2)) {
11801
+ if (!this.canBreakInLastChar(_char3)) {
12232
11802
  lines = this.trimToBreakable(lines);
12233
11803
  currentLineWidth = this.sumTextWidthByCache(lines[currentLineIndex] || '', calcWidth);
12234
11804
  }
12235
- if (this.shouldBreakByKinsokuShorui(_char2, nextChar)) {
11805
+ if (this.shouldBreakByKinsokuShorui(_char3, nextChar)) {
12236
11806
  lines = this.trimByKinsokuShorui(lines);
12237
11807
  currentLineWidth += calcWidth(prevChar || '');
12238
11808
  }
12239
11809
  }
12240
11810
  currentLineWidth += charWidth;
12241
- lines[currentLineIndex] += _char2;
11811
+ lines[currentLineIndex] += _char3;
12242
11812
  }
12243
11813
  return lines.join('\n');
12244
11814
  }
12245
11815
  }, {
12246
11816
  key: "isBreakingSpace",
12247
- value: function isBreakingSpace(_char3) {
12248
- if (typeof _char3 !== 'string') {
11817
+ value: function isBreakingSpace(_char4) {
11818
+ if (typeof _char4 !== 'string') {
12249
11819
  return false;
12250
11820
  }
12251
- return TEXT_METRICS.BreakingSpaces.indexOf(_char3.charCodeAt(0)) >= 0;
11821
+ return TEXT_METRICS.BreakingSpaces.indexOf(_char4.charCodeAt(0)) >= 0;
12252
11822
  }
12253
11823
  }, {
12254
11824
  key: "isNewline",
12255
- value: function isNewline(_char4) {
12256
- if (typeof _char4 !== 'string') {
11825
+ value: function isNewline(_char5) {
11826
+ if (typeof _char5 !== 'string') {
12257
11827
  return false;
12258
11828
  }
12259
- return TEXT_METRICS.Newlines.indexOf(_char4.charCodeAt(0)) >= 0;
11829
+ return TEXT_METRICS.Newlines.indexOf(_char5.charCodeAt(0)) >= 0;
12260
11830
  }
12261
11831
  }, {
12262
11832
  key: "trimToBreakable",
@@ -12275,8 +11845,8 @@ var TextService = /*#__PURE__*/function () {
12275
11845
  }
12276
11846
  }, {
12277
11847
  key: "canBreakInLastChar",
12278
- value: function canBreakInLastChar(_char5) {
12279
- if (_char5 && LATIN_REGEX.test(_char5)) return false;
11848
+ value: function canBreakInLastChar(_char6) {
11849
+ if (_char6 && LATIN_REGEX.test(_char6)) return false;
12280
11850
  return true;
12281
11851
  }
12282
11852
  }, {
@@ -12297,15 +11867,21 @@ var TextService = /*#__PURE__*/function () {
12297
11867
  }, {
12298
11868
  key: "getFromCache",
12299
11869
  value: function getFromCache(key, letterSpacing, cache, context) {
12300
- var width = cache[key];
11870
+ var width = cache.get(key);
12301
11871
  if (typeof width !== 'number') {
12302
11872
  var spacing = key.length * letterSpacing;
12303
11873
  var metrics = context.measureText(key);
12304
11874
  width = metrics.width + spacing;
12305
- cache[key] = width;
11875
+ cache.put(key, width);
12306
11876
  }
12307
11877
  return width;
12308
11878
  }
11879
+ }, {
11880
+ key: "clearCache",
11881
+ value: function clearCache() {
11882
+ this.fontMetricsCache = {};
11883
+ this.charWidthCache.clear();
11884
+ }
12309
11885
  }]);
12310
11886
  }();
12311
11887
 
@@ -13220,6 +12796,34 @@ var DisplayObject = /*#__PURE__*/function (_Element) {
13220
12796
  }
13221
12797
  }
13222
12798
 
12799
+ /**
12800
+ * batch update attributes without attributeChangedCallback, for performance
12801
+ * use with caution
12802
+ * @param attributes
12803
+ * @param parseOptions
12804
+ */
12805
+ }, {
12806
+ key: "setAttributes",
12807
+ value: function setAttributes(attributes) {
12808
+ var parseOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
12809
+ var _parseOptions$skipDis = parseOptions.skipDispatchAttrModifiedEvent,
12810
+ skipDispatchAttrModifiedEvent = _parseOptions$skipDis === void 0 ? false : _parseOptions$skipDis;
12811
+ var oldAttributes;
12812
+ var oldParsedValues;
12813
+ if (!skipDispatchAttrModifiedEvent) {
12814
+ oldAttributes = _objectSpread({}, this.attributes);
12815
+ oldParsedValues = _objectSpread({}, this.parsedStyle);
12816
+ }
12817
+ runtime.styleValueRegistry.processProperties(this, attributes, parseOptions);
12818
+ // redraw at next frame
12819
+ this.dirty();
12820
+ if (!skipDispatchAttrModifiedEvent) {
12821
+ for (var key in attributes) {
12822
+ this.dispatchAttrModifiedEvent(key, oldAttributes[key], attributes[key], oldParsedValues[key]);
12823
+ }
12824
+ }
12825
+ }
12826
+
13223
12827
  /**
13224
12828
  * called when attributes get changed or initialized
13225
12829
  */
@@ -13236,6 +12840,11 @@ var DisplayObject = /*#__PURE__*/function (_Element) {
13236
12840
 
13237
12841
  // return;
13238
12842
 
12843
+ this.dispatchAttrModifiedEvent(name, oldValue, value, oldParsedValue);
12844
+ }
12845
+ }, {
12846
+ key: "dispatchAttrModifiedEvent",
12847
+ value: function dispatchAttrModifiedEvent(name, oldValue, value, oldParsedValue) {
13239
12848
  var newParsedValue = this.parsedStyle[name];
13240
12849
  if (this.isConnected) {
13241
12850
  attrModifiedEvent.relatedNode = this;
@@ -16298,6 +15907,7 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
16298
15907
  clearEventRetain(insertedEvent);
16299
15908
  clearEventRetain(removedEvent);
16300
15909
  clearEventRetain(destroyEvent);
15910
+ runtime.textService.clearCache();
16301
15911
  }
16302
15912
 
16303
15913
  /**
@@ -16646,5 +16256,5 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
16646
16256
  }]);
16647
16257
  }(EventTarget);
16648
16258
 
16649
- export { AABB, AbstractRenderer, AbstractRendererPlugin, BUILT_IN_PROPERTIES, CSS, CSSGradientValue, CSSKeywordValue, CSSRGB, CSSStyleValue, CSSUnitValue, Camera, CameraEvent, CameraProjectionMode, CameraTrackingMode, CameraType, Canvas, CanvasEvent, Circle, CircleUpdater, ClipSpaceNearZ, CustomElement, CustomElementRegistry, CustomEvent, DefaultSceneGraphSelector, DefaultSceneGraphService, DisplayObject, Document, ERROR_MSG_METHOD_NOT_IMPLEMENTED, Element, ElementEvent, Ellipse, EllipseUpdater, EventService, EventTarget, FederatedEvent, FederatedMouseEvent, FederatedPointerEvent, FederatedWheelEvent, Fragment, Frustum, GradientType, Group, GroupUpdater, HTML, HTMLUpdater, Image, Line, LineUpdater, Mask, MutationEvent, Node, OffscreenCanvasCreator, Path, PathUpdater, Plane, Point, Polygon, Polyline, PolylineUpdater, PropertySyntax, RBush, Rect, RectUpdater, Rectangle, RenderReason, RenderingService, Shape, SortReason, Strategy, Text, TextService, TextUpdater, UnitType, attrModifiedEvent, computeLinearGradient, computeRadialGradient, convertToPath, createVec3, decompose, definedProps, deg2rad, deg2turn, destroyEvent, findClosestClipPathTarget, fromRotationTranslationScale, getAngle, getEuler, getOrCalculatePathTotalLength, grad2deg, insertedEvent, isBrowser, isCSSGradientValue, isCSSRGB, isCanvas, isDisplayObject, isFederatedEvent, isFillOrStrokeAffected, isPattern, mergeColors, parseColor, parseLength, parsePath, parseTransform, parsedTransformToMat4, propertyMetadataCache, rad2deg, removedEvent, resetEntityCounter, runtime, setDOMSize, translatePathToString, turn2deg, updateLocalTransform, updateWorldTransform };
16259
+ export { AABB, AbstractRenderer, AbstractRendererPlugin, BUILT_IN_PROPERTIES, CSS, CSSGradientValue, CSSKeywordValue, CSSRGB, CSSStyleValue, CSSUnitValue, Camera, CameraEvent, CameraProjectionMode, CameraTrackingMode, CameraType, Canvas, CanvasEvent, Circle, CircleUpdater, ClipSpaceNearZ, CustomElement, CustomElementRegistry, CustomEvent, DefaultSceneGraphSelector, DefaultSceneGraphService, DisplayObject, Document, ERROR_MSG_METHOD_NOT_IMPLEMENTED, Element, ElementEvent, Ellipse, EllipseUpdater, EventService, EventTarget, FederatedEvent, FederatedMouseEvent, FederatedPointerEvent, FederatedWheelEvent, Fragment, Frustum, GradientType, Group, GroupUpdater, HTML, HTMLUpdater, Image, Line, LineUpdater, Mask, MutationEvent, Node, OffscreenCanvasCreator, Path, PathUpdater, Plane, Point, Polygon, Polyline, PolylineUpdater, PropertySyntax, Rect, RectUpdater, Rectangle, RenderReason, RenderingService, Shape, SortReason, Strategy, Text, TextService, TextUpdater, UnitType, attrModifiedEvent, computeLinearGradient, computeRadialGradient, convertToPath, createVec3, decompose, definedProps, deg2rad, deg2turn, destroyEvent, findClosestClipPathTarget, fromRotationTranslationScale, getAngle, getEuler, getOrCalculatePathTotalLength, grad2deg, insertedEvent, isBrowser, isCSSGradientValue, isCSSRGB, isCanvas, isDisplayObject, isFederatedEvent, isFillOrStrokeAffected, isPattern, mergeColors, parseColor, parseLength, parsePath, parseTransform, parsedTransformToMat4, propertyMetadataCache, rad2deg, removedEvent, resetEntityCounter, runtime, setDOMSize, translatePathToString, turn2deg, updateLocalTransform, updateWorldTransform };
16650
16260
  //# sourceMappingURL=index.esm.js.map