@marver-design/marver 0.29.0 → 0.30.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 +44 -0
- package/README.md +2 -1
- package/dist/{anchor-check-DhlpKl2K.mjs → anchor-check-c52IDkiQ.mjs} +1 -1
- package/dist/{build-CWbrb2bl.mjs → build-C3mUtjEn.mjs} +5 -4
- package/dist/cli.mjs +5 -5
- package/dist/{daemon-Sc_z8gT6.mjs → daemon-B0Wi1OQ3.mjs} +5 -3
- package/dist/{dev-DWBKQhxf.mjs → dev-5dlxoW28.mjs} +8 -8
- package/dist/{perf-Denssrko.mjs → perf-6MOTHxay.mjs} +710 -99
- package/dist/perf-BCxAo0IS.mjs +1743 -0
- package/dist/{plugin-DqoZB-D6.mjs → plugin-CXRoMA8g.mjs} +898 -539
- package/dist/{poster-CrsjqhY4.mjs → poster-CYmCa00B.mjs} +1 -1
- package/dist/{publish-bakes-DW-NDgU2.mjs → publish-bakes-C_2ZtHou.mjs} +2 -2
- package/dist/{recover-GtJ9UDAB.mjs → recover-XD8iXJOj.mjs} +1 -1
- package/dist/{shot-T04Ixrvq.mjs → shot-CRRGgxru.mjs} +3 -3
- package/docs/app.md +194 -0
- package/docs/performance.md +98 -18
- package/package.json +1 -1
- package/src/client/frame-host/bridge.js +17 -8
- package/src/client/frame-host/inplace.ts +124 -0
- package/src/client/frame-host/inspect.d.ts +1 -0
- package/src/client/frame-host/inspect.js +13 -4
- package/src/client/frame-host/main.tsx +12 -3
- package/src/client/frame-host/messages.ts +85 -0
- package/src/client/frame-host/signals.d.ts +15 -0
- package/src/client/frame-host/signals.js +219 -0
- package/src/client/recorder-level.ts +41 -0
- package/src/client/shell/App.tsx +158 -88
- package/src/client/shell/BoardList.tsx +103 -48
- package/src/client/shell/Comments.tsx +66 -42
- package/src/client/shell/ContextMenu.tsx +3 -2
- package/src/client/shell/JamSurface.tsx +116 -71
- package/src/client/shell/LockedApp.tsx +19 -3
- package/src/client/shell/Play.tsx +94 -58
- package/src/client/shell/StatusPicker.tsx +19 -9
- package/src/client/shell/Toolbar.tsx +15 -7
- package/src/client/shell/api.ts +18 -4
- package/src/client/shell/app-bridge.ts +12 -6
- package/src/client/shell/app-perf.ts +31 -1
- package/src/client/shell/canvas/Canvas.tsx +17 -6
- package/src/client/shell/canvas/FrameNode.tsx +25 -12
- package/src/client/shell/canvas/Sticky.tsx +4 -2
- package/src/client/shell/canvas/ctl.ts +2 -0
- package/src/client/shell/canvas/ready-watch.ts +4 -0
- package/src/client/shell/canvas/sleep.ts +2 -0
- package/src/client/shell/canvas/updates.ts +13 -6
- package/src/client/shell/commands.ts +765 -0
- package/src/client/shell/comments-store.ts +42 -27
- package/src/client/shell/goto.ts +11 -6
- package/src/client/shell/jam-keys.ts +141 -75
- package/src/client/shell/jam-lane.tsx +19 -12
- package/src/client/shell/jam-panel.tsx +61 -48
- package/src/client/shell/jam-session.tsx +41 -37
- package/src/client/shell/jam-state.ts +9 -1
- package/src/client/shell/jam-surface-parts.tsx +8 -6
- package/src/client/shell/jam-ui.tsx +9 -6
- package/src/client/shell/jam-voice.ts +4 -2
- package/src/client/shell/main.tsx +7 -1
- package/src/client/shell/marks-ui.tsx +11 -0
- package/src/client/shell/perf.ts +51 -5
- package/src/client/shell/recorder-core.ts +4 -1
- package/src/client/shell/recorder-hmr.ts +36 -0
- package/src/client/shell/recorder-reloads.ts +264 -0
- package/src/client/shell/recorder-seams.ts +116 -0
- package/src/client/shell/recorder-self.ts +73 -0
- package/src/client/shell/recorder-signals-core.ts +139 -0
- package/src/client/shell/recorder-signals.ts +485 -0
- package/src/client/shell/recorder.ts +115 -41
- package/src/client/shell/store.ts +56 -22
- package/src/client/shell/whiteout-probes.ts +3 -1
- package/src/client/stage/main.tsx +10 -5
- package/src/shared/app-api.ts +28 -6
- package/src/shared/app-perf.ts +99 -6
- package/src/shared/app-report.ts +586 -0
- package/src/shared/perf-records.ts +445 -0
- package/src/shared/perf-run.ts +6 -2
- package/dist/perf-jam-CLkERSHo.mjs +0 -642
|
@@ -12,19 +12,28 @@
|
|
|
12
12
|
*/
|
|
13
13
|
import { api, isStopped } from './api.ts'
|
|
14
14
|
import { CONFIG, PUBLISHED, geometryCause, knownHeight, recorderHooks, reflowIdle, settleRule, useStore, type LoadCause, type Manifest, type MeasureResult, type Node, type RequestCut } from './store.ts'
|
|
15
|
+
import type { BoardWriter, LoadTrigger } from '../../shared/perf-records.ts'
|
|
15
16
|
import { admissionIdle, onAdmissionIdle } from './canvas/admission.ts'
|
|
16
17
|
import { canvasCtl } from './canvas/ctl.ts'
|
|
17
18
|
import { bootOf, iframeOf } from './canvas/frame-registry.ts'
|
|
18
|
-
import { adopt, bound, fitWithin, KEEPALIVE_BYTES, LOAD_MAX_MS, newId, Outbox, outcomeOf, QUIET_MS, SEND_MS, stackLines, type Kind, type Outcome, type PerfRecord, type Track } from './recorder-core.ts'
|
|
19
|
+
import { adopt, bound, bytesOf, fitWithin, KEEPALIVE_BYTES, LOAD_MAX_MS, newId, Outbox, outcomeOf, QUIET_MS, SEND_MS, stackLines, type Kind, type Outcome, type PerfRecord, type Track } from './recorder-core.ts'
|
|
19
20
|
import { PERF_RUN, type PerfRunStatus } from './perf-run.ts'
|
|
20
21
|
import { displayHz } from './app-perf.ts'
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
import { nextSeq, PAGE_ID, perfSeams, type LoadPhase } from './recorder-seams.ts'
|
|
23
|
+
import type { DropReason, GestureFields } from '../../shared/perf-records.ts'
|
|
24
|
+
import { fullRecorder } from '../recorder-level.ts'
|
|
25
|
+
import { startReloads } from './recorder-reloads.ts'
|
|
26
|
+
import { errorCounted, modesOn, signalSink, startSignals, type SignalError } from './recorder-signals.ts'
|
|
27
|
+
import { currentCmd, startCommands } from './commands.ts'
|
|
28
|
+
import { selfCounts, startSelf } from './recorder-self.ts'
|
|
29
|
+
|
|
30
|
+
/** This document, in every record (and, in the app, in its hello: the app's records about this tab carry it). Minted in
|
|
31
|
+
* recorder-seams.ts, which the spec 30 streams read without importing this module. */
|
|
32
|
+
export { PAGE_ID }
|
|
24
33
|
|
|
25
34
|
type State = ReturnType<typeof useStore.getState>
|
|
26
35
|
type View = { x: number; y: number; w: number; h: number }
|
|
27
|
-
type Gesture = { type: 'pan' | 'zoom' | 'layout'; ms: number; frames: number; p50: number; p95: number; max: number; over17ms: number; over33ms: number; longFrames: number }
|
|
36
|
+
type Gesture = { type: 'pan' | 'zoom' | 'layout'; ms: number; frames: number; p50: number; p95: number; max: number; over17ms: number; over33ms: number; longFrames: number } & Pick<GestureFields, 'scale' | 'loaf' | 'by'>
|
|
28
37
|
|
|
29
38
|
interface Load {
|
|
30
39
|
id: string; board: string; cause: LoadCause; t0: number
|
|
@@ -36,6 +45,8 @@ interface Load {
|
|
|
36
45
|
quietSent: boolean
|
|
37
46
|
/** the visible cohort: the nodes the first camera placement after the commit showed */
|
|
38
47
|
cohort?: Set<string>
|
|
48
|
+
/** spec 30 #49: its cohort's frames all reached their outcome - `board-open`'s `visibleReady` step, said once */
|
|
49
|
+
visibleReady?: true
|
|
39
50
|
/** store changes that moved a node (before drags are merged), their distance, by cause */
|
|
40
51
|
moves: number; distance: number; causes: Record<string, number>
|
|
41
52
|
errors: number; errAt: Map<string, number>
|
|
@@ -49,7 +60,6 @@ interface Load {
|
|
|
49
60
|
|
|
50
61
|
let on = false
|
|
51
62
|
let ws = ''
|
|
52
|
-
let seq = 0
|
|
53
63
|
let capturesPending = (): boolean => false
|
|
54
64
|
let sealCaptures = (): void => {}
|
|
55
65
|
/** requested, not committed (or cut) yet */
|
|
@@ -85,15 +95,19 @@ let sleeping = (): number => 0
|
|
|
85
95
|
const unowned = { errors: 0, errAt: new Map<string, number>() }
|
|
86
96
|
|
|
87
97
|
const env = (kind: Kind, load: string, body: Record<string, unknown>): PerfRecord =>
|
|
88
|
-
({ ...Object.fromEntries(Object.entries(body).filter(([, x]) => x !== undefined)), v: 1, ws, page: PAGE_ID, load, seq:
|
|
98
|
+
({ ...Object.fromEntries(Object.entries(body).filter(([, x]) => x !== undefined)), v: 1, ws, page: PAGE_ID, load, seq: nextSeq(), ts: Date.now(), kind })
|
|
89
99
|
function rec(kind: Kind, load: string, body: Record<string, unknown>): PerfRecord {
|
|
100
|
+
const t0 = selfCounts.on ? performance.now() : 0 // spec 30 #58: the page's `self`
|
|
90
101
|
if (kind !== 'move') open.clear() // a merged drag ends at the next record of another kind
|
|
91
102
|
const r = env(kind, load, body)
|
|
92
103
|
outbox.push(r)
|
|
93
104
|
armSend()
|
|
105
|
+
if (selfCounts.on) selfCounts.record(performance.now() - t0)
|
|
94
106
|
return r
|
|
95
107
|
}
|
|
96
108
|
const ownerId = () => owner?.id ?? '-'
|
|
109
|
+
/** A load's phase, to whoever listens (spec 30: recorder-seams.ts `load`). */
|
|
110
|
+
const phase = (p: LoadPhase) => perfSeams.load.emit(p)
|
|
97
111
|
/** ms from the load's request; undefined for a moment before it (a document kept from an earlier load) */
|
|
98
112
|
const rel = (L: Load, at?: number) => (at === undefined || at < L.t0 ? undefined : Math.round(at - L.t0))
|
|
99
113
|
const node = (key: string) => useStore.getState().nodes.find((n) => n.key === key)
|
|
@@ -117,10 +131,11 @@ export function startRecorder(opts: { capturesPending: () => boolean; sealCaptur
|
|
|
117
131
|
if (on || PUBLISHED || !CONFIG.workspace || w.__mvRecorderOn) return // a hot-replaced module never records twice
|
|
118
132
|
w.__mvRecorderOn = true
|
|
119
133
|
on = true
|
|
134
|
+
perfSeams.on = true
|
|
120
135
|
ws = CONFIG.workspace
|
|
121
136
|
capturesPending = opts.capturesPending
|
|
122
137
|
sealCaptures = opts.sealCaptures
|
|
123
|
-
recorderHooks.request = (board, cause) => { try { return request(board, cause) } catch { return '' } }
|
|
138
|
+
recorderHooks.request = (board, cause, trigger, writer) => { try { return request(board, cause, trigger, writer) } catch { return '' } }
|
|
124
139
|
recorderHooks.handover = guard(handover)
|
|
125
140
|
recorderHooks.commit = guard(commit)
|
|
126
141
|
recorderHooks.cut = guard(cutRequest)
|
|
@@ -138,6 +153,10 @@ export function startRecorder(opts: { capturesPending: () => boolean; sealCaptur
|
|
|
138
153
|
}))
|
|
139
154
|
addEventListener('pagehide', guard(leave))
|
|
140
155
|
if (import.meta.env.DEV) (window as unknown as { __mvRecorder: unknown }).__mvRecorder = { page: PAGE_ID, ws, state, send }
|
|
156
|
+
// spec 30: the streams write through the page's envelope and outbox, and start only at the full level (#57, #58)
|
|
157
|
+
perfSeams.record = (kind, body, load) => { if (on) rec(kind, load ?? ownerId(), body) }
|
|
158
|
+
if (!fullRecorder()) return
|
|
159
|
+
for (const start of [startReloads, startSignals, startCommands, startSelf]) { try { start() } catch { /* one stream's start never stops another's, nor the page */ } }
|
|
141
160
|
}
|
|
142
161
|
|
|
143
162
|
/** What only the canvas knows, from Canvas.tsx when it mounts: when the camera or a layout animation starts and stops
|
|
@@ -150,13 +169,16 @@ export function attachCanvas(c: { onMotion: (fn: (m: { camera: boolean; preset:
|
|
|
150
169
|
|
|
151
170
|
// ---- loads ------------------------------------------------------------------------------------------------------
|
|
152
171
|
|
|
153
|
-
function request(board: string, cause: LoadCause): string {
|
|
172
|
+
function request(board: string, cause: LoadCause, trigger?: LoadTrigger, writer?: BoardWriter): string {
|
|
154
173
|
if (!on) return ''
|
|
155
174
|
const t0 = performance.now()
|
|
156
175
|
const L: Load = { id: newId(), board, cause, t0, lastMoveAt: t0, quietSent: false, moves: 0, distance: 0, causes: {}, errors: 0, errAt: new Map(), reported: new Map() }
|
|
157
176
|
pending.set(L.id, L)
|
|
158
177
|
// `load`, its uncommitted `cut` and its `commit` carry the request's own id (the load's, once it commits)
|
|
159
|
-
|
|
178
|
+
// spec 30 (#17, #18, `by`): why it read the board, who may have written it, the command behind it
|
|
179
|
+
const why = fullRecorder() ? { trigger, ...writer, by: currentCmd() } : {}
|
|
180
|
+
rec('load', L.id, { board, cause, request: L.id, ...(cause === 'boot' ? { sinceNav: Math.round(t0) } : {}), ...why })
|
|
181
|
+
phase({ phase: 'request', load: L.id, board, cause, ...(fullRecorder() ? { trigger } : {}) })
|
|
160
182
|
// the deadline runs from the request: a load not settled 120 s after it was asked for is cut, committed or not - a
|
|
161
183
|
// board fetch that never answers included
|
|
162
184
|
L.timeout = setTimeout(guard(() => expire(L)), LOAD_MAX_MS)
|
|
@@ -180,6 +202,7 @@ function cutRequest(id: string, reason: RequestCut | 'timeout' | 'hidden'): void
|
|
|
180
202
|
L.done = 'cut'
|
|
181
203
|
L.cutReason = reason
|
|
182
204
|
rec('cut', id, { reason, request: id, ms: Math.round(performance.now() - L.t0) })
|
|
205
|
+
phase({ phase: 'cut', load: id, reason, request: true })
|
|
183
206
|
// its fetch may still answer and mount it
|
|
184
207
|
if (reason === 'timeout' || reason === 'hidden') {
|
|
185
208
|
lapsed.set(id, L)
|
|
@@ -213,6 +236,7 @@ function commit(id: string, nodes: readonly Node[], manifest: Manifest): void {
|
|
|
213
236
|
// a request already cut (its deadline passed, the page hid) mounts all the same: said, its cut kept - its board's
|
|
214
237
|
// geometry is its own from here, every move late
|
|
215
238
|
rec('commit', id, { request: id, ms: Math.round(L.committedAt - L.t0), ...facts(nodes, manifest), ...(late ? { late: true } : {}) })
|
|
239
|
+
phase({ phase: 'commit', load: id, ...(late ? { late: true as const } : {}) })
|
|
216
240
|
if (late) return
|
|
217
241
|
L.quietTimer = setTimeout(guard(() => quiet(L)), QUIET_MS)
|
|
218
242
|
// a page hidden already: cut once the set that mounts this load has run - its nodes, not the board it replaces
|
|
@@ -297,10 +321,18 @@ function progress(n: Node): void {
|
|
|
297
321
|
if (L && !L.done && L.committedAt !== undefined) {
|
|
298
322
|
const o = outcomeNow(n, useStore.getState().manifest)
|
|
299
323
|
if (o && L.reported.get(n.key) !== said(n, o)) frameRecord(L, n, o)
|
|
324
|
+
visibleReadyNow(L)
|
|
300
325
|
}
|
|
301
326
|
settleSoon()
|
|
302
327
|
}
|
|
303
328
|
|
|
329
|
+
/** Spec 30 #49: the cohort's frames all reached their outcome - `board-open`'s `visibleReady` step - once per load. */
|
|
330
|
+
function visibleReadyNow(L: Load): void {
|
|
331
|
+
if (L.visibleReady || !L.cohort || [...L.cohort].some((k) => !L.reported.has(k))) return
|
|
332
|
+
L.visibleReady = true
|
|
333
|
+
phase({ phase: 'visible-ready', load: L.id })
|
|
334
|
+
}
|
|
335
|
+
|
|
304
336
|
function frameRecord(L: Load, n: Node, outcome: Outcome | 'cut'): void {
|
|
305
337
|
const t = tracks.get(n.key)
|
|
306
338
|
const times = [t?.admittedAt, t?.readyAt, t?.firstMeasureAt, t?.settled?.at]
|
|
@@ -347,18 +379,16 @@ function trySettle(): void {
|
|
|
347
379
|
function settle(L: Load, s: State, outs: Outcome[]): void {
|
|
348
380
|
ensureVisible(L)
|
|
349
381
|
s.nodes.forEach((n, i) => { if (L.reported.get(n.key) !== said(n, outs[i])) frameRecord(L, n, outs[i]) })
|
|
350
|
-
const lastReady = (ns: readonly Node[]) => {
|
|
351
|
-
const xs = ns.map((n) => tracks.get(n.key)?.readyAt).filter((x): x is number => x !== undefined)
|
|
352
|
-
return xs.length ? Math.max(0, Math.round(Math.max(...xs) - L.t0)) : undefined
|
|
353
|
-
}
|
|
354
382
|
if (!L.quietSent) { L.quietSent = true; rec('quiet', L.id, { ms: Math.round(L.lastMoveAt - L.t0) }) }
|
|
383
|
+
visibleReadyNow(L)
|
|
355
384
|
rec('settled', L.id, {
|
|
356
385
|
ms: Math.round(performance.now() - L.t0), moves: L.moves, distance: Math.round(L.distance), causes: L.causes, lastMove: rel(L, L.movedAt),
|
|
357
|
-
visibleReadyMs: lastReady(s.nodes.filter((n) => L.cohort?.has(n.key))), allReadyMs: lastReady(s.nodes),
|
|
386
|
+
visibleReadyMs: lastReady(L, s.nodes.filter((n) => L.cohort?.has(n.key))), allReadyMs: lastReady(L, s.nodes),
|
|
358
387
|
missing: outs.filter((o) => o === 'missing').length, neverReady: outs.filter((o) => o === 'never-ready').length, errors: outs.filter((o) => o === 'error').length,
|
|
359
388
|
weight: weight(),
|
|
360
389
|
})
|
|
361
390
|
finish(L, 'settled')
|
|
391
|
+
phase({ phase: 'settled', load: L.id })
|
|
362
392
|
}
|
|
363
393
|
|
|
364
394
|
/** The load ended before it settled: another board, a reload of this one, the page hidden, or 120 s. What its nodes
|
|
@@ -369,15 +399,29 @@ function cut(L: Load, reason: 'switch' | 'reload' | 'hidden' | 'timeout'): void
|
|
|
369
399
|
const s = useStore.getState()
|
|
370
400
|
ensureVisible(L)
|
|
371
401
|
let ready = 0
|
|
402
|
+
const readyNodes: Node[] = []
|
|
372
403
|
for (const n of s.nodes) {
|
|
373
404
|
const o = outcomeNow(n, s.manifest)
|
|
374
|
-
if (o === 'settled' || o === 'ready') ready
|
|
405
|
+
if (o === 'settled' || o === 'ready') { ready++; readyNodes.push(n) }
|
|
375
406
|
if (!o) frameRecord(L, n, 'cut')
|
|
376
407
|
else if (L.reported.get(n.key) !== said(n, o)) frameRecord(L, n, o)
|
|
377
408
|
}
|
|
378
|
-
rec('cut', L.id, { reason, ms: Math.round(performance.now() - L.t0), lastMove: rel(L, L.movedAt), frames: s.nodes.length, ready })
|
|
409
|
+
rec('cut', L.id, { reason, ms: Math.round(performance.now() - L.t0), lastMove: rel(L, L.movedAt), frames: s.nodes.length, ready, ...(fullRecorder() ? partialTimes(L, readyNodes) : {}) })
|
|
379
410
|
L.cutReason = reason
|
|
380
411
|
finish(L, 'cut')
|
|
412
|
+
phase({ phase: 'cut', load: L.id, reason })
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
/** Spec 30 #19: what a cut load had ready, as `settled` computes it, over the frames ready by then - `visibleReady` says
|
|
416
|
+
* how many of the cohort that is, so a partial time is never read as the whole. */
|
|
417
|
+
function partialTimes(L: Load, ready: readonly Node[]) {
|
|
418
|
+
const visible = ready.filter((n) => L.cohort?.has(n.key))
|
|
419
|
+
return { visibleReadyMs: lastReady(L, visible), allReadyMs: lastReady(L, ready), visibleReady: visible.length }
|
|
420
|
+
}
|
|
421
|
+
/** ms from the request to the last of these nodes' ready; none while none was. */
|
|
422
|
+
function lastReady(L: Load, ns: readonly Node[]): number | undefined {
|
|
423
|
+
const xs = ns.map((n) => tracks.get(n.key)?.readyAt).filter((x): x is number => x !== undefined)
|
|
424
|
+
return xs.length ? Math.max(0, Math.round(Math.max(...xs) - L.t0)) : undefined
|
|
381
425
|
}
|
|
382
426
|
|
|
383
427
|
function finish(L: Load, how: 'settled' | 'cut'): void {
|
|
@@ -407,47 +451,62 @@ function ensureVisible(L: Load): void {
|
|
|
407
451
|
const v = canvasCtl.view()
|
|
408
452
|
L.cohort = v ? cohortIn(v) : new Set()
|
|
409
453
|
rec('visible', L.id, { nodes: L.cohort.size, ms: Math.round(performance.now() - L.t0), assumed: true })
|
|
454
|
+
phase({ phase: 'visible', load: L.id, nodes: L.cohort.size, assumed: true })
|
|
410
455
|
}
|
|
411
456
|
|
|
412
457
|
// ---- errors -----------------------------------------------------------------------------------------------------
|
|
413
458
|
|
|
414
459
|
let inError = false
|
|
415
|
-
/**
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
460
|
+
/** each reason's `dropped` record while it waits to be sent (the next one adds to it): the errors past a load's 50, and
|
|
461
|
+
* what a source's rate or a frame's budget refused (spec 30 #33) */
|
|
462
|
+
const drops = new Map<DropReason, PerfRecord>()
|
|
463
|
+
function drop(reason: DropReason, n: number): void {
|
|
464
|
+
const d = drops.get(reason)
|
|
465
|
+
if (d && d.load === ownerId() && outbox.has(d)) { d.n = (d.n as number) + n; outbox.touch(d) }
|
|
466
|
+
else drops.set(reason, rec('dropped', ownerId(), { n, reason }))
|
|
467
|
+
}
|
|
468
|
+
/** Every source (spec 30 #27-#33): ≤ 50 per load (those past it counted), the same one at most once a second; messages and
|
|
469
|
+
* stack lines cut to 200 characters; the modes on with it. An error after the load settled or was cut is `late` - the
|
|
470
|
+
* load owns the geometry for as long as its board stays open. At the `core` level, what 0.29 did. */
|
|
471
|
+
function logError(e: SignalError): void {
|
|
421
472
|
if (inError) return
|
|
422
473
|
inError = true
|
|
423
474
|
try {
|
|
424
475
|
const message = bound(typeof e.message === 'string' ? e.message : String(e.message ?? ''))
|
|
425
476
|
if (!message) return
|
|
426
477
|
const L = owner, mine = L ?? unowned
|
|
478
|
+
const full = fullRecorder()
|
|
427
479
|
const key = `${e.source}|${e.frame ?? ''}|${message}`, now = performance.now()
|
|
428
|
-
if (now - (mine.errAt.get(key) ?? -Infinity) < 1000) return
|
|
429
|
-
if (mine.errors >= 50) {
|
|
430
|
-
if (over && over.load === ownerId() && outbox.has(over)) { over.n = (over.n as number) + 1; outbox.touch(over) }
|
|
431
|
-
else over = rec('dropped', ownerId(), { n: 1, reason: 'errors' })
|
|
432
|
-
return
|
|
433
|
-
}
|
|
480
|
+
if (now - (mine.errAt.get(key) ?? -Infinity) < 1000) { if (full) drop(e.source, 1); return }
|
|
481
|
+
if (mine.errors >= 50) { drop('errors', 1); return }
|
|
434
482
|
mine.errors++
|
|
435
483
|
mine.errAt.set(key, now)
|
|
436
484
|
const stack = Array.isArray(e.stack) ? e.stack.slice(0, 3).map((l) => bound(l)).filter((l): l is string => !!l) : stackLines(e.stack)
|
|
437
|
-
|
|
485
|
+
const modes = full ? modesOn() : []
|
|
486
|
+
rec('error', ownerId(), { source: e.source, frame: bound(e.frame), component: bound(e.component), message, ...(stack?.length ? { stack } : {}), ...(L?.done ? { late: true } : {}), ...(full ? e.fields : {}), ...(modes.length ? { modes } : {}) })
|
|
487
|
+
if (modes.length) errorCounted(modes)
|
|
438
488
|
} finally { inError = false }
|
|
439
489
|
}
|
|
490
|
+
// the signals stream's way in (recorder-signals.ts never imports this module)
|
|
491
|
+
signalSink.error = (e) => { if (on) logError(e) }
|
|
492
|
+
signalSink.dropped = (reason, n) => { if (on) drop(reason, n) }
|
|
440
493
|
|
|
441
494
|
// ---- sending ----------------------------------------------------------------------------------------------------
|
|
442
495
|
|
|
443
496
|
const armSend = () => { if (!sending && sendTimer === undefined && outbox.size) sendTimer = setTimeout(() => { sendTimer = undefined; void send() }, SEND_MS) }
|
|
444
497
|
const csrf = () => /(?:^|;\s*)mv_c=([\w-]+)/.exec(document.cookie)?.[1] ?? ''
|
|
445
|
-
const post = (records: PerfRecord[], keepalive = false) =>
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
}
|
|
498
|
+
const post = (records: PerfRecord[], keepalive = false) => {
|
|
499
|
+
const t0 = selfCounts.on ? performance.now() : 0 // spec 30 #58: `send`'s own work, and the bytes
|
|
500
|
+
const body = JSON.stringify({ records })
|
|
501
|
+
const sent = api('perf/page', {
|
|
502
|
+
method: 'POST',
|
|
503
|
+
headers: { 'content-type': 'application/json', 'x-mv-c': csrf() },
|
|
504
|
+
body,
|
|
505
|
+
...(keepalive ? { keepalive: true } : {}),
|
|
506
|
+
})
|
|
507
|
+
if (selfCounts.on) { selfCounts.bytes += bytesOf(body); perfSeams.selfCost('send', performance.now() - t0) }
|
|
508
|
+
return sent
|
|
509
|
+
}
|
|
451
510
|
const wait = (ms: number) => new Promise<void>((r) => setTimeout(r, ms))
|
|
452
511
|
/** The `dropped` record that says how many went, when any did (the count starts over). */
|
|
453
512
|
const droppedNow = (more = 0): PerfRecord[] => {
|
|
@@ -484,6 +543,8 @@ async function send(): Promise<void> {
|
|
|
484
543
|
}
|
|
485
544
|
} catch { /* never in the way: what it held is counted below */ }
|
|
486
545
|
if (!ok) { failedSends++; outbox.dropped += batch.filter((r) => r.kind !== 'dropped').length + batch.filter((r) => r.kind === 'dropped').reduce((n, r) => n + (r.n as number), 0) }
|
|
546
|
+
// spec 30 #58: every drop said by a `dropped` record that landed, whatever its reason
|
|
547
|
+
else if (selfCounts.on) selfCounts.dropped += batch.reduce((n, r) => n + (r.kind === 'dropped' ? (r.n as number) || 0 : 0), 0)
|
|
487
548
|
inFlight = []
|
|
488
549
|
sending = false
|
|
489
550
|
armSend()
|
|
@@ -501,10 +562,13 @@ function leave(): void {
|
|
|
501
562
|
if (capturesPending() || WARM) return
|
|
502
563
|
// a send on its way may not outlive the page: its records again (the report drops a duplicate by its seq)
|
|
503
564
|
const all = [...inFlight, ...outbox.takeAll()]
|
|
504
|
-
if (
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
565
|
+
if (all.length) {
|
|
566
|
+
// the cuts first, newest first: the load this page leaves in flight ends in the last of them
|
|
567
|
+
const { fit, lost } = fitWithin(all.filter((r) => r.kind === 'cut').reverse(), all.filter((r) => r.kind !== 'cut'), KEEPALIVE_BYTES)
|
|
568
|
+
try { void post([...fit, ...droppedNow(lost)], true).catch(() => {}) } catch { /* going anyway */ }
|
|
569
|
+
}
|
|
570
|
+
// then the reload lines' share (spec 30 #7), after the page's own
|
|
571
|
+
perfSeams.leaving.emit()
|
|
508
572
|
}
|
|
509
573
|
|
|
510
574
|
// ---- a headless perf run (spec 28 A3.8 #17) ----------------------------------------------------------------------
|
|
@@ -596,9 +660,19 @@ export const recorder = {
|
|
|
596
660
|
if (!L || L.committedAt === undefined || L.cohort) return
|
|
597
661
|
L.cohort = cohortIn(view)
|
|
598
662
|
rec('visible', L.id, { nodes: L.cohort.size, ms: Math.round(performance.now() - L.t0) })
|
|
663
|
+
phase({ phase: 'visible', load: L.id, nodes: L.cohort.size })
|
|
599
664
|
}),
|
|
600
665
|
/** A pan, zoom or layout animation ended (perf.ts). */
|
|
601
|
-
gesture: guard((g: Gesture) => {
|
|
666
|
+
gesture: guard((g: Gesture) => {
|
|
667
|
+
let seen = {}
|
|
668
|
+
// spec 30 #34: what it ended showing, and the documents awake then (iframes minus asleep, as `weight()`)
|
|
669
|
+
if (fullRecorder()) {
|
|
670
|
+
const v = canvasCtl.view()
|
|
671
|
+
seen = { ...(v ? { visible: cohortIn(v).size } : {}), awake: Math.max(0, document.querySelectorAll('iframe.sh-live[src]').length - sleeping()) }
|
|
672
|
+
}
|
|
673
|
+
rec('gesture', ownerId(), { ...g, hz: displayHz() ?? undefined, ...seen })
|
|
674
|
+
settleSoon()
|
|
675
|
+
}),
|
|
602
676
|
/** An error the shell saw: its own (window, ShellBoundary) or the play stage's. A shell error goes out at once. */
|
|
603
677
|
error: guard((e: { source: 'shell' | 'stage'; message: unknown; stack?: unknown; component?: string }) => {
|
|
604
678
|
logError(e)
|
|
@@ -6,6 +6,8 @@ import { stableNodeKey } from './keys.ts'
|
|
|
6
6
|
import { canvasCtl } from './canvas/ctl.ts'
|
|
7
7
|
import { api, beforeResume, canvasStopped, holdsReload, lostInResume, mvFetch, noteUnsaved, onLinkNotice, savedInResume, scoped, STOPPED_WAY, withWs } from './api.ts'
|
|
8
8
|
import { unsavedWhen, workChanged } from './unsaved.ts'
|
|
9
|
+
import { nextSeq, PAGE_ID } from './recorder-seams.ts'
|
|
10
|
+
import type { BoardWriter, HeldBy, LoadTrigger } from '../../shared/perf-records.ts'
|
|
9
11
|
// @ts-expect-error virtual module provided by the plugin
|
|
10
12
|
import shConfig from 'virtual:sh-config'
|
|
11
13
|
// @ts-expect-error virtual module: null in dev; a published build inlines manifest+boards
|
|
@@ -176,6 +178,7 @@ import { UNPLACED } from './hash.ts'
|
|
|
176
178
|
import type { BoardType, StatusWord } from '../../shared/board-types.ts'
|
|
177
179
|
import type { Phase, Status } from '../../shared/status.ts'
|
|
178
180
|
import { isNew, type Marks } from '../../shared/marks.ts'
|
|
181
|
+
import { cmd, keepCmds, type CmdOpts } from './commands.ts'
|
|
179
182
|
|
|
180
183
|
/** The CAS tokens a tree write echoes: the sha256 of every board file as last seen, and of
|
|
181
184
|
* the folder registry (null = there was no file). */
|
|
@@ -272,11 +275,26 @@ const TAB = Math.random().toString(36).slice(2, 8)
|
|
|
272
275
|
* means a first load, or a document that reloaded itself (the reload log tells them apart). */
|
|
273
276
|
const reloadCause = new Map<string, 'job' | 'manual' | 'retry'>()
|
|
274
277
|
export const takeReloadCause = (key: string) => { const c = reloadCause.get(key); reloadCause.delete(key); return c }
|
|
278
|
+
/** A reload line with its envelope (spec 30 #16): the tab, and the page and seq the `(page, seq)` dedupe reads. */
|
|
279
|
+
export const reloadLine = (entry: Record<string, unknown>): Record<string, unknown> => ({ tab: TAB, page: PAGE_ID, seq: nextSeq(), ts: Date.now(), ...entry })
|
|
280
|
+
/** The edit's way to the frames, as the recorder sees it: recorder-reloads.ts installs these at the full level (spec 30
|
|
281
|
+
* R1). Until then, and under `core`, a line goes as 0.29's did - one unconfirmed request - and the rest do nothing. */
|
|
282
|
+
export const reloadHooks = {
|
|
283
|
+
line: (l: Record<string, unknown>): void => {
|
|
284
|
+
const body = { records: [l] }
|
|
285
|
+
// a page's very first request may go before its request cookie exists: a GET primes it, then once more
|
|
286
|
+
void postOwner('perf/reload', body).then((r) => (r.status === 403 ? api('work').then(() => postOwner('perf/reload', body)) : r)).catch(() => {})
|
|
287
|
+
},
|
|
288
|
+
/** an edit reached these frames: before their nodes go stale */
|
|
289
|
+
invalidated: (_frames: ReadonlySet<string>, _revision: string): void => {},
|
|
290
|
+
/** a reload job started this navigation of a node */
|
|
291
|
+
started: (_key: string, _nav: number): void => {},
|
|
292
|
+
/** a stale node's turn was refused, and why (canvas/updates.ts) */
|
|
293
|
+
held: (_key: string, _why: HeldBy): void => {},
|
|
294
|
+
}
|
|
275
295
|
export const logReload = (entry: Record<string, unknown>) => {
|
|
276
296
|
if (PUBLISHED) return
|
|
277
|
-
|
|
278
|
-
// a page's very first request may go before its request cookie exists: a GET primes it, then once more
|
|
279
|
-
void postOwner('perf/reload', body).then((r) => (r.status === 403 ? api('work').then(() => postOwner('perf/reload', body)) : r)).catch(() => {})
|
|
297
|
+
reloadHooks.line(reloadLine(entry))
|
|
280
298
|
}
|
|
281
299
|
const postOwner = (path: string, body: unknown) =>
|
|
282
300
|
api(path, { method: 'POST', headers: { 'content-type': 'application/json', 'x-mv-c': csrf() }, body: JSON.stringify(body) })
|
|
@@ -285,11 +303,13 @@ const postOwner = (path: string, body: unknown) =>
|
|
|
285
303
|
* `marver boards pin` does. The answer is said; the file change re-reads the sidebar and the view. */
|
|
286
304
|
export async function addToBoard(board: string, frames: string[]): Promise<void> {
|
|
287
305
|
const { toast } = useStore.getState()
|
|
306
|
+
const h = cmd('add-to-board', { via: 'click', in: 'shell', board, frames: frames.length })
|
|
288
307
|
try {
|
|
289
308
|
const r = await postOwner('boards/pin', { board, frames })
|
|
290
309
|
const body = await r.json().catch(() => ({})) as { added?: string[]; error?: string }
|
|
310
|
+
if (r.ok) h.done(); else h.fail('api')
|
|
291
311
|
toast(r.ok ? `${body.added?.length ? 'pinned' : 'already'} on ${boardLabel(board)}` : body.error ?? `could not pin (${r.status})`)
|
|
292
|
-
} catch { toast('could not reach the dev server') }
|
|
312
|
+
} catch { h.fail('api'); toast('could not reach the dev server') }
|
|
293
313
|
}
|
|
294
314
|
|
|
295
315
|
const HEADER = 28
|
|
@@ -517,7 +537,8 @@ export type RequestCut = 'superseded' | 'error' | 'edited' | 'unsaved'
|
|
|
517
537
|
* on a published one. A request owns the geometry from its commit, and `commit` runs right BEFORE the set that
|
|
518
538
|
* mounts the load: mounting it is never a move. */
|
|
519
539
|
export const recorderHooks = {
|
|
520
|
-
|
|
540
|
+
/** `trigger`, `writer`: why it read the board again, and who may have written it (spec 30 #17, #18) */
|
|
541
|
+
request: (_board: string, _cause: LoadCause, _trigger?: LoadTrigger, _writer?: BoardWriter): string => '',
|
|
521
542
|
/** a request is about to commit: the load that was up ends - before the incoming sizes are installed, so it ends by
|
|
522
543
|
* the sizes it read (which frames measure), its board's nodes still in the store */
|
|
523
544
|
handover: (_request: string): void => {},
|
|
@@ -633,8 +654,9 @@ interface State {
|
|
|
633
654
|
imageBusy: boolean // a copy-as-image render is in flight (one at a time)
|
|
634
655
|
|
|
635
656
|
/** (re)load the open board from disk. `mayCommit`, when given, is asked again at the moment the
|
|
636
|
-
* reload would land - a caller's own conditions (a status write's: nothing moved since its flush)
|
|
637
|
-
|
|
657
|
+
* reload would land - a caller's own conditions (a status write's: nothing moved since its flush).
|
|
658
|
+
* `trigger`, `writer`: why it reads the board again, and who may have written it - the recorder's (spec 30 #17, #18) */
|
|
659
|
+
boot(mayCommit?: () => boolean, trigger?: LoadTrigger, writer?: BoardWriter): Promise<boolean>
|
|
638
660
|
applyManifest(m: Manifest): void
|
|
639
661
|
frameFor(node: Node): FrameEntry | undefined
|
|
640
662
|
moveNode(key: string, x: number, y: number): void
|
|
@@ -688,7 +710,7 @@ interface State {
|
|
|
688
710
|
setScenes(scenes: Manifest['scenes']): void
|
|
689
711
|
arrangeBoards(tree: TreeItem[], base: TreeBase): Promise<{ ok: true } | { ok: false; stale: boolean; error?: string }>
|
|
690
712
|
pulsePath(): void
|
|
691
|
-
copyFrameImage(scale: 2 | 4): void
|
|
713
|
+
copyFrameImage(scale: 2 | 4, how: CmdOpts): void
|
|
692
714
|
setScale(s: number): void
|
|
693
715
|
togglePanel(): void
|
|
694
716
|
setTheme(theme: string): void
|
|
@@ -1168,12 +1190,12 @@ export const useStore = create<State>((set, get) => {
|
|
|
1168
1190
|
panelOpen: true, scale: 1, toasts: [], working: [], workingSince: {}, workingBoards: [], workingSeq: -1, boardHash: null, dirty: false, boardTitles: DATA?.titles ?? {}, boardMeta: DATA?.meta ?? {},
|
|
1169
1191
|
externalLeases: {}, playUpdateRevision: null, stageShown: null, playNav: 0, pathPulse: 0, imagePulse: 0, imageBusy: false,
|
|
1170
1192
|
|
|
1171
|
-
async boot(mayCommit) {
|
|
1193
|
+
async boot(mayCommit, trigger, writer) {
|
|
1172
1194
|
const seq = ++loadSeq
|
|
1173
1195
|
recorderHooks.cut(bootRequest, 'superseded')
|
|
1174
1196
|
const boardName = get().board
|
|
1175
1197
|
// the recorder's request (spec 28 A1.7): the page's first load, else the open board read from disk again
|
|
1176
|
-
const request = bootRequest = recorderHooks.request(boardName, firstLoad ? 'boot' : 'disk-reload')
|
|
1198
|
+
const request = bootRequest = recorderHooks.request(boardName, firstLoad ? 'boot' : 'disk-reload', firstLoad ? 'first' : trigger, writer)
|
|
1177
1199
|
firstLoad = false
|
|
1178
1200
|
const revAtStart = editRev, scenesAtStart = scenesRev
|
|
1179
1201
|
const loaded = await loadBoardState(boardName)
|
|
@@ -1245,6 +1267,7 @@ export const useStore = create<State>((set, get) => {
|
|
|
1245
1267
|
},
|
|
1246
1268
|
|
|
1247
1269
|
renameBoard(name, title, baseHash) {
|
|
1270
|
+
const sending = keepCmds() // spec 30 #18: this write names its command however long it waits for its turn and the flush
|
|
1248
1271
|
return structural(async () => {
|
|
1249
1272
|
const from = name
|
|
1250
1273
|
const active = from === get().board
|
|
@@ -1263,12 +1286,12 @@ export const useStore = create<State>((set, get) => {
|
|
|
1263
1286
|
try {
|
|
1264
1287
|
// the active board's hash is freshest in the store (an autosave may have landed since
|
|
1265
1288
|
// the sidebar looked); every other board's is the sidebar's
|
|
1266
|
-
const send = (base: string | null | undefined) => postOwner('boards/rename', { from, title, ...(base ? { baseHash: base } : {}) })
|
|
1289
|
+
const send = (base: string | null | undefined) => sending(() => postOwner('boards/rename', { from, title, ...(base ? { baseHash: base } : {}) }))
|
|
1267
1290
|
let res: Response
|
|
1268
1291
|
try {
|
|
1269
1292
|
res = await send(active && get().boardHash ? get().boardHash : baseHash)
|
|
1270
1293
|
// the open board changed on disk: reload it, then once more (setBoardStatus's reasoning)
|
|
1271
|
-
if (res.status === 409 && mayReload() && await get().boot(mayReload)) res = await send(get().boardHash)
|
|
1294
|
+
if (res.status === 409 && mayReload() && await get().boot(mayReload, 'save-conflict')) res = await send(get().boardHash)
|
|
1272
1295
|
}
|
|
1273
1296
|
catch { return { ok: false, error: 'could not reach the dev server' } }
|
|
1274
1297
|
const body = await res.json().catch(() => ({} as { error?: string; sha256?: string }))
|
|
@@ -1285,6 +1308,7 @@ export const useStore = create<State>((set, get) => {
|
|
|
1285
1308
|
},
|
|
1286
1309
|
|
|
1287
1310
|
setBoardStatus(name, status, reason, baseHash) {
|
|
1311
|
+
const sending = keepCmds() // renameBoard's
|
|
1288
1312
|
return structural(async () => {
|
|
1289
1313
|
const active = name === get().board
|
|
1290
1314
|
// the active board's file is rewritten under the autosave: flush first, hold across (renameBoard's pattern)
|
|
@@ -1299,14 +1323,14 @@ export const useStore = create<State>((set, get) => {
|
|
|
1299
1323
|
const rev = editRev
|
|
1300
1324
|
const mayReload = () => active && get().board === name && editRev === rev && !get().gesture
|
|
1301
1325
|
try {
|
|
1302
|
-
const send = (base: string | null | undefined) => postOwner('boards/status', { name, status, ...(reason ? { reason } : {}), ...(base ? { baseHash: base } : {}) })
|
|
1326
|
+
const send = (base: string | null | undefined) => sending(() => postOwner('boards/status', { name, status, ...(reason ? { reason } : {}), ...(base ? { baseHash: base } : {}) }))
|
|
1303
1327
|
let res: Response
|
|
1304
1328
|
try {
|
|
1305
1329
|
res = await send(active && get().boardHash ? get().boardHash : baseHash)
|
|
1306
1330
|
// the open board changed on disk (an agent wrote it): its hash in the store is behind, and a
|
|
1307
1331
|
// retry with it would 409 again - reload the board (layout and hash together) when nothing
|
|
1308
1332
|
// has changed here since the flush, then try once more against what is on disk now
|
|
1309
|
-
if (res.status === 409 && mayReload() && await get().boot(mayReload)) res = await send(get().boardHash)
|
|
1333
|
+
if (res.status === 409 && mayReload() && await get().boot(mayReload, 'save-conflict')) res = await send(get().boardHash)
|
|
1310
1334
|
}
|
|
1311
1335
|
catch { return { ok: false, error: 'could not reach the dev server' } }
|
|
1312
1336
|
const body = await res.json().catch(() => ({} as { error?: string; sha256?: string }))
|
|
@@ -1354,6 +1378,7 @@ export const useStore = create<State>((set, get) => {
|
|
|
1354
1378
|
// true and the watcher's echo is filtered as our own. `base` carries the hashes the
|
|
1355
1379
|
// sidebar last saw; a 409 (`stale`) means someone else wrote first - refetch and replay.
|
|
1356
1380
|
arrangeBoards(tree, base) {
|
|
1381
|
+
const sending = keepCmds() // renameBoard's
|
|
1357
1382
|
return structural(async () => {
|
|
1358
1383
|
let ok = true
|
|
1359
1384
|
for (let i = 0; i < 5 && get().dirty && ok; i++) { clearTimeout(saveTimer); ok = await get().save() }
|
|
@@ -1365,7 +1390,7 @@ export const useStore = create<State>((set, get) => {
|
|
|
1365
1390
|
const active = get().board
|
|
1366
1391
|
const boards = { ...base.boards, ...(get().boardHash && base.boards[active] !== undefined ? { [active]: get().boardHash } : {}) }
|
|
1367
1392
|
let res: Response
|
|
1368
|
-
try { res = await postOwner('boards/reorder', { tree: toWire(tree), base: { boards, folders: base.folders }, protocol: TREE_PROTOCOL }) }
|
|
1393
|
+
try { res = await sending(() => postOwner('boards/reorder', { tree: toWire(tree), base: { boards, folders: base.folders }, protocol: TREE_PROTOCOL })) }
|
|
1369
1394
|
catch { return { ok: false as const, stale: false, error: 'could not reach the dev server' } }
|
|
1370
1395
|
const body = await res.json().catch(() => ({} as { error?: string; sha256?: { boards?: Record<string, string> } }))
|
|
1371
1396
|
if (!res.ok) return { ok: false as const, stale: res.status === 409, error: body?.error }
|
|
@@ -1762,6 +1787,7 @@ export const useStore = create<State>((set, get) => {
|
|
|
1762
1787
|
// every document of these frames is behind - one loading too (one running, one waiting): a document
|
|
1763
1788
|
// that shows the revision the edit made clears it when it is ready (setShown)
|
|
1764
1789
|
const want = (f: string) => (docs?.epoch && typeof docs.docs?.[f] === 'number' ? `${docs.epoch}:${docs.docs[f]}` : undefined)
|
|
1790
|
+
reloadHooks.invalidated(ids, revision)
|
|
1765
1791
|
const nodes = s.nodes.map((n) => (ids.has(n.frame) && !n.missing ? { ...n, stale: true, want: later(n.want, want(n.frame)) } : n))
|
|
1766
1792
|
set({ nodes, ...(s.play ? { playUpdateRevision: revision } : {}) })
|
|
1767
1793
|
pumpUpdates()
|
|
@@ -1776,6 +1802,7 @@ export const useStore = create<State>((set, get) => {
|
|
|
1776
1802
|
set((s) => ({ nodes: s.nodes.map((x) => (x.key === key
|
|
1777
1803
|
? { ...x, stale: false, status: 'loading' as const, error: undefined, nav: (x.nav ?? 0) + 1, readyRetried: false }
|
|
1778
1804
|
: x)) }))
|
|
1805
|
+
reloadHooks.started(key, (n.nav ?? 0) + 1)
|
|
1779
1806
|
},
|
|
1780
1807
|
setShown(key, shown) {
|
|
1781
1808
|
set((s) => ({ nodes: s.nodes.map((x) => {
|
|
@@ -1816,15 +1843,19 @@ export const useStore = create<State>((set, get) => {
|
|
|
1816
1843
|
// node shows, at 2x (or 4x). The ClipboardItem takes a PROMISE: clipboard.write runs
|
|
1817
1844
|
// inside the click/keydown gesture and the browser waits for the bytes - a plain
|
|
1818
1845
|
// await-then-write would have lost the transient activation during the 1-4s render.
|
|
1819
|
-
copyFrameImage(scale) {
|
|
1846
|
+
copyFrameImage(scale, how) {
|
|
1820
1847
|
const s = get()
|
|
1821
|
-
if (PUBLISHED
|
|
1848
|
+
if (PUBLISHED) return
|
|
1849
|
+
// spec 30: done when the clipboard holds it (60 s, the ceiling below); each refusal its code
|
|
1850
|
+
const h = cmd('copy-image', { ...how, frames: s.selection.length, arg: `${scale}x` })
|
|
1851
|
+
if (s.imageBusy) { h.noop('busy'); return }
|
|
1852
|
+
if (s.selection.length !== 1) { h.noop('multi'); return }
|
|
1822
1853
|
const node = s.nodes.find((n) => n.key === s.selection[0])
|
|
1823
|
-
if (!node || node.missing) return
|
|
1854
|
+
if (!node || node.missing) { h.noop('indexing'); return }
|
|
1824
1855
|
const frame = s.frameFor(node)
|
|
1825
|
-
if (!frame) { s.toast('frame is still indexing - try again in a second'); return }
|
|
1856
|
+
if (!frame) { h.noop('indexing'); s.toast('frame is still indexing - try again in a second'); return }
|
|
1826
1857
|
const CI = (globalThis as { ClipboardItem?: typeof ClipboardItem }).ClipboardItem
|
|
1827
|
-
if (!CI || !navigator.clipboard?.write || (CI.supports && !CI.supports('image/png'))) { s.toast("this browser can't put images on the clipboard - use Chrome, Edge or Safari"); return }
|
|
1858
|
+
if (!CI || !navigator.clipboard?.write || (CI.supports && !CI.supports('image/png'))) { h.fail('browser'); s.toast("this browser can't put images on the clipboard - use Chrome, Edge or Safari"); return }
|
|
1828
1859
|
set({ imageBusy: true })
|
|
1829
1860
|
void import('./jam-capture.ts').then(({ recordCopy }) => recordCopy('image', frame.id)) // a capture notes that it happened
|
|
1830
1861
|
const done = () => set({ imageBusy: false })
|
|
@@ -1840,11 +1871,13 @@ export const useStore = create<State>((set, get) => {
|
|
|
1840
1871
|
return r.blob()
|
|
1841
1872
|
}).finally(() => clearTimeout(timer))
|
|
1842
1873
|
let renderErr = ''
|
|
1843
|
-
|
|
1874
|
+
let renderTimedOut = false
|
|
1875
|
+
png.catch((e: Error) => { renderTimedOut = e.name === 'AbortError'; renderErr = renderTimedOut ? 'timed out - the renderer is busy' : e.message })
|
|
1844
1876
|
const fail = (err: unknown) => {
|
|
1845
1877
|
done()
|
|
1846
1878
|
// a prompt clipboard refusal (no gesture, focus lost) must not wait a minute on the
|
|
1847
1879
|
// render: abandon the fetch, toast now. A render failure surfaces its own cause.
|
|
1880
|
+
h.fail(renderErr ? (renderTimedOut ? 'render-timeout' : 'render-failed') : (err as Error)?.name === 'NotAllowedError' ? 'clipboard-blocked' : 'render-failed')
|
|
1848
1881
|
if (!renderErr) ctl.abort()
|
|
1849
1882
|
s.toast(renderErr ? `render failed - ${renderErr}` : (err as Error)?.name === 'NotAllowedError' ? 'copy blocked - click the canvas first' : `copy failed - ${(err as Error)?.message ?? err}`)
|
|
1850
1883
|
}
|
|
@@ -1852,6 +1885,7 @@ export const useStore = create<State>((set, get) => {
|
|
|
1852
1885
|
navigator.clipboard.write([new CI({ 'image/png': png })]).then(
|
|
1853
1886
|
() => {
|
|
1854
1887
|
done()
|
|
1888
|
+
h.done()
|
|
1855
1889
|
const used = meta.scale ?? scale
|
|
1856
1890
|
s.toast(used < scale ? `image copied at ${used}x - frame too tall for ${scale}x` : scale === 4 ? 'image copied (4x)' : 'image copied')
|
|
1857
1891
|
set((st) => ({ imagePulse: st.imagePulse + 1 }))
|
|
@@ -2150,7 +2184,7 @@ export const useStore = create<State>((set, get) => {
|
|
|
2150
2184
|
lostInResume('gone') // a save while a resume is owed: the page after its reload says this, not "saved"
|
|
2151
2185
|
return true
|
|
2152
2186
|
}
|
|
2153
|
-
const reloaded = await get().boot() // hash advances only when the authoritative reload commits
|
|
2187
|
+
const reloaded = await get().boot(undefined, 'save-conflict') // hash advances only when the authoritative reload commits
|
|
2154
2188
|
if (reloaded) { get().toast(DISK_WON); lostInResume('disk') }
|
|
2155
2189
|
return reloaded // false keeps dirty set; the next debounce retries once edits settle
|
|
2156
2190
|
}
|
|
@@ -91,8 +91,10 @@ function cameraPath(): { path: PerfCam[]; stop(): void } {
|
|
|
91
91
|
return { path, stop: () => { on = false } }
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
/** The `before` answer for `tick`: the points chosen now, the camera and the viewport.
|
|
94
|
+
/** The `before` answer for `tick`: the points chosen now, the camera and the viewport. A covering play stage leaves no
|
|
95
|
+
* ground to probe, and says so (spec 30 #39): main takes no capture and records the time as uncovered. */
|
|
95
96
|
export function pick(tick: number): Extract<PerfMsg, { kind: 'probes'; at: 'before' }> {
|
|
97
|
+
if (document.querySelector('.sh-play')) return { kind: 'probes', tick, at: 'before', points: [], cam: canvasCtl.transform(), view: view(), stage: true }
|
|
96
98
|
const top = VISIBLE_TOP
|
|
97
99
|
const w = innerWidth, h = Math.max(0, innerHeight - top)
|
|
98
100
|
const rects = nodeRects()
|