@dxos/util 0.8.4-main.84f28bd → 0.8.4-main.a4bbb77

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 (52) hide show
  1. package/dist/lib/browser/index.mjs +425 -163
  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 +425 -163
  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.map +1 -1
  8. package/dist/types/src/assume.d.ts.map +1 -1
  9. package/dist/types/src/di-key.d.ts +3 -3
  10. package/dist/types/src/di-key.d.ts.map +1 -1
  11. package/dist/types/src/index.d.ts +1 -2
  12. package/dist/types/src/index.d.ts.map +1 -1
  13. package/dist/types/src/json.d.ts +1 -1
  14. package/dist/types/src/json.d.ts.map +1 -1
  15. package/dist/types/src/object.d.ts +3 -0
  16. package/dist/types/src/object.d.ts.map +1 -1
  17. package/dist/types/src/safe-parse.d.ts.map +1 -1
  18. package/dist/types/src/string.d.ts +4 -0
  19. package/dist/types/src/string.d.ts.map +1 -1
  20. package/dist/types/src/string.test.d.ts +2 -0
  21. package/dist/types/src/string.test.d.ts.map +1 -0
  22. package/dist/types/src/types.d.ts +1 -1
  23. package/dist/types/src/types.d.ts.map +1 -1
  24. package/dist/types/src/unit.d.ts +15 -0
  25. package/dist/types/src/unit.d.ts.map +1 -0
  26. package/dist/types/src/unit.test.d.ts +2 -0
  27. package/dist/types/src/unit.test.d.ts.map +1 -0
  28. package/dist/types/tsconfig.tsbuildinfo +1 -1
  29. package/package.json +8 -8
  30. package/src/array.test.ts +1 -1
  31. package/src/array.ts +0 -2
  32. package/src/assume.ts +0 -1
  33. package/src/circular-buffer.test.ts +1 -1
  34. package/src/complex.test.ts +1 -1
  35. package/src/human-hash.test.ts +1 -1
  36. package/src/index.ts +1 -2
  37. package/src/json.ts +2 -7
  38. package/src/object.ts +3 -0
  39. package/src/position.test.ts +2 -2
  40. package/src/safe-parse.ts +6 -3
  41. package/src/sort.test.ts +1 -1
  42. package/src/string.test.ts +19 -0
  43. package/src/string.ts +29 -0
  44. package/src/tree.test.ts +1 -1
  45. package/src/types.ts +2 -1
  46. package/src/uint8array.test.ts +1 -1
  47. package/src/unit.test.ts +25 -0
  48. package/src/unit.ts +52 -0
  49. package/src/weak.test.ts +1 -1
  50. package/dist/types/src/first-two-chars.d.ts +0 -9
  51. package/dist/types/src/first-two-chars.d.ts.map +0 -1
  52. package/src/first-two-chars.ts +0 -44
@@ -180,31 +180,90 @@ var BitField = class _BitField {
180
180
  };
181
181
 
182
182
  // 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();
