@tspro/ts-utils-lib 1.19.0 → 1.20.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
@@ -1,4 +1,4 @@
1
- /* TsUtilsLib v1.19.0 | (c) 2023 PahkaSoft | Licensed under the MIT License */
1
+ /* TsUtilsLib v1.20.0 | (c) 2023 PahkaSoft | Licensed under the MIT License */
2
2
  "use strict";
3
3
  var __defProp = Object.defineProperty;
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -24,20 +24,31 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
24
24
  var index_exports = {};
25
25
  __export(index_exports, {
26
26
  Assert: () => assert_exports,
27
+ BaseContainer: () => BaseContainer,
28
+ BiMap: () => BiMap,
27
29
  Cookies: () => cookies_exports,
30
+ DeepSet: () => DeepSet,
31
+ DefaultArray: () => DefaultArray,
32
+ DefaultEqualityFn: () => DefaultEqualityFn,
28
33
  Device: () => device_exports,
29
34
  DivRect: () => DivRect,
30
35
  Guard: () => guard_exports,
31
36
  IndexArray: () => IndexArray,
32
37
  LRUCache: () => LRUCache,
38
+ LinkedList: () => LinkedList,
33
39
  Map1: () => Map1,
34
40
  Map2: () => Map2,
35
41
  Map3: () => Map3,
36
42
  MultiContainer: () => MultiContainer,
43
+ Set1: () => Set1,
44
+ SetBase: () => SetBase,
37
45
  SignedIndexArray: () => SignedIndexArray,
38
46
  SmallIntCache: () => SmallIntCache,
39
47
  Stack: () => Stack,
48
+ TriMap: () => TriMap,
49
+ UniMap: () => UniMap,
40
50
  Utils: () => utils_exports,
51
+ ValueSet: () => ValueSet,
41
52
  Vec: () => Vec,
42
53
  Vec2: () => Vec2,
43
54
  asMulti: () => asMulti
@@ -101,6 +112,7 @@ __export(assert_exports, {
101
112
  isNonEmptyArrayOrUndefined: () => isNonEmptyArrayOrUndefined,
102
113
  isNonEmptyString: () => isNonEmptyString,
103
114
  isNonEmptyStringOrUndefined: () => isNonEmptyStringOrUndefined,
115
+ isNotThrowing: () => isNotThrowing,
104
116
  isNull: () => isNull,
105
117
  isNullish: () => isNullish,
106
118
  isNumber: () => isNumber,
@@ -496,6 +508,11 @@ function isThrowing(throwTestFn, msg) {
496
508
  _fail(`Expected to throw`, msg);
497
509
  return true;
498
510
  }
511
+ function isNotThrowing(throwTestFn, msg) {
512
+ if (!guard_exports.isNotThrowing(throwTestFn))
513
+ _fail(`Expected to throw`, msg);
514
+ return true;
515
+ }
499
516
 
500
517
  // src/web/cookies.ts
501
518
  var cookies_exports = {};
@@ -743,6 +760,7 @@ __export(guard_exports, {
743
760
  isNonEmptyArrayOrUndefined: () => isNonEmptyArrayOrUndefined2,
744
761
  isNonEmptyString: () => isNonEmptyString2,
745
762
  isNonEmptyStringOrUndefined: () => isNonEmptyStringOrUndefined2,
763
+ isNotThrowing: () => isNotThrowing2,
746
764
  isNull: () => isNull2,
747
765
  isNullish: () => isNullish2,
748
766
  isNumber: () => isNumber2,
@@ -992,6 +1010,14 @@ function isThrowing2(throwTestFn) {
992
1010
  return true;
993
1011
  }
994
1012
  }
1013
+ function isNotThrowing2(throwTestFn) {
1014
+ try {
1015
+ throwTestFn();
1016
+ return true;
1017
+ } catch (err) {
1018
+ return false;
1019
+ }
1020
+ }
995
1021
  function tryOr(tryFn, orVal) {
996
1022
  try {
997
1023
  return tryFn();
@@ -1425,99 +1451,19 @@ __export(str_exports, {
1425
1451
  removeAt: () => removeAt,
1426
1452
  repeatString: () => repeatString,
1427
1453
  replaceAt: () => replaceAt,
1454
+ stringify: () => stringify,
1428
1455
  toCharArray: () => toCharArray
1429
1456
  });
1430
- function toCharArray(str2) {
1431
- return str2.split("");
1432
- }
1433
- function repeatString(repeatString2, repeatCount) {
1434
- if (!isInteger2(repeatCount) || repeatCount < 0) {
1435
- throw new Error("repeatStr: Invalid repeatCount = " + repeatCount);
1436
- }
1437
- return new Array(repeatCount + 1).join(repeatString2);
1438
- }
1439
- function chunkString(str2, chunkSize) {
1440
- if (!isInteger2(chunkSize) || chunkSize < 1) {
1441
- throw new Error("chunckString: Invalid chuckSize = " + chunkSize);
1442
- }
1443
- let result = [];
1444
- for (let i = 0; i < str2.length; i += chunkSize) {
1445
- result.push(str2.slice(i, i + chunkSize));
1446
- }
1447
- return result;
1448
- }
1449
- function replaceAt(str2, pos, removeCount, insert) {
1450
- if (!isInteger2(removeCount) || removeCount < 0) {
1451
- throw new Error("replaceAt: Invalid removeCount = " + removeCount);
1452
- } else if (!isInteger2(pos) || pos < 0 || pos + removeCount > str2.length) {
1453
- throw new Error("replaceAt: Invalid pos = " + pos + ", removeCount = " + removeCount + ", str.length = " + str2.length);
1454
- } else {
1455
- return str2.substring(0, pos) + insert + str2.substring(pos + removeCount);
1456
- }
1457
- }
1458
- function insertAt(str2, pos, insertStr) {
1459
- return replaceAt(str2, pos, 0, insertStr);
1460
- }
1461
- function removeAt(str2, pos, removeCount) {
1462
- return replaceAt(str2, pos, removeCount, "");
1463
- }
1464
- function charCount(str2, ch) {
1465
- if (ch.length !== 1 || str2.length === 0) return 0;
1466
- let count = 0;
1467
- for (let i = 0; i < str2.length; i++) {
1468
- if (str2[i] === ch) count++;
1469
- }
1470
- return count;
1471
- }
1472
- function makeSentenceFromPascal(PascalString) {
1473
- if (PascalString === "") {
1474
- return "";
1475
- }
1476
- let word = PascalString.charAt(0);
1477
- let sentence = "";
1478
- const addWord = () => {
1479
- if (word !== "") {
1480
- if (sentence === "") {
1481
- sentence += word.charAt(0).toUpperCase() + word.substring(1);
1482
- } else {
1483
- sentence += " " + word;
1484
- }
1485
- word = "";
1486
- }
1487
- };
1488
- const isLetterAndCapital = (c) => {
1489
- return c.toUpperCase() !== c.toLowerCase() && c === c.toUpperCase();
1490
- };
1491
- for (let i = 1; i < PascalString.length; i++) {
1492
- let c = PascalString.charAt(i);
1493
- if (isLetterAndCapital(c)) {
1494
- addWord();
1495
- }
1496
- word += c.toLowerCase();
1497
- }
1498
- addWord();
1499
- return sentence;
1500
- }
1501
-
1502
- // src/utils/index.ts
1503
- var Is = guard_exports;
1504
1457
 
1505
- // src/core/format-value.ts
1506
- function formatValue(value) {
1507
- if (isString2(value)) {
1508
- return `"${value}"`;
1509
- } else if (isArray2(value)) {
1510
- return `[ ${value.map((e) => formatValue(e)).join(", ")} ]`.replaceAll(" ", " ");
1511
- } else if (isFunction2(value.toString)) {
1512
- return value.toString();
1513
- } else {
1514
- return JSON.stringify(value);
1515
- }
1516
- }
1458
+ // src/core/base.ts
1459
+ var DefaultEqualityFn = (a, b) => a === b;
1460
+ var BaseContainer = class {
1461
+ };
1517
1462
 
1518
1463
  // src/core/stack.ts
1519
- var Stack = class {
1464
+ var Stack = class extends BaseContainer {
1520
1465
  constructor() {
1466
+ super();
1521
1467
  __publicField(this, "data", []);
1522
1468
  }
1523
1469
  assertId(id) {
@@ -1578,13 +1524,14 @@ var Stack = class {
1578
1524
  this.data.length = 0;
1579
1525
  }
1580
1526
  toString() {
1581
- return `Stack(${this.length})${formatValue(this.data)}`;
1527
+ return `Stack(${this.length})${stringify(this.data)}`;
1582
1528
  }
1583
1529
  };
1584
1530
 
1585
1531
  // src/core/vec.ts
1586
- var Vec = class _Vec {
1532
+ var Vec = class _Vec extends BaseContainer {
1587
1533
  constructor(...coords) {
1534
+ super();
1588
1535
  __publicField(this, "coords");
1589
1536
  if (coords.length < 2) {
1590
1537
  throw new TypeError("Vec needs minumum two coords!");
@@ -1785,19 +1732,31 @@ var DivRect = class _DivRect {
1785
1732
  static createSections(leftw, rightw, toph, bottomh) {
1786
1733
  return new _DivRect(-leftw, 0, rightw, -toph, 0, bottomh);
1787
1734
  }
1788
- /** @deprecated - Renamed to anchorX. */
1735
+ /**
1736
+ * @deprecated - Renamed to anchorX. Will be removed in v2.0.0.
1737
+ * @private
1738
+ * */
1789
1739
  get centerX() {
1790
1740
  return this.anchorX;
1791
1741
  }
1792
- /** @deprecated - Renamed to anchorX. */
1742
+ /**
1743
+ * @deprecated - Renamed to anchorX. Will be removed in v2.0.0.
1744
+ * @private
1745
+ * */
1793
1746
  set centerX(x) {
1794
1747
  this.anchorX = x;
1795
1748
  }
1796
- /** @deprecated - Renamed to anchorY. */
1749
+ /**
1750
+ * @deprecated - Renamed to anchorX. Will be removed in v2.0.0.
1751
+ * @private
1752
+ * */
1797
1753
  get centerY() {
1798
1754
  return this.anchorY;
1799
1755
  }
1800
- /** @deprecated - Renamed to anchorY. */
1756
+ /**
1757
+ * @deprecated - Renamed to anchorX. Will be removed in v2.0.0.
1758
+ * @private
1759
+ * */
1801
1760
  set centerY(y) {
1802
1761
  this.anchorY = y;
1803
1762
  }
@@ -1915,7 +1874,10 @@ var DivRect = class _DivRect {
1915
1874
  equalsEdges(other) {
1916
1875
  return _DivRect.equalsEdges(this, other);
1917
1876
  }
1918
- /** @deprecated - Use `DivRect.equalsEdges()` instead. */
1877
+ /**
1878
+ * @deprecated - Use `DivRect.equalsEdges()` instead. Will be removed in v2.0.0.
1879
+ * @private
1880
+ */
1919
1881
  static equalsFrame(a, b) {
1920
1882
  return _DivRect.equalsEdges(a, b);
1921
1883
  }
@@ -2034,9 +1996,10 @@ var DivRect = class _DivRect {
2034
1996
  };
2035
1997
 
2036
1998
  // src/core/LRU-cache.ts
2037
- var LRUCache = class {
1999
+ var LRUCache = class extends BaseContainer {
2038
2000
  // Maximum key length.
2039
2001
  constructor(maxSize, maxKeyLength = Infinity) {
2002
+ super();
2040
2003
  __publicField(this, "cache");
2041
2004
  // Stores the actual key-value pairs
2042
2005
  __publicField(this, "next");
@@ -2128,11 +2091,31 @@ var LRUCache = class {
2128
2091
  }
2129
2092
  this.tail = key;
2130
2093
  }
2094
+ *keys() {
2095
+ for (let key = this.head; key != null; key = this.next[key])
2096
+ yield key;
2097
+ }
2098
+ *values() {
2099
+ for (let key = this.head; key != null; key = this.next[key])
2100
+ yield this.cache[key];
2101
+ }
2102
+ *entries() {
2103
+ for (let key = this.head; key != null; key = this.next[key])
2104
+ yield [key, this.cache[key]];
2105
+ }
2106
+ *[Symbol.iterator]() {
2107
+ yield* this.entries();
2108
+ }
2109
+ toString() {
2110
+ const entries = [...this.entries()];
2111
+ return entries.length === 0 ? `LRUCache(0){ }` : `LRUCache(${entries.length}){ ${entries.map((e) => `${stringify(e[0])}: ${stringify(e[1])}`).join(", ")} }`;
2112
+ }
2131
2113
  };
2132
2114
 
2133
2115
  // src/core/index-array.ts
2134
- var IndexArray = class _IndexArray {
2116
+ var IndexArray = class _IndexArray extends BaseContainer {
2135
2117
  constructor(entries) {
2118
+ super();
2136
2119
  __publicField(this, "posVal");
2137
2120
  __publicField(this, "hasPos");
2138
2121
  // Number of values
@@ -2345,14 +2328,20 @@ var IndexArray = class _IndexArray {
2345
2328
  return this.valuesArray();
2346
2329
  }
2347
2330
  toString() {
2348
- const entries = this.entriesArray().map(([id, v]) => `${formatValue(id)}: ${formatValue(v)}`).join(", ");
2349
- return `IndexArray[ ${entries} ]`.replaceAll(" ", " ");
2331
+ let isRegularArray = true;
2332
+ for (let i = 0; i < this.hasPos.length && isRegularArray; i++)
2333
+ if (!this.hasPos[i]) isRegularArray = false;
2334
+ if (isRegularArray)
2335
+ return stringify(this.posVal.slice(0, this.hasPos.length));
2336
+ const entries = this.entriesArray().map(([id, v]) => `${stringify(id)}: ${stringify(v)}`).join(", ");
2337
+ return entries.length === 0 ? `[ ]` : `[ ${entries} ]`;
2350
2338
  }
2351
2339
  };
2352
2340
 
2353
2341
  // src/core/signed-index-array.ts
2354
- var SignedIndexArray = class _SignedIndexArray {
2342
+ var SignedIndexArray = class _SignedIndexArray extends BaseContainer {
2355
2343
  constructor(entries) {
2344
+ super();
2356
2345
  // For indexes >= 0
2357
2346
  __publicField(this, "posVal");
2358
2347
  __publicField(this, "hasPos");
@@ -2608,65 +2597,101 @@ var SignedIndexArray = class _SignedIndexArray {
2608
2597
  return this.valuesArray();
2609
2598
  }
2610
2599
  toString() {
2611
- const entries = this.entriesArray().map(([id, v]) => `${formatValue(id)}: ${formatValue(v)}`).join(", ");
2612
- return `SignedIndexArray[ ${entries} ]`.replaceAll(" ", " ");
2600
+ let isRegularArray = this.hasNeg.length === 0;
2601
+ for (let i = 0; i < this.hasPos.length && isRegularArray; i++)
2602
+ if (!this.hasPos[i]) isRegularArray = false;
2603
+ if (isRegularArray)
2604
+ return stringify(this.posVal.slice(0, this.hasPos.length));
2605
+ const entries = this.entriesArray().map(([id, v]) => `${stringify(id)}: ${stringify(v)}`).join(", ");
2606
+ return entries.length === 0 ? `[ ]` : `[ ${entries} ]`;
2613
2607
  }
2614
2608
  };
2615
2609
 
2616
- // src/core/map1.ts
2617
- var Map1 = class _Map1 {
2618
- constructor(entries) {
2619
- __publicField(this, "map1");
2620
- this.map1 = entries instanceof _Map1 ? new Map(entries.map1) : new Map(entries);
2610
+ // src/core/default-array.ts
2611
+ var DefaultArray = class _DefaultArray extends BaseContainer {
2612
+ constructor(...args) {
2613
+ super();
2614
+ __publicField(this, "defaultValue");
2615
+ __publicField(this, "data");
2616
+ this.defaultValue = args.pop();
2617
+ if (typeof args[0] === "number") {
2618
+ this.data = Array(args[0]).fill(this.defaultValue);
2619
+ } else {
2620
+ this.data = Array.from(args[0]).map(
2621
+ (v) => v === void 0 ? this.defaultValue : v
2622
+ );
2623
+ }
2621
2624
  }
2622
- has(key1) {
2623
- return this.map1.has(key1);
2625
+ get size() {
2626
+ return this.data.length;
2624
2627
  }
2625
- set(key1, value) {
2626
- this.map1.set(key1, value);
2627
- return value;
2628
+ get length() {
2629
+ return this.data.length;
2628
2630
  }
2629
- get(key1) {
2630
- return this.map1.get(key1);
2631
+ assertId(id) {
2632
+ if (id < 0 || id >= this.data.length)
2633
+ throw new RangeError(`DefaultArray: Index ${id} out of range`);
2634
+ return id;
2631
2635
  }
2632
- getOrDefault(key1, defaultValue) {
2633
- return this.get(key1) ?? defaultValue;
2636
+ isEmpty() {
2637
+ return this.size === 0;
2634
2638
  }
2635
- getOrCreate(key1, creatorOrValue) {
2636
- if (!this.has(key1)) {
2639
+ isDefault(id) {
2640
+ return this.data[this.assertId(id)] === this.defaultValue;
2641
+ }
2642
+ isSet(id) {
2643
+ return this.data[this.assertId(id)] !== this.defaultValue;
2644
+ }
2645
+ /** @internal - This method exists only for interface `KVComponent` compatibility.*/
2646
+ has(id) {
2647
+ return this.isSet(id);
2648
+ }
2649
+ set(id, value) {
2650
+ return this.data[this.assertId(id)] = value;
2651
+ }
2652
+ get(id) {
2653
+ return this.data[this.assertId(id)];
2654
+ }
2655
+ getOrDefault(id, defaultValue) {
2656
+ let value = this.get(id);
2657
+ return value === this.defaultValue ? defaultValue : value;
2658
+ }
2659
+ getOrCreate(id, creatorOrValue) {
2660
+ if (!this.has(id)) {
2637
2661
  const value = isFunction2(creatorOrValue) ? creatorOrValue() : creatorOrValue;
2638
- this.set(key1, value);
2662
+ this.set(id, value);
2639
2663
  return value;
2640
2664
  }
2641
- return this.get(key1);
2642
- }
2643
- delete(key1) {
2644
- return this.map1.delete(key1);
2645
- }
2646
- clear() {
2647
- this.map1.clear();
2665
+ return this.get(id);
2648
2666
  }
2649
- get size() {
2650
- return this.map1.size;
2667
+ delete(id) {
2668
+ this.assertId(id);
2669
+ if (this.data[id] === this.defaultValue) return false;
2670
+ this.data[id] = this.defaultValue;
2671
+ return true;
2651
2672
  }
2652
- isEmpty() {
2653
- return this.size === 0;
2673
+ clear(empty = false) {
2674
+ if (empty)
2675
+ this.data = [];
2676
+ else
2677
+ this.data.fill(this.defaultValue);
2654
2678
  }
2655
2679
  forEach(callbackfn, thisArg) {
2656
- this.map1.forEach((value, key1) => callbackfn.call(thisArg, value, key1, this));
2680
+ for (const [id, value] of this.entries()) {
2681
+ callbackfn.call(thisArg, value, id, this);
2682
+ }
2657
2683
  }
2658
- *keys() {
2659
- yield* this.map1.keys();
2684
+ *indices() {
2685
+ yield* this.data.keys();
2660
2686
  }
2661
2687
  *values() {
2662
- yield* this.map1.values();
2688
+ yield* this.data.values();
2663
2689
  }
2664
2690
  *entries() {
2665
- for (const [key1, value] of this.map1)
2666
- yield [key1, value];
2691
+ yield* this.data.entries();
2667
2692
  }
2668
- keysArray() {
2669
- return [...this.keys()];
2693
+ indicesArray() {
2694
+ return [...this.indices()];
2670
2695
  }
2671
2696
  valuesArray() {
2672
2697
  return [...this.values()];
@@ -2675,52 +2700,58 @@ var Map1 = class _Map1 {
2675
2700
  return [...this.entries()];
2676
2701
  }
2677
2702
  *kvKeys() {
2678
- for (const key of this.keys()) {
2679
- yield [key];
2703
+ for (const id of this.indices()) {
2704
+ yield [id];
2680
2705
  }
2681
2706
  }
2682
2707
  *kvValues() {
2683
- for (const el of this.values()) {
2684
- yield el;
2708
+ for (const value of this.values()) {
2709
+ yield value;
2685
2710
  }
2686
2711
  }
2687
2712
  *kvEntries() {
2688
- for (const [key, el] of this.entries()) {
2689
- yield [[key], el];
2713
+ for (const [id, value] of this.entries()) {
2714
+ yield [[id], value];
2690
2715
  }
2691
2716
  }
2692
2717
  *[Symbol.iterator]() {
2693
2718
  yield* this.entries();
2694
2719
  }
2695
2720
  clone() {
2696
- return new _Map1(this);
2721
+ const ctor = this.constructor;
2722
+ return new ctor(this.values(), this.defaultValue);
2697
2723
  }
2698
2724
  merge(other, conflictResolver) {
2699
- for (const [key1, value] of other.entries()) {
2700
- if (this.has(key1) && conflictResolver) {
2701
- this.set(key1, conflictResolver(this.get(key1), value, key1));
2702
- } else {
2703
- this.set(key1, value);
2704
- }
2725
+ if (this.constructor !== other.constructor)
2726
+ throw new Error(`Cannot merge DefaultArray: different classes (${this.constructor.name} vs ${other.constructor.name})`);
2727
+ if (this.defaultValue !== other.defaultValue)
2728
+ throw new Error(`Cannot merge DefaultArray: different defaultValue (${this.defaultValue} vs ${other.defaultValue})`);
2729
+ for (const [id, value] of other.entries()) {
2730
+ if (this.isDefault(id))
2731
+ this.set(id, value);
2732
+ else if (conflictResolver)
2733
+ this.set(id, conflictResolver(this.get(id), value, id));
2734
+ else
2735
+ this.set(id, value);
2705
2736
  }
2706
2737
  return this;
2707
2738
  }
2708
2739
  some(fn) {
2709
- for (const [key1, value] of this.map1) {
2710
- if (fn(value, key1)) return true;
2740
+ for (const [id, value] of this.entries()) {
2741
+ if (fn(value, id)) return true;
2711
2742
  }
2712
2743
  return false;
2713
2744
  }
2714
2745
  every(fn) {
2715
- for (const [key1, value] of this.map1) {
2716
- if (!fn(value, key1)) return false;
2746
+ for (const [id, value] of this.entries()) {
2747
+ if (!fn(value, id)) return false;
2717
2748
  }
2718
2749
  return true;
2719
2750
  }
2720
2751
  filter(predicate) {
2721
- const result = new this.constructor();
2722
- for (const [key1, value] of this.map1) {
2723
- if (predicate(value, key1, this)) result.set(key1, value);
2752
+ const result = new this.constructor(this.length, this.defaultValue);
2753
+ for (const [id, value] of this.entries()) {
2754
+ if (predicate(value, id, this)) result.set(id, value);
2724
2755
  }
2725
2756
  return result;
2726
2757
  }
@@ -2729,7 +2760,7 @@ var Map1 = class _Map1 {
2729
2760
  let first = iterator.next();
2730
2761
  if (first.done) {
2731
2762
  if (arguments.length < 2) {
2732
- throw new TypeError("Reduce of empty Map1 with no initial value!");
2763
+ throw new TypeError("Reduce of empty DefaultArray with no initial value!");
2733
2764
  }
2734
2765
  return init;
2735
2766
  }
@@ -2743,58 +2774,259 @@ var Map1 = class _Map1 {
2743
2774
  start = first;
2744
2775
  }
2745
2776
  for (let current = start; !current.done; current = iterator.next()) {
2746
- const [key1, value] = current.value;
2747
- acc = fn(acc, value, key1);
2777
+ const [id, value] = current.value;
2778
+ acc = fn(acc, value, id);
2748
2779
  }
2749
2780
  return acc;
2750
2781
  }
2751
- mapEntries(fn) {
2782
+ mapToArray(fn) {
2752
2783
  let result = [];
2753
- for (const [key1, value] of this.map1) {
2754
- result.push(fn(value, key1));
2784
+ for (const [id, value] of this.entries()) {
2785
+ result.push(fn(value, id));
2755
2786
  }
2756
2787
  return result;
2757
2788
  }
2758
- mapValues(fn) {
2759
- let result = new _Map1();
2760
- for (const [key1, value] of this.map1) {
2761
- result.set(key1, fn(value, key1));
2789
+ map(fn, defaultValue) {
2790
+ let result = new _DefaultArray(this.data.length, defaultValue);
2791
+ for (let id = 0; id < this.data.length; id++) {
2792
+ result.data[id] = fn(this.data[id], id);
2762
2793
  }
2763
2794
  return result;
2764
2795
  }
2765
- toMap() {
2766
- return new Map(this.map1);
2796
+ equals(other, eq2) {
2797
+ if (this.size !== other.size) return false;
2798
+ eq2 ?? (eq2 = (a, b) => a === b);
2799
+ for (let id = 0; id < this.data.length; ++id) {
2800
+ if (!eq2(this.data[id], other.data[id])) return false;
2801
+ }
2802
+ return true;
2803
+ }
2804
+ toArray() {
2805
+ return this.valuesArray();
2767
2806
  }
2768
2807
  toString() {
2769
- const entries = [...this.map1].map(([k, v]) => `${formatValue(k)} => ${formatValue(v)}`).join(", ");
2770
- return `Map1(${this.size}){ ${entries} }`.replaceAll(" ", " ");
2808
+ return stringify(this.data);
2771
2809
  }
2772
2810
  };
2773
2811
 
2774
- // src/core/map2.ts
2775
- var Map2 = class _Map2 {
2776
- constructor(entries) {
2777
- __publicField(this, "map1", /* @__PURE__ */ new Map());
2778
- if (entries instanceof _Map2) {
2779
- for (const [key1, inner] of entries.map1) {
2780
- this.map1.set(key1, new Map(inner));
2781
- }
2782
- } else if (entries) {
2783
- for (const [key1, key2, value] of entries) {
2784
- this.set(key1, key2, value);
2785
- }
2786
- }
2812
+ // src/core/uni-map.ts
2813
+ var UniMap = class _UniMap extends BaseContainer {
2814
+ constructor(...args) {
2815
+ super();
2816
+ __publicField(this, "map");
2817
+ __publicField(this, "keyEquals");
2818
+ const maybeEquals = args.at(-1);
2819
+ this.keyEquals = isFunction2(maybeEquals) ? args.pop() : DefaultEqualityFn;
2820
+ const entries = args[0];
2821
+ this.map = new Map(entries);
2787
2822
  }
2788
- has(key1, key2) {
2789
- return this.map1.get(key1)?.has(key2) ?? false;
2823
+ static createDeep(arg) {
2824
+ return arg ? new _UniMap(arg, isDeepEqual2) : new _UniMap(isDeepEqual2);
2790
2825
  }
2791
- set(key1, key2, value) {
2792
- let map2 = this.map1.get(key1) ?? this.map1.set(key1, /* @__PURE__ */ new Map()).get(key1);
2793
- map2.set(key2, value);
2794
- return value;
2826
+ has(key) {
2827
+ if (this.keyEquals === DefaultEqualityFn || this.map.has(key))
2828
+ return this.map.has(key);
2829
+ for (const [k, v] of this.map)
2830
+ if (this.keyEquals(k, key))
2831
+ return true;
2832
+ return false;
2795
2833
  }
2796
- get(key1, key2) {
2797
- return this.map1.get(key1)?.get(key2);
2834
+ set(key, value) {
2835
+ if (this.keyEquals === DefaultEqualityFn || this.map.has(key)) {
2836
+ this.map.set(key, value);
2837
+ return value;
2838
+ }
2839
+ for (const key2 of this.map.keys())
2840
+ if (this.keyEquals(key2, key)) {
2841
+ this.map.set(key2, value);
2842
+ return value;
2843
+ }
2844
+ this.map.set(key, value);
2845
+ return value;
2846
+ }
2847
+ get(key) {
2848
+ if (this.keyEquals === DefaultEqualityFn || this.map.has(key))
2849
+ return this.map.get(key);
2850
+ for (const [k, v] of this.map)
2851
+ if (this.keyEquals(k, key))
2852
+ return v;
2853
+ return void 0;
2854
+ }
2855
+ delete(key) {
2856
+ if (this.keyEquals === DefaultEqualityFn || this.map.has(key))
2857
+ return this.map.delete(key);
2858
+ for (const k of this.map.keys())
2859
+ if (this.keyEquals(k, key))
2860
+ return this.map.delete(k);
2861
+ return this.map.delete(key);
2862
+ }
2863
+ getOrDefault(key, defaultValue) {
2864
+ return this.get(key) ?? defaultValue;
2865
+ }
2866
+ getOrCreate(key, creatorOrValue) {
2867
+ if (!this.has(key)) {
2868
+ const value = isFunction2(creatorOrValue) ? creatorOrValue() : creatorOrValue;
2869
+ return this.set(key, value);
2870
+ }
2871
+ return this.get(key);
2872
+ }
2873
+ clear() {
2874
+ this.map.clear();
2875
+ }
2876
+ get size() {
2877
+ return this.map.size;
2878
+ }
2879
+ isEmpty() {
2880
+ return this.size === 0;
2881
+ }
2882
+ forEach(callbackfn, thisArg) {
2883
+ this.map.forEach((value, key) => callbackfn.call(thisArg, value, key, this));
2884
+ }
2885
+ *keys() {
2886
+ yield* this.map.keys();
2887
+ }
2888
+ *values() {
2889
+ yield* this.map.values();
2890
+ }
2891
+ *entries() {
2892
+ for (const [key, value] of this.map)
2893
+ yield [key, value];
2894
+ }
2895
+ keysArray() {
2896
+ return [...this.keys()];
2897
+ }
2898
+ valuesArray() {
2899
+ return [...this.values()];
2900
+ }
2901
+ entriesArray() {
2902
+ return [...this.entries()];
2903
+ }
2904
+ *kvKeys() {
2905
+ for (const key of this.keys()) {
2906
+ yield [key];
2907
+ }
2908
+ }
2909
+ *kvValues() {
2910
+ for (const el of this.values()) {
2911
+ yield el;
2912
+ }
2913
+ }
2914
+ *kvEntries() {
2915
+ for (const [key, el] of this.entries()) {
2916
+ yield [[key], el];
2917
+ }
2918
+ }
2919
+ *[Symbol.iterator]() {
2920
+ yield* this.entries();
2921
+ }
2922
+ clone() {
2923
+ return new _UniMap(this, this.keyEquals);
2924
+ }
2925
+ merge(other, conflictResolver) {
2926
+ for (const [key, value] of other.entries()) {
2927
+ if (this.has(key) && conflictResolver) {
2928
+ this.set(key, conflictResolver(this.get(key), value, key));
2929
+ } else {
2930
+ this.set(key, value);
2931
+ }
2932
+ }
2933
+ return this;
2934
+ }
2935
+ some(fn) {
2936
+ for (const [key, value] of this.map) {
2937
+ if (fn(value, key)) return true;
2938
+ }
2939
+ return false;
2940
+ }
2941
+ every(fn) {
2942
+ for (const [key, value] of this.map) {
2943
+ if (!fn(value, key)) return false;
2944
+ }
2945
+ return true;
2946
+ }
2947
+ filter(predicate) {
2948
+ const result = new this.constructor();
2949
+ for (const [key, value] of this.map) {
2950
+ if (predicate(value, key, this)) result.set(key, value);
2951
+ }
2952
+ return result;
2953
+ }
2954
+ reduce(fn, init) {
2955
+ let iterator = this.entries();
2956
+ let first = iterator.next();
2957
+ if (first.done) {
2958
+ if (arguments.length < 2) {
2959
+ throw new TypeError("Reduce of empty Map1 with no initial value!");
2960
+ }
2961
+ return init;
2962
+ }
2963
+ let acc;
2964
+ let start;
2965
+ if (arguments.length < 2) {
2966
+ acc = first.value[1];
2967
+ start = iterator.next();
2968
+ } else {
2969
+ acc = init;
2970
+ start = first;
2971
+ }
2972
+ for (let current = start; !current.done; current = iterator.next()) {
2973
+ const [key, value] = current.value;
2974
+ acc = fn(acc, value, key);
2975
+ }
2976
+ return acc;
2977
+ }
2978
+ mapEntries(fn) {
2979
+ let result = [];
2980
+ for (const [key, value] of this.map) {
2981
+ result.push(fn(value, key));
2982
+ }
2983
+ return result;
2984
+ }
2985
+ mapValues(fn) {
2986
+ let result = new _UniMap();
2987
+ for (const [key, value] of this.map) {
2988
+ result.set(key, fn(value, key));
2989
+ }
2990
+ return result;
2991
+ }
2992
+ toMap() {
2993
+ return new Map(this.map);
2994
+ }
2995
+ toString() {
2996
+ const entries = [...this.map].map(([k, v]) => `${stringify(k)} => ${stringify(v)}`).join(", ");
2997
+ return entries.length === 0 ? `Map(${this.size}){ }` : `Map(${this.size}){ ${entries} }`;
2998
+ }
2999
+ };
3000
+
3001
+ // src/core/bi-map.ts
3002
+ var BiMap = class _BiMap extends BaseContainer {
3003
+ constructor(entries) {
3004
+ super();
3005
+ __publicField(this, "map1");
3006
+ __publicField(this, "key1Equals", DefaultEqualityFn);
3007
+ __publicField(this, "key2Equals", DefaultEqualityFn);
3008
+ this.map1 = new UniMap(this.key1Equals);
3009
+ if (entries instanceof _BiMap) {
3010
+ for (const [key1, map2] of entries.map1) {
3011
+ const newMap2 = this.map1.set(key1, new UniMap(this.key2Equals));
3012
+ for (const [key2, value] of map2) {
3013
+ newMap2.set(key2, value);
3014
+ }
3015
+ }
3016
+ } else if (entries) {
3017
+ for (const [key1, key2, value] of entries) {
3018
+ this.set(key1, key2, value);
3019
+ }
3020
+ }
3021
+ }
3022
+ has(key1, key2) {
3023
+ return this.map1.get(key1)?.has(key2) ?? false;
3024
+ }
3025
+ set(key1, key2, value) {
3026
+ return this.map1.getOrCreate(key1, () => new UniMap(this.key2Equals)).set(key2, value);
3027
+ }
3028
+ get(key1, key2) {
3029
+ return this.map1.get(key1)?.get(key2);
2798
3030
  }
2799
3031
  getOrDefault(key1, key2, defaultValue) {
2800
3032
  return this.get(key1, key2) ?? defaultValue;
@@ -2869,7 +3101,7 @@ var Map2 = class _Map2 {
2869
3101
  yield* this.entries();
2870
3102
  }
2871
3103
  clone() {
2872
- return new _Map2(this);
3104
+ return new _BiMap(this);
2873
3105
  }
2874
3106
  merge(other, conflictResolver) {
2875
3107
  for (const [key1, key2, value] of other.entries()) {
@@ -2940,7 +3172,7 @@ var Map2 = class _Map2 {
2940
3172
  return result;
2941
3173
  }
2942
3174
  mapValues(fn) {
2943
- let result = new _Map2();
3175
+ let result = new _BiMap();
2944
3176
  for (const [key1, map2] of this.map1) {
2945
3177
  for (const [key2, value] of map2) {
2946
3178
  result.set(key1, key2, fn(value, key1, key2));
@@ -2960,24 +3192,28 @@ var Map2 = class _Map2 {
2960
3192
  toString() {
2961
3193
  const entries = [];
2962
3194
  for (const [key1, map2] of this.map1) {
2963
- const inner = [...map2].map(([key2, v]) => `${formatValue(key2)} => ${formatValue(v)}`).join(", ");
2964
- entries.push(`${formatValue(key1)} => { ${inner} }`);
3195
+ const inner = [...map2].map(([key2, v]) => `${stringify(key2)} => ${stringify(v)}`).join(", ");
3196
+ entries.push(`${stringify(key1)} => { ${inner} }`);
2965
3197
  }
2966
- return `Map2(${this.size}){ ${entries} }`.replaceAll(" ", " ");
3198
+ return entries.length === 0 ? `Map(${this.size}){ }` : `Map(${this.size}){ ${entries} }`;
2967
3199
  }
2968
3200
  };
2969
3201
 
2970
- // src/core/map3.ts
2971
- var Map3 = class _Map3 {
3202
+ // src/core/tri-map.ts
3203
+ var TriMap = class _TriMap extends BaseContainer {
2972
3204
  constructor(entries) {
2973
- __publicField(this, "map1", /* @__PURE__ */ new Map());
2974
- if (entries instanceof _Map3) {
3205
+ super();
3206
+ __publicField(this, "map1");
3207
+ __publicField(this, "key1Equals", DefaultEqualityFn);
3208
+ __publicField(this, "key2Equals", DefaultEqualityFn);
3209
+ __publicField(this, "key3Equals", DefaultEqualityFn);
3210
+ this.map1 = new UniMap(this.key1Equals);
3211
+ if (entries instanceof _TriMap) {
2975
3212
  for (const [key1, map2] of entries.map1) {
2976
- const newMap2 = /* @__PURE__ */ new Map();
3213
+ const newMap2 = this.map1.set(key1, new UniMap(this.key2Equals));
2977
3214
  for (const [key2, map3] of map2) {
2978
- newMap2.set(key2, new Map(map3));
3215
+ newMap2.set(key2, new UniMap(map3, this.key3Equals));
2979
3216
  }
2980
- this.map1.set(key1, newMap2);
2981
3217
  }
2982
3218
  } else if (entries) {
2983
3219
  for (const [key1, key2, key3, value] of entries) {
@@ -2989,10 +3225,8 @@ var Map3 = class _Map3 {
2989
3225
  return this.map1.get(key1)?.get(key2)?.has(key3) ?? false;
2990
3226
  }
2991
3227
  set(key1, key2, key3, value) {
2992
- let map2 = this.map1.get(key1);
2993
- if (!map2) this.map1.set(key1, map2 = /* @__PURE__ */ new Map());
2994
- let map3 = map2.get(key2);
2995
- if (!map3) map2.set(key2, map3 = /* @__PURE__ */ new Map());
3228
+ let map2 = this.map1.getOrCreate(key1, () => new UniMap(this.key2Equals));
3229
+ let map3 = map2.getOrCreate(key2, () => new UniMap(this.key3Equals));
2996
3230
  map3.set(key3, value);
2997
3231
  return value;
2998
3232
  }
@@ -3084,7 +3318,7 @@ var Map3 = class _Map3 {
3084
3318
  yield* this.entries();
3085
3319
  }
3086
3320
  clone() {
3087
- return new _Map3(this);
3321
+ return new _TriMap(this);
3088
3322
  }
3089
3323
  merge(other, conflictResolver) {
3090
3324
  for (const [key1, key2, key3, value] of other.entries()) {
@@ -3163,7 +3397,7 @@ var Map3 = class _Map3 {
3163
3397
  return result;
3164
3398
  }
3165
3399
  mapValues(fn) {
3166
- let result = new _Map3();
3400
+ let result = new _TriMap();
3167
3401
  for (const [key1, map2] of this.map1) {
3168
3402
  for (const [key2, map3] of map2) {
3169
3403
  for (const [key3, value] of map3) {
@@ -3188,17 +3422,199 @@ var Map3 = class _Map3 {
3188
3422
  const entries = [];
3189
3423
  for (const [key1, map2] of this.map1) {
3190
3424
  for (const [key2, map3] of map2) {
3191
- const inner = [...map3].map(([key3, v]) => `${formatValue(key3)} => ${formatValue(v)}`).join(", ");
3192
- entries.push(`${formatValue(key1)} => ${formatValue(key2)} => { ${inner} }`);
3425
+ const inner = [...map3].map(([key3, v]) => `${stringify(key3)} => ${stringify(v)}`).join(", ");
3426
+ entries.push(`${stringify(key1)} => ${stringify(key2)} => { ${inner} }`);
3427
+ }
3428
+ }
3429
+ return entries.length === 0 ? `Map(${this.size}){ }` : `Map(${this.size}){ ${entries.join(", ")} }`;
3430
+ }
3431
+ };
3432
+
3433
+ // src/core/set.ts
3434
+ var ValueSet = class _ValueSet extends BaseContainer {
3435
+ constructor(...args) {
3436
+ super();
3437
+ __publicField(this, "data");
3438
+ __publicField(this, "equals");
3439
+ const maybeEquals = args.at(-1);
3440
+ this.equals = isFunction2(maybeEquals) ? args.pop() : DefaultEqualityFn;
3441
+ const entries = args[0];
3442
+ this.data = new Set(entries);
3443
+ }
3444
+ static createDeep(arg) {
3445
+ return arg ? new _ValueSet(arg, isDeepEqual2) : new _ValueSet(isDeepEqual2);
3446
+ }
3447
+ has(value) {
3448
+ if (this.equals === DefaultEqualityFn)
3449
+ return this.data.has(value);
3450
+ return this.some((v) => this.equals(v, value));
3451
+ }
3452
+ add(value) {
3453
+ if (!this.has(value))
3454
+ this.data.add(value);
3455
+ return value;
3456
+ }
3457
+ /** @internal - This method exists only for interface `KVComponent` compatibility.*/
3458
+ set(key, value) {
3459
+ if (!this.equals(key, value))
3460
+ throw new TypeError("ValueSet.set() requires key === value.");
3461
+ this.add(value);
3462
+ }
3463
+ /** @internal - This method exists only for interface `KVComponent` compatibility.*/
3464
+ get(key) {
3465
+ return this.has(key) ? key : void 0;
3466
+ }
3467
+ /** @internal - This method exists only for interface `KVComponent` compatibility.*/
3468
+ getOrDefault(key, defaultValue) {
3469
+ return this.get(key) ?? defaultValue;
3470
+ }
3471
+ getOrCreate(key, creatorOrValue) {
3472
+ if (!this.has(key)) {
3473
+ const value = isFunction2(creatorOrValue) ? creatorOrValue() : creatorOrValue;
3474
+ this.set(key, value);
3475
+ return value;
3476
+ }
3477
+ return this.get(key);
3478
+ }
3479
+ delete(value) {
3480
+ if (this.equals === DefaultEqualityFn || this.data.has(value))
3481
+ return this.data.delete(value);
3482
+ for (const v of this.values()) {
3483
+ if (this.equals(v, value)) {
3484
+ this.data.delete(v);
3485
+ return true;
3486
+ }
3487
+ }
3488
+ return false;
3489
+ }
3490
+ clear() {
3491
+ this.data.clear();
3492
+ }
3493
+ get size() {
3494
+ return this.data.size;
3495
+ }
3496
+ isEmpty() {
3497
+ return this.size === 0;
3498
+ }
3499
+ forEach(callbackfn, thisArg) {
3500
+ this.data.forEach((value) => callbackfn.call(thisArg, value, this));
3501
+ }
3502
+ *keys() {
3503
+ yield* this.data.keys();
3504
+ }
3505
+ *values() {
3506
+ yield* this.data.values();
3507
+ }
3508
+ *entries() {
3509
+ yield* this.data.entries();
3510
+ }
3511
+ *kvKeys() {
3512
+ for (const key of this.keys()) {
3513
+ yield [key];
3514
+ }
3515
+ }
3516
+ *kvValues() {
3517
+ for (const el of this.values()) {
3518
+ yield el;
3519
+ }
3520
+ }
3521
+ *kvEntries() {
3522
+ for (const [key, el] of this.entries()) {
3523
+ yield [[key], el];
3524
+ }
3525
+ }
3526
+ *[Symbol.iterator]() {
3527
+ yield* this.values();
3528
+ }
3529
+ clone() {
3530
+ const result = new _ValueSet();
3531
+ for (const v of this.values()) result.add(v);
3532
+ return result;
3533
+ }
3534
+ merge(other) {
3535
+ for (const value of other.values()) {
3536
+ this.add(value);
3537
+ }
3538
+ return this;
3539
+ }
3540
+ some(fn) {
3541
+ for (const value of this.data) {
3542
+ if (fn(value)) return true;
3543
+ }
3544
+ return false;
3545
+ }
3546
+ every(fn) {
3547
+ for (const value of this.data) {
3548
+ if (!fn(value)) return false;
3549
+ }
3550
+ return true;
3551
+ }
3552
+ filter(predicate) {
3553
+ const result = new _ValueSet();
3554
+ for (const value of this.data)
3555
+ if (predicate(value, this)) result.add(value);
3556
+ return result;
3557
+ }
3558
+ reduce(fn, init) {
3559
+ let iterator = this.values();
3560
+ let first = iterator.next();
3561
+ if (first.done) {
3562
+ if (arguments.length < 2) {
3563
+ throw new TypeError("Reduce of empty ValueSet with no initial value!");
3193
3564
  }
3565
+ return init;
3566
+ }
3567
+ let acc;
3568
+ let start;
3569
+ if (arguments.length < 2) {
3570
+ acc = first.value;
3571
+ start = iterator.next();
3572
+ } else {
3573
+ acc = init;
3574
+ start = first;
3575
+ }
3576
+ for (let current = start; !current.done; current = iterator.next()) {
3577
+ const value = current.value;
3578
+ acc = fn(acc, value);
3579
+ }
3580
+ return acc;
3581
+ }
3582
+ mapValues(fn) {
3583
+ let result = new _ValueSet();
3584
+ for (const value of this.data) {
3585
+ result.add(fn(value));
3586
+ }
3587
+ return result;
3588
+ }
3589
+ mapToArray(fn) {
3590
+ let result = [];
3591
+ for (const value of this.values()) {
3592
+ result.push(fn(value));
3194
3593
  }
3195
- return `Map3(${this.size}){ ${entries.join(", ")} }`.replaceAll(" ", " ");
3594
+ return result;
3595
+ }
3596
+ map(fn) {
3597
+ let result = new _ValueSet();
3598
+ for (const value of this.values()) {
3599
+ result.add(fn(value));
3600
+ }
3601
+ return result;
3602
+ }
3603
+ toSet() {
3604
+ return new Set(this.data);
3605
+ }
3606
+ toArray() {
3607
+ return [...this.values()];
3608
+ }
3609
+ toString() {
3610
+ return stringify(this.data);
3196
3611
  }
3197
3612
  };
3198
3613
 
3199
3614
  // src/core/multi-container.ts
3200
- var MultiContainer = class {
3615
+ var MultiContainer = class extends BaseContainer {
3201
3616
  constructor(base) {
3617
+ super();
3202
3618
  this.base = base;
3203
3619
  }
3204
3620
  isEmpty() {
@@ -3254,21 +3670,386 @@ var MultiContainer = class {
3254
3670
  const entries = [];
3255
3671
  for (const keys of this.keys()) {
3256
3672
  const arr = this.getAll(...keys);
3257
- const keyStr = Array.isArray(keys) ? formatValue(keys) : "[ ]";
3258
- const valuesStr = Array.isArray(arr) ? formatValue(arr) : "[ ]";
3673
+ const keyStr = Array.isArray(keys) ? stringify(keys) : "[ ]";
3674
+ const valuesStr = Array.isArray(arr) ? stringify(arr) : "[ ]";
3259
3675
  entries.push(`${keyStr} => ${valuesStr}`);
3260
3676
  }
3261
- return `MultiContainer{ ${entries.join(", ")} }`.replaceAll(" ", " ");
3677
+ return entries.length === 0 ? `MultiContainer{ }` : `MultiContainer{ ${entries.join(", ")} }`;
3262
3678
  }
3263
3679
  };
3264
3680
  function asMulti(base) {
3265
3681
  return new MultiContainer(base);
3266
3682
  }
3267
3683
 
3268
- // src/deprecated/vec2.ts
3269
- var Vec2 = class _Vec2 {
3270
- constructor(x, y) {
3271
- __publicField(this, "x");
3684
+ // src/core/linked-list.ts
3685
+ var LinkedListNode = class {
3686
+ constructor(value) {
3687
+ this.value = value;
3688
+ __publicField(this, "next", null);
3689
+ __publicField(this, "prev", null);
3690
+ }
3691
+ };
3692
+ var LinkedList = class _LinkedList extends BaseContainer {
3693
+ constructor(...args) {
3694
+ super();
3695
+ __publicField(this, "_head", null);
3696
+ __publicField(this, "_tail", null);
3697
+ __publicField(this, "_size", 0);
3698
+ __publicField(this, "equals");
3699
+ const maybeEquals = args.at(-1);
3700
+ this.equals = isFunction2(maybeEquals) ? args.pop() : DefaultEqualityFn;
3701
+ const entries = args[0];
3702
+ if (entries) {
3703
+ for (const v of entries) {
3704
+ this.push(v);
3705
+ }
3706
+ }
3707
+ }
3708
+ static createDeep(entries) {
3709
+ if (entries) {
3710
+ return new _LinkedList(entries, isDeepEqual2);
3711
+ } else {
3712
+ return new _LinkedList(isDeepEqual2);
3713
+ }
3714
+ }
3715
+ get length() {
3716
+ return this._size;
3717
+ }
3718
+ get first() {
3719
+ return this._head?.value;
3720
+ }
3721
+ get last() {
3722
+ return this._tail?.value;
3723
+ }
3724
+ /** Add item to the end of the list */
3725
+ push(value) {
3726
+ const node = new LinkedListNode(value);
3727
+ if (!this._tail) {
3728
+ this._head = this._tail = node;
3729
+ } else {
3730
+ node.prev = this._tail;
3731
+ this._tail.next = node;
3732
+ this._tail = node;
3733
+ }
3734
+ this._size++;
3735
+ }
3736
+ /** Remove item from the end of the list */
3737
+ pop() {
3738
+ if (!this._tail) return void 0;
3739
+ const value = this._tail.value;
3740
+ this._tail = this._tail.prev;
3741
+ if (this._tail) this._tail.next = null;
3742
+ else this._head = null;
3743
+ this._size--;
3744
+ return value;
3745
+ }
3746
+ /** Add item to the beginning of the list */
3747
+ unshift(value) {
3748
+ const node = new LinkedListNode(value);
3749
+ if (!this._head) {
3750
+ this._head = this._tail = node;
3751
+ } else {
3752
+ node.next = this._head;
3753
+ this._head.prev = node;
3754
+ this._head = node;
3755
+ }
3756
+ this._size++;
3757
+ }
3758
+ /** Remove item from the beginning of the list */
3759
+ shift() {
3760
+ if (!this._head) return void 0;
3761
+ const value = this._head.value;
3762
+ this._head = this._head.next;
3763
+ if (this._head) this._head.prev = null;
3764
+ else this._tail = null;
3765
+ this._size--;
3766
+ return value;
3767
+ }
3768
+ /** Check if value exists in the list */
3769
+ has(value) {
3770
+ for (let node = this._head; node; node = node.next) {
3771
+ if (this.equals(node.value, value)) return true;
3772
+ }
3773
+ return false;
3774
+ }
3775
+ /** Get value at index (O(n/2)) */
3776
+ get(index) {
3777
+ return this.nodeAt(index)?.value;
3778
+ }
3779
+ /** Set value at index (O(n/2)) */
3780
+ set(index, value) {
3781
+ const node = this.nodeAt(index);
3782
+ if (!node) return false;
3783
+ node.value = value;
3784
+ return true;
3785
+ }
3786
+ /** Insert value at index (O(n/2)) */
3787
+ insertAt(index, value) {
3788
+ if (index < 0 || index > this._size) return false;
3789
+ if (index === 0) {
3790
+ this.unshift(value);
3791
+ return true;
3792
+ }
3793
+ if (index === this._size) {
3794
+ this.push(value);
3795
+ return true;
3796
+ }
3797
+ const nextNode = this.nodeAt(index);
3798
+ if (!nextNode) return false;
3799
+ const prevNode = nextNode.prev;
3800
+ const newNode = new LinkedListNode(value);
3801
+ newNode.next = nextNode;
3802
+ newNode.prev = prevNode;
3803
+ if (prevNode) prevNode.next = newNode;
3804
+ nextNode.prev = newNode;
3805
+ this._size++;
3806
+ return true;
3807
+ }
3808
+ /** Remove value at index (O(n/2)) */
3809
+ removeAt(index) {
3810
+ const node = this.nodeAt(index);
3811
+ if (!node) return void 0;
3812
+ if (node.prev) node.prev.next = node.next;
3813
+ else this._head = node.next;
3814
+ if (node.next) node.next.prev = node.prev;
3815
+ else this._tail = node.prev;
3816
+ this._size--;
3817
+ return node.value;
3818
+ }
3819
+ /** Remove first matching value (O(n)) */
3820
+ remove(value) {
3821
+ for (let node = this._head; node; node = node.next) {
3822
+ if (this.equals(node.value, value)) {
3823
+ if (node.prev) node.prev.next = node.next;
3824
+ else this._head = node.next;
3825
+ if (node.next) node.next.prev = node.prev;
3826
+ else this._tail = node.prev;
3827
+ this._size--;
3828
+ return true;
3829
+ }
3830
+ }
3831
+ return false;
3832
+ }
3833
+ /** Convert to array */
3834
+ toArray() {
3835
+ const result = [];
3836
+ for (const v of this) result.push(v);
3837
+ return result;
3838
+ }
3839
+ /** Replace contents from array */
3840
+ fromArray(values) {
3841
+ this.clear();
3842
+ for (const v of values) this.push(v);
3843
+ }
3844
+ /** Clear all nodes */
3845
+ clear() {
3846
+ this._head = this._tail = null;
3847
+ this._size = 0;
3848
+ }
3849
+ /** Iterator support */
3850
+ *[Symbol.iterator]() {
3851
+ yield* this.values();
3852
+ }
3853
+ *keys() {
3854
+ for (let id = 0; id < this._size; id++)
3855
+ yield id;
3856
+ }
3857
+ *values() {
3858
+ let node = this._head;
3859
+ while (node) {
3860
+ yield node.value;
3861
+ node = node.next;
3862
+ }
3863
+ }
3864
+ *entries() {
3865
+ let node = this._head;
3866
+ let id = 0;
3867
+ while (node) {
3868
+ yield [id++, node.value];
3869
+ node = node.next;
3870
+ }
3871
+ }
3872
+ toString() {
3873
+ return this._size === 0 ? `LinkedList(0)[ ]` : `LinkedList(${this._size})[ ${this.toArray().join(", ")} ]`;
3874
+ }
3875
+ // ---- Private helpers ----
3876
+ nodeAt(index) {
3877
+ if (index < 0 || index >= this._size) return null;
3878
+ let node;
3879
+ if (index < this._size / 2) {
3880
+ node = this._head;
3881
+ for (let i = 0; i < index; i++) node = node.next;
3882
+ } else {
3883
+ node = this._tail;
3884
+ for (let i = this._size - 1; i > index; i--) node = node.prev;
3885
+ }
3886
+ return node;
3887
+ }
3888
+ clone() {
3889
+ return new _LinkedList(this);
3890
+ }
3891
+ };
3892
+
3893
+ // src/utils/str/index.ts
3894
+ function toCharArray(str2) {
3895
+ return str2.split("");
3896
+ }
3897
+ function repeatString(repeatString2, repeatCount) {
3898
+ if (!isInteger2(repeatCount) || repeatCount < 0) {
3899
+ throw new Error("repeatStr: Invalid repeatCount = " + repeatCount);
3900
+ }
3901
+ return new Array(repeatCount + 1).join(repeatString2);
3902
+ }
3903
+ function chunkString(str2, chunkSize) {
3904
+ if (!isInteger2(chunkSize) || chunkSize < 1) {
3905
+ throw new Error("chunckString: Invalid chuckSize = " + chunkSize);
3906
+ }
3907
+ let result = [];
3908
+ for (let i = 0; i < str2.length; i += chunkSize) {
3909
+ result.push(str2.slice(i, i + chunkSize));
3910
+ }
3911
+ return result;
3912
+ }
3913
+ function replaceAt(str2, pos, removeCount, insert) {
3914
+ if (!isInteger2(removeCount) || removeCount < 0) {
3915
+ throw new Error("replaceAt: Invalid removeCount = " + removeCount);
3916
+ } else if (!isInteger2(pos) || pos < 0 || pos + removeCount > str2.length) {
3917
+ throw new Error("replaceAt: Invalid pos = " + pos + ", removeCount = " + removeCount + ", str.length = " + str2.length);
3918
+ } else {
3919
+ return str2.substring(0, pos) + insert + str2.substring(pos + removeCount);
3920
+ }
3921
+ }
3922
+ function insertAt(str2, pos, insertStr) {
3923
+ return replaceAt(str2, pos, 0, insertStr);
3924
+ }
3925
+ function removeAt(str2, pos, removeCount) {
3926
+ return replaceAt(str2, pos, removeCount, "");
3927
+ }
3928
+ function charCount(str2, ch) {
3929
+ if (ch.length !== 1 || str2.length === 0) return 0;
3930
+ let count = 0;
3931
+ for (let i = 0; i < str2.length; i++) {
3932
+ if (str2[i] === ch) count++;
3933
+ }
3934
+ return count;
3935
+ }
3936
+ function makeSentenceFromPascal(PascalString) {
3937
+ if (PascalString === "") {
3938
+ return "";
3939
+ }
3940
+ let word = PascalString.charAt(0);
3941
+ let sentence = "";
3942
+ const addWord = () => {
3943
+ if (word !== "") {
3944
+ if (sentence === "") {
3945
+ sentence += word.charAt(0).toUpperCase() + word.substring(1);
3946
+ } else {
3947
+ sentence += " " + word;
3948
+ }
3949
+ word = "";
3950
+ }
3951
+ };
3952
+ const isLetterAndCapital = (c) => {
3953
+ return c.toUpperCase() !== c.toLowerCase() && c === c.toUpperCase();
3954
+ };
3955
+ for (let i = 1; i < PascalString.length; i++) {
3956
+ let c = PascalString.charAt(i);
3957
+ if (isLetterAndCapital(c)) {
3958
+ addWord();
3959
+ }
3960
+ word += c.toLowerCase();
3961
+ }
3962
+ addWord();
3963
+ return sentence;
3964
+ }
3965
+ function stringify(value, maxDepth = 5, seen = /* @__PURE__ */ new WeakSet()) {
3966
+ if (value === null) return "null";
3967
+ if (value === void 0) return "undefined";
3968
+ const t = typeof value;
3969
+ switch (t) {
3970
+ case "boolean":
3971
+ return value ? "true" : "false";
3972
+ case "number":
3973
+ if (isNaNValue2(value)) return "NaN";
3974
+ if (!isFinite3(value))
3975
+ return value < 0 ? "-Infinity" : "Infinity";
3976
+ return value.toString();
3977
+ case "bigint":
3978
+ return `${value}n`;
3979
+ case "string":
3980
+ return `"${value}"`;
3981
+ case "symbol":
3982
+ return value.description ? `Symbol(${value.description})` : "Symbol()";
3983
+ case "function":
3984
+ return `[Function${value.name ? ` ${value.name}` : ""}]`;
3985
+ }
3986
+ if (seen.has(value))
3987
+ return "[Circular]";
3988
+ if (maxDepth <= 0)
3989
+ return "[Depth limit]";
3990
+ maxDepth--;
3991
+ seen.add(value);
3992
+ const strfy = (v) => stringify(v, maxDepth, seen);
3993
+ if (isArray2(value)) {
3994
+ const inner = value.map((v) => strfy(v)).join(", ");
3995
+ return inner.length === 0 ? "[ ]" : `[ ${inner} ]`;
3996
+ }
3997
+ if (ArrayBuffer.isView(value)) {
3998
+ if (value instanceof DataView)
3999
+ return `DataView(${value.byteLength})`;
4000
+ const inner = Array.from(value).map((v) => strfy(v)).join(", ");
4001
+ return `${value.constructor.name}[ ${inner} ]`;
4002
+ }
4003
+ if (value instanceof ArrayBuffer)
4004
+ return `ArrayBuffer(${value.byteLength})`;
4005
+ if (value instanceof Map) {
4006
+ const entries = Array.from(value.entries()).map(([k, v]) => `${strfy(k)} => ${strfy(v)}`).join(", ");
4007
+ return entries.length === 0 ? `Map(${value.size}){ }` : `Map(${value.size}){ ${entries} }`;
4008
+ }
4009
+ if (value instanceof Set) {
4010
+ const entries = Array.from(value.values()).map((v) => strfy(v)).join(", ");
4011
+ return entries.length === 0 ? `Set(${value.size}){ }` : `Set(${value.size}){ ${entries} }`;
4012
+ }
4013
+ if (value instanceof WeakMap)
4014
+ return "WeakMap{ ? }";
4015
+ if (value instanceof WeakSet)
4016
+ return "WeakSet{ ? }";
4017
+ if (typeof BaseContainer !== "undefined" && value instanceof BaseContainer)
4018
+ return value.toString();
4019
+ if (value instanceof Date)
4020
+ return `Date("${value.toISOString()}")`;
4021
+ if (value instanceof RegExp)
4022
+ return value.toString();
4023
+ if (value instanceof Error)
4024
+ return `${value.name}("${value.message}")`;
4025
+ if (value instanceof Promise)
4026
+ return "Promise{ ? }";
4027
+ if (value instanceof URL)
4028
+ return `URL("${value.href}")`;
4029
+ if (value instanceof URLSearchParams)
4030
+ return `URLSearchParams("${value.toString()}")`;
4031
+ if (value === Math) return "Math";
4032
+ if (value === JSON) return "JSON";
4033
+ if (value === Reflect) return "Reflect";
4034
+ if (value === Intl) return "Intl";
4035
+ if (t === "object") {
4036
+ const ctorName = value.constructor?.name ?? "Object";
4037
+ const entries = Object.entries(value).map(
4038
+ ([key, val]) => `${strfy(key)}: ${strfy(val)}`
4039
+ );
4040
+ if (entries.length === 0) return `${ctorName}{ }`;
4041
+ return `${ctorName}{ ${entries.join(", ")} }`;
4042
+ }
4043
+ return String(value);
4044
+ }
4045
+
4046
+ // src/utils/index.ts
4047
+ var Is = guard_exports;
4048
+
4049
+ // src/deprecated/vec2.ts
4050
+ var Vec2 = class _Vec2 {
4051
+ constructor(x, y) {
4052
+ __publicField(this, "x");
3272
4053
  __publicField(this, "y");
3273
4054
  this.x = x ?? 0;
3274
4055
  this.y = y ?? 0;
@@ -3341,23 +4122,813 @@ var SmallIntCache = class {
3341
4122
  this.neg = [];
3342
4123
  }
3343
4124
  };
4125
+
4126
+ // src/deprecated/map1.ts
4127
+ var Map1 = class _Map1 extends BaseContainer {
4128
+ constructor(entries) {
4129
+ super();
4130
+ __publicField(this, "map1");
4131
+ this.map1 = entries instanceof _Map1 ? new Map(entries.map1) : new Map(entries);
4132
+ }
4133
+ has(key1) {
4134
+ return this.map1.has(key1);
4135
+ }
4136
+ set(key1, value) {
4137
+ this.map1.set(key1, value);
4138
+ return value;
4139
+ }
4140
+ get(key1) {
4141
+ return this.map1.get(key1);
4142
+ }
4143
+ getOrDefault(key1, defaultValue) {
4144
+ return this.get(key1) ?? defaultValue;
4145
+ }
4146
+ getOrCreate(key1, creatorOrValue) {
4147
+ if (!this.has(key1)) {
4148
+ const value = isFunction2(creatorOrValue) ? creatorOrValue() : creatorOrValue;
4149
+ this.set(key1, value);
4150
+ return value;
4151
+ }
4152
+ return this.get(key1);
4153
+ }
4154
+ delete(key1) {
4155
+ return this.map1.delete(key1);
4156
+ }
4157
+ clear() {
4158
+ this.map1.clear();
4159
+ }
4160
+ get size() {
4161
+ return this.map1.size;
4162
+ }
4163
+ isEmpty() {
4164
+ return this.size === 0;
4165
+ }
4166
+ forEach(callbackfn, thisArg) {
4167
+ this.map1.forEach((value, key1) => callbackfn.call(thisArg, value, key1, this));
4168
+ }
4169
+ *keys() {
4170
+ yield* this.map1.keys();
4171
+ }
4172
+ *values() {
4173
+ yield* this.map1.values();
4174
+ }
4175
+ *entries() {
4176
+ for (const [key1, value] of this.map1)
4177
+ yield [key1, value];
4178
+ }
4179
+ keysArray() {
4180
+ return [...this.keys()];
4181
+ }
4182
+ valuesArray() {
4183
+ return [...this.values()];
4184
+ }
4185
+ entriesArray() {
4186
+ return [...this.entries()];
4187
+ }
4188
+ *kvKeys() {
4189
+ for (const key of this.keys()) {
4190
+ yield [key];
4191
+ }
4192
+ }
4193
+ *kvValues() {
4194
+ for (const el of this.values()) {
4195
+ yield el;
4196
+ }
4197
+ }
4198
+ *kvEntries() {
4199
+ for (const [key, el] of this.entries()) {
4200
+ yield [[key], el];
4201
+ }
4202
+ }
4203
+ *[Symbol.iterator]() {
4204
+ yield* this.entries();
4205
+ }
4206
+ clone() {
4207
+ return new _Map1(this);
4208
+ }
4209
+ merge(other, conflictResolver) {
4210
+ for (const [key1, value] of other.entries()) {
4211
+ if (this.has(key1) && conflictResolver) {
4212
+ this.set(key1, conflictResolver(this.get(key1), value, key1));
4213
+ } else {
4214
+ this.set(key1, value);
4215
+ }
4216
+ }
4217
+ return this;
4218
+ }
4219
+ some(fn) {
4220
+ for (const [key1, value] of this.map1) {
4221
+ if (fn(value, key1)) return true;
4222
+ }
4223
+ return false;
4224
+ }
4225
+ every(fn) {
4226
+ for (const [key1, value] of this.map1) {
4227
+ if (!fn(value, key1)) return false;
4228
+ }
4229
+ return true;
4230
+ }
4231
+ filter(predicate) {
4232
+ const result = new this.constructor();
4233
+ for (const [key1, value] of this.map1) {
4234
+ if (predicate(value, key1, this)) result.set(key1, value);
4235
+ }
4236
+ return result;
4237
+ }
4238
+ reduce(fn, init) {
4239
+ let iterator = this.entries();
4240
+ let first = iterator.next();
4241
+ if (first.done) {
4242
+ if (arguments.length < 2) {
4243
+ throw new TypeError("Reduce of empty Map1 with no initial value!");
4244
+ }
4245
+ return init;
4246
+ }
4247
+ let acc;
4248
+ let start;
4249
+ if (arguments.length < 2) {
4250
+ acc = first.value[1];
4251
+ start = iterator.next();
4252
+ } else {
4253
+ acc = init;
4254
+ start = first;
4255
+ }
4256
+ for (let current = start; !current.done; current = iterator.next()) {
4257
+ const [key1, value] = current.value;
4258
+ acc = fn(acc, value, key1);
4259
+ }
4260
+ return acc;
4261
+ }
4262
+ mapEntries(fn) {
4263
+ let result = [];
4264
+ for (const [key1, value] of this.map1) {
4265
+ result.push(fn(value, key1));
4266
+ }
4267
+ return result;
4268
+ }
4269
+ mapValues(fn) {
4270
+ let result = new _Map1();
4271
+ for (const [key1, value] of this.map1) {
4272
+ result.set(key1, fn(value, key1));
4273
+ }
4274
+ return result;
4275
+ }
4276
+ toMap() {
4277
+ return new Map(this.map1);
4278
+ }
4279
+ toString() {
4280
+ const entries = [...this.map1].map(([k, v]) => `${stringify(k)} => ${stringify(v)}`).join(", ");
4281
+ return entries.length === 0 ? `Map(${this.size}){ }` : `Map(${this.size}){ ${entries} }`;
4282
+ }
4283
+ };
4284
+
4285
+ // src/deprecated/map2.ts
4286
+ var Map2 = class _Map2 extends BaseContainer {
4287
+ constructor(entries) {
4288
+ super();
4289
+ __publicField(this, "map1", /* @__PURE__ */ new Map());
4290
+ if (entries instanceof _Map2) {
4291
+ for (const [key1, inner] of entries.map1) {
4292
+ this.map1.set(key1, new Map(inner));
4293
+ }
4294
+ } else if (entries) {
4295
+ for (const [key1, key2, value] of entries) {
4296
+ this.set(key1, key2, value);
4297
+ }
4298
+ }
4299
+ }
4300
+ has(key1, key2) {
4301
+ return this.map1.get(key1)?.has(key2) ?? false;
4302
+ }
4303
+ set(key1, key2, value) {
4304
+ let map2 = this.map1.get(key1) ?? this.map1.set(key1, /* @__PURE__ */ new Map()).get(key1);
4305
+ map2.set(key2, value);
4306
+ return value;
4307
+ }
4308
+ get(key1, key2) {
4309
+ return this.map1.get(key1)?.get(key2);
4310
+ }
4311
+ getOrDefault(key1, key2, defaultValue) {
4312
+ return this.get(key1, key2) ?? defaultValue;
4313
+ }
4314
+ getOrCreate(key1, key2, creatorOrValue) {
4315
+ if (!this.has(key1, key2)) {
4316
+ const value = isFunction2(creatorOrValue) ? creatorOrValue() : creatorOrValue;
4317
+ this.set(key1, key2, value);
4318
+ return value;
4319
+ }
4320
+ return this.get(key1, key2);
4321
+ }
4322
+ delete(key1, key2) {
4323
+ if (key2 === void 0) return this.map1.delete(key1);
4324
+ const map2 = this.map1.get(key1);
4325
+ if (!map2) return false;
4326
+ return map2.delete(key2);
4327
+ }
4328
+ clear() {
4329
+ this.map1.clear();
4330
+ }
4331
+ get size() {
4332
+ let count = 0;
4333
+ for (const map2 of this.map1.values()) {
4334
+ count += map2.size;
4335
+ }
4336
+ return count;
4337
+ }
4338
+ isEmpty() {
4339
+ return this.size === 0;
4340
+ }
4341
+ forEach(callbackfn, thisArg) {
4342
+ this.map1.forEach((map2, key1) => map2.forEach((value, key2) => callbackfn.call(thisArg, value, key1, key2, this)));
4343
+ }
4344
+ *keys() {
4345
+ for (const [key1, map2] of this.map1)
4346
+ for (const key2 of map2.keys())
4347
+ yield [key1, key2];
4348
+ }
4349
+ *values() {
4350
+ for (const map2 of this.map1.values())
4351
+ for (const value of map2.values())
4352
+ yield value;
4353
+ }
4354
+ *entries() {
4355
+ for (const [key1, map2] of this.map1)
4356
+ for (const [key2, value] of map2)
4357
+ yield [key1, key2, value];
4358
+ }
4359
+ keysArray() {
4360
+ return [...this.keys()];
4361
+ }
4362
+ valuesArray() {
4363
+ return [...this.values()];
4364
+ }
4365
+ entriesArray() {
4366
+ return [...this.entries()];
4367
+ }
4368
+ *kvKeys() {
4369
+ for (const [key1, key2] of this.keys())
4370
+ yield [key1, key2];
4371
+ }
4372
+ *kvValues() {
4373
+ for (const el of this.values())
4374
+ yield el;
4375
+ }
4376
+ *kvEntries() {
4377
+ for (const [key1, key2, el] of this.entries())
4378
+ yield [[key1, key2], el];
4379
+ }
4380
+ *[Symbol.iterator]() {
4381
+ yield* this.entries();
4382
+ }
4383
+ clone() {
4384
+ return new _Map2(this);
4385
+ }
4386
+ merge(other, conflictResolver) {
4387
+ for (const [key1, key2, value] of other.entries()) {
4388
+ if (this.has(key1, key2) && conflictResolver) {
4389
+ this.set(key1, key2, conflictResolver(this.get(key1, key2), value, key1, key2));
4390
+ } else {
4391
+ this.set(key1, key2, value);
4392
+ }
4393
+ }
4394
+ return this;
4395
+ }
4396
+ some(fn) {
4397
+ for (const [key1, map2] of this.map1) {
4398
+ for (const [key2, value] of map2) {
4399
+ if (fn(value, key1, key2)) return true;
4400
+ }
4401
+ }
4402
+ return false;
4403
+ }
4404
+ every(fn) {
4405
+ for (const [key1, map2] of this.map1) {
4406
+ for (const [key2, value] of map2) {
4407
+ if (!fn(value, key1, key2)) return false;
4408
+ }
4409
+ }
4410
+ return true;
4411
+ }
4412
+ filter(predicate) {
4413
+ const result = new this.constructor();
4414
+ for (const [key1, map2] of this.map1) {
4415
+ for (const [key2, value] of map2) {
4416
+ if (predicate(value, key1, key2, this)) result.set(key1, key2, value);
4417
+ }
4418
+ }
4419
+ return result;
4420
+ }
4421
+ reduce(fn, init) {
4422
+ let iterator = this.entries();
4423
+ let first = iterator.next();
4424
+ if (first.done) {
4425
+ if (arguments.length < 2) {
4426
+ throw new TypeError("Reduce of empty Map2 with no initial value!");
4427
+ }
4428
+ return init;
4429
+ }
4430
+ let acc;
4431
+ let start;
4432
+ if (arguments.length < 2) {
4433
+ acc = first.value[2];
4434
+ start = iterator.next();
4435
+ } else {
4436
+ acc = init;
4437
+ start = first;
4438
+ }
4439
+ for (let current = start; !current.done; current = iterator.next()) {
4440
+ const [key1, key2, value] = current.value;
4441
+ acc = fn(acc, value, key1, key2);
4442
+ }
4443
+ return acc;
4444
+ }
4445
+ mapEntries(fn) {
4446
+ let result = [];
4447
+ for (const [key1, map2] of this.map1) {
4448
+ for (const [key2, value] of map2) {
4449
+ result.push(fn(value, key1, key2));
4450
+ }
4451
+ }
4452
+ return result;
4453
+ }
4454
+ mapValues(fn) {
4455
+ let result = new _Map2();
4456
+ for (const [key1, map2] of this.map1) {
4457
+ for (const [key2, value] of map2) {
4458
+ result.set(key1, key2, fn(value, key1, key2));
4459
+ }
4460
+ }
4461
+ return result;
4462
+ }
4463
+ toMap() {
4464
+ let result = /* @__PURE__ */ new Map();
4465
+ for (const [key1, map2] of this.map1) {
4466
+ for (const [key2, value] of map2) {
4467
+ result.set([key1, key2], value);
4468
+ }
4469
+ }
4470
+ return result;
4471
+ }
4472
+ toString() {
4473
+ const entries = [];
4474
+ for (const [key1, map2] of this.map1) {
4475
+ const inner = [...map2].map(([key2, v]) => `${stringify(key2)} => ${stringify(v)}`).join(", ");
4476
+ entries.push(`${stringify(key1)} => { ${inner} }`);
4477
+ }
4478
+ return entries.length === 0 ? `Map(${this.size}){ }` : `Map(${this.size}){ ${entries} }`;
4479
+ }
4480
+ };
4481
+
4482
+ // src/deprecated/map3.ts
4483
+ var Map3 = class _Map3 extends BaseContainer {
4484
+ constructor(entries) {
4485
+ super();
4486
+ __publicField(this, "map1", /* @__PURE__ */ new Map());
4487
+ if (entries instanceof _Map3) {
4488
+ for (const [key1, map2] of entries.map1) {
4489
+ const newMap2 = /* @__PURE__ */ new Map();
4490
+ for (const [key2, map3] of map2) {
4491
+ newMap2.set(key2, new Map(map3));
4492
+ }
4493
+ this.map1.set(key1, newMap2);
4494
+ }
4495
+ } else if (entries) {
4496
+ for (const [key1, key2, key3, value] of entries) {
4497
+ this.set(key1, key2, key3, value);
4498
+ }
4499
+ }
4500
+ }
4501
+ has(key1, key2, key3) {
4502
+ return this.map1.get(key1)?.get(key2)?.has(key3) ?? false;
4503
+ }
4504
+ set(key1, key2, key3, value) {
4505
+ let map2 = this.map1.get(key1);
4506
+ if (!map2) this.map1.set(key1, map2 = /* @__PURE__ */ new Map());
4507
+ let map3 = map2.get(key2);
4508
+ if (!map3) map2.set(key2, map3 = /* @__PURE__ */ new Map());
4509
+ map3.set(key3, value);
4510
+ return value;
4511
+ }
4512
+ get(key1, key2, key3) {
4513
+ return this.map1.get(key1)?.get(key2)?.get(key3);
4514
+ }
4515
+ getOrDefault(key1, key2, key3, defaultValue) {
4516
+ return this.get(key1, key2, key3) ?? defaultValue;
4517
+ }
4518
+ getOrCreate(key1, key2, key3, creatorOrValue) {
4519
+ if (!this.has(key1, key2, key3)) {
4520
+ const value = isFunction2(creatorOrValue) ? creatorOrValue() : creatorOrValue;
4521
+ this.set(key1, key2, key3, value);
4522
+ return value;
4523
+ }
4524
+ return this.get(key1, key2, key3);
4525
+ }
4526
+ delete(key1, key2, key3) {
4527
+ if (key3 === void 0) {
4528
+ if (key2 === void 0) return this.map1.delete(key1);
4529
+ const map2 = this.map1.get(key1);
4530
+ if (!map2) return false;
4531
+ return map2.delete(key2);
4532
+ } else {
4533
+ if (key2 === void 0) return this.map1.delete(key1);
4534
+ const map3 = this.map1.get(key1)?.get(key2);
4535
+ if (!map3) return false;
4536
+ return map3.delete(key3);
4537
+ }
4538
+ }
4539
+ clear() {
4540
+ this.map1.clear();
4541
+ }
4542
+ get size() {
4543
+ let count = 0;
4544
+ for (const map2 of this.map1.values()) {
4545
+ for (const map3 of map2.values()) {
4546
+ count += map3.size;
4547
+ }
4548
+ }
4549
+ return count;
4550
+ }
4551
+ isEmpty() {
4552
+ return this.size === 0;
4553
+ }
4554
+ forEach(callbackfn, thisArg) {
4555
+ this.map1.forEach((map2, key1) => map2.forEach((map3, key2) => map3.forEach((value, key3) => callbackfn.call(thisArg, value, key1, key2, key3, this))));
4556
+ }
4557
+ *keys() {
4558
+ for (const [key1, map2] of this.map1)
4559
+ for (const [key2, map3] of map2)
4560
+ for (const key3 of map3.keys())
4561
+ yield [key1, key2, key3];
4562
+ }
4563
+ *values() {
4564
+ for (const map2 of this.map1.values())
4565
+ for (const map3 of map2.values())
4566
+ for (const value of map3.values())
4567
+ yield value;
4568
+ }
4569
+ *entries() {
4570
+ for (const [key1, map2] of this.map1)
4571
+ for (const [key2, map3] of map2)
4572
+ for (const [key3, value] of map3)
4573
+ yield [key1, key2, key3, value];
4574
+ }
4575
+ keysArray() {
4576
+ return [...this.keys()];
4577
+ }
4578
+ valuesArray() {
4579
+ return [...this.values()];
4580
+ }
4581
+ entriesArray() {
4582
+ return [...this.entries()];
4583
+ }
4584
+ *kvKeys() {
4585
+ for (const [key1, key2, key3] of this.keys())
4586
+ yield [key1, key2, key3];
4587
+ }
4588
+ *kvValues() {
4589
+ for (const el of this.values())
4590
+ yield el;
4591
+ }
4592
+ *kvEntries() {
4593
+ for (const [key1, key2, key3, el] of this.entries())
4594
+ yield [[key1, key2, key3], el];
4595
+ }
4596
+ *[Symbol.iterator]() {
4597
+ yield* this.entries();
4598
+ }
4599
+ clone() {
4600
+ return new _Map3(this);
4601
+ }
4602
+ merge(other, conflictResolver) {
4603
+ for (const [key1, key2, key3, value] of other.entries()) {
4604
+ if (this.has(key1, key2, key3) && conflictResolver) {
4605
+ this.set(key1, key2, key3, conflictResolver(this.get(key1, key2, key3), value, key1, key2, key3));
4606
+ } else {
4607
+ this.set(key1, key2, key3, value);
4608
+ }
4609
+ }
4610
+ return this;
4611
+ }
4612
+ some(fn) {
4613
+ for (const [key1, map2] of this.map1) {
4614
+ for (const [key2, map3] of map2) {
4615
+ for (const [key3, value] of map3) {
4616
+ if (fn(value, key1, key2, key3)) return true;
4617
+ }
4618
+ }
4619
+ }
4620
+ return false;
4621
+ }
4622
+ every(fn) {
4623
+ for (const [key1, map2] of this.map1) {
4624
+ for (const [key2, map3] of map2) {
4625
+ for (const [key3, value] of map3) {
4626
+ if (!fn(value, key1, key2, key3)) return false;
4627
+ }
4628
+ }
4629
+ }
4630
+ return true;
4631
+ }
4632
+ filter(predicate) {
4633
+ const result = new this.constructor();
4634
+ for (const [key1, map2] of this.map1) {
4635
+ for (const [key2, map3] of map2) {
4636
+ for (const [key3, value] of map3) {
4637
+ if (predicate(value, key1, key2, key3, this)) result.set(key1, key2, key3, value);
4638
+ }
4639
+ }
4640
+ }
4641
+ return result;
4642
+ }
4643
+ reduce(fn, init) {
4644
+ let iterator = this.entries();
4645
+ let first = iterator.next();
4646
+ if (first.done) {
4647
+ if (arguments.length < 2) {
4648
+ throw new TypeError("Reduce of empty Map3 with no initial value!");
4649
+ }
4650
+ return init;
4651
+ }
4652
+ let acc;
4653
+ let start;
4654
+ if (arguments.length < 2) {
4655
+ acc = first.value[3];
4656
+ start = iterator.next();
4657
+ } else {
4658
+ acc = init;
4659
+ start = first;
4660
+ }
4661
+ for (let current = start; !current.done; current = iterator.next()) {
4662
+ const [key1, key2, key3, value] = current.value;
4663
+ acc = fn(acc, value, key1, key2, key3);
4664
+ }
4665
+ return acc;
4666
+ }
4667
+ mapEntries(fn) {
4668
+ let result = [];
4669
+ for (const [key1, map2] of this.map1) {
4670
+ for (const [key2, map3] of map2) {
4671
+ for (const [key3, value] of map3) {
4672
+ result.push(fn(value, key1, key2, key3));
4673
+ }
4674
+ }
4675
+ }
4676
+ return result;
4677
+ }
4678
+ mapValues(fn) {
4679
+ let result = new _Map3();
4680
+ for (const [key1, map2] of this.map1) {
4681
+ for (const [key2, map3] of map2) {
4682
+ for (const [key3, value] of map3) {
4683
+ result.set(key1, key2, key3, fn(value, key1, key2, key3));
4684
+ }
4685
+ }
4686
+ }
4687
+ return result;
4688
+ }
4689
+ toMap() {
4690
+ let result = /* @__PURE__ */ new Map();
4691
+ for (const [key1, map2] of this.map1) {
4692
+ for (const [key2, map3] of map2) {
4693
+ for (const [key3, value] of map3) {
4694
+ result.set([key1, key2, key3], value);
4695
+ }
4696
+ }
4697
+ }
4698
+ return result;
4699
+ }
4700
+ toString() {
4701
+ const entries = [];
4702
+ for (const [key1, map2] of this.map1) {
4703
+ for (const [key2, map3] of map2) {
4704
+ const inner = [...map3].map(([key3, v]) => `${stringify(key3)} => ${stringify(v)}`).join(", ");
4705
+ entries.push(`${stringify(key1)} => ${stringify(key2)} => { ${inner} }`);
4706
+ }
4707
+ }
4708
+ return entries.length === 0 ? `Map(${this.size}){ }` : `Map(${this.size}){ ${entries.join(", ")} }`;
4709
+ }
4710
+ };
4711
+
4712
+ // src/deprecated/set.ts
4713
+ var SetBase = class extends BaseContainer {
4714
+ constructor(entries) {
4715
+ super();
4716
+ __publicField(this, "data");
4717
+ this.data = new Set(entries ?? []);
4718
+ }
4719
+ has(value) {
4720
+ return this.some((v) => this.valueEquals(v, value));
4721
+ }
4722
+ add(value) {
4723
+ if (!this.has(value))
4724
+ this.data.add(value);
4725
+ return value;
4726
+ }
4727
+ /** @internal - This method exists only for interface `KVComponent` compatibility.*/
4728
+ set(key, value) {
4729
+ if (!this.valueEquals(key, value))
4730
+ throw new TypeError("SetBase.set() requires key === value.");
4731
+ this.add(value);
4732
+ }
4733
+ /** @internal - This method exists only for interface `KVComponent` compatibility.*/
4734
+ get(key) {
4735
+ return this.has(key) ? key : void 0;
4736
+ }
4737
+ /** @internal - This method exists only for interface `KVComponent` compatibility.*/
4738
+ getOrDefault(key, defaultValue) {
4739
+ return this.get(key) ?? defaultValue;
4740
+ }
4741
+ getOrCreate(key, creatorOrValue) {
4742
+ if (!this.has(key)) {
4743
+ const value = isFunction2(creatorOrValue) ? creatorOrValue() : creatorOrValue;
4744
+ this.set(key, value);
4745
+ return value;
4746
+ }
4747
+ return this.get(key);
4748
+ }
4749
+ delete(value) {
4750
+ if (!this.has(value)) return false;
4751
+ for (const v of this.values()) {
4752
+ if (this.valueEquals(v, value)) {
4753
+ this.data.delete(v);
4754
+ return true;
4755
+ }
4756
+ }
4757
+ return false;
4758
+ }
4759
+ clear() {
4760
+ this.data.clear();
4761
+ }
4762
+ get size() {
4763
+ return this.data.size;
4764
+ }
4765
+ isEmpty() {
4766
+ return this.size === 0;
4767
+ }
4768
+ forEach(callbackfn, thisArg) {
4769
+ this.data.forEach((value) => callbackfn.call(thisArg, value, this));
4770
+ }
4771
+ *keys() {
4772
+ yield* this.data.keys();
4773
+ }
4774
+ *values() {
4775
+ yield* this.data.values();
4776
+ }
4777
+ *entries() {
4778
+ yield* this.data.entries();
4779
+ }
4780
+ *kvKeys() {
4781
+ for (const key of this.keys()) {
4782
+ yield [key];
4783
+ }
4784
+ }
4785
+ *kvValues() {
4786
+ for (const el of this.values()) {
4787
+ yield el;
4788
+ }
4789
+ }
4790
+ *kvEntries() {
4791
+ for (const [key, el] of this.entries()) {
4792
+ yield [[key], el];
4793
+ }
4794
+ }
4795
+ *[Symbol.iterator]() {
4796
+ yield* this.values();
4797
+ }
4798
+ clone() {
4799
+ const result = this.createEmpty();
4800
+ for (const v of this.values()) result.add(v);
4801
+ return result;
4802
+ }
4803
+ merge(other) {
4804
+ for (const value of other.values()) {
4805
+ this.add(value);
4806
+ }
4807
+ return this;
4808
+ }
4809
+ some(fn) {
4810
+ for (const value of this.data) {
4811
+ if (fn(value)) return true;
4812
+ }
4813
+ return false;
4814
+ }
4815
+ every(fn) {
4816
+ for (const value of this.data) {
4817
+ if (!fn(value)) return false;
4818
+ }
4819
+ return true;
4820
+ }
4821
+ filter(predicate) {
4822
+ const result = this.createEmpty();
4823
+ for (const value of this.data)
4824
+ if (predicate(value, this)) result.add(value);
4825
+ return result;
4826
+ }
4827
+ reduce(fn, init) {
4828
+ let iterator = this.values();
4829
+ let first = iterator.next();
4830
+ if (first.done) {
4831
+ if (arguments.length < 2) {
4832
+ throw new TypeError("Reduce of empty SetBase with no initial value!");
4833
+ }
4834
+ return init;
4835
+ }
4836
+ let acc;
4837
+ let start;
4838
+ if (arguments.length < 2) {
4839
+ acc = first.value;
4840
+ start = iterator.next();
4841
+ } else {
4842
+ acc = init;
4843
+ start = first;
4844
+ }
4845
+ for (let current = start; !current.done; current = iterator.next()) {
4846
+ const value = current.value;
4847
+ acc = fn(acc, value);
4848
+ }
4849
+ return acc;
4850
+ }
4851
+ mapValues(fn) {
4852
+ let result = this.createEmpty();
4853
+ for (const value of this.data) {
4854
+ result.add(fn(value));
4855
+ }
4856
+ return result;
4857
+ }
4858
+ mapToArray(fn) {
4859
+ let result = [];
4860
+ for (const value of this.values()) {
4861
+ result.push(fn(value));
4862
+ }
4863
+ return result;
4864
+ }
4865
+ map(fn) {
4866
+ let result = this.createEmpty();
4867
+ for (const value of this.values()) {
4868
+ result.add(fn(value));
4869
+ }
4870
+ return result;
4871
+ }
4872
+ toSet() {
4873
+ return new Set(this.data);
4874
+ }
4875
+ toArray() {
4876
+ return [...this.values()];
4877
+ }
4878
+ toString() {
4879
+ return stringify(this.data);
4880
+ }
4881
+ };
4882
+ var Set1 = class _Set1 extends SetBase {
4883
+ constructor(entries) {
4884
+ super(entries);
4885
+ }
4886
+ createEmpty() {
4887
+ return new _Set1();
4888
+ }
4889
+ valueEquals(a, b) {
4890
+ return a === b;
4891
+ }
4892
+ };
4893
+ var DeepSet = class _DeepSet extends SetBase {
4894
+ constructor(entries) {
4895
+ super(entries);
4896
+ }
4897
+ createEmpty() {
4898
+ return new _DeepSet();
4899
+ }
4900
+ valueEquals(a, b) {
4901
+ return isDeepEqual2(a, b);
4902
+ }
4903
+ };
3344
4904
  // Annotate the CommonJS export names for ESM import in node:
3345
4905
  0 && (module.exports = {
3346
4906
  Assert,
4907
+ BaseContainer,
4908
+ BiMap,
3347
4909
  Cookies,
4910
+ DeepSet,
4911
+ DefaultArray,
4912
+ DefaultEqualityFn,
3348
4913
  Device,
3349
4914
  DivRect,
3350
4915
  Guard,
3351
4916
  IndexArray,
3352
4917
  LRUCache,
4918
+ LinkedList,
3353
4919
  Map1,
3354
4920
  Map2,
3355
4921
  Map3,
3356
4922
  MultiContainer,
4923
+ Set1,
4924
+ SetBase,
3357
4925
  SignedIndexArray,
3358
4926
  SmallIntCache,
3359
4927
  Stack,
4928
+ TriMap,
4929
+ UniMap,
3360
4930
  Utils,
4931
+ ValueSet,
3361
4932
  Vec,
3362
4933
  Vec2,
3363
4934
  asMulti