@marver-design/marver 0.26.0 → 0.27.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 (96) hide show
  1. package/CHANGELOG.md +158 -0
  2. package/README.md +10 -5
  3. package/dist/{anchor-check-Dg5xpNnU.mjs → anchor-check-ChdDqL5z.mjs} +1 -1
  4. package/dist/{audio-CmSRYFEs.mjs → audio-Dw1lfMdb.mjs} +14 -0
  5. package/dist/{bake-DtVlm0_F.mjs → bake-DM_uWgAA.mjs} +1 -1
  6. package/dist/{boards-DYG22tOe.mjs → boards-DlTcpF47.mjs} +1 -1
  7. package/dist/{build-C_gUgcdC.mjs → build-DZnFysGU.mjs} +4 -4
  8. package/dist/{capture-CrqvU_jh.mjs → capture-vadKjuCo.mjs} +2 -1
  9. package/dist/cli.mjs +28 -16
  10. package/dist/{comments-BqXua-XL.mjs → comments-DxOkCSNE.mjs} +4 -4
  11. package/dist/{daemon-DZo6o3rU.mjs → daemon-BSA0lV8d.mjs} +400 -274
  12. package/dist/detect-C0wpaePX.mjs +125 -0
  13. package/dist/dev-eQJhWsqg.mjs +1273 -0
  14. package/dist/dev-lock-C_FC70Mu.mjs +65 -0
  15. package/dist/exclusive-B1RtpeeP.mjs +150 -0
  16. package/dist/{init-D8DtrK_F.mjs → init-COD0x48i.mjs} +5 -3
  17. package/dist/{link-BNzLvdhI.mjs → link-DDXZVGtv.mjs} +20 -8
  18. package/dist/ls-D7O1G505.mjs +38 -0
  19. package/dist/{marks-NQi0wZJ4.mjs → marks-CWM3WJjc.mjs} +1 -1
  20. package/dist/perf-BWzQwZqj.mjs +369 -0
  21. package/dist/perf-BoDSkbEb.mjs +429 -0
  22. package/dist/perf-jam-D55U3FZK.mjs +242 -0
  23. package/dist/{plugin-CTD0rydA.mjs → plugin-C-E7omsh.mjs} +425 -66
  24. package/dist/{poster-ChjXGTS5.mjs → poster-Bx83ZYVK.mjs} +2 -1
  25. package/dist/{profile-WU9qcbIo.mjs → profile-Bh5Y5zpW.mjs} +1 -1
  26. package/dist/{publish-bakes-CEP_2NRc.mjs → publish-bakes-aljgm45S.mjs} +2 -2
  27. package/dist/{queue-BuiCKSX1.mjs → queue-CAM_vNmX.mjs} +3 -3
  28. package/dist/recover-t9Pno3u9.mjs +66 -0
  29. package/dist/{session-qZWKt_VA.mjs → session-BAaJsK5c.mjs} +1 -1
  30. package/dist/{share--oFJ1bCI.mjs → share-W5H3BNvP.mjs} +1 -1
  31. package/dist/shot-DoHLl6ig.mjs +139 -0
  32. package/dist/{shot-DqcxJibP.mjs → shot-LFhC-WYD.mjs} +343 -19
  33. package/dist/slots-DCDo3N0x.mjs +471 -0
  34. package/dist/speech-worker.mjs +40 -5
  35. package/dist/{sync-DKk-yT1V.mjs → sync-BQVlHZpx.mjs} +4 -3
  36. package/dist/{work-F5u-twpJ.mjs → work-Bp1p39kq.mjs} +4 -2
  37. package/dist/{work-VvX_JIgl.mjs → work-BroFwnup.mjs} +4 -2
  38. package/docs/boards-and-folders.md +3 -1
  39. package/docs/jam-session.md +78 -7
  40. package/docs/live-jam.md +8 -0
  41. package/docs/performance.md +262 -0
  42. package/package.json +2 -2
  43. package/src/client/content/index.tsx +3 -0
  44. package/src/client/content/video.tsx +6 -2
  45. package/src/client/frame-host/bridge.js +22 -6
  46. package/src/client/frame-host/inspect.js +8 -3
  47. package/src/client/frame-host/keys.js +6 -2
  48. package/src/client/frame-host/main.tsx +17 -5
  49. package/src/client/shell/App.tsx +188 -29
  50. package/src/client/shell/BoardList.tsx +5 -5
  51. package/src/client/shell/Comments.tsx +3 -2
  52. package/src/client/shell/JamSurface.tsx +13 -5
  53. package/src/client/shell/LockedApp.tsx +5 -5
  54. package/src/client/shell/Play.tsx +27 -15
  55. package/src/client/shell/Toolbar.tsx +17 -5
  56. package/src/client/shell/api.ts +206 -0
  57. package/src/client/shell/canvas/Canvas.tsx +30 -3
  58. package/src/client/shell/canvas/FrameNode.tsx +15 -5
  59. package/src/client/shell/canvas/admission.ts +8 -1
  60. package/src/client/shell/canvas/camera-broadcast.ts +15 -5
  61. package/src/client/shell/canvas/ctl.ts +2 -0
  62. package/src/client/shell/canvas/frame-registry.ts +28 -2
  63. package/src/client/shell/canvas/sleep.ts +4 -1
  64. package/src/client/shell/comments-store.ts +12 -4
  65. package/src/client/shell/goto.ts +22 -10
  66. package/src/client/shell/icons.tsx +2 -0
  67. package/src/client/shell/jam-capture.ts +96 -16
  68. package/src/client/shell/jam-keys.ts +51 -18
  69. package/src/client/shell/jam-lane.tsx +46 -5
  70. package/src/client/shell/jam-panel.tsx +66 -13
  71. package/src/client/shell/jam-queue.ts +3 -3
  72. package/src/client/shell/jam-session.tsx +14 -8
  73. package/src/client/shell/jam-state.ts +48 -6
  74. package/src/client/shell/jam-surface-parts.tsx +10 -6
  75. package/src/client/shell/jam-voice.ts +7 -5
  76. package/src/client/shell/legacy-links.ts +2 -2
  77. package/src/client/shell/main.tsx +4 -0
  78. package/src/client/shell/notes.ts +8 -1
  79. package/src/client/shell/perf.ts +69 -58
  80. package/src/client/shell/recorder-core.ts +183 -0
  81. package/src/client/shell/recorder.ts +565 -0
  82. package/src/client/shell/store.ts +268 -103
  83. package/src/client/shell/styles.css +54 -9
  84. package/src/client/stage/main.tsx +2 -0
  85. package/templates/AGENTS-embedded.md +22 -4
  86. package/templates/AGENTS-studio.md +22 -4
  87. package/templates/demo/dark.tsx +1 -1
  88. package/templates/demo/welcome.tsx +1 -1
  89. package/templates/instructions/jam.md +5 -3
  90. package/templates/instructions/welcome.md +6 -3
  91. package/dist/config-Cf7EjAMf.mjs +0 -292
  92. package/dist/dev-_Nlsc6v9.mjs +0 -742
  93. package/dist/dev-lock-DWSpa6nj.mjs +0 -179
  94. package/dist/perf-D6VmmJ2q.mjs +0 -68
  95. package/dist/perf-DPbLGhhO.mjs +0 -49
  96. package/dist/shot-CNbHoZ6H.mjs +0 -86
