@extable/core 0.3.7 → 0.3.8

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