@tspro/ts-utils-lib 1.18.0 → 1.19.1

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.18.0 | (c) 2023 PahkaSoft | Licensed under the MIT License */
1
+ /* TsUtilsLib v1.19.1 | (c) 2023 PahkaSoft | Licensed under the MIT License */
2
2
  "use strict";
3
3
  var __defProp = Object.defineProperty;
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -25,6 +25,8 @@ var index_exports = {};
25
25
  __export(index_exports, {
26
26
  Assert: () => assert_exports,
27
27
  Cookies: () => cookies_exports,
28
+ DeepSet: () => DeepSet,
29
+ DefaultArray: () => DefaultArray,
28
30
  Device: () => device_exports,
29
31
  DivRect: () => DivRect,
30
32
  Guard: () => guard_exports,
@@ -34,6 +36,8 @@ __export(index_exports, {
34
36
  Map2: () => Map2,
35
37
  Map3: () => Map3,
36
38
  MultiContainer: () => MultiContainer,
39
+ Set1: () => Set1,
40
+ SetBase: () => SetBase,
37
41
  SignedIndexArray: () => SignedIndexArray,
38
42
  SmallIntCache: () => SmallIntCache,
39
43
  Stack: () => Stack,
@@ -516,21 +520,6 @@ var _consent;
516
520
  var _expires;
517
521
  var str = _read(ConsentCookieName);
518
522
  _consent = str === "accept" /* Accept */ || str === "decline" /* Decline */ ? str : void 0;
519
- function setExpireDays(days) {
520
- _expires = /* @__PURE__ */ new Date();
521
- _expires.setDate(_expires.getDate() + days);
522
- }
523
- function isConsentPending() {
524
- return _consent === void 0;
525
- }
526
- function accept() {
527
- _consent = "accept" /* Accept */;
528
- _save(ConsentCookieName, _consent);
529
- }
530
- function decline() {
531
- _consent = "decline" /* Decline */;
532
- _save(ConsentCookieName, _consent);
533
- }
534
523
  function _getList() {
535
524
  let s = document.cookie;
536
525
  return s.split(";").map((c) => c.trim());
@@ -550,18 +539,31 @@ function _read(name, defaultValue) {
550
539
  function _erase(name) {
551
540
  document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 UTC;";
552
541
  }
542
+ function setExpireDays(days) {
543
+ _expires = /* @__PURE__ */ new Date();
544
+ _expires.setDate(_expires.getDate() + days);
545
+ }
546
+ function isConsentPending() {
547
+ return _consent === void 0;
548
+ }
549
+ function accept() {
550
+ _consent = "accept" /* Accept */;
551
+ _save(ConsentCookieName, _consent);
552
+ }
553
+ function decline() {
554
+ _consent = "decline" /* Decline */;
555
+ _save(ConsentCookieName, _consent);
556
+ }
553
557
  function save(name, value) {
554
- if (_consent === "accept" /* Accept */) {
558
+ if (_consent === "accept" /* Accept */)
555
559
  _save(name, value);
556
- }
557
560
  return value;
558
561
  }
559
562
  function read(name, defaultValue) {
560
- if (_consent === "accept" /* Accept */) {
561
- return _read(name, defaultValue) || defaultValue;
562
- } else {
563
+ if (_consent === "accept" /* Accept */)
564
+ return _read(name, defaultValue) ?? defaultValue;
565
+ else
563
566
  return defaultValue;
564
- }
565
567
  }
566
568
  function readInt(name, defaultValue) {
567
569
  if (_consent === "accept" /* Accept */) {
@@ -580,9 +582,8 @@ function readBool(name, defaultValue) {
580
582
  }
581
583
  }
582
584
  function erase(name) {
583
- if (_consent === "accept" /* Accept */ || name === ConsentCookieName) {
585
+ if (_consent === "accept" /* Accept */ || name === ConsentCookieName)
584
586
  _erase(name);
585
- }
586
587
  }
587
588
  function eraseAll() {
588
589
  document.cookie.split(";").forEach((c) => erase(c.trim().split("=")[0]));
@@ -690,7 +691,7 @@ function toPx(input) {
690
691
  } else {
691
692
  value = parseFloat(input);
692
693
  }
693
- assert_exports.finite(value, "value in function toPx");
694
+ assert_exports.isFinite(value, "value in function toPx");
694
695
  switch (unit) {
695
696
  case "mm":
696
697
  return mmToPx(value);
@@ -1038,11 +1039,11 @@ function toArray(a) {
1038
1039
  function duplicate(a) {
1039
1040
  return a === void 0 ? a : a.slice();
1040
1041
  }
1041
- function removeDuplicates(a) {
1042
- return a.filter((item, pos, arr) => arr.indexOf(item) === pos);
1042
+ function removeDuplicates(arr, compareFn) {
1043
+ return compareFn !== void 0 ? arr.filter((a, id, self) => id === self.findIndex((b) => compareFn(a, b))) : arr.filter((a, id, self) => id === self.indexOf(a));
1043
1044
  }
1044
- function removeDuplicatesCmp(arr, cmp2) {
1045
- return arr.filter((t1, index, self) => index === self.findIndex((t2) => cmp2(t1, t2)));
1045
+ function removeDuplicatesCmp(arr, compareFn) {
1046
+ return arr.filter((a, id, self) => id === self.findIndex((b) => compareFn(a, b)));
1046
1047
  }
1047
1048
  function fillArray(fillValue, fillCount) {
1048
1049
  if (!isInteger2(fillCount) || fillCount < 0) {
@@ -1505,30 +1506,83 @@ function makeSentenceFromPascal(PascalString) {
1505
1506
  // src/utils/index.ts
1506
1507
  var Is = guard_exports;
1507
1508
 
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
+ }
1521
+
1508
1522
  // src/core/stack.ts
1509
1523
  var Stack = class {
1510
1524
  constructor() {
1511
- __publicField(this, "list", []);
1525
+ __publicField(this, "data", []);
1526
+ }
1527
+ assertId(id) {
1528
+ assert_exports.isIntegerBetween(id, 0, this.length - 1, `Stack index ${id} out of range.`);
1529
+ return id;
1512
1530
  }
1513
- push(e) {
1514
- this.list.push(e);
1515
- return e;
1531
+ get length() {
1532
+ return this.data.length;
1533
+ }
1534
+ push(el) {
1535
+ this.data.push(el);
1536
+ return el;
1516
1537
  }
1517
1538
  pop() {
1518
- assert_exports.int_gt(this.list.length, 0);
1519
- return this.list.pop();
1539
+ this.assertId(this.length - 1);
1540
+ return this.data.pop();
1541
+ }
1542
+ popOrUndef() {
1543
+ return this.data.pop();
1544
+ }
1545
+ popOr(defaultValueOrCreator) {
1546
+ return this.isEmpty() ? isFunction2(defaultValueOrCreator) ? defaultValueOrCreator() : defaultValueOrCreator : this.data.pop();
1520
1547
  }
1521
1548
  top() {
1522
- return assert_exports.array_elem(this.list, this.list.length - 1, "Stack is empty!");
1549
+ return this.data[this.assertId(this.length - 1)];
1550
+ }
1551
+ topOrUndef() {
1552
+ return this.data[this.length - 1];
1553
+ }
1554
+ topOr(defaultValueOrCreator) {
1555
+ return this.isEmpty() ? isFunction2(defaultValueOrCreator) ? defaultValueOrCreator() : defaultValueOrCreator : this.data[this.length - 1];
1556
+ }
1557
+ peek(depth = 0) {
1558
+ return this.data[this.assertId(this.data.length - 1 - depth)];
1559
+ }
1560
+ peekOrUndef(depth = 0) {
1561
+ return this.data[this.data.length - 1 - depth];
1562
+ }
1563
+ peekOr(depth = 0, defaultValueOrCreator) {
1564
+ const id = this.data.length - 1 - depth;
1565
+ const value = id < 0 ? void 0 : this.data[id];
1566
+ return value === void 0 ? isFunction2(defaultValueOrCreator) ? defaultValueOrCreator() : defaultValueOrCreator : value;
1567
+ }
1568
+ *values() {
1569
+ for (let id = this.data.length - 1; id >= 0; id--)
1570
+ yield this.data[id];
1571
+ }
1572
+ *[Symbol.iterator]() {
1573
+ yield* this.values();
1523
1574
  }
1524
1575
  toArray() {
1525
- return this.list;
1576
+ return [...this.data];
1526
1577
  }
1527
- get length() {
1528
- return this.list.length;
1578
+ isEmpty() {
1579
+ return this.length === 0;
1529
1580
  }
1530
1581
  clear() {
1531
- this.list.length = 0;
1582
+ this.data.length = 0;
1583
+ }
1584
+ toString() {
1585
+ return `Stack(${this.length})${formatValue(this.data)}`;
1532
1586
  }
1533
1587
  };
1534
1588
 
@@ -2112,6 +2166,14 @@ var IndexArray = class _IndexArray {
2112
2166
  get size() {
2113
2167
  return this.valCount;
2114
2168
  }
2169
+ get length() {
2170
+ return this.hasPos.length;
2171
+ }
2172
+ trimRight() {
2173
+ let newLength = this.length;
2174
+ while (newLength > 0 && this.hasPos[newLength - 1] !== true) newLength--;
2175
+ if (newLength < this.length) this.posVal.length = this.hasPos.length = newLength;
2176
+ }
2115
2177
  isEmpty() {
2116
2178
  return this.size === 0;
2117
2179
  }
@@ -2146,6 +2208,7 @@ var IndexArray = class _IndexArray {
2146
2208
  this.posVal[id] = void 0;
2147
2209
  this.hasPos[id] = false;
2148
2210
  this.valCount--;
2211
+ this.trimRight();
2149
2212
  return true;
2150
2213
  }
2151
2214
  clear() {
@@ -2282,10 +2345,12 @@ var IndexArray = class _IndexArray {
2282
2345
  }
2283
2346
  return true;
2284
2347
  }
2348
+ toArray() {
2349
+ return this.valuesArray();
2350
+ }
2285
2351
  toString() {
2286
- if (this.size === 0) return `IndexArray[ ]`;
2287
- const entries = this.entriesArray().map(([id, value]) => `${id}: ${value}`).join(", ");
2288
- return `IndexArray[ ${entries} ]`;
2352
+ const entries = this.entriesArray().map(([id, v]) => `${formatValue(id)}: ${formatValue(v)}`).join(", ");
2353
+ return `IndexArray[ ${entries} ]`.replaceAll(" ", " ");
2289
2354
  }
2290
2355
  };
2291
2356
 
@@ -2543,10 +2608,215 @@ var SignedIndexArray = class _SignedIndexArray {
2543
2608
  }
2544
2609
  return true;
2545
2610
  }
2611
+ toArray() {
2612
+ return this.valuesArray();
2613
+ }
2546
2614
  toString() {
2547
- if (this.size === 0) return `SignedIndexArray[ ]`;
2548
- const entries = this.entriesArray().map(([id, value]) => `${id}: ${value}`).join(", ");
2549
- return `SignedIndexArray[ ${entries} ]`;
2615
+ const entries = this.entriesArray().map(([id, v]) => `${formatValue(id)}: ${formatValue(v)}`).join(", ");
2616
+ return `SignedIndexArray[ ${entries} ]`.replaceAll(" ", " ");
2617
+ }
2618
+ };
2619
+
2620
+ // src/core/default-array.ts
2621
+ var DefaultArray = class _DefaultArray {
2622
+ constructor(lengthOrValues, defaultValue) {
2623
+ this.defaultValue = defaultValue;
2624
+ __publicField(this, "data");
2625
+ if (typeof lengthOrValues === "number") {
2626
+ this.data = Array(lengthOrValues).fill(defaultValue);
2627
+ } else {
2628
+ this.data = Array.from(lengthOrValues).map(
2629
+ (v) => v === void 0 ? defaultValue : v
2630
+ );
2631
+ }
2632
+ }
2633
+ get size() {
2634
+ return this.data.length;
2635
+ }
2636
+ get length() {
2637
+ return this.data.length;
2638
+ }
2639
+ assertId(id) {
2640
+ if (id < 0 || id >= this.data.length)
2641
+ throw new RangeError(`DefaultArray: Index ${id} out of range`);
2642
+ return id;
2643
+ }
2644
+ isEmpty() {
2645
+ return this.size === 0;
2646
+ }
2647
+ isDefault(id) {
2648
+ return this.data[this.assertId(id)] === this.defaultValue;
2649
+ }
2650
+ isSet(id) {
2651
+ return this.data[this.assertId(id)] !== this.defaultValue;
2652
+ }
2653
+ /** @internal - This method exists only for interface `KVComponent` compatibility.*/
2654
+ has(id) {
2655
+ return this.isSet(id);
2656
+ }
2657
+ set(id, value) {
2658
+ return this.data[this.assertId(id)] = value;
2659
+ }
2660
+ get(id) {
2661
+ return this.data[this.assertId(id)];
2662
+ }
2663
+ getOrDefault(id, defaultValue) {
2664
+ let value = this.get(id);
2665
+ return value === this.defaultValue ? defaultValue : value;
2666
+ }
2667
+ getOrCreate(id, creatorOrValue) {
2668
+ if (!this.has(id)) {
2669
+ const value = isFunction2(creatorOrValue) ? creatorOrValue() : creatorOrValue;
2670
+ this.set(id, value);
2671
+ return value;
2672
+ }
2673
+ return this.get(id);
2674
+ }
2675
+ delete(id) {
2676
+ this.assertId(id);
2677
+ if (this.data[id] === this.defaultValue) return false;
2678
+ this.data[id] = this.defaultValue;
2679
+ return true;
2680
+ }
2681
+ clear(empty = false) {
2682
+ if (empty)
2683
+ this.data = [];
2684
+ else
2685
+ this.data.fill(this.defaultValue);
2686
+ }
2687
+ forEach(callbackfn, thisArg) {
2688
+ for (const [id, value] of this.entries()) {
2689
+ callbackfn.call(thisArg, value, id, this);
2690
+ }
2691
+ }
2692
+ *indices() {
2693
+ yield* this.data.keys();
2694
+ }
2695
+ *values() {
2696
+ yield* this.data.values();
2697
+ }
2698
+ *entries() {
2699
+ yield* this.data.entries();
2700
+ }
2701
+ indicesArray() {
2702
+ return [...this.indices()];
2703
+ }
2704
+ valuesArray() {
2705
+ return [...this.values()];
2706
+ }
2707
+ entriesArray() {
2708
+ return [...this.entries()];
2709
+ }
2710
+ *kvKeys() {
2711
+ for (const id of this.indices()) {
2712
+ yield [id];
2713
+ }
2714
+ }
2715
+ *kvValues() {
2716
+ for (const value of this.values()) {
2717
+ yield value;
2718
+ }
2719
+ }
2720
+ *kvEntries() {
2721
+ for (const [id, value] of this.entries()) {
2722
+ yield [[id], value];
2723
+ }
2724
+ }
2725
+ *[Symbol.iterator]() {
2726
+ yield* this.entries();
2727
+ }
2728
+ clone() {
2729
+ const ctor = this.constructor;
2730
+ const clone = new ctor(this.length, this.defaultValue);
2731
+ clone.data = this.data.slice();
2732
+ return clone;
2733
+ }
2734
+ merge(other, conflictResolver) {
2735
+ if (this.constructor !== other.constructor)
2736
+ throw new Error(`Cannot merge DefaultArray: different classes (${this.constructor.name} vs ${other.constructor.name})`);
2737
+ if (this.defaultValue !== other.defaultValue)
2738
+ throw new Error(`Cannot merge DefaultArray: different defaultValue (${this.defaultValue} vs ${other.defaultValue})`);
2739
+ for (const [id, value] of other.entries()) {
2740
+ if (this.isDefault(id))
2741
+ this.set(id, value);
2742
+ else if (conflictResolver)
2743
+ this.set(id, conflictResolver(this.get(id), value, id));
2744
+ else
2745
+ this.set(id, value);
2746
+ }
2747
+ return this;
2748
+ }
2749
+ some(fn) {
2750
+ for (const [id, value] of this.entries()) {
2751
+ if (fn(value, id)) return true;
2752
+ }
2753
+ return false;
2754
+ }
2755
+ every(fn) {
2756
+ for (const [id, value] of this.entries()) {
2757
+ if (!fn(value, id)) return false;
2758
+ }
2759
+ return true;
2760
+ }
2761
+ filter(predicate) {
2762
+ const result = new this.constructor(this.length, this.defaultValue);
2763
+ for (const [id, value] of this.entries()) {
2764
+ if (predicate(value, id, this)) result.set(id, value);
2765
+ }
2766
+ return result;
2767
+ }
2768
+ reduce(fn, init) {
2769
+ let iterator = this.entries();
2770
+ let first = iterator.next();
2771
+ if (first.done) {
2772
+ if (arguments.length < 2) {
2773
+ throw new TypeError("Reduce of empty DefaultArray with no initial value!");
2774
+ }
2775
+ return init;
2776
+ }
2777
+ let acc;
2778
+ let start;
2779
+ if (arguments.length < 2) {
2780
+ acc = first.value[1];
2781
+ start = iterator.next();
2782
+ } else {
2783
+ acc = init;
2784
+ start = first;
2785
+ }
2786
+ for (let current = start; !current.done; current = iterator.next()) {
2787
+ const [id, value] = current.value;
2788
+ acc = fn(acc, value, id);
2789
+ }
2790
+ return acc;
2791
+ }
2792
+ mapToArray(fn) {
2793
+ let result = [];
2794
+ for (const [id, value] of this.entries()) {
2795
+ result.push(fn(value, id));
2796
+ }
2797
+ return result;
2798
+ }
2799
+ map(fn, defaultValue) {
2800
+ let result = new _DefaultArray(this.data.length, defaultValue);
2801
+ for (let id = 0; id < this.data.length; id++) {
2802
+ result.data[id] = fn(this.data[id], id);
2803
+ }
2804
+ return result;
2805
+ }
2806
+ equals(other, eq2) {
2807
+ if (this.size !== other.size) return false;
2808
+ eq2 ?? (eq2 = (a, b) => a === b);
2809
+ for (let id = 0; id < this.data.length; ++id) {
2810
+ if (!eq2(this.data[id], other.data[id])) return false;
2811
+ }
2812
+ return true;
2813
+ }
2814
+ toArray() {
2815
+ return this.valuesArray();
2816
+ }
2817
+ toString() {
2818
+ const entries = this.entriesArray().map(([id, v]) => `${formatValue(id)}: ${formatValue(v)}`).join(", ");
2819
+ return `DefaultArray[ ${entries} ]`.replaceAll(" ", " ");
2550
2820
  }
2551
2821
  };
2552
2822
 
@@ -2703,8 +2973,8 @@ var Map1 = class _Map1 {
2703
2973
  return new Map(this.map1);
2704
2974
  }
2705
2975
  toString() {
2706
- const entries = [...this.map1].map(([k, v]) => `${k} => ${v}`).join(", ");
2707
- return entries.length === 0 ? `Map1(0){ }` : `Map1(${this.size}){ ${entries} }`;
2976
+ const entries = [...this.map1].map(([k, v]) => `${formatValue(k)} => ${formatValue(v)}`).join(", ");
2977
+ return `Map1(${this.size}){ ${entries} }`.replaceAll(" ", " ");
2708
2978
  }
2709
2979
  };
2710
2980
 
@@ -2897,10 +3167,10 @@ var Map2 = class _Map2 {
2897
3167
  toString() {
2898
3168
  const entries = [];
2899
3169
  for (const [key1, map2] of this.map1) {
2900
- const inner = [...map2].map(([key2, v]) => `${key2} => ${v}`).join(", ");
2901
- entries.push(`${key1} => { ${inner} }`);
3170
+ const inner = [...map2].map(([key2, v]) => `${formatValue(key2)} => ${formatValue(v)}`).join(", ");
3171
+ entries.push(`${formatValue(key1)} => { ${inner} }`);
2902
3172
  }
2903
- return entries.length === 0 ? `Map2(0){ }` : `Map2(${this.size}){ ${entries} }`;
3173
+ return `Map2(${this.size}){ ${entries} }`.replaceAll(" ", " ");
2904
3174
  }
2905
3175
  };
2906
3176
 
@@ -3125,11 +3395,209 @@ var Map3 = class _Map3 {
3125
3395
  const entries = [];
3126
3396
  for (const [key1, map2] of this.map1) {
3127
3397
  for (const [key2, map3] of map2) {
3128
- const inner = [...map3].map(([key3, v]) => `${key3} => ${v}`).join(", ");
3129
- entries.push(`${key1} => ${key2} => { ${inner} }`);
3398
+ const inner = [...map3].map(([key3, v]) => `${formatValue(key3)} => ${formatValue(v)}`).join(", ");
3399
+ entries.push(`${formatValue(key1)} => ${formatValue(key2)} => { ${inner} }`);
3400
+ }
3401
+ }
3402
+ return `Map3(${this.size}){ ${entries.join(", ")} }`.replaceAll(" ", " ");
3403
+ }
3404
+ };
3405
+
3406
+ // src/core/set.ts
3407
+ var SetBase = class {
3408
+ constructor(entries) {
3409
+ __publicField(this, "data");
3410
+ this.data = new Set(entries ?? []);
3411
+ }
3412
+ has(value) {
3413
+ return this.some((v) => this.valueEquals(v, value));
3414
+ }
3415
+ add(value) {
3416
+ if (!this.has(value))
3417
+ this.data.add(value);
3418
+ return value;
3419
+ }
3420
+ /** @internal - This method exists only for interface `KVComponent` compatibility.*/
3421
+ set(key, value) {
3422
+ if (!this.valueEquals(key, value))
3423
+ throw new TypeError("SetBase.set() requires key === value.");
3424
+ this.add(value);
3425
+ }
3426
+ /** @internal - This method exists only for interface `KVComponent` compatibility.*/
3427
+ get(key) {
3428
+ return this.has(key) ? key : void 0;
3429
+ }
3430
+ /** @internal - This method exists only for interface `KVComponent` compatibility.*/
3431
+ getOrDefault(key, defaultValue) {
3432
+ return this.get(key) ?? defaultValue;
3433
+ }
3434
+ getOrCreate(key, creatorOrValue) {
3435
+ if (!this.has(key)) {
3436
+ const value = isFunction2(creatorOrValue) ? creatorOrValue() : creatorOrValue;
3437
+ this.set(key, value);
3438
+ return value;
3439
+ }
3440
+ return this.get(key);
3441
+ }
3442
+ delete(value) {
3443
+ if (!this.has(value)) return false;
3444
+ for (const v of this.values()) {
3445
+ if (this.valueEquals(v, value)) {
3446
+ this.data.delete(v);
3447
+ return true;
3448
+ }
3449
+ }
3450
+ return false;
3451
+ }
3452
+ clear() {
3453
+ this.data.clear();
3454
+ }
3455
+ get size() {
3456
+ return this.data.size;
3457
+ }
3458
+ isEmpty() {
3459
+ return this.size === 0;
3460
+ }
3461
+ forEach(callbackfn, thisArg) {
3462
+ this.data.forEach((value) => callbackfn.call(thisArg, value, this));
3463
+ }
3464
+ *keys() {
3465
+ yield* this.data.keys();
3466
+ }
3467
+ *values() {
3468
+ yield* this.data.values();
3469
+ }
3470
+ *entries() {
3471
+ yield* this.data.entries();
3472
+ }
3473
+ *kvKeys() {
3474
+ for (const key of this.keys()) {
3475
+ yield [key];
3476
+ }
3477
+ }
3478
+ *kvValues() {
3479
+ for (const el of this.values()) {
3480
+ yield el;
3481
+ }
3482
+ }
3483
+ *kvEntries() {
3484
+ for (const [key, el] of this.entries()) {
3485
+ yield [[key], el];
3486
+ }
3487
+ }
3488
+ *[Symbol.iterator]() {
3489
+ yield* this.values();
3490
+ }
3491
+ clone() {
3492
+ const result = this.createEmpty();
3493
+ for (const v of this.values()) result.add(v);
3494
+ return result;
3495
+ }
3496
+ merge(other) {
3497
+ for (const value of other.values()) {
3498
+ this.add(value);
3499
+ }
3500
+ return this;
3501
+ }
3502
+ some(fn) {
3503
+ for (const value of this.data) {
3504
+ if (fn(value)) return true;
3505
+ }
3506
+ return false;
3507
+ }
3508
+ every(fn) {
3509
+ for (const value of this.data) {
3510
+ if (!fn(value)) return false;
3511
+ }
3512
+ return true;
3513
+ }
3514
+ filter(predicate) {
3515
+ const result = this.createEmpty();
3516
+ for (const value of this.data)
3517
+ if (predicate(value, this)) result.add(value);
3518
+ return result;
3519
+ }
3520
+ reduce(fn, init) {
3521
+ let iterator = this.values();
3522
+ let first = iterator.next();
3523
+ if (first.done) {
3524
+ if (arguments.length < 2) {
3525
+ throw new TypeError("Reduce of empty SetBase with no initial value!");
3130
3526
  }
3527
+ return init;
3131
3528
  }
3132
- return entries.length === 0 ? `Map3(0){ }` : `Map3(${this.size}){ ${entries.join(", ")} }`;
3529
+ let acc;
3530
+ let start;
3531
+ if (arguments.length < 2) {
3532
+ acc = first.value;
3533
+ start = iterator.next();
3534
+ } else {
3535
+ acc = init;
3536
+ start = first;
3537
+ }
3538
+ for (let current = start; !current.done; current = iterator.next()) {
3539
+ const value = current.value;
3540
+ acc = fn(acc, value);
3541
+ }
3542
+ return acc;
3543
+ }
3544
+ mapValues(fn) {
3545
+ let result = this.createEmpty();
3546
+ for (const value of this.data) {
3547
+ result.add(fn(value));
3548
+ }
3549
+ return result;
3550
+ }
3551
+ mapToArray(fn) {
3552
+ let result = [];
3553
+ for (const value of this.values()) {
3554
+ result.push(fn(value));
3555
+ }
3556
+ return result;
3557
+ }
3558
+ map(fn) {
3559
+ let result = this.createEmpty();
3560
+ for (const value of this.values()) {
3561
+ result.add(fn(value));
3562
+ }
3563
+ return result;
3564
+ }
3565
+ toSet() {
3566
+ return new Set(this.data);
3567
+ }
3568
+ toArray() {
3569
+ return [...this.values()];
3570
+ }
3571
+ 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";
3133
3601
  }
3134
3602
  };
3135
3603
 
@@ -3191,11 +3659,11 @@ var MultiContainer = class {
3191
3659
  const entries = [];
3192
3660
  for (const keys of this.keys()) {
3193
3661
  const arr = this.getAll(...keys);
3194
- const keyStr = Array.isArray(keys) ? `[${keys.map((k) => JSON.stringify(k)).join(", ")}]` : `[${JSON.stringify(keys)}]`;
3195
- const valuesStr = Array.isArray(arr) ? `[${arr.map((v) => JSON.stringify(v)).join(", ")}]` : "[]";
3662
+ const keyStr = Array.isArray(keys) ? formatValue(keys) : "[ ]";
3663
+ const valuesStr = Array.isArray(arr) ? formatValue(arr) : "[ ]";
3196
3664
  entries.push(`${keyStr} => ${valuesStr}`);
3197
3665
  }
3198
- return `MultiContainer{ ${entries.join(", ")} }`;
3666
+ return `MultiContainer{ ${entries.join(", ")} }`.replaceAll(" ", " ");
3199
3667
  }
3200
3668
  };
3201
3669
  function asMulti(base) {
@@ -3282,6 +3750,8 @@ var SmallIntCache = class {
3282
3750
  0 && (module.exports = {
3283
3751
  Assert,
3284
3752
  Cookies,
3753
+ DeepSet,
3754
+ DefaultArray,
3285
3755
  Device,
3286
3756
  DivRect,
3287
3757
  Guard,
@@ -3291,6 +3761,8 @@ var SmallIntCache = class {
3291
3761
  Map2,
3292
3762
  Map3,
3293
3763
  MultiContainer,
3764
+ Set1,
3765
+ SetBase,
3294
3766
  SignedIndexArray,
3295
3767
  SmallIntCache,
3296
3768
  Stack,