@marver-design/marver 0.29.0 → 0.30.1

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 (76) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/README.md +2 -1
  3. package/dist/{anchor-check-DhlpKl2K.mjs → anchor-check-Bv4o-R2T.mjs} +1 -1
  4. package/dist/{build-CWbrb2bl.mjs → build-zWGXSzly.mjs} +5 -4
  5. package/dist/cli.mjs +5 -5
  6. package/dist/{daemon-Sc_z8gT6.mjs → daemon-CChgWJNq.mjs} +2 -2
  7. package/dist/{dev-DWBKQhxf.mjs → dev-DOgIITpT.mjs} +8 -8
  8. package/dist/{perf-Denssrko.mjs → perf-6MOTHxay.mjs} +710 -99
  9. package/dist/perf-BCxAo0IS.mjs +1743 -0
  10. package/dist/{plugin-DqoZB-D6.mjs → plugin-CFWBcAba.mjs} +928 -539
  11. package/dist/{poster-CrsjqhY4.mjs → poster-DPPpQiva.mjs} +1 -1
  12. package/dist/{publish-bakes-DW-NDgU2.mjs → publish-bakes-_Zx8crP3.mjs} +2 -2
  13. package/dist/{recover-GtJ9UDAB.mjs → recover-mDUVsnPd.mjs} +1 -1
  14. package/dist/{shot-T04Ixrvq.mjs → shot-d4h_hJi9.mjs} +3 -3
  15. package/docs/app.md +194 -0
  16. package/docs/performance.md +100 -19
  17. package/package.json +1 -1
  18. package/src/client/frame-host/bridge.js +17 -8
  19. package/src/client/frame-host/inplace.ts +124 -0
  20. package/src/client/frame-host/inspect.d.ts +1 -0
  21. package/src/client/frame-host/inspect.js +13 -4
  22. package/src/client/frame-host/main.tsx +12 -3
  23. package/src/client/frame-host/messages.ts +85 -0
  24. package/src/client/frame-host/signals.d.ts +15 -0
  25. package/src/client/frame-host/signals.js +219 -0
  26. package/src/client/recorder-level.ts +41 -0
  27. package/src/client/shell/App.tsx +158 -88
  28. package/src/client/shell/BoardList.tsx +103 -48
  29. package/src/client/shell/Comments.tsx +66 -42
  30. package/src/client/shell/ContextMenu.tsx +3 -2
  31. package/src/client/shell/JamSurface.tsx +116 -71
  32. package/src/client/shell/LockedApp.tsx +19 -3
  33. package/src/client/shell/Play.tsx +94 -58
  34. package/src/client/shell/StatusPicker.tsx +19 -9
  35. package/src/client/shell/Toolbar.tsx +15 -7
  36. package/src/client/shell/api.ts +18 -4
  37. package/src/client/shell/app-bridge.ts +12 -6
  38. package/src/client/shell/app-perf.ts +31 -1
  39. package/src/client/shell/canvas/Canvas.tsx +17 -6
  40. package/src/client/shell/canvas/FrameNode.tsx +25 -12
  41. package/src/client/shell/canvas/Sticky.tsx +4 -2
  42. package/src/client/shell/canvas/ctl.ts +2 -0
  43. package/src/client/shell/canvas/ready-watch.ts +4 -0
  44. package/src/client/shell/canvas/sleep.ts +2 -0
  45. package/src/client/shell/canvas/updates.ts +13 -6
  46. package/src/client/shell/commands.ts +765 -0
  47. package/src/client/shell/comments-store.ts +42 -27
  48. package/src/client/shell/goto.ts +11 -6
  49. package/src/client/shell/jam-keys.ts +141 -75
  50. package/src/client/shell/jam-lane.tsx +19 -12
  51. package/src/client/shell/jam-panel.tsx +61 -48
  52. package/src/client/shell/jam-session.tsx +41 -37
  53. package/src/client/shell/jam-state.ts +9 -1
  54. package/src/client/shell/jam-surface-parts.tsx +8 -6
  55. package/src/client/shell/jam-ui.tsx +9 -6
  56. package/src/client/shell/jam-voice.ts +4 -2
  57. package/src/client/shell/main.tsx +7 -1
  58. package/src/client/shell/marks-ui.tsx +11 -0
  59. package/src/client/shell/perf.ts +51 -5
  60. package/src/client/shell/recorder-core.ts +4 -1
  61. package/src/client/shell/recorder-hmr.ts +36 -0
  62. package/src/client/shell/recorder-reloads.ts +264 -0
  63. package/src/client/shell/recorder-seams.ts +116 -0
  64. package/src/client/shell/recorder-self.ts +73 -0
  65. package/src/client/shell/recorder-signals-core.ts +139 -0
  66. package/src/client/shell/recorder-signals.ts +485 -0
  67. package/src/client/shell/recorder.ts +118 -43
  68. package/src/client/shell/store.ts +112 -32
  69. package/src/client/shell/whiteout-probes.ts +3 -1
  70. package/src/client/stage/main.tsx +10 -5
  71. package/src/shared/app-api.ts +28 -6
  72. package/src/shared/app-perf.ts +99 -6
  73. package/src/shared/app-report.ts +586 -0
  74. package/src/shared/perf-records.ts +445 -0
  75. package/src/shared/perf-run.ts +6 -2
  76. package/dist/perf-jam-CLkERSHo.mjs +0 -642
@@ -27,6 +27,8 @@ import { stranded, withWs } from './api.ts'
27
27
  import { poweredByUrl } from '../../shared/utm.ts'
28
28
  import { canvasCtl } from './canvas/ctl.ts'
29
29
  import { recorder } from './recorder.ts'
30
+ import { perfSeams } from './recorder-seams.ts'
31
+ import { cmd, endAfterFrames, endOnStage, keysOf, type CmdHandle, type CmdOpts, type CmdName } from './commands.ts'
30
32
  import { revealFrame, switchFor } from './goto.ts'
31
33
  import { Tip } from './Tip.tsx'
32
34
  import { keyAllowed } from '../frame-host/keys.js'
