@marver-design/marver 0.26.1 → 0.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +104 -0
- package/README.md +8 -3
- package/dist/{anchor-check-l-ny3UzH.mjs → anchor-check-ChdDqL5z.mjs} +1 -1
- package/dist/{bake-C-awKgLA.mjs → bake-DM_uWgAA.mjs} +1 -1
- package/dist/{boards-DYG22tOe.mjs → boards-DlTcpF47.mjs} +1 -1
- package/dist/{build-BDRiO_mP.mjs → build-DZnFysGU.mjs} +4 -4
- package/dist/cli.mjs +28 -16
- package/dist/{comments-BqXua-XL.mjs → comments-DxOkCSNE.mjs} +4 -4
- package/dist/{daemon-DL6Fwq6D.mjs → daemon-BSA0lV8d.mjs} +8 -6
- package/dist/detect-C0wpaePX.mjs +125 -0
- package/dist/dev-eQJhWsqg.mjs +1273 -0
- package/dist/dev-lock-C_FC70Mu.mjs +65 -0
- package/dist/exclusive-B1RtpeeP.mjs +150 -0
- package/dist/{init-D8DtrK_F.mjs → init-COD0x48i.mjs} +5 -3
- package/dist/{link-BNzLvdhI.mjs → link-DDXZVGtv.mjs} +20 -8
- package/dist/ls-D7O1G505.mjs +38 -0
- package/dist/{marks-DyWMv_Z1.mjs → marks-CWM3WJjc.mjs} +1 -1
- package/dist/perf-BWzQwZqj.mjs +369 -0
- package/dist/perf-BoDSkbEb.mjs +429 -0
- package/dist/{perf-jam-BU3TVrZu.mjs → perf-jam-D55U3FZK.mjs} +5 -2
- package/dist/{plugin-DkGmZs_r.mjs → plugin-C-E7omsh.mjs} +394 -55
- package/dist/{poster-BdtSKMDm.mjs → poster-Bx83ZYVK.mjs} +1 -1
- package/dist/{profile-WU9qcbIo.mjs → profile-Bh5Y5zpW.mjs} +1 -1
- package/dist/{publish-bakes-9RzRToXV.mjs → publish-bakes-aljgm45S.mjs} +2 -2
- package/dist/{queue-29ok5_eZ.mjs → queue-CAM_vNmX.mjs} +1 -1
- package/dist/recover-t9Pno3u9.mjs +66 -0
- package/dist/{share--oFJ1bCI.mjs → share-W5H3BNvP.mjs} +1 -1
- package/dist/{shot-XQV7HC9A.mjs → shot-DoHLl6ig.mjs} +1 -1
- package/dist/{shot-DQeR_Pfn.mjs → shot-LFhC-WYD.mjs} +9 -3
- package/dist/slots-DCDo3N0x.mjs +471 -0
- package/dist/{sync-DKk-yT1V.mjs → sync-BQVlHZpx.mjs} +4 -3
- package/dist/{work-F5u-twpJ.mjs → work-Bp1p39kq.mjs} +4 -2
- package/dist/{work-VvX_JIgl.mjs → work-BroFwnup.mjs} +4 -2
- package/docs/boards-and-folders.md +3 -1
- package/docs/jam-session.md +55 -1
- package/docs/performance.md +262 -0
- package/package.json +2 -2
- package/src/client/content/index.tsx +3 -0
- package/src/client/content/video.tsx +6 -2
- package/src/client/frame-host/bridge.js +22 -6
- package/src/client/frame-host/main.tsx +17 -5
- package/src/client/shell/App.tsx +180 -25
- package/src/client/shell/BoardList.tsx +5 -5
- package/src/client/shell/Comments.tsx +3 -2
- package/src/client/shell/JamSurface.tsx +4 -2
- package/src/client/shell/LockedApp.tsx +5 -5
- package/src/client/shell/Play.tsx +16 -8
- package/src/client/shell/Toolbar.tsx +12 -1
- package/src/client/shell/api.ts +206 -0
- package/src/client/shell/canvas/Canvas.tsx +30 -3
- package/src/client/shell/canvas/FrameNode.tsx +12 -3
- package/src/client/shell/canvas/admission.ts +8 -1
- package/src/client/shell/canvas/camera-broadcast.ts +15 -5
- package/src/client/shell/canvas/ctl.ts +2 -0
- package/src/client/shell/canvas/frame-registry.ts +28 -2
- package/src/client/shell/canvas/sleep.ts +4 -1
- package/src/client/shell/comments-store.ts +12 -4
- package/src/client/shell/goto.ts +22 -10
- package/src/client/shell/jam-capture.ts +22 -8
- package/src/client/shell/jam-keys.ts +4 -0
- package/src/client/shell/jam-panel.tsx +3 -0
- package/src/client/shell/jam-queue.ts +3 -3
- package/src/client/shell/jam-session.tsx +14 -8
- package/src/client/shell/jam-voice.ts +7 -5
- package/src/client/shell/legacy-links.ts +2 -2
- package/src/client/shell/main.tsx +4 -0
- package/src/client/shell/notes.ts +8 -1
- package/src/client/shell/perf.ts +69 -58
- package/src/client/shell/recorder-core.ts +183 -0
- package/src/client/shell/recorder.ts +565 -0
- package/src/client/shell/store.ts +254 -98
- package/src/client/shell/styles.css +26 -1
- package/templates/AGENTS-embedded.md +22 -4
- package/templates/AGENTS-studio.md +22 -4
- package/templates/demo/dark.tsx +1 -1
- package/templates/demo/welcome.tsx +1 -1
- package/templates/instructions/welcome.md +6 -3
- package/dist/config-Cf7EjAMf.mjs +0 -292
- package/dist/dev-Bw_qYWWq.mjs +0 -755
- package/dist/dev-lock-DWSpa6nj.mjs +0 -179
- package/dist/perf-C75MZ73h.mjs +0 -167
- package/dist/perf-DPbLGhhO.mjs +0 -49
|
@@ -14,13 +14,15 @@
|
|
|
14
14
|
* id it carries.
|
|
15
15
|
*/
|
|
16
16
|
import { create } from 'zustand'
|
|
17
|
-
import {
|
|
18
|
-
import { CONFIG, SLIDE_INTRINSIC, useStore, type Node } from './store.ts'
|
|
17
|
+
import { slideSize } from '../const.ts'
|
|
18
|
+
import { CONFIG, SLIDE_INTRINSIC, stoppedFor, useStore, type Node } from './store.ts'
|
|
19
19
|
import { UNPLACED } from './hash.ts'
|
|
20
20
|
import type { Bundle, CaptureRecord, Step, View } from '../../server/jam/types.ts'
|
|
21
21
|
import { forgetHeard, RATE, setWordsListener, voiceBegin, voiceDrop, voiceEnd } from './jam-voice.ts'
|
|
22
22
|
import { touchedFrames } from '../../shared/capture-frames.ts'
|
|
23
23
|
import { onStageSize, stageSize } from './stage-size.ts'
|
|
24
|
+
import { api, holdsReload } from './api.ts'
|
|
25
|
+
import { bytesOf } from './recorder-core.ts'
|
|
24
26
|
|
|
25
27
|
const csrf = () => /(?:^|;\s*)mv_c=([\w-]+)/.exec(document.cookie)?.[1] ?? ''
|
|
26
28
|
const now = () => performance.timeOrigin + performance.now()
|
|
@@ -550,7 +552,7 @@ function shoot(id: string, frame: string, why: 'key' | 'pick' | 'end', key?: str
|
|
|
550
552
|
// settled exactly once - a picture, or a missing one - whatever fails: the request, its body, the abort
|
|
551
553
|
let settled = false
|
|
552
554
|
const finish = (pid: string | null) => { if (settled) return; settled = true; clearTimeout(timer); done(pid, ctl.signal.aborted) }
|
|
553
|
-
|
|
555
|
+
api('jam/picture', {
|
|
554
556
|
method: 'POST', signal: ctl.signal, headers: { 'content-type': 'application/json', 'x-mv-c': csrf() },
|
|
555
557
|
body: JSON.stringify({ capture: id, frame, theme, ...(size ? { w: Math.round(size.width), h: Math.round(size.height) } : {}) }),
|
|
556
558
|
}).then(async (r) => (r.ok ? ((await r.json()) as { id?: string }).id ?? null : null))
|
|
@@ -570,7 +572,7 @@ export const setSessionEnding = (on: boolean) => { sessionEnding = on }
|
|
|
570
572
|
* that every 20 s until it lands or is dropped: the session's record waits for it, whatever tab ends it. */
|
|
571
573
|
const openOnServer = new Map<string, { session: string; timer: ReturnType<typeof setInterval> }>()
|
|
572
574
|
const tellOpen = (capture: string, session: string, on: boolean) => {
|
|
573
|
-
void
|
|
575
|
+
void api('jam/capture-open', { method: 'POST', headers: { 'content-type': 'application/json', 'x-mv-c': csrf() }, body: JSON.stringify({ capture, session, on }) })
|
|
574
576
|
.then(async (r) => { if (on && r.status === 409 && (await r.json().catch(() => null))?.ended) leftOutOfSession(capture) }, () => {})
|
|
575
577
|
}
|
|
576
578
|
/** The server had already written the session's record (in another tab) when it heard of this capture: it is
|
|
@@ -761,7 +763,7 @@ function sealedSizes(c: Cap): Record<string, { w: number; h: number; play?: true
|
|
|
761
763
|
|
|
762
764
|
/** Jam timings (spec 27a Part D): numbers only, to the dev server's local log - best effort, never in the way. */
|
|
763
765
|
const perf = (body: Record<string, unknown>, keepalive = false) => {
|
|
764
|
-
try { void
|
|
766
|
+
try { void api('perf/jam', { method: 'POST', headers: { 'content-type': 'application/json', 'x-mv-c': csrf() }, body: JSON.stringify(body), ...(keepalive ? { keepalive: true } : {}) }).catch(() => {}) } catch { /* never in the way */ }
|
|
765
767
|
}
|
|
766
768
|
/** A capture's timing as it seals: E to sealed (none when the page sealed it), the wait for its words, its pictures. */
|
|
767
769
|
function timeCapture(c: Cap, interrupted: boolean) {
|
|
@@ -806,6 +808,10 @@ function trySeal(id: string) {
|
|
|
806
808
|
/** Kept per workspace: another project served later on the same port never receives this one's captures. */
|
|
807
809
|
const KEPT = `mv-jam-sealed:${CONFIG.workspace ?? 'unknown'}`
|
|
808
810
|
const syncUnsent = () => useJamCapture.setState({ unsent: [...pendingUploads.keys()] })
|
|
811
|
+
/** A capture is still open (a page that goes seals and sends it), or sealed and not taken by the server yet (waiting,
|
|
812
|
+
* or on its way): the recorder leaves a page's keepalive allowance to it (spec 28 A1.7). By state, not by the order
|
|
813
|
+
* the pagehide listeners run in. */
|
|
814
|
+
export const capturesPending = (): boolean => { const s = useJamCapture.getState(); return s.unsent.length > 0 || Object.keys(s.caps).length > 0 }
|
|
809
815
|
const keepSealed = (r: CaptureRecord) => { try { const all = JSON.parse(localStorage.getItem(KEPT) ?? '{}'); all[r.id] = r; localStorage.setItem(KEPT, JSON.stringify(all)) } catch { /* memory only */ } pendingUploads.set(r.id, r); syncUnsent() }
|
|
810
816
|
const forgetSealed = (id: string) => { pendingUploads.delete(id); syncUnsent(); try { const all = JSON.parse(localStorage.getItem(KEPT) ?? '{}'); delete all[id]; localStorage.setItem(KEPT, JSON.stringify(all)) } catch { /* memory only */ } }
|
|
811
817
|
const pendingUploads = new Map<string, CaptureRecord>()
|
|
@@ -820,8 +826,9 @@ async function upload(record: CaptureRecord, leaving = false): Promise<void> {
|
|
|
820
826
|
uploadTries.set(record.id, (uploadTries.get(record.id) ?? 0) + 1)
|
|
821
827
|
const tUp = performance.now()
|
|
822
828
|
const payload = JSON.stringify({ record, workspace: CONFIG.workspace })
|
|
823
|
-
// a page that is going sends with keepalive (64 kB at most
|
|
824
|
-
|
|
829
|
+
// a page that is going sends with keepalive (64 kB at most, counted in UTF-8 bytes as the body carries it - not
|
|
830
|
+
// `.length`: notes in another script are wider) so the request outlives it; a bigger one, the next page
|
|
831
|
+
const res = await api('jam/capture', { method: 'POST', headers: { 'content-type': 'application/json', 'x-mv-c': csrf() }, body: payload, ...(leaving && bytesOf(payload) < 60_000 ? { keepalive: true } : {}) })
|
|
825
832
|
const body = (await res.json().catch(() => null)) as Verdict | null
|
|
826
833
|
// only an explicit verdict on THIS record is final: taken (200, naming its card) or refused as a
|
|
827
834
|
// record (400, saying why). Anything else - jam not running yet, another workspace, an unreadable
|
|
@@ -906,11 +913,15 @@ export function resendSealed() {
|
|
|
906
913
|
} catch { /* none */ }
|
|
907
914
|
}
|
|
908
915
|
|
|
916
|
+
// the canvas answered again after it stopped (spec 28 A1.11): the page reloads only when no capture is
|
|
917
|
+
// recording or finishing - a sealed one waits in localStorage and goes out from the next page
|
|
918
|
+
holdsReload(() => capturesPending())
|
|
919
|
+
|
|
909
920
|
/** Resume's work, while the caller holds `settling`: load the record, let the caller settle, start. */
|
|
910
921
|
async function resumeNow(draft: string, ready?: () => Promise<boolean>): Promise<boolean> {
|
|
911
922
|
let rec: CaptureRecord | null = null
|
|
912
923
|
try {
|
|
913
|
-
const r = await
|
|
924
|
+
const r = await api(`jam/capture?id=${encodeURIComponent(draft)}`, { headers: { 'x-mv-c': csrf() } })
|
|
914
925
|
const body = r.ok ? ((await r.json()) as { record?: CaptureRecord; sealed?: boolean }) : null
|
|
915
926
|
if (body?.record && body.sealed !== true) { useStore.getState().toast('the capture changed after it was sealed - it cannot be resumed'); return false }
|
|
916
927
|
rec = body?.record ?? null
|
|
@@ -938,11 +949,14 @@ export const useJamCapture = create<CaptureState>((set, get) => ({
|
|
|
938
949
|
lastEnded: null,
|
|
939
950
|
settling: null,
|
|
940
951
|
async resume(draft, ready) {
|
|
952
|
+
if (stoppedFor('Jam needs the canvas running')) return false // spec 28 A1.11: nothing to take it
|
|
941
953
|
if (get().current) { useStore.getState().toast('a capture is recording - press E to end it first'); return false }
|
|
942
954
|
if (sessionEnding) { useStore.getState().toast('the session is being wrapped up - a moment'); return false }
|
|
943
955
|
return resumeNow(draft, ready)
|
|
944
956
|
},
|
|
945
957
|
start(reviewing, session) {
|
|
958
|
+
// the canvas stopped (spec 28 A1.11): a new capture waits for it - one recording goes on, and is kept
|
|
959
|
+
if (!get().current && stoppedFor('Jam needs the canvas running')) return
|
|
946
960
|
// one capture at a time: the one recording is ended or dropped first
|
|
947
961
|
if (get().current) { useStore.getState().toast('a capture is recording - press E to end it first'); return }
|
|
948
962
|
if (sessionEnding) { useStore.getState().toast('the session is being wrapped up - a moment'); return }
|
|
@@ -22,6 +22,7 @@ import { DONE_CLOSE, DONE_GROUP, doneFold, useJamUi } from './jam-state.ts'
|
|
|
22
22
|
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
|
+
import { holdsReload } from './api.ts'
|
|
25
26
|
|
|
26
27
|
export interface KeyIn { key: string; shift?: boolean; alt?: boolean; meta?: boolean; ctrl?: boolean }
|
|
27
28
|
/** `[Ctrl+][Meta+][Alt+][Shift+]key`, a letter lowercase - the frames' descriptor (keys.js). */
|
|
@@ -70,6 +71,9 @@ export function saveEdit(c: JamCard, text: string) {
|
|
|
70
71
|
* keeps a note once, whatever answer was lost; a different note never takes a failed one's place. */
|
|
71
72
|
type PendingNote = { id: string; text: string; failed: boolean; order: number }
|
|
72
73
|
const unsavedNotes = new Map<string, PendingNote[]>()
|
|
74
|
+
// spec 28 A1.11: a page whose canvas came back reloads only once every edit and note of a read-back has saved -
|
|
75
|
+
// one that failed while the canvas was away waits for the read-back's own retry (a decision saves it first)
|
|
76
|
+
holdsReload(() => unsaved.size > 0 || unsavedNotes.size > 0)
|
|
73
77
|
const sendNote = (c: JamCard, n: PendingNote): Promise<boolean> => {
|
|
74
78
|
n.failed = false
|
|
75
79
|
const before = saving.get(c.id) ?? Promise.resolve(true)
|
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
import { LANE_H } from './jam-lane.tsx'
|
|
19
19
|
import { Tip } from './Tip.tsx'
|
|
20
20
|
import { useJamQueue } from './jam-queue.ts'
|
|
21
|
+
import { holdsReload } from './api.ts'
|
|
21
22
|
|
|
22
23
|
/** A heading cut short by its ellipsis: its tooltip shows it whole (one that fits shows none). */
|
|
23
24
|
const cutShort = (el: HTMLElement) => el.scrollWidth > el.clientWidth + 1
|
|
@@ -57,6 +58,8 @@ const moreDrafts = new Map<string, string>()
|
|
|
57
58
|
export const clearMoreDraft = (id: string) => { moreDrafts.delete(id) }
|
|
58
59
|
export const moreDraftOf = (id: string): string => moreDrafts.get(id) ?? ''
|
|
59
60
|
export const setMoreDraft = (id: string, t: string) => { if (t) moreDrafts.set(id, t); else moreDrafts.delete(id) }
|
|
61
|
+
// spec 28 A1.11: a page whose canvas came back reloads only once no such words wait (a reload would drop them)
|
|
62
|
+
holdsReload(() => moreDrafts.size > 0)
|
|
60
63
|
|
|
61
64
|
const unquote = (s: string) => s.replace(/^"(.*)"$/s, '$1')
|
|
62
65
|
const DEVICE: Record<string, string> = { phone: 'mobile', mobile: 'mobile', tablet: 'tablet', laptop: 'laptop', desktop: 'monitor', monitor: 'monitor', tv: 'tv' }
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* failed). A card that fails raises one notice; nothing else here interrupts.
|
|
6
6
|
*/
|
|
7
7
|
import { create } from 'zustand'
|
|
8
|
-
import { ROUTE } from '../const.ts'
|
|
9
8
|
import { PUBLISHED } from './store.ts'
|
|
9
|
+
import { api } from './api.ts'
|
|
10
10
|
|
|
11
11
|
export type JamAction = 'drop' | 'retry' | 'keep' | 'first' | 'confirm' | 'edit' | 'good' | 'more' | 'later' | 'rename' | 'note'
|
|
12
12
|
export type JamCardState = 'draft' | 'confirming' | 'queued' | 'working' | 'asks' | 'review' | 'done' | 'kept' | 'failed' | 'dropped'
|
|
@@ -72,7 +72,7 @@ export const useJamQueue = create<QueueState>((set, get) => {
|
|
|
72
72
|
async load() {
|
|
73
73
|
if (PUBLISHED) return
|
|
74
74
|
try {
|
|
75
|
-
const res = await
|
|
75
|
+
const res = await api('jam/queue', { headers: { 'x-mv-c': csrf() } })
|
|
76
76
|
if (res.ok) get().apply(await res.json())
|
|
77
77
|
} catch { /* no queue: no icons */ }
|
|
78
78
|
},
|
|
@@ -113,7 +113,7 @@ export const useJamQueue = create<QueueState>((set, get) => {
|
|
|
113
113
|
if (get().session?.id === session) set({ session: null })
|
|
114
114
|
},
|
|
115
115
|
async act(card, action, body) {
|
|
116
|
-
const res = await
|
|
116
|
+
const res = await api('jam/card', {
|
|
117
117
|
method: 'POST', headers: { 'content-type': 'application/json', 'x-mv-c': csrf() },
|
|
118
118
|
body: JSON.stringify({ id: card.id, rev: card.rev, action, ...(body !== undefined ? { body } : {}) }),
|
|
119
119
|
}).catch(() => null)
|
|
@@ -10,7 +10,6 @@
|
|
|
10
10
|
* crossed microphone without one); a teal dot only while a capture records. Blue only on hover and press.
|
|
11
11
|
*/
|
|
12
12
|
import { useEffect, useRef, useState, type CSSProperties } from 'react'
|
|
13
|
-
import { ROUTE } from '../const.ts'
|
|
14
13
|
import { setSessionEnding, useJamCapture } from './jam-capture.ts'
|
|
15
14
|
import { laneCards, startCapture } from './jam-keys.ts'
|
|
16
15
|
import { useJamQueue, type JamCard } from './jam-queue.ts'
|
|
@@ -22,7 +21,8 @@ import { HARNESS } from './Comments.tsx'
|
|
|
22
21
|
import { ArrowRightIcon, CaretIcon, KeyboardIcon, MicrophoneIcon, MicrophoneSlashIcon, WarningIcon, WaveformIcon } from './icons.tsx'
|
|
23
22
|
import { Tip } from './Tip.tsx'
|
|
24
23
|
import { useSessionClock } from './jam-lane.tsx'
|
|
25
|
-
import { CONFIG, useStore } from './store.ts'
|
|
24
|
+
import { CONFIG, stoppedFor, useStore } from './store.ts'
|
|
25
|
+
import { api, STOPPED_TIP, useStopped } from './api.ts'
|
|
26
26
|
|
|
27
27
|
const csrf = () => /(?:^|;\s*)mv_c=([\w-]+)/.exec(document.cookie)?.[1] ?? ''
|
|
28
28
|
const now = () => performance.timeOrigin + performance.now()
|
|
@@ -32,7 +32,7 @@ const now = () => performance.timeOrigin + performance.now()
|
|
|
32
32
|
/** Why the last session move was refused (the server's words), for the one line that says so. */
|
|
33
33
|
let lastError: string | undefined
|
|
34
34
|
async function post(body: Record<string, unknown>, onAnswer?: (ok: boolean) => void): Promise<boolean> {
|
|
35
|
-
const r = await
|
|
35
|
+
const r = await api('jam/session', { method: 'POST', headers: { 'content-type': 'application/json', 'x-mv-c': csrf() }, body: JSON.stringify(body) }).catch(() => null)
|
|
36
36
|
lastError = r && !r.ok ? ((await r.json().catch(() => null)) as { error?: string } | null)?.error : r ? undefined : 'marver dev did not answer'
|
|
37
37
|
// what the server's answer settles happens at once, never behind the refresh (which may be slow, and a push
|
|
38
38
|
// may come first)
|
|
@@ -43,6 +43,7 @@ async function post(body: Record<string, unknown>, onAnswer?: (ok: boolean) => v
|
|
|
43
43
|
|
|
44
44
|
/** Start a session: the dev server holds it (it survives a reload); the microphone hears its talk. */
|
|
45
45
|
export async function startSession(): Promise<boolean> {
|
|
46
|
+
if (stoppedFor('Jam needs the canvas running')) return false // spec 28 A1.11
|
|
46
47
|
const id = `ses-${Date.now()}-${Math.random().toString(36).slice(2, 8).padEnd(6, '0')}`
|
|
47
48
|
// this tab holds the session's microphone (a reload of it takes it back; other tabs never take it) - from
|
|
48
49
|
// the moment the server has it: the push of it may come before the refresh
|
|
@@ -112,6 +113,8 @@ let endingOp = 0
|
|
|
112
113
|
* capture recording ends first, and the wrap-up waits for its read-back to close. */
|
|
113
114
|
export function pressJ() {
|
|
114
115
|
const ui = useJamUi.getState()
|
|
116
|
+
// the canvas stopped (spec 28 A1.11): a sheet open still closes; nothing new starts or wraps up
|
|
117
|
+
if (!ui.sheet && stoppedFor('Jam needs the canvas running')) return
|
|
115
118
|
if (!useJamQueue.getState().session) { ui.setSheet(ui.sheet === 'start' ? null : 'start'); return }
|
|
116
119
|
if (ui.sheet === 'wrap' || ui.sheet === 'wrap-pending') { ui.setSheet(null); return }
|
|
117
120
|
if (useJamCapture.getState().current) { useJamCapture.getState().end(); ui.setSheet('wrap-pending'); return }
|
|
@@ -132,11 +135,14 @@ export function JamButton({ inPlay }: { inPlay?: boolean }) {
|
|
|
132
135
|
// off: no, blocked, no engine - or stopped (another tab has it, the connection went) while you said yes
|
|
133
136
|
const micOff = voice.choice === 'no' || voice.denied || voice.server === 'unavailable' || (!!session && voice.choice === 'yes' && !voice.live && !recording)
|
|
134
137
|
const state = recording ? 'rec' : session ? 'live' : 'idle'
|
|
135
|
-
|
|
138
|
+
// the canvas stopped (spec 28 A1.11): quiet, saying why - a capture already recording goes on
|
|
139
|
+
const stopped = useStopped()
|
|
140
|
+
const label = stopped ? <div className="sh-tip-lines"><b>Jam needs the canvas running</b><small>{STOPPED_TIP}</small></div>
|
|
141
|
+
: session ? <><b>End the session</b><span>J</span></> : <><b>Jam session</b><span>J</span></>
|
|
136
142
|
return (
|
|
137
143
|
<Tip side="bottom" inv={inPlay} label={label}>
|
|
138
|
-
<button className={`sh-pill-btn jm-jam${state !== 'idle' ? ` ${state}` : ''}${sheet === 'start' || sheet === 'wrap' ? ' press' : ''}`}
|
|
139
|
-
data-jam-button={state} aria-label={session ? 'End the Jam session' : 'Jam session'} onClick={pressJ}>
|
|
144
|
+
<button className={`sh-pill-btn jm-jam${state !== 'idle' ? ` ${state}` : ''}${sheet === 'start' || sheet === 'wrap' ? ' press' : ''}${stopped ? ' off' : ''}`}
|
|
145
|
+
data-jam-button={state} data-stopped={stopped ? '' : undefined} aria-disabled={stopped || undefined} aria-label={session ? 'End the Jam session' : 'Jam session'} onClick={pressJ}>
|
|
140
146
|
{/* the whole session reads as on: the dot pulses from start to end, between captures too */}
|
|
141
147
|
{session || recording ? <i className="jm-live-dot" /> : <WaveformIcon size={16} />}
|
|
142
148
|
{session && <span className="jm-clock">{minutes}</span>}
|
|
@@ -226,7 +232,7 @@ export function WrapSheet({ style }: { style?: CSSProperties }) {
|
|
|
226
232
|
const [busy, setBusy] = useState(false)
|
|
227
233
|
const field = useRef<HTMLTextAreaElement>(null)
|
|
228
234
|
useEffect(() => {
|
|
229
|
-
|
|
235
|
+
api('jam/session', { headers: { 'x-mv-c': csrf() } }).then((r) => (r.ok ? r.json() : null)).then((b) => { setTalkMin(b?.talkMinutes ?? 0); setTags(b?.tags ?? 0); setFolder(typeof b?.folder === 'string' ? b.folder : null) }, () => {})
|
|
230
236
|
requestAnimationFrame(() => field.current?.focus())
|
|
231
237
|
}, [])
|
|
232
238
|
// the field grows with its words: three lines at least
|
|
@@ -309,7 +315,7 @@ export function RecordDetail({ card, agent, more, onMore, onMoreOpen, onGood, on
|
|
|
309
315
|
const [rec, setRec] = useState<{ file: string; text: string | null; reply?: string } | null>(null)
|
|
310
316
|
useEffect(() => {
|
|
311
317
|
let live = true
|
|
312
|
-
|
|
318
|
+
api(`jam/record?id=${encodeURIComponent(card.id)}`, { headers: { 'x-mv-c': csrf() } })
|
|
313
319
|
.then((r) => (r.ok ? r.json() : null)).then((b) => { if (live && b) setRec(b) }, () => {})
|
|
314
320
|
return () => { live = false }
|
|
315
321
|
}, [card.id, card.state, card.rev])
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
import { create } from 'zustand'
|
|
19
19
|
import { ROUTE } from '../const.ts'
|
|
20
20
|
import { CONFIG, useStore } from './store.ts'
|
|
21
|
+
import { api } from './api.ts'
|
|
21
22
|
|
|
22
23
|
export const RATE = 16_000
|
|
23
24
|
const FINAL_MS = 3_000
|
|
@@ -68,20 +69,20 @@ export const useJamVoice = create<VoiceStore>((set, get) => ({
|
|
|
68
69
|
},
|
|
69
70
|
async refresh() {
|
|
70
71
|
try {
|
|
71
|
-
const r = await
|
|
72
|
+
const r = await api('jam/voice', { headers: { 'x-mv-c': csrf() } })
|
|
72
73
|
if (!r.ok) { set({ server: 'unavailable', reason: 'jam is not running here' }); return }
|
|
73
74
|
const b = await r.json()
|
|
74
75
|
set({ server: b.state, reason: b.reason, download: b.download ?? null, mb: b.mb ?? 490 })
|
|
75
76
|
} catch { set({ server: 'unavailable', reason: 'marver dev did not answer' }) }
|
|
76
77
|
},
|
|
77
78
|
async startDownload() {
|
|
78
|
-
try { await
|
|
79
|
+
try { await api('jam/voice', { method: 'POST', headers: { 'x-mv-c': csrf(), 'content-type': 'application/json' }, body: JSON.stringify({ download: true }) }) } catch { /* the poll says */ }
|
|
79
80
|
poll()
|
|
80
81
|
},
|
|
81
82
|
async retry() {
|
|
82
83
|
toldUnavailable = false
|
|
83
84
|
try {
|
|
84
|
-
const r = await
|
|
85
|
+
const r = await api('jam/voice', { method: 'POST', headers: { 'x-mv-c': csrf(), 'content-type': 'application/json' }, body: JSON.stringify({ retry: true }) })
|
|
85
86
|
if (r.ok) { const b = await r.json(); set({ server: b.state, reason: b.reason, download: b.download ?? null, mb: b.mb ?? 490 }); return }
|
|
86
87
|
} catch { /* below */ }
|
|
87
88
|
await get().refresh()
|
|
@@ -168,7 +169,8 @@ function socket(reclaim = false): Promise<WebSocket | null> {
|
|
|
168
169
|
if (wsOpen) return wsOpen
|
|
169
170
|
wsOpen = (async () => {
|
|
170
171
|
try {
|
|
171
|
-
|
|
172
|
+
// the ticket names this canvas's workspace like every request (A1.11); the socket it opens is bound by it
|
|
173
|
+
const r = await api('jam/audio-ticket', { method: 'POST', headers: { 'x-mv-c': csrf() } })
|
|
172
174
|
if (!r.ok) return null
|
|
173
175
|
const { ticket } = await r.json()
|
|
174
176
|
const s = new WebSocket(`${location.protocol === 'https:' ? 'wss' : 'ws'}://${location.host}${ROUTE}/api/jam/audio?ticket=${encodeURIComponent(ticket)}${reclaim ? '&reclaim=1' : ''}`)
|
|
@@ -242,7 +244,7 @@ function takeBackLater() {
|
|
|
242
244
|
waitingBack = setInterval(async () => {
|
|
243
245
|
if (!session || (mic && !mic.closed)) { clearInterval(waitingBack!); waitingBack = null; return }
|
|
244
246
|
try {
|
|
245
|
-
const r = await
|
|
247
|
+
const r = await api('jam/voice', { headers: { 'x-mv-c': csrf() } })
|
|
246
248
|
const b = r.ok ? await r.json() : null
|
|
247
249
|
if (b && b.busy === false) { clearInterval(waitingBack!); waitingBack = null; reclaiming = true; void reconcile() }
|
|
248
250
|
} catch { /* ask again */ }
|
|
@@ -17,7 +17,7 @@ import { stableNodeKey } from './keys.ts'
|
|
|
17
17
|
import { UNPLACED, type HashState } from './hash.ts'
|
|
18
18
|
import { ALL_SCENES_KEYS, boardLabel, fetchMembership, PUBLISHED } from './store.ts'
|
|
19
19
|
import { useComments } from './comments-store.ts'
|
|
20
|
-
import {
|
|
20
|
+
import { api } from './api.ts'
|
|
21
21
|
|
|
22
22
|
export const isLegacyLink = (h: HashState): boolean => h.board === ALL_SCENES
|
|
23
23
|
|
|
@@ -44,7 +44,7 @@ export async function landLegacy(h: HashState): Promise<{ hash: HashState; notic
|
|
|
44
44
|
const byKey = new Map([...live.map((id) => [stableNodeKey(ALL_SCENES, id, 0), id] as const), ...Object.entries(ALL_SCENES_KEYS)])
|
|
45
45
|
if (!PUBLISHED) {
|
|
46
46
|
try {
|
|
47
|
-
const leftover = (await (await
|
|
47
|
+
const leftover = (await (await api(`boards/${ALL_SCENES}`)).json())?.board as { nodes?: { key?: unknown; frame?: unknown }[] } | null
|
|
48
48
|
for (const node of Array.isArray(leftover?.nodes) ? leftover.nodes : []) if (typeof node?.key === 'string' && typeof node.frame === 'string') byKey.set(node.key, node.frame)
|
|
49
49
|
} catch { /* no leftover, or not JSON: the minted keys stand */ }
|
|
50
50
|
}
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { createRoot } from 'react-dom/client'
|
|
2
2
|
import { App, ShellBoundary } from './App.tsx'
|
|
3
3
|
import { useStore } from './store.ts'
|
|
4
|
+
import { startRecorder } from './recorder.ts'
|
|
5
|
+
import { capturesPending, sealOnLeave } from './jam-capture.ts'
|
|
4
6
|
import './styles.css'
|
|
5
7
|
|
|
6
8
|
// dev aid: inspectable store (harmless in builds; the canvas is a dev surface)
|
|
7
9
|
;(window as any).__sh = useStore
|
|
10
|
+
// what each board load does, from the page (spec 28 A1.7): before the first load; nothing on a published canvas
|
|
11
|
+
startRecorder({ capturesPending, sealCaptures: sealOnLeave })
|
|
8
12
|
|
|
9
13
|
createRoot(document.getElementById('root')!).render(<ShellBoundary><App /></ShellBoundary>)
|
|
@@ -106,7 +106,9 @@ export function notesCramped(
|
|
|
106
106
|
|
|
107
107
|
// ---- per-viewer visibility -------------------------------------------------------------
|
|
108
108
|
|
|
109
|
-
|
|
109
|
+
/** The viewer's choice is kept per canvas (spec 28 A1.6): the shell names the key at boot (store.ts),
|
|
110
|
+
* so this module stays importable without the plugin's virtual modules (test/notes.test.ts). */
|
|
111
|
+
let STORAGE = 'mv-notes'
|
|
110
112
|
interface NotesState {
|
|
111
113
|
/** the N toggle: false hides every note on the canvas */
|
|
112
114
|
all: boolean
|
|
@@ -143,6 +145,11 @@ export const useNotes = create<NotesState>((set, get) => ({
|
|
|
143
145
|
set(next); save(next)
|
|
144
146
|
},
|
|
145
147
|
}))
|
|
148
|
+
/** Keep the notes' visibility under this canvas's key (`mv-notes:<workspace>`), read from it now. */
|
|
149
|
+
export function scopeNotes(key: string) {
|
|
150
|
+
STORAGE = key
|
|
151
|
+
useNotes.setState(load())
|
|
152
|
+
}
|
|
146
153
|
/** Every note id currently on the canvas - read from the DOM, the one place that knows. */
|
|
147
154
|
const allIds = (): string[] => (typeof document === 'undefined' ? [] : [...document.querySelectorAll('[data-note]')].map((el) => el.getAttribute('data-note')!))
|
|
148
155
|
|
package/src/client/shell/perf.ts
CHANGED
|
@@ -1,34 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* B0.4
|
|
2
|
+
* Gesture timing (B0.4; spec 28 A1.7). Frame intervals are sampled ONLY while a gesture runs - a canvas pan or zoom
|
|
3
|
+
* (`sh-camera` on #sh-world) or a layout animation (`sh-preset`) - and no frame is scheduled at rest: the camera
|
|
4
|
+
* observer (canvas/camera-broadcast.ts) says when one starts and stops, and the rAF loop runs between the two. Each
|
|
5
|
+
* gesture ends in one `gesture` record for the recorder (recorder.ts, dev only): the intervals as they are - p50,
|
|
6
|
+
* p95, max, and the counts over 17 ms and over 33 ms - and the long animation frames that started inside it
|
|
7
|
+
* (`longtask` entries where the browser has no long-animation-frame). No median-relative "missed" count: it would call
|
|
8
|
+
* a steady half-rate gesture smooth.
|
|
3
9
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* Two honest signals, sampled ONLY while a gesture is active (the `#sh-world.sh-gesturing`
|
|
9
|
-
* class every gesture path already sets):
|
|
10
|
-
* - frame INTERVALS (rAF deltas). A healthy 60Hz frame is ~16.7ms, so the interval is NOT
|
|
11
|
-
* "main-thread work" - we report its p50/p95/max and, as the jank signal, `dropped` =
|
|
12
|
-
* intervals over 32ms (a missed refresh).
|
|
13
|
-
* - long-task durations (PerformanceObserver 'longtask', >50ms by spec) landing during a
|
|
14
|
-
* gesture: actual main-thread work that blew the budget. 0 long-tasks = smooth.
|
|
15
|
-
*
|
|
16
|
-
* Read it live: __mvPerf.report() / __mvPerf.reset()
|
|
17
|
-
* perfMark(name) + counters are the plug points Stages 2-3 use (blank-frame / warm-latency).
|
|
10
|
+
* Sampled in dev, or in ANY build (a published one too) with `?mvperf` in the URL or `localStorage.mvPerf==='1'` - read
|
|
11
|
+
* it live: __mvPerf.report() / __mvPerf.reset()
|
|
12
|
+
* perfMark(name) + counters are the plug points later stages use (blank-frame / warm-latency).
|
|
18
13
|
*/
|
|
14
|
+
import { onMotion, type Motion } from './canvas/camera-broadcast.ts'
|
|
15
|
+
import { recorder } from './recorder.ts'
|
|
16
|
+
import { gestureStats } from './recorder-core.ts'
|
|
19
17
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
const w = document.getElementById('sh-world')
|
|
24
|
-
return !!w && (w.classList.contains('sh-camera') || w.classList.contains('sh-preset'))
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const frames: number[] = [] // inter-frame intervals (ms) during gestures
|
|
28
|
-
const tasks: number[] = [] // long-task durations (ms) during gestures
|
|
18
|
+
const LOAF = typeof PerformanceObserver !== 'undefined' && (PerformanceObserver.supportedEntryTypes ?? []).includes('long-animation-frame')
|
|
19
|
+
const frames: number[] = [] // inter-frame intervals (ms) across gestures, for report()
|
|
20
|
+
const longs: number[] = [] // the long frames (or long tasks) that started inside a gesture, their durations (ms), for report()
|
|
29
21
|
const MAX = 1200
|
|
30
|
-
let last = 0
|
|
31
|
-
let raf = 0
|
|
32
22
|
|
|
33
23
|
const counters: Record<string, number> = { blankFrames: 0 }
|
|
34
24
|
const marks: { name: string; t: number }[] = []
|
|
@@ -41,52 +31,73 @@ const enabled = (): boolean => {
|
|
|
41
31
|
} catch { return false }
|
|
42
32
|
}
|
|
43
33
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
34
|
+
interface Run { t0: number; last: number; dts: number[]; pan: boolean; zoom: boolean; layout: boolean; longs: number[]; obs?: PerformanceObserver; raf: number }
|
|
35
|
+
/** the gesture running now */
|
|
36
|
+
let g: Run | null = null
|
|
37
|
+
|
|
38
|
+
function note(m: Motion) {
|
|
39
|
+
if (!g) return
|
|
40
|
+
if (m.camera) { if (document.body.classList.contains('sh-panning')) g.pan = true; else g.zoom = true }
|
|
41
|
+
if (m.preset) g.layout = true
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function begin(m: Motion) {
|
|
45
|
+
const run: Run = { t0: performance.now(), last: 0, dts: [], pan: false, zoom: false, layout: false, longs: [], raf: 0 }
|
|
46
|
+
g = run
|
|
47
|
+
note(m)
|
|
48
|
+
try {
|
|
49
|
+
run.obs = new PerformanceObserver((l) => { for (const e of l.getEntries()) if (e.startTime >= run.t0) run.longs.push(e.duration) })
|
|
50
|
+
run.obs.observe({ type: LOAF ? 'long-animation-frame' : 'longtask', buffered: false })
|
|
51
|
+
} catch { /* neither entry type (Safari): the intervals still sample */ }
|
|
52
|
+
// this gesture's own loop: a frame of an earlier one that is still queued finds another run and stops
|
|
53
|
+
const tick = (t: number) => {
|
|
54
|
+
if (g !== run) return
|
|
55
|
+
if (run.last) run.dts.push(t - run.last)
|
|
56
|
+
run.last = t
|
|
57
|
+
run.raf = requestAnimationFrame(tick)
|
|
58
|
+
}
|
|
59
|
+
run.raf = requestAnimationFrame(tick)
|
|
48
60
|
}
|
|
49
61
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
62
|
+
function end() {
|
|
63
|
+
const run = g!
|
|
64
|
+
g = null
|
|
65
|
+
cancelAnimationFrame(run.raf)
|
|
66
|
+
const t1 = performance.now()
|
|
67
|
+
for (const e of run.obs?.takeRecords() ?? []) if (e.startTime >= run.t0 && e.startTime <= t1) run.longs.push(e.duration)
|
|
68
|
+
run.obs?.disconnect()
|
|
69
|
+
for (const d of run.dts) { frames.push(d); if (frames.length > MAX) frames.shift() }
|
|
70
|
+
for (const d of run.longs) { longs.push(d); if (longs.length > MAX) longs.shift() }
|
|
71
|
+
if (run.dts.length < 2) return // a press that never moved the camera
|
|
72
|
+
recorder.gesture({ type: run.pan ? 'pan' : run.zoom ? 'zoom' : 'layout', ms: Math.round(t1 - run.t0), ...gestureStats(run.dts, run.longs.length) })
|
|
54
73
|
}
|
|
55
|
-
const top = (sorted: number[]): number => (sorted.length ? Math.round(sorted[sorted.length - 1] * 100) / 100 : 0)
|
|
56
|
-
const frac = (n: number, d: number): number => (d ? Math.round((n / d) * 1000) / 1000 : 0)
|
|
57
74
|
|
|
58
75
|
/** One-shot event later stages record (e.g. a blank frame, or warm-promotion latency). */
|
|
59
76
|
export const perfMark = (name: string): void => {
|
|
60
77
|
counters[name] = (counters[name] ?? 0) + 1
|
|
61
|
-
marks.push({ name, t:
|
|
78
|
+
marks.push({ name, t: performance.now() })
|
|
62
79
|
if (marks.length > 400) marks.shift()
|
|
63
80
|
}
|
|
64
81
|
|
|
65
|
-
|
|
82
|
+
let started = false
|
|
83
|
+
/** Watch for gestures. Idempotent; a no-op unless enabled() (dev, ?mvperf, or localStorage). */
|
|
66
84
|
export function startPerf(): void {
|
|
67
|
-
if (
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
85
|
+
if (started || !enabled()) return
|
|
86
|
+
started = true
|
|
87
|
+
onMotion((m) => {
|
|
88
|
+
const moving = m.camera || m.preset
|
|
89
|
+
if (moving && !g) begin(m)
|
|
90
|
+
else if (!moving && g) end()
|
|
91
|
+
else note(m)
|
|
92
|
+
})
|
|
75
93
|
;(window as unknown as { __mvPerf: unknown }).__mvPerf = {
|
|
94
|
+
// the intervals as they are, and the main thread's own work: long frames (> 50 ms) that started in a gesture,
|
|
95
|
+
// how many, their p95 and the longest (the same nearest-rank rule)
|
|
76
96
|
report() {
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
const dropped = fi.filter((d) => d > 32).length
|
|
80
|
-
return {
|
|
81
|
-
gestureFrames: fi.length,
|
|
82
|
-
frameP50: pct(fi, 50), frameP95: pct(fi, 95), frameMax: top(fi),
|
|
83
|
-
dropped, droppedFrac: frac(dropped, fi.length),
|
|
84
|
-
// actual main-thread work during gestures (long tasks >50ms). 0 = smooth.
|
|
85
|
-
longTasks: tw.length, longTaskP95: pct(tw, 95), longTaskMax: top(tw),
|
|
86
|
-
counters: { ...counters },
|
|
87
|
-
}
|
|
97
|
+
const s = gestureStats(frames, longs.length), l = gestureStats(longs, 0)
|
|
98
|
+
return { gestureFrames: s.frames, frameP50: s.p50, frameP95: s.p95, frameMax: s.max, over17ms: s.over17ms, over33ms: s.over33ms, longFrames: s.longFrames, longFrameP95: l.p95, longFrameMax: l.max, counters: { ...counters } }
|
|
88
99
|
},
|
|
89
|
-
reset() { frames.length = 0;
|
|
100
|
+
reset() { frames.length = 0; longs.length = 0; marks.length = 0; for (const k in counters) counters[k] = 0 },
|
|
90
101
|
marks: () => [...marks],
|
|
91
102
|
}
|
|
92
103
|
}
|