@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,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The messages spec 30 adds or extends between the shell and its documents - canvas frames (bridge.js, inspect.js,
|
|
3
|
+
* main.tsx) and the play stage (stage/main.tsx) - beside the ones they already exchange. Types and constants only.
|
|
4
|
+
* Every field spec 30 adds to an existing message is optional: an older document, a document of another level
|
|
5
|
+
* (`core`) or a document whose bridge has not run yet sends none, and the shell then counts nothing for it.
|
|
6
|
+
*
|
|
7
|
+
* bridge.js and inspect.js are plain JS that ship verbatim (build.ts copies them for published HTML frames): they
|
|
8
|
+
* post these shapes by hand and repeat `ERROR_BUDGET.frame` (perf-records.ts) inline. A new module either imports
|
|
9
|
+
* must be added to build.ts's copy list, or every published HTML frame stops.
|
|
10
|
+
*
|
|
11
|
+
* FROZEN before the spec 30 streams split. Owners: signals (theme and mode acks, `sh:gesture`, `sh:console`,
|
|
12
|
+
* `sh:resource-error`, `sh:dropped`, `sh:warnings`, `sh:renders`), edits (`sh:inplace`), commands (`sh:stage-key`'s `origin`).
|
|
13
|
+
*/
|
|
14
|
+
import type { ResourceTag } from '../../shared/perf-records.ts'
|
|
15
|
+
|
|
16
|
+
/** The names, one place. The first block is new; the second extends existing messages. */
|
|
17
|
+
export const SH = {
|
|
18
|
+
modeApplied: 'sh:mode-applied',
|
|
19
|
+
console: 'sh:console',
|
|
20
|
+
resourceError: 'sh:resource-error',
|
|
21
|
+
dropped: 'sh:dropped',
|
|
22
|
+
warnings: 'sh:warnings',
|
|
23
|
+
renders: 'sh:renders',
|
|
24
|
+
gesture: 'sh:gesture',
|
|
25
|
+
inplace: 'sh:inplace',
|
|
26
|
+
// extended
|
|
27
|
+
setTheme: 'sh:set-theme',
|
|
28
|
+
themeApplied: 'sh:theme-applied',
|
|
29
|
+
laser: 'sh:laser',
|
|
30
|
+
pick: 'sh:pick',
|
|
31
|
+
hmr: 'sh:hmr',
|
|
32
|
+
stageKey: 'sh:stage-key',
|
|
33
|
+
stageShown: 'sh:stage-shown',
|
|
34
|
+
} as const
|
|
35
|
+
|
|
36
|
+
// ---- the shell to a document --------------------------------------------------------------------------------------
|
|
37
|
+
|
|
38
|
+
/** #21: a theme switch carries its transition `t` (FrameNode.tsx:139, Play.tsx:390). The spec's "`sh:theme`
|
|
39
|
+
* (FrameNode)" is this message. */
|
|
40
|
+
export interface SetThemeMsg { type: 'sh:set-theme'; theme: string; t?: string }
|
|
41
|
+
/** #26: a mode change carries its transition `t` (FrameNode.tsx:180, :187; Play.tsx:356-357). */
|
|
42
|
+
export interface LaserMsg { type: 'sh:laser'; on: boolean; inspect: boolean; t?: string }
|
|
43
|
+
export interface PickMsg { type: 'sh:pick'; on: boolean; quiet: boolean; t?: string }
|
|
44
|
+
/** #36: a gesture's start and end, to the on-screen frames - their Profiler counts `inGesture` between them. */
|
|
45
|
+
export interface GestureMsg { type: 'sh:gesture'; on: boolean }
|
|
46
|
+
|
|
47
|
+
// ---- a document to the shell --------------------------------------------------------------------------------------
|
|
48
|
+
|
|
49
|
+
/** #21: the ack echoes the switch's `t` and the document's boot id (bridge.js:36-40; the stage posts the same, two
|
|
50
|
+
* animation frames after). An ack with an old `t`, or from a document no longer the live one, does not count. */
|
|
51
|
+
export interface ThemeAppliedMsg { type: 'sh:theme-applied'; id: string; theme: string; t?: string; boot?: string }
|
|
52
|
+
/** #26: inspect.js, two animation frames after `applyModes` (:535-536): the modes it applied, for transition `t`. */
|
|
53
|
+
export interface ModeAppliedMsg { type: 'sh:mode-applied'; id: string; t: string; boot: string; laser: boolean; inspect: boolean; pick: boolean }
|
|
54
|
+
/** #28: a frame's `console.error`, as produced (the original runs first). Its own message: `sh:error` marks the
|
|
55
|
+
* frame failed, a console error does not. */
|
|
56
|
+
export interface ConsoleMsg { type: 'sh:console'; id: string; gen: string; boot: string; message: string; stack?: string[] }
|
|
57
|
+
/** #32: an element's load error, caught in the capture phase: `url` a same-origin path without query, else the
|
|
58
|
+
* other origin alone. */
|
|
59
|
+
export interface ResourceErrorMsg { type: 'sh:resource-error'; id: string; gen: string; boot: string; tag: ResourceTag; url: string }
|
|
60
|
+
/** What a frame's budget refuses, by source (#33): console errors, resource errors. A window error spends it and is never refused. */
|
|
61
|
+
export type FrameDropSource = 'console' | 'resource'
|
|
62
|
+
/** #33: counter-only, independent of the detail budget, at most one a second, a final one at `pagehide`. Counts since
|
|
63
|
+
* the document's previous `sh:dropped`: the shell adds them to `dropped { reason: <source>, n }`. */
|
|
64
|
+
export interface DroppedMsg { type: 'sh:dropped'; id: string; boot: string; counts: Partial<Record<FrameDropSource, number>>; final?: true }
|
|
65
|
+
/** #28: a frame's `console.warn` calls, counted - no text. Counter-only, at most one a second, a final one at
|
|
66
|
+
* `pagehide`; the shell adds them up by node into the minute's `warnings` record. */
|
|
67
|
+
export interface WarningsMsg { type: 'sh:warnings'; id: string; boot: string; n: number; final?: true }
|
|
68
|
+
/** #36: a document's minute of React commits (the frame root's, or the stage root's: `id` 'stage'). `minute`: the
|
|
69
|
+
* minute's start, epoch ms. */
|
|
70
|
+
export interface RendersMsg { type: 'sh:renders'; id: string; boot: string; minute: number; commits: number; ms: number; maxMs: number; inGesture: number }
|
|
71
|
+
/** Today's (main.tsx:129): an update applied in place, so a sleeping frame wakes. Unchanged; `sh:inplace` reports. */
|
|
72
|
+
export interface HmrMsg { type: 'sh:hmr'; id: string }
|
|
73
|
+
/** #15: a document that fetched `<acceptedPath>?t=<hmrTs>` (Resource Timing) reports what it saw - after its next
|
|
74
|
+
* observed commit, or `RELOAD_BOUNDS.commitWaitMs` with none. `applied` is `false` only on Vite's own failure message
|
|
75
|
+
* for that path; never `true`. Registry-only updates send nothing (main.tsx:129's filter). `noAfterUpdate`: its round
|
|
76
|
+
* ended with no `vite:afterUpdate`, so this is what was known by then, `applyMs` how long the round stood open. */
|
|
77
|
+
export interface InplaceMsg { type: 'sh:inplace'; id: string; boot: string; hmrTs: number; applyMs?: number; nextObservedCommitMs?: number; applied: 'unknown' | false; noAfterUpdate?: true }
|
|
78
|
+
/** #50: the stage's background click posted as Space (stage/main.tsx:273) says so. */
|
|
79
|
+
export interface StageKeyMsg { type: 'sh:stage-key'; key: string; code: string; alt?: boolean; meta?: boolean; origin?: 'click' }
|
|
80
|
+
/** #26: Play's first `sh:stage-shown` after `enterPlay`/`enterSlides` ends the mode's `firstFrameMs`; the existing
|
|
81
|
+
* fields (stage/main.tsx:152), with the stage's boot id so an old stage's never counts. */
|
|
82
|
+
export interface StageShownMsg { type: 'sh:stage-shown'; at: string; nav: string; epoch: string; doc: number; boot?: string }
|
|
83
|
+
|
|
84
|
+
export type DocMsg = ThemeAppliedMsg | ModeAppliedMsg | ConsoleMsg | ResourceErrorMsg | DroppedMsg | WarningsMsg | RendersMsg | HmrMsg | InplaceMsg | StageKeyMsg | StageShownMsg
|
|
85
|
+
export type ShellMsg = SetThemeMsg | LaserMsg | PickMsg | GestureMsg
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Types for signals.js (plain JS: it serves into frames like bridge.js).
|
|
2
|
+
export const FRAME_BUDGET: { perSecond: number; perDoc: number; countsMs: number }
|
|
3
|
+
export const RESOURCE_TAGS: string[]
|
|
4
|
+
export function documentRecords(search?: string): boolean
|
|
5
|
+
export function periodMs(): number
|
|
6
|
+
export function formatConsole(args: readonly unknown[], max?: number): string
|
|
7
|
+
export function stackOfArgs(args: readonly unknown[]): string[] | undefined
|
|
8
|
+
export function viteEcho(args: readonly unknown[]): boolean
|
|
9
|
+
export function resourceUrl(raw: string, base?: string): string
|
|
10
|
+
export function resourceOf(target: unknown, base?: string): { tag: string; url: string } | null
|
|
11
|
+
export function createBudget<S extends string>(limits: { perSecond: number; perDoc: number }, refused: (source: S) => void, now?: () => number): { take(source: S, force?: boolean): boolean }
|
|
12
|
+
export function createCounter(ms: number, send: (counts: Record<string, number>, final: boolean) => void, now?: () => number): { add(key: string, n?: number): void; final(): void }
|
|
13
|
+
export function onConsoleError(fn: (args: unknown[]) => void): () => void
|
|
14
|
+
export function startDocumentSignals(o: { post: (msg: Record<string, unknown>) => void; id: string; gen: string; boot: string }): { take(source: 'frame' | 'console' | 'resource', force?: boolean): boolean } | null
|
|
15
|
+
export function frameRenders(post: (msg: Record<string, unknown>) => void, id: string, getBoot: () => string | undefined): ((id: string, phase: string, actualDuration: number) => void) | null
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
// The recorder's signals inside a document (spec 30 R5, R6): what a canvas frame (bridge.js) tells the shell beyond its
|
|
2
|
+
// ready and errors - its console errors and counted warnings (#28), its elements' load errors (#32), what its budget
|
|
3
|
+
// refused (#33) - and the React Profiler's minute, which the frames and the play stage post (#36). The shell takes the
|
|
4
|
+
// same rules for its own console and elements (recorder-signals.ts imports this module).
|
|
5
|
+
//
|
|
6
|
+
// Plain JS that ships verbatim beside bridge.js (build.ts copies it for published HTML frames): it repeats
|
|
7
|
+
// perf-records.ts `ERROR_BUDGET.frame` and the minute inline. Nothing runs at import; `startDocumentSignals` and
|
|
8
|
+
// `frameRenders` do nothing unless the document records (dev: its URL names the workspace, at the full level, in a
|
|
9
|
+
// shell's iframe) - a published canvas, a `core` run and a frame opened on its own pay one check.
|
|
10
|
+
//
|
|
11
|
+
// Limited at the source (#33): every count is taken BEFORE a message is formatted or posted. Errors, console errors and
|
|
12
|
+
// resource errors share 5 a second and 50 per document; what the budget refuses is counted by source and travels on
|
|
13
|
+
// its own, in counter-only `sh:dropped` messages (at most one a second, a final one at `pagehide`). A window error spends
|
|
14
|
+
// the budget but is never refused: it marks the frame failed (bridge.js, #5).
|
|
15
|
+
|
|
16
|
+
/** perf-records.ts `ERROR_BUDGET.frame`, repeated (this file ships verbatim). */
|
|
17
|
+
export const FRAME_BUDGET = { perSecond: 5, perDoc: 50, countsMs: 1000 }
|
|
18
|
+
/** perf-records.ts `RESOURCE_TAGS` (#32). */
|
|
19
|
+
export const RESOURCE_TAGS = ['img', 'script', 'link', 'video', 'audio', 'source']
|
|
20
|
+
const MAX = 200
|
|
21
|
+
|
|
22
|
+
/** Does this document record spec 30's signals? In a shell's iframe, on a page that records (its URL names the
|
|
23
|
+
* workspace, as `withWs()` writes it in dev), at the full level (`?mvrecorder=core` turns it off, #58). */
|
|
24
|
+
export function documentRecords(search = location.search) {
|
|
25
|
+
try {
|
|
26
|
+
if (window.parent === window) return false
|
|
27
|
+
const q = new URLSearchParams(search)
|
|
28
|
+
return q.has('ws') && q.get('mvrecorder') !== 'core'
|
|
29
|
+
} catch { return false }
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** The period renders and warnings are counted over: a minute. A test shortens it (`__mvSignalsPeriodMs`, set before the
|
|
33
|
+
* document loads); nothing else does. */
|
|
34
|
+
export function periodMs() {
|
|
35
|
+
const v = globalThis.__mvSignalsPeriodMs
|
|
36
|
+
return typeof v === 'number' && v >= 100 ? v : 60000
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const piece = (x) => {
|
|
40
|
+
if (typeof x === 'string') return x
|
|
41
|
+
if (x instanceof Error) return `${x.name && x.name !== 'Error' ? `${x.name}: ` : ''}${x.message}`
|
|
42
|
+
if (x === null || typeof x !== 'object' && typeof x !== 'function') return String(x)
|
|
43
|
+
if (typeof x === 'function') return `[function ${x.name || 'anonymous'}]`
|
|
44
|
+
if (Array.isArray(x)) return `[Array(${x.length})]`
|
|
45
|
+
// never a deep read: an object's own text is the code's to put in a string (#4)
|
|
46
|
+
return `[${x.constructor?.name || 'Object'}]`
|
|
47
|
+
}
|
|
48
|
+
/** A console call's message as the code produced it (#4, #28): its strings, `%s`/`%d`/`%i`/`%f`/`%o`/`%O`
|
|
49
|
+
* substituted, `%c` styles dropped, errors by their message, objects by their kind - `max` characters, built no
|
|
50
|
+
* further than that. */
|
|
51
|
+
export function formatConsole(args, max = MAX) {
|
|
52
|
+
let out = ''
|
|
53
|
+
let i = 0
|
|
54
|
+
if (typeof args[0] === 'string') {
|
|
55
|
+
i = 1
|
|
56
|
+
out = args[0].replace(/%[sdifoOc%]/g, (spec) => {
|
|
57
|
+
if (spec === '%%') return '%'
|
|
58
|
+
if (i >= args.length) return spec
|
|
59
|
+
const a = args[i++]
|
|
60
|
+
if (spec === '%c') return ''
|
|
61
|
+
try { return spec === '%d' || spec === '%i' ? String(parseInt(a, 10)) : spec === '%f' ? String(Number(a)) : piece(a) } catch { return '?' }
|
|
62
|
+
})
|
|
63
|
+
}
|
|
64
|
+
for (; i < args.length && out.length < max; i++) {
|
|
65
|
+
let p
|
|
66
|
+
try { p = piece(args[i]) } catch { p = '?' }
|
|
67
|
+
out = out ? `${out} ${p}` : p
|
|
68
|
+
}
|
|
69
|
+
return out.slice(0, max)
|
|
70
|
+
}
|
|
71
|
+
/** The first error's first three stack lines among a console call's arguments, when it has them. */
|
|
72
|
+
export function stackOfArgs(args) {
|
|
73
|
+
const err = args.find((a) => a instanceof Error)
|
|
74
|
+
if (!err || typeof err.stack !== 'string') return undefined
|
|
75
|
+
const lines = err.stack.split('\n')
|
|
76
|
+
const chrome = lines.filter((l) => /^\s*at /.test(l))
|
|
77
|
+
const out = (chrome.length ? chrome : lines.filter((l) => /@.*:\d+(:\d+)?$/.test(l.trim()))).slice(0, 3).map((l) => l.trim().slice(0, MAX))
|
|
78
|
+
return out.length ? out : undefined
|
|
79
|
+
}
|
|
80
|
+
/** Vite's own echo of a server error into every document's console (overlay off): the shell's `vite:error` listener
|
|
81
|
+
* records it once (#29), so no console hook does. */
|
|
82
|
+
export const viteEcho = (args) => typeof args[0] === 'string' && args[0].startsWith('[vite] Internal Server Error')
|
|
83
|
+
|
|
84
|
+
/** #32: a same-origin URL's path without its query; another origin, its origin alone; any other scheme, the scheme. */
|
|
85
|
+
export function resourceUrl(raw, base = location.href) {
|
|
86
|
+
try {
|
|
87
|
+
const u = new URL(raw, base)
|
|
88
|
+
if (u.protocol !== 'http:' && u.protocol !== 'https:') return u.protocol
|
|
89
|
+
return u.origin === new URL(base).origin ? u.pathname : u.origin
|
|
90
|
+
} catch { return '' }
|
|
91
|
+
}
|
|
92
|
+
/** An element whose load failed, as #32 records it: its tag and URL, or null for anything else. */
|
|
93
|
+
export function resourceOf(target, base) {
|
|
94
|
+
if (!target || typeof target.tagName !== 'string') return null
|
|
95
|
+
const tag = target.tagName.toLowerCase()
|
|
96
|
+
if (!RESOURCE_TAGS.includes(tag)) return null
|
|
97
|
+
const raw = tag === 'link' ? target.href : (target.currentSrc || target.src || target.getAttribute?.('src') || '')
|
|
98
|
+
return { tag, url: resourceUrl(String(raw ?? ''), base) }
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** #33: the document's budget - `perSecond` and `perDoc`, shared by every source. A refusal is told to `refused` with
|
|
102
|
+
* its source; `force` passes whatever the budget says (and counts against it). */
|
|
103
|
+
export function createBudget(limits, refused, now = () => performance.now()) {
|
|
104
|
+
let used = 0, sec = NaN, inSec = 0
|
|
105
|
+
return {
|
|
106
|
+
take(source, force = false) {
|
|
107
|
+
const s = Math.floor(now() / 1000)
|
|
108
|
+
if (s !== sec) { sec = s; inSec = 0 }
|
|
109
|
+
if (!force && (used >= limits.perDoc || inSec >= limits.perSecond)) { refused(source); return false }
|
|
110
|
+
used++; inSec++
|
|
111
|
+
return true
|
|
112
|
+
},
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** Counts that travel on their own: added up and sent at most once every `ms` (the first at once, after a quiet
|
|
117
|
+
* `ms`), a final send when asked - nothing when there is nothing to say. */
|
|
118
|
+
export function createCounter(ms, send, now = () => performance.now()) {
|
|
119
|
+
let counts = null, timer = null, last = -Infinity
|
|
120
|
+
const go = (final) => {
|
|
121
|
+
if (timer !== null) { clearTimeout(timer); timer = null }
|
|
122
|
+
if (!counts) return
|
|
123
|
+
const c = counts
|
|
124
|
+
counts = null
|
|
125
|
+
last = now()
|
|
126
|
+
send(c, final)
|
|
127
|
+
}
|
|
128
|
+
return {
|
|
129
|
+
add(key, n = 1) {
|
|
130
|
+
if (!counts) counts = {}
|
|
131
|
+
counts[key] = (counts[key] ?? 0) + n
|
|
132
|
+
if (timer === null) timer = setTimeout(() => go(false), Math.max(0, last + ms - now()))
|
|
133
|
+
},
|
|
134
|
+
final() { go(true) },
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// ---- a document's hooks (bridge.js) ------------------------------------------------------------------------------
|
|
139
|
+
|
|
140
|
+
/** a gesture runs on the canvas over this frame (`sh:gesture`): its commits count `inGesture` */
|
|
141
|
+
let gesture = false
|
|
142
|
+
let started = null
|
|
143
|
+
const consoleListeners = new Set()
|
|
144
|
+
/** Told every `console.error` of this document with its arguments, before any budget (the edits stream's #15 reads
|
|
145
|
+
* Vite's own failure message here). Returns the unsubscribe. */
|
|
146
|
+
export function onConsoleError(fn) { consoleListeners.add(fn); return () => { consoleListeners.delete(fn) } }
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* A canvas frame's hooks, once (bridge.js, before anything else it posts): `console.error` and `console.warn` wrapped
|
|
150
|
+
* (the original runs first), the capture-phase element error listener, the budget, the counters, and the shell's
|
|
151
|
+
* `sh:gesture`. Returns `take(source, force?)` - the budget, which the bridge's own window errors spend with `force` -
|
|
152
|
+
* or null when this document does not record.
|
|
153
|
+
*/
|
|
154
|
+
export function startDocumentSignals({ post, id, gen, boot }) {
|
|
155
|
+
if (started) return started
|
|
156
|
+
if (!documentRecords()) return null
|
|
157
|
+
const dropped = createCounter(FRAME_BUDGET.countsMs, (counts, final) => post({ type: 'sh:dropped', id, boot, counts, ...(final ? { final: true } : {}) }))
|
|
158
|
+
const budget = createBudget(FRAME_BUDGET, (source) => dropped.add(source, 1))
|
|
159
|
+
const warns = createCounter(FRAME_BUDGET.countsMs, (counts, final) => post({ type: 'sh:warnings', id, boot, n: counts.n, ...(final ? { final: true } : {}) }))
|
|
160
|
+
|
|
161
|
+
const error0 = console.error, warn0 = console.warn
|
|
162
|
+
console.error = function (...args) {
|
|
163
|
+
error0.apply(this, args)
|
|
164
|
+
try {
|
|
165
|
+
for (const fn of consoleListeners) { try { fn(args) } catch { /* one listener, not the rest */ } }
|
|
166
|
+
if (viteEcho(args) || !budget.take('console')) return
|
|
167
|
+
const stack = stackOfArgs(args)
|
|
168
|
+
post({ type: 'sh:console', id, gen, boot, message: formatConsole(args), ...(stack ? { stack } : {}) })
|
|
169
|
+
} catch { /* never in the way */ }
|
|
170
|
+
}
|
|
171
|
+
console.warn = function (...args) {
|
|
172
|
+
warn0.apply(this, args)
|
|
173
|
+
try { warns.add('n', 1) } catch { /* never in the way */ }
|
|
174
|
+
}
|
|
175
|
+
// an element's load error does not bubble: the capture phase at the window sees every one
|
|
176
|
+
addEventListener('error', (e) => {
|
|
177
|
+
try {
|
|
178
|
+
if (!(e.target instanceof Element)) return
|
|
179
|
+
const r = resourceOf(e.target)
|
|
180
|
+
if (!r || !budget.take('resource')) return
|
|
181
|
+
post({ type: 'sh:resource-error', id, gen, boot, tag: r.tag, url: r.url })
|
|
182
|
+
} catch { /* never in the way */ }
|
|
183
|
+
}, true)
|
|
184
|
+
addEventListener('message', (e) => {
|
|
185
|
+
if (e.source !== window.parent || window.parent === window || (e.origin && e.origin !== location.origin)) return
|
|
186
|
+
if (e.data?.type === 'sh:gesture') gesture = !!e.data.on
|
|
187
|
+
})
|
|
188
|
+
addEventListener('pagehide', () => { dropped.final(); warns.final() })
|
|
189
|
+
started = { take: (source, force) => budget.take(source, force) }
|
|
190
|
+
return started
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* #36: a document's React commits, by minute - the frame root's (frame-host/main.tsx) or the stage root's: `commits`,
|
|
195
|
+
* `ms` (the sum of `actualDuration`), `maxMs` and `inGesture`, posted as `sh:renders` once the minute is over, and the
|
|
196
|
+
* minute so far at `pagehide`. The Profiler's `onRender`, or null when this document does not record. No props, state
|
|
197
|
+
* or text: numbers only.
|
|
198
|
+
*/
|
|
199
|
+
export function frameRenders(post, id, getBoot) {
|
|
200
|
+
if (!documentRecords()) return null
|
|
201
|
+
let minute = -1, commits = 0, ms = 0, maxMs = 0, inGesture = 0, timer = null
|
|
202
|
+
const flush = () => {
|
|
203
|
+
if (timer !== null) { clearTimeout(timer); timer = null }
|
|
204
|
+
if (!commits) return
|
|
205
|
+
post({ type: 'sh:renders', id, boot: getBoot() ?? '', minute, commits, ms: Math.round(ms * 10) / 10, maxMs: Math.round(maxMs * 10) / 10, inGesture })
|
|
206
|
+
commits = 0; ms = 0; maxMs = 0; inGesture = 0
|
|
207
|
+
}
|
|
208
|
+
addEventListener('pagehide', flush)
|
|
209
|
+
return (_id, _phase, actual) => {
|
|
210
|
+
try {
|
|
211
|
+
const p = periodMs(), now = Date.now(), m = Math.floor(now / p) * p
|
|
212
|
+
if (m !== minute) { flush(); minute = m }
|
|
213
|
+
commits++
|
|
214
|
+
if (typeof actual === 'number' && actual > 0) { ms += actual; if (actual > maxMs) maxMs = actual }
|
|
215
|
+
if (gesture) inGesture++
|
|
216
|
+
if (timer === null) timer = setTimeout(flush, m + p - now + 50)
|
|
217
|
+
} catch { /* never in the way */ }
|
|
218
|
+
}
|
|
219
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The recorder's level (spec 30 #57, #58): the one switch every spec 30 hook is gated by, in the shell, the frame host
|
|
3
|
+
* and the stage alike. `core` records what 0.29 recorded - the load tracking a headless run's driver reads
|
|
4
|
+
* (`currentLoad`, recorder.ts) - and nothing spec 30 adds; `full`, the default, records everything.
|
|
5
|
+
*
|
|
6
|
+
* Set by the page's URL, `?mvrecorder=core` (perf-records.ts `RECORDER_PARAM`): `marver perf run <board> --recorder
|
|
7
|
+
* core` puts it on the shell's URL, and `withWs()` (api.ts) carries it onto every frame and stage URL, so a document's
|
|
8
|
+
* hooks keep its page's level. Dev only: a production build has no recorder and reads `full`. bridge.js ships
|
|
9
|
+
* verbatim and imports nothing new (build.ts copies it): it reads the parameter itself, the same way.
|
|
10
|
+
*
|
|
11
|
+
* Owner: app-store (R15) - the run's `--recorder` input, `self` records and the cost test. Every other stream calls
|
|
12
|
+
* `fullRecorder()` (or starts from recorder.ts's stream starters, which are not called under `core`).
|
|
13
|
+
*/
|
|
14
|
+
import { RECORDER_PARAM, SELF_HOOKS, type RecorderLevel, type SelfHook } from '../shared/perf-records.ts'
|
|
15
|
+
|
|
16
|
+
/** This document's level, read once at module load. */
|
|
17
|
+
export const RECORDER_LEVEL: RecorderLevel = (() => {
|
|
18
|
+
if (!import.meta.env.DEV) return 'full'
|
|
19
|
+
try { return new URLSearchParams(location.search).get(RECORDER_PARAM) === 'core' ? 'core' : 'full' } catch { return 'full' }
|
|
20
|
+
})()
|
|
21
|
+
|
|
22
|
+
/** The level, for a hook deciding whether to run. */
|
|
23
|
+
export const recorderLevel = (): RecorderLevel => RECORDER_LEVEL
|
|
24
|
+
/** Does this document record what spec 30 adds? */
|
|
25
|
+
export const fullRecorder = (): boolean => RECORDER_LEVEL === 'full'
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Test-only (#58): `?mvslowhook=<hook>` on the shell's URL adds a 5 ms busy wait to that hook, so the cost run has a
|
|
29
|
+
* cost to find: the run must fail with it, or the run measures nothing. Dev only, set only by a test.
|
|
30
|
+
*/
|
|
31
|
+
export const SLOW_HOOK_PARAM = 'mvslowhook'
|
|
32
|
+
export const SLOW_HOOK_MS = 5
|
|
33
|
+
export const SLOW_HOOK: SelfHook | null = (() => {
|
|
34
|
+
if (!import.meta.env.DEV) return null
|
|
35
|
+
try { const h = new URLSearchParams(location.search).get(SLOW_HOOK_PARAM); return (SELF_HOOKS as readonly string[]).includes(h ?? '') ? h as SelfHook : null } catch { return null }
|
|
36
|
+
})()
|
|
37
|
+
/** The wait itself: this thread held, as a hook's work would hold it. */
|
|
38
|
+
export function busyWait(ms: number): void {
|
|
39
|
+
const end = performance.now() + ms
|
|
40
|
+
while (performance.now() < end) { /* the point */ }
|
|
41
|
+
}
|