@hueest/xray 0.6.0 → 0.7.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.
@@ -1,564 +0,0 @@
1
- //#region src/diagnostics.d.ts
2
- /**
3
- * Dev-only capture diagnostics: a small, serializable record of why a Plate may
4
- * be incomplete or lower-fidelity, plus the one shared formatter both the
5
- * browser console (`client.ts`) and the Vite server output (`index.ts`) print.
6
- *
7
- * Motivation: the serializer silently swallows a handful of capture omissions
8
- * (an unreadable cross-origin stylesheet, skipped pseudo-elements, off-screen
9
- * bones dropped at the fold, an over-the-limit subtree). Early adopters asking "why does this
10
- * skeleton look wrong?" had to read the serializer source to find out. These
11
- * diagnostics surface those omissions as data the capture process returns, so a
12
- * caller can log them — without the core performing any console side effects.
13
- *
14
- * Strictly DEV-ONLY (see the plan's decisions and ADR 0008): this type is NOT a
15
- * public package export and MUST NEVER reach the persisted Plate JSON, the
16
- * `MergedPlate`, or the production adapter. It rides on the TRANSIENT
17
- * `ViewIR.diagnostics` field only, which `captureView` populates and the
18
- * dev client strips before posting (so committed `plates/<name>.json` stays
19
- * byte-identical to a capture that produced no diagnostics).
20
- *
21
- * Centralized on purpose: a follow-up plan (capture-input-validation) reuses
22
- * this same messaging for invalid posted/committed plates, so the code table
23
- * and formatter are kept reusable. Browser and server share `formatDiagnostic`
24
- * so their warning text cannot drift.
25
- *
26
- * @module
27
- */
28
- /**
29
- * One aggregated capture omission. Serializable on purpose: NO DOM nodes, NO
30
- * CSS bodies, NO captured text — only a stable `code`, a human message, an
31
- * optional aggregate `count`, and an optional short `detail` (e.g. a plate name
32
- * or a node count, never user content). `count` aggregates occurrences: there
33
- * is at most one record per code per capture, never one per skipped selector or
34
- * node.
35
- */
36
- interface CaptureDiagnostic {
37
- code: DiagnosticCode;
38
- message: string;
39
- count?: number;
40
- detail?: string;
41
- }
42
- /**
43
- * The closed set of capture-omission codes. Each maps to one silent site in the
44
- * serializer (or an existing oversized-capture warning folded into the same
45
- * vocabulary). Kept as a const union so the message table is exhaustive.
46
- */
47
- type DiagnosticCode = 'unreadable-stylesheet' | 'unreadable-import' | 'skipped-dynamic-pseudo' | 'skipped-pseudo-element' | 'unsupported-rule' | 'dropped-tag' | 'dropped-subset' | 'dropped-cropped' | 'too-large' | 'invalid-plate-file';
48
- //#endregion
49
- //#region src/plate.d.ts
50
- type LeafKind = 'text' | 'text-block' | 'media' | 'box';
51
- /**
52
- * The shipped structural capture of a component's rendered DOM — the TREE
53
- * artifact a Skeleton renders from (see CONTEXT.md). Since the two-artifact
54
- * cutover (plan 005 round 2), a Plate carries structure ONLY: its scoped CSS
55
- * is an INDEPENDENT sibling artifact — the plugin serves it through Vite's
56
- * own CSS pipeline (`virtual:xray/plates/<name>.css`, plus the shared
57
- * `virtual:xray/base.css`, and an `export const css` on the virtual JS module
58
- * for dev/programmatic reads), and the framework-neutral `core.ts` path hands
59
- * it back separately (`captureElement` → `{ plate, css }`;
60
- * `renderPlateHtml(plate, css)` receives it explicitly). Consumers decide how
61
- * to render either part. Still self-contained in ADR 0003's sense: both
62
- * artifacts originate from the capture and depend on nothing in the
63
- * consumer's build. Built from the RenderNode tree at plugin load (see
64
- * chunk.ts), so the adapter injects strings instead of walking a tree on the
65
- * latency-critical first paint — and no per-framework serializer ships to the
66
- * client (ADR 0008).
67
- */
68
- interface Plate {
69
- v: number;
70
- /** Capture name; comes from the virtual-module specifier, never typed at a call site. */
71
- name: string;
72
- /**
73
- * The root's children, pre-serialized (ADR 0008): a stitch-free run is one
74
- * HTML `string`; a stitch is `{ r: name }`; a stitch-bearing element is
75
- * `{ c: className, k: chunk[] }`. Null until first capture.
76
- */
77
- chunks: Chunk[] | null;
78
- /** The root node's own content classes (its inherited font context), if any. */
79
- rootCls?: string;
80
- /**
81
- * Child plates named by the chunks' `{ r }` stitches, resolved through the
82
- * import graph (ADR 0006). Populated by the loader's generated imports, never
83
- * serialized into the plates JSON; absent in production when there are no
84
- * stitches. In dev the live store takes precedence, so this need not be present.
85
- */
86
- refs?: Record<string, Plate>;
87
- }
88
- /**
89
- * One serialized child of a plate root (or of a stitch-bearing node): a
90
- * stitch-free HTML run (`string`), a stitch to a child plate (`{ r: name }`),
91
- * a stitch-bearing element kept real so its inner stitches can mount
92
- * (`{ c: className, k: chunk[] }`), or a templated uniform run (`{ t: html, n }`):
93
- * the cell's HTML once plus a repeat count the adapter expands to N copies (Phase
94
- * 2). The framework-neutral render contract: an adapter injects the strings,
95
- * mounts a child plate at each stitch, and repeats each template (ADR 0008).
96
- */
97
- type Chunk = string | {
98
- r: string;
99
- } | {
100
- c: string;
101
- k: Chunk[];
102
- } | {
103
- t: string;
104
- n: number;
105
- };
106
- /**
107
- * A plate after the in-browser Serialize (emit + merge/gate + classify) but
108
- * before chunk serialization: the build-time RenderNode tree plus its scoped
109
- * CSS. Produced by `serializePlateIR` (the structural part of `StoredPlate`) and
110
- * the single-View `capture`, then serialized into the shipped `Plate` (chunks) at
111
- * load (`serializePlate`). Never shipped to the client.
112
- */
113
- interface MergedPlate {
114
- v: number;
115
- name: string;
116
- tree: RenderNode | null;
117
- css: string;
118
- }
119
- interface PlateNode {
120
- /** Plate-local id; rules reference it pre-classify. Stripped from the shipped tree. */
121
- id: number;
122
- /** Present on paint leaves; absent on layout containers. */
123
- leaf?: LeafKind;
124
- /**
125
- * A stitch: render the named child plate's skeleton here instead of own
126
- * structure (ADR 0006). Mutually exclusive with `leaf`/`kids`. Resolved
127
- * against `Plate.refs` (prod) or the live store (dev).
128
- */
129
- ref?: string;
130
- /**
131
- * A templated uniform run (Phase 2): render this node's subtree `count` times.
132
- * The serializer emits the subtree's HTML once plus the count; the adapter
133
- * expands it to N copies at render. Absent on ordinary nodes.
134
- */
135
- count?: number;
136
- kids?: PlateNode[];
137
- }
138
- /**
139
- * A node in the shipped tree, after classify (ADR 0007). Carries the
140
- * content-addressed style classes it needs instead of an id — the CSS targets
141
- * those classes, not a per-node `data-xr` value, so node scoping (the old
142
- * `nodeKey`) is gone. `cls` is a space-joined class-token list.
143
- */
144
- interface RenderNode {
145
- leaf?: LeafKind;
146
- ref?: string;
147
- cls?: string;
148
- /** A templated uniform run (Phase 2): serialize this subtree once + a count the adapter repeats. */
149
- count?: number;
150
- kids?: RenderNode[];
151
- }
152
- /**
153
- * A captured style rule in id form — selectors are generated at render time,
154
- * so view merging can remap node ids without string surgery. `ids: []`
155
- * targets the plate root.
156
- */
157
- interface PlateRule {
158
- ids: number[];
159
- decls: string[];
160
- /** Media-condition stack, outermost first; conditions AND together. */
161
- media?: string[];
162
- /** `@container`-condition stack, outermost first; conditions AND together. Absent when none. */
163
- container?: string[];
164
- layered?: boolean;
165
- spec: number;
166
- order: number;
167
- }
168
- /**
169
- * One capture of a component within one viewport view — `[min, max)` in px,
170
- * either side open-ended when undefined. The id-form `{ tree, rules }` shape
171
- * `emit` projects a measured View into (ADR 0004). NO LONGER the disk/wire shape
172
- * after the ADR 0022 cutover — `StoredPlate` (below) is. Kept as the
173
- * framework-neutral per-View capture shape, exported for consumers reading the
174
- * id-form projection directly.
175
- */
176
- interface ViewCapture {
177
- /** Viewport width at capture time. */
178
- width: number;
179
- min?: number;
180
- max?: number;
181
- tree: PlateNode;
182
- rules: PlateRule[];
183
- /**
184
- * TRANSIENT, dev-only capture diagnostics (why this view may be lower
185
- * fidelity). Captured in the browser (mirrored onto `ViewIR.diagnostics`); the
186
- * dev client logs it and posts it alongside the `StoredPlate` (so the Vite
187
- * server can print the same text). It MUST NEVER be persisted: it is not part
188
- * of the committed
189
- * `StoredPlate` disk shape, the validator does not carry it, and the POST
190
- * envelope keeps it in a SIBLING field that never reaches the stored artifact
191
- * (ADR 0008). Absent in production (the prod adapter ships no capture). See
192
- * diagnostics.ts and ADR 0008.
193
- */
194
- diagnostics?: CaptureDiagnostic[];
195
- }
196
- /**
197
- * The committed `plates/<name>.json` shape AFTER the ADR 0022 cutover: the whole
198
- * Plate already projected in the browser (the in-browser Serialize folds emit +
199
- * the multi-View merge/gate + classify in one session), so disk holds ONE gated,
200
- * content-addressed tree + css instead of per-View captures merged at load. It is
201
- * a `MergedPlate` (the structural `{tree, css}` `serializePlate` consumes) PLUS the
202
- * `breakpoints` the HUD coverage reads — the analysis-only geometry never crosses
203
- * the wire (ADR 0021). The gen-side runs `serializePlate(stored) → Plate` (chunks)
204
- * at module-load, leaving the Tailwind/Bundle passthrough a clean gen-side seam.
205
- * Replaces `PlateFile` (+ `ViewCapture`) on disk and on the `/__xray` wire.
206
- */
207
- interface StoredPlate extends MergedPlate {
208
- /** Width thresholds (view boundaries); the HUD coverage derives its bands from these. */
209
- breakpoints: number[];
210
- }
211
- /**
212
- * Renderer-owned base styles, emitted once by the outermost view (ADR 0007),
213
- * before a plate's node rules so a node's captured class wins by source order.
214
- * Everything visual is driven by inheritable custom properties, so consumers
215
- * theme by setting `--xr-*` in `:root` or on any ancestor — and per-plate via
216
- * `[data-xr-root="name"]` (the root carries its plate name). See ADR 0011 and
217
- * docs/architecture.md. Class-based and unlayered — `@layer` was rejected
218
- * (unlayered app CSS would beat layered skeleton rules, and it inverts
219
- * `!important`).
220
- *
221
- * Progressive enhancement (ADR 0011): the plain bone fill + opacity pulse use
222
- * only universally-supported CSS and are the floor. `light-dark()` is guarded
223
- * by `@supports` because an unsupported VALUE drops the whole declaration (an
224
- * invisible bone), and it is not Baseline-widely-available until 2026-11-13 —
225
- * drop the guard then. Features that merely no-op when absent (`@property`,
226
- * `prefers-contrast`, relative-color-as-fallback) carry no hard guard.
227
- *
228
- * Tokens (ADR 0017 taxonomy). The `--xr-bone-*` family styles an individual
229
- * Bone: `--xr-bone-color` (fill), `--xr-bone-highlight-color` (sheen),
230
- * `--xr-bone-border-radius` (+ `--xr-bone-text-border-radius` /
231
- * `--xr-bone-text-block-border-radius` / `--xr-bone-media-border-radius`),
232
- * `--xr-bone-animation-duration`, the pulse
233
- * range `--xr-bone-pulse-opacity-min`/`--xr-bone-pulse-opacity-max`,
234
- * `--xr-bone-animation` (mode: `xr-pulse` | `none` | a custom keyframe), and
235
- * `--xr-bone-fill` (override the leaf paint, e.g. a sheen gradient built from the
236
- * two bone color tokens). The `--xr-skeleton-*` family governs whole-skeleton
237
- * display timing (ADR 0016): `--xr-skeleton-delay` (grace before the skeleton
238
- * becomes visible), `--xr-skeleton-min-duration` (minimum visible time once
239
- * shown; read by the `useSkeletonTiming` hook, not used in CSS), and
240
- * `--xr-skeleton-transition-duration` (the reveal/swap fade). The private
241
- * channels `--xr-o` (pulse) and `--xr-reveal` (reveal) stay undocumented
242
- * `@property` plumbing, not a theming surface.
243
- *
244
- * Declared as a PLAIN template literal — no `.trim()` (or any other call) on
245
- * the initializer. A method call is not provably pure to a conservative
246
- * tree-shaker (rolldown/Rollup), and it single-handedly pinned this ~5 KB
247
- * string into every consumer chunk importing the React adapter even after the
248
- * adapter stopped referencing it (plan 005 round 2 finding). The template
249
- * therefore starts immediately after the backtick (the old leading newline
250
- * `.trim()` used to strip simply isn't there), keeping the string value
251
- * byte-identical to the trimmed original.
252
- */
253
- declare const BASE_CSS = "/* One timeline per skeleton, not per leaf: the root animates one inherited\n opacity property and every leaf reads it. Hundreds of independent infinite\n opacity animations would pin the compositor and cook the CPU. */\n@property --xr-o { syntax: \"<number>\"; inherits: true; initial-value: 1 }\n/* The reveal channel (ADR 0016): a second inherited opacity factor the leaf\n multiplies into --xr-o. Transitioning THIS (not opacity directly) sidesteps\n the animation-vs-transition collision ADR 0012 flagged. initial-value 1 (NOT\n 0) is the degradation floor: without @starting-style the reveal can never be\n driven 0->1, so it must REST at 1 (fully visible). The delay-hide below is\n pure progressive enhancement layered on top. */\n@property --xr-reveal { syntax: \"<number>\"; inherits: true; initial-value: 1 }\n.xr-root {\n --xr-bone-highlight-color: #f4f4f5;\n display: contents;\n animation: var(--xr-bone-animation, xr-pulse) var(--xr-bone-animation-duration, 1.2s) ease-in-out infinite alternate;\n}\n/* No pointer-events:none \u2014 it blocks inspecting bones in devtools and buys\n nothing (no real content to click). border-color: a node may capture\n border-width for layout; its paint stays out. list-style: suppress a ::marker\n a captured display:list-item would otherwise paint. */\n.xr-node { border-color: transparent; list-style: none }\n.xr-leaf {\n background: var(--xr-bone-fill, var(--xr-bone-color, #e4e4e7));\n border-radius: var(--xr-bone-border-radius, 4px);\n /* Composed opacity (ADR 0016): the pulse channel times the reveal channel.\n Never transition opacity directly (the pulse animation owns it). */\n opacity: calc(var(--xr-o) * var(--xr-reveal));\n}\n/* Per-kind defaults: a single text LINE reads as a rounded bar; a multi-line\n text BLOCK as a soft rect (a tall pill misreads as a button); media carries\n the author radius, defaulting to the same soft rect. Re-theme any kind via\n [data-xr-root] .xr-leaf-text { ... }. */\n.xr-leaf-text { border-radius: var(--xr-bone-text-border-radius, 999px) }\n.xr-leaf-text-block { border-radius: var(--xr-bone-text-block-border-radius, var(--xr-bone-border-radius, 4px)) }\n.xr-leaf-media { border-radius: var(--xr-bone-media-border-radius, var(--xr-bone-border-radius, 4px)) }\n@keyframes xr-pulse {\n from { --xr-o: var(--xr-bone-pulse-opacity-max, 1) }\n to { --xr-o: var(--xr-bone-pulse-opacity-min, 0.5) }\n}\n/* Reveal delay-hide (ADR 0016), a progressive enhancement guarded so it can NEVER\n strand a skeleton invisible (open Q3). @starting-style is the trigger: only a\n browser that supports it enters this block at all, and such a browser also\n honors @property + transitions, so the 0->1 reveal completes. The @supports\n selector(...) probe is the broadest cross-engine @starting-style feature test\n available. Without support the block is skipped entirely and --xr-reveal stays\n at its initial-value 1 = fully visible instant skeleton. INSIDE the block we\n start at 0 and transition to 1 after the delay: invisible for\n --xr-skeleton-delay, then a --xr-skeleton-transition-duration fade-in; a fast\n load unmounts before the delay elapses and the skeleton is never seen. */\n@supports (selector(:has(*))) {\n /* The delay-hide applies to every root EXCEPT a stitch continuation (ADR 0020).\n Scoping with :not([data-xr-instant]) keeps an ordinary top-level skeleton\n byte-identical to before: it still mounts at --xr-reveal 0 and fades in after\n the delay. The transition/initial-1 rest state matches the original. */\n .xr-root:not([data-xr-instant]) {\n --xr-reveal: 1;\n transition: --xr-reveal var(--xr-skeleton-transition-duration, 150ms) linear var(--xr-skeleton-delay, 250ms);\n }\n @starting-style { .xr-root:not([data-xr-instant]) { --xr-reveal: 0 } }\n /* A stitch continuation (ADR 0020) reveals INSTANTLY: it was already visible as a\n stitch under a still-showing parent, so re-paying the delay would flash it away\n and back. No @starting-style and no transition \u2014 it rests at fully visible from\n its first frame, matching how the stitch inherited the parent's reveal. */\n .xr-root[data-xr-instant] { --xr-reveal: 1 }\n}\n/* Reduced motion (open Q2): keep the anti-flash delay + min-duration (they are\n not motion), drop only the FADE \u2014 collapse the reveal transition to instant and\n kill the pulse animation (as before). */\n@media (prefers-reduced-motion: reduce) {\n .xr-root { animation: none; --xr-skeleton-transition-duration: 0s }\n}\n/* Dark + high-contrast bone defaults. Guarded: light-dark() is an invalid value\n without support and would drop the declaration \u2014 see the note above; remove\n this @supports once widely available (2026-11-13). */\n@supports (color: light-dark(#000, #fff)) {\n .xr-root { --xr-bone-highlight-color: light-dark(#f4f4f5, #52525b) }\n .xr-leaf { background: var(--xr-bone-fill, var(--xr-bone-color, light-dark(#e4e4e7, #3f3f46))) }\n @media (prefers-contrast: more) {\n .xr-leaf { background: var(--xr-bone-fill, var(--xr-bone-color, light-dark(#d4d4d8, #52525b))) }\n }\n}\n/* Derive the sheen highlight from --xr-bone-color so re-theming one token updates\n both. Relative color isn't widely available yet; the static highlight above is\n the fallback (sheen just looks flatter), so no hard guard is needed. */\n@supports (color: oklch(from red l c h)) {\n .xr-root { --xr-bone-highlight-color: oklch(from var(--xr-bone-color, #e4e4e7) calc(l + 0.08) c h) }\n}";
254
- /**
255
- * Compose a plate's scoped css with the renderer-owned BASE_CSS, base first so
256
- * a plate rule beats a base rule at equal specificity by source order — the
257
- * standard composition for rendering a skeleton outside the Vite plugin
258
- * (where `virtual:xray/base.css` + `virtual:xray/plates/<name>.css` do this
259
- * through the CSS pipeline instead). Since the two-artifact cutover (plan 005
260
- * round 2) css is the CALLER's input: `renderPlateHtml(plate,
261
- * composeCss(css))`, or `<Skeleton plate={plate} css={composeCss(css)}>` for
262
- * a runtime-captured plate. Rendering a NESTED stitch under an
263
- * already-composed parent needs the raw css only (base is already on the
264
- * page) — pass the string uncomposed there.
265
- */
266
- declare function composeCss(css: string): string;
267
- /** The (unserialized) plate an import resolves to before anything has been captured. */
268
- declare function emptyPlate(name: string): MergedPlate;
269
- /**
270
- * A dev-only sticky boolean toggle (get/set/subscribe), persisted per tab.
271
- * Used for both "light box" (render every `<Skeleton>` regardless of readiness)
272
- * and "capture" (whether browsing re-captures plates).
273
- */
274
- interface ToggleStore {
275
- get: () => boolean;
276
- set: (value: boolean) => void;
277
- subscribe: (onChange: () => void) => () => void;
278
- }
279
- /**
280
- * Dev-only store of the freshest plate per name, updated in place when a
281
- * capture lands. `<Skeleton>` reads through it so a new plate re-renders the
282
- * site rather than reloading the module — which would remount the capture
283
- * boundary and re-fire the capture, a feedback loop.
284
- */
285
- interface PlateStore {
286
- get: (name: string) => Plate | undefined;
287
- subscribe: (name: string, onChange: () => void) => () => void;
288
- /**
289
- * Register a plate imported via the ref graph if the store has none yet — so a
290
- * stitch resolves even before its child is re-captured, and survives a parent
291
- * hot-swap (whose pushed plate carries no resolved `refs`). Never overwrites a
292
- * live capture.
293
- */
294
- seed: (name: string, plate: Plate) => void;
295
- }
296
- /** A view interval `[min, max)`; an open end is undefined (ADR 0004). */
297
- interface Span {
298
- min?: number;
299
- max?: number;
300
- }
301
- /**
302
- * Dev-only Fixture store (ADR 0015): stored render-INPUT `data` per Plate,
303
- * recorded to and replayed from a `plates/<name>.fixture.json` sidecar. Entirely
304
- * dev-only — devalue and this store never reach the production bundle.
305
- *
306
- * Two cooperating halves, both flowing through the render-prop `data` seam (ADR
307
- * 0014):
308
- * - The dev adapter (`react.dev.tsx`) calls `register(name, data)` at
309
- * `loading=false` with the live `data` it is about to render, so the latest
310
- * recordable input for each mounted Plate is always in scope for Record.
311
- * - `record(name)` serializes that registered live `data` with devalue and POSTs
312
- * it to the sidecar (the HUD button and the `first-ready`/`always` modes call
313
- * it). `has(name)` reports whether a Fixture exists (HUD coverage marker), and
314
- * `read(name)` returns the parsed Fixture `data` for Replay to substitute in
315
- * front of the render prop.
316
- *
317
- * The store holds DECODED values (the dev client owns the devalue parse, since it
318
- * has the live runtime); only the on-disk sidecar and the wire carry the opaque
319
- * devalue string.
320
- */
321
- interface FixtureStore {
322
- /**
323
- * Record the latest live `data` the dev adapter is about to render for `name`,
324
- * so Record always has the current recordable input in scope. A `register` with
325
- * the same value is cheap; the adapter calls it on every ready render. Returns a
326
- * disposer the adapter runs on unmount so an unmounted Skeleton's `data` never
327
- * lingers in the store: an unmounted instance must never be recorded or shadow a
328
- * still-mounted one (ADR 0015). With several Skeletons of the same plate name
329
- * mounted, the live value is the most-recently-registered still-mounted instance.
330
- */
331
- register: (name: string, data: unknown) => () => void;
332
- /** True once a recorded Fixture exists for `name` (drives the HUD coverage marker). */
333
- has: (name: string) => boolean;
334
- /** The parsed Fixture `data` for `name`, or `undefined` when none is recorded. */
335
- read: (name: string) => {
336
- data: unknown;
337
- } | undefined;
338
- /**
339
- * Serialize the registered live `data` for `name` with devalue and POST it to
340
- * the sidecar. Returns a promise that resolves once the write is
341
- * server-confirmed (so the HUD can surface a failed Record). Throws loudly when
342
- * the live `data` is unrecordable (devalue's contract) or no live `data` was
343
- * registered (a plain-children `<Skeleton>` has none).
344
- */
345
- record: (name: string) => Promise<void>;
346
- /**
347
- * Record every Skeleton that currently has live `data` registered (the HUD's
348
- * single "Record fixture" button — one click captures the inputs of all mounted
349
- * render-prop Skeletons). Resolves once all writes are server-confirmed; a
350
- * rejected write surfaces to the HUD.
351
- */
352
- recordAll: () => Promise<void>;
353
- /**
354
- * Seed the store from the on-disk sidecars on boot: a `{ <name>: devalueString }`
355
- * map (the opaque strings the server serves). The client decodes each with
356
- * devalue. Existing entries are not clobbered, so a Fixture recorded this
357
- * session survives a re-seed.
358
- */
359
- seed: (encoded: Record<string, string>) => void;
360
- /** React subscription so the HUD re-renders when a Fixture is recorded or seeded. */
361
- subscribe: (onChange: () => void) => () => void;
362
- }
363
- /** A plate's detected width thresholds and the spans actually captured, from disk. */
364
- interface PlateCoverage {
365
- breakpoints: number[];
366
- spans: Span[];
367
- }
368
- /**
369
- * Dev-only per-plate coverage, sourced from the committed plate files (not the
370
- * session): the breakpoints detected so far and which view spans are captured.
371
- * The HUD renders every band — covered ones lit, the rest dim — and the
372
- * capture-all sweep derives its target widths from the breakpoints.
373
- */
374
- interface CoverageStore {
375
- get: () => ReadonlyMap<string, PlateCoverage>;
376
- set: (name: string, coverage: PlateCoverage) => void;
377
- subscribe: (onChange: () => void) => () => void;
378
- }
379
- /**
380
- * Dev-only capture hook, installed by the dev client before the app boots.
381
- * Absent in production builds, so `<Skeleton>` carries zero capture weight.
382
- * `captured` returns a dispose callback (stop observing this site).
383
- */
384
- interface CaptureHook {
385
- captured: (name: string, el: Element, opts?: {
386
- delay?: number;
387
- walker?: unknown;
388
- mode?: 'auto' | 'manual';
389
- collect?: {
390
- maxNodes?: number;
391
- maxBreadth?: number;
392
- maxDepth?: number;
393
- };
394
- }) => (() => void) | undefined;
395
- /** Light Box toggle: force every `<Skeleton>` to its skeleton, read by `<Skeleton>`. */
396
- lightbox?: ToggleStore;
397
- /** Capture toggle: whether browsing re-captures plates, flipped from the HUD. */
398
- capture?: ToggleStore;
399
- /** Read side for `<Skeleton>`. */
400
- plates?: PlateStore;
401
- /** Write side for the dev client's HMR-event handler. Returns whether the plate changed. */
402
- updatePlate?: (name: string, plate: Plate) => boolean;
403
- /** Dev-only: run the HUD-triggered capture-all-views sweep via the extension (ADR 0010). */
404
- captureAllViews?: () => Promise<void>;
405
- /** Dev-only per-plate breakpoints + captured spans, from disk; fed by the bootstrap. */
406
- coverage?: CoverageStore;
407
- /**
408
- * Replay toggle (ADR 0015): when active, the dev adapter substitutes a recorded
409
- * Fixture's `data` for the live `data` at `loading=false`. The boolean is the
410
- * coarse on/off the HUD owns per tab; the per-mode policy (`prefer` vs
411
- * `missing-only`) is carried alongside in `replayMode`.
412
- */
413
- replay?: ToggleStore;
414
- /** Dev-only Replay policy: how a Fixture substitutes for live `data` (ADR 0015). */
415
- replayMode?: 'prefer' | 'missing-only';
416
- /**
417
- * Dev-only Record policy (ADR 0015): when the dev adapter records the live
418
- * `data` it is about to render. `'manual'` (the default) records nothing
419
- * automatically — only the HUD button does; `'first-ready'` records once when a
420
- * Skeleton goes ready and has no Fixture yet; `'always'` records on every ready
421
- * render.
422
- */
423
- recordMode?: 'manual' | 'first-ready' | 'always';
424
- /** Dev-only Fixture record/replay store (ADR 0015); never present in production. */
425
- fixtures?: FixtureStore;
426
- }
427
- declare global {
428
- var __XRAY__: CaptureHook | undefined;
429
- }
430
- //#endregion
431
- //#region src/serialize.d.ts
432
- /**
433
- * Browser-side capture: walk a live rendered subtree into a Plate — one node
434
- * tree plus one self-contained, scoped CSS string (ADR 0003). The CSS is
435
- * lifted from the author rules that matched each node, rewritten to
436
- * plate-local selectors — it carries `@media` for free and keeps layout live
437
- * (the M1 bake-off winner; ADR 0005).
438
- */
439
- interface CaptureOptions {
440
- /** Plate name; comes from the virtual-module specifier. */
441
- name: string;
442
- /** Collect limits (ADR 0022): refuse a capture whose measured tree exceeds any axis. */
443
- collect?: CollectLimits;
444
- /**
445
- * Optional programmable capture walker (ADR 0018). The declarative `data-xr-*`
446
- * annotations cover the 90%; this is the escape hatch for the 10% a markup
447
- * attribute cannot express. Capture-only: it shapes the resulting `PlateNode`
448
- * tree but is never persisted into the Plate, and the production adapter never
449
- * captures so it ignores this entirely.
450
- */
451
- walker?: XrayCaptureWalker;
452
- /**
453
- * Whether the top-level capture roots ARE this plate's own boundary, so the
454
- * stitch guard must be SKIPPED for them (ADR 0006/0014, finding #6). True ONLY
455
- * for a MANUAL root: there `site.el` is the consumer's own element and its
456
- * `data-xr-boundary` marks the boundary of THIS plate, so the root must be
457
- * serialized as a real Entry (its box/classes/padding/border) rather than a
458
- * stitch-to-itself. Defaults to `false` — the auto path, where the top-level
459
- * roots are the wrapper's CHILDREN and any boundary marker on a direct-child
460
- * root is a NESTED `<Skeleton>` that MUST stitch (the capture-leak guard).
461
- */
462
- captureRootIsBoundary?: boolean;
463
- }
464
- /**
465
- * What a capture walker decides for one element (ADR 0018; ADR 0022 §5). The
466
- * `applyWalker` PASS reads the decision and applies it to the measured IR node —
467
- * a walker NEVER hand-builds a `PlateNode`, so xray keeps ownership of the Plate
468
- * format. `ignore` drops the element + its subtree; `bone` collapses it to one
469
- * Bone leaf (inferring the kind when omitted); `keep` defers to the default
470
- * classifier (`markInk`).
471
- */
472
- type WalkerDecision = {
473
- type: 'ignore';
474
- } | {
475
- type: 'bone';
476
- kind?: LeafKind;
477
- } | {
478
- type: 'keep';
479
- };
480
- /**
481
- * The context handed to a capture walker's `element` hook (ADR 0018). The
482
- * helpers are PURE — each returns a `WalkerDecision` the `applyWalker` pass
483
- * applies; they do NOT mutate. `el` is the element under consideration.
484
- */
485
- interface CaptureWalkerContext {
486
- /** The element currently being classified. */
487
- el: Element;
488
- /** Drop this element AND its whole subtree (no bone). */
489
- ignore(): WalkerDecision;
490
- /**
491
- * Collapse this element's subtree into ONE Bone leaf. `kind` omitted shares
492
- * the default classifier's kind-inference heuristic (`inferLeafKind`; ADR 0018,
493
- * Q4 — ONE code path).
494
- */
495
- bone(opts?: {
496
- kind?: LeafKind;
497
- }): WalkerDecision;
498
- /** Defer to the default classifier (`markInk`) — recurse into the subtree. */
499
- keep(): WalkerDecision;
500
- }
501
- /**
502
- * The programmable capture walker (ADR 0018; ADR 0022 §5). `element` is offered
503
- * each non-boundary element TOP-DOWN over the measured IR (the `applyWalker`
504
- * pass, NOT the DOM walk) and returns a `WalkerDecision` the pass applies. The
505
- * declarative `data-xr-*` annotations cover the 90%; this is the 10% escape
506
- * hatch for what a markup attribute cannot express.
507
- */
508
- interface XrayCaptureWalker {
509
- /**
510
- * Called for every non-boundary element node (a stitch carries no element and
511
- * is skipped — ADR 0006 — so a boundary never reaches here). Return one of
512
- * `ctx.ignore()`, `ctx.bone()`, or `ctx.keep()`. An `ignore`/`bone` decision
513
- * stops the descent (the subtree lowers); `keep` recurses.
514
- */
515
- element?(ctx: CaptureWalkerContext): WalkerDecision;
516
- }
517
- /**
518
- * Typed identity wrapper for authoring a capture walker (ADR 0018) — the
519
- * `defineConfig` pattern. It returns its argument unchanged at runtime; its only
520
- * job is to infer and check the `XrayCaptureWalker` shape at the call site so an
521
- * author gets completion and a typo in a hook name is caught.
522
- */
523
- declare function defineXrayCaptureWalker(walker: XrayCaptureWalker): XrayCaptureWalker;
524
- /**
525
- * Thrown when a subtree has more nodes than the capture limit — almost always
526
- * a `<Skeleton>` sitting too high in the tree. Raised after the cheap walk and
527
- * before the O(rules × nodes) CSS extraction, so an oversized capture is
528
- * refused without freezing the main thread on it.
529
- */
530
- /** The measured size of a capture's surviving tree, one number per Collect axis (ADR 0022). */
531
- type CaptureSize = {
532
- nodes: number;
533
- breadth: number;
534
- depth: number;
535
- };
536
- /** Which Collect axis a too-large capture tripped. */
537
- type CollectAxis = 'nodes' | 'breadth' | 'depth';
538
- declare class CaptureTooLargeError extends Error {
539
- /** The full measured size of the surviving tree that tripped the gate. */
540
- readonly size: CaptureSize;
541
- /** Which axis exceeded its cap, and the cap it exceeded. */
542
- readonly axis: CollectAxis;
543
- readonly max: number;
544
- /** Back-compat alias for `size.nodes` (the sole axis before breadth/depth). */
545
- readonly nodeCount: number;
546
- /** Folds the oversized-capture warning into the shared diagnostics vocabulary (diagnostics.ts). */
547
- readonly code: "too-large";
548
- constructor(size: CaptureSize, axis: CollectAxis, max: number);
549
- }
550
- /**
551
- * Collect-stage size limits (ADR 0022): refuse to capture a boundary whose
552
- * measured tree exceeds any axis. `maxNodes` caps the total surviving-node count;
553
- * `maxBreadth` the widest level (most nodes at any one depth); `maxDepth` the
554
- * nesting depth. Each axis is enforced only when its cap is defined. The defaults
555
- * and the `maxNodes = round(maxBreadth × maxDepth / 4)` derivation live in the
556
- * client (where the other defaults live); this core only enforces what it is handed.
557
- */
558
- type CollectLimits = {
559
- maxNodes?: number;
560
- maxBreadth?: number;
561
- maxDepth?: number;
562
- };
563
- //#endregion
564
- export { ViewCapture as _, CollectAxis as a, CaptureDiagnostic as b, XrayCaptureWalker as c, LeafKind as d, MergedPlate as f, StoredPlate as g, RenderNode as h, CaptureWalkerContext as i, defineXrayCaptureWalker as l, PlateNode as m, CaptureSize as n, CollectLimits as o, Plate as p, CaptureTooLargeError as r, WalkerDecision as s, CaptureOptions as t, BASE_CSS as u, composeCss as v, emptyPlate as y };