@antv/g-lite 2.3.2 → 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.
package/dist/index.js CHANGED
@@ -2,12 +2,13 @@
2
2
  * @antv/g-lite
3
3
  * @description A core module for rendering engine implements DOM API.
4
4
  * @version 2.3.2
5
- * @date 7/30/2025, 1:34:19 PM
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";
@@ -13376,6 +12797,34 @@ var DisplayObject = /*#__PURE__*/function (_Element) {
13376
12797
  }
13377
12798
  }
13378
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
+
13379
12828
  /**
13380
12829
  * called when attributes get changed or initialized
13381
12830
  */
@@ -13392,6 +12841,11 @@ var DisplayObject = /*#__PURE__*/function (_Element) {
13392
12841
 
13393
12842
  // return;
13394
12843
 
12844
+ this.dispatchAttrModifiedEvent(name, oldValue, value, oldParsedValue);
12845
+ }
12846
+ }, {
12847
+ key: "dispatchAttrModifiedEvent",
12848
+ value: function dispatchAttrModifiedEvent(name, oldValue, value, oldParsedValue) {
13395
12849
  var newParsedValue = this.parsedStyle[name];
13396
12850
  if (this.isConnected) {
13397
12851
  attrModifiedEvent.relatedNode = this;
@@ -16803,6 +16257,7 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
16803
16257
  }]);
16804
16258
  }(EventTarget);
16805
16259
 
16260
+ exports.RBush = RBush;
16806
16261
  exports.AABB = AABB;
16807
16262
  exports.AbstractRenderer = AbstractRenderer;
16808
16263
  exports.AbstractRendererPlugin = AbstractRendererPlugin;
@@ -16863,7 +16318,6 @@ exports.Polygon = Polygon;
16863
16318
  exports.Polyline = Polyline;
16864
16319
  exports.PolylineUpdater = PolylineUpdater;
16865
16320
  exports.PropertySyntax = PropertySyntax;
16866
- exports.RBush = RBush;
16867
16321
  exports.Rect = Rect;
16868
16322
  exports.RectUpdater = RectUpdater;
16869
16323
  exports.Rectangle = Rectangle;