@marver-design/marver 0.26.0 → 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 +158 -0
- package/README.md +10 -5
- package/dist/{anchor-check-Dg5xpNnU.mjs → anchor-check-ChdDqL5z.mjs} +1 -1
- package/dist/{audio-CmSRYFEs.mjs → audio-Dw1lfMdb.mjs} +14 -0
- package/dist/{bake-DtVlm0_F.mjs → bake-DM_uWgAA.mjs} +1 -1
- package/dist/{boards-DYG22tOe.mjs → boards-DlTcpF47.mjs} +1 -1
- package/dist/{build-C_gUgcdC.mjs → build-DZnFysGU.mjs} +4 -4
- package/dist/{capture-CrqvU_jh.mjs → capture-vadKjuCo.mjs} +2 -1
- package/dist/cli.mjs +28 -16
- package/dist/{comments-BqXua-XL.mjs → comments-DxOkCSNE.mjs} +4 -4
- package/dist/{daemon-DZo6o3rU.mjs → daemon-BSA0lV8d.mjs} +400 -274
- 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-NQi0wZJ4.mjs → marks-CWM3WJjc.mjs} +1 -1
- package/dist/perf-BWzQwZqj.mjs +369 -0
- package/dist/perf-BoDSkbEb.mjs +429 -0
- package/dist/perf-jam-D55U3FZK.mjs +242 -0
- package/dist/{plugin-CTD0rydA.mjs → plugin-C-E7omsh.mjs} +425 -66
- package/dist/{poster-ChjXGTS5.mjs → poster-Bx83ZYVK.mjs} +2 -1
- package/dist/{profile-WU9qcbIo.mjs → profile-Bh5Y5zpW.mjs} +1 -1
- package/dist/{publish-bakes-CEP_2NRc.mjs → publish-bakes-aljgm45S.mjs} +2 -2
- package/dist/{queue-BuiCKSX1.mjs → queue-CAM_vNmX.mjs} +3 -3
- package/dist/recover-t9Pno3u9.mjs +66 -0
- package/dist/{session-qZWKt_VA.mjs → session-BAaJsK5c.mjs} +1 -1
- package/dist/{share--oFJ1bCI.mjs → share-W5H3BNvP.mjs} +1 -1
- package/dist/shot-DoHLl6ig.mjs +139 -0
- package/dist/{shot-DqcxJibP.mjs → shot-LFhC-WYD.mjs} +343 -19
- package/dist/slots-DCDo3N0x.mjs +471 -0
- package/dist/speech-worker.mjs +40 -5
- 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 +78 -7
- package/docs/live-jam.md +8 -0
- 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/inspect.js +8 -3
- package/src/client/frame-host/keys.js +6 -2
- package/src/client/frame-host/main.tsx +17 -5
- package/src/client/shell/App.tsx +188 -29
- package/src/client/shell/BoardList.tsx +5 -5
- package/src/client/shell/Comments.tsx +3 -2
- package/src/client/shell/JamSurface.tsx +13 -5
- package/src/client/shell/LockedApp.tsx +5 -5
- package/src/client/shell/Play.tsx +27 -15
- package/src/client/shell/Toolbar.tsx +17 -5
- package/src/client/shell/api.ts +206 -0
- package/src/client/shell/canvas/Canvas.tsx +30 -3
- package/src/client/shell/canvas/FrameNode.tsx +15 -5
- 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/icons.tsx +2 -0
- package/src/client/shell/jam-capture.ts +96 -16
- package/src/client/shell/jam-keys.ts +51 -18
- package/src/client/shell/jam-lane.tsx +46 -5
- package/src/client/shell/jam-panel.tsx +66 -13
- package/src/client/shell/jam-queue.ts +3 -3
- package/src/client/shell/jam-session.tsx +14 -8
- package/src/client/shell/jam-state.ts +48 -6
- package/src/client/shell/jam-surface-parts.tsx +10 -6
- 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 +268 -103
- package/src/client/shell/styles.css +54 -9
- package/src/client/stage/main.tsx +2 -0
- 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/jam.md +5 -3
- package/templates/instructions/welcome.md +6 -3
- package/dist/config-Cf7EjAMf.mjs +0 -292
- package/dist/dev-_Nlsc6v9.mjs +0 -742
- package/dist/dev-lock-DWSpa6nj.mjs +0 -179
- package/dist/perf-D6VmmJ2q.mjs +0 -68
- package/dist/perf-DPbLGhhO.mjs +0 -49
- package/dist/shot-CNbHoZ6H.mjs +0 -86
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
|
}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The recorder's pure parts (spec 28 A1.7), kept apart from the browser-coupled store so they can be unit-tested
|
|
3
|
+
* (the ready-watch.ts precedent): the bounded outbox, sizes in UTF-8 bytes, what fits a page's last keepalive send, a
|
|
4
|
+
* gesture's numbers, and a node's outcome from what its live document said.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export const KINDS = ['load', 'commit', 'visible', 'frame', 'move', 'quiet', 'settled', 'cut', 'gesture', 'error', 'dropped'] as const
|
|
8
|
+
export type Kind = typeof KINDS[number]
|
|
9
|
+
/** Every record: the workspace, this page, the load that owns the geometry ('-' before the first commit), its place
|
|
10
|
+
* in this page's order, and when it happened. */
|
|
11
|
+
export interface Envelope { v: 1; ws: string; page: string; load: string; seq: number; ts: number; kind: Kind }
|
|
12
|
+
export type PerfRecord = Envelope & Record<string, unknown>
|
|
13
|
+
|
|
14
|
+
/** The queue's bounds: past either, the oldest go and are counted. */
|
|
15
|
+
export const QUEUE_MAX = 2_000, QUEUE_BYTES = 256 * 1024
|
|
16
|
+
/** A page that is going sends at most this much with keepalive: the rest of the 64 KB allowance is the captures'. */
|
|
17
|
+
export const KEEPALIVE_BYTES = 16 * 1024
|
|
18
|
+
/** Records wait this long for company before a send; a failed send waits this long before it tries again. */
|
|
19
|
+
export const SEND_MS = 2_000
|
|
20
|
+
/** A board is quiet after this long without a move. */
|
|
21
|
+
export const QUIET_MS = 1_000
|
|
22
|
+
/** A load not settled by then is cut. */
|
|
23
|
+
export const LOAD_MAX_MS = 120_000
|
|
24
|
+
|
|
25
|
+
const enc = new TextEncoder()
|
|
26
|
+
/** Size in UTF-8 bytes, as the request body will carry it - not `.length`, which counts UTF-16 units. */
|
|
27
|
+
export const bytesOf = (x: unknown): number => enc.encode(typeof x === 'string' ? x : JSON.stringify(x)).length
|
|
28
|
+
|
|
29
|
+
/** Records waiting to be sent, oldest first. Past `max` records or `maxBytes` the oldest go, counted in `dropped`
|
|
30
|
+
* (the recorder sends that count in a `dropped` record and zeroes it). */
|
|
31
|
+
export class Outbox {
|
|
32
|
+
private items: { rec: PerfRecord; bytes: number }[] = []
|
|
33
|
+
private waiting = new Set<PerfRecord>()
|
|
34
|
+
bytes = 0
|
|
35
|
+
dropped = 0
|
|
36
|
+
constructor(private max = QUEUE_MAX, private maxBytes = QUEUE_BYTES) {}
|
|
37
|
+
get size(): number { return this.items.length }
|
|
38
|
+
push(rec: PerfRecord): void {
|
|
39
|
+
const bytes = bytesOf(rec)
|
|
40
|
+
this.items.push({ rec, bytes })
|
|
41
|
+
this.waiting.add(rec)
|
|
42
|
+
this.bytes += bytes
|
|
43
|
+
this.trim()
|
|
44
|
+
}
|
|
45
|
+
/** A waiting record changed in place (a coalesced move): its size again. */
|
|
46
|
+
touch(rec: PerfRecord): void {
|
|
47
|
+
for (let i = this.items.length - 1; i >= 0; i--) {
|
|
48
|
+
const it = this.items[i]
|
|
49
|
+
if (it.rec !== rec) continue
|
|
50
|
+
const bytes = bytesOf(rec)
|
|
51
|
+
this.bytes += bytes - it.bytes
|
|
52
|
+
it.bytes = bytes
|
|
53
|
+
this.trim()
|
|
54
|
+
return
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/** Still waiting (not sent, not dropped)? */
|
|
58
|
+
has(rec: PerfRecord): boolean { return this.waiting.has(rec) }
|
|
59
|
+
/** Everything waiting, oldest first; the outbox is empty after. */
|
|
60
|
+
takeAll(): PerfRecord[] {
|
|
61
|
+
const out = this.items.map((it) => it.rec)
|
|
62
|
+
this.items = []
|
|
63
|
+
this.waiting.clear()
|
|
64
|
+
this.bytes = 0
|
|
65
|
+
return out
|
|
66
|
+
}
|
|
67
|
+
private trim(): void {
|
|
68
|
+
while (this.items.length && (this.items.length > this.max || this.bytes > this.maxBytes)) {
|
|
69
|
+
const it = this.items.shift()!
|
|
70
|
+
this.waiting.delete(it.rec)
|
|
71
|
+
this.bytes -= it.bytes
|
|
72
|
+
// a `dropped` record that goes takes what it counted with it
|
|
73
|
+
this.dropped += it.rec.kind === 'dropped' && typeof it.rec.n === 'number' ? it.rec.n : 1
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** For a page that is going: as many of `first` (the cuts) as fit, in their order, then the oldest of `rest`, while
|
|
79
|
+
* the whole body `{"records":[…]}` stays within `maxBytes` with `reserve` left for a `dropped` record - the limit
|
|
80
|
+
* holds for the cuts too, however many a stalled send left waiting. The others, cuts included, are `lost`. */
|
|
81
|
+
export function fitWithin(first: readonly PerfRecord[], rest: readonly PerfRecord[], maxBytes = KEEPALIVE_BYTES, reserve = 160): { fit: PerfRecord[]; lost: number } {
|
|
82
|
+
const fit: PerfRecord[] = []
|
|
83
|
+
let size = bytesOf({ records: [] }) + reserve
|
|
84
|
+
const take = (r: PerfRecord) => {
|
|
85
|
+
const add = bytesOf(r) + (fit.length ? 1 : 0)
|
|
86
|
+
if (size + add > maxBytes) return false
|
|
87
|
+
size += add
|
|
88
|
+
fit.push(r)
|
|
89
|
+
return true
|
|
90
|
+
}
|
|
91
|
+
let lost = 0
|
|
92
|
+
for (const r of first) if (!take(r)) lost++
|
|
93
|
+
for (let i = 0; i < rest.length; i++) if (!take(rest[i])) { lost += rest.length - i; break }
|
|
94
|
+
return { fit, lost }
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** A gesture's frame intervals as they are: nearest-rank percentiles (cli/perf.ts `spread`'s rule), one decimal; the
|
|
98
|
+
* counts over 17 ms and over 33 ms; `longFrames` as given. */
|
|
99
|
+
export function gestureStats(dts: readonly number[], longFrames: number): { frames: number; p50: number; p95: number; max: number; over17ms: number; over33ms: number; longFrames: number } {
|
|
100
|
+
const v = [...dts].sort((a, b) => a - b)
|
|
101
|
+
const at = (q: number) => (v.length ? v[Math.min(v.length - 1, Math.ceil(q * v.length) - 1)] : 0)
|
|
102
|
+
const r = (x: number) => Math.round(x * 10) / 10
|
|
103
|
+
return {
|
|
104
|
+
frames: v.length, p50: r(at(0.5)), p95: r(at(0.95)), max: r(v[v.length - 1] ?? 0),
|
|
105
|
+
over17ms: v.filter((d) => d > 17).length, over33ms: v.filter((d) => d > 33).length, longFrames,
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** What a node of a load waits for: a settled measure at its width, its ready, or nothing (missing). */
|
|
110
|
+
export type Rule = 'measure' | 'ready' | 'missing'
|
|
111
|
+
export type Outcome = 'settled' | 'ready' | 'missing' | 'error' | 'never-ready'
|
|
112
|
+
/** One node's story, as its live document told it (page-level, by node key: a reload of the same board keeps the
|
|
113
|
+
* documents, and their facts carry over). Times are performance.now(). */
|
|
114
|
+
export interface Track {
|
|
115
|
+
frame: string
|
|
116
|
+
/** the document these facts belong to */
|
|
117
|
+
boot?: string
|
|
118
|
+
/** that document's URL revision (its own `r`), and the node's navigation when it was adopted */
|
|
119
|
+
gen?: string
|
|
120
|
+
nav?: number
|
|
121
|
+
/** when the node's mount was admitted - not per document (a reload keeps its slot) */
|
|
122
|
+
admittedAt?: number
|
|
123
|
+
readyAt?: number
|
|
124
|
+
firstMeasureAt?: number
|
|
125
|
+
/** a settled report the store took at this width */
|
|
126
|
+
settled?: { at: number; w: number }
|
|
127
|
+
errorAt?: number
|
|
128
|
+
/** the watchdog's second silence, for this navigation */
|
|
129
|
+
neverReady?: { at: number; nav: number }
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** A message from document `boot`: kept only when that document is the one there now. A new live document starts
|
|
133
|
+
* the node's story over - noting its own URL revision (`gen`, from the message) and the node's navigation (`nav`) -
|
|
134
|
+
* and a message from a live document supersedes the watchdog's verdict. */
|
|
135
|
+
export function adopt(t: Track, boot: unknown, live: string | undefined, doc?: { gen?: unknown; nav?: number }): boolean {
|
|
136
|
+
if (typeof boot !== 'string' || !boot || boot !== live) return false
|
|
137
|
+
if (t.boot !== boot) {
|
|
138
|
+
t.boot = boot
|
|
139
|
+
delete t.gen; delete t.nav; delete t.readyAt; delete t.firstMeasureAt; delete t.settled; delete t.errorAt
|
|
140
|
+
if (doc) t.nav = doc.nav ?? 0
|
|
141
|
+
}
|
|
142
|
+
if (typeof doc?.gen === 'string') t.gen = doc.gen
|
|
143
|
+
delete t.neverReady
|
|
144
|
+
return true
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** The node's outcome now, or null (pending). An outcome a document reported counts only while that document is the
|
|
148
|
+
* live one, on the navigation the shell asked for last - a document since replaced, one still booting (no live boot
|
|
149
|
+
* yet), or one a reload is replacing (the node's `nav` moved on, or its iframe was sent to another revision `gen`,
|
|
150
|
+
* while the old document is still there until the new one commits) sends it back to pending.
|
|
151
|
+
* `missing` and `never-ready` have no document and are exempt: missing while the frame is absent from the manifest,
|
|
152
|
+
* never-ready for the navigation the watchdog gave up on, until a new navigation or a live message replaces it. */
|
|
153
|
+
export function outcomeOf(rule: Rule, t: Track | undefined, live: string | undefined, node: { w: number; nav?: number; gen?: string }): Outcome | null {
|
|
154
|
+
if (rule === 'missing') return 'missing'
|
|
155
|
+
if (!t) return null
|
|
156
|
+
const current = !!live && t.boot === live
|
|
157
|
+
&& (t.nav === undefined || t.nav === (node.nav ?? 0))
|
|
158
|
+
&& (t.gen === undefined || node.gen === undefined || t.gen === node.gen)
|
|
159
|
+
if (current && t.errorAt !== undefined) return 'error'
|
|
160
|
+
if (current && rule === 'ready' && t.readyAt !== undefined) return 'ready'
|
|
161
|
+
if (current && rule === 'measure' && t.settled && t.settled.w === Math.round(node.w)) return 'settled'
|
|
162
|
+
if (t.neverReady && t.neverReady.nav === (node.nav ?? 0)) return 'never-ready'
|
|
163
|
+
return null
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** The first three stack lines of an error - Chrome's " at …", else Safari's and Firefox's "fn@url:line:col" -
|
|
167
|
+
* each 200 characters at most. */
|
|
168
|
+
export function stackLines(stack: unknown): string[] | undefined {
|
|
169
|
+
if (typeof stack !== 'string' || !stack) return undefined
|
|
170
|
+
const lines = stack.split('\n')
|
|
171
|
+
const chrome = lines.filter((l) => /^\s*at /.test(l))
|
|
172
|
+
const picked = chrome.length ? chrome : lines.filter((l) => /@.*:\d+(:\d+)?$/.test(l.trim()))
|
|
173
|
+
const out = picked.slice(0, 3).map((l) => l.trim().slice(0, 200)).filter(Boolean)
|
|
174
|
+
return out.length ? out : undefined
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** A string bounded to `n` characters, or undefined. */
|
|
178
|
+
export const bound = (v: unknown, n = 200): string | undefined => (typeof v === 'string' && v ? v.slice(0, n) : undefined)
|
|
179
|
+
|
|
180
|
+
/** 12 hex characters: a page, a load or a document id. */
|
|
181
|
+
export function newId(): string {
|
|
182
|
+
return Array.from(crypto.getRandomValues(new Uint8Array(6)), (b) => b.toString(16).padStart(2, '0')).join('')
|
|
183
|
+
}
|