@extable/core 0.3.5 → 0.3.7

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.
@@ -0,0 +1,1017 @@
1
+ function R() {
2
+ return typeof crypto < "u" && "randomUUID" in crypto ? crypto.randomUUID() : `row_${Math.random().toString(16).slice(2)}`;
3
+ }
4
+ function q(s) {
5
+ if (s !== void 0)
6
+ return Array.isArray(s) ? s : [s];
7
+ }
8
+ function U(s) {
9
+ if (s)
10
+ try {
11
+ s.remove();
12
+ } catch {
13
+ }
14
+ }
15
+ const w = (s, t = 2) => s.toString().padStart(t, "0"), D = {
16
+ yyyy: (s) => w(s.getFullYear(), 4),
17
+ MM: (s) => w(s.getMonth() + 1),
18
+ dd: (s) => w(s.getDate()),
19
+ HH: (s) => w(s.getHours()),
20
+ hh: (s) => {
21
+ const t = s.getHours() % 12 || 12;
22
+ return w(t);
23
+ },
24
+ mm: (s) => w(s.getMinutes()),
25
+ ss: (s) => w(s.getSeconds()),
26
+ a: (s) => s.getHours() >= 12 ? "PM" : "AM"
27
+ }, M = Object.keys(D).sort((s, t) => t.length - s.length), F = /* @__PURE__ */ new Set(["yyyy", "MM", "dd"]), T = /* @__PURE__ */ new Set(["HH", "hh", "mm", "ss", "a"]), A = /* @__PURE__ */ new Set([...F, ...T]), S = {
28
+ iso: "yyyy-MM-dd",
29
+ us: "MM/dd/yyyy",
30
+ eu: "dd.MM.yyyy"
31
+ }, C = {
32
+ iso: "HH:mm:ss",
33
+ "24h": "HH:mm",
34
+ "12h": "hh:mm a"
35
+ }, b = {
36
+ iso: "yyyy-MM-dd'T'HH:mm:ss'Z'",
37
+ "iso-24h": "yyyy-MM-dd'T'HH:mm:ss'Z'",
38
+ "iso-12h": "yyyy-MM-dd hh:mm a",
39
+ us: "MM/dd/yyyy HH:mm",
40
+ "us-24h": "MM/dd/yyyy HH:mm",
41
+ "us-12h": "MM/dd/yyyy hh:mm a",
42
+ eu: "dd.MM.yyyy HH:mm",
43
+ "eu-24h": "dd.MM.yyyy HH:mm",
44
+ "eu-12h": "dd.MM.yyyy hh:mm a"
45
+ };
46
+ function N(s) {
47
+ const t = new Date(s);
48
+ return Number.isNaN(t.getTime()) ? null : t;
49
+ }
50
+ function W(s, t) {
51
+ let e = "", n = 0, i = !1;
52
+ for (; n < t.length; ) {
53
+ const r = t[n];
54
+ if (r === "'") {
55
+ i = !i, n += 1;
56
+ continue;
57
+ }
58
+ if (i) {
59
+ e += r, n += 1;
60
+ continue;
61
+ }
62
+ let l = !1;
63
+ for (const a of M)
64
+ if (t.startsWith(a, n)) {
65
+ e += D[a](s), n += a.length, l = !0;
66
+ break;
67
+ }
68
+ l || (e += r, n += 1);
69
+ }
70
+ return e;
71
+ }
72
+ function B(s, t) {
73
+ return t === "date" ? F.has(s) : t === "time" ? T.has(s) : A.has(s);
74
+ }
75
+ function H(s, t) {
76
+ let e = 0, n = !1;
77
+ for (; e < s.length; ) {
78
+ if (s[e] === "'") {
79
+ n = !n, e += 1;
80
+ continue;
81
+ }
82
+ if (n) {
83
+ e += 1;
84
+ continue;
85
+ }
86
+ let r = !1;
87
+ for (const l of M)
88
+ if (s.startsWith(l, e)) {
89
+ if (!B(l, t)) return !1;
90
+ e += l.length, r = !0;
91
+ break;
92
+ }
93
+ r || (e += 1);
94
+ }
95
+ return !0;
96
+ }
97
+ function k(s, t) {
98
+ if (!s)
99
+ return t === "date" ? S.iso : t === "time" ? C.iso : b.iso;
100
+ if (t === "date" && S[s]) return S[s];
101
+ if (t === "time" && C[s]) return C[s];
102
+ if (t === "datetime" && b[s]) return b[s];
103
+ const e = t === "date" ? S.iso : t === "time" ? C.iso : b.iso;
104
+ return H(s, t) ? s : e;
105
+ }
106
+ const E = (s) => !Number.isNaN(s.getTime()), j = (s) => {
107
+ if (typeof s == "string") return s;
108
+ if (s && typeof s == "object") {
109
+ const t = s;
110
+ if (t.kind === "enum")
111
+ return typeof t.value == "string" ? t.value : null;
112
+ }
113
+ return null;
114
+ }, O = (s) => {
115
+ if (Array.isArray(s) && s.every((t) => typeof t == "string")) return s;
116
+ if (s && typeof s == "object") {
117
+ const t = s;
118
+ if (t.kind === "tags") {
119
+ const e = t.values;
120
+ return Array.isArray(e) && e.every((n) => typeof n == "string") ? e : null;
121
+ }
122
+ }
123
+ return null;
124
+ };
125
+ function I(s, t) {
126
+ if (s == null) return null;
127
+ switch (t.type) {
128
+ case "string": {
129
+ if (typeof s != "string") return "Expected a string";
130
+ const e = t.format;
131
+ if (e?.maxLength !== void 0 && s.length > e.maxLength)
132
+ return `Too long (max ${e.maxLength})`;
133
+ if (e?.regex)
134
+ try {
135
+ if (!new RegExp(e.regex).test(s)) return "Does not match pattern";
136
+ } catch {
137
+ }
138
+ return null;
139
+ }
140
+ case "number":
141
+ return typeof s != "number" || !Number.isFinite(s) ? "Expected a number" : t.format?.signed === !1 && s < 0 ? "Expected a non-negative number" : null;
142
+ case "int":
143
+ return typeof s != "number" || !Number.isSafeInteger(s) ? "Expected an integer" : null;
144
+ case "uint":
145
+ return typeof s != "number" || !Number.isSafeInteger(s) || s < 0 ? "Expected a non-negative integer" : null;
146
+ case "boolean":
147
+ return typeof s != "boolean" ? "Expected a boolean" : null;
148
+ case "enum": {
149
+ const e = j(s);
150
+ if (!e) return "Expected an enum value";
151
+ const n = t.enum?.allowCustom ?? !1, i = t.enum?.options ?? [];
152
+ return !n && i.length && !i.includes(e) ? "Not in allowed options" : null;
153
+ }
154
+ case "tags": {
155
+ const e = O(s);
156
+ if (!e) return "Expected a list of tags";
157
+ const n = t.tags?.allowCustom ?? !1, i = t.tags?.options ?? [];
158
+ if (!n && i.length) {
159
+ for (const r of e)
160
+ if (!i.includes(r)) return "Contains an unknown tag";
161
+ }
162
+ return null;
163
+ }
164
+ case "date":
165
+ case "time":
166
+ case "datetime": {
167
+ const e = t.format;
168
+ if (t.type === "date" ? k(e, "date") : t.type === "time" ? k(e, "time") : k(e, "datetime"), s instanceof Date) return E(s) ? null : "Invalid date";
169
+ if (typeof s == "string") {
170
+ const n = N(s);
171
+ return n && E(n) ? null : "Invalid date/time";
172
+ }
173
+ return "Expected a date/time string";
174
+ }
175
+ default:
176
+ return null;
177
+ }
178
+ }
179
+ class X {
180
+ constructor(t, e, n) {
181
+ this.rows = [], this.baseIndexById = /* @__PURE__ */ new Map(), this.dataVersion = 0, this.visibleRowsCache = null, this.distinctValueCache = /* @__PURE__ */ new Map(), this.pending = /* @__PURE__ */ new Map(), this.rowVersion = /* @__PURE__ */ new Map(), this.listeners = /* @__PURE__ */ new Set(), this.cellStyles = /* @__PURE__ */ new Map(), this.cellConditionalStyles = /* @__PURE__ */ new Map(), this.computedCache = /* @__PURE__ */ new Map(), this.conditionalCache = /* @__PURE__ */ new Map(), this.rowConditionalCache = /* @__PURE__ */ new Map(), this.formulaDiagnostics = /* @__PURE__ */ new Map(), this.conditionalDiagnostics = /* @__PURE__ */ new Map(), this.columnReadonlyCache = /* @__PURE__ */ new Map(), this.baseValidationErrors = /* @__PURE__ */ new Map(), this.uniqueValidationErrors = /* @__PURE__ */ new Map(), this.notifySuspended = !1, this.notifyDirty = !1, this.schema = e, this.view = n, this.setData(t ?? []);
182
+ }
183
+ subscribe(t) {
184
+ return this.listeners.add(t), () => this.listeners.delete(t);
185
+ }
186
+ notify() {
187
+ if (this.visibleRowsCache = null, this.distinctValueCache.clear(), this.notifySuspended) {
188
+ this.notifyDirty = !0;
189
+ return;
190
+ }
191
+ for (const t of this.listeners) t();
192
+ }
193
+ batchUpdate(t) {
194
+ this.notifySuspended = !0;
195
+ try {
196
+ t();
197
+ } finally {
198
+ this.notifySuspended = !1, this.notifyDirty && (this.notifyDirty = !1, this.notify());
199
+ }
200
+ }
201
+ setData(t) {
202
+ this.dataVersion += 1, this.pending.clear(), this.cellStyles.clear(), this.cellConditionalStyles.clear(), this.computedCache.clear(), this.conditionalCache.clear(), this.columnReadonlyCache.clear(), this.rowConditionalCache.clear(), this.formulaDiagnostics.clear(), this.conditionalDiagnostics.clear(), this.baseValidationErrors.clear(), this.uniqueValidationErrors.clear(), this.rows = (t ?? []).map((e, n) => {
203
+ const i = e?.id, r = typeof i == "string" && i ? i : R();
204
+ return this.rowVersion.set(r, 0), {
205
+ id: r,
206
+ raw: e,
207
+ displayIndex: n + 1
208
+ };
209
+ }), this.rebuildBaseIndex(), this.recomputeValidationErrors(), this.notify();
210
+ }
211
+ setSchema(t) {
212
+ this.dataVersion += 1, this.schema = t, this.computedCache.clear(), this.conditionalCache.clear(), this.columnReadonlyCache.clear(), this.rowConditionalCache.clear(), this.formulaDiagnostics.clear(), this.conditionalDiagnostics.clear(), this.recomputeValidationErrors(), this.notify();
213
+ }
214
+ setView(t) {
215
+ this.dataVersion += 1, Array.isArray(t.sorts) && t.sorts.length > 1 ? this.view = { ...t, sorts: t.sorts.slice(0, 1) } : this.view = t, this.notify();
216
+ }
217
+ getSchema() {
218
+ return { ...this.schema, columns: this.getColumns() };
219
+ }
220
+ getColumns() {
221
+ return this.schema.columns;
222
+ }
223
+ getRowConditionalStyleFn() {
224
+ return this.schema.row?.conditionalStyle ?? null;
225
+ }
226
+ getView() {
227
+ return this.view;
228
+ }
229
+ getDataVersion() {
230
+ return this.dataVersion;
231
+ }
232
+ getFullSchema() {
233
+ return this.schema;
234
+ }
235
+ listRows() {
236
+ return this.computeVisibleRows().rows;
237
+ }
238
+ listAllRows() {
239
+ return this.rows;
240
+ }
241
+ getAllRowCount() {
242
+ return this.rows.length;
243
+ }
244
+ findRow(t) {
245
+ const e = this.baseIndexById.get(t);
246
+ if (e === void 0) return null;
247
+ const n = this.rows[e];
248
+ if (n && n.id === t) return { row: n, index: e };
249
+ const i = this.rows.findIndex((l) => l.id === t);
250
+ if (i < 0) return null;
251
+ const r = this.rows[i];
252
+ return r ? (this.rebuildBaseIndex(), { row: r, index: i }) : null;
253
+ }
254
+ getRowHeight(t) {
255
+ return this.view.rowHeights?.[t];
256
+ }
257
+ setRowHeight(t, e) {
258
+ this.view.rowHeights || (this.view.rowHeights = {}), this.view.rowHeights[t] !== e && (this.view.rowHeights[t] = e, this.notify());
259
+ }
260
+ setRowHeightsBulk(t) {
261
+ const e = Object.entries(t);
262
+ if (e.length === 0) return;
263
+ this.view.rowHeights || (this.view.rowHeights = {});
264
+ let n = !1;
265
+ for (const [i, r] of e)
266
+ this.view.rowHeights[i] !== r && (this.view.rowHeights[i] = r, n = !0);
267
+ n && this.notify();
268
+ }
269
+ getCell(t, e) {
270
+ const n = this.findRow(t);
271
+ if (!n) return;
272
+ const i = n.row, r = this.pending.get(t);
273
+ return r && e in r ? r[e] : i.raw[e];
274
+ }
275
+ getRawCell(t, e) {
276
+ const n = this.findRow(t);
277
+ return n ? n.row.raw[e] : void 0;
278
+ }
279
+ isRowReadonly(t) {
280
+ const e = this.findRow(t);
281
+ return e ? !!e.row.raw._readonly : !1;
282
+ }
283
+ isActionType(t) {
284
+ return t === "button" || t === "link";
285
+ }
286
+ supportsConditionalReadonly(t) {
287
+ return t === "boolean" || t === "number" || t === "date" || t === "time" || t === "datetime" || t === "string" || t === "enum" || t === "tags";
288
+ }
289
+ isColumnReadonly(t) {
290
+ const e = this.schema.columns.find((n) => n.key === t);
291
+ return this.isActionType(e?.type) ? !0 : !!(e?.readonly === !0 || e?.formula);
292
+ }
293
+ evalReadonlyFn(t, e) {
294
+ try {
295
+ const n = t(e);
296
+ return n instanceof Error ? { value: !1, diagnostic: { level: "warning", message: n.message, source: "conditionalStyle" } } : { value: !!n, diagnostic: null };
297
+ } catch (n) {
298
+ return { value: !1, diagnostic: { level: "warning", message: n instanceof Error ? n.message : String(n ?? "error"), source: "conditionalStyle" } };
299
+ }
300
+ }
301
+ resolveColumnReadonly(t, e) {
302
+ const n = e.readonly;
303
+ if (!n || typeof n != "function") return { value: !1, diagnostic: null };
304
+ const i = this.getRowVersion(t), r = `${t}::${String(e.key)}::ro`, l = this.columnReadonlyCache.get(r);
305
+ if (l && l.version === i && l.fnRef === n)
306
+ return { value: l.value, diagnostic: l.diagnostic };
307
+ const a = this.getRowObjectEffective(t);
308
+ if (!a) {
309
+ const c = { version: i, fnRef: n, value: !1, diagnostic: null };
310
+ return this.columnReadonlyCache.set(r, c), { value: !1, diagnostic: null };
311
+ }
312
+ const o = this.evalReadonlyFn(n, a);
313
+ return this.columnReadonlyCache.set(r, { version: i, fnRef: n, value: o.value, diagnostic: o.diagnostic }), { value: o.value, diagnostic: o.diagnostic };
314
+ }
315
+ getCellInteraction(t, e) {
316
+ const n = this.schema.columns.find((h) => String(h.key) === String(e));
317
+ if (!n) return { readonly: !1, disabled: !1, muted: !1 };
318
+ const i = this.resolveColumnReadonly(t, n), r = this.isRowReadonly(t) || this.isColumnReadonly(e) || !!i.value, l = this.resolveConditionalStyle(t, n).delta, a = this.getCellStyle(t, e), c = this.supportsConditionalReadonly(n.type) && !!(n.style?.readonly || l?.readonly || a?.readonly), f = this.isActionType(n.type), d = f && !!(n.style?.disabled || l?.disabled || a?.disabled), g = r || c || d, y = !!n.formula;
319
+ return { readonly: g, disabled: d, muted: d || g && !f && !y };
320
+ }
321
+ isReadonly(t, e) {
322
+ return this.getCellInteraction(t, e).readonly;
323
+ }
324
+ setCell(t, e, n, i) {
325
+ this.dataVersion += 1;
326
+ const r = this.findRow(t);
327
+ if (!r) return;
328
+ const l = r.row, a = () => {
329
+ const c = this.rowVersion.get(t) ?? 0;
330
+ this.rowVersion.set(t, c + 1);
331
+ };
332
+ if (i)
333
+ l.raw[e] = n, this.pending.delete(t), a();
334
+ else {
335
+ const c = this.getRawCell(t, e), f = this.pending.get(t) ?? {};
336
+ this.isEqual(c, n) ? delete f[e] : f[e] = n, Object.keys(f).length > 0 ? this.pending.set(t, f) : this.pending.delete(t), a();
337
+ }
338
+ this.updateValidationForCell(t, e, this.getCell(t, e)), this.schema.columns.find((c) => c.key === e)?.unique && this.recomputeUniqueValidationForColumn(e), this.clearDiagnosticsForCell(t, e), this.notify();
339
+ }
340
+ applyPending(t) {
341
+ this.dataVersion += 1;
342
+ const e = this.pending.get(t);
343
+ if (!e) return;
344
+ const n = this.findRow(t);
345
+ if (!n) return;
346
+ const i = n.row, r = /* @__PURE__ */ new Set();
347
+ for (const [l, a] of Object.entries(e)) {
348
+ i.raw[l] = a, this.updateValidationForCell(t, l, a);
349
+ const o = this.schema.columns.find((c) => String(c.key) === String(l));
350
+ o?.unique && r.add(o.key), this.clearDiagnosticsForCell(t, l);
351
+ }
352
+ this.pending.delete(t);
353
+ for (const l of r) this.recomputeUniqueValidationForColumn(l);
354
+ this.notify();
355
+ }
356
+ clearPending(t) {
357
+ this.dataVersion += 1, this.pending.delete(t), this.notify();
358
+ }
359
+ getPending() {
360
+ return this.pending;
361
+ }
362
+ hasPending(t, e) {
363
+ const n = this.pending.get(t);
364
+ return n ? e in n : !1;
365
+ }
366
+ insertRow(t) {
367
+ return this.insertRowAt(t, this.rows.length);
368
+ }
369
+ insertRowAt(t, e, n) {
370
+ this.dataVersion += 1;
371
+ const i = n ?? R(), r = Math.max(0, Math.min(e, this.rows.length));
372
+ return this.rows.splice(r, 0, { id: i, raw: t, displayIndex: 0 }), this.reindexRows(), this.rowVersion.set(i, 0), this.rebuildBaseIndex(), this.recomputeValidationErrors(), this.notify(), i;
373
+ }
374
+ removeRow(t) {
375
+ this.dataVersion += 1;
376
+ const e = this.findRow(t);
377
+ if (!e) return null;
378
+ const n = this.rows.splice(e.index, 1)[0];
379
+ return n ? (this.pending.delete(t), this.rowVersion.delete(t), this.reindexRows(), this.rebuildBaseIndex(), this.recomputeValidationErrors(), this.notify(), { row: n, index: e.index }) : null;
380
+ }
381
+ getDisplayIndex(t) {
382
+ return this.findRow(t)?.row.displayIndex ?? null;
383
+ }
384
+ getRowIndex(t) {
385
+ return this.computeVisibleRows().indexById.get(t) ?? -1;
386
+ }
387
+ getBaseRowIndex(t) {
388
+ return this.baseIndexById.get(t) ?? -1;
389
+ }
390
+ getColumnIndex(t) {
391
+ return this.getColumns().findIndex((e) => e.key === t);
392
+ }
393
+ getColumnByIndex(t) {
394
+ return this.getColumns()[t] ?? null;
395
+ }
396
+ getRowByIndex(t) {
397
+ return this.listRows()[t] ?? null;
398
+ }
399
+ rebuildBaseIndex() {
400
+ this.baseIndexById.clear();
401
+ for (let t = 0; t < this.rows.length; t += 1) {
402
+ const e = this.rows[t];
403
+ e && this.baseIndexById.set(e.id, t);
404
+ }
405
+ }
406
+ getFilterSortKey(t) {
407
+ const e = t?.excludeColumnKey, n = t?.includeSort ?? !0, i = this.view, r = (i.filters ?? []).filter((o) => {
408
+ if (e === void 0) return !0;
409
+ const c = o?.key;
410
+ return String(c) !== String(e);
411
+ }).map((o) => {
412
+ if (o?.kind === "values") {
413
+ const d = o;
414
+ return {
415
+ kind: "values",
416
+ key: String(d.key),
417
+ includeBlanks: !!d.includeBlanks,
418
+ values: (d.values ?? []).map((g) => this.stableValueKey(g))
419
+ };
420
+ }
421
+ const f = o;
422
+ return {
423
+ kind: "op",
424
+ key: String(f.key),
425
+ op: String(f.op ?? ""),
426
+ value: this.stableValueKey(f.value)
427
+ };
428
+ }).sort((o, c) => o.key === c.key ? o.kind < c.kind ? -1 : 1 : o.key < c.key ? -1 : 1), l = Object.entries(i.columnDiagnostics ?? {}).filter(([o]) => e !== void 0 ? String(o) !== String(e) : !0).map(([o, c]) => ({
429
+ key: String(o),
430
+ errors: !!c?.errors,
431
+ warnings: !!c?.warnings
432
+ })).filter((o) => o.errors || o.warnings).sort((o, c) => o.key < c.key ? -1 : o.key > c.key ? 1 : 0), a = n ? (i.sorts ?? []).slice(0, 1).map((o) => ({ key: String(o.key), dir: o.dir })) : [];
433
+ return JSON.stringify({ filters: r, columnDiagnosticsEntries: l, sorts: a });
434
+ }
435
+ stableValueKey(t) {
436
+ if (t === null) return "null";
437
+ if (t === void 0) return "undefined";
438
+ if (t instanceof Date) return `date:${t.getTime()}`;
439
+ if (typeof t == "string") return `s:${t}`;
440
+ if (typeof t == "number") return `n:${Number.isNaN(t) ? "NaN" : String(t)}`;
441
+ if (typeof t == "boolean") return `b:${t ? "1" : "0"}`;
442
+ if (typeof t == "object") {
443
+ const e = t, n = e.kind;
444
+ if (n === "enum" && typeof e.value == "string") return `enum:${e.value}`;
445
+ if (n === "tags" && Array.isArray(e.values))
446
+ return `tags:${e.values.filter((i) => typeof i == "string").join("|")}`;
447
+ }
448
+ try {
449
+ return `json:${JSON.stringify(t)}`;
450
+ } catch {
451
+ return `str:${String(t)}`;
452
+ }
453
+ }
454
+ isBlankValue(t) {
455
+ return t == null || t === "";
456
+ }
457
+ resolveFilterColumnKey(t) {
458
+ return this.getColumns().find((i) => String(i.key) === String(t))?.key ?? t;
459
+ }
460
+ getFilterCellValue(t, e) {
461
+ const n = this.getColumns().find((i) => String(i.key) === String(e));
462
+ return n ? this.resolveCellValue(t, n).value : this.getCell(t, e);
463
+ }
464
+ valuesFilterMatches(t, e) {
465
+ const n = this.resolveFilterColumnKey(e.key), i = this.getFilterCellValue(t, n);
466
+ if (this.isBlankValue(i)) return !!e.includeBlanks;
467
+ if (!e.values || e.values.length === 0) return !1;
468
+ const r = this.stableValueKey(i);
469
+ for (const l of e.values)
470
+ if (this.stableValueKey(l) === r) return !0;
471
+ return !1;
472
+ }
473
+ rowPassesColumnDiagnostics(t, e, n) {
474
+ const i = !!n.errors, r = !!n.warnings;
475
+ if (!i && !r) return !0;
476
+ const l = this.resolveFilterColumnKey(e), a = this.getColumns().find((c) => String(c.key) === String(l));
477
+ a && (this.resolveCellValue(t, a), this.resolveConditionalStyle(t, a));
478
+ const o = this.getCellMarker(t, l);
479
+ return o ? o.level === "error" ? i : r : !1;
480
+ }
481
+ computeRowsAfterFilter(t) {
482
+ const e = t?.excludeColumnKey, n = t?.includeSort ?? !0, i = this.view, r = this.getSchema(), l = (i.filters ?? []).filter((u) => {
483
+ if (e === void 0) return !0;
484
+ const h = u?.key;
485
+ return String(h) !== String(e);
486
+ }), a = Object.entries(i.columnDiagnostics ?? {}).filter(
487
+ ([u]) => e !== void 0 ? String(u) !== String(e) : !0
488
+ ), o = [];
489
+ for (const u of this.rows) {
490
+ let h = !0;
491
+ for (const m of l)
492
+ if (m?.kind === "values" && !this.valuesFilterMatches(u.id, m)) {
493
+ h = !1;
494
+ break;
495
+ }
496
+ if (h) {
497
+ for (const [m, p] of a)
498
+ if (!this.rowPassesColumnDiagnostics(u.id, m, p)) {
499
+ h = !1;
500
+ break;
501
+ }
502
+ h && o.push(u);
503
+ }
504
+ }
505
+ if (!n) return o;
506
+ const c = (i.sorts ?? []).slice(0, 1)[0];
507
+ if (!c) return o;
508
+ const f = r.columns.find((u) => String(u.key) === String(c.key));
509
+ if (!f) return o;
510
+ const d = c.dir === "desc" ? -1 : 1, g = o.map((u) => {
511
+ const h = this.getFilterCellValue(u.id, f.key), m = this.isBlankValue(h), p = this.baseIndexById.get(u.id) ?? 0;
512
+ return { row: u, v: h, blank: m, baseIndex: p };
513
+ }), y = (u, h) => {
514
+ if (u === h) return 0;
515
+ if (u instanceof Date && h instanceof Date) return u.getTime() - h.getTime();
516
+ if (typeof u == "number" && typeof h == "number") return u - h;
517
+ if (typeof u == "boolean" && typeof h == "boolean") return u === h ? 0 : u ? 1 : -1;
518
+ const m = u instanceof Date ? u.toISOString() : typeof u == "string" ? u : String(u), p = h instanceof Date ? h.toISOString() : typeof h == "string" ? h : String(h);
519
+ return m === p ? 0 : m < p ? -1 : 1;
520
+ };
521
+ return g.sort((u, h) => {
522
+ if (u.blank && h.blank) return u.baseIndex - h.baseIndex;
523
+ if (u.blank) return 1;
524
+ if (h.blank) return -1;
525
+ const m = y(u.v, h.v);
526
+ return m !== 0 ? m * d : u.baseIndex - h.baseIndex;
527
+ }), g.map((u) => u.row);
528
+ }
529
+ computeVisibleRows() {
530
+ const t = this.getFilterSortKey(), e = this.visibleRowsCache;
531
+ if (e && e.version === this.dataVersion && e.key === t) return e;
532
+ const i = this.computeRowsAfterFilter({ includeSort: !0 }), r = /* @__PURE__ */ new Map();
533
+ for (let a = 0; a < i.length; a += 1) {
534
+ const o = i[a];
535
+ o && r.set(o.id, a);
536
+ }
537
+ const l = { version: this.dataVersion, key: t, rows: i, indexById: r };
538
+ return this.visibleRowsCache = l, l;
539
+ }
540
+ getDistinctValuesForColumn(t) {
541
+ const e = `${String(t)}|${this.getFilterSortKey({ excludeColumnKey: t, includeSort: !1 })}`, n = this.distinctValueCache.get(e);
542
+ if (n && n.version === this.dataVersion) return n;
543
+ const i = this.computeRowsAfterFilter({ excludeColumnKey: t, includeSort: !1 }), r = this.getSchema().columns.find((f) => String(f.key) === String(t));
544
+ if (!r) {
545
+ const f = { version: this.dataVersion, values: [], hasBlanks: !1, total: 0 };
546
+ return this.distinctValueCache.set(e, f), f;
547
+ }
548
+ const l = /* @__PURE__ */ new Map();
549
+ let a = !1;
550
+ for (const f of i) {
551
+ const d = this.getFilterCellValue(f.id, r.key);
552
+ if (this.isBlankValue(d)) {
553
+ a = !0;
554
+ continue;
555
+ }
556
+ const g = this.stableValueKey(d);
557
+ if (l.has(g)) continue;
558
+ const y = (() => {
559
+ if (d instanceof Date) return d.toISOString();
560
+ if (typeof d == "string") return d;
561
+ if (typeof d == "number" || typeof d == "boolean") return String(d);
562
+ if (typeof d == "object" && d) {
563
+ const u = d, h = u.kind;
564
+ if (h === "enum" && typeof u.value == "string") return u.value;
565
+ if (h === "tags" && Array.isArray(u.values))
566
+ return u.values.filter((m) => typeof m == "string").join(", ");
567
+ }
568
+ return String(d);
569
+ })();
570
+ l.set(g, { value: d, label: y });
571
+ }
572
+ const o = [...l.values()].sort(
573
+ (f, d) => f.label < d.label ? -1 : f.label > d.label ? 1 : 0
574
+ ), c = {
575
+ version: this.dataVersion,
576
+ values: o,
577
+ hasBlanks: a,
578
+ total: o.length + (a ? 1 : 0)
579
+ };
580
+ return this.distinctValueCache.set(e, c), c;
581
+ }
582
+ cellStyleKey(t, e) {
583
+ return `${t}::${String(e)}`;
584
+ }
585
+ clearDiagnosticsForCell(t, e) {
586
+ const n = this.cellStyleKey(t, e);
587
+ this.formulaDiagnostics.delete(n), this.conditionalDiagnostics.delete(n);
588
+ }
589
+ getCellDiagnostic(t, e) {
590
+ const n = this.cellStyleKey(t, e), i = this.formulaDiagnostics.get(n) ?? null, r = this.conditionalDiagnostics.get(n) ?? null;
591
+ return i ? !r || i.level === "error" ? i : r.level === "error" ? r : i : r;
592
+ }
593
+ getDiagnostics() {
594
+ const t = /* @__PURE__ */ new Set();
595
+ for (const e of this.formulaDiagnostics.keys()) t.add(e);
596
+ for (const e of this.conditionalDiagnostics.keys()) t.add(e);
597
+ return [...t].map((e) => {
598
+ const n = e.indexOf("::"), i = n >= 0 ? e.slice(0, n) : e, r = n >= 0 ? e.slice(n + 2) : "";
599
+ return { rowId: i, colKey: r, diag: this.getCellDiagnostic(i, r) };
600
+ });
601
+ }
602
+ getRowObjectEffective(t) {
603
+ const e = this.findRow(t);
604
+ if (!e) return null;
605
+ const n = e.row, i = this.pending.get(t);
606
+ if (!i || Object.keys(i).length === 0)
607
+ return n.raw;
608
+ const r = { ...n.raw };
609
+ for (const [l, a] of Object.entries(i))
610
+ r[l] = a;
611
+ return r;
612
+ }
613
+ resolveCellValue(t, e) {
614
+ if (!e.formula)
615
+ return { value: this.getCell(t, e.key), diagnostic: null };
616
+ const n = this.getRowVersion(t), i = this.cellStyleKey(t, e.key), r = this.computedCache.get(i);
617
+ if (r && r.version === n && r.formulaRef === e.formula)
618
+ return r.diagnostic && this.formulaDiagnostics.set(i, r.diagnostic), {
619
+ value: r.value,
620
+ textOverride: r.textOverride,
621
+ diagnostic: r.diagnostic
622
+ };
623
+ const l = this.getRowObjectEffective(t);
624
+ if (!l) {
625
+ const a = this.getCell(t, e.key), o = {
626
+ version: n,
627
+ formulaRef: e.formula,
628
+ value: a,
629
+ diagnostic: null
630
+ };
631
+ return this.computedCache.set(i, o), { value: a, diagnostic: null };
632
+ }
633
+ try {
634
+ const a = e.formula(l);
635
+ if (Array.isArray(a) && a.length >= 2 && a[1] instanceof Error) {
636
+ const c = {
637
+ level: "warning",
638
+ message: a[1].message,
639
+ source: "formula"
640
+ }, f = a[0];
641
+ return this.computedCache.set(i, { version: n, formulaRef: e.formula, value: f, diagnostic: c }), this.formulaDiagnostics.set(i, c), { value: f, diagnostic: c };
642
+ }
643
+ const o = a;
644
+ return this.computedCache.set(i, { version: n, formulaRef: e.formula, value: o, diagnostic: null }), this.formulaDiagnostics.delete(i), { value: o, diagnostic: null };
645
+ } catch (a) {
646
+ const c = { level: "error", message: a instanceof Error ? a.message : String(a), source: "formula" };
647
+ return this.computedCache.set(i, {
648
+ version: n,
649
+ formulaRef: e.formula,
650
+ value: null,
651
+ textOverride: "#ERROR",
652
+ diagnostic: c
653
+ }), this.formulaDiagnostics.set(i, c), { value: null, textOverride: "#ERROR", diagnostic: c };
654
+ }
655
+ }
656
+ setCellConditionalStyle(t, e, n) {
657
+ const i = this.cellStyleKey(t, e);
658
+ n ? this.cellConditionalStyles.set(i, n) : this.cellConditionalStyles.delete(i), this.conditionalCache.delete(i), this.clearDiagnosticsForCell(t, e), this.notify();
659
+ }
660
+ evalConditionalStyleFn(t, e) {
661
+ try {
662
+ const n = t(e);
663
+ return n instanceof Error ? {
664
+ delta: null,
665
+ diagnostic: { level: "warning", message: n.message, source: "conditionalStyle" },
666
+ forceErrorText: !1
667
+ } : { delta: n ?? null, diagnostic: null, forceErrorText: !1 };
668
+ } catch (n) {
669
+ return {
670
+ delta: null,
671
+ diagnostic: { level: "error", message: n instanceof Error ? n.message : String(n), source: "conditionalStyle" },
672
+ forceErrorText: !0
673
+ };
674
+ }
675
+ }
676
+ resolveRowConditionalStyle(t) {
677
+ const e = this.getRowConditionalStyleFn();
678
+ if (!e) return { delta: null, diagnostic: null, forceErrorText: !1 };
679
+ const n = this.getRowVersion(t), i = this.rowConditionalCache.get(t);
680
+ if (i && i.version === n && i.fnRef === e)
681
+ return {
682
+ delta: i.delta,
683
+ diagnostic: i.diagnostic,
684
+ forceErrorText: i.forceErrorText
685
+ };
686
+ const r = this.getRowObjectEffective(t);
687
+ if (!r) {
688
+ const a = { version: n, fnRef: e, delta: null, diagnostic: null, forceErrorText: !1 };
689
+ return this.rowConditionalCache.set(t, a), { delta: null, diagnostic: null, forceErrorText: !1 };
690
+ }
691
+ const l = this.evalConditionalStyleFn(e, r);
692
+ return this.rowConditionalCache.set(t, { version: n, fnRef: e, ...l }), l;
693
+ }
694
+ resolveConditionalStyle(t, e) {
695
+ const n = this.getRowVersion(t), i = this.cellStyleKey(t, e.key), r = this.getRowObjectEffective(t), l = this.resolveRowConditionalStyle(t), a = (g, y) => y ? g ? { ...g, ...y } : { ...y } : g;
696
+ let o = null, c = null, f = !1;
697
+ if (o = a(o, l.delta), l.diagnostic && (c = l.diagnostic), f = f || l.forceErrorText, e.conditionalStyle && r) {
698
+ const g = `${t}::${String(e.key)}::col`, y = this.conditionalCache.get(g);
699
+ if (y && y.version === n && y.fnRef === e.conditionalStyle)
700
+ o = a(o, y.delta), y.diagnostic && (c === null || c.level !== "error") && (c = y.diagnostic), f = f || y.forceErrorText;
701
+ else {
702
+ const u = this.evalConditionalStyleFn(e.conditionalStyle, r);
703
+ this.conditionalCache.set(g, { version: n, fnRef: e.conditionalStyle, ...u }), o = a(o, u.delta), u.diagnostic && (c === null || c.level !== "error") && (c = u.diagnostic), f = f || u.forceErrorText;
704
+ }
705
+ }
706
+ const d = this.cellConditionalStyles.get(i);
707
+ if (d && r) {
708
+ const g = this.conditionalCache.get(i);
709
+ if (g && g.version === n && g.fnRef === d)
710
+ o = a(o, g.delta), g.diagnostic && (c === null || c.level !== "error") && (c = g.diagnostic), f = f || g.forceErrorText;
711
+ else {
712
+ const y = this.evalConditionalStyleFn(d, r);
713
+ this.conditionalCache.set(i, { version: n, fnRef: d, ...y }), o = a(o, y.delta), y.diagnostic && (c === null || c.level !== "error") && (c = y.diagnostic), f = f || y.forceErrorText;
714
+ }
715
+ }
716
+ return c ? this.conditionalDiagnostics.set(i, c) : this.conditionalDiagnostics.delete(i), { delta: o, diagnostic: c, forceErrorText: f };
717
+ }
718
+ getValidationErrors() {
719
+ const t = /* @__PURE__ */ new Map();
720
+ for (const [n, i] of this.baseValidationErrors.entries()) t.set(n, { ...i });
721
+ for (const [n, i] of this.uniqueValidationErrors.entries()) {
722
+ const r = t.get(n);
723
+ r ? t.set(n, { ...r, message: `${r.message}
724
+ ${i.message}` }) : t.set(n, { ...i });
725
+ }
726
+ const e = [...t.values()];
727
+ return e.sort((n, i) => {
728
+ const r = this.getRowIndex(n.rowId), l = this.getRowIndex(i.rowId);
729
+ if (r !== l) return r - l;
730
+ const a = this.getColumnIndex(n.colKey), o = this.getColumnIndex(i.colKey);
731
+ return a - o;
732
+ }), e;
733
+ }
734
+ getCellValidationMessage(t, e) {
735
+ const n = this.cellStyleKey(t, e), i = this.baseValidationErrors.get(n)?.message ?? null, r = this.uniqueValidationErrors.get(n)?.message ?? null;
736
+ return i ? r ? `${i}
737
+ ${r}` : i : r;
738
+ }
739
+ getCellMarker(t, e) {
740
+ const n = this.getCellDiagnostic(t, e), i = this.getCellValidationMessage(t, e);
741
+ if (!n && !i) return null;
742
+ const r = i ? "error" : n?.level ?? "warning", l = [n?.message ?? null, i].filter(Boolean).join(`
743
+ `);
744
+ return { level: r, message: l };
745
+ }
746
+ updateValidationForCell(t, e, n) {
747
+ const i = this.schema.columns.find((a) => String(a.key) === String(e));
748
+ if (!i) return;
749
+ const r = I(n, i), l = this.cellStyleKey(t, e);
750
+ r ? this.baseValidationErrors.set(l, { rowId: t, colKey: e, message: r }) : this.baseValidationErrors.delete(l);
751
+ }
752
+ recomputeValidationErrors() {
753
+ this.baseValidationErrors.clear(), this.uniqueValidationErrors.clear();
754
+ for (const t of this.rows)
755
+ for (const e of this.schema.columns) {
756
+ const n = this.getCell(t.id, e.key);
757
+ this.updateValidationForCell(t.id, e.key, n);
758
+ }
759
+ for (const t of this.getColumns())
760
+ t.unique && this.recomputeUniqueValidationForColumn(t.key);
761
+ }
762
+ normalizeUniqueValue(t) {
763
+ if (t == null) return null;
764
+ if (typeof t == "string") return t === "" ? null : t;
765
+ if (typeof t == "number" || typeof t == "boolean") return String(t);
766
+ if (t instanceof Date) return String(t.getTime());
767
+ if (typeof t == "object") {
768
+ const e = t, n = e.kind;
769
+ if (n === "enum" && typeof e.value == "string")
770
+ return e.value === "" ? null : e.value;
771
+ if (n === "tags" && Array.isArray(e.values)) {
772
+ const i = e.values.filter((r) => typeof r == "string").join(",");
773
+ return i === "" ? null : i;
774
+ }
775
+ }
776
+ return String(t);
777
+ }
778
+ recomputeUniqueValidationForColumn(t) {
779
+ const e = String(t);
780
+ if (this.schema.columns.find((r) => String(r.key) === e)?.type === "boolean") return;
781
+ for (const r of Array.from(this.uniqueValidationErrors.keys())) {
782
+ const l = r.indexOf("::");
783
+ (l >= 0 ? r.slice(l + 2) : "") === e && this.uniqueValidationErrors.delete(r);
784
+ }
785
+ const i = /* @__PURE__ */ new Map();
786
+ for (const r of this.rows) {
787
+ const l = this.getCell(r.id, t), a = this.normalizeUniqueValue(l);
788
+ if (!a) continue;
789
+ const o = i.get(a) ?? [];
790
+ o.push(r.id), i.set(a, o);
791
+ }
792
+ for (const r of i.values()) {
793
+ if (r.length < 2) continue;
794
+ const l = r.map((o) => this.getDisplayIndex(o)).filter((o) => typeof o == "number" && Number.isFinite(o)).sort((o, c) => o - c), a = l.length ? l.join(", ") : r.join(", ");
795
+ for (const o of r) {
796
+ const c = this.cellStyleKey(o, t);
797
+ this.uniqueValidationErrors.set(c, {
798
+ rowId: o,
799
+ colKey: t,
800
+ message: `Duplicate value
801
+ Rows: ${a}`
802
+ });
803
+ }
804
+ }
805
+ }
806
+ getCellStyle(t, e) {
807
+ return this.cellStyles.get(this.cellStyleKey(t, e)) ?? null;
808
+ }
809
+ setCellStyle(t, e, n) {
810
+ const i = this.cellStyleKey(t, e);
811
+ !n || Object.keys(n).length === 0 ? this.cellStyles.delete(i) : this.cellStyles.set(i, n), this.notify();
812
+ }
813
+ updateColumnStyle(t, e) {
814
+ const n = this.schema.columns.find((r) => String(r.key) === String(t));
815
+ if (!n) return;
816
+ const i = typeof e == "function" ? e(n.style) : e;
817
+ n.style = i, this.notify();
818
+ }
819
+ isEqual(t, e) {
820
+ return t instanceof Date && e instanceof Date ? t.getTime() === e.getTime() : Object.is(t, e);
821
+ }
822
+ getRowVersion(t) {
823
+ return this.rowVersion.get(t) ?? 0;
824
+ }
825
+ reindexRows() {
826
+ let t = 1;
827
+ for (const e of this.rows)
828
+ e.displayIndex = t, t += 1;
829
+ }
830
+ }
831
+ const x = 864e5;
832
+ function V(s) {
833
+ const t = N(s);
834
+ return t ? Number.isNaN(t.getTime()) ? null : t : null;
835
+ }
836
+ function $(s) {
837
+ const t = /* @__PURE__ */ new Date(`1970-01-01T${s}`);
838
+ return Number.isNaN(t.getTime()) ? null : t;
839
+ }
840
+ function G(s, t, e) {
841
+ if (t == null) return null;
842
+ if (typeof t == "object") {
843
+ const n = t;
844
+ if (n.kind === "lookup" && typeof n.value == "string")
845
+ return n.value;
846
+ if (typeof n.label == "string" && "value" in n && e.type === "labeled") {
847
+ const i = n.value;
848
+ return i == null ? null : typeof i == "string" ? i : typeof i == "number" || typeof i == "boolean" ? String(i) : i instanceof Date ? i.toISOString() : String(i);
849
+ }
850
+ }
851
+ if (e.type === "string" || e.type === "labeled") return null;
852
+ if (e.type === "boolean") return String(!!t);
853
+ if ((e.type === "number" || e.type === "int" || e.type === "uint") && typeof t == "number")
854
+ return String(t);
855
+ if (e.type === "datetime") {
856
+ const n = t instanceof Date ? t : V(String(t));
857
+ return n ? String(n.getTime()) : null;
858
+ }
859
+ if (e.type === "date") {
860
+ const n = t instanceof Date ? t : V(String(t));
861
+ if (!n) return null;
862
+ const i = Math.floor(n.getTime() / x) * x;
863
+ return String(i);
864
+ }
865
+ if (e.type === "time") {
866
+ const n = t instanceof Date ? t : $(String(t));
867
+ return n ? String(n.getTime() % x) : null;
868
+ }
869
+ return null;
870
+ }
871
+ const z = 35, Z = 48, J = 35, _ = 80, Y = 6, Q = 8, tt = 4, et = 4;
872
+ function nt(s, t, e = 100) {
873
+ const n = {
874
+ // Reserve extra space for browser UI affordances (e.g. date picker icon) and formatting.
875
+ date: 8
876
+ };
877
+ return s.columns.map((i) => {
878
+ const r = t.columnWidths?.[String(i.key)] ?? i.width ?? e, l = n[i.type] ?? 0;
879
+ return r + l;
880
+ });
881
+ }
882
+ function it(s, t, e = _) {
883
+ const n = Math.max(1, e - t);
884
+ return Math.max(n, s);
885
+ }
886
+ function K(s) {
887
+ const t = s.style, e = t?.decorations;
888
+ return {
889
+ backgroundColor: t?.backgroundColor,
890
+ textColor: t?.textColor,
891
+ bold: e?.bold,
892
+ italic: e?.italic,
893
+ underline: e?.underline,
894
+ strike: e?.strike,
895
+ readonly: t?.readonly,
896
+ disabled: t?.disabled
897
+ };
898
+ }
899
+ function v(s, t) {
900
+ return t ? {
901
+ backgroundColor: t.backgroundColor ?? s.backgroundColor,
902
+ textColor: t.textColor ?? s.textColor,
903
+ bold: t.bold ?? s.bold,
904
+ italic: t.italic ?? s.italic,
905
+ underline: t.underline ?? s.underline,
906
+ strike: t.strike ?? s.strike,
907
+ readonly: t.readonly ?? s.readonly,
908
+ disabled: t.disabled ?? s.disabled
909
+ } : s;
910
+ }
911
+ function st(s, t, e) {
912
+ const n = K(e), i = s.resolveConditionalStyle(t, e).delta ?? {}, r = s.getCellStyle(t, e.key) ?? {}, l = v(v(n, i), r);
913
+ return { columnStyle: n, cellStyle: r, resolved: l };
914
+ }
915
+ function rt(s) {
916
+ let t = "";
917
+ s.backgroundColor && (t += `background-color:${s.backgroundColor};`), s.textColor && (t += `color:${s.textColor};`), s.bold && (t += "font-weight:600;"), s.italic && (t += "font-style:italic;");
918
+ const e = [];
919
+ return s.underline && e.push("underline"), s.strike && e.push("line-through"), e.length && (t += `text-decoration-line:${e.join(" ")};`), t;
920
+ }
921
+ function ot(s) {
922
+ if (typeof s == "string") return { label: s };
923
+ if (!s || typeof s != "object") return null;
924
+ const t = s, e = t.label, n = t.command, i = t.commandfor;
925
+ return typeof e != "string" ? null : typeof n == "string" && typeof i == "string" ? { label: e, command: n, commandfor: i } : null;
926
+ }
927
+ function lt(s) {
928
+ if (typeof s == "string") return s;
929
+ if (!s || typeof s != "object") return "";
930
+ const t = s.label;
931
+ return typeof t == "string" ? t : "";
932
+ }
933
+ function at(s) {
934
+ if (typeof s == "string") return { label: s, href: s };
935
+ if (!s || typeof s != "object") return null;
936
+ const t = s, e = t.label, n = t.href, i = t.target;
937
+ return typeof e != "string" || typeof n != "string" ? null : typeof i == "string" ? { label: e, href: n, target: i } : i === void 0 ? { label: e, href: n } : null;
938
+ }
939
+ function ct(s) {
940
+ if (typeof s == "string") return s;
941
+ if (!s || typeof s != "object") return "";
942
+ const t = s, e = t.label, n = t.href;
943
+ return typeof e == "string" ? e : typeof n == "string" ? n : "";
944
+ }
945
+ function P(s) {
946
+ return s.normalize("NFKC").trim();
947
+ }
948
+ const L = (s) => {
949
+ const t = s.trim(), e = /^([+-]?)(0[bBoOxX])([0-9a-fA-F]+)$/.exec(t);
950
+ if (!e) return null;
951
+ const n = e[1] === "-" ? -1 : 1, i = e[2].toLowerCase(), r = e[3] ?? "";
952
+ let l = 10, a = /^[0-9]+$/;
953
+ if (i === "0b" ? (l = 2, a = /^[01]+$/) : i === "0o" ? (l = 8, a = /^[0-7]+$/) : i === "0x" && (l = 16, a = /^[0-9a-fA-F]+$/), !r || !a.test(r)) return NaN;
954
+ const o = Number.parseInt(r, l);
955
+ return n * o;
956
+ };
957
+ function ut(s) {
958
+ const t = P(s);
959
+ if (t === "") return { ok: !1, reason: "empty" };
960
+ const e = L(t);
961
+ if (e !== null)
962
+ return Number.isFinite(e) ? { ok: !0, value: e } : { ok: !1, reason: "invalid" };
963
+ const n = Number(t);
964
+ return Number.isFinite(n) ? { ok: !0, value: n } : { ok: !1, reason: Number.isNaN(n) ? "invalid" : "non-finite" };
965
+ }
966
+ function ft(s, t) {
967
+ return Number.isFinite(s) ? t === "number" ? { ok: !0, value: s } : Number.isSafeInteger(s) ? t === "uint" && s < 0 ? { ok: !1, reason: "out-of-range" } : { ok: !0, value: s } : { ok: !1, reason: "not-integer" } : { ok: !1, reason: "non-finite" };
968
+ }
969
+ function dt(s, t) {
970
+ const e = s < 0 ? "-" : "", n = Math.abs(s), i = t === "binary" ? n.toString(2) : t === "octal" ? n.toString(8) : n.toString(16);
971
+ return `${e}${t === "binary" ? "0b" : t === "octal" ? "0o" : "0x"}${i}`;
972
+ }
973
+ function ht(s, t) {
974
+ if (!Number.isFinite(s)) return "";
975
+ if ((t?.format ?? "decimal") === "scientific") {
976
+ const i = t?.precision;
977
+ return i !== void 0 && Number.isFinite(i) && i > 0 ? s.toExponential(Math.max(0, Math.floor(i) - 1)) : s.toExponential();
978
+ }
979
+ const n = t?.scale;
980
+ if (n !== void 0 && Number.isFinite(n)) {
981
+ const i = Math.max(0, Math.floor(n));
982
+ return s.toFixed(i);
983
+ }
984
+ return String(s);
985
+ }
986
+ export {
987
+ tt as C,
988
+ J as D,
989
+ z as H,
990
+ Z as R,
991
+ ot as a,
992
+ at as b,
993
+ K as c,
994
+ lt as d,
995
+ ct as e,
996
+ et as f,
997
+ nt as g,
998
+ ht as h,
999
+ dt as i,
1000
+ k as j,
1001
+ W as k,
1002
+ Q as l,
1003
+ v as m,
1004
+ Y as n,
1005
+ ut as o,
1006
+ N as p,
1007
+ ft as q,
1008
+ U as r,
1009
+ rt as s,
1010
+ G as t,
1011
+ P as u,
1012
+ it as v,
1013
+ X as w,
1014
+ q as x,
1015
+ st as y
1016
+ };
1017
+ //# sourceMappingURL=numberIO-CGTV3-KW.js.map