@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
@@ -0,0 +1,95 @@
1
+ /** @jsxRuntime automatic */
2
+ /** @jsxImportSource preact */
3
+ // Injected at `sgContext.routes.componentsIndex` — the component catalog
4
+ // landing: category-grouped tiles, each carrying its component rendered
5
+ // INLINE server-side (no preview iframes), filtered client-side by the
6
+ // CatalogFilter island, inside the StyleguideLayout docs-section shell.
7
+
8
+ import type { JSX, VNode } from "preact";
9
+ import { Island } from "@takazudo/zfb";
10
+ import { ComponentThumb, TILE_SIZE_RESTORE_SCRIPT } from "@takazudo/zudo-sg/catalog";
11
+ import { StyleguideLayout } from "@takazudo/zudo-sg/chrome";
12
+ import { OVERVIEW_SLUG } from "@takazudo/zudo-sg/registry";
13
+ import { CatalogFilter } from "@takazudo/zudo-sg/search";
14
+ import { componentHref } from "@takazudo/zudo-sg/sg-routes";
15
+ import { chromeProps } from "./_chrome.js";
16
+ import { ctx, withBase } from "./_context.js";
17
+ import { registry } from "./_registry.js";
18
+
19
+ export const frontmatter = { title: "Components" };
20
+
21
+ export default function ComponentsIndexRoute(): JSX.Element {
22
+ const groups = registry.getCategoryGroups();
23
+ const total = groups.reduce((n, g) => n + g.stories.length, 0);
24
+ const categories = groups.map((g) => g.category);
25
+
26
+ const filterIsland = Island({
27
+ when: "load",
28
+ children: <CatalogFilter categories={categories} total={total} />,
29
+ }) as unknown as VNode;
30
+
31
+ return (
32
+ <StyleguideLayout
33
+ {...chromeProps({
34
+ pageTitle: "Components",
35
+ path: ctx.routes.componentsIndex,
36
+ // Restore the persisted tile size before first paint so the grid does
37
+ // not re-flow when the island mounts.
38
+ extraHead: <script dangerouslySetInnerHTML={{ __html: TILE_SIZE_RESTORE_SCRIPT }} />,
39
+ activeSlug: OVERVIEW_SLUG,
40
+ })}
41
+ activeSlug={OVERVIEW_SLUG}
42
+ contentWide
43
+ >
44
+ <header class="mb-vsp-lg max-w-[56rem]">
45
+ <h1 class="text-heading font-bold mb-vsp-2xs">{ctx.catalog.title}</h1>
46
+ <p class="text-muted text-small" data-sg-catalog-intro>
47
+ {ctx.catalog.intro ?? (
48
+ <>
49
+ {total} components{ctx.uiPackageName ? <> from <code>{ctx.uiPackageName}</code></> : null},
50
+ discovered from their <code>.stories.tsx</code> files. Each tile previews the
51
+ component's first variant, rendered here on the server.
52
+ </>
53
+ )}
54
+ </p>
55
+ </header>
56
+
57
+ {filterIsland}
58
+
59
+ <div data-sg-catalog>
60
+ {groups.map((group) => (
61
+ <section class="sg-gallery-section" data-sg-section data-category={group.category}>
62
+ <h2 class="mb-vsp-sm text-heading font-semibold">{group.category}</h2>
63
+ <div class="sg-grid">
64
+ {group.stories.map((story) => (
65
+ <div class="sg-tile" data-sg-tile>
66
+ <ComponentThumb entry={story} />
67
+ <a
68
+ href={withBase(componentHref(ctx.routes, story.slug))}
69
+ class="sg-tile-meta"
70
+ data-sg-card
71
+ data-name={story.meta.title.toLowerCase()}
72
+ data-category={group.category}
73
+ data-keywords={[story.meta.title, story.meta.description ?? "", story.meta.category ?? ""]
74
+ .join(" ")
75
+ .toLowerCase()}
76
+ >
77
+ <h3 class="sg-tile-title">{story.meta.title}</h3>
78
+ <p class="sg-tile-desc">{story.meta.description}</p>
79
+ <p class="sg-tile-count">
80
+ {story.variants.length} variant
81
+ {story.variants.length === 1 ? "" : "s"}
82
+ </p>
83
+ </a>
84
+ </div>
85
+ ))}
86
+ </div>
87
+ </section>
88
+ ))}
89
+ <p class="text-muted text-small" data-sg-empty hidden>
90
+ No components match your search.
91
+ </p>
92
+ </div>
93
+ </StyleguideLayout>
94
+ );
95
+ }
@@ -0,0 +1,55 @@
1
+ /** @jsxRuntime automatic */
2
+ /** @jsxImportSource preact */
3
+ // Injected at `sgContext.routes.componentsPreview` — the isolated variant
4
+ // preview document loaded as the `src` of every VariantFrame iframe.
5
+ //
6
+ // Static hosting serves the SAME HTML for every `?slug=…&variant=…`, so the
7
+ // variant is resolved client-side by PreviewApp (through the no-props
8
+ // `ConfiguredPreviewApp` island, statically imported below so the island
9
+ // scanner registers it). Chrome-free: it owns its full `<html>` document.
10
+ //
11
+ // Styling: the standalone-compiled preview stylesheet
12
+ // (`@takazudo/zudo-sg/plugins/preview-css`) is linked here, and `<html>`
13
+ // carries `data-sg-preview-doc` — the compiler rescopes every token block to
14
+ // `:root[data-sg-preview-doc]`, so the preview world's tokens beat the host
15
+ // bundle zfb injects into every route. This entrypoint links assets only; it
16
+ // never calls plugin helpers.
17
+
18
+ import type { JSX, VNode } from "preact";
19
+ import { Island } from "@takazudo/zfb";
20
+ import ConfiguredPreviewApp from "./_preview-app.js";
21
+ import { ctx, withBase } from "./_context.js";
22
+
23
+ export const frontmatter = { title: "Preview" };
24
+
25
+ // DEV-ONLY: the zfb dev server injects /__zfb/livereload.js into every served
26
+ // document. Each preview iframe would then hold a permanent EventSource to
27
+ // /__zfb/reload; a detail page with 5+ variant iframes exhausts the browser's
28
+ // 6-per-host HTTP/1.1 connection cap. Stubbing it inside the iframe keeps the
29
+ // connection closed. No-op in a static build (no livereload script there).
30
+ const LIVERELOAD_STUB =
31
+ "(function(){try{var R=window.EventSource;if(!R)return;window.EventSource=function(u,o){if(typeof u==='string'&&u.indexOf('__zfb/reload')!==-1){return{close:function(){},addEventListener:function(){},removeEventListener:function(){},onmessage:null,onerror:null,onopen:null,readyState:2};}return new R(u,o);};window.EventSource.prototype=R.prototype;}catch(e){}})();";
32
+
33
+ export default function ComponentsPreviewRoute(): JSX.Element {
34
+ // SSR-skip island: the variant depends on `location.search`, so nothing
35
+ // renders server-side and the runtime mounts ConfiguredPreviewApp on load.
36
+ const app = Island({
37
+ when: "load",
38
+ ssrFallback: <div data-sg-preview-loading />,
39
+ children: <ConfiguredPreviewApp />,
40
+ }) as unknown as VNode;
41
+
42
+ return (
43
+ <html lang="en" data-sg-preview-doc>
44
+ <head>
45
+ <meta charset="utf-8" />
46
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
47
+ <meta name="robots" content="noindex" />
48
+ <title>Preview</title>
49
+ <link rel="stylesheet" href={withBase(ctx.previewCssUrl)} data-sg-preview-css />
50
+ <script dangerouslySetInnerHTML={{ __html: LIVERELOAD_STUB }} />
51
+ </head>
52
+ <body class="bg-bg">{app}</body>
53
+ </html>
54
+ );
55
+ }
@@ -0,0 +1,145 @@
1
+ /** @jsxRuntime automatic */
2
+ /** @jsxImportSource preact */
3
+ // Injected at `sgContext.routes.componentsSlug` — the component detail page.
4
+ // zfb extracts `paths()` from this `.tsx` source by AST (one route per story).
5
+ //
6
+ // One DetailWorkbench island owns the page toolbar (theme / viewport / layout
7
+ // / code panel / preview tokens) and one isolated preview iframe per variant;
8
+ // the CodePanel island sits in the right region. Both receive the same
9
+ // base-prefixed preview URL (VariantFrame builds iframe `src` from it; the
10
+ // code panel's CSS injection selects iframes by it). The optional co-located
11
+ // component MDX doc renders as a trailing section.
12
+
13
+ import type { JSX, VNode } from "preact";
14
+ import { Island } from "@takazudo/zfb";
15
+ import { getEntry } from "@takazudo/zfb/content";
16
+ import { makeAdmonition } from "@takazudo/zudo-doc/content-admonition";
17
+ import { StyleguideLayout } from "@takazudo/zudo-sg/chrome";
18
+ import { CodePanel, type CodePanelVariant } from "@takazudo/zudo-sg/code-panel";
19
+ import { DetailWorkbench } from "@takazudo/zudo-sg/preview";
20
+ import { resolveComponentDoc } from "@takazudo/zudo-sg/registry";
21
+ import { componentHref } from "@takazudo/zudo-sg/sg-routes";
22
+ import { chromeProps } from "./_chrome.js";
23
+ import { ctx, withBase } from "./_context.js";
24
+ import { registry } from "./_registry.js";
25
+
26
+ export const frontmatter = { title: "Component" };
27
+
28
+ interface SlugProps {
29
+ slug: string;
30
+ }
31
+
32
+ /** Admonition tags emitted by `:::note` directives / github alerts inside component docs. */
33
+ const componentDocMdxComponents = {
34
+ Note: makeAdmonition("note"),
35
+ Tip: makeAdmonition("tip"),
36
+ Info: makeAdmonition("info"),
37
+ Warning: makeAdmonition("warning"),
38
+ Danger: makeAdmonition("danger"),
39
+ Caution: makeAdmonition("caution"),
40
+ Important: makeAdmonition("important"),
41
+ };
42
+
43
+ export function paths(): Array<{ params: { slug: string }; props: SlugProps }> {
44
+ return registry.getAllSlugs().map((slug) => ({ params: { slug }, props: { slug } }));
45
+ }
46
+
47
+ export default function ComponentsSlugRoute(props: SlugProps & { params: { slug: string } }): JSX.Element {
48
+ const slug = props.slug ?? props.params.slug;
49
+ const entry = registry.getStoryBySlug(slug);
50
+ const previewUrl = withBase(ctx.routes.componentsPreview);
51
+ const chrome = chromeProps({
52
+ pageTitle: entry ? entry.meta.title : "Not found",
53
+ path: componentHref(ctx.routes, slug),
54
+ activeSlug: slug,
55
+ });
56
+
57
+ if (!entry) {
58
+ return (
59
+ <StyleguideLayout {...chrome} activeSlug={slug} codePanel={null}>
60
+ <p class="text-muted">Story not found: {slug}</p>
61
+ </StyleguideLayout>
62
+ );
63
+ }
64
+
65
+ const panelVariants: CodePanelVariant[] = entry.variants.map((v) => ({
66
+ exportName: v.exportName,
67
+ name: v.name,
68
+ source: v.story.source ?? entry.meta.usage,
69
+ }));
70
+ const codePanelIsland = Island({
71
+ when: "load",
72
+ children: <CodePanel storyTitle={entry.meta.title} variants={panelVariants} previewUrl={previewUrl} />,
73
+ }) as unknown as VNode;
74
+ const codePanel = (
75
+ <aside id="sg-code-panel" class="sg-code-panel" aria-label="Code panel">
76
+ <div
77
+ class="sg-code-panel-resizer"
78
+ data-sg-code-panel-resizer
79
+ role="separator"
80
+ aria-label="Resize code panel"
81
+ aria-orientation="vertical"
82
+ tabindex={0}
83
+ />
84
+ {codePanelIsland}
85
+ </aside>
86
+ ) as unknown as VNode;
87
+
88
+ // The collection of the components root this story's registry key belongs to
89
+ // (`./<keyPrefix>/<dir>/<name>.stories.tsx` → `<dir>/<name>`).
90
+ const docRef = resolveComponentDoc(entry.path, ctx.componentDocs);
91
+ const doc = docRef ? getEntry(docRef.collection, docRef.slug) : undefined;
92
+
93
+ // `when: "load"`: the toolbar is the page's primary control surface; each
94
+ // iframe is `loading="lazy"`, so below-the-fold previews still defer.
95
+ const workbench = Island({
96
+ when: "load",
97
+ children: (
98
+ <DetailWorkbench
99
+ slug={slug}
100
+ previewUrl={previewUrl}
101
+ variants={entry.variants.map((v) => ({
102
+ exportName: v.exportName,
103
+ name: v.name,
104
+ controls: v.story.controls,
105
+ }))}
106
+ />
107
+ ),
108
+ }) as unknown as VNode;
109
+
110
+ return (
111
+ <StyleguideLayout {...chrome} activeSlug={slug} codePanel={codePanel} contentWide>
112
+ <div>
113
+ <header class="mb-vsp-lg max-w-[56rem]">
114
+ <h1 class="text-2xl font-bold text-fg">{entry.meta.title}</h1>
115
+ <p class="mt-vsp-xs text-muted">{entry.meta.description}</p>
116
+ <span class="mt-vsp-xs inline-block rounded-full border border-border px-hsp-sm py-vsp-3xs text-caption leading-normal text-muted">
117
+ {entry.meta.category}
118
+ </span>
119
+ </header>
120
+
121
+ {entry.meta.previewRoute && (
122
+ <section class="mb-vsp-xl max-w-[56rem] rounded-md border border-border bg-surface-2 p-hsp-md">
123
+ <h2 class="mb-vsp-2xs text-small font-semibold uppercase tracking-wide text-muted">Live demo</h2>
124
+ <a
125
+ href={withBase(entry.meta.previewRoute)}
126
+ class="text-sm font-medium text-accent underline underline-offset-2"
127
+ >
128
+ Open live demo →
129
+ </a>
130
+ </section>
131
+ )}
132
+
133
+ {workbench}
134
+
135
+ {doc && (
136
+ <section class="mt-vsp-xl border-t border-border pt-vsp-xl">
137
+ <div class="zd-content max-w-[56rem]">
138
+ <doc.Content components={componentDocMdxComponents} />
139
+ </div>
140
+ </section>
141
+ )}
142
+ </div>
143
+ </StyleguideLayout>
144
+ );
145
+ }
@@ -0,0 +1,76 @@
1
+ /** @jsxRuntime automatic */
2
+ /** @jsxImportSource preact */
3
+ // Injected at `sgContext.routes.tokens` — the declared-defaults design-token
4
+ // dashboards. The manifest arrives through `virtual:zudo-sg-tokens` (routes
5
+ // plugin `tokensManifestModule` = `zudo-sg.config.mjs` `tokens.manifestOut`);
6
+ // without one (no `tokens` config) the page renders its header and an empty-state note.
7
+
8
+ import type { JSX, VNode } from "preact";
9
+ import { Island } from "@takazudo/zfb";
10
+ import { resolveRampRef } from "@takazudo/zudo-doc/color-scheme-utils";
11
+ import { tokensManifest } from "virtual:zudo-sg-tokens";
12
+ import { StyleguideLayout } from "@takazudo/zudo-sg/chrome";
13
+ import { TOKENS_SLUG } from "@takazudo/zudo-sg/registry";
14
+ import { buildUiTokenTabs, createTokenDashboards } from "@takazudo/zudo-sg/token-dashboard";
15
+ import PreviewTokensButton from "@takazudo/zudo-sg/token-tweak/preview-tokens-button";
16
+ import { chromeProps, routeCtx, settings } from "./_chrome.js";
17
+ import { ctx } from "./_context.js";
18
+
19
+ export const frontmatter = { title: "Design Tokens" };
20
+
21
+ /**
22
+ * Per-mode dashboard chrome colors resolved from the site's zudo-doc color
23
+ * schemes (`--zdtp-dashboard-{light,dark}-{bg,fg}`); `undefined` when the
24
+ * host passed no `colorSchemes` to the zudo-doc preset.
25
+ */
26
+ function buildDashboardChromeStyle(): Record<string, string> | undefined {
27
+ const schemes = routeCtx.colorSchemes;
28
+ if (!schemes) return undefined;
29
+ const entries: Array<[string, string]> = [];
30
+ for (const mode of ["light", "dark"] as const) {
31
+ const schemeName = settings.colorMode ? settings.colorMode[`${mode}Scheme`] : settings.colorScheme;
32
+ const scheme = schemes[schemeName];
33
+ if (!scheme) return undefined;
34
+ for (const role of ["bg", "fg"] as const) {
35
+ entries.push([`--zdtp-dashboard-${mode}-${role}`, resolveRampRef(scheme.map[role], scheme.ramps)]);
36
+ }
37
+ }
38
+ return Object.fromEntries(entries);
39
+ }
40
+
41
+ export default function TokensRoute(): JSX.Element {
42
+ const previewTokensButton = Island({
43
+ when: "load",
44
+ children: <PreviewTokensButton />,
45
+ }) as unknown as VNode;
46
+
47
+ return (
48
+ <StyleguideLayout
49
+ {...chromeProps({ pageTitle: "Design Tokens", path: ctx.routes.tokens, activeSlug: TOKENS_SLUG, hideSidebar: true })}
50
+ activeSlug={TOKENS_SLUG}
51
+ hideSidebar
52
+ >
53
+ <div>
54
+ <header class="mb-vsp-lg max-w-[56rem]">
55
+ <h1 class="text-heading font-bold mb-vsp-2xs">Design tokens</h1>
56
+ <p class="mt-vsp-xs mb-vsp-sm text-muted">
57
+ Declared defaults{ctx.uiPackageName ? <> for <code>{ctx.uiPackageName}</code></> : null}, shown as
58
+ light, dark, and shared token references. Open Preview tokens to edit the component previews; these
59
+ reference dashboards stay unchanged.
60
+ </p>
61
+ {previewTokensButton}
62
+ </header>
63
+ {tokensManifest
64
+ ? createTokenDashboards(tokensManifest, buildUiTokenTabs(tokensManifest), {
65
+ chromeStyle: buildDashboardChromeStyle(),
66
+ })
67
+ : (
68
+ <p class="text-muted" data-zudo-sg-tokens-empty>
69
+ No design-token manifest is configured. Add <code>tokens</code> to <code>zudo-sg.config.mjs</code> and
70
+ run <code>zudo-sg gen-token-manifest</code> to render the dashboards here.
71
+ </p>
72
+ )}
73
+ </div>
74
+ </StyleguideLayout>
75
+ );
76
+ }