@marver-design/marver 0.28.0 → 0.30.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 (105) hide show
  1. package/CHANGELOG.md +103 -0
  2. package/README.md +4 -3
  3. package/dist/{anchor-check-PHUOFj1N.mjs → anchor-check-c52IDkiQ.mjs} +1 -1
  4. package/dist/{build-BsAyLMT1.mjs → build-C3mUtjEn.mjs} +7 -4
  5. package/dist/{capture-DdZ6xgoz.mjs → capture-DEtM4qm5.mjs} +168 -5
  6. package/dist/cli.mjs +11 -11
  7. package/dist/{comments-CrBHPEQl.mjs → comments-XNhMmSSu.mjs} +2 -2
  8. package/dist/{connectors-MR9d-EBP.mjs → connectors-DekQvKt9.mjs} +3 -1
  9. package/dist/{daemon-C5dg2R-V.mjs → daemon-B0Wi1OQ3.mjs} +30 -29
  10. package/dist/{dev-D7YS7iT2.mjs → dev-5dlxoW28.mjs} +19 -14
  11. package/dist/{init-WE5lQkQL.mjs → init-CYlFaRzG.mjs} +1 -1
  12. package/dist/logo-CXY-1yrn.mjs +305 -0
  13. package/dist/{ls-BZ5TAtd5.mjs → ls-NqmePKOf.mjs} +1 -1
  14. package/dist/{marks-Kmdab_5w.mjs → marks-BnNANic9.mjs} +20 -1
  15. package/dist/{marks-Dyn6tmjp.mjs → marks-DBp3h1Mc.mjs} +2 -5
  16. package/dist/{marver-id-gate-D-R0hSt_.mjs → marver-id-gate-vBLb_Icb.mjs} +1 -1
  17. package/dist/{perf-Cn5LiRaY.mjs → perf-6MOTHxay.mjs} +751 -122
  18. package/dist/perf-BCxAo0IS.mjs +1743 -0
  19. package/dist/{plugin-C_0yb-Fq.mjs → plugin-CXRoMA8g.mjs} +1382 -810
  20. package/dist/{poster-DHi6I1fO.mjs → poster-CYmCa00B.mjs} +1 -1
  21. package/dist/{profile-jIS6BcAs.mjs → profile-B1FKOM1e.mjs} +1 -1
  22. package/dist/{publish-bakes-r4PEZuPl.mjs → publish-bakes-C_2ZtHou.mjs} +3 -3
  23. package/dist/{queue-c-6aTHEz.mjs → queue-DeSQm24g.mjs} +29 -14
  24. package/dist/{recover-nrLEVLyJ.mjs → recover-XD8iXJOj.mjs} +2 -2
  25. package/dist/{serve-Dp3nHstu.mjs → serve-DQv3Ti6X.mjs} +8 -4
  26. package/dist/{session-DyVE7cCk.mjs → session-VDJfXEEm.mjs} +1 -1
  27. package/dist/{share-Ce4tP7ji.mjs → share-Bu_kuOKL.mjs} +1 -1
  28. package/dist/{shot-BrRtqaiS.mjs → shot-CRRGgxru.mjs} +3 -3
  29. package/dist/{slots-CFNnegCc.mjs → slots-Dn4Onb0V.mjs} +101 -3
  30. package/dist/{sync-CQdGARJ9.mjs → sync-CMozOwZ0.mjs} +1 -1
  31. package/docs/app.md +194 -0
  32. package/docs/boards-and-folders.md +11 -0
  33. package/docs/jam-session.md +12 -3
  34. package/docs/live-jam.md +3 -0
  35. package/docs/performance.md +99 -19
  36. package/docs/publish.md +7 -0
  37. package/package.json +1 -1
  38. package/src/client/frame-host/bridge.js +17 -8
  39. package/src/client/frame-host/inplace.ts +124 -0
  40. package/src/client/frame-host/inspect.d.ts +1 -0
  41. package/src/client/frame-host/inspect.js +13 -4
  42. package/src/client/frame-host/main.tsx +12 -3
  43. package/src/client/frame-host/messages.ts +85 -0
  44. package/src/client/frame-host/signals.d.ts +15 -0
  45. package/src/client/frame-host/signals.js +219 -0
  46. package/src/client/recorder-level.ts +41 -0
  47. package/src/client/shell/App.tsx +158 -88
  48. package/src/client/shell/BoardList.tsx +103 -48
  49. package/src/client/shell/Comments.tsx +71 -46
  50. package/src/client/shell/ContextMenu.tsx +8 -6
  51. package/src/client/shell/JamSurface.tsx +187 -71
  52. package/src/client/shell/LockedApp.tsx +19 -3
  53. package/src/client/shell/Play.tsx +110 -62
  54. package/src/client/shell/StatusPicker.tsx +19 -9
  55. package/src/client/shell/Toolbar.tsx +15 -7
  56. package/src/client/shell/api.ts +25 -7
  57. package/src/client/shell/app-bridge.ts +23 -9
  58. package/src/client/shell/app-perf.ts +31 -1
  59. package/src/client/shell/canvas/Canvas.tsx +17 -6
  60. package/src/client/shell/canvas/FrameNode.tsx +25 -12
  61. package/src/client/shell/canvas/Sticky.tsx +4 -2
  62. package/src/client/shell/canvas/ctl.ts +2 -0
  63. package/src/client/shell/canvas/ready-watch.ts +4 -0
  64. package/src/client/shell/canvas/sleep.ts +2 -0
  65. package/src/client/shell/canvas/updates.ts +13 -6
  66. package/src/client/shell/commands.ts +765 -0
  67. package/src/client/shell/comments-store.ts +56 -27
  68. package/src/client/shell/goto.ts +15 -9
  69. package/src/client/shell/jam-capture.ts +39 -15
  70. package/src/client/shell/jam-keys.ts +303 -111
  71. package/src/client/shell/jam-lane.tsx +19 -12
  72. package/src/client/shell/jam-lines.ts +10 -1
  73. package/src/client/shell/jam-panel.tsx +68 -53
  74. package/src/client/shell/jam-queue.ts +6 -1
  75. package/src/client/shell/jam-session.tsx +41 -37
  76. package/src/client/shell/jam-state.ts +28 -5
  77. package/src/client/shell/jam-surface-parts.tsx +8 -6
  78. package/src/client/shell/jam-ui.tsx +12 -5
  79. package/src/client/shell/jam-voice.ts +4 -2
  80. package/src/client/shell/live-picture.ts +134 -0
  81. package/src/client/shell/main.tsx +7 -1
  82. package/src/client/shell/marks-ui.tsx +11 -0
  83. package/src/client/shell/open-item.ts +83 -0
  84. package/src/client/shell/open-resolve.ts +50 -0
  85. package/src/client/shell/perf.ts +51 -5
  86. package/src/client/shell/recorder-core.ts +4 -1
  87. package/src/client/shell/recorder-hmr.ts +36 -0
  88. package/src/client/shell/recorder-reloads.ts +264 -0
  89. package/src/client/shell/recorder-seams.ts +116 -0
  90. package/src/client/shell/recorder-self.ts +73 -0
  91. package/src/client/shell/recorder-signals-core.ts +139 -0
  92. package/src/client/shell/recorder-signals.ts +485 -0
  93. package/src/client/shell/recorder.ts +115 -41
  94. package/src/client/shell/store.ts +62 -24
  95. package/src/client/shell/styles.css +2 -0
  96. package/src/client/shell/whiteout-probes.ts +3 -1
  97. package/src/client/stage/main.tsx +39 -12
  98. package/src/shared/app-api.ts +201 -9
  99. package/src/shared/app-perf.ts +103 -8
  100. package/src/shared/app-report.ts +586 -0
  101. package/src/shared/perf-records.ts +445 -0
  102. package/src/shared/perf-run.ts +6 -2
  103. package/templates/instructions/jam.md +4 -0
  104. package/dist/live-Cgzsicwi.mjs +0 -4
  105. package/dist/perf-jam-QxD_UnzN.mjs +0 -635
