@tspro/ts-utils-lib 1.19.1 → 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.1 | (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,14 +24,18 @@ 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,
28
30
  DeepSet: () => DeepSet,
29
31
  DefaultArray: () => DefaultArray,
32
+ DefaultEqualityFn: () => DefaultEqualityFn,
30
33
  Device: () => device_exports,
31
34
  DivRect: () => DivRect,
32
35
  Guard: () => guard_exports,
33
36
  IndexArray: () => IndexArray,
34
37
  LRUCache: () => LRUCache,
38
+ LinkedList: () => LinkedList,
35
39
  Map1: () => Map1,
36
40
  Map2: () => Map2,
37
41
  Map3: () => Map3,
@@ -41,7 +45,10 @@ __export(index_exports, {
41
45
  SignedIndexArray: () => SignedIndexArray,
42
46
  SmallIntCache: () => SmallIntCache,
43
47
  Stack: () => Stack,
48
+ TriMap: () => TriMap,
49
+ UniMap: () => UniMap,
44
50
  Utils: () => utils_exports,
51
+ ValueSet: () => ValueSet,
45
52
  Vec: () => Vec,
46
53
  Vec2: () => Vec2,
47
54
  asMulti: () => asMulti
@@ -105,6 +112,7 @@ __export(assert_exports, {
105
112
  isNonEmptyArrayOrUndefined: () => isNonEmptyArrayOrUndefined,
106
113
  isNonEmptyString: () => isNonEmptyString,
107
114
  isNonEmptyStringOrUndefined: () => isNonEmptyStringOrUndefined,
115
+ isNotThrowing: () => isNotThrowing,
108
116
  isNull: () => isNull,
109
117
  isNullish: () => isNullish,
110
118
  isNumber: () => isNumber,
@@ -500,6 +508,11 @@ function isThrowing(throwTestFn, msg) {
500
508
  _fail(`Expected to throw`, msg);
501
509
  return true;
502
510
  }
511
+ function isNotThrowing(throwTestFn, msg) {
512
+ if (!guard_exports.isNotThrowing(throwTestFn))
513
+ _fail(`Expected to throw`, msg);
514
+ return true;
515
+ }
503
516
 
504
517
  // src/web/cookies.ts
505
518
  var cookies_exports = {};
@@ -747,6 +760,7 @@ __export(guard_exports, {
747
760
  isNonEmptyArrayOrUndefined: () => isNonEmptyArrayOrUndefined2,
748
761
  isNonEmptyString: () => isNonEmptyString2,
749
762
  isNonEmptyStringOrUndefined: () => isNonEmptyStringOrUndefined2,
763
+ isNotThrowing: () => isNotThrowing2,
750
764
  isNull: () => isNull2,
751
765
  isNullish: () => isNullish2,
752
766
  isNumber: () => isNumber2,
@@ -996,6 +1010,14 @@ function isThrowing2(throwTestFn) {
996
1010
  return true;
997
1011
  }
998
1012
  }
1013
+ function isNotThrowing2(throwTestFn) {
1014
+ try {
1015
+ throwTestFn();
1016
+ return true;
1017
+ } catch (err) {
1018
+ return false;
1019
+ }
1020
+ }
999
1021
  function tryOr(tryFn, orVal) {
1000
1022
  try {
1001
1023
  return tryFn();
@@ -1429,99 +1451,19 @@ __export(str_exports, {
1429
1451
  removeAt: () => removeAt,
1430
1452
  repeatString: () => repeatString,
1431
1453
  replaceAt: () => replaceAt,
1454
+ stringify: () => stringify,
1432
1455
  toCharArray: () => toCharArray
1433
1456
  });
1434
- function toCharArray(str2) {
1435
- return str2.split("");
1436
- }
1437
- function repeatString(repeatString2, repeatCount) {
1438
- if (!isInteger2(repeatCount) || repeatCount < 0) {
1439
- throw new Error("repeatStr: Invalid repeatCount = " + repeatCount);
1440
- }
1441
- return new Array(repeatCount + 1).join(repeatString2);
1442
- }
1443
- function chunkString(str2, chunkSize) {
1444
- if (!isInteger2(chunkSize) || chunkSize < 1) {
1445
- throw new Error("chunckString: Invalid chuckSize = " + chunkSize);
1446
- }
1447
- let result = [];
1448
- for (let i = 0; i < str2.length; i += chunkSize) {
1449
- result.push(str2.slice(i, i + chunkSize));
1450
- }
1451
- return result;
1452
- }
1453
- function replaceAt(str2, pos, removeCount, insert) {
1454
- if (!isInteger2(removeCount) || removeCount < 0) {
1455
- throw new Error("replaceAt: Invalid removeCount = " + removeCount);
1456
- } else if (!isInteger2(pos) || pos < 0 || pos + removeCount > str2.length) {
1457
- throw new Error("replaceAt: Invalid pos = " + pos + ", removeCount = " + removeCount + ", str.length = " + str2.length);
1458
- } else {
1459
- return str2.substring(0, pos) + insert + str2.substring(pos + removeCount);
1460
- }
1461
- }
1462
- function insertAt(str2, pos, insertStr) {
1463
- return replaceAt(str2, pos, 0, insertStr);
1464
- }
1465
- function removeAt(str2, pos, removeCount) {
1466
- return replaceAt(str2, pos, removeCount, "");
1467
- }
1468
- function charCount(str2, ch) {
1469
- if (ch.length !== 1 || str2.length === 0) return 0;
1470
- let count = 0;
1471
- for (let i = 0; i < str2.length; i++) {
1472
- if (str2[i] === ch) count++;
1473
- }
1474
- return count;
1475
- }
1476
- function makeSentenceFromPascal(PascalString) {
1477
- if (PascalString === "") {
1478
- return "";
1479
- }
1480
- let word = PascalString.charAt(0);
1481
- let sentence = "";
1482
- const addWord = () => {
1483
- if (word !== "") {
1484
- if (sentence === "") {
1485
- sentence += word.charAt(0).toUpperCase() + word.substring(1);
1486
- } else {
1487
- sentence += " " + word;
1488
- }
1489
- word = "";
1490
- }
1491
- };
1492
- const isLetterAndCapital = (c) => {
1493
- return c.toUpperCase() !== c.toLowerCase() && c === c.toUpperCase();
1494
- };
1495
- for (let i = 1; i < PascalString.length; i++) {
1496
- let c = PascalString.charAt(i);
1497
- if (isLetterAndCapital(c)) {
1498
- addWord();
1499
- }
1500
- word += c.toLowerCase();
1501
- }
1502
- addWord();
1503
- return sentence;
1504
- }
1505
-
1506
- // src/utils/index.ts
1507
- var Is = guard_exports;
1508
1457
 
1509
- // src/core/format-value.ts
1510
- function formatValue(value) {
1511
- if (isString2(value)) {
1512
- return `"${value}"`;
1513
- } else if (isArray2(value)) {
1514
- return `[ ${value.map((e) => formatValue(e)).join(", ")} ]`.replaceAll(" ", " ");
1515
- } else if (isFunction2(value.toString)) {
1516
- return value.toString();
1517
- } else {
1518
- return JSON.stringify(value);
1519
- }
1520
- }
1458
+ // src/core/base.ts
1459
+ var DefaultEqualityFn = (a, b) => a === b;
1460
+ var BaseContainer = class {
1461
+ };
1521
1462
 
1522
1463
  // src/core/stack.ts
1523
- var Stack = class {
1464
+ var Stack = class extends BaseContainer {
1524
1465
  constructor() {
1466
+ super();
1525
1467
  __publicField(this, "data", []);
1526
1468
  }
1527
1469
  assertId(id) {
@@ -1582,13 +1524,14 @@ var Stack = class {
1582
1524
  this.data.length = 0;
1583
1525
  }
1584
1526
  toString() {
1585
- return `Stack(${this.length})${formatValue(this.data)}`;
1527
+ return `Stack(${this.length})${stringify(this.data)}`;
1586
1528
  }
1587
1529
  };
1588
1530
 
1589
1531
  // src/core/vec.ts
1590
- var Vec = class _Vec {
1532
+ var Vec = class _Vec extends BaseContainer {
1591
1533
  constructor(...coords) {
1534
+ super();
1592
1535
  __publicField(this, "coords");
1593
1536
  if (coords.length < 2) {
1594
1537
  throw new TypeError("Vec needs minumum two coords!");
@@ -1789,19 +1732,31 @@ var DivRect = class _DivRect {
1789
1732
  static createSections(leftw, rightw, toph, bottomh) {
1790
1733
  return new _DivRect(-leftw, 0, rightw, -toph, 0, bottomh);
1791
1734
  }
1792
- /** @deprecated - Renamed to anchorX. */
1735
+ /**
1736
+ * @deprecated - Renamed to anchorX. Will be removed in v2.0.0.
1737
+ * @private
1738
+ * */
1793
1739
  get centerX() {
1794
1740
  return this.anchorX;
1795
1741
  }
1796
- /** @deprecated - Renamed to anchorX. */
1742
+ /**
1743
+ * @deprecated - Renamed to anchorX. Will be removed in v2.0.0.
1744
+ * @private
1745
+ * */
1797
1746
  set centerX(x) {
1798
1747
  this.anchorX = x;
1799
1748
  }
1800
- /** @deprecated - Renamed to anchorY. */
1749
+ /**
1750
+ * @deprecated - Renamed to anchorX. Will be removed in v2.0.0.
1751
+ * @private
1752
+ * */
1801
1753
  get centerY() {
1802
1754
  return this.anchorY;
1803
1755
  }
1804
- /** @deprecated - Renamed to anchorY. */
1756
+ /**
1757
+ * @deprecated - Renamed to anchorX. Will be removed in v2.0.0.
1758
+ * @private
1759
+ * */
1805
1760
  set centerY(y) {
1806
1761
  this.anchorY = y;
1807
1762
  }
@@ -1919,7 +1874,10 @@ var DivRect = class _DivRect {
1919
1874
  equalsEdges(other) {
1920
1875
  return _DivRect.equalsEdges(this, other);
1921
1876
  }
1922
- /** @deprecated - Use `DivRect.equalsEdges()` instead. */
1877
+ /**
1878
+ * @deprecated - Use `DivRect.equalsEdges()` instead. Will be removed in v2.0.0.
1879
+ * @private
1880
+ */
1923
1881
  static equalsFrame(a, b) {
1924
1882
  return _DivRect.equalsEdges(a, b);
1925
1883
  }
@@ -2038,9 +1996,10 @@ var DivRect = class _DivRect {
2038
1996
  };
2039
1997
 
2040
1998
  // src/core/LRU-cache.ts
2041
- var LRUCache = class {
1999
+ var LRUCache = class extends BaseContainer {
2042
2000
  // Maximum key length.
2043
2001
  constructor(maxSize, maxKeyLength = Infinity) {
2002
+ super();
2044
2003
  __publicField(this, "cache");
2045
2004
  // Stores the actual key-value pairs
2046
2005
  __publicField(this, "next");
@@ -2132,11 +2091,31 @@ var LRUCache = class {
2132
2091
  }
2133
2092
  this.tail = key;
2134
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
+ }
2135
2113
  };
2136
2114
 
2137
2115
  // src/core/index-array.ts
2138
- var IndexArray = class _IndexArray {
2116
+ var IndexArray = class _IndexArray extends BaseContainer {
2139
2117
  constructor(entries) {
2118
+ super();
2140
2119
  __publicField(this, "posVal");
2141
2120
  __publicField(this, "hasPos");
2142
2121
  // Number of values
@@ -2349,14 +2328,20 @@ var IndexArray = class _IndexArray {
2349
2328
  return this.valuesArray();
2350
2329
  }
2351
2330
  toString() {
2352
- const entries = this.entriesArray().map(([id, v]) => `${formatValue(id)}: ${formatValue(v)}`).join(", ");
2353
- 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} ]`;
2354
2338
  }
2355
2339
  };
2356
2340
 
2357
2341
  // src/core/signed-index-array.ts
2358
- var SignedIndexArray = class _SignedIndexArray {
2342
+ var SignedIndexArray = class _SignedIndexArray extends BaseContainer {
2359
2343
  constructor(entries) {
2344
+ super();
2360
2345
  // For indexes >= 0
2361
2346
  __publicField(this, "posVal");
2362
2347
  __publicField(this, "hasPos");
@@ -2612,21 +2597,28 @@ var SignedIndexArray = class _SignedIndexArray {
2612
2597
  return this.valuesArray();
2613
2598
  }
2614
2599
  toString() {
2615
- const entries = this.entriesArray().map(([id, v]) => `${formatValue(id)}: ${formatValue(v)}`).join(", ");
2616
- 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} ]`;
2617
2607
  }
2618
2608
  };
2619
2609
 
2620
2610
  // src/core/default-array.ts
2621
- var DefaultArray = class _DefaultArray {
2622
- constructor(lengthOrValues, defaultValue) {
2623
- this.defaultValue = defaultValue;
2611
+ var DefaultArray = class _DefaultArray extends BaseContainer {
2612
+ constructor(...args) {
2613
+ super();
2614
+ __publicField(this, "defaultValue");
2624
2615
  __publicField(this, "data");
2625
- if (typeof lengthOrValues === "number") {
2626
- this.data = Array(lengthOrValues).fill(defaultValue);
2616
+ this.defaultValue = args.pop();
2617
+ if (typeof args[0] === "number") {
2618
+ this.data = Array(args[0]).fill(this.defaultValue);
2627
2619
  } else {
2628
- this.data = Array.from(lengthOrValues).map(
2629
- (v) => v === void 0 ? defaultValue : v
2620
+ this.data = Array.from(args[0]).map(
2621
+ (v) => v === void 0 ? this.defaultValue : v
2630
2622
  );
2631
2623
  }
2632
2624
  }
@@ -2727,9 +2719,7 @@ var DefaultArray = class _DefaultArray {
2727
2719
  }
2728
2720
  clone() {
2729
2721
  const ctor = this.constructor;
2730
- const clone = new ctor(this.length, this.defaultValue);
2731
- clone.data = this.data.slice();
2732
- return clone;
2722
+ return new ctor(this.values(), this.defaultValue);
2733
2723
  }
2734
2724
  merge(other, conflictResolver) {
2735
2725
  if (this.constructor !== other.constructor)
@@ -2815,62 +2805,92 @@ var DefaultArray = class _DefaultArray {
2815
2805
  return this.valuesArray();
2816
2806
  }
2817
2807
  toString() {
2818
- const entries = this.entriesArray().map(([id, v]) => `${formatValue(id)}: ${formatValue(v)}`).join(", ");
2819
- return `DefaultArray[ ${entries} ]`.replaceAll(" ", " ");
2808
+ return stringify(this.data);
2820
2809
  }
2821
2810
  };
2822
2811
 
2823
- // src/core/map1.ts
2824
- var Map1 = class _Map1 {
2825
- constructor(entries) {
2826
- __publicField(this, "map1");
2827
- this.map1 = entries instanceof _Map1 ? new Map(entries.map1) : new Map(entries);
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);
2828
2822
  }
2829
- has(key1) {
2830
- return this.map1.has(key1);
2823
+ static createDeep(arg) {
2824
+ return arg ? new _UniMap(arg, isDeepEqual2) : new _UniMap(isDeepEqual2);
2831
2825
  }
2832
- set(key1, value) {
2833
- this.map1.set(key1, 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;
2833
+ }
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);
2834
2845
  return value;
2835
2846
  }
2836
- get(key1) {
2837
- return this.map1.get(key1);
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;
2838
2854
  }
2839
- getOrDefault(key1, defaultValue) {
2840
- return this.get(key1) ?? defaultValue;
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);
2841
2862
  }
2842
- getOrCreate(key1, creatorOrValue) {
2843
- if (!this.has(key1)) {
2863
+ getOrDefault(key, defaultValue) {
2864
+ return this.get(key) ?? defaultValue;
2865
+ }
2866
+ getOrCreate(key, creatorOrValue) {
2867
+ if (!this.has(key)) {
2844
2868
  const value = isFunction2(creatorOrValue) ? creatorOrValue() : creatorOrValue;
2845
- this.set(key1, value);
2846
- return value;
2869
+ return this.set(key, value);
2847
2870
  }
2848
- return this.get(key1);
2849
- }
2850
- delete(key1) {
2851
- return this.map1.delete(key1);
2871
+ return this.get(key);
2852
2872
  }
2853
2873
  clear() {
2854
- this.map1.clear();
2874
+ this.map.clear();
2855
2875
  }
2856
2876
  get size() {
2857
- return this.map1.size;
2877
+ return this.map.size;
2858
2878
  }
2859
2879
  isEmpty() {
2860
2880
  return this.size === 0;
2861
2881
  }
2862
2882
  forEach(callbackfn, thisArg) {
2863
- this.map1.forEach((value, key1) => callbackfn.call(thisArg, value, key1, this));
2883
+ this.map.forEach((value, key) => callbackfn.call(thisArg, value, key, this));
2864
2884
  }
2865
2885
  *keys() {
2866
- yield* this.map1.keys();
2886
+ yield* this.map.keys();
2867
2887
  }
2868
2888
  *values() {
2869
- yield* this.map1.values();
2889
+ yield* this.map.values();
2870
2890
  }
2871
2891
  *entries() {
2872
- for (const [key1, value] of this.map1)
2873
- yield [key1, value];
2892
+ for (const [key, value] of this.map)
2893
+ yield [key, value];
2874
2894
  }
2875
2895
  keysArray() {
2876
2896
  return [...this.keys()];
@@ -2900,34 +2920,34 @@ var Map1 = class _Map1 {
2900
2920
  yield* this.entries();
2901
2921
  }
2902
2922
  clone() {
2903
- return new _Map1(this);
2923
+ return new _UniMap(this, this.keyEquals);
2904
2924
  }
2905
2925
  merge(other, conflictResolver) {
2906
- for (const [key1, value] of other.entries()) {
2907
- if (this.has(key1) && conflictResolver) {
2908
- this.set(key1, conflictResolver(this.get(key1), value, key1));
2926
+ for (const [key, value] of other.entries()) {
2927
+ if (this.has(key) && conflictResolver) {
2928
+ this.set(key, conflictResolver(this.get(key), value, key));
2909
2929
  } else {
2910
- this.set(key1, value);
2930
+ this.set(key, value);
2911
2931
  }
2912
2932
  }
2913
2933
  return this;
2914
2934
  }
2915
2935
  some(fn) {
2916
- for (const [key1, value] of this.map1) {
2917
- if (fn(value, key1)) return true;
2936
+ for (const [key, value] of this.map) {
2937
+ if (fn(value, key)) return true;
2918
2938
  }
2919
2939
  return false;
2920
2940
  }
2921
2941
  every(fn) {
2922
- for (const [key1, value] of this.map1) {
2923
- if (!fn(value, key1)) return false;
2942
+ for (const [key, value] of this.map) {
2943
+ if (!fn(value, key)) return false;
2924
2944
  }
2925
2945
  return true;
2926
2946
  }
2927
2947
  filter(predicate) {
2928
2948
  const result = new this.constructor();
2929
- for (const [key1, value] of this.map1) {
2930
- if (predicate(value, key1, this)) result.set(key1, value);
2949
+ for (const [key, value] of this.map) {
2950
+ if (predicate(value, key, this)) result.set(key, value);
2931
2951
  }
2932
2952
  return result;
2933
2953
  }
@@ -2950,41 +2970,48 @@ var Map1 = class _Map1 {
2950
2970
  start = first;
2951
2971
  }
2952
2972
  for (let current = start; !current.done; current = iterator.next()) {
2953
- const [key1, value] = current.value;
2954
- acc = fn(acc, value, key1);
2973
+ const [key, value] = current.value;
2974
+ acc = fn(acc, value, key);
2955
2975
  }
2956
2976
  return acc;
2957
2977
  }
2958
2978
  mapEntries(fn) {
2959
2979
  let result = [];
2960
- for (const [key1, value] of this.map1) {
2961
- result.push(fn(value, key1));
2980
+ for (const [key, value] of this.map) {
2981
+ result.push(fn(value, key));
2962
2982
  }
2963
2983
  return result;
2964
2984
  }
2965
2985
  mapValues(fn) {
2966
- let result = new _Map1();
2967
- for (const [key1, value] of this.map1) {
2968
- result.set(key1, fn(value, key1));
2986
+ let result = new _UniMap();
2987
+ for (const [key, value] of this.map) {
2988
+ result.set(key, fn(value, key));
2969
2989
  }
2970
2990
  return result;
2971
2991
  }
2972
2992
  toMap() {
2973
- return new Map(this.map1);
2993
+ return new Map(this.map);
2974
2994
  }
2975
2995
  toString() {
2976
- const entries = [...this.map1].map(([k, v]) => `${formatValue(k)} => ${formatValue(v)}`).join(", ");
2977
- return `Map1(${this.size}){ ${entries} }`.replaceAll(" ", " ");
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} }`;
2978
2998
  }
2979
2999
  };
2980
3000
 
2981
- // src/core/map2.ts
2982
- var Map2 = class _Map2 {
3001
+ // src/core/bi-map.ts
3002
+ var BiMap = class _BiMap extends BaseContainer {
2983
3003
  constructor(entries) {
2984
- __publicField(this, "map1", /* @__PURE__ */ new Map());
2985
- if (entries instanceof _Map2) {
2986
- for (const [key1, inner] of entries.map1) {
2987
- this.map1.set(key1, new Map(inner));
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
+ }
2988
3015
  }
2989
3016
  } else if (entries) {
2990
3017
  for (const [key1, key2, value] of entries) {
@@ -2996,9 +3023,7 @@ var Map2 = class _Map2 {
2996
3023
  return this.map1.get(key1)?.has(key2) ?? false;
2997
3024
  }
2998
3025
  set(key1, key2, value) {
2999
- let map2 = this.map1.get(key1) ?? this.map1.set(key1, /* @__PURE__ */ new Map()).get(key1);
3000
- map2.set(key2, value);
3001
- return value;
3026
+ return this.map1.getOrCreate(key1, () => new UniMap(this.key2Equals)).set(key2, value);
3002
3027
  }
3003
3028
  get(key1, key2) {
3004
3029
  return this.map1.get(key1)?.get(key2);
@@ -3076,7 +3101,7 @@ var Map2 = class _Map2 {
3076
3101
  yield* this.entries();
3077
3102
  }
3078
3103
  clone() {
3079
- return new _Map2(this);
3104
+ return new _BiMap(this);
3080
3105
  }
3081
3106
  merge(other, conflictResolver) {
3082
3107
  for (const [key1, key2, value] of other.entries()) {
@@ -3147,7 +3172,7 @@ var Map2 = class _Map2 {
3147
3172
  return result;
3148
3173
  }
3149
3174
  mapValues(fn) {
3150
- let result = new _Map2();
3175
+ let result = new _BiMap();
3151
3176
  for (const [key1, map2] of this.map1) {
3152
3177
  for (const [key2, value] of map2) {
3153
3178
  result.set(key1, key2, fn(value, key1, key2));
@@ -3167,24 +3192,28 @@ var Map2 = class _Map2 {
3167
3192
  toString() {
3168
3193
  const entries = [];
3169
3194
  for (const [key1, map2] of this.map1) {
3170
- const inner = [...map2].map(([key2, v]) => `${formatValue(key2)} => ${formatValue(v)}`).join(", ");
3171
- entries.push(`${formatValue(key1)} => { ${inner} }`);
3195
+ const inner = [...map2].map(([key2, v]) => `${stringify(key2)} => ${stringify(v)}`).join(", ");
3196
+ entries.push(`${stringify(key1)} => { ${inner} }`);
3172
3197
  }
3173
- return `Map2(${this.size}){ ${entries} }`.replaceAll(" ", " ");
3198
+ return entries.length === 0 ? `Map(${this.size}){ }` : `Map(${this.size}){ ${entries} }`;
3174
3199
  }
3175
3200
  };
3176
3201
 
3177
- // src/core/map3.ts
3178
- var Map3 = class _Map3 {
3202
+ // src/core/tri-map.ts
3203
+ var TriMap = class _TriMap extends BaseContainer {
3179
3204
  constructor(entries) {
3180
- __publicField(this, "map1", /* @__PURE__ */ new Map());
3181
- 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) {
3182
3212
  for (const [key1, map2] of entries.map1) {
3183
- const newMap2 = /* @__PURE__ */ new Map();
3213
+ const newMap2 = this.map1.set(key1, new UniMap(this.key2Equals));
3184
3214
  for (const [key2, map3] of map2) {
3185
- newMap2.set(key2, new Map(map3));
3215
+ newMap2.set(key2, new UniMap(map3, this.key3Equals));
3186
3216
  }
3187
- this.map1.set(key1, newMap2);
3188
3217
  }
3189
3218
  } else if (entries) {
3190
3219
  for (const [key1, key2, key3, value] of entries) {
@@ -3196,10 +3225,8 @@ var Map3 = class _Map3 {
3196
3225
  return this.map1.get(key1)?.get(key2)?.has(key3) ?? false;
3197
3226
  }
3198
3227
  set(key1, key2, key3, value) {
3199
- let map2 = this.map1.get(key1);
3200
- if (!map2) this.map1.set(key1, map2 = /* @__PURE__ */ new Map());
3201
- let map3 = map2.get(key2);
3202
- 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));
3203
3230
  map3.set(key3, value);
3204
3231
  return value;
3205
3232
  }
@@ -3291,7 +3318,7 @@ var Map3 = class _Map3 {
3291
3318
  yield* this.entries();
3292
3319
  }
3293
3320
  clone() {
3294
- return new _Map3(this);
3321
+ return new _TriMap(this);
3295
3322
  }
3296
3323
  merge(other, conflictResolver) {
3297
3324
  for (const [key1, key2, key3, value] of other.entries()) {
@@ -3370,7 +3397,7 @@ var Map3 = class _Map3 {
3370
3397
  return result;
3371
3398
  }
3372
3399
  mapValues(fn) {
3373
- let result = new _Map3();
3400
+ let result = new _TriMap();
3374
3401
  for (const [key1, map2] of this.map1) {
3375
3402
  for (const [key2, map3] of map2) {
3376
3403
  for (const [key3, value] of map3) {
@@ -3395,22 +3422,32 @@ var Map3 = class _Map3 {
3395
3422
  const entries = [];
3396
3423
  for (const [key1, map2] of this.map1) {
3397
3424
  for (const [key2, map3] of map2) {
3398
- const inner = [...map3].map(([key3, v]) => `${formatValue(key3)} => ${formatValue(v)}`).join(", ");
3399
- 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} }`);
3400
3427
  }
3401
3428
  }
3402
- return `Map3(${this.size}){ ${entries.join(", ")} }`.replaceAll(" ", " ");
3429
+ return entries.length === 0 ? `Map(${this.size}){ }` : `Map(${this.size}){ ${entries.join(", ")} }`;
3403
3430
  }
3404
3431
  };
3405
3432
 
3406
3433
  // src/core/set.ts
3407
- var SetBase = class {
3408
- constructor(entries) {
3434
+ var ValueSet = class _ValueSet extends BaseContainer {
3435
+ constructor(...args) {
3436
+ super();
3409
3437
  __publicField(this, "data");
3410
- this.data = new Set(entries ?? []);
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);
3411
3446
  }
3412
3447
  has(value) {
3413
- return this.some((v) => this.valueEquals(v, value));
3448
+ if (this.equals === DefaultEqualityFn)
3449
+ return this.data.has(value);
3450
+ return this.some((v) => this.equals(v, value));
3414
3451
  }
3415
3452
  add(value) {
3416
3453
  if (!this.has(value))
@@ -3419,8 +3456,8 @@ var SetBase = class {
3419
3456
  }
3420
3457
  /** @internal - This method exists only for interface `KVComponent` compatibility.*/
3421
3458
  set(key, value) {
3422
- if (!this.valueEquals(key, value))
3423
- throw new TypeError("SetBase.set() requires key === value.");
3459
+ if (!this.equals(key, value))
3460
+ throw new TypeError("ValueSet.set() requires key === value.");
3424
3461
  this.add(value);
3425
3462
  }
3426
3463
  /** @internal - This method exists only for interface `KVComponent` compatibility.*/
@@ -3440,9 +3477,10 @@ var SetBase = class {
3440
3477
  return this.get(key);
3441
3478
  }
3442
3479
  delete(value) {
3443
- if (!this.has(value)) return false;
3480
+ if (this.equals === DefaultEqualityFn || this.data.has(value))
3481
+ return this.data.delete(value);
3444
3482
  for (const v of this.values()) {
3445
- if (this.valueEquals(v, value)) {
3483
+ if (this.equals(v, value)) {
3446
3484
  this.data.delete(v);
3447
3485
  return true;
3448
3486
  }
@@ -3489,7 +3527,7 @@ var SetBase = class {
3489
3527
  yield* this.values();
3490
3528
  }
3491
3529
  clone() {
3492
- const result = this.createEmpty();
3530
+ const result = new _ValueSet();
3493
3531
  for (const v of this.values()) result.add(v);
3494
3532
  return result;
3495
3533
  }
@@ -3512,7 +3550,7 @@ var SetBase = class {
3512
3550
  return true;
3513
3551
  }
3514
3552
  filter(predicate) {
3515
- const result = this.createEmpty();
3553
+ const result = new _ValueSet();
3516
3554
  for (const value of this.data)
3517
3555
  if (predicate(value, this)) result.add(value);
3518
3556
  return result;
@@ -3522,7 +3560,7 @@ var SetBase = class {
3522
3560
  let first = iterator.next();
3523
3561
  if (first.done) {
3524
3562
  if (arguments.length < 2) {
3525
- throw new TypeError("Reduce of empty SetBase with no initial value!");
3563
+ throw new TypeError("Reduce of empty ValueSet with no initial value!");
3526
3564
  }
3527
3565
  return init;
3528
3566
  }
@@ -3542,7 +3580,7 @@ var SetBase = class {
3542
3580
  return acc;
3543
3581
  }
3544
3582
  mapValues(fn) {
3545
- let result = this.createEmpty();
3583
+ let result = new _ValueSet();
3546
3584
  for (const value of this.data) {
3547
3585
  result.add(fn(value));
3548
3586
  }
@@ -3556,7 +3594,7 @@ var SetBase = class {
3556
3594
  return result;
3557
3595
  }
3558
3596
  map(fn) {
3559
- let result = this.createEmpty();
3597
+ let result = new _ValueSet();
3560
3598
  for (const value of this.values()) {
3561
3599
  result.add(fn(value));
3562
3600
  }
@@ -3569,41 +3607,14 @@ var SetBase = class {
3569
3607
  return [...this.values()];
3570
3608
  }
3571
3609
  toString() {
3572
- return `${this.getName()}(${this.size})${formatValue([...this.data])}`.replaceAll(" ", " ");
3573
- }
3574
- };
3575
- var Set1 = class _Set1 extends SetBase {
3576
- constructor(entries) {
3577
- super(entries);
3578
- }
3579
- createEmpty() {
3580
- return new _Set1();
3581
- }
3582
- valueEquals(a, b) {
3583
- return a === b;
3584
- }
3585
- getName() {
3586
- return "Set1";
3587
- }
3588
- };
3589
- var DeepSet = class _DeepSet extends SetBase {
3590
- constructor(entries) {
3591
- super(entries);
3592
- }
3593
- createEmpty() {
3594
- return new _DeepSet();
3595
- }
3596
- valueEquals(a, b) {
3597
- return isDeepEqual2(a, b);
3598
- }
3599
- getName() {
3600
- return "DeepSet";
3610
+ return stringify(this.data);
3601
3611
  }
3602
3612
  };
3603
3613
 
3604
3614
  // src/core/multi-container.ts
3605
- var MultiContainer = class {
3615
+ var MultiContainer = class extends BaseContainer {
3606
3616
  constructor(base) {
3617
+ super();
3607
3618
  this.base = base;
3608
3619
  }
3609
3620
  isEmpty() {
@@ -3659,39 +3670,404 @@ var MultiContainer = class {
3659
3670
  const entries = [];
3660
3671
  for (const keys of this.keys()) {
3661
3672
  const arr = this.getAll(...keys);
3662
- const keyStr = Array.isArray(keys) ? formatValue(keys) : "[ ]";
3663
- const valuesStr = Array.isArray(arr) ? formatValue(arr) : "[ ]";
3673
+ const keyStr = Array.isArray(keys) ? stringify(keys) : "[ ]";
3674
+ const valuesStr = Array.isArray(arr) ? stringify(arr) : "[ ]";
3664
3675
  entries.push(`${keyStr} => ${valuesStr}`);
3665
3676
  }
3666
- return `MultiContainer{ ${entries.join(", ")} }`.replaceAll(" ", " ");
3677
+ return entries.length === 0 ? `MultiContainer{ }` : `MultiContainer{ ${entries.join(", ")} }`;
3667
3678
  }
3668
3679
  };
3669
3680
  function asMulti(base) {
3670
3681
  return new MultiContainer(base);
3671
3682
  }
3672
3683
 
3673
- // src/deprecated/vec2.ts
3674
- var Vec2 = class _Vec2 {
3675
- constructor(x, y) {
3676
- __publicField(this, "x");
3677
- __publicField(this, "y");
3678
- this.x = x ?? 0;
3679
- this.y = y ?? 0;
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);
3680
3690
  }
3681
- length() {
3682
- return Math.sqrt(this.x * this.x + this.y * this.y);
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
+ }
3683
3707
  }
3684
- add(a) {
3685
- return new _Vec2(this.x + a.x, this.y + a.y);
3708
+ static createDeep(entries) {
3709
+ if (entries) {
3710
+ return new _LinkedList(entries, isDeepEqual2);
3711
+ } else {
3712
+ return new _LinkedList(isDeepEqual2);
3713
+ }
3686
3714
  }
3687
- sub(a) {
3688
- return new _Vec2(this.x - a.x, this.y - a.y);
3715
+ get length() {
3716
+ return this._size;
3689
3717
  }
3690
- mul(a) {
3691
- return new _Vec2(this.x * a, this.y * a);
3718
+ get first() {
3719
+ return this._head?.value;
3692
3720
  }
3693
- div(a) {
3694
- return new _Vec2(this.x / a, this.y / a);
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");
4053
+ __publicField(this, "y");
4054
+ this.x = x ?? 0;
4055
+ this.y = y ?? 0;
4056
+ }
4057
+ length() {
4058
+ return Math.sqrt(this.x * this.x + this.y * this.y);
4059
+ }
4060
+ add(a) {
4061
+ return new _Vec2(this.x + a.x, this.y + a.y);
4062
+ }
4063
+ sub(a) {
4064
+ return new _Vec2(this.x - a.x, this.y - a.y);
4065
+ }
4066
+ mul(a) {
4067
+ return new _Vec2(this.x * a, this.y * a);
4068
+ }
4069
+ div(a) {
4070
+ return new _Vec2(this.x / a, this.y / a);
3695
4071
  }
3696
4072
  };
3697
4073
 
@@ -3746,17 +4122,800 @@ var SmallIntCache = class {
3746
4122
  this.neg = [];
3747
4123
  }
3748
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
+ };
3749
4904
  // Annotate the CommonJS export names for ESM import in node:
3750
4905
  0 && (module.exports = {
3751
4906
  Assert,
4907
+ BaseContainer,
4908
+ BiMap,
3752
4909
  Cookies,
3753
4910
  DeepSet,
3754
4911
  DefaultArray,
4912
+ DefaultEqualityFn,
3755
4913
  Device,
3756
4914
  DivRect,
3757
4915
  Guard,
3758
4916
  IndexArray,
3759
4917
  LRUCache,
4918
+ LinkedList,
3760
4919
  Map1,
3761
4920
  Map2,
3762
4921
  Map3,
@@ -3766,7 +4925,10 @@ var SmallIntCache = class {
3766
4925
  SignedIndexArray,
3767
4926
  SmallIntCache,
3768
4927
  Stack,
4928
+ TriMap,
4929
+ UniMap,
3769
4930
  Utils,
4931
+ ValueSet,
3770
4932
  Vec,
3771
4933
  Vec2,
3772
4934
  asMulti