@marver-design/marver 0.28.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 +103 -0
- package/README.md +4 -3
- package/dist/{anchor-check-PHUOFj1N.mjs → anchor-check-c52IDkiQ.mjs} +1 -1
- package/dist/{build-BsAyLMT1.mjs → build-C3mUtjEn.mjs} +7 -4
- package/dist/{capture-DdZ6xgoz.mjs → capture-DEtM4qm5.mjs} +168 -5
- package/dist/cli.mjs +11 -11
- package/dist/{comments-CrBHPEQl.mjs → comments-XNhMmSSu.mjs} +2 -2
- package/dist/{connectors-MR9d-EBP.mjs → connectors-DekQvKt9.mjs} +3 -1
- package/dist/{daemon-C5dg2R-V.mjs → daemon-B0Wi1OQ3.mjs} +30 -29
- package/dist/{dev-D7YS7iT2.mjs → dev-5dlxoW28.mjs} +19 -14
- package/dist/{init-WE5lQkQL.mjs → init-CYlFaRzG.mjs} +1 -1
- package/dist/logo-CXY-1yrn.mjs +305 -0
- package/dist/{ls-BZ5TAtd5.mjs → ls-NqmePKOf.mjs} +1 -1
- package/dist/{marks-Kmdab_5w.mjs → marks-BnNANic9.mjs} +20 -1
- package/dist/{marks-Dyn6tmjp.mjs → marks-DBp3h1Mc.mjs} +2 -5
- package/dist/{marver-id-gate-D-R0hSt_.mjs → marver-id-gate-vBLb_Icb.mjs} +1 -1
- package/dist/{perf-Cn5LiRaY.mjs → perf-6MOTHxay.mjs} +751 -122
- package/dist/perf-BCxAo0IS.mjs +1743 -0
- package/dist/{plugin-C_0yb-Fq.mjs → plugin-CXRoMA8g.mjs} +1382 -810
- package/dist/{poster-DHi6I1fO.mjs → poster-CYmCa00B.mjs} +1 -1
- package/dist/{profile-jIS6BcAs.mjs → profile-B1FKOM1e.mjs} +1 -1
- package/dist/{publish-bakes-r4PEZuPl.mjs → publish-bakes-C_2ZtHou.mjs} +3 -3
- package/dist/{queue-c-6aTHEz.mjs → queue-DeSQm24g.mjs} +29 -14
- package/dist/{recover-nrLEVLyJ.mjs → recover-XD8iXJOj.mjs} +2 -2
- package/dist/{serve-Dp3nHstu.mjs → serve-DQv3Ti6X.mjs} +8 -4
- package/dist/{session-DyVE7cCk.mjs → session-VDJfXEEm.mjs} +1 -1
- package/dist/{share-Ce4tP7ji.mjs → share-Bu_kuOKL.mjs} +1 -1
- package/dist/{shot-BrRtqaiS.mjs → shot-CRRGgxru.mjs} +3 -3
- package/dist/{slots-CFNnegCc.mjs → slots-Dn4Onb0V.mjs} +101 -3
- package/dist/{sync-CQdGARJ9.mjs → sync-CMozOwZ0.mjs} +1 -1
- package/docs/app.md +194 -0
- package/docs/boards-and-folders.md +11 -0
- package/docs/jam-session.md +12 -3
- package/docs/live-jam.md +3 -0
- package/docs/performance.md +99 -19
- package/docs/publish.md +7 -0
- 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 +71 -46
- package/src/client/shell/ContextMenu.tsx +8 -6
- package/src/client/shell/JamSurface.tsx +187 -71
- package/src/client/shell/LockedApp.tsx +19 -3
- package/src/client/shell/Play.tsx +110 -62
- package/src/client/shell/StatusPicker.tsx +19 -9
- package/src/client/shell/Toolbar.tsx +15 -7
- package/src/client/shell/api.ts +25 -7
- package/src/client/shell/app-bridge.ts +23 -9
- 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 +56 -27
- package/src/client/shell/goto.ts +15 -9
- package/src/client/shell/jam-capture.ts +39 -15
- package/src/client/shell/jam-keys.ts +303 -111
- package/src/client/shell/jam-lane.tsx +19 -12
- package/src/client/shell/jam-lines.ts +10 -1
- package/src/client/shell/jam-panel.tsx +68 -53
- package/src/client/shell/jam-queue.ts +6 -1
- package/src/client/shell/jam-session.tsx +41 -37
- package/src/client/shell/jam-state.ts +28 -5
- package/src/client/shell/jam-surface-parts.tsx +8 -6
- package/src/client/shell/jam-ui.tsx +12 -5
- package/src/client/shell/jam-voice.ts +4 -2
- package/src/client/shell/live-picture.ts +134 -0
- package/src/client/shell/main.tsx +7 -1
- package/src/client/shell/marks-ui.tsx +11 -0
- package/src/client/shell/open-item.ts +83 -0
- package/src/client/shell/open-resolve.ts +50 -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 +62 -24
- package/src/client/shell/styles.css +2 -0
- package/src/client/shell/whiteout-probes.ts +3 -1
- package/src/client/stage/main.tsx +39 -12
- package/src/shared/app-api.ts +201 -9
- package/src/shared/app-perf.ts +103 -8
- 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/templates/instructions/jam.md +4 -0
- package/dist/live-Cgzsicwi.mjs +0 -4
- package/dist/perf-jam-QxD_UnzN.mjs +0 -635
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A notice's click, in the shell (spec 28 A4.6 #29, #30; r1 #1-#3, r2 #1, #2, r3, r4 #1). Main hands `mv:open` the item
|
|
3
|
+
* as the live stream named it, once this document is admitted; the shell reads afresh what it resolves against - never
|
|
4
|
+
* the click's copy - compares the occurrence, its state and its counter, and opens the target through the helpers
|
|
5
|
+
* every other path uses (jam-keys.ts). Its answer: `handled` - the item is on screen; `stale` - its target stands in
|
|
6
|
+
* another state, or the same state with another counter, and opens as it stands (never another item); `missing` - the
|
|
7
|
+
* target is gone, and only its board opens; `busy` - a capture records or words wait unsent, and nothing moved;
|
|
8
|
+
* `dropped` - a read failed, the deadline passed, or a later click, a hidden tab or a revoked trust took its place.
|
|
9
|
+
*
|
|
10
|
+
* One request at a time, under one deadline over everything: `alive()` holds while the request is the current one,
|
|
11
|
+
* before its deadline, with no capture recording and no words typed and unsent - and once it fails it stays failed. The helpers read it before every step
|
|
12
|
+
* that moves the UI - a board change, comments turned on, a thread made active, a panel or a menu opened, Play left -
|
|
13
|
+
* so words typed during the reads or a wait are seen at the next step, and once it fails nothing more moves. Opening
|
|
14
|
+
* a question never marks it answered.
|
|
15
|
+
*/
|
|
16
|
+
import { LIVE_KINDS, type OpenItem, type OpenResult } from '../../shared/app-api.ts'
|
|
17
|
+
import { typedUnsent } from './api.ts'
|
|
18
|
+
import { useComments } from './comments-store.ts'
|
|
19
|
+
import { useJamCapture } from './jam-capture.ts'
|
|
20
|
+
import { openRunControls, openThreadAt, openTile, toBoard, type Alive } from './jam-keys.ts'
|
|
21
|
+
import { useJamQueue } from './jam-queue.ts'
|
|
22
|
+
import { resolveItem, type Target } from './open-resolve.ts'
|
|
23
|
+
import { fetchBoardNames, useStore } from './store.ts'
|
|
24
|
+
|
|
25
|
+
/** One deadline over a request: the manifest, the reads, the helpers' waits. */
|
|
26
|
+
export const OPEN_MS = 10_000
|
|
27
|
+
let current = 0
|
|
28
|
+
|
|
29
|
+
/** The request in hand ends - `mv:app-state` hidden or untrusted: nothing of it moves after this. */
|
|
30
|
+
export function endOpen(): void { current++ }
|
|
31
|
+
|
|
32
|
+
/** Nothing may move: a capture records, or a field holds words typed and not sent (a move would lose them). */
|
|
33
|
+
const busy = () => !!useJamCapture.getState().current || typedUnsent()
|
|
34
|
+
|
|
35
|
+
/** Open the live item a notice named, and say what was found (A4.6 #30). Registered by startAppBridge as `onOpen`. */
|
|
36
|
+
export async function openLiveItem(p: OpenItem): Promise<OpenResult> {
|
|
37
|
+
const n = ++current
|
|
38
|
+
const until = performance.now() + OPEN_MS
|
|
39
|
+
// one way (code review r3): the first time it reads false - a later click, hidden, untrusted, the deadline, a recording,
|
|
40
|
+
// words unsent - the request has ended for good, for every helper and every deferred callback at once. Words cleared or
|
|
41
|
+
// sent after never bring it back: a switch it started would otherwise commit when they go (toBoard's predicate)
|
|
42
|
+
let ended: 'busy' | 'dropped' | null = null
|
|
43
|
+
const alive: Alive = () => {
|
|
44
|
+
if (!ended && (n !== current || performance.now() >= until || busy())) ended = busy() ? 'busy' : 'dropped'
|
|
45
|
+
return !ended
|
|
46
|
+
}
|
|
47
|
+
/** once it fails: busy if a capture recorded or words waited when it ended, else dropped */
|
|
48
|
+
const gaveUp = (): OpenResult => ended ?? (busy() ? 'busy' : 'dropped')
|
|
49
|
+
if (!p || typeof p.board !== 'string' || !(LIVE_KINDS as readonly string[]).includes(p.kind)) return 'dropped'
|
|
50
|
+
if (busy()) return 'busy'
|
|
51
|
+
/** a promise, or undefined at the deadline */
|
|
52
|
+
const inTime = <T>(pr: Promise<T>) => Promise.race([pr.catch(() => undefined), new Promise<undefined>((r) => setTimeout(() => r(undefined), Math.max(0, until - performance.now())))])
|
|
53
|
+
// the board's manifest first
|
|
54
|
+
while (!useStore.getState().manifest) {
|
|
55
|
+
if (!alive()) return gaveUp()
|
|
56
|
+
await new Promise((r) => setTimeout(r, 50))
|
|
57
|
+
}
|
|
58
|
+
// then what it resolves against, read afresh - only a read that succeeds counts
|
|
59
|
+
const needsQueue = p.kind !== 'ask' || !!p.cards?.length
|
|
60
|
+
const [comments, queue] = await Promise.all([inTime(useComments.getState().refresh(p.board)), needsQueue ? inTime(useJamQueue.getState().load()) : Promise.resolve(false)])
|
|
61
|
+
if (!alive() || comments !== true) return gaveUp()
|
|
62
|
+
// the occurrence against what was just read (open-resolve.ts): an ask with cards opens through its thread alone when
|
|
63
|
+
// the queue could not be read; review, failed and stalled stand on it
|
|
64
|
+
const found = resolveItem(p, useComments.getState().threads, queue === true ? useJamQueue.getState().cards ?? [] : null)
|
|
65
|
+
if (found === 'unread') return gaveUp()
|
|
66
|
+
if (found === 'missing') {
|
|
67
|
+
// only its board opens, when it exists - its switch under the request, as every move here
|
|
68
|
+
const exists = p.board === useStore.getState().board || !!(await inTime(fetchBoardNames()))?.includes(p.board)
|
|
69
|
+
if (exists && p.board !== useStore.getState().board && !(await toBoard(p.board, alive))) return gaveUp()
|
|
70
|
+
return 'missing'
|
|
71
|
+
}
|
|
72
|
+
return (await openTarget(p.board, found.target, alive)) ? found.result : gaveUp()
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Open a target through the one helper of its kind (jam-keys.ts), each reading `alive` before every move. */
|
|
76
|
+
function openTarget(board: string, t: Target, alive: Alive): Promise<boolean> {
|
|
77
|
+
if ('thread' in t) return openThreadAt(board, t.thread, { alive })
|
|
78
|
+
if ('tile' in t) return openTile(t.tile, { alive })
|
|
79
|
+
return openRunControls(t.controls, { alive })
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// dev-only inspection hook for tests (never installed in published builds)
|
|
83
|
+
if (typeof window !== 'undefined' && import.meta.env.DEV) (window as unknown as { __mvOpen: unknown }).__mvOpen = { openLiveItem, endOpen }
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a notice's click names, against what the page holds now (spec 28 A4.6 #30, r1 #1, r3 #2) - pure, so its rules
|
|
3
|
+
* are the package's unit cases: the occurrence compared, its state and its counter, and the target to open. A target
|
|
4
|
+
* that still stands in that state with that counter is `handled`; one in another state, or the same state with another
|
|
5
|
+
* counter (a second stall of one claim, a redelivery that failed again, a review after More work), is `stale` and opens
|
|
6
|
+
* as it stands - never another item; one gone is `missing`. A comment card the queue's view no longer holds (it keeps a
|
|
7
|
+
* finished one 60 s) is not gone while its thread stands: stale, its thread opened.
|
|
8
|
+
*/
|
|
9
|
+
import { asks, type Thread } from '../../shared/events.ts'
|
|
10
|
+
import type { OpenItem } from '../../shared/app-api.ts'
|
|
11
|
+
import type { JamCard } from './jam-queue.ts'
|
|
12
|
+
|
|
13
|
+
/** Where it opens: a thread (`openThreadAt`), a card's tile surface (`openTile`), or a run's controls (`openRunControls`). */
|
|
14
|
+
export type Target = { thread: string } | { tile: string } | { controls: JamCard }
|
|
15
|
+
/** `unread`: it stands on the queue, which was not read - nothing can be said, nothing moves. */
|
|
16
|
+
export type Resolution = { result: 'handled' | 'stale'; target: Target } | 'missing' | 'unread'
|
|
17
|
+
|
|
18
|
+
/** A card's target as it stands: a comment card's thread, else its tile's surface. */
|
|
19
|
+
const asItStands = (c: JamCard): Target => (c.kind === 'comment' && c.thread ? { thread: c.thread } : { tile: c.id })
|
|
20
|
+
|
|
21
|
+
/** `threads`: every board's, as the comments store holds them; `cards`: the queue's view read now, or null when unread. */
|
|
22
|
+
export function resolveItem(p: OpenItem, threads: readonly Thread[], cards: readonly JamCard[] | null): Resolution {
|
|
23
|
+
const threadOf = (id?: string) => (id ? threads.find((t) => t.id === id && (!t.board || t.board === p.board)) : undefined)
|
|
24
|
+
const mine = (cards ?? []).filter((c) => p.cards?.includes(c.id))
|
|
25
|
+
const viaThread = (): Resolution => { const t = threadOf(p.thread); return t ? { result: 'stale', target: { thread: t.id } } : 'missing' }
|
|
26
|
+
if (p.kind === 'ask') {
|
|
27
|
+
const t = threadOf(p.thread)
|
|
28
|
+
if (!t) return 'missing'
|
|
29
|
+
const last = t.replies.length ? t.replies[t.replies.length - 1] : t
|
|
30
|
+
const msg = last === t ? t.id : (last as Thread['replies'][number]).id
|
|
31
|
+
const now = !t.resolved && msg === p.msg && !!last.agent && asks(last, last === t)
|
|
32
|
+
// its Jam card is only a way in: read, and still asking, it opens through the card (a capture keeps its panel)
|
|
33
|
+
const card = now ? mine.find((c) => c.state === 'asks' && c.thread === t.id) : undefined
|
|
34
|
+
return { result: now ? 'handled' : 'stale', target: card ? { tile: card.id } : { thread: t.id } }
|
|
35
|
+
}
|
|
36
|
+
if (!cards) return 'unread'
|
|
37
|
+
if (p.kind === 'review') {
|
|
38
|
+
const c = mine[0]
|
|
39
|
+
if (!c) return 'missing'
|
|
40
|
+
const now = c.state === 'review' && c.batch === p.batch && (c.att ?? 0) === p.occ
|
|
41
|
+
return { result: now ? 'handled' : 'stale', target: now ? { tile: c.id } : asItStands(c) }
|
|
42
|
+
}
|
|
43
|
+
// failed: the same run failing again is another occurrence - its batch and failures, or (no run) the card's attempts;
|
|
44
|
+
// stalled: a second stall of the same claim is another
|
|
45
|
+
const now = p.kind === 'failed'
|
|
46
|
+
? mine.find((c) => c.state === 'failed' && (p.batch ? c.batch === p.batch && (c.fails ?? 0) === p.occ : (c.att ?? 0) === p.occ))
|
|
47
|
+
: mine.find((c) => c.state === 'working' && c.runner?.state === 'stalled' && c.runner.batch === p.batch && c.runner.gen === p.gen && (c.runner.stalls ?? 0) === p.occ)
|
|
48
|
+
if (now) return { result: 'handled', target: { controls: now } }
|
|
49
|
+
return mine[0] ? { result: 'stale', target: asItStands(mine[0]) } : viaThread()
|
|
50
|
+
}
|
package/src/client/shell/perf.ts
CHANGED
|
@@ -15,6 +15,12 @@ import { onMotion, type Motion } from './canvas/camera-broadcast.ts'
|
|
|
15
15
|
import { gestureOff, gestureOn } from './app-perf.ts'
|
|
16
16
|
import { recorder } from './recorder.ts'
|
|
17
17
|
import { gestureStats } from './recorder-core.ts'
|
|
18
|
+
import { canvasCtl } from './canvas/ctl.ts'
|
|
19
|
+
import { frameByWindow } from './canvas/frame-registry.ts'
|
|
20
|
+
import { currentCmd } from './commands.ts'
|
|
21
|
+
import { fullRecorder } from '../recorder-level.ts'
|
|
22
|
+
import { keepLongest, pickLoafs, type LoafEntry } from './recorder-signals-core.ts'
|
|
23
|
+
import { useStore } from './store.ts'
|
|
18
24
|
|
|
19
25
|
const LOAF = typeof PerformanceObserver !== 'undefined' && (PerformanceObserver.supportedEntryTypes ?? []).includes('long-animation-frame')
|
|
20
26
|
const frames: number[] = [] // inter-frame intervals (ms) across gestures, for report()
|
|
@@ -32,7 +38,38 @@ const enabled = (): boolean => {
|
|
|
32
38
|
} catch { return false }
|
|
33
39
|
}
|
|
34
40
|
|
|
35
|
-
interface Run {
|
|
41
|
+
interface Run {
|
|
42
|
+
t0: number; last: number; dts: number[]; pan: boolean; zoom: boolean; layout: boolean; longs: number[]; obs?: PerformanceObserver; raf: number
|
|
43
|
+
// spec 30 #34, #35: at the full level, the camera's scale over its frames, the longest frames, the command behind it
|
|
44
|
+
scale?: { from: number; to: number; min: number; max: number }; top: LoafEntry[]; by?: string
|
|
45
|
+
}
|
|
46
|
+
const FULL = fullRecorder()
|
|
47
|
+
const scaleNow = (): number | undefined => { const s = canvasCtl.transform()?.s; return typeof s === 'number' && s > 0 ? s : undefined }
|
|
48
|
+
function readScale(run: Run): void {
|
|
49
|
+
const s = FULL ? scaleNow() : undefined
|
|
50
|
+
if (s === undefined) return
|
|
51
|
+
if (!run.scale) { run.scale = { from: s, to: s, min: s, max: s }; return }
|
|
52
|
+
run.scale.to = s
|
|
53
|
+
if (s < run.scale.min) run.scale.min = s
|
|
54
|
+
if (s > run.scale.max) run.scale.max = s
|
|
55
|
+
}
|
|
56
|
+
/** What a script's path or window names (#35): a frame's module, else the frame whose document ran it. */
|
|
57
|
+
function frameOf(src: string, win: unknown): string | undefined {
|
|
58
|
+
const s = useStore.getState()
|
|
59
|
+
const byPath = src ? s.manifest?.frames.find((f) => `/${f.file}` === src)?.id : undefined
|
|
60
|
+
if (byPath) return byPath
|
|
61
|
+
const reg = frameByWindow(win)
|
|
62
|
+
return reg ? s.nodes.find((n) => n.key === reg.key)?.frame : undefined
|
|
63
|
+
}
|
|
64
|
+
const r3 = (x: number) => Math.round(x * 1000) / 1000
|
|
65
|
+
/** The command behind a layout animation (#34), read in the turn that starts it - the sampler hears of it a microtask
|
|
66
|
+
* later, from the observer, and a command's name lasts its turn - and kept only that long. */
|
|
67
|
+
let nextBy: string | undefined
|
|
68
|
+
export function noteGestureCmd(): void {
|
|
69
|
+
if (!FULL) return
|
|
70
|
+
nextBy = currentCmd()
|
|
71
|
+
if (nextBy) queueMicrotask(() => queueMicrotask(() => { nextBy = undefined }))
|
|
72
|
+
}
|
|
36
73
|
/** the gesture running now */
|
|
37
74
|
let g: Run | null = null
|
|
38
75
|
/** gestures ended so far, every one (a headless perf run waits for each of its three, spec 28 A3.8 #20) */
|
|
@@ -49,13 +86,14 @@ function note(m: Motion) {
|
|
|
49
86
|
}
|
|
50
87
|
|
|
51
88
|
function begin(m: Motion) {
|
|
52
|
-
const run: Run = { t0: performance.now(), last: 0, dts: [], pan: false, zoom: false, layout: false, longs: [], raf: 0 }
|
|
89
|
+
const run: Run = { t0: performance.now(), last: 0, dts: [], pan: false, zoom: false, layout: false, longs: [], raf: 0, top: [], ...(FULL ? { by: nextBy ?? currentCmd() } : {}) }
|
|
53
90
|
g = run
|
|
54
91
|
note(m)
|
|
92
|
+
readScale(run)
|
|
55
93
|
// the Mac app's recorder hears it start (the white-out detector's window, spec 28 A3.8 #15); nothing elsewhere
|
|
56
94
|
gestureOn(run.pan ? 'pan' : run.zoom ? 'zoom' : run.layout ? 'layout' : undefined)
|
|
57
95
|
try {
|
|
58
|
-
run.obs = new PerformanceObserver((l) => { for (const e of l.getEntries()) if (e.startTime >= run.t0) run.longs.push(e.duration) })
|
|
96
|
+
run.obs = new PerformanceObserver((l) => { for (const e of l.getEntries()) if (e.startTime >= run.t0) { run.longs.push(e.duration); if (FULL) keepLongest(run.top, e as unknown as LoafEntry) } })
|
|
59
97
|
run.obs.observe({ type: LOAF ? 'long-animation-frame' : 'longtask', buffered: false })
|
|
60
98
|
} catch { /* neither entry type (Safari): the intervals still sample */ }
|
|
61
99
|
// this gesture's own loop: a frame of an earlier one that is still queued finds another run and stops
|
|
@@ -63,6 +101,7 @@ function begin(m: Motion) {
|
|
|
63
101
|
if (g !== run) return
|
|
64
102
|
if (run.last) run.dts.push(t - run.last)
|
|
65
103
|
run.last = t
|
|
104
|
+
readScale(run)
|
|
66
105
|
run.raf = requestAnimationFrame(tick)
|
|
67
106
|
}
|
|
68
107
|
run.raf = requestAnimationFrame(tick)
|
|
@@ -74,13 +113,20 @@ function end() {
|
|
|
74
113
|
ended++
|
|
75
114
|
cancelAnimationFrame(run.raf)
|
|
76
115
|
const t1 = performance.now()
|
|
77
|
-
for (const e of run.obs?.takeRecords() ?? []) if (e.startTime >= run.t0 && e.startTime <= t1) run.longs.push(e.duration)
|
|
116
|
+
for (const e of run.obs?.takeRecords() ?? []) if (e.startTime >= run.t0 && e.startTime <= t1) { run.longs.push(e.duration); if (FULL) keepLongest(run.top, e as unknown as LoafEntry) }
|
|
78
117
|
run.obs?.disconnect()
|
|
79
118
|
gestureOff()
|
|
80
119
|
for (const d of run.dts) { frames.push(d); if (frames.length > MAX) frames.shift() }
|
|
81
120
|
for (const d of run.longs) { longs.push(d); if (longs.length > MAX) longs.shift() }
|
|
82
121
|
if (run.dts.length < 2) return // a press that never moved the camera
|
|
83
|
-
|
|
122
|
+
readScale(run)
|
|
123
|
+
const c = run.scale
|
|
124
|
+
recorder.gesture({
|
|
125
|
+
type: run.pan ? 'pan' : run.zoom ? 'zoom' : 'layout', ms: Math.round(t1 - run.t0), ...gestureStats(run.dts, run.longs.length),
|
|
126
|
+
...(c ? { scale: { from: r3(c.from), to: r3(c.to), min: r3(c.min), max: r3(c.max) } } : {}),
|
|
127
|
+
...(run.top.length ? { loaf: pickLoafs(run.top, frameOf) } : {}),
|
|
128
|
+
...(run.by ? { by: run.by } : {}),
|
|
129
|
+
})
|
|
84
130
|
}
|
|
85
131
|
|
|
86
132
|
/** One-shot event later stages record (e.g. a blank frame, or warm-promotion latency). */
|
|
@@ -3,8 +3,11 @@
|
|
|
3
3
|
* (the ready-watch.ts precedent): the bounded outbox, sizes in UTF-8 bytes, what fits a page's last keepalive send, a
|
|
4
4
|
* gesture's numbers, and a node's outcome from what its live document said.
|
|
5
5
|
*/
|
|
6
|
+
import { PAGE_KINDS } from '../../shared/perf-records.ts'
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
/** Every kind a page records: 0.29's, and spec 30's (`renders`, `warnings`, `theme`, `mode`, `hmr`, `cmd`, `self`) -
|
|
9
|
+
* one list, the server's allowlist reads it too (perf-records.ts). */
|
|
10
|
+
export const KINDS = PAGE_KINDS
|
|
8
11
|
export type Kind = typeof KINDS[number]
|
|
9
12
|
/** Every record: the workspace, this page, the load that owns the geometry ('-' before the first commit), its place
|
|
10
13
|
* in this page's order, and when it happened. */
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #30: Vite's socket lost, and the canvas back - api.ts's two hooks, in a module of their own: api.ts sits under store.ts
|
|
3
|
+
* and every stream module that reads the stores, so what it imports reaches nothing that imports it back at load.
|
|
4
|
+
* `lost` queues `hmr {phase:'lost'}` when `vite:ws:disconnect` arrives; `back` is `resume()`'s: it writes `hmr
|
|
5
|
+
* {phase:'back', downMs}` and waits at most `HMR_BACK_WAIT_MS` for it to go, before the page may reload itself. The
|
|
6
|
+
* queue's own retries apply (#7): a server down longer than they last counts `lost` in a `dropped` record, and `back`'s
|
|
7
|
+
* `downMs` still says how long.
|
|
8
|
+
*/
|
|
9
|
+
import { HMR_BACK_WAIT_MS } from '../../shared/perf-records.ts'
|
|
10
|
+
import { fullRecorder } from '../recorder-level.ts'
|
|
11
|
+
import { perfSeams } from './recorder-seams.ts'
|
|
12
|
+
|
|
13
|
+
let lostAt: number | null = null
|
|
14
|
+
|
|
15
|
+
/** `vite:ws:disconnect`. */
|
|
16
|
+
export function hmrLost(): void {
|
|
17
|
+
try {
|
|
18
|
+
if (!perfSeams.on || !fullRecorder() || lostAt !== null) return
|
|
19
|
+
lostAt = performance.now()
|
|
20
|
+
perfSeams.record('hmr', { phase: 'lost' })
|
|
21
|
+
} catch { /* never in the way */ }
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** The canvas answered again (`resume()`): says so once per loss, and waits at most a second for it to go. Nothing to
|
|
25
|
+
* wait for when the socket was never lost. */
|
|
26
|
+
export async function hmrBack(): Promise<void> {
|
|
27
|
+
try {
|
|
28
|
+
if (!perfSeams.on || lostAt === null) return
|
|
29
|
+
const downMs = Math.round(performance.now() - lostAt)
|
|
30
|
+
lostAt = null
|
|
31
|
+
perfSeams.record('hmr', { phase: 'back', downMs })
|
|
32
|
+
// the recorder's flush, late-bound: recorder.ts imports this module's importer
|
|
33
|
+
const sent = import('./recorder.ts').then((r) => r.flush()).catch(() => false)
|
|
34
|
+
await Promise.race([sent, new Promise((r) => setTimeout(r, HMR_BACK_WAIT_MS))])
|
|
35
|
+
} catch { /* never in the way */ }
|
|
36
|
+
}
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The edit's way to the frames, from the shell (spec 30 R1, R2): the reload Outbox (#16: `shell-boot`, `ready`,
|
|
3
|
+
* `settled`, `invalidated`/`invalidated-nodes`, `inplace`, `watchdog`, each with `page` and `seq`, batched to
|
|
4
|
+
* `POST perf/reload` under #7), the navigation tokens frozen at `startReload` (#14), the in-place reports
|
|
5
|
+
* (`sh:inplace`, #15), the board writes' `x-mv-page`/`x-mv-cmds` headers (#18, `perfSeams.requestHeaders`) and the
|
|
6
|
+
* watchdog's lines (#20). Owner: the edits stream.
|
|
7
|
+
*
|
|
8
|
+
* recorder.ts calls `startReloads()` once, at the full level only, after the page recorder is on. Until then every hook
|
|
9
|
+
* here does nothing, and a reload line goes as 0.29's did (store.ts `reloadHooks`). It subscribes through
|
|
10
|
+
* recorder-seams.ts and never imports recorder.ts.
|
|
11
|
+
*/
|
|
12
|
+
import { encodeCmds, RELOAD_BOUNDS, RELOAD_OUTBOX, WRITER_HEADERS, type HeldBy } from '../../shared/perf-records.ts'
|
|
13
|
+
import { WATCH_MAX_MS } from '../../shared/app-api.ts'
|
|
14
|
+
import { SH } from '../frame-host/messages.ts'
|
|
15
|
+
import { api, isStopped, resumed } from './api.ts'
|
|
16
|
+
import { watchWindow } from './app-perf.ts'
|
|
17
|
+
import { bootOf, iframeOf } from './canvas/frame-registry.ts'
|
|
18
|
+
import { isAsleep } from './canvas/sleep.ts'
|
|
19
|
+
import { heldBy } from './canvas/updates.ts'
|
|
20
|
+
import { cmdsForWrite } from './commands.ts'
|
|
21
|
+
import { PERF_RUN } from './perf-run.ts'
|
|
22
|
+
import { bound, fitWithin, Outbox, type PerfRecord } from './recorder-core.ts'
|
|
23
|
+
import { PAGE_ID, perfSeams } from './recorder-seams.ts'
|
|
24
|
+
import { logReload, reloadHooks, reloadLine, useStore } from './store.ts'
|
|
25
|
+
|
|
26
|
+
let on = false
|
|
27
|
+
const nodeOf = (key: string) => useStore.getState().nodes.find((n) => n.key === key)
|
|
28
|
+
/** Never in the way (#5), and nothing until started. */
|
|
29
|
+
const guard = <A extends unknown[]>(fn: (...a: A) => void) => (...a: A): void => { if (!on) return; try { fn(...a) } catch { /* never in the way */ } }
|
|
30
|
+
const chunk = <T>(list: readonly T[], n: number): T[][] => Array.from({ length: Math.ceil(list.length / n) }, (_, i) => list.slice(i * n, (i + 1) * n))
|
|
31
|
+
|
|
32
|
+
// ---- #14: attribution frozen per navigation ---------------------------------------------------------------------
|
|
33
|
+
|
|
34
|
+
/** A node's revisions waiting for a navigation: all of them go with the next one (coalesced). `asleep`: as the first of
|
|
35
|
+
* them arrived - going stale wakes a node (FrameNode's sleep effect), so by its `startReload` it is always awake. */
|
|
36
|
+
interface Pending { revisions: string[]; arrivedAt: number; asleep: boolean; heldBy?: HeldBy }
|
|
37
|
+
/** One navigation of a node, frozen as it starts: what arrives after this belongs to the next. */
|
|
38
|
+
interface NavToken extends Pending { nav: number; startedAt: number; release: () => void }
|
|
39
|
+
|
|
40
|
+
const pending = new Map<string, Pending>()
|
|
41
|
+
const tokens = new Map<string, NavToken>()
|
|
42
|
+
/** each live document's id -> the node's navigation when it booted: a document is told by itself, not by the node's nav
|
|
43
|
+
* now (a job may have moved it on, its document not there yet) */
|
|
44
|
+
const docNav = new Map<string, number>()
|
|
45
|
+
|
|
46
|
+
// #38: `reload`, an on-screen job's `startReload` to its ready. One window however many jobs run; a job that never comes
|
|
47
|
+
// to its ready (the watchdog gave up, the node left) lets go at the app's own end for a window.
|
|
48
|
+
let watching = 0
|
|
49
|
+
function holdWatch(): () => void {
|
|
50
|
+
if (watching++ === 0) watchWindow('reload', true)
|
|
51
|
+
let held = true
|
|
52
|
+
const t = setTimeout(() => release(), WATCH_MAX_MS)
|
|
53
|
+
const release = () => {
|
|
54
|
+
if (!held) return
|
|
55
|
+
held = false
|
|
56
|
+
clearTimeout(t)
|
|
57
|
+
if (--watching === 0) watchWindow('reload', false)
|
|
58
|
+
}
|
|
59
|
+
return release
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** #13: counted over the board's nodes - one frame may have several, or none. */
|
|
63
|
+
function invalidated(frames: ReadonlySet<string>, revision: string): void {
|
|
64
|
+
const s = useStore.getState()
|
|
65
|
+
const nodes = s.nodes.filter((n) => frames.has(n.frame))
|
|
66
|
+
const now = performance.now()
|
|
67
|
+
const held: Partial<Record<HeldBy, number>> = {}
|
|
68
|
+
let asleep = 0, awake = 0
|
|
69
|
+
for (const n of nodes) {
|
|
70
|
+
const why = heldBy(n, s)
|
|
71
|
+
if (why) held[why] = (held[why] ?? 0) + 1
|
|
72
|
+
if (isAsleep(n.key)) asleep++
|
|
73
|
+
else if (!n.missing) awake++
|
|
74
|
+
if (n.missing) continue // it never goes stale: no navigation will carry this for it
|
|
75
|
+
const p = pending.get(n.key)
|
|
76
|
+
if (!p) pending.set(n.key, { revisions: [revision], arrivedAt: now, asleep: isAsleep(n.key) })
|
|
77
|
+
else if (!p.revisions.includes(revision)) {
|
|
78
|
+
p.revisions.push(revision)
|
|
79
|
+
if (p.revisions.length > RELOAD_BOUNDS.idsPerLine) p.revisions.shift()
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const shown = new Set(nodes.map((n) => n.frame))
|
|
83
|
+
const parts = chunk(nodes.map((n) => n.key), RELOAD_BOUNDS.idsPerLine)
|
|
84
|
+
logReload({ kind: 'invalidated', revision, asked: frames.size, offBoard: [...frames].filter((f) => !shown.has(f)).length, onBoard: nodes.length, awake, asleep, held, ...(parts.length ? { parts: parts.length } : {}) })
|
|
85
|
+
parts.forEach((p, i) => logReload({ kind: 'invalidated-nodes', revision, part: i + 1, parts: parts.length, nodes: p }))
|
|
86
|
+
// a node gone from the board keeps nothing here: no ready will come for it
|
|
87
|
+
const keys = new Set(s.nodes.map((n) => n.key))
|
|
88
|
+
for (const k of pending.keys()) if (!keys.has(k)) pending.delete(k)
|
|
89
|
+
for (const [k, t] of tokens) if (!keys.has(k)) { t.release(); tokens.delete(k) }
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** The first reason the queue refused a node, for the navigation that will carry its revisions. */
|
|
93
|
+
function held(key: string, why: HeldBy): void {
|
|
94
|
+
const p = pending.get(key)
|
|
95
|
+
if (p) p.heldBy ??= why
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** `startReload`: this navigation's token. A revision arriving from here on is the next navigation's. */
|
|
99
|
+
function started(key: string, nav: number): void {
|
|
100
|
+
const p = pending.get(key)
|
|
101
|
+
pending.delete(key)
|
|
102
|
+
tokens.get(key)?.release()
|
|
103
|
+
tokens.set(key, { revisions: p?.revisions ?? [], arrivedAt: p?.arrivedAt ?? performance.now(), asleep: p?.asleep ?? isAsleep(key), heldBy: p?.heldBy, nav, startedAt: performance.now(), release: holdWatch() })
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* sh:ready, from the live document (App.tsx's `fromLiveDocument`), before `setStatus` pumps the next job and `setShown`
|
|
108
|
+
* moves its wait: the token of the navigation this document belongs to, as the `ready` line's fields. A document with no
|
|
109
|
+
* token - a first load, a reload by hand, a self reload - has none.
|
|
110
|
+
*/
|
|
111
|
+
export function takeNavToken(key: string, data: { boot?: unknown }): Record<string, unknown> | undefined {
|
|
112
|
+
if (!on) return undefined
|
|
113
|
+
try {
|
|
114
|
+
const n = nodeOf(key)
|
|
115
|
+
if (!n) return undefined
|
|
116
|
+
const boot = typeof data.boot === 'string' ? data.boot : ''
|
|
117
|
+
const nav = docNav.get(boot) ?? n.nav ?? 0
|
|
118
|
+
docNav.delete(boot)
|
|
119
|
+
// what setShown decides next: a document that already shows a revision that waited needs no navigation for it
|
|
120
|
+
queueMicrotask(() => { if (!nodeOf(key)?.stale) pending.delete(key) })
|
|
121
|
+
const t = tokens.get(key)
|
|
122
|
+
if (!t || t.nav !== nav) return undefined
|
|
123
|
+
tokens.delete(key)
|
|
124
|
+
t.release()
|
|
125
|
+
return { revisions: t.revisions, queuedMs: Math.round(t.startedAt - t.arrivedAt), bootMs: Math.round(performance.now() - t.startedAt), ...(t.heldBy ? { heldBy: t.heldBy } : {}), ...(t.asleep ? { asleep: true } : {}) }
|
|
126
|
+
} catch { return undefined }
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// ---- messages from the documents --------------------------------------------------------------------------------
|
|
130
|
+
|
|
131
|
+
function onFrameMessage(key: string, data: Record<string, unknown>): void {
|
|
132
|
+
if (data.type === 'sh:boot' && typeof data.boot === 'string') {
|
|
133
|
+
const n = nodeOf(key)
|
|
134
|
+
if (!n) return
|
|
135
|
+
docNav.set(data.boot, n.nav ?? 0)
|
|
136
|
+
if (docNav.size > 1_024) docNav.delete(docNav.keys().next().value!)
|
|
137
|
+
} else if (data.type === SH.inplace) {
|
|
138
|
+
// #15: from the document there now; what it saw, no more
|
|
139
|
+
if (typeof data.boot !== 'string' || data.boot !== bootOf(iframeOf(key))) return
|
|
140
|
+
const n = nodeOf(key)
|
|
141
|
+
if (!n) return
|
|
142
|
+
logReload({ kind: 'inplace', node: key, frame: n.frame, hmrTs: data.hmrTs, fetched: true, applyMs: data.applyMs, nextObservedCommitMs: data.nextObservedCommitMs, applied: data.applied === false ? false : 'unknown', ...(data.noAfterUpdate === true ? { noAfterUpdate: true } : {}) })
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** #20: the watchdog's silence, before it acts. */
|
|
147
|
+
export const watchdogLine = guard((key: string, action: 'retry' | 'gave-up') => {
|
|
148
|
+
const n = nodeOf(key)
|
|
149
|
+
if (n) logReload({ kind: 'watchdog', node: key, frame: n.frame, nav: n.nav ?? 0, action })
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
// ---- #18: a board write names its page and its commands ----------------------------------------------------------
|
|
153
|
+
|
|
154
|
+
const BOARD_WRITE = /\/api\/(boards\/[^?#]+)/
|
|
155
|
+
const NOT_A_BOARD = new Set(['pin', 'status', 'rename', 'reorder'])
|
|
156
|
+
function writeHeaders(url: string, init: RequestInit): Record<string, string> | undefined {
|
|
157
|
+
if (!init.method || init.method === 'GET') return undefined
|
|
158
|
+
const route = BOARD_WRITE.exec(url)?.[1]
|
|
159
|
+
if (!route) return undefined
|
|
160
|
+
// the board, when the path names it - a body is never read (#4)
|
|
161
|
+
const name = route.slice('boards/'.length)
|
|
162
|
+
return { [WRITER_HEADERS.page]: PAGE_ID, [WRITER_HEADERS.cmds]: encodeCmds(cmdsForWrite(NOT_A_BOARD.has(name) ? '' : decodeURIComponent(name), route)) }
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// ---- #16, #7: the reload Outbox ----------------------------------------------------------------------------------
|
|
166
|
+
|
|
167
|
+
const outbox = new Outbox(RELOAD_OUTBOX.max, RELOAD_OUTBOX.bytes)
|
|
168
|
+
let inFlight: PerfRecord[] = []
|
|
169
|
+
let sendTimer: ReturnType<typeof setTimeout> | undefined
|
|
170
|
+
let sending = false
|
|
171
|
+
|
|
172
|
+
const csrf = () => /(?:^|;\s*)mv_c=([\w-]+)/.exec(document.cookie)?.[1] ?? ''
|
|
173
|
+
const post = (records: PerfRecord[], keepalive = false) => api('perf/reload', {
|
|
174
|
+
method: 'POST',
|
|
175
|
+
headers: { 'content-type': 'application/json', 'x-mv-c': csrf() },
|
|
176
|
+
body: JSON.stringify({ records }),
|
|
177
|
+
...(keepalive ? { keepalive: true } : {}),
|
|
178
|
+
})
|
|
179
|
+
const wait = (ms: number) => new Promise<void>((r) => setTimeout(r, ms))
|
|
180
|
+
const armSend = () => { if (!sending && sendTimer === undefined && outbox.size) sendTimer = setTimeout(() => { sendTimer = undefined; void send() }, RELOAD_OUTBOX.sendMs) }
|
|
181
|
+
/** The `dropped` line that says how many went, when any did (the count starts over): R13's, a line like the others. */
|
|
182
|
+
const droppedNow = (more = 0): PerfRecord[] => {
|
|
183
|
+
const n = outbox.dropped + more
|
|
184
|
+
outbox.dropped = 0
|
|
185
|
+
return n ? [reloadLine({ kind: 'dropped', n }) as PerfRecord] : []
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** As the page recorder's `send` (recorder.ts), under #7: a network failure or a server error is tried twice more, 2 s
|
|
189
|
+
* apart - the server answers only after its append returned, 503 when it failed; a 403 primes the request cookie once;
|
|
190
|
+
* any other refusal is final. What never lands is counted. */
|
|
191
|
+
async function send(): Promise<void> {
|
|
192
|
+
clearTimeout(sendTimer)
|
|
193
|
+
sendTimer = undefined
|
|
194
|
+
if (!on || sending || !outbox.size) return
|
|
195
|
+
// a headless run's documents are not this log's (its barrier refuses the route)
|
|
196
|
+
if (PERF_RUN) { outbox.takeAll(); outbox.dropped = 0; return }
|
|
197
|
+
sending = true
|
|
198
|
+
let batch: PerfRecord[] = []
|
|
199
|
+
let ok = false
|
|
200
|
+
try {
|
|
201
|
+
batch = [...droppedNow(), ...outbox.takeAll()]
|
|
202
|
+
inFlight = batch
|
|
203
|
+
for (let attempt = 0; attempt < 3 && !ok; attempt++) {
|
|
204
|
+
if (attempt) await wait(RELOAD_OUTBOX.sendMs)
|
|
205
|
+
try {
|
|
206
|
+
let r = await post(batch)
|
|
207
|
+
if (r.status === 403) { await api('work').catch(() => {}); r = await post(batch) }
|
|
208
|
+
if (r.ok) ok = true
|
|
209
|
+
else if (r.status < 500 || isStopped(r)) break
|
|
210
|
+
} catch { /* the network: again */ }
|
|
211
|
+
}
|
|
212
|
+
} catch { /* never in the way: what it held is counted below */ }
|
|
213
|
+
if (!ok) outbox.dropped += batch.reduce((n, r) => n + (r.kind === 'dropped' ? (r.n as number) : 1), 0)
|
|
214
|
+
inFlight = []
|
|
215
|
+
sending = false
|
|
216
|
+
armSend()
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/** The page is going (recorder.ts, after its own last records, only when no capture holds the allowance): this log's
|
|
220
|
+
* share of the keepalive, what does not fit counted in the last line that does. */
|
|
221
|
+
function leave(): void {
|
|
222
|
+
clearTimeout(sendTimer)
|
|
223
|
+
sendTimer = undefined
|
|
224
|
+
if (PERF_RUN) return
|
|
225
|
+
const all = [...inFlight, ...outbox.takeAll()]
|
|
226
|
+
if (!all.length && !outbox.dropped) return
|
|
227
|
+
const { fit, lost } = fitWithin([], all, RELOAD_OUTBOX.keepaliveBytes)
|
|
228
|
+
try { void post([...fit, ...droppedNow(lost)], true).catch(() => {}) } catch { /* going anyway */ }
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/** The page that left this tab for good, in the tab's own storage until the next page there names it (#48). A page writes
|
|
232
|
+
* it only as it ends: a duplicated tab copies this storage from a live page, which has written nothing, so a copy can
|
|
233
|
+
* never say its original ended. A crash writes nothing either: the app's `gone`, or nothing at all. */
|
|
234
|
+
const LEFT_TAB = 'mv-page-left'
|
|
235
|
+
/** A line, as `logReload` built it. `shell-boot` adds what only the page knows (#16). */
|
|
236
|
+
function take(line: Record<string, unknown>): void {
|
|
237
|
+
if (line.kind === 'shell-boot') {
|
|
238
|
+
const nav = (performance.getEntriesByType('navigation')[0] as PerformanceNavigationTiming | undefined)?.type
|
|
239
|
+
if (nav) line.nav = bound(nav, 16)
|
|
240
|
+
if (resumed) line.resumed = true
|
|
241
|
+
try {
|
|
242
|
+
const prev = sessionStorage.getItem(LEFT_TAB)
|
|
243
|
+
if (prev) { line.prev = prev; sessionStorage.removeItem(LEFT_TAB) }
|
|
244
|
+
} catch { /* storage off: no evidence, and the reader says so */ }
|
|
245
|
+
}
|
|
246
|
+
outbox.push(line as PerfRecord)
|
|
247
|
+
armSend()
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/** recorder.ts `startRecorder`, at the full level: the reload Outbox and its listeners. */
|
|
251
|
+
export function startReloads(): void {
|
|
252
|
+
if (on) return
|
|
253
|
+
on = true
|
|
254
|
+
reloadHooks.line = guard(take)
|
|
255
|
+
reloadHooks.invalidated = guard(invalidated)
|
|
256
|
+
reloadHooks.started = guard(started)
|
|
257
|
+
reloadHooks.held = guard(held)
|
|
258
|
+
perfSeams.requestHeaders = (url, init) => { try { return writeHeaders(url, init) } catch { return undefined } }
|
|
259
|
+
// kept for back and forward (`persisted`), this page may yet come back: it has not ended
|
|
260
|
+
addEventListener('pagehide', (e) => { if (!e.persisted) { try { sessionStorage.setItem(LEFT_TAB, PAGE_ID) } catch { /* storage off */ } } })
|
|
261
|
+
perfSeams.frameMessage.on(guard(onFrameMessage))
|
|
262
|
+
perfSeams.leaving.on(guard(leave))
|
|
263
|
+
document.addEventListener('visibilitychange', guard(() => { if (document.visibilityState === 'hidden') void send() }))
|
|
264
|
+
}
|