@marver-design/marver 0.30.1 → 0.31.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.
Files changed (107) hide show
  1. package/CHANGELOG.md +58 -0
  2. package/README.md +11 -7
  3. package/dist/{anchor-check-Bv4o-R2T.mjs → anchor-check-B92s9tVv.mjs} +1 -1
  4. package/dist/{board-tree-BXR8dw4b.mjs → board-tree-DGj0HhEE.mjs} +6 -2
  5. package/dist/{boards-EH2onUXM.mjs → boards-Cim1GTKc.mjs} +32 -2
  6. package/dist/{boards-BeWtjGUM.mjs → boards-OlAhZ87x.mjs} +7 -7
  7. package/dist/{build-zWGXSzly.mjs → build-BNssmbqd.mjs} +14 -17
  8. package/dist/{capture-DEtM4qm5.mjs → capture-HaS-1or8.mjs} +1 -1
  9. package/dist/cli.mjs +38 -20
  10. package/dist/{collab-BEAcXrBb.mjs → collab-D2NcrOB8.mjs} +53 -14
  11. package/dist/comment-actions-Bxf9Ld4g.mjs +351 -0
  12. package/dist/{comments-XNhMmSSu.mjs → comments-BakJQwaf.mjs} +85 -10
  13. package/dist/config-B0YcFtqS.mjs +510 -0
  14. package/dist/{context-BUnFiyA3.mjs → context-Cj2TcC0H.mjs} +3 -3
  15. package/dist/{daemon-CChgWJNq.mjs → daemon-MxoEQajX.mjs} +222 -23
  16. package/dist/deep-link-DYtuT740.mjs +163 -0
  17. package/dist/{dev-DOgIITpT.mjs → dev-BBZe_brH.mjs} +23 -16
  18. package/dist/devices-uJZ2inMq.mjs +155 -0
  19. package/dist/{events-CLH4ijKP.mjs → events-Dieo1482.mjs} +49 -4
  20. package/dist/{init-CYlFaRzG.mjs → init-BgusplYn.mjs} +40 -10
  21. package/dist/{jam-Cj5gBvwD.mjs → jam-CkuLL8A8.mjs} +1 -1
  22. package/dist/{link-BFFRgrMt.mjs → link-Cmt9Xy4X.mjs} +54 -7
  23. package/dist/{logo-CXY-1yrn.mjs → logo-C9s7-Cy9.mjs} +89 -66
  24. package/dist/{ls-NqmePKOf.mjs → ls-DGVIW-Io.mjs} +1 -1
  25. package/dist/{manifest-DPZ3WNg_.mjs → manifest-CK8Qh4Nq.mjs} +255 -13
  26. package/dist/{marks-BnNANic9.mjs → marks-C8oX8kbE.mjs} +3 -3
  27. package/dist/{marks-DBp3h1Mc.mjs → marks-Dt-5JXCp.mjs} +18 -5
  28. package/dist/{marver-id-gate-vBLb_Icb.mjs → marver-id-gate-BAeuMeaU.mjs} +11 -7
  29. package/dist/md-B9_13Q0R.mjs +105 -0
  30. package/dist/notes-CRAX4wgk.mjs +148 -0
  31. package/dist/own-C8Mq0Hnf.mjs +128 -0
  32. package/dist/pdf-0m721FFn.mjs +117 -0
  33. package/dist/pdf-CZENT6t3.mjs +2299 -0
  34. package/dist/{perf-BCxAo0IS.mjs → perf-BB0XNt1M.mjs} +1 -1
  35. package/dist/{perf-6MOTHxay.mjs → perf-CIMijND6.mjs} +5 -5
  36. package/dist/{plugin-CFWBcAba.mjs → plugin-CL8_wL7a.mjs} +460 -83
  37. package/dist/{poster-DPPpQiva.mjs → poster-B7uSjlEP.mjs} +1 -1
  38. package/dist/{profile-B1FKOM1e.mjs → profile-cdmSer1k.mjs} +1 -1
  39. package/dist/{publish-bakes-_Zx8crP3.mjs → publish-bakes-BjgDNeyS.mjs} +3 -3
  40. package/dist/{queue-DeSQm24g.mjs → queue-BLLfdlDw.mjs} +156 -11
  41. package/dist/{recover-mDUVsnPd.mjs → recover-ByuFQOF9.mjs} +2 -2
  42. package/dist/{serve-DQv3Ti6X.mjs → serve-kcF6-H8V.mjs} +4 -4
  43. package/dist/{session-VDJfXEEm.mjs → session-DBF-nQvq.mjs} +29 -3
  44. package/dist/{share-Bu_kuOKL.mjs → share-CS2mg27O.mjs} +1 -1
  45. package/dist/{shot-d4h_hJi9.mjs → shot-BqwkdtKn.mjs} +4 -4
  46. package/dist/{shot-DBWN8hPP.mjs → shot-D2TQGo2V.mjs} +1 -1
  47. package/dist/show-B1u3DiJw.mjs +101 -0
  48. package/dist/{sizes-wjXDev3b.mjs → sizes-BckcL4Zz.mjs} +1 -1
  49. package/dist/{slots-Dn4Onb0V.mjs → slots-BOcfIqxy.mjs} +15 -3
  50. package/dist/{summary-Y8MY1Wuc.mjs → summary-cPmRDGpX.mjs} +1 -1
  51. package/dist/{sync-CMozOwZ0.mjs → sync-BNWwh8OF.mjs} +205 -7
  52. package/dist/{work-BYWD_1Zf.mjs → work-DRdzXPvg.mjs} +3 -3
  53. package/dist/{work-DJxH7cCX.mjs → work-Nv-n2_Un.mjs} +1 -1
  54. package/docs/app.md +49 -0
  55. package/docs/boards-and-folders.md +37 -6
  56. package/docs/jam-session.md +5 -0
  57. package/docs/live-jam.md +9 -0
  58. package/docs/pdf.md +108 -0
  59. package/docs/publish.md +9 -9
  60. package/docs/sharing.md +11 -0
  61. package/docs/slides.md +9 -0
  62. package/package.json +3 -1
  63. package/src/client/content/index.tsx +4 -2
  64. package/src/client/frame-host/main.tsx +3 -0
  65. package/src/client/shell/App.tsx +71 -24
  66. package/src/client/shell/BoardList.tsx +16 -7
  67. package/src/client/shell/Comments.tsx +77 -16
  68. package/src/client/shell/Play.tsx +24 -22
  69. package/src/client/shell/Toolbar.tsx +4 -3
  70. package/src/client/shell/app-bridge.ts +32 -5
  71. package/src/client/shell/canvas/Canvas.tsx +30 -8
  72. package/src/client/shell/canvas/FrameNode.tsx +3 -1
  73. package/src/client/shell/canvas/ctl.ts +16 -0
  74. package/src/client/shell/commands.ts +20 -0
  75. package/src/client/shell/comments-store.ts +81 -2
  76. package/src/client/shell/devices.tsx +42 -0
  77. package/src/client/shell/goto.ts +56 -9
  78. package/src/client/shell/icons.tsx +11 -4
  79. package/src/client/shell/jam-lines.ts +5 -3
  80. package/src/client/shell/jam-panel.tsx +17 -5
  81. package/src/client/shell/marks-ui.tsx +54 -0
  82. package/src/client/shell/notes.ts +21 -0
  83. package/src/client/shell/pdf-export.tsx +154 -0
  84. package/src/client/shell/pdf-notes.ts +20 -0
  85. package/src/client/shell/show.ts +250 -0
  86. package/src/client/shell/store.ts +23 -38
  87. package/src/client/shell/styles.css +43 -0
  88. package/src/shared/app-api.ts +49 -4
  89. package/src/shared/auto-place.ts +32 -0
  90. package/src/shared/board-tree.ts +3 -0
  91. package/src/shared/board-types.ts +6 -2
  92. package/src/shared/deep-link.ts +212 -0
  93. package/src/shared/devices.ts +89 -0
  94. package/src/shared/events.ts +48 -5
  95. package/src/shared/export-plan.ts +98 -0
  96. package/templates/AGENTS-embedded.md +76 -12
  97. package/templates/AGENTS-studio.md +76 -12
  98. package/templates/instructions/boards.md +6 -5
  99. package/templates/instructions/configure.md +32 -2
  100. package/templates/instructions/iterate.md +8 -0
  101. package/templates/instructions/jam.md +9 -0
  102. package/templates/instructions/publish.md +14 -4
  103. package/templates/instructions/review.md +4 -0
  104. package/templates/instructions/slides.md +67 -1
  105. package/templates/instructions/welcome.md +9 -5
  106. package/templates/playbooks/publish-canvas/PLAYBOOK.md +1 -1
  107. package/dist/config-BezZTiov.mjs +0 -182
