@dxos/util 0.8.4-main.e098934 → 0.8.4-main.e250131250

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.
Files changed (74) hide show
  1. package/dist/lib/browser/index.mjs +485 -483
  2. package/dist/lib/browser/index.mjs.map +4 -4
  3. package/dist/lib/browser/meta.json +1 -1
  4. package/dist/lib/node-esm/index.mjs +485 -483
  5. package/dist/lib/node-esm/index.mjs.map +4 -4
  6. package/dist/lib/node-esm/meta.json +1 -1
  7. package/dist/types/src/array.d.ts +3 -2
  8. package/dist/types/src/array.d.ts.map +1 -1
  9. package/dist/types/src/circular-buffer.d.ts +1 -0
  10. package/dist/types/src/circular-buffer.d.ts.map +1 -1
  11. package/dist/types/src/composite-key.d.ts +10 -0
  12. package/dist/types/src/composite-key.d.ts.map +1 -0
  13. package/dist/types/src/composite-key.test.d.ts +2 -0
  14. package/dist/types/src/composite-key.test.d.ts.map +1 -0
  15. package/dist/types/src/deep.d.ts +0 -3
  16. package/dist/types/src/deep.d.ts.map +1 -1
  17. package/dist/types/src/defer.d.ts +1 -1
  18. package/dist/types/src/defer.d.ts.map +1 -1
  19. package/dist/types/src/di-key.d.ts +3 -3
  20. package/dist/types/src/di-key.d.ts.map +1 -1
  21. package/dist/types/src/error-format.d.ts +5 -0
  22. package/dist/types/src/error-format.d.ts.map +1 -0
  23. package/dist/types/src/filename.d.ts +9 -0
  24. package/dist/types/src/filename.d.ts.map +1 -0
  25. package/dist/types/src/index.d.ts +5 -1
  26. package/dist/types/src/index.d.ts.map +1 -1
  27. package/dist/types/src/platform.d.ts +4 -1
  28. package/dist/types/src/platform.d.ts.map +1 -1
  29. package/dist/types/src/retry.d.ts +32 -0
  30. package/dist/types/src/retry.d.ts.map +1 -0
  31. package/dist/types/src/safe-parse.d.ts +7 -4
  32. package/dist/types/src/safe-parse.d.ts.map +1 -1
  33. package/dist/types/src/safe-stringify.d.ts +22 -0
  34. package/dist/types/src/safe-stringify.d.ts.map +1 -0
  35. package/dist/types/src/safe-stringify.test.d.ts +2 -0
  36. package/dist/types/src/safe-stringify.test.d.ts.map +1 -0
  37. package/dist/types/src/string.d.ts +4 -0
  38. package/dist/types/src/string.d.ts.map +1 -1
  39. package/dist/types/src/to-fallback.d.ts +18 -4
  40. package/dist/types/src/to-fallback.d.ts.map +1 -1
  41. package/dist/types/src/types.d.ts +24 -7
  42. package/dist/types/src/types.d.ts.map +1 -1
  43. package/dist/types/src/unit.d.ts +12 -13
  44. package/dist/types/src/unit.d.ts.map +1 -1
  45. package/dist/types/tsconfig.tsbuildinfo +1 -1
  46. package/package.json +12 -11
  47. package/src/array.ts +9 -2
  48. package/src/binder.ts +2 -2
  49. package/src/circular-buffer.test.ts +26 -0
  50. package/src/circular-buffer.ts +5 -0
  51. package/src/composite-key.test.ts +31 -0
  52. package/src/composite-key.ts +16 -0
  53. package/src/deep.ts +2 -6
  54. package/src/defer.ts +1 -1
  55. package/src/error-format.ts +22 -0
  56. package/src/filename.ts +16 -0
  57. package/src/index.ts +5 -1
  58. package/src/platform.ts +35 -3
  59. package/src/retry.ts +74 -0
  60. package/src/safe-parse.ts +27 -16
  61. package/src/safe-stringify.test.ts +96 -0
  62. package/src/safe-stringify.ts +153 -0
  63. package/src/string.ts +7 -0
  64. package/src/to-fallback.ts +44 -160
  65. package/src/types.test.ts +11 -1
  66. package/src/types.ts +40 -13
  67. package/src/unit.test.ts +1 -1
  68. package/src/unit.ts +59 -28
  69. package/dist/types/src/explicit-resource-management-polyfill.d.ts +0 -1
  70. package/dist/types/src/explicit-resource-management-polyfill.d.ts.map +0 -1
  71. package/dist/types/src/first-two-chars.d.ts +0 -9
  72. package/dist/types/src/first-two-chars.d.ts.map +0 -1
  73. package/src/explicit-resource-management-polyfill.ts +0 -13
  74. package/src/first-two-chars.ts +0 -44
@@ -97,16 +97,24 @@ var intersectBy = (arrays, selector) => {
97
97
  return lookups.every((lookup) => lookup.has(key));
98
98
  });
99
99
  };
100
+ var coerceArray = (arr) => {
101
+ if (arr === void 0) {
102
+ return [];
103
+ }
104
+ return Array.isArray(arr) ? arr : [
105
+ arr
106
+ ];
107
+ };
100
108
 
101
109
  // src/assume.ts
102
110
  function assumeType(value) {
103
111
  }
104
112
 
105
113
  // src/binder.ts
106
- import util from "@dxos/node-std/util";
114
+ import { promisify } from "@dxos/node-std/util";
107
115
  var createBinder = (obj) => ({
108
116
  fn: (fn) => fn.bind(obj),
109
- async: (fn) => util.promisify(fn.bind(obj))
117
+ async: (fn) => promisify(fn.bind(obj))
110
118
  });
111
119
 
112
120
  // src/bitfield.ts
@@ -180,92 +188,34 @@ var BitField = class _BitField {
180
188
  };
181
189
 
182
190
  // src/callback-collection.ts
