@dxos/util 0.8.4-main.fd6878d → 0.8.4-main.fdfb99ef29

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 (125) hide show
  1. package/dist/lib/browser/index.mjs +531 -201
  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 +531 -201
  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-to-hex.d.ts.map +1 -1
  8. package/dist/types/src/array.d.ts +3 -2
  9. package/dist/types/src/array.d.ts.map +1 -1
  10. package/dist/types/src/binder.d.ts.map +1 -1
  11. package/dist/types/src/bitfield.d.ts.map +1 -1
  12. package/dist/types/src/browser-storage.d.ts +9 -0
  13. package/dist/types/src/browser-storage.d.ts.map +1 -0
  14. package/dist/types/src/callback-collection.d.ts.map +1 -1
  15. package/dist/types/src/callback.d.ts.map +1 -1
  16. package/dist/types/src/case.d.ts.map +1 -1
  17. package/dist/types/src/chunk-array.d.ts.map +1 -1
  18. package/dist/types/src/circular-buffer.d.ts +1 -0
  19. package/dist/types/src/circular-buffer.d.ts.map +1 -1
  20. package/dist/types/src/clear-undefined.d.ts.map +1 -1
  21. package/dist/types/src/complex.d.ts +15 -0
  22. package/dist/types/src/complex.d.ts.map +1 -1
  23. package/dist/types/src/composite-key.d.ts +10 -0
  24. package/dist/types/src/composite-key.d.ts.map +1 -0
  25. package/dist/types/src/composite-key.test.d.ts +2 -0
  26. package/dist/types/src/composite-key.test.d.ts.map +1 -0
  27. package/dist/types/src/deep.d.ts +0 -3
  28. package/dist/types/src/deep.d.ts.map +1 -1
  29. package/dist/types/src/defer-function.d.ts.map +1 -1
  30. package/dist/types/src/defer.d.ts +1 -1
  31. package/dist/types/src/defer.d.ts.map +1 -1
  32. package/dist/types/src/di-container.d.ts.map +1 -1
  33. package/dist/types/src/di-key.d.ts +7 -5
  34. package/dist/types/src/di-key.d.ts.map +1 -1
  35. package/dist/types/src/entry.d.ts.map +1 -1
  36. package/dist/types/src/error-format.d.ts +5 -0
  37. package/dist/types/src/error-format.d.ts.map +1 -0
  38. package/dist/types/src/filename.d.ts +9 -0
  39. package/dist/types/src/filename.d.ts.map +1 -0
  40. package/dist/types/src/for-each-async.d.ts.map +1 -1
  41. package/dist/types/src/human-hash.d.ts.map +1 -1
  42. package/dist/types/src/index.d.ts +7 -1
  43. package/dist/types/src/index.d.ts.map +1 -1
  44. package/dist/types/src/instance-id.d.ts.map +1 -1
  45. package/dist/types/src/interval.d.ts.map +1 -1
  46. package/dist/types/src/join-tables.d.ts.map +1 -1
  47. package/dist/types/src/json.d.ts.map +1 -1
  48. package/dist/types/src/map-values.d.ts.map +1 -1
  49. package/dist/types/src/map.d.ts.map +1 -1
  50. package/dist/types/src/object.d.ts.map +1 -1
  51. package/dist/types/src/order-keys.d.ts.map +1 -1
  52. package/dist/types/src/order.d.ts.map +1 -1
  53. package/dist/types/src/pick.d.ts.map +1 -1
  54. package/dist/types/src/platform.d.ts +5 -2
  55. package/dist/types/src/platform.d.ts.map +1 -1
  56. package/dist/types/src/position.d.ts +1 -1
  57. package/dist/types/src/position.d.ts.map +1 -1
  58. package/dist/types/src/random.d.ts.map +1 -1
  59. package/dist/types/src/range.d.ts.map +1 -1
  60. package/dist/types/src/reducers.d.ts.map +1 -1
  61. package/dist/types/src/remove-undefined-keys.d.ts.map +1 -1
  62. package/dist/types/src/retry.d.ts +32 -0
  63. package/dist/types/src/retry.d.ts.map +1 -0
  64. package/dist/types/src/safe-await.d.ts.map +1 -1
  65. package/dist/types/src/safe-instanceof.d.ts.map +1 -1
  66. package/dist/types/src/safe-parse.d.ts +7 -4
  67. package/dist/types/src/safe-parse.d.ts.map +1 -1
  68. package/dist/types/src/safe-stringify.d.ts +22 -0
  69. package/dist/types/src/safe-stringify.d.ts.map +1 -0
  70. package/dist/types/src/safe-stringify.test.d.ts +2 -0
  71. package/dist/types/src/safe-stringify.test.d.ts.map +1 -0
  72. package/dist/types/src/sliding-window-summary.d.ts.map +1 -1
  73. package/dist/types/src/sort.d.ts.map +1 -1
  74. package/dist/types/src/string.d.ts +4 -0
  75. package/dist/types/src/string.d.ts.map +1 -1
  76. package/dist/types/src/sum.d.ts.map +1 -1
  77. package/dist/types/src/throw-unhandled-error.d.ts.map +1 -1
  78. package/dist/types/src/to-fallback.d.ts +18 -4
  79. package/dist/types/src/to-fallback.d.ts.map +1 -1
  80. package/dist/types/src/tracer.d.ts.map +1 -1
  81. package/dist/types/src/tree.d.ts.map +1 -1
  82. package/dist/types/src/types.d.ts +24 -6
  83. package/dist/types/src/types.d.ts.map +1 -1
  84. package/dist/types/src/uint8array.d.ts.map +1 -1
  85. package/dist/types/src/unit.d.ts +14 -0
  86. package/dist/types/src/unit.d.ts.map +1 -0
  87. package/dist/types/src/unit.test.d.ts +2 -0
  88. package/dist/types/src/unit.test.d.ts.map +1 -0
  89. package/dist/types/src/url.d.ts.map +1 -1
  90. package/dist/types/src/weak.d.ts +15 -0
  91. package/dist/types/src/weak.d.ts.map +1 -1
  92. package/dist/types/tsconfig.tsbuildinfo +1 -1
  93. package/package.json +12 -14
  94. package/src/array.ts +9 -2
  95. package/src/binder.ts +2 -2
  96. package/src/browser-storage.ts +60 -0
  97. package/src/circular-buffer.test.ts +26 -0
  98. package/src/circular-buffer.ts +5 -0
  99. package/src/complex.ts +32 -0
  100. package/src/composite-key.test.ts +31 -0
  101. package/src/composite-key.ts +16 -0
  102. package/src/deep.ts +2 -6
  103. package/src/defer.ts +1 -1
  104. package/src/di-key.ts +10 -8
  105. package/src/error-format.ts +24 -0
  106. package/src/filename.ts +16 -0
  107. package/src/index.ts +7 -1
  108. package/src/platform.ts +35 -3
  109. package/src/retry.ts +74 -0
  110. package/src/safe-parse.ts +29 -17
  111. package/src/safe-stringify.test.ts +96 -0
  112. package/src/safe-stringify.ts +153 -0
  113. package/src/string.ts +13 -2
  114. package/src/to-fallback.ts +44 -160
  115. package/src/types.test.ts +11 -1
  116. package/src/types.ts +40 -12
  117. package/src/unit.test.ts +25 -0
  118. package/src/unit.ts +87 -0
  119. package/src/weak.ts +52 -14
  120. package/dist/types/src/explicit-resource-management-polyfill.d.ts +0 -1
  121. package/dist/types/src/explicit-resource-management-polyfill.d.ts.map +0 -1
  122. package/dist/types/src/first-two-chars.d.ts +0 -9
  123. package/dist/types/src/first-two-chars.d.ts.map +0 -1
  124. package/src/explicit-resource-management-polyfill.ts +0 -13
  125. package/src/first-two-chars.ts +0 -44
