@takazudo/zudo-sg 0.4.1 → 0.5.1
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 +77 -0
- package/README.md +281 -61
- package/dist/catalog/catalog-thumb.d.ts +1 -6
- package/dist/catalog/catalog-thumb.js +1 -2
- package/dist/catalog/component-thumb.d.ts +1 -6
- package/dist/catalog/component-thumb.js +8 -7
- package/dist/catalog/descriptor-thumb.d.ts +1 -6
- package/dist/catalog/descriptor-thumb.js +1 -2
- package/dist/chrome/_styleguide-layout.d.ts +8 -9
- package/dist/chrome/_styleguide-layout.js +3 -6
- package/dist/chrome/panel-scripts.d.ts +1 -3
- package/dist/chrome/panel-scripts.js +3 -3
- package/dist/cli/scaffold/component-scaffold.js +35 -16
- package/dist/code-panel/code-panel.d.ts +2 -8
- package/dist/code-panel/code-panel.js +47 -38
- package/dist/code-panel/copy-button.d.ts +1 -7
- package/dist/code-panel/copy-button.js +31 -48
- package/dist/code-panel/copy-text.d.ts +1 -0
- package/dist/code-panel/copy-text.js +26 -0
- package/dist/code-panel/css-injection.d.ts +11 -5
- package/dist/code-panel/css-injection.js +179 -25
- package/dist/code-panel/source-editor.d.ts +1 -2
- package/dist/code-panel/source-editor.js +17 -18
- package/dist/config/index.d.ts +3 -0
- package/dist/config/index.js +6 -1
- package/dist/config/wind.d.ts +265 -0
- package/dist/config/wind.js +133 -0
- package/dist/plugins/preview-css.d.ts +9 -7
- package/dist/plugins/preview-css.js +58 -37
- package/dist/plugins/routes.d.ts +2 -0
- package/dist/plugins/routes.js +7 -3
- package/dist/preview/detail-workbench.d.ts +3 -6
- package/dist/preview/detail-workbench.js +103 -65
- package/dist/preview/external-runtime.d.ts +117 -0
- package/dist/preview/external-runtime.js +121 -0
- package/dist/preview/index.d.ts +4 -2
- package/dist/preview/index.js +7 -7
- package/dist/preview/preview-app.d.ts +2 -5
- package/dist/preview/preview-app.js +76 -46
- package/dist/preview/runtime-controller.d.ts +34 -0
- package/dist/preview/runtime-controller.js +302 -0
- package/dist/preview/variant-frame-config.d.ts +47 -0
- package/dist/preview/variant-frame-config.js +50 -0
- package/dist/preview/variant-frame.d.ts +12 -53
- package/dist/preview/variant-frame.js +313 -158
- package/dist/preview-css/compile.d.ts +15 -29
- package/dist/preview-css/compile.js +183 -31
- package/dist/registry/catalog.d.ts +2 -0
- package/dist/registry/catalog.js +2 -1
- package/dist/registry/descriptors.d.ts +3 -0
- package/dist/registry/descriptors.js +6 -1
- package/dist/registry/external-catalog-node.d.ts +65 -0
- package/dist/registry/external-catalog-node.js +220 -0
- package/dist/registry/external-catalog.d.ts +44 -0
- package/dist/registry/external-catalog.js +72 -0
- package/dist/registry/index.d.ts +2 -0
- package/dist/registry/index.js +4 -0
- package/dist/search/catalog-filter.d.ts +2 -6
- package/dist/search/catalog-filter.js +50 -42
- package/dist/sg-context.d.ts +2 -0
- package/dist/stories/types.d.ts +5 -3
- package/dist/token-dashboard/create-token-dashboards.d.ts +3 -5
- package/dist/token-dashboard/create-token-dashboards.js +14 -44
- package/dist/token-dashboard/dashboard-inventory.d.ts +1 -1
- package/dist/token-dashboard/token-dashboard-adapter.d.ts +2 -0
- package/dist/token-dashboard/token-dashboard-adapter.js +9 -0
- package/dist/token-dashboard/token-dashboard-mount.d.ts +6 -0
- package/dist/token-dashboard/token-dashboard-mount.js +33 -0
- package/dist/token-tweak/iframe-css-vars-bridge.d.ts +14 -6
- package/dist/token-tweak/iframe-css-vars-bridge.js +46 -17
- package/dist/token-tweak/index.d.ts +1 -1
- package/dist/token-tweak/index.js +2 -0
- package/dist/token-tweak/preview-iframe-registry.d.ts +10 -1
- package/dist/token-tweak/preview-iframe-registry.js +48 -7
- package/dist/token-tweak/preview-token-panel-bootstrap.d.ts +1 -6
- package/dist/token-tweak/preview-token-panel-bootstrap.js +4 -2
- package/dist/token-tweak/preview-tokens-button.d.ts +1 -5
- package/dist/token-tweak/preview-tokens-button.js +5 -4
- package/dist/wind.json +119 -0
- package/package.json +34 -22
- package/routes-src/_chrome.tsx +1 -3
- package/routes-src/_preview-app.tsx +3 -8
- package/routes-src/components-index.tsx +5 -10
- package/routes-src/components-preview.tsx +3 -9
- package/routes-src/components-slug.tsx +33 -33
- package/routes-src/tokens.tsx +4 -9
- package/styles.css +17 -11
- package/dist/safelist.css +0 -2
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,83 @@ All notable changes to `@takazudo/zudo-sg` are documented in this file.
|
|
|
4
4
|
|
|
5
5
|
The format is based on Keep a Changelog, and release notes are generated from the changelog MDX pages.
|
|
6
6
|
|
|
7
|
+
## [0.5.1] - 2026-10-12
|
|
8
|
+
|
|
9
|
+
This release adds an opt-in, same-origin external preview runtime contract with
|
|
10
|
+
stricter catalog checks, so a host can render React 19 fixtures in its own
|
|
11
|
+
external document. It also fixes preview lifecycle bugs and updates the engine's
|
|
12
|
+
dependencies after a security audit. Existing module stories and
|
|
13
|
+
framework-free descriptors keep their current behavior.
|
|
14
|
+
|
|
15
|
+
### Features
|
|
16
|
+
|
|
17
|
+
- New `@takazudo/zudo-sg/preview/external-runtime`, `preview/runtime`,
|
|
18
|
+
`registry/external-catalog`, and `registry/external-catalog-node` exports
|
|
19
|
+
define a strict external preview and catalog contract: fixture identity,
|
|
20
|
+
serializable controls, ready/request-ready replay, height, theme, the token
|
|
21
|
+
bridge, live CSS, visible errors, and deterministic cleanup. React and
|
|
22
|
+
ReactDOM stay inside the host's external fixture document; the engine does not
|
|
23
|
+
depend on them.
|
|
24
|
+
- External fixtures keep their root, hooks, focus, and editor state through
|
|
25
|
+
props updates and ordinary prop Reset. A separate full fixture reset remounts
|
|
26
|
+
fixture resources but keeps the current controls, theme, token edits, and
|
|
27
|
+
live CSS.
|
|
28
|
+
- External catalog generation checks descriptor slugs and variant IDs, loader
|
|
29
|
+
keys, displayed-source keys, and thumbnail keys against each other. Thumbnails
|
|
30
|
+
must be real captures of the named fixture or carry an explicit placeholder
|
|
31
|
+
or failed-capture state. Descriptor sources can be shown in the real code
|
|
32
|
+
panel.
|
|
33
|
+
|
|
34
|
+
### Bug Fixes
|
|
35
|
+
|
|
36
|
+
- Reject sparse or malformed external catalog manifests, and messages from the
|
|
37
|
+
wrong origin or window or with stale document or variant identity.
|
|
38
|
+
- Keep owner-scoped live CSS when an iframe becomes ready again, recover
|
|
39
|
+
external fixtures with the current preview state, and keep render errors
|
|
40
|
+
reported during fixture updates visible.
|
|
41
|
+
- Keep mixed-property batches together when the preview token panel resets.
|
|
42
|
+
- Restore code-panel syntax highlighting with a CodeMirror/Lezer update that
|
|
43
|
+
resolves one shared Lezer identity (`@codemirror/language` 6.13.1,
|
|
44
|
+
`@codemirror/state` 6.7.6, `@codemirror/commands` 6.11.1). Hosts that keep
|
|
45
|
+
an older `@lezer/common` in their own lockfile should run `pnpm dedupe`.
|
|
46
|
+
- Fix security advisories in development and test dependencies, including the
|
|
47
|
+
move from Happy DOM 16 to 20.
|
|
48
|
+
|
|
49
|
+
## [0.5.0] - 2026-10-12
|
|
50
|
+
|
|
51
|
+
This release ports the styleguide engine to zfb 4.3.1 and zudo-doc 6.0.0.
|
|
52
|
+
Catalog, preview, descriptor mode, and token editing remain available on the
|
|
53
|
+
new renderer and CSS pipeline.
|
|
54
|
+
|
|
55
|
+
### Breaking Changes
|
|
56
|
+
|
|
57
|
+
- Hosts must use zfb 4.3.1 or later in the 4.x line, zudo-doc 6.0.0 or later in
|
|
58
|
+
the 6.x line, and zdtp 0.8.6 or later in the 0.8.x line. Story renderers and
|
|
59
|
+
engine route components use zudo-react instead of Preact. Hosts should follow
|
|
60
|
+
the zfb 4 and zudo-doc 6 migration guides before upgrading.
|
|
61
|
+
- The engine now publishes a `wind.json` utility manifest in place of its
|
|
62
|
+
Tailwind safelist stylesheet. Host wind configuration must include the engine
|
|
63
|
+
manifest and its declared CSS variables; the old Tailwind source and theme
|
|
64
|
+
directives no longer generate engine utilities.
|
|
65
|
+
|
|
66
|
+
### Features
|
|
67
|
+
|
|
68
|
+
- Render the catalog, thumbnails, detail workbench, preview frames, and search
|
|
69
|
+
islands with zudo-react. Descriptor mode and external preview routes retain
|
|
70
|
+
their framework-free data and message contracts.
|
|
71
|
+
- Compile the isolated preview stylesheet through the `zfb css` CLI with
|
|
72
|
+
preview-root scoping, preserving the preview URL and host override behavior.
|
|
73
|
+
- Keep `/tokens` available through a client-mounted zdtp dashboard adapter with
|
|
74
|
+
a truthful server-rendered loading shell. The engine owns the adapter's
|
|
75
|
+
Preact dependency; hosts do not need a Preact renderer.
|
|
76
|
+
|
|
77
|
+
### Bug Fixes
|
|
78
|
+
|
|
79
|
+
- Serve preview CSS correctly from a host mounted under a non-root base path in
|
|
80
|
+
both development and preview mode.
|
|
81
|
+
- Activate the engine-route preview token panel after hydration so early clicks
|
|
82
|
+
and SPA navigation keep working in packed foreign hosts.
|
|
83
|
+
|
|
7
84
|
## [0.4.1] - 2026-09-27
|
|
8
85
|
|
|
9
86
|
This release replaces the code panel's fixed dark editor theme with an
|
package/README.md
CHANGED
|
@@ -22,13 +22,13 @@ dogfoods the engine as its own styleguide host — see
|
|
|
22
22
|
`Story<P>`, `StoryControl<P>`, `StoryModule`, `defineStory`. Categories are
|
|
23
23
|
open, host-ordered data (`categoryOrder: string[]`), never a closed type.
|
|
24
24
|
- A standalone preview stylesheet compiler
|
|
25
|
-
(`@takazudo/zudo-sg/plugins/preview-css`) that
|
|
26
|
-
|
|
27
|
-
`:root[data-sg-preview-doc]` so it coexists with the
|
|
28
|
-
stylesheet.
|
|
29
|
-
- Generated
|
|
30
|
-
`@takazudo/zudo-sg/styles.css`) so the catalog
|
|
31
|
-
|
|
25
|
+
(`@takazudo/zudo-sg/plugins/preview-css`) that invokes the host-installed
|
|
26
|
+
`zfb css` command with the composed wind config and component sources, then
|
|
27
|
+
scopes the output under `:root[data-sg-preview-doc]` so it coexists with the
|
|
28
|
+
host's global stylesheet.
|
|
29
|
+
- Generated wind manifest and chrome styles (`@takazudo/zudo-sg/wind.json`,
|
|
30
|
+
`@takazudo/zudo-sg/styles.css`) so zfb includes the catalog's utility
|
|
31
|
+
candidates without depending on the host's source scan.
|
|
32
32
|
- Token dashboards and a preview design-token panel, driven by a
|
|
33
33
|
`gen-token-manifest`-produced manifest.
|
|
34
34
|
|
|
@@ -96,9 +96,11 @@ inside detail-page iframes.
|
|
|
96
96
|
|
|
97
97
|
## Framework scope
|
|
98
98
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
99
|
+
Module-mode stories use zfb's zudo-react runtime. Hosts using another
|
|
100
|
+
framework can use descriptor mode with an external preview document; see the
|
|
101
|
+
ADR's "Framework scope" decision. The `/tokens` dashboard is the one renderer
|
|
102
|
+
exception: its opaque adapter mounts zdtp's Preact widget internally, with
|
|
103
|
+
Preact installed as an engine dependency rather than a host peer.
|
|
102
104
|
|
|
103
105
|
## Quick start with the initializer
|
|
104
106
|
|
|
@@ -113,7 +115,7 @@ pnpm gen-token-manifest
|
|
|
113
115
|
pnpm dev
|
|
114
116
|
```
|
|
115
117
|
|
|
116
|
-
It copies a private starter with three example
|
|
118
|
+
It copies a private starter with three example zudo-react components, stories,
|
|
117
119
|
token CSS, a preview entry, and the zfb/zudo-doc composition already wired.
|
|
118
120
|
The CLI prints the same next steps after scaffolding.
|
|
119
121
|
|
|
@@ -130,20 +132,20 @@ output as drift and never writes it.
|
|
|
130
132
|
## Installation
|
|
131
133
|
|
|
132
134
|
```sh
|
|
133
|
-
pnpm add @takazudo/zudo-sg@latest @takazudo/zfb@^
|
|
135
|
+
pnpm add @takazudo/zudo-sg@latest @takazudo/zfb@^4.3.1 @takazudo/zfb-md-wasm@^4.3.1 @takazudo/zfb-runtime@^4.3.1 @takazudo/zudo-doc@^6.0.0 @takazudo/zdtp@^0.8.6 diff@^8.0.4 katex@^0.16.38 zod@^4.3.6
|
|
134
136
|
```
|
|
135
137
|
|
|
136
|
-
The engine peers are `@takazudo/zfb ^
|
|
137
|
-
`@takazudo/zdtp ^0.8.
|
|
138
|
-
the injected `/tokens` route
|
|
138
|
+
The engine peers are `@takazudo/zfb ^4.3.1`, `@takazudo/zudo-doc ^6.0.0`,
|
|
139
|
+
and `@takazudo/zdtp ^0.8.6`. `@takazudo/zdtp` is required:
|
|
140
|
+
the injected `/tokens` route loads its dashboard through the engine-owned
|
|
141
|
+
opaque Preact adapter. Preact is a regular engine dependency, not a host peer. The
|
|
139
142
|
`@takazudo/zfb-md-wasm`, `@takazudo/zfb-runtime`, `diff`, `katex`, and `zod`
|
|
140
143
|
entries are prerequisites inherited from zfb/zudo-doc; zudo-doc's published
|
|
141
144
|
route dist imports `diff` and `katex` even when those features are disabled
|
|
142
145
|
(see [zudolab/zudo-doc#4206](https://github.com/zudolab/zudo-doc/issues/4206)).
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
fixture dependency set.
|
|
146
|
+
The host renders components with zudo-react and compiles preview utilities with
|
|
147
|
+
zfb's zudo-wind compiler. The command above reproduces the full fixture
|
|
148
|
+
dependency set.
|
|
147
149
|
|
|
148
150
|
Keep the `tokens` block in `zudo-sg.config.mjs`: the initializer's config
|
|
149
151
|
typing treats it as required, and `gen-token-manifest` needs its two CSS paths
|
|
@@ -180,11 +182,11 @@ control. Any non-empty host navigation stays authoritative; set
|
|
|
180
182
|
`chromeDefaults: false` in the second argument to keep an intentionally empty
|
|
181
183
|
header. The engine requires `packageOwnedRoutes: true` on the host (its
|
|
182
184
|
routes import zudo-doc's route-context virtual modules). On the engine's zfb
|
|
183
|
-
peer floor (
|
|
185
|
+
peer floor (4.3.1) nothing else is needed: `zfb dev` seeds its island
|
|
184
186
|
scanner from the injected routes. `@takazudo/zudo-sg/islands` remains
|
|
185
187
|
exported as a side-effect module that statically imports every engine
|
|
186
188
|
island — importing it once from a host `pages/` file is optional and
|
|
187
|
-
harmless (it was required
|
|
189
|
+
harmless (it was required before zfb 2.18.0).
|
|
188
190
|
|
|
189
191
|
`uiPackageName` is optional. When set, it names the package used in generated
|
|
190
192
|
usage snippets and catalog labels; when omitted, scaffolded usage snippets
|
|
@@ -208,25 +210,15 @@ this entry already. Use this import order, replacing `ui-tokens.css` with
|
|
|
208
210
|
your own token stylesheet as needed:
|
|
209
211
|
|
|
210
212
|
```css
|
|
211
|
-
@layer
|
|
212
|
-
/* One element reset: theme.css resets color tokens, not elements. */
|
|
213
|
-
@import "tailwindcss/preflight" layer(zd-preflight);
|
|
214
|
-
@import "tailwindcss/utilities";
|
|
213
|
+
@layer zw-reset, zd-flow;
|
|
215
214
|
@import "@takazudo/zudo-doc/theme.css";
|
|
216
215
|
@import "./ui-tokens.css";
|
|
217
216
|
/* Add your component package stylesheet here. */
|
|
218
|
-
@import "@takazudo/zudo-doc/safelist.css";
|
|
219
217
|
@import "@takazudo/zudo-doc/content.css";
|
|
220
218
|
@import "@takazudo/zudo-doc/features.css";
|
|
221
219
|
@import "@takazudo/zudo-doc/page-loading.css";
|
|
222
220
|
@import "@takazudo/zdtp/dashboard/styles.css";
|
|
223
221
|
@import "@takazudo/zudo-sg/styles.css";
|
|
224
|
-
@import "@takazudo/zudo-sg/safelist.css";
|
|
225
|
-
|
|
226
|
-
/* zfb global-entry paths are project-root-relative; add your UI package here. */
|
|
227
|
-
@source "pages/**/*.{tsx,ts,jsx,js}";
|
|
228
|
-
@source "ui/**/*.{tsx,ts,jsx,js,mdx,md}";
|
|
229
|
-
@source "src/content/**/*.{mdx,md}";
|
|
230
222
|
```
|
|
231
223
|
|
|
232
224
|
### Three token worlds and the engine override hook
|
|
@@ -235,15 +227,15 @@ The host contains three independent color-token worlds:
|
|
|
235
227
|
|
|
236
228
|
- zudo-doc's `--zd-*` roles style the documentation shell and doc chrome.
|
|
237
229
|
- zudo-sg's raw `--sg-*` roles style the catalog engine chrome.
|
|
238
|
-
- The host component library owns its own
|
|
230
|
+
- The host component library owns its own `:root` color tokens, usually the
|
|
239
231
|
`--color-*` semantic roles used by previews.
|
|
240
232
|
|
|
241
233
|
The engine's eleven public chrome roles are `--sg-bg`, `--sg-fg`, `--sg-surface`,
|
|
242
234
|
`--sg-surface-2`, `--sg-border`, `--sg-border-strong`, `--sg-muted`, `--sg-accent`,
|
|
243
235
|
`--sg-on-accent`, `--sg-focus`, and `--sg-success`. They are plain properties in a
|
|
244
|
-
zero-specificity `:where(:root)` block, not an engine
|
|
245
|
-
`theme.css`
|
|
246
|
-
the engine
|
|
236
|
+
zero-specificity `:where(:root)` block, not an engine color tier. zudo-doc 6's
|
|
237
|
+
`theme.css` supplies package token values without resetting host `--color-*`
|
|
238
|
+
properties; the engine's raw `--sg-*` namespace remains separate.
|
|
247
239
|
|
|
248
240
|
Override engine chrome from the host with an ordinary, unlayered root rule:
|
|
249
241
|
|
|
@@ -270,31 +262,259 @@ since island props must be JSON-serializable. See
|
|
|
270
262
|
[Tokens and preview CSS](../../src/content/docs/architecture/tokens-and-preview-css.mdx)
|
|
271
263
|
for the full token list and override example.
|
|
272
264
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
265
|
+
Declare host tokens as ordinary `:root` custom properties and map utilities to
|
|
266
|
+
those live variables in `wind.tokens`. Pass the host's `wind` configuration in
|
|
267
|
+
the preset fragment given to `withZudoSg()`. The helper deep-merges engine tokens
|
|
268
|
+
with explicit host entries last, preserves host source controls, and registers
|
|
269
|
+
`@takazudo/zudo-sg/wind.json` automatically. Hosts need no manual manifest import.
|
|
270
|
+
The defaults declare sm/md/lg/xl at 640/768/1024/1280px, strict compilation,
|
|
271
|
+
`dark: false`, `reset: "owned-v1"` and utilities placed before authored CSS.
|
|
272
|
+
|
|
273
|
+
Keep utility overrides and engine styles unlayered. The `zw-reset` layer precedes
|
|
274
|
+
`zd-flow`; the dashboard stylesheet belongs after zudo-doc content CSS.
|
|
275
|
+
Configure consumer source roots in `wind.sources`; the engine manifest covers
|
|
276
|
+
only engine utility candidates.
|
|
277
|
+
|
|
278
|
+
`previewStyles` remains an independent CSS entry containing your component
|
|
279
|
+
tokens and authored component styles. The preview plugin invokes the host's
|
|
280
|
+
installed `zfb css` with composed wind configuration and component roots, then
|
|
281
|
+
scopes token roots to `:root[data-sg-preview-doc]`. CSS imports and component
|
|
282
|
+
source changes refresh without a restart. Host config or imported token-config
|
|
283
|
+
changes require zfb config reload/restart so the snapshot contains fresh data.
|
|
284
|
+
This token precedence rule does not isolate every host stylesheet selector.
|
|
285
|
+
|
|
286
|
+
## External runtime contracts
|
|
287
|
+
|
|
288
|
+
The public leaf modules `@takazudo/zudo-sg/preview/external-runtime` and
|
|
289
|
+
`@takazudo/zudo-sg/registry/external-catalog` contain renderer-free types and
|
|
290
|
+
validators. They can be imported in Node/SSR without a browser. React,
|
|
291
|
+
ReactDOM, fixture loaders and component closures belong only in the host's
|
|
292
|
+
separately built same-origin preview document. The engine shell and catalog
|
|
293
|
+
stay zudo-react; the opaque Preact/zdtp adapter remains independent.
|
|
294
|
+
|
|
295
|
+
These contracts are additive. `preview/messages` remains import-free and
|
|
296
|
+
continues accepting legacy messages with no `v` and current `v: 1` messages.
|
|
297
|
+
The strict extension uses **both** `v: 1` and `runtimeVersion: 1`; it does not
|
|
298
|
+
reinterpret legacy messages. `ExternalRuntimeMode` is `"legacy" |
|
|
299
|
+
"external-v1"`. Select strict mode at the parent boundary before the first
|
|
300
|
+
message: a strict frame must never fall back to an identity-less legacy ready,
|
|
301
|
+
including during startup. `hasExternalRuntimeMarker()` also lets a legacy
|
|
302
|
+
receiver identify and reject malformed extension traffic instead of treating
|
|
303
|
+
it as legacy. Configure `externalPreview: { url: "/frame/", runtime:
|
|
304
|
+
"external-v1" }` to select strict mode in the injected detail route. Direct
|
|
305
|
+
`VariantFrame` and `DetailWorkbench` users pass `runtime="external-v1"`.
|
|
306
|
+
Omitting it preserves legacy module/vanilla behavior.
|
|
307
|
+
|
|
308
|
+
Import `createExternalPreviewRuntime` from `@takazudo/zudo-sg/preview/runtime`
|
|
309
|
+
inside your external document's entrypoint. Pass `mount` (the renderer-owned
|
|
310
|
+
`ExternalFixtureMount`), optional `initialProps`, and `fullReset: true` when
|
|
311
|
+
that fixture supports disposal/remount. Optional `target`, `identity`,
|
|
312
|
+
`onTheme` and `measureHeight` customize the document, query identity, host
|
|
313
|
+
theme side effects and height measurement. The function installs the strict
|
|
314
|
+
receiver and token receiver, mounts the fixture, and returns a controller;
|
|
315
|
+
importing the module alone installs nothing.
|
|
316
|
+
|
|
317
|
+
`controller.getSnapshot()` returns copied `{identity, ready, error}` state.
|
|
318
|
+
`controller.whenStable()` waits for the committed mount, queued prop updates
|
|
319
|
+
and optional fixture stability barrier, then returns the actual runtime
|
|
320
|
+
identity. It rejects errors, disposal/reset or props changes during the wait;
|
|
321
|
+
capture adapters can retry a changed fixture explicitly. Standalone top-level
|
|
322
|
+
capture documents receive a local session identity and emit no parent
|
|
323
|
+
messages. A host may expose its controller to its own capture adapter; the
|
|
324
|
+
engine installs no global capture object. `reportError`, `reportHeight` and
|
|
325
|
+
idempotent asynchronous `dispose` complete the controller API.
|
|
326
|
+
Explicit `dispose()` rejects if fixture cleanup fails. Cleanup failures also
|
|
327
|
+
reach the optional `onCleanupError` callback (default: `console.error`),
|
|
328
|
+
including late cancelled mounts and page unload; they never replace a newer
|
|
329
|
+
fixture's error state. Page unload consumes the already reported rejection.
|
|
330
|
+
Returning to a disposed document from the browser back/forward cache reloads
|
|
331
|
+
that document once to create fresh resources and identity. Explicit disposal
|
|
332
|
+
removes this restoration listener as well.
|
|
333
|
+
|
|
334
|
+
### Identity, readiness and ordering
|
|
335
|
+
|
|
336
|
+
The parent sends `sg:requestReady` with `slug`, `variant`, and a fresh
|
|
337
|
+
`sessionId` challenge, plus the two version fields. Create a new unpredictable
|
|
338
|
+
session on iframe load and variant navigation, invalidate previous readiness,
|
|
339
|
+
height, document binding and errors, and retain the latest host state. A
|
|
340
|
+
same-URL reload requires this transition too: `contentWindow` can retain the
|
|
341
|
+
same WindowProxy after its document changes.
|
|
342
|
+
|
|
343
|
+
The document creates its own unpredictable `documentId`. Its committed
|
|
344
|
+
`sg:ready` echoes the challenge and adds `generation: 0`, `sequence`, and
|
|
345
|
+
`capabilities: { fullReset: boolean }`. A ready means the fixture mounted and
|
|
346
|
+
committed successfully, not merely that message listeners exist. A repeated
|
|
347
|
+
request re-announces the same committed document without remounting it. A
|
|
348
|
+
mount/import failure sends `sg:runtimeError` instead of successful ready.
|
|
349
|
+
|
|
350
|
+
All document-bound messages carry the exact
|
|
351
|
+
`{slug, variant, sessionId, documentId, generation}` identity and a
|
|
352
|
+
nonnegative safe-integer `sequence`. Sequence counters are independent per
|
|
353
|
+
sender and per session/generation. Validate the complete message, exact
|
|
354
|
+
same-origin and source window, current identity, and then monotonically
|
|
355
|
+
increasing sequence **before** mutating state or advancing the receive
|
|
356
|
+
watermark. `isExternalRuntimeMessageEvent()`,
|
|
357
|
+
`matchesExternalRuntimeIdentity()` and `isNewExternalRuntimeSequence()` are
|
|
358
|
+
separate pure checks; none maintains hidden state. Initialize a receive
|
|
359
|
+
watermark to `-1`. Reject opaque `"null"` origins and unknown/null sources.
|
|
360
|
+
|
|
361
|
+
A parent may initially bind a document from a valid ready or error answering
|
|
362
|
+
its current challenge and expected generation. Once bound, another document
|
|
363
|
+
cannot replace it without a new host session. Only an acknowledged full
|
|
364
|
+
reset can advance generation. A stale ready/error/height or malformed
|
|
365
|
+
high-sequence message must not affect the active document or its watermark.
|
|
366
|
+
Duplicate readiness may replay current snapshots, but cannot reset a fixture.
|
|
367
|
+
|
|
368
|
+
### Updates, resets, errors and resource ownership
|
|
369
|
+
|
|
370
|
+
`sg:updateProps` contains a complete `SerializableProps` snapshot that replaces
|
|
371
|
+
previous control overrides. `isSerializableProps()` accepts finite JSON values,
|
|
372
|
+
rejecting callbacks/elements, undefined, cycles, accessors, symbols, prototype
|
|
373
|
+
keys, sparse arrays, and nesting beyond 32 object/array levels. Merge fixture
|
|
374
|
+
base props, declared control defaults and this current snapshot in that order.
|
|
375
|
+
Ordinary prop edits and the controls' **Reset** update the existing renderer
|
|
376
|
+
root and preserve hooks, focus and editor state. Existing module stories
|
|
377
|
+
continue their deliberate remount-on-args behavior.
|
|
378
|
+
|
|
379
|
+
Only runtimes advertising `fullReset: true` receive `sg:resetFixture`. It
|
|
380
|
+
targets the current identity and supplies `nextGeneration: generation + 1`.
|
|
381
|
+
The runtime disposes the current fixture, advances generation, clears its
|
|
382
|
+
per-generation sequence counters and mounts a fresh fixture with the retained
|
|
383
|
+
props. Ready/error then identifies the new generation. Reset replay is rejected
|
|
384
|
+
by identity/sequence checks. The parent retains controls, resolved theme,
|
|
385
|
+
token overrides and live CSS; it replays current state after accepted ready.
|
|
386
|
+
Changing variant seeds that variant's controls; reloading the same variant
|
|
387
|
+
retains its edited values.
|
|
388
|
+
|
|
389
|
+
`ExternalFixtureMount(context)` resolves only after a committed mount and
|
|
390
|
+
returns an `ExternalFixtureInstance` with `update(props)` and `dispose()`.
|
|
391
|
+
Its optional `whenStable()` is a fixture-specific capture barrier after
|
|
392
|
+
commit, for fonts, editor initialization or other async resources. The mount
|
|
393
|
+
context supplies current identity/props, an abort signal and `reportError()`.
|
|
394
|
+
Abort on reset/disposal; check identity after every awaited operation and
|
|
395
|
+
dispose any late instance rather than installing it. Serialize asynchronous
|
|
396
|
+
updates and resets so an older update cannot overwrite newer props.
|
|
397
|
+
|
|
398
|
+
The renderer owns its roots, hooks, portals, editors, workers and fixture
|
|
399
|
+
subscriptions. The runtime owns its message listeners, observers and timers;
|
|
400
|
+
final disposal removes them deterministically. Full fixture reset must not
|
|
401
|
+
erase host-owned theme, token overrides or the live-CSS style element.
|
|
402
|
+
|
|
403
|
+
Errors use `sg:runtimeError` and `{code, message, recoverable}`. Codes are
|
|
404
|
+
`unknown-fixture`, `import`, `render`, and `asset`; display messages as text,
|
|
405
|
+
never HTML or an empty successful tile. React error boundaries must report
|
|
406
|
+
render failures. An initial failure can bind the current document without
|
|
407
|
+
claiming readiness; show a reload/retry action. A successful recovery clears
|
|
408
|
+
only errors for its accepted identity, never another document's error.
|
|
409
|
+
|
|
410
|
+
Tokens retain their separate `zudo-sg-token-tweak-bridge` apply/clear/ready
|
|
411
|
+
envelopes, with exact parent/source and validated custom-property payloads.
|
|
412
|
+
Live CSS retains direct same-origin `contentDocument` injection into
|
|
413
|
+
`style[data-sg-injected-css]`. They are not new runtime message types. Keep
|
|
414
|
+
their snapshots at the parent, retain edits before readiness, replay on
|
|
415
|
+
reload/reset and tear down listeners/styles when their owning scope ends.
|
|
416
|
+
|
|
417
|
+
### Source and canonical capture metadata
|
|
418
|
+
|
|
419
|
+
Descriptors may opt into `variant.source = { key, code }`. Obtain `key` from
|
|
420
|
+
`externalCatalogKey(slug, exportName)`; it encodes a JSON tuple, avoiding
|
|
421
|
+
delimiter collisions. `code` is verbatim text, including JSX or characters
|
|
422
|
+
that resemble HTML; never evaluate or inject it as markup. Existing
|
|
423
|
+
descriptors without source remain valid. Sourced variants mount the existing
|
|
424
|
+
accessible CodePanel, including source tabs/copy and isolated Live CSS. Variants
|
|
425
|
+
without source have no Source tab; a completely source-less descriptor has no
|
|
426
|
+
panel or panel toggle. `sourcePath` remains informational.
|
|
427
|
+
|
|
428
|
+
`validateExternalCatalogManifest(input)` validates and normalizes an array of
|
|
429
|
+
`ExternalCatalogEntry` rows, each containing `slug`, `variant`,
|
|
430
|
+
`loader: {key, module, exportName}`, `source: {key, code}`, and `capture`.
|
|
431
|
+
Loader modules are project-root-relative paths; generated loader functions
|
|
432
|
+
stay in the external bundle. All three keys must equal the canonical tuple
|
|
433
|
+
key, and row identities and captured asset ownership must be unique.
|
|
434
|
+
|
|
435
|
+
A capture is either `{kind: "image", key, fixture: {module, exportName}, src,
|
|
436
|
+
width, height}` matching the loader, or `{kind: "placeholder" | "failed", key,
|
|
437
|
+
note}` with an explicit nonempty explanation. Image paths are root-absolute
|
|
438
|
+
emitted URLs before adding the site base, with positive integer pixel
|
|
439
|
+
dimensions. Existing descriptor image/placeholder/no-thumbnail behavior is
|
|
440
|
+
unchanged unless the host opts into this canonical manifest.
|
|
441
|
+
|
|
442
|
+
This validator checks data, not files or screenshots. An image declaration
|
|
443
|
+
promises a real capture of the named external runtime: capture after committed
|
|
444
|
+
readiness and its stability barrier, then verify the emitted file, actual
|
|
445
|
+
dimensions and fixture/source/loader key agreement before claiming success.
|
|
446
|
+
Missing or invalid promised images fail the build/capture check; explicit
|
|
447
|
+
failed dispositions throw with their recorded note. Compare exact generated key sets,
|
|
448
|
+
source contents and loader references, including extra entries, before build.
|
|
449
|
+
The packed React proof is maintained separately. Never substitute engine React
|
|
450
|
+
SSR, decorative fake screenshots, or a
|
|
451
|
+
host route shadow for this boundary.
|
|
452
|
+
|
|
453
|
+
### Node prebuild and capture API
|
|
454
|
+
|
|
455
|
+
Import these Node-only helpers from
|
|
456
|
+
`@takazudo/zudo-sg/registry/external-catalog-node` in a host build script.
|
|
457
|
+
Do not import them from `zfb.config` (its graph must remain node-free) or from
|
|
458
|
+
the browser bundle. The engine does not install a browser or import React.
|
|
459
|
+
|
|
460
|
+
- `validateExternalCatalogOutputs({manifest, descriptors, loaders, sources})`
|
|
461
|
+
compares complete generated arrays: missing/extra/duplicate keys, actual
|
|
462
|
+
source text and loader module/export references. Generate browser loaders and
|
|
463
|
+
their metadata from the same canonical manifest. The first authored variant
|
|
464
|
+
owns the story's catalog tile; use
|
|
465
|
+
`thumbnailFromExternalCapture(first.capture)` for its thumbnail. Every
|
|
466
|
+
variant's image promise is checked, including those not used for that tile.
|
|
467
|
+
- `captureExternalCatalogImages({manifest, projectRoot, assetRoot, origin,
|
|
468
|
+
base, previewUrl, page})` visits the actual external document with canonical
|
|
469
|
+
slug/variant query parameters. `origin` is an HTTP(S) origin without a
|
|
470
|
+
trailing slash, `base` defaults to `/`, and `previewUrl` is the root-absolute
|
|
471
|
+
document path before adding the base.
|
|
472
|
+
- `validateExternalCatalogAssets({manifest, projectRoot, assetRoot, captures})`
|
|
473
|
+
checks capture receipts against files. Missing images, stale loader/source
|
|
474
|
+
hashes, wrong image hash/dimensions/fixture identity, and `failed` dispositions
|
|
475
|
+
throw. Intentional placeholders remain labelled. Paths reject symlinks,
|
|
476
|
+
including parents, before reading/writing. Captures must be complete,
|
|
477
|
+
noninterlaced 8-bit PNGs of at most 16,777,216 pixels, matching the declared
|
|
478
|
+
viewport dimensions. Only IHDR/IDAT/IEND critical chunks are supported;
|
|
479
|
+
palette chunks are outside this browser screenshot format. Legacy descriptor
|
|
480
|
+
SVG/remote image semantics are unchanged.
|
|
481
|
+
|
|
482
|
+
`loaders` and `sources` are arrays of `ExternalCatalogLoader` and
|
|
483
|
+
`DescriptorSource`. Pass actual generated outputs rather than reconstructing
|
|
484
|
+
expected copies inside the check. Receipts record actual runtime identity and
|
|
485
|
+
SHA-256 hashes of the loader entry file, displayed source and PNG. The loader
|
|
486
|
+
hash covers the entry file, not its transitive imports: rerun captures after
|
|
487
|
+
fixture dependency or asset changes. Receipts establish capture consistency,
|
|
488
|
+
not independent attestation of arbitrary host-supplied metadata.
|
|
489
|
+
|
|
490
|
+
The caller-owned `page` adapter implements `goto(url)`,
|
|
491
|
+
`setViewportSize({width,height})`, `screenshot({type: "png", scale: "css"})`,
|
|
492
|
+
`whenStable()` and `getSnapshot()`. The latter two invoke the actual
|
|
493
|
+
`createExternalPreviewRuntime()` controller in the loaded document. Wait for
|
|
494
|
+
the host-exposed controller property to exist before calling `whenStable()`;
|
|
495
|
+
apply the browser runner's normal timeout. The helper checks committed
|
|
496
|
+
readiness, errors and identity before and after the screenshot. The host must
|
|
497
|
+
surface browser console errors and close its browser/server in `finally`.
|
|
498
|
+
|
|
499
|
+
Run this sequence from a Node script in the host's build command:
|
|
500
|
+
|
|
501
|
+
1. Generate descriptors/source/loader metadata from the canonical manifest and
|
|
502
|
+
call `validateExternalCatalogOutputs`.
|
|
503
|
+
2. Build the independent external preview, serve it under the intended base,
|
|
504
|
+
and capture into `public/`. Missing promised images cannot represent a
|
|
505
|
+
successful catalog build.
|
|
506
|
+
3. Save the returned serializable receipts, validate assets in `public/`, then
|
|
507
|
+
run the final `zfb build` to copy those assets into `dist/`.
|
|
508
|
+
4. Validate the same receipts against the emitted asset directory and verify
|
|
509
|
+
built browser loads. Use `assetRoot: "dist"` at the root base; zfb 4 copies
|
|
510
|
+
public assets under the base, so `/styleguide/` uses
|
|
511
|
+
`assetRoot: "dist/styleguide"`. Capture `src` stays `/captures/example.png`;
|
|
512
|
+
the helper resolves it beneath `assetRoot` without adding the URL base.
|
|
513
|
+
|
|
514
|
+
Adding source text alone neither runs captures nor makes thumbnails mandatory
|
|
515
|
+
for existing catalogs. Source-less legacy descriptors do not use this opt-in
|
|
516
|
+
manifest check. The focused helper tests cover framework-independent capture
|
|
517
|
+
orchestration; the separately installed React consumer supplies real screenshots.
|
|
298
518
|
|
|
299
519
|
## Release scheme
|
|
300
520
|
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
/** @jsxImportSource preact */
|
|
3
|
-
import type { JSX } from "preact";
|
|
1
|
+
import type { JSX } from "@takazudo/zfb/zudo-react/jsx-runtime";
|
|
4
2
|
import type { CatalogEntry } from "../registry/catalog.js";
|
|
5
3
|
export interface CatalogThumbProps {
|
|
6
4
|
entry: CatalogEntry;
|
|
@@ -14,6 +12,3 @@ export interface CatalogThumbProps {
|
|
|
14
12
|
* through `DescriptorThumb`.
|
|
15
13
|
*/
|
|
16
14
|
export declare function CatalogThumb({ entry, base }: CatalogThumbProps): JSX.Element;
|
|
17
|
-
export declare namespace CatalogThumb {
|
|
18
|
-
var displayName: string;
|
|
19
|
-
}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { jsx } from "
|
|
1
|
+
import { jsx } from "@takazudo/zfb/zudo-react/jsx-runtime";
|
|
2
2
|
import { ComponentThumb } from "./component-thumb.js";
|
|
3
3
|
import { DescriptorThumb } from "./descriptor-thumb.js";
|
|
4
4
|
function CatalogThumb({ entry, base }) {
|
|
5
5
|
if (entry.source === "module") return /* @__PURE__ */ jsx(ComponentThumb, { entry: entry.storyEntry });
|
|
6
6
|
return /* @__PURE__ */ jsx(DescriptorThumb, { entry, base });
|
|
7
7
|
}
|
|
8
|
-
CatalogThumb.displayName = "CatalogThumb";
|
|
9
8
|
export {
|
|
10
9
|
CatalogThumb
|
|
11
10
|
};
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
/** @jsxImportSource preact */
|
|
3
|
-
import type { JSX } from "preact";
|
|
1
|
+
import type { JSX } from "@takazudo/zfb/zudo-react/jsx-runtime";
|
|
4
2
|
import type { StoryEntry } from "../registry/registry.js";
|
|
5
3
|
/** Virtual-viewport width (CSS px) a thumbnail lays its component out at. */
|
|
6
4
|
export declare const THUMB_VIEWPORT_W = 720;
|
|
@@ -73,6 +71,3 @@ export interface ComponentThumbProps {
|
|
|
73
71
|
* `aria-hidden` subtree is an accessibility defect, not just noise.
|
|
74
72
|
*/
|
|
75
73
|
export declare function ComponentThumb({ entry }: ComponentThumbProps): JSX.Element;
|
|
76
|
-
export declare namespace ComponentThumb {
|
|
77
|
-
var displayName: string;
|
|
78
|
-
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { jsx } from "@takazudo/zfb/zudo-react/jsx-runtime";
|
|
2
|
+
import { renderToString as renderToStaticHtml } from "@takazudo/zfb/zudo-react/server";
|
|
3
3
|
const THUMB_VIEWPORT_W = 720;
|
|
4
4
|
const THUMB_VIEWPORT_W_ATOM = 400;
|
|
5
5
|
const ATOM_SCALE_CATEGORIES = [
|
|
@@ -56,9 +56,11 @@ function buildThumb(entry) {
|
|
|
56
56
|
const variant = entry.variants[0];
|
|
57
57
|
if (!variant) return { kind: "note", reason: "No variants declared" };
|
|
58
58
|
try {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
let StorySnapshot2 = function() {
|
|
60
|
+
return variant.story.render(defaultsFromControls(variant.story.controls));
|
|
61
|
+
};
|
|
62
|
+
var StorySnapshot = StorySnapshot2;
|
|
63
|
+
const html = renderToStaticHtml(/* @__PURE__ */ jsx(StorySnapshot2, {}));
|
|
62
64
|
return { kind: "html", html: scopeThumbHtml(html, thumbIdPrefix(entry.slug)) };
|
|
63
65
|
} catch (error) {
|
|
64
66
|
return {
|
|
@@ -90,13 +92,12 @@ function ComponentThumb({ entry }) {
|
|
|
90
92
|
"div",
|
|
91
93
|
{
|
|
92
94
|
class: "sg-thumb-inner",
|
|
93
|
-
|
|
95
|
+
rawHtml: thumb.html
|
|
94
96
|
}
|
|
95
97
|
)
|
|
96
98
|
}
|
|
97
99
|
);
|
|
98
100
|
}
|
|
99
|
-
ComponentThumb.displayName = "ComponentThumb";
|
|
100
101
|
export {
|
|
101
102
|
ATOM_SCALE_CATEGORIES,
|
|
102
103
|
ComponentThumb,
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
/** @jsxImportSource preact */
|
|
3
|
-
import type { JSX } from "preact";
|
|
1
|
+
import type { JSX } from "@takazudo/zfb/zudo-react/jsx-runtime";
|
|
4
2
|
import type { DescriptorCatalogEntry } from "../registry/catalog.js";
|
|
5
3
|
/** Note shown when a descriptor declares no `thumbnail` at all. */
|
|
6
4
|
export declare const DESCRIPTOR_THUMB_MISSING_NOTE = "No thumbnail provided";
|
|
@@ -15,6 +13,3 @@ export interface DescriptorThumbProps {
|
|
|
15
13
|
* snapshots out of the tab order and the accessibility tree the same way.
|
|
16
14
|
*/
|
|
17
15
|
export declare function DescriptorThumb({ entry, base }: DescriptorThumbProps): JSX.Element;
|
|
18
|
-
export declare namespace DescriptorThumb {
|
|
19
|
-
var displayName: string;
|
|
20
|
-
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { jsx } from "
|
|
1
|
+
import { jsx } from "@takazudo/zfb/zudo-react/jsx-runtime";
|
|
2
2
|
const DESCRIPTOR_THUMB_MISSING_NOTE = "No thumbnail provided";
|
|
3
3
|
function withThumbBase(base, src) {
|
|
4
4
|
if (!src.startsWith("/")) return src;
|
|
@@ -24,7 +24,6 @@ function DescriptorThumb({ entry, base = "" }) {
|
|
|
24
24
|
}
|
|
25
25
|
) });
|
|
26
26
|
}
|
|
27
|
-
DescriptorThumb.displayName = "DescriptorThumb";
|
|
28
27
|
export {
|
|
29
28
|
DESCRIPTOR_THUMB_MISSING_NOTE,
|
|
30
29
|
DescriptorThumb
|