@@ -5,14 +5,16 @@ import { JamSurface, useLaneLift } from './JamSurface.tsx'
5
5
  import { JamButton } from './jam-session.tsx'
6
6
  import { useJamCapture } from './jam-capture.ts'
7
7
  import { useJamQueue } from './jam-queue.ts'
8
- import { Component, useEffect, useRef, useState, type MouseEvent as ReactMouseEvent, type ReactNode } from 'react'
9
- import { useStore, CONFIG, CANVAS_NAME, LOCKED_SHELL, PUBLISHED, SOURCE_REVEALED, logReload, takeReloadCause, addToBoard, boardLabel, cap, humanize, fetchBoardNames, landingBoard, tabTitle, hydrateBoardPolicy, landingMode, playsAsSlides, sceneLabel, type FrameEntry } from './store.ts'
8
+ import { Component, useEffect, useLayoutEffect, useRef, useState, type MouseEvent as ReactMouseEvent, type ReactNode } from 'react'
9
+ import { useStore, BOARD_GONE, CONFIG, CANVAS_NAME, DISK_WON, LOCKED_SHELL, PUBLISHED, SOURCE_REVEALED, stoppedFor, logReload, takeReloadCause, addToBoard, boardLabel, cap, humanize, fetchBoardNames, landingBoard, tabTitle, hydrateBoardPolicy, landingMode, playsAsSlides, sceneLabel, switchCount, type FrameEntry } from './store.ts'
10
10
  import { AddToBoard, BoardList } from './BoardList.tsx'
11
11
  import { ContextMenu, copyToClipboard, framePath, useContextMenu, type MenuItem } from './ContextMenu.tsx'
12
12
  import { Tip } from './Tip.tsx'
13
13
  import { PKG, ROUTE } from '../const.ts'
14
+ import { api, resumed, scoped, useLink } from './api.ts'
14
15
  import { animateLayout, Canvas, canvasCtl } from './canvas/Canvas.tsx'
15
- import { frameByWindow } from './canvas/frame-registry.ts'
16
+ import { frameByWindow, fromLiveDocument } from './canvas/frame-registry.ts'
17
+ import { recorder } from './recorder.ts'
16
18
  import { enterFocus, enterPlay, enterSlides, playCtl, PlayOverlay } from './Play.tsx'
17
19
  import { bootHash, linkTargets, parseHash, retargetBoot, UNPLACED, writeHash } from './hash.ts'
18
20
  import { isLegacyLink, landLegacy } from './legacy-links.ts'
@@ -21,7 +23,7 @@ import { ALL_SCENES, humanize as slugLabel, readTitle } from '../../shared/board
21
23
  import { CommentsController, parkThread, revealThread } from './Comments.tsx'
22
24
  import { poweredByUrl } from '../../shared/utm.ts'
23
25
  import { avatarFallback, NO_COMMENTS_HERE, useComments } from './comments-store.ts'
24
- import { goTo, isLatest, navigated, revealFrame } from './goto.ts'
26
+ import { goTo, isLatest, navigated, revealFrame, switchFor } from './goto.ts'
25
27
  import { useNotes } from './notes.ts'
26
28
  import { contentOnly } from '../../shared/frames.ts'
27
29
  import { nextToLook } from '../../shared/marks.ts'