@@ -0,0 +1,250 @@
1
+ /**
2
+ * Showing the human a place (spec 31 D1, D3): `marver show`'s `sh:show { seq, board, n?, f?, s?, c? }` from the dev
3
+ * server, and in the Mac app the same command over the bridge (`onShow`) for a `marver://` link into a tab already
4
+ * open. One rule for both:
5
+ *
6
+ * - the command is checked again (shared/deep-link.ts `checkShowTarget`) - the hash's own targets, never a raw hash;
7
+ * - a tab holding unsent words (a comment draft, a Jam edit: api.ts `typedUnsent`) or a capture recording does not move:
8
+ * it puts up "Your agent wants to show you <title> · Go", and Go moves it when the human chooses;
9
+ * - else it switches board, selects (node keys stay node keys - one copy of a frame, never every copy), opens the
10
+ * thread, and fits - even when it is already there: a repeat refits;
11
+ * - a newer command supersedes an older one still on its way (a board read, a fit), and a server seq it already took is
12
+ * never taken twice;
13
+ * - in the app, a server show then asks the main process (`front()`, a trusted bridge call bound to the admitted
14
+ * document) to activate its tab and bring the window forward; a bridge show was activated by main already;
15
+ * - a server show is answered (`POST show/ack { seq, page, outcome }`), so `marver show` can say "shown in 2 tabs".
16
+ */
17
+ import { create } from 'zustand'
18
+ import { checkShowTarget, type ShowTarget } from '../../shared/deep-link.ts'
19
+ import { api, typedUnsent } from './api.ts'
20
+ import { bootLanded, cancelBoot, canvasCtl } from './canvas/ctl.ts'
21
+ import { openThreadAt } from './jam-keys.ts'
22
+ import { handNow, isLatest, navigated, navNow, revealFrame, switchFor } from './goto.ts'
23
+ import { linkTargets } from './hash.ts'
24
+ import { useJamCapture } from './jam-capture.ts'
25
+ import { APP } from './marver-app.ts'
26
+ import { PAGE_ID } from './recorder.ts'
27
+ import { boardLabel, landingBoard, sceneLabel, useStore } from './store.ts'
28
+
29
+ export type ShowFrom = 'server' | 'app'
30
+ export type ShowResult = 'shown' | 'notice' | 'stale' | 'missing' | 'bad' | 'deferred'
31
+
32
+ /** The notice a tab holding unsent words puts up instead of moving: its words, and the target Go opens. */
33
+ export interface ShowNotice { title: string; target: ShowTarget | 'landing'; at: number }
34
+ export const useShowNotice = create<{ notice: ShowNotice | null }>(() => ({ notice: null }))
35
+
36
+ /** Words a move would lose, or a capture it would cut: the same reasons a notice's click reads (open-item.ts). */
37
+ const holdsWords = (): boolean => typedUnsent() || !!useJamCapture.getState().current
38
+
39
+ /**
40
+ * A show never races the boot (spec 31 D3). One that comes while the tab still boots - its board not loaded, or its
41
+ * first camera not applied (the app delivers a link's place right after the page's hello, before its first render) - is
42
+ * deferred: the newest alone is kept, and applied once the boot settles, whether it loaded or failed. A person's own
43
+ * navigation meanwhile wins: the deferred show is dropped. Applying it cancels every boot reveal still to come
44
+ * (canvas/ctl.ts `cancelBoot`).
45
+ */
46
+ let booting = true
47
+ /** The board the boot failed to load, while the tab still names it: a show to it loads it again, never takes it as shown */
48
+ let failedBoard: string | null = null
49
+ let deferred: { t: ShowTarget | 'landing'; seq?: number; from: ShowFrom; n: number; nav: number; hand: number } | null = null
50
+
51
+ /** App.tsx, once `boot()` answered: a board that failed or has no nodes is settled now; one with nodes once its first
52
+ * camera is applied (Canvas.tsx), or two seconds at most. */
53
+ export function bootSettled(ok: boolean): void {
54
+ if (!ok) failedBoard = useStore.getState().board
55
+ const settle = () => {
56
+ if (!booting) return
57
+ booting = false
58
+ const d = deferred
59
+ deferred = null
60
+ // the newest show, and no navigation of a person's since it came: applied now
61
+ if (d && d.n === current && isLatest(d.nav) && d.hand === handNow()) void apply(d.t, d.seq, d.from, d.n)
62
+ }
63
+ if (!ok || !useStore.getState().nodes.length) settle()
64
+ else void Promise.race([bootLanded, new Promise((r) => setTimeout(r, 2000))]).then(settle)
65
+ }
66
+
67
+ /** The newest command's number: an older one still on its way stops at its next step. */
68
+ let current = 0
69
+ /** The last server seq this page took: the same one again (a reconnect's replay) is never taken twice. */
70
+ let lastSeq = 0
71
+
72
+ /** What the notice calls the place: one frame by its title, one scene by its label, else the board. */
73
+ export function titleOf(t: ShowTarget): string {
74
+ const s = useStore.getState()
75
+ const frames = t.f ?? []
76
+ if (frames.length === 1 && !t.s?.length && !t.n?.length) {
77
+ const f = s.manifest?.frames.find((x) => x.id === frames[0])
78
+ return f?.title || frames[0]!
79
+ }
80
+ if (t.s?.length === 1 && !frames.length && !t.n?.length) return sceneLabel(t.s[0]!)
81
+ return boardLabel(t.board)
82
+ }
83
+
84
+ /** The words the notice says for the canvas's own board (a link that named no place it understands). */
85
+ const LANDING = 'the board this canvas opens on'
86
+
87
+ /**
88
+ * Move to the target now - board, selection, thread, camera - each step only while this command is the newest and,
89
+ * unless the person chose it (`force`: the notice's Go), while no words wait unsent: words typed while the board loads
90
+ * stop it before anything moves (`blocked`, which the caller turns into the notice). `shown` only once the camera has
91
+ * landed for this command: a newer show, or a board that went, is never counted shown.
92
+ */
93
+ async function go(t: ShowTarget | 'landing', n: number, force: boolean): Promise<ShowResult | 'blocked'> {
94
+ const nav = navigated()
95
+ const hand = handNow()
96
+ // the newest show, no navigation since, and nothing the person did on the canvas since (goto.ts navigatedByHand)
97
+ const owned = () => n === current && isLatest(nav) && hand === handNow()
98
+ const words = () => !force && holdsWords()
99
+ const alive = () => owned() && !words()
100
+ const ended = (): 'blocked' | 'stale' => (owned() && words() ? 'blocked' : 'stale')
101
+ if (!alive()) return ended()
102
+ // the camera is this show's from here: every boot reveal still to come gives way (the boot camera, its frame fallback,
103
+ // its thread). After a failed boot the show owns the camera for good - if its own board then fails too, the canvas is a
104
+ // failed board load like any other and the boot link's place is not restored (spec 31 as built: accepted)
105
+ cancelBoot()
106
+ let target: ShowTarget
107
+ if (t === 'landing') {
108
+ const board = await landingBoard()
109
+ if (!alive()) return ended()
110
+ target = { board }
111
+ } else target = t
112
+ let s = useStore.getState()
113
+ if (s.play) s.setPlay(null) // a stale overlay never survives a show
114
+ if (target.board !== s.board) {
115
+ if (!await switchFor(target.board, nav, alive)) return alive() ? 'missing' : ended()
116
+ s = useStore.getState()
117
+ } else if (failedBoard === s.board && !s.nodes.length) {
118
+ // the board the boot failed to load: loaded now, or the show did not happen
119
+ if (!await s.boot(alive)) return alive() ? 'missing' : ended()
120
+ s = useStore.getState()
121
+ }
122
+ failedBoard = null
123
+ if (!alive()) return ended()
124
+ const keys = linkTargets(target, s.nodes)
125
+ // nodes or a scene named, none on this board: nothing to show - never answered shown (a frame is followed below)
126
+ if (!keys.length && (target.n?.length || target.s?.length) && !target.f?.length) return 'missing'
127
+ useStore.setState({ selection: keys })
128
+ s.look(keys)
129
+ if (target.c) {
130
+ // the thread where it can be seen - pins turned on, a resolved one in its panel - under the same request, and
131
+ // waited for: a thread that never shows is no "shown"
132
+ if (!await openThreadAt(target.board, target.c, { alive })) return alive() ? 'missing' : ended()
133
+ return (await fitOwn(alive)) ? 'shown' : ended()
134
+ }
135
+ if (!keys.length && target.f?.length) {
136
+ // not on this board's nodes: where it lives, under the same request - shown once it is selected there and the
137
+ // camera has landed, for this command
138
+ const f = target.f[0]!
139
+ await revealFrame(f, nav, alive)
140
+ for (let i = 0; i < 40 && alive(); i++) {
141
+ const now = useStore.getState()
142
+ if (now.selection.some((k) => now.nodes.find((x) => x.key === k)?.frame === f)) return (await fitOwn(alive)) ? 'shown' : ended()
143
+ await new Promise((r) => setTimeout(r, 50))
144
+ }
145
+ return alive() ? 'missing' : ended()
146
+ }
147
+ // the refit, even when the place is already on screen - unless a newer navigation has the camera by then (a frame's
148
+ // worth for the selection to draw; none in a background tab, whose timers run once a second)
149
+ if (document.visibilityState !== 'hidden') await new Promise((r) => setTimeout(r, 60))
150
+ if (!alive()) return ended()
151
+ if (keys.length) canvasCtl.fitNodes(keys); else canvasCtl.fitAll()
152
+ return (await cameraLanded(alive)) ? 'shown' : ended()
153
+ }
154
+
155
+ /** The show's own fit to what the helper selected (revealFrame's and revealThread's fits run on their timers, which a
156
+ * newer show may cancel): this command's camera, then its landing - in a background tab at once. */
157
+ async function fitOwn(alive: () => boolean): Promise<boolean> {
158
+ if (!alive()) return false
159
+ const sel = useStore.getState().selection
160
+ // a thread with no node to fit (a resolved one, in its panel): the board it is on, fitted all the same
161
+ if (sel.length) canvasCtl.fitNodes([...sel]); else canvasCtl.fitAll()
162
+ return cameraLanded(alive)
163
+ }
164
+
165
+ /** The camera came to rest (the commands' own rule, commands.ts `cameraDone`: it flew and stopped, or rested 250 ms),
166
+ * while `alive` held throughout - a newer navigation or words typed meanwhile is no landing. A tab in the background
167
+ * lands its camera at once (Canvas.tsx `fly`), and is timed here without frames. 2 s at most, so `marver show`'s 3 s
168
+ * hear every tab; a camera still flying then has not landed - no "shown". */
169
+ async function cameraLanded(alive: () => boolean): Promise<boolean> {
170
+ const since = performance.now()
171
+ let saw = false
172
+ // a background tab's fit landed synchronously (Canvas.tsx fly): verified now, no polling its throttled timers
173
+ if (document.visibilityState === 'hidden') return alive() && !canvasCtl.cameraBusy()
174
+ for (let n = 1; performance.now() - since < 2000; n++) {
175
+ // a frame, or 50 ms where none come (a tab in the background)
176
+ await new Promise((r) => { const late = setTimeout(r, 50); requestAnimationFrame(() => { clearTimeout(late); r(null) }) })
177
+ if (!alive()) return false
178
+ const busy = canvasCtl.cameraBusy()
179
+ if (busy) saw = true
180
+ if (!busy && (saw || performance.now() - since > 250) && n >= 2) return true
181
+ }
182
+ return false
183
+ }
184
+
185
+ const ack = (seq: number, outcome: 'shown' | 'notice') => {
186
+ const c = /(?:^|;\s*)mv_c=([\w-]+)/.exec(document.cookie)?.[1] ?? ''
187
+ void api('show/ack', { method: 'POST', headers: { 'content-type': 'application/json', 'x-mv-c': c }, body: JSON.stringify({ seq, page: PAGE_ID, outcome }) }).catch(() => {})
188
+ }
189
+
190
+ /** The tab to the front of the app's window (a server show): main checks the asking document and acts. */
191
+ const front = () => { try { APP?.front?.() } catch { /* the app went away under the page */ } }
192
+
193
+ /**
194
+ * A show command, from the dev server (`seq`) or the app's bridge. The app's `null` is a link that named no place this
195
+ * shell takes: the canvas's own board, by the same rule (moved to, or the notice over unsent words).
196
+ */
197
+ export async function showTarget(raw: unknown, from: ShowFrom): Promise<ShowResult> {
198
+ const seq = from === 'server' ? (raw as { seq?: unknown } | null)?.seq : undefined
199
+ if (from === 'server' && (typeof seq !== 'number' || !Number.isSafeInteger(seq) || seq < 1)) return 'bad'
200
+ const t: ShowTarget | 'landing' | null = from === 'app' && raw === null ? 'landing' : checkShowTarget(raw)
201
+ if (!t) return 'bad'
202
+ if (typeof seq === 'number') {
203
+ if (seq <= lastSeq) return 'stale'
204
+ lastSeq = seq
205
+ }
206
+ const n = ++current
207
+ if (booting) {
208
+ // the newest alone waits for the boot (an older deferred one is superseded: never answered)
209
+ deferred = { t, ...(typeof seq === 'number' ? { seq } : {}), from, n, nav: navNow(), hand: handNow() }
210
+ return 'deferred'
211
+ }
212
+ return apply(t, typeof seq === "number" ? seq : undefined, from, n)
213
+ }
214
+
215
+ /** A show applied: the notice over unsent words, or the move - answered, and the window forward, once it is on screen. */
216
+ async function apply(t: ShowTarget | 'landing', seq: number | undefined, from: ShowFrom, n: number): Promise<ShowResult> {
217
+ const notice = (): ShowResult => {
218
+ useShowNotice.setState({ notice: { title: t === 'landing' ? LANDING : titleOf(t), target: t, at: Date.now() } })
219
+ if (typeof seq === 'number') ack(seq, 'notice')
220
+ if (from === 'server') front()
221
+ return 'notice'
222
+ }
223
+ if (holdsWords()) return notice()
224
+ useShowNotice.setState({ notice: null })
225
+ const r = await go(t, n, false)
226
+ // words typed while it was on its way: the notice instead, nothing moved
227
+ if (r === 'blocked') return n === current ? notice() : 'stale'
228
+ // answered, and the window brought forward, once it is on screen: a newer show or a board that went is no "shown"
229
+ if (r === 'shown') {
230
+ if (typeof seq === 'number') ack(seq, 'shown')
231
+ if (from === 'server') front()
232
+ }
233
+ return r
234
+ }
235
+
236
+ /** The notice's Go: the human chose to move, words or not. */
237
+ export async function goNow(): Promise<ShowResult> {
238
+ const notice = useShowNotice.getState().notice
239
+ useShowNotice.setState({ notice: null })
240
+ if (!notice) return 'stale'
241
+ const r = await go(notice.target, ++current, true)
242
+ return r === 'blocked' ? 'stale' : r
243
+ }
244
+ export const dismissShow = (): void => { useShowNotice.setState({ notice: null }) }
245
+
246
+ /** A server seq the page knows (tests read where it stands). */
247
+ export const showState = () => ({ current, lastSeq })
248
+
249
+ // dev-only inspection hook for tests (never installed in published builds)
250
+ if (typeof window !== 'undefined' && import.meta.env.DEV) (window as unknown as { __mvShow: unknown }).__mvShow = { showTarget, goNow, dismissShow, state: showState, notice: () => useShowNotice.getState().notice }
@@ -1,13 +1,14 @@
1
1
  import { create } from 'zustand'
