@dxos/util 0.8.4-main.c1de068 → 0.8.4-main.dedc0f3

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.
@@ -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 "@dxos/node-std/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,6 +772,16 @@ var MapEntry = class {
651
772
  deep(key) {
652
773
  return entry(this.value, key);
653
774
  }
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
+ }
654
785
  };
655
786
 
656
787
  // src/first-two-chars.ts
@@ -685,6 +816,19 @@ var forEachAsync = (items, fn) => Promise.all(items.map(fn));
685
816
 
686
817
  // src/human-hash.ts
687
818
  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
+ }
688
832
  var DEFAULT_WORDLIST = [
689
833
  "ack",
690
834
  "alabama",
@@ -944,26 +1088,6 @@ var DEFAULT_WORDLIST = [
944
1088
  "zulu"
945
1089
  ];
946
1090
  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
1091
  /**
968
1092
  * Humanize a given hexadecimal digest.
969
1093
  *
@@ -1003,6 +1127,27 @@ var HumanHasher = class {
1003
1127
  const checksums = segments.map((x) => x.reduce((acc, curr) => acc ^ curr));
1004
1128
  return checksums;
1005
1129
  }
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
+ }
1006
1151
  };
1007
1152
  var hasher = new HumanHasher();
1008
1153
  var humanize = (value) => {
@@ -1025,8 +1170,10 @@ var defaultMap = (map, key, def) => {
1025
1170
  };
1026
1171
 
1027
1172
  // src/instance-id.ts
1173
+ var _globalThis;
1174
+ var _symbol;
1028
1175
  var symbol = Symbol.for("dxos.instance-contexts");
1029
- var instanceContexts = globalThis[symbol] ??= /* @__PURE__ */ new WeakMap();
1176
+ var instanceContexts = (_globalThis = globalThis)[_symbol = symbol] ?? (_globalThis[_symbol] = /* @__PURE__ */ new WeakMap());
1030
1177
  var getPrototypeSpecificInstanceId = (instance) => {
1031
1178
  const prototype = Object.getPrototypeOf(instance);
1032
1179
  const instanceCtx = defaultMap(instanceContexts, prototype, () => ({
@@ -1198,6 +1345,19 @@ var jsonKeyReplacer = (options = {}) => (key, value) => {
1198
1345
  };
1199
1346
 
1200
1347
  // 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
+ }
1201
1361
  var mapValues = (obj, fn) => {
1202
1362
  const result = {};
1203
1363
  Object.keys(obj).forEach((key) => {
@@ -1209,7 +1369,19 @@ var deepMapValues = (value, fn) => {
1209
1369
  return new DeepMapper(fn).map(value);
1210
1370
  };
1211
1371
  var DeepMapper = class {
1372
+ map(value) {
1373
+ return this._map(value, void 0);
1374
+ }
1375
+ _map(value, key) {
1376
+ if (this._cyclic.has(value)) {
1377
+ return this._cyclic.get(value);
1378
+ }
1379
+ return this._fn(value, this._recurse, key);
1380
+ }
1212
1381
  constructor(_fn) {
1382
+ _define_property7(this, "_fn", void 0);
1383
+ _define_property7(this, "_cyclic", void 0);
1384
+ _define_property7(this, "_recurse", void 0);
1213
1385
  this._fn = _fn;
1214
1386
  this._cyclic = /* @__PURE__ */ new Map();
1215
1387
  this._recurse = (value) => {
@@ -1235,6 +1407,11 @@ var DeepMapper = class {
1235
1407
  }
1236
1408
  };
1237
1409
  }
1410
+ };
1411
+ var deepMapValuesAsync = (value, fn) => {
1412
+ return new DeepMapperAsync(fn).map(value);
1413
+ };
1414
+ var DeepMapperAsync = class {
1238
1415
  map(value) {
1239
1416
  return this._map(value, void 0);
1240
1417
  }
@@ -1244,12 +1421,10 @@ var DeepMapper = class {
1244
1421
  }
1245
1422
  return this._fn(value, this._recurse, key);
1246
1423
  }
1247
- };
1248
- var deepMapValuesAsync = (value, fn) => {
1249
- return new DeepMapperAsync(fn).map(value);
1250
- };
1251
- var DeepMapperAsync = class {
1252
1424
  constructor(_fn) {
1425
+ _define_property7(this, "_fn", void 0);
1426
+ _define_property7(this, "_cyclic", void 0);
1427
+ _define_property7(this, "_recurse", void 0);
1253
1428
  this._fn = _fn;
1254
1429
  this._cyclic = /* @__PURE__ */ new Map();
1255
1430
  this._recurse = async (value) => {
@@ -1275,15 +1450,6 @@ var DeepMapperAsync = class {
1275
1450
  }
1276
1451
  };
1277
1452
  }
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
1453
  };
1288
1454
  var visitValues = (object, visitor) => {
1289
1455
  if (Array.isArray(object)) {
@@ -1605,7 +1771,7 @@ var safeParseInt = (value, defaultValue) => {
1605
1771
  try {
1606
1772
  const n = parseInt(value ?? "");
1607
1773
  return isNaN(n) ? defaultValue : n;
1608
- } catch (err) {
1774
+ } catch {
1609
1775
  return defaultValue;
1610
1776
  }
1611
1777
  };
@@ -1620,7 +1786,7 @@ var safeParseJson = (data, defaultValue) => {
1620
1786
  if (data && data.length > 0) {
1621
1787
  try {
1622
1788
  return JSON.parse(data);
1623
- } catch (err) {
1789
+ } catch {
1624
1790
  }
1625
1791
  }
1626
1792
  return defaultValue;
@@ -1628,24 +1794,21 @@ var safeParseJson = (data, defaultValue) => {
1628
1794
 
1629
1795
  // src/sliding-window-summary.ts
1630
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;
1807
+ }
1808
+ return obj;
1809
+ }
1631
1810
  var __dxlog_file5 = "/__w/dxos/dxos/packages/common/util/src/sliding-window-summary.ts";
1632
1811
  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
1812
  record(value) {
1650
1813
  const evicted = this._buffer.push(value);
1651
1814
  this._sum += value - (evicted ?? 0);
@@ -1680,6 +1843,24 @@ var SlidingWindowSummary = class {
1680
1843
  }
1681
1844
  return Math.round(value * this._precision) / this._precision;
1682
1845
  }
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
+ }
1683
1864
  };
1684
1865
 
1685
1866
  // src/sort.ts
@@ -1711,12 +1892,23 @@ var capitalize = (str) => {
1711
1892
  }
1712
1893
  return str.charAt(0).toUpperCase() + str.slice(1);
1713
1894
  };
1714
- var trim = (strings, ...values) => {
1715
- const full = String.raw(strings, ...values);
1716
- const lines = full.replace(/^\n/, "").split("\n");
1717
- const indent = Math.min(...lines.filter((l) => l.trim()).map((l) => l.match(/^ */)[0].length));
1718
- return lines.map((l) => l.slice(indent)).join("\n");
1719
- };
1895
+ function trim(strings, ...values) {
1896
+ const raw = strings.reduce((out, str, i) => {
1897
+ out += str;
1898
+ if (i < values.length) {
1899
+ const match = str.match(/(^|\n)([ \t]*)$/);
1900
+ const baseIndent = match ? match[2] : "";
1901
+ const val = String(values[i]).replace(/\r?\n/g, "\n" + baseIndent);
1902
+ out += val;
1903
+ }
1904
+ return out;
1905
+ }, "");
1906
+ const lines = raw.split("\n");
1907
+ while (lines.length && !lines[0].trim()) lines.shift();
1908
+ while (lines.length && !lines[lines.length - 1].trim()) lines.pop();
1909
+ const minIndent = Math.min(...lines.filter((l) => l.trim()).map((l) => l.match(/^[ \t]*/)?.[0].length ?? 0));
1910
+ return lines.map((l) => l.slice(minIndent)).join("\n");
1911
+ }
1720
1912
 
1721
1913
  // src/sum.ts
1722
1914
  var sum = (values) => values.reduce((a, b) => a + b, 0);
@@ -1914,11 +2106,20 @@ var toFallback = (hash) => {
1914
2106
  };
1915
2107
 
1916
2108
  // src/tracer.ts
1917
- var Tracer = class {
1918
- constructor() {
1919
- this._events = /* @__PURE__ */ new Map();
1920
- this._recording = false;
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;
1921
2119
  }
2120
+ return obj;
2121
+ }
2122
+ var Tracer = class {
1922
2123
  // TODO(burdon): Start/stop methods for recording data? By id?
1923
2124
  // Alternatively, enable subscriptions to track/compute series.
1924
2125
  // TODO(burdon): Hierarchical traces?
@@ -1975,6 +2176,10 @@ var Tracer = class {
1975
2176
  defaultMap(this._events, event.id, []).push(event);
1976
2177
  }
1977
2178
  }
2179
+ constructor() {
2180
+ _define_property9(this, "_events", /* @__PURE__ */ new Map());
2181
+ _define_property9(this, "_recording", false);
2182
+ }
1978
2183
  };
1979
2184
  var tracer = new Tracer();
1980
2185
 
@@ -2050,6 +2255,70 @@ var arrayMove = (array, from, to) => {
2050
2255
  return array;
2051
2256
  };
2052
2257
 
2258
+ // src/unit.ts
2259
+ var Formatter = (unit) => {
2260
+ return (n, precision = 2) => {
2261
+ const value = n / unit.quotient;
2262
+ return `${value.toFixed(precision)}${unit.symbol}`;
2263
+ };
2264
+ };
2265
+ var Unit = {
2266
+ // ms.
2267
+ Hour: Formatter({
2268
+ symbol: "h",
2269
+ quotient: 60 * 60 * 1e3
2270
+ }),
2271
+ Minute: Formatter({
2272
+ symbol: "m",
2273
+ quotient: 60 * 1e3
2274
+ }),
2275
+ Second: Formatter({
2276
+ symbol: "s",
2277
+ quotient: 1e3
2278
+ }),
2279
+ Millisecond: Formatter({
2280
+ symbol: "ms",
2281
+ quotient: 1
2282
+ }),
2283
+ Duration: (n) => {
2284
+ const hours = Math.floor(n / (60 * 60 * 1e3));
2285
+ const minutes = Math.floor(n % (60 * 60 * 1e3) / (60 * 1e3));
2286
+ if (hours) {
2287
+ return minutes ? `${hours}h ${minutes}m` : `${hours}h`;
2288
+ }
2289
+ const seconds = Math.floor(n % (60 * 1e3) / 1e3);
2290
+ if (minutes) {
2291
+ return seconds ? `${minutes}m ${seconds}s` : `${minutes}m`;
2292
+ }
2293
+ if (seconds) {
2294
+ return `${(n / 1e3).toFixed(1)}s`;
2295
+ }
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
+ })
2320
+ };
2321
+
2053
2322
  // src/url.ts
2054
2323
  var createUrl = (url, search) => {
2055
2324
  const base = typeof url === "string" ? new URL(url) : url;
@@ -2060,18 +2329,20 @@ var createUrl = (url, search) => {
2060
2329
  };
2061
2330
 
2062
2331
  // src/weak.ts
2063
- var WeakDictionary = class {
2064
- constructor(entries2) {
2065
- this._internal = /* @__PURE__ */ new Map();
2066
- this._finalization = new FinalizationRegistry((cleanUpCallback) => {
2067
- cleanUpCallback();
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
2068
2339
  });
2069
- this._internal = new Map(entries2?.map(([key, value]) => [
2070
- key,
2071
- new WeakRef(value)
2072
- ]));
2073
- entries2?.forEach(([key, value]) => this._register(key, value));
2340
+ } else {
2341
+ obj[key] = value;
2074
2342
  }
2343
+ return obj;
2344
+ }
2345
+ var WeakDictionary = class {
2075
2346
  *entries() {
2076
2347
  for (const [key, value] of this._internal) {
2077
2348
  yield [
@@ -2152,6 +2423,17 @@ var WeakDictionary = class {
2152
2423
  _unregister(value) {
2153
2424
  this._finalization.unregister(value);
2154
2425
  }
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));
2436
+ }
2155
2437
  };
2156
2438
  export {
2157
2439
  BitField,
@@ -2164,6 +2446,7 @@ export {
2164
2446
  MapEntry,
2165
2447
  SlidingWindowSummary,
2166
2448
  Tracer,
2449
+ Unit,
2167
2450
  WeakDictionary,
2168
2451
  accessBy,
2169
2452
  arrayMove,