183
224
  var CallbackCollection = class {
184
- #callbacks = [];
185
225
  append(callback) {
186
- this.#callbacks.push(callback);
226
+ _class_private_field_get(this, _callbacks).push(callback);
187
227
  }
188
228
  prepend(callback) {
189
- this.#callbacks.unshift(callback);
229
+ _class_private_field_get(this, _callbacks).unshift(callback);
190
230
  }
191
231
  remove(callback) {
192
- this.#callbacks = this.#callbacks.filter((c) => c !== callback);
232
+ _class_private_field_set(this, _callbacks, _class_private_field_get(this, _callbacks).filter((c) => c !== callback));
193
233
  }
194
234
  callParallel(...args) {
195
- return Promise.all(this.#callbacks.map((callback) => callback(...args)));
235
+ return Promise.all(_class_private_field_get(this, _callbacks).map((callback) => callback(...args)));
196
236
  }
197
237
  async callSerial(...args) {
198
238
  const results = [];
199
- for (const callback of this.#callbacks) {
239
+ for (const callback of _class_private_field_get(this, _callbacks)) {
200
240
  results.push(await callback(...args));
201
241
  }
202
242
  return results;
203
243
  }
244
+ constructor() {
245
+ _class_private_field_init(this, _callbacks, {
246
+ writable: true,
247
+ value: []
248
+ });
249
+ }
204
250
  };
205
251
 
206
252
  // src/callback.ts
207
253
  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
+ }
208
267
  var __dxlog_file2 = "/__w/dxos/dxos/packages/common/util/src/callback.ts";
209
268
  var Callback = class {
210
269
  call(...args) {
@@ -237,6 +296,9 @@ var Callback = class {
237
296
  isSet() {
238
297
  return !!this._callback;
239
298
  }
299
+ constructor() {
300
+ _define_property(this, "_callback", void 0);
301
+ }
240
302
  };
241
303
  var createSetDispatch = ({ handlers }) => {
242
304
  return new Proxy({
@@ -299,22 +361,21 @@ var chunkArray = (array, size) => {
299
361
 
300
362
  // src/circular-buffer.ts
301
363
  import { invariant as invariant3 } from "@dxos/invariant";
302
- var __dxlog_file3 = "/__w/dxos/dxos/packages/common/util/src/circular-buffer.ts";
303
- var CircularBuffer = class {
304
- constructor(size) {
305
- this._nextIndex = 0;
306
- this._elementCount = 0;
307
- invariant3(size >= 1, void 0, {
308
- F: __dxlog_file3,
309
- L: 13,
310
- S: this,
311
- A: [
312
- "size >= 1",
313
- ""
314
- ]
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
315
371
  });
316
- this._buffer = new Array(size);
372
+ } else {
373
+ obj[key] = value;
317
374
  }
375
+ return obj;
376
+ }
377
+ var __dxlog_file3 = "/__w/dxos/dxos/packages/common/util/src/circular-buffer.ts";
378
+ var CircularBuffer = class {
318
379
  push(element) {
319
380
  const evicted = this._elementCount === this._buffer.length ? this._buffer[this._nextIndex] : void 0;
320
381
  this._buffer[this._nextIndex] = element;
@@ -354,6 +415,21 @@ var CircularBuffer = class {
354
415
  yield this._buffer[i];
355
416
  }
356
417
  }
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
+ }
357
433
  };
358
434
 
359
435
  // src/clear-undefined.ts
@@ -372,18 +448,22 @@ var clearUndefined = (obj) => {
372
448
  // src/complex.ts
373
449
  import { inspect } from "node:util";
374
450
  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
+ }
375
464
  var MAX_SERIALIZATION_LENGTH = 10;
465
+ var _inspect_custom = inspect.custom;
376
466
  var ComplexSet = class {
377
- // prettier-ignore
378
- constructor(_projection, values) {
379
- this._projection = _projection;
380
- this._values = /* @__PURE__ */ new Map();
381
- if (values) {
382
- for (const value of values) {
383
- this.add(value);
384
- }
385
- }
386
- }
387
467
  toString() {
388
468
  return inspectObject(this);
389
469
  }
@@ -392,7 +472,7 @@ var ComplexSet = class {
392
472
  size: this._values.size
393
473
  } : Array.from(this._values.values());
394
474
  }
395
- [inspect.custom]() {
475
+ [_inspect_custom]() {
396
476
  return inspectObject(this);
397
477
  }
398
478
  add(value) {
@@ -458,6 +538,18 @@ var ComplexSet = class {
458
538
  isDisjointFrom(other) {
459
539
  throw new Error("Method not implemented.");
460
540
  }
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
+ }
461
553
  };
462
554
  var makeSet = (projection) => {
463
555
  return class BoundComplexSet extends ComplexSet {
@@ -466,18 +558,8 @@ var makeSet = (projection) => {
466
558
  }
467
559
  };
468
560
  };
561
+ var _inspect_custom1 = inspect.custom;
469
562
  var ComplexMap = class _ComplexMap {
470
- // prettier-ignore
471
- constructor(_keyProjection, entries2) {
472
- this._keyProjection = _keyProjection;
473
- this._keys = /* @__PURE__ */ new Map();
474
- this._values = /* @__PURE__ */ new Map();
475
- if (entries2) {
476
- for (const [key, value] of entries2) {
477
- this.set(key, value);
478
- }
479
- }
480
- }
481
563
  toString() {
482
564
  return inspectObject(this);
483
565
  }
@@ -486,7 +568,7 @@ var ComplexMap = class _ComplexMap {
486
568
  size: this._values.size
487
569
  } : Array.from(this._values.values());
488
570
  }
489
- [inspect.custom]() {
571
+ [_inspect_custom1]() {
490
572
  return inspectObject(this);
491
573
  }
492
574
  clear() {
@@ -548,11 +630,28 @@ var ComplexMap = class _ComplexMap {
548
630
  get [Symbol.toStringTag]() {
549
631
  return "ComplexMap";
550
632
  }
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
+ }
551
647
  };
552
- var makeMap = (keyProjection) => class BoundComplexMap extends ComplexMap {
553
- constructor(entries2) {
554
- super(keyProjection, entries2);
648
+ var makeMap = (keyProjection) => {
649
+ class BoundComplexMap extends ComplexMap {
650
+ constructor(entries2) {
651
+ super(keyProjection, entries2);
652
+ }
555
653
  }
654
+ return BoundComplexMap;
556
655
  };
557
656
 
558
657
  // src/deep.ts
@@ -593,49 +692,71 @@ var getDeep = (obj, path) => {
593
692
  var deferFunction = (fnProvider) => (...args) => fnProvider()(...args);
594
693
 
595
694
  // src/explicit-resource-management-polyfill.ts
596
- Symbol.dispose ??= Symbol("Symbol.dispose");
597
- Symbol.asyncDispose ??= Symbol("Symbol.asyncDispose");
695
+ var _Symbol;
696
+ var _Symbol1;
697
+ (_Symbol = Symbol).dispose ?? (_Symbol.dispose = Symbol("Symbol.dispose"));
698
+ (_Symbol1 = Symbol).asyncDispose ?? (_Symbol1.asyncDispose = Symbol("Symbol.asyncDispose"));
598
699
 
599
700
  // 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
+ }
600
714
  var defer = (fn) => new DeferGuard(fn);
601
715
  var DeferGuard = class {
602
- /**
603
- * @internal
604
- */
605
- constructor(_fn) {
606
- this._fn = _fn;
607
- }
608
716
  [Symbol.dispose]() {
609
717
  const result = this._fn();
610
718
  if (result instanceof Promise) {
611
719
  throw new Error("Async functions in defer are not supported. Use deferAsync instead.");
612
720
  }
613
721
  }
614
- };
615
- var deferAsync = (fn) => new DeferAsyncGuard(fn);
616
- var DeferAsyncGuard = class {
617
722
  /**
618
723
  * @internal
619
724
  */
620
725
  constructor(_fn) {
726
+ _define_property4(this, "_fn", void 0);
621
727
  this._fn = _fn;
622
728
  }
729
+ };
730
+ var deferAsync = (fn) => new DeferAsyncGuard(fn);
731
+ var DeferAsyncGuard = class {
623
732
  async [Symbol.asyncDispose]() {
624
733
  await this._fn();
625
734
  }
735
+ /**
736
+ * @internal
737
+ */
738
+ constructor(_fn) {
739
+ _define_property4(this, "_fn", void 0);
740
+ this._fn = _fn;
741
+ }
626
742
  };
627
743
 
628
744
  // 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
+ }
629
758
  var entry = (map, key) => new MapEntry(map, key);
630
759
  var MapEntry = class {
631
- /**
632
- * @internal
633
- */
634
- // prettier-ignore
635
- constructor(_map, _key) {
636
- this._map = _map;
637
- this._key = _key;
638
- }
639
760
  get key() {
640
761
  return this._key;
641
762
  }
@@ -651,33 +772,16 @@ var MapEntry = class {
651
772
  deep(key) {
652
773
  return entry(this.value, key);
653
774
  }
654
- };
655
-
656
- // src/first-two-chars.ts
657
- var renderableCharRegex = /^(?![\p{Control}\p{Mark}\p{Separator}\p{Surrogate}\p{Unassigned}\p{P}])[\p{L}\p{N}\p{S}\p{Emoji}]$/u;
658
- var getFirstTwoRenderableChars = (label) => {
659
- const characters = Array.from(label);
660
- const result = [
661
- "",
662
- ""
663
- ];
664
- let foundFirst = false;
665
- for (let i = 0; i < characters.length; i++) {
666
- const char = characters[i];
667
- if (renderableCharRegex.test(char)) {
668
- if (!foundFirst) {
669
- result[0] = char;
670
- foundFirst = true;
671
- } else {
672
- const textBetween = characters.slice(result[0].length, i).join("");
673
- if (/[^\p{L}\p{N}_]/u.test(textBetween)) {
674
- result[1] = char;
675
- break;
676
- }
677
- }
678
- }
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;
679
784
  }
680
- return result;
681
785
  };
682
786
 
683
787
  // src/for-each-async.ts
@@ -685,6 +789,19 @@ var forEachAsync = (items, fn) => Promise.all(items.map(fn));
685
789
 
686
790
  // src/human-hash.ts
687
791
  import { PublicKey } from "@dxos/keys";
792
+ function _define_property6(obj, key, value) {
793
+ if (key in obj) {
794
+ Object.defineProperty(obj, key, {
795
+ value,
796
+ enumerable: true,
797
+ configurable: true,
798
+ writable: true
799
+ });
800
+ } else {
801
+ obj[key] = value;
802
+ }
803
+ return obj;
804
+ }
688
805
  var DEFAULT_WORDLIST = [
689
806
  "ack",
690
807
  "alabama",
@@ -944,26 +1061,6 @@ var DEFAULT_WORDLIST = [
944
1061
  "zulu"
945
1062
  ];
946
1063
  var HumanHasher = class {
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
- }
967
1064
  /**
968
1065
  * Humanize a given hexadecimal digest.
969
1066
  *
@@ -1003,6 +1100,27 @@ var HumanHasher = class {
1003
1100
  const checksums = segments.map((x) => x.reduce((acc, curr) => acc ^ curr));
1004
1101
  return checksums;
1005
1102
  }
1103
+ /**
1104
+ * Transforms hex digests to human-readable strings.
1105
+ *
1106
+ * The format of these strings will look something like:
1107
+ * `victor-bacon-zulu-lima`. The output is obtained by compressing the input
1108
+ * digest to a fixed number of bytes, then mapping those bytes to one of 256
1109
+ * words. A default wordlist is provided, but you can override this if you
1110
+ * prefer.
1111
+ * As long as you use the same wordlist, the output will be consistent (i.e.
1112
+ * the same digest will always render the same representation).
1113
+ *
1114
+ * @param wordlist A list of exactly 256 words to choose from
1115
+ */
1116
+ constructor(wordlist = DEFAULT_WORDLIST) {
1117
+ _define_property6(this, "wordlist", void 0);
1118
+ this.wordlist = wordlist;
1119
+ if (wordlist.length !== 256) {
1120
+ throw new Error("Wordlist must have exactly 256 items");
1121
+ }
1122
+ this.wordlist = wordlist;
1123
+ }
1006
1124
  };
1007
1125
  var hasher = new HumanHasher();
1008
1126
  var humanize = (value) => {
@@ -1025,8 +1143,10 @@ var defaultMap = (map, key, def) => {
1025
1143
  };
1026
1144
 
1027
1145
  // src/instance-id.ts
1146
+ var _globalThis;
1147
+ var _symbol;
1028
1148
  var symbol = Symbol.for("dxos.instance-contexts");
1029
- var instanceContexts = globalThis[symbol] ??= /* @__PURE__ */ new WeakMap();
1149
+ var instanceContexts = (_globalThis = globalThis)[_symbol = symbol] ?? (_globalThis[_symbol] = /* @__PURE__ */ new WeakMap());
1030
1150
  var getPrototypeSpecificInstanceId = (instance) => {
1031
1151
  const prototype = Object.getPrototypeOf(instance);
1032
1152
  const instanceCtx = defaultMap(instanceContexts, prototype, () => ({
@@ -1109,7 +1229,7 @@ var arrayToString = (array) => arrayToBuffer(array).toString("hex");
1109
1229
  // src/json.ts
1110
1230
  var MAX_DEPTH = 5;
1111
1231
  var LOG_MAX_DEPTH = 7;
1112
- function jsonReplacer(key, value) {
1232
+ var jsonReplacer = (key, value) => {
1113
1233
  if (value !== null && typeof value === "object" && typeof value[inspect2.custom] === "function") {
1114
1234
  return value[inspect2.custom]();
1115
1235
  }
@@ -1122,7 +1242,7 @@ function jsonReplacer(key, value) {
1122
1242
  }
1123
1243
  }
1124
1244
  return value;
1125
- }
1245
+ };
1126
1246
  var jsonify = (value, depth = 0, visitedObjects = /* @__PURE__ */ new WeakSet()) => {
1127
1247
  if (depth > MAX_DEPTH) {
1128
1248
  return null;
@@ -1198,6 +1318,19 @@ var jsonKeyReplacer = (options = {}) => (key, value) => {
1198
1318
  };
1199
1319
 
1200
1320
  // src/map-values.ts
1321
+ function _define_property7(obj, key, value) {
1322
+ if (key in obj) {
1323
+ Object.defineProperty(obj, key, {
1324
+ value,
1325
+ enumerable: true,
1326
+ configurable: true,
1327
+ writable: true
1328
+ });
1329
+ } else {
1330
+ obj[key] = value;
1331
+ }
1332
+ return obj;
1333
+ }
1201
1334
  var mapValues = (obj, fn) => {
1202
1335
  const result = {};
1203
1336
  Object.keys(obj).forEach((key) => {
@@ -1209,7 +1342,19 @@ var deepMapValues = (value, fn) => {
1209
1342
  return new DeepMapper(fn).map(value);
1210
1343
  };
1211
1344
  var DeepMapper = class {
1345
+ map(value) {
1346
+ return this._map(value, void 0);
1347
+ }
1348
+ _map(value, key) {
1349
+ if (this._cyclic.has(value)) {
1350
+ return this._cyclic.get(value);
1351
+ }
1352
+ return this._fn(value, this._recurse, key);
1353
+ }
1212
1354
  constructor(_fn) {
1355
+ _define_property7(this, "_fn", void 0);
1356
+ _define_property7(this, "_cyclic", void 0);
1357
+ _define_property7(this, "_recurse", void 0);
1213
1358
  this._fn = _fn;
1214
1359
  this._cyclic = /* @__PURE__ */ new Map();
1215
1360
  this._recurse = (value) => {
@@ -1235,6 +1380,11 @@ var DeepMapper = class {
1235
1380
  }
1236
1381
  };
1237
1382
  }
1383
+ };
1384
+ var deepMapValuesAsync = (value, fn) => {
1385
+ return new DeepMapperAsync(fn).map(value);
1386
+ };
1387
+ var DeepMapperAsync = class {
1238
1388
  map(value) {
1239
1389
  return this._map(value, void 0);
1240
1390
  }
@@ -1244,12 +1394,10 @@ var DeepMapper = class {
1244
1394
  }
1245
1395
  return this._fn(value, this._recurse, key);
1246
1396
  }
1247
- };
1248
- var deepMapValuesAsync = (value, fn) => {
1249
- return new DeepMapperAsync(fn).map(value);
1250
- };
1251
- var DeepMapperAsync = class {
1252
1397
  constructor(_fn) {
1398
+ _define_property7(this, "_fn", void 0);
1399
+ _define_property7(this, "_cyclic", void 0);
1400
+ _define_property7(this, "_recurse", void 0);
1253
1401
  this._fn = _fn;
1254
1402
  this._cyclic = /* @__PURE__ */ new Map();
1255
1403
  this._recurse = async (value) => {
@@ -1275,15 +1423,6 @@ var DeepMapperAsync = class {
1275
1423
  }
1276
1424
  };
1277
1425
  }
1278
- map(value) {
1279
- return this._map(value, void 0);
1280
- }
1281
- _map(value, key) {
1282
- if (this._cyclic.has(value)) {
1283
- return this._cyclic.get(value);
1284
- }
1285
- return this._fn(value, this._recurse, key);
1286
- }
1287
1426
  };
1288
1427
  var visitValues = (object, visitor) => {
1289
1428
  if (Array.isArray(object)) {
@@ -1605,7 +1744,7 @@ var safeParseInt = (value, defaultValue) => {
1605
1744
  try {
1606
1745
  const n = parseInt(value ?? "");
1607
1746
  return isNaN(n) ? defaultValue : n;
1608
- } catch (err) {
1747
+ } catch {
1609
1748
  return defaultValue;
1610
1749
  }
1611
1750
  };
@@ -1620,7 +1759,7 @@ var safeParseJson = (data, defaultValue) => {
1620
1759
  if (data && data.length > 0) {
1621
1760
  try {
1622
1761
  return JSON.parse(data);
1623
- } catch (err) {
1762
+ } catch {
1624
1763
  }
1625
1764
  }
1626
1765
  return defaultValue;
@@ -1628,24 +1767,21 @@ var safeParseJson = (data, defaultValue) => {
1628
1767
 
1629
1768
  // src/sliding-window-summary.ts
1630
1769
  import { invariant as invariant5 } from "@dxos/invariant";
1770
+ function _define_property8(obj, key, value) {
1771
+ if (key in obj) {
1772
+ Object.defineProperty(obj, key, {
1773
+ value,
1774
+ enumerable: true,
1775
+ configurable: true,
1776
+ writable: true
1777
+ });
1778
+ } else {
1779
+ obj[key] = value;
1780
+ }
1781
+ return obj;
1782
+ }
1631
1783
  var __dxlog_file5 = "/__w/dxos/dxos/packages/common/util/src/sliding-window-summary.ts";
1632
1784
  var SlidingWindowSummary = class {
1633
- constructor(options) {
1634
- this._sum = 0;
1635
- this._buffer = new CircularBuffer(options.dataPoints);
1636
- if (options.precision != null) {
1637
- invariant5(options.precision >= 0, void 0, {
1638
- F: __dxlog_file5,
1639
- L: 26,
1640
- S: this,
1641
- A: [
1642
- "options.precision >= 0",
1643
- ""
1644
- ]
1645
- });
1646
- this._precision = Math.pow(10, options.precision);
1647
- }
1648
- }
1649
1785
  record(value) {
1650
1786
  const evicted = this._buffer.push(value);
1651
1787
  this._sum += value - (evicted ?? 0);
@@ -1680,6 +1816,24 @@ var SlidingWindowSummary = class {
1680
1816
  }
1681
1817
  return Math.round(value * this._precision) / this._precision;
1682
1818
  }
1819
+ constructor(options) {
1820
+ _define_property8(this, "_buffer", void 0);
1821
+ _define_property8(this, "_sum", 0);
1822
+ _define_property8(this, "_precision", void 0);
1823
+ this._buffer = new CircularBuffer(options.dataPoints);
1824
+ if (options.precision != null) {
1825
+ invariant5(options.precision >= 0, void 0, {
1826
+ F: __dxlog_file5,
1827
+ L: 26,
1828
+ S: this,
1829
+ A: [
1830
+ "options.precision >= 0",
1831
+ ""
1832
+ ]
1833
+ });
1834
+ this._precision = Math.pow(10, options.precision);
1835
+ }
1836
+ }
1683
1837
  };
1684
1838
 
1685
1839
  // src/sort.ts
@@ -1711,6 +1865,23 @@ var capitalize = (str) => {
1711
1865
  }
1712
1866
  return str.charAt(0).toUpperCase() + str.slice(1);
1713
1867
  };
1868
+ function trim(strings, ...values) {
1869
+ const raw = strings.reduce((out, str, i) => {
1870
+ out += str;
1871
+ if (i < values.length) {
1872
+ const match = str.match(/(^|\n)([ \t]*)$/);
1873
+ const baseIndent = match ? match[2] : "";
1874
+ const val = String(values[i]).replace(/\r?\n/g, "\n" + baseIndent);
1875
+ out += val;
1876
+ }
1877
+ return out;
1878
+ }, "");
1879
+ const lines = raw.split("\n");
1880
+ while (lines.length && !lines[0].trim()) lines.shift();
1881
+ while (lines.length && !lines[lines.length - 1].trim()) lines.pop();
1882
+ const minIndent = Math.min(...lines.filter((l) => l.trim()).map((l) => l.match(/^[ \t]*/)?.[0].length ?? 0));
1883
+ return lines.map((l) => l.slice(minIndent)).join("\n");
1884
+ }
1714
1885
 
1715
1886
  // src/sum.ts
1716
1887
  var sum = (values) => values.reduce((a, b) => a + b, 0);
@@ -1908,11 +2079,20 @@ var toFallback = (hash) => {
1908
2079
  };
1909
2080
 
1910
2081
  // src/tracer.ts
1911
- var Tracer = class {
1912
- constructor() {
1913
- this._events = /* @__PURE__ */ new Map();
1914
- this._recording = false;
2082
+ function _define_property9(obj, key, value) {
2083
+ if (key in obj) {
2084
+ Object.defineProperty(obj, key, {
2085
+ value,
2086
+ enumerable: true,
2087
+ configurable: true,
2088
+ writable: true
2089
+ });
2090
+ } else {
2091
+ obj[key] = value;
1915
2092
  }
2093
+ return obj;
2094
+ }
2095
+ var Tracer = class {
1916
2096
  // TODO(burdon): Start/stop methods for recording data? By id?
1917
2097
  // Alternatively, enable subscriptions to track/compute series.
1918
2098
  // TODO(burdon): Hierarchical traces?
@@ -1969,6 +2149,10 @@ var Tracer = class {
1969
2149
  defaultMap(this._events, event.id, []).push(event);
1970
2150
  }
1971
2151
  }
2152
+ constructor() {
2153
+ _define_property9(this, "_events", /* @__PURE__ */ new Map());
2154
+ _define_property9(this, "_recording", false);
2155
+ }
1972
2156
  };
1973
2157
  var tracer = new Tracer();
1974
2158
 
@@ -2013,7 +2197,7 @@ var stringifyTree = (node, ancestors = [], rows = []) => {
2013
2197
  };
2014
2198
 
2015
2199
  // src/types.ts
2016
- var isNotFalsy = (value) => !!value;
2200
+ var isTruthy = (value) => !!value;
2017
2201
  var isNonNullable = (value) => value != null;
2018
2202
  var doAsync = async (fn) => fn();
2019
2203
  var getProviderValue = (provider, arg) => {
@@ -2044,6 +2228,70 @@ var arrayMove = (array, from, to) => {
2044
2228
  return array;
2045
2229
  };
2046
2230
 
2231
+ // src/unit.ts
2232
+ var Formatter = (unit) => {
2233
+ return (n, precision = 2) => {
2234
+ const value = n / unit.quotient;
2235
+ return `${value.toFixed(precision)}${unit.symbol}`;
2236
+ };
2237
+ };
2238
+ var Unit = {
2239
+ // ms.
2240
+ Hour: Formatter({
2241
+ symbol: "h",
2242
+ quotient: 60 * 60 * 1e3
2243
+ }),
2244
+ Minute: Formatter({
2245
+ symbol: "m",
2246
+ quotient: 60 * 1e3
2247
+ }),
2248
+ Second: Formatter({
2249
+ symbol: "s",
2250
+ quotient: 1e3
2251
+ }),
2252
+ Millisecond: Formatter({
2253
+ symbol: "ms",
2254
+ quotient: 1
2255
+ }),
2256
+ Duration: (n) => {
2257
+ const hours = Math.floor(n / (60 * 60 * 1e3));
2258
+ const minutes = Math.floor(n % (60 * 60 * 1e3) / (60 * 1e3));
2259
+ if (hours) {
2260
+ return minutes ? `${hours}h ${minutes}m` : `${hours}h`;
2261
+ }
2262
+ const seconds = Math.floor(n % (60 * 1e3) / 1e3);
2263
+ if (minutes) {
2264
+ return seconds ? `${minutes}m ${seconds}s` : `${minutes}m`;
2265
+ }
2266
+ if (seconds) {
2267
+ return `${(n / 1e3).toFixed(1)}s`;
2268
+ }
2269
+ return `${n}ms`;
2270
+ },
2271
+ // bytes (note KB via KiB).
2272
+ Gigabyte: Formatter({
2273
+ symbol: "GB",
2274
+ quotient: 1e3 * 1e3 * 1e3
2275
+ }),
2276
+ Megabyte: Formatter({
2277
+ symbol: "MB",
2278
+ quotient: 1e3 * 1e3
2279
+ }),
2280
+ Kilobyte: Formatter({
2281
+ symbol: "KB",
2282
+ quotient: 1e3
2283
+ }),
2284
+ // general.
2285
+ Thousand: Formatter({
2286
+ symbol: "k",
2287
+ quotient: 1e3
2288
+ }),
2289
+ Percent: Formatter({
2290
+ symbol: "%",
2291
+ quotient: 1 / 100
2292
+ })
2293
+ };
2294
+
2047
2295
  // src/url.ts
2048
2296
  var createUrl = (url, search) => {
2049
2297
  const base = typeof url === "string" ? new URL(url) : url;
@@ -2054,18 +2302,20 @@ var createUrl = (url, search) => {
2054
2302
  };
2055
2303
 
2056
2304
  // src/weak.ts
2057
- var WeakDictionary = class {
2058
- constructor(entries2) {
2059
- this._internal = /* @__PURE__ */ new Map();
2060
- this._finalization = new FinalizationRegistry((cleanUpCallback) => {
2061
- cleanUpCallback();
2305
+ function _define_property10(obj, key, value) {
2306
+ if (key in obj) {
2307
+ Object.defineProperty(obj, key, {
2308
+ value,
2309
+ enumerable: true,
2310
+ configurable: true,
2311
+ writable: true
2062
2312
  });
2063
- this._internal = new Map(entries2?.map(([key, value]) => [
2064
- key,
2065
- new WeakRef(value)
2066
- ]));
2067
- entries2?.forEach(([key, value]) => this._register(key, value));
2313
+ } else {
2314
+ obj[key] = value;
2068
2315
  }
2316
+ return obj;
2317
+ }
2318
+ var WeakDictionary = class {
2069
2319
  *entries() {
2070
2320
  for (const [key, value] of this._internal) {
2071
2321
  yield [
@@ -2146,6 +2396,17 @@ var WeakDictionary = class {
2146
2396
  _unregister(value) {
2147
2397
  this._finalization.unregister(value);
2148
2398
  }
2399
+ constructor(entries2) {
2400
+ _define_property10(this, "_internal", /* @__PURE__ */ new Map());
2401
+ _define_property10(this, "_finalization", new FinalizationRegistry((cleanUpCallback) => {
2402
+ cleanUpCallback();
2403
+ }));
2404
+ this._internal = new Map(entries2?.map(([key, value]) => [
2405
+ key,
2406
+ new WeakRef(value)
2407
+ ]));
2408
+ entries2?.forEach(([key, value]) => this._register(key, value));
2409
+ }
2149
2410
  };
2150
2411
  export {
2151
2412
  BitField,
@@ -2158,6 +2419,7 @@ export {
2158
2419
  MapEntry,
2159
2420
  SlidingWindowSummary,
2160
2421
  Tracer,
2422
+ Unit,
2161
2423
  WeakDictionary,
2162
2424
  accessBy,
2163
2425
  arrayMove,
@@ -2200,7 +2462,6 @@ export {
2200
2462
  getDate,
2201
2463
  getDebugName,
2202
2464
  getDeep,
2203
- getFirstTwoRenderableChars,
2204
2465
  getHostPlatform,
2205
2466
  getPrototypeSpecificInstanceId,
2206
2467
  getProviderValue,
@@ -2218,7 +2479,7 @@ export {
2218
2479
  iosCheck,
2219
2480
  isNode,
2220
2481
  isNonNullable,
2221
- isNotFalsy,
2482
+ isTruthy,
2222
2483
  joinTables,
2223
2484
  jsonKeyReplacer,
2224
2485
  jsonReplacer,
@@ -2266,6 +2527,7 @@ export {
2266
2527
  toFallback,
2267
2528
  toHue,
2268
2529
  tracer,
2530
+ trim,
2269
2531
  visitValues
2270
2532
  };
2271
2533
  //# sourceMappingURL=index.mjs.map