@hueest/xray 0.1.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/dist/breakpoints-CBNlh7lQ.js +47 -0
- package/dist/client.d.ts +42 -0
- package/dist/client.js +354 -0
- package/dist/core.d.ts +55 -0
- package/dist/core.js +230 -0
- package/dist/hud.d.ts +18 -0
- package/dist/hud.js +165 -0
- package/dist/index.d.ts +317 -0
- package/dist/index.js +726 -0
- package/dist/plate-BuzRMPx4.js +94 -0
- package/dist/plate-DboxMKg-.d.ts +196 -0
- package/dist/react.core-CqnDjfAJ.js +59 -0
- package/dist/react.core-fgWG_svU.d.ts +21 -0
- package/dist/react.d.ts +29 -0
- package/dist/react.dev.d.ts +19 -0
- package/dist/react.dev.js +101 -0
- package/dist/react.js +58 -0
- package/dist/serialize-Bq6yJnNV.js +1071 -0
- package/dist/serialize.d.ts +88 -0
- package/dist/serialize.js +2 -0
- package/package.json +95 -0
- package/virtual.d.ts +53 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/** Marks the rendered skeleton root; carries the plate name. Also a dev capture marker. */
|
|
2
|
+
const ROOT_ATTR = "data-xr-root";
|
|
3
|
+
/**
|
|
4
|
+
* Marks a `<Content>` capture boundary in dev; carries the plate name. A parent
|
|
5
|
+
* capture treats it as a stitch — it references the child plate by name instead of
|
|
6
|
+
* re-serializing the child's subtree (ADR 0006).
|
|
7
|
+
*/
|
|
8
|
+
const BOUNDARY_ATTR = "data-xr-boundary";
|
|
9
|
+
const SPEC_LEAF = 9e6;
|
|
10
|
+
const SPEC_INLINE = 1e7;
|
|
11
|
+
const SPEC_GATE = 2e7;
|
|
12
|
+
/** Fixed renderer-owned classes every rendered node carries. */
|
|
13
|
+
const ROOT_CLASS = "xr-root";
|
|
14
|
+
const NODE_CLASS = "xr-node";
|
|
15
|
+
const LEAF_CLASS = "xr-leaf";
|
|
16
|
+
/**
|
|
17
|
+
* Renderer-owned base styles, emitted once by the outermost view (ADR 0007),
|
|
18
|
+
* before a plate's node rules so a node's captured class wins by source order.
|
|
19
|
+
* Everything visual is driven by inheritable custom properties, so consumers
|
|
20
|
+
* theme by setting `--xr-*` in `:root` or on any ancestor — and per-plate via
|
|
21
|
+
* `[data-xr-root="name"]` (the root carries its plate name). See ADR 0011 and
|
|
22
|
+
* docs/architecture.md. Class-based and unlayered — `@layer` was rejected
|
|
23
|
+
* (unlayered app CSS would beat layered skeleton rules, and it inverts
|
|
24
|
+
* `!important`).
|
|
25
|
+
*
|
|
26
|
+
* Progressive enhancement (ADR 0011): the plain bone fill + opacity pulse use
|
|
27
|
+
* only universally-supported CSS and are the floor. `light-dark()` is guarded
|
|
28
|
+
* by `@supports` because an unsupported VALUE drops the whole declaration (an
|
|
29
|
+
* invisible bone), and it is not Baseline-widely-available until 2026-11-13 —
|
|
30
|
+
* drop the guard then. Features that merely no-op when absent (`@property`,
|
|
31
|
+
* `prefers-contrast`, relative-color-as-fallback) carry no hard guard.
|
|
32
|
+
*
|
|
33
|
+
* Tokens: `--xr-bone` (fill), `--xr-bone-highlight` (sheen), `--xr-radius`
|
|
34
|
+
* (+ `--xr-radius-text` / `--xr-radius-media`), `--xr-duration`, the pulse range
|
|
35
|
+
* `--xr-pulse-min`/`--xr-pulse-max`, `--xr-anim` (mode: `xr-pulse` | `none` | a
|
|
36
|
+
* custom keyframe), and `--xr-fill` (override the leaf paint, e.g. a sheen
|
|
37
|
+
* gradient built from the two bone tokens).
|
|
38
|
+
*/
|
|
39
|
+
const BASE_CSS = `
|
|
40
|
+
/* One timeline per skeleton, not per leaf: the root animates one inherited
|
|
41
|
+
opacity property and every leaf reads it. Hundreds of independent infinite
|
|
42
|
+
opacity animations would pin the compositor and cook the CPU. */
|
|
43
|
+
@property --xr-o { syntax: "<number>"; inherits: true; initial-value: 1 }
|
|
44
|
+
.${ROOT_CLASS} {
|
|
45
|
+
--xr-bone-highlight: #f4f4f5;
|
|
46
|
+
display: contents;
|
|
47
|
+
animation: var(--xr-anim, xr-pulse) var(--xr-duration, 1.2s) ease-in-out infinite alternate;
|
|
48
|
+
}
|
|
49
|
+
/* No pointer-events:none — it blocks inspecting bones in devtools and buys
|
|
50
|
+
nothing (no real content to click). border-color: a node may capture
|
|
51
|
+
border-width for layout; its paint stays out. list-style: suppress a ::marker
|
|
52
|
+
a captured display:list-item would otherwise paint. */
|
|
53
|
+
.${NODE_CLASS} { border-color: transparent; list-style: none }
|
|
54
|
+
.${LEAF_CLASS} {
|
|
55
|
+
background: var(--xr-fill, var(--xr-bone, #e4e4e7));
|
|
56
|
+
border-radius: var(--xr-radius, 4px);
|
|
57
|
+
opacity: var(--xr-o);
|
|
58
|
+
}
|
|
59
|
+
/* Per-kind defaults: text reads as rounded bars, media as blocks. Re-theme any
|
|
60
|
+
kind via [data-xr-root] .${LEAF_CLASS}-text { ... }. */
|
|
61
|
+
.${LEAF_CLASS}-text { border-radius: var(--xr-radius-text, 999px) }
|
|
62
|
+
.${LEAF_CLASS}-media { border-radius: var(--xr-radius-media, var(--xr-radius, 4px)) }
|
|
63
|
+
@keyframes xr-pulse {
|
|
64
|
+
from { --xr-o: var(--xr-pulse-max, 1) }
|
|
65
|
+
to { --xr-o: var(--xr-pulse-min, 0.5) }
|
|
66
|
+
}
|
|
67
|
+
@media (prefers-reduced-motion: reduce) { .${ROOT_CLASS} { animation: none } }
|
|
68
|
+
/* Dark + high-contrast bone defaults. Guarded: light-dark() is an invalid value
|
|
69
|
+
without support and would drop the declaration — see the note above; remove
|
|
70
|
+
this @supports once widely available (2026-11-13). */
|
|
71
|
+
@supports (color: light-dark(#000, #fff)) {
|
|
72
|
+
.${ROOT_CLASS} { --xr-bone-highlight: light-dark(#f4f4f5, #52525b) }
|
|
73
|
+
.${LEAF_CLASS} { background: var(--xr-fill, var(--xr-bone, light-dark(#e4e4e7, #3f3f46))) }
|
|
74
|
+
@media (prefers-contrast: more) {
|
|
75
|
+
.${LEAF_CLASS} { background: var(--xr-fill, var(--xr-bone, light-dark(#d4d4d8, #52525b))) }
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/* Derive the sheen highlight from --xr-bone so re-theming one token updates both.
|
|
79
|
+
Relative color isn't widely available yet; the static highlight above is the
|
|
80
|
+
fallback (sheen just looks flatter), so no hard guard is needed. */
|
|
81
|
+
@supports (color: oklch(from red l c h)) {
|
|
82
|
+
.${ROOT_CLASS} { --xr-bone-highlight: oklch(from var(--xr-bone, #e4e4e7) calc(l + 0.08) c h) }
|
|
83
|
+
}`.trim();
|
|
84
|
+
/** The (unserialized) plate an import resolves to before anything has been captured. */
|
|
85
|
+
function emptyPlate(name) {
|
|
86
|
+
return {
|
|
87
|
+
v: 1,
|
|
88
|
+
name,
|
|
89
|
+
tree: null,
|
|
90
|
+
css: ""
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
//#endregion
|
|
94
|
+
export { ROOT_ATTR as a, SPEC_INLINE as c, NODE_CLASS as i, SPEC_LEAF as l, BOUNDARY_ATTR as n, ROOT_CLASS as o, LEAF_CLASS as r, SPEC_GATE as s, BASE_CSS as t, emptyPlate as u };
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
//#region src/plate.d.ts
|
|
2
|
+
type LeafKind = 'text' | 'media' | 'box';
|
|
3
|
+
/**
|
|
4
|
+
* The shipped structural capture of a component's rendered DOM — the data a
|
|
5
|
+
* Skeleton renders from (see CONTEXT.md). Self-contained: pre-serialized chunks
|
|
6
|
+
* plus one scoped CSS string; depends on nothing in the consumer's build (ADR
|
|
7
|
+
* 0003). Built from the RenderNode tree at plugin load (see chunk.ts), so the
|
|
8
|
+
* adapter injects strings instead of walking a tree on the latency-critical
|
|
9
|
+
* first paint — and no per-framework serializer ships to the client (ADR 0008).
|
|
10
|
+
*/
|
|
11
|
+
interface Plate {
|
|
12
|
+
v: number;
|
|
13
|
+
/** Capture name; comes from the virtual-module specifier, never typed at a call site. */
|
|
14
|
+
name: string;
|
|
15
|
+
/**
|
|
16
|
+
* The root's children, pre-serialized (ADR 0008): a stitch-free run is one
|
|
17
|
+
* HTML `string`; a stitch is `{ r: name }`; a stitch-bearing element is
|
|
18
|
+
* `{ c: className, k: chunk[] }`. Null until first capture.
|
|
19
|
+
*/
|
|
20
|
+
chunks: Chunk[] | null;
|
|
21
|
+
/** The root node's own content classes (its inherited font context), if any. */
|
|
22
|
+
rootCls?: string;
|
|
23
|
+
/** Layout-relevant CSS (incl. `@media`) scoped under the plate root, paint stripped. */
|
|
24
|
+
css: string;
|
|
25
|
+
/**
|
|
26
|
+
* Child plates named by the chunks' `{ r }` stitches, resolved through the
|
|
27
|
+
* import graph (ADR 0006). Populated by the loader's generated imports, never
|
|
28
|
+
* serialized into the plates JSON; absent in production when there are no
|
|
29
|
+
* stitches. In dev the live store takes precedence, so this need not be present.
|
|
30
|
+
*/
|
|
31
|
+
refs?: Record<string, Plate>;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* One serialized child of a plate root (or of a stitch-bearing node): a
|
|
35
|
+
* stitch-free HTML run (`string`), a stitch to a child plate (`{ r: name }`),
|
|
36
|
+
* or a stitch-bearing element kept real so its inner stitches can mount
|
|
37
|
+
* (`{ c: className, k: chunk[] }`). The framework-neutral render contract: an
|
|
38
|
+
* adapter injects the strings and mounts a child plate at each stitch (ADR 0008).
|
|
39
|
+
*/
|
|
40
|
+
type Chunk = string | {
|
|
41
|
+
r: string;
|
|
42
|
+
} | {
|
|
43
|
+
c: string;
|
|
44
|
+
k: Chunk[];
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* A plate after view-merge + classify but before chunk serialization: the
|
|
48
|
+
* build-time RenderNode tree plus its scoped CSS. Produced by `mergeViews` and
|
|
49
|
+
* `capture`, then serialized into the shipped `Plate` (chunks) at load
|
|
50
|
+
* (`serializePlate`). Never shipped to the client.
|
|
51
|
+
*/
|
|
52
|
+
interface MergedPlate {
|
|
53
|
+
v: number;
|
|
54
|
+
name: string;
|
|
55
|
+
tree: RenderNode | null;
|
|
56
|
+
css: string;
|
|
57
|
+
}
|
|
58
|
+
interface PlateNode {
|
|
59
|
+
/** Plate-local id; rules reference it pre-classify. Stripped from the shipped tree. */
|
|
60
|
+
id: number;
|
|
61
|
+
/** Present on paint leaves; absent on layout containers. */
|
|
62
|
+
leaf?: LeafKind;
|
|
63
|
+
/**
|
|
64
|
+
* A stitch: render the named child plate's skeleton here instead of own
|
|
65
|
+
* structure (ADR 0006). Mutually exclusive with `leaf`/`kids`. Resolved
|
|
66
|
+
* against `Plate.refs` (prod) or the live store (dev).
|
|
67
|
+
*/
|
|
68
|
+
ref?: string;
|
|
69
|
+
kids?: PlateNode[];
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* A node in the shipped tree, after classify (ADR 0007). Carries the
|
|
73
|
+
* content-addressed style classes it needs instead of an id — the CSS targets
|
|
74
|
+
* those classes, not a per-node `data-xr` value, so node scoping (the old
|
|
75
|
+
* `nodeKey`) is gone. `cls` is a space-joined class-token list.
|
|
76
|
+
*/
|
|
77
|
+
interface RenderNode {
|
|
78
|
+
leaf?: LeafKind;
|
|
79
|
+
ref?: string;
|
|
80
|
+
cls?: string;
|
|
81
|
+
kids?: RenderNode[];
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* A captured style rule in id form — selectors are generated at render time,
|
|
85
|
+
* so view merging can remap node ids without string surgery. `ids: []`
|
|
86
|
+
* targets the plate root.
|
|
87
|
+
*/
|
|
88
|
+
interface PlateRule {
|
|
89
|
+
ids: number[];
|
|
90
|
+
decls: string[];
|
|
91
|
+
/** Media-condition stack, outermost first; conditions AND together. */
|
|
92
|
+
media?: string[];
|
|
93
|
+
/** `@container`-condition stack, outermost first; conditions AND together. Absent when none. */
|
|
94
|
+
container?: string[];
|
|
95
|
+
layered?: boolean;
|
|
96
|
+
spec: number;
|
|
97
|
+
order: number;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* One capture of a component within one viewport view — `[min, max)` in px,
|
|
101
|
+
* either side open-ended when undefined. What the dev client ships to the
|
|
102
|
+
* plugin, and what the plate file accumulates (ADR 0004).
|
|
103
|
+
*/
|
|
104
|
+
interface ViewCapture {
|
|
105
|
+
/** Viewport width at capture time. */
|
|
106
|
+
width: number;
|
|
107
|
+
min?: number;
|
|
108
|
+
max?: number;
|
|
109
|
+
tree: PlateNode;
|
|
110
|
+
rules: PlateRule[];
|
|
111
|
+
}
|
|
112
|
+
/** The committed `plates/<name>.json`: per-view captures, merged at load. */
|
|
113
|
+
interface PlateFile {
|
|
114
|
+
v: number;
|
|
115
|
+
name: string;
|
|
116
|
+
/** Width thresholds (view boundaries) derived so far. */
|
|
117
|
+
breakpoints: number[];
|
|
118
|
+
views: ViewCapture[];
|
|
119
|
+
}
|
|
120
|
+
/** The (unserialized) plate an import resolves to before anything has been captured. */
|
|
121
|
+
declare function emptyPlate(name: string): MergedPlate;
|
|
122
|
+
/**
|
|
123
|
+
* A dev-only sticky boolean toggle (get/set/subscribe), persisted per tab.
|
|
124
|
+
* Used for both "light box" (render every `<Skeleton>` regardless of readiness)
|
|
125
|
+
* and "capture" (whether browsing re-captures plates).
|
|
126
|
+
*/
|
|
127
|
+
interface ToggleStore {
|
|
128
|
+
get: () => boolean;
|
|
129
|
+
set: (value: boolean) => void;
|
|
130
|
+
subscribe: (onChange: () => void) => () => void;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Dev-only store of the freshest plate per name, updated in place when a
|
|
134
|
+
* capture lands. `<Skeleton>` reads through it so a new plate re-renders the
|
|
135
|
+
* site rather than reloading the module — which would remount the capture
|
|
136
|
+
* boundary and re-fire the capture, a feedback loop.
|
|
137
|
+
*/
|
|
138
|
+
interface PlateStore {
|
|
139
|
+
get: (name: string) => Plate | undefined;
|
|
140
|
+
subscribe: (name: string, onChange: () => void) => () => void;
|
|
141
|
+
/**
|
|
142
|
+
* Register a plate imported via the ref graph if the store has none yet — so a
|
|
143
|
+
* stitch resolves even before its child is re-captured, and survives a parent
|
|
144
|
+
* hot-swap (whose pushed plate carries no resolved `refs`). Never overwrites a
|
|
145
|
+
* live capture.
|
|
146
|
+
*/
|
|
147
|
+
seed: (name: string, plate: Plate) => void;
|
|
148
|
+
}
|
|
149
|
+
/** A view interval `[min, max)`; an open end is undefined (ADR 0004). */
|
|
150
|
+
interface Span {
|
|
151
|
+
min?: number;
|
|
152
|
+
max?: number;
|
|
153
|
+
}
|
|
154
|
+
/** A plate's detected width thresholds and the spans actually captured, from disk. */
|
|
155
|
+
interface PlateCoverage {
|
|
156
|
+
breakpoints: number[];
|
|
157
|
+
spans: Span[];
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Dev-only per-plate coverage, sourced from the committed plate files (not the
|
|
161
|
+
* session): the breakpoints detected so far and which view spans are captured.
|
|
162
|
+
* The HUD renders every band — covered ones lit, the rest dim — and the
|
|
163
|
+
* capture-all sweep derives its target widths from the breakpoints.
|
|
164
|
+
*/
|
|
165
|
+
interface CoverageStore {
|
|
166
|
+
get: () => ReadonlyMap<string, PlateCoverage>;
|
|
167
|
+
set: (name: string, coverage: PlateCoverage) => void;
|
|
168
|
+
subscribe: (onChange: () => void) => () => void;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Dev-only capture hook, installed by the dev client before the app boots.
|
|
172
|
+
* Absent in production builds, so `<Skeleton>` carries zero capture weight.
|
|
173
|
+
* `captured` returns a dispose callback (stop observing this site).
|
|
174
|
+
*/
|
|
175
|
+
interface CaptureHook {
|
|
176
|
+
captured: (name: string, el: Element, opts?: {
|
|
177
|
+
delay?: number;
|
|
178
|
+
}) => (() => void) | undefined;
|
|
179
|
+
/** Light Box toggle: force every `<Skeleton>` to its skeleton, read by `<Skeleton>`. */
|
|
180
|
+
lightbox?: ToggleStore;
|
|
181
|
+
/** Capture toggle: whether browsing re-captures plates, flipped from the HUD. */
|
|
182
|
+
capture?: ToggleStore;
|
|
183
|
+
/** Read side for `<Skeleton>`. */
|
|
184
|
+
plates?: PlateStore;
|
|
185
|
+
/** Write side for the dev client's HMR-event handler. */
|
|
186
|
+
updatePlate?: (name: string, plate: Plate) => void;
|
|
187
|
+
/** Dev-only: run the HUD-triggered capture-all-views sweep via the extension (ADR 0010). */
|
|
188
|
+
captureAllViews?: () => Promise<void>;
|
|
189
|
+
/** Dev-only per-plate breakpoints + captured spans, from disk; fed by the bootstrap. */
|
|
190
|
+
coverage?: CoverageStore;
|
|
191
|
+
}
|
|
192
|
+
declare global {
|
|
193
|
+
var __XRAY__: CaptureHook | undefined;
|
|
194
|
+
}
|
|
195
|
+
//#endregion
|
|
196
|
+
export { PlateNode as a, emptyPlate as c, PlateFile as i, MergedPlate as n, RenderNode as o, Plate as r, ViewCapture as s, LeafKind as t };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { a as ROOT_ATTR, o as ROOT_CLASS, t as BASE_CSS } from "./plate-BuzRMPx4.js";
|
|
2
|
+
import { Fragment } from "react";
|
|
3
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
//#region src/react.core.tsx
|
|
5
|
+
/** Layout-neutral wrapper for an HTML island sitting beside React stitch nodes —
|
|
6
|
+
* its children participate in the grandparent's flow, so grid/flex item counts
|
|
7
|
+
* are unchanged. */
|
|
8
|
+
const DISPLAY_CONTENTS = { display: "contents" };
|
|
9
|
+
/**
|
|
10
|
+
* Render a shipped plate's skeleton. `resolveStitch` turns a child plate name
|
|
11
|
+
* into the node that mounts it (static `refs` in prod, a store-subscribed
|
|
12
|
+
* component in dev). `nested` is true for a stitch-mounted child, which skips
|
|
13
|
+
* BASE_CSS — the outermost view already emitted it (ADR 0007). Returns null
|
|
14
|
+
* when the plate has no capture yet; the caller renders the fallback.
|
|
15
|
+
*/
|
|
16
|
+
function renderPlate(plate, resolveStitch, nested) {
|
|
17
|
+
if (!plate.chunks) return null;
|
|
18
|
+
const className = plate.rootCls ? `${ROOT_CLASS} ${plate.rootCls}` : ROOT_CLASS;
|
|
19
|
+
const rootAttrs = {
|
|
20
|
+
[ROOT_ATTR]: plate.name,
|
|
21
|
+
className,
|
|
22
|
+
"aria-hidden": true,
|
|
23
|
+
"aria-busy": true
|
|
24
|
+
};
|
|
25
|
+
const css = nested ? plate.css : `${BASE_CSS}\n${plate.css}`;
|
|
26
|
+
const chunks = plate.chunks;
|
|
27
|
+
if (chunks.length === 1 && typeof chunks[0] === "string") {
|
|
28
|
+
const html = `<style>${css}</style>${chunks[0]}`;
|
|
29
|
+
return /* @__PURE__ */ jsx("div", {
|
|
30
|
+
...rootAttrs,
|
|
31
|
+
dangerouslySetInnerHTML: { __html: html }
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
35
|
+
...rootAttrs,
|
|
36
|
+
children: [/* @__PURE__ */ jsx("style", { children: css }), renderChunks(chunks, resolveStitch)]
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Each `string` chunk is injected as a display:contents innerHTML island; each
|
|
41
|
+
* `{ r }` stitch resolves through `resolveStitch`; a `{ c, k }` node stays a
|
|
42
|
+
* real element and recurses (it holds a stitch deeper). No per-node tree walk —
|
|
43
|
+
* the strings are already serialized.
|
|
44
|
+
*/
|
|
45
|
+
function renderChunks(chunks, resolveStitch) {
|
|
46
|
+
return chunks.map((chunk, i) => {
|
|
47
|
+
if (typeof chunk === "string") return /* @__PURE__ */ jsx("div", {
|
|
48
|
+
style: DISPLAY_CONTENTS,
|
|
49
|
+
dangerouslySetInnerHTML: { __html: chunk }
|
|
50
|
+
}, i);
|
|
51
|
+
if ("r" in chunk) return /* @__PURE__ */ jsx(Fragment, { children: resolveStitch(chunk.r) }, i);
|
|
52
|
+
return /* @__PURE__ */ jsx("div", {
|
|
53
|
+
className: chunk.c,
|
|
54
|
+
children: renderChunks(chunk.k, resolveStitch)
|
|
55
|
+
}, i);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
//#endregion
|
|
59
|
+
export { renderPlate as t };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { r as Plate } from "./plate-DboxMKg-.js";
|
|
2
|
+
import { ReactNode } from "react";
|
|
3
|
+
|
|
4
|
+
//#region src/react.core.d.ts
|
|
5
|
+
/** Props accepted by the React `<Skeleton>` component. */
|
|
6
|
+
interface SkeletonProps {
|
|
7
|
+
/** The plate to render while loading, imported from `virtual:xray/plates/<name>`. */
|
|
8
|
+
plate: Plate;
|
|
9
|
+
/** Explicit readiness mode: render the Skeleton while true, then render children and capture them in dev when false. */
|
|
10
|
+
loading?: boolean;
|
|
11
|
+
/** Suspense mode: make `<Skeleton>` the Suspense boundary and use the Plate as the fallback until children resolve. */
|
|
12
|
+
suspense?: boolean;
|
|
13
|
+
/** Shown while loading when the plate has no capture yet. */
|
|
14
|
+
fallback?: ReactNode;
|
|
15
|
+
/** Override the plugin's settle delay before this site is captured (dev only). */
|
|
16
|
+
delay?: number;
|
|
17
|
+
/** Real content. In dev, these children are also the capture source once ready. */
|
|
18
|
+
children?: ReactNode;
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
export { SkeletonProps as t };
|
package/dist/react.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { t as SkeletonProps } from "./react.core-fgWG_svU.js";
|
|
2
|
+
|
|
3
|
+
//#region src/react.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Render a committed Plate while content is loading.
|
|
6
|
+
*
|
|
7
|
+
* Use `loading` when your data source exposes an explicit pending state. Use
|
|
8
|
+
* `suspense` when the child suspends; in that mode `<Skeleton>` is the Suspense
|
|
9
|
+
* boundary and the Plate is the fallback. You can also render a bare Skeleton
|
|
10
|
+
* with no children when another framework or router owns the loading boundary.
|
|
11
|
+
*
|
|
12
|
+
* In dev, the plugin aliases this component to the dev adapter. When children
|
|
13
|
+
* are ready, that adapter marks the capture boundary, waits for the subtree to
|
|
14
|
+
* settle, and sends the rendered DOM to the xray client. Nested `<Skeleton>`
|
|
15
|
+
* boundaries become Stitches so a parent Plate records a child Plate reference
|
|
16
|
+
* instead of serializing the child subtree again.
|
|
17
|
+
*
|
|
18
|
+
* In production this component ships no capture client, HUD, Light Box, store,
|
|
19
|
+
* or subscriptions. Stitches resolve from the statically imported `refs` graph.
|
|
20
|
+
*/
|
|
21
|
+
declare function Skeleton({
|
|
22
|
+
plate,
|
|
23
|
+
loading,
|
|
24
|
+
suspense,
|
|
25
|
+
fallback,
|
|
26
|
+
children
|
|
27
|
+
}: SkeletonProps): import("react").JSX.Element;
|
|
28
|
+
//#endregion
|
|
29
|
+
export { Skeleton, type SkeletonProps };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { t as SkeletonProps } from "./react.core-fgWG_svU.js";
|
|
2
|
+
|
|
3
|
+
//#region src/react.dev.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Dev `<Skeleton>`: production behavior plus the Light Box override, the
|
|
6
|
+
* live-store hot-swap, and browse-time capture. The xray plugin aliases
|
|
7
|
+
* `@hueest/xray/react` to this module in `serve`; production gets the hook-free
|
|
8
|
+
* `react.tsx`.
|
|
9
|
+
*/
|
|
10
|
+
declare function Skeleton({
|
|
11
|
+
plate,
|
|
12
|
+
loading,
|
|
13
|
+
suspense,
|
|
14
|
+
fallback,
|
|
15
|
+
delay,
|
|
16
|
+
children
|
|
17
|
+
}: SkeletonProps): import("react").JSX.Element;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { Skeleton, type SkeletonProps };
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { n as BOUNDARY_ATTR } from "./plate-BuzRMPx4.js";
|
|
2
|
+
import { t as renderPlate } from "./react.core-CqnDjfAJ.js";
|
|
3
|
+
import { Suspense, useCallback, useEffect, useRef, useSyncExternalStore } from "react";
|
|
4
|
+
import { Fragment as Fragment$1, jsx } from "react/jsx-runtime";
|
|
5
|
+
//#region src/react.dev.tsx
|
|
6
|
+
const noSubscribe = () => () => {};
|
|
7
|
+
const alwaysFalse = () => false;
|
|
8
|
+
/** True while the HUD/console "Light Box" toggle is on. */
|
|
9
|
+
function useLightBox() {
|
|
10
|
+
const lightbox = globalThis.__XRAY__?.lightbox;
|
|
11
|
+
return useSyncExternalStore(lightbox?.subscribe ?? noSubscribe, lightbox?.get ?? alwaysFalse, alwaysFalse);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The plate to render: the freshest capture from the client store (hot-swapped
|
|
15
|
+
* in place, no remount) when present, else the imported prop.
|
|
16
|
+
*/
|
|
17
|
+
function useLivePlate(plate) {
|
|
18
|
+
const store = globalThis.__XRAY__?.plates;
|
|
19
|
+
const subscribe = useCallback((onChange) => store?.subscribe(plate.name, onChange) ?? noSubscribe(), [store, plate.name]);
|
|
20
|
+
const getSnapshot = () => store?.get(plate.name) ?? plate;
|
|
21
|
+
return useSyncExternalStore(subscribe, getSnapshot, () => plate);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Dev `<Skeleton>`: production behavior plus the Light Box override, the
|
|
25
|
+
* live-store hot-swap, and browse-time capture. The xray plugin aliases
|
|
26
|
+
* `@hueest/xray/react` to this module in `serve`; production gets the hook-free
|
|
27
|
+
* `react.tsx`.
|
|
28
|
+
*/
|
|
29
|
+
function Skeleton({ plate, loading = false, suspense = false, fallback, delay, children }) {
|
|
30
|
+
const lightBoxOn = useLightBox();
|
|
31
|
+
const skeleton = /* @__PURE__ */ jsx(PlateView, {
|
|
32
|
+
plate: useLivePlate(plate),
|
|
33
|
+
fallback
|
|
34
|
+
});
|
|
35
|
+
if (lightBoxOn) return skeleton;
|
|
36
|
+
if (suspense) return /* @__PURE__ */ jsx(Suspense, {
|
|
37
|
+
fallback: skeleton,
|
|
38
|
+
children: /* @__PURE__ */ jsx(Content, {
|
|
39
|
+
plate,
|
|
40
|
+
delay,
|
|
41
|
+
children
|
|
42
|
+
})
|
|
43
|
+
});
|
|
44
|
+
if (loading) return skeleton;
|
|
45
|
+
return /* @__PURE__ */ jsx(Content, {
|
|
46
|
+
plate,
|
|
47
|
+
delay,
|
|
48
|
+
children
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
function Content(props) {
|
|
52
|
+
if (globalThis.__XRAY__ === void 0) return /* @__PURE__ */ jsx(Fragment$1, { children: props.children });
|
|
53
|
+
return /* @__PURE__ */ jsx(CaptureBoundary, { ...props });
|
|
54
|
+
}
|
|
55
|
+
function CaptureBoundary({ plate, delay, children }) {
|
|
56
|
+
const ref = useRef(null);
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
const el = ref.current;
|
|
59
|
+
if (!el) return void 0;
|
|
60
|
+
return globalThis.__XRAY__?.captured(plate.name, el, { delay });
|
|
61
|
+
}, [plate.name, delay]);
|
|
62
|
+
return /* @__PURE__ */ jsx("div", {
|
|
63
|
+
[BOUNDARY_ATTR]: plate.name,
|
|
64
|
+
style: { display: "contents" },
|
|
65
|
+
ref,
|
|
66
|
+
children
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
/** Render a plate's skeleton, seeding the live store from its resolved refs so a
|
|
70
|
+
* stitch resolves before its child is re-captured and survives a parent
|
|
71
|
+
* hot-swap (which pushes a refs-less plate). Never overwrites a live capture. */
|
|
72
|
+
function PlateView({ plate, fallback, nested = false }) {
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
const store = globalThis.__XRAY__?.plates;
|
|
75
|
+
if (!store || !plate.refs) return;
|
|
76
|
+
for (const [name, child] of Object.entries(plate.refs)) store.seed(name, child);
|
|
77
|
+
}, [plate.refs]);
|
|
78
|
+
if (!plate.chunks) return /* @__PURE__ */ jsx(Fragment$1, { children: fallback ?? null });
|
|
79
|
+
return renderPlate(plate, (name) => /* @__PURE__ */ jsx(RefNode, {
|
|
80
|
+
name,
|
|
81
|
+
staticRefs: plate.refs
|
|
82
|
+
}), nested);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* A stitch in dev: resolve the child plate from the live store (so re-capturing
|
|
86
|
+
* it hot-swaps it inside every parent), falling back to the parent's statically
|
|
87
|
+
* imported `refs` until the first capture lands.
|
|
88
|
+
*/
|
|
89
|
+
function RefNode({ name, staticRefs }) {
|
|
90
|
+
const store = globalThis.__XRAY__?.plates;
|
|
91
|
+
const subscribe = useCallback((onChange) => store?.subscribe(name, onChange) ?? noSubscribe(), [store, name]);
|
|
92
|
+
const fallback = staticRefs?.[name];
|
|
93
|
+
const child = useSyncExternalStore(subscribe, () => store?.get(name) ?? fallback, () => fallback);
|
|
94
|
+
if (!child) return null;
|
|
95
|
+
return /* @__PURE__ */ jsx(PlateView, {
|
|
96
|
+
plate: child,
|
|
97
|
+
nested: true
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
//#endregion
|
|
101
|
+
export { Skeleton };
|
package/dist/react.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { t as renderPlate } from "./react.core-CqnDjfAJ.js";
|
|
2
|
+
import { Suspense } from "react";
|
|
3
|
+
import { Fragment as Fragment$1, jsx } from "react/jsx-runtime";
|
|
4
|
+
//#region src/react.tsx
|
|
5
|
+
/**
|
|
6
|
+
* React adapter for rendering committed Plates through `<Skeleton>`.
|
|
7
|
+
*
|
|
8
|
+
* In production this adapter is hook-free and renders only committed Plate data.
|
|
9
|
+
* During `vite serve`, `xrayVitePlugin()` aliases this export to the dev adapter
|
|
10
|
+
* so ready children can be captured without shipping the capture client, HUD, or
|
|
11
|
+
* Light Box code in production builds.
|
|
12
|
+
*
|
|
13
|
+
* @module @hueest/xray/react
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Render a committed Plate while content is loading.
|
|
17
|
+
*
|
|
18
|
+
* Use `loading` when your data source exposes an explicit pending state. Use
|
|
19
|
+
* `suspense` when the child suspends; in that mode `<Skeleton>` is the Suspense
|
|
20
|
+
* boundary and the Plate is the fallback. You can also render a bare Skeleton
|
|
21
|
+
* with no children when another framework or router owns the loading boundary.
|
|
22
|
+
*
|
|
23
|
+
* In dev, the plugin aliases this component to the dev adapter. When children
|
|
24
|
+
* are ready, that adapter marks the capture boundary, waits for the subtree to
|
|
25
|
+
* settle, and sends the rendered DOM to the xray client. Nested `<Skeleton>`
|
|
26
|
+
* boundaries become Stitches so a parent Plate records a child Plate reference
|
|
27
|
+
* instead of serializing the child subtree again.
|
|
28
|
+
*
|
|
29
|
+
* In production this component ships no capture client, HUD, Light Box, store,
|
|
30
|
+
* or subscriptions. Stitches resolve from the statically imported `refs` graph.
|
|
31
|
+
*/
|
|
32
|
+
function Skeleton({ plate, loading = false, suspense = false, fallback, children }) {
|
|
33
|
+
const skeleton = /* @__PURE__ */ jsx(PlateView, {
|
|
34
|
+
plate,
|
|
35
|
+
fallback
|
|
36
|
+
});
|
|
37
|
+
if (suspense) return /* @__PURE__ */ jsx(Suspense, {
|
|
38
|
+
fallback: skeleton,
|
|
39
|
+
children
|
|
40
|
+
});
|
|
41
|
+
if (loading) return skeleton;
|
|
42
|
+
return /* @__PURE__ */ jsx(Fragment$1, { children });
|
|
43
|
+
}
|
|
44
|
+
/** Render a plate's skeleton, mounting each stitch's child plate from `refs`. */
|
|
45
|
+
function PlateView({ plate, fallback }) {
|
|
46
|
+
if (!plate.chunks) return /* @__PURE__ */ jsx(Fragment$1, { children: fallback ?? null });
|
|
47
|
+
return renderStatic(plate, false);
|
|
48
|
+
}
|
|
49
|
+
/** Resolve stitches statically through the import graph (ADR 0006) — pure
|
|
50
|
+
* recursion, no store, no subscription. An unknown child renders nothing. */
|
|
51
|
+
function renderStatic(plate, nested) {
|
|
52
|
+
return renderPlate(plate, (name) => {
|
|
53
|
+
const child = plate.refs?.[name];
|
|
54
|
+
return child ? renderStatic(child, true) : null;
|
|
55
|
+
}, nested);
|
|
56
|
+
}
|
|
57
|
+
//#endregion
|
|
58
|
+
export { Skeleton };
|