@takazudo/zudo-sg 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.
Files changed (138) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/LICENSE +21 -0
  3. package/README.md +99 -0
  4. package/bin/zudo-sg.js +6 -0
  5. package/dist/catalog/component-thumb.d.ts +78 -0
  6. package/dist/catalog/component-thumb.js +110 -0
  7. package/dist/catalog/index.d.ts +4 -0
  8. package/dist/catalog/index.js +40 -0
  9. package/dist/catalog/tile-size.d.ts +28 -0
  10. package/dist/catalog/tile-size.js +42 -0
  11. package/dist/chrome/_styleguide-layout.d.ts +59 -0
  12. package/dist/chrome/_styleguide-layout.js +69 -0
  13. package/dist/chrome/index.d.ts +4 -0
  14. package/dist/chrome/index.js +39 -0
  15. package/dist/chrome/panel-contract.d.ts +15 -0
  16. package/dist/chrome/panel-contract.js +65 -0
  17. package/dist/chrome/panel-scripts-source.d.ts +2 -0
  18. package/dist/chrome/panel-scripts-source.js +121 -0
  19. package/dist/chrome/panel-scripts.d.ts +5 -0
  20. package/dist/chrome/panel-scripts.js +12 -0
  21. package/dist/cli/bin.d.ts +1 -0
  22. package/dist/cli/bin.js +74 -0
  23. package/dist/cli/config.d.ts +54 -0
  24. package/dist/cli/config.js +14 -0
  25. package/dist/cli/registry/build-registry-source.d.ts +27 -0
  26. package/dist/cli/registry/build-registry-source.js +77 -0
  27. package/dist/cli/registry/discover-stories.d.ts +36 -0
  28. package/dist/cli/registry/discover-stories.js +61 -0
  29. package/dist/cli/registry/gen-registry.d.ts +23 -0
  30. package/dist/cli/registry/gen-registry.js +74 -0
  31. package/dist/cli/scaffold/component-scaffold.d.ts +64 -0
  32. package/dist/cli/scaffold/component-scaffold.js +233 -0
  33. package/dist/cli/scaffold/new-component.d.ts +17 -0
  34. package/dist/cli/scaffold/new-component.js +119 -0
  35. package/dist/cli/token-manifest/css-var-parser.d.ts +9 -0
  36. package/dist/cli/token-manifest/css-var-parser.js +23 -0
  37. package/dist/cli/token-manifest/gen-token-manifest.d.ts +16 -0
  38. package/dist/cli/token-manifest/gen-token-manifest.js +49 -0
  39. package/dist/cli/token-manifest/ui-token-manifest.d.ts +78 -0
  40. package/dist/cli/token-manifest/ui-token-manifest.js +340 -0
  41. package/dist/code-panel/code-panel.d.ts +18 -0
  42. package/dist/code-panel/code-panel.js +76 -0
  43. package/dist/code-panel/copy-button.d.ts +15 -0
  44. package/dist/code-panel/copy-button.js +92 -0
  45. package/dist/code-panel/css-injection.d.ts +6 -0
  46. package/dist/code-panel/css-injection.js +37 -0
  47. package/dist/code-panel/editor-setup.d.ts +10 -0
  48. package/dist/code-panel/editor-setup.js +33 -0
  49. package/dist/code-panel/index.d.ts +6 -0
  50. package/dist/code-panel/index.js +10 -0
  51. package/dist/code-panel/source-editor.d.ts +8 -0
  52. package/dist/code-panel/source-editor.js +39 -0
  53. package/dist/config/index.d.ts +73 -0
  54. package/dist/config/index.js +68 -0
  55. package/dist/host-paths.d.ts +19 -0
  56. package/dist/host-paths.js +41 -0
  57. package/dist/index.d.ts +6 -0
  58. package/dist/index.js +18 -0
  59. package/dist/islands.d.ts +2 -0
  60. package/dist/islands.js +6 -0
  61. package/dist/plugins/preview-css.d.ts +53 -0
  62. package/dist/plugins/preview-css.js +183 -0
  63. package/dist/plugins/routes.d.ts +84 -0
  64. package/dist/plugins/routes.js +237 -0
  65. package/dist/plugins/zdtp-apply-proxy.d.ts +58 -0
  66. package/dist/plugins/zdtp-apply-proxy.js +171 -0
  67. package/dist/preview/detail-workbench.d.ts +22 -0
  68. package/dist/preview/detail-workbench.js +179 -0
  69. package/dist/preview/index.d.ts +8 -0
  70. package/dist/preview/index.js +21 -0
  71. package/dist/preview/messages.d.ts +34 -0
  72. package/dist/preview/messages.js +32 -0
  73. package/dist/preview/preview-app.d.ts +11 -0
  74. package/dist/preview/preview-app.js +87 -0
  75. package/dist/preview/route.d.ts +1 -0
  76. package/dist/preview/route.js +5 -0
  77. package/dist/preview/variant-frame.d.ts +42 -0
  78. package/dist/preview/variant-frame.js +289 -0
  79. package/dist/preview-css/compile.d.ts +40 -0
  80. package/dist/preview-css/compile.js +42 -0
  81. package/dist/preview-css/index.d.ts +2 -0
  82. package/dist/preview-css/index.js +10 -0
  83. package/dist/registry/component-docs.d.ts +38 -0
  84. package/dist/registry/component-docs.js +34 -0
  85. package/dist/registry/index.d.ts +6 -0
  86. package/dist/registry/index.js +28 -0
  87. package/dist/registry/nav-nodes.d.ts +22 -0
  88. package/dist/registry/nav-nodes.js +36 -0
  89. package/dist/registry/registry.d.ts +68 -0
  90. package/dist/registry/registry.js +91 -0
  91. package/dist/safelist.css +2 -0
  92. package/dist/search/catalog-filter.d.ts +12 -0
  93. package/dist/search/catalog-filter.js +175 -0
  94. package/dist/search/index.d.ts +2 -0
  95. package/dist/search/index.js +4 -0
  96. package/dist/sg-context.d.ts +24 -0
  97. package/dist/sg-context.js +6 -0
  98. package/dist/sg-routes.d.ts +12 -0
  99. package/dist/sg-routes.js +17 -0
  100. package/dist/stories/index.d.ts +2 -0
  101. package/dist/stories/index.js +4 -0
  102. package/dist/stories/types.d.ts +164 -0
  103. package/dist/stories/types.js +6 -0
  104. package/dist/token-dashboard/create-token-dashboards.d.ts +24 -0
  105. package/dist/token-dashboard/create-token-dashboards.js +57 -0
  106. package/dist/token-dashboard/dashboard-inventory.d.ts +11 -0
  107. package/dist/token-dashboard/dashboard-inventory.js +13 -0
  108. package/dist/token-dashboard/index.d.ts +5 -0
  109. package/dist/token-dashboard/index.js +20 -0
  110. package/dist/token-dashboard/ui-token-tabs.d.ts +53 -0
  111. package/dist/token-dashboard/ui-token-tabs.js +159 -0
  112. package/dist/token-tweak/bootstrap-preview-token-panel.d.ts +12 -0
  113. package/dist/token-tweak/bootstrap-preview-token-panel.js +18 -0
  114. package/dist/token-tweak/iframe-css-vars-bridge.d.ts +35 -0
  115. package/dist/token-tweak/iframe-css-vars-bridge.js +73 -0
  116. package/dist/token-tweak/index.d.ts +6 -0
  117. package/dist/token-tweak/index.js +36 -0
  118. package/dist/token-tweak/preview-iframe-registry.d.ts +16 -0
  119. package/dist/token-tweak/preview-iframe-registry.js +48 -0
  120. package/dist/token-tweak/preview-token-panel-bootstrap.d.ts +6 -0
  121. package/dist/token-tweak/preview-token-panel-bootstrap.js +17 -0
  122. package/dist/token-tweak/preview-token-panel-config.d.ts +42 -0
  123. package/dist/token-tweak/preview-token-panel-config.js +37 -0
  124. package/dist/token-tweak/preview-tokens-button.d.ts +5 -0
  125. package/dist/token-tweak/preview-tokens-button.js +17 -0
  126. package/dist/token-tweak/token-panel-native-bootstrap.d.ts +17 -0
  127. package/dist/token-tweak/token-panel-native-bootstrap.js +49 -0
  128. package/package.json +172 -0
  129. package/routes-src/_chrome.tsx +83 -0
  130. package/routes-src/_context.ts +15 -0
  131. package/routes-src/_preview-app.tsx +32 -0
  132. package/routes-src/_registry.ts +12 -0
  133. package/routes-src/components-index.tsx +95 -0
  134. package/routes-src/components-preview.tsx +55 -0
  135. package/routes-src/components-slug.tsx +145 -0
  136. package/routes-src/tokens.tsx +76 -0
  137. package/styles.css +612 -0
  138. package/virtual-modules.d.ts +25 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,35 @@