@@ -12,6 +12,7 @@ import { ROUTE } from '../const.ts'
12
12
  import { ALL_SCENES } from '../../shared/board-tree.ts'
13
13
  import { UNPLACED } from './hash.ts'
14
14
  import { api as request, canvasStopped, scoped, stoppedLink, useLink } from './api.ts'
15
+ import type { CmdHandle } from './commands.ts'
15
16
 
16
17
  /** What the Not on a board view says when asked for a comment: a note needs a board to live on. */
17
18
  export const NO_COMMENTS_HERE = 'pin it on a board to comment'
@@ -59,22 +60,26 @@ interface CommentsState {
59
60
  * path as the poll, so dedup + the reply notification behave identically. ANY board:
60
61
  * notifications must reach the user wherever they are on the canvas. */
61
62
  poke(board?: string): void
63
+ /** Read a board's log now and answer whether the read succeeded (spec 28 A4.6 #30): `poke`'s read, awaited, its
64
+ * events merged - the board, the open thread and a draft stay as they are (never `load`, which clears them first). */
65
+ refresh(board: string): Promise<boolean>
62
66
  /** A thread by id, from any board's log - one sweep first when it is not loaded yet. */
63
67
  findThread(id: string): Promise<Thread | null>
64
- /** `board` routes the write to a thread's ORIGIN log; default = the active board. */
65
- send(events: CommentEvent[], board?: string): Promise<boolean>
66
- create(body: string): Promise<void>
68
+ /** `board` routes the write to a thread's ORIGIN log; default = the active board. `h` (spec 30): the command behind the
69
+ * write, ended here on its answer - `done`, `failed signed-out` on a 401, else `failed send-failed`. */
70
+ send(events: CommentEvent[], board?: string, h?: CmdHandle): Promise<boolean>
71
+ create(body: string, h?: CmdHandle): Promise<void>
67
72
  reply(threadId: string, body: string): Promise<void>
68
- replyOk(threadId: string, body: string): Promise<boolean>
69
- resolve(threadId: string, reopen?: boolean): Promise<void>
73
+ replyOk(threadId: string, body: string, h?: CmdHandle): Promise<boolean>
74
+ resolve(threadId: string, reopen?: boolean, h?: CmdHandle): Promise<void>
70
75
  setMode(on: boolean): void
71
76
  setShow(show: boolean): void
72
77
  setShowAnchor(on: boolean): void
73
78
  setActive(id: string | null): void
74
79
  setDraft(d: CommentsState['draft']): void
75
- signIn(email: string, password: string): Promise<string | null>
76
- claim(token: string, password: string, name: string, avatar?: string): Promise<string | null>
77
- saveProfile(patch: Partial<Me>): Promise<string | null>
80
+ signIn(email: string, password: string, h?: CmdHandle): Promise<string | null>
81
+ claim(token: string, password: string, name: string, avatar?: string, h?: CmdHandle): Promise<string | null>
82
+ saveProfile(patch: Partial<Me>, h?: CmdHandle): Promise<string | null>
78
83
  dismissIdentity(): void
79
84
  /** The admitted viewer's "Ask to comment" - one request into the owner's queue. */
80
85
  askToComment(): Promise<boolean>
@@ -92,6 +97,15 @@ const api = async (path: string, body?: unknown) => {
92
97
  })