183
- function _check_private_redeclaration(obj, privateCollection) {
184
- if (privateCollection.has(obj)) {
185
- throw new TypeError("Cannot initialize the same private elements twice on an object");
186
- }
187
- }
188
- function _class_apply_descriptor_get(receiver, descriptor) {
189
- if (descriptor.get) {
190
- return descriptor.get.call(receiver);
191
- }
192
- return descriptor.value;
193
- }
194
- function _class_apply_descriptor_set(receiver, descriptor, value) {
195
- if (descriptor.set) {
196
- descriptor.set.call(receiver, value);
197
- } else {
198
- if (!descriptor.writable) {
199
- throw new TypeError("attempted to set read only private field");
200
- }
201
- descriptor.value = value;
202
- }
203
- }
204
- function _class_extract_field_descriptor(receiver, privateMap, action) {
205
- if (!privateMap.has(receiver)) {
206
- throw new TypeError("attempted to " + action + " private field on non-instance");
207
- }
208
- return privateMap.get(receiver);
209
- }
210
- function _class_private_field_get(receiver, privateMap) {
211
- var descriptor = _class_extract_field_descriptor(receiver, privateMap, "get");
212
- return _class_apply_descriptor_get(receiver, descriptor);
213
- }
214
- function _class_private_field_init(obj, privateMap, value) {
215
- _check_private_redeclaration(obj, privateMap);
216
- privateMap.set(obj, value);
217
- }
218
- function _class_private_field_set(receiver, privateMap, value) {
219
- var descriptor = _class_extract_field_descriptor(receiver, privateMap, "set");
220
- _class_apply_descriptor_set(receiver, descriptor, value);
221
- return value;
222
- }
223
- var _callbacks = /* @__PURE__ */ new WeakMap();
224
191
  var CallbackCollection = class {
192
+ #callbacks = [];
225
193
  append(callback) {
226
- _class_private_field_get(this, _callbacks).push(callback);
194
+ this.#callbacks.push(callback);
227
195
  }
228
196
  prepend(callback) {
229
- _class_private_field_get(this, _callbacks).unshift(callback);
197
+ this.#callbacks.unshift(callback);
230
198
  }
231
199
  remove(callback) {
232
- _class_private_field_set(this, _callbacks, _class_private_field_get(this, _callbacks).filter((c) => c !== callback));
200
+ this.#callbacks = this.#callbacks.filter((c) => c !== callback);
233
201
  }
234
202
  callParallel(...args) {
235
- return Promise.all(_class_private_field_get(this, _callbacks).map((callback) => callback(...args)));
203
+ return Promise.all(this.#callbacks.map((callback) => callback(...args)));
236
204
  }
237
205
  async callSerial(...args) {
238
206
  const results = [];
239
- for (const callback of _class_private_field_get(this, _callbacks)) {
207
+ for (const callback of this.#callbacks) {
240
208
  results.push(await callback(...args));
241
209
  }
242
210
  return results;
243
211
  }
244
- constructor() {
245
- _class_private_field_init(this, _callbacks, {
246
- writable: true,
247
- value: []
248
- });
249
- }
250
212
  };
251
213
 
252
214
  // src/callback.ts
253
215
  import { invariant as invariant2 } from "@dxos/invariant";
254
- function _define_property(obj, key, value) {
255
- if (key in obj) {
256
- Object.defineProperty(obj, key, {
257
- value,
258
- enumerable: true,
259
- configurable: true,
260
- writable: true
261
- });
262
- } else {
263
- obj[key] = value;
264
- }
265
- return obj;
266
- }
267
216
  var __dxlog_file2 = "/__w/dxos/dxos/packages/common/util/src/callback.ts";
268
217
  var Callback = class {
218
+ _callback;
269
219
  call(...args) {
270
220
  invariant2(this._callback, "Callback not set", {
271
221
  F: __dxlog_file2,
@@ -296,9 +246,6 @@ var Callback = class {
296
246
  isSet() {
297
247
  return !!this._callback;
298
248
  }
299
- constructor() {
300
- _define_property(this, "_callback", void 0);
301
- }
302
249
  };
303
250
  var createSetDispatch = ({ handlers }) => {
304
251
  return new Proxy({
@@ -361,21 +308,23 @@ var chunkArray = (array, size) => {
361
308
 
362
309
  // src/circular-buffer.ts
363
310
  import { invariant as invariant3 } from "@dxos/invariant";
364
- function _define_property2(obj, key, value) {
365
- if (key in obj) {
366
- Object.defineProperty(obj, key, {
367
- value,
368
- enumerable: true,
369
- configurable: true,
370
- writable: true
371
- });
372
- } else {
373
- obj[key] = value;
374
- }
375
- return obj;
376
- }
377
311
  var __dxlog_file3 = "/__w/dxos/dxos/packages/common/util/src/circular-buffer.ts";
378
312
  var CircularBuffer = class {
313
+ _buffer;
314
+ _nextIndex = 0;
315
+ _elementCount = 0;
316
+ constructor(size) {
317
+ invariant3(size >= 1, void 0, {
318
+ F: __dxlog_file3,
319
+ L: 13,
320
+ S: this,
321
+ A: [
322
+ "size >= 1",
323
+ ""
324
+ ]
325
+ });
326
+ this._buffer = new Array(size);
327
+ }
379
328
  push(element) {
380
329
  const evicted = this._elementCount === this._buffer.length ? this._buffer[this._nextIndex] : void 0;
381
330
  this._buffer[this._nextIndex] = element;
@@ -386,6 +335,10 @@ var CircularBuffer = class {
386
335
  get elementCount() {
387
336
  return this._elementCount;
388
337
  }
338
+ clear() {
339
+ this._nextIndex = 0;
340
+ this._elementCount = 0;
341
+ }
389
342
  getLast() {
390
343
  if (this._elementCount === 0) {
391
344
  return void 0;
@@ -415,21 +368,6 @@ var CircularBuffer = class {
415
368
  yield this._buffer[i];
416
369
  }
417
370
  }
418
- constructor(size) {
419
- _define_property2(this, "_buffer", void 0);
420
- _define_property2(this, "_nextIndex", 0);
421
- _define_property2(this, "_elementCount", 0);
422
- invariant3(size >= 1, void 0, {
423
- F: __dxlog_file3,
424
- L: 13,
425
- S: this,
426
- A: [
427
- "size >= 1",
428
- ""
429
- ]
430
- });
431
- this._buffer = new Array(size);
432
- }
433
371
  };
434
372
 
435
373
  // src/clear-undefined.ts
@@ -448,22 +386,19 @@ var clearUndefined = (obj) => {
448
386
  // src/complex.ts
449
387
  import { inspect } from "@dxos/node-std/util";
450
388
  import { inspectObject, raise } from "@dxos/debug";
451
- function _define_property3(obj, key, value) {
452
- if (key in obj) {
453
- Object.defineProperty(obj, key, {
454
- value,
455
- enumerable: true,
456
- configurable: true,
457
- writable: true
458
- });
459
- } else {
460
- obj[key] = value;
461
- }
462
- return obj;
463
- }
464
389
  var MAX_SERIALIZATION_LENGTH = 10;
465
- var _inspect_custom = inspect.custom;
466
390
  var ComplexSet = class {
391
+ _projection;
392
+ _values = /* @__PURE__ */ new Map();
393
+ // prettier-ignore
394
+ constructor(_projection, values) {
395
+ this._projection = _projection;
396
+ if (values) {
397
+ for (const value of values) {
398
+ this.add(value);
399
+ }
400
+ }
401
+ }
467
402
  toString() {
468
403
  return inspectObject(this);
469
404
  }
@@ -472,7 +407,7 @@ var ComplexSet = class {
472
407
  size: this._values.size
473
408
  } : Array.from(this._values.values());
474
409
  }
475
- [_inspect_custom]() {
410
+ [inspect.custom]() {
476
411
  return inspectObject(this);
477
412
  }
478
413
  add(value) {
@@ -538,18 +473,6 @@ var ComplexSet = class {
538
473
  isDisjointFrom(other) {
539
474
  throw new Error("Method not implemented.");
540
475
  }
541
- // prettier-ignore
542
- constructor(_projection, values) {
543
- _define_property3(this, "_projection", void 0);
544
- _define_property3(this, "_values", void 0);
545
- this._projection = _projection;
546
- this._values = /* @__PURE__ */ new Map();
547
- if (values) {
548
- for (const value of values) {
549
- this.add(value);
550
- }
551
- }
552
- }
553
476
  };
554
477
  var makeSet = (projection) => {
555
478
  return class BoundComplexSet extends ComplexSet {
@@ -558,8 +481,19 @@ var makeSet = (projection) => {
558
481
  }
559
482
  };
560
483
  };
561
- var _inspect_custom1 = inspect.custom;
562
484
  var ComplexMap = class _ComplexMap {
485
+ _keyProjection;
486
+ _keys = /* @__PURE__ */ new Map();
487
+ _values = /* @__PURE__ */ new Map();
488
+ // prettier-ignore
489
+ constructor(_keyProjection, entries2) {
490
+ this._keyProjection = _keyProjection;
491
+ if (entries2) {
492
+ for (const [key, value] of entries2) {
493
+ this.set(key, value);
494
+ }
495
+ }
496
+ }
563
497
  toString() {
564
498
  return inspectObject(this);
565
499
  }
@@ -568,7 +502,7 @@ var ComplexMap = class _ComplexMap {
568
502
  size: this._values.size
569
503
  } : Array.from(this._values.values());
570
504
  }
571
- [_inspect_custom1]() {
505
+ [inspect.custom]() {
572
506
  return inspectObject(this);
573
507
  }
574
508
  clear() {
@@ -630,39 +564,25 @@ var ComplexMap = class _ComplexMap {
630
564
  get [Symbol.toStringTag]() {
631
565
  return "ComplexMap";
632
566
  }
633
- // prettier-ignore
634
- constructor(_keyProjection, entries2) {
635
- _define_property3(this, "_keyProjection", void 0);
636
- _define_property3(this, "_keys", void 0);
637
- _define_property3(this, "_values", void 0);
638
- this._keyProjection = _keyProjection;
639
- this._keys = /* @__PURE__ */ new Map();
640
- this._values = /* @__PURE__ */ new Map();
641
- if (entries2) {
642
- for (const [key, value] of entries2) {
643
- this.set(key, value);
644
- }
645
- }
646
- }
647
567
  };
648
- var makeMap = (keyProjection) => {
649
- class BoundComplexMap extends ComplexMap {
650
- constructor(entries2) {
651
- super(keyProjection, entries2);
652
- }
568
+ var makeMap = (keyProjection) => class BoundComplexMap extends ComplexMap {
569
+ constructor(entries2) {
570
+ super(keyProjection, entries2);
653
571
  }
654
- return BoundComplexMap;
655
572
  };
656
573
 
574
+ // src/composite-key.ts
575
+ var SEPARATOR = ":";
576
+ var compositeKey = (...parts) => parts.join(SEPARATOR);
577
+ var splitCompositeKey = (key) => key.split(SEPARATOR);
578
+
657
579
  // src/deep.ts
658
- import get from "lodash.get";
659
- import set from "lodash.set";
660
580
  import { invariant as invariant4 } from "@dxos/invariant";
661
581
  var __dxlog_file4 = "/__w/dxos/dxos/packages/common/util/src/deep.ts";
662
582
  var setDeep = (obj, path, value) => {
663
583
  invariant4(path.length > 0, void 0, {
664
584
  F: __dxlog_file4,
665
- L: 18,
585
+ L: 12,
666
586
  S: void 0,
667
587
  A: [
668
588
  "path.length > 0",
@@ -691,72 +611,51 @@ var getDeep = (obj, path) => {
691
611
  // src/defer-function.ts
692
612
  var deferFunction = (fnProvider) => (...args) => fnProvider()(...args);
693
613
 
694
- // src/explicit-resource-management-polyfill.ts
695
- var _Symbol;
696
- var _Symbol1;
697
- (_Symbol = Symbol).dispose ?? (_Symbol.dispose = Symbol("Symbol.dispose"));
698
- (_Symbol1 = Symbol).asyncDispose ?? (_Symbol1.asyncDispose = Symbol("Symbol.asyncDispose"));
699
-
700
614
  // src/defer.ts
701
- function _define_property4(obj, key, value) {
702
- if (key in obj) {
703
- Object.defineProperty(obj, key, {
704
- value,
705
- enumerable: true,
706
- configurable: true,
707
- writable: true
708
- });
709
- } else {
710
- obj[key] = value;
711
- }
712
- return obj;
713
- }
615
+ import "@hazae41/symbol-dispose-polyfill";
714
616
  var defer = (fn) => new DeferGuard(fn);
715
617
  var DeferGuard = class {
716
- [Symbol.dispose]() {
717
- const result = this._fn();
718
- if (result instanceof Promise) {
719
- throw new Error("Async functions in defer are not supported. Use deferAsync instead.");
720
- }
721
- }
618
+ _fn;
722
619
  /**
723
620
  * @internal
724
621
  */
725
622
  constructor(_fn) {
726
- _define_property4(this, "_fn", void 0);
727
623
  this._fn = _fn;
728
624
  }
625
+ [Symbol.dispose]() {
626
+ const result = this._fn();
627
+ if (result instanceof Promise) {
628
+ throw new Error("Async functions in defer are not supported. Use deferAsync instead.");
629
+ }
630
+ }
729
631
  };
730
632
  var deferAsync = (fn) => new DeferAsyncGuard(fn);
731
633
  var DeferAsyncGuard = class {
732
- async [Symbol.asyncDispose]() {
733
- await this._fn();
734
- }
634
+ _fn;
735
635
  /**
736
636
  * @internal
737
637
  */
738
638
  constructor(_fn) {
739
- _define_property4(this, "_fn", void 0);
740
639
  this._fn = _fn;
741
640
  }
641
+ async [Symbol.asyncDispose]() {
642
+ await this._fn();
643
+ }
742
644
  };
743
645
 
744
646
  // src/entry.ts
745
- function _define_property5(obj, key, value) {
746
- if (key in obj) {
747
- Object.defineProperty(obj, key, {
748
- value,
749
- enumerable: true,
750
- configurable: true,
751
- writable: true
752
- });
753
- } else {
754
- obj[key] = value;
755
- }
756
- return obj;
757
- }
758
647
  var entry = (map, key) => new MapEntry(map, key);
759
648
  var MapEntry = class {
649
+ _map;
650
+ _key;
651
+ /**
652
+ * @internal
653
+ */
654
+ // prettier-ignore
655
+ constructor(_map, _key) {
656
+ this._map = _map;
657
+ this._key = _key;
658
+ }
760
659
  get key() {
761
660
  return this._key;
762
661
  }
@@ -772,63 +671,19 @@ var MapEntry = class {
772
671
  deep(key) {
773
672
  return entry(this.value, key);
774
673
  }
775
- /**
776
- * @internal
777
- */
778
- // prettier-ignore
779
- constructor(_map, _key) {
780
- _define_property5(this, "_map", void 0);
781
- _define_property5(this, "_key", void 0);
782
- this._map = _map;
783
- this._key = _key;
784
- }
785
674
  };
786
675
 
787
- // src/first-two-chars.ts
788
- var renderableCharRegex = /^(?![\p{Control}\p{Mark}\p{Separator}\p{Surrogate}\p{Unassigned}\p{P}])[\p{L}\p{N}\p{S}\p{Emoji}]$/u;
789
- var getFirstTwoRenderableChars = (label) => {
790
- const characters = Array.from(label);
791
- const result = [
792
- "",
793
- ""
794
- ];
795
- let foundFirst = false;
796
- for (let i = 0; i < characters.length; i++) {
797
- const char = characters[i];
798
- if (renderableCharRegex.test(char)) {
799
- if (!foundFirst) {
800
- result[0] = char;
801
- foundFirst = true;
802
- } else {
803
- const textBetween = characters.slice(result[0].length, i).join("");
804
- if (/[^\p{L}\p{N}_]/u.test(textBetween)) {
805
- result[1] = char;
806
- break;
807
- }
808
- }
809
- }
810
- }
811
- return result;
812
- };
676
+ // src/filename.ts
677
+ var createFilename = ({ parts = [], ext, date = /* @__PURE__ */ new Date() }) => [
678
+ date.toISOString().replace(/[:.]/g, "-"),
679
+ ...parts
680
+ ].join("_") + (ext ? `.${ext}` : "");
813
681
 
814
682
  // src/for-each-async.ts
815
683
  var forEachAsync = (items, fn) => Promise.all(items.map(fn));
816
684
 
817
685
  // src/human-hash.ts
818
686
  import { PublicKey } from "@dxos/keys";
819
- function _define_property6(obj, key, value) {
820
- if (key in obj) {
821
- Object.defineProperty(obj, key, {
822
- value,
823
- enumerable: true,
824
- configurable: true,
825
- writable: true
826
- });
827
- } else {
828
- obj[key] = value;
829
- }
830
- return obj;
831
- }
832
687
  var DEFAULT_WORDLIST = [
833
688
  "ack",
834
689
  "alabama",
@@ -1088,6 +943,27 @@ var DEFAULT_WORDLIST = [
1088
943
  "zulu"
1089
944
  ];
1090
945
  var HumanHasher = class {
946
+ wordlist;
947
+ /**
948
+ * Transforms hex digests to human-readable strings.
949
+ *
950
+ * The format of these strings will look something like:
951
+ * `victor-bacon-zulu-lima`. The output is obtained by compressing the input
952
+ * digest to a fixed number of bytes, then mapping those bytes to one of 256
953
+ * words. A default wordlist is provided, but you can override this if you
954
+ * prefer.
955
+ * As long as you use the same wordlist, the output will be consistent (i.e.
956
+ * the same digest will always render the same representation).
957
+ *
958
+ * @param wordlist A list of exactly 256 words to choose from
959
+ */
960
+ constructor(wordlist = DEFAULT_WORDLIST) {
961
+ this.wordlist = wordlist;
962
+ if (wordlist.length !== 256) {
963
+ throw new Error("Wordlist must have exactly 256 items");
964
+ }
965
+ this.wordlist = wordlist;
966
+ }
1091
967
  /**
1092
968
  * Humanize a given hexadecimal digest.
1093
969
  *
@@ -1127,27 +1003,6 @@ var HumanHasher = class {
1127
1003
  const checksums = segments.map((x) => x.reduce((acc, curr) => acc ^ curr));
1128
1004
  return checksums;
1129
1005
  }
1130
- /**
1131
- * Transforms hex digests to human-readable strings.
1132
- *
1133
- * The format of these strings will look something like:
1134
- * `victor-bacon-zulu-lima`. The output is obtained by compressing the input
1135
- * digest to a fixed number of bytes, then mapping those bytes to one of 256
1136
- * words. A default wordlist is provided, but you can override this if you
1137
- * prefer.
1138
- * As long as you use the same wordlist, the output will be consistent (i.e.
1139
- * the same digest will always render the same representation).
1140
- *
1141
- * @param wordlist A list of exactly 256 words to choose from
1142
- */
1143
- constructor(wordlist = DEFAULT_WORDLIST) {
1144
- _define_property6(this, "wordlist", void 0);
1145
- this.wordlist = wordlist;
1146
- if (wordlist.length !== 256) {
1147
- throw new Error("Wordlist must have exactly 256 items");
1148
- }
1149
- this.wordlist = wordlist;
1150
- }
1151
1006
  };
1152
1007
  var hasher = new HumanHasher();
1153
1008
  var humanize = (value) => {
@@ -1170,10 +1025,8 @@ var defaultMap = (map, key, def) => {
1170
1025
  };
1171
1026
 
1172
1027
  // src/instance-id.ts
1173
- var _globalThis;
1174
- var _symbol;
1175
- var symbol = Symbol.for("dxos.instance-contexts");
1176
- var instanceContexts = (_globalThis = globalThis)[_symbol = symbol] ?? (_globalThis[_symbol] = /* @__PURE__ */ new WeakMap());
1028
+ var symbol = /* @__PURE__ */ Symbol.for("dxos.instance-contexts");
1029
+ var instanceContexts = globalThis[symbol] ??= /* @__PURE__ */ new WeakMap();
1177
1030
  var getPrototypeSpecificInstanceId = (instance) => {
1178
1031
  const prototype = Object.getPrototypeOf(instance);
1179
1032
  const instanceCtx = defaultMap(instanceContexts, prototype, () => ({
@@ -1345,19 +1198,6 @@ var jsonKeyReplacer = (options = {}) => (key, value) => {
1345
1198
  };
1346
1199
 
1347
1200
  // src/map-values.ts
1348
- function _define_property7(obj, key, value) {
1349
- if (key in obj) {
1350
- Object.defineProperty(obj, key, {
1351
- value,
1352
- enumerable: true,
1353
- configurable: true,
1354
- writable: true
1355
- });
1356
- } else {
1357
- obj[key] = value;
1358
- }
1359
- return obj;
1360
- }
1361
1201
  var mapValues = (obj, fn) => {
1362
1202
  const result = {};
1363
1203
  Object.keys(obj).forEach((key) => {
@@ -1369,6 +1209,11 @@ var deepMapValues = (value, fn) => {
1369
1209
  return new DeepMapper(fn).map(value);
1370
1210
  };
1371
1211
  var DeepMapper = class {
1212
+ _fn;
1213
+ _cyclic = /* @__PURE__ */ new Map();
1214
+ constructor(_fn) {
1215
+ this._fn = _fn;
1216
+ }
1372
1217
  map(value) {
1373
1218
  return this._map(value, void 0);
1374
1219
  }
@@ -1378,40 +1223,38 @@ var DeepMapper = class {
1378
1223
  }
1379
1224
  return this._fn(value, this._recurse, key);
1380
1225
  }
1381
- constructor(_fn) {
1382
- _define_property7(this, "_fn", void 0);
1383
- _define_property7(this, "_cyclic", void 0);
1384
- _define_property7(this, "_recurse", void 0);
1385
- this._fn = _fn;
1386
- this._cyclic = /* @__PURE__ */ new Map();
1387
- this._recurse = (value) => {
1388
- if (this._cyclic.has(value)) {
1389
- return this._cyclic.get(value);
1226
+ _recurse = (value) => {
1227
+ if (this._cyclic.has(value)) {
1228
+ return this._cyclic.get(value);
1229
+ }
1230
+ if (Array.isArray(value)) {
1231
+ const res = new Array(value.length);
1232
+ this._cyclic.set(value, res);
1233
+ for (let i = 0; i < value.length; i++) {
1234
+ res[i] = this._map(value[i], i);
1390
1235
  }
1391
- if (Array.isArray(value)) {
1392
- const res = new Array(value.length);
1393
- this._cyclic.set(value, res);
1394
- for (let i = 0; i < value.length; i++) {
1395
- res[i] = this._map(value[i], i);
1396
- }
1397
- return res;
1398
- } else if (value !== null && typeof value === "object") {
1399
- const res = {};
1400
- this._cyclic.set(value, res);
1401
- for (const key in value) {
1402
- res[key] = this._map(value[key], key);
1403
- }
1404
- return res;
1405
- } else {
1406
- return value;
1236
+ return res;
1237
+ } else if (value !== null && typeof value === "object") {
1238
+ const res = {};
1239
+ this._cyclic.set(value, res);
1240
+ for (const key in value) {
1241
+ res[key] = this._map(value[key], key);
1407
1242
  }
1408
- };
1409
- }
1243
+ return res;
1244
+ } else {
1245
+ return value;
1246
+ }
1247
+ };
1410
1248
  };
1411
1249
  var deepMapValuesAsync = (value, fn) => {
1412
1250
  return new DeepMapperAsync(fn).map(value);
1413
1251
  };
1414
1252
  var DeepMapperAsync = class {
1253
+ _fn;
1254
+ _cyclic = /* @__PURE__ */ new Map();
1255
+ constructor(_fn) {
1256
+ this._fn = _fn;
1257
+ }
1415
1258
  map(value) {
1416
1259
  return this._map(value, void 0);
1417
1260
  }
@@ -1421,35 +1264,28 @@ var DeepMapperAsync = class {
1421
1264
  }
1422
1265
  return this._fn(value, this._recurse, key);
1423
1266
  }
1424
- constructor(_fn) {
1425
- _define_property7(this, "_fn", void 0);
1426
- _define_property7(this, "_cyclic", void 0);
1427
- _define_property7(this, "_recurse", void 0);
1428
- this._fn = _fn;
1429
- this._cyclic = /* @__PURE__ */ new Map();
1430
- this._recurse = async (value) => {
1431
- if (this._cyclic.has(value)) {
1432
- return this._cyclic.get(value);
1267
+ _recurse = async (value) => {
1268
+ if (this._cyclic.has(value)) {
1269
+ return this._cyclic.get(value);
1270
+ }
1271
+ if (Array.isArray(value)) {
1272
+ const res = new Array(value.length);
1273
+ this._cyclic.set(value, res);
1274
+ for (let i = 0; i < value.length; i++) {
1275
+ res[i] = await this._map(value[i], i);
1433
1276
  }
1434
- if (Array.isArray(value)) {
1435
- const res = new Array(value.length);
1436
- this._cyclic.set(value, res);
1437
- for (let i = 0; i < value.length; i++) {
1438
- res[i] = await this._map(value[i], i);
1439
- }
1440
- return res;
1441
- } else if (value !== null && typeof value === "object") {
1442
- const res = {};
1443
- this._cyclic.set(value, res);
1444
- for (const key in value) {
1445
- res[key] = await this._map(value[key], key);
1446
- }
1447
- return res;
1448
- } else {
1449
- return value;
1277
+ return res;
1278
+ } else if (value !== null && typeof value === "object") {
1279
+ const res = {};
1280
+ this._cyclic.set(value, res);
1281
+ for (const key in value) {
1282
+ res[key] = await this._map(value[key], key);
1450
1283
  }
1451
- };
1452
- }
1284
+ return res;
1285
+ } else {
1286
+ return value;
1287
+ }
1288
+ };
1453
1289
  };
1454
1290
  var visitValues = (object, visitor) => {
1455
1291
  if (Array.isArray(object)) {
@@ -1538,7 +1374,18 @@ var omit = (obj, keys2) => {
1538
1374
 
1539
1375
  // src/platform.ts
1540
1376
  var isNode = () => typeof process !== "undefined" && process.versions != null && process.versions.node != null;
1541
- var mobileAndTabletCheck = () => {
1377
+ var isBun = () => globalThis.Bun !== void 0;
1378
+ var isTauri = () => !!globalThis.__TAURI__;
1379
+ var isMobile = () => {
1380
+ let check = false;
1381
+ (function(a) {
1382
+ if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0, 4))) {
1383
+ check = true;
1384
+ }
1385
+ })(navigator.userAgent || navigator.vendor || window.opera);
1386
+ return check;
1387
+ };
1388
+ var isMobileOrTablet = () => {
1542
1389
  let check = false;
1543
1390
  ((a) => {
1544
1391
  if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino|android|ipad|playbook|silk/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0, 4))) {
@@ -1560,7 +1407,7 @@ var iosCheck = () => {
1560
1407
  };
1561
1408
  var safariCheck = () => typeof navigator !== "undefined" && /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
1562
1409
  var getHostPlatform = () => {
1563
- if (!("navigator" in window)) {
1410
+ if (!("navigator" in globalThis)) {
1564
1411
  return "unknown";
1565
1412
  }
1566
1413
  const platform = (navigator.userAgentData?.platform || navigator.platform)?.toLowerCase();
@@ -1755,7 +1602,7 @@ var safeAwaitAll = async (source, taskFactory, onError) => {
1755
1602
  };
1756
1603
 
1757
1604
  // src/safe-instanceof.ts
1758
- var instanceTag = Symbol("instanceTag");
1605
+ var instanceTag = /* @__PURE__ */ Symbol("instanceTag");
1759
1606
  var safeInstanceof = (tag) => (target) => {
1760
1607
  target.prototype[instanceTag] = tag;
1761
1608
  Object.defineProperty(target.prototype, Symbol.hasInstance, {
@@ -1767,48 +1614,151 @@ var safeInstanceof = (tag) => (target) => {
1767
1614
  };
1768
1615
 
1769
1616
  // src/safe-parse.ts
1770
- var safeParseInt = (value, defaultValue) => {
1617
+ function safeParseInt(str, defaultValue) {
1771
1618
  try {
1772
- const n = parseInt(value ?? "");
1773
- return isNaN(n) ? defaultValue : n;
1619
+ const value = parseInt(str ?? "");
1620
+ return isNaN(value) ? defaultValue : value;
1774
1621
  } catch {
1775
1622
  return defaultValue;
1776
1623
  }
1777
- };
1778
- var safeParseFloat = (str, defaultValue) => {
1624
+ }
1625
+ function safeParseFloat(str, defaultValue) {
1779
1626
  try {
1780
- return parseFloat(str);
1627
+ const value = parseFloat(str ?? "");
1628
+ return isNaN(value) ? defaultValue : value;
1781
1629
  } catch {
1782
- return defaultValue ?? 0;
1630
+ return defaultValue;
1783
1631
  }
1784
- };
1785
- var safeParseJson = (data, defaultValue) => {
1786
- if (data && data.length > 0) {
1632
+ }
1633
+ var safeParseJson = (str, defaultValue) => {
1634
+ if (str && str.length > 0) {
1787
1635
  try {
1788
- return JSON.parse(data);
1636
+ return JSON.parse(str);
1789
1637
  } catch {
1790
1638
  }
1791
1639
  }
1792
1640
  return defaultValue;
1793
1641
  };
1642
+ var safeUrl = (str) => {
1643
+ try {
1644
+ return new URL(str ?? "");
1645
+ } catch {
1646
+ return void 0;
1647
+ }
1648
+ };
1794
1649
 
1795
- // src/sliding-window-summary.ts
1796
- import { invariant as invariant5 } from "@dxos/invariant";
1797
- function _define_property8(obj, key, value) {
1798
- if (key in obj) {
1799
- Object.defineProperty(obj, key, {
1800
- value,
1801
- enumerable: true,
1802
- configurable: true,
1803
- writable: true
1804
- });
1805
- } else {
1806
- obj[key] = value;
1650
+ // src/safe-stringify.ts
1651
+ var SKIP = Object.freeze({});
1652
+ function safeStringify(obj, filter = defaultFilter, indent = 2) {
1653
+ const seen = /* @__PURE__ */ new WeakMap();
1654
+ function replacer(key, value) {
1655
+ try {
1656
+ let path = key;
1657
+ if (!key) {
1658
+ path = "$";
1659
+ if (value != null && typeof value === "object") {
1660
+ seen.set(value, path);
1661
+ }
1662
+ return value;
1663
+ } else if (this) {
1664
+ const parentPath = seen.get(this);
1665
+ path = parentPath ? `${parentPath}.${key}` : key;
1666
+ }
1667
+ if (value == null) {
1668
+ return value;
1669
+ }
1670
+ if (typeof value === "function") {
1671
+ return void 0;
1672
+ }
1673
+ if (typeof value === "object" && Object.getPrototypeOf(value) !== Object.prototype && !Array.isArray(value)) {
1674
+ return void 0;
1675
+ }
1676
+ if (typeof value === "object" && value !== null) {
1677
+ const exists = seen.get(value);
1678
+ if (exists) {
1679
+ return `[${path} => ${exists}]`;
1680
+ }
1681
+ seen.set(value, path);
1682
+ }
1683
+ if (filter) {
1684
+ const filteredValue = filter?.(key, value);
1685
+ if (filteredValue !== void 0) {
1686
+ return filteredValue === SKIP ? void 0 : filteredValue;
1687
+ }
1688
+ }
1689
+ return value;
1690
+ } catch (error) {
1691
+ return `ERROR: ${error.message}`;
1692
+ }
1693
+ }
1694
+ try {
1695
+ return JSON.stringify(obj, replacer, indent);
1696
+ } catch (error) {
1697
+ return `ERROR: ${error.message}`;
1807
1698
  }
1808
- return obj;
1809
1699
  }
1700
+ var createReplacer = ({ omit: omit2, parse, maxDepth, maxArrayLen, maxStringLen } = {}) => {
1701
+ let currentDepth = 0;
1702
+ const depthMap = /* @__PURE__ */ new WeakMap();
1703
+ return function(key, value) {
1704
+ if (key === "") {
1705
+ currentDepth = 0;
1706
+ } else if (this && typeof this === "object") {
1707
+ const parentDepth = depthMap.get(this) ?? 0;
1708
+ currentDepth = parentDepth + 1;
1709
+ }
1710
+ if (typeof value === "function") {
1711
+ return SKIP;
1712
+ }
1713
+ if (maxArrayLen != null && Array.isArray(value) && value.length > maxArrayLen) {
1714
+ return `[length: ${value.length}]`;
1715
+ }
1716
+ if (value && typeof value === "object") {
1717
+ depthMap.set(value, currentDepth);
1718
+ if (maxDepth != null && currentDepth >= maxDepth) {
1719
+ return Array.isArray(value) ? `[{ length: ${value.length} }]` : `{ keys: ${Object.keys(value).length} }`;
1720
+ }
1721
+ }
1722
+ if (omit2?.includes(key)) {
1723
+ return SKIP;
1724
+ }
1725
+ if (parse?.includes(key) && typeof value === "string") {
1726
+ try {
1727
+ return JSON.parse(value);
1728
+ } catch {
1729
+ return value;
1730
+ }
1731
+ }
1732
+ if (maxStringLen != null && typeof value === "string" && value.length > maxStringLen) {
1733
+ return value.slice(0, maxStringLen) + "...";
1734
+ }
1735
+ return value;
1736
+ };
1737
+ };
1738
+ var defaultFilter = createReplacer();
1739
+
1740
+ // src/sliding-window-summary.ts
1741
+ import { invariant as invariant5 } from "@dxos/invariant";
1810
1742
  var __dxlog_file5 = "/__w/dxos/dxos/packages/common/util/src/sliding-window-summary.ts";
1811
1743
  var SlidingWindowSummary = class {
1744
+ _buffer;
1745
+ _sum = 0;
1746
+ _precision;
1747
+ constructor(options) {
1748
+ this._buffer = new CircularBuffer(options.dataPoints);
1749
+ if (options.precision != null) {
1750
+ invariant5(options.precision >= 0, void 0, {
1751
+ F: __dxlog_file5,
1752
+ L: 26,
1753
+ S: this,
1754
+ A: [
1755
+ "options.precision >= 0",
1756
+ ""
1757
+ ]
1758
+ });
1759
+ this._precision = Math.pow(10, options.precision);
1760
+ }
1761
+ }
1812
1762
  record(value) {
1813
1763
  const evicted = this._buffer.push(value);
1814
1764
  this._sum += value - (evicted ?? 0);
@@ -1843,24 +1793,6 @@ var SlidingWindowSummary = class {
1843
1793
  }
1844
1794
  return Math.round(value * this._precision) / this._precision;
1845
1795
  }
1846
- constructor(options) {
1847
- _define_property8(this, "_buffer", void 0);
1848
- _define_property8(this, "_sum", 0);
1849
- _define_property8(this, "_precision", void 0);
1850
- this._buffer = new CircularBuffer(options.dataPoints);
1851
- if (options.precision != null) {
1852
- invariant5(options.precision >= 0, void 0, {
1853
- F: __dxlog_file5,
1854
- L: 26,
1855
- S: this,
1856
- A: [
1857
- "options.precision >= 0",
1858
- ""
1859
- ]
1860
- });
1861
- this._precision = Math.pow(10, options.precision);
1862
- }
1863
- }
1864
1796
  };
1865
1797
 
1866
1798
  // src/sort.ts
@@ -1909,6 +1841,7 @@ function trim(strings, ...values) {
1909
1841
  const minIndent = Math.min(...lines.filter((l) => l.trim()).map((l) => l.match(/^[ \t]*/)?.[0].length ?? 0));
1910
1842
  return lines.map((l) => l.slice(minIndent)).join("\n");
1911
1843
  }
1844
+ var kebabize = (str) => str.replace(/[A-Z]+(?![a-z])|[A-Z]/g, ($, ofs) => (ofs ? "-" : "") + $.toLowerCase());
1912
1845
 
1913
1846
  // src/sum.ts
1914
1847
  var sum = (values) => values.reduce((a, b) => a + b, 0);
@@ -1922,18 +1855,6 @@ var throwUnhandledError = (error) => {
1922
1855
 
1923
1856
  // src/to-fallback.ts
1924
1857
  var idEmoji = [
1925
- // When changing this set, please check the result in a console or e.g. RunKit (https://runkit.com/thure/642214441dd6ae000855a8de)
1926
- // Emoji sometimes use a combination of code points, and some code points aren't visible on their own, so by adding or deleting you may unintentionally create non-visible items.
1927
- // This set was chosen from the characters in Unicode Emoji v15.0 based on the following criteria:
1928
- // – not people or isolated anthropomorphic faces
1929
- // – not flags
1930
- // – more concrete than abstract
1931
- // – less culturally specific
1932
- // – less easily confused with another emoji in the set
1933
- // – requires less special knowledge to identify
1934
- // – less likely to evoke negative feelings (no meat, no drugs, no weapons, etc)
1935
- // – less common as a signifier in UX
1936
- // NOTE that this is intentionally an array of strings because of the way emoji graphemes work.
1937
1858
  "\u{1F47B}",
1938
1859
  "\u{1F479}",
1939
1860
  "\u{1F47D}",
@@ -2069,17 +1990,18 @@ var idEmoji = [
2069
1990
  ];
2070
1991
  var idHue = [
2071
1992
  "red",
2072
- // 'orange' as const, /* More shades in these palettes are considered “ugly” */
1993
+ "orange",
2073
1994
  "amber",
2074
- // 'yellow' as const, /* More shades in these palettes are considered “ugly” */
1995
+ "yellow",
2075
1996
  "lime",
2076
1997
  "green",
2077
1998
  "emerald",
2078
1999
  "teal",
2079
2000
  "cyan",
2080
- // 'sky' as const, /* Omitted since it is quite similar to the primary accent palette */
2081
- // 'blue' as const, /* Omitted since it is quite similar to the primary accent palette */
2082
- // 'indigo' as const, /* Omitted since it is quite similar to the primary accent palette */
2001
+ // Omit colors similar to primary accent.
2002
+ // 'sky' as const,
2003
+ // 'blue' as const,
2004
+ // 'indigo' as const,
2083
2005
  "violet",
2084
2006
  "purple",
2085
2007
  "fuchsia",
@@ -2106,20 +2028,9 @@ var toFallback = (hash) => {
2106
2028
  };
2107
2029
 
2108
2030
  // src/tracer.ts
2109
- function _define_property9(obj, key, value) {
2110
- if (key in obj) {
2111
- Object.defineProperty(obj, key, {
2112
- value,
2113
- enumerable: true,
2114
- configurable: true,
2115
- writable: true
2116
- });
2117
- } else {
2118
- obj[key] = value;
2119
- }
2120
- return obj;
2121
- }
2122
2031
  var Tracer = class {
2032
+ _events = /* @__PURE__ */ new Map();
2033
+ _recording = false;
2123
2034
  // TODO(burdon): Start/stop methods for recording data? By id?
2124
2035
  // Alternatively, enable subscriptions to track/compute series.
2125
2036
  // TODO(burdon): Hierarchical traces?
@@ -2176,10 +2087,6 @@ var Tracer = class {
2176
2087
  defaultMap(this._events, event.id, []).push(event);
2177
2088
  }
2178
2089
  }
2179
- constructor() {
2180
- _define_property9(this, "_events", /* @__PURE__ */ new Map());
2181
- _define_property9(this, "_recording", false);
2182
- }
2183
2090
  };
2184
2091
  var tracer = new Tracer();
2185
2092
 
@@ -2224,7 +2131,7 @@ var stringifyTree = (node, ancestors = [], rows = []) => {
2224
2131
  };
2225
2132
 
2226
2133
  // src/types.ts
2227
- var isNotFalsy = (value) => !!value;
2134
+ var isTruthy = (value) => !!value;
2228
2135
  var isNonNullable = (value) => value != null;
2229
2136
  var doAsync = async (fn) => fn();
2230
2137
  var getProviderValue = (provider, arg) => {
@@ -2254,69 +2161,112 @@ var arrayMove = (array, from, to) => {
2254
2161
  array.splice(to < 0 ? array.length + to : to, 0, array.splice(from, 1)[0]);
2255
2162
  return array;
2256
2163
  };
2164
+ function arraySwap(array, from, to) {
2165
+ const current = array[from];
2166
+ array[from] = array[to];
2167
+ array[to] = current;
2168
+ return array;
2169
+ }
2257
2170
 
2258
2171
  // src/unit.ts
2259
- var Formatter = (unit) => {
2260
- return (n, precision = 2) => {
2172
+ var createFormat = (unit) => {
2173
+ return (n, precision = unit.precision ?? 0) => {
2261
2174
  const value = n / unit.quotient;
2262
- return `${value.toFixed(precision)}${unit.symbol}`;
2175
+ return {
2176
+ unit,
2177
+ value,
2178
+ formattedValue: value.toFixed(precision),
2179
+ toString: () => `${value.toFixed(precision)}${unit.symbol}`
2180
+ };
2263
2181
  };
2264
2182
  };
2183
+ var MS_SECONDS = 1e3;
2184
+ var MS_MINUTES = 60 * MS_SECONDS;
2185
+ var MS_HOURS = 60 * MS_MINUTES;
2265
2186
  var Unit = {
2266
- // ms.
2267
- Hour: Formatter({
2187
+ // General.
2188
+ Percent: createFormat({
2189
+ symbol: "%",
2190
+ quotient: 1 / 100,
2191
+ precision: 2
2192
+ }),
2193
+ Thousand: createFormat({
2194
+ symbol: "k",
2195
+ quotient: 1e3,
2196
+ precision: 2
2197
+ }),
2198
+ // Bytes (note KB vs KiB).
2199
+ Gigabyte: createFormat({
2200
+ symbol: "GB",
2201
+ quotient: 1e3 * 1e3 * 1e3,
2202
+ precision: 2
2203
+ }),
2204
+ Megabyte: createFormat({
2205
+ symbol: "MB",
2206
+ quotient: 1e3 * 1e3,
2207
+ precision: 2
2208
+ }),
2209
+ Kilobyte: createFormat({
2210
+ symbol: "KB",
2211
+ quotient: 1e3,
2212
+ precision: 2
2213
+ }),
2214
+ Byte: createFormat({
2215
+ symbol: "B",
2216
+ quotient: 1
2217
+ }),
2218
+ // Time.
2219
+ Hour: createFormat({
2268
2220
  symbol: "h",
2269
- quotient: 60 * 60 * 1e3
2221
+ quotient: MS_HOURS
2270
2222
  }),
2271
- Minute: Formatter({
2223
+ Minute: createFormat({
2272
2224
  symbol: "m",
2273
- quotient: 60 * 1e3
2225
+ quotient: MS_MINUTES
2274
2226
  }),
2275
- Second: Formatter({
2227
+ Second: createFormat({
2276
2228
  symbol: "s",
2277
- quotient: 1e3
2229
+ quotient: MS_SECONDS,
2230
+ precision: 1
2278
2231
  }),
2279
- Millisecond: Formatter({
2232
+ Millisecond: createFormat({
2280
2233
  symbol: "ms",
2281
2234
  quotient: 1
2282
2235
  }),
2283
2236
  Duration: (n) => {
2284
- const hours = Math.floor(n / (60 * 60 * 1e3));
2285
- const minutes = Math.floor(n % (60 * 60 * 1e3) / (60 * 1e3));
2237
+ const hours = Math.floor(n / MS_HOURS);
2238
+ const minutes = Math.floor(n % MS_HOURS / MS_MINUTES);
2286
2239
  if (hours) {
2287
- return minutes ? `${hours}h ${minutes}m` : `${hours}h`;
2240
+ const formattedValue = minutes ? `${hours}h ${minutes}m` : `${hours}h`;
2241
+ return {
2242
+ unit: {
2243
+ symbol: "h",
2244
+ quotient: MS_HOURS
2245
+ },
2246
+ value: hours,
2247
+ formattedValue,
2248
+ toString: () => formattedValue
2249
+ };
2288
2250
  }
2289
- const seconds = Math.floor(n % (60 * 1e3) / 1e3);
2290
2251
  if (minutes) {
2291
- return seconds ? `${minutes}m ${seconds}s` : `${minutes}m`;
2252
+ const seconds2 = (n - MS_MINUTES * minutes) / MS_SECONDS;
2253
+ const formattedValue = seconds2 ? `${minutes}m ${seconds2}s` : `${minutes}m`;
2254
+ return {
2255
+ unit: {
2256
+ symbol: "m",
2257
+ quotient: MS_MINUTES
2258
+ },
2259
+ value: minutes,
2260
+ formattedValue,
2261
+ toString: () => formattedValue
2262
+ };
2292
2263
  }
2264
+ const seconds = n >= MS_SECONDS;
2293
2265
  if (seconds) {
2294
- return `${(n / 1e3).toFixed(1)}s`;
2266
+ return Unit.Second(n);
2295
2267
  }
2296
- return `${n}ms`;
2297
- },
2298
- // bytes (note KB via KiB).
2299
- Gigabyte: Formatter({
2300
- symbol: "GB",
2301
- quotient: 1e3 * 1e3 * 1e3
2302
- }),
2303
- Megabyte: Formatter({
2304
- symbol: "MB",
2305
- quotient: 1e3 * 1e3
2306
- }),
2307
- Kilobyte: Formatter({
2308
- symbol: "KB",
2309
- quotient: 1e3
2310
- }),
2311
- // general.
2312
- Thousand: Formatter({
2313
- symbol: "k",
2314
- quotient: 1e3
2315
- }),
2316
- Percent: Formatter({
2317
- symbol: "%",
2318
- quotient: 1 / 100
2319
- })
2268
+ return Unit.Millisecond(n);
2269
+ }
2320
2270
  };
2321
2271
 
2322
2272
  // src/url.ts
@@ -2329,20 +2279,18 @@ var createUrl = (url, search) => {
2329
2279
  };
2330
2280
 
2331
2281
  // src/weak.ts
2332
- function _define_property10(obj, key, value) {
2333
- if (key in obj) {
2334
- Object.defineProperty(obj, key, {
2335
- value,
2336
- enumerable: true,
2337
- configurable: true,
2338
- writable: true
2339
- });
2340
- } else {
2341
- obj[key] = value;
2342
- }
2343
- return obj;
2344
- }
2345
2282
  var WeakDictionary = class {
2283
+ _internal = /* @__PURE__ */ new Map();
2284
+ _finalization = new FinalizationRegistry((cleanUpCallback) => {
2285
+ cleanUpCallback();
2286
+ });
2287
+ constructor(entries2) {
2288
+ this._internal = new Map(entries2?.map(([key, value]) => [
2289
+ key,
2290
+ new WeakRef(value)
2291
+ ]));
2292
+ entries2?.forEach(([key, value]) => this._register(key, value));
2293
+ }
2346
2294
  *entries() {
2347
2295
  for (const [key, value] of this._internal) {
2348
2296
  yield [
@@ -2423,16 +2371,57 @@ var WeakDictionary = class {
2423
2371
  _unregister(value) {
2424
2372
  this._finalization.unregister(value);
2425
2373
  }
2426
- constructor(entries2) {
2427
- _define_property10(this, "_internal", /* @__PURE__ */ new Map());
2428
- _define_property10(this, "_finalization", new FinalizationRegistry((cleanUpCallback) => {
2429
- cleanUpCallback();
2430
- }));
2431
- this._internal = new Map(entries2?.map(([key, value]) => [
2432
- key,
2433
- new WeakRef(value)
2434
- ]));
2435
- entries2?.forEach(([key, value]) => this._register(key, value));
2374
+ };
2375
+
2376
+ // src/error-format.ts
2377
+ var formatErrorWithCauses = (error) => {
2378
+ const lines = [];
2379
+ let current = error;
2380
+ let level = 0;
2381
+ while (current) {
2382
+ const prefix = level === 0 ? "" : `Caused by: `;
2383
+ lines.push(prefix + (current.stack ?? String(current)));
2384
+ if (!(current.cause instanceof Error)) break;
2385
+ current = current.cause;
2386
+ level += 1;
2387
+ }
2388
+ return lines.join("\n\n");
2389
+ };
2390
+
2391
+ // src/retry.ts
2392
+ var DEFAULT_RETRY_OPTIONS = {
2393
+ count: 3,
2394
+ delayMs: 100,
2395
+ exponent: 2,
2396
+ retryOnError: async () => true,
2397
+ retryOnValue: async () => false
2398
+ };
2399
+ var retry = async (options, cb) => {
2400
+ const fullOptions = {
2401
+ ...DEFAULT_RETRY_OPTIONS,
2402
+ ...options
2403
+ };
2404
+ let numRetries = 0, currentDelay = fullOptions.delayMs;
2405
+ while (true) {
2406
+ let result;
2407
+ try {
2408
+ result = await cb();
2409
+ } catch (err) {
2410
+ if (numRetries > fullOptions.count || !await fullOptions.retryOnError(err)) {
2411
+ throw err;
2412
+ }
2413
+ await new Promise((resolve) => setTimeout(resolve, currentDelay));
2414
+ currentDelay *= fullOptions.exponent;
2415
+ numRetries++;
2416
+ continue;
2417
+ }
2418
+ if (!await fullOptions.retryOnValue(result)) {
2419
+ return result;
2420
+ }
2421
+ await new Promise((resolve) => setTimeout(resolve, currentDelay));
2422
+ currentDelay *= fullOptions.exponent;
2423
+ numRetries++;
2424
+ continue;
2436
2425
  }
2437
2426
  };
2438
2427
  export {
@@ -2444,12 +2433,14 @@ export {
2444
2433
  ComplexSet,
2445
2434
  HumanHasher,
2446
2435
  MapEntry,
2436
+ SKIP,
2447
2437
  SlidingWindowSummary,
2448
2438
  Tracer,
2449
2439
  Unit,
2450
2440
  WeakDictionary,
2451
2441
  accessBy,
2452
2442
  arrayMove,
2443
+ arraySwap,
2453
2444
  arrayToBuffer,
2454
2445
  arrayToHex,
2455
2446
  arrayToString,
@@ -2461,18 +2452,23 @@ export {
2461
2452
  chunkArray,
2462
2453
  clamp,
2463
2454
  clearUndefined,
2455
+ coerceArray,
2464
2456
  compareMulti,
2465
2457
  compareObject,
2466
2458
  compareScalar,
2467
2459
  compareString,
2460
+ compositeKey,
2468
2461
  createBinder,
2469
2462
  createBucketReducer,
2463
+ createFilename,
2470
2464
  createGroupReducer,
2465
+ createReplacer,
2471
2466
  createSetDispatch,
2472
2467
  createUrl,
2473
2468
  decamelize,
2474
2469
  deepMapValues,
2475
2470
  deepMapValuesAsync,
2471
+ defaultFilter,
2476
2472
  defaultMap,
2477
2473
  defer,
2478
2474
  deferAsync,
@@ -2484,12 +2480,11 @@ export {
2484
2480
  entry,
2485
2481
  exponentialBackoffInterval,
2486
2482
  forEachAsync,
2487
- get,
2483
+ formatErrorWithCauses,
2488
2484
  getAsyncProviderValue,
2489
2485
  getDate,
2490
2486
  getDebugName,
2491
2487
  getDeep,
2492
- getFirstTwoRenderableChars,
2493
2488
  getHostPlatform,
2494
2489
  getPrototypeSpecificInstanceId,
2495
2490
  getProviderValue,
@@ -2505,14 +2500,19 @@ export {
2505
2500
  intersectBy,
2506
2501
  intersection,
2507
2502
  iosCheck,
2503
+ isBun,
2504
+ isMobile,
2505
+ isMobileOrTablet,
2508
2506
  isNode,
2509
2507
  isNonNullable,
2510
- isNotFalsy,
2508
+ isTauri,
2509
+ isTruthy,
2511
2510
  joinTables,
2512
2511
  jsonKeyReplacer,
2513
2512
  jsonReplacer,
2514
2513
  jsonify,
2515
2514
  jsonlogify,
2515
+ kebabize,
2516
2516
  keyToEmoji,
2517
2517
  keyToFallback,
2518
2518
  keyToHue,
@@ -2521,7 +2521,6 @@ export {
2521
2521
  makeSet,
2522
2522
  mapValues,
2523
2523
  median,
2524
- mobileAndTabletCheck,
2525
2524
  numericalValues,
2526
2525
  omit,
2527
2526
  orderKeys,
@@ -2537,15 +2536,18 @@ export {
2537
2536
  removeBy,
2538
2537
  removeProperties,
2539
2538
  removeUndefinedProperties,
2539
+ retry,
2540
2540
  safariCheck,
2541
2541
  safeAwaitAll,
2542
2542
  safeInstanceof,
2543
2543
  safeParseFloat,
2544
2544
  safeParseInt,
2545
2545
  safeParseJson,
2546
- set,
2546
+ safeStringify,
2547
+ safeUrl,
2547
2548
  setDeep,
2548
2549
  sortKeys,
2550
+ splitCompositeKey,
2549
2551
  stringToArray,
2550
2552
  stringifyTree,
2551
2553
  stripUndefined,