@uiresponse/renderer-react 0.1.0

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,2213 @@
1
+ import { jsxs as m, jsx as s, Fragment as Me } from "react/jsx-runtime";
2
+ import ln, { createContext as cn, useContext as un, useReducer as dn, useMemo as E, useRef as C, useCallback as P, useEffect as j, useId as Pt, useState as V, useLayoutEffect as hn } from "react";
3
+ import { MiniLineChart as mn, AreaChart as fn, LineChart as pn, BarChart as gn } from "@openuidev/react-ui";
4
+ const Xe = cn(null);
5
+ function W() {
6
+ const e = un(Xe);
7
+ if (!e) throw new Error("OBL blocks must render inside <UIResponsePage>.");
8
+ return e;
9
+ }
10
+ function Y(e, t, n) {
11
+ return { dataset: e.dataset, params: e.params, now: e.now, row: t };
12
+ }
13
+ const X = (e) => e !== null && typeof e == "object" && !Array.isArray(e) && "$bind" in e, It = (e) => e !== null && typeof e == "object" && typeof e.$param == "string", yn = (e) => e !== null && typeof e == "object" && e.$now !== null && typeof e.$now == "object", Ot = (e) => e !== null && typeof e == "object" && e.$self === !0, U = (e) => e != null;
14
+ class ge extends Error {
15
+ }
16
+ function _n(e) {
17
+ return e.field ? e.aggregate || e.row || e.scope === "row" ? "scalar" : "column" : e.aggregate ? "scalar" : "rows";
18
+ }
19
+ function wn(e, t) {
20
+ const n = new Date(e);
21
+ switch (t) {
22
+ case "year":
23
+ n.setMonth(0, 1), n.setHours(0, 0, 0, 0);
24
+ break;
25
+ case "quarter":
26
+ n.setMonth(Math.floor(n.getMonth() / 3) * 3, 1), n.setHours(0, 0, 0, 0);
27
+ break;
28
+ case "month":
29
+ n.setDate(1), n.setHours(0, 0, 0, 0);
30
+ break;
31
+ case "week": {
32
+ const r = (n.getDay() + 6) % 7;
33
+ n.setDate(n.getDate() - r), n.setHours(0, 0, 0, 0);
34
+ break;
35
+ }
36
+ case "day":
37
+ n.setHours(0, 0, 0, 0);
38
+ break;
39
+ }
40
+ return n;
41
+ }
42
+ function bn(e, t) {
43
+ const n = e.$now ?? {};
44
+ let r = new Date(t);
45
+ return n.offset_days && r.setDate(r.getDate() + n.offset_days), n.offset_months && r.setMonth(r.getMonth() + n.offset_months), n.offset_years && r.setFullYear(r.getFullYear() + n.offset_years), n.truncate && (r = wn(r, n.truncate)), r;
46
+ }
47
+ const vn = (e) => e.filter((t) => t != null && t !== "" && Number.isFinite(Number(t))).map(Number);
48
+ function Nn(e) {
49
+ if (!e.length) return null;
50
+ const t = [...e].sort((r, i) => r - i), n = t.length >> 1;
51
+ return t.length % 2 ? t[n] : (t[n - 1] + t[n]) / 2;
52
+ }
53
+ function kn(e, t, n) {
54
+ if (n === "count") return t ? e.filter((i) => U(i[t])).length : e.length;
55
+ if (n === "count_distinct") return new Set(e.map((i) => i[t]).filter(U)).size;
56
+ const r = vn(e.map((i) => i[t]));
57
+ if (!r.length) return null;
58
+ switch (n) {
59
+ case "sum":
60
+ return r.reduce((i, a) => i + a, 0);
61
+ case "avg":
62
+ return r.reduce((i, a) => i + a, 0) / r.length;
63
+ case "min":
64
+ return Math.min(...r);
65
+ case "max":
66
+ return Math.max(...r);
67
+ case "median":
68
+ return Nn(r);
69
+ default:
70
+ throw new ge(`unknown aggregate "${n}"`);
71
+ }
72
+ }
73
+ function $n(e, t, n) {
74
+ if (t === "only") {
75
+ if (e.length !== 1)
76
+ throw new ge(
77
+ `\`row: "only"\` on \`${n.dataset}.${n.field}\` requires exactly one row; the dataset resolved ${e.length}.`
78
+ );
79
+ return e[0];
80
+ }
81
+ return e.length ? t === "last" ? e[e.length - 1] : e[0] : null;
82
+ }
83
+ function fe(e, t) {
84
+ var r;
85
+ if (!(e != null && e.field)) return null;
86
+ const n = t.dataset(e.dataset);
87
+ return ((r = n == null ? void 0 : n.columns) == null ? void 0 : r.find((i) => i.name === e.field)) ?? null;
88
+ }
89
+ function Ve(e, t) {
90
+ const n = t.dataset(e.dataset);
91
+ if (!n) throw new ge(`dataset "${e.dataset}" has not resolved`);
92
+ const r = n.rows ?? [];
93
+ switch (_n(e)) {
94
+ case "rows":
95
+ return r;
96
+ case "column":
97
+ return r.map((i) => i[e.field]);
98
+ case "scalar": {
99
+ if (e.scope === "row") {
100
+ if (!t.row) throw new ge('`scope: "row"` used outside a repeating element');
101
+ return t.row[e.field] ?? null;
102
+ }
103
+ if (e.aggregate) return kn(r, e.field, e.aggregate);
104
+ const i = $n(r, e.row, e);
105
+ return i ? i[e.field] ?? null : null;
106
+ }
107
+ default:
108
+ throw new ge("unresolvable binding arity");
109
+ }
110
+ }
111
+ function H(e, t) {
112
+ var n;
113
+ if (X(e)) return Ve(e.$bind, t);
114
+ if (It(e)) return ((n = t.params) == null ? void 0 : n[e.$param]) ?? null;
115
+ if (yn(e)) return bn(e, t.now);
116
+ if (Ot(e)) {
117
+ if (t.self === void 0) throw new ge('`{"$self": true}` used outside an input\'s `on_change`');
118
+ return t.self;
119
+ }
120
+ return e;
121
+ }
122
+ function ue(e, t = /* @__PURE__ */ new Set()) {
123
+ if (e === null || typeof e != "object") return t;
124
+ if (Array.isArray(e))
125
+ return e.forEach((n) => ue(n, t)), t;
126
+ if (X(e))
127
+ return e.$bind.dataset && t.add(e.$bind.dataset), t;
128
+ for (const n of Object.values(e)) ue(n, t);
129
+ return t;
130
+ }
131
+ function Ke(e, t = /* @__PURE__ */ new Set()) {
132
+ if (e === null || typeof e != "object") return t;
133
+ if (Array.isArray(e))
134
+ return e.forEach((n) => Ke(n, t)), t;
135
+ if (It(e))
136
+ return t.add(e.$param), t;
137
+ for (const n of Object.values(e)) Ke(n, t);
138
+ return t;
139
+ }
140
+ const xn = { primary: 0, supporting: 1, ambient: 2 }, An = (e) => {
141
+ var t;
142
+ return xn[(t = e == null ? void 0 : e.intent) == null ? void 0 : t.priority] ?? 1;
143
+ }, Lt = 2e4;
144
+ function Fn(e) {
145
+ const t = [], n = (r, i, a) => {
146
+ t.push({ block: r, depth: i, parent: a });
147
+ for (const o of r.children ?? []) n(o, i + 1, r);
148
+ };
149
+ for (const r of e.blocks ?? []) n(r, 0, null);
150
+ return t;
151
+ }
152
+ function Sn(e) {
153
+ const t = Fn(e), n = /* @__PURE__ */ new Map();
154
+ t.forEach(({ block: i }, a) => {
155
+ for (const o of ue(i))
156
+ n.has(o) || n.set(o, { index: a, rank: An(i) });
157
+ });
158
+ const r = (e.data ?? []).map((i) => i.name);
159
+ return r.filter((i) => n.has(i)).sort((i, a) => {
160
+ const o = n.get(i), l = n.get(a);
161
+ return o.index - l.index || o.rank - l.rank || r.indexOf(i) - r.indexOf(a);
162
+ });
163
+ }
164
+ function Cn(e) {
165
+ const t = /* @__PURE__ */ new Map();
166
+ for (const n of e.data ?? []) t.set(n.name, Ke(n.query ?? {}));
167
+ return t;
168
+ }
169
+ function Dn(e, t = {}) {
170
+ const n = {};
171
+ for (const r of e.params ?? [])
172
+ n[r.name] = Object.prototype.hasOwnProperty.call(t, r.name) ? t[r.name] : "default" in r ? r.default : null;
173
+ return { ...n, ...t };
174
+ }
175
+ function Mn(e, t) {
176
+ switch (t.type) {
177
+ case "sync": {
178
+ const n = {};
179
+ for (const r of t.datasets)
180
+ n[r.name] = e.datasets[r.name] ?? {
181
+ status: "idle",
182
+ rows: [],
183
+ columns: r.columns ?? [],
184
+ error: null,
185
+ stale: !1
186
+ };
187
+ return { ...e, datasets: n };
188
+ }
189
+ case "loading":
190
+ return { ...e, datasets: { ...e.datasets, [t.name]: { ...e.datasets[t.name], status: "loading" } } };
191
+ case "ready":
192
+ return { ...e, datasets: { ...e.datasets, [t.name]: { status: "ready", rows: t.rows, columns: t.columns, error: null } } };
193
+ case "error":
194
+ return { ...e, datasets: { ...e.datasets, [t.name]: { status: "error", rows: [], columns: t.columns ?? [], error: t.error } } };
195
+ case "invalidate": {
196
+ const n = { ...e.datasets };
197
+ for (const r of t.names) n[r] = { ...n[r], status: "idle", stale: !0 };
198
+ return { ...e, datasets: n, epoch: e.epoch + 1 };
199
+ }
200
+ case "params":
201
+ return { ...e, params: { ...e.params, ...t.params } };
202
+ default:
203
+ return e;
204
+ }
205
+ }
206
+ function Bn(e, t, { timeoutMs: n = Lt } = {}) {
207
+ const r = new AbortController();
208
+ let i = !1, a, o;
209
+ return {
210
+ promise: new Promise((d, c) => {
211
+ o = c;
212
+ const u = (h, f) => {
213
+ i || (i = !0, clearTimeout(a), h(f));
214
+ };
215
+ a = setTimeout(() => {
216
+ const h = new Error(`Dataset "${t.dataset}" timed out after ${Math.ceil(n / 1e3)}s.`);
217
+ r.abort(h), u(c, h);
218
+ }, n), Promise.resolve().then(() => e({ ...t, signal: r.signal })).then((h) => u(d, h), (h) => u(c, h));
219
+ }),
220
+ signal: r.signal,
221
+ abort(d = `Dataset "${t.dataset}" was cancelled.`) {
222
+ if (i) return;
223
+ const c = new Error(d);
224
+ r.abort(c), i = !0, clearTimeout(a), o(c);
225
+ }
226
+ };
227
+ }
228
+ function En(e, t) {
229
+ const n = {};
230
+ for (const r of e.data ?? []) n[r.name] = { status: "idle", rows: [], columns: r.columns ?? [], error: null, stale: !1 };
231
+ return { datasets: n, params: Dn(e, t), epoch: 0 };
232
+ }
233
+ function Tn(e, t, { params: n, concurrency: r = 2, timeoutMs: i = Lt } = {}) {
234
+ const [a, o] = dn(Mn, void 0, () => En(e, n)), l = E(() => Sn(e), [e]), d = E(() => Cn(e), [e]), c = C(/* @__PURE__ */ new Set()), u = C(/* @__PURE__ */ new Map()), h = C(0), f = C(!1), k = C(/* @__PURE__ */ new Map()), p = C(a);
235
+ p.current = a;
236
+ const y = P(
237
+ (N) => {
238
+ var b;
239
+ return ((b = (e.data ?? []).find(($) => $.name === N)) == null ? void 0 : b.columns) ?? [];
240
+ },
241
+ [e]
242
+ );
243
+ j(() => (f.current = !1, () => {
244
+ f.current = !0;
245
+ for (const N of u.current.values()) N.abort();
246
+ u.current.clear(), c.current.clear();
247
+ }), []);
248
+ const v = (e.data ?? []).map((N) => N.name).join("");
249
+ j(() => {
250
+ const N = new Set((e.data ?? []).map((b) => b.name));
251
+ for (const [b, $] of u.current)
252
+ N.has(b) || $.abort();
253
+ o({ type: "sync", datasets: e.data ?? [] });
254
+ }, [v]);
255
+ const S = P(() => {
256
+ var N;
257
+ for (const b of l) {
258
+ if (f.current || c.current.size >= r) return;
259
+ if (c.current.has(b) || k.current.get(b) === h.current || ((N = p.current.datasets[b]) == null ? void 0 : N.status) !== "idle") continue;
260
+ const $ = h.current;
261
+ c.current.add(b), o({ type: "loading", name: b });
262
+ const B = Bn(
263
+ t,
264
+ { page: e.id, dataset: b, params: p.current.params, pageDoc: e },
265
+ { timeoutMs: i }
266
+ );
267
+ u.current.set(b, B), B.promise.then((x) => {
268
+ var te;
269
+ f.current || h.current !== $ || (k.current.set(b, $), o({ type: "ready", name: b, rows: (x == null ? void 0 : x.rows) ?? [], columns: (te = x == null ? void 0 : x.columns) != null && te.length ? x.columns : y(b) }));
270
+ }).catch((x) => {
271
+ f.current || h.current !== $ || (k.current.set(b, $), o({ type: "error", name: b, error: (x == null ? void 0 : x.message) ?? String(x), columns: y(b) }));
272
+ }).finally(() => {
273
+ u.current.get(b) === B && u.current.delete(b), c.current.delete(b), f.current || queueMicrotask(() => w.current());
274
+ });
275
+ }
276
+ }, [e, t, l, r, y, i]), w = C(S);
277
+ w.current = S, j(() => {
278
+ S();
279
+ });
280
+ const M = P((N, b) => {
281
+ var B;
282
+ h.current += 1, o({ type: "params", params: { [N]: b } });
283
+ const $ = [...d.entries()].filter(([, x]) => x.has(N)).map(([x]) => x);
284
+ if ($.length) {
285
+ for (const x of $) (B = u.current.get(x)) == null || B.abort();
286
+ o({ type: "invalidate", names: $ });
287
+ }
288
+ }, [d]), I = P((N) => {
289
+ var B;
290
+ h.current += 1;
291
+ const b = (e.data ?? []).map((x) => x.name), $ = N === "all" || !N ? b : N;
292
+ for (const x of $) (B = u.current.get(x)) == null || B.abort();
293
+ o({ type: "invalidate", names: $ });
294
+ }, [e]), K = P((N) => a.datasets[N], [a.datasets]), Q = P(
295
+ (N) => [...ue(N)].every((b) => {
296
+ var $;
297
+ return (($ = a.datasets[b]) == null ? void 0 : $.status) === "ready";
298
+ }),
299
+ [a.datasets]
300
+ ), ee = P(
301
+ (N) => {
302
+ var b;
303
+ return ((b = [...ue(N)].map(($) => a.datasets[$]).find(($) => ($ == null ? void 0 : $.status) === "error")) == null ? void 0 : b.error) ?? null;
304
+ },
305
+ [a.datasets]
306
+ ), we = P(
307
+ (N) => [...ue(N)].some((b) => {
308
+ var $, B;
309
+ return (($ = a.datasets[b]) == null ? void 0 : $.stale) && ((B = a.datasets[b]) == null ? void 0 : B.status) !== "ready";
310
+ }),
311
+ [a.datasets]
312
+ );
313
+ return { datasets: a.datasets, params: a.params, dataset: K, setParam: M, refresh: I, blockReady: Q, blockError: ee, blockStale: we, order: l };
314
+ }
315
+ const Rn = ({ needsData: e, error: t, dataReady: n, held: r }) => !e || !!t || n && !r, Pn = (e, t) => ({ ...e, ...t }), Nt = (e) => Array.isArray(e) ? e : [e];
316
+ function Se(e, t) {
317
+ if (typeof e == "number" && typeof t == "number") return e - t;
318
+ const n = Date.parse(e), r = Date.parse(t);
319
+ if (!Number.isNaN(n) && !Number.isNaN(r)) return n - r;
320
+ const i = Number(e), a = Number(t);
321
+ return Number.isFinite(i) && Number.isFinite(a) ? i - a : String(e) < String(t) ? -1 : String(e) > String(t) ? 1 : 0;
322
+ }
323
+ const Fe = (e, t) => e === t ? !0 : Se(e, t) === 0 && typeof e == typeof t;
324
+ function In(e, t) {
325
+ const n = H(e.left, t);
326
+ switch (e.op) {
327
+ // Unary operators take no `right` — the schema enforces that, so we never read one.
328
+ case "is_empty":
329
+ return !U(n) || n === "" || Array.isArray(n) && n.length === 0;
330
+ case "is_not_empty":
331
+ return U(n) && n !== "" && !(Array.isArray(n) && n.length === 0);
332
+ case "is_true":
333
+ return n === !0;
334
+ case "is_false":
335
+ return n === !1;
336
+ }
337
+ const r = H(e.right, t);
338
+ switch (e.op) {
339
+ case "eq":
340
+ return Fe(n, r);
341
+ case "neq":
342
+ return !Fe(n, r);
343
+ // A comparison against absent data is FALSE, never a coerced 0. `null > 0` must not be true.
344
+ case "gt":
345
+ return U(n) && U(r) && Se(n, r) > 0;
346
+ case "gte":
347
+ return U(n) && U(r) && Se(n, r) >= 0;
348
+ case "lt":
349
+ return U(n) && U(r) && Se(n, r) < 0;
350
+ case "lte":
351
+ return U(n) && U(r) && Se(n, r) <= 0;
352
+ case "in":
353
+ return Nt(r).some((i) => Fe(n, i));
354
+ case "not_in":
355
+ return !Nt(r).some((i) => Fe(n, i));
356
+ case "contains":
357
+ return Array.isArray(n) ? n.some((i) => Fe(i, r)) : U(n) && String(n).toLowerCase().includes(String(r).toLowerCase());
358
+ default:
359
+ throw new ge(`unknown condition operator "${e.op}"`);
360
+ }
361
+ }
362
+ function Ce(e, t) {
363
+ return !e || typeof e != "object" ? !0 : Array.isArray(e.all) ? e.all.every((n) => Ce(n, t)) : Array.isArray(e.any) ? e.any.some((n) => Ce(n, t)) : e.not ? !Ce(e.not, t) : In(e, t);
364
+ }
365
+ function On(e, t, n) {
366
+ if (!e.visible_when) return "visible";
367
+ if (!n) return "pending";
368
+ try {
369
+ return Ce(e.visible_when, t) ? "visible" : "hidden";
370
+ } catch {
371
+ return "visible";
372
+ }
373
+ }
374
+ const Ln = [
375
+ { at: 1e12, suffix: "T" },
376
+ { at: 1e9, suffix: "B" },
377
+ { at: 1e6, suffix: "M" },
378
+ { at: 1e3, suffix: "K" }
379
+ ];
380
+ function Oe(e, { compact: t, as: n }) {
381
+ const r = Math.abs(e);
382
+ return t ? r >= 1e3 && r < 1e6 ? 0 : 1 : n === "currency" ? r >= 1e3 ? 0 : 2 : n === "percent" ? r < 10 ? 1 : 0 : Number.isInteger(e) ? 0 : r < 1 ? 2 : r < 100 ? 1 : 0;
383
+ }
384
+ function Le(e, t, n) {
385
+ return n === "never" ? e.replace(/^-/, "") : n === "always" && t > 0 ? `+${e}` : e;
386
+ }
387
+ function kt(e) {
388
+ return e.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
389
+ }
390
+ function pe(e, t) {
391
+ const n = Math.abs(e).toFixed(t), [r, i] = n.split("."), a = i ? `${kt(r)}.${i}` : kt(r);
392
+ return e < 0 ? `-${a}` : a;
393
+ }
394
+ function ze(e, t) {
395
+ const n = Math.abs(e);
396
+ for (const { at: r, suffix: i } of Ln)
397
+ if (n >= r) {
398
+ const a = e / r, o = t ?? (Math.abs(a) >= 100 ? 0 : 1);
399
+ return `${a.toFixed(o).replace(/\.0$/, "")}${i}`;
400
+ }
401
+ return pe(e, t ?? 0);
402
+ }
403
+ const Un = { GBP: "£", USD: "$", EUR: "€", JPY: "¥", AUD: "A$", CAD: "C$", CHF: "CHF ", SEK: "kr " }, Vn = (e) => Un[e] ?? `${e} `, jn = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
404
+ function Ut(e) {
405
+ if (e instanceof Date) return e;
406
+ if (typeof e == "number") return new Date(e);
407
+ if (typeof e != "string") return null;
408
+ const t = /^\d{4}-\d{2}-\d{2}$/.test(e), n = new Date(t ? `${e}T12:00:00` : e);
409
+ return Number.isNaN(n.getTime()) ? null : n;
410
+ }
411
+ function Hn(e, t) {
412
+ const n = Ut(e);
413
+ if (!n) return String(e);
414
+ const r = n.getDate(), i = jn[n.getMonth()], a = n.getFullYear();
415
+ switch (t) {
416
+ case "iso":
417
+ return n.toISOString().slice(0, 10);
418
+ case "year":
419
+ return String(a);
420
+ case "quarter":
421
+ return `Q${Math.floor(n.getMonth() / 3) + 1} ${a}`;
422
+ case "month":
423
+ return `${i} ${a}`;
424
+ case "full":
425
+ return `${r} ${i} ${a}`;
426
+ case "day":
427
+ default:
428
+ return `${r} ${i}`;
429
+ }
430
+ }
431
+ const ve = 60, Ne = 3600, ce = 86400;
432
+ function zn(e, t) {
433
+ const n = Ut(e);
434
+ if (!n) return String(e);
435
+ const r = Math.round((n.getTime() - t.getTime()) / 1e3), i = r < 0, a = Math.abs(r), o = (d, c) => `${d} ${c}${d === 1 ? "" : "s"}`;
436
+ let l;
437
+ return a < 45 ? "just now" : (a < 45 * ve ? l = o(Math.round(a / ve), "minute") : a < 22 * Ne ? l = o(Math.round(a / Ne), "hour") : a < 26 * ce ? l = o(Math.round(a / ce), "day") : a < 320 * ce ? l = o(Math.round(a / (30 * ce)), "month") : l = o(Math.round(a / (365 * ce)), "year"), i ? `${l} ago` : `in ${l}`);
438
+ }
439
+ function Yn(e, t) {
440
+ const n = Number(e);
441
+ if (!Number.isFinite(n)) return String(e);
442
+ const r = Math.abs(n);
443
+ if (r < ve) return `${pe(n, t ?? 0)}s`;
444
+ if (r < Ne) {
445
+ const o = Math.floor(r / ve), l = Math.round(r % ve);
446
+ return l ? `${o}m ${l}s` : `${o}m`;
447
+ }
448
+ if (r < ce) {
449
+ const o = Math.floor(r / Ne), l = Math.round(r % Ne / ve);
450
+ return l ? `${o}h ${l}m` : `${o}h`;
451
+ }
452
+ const i = Math.floor(r / ce), a = Math.round(r % ce / Ne);
453
+ return a ? `${i}d ${a}h` : `${i}d`;
454
+ }
455
+ const $t = ["B", "KB", "MB", "GB", "TB", "PB"];
456
+ function Kn(e, t) {
457
+ let n = Number(e);
458
+ if (!Number.isFinite(n)) return String(e);
459
+ let r = 0;
460
+ for (; Math.abs(n) >= 1024 && r < $t.length - 1; )
461
+ n /= 1024, r++;
462
+ return `${pe(n, t ?? (r === 0 ? 0 : 1))} ${$t[r]}`;
463
+ }
464
+ function q(e, t, n = {}) {
465
+ const r = n.now ?? /* @__PURE__ */ new Date(), i = n.column;
466
+ if (e == null) return "";
467
+ const a = (t == null ? void 0 : t.as) ?? ((i == null ? void 0 : i.type) === "currency" ? "currency" : (i == null ? void 0 : i.type) === "date" ? "date" : void 0), o = (t == null ? void 0 : t.currency) ?? (i == null ? void 0 : i.currency), l = t == null ? void 0 : t.precision, d = (t == null ? void 0 : t.compact) ?? !1, c = (t == null ? void 0 : t.sign) ?? "auto";
468
+ switch (a) {
469
+ case "currency": {
470
+ const u = Number(e);
471
+ if (!Number.isFinite(u)) return String(e);
472
+ const h = l ?? Oe(u, { compact: d, as: a }), f = d ? ze(u, l) : pe(u, h), k = f.startsWith("-"), p = k ? f.slice(1) : f, y = `${k ? "-" : ""}${Vn(o ?? "")}${p}`;
473
+ return Le(y, u, c);
474
+ }
475
+ case "percent": {
476
+ const u = Number(e);
477
+ if (!Number.isFinite(u)) return String(e);
478
+ const h = l ?? Oe(u, { compact: d, as: a });
479
+ return Le(`${pe(u, h)}%`, u, c);
480
+ }
481
+ case "number": {
482
+ const u = Number(e);
483
+ if (!Number.isFinite(u)) return String(e);
484
+ const h = l ?? Oe(u, { compact: d, as: a });
485
+ return Le(d ? ze(u, l) : pe(u, h), u, c);
486
+ }
487
+ case "date":
488
+ return Hn(e, (t == null ? void 0 : t.date_style) ?? ((i == null ? void 0 : i.precision) === "time" ? "full" : "day"));
489
+ case "relative_time":
490
+ return zn(e, r);
491
+ case "duration":
492
+ return Yn(e, l);
493
+ case "bytes":
494
+ return Kn(e, l);
495
+ case "text":
496
+ return String(e);
497
+ default:
498
+ return typeof e == "boolean" ? e ? "Yes" : "No" : typeof e == "number" ? Le(d ? ze(e, l) : pe(e, l ?? Oe(e, { compact: d })), e, c) : String(e);
499
+ }
500
+ }
501
+ function qn(e, t) {
502
+ const n = (e == null ? void 0 : e.as) ?? ((t == null ? void 0 : t.type) === "currency" ? "currency" : void 0);
503
+ return n === "number" || n === "currency" || n === "percent" || n === "bytes" || n === "duration" || !n && ((t == null ? void 0 : t.type) === "number" || (t == null ? void 0 : t.type) === "currency");
504
+ }
505
+ function Vt(e) {
506
+ return { show: (e == null ? void 0 : e.show) ?? "dash", text: e == null ? void 0 : e.text };
507
+ }
508
+ function ke(e) {
509
+ return !!(e == null || typeof e == "number" && Number.isNaN(e));
510
+ }
511
+ const Wn = (e) => Vt(e).show === "hide";
512
+ function Gn(e) {
513
+ const { show: t, text: n } = Vt(e);
514
+ return t === "text" ? { kind: "text", text: n ?? "" } : { kind: t };
515
+ }
516
+ const Jn = [
517
+ [/^(live|released|complete|completed|done|signed|approved|delivered|paid|cleared)$/i, "positive"],
518
+ [/^(overdue|blocked|rejected|cancelled|canceled|failed|void|at risk)$/i, "negative"],
519
+ [/^(pending|waiting|in progress|in review|draft|scheduled|chasing|on hold)$/i, "warning"]
520
+ ];
521
+ function Zn(e) {
522
+ const t = String(e ?? "").trim();
523
+ for (const [n, r] of Jn) if (n.test(t)) return r;
524
+ return "neutral";
525
+ }
526
+ const jt = (e) => typeof e == "string" && /^https?:\/\//i.test(e), xt = (e) => jt(e) || typeof e == "string" && /^data:image\//i.test(e), At = (e) => e == null || e === "";
527
+ function Xn(e) {
528
+ try {
529
+ const t = new URL(e), n = `${t.pathname}${t.search}`.replace(/\/$/, "");
530
+ return `${t.host.replace(/^www\./, "")}${n}`;
531
+ } catch {
532
+ return e;
533
+ }
534
+ }
535
+ const qe = (e) => (e ?? []).find((t) => (t == null ? void 0 : t.role) === "image") ?? null, Qn = 4, er = (e) => e >= Qn ? "rail" : "grid", Ht = (e) => {
536
+ var t, n;
537
+ return !!(e != null && e.title) && ((n = (t = e == null ? void 0 : e.children) == null ? void 0 : t[0]) == null ? void 0 : n.type) === "text";
538
+ }, tr = (e) => {
539
+ var n;
540
+ const t = (e == null ? void 0 : e.blocks) ?? [];
541
+ return t.length === 1 && ((n = t[0]) == null ? void 0 : n.type) === "section" && Ht(t[0]);
542
+ }, zt = "_thumb_url", Yt = (e) => typeof e == "string" ? `${e.replace(/_url$/, "")}${zt}` : null, nr = (e) => typeof e == "string" && e.endsWith(zt), Kt = (e, t) => {
543
+ if (!t) return null;
544
+ const n = Yt(t.name);
545
+ return (e ?? []).find((r) => (r == null ? void 0 : r.name) === n) ?? null;
546
+ }, rr = (e) => (e ?? []).filter((t) => !nr(t == null ? void 0 : t.name)).map((t) => ({ field: t.name })), ar = 12, ir = (e) => Math.min(e, ar);
547
+ function sr(e, t) {
548
+ const n = e.find(({ col: o }) => (o == null ? void 0 : o.role) === "name" && !At(t[o.name])) ?? null, r = n ? e.filter(({ col: o }) => (o == null ? void 0 : o.role) === "status" && !At(t[o.name])) : [], i = new Set([n, ...r].filter(Boolean).map(({ spec: o }) => o.field)), a = e.filter(({ spec: o }) => !i.has(o.field));
549
+ return { head: n, badges: r, facts: a };
550
+ }
551
+ const ka = { hero: 0, primary: 1, normal: 2, subtle: 3 }, le = {
552
+ fold: "0.45s cubic-bezier(0.2, 0.7, 0.3, 1)",
553
+ shimmer: "1.4s linear infinite",
554
+ tick: "2.6s ease forwards",
555
+ // Sheet `2a · Chat to page prototype`. Extracted from its inline styles, not chosen.
556
+ slideIn: "0.32s cubic-bezier(0.2, 0.7, 0.3, 1)",
557
+ fade: "0.25s ease",
558
+ dot: "1.2s ease infinite",
559
+ barIn: "0.9s cubic-bezier(0.2, 0.7, 0.3, 1)",
560
+ // No count-up in the design. See `countUp` below and NOTES-designsync D7.
561
+ countUp: "0.62s cubic-bezier(0.2, 0.7, 0.3, 1)"
562
+ }, Ye = {
563
+ width: "372px",
564
+ scrim: "rgba(9, 9, 11, 0.18)",
565
+ shadow: "-16px 0 40px rgba(0, 0, 0, 0.1)"
566
+ }, T = {
567
+ name: "OBL element system",
568
+ scheme: "light",
569
+ // Sheet light (`data-screen-label="Sheet light"`). Zinc neutrals.
570
+ color: {
571
+ ground: "#FFFFFF",
572
+ sheet: "#FFFFFF",
573
+ sunk: "#F4F4F5",
574
+ // segmented control track, row hover
575
+ sunkStrong: "#FAFAFA",
576
+ // shimmer highlight, button hover
577
+ ink: "#18181B",
578
+ muted: "#52525B",
579
+ // subtle metric value, legend labels
580
+ graphite: "#71717A",
581
+ // tile labels
582
+ faint: "#A1A1AA",
583
+ // column headers, captions, units
584
+ rule: "#E4E4E7",
585
+ // tile border
586
+ ruleSoft: "#F0F0F2",
587
+ // separators INSIDE a tile — lighter than its own border
588
+ ruleStrong: "#D4D4D8",
589
+ // The one accent. `#3B6FE6` is the design's default; its tweak offered teal and violet too.
590
+ brand: "#3B6FE6",
591
+ brandHover: "#2D5AC4",
592
+ brandSoft: "#EFF6FF",
593
+ // Status tones, from the design's `tones` map.
594
+ positive: "#177A3D",
595
+ positiveSoft: "#ECFDF3",
596
+ warning: "#B54708",
597
+ warningSoft: "#FFFAEB",
598
+ negative: "#B42318",
599
+ negativeSoft: "#FEF3F2",
600
+ info: "#175CD3",
601
+ infoSoft: "#EFF6FF",
602
+ neutral: "#52525B",
603
+ neutralSoft: "#F4F4F5",
604
+ /** The validation tick's check. Deliberately not `positive`: it is a mark, not a status. */
605
+ tick: "#16A34A",
606
+ focus: "#3B6FE6"
607
+ },
608
+ /** Only our own donut reads this. Their charts are handed no palette and keep their own. */
609
+ chart: ["#3B6FE6", "#A1A1AA", "#1F9E86", "#7A5AF0", "#B54708", "#B42318", "#175CD3", "#52525B"],
610
+ /** Sheet `02 · Chart`: one accent slice, then four desaturating neutrals. */
611
+ pie: ["#3B6FE6", "#A7BFF2", "#C9CDD4", "#A1A1AA", "#E4E4E7"],
612
+ font: {
613
+ body: '-apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif',
614
+ mono: "ui-monospace, Menlo, SFMono-Regular, Consolas, monospace",
615
+ display: '-apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif'
616
+ },
617
+ /**
618
+ * The metric ladder, read off the four tiles in `01 · Metric`:
619
+ * hero 44 / 600 / -0.02em primary 30 / 600 / -0.015em
620
+ * normal 22 / 600 subtle 17 / 500, in `muted`
621
+ * Emphasis is type scale and tile size. Never colour, never rule weight.
622
+ */
623
+ size: {
624
+ stamp: "0.625rem",
625
+ // 10px — the mono captions under each sheet tile
626
+ micro: "0.6875rem",
627
+ // 11px
628
+ small: "0.75rem",
629
+ // 12px — column headers, legend
630
+ label: "0.8125rem",
631
+ // 13px — a tile's label
632
+ base: "0.8125rem",
633
+ // 13px
634
+ large: "0.9375rem",
635
+ // 15px — a tile's title
636
+ heroValue: "2.75rem",
637
+ // 44px
638
+ primaryValue: "1.875rem",
639
+ // 30px
640
+ normalValue: "1.375rem",
641
+ // 22px
642
+ subtleValue: "1.0625rem",
643
+ // 17px
644
+ unit: "0.875rem"
645
+ // 14px
646
+ },
647
+ space: { xs: "4px", sm: "8px", md: "12px", lg: "16px", xl: "24px", xxl: "36px" },
648
+ /** Tile 12, inner element 8, control 6. */
649
+ radius: { sm: "6px", md: "8px", lg: "12px" },
650
+ /** Tile padding is asymmetric in the design: 18px vertical, 20px horizontal. */
651
+ tilePad: { y: "18px", x: "20px" },
652
+ shadow: "0 1px 2px rgba(0, 0, 0, 0.04)",
653
+ /** `rowPadY` in the design's table: 12 comfortable, 6 compact. */
654
+ density: { comfortable: "12px", compact: "6px" },
655
+ /** The skeleton's shimmer sweep. */
656
+ shimmer: { from: "#F0F0F2", to: "#FAFAFA" },
657
+ measure: "1260px"
658
+ // the sheets are drawn at 1260px
659
+ }, qt = {
660
+ name: "OBL element system — dark",
661
+ scheme: "dark",
662
+ color: {
663
+ ground: "#0E0E10",
664
+ sheet: "#17171A",
665
+ sunk: "#232327",
666
+ sunkStrong: "#2A2A2F",
667
+ ink: "#F4F4F5",
668
+ muted: "#D4D4D8",
669
+ graphite: "#A1A1AA",
670
+ faint: "#6E6E78",
671
+ rule: "#2A2A2F",
672
+ ruleSoft: "#222227",
673
+ ruleStrong: "#34343B",
674
+ brand: "#6F95F2",
675
+ // the design's `accentDark` map for #3B6FE6
676
+ brandHover: "#8FAEF6",
677
+ brandSoft: "rgba(96, 165, 250, 0.14)",
678
+ positive: "#4ADE80",
679
+ positiveSoft: "rgba(74, 222, 128, 0.13)",
680
+ warning: "#FBBF24",
681
+ warningSoft: "rgba(251, 191, 36, 0.13)",
682
+ negative: "#F87171",
683
+ negativeSoft: "rgba(248, 113, 113, 0.14)",
684
+ info: "#60A5FA",
685
+ infoSoft: "rgba(96, 165, 250, 0.14)",
686
+ neutral: "#A1A1AA",
687
+ neutralSoft: "rgba(161, 161, 170, 0.16)",
688
+ tick: "#4ADE80",
689
+ focus: "#6F95F2"
690
+ },
691
+ chart: ["#6F95F2", "#A1A1AA", "#4CC5AE", "#A08CF5", "#FBBF24", "#F87171", "#60A5FA", "#D4D4D8"],
692
+ pie: ["#6F95F2", "#5372B8", "#52525B", "#3F3F46", "#2C2C31"],
693
+ shadow: "0 1px 2px rgba(0, 0, 0, 0.5)",
694
+ shimmer: { from: "#222227", to: "#2A2A2F" }
695
+ }, be = (e) => e.replace(/[A-Z]/g, (t) => `-${t.toLowerCase()}`), or = {
696
+ "--openui-background": { light: "oklch(0.97 0 89.876 / 1)", dark: "oklch(0.145 0 0 / 1)" },
697
+ "--openui-foreground": { light: "oklch(0.994 0 89.876 / 1)", dark: "oklch(0.205 0 0 / 1)" },
698
+ "--openui-popover-background": { light: "oklch(0.994 0 89.876 / 1)", dark: "oklch(0.205 0 0 / 1)" },
699
+ "--openui-sunk-light": { light: "oklch(0.097 0 0 / 0.02)", dark: "oklch(0.994 0 89.876 / 0.02)" },
700
+ "--openui-sunk": { light: "oklch(0.097 0 0 / 0.04)", dark: "oklch(0.994 0 89.876 / 0.04)" },
701
+ "--openui-sunk-deep": { light: "oklch(0.097 0 0 / 0.08)", dark: "oklch(0.994 0 89.876 / 0.08)" },
702
+ "--openui-elevated-light": { light: "oklch(0.097 0 0 / 0.04)", dark: "oklch(0.994 0 89.876 / 0.04)" },
703
+ "--openui-elevated": { light: "oklch(0.097 0 0 / 0.08)", dark: "oklch(0.994 0 89.876 / 0.08)" },
704
+ "--openui-elevated-strong": { light: "oklch(0.097 0 0 / 0.16)", dark: "oklch(0.994 0 89.876 / 0.16)" },
705
+ "--openui-elevated-intense": { light: "oklch(0.097 0 0 / 0.32)", dark: "oklch(0.994 0 89.876 / 0.32)" },
706
+ "--openui-overlay": { light: "oklch(0 0 0 / 0.4)", dark: "oklch(0 0 0 / 0.6)" },
707
+ "--openui-highlight-subtle": { light: "oklch(0.097 0 0 / 0.02)", dark: "oklch(0.994 0 89.876 / 0.02)" },
708
+ "--openui-highlight": { light: "oklch(0.097 0 0 / 0.04)", dark: "oklch(0.994 0 89.876 / 0.04)" },
709
+ "--openui-highlight-strong": { light: "oklch(0.097 0 0 / 0.08)", dark: "oklch(0.994 0 89.876 / 0.08)" },
710
+ "--openui-highlight-intense": { light: "oklch(0.097 0 0 / 0.32)", dark: "oklch(0.994 0 89.876 / 0.3)" },
711
+ "--openui-inverted-background": { light: "oklch(0.097 0 0 / 1)", dark: "oklch(0.994 0 89.876 / 1)" },
712
+ "--openui-text-neutral-primary": { light: "oklch(0.097 0 0 / 1)", dark: "oklch(0.985 0 89.876 / 1)" },
713
+ "--openui-text-neutral-secondary": { light: "oklch(0.097 0 0 / 0.5)", dark: "oklch(0.985 0 89.876 / 0.5)" },
714
+ "--openui-text-neutral-tertiary": { light: "oklch(0.097 0 0 / 0.2)", dark: "oklch(0.985 0 89.876 / 0.2)" },
715
+ "--openui-text-neutral-link": { light: "oklch(0.097 0 0 / 1)", dark: "oklch(0.985 0 89.876 / 1)" },
716
+ "--openui-text-brand": { light: "oklch(0.097 0 0 / 1)", dark: "oklch(0.994 0 89.876 / 1)" },
717
+ "--openui-text-accent-primary": { light: "oklch(0.994 0 89.876 / 1)", dark: "oklch(0.097 0 0 / 1)" },
718
+ "--openui-text-accent-secondary": { light: "oklch(0.994 0 89.876 / 0.5)", dark: "oklch(0.097 0 0 / 0.5)" },
719
+ "--openui-text-accent-tertiary": { light: "oklch(0.994 0 89.876 / 0.2)", dark: "oklch(0.097 0 0 / 0.2)" },
720
+ "--openui-text-success-primary": { light: "oklch(0.448 0.108 151.328 / 1)", dark: "oklch(0.871 0.136 154.449 / 1)" },
721
+ "--openui-text-alert-primary": { light: "oklch(0.476 0.103 61.907 / 1)", dark: "oklch(0.905 0.166 98.111 / 1)" },
722
+ "--openui-text-danger-primary": { light: "oklch(0.505 0.19 27.518 / 1)", dark: "oklch(0.808 0.103 19.571 / 1)" },
723
+ "--openui-text-danger-secondary": { light: "oklch(0.711 0.166 22.216 / 1)", dark: "oklch(0.885 0.059 18.334 / 1)" },
724
+ "--openui-text-danger-tertiary": { light: "oklch(0.808 0.103 19.571 / 1)", dark: "oklch(0.936 0.031 17.717 / 1)" },
725
+ "--openui-text-info-primary": { light: "oklch(0.424 0.181 265.638 / 1)", dark: "oklch(0.809 0.096 251.813 / 1)" },
726
+ "--openui-text-pink-primary": { light: "oklch(0.459 0.17 3.815 / 1)", dark: "oklch(0.823 0.11 346.018 / 1)" },
727
+ "--openui-text-purple-primary": { light: "oklch(0.438 0.198 303.724 / 1)", dark: "oklch(0.827 0.108 306.383 / 1)" },
728
+ "--openui-interactive-accent-default": { light: "oklch(0.097 0 0 / 1)", dark: "oklch(0.994 0 89.876 / 1)" },
729
+ "--openui-interactive-accent-hover": { light: "oklch(0.097 0 0 / 0.8)", dark: "oklch(0.994 0 89.876 / 0.8)" },
730
+ "--openui-interactive-accent-disabled": { light: "oklch(0.097 0 0 / 0.4)", dark: "oklch(0.994 0 89.876 / 0.4)" },
731
+ "--openui-interactive-accent-pressed": { light: "oklch(0.097 0 0 / 1)", dark: "oklch(0.994 0 89.876 / 1)" },
732
+ "--openui-chat-user-response-bg": { light: "oklch(0.097 0 0 / 0.08)", dark: "oklch(0.994 0 89.876 / 0.08)" },
733
+ "--openui-chat-user-response-text": { light: "oklch(0.097 0 0 / 1)", dark: "oklch(0.985 0 89.876 / 1)" },
734
+ "--openui-border-default": { light: "oklch(0.097 0 0 / 0.06)", dark: "oklch(0.994 0 89.876 / 0.06)" },
735
+ "--openui-border-interactive": { light: "oklch(0.097 0 0 / 0.12)", dark: "oklch(0.994 0 89.876 / 0.12)" },
736
+ "--openui-border-interactive-emphasis": { light: "oklch(0.097 0 0 / 0.3)", dark: "oklch(0.994 0 89.876 / 0.4)" },
737
+ "--openui-border-interactive-selected": { light: "oklch(0.097 0 0 / 1)", dark: "oklch(0.985 0 89.876 / 1)" },
738
+ "--openui-border-accent": { light: "oklch(0.097 0 0 / 0.08)", dark: "oklch(0.994 0 89.876 / 0.2)" },
739
+ "--openui-border-accent-emphasis": { light: "oklch(0.097 0 0 / 0.3)", dark: "oklch(0.994 0 89.876 / 0.4)" },
740
+ "--openui-shadow-s": { light: "0 1px 3px -2px oklch(0 0 0 / 0.02), 0 2px 5px -2px oklch(0 0 0 / 0.04)", dark: "0 1px 3px -2px oklch(0 0 0 / 0.06), 0 2px 5px -2px oklch(0 0 0 / 0.10)" },
741
+ "--openui-shadow-m": { light: "0 4px 6px -2px oklch(0 0 0 / 0.025), 0 2px 2px -2px oklch(0 0 0 / 0.05)", dark: "0 4px 6px -2px oklch(0 0 0 / 0.08), 0 2px 2px -2px oklch(0 0 0 / 0.12)" },
742
+ "--openui-shadow-l": { light: "0 4px 4px -2px oklch(0 0 0 / 0.05), 0 4px 8px -2px oklch(0 0 0 / 0.04)", dark: "0 4px 4px -2px oklch(0 0 0 / 0.12), 0 4px 8px -2px oklch(0 0 0 / 0.10)" },
743
+ "--openui-shadow-xl": { light: "0 8px 16px -4px oklch(0 0 0 / 0.08), 0 16px 32px -6px oklch(0 0 0 / 0.12)", dark: "0 8px 16px -4px oklch(0 0 0 / 0.16), 0 16px 32px -6px oklch(0 0 0 / 0.20)" },
744
+ "--openui-shadow-2xl": { light: "0 12px 24px -6px oklch(0 0 0 / 0.12), 0 24px 48px -8px oklch(0 0 0 / 0.16)", dark: "0 12px 24px -6px oklch(0 0 0 / 0.20), 0 24px 48px -8px oklch(0 0 0 / 0.24)" },
745
+ "--openui-shadow-3xl": { light: "0 16px 32px -8px oklch(0 0 0 / 0.16), 0 32px 64px -12px oklch(0 0 0 / 0.22)", dark: "0 16px 32px -8px oklch(0 0 0 / 0.24), 0 32px 64px -12px oklch(0 0 0 / 0.28)" }
746
+ };
747
+ function lr(e = T) {
748
+ const t = {
749
+ ...T,
750
+ ...e,
751
+ color: { ...T.color, ...e.color ?? {} },
752
+ font: { ...T.font, ...e.font ?? {} },
753
+ size: { ...T.size, ...e.size ?? {} },
754
+ shimmer: { ...T.shimmer, ...e.shimmer ?? {} },
755
+ tilePad: { ...T.tilePad, ...e.tilePad ?? {} }
756
+ }, n = {};
757
+ for (const [a, o] of Object.entries(t.color)) n[`--uir-color-${be(a)}`] = o;
758
+ for (const [a, o] of Object.entries(t.font)) n[`--uir-font-${be(a)}`] = o;
759
+ for (const [a, o] of Object.entries(t.size)) n[`--uir-size-${be(a)}`] = o;
760
+ for (const [a, o] of Object.entries(t.space)) n[`--uir-space-${be(a)}`] = o;
761
+ for (const [a, o] of Object.entries(t.radius)) n[`--uir-radius-${be(a)}`] = o;
762
+ for (const [a, o] of Object.entries(t.density)) n[`--uir-density-${be(a)}`] = o;
763
+ n["--uir-tile-pad-y"] = t.tilePad.y, n["--uir-tile-pad-x"] = t.tilePad.x, n["--uir-shimmer-from"] = t.shimmer.from, n["--uir-shimmer-to"] = t.shimmer.to, n["--uir-measure"] = t.measure, n["--uir-shadow"] = t.shadow ?? T.shadow, n["--uir-motion-fold"] = le.fold, n["--uir-motion-shimmer"] = le.shimmer, n["--uir-motion-tick"] = le.tick, n["--uir-motion-slide-in"] = le.slideIn, n["--uir-motion-fade"] = le.fade, n["--uir-motion-dot"] = le.dot, n["--uir-motion-bar-in"] = le.barIn, n["--uir-motion-count-up"] = le.countUp, n["--uir-overlay-width"] = Ye.width, n["--uir-overlay-scrim"] = Ye.scrim, n["--uir-overlay-shadow"] = Ye.shadow, (t.chart ?? T.chart).forEach((a, o) => {
764
+ n[`--uir-chart-${o + 1}`] = a;
765
+ });
766
+ const r = t.scheme === "dark" ? qt.pie : T.pie;
767
+ (e.pie ?? [t.color.brand, ...r.slice(1)]).forEach((a, o) => {
768
+ n[`--uir-pie-${o + 1}`] = a;
769
+ });
770
+ const i = t.scheme === "dark" ? "dark" : "light";
771
+ for (const [a, o] of Object.entries(or)) n[a] = o[i];
772
+ return t.scheme === "dark" && Object.assign(n, {
773
+ "--openui-background": t.color.ground,
774
+ "--openui-foreground": t.color.sheet,
775
+ "--openui-popover-background": t.color.sheet,
776
+ "--openui-inverted-background": t.color.ink,
777
+ "--openui-sunk-light": "rgba(255,255,255,0.02)",
778
+ "--openui-sunk": "rgba(255,255,255,0.04)",
779
+ "--openui-sunk-deep": "rgba(255,255,255,0.08)",
780
+ "--openui-elevated-light": "rgba(255,255,255,0.04)",
781
+ "--openui-elevated": "rgba(255,255,255,0.08)",
782
+ "--openui-elevated-strong": "rgba(255,255,255,0.16)",
783
+ "--openui-highlight-subtle": "rgba(255,255,255,0.02)",
784
+ "--openui-highlight": "rgba(255,255,255,0.04)",
785
+ "--openui-highlight-strong": "rgba(255,255,255,0.08)",
786
+ "--openui-text-neutral-primary": t.color.ink,
787
+ "--openui-text-neutral-secondary": t.color.graphite,
788
+ "--openui-text-neutral-tertiary": t.color.faint,
789
+ "--openui-text-neutral-link": t.color.ink,
790
+ "--openui-text-brand": t.color.ink,
791
+ // `--openui-border-neutral` / `-strong` used to be here. OpenUI defines NEITHER and reads
792
+ // neither: two variables repairing nothing, for as long as the dark theme has existed. Their
793
+ // real border properties are these.
794
+ "--openui-border-default": t.color.rule,
795
+ "--openui-border-interactive": t.color.ruleStrong
796
+ }), n;
797
+ }
798
+ const cr = (e = {}) => {
799
+ var n;
800
+ const t = e.scheme === "dark" ? qt.pie : T.pie;
801
+ return {
802
+ ...T,
803
+ ...e,
804
+ color: { ...T.color, ...e.color ?? {} },
805
+ font: { ...T.font, ...e.font ?? {} },
806
+ size: { ...T.size, ...e.size ?? {} },
807
+ chart: e.chart ?? T.chart,
808
+ pie: e.pie ?? [((n = e.color) == null ? void 0 : n.brand) ?? t[0], ...t.slice(1)]
809
+ };
810
+ }, We = {
811
+ navigate: "Navigation between pages is the host application's job. This renderer draws one page.",
812
+ mutate: "Writes are disabled in v1. A mutation must be authorized by the resolver, and this renderer will not pretend a write succeeded."
813
+ }, ur = "This page asks to be presented in an overlay, but the host supplied no `resolvePage`, so there is no page to present.";
814
+ function dr(e, t) {
815
+ return e ? e.type === "mutate" ? We.mutate : e.type !== "navigate" ? null : e.mode === "overlay" ? t != null && t.openOverlay ? null : ur : We.navigate : null;
816
+ }
817
+ const $a = (e) => !!(e && We[e.type]), hr = (e, t = "Run") => (e == null ? void 0 : e.label) ?? t;
818
+ function Qe(e, t) {
819
+ if (!e) return { disabled: !1, reason: null };
820
+ const n = dr(e, t);
821
+ if (n) return { disabled: !0, reason: n };
822
+ if (!e.enabled_when) return { disabled: !1, reason: null };
823
+ let r;
824
+ try {
825
+ r = Ce(e.enabled_when, t == null ? void 0 : t.scope);
826
+ } catch {
827
+ r = !1;
828
+ }
829
+ return r === !0 ? { disabled: !1, reason: null } : { disabled: !0, reason: e.disabled_reason ?? "This action is not available right now." };
830
+ }
831
+ async function et(e, t) {
832
+ var r, i, a, o;
833
+ if (!e) return;
834
+ const n = Qe(e, t);
835
+ if (n.disabled) {
836
+ (r = t.onNotice) == null || r.call(t, n.reason);
837
+ return;
838
+ }
839
+ switch (e.type) {
840
+ case "navigate": {
841
+ const l = {};
842
+ for (const [d, c] of Object.entries(e.params ?? {})) l[d] = t.resolveValue(c, t.scope);
843
+ await t.openOverlay({ pageId: e.page, params: l });
844
+ break;
845
+ }
846
+ case "set_param": {
847
+ const l = t.resolveValue(e.value, t.scope);
848
+ t.setParam(e.param, l);
849
+ break;
850
+ }
851
+ case "refresh":
852
+ t.refresh(e.datasets === "all" ? "all" : e.datasets);
853
+ break;
854
+ case "open": {
855
+ if (e.url) {
856
+ if (!/^https?:\/\//i.test(e.url)) {
857
+ (i = t.onNotice) == null || i.call(t, "Refused to open a non-http(s) URL.");
858
+ return;
859
+ }
860
+ window.open(e.url, e.target === "self" ? "_self" : "_blank", "noopener,noreferrer");
861
+ } else if (e.record) {
862
+ const l = t.resolveValue(e.record.id, t.scope);
863
+ if (!t.onOpenRecord) {
864
+ (a = t.onNotice) == null || a.call(t, `Opening ${e.record.dataset} record "${l}" needs a host. Pass \`onOpenRecord\` to <UIResponsePage>.`);
865
+ return;
866
+ }
867
+ t.onOpenRecord({ dataset: e.record.dataset, id: l, target: e.target ?? "new_window" });
868
+ }
869
+ break;
870
+ }
871
+ default:
872
+ (o = t.onNotice) == null || o.call(t, `Unknown action verb "${e.type}".`);
873
+ return;
874
+ }
875
+ for (const l of e.then ?? []) await et(l, t);
876
+ }
877
+ async function mr(e, t, { row: n, widgetValue: r }) {
878
+ const i = { ...t.scope, row: n, self: r };
879
+ if (n === null && (e == null ? void 0 : e.type) === "set_param" && !Ot(e.value)) {
880
+ t.setParam(e.param, null);
881
+ for (const a of e.then ?? []) await et(a, { ...t, scope: i });
882
+ return;
883
+ }
884
+ await Be(e, { ...t, scope: i });
885
+ }
886
+ async function Be(e, t) {
887
+ if (e != null && e.confirm && !Qe(e, t).disabled) {
888
+ const { title: n, body: r, confirm_label: i } = e.confirm;
889
+ if (!(t.confirm ? await t.confirm(e.confirm) : window.confirm([n, r].filter(Boolean).join(`
890
+
891
+ `) + (i ? `
892
+
893
+ [${i}]` : "")))) return;
894
+ }
895
+ await et(e, t);
896
+ }
897
+ const fr = 5;
898
+ function pr(e) {
899
+ const t = String(e ?? "").trim().split(/\s+/).filter(Boolean);
900
+ return t.length ? `${t[0][0]}${t.length > 1 ? t[t.length - 1][0] : t[0][1] ?? ""}`.toUpperCase() : "—";
901
+ }
902
+ function gr(e, t, n = fr) {
903
+ const r = (e == null ? void 0 : e.length) ?? 0, i = Math.max(1, Math.ceil(r / n)), a = Math.max(0, Math.min(Number.isFinite(t) ? t : 0, i - 1)), o = a * n;
904
+ return { items: (e ?? []).slice(o, o + n), page: a, pageCount: i, start: r ? o + 1 : 0, end: Math.min(o + n, r), count: r };
905
+ }
906
+ const yr = (e) => new Intl.DateTimeFormat("en", { month: "short" }).format(new Date(e));
907
+ function _r(e, t, n, r) {
908
+ const i = (e ?? []).map((h) => ({ row: h, t: Date.parse(h[t]), end: n ? Date.parse(h[n]) : NaN })).filter((h) => Number.isFinite(h.t)).sort((h, f) => h.t - f.t);
909
+ if (!i.length) return { items: [], ticks: [], today: null };
910
+ const a = i[0].t, o = Math.max(...i.map((h) => Number.isFinite(h.end) ? h.end : h.t)), l = o - a || 1, d = (h) => 6 + (h - a) / l * 88, c = [0, 1 / 3, 2 / 3, 1].map((h) => {
911
+ const f = a + l * h;
912
+ return { label: yr(f), left: d(f) };
913
+ }), u = new Date(r).getTime();
914
+ return {
915
+ items: i.map((h) => ({
916
+ ...h,
917
+ left: d(h.t),
918
+ width: Number.isFinite(h.end) ? d(h.end) - d(h.t) : 0
919
+ })),
920
+ ticks: c,
921
+ today: Number.isFinite(u) && u >= a && u <= o ? d(u) : null
922
+ };
923
+ }
924
+ function Ft(e) {
925
+ if (!Number.isFinite(e) || e < 0) return "0:00";
926
+ const t = Math.floor(e);
927
+ return `${Math.floor(t / 60)}:${String(t % 60).padStart(2, "0")}`;
928
+ }
929
+ const wr = (e) => {
930
+ var t;
931
+ return !!((t = e == null ? void 0 : e.confirm) != null && t.destructive || (e == null ? void 0 : e.type) === "mutate" && e.operation === "delete");
932
+ }, br = (e) => typeof e == "string" && /^https?:\/\/[^"'()\s\\]+$/i.test(e) ? `url("${e}")` : null;
933
+ function tt({ src: e, thumb: t, alt: n = "", className: r, ...i }) {
934
+ const a = C(null), [o, l] = V(!1);
935
+ j(() => {
936
+ const c = a.current;
937
+ l(!!(c != null && c.complete && c.naturalWidth > 0));
938
+ }, [e]);
939
+ const d = br(t);
940
+ return /* @__PURE__ */ s(
941
+ "img",
942
+ {
943
+ ...i,
944
+ ref: a,
945
+ className: ["uir-img", r].filter(Boolean).join(" "),
946
+ src: e,
947
+ alt: n,
948
+ loading: "lazy",
949
+ decoding: "async",
950
+ style: d ? { ...i.style, backgroundImage: d } : i.style,
951
+ "data-blurup": d ? "thumb" : "none",
952
+ "data-loaded": o || void 0,
953
+ onLoad: () => l(!0),
954
+ onError: () => l(!0)
955
+ }
956
+ );
957
+ }
958
+ function De({ policy: e }) {
959
+ const { kind: t, text: n } = Gn(e);
960
+ return t === "hide" || t === "blank" ? null : t === "zero" ? /* @__PURE__ */ s("span", { className: "uir-absent uir-absent--zero", children: "0" }) : t === "text" ? /* @__PURE__ */ s("span", { className: "uir-absent uir-absent--text", title: "No value recorded", children: n }) : /* @__PURE__ */ s("span", { className: "uir-absent uir-absent--dash", "aria-label": "No value recorded", title: "No value recorded", children: "—" });
961
+ }
962
+ function _e({ value: e, format: t, empty: n, column: r, now: i, thumb: a, spec: o }) {
963
+ var d, c;
964
+ if (ke(e)) return /* @__PURE__ */ s(De, { policy: n });
965
+ if ((r == null ? void 0 : r.role) === "image" && typeof e == "string")
966
+ return /^https?:\/\//i.test(e) ? /* @__PURE__ */ s(tt, { className: "uir-thumb", src: e, thumb: a, alt: "" }) : /* @__PURE__ */ s(De, { policy: n });
967
+ const l = q(e, t, { column: r, now: i });
968
+ if ((o == null ? void 0 : o.as) === "badge") {
969
+ const u = o.tone ?? ((c = (d = o.tone_map) == null ? void 0 : d.find((h) => h.value === e)) == null ? void 0 : c.tone) ?? "neutral";
970
+ return /* @__PURE__ */ s("span", { className: "uir-badge uir-badge--cell", "data-tone": u, children: l });
971
+ }
972
+ return /* @__PURE__ */ s(Me, { children: l });
973
+ }
974
+ const Ge = (e, t) => qn(e, t);
975
+ function Wt({ value: e, shape: t = "round" }) {
976
+ return /* @__PURE__ */ s("span", { className: "uir-initials", "data-shape": t, "aria-hidden": "true", children: pr(e) });
977
+ }
978
+ const vr = (e) => String(e).replace(/_/g, " ").replace(/^./, (t) => t.toUpperCase());
979
+ function Je({ variant: e = "bars", block: t }) {
980
+ const n = t == null ? void 0 : t.title, r = (t == null ? void 0 : t.type) === "table" ? t.columns : null;
981
+ return e === "metric" ? /* @__PURE__ */ m("div", { className: "uir-skeleton", children: [
982
+ t != null && t.label ? /* @__PURE__ */ s("span", { className: "uir-skeleton__label", children: t.label }) : /* @__PURE__ */ s("div", { className: "uir-skeleton__bar" }),
983
+ /* @__PURE__ */ s("div", { className: "uir-skeleton__value" })
984
+ ] }) : e === "value" ? /* @__PURE__ */ m("div", { className: "uir-skeleton", children: [
985
+ t != null && t.label ? /* @__PURE__ */ s("span", { className: "uir-skeleton__label", children: t.label }) : /* @__PURE__ */ s("div", { className: "uir-skeleton__bar" }),
986
+ /* @__PURE__ */ s("div", { className: "uir-skeleton__bar uir-skeleton__bar--narrow" })
987
+ ] }) : /* @__PURE__ */ m("div", { className: "uir-skeleton", children: [
988
+ n ? /* @__PURE__ */ s("h3", { className: "uir-skeleton__heading", children: n }) : /* @__PURE__ */ s("div", { className: "uir-skeleton__bar" }),
989
+ r != null && r.length ? (
990
+ // The column heads are the table's shape. They are in the document, so they are on the screen.
991
+ /* @__PURE__ */ s("div", { className: "uir-skeleton__cols", children: r.map((i) => /* @__PURE__ */ s("span", { children: i.label ?? vr(i.field) }, i.field)) })
992
+ ) : null,
993
+ /* @__PURE__ */ s("div", { className: "uir-skeleton__value", style: { height: 56, width: "100%" } })
994
+ ] });
995
+ }
996
+ function de({ message: e, onRetry: t }) {
997
+ const n = String(e).split(/`([^`]+)`/g);
998
+ return /* @__PURE__ */ m("div", { className: "uir-error", role: "alert", children: [
999
+ /* @__PURE__ */ s("span", { className: "uir-error__mark", "aria-hidden": "true", children: "!" }),
1000
+ /* @__PURE__ */ m("span", { className: "uir-error__body", children: [
1001
+ /* @__PURE__ */ s("span", { className: "uir-error__label", children: "Could not resolve" }),
1002
+ /* @__PURE__ */ s("span", { className: "uir-error__msg", title: e, children: n.map((r, i) => i % 2 ? /* @__PURE__ */ s("code", { children: r }, i) : r) }),
1003
+ t && /* @__PURE__ */ s("button", { type: "button", className: "uir-error__retry", onClick: t, children: "Retry" })
1004
+ ] })
1005
+ ] });
1006
+ }
1007
+ function Nr() {
1008
+ return /* @__PURE__ */ s("span", { className: "uir-tick", "aria-hidden": "true", children: /* @__PURE__ */ s("svg", { width: "9", height: "7", viewBox: "0 0 9 7", children: /* @__PURE__ */ s("polyline", { points: "1,3.5 3.5,6 8,1" }) }) });
1009
+ }
1010
+ function kr({ prompt: e, onResolve: t }) {
1011
+ const n = C(null), r = Pt();
1012
+ return j(() => {
1013
+ var a;
1014
+ (a = n.current) == null || a.focus();
1015
+ const i = (o) => {
1016
+ o.key === "Escape" && t(!1);
1017
+ };
1018
+ return document.addEventListener("keydown", i), () => document.removeEventListener("keydown", i);
1019
+ }, [t]), /* @__PURE__ */ m("div", { className: "uir-confirm", role: "dialog", "aria-modal": "true", "aria-labelledby": r, children: [
1020
+ /* @__PURE__ */ s("button", { className: "uir-confirm__scrim", type: "button", "aria-label": "Cancel", onClick: () => t(!1) }),
1021
+ /* @__PURE__ */ m("div", { className: "uir-confirm__panel", ref: n, tabIndex: -1, children: [
1022
+ /* @__PURE__ */ s("h2", { id: r, children: e.title }),
1023
+ e.body && /* @__PURE__ */ s("p", { children: e.body }),
1024
+ /* @__PURE__ */ m("div", { className: "uir-confirm__actions", children: [
1025
+ /* @__PURE__ */ s("button", { type: "button", className: "uir-button uir-button--ghost", onClick: () => t(!1), children: "Cancel" }),
1026
+ /* @__PURE__ */ s("button", { type: "button", className: `uir-button${e.destructive ? " uir-button--confirm" : ""}`, onClick: () => t(!0), children: e.confirm_label ?? "Confirm" })
1027
+ ] })
1028
+ ] })
1029
+ ] });
1030
+ }
1031
+ function Gt({ action: e, ctx: t, variant: n = "ghost", small: r = !1, fallbackLabel: i }) {
1032
+ const a = Pt(), { disabled: o, reason: l } = Qe(e, t), d = hr(e, i), c = wr(e) ? "danger" : n, u = [
1033
+ "uir-button",
1034
+ c === "ghost" ? "uir-button--ghost" : "",
1035
+ c === "danger" ? "uir-button--danger" : "",
1036
+ r ? "uir-button--small" : ""
1037
+ ].filter(Boolean).join(" "), h = /* @__PURE__ */ s(
1038
+ "button",
1039
+ {
1040
+ type: "button",
1041
+ className: u,
1042
+ disabled: o,
1043
+ "aria-describedby": o ? a : void 0,
1044
+ onClick: (f) => {
1045
+ f.stopPropagation(), Be(e, t);
1046
+ },
1047
+ children: d
1048
+ }
1049
+ );
1050
+ return o ? /* @__PURE__ */ m("span", { className: "uir-disabled-wrap", children: [
1051
+ h,
1052
+ /* @__PURE__ */ s("span", { className: "uir-reason", role: "note", id: a, children: l })
1053
+ ] }) : h;
1054
+ }
1055
+ const Jt = (e) => {
1056
+ var t;
1057
+ return ((t = e.layout) == null ? void 0 : t.arrangement) ?? "stack";
1058
+ }, St = (e) => {
1059
+ var t;
1060
+ return ((t = e.layout) == null ? void 0 : t.density) ?? void 0;
1061
+ }, Ct = { primary: 0, supporting: 1, ambient: 2 }, Dt = { hero: 0, primary: 1, normal: 2, subtle: 3 };
1062
+ function Zt(e, t) {
1063
+ return t === "stack" ? e : e.map((n, r) => ({ block: n, index: r })).sort((n, r) => {
1064
+ var d, c;
1065
+ const i = Dt[n.block.emphasis ?? "normal"], a = Dt[r.block.emphasis ?? "normal"];
1066
+ if (i !== a) return i - a;
1067
+ const o = Ct[(d = n.block.intent) == null ? void 0 : d.priority] ?? 1, l = Ct[(c = r.block.intent) == null ? void 0 : c.priority] ?? 1;
1068
+ return o !== l ? o - l : n.index - r.index;
1069
+ }).map((n) => n.block);
1070
+ }
1071
+ function $r({ block: e, children: t }) {
1072
+ return /* @__PURE__ */ s("div", { className: "uir-arrange", "data-arrangement": Jt(e), children: t });
1073
+ }
1074
+ function xr({ block: e, renderChild: t, hideTitle: n }) {
1075
+ const r = W(), i = Jt(e), a = St(e) ?? r.density, o = Ht(e) && !n;
1076
+ return /* @__PURE__ */ m("section", { className: "uir-section", "data-density": St(e), "data-editorial": o || void 0, children: [
1077
+ e.title && !n && /* @__PURE__ */ s("h2", { className: "uir-section__label", children: e.title }),
1078
+ /* @__PURE__ */ s(Xe.Provider, { value: { ...r, density: a }, children: /* @__PURE__ */ s($r, { block: e, children: Zt(e.children ?? [], o ? "stack" : i).map(t) }) })
1079
+ ] });
1080
+ }
1081
+ function Ar({ block: e, renderChild: t, emphasis: n }) {
1082
+ const r = W(), i = !!e.on_click;
1083
+ return /* @__PURE__ */ m(
1084
+ "div",
1085
+ {
1086
+ className: `uir-card${i ? " uir-card--clickable" : ""}`,
1087
+ "data-emphasis": n,
1088
+ onClick: i ? () => Be(e.on_click, { ...r.actionCtx, scope: Y(r) }) : void 0,
1089
+ children: [
1090
+ e.title && /* @__PURE__ */ s("h3", { className: "uir-card__title", children: e.title }),
1091
+ /* @__PURE__ */ s("div", { className: "uir-arrange", "data-arrangement": "grid", children: Zt(e.children ?? [], "grid").map(t) })
1092
+ ]
1093
+ }
1094
+ );
1095
+ }
1096
+ function Fr({ block: e, renderChild: t }) {
1097
+ const [n, r] = V(0), i = e.children ?? [];
1098
+ return /* @__PURE__ */ m("div", { className: "uir-tabs", children: [
1099
+ /* @__PURE__ */ s("div", { className: "uir-tabs__list", role: "tablist", children: i.map((a, o) => /* @__PURE__ */ s(
1100
+ "button",
1101
+ {
1102
+ type: "button",
1103
+ role: "tab",
1104
+ className: "uir-tab",
1105
+ "aria-selected": o === n,
1106
+ "aria-controls": `panel-${a.id}`,
1107
+ onClick: () => r(o),
1108
+ children: a.title
1109
+ },
1110
+ a.id
1111
+ )) }),
1112
+ i.map((a, o) => /* @__PURE__ */ s(
1113
+ "div",
1114
+ {
1115
+ id: `panel-${a.id}`,
1116
+ role: "tabpanel",
1117
+ hidden: o !== n,
1118
+ children: t(a, o)
1119
+ },
1120
+ a.id
1121
+ ))
1122
+ ] });
1123
+ }
1124
+ const Xt = rr, Sr = () => /* @__PURE__ */ s("svg", { className: "uir-chevron", width: "7", height: "11", viewBox: "0 0 7 11", "aria-hidden": "true", focusable: "false", children: /* @__PURE__ */ s("polyline", { points: "1.5,1.5 5.5,5.5 1.5,9.5", fill: "none", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" }) }), nt = (e) => ({ "--uir-i": ir(e) }), ye = (e, t) => e.find((n) => n.name === t), Mt = (e) => e.replace(/_/g, " ").replace(/^./, (t) => t.toUpperCase()), Ze = (e, t) => e.label ?? (t == null ? void 0 : t.label) ?? (t != null && t.name ? Mt(t.name) : Mt(e.field));
1125
+ function Ee(e, t) {
1126
+ var a;
1127
+ const n = W(), r = (a = e[t]) == null ? void 0 : a.$bind, i = r ? n.dataset(r.dataset) : null;
1128
+ return { uir: n, bind: r, rows: (i == null ? void 0 : i.rows) ?? [], columns: (i == null ? void 0 : i.columns) ?? [] };
1129
+ }
1130
+ function rt(e) {
1131
+ return (t, n) => Be(t, { ...e.actionCtx, scope: Y(e, n) });
1132
+ }
1133
+ function Cr({ block: e }) {
1134
+ const { uir: t, rows: n, columns: r } = Ee(e, "rows"), i = rt(t), a = e.columns ?? Xt(r), o = e.row_actions ?? [], l = !!e.row_action, [d, c] = V(t.density ?? "comfortable"), [u, h] = V(0), f = Kt(r, qe(r)), p = qe(r) ? null : a.find((v) => {
1135
+ var S;
1136
+ return ((S = ye(r, v.field)) == null ? void 0 : S.role) === "name";
1137
+ }), y = gr(n, u);
1138
+ return j(() => {
1139
+ y.page !== u && h(y.page);
1140
+ }, [u, y.page]), /* @__PURE__ */ m(Me, { children: [
1141
+ /* @__PURE__ */ m("div", { className: "uir-table__head", children: [
1142
+ e.title && /* @__PURE__ */ s("h3", { className: "uir-table__title", children: e.title }),
1143
+ /* @__PURE__ */ s("div", { className: "uir-density", role: "group", "aria-label": "Table density", children: [["comfortable", "Comfortable"], ["compact", "Compact"]].map(([v, S]) => /* @__PURE__ */ s("button", { type: "button", "aria-pressed": d === v, onClick: () => c(v), children: S }, v)) })
1144
+ ] }),
1145
+ /* @__PURE__ */ m("div", { className: "uir-table-wrap", children: [
1146
+ /* @__PURE__ */ s("div", { className: "uir-table__scroll", children: /* @__PURE__ */ m("table", { className: "uir-table", "data-density": d, children: [
1147
+ /* @__PURE__ */ s("thead", { children: /* @__PURE__ */ m("tr", { children: [
1148
+ a.map((v) => {
1149
+ const S = ye(r, v.field);
1150
+ return /* @__PURE__ */ s("th", { "data-numeric": Ge(v.format, S) || void 0, scope: "col", children: Ze(v, S) }, v.field);
1151
+ }),
1152
+ o.length > 0 && /* @__PURE__ */ s("th", { className: "uir-table__actions-cell", scope: "col", "aria-label": "Row actions" })
1153
+ ] }) }),
1154
+ /* @__PURE__ */ s("tbody", { children: y.items.map((v, S) => /* @__PURE__ */ m(
1155
+ "tr",
1156
+ {
1157
+ style: nt(S),
1158
+ "data-clickable": l || void 0,
1159
+ tabIndex: l ? 0 : void 0,
1160
+ role: l ? "button" : void 0,
1161
+ onClick: l ? (w) => {
1162
+ w.currentTarget.focus(), i(e.row_action, v);
1163
+ } : void 0,
1164
+ onKeyDown: l ? (w) => {
1165
+ (w.key === "Enter" || w.key === " ") && (w.preventDefault(), i(e.row_action, v));
1166
+ } : void 0,
1167
+ children: [
1168
+ a.map((w) => {
1169
+ const M = ye(r, w.field);
1170
+ return /* @__PURE__ */ s("td", { "data-numeric": Ge(w.format, M) || void 0, children: p === w ? /* @__PURE__ */ m("span", { className: "uir-name-cell", children: [
1171
+ /* @__PURE__ */ s(Wt, { value: v[w.field] }),
1172
+ /* @__PURE__ */ s(
1173
+ _e,
1174
+ {
1175
+ value: v[w.field],
1176
+ format: w.format,
1177
+ empty: w.empty,
1178
+ column: M,
1179
+ now: t.now,
1180
+ spec: w
1181
+ }
1182
+ )
1183
+ ] }) : /* @__PURE__ */ s(
1184
+ _e,
1185
+ {
1186
+ value: v[w.field],
1187
+ format: w.format,
1188
+ empty: w.empty,
1189
+ column: M,
1190
+ now: t.now,
1191
+ thumb: (M == null ? void 0 : M.role) === "image" && f ? v[f.name] : void 0,
1192
+ spec: w
1193
+ }
1194
+ ) }, w.field);
1195
+ }),
1196
+ o.length > 0 && /* @__PURE__ */ s("td", { className: "uir-table__actions-cell", children: /* @__PURE__ */ s("div", { className: "uir-table__actions", children: o.map((w, M) => /* @__PURE__ */ s(
1197
+ Gt,
1198
+ {
1199
+ action: w,
1200
+ small: !0,
1201
+ ctx: { ...t.actionCtx, scope: Y(t, v) },
1202
+ fallbackLabel: w.type
1203
+ },
1204
+ M
1205
+ )) }) })
1206
+ ]
1207
+ },
1208
+ S
1209
+ )) })
1210
+ ] }) }),
1211
+ y.count > 0 && /* @__PURE__ */ m("div", { className: "uir-pagination", children: [
1212
+ /* @__PURE__ */ m("span", { children: [
1213
+ y.start,
1214
+ "–",
1215
+ y.end,
1216
+ " of ",
1217
+ y.count
1218
+ ] }),
1219
+ /* @__PURE__ */ m("div", { children: [
1220
+ /* @__PURE__ */ s("button", { type: "button", "aria-label": "Previous page", disabled: y.page === 0, onClick: () => h((v) => v - 1), children: "‹" }),
1221
+ /* @__PURE__ */ s("button", { type: "button", "aria-label": "Next page", disabled: y.page >= y.pageCount - 1, onClick: () => h((v) => v + 1), children: "›" })
1222
+ ] })
1223
+ ] })
1224
+ ] })
1225
+ ] });
1226
+ }
1227
+ function Dr({ block: e, uir: t, rows: n, columns: r, imageCol: i }) {
1228
+ const a = rt(t), o = !!e.item_action, l = e.subtitle_field ? ye(r, e.subtitle_field) : null, d = Kt(r, i), c = o ? "button" : "div";
1229
+ return /* @__PURE__ */ s("div", { className: "uir-posters", "data-mode": er(n.length), children: n.map((u, h) => {
1230
+ const f = u[i.name];
1231
+ return /* @__PURE__ */ m(
1232
+ c,
1233
+ {
1234
+ type: o ? "button" : void 0,
1235
+ className: "uir-poster",
1236
+ style: nt(h),
1237
+ "data-clickable": o || void 0,
1238
+ onClick: o ? (k) => {
1239
+ k.currentTarget.focus(), a(e.item_action, u);
1240
+ } : void 0,
1241
+ children: [
1242
+ /* @__PURE__ */ s("span", { className: "uir-poster__art", "data-empty": xt(f) ? void 0 : "true", children: xt(f) && /* @__PURE__ */ s(tt, { src: f, thumb: d ? u[d.name] : null, alt: "" }) }),
1243
+ /* @__PURE__ */ s("span", { className: "uir-poster__title", children: u[e.title_field] }),
1244
+ e.subtitle_field && /* @__PURE__ */ s("span", { className: "uir-poster__caption", children: /* @__PURE__ */ s(_e, { value: u[e.subtitle_field], column: l, now: t.now }) })
1245
+ ]
1246
+ },
1247
+ h
1248
+ );
1249
+ }) });
1250
+ }
1251
+ function Mr({ block: e }) {
1252
+ const { uir: t, rows: n, columns: r } = Ee(e, "items"), i = rt(t), a = !!e.item_action, o = e.subtitle_field ? ye(r, e.subtitle_field) : null, l = qe(r);
1253
+ return l && n.length ? /* @__PURE__ */ s(Dr, { block: e, uir: t, rows: n, columns: r, imageCol: l }) : /* @__PURE__ */ s("div", { className: "uir-list", children: n.map((d, c) => /* @__PURE__ */ m(
1254
+ a ? "button" : "div",
1255
+ {
1256
+ type: a ? "button" : void 0,
1257
+ className: "uir-list__item",
1258
+ style: nt(c),
1259
+ "data-clickable": a || void 0,
1260
+ onClick: a ? (h) => {
1261
+ h.currentTarget.focus(), i(e.item_action, d);
1262
+ } : void 0,
1263
+ children: [
1264
+ /* @__PURE__ */ s(Wt, { value: d[e.title_field], shape: "square" }),
1265
+ /* @__PURE__ */ m("span", { className: "uir-list__copy", children: [
1266
+ /* @__PURE__ */ s("span", { className: "uir-list__title", children: d[e.title_field] }),
1267
+ e.subtitle_field && /* @__PURE__ */ s("span", { className: "uir-list__subtitle", children: /* @__PURE__ */ s(_e, { value: d[e.subtitle_field], column: o, now: t.now }) })
1268
+ ] }),
1269
+ a && /* @__PURE__ */ s(Sr, {})
1270
+ ]
1271
+ },
1272
+ c
1273
+ )) });
1274
+ }
1275
+ const Br = (e) => e == null ? void 0 : e.role;
1276
+ function Er({ block: e, emphasis: t = "normal" }) {
1277
+ const { uir: n, rows: r, columns: i } = Ee(e, "source"), a = e.select ?? "only";
1278
+ if (a === "only" && r.length !== 1)
1279
+ return /* @__PURE__ */ s(de, { message: `\`select: "only"\` requires exactly one row; the dataset resolved ${r.length}.` });
1280
+ const o = a === "last" ? r[r.length - 1] : r[0];
1281
+ if (!o) return /* @__PURE__ */ s(de, { message: "The dataset resolved no rows to describe." });
1282
+ const d = (e.fields ?? Xt(i)).map((f) => ({ spec: f, col: ye(i, f.field) })), { head: c, badges: u, facts: h } = sr(d, o);
1283
+ return /* @__PURE__ */ m("div", { className: "uir-detail", "data-emphasis": t, "data-headed": c ? "true" : void 0, children: [
1284
+ c && /* @__PURE__ */ m("div", { className: "uir-detail__head", children: [
1285
+ /* @__PURE__ */ s("h3", { className: "uir-detail__name", children: /* @__PURE__ */ s(_e, { value: o[c.spec.field], format: c.spec.format, empty: c.spec.empty, column: c.col, now: n.now, spec: c.spec }) }),
1286
+ u.length > 0 && /* @__PURE__ */ s("div", { className: "uir-detail__badges", children: u.map(({ spec: f, col: k }) => /* @__PURE__ */ m("span", { className: "uir-badge", "data-tone": Zn(o[f.field]), children: [
1287
+ /* @__PURE__ */ s("span", { className: "uir-badge__label", children: Ze(f, k) }),
1288
+ String(o[f.field])
1289
+ ] }, f.field)) })
1290
+ ] }),
1291
+ h.length > 0 && /* @__PURE__ */ s("dl", { className: "uir-detail__facts", children: h.map(({ spec: f, col: k }) => /* @__PURE__ */ m("div", { className: "uir-detail__row", children: [
1292
+ /* @__PURE__ */ s("dt", { className: "uir-eyebrow", children: Ze(f, k) }),
1293
+ /* @__PURE__ */ s("dd", { className: "uir-detail__value", "data-numeric": Ge(f.format, k) || void 0, children: Br(k) === "url" && jt(o[f.field]) ? /* @__PURE__ */ s("a", { className: "uir-detail__link", href: o[f.field], target: "_blank", rel: "noreferrer noopener", children: Xn(o[f.field]) }) : /* @__PURE__ */ s(_e, { value: o[f.field], format: f.format, empty: f.empty, column: k, now: n.now, spec: f }) })
1294
+ ] }, f.field)) })
1295
+ ] });
1296
+ }
1297
+ function Tr({ block: e }) {
1298
+ const { uir: t, rows: n, columns: r } = Ee(e, "items"), i = ye(r, e.date_field), a = E(
1299
+ () => _r(n, e.date_field, e.end_date_field, t.now),
1300
+ [n, e.date_field, e.end_date_field, t.now]
1301
+ ), { items: o, ticks: l, today: d } = a;
1302
+ return o.length ? /* @__PURE__ */ s("div", { className: "uir-timeline", children: /* @__PURE__ */ m("div", { className: "uir-timeline__track", children: [
1303
+ /* @__PURE__ */ s("div", { className: "uir-timeline__axis" }),
1304
+ d !== null && /* @__PURE__ */ m(Me, { children: [
1305
+ /* @__PURE__ */ s("div", { className: "uir-timeline__today-line", style: { left: `${d}%` } }),
1306
+ /* @__PURE__ */ s("span", { className: "uir-timeline__today", style: { left: `${d}%` }, children: "today" })
1307
+ ] }),
1308
+ o.map(({ row: c, left: u, width: h }, f) => (
1309
+ // Captions rotate through FOUR lanes — two above the axis, two below. Alternating only two
1310
+ // sides was not enough: eight releases across twelve weeks put four captions inside one
1311
+ // hundred pixels and they printed over each other. The dots never move, because their
1312
+ // positions are the only thing this block asserts; only the captions are given room.
1313
+ /* @__PURE__ */ m(
1314
+ "div",
1315
+ {
1316
+ className: "uir-timeline__item",
1317
+ style: { left: `${u}%` },
1318
+ "data-side": f % 2 === 0 ? "above" : "below",
1319
+ "data-lane": f % 4,
1320
+ children: [
1321
+ h > 0 && /* @__PURE__ */ s("div", { className: "uir-timeline__span", style: { width: `${h}%` } }),
1322
+ /* @__PURE__ */ s("div", { className: "uir-timeline__stem" }),
1323
+ /* @__PURE__ */ s("div", { className: "uir-timeline__dot" }),
1324
+ /* @__PURE__ */ m("div", { className: "uir-timeline__caption", children: [
1325
+ /* @__PURE__ */ s("div", { className: "uir-timeline__label", children: c[e.label_field] }),
1326
+ /* @__PURE__ */ s("div", { className: "uir-timeline__date", children: q(c[e.date_field], { as: "date", date_style: "day" }, { column: i, now: t.now }) })
1327
+ ] })
1328
+ ]
1329
+ },
1330
+ f
1331
+ )
1332
+ )),
1333
+ /* @__PURE__ */ s("div", { className: "uir-timeline__ticks", children: l.map((c, u) => /* @__PURE__ */ s("span", { style: { left: `${c.left}%` }, children: c.label }, u)) })
1334
+ ] }) }) : null;
1335
+ }
1336
+ const Rr = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"], Bt = (e, t, n) => `${e}-${String(t + 1).padStart(2, "0")}-${String(n).padStart(2, "0")}`, Et = (e) => (e + 6) % 7;
1337
+ function Pr(e) {
1338
+ if (typeof e == "string") {
1339
+ const n = /^(\d{4})-(\d{2})-(\d{2})/.exec(e);
1340
+ if (n) return { y: +n[1], m: +n[2] - 1, d: +n[3] };
1341
+ }
1342
+ if (e == null) return null;
1343
+ const t = e instanceof Date ? e : new Date(e);
1344
+ return Number.isNaN(t.getTime()) ? null : { y: t.getFullYear(), m: t.getMonth(), d: t.getDate() };
1345
+ }
1346
+ function Ir({ block: e }) {
1347
+ const { rows: t } = Ee(e, "items"), n = e.span === "week" ? "week" : "month", { cells: r, title: i, count: a } = E(() => {
1348
+ const o = [];
1349
+ for (const p of t) {
1350
+ const y = Pr(p[e.date_field]);
1351
+ y && o.push({ day: y, label: p[e.label_field] });
1352
+ }
1353
+ if (!o.length) return { cells: [], title: null, count: 0 };
1354
+ const l = /* @__PURE__ */ new Map();
1355
+ for (const p of o) {
1356
+ const y = Bt(p.day.y, p.day.m, p.day.d);
1357
+ l.has(y) || l.set(y, []), l.get(y).push(p.label);
1358
+ }
1359
+ const c = [...o].sort((p, y) => new Date(p.day.y, p.day.m, p.day.d) - new Date(y.day.y, y.day.m, y.day.d))[0].day;
1360
+ let u, h;
1361
+ if (n === "week") {
1362
+ const p = new Date(c.y, c.m, c.d);
1363
+ p.setDate(p.getDate() - Et(p.getDay())), u = p, h = 7;
1364
+ } else {
1365
+ const p = new Date(c.y, c.m, 1), y = Et(p.getDay());
1366
+ u = new Date(c.y, c.m, 1 - y);
1367
+ const v = new Date(c.y, c.m + 1, 0).getDate();
1368
+ h = Math.ceil((y + v) / 7) * 7;
1369
+ }
1370
+ const f = [];
1371
+ for (let p = 0; p < h; p++) {
1372
+ const y = new Date(u.getFullYear(), u.getMonth(), u.getDate() + p), v = Bt(y.getFullYear(), y.getMonth(), y.getDate());
1373
+ f.push({
1374
+ key: v,
1375
+ date: y.getDate(),
1376
+ inPeriod: n === "week" || y.getMonth() === c.m,
1377
+ labels: l.get(v) ?? []
1378
+ });
1379
+ }
1380
+ const k = n === "week" ? `Week of ${u.toLocaleDateString(void 0, { month: "long", day: "numeric" })}` : new Date(c.y, c.m, 1).toLocaleDateString(void 0, { month: "long", year: "numeric" });
1381
+ return { cells: f, title: k, count: o.length };
1382
+ }, [t, e.date_field, e.label_field, n]);
1383
+ return r.length ? /* @__PURE__ */ m("div", { className: "uir-calendar", "data-span": n, children: [
1384
+ /* @__PURE__ */ m("div", { className: "uir-calendar__head", children: [
1385
+ /* @__PURE__ */ s("span", { className: "uir-eyebrow", children: i }),
1386
+ /* @__PURE__ */ m("span", { className: "uir-calendar__count", children: [
1387
+ a,
1388
+ " ",
1389
+ a === 1 ? "item" : "items"
1390
+ ] })
1391
+ ] }),
1392
+ /* @__PURE__ */ m("div", { className: "uir-calendar__grid", role: "grid", "aria-label": `${i}: ${a} items`, children: [
1393
+ Rr.map((o) => /* @__PURE__ */ s("div", { className: "uir-calendar__weekday", role: "columnheader", children: o }, o)),
1394
+ r.map((o) => /* @__PURE__ */ m(
1395
+ "div",
1396
+ {
1397
+ className: "uir-calendar__cell",
1398
+ role: "gridcell",
1399
+ "data-outside": !o.inPeriod || void 0,
1400
+ "data-occupied": o.labels.length > 0 || void 0,
1401
+ children: [
1402
+ /* @__PURE__ */ s("span", { className: "uir-calendar__date", children: o.date }),
1403
+ o.labels.map((l, d) => /* @__PURE__ */ s("span", { className: "uir-calendar__item", title: String(l), children: l }, d))
1404
+ ]
1405
+ },
1406
+ o.key
1407
+ ))
1408
+ ] })
1409
+ ] }) : null;
1410
+ }
1411
+ const Or = {
1412
+ up: { up: "positive", down: "negative", flat: "neutral" },
1413
+ down: { up: "negative", down: "positive", flat: "neutral" }
1414
+ }, Lr = { up: "▲", down: "▼", flat: "–" }, Ur = { up: "up", down: "down", flat: "unchanged" };
1415
+ function Vr({ delta: e, scope: t, now: n }) {
1416
+ var u;
1417
+ if (!e) return null;
1418
+ let r;
1419
+ try {
1420
+ r = H(e.value, t);
1421
+ } catch {
1422
+ return null;
1423
+ }
1424
+ if (ke(r) || !Number.isFinite(Number(r))) return null;
1425
+ const i = Number(r), a = i > 0 ? "up" : i < 0 ? "down" : "flat", o = ((u = Or[e.direction_good]) == null ? void 0 : u[a]) ?? "neutral", l = X(e.value) ? e.value.$bind : null, d = q(Math.abs(i), { ...(l == null ? void 0 : l.format) ?? {}, sign: "never" }, { column: l ? fe(l, t) : null, now: n }), c = `${Ur[a]} ${d}${e.vs ? ` ${e.vs}` : ""}`;
1426
+ return /* @__PURE__ */ m("span", { className: "uir-metric__delta", "data-tone": o, "data-direction": a, "aria-label": c, children: [
1427
+ /* @__PURE__ */ m("em", { "aria-hidden": "true", children: [
1428
+ Lr[a],
1429
+ " ",
1430
+ d
1431
+ ] }),
1432
+ e.vs && /* @__PURE__ */ s("span", { "aria-hidden": "true", children: e.vs })
1433
+ ] });
1434
+ }
1435
+ const jr = () => typeof window < "u" && typeof window.matchMedia == "function" ? window.matchMedia("(prefers-reduced-motion: reduce)").matches : !1, Hr = 750, zr = (e, t) => e && t ? `uir-count:${e}:${t}` : null;
1436
+ function Yr(e) {
1437
+ if (!e || typeof window > "u") return null;
1438
+ try {
1439
+ const t = window.sessionStorage.getItem(e), n = t === null ? NaN : Number(t);
1440
+ return Number.isFinite(n) ? n : null;
1441
+ } catch {
1442
+ return null;
1443
+ }
1444
+ }
1445
+ function Tt(e, t) {
1446
+ if (!(!e || typeof window > "u"))
1447
+ try {
1448
+ window.sessionStorage.setItem(e, String(t));
1449
+ } catch {
1450
+ }
1451
+ }
1452
+ function Kr(e, t, n = null) {
1453
+ const [r, i] = V(e), a = C(!1);
1454
+ return j(() => {
1455
+ if (!t || a.current || jr()) {
1456
+ i(e), t && (a.current = !0, Tt(n, e));
1457
+ return;
1458
+ }
1459
+ a.current = !0;
1460
+ const o = Yr(n) ?? 0;
1461
+ if (Tt(n, e), o === e) {
1462
+ i(e);
1463
+ return;
1464
+ }
1465
+ let l = 0;
1466
+ const d = performance.now(), c = (u) => {
1467
+ const h = Math.min(1, (u - d) / Hr);
1468
+ i(o + (e - o) * (1 - (1 - h) ** 3)), h < 1 ? l = requestAnimationFrame(c) : i(e);
1469
+ };
1470
+ return l = requestAnimationFrame(c), () => cancelAnimationFrame(l);
1471
+ }, [e, t, n]), r;
1472
+ }
1473
+ const qr = /* @__PURE__ */ new Set(["date", "relative_time"]);
1474
+ function Wr({ block: e, emphasis: t }) {
1475
+ const n = W(), r = Y(n), i = X(e.value) ? fe(e.value.$bind, r) : null, a = X(e.value) ? e.value.$bind.format : void 0, o = X(e.value) ? e.value.$bind.empty : void 0;
1476
+ let l = null, d = null;
1477
+ try {
1478
+ l = H(e.value, r);
1479
+ } catch (f) {
1480
+ d = f;
1481
+ }
1482
+ const c = typeof l == "number" && Number.isFinite(l) && !qr.has(a == null ? void 0 : a.as) && (i == null ? void 0 : i.type) !== "date", u = Kr(c ? l : 0, c, c ? zr(n.pageId, e.id) : null);
1483
+ if (d) return /* @__PURE__ */ s(de, { message: d.message });
1484
+ const h = /* @__PURE__ */ m("div", { className: "uir-metric", "data-emphasis": t, children: [
1485
+ /* @__PURE__ */ s("span", { className: "uir-eyebrow uir-metric__label", children: e.label }),
1486
+ /* @__PURE__ */ m("span", { className: "uir-metric__value", children: [
1487
+ /* @__PURE__ */ s(_e, { value: c ? u : l, format: a, empty: o, column: i, now: n.now }),
1488
+ e.unit && !ke(l) && !Gr.has(a == null ? void 0 : a.as) && /* @__PURE__ */ s("span", { className: "uir-metric__unit", children: e.unit })
1489
+ ] }),
1490
+ /* @__PURE__ */ s(Vr, { delta: e.delta, scope: r, now: n.now })
1491
+ ] });
1492
+ return e.on_click ? /* @__PURE__ */ s("button", { type: "button", className: "uir-metric--clickable", onClick: () => Be(e.on_click, { ...n.actionCtx, scope: r }), children: h }) : h;
1493
+ }
1494
+ const Gr = /* @__PURE__ */ new Set(["currency", "percent", "bytes", "duration"]);
1495
+ function Jr({ block: e }) {
1496
+ const t = W(), n = Y(t), r = H(e.value, n), i = H(e.total, n), a = X(e.value) ? fe(e.value.$bind, n) : null, o = X(e.value) ? e.value.$bind.format : void 0, l = !ke(r) && !ke(i) && Number(i) > 0, d = l ? Math.max(0, Math.min(100, Number(r) / Number(i) * 100)) : 0;
1497
+ return /* @__PURE__ */ m("div", { className: "uir-progress", children: [
1498
+ /* @__PURE__ */ m("div", { className: "uir-progress__head", children: [
1499
+ e.label && /* @__PURE__ */ s("span", { className: "uir-eyebrow", children: e.label }),
1500
+ /* @__PURE__ */ s("span", { className: "uir-progress__value", children: l ? /* @__PURE__ */ m(Me, { children: [
1501
+ q(r, o, { column: a, now: t.now }),
1502
+ /* @__PURE__ */ m("span", { className: "uir-progress__ratio", children: [
1503
+ " / ",
1504
+ q(i, o, { column: a, now: t.now })
1505
+ ] })
1506
+ ] }) : (
1507
+ // Progress against an unknown total is not 0%. It is unknown, and it says so.
1508
+ /* @__PURE__ */ s(De, { policy: X(e.value) ? e.value.$bind.empty : void 0 })
1509
+ ) })
1510
+ ] }),
1511
+ /* @__PURE__ */ s(
1512
+ "div",
1513
+ {
1514
+ className: "uir-progress__track",
1515
+ role: "progressbar",
1516
+ "aria-valuenow": l ? Math.round(d) : void 0,
1517
+ "aria-valuemin": 0,
1518
+ "aria-valuemax": 100,
1519
+ "aria-label": e.label ?? "Progress",
1520
+ children: /* @__PURE__ */ s("div", { className: "uir-progress__fill", style: { width: `${d}%` } })
1521
+ }
1522
+ )
1523
+ ] });
1524
+ }
1525
+ function Zr({ block: e }) {
1526
+ var o, l;
1527
+ const t = W(), n = Y(t, t.row), r = H(e.value, n), i = (l = (o = e.tone_map) == null ? void 0 : o.find((d) => d.value === r)) == null ? void 0 : l.tone, a = e.tone ?? i ?? "neutral";
1528
+ return ke(r) ? /* @__PURE__ */ s(De, { policy: X(e.value) ? e.value.$bind.empty : void 0 }) : /* @__PURE__ */ m("span", { className: "uir-badge", "data-tone": a, children: [
1529
+ e.label && /* @__PURE__ */ s("span", { className: "uir-badge__label", children: e.label }),
1530
+ String(r)
1531
+ ] });
1532
+ }
1533
+ function Xr({ block: e }) {
1534
+ const t = W(), n = Y(t, t.row), r = (e.stages ?? []).map((a) => {
1535
+ let o = !1;
1536
+ try {
1537
+ o = H(a.done, n) === !0;
1538
+ } catch {
1539
+ o = !1;
1540
+ }
1541
+ return { label: a.label, done: o };
1542
+ }), i = r.findIndex((a) => !a.done);
1543
+ return /* @__PURE__ */ s("ol", { className: "uir-stages", "aria-label": e.title ?? "Stages", children: r.map((a, o) => /* @__PURE__ */ m(
1544
+ "li",
1545
+ {
1546
+ className: "uir-stages__stage",
1547
+ "data-done": a.done || void 0,
1548
+ "data-current": o === i || void 0,
1549
+ children: [
1550
+ /* @__PURE__ */ s("span", { className: "uir-stages__mark", "aria-hidden": "true", children: a.done ? "✓" : "" }),
1551
+ /* @__PURE__ */ s("span", { className: "uir-stages__label", children: a.label }),
1552
+ /* @__PURE__ */ s("span", { className: "uir-stages__state", children: a.done ? "done" : "pending" })
1553
+ ]
1554
+ },
1555
+ o
1556
+ )) });
1557
+ }
1558
+ const Rt = 300;
1559
+ function Qr() {
1560
+ const e = C(null), [t, n] = V(0);
1561
+ return hn(() => {
1562
+ const r = e.current;
1563
+ if (!r) return;
1564
+ const i = () => n(r.clientWidth);
1565
+ i();
1566
+ const a = new ResizeObserver(i);
1567
+ return a.observe(r), () => a.disconnect();
1568
+ }, []), [e, t];
1569
+ }
1570
+ const Qt = Math.PI * 2, Ue = (e, t, n, r) => [e + n * Math.cos(r - Math.PI / 2), t + n * Math.sin(r - Math.PI / 2)];
1571
+ function ea(e, t, n, r, i, a) {
1572
+ if (a - i >= Qt - 1e-6)
1573
+ return [
1574
+ `M ${e - n} ${t}`,
1575
+ `A ${n} ${n} 0 1 1 ${e + n} ${t}`,
1576
+ `A ${n} ${n} 0 1 1 ${e - n} ${t}`,
1577
+ `M ${e - r} ${t}`,
1578
+ `A ${r} ${r} 0 1 0 ${e + r} ${t}`,
1579
+ `A ${r} ${r} 0 1 0 ${e - r} ${t}`,
1580
+ "Z"
1581
+ ].join(" ");
1582
+ const o = a - i > Math.PI ? 1 : 0, [l, d] = Ue(e, t, n, i), [c, u] = Ue(e, t, n, a), [h, f] = Ue(e, t, r, a), [k, p] = Ue(e, t, r, i);
1583
+ return `M ${l} ${d} A ${n} ${n} 0 ${o} 1 ${c} ${u} L ${h} ${f} A ${r} ${r} 0 ${o} 0 ${k} ${p} Z`;
1584
+ }
1585
+ function ta({ slices: e, palette: t, format: n, column: r, now: i }) {
1586
+ const a = e.reduce((p, y) => p + y.value, 0), o = 148, l = o / 2, d = o / 2, c = 68, u = 44;
1587
+ let h = 0;
1588
+ const f = e.map((p, y) => {
1589
+ const v = a > 0 ? p.value / a * Qt : 0, S = ea(l, d, c, u, h, h + v);
1590
+ return h += v, { d: S, color: t[y % t.length], ...p };
1591
+ }), k = (p) => a > 0 ? `${(p / a * 100).toFixed(a > 0 && p / a < 0.1 ? 1 : 0)}%` : null;
1592
+ return /* @__PURE__ */ m("div", { className: "uir-pie", children: [
1593
+ /* @__PURE__ */ m("svg", { width: o, height: o, viewBox: `0 0 ${o} ${o}`, role: "img", "aria-label": `${e.length} categories`, children: [
1594
+ f.map((p, y) => /* @__PURE__ */ s("path", { d: p.d, fill: p.color, stroke: "var(--uir-color-sheet)", strokeWidth: "1.5", children: /* @__PURE__ */ s("title", { children: `${p.label}: ${p.value}` }) }, y)),
1595
+ /* @__PURE__ */ s(
1596
+ "text",
1597
+ {
1598
+ x: l,
1599
+ y: d - 3,
1600
+ textAnchor: "middle",
1601
+ fill: "var(--uir-color-ink)",
1602
+ style: { font: "600 20px var(--uir-font-body)", fontVariantNumeric: "tabular-nums" },
1603
+ children: q(a, n, { column: r, now: i })
1604
+ }
1605
+ ),
1606
+ /* @__PURE__ */ s(
1607
+ "text",
1608
+ {
1609
+ x: l,
1610
+ y: d + 14,
1611
+ textAnchor: "middle",
1612
+ fill: "var(--uir-color-faint)",
1613
+ style: { font: "400 10px var(--uir-font-body)" },
1614
+ children: "total"
1615
+ }
1616
+ )
1617
+ ] }),
1618
+ /* @__PURE__ */ s("div", { className: "uir-pie__legend", children: f.map((p, y) => /* @__PURE__ */ m("div", { className: "uir-pie__row", children: [
1619
+ /* @__PURE__ */ s("span", { className: "uir-pie__swatch", style: { background: p.color } }),
1620
+ /* @__PURE__ */ s("span", { className: "uir-pie__label", title: p.label, children: p.label }),
1621
+ /* @__PURE__ */ s("span", { className: "uir-pie__value", children: q(p.value, n, { column: r, now: i }) }),
1622
+ /* @__PURE__ */ s("span", { className: "uir-pie__pct", children: k(p.value) ?? /* @__PURE__ */ s(De, {}) })
1623
+ ] }, y)) })
1624
+ ] });
1625
+ }
1626
+ function na({ names: e, values: t, palette: n }) {
1627
+ return e.length < 2 ? null : /* @__PURE__ */ s("div", { className: "uir-chart__legend", children: e.map((r, i) => /* @__PURE__ */ m("span", { className: "uir-chart__legend-item", children: [
1628
+ /* @__PURE__ */ s("span", { className: "uir-chart__swatch", style: { background: n[i % n.length] } }),
1629
+ /* @__PURE__ */ s("span", { className: "uir-chart__legend-label", children: r }),
1630
+ /* @__PURE__ */ s("span", { className: "uir-chart__legend-value", children: t[i] })
1631
+ ] }, i)) });
1632
+ }
1633
+ function ra({ block: e }) {
1634
+ var S;
1635
+ const t = W(), n = E(() => Y(t), [t]), { data: r, xKey: i, yKey: a, yValues: o, names: l, legendValues: d } = E(() => {
1636
+ const w = e.y.$bind, M = fe(w, n), I = Ve(w, n), K = (M == null ? void 0 : M.label) ?? w.field;
1637
+ if (!e.x) return { data: [], xKey: null, yKey: K, yValues: I.map(Number), names: [K], legendValues: [] };
1638
+ const Q = e.x.$bind, ee = fe(Q, n), we = Ve(Q, n), N = (ee == null ? void 0 : ee.label) ?? Q.field, b = (e.series ?? []).filter((F) => {
1639
+ var R;
1640
+ return (R = F == null ? void 0 : F.y) == null ? void 0 : R.$bind;
1641
+ }).map((F) => ({
1642
+ name: F.label,
1643
+ values: Ve(F.y.$bind, n),
1644
+ bind: F.y.$bind,
1645
+ column: fe(F.y.$bind, n)
1646
+ })), $ = /* @__PURE__ */ new Set([N, K]);
1647
+ for (const F of b) {
1648
+ let R = F.name;
1649
+ for (let G = 2; $.has(R); G++) R = `${F.name} (${G})`;
1650
+ $.add(R), F.name = R;
1651
+ }
1652
+ const B = we.map((F, R) => {
1653
+ const G = {
1654
+ [N]: q(F, Q.format, { column: ee, now: t.now }),
1655
+ [K]: Number(I[R])
1656
+ };
1657
+ for (const $e of b) G[$e.name] = Number($e.values[R]);
1658
+ return G;
1659
+ }), x = (F) => [...F].reverse().find((R) => R != null), te = [
1660
+ q(x(I), w.format, { column: M, now: t.now }),
1661
+ ...b.map((F) => q(x(F.values), F.bind.format, { column: F.column, now: t.now }))
1662
+ ];
1663
+ return { data: B, xKey: N, yKey: K, yValues: I.map(Number), names: [K, ...b.map((F) => F.name)], legendValues: te };
1664
+ }, [e, n, t.now]), c = (e.series ?? []).filter((w) => w.kind && w.kind !== e.kind).map((w) => w.label), u = (S = t.actionCtx) == null ? void 0 : S.onNotice;
1665
+ j(() => {
1666
+ c.length && (u == null || u(`This renderer draws every series in one shape. ${c.length === 1 ? `"${c[0]}" is` : `${c.length} series are`} drawn as ${e.kind} rather than the shape the page asked for.`));
1667
+ }, [e.id, c.length, u]);
1668
+ const h = t.theme.chart, [f, k] = Qr(), p = E(() => e.kind !== "pie" || !e.x ? [] : r.map((w) => ({ label: String(w[i]), value: Number(w[a]) })).filter((w) => Number.isFinite(w.value) && w.value > 0).sort((w, M) => M.value - w.value), [e.kind, e.x, r, i, a]);
1669
+ if (e.kind === "sparkline")
1670
+ return /* @__PURE__ */ s(mn, { data: o, size: "100%" });
1671
+ if (!r.length) return null;
1672
+ if (e.kind === "pie") {
1673
+ const w = fe(e.y.$bind, n);
1674
+ return /* @__PURE__ */ s(ta, { slices: p, palette: t.theme.pie, format: e.y.$bind.format, column: w, now: t.now });
1675
+ }
1676
+ const y = Math.max(0, k), v = { data: r, categoryKey: i, height: Rt, legend: !1, isAnimationActive: !0, width: y };
1677
+ return /* @__PURE__ */ m("div", { className: "uir-chart-frame", children: [
1678
+ /* @__PURE__ */ s(na, { names: l, values: d, palette: h }),
1679
+ /* @__PURE__ */ s("div", { className: "uir-chart-frame__inner", ref: f, children: y === 0 ? /* @__PURE__ */ s("div", { style: { height: Rt } }) : /* @__PURE__ */ m(Me, { children: [
1680
+ e.kind === "area" && /* @__PURE__ */ s(fn, { ...v, grid: !0, showYAxis: !0 }),
1681
+ e.kind === "line" && /* @__PURE__ */ s(pn, { ...v, grid: !0, showYAxis: !0 }),
1682
+ e.kind === "bar" && /* @__PURE__ */ s(gn, { ...v, grid: !0, showYAxis: !0, radius: 2 })
1683
+ ] }) })
1684
+ ] });
1685
+ }
1686
+ function aa({ block: e, emphasis: t }) {
1687
+ return /* @__PURE__ */ s("p", { className: "uir-text", "data-emphasis": t, children: e.body });
1688
+ }
1689
+ const ia = {
1690
+ youtube: { origin: "https://www.youtube-nocookie.com", url: (e) => `https://www.youtube-nocookie.com/embed/${e}`, open: (e) => `https://www.youtube.com/watch?v=${e}`, domain: "youtube.com", name: "YouTube" },
1691
+ tiktok: { origin: "https://www.tiktok.com", url: (e) => `https://www.tiktok.com/embed/v2/${e}`, open: (e) => `https://www.tiktok.com/player/v1/${e}`, domain: "tiktok.com", name: "TikTok" },
1692
+ // An opaque id cannot say track-vs-playlist-vs-episode, so `spotify` resolves to the default
1693
+ // surface. Widening that is a `content_type` prop or more enum members; encoding it in the id
1694
+ // would be a microsyntax (B2) and would reopen the path surface the pattern closes.
1695
+ spotify: { origin: "https://open.spotify.com", url: (e) => `https://open.spotify.com/embed/track/${e}`, open: (e) => `https://open.spotify.com/track/${e}`, domain: "open.spotify.com", name: "Spotify" }
1696
+ }, sa = "allow-scripts allow-same-origin allow-presentation";
1697
+ function oa({ block: e }) {
1698
+ const t = ia[e.provider];
1699
+ if (!t)
1700
+ return /* @__PURE__ */ s(de, { message: `This renderer does not know the media provider \`${e.provider}\`. It will not guess an origin.` });
1701
+ const n = t.url(encodeURIComponent(e.content_id)), r = t.open(encodeURIComponent(e.content_id)), i = e.aspect ?? "16:9";
1702
+ return /* @__PURE__ */ m("figure", { className: "uir-media", children: [
1703
+ /* @__PURE__ */ s("div", { className: "uir-media__frame", "data-aspect": i, style: { aspectRatio: i.replace(":", " / ") }, children: /* @__PURE__ */ s(
1704
+ "iframe",
1705
+ {
1706
+ className: "uir-media__embed",
1707
+ src: n,
1708
+ title: e.alt,
1709
+ sandbox: sa,
1710
+ referrerPolicy: "no-referrer",
1711
+ allow: "encrypted-media; picture-in-picture; clipboard-write",
1712
+ allowFullScreen: !0,
1713
+ loading: "lazy"
1714
+ }
1715
+ ) }),
1716
+ /* @__PURE__ */ m("figcaption", { className: "uir-embed-meta", children: [
1717
+ /* @__PURE__ */ s("span", { className: "uir-embed-meta__icon", "aria-hidden": "true", children: t.name[0] }),
1718
+ /* @__PURE__ */ m("span", { className: "uir-embed-meta__copy", children: [
1719
+ /* @__PURE__ */ s("strong", { children: e.caption ?? e.alt }),
1720
+ /* @__PURE__ */ s("span", { children: t.domain })
1721
+ ] }),
1722
+ /* @__PURE__ */ m("a", { href: r, target: "_blank", rel: "noreferrer", children: [
1723
+ "Open ",
1724
+ /* @__PURE__ */ s("span", { "aria-hidden": "true", children: "↗" })
1725
+ ] })
1726
+ ] })
1727
+ ] });
1728
+ }
1729
+ function la({ src: e, title: t }) {
1730
+ const n = C(null), [r, i] = V(!1), [a, o] = V(0), [l, d] = V(0);
1731
+ j(() => {
1732
+ i(!1), o(0), d(0);
1733
+ }, [e]);
1734
+ const c = async () => {
1735
+ if (n.current)
1736
+ try {
1737
+ n.current.paused ? await n.current.play() : n.current.pause();
1738
+ } catch {
1739
+ i(!1);
1740
+ }
1741
+ }, u = l > 0 ? Math.min(100, a / l * 100) : 0;
1742
+ return /* @__PURE__ */ m("div", { className: "uir-audio", children: [
1743
+ /* @__PURE__ */ s(
1744
+ "audio",
1745
+ {
1746
+ ref: n,
1747
+ src: e,
1748
+ preload: "metadata",
1749
+ onPlay: () => i(!0),
1750
+ onPause: () => i(!1),
1751
+ onEnded: () => i(!1),
1752
+ onTimeUpdate: (h) => o(h.currentTarget.currentTime),
1753
+ onLoadedMetadata: (h) => d(h.currentTarget.duration)
1754
+ }
1755
+ ),
1756
+ /* @__PURE__ */ s("button", { type: "button", onClick: c, "aria-label": r ? `Pause ${t}` : `Play ${t}`, children: /* @__PURE__ */ s("span", { "aria-hidden": "true", children: r ? "Ⅱ" : "▶" }) }),
1757
+ /* @__PURE__ */ m("div", { className: "uir-audio__body", children: [
1758
+ /* @__PURE__ */ m("div", { className: "uir-audio__line", children: [
1759
+ /* @__PURE__ */ s("strong", { title: t, children: t }),
1760
+ /* @__PURE__ */ m("span", { children: [
1761
+ Ft(a),
1762
+ " / ",
1763
+ Ft(l)
1764
+ ] })
1765
+ ] }),
1766
+ /* @__PURE__ */ s("div", { className: "uir-audio__track", children: /* @__PURE__ */ s("span", { style: { width: `${u}%` } }) })
1767
+ ] })
1768
+ ] });
1769
+ }
1770
+ function ca({ block: e }) {
1771
+ const t = W(), n = Y(t, t.row);
1772
+ if (e.kind === "video" || e.kind === "embed") return /* @__PURE__ */ s(oa, { block: e });
1773
+ const r = H(e.src, n);
1774
+ return typeof r != "string" || !/^https?:\/\//i.test(r) ? /* @__PURE__ */ m("div", { className: "uir-error", role: "alert", children: [
1775
+ /* @__PURE__ */ s("span", { className: "uir-error__label", children: "Refused media source" }),
1776
+ "Only absolute http(s) URLs may be rendered."
1777
+ ] }) : e.kind === "audio" ? /* @__PURE__ */ s("figure", { className: "uir-media", children: /* @__PURE__ */ s(la, { src: r, title: e.caption ?? "Audio" }) }) : /* @__PURE__ */ m("figure", { className: "uir-media", children: [
1778
+ /* @__PURE__ */ s(tt, { className: "uir-media__image", src: r, thumb: ua(e.src, n), alt: e.alt ?? "" }),
1779
+ e.caption && /* @__PURE__ */ s("figcaption", { className: "uir-media__caption", children: e.caption })
1780
+ ] });
1781
+ }
1782
+ function ua(e, t) {
1783
+ var a;
1784
+ const n = e == null ? void 0 : e.$bind;
1785
+ if (!(n != null && n.dataset) || !n.field) return null;
1786
+ const r = Yt(n.field);
1787
+ if (!(((a = t.dataset(n.dataset)) == null ? void 0 : a.columns) ?? []).some((o) => (o == null ? void 0 : o.name) === r)) return null;
1788
+ try {
1789
+ const o = H({ $bind: { ...n, field: r } }, t);
1790
+ return typeof o == "string" && o ? o : null;
1791
+ } catch {
1792
+ return null;
1793
+ }
1794
+ }
1795
+ function da({ block: e }) {
1796
+ var o, l, d;
1797
+ const t = W();
1798
+ Y(t);
1799
+ const n = ((o = e.value) == null ? void 0 : o.$param) ?? (((l = e.on_change) == null ? void 0 : l.type) === "set_param" ? e.on_change.param : null), r = n ? t.params[n] : void 0, i = { ...t.actionCtx, scope: Y(t) }, a = ({ row: c, widgetValue: u }) => mr(e.on_change, i, { row: c, widgetValue: u });
1800
+ if (e.input_type === "select") {
1801
+ const c = (d = e.options) == null ? void 0 : d.$bind, u = c ? t.dataset(c.dataset) : null, h = (u == null ? void 0 : u.rows) ?? [], f = e.option_label_field, k = e.option_value_field ?? f;
1802
+ return /* @__PURE__ */ m("div", { className: "uir-field", children: [
1803
+ /* @__PURE__ */ s("span", { className: "uir-eyebrow", children: e.label }),
1804
+ /* @__PURE__ */ m("div", { className: "uir-select-row", children: [
1805
+ /* @__PURE__ */ m(
1806
+ "select",
1807
+ {
1808
+ "aria-label": e.label,
1809
+ className: "uir-select",
1810
+ value: r ?? "",
1811
+ onChange: (p) => {
1812
+ const y = h.find((v) => String(v[k]) === p.target.value);
1813
+ if (!y) {
1814
+ a({ row: null, widgetValue: null });
1815
+ return;
1816
+ }
1817
+ a({ row: y, widgetValue: y[k] ?? null });
1818
+ },
1819
+ children: [
1820
+ /* @__PURE__ */ s("option", { value: "", children: "All" }),
1821
+ h.map((p, y) => /* @__PURE__ */ s("option", { value: String(p[k]), children: p[f] }, y))
1822
+ ]
1823
+ }
1824
+ ),
1825
+ r != null && r !== "" && /* @__PURE__ */ s("button", { type: "button", className: "uir-select-clear", onClick: () => a({ row: null, widgetValue: null }), children: "Clear" })
1826
+ ] })
1827
+ ] });
1828
+ }
1829
+ return e.input_type === "toggle" ? /* @__PURE__ */ m("div", { className: "uir-toggle", children: [
1830
+ /* @__PURE__ */ s("span", { children: e.label }),
1831
+ /* @__PURE__ */ s(
1832
+ "button",
1833
+ {
1834
+ type: "button",
1835
+ role: "switch",
1836
+ "aria-checked": !!r,
1837
+ "aria-label": e.label,
1838
+ onClick: () => a({ widgetValue: !r }),
1839
+ children: /* @__PURE__ */ s("span", { "aria-hidden": "true" })
1840
+ }
1841
+ )
1842
+ ] }) : /* @__PURE__ */ m("label", { className: "uir-field", children: [
1843
+ /* @__PURE__ */ s("span", { className: "uir-eyebrow", children: e.label }),
1844
+ /* @__PURE__ */ s(
1845
+ "input",
1846
+ {
1847
+ className: "uir-input",
1848
+ type: e.input_type === "date" ? "date" : "text",
1849
+ placeholder: e.placeholder,
1850
+ value: r ?? "",
1851
+ onChange: (c) => a({ widgetValue: c.target.value })
1852
+ }
1853
+ )
1854
+ ] });
1855
+ }
1856
+ function ha({ block: e, emphasis: t }) {
1857
+ var r;
1858
+ const n = W();
1859
+ return /* @__PURE__ */ s("div", { children: /* @__PURE__ */ s(
1860
+ Gt,
1861
+ {
1862
+ action: e.on_click,
1863
+ ctx: { ...n.actionCtx, scope: Y(n) },
1864
+ variant: t === "hero" || t === "primary" ? "solid" : "ghost",
1865
+ fallbackLabel: (r = e.on_click) == null ? void 0 : r.type
1866
+ }
1867
+ ) });
1868
+ }
1869
+ const ma = {
1870
+ table: Cr,
1871
+ list: Mr,
1872
+ detail: Er,
1873
+ timeline: Tr,
1874
+ calendar: Ir,
1875
+ chart: ra,
1876
+ metric: Wr,
1877
+ progress: Jr,
1878
+ badge: Zr,
1879
+ stage_checklist: Xr,
1880
+ text: aa,
1881
+ media: ca,
1882
+ input: da,
1883
+ button: ha
1884
+ }, en = /* @__PURE__ */ new Set(["section", "card", "tabs"]), fa = /* @__PURE__ */ new Set(["metric", "chart", "table", "list", "detail", "timeline", "calendar", "progress", "media"]), pa = { metric: "metric", progress: "value", badge: "value", text: "value", stage_checklist: "value" }, ga = () => typeof window < "u" && typeof window.matchMedia == "function" ? window.matchMedia("(prefers-reduced-motion: reduce)").matches : !1;
1885
+ function tn(e, t = 0) {
1886
+ for (const n of e ?? [])
1887
+ t = en.has(n.type) ? tn(n.children, t) : t + 1;
1888
+ return t;
1889
+ }
1890
+ function ya({
1891
+ page: e,
1892
+ resolve: t,
1893
+ theme: n,
1894
+ params: r,
1895
+ onOpenRecord: i,
1896
+ onNotice: a,
1897
+ confirm: o,
1898
+ now: l,
1899
+ concurrency: d = 2,
1900
+ datasetTimeoutMs: c,
1901
+ /** Inline chat context: same artifact and data semantics, without title/shell chrome. */
1902
+ inline: u = !1,
1903
+ className: h,
1904
+ /**
1905
+ * The minimum time a data-bearing block wears its skeleton before its content is allowed to
1906
+ * paint (design behavior B4: "skeleton-before-content, always"). Instant data is real — but a
1907
+ * tile that skips its skeleton reads as a pop, not an arrival, so the host may ask for a floor.
1908
+ * 0 (the default) keeps today's paint-when-ready behavior; `prefers-reduced-motion` forces 0.
1909
+ */
1910
+ revealDwellMs: f = 0,
1911
+ /**
1912
+ * The host says the page passed Phase 2. Only then does a block draw the design's validation tick:
1913
+ * the renderer does not validate, so a tick it drew unbidden would assert a check nobody ran.
1914
+ */
1915
+ validated: k = !1,
1916
+ /**
1917
+ * `(pageId) => pageDoc | Promise<pageDoc>`. What makes `navigate.mode: "overlay"` executable
1918
+ * (DECISIONS A13): the renderer can PRESENT a page over the one it is drawing, but it cannot
1919
+ * invent the document. Without this, an overlay navigate draws disabled, wearing its reason.
1920
+ *
1921
+ * The host must return a page it has VALIDATED. The overlay renders it exactly as `<UIResponsePage>`
1922
+ * renders anything, and this renderer trusts its input.
1923
+ */
1924
+ resolvePage: p,
1925
+ /**
1926
+ * THE COMMENTARY TRACK. Generation-time narration lines — `[{ after, text, slots }]` — spoken
1927
+ * over the page as it fills in: "The soonest is {title}, {date}." The model PHRASES a line and
1928
+ * POINTS at values with slots (ordinary OBL bindings); it never states one, because it has
1929
+ * never seen a row. Each line paints after the block it narrates, once every slot's dataset is
1930
+ * ready, with the slots resolved and formatted by the same machinery as every block. A slot
1931
+ * that cannot resolve withholds its line — narration understates, never invents. Not part of
1932
+ * the page document: a saved view keeps its data live and its commentary in the past.
1933
+ */
1934
+ narration: y = null,
1935
+ /**
1936
+ * `(settled: boolean) => void` — called with `true` each time the page reaches the state where
1937
+ * every data-bearing block on screen has revealed its content (or settled terminally into an
1938
+ * error), and with `false` when new unrevealed content appears (a streamed document growing,
1939
+ * a refresh). Reported after commit, on transitions only; the mount state is always reported.
1940
+ *
1941
+ * THE SEAM, and why it is this and not dataset events: "revealed" is not "resolved". The dwell
1942
+ * gate holds a tile's content on its skeleton after its rows are already in memory, page-wide,
1943
+ * one per beat — timing only this component knows. A host deriving readiness from its own
1944
+ * `resolve` calls would re-implement that private choreography and drift the first time it
1945
+ * changed. So the renderer reports the FACT (what a viewer can see) and keeps the mechanism;
1946
+ * the host composes rhythm — outros, CTAs, composer re-enable — on top of the fact.
1947
+ */
1948
+ onAllRevealed: v,
1949
+ /** Internal. An overlay does not open an overlay — see the comment on `openOverlay`. */
1950
+ __inOverlay: S = !1
1951
+ }) {
1952
+ const w = E(() => n ? cr(n) : T, [n]), M = E(() => lr(w), [w]), I = E(() => l ?? /* @__PURE__ */ new Date(), [l]), [K, Q] = V(null), [ee, we] = V(null), N = C(null), b = P((_) => new Promise((g) => {
1953
+ var A;
1954
+ (A = N.current) == null || A.call(N, !1), N.current = g, we(_);
1955
+ }), []), $ = P((_) => {
1956
+ const g = N.current;
1957
+ N.current = null, we(null), g == null || g(_);
1958
+ }, []);
1959
+ j(() => () => {
1960
+ var _;
1961
+ return (_ = N.current) == null ? void 0 : _.call(N, !1);
1962
+ }, []);
1963
+ const B = o ?? b, { datasets: x, dataset: te, params: F, setParam: R, refresh: G, blockReady: $e, blockError: at, blockStale: it } = Tn(e, t, { params: r, concurrency: d, timeoutMs: c }), je = E(() => {
1964
+ const _ = Object.values(x);
1965
+ if (!_.length) return null;
1966
+ const g = _.filter((z) => z.status === "ready").length, A = _.filter((z) => z.status === "error").length;
1967
+ return A ? `${A} of ${_.length} datasets failed` : g < _.length ? `Resolving · ${g} of ${_.length} datasets` : `${_.length} ${_.length === 1 ? "dataset" : "datasets"} · live`;
1968
+ }, [x]), st = P((_) => {
1969
+ a == null || a(_), Q(_);
1970
+ }, [a]), [xe, Te] = V(null), ot = C(null), lt = P(async ({ pageId: _, params: g }) => {
1971
+ ot.current = typeof document < "u" ? document.activeElement : null, Te({ pageId: _, params: g, doc: null, error: null });
1972
+ try {
1973
+ const A = await p(_);
1974
+ if (!A) throw new Error(`the host has no page \`${_}\``);
1975
+ Te({ pageId: _, params: g, doc: A, error: null });
1976
+ } catch (A) {
1977
+ Te({ pageId: _, params: g, doc: null, error: A.message });
1978
+ }
1979
+ }, [p]), nn = P(() => Te(null), []), ct = E(() => ({
1980
+ setParam: R,
1981
+ refresh: G,
1982
+ onOpenRecord: i,
1983
+ onNotice: st,
1984
+ confirm: B,
1985
+ resolveValue: H,
1986
+ ...p && !S ? { openOverlay: lt } : null
1987
+ }), [R, G, i, st, B, p, S, lt]), rn = E(() => ({
1988
+ // `pageId` is here for continuity across closes and reopens — the count-up seeds its climb
1989
+ // from the value this page last showed, and a value is only "the same one" per page per block.
1990
+ dataset: te,
1991
+ params: F,
1992
+ now: I,
1993
+ theme: w,
1994
+ actionCtx: ct,
1995
+ row: void 0,
1996
+ pageId: e.id
1997
+ }), [te, F, I, w, ct, e.id]), Ae = E(() => ({ dataset: te, params: F, now: I }), [te, F, I]), Re = f > 0 && !ga() ? f : 0, ut = C(/* @__PURE__ */ new Map()), dt = C(/* @__PURE__ */ new Set()), ht = C(-1 / 0), Pe = C(/* @__PURE__ */ new Map()), [, an] = V(0);
1998
+ j(() => {
1999
+ const _ = Pe.current;
2000
+ return () => {
2001
+ for (const g of _.values()) clearTimeout(g);
2002
+ };
2003
+ }, []);
2004
+ const mt = P((_, g) => {
2005
+ if (!Re || dt.current.has(_)) return !1;
2006
+ const A = Date.now();
2007
+ let z = ut.current.get(_);
2008
+ if (z === void 0 && (z = A, ut.current.set(_, z)), !g) return !1;
2009
+ const ne = Math.max(z + Re, ht.current + Re);
2010
+ return A >= ne ? (dt.current.add(_), ht.current = A, !1) : (Pe.current.has(_) || Pe.current.set(
2011
+ _,
2012
+ setTimeout(() => {
2013
+ Pe.current.delete(_), an((ae) => ae + 1);
2014
+ }, ne - A + 15)
2015
+ ), !0);
2016
+ }, [Re]), He = C(/* @__PURE__ */ new Map()), ft = C(void 0);
2017
+ He.current = /* @__PURE__ */ new Map(), j(() => {
2018
+ if (!v) return;
2019
+ let _ = !0;
2020
+ for (const g of He.current.values())
2021
+ if (!g) {
2022
+ _ = !1;
2023
+ break;
2024
+ }
2025
+ _ !== ft.current && (ft.current = _, v(_));
2026
+ });
2027
+ const pt = E(() => tn(e.blocks) <= 2, [e.blocks]), gt = !E(() => tr(e), [e]) && !S, sn = P(function _(g, A, z = {}) {
2028
+ var bt, vt;
2029
+ const ne = g.emphasis ?? "normal", ae = ue(g).size > 0, ie = !ae || $e(g), he = at(g), Ie = it(g), se = ae && !he && mt(g.id ?? A, ie), J = ie && !se, D = (L, oe) => (He.current.set(String(g.id ?? A), L), oe), O = Rn({ needsData: ae, error: he, dataReady: ie, held: se }), me = On(g, Ae, ie);
2030
+ if (me === "hidden") return D(!0, null);
2031
+ if (me === "pending") return D(O, null);
2032
+ const Z = fa.has(g.type), re = (L, oe) => /* @__PURE__ */ m(
2033
+ "div",
2034
+ {
2035
+ className: "uir-block",
2036
+ "data-block": g.id,
2037
+ "data-type": g.type,
2038
+ "data-emphasis": ne,
2039
+ "data-state": oe,
2040
+ "data-stale": Ie || void 0,
2041
+ "data-tile": Z || void 0,
2042
+ "data-arrived": Z && oe === "ready" && ae || void 0,
2043
+ children: [
2044
+ k && Z && oe === "ready" && /* @__PURE__ */ s(Nr, {}),
2045
+ L
2046
+ ]
2047
+ },
2048
+ A
2049
+ );
2050
+ if (en.has(g.type)) {
2051
+ const L = (oe, on) => _(oe, oe.id ?? on, { hideTitle: g.type === "tabs" });
2052
+ if (g.type === "section") return D(!0, re(/* @__PURE__ */ s(xr, { block: g, renderChild: L, hideTitle: z.hideTitle }), "ready"));
2053
+ if (g.type === "card")
2054
+ return !J && ae ? D(O, re(/* @__PURE__ */ s(Je, { block: g }), "pending")) : D(O, re(/* @__PURE__ */ s(Ar, { block: g, renderChild: L, emphasis: ne }), "ready"));
2055
+ if (g.type === "tabs") return D(!0, re(/* @__PURE__ */ s(Fr, { block: g, renderChild: L }), "ready"));
2056
+ }
2057
+ const wt = ma[g.type];
2058
+ if (!wt)
2059
+ return D(!0, re(/* @__PURE__ */ s(de, { message: `This renderer does not know the block type "${g.type}". It needs a newer renderer.` }), "ready"));
2060
+ if (he)
2061
+ return D(!0, re(/* @__PURE__ */ s(de, { message: he, onRetry: () => G([...ue(g)]) }), "error"));
2062
+ if (!J)
2063
+ return D(O, re(/* @__PURE__ */ s(Je, { variant: pa[g.type] ?? "bars", block: g }), "pending"));
2064
+ if ((vt = (bt = g.value) == null ? void 0 : bt.$bind) != null && vt.empty && Wn(g.value.$bind.empty)) {
2065
+ const L = H(g.value, Ae);
2066
+ if (L == null) return D(!0, null);
2067
+ }
2068
+ try {
2069
+ return D(O, re(/* @__PURE__ */ s(wt, { block: g, emphasis: ne }), "ready"));
2070
+ } catch (L) {
2071
+ return D(!0, re(/* @__PURE__ */ s(de, { message: L.message }), "error"));
2072
+ }
2073
+ }, [$e, at, it, Ae, G, k, mt]), yt = E(() => {
2074
+ const _ = /* @__PURE__ */ new Map();
2075
+ for (const g of y ?? []) {
2076
+ if (!g || typeof g.text != "string") continue;
2077
+ const A = typeof g.after == "string" ? g.after : "__end__";
2078
+ _.has(A) || _.set(A, []), _.get(A).push(g);
2079
+ }
2080
+ return _;
2081
+ }, [y]), _t = P((_) => {
2082
+ const g = yt.get(_);
2083
+ return g != null && g.length ? g.map((A, z) => {
2084
+ var he, Ie;
2085
+ const ne = Object.keys(A.slots ?? {});
2086
+ if (ne.some((se) => {
2087
+ var D, O, me, Z;
2088
+ const J = ((O = (D = A.slots[se]) == null ? void 0 : D.$bind) == null ? void 0 : O.dataset) ?? ((me = A.slots[se]) == null ? void 0 : me.dataset);
2089
+ return J && ((Z = x[J]) == null ? void 0 : Z.status) !== "ready";
2090
+ })) return null;
2091
+ let ie = A.text;
2092
+ try {
2093
+ for (const se of ne) {
2094
+ const J = A.slots[se], D = (J == null ? void 0 : J.$bind) ?? J, O = H({ $bind: D }, Ae);
2095
+ if (O == null || O === "") throw new Error("empty slot");
2096
+ const me = (Ie = (he = (e.data ?? []).find((Z) => Z.name === D.dataset)) == null ? void 0 : he.columns) == null ? void 0 : Ie.find((Z) => Z.name === D.field);
2097
+ ie = ie.split(`{${se}}`).join(q(O, D.format, { column: me, now: I }));
2098
+ }
2099
+ } catch {
2100
+ return null;
2101
+ }
2102
+ return /* @__PURE__ */ s("p", { className: "uir-narration", children: ie }, `narr-${_}-${z}`);
2103
+ }) : null;
2104
+ }, [yt, x, Ae, e, I]);
2105
+ return /* @__PURE__ */ s(Xe.Provider, { value: rn, children: /* @__PURE__ */ m(
2106
+ "div",
2107
+ {
2108
+ className: ["uir-page", u ? "uir-page--inline" : null, h].filter(Boolean).join(" "),
2109
+ style: M,
2110
+ "aria-label": u ? e.title : void 0,
2111
+ children: [
2112
+ /* @__PURE__ */ m("div", { className: "uir-shell", children: [
2113
+ !u && /* @__PURE__ */ m("header", { className: "uir-header", "data-minimal": pt || void 0, children: [
2114
+ /* @__PURE__ */ m("div", { className: "uir-header__line", children: [
2115
+ gt && /* @__PURE__ */ s("h1", { className: "uir-header__title", children: e.title }),
2116
+ je && /* @__PURE__ */ s("span", { className: "uir-header__status", "data-settled": je.endsWith("live") || void 0, children: je })
2117
+ ] }),
2118
+ e.subtitle && !pt && gt && /* @__PURE__ */ s("p", { className: "uir-header__subtitle", children: e.subtitle })
2119
+ ] }),
2120
+ e.blocks.map((_, g) => /* @__PURE__ */ m(ln.Fragment, { children: [
2121
+ sn(_, _.id ?? g),
2122
+ _t(_.id)
2123
+ ] }, `f-${_.id ?? g}`)),
2124
+ _t("__end__"),
2125
+ K && /* @__PURE__ */ m("div", { className: "uir-notice", role: "status", children: [
2126
+ /* @__PURE__ */ s("button", { type: "button", className: "uir-notice__close", onClick: () => Q(null), "aria-label": "Dismiss", children: "×" }),
2127
+ K
2128
+ ] })
2129
+ ] }),
2130
+ xe && /* @__PURE__ */ s(_a, { overlay: xe, onClose: nn, returnFocusTo: ot, children: xe.doc && /* @__PURE__ */ s(
2131
+ ya,
2132
+ {
2133
+ page: xe.doc,
2134
+ resolve: t,
2135
+ theme: n,
2136
+ params: Pn(r, xe.params),
2137
+ onOpenRecord: i,
2138
+ onNotice: a,
2139
+ confirm: o,
2140
+ now: l,
2141
+ validated: k,
2142
+ revealDwellMs: f,
2143
+ className: "uir-page--nested",
2144
+ __inOverlay: !0
2145
+ }
2146
+ ) }),
2147
+ ee && /* @__PURE__ */ s(kr, { prompt: ee, onResolve: $ })
2148
+ ]
2149
+ }
2150
+ ) });
2151
+ }
2152
+ function _a({ overlay: e, onClose: t, returnFocusTo: n, children: r }) {
2153
+ var a, o;
2154
+ const i = C(null);
2155
+ return j(() => {
2156
+ var d;
2157
+ (d = i.current) == null || d.focus();
2158
+ const l = (c) => {
2159
+ c.key === "Escape" && (c.stopPropagation(), t());
2160
+ };
2161
+ return document.addEventListener("keydown", l), () => {
2162
+ document.removeEventListener("keydown", l);
2163
+ const c = n == null ? void 0 : n.current;
2164
+ c && c !== document.body && c.isConnected && c.focus();
2165
+ };
2166
+ }, [t]), /* @__PURE__ */ m("div", { className: "uir-overlay", role: "dialog", "aria-modal": "true", "aria-label": ((a = e.doc) == null ? void 0 : a.title) ?? "Loading", children: [
2167
+ /* @__PURE__ */ s("div", { className: "uir-overlay__scrim", onClick: t }),
2168
+ /* @__PURE__ */ m("div", { className: "uir-overlay__panel", ref: i, tabIndex: -1, children: [
2169
+ /* @__PURE__ */ m("div", { className: "uir-overlay__head", children: [
2170
+ /* @__PURE__ */ s("span", { className: "uir-overlay__title", children: ((o = e.doc) == null ? void 0 : o.title) ?? e.pageId }),
2171
+ /* @__PURE__ */ s("button", { type: "button", className: "uir-overlay__close", onClick: t, "aria-label": "Close", children: /* @__PURE__ */ m("svg", { width: "9", height: "9", viewBox: "0 0 9 9", "aria-hidden": "true", children: [
2172
+ /* @__PURE__ */ s("line", { x1: "1", y1: "1", x2: "8", y2: "8" }),
2173
+ /* @__PURE__ */ s("line", { x1: "8", y1: "1", x2: "1", y2: "8" })
2174
+ ] }) })
2175
+ ] }),
2176
+ /* @__PURE__ */ s("div", { className: "uir-overlay__body", children: e.error ? /* @__PURE__ */ s(de, { message: `Could not present \`${e.pageId}\`: ${e.error}` }) : e.doc ? r : /* @__PURE__ */ s(Je, {}) })
2177
+ ] })
2178
+ ] });
2179
+ }
2180
+ export {
2181
+ We as DISABLED_VERBS,
2182
+ ka as EMPHASIS_RANK,
2183
+ fr as TABLE_PAGE_SIZE,
2184
+ ya as UIResponsePage,
2185
+ Qe as actionGate,
2186
+ kn as aggregate,
2187
+ _n as bindingArity,
2188
+ ue as collectDatasets,
2189
+ Ke as collectParams,
2190
+ qt as darkTheme,
2191
+ ya as default,
2192
+ T as defaultTheme,
2193
+ Gn as emptyRender,
2194
+ Ce as evaluateCondition,
2195
+ Fn as flattenBlocks,
2196
+ Ft as formatAudioTime,
2197
+ q as formatValue,
2198
+ Wn as hidesBlock,
2199
+ pr as initialsFor,
2200
+ wr as isDestructiveAction,
2201
+ $a as isDisabledVerb,
2202
+ ke as isEmptyValue,
2203
+ qn as isNumericFormat,
2204
+ cr as makeTheme,
2205
+ Pn as overlayParams,
2206
+ gr as paginateRows,
2207
+ Sn as planDatasetOrder,
2208
+ Ve as resolveBinding,
2209
+ H as resolveValue,
2210
+ lr as themeToCssVars,
2211
+ _r as timelineLayout,
2212
+ dr as verbReason
2213
+ };