@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.mjs 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
  var __defProp = Object.defineProperty;
3
3
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4
4
  var __export = (target, all) => {
@@ -64,6 +64,7 @@ __export(assert_exports, {
64
64
  isNonEmptyArrayOrUndefined: () => isNonEmptyArrayOrUndefined,
65
65
  isNonEmptyString: () => isNonEmptyString,
66
66
  isNonEmptyStringOrUndefined: () => isNonEmptyStringOrUndefined,
67
+ isNotThrowing: () => isNotThrowing,
67
68
  isNull: () => isNull,
68
69
  isNullish: () => isNullish,
69
70
  isNumber: () => isNumber,
@@ -459,6 +460,11 @@ function isThrowing(throwTestFn, msg) {
459
460
  _fail(`Expected to throw`, msg);
460
461
  return true;
461
462
  }
463
+ function isNotThrowing(throwTestFn, msg) {
464
+ if (!guard_exports.isNotThrowing(throwTestFn))
465
+ _fail(`Expected to throw`, msg);
466
+ return true;
467
+ }
462
468
 
463
469
  // src/web/cookies.ts
464
470
  var cookies_exports = {};
@@ -706,6 +712,7 @@ __export(guard_exports, {
706
712
  isNonEmptyArrayOrUndefined: () => isNonEmptyArrayOrUndefined2,
707
713
  isNonEmptyString: () => isNonEmptyString2,
708
714
  isNonEmptyStringOrUndefined: () => isNonEmptyStringOrUndefined2,
715
+ isNotThrowing: () => isNotThrowing2,
709
716
  isNull: () => isNull2,
710
717
  isNullish: () => isNullish2,
711
718
  isNumber: () => isNumber2,
@@ -955,6 +962,14 @@ function isThrowing2(throwTestFn) {
955
962
  return true;
956
963
  }
957
964
  }
965
+ function isNotThrowing2(throwTestFn) {
966
+ try {
967
+ throwTestFn();
968
+ return true;
969
+ } catch (err) {
970
+ return false;
971
+ }
972
+ }
958
973
  function tryOr(tryFn, orVal) {
959
974
  try {
960
975
  return tryFn();
@@ -1388,99 +1403,19 @@ __export(str_exports, {
1388
1403
  removeAt: () => removeAt,
1389
1404
  repeatString: () => repeatString,
1390
1405
  replaceAt: () => replaceAt,
1406
+ stringify: () => stringify,
1391
1407
  toCharArray: () => toCharArray
1392
1408
  });
1393
- function toCharArray(str2) {
1394
- return str2.split("");
1395
- }
1396
- function repeatString(repeatString2, repeatCount) {
1397
- if (!isInteger2(repeatCount) || repeatCount < 0) {
1398
- throw new Error("repeatStr: Invalid repeatCount = " + repeatCount);
1399
- }
1400
- return new Array(repeatCount + 1).join(repeatString2);
1401
- }
1402
- function chunkString(str2, chunkSize) {
1403
- if (!isInteger2(chunkSize) || chunkSize < 1) {
1404
- throw new Error("chunckString: Invalid chuckSize = " + chunkSize);
1405
- }
1406
- let result = [];
1407
- for (let i = 0; i < str2.length; i += chunkSize) {
1408
- result.push(str2.slice(i, i + chunkSize));
1409
- }
1410
- return result;
1411
- }
1412
- function replaceAt(str2, pos, removeCount, insert) {
1413
- if (!isInteger2(removeCount) || removeCount < 0) {
1414
- throw new Error("replaceAt: Invalid removeCount = " + removeCount);
1415
- } else if (!isInteger2(pos) || pos < 0 || pos + removeCount > str2.length) {
1416
- throw new Error("replaceAt: Invalid pos = " + pos + ", removeCount = " + removeCount + ", str.length = " + str2.length);
1417
- } else {
1418
- return str2.substring(0, pos) + insert + str2.substring(pos + removeCount);
1419
- }
1420
- }
1421
- function insertAt(str2, pos, insertStr) {
1422
- return replaceAt(str2, pos, 0, insertStr);
1423
- }
1424
- function removeAt(str2, pos, removeCount) {
1425
- return replaceAt(str2, pos, removeCount, "");
1426
- }
1427
- function charCount(str2, ch) {
1428
- if (ch.length !== 1 || str2.length === 0) return 0;
1429
- let count = 0;
1430
- for (let i = 0; i < str2.length; i++) {
1431
- if (str2[i] === ch) count++;
1432
- }
1433
- return count;
1434
- }
1435
- function makeSentenceFromPascal(PascalString) {
1436
- if (PascalString === "") {
1437
- return "";
1438
- }
1439
- let word = PascalString.charAt(0);
1440
- let sentence = "";
1441
- const addWord = () => {
1442
- if (word !== "") {
1443
- if (sentence === "") {
1444
- sentence += word.charAt(0).toUpperCase() + word.substring(1);
1445
- } else {
1446
- sentence += " " + word;
1447
- }
1448
- word = "";
1449
- }
1450
- };
1451
- const isLetterAndCapital = (c) => {
1452
- return c.toUpperCase() !== c.toLowerCase() && c === c.toUpperCase();
1453
- };
1454
- for (let i = 1; i < PascalString.length; i++) {
1455
- let c = PascalString.charAt(i);
1456
- if (isLetterAndCapital(c)) {
1457
- addWord();
1458
- }
1459
- word += c.toLowerCase();
1460
- }
1461
- addWord();
1462
- return sentence;
1463
- }
1464
-
1465
- // src/utils/index.ts
1466
- var Is = guard_exports;
1467
1409
 
1468
- // src/core/format-value.ts
1469
- function formatValue(value) {
1470
- if (isString2(value)) {
1471
- return `"${value}"`;
1472
- } else if (isArray2(value)) {
1473
- return `[ ${value.map((e) => formatValue(e)).join(", ")} ]`.replaceAll(" ", " ");
1474
- } else if (isFunction2(value.toString)) {
1475
- return value.toString();
1476
- } else {
1477
- return JSON.stringify(value);
1478
- }
1479
- }
1410
+ // src/core/base.ts
1411
+ var DefaultEqualityFn = (a, b) => a === b;
1412
+ var BaseContainer = class {
1413
+ };
1480
1414
 
1481
1415
  // src/core/stack.ts
1482
- var Stack = class {
1416
+ var Stack = class extends BaseContainer {
1483
1417
  constructor() {
1418
+ super();
1484
1419
  __publicField(this, "data", []);
1485
1420
  }
1486
1421
  assertId(id) {
@@ -1541,13 +1476,14 @@ var Stack = class {
1541
1476
  this.data.length = 0;
1542
1477
  }
1543
1478
  toString() {
1544
- return `Stack(${this.length})${formatValue(this.data)}`;
1479
+ return `Stack(${this.length})${stringify(this.data)}`;
1545
1480
  }
1546
1481
  };
1547
1482
 
1548
1483
  // src/core/vec.ts
1549
- var Vec = class _Vec {
1484
+ var Vec = class _Vec extends BaseContainer {
1550
1485
  constructor(...coords) {
1486
+ super();
1551
1487
  __publicField(this, "coords");
1552
1488
  if (coords.length < 2) {
1553
1489
  throw new TypeError("Vec needs minumum two coords!");
@@ -1748,19 +1684,31 @@ var DivRect = class _DivRect {
1748
1684
  static createSections(leftw, rightw, toph, bottomh) {
1749
1685
  return new _DivRect(-leftw, 0, rightw, -toph, 0, bottomh);
1750
1686
  }
1751
- /** @deprecated - Renamed to anchorX. */
1687
+ /**
1688
+ * @deprecated - Renamed to anchorX. Will be removed in v2.0.0.
1689
+ * @private
1690
+ * */
1752
1691
  get centerX() {
1753
1692
  return this.anchorX;
1754
1693
  }
1755
- /** @deprecated - Renamed to anchorX. */
1694
+ /**
1695
+ * @deprecated - Renamed to anchorX. Will be removed in v2.0.0.
1696
+ * @private
1697
+ * */
1756
1698
  set centerX(x) {
1757
1699
  this.anchorX = x;
1758
1700
  }
1759
- /** @deprecated - Renamed to anchorY. */
1701
+ /**
1702
+ * @deprecated - Renamed to anchorX. Will be removed in v2.0.0.
1703
+ * @private
1704
+ * */
1760
1705
  get centerY() {
1761
1706
  return this.anchorY;
1762
1707
  }
1763
- /** @deprecated - Renamed to anchorY. */
1708
+ /**
1709
+ * @deprecated - Renamed to anchorX. Will be removed in v2.0.0.
1710
+ * @private
1711
+ * */
1764
1712
  set centerY(y) {
1765
1713
  this.anchorY = y;
1766
1714
  }
@@ -1878,7 +1826,10 @@ var DivRect = class _DivRect {
1878
1826
  equalsEdges(other) {
1879
1827
  return _DivRect.equalsEdges(this, other);
1880
1828
  }
1881
- /** @deprecated - Use `DivRect.equalsEdges()` instead. */
1829
+ /**
1830
+ * @deprecated - Use `DivRect.equalsEdges()` instead. Will be removed in v2.0.0.
1831
+ * @private
1832
+ */
1882
1833
  static equalsFrame(a, b) {
1883
1834
  return _DivRect.equalsEdges(a, b);
1884
1835
  }
@@ -1997,9 +1948,10 @@ var DivRect = class _DivRect {
1997
1948
  };
1998
1949
 
1999
1950
  // src/core/LRU-cache.ts
2000
- var LRUCache = class {
1951
+ var LRUCache = class extends BaseContainer {
2001
1952
  // Maximum key length.
2002
1953
  constructor(maxSize, maxKeyLength = Infinity) {
1954
+ super();
2003
1955
  __publicField(this, "cache");
2004
1956
  // Stores the actual key-value pairs
2005
1957
  __publicField(this, "next");
@@ -2091,11 +2043,31 @@ var LRUCache = class {
2091
2043
  }
2092
2044
  this.tail = key;
2093
2045
  }
2046
+ *keys() {
2047
+ for (let key = this.head; key != null; key = this.next[key])
2048
+ yield key;
2049
+ }
2050
+ *values() {
2051
+ for (let key = this.head; key != null; key = this.next[key])
2052
+ yield this.cache[key];
2053
+ }
2054
+ *entries() {
2055
+ for (let key = this.head; key != null; key = this.next[key])
2056
+ yield [key, this.cache[key]];
2057
+ }
2058
+ *[Symbol.iterator]() {
2059
+ yield* this.entries();
2060
+ }
2061
+ toString() {
2062
+ const entries = [...this.entries()];
2063
+ return entries.length === 0 ? `LRUCache(0){ }` : `LRUCache(${entries.length}){ ${entries.map((e) => `${stringify(e[0])}: ${stringify(e[1])}`).join(", ")} }`;
2064
+ }
2094
2065
  };
2095
2066
 
2096
2067
  // src/core/index-array.ts
2097
- var IndexArray = class _IndexArray {
2068
+ var IndexArray = class _IndexArray extends BaseContainer {
2098
2069
  constructor(entries) {
2070
+ super();
2099
2071
  __publicField(this, "posVal");
2100
2072
  __publicField(this, "hasPos");
2101
2073
  // Number of values
@@ -2308,14 +2280,20 @@ var IndexArray = class _IndexArray {
2308
2280
  return this.valuesArray();
2309
2281
  }
2310
2282
  toString() {
2311
- const entries = this.entriesArray().map(([id, v]) => `${formatValue(id)}: ${formatValue(v)}`).join(", ");
2312
- return `IndexArray[ ${entries} ]`.replaceAll(" ", " ");
2283
+ let isRegularArray = true;
2284
+ for (let i = 0; i < this.hasPos.length && isRegularArray; i++)
2285
+ if (!this.hasPos[i]) isRegularArray = false;
2286
+ if (isRegularArray)
2287
+ return stringify(this.posVal.slice(0, this.hasPos.length));
2288
+ const entries = this.entriesArray().map(([id, v]) => `${stringify(id)}: ${stringify(v)}`).join(", ");
2289
+ return entries.length === 0 ? `[ ]` : `[ ${entries} ]`;
2313
2290
  }
2314
2291
  };
2315
2292
 
2316
2293
  // src/core/signed-index-array.ts
2317
- var SignedIndexArray = class _SignedIndexArray {
2294
+ var SignedIndexArray = class _SignedIndexArray extends BaseContainer {
2318
2295
  constructor(entries) {
2296
+ super();
2319
2297
  // For indexes >= 0
2320
2298
  __publicField(this, "posVal");
2321
2299
  __publicField(this, "hasPos");
@@ -2571,65 +2549,101 @@ var SignedIndexArray = class _SignedIndexArray {
2571
2549
  return this.valuesArray();
2572
2550
  }
2573
2551
  toString() {
2574
- const entries = this.entriesArray().map(([id, v]) => `${formatValue(id)}: ${formatValue(v)}`).join(", ");
2575
- return `SignedIndexArray[ ${entries} ]`.replaceAll(" ", " ");
2552
+ let isRegularArray = this.hasNeg.length === 0;
2553
+ for (let i = 0; i < this.hasPos.length && isRegularArray; i++)
2554
+ if (!this.hasPos[i]) isRegularArray = false;
2555
+ if (isRegularArray)
2556
+ return stringify(this.posVal.slice(0, this.hasPos.length));
2557
+ const entries = this.entriesArray().map(([id, v]) => `${stringify(id)}: ${stringify(v)}`).join(", ");
2558
+ return entries.length === 0 ? `[ ]` : `[ ${entries} ]`;
2576
2559
  }
2577
2560
  };
2578
2561
 
2579
- // src/core/map1.ts
2580
- var Map1 = class _Map1 {
2581
- constructor(entries) {
2582
- __publicField(this, "map1");
2583
- this.map1 = entries instanceof _Map1 ? new Map(entries.map1) : new Map(entries);
2562
+ // src/core/default-array.ts
2563
+ var DefaultArray = class _DefaultArray extends BaseContainer {
2564
+ constructor(...args) {
2565
+ super();
2566
+ __publicField(this, "defaultValue");
2567
+ __publicField(this, "data");
2568
+ this.defaultValue = args.pop();
2569
+ if (typeof args[0] === "number") {
2570
+ this.data = Array(args[0]).fill(this.defaultValue);
2571
+ } else {
2572
+ this.data = Array.from(args[0]).map(
2573
+ (v) => v === void 0 ? this.defaultValue : v
2574
+ );
2575
+ }
2584
2576
  }
2585
- has(key1) {
2586
- return this.map1.has(key1);
2577
+ get size() {
2578
+ return this.data.length;
2587
2579
  }
2588
- set(key1, value) {
2589
- this.map1.set(key1, value);
2590
- return value;
2580
+ get length() {
2581
+ return this.data.length;
2591
2582
  }
2592
- get(key1) {
2593
- return this.map1.get(key1);
2583
+ assertId(id) {
2584
+ if (id < 0 || id >= this.data.length)
2585
+ throw new RangeError(`DefaultArray: Index ${id} out of range`);
2586
+ return id;
2594
2587
  }
2595
- getOrDefault(key1, defaultValue) {
2596
- return this.get(key1) ?? defaultValue;
2588
+ isEmpty() {
2589
+ return this.size === 0;
2597
2590
  }
2598
- getOrCreate(key1, creatorOrValue) {
2599
- if (!this.has(key1)) {
2591
+ isDefault(id) {
2592
+ return this.data[this.assertId(id)] === this.defaultValue;
2593
+ }
2594
+ isSet(id) {
2595
+ return this.data[this.assertId(id)] !== this.defaultValue;
2596
+ }
2597
+ /** @internal - This method exists only for interface `KVComponent` compatibility.*/
2598
+ has(id) {
2599
+ return this.isSet(id);
2600
+ }
2601
+ set(id, value) {
2602
+ return this.data[this.assertId(id)] = value;
2603
+ }
2604
+ get(id) {
2605
+ return this.data[this.assertId(id)];
2606
+ }
2607
+ getOrDefault(id, defaultValue) {
2608
+ let value = this.get(id);
2609
+ return value === this.defaultValue ? defaultValue : value;
2610
+ }
2611
+ getOrCreate(id, creatorOrValue) {
2612
+ if (!this.has(id)) {
2600
2613
  const value = isFunction2(creatorOrValue) ? creatorOrValue() : creatorOrValue;
2601
- this.set(key1, value);
2614
+ this.set(id, value);
2602
2615
  return value;
2603
2616
  }
2604
- return this.get(key1);
2605
- }
2606
- delete(key1) {
2607
- return this.map1.delete(key1);
2608
- }
2609
- clear() {
2610
- this.map1.clear();
2617
+ return this.get(id);
2611
2618
  }
2612
- get size() {
2613
- return this.map1.size;
2619
+ delete(id) {
2620
+ this.assertId(id);
2621
+ if (this.data[id] === this.defaultValue) return false;
2622
+ this.data[id] = this.defaultValue;
2623
+ return true;
2614
2624
  }
2615
- isEmpty() {
2616
- return this.size === 0;
2625
+ clear(empty = false) {
2626
+ if (empty)
2627
+ this.data = [];
2628
+ else
2629
+ this.data.fill(this.defaultValue);
2617
2630
  }
2618
2631
  forEach(callbackfn, thisArg) {
2619
- this.map1.forEach((value, key1) => callbackfn.call(thisArg, value, key1, this));
2632
+ for (const [id, value] of this.entries()) {
2633
+ callbackfn.call(thisArg, value, id, this);
2634
+ }
2620
2635
  }
2621
- *keys() {
2622
- yield* this.map1.keys();
2636
+ *indices() {
2637
+ yield* this.data.keys();
2623
2638
  }
2624
2639
  *values() {
2625
- yield* this.map1.values();
2640
+ yield* this.data.values();
2626
2641
  }
2627
2642
  *entries() {
2628
- for (const [key1, value] of this.map1)
2629
- yield [key1, value];
2643
+ yield* this.data.entries();
2630
2644
  }
2631
- keysArray() {
2632
- return [...this.keys()];
2645
+ indicesArray() {
2646
+ return [...this.indices()];
2633
2647
  }
2634
2648
  valuesArray() {
2635
2649
  return [...this.values()];
@@ -2638,52 +2652,58 @@ var Map1 = class _Map1 {
2638
2652
  return [...this.entries()];
2639
2653
  }
2640
2654
  *kvKeys() {
2641
- for (const key of this.keys()) {
2642
- yield [key];
2655
+ for (const id of this.indices()) {
2656
+ yield [id];
2643
2657
  }
2644
2658
  }
2645
2659
  *kvValues() {
2646
- for (const el of this.values()) {
2647
- yield el;
2660
+ for (const value of this.values()) {
2661
+ yield value;
2648
2662
  }
2649
2663
  }
2650
2664
  *kvEntries() {
2651
- for (const [key, el] of this.entries()) {
2652
- yield [[key], el];
2665
+ for (const [id, value] of this.entries()) {
2666
+ yield [[id], value];
2653
2667
  }
2654
2668
  }
2655
2669
  *[Symbol.iterator]() {
2656
2670
  yield* this.entries();
2657
2671
  }
2658
2672
  clone() {
2659
- return new _Map1(this);
2673
+ const ctor = this.constructor;
2674
+ return new ctor(this.values(), this.defaultValue);
2660
2675
  }
2661
2676
  merge(other, conflictResolver) {
2662
- for (const [key1, value] of other.entries()) {
2663
- if (this.has(key1) && conflictResolver) {
2664
- this.set(key1, conflictResolver(this.get(key1), value, key1));
2665
- } else {
2666
- this.set(key1, value);
2667
- }
2677
+ if (this.constructor !== other.constructor)
2678
+ throw new Error(`Cannot merge DefaultArray: different classes (${this.constructor.name} vs ${other.constructor.name})`);
2679
+ if (this.defaultValue !== other.defaultValue)
2680
+ throw new Error(`Cannot merge DefaultArray: different defaultValue (${this.defaultValue} vs ${other.defaultValue})`);
2681
+ for (const [id, value] of other.entries()) {
2682
+ if (this.isDefault(id))
2683
+ this.set(id, value);
2684
+ else if (conflictResolver)
2685
+ this.set(id, conflictResolver(this.get(id), value, id));
2686
+ else
2687
+ this.set(id, value);
2668
2688
  }
2669
2689
  return this;
2670
2690
  }
2671
2691
  some(fn) {
2672
- for (const [key1, value] of this.map1) {
2673
- if (fn(value, key1)) return true;
2692
+ for (const [id, value] of this.entries()) {
2693
+ if (fn(value, id)) return true;
2674
2694
  }
2675
2695
  return false;
2676
2696
  }
2677
2697
  every(fn) {
2678
- for (const [key1, value] of this.map1) {
2679
- if (!fn(value, key1)) return false;
2698
+ for (const [id, value] of this.entries()) {
2699
+ if (!fn(value, id)) return false;
2680
2700
  }
2681
2701
  return true;
2682
2702
  }
2683
2703
  filter(predicate) {
2684
- const result = new this.constructor();
2685
- for (const [key1, value] of this.map1) {
2686
- if (predicate(value, key1, this)) result.set(key1, value);
2704
+ const result = new this.constructor(this.length, this.defaultValue);
2705
+ for (const [id, value] of this.entries()) {
2706
+ if (predicate(value, id, this)) result.set(id, value);
2687
2707
  }
2688
2708
  return result;
2689
2709
  }
@@ -2692,7 +2712,7 @@ var Map1 = class _Map1 {
2692
2712
  let first = iterator.next();
2693
2713
  if (first.done) {
2694
2714
  if (arguments.length < 2) {
2695
- throw new TypeError("Reduce of empty Map1 with no initial value!");
2715
+ throw new TypeError("Reduce of empty DefaultArray with no initial value!");
2696
2716
  }
2697
2717
  return init;
2698
2718
  }
@@ -2706,58 +2726,259 @@ var Map1 = class _Map1 {
2706
2726
  start = first;
2707
2727
  }
2708
2728
  for (let current = start; !current.done; current = iterator.next()) {
2709
- const [key1, value] = current.value;
2710
- acc = fn(acc, value, key1);
2729
+ const [id, value] = current.value;
2730
+ acc = fn(acc, value, id);
2711
2731
  }
2712
2732
  return acc;
2713
2733
  }
2714
- mapEntries(fn) {
2734
+ mapToArray(fn) {
2715
2735
  let result = [];
2716
- for (const [key1, value] of this.map1) {
2717
- result.push(fn(value, key1));
2736
+ for (const [id, value] of this.entries()) {
2737
+ result.push(fn(value, id));
2718
2738
  }
2719
2739
  return result;
2720
2740
  }
2721
- mapValues(fn) {
2722
- let result = new _Map1();
2723
- for (const [key1, value] of this.map1) {
2724
- result.set(key1, fn(value, key1));
2741
+ map(fn, defaultValue) {
2742
+ let result = new _DefaultArray(this.data.length, defaultValue);
2743
+ for (let id = 0; id < this.data.length; id++) {
2744
+ result.data[id] = fn(this.data[id], id);
2725
2745
  }
2726
2746
  return result;
2727
2747
  }
2728
- toMap() {
2729
- return new Map(this.map1);
2748
+ equals(other, eq2) {
2749
+ if (this.size !== other.size) return false;
2750
+ eq2 ?? (eq2 = (a, b) => a === b);
2751
+ for (let id = 0; id < this.data.length; ++id) {
2752
+ if (!eq2(this.data[id], other.data[id])) return false;
2753
+ }
2754
+ return true;
2755
+ }
2756
+ toArray() {
2757
+ return this.valuesArray();
2730
2758
  }
2731
2759
  toString() {
2732
- const entries = [...this.map1].map(([k, v]) => `${formatValue(k)} => ${formatValue(v)}`).join(", ");
2733
- return `Map1(${this.size}){ ${entries} }`.replaceAll(" ", " ");
2760
+ return stringify(this.data);
2734
2761
  }
2735
2762
  };
2736
2763
 
2737
- // src/core/map2.ts
2738
- var Map2 = class _Map2 {
2739
- constructor(entries) {
2740
- __publicField(this, "map1", /* @__PURE__ */ new Map());
2741
- if (entries instanceof _Map2) {
2742
- for (const [key1, inner] of entries.map1) {
2743
- this.map1.set(key1, new Map(inner));
2744
- }
2745
- } else if (entries) {
2746
- for (const [key1, key2, value] of entries) {
2747
- this.set(key1, key2, value);
2748
- }
2749
- }
2764
+ // src/core/uni-map.ts
2765
+ var UniMap = class _UniMap extends BaseContainer {
2766
+ constructor(...args) {
2767
+ super();
2768
+ __publicField(this, "map");
2769
+ __publicField(this, "keyEquals");
2770
+ const maybeEquals = args.at(-1);
2771
+ this.keyEquals = isFunction2(maybeEquals) ? args.pop() : DefaultEqualityFn;
2772
+ const entries = args[0];
2773
+ this.map = new Map(entries);
2750
2774
  }
2751
- has(key1, key2) {
2752
- return this.map1.get(key1)?.has(key2) ?? false;
2775
+ static createDeep(arg) {
2776
+ return arg ? new _UniMap(arg, isDeepEqual2) : new _UniMap(isDeepEqual2);
2753
2777
  }
2754
- set(key1, key2, value) {
2755
- let map2 = this.map1.get(key1) ?? this.map1.set(key1, /* @__PURE__ */ new Map()).get(key1);
2756
- map2.set(key2, value);
2757
- return value;
2778
+ has(key) {
2779
+ if (this.keyEquals === DefaultEqualityFn || this.map.has(key))
2780
+ return this.map.has(key);
2781
+ for (const [k, v] of this.map)
2782
+ if (this.keyEquals(k, key))
2783
+ return true;
2784
+ return false;
2758
2785
  }
2759
- get(key1, key2) {
2760
- return this.map1.get(key1)?.get(key2);
2786
+ set(key, value) {
2787
+ if (this.keyEquals === DefaultEqualityFn || this.map.has(key)) {
2788
+ this.map.set(key, value);
2789
+ return value;
2790
+ }
2791
+ for (const key2 of this.map.keys())
2792
+ if (this.keyEquals(key2, key)) {
2793
+ this.map.set(key2, value);
2794
+ return value;
2795
+ }
2796
+ this.map.set(key, value);
2797
+ return value;
2798
+ }
2799
+ get(key) {
2800
+ if (this.keyEquals === DefaultEqualityFn || this.map.has(key))
2801
+ return this.map.get(key);
2802
+ for (const [k, v] of this.map)
2803
+ if (this.keyEquals(k, key))
2804
+ return v;
2805
+ return void 0;
2806
+ }
2807
+ delete(key) {
2808
+ if (this.keyEquals === DefaultEqualityFn || this.map.has(key))
2809
+ return this.map.delete(key);
2810
+ for (const k of this.map.keys())
2811
+ if (this.keyEquals(k, key))
2812
+ return this.map.delete(k);
2813
+ return this.map.delete(key);
2814
+ }
2815
+ getOrDefault(key, defaultValue) {
2816
+ return this.get(key) ?? defaultValue;
2817
+ }
2818
+ getOrCreate(key, creatorOrValue) {
2819
+ if (!this.has(key)) {
2820
+ const value = isFunction2(creatorOrValue) ? creatorOrValue() : creatorOrValue;
2821
+ return this.set(key, value);
2822
+ }
2823
+ return this.get(key);
2824
+ }
2825
+ clear() {
2826
+ this.map.clear();
2827
+ }
2828
+ get size() {
2829
+ return this.map.size;
2830
+ }
2831
+ isEmpty() {
2832
+ return this.size === 0;
2833
+ }
2834
+ forEach(callbackfn, thisArg) {
2835
+ this.map.forEach((value, key) => callbackfn.call(thisArg, value, key, this));
2836
+ }
2837
+ *keys() {
2838
+ yield* this.map.keys();
2839
+ }
2840
+ *values() {
2841
+ yield* this.map.values();
2842
+ }
2843
+ *entries() {
2844
+ for (const [key, value] of this.map)
2845
+ yield [key, value];
2846
+ }
2847
+ keysArray() {
2848
+ return [...this.keys()];
2849
+ }
2850
+ valuesArray() {
2851
+ return [...this.values()];
2852
+ }
2853
+ entriesArray() {
2854
+ return [...this.entries()];
2855
+ }
2856
+ *kvKeys() {
2857
+ for (const key of this.keys()) {
2858
+ yield [key];
2859
+ }
2860
+ }
2861
+ *kvValues() {
2862
+ for (const el of this.values()) {
2863
+ yield el;
2864
+ }
2865
+ }
2866
+ *kvEntries() {
2867
+ for (const [key, el] of this.entries()) {
2868
+ yield [[key], el];
2869
+ }
2870
+ }
2871
+ *[Symbol.iterator]() {
2872
+ yield* this.entries();
2873
+ }
2874
+ clone() {
2875
+ return new _UniMap(this, this.keyEquals);
2876
+ }
2877
+ merge(other, conflictResolver) {
2878
+ for (const [key, value] of other.entries()) {
2879
+ if (this.has(key) && conflictResolver) {
2880
+ this.set(key, conflictResolver(this.get(key), value, key));
2881
+ } else {
2882
+ this.set(key, value);
2883
+ }
2884
+ }
2885
+ return this;
2886
+ }
2887
+ some(fn) {
2888
+ for (const [key, value] of this.map) {
2889
+ if (fn(value, key)) return true;
2890
+ }
2891
+ return false;
2892
+ }
2893
+ every(fn) {
2894
+ for (const [key, value] of this.map) {
2895
+ if (!fn(value, key)) return false;
2896
+ }
2897
+ return true;
2898
+ }
2899
+ filter(predicate) {
2900
+ const result = new this.constructor();
2901
+ for (const [key, value] of this.map) {
2902
+ if (predicate(value, key, this)) result.set(key, value);
2903
+ }
2904
+ return result;
2905
+ }
2906
+ reduce(fn, init) {
2907
+ let iterator = this.entries();
2908
+ let first = iterator.next();
2909
+ if (first.done) {
2910
+ if (arguments.length < 2) {
2911
+ throw new TypeError("Reduce of empty Map1 with no initial value!");
2912
+ }
2913
+ return init;
2914
+ }
2915
+ let acc;
2916
+ let start;
2917
+ if (arguments.length < 2) {
2918
+ acc = first.value[1];
2919
+ start = iterator.next();
2920
+ } else {
2921
+ acc = init;
2922
+ start = first;
2923
+ }
2924
+ for (let current = start; !current.done; current = iterator.next()) {
2925
+ const [key, value] = current.value;
2926
+ acc = fn(acc, value, key);
2927
+ }
2928
+ return acc;
2929
+ }
2930
+ mapEntries(fn) {
2931
+ let result = [];
2932
+ for (const [key, value] of this.map) {
2933
+ result.push(fn(value, key));
2934
+ }
2935
+ return result;
2936
+ }
2937
+ mapValues(fn) {
2938
+ let result = new _UniMap();
2939
+ for (const [key, value] of this.map) {
2940
+ result.set(key, fn(value, key));
2941
+ }
2942
+ return result;
2943
+ }
2944
+ toMap() {
2945
+ return new Map(this.map);
2946
+ }
2947
+ toString() {
2948
+ const entries = [...this.map].map(([k, v]) => `${stringify(k)} => ${stringify(v)}`).join(", ");
2949
+ return entries.length === 0 ? `Map(${this.size}){ }` : `Map(${this.size}){ ${entries} }`;
2950
+ }
2951
+ };
2952
+
2953
+ // src/core/bi-map.ts
2954
+ var BiMap = class _BiMap extends BaseContainer {
2955
+ constructor(entries) {
2956
+ super();
2957
+ __publicField(this, "map1");
2958
+ __publicField(this, "key1Equals", DefaultEqualityFn);
2959
+ __publicField(this, "key2Equals", DefaultEqualityFn);
2960
+ this.map1 = new UniMap(this.key1Equals);
2961
+ if (entries instanceof _BiMap) {
2962
+ for (const [key1, map2] of entries.map1) {
2963
+ const newMap2 = this.map1.set(key1, new UniMap(this.key2Equals));
2964
+ for (const [key2, value] of map2) {
2965
+ newMap2.set(key2, value);
2966
+ }
2967
+ }
2968
+ } else if (entries) {
2969
+ for (const [key1, key2, value] of entries) {
2970
+ this.set(key1, key2, value);
2971
+ }
2972
+ }
2973
+ }
2974
+ has(key1, key2) {
2975
+ return this.map1.get(key1)?.has(key2) ?? false;
2976
+ }
2977
+ set(key1, key2, value) {
2978
+ return this.map1.getOrCreate(key1, () => new UniMap(this.key2Equals)).set(key2, value);
2979
+ }
2980
+ get(key1, key2) {
2981
+ return this.map1.get(key1)?.get(key2);
2761
2982
  }
2762
2983
  getOrDefault(key1, key2, defaultValue) {
2763
2984
  return this.get(key1, key2) ?? defaultValue;
@@ -2832,7 +3053,7 @@ var Map2 = class _Map2 {
2832
3053
  yield* this.entries();
2833
3054
  }
2834
3055
  clone() {
2835
- return new _Map2(this);
3056
+ return new _BiMap(this);
2836
3057
  }
2837
3058
  merge(other, conflictResolver) {
2838
3059
  for (const [key1, key2, value] of other.entries()) {
@@ -2903,7 +3124,7 @@ var Map2 = class _Map2 {
2903
3124
  return result;
2904
3125
  }
2905
3126
  mapValues(fn) {
2906
- let result = new _Map2();
3127
+ let result = new _BiMap();
2907
3128
  for (const [key1, map2] of this.map1) {
2908
3129
  for (const [key2, value] of map2) {
2909
3130
  result.set(key1, key2, fn(value, key1, key2));
@@ -2923,24 +3144,28 @@ var Map2 = class _Map2 {
2923
3144
  toString() {
2924
3145
  const entries = [];
2925
3146
  for (const [key1, map2] of this.map1) {
2926
- const inner = [...map2].map(([key2, v]) => `${formatValue(key2)} => ${formatValue(v)}`).join(", ");
2927
- entries.push(`${formatValue(key1)} => { ${inner} }`);
3147
+ const inner = [...map2].map(([key2, v]) => `${stringify(key2)} => ${stringify(v)}`).join(", ");
3148
+ entries.push(`${stringify(key1)} => { ${inner} }`);
2928
3149
  }
2929
- return `Map2(${this.size}){ ${entries} }`.replaceAll(" ", " ");
3150
+ return entries.length === 0 ? `Map(${this.size}){ }` : `Map(${this.size}){ ${entries} }`;
2930
3151
  }
2931
3152
  };
2932
3153
 
2933
- // src/core/map3.ts
2934
- var Map3 = class _Map3 {
3154
+ // src/core/tri-map.ts
3155
+ var TriMap = class _TriMap extends BaseContainer {
2935
3156
  constructor(entries) {
2936
- __publicField(this, "map1", /* @__PURE__ */ new Map());
2937
- if (entries instanceof _Map3) {
3157
+ super();
3158
+ __publicField(this, "map1");
3159
+ __publicField(this, "key1Equals", DefaultEqualityFn);
3160
+ __publicField(this, "key2Equals", DefaultEqualityFn);
3161
+ __publicField(this, "key3Equals", DefaultEqualityFn);
3162
+ this.map1 = new UniMap(this.key1Equals);
3163
+ if (entries instanceof _TriMap) {
2938
3164
  for (const [key1, map2] of entries.map1) {
2939
- const newMap2 = /* @__PURE__ */ new Map();
3165
+ const newMap2 = this.map1.set(key1, new UniMap(this.key2Equals));
2940
3166
  for (const [key2, map3] of map2) {
2941
- newMap2.set(key2, new Map(map3));
3167
+ newMap2.set(key2, new UniMap(map3, this.key3Equals));
2942
3168
  }
2943
- this.map1.set(key1, newMap2);
2944
3169
  }
2945
3170
  } else if (entries) {
2946
3171
  for (const [key1, key2, key3, value] of entries) {
@@ -2952,10 +3177,8 @@ var Map3 = class _Map3 {
2952
3177
  return this.map1.get(key1)?.get(key2)?.has(key3) ?? false;
2953
3178
  }
2954
3179
  set(key1, key2, key3, value) {
2955
- let map2 = this.map1.get(key1);
2956
- if (!map2) this.map1.set(key1, map2 = /* @__PURE__ */ new Map());
2957
- let map3 = map2.get(key2);
2958
- if (!map3) map2.set(key2, map3 = /* @__PURE__ */ new Map());
3180
+ let map2 = this.map1.getOrCreate(key1, () => new UniMap(this.key2Equals));
3181
+ let map3 = map2.getOrCreate(key2, () => new UniMap(this.key3Equals));
2959
3182
  map3.set(key3, value);
2960
3183
  return value;
2961
3184
  }
@@ -3047,7 +3270,7 @@ var Map3 = class _Map3 {
3047
3270
  yield* this.entries();
3048
3271
  }
3049
3272
  clone() {
3050
- return new _Map3(this);
3273
+ return new _TriMap(this);
3051
3274
  }
3052
3275
  merge(other, conflictResolver) {
3053
3276
  for (const [key1, key2, key3, value] of other.entries()) {
@@ -3126,7 +3349,7 @@ var Map3 = class _Map3 {
3126
3349
  return result;
3127
3350
  }
3128
3351
  mapValues(fn) {
3129
- let result = new _Map3();
3352
+ let result = new _TriMap();
3130
3353
  for (const [key1, map2] of this.map1) {
3131
3354
  for (const [key2, map3] of map2) {
3132
3355
  for (const [key3, value] of map3) {
@@ -3151,17 +3374,199 @@ var Map3 = class _Map3 {
3151
3374
  const entries = [];
3152
3375
  for (const [key1, map2] of this.map1) {
3153
3376
  for (const [key2, map3] of map2) {
3154
- const inner = [...map3].map(([key3, v]) => `${formatValue(key3)} => ${formatValue(v)}`).join(", ");
3155
- entries.push(`${formatValue(key1)} => ${formatValue(key2)} => { ${inner} }`);
3377
+ const inner = [...map3].map(([key3, v]) => `${stringify(key3)} => ${stringify(v)}`).join(", ");
3378
+ entries.push(`${stringify(key1)} => ${stringify(key2)} => { ${inner} }`);
3379
+ }
3380
+ }
3381
+ return entries.length === 0 ? `Map(${this.size}){ }` : `Map(${this.size}){ ${entries.join(", ")} }`;
3382
+ }
3383
+ };
3384
+
3385
+ // src/core/set.ts
3386
+ var ValueSet = class _ValueSet extends BaseContainer {
3387
+ constructor(...args) {
3388
+ super();
3389
+ __publicField(this, "data");
3390
+ __publicField(this, "equals");
3391
+ const maybeEquals = args.at(-1);
3392
+ this.equals = isFunction2(maybeEquals) ? args.pop() : DefaultEqualityFn;
3393
+ const entries = args[0];
3394
+ this.data = new Set(entries);
3395
+ }
3396
+ static createDeep(arg) {
3397
+ return arg ? new _ValueSet(arg, isDeepEqual2) : new _ValueSet(isDeepEqual2);
3398
+ }
3399
+ has(value) {
3400
+ if (this.equals === DefaultEqualityFn)
3401
+ return this.data.has(value);
3402
+ return this.some((v) => this.equals(v, value));
3403
+ }
3404
+ add(value) {
3405
+ if (!this.has(value))
3406
+ this.data.add(value);
3407
+ return value;
3408
+ }
3409
+ /** @internal - This method exists only for interface `KVComponent` compatibility.*/
3410
+ set(key, value) {
3411
+ if (!this.equals(key, value))
3412
+ throw new TypeError("ValueSet.set() requires key === value.");
3413
+ this.add(value);
3414
+ }
3415
+ /** @internal - This method exists only for interface `KVComponent` compatibility.*/
3416
+ get(key) {
3417
+ return this.has(key) ? key : void 0;
3418
+ }
3419
+ /** @internal - This method exists only for interface `KVComponent` compatibility.*/
3420
+ getOrDefault(key, defaultValue) {
3421
+ return this.get(key) ?? defaultValue;
3422
+ }
3423
+ getOrCreate(key, creatorOrValue) {
3424
+ if (!this.has(key)) {
3425
+ const value = isFunction2(creatorOrValue) ? creatorOrValue() : creatorOrValue;
3426
+ this.set(key, value);
3427
+ return value;
3428
+ }
3429
+ return this.get(key);
3430
+ }
3431
+ delete(value) {
3432
+ if (this.equals === DefaultEqualityFn || this.data.has(value))
3433
+ return this.data.delete(value);
3434
+ for (const v of this.values()) {
3435
+ if (this.equals(v, value)) {
3436
+ this.data.delete(v);
3437
+ return true;
3438
+ }
3439
+ }
3440
+ return false;
3441
+ }
3442
+ clear() {
3443
+ this.data.clear();
3444
+ }
3445
+ get size() {
3446
+ return this.data.size;
3447
+ }
3448
+ isEmpty() {
3449
+ return this.size === 0;
3450
+ }
3451
+ forEach(callbackfn, thisArg) {
3452
+ this.data.forEach((value) => callbackfn.call(thisArg, value, this));
3453
+ }
3454
+ *keys() {
3455
+ yield* this.data.keys();
3456
+ }
3457
+ *values() {
3458
+ yield* this.data.values();
3459
+ }
3460
+ *entries() {
3461
+ yield* this.data.entries();
3462
+ }
3463
+ *kvKeys() {
3464
+ for (const key of this.keys()) {
3465
+ yield [key];
3466
+ }
3467
+ }
3468
+ *kvValues() {
3469
+ for (const el of this.values()) {
3470
+ yield el;
3471
+ }
3472
+ }
3473
+ *kvEntries() {
3474
+ for (const [key, el] of this.entries()) {
3475
+ yield [[key], el];
3476
+ }
3477
+ }
3478
+ *[Symbol.iterator]() {
3479
+ yield* this.values();
3480
+ }
3481
+ clone() {
3482
+ const result = new _ValueSet();
3483
+ for (const v of this.values()) result.add(v);
3484
+ return result;
3485
+ }
3486
+ merge(other) {
3487
+ for (const value of other.values()) {
3488
+ this.add(value);
3489
+ }
3490
+ return this;
3491
+ }
3492
+ some(fn) {
3493
+ for (const value of this.data) {
3494
+ if (fn(value)) return true;
3495
+ }
3496
+ return false;
3497
+ }
3498
+ every(fn) {
3499
+ for (const value of this.data) {
3500
+ if (!fn(value)) return false;
3501
+ }
3502
+ return true;
3503
+ }
3504
+ filter(predicate) {
3505
+ const result = new _ValueSet();
3506
+ for (const value of this.data)
3507
+ if (predicate(value, this)) result.add(value);
3508
+ return result;
3509
+ }
3510
+ reduce(fn, init) {
3511
+ let iterator = this.values();
3512
+ let first = iterator.next();
3513
+ if (first.done) {
3514
+ if (arguments.length < 2) {
3515
+ throw new TypeError("Reduce of empty ValueSet with no initial value!");
3156
3516
  }
3517
+ return init;
3518
+ }
3519
+ let acc;
3520
+ let start;
3521
+ if (arguments.length < 2) {
3522
+ acc = first.value;
3523
+ start = iterator.next();
3524
+ } else {
3525
+ acc = init;
3526
+ start = first;
3527
+ }
3528
+ for (let current = start; !current.done; current = iterator.next()) {
3529
+ const value = current.value;
3530
+ acc = fn(acc, value);
3531
+ }
3532
+ return acc;
3533
+ }
3534
+ mapValues(fn) {
3535
+ let result = new _ValueSet();
3536
+ for (const value of this.data) {
3537
+ result.add(fn(value));
3538
+ }
3539
+ return result;
3540
+ }
3541
+ mapToArray(fn) {
3542
+ let result = [];
3543
+ for (const value of this.values()) {
3544
+ result.push(fn(value));
3157
3545
  }
3158
- return `Map3(${this.size}){ ${entries.join(", ")} }`.replaceAll(" ", " ");
3546
+ return result;
3547
+ }
3548
+ map(fn) {
3549
+ let result = new _ValueSet();
3550
+ for (const value of this.values()) {
3551
+ result.add(fn(value));
3552
+ }
3553
+ return result;
3554
+ }
3555
+ toSet() {
3556
+ return new Set(this.data);
3557
+ }
3558
+ toArray() {
3559
+ return [...this.values()];
3560
+ }
3561
+ toString() {
3562
+ return stringify(this.data);
3159
3563
  }
3160
3564
  };
3161
3565
 
3162
3566
  // src/core/multi-container.ts
3163
- var MultiContainer = class {
3567
+ var MultiContainer = class extends BaseContainer {
3164
3568
  constructor(base) {
3569
+ super();
3165
3570
  this.base = base;
3166
3571
  }
3167
3572
  isEmpty() {
@@ -3217,21 +3622,386 @@ var MultiContainer = class {
3217
3622
  const entries = [];
3218
3623
  for (const keys of this.keys()) {
3219
3624
  const arr = this.getAll(...keys);
3220
- const keyStr = Array.isArray(keys) ? formatValue(keys) : "[ ]";
3221
- const valuesStr = Array.isArray(arr) ? formatValue(arr) : "[ ]";
3625
+ const keyStr = Array.isArray(keys) ? stringify(keys) : "[ ]";
3626
+ const valuesStr = Array.isArray(arr) ? stringify(arr) : "[ ]";
3222
3627
  entries.push(`${keyStr} => ${valuesStr}`);
3223
3628
  }
3224
- return `MultiContainer{ ${entries.join(", ")} }`.replaceAll(" ", " ");
3629
+ return entries.length === 0 ? `MultiContainer{ }` : `MultiContainer{ ${entries.join(", ")} }`;
3225
3630
  }
3226
3631
  };
3227
3632
  function asMulti(base) {
3228
3633
  return new MultiContainer(base);
3229
3634
  }
3230
3635
 
3231
- // src/deprecated/vec2.ts
3232
- var Vec2 = class _Vec2 {
3233
- constructor(x, y) {
3234
- __publicField(this, "x");
3636
+ // src/core/linked-list.ts
3637
+ var LinkedListNode = class {
3638
+ constructor(value) {
3639
+ this.value = value;
3640
+ __publicField(this, "next", null);
3641
+ __publicField(this, "prev", null);
3642
+ }
3643
+ };
3644
+ var LinkedList = class _LinkedList extends BaseContainer {
3645
+ constructor(...args) {
3646
+ super();
3647
+ __publicField(this, "_head", null);
3648
+ __publicField(this, "_tail", null);
3649
+ __publicField(this, "_size", 0);
3650
+ __publicField(this, "equals");
3651
+ const maybeEquals = args.at(-1);
3652
+ this.equals = isFunction2(maybeEquals) ? args.pop() : DefaultEqualityFn;
3653
+ const entries = args[0];
3654
+ if (entries) {
3655
+ for (const v of entries) {
3656
+ this.push(v);
3657
+ }
3658
+ }
3659
+ }
3660
+ static createDeep(entries) {
3661
+ if (entries) {
3662
+ return new _LinkedList(entries, isDeepEqual2);
3663
+ } else {
3664
+ return new _LinkedList(isDeepEqual2);
3665
+ }
3666
+ }
3667
+ get length() {
3668
+ return this._size;
3669
+ }
3670
+ get first() {
3671
+ return this._head?.value;
3672
+ }
3673
+ get last() {
3674
+ return this._tail?.value;
3675
+ }
3676
+ /** Add item to the end of the list */
3677
+ push(value) {
3678
+ const node = new LinkedListNode(value);
3679
+ if (!this._tail) {
3680
+ this._head = this._tail = node;
3681
+ } else {
3682
+ node.prev = this._tail;
3683
+ this._tail.next = node;
3684
+ this._tail = node;
3685
+ }
3686
+ this._size++;
3687
+ }
3688
+ /** Remove item from the end of the list */
3689
+ pop() {
3690
+ if (!this._tail) return void 0;
3691
+ const value = this._tail.value;
3692
+ this._tail = this._tail.prev;
3693
+ if (this._tail) this._tail.next = null;
3694
+ else this._head = null;
3695
+ this._size--;
3696
+ return value;
3697
+ }
3698
+ /** Add item to the beginning of the list */
3699
+ unshift(value) {
3700
+ const node = new LinkedListNode(value);
3701
+ if (!this._head) {
3702
+ this._head = this._tail = node;
3703
+ } else {
3704
+ node.next = this._head;
3705
+ this._head.prev = node;
3706
+ this._head = node;
3707
+ }
3708
+ this._size++;
3709
+ }
3710
+ /** Remove item from the beginning of the list */
3711
+ shift() {
3712
+ if (!this._head) return void 0;
3713
+ const value = this._head.value;
3714
+ this._head = this._head.next;
3715
+ if (this._head) this._head.prev = null;
3716
+ else this._tail = null;
3717
+ this._size--;
3718
+ return value;
3719
+ }
3720
+ /** Check if value exists in the list */
3721
+ has(value) {
3722
+ for (let node = this._head; node; node = node.next) {
3723
+ if (this.equals(node.value, value)) return true;
3724
+ }
3725
+ return false;
3726
+ }
3727
+ /** Get value at index (O(n/2)) */
3728
+ get(index) {
3729
+ return this.nodeAt(index)?.value;
3730
+ }
3731
+ /** Set value at index (O(n/2)) */
3732
+ set(index, value) {
3733
+ const node = this.nodeAt(index);
3734
+ if (!node) return false;
3735
+ node.value = value;
3736
+ return true;
3737
+ }
3738
+ /** Insert value at index (O(n/2)) */
3739
+ insertAt(index, value) {
3740
+ if (index < 0 || index > this._size) return false;
3741
+ if (index === 0) {
3742
+ this.unshift(value);
3743
+ return true;
3744
+ }
3745
+ if (index === this._size) {
3746
+ this.push(value);
3747
+ return true;
3748
+ }
3749
+ const nextNode = this.nodeAt(index);
3750
+ if (!nextNode) return false;
3751
+ const prevNode = nextNode.prev;
3752
+ const newNode = new LinkedListNode(value);
3753
+ newNode.next = nextNode;
3754
+ newNode.prev = prevNode;
3755
+ if (prevNode) prevNode.next = newNode;
3756
+ nextNode.prev = newNode;
3757
+ this._size++;
3758
+ return true;
3759
+ }
3760
+ /** Remove value at index (O(n/2)) */
3761
+ removeAt(index) {
3762
+ const node = this.nodeAt(index);
3763
+ if (!node) return void 0;
3764
+ if (node.prev) node.prev.next = node.next;
3765
+ else this._head = node.next;
3766
+ if (node.next) node.next.prev = node.prev;
3767
+ else this._tail = node.prev;
3768
+ this._size--;
3769
+ return node.value;
3770
+ }
3771
+ /** Remove first matching value (O(n)) */
3772
+ remove(value) {
3773
+ for (let node = this._head; node; node = node.next) {
3774
+ if (this.equals(node.value, value)) {
3775
+ if (node.prev) node.prev.next = node.next;
3776
+ else this._head = node.next;
3777
+ if (node.next) node.next.prev = node.prev;
3778
+ else this._tail = node.prev;
3779
+ this._size--;
3780
+ return true;
3781
+ }
3782
+ }
3783
+ return false;
3784
+ }
3785
+ /** Convert to array */
3786
+ toArray() {
3787
+ const result = [];
3788
+ for (const v of this) result.push(v);
3789
+ return result;
3790
+ }
3791
+ /** Replace contents from array */
3792
+ fromArray(values) {
3793
+ this.clear();
3794
+ for (const v of values) this.push(v);
3795
+ }
3796
+ /** Clear all nodes */
3797
+ clear() {
3798
+ this._head = this._tail = null;
3799
+ this._size = 0;
3800
+ }
3801
+ /** Iterator support */
3802
+ *[Symbol.iterator]() {
3803
+ yield* this.values();
3804
+ }
3805
+ *keys() {
3806
+ for (let id = 0; id < this._size; id++)
3807
+ yield id;
3808
+ }
3809
+ *values() {
3810
+ let node = this._head;
3811
+ while (node) {
3812
+ yield node.value;
3813
+ node = node.next;
3814
+ }
3815
+ }
3816
+ *entries() {
3817
+ let node = this._head;
3818
+ let id = 0;
3819
+ while (node) {
3820
+ yield [id++, node.value];
3821
+ node = node.next;
3822
+ }
3823
+ }
3824
+ toString() {
3825
+ return this._size === 0 ? `LinkedList(0)[ ]` : `LinkedList(${this._size})[ ${this.toArray().join(", ")} ]`;
3826
+ }
3827
+ // ---- Private helpers ----
3828
+ nodeAt(index) {
3829
+ if (index < 0 || index >= this._size) return null;
3830
+ let node;
3831
+ if (index < this._size / 2) {
3832
+ node = this._head;
3833
+ for (let i = 0; i < index; i++) node = node.next;
3834
+ } else {
3835
+ node = this._tail;
3836
+ for (let i = this._size - 1; i > index; i--) node = node.prev;
3837
+ }
3838
+ return node;
3839
+ }
3840
+ clone() {
3841
+ return new _LinkedList(this);
3842
+ }
3843
+ };
3844
+
3845
+ // src/utils/str/index.ts
3846
+ function toCharArray(str2) {
3847
+ return str2.split("");
3848
+ }
3849
+ function repeatString(repeatString2, repeatCount) {
3850
+ if (!isInteger2(repeatCount) || repeatCount < 0) {
3851
+ throw new Error("repeatStr: Invalid repeatCount = " + repeatCount);
3852
+ }
3853
+ return new Array(repeatCount + 1).join(repeatString2);
3854
+ }
3855
+ function chunkString(str2, chunkSize) {
3856
+ if (!isInteger2(chunkSize) || chunkSize < 1) {
3857
+ throw new Error("chunckString: Invalid chuckSize = " + chunkSize);
3858
+ }
3859
+ let result = [];
3860
+ for (let i = 0; i < str2.length; i += chunkSize) {
3861
+ result.push(str2.slice(i, i + chunkSize));
3862
+ }
3863
+ return result;
3864
+ }
3865
+ function replaceAt(str2, pos, removeCount, insert) {
3866
+ if (!isInteger2(removeCount) || removeCount < 0) {
3867
+ throw new Error("replaceAt: Invalid removeCount = " + removeCount);
3868
+ } else if (!isInteger2(pos) || pos < 0 || pos + removeCount > str2.length) {
3869
+ throw new Error("replaceAt: Invalid pos = " + pos + ", removeCount = " + removeCount + ", str.length = " + str2.length);
3870
+ } else {
3871
+ return str2.substring(0, pos) + insert + str2.substring(pos + removeCount);
3872
+ }
3873
+ }
3874
+ function insertAt(str2, pos, insertStr) {
3875
+ return replaceAt(str2, pos, 0, insertStr);
3876
+ }
3877
+ function removeAt(str2, pos, removeCount) {
3878
+ return replaceAt(str2, pos, removeCount, "");
3879
+ }
3880
+ function charCount(str2, ch) {
3881
+ if (ch.length !== 1 || str2.length === 0) return 0;
3882
+ let count = 0;
3883
+ for (let i = 0; i < str2.length; i++) {
3884
+ if (str2[i] === ch) count++;
3885
+ }
3886
+ return count;
3887
+ }
3888
+ function makeSentenceFromPascal(PascalString) {
3889
+ if (PascalString === "") {
3890
+ return "";
3891
+ }
3892
+ let word = PascalString.charAt(0);
3893
+ let sentence = "";
3894
+ const addWord = () => {
3895
+ if (word !== "") {
3896
+ if (sentence === "") {
3897
+ sentence += word.charAt(0).toUpperCase() + word.substring(1);
3898
+ } else {
3899
+ sentence += " " + word;
3900
+ }
3901
+ word = "";
3902
+ }
3903
+ };
3904
+ const isLetterAndCapital = (c) => {
3905
+ return c.toUpperCase() !== c.toLowerCase() && c === c.toUpperCase();
3906
+ };
3907
+ for (let i = 1; i < PascalString.length; i++) {
3908
+ let c = PascalString.charAt(i);
3909
+ if (isLetterAndCapital(c)) {
3910
+ addWord();
3911
+ }
3912
+ word += c.toLowerCase();
3913
+ }
3914
+ addWord();
3915
+ return sentence;
3916
+ }
3917
+ function stringify(value, maxDepth = 5, seen = /* @__PURE__ */ new WeakSet()) {
3918
+ if (value === null) return "null";
3919
+ if (value === void 0) return "undefined";
3920
+ const t = typeof value;
3921
+ switch (t) {
3922
+ case "boolean":
3923
+ return value ? "true" : "false";
3924
+ case "number":
3925
+ if (isNaNValue2(value)) return "NaN";
3926
+ if (!isFinite3(value))
3927
+ return value < 0 ? "-Infinity" : "Infinity";
3928
+ return value.toString();
3929
+ case "bigint":
3930
+ return `${value}n`;
3931
+ case "string":
3932
+ return `"${value}"`;
3933
+ case "symbol":
3934
+ return value.description ? `Symbol(${value.description})` : "Symbol()";
3935
+ case "function":
3936
+ return `[Function${value.name ? ` ${value.name}` : ""}]`;
3937
+ }
3938
+ if (seen.has(value))
3939
+ return "[Circular]";
3940
+ if (maxDepth <= 0)
3941
+ return "[Depth limit]";
3942
+ maxDepth--;
3943
+ seen.add(value);
3944
+ const strfy = (v) => stringify(v, maxDepth, seen);
3945
+ if (isArray2(value)) {
3946
+ const inner = value.map((v) => strfy(v)).join(", ");
3947
+ return inner.length === 0 ? "[ ]" : `[ ${inner} ]`;
3948
+ }
3949
+ if (ArrayBuffer.isView(value)) {
3950
+ if (value instanceof DataView)
3951
+ return `DataView(${value.byteLength})`;
3952
+ const inner = Array.from(value).map((v) => strfy(v)).join(", ");
3953
+ return `${value.constructor.name}[ ${inner} ]`;
3954
+ }
3955
+ if (value instanceof ArrayBuffer)
3956
+ return `ArrayBuffer(${value.byteLength})`;
3957
+ if (value instanceof Map) {
3958
+ const entries = Array.from(value.entries()).map(([k, v]) => `${strfy(k)} => ${strfy(v)}`).join(", ");
3959
+ return entries.length === 0 ? `Map(${value.size}){ }` : `Map(${value.size}){ ${entries} }`;
3960
+ }
3961
+ if (value instanceof Set) {
3962
+ const entries = Array.from(value.values()).map((v) => strfy(v)).join(", ");
3963
+ return entries.length === 0 ? `Set(${value.size}){ }` : `Set(${value.size}){ ${entries} }`;
3964
+ }
3965
+ if (value instanceof WeakMap)
3966
+ return "WeakMap{ ? }";
3967
+ if (value instanceof WeakSet)
3968
+ return "WeakSet{ ? }";
3969
+ if (typeof BaseContainer !== "undefined" && value instanceof BaseContainer)
3970
+ return value.toString();
3971
+ if (value instanceof Date)
3972
+ return `Date("${value.toISOString()}")`;
3973
+ if (value instanceof RegExp)
3974
+ return value.toString();
3975
+ if (value instanceof Error)
3976
+ return `${value.name}("${value.message}")`;
3977
+ if (value instanceof Promise)
3978
+ return "Promise{ ? }";
3979
+ if (value instanceof URL)
3980
+ return `URL("${value.href}")`;
3981
+ if (value instanceof URLSearchParams)
3982
+ return `URLSearchParams("${value.toString()}")`;
3983
+ if (value === Math) return "Math";
3984
+ if (value === JSON) return "JSON";
3985
+ if (value === Reflect) return "Reflect";
3986
+ if (value === Intl) return "Intl";
3987
+ if (t === "object") {
3988
+ const ctorName = value.constructor?.name ?? "Object";
3989
+ const entries = Object.entries(value).map(
3990
+ ([key, val]) => `${strfy(key)}: ${strfy(val)}`
3991
+ );
3992
+ if (entries.length === 0) return `${ctorName}{ }`;
3993
+ return `${ctorName}{ ${entries.join(", ")} }`;
3994
+ }
3995
+ return String(value);
3996
+ }
3997
+
3998
+ // src/utils/index.ts
3999
+ var Is = guard_exports;
4000
+
4001
+ // src/deprecated/vec2.ts
4002
+ var Vec2 = class _Vec2 {
4003
+ constructor(x, y) {
4004
+ __publicField(this, "x");
3235
4005
  __publicField(this, "y");
3236
4006
  this.x = x ?? 0;
3237
4007
  this.y = y ?? 0;
@@ -3304,22 +4074,812 @@ var SmallIntCache = class {
3304
4074
  this.neg = [];
3305
4075
  }
3306
4076
  };
4077
+
4078
+ // src/deprecated/map1.ts
4079
+ var Map1 = class _Map1 extends BaseContainer {
4080
+ constructor(entries) {
4081
+ super();
4082
+ __publicField(this, "map1");
4083
+ this.map1 = entries instanceof _Map1 ? new Map(entries.map1) : new Map(entries);
4084
+ }
4085
+ has(key1) {
4086
+ return this.map1.has(key1);
4087
+ }
4088
+ set(key1, value) {
4089
+ this.map1.set(key1, value);
4090
+ return value;
4091
+ }
4092
+ get(key1) {
4093
+ return this.map1.get(key1);
4094
+ }
4095
+ getOrDefault(key1, defaultValue) {
4096
+ return this.get(key1) ?? defaultValue;
4097
+ }
4098
+ getOrCreate(key1, creatorOrValue) {
4099
+ if (!this.has(key1)) {
4100
+ const value = isFunction2(creatorOrValue) ? creatorOrValue() : creatorOrValue;
4101
+ this.set(key1, value);
4102
+ return value;
4103
+ }
4104
+ return this.get(key1);
4105
+ }
4106
+ delete(key1) {
4107
+ return this.map1.delete(key1);
4108
+ }
4109
+ clear() {
4110
+ this.map1.clear();
4111
+ }
4112
+ get size() {
4113
+ return this.map1.size;
4114
+ }
4115
+ isEmpty() {
4116
+ return this.size === 0;
4117
+ }
4118
+ forEach(callbackfn, thisArg) {
4119
+ this.map1.forEach((value, key1) => callbackfn.call(thisArg, value, key1, this));
4120
+ }
4121
+ *keys() {
4122
+ yield* this.map1.keys();
4123
+ }
4124
+ *values() {
4125
+ yield* this.map1.values();
4126
+ }
4127
+ *entries() {
4128
+ for (const [key1, value] of this.map1)
4129
+ yield [key1, value];
4130
+ }
4131
+ keysArray() {
4132
+ return [...this.keys()];
4133
+ }
4134
+ valuesArray() {
4135
+ return [...this.values()];
4136
+ }
4137
+ entriesArray() {
4138
+ return [...this.entries()];
4139
+ }
4140
+ *kvKeys() {
4141
+ for (const key of this.keys()) {
4142
+ yield [key];
4143
+ }
4144
+ }
4145
+ *kvValues() {
4146
+ for (const el of this.values()) {
4147
+ yield el;
4148
+ }
4149
+ }
4150
+ *kvEntries() {
4151
+ for (const [key, el] of this.entries()) {
4152
+ yield [[key], el];
4153
+ }
4154
+ }
4155
+ *[Symbol.iterator]() {
4156
+ yield* this.entries();
4157
+ }
4158
+ clone() {
4159
+ return new _Map1(this);
4160
+ }
4161
+ merge(other, conflictResolver) {
4162
+ for (const [key1, value] of other.entries()) {
4163
+ if (this.has(key1) && conflictResolver) {
4164
+ this.set(key1, conflictResolver(this.get(key1), value, key1));
4165
+ } else {
4166
+ this.set(key1, value);
4167
+ }
4168
+ }
4169
+ return this;
4170
+ }
4171
+ some(fn) {
4172
+ for (const [key1, value] of this.map1) {
4173
+ if (fn(value, key1)) return true;
4174
+ }
4175
+ return false;
4176
+ }
4177
+ every(fn) {
4178
+ for (const [key1, value] of this.map1) {
4179
+ if (!fn(value, key1)) return false;
4180
+ }
4181
+ return true;
4182
+ }
4183
+ filter(predicate) {
4184
+ const result = new this.constructor();
4185
+ for (const [key1, value] of this.map1) {
4186
+ if (predicate(value, key1, this)) result.set(key1, value);
4187
+ }
4188
+ return result;
4189
+ }
4190
+ reduce(fn, init) {
4191
+ let iterator = this.entries();
4192
+ let first = iterator.next();
4193
+ if (first.done) {
4194
+ if (arguments.length < 2) {
4195
+ throw new TypeError("Reduce of empty Map1 with no initial value!");
4196
+ }
4197
+ return init;
4198
+ }
4199
+ let acc;
4200
+ let start;
4201
+ if (arguments.length < 2) {
4202
+ acc = first.value[1];
4203
+ start = iterator.next();
4204
+ } else {
4205
+ acc = init;
4206
+ start = first;
4207
+ }
4208
+ for (let current = start; !current.done; current = iterator.next()) {
4209
+ const [key1, value] = current.value;
4210
+ acc = fn(acc, value, key1);
4211
+ }
4212
+ return acc;
4213
+ }
4214
+ mapEntries(fn) {
4215
+ let result = [];
4216
+ for (const [key1, value] of this.map1) {
4217
+ result.push(fn(value, key1));
4218
+ }
4219
+ return result;
4220
+ }
4221
+ mapValues(fn) {
4222
+ let result = new _Map1();
4223
+ for (const [key1, value] of this.map1) {
4224
+ result.set(key1, fn(value, key1));
4225
+ }
4226
+ return result;
4227
+ }
4228
+ toMap() {
4229
+ return new Map(this.map1);
4230
+ }
4231
+ toString() {
4232
+ const entries = [...this.map1].map(([k, v]) => `${stringify(k)} => ${stringify(v)}`).join(", ");
4233
+ return entries.length === 0 ? `Map(${this.size}){ }` : `Map(${this.size}){ ${entries} }`;
4234
+ }
4235
+ };
4236
+
4237
+ // src/deprecated/map2.ts
4238
+ var Map2 = class _Map2 extends BaseContainer {
4239
+ constructor(entries) {
4240
+ super();
4241
+ __publicField(this, "map1", /* @__PURE__ */ new Map());
4242
+ if (entries instanceof _Map2) {
4243
+ for (const [key1, inner] of entries.map1) {
4244
+ this.map1.set(key1, new Map(inner));
4245
+ }
4246
+ } else if (entries) {
4247
+ for (const [key1, key2, value] of entries) {
4248
+ this.set(key1, key2, value);
4249
+ }
4250
+ }
4251
+ }
4252
+ has(key1, key2) {
4253
+ return this.map1.get(key1)?.has(key2) ?? false;
4254
+ }
4255
+ set(key1, key2, value) {
4256
+ let map2 = this.map1.get(key1) ?? this.map1.set(key1, /* @__PURE__ */ new Map()).get(key1);
4257
+ map2.set(key2, value);
4258
+ return value;
4259
+ }
4260
+ get(key1, key2) {
4261
+ return this.map1.get(key1)?.get(key2);
4262
+ }
4263
+ getOrDefault(key1, key2, defaultValue) {
4264
+ return this.get(key1, key2) ?? defaultValue;
4265
+ }
4266
+ getOrCreate(key1, key2, creatorOrValue) {
4267
+ if (!this.has(key1, key2)) {
4268
+ const value = isFunction2(creatorOrValue) ? creatorOrValue() : creatorOrValue;
4269
+ this.set(key1, key2, value);
4270
+ return value;
4271
+ }
4272
+ return this.get(key1, key2);
4273
+ }
4274
+ delete(key1, key2) {
4275
+ if (key2 === void 0) return this.map1.delete(key1);
4276
+ const map2 = this.map1.get(key1);
4277
+ if (!map2) return false;
4278
+ return map2.delete(key2);
4279
+ }
4280
+ clear() {
4281
+ this.map1.clear();
4282
+ }
4283
+ get size() {
4284
+ let count = 0;
4285
+ for (const map2 of this.map1.values()) {
4286
+ count += map2.size;
4287
+ }
4288
+ return count;
4289
+ }
4290
+ isEmpty() {
4291
+ return this.size === 0;
4292
+ }
4293
+ forEach(callbackfn, thisArg) {
4294
+ this.map1.forEach((map2, key1) => map2.forEach((value, key2) => callbackfn.call(thisArg, value, key1, key2, this)));
4295
+ }
4296
+ *keys() {
4297
+ for (const [key1, map2] of this.map1)
4298
+ for (const key2 of map2.keys())
4299
+ yield [key1, key2];
4300
+ }
4301
+ *values() {
4302
+ for (const map2 of this.map1.values())
4303
+ for (const value of map2.values())
4304
+ yield value;
4305
+ }
4306
+ *entries() {
4307
+ for (const [key1, map2] of this.map1)
4308
+ for (const [key2, value] of map2)
4309
+ yield [key1, key2, value];
4310
+ }
4311
+ keysArray() {
4312
+ return [...this.keys()];
4313
+ }
4314
+ valuesArray() {
4315
+ return [...this.values()];
4316
+ }
4317
+ entriesArray() {
4318
+ return [...this.entries()];
4319
+ }
4320
+ *kvKeys() {
4321
+ for (const [key1, key2] of this.keys())
4322
+ yield [key1, key2];
4323
+ }
4324
+ *kvValues() {
4325
+ for (const el of this.values())
4326
+ yield el;
4327
+ }
4328
+ *kvEntries() {
4329
+ for (const [key1, key2, el] of this.entries())
4330
+ yield [[key1, key2], el];
4331
+ }
4332
+ *[Symbol.iterator]() {
4333
+ yield* this.entries();
4334
+ }
4335
+ clone() {
4336
+ return new _Map2(this);
4337
+ }
4338
+ merge(other, conflictResolver) {
4339
+ for (const [key1, key2, value] of other.entries()) {
4340
+ if (this.has(key1, key2) && conflictResolver) {
4341
+ this.set(key1, key2, conflictResolver(this.get(key1, key2), value, key1, key2));
4342
+ } else {
4343
+ this.set(key1, key2, value);
4344
+ }
4345
+ }
4346
+ return this;
4347
+ }
4348
+ some(fn) {
4349
+ for (const [key1, map2] of this.map1) {
4350
+ for (const [key2, value] of map2) {
4351
+ if (fn(value, key1, key2)) return true;
4352
+ }
4353
+ }
4354
+ return false;
4355
+ }
4356
+ every(fn) {
4357
+ for (const [key1, map2] of this.map1) {
4358
+ for (const [key2, value] of map2) {
4359
+ if (!fn(value, key1, key2)) return false;
4360
+ }
4361
+ }
4362
+ return true;
4363
+ }
4364
+ filter(predicate) {
4365
+ const result = new this.constructor();
4366
+ for (const [key1, map2] of this.map1) {
4367
+ for (const [key2, value] of map2) {
4368
+ if (predicate(value, key1, key2, this)) result.set(key1, key2, value);
4369
+ }
4370
+ }
4371
+ return result;
4372
+ }
4373
+ reduce(fn, init) {
4374
+ let iterator = this.entries();
4375
+ let first = iterator.next();
4376
+ if (first.done) {
4377
+ if (arguments.length < 2) {
4378
+ throw new TypeError("Reduce of empty Map2 with no initial value!");
4379
+ }
4380
+ return init;
4381
+ }
4382
+ let acc;
4383
+ let start;
4384
+ if (arguments.length < 2) {
4385
+ acc = first.value[2];
4386
+ start = iterator.next();
4387
+ } else {
4388
+ acc = init;
4389
+ start = first;
4390
+ }
4391
+ for (let current = start; !current.done; current = iterator.next()) {
4392
+ const [key1, key2, value] = current.value;
4393
+ acc = fn(acc, value, key1, key2);
4394
+ }
4395
+ return acc;
4396
+ }
4397
+ mapEntries(fn) {
4398
+ let result = [];
4399
+ for (const [key1, map2] of this.map1) {
4400
+ for (const [key2, value] of map2) {
4401
+ result.push(fn(value, key1, key2));
4402
+ }
4403
+ }
4404
+ return result;
4405
+ }
4406
+ mapValues(fn) {
4407
+ let result = new _Map2();
4408
+ for (const [key1, map2] of this.map1) {
4409
+ for (const [key2, value] of map2) {
4410
+ result.set(key1, key2, fn(value, key1, key2));
4411
+ }
4412
+ }
4413
+ return result;
4414
+ }
4415
+ toMap() {
4416
+ let result = /* @__PURE__ */ new Map();
4417
+ for (const [key1, map2] of this.map1) {
4418
+ for (const [key2, value] of map2) {
4419
+ result.set([key1, key2], value);
4420
+ }
4421
+ }
4422
+ return result;
4423
+ }
4424
+ toString() {
4425
+ const entries = [];
4426
+ for (const [key1, map2] of this.map1) {
4427
+ const inner = [...map2].map(([key2, v]) => `${stringify(key2)} => ${stringify(v)}`).join(", ");
4428
+ entries.push(`${stringify(key1)} => { ${inner} }`);
4429
+ }
4430
+ return entries.length === 0 ? `Map(${this.size}){ }` : `Map(${this.size}){ ${entries} }`;
4431
+ }
4432
+ };
4433
+
4434
+ // src/deprecated/map3.ts
4435
+ var Map3 = class _Map3 extends BaseContainer {
4436
+ constructor(entries) {
4437
+ super();
4438
+ __publicField(this, "map1", /* @__PURE__ */ new Map());
4439
+ if (entries instanceof _Map3) {
4440
+ for (const [key1, map2] of entries.map1) {
4441
+ const newMap2 = /* @__PURE__ */ new Map();
4442
+ for (const [key2, map3] of map2) {
4443
+ newMap2.set(key2, new Map(map3));
4444
+ }
4445
+ this.map1.set(key1, newMap2);
4446
+ }
4447
+ } else if (entries) {
4448
+ for (const [key1, key2, key3, value] of entries) {
4449
+ this.set(key1, key2, key3, value);
4450
+ }
4451
+ }
4452
+ }
4453
+ has(key1, key2, key3) {
4454
+ return this.map1.get(key1)?.get(key2)?.has(key3) ?? false;
4455
+ }
4456
+ set(key1, key2, key3, value) {
4457
+ let map2 = this.map1.get(key1);
4458
+ if (!map2) this.map1.set(key1, map2 = /* @__PURE__ */ new Map());
4459
+ let map3 = map2.get(key2);
4460
+ if (!map3) map2.set(key2, map3 = /* @__PURE__ */ new Map());
4461
+ map3.set(key3, value);
4462
+ return value;
4463
+ }
4464
+ get(key1, key2, key3) {
4465
+ return this.map1.get(key1)?.get(key2)?.get(key3);
4466
+ }
4467
+ getOrDefault(key1, key2, key3, defaultValue) {
4468
+ return this.get(key1, key2, key3) ?? defaultValue;
4469
+ }
4470
+ getOrCreate(key1, key2, key3, creatorOrValue) {
4471
+ if (!this.has(key1, key2, key3)) {
4472
+ const value = isFunction2(creatorOrValue) ? creatorOrValue() : creatorOrValue;
4473
+ this.set(key1, key2, key3, value);
4474
+ return value;
4475
+ }
4476
+ return this.get(key1, key2, key3);
4477
+ }
4478
+ delete(key1, key2, key3) {
4479
+ if (key3 === void 0) {
4480
+ if (key2 === void 0) return this.map1.delete(key1);
4481
+ const map2 = this.map1.get(key1);
4482
+ if (!map2) return false;
4483
+ return map2.delete(key2);
4484
+ } else {
4485
+ if (key2 === void 0) return this.map1.delete(key1);
4486
+ const map3 = this.map1.get(key1)?.get(key2);
4487
+ if (!map3) return false;
4488
+ return map3.delete(key3);
4489
+ }
4490
+ }
4491
+ clear() {
4492
+ this.map1.clear();
4493
+ }
4494
+ get size() {
4495
+ let count = 0;
4496
+ for (const map2 of this.map1.values()) {
4497
+ for (const map3 of map2.values()) {
4498
+ count += map3.size;
4499
+ }
4500
+ }
4501
+ return count;
4502
+ }
4503
+ isEmpty() {
4504
+ return this.size === 0;
4505
+ }
4506
+ forEach(callbackfn, thisArg) {
4507
+ this.map1.forEach((map2, key1) => map2.forEach((map3, key2) => map3.forEach((value, key3) => callbackfn.call(thisArg, value, key1, key2, key3, this))));
4508
+ }
4509
+ *keys() {
4510
+ for (const [key1, map2] of this.map1)
4511
+ for (const [key2, map3] of map2)
4512
+ for (const key3 of map3.keys())
4513
+ yield [key1, key2, key3];
4514
+ }
4515
+ *values() {
4516
+ for (const map2 of this.map1.values())
4517
+ for (const map3 of map2.values())
4518
+ for (const value of map3.values())
4519
+ yield value;
4520
+ }
4521
+ *entries() {
4522
+ for (const [key1, map2] of this.map1)
4523
+ for (const [key2, map3] of map2)
4524
+ for (const [key3, value] of map3)
4525
+ yield [key1, key2, key3, value];
4526
+ }
4527
+ keysArray() {
4528
+ return [...this.keys()];
4529
+ }
4530
+ valuesArray() {
4531
+ return [...this.values()];
4532
+ }
4533
+ entriesArray() {
4534
+ return [...this.entries()];
4535
+ }
4536
+ *kvKeys() {
4537
+ for (const [key1, key2, key3] of this.keys())
4538
+ yield [key1, key2, key3];
4539
+ }
4540
+ *kvValues() {
4541
+ for (const el of this.values())
4542
+ yield el;
4543
+ }
4544
+ *kvEntries() {
4545
+ for (const [key1, key2, key3, el] of this.entries())
4546
+ yield [[key1, key2, key3], el];
4547
+ }
4548
+ *[Symbol.iterator]() {
4549
+ yield* this.entries();
4550
+ }
4551
+ clone() {
4552
+ return new _Map3(this);
4553
+ }
4554
+ merge(other, conflictResolver) {
4555
+ for (const [key1, key2, key3, value] of other.entries()) {
4556
+ if (this.has(key1, key2, key3) && conflictResolver) {
4557
+ this.set(key1, key2, key3, conflictResolver(this.get(key1, key2, key3), value, key1, key2, key3));
4558
+ } else {
4559
+ this.set(key1, key2, key3, value);
4560
+ }
4561
+ }
4562
+ return this;
4563
+ }
4564
+ some(fn) {
4565
+ for (const [key1, map2] of this.map1) {
4566
+ for (const [key2, map3] of map2) {
4567
+ for (const [key3, value] of map3) {
4568
+ if (fn(value, key1, key2, key3)) return true;
4569
+ }
4570
+ }
4571
+ }
4572
+ return false;
4573
+ }
4574
+ every(fn) {
4575
+ for (const [key1, map2] of this.map1) {
4576
+ for (const [key2, map3] of map2) {
4577
+ for (const [key3, value] of map3) {
4578
+ if (!fn(value, key1, key2, key3)) return false;
4579
+ }
4580
+ }
4581
+ }
4582
+ return true;
4583
+ }
4584
+ filter(predicate) {
4585
+ const result = new this.constructor();
4586
+ for (const [key1, map2] of this.map1) {
4587
+ for (const [key2, map3] of map2) {
4588
+ for (const [key3, value] of map3) {
4589
+ if (predicate(value, key1, key2, key3, this)) result.set(key1, key2, key3, value);
4590
+ }
4591
+ }
4592
+ }
4593
+ return result;
4594
+ }
4595
+ reduce(fn, init) {
4596
+ let iterator = this.entries();
4597
+ let first = iterator.next();
4598
+ if (first.done) {
4599
+ if (arguments.length < 2) {
4600
+ throw new TypeError("Reduce of empty Map3 with no initial value!");
4601
+ }
4602
+ return init;
4603
+ }
4604
+ let acc;
4605
+ let start;
4606
+ if (arguments.length < 2) {
4607
+ acc = first.value[3];
4608
+ start = iterator.next();
4609
+ } else {
4610
+ acc = init;
4611
+ start = first;
4612
+ }
4613
+ for (let current = start; !current.done; current = iterator.next()) {
4614
+ const [key1, key2, key3, value] = current.value;
4615
+ acc = fn(acc, value, key1, key2, key3);
4616
+ }
4617
+ return acc;
4618
+ }
4619
+ mapEntries(fn) {
4620
+ let result = [];
4621
+ for (const [key1, map2] of this.map1) {
4622
+ for (const [key2, map3] of map2) {
4623
+ for (const [key3, value] of map3) {
4624
+ result.push(fn(value, key1, key2, key3));
4625
+ }
4626
+ }
4627
+ }
4628
+ return result;
4629
+ }
4630
+ mapValues(fn) {
4631
+ let result = new _Map3();
4632
+ for (const [key1, map2] of this.map1) {
4633
+ for (const [key2, map3] of map2) {
4634
+ for (const [key3, value] of map3) {
4635
+ result.set(key1, key2, key3, fn(value, key1, key2, key3));
4636
+ }
4637
+ }
4638
+ }
4639
+ return result;
4640
+ }
4641
+ toMap() {
4642
+ let result = /* @__PURE__ */ new Map();
4643
+ for (const [key1, map2] of this.map1) {
4644
+ for (const [key2, map3] of map2) {
4645
+ for (const [key3, value] of map3) {
4646
+ result.set([key1, key2, key3], value);
4647
+ }
4648
+ }
4649
+ }
4650
+ return result;
4651
+ }
4652
+ toString() {
4653
+ const entries = [];
4654
+ for (const [key1, map2] of this.map1) {
4655
+ for (const [key2, map3] of map2) {
4656
+ const inner = [...map3].map(([key3, v]) => `${stringify(key3)} => ${stringify(v)}`).join(", ");
4657
+ entries.push(`${stringify(key1)} => ${stringify(key2)} => { ${inner} }`);
4658
+ }
4659
+ }
4660
+ return entries.length === 0 ? `Map(${this.size}){ }` : `Map(${this.size}){ ${entries.join(", ")} }`;
4661
+ }
4662
+ };
4663
+
4664
+ // src/deprecated/set.ts
4665
+ var SetBase = class extends BaseContainer {
4666
+ constructor(entries) {
4667
+ super();
4668
+ __publicField(this, "data");
4669
+ this.data = new Set(entries ?? []);
4670
+ }
4671
+ has(value) {
4672
+ return this.some((v) => this.valueEquals(v, value));
4673
+ }
4674
+ add(value) {
4675
+ if (!this.has(value))
4676
+ this.data.add(value);
4677
+ return value;
4678
+ }
4679
+ /** @internal - This method exists only for interface `KVComponent` compatibility.*/
4680
+ set(key, value) {
4681
+ if (!this.valueEquals(key, value))
4682
+ throw new TypeError("SetBase.set() requires key === value.");
4683
+ this.add(value);
4684
+ }
4685
+ /** @internal - This method exists only for interface `KVComponent` compatibility.*/
4686
+ get(key) {
4687
+ return this.has(key) ? key : void 0;
4688
+ }
4689
+ /** @internal - This method exists only for interface `KVComponent` compatibility.*/
4690
+ getOrDefault(key, defaultValue) {
4691
+ return this.get(key) ?? defaultValue;
4692
+ }
4693
+ getOrCreate(key, creatorOrValue) {
4694
+ if (!this.has(key)) {
4695
+ const value = isFunction2(creatorOrValue) ? creatorOrValue() : creatorOrValue;
4696
+ this.set(key, value);
4697
+ return value;
4698
+ }
4699
+ return this.get(key);
4700
+ }
4701
+ delete(value) {
4702
+ if (!this.has(value)) return false;
4703
+ for (const v of this.values()) {
4704
+ if (this.valueEquals(v, value)) {
4705
+ this.data.delete(v);
4706
+ return true;
4707
+ }
4708
+ }
4709
+ return false;
4710
+ }
4711
+ clear() {
4712
+ this.data.clear();
4713
+ }
4714
+ get size() {
4715
+ return this.data.size;
4716
+ }
4717
+ isEmpty() {
4718
+ return this.size === 0;
4719
+ }
4720
+ forEach(callbackfn, thisArg) {
4721
+ this.data.forEach((value) => callbackfn.call(thisArg, value, this));
4722
+ }
4723
+ *keys() {
4724
+ yield* this.data.keys();
4725
+ }
4726
+ *values() {
4727
+ yield* this.data.values();
4728
+ }
4729
+ *entries() {
4730
+ yield* this.data.entries();
4731
+ }
4732
+ *kvKeys() {
4733
+ for (const key of this.keys()) {
4734
+ yield [key];
4735
+ }
4736
+ }
4737
+ *kvValues() {
4738
+ for (const el of this.values()) {
4739
+ yield el;
4740
+ }
4741
+ }
4742
+ *kvEntries() {
4743
+ for (const [key, el] of this.entries()) {
4744
+ yield [[key], el];
4745
+ }
4746
+ }
4747
+ *[Symbol.iterator]() {
4748
+ yield* this.values();
4749
+ }
4750
+ clone() {
4751
+ const result = this.createEmpty();
4752
+ for (const v of this.values()) result.add(v);
4753
+ return result;
4754
+ }
4755
+ merge(other) {
4756
+ for (const value of other.values()) {
4757
+ this.add(value);
4758
+ }
4759
+ return this;
4760
+ }
4761
+ some(fn) {
4762
+ for (const value of this.data) {
4763
+ if (fn(value)) return true;
4764
+ }
4765
+ return false;
4766
+ }
4767
+ every(fn) {
4768
+ for (const value of this.data) {
4769
+ if (!fn(value)) return false;
4770
+ }
4771
+ return true;
4772
+ }
4773
+ filter(predicate) {
4774
+ const result = this.createEmpty();
4775
+ for (const value of this.data)
4776
+ if (predicate(value, this)) result.add(value);
4777
+ return result;
4778
+ }
4779
+ reduce(fn, init) {
4780
+ let iterator = this.values();
4781
+ let first = iterator.next();
4782
+ if (first.done) {
4783
+ if (arguments.length < 2) {
4784
+ throw new TypeError("Reduce of empty SetBase with no initial value!");
4785
+ }
4786
+ return init;
4787
+ }
4788
+ let acc;
4789
+ let start;
4790
+ if (arguments.length < 2) {
4791
+ acc = first.value;
4792
+ start = iterator.next();
4793
+ } else {
4794
+ acc = init;
4795
+ start = first;
4796
+ }
4797
+ for (let current = start; !current.done; current = iterator.next()) {
4798
+ const value = current.value;
4799
+ acc = fn(acc, value);
4800
+ }
4801
+ return acc;
4802
+ }
4803
+ mapValues(fn) {
4804
+ let result = this.createEmpty();
4805
+ for (const value of this.data) {
4806
+ result.add(fn(value));
4807
+ }
4808
+ return result;
4809
+ }
4810
+ mapToArray(fn) {
4811
+ let result = [];
4812
+ for (const value of this.values()) {
4813
+ result.push(fn(value));
4814
+ }
4815
+ return result;
4816
+ }
4817
+ map(fn) {
4818
+ let result = this.createEmpty();
4819
+ for (const value of this.values()) {
4820
+ result.add(fn(value));
4821
+ }
4822
+ return result;
4823
+ }
4824
+ toSet() {
4825
+ return new Set(this.data);
4826
+ }
4827
+ toArray() {
4828
+ return [...this.values()];
4829
+ }
4830
+ toString() {
4831
+ return stringify(this.data);
4832
+ }
4833
+ };
4834
+ var Set1 = class _Set1 extends SetBase {
4835
+ constructor(entries) {
4836
+ super(entries);
4837
+ }
4838
+ createEmpty() {
4839
+ return new _Set1();
4840
+ }
4841
+ valueEquals(a, b) {
4842
+ return a === b;
4843
+ }
4844
+ };
4845
+ var DeepSet = class _DeepSet extends SetBase {
4846
+ constructor(entries) {
4847
+ super(entries);
4848
+ }
4849
+ createEmpty() {
4850
+ return new _DeepSet();
4851
+ }
4852
+ valueEquals(a, b) {
4853
+ return isDeepEqual2(a, b);
4854
+ }
4855
+ };
3307
4856
  export {
3308
4857
  assert_exports as Assert,
4858
+ BaseContainer,
4859
+ BiMap,
3309
4860
  cookies_exports as Cookies,
4861
+ DeepSet,
4862
+ DefaultArray,
4863
+ DefaultEqualityFn,
3310
4864
  device_exports as Device,
3311
4865
  DivRect,
3312
4866
  guard_exports as Guard,
3313
4867
  IndexArray,
3314
4868
  LRUCache,
4869
+ LinkedList,
3315
4870
  Map1,
3316
4871
  Map2,
3317
4872
  Map3,
3318
4873
  MultiContainer,
4874
+ Set1,
4875
+ SetBase,
3319
4876
  SignedIndexArray,
3320
4877
  SmallIntCache,
3321
4878
  Stack,
4879
+ TriMap,
4880
+ UniMap,
3322
4881
  utils_exports as Utils,
4882
+ ValueSet,
3323
4883
  Vec,
3324
4884
  Vec2,
3325
4885
  asMulti