93
98
  return { ok: res.ok, status: res.status, data: await res.json().catch(() => ({})) }
94
99
  }
100
+ /** An identity write and the command behind it (spec 30's `sign-in`, `claim`, `profile-save`): ok → done, the answer
101
+ * said no → `rejected`, no answer → `api`. */
102
+ const identityWrite = async (path: string, body: unknown, h?: CmdHandle) => {
103
+ try {
104
+ const res = await api(path, body)
105
+ if (res.ok) h?.done(); else h?.fail(res.status < 500 ? 'rejected' : 'api')
106
+ return res
107
+ } catch (e) { h?.fail('api'); throw e }
108
+ }
95
109
 
96
110
  export const useComments = create<CommentsState>((set, get) => {
97
111
  // replay PER BOARD, then concatenate: replay keys threads by commentId alone, so a
@@ -253,6 +267,17 @@ export const useComments = create<CommentsState>((set, get) => {
253
267
  })
254
268
  },
255
269
 
270
+ async refresh(board) {
271
+ if (!board || apiOff || board === UNPLACED) return false
272
+ try {
273
+ const r = await api(`comments/${board}`)
274
+ if (!r.ok) return false
275
+ union(stamped(r.data.events, board))
276
+ baselinedBoards.add(board)
277
+ return true
278
+ } catch { return false }
279
+ },
280
+
256
281
  async load(board) {
257
282
  // threads are frame-scoped and global - a board switch keeps them all (the same
258
283
  // frame on another board keeps its pins); only the open card and a draft reset
@@ -301,45 +326,46 @@ export const useComments = create<CommentsState>((set, get) => {
301
326
  return () => stops.forEach((f) => f())
302
327
  },
303
328
 
304
- async send(events, board) {
329
+ async send(events, board, h) {
305
330
  const target = board ?? get().board
306
- if (!target) return false
331
+ if (!target) { h?.fail('send-failed'); return false }
307
332
  // stamp the origin board BEFORE the POST: the dev server fills it at origin, but
308
333
  // the published server stores events as sent - an unstamped event would come back
309
334
  // board-less on the next load and its replies could then route to the wrong log.
310
335
  // Stamping client-side keeps the stored bytes and the optimistic copy identical.
311
336
  const stamped = events.map((e) => ({ ...e, board: e.board ?? target }))
312
- const res = await api(`comments/${target}`, { events: stamped })
313
- if (res.status === 401) { set({ needsIdentity: true }); return false }
337
+ const res = await api(`comments/${target}`, { events: stamped }).catch((e: unknown) => { h?.fail('send-failed'); throw e })
338
+ if (res.status === 401) { h?.fail('signed-out'); set({ needsIdentity: true }); return false }
314
339
  // any other refusal gets said out loud - a silent dead Enter key reads as a bug
315
340
  // (the canonical case: a signed-in viewer on a read-only board)
316
341
  if (!res.ok) {
342
+ h?.fail('send-failed')
317
343
  const { useStore } = await import('./store.ts')
318
344
  useStore.getState().toast(String((res.data as any)?.error ?? 'comment rejected'))
319
345
  }
320
346
  // union only what the server took - a rejected send must not leave phantoms; the
321
347
  // store is global now, so an accepted write lands regardless of the viewed board
322
348
  // (client ids keep the eventual SSE/poll echo idempotent)
323
- if (res.ok) union(stamped)
349
+ if (res.ok) { union(stamped); h?.done() }
324
350
  return res.ok
325
351
  },
326
352
 
327
- async create(body) {
353
+ async create(body, h) {
328
354
  const { draft, me } = get()
329
- if (!draft || !body.trim()) return
355
+ if (!draft || !body.trim()) { h?.fail('send-failed'); return }
330
356
  const id = uuid()
331
357
  const mentions = mentionsIn(body.trim(), mentionPeople(get().events, me ?? undefined))
332
358
  const ok = await get().send([{
333
359
  id: uuid(), ts: Date.now(), type: 'create', commentId: id,
334
360
  nodeKey: draft.nodeKey, frame: draft.frame, anchor: draft.anchor,
335
361
  author: postAuthor(me), body: body.trim(), ...(mentions ? { mentions } : {}),
336
- }], draft.board)
362
+ }], draft.board, h)
337
363
  if (ok) set({ draft: null, active: id, commentMode: false })
338
364
  },
339
365
 
340
366
  async reply(threadId, body) { await get().replyOk(threadId, body) },
341
- async replyOk(threadId, body) {
342
- if (!body.trim()) return false
367
+ async replyOk(threadId, body, h) {
368
+ if (!body.trim()) { h?.fail('send-failed'); return false }
343
369
  // route to the thread's ORIGIN log - the viewer may be reading it from another
344
370
  // board (frame-scoped display); a reply landing in the wrong log would fork it
345
371
  const origin = get().threads.find((t) => t.id === threadId)?.board
@@ -347,12 +373,15 @@ export const useComments = create<CommentsState>((set, get) => {
347
373
  return get().send([{
348
374
  id: uuid(), ts: Date.now(), type: 'reply', commentId: uuid(), parentId: threadId,
349
375
  author: postAuthor(get().me), body: body.trim(), ...(mentions ? { mentions } : {}),
350
- }], origin)
376
+ }], origin, h)
351
377
  },
352
378
 
353
- async resolve(threadId, reopen = false) {
379
+ async resolve(threadId, reopen = false, h) {
354
380
  const origin = get().threads.find((t) => t.id === threadId)?.board
355
- await get().send([{ id: uuid(), ts: Date.now(), type: reopen ? 'reopen' : 'resolve', commentId: threadId }], origin)
381
+ // `comment-resolve`'s one code: a resolve refused for any reason did not send
382
+ const sent = await get().send([{ id: uuid(), ts: Date.now(), type: reopen ? 'reopen' : 'resolve', commentId: threadId }], origin)
383
+ .catch((e: unknown) => { h?.fail('send-failed'); throw e })
384
+ if (sent) h?.done(); else h?.fail('send-failed')
356
385
  },
357
386
 
358
387
  async findThread(id) {
@@ -380,20 +409,20 @@ export const useComments = create<CommentsState>((set, get) => {
380
409
  },
381
410
  dismissIdentity() { set({ needsIdentity: false }) }, // inviteToken survives dismissal - commenting later reopens the claim
382
411
 
383
- async signIn(email, password) {
384
- const res = await api('auth/signin', { email, password })
412
+ async signIn(email, password, h) {
413
+ const res = await identityWrite('auth/signin', { email, password }, h)
385
414
  if (!res.ok) return res.data?.error ?? 'sign-in failed'
386
415
  set({ me: res.data.user, needsIdentity: false })
387
416
  return null
388
417
  },
389
- async claim(token, password, name, avatar) {
390
- const res = await api('auth/claim', { token, password, name, avatar })
418
+ async claim(token, password, name, avatar, h) {
419
+ const res = await identityWrite('auth/claim', { token, password, name, avatar }, h)
391
420
  if (!res.ok) return res.data?.error ?? 'claim failed'
392
421
  set({ me: res.data.user, needsIdentity: false, inviteToken: null })
393
422
  return null
394
423
  },
395
- async saveProfile(patch) {
396
- const res = await api('profile', patch)
424
+ async saveProfile(patch, h) {
425
+ const res = await identityWrite('profile', patch, h)
397
426
  if (!res.ok) return res.data?.error ?? 'could not save - try again'
398
427
  set({ me: res.data.user })
399
428
  return null
@@ -6,10 +6,11 @@
6
6
  import { fetchMembership, useStore } from './store.ts'
7
7
  import { UNPLACED } from './hash.ts'
8
8
  import { canvasCtl } from './canvas/ctl.ts'
9
+ import { endOnCamera, endOnLoad, type CmdHandle } from './commands.ts'
9
10
 
10
11
  /** Navigate to a frame id. `carry` keeps interact mode across the hop (a link inside an
11
12
  * interacting frame walks a flow - it must not eject you to design mode). */
12
- export function goTo(target: string, carry = false): void {
13
+ export function goTo(target: string, carry = false, h?: CmdHandle): void {
13
14
  const s = useStore.getState()
14
15
  const existing = s.nodes.find((n) => n.frame === target && !n.missing)
15
16
  if (existing) {
@@ -17,7 +18,8 @@ export function goTo(target: string, carry = false): void {
17
18
  s.select(existing.key)
18
19
  if (carry) s.setInteract(existing.key)
19
20
  fitLater(existing.key, seq)
20
- } else void gotoAcrossBoards(target, carry)
21
+ if (h) endOnCamera(h) // the recorder's (spec 30): the camera lands
22
+ } else void gotoAcrossBoards(target, carry, h)
21
23
  }
22
24
 
23
25
  /** A data-goto whose target frame is not on the current board follows the frame HOME:
@@ -27,12 +29,12 @@ export function goTo(target: string, carry = false): void {
27
29
  * for unpinned targets); an id the manifest doesn't know stays a toast. Every goto
28
30
  * bumps `gotoSeq` so a slow older resolution can never override newer navigation. */
29
31
  let gotoSeq = 0
30
- async function gotoAcrossBoards(target: string, carry: boolean) {
32
+ async function gotoAcrossBoards(target: string, carry: boolean, h?: CmdHandle) {
31
33
  const s = useStore.getState()
32
34
  const from = s.board
33
35
  // an id the manifest doesn't know resolves NOWHERE - a tombstone pin on some board
34
36
  // must not send us on a trip that ends in a silent timeout
35
- if (!s.manifest?.frames.some((f) => f.id === target)) return s.toast(`unknown goto target "${target}"`)
37
+ if (!s.manifest?.frames.some((f) => f.id === target)) { h?.fail('no-target'); return s.toast(`unknown goto target "${target}"`) }
36
38
  const seq = navigated()
37
39
  let home: string | null = null
38
40
  try {
@@ -40,19 +42,22 @@ async function gotoAcrossBoards(target: string, carry: boolean) {
40
42
  } catch {
41
43
  // a transport failure is NOT proof the frame is unpinned - spawning here would
42
44
  // recreate the board mutation this function exists to prevent
45
+ h?.fail('no-target')
43
46
  return useStore.getState().toast(`goto: could not read the boards - try again`)
44
47
  }
45
- if (seq !== gotoSeq) return // superseded by newer navigation
48
+ if (seq !== gotoSeq) { h?.cancel('superseded'); return } // superseded by newer navigation
46
49
  if (!home) {
47
50
  // no curated board pins it - the original prototype behavior: spawn beside you
48
51
  const st = useStore.getState()
49
52
  const node = st.spawn(target)
50
- if (!node) return st.toast(`unknown goto target "${target}"`)
53
+ if (!node) { h?.fail('no-target'); return st.toast(`unknown goto target "${target}"`) }
51
54
  st.select(node.key)
52
55
  if (carry) st.setInteract(node.key)
53
56
  fitLater(node.key, seq)
57
+ if (h) endOnCamera(h)
54
58
  return
55
59
  }
60
+ if (h) endOnLoad(h, home, 'visible') // the recorder's (spec 30): the target board's `visible`
56
61
  await landOn(home, target, carry, seq, from)
57
62
  }
58
63
 
@@ -72,9 +77,10 @@ export const isLatest = (seq: number): boolean => seq === gotoSeq
72
77
  * notification's View: the switch is navigation `nav`'s (a new one, unless the caller took it at its own start, before
73
78
  * a lookup), and true only once it landed with nothing newer since. What the caller does on the board - select, set a
74
79
  * mode, enter play, move the camera - waits for true: a switch a newer navigation cancelled comes back too, and may
75
- * find the board it asked for, the newer one's by then. */
76
- export async function switchFor(board: string, nav: number = navigated()): Promise<boolean> {
77
- await useStore.getState().switchBoard(board)
80
+ * find the board it asked for, the newer one's by then. `mayCommit`: the caller's own condition, read just before the
81
+ * board commits - false keeps the board shown (a notice's request, jam-keys.ts toBoard). */
82
+ export async function switchFor(board: string, nav: number = navigated(), mayCommit?: () => boolean): Promise<boolean> {
83
+ await useStore.getState().switchBoard(board, mayCommit)
78
84
  return isLatest(nav) && useStore.getState().board === board
79
85
  }
80
86
  /** The camera to a node once it is drawn - unless a newer navigation has it by then. */
@@ -25,6 +25,7 @@ import { onStageSize, stageSize } from './stage-size.ts'
25
25
  import { api, holdsReload } from './api.ts'
26
26
  import { unsavedWhen, workChanged } from './unsaved.ts'
27
27
  import { bytesOf } from './recorder-core.ts'
28
+ import { LIVE_PICTURE_MS, liveAsk, takeLive } from './live-picture.ts'
28
29
 
29
30
  const csrf = () => /(?:^|;\s*)mv_c=([\w-]+)/.exec(document.cookie)?.[1] ?? ''
30
31
  const now = () => performance.timeOrigin + performance.now()
@@ -94,8 +95,9 @@ interface Cap {
94
95
  pictures: string[]
95
96
  probes: number // probe answers still out
96
97
  shots: number // picture requests still out
97
- /** its timing (spec 27a Part D): when E was pressed, the wait for its last words, each picture's time, the missing ones */
98
- timing?: { endAt?: number; wordsMs?: number; pics: number[]; late: number; failed: number }
98
+ /** its timing (spec 27a Part D): when E was pressed, the wait for its last words, each picture's time, the missing ones;
99
+ * `live` (A4.6 #36): the app's pictures of the stage kept, the ones that failed, and the renders that replaced them */
100
+ timing?: { endAt?: number; wordsMs?: number; pics: number[]; late: number; failed: number; live?: { count: number; failed: number; fellBack: number } }
99
101
  shotFrames: string[] // frames pictured (or being pictured) in it: an automatic picture is taken once per frame
100
102
  review?: boolean // ended with ⇧E: it waits for its read-back (E: queued once sealed)
101
103
  endShot?: boolean // its end pictures were asked for (once its steps were all in)
@@ -520,12 +522,20 @@ let pointerAt: { key: string; at: number } | null = null
520
522
 
521
523
  // ---- pictures ------------------------------------------------------------------------------------------
522
524
 
525
+ /**
526
+ * One picture of `frame` - one bounded operation with one settlement, counted in `shots` from its start, so the seal
527
+ * waits for it (A4.6 #36): in the Mac app, when the shot is eligible (live-picture.ts, decided here at the trigger), the
528
+ * app's picture of the stage and its upload, under one deadline; on any failure there - and everywhere else - the
529
+ * server's render, as in 0.28. One step at the end: a picture (`source: 'live'` for a live one), or the render's
530
+ * missing step when that fails too; a live failure alone adds none.
531
+ */
523
532
  function shoot(id: string, frame: string, why: 'key' | 'pick' | 'end', key?: string) {
524
533
  const c = capOf(id)
525
534
  if (!c || c.pictures.length + c.shots >= MAX_PICTURES) return
526
535
  // each picture is a render on the server, and the capture waits for it as it ends: a point or the end
527
536
  // pictures a frame once - only I asks for another
528
537
  if (why !== 'key' && c.shotFrames.includes(frame)) return
538
+ const live = liveAsk(frame)
529
539
  // the instance pictured is the one this frame is about (its size for the run's pictures)
530
540
  // (an I picture is a touch at this instant: a hover from before it, answering late, never overrides it)
531
541
  const touchAt = now()
@@ -543,29 +553,43 @@ function shoot(id: string, frame: string, why: 'key' | 'pick' | 'end', key?: str
543
553
  const theme = st.play && st.play.at === frame ? st.play.theme : n?.theme ?? st.viewTheme
544
554
  mutate((s) => { const x = s.caps[id]; if (x) x.shots += 1 })
545
555
  const t0 = performance.now()
546
- const done = (pid: string | null, late: boolean) => {
556
+ const done = (pid: string | null, late: boolean, source?: 'live') => {
547
557
  mutate((s) => {
548
558
  const x = s.caps[id]
549
559
  if (!x) return
550
560
  x.shots -= 1
551
561
  const tm = (x.timing ??= { pics: [], late: 0, failed: 0 })
552
562
  if (pid) tm.pics.push(Math.round(performance.now() - t0)); else if (late) tm.late++; else tm.failed++
553
- if (pid) { x.pictures.push(pid); x.steps.push({ at, frame, event: 'picture', id: pid, why }) }
563
+ if (live) { const l = (tm.live ??= { count: 0, failed: 0, fellBack: 0 }); if (source) l.count++; else { l.failed++; if (pid) l.fellBack++ } }
564
+ if (pid) { x.pictures.push(pid); x.steps.push({ at, frame, event: 'picture', id: pid, why, ...(source ? { source } : {}) }) }
554
565
  else x.steps.push({ at, frame, event: 'missing', what: `no picture of ${frame} - ${late ? `it took over ${PICTURE_MS / 1000} s` : 'the render failed'}` })
555
566
  })
556
567
  trySeal(id)
557
568
  }
569
+ const render = () => {
570
+ const ctl = new AbortController()
571
+ const timer = setTimeout(() => ctl.abort(), PICTURE_MS)
572
+ // settled exactly once - a picture, or a missing one - whatever fails: the request, its body, the abort
573
+ let settled = false
574
+ const finish = (pid: string | null) => { if (settled) return; settled = true; clearTimeout(timer); done(pid, ctl.signal.aborted) }
575
+ api('jam/picture', {
576
+ method: 'POST', signal: ctl.signal, headers: { 'content-type': 'application/json', 'x-mv-c': csrf() },
577
+ body: JSON.stringify({ capture: id, frame, theme, ...(size ? { w: Math.round(size.width), h: Math.round(size.height) } : {}) }),
578
+ }).then(async (r) => (r.ok ? ((await r.json()) as { id?: string }).id ?? null : null))
579
+ .catch(() => null)
580
+ .then((pid) => finish(typeof pid === 'string' ? pid : null))
581
+ }
582
+ if (!live) { render(); return }
583
+ // the call and the upload under one deadline; a result after it is dropped, and the render starts. Sealed meanwhile
584
+ // (the page left: sealOnLeave sealed it as it stood), nothing changes
558
585
  const ctl = new AbortController()
559
- const timer = setTimeout(() => ctl.abort(), PICTURE_MS)
560
- // settled exactly once - a picture, or a missing one - whatever fails: the request, its body, the abort
561
- let settled = false
562
- const finish = (pid: string | null) => { if (settled) return; settled = true; clearTimeout(timer); done(pid, ctl.signal.aborted) }
563
- api('jam/picture', {
564
- method: 'POST', signal: ctl.signal, headers: { 'content-type': 'application/json', 'x-mv-c': csrf() },
565
- body: JSON.stringify({ capture: id, frame, theme, ...(size ? { w: Math.round(size.width), h: Math.round(size.height) } : {}) }),
566
- }).then(async (r) => (r.ok ? ((await r.json()) as { id?: string }).id ?? null : null))
567
- .catch(() => null)
568
- .then((pid) => finish(typeof pid === 'string' ? pid : null))
586
+ const timer = setTimeout(() => ctl.abort(), LIVE_PICTURE_MS)
587
+ void takeLive(live, id, () => !!capOf(id), ctl.signal).then((pid) => {
588
+ clearTimeout(timer)
589
+ if (!capOf(id)) return
590
+ if (pid && !ctl.signal.aborted) done(pid, false, 'live')
591
+ else render()
592
+ })
569
593
  }
570
594
 
571
595
  // ---- start, end, seal ----------------------------------------------------------------------------------
@@ -779,7 +803,7 @@ function timeCapture(c: Cap, interrupted: boolean) {
779
803
  const t = c.timing
780
804
  perf({ kind: 'capture', capture: c.id, ...(t?.endAt !== undefined && !interrupted ? { sealMs: performance.now() - t.endAt } : {}),
781
805
  ...(t?.wordsMs !== undefined ? { wordsWaitMs: t.wordsMs } : {}),
782
- pictures: { count: t?.pics.length ?? 0, ms: t?.pics ?? [], late: t?.late ?? 0, failed: t?.failed ?? 0 }, ...(interrupted ? { interrupted: true } : {}) }, interrupted)
806
+ pictures: { count: t?.pics.length ?? 0, ms: t?.pics ?? [], late: t?.late ?? 0, failed: t?.failed ?? 0, ...(t?.live ? { live: t.live } : {}) }, ...(interrupted ? { interrupted: true } : {}) }, interrupted)
783
807
  }
784
808
  const uploadTries = new Map<string, number>()
785
809