1
+ # Changelog
2
+
3
+ All notable changes to `@takazudo/zudo-sg` are documented in this file.
4
+
5
+ The format is based on Keep a Changelog, and release notes are generated from the changelog MDX pages.
6
+
7
+ ## [0.1.0] - 2026-09-15
8
+
9
+ Initial release of `@takazudo/zudo-sg`, the installable styleguide engine
10
+ package.
11
+
12
+ ### Features
13
+
14
+ - Package-owned catalog routes — `/components`, `/components/[slug]`,
15
+ `/components/preview`, `/tokens` — injected into a host's zfb build via
16
+ `@takazudo/zudo-sg/plugins/routes`, mirroring `@takazudo/zudo-doc`'s
17
+ route-injection seam.
18
+ - `zudo-sg` CLI: `gen-registry [--check]`, `new-component <name> --category <c>
19
+ [--nested] [--skip-barrel]`, `gen-token-manifest [--check]`, all driven by a
20
+ host `zudo-sg.config.mjs`.
21
+ - Story-authoring contract (`@takazudo/zudo-sg/stories`): `StoryMeta`,
22
+ `Story`, `StoryControl`, `StoryModule`, `defineStory`. Story
23
+ categories are open, host-ordered data, not a closed type.
24
+ - Standalone preview stylesheet compiler (`@takazudo/zudo-sg/plugins/preview-css`)
25
+ that compiles the host's token CSS with `@tailwindcss/node` and rescopes it
26
+ under `:root[data-sg-preview-doc]` so it coexists with the host's own global
27
+ stylesheet.
28
+ - Generated safelist and chrome styles (`@takazudo/zudo-sg/safelist.css`,
29
+ `@takazudo/zudo-sg/styles.css`) so package-owned catalog UI ships its own
30
+ Tailwind utilities without depending on the host's content scan.
31
+ - Token dashboards and the preview design-token panel, driven by a
32
+ `gen-token-manifest`-produced manifest.
33
+ - Framework scope: Preact/zfb hosts only for this release.
34
+ - Release toolchain: `@takazudo/zfb` 2.17.0 with `@takazudo/zudo-doc` 5.24.0.
35
+ The injected `/tokens` route makes `@takazudo/zdtp ^0.8.0` a required peer.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Takeshi Takatsudo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,99 @@
1
+ # `@takazudo/zudo-sg`
2
+
3
+ The zudo-sg **styleguide engine** — an installable package that gives a
4
+ [`@takazudo/zfb`](https://www.npmjs.com/package/@takazudo/zfb) +
5
+ [`@takazudo/zudo-doc`](https://www.npmjs.com/package/@takazudo/zudo-doc) host
6
+ a component catalog, story registry, preview iframe, code panel, and design
7
+ token dashboards, built and shipped the same way `@takazudo/zudo-doc` itself
8
+ is. This repository ([`Takazudo/zudo-sg`](https://github.com/Takazudo/zudo-sg))
9
+ dogfoods the engine as its own styleguide host — see
10
+ `docs/adr/styleguide-engine.md` there for the full seam contract.
11
+
12
+ ## What it gives a host
13
+
14
+ - Package-owned routes — `/components`, `/components/[slug]`,
15
+ `/components/preview`, `/tokens` — injected into the host's zfb build via
16
+ `@takazudo/zudo-sg/plugins/routes` (mirrors `@takazudo/zudo-doc`'s own
17
+ route-injection seam).
18
+ - A `zudo-sg` CLI: `gen-registry [--check]`, `new-component <name> --category
19
+ <c> [--nested] [--skip-barrel]`, `gen-token-manifest [--check]`, all driven
20
+ by a host `zudo-sg.config.mjs`.
21
+ - A story-authoring contract (`@takazudo/zudo-sg/stories`): `StoryMeta`,
22
+ `Story<P>`, `StoryControl<P>`, `StoryModule`, `defineStory`. Categories are
23
+ open, host-ordered data (`categoryOrder: string[]`), never a closed type.
24
+ - A standalone preview stylesheet compiler
25
+ (`@takazudo/zudo-sg/plugins/preview-css`) that compiles the host's own token
26
+ CSS with `@tailwindcss/node` and rescopes it under
27
+ `:root[data-sg-preview-doc]` so it coexists with the host's global
28
+ stylesheet.
29
+ - Generated safelist and chrome styles (`@takazudo/zudo-sg/safelist.css`,
30
+ `@takazudo/zudo-sg/styles.css`) so the catalog UI ships its own Tailwind
31
+ utilities without depending on the host's content scan.
32
+ - Token dashboards and a preview design-token panel, driven by a
33
+ `gen-token-manifest`-produced manifest.
34
+
35
+ ## Framework scope
36
+
37
+ Preact + zfb hosts only. React 19 hosts are an explicit non-goal for this
38
+ release (see the ADR's "Framework scope" decision for the seam that would
39
+ enable them later).
40
+
41
+ ## Installation
42
+
43
+ ```sh
44
+ pnpm add @takazudo/zudo-sg@latest @takazudo/zfb@^2.17.0 @takazudo/zfb-md-wasm@^2.17.0 @takazudo/zfb-runtime@^2.17.0 @takazudo/zudo-doc@^5.24.0 @takazudo/zdtp@^0.8.0 diff@^8.0.4 katex@^0.16.38 preact@^10.29.1 preact-render-to-string@^6.6.6 tailwindcss@^4.2.0 zod@^4.3.6
45
+ ```
46
+
47
+ The engine peers are `@takazudo/zfb ^2.17.0`, `@takazudo/zudo-doc ^5.24.0`,
48
+ `@takazudo/zdtp ^0.8.0`, and `preact ^10.29.1`. `@takazudo/zdtp` is required:
49
+ the injected `/tokens` route imports its dashboard at build time. The
50
+ `@takazudo/zfb-md-wasm`, `@takazudo/zfb-runtime`, `diff`, `katex`, and `zod`
51
+ entries are prerequisites inherited from zfb/zudo-doc; zudo-doc's published
52
+ route dist imports `diff` and `katex` even when those features are disabled
53
+ (see [zudolab/zudo-doc#4206](https://github.com/zudolab/zudo-doc/issues/4206)).
54
+ `preact-render-to-string` and `tailwindcss` are host-specific dependencies used
55
+ by the fixture's component and preview-style setup, respectively; add them
56
+ when your host uses those same pieces. The command above reproduces the full
57
+ fixture dependency set.
58
+
59
+ ## Composing it into a host
60
+
61
+ ```ts
62
+ import { defineConfig } from "zfb/config";
63
+ import { zudoDoc } from "@takazudo/zudo-doc/config";
64
+ import { withZudoSg } from "@takazudo/zudo-sg/config";
65
+
66
+ export default defineConfig(
67
+ withZudoSg(
68
+ zudoDoc({
69
+ /* ... */
70
+ }),
71
+ {
72
+ componentsRoots: [{ dir: "./src/components", importBase: "@/components" }],
73
+ registryOut: "./src/styleguide/sg-registry.ts",
74
+ uiPackageName: "@your-scope/ui",
75
+ previewStyles: "./src/styles/preview-entry.css",
76
+ },
77
+ ),
78
+ );
79
+ ```
80
+
81
+ `withZudoSg` merges the engine's plugins and collections after the zudo-doc
82
+ preset's own. The engine requires `packageOwnedRoutes: true` on the host (its
83
+ routes import zudo-doc's route-context virtual modules) and — because `zfb
84
+ dev` only scans a host's own `pages/` tree for `"use client"` islands — a host
85
+ `pages/` file that statically imports `@takazudo/zudo-sg/islands` once (see
86
+ the ADR's "Island rule" for why).
87
+
88
+ Full option shape, virtual modules, and every locked constant:
89
+ `docs/adr/styleguide-engine.md` in this repository.
90
+
91
+ ## Release scheme
92
+
93
+ Stable only. `v*.*.*` tags publish to the npm `latest` dist-tag — there is no
94
+ `next` prerelease channel for this package. See the
95
+ [release runbook](https://github.com/Takazudo/zudo-sg/blob/main/packages/styleguide/RELEASE.md).
96
+
97
+ ## License
98
+
99
+ MIT
package/bin/zudo-sg.js ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env node
2
+ import { runZudoSgCli } from "../dist/cli/bin.js";
3
+
4
+ runZudoSgCli(process.argv.slice(2)).then((code) => {
5
+ process.exitCode = code;
6
+ });
@@ -0,0 +1,78 @@
1
+ /** @jsxRuntime automatic */
2
+ /** @jsxImportSource preact */
3
+ import type { JSX } from "preact";
4
+ import type { StoryEntry } from "../registry/registry.js";
5
+ /** Virtual-viewport width (CSS px) a thumbnail lays its component out at. */
6
+ export declare const THUMB_VIEWPORT_W = 720;
7
+ /**
8
+ * Narrower virtual viewport for categories whose components are atoms — a
9
+ * button or a paragraph laid out at 720px is a speck in the tile.
10
+ */
11
+ export declare const THUMB_VIEWPORT_W_ATOM = 400;
12
+ /**
13
+ * Categories that use the atom-scale virtual viewport. Category values are
14
+ * plain strings (host-declared `categoryOrder`, ADR decision 5) — the engine
15
+ * does not own a closed category union.
16
+ */
17
+ export declare const ATOM_SCALE_CATEGORIES: readonly string[];
18
+ /**
19
+ * Per-component opt-out to a static note, keyed by story slug. A component
20
+ * earns an entry ONLY when it throws during the server render, needs a client
21
+ * island to show anything at all, or escapes its tile; the value is the reason,
22
+ * rendered in the tile so a reader never meets an unexplained blank.
23
+ *
24
+ * Intentionally empty by default — a host wires its own entries in only where
25
+ * a real story needs the opt-out. `buildThumb` also falls back to this path on
26
+ * a thrown render, so one broken story degrades to a labelled tile instead of
27
+ * taking the whole catalogue build down.
28
+ */
29
+ export declare const THUMB_OPT_OUTS: Readonly<Record<string, string>>;
30
+ /** Virtual-viewport width for a category's tiles. */
31
+ export declare function thumbViewportWidth(category: string): number;
32
+ /**
33
+ * The scale the package's `styles.css` applies, as a number: the tile's track
34
+ * minimum over the virtual-viewport width.
35
+ *
36
+ * Deliberately has no runtime caller. The CSS owns the arithmetic — it computes
37
+ * `--sg-thumb-scale` from the same two custom properties so the tile-size
38
+ * control can change the track without re-rendering every thumbnail — and this
39
+ * is the checkable mirror of it, which the contract test in `__tests__` pins
40
+ * against both the CSS formula and TILE_SIZES.
41
+ */
42
+ export declare function thumbScale(trackMin: number, viewportWidth: number): number;
43
+ /**
44
+ * Make one rendered story safe to inline alongside every other tile: strip
45
+ * `<script>` and `<style>` blocks, and namespace every id (and every
46
+ * reference to one) under `prefix`, so intra-tile wiring — a `<label for>`, an
47
+ * `aria-controls`, an SVG `url(#gradient)` — keeps working while nothing leaks
48
+ * across tiles.
49
+ *
50
+ * `<style>` is stripped for two independent reasons, either of which alone
51
+ * would justify it. It is invalid here: `<style>` is metadata content, so
52
+ * html-validate rejects it under a `<div>` (`element-permitted-content`). And
53
+ * it is *global*: a story-only rule pinning something to its own frame would,
54
+ * inlined verbatim, apply to the whole catalogue page rather than just the
55
+ * tile that carries it. Nothing is lost: the tile's `transform` already
56
+ * establishes a containing block, which is what actually keeps
57
+ * fixed-position content inside its own box here.
58
+ *
59
+ * Attribute-shaped text inside a component's own *content* (a code sample that
60
+ * literally prints ` id="…"`) would be rewritten too. That is cosmetic in a
61
+ * decorative snapshot.
62
+ */
63
+ export declare function scopeThumbHtml(html: string, prefix: string): string;
64
+ /** Per-tile id namespace. Story slugs are unique by construction. */
65
+ export declare function thumbIdPrefix(slug: string): string;
66
+ export interface ComponentThumbProps {
67
+ entry: StoryEntry;
68
+ }
69
+ /**
70
+ * One tile's thumbnail slot. `aria-hidden` + `inert` keep the snapshot out of
71
+ * the accessibility tree AND out of the tab order — a catalogue page renders a
72
+ * lot of focusable controls this way, and focusable content inside an
73
+ * `aria-hidden` subtree is an accessibility defect, not just noise.
74
+ */
75
+ export declare function ComponentThumb({ entry }: ComponentThumbProps): JSX.Element;
76
+ export declare namespace ComponentThumb {
77
+ var displayName: string;
78
+ }
@@ -0,0 +1,110 @@
1
+ import { Fragment, jsx } from "preact/jsx-runtime";
2
+ import { render as renderToStaticHtml } from "preact-render-to-string";
3
+ const THUMB_VIEWPORT_W = 720;
4
+ const THUMB_VIEWPORT_W_ATOM = 400;
5
+ const ATOM_SCALE_CATEGORIES = [
6
+ "Typography",
7
+ "Actions",
8
+ "Feedback",
9
+ "News",
10
+ "Media",
11
+ "Forms"
12
+ ];
13
+ const THUMB_OPT_OUTS = {};
14
+ function thumbViewportWidth(category) {
15
+ return ATOM_SCALE_CATEGORIES.includes(category) ? THUMB_VIEWPORT_W_ATOM : THUMB_VIEWPORT_W;
16
+ }
17
+ function thumbScale(trackMin, viewportWidth) {
18
+ return trackMin / viewportWidth;
19
+ }
20
+ function defaultsFromControls(controls) {
21
+ const args = {};
22
+ for (const control of controls ?? []) args[control.prop] = control.defaultValue;
23
+ return args;
24
+ }
25
+ const ID_REF_ATTRS = [
26
+ "for",
27
+ "form",
28
+ "list",
29
+ "headers",
30
+ "aria-controls",
31
+ "aria-labelledby",
32
+ "aria-describedby",
33
+ "aria-details",
34
+ "aria-owns",
35
+ "aria-activedescendant"
36
+ ];
37
+ const SCRIPT_RE = /<script\b[^>]*>[\s\S]*?<\/script>/gi;
38
+ const STYLE_RE = /<style\b[^>]*>[\s\S]*?<\/style>/gi;
39
+ const ID_ATTR_RE = /\sid="([^"]*)"/g;
40
+ const ID_REF_ATTR_RE = new RegExp(`\\s(${ID_REF_ATTRS.join("|")})="([^"]*)"`, "g");
41
+ const FRAGMENT_HREF_RE = /\shref="#([^"\s]+)"/g;
42
+ const FRAGMENT_URL_RE = /url\(#([^)"\s]+)\)/g;
43
+ function scopeThumbHtml(html, prefix) {
44
+ const scopeRefList = (value) => value.split(/\s+/).filter(Boolean).map((ref) => `${prefix}${ref}`).join(" ");
45
+ return html.replace(SCRIPT_RE, "").replace(STYLE_RE, "").replace(ID_ATTR_RE, (_match, id) => ` id="${prefix}${id}"`).replace(
46
+ ID_REF_ATTR_RE,
47
+ (_match, attr, value) => ` ${attr}="${scopeRefList(value)}"`
48
+ ).replace(FRAGMENT_HREF_RE, (_match, id) => ` href="#${prefix}${id}"`).replace(FRAGMENT_URL_RE, (_match, id) => `url(#${prefix}${id})`);
49
+ }
50
+ function thumbIdPrefix(slug) {
51
+ return `sgt-${slug}-`;
52
+ }
53
+ function buildThumb(entry) {
54
+ const optOut = THUMB_OPT_OUTS[entry.slug];
55
+ if (optOut) return { kind: "note", reason: optOut };
56
+ const variant = entry.variants[0];
57
+ if (!variant) return { kind: "note", reason: "No variants declared" };
58
+ try {
59
+ const html = renderToStaticHtml(
60
+ /* @__PURE__ */ jsx(Fragment, { children: variant.story.render(defaultsFromControls(variant.story.controls)) })
61
+ );
62
+ return { kind: "html", html: scopeThumbHtml(html, thumbIdPrefix(entry.slug)) };
63
+ } catch (error) {
64
+ return {
65
+ kind: "note",
66
+ reason: `Preview unavailable: ${error.message}`
67
+ };
68
+ }
69
+ }
70
+ const thumbCache = /* @__PURE__ */ new Map();
71
+ function getThumb(entry) {
72
+ const cached = thumbCache.get(entry.slug);
73
+ if (cached) return cached;
74
+ const thumb = buildThumb(entry);
75
+ thumbCache.set(entry.slug, thumb);
76
+ return thumb;
77
+ }
78
+ function ComponentThumb({ entry }) {
79
+ const thumb = getThumb(entry);
80
+ const viewportWidth = thumbViewportWidth(entry.meta.category);
81
+ return /* @__PURE__ */ jsx(
82
+ "div",
83
+ {
84
+ class: "sg-thumb",
85
+ "data-sg-preview-scope": true,
86
+ "aria-hidden": "true",
87
+ inert: true,
88
+ style: viewportWidth === THUMB_VIEWPORT_W ? void 0 : `--sg-thumb-vw-n: ${viewportWidth}`,
89
+ children: thumb.kind === "note" ? /* @__PURE__ */ jsx("p", { class: "sg-thumb-note", children: thumb.reason }) : /* @__PURE__ */ jsx(
90
+ "div",
91
+ {
92
+ class: "sg-thumb-inner",
93
+ dangerouslySetInnerHTML: { __html: thumb.html }
94
+ }
95
+ )
96
+ }
97
+ );
98
+ }
99
+ ComponentThumb.displayName = "ComponentThumb";
100
+ export {
101
+ ATOM_SCALE_CATEGORIES,
102
+ ComponentThumb,
103
+ THUMB_OPT_OUTS,
104
+ THUMB_VIEWPORT_W,
105
+ THUMB_VIEWPORT_W_ATOM,
106
+ scopeThumbHtml,
107
+ thumbIdPrefix,
108
+ thumbScale,
109
+ thumbViewportWidth
110
+ };
@@ -0,0 +1,4 @@
1
+ export { ATOM_SCALE_CATEGORIES, ComponentThumb, THUMB_OPT_OUTS, THUMB_VIEWPORT_W, THUMB_VIEWPORT_W_ATOM, scopeThumbHtml, thumbIdPrefix, thumbScale, thumbViewportWidth, } from "./component-thumb.js";
2
+ export type { ComponentThumbProps } from "./component-thumb.js";
3
+ export { ATTR_TILE_SIZE, DEFAULT_TILE_SIZE, LS_TILE_SIZE, TILE_SIZES, TILE_SIZE_RESTORE_SCRIPT, applyTileSize, isTileSize, readTileSize, } from "./tile-size.js";
4
+ export type { TileSize, TileSizeOption } from "./tile-size.js";
@@ -0,0 +1,40 @@
1
+ import {
2
+ ATOM_SCALE_CATEGORIES,
3
+ ComponentThumb,
4
+ THUMB_OPT_OUTS,
5
+ THUMB_VIEWPORT_W,
6
+ THUMB_VIEWPORT_W_ATOM,
7
+ scopeThumbHtml,
8
+ thumbIdPrefix,
9
+ thumbScale,
10
+ thumbViewportWidth
11
+ } from "./component-thumb.js";
12
+ import {
13
+ ATTR_TILE_SIZE,
14
+ DEFAULT_TILE_SIZE,
15
+ LS_TILE_SIZE,
16
+ TILE_SIZES,
17
+ TILE_SIZE_RESTORE_SCRIPT,
18
+ applyTileSize,
19
+ isTileSize,
20
+ readTileSize
21
+ } from "./tile-size.js";
22
+ export {
23
+ ATOM_SCALE_CATEGORIES,
24
+ ATTR_TILE_SIZE,
25
+ ComponentThumb,
26
+ DEFAULT_TILE_SIZE,
27
+ LS_TILE_SIZE,
28
+ THUMB_OPT_OUTS,
29
+ THUMB_VIEWPORT_W,
30
+ THUMB_VIEWPORT_W_ATOM,
31
+ TILE_SIZES,
32
+ TILE_SIZE_RESTORE_SCRIPT,
33
+ applyTileSize,
34
+ isTileSize,
35
+ readTileSize,
36
+ scopeThumbHtml,
37
+ thumbIdPrefix,
38
+ thumbScale,
39
+ thumbViewportWidth
40
+ };
@@ -0,0 +1,28 @@
1
+ /** Attribute set on `<html>`; the package's `styles.css` reads it to pick the track size. */
2
+ export declare const ATTR_TILE_SIZE = "data-sg-tile-size";
3
+ /** localStorage key (styleguide-private `sg-` namespace). */
4
+ export declare const LS_TILE_SIZE = "sg-catalog-tile-size";
5
+ export type TileSize = "compact" | "large";
6
+ export interface TileSizeOption {
7
+ id: TileSize;
8
+ label: string;
9
+ /**
10
+ * Grid track minimum in CSS px. Must equal the `--sg-tile-min-n` value the
11
+ * matching `styles.css` rule sets — the unit test asserts the two agree.
12
+ */
13
+ trackMin: number;
14
+ }
15
+ export declare const TILE_SIZES: readonly TileSizeOption[];
16
+ export declare const DEFAULT_TILE_SIZE: TileSize;
17
+ export declare function isTileSize(value: unknown): value is TileSize;
18
+ /** Persisted size, or the default when storage is unavailable or unset. */
19
+ export declare function readTileSize(): TileSize;
20
+ /** Write the attribute (drives the CSS) and persist it, best-effort. */
21
+ export declare function applyTileSize(size: TileSize, el?: HTMLElement): void;
22
+ /**
23
+ * Inline `<head>` script source. Runs before first paint so a reader who chose
24
+ * Large does not watch the whole grid re-lay itself out when the island
25
+ * mounts. Built from the constants above; keep it dependency-free and
26
+ * self-contained — an inline script cannot import this module at runtime.
27
+ */
28
+ export declare const TILE_SIZE_RESTORE_SCRIPT: string;
@@ -0,0 +1,42 @@
1
+ const ATTR_TILE_SIZE = "data-sg-tile-size";
2
+ const LS_TILE_SIZE = "sg-catalog-tile-size";
3
+ const TILE_SIZES = [
4
+ { id: "compact", label: "Compact", trackMin: 272 },
5
+ { id: "large", label: "Large", trackMin: 400 }
6
+ ];
7
+ const DEFAULT_TILE_SIZE = "compact";
8
+ function isTileSize(value) {
9
+ return TILE_SIZES.some((option) => option.id === value);
10
+ }
11
+ function readTileSize() {
12
+ try {
13
+ const raw = localStorage.getItem(LS_TILE_SIZE);
14
+ return isTileSize(raw) ? raw : DEFAULT_TILE_SIZE;
15
+ } catch {
16
+ return DEFAULT_TILE_SIZE;
17
+ }
18
+ }
19
+ function applyTileSize(size, el) {
20
+ (el ?? document.documentElement).setAttribute(ATTR_TILE_SIZE, size);
21
+ try {
22
+ localStorage.setItem(LS_TILE_SIZE, size);
23
+ } catch {
24
+ }
25
+ }
26
+ const TILE_SIZE_RESTORE_SCRIPT = [
27
+ "try{",
28
+ `var v=localStorage.getItem(${JSON.stringify(LS_TILE_SIZE)});`,
29
+ `if(${JSON.stringify(TILE_SIZES.map((option) => option.id))}.indexOf(v)>-1)`,
30
+ `document.documentElement.setAttribute(${JSON.stringify(ATTR_TILE_SIZE)},v)`,
31
+ "}catch(e){}"
32
+ ].join("");
33
+ export {
34
+ ATTR_TILE_SIZE,
35
+ DEFAULT_TILE_SIZE,
36
+ LS_TILE_SIZE,
37
+ TILE_SIZES,
38
+ TILE_SIZE_RESTORE_SCRIPT,
39
+ applyTileSize,
40
+ isTileSize,
41
+ readTileSize
42
+ };
@@ -0,0 +1,59 @@
1
+ /** @jsxRuntime automatic */
2
+ /** @jsxImportSource preact */
3
+ import type { ComponentChildren, JSX, VNode } from "preact";
4
+ import type { NavNode } from "../registry/nav-nodes.js";
5
+ export interface StyleguideLayoutProps {
6
+ /**
7
+ * Already-composed meta title (e.g. `composeMetaTitle("Components")`).
8
+ * Passed pre-composed because the title-composition helper is a host-owned
9
+ * concern and this package must not import the host's page tree.
10
+ */
11
+ title: string;
12
+ /**
13
+ * Active sidebar slug for the initial SSR highlight. The catalog landing
14
+ * passes "" (the Overview leaf); a story detail page passes its story slug.
15
+ * Ignored when the sidebar is hidden. `useActiveSlug` re-derives this from
16
+ * the URL on each page load, so this is just the initial value.
17
+ */
18
+ activeSlug?: string;
19
+ /** Active locale — the host's `defaultLocale` or a page's explicit locale. */
20
+ lang: string;
21
+ /** Hide the component sidebar for standalone pages such as /tokens. */
22
+ hideSidebar?: boolean;
23
+ /** `<head>` content — the host passes its `HeadWithDefaults` output. */
24
+ head: ComponentChildren;
25
+ /** Header region — the host passes its `HeaderWithDefaults` output. */
26
+ header: ComponentChildren;
27
+ /** Footer region — the host passes its `FooterWithDefaults` output. */
28
+ footer: ComponentChildren;
29
+ /** Body-end islands — the host passes its `BodyEndIslands` output. */
30
+ bodyEnd: ComponentChildren;
31
+ /**
32
+ * Right-region code panel content (detail pages only, #49). When present the
33
+ * TOC slot hosts it; when absent the slot is empty and `hideToc` frees the
34
+ * width.
35
+ */
36
+ codePanel?: VNode | null;
37
+ /**
38
+ * Opt the content band into the DocLayout **wide** layout — forwarded
39
+ * verbatim to `DocLayoutWithDefaults contentWide`. Defaults to `false`.
40
+ */
41
+ contentWide?: boolean;
42
+ /**
43
+ * The sidebar's nav tree — the host's generated styleguide nav (built with
44
+ * `@takazudo/zudo-sg/registry`'s `buildNavNodes`). Ignored when
45
+ * `hideSidebar` is set.
46
+ */
47
+ navNodes: NavNode[];
48
+ /** Mirrors the host's `settings.sidebarToggle` feature flag. */
49
+ sidebarToggle: boolean;
50
+ /**
51
+ * Mirrors the host's `settings.dynamicPageTransition` — forwarded to
52
+ * `DocLayoutWithDefaults`'s `enableClientRouter`.
53
+ */
54
+ enableClientRouter: boolean;
55
+ /** Mirrors the host's `settings.noindex`. */
56
+ noindex: boolean;
57
+ children: JSX.Element | JSX.Element[];
58
+ }
59
+ export declare function StyleguideLayout({ title, activeSlug, lang, hideSidebar, head, header, footer, bodyEnd, codePanel, contentWide, navNodes, sidebarToggle, enableClientRouter, noindex, children, }: StyleguideLayoutProps): JSX.Element;
@@ -0,0 +1,69 @@
1
+ import { Fragment, jsx, jsxs } from "preact/jsx-runtime";
2
+ import { Island } from "@takazudo/zfb";
3
+ import { DocLayoutWithDefaults } from "@takazudo/zudo-doc/doclayout";
4
+ import { SidebarTree } from "@takazudo/zudo-doc/sidebar-tree-island";
5
+ import {
6
+ createSidebarPrepaint,
7
+ createSidebarVisibilityPrepaint
8
+ } from "@takazudo/zudo-doc/sidebar-prepaint";
9
+ import { PanelStateHeadScript, PanelResizersInitScript } from "./panel-scripts.js";
10
+ function StyleguideLayout({
11
+ title,
12
+ activeSlug,
13
+ lang,
14
+ hideSidebar = false,
15
+ head,
16
+ header,
17
+ footer,
18
+ bodyEnd,
19
+ codePanel,
20
+ contentWide,
21
+ navNodes,
22
+ sidebarToggle,
23
+ enableClientRouter,
24
+ noindex,
25
+ children
26
+ }) {
27
+ const showCodePanel = Boolean(codePanel);
28
+ const sidebarToggleSettings = { sidebarToggle };
29
+ const SidebarPrepaint = createSidebarPrepaint(sidebarToggleSettings);
30
+ const SidebarVisibilityPrepaint = createSidebarVisibilityPrepaint(sidebarToggleSettings);
31
+ const sidebarOverride = hideSidebar ? /* @__PURE__ */ jsx(Fragment, {}) : Island({
32
+ when: "load",
33
+ children: /* @__PURE__ */ jsx(SidebarTree, { nodes: navNodes, currentSlug: activeSlug })
34
+ });
35
+ const tocOverride = showCodePanel ? codePanel : /* @__PURE__ */ jsx(Fragment, {});
36
+ const composedHead = /* @__PURE__ */ jsxs(Fragment, { children: [
37
+ head,
38
+ /* @__PURE__ */ jsx(SidebarVisibilityPrepaint, { hideSidebar }),
39
+ /* @__PURE__ */ jsx(PanelStateHeadScript, {})
40
+ ] });
41
+ const composedBodyEnd = /* @__PURE__ */ jsxs(Fragment, { children: [
42
+ bodyEnd,
43
+ /* @__PURE__ */ jsx(PanelResizersInitScript, {})
44
+ ] });
45
+ return /* @__PURE__ */ jsx(
46
+ DocLayoutWithDefaults,
47
+ {
48
+ title,
49
+ enableClientRouter,
50
+ head: composedHead,
51
+ lang,
52
+ noindex,
53
+ hideSidebar,
54
+ hideToc: !showCodePanel,
55
+ contentWide,
56
+ ...!hideSidebar ? { sidebarPersistKey: `sidebar-${lang}-components` } : {},
57
+ headerOverride: header,
58
+ sidebarOverride,
59
+ afterSidebar: /* @__PURE__ */ jsx(SidebarPrepaint, { hideSidebar }),
60
+ tocOverride,
61
+ footerOverride: footer,
62
+ bodyEndComponents: composedBodyEnd,
63
+ children
64
+ }
65
+ );
66
+ }
67
+ export {
68
+ StyleguideLayout
69
+ };
@@ -0,0 +1,4 @@
1
+ export { StyleguideLayout } from "./_styleguide-layout.js";
2
+ export type { StyleguideLayoutProps } from "./_styleguide-layout.js";
3
+ export { AFTER_SWAP_EVENT, ATTR_CODE_PANEL_HIDDEN, ATTR_CODE_PANEL_RESIZER, CSS_VAR_CODE_PANEL_W, CSS_VAR_SIDEBAR_W, ID_CODE_PANEL, LS_CODE_PANEL_HIDDEN, LS_CODE_PANEL_WIDTH, LS_SIDEBAR_WIDTH, MIN_CODE_PANEL_W, getPersistedWidth, isCodePanelHidden, setCodePanelHidden, setPanelWidth, toggleCodePanel, } from "./panel-contract.js";
4
+ export { PanelResizersInitScript, PanelStateHeadScript } from "./panel-scripts.js";
@@ -0,0 +1,39 @@
1
+ import { StyleguideLayout } from "./_styleguide-layout.js";
2
+ import {
3
+ AFTER_SWAP_EVENT,
4
+ ATTR_CODE_PANEL_HIDDEN,
5
+ ATTR_CODE_PANEL_RESIZER,
6
+ CSS_VAR_CODE_PANEL_W,
7
+ CSS_VAR_SIDEBAR_W,
8
+ ID_CODE_PANEL,
9
+ LS_CODE_PANEL_HIDDEN,
10
+ LS_CODE_PANEL_WIDTH,
11
+ LS_SIDEBAR_WIDTH,
12
+ MIN_CODE_PANEL_W,
13
+ getPersistedWidth,
14
+ isCodePanelHidden,
15
+ setCodePanelHidden,
16
+ setPanelWidth,
17
+ toggleCodePanel
18
+ } from "./panel-contract.js";
19
+ import { PanelResizersInitScript, PanelStateHeadScript } from "./panel-scripts.js";
20
+ export {
21
+ AFTER_SWAP_EVENT,
22
+ ATTR_CODE_PANEL_HIDDEN,
23
+ ATTR_CODE_PANEL_RESIZER,
24
+ CSS_VAR_CODE_PANEL_W,
25
+ CSS_VAR_SIDEBAR_W,
26
+ ID_CODE_PANEL,
27
+ LS_CODE_PANEL_HIDDEN,
28
+ LS_CODE_PANEL_WIDTH,
29
+ LS_SIDEBAR_WIDTH,
30
+ MIN_CODE_PANEL_W,
31
+ PanelResizersInitScript,
32
+ PanelStateHeadScript,
33
+ StyleguideLayout,
34
+ getPersistedWidth,
35
+ isCodePanelHidden,
36
+ setCodePanelHidden,
37
+ setPanelWidth,
38
+ toggleCodePanel
39
+ };
@@ -0,0 +1,15 @@
1
+ export declare const ATTR_CODE_PANEL_HIDDEN = "data-sg-code-panel-hidden";
2
+ export declare const LS_CODE_PANEL_HIDDEN = "sg-code-panel-hidden";
3
+ export declare const LS_SIDEBAR_WIDTH = "zudo-doc-sidebar-width";
4
+ export declare const LS_CODE_PANEL_WIDTH = "sg-code-panel-width";
5
+ export declare const CSS_VAR_SIDEBAR_W = "--zd-sidebar-w";
6
+ export declare const CSS_VAR_CODE_PANEL_W = "--sg-code-panel-w";
7
+ export declare const MIN_CODE_PANEL_W = 280;
8
+ export declare const ID_CODE_PANEL = "sg-code-panel";
9
+ export declare const ATTR_CODE_PANEL_RESIZER = "data-sg-code-panel-resizer";
10
+ export { AFTER_NAVIGATE_EVENT as AFTER_SWAP_EVENT } from "@takazudo/zudo-doc/transitions";
11
+ export declare function isCodePanelHidden(el?: HTMLElement): boolean;
12
+ export declare function setCodePanelHidden(hidden: boolean, el?: HTMLElement): void;
13
+ export declare function toggleCodePanel(el?: HTMLElement): void;
14
+ export declare function setPanelWidth(cssVar: string, lsKey: string, px: number, el?: HTMLElement): void;
15
+ export declare function getPersistedWidth(lsKey: string): number | undefined;