2
2
  import { ROUTE, slideSize } from '../const.ts'
3
3
  import { tidy, parseLayout, type BoardLayout, type TidyNode } from './tidy.ts'
4
- import { clearNoteHeights, noteHeight, noteReserve, notesCramped, scopeNotes, setNoteHeight } from './notes.ts'
4
+ import { clearNoteHeights, noteHeight, noteReserve, notesCramped, scopeNotes, setNoteHeight, tidyNodes } from './notes.ts'
5
5
  import { stableNodeKey } from './keys.ts'
6
6
  import { canvasCtl } from './canvas/ctl.ts'
7
7
  import { api, beforeResume, canvasStopped, holdsReload, lostInResume, mvFetch, noteUnsaved, onLinkNotice, savedInResume, scoped, STOPPED_WAY, withWs } from './api.ts'
8
8
  import { unsavedWhen, workChanged } from './unsaved.ts'
9
9
  import { nextSeq, PAGE_ID } from './recorder-seams.ts'
10
10
  import type { BoardWriter, HeldBy, LoadTrigger } from '../../shared/perf-records.ts'
11
+ import type { DeviceLook } from '../../shared/devices.ts'
11
12
  // @ts-expect-error virtual module provided by the plugin
12
13
  import shConfig from 'virtual:sh-config'