@@ -97,21 +97,28 @@ 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
113
121
  import { invariant } from "@dxos/invariant";
114
- var __dxlog_file = "/__w/dxos/dxos/packages/common/util/src/bitfield.ts";
115
122
  var BitField = class _BitField {
116
123
  static get(data, idx) {
117
124
  const bit = data[idx >> 3] >> 7 - idx % 8 & 1;
@@ -143,15 +150,7 @@ var BitField = class _BitField {
143
150
  return result;
144
151
  }
145
152
  static and(first, second) {
146
- invariant(first.length === second.length, "Bitfields must be of the same length", {
147
- F: __dxlog_file,
148
- L: 52,
149
- S: this,
150
- A: [
151
- "first.length === second.length",
152
- "'Bitfields must be of the same length'"
153
- ]
154
- });
153
+ invariant(first.length === second.length, "Bitfields must be of the same length");
155
154
  const result = new Uint8Array(first.length);
156
155
  for (let i = 0; i < first.length; i++) {
157
156
  result[i] = first[i] & second[i];
@@ -179,6 +178,49 @@ var BitField = class _BitField {
179
178
  }
180
179
  };
181
180
 
181
+ // src/browser-storage.ts
182
+ var clearIndexedDB = async () => {
183
+ const dbs = await indexedDB.databases();
184
+ const results = await Promise.allSettled(dbs.filter((db) => db.name != null).map((db) => new Promise((resolve, reject) => {
185
+ const request = indexedDB.deleteDatabase(db.name);
186
+ request.onsuccess = () => resolve();
187
+ request.onerror = () => reject(request.error);
188
+ request.onblocked = () => reject(new Error(`IndexedDB deletion blocked: ${db.name}`));
189
+ })));
190
+ const failures = results.filter((r) => r.status === "rejected");
191
+ if (failures.length > 0) {
192
+ throw new AggregateError(failures.map((r) => r.reason), "Failed to delete some IndexedDB databases");
193
+ }
194
+ };
195
+ var clearOPFS = async () => {
196
+ const root = await navigator.storage.getDirectory();
197
+ const errors = [];
198
+ for await (const [name] of root.entries()) {
199
+ try {
200
+ await root.removeEntry(name, {
201
+ recursive: true
202
+ });
203
+ } catch (err) {
204
+ errors.push(err);
205
+ }
206
+ }
207
+ if (errors.length > 0) {
208
+ throw new AggregateError(errors, "Failed to remove some OPFS entries");
209
+ }
210
+ };
211
+ var clearServiceWorkers = async () => {
212
+ const regs = await navigator.serviceWorker.getRegistrations();
213
+ for (const reg of regs) {
214
+ await reg.unregister();
215
+ }
216
+ };
217
+ var clearCaches = async () => {
218
+ const keys2 = await caches.keys();
219
+ for (const key of keys2) {
220
+ await caches.delete(key);
221
+ }
222
+ };
223
+
182
224
  // src/callback-collection.ts
183
225
  var CallbackCollection = class {
184
226
  #callbacks = [];
@@ -205,34 +247,17 @@ var CallbackCollection = class {
205
247
 
206
248
  // src/callback.ts
207
249
  import { invariant as invariant2 } from "@dxos/invariant";
208
- var __dxlog_file2 = "/__w/dxos/dxos/packages/common/util/src/callback.ts";
209
250
  var Callback = class {
210
251
  _callback;
211
252
  call(...args) {
212
- invariant2(this._callback, "Callback not set", {
213
- F: __dxlog_file2,
214
- L: 20,
215
- S: this,
216
- A: [
217
- "this._callback",
218
- "'Callback not set'"
219
- ]
220
- });
253
+ invariant2(this._callback, "Callback not set");
221
254
  return this._callback(...args);
222
255
  }
223
256
  callIfSet(...args) {
224
257
  return this._callback?.(...args);
225
258
  }
226
259
  set(callback) {
227
- invariant2(!this._callback, "Callback already set", {
228
- F: __dxlog_file2,
229
- L: 29,
230
- S: this,
231
- A: [
232
- "!this._callback",
233
- "'Callback already set'"
234
- ]
235
- });
260
+ invariant2(!this._callback, "Callback already set");
236
261
  this._callback = callback;
237
262
  }
238
263
  isSet() {
@@ -300,21 +325,12 @@ var chunkArray = (array, size) => {
300
325
 
301
326
  // src/circular-buffer.ts
302
327
  import { invariant as invariant3 } from "@dxos/invariant";
303
- var __dxlog_file3 = "/__w/dxos/dxos/packages/common/util/src/circular-buffer.ts";
304
328
  var CircularBuffer = class {
305
329
  _buffer;
306
330
  _nextIndex = 0;
307
331
  _elementCount = 0;
308
332
  constructor(size) {
309
- invariant3(size >= 1, void 0, {
310
- F: __dxlog_file3,
311
- L: 13,
312
- S: this,
313
- A: [
314
- "size >= 1",
315
- ""
316
- ]
317
- });
333
+ invariant3(size >= 1);
318
334
  this._buffer = new Array(size);
319
335
  }
320
336
  push(element) {
@@ -327,6 +343,10 @@ var CircularBuffer = class {
327
343
  get elementCount() {
328
344
  return this._elementCount;
329
345
  }
346
+ clear() {
347
+ this._nextIndex = 0;
348
+ this._elementCount = 0;
349
+ }
330
350
  getLast() {
331
351
  if (this._elementCount === 0) {
332
352
  return void 0;
@@ -377,11 +397,10 @@ import { inspectObject, raise } from "@dxos/debug";
377
397
  var MAX_SERIALIZATION_LENGTH = 10;
378
398
  var ComplexSet = class {
379
399
  _projection;
380
- _values;
400
+ _values = /* @__PURE__ */ new Map();
381
401
  // prettier-ignore
382
402
  constructor(_projection, values) {
383
403
  this._projection = _projection;
384
- this._values = /* @__PURE__ */ new Map();
385
404
  if (values) {
386
405
  for (const value of values) {
387
406
  this.add(value);
@@ -472,13 +491,11 @@ var makeSet = (projection) => {
472
491
  };
473
492
  var ComplexMap = class _ComplexMap {
474
493
  _keyProjection;
475
- _keys;
476
- _values;
494
+ _keys = /* @__PURE__ */ new Map();
495
+ _values = /* @__PURE__ */ new Map();
477
496
  // prettier-ignore
478
497
  constructor(_keyProjection, entries2) {
479
498
  this._keyProjection = _keyProjection;
480
- this._keys = /* @__PURE__ */ new Map();
481
- this._values = /* @__PURE__ */ new Map();
482
499
  if (entries2) {
483
500
  for (const [key, value] of entries2) {
484
501
  this.set(key, value);
@@ -523,6 +540,36 @@ var ComplexMap = class _ComplexMap {
523
540
  this._values.set(primitive, value);
524
541
  return this;
525
542
  }
543
+ /**
544
+ * Returns the value for the given key if present, otherwise inserts and returns the default value.
545
+ * @param key - The key to look up or insert.
546
+ * @param defaultValue - The value to insert if the key is not present.
547
+ * @returns The existing or newly inserted value.
548
+ */
549
+ getOrInsert(key, defaultValue) {
550
+ const primitive = this._keyProjection(key);
551
+ if (this._values.has(primitive)) {
552
+ return this._values.get(primitive);
553
+ }
554
+ this.set(key, defaultValue);
555
+ return defaultValue;
556
+ }
557
+ /**
558
+ * Returns the value for the given key if present, otherwise computes, inserts, and returns a new value.
559
+ * The callback is only invoked when the key is missing.
560
+ * @param key - The key to look up or insert.
561
+ * @param callbackfn - Function to compute the value if the key is not present.
562
+ * @returns The existing or newly computed value.
563
+ */
564
+ getOrInsertComputed(key, callbackfn) {
565
+ const primitive = this._keyProjection(key);
566
+ if (this._values.has(primitive)) {
567
+ return this._values.get(primitive);
568
+ }
569
+ const value = callbackfn(key);
570
+ this.set(key, value);
571
+ return value;
572
+ }
526
573
  get size() {
527
574
  return this._keys.size;
528
575
  }
@@ -562,21 +609,15 @@ var makeMap = (keyProjection) => class BoundComplexMap extends ComplexMap {
562
609
  }
563
610
  };
564
611
 
612
+ // src/composite-key.ts
613
+ var SEPARATOR = ":";
614
+ var compositeKey = (...parts) => parts.join(SEPARATOR);
615
+ var splitCompositeKey = (key) => key.split(SEPARATOR);
616
+
565
617
  // src/deep.ts
566
- import get from "lodash.get";
567
- import set from "lodash.set";
568
618
  import { invariant as invariant4 } from "@dxos/invariant";
569
- var __dxlog_file4 = "/__w/dxos/dxos/packages/common/util/src/deep.ts";
570
619
  var setDeep = (obj, path, value) => {
571
- invariant4(path.length > 0, void 0, {
572
- F: __dxlog_file4,
573
- L: 18,
574
- S: void 0,
575
- A: [
576
- "path.length > 0",
577
- ""
578
- ]
579
- });
620
+ invariant4(path.length > 0);
580
621
  let parent = obj;
581
622
  for (const key of path.slice(0, -1)) {
582
623
  if (parent[key] === void 0) {
@@ -599,11 +640,8 @@ var getDeep = (obj, path) => {
599
640
  // src/defer-function.ts
600
641
  var deferFunction = (fnProvider) => (...args) => fnProvider()(...args);
601
642
 
602
- // src/explicit-resource-management-polyfill.ts
603
- Symbol.dispose ??= Symbol("Symbol.dispose");
604
- Symbol.asyncDispose ??= Symbol("Symbol.asyncDispose");
605
-
606
643
  // src/defer.ts
644
+ import "@hazae41/symbol-dispose-polyfill";
607
645
  var defer = (fn) => new DeferGuard(fn);
608
646
  var DeferGuard = class {
609
647
  _fn;
@@ -664,33 +702,29 @@ var MapEntry = class {
664
702
  }
665
703
  };
666
704
 
667
- // src/first-two-chars.ts
668
- var renderableCharRegex = /^(?![\p{Control}\p{Mark}\p{Separator}\p{Surrogate}\p{Unassigned}\p{P}])[\p{L}\p{N}\p{S}\p{Emoji}]$/u;
669
- var getFirstTwoRenderableChars = (label) => {
670
- const characters = Array.from(label);
671
- const result = [
672
- "",
673
- ""
674
- ];
675
- let foundFirst = false;
676
- for (let i = 0; i < characters.length; i++) {
677
- const char = characters[i];
678
- if (renderableCharRegex.test(char)) {
679
- if (!foundFirst) {
680
- result[0] = char;
681
- foundFirst = true;
682
- } else {
683
- const textBetween = characters.slice(result[0].length, i).join("");
684
- if (/[^\p{L}\p{N}_]/u.test(textBetween)) {
685
- result[1] = char;
686
- break;
687
- }
688
- }
689
- }
690
- }
691
- return result;
705
+ // src/error-format.ts
706
+ var formatErrorWithCauses = (error) => {
707
+ const lines = [];
708
+ let current = error;
709
+ let level = 0;
710
+ while (current) {
711
+ const prefix = level === 0 ? "" : `Caused by: `;
712
+ lines.push(prefix + (current.stack ?? String(current)));
713
+ if (!(current.cause instanceof Error)) {
714
+ break;
715
+ }
716
+ current = current.cause;
717
+ level += 1;
718
+ }
719
+ return lines.join("\n\n");
692
720
  };
693
721
 
722
+ // src/filename.ts
723
+ var createFilename = ({ parts = [], ext, date = /* @__PURE__ */ new Date() }) => [
724
+ date.toISOString().replace(/[:.]/g, "-"),
725
+ ...parts
726
+ ].join("_") + (ext ? `.${ext}` : "");
727
+
694
728
  // src/for-each-async.ts
695
729
  var forEachAsync = (items, fn) => Promise.all(items.map(fn));
696
730
 
@@ -1037,7 +1071,7 @@ var defaultMap = (map, key, def) => {
1037
1071
  };
1038
1072
 
1039
1073
  // src/instance-id.ts
1040
- var symbol = Symbol.for("dxos.instance-contexts");
1074
+ var symbol = /* @__PURE__ */ Symbol.for("dxos.instance-contexts");
1041
1075
  var instanceContexts = globalThis[symbol] ??= /* @__PURE__ */ new WeakMap();
1042
1076
  var getPrototypeSpecificInstanceId = (instance) => {
1043
1077
  const prototype = Object.getPrototypeOf(instance);
@@ -1222,32 +1256,9 @@ var deepMapValues = (value, fn) => {
1222
1256
  };
1223
1257
  var DeepMapper = class {
1224
1258
  _fn;
1225
- _cyclic;
1259
+ _cyclic = /* @__PURE__ */ new Map();
1226
1260
  constructor(_fn) {
1227
1261
  this._fn = _fn;
1228
- this._cyclic = /* @__PURE__ */ new Map();
1229
- this._recurse = (value) => {
1230
- if (this._cyclic.has(value)) {
1231
- return this._cyclic.get(value);
1232
- }
1233
- if (Array.isArray(value)) {
1234
- const res = new Array(value.length);
1235
- this._cyclic.set(value, res);
1236
- for (let i = 0; i < value.length; i++) {
1237
- res[i] = this._map(value[i], i);
1238
- }
1239
- return res;
1240
- } else if (value !== null && typeof value === "object") {
1241
- const res = {};
1242
- this._cyclic.set(value, res);
1243
- for (const key in value) {
1244
- res[key] = this._map(value[key], key);
1245
- }
1246
- return res;
1247
- } else {
1248
- return value;
1249
- }
1250
- };
1251
1262
  }
1252
1263
  map(value) {
1253
1264
  return this._map(value, void 0);
@@ -1258,39 +1269,37 @@ var DeepMapper = class {
1258
1269
  }
1259
1270
  return this._fn(value, this._recurse, key);
1260
1271
  }
1261
- _recurse;
1272
+ _recurse = (value) => {
1273
+ if (this._cyclic.has(value)) {
1274
+ return this._cyclic.get(value);
1275
+ }
1276
+ if (Array.isArray(value)) {
1277
+ const res = new Array(value.length);
1278
+ this._cyclic.set(value, res);
1279
+ for (let i = 0; i < value.length; i++) {
1280
+ res[i] = this._map(value[i], i);
1281
+ }
1282
+ return res;
1283
+ } else if (value !== null && typeof value === "object") {
1284
+ const res = {};
1285
+ this._cyclic.set(value, res);
1286
+ for (const key in value) {
1287
+ res[key] = this._map(value[key], key);
1288
+ }
1289
+ return res;
1290
+ } else {
1291
+ return value;
1292
+ }
1293
+ };
1262
1294
  };
1263
1295
  var deepMapValuesAsync = (value, fn) => {
1264
1296
  return new DeepMapperAsync(fn).map(value);
1265
1297
  };
1266
1298
  var DeepMapperAsync = class {
1267
1299
  _fn;
1268
- _cyclic;
1300
+ _cyclic = /* @__PURE__ */ new Map();
1269
1301
  constructor(_fn) {
1270
1302
  this._fn = _fn;
1271
- this._cyclic = /* @__PURE__ */ new Map();
1272
- this._recurse = async (value) => {
1273
- if (this._cyclic.has(value)) {
1274
- return this._cyclic.get(value);
1275
- }
1276
- if (Array.isArray(value)) {
1277
- const res = new Array(value.length);
1278
- this._cyclic.set(value, res);
1279
- for (let i = 0; i < value.length; i++) {
1280
- res[i] = await this._map(value[i], i);
1281
- }
1282
- return res;
1283
- } else if (value !== null && typeof value === "object") {
1284
- const res = {};
1285
- this._cyclic.set(value, res);
1286
- for (const key in value) {
1287
- res[key] = await this._map(value[key], key);
1288
- }
1289
- return res;
1290
- } else {
1291
- return value;
1292
- }
1293
- };
1294
1303
  }
1295
1304
  map(value) {
1296
1305
  return this._map(value, void 0);
@@ -1301,7 +1310,28 @@ var DeepMapperAsync = class {
1301
1310
  }
1302
1311
  return this._fn(value, this._recurse, key);
1303
1312
  }
1304
- _recurse;
1313
+ _recurse = async (value) => {
1314
+ if (this._cyclic.has(value)) {
1315
+ return this._cyclic.get(value);
1316
+ }
1317
+ if (Array.isArray(value)) {
1318
+ const res = new Array(value.length);
1319
+ this._cyclic.set(value, res);
1320
+ for (let i = 0; i < value.length; i++) {
1321
+ res[i] = await this._map(value[i], i);
1322
+ }
1323
+ return res;
1324
+ } else if (value !== null && typeof value === "object") {
1325
+ const res = {};
1326
+ this._cyclic.set(value, res);
1327
+ for (const key in value) {
1328
+ res[key] = await this._map(value[key], key);
1329
+ }
1330
+ return res;
1331
+ } else {
1332
+ return value;
1333
+ }
1334
+ };
1305
1335
  };
1306
1336
  var visitValues = (object, visitor) => {
1307
1337
  if (Array.isArray(object)) {
@@ -1390,7 +1420,18 @@ var omit = (obj, keys2) => {
1390
1420
 
1391
1421
  // src/platform.ts
1392
1422
  var isNode = () => typeof process !== "undefined" && process.versions != null && process.versions.node != null;
1393
- var mobileAndTabletCheck = () => {
1423
+ var isBun = () => globalThis.Bun !== void 0;
1424
+ var isTauri = () => !!globalThis.__TAURI__;
1425
+ var isMobile = () => {
1426
+ let check = false;
1427
+ (function(a) {
1428
+ 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))) {
1429
+ check = true;
1430
+ }
1431
+ })(navigator.userAgent || navigator.vendor || window.opera);
1432
+ return check;
1433
+ };
1434
+ var isMobileOrTablet = () => {
1394
1435
  let check = false;
1395
1436
  ((a) => {
1396
1437
  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))) {
@@ -1412,7 +1453,7 @@ var iosCheck = () => {
1412
1453
  };
1413
1454
  var safariCheck = () => typeof navigator !== "undefined" && /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
1414
1455
  var getHostPlatform = () => {
1415
- if (!("navigator" in window)) {
1456
+ if (!("navigator" in globalThis)) {
1416
1457
  return "unknown";
1417
1458
  }
1418
1459
  const platform = (navigator.userAgentData?.platform || navigator.platform)?.toLowerCase();
@@ -1588,6 +1629,43 @@ var removeProperties = (root, condition) => {
1588
1629
  return result;
1589
1630
  };
1590
1631
 
1632
+ // src/retry.ts
1633
+ var DEFAULT_RETRY_OPTIONS = {
1634
+ count: 3,
1635
+ delayMs: 100,
1636
+ exponent: 2,
1637
+ retryOnError: async () => true,
1638
+ retryOnValue: async () => false
1639
+ };
1640
+ var retry = async (options, cb) => {
1641
+ const fullOptions = {
1642
+ ...DEFAULT_RETRY_OPTIONS,
1643
+ ...options
1644
+ };
1645
+ let numRetries = 0, currentDelay = fullOptions.delayMs;
1646
+ while (true) {
1647
+ let result;
1648
+ try {
1649
+ result = await cb();
1650
+ } catch (err) {
1651
+ if (numRetries > fullOptions.count || !await fullOptions.retryOnError(err)) {
1652
+ throw err;
1653
+ }
1654
+ await new Promise((resolve) => setTimeout(resolve, currentDelay));
1655
+ currentDelay *= fullOptions.exponent;
1656
+ numRetries++;
1657
+ continue;
1658
+ }
1659
+ if (!await fullOptions.retryOnValue(result)) {
1660
+ return result;
1661
+ }
1662
+ await new Promise((resolve) => setTimeout(resolve, currentDelay));
1663
+ currentDelay *= fullOptions.exponent;
1664
+ numRetries++;
1665
+ continue;
1666
+ }
1667
+ };
1668
+
1591
1669
  // src/safe-await.ts
1592
1670
  var safeAwaitAll = async (source, taskFactory, onError) => {
1593
1671
  const failedItems = [];
@@ -1607,7 +1685,7 @@ var safeAwaitAll = async (source, taskFactory, onError) => {
1607
1685
  };
1608
1686
 
1609
1687
  // src/safe-instanceof.ts
1610
- var instanceTag = Symbol("instanceTag");
1688
+ var instanceTag = /* @__PURE__ */ Symbol("instanceTag");
1611
1689
  var safeInstanceof = (tag) => (target) => {
1612
1690
  target.prototype[instanceTag] = tag;
1613
1691
  Object.defineProperty(target.prototype, Symbol.hasInstance, {
@@ -1619,34 +1697,131 @@ var safeInstanceof = (tag) => (target) => {
1619
1697
  };
1620
1698
 
1621
1699
  // src/safe-parse.ts
1622
- var safeParseInt = (value, defaultValue) => {
1700
+ function safeParseInt(str, defaultValue) {
1623
1701
  try {
1624
- const n = parseInt(value ?? "");
1625
- return isNaN(n) ? defaultValue : n;
1626
- } catch (err) {
1702
+ const value = parseInt(str ?? "");
1703
+ return isNaN(value) ? defaultValue : value;
1704
+ } catch {
1627
1705
  return defaultValue;
1628
1706
  }
1707
+ }
1708
+ function safeParseFloat(str, defaultValue) {
1709
+ try {
1710
+ const value = parseFloat(str ?? "");
1711
+ return isNaN(value) ? defaultValue : value;
1712
+ } catch {
1713
+ return defaultValue;
1714
+ }
1715
+ }
1716
+ var safeParseJson = (str, defaultValue) => {
1717
+ if (str && str.length > 0) {
1718
+ try {
1719
+ return JSON.parse(str);
1720
+ } catch {
1721
+ }
1722
+ }
1723
+ return defaultValue;
1629
1724
  };
1630
- var safeParseFloat = (str, defaultValue) => {
1725
+ var safeUrl = (str) => {
1631
1726
  try {
1632
- return parseFloat(str);
1727
+ return new URL(str ?? "");
1633
1728
  } catch {
1634
- return defaultValue ?? 0;
1729
+ return void 0;
1635
1730
  }
1636
1731
  };
1637
- var safeParseJson = (data, defaultValue) => {
1638
- if (data && data.length > 0) {
1732
+
1733
+ // src/safe-stringify.ts
1734
+ var SKIP = Object.freeze({});
1735
+ function safeStringify(obj, filter = defaultFilter, indent = 2) {
1736
+ const seen = /* @__PURE__ */ new WeakMap();
1737
+ function replacer(key, value) {
1639
1738
  try {
1640
- return JSON.parse(data);
1641
- } catch (err) {
1739
+ let path = key;
1740
+ if (!key) {
1741
+ path = "$";
1742
+ if (value != null && typeof value === "object") {
1743
+ seen.set(value, path);
1744
+ }
1745
+ return value;
1746
+ } else if (this) {
1747
+ const parentPath = seen.get(this);
1748
+ path = parentPath ? `${parentPath}.${key}` : key;
1749
+ }
1750
+ if (value == null) {
1751
+ return value;
1752
+ }
1753
+ if (typeof value === "function") {
1754
+ return void 0;
1755
+ }
1756
+ if (typeof value === "object" && Object.getPrototypeOf(value) !== Object.prototype && !Array.isArray(value)) {
1757
+ return void 0;
1758
+ }
1759
+ if (typeof value === "object" && value !== null) {
1760
+ const exists = seen.get(value);
1761
+ if (exists) {
1762
+ return `[${path} => ${exists}]`;
1763
+ }
1764
+ seen.set(value, path);
1765
+ }
1766
+ if (filter) {
1767
+ const filteredValue = filter?.(key, value);
1768
+ if (filteredValue !== void 0) {
1769
+ return filteredValue === SKIP ? void 0 : filteredValue;
1770
+ }
1771
+ }
1772
+ return value;
1773
+ } catch (error) {
1774
+ return `ERROR: ${error.message}`;
1642
1775
  }
1643
1776
  }
1644
- return defaultValue;
1777
+ try {
1778
+ return JSON.stringify(obj, replacer, indent);
1779
+ } catch (error) {
1780
+ return `ERROR: ${error.message}`;
1781
+ }
1782
+ }
1783
+ var createReplacer = ({ omit: omit2, parse, maxDepth, maxArrayLen, maxStringLen } = {}) => {
1784
+ let currentDepth = 0;
1785
+ const depthMap = /* @__PURE__ */ new WeakMap();
1786
+ return function(key, value) {
1787
+ if (key === "") {
1788
+ currentDepth = 0;
1789
+ } else if (this && typeof this === "object") {
1790
+ const parentDepth = depthMap.get(this) ?? 0;
1791
+ currentDepth = parentDepth + 1;
1792
+ }
1793
+ if (typeof value === "function") {
1794
+ return SKIP;
1795
+ }
1796
+ if (maxArrayLen != null && Array.isArray(value) && value.length > maxArrayLen) {
1797
+ return `[length: ${value.length}]`;
1798
+ }
1799
+ if (value && typeof value === "object") {
1800
+ depthMap.set(value, currentDepth);
1801
+ if (maxDepth != null && currentDepth >= maxDepth) {
1802
+ return Array.isArray(value) ? `[{ length: ${value.length} }]` : `{ keys: ${Object.keys(value).length} }`;
1803
+ }
1804
+ }
1805
+ if (omit2?.includes(key)) {
1806
+ return SKIP;
1807
+ }
1808
+ if (parse?.includes(key) && typeof value === "string") {
1809
+ try {
1810
+ return JSON.parse(value);
1811
+ } catch {
1812
+ return value;
1813
+ }
1814
+ }
1815
+ if (maxStringLen != null && typeof value === "string" && value.length > maxStringLen) {
1816
+ return value.slice(0, maxStringLen) + "...";
1817
+ }
1818
+ return value;
1819
+ };
1645
1820
  };
1821
+ var defaultFilter = createReplacer();
1646
1822
 
1647
1823
  // src/sliding-window-summary.ts
1648
1824
  import { invariant as invariant5 } from "@dxos/invariant";
1649
- var __dxlog_file5 = "/__w/dxos/dxos/packages/common/util/src/sliding-window-summary.ts";
1650
1825
  var SlidingWindowSummary = class {
1651
1826
  _buffer;
1652
1827
  _sum = 0;
@@ -1654,15 +1829,7 @@ var SlidingWindowSummary = class {
1654
1829
  constructor(options) {
1655
1830
  this._buffer = new CircularBuffer(options.dataPoints);
1656
1831
  if (options.precision != null) {
1657
- invariant5(options.precision >= 0, void 0, {
1658
- F: __dxlog_file5,
1659
- L: 26,
1660
- S: this,
1661
- A: [
1662
- "options.precision >= 0",
1663
- ""
1664
- ]
1665
- });
1832
+ invariant5(options.precision >= 0);
1666
1833
  this._precision = Math.pow(10, options.precision);
1667
1834
  }
1668
1835
  }
@@ -1743,11 +1910,16 @@ function trim(strings, ...values) {
1743
1910
  return out;
1744
1911
  }, "");
1745
1912
  const lines = raw.split("\n");
1746
- while (lines.length && !lines[0].trim()) lines.shift();
1747
- while (lines.length && !lines[lines.length - 1].trim()) lines.pop();
1913
+ while (lines.length && !lines[0].trim()) {
1914
+ lines.shift();
1915
+ }
1916
+ while (lines.length && !lines[lines.length - 1].trim()) {
1917
+ lines.pop();
1918
+ }
1748
1919
  const minIndent = Math.min(...lines.filter((l) => l.trim()).map((l) => l.match(/^[ \t]*/)?.[0].length ?? 0));
1749
1920
  return lines.map((l) => l.slice(minIndent)).join("\n");
1750
1921
  }
1922
+ var kebabize = (str) => str.replace(/[A-Z]+(?![a-z])|[A-Z]/g, ($, ofs) => (ofs ? "-" : "") + $.toLowerCase());
1751
1923
 
1752
1924
  // src/sum.ts
1753
1925
  var sum = (values) => values.reduce((a, b) => a + b, 0);
@@ -1761,18 +1933,6 @@ var throwUnhandledError = (error) => {
1761
1933
 
1762
1934
  // src/to-fallback.ts
1763
1935
  var idEmoji = [
1764
- // When changing this set, please check the result in a console or e.g. RunKit (https://runkit.com/thure/642214441dd6ae000855a8de)
1765
- // 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.
1766
- // This set was chosen from the characters in Unicode Emoji v15.0 based on the following criteria:
1767
- // – not people or isolated anthropomorphic faces
1768
- // – not flags
1769
- // – more concrete than abstract
1770
- // – less culturally specific
1771
- // – less easily confused with another emoji in the set
1772
- // – requires less special knowledge to identify
1773
- // – less likely to evoke negative feelings (no meat, no drugs, no weapons, etc)
1774
- // – less common as a signifier in UX
1775
- // NOTE that this is intentionally an array of strings because of the way emoji graphemes work.
1776
1936
  "\u{1F47B}",
1777
1937
  "\u{1F479}",
1778
1938
  "\u{1F47D}",
@@ -1908,17 +2068,18 @@ var idEmoji = [
1908
2068
  ];
1909
2069
  var idHue = [
1910
2070
  "red",
1911
- // 'orange' as const, /* More shades in these palettes are considered “ugly” */
2071
+ "orange",
1912
2072
  "amber",
1913
- // 'yellow' as const, /* More shades in these palettes are considered “ugly” */
2073
+ "yellow",
1914
2074
  "lime",
1915
2075
  "green",
1916
2076
  "emerald",
1917
2077
  "teal",
1918
2078
  "cyan",
1919
- // 'sky' as const, /* Omitted since it is quite similar to the primary accent palette */
1920
- // 'blue' as const, /* Omitted since it is quite similar to the primary accent palette */
1921
- // 'indigo' as const, /* Omitted since it is quite similar to the primary accent palette */
2079
+ // Omit colors similar to primary accent.
2080
+ // 'sky' as const,
2081
+ // 'blue' as const,
2082
+ // 'indigo' as const,
1922
2083
  "violet",
1923
2084
  "purple",
1924
2085
  "fuchsia",
@@ -2048,7 +2209,7 @@ var stringifyTree = (node, ancestors = [], rows = []) => {
2048
2209
  };
2049
2210
 
2050
2211
  // src/types.ts
2051
- var isNotFalsy = (value) => !!value;
2212
+ var isTruthy = (value) => !!value;
2052
2213
  var isNonNullable = (value) => value != null;
2053
2214
  var doAsync = async (fn) => fn();
2054
2215
  var getProviderValue = (provider, arg) => {
@@ -2078,6 +2239,117 @@ var arrayMove = (array, from, to) => {
2078
2239
  array.splice(to < 0 ? array.length + to : to, 0, array.splice(from, 1)[0]);
2079
2240
  return array;
2080
2241
  };
2242
+ function arraySwap(array, from, to) {
2243
+ const current = array[from];
2244
+ array[from] = array[to];
2245
+ array[to] = current;
2246
+ return array;
2247
+ }
2248
+
2249
+ // src/unit.ts
2250
+ var createFormat = (unit) => {
2251
+ return (n, precision = unit.precision ?? 0) => {
2252
+ const value = n / unit.quotient;
2253
+ const formattedValue = value.toLocaleString("en-US", {
2254
+ minimumFractionDigits: precision,
2255
+ maximumFractionDigits: precision
2256
+ });
2257
+ return {
2258
+ unit,
2259
+ value,
2260
+ formattedValue,
2261
+ toString: () => `${formattedValue}${unit.symbol}`
2262
+ };
2263
+ };
2264
+ };
2265
+ var MS_SECONDS = 1e3;
2266
+ var MS_MINUTES = 60 * MS_SECONDS;
2267
+ var MS_HOURS = 60 * MS_MINUTES;
2268
+ var Unit = {
2269
+ // General.
2270
+ Percent: createFormat({
2271
+ symbol: "%",
2272
+ quotient: 1 / 100,
2273
+ precision: 2
2274
+ }),
2275
+ Thousand: createFormat({
2276
+ symbol: "k",
2277
+ quotient: 1e3,
2278
+ precision: 2
2279
+ }),
2280
+ // Bytes (note KB vs KiB).
2281
+ Gigabyte: createFormat({
2282
+ symbol: "GB",
2283
+ quotient: 1e3 * 1e3 * 1e3,
2284
+ precision: 2
2285
+ }),
2286
+ Megabyte: createFormat({
2287
+ symbol: "MB",
2288
+ quotient: 1e3 * 1e3,
2289
+ precision: 2
2290
+ }),
2291
+ Kilobyte: createFormat({
2292
+ symbol: "KB",
2293
+ quotient: 1e3,
2294
+ precision: 2
2295
+ }),
2296
+ Byte: createFormat({
2297
+ symbol: "B",
2298
+ quotient: 1
2299
+ }),
2300
+ // Time.
2301
+ Hour: createFormat({
2302
+ symbol: "h",
2303
+ quotient: MS_HOURS
2304
+ }),
2305
+ Minute: createFormat({
2306
+ symbol: "m",
2307
+ quotient: MS_MINUTES
2308
+ }),
2309
+ Second: createFormat({
2310
+ symbol: "s",
2311
+ quotient: MS_SECONDS,
2312
+ precision: 1
2313
+ }),
2314
+ Millisecond: createFormat({
2315
+ symbol: "ms",
2316
+ quotient: 1
2317
+ }),
2318
+ Duration: (n) => {
2319
+ const hours = Math.floor(n / MS_HOURS);
2320
+ const minutes = Math.floor(n % MS_HOURS / MS_MINUTES);
2321
+ if (hours) {
2322
+ const formattedValue = minutes ? `${hours}h ${minutes}m` : `${hours}h`;
2323
+ return {
2324
+ unit: {
2325
+ symbol: "h",
2326
+ quotient: MS_HOURS
2327
+ },
2328
+ value: hours,
2329
+ formattedValue,
2330
+ toString: () => formattedValue
2331
+ };
2332
+ }
2333
+ if (minutes) {
2334
+ const seconds2 = (n - MS_MINUTES * minutes) / MS_SECONDS;
2335
+ const formattedValue = seconds2 ? `${minutes}m ${seconds2}s` : `${minutes}m`;
2336
+ return {
2337
+ unit: {
2338
+ symbol: "m",
2339
+ quotient: MS_MINUTES
2340
+ },
2341
+ value: minutes,
2342
+ formattedValue,
2343
+ toString: () => formattedValue
2344
+ };
2345
+ }
2346
+ const seconds = n >= MS_SECONDS;
2347
+ if (seconds) {
2348
+ return Unit.Second(n);
2349
+ }
2350
+ return Unit.Millisecond(n);
2351
+ }
2352
+ };
2081
2353
 
2082
2354
  // src/url.ts
2083
2355
  var createUrl = (url, search) => {
@@ -2091,15 +2363,19 @@ var createUrl = (url, search) => {
2091
2363
  // src/weak.ts
2092
2364
  var WeakDictionary = class {
2093
2365
  _internal = /* @__PURE__ */ new Map();
2094
- _finalization = new FinalizationRegistry((cleanUpCallback) => {
2095
- cleanUpCallback();
2366
+ _finalization = new FinalizationRegistry(({ key, ref }) => {
2367
+ if (this._internal.get(key) === ref) {
2368
+ this._internal.delete(key);
2369
+ }
2096
2370
  });
2097
2371
  constructor(entries2) {
2098
- this._internal = new Map(entries2?.map(([key, value]) => [
2099
- key,
2100
- new WeakRef(value)
2101
- ]));
2102
- entries2?.forEach(([key, value]) => this._register(key, value));
2372
+ if (entries2) {
2373
+ for (const [key, value] of entries2) {
2374
+ const ref = new WeakRef(value);
2375
+ this._internal.set(key, ref);
2376
+ this._register(key, value, ref);
2377
+ }
2378
+ }
2103
2379
  }
2104
2380
  *entries() {
2105
2381
  for (const [key, value] of this._internal) {
@@ -2139,10 +2415,45 @@ var WeakDictionary = class {
2139
2415
  return this._internal.get(key)?.deref();
2140
2416
  }
2141
2417
  set(key, value) {
2142
- this._internal.set(key, new WeakRef(value));
2143
- this._register(key, value);
2418
+ const previous = this._internal.get(key)?.deref();
2419
+ if (previous) {
2420
+ this._unregister(previous);
2421
+ }
2422
+ const ref = new WeakRef(value);
2423
+ this._internal.set(key, ref);
2424
+ this._register(key, value, ref);
2144
2425
  return this;
2145
2426
  }
2427
+ /**
2428
+ * Returns the value for the given key if present, otherwise inserts and returns the default value.
2429
+ * @param key - The key to look up or insert.
2430
+ * @param defaultValue - The value to insert if the key is not present.
2431
+ * @returns The existing or newly inserted value.
2432
+ */
2433
+ getOrInsert(key, defaultValue) {
2434
+ const existing = this.get(key);
2435
+ if (existing !== void 0) {
2436
+ return existing;
2437
+ }
2438
+ this.set(key, defaultValue);
2439
+ return defaultValue;
2440
+ }
2441
+ /**
2442
+ * Returns the value for the given key if present, otherwise computes, inserts, and returns a new value.
2443
+ * The callback is only invoked when the key is missing.
2444
+ * @param key - The key to look up or insert.
2445
+ * @param callbackfn - Function to compute the value if the key is not present.
2446
+ * @returns The existing or newly computed value.
2447
+ */
2448
+ getOrInsertComputed(key, callbackfn) {
2449
+ const existing = this.get(key);
2450
+ if (existing !== void 0) {
2451
+ return existing;
2452
+ }
2453
+ const value = callbackfn(key);
2454
+ this.set(key, value);
2455
+ return value;
2456
+ }
2146
2457
  has(key) {
2147
2458
  return this._internal.has(key) && this._internal.get(key).deref() !== void 0;
2148
2459
  }
@@ -2173,9 +2484,10 @@ var WeakDictionary = class {
2173
2484
  }
2174
2485
  });
2175
2486
  }
2176
- _register(key, value) {
2177
- this._finalization.register(value, () => {
2178
- this._internal.delete(key);
2487
+ _register(key, value, ref) {
2488
+ this._finalization.register(value, {
2489
+ key,
2490
+ ref
2179
2491
  }, value);
2180
2492
  }
2181
2493
  _unregister(value) {
@@ -2191,11 +2503,14 @@ export {
2191
2503
  ComplexSet,
2192
2504
  HumanHasher,
2193
2505
  MapEntry,
2506
+ SKIP,
2194
2507
  SlidingWindowSummary,
2195
2508
  Tracer,
2509
+ Unit,
2196
2510
  WeakDictionary,
2197
2511
  accessBy,
2198
2512
  arrayMove,
2513
+ arraySwap,
2199
2514
  arrayToBuffer,
2200
2515
  arrayToHex,
2201
2516
  arrayToString,
@@ -2206,19 +2521,28 @@ export {
2206
2521
  capitalize,
2207
2522
  chunkArray,
2208
2523
  clamp,
2524
+ clearCaches,
2525
+ clearIndexedDB,
2526
+ clearOPFS,
2527
+ clearServiceWorkers,
2209
2528
  clearUndefined,
2529
+ coerceArray,
2210
2530
  compareMulti,
2211
2531
  compareObject,
2212
2532
  compareScalar,
2213
2533
  compareString,
2534
+ compositeKey,
2214
2535
  createBinder,
2215
2536
  createBucketReducer,
2537
+ createFilename,
2216
2538
  createGroupReducer,
2539
+ createReplacer,
2217
2540
  createSetDispatch,
2218
2541
  createUrl,
2219
2542
  decamelize,
2220
2543
  deepMapValues,
2221
2544
  deepMapValuesAsync,
2545
+ defaultFilter,
2222
2546
  defaultMap,
2223
2547
  defer,
2224
2548
  deferAsync,
@@ -2230,12 +2554,11 @@ export {
2230
2554
  entry,
2231
2555
  exponentialBackoffInterval,
2232
2556
  forEachAsync,
2233
- get,
2557
+ formatErrorWithCauses,
2234
2558
  getAsyncProviderValue,
2235
2559
  getDate,
2236
2560
  getDebugName,
2237
2561
  getDeep,
2238
- getFirstTwoRenderableChars,
2239
2562
  getHostPlatform,
2240
2563
  getPrototypeSpecificInstanceId,
2241
2564
  getProviderValue,
@@ -2251,14 +2574,19 @@ export {
2251
2574
  intersectBy,
2252
2575
  intersection,
2253
2576
  iosCheck,
2577
+ isBun,
2578
+ isMobile,
2579
+ isMobileOrTablet,
2254
2580
  isNode,
2255
2581
  isNonNullable,
2256
- isNotFalsy,
2582
+ isTauri,
2583
+ isTruthy,
2257
2584
  joinTables,
2258
2585
  jsonKeyReplacer,
2259
2586
  jsonReplacer,
2260
2587
  jsonify,
2261
2588
  jsonlogify,
2589
+ kebabize,
2262
2590
  keyToEmoji,
2263
2591
  keyToFallback,
2264
2592
  keyToHue,
@@ -2267,7 +2595,6 @@ export {
2267
2595
  makeSet,
2268
2596
  mapValues,
2269
2597
  median,
2270
- mobileAndTabletCheck,
2271
2598
  numericalValues,
2272
2599
  omit,
2273
2600
  orderKeys,
@@ -2283,15 +2610,18 @@ export {
2283
2610
  removeBy,
2284
2611
  removeProperties,
2285
2612
  removeUndefinedProperties,
2613
+ retry,
2286
2614
  safariCheck,
2287
2615
  safeAwaitAll,
2288
2616
  safeInstanceof,
2289
2617
  safeParseFloat,
2290
2618
  safeParseInt,
2291
2619
  safeParseJson,
2292
- set,
2620
+ safeStringify,
2621
+ safeUrl,
2293
2622
  setDeep,
2294
2623
  sortKeys,
2624
+ splitCompositeKey,
2295
2625
  stringToArray,
2296
2626
  stringifyTree,
2297
2627
  stripUndefined,