@marver-design/marver 0.26.1 → 0.27.2

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 (109) hide show
  1. package/CHANGELOG.md +198 -0
  2. package/README.md +12 -4
  3. package/dist/{anchor-check-l-ny3UzH.mjs → anchor-check-gkxkPAIv.mjs} +1 -1
  4. package/dist/{board-tree-DRioF94d.mjs → board-tree-BXR8dw4b.mjs} +3 -1
  5. package/dist/{boards-CGg6piKF.mjs → boards-BHKP5yhI.mjs} +1 -1
  6. package/dist/{boards-DYG22tOe.mjs → boards-BqUqKNW8.mjs} +4 -4
  7. package/dist/{build-BDRiO_mP.mjs → build-VgNg4rr8.mjs} +8 -23
  8. package/dist/cli.mjs +45 -19
  9. package/dist/{collab-Dxg2trOK.mjs → collab-BEAcXrBb.mjs} +1 -1
  10. package/dist/{comments-BqXua-XL.mjs → comments-YEU1Zhv9.mjs} +4 -4
  11. package/dist/{context-HQ4Giw58.mjs → context-Ccjrhr1J.mjs} +3 -3
  12. package/dist/{daemon-DL6Fwq6D.mjs → daemon-Dc9AH0M3.mjs} +9 -7
  13. package/dist/detect-C0wpaePX.mjs +125 -0
  14. package/dist/dev-lock-C_FC70Mu.mjs +65 -0
  15. package/dist/dev-ri6nAlRp.mjs +1273 -0
  16. package/dist/exclusive-B1RtpeeP.mjs +150 -0
  17. package/dist/{init-D8DtrK_F.mjs → init-W0nxR1OY.mjs} +8 -6
  18. package/dist/{link-BNzLvdhI.mjs → link-CdTgn94Y.mjs} +23 -11
  19. package/dist/ls-BZ5TAtd5.mjs +38 -0
  20. package/dist/{manifest-Nl3KSVOk.mjs → manifest-aFyDmL8C.mjs} +2 -2
  21. package/dist/{marks-DyWMv_Z1.mjs → marks-BF9pNEgH.mjs} +3 -3
  22. package/dist/{marks-CKgzucHZ.mjs → marks-CnCCfAbD.mjs} +3 -3
  23. package/dist/{marver-id-gate-BjF6v4bT.mjs → marver-id-gate-D-R0hSt_.mjs} +1 -1
  24. package/dist/perf-DkAUFT6W.mjs +1319 -0
  25. package/dist/perf-jam-BaH3Lg0m.mjs +635 -0
  26. package/dist/plugin-B8UghYuF.mjs +5242 -0
  27. package/dist/{poster-BdtSKMDm.mjs → poster-BNgafWMK.mjs} +1 -1
  28. package/dist/{profile-WU9qcbIo.mjs → profile-jIS6BcAs.mjs} +1 -1
  29. package/dist/{publish-bakes-9RzRToXV.mjs → publish-bakes-38Nja78p.mjs} +3 -3
  30. package/dist/{queue-29ok5_eZ.mjs → queue-CAM_vNmX.mjs} +1 -1
  31. package/dist/recover-B8AiI29B.mjs +66 -0
  32. package/dist/{serve-C8rVheYk.mjs → serve-Dp3nHstu.mjs} +3 -3
  33. package/dist/{share--oFJ1bCI.mjs → share-Ce4tP7ji.mjs} +1 -1
  34. package/dist/{shot-XQV7HC9A.mjs → shot-CMQgMVZm.mjs} +1 -1
  35. package/dist/{shot-DQeR_Pfn.mjs → shot-Ch24tiMO.mjs} +36 -5
  36. package/dist/slots-CFNnegCc.mjs +478 -0
  37. package/dist/{sync-DKk-yT1V.mjs → sync-CQdGARJ9.mjs} +4 -3
  38. package/dist/{work-VvX_JIgl.mjs → work-Bxz-ObF3.mjs} +4 -2
  39. package/dist/{work-F5u-twpJ.mjs → work-CNhFF9pU.mjs} +5 -3
  40. package/docs/boards-and-folders.md +3 -1
  41. package/docs/jam-session.md +57 -2
  42. package/docs/performance.md +424 -0
  43. package/package.json +2 -2
  44. package/src/client/content/index.tsx +3 -0
  45. package/src/client/content/video.tsx +16 -4
  46. package/src/client/frame-host/bridge.js +22 -6
  47. package/src/client/frame-host/main.tsx +17 -5
  48. package/src/client/shell/App.tsx +188 -26
  49. package/src/client/shell/BoardList.tsx +5 -5
  50. package/src/client/shell/Comments.tsx +8 -5
  51. package/src/client/shell/ContextMenu.tsx +5 -3
  52. package/src/client/shell/JamSurface.tsx +4 -2
  53. package/src/client/shell/LockedApp.tsx +8 -5
  54. package/src/client/shell/Play.tsx +20 -10
  55. package/src/client/shell/Tip.tsx +3 -1
  56. package/src/client/shell/Toolbar.tsx +12 -1
  57. package/src/client/shell/api.ts +233 -0
  58. package/src/client/shell/app-bridge.ts +254 -0
  59. package/src/client/shell/app-perf.ts +92 -0
  60. package/src/client/shell/canvas/Canvas.tsx +141 -21
  61. package/src/client/shell/canvas/FrameNode.tsx +22 -9
  62. package/src/client/shell/canvas/admission.ts +31 -9
  63. package/src/client/shell/canvas/camera-broadcast.ts +15 -5
  64. package/src/client/shell/canvas/ctl.ts +8 -0
  65. package/src/client/shell/canvas/frame-registry.ts +28 -2
  66. package/src/client/shell/canvas/sleep.ts +60 -17
  67. package/src/client/shell/canvas/updates.ts +2 -1
  68. package/src/client/shell/comments-store.ts +12 -4
  69. package/src/client/shell/goto.ts +22 -10
  70. package/src/client/shell/inset.ts +44 -0
  71. package/src/client/shell/jam-capture.ts +41 -22
  72. package/src/client/shell/jam-keys.ts +12 -3
  73. package/src/client/shell/jam-panel.tsx +9 -3
  74. package/src/client/shell/jam-queue.ts +3 -3
  75. package/src/client/shell/jam-session.tsx +14 -8
  76. package/src/client/shell/jam-voice.ts +55 -15
  77. package/src/client/shell/legacy-links.ts +2 -2
  78. package/src/client/shell/main.tsx +18 -1
  79. package/src/client/shell/marks-ui.tsx +5 -3
  80. package/src/client/shell/marver-app.ts +21 -0
  81. package/src/client/shell/notes.ts +8 -1
  82. package/src/client/shell/perf-run-probe.ts +34 -0
  83. package/src/client/shell/perf-run.ts +70 -0
  84. package/src/client/shell/perf.ts +80 -58
  85. package/src/client/shell/recorder-core.ts +183 -0
  86. package/src/client/shell/recorder.ts +607 -0
  87. package/src/client/shell/store.ts +294 -110
  88. package/src/client/shell/styles.css +72 -15
  89. package/src/client/shell/unsaved.ts +81 -0
  90. package/src/client/shell/whiteout-probes.ts +141 -0
  91. package/src/shared/app-api.ts +205 -0
  92. package/src/shared/app-perf.ts +308 -0
  93. package/src/shared/logo-sniff.ts +86 -0
  94. package/src/shared/machine.ts +132 -0
  95. package/src/shared/perf-run.ts +177 -0
  96. package/templates/AGENTS-embedded.md +25 -4
  97. package/templates/AGENTS-studio.md +25 -4
  98. package/templates/demo/dark.tsx +1 -1
  99. package/templates/demo/welcome.tsx +1 -1
  100. package/templates/instructions/boards.md +3 -1
  101. package/templates/instructions/welcome.md +6 -3
  102. package/dist/bake-C-awKgLA.mjs +0 -786
  103. package/dist/config-Cf7EjAMf.mjs +0 -292
  104. package/dist/dev-Bw_qYWWq.mjs +0 -755
  105. package/dist/dev-lock-DWSpa6nj.mjs +0 -179
  106. package/dist/perf-C75MZ73h.mjs +0 -167
  107. package/dist/perf-DPbLGhhO.mjs +0 -49
  108. package/dist/perf-jam-BU3TVrZu.mjs +0 -239
  109. package/dist/plugin-DkGmZs_r.mjs +0 -2423
