@miadi/stateloom-canvas 0.1.5 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,101 @@
1
+ /**
2
+ * Talking with a companion from the canvas (Spec 84) — the dock.
3
+ *
4
+ * The phone page's conversation, folded into a corner of the board: one button records a
5
+ * take (Record → Stop & send → Sending…, Send again when a send failed), the line under
6
+ * it says what happened, and the conversation reads newest first — the person's takes
7
+ * (with the drawing they were looking at) and the companion's replies, each with ▶ to
8
+ * hear it walk the diagram again, and a thumb. Closed, it is one round button that shows
9
+ * the clock while recording and how many replies are new.
10
+ *
11
+ * Props in, callbacks out: the host holds the recorder, the conversation and the stage
12
+ * (`createTakeRecorder`, `createCompanionThread`, `present` in `@miadi/stateloom-react`).
13
+ */
14
+ import type { CSSProperties } from "react";
15
+ import { type CanvasTheme } from "./theme.js";
16
+ export interface DockTake {
17
+ kind: "take";
18
+ take: string;
19
+ at: string;
20
+ text: string;
21
+ canvas?: {
22
+ doc: string | null;
23
+ kind: string | null;
24
+ focus: string | null;
25
+ step?: {
26
+ title?: string;
27
+ index?: number;
28
+ count?: number;
29
+ } | null;
30
+ };
31
+ }
32
+ /** One step of a reply that walks the diagram: what is said, on which drawing, lighting what. */
33
+ export interface DockStep {
34
+ say: string;
35
+ title?: string;
36
+ doc?: string;
37
+ focus?: string;
38
+ spotlight?: string[];
39
+ }
40
+ export interface DockReply {
41
+ kind: "reply";
42
+ id: string;
43
+ take: string | null;
44
+ text: string;
45
+ at: string;
46
+ audio: string | null;
47
+ unvoiced?: string;
48
+ feedback?: "up" | "down";
49
+ steps?: DockStep[];
50
+ }
51
+ export type DockItem = DockTake | DockReply;
52
+ export interface CompanionDockProps {
53
+ open: boolean;
54
+ onOpenChange: (open: boolean) => void;
55
+ /** Who answers. Default "Mia". */
56
+ who?: string;
57
+ episode: string | null;
58
+ episodes?: readonly {
59
+ path: string;
60
+ number: number;
61
+ }[];
62
+ onEpisode?: (path: string) => void;
63
+ presence: {
64
+ state: string;
65
+ takes?: string[];
66
+ } | null;
67
+ recorder: {
68
+ state: "idle" | "starting" | "recording" | "sending" | "retry";
69
+ seconds: number;
70
+ held: number;
71
+ message: string;
72
+ error: boolean;
73
+ unavailable?: string;
74
+ };
75
+ onRecord: () => void;
76
+ items: readonly DockItem[];
77
+ /** Replies that arrived and were not heard yet. */
78
+ unheard?: readonly string[];
79
+ /** The reply being heard now. */
80
+ playing?: string | null;
81
+ /** The step of that reply on the board now, counted from 0. */
82
+ playingStep?: number | null;
83
+ /** Play a reply; `from` starts a reply with steps at that step (from 0). */
84
+ onPlay: (id: string, from?: number) => void;
85
+ onStop?: () => void;
86
+ onFeedback?: (id: string, value: "up" | "down" | "") => void;
87
+ autoplay: boolean;
88
+ onAutoplay: (on: boolean) => void;
89
+ /** A take waiting for its reply, and for how long. */
90
+ waiting?: {
91
+ take: string;
92
+ seconds: number;
93
+ } | null;
94
+ notice?: string | null;
95
+ error?: string | null;
96
+ theme?: Partial<CanvasTheme>;
97
+ className?: string;
98
+ style?: CSSProperties;
99
+ }
100
+ export declare function CompanionDock({ open, onOpenChange, who, episode, episodes, onEpisode, presence, recorder, onRecord, items, unheard, playing, playingStep, onPlay, onStop, onFeedback, autoplay, onAutoplay, waiting, notice, error, theme, className, style, }: CompanionDockProps): import("react").JSX.Element;
101
+ export default CompanionDock;
@@ -0,0 +1,62 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { themeStyle } from "./theme.js";
3
+ import { CloseIcon, MicIcon, PlayIcon, SpeakerIcon, StopIcon, ThumbDownIcon, ThumbUpIcon } from "./icons.js";
4
+ const clock = (s) => `${Math.floor(s / 60)}:${String(s % 60).padStart(2, "0")}`;
5
+ const when = (iso) => {
6
+ const d = new Date(iso);
7
+ return Number.isNaN(d.getTime()) ? "" : d.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" });
8
+ };
9
+ const fileOf = (p) => (p ? p.split("/").pop() ?? p : "");
10
+ /** A drawing named for a person: its file name without the format's extensions. */
11
+ const drawingOf = (p) => fileOf(p).replace(/\.(smdf|erdf|sqdf|sysdf)\.json$/i, "").replace(/\.json$/i, "");
12
+ /** What a step lights, said briefly: the element's own name, or how many. */
13
+ function litOf(step) {
14
+ const names = step.spotlight?.length ? step.spotlight : step.focus ? [step.focus] : [];
15
+ // A message is known by its number on the drawing; everything else by its name.
16
+ const bare = names.map((n) => (n.startsWith("message:") ? `#${n.slice(8)}` : n.slice(n.indexOf(":") + 1)));
17
+ if (!bare.length)
18
+ return "";
19
+ return bare.length <= 2 ? bare.join(", ") : `${bare.slice(0, 2).join(", ")} +${bare.length - 2}`;
20
+ }
21
+ function presenceLine(who, presence, episode) {
22
+ if (!episode)
23
+ return { text: "Choose the episode you are speaking in.", away: true };
24
+ switch (presence?.state) {
25
+ case "listening":
26
+ return { text: `${who} is listening.`, away: false };
27
+ case "answering":
28
+ return { text: `${who} is answering${presence.takes?.length ? ` take ${presence.takes.join(", ")}` : ""}.`, away: false };
29
+ case "answered":
30
+ return { text: `${who} has answered and is getting ready to listen again.`, away: false };
31
+ default:
32
+ return { text: `Nobody is listening yet. A take waits in the episode until ${who} does.`, away: true };
33
+ }
34
+ }
35
+ const RECORD_LABEL = {
36
+ idle: "● Record",
37
+ starting: "Opening the mic…",
38
+ recording: "■ Stop & send",
39
+ sending: "Sending…",
40
+ retry: "Send again",
41
+ };
42
+ export function CompanionDock({ open, onOpenChange, who = "Mia", episode, episodes, onEpisode, presence, recorder, onRecord, items, unheard = [], playing = null, playingStep = null, onPlay, onStop, onFeedback, autoplay, onAutoplay, waiting, notice, error, theme, className, style, }) {
43
+ const live = recorder.state === "recording";
44
+ const busy = recorder.state === "starting" || recorder.state === "sending";
45
+ const fresh = unheard.length;
46
+ if (!open) {
47
+ return (_jsx("div", { className: `slc-talk${className ? ` ${className}` : ""}`, style: { ...themeStyle(theme), ...style }, children: _jsxs("button", { type: "button", className: `slc-talk-fab${live ? " slc-talk-fab--live" : ""}${!live && playing ? " slc-talk-fab--speaking" : ""}`, onClick: () => (live ? onRecord() : onOpenChange(true)), "aria-label": live ? `Stop and send (${clock(recorder.seconds)})` : playing ? `${who} is speaking. Open the conversation` : `Talk with ${who}${fresh ? `, ${fresh} new` : ""}`, title: live ? "Stop and send your take" : playing ? `${who} is walking the diagram` : `Talk with ${who} about what is on the canvas`, children: [live ? _jsx("span", { className: "slc-talk-fab-clock", children: clock(recorder.seconds) }) : playing ? _jsx(SpeakerIcon, { size: 24 }) : _jsx(MicIcon, { size: 24 }), !live && fresh > 0 && _jsx("span", { className: "slc-talk-fab-badge", children: fresh })] }) }));
48
+ }
49
+ const line = presenceLine(who, presence, episode);
50
+ const newest = [...items].reverse();
51
+ return (_jsx("div", { className: `slc-talk slc-talk--open${className ? ` ${className}` : ""}`, style: { ...themeStyle(theme), ...style }, children: _jsxs("section", { className: "slc-talk-panel", "aria-label": `Conversation with ${who}`, onPointerDown: (e) => e.stopPropagation(), children: [_jsxs("header", { className: "slc-talk-head", children: [_jsxs("span", { className: "slc-talk-title", children: [_jsx(MicIcon, {}), " Talk with ", who] }), _jsx("span", { className: `slc-talk-presence${line.away ? " slc-talk-presence--away" : ""}`, title: line.text }), _jsx("span", { className: "slc-stage-spacer" }), _jsx("button", { type: "button", className: "slc-stage-btn slc-stage-btn--quiet", onClick: () => onOpenChange(false), "aria-label": "Close the conversation", children: _jsx(CloseIcon, {}) })] }), episodes?.length && onEpisode ? (_jsxs("select", { className: "slc-stage-input slc-talk-episode", value: episode ?? "", onChange: (e) => onEpisode(e.target.value), disabled: live || busy, "aria-label": "The episode this conversation belongs to", children: [!episode && _jsx("option", { value: "", children: "Choose the episode\u2026" }), episodes.map((ep) => (_jsxs("option", { value: ep.path, children: [ep.number ? `${String(ep.number).padStart(3, "0")} · ` : "", ep.path.replace(/^\d{4}-\d{2}-\d{2}-episode-\d+-/, "")] }, ep.path)))] })) : (_jsx("div", { className: "slc-talk-meta", children: episode ?? "No episode chosen." })), _jsx("div", { className: `slc-talk-meta${line.away ? " slc-talk-meta--away" : ""}`, children: line.text }), _jsxs("button", { type: "button", className: `slc-talk-record${live ? " slc-talk-record--live" : ""}${recorder.state === "retry" ? " slc-talk-record--retry" : ""}`, onClick: onRecord, disabled: busy || !!recorder.unavailable || !episode, title: recorder.unavailable ? `Cannot record: ${recorder.unavailable}` : live ? "Stop and send your take" : "Speak to the episode, about what is on the canvas", children: [RECORD_LABEL[recorder.state], live && _jsx("span", { className: "slc-talk-clock", children: clock(recorder.seconds) })] }), recorder.unavailable && _jsxs("div", { className: "slc-talk-meta slc-talk-meta--error", children: ["Cannot record here: ", recorder.unavailable, "."] }), recorder.message && _jsx("div", { className: `slc-talk-meta${recorder.error ? " slc-talk-meta--error" : ""}`, children: recorder.message }), waiting && _jsxs("div", { className: "slc-talk-meta", children: ["Waiting for ", who, "\u2026 ", clock(waiting.seconds)] }), notice && _jsx("div", { className: "slc-talk-notice", children: notice }), error && _jsx("div", { className: "slc-talk-meta slc-talk-meta--error", children: error }), _jsxs("label", { className: "slc-talk-toggle", children: [_jsx("input", { type: "checkbox", checked: autoplay, onChange: (e) => onAutoplay(e.target.checked) }), "Play ", who, "'s replies on the diagram as they arrive"] }), _jsxs("ol", { className: "slc-talk-thread", children: [newest.length === 0 && _jsx("li", { className: "slc-stage-empty", children: "Nothing said in this episode yet. Look at a drawing, press Record, and speak." }), newest.map((item) => item.kind === "take" ? (_jsxs("li", { className: "slc-talk-entry slc-talk-entry--take", children: [_jsxs("div", { className: "slc-talk-who", children: [_jsx("strong", { children: "You" }), _jsxs("span", { children: ["take ", item.take, " \u00B7 ", when(item.at)] })] }), item.canvas?.doc && (_jsxs("div", { className: "slc-talk-canvas", children: ["on ", drawingOf(item.canvas.doc), item.canvas.focus ? ` · ${item.canvas.focus.slice(item.canvas.focus.indexOf(":") + 1)}` : "", item.canvas.step?.title ? ` · during “${item.canvas.step.title}”` : ""] })), _jsx("div", { className: "slc-talk-text", children: item.text || "(no transcript yet)" })] }, `t${item.take}`)) : (_jsxs("li", { className: `slc-talk-entry slc-talk-entry--reply${unheard.includes(item.id) ? " slc-talk-entry--new" : ""}`, children: [_jsxs("div", { className: "slc-talk-who", children: [_jsx("strong", { children: who }), _jsx("span", { children: when(item.at) }), (!item.unvoiced || (item.steps?.length ?? 0) > 0) &&
52
+ (playing === item.id ? (_jsx("button", { type: "button", className: "slc-stage-btn slc-talk-play slc-talk-play--on", onClick: onStop, "aria-label": "Stop", title: "Stop", children: _jsx(StopIcon, {}) })) : (_jsxs("button", { type: "button", className: "slc-stage-btn slc-talk-play", onClick: () => onPlay(item.id), disabled: live, title: item.unvoiced
53
+ ? `Walk the diagram with ${who}'s words (no voice)`
54
+ : item.steps?.length
55
+ ? `Hear ${who} walk the diagram (${item.steps.length} steps)`
56
+ : `Hear ${who}`, children: [_jsx(PlayIcon, {}), (item.steps?.length ?? 0) > 0 ? _jsxs("span", { children: ["Walk ", item.steps.length, " steps"] }) : null, unheard.includes(item.id) ? _jsx("span", { className: "slc-talk-new", children: "New" }) : null] }))), onFeedback && (_jsx("span", { className: "slc-talk-thumbs", children: ["up", "down"].map((v) => (_jsx("button", { type: "button", className: `slc-talk-thumb${item.feedback === v ? " slc-talk-thumb--on" : ""}`, onClick: () => onFeedback(item.id, item.feedback === v ? "" : v), "aria-label": v === "up" ? "This reply worked" : "This reply missed", children: v === "up" ? _jsx(ThumbUpIcon, { size: 15 }) : _jsx(ThumbDownIcon, { size: 15 }) }, v))) }))] }), (item.steps?.length ?? 0) > 0 ? (_jsx("ol", { className: "slc-talk-steps", "aria-label": `${who}'s walk through the diagram`, children: item.steps.map((step, i) => {
57
+ const here = playing === item.id && playingStep === i;
58
+ return (_jsx("li", { children: _jsxs("button", { type: "button", className: `slc-talk-step${here ? " slc-talk-step--here" : ""}`, onClick: () => onPlay(item.id, i), disabled: live, "aria-current": here ? "step" : undefined, title: `Walk from step ${i + 1}`, children: [_jsx("span", { className: "slc-talk-step-n", children: i + 1 }), _jsxs("span", { className: "slc-talk-step-body", children: [(step.title || step.doc) && (_jsxs("span", { className: "slc-talk-step-head", children: [step.title && _jsx("strong", { children: step.title }), (step.doc || litOf(step)) && (_jsx("span", { className: "slc-talk-step-where", children: [drawingOf(step.doc), litOf(step)].filter(Boolean).join(" · ") }))] })), _jsx("span", { className: "slc-talk-step-say", children: step.say })] })] }) }, i));
59
+ }) })) : (_jsx("div", { className: "slc-talk-text", children: item.text })), item.unvoiced && _jsx("div", { className: "slc-talk-meta", children: item.unvoiced })] }, `r${item.id}`)))] })] }) }));
60
+ }
61
+ export default CompanionDock;
62
+ //# sourceMappingURL=CompanionDock.js.map
@@ -0,0 +1,110 @@
1
+ /**
2
+ * The cards a person writes and reads marks in (Spec 83).
3
+ *
4
+ * - `<MarkComposer>`: what was pointed at, and a box to say something about
5
+ * it — typed, or spoken when the host hands it something that listens.
6
+ * - `<MarkThread>`: one mark and its replies; reply, resolve, reopen, remove.
7
+ * - `<MarksPanel>`: every mark on the drawing, the ones with an agent's word
8
+ * not yet read first (marked "new"), and the button that copies them as a
9
+ * review for an agent.
10
+ * - `<MarkNotice>`: one line near the board's controls when an agent answers
11
+ * ("Mia answered mark 3"); a tap opens that thread. It takes no focus.
12
+ *
13
+ * Props in, callbacks out, as the canvases: the host writes the sidecar and
14
+ * tells the hub. A host that knows who will answer says so in `note`: one quiet
15
+ * line under the card ("Mia is listening in episode 412: she answers here"). The listener is any object shaped like
16
+ * `@miadi/stateloom-react`'s `browserDictation()`, so this package needs no
17
+ * socket and no speech code of its own.
18
+ */
19
+ import { type CSSProperties, type ReactNode } from "react";
20
+ import { type Box, type Mark, type MarkKind } from "@miadi/stateloom-protocol";
21
+ import { type CanvasTheme } from "./theme.js";
22
+ /** Something that turns speech into words (`browserDictation()`). */
23
+ export interface ListenerLike {
24
+ start(onText: (text: string, final: boolean) => void, onEnd?: (error?: string) => void): void;
25
+ stop(): void;
26
+ }
27
+ export interface MarkComposerProps {
28
+ elements: readonly string[];
29
+ region?: Box;
30
+ /** The name marks are signed with. Empty: the composer asks for one. */
31
+ author: string;
32
+ onAuthorChange?: (name: string) => void;
33
+ /** `author` is the name the mark is signed with: the one given, or the one typed here. */
34
+ onSubmit: (mark: {
35
+ text: string;
36
+ kind: MarkKind;
37
+ author: string;
38
+ }) => void;
39
+ onCancel: () => void;
40
+ listener?: ListenerLike | null;
41
+ /** Start listening as soon as it opens (the person pressed Answer by voice). */
42
+ listenAtOnce?: boolean;
43
+ busy?: boolean;
44
+ error?: string | null;
45
+ placeholder?: string;
46
+ /** Who will answer the mark, from the host: one quiet line under the card. */
47
+ note?: ReactNode;
48
+ theme?: Partial<CanvasTheme>;
49
+ className?: string;
50
+ style?: CSSProperties;
51
+ }
52
+ export declare function MarkComposer({ elements, region, author, onAuthorChange, onSubmit, onCancel, listener, listenAtOnce, busy, error, placeholder, note, theme, className, style, }: MarkComposerProps): import("react").JSX.Element;
53
+ export interface MarkThreadProps {
54
+ mark: Mark;
55
+ /** Its number on the board. */
56
+ number?: number;
57
+ onReply?: (text: string) => void;
58
+ onResolve?: () => void;
59
+ onReopen?: () => void;
60
+ onRemove?: () => void;
61
+ onClose: () => void;
62
+ listener?: ListenerLike | null;
63
+ busy?: boolean;
64
+ error?: string | null;
65
+ /**
66
+ * Who will answer, from the host. Shown under the thread only while it waits on an
67
+ * agent: the last word is a person's and the mark is not resolved.
68
+ */
69
+ note?: ReactNode;
70
+ theme?: Partial<CanvasTheme>;
71
+ className?: string;
72
+ style?: CSSProperties;
73
+ }
74
+ export declare function MarkThread({ mark, number, onReply, onResolve, onReopen, onRemove, onClose, listener, busy, error, note, theme, className, style, }: MarkThreadProps): import("react").JSX.Element;
75
+ export interface MarksPanelProps {
76
+ marks: readonly Mark[];
77
+ selected?: string | null;
78
+ onSelect: (id: string) => void;
79
+ /** Copy the waiting marks as a review an agent reads. */
80
+ onCopy?: () => void;
81
+ copied?: boolean;
82
+ onClose?: () => void;
83
+ /** Who will answer the marks, from the host: one quiet line under the list. */
84
+ note?: ReactNode;
85
+ /**
86
+ * Marks with an agent's word not yet opened (their ids): listed first and
87
+ * marked "new". `unreadMarks(marks, read)` from the protocol.
88
+ */
89
+ unread?: readonly string[];
90
+ theme?: Partial<CanvasTheme>;
91
+ className?: string;
92
+ style?: CSSProperties;
93
+ }
94
+ export declare function MarksPanel({ marks, selected, onSelect, onCopy, copied, onClose, note, unread, theme, className, style }: MarksPanelProps): import("react").JSX.Element;
95
+ export interface MarkNoticeProps {
96
+ /** The line: `agentWordText(agentWordIn(envelope))`, e.g. "Mia answered mark 3". */
97
+ children: ReactNode;
98
+ /** Open the thread it speaks of. */
99
+ onOpen: () => void;
100
+ onDismiss?: () => void;
101
+ theme?: Partial<CanvasTheme>;
102
+ className?: string;
103
+ style?: CSSProperties;
104
+ }
105
+ /**
106
+ * One line that says an agent answered, near the board's controls. A polite
107
+ * live region: read out, never focused, never a card over the board. The host
108
+ * decides how long it stays (a few seconds) and what a tap opens.
109
+ */
110
+ export declare function MarkNotice({ children, onOpen, onDismiss, theme, className, style }: MarkNoticeProps): import("react").JSX.Element;
@@ -0,0 +1,137 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /**
3
+ * The cards a person writes and reads marks in (Spec 83).
4
+ *
5
+ * - `<MarkComposer>`: what was pointed at, and a box to say something about
6
+ * it — typed, or spoken when the host hands it something that listens.
7
+ * - `<MarkThread>`: one mark and its replies; reply, resolve, reopen, remove.
8
+ * - `<MarksPanel>`: every mark on the drawing, the ones with an agent's word
9
+ * not yet read first (marked "new"), and the button that copies them as a
10
+ * review for an agent.
11
+ * - `<MarkNotice>`: one line near the board's controls when an agent answers
12
+ * ("Mia answered mark 3"); a tap opens that thread. It takes no focus.
13
+ *
14
+ * Props in, callbacks out, as the canvases: the host writes the sidecar and
15
+ * tells the hub. A host that knows who will answer says so in `note`: one quiet
16
+ * line under the card ("Mia is listening in episode 412: she answers here"). The listener is any object shaped like
17
+ * `@miadi/stateloom-react`'s `browserDictation()`, so this package needs no
18
+ * socket and no speech code of its own.
19
+ */
20
+ import { useEffect, useRef, useState } from "react";
21
+ import { MARK_KINDS, lastWordOf, markAnchorText } from "@miadi/stateloom-protocol";
22
+ import { themeStyle } from "./theme.js";
23
+ import { CloseIcon, MicIcon } from "./icons.js";
24
+ const KIND_LABEL = {
25
+ comment: "Comment",
26
+ question: "Question",
27
+ looks_good: "Looks good",
28
+ delete: "Should go",
29
+ };
30
+ function useListening(listener, onText) {
31
+ const [listening, setListening] = useState(false);
32
+ const base = useRef("");
33
+ useEffect(() => () => listener?.stop(), [listener]);
34
+ const toggle = (current) => {
35
+ if (!listener)
36
+ return;
37
+ if (listening) {
38
+ listener.stop();
39
+ setListening(false);
40
+ return;
41
+ }
42
+ base.current = current ? `${current.trimEnd()} ` : "";
43
+ setListening(true);
44
+ listener.start((heard) => onText(base.current + heard), () => setListening(false));
45
+ };
46
+ return { listening, toggle };
47
+ }
48
+ function Anchor({ elements, region }) {
49
+ if (!elements?.length && !region)
50
+ return _jsx("span", { className: "slc-stage-chip slc-stage-chip--quiet", children: "the drawing" });
51
+ return (_jsxs(_Fragment, { children: [elements?.map((e) => (_jsx("span", { className: "slc-stage-chip", children: e }, e))), region && !elements?.length && _jsx("span", { className: "slc-stage-chip slc-stage-chip--quiet", children: "an area" })] }));
52
+ }
53
+ /** Who will answer, as the host knows it: one muted line, nothing when the host has nothing to say. */
54
+ function Note({ children }) {
55
+ if (children === undefined || children === null || children === false || children === "")
56
+ return null;
57
+ return (_jsx("div", { className: "slc-stage-card-note", role: "status", children: children }));
58
+ }
59
+ /** A mouse or trackpad: the composer may take focus without raising a keyboard. */
60
+ function finePointer() {
61
+ try {
62
+ return typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(pointer: fine)").matches;
63
+ }
64
+ catch {
65
+ return false;
66
+ }
67
+ }
68
+ export function MarkComposer({ elements, region, author, onAuthorChange, onSubmit, onCancel, listener, listenAtOnce = false, busy = false, error, placeholder = "What should the agent know about this?", note, theme, className, style, }) {
69
+ const [text, setText] = useState("");
70
+ const [kind, setKind] = useState("comment");
71
+ const [name, setName] = useState(author);
72
+ const { listening, toggle } = useListening(listener, setText);
73
+ const area = useRef(null);
74
+ useEffect(() => {
75
+ if (listenAtOnce && listener)
76
+ toggle("");
77
+ // On a phone, focusing raises the keyboard over the board before the person
78
+ // asked to type: the box takes focus by itself only under a fine pointer,
79
+ // or when they pressed Answer (by voice, where nothing listens).
80
+ else if (listenAtOnce || finePointer())
81
+ area.current?.focus();
82
+ // Once, when the composer opens.
83
+ // eslint-disable-next-line react-hooks/exhaustive-deps
84
+ }, []);
85
+ const submit = (e) => {
86
+ e?.preventDefault();
87
+ if (!text.trim() || busy)
88
+ return;
89
+ if (listening)
90
+ listener?.stop();
91
+ const signed = author || name.trim();
92
+ if (!author && signed)
93
+ onAuthorChange?.(signed);
94
+ onSubmit({ text: text.trim(), kind, author: signed });
95
+ };
96
+ return (_jsxs("form", { className: `slc-stage-card slc-stage-composer${className ? ` ${className}` : ""}`, style: { ...themeStyle(theme), ...style }, onSubmit: submit, onPointerDown: (e) => e.stopPropagation(), children: [_jsxs("div", { className: "slc-stage-card-anchor", children: [_jsx("span", { className: "slc-stage-card-label", children: "On" }), _jsx(Anchor, { elements: elements, region: region })] }), _jsx("textarea", { ref: area, className: "slc-stage-input slc-stage-textarea", value: text, placeholder: listening ? "Listening…" : placeholder, onChange: (e) => setText(e.target.value), onKeyDown: (e) => {
97
+ if (e.key === "Enter" && (e.metaKey || e.ctrlKey))
98
+ submit();
99
+ if (e.key === "Escape")
100
+ onCancel();
101
+ }, rows: 3 }), !author && (_jsx("input", { className: "slc-stage-input", value: name, placeholder: "Your name (signs your marks)", onChange: (e) => setName(e.target.value) })), _jsxs("div", { className: "slc-stage-card-row", children: [_jsx("select", { className: "slc-stage-input slc-stage-select", value: kind, onChange: (e) => setKind(e.target.value), "aria-label": "Kind of mark", children: MARK_KINDS.map((k) => (_jsx("option", { value: k, children: KIND_LABEL[k] }, k))) }), listener && (_jsx("button", { type: "button", className: `slc-stage-btn${listening ? " slc-stage-btn--live" : ""}`, onClick: () => toggle(text), "aria-pressed": listening, title: listening ? "Stop listening" : "Speak instead of typing", children: _jsx(MicIcon, {}) })), _jsx("span", { className: "slc-stage-spacer" }), _jsx("button", { type: "button", className: "slc-stage-btn slc-stage-btn--quiet", onClick: onCancel, children: "Cancel" }), _jsx("button", { type: "submit", className: "slc-stage-btn slc-stage-btn--main", disabled: !text.trim() || busy || (!author && !name.trim()), children: busy ? "Saving…" : "Mark" })] }), _jsx(Note, { children: note }), error && _jsx("div", { className: "slc-stage-card-error", children: error })] }));
102
+ }
103
+ export function MarkThread({ mark, number, onReply, onResolve, onReopen, onRemove, onClose, listener, busy = false, error, note, theme, className, style, }) {
104
+ const [reply, setReply] = useState("");
105
+ const { listening, toggle } = useListening(listener, setReply);
106
+ const send = (e) => {
107
+ e?.preventDefault();
108
+ if (!reply.trim() || busy)
109
+ return;
110
+ if (listening)
111
+ listener?.stop();
112
+ onReply?.(reply.trim());
113
+ setReply("");
114
+ };
115
+ return (_jsxs("div", { className: `slc-stage-card slc-stage-thread${className ? ` ${className}` : ""}`, style: { ...themeStyle(theme), ...style }, onPointerDown: (e) => e.stopPropagation(), children: [_jsxs("div", { className: "slc-stage-card-row", children: [number !== undefined && _jsx("span", { className: `slc-stage-pin slc-stage-pin--inline slc-stage-pin--${mark.status === "resolved" ? "resolved" : mark.status}`, children: number }), _jsxs("span", { className: "slc-stage-card-label", children: [KIND_LABEL[mark.kind], " \u00B7 ", mark.status] }), _jsx("span", { className: "slc-stage-spacer" }), _jsx("button", { type: "button", className: "slc-stage-btn slc-stage-btn--quiet", onClick: onClose, "aria-label": "Close", children: _jsx(CloseIcon, {}) })] }), _jsx("div", { className: "slc-stage-card-anchor", children: _jsx(Anchor, { elements: mark.elements, region: mark.region }) }), _jsxs("ol", { className: "slc-stage-thread-list", children: [_jsxs("li", { className: `slc-stage-said slc-stage-said--${mark.author.role}`, children: [_jsx("span", { className: "slc-stage-said-who", children: mark.author.name }), _jsx("span", { className: "slc-stage-said-text", children: mark.text })] }), (mark.replies ?? []).map((r, i) => (_jsxs("li", { className: `slc-stage-said slc-stage-said--${r.author.role}`, children: [_jsx("span", { className: "slc-stage-said-who", children: r.author.name }), _jsx("span", { className: "slc-stage-said-text", children: r.text })] }, i)))] }), mark.status !== "resolved" && lastWordOf(mark) === "person" && _jsx(Note, { children: note }), onReply && (_jsxs("form", { className: "slc-stage-card-row", onSubmit: send, children: [_jsx("input", { className: "slc-stage-input slc-stage-grow", value: reply, placeholder: listening ? "Listening…" : "Reply…", onChange: (e) => setReply(e.target.value) }), listener && (_jsx("button", { type: "button", className: `slc-stage-btn${listening ? " slc-stage-btn--live" : ""}`, onClick: () => toggle(reply), "aria-pressed": listening, title: "Speak the reply", children: _jsx(MicIcon, {}) })), _jsx("button", { type: "submit", className: "slc-stage-btn slc-stage-btn--main", disabled: !reply.trim() || busy, children: "Reply" })] })), _jsxs("div", { className: "slc-stage-card-row", children: [mark.status === "resolved"
116
+ ? onReopen && (_jsx("button", { type: "button", className: "slc-stage-btn", onClick: onReopen, children: "Reopen" }))
117
+ : onResolve && (_jsx("button", { type: "button", className: "slc-stage-btn", onClick: onResolve, children: "Resolve" })), _jsx("span", { className: "slc-stage-spacer" }), onRemove && (_jsx("button", { type: "button", className: "slc-stage-btn slc-stage-btn--danger", onClick: onRemove, children: "Remove" }))] }), error && _jsx("div", { className: "slc-stage-card-error", children: error })] }));
118
+ }
119
+ export function MarksPanel({ marks, selected, onSelect, onCopy, copied, onClose, note, unread, theme, className, style }) {
120
+ const [all, setAll] = useState(false);
121
+ const unreadIds = new Set(unread ?? []);
122
+ // Numbered as on the board; the ones with an agent's word not yet read first.
123
+ const numbered = marks.map((m, i) => ({ m, n: i + 1 }));
124
+ const ordered = [...numbered.filter(({ m }) => unreadIds.has(m.id)), ...numbered.filter(({ m }) => !unreadIds.has(m.id))];
125
+ const shown = all ? ordered : ordered.filter(({ m }) => m.status !== "resolved");
126
+ const open = marks.filter((m) => m.status !== "resolved").length;
127
+ return (_jsxs("div", { className: `slc-stage-card slc-stage-panel${className ? ` ${className}` : ""}`, style: { ...themeStyle(theme), ...style }, onPointerDown: (e) => e.stopPropagation(), children: [_jsxs("div", { className: "slc-stage-card-row", children: [_jsx("span", { className: "slc-stage-card-label", children: "Marks on this drawing" }), _jsx("span", { className: "slc-stage-spacer" }), _jsxs("span", { className: "slc-stage-segment", role: "group", "aria-label": "Which marks to list", children: [_jsxs("button", { type: "button", className: `slc-stage-segment-btn${all ? "" : " slc-stage-segment-btn--on"}`, "aria-pressed": !all, onClick: () => setAll(false), children: ["Open ", open] }), _jsxs("button", { type: "button", className: `slc-stage-segment-btn${all ? " slc-stage-segment-btn--on" : ""}`, "aria-pressed": all, onClick: () => setAll(true), children: ["All ", marks.length] })] }), onClose && (_jsx("button", { type: "button", className: "slc-stage-btn slc-stage-btn--quiet", onClick: onClose, "aria-label": "Close", children: _jsx(CloseIcon, {}) }))] }), shown.length === 0 && _jsx("div", { className: "slc-stage-empty", children: marks.length ? "Every mark is resolved." : "No marks yet. Turn on marking (✎) and tap or draw around what you mean." }), _jsx("ul", { className: "slc-stage-panel-list", children: shown.map(({ m, n }) => (_jsx("li", { children: _jsxs("button", { type: "button", className: `slc-stage-panel-item${m.id === selected ? " slc-stage-panel-item--selected" : ""}`, onClick: () => onSelect(m.id), children: [_jsx("span", { className: `slc-stage-pin slc-stage-pin--inline slc-stage-pin--${m.status === "resolved" ? "resolved" : m.author.role === "agent" && m.status === "open" ? "question" : m.status}${unreadIds.has(m.id) ? " slc-stage-pin--new" : ""}`, children: n }), _jsxs("span", { className: "slc-stage-panel-text", children: [_jsx("span", { className: "slc-stage-panel-said", children: m.text }), _jsxs("span", { className: "slc-stage-panel-meta", children: [unreadIds.has(m.id) && _jsx("span", { className: "slc-stage-new", children: "new" }), m.author.name, " \u00B7 ", markAnchorText(m), m.replies?.length ? ` · ${m.replies.length} repl${m.replies.length === 1 ? "y" : "ies"}` : ""] })] })] }) }, m.id))) }), _jsx(Note, { children: note }), onCopy && (_jsxs("div", { className: "slc-stage-card-row", children: [_jsx("span", { className: "slc-stage-spacer" }), _jsx("button", { type: "button", className: "slc-stage-btn", onClick: onCopy, title: "Copy what is on screen and the waiting marks, to paste into any agent", children: copied ? "Copied" : "Copy for the agent" })] }))] }));
128
+ }
129
+ /**
130
+ * One line that says an agent answered, near the board's controls. A polite
131
+ * live region: read out, never focused, never a card over the board. The host
132
+ * decides how long it stays (a few seconds) and what a tap opens.
133
+ */
134
+ export function MarkNotice({ children, onOpen, onDismiss, theme, className, style }) {
135
+ return (_jsxs("div", { className: `slc-stage-notice${className ? ` ${className}` : ""}`, style: { ...themeStyle(theme), ...style }, role: "status", "aria-live": "polite", onPointerDown: (e) => e.stopPropagation(), children: [_jsxs("button", { type: "button", className: "slc-stage-notice-open", onClick: onOpen, title: "Open the thread", children: [_jsx("span", { className: "slc-stage-notice-dot", "aria-hidden": "true" }), _jsx("span", { className: "slc-stage-notice-text", children: children })] }), onDismiss && (_jsx("button", { type: "button", className: "slc-stage-notice-close", onClick: onDismiss, "aria-label": "Dismiss", children: _jsx(CloseIcon, {}) }))] }));
136
+ }
137
+ //# sourceMappingURL=MarkCards.js.map
@@ -0,0 +1,39 @@
1
+ /**
2
+ * The words of the step on stage, and the buttons that move a tour (Spec 83).
3
+ *
4
+ * A card over the bottom of the board: who is presenting, the tour and the
5
+ * step's title, what the agent says, where the tour stands. The controls are
6
+ * the person's: back, play or pause, forward, the voice on or off, answer
7
+ * (the host opens a mark on what is lit), close. Nothing here plays anything;
8
+ * the buttons call the host, which holds the stage session.
9
+ */
10
+ import type { CSSProperties } from "react";
11
+ import type { TourStep } from "@miadi/stateloom-protocol";
12
+ import { type CanvasTheme } from "./theme.js";
13
+ export interface StageCaptionProps {
14
+ shown: {
15
+ step: TourStep;
16
+ index: number | null;
17
+ count: number | null;
18
+ title?: string;
19
+ origin?: string;
20
+ } | null;
21
+ playing?: boolean;
22
+ speaking?: boolean;
23
+ /** The canvas's voice is on. Absent: no voice button. */
24
+ voice?: boolean;
25
+ onToggleVoice?: () => void;
26
+ onPlay?: () => void;
27
+ onPause?: () => void;
28
+ onNext?: () => void;
29
+ onPrev?: () => void;
30
+ onGoto?: (index: number) => void;
31
+ onClose?: () => void;
32
+ /** Answer what is lit: the host opens a mark on it. Absent: no answer button. */
33
+ onAnswer?: () => void;
34
+ theme?: Partial<CanvasTheme>;
35
+ className?: string;
36
+ style?: CSSProperties;
37
+ }
38
+ export declare function StageCaption({ shown, playing, speaking, voice, onToggleVoice, onPlay, onPause, onNext, onPrev, onGoto, onClose, onAnswer, theme, className, style, }: StageCaptionProps): import("react").JSX.Element | null;
39
+ export default StageCaption;
@@ -0,0 +1,15 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { themeStyle } from "./theme.js";
3
+ import { CloseIcon, NextIcon, PauseIcon, PlayIcon, PrevIcon, SpeakerIcon, SpeakerOffIcon } from "./icons.js";
4
+ /** Past this many steps the dots give way to the count alone. */
5
+ const MAX_DOTS = 24;
6
+ export function StageCaption({ shown, playing = false, speaking = false, voice, onToggleVoice, onPlay, onPause, onNext, onPrev, onGoto, onClose, onAnswer, theme, className, style, }) {
7
+ if (!shown)
8
+ return null;
9
+ const { step, index, count, title, origin } = shown;
10
+ const inTour = index !== null && count !== null;
11
+ const heading = [title, step.title].filter(Boolean).join(" · ");
12
+ return (_jsxs("section", { className: `slc-stage-caption${className ? ` ${className}` : ""}`, style: { ...themeStyle(theme), ...style }, role: "region", "aria-label": "What the agent is showing", "aria-live": "polite", children: [_jsxs("header", { className: "slc-stage-caption-head", children: [origin && _jsx("span", { className: "slc-stage-caption-origin", children: origin }), heading && _jsx("span", { className: "slc-stage-caption-title", children: heading }), inTour && (_jsxs("span", { className: "slc-stage-caption-count", children: [index + 1, " / ", count] })), speaking && _jsx("span", { className: "slc-stage-caption-speaking", "aria-label": "speaking" }), onClose && (_jsx("button", { type: "button", className: "slc-stage-btn slc-stage-btn--quiet", onClick: onClose, "aria-label": "Close", title: "Close", children: _jsx(CloseIcon, {}) }))] }), _jsx("p", { className: "slc-stage-caption-say", children: step.say }), inTour && count <= MAX_DOTS && count > 1 && (_jsx("nav", { className: "slc-stage-dots", "aria-label": "Steps", children: Array.from({ length: count }, (_, i) => (_jsx("button", { type: "button", className: `slc-stage-dot${i === index ? " slc-stage-dot--current" : i < index ? " slc-stage-dot--seen" : ""}`, onClick: () => onGoto?.(i), "aria-label": `Step ${i + 1}`, "aria-current": i === index ? "step" : undefined }, i))) })), _jsxs("footer", { className: "slc-stage-caption-controls", children: [inTour && (_jsxs(_Fragment, { children: [_jsx("button", { type: "button", className: "slc-stage-btn", onClick: onPrev, disabled: index === 0, "aria-label": "Previous step", title: "Previous step", children: _jsx(PrevIcon, {}) }), playing ? (_jsx("button", { type: "button", className: "slc-stage-btn slc-stage-btn--main", onClick: onPause, "aria-label": "Pause", title: "Pause", children: _jsx(PauseIcon, {}) })) : (_jsx("button", { type: "button", className: "slc-stage-btn slc-stage-btn--main", onClick: onPlay, "aria-label": "Play", title: "Play", children: _jsx(PlayIcon, {}) })), _jsx("button", { type: "button", className: "slc-stage-btn", onClick: onNext, disabled: index === count - 1, "aria-label": "Next step", title: "Next step", children: _jsx(NextIcon, {}) })] })), _jsx("span", { className: "slc-stage-spacer" }), voice !== undefined && (_jsx("button", { type: "button", className: `slc-stage-btn${voice ? " slc-stage-btn--on" : ""}`, onClick: onToggleVoice, "aria-pressed": voice, title: voice ? "Voice on — the steps are read aloud" : "Voice off — the steps are read on screen", children: voice ? _jsx(SpeakerIcon, {}) : _jsx(SpeakerOffIcon, {}) })), onAnswer && (_jsx("button", { type: "button", className: "slc-stage-btn slc-stage-btn--answer", onClick: onAnswer, title: "Answer \u2014 mark what is lit and say something about it", children: "Answer" }))] })] }));
13
+ }
14
+ export default StageCaption;
15
+ //# sourceMappingURL=StageCaption.js.map
@@ -0,0 +1,65 @@
1
+ /**
2
+ * The stage's layer over a canvas (Spec 83) — any of the three boards, or any
3
+ * host's board that shares a viewport.
4
+ *
5
+ * It never reaches into the canvas under it. It is told the viewport and where
6
+ * the elements are (`machineElementBoxes`, `erdElementBoxes`,
7
+ * `sequenceElementBoxes` from the protocol), and from those alone it:
8
+ *
9
+ * - **lights** what an agent points at: the rest of the drawing dims behind a
10
+ * scrim with a hole around each spotlighted element, and each hole is ringed;
11
+ * - **frames** an area the agent names;
12
+ * - **pins** each mark at what it points at, numbered, coloured by whether it
13
+ * waits (open), was answered, or is done — a tap opens its thread; a mark
14
+ * the host lists in `unread` (an agent's word not yet opened) wears a quiet
15
+ * "new" ring and dot;
16
+ * - **takes a mark** when the host turns marking on: a tap names the element
17
+ * under it, a drag names the elements inside the area drawn (and the area).
18
+ * A mouse or pen tap on empty board marks a small area there; a finger's tap
19
+ * on empty board does nothing, so a phone's stray touch never makes a mark
20
+ * (a finger's drag still frames an area).
21
+ *
22
+ * Positioned over the canvas by the host (both in one `position: relative`
23
+ * box); it lets every pointer through to the canvas except on its pins and
24
+ * while marking.
25
+ */
26
+ import { type CSSProperties } from "react";
27
+ import { type Box, type ElementBox, type Mark, type Viewport } from "@miadi/stateloom-protocol";
28
+ import { type CanvasTheme } from "./theme.js";
29
+ /** What a person pointed at while marking, before they say anything about it. */
30
+ export interface MarkDraft {
31
+ elements: string[];
32
+ region?: Box;
33
+ }
34
+ export interface StageOverlayProps {
35
+ viewport: Viewport;
36
+ /** Where the drawn elements are, in the drawing's coordinates. */
37
+ boxes: readonly ElementBox[];
38
+ /** Elements to light; the rest dims. */
39
+ spotlight?: readonly string[];
40
+ /** An area to frame. */
41
+ region?: Box | null;
42
+ marks?: readonly Mark[];
43
+ selectedMark?: string | null;
44
+ onSelectMark?: (id: string) => void;
45
+ /**
46
+ * Marks with an agent's word the person has not opened yet (their ids): the
47
+ * pin wears a quiet "new" ring. `unreadMarks(marks, read)` from the protocol,
48
+ * with `read` from `useMarksRead`.
49
+ */
50
+ unread?: readonly string[];
51
+ /** Resolved marks keep no pin. Default true. */
52
+ hideResolved?: boolean;
53
+ /** Take the next tap or drag as a mark. */
54
+ marking?: boolean;
55
+ onDraft?: (draft: MarkDraft) => void;
56
+ /** A mark being written: its elements ringed, its area framed. */
57
+ draft?: MarkDraft | null;
58
+ theme?: Partial<CanvasTheme>;
59
+ className?: string;
60
+ style?: CSSProperties;
61
+ }
62
+ /** Where a mark sits: its elements that are drawn here, else its area. */
63
+ export declare function markAnchor(mark: Pick<Mark, "elements" | "region">, boxes: readonly ElementBox[]): Box | null;
64
+ export declare function StageOverlay({ viewport, boxes, spotlight, region, marks, selectedMark, onSelectMark, unread, hideResolved, marking, onDraft, draft, theme, className, style, }: StageOverlayProps): import("react").JSX.Element;
65
+ export default StageOverlay;