@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.js CHANGED
@@ -1,13 +1,14 @@
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
9
  'use strict';
10
10
 
11
+ var RBush = require('rbush/rbush.js');
11
12
  var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
12
13
  var _classCallCheck = require('@babel/runtime/helpers/classCallCheck');
13
14
  var _createClass = require('@babel/runtime/helpers/createClass');
@@ -27,586 +28,6 @@ var _asyncToGenerator = require('@babel/runtime/helpers/asyncToGenerator');
27
28
  var _createForOfIteratorHelper = require('@babel/runtime/helpers/createForOfIteratorHelper');
28
29
  var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
29
30
 
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
31
  var Shape = /*#__PURE__*/function (Shape) {
611
32
  Shape["GROUP"] = "g";
612
33
  Shape["FRAGMENT"] = "fragment";
@@ -7988,7 +7409,7 @@ var SyncWaterfallHook = /*#__PURE__*/function () {
7988
7409
 
7989
7410
  var genericFontFamilies = ['serif', 'sans-serif', 'monospace', 'cursive', 'fantasy', 'system-ui'];
7990
7411
  var stringRegExp = /([\"\'])[^\'\"]+\1/;
7991
- function toFontString(attributes) {
7412
+ function getFontAttr(attributes) {
7992
7413
  var _attributes$fontSize = attributes.fontSize,
7993
7414
  fontSize = _attributes$fontSize === void 0 ? 16 : _attributes$fontSize,
7994
7415
  _attributes$fontFamil = attributes.fontFamily,
@@ -7999,6 +7420,21 @@ function toFontString(attributes) {
7999
7420
  fontVariant = _attributes$fontVaria === void 0 ? 'normal' : _attributes$fontVaria,
8000
7421
  _attributes$fontWeigh = attributes.fontWeight,
8001
7422
  fontWeight = _attributes$fontWeigh === void 0 ? 'normal' : _attributes$fontWeigh;
7423
+ return {
7424
+ fontSize: fontSize,
7425
+ fontFamily: fontFamily,
7426
+ fontStyle: fontStyle,
7427
+ fontVariant: fontVariant,
7428
+ fontWeight: fontWeight
7429
+ };
7430
+ }
7431
+ var toFontString = memoize(function toFontStringRaw(attributes) {
7432
+ var _getFontAttr = getFontAttr(attributes),
7433
+ fontSize = _getFontAttr.fontSize,
7434
+ fontFamily = _getFontAttr.fontFamily,
7435
+ fontStyle = _getFontAttr.fontStyle,
7436
+ fontVariant = _getFontAttr.fontVariant,
7437
+ fontWeight = _getFontAttr.fontWeight;
8002
7438
 
8003
7439
  // build canvas api font setting from individual components. Convert a numeric this.fontSize to px
8004
7440
  // const fontSizeString: string = isNumber(fontSize) ? `${fontSize}px` : fontSize.toString();
@@ -8017,8 +7453,27 @@ function toFontString(attributes) {
8017
7453
  fontFamilies[i] = _fontFamily;
8018
7454
  }
8019
7455
  return "".concat(fontStyle, " ").concat(fontVariant, " ").concat(fontWeight, " ").concat(fontSizeString, " ").concat(fontFamilies.join(','));
8020
- }
7456
+ }, function (attributes) {
7457
+ var _getFontAttr2 = getFontAttr(attributes),
7458
+ fontSize = _getFontAttr2.fontSize,
7459
+ fontFamily = _getFontAttr2.fontFamily,
7460
+ fontStyle = _getFontAttr2.fontStyle,
7461
+ fontVariant = _getFontAttr2.fontVariant,
7462
+ fontWeight = _getFontAttr2.fontWeight;
7463
+ return "".concat(fontStyle, "_").concat(fontVariant, "_").concat(fontWeight, "_").concat(fontSize, "_").concat(fontFamily);
7464
+ });
8021
7465
 
7466
+ /**
7467
+ * Minimum scaling limit
7468
+ *
7469
+ * When `scale` is 0, the matrix will become an irreversible matrix,
7470
+ * and `NaN` will appear during matrix calculation and decomposition,
7471
+ * causing exceptions
7472
+ */
7473
+ var MIN_SCALE = 0.000001;
7474
+ var clampScale = function clampScale(item) {
7475
+ return Math.max(item, MIN_SCALE);
7476
+ };
8022
7477
  function createSkewMatrix(skewMatrix, skewX, skewY) {
8023
7478
  // Create an identity matrix
8024
7479
  glMatrix.mat4.identity(skewMatrix);
@@ -8032,19 +7487,29 @@ var $mat4_1 = glMatrix.mat4.create();
8032
7487
  var $mat4_2 = glMatrix.mat4.create();
8033
7488
  var parser = {
8034
7489
  scale: function scale(d) {
8035
- glMatrix.mat4.fromScaling($mat4_1, [d[0].value, d[1].value, 1]);
7490
+ glMatrix.mat4.fromScaling($mat4_1, [d[0].value, d[1].value, 1].map(function (item) {
7491
+ return clampScale(item);
7492
+ }));
8036
7493
  },
8037
7494
  scaleX: function scaleX(d) {
8038
- glMatrix.mat4.fromScaling($mat4_1, [d[0].value, 1, 1]);
7495
+ glMatrix.mat4.fromScaling($mat4_1, [d[0].value, 1, 1].map(function (item) {
7496
+ return clampScale(item);
7497
+ }));
8039
7498
  },
8040
7499
  scaleY: function scaleY(d) {
8041
- glMatrix.mat4.fromScaling($mat4_1, [1, d[0].value, 1]);
7500
+ glMatrix.mat4.fromScaling($mat4_1, [1, d[0].value, 1].map(function (item) {
7501
+ return clampScale(item);
7502
+ }));
8042
7503
  },
8043
7504
  scaleZ: function scaleZ(d) {
8044
- glMatrix.mat4.fromScaling($mat4_1, [1, 1, d[0].value]);
7505
+ glMatrix.mat4.fromScaling($mat4_1, [1, 1, d[0].value].map(function (item) {
7506
+ return clampScale(item);
7507
+ }));
8045
7508
  },
8046
7509
  scale3d: function scale3d(d) {
8047
- glMatrix.mat4.fromScaling($mat4_1, [d[0].value, d[1].value, d[2].value]);
7510
+ glMatrix.mat4.fromScaling($mat4_1, [d[0].value, d[1].value, d[2].value].map(function (item) {
7511
+ return clampScale(item);
7512
+ }));
8048
7513
  },
8049
7514
  translate: function translate(d) {
8050
7515
  glMatrix.mat4.fromTranslation($mat4_1, [d[0].value, d[1].value, 0]);
@@ -11820,6 +11285,94 @@ var DefaultSceneGraphService = /*#__PURE__*/function () {
11820
11285
  }]);
11821
11286
  }();
11822
11287
 
11288
+ /**
11289
+ * A classic LRU (Least Recently Used) cache implementation.
11290
+ * It evicts the least recently used item when the cache is full.
11291
+ *
11292
+ * It uses a Map for O(1) key-based access
11293
+ * to maintain the usage order of items.
11294
+ *
11295
+ * 通过利用 JavaScript 内置 Map 的特性(按插入顺序迭代),我们不再需要手动维护一个双向链表
11296
+ */
11297
+ var LRU = /*#__PURE__*/function () {
11298
+ function LRU(capacity) {
11299
+ _classCallCheck(this, LRU);
11300
+ if (capacity <= 0) {
11301
+ throw new Error('LRU capacity must be a positive number.');
11302
+ }
11303
+ this.capacity = capacity;
11304
+ // Using a Map directly simplifies the implementation significantly.
11305
+ // A Map in modern JS engines iterates in insertion order, which is exactly what we need.
11306
+ this.cache = new Map();
11307
+ }
11308
+
11309
+ /**
11310
+ * Retrieves an item from the cache. Marks the item as recently used.
11311
+ * @param key The key of the item to retrieve.
11312
+ * @returns The value of the item, or undefined if not found.
11313
+ */
11314
+ return _createClass(LRU, [{
11315
+ key: "get",
11316
+ value: function get(key) {
11317
+ if (!this.cache.has(key)) {
11318
+ return undefined;
11319
+ }
11320
+
11321
+ // Get the value.
11322
+ var value = this.cache.get(key);
11323
+
11324
+ // Mark as recently used by deleting and re-setting the key.
11325
+ // This moves the key to the end of the Map's internal order.
11326
+ this.cache["delete"](key);
11327
+ this.cache.set(key, value);
11328
+ return value;
11329
+ }
11330
+
11331
+ /**
11332
+ * Adds or updates an item in the cache. Marks the item as recently used.
11333
+ * If the cache is full, it removes the least recently used item.
11334
+ * @param key The key of the item.
11335
+ * @param value The value of the item.
11336
+ */
11337
+ }, {
11338
+ key: "put",
11339
+ value: function put(key, value) {
11340
+ // If the key already exists, delete it first to ensure it's moved to the end.
11341
+ if (this.cache.has(key)) {
11342
+ this.cache["delete"](key);
11343
+ }
11344
+
11345
+ // Add the new item. It will be the most recently used.
11346
+ this.cache.set(key, value);
11347
+
11348
+ // Check if the cache has exceeded its capacity.
11349
+ if (this.cache.size > this.capacity) {
11350
+ // Evict the least recently used item, which is the first one in the Map's iteration order.
11351
+ var leastRecentlyUsedKey = this.cache.keys().next().value;
11352
+ this.cache["delete"](leastRecentlyUsedKey);
11353
+ }
11354
+ }
11355
+
11356
+ /**
11357
+ * Returns the current number of items in the cache.
11358
+ */
11359
+ }, {
11360
+ key: "len",
11361
+ value: function len() {
11362
+ return this.cache.size;
11363
+ }
11364
+
11365
+ /**
11366
+ * Clears all items from the cache.
11367
+ */
11368
+ }, {
11369
+ key: "clear",
11370
+ value: function clear() {
11371
+ this.cache.clear();
11372
+ }
11373
+ }]);
11374
+ }();
11375
+
11823
11376
  var TEXT_METRICS = {
11824
11377
  MetricsString: '|ÉqÅ',
11825
11378
  BaselineSymbol: 'M',
@@ -11906,10 +11459,16 @@ var TextService = /*#__PURE__*/function () {
11906
11459
  return next;
11907
11460
  };
11908
11461
  this.runtime = runtime;
11462
+ this.charWidthCache = new LRU(100);
11909
11463
  }
11910
11464
  return _createClass(TextService, [{
11911
11465
  key: "measureFont",
11912
11466
  value:
11467
+ /**
11468
+ * A global cache for character widths, keyed by font string.
11469
+ * e.g. { '16px Arial': { 'a': 8, 'b': 9 } }
11470
+ */
11471
+
11913
11472
  /**
11914
11473
  * Calculates the ascent, descent and fontSize of a given font-style.
11915
11474
  */
@@ -12131,9 +11690,19 @@ var TextService = /*#__PURE__*/function () {
12131
11690
  var currentLineWidth = 0;
12132
11691
  // @see https://github.com/antvis/G/issues/1932
12133
11692
  var prevLineLastCharIndex = -1;
12134
- var cache = {};
12135
- var calcWidth = function calcWidth(txt) {
12136
- return _this2.getFromCache(txt, letterSpacing, cache, context);
11693
+
11694
+ // --- 优化核心 ---
11695
+ // 1. 获取或创建当前字体对应的字符缓存
11696
+ var font = toFontString(parsedStyle);
11697
+ var charCache = this.charWidthCache.get(font);
11698
+ if (!charCache) {
11699
+ charCache = new LRU(500);
11700
+ this.charWidthCache.put(font, charCache);
11701
+ }
11702
+
11703
+ // 2. calcWidth 现在直接使用持久化的 charCache
11704
+ var calcWidth = function calcWidth(_char2) {
11705
+ return _this2.getFromCache(_char2, letterSpacing, charCache, context);
12137
11706
  };
12138
11707
  var ellipsisWidth = calcWidth(ellipsis);
12139
11708
 
@@ -12179,11 +11748,11 @@ var TextService = /*#__PURE__*/function () {
12179
11748
  lines[lineIndex] = result.lineTxt + ellipsis;
12180
11749
  }
12181
11750
  for (var i = 0; i < chars.length; i++) {
12182
- var _char2 = chars[i];
11751
+ var _char3 = chars[i];
12183
11752
  var prevChar = chars[i - 1];
12184
11753
  var nextChar = chars[i + 1];
12185
- var charWidth = calcWidth(_char2);
12186
- if (this.isNewline(_char2)) {
11754
+ var charWidth = calcWidth(_char3);
11755
+ if (this.isNewline(_char3)) {
12187
11756
  // exceed maxLines, break immediately
12188
11757
  if (currentLineIndex + 1 >= maxLines) {
12189
11758
  if (i < chars.length - 1) {
@@ -12213,10 +11782,10 @@ var TextService = /*#__PURE__*/function () {
12213
11782
  break;
12214
11783
  }
12215
11784
  i = result.txtLastCharIndex + 1;
12216
- _char2 = chars[i];
11785
+ _char3 = chars[i];
12217
11786
  prevChar = chars[i - 1];
12218
11787
  nextChar = chars[i + 1];
12219
- charWidth = calcWidth(_char2);
11788
+ charWidth = calcWidth(_char3);
12220
11789
  }
12221
11790
  if (currentLineIndex + 1 >= maxLines) {
12222
11791
  appendEllipsis(currentLineIndex, i - 1);
@@ -12227,38 +11796,38 @@ var TextService = /*#__PURE__*/function () {
12227
11796
  currentLineIndex += 1;
12228
11797
  currentLineWidth = 0;
12229
11798
  lines[currentLineIndex] = '';
12230
- if (this.isBreakingSpace(_char2)) {
11799
+ if (this.isBreakingSpace(_char3)) {
12231
11800
  continue;
12232
11801
  }
12233
- if (!this.canBreakInLastChar(_char2)) {
11802
+ if (!this.canBreakInLastChar(_char3)) {
12234
11803
  lines = this.trimToBreakable(lines);
12235
11804
  currentLineWidth = this.sumTextWidthByCache(lines[currentLineIndex] || '', calcWidth);
12236
11805
  }
12237
- if (this.shouldBreakByKinsokuShorui(_char2, nextChar)) {
11806
+ if (this.shouldBreakByKinsokuShorui(_char3, nextChar)) {
12238
11807
  lines = this.trimByKinsokuShorui(lines);
12239
11808
  currentLineWidth += calcWidth(prevChar || '');
12240
11809
  }
12241
11810
  }
12242
11811
  currentLineWidth += charWidth;
12243
- lines[currentLineIndex] += _char2;
11812
+ lines[currentLineIndex] += _char3;
12244
11813
  }
12245
11814
  return lines.join('\n');
12246
11815
  }
12247
11816
  }, {
12248
11817
  key: "isBreakingSpace",
12249
- value: function isBreakingSpace(_char3) {
12250
- if (typeof _char3 !== 'string') {
11818
+ value: function isBreakingSpace(_char4) {
11819
+ if (typeof _char4 !== 'string') {
12251
11820
  return false;
12252
11821
  }
12253
- return TEXT_METRICS.BreakingSpaces.indexOf(_char3.charCodeAt(0)) >= 0;
11822
+ return TEXT_METRICS.BreakingSpaces.indexOf(_char4.charCodeAt(0)) >= 0;
12254
11823
  }
12255
11824
  }, {
12256
11825
  key: "isNewline",
12257
- value: function isNewline(_char4) {
12258
- if (typeof _char4 !== 'string') {
11826
+ value: function isNewline(_char5) {
11827
+ if (typeof _char5 !== 'string') {
12259
11828
  return false;
12260
11829
  }
12261
- return TEXT_METRICS.Newlines.indexOf(_char4.charCodeAt(0)) >= 0;
11830
+ return TEXT_METRICS.Newlines.indexOf(_char5.charCodeAt(0)) >= 0;
12262
11831
  }
12263
11832
  }, {
12264
11833
  key: "trimToBreakable",
@@ -12277,8 +11846,8 @@ var TextService = /*#__PURE__*/function () {
12277
11846
  }
12278
11847
  }, {
12279
11848
  key: "canBreakInLastChar",
12280
- value: function canBreakInLastChar(_char5) {
12281
- if (_char5 && LATIN_REGEX.test(_char5)) return false;
11849
+ value: function canBreakInLastChar(_char6) {
11850
+ if (_char6 && LATIN_REGEX.test(_char6)) return false;
12282
11851
  return true;
12283
11852
  }
12284
11853
  }, {
@@ -12299,15 +11868,21 @@ var TextService = /*#__PURE__*/function () {
12299
11868
  }, {
12300
11869
  key: "getFromCache",
12301
11870
  value: function getFromCache(key, letterSpacing, cache, context) {
12302
- var width = cache[key];
11871
+ var width = cache.get(key);
12303
11872
  if (typeof width !== 'number') {
12304
11873
  var spacing = key.length * letterSpacing;
12305
11874
  var metrics = context.measureText(key);
12306
11875
  width = metrics.width + spacing;
12307
- cache[key] = width;
11876
+ cache.put(key, width);
12308
11877
  }
12309
11878
  return width;
12310
11879
  }
11880
+ }, {
11881
+ key: "clearCache",
11882
+ value: function clearCache() {
11883
+ this.fontMetricsCache = {};
11884
+ this.charWidthCache.clear();
11885
+ }
12311
11886
  }]);
12312
11887
  }();
12313
11888
 
@@ -13222,6 +12797,34 @@ var DisplayObject = /*#__PURE__*/function (_Element) {
13222
12797
  }
13223
12798
  }
13224
12799
 
12800
+ /**
12801
+ * batch update attributes without attributeChangedCallback, for performance
12802
+ * use with caution
12803
+ * @param attributes
12804
+ * @param parseOptions
12805
+ */
12806
+ }, {
12807
+ key: "setAttributes",
12808
+ value: function setAttributes(attributes) {
12809
+ var parseOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
12810
+ var _parseOptions$skipDis = parseOptions.skipDispatchAttrModifiedEvent,
12811
+ skipDispatchAttrModifiedEvent = _parseOptions$skipDis === void 0 ? false : _parseOptions$skipDis;
12812
+ var oldAttributes;
12813
+ var oldParsedValues;
12814
+ if (!skipDispatchAttrModifiedEvent) {
12815
+ oldAttributes = _objectSpread({}, this.attributes);
12816
+ oldParsedValues = _objectSpread({}, this.parsedStyle);
12817
+ }
12818
+ runtime.styleValueRegistry.processProperties(this, attributes, parseOptions);
12819
+ // redraw at next frame
12820
+ this.dirty();
12821
+ if (!skipDispatchAttrModifiedEvent) {
12822
+ for (var key in attributes) {
12823
+ this.dispatchAttrModifiedEvent(key, oldAttributes[key], attributes[key], oldParsedValues[key]);
12824
+ }
12825
+ }
12826
+ }
12827
+
13225
12828
  /**
13226
12829
  * called when attributes get changed or initialized
13227
12830
  */
@@ -13238,6 +12841,11 @@ var DisplayObject = /*#__PURE__*/function (_Element) {
13238
12841
 
13239
12842
  // return;
13240
12843
 
12844
+ this.dispatchAttrModifiedEvent(name, oldValue, value, oldParsedValue);
12845
+ }
12846
+ }, {
12847
+ key: "dispatchAttrModifiedEvent",
12848
+ value: function dispatchAttrModifiedEvent(name, oldValue, value, oldParsedValue) {
13241
12849
  var newParsedValue = this.parsedStyle[name];
13242
12850
  if (this.isConnected) {
13243
12851
  attrModifiedEvent.relatedNode = this;
@@ -16300,6 +15908,7 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
16300
15908
  clearEventRetain(insertedEvent);
16301
15909
  clearEventRetain(removedEvent);
16302
15910
  clearEventRetain(destroyEvent);
15911
+ runtime.textService.clearCache();
16303
15912
  }
16304
15913
 
16305
15914
  /**
@@ -16648,6 +16257,7 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
16648
16257
  }]);
16649
16258
  }(EventTarget);
16650
16259
 
16260
+ exports.RBush = RBush;
16651
16261
  exports.AABB = AABB;
16652
16262
  exports.AbstractRenderer = AbstractRenderer;
16653
16263
  exports.AbstractRendererPlugin = AbstractRendererPlugin;
@@ -16708,7 +16318,6 @@ exports.Polygon = Polygon;
16708
16318
  exports.Polyline = Polyline;
16709
16319
  exports.PolylineUpdater = PolylineUpdater;
16710
16320
  exports.PropertySyntax = PropertySyntax;
16711
- exports.RBush = RBush;
16712
16321
  exports.Rect = Rect;
16713
16322
  exports.RectUpdater = RectUpdater;
16714
16323
  exports.Rectangle = Rectangle;