13
14
  // @ts-expect-error virtual module: null in dev; a published build inlines manifest+boards
@@ -128,9 +129,12 @@ export interface JamNote {
128
129
  /** earlier notices folded under this one - View walks through them */
129
130
  stack?: JamNote[]
130
131
  }
131
- export interface Toast { id: number; text: string; jam?: JamNote }
132
+ /** A plain notice's one action (spec 31 B.3: "Resolved 31 conversations · Undo"): what its click runs - which records
133
+ * its own command (`resolve-undo`). `id` names it on the notice (`data-toast`). */
134
+ export interface ToastAction { label: string; id: string; run: () => void }
135
+ export interface Toast { id: number; text: string; jam?: JamNote; action?: ToastAction }
132
136
 
133
- export const CONFIG: { viewports: Record<string, { width: number; height: number }>; themes: string[]; zoomSpeed?: number; noTheme: boolean; setup?: boolean; projectName?: string; branding?: boolean; jam?: { chime: boolean; capture: 'confirm' | 'at-once'; names?: boolean } | null; workspace?: string; version?: string } = shConfig
137
+ export const CONFIG: { viewports: Record<string, { width: number; height: number }>; devices?: Record<string, DeviceLook>; themes: string[]; zoomSpeed?: number; noTheme: boolean; setup?: boolean; projectName?: string; branding?: boolean; jam?: { chime: boolean; capture: 'confirm' | 'at-once'; names?: boolean } | null; workspace?: string; version?: string } = shConfig
134
138
 
135
139
  /** Invariant: `branding: false` strips every Marver mention - new chrome included. */
136
140
  export const BRANDING = CONFIG.branding !== false
@@ -173,8 +177,9 @@ export { cap, humanize } from './labels.ts'
173
177
  import { cap, humanize } from './labels.ts'
174
178
  import { canAutoReload } from './canvas/ready-watch.ts'
175
179
  import { pumpUpdates } from './canvas/updates.ts'
176
- import { archiveLast, buildTree, flatten, framesOn, labelOf, toWire, TREE_PROTOCOL, type TreeItem } from '../../shared/board-tree.ts'
180
+ import { archiveLast, buildTree, canvasLabel, flatten, framesOn, labelOf, toWire, TREE_PROTOCOL, type TreeItem } from '../../shared/board-tree.ts'
177
181
  import { UNPLACED } from './hash.ts'
