@jirathip-dev/blocks 0.0.0 → 2.2.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.
- package/LICENSE +21 -0
- package/README.md +68 -0
- package/package.json +48 -1
- package/web/dist/blocks.css +1 -0
- package/web/dist/blocks.js +10 -0
- package/web/dist/blocks.scoped.css +1 -0
- package/web/dist/core.js +9749 -0
- package/web/dist/import.js +2 -0
- package/web/dist/react.js +4073 -0
- package/web/dist/scan.js +22 -0
- package/web/dist/types/react/src/act.d.ts +71 -0
- package/web/dist/types/react/src/arrange.d.ts +10 -0
- package/web/dist/types/react/src/block.d.ts +41 -0
- package/web/dist/types/react/src/draw.d.ts +34 -0
- package/web/dist/types/react/src/fields/_input.d.ts +16 -0
- package/web/dist/types/react/src/fields/_view.d.ts +27 -0
- package/web/dist/types/react/src/fields/picker.d.ts +3 -0
- package/web/dist/types/react/src/fields/scan.d.ts +3 -0
- package/web/dist/types/react/src/fields/search.d.ts +14 -0
- package/web/dist/types/react/src/fields/secret.d.ts +3 -0
- package/web/dist/types/react/src/fields/slider.d.ts +5 -0
- package/web/dist/types/react/src/fields/text.d.ts +3 -0
- package/web/dist/types/react/src/fields/toggle.d.ts +3 -0
- package/web/dist/types/react/src/fields/upload.d.ts +7 -0
- package/web/dist/types/react/src/gen/fields.d.ts +2 -0
- package/web/dist/types/react/src/gen/views.d.ts +2 -0
- package/web/dist/types/react/src/h.d.ts +7 -0
- package/web/dist/types/react/src/index.d.ts +3 -0
- package/web/dist/types/react/src/island.d.ts +7 -0
- package/web/dist/types/react/src/kinds/button.d.ts +5 -0
- package/web/dist/types/react/src/kinds/card.d.ts +5 -0
- package/web/dist/types/react/src/kinds/chips.d.ts +5 -0
- package/web/dist/types/react/src/kinds/choice.d.ts +5 -0
- package/web/dist/types/react/src/kinds/composer.d.ts +5 -0
- package/web/dist/types/react/src/kinds/config.d.ts +5 -0
- package/web/dist/types/react/src/kinds/diagram.d.ts +7 -0
- package/web/dist/types/react/src/kinds/diff.d.ts +7 -0
- package/web/dist/types/react/src/kinds/editor.d.ts +5 -0
- package/web/dist/types/react/src/kinds/form.d.ts +22 -0
- package/web/dist/types/react/src/kinds/hero.d.ts +5 -0
- package/web/dist/types/react/src/kinds/images.d.ts +5 -0
- package/web/dist/types/react/src/kinds/import.d.ts +5 -0
- package/web/dist/types/react/src/kinds/list.d.ts +6 -0
- package/web/dist/types/react/src/kinds/media.d.ts +6 -0
- package/web/dist/types/react/src/kinds/message.d.ts +5 -0
- package/web/dist/types/react/src/kinds/modal.d.ts +5 -0
- package/web/dist/types/react/src/kinds/nav.d.ts +5 -0
- package/web/dist/types/react/src/kinds/pages.d.ts +5 -0
- package/web/dist/types/react/src/kinds/prose.d.ts +5 -0
- package/web/dist/types/react/src/kinds/row.d.ts +5 -0
- package/web/dist/types/react/src/kinds/run.d.ts +5 -0
- package/web/dist/types/react/src/kinds/scene.d.ts +5 -0
- package/web/dist/types/react/src/kinds/screen.d.ts +5 -0
- package/web/dist/types/react/src/kinds/secret.d.ts +5 -0
- package/web/dist/types/react/src/kinds/section.d.ts +5 -0
- package/web/dist/types/react/src/kinds/sheet.d.ts +1 -0
- package/web/dist/types/react/src/kinds/sidebar.d.ts +5 -0
- package/web/dist/types/react/src/kinds/stat.d.ts +5 -0
- package/web/dist/types/react/src/kinds/steps.d.ts +7 -0
- package/web/dist/types/react/src/kinds/table.d.ts +5 -0
- package/web/dist/types/react/src/kinds/text.d.ts +5 -0
- package/web/dist/types/react/src/kinds/timeline.d.ts +5 -0
- package/web/dist/types/react/src/kinds/tool.d.ts +5 -0
- package/web/dist/types/react/src/kinds/web.d.ts +5 -0
- package/web/dist/types/react/src/view.d.ts +14 -0
- package/web/dist/types/src/arrange.d.ts +8 -0
- package/web/dist/types/src/behave.d.ts +1 -0
- package/web/dist/types/src/core/apply.d.ts +7 -0
- package/web/dist/types/src/core/built.d.ts +7 -0
- package/web/dist/types/src/core/check.d.ts +5 -0
- package/web/dist/types/src/core/code.d.ts +7 -0
- package/web/dist/types/src/core/eval.d.ts +25 -0
- package/web/dist/types/src/core/field/files.d.ts +53 -0
- package/web/dist/types/src/core/field/match.d.ts +15 -0
- package/web/dist/types/src/core/field/slider.d.ts +3 -0
- package/web/dist/types/src/core/gate.d.ts +7 -0
- package/web/dist/types/src/core/gesture.d.ts +53 -0
- package/web/dist/types/src/core/index.d.ts +21 -0
- package/web/dist/types/src/core/kind/boxplot.d.ts +7 -0
- package/web/dist/types/src/core/kind/chart.d.ts +18 -0
- package/web/dist/types/src/core/kind/diagram.d.ts +44 -0
- package/web/dist/types/src/core/kind/import.d.ts +40 -0
- package/web/dist/types/src/core/kind/list.d.ts +3 -0
- package/web/dist/types/src/core/kind/media.d.ts +36 -0
- package/web/dist/types/src/core/kind/message.d.ts +4 -0
- package/web/dist/types/src/core/kind/modal.d.ts +23 -0
- package/web/dist/types/src/core/kind/plot.d.ts +22 -0
- package/web/dist/types/src/core/kind/prose.d.ts +5 -0
- package/web/dist/types/src/core/kind/sidebar.d.ts +7 -0
- package/web/dist/types/src/core/kind/table.d.ts +26 -0
- package/web/dist/types/src/core/kind/timeline.d.ts +28 -0
- package/web/dist/types/src/core/layout.d.ts +9 -0
- package/web/dist/types/src/core/look.d.ts +11 -0
- package/web/dist/types/src/core/nonce.d.ts +1 -0
- package/web/dist/types/src/core/share.d.ts +1 -0
- package/web/dist/types/src/core/table.d.ts +6 -0
- package/web/dist/types/src/core/text.d.ts +6 -0
- package/web/dist/types/src/core/tree.d.ts +12 -0
- package/web/dist/types/src/dump.d.ts +2 -0
- package/web/dist/types/src/edits.d.ts +18 -0
- package/web/dist/types/src/gen/builders.d.ts +64 -0
- package/web/dist/types/src/gen/fields.d.ts +2 -0
- package/web/dist/types/src/gen/hooks.d.ts +11 -0
- package/web/dist/types/src/gen/kinds.d.ts +9 -0
- package/web/dist/types/src/gen/layout.d.ts +19 -0
- package/web/dist/types/src/gen/schemes.d.ts +73 -0
- package/web/dist/types/src/gen/shapes.d.ts +61 -0
- package/web/dist/types/src/gen/types.d.ts +1517 -0
- package/web/dist/types/src/gen/words-import.d.ts +1 -0
- package/web/dist/types/src/gen/words.d.ts +1 -0
- package/web/dist/types/src/gesture.d.ts +54 -0
- package/web/dist/types/src/island.d.ts +3 -0
- package/web/dist/types/src/lazy/import.d.ts +13 -0
- package/web/dist/types/src/modal.d.ts +14 -0
- package/web/dist/types/src/motion.d.ts +2 -0
- package/web/dist/types/src/paging.d.ts +2 -0
- package/web/dist/types/src/patch.d.ts +17 -0
- package/web/dist/types/src/render/act.d.ts +9 -0
- package/web/dist/types/src/render/block.d.ts +5 -0
- package/web/dist/types/src/render/ctx.d.ts +34 -0
- package/web/dist/types/src/render/dom.d.ts +16 -0
- package/web/dist/types/src/render/field/_input.d.ts +3 -0
- package/web/dist/types/src/render/field/_view.d.ts +26 -0
- package/web/dist/types/src/render/field/picker.d.ts +3 -0
- package/web/dist/types/src/render/field/scan.d.ts +3 -0
- package/web/dist/types/src/render/field/search.d.ts +5 -0
- package/web/dist/types/src/render/field/secret.d.ts +3 -0
- package/web/dist/types/src/render/field/slider.d.ts +5 -0
- package/web/dist/types/src/render/field/text.d.ts +3 -0
- package/web/dist/types/src/render/field/toggle.d.ts +3 -0
- package/web/dist/types/src/render/field/upload.d.ts +5 -0
- package/web/dist/types/src/render/kind/boxplot.d.ts +3 -0
- package/web/dist/types/src/render/kind/button.d.ts +3 -0
- package/web/dist/types/src/render/kind/card.d.ts +3 -0
- package/web/dist/types/src/render/kind/chart.d.ts +4 -0
- package/web/dist/types/src/render/kind/chips.d.ts +3 -0
- package/web/dist/types/src/render/kind/choice.d.ts +3 -0
- package/web/dist/types/src/render/kind/composer.d.ts +3 -0
- package/web/dist/types/src/render/kind/config.d.ts +3 -0
- package/web/dist/types/src/render/kind/diagram.d.ts +3 -0
- package/web/dist/types/src/render/kind/diff.d.ts +3 -0
- package/web/dist/types/src/render/kind/editor.d.ts +3 -0
- package/web/dist/types/src/render/kind/form.d.ts +14 -0
- package/web/dist/types/src/render/kind/heat.d.ts +3 -0
- package/web/dist/types/src/render/kind/hero.d.ts +3 -0
- package/web/dist/types/src/render/kind/images.d.ts +3 -0
- package/web/dist/types/src/render/kind/import.d.ts +3 -0
- package/web/dist/types/src/render/kind/island.d.ts +3 -0
- package/web/dist/types/src/render/kind/lines.d.ts +5 -0
- package/web/dist/types/src/render/kind/list.d.ts +3 -0
- package/web/dist/types/src/render/kind/media.d.ts +4 -0
- package/web/dist/types/src/render/kind/message.d.ts +3 -0
- package/web/dist/types/src/render/kind/modal.d.ts +9 -0
- package/web/dist/types/src/render/kind/nav.d.ts +2 -0
- package/web/dist/types/src/render/kind/pages.d.ts +2 -0
- package/web/dist/types/src/render/kind/plot.d.ts +3 -0
- package/web/dist/types/src/render/kind/prose.d.ts +4 -0
- package/web/dist/types/src/render/kind/row.d.ts +3 -0
- package/web/dist/types/src/render/kind/run.d.ts +3 -0
- package/web/dist/types/src/render/kind/scene.d.ts +3 -0
- package/web/dist/types/src/render/kind/screen.d.ts +3 -0
- package/web/dist/types/src/render/kind/secret.d.ts +3 -0
- package/web/dist/types/src/render/kind/section.d.ts +3 -0
- package/web/dist/types/src/render/kind/sheet.d.ts +1 -0
- package/web/dist/types/src/render/kind/sidebar.d.ts +3 -0
- package/web/dist/types/src/render/kind/stat.d.ts +2 -0
- package/web/dist/types/src/render/kind/steps.d.ts +3 -0
- package/web/dist/types/src/render/kind/table.d.ts +3 -0
- package/web/dist/types/src/render/kind/text.d.ts +3 -0
- package/web/dist/types/src/render/kind/timeline.d.ts +3 -0
- package/web/dist/types/src/render/kind/toast.d.ts +4 -0
- package/web/dist/types/src/render/kind/tool.d.ts +3 -0
- package/web/dist/types/src/render/kind/web.d.ts +2 -0
- package/web/dist/types/src/render/more.d.ts +11 -0
- package/web/dist/types/src/render/text.d.ts +5 -0
- package/web/dist/types/src/scan/index.d.ts +26 -0
- package/web/dist/types/src/scan/page.d.ts +18 -0
- package/web/dist/types/src/shell/adopt.d.ts +8 -0
- package/web/dist/types/src/shell/host.d.ts +30 -0
- package/web/dist/types/src/shell/layout.d.ts +29 -0
- package/web/dist/types/src/shell/local.d.ts +10 -0
- package/web/dist/types/src/shell/look.d.ts +15 -0
- package/web/dist/types/src/shell/mount.d.ts +34 -0
- package/web/dist/types/src/shell/sheet.d.ts +17 -0
- package/web/dist/types/src/shell/source.d.ts +12 -0
- package/web/dist/types/src/shell/store.d.ts +2 -0
- package/web/dist/types/src/shell.d.ts +26 -0
- package/web/dist/types/src/sidebar.d.ts +2 -0
- package/web/dist/types/src/stream.d.ts +28 -0
- package/web/dist/types/src/theme.d.ts +24 -0
- package/web/dist/types/src/toasts.d.ts +7 -0
|
@@ -0,0 +1,4073 @@
|
|
|
1
|
+
// react/src/arrange.ts
|
|
2
|
+
import { useLayoutEffect, useRef, useState } from "react";
|
|
3
|
+
|
|
4
|
+
// src/core/gesture.ts
|
|
5
|
+
var same = (a, b) => JSON.stringify(a) === JSON.stringify(b);
|
|
6
|
+
function step(p, e, start2) {
|
|
7
|
+
const live3 = p.at === "pressed" || p.at === "dragging" || p.at === "previewing";
|
|
8
|
+
if (p.at === "idle" && e.on === "press") return [{ at: "pressed" }, null];
|
|
9
|
+
if (p.at === "pressed" && e.on === "release") return [{ at: "idle" }, "tap"];
|
|
10
|
+
if (live3 && e.on === "move") return e.c == null ? [{ at: "dragging" }, null] : [{ at: "previewing", c: e.c }, null];
|
|
11
|
+
if (live3 && e.on === "cancel" || p.at === "dragging" && e.on === "release") return [{ at: "idle" }, null];
|
|
12
|
+
if (p.at === "previewing" && e.on === "release") return same(p.c, start2) ? [{ at: "idle" }, null] : [{ at: "sent", c: p.c }, { send: p.c }];
|
|
13
|
+
if (p.at === "sent" && e.on === "answer") return e.ok ? [{ at: "confirmed" }, null] : [{ at: "refused", why: e.why ?? "" }, null];
|
|
14
|
+
if ((p.at === "confirmed" || p.at === "refused") && e.on === "settled") return [{ at: "idle" }, null];
|
|
15
|
+
return [p, null];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// src/core/layout.ts
|
|
19
|
+
var MAX_DEPTH = 6;
|
|
20
|
+
var kids = (n) => Object.values(n.slots ?? {}).flat();
|
|
21
|
+
var height = (n) => 1 + Math.max(0, ...kids(n).map(height));
|
|
22
|
+
var move = (id, into, slot, before2) => ({ edit: "move", id, into, slot, before: before2 });
|
|
23
|
+
function path(n, id) {
|
|
24
|
+
if (n.id === id) return [n.id];
|
|
25
|
+
for (const k of kids(n)) {
|
|
26
|
+
const p = path(k, id);
|
|
27
|
+
if (p) return [n.id, ...p];
|
|
28
|
+
}
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
function stay(n, grabbed) {
|
|
32
|
+
for (const [slot, list3] of Object.entries(n.slots ?? {})) {
|
|
33
|
+
const i = list3.findIndex((k) => k.id === grabbed);
|
|
34
|
+
if (i >= 0) return move(grabbed, n.id, slot, list3[i + 1]?.id ?? null);
|
|
35
|
+
}
|
|
36
|
+
for (const k of kids(n)) {
|
|
37
|
+
const s = stay(k, grabbed);
|
|
38
|
+
if (s) return s;
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
function places(tree, slots, grabbed) {
|
|
43
|
+
const at2 = path(tree, grabbed);
|
|
44
|
+
const g = at2 && at2.length > 1 ? walkTo(tree, grabbed) : void 0;
|
|
45
|
+
if (!at2 || !g) return [];
|
|
46
|
+
const [h3, depth, above] = [height(g), at2.length, at2.slice(0, -1)];
|
|
47
|
+
const out2 = [];
|
|
48
|
+
const walk = (host, d2) => {
|
|
49
|
+
if (host.type === "screen") return;
|
|
50
|
+
const fits2 = d2 + h3 <= MAX_DEPTH;
|
|
51
|
+
for (const slot of [...slots[host.type] ?? []].sort()) {
|
|
52
|
+
for (const k of host.slots?.[slot] ?? []) {
|
|
53
|
+
if (k.id === grabbed) continue;
|
|
54
|
+
if (fits2) out2.push(move(grabbed, host.id, slot, k.id));
|
|
55
|
+
if (fits2 && !above.includes(k.id) && depth + height(k) <= MAX_DEPTH + 1) out2.push({ edit: "swap", a: grabbed, b: k.id });
|
|
56
|
+
walk(k, d2 + 1);
|
|
57
|
+
}
|
|
58
|
+
if (fits2) out2.push(move(grabbed, host.id, slot, null));
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
walk(tree, 1);
|
|
62
|
+
return out2;
|
|
63
|
+
}
|
|
64
|
+
function walkTo(n, id) {
|
|
65
|
+
if (n.id === id) return n;
|
|
66
|
+
for (const k of kids(n)) {
|
|
67
|
+
const f = walkTo(k, id);
|
|
68
|
+
if (f) return f;
|
|
69
|
+
}
|
|
70
|
+
return void 0;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// src/gesture.ts
|
|
74
|
+
var ARROWS = { ArrowLeft: "left", ArrowRight: "right", ArrowUp: "up", ArrowDown: "down" };
|
|
75
|
+
var key = (b, item3) => `${b.id ?? ""}
|
|
76
|
+
${item3}`;
|
|
77
|
+
var speaker;
|
|
78
|
+
function say(text4) {
|
|
79
|
+
if (!speaker?.isConnected) {
|
|
80
|
+
speaker = Object.assign(document.createElement("div"), { className: "b-sr" });
|
|
81
|
+
speaker.setAttribute("aria-live", "polite");
|
|
82
|
+
document.body.append(speaker);
|
|
83
|
+
}
|
|
84
|
+
speaker.textContent = text4;
|
|
85
|
+
}
|
|
86
|
+
var beside = (el2, steps2, run2) => el2.parentElement?.append(
|
|
87
|
+
...steps2.map(([name, n]) => {
|
|
88
|
+
const b = Object.assign(document.createElement("button"), { type: "button", className: "b-sr", tabIndex: -1, textContent: name });
|
|
89
|
+
b.onclick = () => run2(n);
|
|
90
|
+
return b;
|
|
91
|
+
})
|
|
92
|
+
);
|
|
93
|
+
function held(c, o) {
|
|
94
|
+
const h3 = c.held?.get(key(o.block, o.item));
|
|
95
|
+
return h3 && same(h3.start, o.rules.start(o.block, o.grab)) ? h3.c : void 0;
|
|
96
|
+
}
|
|
97
|
+
function gestured(el2, c, o) {
|
|
98
|
+
const start2 = o.rules.word(o.block, o.grab) ? o.rules.start(o.block, o.grab) : null;
|
|
99
|
+
if (start2 === null) return () => {
|
|
100
|
+
};
|
|
101
|
+
const k = key(o.block, o.item);
|
|
102
|
+
el2.dataset["grab"] = JSON.stringify(o.grab);
|
|
103
|
+
const out2 = c.held?.get(k);
|
|
104
|
+
let p = out2 ? { at: "sent", c: start2 } : { at: "idle" };
|
|
105
|
+
let x0 = 0;
|
|
106
|
+
let y0 = 0;
|
|
107
|
+
const mark2 = () => {
|
|
108
|
+
el2.dataset["phase"] = p.at;
|
|
109
|
+
el2.setAttribute("aria-pressed", String(p.at === "pressed" || p.at === "dragging" || p.at === "previewing"));
|
|
110
|
+
};
|
|
111
|
+
const back = (ok) => {
|
|
112
|
+
go2({ on: "answer", ok });
|
|
113
|
+
go2({ on: "settled" });
|
|
114
|
+
};
|
|
115
|
+
if (out2) out2.back = back;
|
|
116
|
+
const send4 = async (cand) => {
|
|
117
|
+
const h3 = { start: start2, c: cand, back };
|
|
118
|
+
c.held?.set(k, h3);
|
|
119
|
+
say("sending");
|
|
120
|
+
const ok = await c.act({ action: o.gesture.action, block: o.block.id, values: { [o.gesture.name]: cand } }, el2).catch(() => false);
|
|
121
|
+
c.held?.delete(k);
|
|
122
|
+
h3.back(ok);
|
|
123
|
+
say(ok ? o.rules.says(o.block, o.grab, cand) : "not changed");
|
|
124
|
+
};
|
|
125
|
+
const go2 = (e) => {
|
|
126
|
+
const [next, fx] = step(p, e, start2);
|
|
127
|
+
if (next.at === p.at && e.on !== "move") return;
|
|
128
|
+
p = next;
|
|
129
|
+
mark2();
|
|
130
|
+
if (p.at === "previewing") o.show(p.c);
|
|
131
|
+
if (p.at === "idle" || p.at === "dragging") o.show(null);
|
|
132
|
+
if (p.at === "pressed") say(`${el2.getAttribute("aria-label") ?? ""}, grabbed, ${o.rules.says(o.block, o.grab, start2)}. Arrows move, Enter drops, Escape cancels`);
|
|
133
|
+
if (p.at === "dragging") say("no drop here");
|
|
134
|
+
if (p.at === "previewing") say(o.rules.says(o.block, o.grab, p.c));
|
|
135
|
+
if (fx && fx !== "tap") void send4(fx.send);
|
|
136
|
+
};
|
|
137
|
+
const phase = () => p.at;
|
|
138
|
+
const live3 = () => p.at === "pressed" || p.at === "dragging" || p.at === "previewing";
|
|
139
|
+
const nudge = (n) => {
|
|
140
|
+
const next = o.rules.nudge(o.block, o.grab, p.at === "previewing" ? p.c : start2, n);
|
|
141
|
+
if (next !== null) go2({ on: "move", c: next });
|
|
142
|
+
};
|
|
143
|
+
el2.style.touchAction = "none";
|
|
144
|
+
el2.addEventListener("pointerdown", (e) => {
|
|
145
|
+
if (p.at !== "idle" || e.button !== 0) return;
|
|
146
|
+
el2.setPointerCapture(e.pointerId);
|
|
147
|
+
[x0, y0] = [e.clientX, e.clientY];
|
|
148
|
+
go2({ on: "press" });
|
|
149
|
+
});
|
|
150
|
+
el2.addEventListener("pointermove", (e) => {
|
|
151
|
+
const [dx, dy] = [e.clientX - x0, e.clientY - y0];
|
|
152
|
+
if (live3() && (p.at !== "pressed" || Math.hypot(dx, dy) >= 4)) go2({ on: "move", c: o.rules.candidate(o.block, o.grab, o.reach(dx, dy, x0, y0)) });
|
|
153
|
+
});
|
|
154
|
+
el2.addEventListener("pointerup", () => live3() && go2({ on: "release" }));
|
|
155
|
+
el2.addEventListener("pointercancel", () => go2({ on: "cancel" }));
|
|
156
|
+
el2.addEventListener("blur", () => go2({ on: "cancel" }));
|
|
157
|
+
el2.addEventListener("keydown", (e) => {
|
|
158
|
+
const dir = ARROWS[e.key];
|
|
159
|
+
if (p.at === "idle" && e.key === " ") go2({ on: "press" });
|
|
160
|
+
else if (!live3()) return;
|
|
161
|
+
else if (dir) nudge({ dir, big: e.shiftKey });
|
|
162
|
+
else if (e.key === "Enter" || e.key === " ") go2({ on: p.at === "pressed" ? "cancel" : "release" });
|
|
163
|
+
else if (e.key === "Escape") go2({ on: "cancel" });
|
|
164
|
+
else return;
|
|
165
|
+
e.preventDefault();
|
|
166
|
+
});
|
|
167
|
+
const run2 = (n) => {
|
|
168
|
+
if (p.at !== "idle") return;
|
|
169
|
+
go2({ on: "press" });
|
|
170
|
+
nudge(n);
|
|
171
|
+
go2({ on: phase() === "pressed" ? "cancel" : "release" });
|
|
172
|
+
};
|
|
173
|
+
beside(el2, o.rules.steps(o.block, o.grab), run2);
|
|
174
|
+
mark2();
|
|
175
|
+
return run2;
|
|
176
|
+
}
|
|
177
|
+
function zoomed(el2, keep, o) {
|
|
178
|
+
const at2 = /* @__PURE__ */ new Map();
|
|
179
|
+
const z = () => typeof keep["zoom"] === "number" ? keep["zoom"] : o.min;
|
|
180
|
+
const to = (k, live3 = false) => o.apply(keep["zoom"] = Math.min(o.max, Math.max(o.min, k)), live3);
|
|
181
|
+
const span2 = () => {
|
|
182
|
+
const [a, b] = [...at2.values()];
|
|
183
|
+
return a && b ? Math.hypot(a[0] - b[0], a[1] - b[1]) : 0;
|
|
184
|
+
};
|
|
185
|
+
let d0 = 0;
|
|
186
|
+
let z0 = 1;
|
|
187
|
+
el2.style.touchAction = "none";
|
|
188
|
+
el2.addEventListener("pointerdown", (e) => {
|
|
189
|
+
at2.set(e.pointerId, [e.clientX, e.clientY]);
|
|
190
|
+
if (at2.size === 2) [d0, z0] = [span2(), z()];
|
|
191
|
+
});
|
|
192
|
+
el2.addEventListener("pointermove", (e) => {
|
|
193
|
+
if (!at2.has(e.pointerId)) return;
|
|
194
|
+
at2.set(e.pointerId, [e.clientX, e.clientY]);
|
|
195
|
+
if (at2.size === 2 && d0) to(z0 * span2() / d0, true);
|
|
196
|
+
});
|
|
197
|
+
const up = (e) => {
|
|
198
|
+
at2.delete(e.pointerId);
|
|
199
|
+
if (at2.size < 2 && d0) to(z());
|
|
200
|
+
if (at2.size < 2) d0 = 0;
|
|
201
|
+
};
|
|
202
|
+
let still2;
|
|
203
|
+
el2.addEventListener("pointerup", up);
|
|
204
|
+
el2.addEventListener("pointercancel", up);
|
|
205
|
+
const wheel = (e) => {
|
|
206
|
+
if (!e.ctrlKey) return;
|
|
207
|
+
e.preventDefault();
|
|
208
|
+
to(z() * Math.exp(-e.deltaY / 100), true);
|
|
209
|
+
clearTimeout(still2);
|
|
210
|
+
still2 = setTimeout(() => to(z()), 150);
|
|
211
|
+
};
|
|
212
|
+
el2.addEventListener("wheel", wheel, { passive: false });
|
|
213
|
+
el2.addEventListener("dblclick", () => to(z() > o.min ? o.min : 2.5));
|
|
214
|
+
el2.addEventListener("keydown", (e) => {
|
|
215
|
+
const k = { "+": z() * 1.25, "=": z() * 1.25, "-": z() / 1.25, "0": o.min };
|
|
216
|
+
if (k[e.key] === void 0) return;
|
|
217
|
+
e.preventDefault();
|
|
218
|
+
to(k[e.key] ?? o.min);
|
|
219
|
+
});
|
|
220
|
+
to(z());
|
|
221
|
+
}
|
|
222
|
+
function edited(input3, c, o) {
|
|
223
|
+
const start2 = o.rules.word(o.block, o.grab) ? o.rules.start(o.block, o.grab) : null;
|
|
224
|
+
if (start2 === null) return;
|
|
225
|
+
const k = key(o.block, o.item);
|
|
226
|
+
let p = { at: "idle" };
|
|
227
|
+
let gone2 = false;
|
|
228
|
+
const go2 = (e) => {
|
|
229
|
+
const [next, fx] = step(p, e, start2);
|
|
230
|
+
p = next;
|
|
231
|
+
o.show(p.at, p.at === "previewing" ? p.c : null);
|
|
232
|
+
if (!fx || fx === "tap") return;
|
|
233
|
+
const back = (ok) => (go2({ on: "answer", ok }), go2({ on: "settled" }));
|
|
234
|
+
const h3 = { start: start2, c: fx.send, back };
|
|
235
|
+
c.held?.set(k, h3);
|
|
236
|
+
say("sending");
|
|
237
|
+
void c.act({ action: o.gesture.action, block: o.block.id, values: { [o.gesture.name]: fx.send } }, input3).catch(() => false).then((ok) => {
|
|
238
|
+
c.held?.delete(k);
|
|
239
|
+
h3.back(ok);
|
|
240
|
+
say(ok ? o.rules.says(o.block, o.grab, fx.send) : "not changed");
|
|
241
|
+
});
|
|
242
|
+
};
|
|
243
|
+
const leave = (e, how) => {
|
|
244
|
+
if (gone2) return;
|
|
245
|
+
gone2 = true;
|
|
246
|
+
go2(e);
|
|
247
|
+
o.left(how);
|
|
248
|
+
};
|
|
249
|
+
input3.addEventListener("focus", () => p.at === "idle" && (go2({ on: "press" }), go2({ on: "move", c: o.rules.candidate(o.block, o.grab, input3.value) })));
|
|
250
|
+
input3.addEventListener("input", () => go2({ on: "move", c: o.rules.candidate(o.block, o.grab, input3.value) }));
|
|
251
|
+
input3.addEventListener("blur", () => leave({ on: "release" }, "blur"));
|
|
252
|
+
input3.addEventListener("keydown", (e) => {
|
|
253
|
+
const how = e.key === "Enter" ? "down" : e.key === "Tab" ? e.shiftKey ? "left" : "right" : e.key === "Escape" ? "stay" : "";
|
|
254
|
+
if (!how) return;
|
|
255
|
+
e.preventDefault();
|
|
256
|
+
leave({ on: how === "stay" ? "cancel" : "release" }, how);
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
function steered(el2, o) {
|
|
260
|
+
let p = { at: "idle" };
|
|
261
|
+
let b = o.now();
|
|
262
|
+
let start2 = null;
|
|
263
|
+
let [x0, y0] = [0, 0];
|
|
264
|
+
const go2 = (e) => {
|
|
265
|
+
if (start2 === null) return;
|
|
266
|
+
const [next, fx] = step(p, e, start2);
|
|
267
|
+
p = next;
|
|
268
|
+
(o.mark ?? el2).dataset["phase"] = p.at;
|
|
269
|
+
if (p.at === "previewing") o.show(p.c);
|
|
270
|
+
if (p.at === "idle" || p.at === "dragging") o.show(null);
|
|
271
|
+
if (fx === "tap") o.tap?.();
|
|
272
|
+
if (!fx || fx === "tap") return;
|
|
273
|
+
const ok = o.send(fx.send);
|
|
274
|
+
say(o.rules.says(b, o.grab, ok ? fx.send : start2));
|
|
275
|
+
go2({ on: "answer", ok });
|
|
276
|
+
go2({ on: "settled" });
|
|
277
|
+
};
|
|
278
|
+
const press2 = () => {
|
|
279
|
+
b = o.now();
|
|
280
|
+
start2 = o.rules.start(b, o.grab);
|
|
281
|
+
if (start2 !== null) go2({ on: "press" });
|
|
282
|
+
return start2 !== null;
|
|
283
|
+
};
|
|
284
|
+
const live3 = () => p.at === "pressed" || p.at === "dragging" || p.at === "previewing";
|
|
285
|
+
el2.style.touchAction = "none";
|
|
286
|
+
el2.addEventListener("pointerdown", (e) => {
|
|
287
|
+
if (e.button !== 0 || p.at !== "idle" || o.skip?.(e) || !press2()) return;
|
|
288
|
+
el2.setPointerCapture(e.pointerId);
|
|
289
|
+
[x0, y0] = [e.clientX, e.clientY];
|
|
290
|
+
});
|
|
291
|
+
el2.addEventListener("pointermove", (e) => {
|
|
292
|
+
const [dx, dy] = [e.clientX - x0, e.clientY - y0];
|
|
293
|
+
if (live3() && (p.at !== "pressed" || Math.hypot(dx, dy) >= 4)) go2({ on: "move", c: o.rules.candidate(b, o.grab, o.reach(dx, dy)) });
|
|
294
|
+
});
|
|
295
|
+
el2.addEventListener("pointerup", () => live3() && go2({ on: "release" }));
|
|
296
|
+
el2.addEventListener("pointercancel", () => go2({ on: "cancel" }));
|
|
297
|
+
o.keys?.addEventListener("keydown", (e) => {
|
|
298
|
+
const dir = ARROWS[e.key];
|
|
299
|
+
if (!dir || p.at !== "idle" || o.skip?.(e) || !press2() || start2 === null) return;
|
|
300
|
+
e.preventDefault();
|
|
301
|
+
const c = o.rules.nudge(b, o.grab, start2, { dir, big: e.shiftKey });
|
|
302
|
+
if (c === null) return go2({ on: "cancel" });
|
|
303
|
+
go2({ on: "move", c });
|
|
304
|
+
go2({ on: "release" });
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// src/edits.ts
|
|
309
|
+
var PLACES = ["push", "sheet", "panel", "column", "strip", "cards", "menu", "inline", "hidden"];
|
|
310
|
+
var STEPS = [
|
|
311
|
+
["Move earlier", { dir: "up" }],
|
|
312
|
+
["Move later", { dir: "down" }],
|
|
313
|
+
["Swap with the previous", { dir: "left" }],
|
|
314
|
+
["Swap with the next", { dir: "right" }],
|
|
315
|
+
["Move to the previous slot", { dir: "up", big: true }],
|
|
316
|
+
["Move to the next slot", { dir: "down", big: true }]
|
|
317
|
+
];
|
|
318
|
+
var read = (n, depth = 0) => [[n, depth], ...Object.keys(n.slots ?? {}).sort().flatMap((k) => (n.slots?.[k] ?? []).flatMap((c) => read(c, depth + 1)))];
|
|
319
|
+
var slotOf = (e) => e.edit === "move" ? `${e.into}
|
|
320
|
+
${e.slot}` : "";
|
|
321
|
+
var rows = (tree) => read(tree).map(([n, depth]) => ({ id: n.id, depth, label: n.label ?? n.id, places: PLACES.filter((p) => depth > 0 || p !== "hidden") }));
|
|
322
|
+
function rules(tree, slots, name) {
|
|
323
|
+
const walk = (g, from, step2, ok) => {
|
|
324
|
+
const all = places(tree, slots, g);
|
|
325
|
+
for (let i = all.findIndex((p) => same(p, from)) + step2; i >= 0 && i < all.length; i += step2) {
|
|
326
|
+
const e = all[i];
|
|
327
|
+
if (e && ok(e)) return e;
|
|
328
|
+
}
|
|
329
|
+
return null;
|
|
330
|
+
};
|
|
331
|
+
return {
|
|
332
|
+
word: (_, g) => stay(tree, g) ? "move" : null,
|
|
333
|
+
start: (_, g) => stay(tree, g),
|
|
334
|
+
candidate: (_, g, r) => {
|
|
335
|
+
const s = stay(tree, g);
|
|
336
|
+
const all = places(tree, slots, g);
|
|
337
|
+
return s ? all[all.findIndex((p) => same(p, s)) + r] ?? null : null;
|
|
338
|
+
},
|
|
339
|
+
nudge: (_, g, from, n) => {
|
|
340
|
+
const step2 = n.dir === "up" || n.dir === "left" ? -1 : 1;
|
|
341
|
+
if (n.dir === "left" || n.dir === "right") return walk(g, from, step2, (e) => e.edit === "swap");
|
|
342
|
+
return walk(g, from, step2, (e) => e.edit === "move" && (!n.big || slotOf(e) !== slotOf(from)));
|
|
343
|
+
},
|
|
344
|
+
steps: () => STEPS,
|
|
345
|
+
says: (_, __, c) => c.edit === "swap" ? `swapped with ${name(c.b)}` : c.edit === "move" ? `${c.before ? `before ${name(c.before)}` : "last"} in ${c.slot} of ${name(c.into)}` : c.place
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
function wire(list3, tree, size, o, refuse, done) {
|
|
349
|
+
const nodes2 = read(tree);
|
|
350
|
+
const name = (id) => nodes2.find(([n]) => n.id === id)?.[0].label ?? id;
|
|
351
|
+
const rows2 = new Map(Array.from(list3.children).flatMap((e) => e instanceof HTMLElement && e.dataset["id"] ? [[e.dataset["id"], e]] : []));
|
|
352
|
+
const r = rules(tree, o.slots, name);
|
|
353
|
+
let out2 = null;
|
|
354
|
+
const deliver = async (e) => {
|
|
355
|
+
const got = await o.save(e).catch((x) => String(x));
|
|
356
|
+
if (got !== true) refuse(typeof got === "string" ? got : "not saved");
|
|
357
|
+
return got === true;
|
|
358
|
+
};
|
|
359
|
+
const ctx = { act: () => out2 ? deliver(out2) : Promise.resolve(false) };
|
|
360
|
+
const end = (host, slot) => {
|
|
361
|
+
const kids3 = nodes2.find(([n]) => n.id === host)?.[0].slots?.[slot] ?? [];
|
|
362
|
+
const last = kids3[kids3.length - 1];
|
|
363
|
+
const deep = last ? read(last) : [];
|
|
364
|
+
return rows2.get(deep[deep.length - 1]?.[0].id ?? host);
|
|
365
|
+
};
|
|
366
|
+
const show = (g) => (e) => {
|
|
367
|
+
out2 = e;
|
|
368
|
+
for (const x of rows2.values()) {
|
|
369
|
+
x.style.transform = "";
|
|
370
|
+
x.removeAttribute("data-drop");
|
|
371
|
+
}
|
|
372
|
+
const me = rows2.get(g);
|
|
373
|
+
const at2 = !e || e.edit === "show" ? void 0 : e.edit === "swap" ? rows2.get(e.b) : e.before ? rows2.get(e.before) : end(e.into, e.slot);
|
|
374
|
+
if (!me || !at2 || !e) return;
|
|
375
|
+
at2.dataset["drop"] = e.edit === "swap" ? "onto" : e.edit === "move" && e.before ? "before" : "after";
|
|
376
|
+
me.style.transform = `translateY(${at2.offsetTop + (at2.dataset["drop"] === "after" ? at2.offsetHeight : 0) - me.offsetTop}px)`;
|
|
377
|
+
};
|
|
378
|
+
const esc = (e) => e.key === "Escape" && !e.defaultPrevented && done();
|
|
379
|
+
list3.addEventListener("keydown", esc);
|
|
380
|
+
const added = [];
|
|
381
|
+
for (const [n, depth] of nodes2) {
|
|
382
|
+
const row5 = rows2.get(n.id);
|
|
383
|
+
const pick2 = row5?.querySelector("select");
|
|
384
|
+
if (!row5 || !pick2) continue;
|
|
385
|
+
pick2.value = n.place;
|
|
386
|
+
pick2.onchange = () => {
|
|
387
|
+
const place3 = PLACES.find((p) => p === pick2.value);
|
|
388
|
+
if (place3) void deliver({ edit: "show", id: n.id, size, place: place3 }).then((ok) => ok || (pick2.value = n.place));
|
|
389
|
+
};
|
|
390
|
+
if (depth === 0) continue;
|
|
391
|
+
const hd = Object.assign(document.createElement("button"), { className: "b-hd", type: "button", textContent: "\u2261" });
|
|
392
|
+
hd.setAttribute("aria-label", `Move ${n.label ?? n.id}`);
|
|
393
|
+
const mine = row5.children.length;
|
|
394
|
+
row5.append(hd);
|
|
395
|
+
gestured(hd, ctx, { block: { id: "layout" }, gesture: { action: "layout", name: "edit" }, rules: r, grab: n.id, item: n.id, reach: (_, dy) => Math.round(dy / ((row5.offsetHeight || 2) / 2)), show: show(n.id) });
|
|
396
|
+
added.push(...Array.from(row5.children).slice(mine));
|
|
397
|
+
}
|
|
398
|
+
return () => {
|
|
399
|
+
list3.removeEventListener("keydown", esc);
|
|
400
|
+
added.forEach((x) => x.remove());
|
|
401
|
+
for (const x of rows2.values()) x.style.transform = "";
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
// react/src/h.ts
|
|
406
|
+
import { createElement } from "react";
|
|
407
|
+
var h = (tag, cls, attrs, ...kids3) => createElement(tag, { ...attrs, className: [attrs?.className, cls].filter(Boolean).join(" ") || void 0 }, ...kids3);
|
|
408
|
+
|
|
409
|
+
// react/src/arrange.ts
|
|
410
|
+
function Arrange(p) {
|
|
411
|
+
const ref3 = useRef(null);
|
|
412
|
+
const [why, setWhy] = useState("");
|
|
413
|
+
const live3 = useRef(p);
|
|
414
|
+
live3.current = p;
|
|
415
|
+
const { tree, size } = p;
|
|
416
|
+
useLayoutEffect(() => {
|
|
417
|
+
const l = ref3.current;
|
|
418
|
+
if (!l) return;
|
|
419
|
+
const o = { slots: live3.current.edit.slots, save: (e) => live3.current.edit.save(e) };
|
|
420
|
+
return wire(l, tree, size, o, setWhy, () => live3.current.onDone?.());
|
|
421
|
+
}, [tree, size]);
|
|
422
|
+
const row5 = (r) => h(
|
|
423
|
+
"div",
|
|
424
|
+
"row as-surface",
|
|
425
|
+
{ key: r.id, "data-id": r.id, style: { paddingInlineStart: `calc(var(--s3) * ${r.depth + 1})` } },
|
|
426
|
+
h("span", "rm", null, h("span", "rt as-title-label", null, r.label)),
|
|
427
|
+
h("select", "", { "aria-label": `${r.label} shows on ${size} as` }, ...r.places.map((x) => h("option", "", { key: x, value: x }, x)))
|
|
428
|
+
);
|
|
429
|
+
return h("div", "b-sheet__body", null, h("div", "list b-arrange", { ref: ref3, "aria-label": `layout on ${size}` }, ...rows(tree).map(row5)), h("p", "m", { role: "alert" }, why));
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
// react/src/view.ts
|
|
433
|
+
import { createElement as createElement18, useMemo as useMemo3, useRef as useRef20, useSyncExternalStore } from "react";
|
|
434
|
+
import { hooks as hooks3, share } from "./core.js";
|
|
435
|
+
|
|
436
|
+
// react/src/act.ts
|
|
437
|
+
import { createContext, useEffect, useMemo, useRef as useRef2, useState as useState2 } from "react";
|
|
438
|
+
import { check, evaluate, linkable, seeks, start, view } from "./core.js";
|
|
439
|
+
var none = { hidden: /* @__PURE__ */ new Set(), disabled: /* @__PURE__ */ new Set(), says: {}, acts: /* @__PURE__ */ new Set(), values: {} };
|
|
440
|
+
var Cx = createContext({ screen: "", locale: {}, v: none, state: {}, edits: {}, put: () => {
|
|
441
|
+
}, busy: /* @__PURE__ */ new Set(), act: async () => false, tap: () => {
|
|
442
|
+
}, report: () => {
|
|
443
|
+
}, kinds: {}, islands: {}, seek: {} });
|
|
444
|
+
var goOf = (t) => t.open != null ? { open: t.open } : t.sheet != null ? { sheet: t.sheet } : t.thread != null ? { thread: t.thread } : null;
|
|
445
|
+
function useCx(p, screen2) {
|
|
446
|
+
const props = useRef2(p);
|
|
447
|
+
props.current = p;
|
|
448
|
+
const [edits, setEdits] = useState2({});
|
|
449
|
+
const [busy, setBusy] = useState2(/* @__PURE__ */ new Set());
|
|
450
|
+
const [asking, setAsking] = useState2(null);
|
|
451
|
+
const state3 = start(screen2);
|
|
452
|
+
for (const [k, x] of Object.entries(edits)) if (Object.prototype.hasOwnProperty.call(state3, k)) state3[k] = x;
|
|
453
|
+
const v = view(screen2, state3);
|
|
454
|
+
const live3 = useRef2({ screen: screen2, state: state3, v, busy: /* @__PURE__ */ new Set() });
|
|
455
|
+
live3.current = { ...live3.current, screen: screen2, state: state3, v };
|
|
456
|
+
useEffect(() => {
|
|
457
|
+
const out2 = props.current.onReport;
|
|
458
|
+
if (out2) for (const fault of check(screen2, Object.keys(props.current.kinds ?? {}))) out2({ what: "fault", fault });
|
|
459
|
+
}, [screen2]);
|
|
460
|
+
const key3 = JSON.stringify([[...v.hidden], [...v.disabled], v.says, [...v.acts], v.values, [...busy], state3, edits]);
|
|
461
|
+
const cx = useMemo(() => {
|
|
462
|
+
const report = (r) => props.current.onReport?.(r);
|
|
463
|
+
const mark2 = (k, on) => {
|
|
464
|
+
const b = live3.current.busy;
|
|
465
|
+
if (on) b.add(k);
|
|
466
|
+
else b.delete(k);
|
|
467
|
+
setBusy(new Set(b));
|
|
468
|
+
};
|
|
469
|
+
const act2 = async (a) => {
|
|
470
|
+
const k = a.block ?? a.action;
|
|
471
|
+
if (live3.current.busy.has(k) || a.block != null && live3.current.v.disabled.has(a.block)) return false;
|
|
472
|
+
const c = a.confirm;
|
|
473
|
+
if (c && !await new Promise((done) => setAsking({ c, done }))) return false;
|
|
474
|
+
mark2(k, true);
|
|
475
|
+
try {
|
|
476
|
+
const sent2 = { screen: String(live3.current.screen.id ?? ""), action: a.action, block: a.block ?? null, values: a.values ?? null };
|
|
477
|
+
return await props.current.onAction(sent2) !== false;
|
|
478
|
+
} catch (error) {
|
|
479
|
+
report({ what: "failed", action: a.action, error });
|
|
480
|
+
return false;
|
|
481
|
+
} finally {
|
|
482
|
+
mark2(k, false);
|
|
483
|
+
}
|
|
484
|
+
};
|
|
485
|
+
const tap = (t) => {
|
|
486
|
+
const go2 = goOf(t);
|
|
487
|
+
if (go2) props.current.onOpen?.(go2);
|
|
488
|
+
if (t.url != null && linkable(t.url)) window.open(t.url, "_blank", "noopener");
|
|
489
|
+
if (t.copy != null) void navigator.clipboard?.writeText(t.copy);
|
|
490
|
+
const sets = {};
|
|
491
|
+
for (const x of t.set ?? []) sets[x.key] = evaluate(x.to, live3.current.state);
|
|
492
|
+
if (t.set?.length) setEdits((e) => ({ ...e, ...sets }));
|
|
493
|
+
if (!go2 && t.action) void act2({ action: t.action, values: t.values });
|
|
494
|
+
};
|
|
495
|
+
const put = (k, to) => setEdits((e) => ({ ...Object.fromEntries(Object.entries(e).filter(([x]) => x !== k)), ...to === void 0 ? null : { [k]: to } }));
|
|
496
|
+
return { screen: String(screen2.id ?? ""), locale: screen2.locale ?? {}, v, state: state3, edits, put, busy, act: act2, tap, report, kinds: p.kinds ?? {}, islands: p.islands ?? {}, file: p.onFile, seek: seeks(screen2, state3) };
|
|
497
|
+
}, [key3, screen2.id, p.kinds, p.islands, p.onFile]);
|
|
498
|
+
const end = (ok) => {
|
|
499
|
+
asking?.done(ok);
|
|
500
|
+
setAsking(null);
|
|
501
|
+
};
|
|
502
|
+
const button3 = (label2, ok, cls = "") => h("button", cls, { type: "button", onClick: () => end(ok) }, h("span", "", null, label2));
|
|
503
|
+
const ask = asking ? h("div", "b-confirm", { role: "dialog" }, h("p", "", null, h("b", "", null, asking.c.title)), asking.c.message ? h("p", "m", null, asking.c.message) : null, h("div", "bar", null, button3("cancel", false), button3(asking.c.ok ?? "ok", true, asking.c.destructive ? "bad" : ""))) : null;
|
|
504
|
+
return { cx, ask };
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
// react/src/block.ts
|
|
508
|
+
import { Component, createElement as createElement17, memo, useContext as useContext27 } from "react";
|
|
509
|
+
import { hooks as hooks2, named as named3, role } from "./core.js";
|
|
510
|
+
|
|
511
|
+
// react/src/draw.ts
|
|
512
|
+
import { actionOf, figured, linkable as linkable2, value } from "./core.js";
|
|
513
|
+
var urlOf = (t) => t?.url != null && linkable2(t.url) ? t.url : void 0;
|
|
514
|
+
var sends = (t, action) => {
|
|
515
|
+
const a = t ? t.url != null || t.open != null || t.sheet != null ? null : t.action : action;
|
|
516
|
+
return typeof a === "string" && a ? a : void 0;
|
|
517
|
+
};
|
|
518
|
+
var out = (url2) => ({ href: url2, target: "_blank", rel: "noopener" });
|
|
519
|
+
var press = (go2) => ({ role: "button", tabIndex: 0, onClick: go2, onKeyDown: (e) => e.key === "Enter" && go2() });
|
|
520
|
+
var btn = (label2, cls, url2, action, attrs, off = false, part3 = "") => {
|
|
521
|
+
const own3 = { "data-action": typeof action === "string" && action ? action : void 0, ...attrs };
|
|
522
|
+
const span2 = h("span", part3, null, String(label2 ?? ""));
|
|
523
|
+
return url2 ? h("a", `btn ${cls}`, { ...own3, ...out(url2) }, span2) : h("button", cls, { type: "button", ...own3, disabled: off || void 0 }, span2);
|
|
524
|
+
};
|
|
525
|
+
var act = (a, cls, cx, url2, go2) => {
|
|
526
|
+
const k = actionOf(a);
|
|
527
|
+
return btn(a.label, cls, url2, sends(a.tap, a.action), { "data-act": k || void 0, onClick: go2 }, k !== void 0 && cx.v.acts.has(k));
|
|
528
|
+
};
|
|
529
|
+
var rec = (v) => typeof v === "object" && v !== null;
|
|
530
|
+
function ticked(v, cx) {
|
|
531
|
+
if (rec(v) && typeof v["get"] === "string") return h("span", "", { "data-get": v["get"] }, cx.v.values[v["get"]] ?? "");
|
|
532
|
+
return rec(v) && ("since" in v || "until" in v) ? h("span", "", { "data-tick": JSON.stringify(v) }, value(v)) : value(v);
|
|
533
|
+
}
|
|
534
|
+
var figure = (f, cls) => {
|
|
535
|
+
const s = String(f.state);
|
|
536
|
+
const { glyph: glyph2, word: word2, tone: tone2 } = figured(s);
|
|
537
|
+
return h("span", `rsg ${s} ${cls}`, { role: "img", "aria-label": word2, title: word2 }, h("i", `gl ${tone2}`, null, glyph2));
|
|
538
|
+
};
|
|
539
|
+
function inline(s, stages) {
|
|
540
|
+
const [stage2, ...rest] = stages;
|
|
541
|
+
if (!stage2) return s ? [s] : [];
|
|
542
|
+
const next = (t) => inline(t, rest);
|
|
543
|
+
const got = [];
|
|
544
|
+
let at2 = 0;
|
|
545
|
+
for (const m of s.matchAll(stage2[0])) {
|
|
546
|
+
got.push(...next(s.slice(at2, m.index)), stage2[1](m, next));
|
|
547
|
+
at2 = (m.index ?? 0) + m[0].length;
|
|
548
|
+
}
|
|
549
|
+
return [...got, ...next(s.slice(at2))];
|
|
550
|
+
}
|
|
551
|
+
function md(s, refs) {
|
|
552
|
+
const link3 = new RegExp(String.raw`\[([^\]]+)\]\((https?:[^)\s]+)\)|(https?:\/\/[^\s<]*[^\s<.,;:!?)])|\b(${refs ? "t\\d+" : "(?!)"})\b`, "g");
|
|
553
|
+
const stages = [
|
|
554
|
+
[/`([^`]+)`/g, (m, n) => h("code", "", null, ...n(m[1] ?? ""))],
|
|
555
|
+
[/\*\*([^*]+)\*\*/g, (m, n) => h("b", "", null, ...n(m[1] ?? ""))],
|
|
556
|
+
[link3, (m, n) => m[4] ? h("a", "", { href: "#", "data-thread": m[4] }, m[4]) : h("a", "", out(m[2] ?? m[3] ?? ""), ...n(m[1] ?? m[3] ?? ""))],
|
|
557
|
+
[/\n/g, () => h("br", "", null)]
|
|
558
|
+
];
|
|
559
|
+
const cb = (part3) => h("div", "cb", null, h("pre", "", null, part3.replace(/\n$/, "")), h("button", "cpy", { type: "button" }, h("span", "", null, "copy")));
|
|
560
|
+
return String(s ?? "").split(/```(?:[a-z]*)\n?/).flatMap((part3, i) => i % 2 ? [cb(part3)] : inline(part3, stages));
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
// react/src/kinds/button.ts
|
|
564
|
+
import { useContext } from "react";
|
|
565
|
+
function button({ b, hooks: hooks4 }) {
|
|
566
|
+
const cx = useContext(Cx);
|
|
567
|
+
const url2 = urlOf(b.tap);
|
|
568
|
+
const go2 = () => b.tap ? cx.tap(b.tap) : void cx.act({ action: b.action ?? "", block: b.id, values: b.values ?? {}, confirm: b.confirm });
|
|
569
|
+
return btn(b.label, b.style ?? "", url2, sends(b.tap, b.action), { ...hooks4, "data-id": b.id ?? "", onClick: url2 ? void 0 : go2 }, b.id != null && cx.v.disabled.has(b.id), "as-button-label");
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
// react/src/kinds/card.ts
|
|
573
|
+
import { useContext as useContext2, useState as useState3 } from "react";
|
|
574
|
+
function card({ b, hooks: hooks4 }) {
|
|
575
|
+
const cx = useContext2(Cx);
|
|
576
|
+
const [open2, setOpen] = useState3(false);
|
|
577
|
+
const cls = `card as-surface ${b.tone ?? ""} k-${b.kind ?? ""}`;
|
|
578
|
+
const attrs = { ...hooks4, "data-id": b.id ?? "" };
|
|
579
|
+
const fold2 = b.fold ?? null;
|
|
580
|
+
const main = fold2?.main ?? null;
|
|
581
|
+
const shut = fold2 !== null && !open2;
|
|
582
|
+
const send4 = main && (() => void cx.act({ action: main.action, block: main.block, values: { ...main.values, choice: main.value } }));
|
|
583
|
+
const flip = (e) => e.target instanceof Element && e.target.closest("button") || setOpen((o) => !o);
|
|
584
|
+
const mainBtn = main && shut ? btn(main.label, "main", void 0, main.action, { onClick: send4 }) : null;
|
|
585
|
+
const line = fold2 ? h("div", "fold", { tabIndex: 0, role: "button", "aria-expanded": String(!shut), onClick: flip }, h("span", "fl", null, fold2.line), mainBtn) : null;
|
|
586
|
+
if (shut) return h("div", cls, attrs, line);
|
|
587
|
+
const badge2 = b.badge ? [" ", h("span", `tag b-card__badge ${b.badge.tone ?? ""}`, null, ticked(b.badge.text, cx))] : [];
|
|
588
|
+
const meta = b.meta ? [" ", h("span", "m", null, ticked(b.meta, cx))] : [];
|
|
589
|
+
const head4 = b.title || b.badge ? h("div", "ch", null, h("b", "b-card__title as-title-label", null, b.title ?? ""), ...badge2, ...meta) : null;
|
|
590
|
+
const buttons = b.buttons ?? [];
|
|
591
|
+
const bar6 = buttons.length ? h("div", "bar b-card__actions", null, ...kids2(buttons)) : null;
|
|
592
|
+
const s = !b.subtitle ? null : typeof b.subtitle === "string" ? { text: b.subtitle, tone: null } : b.subtitle;
|
|
593
|
+
const sub = s ? h("p", `m b-card__subtitle ${s.tone ?? ""}`.trimEnd(), null, ticked(s.text, cx)) : null;
|
|
594
|
+
return h("div", cls, attrs, line, head4, sub, ...kids2(b.blocks), bar6);
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
// react/src/kinds/chips.ts
|
|
598
|
+
import { useContext as useContext3 } from "react";
|
|
599
|
+
function chips({ b, hooks: hooks4 }) {
|
|
600
|
+
const cx = useContext3(Cx);
|
|
601
|
+
const sel = b.selected ?? [];
|
|
602
|
+
const pick2 = (v) => {
|
|
603
|
+
const next = !b.multi || v === "all" ? [v] : sel.includes(v) ? sel.filter((x) => x !== v) : [...sel.filter((x) => x !== "all"), v];
|
|
604
|
+
void cx.act({ action: b.action ?? "", block: b.id, values: { [b.name]: next.length ? next : ["all"] } });
|
|
605
|
+
};
|
|
606
|
+
const chip = (o) => btn(o.label, sel.includes(o.value) ? "on as-tint" : "", void 0, b.action, { key: o.value, "aria-pressed": String(sel.includes(o.value)), onClick: () => pick2(o.value) }, false, "as-chip-label");
|
|
607
|
+
return h("div", "chips", hooks4, ...b.options.map(chip));
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
// react/src/kinds/choice.ts
|
|
611
|
+
import { useContext as useContext4, useState as useState4 } from "react";
|
|
612
|
+
function choice({ b, hooks: hooks4 }) {
|
|
613
|
+
const cx = useContext4(Cx);
|
|
614
|
+
const [v, setV] = useState4("");
|
|
615
|
+
const opts2 = [...b.options].sort((x, y) => Number(y.value === b.recommended) - Number(x.value === b.recommended));
|
|
616
|
+
const picks = opts2.map((o) => {
|
|
617
|
+
const go2 = () => void cx.act({ action: b.action, block: b.id, values: { ...b.values, ...o.values, choice: o.value }, confirm: o.confirm });
|
|
618
|
+
return btn(`${o.label}${o.value === b.recommended ? " \xB7 recommended" : ""}`, "pick", void 0, b.action, { key: o.value, name: "choice", onClick: go2 });
|
|
619
|
+
});
|
|
620
|
+
const other = b.other;
|
|
621
|
+
const submit = (e) => {
|
|
622
|
+
e.preventDefault();
|
|
623
|
+
if (other && v.trim()) void cx.act({ action: b.action, block: b.id, values: { ...b.values, choice: other.for ?? "", other: v } }).then((ok) => ok && setV(""));
|
|
624
|
+
};
|
|
625
|
+
const draft = `draft:${cx.screen}:${String(b.id)}:other`;
|
|
626
|
+
const input3 = h("input", "", { name: "other", value: v, placeholder: other?.placeholder ?? "other\u2026", autoComplete: "off", "data-draft": draft, onChange: (e) => setV(e.target.value) });
|
|
627
|
+
const form2 = other ? h("form", "other", { onSubmit: submit }, input3, btn("send", "", void 0, b.action, { type: "submit" })) : null;
|
|
628
|
+
const d2 = b.default;
|
|
629
|
+
return h("div", "choice as-surface", hooks4, ...picks, d2 ? h("p", "m", null, ticked({ until: d2.until, label: d2.label }, cx)) : null, form2);
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
// react/src/kinds/composer.ts
|
|
633
|
+
import { createElement as createElement2, useContext as useContext5, useEffect as useEffect2, useLayoutEffect as useLayoutEffect2, useRef as useRef3, useState as useState5 } from "react";
|
|
634
|
+
import { nonce as mint, send as upload } from "./core.js";
|
|
635
|
+
var SAID = { sending: "sending\u2026", sent: "\u2713 sent", failed: "not sent" };
|
|
636
|
+
function Pill({ b, post }) {
|
|
637
|
+
const [, tick2] = useState5(0);
|
|
638
|
+
const [stopping, setStopping] = useState5(false);
|
|
639
|
+
useEffect2(() => {
|
|
640
|
+
const t = setInterval(() => tick2((n) => n + 1), 1e3);
|
|
641
|
+
return () => clearInterval(t);
|
|
642
|
+
}, []);
|
|
643
|
+
const stop = b.acts?.["stop"] ?? "";
|
|
644
|
+
const halt = async (e) => {
|
|
645
|
+
e.stopPropagation();
|
|
646
|
+
if (await post(stop, {})) setStopping(true);
|
|
647
|
+
};
|
|
648
|
+
if (!navigator.onLine) return h("div", "pill", { onClick: () => tick2((n) => n + 1) }, h("span", "r", null, "offline \xB7 tap to retry"));
|
|
649
|
+
const s = Math.max(0, Math.floor((Date.now() - Date.parse(String(b.working?.since))) / 1e3));
|
|
650
|
+
const said5 = stopping ? "stopping\u2026" : `working ${s >= 60 ? `${Math.floor(s / 60)}m ` : ""}${s % 60}s`;
|
|
651
|
+
return h("div", "pill", null, figure({ state: "working" }, ""), h("span", "pt", null, said5), stop && !stopping ? btn("stop", "bad", void 0, stop, { onClick: halt }) : null);
|
|
652
|
+
}
|
|
653
|
+
function queued({ q, text: text4 }, steer, unqueue, post, edit2) {
|
|
654
|
+
const now = btn("send now", "primary", void 0, steer, { onClick: () => void post(steer, { q }) });
|
|
655
|
+
const rm = btn("remove", "bad", void 0, unqueue, { onClick: () => void post(unqueue, { q }) });
|
|
656
|
+
return h("div", "qd", { key: `q${q}`, "data-q": String(q) }, h("span", "qt", null, text4), now, btn("edit", "", void 0, void 0, { onClick: edit2 }), rm);
|
|
657
|
+
}
|
|
658
|
+
function attached(files, drop) {
|
|
659
|
+
const tile = (a, i) => h("span", `tb ${a.state}`, { key: i }, a.src ? h("img", "", { alt: a.name, src: a.src }) : h("span", "", null, a.name), btn("\xD7", "", void 0, void 0, { "aria-label": `remove ${a.name}`, onClick: () => drop(a) }));
|
|
660
|
+
return h("div", "th", null, ...files.map(tile));
|
|
661
|
+
}
|
|
662
|
+
function chips2(b, picks, pick2) {
|
|
663
|
+
const all = (b.chips ?? []).map(({ name: n, ...ch }) => {
|
|
664
|
+
const cur = String(picks[n] ?? ch.cur ?? "");
|
|
665
|
+
const opts2 = [...cur ? [] : [h("option", "", { key: "", value: "" }, n)], ...ch.all.map((o) => h("option", "", { key: o, value: o }, o))];
|
|
666
|
+
return h("select", "", { key: n, "aria-label": n, value: cur, onChange: (e) => pick2(n, e.target.value) }, ...opts2);
|
|
667
|
+
});
|
|
668
|
+
return all.length ? h("div", "pk", null, ...all) : null;
|
|
669
|
+
}
|
|
670
|
+
function useSend(b, cx) {
|
|
671
|
+
const [files, setFiles] = useState5([]);
|
|
672
|
+
const live3 = useRef3(files);
|
|
673
|
+
const set = (next) => setFiles(live3.current = next);
|
|
674
|
+
const add = (blobs) => {
|
|
675
|
+
const fresh = blobs.map((blob) => ({ name: blob.name, size: blob.size, mime: blob.type, state: "uploading", part: 0, blob })).slice(0, 10 - live3.current.length);
|
|
676
|
+
set([...live3.current, ...fresh]);
|
|
677
|
+
for (const r of fresh) if (cx.file) upload(r, cx.file, { screen: cx.screen, block: b.id ?? void 0, field: "files" }, () => set([...live3.current]));
|
|
678
|
+
};
|
|
679
|
+
const drop = (r) => {
|
|
680
|
+
r.stop?.abort();
|
|
681
|
+
set(live3.current.filter((x) => x !== r));
|
|
682
|
+
};
|
|
683
|
+
return { files, add, drop, clear: () => set([]) };
|
|
684
|
+
}
|
|
685
|
+
function useHold(tap, hold) {
|
|
686
|
+
const h3 = useRef3({ held: false, t: 0 });
|
|
687
|
+
const up = () => clearTimeout(h3.current.t);
|
|
688
|
+
const down = () => {
|
|
689
|
+
h3.current.held = false;
|
|
690
|
+
h3.current.t = window.setTimeout(() => {
|
|
691
|
+
h3.current.held = true;
|
|
692
|
+
hold();
|
|
693
|
+
}, 500);
|
|
694
|
+
};
|
|
695
|
+
const onClick = () => {
|
|
696
|
+
if (!h3.current.held) tap();
|
|
697
|
+
h3.current.held = false;
|
|
698
|
+
};
|
|
699
|
+
return { onPointerDown: down, onPointerUp: up, onPointerLeave: up, onContextMenu: (e) => e.preventDefault(), onClick };
|
|
700
|
+
}
|
|
701
|
+
function composer({ b, hooks: hooks4 }) {
|
|
702
|
+
const cx = useContext5(Cx);
|
|
703
|
+
const act2 = (k) => b.acts?.[k] ?? "";
|
|
704
|
+
const [text4, setText] = useState5("");
|
|
705
|
+
const [picks, setPicks] = useState5({});
|
|
706
|
+
const [q, setQ] = useState5(void 0);
|
|
707
|
+
const [st, setSt] = useState5("");
|
|
708
|
+
const [steering, setSteering] = useState5(false);
|
|
709
|
+
const nonce = useRef3(void 0);
|
|
710
|
+
const { files, add, drop, clear } = useSend(b, cx);
|
|
711
|
+
const ta = useRef3(null);
|
|
712
|
+
const pick2 = useRef3(null);
|
|
713
|
+
useLayoutEffect2(() => {
|
|
714
|
+
const t = ta.current;
|
|
715
|
+
if (t) t.style.height = "auto";
|
|
716
|
+
if (t) t.style.height = `${t.scrollHeight}px`;
|
|
717
|
+
}, [text4]);
|
|
718
|
+
const post = (action, values2) => cx.act({ action, block: b.id, values: { ...b.values, ...values2 } });
|
|
719
|
+
const send4 = async (steer = false) => {
|
|
720
|
+
const done = files.filter((r) => r.state === "done");
|
|
721
|
+
if (!text4.trim() && !done.length || files.some((r) => r.state === "uploading")) return;
|
|
722
|
+
const queue = !steer && (b.working || q != null) ? act2("queue") : "";
|
|
723
|
+
nonce.current ??= mint();
|
|
724
|
+
const v = { ...picks, text: text4, files: done.map(({ id, name, src }) => ({ id, name, src: src ?? null })), nonce: nonce.current, ...queue && q != null ? { q } : null };
|
|
725
|
+
setSt("sending");
|
|
726
|
+
setSteering(false);
|
|
727
|
+
const ok = await post(steer ? act2("steer") : queue || b.action, v);
|
|
728
|
+
if (ok) {
|
|
729
|
+
nonce.current = void 0;
|
|
730
|
+
clear();
|
|
731
|
+
setQ(void 0);
|
|
732
|
+
setText("");
|
|
733
|
+
}
|
|
734
|
+
setSt(ok ? "sent" : "failed");
|
|
735
|
+
};
|
|
736
|
+
const key3 = (e) => {
|
|
737
|
+
if (e.key !== "Enter" || !(e.metaKey || e.ctrlKey)) return;
|
|
738
|
+
e.preventDefault();
|
|
739
|
+
void send4();
|
|
740
|
+
};
|
|
741
|
+
const held3 = useHold(() => void send4(), () => b.working && act2("steer") && setSteering(true));
|
|
742
|
+
const edit2 = (x) => () => {
|
|
743
|
+
setQ(x.q);
|
|
744
|
+
setText(x.text);
|
|
745
|
+
nonce.current = void 0;
|
|
746
|
+
ta.current?.focus();
|
|
747
|
+
};
|
|
748
|
+
const said5 = q != null ? "save" : b.working ? "queue" : b.label ?? "";
|
|
749
|
+
const go2 = btn(said5, "primary", void 0, b.action, { "aria-label": said5 || "send", "aria-busy": st === "sending" || void 0, ...held3 });
|
|
750
|
+
const typed2 = (e) => {
|
|
751
|
+
setText(e.target.value);
|
|
752
|
+
nonce.current = void 0;
|
|
753
|
+
if (st === "sent") setSt("");
|
|
754
|
+
};
|
|
755
|
+
const took = (e) => {
|
|
756
|
+
add(Array.from(e.target.files ?? []));
|
|
757
|
+
e.target.value = "";
|
|
758
|
+
nonce.current = void 0;
|
|
759
|
+
setSt("");
|
|
760
|
+
};
|
|
761
|
+
const row5 = h(
|
|
762
|
+
"div",
|
|
763
|
+
"cr",
|
|
764
|
+
{ key: "cr" },
|
|
765
|
+
btn("+", "", void 0, void 0, { "aria-label": "attach", onClick: () => pick2.current?.click() }, !cx.file),
|
|
766
|
+
h("input", "", { ref: pick2, type: "file", multiple: true, hidden: true, onChange: took }),
|
|
767
|
+
h("textarea", "", { ref: ta, name: "text", rows: 1, value: text4, placeholder: b.placeholder ?? "", onChange: typed2, onKeyDown: key3 }),
|
|
768
|
+
go2,
|
|
769
|
+
b.working && steering ? btn("steer", "", void 0, void 0, { onClick: () => void send4(true) }) : null
|
|
770
|
+
);
|
|
771
|
+
const retry = st === "failed" ? [" ", btn("retry", "bad", void 0, void 0, { onClick: () => void send4() })] : [];
|
|
772
|
+
const status2 = st ? h("p", `cs ${st === "failed" ? "r" : "m"}`, null, SAID[st] ?? "", ...retry) : null;
|
|
773
|
+
const top = [b.working ? createElement2(Pill, { key: "pill", b, post }) : null, ...(b.queued ?? []).map((x) => queued(x, act2("steer"), act2("unqueue"), post, edit2(x))), files.length ? attached(files, drop) : null, status2];
|
|
774
|
+
const chose = (n, v) => act2("model") ? void post(act2("model"), { [n]: v }) : setPicks((p) => ({ ...p, [n]: v }));
|
|
775
|
+
return h("div", "cmp", { ...hooks4, "data-id": b.id ?? "" }, ...top, row5, chips2(b, picks, chose));
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
// react/src/kinds/config.ts
|
|
779
|
+
import { useContext as useContext7, useEffect as useEffect3, useRef as useRef8, useState as useState10 } from "react";
|
|
780
|
+
|
|
781
|
+
// react/src/kinds/form.ts
|
|
782
|
+
import { useContext as useContext6, useRef as useRef7, useState as useState9 } from "react";
|
|
783
|
+
import { fill as fill3, lit } from "./core.js";
|
|
784
|
+
|
|
785
|
+
// src/gen/words.ts
|
|
786
|
+
var words = {
|
|
787
|
+
was: ["was", "\u0E40\u0E14\u0E34\u0E21"],
|
|
788
|
+
set: ["set \u2713 \xB7 type to replace", "\u0E15\u0E31\u0E49\u0E07\u0E44\u0E27\u0E49\u0E41\u0E25\u0E49\u0E27 \u2713 \xB7 \u0E1E\u0E34\u0E21\u0E1E\u0E4C\u0E40\u0E1E\u0E37\u0E48\u0E2D\u0E41\u0E17\u0E19\u0E17\u0E35\u0E48"],
|
|
789
|
+
unset: ["not set", "\u0E22\u0E31\u0E07\u0E44\u0E21\u0E48\u0E44\u0E14\u0E49\u0E15\u0E31\u0E49\u0E07"],
|
|
790
|
+
clear: ["clear", "\u0E25\u0E49\u0E32\u0E07"],
|
|
791
|
+
hits: ["{n} of {m}", "{n} \u0E08\u0E32\u0E01 {m}"],
|
|
792
|
+
none: ["no match", "\u0E44\u0E21\u0E48\u0E1E\u0E1A"],
|
|
793
|
+
busy: ["searching", "\u0E01\u0E33\u0E25\u0E31\u0E07\u0E04\u0E49\u0E19\u0E2B\u0E32"],
|
|
794
|
+
nomatch: ["No rows match \u201C{q}\u201D.", "\u0E44\u0E21\u0E48\u0E21\u0E35\u0E41\u0E16\u0E27\u0E17\u0E35\u0E48\u0E15\u0E23\u0E07\u0E01\u0E31\u0E1A \u201C{q}\u201D"],
|
|
795
|
+
file1: ["choose file", "\u0E40\u0E25\u0E37\u0E2D\u0E01\u0E44\u0E1F\u0E25\u0E4C"],
|
|
796
|
+
fileN: ["add files", "\u0E40\u0E1E\u0E34\u0E48\u0E21\u0E44\u0E1F\u0E25\u0E4C"],
|
|
797
|
+
photo1: ["choose photo", "\u0E40\u0E25\u0E37\u0E2D\u0E01\u0E23\u0E39\u0E1B"],
|
|
798
|
+
photoN: ["add photos", "\u0E40\u0E1E\u0E34\u0E48\u0E21\u0E23\u0E39\u0E1B"],
|
|
799
|
+
camera: ["take photo", "\u0E16\u0E48\u0E32\u0E22\u0E23\u0E39\u0E1B"],
|
|
800
|
+
replace: ["replace", "\u0E40\u0E1B\u0E25\u0E35\u0E48\u0E22\u0E19"],
|
|
801
|
+
remove: ["remove", "\u0E25\u0E1A"],
|
|
802
|
+
retry: ["retry", "\u0E25\u0E2D\u0E07\u0E2D\u0E35\u0E01\u0E04\u0E23\u0E31\u0E49\u0E07"],
|
|
803
|
+
dismiss: ["dismiss", "\u0E1B\u0E34\u0E14"],
|
|
804
|
+
image: ["images", "\u0E23\u0E39\u0E1B\u0E20\u0E32\u0E1E"],
|
|
805
|
+
pdf: ["PDF", "PDF"],
|
|
806
|
+
sheet: ["sheets", "\u0E44\u0E1F\u0E25\u0E4C\u0E15\u0E32\u0E23\u0E32\u0E07"],
|
|
807
|
+
or: [" or ", " \u0E2B\u0E23\u0E37\u0E2D "],
|
|
808
|
+
upTo: ["up to {mb} MB", "\u0E44\u0E21\u0E48\u0E40\u0E01\u0E34\u0E19 {mb} MB"],
|
|
809
|
+
each: ["up to {mb} MB each", "\u0E44\u0E21\u0E48\u0E40\u0E01\u0E34\u0E19 {mb} MB \u0E15\u0E48\u0E2D\u0E44\u0E1F\u0E25\u0E4C"],
|
|
810
|
+
uploading: ["uploading {p} %", "\u0E01\u0E33\u0E25\u0E31\u0E07\u0E2D\u0E31\u0E1B\u0E42\u0E2B\u0E25\u0E14 {p} %"],
|
|
811
|
+
failed: ["upload failed", "\u0E2D\u0E31\u0E1B\u0E42\u0E2B\u0E25\u0E14\u0E44\u0E21\u0E48\u0E2A\u0E33\u0E40\u0E23\u0E47\u0E08"],
|
|
812
|
+
onlyType: ["refused: only {types}", "\u0E44\u0E21\u0E48\u0E23\u0E31\u0E1A: \u0E23\u0E31\u0E1A\u0E40\u0E09\u0E1E\u0E32\u0E30{types}"],
|
|
813
|
+
tooBig: ["refused: {size} is over {mb} MB", "\u0E44\u0E21\u0E48\u0E23\u0E31\u0E1A: {size} \u0E40\u0E01\u0E34\u0E19 {mb} MB"],
|
|
814
|
+
off: ["uploads are off here", "\u0E2D\u0E31\u0E1B\u0E42\u0E2B\u0E25\u0E14\u0E44\u0E21\u0E48\u0E44\u0E14\u0E49\u0E17\u0E35\u0E48\u0E19\u0E35\u0E48"],
|
|
815
|
+
wait1: ["waiting for {n} upload", "\u0E23\u0E2D\u0E2D\u0E31\u0E1B\u0E42\u0E2B\u0E25\u0E14 {n} \u0E44\u0E1F\u0E25\u0E4C"],
|
|
816
|
+
waitN: ["waiting for {n} uploads", "\u0E23\u0E2D\u0E2D\u0E31\u0E1B\u0E42\u0E2B\u0E25\u0E14 {n} \u0E44\u0E1F\u0E25\u0E4C"],
|
|
817
|
+
stuck: ["an upload failed: retry or remove it", "\u0E2D\u0E31\u0E1B\u0E42\u0E2B\u0E25\u0E14\u0E44\u0E21\u0E48\u0E2A\u0E33\u0E40\u0E23\u0E47\u0E08: \u0E25\u0E2D\u0E07\u0E2D\u0E35\u0E01\u0E04\u0E23\u0E31\u0E49\u0E07\u0E2B\u0E23\u0E37\u0E2D\u0E25\u0E1A"],
|
|
818
|
+
files: ["{label}, {n} files", "{label}, {n} \u0E44\u0E1F\u0E25\u0E4C"],
|
|
819
|
+
scan: ["scan pages", "\u0E2A\u0E41\u0E01\u0E19\u0E40\u0E2D\u0E01\u0E2A\u0E32\u0E23"],
|
|
820
|
+
rescan: ["scan again", "\u0E2A\u0E41\u0E01\u0E19\u0E43\u0E2B\u0E21\u0E48"],
|
|
821
|
+
scanHint: ["makes one A4 PDF \xB7 up to {max} pages", "\u0E44\u0E14\u0E49 PDF \u0E02\u0E19\u0E32\u0E14 A4 \u0E2B\u0E19\u0E36\u0E48\u0E07\u0E44\u0E1F\u0E25\u0E4C \xB7 \u0E44\u0E21\u0E48\u0E40\u0E01\u0E34\u0E19 {max} \u0E2B\u0E19\u0E49\u0E32"],
|
|
822
|
+
editPages: ["edit pages", "\u0E41\u0E01\u0E49\u0E2B\u0E19\u0E49\u0E32"],
|
|
823
|
+
scanned1: ["1 page \xB7 A4 \xB7 {kb} KB", "1 \u0E2B\u0E19\u0E49\u0E32 \xB7 A4 \xB7 {kb} KB"],
|
|
824
|
+
scannedN: ["{n} pages \xB7 A4 \xB7 {kb} KB", "{n} \u0E2B\u0E19\u0E49\u0E32 \xB7 A4 \xB7 {kb} KB"],
|
|
825
|
+
scanOff: ["scanning is off here", "\u0E2A\u0E41\u0E01\u0E19\u0E44\u0E21\u0E48\u0E44\u0E14\u0E49\u0E17\u0E35\u0E48\u0E19\u0E35\u0E48"],
|
|
826
|
+
cancel: ["cancel", "\u0E22\u0E01\u0E40\u0E25\u0E34\u0E01"],
|
|
827
|
+
pickImages: ["pick images", "\u0E40\u0E25\u0E37\u0E2D\u0E01\u0E23\u0E39\u0E1B"],
|
|
828
|
+
pageN: ["page {n}", "\u0E2B\u0E19\u0E49\u0E32 {n}"],
|
|
829
|
+
pageOf: ["page {n} of {of}", "\u0E2B\u0E19\u0E49\u0E32 {n} \u0E08\u0E32\u0E01 {of}"],
|
|
830
|
+
seek: ["looking for the page's edges", "\u0E01\u0E33\u0E25\u0E31\u0E07\u0E2B\u0E32\u0E02\u0E2D\u0E1A\u0E01\u0E23\u0E30\u0E14\u0E32\u0E29"],
|
|
831
|
+
found: ["page found: hold still and take it", "\u0E1E\u0E1A\u0E2B\u0E19\u0E49\u0E32\u0E01\u0E23\u0E30\u0E14\u0E32\u0E29: \u0E16\u0E37\u0E2D\u0E19\u0E34\u0E48\u0E07\u0E46 \u0E41\u0E25\u0E49\u0E27\u0E16\u0E48\u0E32\u0E22"],
|
|
832
|
+
noEdge: ["no page edge found: fill the frame with the page, or take it and set the corners by hand", "\u0E44\u0E21\u0E48\u0E1E\u0E1A\u0E02\u0E2D\u0E1A\u0E01\u0E23\u0E30\u0E14\u0E32\u0E29: \u0E43\u0E2B\u0E49\u0E01\u0E23\u0E30\u0E14\u0E32\u0E29\u0E40\u0E15\u0E47\u0E21\u0E01\u0E23\u0E2D\u0E1A \u0E2B\u0E23\u0E37\u0E2D\u0E16\u0E48\u0E32\u0E22\u0E41\u0E25\u0E49\u0E27\u0E15\u0E31\u0E49\u0E07\u0E21\u0E38\u0E21\u0E40\u0E2D\u0E07"],
|
|
833
|
+
take: ["take page {n}", "\u0E16\u0E48\u0E32\u0E22\u0E2B\u0E19\u0E49\u0E32 {n}"],
|
|
834
|
+
done1: ["done \xB7 1 page", "\u0E40\u0E2A\u0E23\u0E47\u0E08 \xB7 1 \u0E2B\u0E19\u0E49\u0E32"],
|
|
835
|
+
doneN: ["done \xB7 {n} pages", "\u0E40\u0E2A\u0E23\u0E47\u0E08 \xB7 {n} \u0E2B\u0E19\u0E49\u0E32"],
|
|
836
|
+
retake: ["retake", "\u0E16\u0E48\u0E32\u0E22\u0E43\u0E2B\u0E21\u0E48"],
|
|
837
|
+
usePage: ["use page", "\u0E43\u0E0A\u0E49\u0E2B\u0E19\u0E49\u0E32\u0E19\u0E35\u0E49"],
|
|
838
|
+
reset: ["reset corners", "\u0E04\u0E37\u0E19\u0E21\u0E38\u0E21\u0E40\u0E14\u0E34\u0E21"],
|
|
839
|
+
drag: ["drag a corner onto the page's edge, or press space on it and move it with the arrow keys", "\u0E25\u0E32\u0E01\u0E21\u0E38\u0E21\u0E44\u0E1B\u0E17\u0E35\u0E48\u0E02\u0E2D\u0E1A\u0E01\u0E23\u0E30\u0E14\u0E32\u0E29"],
|
|
840
|
+
tl: ["top-left corner", "\u0E21\u0E38\u0E21\u0E1A\u0E19\u0E0B\u0E49\u0E32\u0E22"],
|
|
841
|
+
tr: ["top-right corner", "\u0E21\u0E38\u0E21\u0E1A\u0E19\u0E02\u0E27\u0E32"],
|
|
842
|
+
br: ["bottom-right corner", "\u0E21\u0E38\u0E21\u0E25\u0E48\u0E32\u0E07\u0E02\u0E27\u0E32"],
|
|
843
|
+
bl: ["bottom-left corner", "\u0E21\u0E38\u0E21\u0E25\u0E48\u0E32\u0E07\u0E0B\u0E49\u0E32\u0E22"],
|
|
844
|
+
corners: ["corners", "\u0E21\u0E38\u0E21"],
|
|
845
|
+
rotate: ["rotate", "\u0E2B\u0E21\u0E38\u0E19"],
|
|
846
|
+
delete: ["delete", "\u0E25\u0E1A"],
|
|
847
|
+
earlier: ["move earlier", "\u0E40\u0E25\u0E37\u0E48\u0E2D\u0E19\u0E02\u0E36\u0E49\u0E19"],
|
|
848
|
+
later: ["move later", "\u0E40\u0E25\u0E37\u0E48\u0E2D\u0E19\u0E25\u0E07"],
|
|
849
|
+
addPage: ["add page", "\u0E40\u0E1E\u0E34\u0E48\u0E21\u0E2B\u0E19\u0E49\u0E32"],
|
|
850
|
+
making: ["making the PDF \xB7 page {n} of {of}", "\u0E01\u0E33\u0E25\u0E31\u0E07\u0E17\u0E33 PDF \xB7 \u0E2B\u0E19\u0E49\u0E32 {n} \u0E08\u0E32\u0E01 {of}"],
|
|
851
|
+
noCam: ["no camera here", "\u0E44\u0E21\u0E48\u0E21\u0E35\u0E01\u0E25\u0E49\u0E2D\u0E07"],
|
|
852
|
+
noCamWhy: ["pick photos of the pages instead: each one gets its corners found the same way", "\u0E40\u0E25\u0E37\u0E2D\u0E01\u0E23\u0E39\u0E1B\u0E02\u0E2D\u0E07\u0E41\u0E15\u0E48\u0E25\u0E30\u0E2B\u0E19\u0E49\u0E32\u0E41\u0E17\u0E19"],
|
|
853
|
+
limit: ["{n} of {n} pages: the most one scan takes", "{n} \u0E08\u0E32\u0E01 {n} \u0E2B\u0E19\u0E49\u0E32: \u0E2A\u0E41\u0E01\u0E19\u0E44\u0E14\u0E49\u0E21\u0E32\u0E01\u0E17\u0E35\u0E48\u0E2A\u0E38\u0E14\u0E40\u0E17\u0E48\u0E32\u0E19\u0E35\u0E49"],
|
|
854
|
+
review: ["review", "\u0E15\u0E23\u0E27\u0E08"],
|
|
855
|
+
strip: ["pages, in order", "\u0E2B\u0E19\u0E49\u0E32\u0E15\u0E32\u0E21\u0E25\u0E33\u0E14\u0E31\u0E1A"],
|
|
856
|
+
denied: ["the camera is blocked for this site", "\u0E01\u0E25\u0E49\u0E2D\u0E07\u0E16\u0E39\u0E01\u0E1B\u0E34\u0E14\u0E2A\u0E33\u0E2B\u0E23\u0E31\u0E1A\u0E40\u0E27\u0E47\u0E1A\u0E19\u0E35\u0E49"],
|
|
857
|
+
deniedWhy: ["allow it in the browser's settings, or pick photos of the pages", "\u0E40\u0E1B\u0E34\u0E14\u0E44\u0E14\u0E49\u0E43\u0E19\u0E01\u0E32\u0E23\u0E15\u0E31\u0E49\u0E07\u0E04\u0E48\u0E32\u0E40\u0E1A\u0E23\u0E32\u0E27\u0E4C\u0E40\u0E0B\u0E2D\u0E23\u0E4C \u0E2B\u0E23\u0E37\u0E2D\u0E40\u0E25\u0E37\u0E2D\u0E01\u0E23\u0E39\u0E1B\u0E02\u0E2D\u0E07\u0E41\u0E15\u0E48\u0E25\u0E30\u0E2B\u0E19\u0E49\u0E32"]
|
|
858
|
+
};
|
|
859
|
+
|
|
860
|
+
// react/src/fields/_view.ts
|
|
861
|
+
var word = (c, key3) => words[key3]?.[c.locale.lang === "th" ? 1 : 0] ?? "";
|
|
862
|
+
|
|
863
|
+
// react/src/fields/_input.ts
|
|
864
|
+
import { createElement as createElement3 } from "react";
|
|
865
|
+
function input(x, c, attrs, password, placeholder) {
|
|
866
|
+
const kb = x.keyboard ?? "default";
|
|
867
|
+
const was = password ? "" : String(x.value ?? "");
|
|
868
|
+
const own3 = { type: password ? "password" : kb === "url" ? "url" : "text", inputMode: kb === "default" ? void 0 : kb === "number" ? "decimal" : "url" };
|
|
869
|
+
const draft = password ? void 0 : c.key + x.name;
|
|
870
|
+
const value3 = c.value == null ? "" : String(c.value);
|
|
871
|
+
return createElement3("input", { ...attrs, ...own3, value: value3, placeholder, autoComplete: "off", "data-was": was, "data-draft": draft, onChange: (e) => c.put(e.target.value) });
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
// react/src/fields/text.ts
|
|
875
|
+
var text = { draw: (x, c, attrs) => input(x, c, attrs, false, x.placeholder ?? "") };
|
|
876
|
+
|
|
877
|
+
// react/src/fields/picker.ts
|
|
878
|
+
import { createElement as createElement4 } from "react";
|
|
879
|
+
var opts = (x) => [...new Set([x.value, ...x.options ?? []].filter((o) => o != null && o !== "").map(String))];
|
|
880
|
+
var picker = {
|
|
881
|
+
draw: (x, c, attrs) => createElement4("select", { ...attrs, value: c.value == null || c.value === "" ? opts(x)[0] : String(c.value), onChange: (e) => c.put(e.target.value) }, ...opts(x).map((o) => createElement4("option", { key: o, value: o }, o))),
|
|
882
|
+
sent: (x, v) => v == null || v === "" ? opts(x)[0] ?? "" : v
|
|
883
|
+
};
|
|
884
|
+
|
|
885
|
+
// react/src/fields/scan.ts
|
|
886
|
+
import { createElement as createElement6, useRef as useRef5, useState as useState7 } from "react";
|
|
887
|
+
import { ids as ids2, scanHeld, scanHint, scanLine, scanned, scanner, send as send2, waits as waits2 } from "./core.js";
|
|
888
|
+
|
|
889
|
+
// react/src/fields/upload.ts
|
|
890
|
+
import { createElement as createElement5, useRef as useRef4, useState as useState6 } from "react";
|
|
891
|
+
import { accepts, fill, held as held2, hint, ids, pick, picked, send, status, waits } from "./core.js";
|
|
892
|
+
function item(line, r, w, drop, again, more = []) {
|
|
893
|
+
const hide = { "aria-hidden": "true" };
|
|
894
|
+
const head4 = r.src && r.state !== "refused" ? h("img", "fut", { ...hide, src: r.src, alt: "" }) : h("span", "fux", hide, r.state === "refused" ? "!" : (r.name.split(".").pop() ?? "").slice(0, 4));
|
|
895
|
+
const p = Math.round(r.part * 100);
|
|
896
|
+
const bar6 = { role: "progressbar", "aria-valuemin": "0", "aria-valuemax": "100", "aria-valuenow": String(p), "aria-label": r.name, style: { "--v": p } };
|
|
897
|
+
const b = (k, f, cls = "") => btn(w(k), cls, void 0, void 0, { "aria-label": `${w(k)} ${r.name}`, onClick: f });
|
|
898
|
+
const acts2 = r.state === "failed" ? [b("retry", () => again(r)), ...more, b("remove", () => drop(r), "bad")] : [...more, b(r.state === "refused" ? "dismiss" : "remove", () => drop(r))];
|
|
899
|
+
const m = h("span", "fum", null, h("span", "fun", null, r.name), r.state === "uploading" ? h("span", "pgt", bar6, h("b", "", null)) : null, h("span", "fus", null, line));
|
|
900
|
+
return h("li", `fui ${r.state}`, { key: r.id ?? `${r.name}~${r.size}`, "aria-label": `${r.name}, ${line}` }, head4, m, h("span", "fua", null, ...acts2));
|
|
901
|
+
}
|
|
902
|
+
function Upload({ x, c, attrs }) {
|
|
903
|
+
const w = (k) => word(c, k);
|
|
904
|
+
const [rows2, setRows] = useState6(() => held2(x));
|
|
905
|
+
const live3 = useRef4(rows2);
|
|
906
|
+
const input3 = useRef4(null);
|
|
907
|
+
const changed = (next) => {
|
|
908
|
+
live3.current = next;
|
|
909
|
+
setRows(next);
|
|
910
|
+
c.hold(ids(next), waits(next));
|
|
911
|
+
};
|
|
912
|
+
const go2 = (r) => c.file && send(r, c.file, { screen: c.screen, block: c.block, field: x.name }, () => changed([...live3.current]));
|
|
913
|
+
const drop = (r) => {
|
|
914
|
+
r.stop?.abort();
|
|
915
|
+
changed(live3.current.filter((o) => o !== r));
|
|
916
|
+
};
|
|
917
|
+
const open2 = (camera) => {
|
|
918
|
+
const i = input3.current;
|
|
919
|
+
if (camera) i?.setAttribute("capture", "environment");
|
|
920
|
+
else i?.removeAttribute("capture");
|
|
921
|
+
i?.click();
|
|
922
|
+
};
|
|
923
|
+
const take = (e) => {
|
|
924
|
+
const files = Array.from(e.target.files ?? []);
|
|
925
|
+
const next = picked(x, live3.current, files, files.map((f) => f.name));
|
|
926
|
+
e.target.value = "";
|
|
927
|
+
changed(next.rows);
|
|
928
|
+
next.send.forEach(go2);
|
|
929
|
+
};
|
|
930
|
+
const label2 = x.label ?? x.name;
|
|
931
|
+
const choice2 = pick(x, rows2, w);
|
|
932
|
+
const tip = hint(x, w, !!c.file);
|
|
933
|
+
const off = !c.file;
|
|
934
|
+
const fub = h(
|
|
935
|
+
"div",
|
|
936
|
+
"fub",
|
|
937
|
+
null,
|
|
938
|
+
x.capture ? btn(w("camera"), "fuc", void 0, void 0, { onClick: () => open2(true) }, off) : null,
|
|
939
|
+
btn(choice2, "", void 0, void 0, { "aria-label": `${choice2}: ${label2}`, onClick: () => open2(false) }, off),
|
|
940
|
+
tip ? h("span", "fuh", null, tip) : null,
|
|
941
|
+
h("input", "", { ref: input3, type: "file", tabIndex: -1, multiple: !!x.many, accept: accepts(x.accept ?? []), "aria-hidden": "true", onChange: take })
|
|
942
|
+
);
|
|
943
|
+
const named4 = { role: "group", "data-field": x.name, "aria-label": fill(w("files"), { label: label2, n: rows2.filter((r) => r.state !== "refused").length }), "aria-invalid": attrs["aria-invalid"] };
|
|
944
|
+
return h("div", "fu", named4, x.error ? h("span", "fe", null, x.error) : null, rows2.length ? h("ul", "fuf", null, ...rows2.map((r) => item(status(x, r, w), r, w, drop, go2))) : null, fub);
|
|
945
|
+
}
|
|
946
|
+
var upload2 = {
|
|
947
|
+
row: " up",
|
|
948
|
+
group: true,
|
|
949
|
+
waits: true,
|
|
950
|
+
draw: (x, c, attrs) => createElement5(Upload, { x, c, attrs }),
|
|
951
|
+
sent: (x) => ids(held2(x))
|
|
952
|
+
};
|
|
953
|
+
|
|
954
|
+
// react/src/fields/scan.ts
|
|
955
|
+
function Scan({ x, c, attrs }) {
|
|
956
|
+
const w = (k) => word(c, k), label2 = x.label ?? x.name, off = !c.file;
|
|
957
|
+
const [rows2, setRows] = useState7(() => scanHeld(x));
|
|
958
|
+
const live3 = useRef5(rows2), kept2 = useRef5(void 0);
|
|
959
|
+
const changed = (next) => {
|
|
960
|
+
live3.current = next;
|
|
961
|
+
setRows(next);
|
|
962
|
+
c.hold(ids2(next), waits2(next));
|
|
963
|
+
};
|
|
964
|
+
const go2 = (r) => c.file && send2(r, c.file, { screen: c.screen, block: c.block, field: x.name }, () => changed([...live3.current]));
|
|
965
|
+
const drop = () => {
|
|
966
|
+
live3.current.forEach((r) => r.stop?.abort());
|
|
967
|
+
kept2.current = void 0;
|
|
968
|
+
changed([]);
|
|
969
|
+
};
|
|
970
|
+
const open2 = async (again2) => {
|
|
971
|
+
const out2 = await (await scanner()).scan({ label: label2, max: x.max ?? 20, w, pages: again2 ? kept2.current : void 0 });
|
|
972
|
+
if (!out2) return;
|
|
973
|
+
live3.current.forEach((r2) => r2.stop?.abort());
|
|
974
|
+
kept2.current = out2.pages;
|
|
975
|
+
const r = scanned(x, out2.pdf, out2.pages.length, out2.pages[0]?.url);
|
|
976
|
+
changed([r]);
|
|
977
|
+
go2(r);
|
|
978
|
+
};
|
|
979
|
+
const named4 = (k, name, f) => btn(w(k), "", void 0, void 0, { "aria-label": `${w(k)}: ${name}`, onClick: f }, off);
|
|
980
|
+
const list3 = rows2.map((r) => item(scanLine(r, w), r, w, drop, go2, kept2.current ? [named4("editPages", r.name, () => open2(true))] : []));
|
|
981
|
+
const again = rows2.length ? "rescan" : "scan";
|
|
982
|
+
const group2 = { role: "group", "data-field": x.name, "aria-label": label2, "aria-invalid": attrs["aria-invalid"] };
|
|
983
|
+
return h("div", "fu", group2, x.error ? h("span", "fe", null, x.error) : null, list3.length ? h("ul", "fuf", null, ...list3) : null, h("div", "fub", null, named4(again, label2, () => open2(false)), h("span", "fuh", null, scanHint(x, w, !off))));
|
|
984
|
+
}
|
|
985
|
+
var scan = {
|
|
986
|
+
row: " up",
|
|
987
|
+
group: true,
|
|
988
|
+
waits: true,
|
|
989
|
+
draw: (x, c, attrs) => createElement6(Scan, { x, c, attrs }),
|
|
990
|
+
sent: (x) => ids2(scanHeld(x))
|
|
991
|
+
};
|
|
992
|
+
|
|
993
|
+
// react/src/fields/search.ts
|
|
994
|
+
import { createElement as createElement7, useRef as useRef6, useState as useState8 } from "react";
|
|
995
|
+
import { fill as fill2, typing } from "./core.js";
|
|
996
|
+
function Search({ x, c, attrs }) {
|
|
997
|
+
const w = (k) => word(c, k);
|
|
998
|
+
const [busy, setBusy] = useState8(false);
|
|
999
|
+
const out2 = useRef6(c.send);
|
|
1000
|
+
out2.current = c.send;
|
|
1001
|
+
const sender = useRef6(null);
|
|
1002
|
+
const send4 = sender.current ??= typing((q2) => out2.current?.(q2), setBusy);
|
|
1003
|
+
const input3 = useRef6(null);
|
|
1004
|
+
const live3 = !!c.send && x.filters == null;
|
|
1005
|
+
const q = c.value == null ? "" : String(c.value);
|
|
1006
|
+
const f = c.found;
|
|
1007
|
+
const hit = f && q && (f.n ? fill2(w("hits"), { n: f.n, m: f.m }) : w("none"));
|
|
1008
|
+
const line = busy ? w("busy") : hit || "";
|
|
1009
|
+
const wipe = () => {
|
|
1010
|
+
c.put("");
|
|
1011
|
+
if (live3) send4.now("");
|
|
1012
|
+
input3.current?.focus();
|
|
1013
|
+
};
|
|
1014
|
+
const enter = (e) => {
|
|
1015
|
+
if (e.key !== "Enter" || !live3) return;
|
|
1016
|
+
e.preventDefault();
|
|
1017
|
+
send4.now(q);
|
|
1018
|
+
};
|
|
1019
|
+
const own3 = { ref: input3, type: "search", value: q, placeholder: x.placeholder ?? "", autoComplete: "off", "data-draft": c.key + x.name, "data-was": String(x.value ?? "") };
|
|
1020
|
+
const typed2 = (e) => (c.put(e.target.value), live3 && send4.key(e.target.value));
|
|
1021
|
+
return h(
|
|
1022
|
+
"span",
|
|
1023
|
+
"sb",
|
|
1024
|
+
{ "aria-busy": busy ? "true" : void 0, "aria-invalid": attrs["aria-invalid"] },
|
|
1025
|
+
h("input", "", { ...attrs, ...own3, onChange: typed2, onKeyDown: enter }),
|
|
1026
|
+
h("span", "sbn", { "aria-live": "polite" }, line),
|
|
1027
|
+
btn(w("clear"), "sbx", void 0, void 0, { hidden: !q, onClick: wipe })
|
|
1028
|
+
);
|
|
1029
|
+
}
|
|
1030
|
+
var search = { row: " sr", draw: (x, c, attrs) => createElement7(Search, { x, c, attrs }) };
|
|
1031
|
+
|
|
1032
|
+
// react/src/fields/secret.ts
|
|
1033
|
+
var secret = {
|
|
1034
|
+
draw: (x, c, attrs) => input({ name: x.name }, c, attrs, true, x.set ? word(c, "set") : x.placeholder ?? word(c, "unset")),
|
|
1035
|
+
sent: (_x, v) => v === "" || v == null ? void 0 : v
|
|
1036
|
+
};
|
|
1037
|
+
|
|
1038
|
+
// react/src/fields/slider.ts
|
|
1039
|
+
import { createElement as createElement8 } from "react";
|
|
1040
|
+
import { along, reads } from "./core.js";
|
|
1041
|
+
var slider = {
|
|
1042
|
+
row: " sl",
|
|
1043
|
+
group: true,
|
|
1044
|
+
draw(x, c, attrs) {
|
|
1045
|
+
const n = typeof c.value === "number" ? c.value : x.value ?? x.min;
|
|
1046
|
+
const [hide, t] = [{ "aria-hidden": "true" }, reads(x, n)];
|
|
1047
|
+
const own3 = { type: "range", min: x.min, max: x.max, step: x.step ?? 1, value: n, "aria-label": x.label ?? x.name, "aria-valuetext": t, "data-was": String(x.value ?? x.min), "data-draft": c.key + x.name };
|
|
1048
|
+
const i = createElement8("input", { ...attrs, ...own3, onChange: (e) => c.put(e.target.valueAsNumber) });
|
|
1049
|
+
const ends2 = h("span", "fse", hide, h("span", "", null, reads(x, x.min)), h("span", "", null, reads(x, x.max)));
|
|
1050
|
+
return h("div", "fs", { "data-field": x.name, "aria-invalid": attrs["aria-invalid"], style: { "--v": along(x, n) } }, i, h("output", "fsv", hide, t), h("span", "fst", hide, h("b", "", null)), h("span", "fsb", hide), ends2, x.error ? h("span", "fe", null, x.error) : null);
|
|
1051
|
+
},
|
|
1052
|
+
sent: (x, v) => typeof v === "number" ? v : x.value ?? x.min
|
|
1053
|
+
};
|
|
1054
|
+
|
|
1055
|
+
// react/src/fields/toggle.ts
|
|
1056
|
+
import { createElement as createElement9 } from "react";
|
|
1057
|
+
var toggle = {
|
|
1058
|
+
row: " tg",
|
|
1059
|
+
draw: (x, c, attrs) => createElement9("input", { ...attrs, type: "checkbox", role: x.as === "check" ? void 0 : "switch", checked: !!c.value, onChange: (e) => c.put(e.target.checked) }),
|
|
1060
|
+
sent: (_x, v) => !!v
|
|
1061
|
+
};
|
|
1062
|
+
|
|
1063
|
+
// react/src/gen/fields.ts
|
|
1064
|
+
var views = { picker, scan, search, secret, slider, text, toggle, upload: upload2 };
|
|
1065
|
+
|
|
1066
|
+
// react/src/kinds/form.ts
|
|
1067
|
+
var viewOf = (x) => views[x.type] ?? text;
|
|
1068
|
+
var note = (x, was) => x.error ? ["fn err", x.error] : x.was != null ? ["fn was", `${was} ${x.was}`] : ["fn", x.doc ?? ""];
|
|
1069
|
+
function field(x, key3, cx, held3, shown4) {
|
|
1070
|
+
const v = viewOf(x);
|
|
1071
|
+
const [cls, say2] = shown4 ?? note(v.group ? { ...x, error: null } : x, word(cx, "was"));
|
|
1072
|
+
const said5 = Object.prototype.hasOwnProperty.call(cx.edits, x.name) ? cx.v.says[x.name] : void 0;
|
|
1073
|
+
const attrs = { name: x.name, disabled: cx.v.disabled.has(x.name) || void 0, "aria-invalid": x.error ? "true" : void 0 };
|
|
1074
|
+
const hold = (sent2, w) => {
|
|
1075
|
+
held3.sent[x.name] = sent2;
|
|
1076
|
+
held3.wait(x.name, w);
|
|
1077
|
+
cx.put(x.name, lit(x, sent2));
|
|
1078
|
+
};
|
|
1079
|
+
const c = { locale: cx.locale, key: key3, value: cx.state[x.name] ?? null, put: (to) => cx.put(x.name, to), screen: cx.screen, block: held3.block, file: cx.file, hold, send: held3.send && ((v2) => held3.send?.(x.name, v2)), found: "filters" in x && typeof x.filters === "string" ? cx.seek[x.filters] : void 0 };
|
|
1080
|
+
const control = v.draw(x, c, attrs);
|
|
1081
|
+
const l = `fd${v.row ?? ""}${held3.solo ? " solo" : ""}${x.error ? " err" : ""}${x.open ? " open" : ""}`;
|
|
1082
|
+
return h(v.group ? "div" : "label", l, { key: x.name, hidden: cx.v.hidden.has(x.name) || void 0 }, h("span", "fl", null, h("span", "fk", null, x.label ?? x.name), h("span", cls, null, say2)), control, said5 ? h("span", "fe", null, said5) : null);
|
|
1083
|
+
}
|
|
1084
|
+
function values(fields2, sent2, cx) {
|
|
1085
|
+
const v = {};
|
|
1086
|
+
for (const x of fields2) {
|
|
1087
|
+
const own3 = viewOf(x).sent;
|
|
1088
|
+
const got = Object.prototype.hasOwnProperty.call(sent2, x.name) ? sent2[x.name] : own3 ? own3(x, cx.state[x.name] ?? null) : cx.state[x.name];
|
|
1089
|
+
if (typeof got === "string" || typeof got === "boolean" || typeof got === "number" || Array.isArray(got)) v[x.name] = got;
|
|
1090
|
+
}
|
|
1091
|
+
return v;
|
|
1092
|
+
}
|
|
1093
|
+
function form({ b, hooks: hooks4 }) {
|
|
1094
|
+
const cx = useContext6(Cx);
|
|
1095
|
+
const s = b.submit;
|
|
1096
|
+
const sent2 = useRef7({});
|
|
1097
|
+
const [waits4, setWaits] = useState9({});
|
|
1098
|
+
const live3 = s ? void 0 : b.action;
|
|
1099
|
+
const out2 = live3 ? (name, v) => cx.act({ action: live3, block: b.id, values: { [name]: v } }) : void 0;
|
|
1100
|
+
const held3 = { sent: sent2.current, wait: (n, w) => setWaits((o) => ({ ...o, [n]: w })), block: b.id ?? void 0, send: out2, solo: !s && b.fields.length === 1 };
|
|
1101
|
+
const rows2 = b.fields.map((x) => field(x, `draft:${cx.screen}:${String(b.id)}:`, cx, held3));
|
|
1102
|
+
if (!s) return h("div", "form as-surface", { ...hooks4, "data-id": b.id ?? "" }, ...rows2);
|
|
1103
|
+
const send4 = () => {
|
|
1104
|
+
const v = values(b.fields, sent2.current, cx);
|
|
1105
|
+
if (Object.values(v).every((x) => !String(x || "").trim())) return;
|
|
1106
|
+
void cx.act({ action: s.action, block: b.id, values: { ...s.values, ...v } }).then((ok) => ok && b.fields.forEach((x) => cx.put(x.name, void 0)));
|
|
1107
|
+
};
|
|
1108
|
+
const enter = (e) => {
|
|
1109
|
+
if (e.key !== "Enter" || !(e.target instanceof HTMLInputElement) || e.target.type === "checkbox") return;
|
|
1110
|
+
e.preventDefault();
|
|
1111
|
+
send4();
|
|
1112
|
+
};
|
|
1113
|
+
const busy = cx.busy.has(b.id ?? s.action);
|
|
1114
|
+
const all = Object.values(waits4), up = all.reduce((n, w) => n + w.up, 0), bad = all.some((w) => w.failed > 0);
|
|
1115
|
+
const off = b.id != null && cx.v.disabled.has(b.id) || up > 0 || bad;
|
|
1116
|
+
const go2 = btn(busy ? "sending\u2026" : s.label, "", void 0, s.action, { "data-submit": "", onClick: send4 }, off);
|
|
1117
|
+
const line = bad ? word(cx, "stuck") : up ? fill3(word(cx, up > 1 ? "waitN" : "wait1"), { n: up }) : "";
|
|
1118
|
+
const wait = b.fields.some((x) => viewOf(x).waits) ? h("span", `say-busy${bad ? " bad" : ""}`, null, line) : null;
|
|
1119
|
+
return h("div", "form say", { ...hooks4, "data-id": b.id ?? "", onKeyDown: enter }, ...rows2, wait, go2);
|
|
1120
|
+
}
|
|
1121
|
+
|
|
1122
|
+
// react/src/kinds/config.ts
|
|
1123
|
+
var typed = (i) => {
|
|
1124
|
+
if (i instanceof HTMLSelectElement) return i.value;
|
|
1125
|
+
if (i.type === "checkbox") return i.checked;
|
|
1126
|
+
return i.type === "range" ? Number(i.value) : i.value;
|
|
1127
|
+
};
|
|
1128
|
+
function config({ b, hooks: hooks4 }) {
|
|
1129
|
+
const cx = useContext7(Cx);
|
|
1130
|
+
const live3 = useRef8(cx);
|
|
1131
|
+
live3.current = cx;
|
|
1132
|
+
const root = useRef8(null);
|
|
1133
|
+
const sent2 = useRef8({});
|
|
1134
|
+
const [notes, setNotes] = useState10({});
|
|
1135
|
+
const save2 = (name, v) => {
|
|
1136
|
+
const a = b.action;
|
|
1137
|
+
if (!a || v === "" || v === void 0) return;
|
|
1138
|
+
const say2 = (n) => setNotes((o) => ({ ...Object.fromEntries(Object.entries(o).filter(([k]) => k !== name)), ...n ? { [name]: n } : null }));
|
|
1139
|
+
say2(["fn", "saving\u2026"]);
|
|
1140
|
+
void live3.current.act({ action: a, block: b.id, values: { [name]: v } }).then((ok) => ok ? (say2(null), live3.current.put(name, void 0)) : say2(["fn err", "not saved"]));
|
|
1141
|
+
};
|
|
1142
|
+
const commit = useRef8(save2);
|
|
1143
|
+
commit.current = save2;
|
|
1144
|
+
useEffect3(() => {
|
|
1145
|
+
const f = root.current;
|
|
1146
|
+
const open2 = b.fields.find((x) => x.open);
|
|
1147
|
+
if (open2) f?.querySelector(`[name="${CSS.escape(open2.name)}"]`)?.focus();
|
|
1148
|
+
const heard = (e) => {
|
|
1149
|
+
const t = e.target;
|
|
1150
|
+
if (t instanceof HTMLSelectElement || t instanceof HTMLInputElement && t.type !== "file") commit.current(t.name, typed(t));
|
|
1151
|
+
};
|
|
1152
|
+
f?.addEventListener("change", heard);
|
|
1153
|
+
return () => f?.removeEventListener("change", heard);
|
|
1154
|
+
}, []);
|
|
1155
|
+
const held3 = { sent: sent2.current, wait: (n, w) => w.up + w.failed === 0 && save2(n, sent2.current[n]), block: b.id ?? void 0 };
|
|
1156
|
+
const rows2 = b.fields.map((x) => field(x, `draft:${cx.screen}:${String(b.id)}:`, cx, held3, notes[x.name]));
|
|
1157
|
+
const s = b.submit;
|
|
1158
|
+
const go2 = () => s && void cx.act({ action: s.action, block: b.id, values: { ...s.values, ...values(b.fields, sent2.current, cx) } }).then((ok) => ok && b.fields.forEach((x) => cx.put(x.name, void 0)));
|
|
1159
|
+
const bar6 = s ? h("div", "bar", null, btn(s.label, "", void 0, s.action, { onClick: go2 }, !!s.off)) : null;
|
|
1160
|
+
return h("div", "form cfg as-surface", { ...hooks4, ref: root, "data-id": b.id ?? "" }, ...rows2, bar6);
|
|
1161
|
+
}
|
|
1162
|
+
|
|
1163
|
+
// react/src/kinds/diagram.ts
|
|
1164
|
+
import { createElement as createElement10, useContext as useContext8, useMemo as useMemo2 } from "react";
|
|
1165
|
+
|
|
1166
|
+
// src/core/kind/diagram.ts
|
|
1167
|
+
var WIDE = { cls: "wide", widths: [156, 176, 140], gap: 40, gutter: 18, height: 54, rowGap: 22 };
|
|
1168
|
+
var PHONE = { cls: "phone", widths: [108, 100, 78], gap: 22, gutter: 12, height: 46, rowGap: 20 };
|
|
1169
|
+
var TOP = 34;
|
|
1170
|
+
var seen = /* @__PURE__ */ new Map();
|
|
1171
|
+
var same2 = (a, b) => JSON.stringify(Object.entries(a).sort()) === JSON.stringify(Object.entries(b).sort());
|
|
1172
|
+
var isObj = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
1173
|
+
var obj = (v) => isObj(v) ? v : {};
|
|
1174
|
+
var node = (b, id) => {
|
|
1175
|
+
const nodes2 = b["nodes"];
|
|
1176
|
+
return obj(Array.isArray(nodes2) ? nodes2.find((n) => obj(n)["id"] === id) : obj(nodes2)[id]);
|
|
1177
|
+
};
|
|
1178
|
+
function chart(source) {
|
|
1179
|
+
const order2 = [], spine = [], parsed2 = [], edges = [];
|
|
1180
|
+
const names2 = /* @__PURE__ */ new Map(), row5 = /* @__PURE__ */ new Map(), side = /* @__PURE__ */ new Map(), optional = /* @__PURE__ */ new Set();
|
|
1181
|
+
const add = (id2) => void (id2 !== "[*]" && !order2.includes(id2) && order2.push(id2));
|
|
1182
|
+
for (const line of source.split("\n").map((l) => l.trim())) {
|
|
1183
|
+
const [, label2, id2] = /^state\s+"([^"]+)"\s+as\s+(\w+)$/.exec(line) ?? [];
|
|
1184
|
+
const [, alone] = /^state\s+(\w+)$/.exec(line) ?? [];
|
|
1185
|
+
const [, from, into] = /^(\[\*\]|\w+)\s*-->\s*(\[\*\]|\w+)/.exec(line) ?? [];
|
|
1186
|
+
if (label2 && id2) {
|
|
1187
|
+
names2.set(id2, label2);
|
|
1188
|
+
add(id2);
|
|
1189
|
+
} else if (alone) add(alone);
|
|
1190
|
+
else if (from && into) {
|
|
1191
|
+
add(from);
|
|
1192
|
+
add(into);
|
|
1193
|
+
parsed2.push({ from, into, both: false });
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
1196
|
+
const at2 = (id2) => order2.indexOf(id2);
|
|
1197
|
+
const forward = parsed2.filter((e) => at2(e.from) >= 0 && at2(e.from) < at2(e.into));
|
|
1198
|
+
const length = /* @__PURE__ */ new Map(), next = /* @__PURE__ */ new Map();
|
|
1199
|
+
const len = (id2) => length.get(id2) ?? 1;
|
|
1200
|
+
for (const id2 of [...order2].reverse())
|
|
1201
|
+
for (const e of forward)
|
|
1202
|
+
if (e.from === id2 && len(e.into) + 1 > len(id2)) {
|
|
1203
|
+
length.set(id2, len(e.into) + 1);
|
|
1204
|
+
next.set(id2, e.into);
|
|
1205
|
+
}
|
|
1206
|
+
let id = parsed2.find((e) => e.from === "[*]")?.into ?? order2[0];
|
|
1207
|
+
while (id !== void 0 && !spine.includes(id)) {
|
|
1208
|
+
row5.set(id, spine.length);
|
|
1209
|
+
side.set(id, 0);
|
|
1210
|
+
spine.push(id);
|
|
1211
|
+
id = next.get(id);
|
|
1212
|
+
}
|
|
1213
|
+
for (const e of forward) {
|
|
1214
|
+
const a = spine.indexOf(e.from), z = spine.indexOf(e.into);
|
|
1215
|
+
if (a >= 0 && z > a + 1) spine.slice(a + 1, z).forEach((s) => optional.add(s));
|
|
1216
|
+
}
|
|
1217
|
+
for (const id2 of order2.filter((o) => !side.has(o))) {
|
|
1218
|
+
const touching = parsed2.flatMap((e) => e.from === id2 ? [e.into] : e.into === id2 ? [e.from] : []).filter((n) => side.get(n) === 0);
|
|
1219
|
+
const before2 = parsed2.filter((e) => e.into === id2 && row5.has(e.from)).map((e) => e.from);
|
|
1220
|
+
let column2 = 1, place3 = 0;
|
|
1221
|
+
if (touching.length) {
|
|
1222
|
+
place3 = Math.min(...touching.map((n) => row5.get(n) ?? 0));
|
|
1223
|
+
column2 = parsed2.some((e) => e.from === id2 && side.get(e.into) === 0) ? 1 : -1;
|
|
1224
|
+
} else if (before2.length) {
|
|
1225
|
+
place3 = Math.max(...before2.map((b) => row5.get(b) ?? 0)) + 1;
|
|
1226
|
+
column2 = before2.map((b) => side.get(b)).find((s) => s !== 0) ?? 1;
|
|
1227
|
+
}
|
|
1228
|
+
while ([...side].some(([k, s]) => s === column2 && row5.get(k) === place3)) place3 += 1;
|
|
1229
|
+
row5.set(id2, place3);
|
|
1230
|
+
side.set(id2, column2);
|
|
1231
|
+
}
|
|
1232
|
+
for (const e of parsed2) {
|
|
1233
|
+
const a = row5.get(e.from), z = row5.get(e.into);
|
|
1234
|
+
if (a === void 0 || z === void 0 || side.get(e.from) === 0 && side.get(e.into) === 0 && Math.abs(a - z) > 1) continue;
|
|
1235
|
+
const twin = edges.find((t) => t.from === e.into && t.into === e.from);
|
|
1236
|
+
if (twin) twin.both = true;
|
|
1237
|
+
else edges.push({ ...e });
|
|
1238
|
+
}
|
|
1239
|
+
return { order: order2, names: names2, spine, row: row5, side, optional, edges, rows: Math.max(-1, ...row5.values()) + 1 };
|
|
1240
|
+
}
|
|
1241
|
+
var d = (pts) => `M${pts.map((p) => p.join(" ")).join("L")}`;
|
|
1242
|
+
var head = (tip, back) => {
|
|
1243
|
+
const a = Math.atan2(tip[1] - back[1], tip[0] - back[0]);
|
|
1244
|
+
return { d: d([-0.45, 0, 0.45].map((t) => t ? [tip[0] - 8 * Math.cos(a + t), tip[1] - 8 * Math.sin(a + t)] : tip)), cls: "dgh" };
|
|
1245
|
+
};
|
|
1246
|
+
function route(f, t, s, m) {
|
|
1247
|
+
const down = t.my > f.my;
|
|
1248
|
+
if (f.my === t.my) return f.mx < t.mx ? [[f.x + f.w, f.my], [t.x, t.my]] : [[f.x, f.my], [t.x + t.w, t.my]];
|
|
1249
|
+
if (f.mx === t.mx && Math.abs(f.my - t.my) <= m.height + m.rowGap + 1) return [[f.mx, down ? f.y + f.h : f.y], [t.mx, down ? t.y : t.y + t.h]];
|
|
1250
|
+
if (f.mx === t.mx) {
|
|
1251
|
+
const ex = s < 0 ? f.x : f.x + f.w, gx = ex + (s < 0 ? -1 : 1) * (m.gutter - 3);
|
|
1252
|
+
return [[ex, f.my], [gx, f.my], [gx, t.my], [ex, t.my]];
|
|
1253
|
+
}
|
|
1254
|
+
if (s === 0) return [[t.mx > f.mx ? f.x + f.w : f.x, f.my], [t.mx, f.my], [t.mx, down ? t.y : t.y + t.h]];
|
|
1255
|
+
return [[f.mx, down ? f.y + f.h : f.y], [f.mx, t.my], [t.mx > f.mx ? t.x : t.x + t.w, t.my]];
|
|
1256
|
+
}
|
|
1257
|
+
function place(g, b, id, at2, counts, was) {
|
|
1258
|
+
const n = node(b, id);
|
|
1259
|
+
const name = g.names.get(id) ?? id, label2 = String(n["label"] ?? name), tap = n["tap"];
|
|
1260
|
+
const base = { id, at: at2, title: label2, tap };
|
|
1261
|
+
if (n["limit"] != null) {
|
|
1262
|
+
const value3 = String(n["value"] ?? "");
|
|
1263
|
+
return { ...base, name: label2, cls: "dgn timer", aria: `${label2} ${value3}, opens its setting`, timer: { value: value3 }, count: null };
|
|
1264
|
+
}
|
|
1265
|
+
const count = counts[id] ?? 0, before2 = was[id], moved3 = before2 !== void 0 && before2 !== count, opt = g.optional.has(id);
|
|
1266
|
+
const cls = `dgn ${String(n["state"] ?? "idle")}${count === 0 ? " zero" : ""}${moved3 ? " moved" : ""}${b["selected"] === id ? " picked" : ""}`;
|
|
1267
|
+
const note2 = moved3 ? { cls: "", text: `was ${before2}` } : opt ? { cls: "opt", text: "optional" } : null;
|
|
1268
|
+
return { ...base, name, cls, aria: `${name}, ${count} issue${count === 1 ? "" : "s"}${opt ? ", optional" : ""}`, timer: null, count: { n: String(count), note: note2 } };
|
|
1269
|
+
}
|
|
1270
|
+
function plan(g, b, m, counts, was) {
|
|
1271
|
+
const centre = /* @__PURE__ */ new Map(), used = new Set(g.side.values());
|
|
1272
|
+
let left = m.gutter;
|
|
1273
|
+
for (const s of [-1, 0, 1].filter((s2) => used.has(s2))) {
|
|
1274
|
+
const w = m.widths[s + 1] ?? 0;
|
|
1275
|
+
centre.set(s, left + w / 2);
|
|
1276
|
+
left += w + m.gap;
|
|
1277
|
+
}
|
|
1278
|
+
const box = (id) => {
|
|
1279
|
+
const s = g.side.get(id) ?? 0, w = m.widths[s + 1] ?? 0, y = TOP + (g.row.get(id) ?? 0) * (m.height + m.rowGap), mx = centre.get(s) ?? 0;
|
|
1280
|
+
return { x: mx - w / 2, y, w, h: m.height, mx, my: y + m.height / 2 };
|
|
1281
|
+
};
|
|
1282
|
+
const limited = (id) => node(b, id)["limit"] != null;
|
|
1283
|
+
const paths = [];
|
|
1284
|
+
const first2 = g.spine[0] === void 0 ? null : box(g.spine[0]);
|
|
1285
|
+
if (first2) paths.push({ d: d([[first2.mx, 16], [first2.mx, first2.y]]), cls: "dge" });
|
|
1286
|
+
for (const e of g.edges) {
|
|
1287
|
+
const pts = route(box(e.from), box(e.into), g.side.get(e.from) ?? 0, m);
|
|
1288
|
+
paths.push({ d: d(pts), cls: limited(e.from) || limited(e.into) ? "dge timer" : "dge" });
|
|
1289
|
+
const [tip, back] = [pts[pts.length - 1], pts[pts.length - 2]];
|
|
1290
|
+
if (tip && back) paths.push(head(tip, back));
|
|
1291
|
+
const [start2, after] = pts;
|
|
1292
|
+
if (e.both && start2 && after) paths.push(head(start2, after));
|
|
1293
|
+
}
|
|
1294
|
+
const height2 = TOP + g.rows * (m.height + m.rowGap) - m.rowGap + 12;
|
|
1295
|
+
return { cls: m.cls, width: left - m.gap + m.gutter, height: height2, dot: first2 ? { cx: first2.mx, cy: 10 } : null, paths, places: g.order.map((id) => place(g, b, id, box(id), counts, was)) };
|
|
1296
|
+
}
|
|
1297
|
+
function diagrams(b) {
|
|
1298
|
+
const g = chart(String(b["source"] ?? ""));
|
|
1299
|
+
if (!g.order.length) return [];
|
|
1300
|
+
const counts = Object.fromEntries(Object.entries(obj(b["counts"])).map(([k, v]) => [k, Number(v)]));
|
|
1301
|
+
const key3 = String(b["id"] ?? ""), prev = seen.get(key3);
|
|
1302
|
+
const was = !prev ? {} : same2(prev.counts, counts) ? prev.was : prev.counts;
|
|
1303
|
+
seen.set(key3, { counts, was });
|
|
1304
|
+
return [WIDE, PHONE].map((m) => plan(g, b, m, counts, was));
|
|
1305
|
+
}
|
|
1306
|
+
|
|
1307
|
+
// react/src/kinds/diagram.ts
|
|
1308
|
+
var isTap = (v) => typeof v === "object" && v !== null;
|
|
1309
|
+
function state(p, cx) {
|
|
1310
|
+
const note2 = p.count?.note;
|
|
1311
|
+
const body2 = p.timer ? [h("span", "", { "aria-hidden": "true" }, "\u29D7"), h("span", "", null, h("span", "dgl", null, p.name), h("span", "dgv", null, p.timer.value))] : [h("span", p.cls.split(" ").includes("picked") ? "dgl as-picked-label" : "dgl", null, p.name), h("span", "dgc", null, p.count?.n ?? "", note2 ? h("small", note2.cls, null, note2.text) : null)];
|
|
1312
|
+
const tap = p.tap;
|
|
1313
|
+
const own3 = { key: p.id, "aria-label": p.aria, title: p.title, style: { left: p.at.x, top: p.at.y, width: p.at.w, height: p.at.h } };
|
|
1314
|
+
return h("div", `${p.cls}${tap ? " tap" : ""}`, { ...own3, ...isTap(tap) ? press(() => cx.tap(tap)) : null }, ...body2);
|
|
1315
|
+
}
|
|
1316
|
+
function map(p, cx) {
|
|
1317
|
+
const dot = p.dot ? h("circle", "dgs", { ...p.dot, r: 6 }) : null;
|
|
1318
|
+
const svg = h("svg", "", { width: p.width, height: p.height, "aria-hidden": "true" }, dot, ...p.paths.map((x, i) => h("path", x.cls, { key: i, d: x.d })));
|
|
1319
|
+
return h("div", `dgm ${p.cls}`, { key: p.cls, style: { width: p.width, height: p.height } }, svg, ...p.places.map((x) => state(x, cx)));
|
|
1320
|
+
}
|
|
1321
|
+
function diagram({ b, hooks: hooks4 }) {
|
|
1322
|
+
const cx = useContext8(Cx);
|
|
1323
|
+
const plans = useMemo2(() => diagrams(b), [b]);
|
|
1324
|
+
return plans.length ? h("div", "dg", hooks4, ...plans.map((p) => map(p, cx))) : createElement10(Fallen, { b });
|
|
1325
|
+
}
|
|
1326
|
+
|
|
1327
|
+
// react/src/kinds/diff.ts
|
|
1328
|
+
import { createElement as createElement11 } from "react";
|
|
1329
|
+
var mark = (line) => line.startsWith("+") ? "add" : line.startsWith("-") ? "del" : "ctx";
|
|
1330
|
+
function diff({ b, hooks: hooks4 }) {
|
|
1331
|
+
if (typeof b.file !== "string" || !Array.isArray(b.hunks)) return createElement11(Fallen, { b });
|
|
1332
|
+
const head4 = h("div", "dfh", null, h("span", "dff", null, b.file), b.summary != null ? h("span", "dfs", null, b.summary) : null);
|
|
1333
|
+
const lines = b.hunks.flatMap((k) => [h("div", "dfk", null, k.at), ...k.lines.map((l) => h("div", `dfl ${mark(l)}`, null, h("i", "dfm", null, l.slice(0, 1) || " "), l.slice(1)))]);
|
|
1334
|
+
return h("div", "df", hooks4, head4, b.hunks.length ? h("div", "dfb", null, ...lines) : null);
|
|
1335
|
+
}
|
|
1336
|
+
|
|
1337
|
+
// react/src/kinds/editor.ts
|
|
1338
|
+
import { useContext as useContext9, useEffect as useEffect4, useRef as useRef9, useState as useState11 } from "react";
|
|
1339
|
+
function editor({ b, hooks: hooks4 }) {
|
|
1340
|
+
const cx = useContext9(Cx);
|
|
1341
|
+
const [text4, setText] = useState11(null);
|
|
1342
|
+
const live3 = useRef9({ b, cx });
|
|
1343
|
+
live3.current = { b, cx };
|
|
1344
|
+
const timer = useRef9(void 0);
|
|
1345
|
+
const area = useRef9(null);
|
|
1346
|
+
useEffect4(() => area.current?.focus(), [text4 === null]);
|
|
1347
|
+
useEffect4(() => () => clearTimeout(timer.current), []);
|
|
1348
|
+
const first2 = b.first ?? 1;
|
|
1349
|
+
const lines = b.text.split("\n");
|
|
1350
|
+
const errs = /* @__PURE__ */ new Map();
|
|
1351
|
+
for (const e of b.errors ?? []) if (!errs.has(e.line)) errs.set(e.line, e.message);
|
|
1352
|
+
const notes = (cls, keep) => [...errs].filter(([n]) => keep(n)).sort((x, y) => x[0] - y[0]).map(([n, m]) => h("p", cls, { key: `e${n}` }, `line ${n} \xB7 ${m}`));
|
|
1353
|
+
if (text4 !== null) {
|
|
1354
|
+
const edit2 = (e) => {
|
|
1355
|
+
const v = e.target.value;
|
|
1356
|
+
setText(v);
|
|
1357
|
+
clearTimeout(timer.current);
|
|
1358
|
+
timer.current = setTimeout(() => {
|
|
1359
|
+
const o = live3.current;
|
|
1360
|
+
if (v !== o.b.text) void o.cx.act({ action: o.b.action, block: o.b.id, values: { [o.b.name]: v } });
|
|
1361
|
+
}, 400);
|
|
1362
|
+
};
|
|
1363
|
+
const ta = h("textarea", "", { ref: area, name: b.name, value: text4, spellCheck: false, "aria-label": b.name, onChange: edit2 });
|
|
1364
|
+
return h("div", "ed on", { ...hooks4, role: "group" }, ta, ...notes("ede", () => true));
|
|
1365
|
+
}
|
|
1366
|
+
const start2 = () => setText(b.text);
|
|
1367
|
+
const key3 = (e) => {
|
|
1368
|
+
if (e.key !== "Enter" && e.key !== " ") return;
|
|
1369
|
+
e.preventDefault();
|
|
1370
|
+
start2();
|
|
1371
|
+
};
|
|
1372
|
+
const rows2 = lines.flatMap((t, i) => {
|
|
1373
|
+
const m = errs.get(first2 + i);
|
|
1374
|
+
return [h("div", m == null ? "edl" : "edl err", null, h("i", "", null, String(first2 + i)), h("span", "", null, t || " ")), m == null ? null : h("p", "ede", null, m)];
|
|
1375
|
+
});
|
|
1376
|
+
const far = notes("ede far", (n) => n < first2 || n >= first2 + lines.length);
|
|
1377
|
+
return h("div", "ed", { ...hooks4, role: "button", tabIndex: 0, onClick: start2, onKeyDown: key3 }, ...rows2, ...far);
|
|
1378
|
+
}
|
|
1379
|
+
|
|
1380
|
+
// react/src/kinds/hero.ts
|
|
1381
|
+
import { useContext as useContext11 } from "react";
|
|
1382
|
+
|
|
1383
|
+
// react/src/kinds/media.ts
|
|
1384
|
+
import { createElement as createElement12, Fragment, useContext as useContext10, useLayoutEffect as useLayoutEffect3, useReducer, useRef as useRef10, useState as useState12 } from "react";
|
|
1385
|
+
|
|
1386
|
+
// src/core/kind/media.ts
|
|
1387
|
+
var SMALL = 0.02;
|
|
1388
|
+
var SIDE = 0.05;
|
|
1389
|
+
var MIDDLE = [0.5, 0.5];
|
|
1390
|
+
var WORDS = { arrow: "Arrow", box: "Box", ellipse: "Ellipse", text: "Text", pin: "Pin", highlight: "Highlight", line: "Line" };
|
|
1391
|
+
var TWO = /* @__PURE__ */ new Set(["arrow", "box", "ellipse", "highlight", "line"]);
|
|
1392
|
+
var round = (x) => Math.round(Math.min(1, Math.max(0, x)) * 1e4) / 1e4 + 0;
|
|
1393
|
+
var snap = ([x, y]) => [round(x), round(y)];
|
|
1394
|
+
var spot = (p) => p?.length === 2 && p[0] !== void 0 && p[1] !== void 0 ? [p[0], p[1]] : null;
|
|
1395
|
+
var ends = (c) => {
|
|
1396
|
+
const at2 = spot(c.at);
|
|
1397
|
+
const to = c.to === void 0 ? null : spot(c.to);
|
|
1398
|
+
return at2 && (c.to === void 0 || to) ? [at2, to] : null;
|
|
1399
|
+
};
|
|
1400
|
+
var big = ([ax, ay], [tx, ty]) => Math.max(Math.abs(tx - ax), Math.abs(ty - ay)) >= SMALL;
|
|
1401
|
+
var placed = (c, at2, to) => {
|
|
1402
|
+
const { to: _, ...rest } = c;
|
|
1403
|
+
return to ? { ...rest, at: snap(at2), to: snap(to) } : { ...rest, at: snap(at2) };
|
|
1404
|
+
};
|
|
1405
|
+
var moved = (c, [dx, dy]) => {
|
|
1406
|
+
const e = ends(c);
|
|
1407
|
+
if (!e) return null;
|
|
1408
|
+
const [[ax, ay], to] = e;
|
|
1409
|
+
const [tx, ty] = to ?? [ax, ay];
|
|
1410
|
+
const x = Math.min(Math.max(dx, -Math.min(ax, tx)), 1 - Math.max(ax, tx));
|
|
1411
|
+
const y = Math.min(Math.max(dy, -Math.min(ay, ty)), 1 - Math.max(ay, ty));
|
|
1412
|
+
return placed(c, [ax + x, ay + y], to && [tx + x, ty + y]);
|
|
1413
|
+
};
|
|
1414
|
+
var stretched = (c, end, [dx, dy]) => {
|
|
1415
|
+
const e = ends(c);
|
|
1416
|
+
if (!e?.[1]) return null;
|
|
1417
|
+
const [at2, to] = [e[0], e[1]];
|
|
1418
|
+
const [[x, y], fixed] = end ? [to, at2] : [at2, to];
|
|
1419
|
+
const pulled = snap([x + dx, y + dy]);
|
|
1420
|
+
const [a, t] = end ? [fixed, pulled] : [pulled, fixed];
|
|
1421
|
+
return big(a, t) ? placed(c, a, t) : null;
|
|
1422
|
+
};
|
|
1423
|
+
var made = (p, at2, to) => {
|
|
1424
|
+
const text4 = p.tool === "text" ? p.text?.trim() && p.text : void 0;
|
|
1425
|
+
if (p.tool === "text" && !text4) return null;
|
|
1426
|
+
const c = { kind: p.tool };
|
|
1427
|
+
if (text4) c.text = text4;
|
|
1428
|
+
if (p.group != null) c.group = p.group;
|
|
1429
|
+
return placed(c, at2, to);
|
|
1430
|
+
};
|
|
1431
|
+
var drawn = (p, from, to) => {
|
|
1432
|
+
const [f, t] = [snap(from), snap(to)];
|
|
1433
|
+
if (p.tool === "pin" || p.tool === "text") return made(p, t, null);
|
|
1434
|
+
return TWO.has(p.tool) && big(f, t) ? made(p, f, t) : null;
|
|
1435
|
+
};
|
|
1436
|
+
var keyed = (p) => {
|
|
1437
|
+
const [x, y] = p.at ?? MIDDLE;
|
|
1438
|
+
return TWO.has(p.tool) ? made(p, [x - SIDE, y - SIDE], [x + SIDE, y + SIDE]) : made(p, [x, y], null);
|
|
1439
|
+
};
|
|
1440
|
+
var toward = ([dx, dy]) => Math.abs(dx) >= Math.abs(dy) ? dx >= 0 ? "right" : "left" : dy >= 0 ? "down" : "up";
|
|
1441
|
+
var BACK = { left: "right", right: "left", up: "down", down: "up" };
|
|
1442
|
+
var idOf = (g) => "body" in g ? g.body : "start" in g ? g.start : "end" in g ? g.end : "remove" in g ? g.remove : null;
|
|
1443
|
+
var of = (b, id) => b.marks?.find((m) => m.id === id);
|
|
1444
|
+
var live = (b, id, g) => g ? of(b, id) : void 0;
|
|
1445
|
+
var said = (k) => WORDS[k] ?? k;
|
|
1446
|
+
var ninth = ([x, y]) => {
|
|
1447
|
+
const row5 = y < 1 / 3 ? "upper" : y < 2 / 3 ? "middle" : "lower";
|
|
1448
|
+
const col = x < 1 / 3 ? "left" : x < 2 / 3 ? "centre" : "right";
|
|
1449
|
+
return row5 === "middle" && col === "centre" ? "centre" : `${row5} ${col}`;
|
|
1450
|
+
};
|
|
1451
|
+
var named = (b, id) => {
|
|
1452
|
+
const m = of(b, id);
|
|
1453
|
+
if (!m) return null;
|
|
1454
|
+
const n = (b.marks ?? []).filter((o) => o.kind === m.kind).findIndex((o) => o.id === id) + 1;
|
|
1455
|
+
const group2 = m.group != null ? `${m.group}, ` : "";
|
|
1456
|
+
const place3 = ninth(spot(m.at) ?? MIDDLE);
|
|
1457
|
+
const text4 = m.text ?? "";
|
|
1458
|
+
if (m.kind === "text") return `${group2}Text \u201C${text4}\u201D, ${place3}`;
|
|
1459
|
+
if (m.kind === "pin" && text4) return `${group2}Pin ${text4}, ${place3}`;
|
|
1460
|
+
return `${group2}${said(m.kind)} ${n}, ${place3}`;
|
|
1461
|
+
};
|
|
1462
|
+
var media = {
|
|
1463
|
+
word: (b, g) => {
|
|
1464
|
+
const id = idOf(g);
|
|
1465
|
+
const m = id === null ? null : live(b, id, "body" in g ? b.move : "remove" in g ? b.remove : b.stretch);
|
|
1466
|
+
if ("draw" in g) return b.draw != null && b.tools?.includes(g.draw.tool) && g.draw.tool in WORDS ? "draw" : null;
|
|
1467
|
+
if (!m || m.fixed === true) return null;
|
|
1468
|
+
if ("body" in g) return "move";
|
|
1469
|
+
if ("remove" in g) return "remove";
|
|
1470
|
+
return m.to != null ? "stretch" : null;
|
|
1471
|
+
},
|
|
1472
|
+
start: (b, g) => {
|
|
1473
|
+
if (!media.word(b, g)) return null;
|
|
1474
|
+
const m = of(b, idOf(g) ?? "");
|
|
1475
|
+
if (!m) return {};
|
|
1476
|
+
const c = m.to != null ? { id: m.id, at: m.at, to: m.to } : { id: m.id, at: m.at };
|
|
1477
|
+
const e = ends(c);
|
|
1478
|
+
return e && placed(c, e[0], e[1]);
|
|
1479
|
+
},
|
|
1480
|
+
candidate: (b, g, r) => {
|
|
1481
|
+
const s = media.start(b, g);
|
|
1482
|
+
if (!s) return null;
|
|
1483
|
+
const d2 = [r.to[0] - r.from[0], r.to[1] - r.from[1]];
|
|
1484
|
+
if ("body" in g) return moved(s, d2);
|
|
1485
|
+
if ("start" in g) return stretched(s, false, d2);
|
|
1486
|
+
if ("end" in g) return stretched(s, true, d2);
|
|
1487
|
+
if ("remove" in g) return { id: g.remove };
|
|
1488
|
+
return r.from.every((v) => v >= 0 && v <= 1) ? drawn(g.draw, r.from, r.to) : null;
|
|
1489
|
+
},
|
|
1490
|
+
nudge: (b, g, from, by) => {
|
|
1491
|
+
const s = media.start(b, g);
|
|
1492
|
+
if (!s) return null;
|
|
1493
|
+
const k = by.big ? 0.1 : 0.01;
|
|
1494
|
+
const d2 = by.dir === "left" ? [-k, 0] : by.dir === "right" ? [k, 0] : by.dir === "up" ? [0, -k] : [0, k];
|
|
1495
|
+
const next = "draw" in g && JSON.stringify(from) === JSON.stringify(s) ? keyed(g.draw) : "body" in g || "draw" in g ? moved(from, d2) : "start" in g ? stretched(from, false, d2) : "end" in g ? stretched(from, true, d2) : { id: g.remove };
|
|
1496
|
+
return next && JSON.stringify(next) !== JSON.stringify(from) ? next : null;
|
|
1497
|
+
},
|
|
1498
|
+
steps: (b, g) => {
|
|
1499
|
+
const s = media.start(b, g);
|
|
1500
|
+
if (!s) return [];
|
|
1501
|
+
let ways;
|
|
1502
|
+
if ("body" in g) ways = [["Move up", "up"], ["Move down", "down"], ["Move left", "left"], ["Move right", "right"]];
|
|
1503
|
+
else if ("remove" in g) ways = [["Delete", "right"]];
|
|
1504
|
+
else if ("draw" in g) ways = [[`Add ${said(g.draw.tool).toLowerCase()}`, "right"]];
|
|
1505
|
+
else {
|
|
1506
|
+
const e = ends(s);
|
|
1507
|
+
if (!e?.[1]) return [];
|
|
1508
|
+
const [[ax, ay], [tx, ty]] = [e[0], e[1]];
|
|
1509
|
+
const d2 = toward("end" in g ? [tx - ax, ty - ay] : [ax - tx, ay - ty]);
|
|
1510
|
+
ways = [["Longer", d2], ["Shorter", BACK[d2]]];
|
|
1511
|
+
}
|
|
1512
|
+
return ways.map(([n, dir]) => [n, { dir }]).filter(([, n]) => media.nudge(b, g, s, n) !== null);
|
|
1513
|
+
},
|
|
1514
|
+
says: (b, g, c) => {
|
|
1515
|
+
const id = idOf(g);
|
|
1516
|
+
const m = id === null ? void 0 : of(b, id);
|
|
1517
|
+
if ("remove" in g && c.at === void 0) return `Delete ${named(b, g.remove) ?? ""}`;
|
|
1518
|
+
const kind = c.kind ?? m?.kind ?? "arrow";
|
|
1519
|
+
const text4 = c.text ?? m?.text;
|
|
1520
|
+
const what = kind === "text" && text4 != null ? `Text \u201C${text4}\u201D` : said(kind);
|
|
1521
|
+
const e = ends(c);
|
|
1522
|
+
if (!e) return what;
|
|
1523
|
+
return e[1] ? `${what}, ${ninth(e[0])} to ${ninth(e[1])}` : `${what}, ${ninth(e[0])}`;
|
|
1524
|
+
}
|
|
1525
|
+
};
|
|
1526
|
+
|
|
1527
|
+
// react/src/kinds/media.ts
|
|
1528
|
+
var TONES = ["ok", "warn", "bad", "info", "accent", "ink"];
|
|
1529
|
+
var HINT = "pick a tool, then drag on the photo";
|
|
1530
|
+
var ref = () => ({ current: null });
|
|
1531
|
+
var pc = (v) => `${(v ?? 0) * 100}%`;
|
|
1532
|
+
var tone = (m) => typeof m.tone === "string" && TONES.includes(m.tone) ? ` mk-${m.tone}` : "";
|
|
1533
|
+
var str = (v) => typeof v === "string" ? v : void 0;
|
|
1534
|
+
var idle = (e) => (e.dataset["phase"] ?? "idle") === "idle";
|
|
1535
|
+
var merged = (m, c) => c?.at ? { ...m, at: c.at, ...c.to ? { to: c.to } : {} } : m;
|
|
1536
|
+
var isChange = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
1537
|
+
var places2 = (m) => [m.at, ...m.to ? [m.to] : [], ...m.path ?? []].map((p) => [p[0] ?? 0, p[1] ?? 0]);
|
|
1538
|
+
var mirror = (from, g) => new MutationObserver(() => from.dataset["phase"] && g.setAttribute("data-phase", from.dataset["phase"])).observe(from, { attributeFilter: ["data-phase"] });
|
|
1539
|
+
function beside2(el2, wire3) {
|
|
1540
|
+
const n = el2.parentElement?.children.length ?? 0;
|
|
1541
|
+
wire3();
|
|
1542
|
+
el2.after(...Array.from(el2.parentElement?.children ?? []).slice(n));
|
|
1543
|
+
}
|
|
1544
|
+
function shape(m, w, ht) {
|
|
1545
|
+
const [x1, y1] = [(m.at[0] ?? 0) * w, (m.at[1] ?? 0) * ht];
|
|
1546
|
+
const [x2, y2] = [(m.to?.[0] ?? m.at[0] ?? 0) * w, (m.to?.[1] ?? m.at[1] ?? 0) * ht];
|
|
1547
|
+
const both = (t, a2) => [h(t, "mkh", a2), h(t, "mki", a2)];
|
|
1548
|
+
const r = { x: Math.min(x1, x2), y: Math.min(y1, y2), width: Math.abs(x2 - x1), height: Math.abs(y2 - y1) };
|
|
1549
|
+
const body2 = m.path ? both("polyline", { points: m.path.map((p) => `${(p[0] ?? 0) * w},${(p[1] ?? 0) * ht}`).join(" ") }) : m.kind === "line" || m.kind === "arrow" ? both("line", { x1, y1, x2, y2 }) : m.kind === "box" ? both("rect", r) : m.kind === "highlight" ? [h("rect", "mkl", r)] : m.kind === "ellipse" ? both("ellipse", { cx: (x1 + x2) / 2, cy: (y1 + y2) / 2, rx: r.width / 2, ry: r.height / 2 }) : [];
|
|
1550
|
+
if (m.kind !== "arrow" || m.path) return body2;
|
|
1551
|
+
const [a, len] = [Math.atan2(y2 - y1, x2 - x1), Math.max(w, ht) * 0.025];
|
|
1552
|
+
const [bx, by, s, co] = [x2 - len * Math.cos(a), y2 - len * Math.sin(a), len / 2 * Math.sin(a), len / 2 * Math.cos(a)];
|
|
1553
|
+
return [...body2, ...both("polygon", { points: `${x2},${y2} ${bx + s},${by - co} ${bx - s},${by + co}` })];
|
|
1554
|
+
}
|
|
1555
|
+
function label(m) {
|
|
1556
|
+
if (m.kind !== "pin" && m.kind !== "text") return null;
|
|
1557
|
+
const kids3 = m.kind === "pin" ? [h("i", "mkpd", null), m.text ? h("span", "mkn", null, m.text) : null] : [h("span", "mkt", null, m.text ?? "")];
|
|
1558
|
+
return h("span", `mkla${tone(m)}`, { "aria-hidden": "true", style: { left: pc(m.at[0]), top: pc(m.at[1]) } }, ...kids3);
|
|
1559
|
+
}
|
|
1560
|
+
var painted = (b, m, cls = "", g) => ({ art: h("g", `mkd${tone(m)}${m.fixed ? " fixed" : ""}${cls}`, g ? { ref: g } : null, ...shape(m, b.width, b.height)), top: label(m) });
|
|
1561
|
+
function frame(b, img, art, top, o = {}) {
|
|
1562
|
+
const svg = h("svg", "mkv", { viewBox: `0 0 ${b.width} ${b.height}`, preserveAspectRatio: "none", "aria-hidden": "true" }, ...art);
|
|
1563
|
+
const z = h("div", "mkz", { ref: o.z, style: { aspectRatio: `${b.width} / ${b.height}` } }, img, svg, o.under, h("div", "mko", null, ...top));
|
|
1564
|
+
return h("div", `mkw${o.cls ?? ""}`, { ref: o.w, style: { width: `min(100%, ${b.width}px)` } }, z);
|
|
1565
|
+
}
|
|
1566
|
+
function still(b, hooks4) {
|
|
1567
|
+
const marks = b.marks ?? [];
|
|
1568
|
+
const alt = marks.length ? `${b.alt}. ${marks.length} marks: ${marks.map((x) => named(b, x.id)).join("; ")}` : b.alt;
|
|
1569
|
+
const size = { width: b.width, height: b.height };
|
|
1570
|
+
const v = b.video ? h("video", "", { src: b.src, "aria-label": b.alt, controls: true, preload: "metadata", ...size, poster: b.poster ?? void 0 }) : h("img", "", { src: b.src, alt, loading: "lazy", ...size });
|
|
1571
|
+
const drawn2 = marks.map((m) => painted(b, m));
|
|
1572
|
+
const body2 = !marks.length || b.video ? v : frame(b, v, drawn2.map((p) => p.art), drawn2.map((p) => p.top));
|
|
1573
|
+
return h("figure", "media", hooks4, body2, b.caption ? h("figcaption", "", null, b.caption) : null);
|
|
1574
|
+
}
|
|
1575
|
+
function media2({ b, hooks: hooks4 }) {
|
|
1576
|
+
const cx = useContext10(Cx);
|
|
1577
|
+
const live3 = useRef10(cx);
|
|
1578
|
+
live3.current = cx;
|
|
1579
|
+
const keep = useRef10(/* @__PURE__ */ new Map());
|
|
1580
|
+
const v = useRef10({}).current;
|
|
1581
|
+
const [, redraw] = useReducer((n) => n + 1, 0);
|
|
1582
|
+
const [now, show] = useState12(null);
|
|
1583
|
+
const [root, z] = [useRef10(null), useRef10(null)];
|
|
1584
|
+
const after = useRef10({});
|
|
1585
|
+
const k = JSON.stringify([b, v["tool"], v["into"], v["sel"], v["typing"]]);
|
|
1586
|
+
const c = { act: (a) => live3.current.act(a), held: keep.current };
|
|
1587
|
+
const wires = [];
|
|
1588
|
+
useLayoutEffect3(() => {
|
|
1589
|
+
for (const w of wires) w(c);
|
|
1590
|
+
}, [k]);
|
|
1591
|
+
useLayoutEffect3(() => {
|
|
1592
|
+
const { focus, press: press2 } = after.current;
|
|
1593
|
+
after.current = {};
|
|
1594
|
+
const at2 = (key3) => key3 ? root.current?.querySelector(`[data-key="${CSS.escape(key3)}"]`) : null;
|
|
1595
|
+
at2(focus)?.focus();
|
|
1596
|
+
at2(press2)?.click();
|
|
1597
|
+
});
|
|
1598
|
+
if (b.video || b.id == null || !(b.draw ?? b.move ?? b.stretch ?? b.remove)) return still(b, hooks4);
|
|
1599
|
+
const again = (press2) => {
|
|
1600
|
+
const a = document.activeElement;
|
|
1601
|
+
after.current = { focus: a instanceof HTMLElement && root.current?.contains(a) ? a.dataset["key"] : void 0, press: press2 };
|
|
1602
|
+
redraw();
|
|
1603
|
+
};
|
|
1604
|
+
const reach = (dx, dy, x, y) => {
|
|
1605
|
+
const r = z.current?.getBoundingClientRect() ?? { left: 0, top: 0, width: 1, height: 1 };
|
|
1606
|
+
const at2 = (px, py) => [(px - r.left) / (r.width || 1), (py - r.top) / (r.height || 1)];
|
|
1607
|
+
return { from: at2(x, y), to: at2(x + dx, y + dy) };
|
|
1608
|
+
};
|
|
1609
|
+
const o = { b, k, v, shown: now?.k === k ? now : null, show, reach, again, wires };
|
|
1610
|
+
return h("figure", "media mkm", { ...hooks4, ref: root }, createElement12(Fragment, { key: k }, ...marked(o, c, z)));
|
|
1611
|
+
}
|
|
1612
|
+
function marked(o, c, z) {
|
|
1613
|
+
const { b, v, shown: shown4 } = o;
|
|
1614
|
+
const marks = b.marks ?? [];
|
|
1615
|
+
const tool2 = (b.tools ?? []).find((t) => t === str(v["tool"])) ?? (b.tools?.length === 1 ? b.tools[0] : void 0);
|
|
1616
|
+
const groups = [...new Set(marks.filter((m) => !m.fixed && m.group != null).map((m) => m.group ?? ""))];
|
|
1617
|
+
const into = groups.find((g) => g === str(v["into"])) ?? groups[groups.length - 1];
|
|
1618
|
+
const sel = marks.find((m) => m.id === str(v["sel"]) && !m.fixed);
|
|
1619
|
+
const pen = (t) => ({ tool: t, ...into != null ? { group: into } : {} });
|
|
1620
|
+
const [art, top, late] = [[], [], []];
|
|
1621
|
+
const paint = (m, cls, g) => {
|
|
1622
|
+
const p = painted(b, m, cls, g);
|
|
1623
|
+
art.push(p.art);
|
|
1624
|
+
top.push(p.top);
|
|
1625
|
+
};
|
|
1626
|
+
const out2 = held(c, { block: b, rules: media, grab: { draw: pen(tool2 ?? b.tools?.[0] ?? "pin") }, item: "draw" });
|
|
1627
|
+
for (const m of marks) {
|
|
1628
|
+
const g = [{ body: m.id }, { end: m.id }, { remove: m.id }].find((x) => media.word(b, x));
|
|
1629
|
+
const h0 = g ? held(c, { block: b, rules: media, grab: g, item: m.id }) : void 0;
|
|
1630
|
+
const mine = shown4?.item === m.id;
|
|
1631
|
+
const d2 = mine ? shown4.c : isChange(h0) ? h0 : null;
|
|
1632
|
+
const gr = ref();
|
|
1633
|
+
paint(merged(m, d2), !mine && isChange(h0) ? " sent" : "", gr);
|
|
1634
|
+
if (mine) late.push(painted(b, m, " ghost").art);
|
|
1635
|
+
if (!m.fixed) stops(o, { m, d: d2, gr, sel: m.id === sel?.id, top });
|
|
1636
|
+
}
|
|
1637
|
+
if (isChange(out2) && out2.kind) paint({ id: "", kind: out2.kind, at: out2.at ?? [], to: out2.to ?? null, text: out2.text ?? null }, " sent");
|
|
1638
|
+
if (shown4?.item === "draw" && shown4.kind && shown4.c.at) paint(merged({ id: "", kind: shown4.kind, at: [] }, shown4.c), " new");
|
|
1639
|
+
art.push(...late);
|
|
1640
|
+
const zooms2 = b.draw && b.tools?.length === 1 && tool2 === "pin";
|
|
1641
|
+
const w = ref();
|
|
1642
|
+
const tools = b.draw && b.tools?.length ? bar(o, { tool: tool2, groups, into, sel, pen, zoom: zooms2 ? { w, z } : null }) : null;
|
|
1643
|
+
const under = b.draw && tool2 ? surface(o, { tool: tool2, pen: pen(tool2) }) : null;
|
|
1644
|
+
if (b.draw && tool2 === "text" && Array.isArray(v["typing"])) top.push(typing2(o, { at: v["typing"], pen: pen("text") }));
|
|
1645
|
+
const parts2 = [tools, frame(b, h("img", "", { src: b.src, alt: b.alt, width: b.width, height: b.height }), art, top, { w, z, cls: zooms2 ? " zoom" : "", under })];
|
|
1646
|
+
if (!marks.length && b.draw) parts2.push(h("p", "mkhint", null, HINT));
|
|
1647
|
+
if (b.caption) parts2.push(h("figcaption", "", null, b.caption));
|
|
1648
|
+
return parts2;
|
|
1649
|
+
}
|
|
1650
|
+
function over(m) {
|
|
1651
|
+
const ps = places2(m);
|
|
1652
|
+
const [xs, ys] = [ps.map((p) => p[0]), ps.map((p) => p[1])];
|
|
1653
|
+
const [l, t, r, d2] = [Math.min(...xs), Math.min(...ys), Math.max(...xs), Math.max(...ys)];
|
|
1654
|
+
return { left: pc((l + r) / 2), top: pc((t + d2) / 2), width: `calc(${pc(r - l)} + 12px)`, height: `calc(${pc(d2 - t)} + 12px)` };
|
|
1655
|
+
}
|
|
1656
|
+
function stops(o, s) {
|
|
1657
|
+
const { b, k, v } = o;
|
|
1658
|
+
const { m } = s;
|
|
1659
|
+
const name = named(b, m.id) ?? m.id;
|
|
1660
|
+
const at2 = merged(m, s.d);
|
|
1661
|
+
const follow = (d2) => o.show(d2 && { k, item: m.id, c: d2 });
|
|
1662
|
+
const stop = ref();
|
|
1663
|
+
const pick2 = (e) => {
|
|
1664
|
+
if (!idle(e)) return;
|
|
1665
|
+
v["sel"] = s.sel ? void 0 : m.id;
|
|
1666
|
+
o.again();
|
|
1667
|
+
};
|
|
1668
|
+
const key3 = (e) => {
|
|
1669
|
+
if (e.key === "Enter" && idle(e.currentTarget)) pick2(e.currentTarget);
|
|
1670
|
+
else if ((e.key === "Delete" || e.key === "Backspace") && b.remove) {
|
|
1671
|
+
v["sel"] = m.id;
|
|
1672
|
+
o.again("rm");
|
|
1673
|
+
} else return;
|
|
1674
|
+
e.preventDefault();
|
|
1675
|
+
};
|
|
1676
|
+
const own3 = { ref: stop, role: "button", tabIndex: 0, "aria-roledescription": "mark", "aria-label": name, "data-key": m.id, style: over(at2) };
|
|
1677
|
+
s.top.push(h("span", `mk${s.sel ? " sel" : ""}`, { ...own3, onClick: (e) => pick2(e.currentTarget), onKeyDown: key3 }));
|
|
1678
|
+
o.wires.push((c) => {
|
|
1679
|
+
const [el2, g] = [stop.current, s.gr.current];
|
|
1680
|
+
if (!el2 || !g) return;
|
|
1681
|
+
mirror(el2, g);
|
|
1682
|
+
const move2 = b.move;
|
|
1683
|
+
if (move2) beside2(el2, () => gestured(el2, c, { block: b, gesture: move2, rules: media, grab: { body: m.id }, item: m.id, reach: o.reach, show: follow }));
|
|
1684
|
+
});
|
|
1685
|
+
const to = m.to;
|
|
1686
|
+
const stretch = b.stretch;
|
|
1687
|
+
if (!s.sel || !to || !stretch) return;
|
|
1688
|
+
for (const end of ["start", "end"]) {
|
|
1689
|
+
const grip2 = ref();
|
|
1690
|
+
const p = end === "start" ? at2.at : at2.to ?? to;
|
|
1691
|
+
s.top.push(h("span", "mkg", { ref: grip2, role: "button", tabIndex: 0, "aria-label": `${end === "start" ? "Start" : "End"} of ${name}`, "data-key": `${m.id}:${end}`, style: { left: pc(p[0]), top: pc(p[1]) } }));
|
|
1692
|
+
const grab = end === "start" ? { start: m.id } : { end: m.id };
|
|
1693
|
+
o.wires.push((c) => {
|
|
1694
|
+
const [el2, g] = [grip2.current, s.gr.current];
|
|
1695
|
+
if (!el2 || !g) return;
|
|
1696
|
+
mirror(el2, g);
|
|
1697
|
+
beside2(el2, () => gestured(el2, c, { block: b, gesture: stretch, rules: media, grab, item: m.id, reach: o.reach, show: follow }));
|
|
1698
|
+
});
|
|
1699
|
+
}
|
|
1700
|
+
}
|
|
1701
|
+
function bar(o, t) {
|
|
1702
|
+
const { b, k, v } = o;
|
|
1703
|
+
const draw3 = b.draw;
|
|
1704
|
+
const tools = (b.tools ?? []).map((kind) => {
|
|
1705
|
+
const r = ref();
|
|
1706
|
+
const pick2 = (e) => {
|
|
1707
|
+
if (!idle(e.currentTarget)) return;
|
|
1708
|
+
[v["tool"], v["typing"]] = [t.tool === kind ? "" : kind, void 0];
|
|
1709
|
+
o.again();
|
|
1710
|
+
};
|
|
1711
|
+
if (draw3) {
|
|
1712
|
+
const show = (d2) => o.show(d2 && { k, item: "draw", kind, c: d2 });
|
|
1713
|
+
const grab = { draw: { ...t.pen(kind), at: [0.5, 0.5] } };
|
|
1714
|
+
o.wires.push((c) => {
|
|
1715
|
+
const el2 = r.current;
|
|
1716
|
+
if (el2) beside2(el2, () => gestured(el2, c, { block: b, gesture: draw3, rules: media, grab, item: "draw", reach: o.reach, show }));
|
|
1717
|
+
});
|
|
1718
|
+
}
|
|
1719
|
+
const own3 = { ref: r, type: "button", "aria-label": `${said(kind)} tool`, "aria-current": t.tool === kind ? "true" : void 0, "data-key": `tool:${kind}`, onClick: pick2 };
|
|
1720
|
+
return h("button", t.tool === kind ? "on" : "", own3, h("span", "", null, kind));
|
|
1721
|
+
});
|
|
1722
|
+
const into = (e) => {
|
|
1723
|
+
v["into"] = e.currentTarget.value;
|
|
1724
|
+
o.again();
|
|
1725
|
+
};
|
|
1726
|
+
const options = t.groups.map((g) => h("option", "", { value: g }, g));
|
|
1727
|
+
const groups = t.groups.length ? h("label", "mkgp", null, h("span", "m", null, "into"), h("select", "", { "aria-label": "Into group", value: t.into, onChange: into }, ...options)) : null;
|
|
1728
|
+
const right = h("div", "mkr", null, b.remove ? remove(o, t.sel) : null, ...t.zoom ? zoom(o, t.zoom) : []);
|
|
1729
|
+
return h("div", "mkbar", null, h("div", "mktl", { role: "toolbar", "aria-label": "Marks" }, ...tools), groups, right);
|
|
1730
|
+
}
|
|
1731
|
+
function remove(o, sel) {
|
|
1732
|
+
const { b } = o;
|
|
1733
|
+
const id = sel && media.word(b, { remove: sel.id }) ? sel.id : null;
|
|
1734
|
+
const r = ref();
|
|
1735
|
+
const gone2 = b.remove;
|
|
1736
|
+
if (id !== null && gone2)
|
|
1737
|
+
o.wires.push((c) => {
|
|
1738
|
+
const el2 = r.current;
|
|
1739
|
+
if (!el2) return;
|
|
1740
|
+
let run2 = (_) => {
|
|
1741
|
+
};
|
|
1742
|
+
beside2(el2, () => run2 = gestured(el2, c, { block: b, gesture: gone2, rules: media, grab: { remove: id }, item: id, reach: o.reach, show: () => {
|
|
1743
|
+
} }));
|
|
1744
|
+
el2.addEventListener("click", () => run2({ dir: "right" }));
|
|
1745
|
+
});
|
|
1746
|
+
return h("button", "bad", { ref: r, type: "button", "data-key": "rm", disabled: id === null || void 0 }, h("span", "", null, "delete"));
|
|
1747
|
+
}
|
|
1748
|
+
function surface(o, s) {
|
|
1749
|
+
const { b, k, v } = o;
|
|
1750
|
+
const draw3 = b.draw;
|
|
1751
|
+
const r = ref();
|
|
1752
|
+
if (draw3)
|
|
1753
|
+
o.wires.push((c) => {
|
|
1754
|
+
const el2 = r.current;
|
|
1755
|
+
if (!el2) return;
|
|
1756
|
+
const show = (d2) => o.show(d2 && { k, item: "draw", kind: s.tool, c: d2 });
|
|
1757
|
+
const run2 = gestured(el2, c, { block: b, gesture: draw3, rules: media, grab: { draw: s.pen }, item: "draw", reach: o.reach, show });
|
|
1758
|
+
el2.addEventListener("click", (e) => {
|
|
1759
|
+
if (!idle(el2)) return;
|
|
1760
|
+
const { to } = o.reach(0, 0, e.clientX, e.clientY);
|
|
1761
|
+
if (s.tool === "text") {
|
|
1762
|
+
v["typing"] = to;
|
|
1763
|
+
o.again();
|
|
1764
|
+
} else if (s.tool === "pin") {
|
|
1765
|
+
s.pen.at = to;
|
|
1766
|
+
run2({ dir: "right" });
|
|
1767
|
+
}
|
|
1768
|
+
});
|
|
1769
|
+
});
|
|
1770
|
+
return h("div", "mks", { ref: r });
|
|
1771
|
+
}
|
|
1772
|
+
function typing2(o, t) {
|
|
1773
|
+
const { b, v } = o;
|
|
1774
|
+
const draw3 = b.draw;
|
|
1775
|
+
const at2 = [Number(t.at[0]) || 0, Number(t.at[1]) || 0];
|
|
1776
|
+
const pen = { ...t.pen, at: at2, text: str(v["words"]) ?? "" };
|
|
1777
|
+
const [i, add] = [ref(), ref()];
|
|
1778
|
+
if (draw3)
|
|
1779
|
+
o.wires.push((c) => {
|
|
1780
|
+
const [input3, el2] = [i.current, add.current];
|
|
1781
|
+
if (!input3 || !el2) return;
|
|
1782
|
+
input3.addEventListener("input", () => pen.text = v["words"] = input3.value);
|
|
1783
|
+
const run2 = gestured(el2, c, { block: b, gesture: draw3, rules: media, grab: { draw: pen }, item: "draw", reach: () => ({ from: [-1, -1], to: [-1, -1] }), show: () => {
|
|
1784
|
+
} });
|
|
1785
|
+
const done = () => {
|
|
1786
|
+
run2({ dir: "right" });
|
|
1787
|
+
[v["typing"], v["words"]] = [void 0, void 0];
|
|
1788
|
+
};
|
|
1789
|
+
el2.addEventListener("click", done);
|
|
1790
|
+
input3.addEventListener("keydown", (e) => {
|
|
1791
|
+
if (e.key === "Enter") done();
|
|
1792
|
+
if (e.key !== "Escape") return;
|
|
1793
|
+
v["typing"] = void 0;
|
|
1794
|
+
o.again();
|
|
1795
|
+
});
|
|
1796
|
+
queueMicrotask(() => input3.isConnected && input3.focus());
|
|
1797
|
+
});
|
|
1798
|
+
const style = { left: pc(at2[0]), top: pc(at2[1]) };
|
|
1799
|
+
return h("span", "mkin", { style }, h("input", "", { ref: i, defaultValue: pen.text, "aria-label": "Text of the new mark" }), h("button", "", { ref: add, type: "button", "data-key": "add" }, h("span", "", null, "add")));
|
|
1800
|
+
}
|
|
1801
|
+
function zoom(o, at2) {
|
|
1802
|
+
const { v } = o;
|
|
1803
|
+
const pct = ref();
|
|
1804
|
+
const ways = [
|
|
1805
|
+
["\u2212", "Zoom out", (n) => n / 1.25],
|
|
1806
|
+
["", "Fit", () => 1],
|
|
1807
|
+
["+", "Zoom in", (n) => n * 1.25]
|
|
1808
|
+
];
|
|
1809
|
+
const refs = ways.map(() => ref());
|
|
1810
|
+
o.wires.push(() => {
|
|
1811
|
+
const [w, z, p] = [at2.w.current, at2.z.current, pct.current];
|
|
1812
|
+
if (!w || !z || !p) return;
|
|
1813
|
+
const apply = (n) => {
|
|
1814
|
+
z.style.width = `${n * 100}%`;
|
|
1815
|
+
p.textContent = `${Math.round(n * 100)}%`;
|
|
1816
|
+
};
|
|
1817
|
+
zoomed(w, v, { min: 1, max: 3, apply });
|
|
1818
|
+
const now = () => typeof v["zoom"] === "number" ? v["zoom"] : 1;
|
|
1819
|
+
ways.forEach(([, , go2], n) => refs[n]?.current?.addEventListener("click", () => apply(v["zoom"] = Math.min(3, Math.max(1, go2(now()))))));
|
|
1820
|
+
});
|
|
1821
|
+
return ways.map(([t, name], n) => h("button", "", { ref: refs[n], type: "button", "aria-label": name }, t ? h("span", "", null, t) : h("span", "mkzm", { ref: pct })));
|
|
1822
|
+
}
|
|
1823
|
+
|
|
1824
|
+
// react/src/kinds/hero.ts
|
|
1825
|
+
function hero({ b, hooks: hooks4 }) {
|
|
1826
|
+
const cx = useContext11(Cx);
|
|
1827
|
+
const acts2 = (b.actions ?? []).map((a) => {
|
|
1828
|
+
const tap = a.tap;
|
|
1829
|
+
const go2 = tap ? () => cx.tap(tap) : () => void cx.act({ action: a.action ?? "", block: b.id, values: a.values ?? {}, confirm: a.confirm });
|
|
1830
|
+
const url2 = urlOf(tap);
|
|
1831
|
+
return act(a, "primary", cx, url2, url2 ? void 0 : go2);
|
|
1832
|
+
});
|
|
1833
|
+
const sub = b.subtitle ? h("p", "b-hero__subtitle", null, b.subtitle) : null;
|
|
1834
|
+
return h("header", "hero", hooks4, h("h1", "b-hero__title", null, b.title), sub, b.media ? still(b.media, {}) : null, acts2.length ? h("div", "bar b-hero__actions", null, ...acts2) : null);
|
|
1835
|
+
}
|
|
1836
|
+
|
|
1837
|
+
// react/src/kinds/images.ts
|
|
1838
|
+
import { linkable as linkable3 } from "./core.js";
|
|
1839
|
+
function images({ b, hooks: hooks4 }) {
|
|
1840
|
+
const item3 = (i, n) => {
|
|
1841
|
+
if (!linkable3(i.src)) return h("span", "", { key: n }, i.alt ?? "");
|
|
1842
|
+
const src = i.src.replace(/^[/]/, "");
|
|
1843
|
+
return h("a", "", { key: n, ...out(src) }, h("img", "", { src, alt: i.alt ?? "", loading: "lazy" }));
|
|
1844
|
+
};
|
|
1845
|
+
return h("div", "imgs", hooks4, ...b.items.map(item3));
|
|
1846
|
+
}
|
|
1847
|
+
|
|
1848
|
+
// react/src/kinds/import.ts
|
|
1849
|
+
import { useContext as useContext12, useLayoutEffect as useLayoutEffect4, useRef as useRef11 } from "react";
|
|
1850
|
+
function import_({ b, hooks: hooks4 }) {
|
|
1851
|
+
const cx = useContext12(Cx);
|
|
1852
|
+
const root = useRef11(null);
|
|
1853
|
+
useLayoutEffect4(() => {
|
|
1854
|
+
const box = root.current;
|
|
1855
|
+
if (box) void import("./import.js").then((m) => m.draw(box, b, cx));
|
|
1856
|
+
}, [b, cx]);
|
|
1857
|
+
return h("section", "im", { ...hooks4, ref: root });
|
|
1858
|
+
}
|
|
1859
|
+
|
|
1860
|
+
// react/src/kinds/list.ts
|
|
1861
|
+
import { createContext as createContext2, createElement as createElement13, useContext as useContext13, useLayoutEffect as useLayoutEffect5, useRef as useRef12 } from "react";
|
|
1862
|
+
import { fill as fill4, hits, said as said2 } from "./core.js";
|
|
1863
|
+
|
|
1864
|
+
// src/core/kind/list.ts
|
|
1865
|
+
var STEPS2 = [
|
|
1866
|
+
["Move up", { dir: "up" }],
|
|
1867
|
+
["Move down", { dir: "down" }],
|
|
1868
|
+
["Move to top", { dir: "up", big: true }],
|
|
1869
|
+
["Move to bottom", { dir: "down", big: true }]
|
|
1870
|
+
];
|
|
1871
|
+
var order = (b) => b.rows.flatMap((r) => typeof r.id === "string" ? [r.id] : []);
|
|
1872
|
+
var row = (b, id) => b.rows.find((r) => r.type === "row" && r.id === id);
|
|
1873
|
+
var moved2 = (ids3, id, to) => {
|
|
1874
|
+
const from = ids3.indexOf(id);
|
|
1875
|
+
if (from < 0) return null;
|
|
1876
|
+
const out2 = ids3.filter((i) => i !== id);
|
|
1877
|
+
out2.splice(Math.min(Math.max(to, 0), out2.length), 0, id);
|
|
1878
|
+
return out2;
|
|
1879
|
+
};
|
|
1880
|
+
var list = {
|
|
1881
|
+
word: (b, g) => b.reorder != null && row(b, g)?.handle === true ? "reorder" : null,
|
|
1882
|
+
start: (b, g) => list.word(b, g) ? order(b) : null,
|
|
1883
|
+
candidate: (b, g, r) => {
|
|
1884
|
+
const ids3 = list.start(b, g);
|
|
1885
|
+
return ids3 && moved2(ids3, g, ids3.indexOf(g) + r);
|
|
1886
|
+
},
|
|
1887
|
+
nudge: (b, g, from, by) => {
|
|
1888
|
+
const at2 = from.indexOf(g);
|
|
1889
|
+
const last = from.length - 1;
|
|
1890
|
+
if (!list.word(b, g) || at2 < 0 || by.dir === "left" || by.dir === "right") return null;
|
|
1891
|
+
if (by.dir === "up") return at2 === 0 ? null : moved2(from, g, by.big ? 0 : at2 - 1);
|
|
1892
|
+
return at2 === last ? null : moved2(from, g, by.big ? last : at2 + 1);
|
|
1893
|
+
},
|
|
1894
|
+
steps: (b, g) => {
|
|
1895
|
+
const s = list.start(b, g);
|
|
1896
|
+
return s ? STEPS2.filter(([, n]) => list.nudge(b, g, s, n) !== null) : [];
|
|
1897
|
+
},
|
|
1898
|
+
says: (b, g, c) => `${row(b, g)?.title ?? g}, ${c.indexOf(g) + 1} of ${c.length}`
|
|
1899
|
+
};
|
|
1900
|
+
|
|
1901
|
+
// react/src/kinds/list.ts
|
|
1902
|
+
var rec2 = (v) => typeof v === "object" && v !== null;
|
|
1903
|
+
var Tiles = createContext2([]);
|
|
1904
|
+
function list2({ b, hooks: hooks4 }) {
|
|
1905
|
+
const cx = useContext13(Cx);
|
|
1906
|
+
const ref3 = useRef12(null);
|
|
1907
|
+
const act2 = useRef12(cx.act);
|
|
1908
|
+
act2.current = cx.act;
|
|
1909
|
+
useLayoutEffect5(() => {
|
|
1910
|
+
const l = ref3.current;
|
|
1911
|
+
const g = b.reorder;
|
|
1912
|
+
if (!l || !g) return;
|
|
1913
|
+
const drawn2 = () => Array.from(l.children).filter((e) => e instanceof HTMLElement);
|
|
1914
|
+
const at2 = (id) => drawn2().find((e) => e.dataset["id"] === id);
|
|
1915
|
+
const show = (order2) => {
|
|
1916
|
+
const d2 = drawn2();
|
|
1917
|
+
const gap = d2.length > 1 && d2[0] && d2[1] ? d2[1].offsetTop - d2[0].offsetTop - d2[0].offsetHeight : 0;
|
|
1918
|
+
let y = d2[0]?.offsetTop ?? 0;
|
|
1919
|
+
for (const e of (order2 ?? []).flatMap((id) => at2(id) ?? [])) {
|
|
1920
|
+
e.style.transform = `translateY(${y - e.offsetTop}px)`;
|
|
1921
|
+
y += e.offsetHeight + gap;
|
|
1922
|
+
}
|
|
1923
|
+
if (!order2) d2.forEach((e) => e.style.transform = "");
|
|
1924
|
+
};
|
|
1925
|
+
const c = { act: (a) => act2.current({ action: g.action, block: b.id, values: rec2(a.values) ? a.values : null }) };
|
|
1926
|
+
const added = [];
|
|
1927
|
+
for (const r of b.rows) {
|
|
1928
|
+
const e = r.id ? at2(r.id) : void 0;
|
|
1929
|
+
if (!e || !r.id || r.type !== "row" || !list.word(b, r.id)) continue;
|
|
1930
|
+
const hd = Object.assign(document.createElement("button"), { className: "b-hd", type: "button", textContent: "\u2261" });
|
|
1931
|
+
hd.setAttribute("aria-label", `Move ${r.title}`);
|
|
1932
|
+
hd.dataset["act"] = g.action;
|
|
1933
|
+
e.append(hd);
|
|
1934
|
+
gestured(hd, c, { block: b, gesture: g, rules: list, grab: r.id, item: r.id, reach: (_, dy) => Math.round(dy / (e.offsetHeight || 1)), show });
|
|
1935
|
+
for (let n = hd; n; n = n.nextElementSibling) added.push(n);
|
|
1936
|
+
}
|
|
1937
|
+
return () => {
|
|
1938
|
+
added.forEach((n) => n.remove());
|
|
1939
|
+
show(null);
|
|
1940
|
+
};
|
|
1941
|
+
}, [b]);
|
|
1942
|
+
const s = cx.seek[b.id ?? ""];
|
|
1943
|
+
const rows2 = s?.q ? b.rows.filter((r) => hits(said2(r), s.q)) : b.rows;
|
|
1944
|
+
const none2 = s?.q && !s.n ? h("div", "lsm sm", null, fill4(word(cx, "nomatch"), { q: s.q }), " ", btn(word(cx, "clear"), "", void 0, void 0, { onClick: () => cx.put(s.name, "") })) : null;
|
|
1945
|
+
const empty = !b.rows.length && b.empty ? h("p", "empty", null, b.empty) : null;
|
|
1946
|
+
return h("div", "list", { ...hooks4, ref: ref3 }, empty, createElement13(Tiles.Provider, { value: rows2 }, ...kids2(rows2)), none2);
|
|
1947
|
+
}
|
|
1948
|
+
|
|
1949
|
+
// react/src/kinds/message.ts
|
|
1950
|
+
import { useContext as useContext14 } from "react";
|
|
1951
|
+
import { ext, initial, linkable as linkable4, roleWord } from "./core.js";
|
|
1952
|
+
var image = (f) => f.src != null && linkable4(f.src);
|
|
1953
|
+
function message({ b, hooks: hooks4 }) {
|
|
1954
|
+
const cx = useContext14(Cx);
|
|
1955
|
+
const file = (f, n) => {
|
|
1956
|
+
const url2 = urlOf(f.tap);
|
|
1957
|
+
const [x, rest] = ext(f.name);
|
|
1958
|
+
const shown4 = image(f) ? [h("img", "", { key: "i", src: f.src, alt: f.name, loading: "lazy" })] : [h("span", "mfx", { key: "x" }, x), h("span", "mfn", { key: "n" }, rest)];
|
|
1959
|
+
const attrs = { key: n, title: f.name, "aria-label": f.name };
|
|
1960
|
+
const cls = image(f) ? "" : "mff";
|
|
1961
|
+
if (url2) return h("a", cls, { ...attrs, ...out(url2) }, ...shown4);
|
|
1962
|
+
return h("button", cls, { ...attrs, type: "button", "data-action": sends(f.tap), onClick: () => cx.tap(f.tap) }, ...shown4);
|
|
1963
|
+
};
|
|
1964
|
+
const face = b.role === "system" ? null : b.avatar != null && linkable4(b.avatar) ? h("img", "mav b-message__avatar", { src: b.avatar, alt: "", "aria-hidden": "true" }) : h("span", "mav ini", { "aria-hidden": "true" }, initial(b.name));
|
|
1965
|
+
const files = b.files ?? [];
|
|
1966
|
+
const images2 = files.filter(image);
|
|
1967
|
+
const box = files.length ? h("div", "mf b-message__files", null, images2.length ? h("div", "mfi", null, ...images2.map(file)) : null, ...files.filter((f) => !image(f)).map(file)) : null;
|
|
1968
|
+
const head4 = h("div", "mh", null, h("span", "mn b-message__name", null, b.name), h("span", "mr", null, roleWord(b.role)), b.time ? h("time", "mt", null, b.time) : null);
|
|
1969
|
+
return h("article", "msg", hooks4, face, head4, h("div", "mb", null, ...kids2(b.blocks), box));
|
|
1970
|
+
}
|
|
1971
|
+
|
|
1972
|
+
// react/src/kinds/modal.ts
|
|
1973
|
+
import { useContext as useContext15, useLayoutEffect as useLayoutEffect6, useRef as useRef13 } from "react";
|
|
1974
|
+
|
|
1975
|
+
// src/core/kind/modal.ts
|
|
1976
|
+
var MIN = { w: 280, h: 200, margin: 16 };
|
|
1977
|
+
var STEP = 16;
|
|
1978
|
+
var BIG = 64;
|
|
1979
|
+
var variant = (b) => b.variant === "alert" || b.variant === "tool" ? b.variant : "dialog";
|
|
1980
|
+
var fit = (v, lo, hi) => Math.round(Math.min(Math.max(v, lo), Math.max(lo, hi)));
|
|
1981
|
+
function clamp(p, vw, vh) {
|
|
1982
|
+
const w = Math.min(p.w, vw - 2 * MIN.margin);
|
|
1983
|
+
const h3 = Math.min(p.h, vh - 2 * MIN.margin);
|
|
1984
|
+
const mx = Math.max(0, (vw - w) / 2 - MIN.margin);
|
|
1985
|
+
const my = Math.max(0, (vh - h3) / 2 - MIN.margin);
|
|
1986
|
+
return { x: fit(p.x, -mx, mx), y: fit(p.y, -my, my), w: Math.round(w), h: Math.round(h3) };
|
|
1987
|
+
}
|
|
1988
|
+
var sized = (f, dw, dh) => {
|
|
1989
|
+
const w = fit(f.at.w + dw, MIN.w, f.vw - 2 * MIN.margin);
|
|
1990
|
+
const h3 = fit(f.at.h + dh, MIN.h, f.vh - 2 * MIN.margin);
|
|
1991
|
+
return clamp({ x: f.at.x + (w - f.at.w) / 2, y: f.at.y + (h3 - f.at.h) / 2, w, h: h3 }, f.vw, f.vh);
|
|
1992
|
+
};
|
|
1993
|
+
var gone = (f) => Math.min(f.at.h / 3, 120);
|
|
1994
|
+
var MOVES = [
|
|
1995
|
+
["move left", { dir: "left" }],
|
|
1996
|
+
["move right", { dir: "right" }],
|
|
1997
|
+
["move up", { dir: "up" }],
|
|
1998
|
+
["move down", { dir: "down" }]
|
|
1999
|
+
];
|
|
2000
|
+
var SIZES = [
|
|
2001
|
+
["narrower", { dir: "left" }],
|
|
2002
|
+
["wider", { dir: "right" }],
|
|
2003
|
+
["shorter", { dir: "up" }],
|
|
2004
|
+
["taller", { dir: "down" }]
|
|
2005
|
+
];
|
|
2006
|
+
var BY = { left: [-1, 0], right: [1, 0], up: [0, -1], down: [0, 1] };
|
|
2007
|
+
var toward2 = (n) => {
|
|
2008
|
+
const d2 = n.big ? BIG : STEP;
|
|
2009
|
+
const [x, y] = BY[n.dir];
|
|
2010
|
+
return { dx: x * d2, dy: y * d2 };
|
|
2011
|
+
};
|
|
2012
|
+
var said3 = (d2, less, more) => {
|
|
2013
|
+
if (d2 === 0) return "";
|
|
2014
|
+
return d2 < 0 ? less : more;
|
|
2015
|
+
};
|
|
2016
|
+
var modal = {
|
|
2017
|
+
word: (f, g) => {
|
|
2018
|
+
const v = variant(f.b);
|
|
2019
|
+
if (g === "head") return v === "alert" ? null : "move";
|
|
2020
|
+
if (g === "handle") return v === "alert" ? null : "remove";
|
|
2021
|
+
return v === "tool" ? "stretch" : null;
|
|
2022
|
+
},
|
|
2023
|
+
start: (f, g) => {
|
|
2024
|
+
if (!modal.word(f, g)) return null;
|
|
2025
|
+
return g === "handle" ? { ...f.at, x: 0, y: 0 } : f.at;
|
|
2026
|
+
},
|
|
2027
|
+
candidate: (f, g, r) => {
|
|
2028
|
+
if (!modal.word(f, g)) return null;
|
|
2029
|
+
if (g === "head") return clamp({ ...f.at, x: f.at.x + r.dx, y: f.at.y + r.dy }, f.vw, f.vh);
|
|
2030
|
+
if (g === "handle") return { ...f.at, x: 0, y: Math.max(0, Math.round(r.dy)) };
|
|
2031
|
+
return sized(f, r.dx, g === "corner" ? r.dy : 0);
|
|
2032
|
+
},
|
|
2033
|
+
nudge: (f, g, from, by) => {
|
|
2034
|
+
if (!modal.word(f, g) || g === "handle") return null;
|
|
2035
|
+
const { dx, dy } = toward2(by);
|
|
2036
|
+
if (g === "edge" && dy !== 0) return null;
|
|
2037
|
+
return g === "head" ? clamp({ ...from, x: from.x + dx, y: from.y + dy }, f.vw, f.vh) : sized({ ...f, at: from }, dx, dy);
|
|
2038
|
+
},
|
|
2039
|
+
steps: (f, g) => {
|
|
2040
|
+
if (!modal.word(f, g)) return [];
|
|
2041
|
+
if (g === "head") return MOVES;
|
|
2042
|
+
return g === "corner" ? SIZES : [];
|
|
2043
|
+
},
|
|
2044
|
+
says: (f, g, c) => {
|
|
2045
|
+
if (g === "handle") return c.y >= gone(f) ? "closes" : "springs back";
|
|
2046
|
+
if (g !== "head") return `${c.w} by ${c.h}`;
|
|
2047
|
+
const where = [said3(c.x - f.at.x, "left", "right"), said3(c.y - f.at.y, "up", "down")].filter(Boolean).join(" and ");
|
|
2048
|
+
return where ? `moved ${where}` : "in place";
|
|
2049
|
+
}
|
|
2050
|
+
};
|
|
2051
|
+
|
|
2052
|
+
// src/modal.ts
|
|
2053
|
+
var TOOL = { w: 360, h: 440 };
|
|
2054
|
+
var PHONE2 = "(max-width: 600px)";
|
|
2055
|
+
var local = {
|
|
2056
|
+
get: (k) => {
|
|
2057
|
+
try {
|
|
2058
|
+
return localStorage.getItem(k);
|
|
2059
|
+
} catch {
|
|
2060
|
+
return null;
|
|
2061
|
+
}
|
|
2062
|
+
},
|
|
2063
|
+
put: (k, v) => {
|
|
2064
|
+
try {
|
|
2065
|
+
if (v === null) localStorage.removeItem(k);
|
|
2066
|
+
else localStorage.setItem(k, v);
|
|
2067
|
+
return true;
|
|
2068
|
+
} catch {
|
|
2069
|
+
return false;
|
|
2070
|
+
}
|
|
2071
|
+
}
|
|
2072
|
+
};
|
|
2073
|
+
var num = (v, or2) => typeof v === "number" && Number.isFinite(v) ? v : or2;
|
|
2074
|
+
function read2(store, key3) {
|
|
2075
|
+
const s = key3 ? store.get(key3) : null;
|
|
2076
|
+
if (!s) return null;
|
|
2077
|
+
try {
|
|
2078
|
+
const v = JSON.parse(s);
|
|
2079
|
+
if (typeof v !== "object" || v === null) return null;
|
|
2080
|
+
const o = Object.fromEntries(Object.entries(v));
|
|
2081
|
+
return { x: num(o["x"], 0), y: num(o["y"], 0), w: num(o["w"], TOOL.w), h: num(o["h"], TOOL.h), min: o["min"] === true };
|
|
2082
|
+
} catch {
|
|
2083
|
+
return null;
|
|
2084
|
+
}
|
|
2085
|
+
}
|
|
2086
|
+
var focusable = (d2) => Array.from(d2.querySelectorAll("button, input, select, textarea, a[href], [tabindex]")).filter((e) => e.tabIndex >= 0 && !e.closest("[hidden]"));
|
|
2087
|
+
var phone = () => typeof matchMedia === "function" && matchMedia(PHONE2).matches;
|
|
2088
|
+
var onButton = (e) => e.target instanceof Element && e.target.closest("button") !== null;
|
|
2089
|
+
function fields(d2) {
|
|
2090
|
+
const out2 = {};
|
|
2091
|
+
for (const i of d2.querySelectorAll("input[name], select[name], textarea[name]")) {
|
|
2092
|
+
if (i instanceof HTMLInputElement && i.type === "checkbox") out2[i.name] = i.checked;
|
|
2093
|
+
else out2[i.name] = i.value;
|
|
2094
|
+
}
|
|
2095
|
+
return out2;
|
|
2096
|
+
}
|
|
2097
|
+
var pills;
|
|
2098
|
+
var tray = () => {
|
|
2099
|
+
if (!pills?.isConnected) {
|
|
2100
|
+
pills = Object.assign(document.createElement("nav"), { className: "mdp" });
|
|
2101
|
+
pills.setAttribute("aria-label", "minimised windows");
|
|
2102
|
+
document.body.append(pills);
|
|
2103
|
+
}
|
|
2104
|
+
return pills;
|
|
2105
|
+
};
|
|
2106
|
+
var part = (s, cls) => s.d.querySelector(`.${cls}`);
|
|
2107
|
+
function framing(s) {
|
|
2108
|
+
const r = s.d.getBoundingClientRect();
|
|
2109
|
+
return { b: s.b, at: s.v === "tool" ? s.place : { ...s.place, w: r.width, h: r.height }, vw: innerWidth, vh: innerHeight };
|
|
2110
|
+
}
|
|
2111
|
+
function draw(s, p) {
|
|
2112
|
+
s.d.style.setProperty("--mx", `${p.x}px`);
|
|
2113
|
+
s.d.style.setProperty("--my", `${p.y}px`);
|
|
2114
|
+
if (s.v !== "tool") return;
|
|
2115
|
+
s.d.style.setProperty("--tw", `${p.w}px`);
|
|
2116
|
+
s.d.style.setProperty("--th", `${p.h}px`);
|
|
2117
|
+
const z = part(s, "mdz");
|
|
2118
|
+
z?.setAttribute("aria-valuenow", String(p.w));
|
|
2119
|
+
z?.setAttribute("aria-valuetext", `${p.w} by ${p.h}`);
|
|
2120
|
+
}
|
|
2121
|
+
var save = (s) => s.key && s.store.put(s.key, JSON.stringify(s.v === "tool" ? { ...s.place, min: s.min } : { x: s.place.x, y: s.place.y }));
|
|
2122
|
+
function fit2(s) {
|
|
2123
|
+
if (!s.on) return;
|
|
2124
|
+
if (!s.d.isConnected) return s.stop();
|
|
2125
|
+
s.d.classList.remove("full");
|
|
2126
|
+
if (phone()) {
|
|
2127
|
+
const body2 = part(s, "mdb");
|
|
2128
|
+
s.d.style.removeProperty("--sy");
|
|
2129
|
+
s.d.classList.toggle("full", s.v !== "alert" && !!body2 && body2.scrollHeight > body2.clientHeight);
|
|
2130
|
+
return draw(s, { ...s.place, x: 0, y: 0 });
|
|
2131
|
+
}
|
|
2132
|
+
const f = framing(s);
|
|
2133
|
+
s.place = { ...clamp(f.at, f.vw, f.vh), ...s.v === "tool" ? {} : { w: s.place.w, h: s.place.h } };
|
|
2134
|
+
draw(s, s.place);
|
|
2135
|
+
}
|
|
2136
|
+
function fold(s, to) {
|
|
2137
|
+
s.min = to && !phone();
|
|
2138
|
+
s.d.hidden = s.min;
|
|
2139
|
+
if (s.min) tray().append(s.pill);
|
|
2140
|
+
else s.pill.remove();
|
|
2141
|
+
if (pills && !pills.childElementCount) pills.remove();
|
|
2142
|
+
save(s);
|
|
2143
|
+
if (!s.min) part(s, "mdt")?.focus();
|
|
2144
|
+
}
|
|
2145
|
+
function close(s) {
|
|
2146
|
+
s.pill.remove();
|
|
2147
|
+
if (pills && !pills.childElementCount) pills.remove();
|
|
2148
|
+
if (s.d.open) s.d.close();
|
|
2149
|
+
s.stop();
|
|
2150
|
+
if (s.opener?.isConnected) s.opener.focus();
|
|
2151
|
+
}
|
|
2152
|
+
function drive(s, el2, grab, keys3) {
|
|
2153
|
+
if (!el2 || !modal.word(framing(s), grab)) return;
|
|
2154
|
+
const handle = grab === "handle";
|
|
2155
|
+
const send4 = (c) => {
|
|
2156
|
+
if (handle) return c.y >= gone(framing(s)) && (close(s), true);
|
|
2157
|
+
s.place = c;
|
|
2158
|
+
save(s);
|
|
2159
|
+
return true;
|
|
2160
|
+
};
|
|
2161
|
+
const show = (c) => {
|
|
2162
|
+
if (handle) s.d.style.setProperty("--sy", `${c?.y ?? 0}px`);
|
|
2163
|
+
else draw(s, c ?? s.place);
|
|
2164
|
+
};
|
|
2165
|
+
steered(el2, { rules: modal, grab, now: () => framing(s), reach: (dx, dy) => ({ dx, dy }), show, send: send4, tap: handle ? () => close(s) : void 0, keys: keys3, mark: s.d, skip: (e) => phone() !== handle || grab === "head" && onButton(e) });
|
|
2166
|
+
}
|
|
2167
|
+
function wire2(s, done) {
|
|
2168
|
+
const head4 = part(s, "mdh");
|
|
2169
|
+
drive(s, head4, "head", part(s, "mdt"));
|
|
2170
|
+
drive(s, part(s, "mdk"), "handle", null);
|
|
2171
|
+
drive(s, part(s, "mdz"), "corner", part(s, "mdz"));
|
|
2172
|
+
drive(s, part(s, "mde"), "edge", null);
|
|
2173
|
+
part(s, "mdn")?.addEventListener("click", () => fold(s, true));
|
|
2174
|
+
s.pill.addEventListener("click", () => fold(s, false));
|
|
2175
|
+
head4?.addEventListener("dblclick", (e) => {
|
|
2176
|
+
if (s.v === "alert" || onButton(e)) return;
|
|
2177
|
+
s.place = { ...s.place, x: 0, y: 0 };
|
|
2178
|
+
if (s.v === "tool") save(s);
|
|
2179
|
+
else if (s.key) s.store.put(s.key, null);
|
|
2180
|
+
fit2(s);
|
|
2181
|
+
});
|
|
2182
|
+
part(s, "mdk")?.addEventListener("keydown", (e) => (e.key === "Enter" || e.key === " ") && (e.preventDefault(), close(s)));
|
|
2183
|
+
for (const x of s.d.querySelectorAll(".mdx, .mdc")) x.addEventListener("click", () => close(s));
|
|
2184
|
+
part(s, "mdo")?.addEventListener("click", () => {
|
|
2185
|
+
const a = s.b.done;
|
|
2186
|
+
if (!a) return close(s);
|
|
2187
|
+
void done({ action: a.action, block: s.b.id, values: { ...a.values, ...fields(s.d) } }).then((ok) => ok && close(s));
|
|
2188
|
+
});
|
|
2189
|
+
}
|
|
2190
|
+
function keys(s) {
|
|
2191
|
+
s.d.addEventListener("cancel", (e) => (e.preventDefault(), close(s)));
|
|
2192
|
+
s.d.addEventListener("keydown", (e) => {
|
|
2193
|
+
if (e.key === "Escape" && s.v === "tool") return e.preventDefault(), close(s);
|
|
2194
|
+
if (e.key !== "Tab" || s.v === "tool") return;
|
|
2195
|
+
const all = focusable(s.d);
|
|
2196
|
+
const at2 = all.findIndex((x) => x === document.activeElement);
|
|
2197
|
+
const n = Math.max(1, all.length);
|
|
2198
|
+
let step2 = (at2 + (e.shiftKey ? n - 1 : 1)) % n;
|
|
2199
|
+
if (at2 < 0) step2 = e.shiftKey ? n - 1 : 0;
|
|
2200
|
+
e.preventDefault();
|
|
2201
|
+
all[step2]?.focus();
|
|
2202
|
+
});
|
|
2203
|
+
}
|
|
2204
|
+
var away = (s) => (e) => {
|
|
2205
|
+
if (e.key !== "F6" || s.d.hidden || !s.d.open) return;
|
|
2206
|
+
e.preventDefault();
|
|
2207
|
+
if (s.d.contains(document.activeElement)) (s.opener?.isConnected ? s.opener : document.body).focus();
|
|
2208
|
+
else part(s, "mdt")?.focus();
|
|
2209
|
+
};
|
|
2210
|
+
function first(s) {
|
|
2211
|
+
if (s.v === "alert") return (s.b.destructive ? part(s, "mdc") : null) ?? part(s, "mdo");
|
|
2212
|
+
if (s.v === "tool") return part(s, "mdt");
|
|
2213
|
+
return part(s, "mdb")?.querySelector("input, select, textarea") ?? part(s, "mdo") ?? part(s, "mdt");
|
|
2214
|
+
}
|
|
2215
|
+
function framed(d2, b, o) {
|
|
2216
|
+
const store = o.store ?? local;
|
|
2217
|
+
const v = variant(b);
|
|
2218
|
+
const key3 = v !== "alert" && b.id ? `b:modal:${b.id}` : null;
|
|
2219
|
+
const kept2 = read2(store, key3);
|
|
2220
|
+
const pill = Object.assign(document.createElement("button"), { type: "button" });
|
|
2221
|
+
pill.setAttribute("aria-label", `restore ${b.title}`);
|
|
2222
|
+
pill.append(Object.assign(document.createElement("span"), { textContent: `\u25A3 ${b.title}` }));
|
|
2223
|
+
const place3 = { x: kept2?.x ?? 0, y: kept2?.y ?? 0, w: kept2?.w ?? TOOL.w, h: kept2?.h ?? TOOL.h };
|
|
2224
|
+
const opener = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
|
2225
|
+
const s = { d: d2, b, v, store, key: key3, place: place3, min: v === "tool" && kept2?.min === true, on: true, opener, pill, stop: () => {
|
|
2226
|
+
} };
|
|
2227
|
+
const resize = () => fit2(s);
|
|
2228
|
+
const f6 = away(s);
|
|
2229
|
+
s.stop = () => {
|
|
2230
|
+
s.on = false;
|
|
2231
|
+
removeEventListener("resize", resize);
|
|
2232
|
+
document.removeEventListener("keydown", f6);
|
|
2233
|
+
};
|
|
2234
|
+
wire2(s, o.done);
|
|
2235
|
+
keys(s);
|
|
2236
|
+
addEventListener("resize", resize);
|
|
2237
|
+
if (v === "tool") document.addEventListener("keydown", f6);
|
|
2238
|
+
d2.dataset["live"] = "";
|
|
2239
|
+
if (!d2.open) {
|
|
2240
|
+
try {
|
|
2241
|
+
if (v === "tool") d2.show();
|
|
2242
|
+
else d2.showModal();
|
|
2243
|
+
} catch {
|
|
2244
|
+
d2.setAttribute("open", "");
|
|
2245
|
+
}
|
|
2246
|
+
}
|
|
2247
|
+
fit2(s);
|
|
2248
|
+
if (s.min) fold(s, true);
|
|
2249
|
+
else first(s)?.focus();
|
|
2250
|
+
return s.stop;
|
|
2251
|
+
}
|
|
2252
|
+
|
|
2253
|
+
// react/src/kinds/modal.ts
|
|
2254
|
+
function modal2({ b, hooks: hooks4 }) {
|
|
2255
|
+
const cx = useContext15(Cx);
|
|
2256
|
+
const d2 = useRef13(null);
|
|
2257
|
+
const act2 = useRef13(cx.act);
|
|
2258
|
+
act2.current = cx.act;
|
|
2259
|
+
useLayoutEffect6(() => {
|
|
2260
|
+
const e = d2.current;
|
|
2261
|
+
return e ? framed(e, b, { done: (a) => act2.current(a) }) : void 0;
|
|
2262
|
+
}, [b]);
|
|
2263
|
+
const v = variant(b);
|
|
2264
|
+
const mid = `${b.id ?? "modal"}-m`;
|
|
2265
|
+
const own3 = v === "tool" ? { role: "dialog" } : { role: v === "alert" ? "alertdialog" : "dialog", "aria-modal": "true", "aria-describedby": v === "alert" && b.message ? mid : void 0 };
|
|
2266
|
+
const ok = b.ok ?? b.done?.label ?? (v === "alert" ? "ok" : null);
|
|
2267
|
+
const head4 = v === "alert" ? h("header", "mdh", null, h("span", "mdt", null, b.title)) : h(
|
|
2268
|
+
"header",
|
|
2269
|
+
"mdh",
|
|
2270
|
+
null,
|
|
2271
|
+
h("span", "mdg", { "aria-hidden": "true" }, "\u22EE\u22EE"),
|
|
2272
|
+
h("span", "mdt", { tabIndex: 0, "aria-roledescription": "movable heading" }, b.title),
|
|
2273
|
+
v === "tool" ? btn("\u2013", "mdn", void 0, void 0, { "aria-label": "minimise" }) : null,
|
|
2274
|
+
btn("\xD7", "mdx", void 0, void 0, { "aria-label": "close" })
|
|
2275
|
+
);
|
|
2276
|
+
const foot2 = b.cancel != null || ok != null ? h("footer", "mdf", null, b.cancel != null ? btn(b.cancel, "mdc", void 0, void 0, {}) : null, ok != null ? btn(ok, `mdo${b.destructive ? " bad" : ""}`, void 0, b.done?.action, {}) : null) : null;
|
|
2277
|
+
return h(
|
|
2278
|
+
"dialog",
|
|
2279
|
+
`md ${v === "dialog" ? "dlg" : v}`,
|
|
2280
|
+
{ ...hooks4, ...own3, ref: d2 },
|
|
2281
|
+
v !== "alert" ? h("div", "mdk", { role: "button", tabIndex: 0, "aria-label": "close" }) : null,
|
|
2282
|
+
head4,
|
|
2283
|
+
h("div", "mdb", null, b.message ? h("p", "mdm", { id: mid }, b.message) : null, ...kids2(b.blocks)),
|
|
2284
|
+
foot2,
|
|
2285
|
+
v === "tool" ? h("span", "mdz", { role: "slider", tabIndex: 0, "aria-label": "resize", "aria-valuemin": "280", "aria-valuenow": "360", "aria-valuetext": "360 by 440" }) : null,
|
|
2286
|
+
v === "tool" ? h("span", "mde", { "aria-hidden": "true" }) : null
|
|
2287
|
+
);
|
|
2288
|
+
}
|
|
2289
|
+
|
|
2290
|
+
// react/src/kinds/nav.ts
|
|
2291
|
+
import { linkable as linkable5 } from "./core.js";
|
|
2292
|
+
var link = (l, cls = "") => h(linkable5(l.href) ? "a" : "span", cls, { href: linkable5(l.href) ? l.href : void 0, "aria-current": l.current ? "page" : void 0 }, l.label);
|
|
2293
|
+
function nav({ b, hooks: hooks4 }) {
|
|
2294
|
+
return h("nav", "nav", hooks4, b.brand ? link(b.brand, "brand") : null, ...b.links.map((l) => link(l)));
|
|
2295
|
+
}
|
|
2296
|
+
|
|
2297
|
+
// react/src/kinds/pages.ts
|
|
2298
|
+
import { createElement as createElement14, Fragment as Fragment2, useLayoutEffect as useLayoutEffect7, useRef as useRef14 } from "react";
|
|
2299
|
+
import { linkable as linkable7 } from "./core.js";
|
|
2300
|
+
|
|
2301
|
+
// src/gen/shapes.ts
|
|
2302
|
+
var kinds = {
|
|
2303
|
+
"boxplot": "Boxplot",
|
|
2304
|
+
"button": "Button",
|
|
2305
|
+
"card": "Card",
|
|
2306
|
+
"chart": "Chart",
|
|
2307
|
+
"chips": "Chips",
|
|
2308
|
+
"choice": "Choice",
|
|
2309
|
+
"composer": "Composer",
|
|
2310
|
+
"config": "Form",
|
|
2311
|
+
"diagram": "Diagram",
|
|
2312
|
+
"diff": "Diff",
|
|
2313
|
+
"editor": "Editor",
|
|
2314
|
+
"form": "Form",
|
|
2315
|
+
"glance": "Glance",
|
|
2316
|
+
"heat": "Heat",
|
|
2317
|
+
"hero": "Hero",
|
|
2318
|
+
"images": "Images",
|
|
2319
|
+
"import": "Import",
|
|
2320
|
+
"island": "Island",
|
|
2321
|
+
"lines": "Lines",
|
|
2322
|
+
"list": "List",
|
|
2323
|
+
"media": "Media",
|
|
2324
|
+
"message": "Message",
|
|
2325
|
+
"modal": "Modal",
|
|
2326
|
+
"nav": "Nav",
|
|
2327
|
+
"pages": "Pages",
|
|
2328
|
+
"plot": "Plot",
|
|
2329
|
+
"prose": "Prose",
|
|
2330
|
+
"row": "Row",
|
|
2331
|
+
"run": "Run",
|
|
2332
|
+
"scene": "Scene",
|
|
2333
|
+
"screen": "Screen",
|
|
2334
|
+
"secret": "Secret",
|
|
2335
|
+
"section": "Section",
|
|
2336
|
+
"sheet": "Modal",
|
|
2337
|
+
"sidebar": "Sidebar",
|
|
2338
|
+
"stat": "Stat",
|
|
2339
|
+
"steps": "Steps",
|
|
2340
|
+
"table": "Table",
|
|
2341
|
+
"text": "Text",
|
|
2342
|
+
"timeline": "Timeline",
|
|
2343
|
+
"toast": "Toast",
|
|
2344
|
+
"tool": "Tool",
|
|
2345
|
+
"web": "Web"
|
|
2346
|
+
};
|
|
2347
|
+
|
|
2348
|
+
// src/core/check.ts
|
|
2349
|
+
var KINDS = Object.keys(kinds);
|
|
2350
|
+
|
|
2351
|
+
// src/core/eval.ts
|
|
2352
|
+
var own = (o, k) => Object.prototype.hasOwnProperty.call(o, k);
|
|
2353
|
+
var rec3 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
2354
|
+
var UNKNOWN = { "?": null };
|
|
2355
|
+
var PAIRS = { eq: 2, lt: 2, has: 2, add: 2, sub: 2, mul: 2, div: 2, pick: 3 };
|
|
2356
|
+
function read3(v) {
|
|
2357
|
+
if (Array.isArray(v)) return void 0;
|
|
2358
|
+
if (!rec3(v)) return v;
|
|
2359
|
+
const keys3 = Object.keys(v);
|
|
2360
|
+
const k = keys3[0] ?? "";
|
|
2361
|
+
const a = v[k];
|
|
2362
|
+
const one = (x) => x === void 0 ? UNKNOWN : { [k]: x };
|
|
2363
|
+
const list3 = (n) => {
|
|
2364
|
+
if (!Array.isArray(a) || n !== void 0 && a.length !== n) return UNKNOWN;
|
|
2365
|
+
const xs = a.map(read3);
|
|
2366
|
+
return xs.includes(void 0) ? UNKNOWN : { [k]: xs };
|
|
2367
|
+
};
|
|
2368
|
+
if (keys3.length !== 1) return UNKNOWN;
|
|
2369
|
+
if (k === "get") return typeof a === "string" ? v : UNKNOWN;
|
|
2370
|
+
if (k === "not" || k === "len") return one(read3(a));
|
|
2371
|
+
if (k === "all" || k === "any" || k === "cat") return list3();
|
|
2372
|
+
if (own(PAIRS, k)) return list3(PAIRS[k]);
|
|
2373
|
+
if (k === "is" && rec3(a) && typeof a["pattern"] === "string" && "value" in a) {
|
|
2374
|
+
const x = read3(a["value"]);
|
|
2375
|
+
return x === void 0 ? UNKNOWN : { is: { value: x, pattern: a["pattern"] } };
|
|
2376
|
+
}
|
|
2377
|
+
return UNKNOWN;
|
|
2378
|
+
}
|
|
2379
|
+
var flag = (l) => l === null ? false : typeof l === "boolean" ? l : void 0;
|
|
2380
|
+
var or = (b) => b ?? null;
|
|
2381
|
+
var num2 = (f) => Number.isFinite(f) ? f : null;
|
|
2382
|
+
var text2 = (l) => l === null ? "" : String(l);
|
|
2383
|
+
var blank = /\p{White_Space}/u;
|
|
2384
|
+
var trim = (s) => s.replace(/^\p{White_Space}+|\p{White_Space}+$/gu, "");
|
|
2385
|
+
var points = (s) => Array.from(s, (c) => c.codePointAt(0) ?? 0);
|
|
2386
|
+
function before(a, b) {
|
|
2387
|
+
const [x, y] = [points(a), points(b)];
|
|
2388
|
+
const i = x.findIndex((c, j) => c !== y[j]);
|
|
2389
|
+
return i < 0 ? x.length < y.length : i < y.length && (x[i] ?? 0) < (y[i] ?? 0);
|
|
2390
|
+
}
|
|
2391
|
+
function email(s) {
|
|
2392
|
+
const at2 = s.indexOf("@");
|
|
2393
|
+
if (at2 < 0) return false;
|
|
2394
|
+
const [user, host] = [s.slice(0, at2), s.slice(at2 + 1)];
|
|
2395
|
+
const dot = host.indexOf(".");
|
|
2396
|
+
return user !== "" && dot > 0 && dot + 1 < host.length && !host.endsWith(".") && !host.includes("@") && !blank.test(s);
|
|
2397
|
+
}
|
|
2398
|
+
function url(s) {
|
|
2399
|
+
const rest = s.startsWith("https://") ? s.slice(8) : s.startsWith("http://") ? s.slice(7) : void 0;
|
|
2400
|
+
return rest !== void 0 && rest !== "" && !rest.startsWith("/") && !blank.test(s);
|
|
2401
|
+
}
|
|
2402
|
+
function is(l, p) {
|
|
2403
|
+
if (p === "filled") return typeof l === "string" ? trim(l) !== "" : l !== null;
|
|
2404
|
+
if (p === "number" && typeof l === "number") return true;
|
|
2405
|
+
if (typeof l !== "string") return null;
|
|
2406
|
+
const t = trim(l);
|
|
2407
|
+
if (p === "number") return /^[+-]?([0-9]+\.?[0-9]*|\.[0-9]+)([eE][+-]?[0-9]+)?$/.test(t) && Number.isFinite(Number(t));
|
|
2408
|
+
return p === "email" ? email(l) : p === "url" ? url(l) : null;
|
|
2409
|
+
}
|
|
2410
|
+
function ev(e, s) {
|
|
2411
|
+
if (!rec3(e)) return e === null || typeof e === "boolean" || typeof e === "number" || typeof e === "string" ? e : null;
|
|
2412
|
+
const [k = "", a] = Object.entries(e)[0] ?? [];
|
|
2413
|
+
const xs = (Array.isArray(a) ? a : [a]).map((x2) => k === "is" ? null : ev(x2, s));
|
|
2414
|
+
const [x = null, y = null] = xs;
|
|
2415
|
+
const n = typeof x === "number" && typeof y === "number" ? { x, y } : void 0;
|
|
2416
|
+
const flags = xs.map(flag);
|
|
2417
|
+
switch (k) {
|
|
2418
|
+
case "get":
|
|
2419
|
+
return typeof a === "string" && own(s, a) ? s[a] ?? null : null;
|
|
2420
|
+
case "not":
|
|
2421
|
+
return or(flag(x) === void 0 ? void 0 : !flag(x));
|
|
2422
|
+
case "all":
|
|
2423
|
+
return or(flags.includes(void 0) ? void 0 : flags.every(Boolean));
|
|
2424
|
+
case "any":
|
|
2425
|
+
return or(flags.includes(void 0) ? void 0 : flags.some(Boolean));
|
|
2426
|
+
case "eq":
|
|
2427
|
+
return x === y;
|
|
2428
|
+
case "lt":
|
|
2429
|
+
return n ? n.x < n.y : typeof x === "string" && typeof y === "string" ? before(x, y) : null;
|
|
2430
|
+
case "len":
|
|
2431
|
+
return typeof x === "string" ? points(x).length : null;
|
|
2432
|
+
case "has":
|
|
2433
|
+
return typeof x === "string" && typeof y === "string" ? x.includes(y) : null;
|
|
2434
|
+
case "is":
|
|
2435
|
+
return rec3(a) ? is(ev(a["value"], s), a["pattern"]) : null;
|
|
2436
|
+
case "add":
|
|
2437
|
+
return n ? num2(n.x + n.y) : null;
|
|
2438
|
+
case "sub":
|
|
2439
|
+
return n ? num2(n.x - n.y) : null;
|
|
2440
|
+
case "mul":
|
|
2441
|
+
return n ? num2(n.x * n.y) : null;
|
|
2442
|
+
case "div":
|
|
2443
|
+
return n ? num2(n.x / n.y) : null;
|
|
2444
|
+
case "cat":
|
|
2445
|
+
return xs.map(text2).join("");
|
|
2446
|
+
case "pick":
|
|
2447
|
+
return flags[0] === void 0 ? null : xs[flags[0] ? 1 : 2] ?? null;
|
|
2448
|
+
}
|
|
2449
|
+
return null;
|
|
2450
|
+
}
|
|
2451
|
+
function evaluate2(e, s) {
|
|
2452
|
+
const x = read3(e);
|
|
2453
|
+
return x === void 0 ? null : ev(x, s);
|
|
2454
|
+
}
|
|
2455
|
+
|
|
2456
|
+
// src/render/dom.ts
|
|
2457
|
+
var nodes = (html) => Array.from(new DOMParser().parseFromString("<body>" + html, "text/html").body.childNodes);
|
|
2458
|
+
var el = (tag, cls = "", html = "") => {
|
|
2459
|
+
const e = document.createElement(tag);
|
|
2460
|
+
if (cls) e.className = cls;
|
|
2461
|
+
if (html) e.replaceChildren(...nodes(html));
|
|
2462
|
+
return e;
|
|
2463
|
+
};
|
|
2464
|
+
var h2 = (tag, cls, ...kids3) => {
|
|
2465
|
+
const e = el(tag, cls);
|
|
2466
|
+
e.append(...kids3);
|
|
2467
|
+
return e;
|
|
2468
|
+
};
|
|
2469
|
+
|
|
2470
|
+
// src/paging.ts
|
|
2471
|
+
var views2 = /* @__PURE__ */ new Map();
|
|
2472
|
+
var MOST = 4;
|
|
2473
|
+
var calm = (e) => matchMedia("(prefers-reduced-motion: reduce)").matches || getComputedStyle(e).getPropertyValue("--motion").trim() === "0";
|
|
2474
|
+
var scroller = (e) => {
|
|
2475
|
+
for (let p = e.parentElement; p; p = p.parentElement) if (/auto|scroll/.test(getComputedStyle(p).overflowY) && p.scrollHeight > p.clientHeight) return p;
|
|
2476
|
+
return document.scrollingElement ?? document.documentElement;
|
|
2477
|
+
};
|
|
2478
|
+
var zoom2 = (s, well, col, keep, drawn2) => {
|
|
2479
|
+
let w = typeof keep["zoom"] === "number" ? keep["zoom"] : 1;
|
|
2480
|
+
let [o, shown4] = [[0, 0], 1];
|
|
2481
|
+
const write = (z) => {
|
|
2482
|
+
const k = z / w;
|
|
2483
|
+
[w, shown4] = [z, 1];
|
|
2484
|
+
col.classList.remove("zs");
|
|
2485
|
+
col.style.cssText = `--z:${z}`;
|
|
2486
|
+
well.scrollLeft = (o[0] ?? 0) * k - well.clientWidth / 2;
|
|
2487
|
+
scroller(s).scrollTop += (o[1] ?? 0) * (k - 1);
|
|
2488
|
+
drawn2(z);
|
|
2489
|
+
};
|
|
2490
|
+
const apply = (z, live3) => {
|
|
2491
|
+
if (z === w && shown4 === 1) return;
|
|
2492
|
+
if (shown4 === 1) o = [well.scrollLeft + well.clientWidth / 2, Math.max(0, Math.min(col.offsetHeight, innerHeight / 2 - well.getBoundingClientRect().top))];
|
|
2493
|
+
const was = shown4;
|
|
2494
|
+
shown4 = z / w;
|
|
2495
|
+
col.classList.toggle("zs", !live3);
|
|
2496
|
+
col.style.transformOrigin = `${o[0] ?? 0}px ${o[1] ?? 0}px`;
|
|
2497
|
+
col.style.transform = `scale(${shown4})`;
|
|
2498
|
+
if (live3) return;
|
|
2499
|
+
if (was === shown4 || calm(s)) write(z);
|
|
2500
|
+
else col.addEventListener("transitionend", () => write(z), { once: true });
|
|
2501
|
+
};
|
|
2502
|
+
zoomed(well, keep, { min: 1, max: MOST, apply });
|
|
2503
|
+
well.style.touchAction = "pan-x pan-y";
|
|
2504
|
+
col.style.cssText = `--z:${w}`;
|
|
2505
|
+
drawn2(w);
|
|
2506
|
+
};
|
|
2507
|
+
function paging(s, b, had) {
|
|
2508
|
+
const n = b.pages.length;
|
|
2509
|
+
const keep = views2.get(String(b.id ?? "")) ?? {};
|
|
2510
|
+
views2.set(String(b.id ?? ""), keep);
|
|
2511
|
+
const by = (name) => s.querySelector(`button[aria-label="${name}"]`);
|
|
2512
|
+
const [prev, next, out2, fit4, into] = ["previous page", "next page", "zoom out", "fit to width", "zoom in"].map(by);
|
|
2513
|
+
const [count, well, col] = [s.querySelector(".dcc"), s.querySelector(".dcw"), s.querySelector(".dck")];
|
|
2514
|
+
if (!n || !prev || !next || !out2 || !fit4 || !into || !count || !well || !col) return;
|
|
2515
|
+
const figs = Array.from(col.children);
|
|
2516
|
+
figs.forEach((f, i) => {
|
|
2517
|
+
const im = f.querySelector("img");
|
|
2518
|
+
const named4 = (e) => (e.setAttribute("aria-label", `${im?.alt ?? ""} Not loaded.`), e.setAttribute("role", "img"), e);
|
|
2519
|
+
im?.addEventListener("error", () => im.replaceWith(named4(h2("div", "dcx bad", `Page ${i + 1} didn't load. ${b.pages[i]?.alt ?? ""}`))));
|
|
2520
|
+
});
|
|
2521
|
+
const at2 = () => Math.min(n - 1, Math.max(0, typeof keep["at"] === "number" ? keep["at"] : 0));
|
|
2522
|
+
let w = 1;
|
|
2523
|
+
const sync = () => {
|
|
2524
|
+
count.textContent = `page ${at2() + 1} of ${n}`;
|
|
2525
|
+
const had2 = document.activeElement;
|
|
2526
|
+
[prev.disabled, next.disabled] = [at2() === 0, at2() === n - 1];
|
|
2527
|
+
[out2.disabled, fit4.disabled, into.disabled] = [w <= 1, w <= 1, w >= MOST];
|
|
2528
|
+
if ([prev, next, out2, fit4, into].some((x) => x.disabled && x === had2)) well.focus({ preventScroll: true });
|
|
2529
|
+
fit4.replaceChildren(h2("span", "", w <= 1 ? "fit" : `${Math.round(w * 100)}%`));
|
|
2530
|
+
};
|
|
2531
|
+
const go2 = (i) => {
|
|
2532
|
+
keep["at"] = Math.min(n - 1, Math.max(0, i));
|
|
2533
|
+
figs[at2()]?.scrollIntoView({ block: "start", behavior: calm(s) ? "instant" : "smooth" });
|
|
2534
|
+
sync();
|
|
2535
|
+
say(`page ${at2() + 1} of ${n}`);
|
|
2536
|
+
};
|
|
2537
|
+
const seen2 = () => {
|
|
2538
|
+
if (!well.isConnected) return s.ownerDocument.removeEventListener("scroll", seen2, true);
|
|
2539
|
+
const shown4 = figs.map((f) => f.getBoundingClientRect()).map((r) => Math.min(r.bottom, innerHeight) - Math.max(r.top, 0));
|
|
2540
|
+
keep["at"] = shown4.indexOf(Math.max(...shown4));
|
|
2541
|
+
sync();
|
|
2542
|
+
};
|
|
2543
|
+
s.ownerDocument.addEventListener("scroll", seen2, { capture: true, passive: true });
|
|
2544
|
+
zoom2(s, well, col, keep, (z) => (w = z, sync()));
|
|
2545
|
+
well.addEventListener("keydown", (e) => {
|
|
2546
|
+
if (e.key !== "PageDown" && e.key !== "PageUp") return;
|
|
2547
|
+
e.preventDefault();
|
|
2548
|
+
go2(at2() + (e.key === "PageDown" ? 1 : -1));
|
|
2549
|
+
});
|
|
2550
|
+
const step2 = (k) => () => well.dispatchEvent(new KeyboardEvent("keydown", { key: k }));
|
|
2551
|
+
[prev.onclick, next.onclick] = [() => go2(at2() - 1), () => go2(at2() + 1)];
|
|
2552
|
+
[into.onclick, out2.onclick, fit4.onclick] = [step2("+"), step2("-"), step2("0")];
|
|
2553
|
+
if (had) queueMicrotask(() => [well, ...s.querySelectorAll("button, a")].find((x) => x.getAttribute("aria-label") === had)?.focus({ preventScroll: true }));
|
|
2554
|
+
}
|
|
2555
|
+
|
|
2556
|
+
// react/src/kinds/pages.ts
|
|
2557
|
+
var key2 = (label2, name) => h("button", "", { type: "button", "aria-label": name }, h("span", "", null, label2));
|
|
2558
|
+
function pages({ b, hooks: hooks4 }) {
|
|
2559
|
+
const root = useRef14(null);
|
|
2560
|
+
const a = typeof document === "undefined" ? null : document.activeElement;
|
|
2561
|
+
const had = a && root.current?.contains(a) ? a.getAttribute("aria-label") : null;
|
|
2562
|
+
useLayoutEffect7(() => void (root.current && paging(root.current, b, had)), [b]);
|
|
2563
|
+
const [title, n] = [b.title || "Document", b.pages.length];
|
|
2564
|
+
const wide = Math.max(1, ...b.pages.map((p) => p.width));
|
|
2565
|
+
const bar6 = n ? [key2("\u2039", "previous page"), key2("\u203A", "next page"), h("i", "", null), key2("\u2212", "zoom out"), key2("fit", "fit to width"), key2("+", "zoom in")] : [];
|
|
2566
|
+
if (b.file && linkable7(b.file)) bar6.push(...n ? [h("i", "", null)] : [], btn("pdf", "", b.file, void 0, { "aria-label": `download ${title} as PDF` }));
|
|
2567
|
+
const sheet2 = (p, i) => h("figure", "dc", { style: { "--pw": p.width / wide, "--a": `${p.width} / ${p.height}` } }, h("img", "", { loading: "lazy", alt: `Page ${i + 1} of ${n}. ${p.alt}`, width: p.width, height: p.height, src: linkable7(p.src) ? p.src : "" }));
|
|
2568
|
+
const body2 = n ? h("div", "dcw", { role: "region", "aria-label": `${title}, ${n} pages`, tabIndex: 0 }, h("div", "dck", null, ...b.pages.map(sheet2))) : h("div", "dce", null, "No pages yet");
|
|
2569
|
+
const head4 = h("div", "dch", null, h("b", "dct", null, title), h("span", "dcc", null, n ? null : "no pages"), bar6.length ? h("div", "dcb", null, ...bar6) : null);
|
|
2570
|
+
return h("section", "dcs", { ...hooks4, ref: root }, createElement14(Fragment2, { key: JSON.stringify(b) }, head4, b.note ? h("p", "dcn", null, b.note) : null, body2));
|
|
2571
|
+
}
|
|
2572
|
+
|
|
2573
|
+
// react/src/kinds/prose.ts
|
|
2574
|
+
import { linkable as linkable8 } from "./core.js";
|
|
2575
|
+
var MARKS = [["code", "code"], ["i", "italic"], ["b", "bold"]];
|
|
2576
|
+
var spans = (ss) => ss.map((s) => {
|
|
2577
|
+
let n = s.text;
|
|
2578
|
+
for (const [tag, k] of MARKS) if (s[k]) n = h(tag, "", null, n);
|
|
2579
|
+
return s.link != null && linkable8(s.link) ? h("a", "", { href: s.link }, n) : n;
|
|
2580
|
+
});
|
|
2581
|
+
function part2(p) {
|
|
2582
|
+
switch (p.part) {
|
|
2583
|
+
case "heading":
|
|
2584
|
+
return h(`h${Math.min(6, Math.max(1, p.level))}`, "", null, ...spans(p.spans));
|
|
2585
|
+
case "para":
|
|
2586
|
+
return h("p", "", null, ...spans(p.spans));
|
|
2587
|
+
case "quote":
|
|
2588
|
+
return h("blockquote", "", null, ...spans(p.spans));
|
|
2589
|
+
case "list":
|
|
2590
|
+
return h(p.ordered ? "ol" : "ul", "", null, ...p.items.map((i) => h("li", "", null, ...spans(i))));
|
|
2591
|
+
case "code":
|
|
2592
|
+
return h("pre", "", null, h("code", p.lang != null ? `lang-${p.lang}` : "", null, p.text));
|
|
2593
|
+
case "rule":
|
|
2594
|
+
return h("hr", "", null);
|
|
2595
|
+
}
|
|
2596
|
+
}
|
|
2597
|
+
function prose({ b, hooks: hooks4 }) {
|
|
2598
|
+
return h("div", "prose", { ...hooks4, ...b.streaming ? { "aria-busy": "true" } : null }, ...b.parts.map(part2));
|
|
2599
|
+
}
|
|
2600
|
+
|
|
2601
|
+
// react/src/kinds/row.ts
|
|
2602
|
+
import { useContext as useContext16, useRef as useRef15, useState as useState13 } from "react";
|
|
2603
|
+
function round2(d2, now, cx) {
|
|
2604
|
+
const tap = now ? null : d2.tap ?? null;
|
|
2605
|
+
const url2 = urlOf(tap);
|
|
2606
|
+
const parts2 = [h("span", "rdn", null, d2.name), h("span", "rdu", null, d2.summary ?? ""), d2.since ? h("span", "rdt", null, ticked({ since: d2.since }, cx)) : null, tap ? h("span", "rc", null, "\u203A") : null];
|
|
2607
|
+
const pressed = tap && { "data-action": sends(tap), ...press(() => cx.tap(tap)) };
|
|
2608
|
+
const l = url2 ? h("a", "rdl tap", out(url2), ...parts2) : h("div", tap ? "rdl tap" : "rdl", pressed || null, ...parts2);
|
|
2609
|
+
const links = d2.links ?? [];
|
|
2610
|
+
const lines = d2.lane?.lines ?? [];
|
|
2611
|
+
const line = (t, i) => d2.state === "working" && i === lines.length - 1 ? h("div", "live", null, `\u258D ${t}`) : h("div", "", null, t);
|
|
2612
|
+
const lane2 = d2.lane ? [h("div", "rdh", null, [d2.lane.name, d2.lane.harness, d2.lane.model, d2.lane.host].filter(Boolean).join(" \xB7 ")), h("div", "rdo", null, ...lines.map(line))] : [];
|
|
2613
|
+
const link3 = links.map((k) => btn(k.label, "", urlOf(k.tap), sends(k.tap), { onClick: urlOf(k.tap) ? void 0 : () => cx.tap(k.tap) }));
|
|
2614
|
+
const body2 = now && (d2.lane || d2.blocks?.length || links.length) ? h("div", "rdb", null, ...lane2, ...kids2(d2.blocks), links.length ? h("div", "rdk", null, ...link3) : null) : null;
|
|
2615
|
+
return h("li", `rd ${d2.state}${now ? " now" : ""}`, null, h("i", "rdm", { "aria-label": d2.state }), h("div", "rdx", null, l, body2));
|
|
2616
|
+
}
|
|
2617
|
+
function row2({ b, hooks: hooks4 }) {
|
|
2618
|
+
const cx = useContext16(Cx);
|
|
2619
|
+
const tile = useContext16(Tiles).includes(b) ? " as-surface" : "";
|
|
2620
|
+
const [flip, setFlip] = useState13(false);
|
|
2621
|
+
const x0 = useRef15(0);
|
|
2622
|
+
const toggle2 = () => setFlip((f) => !f);
|
|
2623
|
+
const cls = `row${b.style === "link" ? " link" : ""}${b.sticky ? " sticky" : ""}${b.indent ? " in" + Math.min(b.indent, 3) : ""}`;
|
|
2624
|
+
const rounds = b.rounds ?? [];
|
|
2625
|
+
const last = rounds[rounds.length - 1];
|
|
2626
|
+
const open2 = last !== void 0 && last.state === "needs" !== flip;
|
|
2627
|
+
const sub = b.subtitle == null || open2 ? null : typeof b.subtitle === "string" ? { text: b.subtitle, tone: null } : b.subtitle;
|
|
2628
|
+
const badge2 = b.badge ? [" ", h("span", `tag b-row__badge ${b.badge.tone ?? ""}`, null, ticked(b.badge.text, cx))] : [];
|
|
2629
|
+
const main = h("span", "rm", null, h("span", "rt b-row__title as-title-label", null, b.title ?? ""), ...badge2, sub ? h("span", `rs b-row__subtitle ${sub.tone ?? ""}`, null, ticked(sub.text, cx)) : null);
|
|
2630
|
+
const parts2 = [b.figure ? figure(b.figure, "b-row__figure") : null, main, b.value != null ? h("span", "rv b-row__value", null, ticked(b.value, cx)) : null];
|
|
2631
|
+
const id = { "data-id": b.id ?? "" };
|
|
2632
|
+
if (last) {
|
|
2633
|
+
const r = h("div", `${cls} tap`, { ...id, "aria-expanded": String(open2), ...press(toggle2) }, ...parts2, h("span", "rc", null, "\u203A"));
|
|
2634
|
+
return h("div", `rr${open2 ? " open" : ""}`, hooks4, r, open2 ? h("ol", "rds", null, ...rounds.map((d2) => round2(d2, d2 === last, cx))) : null);
|
|
2635
|
+
}
|
|
2636
|
+
const url2 = urlOf(b.tap);
|
|
2637
|
+
const swipe2 = b.swipe ?? [];
|
|
2638
|
+
const tapped = !url2 && (b.tap != null || swipe2.length > 0);
|
|
2639
|
+
const own3 = { ...id, ...tapped ? { "data-action": sends(b.tap), ...press(() => b.tap ? cx.tap(b.tap) : toggle2()) } : null };
|
|
2640
|
+
const rc = url2 || tapped ? `${cls} tap` : cls;
|
|
2641
|
+
if (!swipe2.length) return url2 ? h("a", `${rc}${tile}`, { ...hooks4, ...own3, ...out(url2) }, ...parts2) : h("div", `${rc}${tile}`, { ...hooks4, ...own3 }, ...parts2);
|
|
2642
|
+
const touch = { onTouchStart: (e) => x0.current = e.touches[0]?.clientX ?? x0.current, onTouchEnd: (e) => x0.current - (e.changedTouches[0]?.clientX ?? x0.current) > 40 && !flip && toggle2() };
|
|
2643
|
+
const go2 = (s) => () => void cx.act({ action: s.action ?? "", block: b.id, values: s.values ?? {}, confirm: s.confirm });
|
|
2644
|
+
const bar6 = h("div", "ra b-row__actions", { hidden: !flip }, ...swipe2.map((s) => act(s, s.tone === "bad" ? "bad" : "", cx, void 0, go2(s))));
|
|
2645
|
+
return h("div", `rw${tile}`, hooks4, h("div", rc, { ...own3, ...touch }, ...parts2), bar6);
|
|
2646
|
+
}
|
|
2647
|
+
|
|
2648
|
+
// react/src/kinds/run.ts
|
|
2649
|
+
import { useContext as useContext17 } from "react";
|
|
2650
|
+
function run({ b, hooks: hooks4 }) {
|
|
2651
|
+
const cx = useContext17(Cx);
|
|
2652
|
+
const go2 = (choice2) => () => void cx.act({ action: b.action, block: b.id, values: { choice: choice2, sha: b.sha } });
|
|
2653
|
+
const meta = [b.dir, b.touches, b.sha && `sha ${b.sha}`].filter(Boolean).join(" \xB7 ");
|
|
2654
|
+
const bar6 = h("div", "bar", null, ...["approve", "deny"].map((c) => btn(c, c === "deny" ? "bad" : "primary", void 0, b.action, { key: c, onClick: go2(c) })));
|
|
2655
|
+
return h("div", "run as-surface", hooks4, h("pre", "cmd", null, b.command), h("p", "m", null, meta), bar6);
|
|
2656
|
+
}
|
|
2657
|
+
|
|
2658
|
+
// react/src/kinds/scene.ts
|
|
2659
|
+
import { useContext as useContext18 } from "react";
|
|
2660
|
+
function lane(l, cx) {
|
|
2661
|
+
const url2 = urlOf(l.tap);
|
|
2662
|
+
const tap = l.tap;
|
|
2663
|
+
const own3 = { "data-id": l.id, "aria-label": `${l.title}, ${l.state}` };
|
|
2664
|
+
const go2 = tap && !url2 ? { ...press(() => cx.tap(tap)), "data-action": sends(tap) } : null;
|
|
2665
|
+
const meta = [l.stage, l.tool, l.since ? { since: l.since } : null].filter((v) => v != null && v !== "").map((m) => ticked(m, cx));
|
|
2666
|
+
const x = meta.length ? h("span", "lnx", null, ...meta.flatMap((m, i) => i ? [" \xB7 ", m] : [m])) : null;
|
|
2667
|
+
const body2 = h("span", "lnb", null, h("span", "lnh", null, h("span", "lnt", null, l.title), h("span", "lns", null, l.state)), x);
|
|
2668
|
+
return h(url2 ? "a" : "div", `ln ${l.state}${tap ? " tap" : ""}`, { ...own3, ...go2, ...url2 ? out(url2) : null }, h("i", "lnm", null), body2);
|
|
2669
|
+
}
|
|
2670
|
+
function scene({ b, hooks: hooks4 }) {
|
|
2671
|
+
const cx = useContext18(Cx);
|
|
2672
|
+
const lanes2 = b.lanes ?? [];
|
|
2673
|
+
return h("div", "scn", hooks4, b.label ? h("div", "sh as-section-label", null, b.label) : null, lanes2.length ? h("ul", "scl", null, ...lanes2.map((l) => h("li", "", { key: l.id }, lane(l, cx)))) : null);
|
|
2674
|
+
}
|
|
2675
|
+
|
|
2676
|
+
// react/src/kinds/screen.ts
|
|
2677
|
+
import { useContext as useContext19 } from "react";
|
|
2678
|
+
import { columns } from "./core.js";
|
|
2679
|
+
var stays = (x) => x.type === "row" && x.sticky === true || x.type === "composer";
|
|
2680
|
+
function screen({ b, hooks: hooks4 }) {
|
|
2681
|
+
const cx = useContext19(Cx);
|
|
2682
|
+
const go2 = (m) => () => m.tap ? cx.tap(m.tap) : void cx.act({ action: m.action ?? "", values: m.values, confirm: m.confirm });
|
|
2683
|
+
const acts2 = (b.actions ?? []).flatMap((a) => a.menu ?? [a]).map((m) => act(m, "b-screen__actions", cx, urlOf(m.tap), urlOf(m.tap) ? void 0 : go2(m)));
|
|
2684
|
+
const head4 = h("p", "tabh", null, h("span", "tw b-screen__title as-screen-label", null, b.title ?? ""), ...acts2);
|
|
2685
|
+
const attrs = { ...hooks4, "data-id": String(b.id) };
|
|
2686
|
+
const bs = b.blocks ?? [];
|
|
2687
|
+
const split = columns(b);
|
|
2688
|
+
if (split)
|
|
2689
|
+
return h(
|
|
2690
|
+
"div",
|
|
2691
|
+
"scr split",
|
|
2692
|
+
attrs,
|
|
2693
|
+
head4,
|
|
2694
|
+
h(
|
|
2695
|
+
"div",
|
|
2696
|
+
"scr-cols",
|
|
2697
|
+
null,
|
|
2698
|
+
h("div", "scr-main", { "data-kids": "" }, ...kids2(split[0])),
|
|
2699
|
+
h("aside", "scr-side", { "aria-label": split[1].map((x) => String(x["header"] ?? "")).join(", ") }, ...kids2(split[1]))
|
|
2700
|
+
)
|
|
2701
|
+
);
|
|
2702
|
+
if (!b.focus) return h("div", "scr", attrs, head4, ...kids2(bs));
|
|
2703
|
+
const kept2 = bs.filter(stays);
|
|
2704
|
+
const at2 = kept2.findIndex((x) => x.type === "composer");
|
|
2705
|
+
const cut = at2 < 0 ? kept2.length : at2;
|
|
2706
|
+
return h("div", "scr", attrs, ...kids2(kept2.slice(0, cut)), h("div", "msgs", null, head4, ...kids2(bs.filter((x) => !stays(x)))), ...kids2(kept2.slice(cut)));
|
|
2707
|
+
}
|
|
2708
|
+
|
|
2709
|
+
// react/src/kinds/secret.ts
|
|
2710
|
+
import { useContext as useContext20, useRef as useRef16, useState as useState14 } from "react";
|
|
2711
|
+
function secret2({ b, hooks: hooks4 }) {
|
|
2712
|
+
const cx = useContext20(Cx);
|
|
2713
|
+
const [v, setV] = useState14("");
|
|
2714
|
+
const [sending, setSending] = useState14(false);
|
|
2715
|
+
const field2 = useRef16(null);
|
|
2716
|
+
const send4 = () => {
|
|
2717
|
+
if (!v) return field2.current?.focus();
|
|
2718
|
+
setSending(true);
|
|
2719
|
+
void cx.act({ action: b.action, block: b.id, values: { ...b.values, [b.name]: v } }).then((ok) => ok && setV("")).finally(() => setSending(false));
|
|
2720
|
+
};
|
|
2721
|
+
const enter = (e) => {
|
|
2722
|
+
if (e.key !== "Enter") return;
|
|
2723
|
+
e.preventDefault();
|
|
2724
|
+
send4();
|
|
2725
|
+
};
|
|
2726
|
+
const own3 = { ref: field2, type: "password", name: b.name, value: v, placeholder: b.set ? "paste to replace" : b.placeholder ?? "", autoComplete: "new-password", spellCheck: false };
|
|
2727
|
+
const input3 = h("input", "", { ...own3, onChange: (e) => setV(e.target.value), onKeyDown: enter });
|
|
2728
|
+
const k = h("span", "fk", null, b.label ?? b.name, b.set ? h("span", "set", null, "set \u2713") : null);
|
|
2729
|
+
const note2 = h("div", "ra", null, h("p", "m sn", null, "sent to the app only, never to the agent"), btn(sending ? "sending\u2026" : "send", "", void 0, b.action, { onClick: send4 }));
|
|
2730
|
+
return h("div", "secret as-surface", hooks4, h("label", "fd", null, k, input3), note2);
|
|
2731
|
+
}
|
|
2732
|
+
|
|
2733
|
+
// react/src/kinds/section.ts
|
|
2734
|
+
var GROUP = { waiting: "needs", blocked: "needs", asleep: "idle", in: "working" };
|
|
2735
|
+
var SH = { needs: "r", working: "g" };
|
|
2736
|
+
function section({ b, hooks: hooks4 }) {
|
|
2737
|
+
const w = (b.header ?? "").split(" ")[0] ?? "";
|
|
2738
|
+
const k = GROUP[w] ?? w;
|
|
2739
|
+
return h("section", "sec", hooks4, b.header ? h("h3", `sh as-header-label ${SH[k] ?? ""}`, null, b.header) : null, ...kids2(b.blocks), b.footer ? h("p", "m foot", null, b.footer) : null);
|
|
2740
|
+
}
|
|
2741
|
+
|
|
2742
|
+
// react/src/kinds/sidebar.ts
|
|
2743
|
+
import { useLayoutEffect as useLayoutEffect8, useRef as useRef17 } from "react";
|
|
2744
|
+
import { linkable as linkable9, sideCount, sideIcon, sideTitle } from "./core.js";
|
|
2745
|
+
|
|
2746
|
+
// src/sidebar.ts
|
|
2747
|
+
var HOVER_IN = 150;
|
|
2748
|
+
var HOVER_OUT = 300;
|
|
2749
|
+
var FLICK = 0.5;
|
|
2750
|
+
var CUT = 33;
|
|
2751
|
+
function toggles(root, signal, open2) {
|
|
2752
|
+
for (const g of root.querySelectorAll("button.sdk[aria-controls]")) {
|
|
2753
|
+
const id = g.getAttribute("aria-controls") ?? "";
|
|
2754
|
+
const key3 = `sidebar:${id}`;
|
|
2755
|
+
const flip = () => {
|
|
2756
|
+
const now = g.getAttribute("aria-expanded") !== "true";
|
|
2757
|
+
g.setAttribute("aria-expanded", String(now));
|
|
2758
|
+
root.querySelector(`#${CSS.escape(id)}`)?.toggleAttribute("hidden", !now);
|
|
2759
|
+
if (!open2) return;
|
|
2760
|
+
if (open2.has(key3)) open2.delete(key3);
|
|
2761
|
+
else open2.add(key3);
|
|
2762
|
+
};
|
|
2763
|
+
g.addEventListener("click", flip, { signal });
|
|
2764
|
+
}
|
|
2765
|
+
}
|
|
2766
|
+
var pullOf = (from, x0, x, wide) => Math.round(Math.min(100, Math.max(0, from + (x - x0) / wide * 100)));
|
|
2767
|
+
function swipe(d2, from, signal) {
|
|
2768
|
+
return (e) => {
|
|
2769
|
+
if (e.pointerType === "mouse" || from === 0 === (d2.shown() === "drawer")) return;
|
|
2770
|
+
const [x0, wide] = [e.clientX, d2.panel.getBoundingClientRect().width || 1];
|
|
2771
|
+
let [x1, t1] = [x0, performance.now()];
|
|
2772
|
+
let p = { at: "idle" };
|
|
2773
|
+
const go2 = (ev2) => {
|
|
2774
|
+
const [next, fx] = step(p, ev2, from);
|
|
2775
|
+
p = next;
|
|
2776
|
+
if (p.at === "previewing") {
|
|
2777
|
+
d2.root.style.setProperty("--pull", String(p.c / 100));
|
|
2778
|
+
d2.root.dataset["pull"] = "";
|
|
2779
|
+
}
|
|
2780
|
+
if (fx && fx !== "tap") {
|
|
2781
|
+
p = step(step(p, { on: "answer", ok: true }, from)[0], { on: "settled" }, from)[0];
|
|
2782
|
+
if (Math.abs(fx.send - from) > CUT === (from === 0)) d2.open();
|
|
2783
|
+
else d2.shut();
|
|
2784
|
+
} else if (p.at === "idle" && ev2.on !== "press") d2.back();
|
|
2785
|
+
};
|
|
2786
|
+
const move2 = (m) => {
|
|
2787
|
+
const t = performance.now();
|
|
2788
|
+
const fast = Math.abs(m.clientX - x1) / Math.max(1, t - t1) > FLICK;
|
|
2789
|
+
[x1, t1] = [m.clientX, t];
|
|
2790
|
+
const flung = m.clientX > x0 ? 100 : 0;
|
|
2791
|
+
go2({ on: "move", c: fast ? flung : pullOf(from, x0, m.clientX, wide) });
|
|
2792
|
+
};
|
|
2793
|
+
const drag = new AbortController();
|
|
2794
|
+
const end = (on) => () => {
|
|
2795
|
+
drag.abort();
|
|
2796
|
+
go2({ on });
|
|
2797
|
+
};
|
|
2798
|
+
addEventListener("pointermove", move2, { signal: drag.signal });
|
|
2799
|
+
addEventListener("pointerup", end("release"), { signal: drag.signal });
|
|
2800
|
+
addEventListener("pointercancel", end("cancel"), { signal: drag.signal });
|
|
2801
|
+
signal.addEventListener("abort", () => drag.abort());
|
|
2802
|
+
go2({ on: "press" });
|
|
2803
|
+
};
|
|
2804
|
+
}
|
|
2805
|
+
function behave(root, key3, store, open2) {
|
|
2806
|
+
const q = (s) => root.querySelector(s);
|
|
2807
|
+
const [panel, menu2, pin] = [q(".sdp"), q(".sdm"), q(".sdpin")];
|
|
2808
|
+
if (!panel || !menu2 || !pin) return () => {
|
|
2809
|
+
};
|
|
2810
|
+
const life = new AbortController();
|
|
2811
|
+
const { signal } = life;
|
|
2812
|
+
const on = (e, type, f) => e?.addEventListener(type, f, { signal });
|
|
2813
|
+
let pinned = store.get(key3) === "1";
|
|
2814
|
+
let shown4 = "rail";
|
|
2815
|
+
let timer;
|
|
2816
|
+
const to = (s) => {
|
|
2817
|
+
clearTimeout(timer);
|
|
2818
|
+
shown4 = s;
|
|
2819
|
+
if (root.dataset["pull"] !== void 0) {
|
|
2820
|
+
root.style.removeProperty("--pull");
|
|
2821
|
+
delete root.dataset["pull"];
|
|
2822
|
+
}
|
|
2823
|
+
root.dataset["side"] = shown4 === "rail" && pinned ? "pinned" : shown4;
|
|
2824
|
+
menu2.setAttribute("aria-expanded", String(shown4 === "drawer"));
|
|
2825
|
+
pin.setAttribute("aria-pressed", String(pinned));
|
|
2826
|
+
pin.setAttribute("aria-label", pinned ? "unpin sidebar" : "pin sidebar");
|
|
2827
|
+
};
|
|
2828
|
+
const focusables = () => Array.from(panel.querySelectorAll("a[href], button")).filter((e) => e.offsetParent !== null);
|
|
2829
|
+
const openDrawer = () => {
|
|
2830
|
+
to("drawer");
|
|
2831
|
+
focusables()[0]?.focus();
|
|
2832
|
+
};
|
|
2833
|
+
const shut = () => {
|
|
2834
|
+
const was = shown4;
|
|
2835
|
+
to("rail");
|
|
2836
|
+
if (was === "drawer") menu2.focus();
|
|
2837
|
+
};
|
|
2838
|
+
const hover = (s, ms) => (e) => {
|
|
2839
|
+
const mouse = !(e instanceof PointerEvent) || e.pointerType === "mouse";
|
|
2840
|
+
const inside = s === "rail" && e instanceof FocusEvent && e.relatedTarget instanceof Node && panel.contains(e.relatedTarget);
|
|
2841
|
+
if (!mouse || inside || pinned || shown4 !== (s === "open" ? "rail" : "open")) return;
|
|
2842
|
+
clearTimeout(timer);
|
|
2843
|
+
timer = setTimeout(() => to(s), ms);
|
|
2844
|
+
};
|
|
2845
|
+
on(menu2, "click", openDrawer);
|
|
2846
|
+
on(q(".sdx"), "click", shut);
|
|
2847
|
+
on(q(".sdscrim"), "click", shut);
|
|
2848
|
+
on(pin, "click", () => {
|
|
2849
|
+
pinned = !pinned;
|
|
2850
|
+
store.put(key3, pinned ? "1" : null);
|
|
2851
|
+
to("rail");
|
|
2852
|
+
});
|
|
2853
|
+
on(panel, "pointerenter", hover("open", HOVER_IN));
|
|
2854
|
+
on(panel, "focusin", hover("open", HOVER_IN));
|
|
2855
|
+
on(panel, "pointerleave", hover("rail", HOVER_OUT));
|
|
2856
|
+
on(panel, "focusout", hover("rail", HOVER_OUT));
|
|
2857
|
+
on(panel, "click", (e) => {
|
|
2858
|
+
if (shown4 === "drawer" && e.target instanceof Element && e.target.closest("a[href]")) shut();
|
|
2859
|
+
});
|
|
2860
|
+
on(root, "keydown", (e) => {
|
|
2861
|
+
if (e.key === "Escape" && shown4 !== "rail") {
|
|
2862
|
+
e.preventDefault();
|
|
2863
|
+
shut();
|
|
2864
|
+
}
|
|
2865
|
+
if (e.key !== "Tab" || shown4 !== "drawer") return;
|
|
2866
|
+
const all = focusables();
|
|
2867
|
+
const [first2, last] = [all[0], all[all.length - 1]];
|
|
2868
|
+
const at2 = document.activeElement;
|
|
2869
|
+
if (!(e.shiftKey ? at2 === first2 || !panel.contains(at2) : at2 === last)) return;
|
|
2870
|
+
e.preventDefault();
|
|
2871
|
+
(e.shiftKey ? last : first2)?.focus();
|
|
2872
|
+
});
|
|
2873
|
+
const d2 = { root, panel, shown: () => shown4, open: openDrawer, shut, back: () => to(shown4) };
|
|
2874
|
+
on(q(".sdedge"), "pointerdown", swipe(d2, 0, signal));
|
|
2875
|
+
on(panel, "pointerdown", swipe(d2, 100, signal));
|
|
2876
|
+
toggles(root, signal, open2);
|
|
2877
|
+
to("rail");
|
|
2878
|
+
return () => {
|
|
2879
|
+
life.abort();
|
|
2880
|
+
clearTimeout(timer);
|
|
2881
|
+
};
|
|
2882
|
+
}
|
|
2883
|
+
|
|
2884
|
+
// react/src/kinds/sidebar.ts
|
|
2885
|
+
var shelf = () => {
|
|
2886
|
+
try {
|
|
2887
|
+
return typeof localStorage === "undefined" ? null : localStorage;
|
|
2888
|
+
} catch {
|
|
2889
|
+
return null;
|
|
2890
|
+
}
|
|
2891
|
+
};
|
|
2892
|
+
var kept = {
|
|
2893
|
+
get: (k) => shelf()?.getItem(k) ?? null,
|
|
2894
|
+
put: (k, v) => {
|
|
2895
|
+
if (v === null) shelf()?.removeItem(k);
|
|
2896
|
+
else shelf()?.setItem(k, v);
|
|
2897
|
+
}
|
|
2898
|
+
};
|
|
2899
|
+
var badge = (b) => {
|
|
2900
|
+
if (!b) return null;
|
|
2901
|
+
const [shown4, said5] = sideCount(b);
|
|
2902
|
+
return h("span", b.tone === "bad" ? "tag bad" : "tag", null, h("span", "", { "aria-hidden": "true" }, shown4), h("span", "b-sr", null, said5));
|
|
2903
|
+
};
|
|
2904
|
+
var icon = (l) => {
|
|
2905
|
+
const [g, initials] = sideIcon(l);
|
|
2906
|
+
return h("i", initials ? "sdi av" : "sdi", { "aria-hidden": "true" }, g);
|
|
2907
|
+
};
|
|
2908
|
+
var link2 = (l, child, cls = "sdk") => h(
|
|
2909
|
+
linkable9(l.href ?? "") ? "a" : "span",
|
|
2910
|
+
cls,
|
|
2911
|
+
{ href: linkable9(l.href ?? "") ? l.href ?? void 0 : void 0, "aria-current": l.current ? "page" : void 0 },
|
|
2912
|
+
child ? null : icon(l),
|
|
2913
|
+
h("span", "sdl", { title: l.label }, l.label),
|
|
2914
|
+
badge(l.badge)
|
|
2915
|
+
);
|
|
2916
|
+
function parent(l, id) {
|
|
2917
|
+
const kids3 = l.children ?? [];
|
|
2918
|
+
const inner = kids3.some((k) => k.current);
|
|
2919
|
+
const open2 = l.open === true || inner;
|
|
2920
|
+
return [
|
|
2921
|
+
h("button", inner ? "sdk in" : "sdk", { key: "b", type: "button", "aria-controls": id, "aria-expanded": String(open2) }, icon(l), h("span", "sdl", { title: l.label }, l.label), badge(l.badge), h("i", "sdc", { "aria-hidden": "true" }, "\u25B8")),
|
|
2922
|
+
h("ul", "sdsub", { key: "u", id, hidden: !open2 || void 0 }, ...kids3.map((k) => h("li", "", null, link2(k, true))))
|
|
2923
|
+
];
|
|
2924
|
+
}
|
|
2925
|
+
var button2 = (cls, name, ...text4) => h("button", cls, { type: "button", "aria-label": name }, ...text4.map((t) => h("span", "", null, t)));
|
|
2926
|
+
function sidebar({ b, hooks: hooks4 }) {
|
|
2927
|
+
const ref3 = useRef17(null);
|
|
2928
|
+
const id = `sd-${b.id ?? "side"}`;
|
|
2929
|
+
useLayoutEffect8(() => ref3.current ? behave(ref3.current, `sidebar-pin:${b.id ?? "side"}`, kept) : void 0, [b]);
|
|
2930
|
+
const groups = b.groups.flatMap(
|
|
2931
|
+
(g, gi) => g.links.length ? [
|
|
2932
|
+
h(
|
|
2933
|
+
"section",
|
|
2934
|
+
"sdgr",
|
|
2935
|
+
{ "aria-labelledby": g.title ? `${id}-t${gi}` : void 0 },
|
|
2936
|
+
g.title ? h("h3", "sdgt", { id: `${id}-t${gi}` }, g.title) : null,
|
|
2937
|
+
h("ul", "", null, ...g.links.map((l, li) => h("li", "", null, ...l.children ? parent(l, `${id}-g${gi}-${li}`) : [link2(l, false)])))
|
|
2938
|
+
)
|
|
2939
|
+
] : []
|
|
2940
|
+
);
|
|
2941
|
+
const foot2 = b.footer?.length ? h("div", "sdf", null, h("ul", "", null, ...b.footer.map((l) => h("li", "", null, link2(l, false))))) : null;
|
|
2942
|
+
return h(
|
|
2943
|
+
"div",
|
|
2944
|
+
"sd",
|
|
2945
|
+
{ ...hooks4, ref: ref3 },
|
|
2946
|
+
h("button", "sdm", { type: "button", "aria-label": "menu", "aria-controls": id, "aria-expanded": "false" }, h("span", "", null, "\u2261")),
|
|
2947
|
+
h("span", "sdn", null, sideTitle(b)),
|
|
2948
|
+
h("div", "sdscrim", { "aria-hidden": "true" }),
|
|
2949
|
+
h("div", "sdedge", { "aria-hidden": "true" }),
|
|
2950
|
+
h(
|
|
2951
|
+
"div",
|
|
2952
|
+
"sdp",
|
|
2953
|
+
{ id },
|
|
2954
|
+
h("div", "sdh", null, b.brand ? link2(b.brand, false, "sdk sdb") : null, button2("sdpin", "pin sidebar", "pin", "unpin"), button2("sdx", "close menu", "\xD7")),
|
|
2955
|
+
h("div", "sdg", null, ...groups.length ? groups : [h("p", "empty", null, b.empty ?? "No pages yet")]),
|
|
2956
|
+
foot2
|
|
2957
|
+
)
|
|
2958
|
+
);
|
|
2959
|
+
}
|
|
2960
|
+
|
|
2961
|
+
// react/src/kinds/stat.ts
|
|
2962
|
+
import { useContext as useContext21 } from "react";
|
|
2963
|
+
function stat({ b, hooks: hooks4 }) {
|
|
2964
|
+
const cx = useContext21(Cx);
|
|
2965
|
+
const tile = (i) => {
|
|
2966
|
+
const sp = i.spark ?? [];
|
|
2967
|
+
const hi = Math.max(1, ...sp);
|
|
2968
|
+
const points2 = sp.map((v, x) => `${x},${10 - v / hi * 10}`).join(" ");
|
|
2969
|
+
const spark2 = h("svg", "spark", { viewBox: `0 0 ${sp.length - 1} 10`, preserveAspectRatio: "none", "aria-hidden": "true" }, h("polyline", "", { points: points2 }));
|
|
2970
|
+
const unit2 = i.unit ? [" ", h("small", "", null, i.unit)] : [];
|
|
2971
|
+
return h("div", `st as-surface ${i.tone ?? ""}`, null, h("b", "b-stat__value", null, ticked(i.value, cx)), ...unit2, h("span", "m", null, i.label ?? ""), sp.length > 1 ? spark2 : null);
|
|
2972
|
+
};
|
|
2973
|
+
return h("div", "stats", hooks4, ...(b.items ?? [b]).map(tile));
|
|
2974
|
+
}
|
|
2975
|
+
|
|
2976
|
+
// react/src/kinds/steps.ts
|
|
2977
|
+
import { createElement as createElement15, useContext as useContext22 } from "react";
|
|
2978
|
+
var WORD = { done: "done", now: "current", todo: "to do" };
|
|
2979
|
+
function stage(s, i, n, at2, cx) {
|
|
2980
|
+
const state3 = ["done", "now", "todo"][Math.sign(i - at2) + 1] ?? "todo";
|
|
2981
|
+
const tap = state3 === "done" ? s.tap ?? null : null;
|
|
2982
|
+
const url2 = urlOf(tap);
|
|
2983
|
+
const own3 = { "aria-label": `${s.label}, step ${i + 1} of ${n}, ${WORD[state3]}`, title: s.label };
|
|
2984
|
+
const mark2 = h("span", "spr", { "aria-hidden": "true" }, i < at2 ? h("i", "spm as-mark as-tint", { "data-mark": "done" }, "\u2713") : h("i", "spm", null, String(i + 1)), h("span", "spk", null));
|
|
2985
|
+
const sub = s.sub || (i === at2 ? `step ${i + 1} of ${n}` : "");
|
|
2986
|
+
const kids3 = [mark2, h("span", "spn", null, s.label), sub ? h("span", "sps", null, sub) : null];
|
|
2987
|
+
const pressed = tap && !url2 ? { "data-action": sends(tap), ...press(() => cx.tap(tap)) } : null;
|
|
2988
|
+
const cls = tap ? "spc tap" : "spc";
|
|
2989
|
+
const x = url2 ? h("a", cls, { ...own3, ...out(url2) }, ...kids3) : h("div", cls, { ...own3, ...pressed }, ...kids3);
|
|
2990
|
+
return h("li", `spi ${state3}`, { "aria-current": i === at2 ? "step" : void 0 }, x);
|
|
2991
|
+
}
|
|
2992
|
+
function bar2(r) {
|
|
2993
|
+
const v = Math.max(0, Math.min(100, Math.round(r.value)));
|
|
2994
|
+
const aria = { role: "progressbar", "aria-valuemin": "0", "aria-valuemax": "100", "aria-valuenow": String(v), "aria-label": r.label, "aria-valuetext": r.sub ? `${v}%, ${r.sub}` : void 0 };
|
|
2995
|
+
const t = h("span", "pgt", null, h("b", "", { style: { "--v": v } }));
|
|
2996
|
+
return h("div", `pgr${r.tone ? ` ${r.tone}` : ""}${v === 0 ? " zero" : ""}`, aria, h("span", "pgn", null, r.label), h("span", "pgv", null, `${v}%`), t, r.sub ? h("span", "pgs", null, r.sub) : null);
|
|
2997
|
+
}
|
|
2998
|
+
function steps({ b, hooks: hooks4 }) {
|
|
2999
|
+
const cx = useContext22(Cx);
|
|
3000
|
+
const list3 = b.steps ?? [];
|
|
3001
|
+
const bars = b.bars ?? [];
|
|
3002
|
+
const n = list3.length;
|
|
3003
|
+
const end = b.done ? n : -1;
|
|
3004
|
+
const at2 = b.current != null ? list3.findIndex((s) => s.id === b.current) : end;
|
|
3005
|
+
if (n ? at2 < 0 : !bars.length) return createElement15(Fallen, { b });
|
|
3006
|
+
const title = b.title ? h("div", "sh as-section-label", null, b.title) : null;
|
|
3007
|
+
if (!n) return h("div", "pg", hooks4, title, h("div", bars.length > 1 ? "pgl rows" : "pgl", null, ...bars.map(bar2)));
|
|
3008
|
+
const cur = list3[at2];
|
|
3009
|
+
const tail = cur?.sub ? ` \xB7 ${cur.sub}` : "";
|
|
3010
|
+
const x = cur ? [h("b", "", null, cur.label), h("span", "m", null, `step ${at2 + 1} of ${n}${tail}`)] : [h("b", "", null, "All done"), h("span", "m", null, `${n} of ${n}`)];
|
|
3011
|
+
return h("div", "sp", hooks4, title, h("ol", "spl", null, ...list3.map((s, i) => stage(s, i, n, at2, cx))), h("div", "spx", { "aria-hidden": "true" }, ...x));
|
|
3012
|
+
}
|
|
3013
|
+
|
|
3014
|
+
// react/src/kinds/table.ts
|
|
3015
|
+
import { useContext as useContext23, useLayoutEffect as useLayoutEffect9, useReducer as useReducer2, useRef as useRef18 } from "react";
|
|
3016
|
+
|
|
3017
|
+
// src/core/table.ts
|
|
3018
|
+
var SIGN = { THB: "\u0E3F", USD: "$", EUR: "\u20AC" };
|
|
3019
|
+
var at = (r, id) => r.cells[id];
|
|
3020
|
+
var unit = (c) => c.kind === "money" ? c.currency ? SIGN[c.currency] ?? c.currency : null : c.unit;
|
|
3021
|
+
var grouped = (v, d2, fixed) => v.toLocaleString("en-US", { minimumFractionDigits: fixed ? d2 : 0, maximumFractionDigits: d2 });
|
|
3022
|
+
var number = (c, v) => c.kind === "money" ? grouped(v, 2, true) : grouped(v, c.digits ?? 2, false);
|
|
3023
|
+
function total(c, rows2) {
|
|
3024
|
+
const cells = rows2.map((r) => at(r, c.id)).filter((v) => v !== void 0);
|
|
3025
|
+
const vs = cells.filter((v) => typeof v === "number");
|
|
3026
|
+
const sum = vs.reduce((a, v) => a + v, 0);
|
|
3027
|
+
if (!c.total) return null;
|
|
3028
|
+
if (c.total === "count") return ["count", String(cells.length)];
|
|
3029
|
+
if (!vs.length) return ["", "\u2014"];
|
|
3030
|
+
return c.total === "avg" ? ["avg", grouped(sum / vs.length, 1, false)] : ["", number(c, sum)];
|
|
3031
|
+
}
|
|
3032
|
+
|
|
3033
|
+
// src/core/tree.ts
|
|
3034
|
+
var isBlk = (v) => typeof v === "object" && v !== null;
|
|
3035
|
+
|
|
3036
|
+
// src/core/text.ts
|
|
3037
|
+
function value2(v) {
|
|
3038
|
+
if (isBlk(v) && "until" in v) return String(v["label"] ?? "").replace("{rel}", `${Math.max(0, Math.round((Date.parse(String(v["until"])) - Date.now()) / 6e4))}m`);
|
|
3039
|
+
if (isBlk(v) && "since" in v) {
|
|
3040
|
+
const s = Math.max(0, (Date.now() - Date.parse(String(v["since"]))) / 1e3);
|
|
3041
|
+
if (v["label"] != null) return String(v["label"]).replace("{}", s < 120 ? `${Math.floor(s)}s` : s < 7200 ? `${Math.floor(s / 60)}m` : s < 172800 ? `${Math.floor(s / 3600)}h` : `${Math.floor(s / 86400)}d`);
|
|
3042
|
+
return s < 60 ? "now" : s < 3600 ? `${Math.floor(s / 60)}m` : s < 86400 ? `${Math.floor(s / 3600)}h ${Math.floor(s / 60) % 60}m` : `${Math.floor(s / 86400)}d`;
|
|
3043
|
+
}
|
|
3044
|
+
return String(v ?? "");
|
|
3045
|
+
}
|
|
3046
|
+
|
|
3047
|
+
// src/core/kind/table.ts
|
|
3048
|
+
var STEPS3 = [
|
|
3049
|
+
["Move up", { dir: "up" }],
|
|
3050
|
+
["Move down", { dir: "down" }],
|
|
3051
|
+
["Move to top", { dir: "up", big: true }],
|
|
3052
|
+
["Move to bottom", { dir: "down", big: true }]
|
|
3053
|
+
];
|
|
3054
|
+
var MON = "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec".split(" ");
|
|
3055
|
+
var THAI = "\u0E21.\u0E04. \u0E01.\u0E1E. \u0E21\u0E35.\u0E04. \u0E40\u0E21.\u0E22. \u0E1E.\u0E04. \u0E21\u0E34.\u0E22. \u0E01.\u0E04. \u0E2A.\u0E04. \u0E01.\u0E22. \u0E15.\u0E04. \u0E1E.\u0E22. \u0E18.\u0E04.".split(" ");
|
|
3056
|
+
function shown(c, v, thai2 = false) {
|
|
3057
|
+
if (v === void 0) return "";
|
|
3058
|
+
if (Array.isArray(v)) return v.map((n) => number(c, n)).join(", ");
|
|
3059
|
+
if (typeof v === "object") return typeof v.text === "string" ? v.text : typeof v.text === "number" ? String(v.text) : "";
|
|
3060
|
+
if (typeof v === "number") return number(c, v);
|
|
3061
|
+
const d2 = /^(\d+)-(\d+)-(\d+)$/.exec(v);
|
|
3062
|
+
if (c.kind !== "date" || !d2) return v;
|
|
3063
|
+
const be = c.era === "be";
|
|
3064
|
+
const month = (be && thai2 ? THAI : MON)[Number(d2[2]) - 1];
|
|
3065
|
+
return month ? `${Number(d2[3])} ${month} ${Number(d2[1]) + (be ? 543 : 0)}` : v;
|
|
3066
|
+
}
|
|
3067
|
+
function parse(c, text4) {
|
|
3068
|
+
if (c.kind === "number" || c.kind === "money") {
|
|
3069
|
+
const t = text4.replace(/[,\s]/g, "");
|
|
3070
|
+
return /^[+-]?([0-9]+\.?[0-9]*|\.[0-9]+)$/.test(t) ? Number(t) : null;
|
|
3071
|
+
}
|
|
3072
|
+
if (c.kind === "date") return /^\d{4}-\d{2}-\d{2}$/.test(text4.trim()) ? text4.trim() : null;
|
|
3073
|
+
return c.kind === "text" ? text4 : null;
|
|
3074
|
+
}
|
|
3075
|
+
var editable = (b, c) => c.edit === true && b.calc?.[c.id] == null && ["text", "number", "money", "date"].includes(c.kind);
|
|
3076
|
+
var named2 = (b, r) => {
|
|
3077
|
+
const c = b.columns[0];
|
|
3078
|
+
return c && shown(c, r.cells[c.id]) || r.id;
|
|
3079
|
+
};
|
|
3080
|
+
function worked(b, r) {
|
|
3081
|
+
if (!b.calc || r.group) return r;
|
|
3082
|
+
const cells = { ...r.cells };
|
|
3083
|
+
for (const c of b.columns) {
|
|
3084
|
+
const e = b.calc[c.id];
|
|
3085
|
+
if (e == null) continue;
|
|
3086
|
+
const s = Object.fromEntries(Object.entries(cells).map(([k, v2]) => [k, Array.isArray(v2) ? null : typeof v2 !== "object" ? v2 : typeof v2.text === "string" || typeof v2.text === "number" ? v2.text : null]));
|
|
3087
|
+
const v = evaluate2(e, s);
|
|
3088
|
+
if (typeof v === "number" || typeof v === "string") cells[c.id] = v;
|
|
3089
|
+
else delete cells[c.id];
|
|
3090
|
+
}
|
|
3091
|
+
return { ...r, cells };
|
|
3092
|
+
}
|
|
3093
|
+
var head2 = (b, id) => b.rows.some((r) => r.id === id && r.group === true);
|
|
3094
|
+
var row3 = (b, id) => b.rows.find((r) => r.id === id);
|
|
3095
|
+
var column = (b, id) => b.columns.find((c) => c.id === id);
|
|
3096
|
+
function chunks(order2, isHead) {
|
|
3097
|
+
const prefix = [];
|
|
3098
|
+
const out2 = [];
|
|
3099
|
+
for (const id of order2) {
|
|
3100
|
+
const last = out2[out2.length - 1];
|
|
3101
|
+
if (isHead(id)) out2.push([id]);
|
|
3102
|
+
else if (last) last.push(id);
|
|
3103
|
+
else prefix.push(id);
|
|
3104
|
+
}
|
|
3105
|
+
return [prefix, out2];
|
|
3106
|
+
}
|
|
3107
|
+
function itemTo(b, from, g, to) {
|
|
3108
|
+
const rest = from.filter((i) => i !== g);
|
|
3109
|
+
const at2 = Math.min(to, rest.length);
|
|
3110
|
+
const first2 = rest.findIndex((i) => head2(b, i));
|
|
3111
|
+
if (first2 >= 0 && at2 <= first2) return null;
|
|
3112
|
+
rest.splice(at2, 0, g);
|
|
3113
|
+
return rest;
|
|
3114
|
+
}
|
|
3115
|
+
function groupTo(b, from, g, to) {
|
|
3116
|
+
const [prefix, all] = chunks(from, (i) => head2(b, i));
|
|
3117
|
+
const at2 = all.findIndex((c) => c[0] === g);
|
|
3118
|
+
if (at2 < 0) return null;
|
|
3119
|
+
const [it = []] = all.splice(at2, 1);
|
|
3120
|
+
all.splice(Math.min(to, all.length), 0, it);
|
|
3121
|
+
return [...prefix, ...all.flat()];
|
|
3122
|
+
}
|
|
3123
|
+
function rowsTo(b, from, g, n) {
|
|
3124
|
+
const at2 = from.indexOf(g);
|
|
3125
|
+
if (at2 < 0) return null;
|
|
3126
|
+
const t = Math.max(0, at2 + n);
|
|
3127
|
+
if (!head2(b, g)) return itemTo(b, from, g, t);
|
|
3128
|
+
const [prefix, all] = chunks(from, (i) => head2(b, i));
|
|
3129
|
+
let start2 = prefix.length;
|
|
3130
|
+
let best = [Infinity, 0];
|
|
3131
|
+
const pick2 = (d2, j) => d2 < best[0] || d2 === best[0] && j < best[1] ? [d2, j] : best;
|
|
3132
|
+
all.filter((c) => c[0] !== g).forEach((c, j) => {
|
|
3133
|
+
best = pick2(Math.abs(start2 - t), j);
|
|
3134
|
+
start2 += c.length;
|
|
3135
|
+
});
|
|
3136
|
+
best = pick2(Math.abs(start2 - t), Math.max(0, all.length - 1));
|
|
3137
|
+
return groupTo(b, from, g, best[1]);
|
|
3138
|
+
}
|
|
3139
|
+
function nudged(b, from, g, by) {
|
|
3140
|
+
if (by.dir === "left" || by.dir === "right") return null;
|
|
3141
|
+
const up = by.dir === "up";
|
|
3142
|
+
let out2;
|
|
3143
|
+
if (head2(b, g)) {
|
|
3144
|
+
const [, all] = chunks(from, (i) => head2(b, i));
|
|
3145
|
+
const at2 = all.findIndex((c) => c[0] === g);
|
|
3146
|
+
if (at2 < 0 || up && !by.big && at2 === 0) return null;
|
|
3147
|
+
out2 = groupTo(b, from, g, up ? by.big ? 0 : at2 - 1 : by.big ? all.length - 1 : at2 + 1);
|
|
3148
|
+
} else {
|
|
3149
|
+
const at2 = from.indexOf(g);
|
|
3150
|
+
if (at2 < 0 || up && !by.big && at2 === 0) return null;
|
|
3151
|
+
out2 = itemTo(b, from, g, up ? by.big ? from.findIndex((i) => head2(b, i)) + 1 : at2 - 1 : by.big ? from.length : at2 + 1);
|
|
3152
|
+
}
|
|
3153
|
+
return out2 && out2.join("\n") !== from.join("\n") ? out2 : null;
|
|
3154
|
+
}
|
|
3155
|
+
function place2(b, g, order2) {
|
|
3156
|
+
const r = row3(b, g);
|
|
3157
|
+
const name = r ? named2(b, r) : g;
|
|
3158
|
+
const [, all] = chunks(order2, (i) => head2(b, i));
|
|
3159
|
+
if (head2(b, g)) return `${name}, ${all.findIndex((c) => c[0] === g) + 1} of ${all.length}`;
|
|
3160
|
+
const mine = all.find((c) => c.includes(g));
|
|
3161
|
+
const hr = mine?.[0] === void 0 ? void 0 : row3(b, mine[0]);
|
|
3162
|
+
return mine && hr ? `${name}, ${mine.indexOf(g)} of ${mine.length - 1} in ${named2(b, hr)}` : `${name}, ${order2.indexOf(g) + 1} of ${order2.length}`;
|
|
3163
|
+
}
|
|
3164
|
+
var free = (b, id) => {
|
|
3165
|
+
const r = row3(b, id);
|
|
3166
|
+
return r && r.fixed !== true ? r : void 0;
|
|
3167
|
+
};
|
|
3168
|
+
var grid = {
|
|
3169
|
+
word: (b, g) => {
|
|
3170
|
+
if (typeof g === "string") return b.reorder != null && free(b, g) ? "reorder" : null;
|
|
3171
|
+
const c = column(b, g.column);
|
|
3172
|
+
const r = free(b, g.row);
|
|
3173
|
+
return b.edit != null && r && !r.group && c && editable(b, c) ? "edit" : null;
|
|
3174
|
+
},
|
|
3175
|
+
start: (b, g) => {
|
|
3176
|
+
if (!grid.word(b, g)) return null;
|
|
3177
|
+
if (typeof g === "string") return b.rows.map((r) => r.id);
|
|
3178
|
+
return { row: g.row, column: g.column, value: row3(b, g.row)?.cells[g.column] ?? "" };
|
|
3179
|
+
},
|
|
3180
|
+
candidate: (b, g, reach) => {
|
|
3181
|
+
const s = grid.start(b, g);
|
|
3182
|
+
if (s === null) return null;
|
|
3183
|
+
if (typeof g === "string") return Array.isArray(s) && typeof reach === "number" ? rowsTo(b, s, g, reach) : null;
|
|
3184
|
+
const c = column(b, g.column);
|
|
3185
|
+
const value3 = c && typeof reach === "string" ? parse(c, reach) : null;
|
|
3186
|
+
return value3 === null ? null : { row: g.row, column: g.column, value: value3 };
|
|
3187
|
+
},
|
|
3188
|
+
nudge: (b, g, from, by) => grid.word(b, g) && typeof g === "string" && Array.isArray(from) ? nudged(b, from, g, by) : null,
|
|
3189
|
+
steps: (b, g) => {
|
|
3190
|
+
const s = grid.start(b, g);
|
|
3191
|
+
return s ? STEPS3.filter(([, n]) => grid.nudge(b, g, s, n) !== null) : [];
|
|
3192
|
+
},
|
|
3193
|
+
says: (b, g, ch) => {
|
|
3194
|
+
if (Array.isArray(ch)) return typeof g === "string" ? place2(b, g, ch) : "";
|
|
3195
|
+
const r = row3(b, ch.row);
|
|
3196
|
+
const c = column(b, ch.column);
|
|
3197
|
+
return `${c?.label ?? ch.column}, ${r ? named2(b, r) : ch.row}, ${c ? shown(c, ch.value) : ""}`;
|
|
3198
|
+
}
|
|
3199
|
+
};
|
|
3200
|
+
var numeric = (c) => c.kind === "number" || c.kind === "money" || c.kind === "bar";
|
|
3201
|
+
var atEnd = (c) => (c.align ?? (numeric(c) ? "end" : "start")) === "end";
|
|
3202
|
+
var cellText = (c, v, thai2) => typeof v === "object" && !Array.isArray(v) ? value2(v.text) : shown(c, v, thai2);
|
|
3203
|
+
function spark(v) {
|
|
3204
|
+
const lo = Math.min(...v), hi = Math.max(...v), last = v.length - 1;
|
|
3205
|
+
return v.map((n, i) => [last > 0 ? i / last : 0.5, hi > lo ? (n - lo) / (hi - lo) : 0.5]);
|
|
3206
|
+
}
|
|
3207
|
+
var sparkPoints = (v) => spark(v).map(([x, y]) => `${(x * 100).toFixed(1)},${((1 - y) * 24).toFixed(1)}`).join(" ");
|
|
3208
|
+
var sortKey = (c, v) => c.kind === "date" && typeof v === "string" ? v : cellText(c, v, false).toLowerCase();
|
|
3209
|
+
var cmp = (c, a, b) => numeric(c) && typeof a === "number" && typeof b === "number" ? a - b : sortKey(c, a) < sortKey(c, b) ? -1 : sortKey(c, a) > sortKey(c, b) ? 1 : 0;
|
|
3210
|
+
function sorted(rows2, c, dir) {
|
|
3211
|
+
if (!c) return rows2;
|
|
3212
|
+
const by = (r, s) => {
|
|
3213
|
+
const a = at(r, c.id), b = at(s, c.id);
|
|
3214
|
+
if (a === void 0 || b === void 0) return Number(a === void 0) - Number(b === void 0);
|
|
3215
|
+
return dir === "desc" ? cmp(c, b, a) : cmp(c, a, b);
|
|
3216
|
+
};
|
|
3217
|
+
const out2 = [];
|
|
3218
|
+
let run2 = [];
|
|
3219
|
+
for (const r of rows2) {
|
|
3220
|
+
if (!r.group) run2.push(r);
|
|
3221
|
+
else out2.push(...run2.sort(by), r), run2 = [];
|
|
3222
|
+
}
|
|
3223
|
+
return [...out2, ...run2.sort(by)];
|
|
3224
|
+
}
|
|
3225
|
+
var itemsOf = (rows2, i) => {
|
|
3226
|
+
const n = rows2.slice(i + 1).findIndex((r) => r.group);
|
|
3227
|
+
return rows2.slice(i + 1, n < 0 ? void 0 : i + 1 + n);
|
|
3228
|
+
};
|
|
3229
|
+
function roles2(cols) {
|
|
3230
|
+
const r = cols.map((c) => c.phone ?? void 0);
|
|
3231
|
+
const claim = (part3, ok, pick2) => {
|
|
3232
|
+
const i = r.includes(part3) ? void 0 : pick2(cols.flatMap((c, i2) => r[i2] === void 0 && ok(c) ? [i2] : []));
|
|
3233
|
+
if (i !== void 0) r[i] = part3;
|
|
3234
|
+
};
|
|
3235
|
+
claim("title", (c) => c.kind === "text", (f) => f[0]);
|
|
3236
|
+
claim("tag", (c) => c.kind === "tone", (f) => f[0]);
|
|
3237
|
+
claim("value", (c) => c.kind === "number" || c.kind === "money", (f) => f.filter((i) => cols[i]?.total).pop() ?? f.pop());
|
|
3238
|
+
return r.map((x) => x ?? "meta");
|
|
3239
|
+
}
|
|
3240
|
+
var cellRole = (b, x) => b.edit && editable(b, x) ? "ed" : b.calc?.[x.id] != null ? "fx" : x.kind === "number" || x.kind === "money" ? "app" : "";
|
|
3241
|
+
|
|
3242
|
+
// react/src/kinds/table.ts
|
|
3243
|
+
var FORMAT = { csv: "CSV", xlsx: "Excel" };
|
|
3244
|
+
var thai = () => document.documentElement.lang.startsWith("th");
|
|
3245
|
+
var shown2 = (c, v) => cellText(c, v, thai());
|
|
3246
|
+
var pk = (p) => `${p.row}
|
|
3247
|
+
${p.col}`;
|
|
3248
|
+
var isIds = (v) => Array.isArray(v) && v.every((x) => typeof x === "string");
|
|
3249
|
+
var isEdit = (v) => typeof v === "object" && v !== null && !Array.isArray(v) && "value" in v;
|
|
3250
|
+
function cell(tag, c, part3, kids3, blank2, attrs = {}) {
|
|
3251
|
+
const cls = `${atEnd(c) ? "end" : "start"} k-${c.kind} p-${part3}${c.width ? " w" : ""}${blank2 ? " nil" : ""}`;
|
|
3252
|
+
return h(tag, cls, { "data-l": c.label, ...attrs, style: c.width ? { "--w": `${c.width}ch` } : void 0 }, ...kids3);
|
|
3253
|
+
}
|
|
3254
|
+
var send3 = (v, action, values2) => void v.c.act({ action, block: v.b.id, values: values2 });
|
|
3255
|
+
var go = (v, f) => ({ onClick: () => (f(), v.draw()) });
|
|
3256
|
+
var sent = (v, row5, col) => {
|
|
3257
|
+
const c = held(v.c, { block: v.b, rules: grid, grab: { row: row5, column: col }, item: pk({ row: row5, col }) });
|
|
3258
|
+
return isEdit(c) ? c.value : void 0;
|
|
3259
|
+
};
|
|
3260
|
+
var waits3 = (v, r) => v.b.columns.some((x) => sent(v, r.id, x.id) !== void 0);
|
|
3261
|
+
var sort = (v) => v.b.columns.find((x) => x.id === v.st.sort?.by);
|
|
3262
|
+
var cellAt = (v, p) => Array.from(v.box.current?.querySelectorAll("tbody td[data-c]") ?? []).find((td) => td.dataset["c"] === p.col && td.parentElement?.dataset["id"] === p.row);
|
|
3263
|
+
var fit3 = (ids3, i, by) => ids3[Math.max(0, Math.min(ids3.length - 1, ids3.indexOf(i) + by))] ?? i;
|
|
3264
|
+
function tick(v, on, label2, set, mixed = false, cls = "", off = false) {
|
|
3265
|
+
const ref3 = (e) => {
|
|
3266
|
+
if (e) e.indeterminate = mixed;
|
|
3267
|
+
};
|
|
3268
|
+
const change = (e) => (set(e.target.checked), v.draw());
|
|
3269
|
+
return h("input", cls, { type: "checkbox", checked: on, disabled: off || void 0, "aria-label": label2, ref: ref3, onClick: (e) => e.stopPropagation(), onChange: change });
|
|
3270
|
+
}
|
|
3271
|
+
var every = (v, d2, cls = "") => tick(v, d2.all, "Select all shown rows", (on) => v.st.sel = new Set(on ? d2.items.map((r) => r.id) : []), d2.sel > 0 && !d2.all, cls);
|
|
3272
|
+
var menu = (v, name, label2) => btn(label2, "", void 0, void 0, { "aria-expanded": String(v.st.menu === name), ...go(v, () => v.st.menu = v.st.menu === name ? "" : name) });
|
|
3273
|
+
function exporter(v, d2, f) {
|
|
3274
|
+
const label2 = v.b.export?.length === 1 ? `export ${(FORMAT[f] ?? f).toLowerCase()}` : FORMAT[f] ?? f;
|
|
3275
|
+
const values2 = () => ({ format: f, columns: d2.cols.map((x) => x.id), sort: v.st.sort, q: v.st.q, rows: [...v.st.sel] });
|
|
3276
|
+
return btn(label2, "", void 0, "export", { onClick: () => send3(v, "export", values2()) });
|
|
3277
|
+
}
|
|
3278
|
+
function sorter(v, d2) {
|
|
3279
|
+
const opts2 = [h("option", "", { value: "" }, "sort: as sent")];
|
|
3280
|
+
for (const x of d2.cols) if (x.sort !== false) for (const dir of ["asc", "desc"]) opts2.push(h("option", "", { value: `${x.id}:${dir}` }, `sort: ${x.label.toLowerCase()} ${dir === "asc" ? "\u2191" : "\u2193"}`));
|
|
3281
|
+
const change = (e) => {
|
|
3282
|
+
const [by, dir] = e.target.value.split(":");
|
|
3283
|
+
v.st.sort = by && (dir === "asc" || dir === "desc") ? { by, dir } : null;
|
|
3284
|
+
v.draw();
|
|
3285
|
+
};
|
|
3286
|
+
return h("select", "tbs", { "aria-label": "Sort", value: v.st.sort ? `${v.st.sort.by}:${v.st.sort.dir}` : "", onChange: change }, ...opts2);
|
|
3287
|
+
}
|
|
3288
|
+
function bar3(v, d2) {
|
|
3289
|
+
const { b, st } = v, n = b.rows.filter((r) => !r.group).length;
|
|
3290
|
+
const q = h("input", "tbq", { key: "q", type: "search", placeholder: "filter", value: st.q, "aria-label": `Filter ${b.title ?? "rows"}`, onChange: (e) => (st.q = e.target.value, v.draw()) });
|
|
3291
|
+
const out2 = [];
|
|
3292
|
+
if (d2.pick) out2.push(every(v, d2, "tbk"));
|
|
3293
|
+
if (d2.sel) {
|
|
3294
|
+
out2.push(h("b", "tbt", null, `${d2.sel} selected`));
|
|
3295
|
+
for (const a of b.select?.actions ?? []) out2.push(btn(a.label, a.bad ? "bad" : "", void 0, a.action, { onClick: () => send3(v, a.action, { rows: [...st.sel] }) }));
|
|
3296
|
+
out2.push(h("span", "tbn", null));
|
|
3297
|
+
} else out2.push(b.title ? h("b", "tbt", null, b.title) : null, h("span", "tbn", null, st.q ? `${d2.items.length} of ${n} rows` : `${n} row${n === 1 ? "" : "s"}`));
|
|
3298
|
+
if (b.reorder && !d2.sel && (st.sort || st.q)) out2.push(h("span", "tbn", null, `${st.sort ? "sorted" : "filtered"}, so rows stay put`), btn("as sent", "", void 0, void 0, go(v, () => (st.sort = null, st.q = ""))));
|
|
3299
|
+
if (n && !d2.sel) {
|
|
3300
|
+
if (b.filter !== false) out2.push(q);
|
|
3301
|
+
out2.push(sorter(v, d2));
|
|
3302
|
+
if (b.columns.length > 2) out2.push(menu(v, "columns", st.hidden.size ? `columns \xB7 ${st.hidden.size} hidden` : "columns"));
|
|
3303
|
+
}
|
|
3304
|
+
const formats = n ? b.export ?? [] : [];
|
|
3305
|
+
if (formats.length === 1 && formats[0]) out2.push(exporter(v, d2, formats[0]));
|
|
3306
|
+
else if (formats.length) out2.push(menu(v, "export", "export"));
|
|
3307
|
+
if (d2.sel) out2.push(btn("clear", "", void 0, void 0, go(v, () => st.sel.clear())));
|
|
3308
|
+
const menus = [];
|
|
3309
|
+
if (st.menu === "columns" && !d2.sel && n) {
|
|
3310
|
+
const ticks = b.columns.map((x, i) => {
|
|
3311
|
+
const k = tick(v, i === 0 || !st.hidden.has(x.id), `Show ${x.label}`, (on) => on ? st.hidden.delete(x.id) : st.hidden.add(x.id), false, "", i === 0);
|
|
3312
|
+
return h("label", "", null, k, x.label);
|
|
3313
|
+
});
|
|
3314
|
+
menus.push(h("div", "tbm", { role: "group", "aria-label": "Columns" }, ...ticks));
|
|
3315
|
+
}
|
|
3316
|
+
const note2 = d2.sel ? `${d2.sel} selected rows` : `${d2.items.length} rows, as sorted and shown`;
|
|
3317
|
+
if (st.menu === "export" && formats.length > 1) menus.push(h("div", "tbm", null, ...formats.map((f) => exporter(v, d2, f)), h("p", "note", null, note2)));
|
|
3318
|
+
return [h("div", "tbh", null, ...out2), ...menus];
|
|
3319
|
+
}
|
|
3320
|
+
function head3(v, d2) {
|
|
3321
|
+
const ths = d2.cols.map((x) => {
|
|
3322
|
+
const on = v.st.sort?.by === x.id ? v.st.sort.dir : null;
|
|
3323
|
+
const u = unit(x);
|
|
3324
|
+
const label2 = [h("span", "", null, x.label), u ? h("span", "tbu", null, u) : null, h("i", "", null, on === "asc" ? "\u2191" : on === "desc" ? "\u2193" : "")];
|
|
3325
|
+
const cycle = () => v.st.sort = on === "desc" ? null : { by: x.id, dir: on === "asc" ? "desc" : "asc" };
|
|
3326
|
+
const kids3 = x.sort === false ? label2 : [h("button", "tsh", { type: "button", ...go(v, cycle) }, ...label2)];
|
|
3327
|
+
return cell("th", x, "meta", kids3, false, { scope: "col", "aria-sort": on === "asc" ? "ascending" : on === "desc" ? "descending" : void 0 });
|
|
3328
|
+
});
|
|
3329
|
+
return h("thead", "", null, h("tr", "", null, d2.handles ? h("th", "tbg", null) : null, d2.pick ? h("th", "tbc", null, every(v, d2)) : null, ...ths));
|
|
3330
|
+
}
|
|
3331
|
+
function slide(v, order2, g) {
|
|
3332
|
+
const trs = Array.from(v.box.current?.querySelectorAll("tbody>tr") ?? []);
|
|
3333
|
+
const [, all] = chunks(order2 ?? [], (i) => v.b.rows.some((r) => r.id === i && r.group));
|
|
3334
|
+
const lifted = order2 ? all.find((c) => c[0] === g) ?? [g] : [];
|
|
3335
|
+
let y = trs[0]?.offsetTop ?? 0;
|
|
3336
|
+
for (const e of trs) {
|
|
3337
|
+
e.style.transform = "";
|
|
3338
|
+
e.classList.toggle("lift", lifted.includes(e.dataset["id"] ?? ""));
|
|
3339
|
+
}
|
|
3340
|
+
for (const e of (order2 ?? []).flatMap((id) => trs.find((t) => t.dataset["id"] === id) ?? [])) {
|
|
3341
|
+
e.style.transform = `translateY(${y - e.offsetTop}px)`;
|
|
3342
|
+
y += e.offsetHeight;
|
|
3343
|
+
}
|
|
3344
|
+
}
|
|
3345
|
+
function grip(v, r) {
|
|
3346
|
+
const g = v.b.reorder;
|
|
3347
|
+
if (!g || !grid.word(v.b, r.id)) return h("td", "tbg", null);
|
|
3348
|
+
const wire3 = (hd) => {
|
|
3349
|
+
const td = hd?.parentElement;
|
|
3350
|
+
if (!hd || !td || v.wired.has(hd)) return;
|
|
3351
|
+
v.wired.add(hd);
|
|
3352
|
+
const reach = (_, dy) => Math.round(dy / (td.offsetHeight || 1));
|
|
3353
|
+
gestured(hd, v.c, { block: v.b, gesture: g, rules: grid, grab: r.id, item: r.id, reach, show: (o) => slide(v, isIds(o) ? o : null, r.id) });
|
|
3354
|
+
};
|
|
3355
|
+
return h("td", "tbg", null, h("button", "b-hd", { type: "button", "aria-label": `Move ${named2(v.b, r)}`, "data-act": g.action, ref: wire3 }, "\u2261"));
|
|
3356
|
+
}
|
|
3357
|
+
function input2(v, r, x, field2) {
|
|
3358
|
+
const { b, st } = v;
|
|
3359
|
+
const p = { row: r.id, col: x.id };
|
|
3360
|
+
const ik = `${field2 ? "f" : "c"}
|
|
3361
|
+
${pk(p)}`;
|
|
3362
|
+
const was = r.cells[x.id];
|
|
3363
|
+
const typed2 = field2 ? null : st.open?.typed ?? null;
|
|
3364
|
+
const gesture = b.edit;
|
|
3365
|
+
const wire3 = (e) => {
|
|
3366
|
+
if (!e || !gesture || v.wired.has(e)) return;
|
|
3367
|
+
v.wired.add(e);
|
|
3368
|
+
if (!field2 && e.offsetParent === null) return st.open = null, v.draw();
|
|
3369
|
+
const show = (now, ch) => {
|
|
3370
|
+
if (now === "previewing" && isEdit(ch)) st.typed = { ...p, value: ch.value };
|
|
3371
|
+
if (now === "refused") st.no = pk(p);
|
|
3372
|
+
if (now !== "previewing" && now !== "dragging") st.typed = null;
|
|
3373
|
+
if (now === "dragging") st.bad.add(ik);
|
|
3374
|
+
else st.bad.delete(ik);
|
|
3375
|
+
if (now !== "pressed") v.draw();
|
|
3376
|
+
};
|
|
3377
|
+
const left = (how) => {
|
|
3378
|
+
st.bad.delete(ik);
|
|
3379
|
+
if (field2) return st.fields.set(x.id, (st.fields.get(x.id) ?? 0) + 1), v.draw();
|
|
3380
|
+
st.open = null;
|
|
3381
|
+
const d2 = shows(v), ids3 = d2.items.map((i) => i.id), cols = d2.cols.map((i) => i.id);
|
|
3382
|
+
const [dr, dc] = { down: [1, 0], right: [0, 1], left: [0, -1] }[how] ?? [0, 0];
|
|
3383
|
+
if (how !== "blur") st.cur = { row: fit3(ids3, p.row, dr), col: fit3(cols, p.col, dc) }, st.focus = true;
|
|
3384
|
+
v.draw();
|
|
3385
|
+
};
|
|
3386
|
+
edited(e, v.c, { block: b, gesture, rules: grid, grab: { row: p.row, column: p.col }, item: pk(p), show, left });
|
|
3387
|
+
if (!field2) st.no = "", e.focus();
|
|
3388
|
+
};
|
|
3389
|
+
const value3 = typed2 ?? (typeof was === "number" ? String(was) : typeof was === "string" ? was : "");
|
|
3390
|
+
const box = h("input", "tbi", { key: `${ik}
|
|
3391
|
+
${st.fields.get(x.id) ?? 0}`, defaultValue: value3, "aria-label": `${x.label}, ${named2(b, r)}`, "aria-invalid": st.bad.has(ik) ? "true" : void 0, ref: wire3 });
|
|
3392
|
+
return [box, st.bad.has(ik) ? h("span", "tbx", null, x.kind === "date" ? "not a date (2026-01-31)" : "not a number") : null];
|
|
3393
|
+
}
|
|
3394
|
+
function group(v, d2, i) {
|
|
3395
|
+
const r = d2.rows[i] ?? { id: "", cells: {} };
|
|
3396
|
+
const items = itemsOf(d2.rows, i);
|
|
3397
|
+
const tds = d2.cols.map((x, j) => {
|
|
3398
|
+
const sub = j > 0 && x.total && x.total !== "count" ? total(x, items) : null;
|
|
3399
|
+
const wait = sub && cellRole(v.b, x) === "app" && items.some((it) => waits3(v, it));
|
|
3400
|
+
return cell("td", x, d2.role[j] ?? "meta", j === 0 ? [shown2(x, r.cells[x.id]), h("span", "tbgn", null, String(items.length))] : sub ? [sub[1]] : [], j > 0 && !sub, { className: wait ? "wait" : void 0 });
|
|
3401
|
+
});
|
|
3402
|
+
return h("tr", "grp", { key: r.id, "data-id": r.id }, d2.handles ? grip(v, r) : null, d2.pick ? h("td", "tbc", null) : null, ...tds);
|
|
3403
|
+
}
|
|
3404
|
+
function item2(v, d2, r) {
|
|
3405
|
+
const { b, st } = v;
|
|
3406
|
+
const max = (x) => x.max ?? Math.max(1, ...b.rows.map((r2) => at(r2, x.id)).filter((n) => typeof n === "number"));
|
|
3407
|
+
const cls = [r.tap && !d2.ed ? "tap" : "", st.changed.has(r.id) ? "chg" : "", st.fresh.has(r.id) ? "b-late" : "", st.sel.has(r.id) ? "sel" : ""].filter(Boolean).join(" ");
|
|
3408
|
+
const tap = r.tap;
|
|
3409
|
+
const wait = waits3(v, r);
|
|
3410
|
+
const tds = d2.cols.map((x, i) => {
|
|
3411
|
+
const c = at(r, x.id), t = shown2(x, c), k = cellRole(b, x), p = { row: r.id, col: x.id };
|
|
3412
|
+
const fill5 = h("i", "", { style: { width: `${Math.min(1, Math.max(0, Number(c) / max(x))) * 100}%` } });
|
|
3413
|
+
const line = (n) => h("svg", `tbsp ${x.tone ?? ""}`, { viewBox: "0 0 100 24", preserveAspectRatio: "none", role: "img", "aria-label": t }, h("polyline", "", { points: sparkPoints(n) }));
|
|
3414
|
+
const kids3 = c === void 0 ? [] : Array.isArray(c) ? x.kind === "spark" && c.length ? [line(c)] : [t] : typeof c === "object" ? [h("span", `tag ${c.tone ?? ""}`, null, t)] : x.kind === "bar" ? [h("span", `tbb ${x.tone ?? ""}`, null, fill5), t] : [t];
|
|
3415
|
+
const typed2 = k === "ed" && !r.fixed;
|
|
3416
|
+
const out2 = sent(v, r.id, x.id) !== void 0;
|
|
3417
|
+
const ing = st.open !== null && pk(st.open) === pk(p);
|
|
3418
|
+
const more = [out2 ? "sent" : "", k === "app" && wait ? "wait" : "", st.no === pk(p) ? "no" : "", ing ? "ing" : "", ing && st.bad.has(`c
|
|
3419
|
+
${pk(p)}`) ? "bad" : ""].filter(Boolean).join(" ");
|
|
3420
|
+
const attrs = {
|
|
3421
|
+
className: more || void 0,
|
|
3422
|
+
title: x.width && c !== void 0 ? t : void 0,
|
|
3423
|
+
"data-c": d2.ed ? x.id : void 0,
|
|
3424
|
+
tabIndex: d2.ed ? d2.tab === pk(p) ? 0 : -1 : void 0,
|
|
3425
|
+
"aria-label": d2.ed ? [x.label, named2(b, r), ...t ? [t] : []].join(", ") : void 0,
|
|
3426
|
+
"data-act": typed2 && b.edit ? b.edit.action : void 0,
|
|
3427
|
+
"aria-readonly": k === "fx" ? "true" : void 0,
|
|
3428
|
+
"aria-description": k === "fx" ? "worked out" : void 0,
|
|
3429
|
+
"aria-busy": out2 ? "true" : void 0
|
|
3430
|
+
};
|
|
3431
|
+
return cell("td", x, d2.role[i] ?? "meta", [...typed2 ? [h("span", "tbf", null, ...kids3)] : kids3, ...ing ? input2(v, r, x, false) : []], c === void 0, attrs);
|
|
3432
|
+
});
|
|
3433
|
+
const edit2 = d2.ed ? h("td", "tbo", null, h("button", "", { type: "button", "aria-label": `Edit ${named2(b, r)}`, ...go(v, () => st.sheet = r.id) }, "\u203A")) : null;
|
|
3434
|
+
const pick2 = d2.pick ? h("td", "tbc", null, tick(v, st.sel.has(r.id), `Select ${r.id}`, (on) => on ? st.sel.add(r.id) : st.sel.delete(r.id))) : null;
|
|
3435
|
+
return h("tr", cls, { key: r.id, "data-id": r.id, onClick: tap && !d2.ed ? () => v.tap(tap) : void 0 }, d2.handles ? grip(v, r) : null, pick2, ...tds, edit2);
|
|
3436
|
+
}
|
|
3437
|
+
function body(v, d2) {
|
|
3438
|
+
const { b, st } = v;
|
|
3439
|
+
const rows2 = d2.rows.map((r, i) => r.group ? group(v, d2, i) : item2(v, d2, r));
|
|
3440
|
+
if (!d2.items.length) {
|
|
3441
|
+
const clear = b.rows.length ? btn("clear", "", void 0, void 0, go(v, () => (st.q = "", v.unseek()))) : null;
|
|
3442
|
+
const p = h("p", "empty", null, b.rows.length ? `No rows match \u201C${st.q}\u201D. ` : b.empty ?? "No rows yet.", clear);
|
|
3443
|
+
rows2.push(h("tr", "", { key: "~" }, h("td", "", { colSpan: d2.cols.length + (d2.pick ? 1 : 0) + (d2.handles ? 1 : 0) }, p)));
|
|
3444
|
+
}
|
|
3445
|
+
return h("tbody", "", d2.ed ? keys2(v) : null, ...rows2);
|
|
3446
|
+
}
|
|
3447
|
+
function foot(v, d2) {
|
|
3448
|
+
if (!d2.items.length || !d2.cols.some((x) => x.total)) return null;
|
|
3449
|
+
const wait = d2.items.some((r) => waits3(v, r));
|
|
3450
|
+
const tds = d2.cols.slice(1).map((x, j) => {
|
|
3451
|
+
const i = j + 1;
|
|
3452
|
+
const t = total(x, d2.items);
|
|
3453
|
+
const part3 = d2.role[i] === "title" ? "meta" : d2.role[i] ?? "meta";
|
|
3454
|
+
return cell("td", x, part3, t ? [...t[0] ? [h("span", "agg", null, t[0]), " "] : [], t[1]] : [], !t, { className: t && wait && cellRole(v.b, x) === "app" ? "wait" : void 0 });
|
|
3455
|
+
});
|
|
3456
|
+
return h("tfoot", "", null, h("tr", "", null, d2.handles ? h("td", "tbg", null) : null, d2.pick ? h("td", "tbc", null) : null, h("th", "p-title", { scope: "row" }, "Total"), ...tds));
|
|
3457
|
+
}
|
|
3458
|
+
function live2(v, r) {
|
|
3459
|
+
if (r.group) return r;
|
|
3460
|
+
const cells = { ...r.cells };
|
|
3461
|
+
for (const x of v.b.columns) {
|
|
3462
|
+
const s = sent(v, r.id, x.id);
|
|
3463
|
+
if (s !== void 0) cells[x.id] = s;
|
|
3464
|
+
}
|
|
3465
|
+
const t = v.st.typed;
|
|
3466
|
+
if (t?.row === r.id) cells[t.col] = t.value;
|
|
3467
|
+
return worked(v.b, { ...r, cells });
|
|
3468
|
+
}
|
|
3469
|
+
function shows(v) {
|
|
3470
|
+
const { b, st } = v;
|
|
3471
|
+
const cols = b.columns.filter((x, i) => i === 0 || !st.hidden.has(x.id));
|
|
3472
|
+
const words3 = st.q.toLowerCase().split(/\s+/).filter(Boolean);
|
|
3473
|
+
const out2 = b.rows.map((r) => held(v.c, { block: b, rules: grid, grab: r.id, item: r.id })).find(isIds);
|
|
3474
|
+
const all = (out2 ? out2.flatMap((id) => b.rows.find((r) => r.id === id) ?? []) : b.rows).map((r) => live2(v, r));
|
|
3475
|
+
const hit = (r) => words3.every((w) => cols.some((x) => shown2(x, at(r, x.id)).toLowerCase().includes(w)));
|
|
3476
|
+
const kept2 = all.filter((r, i) => r.group ? itemsOf(all, i).some(hit) : hit(r));
|
|
3477
|
+
const rows2 = sorted(kept2, sort(v), st.sort?.dir);
|
|
3478
|
+
const items = rows2.filter((r) => !r.group);
|
|
3479
|
+
for (const s of st.sel) if (!items.some((r) => r.id === s)) st.sel.delete(s);
|
|
3480
|
+
const sel = st.sel.size;
|
|
3481
|
+
const handles = !!b.reorder && !st.sort && !st.q;
|
|
3482
|
+
const cur = st.cur && items.some((r) => r.id === st.cur?.row) && cols.some((x) => x.id === st.cur?.col) ? pk(st.cur) : null;
|
|
3483
|
+
const first2 = items[0] && cols[0] ? pk({ row: items[0].id, col: cols[0].id }) : "";
|
|
3484
|
+
return { cols, role: roles2(cols), rows: rows2, items, pick: !!b.select && b.rows.length > 0, sel, all: sel > 0 && sel === items.length, handles, ed: !!b.edit, tab: cur ?? first2 };
|
|
3485
|
+
}
|
|
3486
|
+
function open(v, p, typed2 = null) {
|
|
3487
|
+
const td = cellAt(v, p);
|
|
3488
|
+
const now = v.st.open !== null && pk(v.st.open) === pk(p);
|
|
3489
|
+
if (!v.b.edit || !td || now || td.getAttribute("aria-disabled") === "true" || sent(v, p.row, p.col) !== void 0 || !grid.word(v.b, { row: p.row, column: p.col })) return;
|
|
3490
|
+
v.st.open = { ...p, typed: typed2 };
|
|
3491
|
+
}
|
|
3492
|
+
function keys2(v) {
|
|
3493
|
+
const moves = { ArrowUp: [-1, 0], ArrowDown: [1, 0], ArrowLeft: [0, -1], ArrowRight: [0, 1] };
|
|
3494
|
+
const onKeyDown = (e) => {
|
|
3495
|
+
const td = e.target instanceof HTMLElement && e.target.matches("td[data-c]") ? e.target : null;
|
|
3496
|
+
const row5 = td?.parentElement?.dataset["id"];
|
|
3497
|
+
if (!td || !row5 || !td.dataset["c"]) return;
|
|
3498
|
+
const p = { row: row5, col: td.dataset["c"] };
|
|
3499
|
+
const m = moves[e.key];
|
|
3500
|
+
const d2 = shows(v), ids3 = d2.items.map((i) => i.id), cols = d2.cols.map((i) => i.id);
|
|
3501
|
+
if (m) v.st.cur = { row: fit3(ids3, row5, m[0]), col: fit3(cols, p.col, m[1]) }, v.st.focus = true;
|
|
3502
|
+
else if (e.key === "Enter") open(v, p);
|
|
3503
|
+
else if (e.key.length === 1 && !e.ctrlKey && !e.metaKey && e.key !== " ") open(v, p, e.key);
|
|
3504
|
+
else return;
|
|
3505
|
+
e.preventDefault();
|
|
3506
|
+
v.draw();
|
|
3507
|
+
};
|
|
3508
|
+
const onClick = (e) => {
|
|
3509
|
+
const td = e.target instanceof Element ? e.target.closest("td[data-c]") : null;
|
|
3510
|
+
const row5 = td?.parentElement?.dataset["id"];
|
|
3511
|
+
if (!td || !row5 || !td.dataset["c"] || td.querySelector(".tbi")) return;
|
|
3512
|
+
v.st.cur = { row: row5, col: td.dataset["c"] };
|
|
3513
|
+
open(v, v.st.cur);
|
|
3514
|
+
v.draw();
|
|
3515
|
+
};
|
|
3516
|
+
return { onKeyDown, onClick };
|
|
3517
|
+
}
|
|
3518
|
+
function sheet(v, d2) {
|
|
3519
|
+
const { b, st } = v;
|
|
3520
|
+
const r = d2.items.find((i) => i.id === st.sheet);
|
|
3521
|
+
if (!r) return null;
|
|
3522
|
+
const g = [...d2.rows].reverse().find((x, i, all) => x.group && all.indexOf(r) < i);
|
|
3523
|
+
const mine = g ? itemsOf(d2.rows, d2.rows.indexOf(g)) : [];
|
|
3524
|
+
const where = g ? h("span", "shp", null, `${named2(b, g)} \xB7 ${mine.indexOf(r) + 1} of ${mine.length}`) : null;
|
|
3525
|
+
const tap = r.tap;
|
|
3526
|
+
const top = h("div", "b-sheet__head", null, h("b", "b-sheet__title", null, named2(b, r), where), tap ? btn("open", "", void 0, void 0, { onClick: () => v.tap(tap) }) : null, btn("done", "", void 0, void 0, go(v, () => st.sheet = "")));
|
|
3527
|
+
const fields2 = b.columns.map((x) => {
|
|
3528
|
+
const k = cellRole(b, x), u = unit(x);
|
|
3529
|
+
const typed2 = k === "ed" && !r.fixed;
|
|
3530
|
+
const out2 = sent(v, r.id, x.id) !== void 0;
|
|
3531
|
+
const ing = typed2 && !out2 && grid.word(b, { row: r.id, column: x.id }) !== null;
|
|
3532
|
+
const bad = ing && st.bad.has(`f
|
|
3533
|
+
${pk({ row: r.id, col: x.id })}`);
|
|
3534
|
+
const box = h("span", ["shv", ing ? "ing" : "", bad ? "bad" : ""].filter(Boolean).join(" "), null, ...typed2 ? ing ? input2(v, r, x, true) : [] : [shown2(x, at(r, x.id))]);
|
|
3535
|
+
const cls = [out2 ? "sent" : "", k === "app" && waits3(v, r) ? "wait" : ""].filter(Boolean).join(" ");
|
|
3536
|
+
return h("label", `fd shf ${atEnd(x) ? "end" : "start"}`, { className: cls || void 0 }, h("span", "fk", null, x.label, u ? h("span", "tbu", null, u) : null), box);
|
|
3537
|
+
});
|
|
3538
|
+
return h("div", "tbsh", { key: `sheet${st.gen}` }, h("div", "b-sheet__card", { role: "dialog", "aria-label": `Edit ${named2(b, r)}` }, top, ...fields2));
|
|
3539
|
+
}
|
|
3540
|
+
function state2(b, st) {
|
|
3541
|
+
if (st.b === b) return st;
|
|
3542
|
+
const now = new Map(b.rows.map((r) => [r.id, JSON.stringify(r)]));
|
|
3543
|
+
if (st.seen.size && JSON.stringify([...now]) !== JSON.stringify([...st.seen])) {
|
|
3544
|
+
st.changed = new Set(b.rows.filter((r) => st.seen.get(r.id) !== now.get(r.id)).map((r) => r.id));
|
|
3545
|
+
st.fresh = new Set([...st.changed].filter((r) => !st.seen.has(r)));
|
|
3546
|
+
st.no = "";
|
|
3547
|
+
}
|
|
3548
|
+
return Object.assign(st, { b, seen: now, gen: st.gen + 1, open: null });
|
|
3549
|
+
}
|
|
3550
|
+
var init = (b) => ({
|
|
3551
|
+
b: null,
|
|
3552
|
+
gen: 0,
|
|
3553
|
+
sort: b.sort ?? null,
|
|
3554
|
+
q: "",
|
|
3555
|
+
hidden: new Set(b.columns.filter((x) => x.hide).map((x) => x.id)),
|
|
3556
|
+
sel: /* @__PURE__ */ new Set(),
|
|
3557
|
+
menu: "",
|
|
3558
|
+
seen: /* @__PURE__ */ new Map(),
|
|
3559
|
+
changed: /* @__PURE__ */ new Set(),
|
|
3560
|
+
fresh: /* @__PURE__ */ new Set(),
|
|
3561
|
+
cur: null,
|
|
3562
|
+
focus: false,
|
|
3563
|
+
typed: null,
|
|
3564
|
+
no: "",
|
|
3565
|
+
sheet: "",
|
|
3566
|
+
open: null,
|
|
3567
|
+
bad: /* @__PURE__ */ new Set(),
|
|
3568
|
+
fields: /* @__PURE__ */ new Map()
|
|
3569
|
+
});
|
|
3570
|
+
function table({ b, hooks: hooks4 }) {
|
|
3571
|
+
const cx = useContext23(Cx);
|
|
3572
|
+
const live3 = useRef18(cx);
|
|
3573
|
+
live3.current = cx;
|
|
3574
|
+
const keep = useRef18(/* @__PURE__ */ new Map());
|
|
3575
|
+
const wired = useRef18(/* @__PURE__ */ new WeakSet());
|
|
3576
|
+
const box = useRef18(null);
|
|
3577
|
+
const kept2 = useRef18(null);
|
|
3578
|
+
const [, draw3] = useReducer2((n) => n + 1, 0);
|
|
3579
|
+
const st = state2(b, kept2.current ??= init(b));
|
|
3580
|
+
const sought = cx.seek[b.id ?? ""];
|
|
3581
|
+
if (sought) st.q = sought.q;
|
|
3582
|
+
const v = { b, c: { act: (a) => live3.current.act(a), held: keep.current }, tap: (t2) => live3.current.tap(t2), unseek: () => sought && cx.put(sought.name, ""), st, box, wired: wired.current, draw: draw3 };
|
|
3583
|
+
useLayoutEffect9(() => {
|
|
3584
|
+
if (!st.focus || !st.cur) return;
|
|
3585
|
+
st.focus = false;
|
|
3586
|
+
cellAt(v, st.cur)?.focus();
|
|
3587
|
+
});
|
|
3588
|
+
const d2 = shows(v);
|
|
3589
|
+
const t = h("table", "", d2.ed ? { role: "grid" } : null, h("caption", "", null, b.title ?? "Table"), head3(v, d2), body(v, d2), foot(v, d2));
|
|
3590
|
+
const cls = ["tbl as-surface", d2.sel > 0 ? "bulk" : "", b.edit || b.reorder ? "ed" : ""].filter(Boolean).join(" ");
|
|
3591
|
+
return h("div", cls, { ...hooks4, ref: box }, ...bar3(v, d2), h("div", "tbw", { key: `w${st.gen}` }, t), sheet(v, d2));
|
|
3592
|
+
}
|
|
3593
|
+
|
|
3594
|
+
// react/src/kinds/text.ts
|
|
3595
|
+
import { useContext as useContext24 } from "react";
|
|
3596
|
+
function text3({ b, hooks: hooks4 }) {
|
|
3597
|
+
const cx = useContext24(Cx);
|
|
3598
|
+
return h("div", "txt", { ...hooks4, "data-md": b.markdown ?? "" }, ...md(b.markdown, cx.screen.startsWith("thread-")));
|
|
3599
|
+
}
|
|
3600
|
+
|
|
3601
|
+
// react/src/kinds/timeline.ts
|
|
3602
|
+
import { useContext as useContext25, useLayoutEffect as useLayoutEffect10, useRef as useRef19, useState as useState15 } from "react";
|
|
3603
|
+
|
|
3604
|
+
// src/core/kind/timeline.ts
|
|
3605
|
+
var MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
|
3606
|
+
var MS = 864e5;
|
|
3607
|
+
var STEPS4 = [
|
|
3608
|
+
["body", "One day earlier", { dir: "left" }],
|
|
3609
|
+
["body", "One day later", { dir: "right" }],
|
|
3610
|
+
["body", "One week earlier", { dir: "left", big: true }],
|
|
3611
|
+
["body", "One week later", { dir: "right", big: true }],
|
|
3612
|
+
["start", "Start one day earlier", { dir: "left" }],
|
|
3613
|
+
["start", "Start one day later", { dir: "right" }],
|
|
3614
|
+
["end", "End one day earlier", { dir: "left" }],
|
|
3615
|
+
["end", "End one day later", { dir: "right" }]
|
|
3616
|
+
];
|
|
3617
|
+
function day(s) {
|
|
3618
|
+
const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(s);
|
|
3619
|
+
if (!m) return null;
|
|
3620
|
+
const n = Date.UTC(Number(m[1]), Number(m[2]) - 1, Number(m[3])) / MS;
|
|
3621
|
+
return iso(n) === s ? n : null;
|
|
3622
|
+
}
|
|
3623
|
+
var iso = (n) => new Date(n * MS).toISOString().slice(0, 10);
|
|
3624
|
+
var parts = (n) => {
|
|
3625
|
+
const d2 = new Date(n * MS);
|
|
3626
|
+
return { date: d2.getUTCDate(), month: d2.getUTCMonth(), year: d2.getUTCFullYear(), weekday: d2.getUTCDay() };
|
|
3627
|
+
};
|
|
3628
|
+
var short = (n) => `${parts(n).date} ${MONTHS[parts(n).month] ?? ""}`;
|
|
3629
|
+
function words2(start2, end) {
|
|
3630
|
+
const [a, b] = [day(start2), day(end)];
|
|
3631
|
+
if (a === null || b === null) return `${start2} to ${end}`;
|
|
3632
|
+
const k = b - a + 1;
|
|
3633
|
+
return `${a === b ? short(a) : `${short(a)} to ${short(b)}`}, ${k} ${k === 1 ? "day" : "days"}`;
|
|
3634
|
+
}
|
|
3635
|
+
var covers = (b, a, z) => {
|
|
3636
|
+
const [s, e] = [day(b.start), day(b.end)];
|
|
3637
|
+
return s !== null && e !== null && s <= z && e >= a;
|
|
3638
|
+
};
|
|
3639
|
+
var range = (t) => {
|
|
3640
|
+
const [f, z] = [day(t.from), day(t.to)];
|
|
3641
|
+
return f === null || z === null ? null : { f, z };
|
|
3642
|
+
};
|
|
3643
|
+
var track = (t, id) => t.tracks.find((r) => r.id === id);
|
|
3644
|
+
var bar4 = (t, id) => {
|
|
3645
|
+
for (const r of t.tracks) for (const b of r.bars) if (b.id === id) return [r, b];
|
|
3646
|
+
return null;
|
|
3647
|
+
};
|
|
3648
|
+
function firstFree(t, r) {
|
|
3649
|
+
const at2 = range(t);
|
|
3650
|
+
for (let d2 = at2?.f ?? 0; at2 && d2 <= at2.z; d2++) if (!r.bars.some((b) => covers(b, d2, d2))) return d2;
|
|
3651
|
+
return null;
|
|
3652
|
+
}
|
|
3653
|
+
var span = (a, b, id) => ({ ...id, start: iso(a), end: iso(b) });
|
|
3654
|
+
function fits(t, g, a, b) {
|
|
3655
|
+
const at2 = range(t);
|
|
3656
|
+
if (!at2 || a > b) return null;
|
|
3657
|
+
if ("row" in g) {
|
|
3658
|
+
const r = track(t, g.row);
|
|
3659
|
+
return r && a >= at2.f && b <= at2.z && !r.bars.some((o) => covers(o, a, b)) ? span(a, b, { row: g.row }) : null;
|
|
3660
|
+
}
|
|
3661
|
+
const found = bar4(t, g.bar);
|
|
3662
|
+
const [s, e] = found ? [day(found[1].start), day(found[1].end)] : [null, null];
|
|
3663
|
+
if (!found || s === null || e === null) return null;
|
|
3664
|
+
const past = a !== s && a < at2.f || b !== e && b > at2.z;
|
|
3665
|
+
const onto = found[0].bars.some((o) => o.id !== g.bar && o.fixed === true && covers(o, a, b));
|
|
3666
|
+
return past || onto ? null : span(a, b, { id: g.bar });
|
|
3667
|
+
}
|
|
3668
|
+
function edit(t, g, from, by) {
|
|
3669
|
+
const [a, b] = [day(from.start), day(from.end)];
|
|
3670
|
+
if (a === null || b === null) return null;
|
|
3671
|
+
if ("row" in g) return by >= 0 ? fits(t, g, a, a + by) : fits(t, g, a + by, a);
|
|
3672
|
+
if (g.part === "body") return fits(t, g, a + by, b + by);
|
|
3673
|
+
return g.part === "start" ? fits(t, g, Math.min(a + by, b), b) : fits(t, g, a, Math.max(b + by, a));
|
|
3674
|
+
}
|
|
3675
|
+
var same3 = (x, y) => x.id === y.id && x.row === y.row && x.start === y.start && x.end === y.end;
|
|
3676
|
+
var timeline = {
|
|
3677
|
+
word: (t, g) => {
|
|
3678
|
+
if ("row" in g) {
|
|
3679
|
+
const r = track(t, g.row);
|
|
3680
|
+
return t.draw != null && r && firstFree(t, r) !== null ? "draw" : null;
|
|
3681
|
+
}
|
|
3682
|
+
const x = bar4(t, g.bar)?.[1];
|
|
3683
|
+
if (!x || x.fixed === true || day(x.start) === null || day(x.end) === null) return null;
|
|
3684
|
+
if (g.part === "body") return t.move != null ? "move" : null;
|
|
3685
|
+
return t.stretch != null ? "stretch" : null;
|
|
3686
|
+
},
|
|
3687
|
+
start: (t, g) => {
|
|
3688
|
+
if (!timeline.word(t, g)) return null;
|
|
3689
|
+
if ("bar" in g) {
|
|
3690
|
+
const x = bar4(t, g.bar)?.[1];
|
|
3691
|
+
return x ? { id: x.id, start: x.start, end: x.end } : null;
|
|
3692
|
+
}
|
|
3693
|
+
const r = track(t, g.row);
|
|
3694
|
+
const d2 = r ? firstFree(t, r) : null;
|
|
3695
|
+
return d2 === null ? null : { start: iso(d2), end: iso(d2) };
|
|
3696
|
+
},
|
|
3697
|
+
candidate: (t, g, r) => {
|
|
3698
|
+
const s = timeline.start(t, g);
|
|
3699
|
+
if (!s) return null;
|
|
3700
|
+
return edit(t, g, "row" in g && r.from != null ? { start: r.from, end: r.from } : s, r.days);
|
|
3701
|
+
},
|
|
3702
|
+
nudge: (t, g, from, n) => {
|
|
3703
|
+
if (n.dir === "up" || n.dir === "down") return null;
|
|
3704
|
+
const by = (n.dir === "left" ? -1 : 1) * (n.big ? 7 : 1);
|
|
3705
|
+
const [a, b] = [day(from.start), day(from.end)];
|
|
3706
|
+
let next;
|
|
3707
|
+
if ("row" in g && from.row == null) next = edit(t, g, from, Math.min(Math.abs(by) - 1, 6));
|
|
3708
|
+
else if ("row" in g) next = a === null || b === null ? null : fits(t, g, a, Math.max(b + by, a));
|
|
3709
|
+
else next = edit(t, g, from, by);
|
|
3710
|
+
return next && !same3(next, from) ? next : null;
|
|
3711
|
+
},
|
|
3712
|
+
steps: (t, g) => {
|
|
3713
|
+
const s = timeline.start(t, g);
|
|
3714
|
+
if (!s) return [];
|
|
3715
|
+
if ("row" in g) return [["Add a bar", { dir: "right" }]];
|
|
3716
|
+
return STEPS4.filter(([p, , n]) => p === g.part && timeline.nudge(t, g, s, n) !== null).map(([, name, n]) => [name, n]);
|
|
3717
|
+
},
|
|
3718
|
+
says: (_, __, c) => words2(c.start, c.end)
|
|
3719
|
+
};
|
|
3720
|
+
function lanes(bars) {
|
|
3721
|
+
const ends2 = [];
|
|
3722
|
+
const of2 = /* @__PURE__ */ new Map();
|
|
3723
|
+
for (const x of [...bars].sort((p, q) => (day(p.start) ?? 0) - (day(q.start) ?? 0))) {
|
|
3724
|
+
const s = day(x.start) ?? 0;
|
|
3725
|
+
let i = ends2.findIndex((e) => e < s);
|
|
3726
|
+
if (i < 0) i = ends2.push(0) - 1;
|
|
3727
|
+
ends2[i] = day(x.end) ?? s;
|
|
3728
|
+
of2.set(x.id, i);
|
|
3729
|
+
}
|
|
3730
|
+
return { of: of2, n: Math.max(1, ends2.length) };
|
|
3731
|
+
}
|
|
3732
|
+
var barName = (x) => `${x.label ?? "Bar"}, ${words2(x.start, x.end)}${x.progress != null ? `, ${x.progress} % done` : ""}${x.fixed ? ", fixed" : ""}`;
|
|
3733
|
+
|
|
3734
|
+
// react/src/kinds/timeline.ts
|
|
3735
|
+
var MONTH = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
|
|
3736
|
+
var STEPS5 = [48, 32, 24, 16, 8, 4];
|
|
3737
|
+
var WD = "SMTWTFS";
|
|
3738
|
+
var ref2 = () => ({ current: null });
|
|
3739
|
+
var vars = (v) => ({ style: Object.fromEntries(Object.entries(v).map(([k, n]) => [`--${k}`, n])) });
|
|
3740
|
+
var clip = (a, b, x) => ({ o: Math.max(a, x.f) - x.f, d: Math.min(b, x.t) - Math.max(a, x.f) + 1 });
|
|
3741
|
+
var isSpan = (v) => typeof v === "object" && v !== null && "start" in v && "end" in v;
|
|
3742
|
+
function axis(x, off) {
|
|
3743
|
+
const mo = [];
|
|
3744
|
+
const dy = [];
|
|
3745
|
+
for (let d2 = x.f; d2 <= x.t; ) {
|
|
3746
|
+
const { month, year } = parts(d2);
|
|
3747
|
+
let k = 0;
|
|
3748
|
+
while (d2 + k <= x.t && parts(d2 + k).month === month) k++;
|
|
3749
|
+
const name = x.z === 3 && x.px !== null && k * x.px < 90 ? (MONTH[month] ?? "").slice(0, 3) : MONTH[month] ?? "";
|
|
3750
|
+
mo.push(h("span", "", vars({ k }), h("b", "", null, `${name} ${year}`)));
|
|
3751
|
+
d2 += k;
|
|
3752
|
+
}
|
|
3753
|
+
for (let d2 = x.f; d2 <= x.t; d2++) {
|
|
3754
|
+
const { date, weekday } = parts(d2);
|
|
3755
|
+
const kids3 = x.z === 1 ? [h("b", "", null, String(date)), h("i", "", null, WD[weekday] ?? "")] : x.z === 2 && (weekday === 1 || d2 === x.f) ? [h("b", "", null, String(date))] : [];
|
|
3756
|
+
dy.push(h("span", off.has(d2) ? "off" : "", null, ...kids3));
|
|
3757
|
+
}
|
|
3758
|
+
return h("div", "tmhd", null, h("div", "tmc", null), h("div", "tmx", null, h("div", "tmm", null, ...mo), h("div", "tmd", null, ...dy)));
|
|
3759
|
+
}
|
|
3760
|
+
function shown3(ghost, tag, home, to, px, text4) {
|
|
3761
|
+
ghost.classList.toggle("on", to !== null);
|
|
3762
|
+
ghost.style.transform = to ? `translateX(${(to.o - home.o) * px}px) scaleX(${to.d / home.d})` : "";
|
|
3763
|
+
tag.textContent = text4;
|
|
3764
|
+
tag.classList.toggle("on", text4 !== "");
|
|
3765
|
+
tag.style.transform = to ? `translateX(${(to.o - home.o) * px}px)` : "";
|
|
3766
|
+
}
|
|
3767
|
+
function bar5(b, x, y, gap, ax, wires) {
|
|
3768
|
+
const [s, e] = [day(x.start) ?? 0, day(x.end) ?? 0];
|
|
3769
|
+
const home = clip(s, e, ax);
|
|
3770
|
+
const cls = ["tmb", x.tone, x.fixed ? "fix" : "", s < ax.f ? "cs" : "", e > ax.t ? "ce" : "", home.d <= 1 && gap >= 2 && x.label ? "out" : ""];
|
|
3771
|
+
const [w, ghost, tag, body2] = [ref2(), ref2(), ref2(), ref2()];
|
|
3772
|
+
const movable = ax.live && (b.move != null || b.stretch != null) && !x.fixed;
|
|
3773
|
+
const grips = [];
|
|
3774
|
+
const grip2 = (part3) => {
|
|
3775
|
+
const g = ref2();
|
|
3776
|
+
grips.push(h("span", part3 === "start" ? "tmgs" : "tmge", { ref: g, role: "button", "aria-label": `${part3 === "start" ? "Start" : "End"} of ${x.label ?? "bar"}`, tabIndex: b.stretch ? -1 : void 0 }));
|
|
3777
|
+
return g;
|
|
3778
|
+
};
|
|
3779
|
+
const all = movable ? [
|
|
3780
|
+
[body2, "body", b.move],
|
|
3781
|
+
[ax.z === 1 && s >= ax.f ? grip2("start") : null, "start", b.stretch],
|
|
3782
|
+
[ax.z === 1 && e <= ax.t ? grip2("end") : null, "end", b.stretch]
|
|
3783
|
+
] : [];
|
|
3784
|
+
const own3 = { ref: body2, "aria-label": barName(x), role: movable ? "button" : "listitem", "aria-roledescription": movable ? "bar" : void 0, tabIndex: x.tap || movable && b.move ? -1 : void 0 };
|
|
3785
|
+
wires.push((c) => {
|
|
3786
|
+
const [we, gh, tg, bd] = [w.current, ghost.current, tag.current, body2.current];
|
|
3787
|
+
if (!we || !gh || !tg || !bd) return;
|
|
3788
|
+
const tap = x.tap;
|
|
3789
|
+
if (tap) {
|
|
3790
|
+
bd.addEventListener("click", () => c.tap(tap));
|
|
3791
|
+
bd.addEventListener("keydown", (k) => k.key === "Enter" && !k.defaultPrevented && bd.dataset["phase"] !== "previewing" && c.tap(tap));
|
|
3792
|
+
}
|
|
3793
|
+
for (const [r, part3, gesture] of all) {
|
|
3794
|
+
const g = r?.current;
|
|
3795
|
+
if (!g || !gesture) continue;
|
|
3796
|
+
const grab = { bar: x.id, part: part3 };
|
|
3797
|
+
const item3 = `${x.id}${part3 === "body" ? "" : part3 === "start" ? "<" : ">"}`;
|
|
3798
|
+
const show = (span2) => {
|
|
3799
|
+
const [a, z] = span2 ? [day(span2.start) ?? s, day(span2.end) ?? e] : [s, e];
|
|
3800
|
+
const px = ax.lane() / ax.n;
|
|
3801
|
+
const text4 = span2 ? words2(span2.start, span2.end) : g.dataset["phase"] === "dragging" ? "no drop here" : "";
|
|
3802
|
+
if (part3 !== "body") return shown3(gh, tg, home, span2 ? clip(a, z, ax) : null, px, text4);
|
|
3803
|
+
we.style.transform = span2 ? `translate(${(a - s) * px}px, -3px)` : "";
|
|
3804
|
+
shown3(gh, tg, home, null, px, text4);
|
|
3805
|
+
gh.classList.toggle("on", span2 !== null);
|
|
3806
|
+
tg.style.transform = span2 ? `translateX(${(a - s) * px}px)` : "";
|
|
3807
|
+
};
|
|
3808
|
+
gestured(g, c, { block: b, gesture, rules: timeline, grab, item: item3, reach: (dx) => ({ days: Math.round(dx / (ax.lane() / ax.n)) }), show });
|
|
3809
|
+
const out2 = held(c, { block: b, rules: timeline, grab, item: item3 });
|
|
3810
|
+
if (isSpan(out2)) show(out2);
|
|
3811
|
+
if (ax.z > 1) g.addEventListener("pointerdown", (p) => p.stopImmediatePropagation(), { capture: true });
|
|
3812
|
+
}
|
|
3813
|
+
});
|
|
3814
|
+
const kids3 = [x.progress != null ? h("i", "tmp", vars({ p: x.progress / 100 })) : null, h("span", "tmbx", null, x.label ?? ""), h("div", "tmbb", own3), ...grips];
|
|
3815
|
+
return [h("div", "tmgh", { ref: ghost, ...vars({ ...home, y }) }), h("div", cls.filter(Boolean).join(" "), { ref: w, ...vars({ ...home, y, gap }) }, ...kids3), h("span", "tmtag", { ref: tag, ...vars({ o: home.o, y }) })];
|
|
3816
|
+
}
|
|
3817
|
+
function draw2(b, r, ax, gesture, wires) {
|
|
3818
|
+
const [hit, ghost, tag] = [ref2(), ref2(), ref2()];
|
|
3819
|
+
const home = { o: 0, d: 1 };
|
|
3820
|
+
wires.push((c) => {
|
|
3821
|
+
const [ht, gh, tg, lane2] = [hit.current, ghost.current, tag.current, hit.current?.parentElement];
|
|
3822
|
+
if (!ht || !gh || !tg || !lane2) return;
|
|
3823
|
+
let from = null;
|
|
3824
|
+
ht.addEventListener("pointerdown", (p) => {
|
|
3825
|
+
const at2 = Math.floor((p.clientX - lane2.getBoundingClientRect().left) / (ax.lane() / ax.n));
|
|
3826
|
+
from = firstFree(b, r) === null ? null : iso(ax.f + at2);
|
|
3827
|
+
});
|
|
3828
|
+
const grab = { row: r.id };
|
|
3829
|
+
const show = (span2) => {
|
|
3830
|
+
const to = span2 ? clip(day(span2.start) ?? ax.f, day(span2.end) ?? ax.f, ax) : null;
|
|
3831
|
+
shown3(gh, tg, home, to, ax.lane() / ax.n, span2 ? words2(span2.start, span2.end) : "");
|
|
3832
|
+
};
|
|
3833
|
+
const n = lane2.children.length;
|
|
3834
|
+
gestured(ht, c, { block: b, gesture, rules: timeline, grab, item: `row:${r.id}`, reach: (dx) => ({ days: Math.round(dx / (ax.lane() / ax.n)), from }), show });
|
|
3835
|
+
tg.after(...Array.from(lane2.children).slice(n));
|
|
3836
|
+
const out2 = held(c, { block: b, rules: timeline, grab, item: `row:${r.id}` });
|
|
3837
|
+
if (isSpan(out2)) show(out2);
|
|
3838
|
+
if (ax.z > 1) ht.addEventListener("pointerdown", (p) => p.stopImmediatePropagation(), { capture: true });
|
|
3839
|
+
});
|
|
3840
|
+
return [h("div", "tmbb", { ref: hit, "aria-label": `${r.title}, Add a bar`, role: "button", tabIndex: -1 }), h("div", "tmgh st as-surface", { ref: ghost, ...vars({ ...home, y: 0 }) }), h("span", "tmtag", { ref: tag, ...vars({ o: 0, y: 0 }) })];
|
|
3841
|
+
}
|
|
3842
|
+
function track2(b, r, ax, off, wires) {
|
|
3843
|
+
const L = lanes(r.bars);
|
|
3844
|
+
const marks = [];
|
|
3845
|
+
for (let d2 = ax.f; d2 <= ax.t; d2++) {
|
|
3846
|
+
if (off.has(d2)) marks.push(h("div", "tmo", vars({ o: d2 - ax.f })));
|
|
3847
|
+
else if (ax.z > 1 && parts(d2).weekday === 1) marks.push(h("div", "tmk", vars({ o: d2 - ax.f })));
|
|
3848
|
+
}
|
|
3849
|
+
const drawn2 = b.draw && ax.live ? draw2(b, r, ax, b.draw, wires) : [];
|
|
3850
|
+
const bars = r.bars.flatMap((x) => {
|
|
3851
|
+
const [s, e] = [day(x.start), day(x.end)];
|
|
3852
|
+
if (s === null || e === null || e < ax.f || s > ax.t) return [];
|
|
3853
|
+
const y = L.of.get(x.id) ?? 0;
|
|
3854
|
+
const next = r.bars.filter((q) => L.of.get(q.id) === y && (day(q.start) ?? 0) > e).map((q) => day(q.start) ?? 0);
|
|
3855
|
+
return bar5(b, x, y, Math.min(...next, ax.t + 1) - Math.min(e, ax.t) - 1, ax, wires);
|
|
3856
|
+
});
|
|
3857
|
+
const label2 = h("div", "tml", null, h("b", "", null, r.title), r.subtitle ? h("span", "", null, r.subtitle) : null);
|
|
3858
|
+
return h("div", "tmr", null, label2, h("div", "tmn", { ...vars({ rows: L.n }), role: "list", "aria-label": r.title }, ...marks, ...drawn2, ...bars));
|
|
3859
|
+
}
|
|
3860
|
+
function rove(root) {
|
|
3861
|
+
const stops2 = () => Array.from(root.querySelectorAll("[data-grab]"));
|
|
3862
|
+
const focus = (e) => {
|
|
3863
|
+
if (!(e.target instanceof HTMLElement) || !e.target.dataset["grab"]) return;
|
|
3864
|
+
const at2 = e.target;
|
|
3865
|
+
for (const s of stops2()) s.tabIndex = s === at2 || at2.classList.contains("tmbb") && s.parentElement === at2.parentElement ? 0 : -1;
|
|
3866
|
+
};
|
|
3867
|
+
const key3 = (e) => {
|
|
3868
|
+
const all = stops2();
|
|
3869
|
+
const i = e.target instanceof HTMLElement ? all.indexOf(e.target) : -1;
|
|
3870
|
+
const by = { ArrowLeft: -1, ArrowUp: -1, ArrowRight: 1, ArrowDown: 1 }[e.key];
|
|
3871
|
+
if (e.defaultPrevented || i < 0 || by === void 0) return;
|
|
3872
|
+
all[Math.min(all.length - 1, Math.max(0, i + by))]?.focus();
|
|
3873
|
+
e.preventDefault();
|
|
3874
|
+
};
|
|
3875
|
+
root.addEventListener("focusin", focus);
|
|
3876
|
+
root.addEventListener("keydown", key3);
|
|
3877
|
+
return () => {
|
|
3878
|
+
root.removeEventListener("focusin", focus);
|
|
3879
|
+
root.removeEventListener("keydown", key3);
|
|
3880
|
+
};
|
|
3881
|
+
}
|
|
3882
|
+
function timeline2({ b, hooks: hooks4 }) {
|
|
3883
|
+
const cx = useContext25(Cx);
|
|
3884
|
+
const live3 = useRef19(cx);
|
|
3885
|
+
live3.current = cx;
|
|
3886
|
+
const keep = useRef19(/* @__PURE__ */ new Map());
|
|
3887
|
+
const done = useRef19(/* @__PURE__ */ new WeakSet());
|
|
3888
|
+
const [root, wrap, grid2] = [useRef19(null), useRef19(null), useRef19(null)];
|
|
3889
|
+
const [px, setPx] = useState15(null);
|
|
3890
|
+
const [f, t] = [day(b.from), day(b.to)];
|
|
3891
|
+
const on = b.move != null || b.stretch != null || b.draw != null;
|
|
3892
|
+
const z = px === null || px >= 24 ? 1 : px >= 12 ? 2 : 3;
|
|
3893
|
+
const ax = f === null || t === null || t < f || b.tracks.length === 0 ? null : { f, t, n: t - f + 1, z, px, live: on, lane: () => grid2.current?.querySelector(".tmn")?.offsetWidth ?? 1 };
|
|
3894
|
+
const k = JSON.stringify([b, px]);
|
|
3895
|
+
const wires = [];
|
|
3896
|
+
useLayoutEffect10(() => root.current ? rove(root.current) : void 0, []);
|
|
3897
|
+
useLayoutEffect10(() => {
|
|
3898
|
+
if (done.current.has(wires)) return;
|
|
3899
|
+
done.current.add(wires);
|
|
3900
|
+
const c = { act: (a) => live3.current.act(a), tap: (x) => live3.current.tap(x), held: keep.current };
|
|
3901
|
+
for (const w of wires) w(c);
|
|
3902
|
+
const first2 = root.current?.querySelector("[data-grab]");
|
|
3903
|
+
if (first2) first2.tabIndex = 0;
|
|
3904
|
+
}, [k]);
|
|
3905
|
+
const head4 = h("div", "tmh", null, h("span", "tmt", null, b.title ?? ""), on && z > 1 ? h("span", "tmq", null, "zoom in to drag") : null, ax ? zooms(ax, px, setPx, wrap, grid2) : null);
|
|
3906
|
+
if (!ax) return h("div", `tm z${z}`, { ...hooks4, ref: root }, head4, h("div", "tme", null, b.empty ?? "Nothing scheduled"));
|
|
3907
|
+
const off = new Set((b.off ?? []).flatMap((d2) => day(d2) ?? []));
|
|
3908
|
+
const body2 = h("div", "tmg", { ref: grid2 }, axis(ax, off), ...b.tracks.map((r) => track2(b, r, ax, off, wires)));
|
|
3909
|
+
return h("div", `tm z${z}`, { ...hooks4, ref: root }, head4, h("div", "tmw", { key: k, ref: wrap, style: { "--n": ax.n, ...px === null ? null : { "--day": `${px}px` } } }, body2));
|
|
3910
|
+
}
|
|
3911
|
+
function zooms(ax, px, set, wrap, grid2) {
|
|
3912
|
+
const fit4 = () => Math.min(48, Math.max(24, ((wrap.current?.clientWidth ?? 0) - (grid2.current?.querySelector(".tml")?.offsetWidth ?? 200)) / ax.n));
|
|
3913
|
+
const now = () => px ?? fit4();
|
|
3914
|
+
const zoom3 = (name, label2, to, end) => h("button", "", { type: "button", "aria-label": name, disabled: end || void 0, onClick: () => set(to()) }, label2);
|
|
3915
|
+
return h(
|
|
3916
|
+
"div",
|
|
3917
|
+
"tmz",
|
|
3918
|
+
null,
|
|
3919
|
+
zoom3("zoom out", "\u2212", () => STEPS5.find((s) => s < now()) ?? 4, px === 4),
|
|
3920
|
+
zoom3("fit to width", "fit", () => null, px === null),
|
|
3921
|
+
zoom3("zoom in", "+", () => [...STEPS5].reverse().find((s) => s > now()) ?? 48, px === 48)
|
|
3922
|
+
);
|
|
3923
|
+
}
|
|
3924
|
+
|
|
3925
|
+
// react/src/kinds/tool.ts
|
|
3926
|
+
import { useState as useState16 } from "react";
|
|
3927
|
+
import { glyph } from "./core.js";
|
|
3928
|
+
function tool({ b, hooks: hooks4 }) {
|
|
3929
|
+
const [open2, setOpen] = useState16(false);
|
|
3930
|
+
const attrs = { ...hooks4, ...b.state === "running" ? { "aria-busy": "true" } : null };
|
|
3931
|
+
const parts2 = [h("i", "tog", { key: "g", "aria-hidden": "true" }, glyph(b.state)), h("span", "ton b-tool__name", { key: "n" }, b.name), h("span", "tos b-tool__summary", { key: "s" }, b.summary ?? "")];
|
|
3932
|
+
if (b.body == null) return h("div", "tol", attrs, h("div", "toh", null, ...parts2));
|
|
3933
|
+
const head4 = h("button", "toh", { type: "button", "aria-label": b.name, "aria-expanded": String(open2), onClick: () => setOpen((o) => !o) }, ...parts2, h("span", "toc", { key: "c" }, "\u203A"));
|
|
3934
|
+
return h("div", "tol has", attrs, head4, h("pre", "tob b-tool__body", { hidden: !open2 || void 0 }, b.body));
|
|
3935
|
+
}
|
|
3936
|
+
|
|
3937
|
+
// react/src/kinds/web.ts
|
|
3938
|
+
var sandbox = "allow-scripts allow-forms allow-popups allow-popups-to-escape-sandbox";
|
|
3939
|
+
var parsed = (src) => {
|
|
3940
|
+
try {
|
|
3941
|
+
return new URL(src, document.baseURI);
|
|
3942
|
+
} catch {
|
|
3943
|
+
return null;
|
|
3944
|
+
}
|
|
3945
|
+
};
|
|
3946
|
+
function web({ b, hooks: hooks4 }) {
|
|
3947
|
+
const url2 = parsed(b.src);
|
|
3948
|
+
const style = { height: `${b.height}px` };
|
|
3949
|
+
if (!url2 || !["http:", "https:"].includes(url2.protocol)) return h("div", "web", hooks4, h("div", "wf none", { style }, "This page can't be shown here."));
|
|
3950
|
+
const shown4 = b.src.replace(/^https?:[/]{2}/i, "").replace(/[?#].*$/, "").replace(/\/$/, "");
|
|
3951
|
+
const frame2 = h("iframe", "wf", { style, sandbox, allow: "", referrerPolicy: "no-referrer", loading: "lazy", title: shown4, src: url2.href });
|
|
3952
|
+
return h("div", "web", hooks4, frame2, h("div", "wm", null, h("span", "wu", null, shown4), h("a", "", out(url2.href), "open \u2197")));
|
|
3953
|
+
}
|
|
3954
|
+
|
|
3955
|
+
// react/src/gen/views.ts
|
|
3956
|
+
var views3 = { button, card, chips, choice, composer, config, diagram, diff, editor, form, hero, images, import: import_, list: list2, media: media2, message, modal: modal2, nav, pages, prose, row: row2, run, scene, screen, secret: secret2, section, sheet: modal2, sidebar, stat, steps, table, text: text3, timeline: timeline2, tool, web };
|
|
3957
|
+
|
|
3958
|
+
// react/src/island.ts
|
|
3959
|
+
import { createElement as createElement16, Suspense, useContext as useContext26, useLayoutEffect as useLayoutEffect11, useState as useState17 } from "react";
|
|
3960
|
+
function Mark({ on }) {
|
|
3961
|
+
useLayoutEffect11(() => {
|
|
3962
|
+
on(true);
|
|
3963
|
+
return () => on(false);
|
|
3964
|
+
}, [on]);
|
|
3965
|
+
return null;
|
|
3966
|
+
}
|
|
3967
|
+
function Isle({ b, attrs }) {
|
|
3968
|
+
const cx = useContext26(Cx);
|
|
3969
|
+
const [live3, setLive] = useState17(false);
|
|
3970
|
+
const C = Object.prototype.hasOwnProperty.call(cx.islands, b.name) ? cx.islands[b.name] : void 0;
|
|
3971
|
+
const fallback = row4(b.fallback, cx);
|
|
3972
|
+
const id = b.id ?? "";
|
|
3973
|
+
const emit = (name, values2) => b.events?.includes(name) ? void cx.act({ action: name, block: id, values: values2 ?? {} }) : cx.report({ what: "dropped", block: id, event: name });
|
|
3974
|
+
const style = { overflow: "hidden", aspectRatio: b.size?.aspect ?? void 0, width: b.size?.width ?? void 0, height: b.size?.height ?? void 0 };
|
|
3975
|
+
const inner = C && createElement16(Boundary, { b, report: cx.report, fallback }, createElement16(Suspense, { fallback }, createElement16(Mark, { on: setLive }), createElement16(C, { props: b.props ?? {}, emit })));
|
|
3976
|
+
return h("div", "", { ...attrs, "data-fallback": C && live3 ? void 0 : "", style }, inner || fallback);
|
|
3977
|
+
}
|
|
3978
|
+
|
|
3979
|
+
// react/src/block.ts
|
|
3980
|
+
var isBlk2 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
3981
|
+
var core = (b) => Object.prototype.hasOwnProperty.call(hooks2, String(b["type"]));
|
|
3982
|
+
var isIsland = (b) => b["type"] === "island" && typeof b["name"] === "string" && isBlk2(b["fallback"]);
|
|
3983
|
+
var isFallback = (v) => isBlk2(v) && typeof v["title"] === "string";
|
|
3984
|
+
function hooksOf(b, cx, fallback, cont = false) {
|
|
3985
|
+
const t = String(b["type"]);
|
|
3986
|
+
const id = typeof b["id"] === "string" ? b["id"] : void 0;
|
|
3987
|
+
const v = core(b) ? hooks2[b.type].variant : null;
|
|
3988
|
+
return {
|
|
3989
|
+
className: `b${core(b) ? "" : " b-app"} b-${t}${cont ? " cont" : ""}`,
|
|
3990
|
+
"data-block": t,
|
|
3991
|
+
"data-id": id,
|
|
3992
|
+
"data-variant": v && b[v] != null ? String(b[v]) : void 0,
|
|
3993
|
+
"data-tone": typeof b["tone"] === "string" ? b["tone"] : void 0,
|
|
3994
|
+
"data-fallback": fallback ? "" : void 0,
|
|
3995
|
+
hidden: id !== void 0 && cx.v.hidden.has(id) ? true : void 0,
|
|
3996
|
+
"aria-busy": id !== void 0 && cx.busy.has(id) ? true : void 0,
|
|
3997
|
+
role: role(b, t),
|
|
3998
|
+
"aria-label": named3(b, t)
|
|
3999
|
+
};
|
|
4000
|
+
}
|
|
4001
|
+
function row4(f, cx) {
|
|
4002
|
+
const tap = f.tap;
|
|
4003
|
+
const pressed = tap ? press(() => cx.tap(tap)) : null;
|
|
4004
|
+
const sub = f.subtitle != null ? h("span", "rs b-row__subtitle", null, f.subtitle) : null;
|
|
4005
|
+
return h("div", tap ? "row tap" : "row", pressed, h("span", "rm", null, h("span", "rt b-row__title as-title-label", null, f.title), sub));
|
|
4006
|
+
}
|
|
4007
|
+
var said4 = (a, b) => b["type"] === "message" && a?.["type"] === "message" && a["role"] === b["role"] && a["name"] === b["name"];
|
|
4008
|
+
var kids2 = (bs) => {
|
|
4009
|
+
const all = Array.isArray(bs) ? bs.filter(isBlk2) : [];
|
|
4010
|
+
return all.map((b, i) => createElement17(Block, { key: typeof b["id"] === "string" ? b["id"] : `~${i}`, b, cont: said4(all[i - 1], b) }));
|
|
4011
|
+
};
|
|
4012
|
+
function Fallen({ b }) {
|
|
4013
|
+
const cx = useContext27(Cx);
|
|
4014
|
+
const f = b["fallback"] ?? { title: String(b["type"]) };
|
|
4015
|
+
return h("div", "", hooksOf(b, cx, true), isFallback(f) ? row4(f, cx) : null, ...kids2(b["blocks"]));
|
|
4016
|
+
}
|
|
4017
|
+
var Boundary = class extends Component {
|
|
4018
|
+
constructor() {
|
|
4019
|
+
super(...arguments);
|
|
4020
|
+
this.state = { threw: false };
|
|
4021
|
+
}
|
|
4022
|
+
static getDerivedStateFromError() {
|
|
4023
|
+
return { threw: true };
|
|
4024
|
+
}
|
|
4025
|
+
componentDidCatch(error) {
|
|
4026
|
+
this.props.report({ what: "threw", block: String(this.props.b["id"] ?? this.props.b["type"]), error });
|
|
4027
|
+
}
|
|
4028
|
+
componentDidUpdate(was) {
|
|
4029
|
+
if (was.b !== this.props.b && this.state.threw) this.setState({ threw: false });
|
|
4030
|
+
}
|
|
4031
|
+
render() {
|
|
4032
|
+
return this.state.threw ? this.props.fallback : this.props.children;
|
|
4033
|
+
}
|
|
4034
|
+
};
|
|
4035
|
+
var own2 = (t, b, attrs) => {
|
|
4036
|
+
const V = views3[t];
|
|
4037
|
+
return V ? createElement17(V, { b, hooks: attrs }) : void 0;
|
|
4038
|
+
};
|
|
4039
|
+
function Draw({ b, cont }) {
|
|
4040
|
+
const cx = useContext27(Cx);
|
|
4041
|
+
if (isIsland(b)) return createElement17(Isle, { b, attrs: hooksOf(b, cx, false) });
|
|
4042
|
+
if (core(b)) return own2(b.type, b, hooksOf(b, cx, false, cont)) ?? createElement17(Fallen, { b });
|
|
4043
|
+
const K = cx.kinds[String(b["type"])];
|
|
4044
|
+
const act2 = (a) => cx.act({ ...a, block: typeof b["id"] === "string" ? b["id"] : null });
|
|
4045
|
+
return K ? h("div", "", hooksOf(b, cx, false), createElement17(K, { block: { ...b, type: String(b["type"]) }, act: act2 })) : createElement17(Fallen, { b });
|
|
4046
|
+
}
|
|
4047
|
+
var Block = memo(function Block2({ b, cont = false }) {
|
|
4048
|
+
const cx = useContext27(Cx);
|
|
4049
|
+
return createElement17(Boundary, { b, report: cx.report, fallback: createElement17(Fallen, { b }) }, createElement17(Draw, { b, cont }));
|
|
4050
|
+
});
|
|
4051
|
+
|
|
4052
|
+
// react/src/view.ts
|
|
4053
|
+
var native = Object.keys(hooks3).filter((k) => Object.prototype.hasOwnProperty.call(views3, k));
|
|
4054
|
+
var DARK = "(prefers-color-scheme: dark)";
|
|
4055
|
+
var watch = (on) => {
|
|
4056
|
+
const m = matchMedia(DARK);
|
|
4057
|
+
m.addEventListener("change", on);
|
|
4058
|
+
return () => m.removeEventListener("change", on);
|
|
4059
|
+
};
|
|
4060
|
+
function BlocksView(p) {
|
|
4061
|
+
const last = useRef20(void 0);
|
|
4062
|
+
const screen2 = useMemo3(() => last.current = share(last.current, p.screen), [p.screen]);
|
|
4063
|
+
const { cx, ask } = useCx(p, screen2);
|
|
4064
|
+
const dark = useSyncExternalStore(watch, () => matchMedia(DARK).matches, () => false);
|
|
4065
|
+
const s = p.look?.[p.mode === "dark" || p.mode !== "light" && dark ? "dark" : "light"];
|
|
4066
|
+
const style = s ? { ...s.tokens, colorScheme: s["color-scheme"] } : void 0;
|
|
4067
|
+
return h("div", "b-view", { style }, createElement18(Cx.Provider, { value: cx }, createElement18(Block, { b: screen2 })), ask);
|
|
4068
|
+
}
|
|
4069
|
+
export {
|
|
4070
|
+
Arrange,
|
|
4071
|
+
BlocksView,
|
|
4072
|
+
native
|
|
4073
|
+
};
|