@dxos/util 0.8.4-main.fd6878d → 0.8.4-staging.ac66bdf99f
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/browser/index.mjs +514 -141
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +514 -141
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/array.d.ts +3 -2
- package/dist/types/src/array.d.ts.map +1 -1
- package/dist/types/src/browser-storage.d.ts +9 -0
- package/dist/types/src/browser-storage.d.ts.map +1 -0
- package/dist/types/src/circular-buffer.d.ts +1 -0
- package/dist/types/src/circular-buffer.d.ts.map +1 -1
- package/dist/types/src/complex.d.ts +15 -0
- package/dist/types/src/complex.d.ts.map +1 -1
- package/dist/types/src/composite-key.d.ts +10 -0
- package/dist/types/src/composite-key.d.ts.map +1 -0
- package/dist/types/src/composite-key.test.d.ts +2 -0
- package/dist/types/src/composite-key.test.d.ts.map +1 -0
- package/dist/types/src/deep.d.ts +0 -3
- package/dist/types/src/deep.d.ts.map +1 -1
- package/dist/types/src/defer.d.ts +1 -1
- package/dist/types/src/defer.d.ts.map +1 -1
- package/dist/types/src/di-key.d.ts +7 -5
- package/dist/types/src/di-key.d.ts.map +1 -1
- package/dist/types/src/error-format.d.ts +5 -0
- package/dist/types/src/error-format.d.ts.map +1 -0
- package/dist/types/src/filename.d.ts +9 -0
- package/dist/types/src/filename.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +7 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/platform.d.ts +4 -1
- package/dist/types/src/platform.d.ts.map +1 -1
- package/dist/types/src/retry.d.ts +32 -0
- package/dist/types/src/retry.d.ts.map +1 -0
- package/dist/types/src/safe-parse.d.ts +7 -4
- package/dist/types/src/safe-parse.d.ts.map +1 -1
- package/dist/types/src/safe-stringify.d.ts +22 -0
- package/dist/types/src/safe-stringify.d.ts.map +1 -0
- package/dist/types/src/safe-stringify.test.d.ts +2 -0
- package/dist/types/src/safe-stringify.test.d.ts.map +1 -0
- package/dist/types/src/string.d.ts +4 -0
- package/dist/types/src/string.d.ts.map +1 -1
- package/dist/types/src/to-fallback.d.ts +18 -4
- package/dist/types/src/to-fallback.d.ts.map +1 -1
- package/dist/types/src/types.d.ts +24 -6
- package/dist/types/src/types.d.ts.map +1 -1
- package/dist/types/src/unit.d.ts +14 -0
- package/dist/types/src/unit.d.ts.map +1 -0
- package/dist/types/src/unit.test.d.ts +2 -0
- package/dist/types/src/unit.test.d.ts.map +1 -0
- package/dist/types/src/weak.d.ts +15 -0
- package/dist/types/src/weak.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +12 -11
- package/src/array.ts +9 -2
- package/src/binder.ts +2 -2
- package/src/browser-storage.ts +60 -0
- package/src/circular-buffer.test.ts +26 -0
- package/src/circular-buffer.ts +5 -0
- package/src/complex.ts +32 -0
- package/src/composite-key.test.ts +31 -0
- package/src/composite-key.ts +16 -0
- package/src/deep.ts +2 -6
- package/src/defer.ts +1 -1
- package/src/di-key.ts +10 -8
- package/src/error-format.ts +22 -0
- package/src/filename.ts +16 -0
- package/src/index.ts +7 -1
- package/src/platform.ts +35 -3
- package/src/retry.ts +74 -0
- package/src/safe-parse.ts +29 -17
- package/src/safe-stringify.test.ts +96 -0
- package/src/safe-stringify.ts +153 -0
- package/src/string.ts +7 -0
- package/src/to-fallback.ts +44 -160
- package/src/types.test.ts +11 -1
- package/src/types.ts +40 -12
- package/src/unit.test.ts +25 -0
- package/src/unit.ts +83 -0
- package/src/weak.ts +52 -14
- package/dist/types/src/explicit-resource-management-polyfill.d.ts +0 -1
- package/dist/types/src/explicit-resource-management-polyfill.d.ts.map +0 -1
- package/dist/types/src/first-two-chars.d.ts +0 -9
- package/dist/types/src/first-two-chars.d.ts.map +0 -1
- package/src/explicit-resource-management-polyfill.ts +0 -13
- package/src/first-two-chars.ts +0 -44
|
@@ -97,16 +97,24 @@ var intersectBy = (arrays, selector) => {
|
|
|
97
97
|
return lookups.every((lookup) => lookup.has(key));
|
|
98
98
|
});
|
|
99
99
|
};
|
|
100
|
+
var coerceArray = (arr) => {
|
|
101
|
+
if (arr === void 0) {
|
|
102
|
+
return [];
|
|
103
|
+
}
|
|
104
|
+
return Array.isArray(arr) ? arr : [
|
|
105
|
+
arr
|
|
106
|
+
];
|
|
107
|
+
};
|
|
100
108
|
|
|
101
109
|
// src/assume.ts
|
|
102
110
|
function assumeType(value) {
|
|
103
111
|
}
|
|
104
112
|
|
|
105
113
|
// src/binder.ts
|
|
106
|
-
import
|
|
114
|
+
import { promisify } from "@dxos/node-std/util";
|
|
107
115
|
var createBinder = (obj) => ({
|
|
108
116
|
fn: (fn) => fn.bind(obj),
|
|
109
|
-
async: (fn) =>
|
|
117
|
+
async: (fn) => promisify(fn.bind(obj))
|
|
110
118
|
});
|
|
111
119
|
|
|
112
120
|
// src/bitfield.ts
|
|
@@ -179,6 +187,49 @@ var BitField = class _BitField {
|
|
|
179
187
|
}
|
|
180
188
|
};
|
|
181
189
|
|
|
190
|
+
// src/browser-storage.ts
|
|
191
|
+
var clearIndexedDB = async () => {
|
|
192
|
+
const dbs = await indexedDB.databases();
|
|
193
|
+
const results = await Promise.allSettled(dbs.filter((db) => db.name != null).map((db) => new Promise((resolve, reject) => {
|
|
194
|
+
const request = indexedDB.deleteDatabase(db.name);
|
|
195
|
+
request.onsuccess = () => resolve();
|
|
196
|
+
request.onerror = () => reject(request.error);
|
|
197
|
+
request.onblocked = () => reject(new Error(`IndexedDB deletion blocked: ${db.name}`));
|
|
198
|
+
})));
|
|
199
|
+
const failures = results.filter((r) => r.status === "rejected");
|
|
200
|
+
if (failures.length > 0) {
|
|
201
|
+
throw new AggregateError(failures.map((r) => r.reason), "Failed to delete some IndexedDB databases");
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
var clearOPFS = async () => {
|
|
205
|
+
const root = await navigator.storage.getDirectory();
|
|
206
|
+
const errors = [];
|
|
207
|
+
for await (const [name] of root.entries()) {
|
|
208
|
+
try {
|
|
209
|
+
await root.removeEntry(name, {
|
|
210
|
+
recursive: true
|
|
211
|
+
});
|
|
212
|
+
} catch (err) {
|
|
213
|
+
errors.push(err);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
if (errors.length > 0) {
|
|
217
|
+
throw new AggregateError(errors, "Failed to remove some OPFS entries");
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
var clearServiceWorkers = async () => {
|
|
221
|
+
const regs = await navigator.serviceWorker.getRegistrations();
|
|
222
|
+
for (const reg of regs) {
|
|
223
|
+
await reg.unregister();
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
var clearCaches = async () => {
|
|
227
|
+
const keys2 = await caches.keys();
|
|
228
|
+
for (const key of keys2) {
|
|
229
|
+
await caches.delete(key);
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
|
|
182
233
|
// src/callback-collection.ts
|
|
183
234
|
var CallbackCollection = class {
|
|
184
235
|
#callbacks = [];
|
|
@@ -327,6 +378,10 @@ var CircularBuffer = class {
|
|
|
327
378
|
get elementCount() {
|
|
328
379
|
return this._elementCount;
|
|
329
380
|
}
|
|
381
|
+
clear() {
|
|
382
|
+
this._nextIndex = 0;
|
|
383
|
+
this._elementCount = 0;
|
|
384
|
+
}
|
|
330
385
|
getLast() {
|
|
331
386
|
if (this._elementCount === 0) {
|
|
332
387
|
return void 0;
|
|
@@ -377,11 +432,10 @@ import { inspectObject, raise } from "@dxos/debug";
|
|
|
377
432
|
var MAX_SERIALIZATION_LENGTH = 10;
|
|
378
433
|
var ComplexSet = class {
|
|
379
434
|
_projection;
|
|
380
|
-
_values;
|
|
435
|
+
_values = /* @__PURE__ */ new Map();
|
|
381
436
|
// prettier-ignore
|
|
382
437
|
constructor(_projection, values) {
|
|
383
438
|
this._projection = _projection;
|
|
384
|
-
this._values = /* @__PURE__ */ new Map();
|
|
385
439
|
if (values) {
|
|
386
440
|
for (const value of values) {
|
|
387
441
|
this.add(value);
|
|
@@ -472,13 +526,11 @@ var makeSet = (projection) => {
|
|
|
472
526
|
};
|
|
473
527
|
var ComplexMap = class _ComplexMap {
|
|
474
528
|
_keyProjection;
|
|
475
|
-
_keys;
|
|
476
|
-
_values;
|
|
529
|
+
_keys = /* @__PURE__ */ new Map();
|
|
530
|
+
_values = /* @__PURE__ */ new Map();
|
|
477
531
|
// prettier-ignore
|
|
478
532
|
constructor(_keyProjection, entries2) {
|
|
479
533
|
this._keyProjection = _keyProjection;
|
|
480
|
-
this._keys = /* @__PURE__ */ new Map();
|
|
481
|
-
this._values = /* @__PURE__ */ new Map();
|
|
482
534
|
if (entries2) {
|
|
483
535
|
for (const [key, value] of entries2) {
|
|
484
536
|
this.set(key, value);
|
|
@@ -523,6 +575,36 @@ var ComplexMap = class _ComplexMap {
|
|
|
523
575
|
this._values.set(primitive, value);
|
|
524
576
|
return this;
|
|
525
577
|
}
|
|
578
|
+
/**
|
|
579
|
+
* Returns the value for the given key if present, otherwise inserts and returns the default value.
|
|
580
|
+
* @param key - The key to look up or insert.
|
|
581
|
+
* @param defaultValue - The value to insert if the key is not present.
|
|
582
|
+
* @returns The existing or newly inserted value.
|
|
583
|
+
*/
|
|
584
|
+
getOrInsert(key, defaultValue) {
|
|
585
|
+
const primitive = this._keyProjection(key);
|
|
586
|
+
if (this._values.has(primitive)) {
|
|
587
|
+
return this._values.get(primitive);
|
|
588
|
+
}
|
|
589
|
+
this.set(key, defaultValue);
|
|
590
|
+
return defaultValue;
|
|
591
|
+
}
|
|
592
|
+
/**
|
|
593
|
+
* Returns the value for the given key if present, otherwise computes, inserts, and returns a new value.
|
|
594
|
+
* The callback is only invoked when the key is missing.
|
|
595
|
+
* @param key - The key to look up or insert.
|
|
596
|
+
* @param callbackfn - Function to compute the value if the key is not present.
|
|
597
|
+
* @returns The existing or newly computed value.
|
|
598
|
+
*/
|
|
599
|
+
getOrInsertComputed(key, callbackfn) {
|
|
600
|
+
const primitive = this._keyProjection(key);
|
|
601
|
+
if (this._values.has(primitive)) {
|
|
602
|
+
return this._values.get(primitive);
|
|
603
|
+
}
|
|
604
|
+
const value = callbackfn(key);
|
|
605
|
+
this.set(key, value);
|
|
606
|
+
return value;
|
|
607
|
+
}
|
|
526
608
|
get size() {
|
|
527
609
|
return this._keys.size;
|
|
528
610
|
}
|
|
@@ -562,15 +644,18 @@ var makeMap = (keyProjection) => class BoundComplexMap extends ComplexMap {
|
|
|
562
644
|
}
|
|
563
645
|
};
|
|
564
646
|
|
|
647
|
+
// src/composite-key.ts
|
|
648
|
+
var SEPARATOR = ":";
|
|
649
|
+
var compositeKey = (...parts) => parts.join(SEPARATOR);
|
|
650
|
+
var splitCompositeKey = (key) => key.split(SEPARATOR);
|
|
651
|
+
|
|
565
652
|
// src/deep.ts
|
|
566
|
-
import get from "lodash.get";
|
|
567
|
-
import set from "lodash.set";
|
|
568
653
|
import { invariant as invariant4 } from "@dxos/invariant";
|
|
569
654
|
var __dxlog_file4 = "/__w/dxos/dxos/packages/common/util/src/deep.ts";
|
|
570
655
|
var setDeep = (obj, path, value) => {
|
|
571
656
|
invariant4(path.length > 0, void 0, {
|
|
572
657
|
F: __dxlog_file4,
|
|
573
|
-
L:
|
|
658
|
+
L: 12,
|
|
574
659
|
S: void 0,
|
|
575
660
|
A: [
|
|
576
661
|
"path.length > 0",
|
|
@@ -599,11 +684,8 @@ var getDeep = (obj, path) => {
|
|
|
599
684
|
// src/defer-function.ts
|
|
600
685
|
var deferFunction = (fnProvider) => (...args) => fnProvider()(...args);
|
|
601
686
|
|
|
602
|
-
// src/explicit-resource-management-polyfill.ts
|
|
603
|
-
Symbol.dispose ??= Symbol("Symbol.dispose");
|
|
604
|
-
Symbol.asyncDispose ??= Symbol("Symbol.asyncDispose");
|
|
605
|
-
|
|
606
687
|
// src/defer.ts
|
|
688
|
+
import "@hazae41/symbol-dispose-polyfill";
|
|
607
689
|
var defer = (fn) => new DeferGuard(fn);
|
|
608
690
|
var DeferGuard = class {
|
|
609
691
|
_fn;
|
|
@@ -664,33 +746,27 @@ var MapEntry = class {
|
|
|
664
746
|
}
|
|
665
747
|
};
|
|
666
748
|
|
|
667
|
-
// src/
|
|
668
|
-
var
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
""
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
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;
|
|
749
|
+
// src/error-format.ts
|
|
750
|
+
var formatErrorWithCauses = (error) => {
|
|
751
|
+
const lines = [];
|
|
752
|
+
let current = error;
|
|
753
|
+
let level = 0;
|
|
754
|
+
while (current) {
|
|
755
|
+
const prefix = level === 0 ? "" : `Caused by: `;
|
|
756
|
+
lines.push(prefix + (current.stack ?? String(current)));
|
|
757
|
+
if (!(current.cause instanceof Error)) break;
|
|
758
|
+
current = current.cause;
|
|
759
|
+
level += 1;
|
|
760
|
+
}
|
|
761
|
+
return lines.join("\n\n");
|
|
692
762
|
};
|
|
693
763
|
|
|
764
|
+
// src/filename.ts
|
|
765
|
+
var createFilename = ({ parts = [], ext, date = /* @__PURE__ */ new Date() }) => [
|
|
766
|
+
date.toISOString().replace(/[:.]/g, "-"),
|
|
767
|
+
...parts
|
|
768
|
+
].join("_") + (ext ? `.${ext}` : "");
|
|
769
|
+
|
|
694
770
|
// src/for-each-async.ts
|
|
695
771
|
var forEachAsync = (items, fn) => Promise.all(items.map(fn));
|
|
696
772
|
|
|
@@ -1037,7 +1113,7 @@ var defaultMap = (map, key, def) => {
|
|
|
1037
1113
|
};
|
|
1038
1114
|
|
|
1039
1115
|
// src/instance-id.ts
|
|
1040
|
-
var symbol = Symbol.for("dxos.instance-contexts");
|
|
1116
|
+
var symbol = /* @__PURE__ */ Symbol.for("dxos.instance-contexts");
|
|
1041
1117
|
var instanceContexts = globalThis[symbol] ??= /* @__PURE__ */ new WeakMap();
|
|
1042
1118
|
var getPrototypeSpecificInstanceId = (instance) => {
|
|
1043
1119
|
const prototype = Object.getPrototypeOf(instance);
|
|
@@ -1222,32 +1298,9 @@ var deepMapValues = (value, fn) => {
|
|
|
1222
1298
|
};
|
|
1223
1299
|
var DeepMapper = class {
|
|
1224
1300
|
_fn;
|
|
1225
|
-
_cyclic;
|
|
1301
|
+
_cyclic = /* @__PURE__ */ new Map();
|
|
1226
1302
|
constructor(_fn) {
|
|
1227
1303
|
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
1304
|
}
|
|
1252
1305
|
map(value) {
|
|
1253
1306
|
return this._map(value, void 0);
|
|
@@ -1258,39 +1311,37 @@ var DeepMapper = class {
|
|
|
1258
1311
|
}
|
|
1259
1312
|
return this._fn(value, this._recurse, key);
|
|
1260
1313
|
}
|
|
1261
|
-
_recurse
|
|
1314
|
+
_recurse = (value) => {
|
|
1315
|
+
if (this._cyclic.has(value)) {
|
|
1316
|
+
return this._cyclic.get(value);
|
|
1317
|
+
}
|
|
1318
|
+
if (Array.isArray(value)) {
|
|
1319
|
+
const res = new Array(value.length);
|
|
1320
|
+
this._cyclic.set(value, res);
|
|
1321
|
+
for (let i = 0; i < value.length; i++) {
|
|
1322
|
+
res[i] = this._map(value[i], i);
|
|
1323
|
+
}
|
|
1324
|
+
return res;
|
|
1325
|
+
} else if (value !== null && typeof value === "object") {
|
|
1326
|
+
const res = {};
|
|
1327
|
+
this._cyclic.set(value, res);
|
|
1328
|
+
for (const key in value) {
|
|
1329
|
+
res[key] = this._map(value[key], key);
|
|
1330
|
+
}
|
|
1331
|
+
return res;
|
|
1332
|
+
} else {
|
|
1333
|
+
return value;
|
|
1334
|
+
}
|
|
1335
|
+
};
|
|
1262
1336
|
};
|
|
1263
1337
|
var deepMapValuesAsync = (value, fn) => {
|
|
1264
1338
|
return new DeepMapperAsync(fn).map(value);
|
|
1265
1339
|
};
|
|
1266
1340
|
var DeepMapperAsync = class {
|
|
1267
1341
|
_fn;
|
|
1268
|
-
_cyclic;
|
|
1342
|
+
_cyclic = /* @__PURE__ */ new Map();
|
|
1269
1343
|
constructor(_fn) {
|
|
1270
1344
|
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
1345
|
}
|
|
1295
1346
|
map(value) {
|
|
1296
1347
|
return this._map(value, void 0);
|
|
@@ -1301,7 +1352,28 @@ var DeepMapperAsync = class {
|
|
|
1301
1352
|
}
|
|
1302
1353
|
return this._fn(value, this._recurse, key);
|
|
1303
1354
|
}
|
|
1304
|
-
_recurse
|
|
1355
|
+
_recurse = async (value) => {
|
|
1356
|
+
if (this._cyclic.has(value)) {
|
|
1357
|
+
return this._cyclic.get(value);
|
|
1358
|
+
}
|
|
1359
|
+
if (Array.isArray(value)) {
|
|
1360
|
+
const res = new Array(value.length);
|
|
1361
|
+
this._cyclic.set(value, res);
|
|
1362
|
+
for (let i = 0; i < value.length; i++) {
|
|
1363
|
+
res[i] = await this._map(value[i], i);
|
|
1364
|
+
}
|
|
1365
|
+
return res;
|
|
1366
|
+
} else if (value !== null && typeof value === "object") {
|
|
1367
|
+
const res = {};
|
|
1368
|
+
this._cyclic.set(value, res);
|
|
1369
|
+
for (const key in value) {
|
|
1370
|
+
res[key] = await this._map(value[key], key);
|
|
1371
|
+
}
|
|
1372
|
+
return res;
|
|
1373
|
+
} else {
|
|
1374
|
+
return value;
|
|
1375
|
+
}
|
|
1376
|
+
};
|
|
1305
1377
|
};
|
|
1306
1378
|
var visitValues = (object, visitor) => {
|
|
1307
1379
|
if (Array.isArray(object)) {
|
|
@@ -1390,7 +1462,18 @@ var omit = (obj, keys2) => {
|
|
|
1390
1462
|
|
|
1391
1463
|
// src/platform.ts
|
|
1392
1464
|
var isNode = () => typeof process !== "undefined" && process.versions != null && process.versions.node != null;
|
|
1393
|
-
var
|
|
1465
|
+
var isBun = () => globalThis.Bun !== void 0;
|
|
1466
|
+
var isTauri = () => !!globalThis.__TAURI__;
|
|
1467
|
+
var isMobile = () => {
|
|
1468
|
+
let check = false;
|
|
1469
|
+
(function(a) {
|
|
1470
|
+
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))) {
|
|
1471
|
+
check = true;
|
|
1472
|
+
}
|
|
1473
|
+
})(navigator.userAgent || navigator.vendor || window.opera);
|
|
1474
|
+
return check;
|
|
1475
|
+
};
|
|
1476
|
+
var isMobileOrTablet = () => {
|
|
1394
1477
|
let check = false;
|
|
1395
1478
|
((a) => {
|
|
1396
1479
|
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 +1495,7 @@ var iosCheck = () => {
|
|
|
1412
1495
|
};
|
|
1413
1496
|
var safariCheck = () => typeof navigator !== "undefined" && /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
|
|
1414
1497
|
var getHostPlatform = () => {
|
|
1415
|
-
if (!("navigator" in
|
|
1498
|
+
if (!("navigator" in globalThis)) {
|
|
1416
1499
|
return "unknown";
|
|
1417
1500
|
}
|
|
1418
1501
|
const platform = (navigator.userAgentData?.platform || navigator.platform)?.toLowerCase();
|
|
@@ -1588,6 +1671,43 @@ var removeProperties = (root, condition) => {
|
|
|
1588
1671
|
return result;
|
|
1589
1672
|
};
|
|
1590
1673
|
|
|
1674
|
+
// src/retry.ts
|
|
1675
|
+
var DEFAULT_RETRY_OPTIONS = {
|
|
1676
|
+
count: 3,
|
|
1677
|
+
delayMs: 100,
|
|
1678
|
+
exponent: 2,
|
|
1679
|
+
retryOnError: async () => true,
|
|
1680
|
+
retryOnValue: async () => false
|
|
1681
|
+
};
|
|
1682
|
+
var retry = async (options, cb) => {
|
|
1683
|
+
const fullOptions = {
|
|
1684
|
+
...DEFAULT_RETRY_OPTIONS,
|
|
1685
|
+
...options
|
|
1686
|
+
};
|
|
1687
|
+
let numRetries = 0, currentDelay = fullOptions.delayMs;
|
|
1688
|
+
while (true) {
|
|
1689
|
+
let result;
|
|
1690
|
+
try {
|
|
1691
|
+
result = await cb();
|
|
1692
|
+
} catch (err) {
|
|
1693
|
+
if (numRetries > fullOptions.count || !await fullOptions.retryOnError(err)) {
|
|
1694
|
+
throw err;
|
|
1695
|
+
}
|
|
1696
|
+
await new Promise((resolve) => setTimeout(resolve, currentDelay));
|
|
1697
|
+
currentDelay *= fullOptions.exponent;
|
|
1698
|
+
numRetries++;
|
|
1699
|
+
continue;
|
|
1700
|
+
}
|
|
1701
|
+
if (!await fullOptions.retryOnValue(result)) {
|
|
1702
|
+
return result;
|
|
1703
|
+
}
|
|
1704
|
+
await new Promise((resolve) => setTimeout(resolve, currentDelay));
|
|
1705
|
+
currentDelay *= fullOptions.exponent;
|
|
1706
|
+
numRetries++;
|
|
1707
|
+
continue;
|
|
1708
|
+
}
|
|
1709
|
+
};
|
|
1710
|
+
|
|
1591
1711
|
// src/safe-await.ts
|
|
1592
1712
|
var safeAwaitAll = async (source, taskFactory, onError) => {
|
|
1593
1713
|
const failedItems = [];
|
|
@@ -1607,7 +1727,7 @@ var safeAwaitAll = async (source, taskFactory, onError) => {
|
|
|
1607
1727
|
};
|
|
1608
1728
|
|
|
1609
1729
|
// src/safe-instanceof.ts
|
|
1610
|
-
var instanceTag = Symbol("instanceTag");
|
|
1730
|
+
var instanceTag = /* @__PURE__ */ Symbol("instanceTag");
|
|
1611
1731
|
var safeInstanceof = (tag) => (target) => {
|
|
1612
1732
|
target.prototype[instanceTag] = tag;
|
|
1613
1733
|
Object.defineProperty(target.prototype, Symbol.hasInstance, {
|
|
@@ -1619,30 +1739,128 @@ var safeInstanceof = (tag) => (target) => {
|
|
|
1619
1739
|
};
|
|
1620
1740
|
|
|
1621
1741
|
// src/safe-parse.ts
|
|
1622
|
-
|
|
1742
|
+
function safeParseInt(str, defaultValue) {
|
|
1743
|
+
try {
|
|
1744
|
+
const value = parseInt(str ?? "");
|
|
1745
|
+
return isNaN(value) ? defaultValue : value;
|
|
1746
|
+
} catch {
|
|
1747
|
+
return defaultValue;
|
|
1748
|
+
}
|
|
1749
|
+
}
|
|
1750
|
+
function safeParseFloat(str, defaultValue) {
|
|
1623
1751
|
try {
|
|
1624
|
-
const
|
|
1625
|
-
return isNaN(
|
|
1626
|
-
} catch
|
|
1752
|
+
const value = parseFloat(str ?? "");
|
|
1753
|
+
return isNaN(value) ? defaultValue : value;
|
|
1754
|
+
} catch {
|
|
1627
1755
|
return defaultValue;
|
|
1628
1756
|
}
|
|
1757
|
+
}
|
|
1758
|
+
var safeParseJson = (str, defaultValue) => {
|
|
1759
|
+
if (str && str.length > 0) {
|
|
1760
|
+
try {
|
|
1761
|
+
return JSON.parse(str);
|
|
1762
|
+
} catch {
|
|
1763
|
+
}
|
|
1764
|
+
}
|
|
1765
|
+
return defaultValue;
|
|
1629
1766
|
};
|
|
1630
|
-
var
|
|
1767
|
+
var safeUrl = (str) => {
|
|
1631
1768
|
try {
|
|
1632
|
-
return
|
|
1769
|
+
return new URL(str ?? "");
|
|
1633
1770
|
} catch {
|
|
1634
|
-
return
|
|
1771
|
+
return void 0;
|
|
1635
1772
|
}
|
|
1636
1773
|
};
|
|
1637
|
-
|
|
1638
|
-
|
|
1774
|
+
|
|
1775
|
+
// src/safe-stringify.ts
|
|
1776
|
+
var SKIP = Object.freeze({});
|
|
1777
|
+
function safeStringify(obj, filter = defaultFilter, indent = 2) {
|
|
1778
|
+
const seen = /* @__PURE__ */ new WeakMap();
|
|
1779
|
+
function replacer(key, value) {
|
|
1639
1780
|
try {
|
|
1640
|
-
|
|
1641
|
-
|
|
1781
|
+
let path = key;
|
|
1782
|
+
if (!key) {
|
|
1783
|
+
path = "$";
|
|
1784
|
+
if (value != null && typeof value === "object") {
|
|
1785
|
+
seen.set(value, path);
|
|
1786
|
+
}
|
|
1787
|
+
return value;
|
|
1788
|
+
} else if (this) {
|
|
1789
|
+
const parentPath = seen.get(this);
|
|
1790
|
+
path = parentPath ? `${parentPath}.${key}` : key;
|
|
1791
|
+
}
|
|
1792
|
+
if (value == null) {
|
|
1793
|
+
return value;
|
|
1794
|
+
}
|
|
1795
|
+
if (typeof value === "function") {
|
|
1796
|
+
return void 0;
|
|
1797
|
+
}
|
|
1798
|
+
if (typeof value === "object" && Object.getPrototypeOf(value) !== Object.prototype && !Array.isArray(value)) {
|
|
1799
|
+
return void 0;
|
|
1800
|
+
}
|
|
1801
|
+
if (typeof value === "object" && value !== null) {
|
|
1802
|
+
const exists = seen.get(value);
|
|
1803
|
+
if (exists) {
|
|
1804
|
+
return `[${path} => ${exists}]`;
|
|
1805
|
+
}
|
|
1806
|
+
seen.set(value, path);
|
|
1807
|
+
}
|
|
1808
|
+
if (filter) {
|
|
1809
|
+
const filteredValue = filter?.(key, value);
|
|
1810
|
+
if (filteredValue !== void 0) {
|
|
1811
|
+
return filteredValue === SKIP ? void 0 : filteredValue;
|
|
1812
|
+
}
|
|
1813
|
+
}
|
|
1814
|
+
return value;
|
|
1815
|
+
} catch (error) {
|
|
1816
|
+
return `ERROR: ${error.message}`;
|
|
1642
1817
|
}
|
|
1643
1818
|
}
|
|
1644
|
-
|
|
1819
|
+
try {
|
|
1820
|
+
return JSON.stringify(obj, replacer, indent);
|
|
1821
|
+
} catch (error) {
|
|
1822
|
+
return `ERROR: ${error.message}`;
|
|
1823
|
+
}
|
|
1824
|
+
}
|
|
1825
|
+
var createReplacer = ({ omit: omit2, parse, maxDepth, maxArrayLen, maxStringLen } = {}) => {
|
|
1826
|
+
let currentDepth = 0;
|
|
1827
|
+
const depthMap = /* @__PURE__ */ new WeakMap();
|
|
1828
|
+
return function(key, value) {
|
|
1829
|
+
if (key === "") {
|
|
1830
|
+
currentDepth = 0;
|
|
1831
|
+
} else if (this && typeof this === "object") {
|
|
1832
|
+
const parentDepth = depthMap.get(this) ?? 0;
|
|
1833
|
+
currentDepth = parentDepth + 1;
|
|
1834
|
+
}
|
|
1835
|
+
if (typeof value === "function") {
|
|
1836
|
+
return SKIP;
|
|
1837
|
+
}
|
|
1838
|
+
if (maxArrayLen != null && Array.isArray(value) && value.length > maxArrayLen) {
|
|
1839
|
+
return `[length: ${value.length}]`;
|
|
1840
|
+
}
|
|
1841
|
+
if (value && typeof value === "object") {
|
|
1842
|
+
depthMap.set(value, currentDepth);
|
|
1843
|
+
if (maxDepth != null && currentDepth >= maxDepth) {
|
|
1844
|
+
return Array.isArray(value) ? `[{ length: ${value.length} }]` : `{ keys: ${Object.keys(value).length} }`;
|
|
1845
|
+
}
|
|
1846
|
+
}
|
|
1847
|
+
if (omit2?.includes(key)) {
|
|
1848
|
+
return SKIP;
|
|
1849
|
+
}
|
|
1850
|
+
if (parse?.includes(key) && typeof value === "string") {
|
|
1851
|
+
try {
|
|
1852
|
+
return JSON.parse(value);
|
|
1853
|
+
} catch {
|
|
1854
|
+
return value;
|
|
1855
|
+
}
|
|
1856
|
+
}
|
|
1857
|
+
if (maxStringLen != null && typeof value === "string" && value.length > maxStringLen) {
|
|
1858
|
+
return value.slice(0, maxStringLen) + "...";
|
|
1859
|
+
}
|
|
1860
|
+
return value;
|
|
1861
|
+
};
|
|
1645
1862
|
};
|
|
1863
|
+
var defaultFilter = createReplacer();
|
|
1646
1864
|
|
|
1647
1865
|
// src/sliding-window-summary.ts
|
|
1648
1866
|
import { invariant as invariant5 } from "@dxos/invariant";
|
|
@@ -1748,6 +1966,7 @@ function trim(strings, ...values) {
|
|
|
1748
1966
|
const minIndent = Math.min(...lines.filter((l) => l.trim()).map((l) => l.match(/^[ \t]*/)?.[0].length ?? 0));
|
|
1749
1967
|
return lines.map((l) => l.slice(minIndent)).join("\n");
|
|
1750
1968
|
}
|
|
1969
|
+
var kebabize = (str) => str.replace(/[A-Z]+(?![a-z])|[A-Z]/g, ($, ofs) => (ofs ? "-" : "") + $.toLowerCase());
|
|
1751
1970
|
|
|
1752
1971
|
// src/sum.ts
|
|
1753
1972
|
var sum = (values) => values.reduce((a, b) => a + b, 0);
|
|
@@ -1761,18 +1980,6 @@ var throwUnhandledError = (error) => {
|
|
|
1761
1980
|
|
|
1762
1981
|
// src/to-fallback.ts
|
|
1763
1982
|
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
1983
|
"\u{1F47B}",
|
|
1777
1984
|
"\u{1F479}",
|
|
1778
1985
|
"\u{1F47D}",
|
|
@@ -1908,17 +2115,18 @@ var idEmoji = [
|
|
|
1908
2115
|
];
|
|
1909
2116
|
var idHue = [
|
|
1910
2117
|
"red",
|
|
1911
|
-
|
|
2118
|
+
"orange",
|
|
1912
2119
|
"amber",
|
|
1913
|
-
|
|
2120
|
+
"yellow",
|
|
1914
2121
|
"lime",
|
|
1915
2122
|
"green",
|
|
1916
2123
|
"emerald",
|
|
1917
2124
|
"teal",
|
|
1918
2125
|
"cyan",
|
|
1919
|
-
//
|
|
1920
|
-
// '
|
|
1921
|
-
// '
|
|
2126
|
+
// Omit colors similar to primary accent.
|
|
2127
|
+
// 'sky' as const,
|
|
2128
|
+
// 'blue' as const,
|
|
2129
|
+
// 'indigo' as const,
|
|
1922
2130
|
"violet",
|
|
1923
2131
|
"purple",
|
|
1924
2132
|
"fuchsia",
|
|
@@ -2048,7 +2256,7 @@ var stringifyTree = (node, ancestors = [], rows = []) => {
|
|
|
2048
2256
|
};
|
|
2049
2257
|
|
|
2050
2258
|
// src/types.ts
|
|
2051
|
-
var
|
|
2259
|
+
var isTruthy = (value) => !!value;
|
|
2052
2260
|
var isNonNullable = (value) => value != null;
|
|
2053
2261
|
var doAsync = async (fn) => fn();
|
|
2054
2262
|
var getProviderValue = (provider, arg) => {
|
|
@@ -2078,6 +2286,113 @@ var arrayMove = (array, from, to) => {
|
|
|
2078
2286
|
array.splice(to < 0 ? array.length + to : to, 0, array.splice(from, 1)[0]);
|
|
2079
2287
|
return array;
|
|
2080
2288
|
};
|
|
2289
|
+
function arraySwap(array, from, to) {
|
|
2290
|
+
const current = array[from];
|
|
2291
|
+
array[from] = array[to];
|
|
2292
|
+
array[to] = current;
|
|
2293
|
+
return array;
|
|
2294
|
+
}
|
|
2295
|
+
|
|
2296
|
+
// src/unit.ts
|
|
2297
|
+
var createFormat = (unit) => {
|
|
2298
|
+
return (n, precision = unit.precision ?? 0) => {
|
|
2299
|
+
const value = n / unit.quotient;
|
|
2300
|
+
return {
|
|
2301
|
+
unit,
|
|
2302
|
+
value,
|
|
2303
|
+
formattedValue: value.toFixed(precision),
|
|
2304
|
+
toString: () => `${value.toFixed(precision)}${unit.symbol}`
|
|
2305
|
+
};
|
|
2306
|
+
};
|
|
2307
|
+
};
|
|
2308
|
+
var MS_SECONDS = 1e3;
|
|
2309
|
+
var MS_MINUTES = 60 * MS_SECONDS;
|
|
2310
|
+
var MS_HOURS = 60 * MS_MINUTES;
|
|
2311
|
+
var Unit = {
|
|
2312
|
+
// General.
|
|
2313
|
+
Percent: createFormat({
|
|
2314
|
+
symbol: "%",
|
|
2315
|
+
quotient: 1 / 100,
|
|
2316
|
+
precision: 2
|
|
2317
|
+
}),
|
|
2318
|
+
Thousand: createFormat({
|
|
2319
|
+
symbol: "k",
|
|
2320
|
+
quotient: 1e3,
|
|
2321
|
+
precision: 2
|
|
2322
|
+
}),
|
|
2323
|
+
// Bytes (note KB vs KiB).
|
|
2324
|
+
Gigabyte: createFormat({
|
|
2325
|
+
symbol: "GB",
|
|
2326
|
+
quotient: 1e3 * 1e3 * 1e3,
|
|
2327
|
+
precision: 2
|
|
2328
|
+
}),
|
|
2329
|
+
Megabyte: createFormat({
|
|
2330
|
+
symbol: "MB",
|
|
2331
|
+
quotient: 1e3 * 1e3,
|
|
2332
|
+
precision: 2
|
|
2333
|
+
}),
|
|
2334
|
+
Kilobyte: createFormat({
|
|
2335
|
+
symbol: "KB",
|
|
2336
|
+
quotient: 1e3,
|
|
2337
|
+
precision: 2
|
|
2338
|
+
}),
|
|
2339
|
+
Byte: createFormat({
|
|
2340
|
+
symbol: "B",
|
|
2341
|
+
quotient: 1
|
|
2342
|
+
}),
|
|
2343
|
+
// Time.
|
|
2344
|
+
Hour: createFormat({
|
|
2345
|
+
symbol: "h",
|
|
2346
|
+
quotient: MS_HOURS
|
|
2347
|
+
}),
|
|
2348
|
+
Minute: createFormat({
|
|
2349
|
+
symbol: "m",
|
|
2350
|
+
quotient: MS_MINUTES
|
|
2351
|
+
}),
|
|
2352
|
+
Second: createFormat({
|
|
2353
|
+
symbol: "s",
|
|
2354
|
+
quotient: MS_SECONDS,
|
|
2355
|
+
precision: 1
|
|
2356
|
+
}),
|
|
2357
|
+
Millisecond: createFormat({
|
|
2358
|
+
symbol: "ms",
|
|
2359
|
+
quotient: 1
|
|
2360
|
+
}),
|
|
2361
|
+
Duration: (n) => {
|
|
2362
|
+
const hours = Math.floor(n / MS_HOURS);
|
|
2363
|
+
const minutes = Math.floor(n % MS_HOURS / MS_MINUTES);
|
|
2364
|
+
if (hours) {
|
|
2365
|
+
const formattedValue = minutes ? `${hours}h ${minutes}m` : `${hours}h`;
|
|
2366
|
+
return {
|
|
2367
|
+
unit: {
|
|
2368
|
+
symbol: "h",
|
|
2369
|
+
quotient: MS_HOURS
|
|
2370
|
+
},
|
|
2371
|
+
value: hours,
|
|
2372
|
+
formattedValue,
|
|
2373
|
+
toString: () => formattedValue
|
|
2374
|
+
};
|
|
2375
|
+
}
|
|
2376
|
+
if (minutes) {
|
|
2377
|
+
const seconds2 = (n - MS_MINUTES * minutes) / MS_SECONDS;
|
|
2378
|
+
const formattedValue = seconds2 ? `${minutes}m ${seconds2}s` : `${minutes}m`;
|
|
2379
|
+
return {
|
|
2380
|
+
unit: {
|
|
2381
|
+
symbol: "m",
|
|
2382
|
+
quotient: MS_MINUTES
|
|
2383
|
+
},
|
|
2384
|
+
value: minutes,
|
|
2385
|
+
formattedValue,
|
|
2386
|
+
toString: () => formattedValue
|
|
2387
|
+
};
|
|
2388
|
+
}
|
|
2389
|
+
const seconds = n >= MS_SECONDS;
|
|
2390
|
+
if (seconds) {
|
|
2391
|
+
return Unit.Second(n);
|
|
2392
|
+
}
|
|
2393
|
+
return Unit.Millisecond(n);
|
|
2394
|
+
}
|
|
2395
|
+
};
|
|
2081
2396
|
|
|
2082
2397
|
// src/url.ts
|
|
2083
2398
|
var createUrl = (url, search) => {
|
|
@@ -2091,15 +2406,19 @@ var createUrl = (url, search) => {
|
|
|
2091
2406
|
// src/weak.ts
|
|
2092
2407
|
var WeakDictionary = class {
|
|
2093
2408
|
_internal = /* @__PURE__ */ new Map();
|
|
2094
|
-
_finalization = new FinalizationRegistry((
|
|
2095
|
-
|
|
2409
|
+
_finalization = new FinalizationRegistry(({ key, ref }) => {
|
|
2410
|
+
if (this._internal.get(key) === ref) {
|
|
2411
|
+
this._internal.delete(key);
|
|
2412
|
+
}
|
|
2096
2413
|
});
|
|
2097
2414
|
constructor(entries2) {
|
|
2098
|
-
|
|
2099
|
-
key,
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2415
|
+
if (entries2) {
|
|
2416
|
+
for (const [key, value] of entries2) {
|
|
2417
|
+
const ref = new WeakRef(value);
|
|
2418
|
+
this._internal.set(key, ref);
|
|
2419
|
+
this._register(key, value, ref);
|
|
2420
|
+
}
|
|
2421
|
+
}
|
|
2103
2422
|
}
|
|
2104
2423
|
*entries() {
|
|
2105
2424
|
for (const [key, value] of this._internal) {
|
|
@@ -2139,10 +2458,45 @@ var WeakDictionary = class {
|
|
|
2139
2458
|
return this._internal.get(key)?.deref();
|
|
2140
2459
|
}
|
|
2141
2460
|
set(key, value) {
|
|
2142
|
-
this._internal.
|
|
2143
|
-
|
|
2461
|
+
const previous = this._internal.get(key)?.deref();
|
|
2462
|
+
if (previous) {
|
|
2463
|
+
this._unregister(previous);
|
|
2464
|
+
}
|
|
2465
|
+
const ref = new WeakRef(value);
|
|
2466
|
+
this._internal.set(key, ref);
|
|
2467
|
+
this._register(key, value, ref);
|
|
2144
2468
|
return this;
|
|
2145
2469
|
}
|
|
2470
|
+
/**
|
|
2471
|
+
* Returns the value for the given key if present, otherwise inserts and returns the default value.
|
|
2472
|
+
* @param key - The key to look up or insert.
|
|
2473
|
+
* @param defaultValue - The value to insert if the key is not present.
|
|
2474
|
+
* @returns The existing or newly inserted value.
|
|
2475
|
+
*/
|
|
2476
|
+
getOrInsert(key, defaultValue) {
|
|
2477
|
+
const existing = this.get(key);
|
|
2478
|
+
if (existing !== void 0) {
|
|
2479
|
+
return existing;
|
|
2480
|
+
}
|
|
2481
|
+
this.set(key, defaultValue);
|
|
2482
|
+
return defaultValue;
|
|
2483
|
+
}
|
|
2484
|
+
/**
|
|
2485
|
+
* Returns the value for the given key if present, otherwise computes, inserts, and returns a new value.
|
|
2486
|
+
* The callback is only invoked when the key is missing.
|
|
2487
|
+
* @param key - The key to look up or insert.
|
|
2488
|
+
* @param callbackfn - Function to compute the value if the key is not present.
|
|
2489
|
+
* @returns The existing or newly computed value.
|
|
2490
|
+
*/
|
|
2491
|
+
getOrInsertComputed(key, callbackfn) {
|
|
2492
|
+
const existing = this.get(key);
|
|
2493
|
+
if (existing !== void 0) {
|
|
2494
|
+
return existing;
|
|
2495
|
+
}
|
|
2496
|
+
const value = callbackfn(key);
|
|
2497
|
+
this.set(key, value);
|
|
2498
|
+
return value;
|
|
2499
|
+
}
|
|
2146
2500
|
has(key) {
|
|
2147
2501
|
return this._internal.has(key) && this._internal.get(key).deref() !== void 0;
|
|
2148
2502
|
}
|
|
@@ -2173,9 +2527,10 @@ var WeakDictionary = class {
|
|
|
2173
2527
|
}
|
|
2174
2528
|
});
|
|
2175
2529
|
}
|
|
2176
|
-
_register(key, value) {
|
|
2177
|
-
this._finalization.register(value,
|
|
2178
|
-
|
|
2530
|
+
_register(key, value, ref) {
|
|
2531
|
+
this._finalization.register(value, {
|
|
2532
|
+
key,
|
|
2533
|
+
ref
|
|
2179
2534
|
}, value);
|
|
2180
2535
|
}
|
|
2181
2536
|
_unregister(value) {
|
|
@@ -2191,11 +2546,14 @@ export {
|
|
|
2191
2546
|
ComplexSet,
|
|
2192
2547
|
HumanHasher,
|
|
2193
2548
|
MapEntry,
|
|
2549
|
+
SKIP,
|
|
2194
2550
|
SlidingWindowSummary,
|
|
2195
2551
|
Tracer,
|
|
2552
|
+
Unit,
|
|
2196
2553
|
WeakDictionary,
|
|
2197
2554
|
accessBy,
|
|
2198
2555
|
arrayMove,
|
|
2556
|
+
arraySwap,
|
|
2199
2557
|
arrayToBuffer,
|
|
2200
2558
|
arrayToHex,
|
|
2201
2559
|
arrayToString,
|
|
@@ -2206,19 +2564,28 @@ export {
|
|
|
2206
2564
|
capitalize,
|
|
2207
2565
|
chunkArray,
|
|
2208
2566
|
clamp,
|
|
2567
|
+
clearCaches,
|
|
2568
|
+
clearIndexedDB,
|
|
2569
|
+
clearOPFS,
|
|
2570
|
+
clearServiceWorkers,
|
|
2209
2571
|
clearUndefined,
|
|
2572
|
+
coerceArray,
|
|
2210
2573
|
compareMulti,
|
|
2211
2574
|
compareObject,
|
|
2212
2575
|
compareScalar,
|
|
2213
2576
|
compareString,
|
|
2577
|
+
compositeKey,
|
|
2214
2578
|
createBinder,
|
|
2215
2579
|
createBucketReducer,
|
|
2580
|
+
createFilename,
|
|
2216
2581
|
createGroupReducer,
|
|
2582
|
+
createReplacer,
|
|
2217
2583
|
createSetDispatch,
|
|
2218
2584
|
createUrl,
|
|
2219
2585
|
decamelize,
|
|
2220
2586
|
deepMapValues,
|
|
2221
2587
|
deepMapValuesAsync,
|
|
2588
|
+
defaultFilter,
|
|
2222
2589
|
defaultMap,
|
|
2223
2590
|
defer,
|
|
2224
2591
|
deferAsync,
|
|
@@ -2230,12 +2597,11 @@ export {
|
|
|
2230
2597
|
entry,
|
|
2231
2598
|
exponentialBackoffInterval,
|
|
2232
2599
|
forEachAsync,
|
|
2233
|
-
|
|
2600
|
+
formatErrorWithCauses,
|
|
2234
2601
|
getAsyncProviderValue,
|
|
2235
2602
|
getDate,
|
|
2236
2603
|
getDebugName,
|
|
2237
2604
|
getDeep,
|
|
2238
|
-
getFirstTwoRenderableChars,
|
|
2239
2605
|
getHostPlatform,
|
|
2240
2606
|
getPrototypeSpecificInstanceId,
|
|
2241
2607
|
getProviderValue,
|
|
@@ -2251,14 +2617,19 @@ export {
|
|
|
2251
2617
|
intersectBy,
|
|
2252
2618
|
intersection,
|
|
2253
2619
|
iosCheck,
|
|
2620
|
+
isBun,
|
|
2621
|
+
isMobile,
|
|
2622
|
+
isMobileOrTablet,
|
|
2254
2623
|
isNode,
|
|
2255
2624
|
isNonNullable,
|
|
2256
|
-
|
|
2625
|
+
isTauri,
|
|
2626
|
+
isTruthy,
|
|
2257
2627
|
joinTables,
|
|
2258
2628
|
jsonKeyReplacer,
|
|
2259
2629
|
jsonReplacer,
|
|
2260
2630
|
jsonify,
|
|
2261
2631
|
jsonlogify,
|
|
2632
|
+
kebabize,
|
|
2262
2633
|
keyToEmoji,
|
|
2263
2634
|
keyToFallback,
|
|
2264
2635
|
keyToHue,
|
|
@@ -2267,7 +2638,6 @@ export {
|
|
|
2267
2638
|
makeSet,
|
|
2268
2639
|
mapValues,
|
|
2269
2640
|
median,
|
|
2270
|
-
mobileAndTabletCheck,
|
|
2271
2641
|
numericalValues,
|
|
2272
2642
|
omit,
|
|
2273
2643
|
orderKeys,
|
|
@@ -2283,15 +2653,18 @@ export {
|
|
|
2283
2653
|
removeBy,
|
|
2284
2654
|
removeProperties,
|
|
2285
2655
|
removeUndefinedProperties,
|
|
2656
|
+
retry,
|
|
2286
2657
|
safariCheck,
|
|
2287
2658
|
safeAwaitAll,
|
|
2288
2659
|
safeInstanceof,
|
|
2289
2660
|
safeParseFloat,
|
|
2290
2661
|
safeParseInt,
|
|
2291
2662
|
safeParseJson,
|
|
2292
|
-
|
|
2663
|
+
safeStringify,
|
|
2664
|
+
safeUrl,
|
|
2293
2665
|
setDeep,
|
|
2294
2666
|
sortKeys,
|
|
2667
|
+
splitCompositeKey,
|
|
2295
2668
|
stringToArray,
|
|
2296
2669
|
stringifyTree,
|
|
2297
2670
|
stripUndefined,
|