@@ -5,14 +5,19 @@ 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
+ import { TOP } from './inset.ts'
13
+ // a headless run's probe (main.tsx): canvas code, so it comes through this module, never into a locked bundle
14
+ export { startPerfRunProbe } from './perf-run-probe.ts'
12
15
  import { Tip } from './Tip.tsx'
13
16
  import { PKG, ROUTE } from '../const.ts'
17
+ import { api, resumed, scoped, useLink } from './api.ts'
14
18
  import { animateLayout, Canvas, canvasCtl } from './canvas/Canvas.tsx'
15
- import { frameByWindow } from './canvas/frame-registry.ts'
19
+ import { frameByWindow, fromLiveDocument } from './canvas/frame-registry.ts'
20
+ import { recorder } from './recorder.ts'
16
21
  import { enterFocus, enterPlay, enterSlides, playCtl, PlayOverlay } from './Play.tsx'
17
22
  import { bootHash, linkTargets, parseHash, retargetBoot, UNPLACED, writeHash } from './hash.ts'
18
23
  import { isLegacyLink, landLegacy } from './legacy-links.ts'
@@ -21,7 +26,7 @@ import { ALL_SCENES, humanize as slugLabel, readTitle } from '../../shared/board
21
26
  import { CommentsController, parkThread, revealThread } from './Comments.tsx'
22
27
  import { poweredByUrl } from '../../shared/utm.ts'
23
28
  import { avatarFallback, NO_COMMENTS_HERE, useComments } from './comments-store.ts'
24
- import { goTo, isLatest, navigated, revealFrame } from './goto.ts'
29
+ import { goTo, isLatest, navigated, revealFrame, switchFor } from './goto.ts'
25
30
  import { useNotes } from './notes.ts'
26
31
  import { contentOnly } from '../../shared/frames.ts'
27
32
  import { nextToLook } from '../../shared/marks.ts'