182
+ import { placeNewcomers } from '../../shared/auto-place.ts'
178
183
  import type { BoardType, StatusWord } from '../../shared/board-types.ts'
179
184
  import type { Phase, Status } from '../../shared/status.ts'
180
185
  import { isNew, type Marks } from '../../shared/marks.ts'
@@ -259,7 +264,7 @@ export async function fetchMembership(): Promise<{ boards: { name: string; frame
259
264
  * re-render on change), else the Title-Cased slug. */
260
265
  export const boardLabel = (n: string) => (n === UNPLACED ? 'Not on a board' : labelOf(n, useStore.getState().boardTitles[n]))
261
266
  /** The canvas's name, as the sidebar heads it: the project's (share.name, else the repo folder). */
262
- export const CANVAS_NAME = CONFIG.projectName ? humanize(CONFIG.projectName) : 'Marver'
267
+ export const CANVAS_NAME = CONFIG.projectName ? canvasLabel(CONFIG.projectName) : 'Marver'
263
268
  /** The browser tab: the board, then the canvas - "Start here - Acme Studio" - so a row of canvas tabs
264
269
  * says which project each one is (it said "- Marver" on all of them). */
265
270
  export const tabTitle = (board: string | null | undefined): string => (board ? `${boardLabel(board)} - ${CANVAS_NAME}` : CANVAS_NAME)
@@ -318,16 +323,7 @@ const HEADER = 28
318
323
  * tidy keeps the scene reserve on the first node it places), and the measured height of the
319
324
  * column standing there, so a note longer than its frame gets its room below as well. */
320
325
  export function tidyInput(nodes: readonly Node[], manifest: Manifest | null): TidyNode[] {
321
- const entryOf = (id: string) => manifest?.frames.find((f) => f.id === id)
322
- const sceneNote = (scene: string) => !!manifest?.scenes.find((s) => s.name === scene)?.note
323
- return nodes.map((n) => {
324
- const f = entryOf(n.frame)
325
- const scene = f?.scene ?? ''
326
- return {
327
- key: n.key, frame: n.frame, scene, group: f?.variantGroup, variant: f?.variant, w: n.w, h: n.h + HEADER,
328
- noteW: noteReserve(!!f?.note, false), sceneNoteW: noteReserve(false, sceneNote(scene)), noteH: noteHeight(n.key),
329
- }
330
- })
326
+ return tidyNodes(nodes, manifest) // notes.ts: the deck PDF's plan lays boards out with the same input
331
327
  }
332
328
  let toastSeq = 0
333
329
  const nodeKey = () => 'n_' + Math.random().toString(36).slice(2, 8)
