@marver-design/marver 0.27.0 → 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.
- package/CHANGELOG.md +94 -0
- package/README.md +5 -2
- package/dist/{anchor-check-ChdDqL5z.mjs → anchor-check-gkxkPAIv.mjs} +1 -1
- package/dist/{board-tree-DRioF94d.mjs → board-tree-BXR8dw4b.mjs} +3 -1
- package/dist/{boards-CGg6piKF.mjs → boards-BHKP5yhI.mjs} +1 -1
- package/dist/{boards-DlTcpF47.mjs → boards-BqUqKNW8.mjs} +4 -4
- package/dist/{build-DZnFysGU.mjs → build-VgNg4rr8.mjs} +7 -22
- package/dist/cli.mjs +32 -18
- package/dist/{collab-Dxg2trOK.mjs → collab-BEAcXrBb.mjs} +1 -1
- package/dist/{comments-DxOkCSNE.mjs → comments-YEU1Zhv9.mjs} +4 -4
- package/dist/{context-HQ4Giw58.mjs → context-Ccjrhr1J.mjs} +3 -3
- package/dist/{daemon-BSA0lV8d.mjs → daemon-Dc9AH0M3.mjs} +4 -4
- package/dist/{dev-eQJhWsqg.mjs → dev-ri6nAlRp.mjs} +11 -11
- package/dist/{init-COD0x48i.mjs → init-W0nxR1OY.mjs} +3 -3
- package/dist/{link-DDXZVGtv.mjs → link-CdTgn94Y.mjs} +4 -4
- package/dist/{ls-D7O1G505.mjs → ls-BZ5TAtd5.mjs} +1 -1
- package/dist/{manifest-Nl3KSVOk.mjs → manifest-aFyDmL8C.mjs} +2 -2
- package/dist/{marks-CWM3WJjc.mjs → marks-BF9pNEgH.mjs} +2 -2
- package/dist/{marks-CKgzucHZ.mjs → marks-CnCCfAbD.mjs} +3 -3
- package/dist/{marver-id-gate-BjF6v4bT.mjs → marver-id-gate-D-R0hSt_.mjs} +1 -1
- package/dist/perf-DkAUFT6W.mjs +1319 -0
- package/dist/perf-jam-BaH3Lg0m.mjs +635 -0
- package/dist/{plugin-C-E7omsh.mjs → plugin-B8UghYuF.mjs} +2592 -112
- package/dist/{poster-Bx83ZYVK.mjs → poster-BNgafWMK.mjs} +1 -1
- package/dist/{profile-Bh5Y5zpW.mjs → profile-jIS6BcAs.mjs} +1 -1
- package/dist/{publish-bakes-aljgm45S.mjs → publish-bakes-38Nja78p.mjs} +3 -3
- package/dist/{recover-t9Pno3u9.mjs → recover-B8AiI29B.mjs} +2 -2
- package/dist/{serve-C8rVheYk.mjs → serve-Dp3nHstu.mjs} +3 -3
- package/dist/{share-W5H3BNvP.mjs → share-Ce4tP7ji.mjs} +1 -1
- package/dist/{shot-DoHLl6ig.mjs → shot-CMQgMVZm.mjs} +1 -1
- package/dist/{shot-LFhC-WYD.mjs → shot-Ch24tiMO.mjs} +30 -5
- package/dist/{slots-DCDo3N0x.mjs → slots-CFNnegCc.mjs} +8 -1
- package/dist/{sync-BQVlHZpx.mjs → sync-CQdGARJ9.mjs} +1 -1
- package/dist/{work-BroFwnup.mjs → work-Bxz-ObF3.mjs} +3 -3
- package/dist/{work-Bp1p39kq.mjs → work-CNhFF9pU.mjs} +1 -1
- package/docs/jam-session.md +2 -1
- package/docs/performance.md +197 -35
- package/package.json +1 -1
- package/src/client/content/video.tsx +10 -2
- package/src/client/shell/App.tsx +10 -3
- package/src/client/shell/Comments.tsx +5 -3
- package/src/client/shell/ContextMenu.tsx +5 -3
- package/src/client/shell/LockedApp.tsx +3 -0
- package/src/client/shell/Play.tsx +4 -2
- package/src/client/shell/Tip.tsx +3 -1
- package/src/client/shell/api.ts +47 -20
- package/src/client/shell/app-bridge.ts +254 -0
- package/src/client/shell/app-perf.ts +92 -0
- package/src/client/shell/canvas/Canvas.tsx +115 -22
- package/src/client/shell/canvas/FrameNode.tsx +10 -6
- package/src/client/shell/canvas/admission.ts +23 -8
- package/src/client/shell/canvas/ctl.ts +6 -0
- package/src/client/shell/canvas/sleep.ts +57 -17
- package/src/client/shell/canvas/updates.ts +2 -1
- package/src/client/shell/inset.ts +44 -0
- package/src/client/shell/jam-capture.ts +19 -14
- package/src/client/shell/jam-keys.ts +8 -3
- package/src/client/shell/jam-panel.tsx +6 -3
- package/src/client/shell/jam-voice.ts +48 -10
- package/src/client/shell/main.tsx +14 -1
- package/src/client/shell/marks-ui.tsx +5 -3
- package/src/client/shell/marver-app.ts +21 -0
- package/src/client/shell/perf-run-probe.ts +34 -0
- package/src/client/shell/perf-run.ts +70 -0
- package/src/client/shell/perf.ts +11 -0
- package/src/client/shell/recorder.ts +45 -3
- package/src/client/shell/store.ts +52 -24
- package/src/client/shell/styles.css +47 -15
- package/src/client/shell/unsaved.ts +81 -0
- package/src/client/shell/whiteout-probes.ts +141 -0
- package/src/shared/app-api.ts +205 -0
- package/src/shared/app-perf.ts +308 -0
- package/src/shared/logo-sniff.ts +86 -0
- package/src/shared/machine.ts +132 -0
- package/src/shared/perf-run.ts +177 -0
- package/templates/AGENTS-embedded.md +3 -0
- package/templates/AGENTS-studio.md +3 -0
- package/templates/instructions/boards.md +3 -1
- package/dist/bake-DM_uWgAA.mjs +0 -786
- package/dist/perf-BWzQwZqj.mjs +0 -369
- package/dist/perf-BoDSkbEb.mjs +0 -429
- package/dist/perf-jam-D55U3FZK.mjs +0 -242
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
* starts nothing - it is ended (E) or dropped (Esc) first. Each message lands in the capture whose
|
|
14
14
|
* id it carries.
|
|
15
15
|
*/
|
|
16
|
+
import { onScreen, usable } from './inset.ts'
|
|
16
17
|
import { create } from 'zustand'
|
|
17
18
|
import { slideSize } from '../const.ts'
|
|
18
19
|
import { CONFIG, SLIDE_INTRINSIC, stoppedFor, useStore, type Node } from './store.ts'
|
|
@@ -22,6 +23,7 @@ import { forgetHeard, RATE, setWordsListener, voiceBegin, voiceDrop, voiceEnd }
|
|
|
22
23
|
import { touchedFrames } from '../../shared/capture-frames.ts'
|
|
23
24
|
import { onStageSize, stageSize } from './stage-size.ts'
|
|
24
25
|
import { api, holdsReload } from './api.ts'
|
|
26
|
+
import { unsavedWhen, workChanged } from './unsaved.ts'
|
|
25
27
|
import { bytesOf } from './recorder-core.ts'
|
|
26
28
|
|
|
27
29
|
const csrf = () => /(?:^|;\s*)mv_c=([\w-]+)/.exec(document.cookie)?.[1] ?? ''
|
|
@@ -175,7 +177,7 @@ function sizeNow(f: string, key?: string): { w: number; h: number; play?: true }
|
|
|
175
177
|
const entry = st.manifest?.frames.find((x) => x.id === f)
|
|
176
178
|
const slide = (entry && slideSize(entry, CONFIG.viewports)) ?? (st.play.slides ? SLIDE_INTRINSIC : null)
|
|
177
179
|
if (slide) return { w: Math.round(slide.width), h: Math.round(slide.height), play: true }
|
|
178
|
-
if (st.play.device === 'fill') return { w:
|
|
180
|
+
if (st.play.device === 'fill') { const u = usable(); return { w: u.width, h: u.height, play: true } }
|
|
179
181
|
const v = CONFIG.viewports[st.play.device]
|
|
180
182
|
return v ? { w: Math.round(v.width), h: Math.round(v.height), play: true } : undefined
|
|
181
183
|
}
|
|
@@ -243,13 +245,13 @@ const viewNow = (focus = false): View => {
|
|
|
243
245
|
* nothing that covers it (the panel and the lane leave their own room). */
|
|
244
246
|
export function visibleNodes(): Node[] {
|
|
245
247
|
const s = useStore.getState()
|
|
246
|
-
const W = window.innerWidth, H = window.innerHeight
|
|
247
248
|
const out: Node[] = []
|
|
248
249
|
for (const n of s.nodes) {
|
|
249
250
|
if (n.missing) continue
|
|
250
251
|
const el = document.querySelector(`.sh-node[data-node="${CSS.escape(n.key)}"]`)
|
|
251
252
|
const r = el?.getBoundingClientRect()
|
|
252
|
-
|
|
253
|
+
// on screen below the scroll edge (inset.ts): a frame under the Mac app's strip is not in view
|
|
254
|
+
if (r && onScreen(r)) out.push(n)
|
|
253
255
|
}
|
|
254
256
|
return out.slice(0, 20)
|
|
255
257
|
}
|
|
@@ -854,20 +856,16 @@ async function upload(record: CaptureRecord, leaving = false): Promise<void> {
|
|
|
854
856
|
}
|
|
855
857
|
|
|
856
858
|
/** A capture still recording, or finishing (its pictures and last words coming in), lives only in this page until it
|
|
857
|
-
* seals; a sealed one is kept in localStorage until it lands. Leaving the page asks first -
|
|
858
|
-
*
|
|
859
|
-
*
|
|
860
|
-
*
|
|
861
|
-
*
|
|
859
|
+
* seals; a sealed one is kept in localStorage until it lands. Leaving the page asks first - unsaved.ts's one
|
|
860
|
+
* `beforeunload`, which hears this module's two reasons below - and if you leave anyway (`pagehide`: a close, a
|
|
861
|
+
* reload, a navigation, the back-forward cache alike), every capture not sealed yet is sealed at once, as it stood,
|
|
862
|
+
* for good: a missing step says so, the server keeps it as a draft, and it goes out like any sealed record not sent
|
|
863
|
+
* yet - from the next page, or this one if it comes back. Carrying on is Resume, with a new id. Best effort: a crash
|
|
864
|
+
* or a killed process fires nothing. */
|
|
862
865
|
let guarded = false
|
|
863
866
|
function guardUnload() {
|
|
864
867
|
if (guarded || typeof window === 'undefined') return
|
|
865
868
|
guarded = true
|
|
866
|
-
window.addEventListener('beforeunload', (e) => {
|
|
867
|
-
if (!Object.keys(useJamCapture.getState().caps).length) return
|
|
868
|
-
e.preventDefault()
|
|
869
|
-
e.returnValue = ''
|
|
870
|
-
})
|
|
871
869
|
window.addEventListener('pagehide', () => sealOnLeave())
|
|
872
870
|
// back from the back-forward cache: what was kept goes out now (never amended, never dropped)
|
|
873
871
|
window.addEventListener('pageshow', (e) => { if (e.persisted) for (const r of pendingUploads.values()) void upload(r) })
|
|
@@ -916,6 +914,10 @@ export function resendSealed() {
|
|
|
916
914
|
// the canvas answered again after it stopped (spec 28 A1.11): the page reloads only when no capture is
|
|
917
915
|
// recording or finishing - a sealed one waits in localStorage and goes out from the next page
|
|
918
916
|
holdsReload(() => capturesPending())
|
|
917
|
+
// leaving the page with a capture open, or one sealed and not taken by the server yet - a memory-only one too, its
|
|
918
|
+
// localStorage copy failed - asks first (spec 28 A2.9); the Mac app hears the same two reasons
|
|
919
|
+
unsavedWhen('capture-recording', () => Object.keys(useJamCapture.getState().caps).length > 0)
|
|
920
|
+
unsavedWhen('capture-unsent', () => useJamCapture.getState().unsent.length > 0)
|
|
919
921
|
|
|
920
922
|
/** Resume's work, while the caller holds `settling`: load the record, let the caller settle, start. */
|
|
921
923
|
async function resumeNow(draft: string, ready?: () => Promise<boolean>): Promise<boolean> {
|
|
@@ -1002,6 +1004,9 @@ export const useJamCapture = create<CaptureState>((set, get) => ({
|
|
|
1002
1004
|
},
|
|
1003
1005
|
}))
|
|
1004
1006
|
|
|
1007
|
+
// a capture opened, sealed or taken by the server: what this page holds changed (unsaved.ts)
|
|
1008
|
+
useJamCapture.subscribe((s, p) => { if (Object.keys(s.caps).length !== Object.keys(p.caps).length || s.unsent.length !== p.unsent.length) workChanged() })
|
|
1009
|
+
|
|
1005
1010
|
/** What the capture tile shows: the timer and the counts. */
|
|
1006
1011
|
export function captureCounts(c: Cap | undefined, t = now()): { time: string; counts: string; notes: number } {
|
|
1007
1012
|
if (!c) return { time: '0:00', counts: '', notes: 0 }
|
|
@@ -1016,4 +1021,4 @@ export function captureCounts(c: Cap | undefined, t = now()): { time: string; co
|
|
|
1016
1021
|
}
|
|
1017
1022
|
}
|
|
1018
1023
|
|
|
1019
|
-
if (typeof window !== 'undefined' && (import.meta as any).env?.DEV) { (window as any).__mvJamCapture = useJamCapture; (window as any).__mvJamInstances = instances }
|
|
1024
|
+
if (typeof window !== 'undefined' && (import.meta as any).env?.DEV) { (window as any).__mvJamCapture = useJamCapture; (window as any).__mvJamInstances = instances; (window as any).__mvJamVisible = visibleNodes }
|
|
@@ -23,6 +23,7 @@ import { pressJ, startSession, wrapWrite } from './jam-session.tsx'
|
|
|
23
23
|
import { clearMoreDraft } from './jam-panel.tsx'
|
|
24
24
|
import { CONFIG, PUBLISHED, SOURCE_REVEALED, useStore } from './store.ts'
|
|
25
25
|
import { holdsReload } from './api.ts'
|
|
26
|
+
import { unsavedWhen, workChanged } from './unsaved.ts'
|
|
26
27
|
|
|
27
28
|
export interface KeyIn { key: string; shift?: boolean; alt?: boolean; meta?: boolean; ctrl?: boolean }
|
|
28
29
|
/** `[Ctrl+][Meta+][Alt+][Shift+]key`, a letter lowercase - the frames' descriptor (keys.js). */
|
|
@@ -59,12 +60,13 @@ export function saveEdit(c: JamCard, text: string) {
|
|
|
59
60
|
const g = ++gen
|
|
60
61
|
latest.set(c.id, g)
|
|
61
62
|
unsaved.set(c.id, text)
|
|
63
|
+
workChanged()
|
|
62
64
|
const before = saving.get(c.id) ?? Promise.resolve(true)
|
|
63
65
|
// saves of one card run in order, each at the card's rev as the one before left it
|
|
64
66
|
saving.set(c.id, before.then(() => {
|
|
65
67
|
const fresh = useJamQueue.getState().cards?.find((x) => x.id === c.id) ?? c
|
|
66
68
|
return useJamQueue.getState().act(fresh, 'edit', text)
|
|
67
|
-
}).then((ok) => { if (ok && latest.get(c.id) === g) unsaved.delete(c.id); return ok }))
|
|
69
|
+
}).then((ok) => { if (ok && latest.get(c.id) === g) { unsaved.delete(c.id); workChanged() } return ok }))
|
|
68
70
|
}
|
|
69
71
|
/** Notes added in a read-back not saved yet, per card: each with its own id - one on its way, or one that failed
|
|
70
72
|
* and waits to be sent again. Sent again (from the field, or before a decision) it keeps its id: the server
|
|
@@ -74,6 +76,8 @@ const unsavedNotes = new Map<string, PendingNote[]>()
|
|
|
74
76
|
// spec 28 A1.11: a page whose canvas came back reloads only once every edit and note of a read-back has saved -
|
|
75
77
|
// one that failed while the canvas was away waits for the read-back's own retry (a decision saves it first)
|
|
76
78
|
holdsReload(() => unsaved.size > 0 || unsavedNotes.size > 0)
|
|
79
|
+
// and leaving the page asks first (spec 28 A2.9): a read-back's edit or note not saved yet is words not sent
|
|
80
|
+
unsavedWhen('typing', () => unsaved.size > 0 || unsavedNotes.size > 0)
|
|
77
81
|
const sendNote = (c: JamCard, n: PendingNote): Promise<boolean> => {
|
|
78
82
|
n.failed = false
|
|
79
83
|
const before = saving.get(c.id) ?? Promise.resolve(true)
|
|
@@ -82,7 +86,7 @@ const sendNote = (c: JamCard, n: PendingNote): Promise<boolean> => {
|
|
|
82
86
|
return useJamQueue.getState().act(fresh, 'note', JSON.stringify({ id: n.id, text: n.text, order: n.order }))
|
|
83
87
|
}).then((ok) => {
|
|
84
88
|
const list = unsavedNotes.get(c.id) ?? []
|
|
85
|
-
if (ok) { const left = list.filter((x) => x !== n); if (left.length) unsavedNotes.set(c.id, left); else unsavedNotes.delete(c.id) } else n.failed = true
|
|
89
|
+
if (ok) { const left = list.filter((x) => x !== n); if (left.length) unsavedNotes.set(c.id, left); else unsavedNotes.delete(c.id); workChanged() } else n.failed = true
|
|
86
90
|
return ok
|
|
87
91
|
}, () => { n.failed = true; return false })
|
|
88
92
|
saving.set(c.id, p.then(() => true))
|
|
@@ -95,6 +99,7 @@ export function addNote(c: JamCard, text: string, id: string): Promise<boolean>
|
|
|
95
99
|
const was = (unsavedNotes.get(c.id) ?? []).find((x) => x.id === id)
|
|
96
100
|
const n: PendingNote = { id, text, failed: false, order: was?.order ?? Date.now() }
|
|
97
101
|
unsavedNotes.set(c.id, [...(unsavedNotes.get(c.id) ?? []).filter((x) => x.id !== id), n])
|
|
102
|
+
workChanged()
|
|
98
103
|
return sendNote(c, n)
|
|
99
104
|
}
|
|
100
105
|
/** Every note added to a draft saved (a failed one sent again, once): before it is sent, kept or resumed. */
|
|
@@ -119,7 +124,7 @@ export async function decideDraft(id: string, action: 'confirm' | 'keep' | 'drop
|
|
|
119
124
|
}
|
|
120
125
|
// a note added in its read-back goes with it: one that did not save is sent again, and nothing is sent without it
|
|
121
126
|
if (action !== 'drop' && unsavedNotes.has(id) && !(await notesSaved(id))) { useStore.getState().toast('your note could not be added - try again before you send it'); return }
|
|
122
|
-
if (action === 'drop') { unsaved.delete(id); unsavedNotes.delete(id) }
|
|
127
|
+
if (action === 'drop') { unsaved.delete(id); unsavedNotes.delete(id); workChanged() }
|
|
123
128
|
const fresh = useJamQueue.getState().cards?.find((c) => c.id === id)
|
|
124
129
|
if (!fresh) return
|
|
125
130
|
if (await useJamQueue.getState().act(fresh, action)) useJamUi.getState().close()
|
|
@@ -19,6 +19,7 @@ import { LANE_H } from './jam-lane.tsx'
|
|
|
19
19
|
import { Tip } from './Tip.tsx'
|
|
20
20
|
import { useJamQueue } from './jam-queue.ts'
|
|
21
21
|
import { holdsReload } from './api.ts'
|
|
22
|
+
import { unsavedWhen, workChanged } from './unsaved.ts'
|
|
22
23
|
|
|
23
24
|
/** A heading cut short by its ellipsis: its tooltip shows it whole (one that fits shows none). */
|
|
24
25
|
const cutShort = (el: HTMLElement) => el.scrollWidth > el.clientWidth + 1
|
|
@@ -55,11 +56,13 @@ export function FocusPanel({ children, left, width = 580, onClose }: { children:
|
|
|
55
56
|
|
|
56
57
|
/** More work words not sent yet, by card - they survive the panel closing on a click elsewhere. */
|
|
57
58
|
const moreDrafts = new Map<string, string>()
|
|
58
|
-
export const clearMoreDraft = (id: string) => { moreDrafts.delete(id) }
|
|
59
|
+
export const clearMoreDraft = (id: string) => { moreDrafts.delete(id); workChanged() }
|
|
59
60
|
export const moreDraftOf = (id: string): string => moreDrafts.get(id) ?? ''
|
|
60
|
-
export const setMoreDraft = (id: string, t: string) => { if (t) moreDrafts.set(id, t); else moreDrafts.delete(id) }
|
|
61
|
+
export const setMoreDraft = (id: string, t: string) => { if (t) moreDrafts.set(id, t); else moreDrafts.delete(id); workChanged() }
|
|
61
62
|
// spec 28 A1.11: a page whose canvas came back reloads only once no such words wait (a reload would drop them)
|
|
62
63
|
holdsReload(() => moreDrafts.size > 0)
|
|
64
|
+
// and leaving the page asks first (spec 28 A2.9)
|
|
65
|
+
unsavedWhen('typing', () => moreDrafts.size > 0)
|
|
63
66
|
|
|
64
67
|
const unquote = (s: string) => s.replace(/^"(.*)"$/s, '$1')
|
|
65
68
|
const DEVICE: Record<string, string> = { phone: 'mobile', mobile: 'mobile', tablet: 'tablet', laptop: 'laptop', desktop: 'monitor', monitor: 'monitor', tv: 'tv' }
|
|
@@ -370,7 +373,7 @@ export function ReviewDetail({ title, head, of, onPrev, onNext, frames, active,
|
|
|
370
373
|
// the More work words outlive the panel: a click elsewhere closes it, and the words wait for its return -
|
|
371
374
|
// they go only when sent, or when you leave the composer yourself (Esc)
|
|
372
375
|
const [text, setTextState] = useState(() => (draftKey ? moreDrafts.get(draftKey) ?? '' : ''))
|
|
373
|
-
const setText = (t: string) => { setTextState(t); if (draftKey) { if (t) moreDrafts.set(draftKey, t); else moreDrafts.delete(draftKey) } }
|
|
376
|
+
const setText = (t: string) => { setTextState(t); if (draftKey) { if (t) moreDrafts.set(draftKey, t); else moreDrafts.delete(draftKey); workChanged() } }
|
|
374
377
|
const field = useRef<HTMLTextAreaElement>(null)
|
|
375
378
|
useEffect(() => { if (draftKey && moreDrafts.get(draftKey) && !more) onMoreOpen(true) }, []) // back with words waiting: the composer is open
|
|
376
379
|
// left on purpose (Esc cleared its words from the map): the composer's words go too; closed by a click
|
|
@@ -145,8 +145,11 @@ interface Segment {
|
|
|
145
145
|
}
|
|
146
146
|
interface Mic { ctx: AudioContext; stream: MediaStream; node: AudioWorkletNode; seg: Segment | null; closed: boolean }
|
|
147
147
|
let mic: Mic | null = null
|
|
148
|
-
/** A microphone being opened (its permission, its worklet): a newer change cancels it.
|
|
149
|
-
|
|
148
|
+
/** A microphone being opened (its permission, its worklet, its connection): a newer change cancels it. It holds
|
|
149
|
+
* what it has opened so far, so a cancel stops its track and closes its context in that same turn - an opening
|
|
150
|
+
* can wait on a request that never answers, and a track it holds is live until stopped (A2.14 #13). */
|
|
151
|
+
interface Opening { cancelled: boolean; stream: MediaStream | null; ctx: AudioContext | null }
|
|
152
|
+
let opening: Opening | null = null
|
|
150
153
|
let segN = 0
|
|
151
154
|
/** segment -> its owner (the words it brings back belong to it) */
|
|
152
155
|
const owners = new Map<string, Owner>()
|
|
@@ -316,10 +319,30 @@ function endSegment(s: Segment, at: { start: number; pcm: Int16Array; mark: numb
|
|
|
316
319
|
/** Who the microphone should hear now: what runs (a capture, else the session's talk) - if you said yes
|
|
317
320
|
* and the engine can run. */
|
|
318
321
|
const wanted = (): Owner | null => {
|
|
322
|
+
if (barred) return null
|
|
319
323
|
const v = useJamVoice.getState()
|
|
320
324
|
return v.choice === 'yes' && (v.server === 'ready' || v.server === 'loading') ? target() : null
|
|
321
325
|
}
|
|
322
326
|
|
|
327
|
+
/** The page lost the Mac app's trust while it lives (spec 28 A2.14 #13, `mv:app-state untrusted`): the app can refuse
|
|
328
|
+
* every new microphone request, but only the page can stop a track it already holds. */
|
|
329
|
+
let barred = false
|
|
330
|
+
/** Every microphone track this page holds stops now - the way a lost connection stops it: the words heard so far
|
|
331
|
+
* are kept, marked maybe incomplete - an opening still waiting is cancelled, and nothing opens the microphone again
|
|
332
|
+
* in this document (the next one is proved afresh). */
|
|
333
|
+
export function voiceUntrusted(): void {
|
|
334
|
+
barred = true
|
|
335
|
+
cancelOpening()
|
|
336
|
+
const m = mic
|
|
337
|
+
if (m && !m.closed) {
|
|
338
|
+
if (m.seg) broken.add(m.seg.owner.id)
|
|
339
|
+
closeNow(m)
|
|
340
|
+
if (mic === m) mic = null
|
|
341
|
+
setLive()
|
|
342
|
+
}
|
|
343
|
+
useJamVoice.setState({ asking: false })
|
|
344
|
+
}
|
|
345
|
+
|
|
323
346
|
/** Bring the microphone to what should be heard NOW. Every change - open, switch, close - is one step in
|
|
324
347
|
* one chain, so no change overtakes another: a switch ends the current segment and starts the next at
|
|
325
348
|
* the same worklet mark (nothing lost, nothing heard twice); an opening still waiting gives way to a
|
|
@@ -350,19 +373,20 @@ async function step() {
|
|
|
350
373
|
|
|
351
374
|
/** Open the microphone for `owner` - one step of the chain; a newer state cancels it at its next wait. */
|
|
352
375
|
async function open(owner: Owner) {
|
|
353
|
-
const op = { cancelled: false }
|
|
376
|
+
const op: Opening = { cancelled: false, stream: null, ctx: null }
|
|
354
377
|
opening = op
|
|
355
378
|
const stale = () => op.cancelled || wanted()?.id !== owner.id
|
|
356
|
-
|
|
357
|
-
let ctx: AudioContext | null = null
|
|
358
|
-
const undo = () => { stream?.getTracks().forEach((t) => t.stop()); void ctx?.close().catch(() => {}) }
|
|
379
|
+
const undo = () => release(op)
|
|
359
380
|
try {
|
|
360
381
|
// the microphone first (its permission, its worklet), the connection last: a page never holds the one
|
|
361
382
|
// audio connection while it is still starting - and a reclaim takes it only if it is free
|
|
383
|
+
let stream: MediaStream
|
|
362
384
|
try { stream = await navigator.mediaDevices.getUserMedia({ audio: { channelCount: 1, echoCancellation: true, noiseSuppression: true } }) }
|
|
363
385
|
catch { useJamVoice.setState({ denied: true }); useStore.getState().toast('the microphone is blocked for this page - typed notes only'); return }
|
|
386
|
+
op.stream = stream
|
|
364
387
|
if (stale()) { undo(); return }
|
|
365
|
-
ctx = new AudioContext({ sampleRate: RATE })
|
|
388
|
+
const ctx = new AudioContext({ sampleRate: RATE })
|
|
389
|
+
op.ctx = ctx
|
|
366
390
|
await ctx.audioWorklet.addModule(URL.createObjectURL(new Blob([WORKLET], { type: 'application/javascript' })))
|
|
367
391
|
if (stale()) { undo(); return }
|
|
368
392
|
// a capture is something you just did here: it takes the connection; a session's talk only takes it if it
|
|
@@ -375,6 +399,9 @@ async function open(owner: Owner) {
|
|
|
375
399
|
const node = new AudioWorkletNode(ctx, 'mv-pcm')
|
|
376
400
|
ctx.createMediaStreamSource(stream).connect(node)
|
|
377
401
|
const m: Mic = { ctx, stream, node, seg: null, closed: false }
|
|
402
|
+
// the microphone owns them now: closeNow stops them, never the opening
|
|
403
|
+
op.stream = null
|
|
404
|
+
op.ctx = null
|
|
378
405
|
mic = m
|
|
379
406
|
const seg = segmentFor(owner, -1)
|
|
380
407
|
m.seg = seg
|
|
@@ -385,10 +412,21 @@ async function open(owner: Owner) {
|
|
|
385
412
|
setLive()
|
|
386
413
|
} catch {
|
|
387
414
|
undo()
|
|
388
|
-
|
|
415
|
+
// a cancelled opening whose context closed under its worklet says nothing: nothing failed
|
|
416
|
+
if (!op.cancelled) useStore.getState().toast('the microphone could not start - typed notes only')
|
|
389
417
|
} finally { if (opening === op) opening = null }
|
|
390
418
|
}
|
|
391
|
-
|
|
419
|
+
/** What an opening holds goes, once: its tracks stopped, its context closed. */
|
|
420
|
+
function release(op: Opening) {
|
|
421
|
+
const { stream, ctx } = op
|
|
422
|
+
op.stream = null
|
|
423
|
+
op.ctx = null
|
|
424
|
+
stream?.getTracks().forEach((t) => t.stop())
|
|
425
|
+
void ctx?.close().catch(() => {})
|
|
426
|
+
}
|
|
427
|
+
/** A newer change, or the app's `untrusted`: the opening goes, and what it already holds stops now - not at its
|
|
428
|
+
* next wait, which may never come. The opening still sees itself cancelled when that wait ends, and opens nothing. */
|
|
429
|
+
const cancelOpening = () => { if (opening) { opening.cancelled = true; release(opening) } }
|
|
392
430
|
/** The chain settled - but never longer than `ms` (an opening may wait on the browser's permission
|
|
393
431
|
* question; what the caller needs - the cuts of its segments - is done before it). */
|
|
394
432
|
const settle = (ms = 2_000) => Promise.race([reconcile(), new Promise<void>((r) => setTimeout(r, ms))])
|
|
@@ -478,4 +516,4 @@ export async function voiceSessionEnd(): Promise<void> {
|
|
|
478
516
|
await settled(s.id)
|
|
479
517
|
}
|
|
480
518
|
|
|
481
|
-
if (typeof window !== 'undefined' && (import.meta as any).env?.DEV) { (window as any).__mvJamVoice = useJamVoice; (window as any).__mvJamVoiceSession = voiceSessionId }
|
|
519
|
+
if (typeof window !== 'undefined' && (import.meta as any).env?.DEV) { (window as any).__mvJamVoice = useJamVoice; (window as any).__mvJamVoiceSession = voiceSessionId; (window as any).__mvJamVoiceTalk = voiceSession }
|
|
@@ -1,13 +1,26 @@
|
|
|
1
1
|
import { createRoot } from 'react-dom/client'
|
|
2
|
-
|
|
2
|
+
// an all-boards-locked build gives LockedApp.tsx in App.tsx's place: what only the canvas uses comes through it
|
|
3
|
+
import { App, ShellBoundary, startPerfRunProbe } from './App.tsx'
|
|
3
4
|
import { useStore } from './store.ts'
|
|
4
5
|
import { startRecorder } from './recorder.ts'
|
|
5
6
|
import { capturesPending, sealOnLeave } from './jam-capture.ts'
|
|
7
|
+
import { startAppBridge } from './app-bridge.ts'
|
|
8
|
+
import { startAppPerf } from './app-perf.ts'
|
|
9
|
+
import { applyInset } from './inset.ts'
|
|
6
10
|
import './styles.css'
|
|
7
11
|
|
|
8
12
|
// dev aid: inspectable store (harmless in builds; the canvas is a dev surface)
|
|
9
13
|
;(window as any).__sh = useStore
|
|
10
14
|
// what each board load does, from the page (spec 28 A1.7): before the first load; nothing on a published canvas
|
|
11
15
|
startRecorder({ capturesPending, sealCaptures: sealOnLeave })
|
|
16
|
+
// under the Mac app's transparent strip (0.27.2, A3.8 #31): --mv-top on :root before anything is placed; nothing
|
|
17
|
+
// anywhere else (Chrome, a published canvas, app 0.1)
|
|
18
|
+
applyInset()
|
|
19
|
+
// in the Mac app: hello, theme, busy and menu before the first render (spec 28 A2.9); nothing anywhere else
|
|
20
|
+
startAppBridge()
|
|
21
|
+
// in the Mac app 0.2: the recorder's probes and the board's frame count (spec 28 A3.8 #9, #16); nothing anywhere else
|
|
22
|
+
startAppPerf()
|
|
23
|
+
// a headless perf run (spec 28 A3.8 #17): what its driver reads and asks, through CDP - nothing without ?mvperfrun
|
|
24
|
+
startPerfRunProbe()
|
|
12
25
|
|
|
13
26
|
createRoot(document.getElementById('root')!).render(<ShellBoundary><App /></ShellBoundary>)
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* carries the state (blue new, orange needs you); the row's one right-hand slot holds what matters
|
|
4
4
|
* most: a question's numbered bubble, then the row's own count or status, then a frame's dot.
|
|
5
5
|
*/
|
|
6
|
+
import { onScreen } from './inset.ts'
|
|
6
7
|
import { useEffect, type HTMLAttributes, type ReactNode } from 'react'
|
|
7
8
|
import { create } from 'zustand'
|
|
8
9
|
import { useStore, PUBLISHED, shownRev } from './store.ts'
|
|
@@ -95,13 +96,14 @@ export function useSeenOnScreen() {
|
|
|
95
96
|
} else if (m && !document.hidden && s.scale >= 0.5) {
|
|
96
97
|
// in view: some of it inside the window and not all of that under the open sidebar
|
|
97
98
|
const P = document.querySelector('.sh-panel:not(.closed)')?.getBoundingClientRect()
|
|
98
|
-
const W = window.innerWidth, H = window.innerHeight
|
|
99
99
|
for (const n of s.nodes) {
|
|
100
100
|
if (n.status !== 'ready' || n.stale || !isNew(m, n.frame) || shownRev(n, m) < (m.doc[n.frame] ?? 0)) continue
|
|
101
101
|
const r = document.querySelector<HTMLElement>(`.sh-node[data-node="${CSS.escape(n.key)}"]`)?.getBoundingClientRect()
|
|
102
102
|
if (!r) continue
|
|
103
|
-
|
|
104
|
-
|
|
103
|
+
// the part on screen below the scroll edge (inset.ts): under the Mac app's strip is not seen
|
|
104
|
+
const on = onScreen(r)
|
|
105
|
+
if (!on) continue
|
|
106
|
+
const x0 = on.left, x1 = on.right, y0 = on.top, y1 = on.bottom
|
|
105
107
|
if (P && x0 >= P.left && x1 <= P.right && y0 >= P.top && y1 <= P.bottom) continue
|
|
106
108
|
shown.set(`${n.key}@${m.changed[n.frame] ?? 0}:${n.shown}`, n.key)
|
|
107
109
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `window.marverApp` - there only when this page is a verified local canvas in the Mac app (spec 28 A2.9; the app's
|
|
3
|
+
* canvas preload exposes it). Everywhere else - Chrome, Safari, a published canvas, `marver shot` - it is null, and
|
|
4
|
+
* nothing that reads it does anything. Kept apart from app-bridge.ts, so the canvas can read `reopen` without
|
|
5
|
+
* importing the bridge.
|
|
6
|
+
*/
|
|
7
|
+
import type { MarverAppV1 } from '../../shared/app-api.ts'
|
|
8
|
+
|
|
9
|
+
/** The app's bridge, when it speaks this version of the contract and has every method this shell calls. */
|
|
10
|
+
export const APP: MarverAppV1 | null = (() => {
|
|
11
|
+
try {
|
|
12
|
+
const a = (globalThis as { marverApp?: Partial<MarverAppV1> }).marverApp
|
|
13
|
+
if (!a || a.v !== 1) return null
|
|
14
|
+
const calls = ['hello', 'theme', 'busy', 'menu', 'onAppState', 'onMenuClick'] as const
|
|
15
|
+
return calls.every((k) => typeof a[k] === 'function') ? a as MarverAppV1 : null
|
|
16
|
+
} catch { return null }
|
|
17
|
+
})()
|
|
18
|
+
|
|
19
|
+
/** The app reloaded this tab after a crash: the canvas opens on its saved camera, even when the link names a
|
|
20
|
+
* selection (A2.14 #9). */
|
|
21
|
+
export const APP_REOPEN = APP?.reopen === true
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A headless perf run's probe (spec 28 A3.8 #17): what its driver reads and asks, through CDP - nothing without
|
|
3
|
+
* ?mvperfrun. Canvas code (the camera, the gestures, the sleeps): main.tsx reaches it through App.tsx, so an
|
|
4
|
+
* all-boards-locked bundle, which the build gives LockedApp.tsx in App.tsx's place, carries none of it - a run's page
|
|
5
|
+
* is always a dev canvas, never a locked one.
|
|
6
|
+
*/
|
|
7
|
+
import { currentLoad, flush } from './recorder.ts'
|
|
8
|
+
import { installPerfRunProbe, PERF_RUN, postersSkipped, refusedInPage } from './perf-run.ts'
|
|
9
|
+
import { bakeIdle, bakeWork } from './canvas/sleep.ts'
|
|
10
|
+
import { canvasCtl } from './canvas/ctl.ts'
|
|
11
|
+
import { gestureRunning, gesturesEnded } from './perf.ts'
|
|
12
|
+
|
|
13
|
+
/** main.tsx, after startAppPerf(): the probe, installed only on a run's page. */
|
|
14
|
+
export function startPerfRunProbe(): void {
|
|
15
|
+
if (!PERF_RUN) return
|
|
16
|
+
const run = PERF_RUN
|
|
17
|
+
const moving = () => gestureRunning() || canvasCtl.cameraBusy()
|
|
18
|
+
const wait = (ms: number) => new Promise((r) => setTimeout(r, ms))
|
|
19
|
+
installPerfRunProbe({
|
|
20
|
+
status: () => ({ run: run.id, warm: run.warm, load: currentLoad(), bakeIdle: bakeIdle(), bake: bakeWork(), moving: moving(), gestures: gesturesEnded(), postersSkipped: postersSkipped(), refused: refusedInPage() }),
|
|
21
|
+
// the whole board, then the camera still (two looks 50 ms apart), 3 s at most
|
|
22
|
+
async fit() {
|
|
23
|
+
canvasCtl.fitAll()
|
|
24
|
+
const by = performance.now() + 3000
|
|
25
|
+
for (let still = 0; performance.now() < by; await wait(50)) if (moving()) still = 0; else if (++still >= 2) return true
|
|
26
|
+
return false
|
|
27
|
+
},
|
|
28
|
+
centre() {
|
|
29
|
+
const r = document.querySelector('.sh-canvas')?.getBoundingClientRect()
|
|
30
|
+
return r ? { x: Math.round(r.left + r.width / 2), y: Math.round(r.top + r.height / 2) } : { x: Math.round(innerWidth / 2), y: Math.round(innerHeight / 2) }
|
|
31
|
+
},
|
|
32
|
+
flush,
|
|
33
|
+
})
|
|
34
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Perf mode, the page's half of a headless run (spec 28 A3.4, A3.8 #17): `?mvperfrun=<16 hex>[&warm=1]` sets
|
|
3
|
+
* `PERF_RUN` at module load, before boot, in dev only. Owner: the headless stream; the contract is
|
|
4
|
+
* src/shared/perf-run.ts, which the server reads too.
|
|
5
|
+
*
|
|
6
|
+
* - The barrier sits in `mvFetch` (api.ts), before any `fetch`: GET and HEAD pass, and under `${ROUTE}/api/` only
|
|
7
|
+
* `POST perf/page` and `POST bakes`; anything else gets a synthetic 403, counted as `refused`, and never reaches
|
|
8
|
+
* `lost()`. Every request carries `x-mv-perfrun`; `withWs()` adds `mvperfrun` to frame URLs, the play stage and
|
|
9
|
+
* Jam pictures.
|
|
10
|
+
* - Warm mode: the recorder runs (the driver reads `settled` from it) and posts nothing; `flush()` sends until the
|
|
11
|
+
* outbox is empty and answers whether every batch landed.
|
|
12
|
+
* - In perf mode `beforeunload` never refuses, and the Video primitive never asks for a poster
|
|
13
|
+
* (`data-mv-poster-skipped`).
|
|
14
|
+
* - `window.__mvPerfRun` (`PerfRunProbe`): status(), fit(), centre(), flush().
|
|
15
|
+
*
|
|
16
|
+
* FROZEN (A3.8 #53): `PERF_RUN`, `runApiPath`, `perfRunGate` and `installPerfRunProbe`'s signature.
|
|
17
|
+
*/
|
|
18
|
+
import { ROUTE } from '../const.ts'
|
|
19
|
+
import { allowedInRun, RUN_HEADER, RUN_ID, RUN_PARAM, WARM_PARAM, type PerfRunProbe } from '../../shared/perf-run.ts'
|
|
20
|
+
|
|
21
|
+
export * from '../../shared/perf-run.ts'
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* This page's run, or null: a published canvas (a production build), or no `mvperfrun`. Read with no import of
|
|
25
|
+
* api.ts, which calls `perfRunGate` (a cycle would read this before it exists).
|
|
26
|
+
*/
|
|
27
|
+
export const PERF_RUN: { id: string; warm: boolean } | null = (() => {
|
|
28
|
+
if (!import.meta.env.DEV) return null
|
|
29
|
+
try {
|
|
30
|
+
const q = new URLSearchParams(location.search)
|
|
31
|
+
const id = q.get(RUN_PARAM)
|
|
32
|
+
return id && RUN_ID.test(id) ? { id, warm: q.get(WARM_PARAM) === '1' } : null
|
|
33
|
+
} catch { return null }
|
|
34
|
+
})()
|
|
35
|
+
|
|
36
|
+
/** The path under `${ROUTE}/api/` a URL names (no query), or null for any other path. */
|
|
37
|
+
export function runApiPath(url: string): string | null {
|
|
38
|
+
let p: string
|
|
39
|
+
try { p = new URL(url, location.href).pathname } catch { return null }
|
|
40
|
+
const base = `${ROUTE}/api/`
|
|
41
|
+
return p.startsWith(base) ? p.slice(base.length) : null
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
let refused = 0
|
|
45
|
+
/** Requests refused before sending, so far. */
|
|
46
|
+
export const refusedInPage = (): number => refused
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The barrier, called first by `mvFetch` in perf mode: null lets the request go (it then carries `x-mv-perfrun`);
|
|
50
|
+
* a Response is the synthetic refusal, never sent.
|
|
51
|
+
*/
|
|
52
|
+
export function perfRunGate(url: string, init: RequestInit = {}): Response | null {
|
|
53
|
+
if (!PERF_RUN) return null
|
|
54
|
+
if (allowedInRun(init.method ?? 'GET', runApiPath(url))) return null
|
|
55
|
+
refused += 1
|
|
56
|
+
return new Response('{"error":"a perf run is read-only"}', { status: 403, headers: { 'content-type': 'application/json', [RUN_HEADER]: 'refused' } })
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Same-origin frames whose document skipped a missing poster (the Video primitive's `data-mv-poster-skipped`). */
|
|
60
|
+
export function postersSkipped(): number {
|
|
61
|
+
let n = 0
|
|
62
|
+
for (const f of document.querySelectorAll('iframe')) { try { if (f.contentDocument?.documentElement.hasAttribute('data-mv-poster-skipped')) n++ } catch { /* another origin */ } }
|
|
63
|
+
return n
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** main.tsx in perf mode: `window.__mvPerfRun`. */
|
|
67
|
+
export function installPerfRunProbe(probe: PerfRunProbe): void {
|
|
68
|
+
if (!PERF_RUN) return
|
|
69
|
+
;(window as unknown as { __mvPerfRun?: PerfRunProbe }).__mvPerfRun = probe
|
|
70
|
+
}
|
package/src/client/shell/perf.ts
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
* perfMark(name) + counters are the plug points later stages use (blank-frame / warm-latency).
|
|
13
13
|
*/
|
|
14
14
|
import { onMotion, type Motion } from './canvas/camera-broadcast.ts'
|
|
15
|
+
import { gestureOff, gestureOn } from './app-perf.ts'
|
|
15
16
|
import { recorder } from './recorder.ts'
|
|
16
17
|
import { gestureStats } from './recorder-core.ts'
|
|
17
18
|
|
|
@@ -34,6 +35,12 @@ const enabled = (): boolean => {
|
|
|
34
35
|
interface Run { t0: number; last: number; dts: number[]; pan: boolean; zoom: boolean; layout: boolean; longs: number[]; obs?: PerformanceObserver; raf: number }
|
|
35
36
|
/** the gesture running now */
|
|
36
37
|
let g: Run | null = null
|
|
38
|
+
/** gestures ended so far, every one (a headless perf run waits for each of its three, spec 28 A3.8 #20) */
|
|
39
|
+
let ended = 0
|
|
40
|
+
/** How many gestures have ended since the page loaded. */
|
|
41
|
+
export const gesturesEnded = (): number => ended
|
|
42
|
+
/** Is a gesture (a pan, a zoom, a layout animation) running now? */
|
|
43
|
+
export const gestureRunning = (): boolean => g !== null
|
|
37
44
|
|
|
38
45
|
function note(m: Motion) {
|
|
39
46
|
if (!g) return
|
|
@@ -45,6 +52,8 @@ function begin(m: Motion) {
|
|
|
45
52
|
const run: Run = { t0: performance.now(), last: 0, dts: [], pan: false, zoom: false, layout: false, longs: [], raf: 0 }
|
|
46
53
|
g = run
|
|
47
54
|
note(m)
|
|
55
|
+
// the Mac app's recorder hears it start (the white-out detector's window, spec 28 A3.8 #15); nothing elsewhere
|
|
56
|
+
gestureOn(run.pan ? 'pan' : run.zoom ? 'zoom' : run.layout ? 'layout' : undefined)
|
|
48
57
|
try {
|
|
49
58
|
run.obs = new PerformanceObserver((l) => { for (const e of l.getEntries()) if (e.startTime >= run.t0) run.longs.push(e.duration) })
|
|
50
59
|
run.obs.observe({ type: LOAF ? 'long-animation-frame' : 'longtask', buffered: false })
|
|
@@ -62,10 +71,12 @@ function begin(m: Motion) {
|
|
|
62
71
|
function end() {
|
|
63
72
|
const run = g!
|
|
64
73
|
g = null
|
|
74
|
+
ended++
|
|
65
75
|
cancelAnimationFrame(run.raf)
|
|
66
76
|
const t1 = performance.now()
|
|
67
77
|
for (const e of run.obs?.takeRecords() ?? []) if (e.startTime >= run.t0 && e.startTime <= t1) run.longs.push(e.duration)
|
|
68
78
|
run.obs?.disconnect()
|
|
79
|
+
gestureOff()
|
|
69
80
|
for (const d of run.dts) { frames.push(d); if (frames.length > MAX) frames.shift() }
|
|
70
81
|
for (const d of run.longs) { longs.push(d); if (longs.length > MAX) longs.shift() }
|
|
71
82
|
if (run.dts.length < 2) return // a press that never moved the camera
|