@@ -69,6 +74,10 @@ function SceneGroup({ name, label, count, held, renaming, onRename, onPick, onCo
69
74
  export class ShellBoundary extends Component<{ children: ReactNode }, { err: Error | null }> {
70
75
  state = { err: null as Error | null }
71
76
  static getDerivedStateFromError(err: Error) { return { err } }
77
+ // the recorder's (spec 28 A1.7): the error, and the component it came from
78
+ componentDidCatch(err: Error, info: { componentStack?: string | null }) {
79
+ recorder.error({ source: 'shell', message: err.message, stack: err.stack, component: /\bat (\w+)/.exec(info.componentStack ?? '')?.[1] })
80
+ }
72
81
  render() {
73
82
  if (!this.state.err) return this.props.children
74
83
  return (
@@ -164,7 +173,8 @@ function SelectionBar() {
164
173
  left: barW
165
174
  ? `clamp(8px, calc(${centerX} - ${Math.round(barW / 2)}px), calc(100vw - ${barW + 8}px))`
166
175
  : centerX,
167
- top: `clamp(8px, ${rawTop}, calc(100vh - 52px))`,
176
+ // below the Mac app's strip and its scroll edge when the shell took the inset (TOP 44: 52 px; else 8)
177
+ top: `clamp(${TOP + 8}px, ${rawTop}, calc(100vh - 52px))`,
168
178
  transform: barW ? undefined : 'translateX(-50%)',
169
179
  }}
170
180
  >
@@ -254,10 +264,10 @@ function UpdatePill() {
254
264
  const play = useStore((s) => s.play)
255
265
  useEffect(() => {
256
266
  if (PUBLISHED) return // a shared canvas never nags its viewers
257
- fetch(`${ROUTE}/api/update`)
267
+ api('update')
258
268
  .then((r) => (r.ok ? r.json() : null))
259
269
  .then((u) => {
260
- if (u?.latest && localStorage.getItem('mv-update-seen') !== u.latest) setLatest(u.latest)
270
+ if (u?.latest && localStorage.getItem(scoped('mv-update-seen')) !== u.latest) setLatest(u.latest)
261
271
  })
262
272
  .catch(() => { /* dev server gone or endpoint absent - stay quiet */ })
263
273
  }, [])
@@ -265,7 +275,7 @@ function UpdatePill() {
265
275
  // init rides along so managed files (AGENTS.md, instructions/) refresh with the code
266
276
  const cmd = `npm i -D ${PKG}@latest && npx marver init`
267
277
  const dismiss = () => {
268
- try { localStorage.setItem('mv-update-seen', latest) } catch { /* storage unavailable */ }
278
+ try { localStorage.setItem(scoped('mv-update-seen'), latest) } catch { /* storage unavailable */ }
269
279
  setLatest(null)
270
280
  }
271
281
  return (
@@ -344,6 +354,7 @@ export function App() {
344
354
  // re-rendered the entire shell on every setScale tick during a pan/zoom).
345
355
  useSeenOnScreen()
346
356
  const manifest = useStore((s) => s.manifest)
357
+ const stopped = useLink((s) => s.shown) // the canvas stopped (spec 28 A1.11): nothing leaves this page
347
358
  const nodes = useStore((s) => s.nodes)
348
359
  const panelOpen = useStore((s) => s.panelOpen)
349
360
  const laneLift = useLaneLift()
@@ -376,7 +387,7 @@ export function App() {
376
387
  // dev: hydrate board policy (slides/type/open) from the repo so P and
377
388
  // deep links preview exactly what viewers get
378
389
  try {
379
- const r = await fetch(`${ROUTE}/api/policy`)
390
+ const r = await api('policy')
380
391
  if (r.ok) hydrateBoardPolicy(((await r.json()) as { boards?: Record<string, never> }).boards ?? {})
381
392
  } catch { /* dev server without the route - fine */ }
382
393
  }
@@ -398,6 +409,11 @@ export function App() {
398
409
  }
399
410
  const ok = await boot()
400
411
  if (notice) toast(notice)
412
+ // the page before this one reloaded itself when its canvas came back (A1.11): what its save came to - saved, or
413
+ // the board's file won on disk, or the board was gone
414
+ if (ok && resumed?.outcome === 'saved') toast('Back - your edits were saved')
415
+ else if (resumed?.outcome === 'disk') toast(DISK_WON)
416
+ else if (resumed?.outcome === 'gone') toast(BOARD_GONE)
401
417
  urlReady.current = true
402
418
  // a link naming frames on a board with NO nodes: the canvas's boot fit never runs (it waits
403
419
  // for the first frame) - follow the frame to where it lives from here
@@ -447,7 +463,15 @@ export function App() {
447
463
  // selection against the newly loaded state. writeHash skips identical hashes, so
448
464
  // restores never echo back into history.
449
465
  useEffect(() => {
466
+ // the switch a navigation started, while it may still run: back/forward, a pasted link and `location.hash =` each
467
+ // fire popstate AND hashchange, and a second switch to the same board would supersede the first - a second board
468
+ // fetch, and a load that never committed in perf --loads
469
+ let routing: { hash: string; switches: number } | null = null
450
470
  const onPop = async () => {
471
+ // the same hash, and no switch or cancel since this router started its own (a board picked, a goto, a newer
472
+ // navigation): the second event of the navigation the first is carrying through - board, frame and view
473
+ if (routing && routing.hash === location.hash && routing.switches === switchCount()) return
474
+ const raw = location.hash
451
475
  const nav = navigated() // a reveal still looking up its board must not land after this
452
476
  // a lookup below still running when newer navigation lands - a link, a board picked, a step in play - is dropped
453
477
  const at = useStore.getState().board, step = useStore.getState().play?.at
@@ -473,9 +497,15 @@ export function App() {
473
497
  let s = useStore.getState()
474
498
  if (h.board && h.board !== s.board) {
475
499
  if (s.play) s.setPlay(null) // a stale overlay must never survive into another board
476
- await s.switchBoard(h.board)
500
+ const switched = switchFor(h.board, nav)
501
+ const mine = routing = { hash: raw, switches: switchCount() }
502
+ const landed = await switched
503
+ if (routing === mine) routing = null
504
+ // the switch failed (the projection effect re-syncs the URL), or a newer navigation came while this one's board
505
+ // was read - a link, a goto, a board picked - and may have landed on this same board first: the board is the
506
+ // newer one's then, and so are the selection, the mode and the camera
507
+ if (!landed) return
477
508
  s = useStore.getState()
478
- if (s.board !== h.board) return // switch failed; the projection effect will re-sync the URL
479
509
  }
480
510
  // the thread an old link names (Comments.tsx opens every other link's): now, or once the new board's comments load
481
511
  if (legacy && h.c) { if (s.board !== at) parkThread(h.c); else revealThread(h.c) }
@@ -493,13 +523,14 @@ export function App() {
493
523
  useStore.setState({ selection: keys })
494
524
  s.look(keys) // a link opened is a look
495
525
  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)
526
+ else setTimeout(() => { if (isLatest(nav)) (keys.length ? canvasCtl.fitNodes(keys) : canvasCtl.fitAll()) }, 60) // unless a newer navigation has the camera
497
527
  }
498
528
  }
499
529
  // hashchange too: pasting a link into the same tab or editing the URL bar changes
500
530
  // the hash WITHOUT a popstate - ignoring it let the projection rewrite the URL back.
501
531
  // 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.
532
+ // back/forward fires both: the second finds the first's switch on its way and leaves it
533
+ // be (above) - without a switch, the handler is idempotent under the double call.
503
534
  window.addEventListener('popstate', onPop)
504
535
  window.addEventListener('hashchange', onPop)
505
536
  return () => { window.removeEventListener('popstate', onPop); window.removeEventListener('hashchange', onPop) }
@@ -624,14 +655,15 @@ export function App() {
624
655
 
625
656
  if (data.type === 'sh:ready') {
626
657
  // 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
658
+ // ready-watchdog auto-renavigated past, or a same-URL reload's predecessor) can arrive here;
659
+ // dropped by generation and document before it touches anything, so a stale ready never marks
660
+ // a reloading frame ready, frees its admission slot or counts as seen
661
+ if (!fromLiveDocument(el, data)) return
631
662
  // a document that loaded again on its own (a full reload) is a new source revision: the
632
663
  // sleeping override of the previous document must not be trusted for this one
633
664
  if (s.nodes.find((n) => n.key === nodeKey)?.status === 'ready') s.bumpRev(nodeKey)
634
665
  s.setStatus(nodeKey, 'ready')
666
+ recorder.ready(nodeKey, data)
635
667
  frameReady(nodeKey)
636
668
  // the revision this document was served with (spec 26): a look counts up to it, and one older
637
669
  // than the frame's last edit reloads
@@ -639,7 +671,12 @@ export function App() {
639
671
  if (typeof data.doc === 'string') s.setShown(nodeKey, data.doc)
640
672
  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
673
  } else if (data.type === 'sh:error') {
674
+ // the same guard as sh:ready: an error from a document since replaced fails nothing and is not recorded
675
+ if (!fromLiveDocument(el, data)) return
642
676
  s.setStatus(nodeKey, 'error', String(data.message ?? 'unknown error'))
677
+ recorder.frameError(nodeKey, data)
678
+ } else if (data.type === 'sh:boot') {
679
+ recorder.booted(nodeKey, data) // a new document: its node's outcome starts over (spec 28 A1.7)
643
680
  } else if (data.type === 'sh:exit-interact') {
644
681
  if (s.interact === nodeKey) setInteract(null)
645
682
  } else if (data.type === 'sh:theme-applied') {
@@ -647,16 +684,16 @@ export function App() {
647
684
  } else if (data.type === 'sh:hmr') {
648
685
  s.bumpRev(nodeKey)
649
686
  } else if (data.type === 'sh:measure') {
650
- // Generation guard: the sender echoes ITS document's URL rev; a
687
+ // Generation and document guard: the sender echoes ITS document's URL rev and id; a
651
688
  // 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
689
+ // otherwise route as if it came from the current document. Compared against
690
+ // the iframe's CURRENT src and document - a stale one moves and keeps nothing.
691
+ if (!fromLiveDocument(el, data)) return
656
692
  // measureNode does the rest of the admission (content frames only,
657
693
  // frame-id match, finite positive, clamped)
658
- s.measureNode(nodeKey, String(data.frame ?? ''), Number(data.ownWidth), Number(data.measuredWidth), Number(data.height),
694
+ const took = s.measureNode(nodeKey, String(data.frame ?? ''), Number(data.ownWidth), Number(data.measuredWidth), Number(data.height),
659
695
  typeof data.settled === 'boolean' ? data.settled : undefined)
696
+ recorder.measured(nodeKey, data, took)
660
697
  } else if (data.type === 'sh:laser-copy') {
661
698
  // laser click = copy the element's full address for the agent: WHERE it lives on
662
699
  // the canvas ([board ▸ scene]) + frame source file + css path (+ jsx source loc)
@@ -761,6 +798,7 @@ export function App() {
761
798
  if (e.key === 'c' && !e.shiftKey) {
762
799
  const c = commentsStore()
763
800
  if (!c.commentMode && s.board === UNPLACED) return void toast(NO_COMMENTS_HERE)
801
+ if (!c.commentMode && stoppedFor('Comments need the canvas running')) return
764
802
  if (!c.commentMode) s.setLaser(false)
765
803
  c.setMode(!c.commentMode)
766
804
  toast(c.commentMode ? 'comment mode off' : 'comment mode - click an element in a frame')
@@ -882,6 +920,8 @@ export function App() {
882
920
  return (
883
921
  <div ref={appRef} tabIndex={-1} className={`sh-app${dark ? ' dark' : ''}${interacting ? ' interacting' : ''}${laneLift}`}>
884
922
  <Canvas />
923
+ {/* the scroll edge under the Mac app's transparent strip (0.27.2, A3.8 #31): over the world, under the chrome */}
924
+ {TOP ? <div className="sh-edge" aria-hidden="true" /> : null}
885
925
  <SelectionBar />
886
926
 
887
927
  {/* floating pill panel (no top bar - spec); panel and fab are both always
@@ -1067,6 +1107,7 @@ export function App() {
1067
1107
  {CONFIG.setup
1068
1108
  ? <div className="sh-banner">no app detected - designs would be built from nothing. See design/instructions/setup.md, then restart</div>
1069
1109
  : 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>}
1110
+ {stopped && <StoppedBanner />}
1070
1111
  <UpdatePill />
1071
1112
 
1072
1113
  {/* Jam V2 (spec 27): the lane, the focus panel, the notes card, the recording ring */}
@@ -1076,6 +1117,125 @@ export function App() {
1076
1117
  )
1077
1118
  }
1078
1119
 
1120
+ /** The canvas stopped (spec 28 A1.11): what happened and the way back - and, only when this tab holds some, that
1121
+ * its unsaved edits are kept. It sits on the toolbar's centre line in the free gap between the sidebar and the
1122
+ * toolbar, or just below the toolbar row when that gap is too narrow; it never covers either, and Hide UI (H)
1123
+ * leaves it up. In play it wears the play chrome's dark skin. */
1124
+ function StoppedBanner() {
1125
+ const link = useLink((s) => s.link)
1126
+ const unsaved = useLink((s) => s.unsaved)
1127
+ const play = useStore((s) => !!s.play)
1128
+ const ref = useRef<HTMLDivElement>(null)
1129
+ const cmd = <code>npx marver dev</code>
1130
+ const what = link === 'resuming' ? <>This canvas is back{unsaved ? ' - saving your edits' : ''}</>
1131
+ : link === 'elsewhere' ? <>Another canvas is running on this address - stop it and run {cmd} to bring this one back</>
1132
+ : <>This canvas stopped - run {cmd} to bring it back</>
1133
+ const kept = unsaved && link !== 'resuming'
1134
+ useLayoutEffect(() => {
1135
+ const el = ref.current
1136
+ if (!el) return
1137
+ let raf = 0
1138
+ const place = () => { cancelAnimationFrame(raf); raf = 0; placeBanner(el) }
1139
+ const soon = () => { raf ||= requestAnimationFrame(place) }
1140
+ place()
1141
+ // what moves the gap: the window, the chrome around it opening, closing or changing size, play, Hide UI
1142
+ const seen = new Set<Element>()
1143
+ const ro = new ResizeObserver(soon)
1144
+ const watch = () => { for (const n of el.parentElement?.querySelectorAll(OBSTACLES) ?? []) if (!seen.has(n)) { seen.add(n); ro.observe(n) } }
1145
+ watch()
1146
+ const mo = new MutationObserver(() => { watch(); soon() })
1147
+ if (el.parentElement) mo.observe(el.parentElement, { childList: true, subtree: true, attributes: true, attributeFilter: ['class'] })
1148
+ mo.observe(document.body, { attributes: true, attributeFilter: ['class'] })
1149
+ window.addEventListener('resize', soon)
1150
+ return () => { cancelAnimationFrame(raf); ro.disconnect(); mo.disconnect(); window.removeEventListener('resize', soon) }
1151
+ }, [link, unsaved, play])
1152
+ return (
1153
+ <div ref={ref} className={`sh-banner sh-stopped${play ? ' dark' : ''}`} role="status" data-link={link}>
1154
+ {what}{kept && <><span className="dot"> · </span><span className="kept">your unsaved edits are kept in this tab</span></>}
1155
+ </div>
1156
+ )
1157
+ }
1158
+
1159
+ /** The chrome the stopped banner keeps clear of: the sidebar (or its button) on the left, the toolbar (or its
1160
+ * button) on the right - the canvas's own, or play's brand and toolbar pills over it. */
1161
+ 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'
1162
+ const BANNER_GAP = 12
1163
+ function placeBanner(el: HTMLElement) {
1164
+ const app = el.parentElement
1165
+ if (!app) return
1166
+ const edge = parseFloat(getComputedStyle(app).getPropertyValue('--edge')) || 10
1167
+ // a box in the app's own coordinates, from layout - never the rect mid-morph (a closing panel scales down)
1168
+ const box = (n: HTMLElement) => {
1169
+ let x = 0, y = 0
1170
+ for (let e: HTMLElement | null = n; e && e !== app; e = e.offsetParent as HTMLElement | null) { x += e.offsetLeft; y += e.offsetTop }
1171
+ return { left: x, top: y, right: x + n.offsetWidth, bottom: y + n.offsetHeight }
1172
+ }
1173
+ const pick = (root: Element, sel: string) => {
1174
+ const n = root.querySelector<HTMLElement>(sel)
1175
+ return n && !n.matches('.closed, .hidden') && n.offsetWidth ? box(n) : null
1176
+ }
1177
+ let left: ReturnType<typeof box> | null = null, right: ReturnType<typeof box> | null = null
1178
+ if (!document.body.classList.contains('sh-hide-ui')) {
1179
+ const stage = app.querySelector(':scope > .sh-play')
1180
+ if (stage) {
1181
+ left = pick(stage, ':scope > .sh-play-brand')
1182
+ right = pick(stage, ':scope > .sh-play-pill:not(.sh-play-brand)') ?? pick(stage, ':scope > .sh-pill-fab')
1183
+ } else {
1184
+ left = pick(app, ':scope > .sh-panel') ?? pick(app, ':scope > .sh-fab')
1185
+ right = pick(app, ':scope > nav.sh-pill') ?? pick(app, ':scope > .sh-pill-fab')
1186
+ }
1187
+ }
1188
+ // the toolbar row: its centre line, and its foot - the sidebar runs down the page, so it is no part of the row
1189
+ const tall = !!left && left.bottom - left.top > 64
1190
+ const row = [right, tall ? null : left].filter((b): b is NonNullable<typeof b> => !!b)
1191
+ // with no row to measure: the toolbar's line, below the Mac app's strip when the shell took the inset
1192
+ const mid = row.length ? Math.max(...row.map((b) => (b.top + b.bottom) / 2)) : TOP + edge + 23
1193
+ const foot = Math.max(TOP + edge + 46, ...row.map((b) => b.bottom))
1194
+ const W = app.clientWidth
1195
+ const from = left ? left.right + BANNER_GAP : edge, to = right ? right.left - BANNER_GAP : W - edge
1196
+ const at = (where: 'row' | 'stack' | 'below', x0: number, x1: number, top?: number) => {
1197
+ el.dataset.at = where
1198
+ el.style.left = `${Math.round(x0 + Math.max(0, (x1 - x0 - el.offsetWidth) / 2))}px`
1199
+ el.style.top = `${Math.round(top ?? mid - el.offsetHeight / 2)}px`
1200
+ }
1201
+ el.style.transform = 'none'
1202
+ el.dataset.at = 'row'
1203
+ // one line in the gap
1204
+ el.style.whiteSpace = 'nowrap'
1205
+ el.style.maxWidth = 'none'
1206
+ const line = el.offsetHeight
1207
+ if (el.offsetWidth <= to - from) return at('row', from, to)
1208
+ // two lines in the gap: what happened, then the kept edits under it
1209
+ if (el.querySelector('.kept')) {
1210
+ el.dataset.at = 'stack'
1211
+ if (el.offsetWidth <= to - from) return at('stack', from, to)
1212
+ el.dataset.at = 'row'
1213
+ }
1214
+ // or wrapped in two, the box no wider than its longest line
1215
+ el.style.whiteSpace = 'normal'
1216
+ el.style.maxWidth = `${to - from}px`
1217
+ if (to - from >= 220 && el.offsetHeight <= line + 18) { hug(el); return at('row', from, to) }
1218
+ // too narrow: under the toolbar row, centred in what the sidebar leaves, the kept edits on a line of their own
1219
+ el.dataset.at = 'below'
1220
+ const lo = tall && left ? left.right + BANNER_GAP : edge, hi = W - edge
1221
+ el.style.maxWidth = `${Math.max(160, Math.min(680, hi - lo))}px`
1222
+ hug(el)
1223
+ at('below', lo, hi, row.length ? foot + 8 : edge) // no row with the chrome hidden: the top edge
1224
+ }
1225
+ /** A wrapped banner's box shrinks to its longest line (a max-width box stays as wide as it may be). */
1226
+ function hug(el: HTMLElement) {
1227
+ const r = document.createRange()
1228
+ r.selectNodeContents(el)
1229
+ const lines = [...r.getClientRects()]
1230
+ if (!lines.length) return
1231
+ const cs = getComputedStyle(el)
1232
+ const chrome = el.offsetWidth - el.clientWidth + parseFloat(cs.paddingLeft) + parseFloat(cs.paddingRight)
1233
+ const need = Math.ceil(Math.max(...lines.map((l) => l.right)) - Math.min(...lines.map((l) => l.left)) + chrome) + 1
1234
+ const was = el.style.maxWidth, h = el.offsetHeight
1235
+ el.style.maxWidth = `${Math.min(need, el.offsetWidth)}px`
1236
+ if (el.offsetHeight > h) el.style.maxWidth = was // never a line more than it had (a balanced wrap re-flows)
1237
+ }
1238
+
1079
1239
  /** The bottom-right notification corner. Plain toasts render as before.
1080
1240
  * Jam pills are FRAME-FIRST (icon + frame title, then Marver · preview) and stack as a DECK:
1081
1241
  * 1-2 show in full; 3+ collapse to the newest pill with two card edges peeking beneath and a
@@ -1129,10 +1289,12 @@ function JamAvatar({ author }: { author: { name?: string; avatar?: string; id?:
1129
1289
  async function viewNote(note: import('./store.ts').JamNote, dismiss: () => void) {
1130
1290
  if (revealThread(note.threadId)) { dismiss(); return }
1131
1291
  const s = useStore.getState()
1292
+ // a navigation: a link still finding its board gives way to it - and it to a newer one, wherever this one has got to
1293
+ const nav = navigated()
1132
1294
  // a thread in the old all-scenes log has no board of its own: its frame's board shows it (spec 26)
1133
- if (note.board === ALL_SCENES) { if (note.frame) await revealFrame(note.frame) }
1134
- else if (note.board && s.board !== note.board) await s.switchBoard(note.board)
1135
- for (let i = 0; i < 12; i++) {
1295
+ if (note.board === ALL_SCENES) { if (note.frame) await revealFrame(note.frame, nav) }
1296
+ else if (note.board && s.board !== note.board && !await switchFor(note.board, nav)) return
1297
+ for (let i = 0; i < 12 && isLatest(nav); i++) {
1136
1298
  if (revealThread(note.threadId)) { dismiss(); return }
1137
1299
  await new Promise((r) => setTimeout(r, 250))
1138
1300
  }
@@ -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
@@ -5,9 +5,11 @@
5
5
  * size via --sh-inv (the vbadge pattern) so zoom never shrinks them away, and never
6
6
  * overlap (pin-layout.ts places them).
7
7
  */
8
+ import { TOP } from './inset.ts'
8
9
  import { useEffect, useMemo, useRef, useState } from 'react'
9
10
  import { createPortal } from 'react-dom'
10
11
  import { avatarFallback, useComments } from './comments-store.ts'
12
+ import { api } from './api.ts'
11
13
  import { CONFIG, useStore, type Node } from './store.ts'
12
14
  import { threadHostKey } from './keys.ts'
13
15
  import { isNoteAnchor, resolveNoteAnchor, useNotes } from './notes.ts'
@@ -21,7 +23,7 @@ import { TagStatus } from './jam-ui.tsx'
21
23
  import { CaptureBlock } from './jam-panel.tsx'
22
24
  import { useJamQueue } from './jam-queue.ts'
23
25
  import { mentionAlerts, mentionPeople, mentionQueryAt, parseBody, type MentionPerson } from './mentions.ts'
24
- import { ROUTE, slideSize, stageFit } from '../const.ts'
26
+ import { slideSize, stageFit } from '../const.ts'
25
27
  import type { AgentMeta, Thread } from '../../shared/events.ts'
26
28
 
27
29
  /** Tint the pin / composer / thread card EDGES (border, outline, focus ring) in the anchored
@@ -728,15 +730,16 @@ export function ThreadCard({ thread, at, bounds, nodeKey, side = 'r', flank, sta
728
730
  // a device/theme switch resizes .sh-play-stage and a window resize shifts it.
729
731
  const computeStagePos = (): React.CSSProperties | null => {
730
732
  if (!stage) return null
731
- const W = 320, M = 12, maxH = Math.min(660, window.innerHeight - 2 * M)
733
+ // the view below the Mac app's strip when the shell took the inset (TOP 44)
734
+ const W = 320, M = 12, maxH = Math.min(660, window.innerHeight - TOP - 2 * M)
732
735
  const rect = document.querySelector('.sh-play-stage')?.getBoundingClientRect()
733
- if (!rect) return { position: 'fixed', left: M, top: 72, maxHeight: maxH }
736
+ if (!rect) return { position: 'fixed', left: M, top: TOP + 72, maxHeight: maxH }
734
737
  const roomR = window.innerWidth - rect.right >= W + 30
735
738
  const roomL = rect.left >= W + 30
736
739
  const s: 'l' | 'r' = at.x < bounds.w / 2 ? (roomL ? 'l' : 'r') : (roomR ? 'r' : 'l')
737
740
  const x = Math.min(Math.max(s === 'r' ? rect.right + 18 : rect.left - 18 - W, M), window.innerWidth - W - M)
738
741
  // worst-case clamp (content = maxH): even a full-height thread keeps its composer on screen
739
- const y = Math.min(Math.max(rect.top + at.y - 36, M), Math.max(M, window.innerHeight - maxH - M))
742
+ const y = Math.min(Math.max(rect.top + at.y - 36, TOP + M), Math.max(TOP + M, window.innerHeight - maxH - M))
740
743
  return { position: 'fixed', left: x, top: y, maxHeight: maxH }
741
744
  }
742
745
  const [stagePos, setStagePos] = useState<React.CSSProperties | null>(computeStagePos)
@@ -901,7 +904,7 @@ export function IdentityDialog() {
901
904
  // an invite link knows WHO it's for - show it (the token is the proof of holding)
902
905
  useEffect(() => {
903
906
  if (!needs || !invite) return setInvitedAs('')
904
- fetch(`${ROUTE}/api/invite-info?token=${encodeURIComponent(invite)}`)
907
+ api(`invite-info?token=${encodeURIComponent(invite)}`)
905
908
  .then((r) => (r.ok ? r.json() : null))
906
909
  .then((d) => d?.email && setInvitedAs(d.email))
907
910
  .catch(() => { /* chip just stays hidden */ })
@@ -2,6 +2,7 @@ import { useEffect, useLayoutEffect, useRef, useState, type ReactNode } from 're
2
2
  import { createPortal } from 'react-dom'
3
3
  import { useStore, SOURCE_REVEALED } from './store.ts'
4
4
  import { UNPLACED } from './hash.ts'
5
+ import { TOP } from './inset.ts'
5
6
 
6
7
  /** Copy text to the clipboard, toasting the outcome. Success is confirmed out loud; a
7
8
  * blocked clipboard (no user gesture / permission) says so instead of failing silently. */
@@ -35,8 +36,9 @@ export function useContextMenu() {
35
36
  e.preventDefault()
36
37
  const MENU_W = 240 // the CSS max-width; labels ellipsize inside it
37
38
  // a menu taller than the window (many "Move to …" folders) pins to the top edge and scrolls
38
- const h = Math.min(items.length * 32 + 12, window.innerHeight - 16)
39
- setMenu({ x: Math.max(8, Math.min(e.clientX, window.innerWidth - MENU_W - 8)), y: Math.max(8, Math.min(e.clientY, window.innerHeight - h - 8)), items })
39
+ // ...and never under the Mac app's strip (TOP 44 when the shell took the inset)
40
+ const h = Math.min(items.length * 32 + 12, window.innerHeight - 16 - TOP)
41
+ setMenu({ x: Math.max(8, Math.min(e.clientX, window.innerWidth - MENU_W - 8)), y: Math.max(TOP + 8, Math.min(e.clientY, window.innerHeight - h - 8)), items })
40
42
  }
41
43
  return { menu, open, close: () => setMenu(null) }
42
44
  }
@@ -50,7 +52,7 @@ export function ContextMenu({ menu, close }: { menu: MenuState | null; close: ()
50
52
  useLayoutEffect(() => {
51
53
  if (!menu || !ref.current) return
52
54
  const h = ref.current.getBoundingClientRect().height
53
- setTop(Math.max(8, Math.min(menu.y, window.innerHeight - h - 8)))
55
+ setTop(Math.max(TOP + 8, Math.min(menu.y, window.innerHeight - h - 8)))
54
56
  }, [menu, panel])
55
57
  useEffect(() => {
56
58
  if (!menu) return
@@ -22,10 +22,12 @@ 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])
@@ -15,6 +15,10 @@ 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'
19
+
20
+ /** App.tsx's headless-run probe (perf-run-probe.ts): a run's page is always a dev canvas, never a locked bundle. */
21
+ export function startPerfRunProbe(): void {}
18
22
 
19
23
  export class ShellBoundary extends Component<{ children: ReactNode }, { err: Error | null }> {
20
24
  state = { err: null as Error | null }
@@ -96,10 +100,9 @@ export function App() {
96
100
 
97
101
  // back/forward + pasted links, within what the lock allows
98
102
  useEffect(() => {
99
- let popSeq = 0
100
103
  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()
104
+ // a lookup newer navigation overtook - a link, a goto, a step on the stage - is dropped
105
+ const nav = navigated(), was = useStore.getState()
103
106
  const parsed = parseHash()
104
107
  const raw = parsed.board === UNPLACED ? {} : parsed // dev's view, and what it names: not here
105
108
  // an old All Scenes link lands on a real board; it, and the bare #/, with no board: the landing one
@@ -107,11 +110,11 @@ export function App() {
107
110
  const h = r.hash
108
111
  const board = h.board ?? (h.focus ? undefined : await landingBoard())
109
112
  const s = useStore.getState()
110
- if (mine !== popSeq || s.board !== was.board || s.play?.at !== was.play?.at) return
113
+ if (!isLatest(nav) || s.board !== was.board || s.play?.at !== was.play?.at) return
111
114
  if (r.notice) s.toast(r.notice)
112
115
  if (h.c) pendingThread = h.c
113
116
  if (board && board !== s.board) {
114
- await s.switchBoard(board)
117
+ if (!await switchFor(board, nav)) return // failed, or a newer navigation's board and stage by now
115
118
  useStore.getState().setPlay(null) // the stage restarts on the board the link names, at its frame
116
119
  if (h.play?.slides) enterSlides(h.play)
117
120
  else if (h.play) enterPlay(h.play)