@@ -745,7 +741,10 @@ interface State {
745
741
  togglePanel(): void
746
742
  setTheme(theme: string): void
747
743
  runTidy(): void
748
- toast(text: string): void
744
+ /** a plain notice, gone after 4 s - or `ms`; one with an `action` (Undo) stays its own while it shows */
745
+ toast(text: string, action?: ToastAction, ms?: number): void
746
+ /** take a plain notice down now (its action ran) */
747
+ dropToast(id: number): void
749
748
  jamToast(note: JamNote): void
750
749
  /** a jam card failed - one notice, with Retry (spec 27: only a question or a failure interrupts) */
751
750
  jamFailed(cards: { id: string; rev: number; board: string; thread?: string; frames: string[]; note?: string; batch?: string }[]): void
@@ -1159,7 +1158,6 @@ export const useStore = create<State>((set, get) => {
1159
1158
  // (the old published everything-board bug: frames created after the board file was last
1160
1159
  // saved piled up at the origin)
1161
1160
  if (boardAuto) {
1162
- const placed = new Set(nodes.map((n) => n.frame))
1163
1161
  // newcomers get deterministic keys too - on a published auto board
1164
1162
  // this path mints EVERY key, every visit, and comments anchor to them
1165
1163
  const haveKeys = new Set(nodes.map((n) => n.key))
@@ -1169,24 +1167,10 @@ export const useStore = create<State>((set, get) => {
1169
1167
  haveKeys.add(k)
1170
1168
  return k
1171
1169
  }
1172
- let maxX = nodes.reduce((a, n) => Math.max(a, n.x + n.w), 0)
1173
- for (const f of manifest.frames) {
1174
- if (placed.has(f.id)) continue
1175
- placed.add(f.id)
1176
- const d = defaultSize(f)
1177
- const vp = deviceView ? CONFIG.viewports[deviceView] : null
1178
- const w = vp?.width ?? d.w, h = vp?.height ?? d.h
1179
- let x: number, y: number
1180
- const sibling = f.variantGroup
1181
- ? nodes.filter((n) => manifest.frames.find((m) => m.id === n.frame)?.variantGroup === f.variantGroup)
1182
- .reduce<Node | null>((a, n) => (!a || n.x + n.w > a.x + a.w ? n : a), null)
1183
- : null
1184
- if (sibling) { x = sibling.x + sibling.w + Math.max(140, sibling.w * 0.12); y = sibling.y }
1185
- else { x = nodes.length ? maxX + 96 : 0; y = 0 }
1186
- const node: Node = { key: mint(f.id), frame: f.id, x, y, w, h, theme: resolveTheme(f), status: 'loading', ...(f.contentWidth ? { sizeMode: (vp ? 'device' : 'auto') as Node['sizeMode'] } : {}) }
1187
- nodes.push(node)
1188
- maxX = Math.max(maxX, x + w)
1189
- }
1170
+ // the placement rule the deck PDF's plan shares (src/shared/auto-place.ts)
1171
+ const vp = deviceView ? CONFIG.viewports[deviceView] : null
1172
+ placeNewcomers(nodes, manifest.frames, (f) => { const d = defaultSize(f); return { w: vp?.width ?? d.w, h: vp?.height ?? d.h } },
1173
+ (f, x, y, w, h): Node => ({ key: mint(f.id), frame: f.id, x, y, w, h, theme: resolveTheme(f), status: 'loading', ...(f.contentWidth ? { sizeMode: (vp ? 'device' : 'auto') as Node['sizeMode'] } : {}) }))
1190
1174
  }
1191
1175
  // published: re-apply this visit's pins and content sizes over the inlined data
1192
1176
  if (DATA && nodes.length) {
@@ -1968,11 +1952,12 @@ export const useStore = create<State>((set, get) => {
1968
1952
  })))
1969
1953
  scheduleSave()
1970
1954
  },
1971
- toast(text) {
1955
+ toast(text, action, ms) {
1972
1956
  const id = ++toastSeq
1973
- set((s) => ({ toasts: [...s.toasts, { id, text }] }))
1974
- setTimeout(() => set((s) => ({ toasts: s.toasts.filter((t) => t.id !== id) })), 4000)
1957
+ set((s) => ({ toasts: [...s.toasts, { id, text, ...(action ? { action } : {}) }] }))
1958
+ setTimeout(() => set((s) => ({ toasts: s.toasts.filter((t) => t.id !== id) })), ms ?? 4000)
1975
1959
  },
1960
+ dropToast(id) { set((s) => ({ toasts: s.toasts.filter((t) => t.id !== id) })) },
1976
1961
  /** A Live Jam reply notification: persistent (no auto-dismiss), one per thread (a newer reply
1977
1962
  * supersedes), capped so the stack stays small. */
1978
1963
  jamToast(note) {
@@ -635,6 +635,8 @@ body.sh-space .sh-node { pointer-events: none } /* space-drag
635
635
  cursor: pointer; text-align: left }
636
636
  .sh-menu button:hover { background: var(--glass-hover) }
637
637
  .sh-menu button span { flex: 1; text-transform: capitalize }
638
+ /* a device's label is written as it should read ("iPad landscape", spec 31 F.2) - never re-capitalised */
639
+ .sh-menu button span.dev-label { text-transform: none }
638
640
  /* the sidebar right-click menu keeps its labels verbatim (they match the toolbar exactly);
639
641
  it scrolls rather than overflowing the window when the folder list grows long */
640
642
  .sh-ctxmenu { max-height: calc(100vh - 16px - var(--mv-top, 0px)); max-width: 240px; overflow-y: auto; scrollbar-width: thin }
@@ -712,6 +714,9 @@ body.sh-space .sh-node { pointer-events: none } /* space-drag
712
714
  border: 0; background: none; border-radius: 999px; color: var(--glass-ink-3); cursor: pointer;
713
715
  transition: color .15s, background .15s }
714
716
  .sh-update .x:hover { background: var(--glass-hover); color: var(--glass-ink) }
717
+ /* `marver show` over unsent words (spec 31 D3): above the update pill, so both can be up */
718
+ .sh-show-notice { bottom: calc(var(--edge) + 50px); z-index: 33 } /* over Play (30, 31) and the toasts (32): a draft typed in Play keeps its notice in view */
719
+ .sh-show-notice .cmd code { color: var(--glass-ink) }
715
720
 
716
721
  /* bottom-RIGHT now: jam reply pills live here; plain toasts ride along */
717
722
  .sh-toasts { position: absolute; right: var(--edge); bottom: var(--edge); z-index: 32; display: flex;
@@ -719,10 +724,24 @@ body.sh-space .sh-node { pointer-events: none } /* space-drag
719
724
  .sh-toast { display: flex; align-items: center; gap: 6px; font: 500 12px -apple-system, system-ui, sans-serif;
720
725
  color: var(--glass-ink-2); border-radius: 999px; padding: 7px 13px }
721
726
  .sh-toast svg { color: var(--glass-good); flex: none }
727
+ /* a notice's one action (spec 31 B.3: Undo) */
728
+ .sh-toast-act { margin-left: 6px; padding: 2px 9px; border: 0; border-radius: 999px; cursor: pointer;
729
+ background: var(--glass-hover); color: var(--glass-ink); font: 600 12px -apple-system, system-ui, sans-serif }
730
+ .sh-toast-act:hover { background: color-mix(in srgb, var(--glass-ink) 14%, transparent) }
722
731
  /* the jam pill's svgs are NOT the toast checkmark: the mark stays white/90 on blue, the X keeps
723
732
  its own muted ink - undo the blanket green above */
724
733
  .sh-toast.jam svg { color: currentColor }
725
734
  .sh-toast-more { color: var(--glass-ink-3); font-size: 11px; padding: 2px 10px }
735
+ /* a deck PDF being made (spec 31): its board and page, a thin progress bar, Cancel */
736
+ .sh-toast.sh-pdf-notice { gap: 8px; padding: 7px 8px 7px 13px; pointer-events: auto }
737
+ .sh-toast.sh-pdf-notice svg { color: currentColor }
738
+ .sh-toast.sh-pdf-notice b { font-weight: 600; color: var(--glass-ink) }
739
+ .sh-pdf-notice .bar { width: 56px; height: 3px; border-radius: 2px; background: var(--glass-line, rgba(127,127,127,.25)); overflow: hidden; flex: none }
740
+ .sh-pdf-notice .bar i { display: block; height: 100%; background: currentColor; opacity: .7; transition: width .3s }
741
+ .sh-pdf-notice button { display: grid; place-items: center; width: 20px; height: 20px; border-radius: 999px; border: 0; background: transparent; color: var(--glass-ink-3); cursor: pointer }
742
+ .sh-pdf-notice button:hover { background: var(--glass-hover, rgba(127,127,127,.15)); color: var(--glass-ink) }
743
+ /* app 1.0.1: the held file's Download, a word not an icon */
744
+ .sh-pdf-notice button.go { width: auto; padding: 0 9px; font: inherit; font-weight: 600; color: var(--glass-ink) }
726
745
 
727
746
  /* the Live Jam reply pill: our full glass treatment, full radius, one row (§9) */
728
747
  .sh-toast.jam { gap: 12px; padding: 12px 12px 12px 14px; width: 380px; max-width: 100%; border-radius: 999px;
@@ -1184,6 +1203,23 @@ body.sh-hide-ui .sh-play-nav { display: none !important }
1184
1203
  color: var(--glass-ink); white-space: pre-wrap; overflow-wrap: break-word }
1185
1204
  .cm-scroll > .cm-body { margin-top: -10px } /* pulls against the scroller's 12px gap -> the same 2px replies get */
1186
1205
  .cm-msg { display: flex; flex-direction: column; gap: 2px }
1206
+ /* spec 31 C.1: a card's words can be selected and copied - the pan/zoom wrapper sets user-select: none on everything
1207
+ inside it (Canvas.tsx), and Play's stage overlay too; the card's own controls stay unselectable */
1208
+ .cm-card, .sh-play-comments .cm-card { user-select: text; -webkit-user-select: text; cursor: auto }
1209
+ .cm-card button, .cm-card .cm-actions, .cm-card header .dim, .cm-card .cm-tools { user-select: none; -webkit-user-select: none }
1210
+ /* spec 31 C.3-C.4: your own message's Edit and Delete - quiet until the message is hovered */
1211
+ .cm-card .cm-tools { margin-left: auto; display: inline-flex; gap: 2px; opacity: 0; transition: opacity .12s }
1212
+ .cm-card header:hover .cm-tools, .cm-card .cm-tools:focus-within, .cm-msg:hover .cm-tools { opacity: 1 }
1213
+ @media (hover: none) { .cm-card .cm-tools { opacity: 1 } }
1214
+ .cm-tool { height: 20px; padding: 0 6px; border: 0; border-radius: 6px; background: none; cursor: pointer;
1215
+ color: var(--glass-ink-3); font: 500 11.5px -apple-system, system-ui, sans-serif }
1216
+ .cm-tool:hover { background: var(--glass-hover); color: var(--glass-ink) }
1217
+ .cm-tool.danger { color: var(--mk-ask) }
1218
+ .cm-card .cm-edited { font-style: italic }
1219
+ .cm-editing { padding-left: 33px }
1220
+ .cm-confirm { display: flex; align-items: center; gap: 4px; padding-left: 33px; font-size: 12px; color: var(--glass-ink-2) }
1221
+ .cm-confirm span { flex: 1 }
1222
+ .cm-card .cm-deleted { color: var(--glass-ink-3); font-style: italic; padding-left: 0 }
1187
1223
  .cm-icon { display: inline-flex; align-items: center; justify-content: center; width: 26px; height: 26px;
1188
1224
  border: 0; border-radius: 8px; background: none; color: var(--glass-ink-3); cursor: pointer;
1189
1225
  transition: background .12s, color .12s }
@@ -2059,3 +2095,10 @@ textarea.jm-field:focus { border-color: transparent; box-shadow: 0 0 0 1px var(-
2059
2095
  .jm-count { cursor: pointer }
2060
2096
  /* in play the Jam button's crossed microphone wears the dark pill's ink (the canvas grey would vanish) */
2061
2097
  .sh-play-pill .sh-pill-btn.jm-jam .jm-nomic { color: inherit }
2098
+
2099
+ /* spec 31 F.1: a device's own icon - its sanitized SVG as a mask, filled with the ink it sits in */
2100
+ .sh-dev-mask { display: inline-block; flex: none; background-color: currentColor;
2101
+ -webkit-mask-size: contain; mask-size: contain; -webkit-mask-repeat: no-repeat; mask-repeat: no-repeat;
2102
+ -webkit-mask-position: center; mask-position: center }
2103
+ /* a Jam view line's device, as it reads, with its icon */
2104
+ .jm-dev { display: inline-flex; align-items: center; gap: 3px; vertical-align: -2px }
@@ -51,7 +51,9 @@ export interface Busy { busy: boolean; unsaved: boolean; why: Why[] }
51
51
  /** `mv:theme` - the shell's `play || slides || viewTheme === 'dark'` (A2.14 #26). */
52
52
  export interface Theme { dark: boolean }
53
53
  /** `mv:menu` - at most 40, no separators in 0.1 (A2.7). */
54
- export interface MenuItem { id: string; group: 'view' | 'jam'; label: string; hint?: string; checked?: boolean }
54
+ /** `group: 'file'` (app 1.1, spec 31): an item for the File menu under the canvas's name - a shell offers one only to an
55
+ * app that has `exportPdf` (an older app refuses a menu naming a group it does not know). */
56
+ export interface MenuItem { id: string; group: 'view' | 'jam' | 'file'; label: string; hint?: string; checked?: boolean }
55
57
  /** `mv:app-state` (main to canvas). `untrusted`: stop every microphone track (A2.14 #13). A4 adds `mv:open` and
56
58
  * `mv:capture`; this stays these three (A4.6 #29). */
57
59
  export type AppState = 'shown' | 'hidden' | 'untrusted'
@@ -71,10 +73,11 @@ export type MenuIn = (typeof MENU_IN)[number]
71
73
  export interface MenuClick { id: string; in?: MenuIn }
72
74
  /**
73
75
  * The ids main sends of its own, never in the page's `mv:menu`: the tab's right-click Mark All as Seen (A2.4's
74
- * channels table: "Mark all as seen sends `mv:menu-click mark-all-seen` to the canvas"). A shell that does not know
75
- * one does nothing with it.
76
+ * channels table: "Mark all as seen sends `mv:menu-click mark-all-seen` to the canvas") and Resolve All Comments
77
+ * (0.31, spec 31 B.1: sent only to a canvas whose features list `resolve-all`). A shell that does not know one does
78
+ * nothing with it.
76
79
  */
77
- export const APP_MENU_IDS = ['mark-all-seen'] as const
80
+ export const APP_MENU_IDS = ['mark-all-seen', 'resolve-all-comments'] as const
78
81
 
79
82
  /**
80
83
  * `mv:present` (main to canvas; on the wire `{ doc, ...Present }`, stamped by main like `mv:app-state`): show the
@@ -157,6 +160,12 @@ export const CANVAS_CHANNELS = {
157
160
  opened: 'mv:opened',
158
161
  /** A4: a live picture of the document's own view - an invoke (A4.6 #35) */
159
162
  capture: 'mv:capture',
163
+ /** spec 31 D1: a `marver://` link into a tab already open - the navigation command (main to canvas), never a reload */
164
+ show: 'mv:show',
165
+ /** spec 31 D3: the shell showed what `marver show` asked - its tab to the front of the window (canvas to main) */
166
+ front: 'mv:front',
167
+ /** app 1.1 (spec 31): a finished deck PDF saved where the person says - an invoke carrying only the job id */
168
+ exportPdf: 'mv:export-pdf',
160
169
  } as const
161
170
 
162
171
  /** Bounds main checks again (A2.14 #19): unknown fields are stripped, a known one of the wrong type or past its bound refuses the message. */
@@ -216,6 +225,14 @@ export const FEATURE = {
216
225
  open: 'open',
217
226
  /** 0.29.0 (A4.6 #33-#37): the shell asks `mv:capture` for live pictures and the server takes `POST /api/jam/picture/live` */
218
227
  capture: 'capture',
228
+ /** 0.31.0 (spec 31 D1, D3): the shell takes `mv:show` (a deep link's place, moved to or noticed over unsent words)
229
+ * and asks `mv:front` once it showed a `marver show` */
230
+ show: 'show',
231
+ /** 0.31.0 (spec 31 B.1): the shell handles `mv:menu-click resolve-all-comments` - every open thread on the canvas resolved,
232
+ * but what Jam is at work on, with its Undo. The app offers the tab menu's Resolve All Comments only to a canvas that says so */
233
+ resolveAll: 'resolve-all',
234
+ /** 0.31.0 (spec 31 Part A): the server makes deck PDFs (`/__mv/api/pdf`) and the shell asks `mv:export-pdf` to save one */
235
+ pdf: 'pdf',
219
236
  } as const
220
237
  export type Feature = (typeof FEATURE)[keyof typeof FEATURE]
221
238
 
@@ -339,6 +356,19 @@ export type CaptureWhy = (typeof CAPTURE_WHY)[number]
339
356
  * size in device pixels, its long side at most `BOUNDS.captureLong`. */
340
357
  export type CaptureAnswer = { ok: true; png: Uint8Array; width: number; height: number } | { ok: false; why: CaptureWhy }
341
358
 
359
+ /** A deck PDF job's id (src/server/pdf.ts JOB_ID): 128 random bits, base64url. */
360
+ export const PDF_JOB = /^[A-Za-z0-9_-]{22}$/
361
+ /** The largest PDF main fetches and writes (spec 31: 200 MB). */
362
+ export const PDF_MAX = 200 * 2 ** 20
363
+ /** `mv:export-pdf` (canvas to main, an invoke; on the wire `{ doc, p }`): the finished job to save. */
364
+ export interface ExportPdfAsk { job: string }
365
+ /** Why nothing was saved: `cancelled` - the person closed the save panel; `untrusted` - the document is not the admitted,
366
+ * trusted one (before the panel or after it); `bad-job` - no such finished job on this canvas; `too-large` - past
367
+ * `PDF_MAX`; `failed` - the fetch or the write failed. */
368
+ export const EXPORT_PDF_WHY = ['cancelled', 'untrusted', 'bad-job', 'too-large', 'failed'] as const
369
+ export type ExportPdfWhy = (typeof EXPORT_PDF_WHY)[number]
370
+ export type ExportPdfAnswer = { ok: true } | { ok: false; why: ExportPdfWhy }
371
+
342
372
  /**
343
373
  * `window.marverApp`, exposed by the canvas preload to verified local canvases. Typed methods only: a page never
344
374
  * names a channel. The six methods of 0.1 are required (marver-app.ts checks them); every A3 and A4 one is optional.
@@ -382,8 +412,23 @@ export interface MarverAppV1 {
382
412
  * answers `untrusted` with no IPC; main answers `hidden`, `busy`, `bounds`, `empty`, `timeout` or `stale` otherwise
383
413
  */
384
414
  capture?(a: CaptureAsk): Promise<CaptureAnswer>
415
+ /**
416
+ * spec 31 D1 (app 1.1): main's navigation command for a `marver://` link into this tab - the hash's own targets
417
+ * (shared/deep-link.ts `ShowTarget`), checked by the preload - null for the canvas's own board (a link whose place
418
+ * the app could not take); never a reload or a hash replaced under the page
419
+ */
420
+ onShow?(fn: (t: ShowTarget | null) => void): () => void
421
+ /** spec 31 D3 (app 1.1): this document showed a `marver show` - main brings its tab and the window forward */
422
+ front?(): void
423
+ /**
424
+ * app 1.1 (spec 31): save a finished deck PDF. Only the job id crosses: main fetches the file itself from the admitted
425
+ * canvas origin, shows the save panel, checks the document again, and writes the file where the panel says
426
+ */
427
+ exportPdf?(a: ExportPdfAsk): Promise<ExportPdfAnswer>
385
428
  }
386
429
 
430
+ import type { ShowTarget } from './deep-link.ts'
431
+
387
432
  /** Main's words for a reason (the hang sheet, the unsaved pill); `heights` is never named (A2.14 #18). */
388
433
  export const WHY_WORDS: Record<Why, string | null> = {
389
434
  'capture-recording': 'a capture being recorded',
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Where an auto board puts the frames it has not placed yet (friction log #15), one rule for the canvas (store.ts, as it
3
+ * loads a board) and the deck PDF's plan (pdf.ts), so a PDF's reading order is the one Play walks (spec 31 #2).
4
+ *
5
+ * Saved positions are kept. A grouped newcomer lands right of its variant group's rightmost node, on its row; any other
6
+ * goes past the board's right edge, on the top row - never at (0, 0) over a frame already there (the old published
7
+ * everything-board bug). Pure: the caller says each frame's size and builds its node.
8
+ */
9
+ export interface PlacedNode { frame: string; x: number; y: number; w: number }
10
+ export interface NewcomerFrame { id: string; variantGroup?: string }
11
+
12
+ /** Append a node for every frame in `frames` not on `nodes` yet, in `frames`' order. Mutates and returns `nodes`. */
13
+ export function placeNewcomers<N extends PlacedNode, F extends NewcomerFrame>(
14
+ nodes: N[], frames: readonly F[], size: (f: F) => { w: number; h: number }, make: (f: F, x: number, y: number, w: number, h: number) => N,
15
+ ): N[] {
16
+ const placed = new Set(nodes.map((n) => n.frame))
17
+ const groupOf = new Map(frames.map((f) => [f.id, f.variantGroup]))
18
+ let maxX = nodes.reduce((a, n) => Math.max(a, n.x + n.w), 0)
19
+ for (const f of frames) {
20
+ if (placed.has(f.id)) continue
21
+ placed.add(f.id)
22
+ const { w, h } = size(f)
23
+ const sibling = f.variantGroup
24
+ ? nodes.filter((n) => groupOf.get(n.frame) === f.variantGroup).reduce<N | null>((a, n) => (!a || n.x + n.w > a.x + a.w ? n : a), null)
25
+ : null
26
+ const x = sibling ? sibling.x + sibling.w + Math.max(140, sibling.w * 0.12) : nodes.length ? maxX + 96 : 0
27
+ const y = sibling ? sibling.y : 0
28
+ nodes.push(make(f, x, y, w, h))
29
+ maxX = Math.max(maxX, x + w)
30
+ }
31
+ return nodes
32
+ }
@@ -66,6 +66,9 @@ export const readTitle = (v: unknown): string | undefined => {
66
66
  }
67
67
  /** Title Case off a slug - the display when no title is set ("old-stuff" → "Old Stuff"). */
68
68
  export const humanize = (s: string): string => s.replace(/-/g, ' ').replace(/(^|\s)\S/g, (c) => c.toUpperCase())
69
+ /** The canvas's name on screen: a name someone wrote (a capital or a space in it - `name: "iPad Lab"`) stays exactly as
70
+ * written; a slug-like one (a folder's name, `my-repo`) is humanized ("My Repo") (spec 31 G). */
71
+ export const canvasLabel = (name: string): string => (/[A-Z\s]/.test(name) ? name : humanize(name))
69
72
  /** What a board, folder or scene is called on screen: its title, else its humanized slug. */
70
73
  export const labelOf = (name: string, title?: string): string => title ?? humanize(name)
71
74
 
@@ -30,6 +30,10 @@ export const TYPE_ROLES: Record<BoardType, string> = {
30
30
  export const TYPE_GRAMMAR = /^[a-z][a-z-]{0,31}$/
31
31
  /** A type off a file: the word when it is on-grammar, else absent. */
32
32
  export const readType = (v: unknown): string | undefined => (typeof v === 'string' && TYPE_GRAMMAR.test(v) ? v : undefined)
33
+ /** Words read as another type (spec 31): `slides` is a deck - for the type only; whether a board plays as slides stays
34
+ * its publish policy's. */
35
+ export const TYPE_ALIASES: Readonly<Record<string, KnownType>> = { slides: 'deck' }
36
+ const alias = (v: unknown): unknown => (typeof v === 'string' && Object.hasOwn(TYPE_ALIASES, v) ? TYPE_ALIASES[v] : v)
33
37
  /** A type this Marver draws. */
34
38
  export const knownType = (v: unknown): KnownType | undefined =>
35
39
  (BOARD_TYPES as readonly string[]).includes(v as string) ? (v as KnownType) : undefined
@@ -37,8 +41,8 @@ export const knownType = (v: unknown): KnownType | undefined =>
37
41
  /** A board's type: its own when it states one (an unknown word reads as plain - the board spoke
38
42
  * for itself), else its folder's, else that folder's parent's, else plain. */
39
43
  export function resolveType(own: unknown, folder?: unknown, parent?: unknown): BoardType {
40
- if (readType(own)) return knownType(own) ?? 'plain'
41
- return knownType(folder) ?? knownType(parent) ?? 'plain'
44
+ if (readType(own)) return knownType(alias(own)) ?? 'plain'
45
+ return knownType(alias(folder)) ?? knownType(alias(parent)) ?? 'plain'
42
46
  }
43
47
 
44
48
  /** The publish type a board's type proposes when its publish row names none - how a board