@@ -146,13 +148,13 @@ export function enterFocus(at?: string, over?: { device?: string; theme?: string
146
148
 
147
149
  /** Switch boards WITHOUT leaving play: the overlay stays up over the canvas churn, then
148
150
  * a fresh stage mounts at the new board's start (PlayInner is keyed by board). */
149
- async function switchPlayBoard(name: string) {
151
+ async function switchPlayBoard(name: string, h: CmdHandle) {
150
152
  const s = useStore.getState()
151
- if (name === s.board) return
153
+ if (name === s.board) { h.cancel('same-board'); return }
152
154
  const device = s.play?.device // the device is the viewer's choice - it survives the switch
153
155
  // a navigation like any other: a link still reading its board gives way to it, and it to a newer one - which then
154
156
  // has the board, the stage and the camera
155
- if (!await switchFor(name)) return
157
+ if (!await switchFor(name)) { h.cancel('superseded'); return }
156
158
  const dev = device && device !== 'slide' ? { device } : undefined // the deck's own size does not follow to a prototype
157
159
  if (playsAsSlides(name)) enterSlides(device ? { device } : undefined)
158
160
  else enterPlay(dev)
@@ -199,7 +201,7 @@ function BoardMenu({ current }: { current: string }) {
199
201
  </Tip>
200
202
  <Popover pop={pop} dark>
201
203
  {names.map((n) => (
202
- <button key={n} onClick={() => { pop.setOpen(false); switchPlayBoard(n) }}>
204
+ <button key={n} onClick={() => { pop.setOpen(false); switchPlayBoard(n, cmd('play-board', { via: 'click', in: 'pill', board: n })) }}>
203
205
  <span>{boardLabel(n)}</span>
204
206
  {n === current && <CheckIcon size={13} className="chk" />}
205
207
  </button>
@@ -348,13 +350,13 @@ function PlayInner() {
348
350
  if (!p) return
349
351
  iframeRef.current.src = withWs(`${ROUTE}/stage/?at=${encodeURIComponent(p.at)}&theme=${encodeURIComponent(p.theme)}${slParams(p)}&r=${playNav}`)
350
352
  }, [playNav])
351
- const applyUpdate = () => useStore.getState().applyPlayUpdate()
353
+ const applyUpdate = () => { cmd('play-update', { via: 'click', in: 'pill' }); useStore.getState().applyPlayUpdate() }
352
354
 
353
355
  // laser / comment ride the same rail as canvas frames, broadcast to the stage iframe.
354
356
  // Re-sent on stage-ready (below) so a stage reload restores the mode.
355
357
  const laserInspect = useStore((s) => s.laserInspect)
356
- useEffect(() => { postStage({ type: 'sh:laser', on: laser, inspect: laserInspect }) }, [laser, laserInspect])
357
- useEffect(() => { postStage({ type: 'sh:pick', on: commentMode, quiet: !useComments.getState().showAnchor }) }, [commentMode, playShowAnchor])
358
+ useEffect(() => { postStage({ type: 'sh:laser', on: laser, inspect: laserInspect, t: perfSeams.transition('mode') }) }, [laser, laserInspect])
359
+ useEffect(() => { postStage({ type: 'sh:pick', on: commentMode, quiet: !useComments.getState().showAnchor, t: perfSeams.transition('mode') }) }, [commentMode, playShowAnchor])
358
360
 
359
361
  /** Play torn down, nothing more: false where there is no way out */
360
362
  const leave = (): boolean => {
@@ -366,6 +368,8 @@ function PlayInner() {
366
368
  useStore.getState().setPlay(null)
367
369
  return true
368
370
  }
371
+ /** Open in canvas, or an Esc with nothing live (spec 30 `play-exit`): a board with no way out stays. */
372
+ const exitFrom = (how: CmdOpts) => { const h = cmd('play-exit', how); if (noDoor) h.noop('no-door'); exit() }
369
373
  const exit = () => {
370
374
  const { at } = useStore.getState().play ?? {}
371
375
  if (!leave()) return
@@ -383,17 +387,19 @@ function PlayInner() {
383
387
  if (p.slides) { useStore.getState().setPlay({ ...p, device: name === 'fill' ? 'fill' : 'slide' }); return }
384
388
  if (CONFIG.viewports[name] || name === 'fill') useStore.getState().setPlay({ ...p, device: name })
385
389
  }
386
- const setTheme = (t: string) => {
390
+ const setTheme = (t: string, how?: CmdOpts) => {
387
391
  const p = useStore.getState().play
388
392
  if (!p) return
393
+ if (how) cmd('theme', how)
389
394
  useStore.getState().setPlay({ ...p, theme: t })
390
- postStage({ type: 'sh:set-theme', theme: t })
395
+ postStage({ type: 'sh:set-theme', theme: t, t: perfSeams.transition('theme') })
391
396
  }
392
397
  /** Walk to a frame: the stage swaps silently; state + URL follow via the projection. */
393
398
  const goTo = (at: string) => playCtl.setAt(at)
394
- const step = (dir: 1 | -1) => {
399
+ const step = (dir: 1 | -1, how: CmdOpts) => {
400
+ const h = cmd(dir === 1 ? 'play-next' : 'play-prev', how)
395
401
  const p = useStore.getState().play
396
- if (!p || p.focus) return // focus is one frame - no walking
402
+ if (!p || p.focus) { h.noop('end'); return } // focus is one frame - no walking
397
403
  if (p.slides) {
398
404
  // a deck never wraps: past the last slide is the end, before the first is
399
405
  // the start. A variant swap can put `at` off the frozen deck - step from
@@ -406,20 +412,27 @@ function PlayInner() {
406
412
  if (g) i = deck.findIndex((id) => frames.find((f) => f.id === id)?.variantGroup === g)
407
413
  }
408
414
  const next = i === -1 ? deck[0] : deck[Math.min(deck.length - 1, Math.max(0, i + dir))]
409
- if (next && next !== p.at) goTo(next)
415
+ if (next && next !== p.at) { endOnStage(h, next); goTo(next) } else h.noop('end')
410
416
  return
411
417
  }
412
418
  const list = playList()
413
- if (!list.length) return
419
+ if (!list.length) { h.noop('end'); return }
414
420
  const i = list.indexOf(p.at)
415
421
  // an off-board frame has no position: → restarts, ← goes to the last board frame
416
- goTo(i === -1 ? (dir === 1 ? list[0] : list[list.length - 1]) : list[(i + dir + list.length) % list.length])
422
+ const to = i === -1 ? (dir === 1 ? list[0] : list[list.length - 1]) : list[(i + dir + list.length) % list.length]
423
+ if (to === p.at) { h.noop('end'); return } // a board of one frame
424
+ endOnStage(h, to)
425
+ goTo(to)
417
426
  }
418
- const restart = () => {
427
+ const restart = (how: CmdOpts) => {
428
+ const h = cmd('play-restart', how)
419
429
  const p = useStore.getState().play
420
- if (p?.focus) return
430
+ if (p?.focus) { h.noop('no-frames'); return }
421
431
  const list = p?.slides ? currentDeck() : playList()
422
- if (list.length) goTo(list[0])
432
+ if (!list.length) { h.noop('no-frames'); return }
433
+ // already on the first: nothing to swap, nothing for the stage to say
434
+ if (list[0] === p?.at) endAfterFrames(h); else endOnStage(h, list[0])
435
+ goTo(list[0])
423
436
  }
424
437
 
425
438
  /** Variant siblings of the CURRENT frame present on this board: the
@@ -435,13 +448,16 @@ function PlayInner() {
435
448
  .filter((f) => f.variantGroup === cur.variantGroup && f.kind === 'tsx' && onBoard.has(f.id))
436
449
  .sort((a, b) => (a.variant ?? '').localeCompare(b.variant ?? ''))
437
450
  }
438
- const switchVariant = (dir: 1 | -1) => {
451
+ const switchVariant = (dir: 1 | -1, how: CmdOpts) => {
452
+ const h = cmd('play-variant', how)
439
453
  const p = useStore.getState().play
440
- if (!p) return
454
+ if (!p) { h.noop('no-variants'); return }
441
455
  const vs = variantList()
442
- if (vs.length < 2) return
456
+ if (vs.length < 2) { h.noop('no-variants'); return }
443
457
  const i = vs.findIndex((f) => f.id === p.at)
444
- goTo(vs[(i + dir + vs.length) % vs.length].id)
458
+ const to = vs[(i + dir + vs.length) % vs.length].id
459
+ endOnStage(h, to)
460
+ goTo(to)
445
461
  }
446
462
 
447
463
  // history restores + walk: swap the stage silently (no sh:stage-at back) and track here
@@ -470,9 +486,11 @@ function PlayInner() {
470
486
  const data = e.data
471
487
  if (!data || typeof data.type !== 'string') return
472
488
  const s = useStore.getState()
489
+ // the recorder's (spec 30): every stage message, before the shell acts on it - never consumed here
490
+ perfSeams.stageMessage.emit(data)
473
491
  // Jam (spec 27): the stage records like a frame; a key the shell owns comes back as sh:key
474
492
  if (onFrameMessage('stage', data)) return
475
- if (data.type === 'sh:key') { if (typeof data.key === 'string') jamKey({ key: data.key, shift: !!data.shift, alt: !!data.alt, meta: !!data.meta, ctrl: !!data.ctrl }); return }
493
+ if (data.type === 'sh:key') { if (typeof data.key === 'string') jamKey({ key: data.key, shift: !!data.shift, alt: !!data.alt, meta: !!data.meta, ctrl: !!data.ctrl }, 'stage'); return }
476
494
  if (data.type === 'sh:stage-ready') {
477
495
  frameReady('stage')
478
496
  // an iframe reload (registry HMR invalidation) boots at the frozen initial src -
@@ -492,7 +510,8 @@ function PlayInner() {
492
510
  useStore.setState({ stageShown: { at: data.at, shown: `${String(data.epoch ?? '')}:${Number(data.doc) || 0}` } })
493
511
  } else if (data.type === 'sh:stage-at') {
494
512
  const p = s.play
495
- if (p && typeof data.at === 'string') stageNavigated(data.at, () => s.setPlay({ ...p, at: data.at }))
513
+ // a data-goto in the stage, handled there in place (stage/main.tsx:277)
514
+ if (p && typeof data.at === 'string') { endOnStage(cmd('goto', { via: 'click', in: 'stage', frame: data.at }), data.at); stageNavigated(data.at, () => s.setPlay({ ...p, at: data.at })) }
496
515
  } else if (data.type === 'sh:stage-exit') {
497
516
  exit()
498
517
  } else if (data.type === 'sh:stage-error') {
@@ -506,8 +525,9 @@ function PlayInner() {
506
525
  if (s.playNav && !s.stageShown) useStore.setState({ playUpdateRevision: 'retry' }) // an Update that failed: offer it again
507
526
  }
508
527
  } else if (data.type === 'sh:stage-key') {
509
- if (data.meta && data.key === '/') toggleCollapse()
510
- else handleKey(String(data.key), String(data.code), !!data.alt)
528
+ if (data.meta && data.key === '/') { cmd('toolbar', { via: 'key', in: 'stage', keys: 'Meta+/' }); toggleCollapse() }
529
+ // the stage's background click, posted as Space, says so (#50)
530
+ else handleKey(String(data.key), String(data.code), !!data.alt, data.origin === 'click' ? { via: 'click', in: 'stage' } : { via: 'key', in: 'stage', keys: keysOf({ key: String(data.key), alt: !!data.alt }) })
511
531
  } else if (data.type === 'sh:picked') {
512
532
  // comment pick from the stage: stage the draft on the walked frame (its canvas
513
533
  // node when one is on this board, so the thread also lands on the canvas). Stamp
@@ -519,11 +539,12 @@ function PlayInner() {
519
539
  const at = String(data.id ?? '')
520
540
  if (!at || at !== s.play?.at) return
521
541
  const n = s.nodes.find((x) => x.frame === at && !x.missing)
542
+ cmd('comment-pick', { via: 'click', in: 'stage', frame: at })
522
543
  c.setDraft({ nodeKey: n?.key ?? '', frame: at, anchor: data.anchor })
523
544
  } else if (data.type === 'sh:frame-down') {
524
545
  const c = commentsStore()
525
- if (c.active) c.setActive(null)
526
- letGoOfTile() // a click in the prototype closes the review open over it, as on the canvas
546
+ if (c.active) { cmd('thread-close', { via: 'click', in: 'stage' }); c.setActive(null) }
547
+ letGoOfTile({ via: 'click', in: 'stage' }) // a click in the prototype closes the review open over it, as on the canvas
527
548
  } else if (data.type === 'sh:laser-copy') {
528
549
  // laser click in the prototype: copy the element's address ([board ▸ scene] +
529
550
  // frame file + css path) and confirm in the frame's own hover label, like the canvas
@@ -532,9 +553,10 @@ function PlayInner() {
532
553
  // drop a stale post that outran a stage swap (the sender echoes its frame id)
533
554
  if (f && String(data.id ?? '') === at) {
534
555
  const addr = `[${s.board} ▸ ${f.scene || '(root)'}] ${f.file} · ${String(data.path ?? '')}${data.source ? ` (${String(data.source)})` : ''}`
556
+ const h = cmd('laser-copy', { via: 'click', in: 'stage', frame: at })
535
557
  navigator.clipboard.writeText(addr).then(
536
- () => postStage({ type: 'sh:copy-ok', seq: data.seq }),
537
- () => s.toast('copy blocked - click the canvas first'))
558
+ () => { h.done(); postStage({ type: 'sh:copy-ok', seq: data.seq }) },
559
+ () => { h.fail('clipboard-blocked'); s.toast('copy blocked - click the canvas first') })
538
560
  }
539
561
  }
540
562
  }
@@ -543,38 +565,52 @@ function PlayInner() {
543
565
  }, [])
544
566
 
545
567
  // shared handler: keys arrive directly (focus in shell) or forwarded by the stage
546
- const handleKey = (key: string, code: string, alt = false) => {
568
+ const handleKey = (key: string, code: string, alt: boolean, how: CmdOpts) => {
547
569
  if (key === 'Escape') {
548
570
  // a live review mode swallows Escape first (cancel), so it never ejects you from
549
571
  // the prototype mid-comment; a second Escape (nothing live) exits
550
572
  const c = commentsStore()
551
573
  const s = useStore.getState()
552
- if (c.commentMode || s.laser || c.active || c.draft) { c.setMode(false); c.setActive(null); c.setDraft(null); s.setLaser(false) }
553
- else exit()
574
+ if (c.commentMode || s.laser || c.active || c.draft) {
575
+ const h = cmd('escape', how)
576
+ if (c.commentMode || c.active || c.draft) h.step('comments-off')
577
+ if (s.laser) h.step('laser-off')
578
+ c.setMode(false); c.setActive(null); c.setDraft(null); s.setLaser(false)
579
+ endAfterFrames(h)
580
+ }
581
+ else exitFrom(how)
554
582
  return
555
583
  }
556
- if (key === 'ArrowRight') { step(1); return }
557
- if (key === 'ArrowLeft') { step(-1); return }
558
- if (key === ' ' && useStore.getState().play?.slides) { step(1); return }
559
- if (key === '[') { switchVariant(-1); return }
560
- if (key === ']') { switchVariant(1); return }
561
- if (key === 'r') { restart(); return }
562
- if (key === 'h') { toggleHideUI(); return }
584
+ if (key === 'ArrowRight') { step(1, how); return }
585
+ if (key === 'ArrowLeft') { step(-1, how); return }
586
+ if (key === ' ' && useStore.getState().play?.slides) { step(1, how); return }
587
+ if (key === '[') { switchVariant(-1, how); return }
588
+ if (key === ']') { switchVariant(1, how); return }
589
+ if (key === 'r') { restart(how); return }
590
+ if (key === 'h') { cmd('hide-ui', how); toggleHideUI(); return }
563
591
  // L: the pointer laser; ⌥L: inspect
564
- if (key === 'l' && SOURCE_REVEALED) { commentsStore().setMode(false); useStore.getState().toggleLaser(alt); return }
565
- if (key === 'c') { const c = commentsStore(); if (!c.commentMode && useStore.getState().board === UNPLACED) return useStore.getState().toast(NO_COMMENTS_HERE); if (!c.commentMode && stoppedFor('Comments need the canvas running')) return; if (!c.commentMode) useStore.getState().setLaser(false); c.setMode(!c.commentMode); return }
566
- if (key === 'C') { const c = commentsStore(); c.setShow(!c.show); return } // ⇧C hides/shows pins
567
- if (key === 'L') { const c = commentsStore(); c.setShowAnchor(!c.showAnchor); return } // ⇧L element focus
592
+ if (key === 'l') {
593
+ const h = cmd(alt ? 'inspect' : 'laser', how)
594
+ if (!SOURCE_REVEALED) h.noop('stripped')
595
+ else { commentsStore().setMode(false); useStore.getState().toggleLaser(alt); return }
596
+ }
597
+ if (key === 'c') { const c = commentsStore(); const h = cmd('comments', how); if (!c.commentMode && useStore.getState().board === UNPLACED) { h.noop('unplaced'); return useStore.getState().toast(NO_COMMENTS_HERE) } if (!c.commentMode && stoppedFor('Comments need the canvas running')) { h.noop('stopped'); return } if (!c.commentMode) useStore.getState().setLaser(false); c.setMode(!c.commentMode); return }
598
+ if (key === 'C') { const c = commentsStore(); cmd('pins', how); c.setShow(!c.show); return } // ⇧C hides/shows pins
599
+ if (key === 'L') { const c = commentsStore(); cmd('laser-comment', how); c.setShowAnchor(!c.showAnchor); return } // ⇧L element focus
568
600
 
569
601
  if (/^Digit[1-9]$/.test(code)) {
570
602
  const names = Object.keys(CONFIG.viewports)
571
603
  const idx = Number(code.slice(5))
604
+ const h = cmd('device', how)
572
605
  if (idx <= names.length) setDevice(names[idx - 1])
573
606
  else if (idx === names.length + 1) setDevice('fill')
607
+ else h.noop('unknown-device')
574
608
  }
575
- if (key === 'd' && CONFIG.themes.length > 1) {
576
- const p = useStore.getState().play!
577
- setTheme(CONFIG.themes[(CONFIG.themes.indexOf(p.theme) + 1) % CONFIG.themes.length])
609
+ if (key === 'd') {
610
+ if (CONFIG.themes.length > 1) {
611
+ const p = useStore.getState().play!
612
+ setTheme(CONFIG.themes[(CONFIG.themes.indexOf(p.theme) + 1) % CONFIG.themes.length], how)
613
+ } else cmd('theme', how).noop('one-theme')
578
614
  }
579
615
  }
580
616
  /** ⌘/ collapses the toolbar to a re-open fab - same shortcut + ladder as design mode. */
@@ -586,9 +622,9 @@ function PlayInner() {
586
622
  // with Option a Mac types a symbol (⌥L is "¬"): an Alt shortcut is named by the key pressed
587
623
  const key = e.altKey && /^Key[A-Z]$/.test(e.code) ? e.code.slice(3).toLowerCase() : e.key
588
624
  if (!e.repeat && jamKey({ key, shift: e.shiftKey, alt: e.altKey, meta: e.metaKey, ctrl: e.ctrlKey })) { e.preventDefault(); return }
589
- if ((e.metaKey || e.ctrlKey) && e.key === '/') { e.preventDefault(); toggleCollapse(); return }
625
+ if ((e.metaKey || e.ctrlKey) && e.key === '/') { e.preventDefault(); cmd('toolbar', { via: 'key', in: 'shell', keys: keysOf(e) }); toggleCollapse(); return }
590
626
  if (e.metaKey || e.ctrlKey) return
591
- handleKey(key, e.code, e.altKey)
627
+ handleKey(key, e.code, e.altKey, { via: 'key', in: 'shell', keys: keysOf(e, key) })
592
628
  }
593
629
  window.addEventListener('keydown', onKey)
594
630
  return () => window.removeEventListener('keydown', onKey)
@@ -646,7 +682,7 @@ function PlayInner() {
646
682
  // background advance: never on controls, links, media, comments, or goto targets
647
683
  const t = e.target as Element
648
684
  if (t.closest('a, button, input, textarea, select, video, [contenteditable], [data-goto], .cm-card, .cm-pin, .cm-stack, .sh-pill')) return
649
- step(1)
685
+ step(1, { via: 'click', in: 'stage' })
650
686
  } : undefined}>
651
687
  <div className="dev" data-theme={play.theme} style={{ width: dw, height: dh }}>
652
688
  <iframe
@@ -714,8 +750,8 @@ function PlayInner() {
714
750
  <LaserButton />
715
751
  {!PUBLISHED && CONFIG.jam && <JamButton inPlay />}
716
752
  <i className="sep" />
717
- {!docPreset && <DevicePicker value={fill ? 'fill' : play.device} onSelect={(n) => n && setDevice(n)} includeFill includeSlide={slides} stageOnly={slides} hint={deviceHint} dark />}
718
- <ThemePicker value={play.theme} onSelect={setTheme} hint="D" dark />
753
+ {!docPreset && <DevicePicker value={fill ? 'fill' : play.device} onSelect={(n) => { if (!n) return; cmd('device', { via: 'click', in: 'pill', arg: n }); setDevice(n) }} includeFill includeSlide={slides} stageOnly={slides} hint={deviceHint} dark />}
754
+ <ThemePicker value={play.theme} onSelect={(t) => setTheme(t, { via: 'click', in: 'pill' })} hint="D" dark />
719
755
  </>}
720
756
  {playUpdateRevision && <>
721
757
  <i className="sep" />
@@ -727,7 +763,7 @@ function PlayInner() {
727
763
  <i className="sep" />
728
764
  <HideUIButton />
729
765
  <Tip side="bottom" label={<><b>Collapse toolbar</b><span>H hides everything · ⌘/</span></>}>
730
- <button className="sh-pill-btn" onClick={() => setPillOpen(false)} tabIndex={pillOpen ? 0 : -1}>
766
+ <button className="sh-pill-btn" onClick={() => { cmd('toolbar', { via: 'click', in: 'pill' }); setPillOpen(false) }} tabIndex={pillOpen ? 0 : -1}>
731
767
  <PanelFilledIcon size={17} style={{ transform: 'rotate(90deg)' }} />
732
768
  </button>
733
769
  </Tip>
@@ -736,7 +772,7 @@ function PlayInner() {
736
772
  deep link (the link's chrome) - not hidden, not rendered */}
737
773
  {!noDoor && (
738
774
  <Tip side="bottom" label={<><b>Open in canvas</b><span>Esc</span></>}>
739
- <button className="sh-pill-btn" data-play-exit="" onClick={exit}><GridIcon size={16} /></button>
775
+ <button className="sh-pill-btn" data-play-exit="" onClick={() => exitFrom({ via: 'click', in: 'pill' })}><GridIcon size={16} /></button>
740
776
  </Tip>
741
777
  )}
742
778
  {BRANDING && PUBLISHED && !trimmed && (
@@ -750,28 +786,28 @@ function PlayInner() {
750
786
  )}
751
787
  {!(slides && deckChrome === 'none') && (
752
788
  <Tip side="bottom" label={<><b>Open toolbar</b><span>⌘/</span></>}>
753
- <button className={`sh-pill-fab${pillOpen ? ' hidden' : ''}`} onClick={() => setPillOpen(true)}
789
+ <button className={`sh-pill-fab${pillOpen ? ' hidden' : ''}`} onClick={() => { cmd('toolbar', { via: 'click', in: 'pill' }); setPillOpen(true) }}
754
790
  aria-hidden={pillOpen} tabIndex={pillOpen ? -1 : 0}><PanelHollowIcon size={18} style={{ transform: 'rotate(90deg)' }} /></button>
755
791
  </Tip>
756
792
  )}
757
793
 
758
794
  {!focus && !trimmed && <div className="sh-play-nav">
759
795
  <Tip inv label={<><b>Restart</b><span className="k">R</span></>}>
760
- <button onClick={restart}><ReloadIcon size={14} /></button>
796
+ <button onClick={() => restart({ via: 'click', in: 'pill' })}><ReloadIcon size={14} /></button>
761
797
  </Tip>
762
798
  <i className="sep" />
763
799
  <Tip inv label={<><b>Previous frame</b><span className="k">←</span></>}>
764
- <button onClick={() => step(-1)}><ArrowLeftIcon size={14} /></button>
800
+ <button onClick={() => step(-1, { via: 'click', in: 'pill' })}><ArrowLeftIcon size={14} /></button>
765
801
  </Tip>
766
802
  <span className="pos">{pos === -1 ? '·' : pos + 1}<em>/</em>{list.length}</span>
767
803
  <Tip inv label={<><b>Next frame</b><span className="k">→</span></>}>
768
- <button onClick={() => step(1)}><ArrowRightIcon size={14} /></button>
804
+ <button onClick={() => step(1, { via: 'click', in: 'pill' })}><ArrowRightIcon size={14} /></button>
769
805
  </Tip>
770
806
  {variants.length > 1 && <>
771
807
  <i className="sep" />
772
808
  {variants.map((v) => (
773
809
  <Tip inv key={v.id} label={<><b>{v.title ?? v.id}</b><span className="k">[ ]</span></>}>
774
- <button className={`vchip${v.id === play.at ? ' on' : ''}`} onClick={() => goTo(v.id)}>
810
+ <button className={`vchip${v.id === play.at ? ' on' : ''}`} onClick={() => { if (v.id === play.at) cmd('play-variant', { via: 'click', in: 'pill' }).noop('no-variants'); else { endOnStage(cmd('play-variant', { via: 'click', in: 'pill' }), v.id); goTo(v.id) } }}>
775
811
  {(v.variant ?? '?').toUpperCase()}
776
812
  </button>
777
813
  </Tip>
@@ -3,6 +3,7 @@ import { StatusIcon } from './board-icons.tsx'
3
3
  import { STATUS_LABEL, type Status } from '../../shared/status.ts'
4
4
  import type { StatusWord } from '../../shared/board-types.ts'
5
5
  import type { BoardMeta } from './store.ts'
6
+ import { cmd, keysOf, type CmdHandle, type CmdOpts } from './commands.ts'
6
7
 
7
8
  /**
8
9
  * A board's status, from its right-click menu - Linear's picker, on Marver's rule (spec 20): a
@@ -13,10 +14,14 @@ import type { BoardMeta } from './store.ts'
13
14
  * the shipped record. The status the evidence gives shows read-only at the top, with where it came from.
14
15
  *
15
16
  * Type to filter, arrows and Enter, or a number. Blocked asks why before it writes.
17
+ *
18
+ * `board-status` (spec 30) starts at the decision and `onPick` ends it on the write's answer; the status and the reason
19
+ * stay out of it. Closing with nothing chosen is BoardList's to record: ContextMenu's listeners close this panel, and
20
+ * BoardList's run first (`data-board` says which board was being decided).
16
21
  */
17
22
  type Opt = { key: string; status: StatusWord | null; label: string; icon: Status | 'clear' }
18
23
 
19
- export function StatusPicker({ meta, onPick }: { meta: BoardMeta; onPick: (status: StatusWord | null, reason?: string) => void }) {
24
+ export function StatusPicker({ board, meta, close, onPick }: { board: string; meta: BoardMeta; close: () => void; onPick: (board: string, status: StatusWord | null, reason: string | undefined, h: CmdHandle) => void }) {
20
25
  const settable = meta.settable ?? []
21
26
  const current = meta.status
22
27
  const hasContext = !settable.includes('todo')
@@ -31,26 +36,31 @@ export function StatusPicker({ meta, onPick }: { meta: BoardMeta; onPick: (statu
31
36
  const [asking, setAsking] = useState(false)
32
37
  const [reason, setReason] = useState(current?.status === 'blocked' ? current.reason ?? '' : '')
33
38
 
34
- const choose = (o: Opt | undefined) => {
39
+ const decide = (status: StatusWord | null, reason: string | undefined, how: CmdOpts) => {
40
+ const h = cmd('board-status', { ...how, board })
41
+ close()
42
+ onPick(board, status, reason, h)
43
+ }
44
+ const choose = (o: Opt | undefined, how: CmdOpts) => {
35
45
  if (!o) return
36
46
  if (o.status === 'blocked') { setAsking(true); return }
37
- onPick(o.status)
47
+ decide(o.status, undefined, how)
38
48
  }
39
49
  const keys = (e: KeyboardEvent<HTMLInputElement>) => {
40
50
  if (e.key === 'ArrowDown') { e.preventDefault(); setHi((h) => Math.min(h + 1, shown.length - 1)) }
41
51
  else if (e.key === 'ArrowUp') { e.preventDefault(); setHi((h) => Math.max(h - 1, 0)) }
42
- else if (e.key === 'Enter') { e.preventDefault(); choose(shown[hi]) }
43
- else if (/^[1-9]$/.test(e.key) && !q) { e.preventDefault(); choose(opts[Number(e.key) - 1]) }
52
+ else if (e.key === 'Enter') { e.preventDefault(); choose(shown[hi], { via: 'key', in: 'shell', keys: keysOf(e) }) }
53
+ else if (/^[1-9]$/.test(e.key) && !q) { e.preventDefault(); choose(opts[Number(e.key) - 1], { via: 'key', in: 'shell', keys: keysOf(e) }) }
44
54
  }
45
55
 
46
56
  if (asking) {
47
57
  const ok = !!reason.trim()
48
58
  return (
49
- <div className="sh-status-picker" data-status-picker="reason">
59
+ <div className="sh-status-picker" data-status-picker="reason" data-board={board}>
50
60
  <div className="sp-head"><StatusIcon status="blocked" /><b>Blocked - why?</b></div>
51
61
  <input autoFocus className="sp-input" value={reason} maxLength={300} placeholder="Waiting on…"
52
62
  onChange={(e) => setReason(e.target.value)}
53
- onKeyDown={(e) => { if (e.key === 'Enter' && ok) { e.preventDefault(); onPick('blocked', reason.trim()) } }} />
63
+ onKeyDown={(e) => { if (e.key === 'Enter' && ok) { e.preventDefault(); decide('blocked', reason.trim(), { via: 'key', in: 'shell', keys: keysOf(e) }) } }} />
54
64
  <div className="sp-foot">{ok ? 'Enter to save' : 'A blocked board says why'} · Esc to close</div>
55
65
  </div>
56
66
  )
@@ -59,7 +69,7 @@ export function StatusPicker({ meta, onPick }: { meta: BoardMeta; onPick: (statu
59
69
  // what the evidence says, when no decision hides it: the status and the line that decided it
60
70
  const evidence = !decided && current && hasContext ? current.evidence?.[0] : undefined
61
71
  return (
62
- <div className="sh-status-picker" data-status-picker="list">
72
+ <div className="sh-status-picker" data-status-picker="list" data-board={board}>
63
73
  <input autoFocus className="sp-input" value={q} placeholder="Change status…"
64
74
  onChange={(e) => { setQ(e.target.value); setHi(0) }} onKeyDown={keys} />
65
75
  {current && evidence && (
@@ -76,7 +86,7 @@ export function StatusPicker({ meta, onPick }: { meta: BoardMeta; onPick: (statu
76
86
  const isCurrent = o.status !== null && o.status === current?.status && (decided || !hasContext || fromPlan)
77
87
  return (
78
88
  <button key={o.key} data-status-option={o.key} className={i === hi ? 'hi' : undefined}
79
- onMouseEnter={() => setHi(i)} onClick={() => choose(o)}>
89
+ onMouseEnter={() => setHi(i)} onClick={() => choose(o, { via: 'click', in: 'shell' })}>
80
90
  {o.icon === 'clear'
81
91
  ? <svg width="14" height="14" viewBox="0 0 14 14" fill="none" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round" strokeLinejoin="round" aria-hidden><path d="M3.2 6.2 A4.2 4.2 0 1 1 4.4 10.4 M3.2 3.4 V6.2 H6" /></svg>
82
92
  : <StatusIcon status={o.icon} />}
@@ -13,6 +13,7 @@ import { STOPPED_TIP, useStopped } from './api.ts'
13
13
  import { NO_COMMENTS_HERE, useComments } from './comments-store.ts'
14
14
  import { UNPLACED } from './hash.ts'
15
15
  import { Tip } from './Tip.tsx'
16
+ import { cmd } from './commands.ts'
16
17
  import { CaretIcon, CheckIcon, CommentIcon, DevicesIcon, EyeSlashIcon, FrameCornersIcon, LaserIcon, MoonIcon, SlideFrameIcon, SunIcon, deviceIcon } from './icons.tsx'
17
18
 
18
19
  const commentsStore = () => useComments.getState()
@@ -63,6 +64,8 @@ export function toggleHideUI() {
63
64
  document.body.classList.toggle('sh-hide-ui', !isHideUI())
64
65
  hideListeners.forEach((f) => f())
65
66
  }
67
+ /** Told at every toggle, in its own turn (the recorder's `hide-ui` mode, spec 30 #25). Returns the unsubscribe. */
68
+ export const onHideUI = (f: () => void) => { hideListeners.add(f); return () => { hideListeners.delete(f) } }
66
69
  export function useHideUI() {
67
70
  const [on, setOn] = useState(isHideUI)
68
71
  useEffect(() => {
@@ -98,6 +101,7 @@ export function LaserButton() {
98
101
  return (
99
102
  <Tip side="bottom" label={<TipRows rows={[['Laser', 'L'], ['Inspect', '⌥L'], [showAnchor ? 'Hide laser comment' : 'Show laser comment', '⇧L']]} />}>
100
103
  <button className={`sh-pill-btn${laser ? ' on' : ''}`} data-laser={laser ? (laserInspect ? 'inspect' : 'pointer') : 'off'} onClick={(e) => {
104
+ cmd(e.altKey ? 'inspect' : 'laser', { via: 'click', in: 'pill' })
101
105
  commentsStore().setMode(false)
102
106
  useStore.getState().toggleLaser(e.altKey)
103
107
  }}><LaserIcon size={16} /></button>
@@ -122,7 +126,7 @@ export function CommentButton() {
122
126
  if (stopped && !commentMode) {
123
127
  return (
124
128
  <Tip side="bottom" label={<div className="sh-tip-lines"><b>Comments need the canvas running</b><small>{STOPPED_TIP}</small></div>}>
125
- <button className="sh-pill-btn off" aria-disabled="true" data-stopped="" onClick={() => stoppedFor('Comments need the canvas running')}><CommentIcon size={16} /></button>
129
+ <button className="sh-pill-btn off" aria-disabled="true" data-stopped="" onClick={() => { const h = cmd('comments', { via: 'click', in: 'pill' }); stoppedFor('Comments need the canvas running'); h.noop('stopped') }}><CommentIcon size={16} /></button>
126
130
  </Tip>
127
131
  )
128
132
  }
@@ -131,10 +135,13 @@ export function CommentButton() {
131
135
  <Tip side="bottom" label={<><b>Commenting is not available for you yet</b><span>click to ask the owner</span></>}>
132
136
  <button className="sh-pill-btn" style={{ opacity: .55 }} onClick={() => {
133
137
  const s = useStore.getState()
134
- if (Date.now() - asked.current < 8000) return
138
+ const h = cmd('ask-to-comment', { via: 'click', in: 'pill' })
139
+ if (Date.now() - asked.current < 8000) { h.noop('too-soon'); return }
135
140
  asked.current = Date.now()
136
- void commentsStore().askToComment().then((ok) =>
137
- s.toast(ok ? 'asked the owner for comment access - they decide' : 'could not send the request - try again'))
141
+ void commentsStore().askToComment().then((ok) => {
142
+ if (ok) h.done(); else h.fail('api')
143
+ s.toast(ok ? 'asked the owner for comment access - they decide' : 'could not send the request - try again')
144
+ }, (e: unknown) => { h.fail('api'); throw e })
138
145
  }}><CommentIcon size={16} /></button>
139
146
  </Tip>
140
147
  )
@@ -143,8 +150,9 @@ export function CommentButton() {
143
150
  <Tip side="bottom" label={<TipRows rows={[['Comment', 'C'], [show ? 'Hide pins' : 'Show pins', '⇧C']]} />}>
144
151
  <button className={`sh-pill-btn${commentMode ? ' on' : ''}`} onClick={() => {
145
152
  const c = commentsStore()
146
- if (!c.commentMode && useStore.getState().board === UNPLACED) return useStore.getState().toast(NO_COMMENTS_HERE)
147
- if (!c.commentMode && stoppedFor('Comments need the canvas running')) return
153
+ const h = cmd('comments', { via: 'click', in: 'pill' })
154
+ if (!c.commentMode && useStore.getState().board === UNPLACED) { h.noop('unplaced'); return useStore.getState().toast(NO_COMMENTS_HERE) }
155
+ if (!c.commentMode && stoppedFor('Comments need the canvas running')) { h.noop('stopped'); return }
148
156
  if (!c.commentMode) useStore.getState().setLaser(false)
149
157
  c.setMode(!c.commentMode)
150
158
  useStore.getState().toast(c.commentMode ? 'comment mode off' : 'comment mode - click an element in a frame')
@@ -159,7 +167,7 @@ export function HideUIButton() {
159
167
  const on = useHideUI()
160
168
  return (
161
169
  <Tip side="bottom" label={<><b>Hide all UI</b><span>press H to reveal</span></>}>
162
- <button className={`sh-pill-btn${on ? ' on' : ''}`} onClick={toggleHideUI}><EyeSlashIcon size={16} /></button>
170
+ <button className={`sh-pill-btn${on ? ' on' : ''}`} onClick={() => { cmd('hide-ui', { via: 'click', in: 'pill' }); toggleHideUI() }}><EyeSlashIcon size={16} /></button>
163
171
  </Tip>
164
172
  )
165
173
  }
@@ -10,6 +10,10 @@ import { create } from 'zustand'
10
10
  import { ROUTE } from '../const.ts'
11
11
  import { guardLeaving, leaveNow, unsavedWhen, workChanged } from './unsaved.ts'
12
12
  import { PERF_RUN, perfRunGate, RUN_HEADER, RUN_PARAM } from './perf-run.ts'
13
+ import { RECORDER_LEVEL } from '../recorder-level.ts'
14
+ import { RECORDER_PARAM } from '../../shared/perf-records.ts'
15
+ import { perfSeams } from './recorder-seams.ts'
16
+ import { hmrBack, hmrLost as recordHmrLost } from './recorder-hmr.ts'
13
17
  // @ts-expect-error virtual module provided by the plugin
14
18
  import shConfig from 'virtual:sh-config'
15
19
  // @ts-expect-error virtual module: null in dev; a published build inlines manifest+boards
@@ -22,10 +26,12 @@ export const WS: string = shData === null && typeof shConfig?.workspace === 'str
22
26
  export const scoped = (key: string) => (WS ? `${key}:${WS}` : key)
23
27
  const param = (url: string, k: string, v: string) => `${url}${url.includes('?') ? '&' : '?'}${k}=${v}`
24
28
  /** A URL a document or an <img> loads, naming the workspace (frames, the stage, Jam pictures) - and, in a headless
25
- * perf run, the run (spec 28 A3.8 #17): a frame's own writes are refused by its Referer, its Video asks no poster. */
29
+ * perf run, the run (spec 28 A3.8 #17): a frame's own writes are refused by its Referer, its Video asks no poster.
30
+ * A page recording at the `core` level (spec 30 #58) says so too, so its frames' hooks keep its level. */
26
31
  export const withWs = (url: string) => {
27
32
  const u = WS ? param(url, 'ws', WS) : url
28
- return PERF_RUN ? param(u, RUN_PARAM, PERF_RUN.id) : u
33
+ const v = RECORDER_LEVEL === 'core' ? param(u, RECORDER_PARAM, 'core') : u
34
+ return PERF_RUN ? param(v, RUN_PARAM, PERF_RUN.id) : v
29
35
  }
30
36
  /** The headers every request of this page carries: its workspace, and its perf run's id. */
31
37
  const named = (h: Record<string, string> | undefined): Record<string, string> => ({ ...h, ...(WS ? { 'x-mv-ws': WS } : {}), ...(PERF_RUN ? { [RUN_HEADER]: PERF_RUN.id } : {}) })
@@ -56,14 +62,20 @@ export function mvFetch(url: string, init: RequestInit = {}): Promise<Response>
56
62
  const refused = perfRunGate(url, init)
57
63
  if (refused) return Promise.resolve(refused)
58
64
  if (WS && canvasStopped()) return Promise.resolve(stoppedAnswer())
59
- const sent = fetch(url, WS || PERF_RUN ? { ...init, headers: named(init.headers as Record<string, string> | undefined) } : init)
65
+ // the recorder's (spec 30 #18): a board write names its page and the commands folded into it - none until then
66
+ const extra = WS ? perfSeams.requestHeaders(url, init) : undefined
67
+ const headers = extra ? { ...(init.headers as Record<string, string> | undefined), ...extra } : init.headers as Record<string, string> | undefined
68
+ const t0 = performance.now()
69
+ const sent = fetch(url, WS || PERF_RUN ? { ...init, headers: named(headers) } : init)
60
70
  if (!WS) return sent
61
71
  // the server's refusal is told apart here, before any caller's own 409 (a board conflict, a stale tree)
62
72
  return sent.then((r) => {
73
+ perfSeams.answered.emit({ url, init, headers, status: r.status, ms: performance.now() - t0 })
63
74
  if (r.status !== 409 || r.headers.get('x-mv-elsewhere') !== '1') return r
64
75
  lost('elsewhere')
65
76
  return stoppedAnswer()
66
77
  }, (e: unknown) => {
78
+ perfSeams.answered.emit({ url, init, headers, status: (e as Error)?.name === 'TimeoutError' ? 'timeout' : 0, ms: performance.now() - t0 })
67
79
  // the live socket is gone, so nothing else would say so: a request that reaches nothing stops the page
68
80
  if (hmrLost && (e as Error)?.name !== 'AbortError') lost('down')
69
81
  throw e
@@ -127,6 +139,8 @@ async function resume() {
127
139
  if (back) useLink.setState({ link: 'resuming' }) // requests flow again: the flushers use them
128
140
  let ok = true
129
141
  for (const fn of flushers) ok = (await fn().catch(() => false)) && ok
142
+ // the socket's way back (spec 30 #30): said before anything below decides, a second at most - the holds are asked after it
143
+ await hmrBack()
130
144
  const now = useLink.getState().link
131
145
  if (now !== 'resuming' && now !== 'live') return // lost again while saving: the probe goes on
132
146
  // asked here, with nothing awaited between the answer and the reload: words typed or an edit made while a
@@ -229,7 +243,7 @@ if (typeof window !== 'undefined' && !PERF_RUN) guardLeaving(window)
229
243
  // Vite - not into another project that took the port, and not into this one's next run before it has
230
244
  // saved what it holds - and its socket stays closed, so no other project's broadcast reaches it. It
231
245
  // reloads itself in resume(). Frames keep Vite's own reload: their URLs name the workspace.
232
- if (WS && import.meta.hot) import.meta.hot.on('vite:ws:disconnect', () => { hmrLost = true; lost('down'); return new Promise<never>(() => {}) })
246
+ if (WS && import.meta.hot) import.meta.hot.on('vite:ws:disconnect', () => { hmrLost = true; recordHmrLost(); lost('down'); return new Promise<never>(() => {}) })
233
247
 
234
248
  // dev-only inspection hook for tests (never installed in published builds)
235
249
  if (WS && import.meta.env.DEV) (window as unknown as { __mvLink: unknown }).__mvLink = useLink