@@ -69,6 +71,10 @@ function SceneGroup({ name, label, count, held, renaming, onRename, onPick, onCo
69
71
  export class ShellBoundary extends Component<{ children: ReactNode }, { err: Error | null }> {
70
72
  state = { err: null as Error | null }
71
73
  static getDerivedStateFromError(err: Error) { return { err } }
74
+ // the recorder's (spec 28 A1.7): the error, and the component it came from
75
+ componentDidCatch(err: Error, info: { componentStack?: string | null }) {
76
+ recorder.error({ source: 'shell', message: err.message, stack: err.stack, component: /\bat (\w+)/.exec(info.componentStack ?? '')?.[1] })
77
+ }
72
78
  render() {
73
79
  if (!this.state.err) return this.props.children
74
80
  return (
@@ -254,10 +260,10 @@ function UpdatePill() {
254
260
  const play = useStore((s) => s.play)
255
261
  useEffect(() => {
256
262
  if (PUBLISHED) return // a shared canvas never nags its viewers
257
- fetch(`${ROUTE}/api/update`)
263
+ api('update')
258
264
  .then((r) => (r.ok ? r.json() : null))
259
265
  .then((u) => {
260
- if (u?.latest && localStorage.getItem('mv-update-seen') !== u.latest) setLatest(u.latest)
266
+ if (u?.latest && localStorage.getItem(scoped('mv-update-seen')) !== u.latest) setLatest(u.latest)
261
267
  })
262
268
  .catch(() => { /* dev server gone or endpoint absent - stay quiet */ })
263
269
  }, [])
@@ -265,7 +271,7 @@ function UpdatePill() {
265
271
  // init rides along so managed files (AGENTS.md, instructions/) refresh with the code
266
272
  const cmd = `npm i -D ${PKG}@latest && npx marver init`
267
273
  const dismiss = () => {
268
- try { localStorage.setItem('mv-update-seen', latest) } catch { /* storage unavailable */ }
274
+ try { localStorage.setItem(scoped('mv-update-seen'), latest) } catch { /* storage unavailable */ }
269
275
  setLatest(null)
270
276
  }
271
277
  return (
@@ -344,6 +350,7 @@ export function App() {
344
350
  // re-rendered the entire shell on every setScale tick during a pan/zoom).
345
351
  useSeenOnScreen()
346
352
  const manifest = useStore((s) => s.manifest)
353
+ const stopped = useLink((s) => s.shown) // the canvas stopped (spec 28 A1.11): nothing leaves this page
347
354
  const nodes = useStore((s) => s.nodes)
348
355
  const panelOpen = useStore((s) => s.panelOpen)
349
356
  const laneLift = useLaneLift()
@@ -376,7 +383,7 @@ export function App() {
376
383
  // dev: hydrate board policy (slides/type/open) from the repo so P and
377
384
  // deep links preview exactly what viewers get
378
385
  try {
379
- const r = await fetch(`${ROUTE}/api/policy`)
386
+ const r = await api('policy')
380
387
  if (r.ok) hydrateBoardPolicy(((await r.json()) as { boards?: Record<string, never> }).boards ?? {})
381
388
  } catch { /* dev server without the route - fine */ }
382
389
  }
@@ -398,6 +405,11 @@ export function App() {
398
405
  }
399
406
  const ok = await boot()
400
407
  if (notice) toast(notice)
408
+ // the page before this one reloaded itself when its canvas came back (A1.11): what its save came to - saved, or
409
+ // the board's file won on disk, or the board was gone
410
+ if (ok && resumed?.outcome === 'saved') toast('Back - your edits were saved')
411
+ else if (resumed?.outcome === 'disk') toast(DISK_WON)
412
+ else if (resumed?.outcome === 'gone') toast(BOARD_GONE)
401
413
  urlReady.current = true
402
414
  // a link naming frames on a board with NO nodes: the canvas's boot fit never runs (it waits
403
415
  // for the first frame) - follow the frame to where it lives from here
@@ -447,7 +459,15 @@ export function App() {
447
459
  // selection against the newly loaded state. writeHash skips identical hashes, so
448
460
  // restores never echo back into history.
449
461
  useEffect(() => {
462
+ // the switch a navigation started, while it may still run: back/forward, a pasted link and `location.hash =` each
463
+ // fire popstate AND hashchange, and a second switch to the same board would supersede the first - a second board
464
+ // fetch, and a load that never committed in perf --loads
465
+ let routing: { hash: string; switches: number } | null = null
450
466
  const onPop = async () => {
467
+ // the same hash, and no switch or cancel since this router started its own (a board picked, a goto, a newer
468
+ // navigation): the second event of the navigation the first is carrying through - board, frame and view
469
+ if (routing && routing.hash === location.hash && routing.switches === switchCount()) return
470
+ const raw = location.hash
451
471
  const nav = navigated() // a reveal still looking up its board must not land after this
452
472
  // a lookup below still running when newer navigation lands - a link, a board picked, a step in play - is dropped
453
473
  const at = useStore.getState().board, step = useStore.getState().play?.at
@@ -473,9 +493,15 @@ export function App() {
473
493
  let s = useStore.getState()
474
494
  if (h.board && h.board !== s.board) {
475
495
  if (s.play) s.setPlay(null) // a stale overlay must never survive into another board
476
- await s.switchBoard(h.board)
496
+ const switched = switchFor(h.board, nav)
497
+ const mine = routing = { hash: raw, switches: switchCount() }
498
+ const landed = await switched
499
+ if (routing === mine) routing = null
500
+ // the switch failed (the projection effect re-syncs the URL), or a newer navigation came while this one's board
501
+ // was read - a link, a goto, a board picked - and may have landed on this same board first: the board is the
502
+ // newer one's then, and so are the selection, the mode and the camera
503
+ if (!landed) return
477
504
  s = useStore.getState()
478
- if (s.board !== h.board) return // switch failed; the projection effect will re-sync the URL
479
505
  }
480
506
  // the thread an old link names (Comments.tsx opens every other link's): now, or once the new board's comments load
481
507
  if (legacy && h.c) { if (s.board !== at) parkThread(h.c); else revealThread(h.c) }
@@ -493,13 +519,14 @@ export function App() {
493
519
  useStore.setState({ selection: keys })
494
520
  s.look(keys) // a link opened is a look
495
521
  if (!keys.length && h.f?.length) void revealFrame(h.f[0]) // not on this board - where it lives
496
- else setTimeout(() => (keys.length ? canvasCtl.fitNodes(keys) : canvasCtl.fitAll()), 60)
522
+ else setTimeout(() => { if (isLatest(nav)) (keys.length ? canvasCtl.fitNodes(keys) : canvasCtl.fitAll()) }, 60) // unless a newer navigation has the camera
497
523
  }
498
524
  }
499
525
  // hashchange too: pasting a link into the same tab or editing the URL bar changes
500
526
  // the hash WITHOUT a popstate - ignoring it let the projection rewrite the URL back.
501
527
  // Our own writeHash never fires either event (history API), so there is no echo;
502
- // back/forward fires both, and the handler is idempotent under the double call.
528
+ // back/forward fires both: the second finds the first's switch on its way and leaves it
529
+ // be (above) - without a switch, the handler is idempotent under the double call.
503
530
  window.addEventListener('popstate', onPop)
504
531
  window.addEventListener('hashchange', onPop)
505
532
  return () => { window.removeEventListener('popstate', onPop); window.removeEventListener('hashchange', onPop) }
@@ -624,14 +651,15 @@ export function App() {
624
651
 
625
652
  if (data.type === 'sh:ready') {
626
653
  // a WindowProxy survives navigation, so a ready queued by a SUPERSEDED document (one the
627
- // ready-watchdog auto-renavigated past) can arrive here; drop it by generation like
628
- // sh:measure does, so a stale ready never marks a reloading frame ready.
629
- const gen = el.src.match(/[?&]r=(\d+)/)?.[1] ?? ''
630
- if (String(data.gen ?? '') !== gen) return
654
+ // ready-watchdog auto-renavigated past, or a same-URL reload's predecessor) can arrive here;
655
+ // dropped by generation and document before it touches anything, so a stale ready never marks
656
+ // a reloading frame ready, frees its admission slot or counts as seen
657
+ if (!fromLiveDocument(el, data)) return
631
658
  // a document that loaded again on its own (a full reload) is a new source revision: the
632
659
  // sleeping override of the previous document must not be trusted for this one
633
660
  if (s.nodes.find((n) => n.key === nodeKey)?.status === 'ready') s.bumpRev(nodeKey)
634
661
  s.setStatus(nodeKey, 'ready')
662
+ recorder.ready(nodeKey, data)
635
663
  frameReady(nodeKey)
636
664
  // the revision this document was served with (spec 26): a look counts up to it, and one older
637
665
  // than the frame's last edit reloads
@@ -639,7 +667,12 @@ export function App() {
639
667
  if (typeof data.doc === 'string') s.setShown(nodeKey, data.doc)
640
668
  logReload({ kind: 'ready', cause: takeReloadCause(nodeKey) ?? (before === undefined ? 'first' : 'self'), node: nodeKey, frame: String(data.id ?? ''), shown: typeof data.doc === 'string' ? data.doc : undefined, ms: Number(data.phases?.commit) })
641
669
  } else if (data.type === 'sh:error') {
670
+ // the same guard as sh:ready: an error from a document since replaced fails nothing and is not recorded
671
+ if (!fromLiveDocument(el, data)) return
642
672
  s.setStatus(nodeKey, 'error', String(data.message ?? 'unknown error'))
673
+ recorder.frameError(nodeKey, data)
674
+ } else if (data.type === 'sh:boot') {
675
+ recorder.booted(nodeKey, data) // a new document: its node's outcome starts over (spec 28 A1.7)
643
676
  } else if (data.type === 'sh:exit-interact') {
644
677
  if (s.interact === nodeKey) setInteract(null)
645
678
  } else if (data.type === 'sh:theme-applied') {
@@ -647,16 +680,16 @@ export function App() {
647
680
  } else if (data.type === 'sh:hmr') {
648
681
  s.bumpRev(nodeKey)
649
682
  } else if (data.type === 'sh:measure') {
650
- // Generation guard: the sender echoes ITS document's URL rev; a
683
+ // Generation and document guard: the sender echoes ITS document's URL rev and id; a
651
684
  // WindowProxy survives navigation, so a stale pre-navigation message would
652
- // otherwise route as if it came from the current document. Compare against
653
- // the iframe's CURRENT src - mismatched generations are dropped.
654
- const gen = el.src.match(/[?&]r=(\d+)/)?.[1] ?? ''
655
- if (String(data.gen ?? '') !== gen) return
685
+ // otherwise route as if it came from the current document. Compared against
686
+ // the iframe's CURRENT src and document - a stale one moves and keeps nothing.
687
+ if (!fromLiveDocument(el, data)) return
656
688
  // measureNode does the rest of the admission (content frames only,
657
689
  // frame-id match, finite positive, clamped)
658
- s.measureNode(nodeKey, String(data.frame ?? ''), Number(data.ownWidth), Number(data.measuredWidth), Number(data.height),
690
+ const took = s.measureNode(nodeKey, String(data.frame ?? ''), Number(data.ownWidth), Number(data.measuredWidth), Number(data.height),
659
691
  typeof data.settled === 'boolean' ? data.settled : undefined)
692
+ recorder.measured(nodeKey, data, took)
660
693
  } else if (data.type === 'sh:laser-copy') {
661
694
  // laser click = copy the element's full address for the agent: WHERE it lives on
662
695
  // the canvas ([board ▸ scene]) + frame source file + css path (+ jsx source loc)
@@ -728,7 +761,9 @@ export function App() {
728
761
  const s = useStore.getState()
729
762
  if (s.play) return // play mode owns the keyboard (Play.tsx)
730
763
  // Jam's keys first (spec 27): the first state that takes the key; the rest falls through
731
- if (!e.repeat && jamKey({ key: e.key, shift: e.shiftKey, alt: e.altKey, meta: e.metaKey, ctrl: e.ctrlKey })) { e.preventDefault(); return }
764
+ // with Option a Mac types a symbol (⌥L is "¬"): an Alt shortcut is named by the key pressed
765
+ const key = e.altKey && /^Key[A-Z]$/.test(e.code) ? e.code.slice(3).toLowerCase() : e.key
766
+ if (!e.repeat && jamKey({ key, shift: e.shiftKey, alt: e.altKey, meta: e.metaKey, ctrl: e.ctrlKey })) { e.preventDefault(); return }
732
767
  if ((e.metaKey || e.ctrlKey) && e.key === '\\') { e.preventDefault(); togglePanel(); return }
733
768
  if ((e.metaKey || e.ctrlKey) && e.key === '/') { e.preventDefault(); setPillOpen((o) => !o); return }
734
769
  if ((e.metaKey || e.ctrlKey) && e.key === 'a') { e.preventDefault(); s.selectAll(); return }
@@ -748,15 +783,18 @@ export function App() {
748
783
  if (e.key === 't') { animateLayout(); runTidy() }
749
784
  // laser and comment mode are one-at-a-time: comment mode already highlights
750
785
  // what you'd click, so stacking the full rainbow on top only adds noise
751
- if (e.key === 'l' && SOURCE_REVEALED) {
752
- if (!s.laser) commentsStore().setMode(false)
753
- s.setLaser(!s.laser)
786
+ // L: the pointer laser (the element under the cursor); ⌥L: inspect (every element outlined)
787
+ if (key === 'l' && !e.shiftKey && SOURCE_REVEALED) {
788
+ e.preventDefault()
789
+ commentsStore().setMode(false)
790
+ s.toggleLaser(e.altKey)
754
791
  }
755
792
  // C = comment mode (the Figma/Miro convention) · Shift+C = hide/show
756
793
  // pins · Shift+P = copy file path(s) (P alone is play; D6, changelog 0.4.0)
757
794
  if (e.key === 'c' && !e.shiftKey) {
758
795
  const c = commentsStore()
759
796
  if (!c.commentMode && s.board === UNPLACED) return void toast(NO_COMMENTS_HERE)
797
+ if (!c.commentMode && stoppedFor('Comments need the canvas running')) return
760
798
  if (!c.commentMode) s.setLaser(false)
761
799
  c.setMode(!c.commentMode)
762
800
  toast(c.commentMode ? 'comment mode off' : 'comment mode - click an element in a frame')
@@ -1063,6 +1101,7 @@ export function App() {
1063
1101
  {CONFIG.setup
1064
1102
  ? <div className="sh-banner">no app detected - designs would be built from nothing. See design/instructions/setup.md, then restart</div>
1065
1103
  : CONFIG.noTheme && !contentOnly(manifest?.frames ?? []) && <div className="sh-banner">no theme configured - frames render unstyled. Create design/theme.css importing your app's stylesheet (or set theme in design/config.ts)</div>}
1104
+ {stopped && <StoppedBanner />}
1066
1105
  <UpdatePill />
1067
1106
 
1068
1107
  {/* Jam V2 (spec 27): the lane, the focus panel, the notes card, the recording ring */}
@@ -1072,6 +1111,124 @@ export function App() {
1072
1111
  )
1073
1112
  }
1074
1113
 
1114
+ /** The canvas stopped (spec 28 A1.11): what happened and the way back - and, only when this tab holds some, that
1115
+ * its unsaved edits are kept. It sits on the toolbar's centre line in the free gap between the sidebar and the
1116
+ * toolbar, or just below the toolbar row when that gap is too narrow; it never covers either, and Hide UI (H)
1117
+ * leaves it up. In play it wears the play chrome's dark skin. */
1118
+ function StoppedBanner() {
1119
+ const link = useLink((s) => s.link)
1120
+ const unsaved = useLink((s) => s.unsaved)
1121
+ const play = useStore((s) => !!s.play)
1122
+ const ref = useRef<HTMLDivElement>(null)
1123
+ const cmd = <code>npx marver dev</code>
1124
+ const what = link === 'resuming' ? <>This canvas is back{unsaved ? ' - saving your edits' : ''}</>
1125
+ : link === 'elsewhere' ? <>Another canvas is running on this address - stop it and run {cmd} to bring this one back</>
1126
+ : <>This canvas stopped - run {cmd} to bring it back</>
1127
+ const kept = unsaved && link !== 'resuming'
1128
+ useLayoutEffect(() => {
1129
+ const el = ref.current
1130
+ if (!el) return
1131
+ let raf = 0
1132
+ const place = () => { cancelAnimationFrame(raf); raf = 0; placeBanner(el) }
1133
+ const soon = () => { raf ||= requestAnimationFrame(place) }
1134
+ place()
1135
+ // what moves the gap: the window, the chrome around it opening, closing or changing size, play, Hide UI
1136
+ const seen = new Set<Element>()
1137
+ const ro = new ResizeObserver(soon)
1138
+ const watch = () => { for (const n of el.parentElement?.querySelectorAll(OBSTACLES) ?? []) if (!seen.has(n)) { seen.add(n); ro.observe(n) } }
1139
+ watch()
1140
+ const mo = new MutationObserver(() => { watch(); soon() })
1141
+ if (el.parentElement) mo.observe(el.parentElement, { childList: true, subtree: true, attributes: true, attributeFilter: ['class'] })
1142
+ mo.observe(document.body, { attributes: true, attributeFilter: ['class'] })
1143
+ window.addEventListener('resize', soon)
1144
+ return () => { cancelAnimationFrame(raf); ro.disconnect(); mo.disconnect(); window.removeEventListener('resize', soon) }
1145
+ }, [link, unsaved, play])
1146
+ return (
1147
+ <div ref={ref} className={`sh-banner sh-stopped${play ? ' dark' : ''}`} role="status" data-link={link}>
1148
+ {what}{kept && <><span className="dot"> · </span><span className="kept">your unsaved edits are kept in this tab</span></>}
1149
+ </div>
1150
+ )
1151
+ }
1152
+
1153
+ /** The chrome the stopped banner keeps clear of: the sidebar (or its button) on the left, the toolbar (or its
1154
+ * button) on the right - the canvas's own, or play's brand and toolbar pills over it. */
1155
+ const OBSTACLES = ':scope > .sh-panel, :scope > .sh-fab, :scope > nav.sh-pill, :scope > .sh-pill-fab, :scope > .sh-play > .sh-pill, :scope > .sh-play > .sh-pill-fab'
1156
+ const BANNER_GAP = 12
1157
+ function placeBanner(el: HTMLElement) {
1158
+ const app = el.parentElement
1159
+ if (!app) return
1160
+ const edge = parseFloat(getComputedStyle(app).getPropertyValue('--edge')) || 10
1161
+ // a box in the app's own coordinates, from layout - never the rect mid-morph (a closing panel scales down)
1162
+ const box = (n: HTMLElement) => {
1163
+ let x = 0, y = 0
1164
+ for (let e: HTMLElement | null = n; e && e !== app; e = e.offsetParent as HTMLElement | null) { x += e.offsetLeft; y += e.offsetTop }
1165
+ return { left: x, top: y, right: x + n.offsetWidth, bottom: y + n.offsetHeight }
1166
+ }
1167
+ const pick = (root: Element, sel: string) => {
1168
+ const n = root.querySelector<HTMLElement>(sel)
1169
+ return n && !n.matches('.closed, .hidden') && n.offsetWidth ? box(n) : null
1170
+ }
1171
+ let left: ReturnType<typeof box> | null = null, right: ReturnType<typeof box> | null = null
1172
+ if (!document.body.classList.contains('sh-hide-ui')) {
1173
+ const stage = app.querySelector(':scope > .sh-play')
1174
+ if (stage) {
1175
+ left = pick(stage, ':scope > .sh-play-brand')
1176
+ right = pick(stage, ':scope > .sh-play-pill:not(.sh-play-brand)') ?? pick(stage, ':scope > .sh-pill-fab')
1177
+ } else {
1178
+ left = pick(app, ':scope > .sh-panel') ?? pick(app, ':scope > .sh-fab')
1179
+ right = pick(app, ':scope > nav.sh-pill') ?? pick(app, ':scope > .sh-pill-fab')
1180
+ }
1181
+ }
1182
+ // the toolbar row: its centre line, and its foot - the sidebar runs down the page, so it is no part of the row
1183
+ const tall = !!left && left.bottom - left.top > 64
1184
+ const row = [right, tall ? null : left].filter((b): b is NonNullable<typeof b> => !!b)
1185
+ const mid = row.length ? Math.max(...row.map((b) => (b.top + b.bottom) / 2)) : edge + 23
1186
+ const foot = Math.max(edge + 46, ...row.map((b) => b.bottom))
1187
+ const W = app.clientWidth
1188
+ const from = left ? left.right + BANNER_GAP : edge, to = right ? right.left - BANNER_GAP : W - edge
1189
+ const at = (where: 'row' | 'stack' | 'below', x0: number, x1: number, top?: number) => {
1190
+ el.dataset.at = where
1191
+ el.style.left = `${Math.round(x0 + Math.max(0, (x1 - x0 - el.offsetWidth) / 2))}px`
1192
+ el.style.top = `${Math.round(top ?? mid - el.offsetHeight / 2)}px`
1193
+ }
1194
+ el.style.transform = 'none'
1195
+ el.dataset.at = 'row'
1196
+ // one line in the gap
1197
+ el.style.whiteSpace = 'nowrap'
1198
+ el.style.maxWidth = 'none'
1199
+ const line = el.offsetHeight
1200
+ if (el.offsetWidth <= to - from) return at('row', from, to)
1201
+ // two lines in the gap: what happened, then the kept edits under it
1202
+ if (el.querySelector('.kept')) {
1203
+ el.dataset.at = 'stack'
1204
+ if (el.offsetWidth <= to - from) return at('stack', from, to)
1205
+ el.dataset.at = 'row'
1206
+ }
1207
+ // or wrapped in two, the box no wider than its longest line
1208
+ el.style.whiteSpace = 'normal'
1209
+ el.style.maxWidth = `${to - from}px`
1210
+ if (to - from >= 220 && el.offsetHeight <= line + 18) { hug(el); return at('row', from, to) }
1211
+ // too narrow: under the toolbar row, centred in what the sidebar leaves, the kept edits on a line of their own
1212
+ el.dataset.at = 'below'
1213
+ const lo = tall && left ? left.right + BANNER_GAP : edge, hi = W - edge
1214
+ el.style.maxWidth = `${Math.max(160, Math.min(680, hi - lo))}px`
1215
+ hug(el)
1216
+ at('below', lo, hi, row.length ? foot + 8 : edge) // no row with the chrome hidden: the top edge
1217
+ }
1218
+ /** A wrapped banner's box shrinks to its longest line (a max-width box stays as wide as it may be). */
1219
+ function hug(el: HTMLElement) {
1220
+ const r = document.createRange()
1221
+ r.selectNodeContents(el)
1222
+ const lines = [...r.getClientRects()]
1223
+ if (!lines.length) return
1224
+ const cs = getComputedStyle(el)
1225
+ const chrome = el.offsetWidth - el.clientWidth + parseFloat(cs.paddingLeft) + parseFloat(cs.paddingRight)
1226
+ const need = Math.ceil(Math.max(...lines.map((l) => l.right)) - Math.min(...lines.map((l) => l.left)) + chrome) + 1
1227
+ const was = el.style.maxWidth, h = el.offsetHeight
1228
+ el.style.maxWidth = `${Math.min(need, el.offsetWidth)}px`
1229
+ if (el.offsetHeight > h) el.style.maxWidth = was // never a line more than it had (a balanced wrap re-flows)
1230
+ }
1231
+
1075
1232
  /** The bottom-right notification corner. Plain toasts render as before.
1076
1233
  * Jam pills are FRAME-FIRST (icon + frame title, then Marver · preview) and stack as a DECK:
1077
1234
  * 1-2 show in full; 3+ collapse to the newest pill with two card edges peeking beneath and a
@@ -1125,10 +1282,12 @@ function JamAvatar({ author }: { author: { name?: string; avatar?: string; id?:
1125
1282
  async function viewNote(note: import('./store.ts').JamNote, dismiss: () => void) {
1126
1283
  if (revealThread(note.threadId)) { dismiss(); return }
1127
1284
  const s = useStore.getState()
1285
+ // a navigation: a link still finding its board gives way to it - and it to a newer one, wherever this one has got to
1286
+ const nav = navigated()
1128
1287
  // a thread in the old all-scenes log has no board of its own: its frame's board shows it (spec 26)
1129
- if (note.board === ALL_SCENES) { if (note.frame) await revealFrame(note.frame) }
1130
- else if (note.board && s.board !== note.board) await s.switchBoard(note.board)
1131
- for (let i = 0; i < 12; i++) {
1288
+ if (note.board === ALL_SCENES) { if (note.frame) await revealFrame(note.frame, nav) }
1289
+ else if (note.board && s.board !== note.board && !await switchFor(note.board, nav)) return
1290
+ for (let i = 0; i < 12 && isLatest(nav); i++) {
1132
1291
  if (revealThread(note.threadId)) { dismiss(); return }
1133
1292
  await new Promise((r) => setTimeout(r, 250))
1134
1293
  }
@@ -1,12 +1,13 @@
1
1
  import { useEffect, useRef, useState, type CSSProperties, type MouseEvent as ReactMouseEvent, type PointerEvent as ReactPointerEvent, type ReactNode } from 'react'
2
2
  import { useStore, PUBLISHED, STATUS_AS_OF, addToBoard, boardLabel, fetchBoardNames, fetchBoardTree, fetchMembership, rememberMeta, rememberTitles, type BoardMeta, type TreeBase } from './store.ts'
3
3
  import { UNPLACED } from './hash.ts'
4
+ import { scoped } from './api.ts'
4
5
  import { LiveIcon, StatusIcon, TypeIcon } from './board-icons.tsx'
5
6
  import { StatusPicker } from './StatusPicker.tsx'
6
7
  import type { StatusWord } from '../../shared/board-types.ts'
7
8
  import { PHASE_LABEL, STATUS_LABEL } from '../../shared/status.ts'
8
9
  import { canvasCtl } from './canvas/Canvas.tsx'
9
- import { navigated } from './goto.ts'
10
+ import { isLatest, navigated, switchFor } from './goto.ts'
10
11
  import { rollup } from '../../shared/marks.ts'
11
12
  import { Bubble, useAsks } from './marks-ui.tsx'
12
13
  import { Tip } from './Tip.tsx'
@@ -28,7 +29,7 @@ import {
28
29
  * Active board = accent icon + wash, same language as scenes.
29
30
  */
30
31
 
31
- const CLOSED_KEY = 'mv-folders-closed' // collapsed folders are a viewer preference, never data
32
+ const CLOSED_KEY = scoped('mv-folders-closed') // collapsed folders are a viewer preference, per canvas, never data
32
33
  const readClosed = (): Record<string, true> => { try { return JSON.parse(localStorage.getItem(CLOSED_KEY) ?? '{}') } catch { return {} } }
33
34
 
34
35
  /** The inline input: renaming a board or a folder, or naming a NEW folder that does not exist
@@ -171,9 +172,8 @@ export function BoardList({ onMenu }: { onMenu: MenuOpener }) {
171
172
  }
172
173
  const pick = async (name: string) => {
173
174
  if (name === useStore.getState().board) return
174
- navigated() // a link still finding its board gives way
175
- await useStore.getState().switchBoard(name)
176
- setTimeout(() => canvasCtl.fitAll(), 60)
175
+ const nav = navigated() // a link still finding its board gives way
176
+ if (await switchFor(name, nav)) setTimeout(() => { if (isLatest(nav)) canvasCtl.fitAll() }, 60) // unless a newer one has the camera
177
177
  }
178
178
 
179
179
  /** The one write path: queue the intent, show it at once, persist. The flush takes EVERY
@@ -8,6 +8,7 @@
8
8
  import { useEffect, useMemo, useRef, useState } from 'react'
9
9
  import { createPortal } from 'react-dom'
10
10
  import { avatarFallback, useComments } from './comments-store.ts'
11
+ import { api } from './api.ts'
11
12
  import { CONFIG, useStore, type Node } from './store.ts'
12
13
  import { threadHostKey } from './keys.ts'
13
14
  import { isNoteAnchor, resolveNoteAnchor, useNotes } from './notes.ts'
@@ -21,7 +22,7 @@ import { TagStatus } from './jam-ui.tsx'
21
22
  import { CaptureBlock } from './jam-panel.tsx'
22
23
  import { useJamQueue } from './jam-queue.ts'
23
24
  import { mentionAlerts, mentionPeople, mentionQueryAt, parseBody, type MentionPerson } from './mentions.ts'
24
- import { ROUTE, slideSize, stageFit } from '../const.ts'
25
+ import { slideSize, stageFit } from '../const.ts'
25
26
  import type { AgentMeta, Thread } from '../../shared/events.ts'
26
27
 
27
28
  /** Tint the pin / composer / thread card EDGES (border, outline, focus ring) in the anchored
@@ -901,7 +902,7 @@ export function IdentityDialog() {
901
902
  // an invite link knows WHO it's for - show it (the token is the proof of holding)
902
903
  useEffect(() => {
903
904
  if (!needs || !invite) return setInvitedAs('')
904
- fetch(`${ROUTE}/api/invite-info?token=${encodeURIComponent(invite)}`)
905
+ api(`invite-info?token=${encodeURIComponent(invite)}`)
905
906
  .then((r) => (r.ok ? r.json() : null))
906
907
  .then((d) => d?.email && setInvitedAs(d.email))
907
908
  .catch(() => { /* chip just stays hidden */ })
@@ -16,16 +16,18 @@ import { ContextMenu, useContextMenu, type MenuItem } from './ContextMenu.tsx'
16
16
  import { ArrowBendUpLeftIcon, ArrowLineUpIcon, ArrowUpIcon, CheckSquareOffsetIcon, CommentIcon, EyeIcon, NotebookIcon, PencilSimpleIcon, PlayIcon, ReloadIcon, XIcon } from './icons.tsx'
17
17
  import { laneLine, timelineLines } from './jam-lines.ts'
18
18
  import { changedShots, useJamQueue, type JamCard } from './jam-queue.ts'
19
- import { letGoOfTile, useJamUi } from './jam-state.ts'
19
+ import { DONE_GROUP, doneFold, letGoOfTile, useJamUi } from './jam-state.ts'
20
20
  import { CaptureLaneRow, FocusPanelView } from './jam-surface-parts.tsx'
21
21
  import { clearMoreDraft, EdgeRing } from './jam-panel.tsx'
22
22
  import { useComments } from './comments-store.ts'
23
23
  import { HARNESS } from './Comments.tsx'
24
24
  import { PUBLISHED, useStore } from './store.ts'
25
+ import { api, withWs } from './api.ts'
25
26
  import type { CaptureRecord } from '../../server/jam/types.ts'
26
27
 
27
28
  const csrf = () => /(?:^|;\s*)mv_c=([\w-]+)/.exec(document.cookie)?.[1] ?? ''
28
- const picture = (id?: string) => (id ? `${ROUTE}/api/jam/picture?id=${encodeURIComponent(id)}` : undefined)
29
+ /** An <img> cannot send a header: its URL names the workspace, which the server's guard reads (A1.11). */
30
+ const picture = (id?: string) => (id ? withWs(`${ROUTE}/api/jam/picture?id=${encodeURIComponent(id)}`) : undefined)
29
31
 
30
32
  /** Is the lane showing? While a run lasts with a capture in it, or a capture records. */
31
33
  export function useLaneShown(): boolean {
@@ -44,7 +46,7 @@ function useRecord(id: string | undefined) {
44
46
  useEffect(() => {
45
47
  if (!id || rec?.id === id) return
46
48
  let live = true
47
- fetch(`${ROUTE}/api/jam/capture?id=${encodeURIComponent(id)}`, { headers: { 'x-mv-c': csrf() } })
49
+ api(`jam/capture?id=${encodeURIComponent(id)}`, { headers: { 'x-mv-c': csrf() } })
48
50
  .then((r) => (r.ok ? r.json() : null)).then((r) => { if (live && r?.record) setRec({ id, record: r.record, edited: r.edited }) }, () => {})
49
51
  return () => { live = false }
50
52
  }, [id])
@@ -118,13 +120,18 @@ export function JamSurface({ sidebarRight }: { sidebarRight: number }) {
118
120
  if (sel?.thread === s.active) { if (st.panel) st.close() } else letGoOfTile()
119
121
  }), [])
120
122
  const made = (id: string) => Number(/^cap-(\d+)-/.exec(id)?.[1] ?? 0)
121
- const withMade = list.map((c) => ({ made: c.made, tile: { id: c.id, state: c.state, title: c.title ?? 'Capture', line: laneLine(c), ...(c.exclusive ? { exclusive: true } : {}) } as { id: string; state: JamCard['state']; title: string; line: string; exclusive?: boolean } }))
123
+ const withMade = list.map((c) => ({ made: c.made, tile: { id: c.id, state: c.state, title: c.title ?? 'Capture', line: laneLine(c), ...(c.exclusive ? { exclusive: true } : {}), ...(c.state === 'done' && c.shots?.some((x) => !x.same) ? { frames: c.shots.filter((x) => !x.same).map((x) => x.frame) } : {}), ...(c.kind === 'wrapup' ? { record: true } : {}) } as { id: string; state: JamCard['state']; title: string; line: string; exclusive?: boolean; frames?: string[]; record?: boolean } }))
122
124
  // captures the server does not hold yet: sealing (pictures and flushes still out) or waiting to send -
123
125
  // each in its place by when it started, so one sealing late never swaps with a newer one
124
126
  const known = new Set(list.map((c) => c.id))
125
127
  for (const c of Object.values(cap.caps)) if (c.state === 'draining' && !known.has(c.id)) withMade.push({ made: made(c.id), tile: { id: c.id, state: 'confirming', title: 'Capture', line: 'Finishing' } })
126
128
  for (const id of cap.unsent) if (!known.has(id) && !cap.caps[id]) withMade.push({ made: made(id), tile: { id, state: 'confirming', title: 'Capture', line: 'Waiting to send' } })
127
129
  const tiles = withMade.sort((a, b) => a.made - b.made).map((x) => x.tile)
130
+ // a selected tile that became done while the Done group is folded: the group holds the selection now
131
+ const doneNow = doneFold(tiles, ui.doneOpen)
132
+ useEffect(() => {
133
+ if (doneNow.fold && !ui.doneOpen && ui.selected && doneNow.done.some((t) => t.id === ui.selected)) ui.select(DONE_GROUP)
134
+ }, [doneNow.fold, ui.doneOpen, ui.selected, doneNow.done.length])
128
135
  const recording = cap.current ? (() => {
129
136
  const c = cap.caps[cap.current!]
130
137
  const counts = captureCounts(c)
@@ -177,6 +184,7 @@ export function JamSurface({ sidebarRight }: { sidebarRight: number }) {
177
184
  {shown && (
178
185
  <CaptureLaneRow
179
186
  tiles={folded ? [] : tiles} recording={recording} between={between} selected={ui.selected ?? undefined} keyboard={ui.laneKeys} followEnd={ui.followEnd}
187
+ doneOpen={ui.doneOpen} onDoneOpen={(open, ids) => ui.setDoneOpen(open, ids)}
180
188
  onOpen={(id) => openTile(id)}
181
189
  onMenu={(e, id) => { const c = cards?.find((x) => x.id === id); if (c) { ui.select(id); cm.open(e, tileMenu(c)) } else e.preventDefault() }}
182
190
  ask={voice.asking && cap.current ? voiceAsk(voice) : undefined}
@@ -214,7 +222,7 @@ export function JamSurface({ sidebarRight }: { sidebarRight: number }) {
214
222
  shots={changedShots(panelCard.shots).map((x) => ({ frame: x.frame, before: picture(x.before), after: picture(x.after), ...(x.new ? { new: true } : {}) }))}
215
223
  reply={panelCard.reply ? replyText(panelCard) : ''}
216
224
  view={ui.view} tab={ui.tab} moreOpen={ui.moreOpen}
217
- onTab={(i) => ui.setTab(i)} onFlip={() => ui.flip()} onMoreOpen={(on) => ui.setMoreOpen(on)}
225
+ onTab={(i) => ui.setTab(i)} onFlip={(v) => ui.setView(v)} onMoreOpen={(on) => ui.setMoreOpen(on)}
218
226
  onClose={() => ui.close()}
219
227
  onEdit={(text) => saveEdit(panelCard, text)}
220
228
  onConfirm={() => void decideDraft(panelCard.id, 'confirm')}
@@ -15,6 +15,7 @@ import { enterFocus, enterPlay, enterSlides, PlayOverlay, playCtl } from './Play
15
15
  import { UNPLACED, bootHash, parseHash, retargetBoot, writeHash } from './hash.ts'
16
16
  import { isLegacyLink, landLegacy } from './legacy-links.ts'
17
17
  import { useComments } from './comments-store.ts'
18
+ import { isLatest, navigated, switchFor } from './goto.ts'
18
19
 
19
20
  export class ShellBoundary extends Component<{ children: ReactNode }, { err: Error | null }> {
20
21
  state = { err: null as Error | null }
@@ -96,10 +97,9 @@ export function App() {
96
97
 
97
98
  // back/forward + pasted links, within what the lock allows
98
99
  useEffect(() => {
99
- let popSeq = 0
100
100
  const onPop = async () => {
101
- // a lookup newer navigation overtook - a link, a step on the stage - is dropped
102
- const mine = ++popSeq, was = useStore.getState()
101
+ // a lookup newer navigation overtook - a link, a goto, a step on the stage - is dropped
102
+ const nav = navigated(), was = useStore.getState()
103
103
  const parsed = parseHash()
104
104
  const raw = parsed.board === UNPLACED ? {} : parsed // dev's view, and what it names: not here
105
105
  // an old All Scenes link lands on a real board; it, and the bare #/, with no board: the landing one
@@ -107,11 +107,11 @@ export function App() {
107
107
  const h = r.hash
108
108
  const board = h.board ?? (h.focus ? undefined : await landingBoard())
109
109
  const s = useStore.getState()
110
- if (mine !== popSeq || s.board !== was.board || s.play?.at !== was.play?.at) return
110
+ if (!isLatest(nav) || s.board !== was.board || s.play?.at !== was.play?.at) return
111
111
  if (r.notice) s.toast(r.notice)
112
112
  if (h.c) pendingThread = h.c
113
113
  if (board && board !== s.board) {
114
- await s.switchBoard(board)
114
+ if (!await switchFor(board, nav)) return // failed, or a newer navigation's board and stage by now
115
115
  useStore.getState().setPlay(null) // the stage restarts on the board the link names, at its frame
116
116
  if (h.play?.slides) enterSlides(h.play)
117
117
  else if (h.play) enterPlay(h.play)