@takazudo/zudo-sg 0.3.0 → 0.3.2
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 +45 -0
- package/README.md +62 -0
- package/dist/cli/config.d.ts +4 -0
- package/dist/cli/registry/allocate-import-names.d.ts +3 -0
- package/dist/cli/registry/allocate-import-names.js +104 -0
- package/dist/cli/registry/build-registry-source.js +5 -5
- package/dist/cli/registry/discover-stories.d.ts +3 -10
- package/dist/cli/registry/discover-stories.js +0 -14
- package/dist/cli/registry/gen-registry.js +5 -4
- package/dist/cli/scaffold/component-scaffold.d.ts +4 -4
- package/dist/cli/scaffold/component-scaffold.js +5 -6
- package/dist/cli/token-manifest/gen-token-manifest.js +1 -1
- package/dist/cli/token-manifest/ui-token-manifest.d.ts +15 -1
- package/dist/cli/token-manifest/ui-token-manifest.js +197 -11
- package/dist/config/index.d.ts +33 -1
- package/dist/config/index.js +34 -1
- package/dist/plugins/routes.js +3 -4
- package/dist/plugins/zdtp-apply-proxy.d.ts +7 -2
- package/dist/safelist.css +1 -1
- package/dist/token-dashboard/create-token-dashboards.js +4 -3
- package/dist/token-dashboard/ui-token-tabs.d.ts +17 -4
- package/dist/token-dashboard/ui-token-tabs.js +39 -4
- package/dist/token-spec.d.ts +41 -0
- package/dist/token-spec.js +0 -0
- package/package.json +1 -1
- package/routes-src/_chrome.tsx +13 -1
- package/routes-src/components-preview.tsx +4 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,51 @@ 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.3.2] - 2026-09-23
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
- Configure an ordered host-owned vocabulary with `tokens.spec` for palette,
|
|
12
|
+
semantic colors, spacing, fonts, and sizes. CSS supplies values, while the
|
|
13
|
+
spec controls groups, labels, controls, options, units, and previews.
|
|
14
|
+
- Carry custom token metadata into the dashboard and preview panel, including
|
|
15
|
+
sparse palettes and unrelated CSS variable prefixes. Hosts that omit the
|
|
16
|
+
spec retain the existing default vocabulary and legacy manifest support.
|
|
17
|
+
- Validate custom specs before writing generated files and document the
|
|
18
|
+
supported metadata and CSS parser constraints.
|
|
19
|
+
|
|
20
|
+
### Bug Fixes
|
|
21
|
+
|
|
22
|
+
- Generate components without a demo-local class-name helper dependency and
|
|
23
|
+
import story types from the public `@takazudo/zudo-sg/stories` entry point.
|
|
24
|
+
Flat and nested scaffolds now typecheck and build in a fresh starter.
|
|
25
|
+
- Allocate deterministic, unique registry import bindings for sibling stories,
|
|
26
|
+
multiple roots, sanitized names, and names reserved by generated code.
|
|
27
|
+
- Keep the starter's token adapter compatible with legacy five-array manifests
|
|
28
|
+
while accepting optional host-group metadata.
|
|
29
|
+
|
|
30
|
+
## [0.3.1] - 2026-09-21
|
|
31
|
+
|
|
32
|
+
The preview token panel is now reachable from the doc header, not just from the
|
|
33
|
+
workbench button and the `/tokens` dashboard. The engine injects that trigger
|
|
34
|
+
itself, so adopting hosts get it without wiring anything.
|
|
35
|
+
|
|
36
|
+
### Features
|
|
37
|
+
|
|
38
|
+
- `withZudoSg()` appends a preview-token-panel trigger to the doc header's right
|
|
39
|
+
side, revealed only on engine routes. Gated by the new `headerTokenTrigger`
|
|
40
|
+
option, which defaults to `true`.
|
|
41
|
+
- Export `HEADER_TOKEN_TRIGGER_ITEM` so a host that renders its own zudo-doc
|
|
42
|
+
header can list the trigger alongside its own items.
|
|
43
|
+
- Emit a `data-sg-engine-route` marker from `bodyEnd` on every chrome-rendered
|
|
44
|
+
engine route, and on the preview iframe document's own `html` tag, so client
|
|
45
|
+
code can detect "this page can use the preview token panel" after each
|
|
46
|
+
navigation.
|
|
47
|
+
- `ZdtpApplyProxyOptions` now accepts `tabsModule` on its own: `routingFile` and
|
|
48
|
+
`writeRoot` became optional together, so a host can wire the panel's tabs
|
|
49
|
+
without opting into the dev-only Apply endpoint. Supplying exactly one of the
|
|
50
|
+
pair still fails at both the type level and at runtime.
|
|
51
|
+
|
|
7
52
|
## [0.3.0] - 2026-09-21
|
|
8
53
|
|
|
9
54
|
The catalog chrome no longer borrows a host's bare `--color-*` tokens. It now
|
package/README.md
CHANGED
|
@@ -32,6 +32,64 @@ dogfoods the engine as its own styleguide host — see
|
|
|
32
32
|
- Token dashboards and a preview design-token panel, driven by a
|
|
33
33
|
`gen-token-manifest`-produced manifest.
|
|
34
34
|
|
|
35
|
+
## Host-owned token vocabulary
|
|
36
|
+
|
|
37
|
+
`tokens.spec` is optional. Without it, `gen-token-manifest` keeps the historical
|
|
38
|
+
UI token vocabulary and the five legacy arrays. With it, the supplied spec
|
|
39
|
+
**replaces** that vocabulary: omitted categories produce no rows. Each category
|
|
40
|
+
(`palette`, `color`, `spacing`, `font`, `size`) is an ordered array of groups;
|
|
41
|
+
each group has `id`, `label`, `tokens`, and optional `preview` / `previewBase`.
|
|
42
|
+
Every token names a declared `cssVar`; optional `id`, `label`, `control`, `step`,
|
|
43
|
+
`unit`, `units`, `options`, `readonly`, `pill`, `note`, and `valueKind: "number"`
|
|
44
|
+
provide metadata. `note` stays in the generated module; zdtp has no per-row
|
|
45
|
+
note field, so it is not displayed in the panel. The generated module still exports the five familiar
|
|
46
|
+
arrays, plus `UI_TOKEN_GROUPS` for custom specs. The engine's injected `/tokens`
|
|
47
|
+
route and preview panel consume the same groups. Existing five-array modules
|
|
48
|
+
remain valid without metadata.
|
|
49
|
+
|
|
50
|
+
```js
|
|
51
|
+
// zudo-sg.config.mjs — CSS files must declare every listed variable.
|
|
52
|
+
tokens: {
|
|
53
|
+
cssFiles: ["./src/styles/tokens.css", "./src/styles/colors.css"],
|
|
54
|
+
manifestOut: "./src/styleguide/token-manifest.ts",
|
|
55
|
+
spec: {
|
|
56
|
+
palette: [{ id: "brand", label: "Brand", tokens: [
|
|
57
|
+
{ cssVar: "--brand-100" }, { cssVar: "--brand-500", readonly: true },
|
|
58
|
+
] }],
|
|
59
|
+
color: [{ id: "surface", label: "Surfaces", tokens: [
|
|
60
|
+
{ cssVar: "--surface-canvas", control: "text" },
|
|
61
|
+
] }],
|
|
62
|
+
spacing: [{ id: "inset", label: "Inset", preview: "bar", tokens: [
|
|
63
|
+
{ cssVar: "--space-inline", step: 0.125, unit: "rem", units: ["rem", "px"] },
|
|
64
|
+
] }],
|
|
65
|
+
font: [{ id: "leading", label: "Leading", preview: "line-height",
|
|
66
|
+
previewBase: "--type-body", tokens: [
|
|
67
|
+
{ cssVar: "--type-leading", valueKind: "number", step: 0.1 },
|
|
68
|
+
] }],
|
|
69
|
+
size: [{ id: "corners", label: "Corners", preview: "radius", tokens: [
|
|
70
|
+
{ cssVar: "--corner-card", step: 0.125, unit: "rem" },
|
|
71
|
+
] }],
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
The supported preview/kind pairs are `size`, `bar`, and `radius` with lengths;
|
|
77
|
+
`line-height` with numbers; `family` with text; `weight` with select options or
|
|
78
|
+
unitless numbers; and `duration` with `ms`/`s` lengths or numbers. `previewBase`
|
|
79
|
+
requires `line-height` and an existing CSS variable. Omit preview for ordinary
|
|
80
|
+
rows. Palette colors use their explicit CSS names, including sparse ramps and
|
|
81
|
+
unrelated prefixes; custom groups use generic panel tabs. Values such as
|
|
82
|
+
`light-dark()` and `var()` remain raw CSS expressions in the manifest.
|
|
83
|
+
|
|
84
|
+
The parser reads literal custom-property declarations in the configured CSS
|
|
85
|
+
files. It does not follow CSS imports or evaluate expressions. Conflicting
|
|
86
|
+
repeat declarations, invalid or duplicate effective IDs/names, unsupported
|
|
87
|
+
preview/control combinations, and missing references fail generation before
|
|
88
|
+
writing output. Run `pnpm gen-token-manifest` after changing CSS or the spec,
|
|
89
|
+
then `pnpm gen-token-manifest --check` in CI. The complete foreign configuration lives in `fixtures/foreign-tokens/`. The packed foreign-host
|
|
90
|
+
proof is `node scripts/verify-styleguide-install.mjs` from
|
|
91
|
+
this repository (a guarded heavy check).
|
|
92
|
+
|
|
35
93
|
## Framework scope
|
|
36
94
|
|
|
37
95
|
Preact + zfb hosts only. React 19 hosts are an explicit non-goal for this
|
|
@@ -55,6 +113,10 @@ It copies a private starter with three example Preact components, stories,
|
|
|
55
113
|
token CSS, a preview entry, and the zfb/zudo-doc composition already wired.
|
|
56
114
|
The CLI prints the same next steps after scaffolding.
|
|
57
115
|
|
|
116
|
+
`new-component` emits stories that import their `StoryMeta` and `Story` types
|
|
117
|
+
from `@takazudo/zudo-sg/stories`. Generated components compose their classes
|
|
118
|
+
locally, so a host does not need to add a demo-specific `cx` helper.
|
|
119
|
+
|
|
58
120
|
`gen-registry` bootstraps a missing or whitespace-only `registryOut` and its
|
|
59
121
|
parent directories, so a new host does not need to create a marker-only seed
|
|
60
122
|
file by hand. A non-empty registry without generated markers is rejected to
|
package/dist/cli/config.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { HostTokensSpec } from "../token-spec.js";
|
|
2
|
+
export type { HostTokensSpec, HostTokenGroupSpec, HostTokenSpec, TokenPreview, TokenControl, GeneratedTokenGroups, GeneratedTokenGroup } from "../token-spec.js";
|
|
1
3
|
/** One corpus of `*.stories.tsx` files the registry codegen discovers. */
|
|
2
4
|
export interface ZudoSgComponentsRoot {
|
|
3
5
|
/** Project-root-relative directory to scan, e.g. "packages/demo-ui/src". */
|
|
@@ -14,6 +16,8 @@ export interface ZudoSgTokensConfig {
|
|
|
14
16
|
cssFiles: [string, string];
|
|
15
17
|
/** Project-root-relative output path for the generated manifest. */
|
|
16
18
|
manifestOut: string;
|
|
19
|
+
/** Ordered host token vocabulary; omitted retains the bundled demo vocabulary. */
|
|
20
|
+
spec?: HostTokensSpec;
|
|
17
21
|
}
|
|
18
22
|
export interface ZudoSgConfig {
|
|
19
23
|
componentsRoots: ZudoSgComponentsRoot[];
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
const RESERVED = /* @__PURE__ */ new Set([
|
|
2
|
+
"arguments",
|
|
3
|
+
"as",
|
|
4
|
+
"async",
|
|
5
|
+
"await",
|
|
6
|
+
"break",
|
|
7
|
+
"case",
|
|
8
|
+
"catch",
|
|
9
|
+
"class",
|
|
10
|
+
"const",
|
|
11
|
+
"continue",
|
|
12
|
+
"debugger",
|
|
13
|
+
"declare",
|
|
14
|
+
"default",
|
|
15
|
+
"delete",
|
|
16
|
+
"do",
|
|
17
|
+
"else",
|
|
18
|
+
"enum",
|
|
19
|
+
"eval",
|
|
20
|
+
"export",
|
|
21
|
+
"extends",
|
|
22
|
+
"false",
|
|
23
|
+
"finally",
|
|
24
|
+
"for",
|
|
25
|
+
"from",
|
|
26
|
+
"function",
|
|
27
|
+
"get",
|
|
28
|
+
"if",
|
|
29
|
+
"implements",
|
|
30
|
+
"import",
|
|
31
|
+
"in",
|
|
32
|
+
"instanceof",
|
|
33
|
+
"interface",
|
|
34
|
+
"let",
|
|
35
|
+
"module",
|
|
36
|
+
"new",
|
|
37
|
+
"null",
|
|
38
|
+
"of",
|
|
39
|
+
"package",
|
|
40
|
+
"private",
|
|
41
|
+
"protected",
|
|
42
|
+
"public",
|
|
43
|
+
"require",
|
|
44
|
+
"return",
|
|
45
|
+
"set",
|
|
46
|
+
"static",
|
|
47
|
+
"super",
|
|
48
|
+
"switch",
|
|
49
|
+
"this",
|
|
50
|
+
"throw",
|
|
51
|
+
"true",
|
|
52
|
+
"try",
|
|
53
|
+
"type",
|
|
54
|
+
"typeof",
|
|
55
|
+
"undefined",
|
|
56
|
+
"var",
|
|
57
|
+
"void",
|
|
58
|
+
"while",
|
|
59
|
+
"with",
|
|
60
|
+
"yield",
|
|
61
|
+
"storyModules",
|
|
62
|
+
"storyExportOrder",
|
|
63
|
+
"StoryModule",
|
|
64
|
+
"STORY_MODULES"
|
|
65
|
+
]);
|
|
66
|
+
function validBinding(name) {
|
|
67
|
+
return /^[A-Za-z_$][\w$]*$/.test(name) && !RESERVED.has(name);
|
|
68
|
+
}
|
|
69
|
+
function identityBinding(mapKey) {
|
|
70
|
+
const parts = mapKey.replace(/\.stories\.tsx$/, "").split(/[^A-Za-z0-9_$]+/).filter(Boolean);
|
|
71
|
+
const name = parts.map(
|
|
72
|
+
(part, index) => index === 0 ? part : part[0].toUpperCase() + part.slice(1)
|
|
73
|
+
).join("");
|
|
74
|
+
return /^[A-Za-z_$]/.test(name) ? name : `_${name || "story"}`;
|
|
75
|
+
}
|
|
76
|
+
function allocateImportNames(entries) {
|
|
77
|
+
const sorted = [...entries].sort((a, b) => a.mapKey < b.mapKey ? -1 : a.mapKey > b.mapKey ? 1 : 0);
|
|
78
|
+
for (let i = 1; i < sorted.length; i++) {
|
|
79
|
+
if (sorted[i].mapKey === sorted[i - 1].mapKey) {
|
|
80
|
+
throw new Error(`gen-registry: duplicate story map key ${JSON.stringify(sorted[i].mapKey)}`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
const counts = /* @__PURE__ */ new Map();
|
|
84
|
+
for (const entry of sorted) counts.set(entry.importName, (counts.get(entry.importName) ?? 0) + 1);
|
|
85
|
+
const used = /* @__PURE__ */ new Set();
|
|
86
|
+
for (const entry of sorted) {
|
|
87
|
+
if (counts.get(entry.importName) === 1 && validBinding(entry.importName)) {
|
|
88
|
+
used.add(entry.importName);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return sorted.map((entry) => {
|
|
92
|
+
if (counts.get(entry.importName) === 1 && validBinding(entry.importName)) return entry;
|
|
93
|
+
const base = identityBinding(entry.mapKey);
|
|
94
|
+
let name = base;
|
|
95
|
+
for (let suffix = 2; !validBinding(name) || used.has(name); suffix++) {
|
|
96
|
+
name = `${base}_${suffix}`;
|
|
97
|
+
}
|
|
98
|
+
used.add(name);
|
|
99
|
+
return { ...entry, importName: name };
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
export {
|
|
103
|
+
allocateImportNames
|
|
104
|
+
};
|
|
@@ -6,7 +6,7 @@ function buildRegistryBlock(entries) {
|
|
|
6
6
|
lines.push(`import type { StoryModule } from "@takazudo/zudo-sg/stories";`);
|
|
7
7
|
lines.push(``);
|
|
8
8
|
for (const e of entries) {
|
|
9
|
-
lines.push(`import * as ${e.importName} from
|
|
9
|
+
lines.push(`import * as ${e.importName} from ${JSON.stringify(e.importSpecifier)};`);
|
|
10
10
|
}
|
|
11
11
|
lines.push(``);
|
|
12
12
|
lines.push(`/**`);
|
|
@@ -16,7 +16,7 @@ function buildRegistryBlock(entries) {
|
|
|
16
16
|
lines.push(` */`);
|
|
17
17
|
lines.push(`export const storyModules: Record<string, StoryModule> = {`);
|
|
18
18
|
for (const e of entries) {
|
|
19
|
-
lines.push(`
|
|
19
|
+
lines.push(` ${JSON.stringify(e.mapKey)}: ${e.importName} as unknown as StoryModule,`);
|
|
20
20
|
}
|
|
21
21
|
lines.push(`};`);
|
|
22
22
|
lines.push(``);
|
|
@@ -33,7 +33,7 @@ function buildRegistryBlock(entries) {
|
|
|
33
33
|
lines.push(`export const storyExportOrder: Record<string, string[]> = {`);
|
|
34
34
|
for (const e of entries) {
|
|
35
35
|
const arr = e.exportOrder.map((n) => JSON.stringify(n)).join(", ");
|
|
36
|
-
lines.push(`
|
|
36
|
+
lines.push(` ${JSON.stringify(e.mapKey)}: [${arr}],`);
|
|
37
37
|
}
|
|
38
38
|
lines.push(`};`);
|
|
39
39
|
lines.push(`// ${END_MARKER}`);
|
|
@@ -43,12 +43,12 @@ function buildStoryModulesBlock(entries, relativeImportPrefix) {
|
|
|
43
43
|
const lines = [];
|
|
44
44
|
lines.push(`// ${BEGIN_MARKER} \u2014 do not hand-edit; run \`zudo-sg gen-registry\`.`);
|
|
45
45
|
for (const e of entries) {
|
|
46
|
-
lines.push(`import * as ${e.importName} from
|
|
46
|
+
lines.push(`import * as ${e.importName} from ${JSON.stringify(`${relativeImportPrefix}/${e.relDirStem}.stories`)};`);
|
|
47
47
|
}
|
|
48
48
|
lines.push(``);
|
|
49
49
|
lines.push(`export const STORY_MODULES: Record<string, StoryModule> = {`);
|
|
50
50
|
for (const e of entries) {
|
|
51
|
-
lines.push(`
|
|
51
|
+
lines.push(` ${JSON.stringify(`${e.relDirStem}.stories.tsx`)}: ${e.importName} as unknown as StoryModule,`);
|
|
52
52
|
}
|
|
53
53
|
lines.push(`};`);
|
|
54
54
|
lines.push(`// ${END_MARKER}`);
|
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
export interface DiscoveredStory {
|
|
2
2
|
/** Path stem relative to the components root, e.g. "badge/badge" or "layout/badge-icon/badge-icon". */
|
|
3
3
|
relDirStem: string;
|
|
4
|
-
/**
|
|
4
|
+
/** Preferred import binding; the combined registry allocates a unique final name. */
|
|
5
5
|
importName: string;
|
|
6
6
|
/** Named-export declaration order of the story file, in source order. */
|
|
7
7
|
exportOrder: string[];
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
|
-
* Derive the `import * as <name>` identifier from a story's containing
|
|
10
|
+
* Derive the preferred `import * as <name>` identifier from a story's containing
|
|
11
11
|
* directory path (relative to the components root) — never from the file
|
|
12
12
|
* stem alone. A 1-segment `relDir` (old flat layout) is byte-identical to
|
|
13
13
|
* the previous `camelCase(stem)` derivation; a multi-segment `relDir`
|
|
14
|
-
* (category-nested layout) folds the whole path into one identifier
|
|
15
|
-
* categories scaffolding a same-named component get distinct identifiers.
|
|
14
|
+
* (category-nested layout) folds the whole path into one identifier.
|
|
16
15
|
*/
|
|
17
16
|
export declare function dirPathToImportName(relDir: string): string;
|
|
18
17
|
/**
|
|
@@ -22,12 +21,6 @@ export declare function dirPathToImportName(relDir: string): string;
|
|
|
22
21
|
* captured here at discovery time.
|
|
23
22
|
*/
|
|
24
23
|
export declare function scanExportOrder(body: string): string[];
|
|
25
|
-
/**
|
|
26
|
-
* Throws if two entries derive the same `importName` — a duplicate
|
|
27
|
-
* `import * as X` is a syntax error; this surfaces it as a clear
|
|
28
|
-
* discovery-time message naming the two colliding directories.
|
|
29
|
-
*/
|
|
30
|
-
export declare function assertUniqueImportNames(entries: DiscoveredStory[]): void;
|
|
31
24
|
/**
|
|
32
25
|
* Glob `<absRoot>/**\/*.stories.tsx` off the filesystem (any depth) and
|
|
33
26
|
* derive each entry's `relDirStem`, `importName`, and `exportOrder`.
|
|
@@ -22,18 +22,6 @@ function dirPathToImportName(relDir) {
|
|
|
22
22
|
function scanExportOrder(body) {
|
|
23
23
|
return [...body.matchAll(/^export const (\w+)/gm)].map((m) => m[1]);
|
|
24
24
|
}
|
|
25
|
-
function assertUniqueImportNames(entries) {
|
|
26
|
-
const seen = /* @__PURE__ */ new Map();
|
|
27
|
-
for (const entry of entries) {
|
|
28
|
-
const prior = seen.get(entry.importName);
|
|
29
|
-
if (prior !== void 0) {
|
|
30
|
-
throw new Error(
|
|
31
|
-
`gen-registry: "${prior}" and "${entry.relDirStem}" both derive the import identifier "${entry.importName}" \u2014 rename one of the component directories so their derived identifiers don't collide.`
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
seen.set(entry.importName, entry.relDirStem);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
25
|
function discoverStories(absRoot) {
|
|
38
26
|
const found = walkStoryFiles(absRoot, "");
|
|
39
27
|
const entries = found.map(({ relDir, file }) => {
|
|
@@ -50,11 +38,9 @@ function discoverStories(absRoot) {
|
|
|
50
38
|
throw new Error(`No *${STORIES_SUFFIX} files found under ${absRoot}`);
|
|
51
39
|
}
|
|
52
40
|
entries.sort((a, b) => a.relDirStem.localeCompare(b.relDirStem));
|
|
53
|
-
assertUniqueImportNames(entries);
|
|
54
41
|
return entries;
|
|
55
42
|
}
|
|
56
43
|
export {
|
|
57
|
-
assertUniqueImportNames,
|
|
58
44
|
dirPathToImportName,
|
|
59
45
|
discoverStories,
|
|
60
46
|
scanExportOrder
|
|
@@ -6,7 +6,8 @@ import {
|
|
|
6
6
|
replaceBlock
|
|
7
7
|
} from "./build-registry-source.js";
|
|
8
8
|
import { deriveMapKeyPrefix } from "../../registry/component-docs.js";
|
|
9
|
-
import {
|
|
9
|
+
import { discoverStories } from "./discover-stories.js";
|
|
10
|
+
import { allocateImportNames } from "./allocate-import-names.js";
|
|
10
11
|
const STORY_MODULES_RELATIVE_PATH = "stories/__tests__/story-modules.ts";
|
|
11
12
|
function buildEntriesForRoot(projectRoot, root) {
|
|
12
13
|
const absDir = resolve(projectRoot, root.dir);
|
|
@@ -22,8 +23,8 @@ function runGenRegistry(projectRoot, config, options = {}) {
|
|
|
22
23
|
root,
|
|
23
24
|
entries: buildEntriesForRoot(projectRoot, root)
|
|
24
25
|
}));
|
|
25
|
-
const allEntries = perRootEntries.flatMap((r) => r.entries)
|
|
26
|
-
|
|
26
|
+
const allEntries = allocateImportNames(perRootEntries.flatMap((r) => r.entries));
|
|
27
|
+
const allocatedByKey = new Map(allEntries.map((entry) => [entry.mapKey, entry]));
|
|
27
28
|
const registryPath = resolve(projectRoot, config.registryOut);
|
|
28
29
|
let registrySrc = "";
|
|
29
30
|
let bootstrapRegistry = false;
|
|
@@ -47,7 +48,7 @@ function runGenRegistry(projectRoot, config, options = {}) {
|
|
|
47
48
|
const before = readFileSync(storyModulesPath, "utf8");
|
|
48
49
|
const after = replaceBlock(
|
|
49
50
|
before,
|
|
50
|
-
buildStoryModulesBlock(entries, relativeImportPrefix),
|
|
51
|
+
buildStoryModulesBlock(entries.map((entry) => allocatedByKey.get(entry.mapKey)), relativeImportPrefix),
|
|
51
52
|
storyModulesPath
|
|
52
53
|
);
|
|
53
54
|
targets.push({ path: storyModulesPath, before, after });
|
|
@@ -25,10 +25,10 @@ export interface ComponentTemplateArgs {
|
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
27
27
|
* `<componentsRoot>/<name>/<name>.tsx` — typed-props skeleton following the
|
|
28
|
-
* house pattern. `nested`
|
|
29
|
-
*
|
|
28
|
+
* house pattern. `nested` is accepted for symmetry with the story template;
|
|
29
|
+
* the component source has no host-local imports to adjust by layout.
|
|
30
30
|
*/
|
|
31
|
-
export declare function componentTemplate({ pascalName
|
|
31
|
+
export declare function componentTemplate({ pascalName }: ComponentTemplateArgs): string;
|
|
32
32
|
export interface StoriesTemplateArgs {
|
|
33
33
|
pascalName: string;
|
|
34
34
|
kebabName: string;
|
|
@@ -40,7 +40,7 @@ export interface StoriesTemplateArgs {
|
|
|
40
40
|
* `<componentsRoot>/<name>/<name>.stories.tsx` — StoryMeta + a Playground
|
|
41
41
|
* variant in the typed `Story<Props>` shape.
|
|
42
42
|
*/
|
|
43
|
-
export declare function storiesTemplate({ pascalName, kebabName, category, uiPackageName,
|
|
43
|
+
export declare function storiesTemplate({ pascalName, kebabName, category, uiPackageName, }: StoriesTemplateArgs): string;
|
|
44
44
|
export interface TestTemplateArgs {
|
|
45
45
|
pascalName: string;
|
|
46
46
|
kebabName: string;
|
|
@@ -27,10 +27,9 @@ function assertUnusedName(name, existingNames, componentsRootLabel) {
|
|
|
27
27
|
function toPascalCase(kebabName) {
|
|
28
28
|
return kebabName.split("-").map((segment) => segment.charAt(0).toUpperCase() + segment.slice(1)).join("");
|
|
29
29
|
}
|
|
30
|
-
function componentTemplate({ pascalName
|
|
30
|
+
function componentTemplate({ pascalName }) {
|
|
31
31
|
const lines = [
|
|
32
32
|
`import type { ComponentChildren } from "preact";`,
|
|
33
|
-
`import { cx } from "${nested ? "../../lib/cx" : "../lib/cx"}";`,
|
|
34
33
|
``,
|
|
35
34
|
`export type ${pascalName}Variant = "primary" | "secondary";`,
|
|
36
35
|
``,
|
|
@@ -55,7 +54,8 @@ function componentTemplate({ pascalName, nested = false }) {
|
|
|
55
54
|
` * TODO: describe ${pascalName} \u2014 what it renders and when to use it.`,
|
|
56
55
|
` */`,
|
|
57
56
|
`export function ${pascalName}({ variant = "primary", class: cls, children }: ${pascalName}Props) {`,
|
|
58
|
-
`
|
|
57
|
+
` const className = [base, variants[variant], cls].filter(Boolean).join(" ");`,
|
|
58
|
+
` return <div class={className}>{children}</div>;`,
|
|
59
59
|
`}`
|
|
60
60
|
];
|
|
61
61
|
return lines.join("\n") + "\n";
|
|
@@ -64,12 +64,11 @@ function storiesTemplate({
|
|
|
64
64
|
pascalName,
|
|
65
65
|
kebabName,
|
|
66
66
|
category,
|
|
67
|
-
uiPackageName
|
|
68
|
-
nested = false
|
|
67
|
+
uiPackageName
|
|
69
68
|
}) {
|
|
70
69
|
const usageImport = uiPackageName ?? `./${kebabName}`;
|
|
71
70
|
const lines = [
|
|
72
|
-
`import type { StoryMeta, Story } from "
|
|
71
|
+
`import type { StoryMeta, Story } from "@takazudo/zudo-sg/stories";`,
|
|
73
72
|
`import { ${pascalName}, type ${pascalName}Props } from "./${kebabName}";`,
|
|
74
73
|
``,
|
|
75
74
|
`const meta: StoryMeta = {`,
|
|
@@ -24,7 +24,7 @@ function runGenTokenManifest(projectRoot, config, options = {}) {
|
|
|
24
24
|
const [tokensCssPath, colorsCssPath] = tokens.cssFiles;
|
|
25
25
|
const tokensCss = readFileSync(resolve(projectRoot, tokensCssPath), "utf8");
|
|
26
26
|
const colorsCss = readFileSync(resolve(projectRoot, colorsCssPath), "utf8");
|
|
27
|
-
const manifest = buildUiTokenManifest({ tokensCss, colorsCss });
|
|
27
|
+
const manifest = buildUiTokenManifest({ tokensCss, colorsCss, spec: tokens.spec });
|
|
28
28
|
const next = renderUiTokenManifestFile(manifest, { tokensCssPath, colorsCssPath });
|
|
29
29
|
const tokenCount = manifest.paletteColors.length + manifest.colorTokens.length + manifest.spacingTokens.length + manifest.fontTokens.length + manifest.sizeTokens.length;
|
|
30
30
|
const manifestPath = resolve(projectRoot, tokens.manifestOut);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { GeneratedTokenGroups, HostTokensSpec } from "../../token-spec.js";
|
|
1
2
|
export interface TokenSpec {
|
|
2
3
|
cssVar: string;
|
|
3
4
|
group: string;
|
|
@@ -26,10 +27,20 @@ export interface BuiltToken {
|
|
|
26
27
|
customDefault: string;
|
|
27
28
|
};
|
|
28
29
|
note?: string;
|
|
30
|
+
units?: string[];
|
|
31
|
+
readonly?: boolean;
|
|
32
|
+
valueKind?: "number";
|
|
29
33
|
}
|
|
30
34
|
export interface PaletteEntry {
|
|
31
35
|
name: string;
|
|
32
36
|
value: string;
|
|
37
|
+
/** Present for host specs, where names need not start with `--palette-`. */
|
|
38
|
+
cssVar?: string;
|
|
39
|
+
id?: string;
|
|
40
|
+
label?: string;
|
|
41
|
+
group?: string;
|
|
42
|
+
readonly?: boolean;
|
|
43
|
+
note?: string;
|
|
33
44
|
}
|
|
34
45
|
/**
|
|
35
46
|
* Tier-1 raw palette — every `--palette-*` in the colors CSS file's `:root`
|
|
@@ -63,6 +74,8 @@ export interface UiTokenManifest {
|
|
|
63
74
|
spacingTokens: BuiltToken[];
|
|
64
75
|
fontTokens: BuiltToken[];
|
|
65
76
|
sizeTokens: BuiltToken[];
|
|
77
|
+
/** Present only for a supplied host spec. */
|
|
78
|
+
groups?: GeneratedTokenGroups;
|
|
66
79
|
}
|
|
67
80
|
export interface TokenManifestProvenance {
|
|
68
81
|
/** Project-root-relative path configured for spacing/font/size tokens. */
|
|
@@ -76,9 +89,10 @@ export interface TokenManifestProvenance {
|
|
|
76
89
|
* shape as the arrays exported by the generated manifest, minus the TS
|
|
77
90
|
* syntax.
|
|
78
91
|
*/
|
|
79
|
-
export declare function buildUiTokenManifest({ tokensCss, colorsCss }: {
|
|
92
|
+
export declare function buildUiTokenManifest({ tokensCss, colorsCss, spec }: {
|
|
80
93
|
tokensCss: string;
|
|
81
94
|
colorsCss: string;
|
|
95
|
+
spec?: HostTokensSpec;
|
|
82
96
|
}): UiTokenManifest;
|
|
83
97
|
/** Render the full generated manifest `.ts` source. */
|
|
84
98
|
export declare function renderUiTokenManifestFile(manifest: UiTokenManifest, provenance: TokenManifestProvenance): string;
|
|
@@ -181,9 +181,141 @@ function buildFromSpecs(specs, tokenVars, sourceLabel) {
|
|
|
181
181
|
...pill ? { pill } : {}
|
|
182
182
|
}));
|
|
183
183
|
}
|
|
184
|
-
|
|
184
|
+
const CATEGORIES = ["palette", "color", "spacing", "font", "size"];
|
|
185
|
+
const PREVIEWS = ["size", "line-height", "family", "weight", "bar", "radius", "duration"];
|
|
186
|
+
const CONTROLS = ["slider", "text", "select"];
|
|
187
|
+
const CSS_VAR_RE = /^--[A-Za-z0-9_\u{80}-\u{10FFFF}][A-Za-z0-9_\u{80}-\u{10FFFF}-]*$/u;
|
|
188
|
+
const ID_RE = /^[A-Za-z][A-Za-z0-9_-]*$/;
|
|
189
|
+
function specError(path, detail) {
|
|
190
|
+
throw new Error(`[zudo-sg] tokens.spec${path ? `.${path}` : ""}: ${detail}`);
|
|
191
|
+
}
|
|
192
|
+
function record(value) {
|
|
193
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
194
|
+
}
|
|
195
|
+
function nonempty(value, path) {
|
|
196
|
+
if (typeof value !== "string" || !value.trim()) specError(path, "expected a non-empty string");
|
|
197
|
+
return value;
|
|
198
|
+
}
|
|
199
|
+
function optionalString(value, path) {
|
|
200
|
+
if (value !== void 0 && typeof value !== "string") specError(path, "expected a string");
|
|
201
|
+
}
|
|
202
|
+
function validateToken(token, path, category) {
|
|
203
|
+
if (!record(token)) specError(path, "expected a token object");
|
|
204
|
+
const fields = ["cssVar", "id", "label", "control", "valueKind", "step", "unit", "units", "options", "readonly", "pill", "note"];
|
|
205
|
+
for (const key of Object.keys(token)) if (!fields.includes(key)) specError(`${path}.${key}`, "unknown token field");
|
|
206
|
+
const cssVar = nonempty(token.cssVar, `${path}.cssVar`);
|
|
207
|
+
if (!CSS_VAR_RE.test(cssVar)) specError(`${path}.cssVar`, `invalid CSS custom property ${JSON.stringify(cssVar)}`);
|
|
208
|
+
if (token.id !== void 0 && !ID_RE.test(nonempty(token.id, `${path}.id`))) specError(`${path}.id`, "expected an id starting with a letter, followed by letters, numbers, '_' or '-'");
|
|
209
|
+
if (token.label !== void 0) nonempty(token.label, `${path}.label`);
|
|
210
|
+
if (token.control !== void 0 && !CONTROLS.includes(token.control)) specError(`${path}.control`, `unsupported control ${JSON.stringify(token.control)}`);
|
|
211
|
+
if (token.valueKind !== void 0 && token.valueKind !== "number") specError(`${path}.valueKind`, "only 'number' is supported");
|
|
212
|
+
if (token.valueKind === "number" && (token.control === "text" || token.control === "select" || token.unit !== void 0 && (typeof token.unit !== "string" || !["", "ms", "s"].includes(token.unit)))) specError(`${path}.valueKind`, "number requires a slider token with no unit or a duration unit (ms/s)");
|
|
213
|
+
if (category === "color" && token.valueKind === "number" && token.control !== "slider") specError(`${path}.valueKind`, "color tokens default to text; set control: 'slider' for a number row");
|
|
214
|
+
if (category === "palette" && token.control !== void 0) specError(`${path}.control`, "palette colors use the color editor; omit control");
|
|
215
|
+
if (category === "palette" && ["step", "unit", "units", "options", "pill", "valueKind"].some((key) => token[key] !== void 0)) specError(path, "palette colors accept only cssVar, id, label, readonly and note");
|
|
216
|
+
if (token.step !== void 0 && (typeof token.step !== "number" || !Number.isFinite(token.step) || token.step <= 0)) specError(`${path}.step`, "expected a positive finite number");
|
|
217
|
+
for (const key of ["unit", "note"]) optionalString(token[key], `${path}.${key}`);
|
|
218
|
+
if (token.readonly !== void 0 && typeof token.readonly !== "boolean") specError(`${path}.readonly`, "expected a boolean");
|
|
219
|
+
if (token.options !== void 0) {
|
|
220
|
+
if (!Array.isArray(token.options) || token.options.length === 0 || token.options.some((o) => typeof o !== "string" || !o.trim()) || new Set(token.options).size !== token.options.length) specError(`${path}.options`, "expected unique, non-empty string options");
|
|
221
|
+
if (token.control !== "select") specError(`${path}.options`, "options require control: 'select'");
|
|
222
|
+
}
|
|
223
|
+
if (token.control === "select" && token.options === void 0) specError(`${path}.options`, "select requires options");
|
|
224
|
+
if (token.units !== void 0) {
|
|
225
|
+
if (!Array.isArray(token.units) || token.units.length === 0 || token.units.some((u) => typeof u !== "string") || new Set(token.units).size !== token.units.length) specError(`${path}.units`, "expected unique string units");
|
|
226
|
+
if (token.control !== "slider" && token.control !== void 0) specError(`${path}.units`, "units require a slider control");
|
|
227
|
+
if (token.valueKind === "number") specError(`${path}.units`, "number rows cannot have units");
|
|
228
|
+
if (token.unit === void 0) specError(`${path}.unit`, "unit is required when units are listed");
|
|
229
|
+
if (token.unit !== void 0 && !token.units.includes(token.unit)) specError(`${path}.unit`, "unit must appear in units");
|
|
230
|
+
}
|
|
231
|
+
if (token.pill !== void 0) {
|
|
232
|
+
if (token.control === "text" || token.control === "select" || category === "color" && token.control !== "slider") specError(`${path}.pill`, "pill requires a slider control");
|
|
233
|
+
if (!record(token.pill)) specError(`${path}.pill`, "expected { value, customDefault }");
|
|
234
|
+
nonempty(token.pill.value, `${path}.pill.value`);
|
|
235
|
+
nonempty(token.pill.customDefault, `${path}.pill.customDefault`);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
function buildHostManifest(spec, tokenVars, colorVars) {
|
|
239
|
+
if (!record(spec)) specError("", "expected an object of category group arrays");
|
|
240
|
+
for (const key of Object.keys(spec)) if (!CATEGORIES.includes(key)) specError(key, "unknown category");
|
|
241
|
+
const groups = { palette: [], color: [], spacing: [], font: [], size: [] };
|
|
242
|
+
const result = { paletteColors: [], colorTokens: [], spacingTokens: [], fontTokens: [], sizeTokens: [], groups };
|
|
243
|
+
const usedIds = /* @__PURE__ */ new Map();
|
|
244
|
+
const usedVars = /* @__PURE__ */ new Map();
|
|
245
|
+
for (const category of CATEGORIES) {
|
|
246
|
+
const entries = spec[category] === void 0 ? [] : spec[category];
|
|
247
|
+
if (!Array.isArray(entries)) specError(category, "expected an ordered array of groups");
|
|
248
|
+
const groupIds = /* @__PURE__ */ new Set();
|
|
249
|
+
entries.forEach((group, groupIndex) => {
|
|
250
|
+
const path = `${category}[${groupIndex}]`;
|
|
251
|
+
if (!record(group)) specError(path, "expected a group object");
|
|
252
|
+
for (const key of Object.keys(group)) if (!["id", "label", "tokens", "preview", "previewBase"].includes(key)) specError(`${path}.${key}`, "unknown group field");
|
|
253
|
+
const groupId = nonempty(group.id, `${path}.id`);
|
|
254
|
+
if (!ID_RE.test(groupId)) specError(`${path}.id`, "invalid group id");
|
|
255
|
+
if (groupIds.has(groupId)) specError(`${path}.id`, `duplicate group id ${JSON.stringify(groupId)}`);
|
|
256
|
+
groupIds.add(groupId);
|
|
257
|
+
const label = nonempty(group.label, `${path}.label`);
|
|
258
|
+
if (!Array.isArray(group.tokens)) specError(`${path}.tokens`, "expected an ordered array of tokens");
|
|
259
|
+
if (group.preview !== void 0 && !PREVIEWS.includes(group.preview)) specError(`${path}.preview`, `unsupported preview ${JSON.stringify(group.preview)}`);
|
|
260
|
+
if (group.previewBase !== void 0) {
|
|
261
|
+
if (group.preview !== "line-height") specError(`${path}.previewBase`, "previewBase requires preview: 'line-height'");
|
|
262
|
+
if (typeof group.previewBase !== "string" || !CSS_VAR_RE.test(group.previewBase)) specError(`${path}.previewBase`, "expected a CSS custom property");
|
|
263
|
+
if (!tokenVars.has(group.previewBase) && !colorVars.has(group.previewBase)) specError(`${path}.previewBase`, `${group.previewBase} was not found in either configured CSS file`);
|
|
264
|
+
}
|
|
265
|
+
groups[category].push({ id: groupId, label, ...group.preview ? { preview: group.preview } : {}, ...group.previewBase ? { previewBase: group.previewBase } : {} });
|
|
266
|
+
const kinds = /* @__PURE__ */ new Set();
|
|
267
|
+
group.tokens.forEach((rawToken, tokenIndex) => {
|
|
268
|
+
const tokenPath = `${path}.tokens[${tokenIndex}]`;
|
|
269
|
+
validateToken(rawToken, tokenPath, category);
|
|
270
|
+
const control = rawToken.control ?? (category === "color" ? "text" : "slider");
|
|
271
|
+
const kind = category === "palette" ? "color" : control === "select" ? "select" : control === "text" ? "text" : rawToken.valueKind === "number" || group.preview === "line-height" || group.preview === "weight" && (rawToken.unit ?? "") === "" ? "number" : "length";
|
|
272
|
+
kinds.add(kind);
|
|
273
|
+
if (kinds.size > 1) specError(`${path}.tokens`, "a group must use one value kind for all rows");
|
|
274
|
+
const allowed = { size: ["length"], "line-height": ["number"], family: ["text"], weight: ["select", "number"], bar: ["length"], radius: ["length"], duration: ["length", "number"] };
|
|
275
|
+
if (group.preview && !allowed[group.preview].includes(kind)) specError(`${path}.preview`, `${group.preview} does not support ${kind} rows`);
|
|
276
|
+
if ((group.preview === "line-height" || group.preview === "weight") && kind === "number" && ((rawToken.unit ?? "") !== "" || rawToken.units !== void 0)) specError(`${path}.preview`, `${group.preview} requires unitless number tokens`);
|
|
277
|
+
if (group.preview === "duration" && !["ms", "s"].includes(rawToken.unit ?? "")) specError(`${path}.preview`, "duration requires ms or s units");
|
|
278
|
+
const cssVar = rawToken.cssVar;
|
|
279
|
+
const id = rawToken.id ?? idOf(cssVar);
|
|
280
|
+
const oldVar = usedVars.get(cssVar);
|
|
281
|
+
if (oldVar) specError(`${tokenPath}.cssVar`, `${cssVar} is already used by ${oldVar}`);
|
|
282
|
+
const oldId = usedIds.get(id);
|
|
283
|
+
if (oldId) specError(`${tokenPath}.id`, `${id} collides with ${oldId}; set a distinct id`);
|
|
284
|
+
usedIds.set(id, tokenPath);
|
|
285
|
+
usedVars.set(cssVar, tokenPath);
|
|
286
|
+
const sourceVars = category === "palette" || category === "color" ? colorVars : tokenVars;
|
|
287
|
+
if (!sourceVars.has(cssVar)) specError(`${tokenPath}.cssVar`, `${cssVar} was not found in the configured ${category === "palette" || category === "color" ? "colors" : "tokens"} CSS file`);
|
|
288
|
+
const value = sourceVars.get(cssVar);
|
|
289
|
+
if (category === "palette") {
|
|
290
|
+
result.paletteColors.push({ name: cssVar.slice(2), cssVar, id, label: rawToken.label ?? labelOf(cssVar), group: groupId, value, ...rawToken.readonly ? { readonly: true } : {}, ...rawToken.note ? { note: rawToken.note } : {} });
|
|
291
|
+
} else {
|
|
292
|
+
const built = {
|
|
293
|
+
id,
|
|
294
|
+
cssVar,
|
|
295
|
+
label: rawToken.label ?? labelOf(cssVar),
|
|
296
|
+
group: groupId,
|
|
297
|
+
default: value,
|
|
298
|
+
step: rawToken.step ?? 1,
|
|
299
|
+
unit: rawToken.unit ?? "",
|
|
300
|
+
...rawToken.control || category === "color" ? { control } : {},
|
|
301
|
+
...rawToken.units ? { units: rawToken.units } : {},
|
|
302
|
+
...rawToken.options ? { options: rawToken.options } : {},
|
|
303
|
+
...rawToken.pill ? { pill: rawToken.pill } : {},
|
|
304
|
+
...rawToken.note ? { note: rawToken.note } : {},
|
|
305
|
+
...kind === "number" ? { valueKind: "number" } : {},
|
|
306
|
+
...rawToken.readonly ? { readonly: true } : {}
|
|
307
|
+
};
|
|
308
|
+
result[`${category}Tokens`].push(built);
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
return result;
|
|
314
|
+
}
|
|
315
|
+
function buildUiTokenManifest({ tokensCss, colorsCss, spec }) {
|
|
185
316
|
const tokenVars = parseCssCustomProperties(tokensCss);
|
|
186
317
|
const colorVars = parseCssCustomProperties(colorsCss);
|
|
318
|
+
if (spec !== void 0) return buildHostManifest(spec, tokenVars, colorVars);
|
|
187
319
|
return {
|
|
188
320
|
paletteColors: buildPaletteColors(colorVars),
|
|
189
321
|
colorTokens: buildColorTokens(colorVars),
|
|
@@ -198,7 +330,7 @@ function jsStringLiteral(value) {
|
|
|
198
330
|
function normalizeProvenancePath(path) {
|
|
199
331
|
return path.replace(/\\/g, "/").replace(/^\.\//, "");
|
|
200
332
|
}
|
|
201
|
-
function renderTokenDefObject(token, indent) {
|
|
333
|
+
function renderTokenDefObject(token, indent, custom = false) {
|
|
202
334
|
const pad = " ".repeat(indent);
|
|
203
335
|
const fields = [
|
|
204
336
|
`id: ${jsStringLiteral(token.id)}`,
|
|
@@ -211,33 +343,39 @@ function renderTokenDefObject(token, indent) {
|
|
|
211
343
|
];
|
|
212
344
|
if (token.control) fields.push(`control: ${jsStringLiteral(token.control)}`);
|
|
213
345
|
if (token.options) {
|
|
214
|
-
fields.push(`options: FONT_WEIGHT_OPTIONS`);
|
|
346
|
+
fields.push(custom ? `options: ${JSON.stringify(token.options)}` : `options: FONT_WEIGHT_OPTIONS`);
|
|
215
347
|
}
|
|
348
|
+
if (custom && token.units) fields.push(`units: ${JSON.stringify(token.units)}`);
|
|
349
|
+
if (custom && token.readonly) fields.push("readonly: true");
|
|
350
|
+
if (custom && token.valueKind) fields.push(`valueKind: ${jsStringLiteral(token.valueKind)}`);
|
|
351
|
+
if (custom && token.note) fields.push(`note: ${jsStringLiteral(token.note)}`);
|
|
216
352
|
if (token.pill) {
|
|
217
353
|
fields.push(
|
|
218
354
|
`pill: { value: ${jsStringLiteral(token.pill.value)}, customDefault: ${jsStringLiteral(token.pill.customDefault)} }`
|
|
219
355
|
);
|
|
220
356
|
}
|
|
221
357
|
const body = fields.map((f) => `${pad} ${f},`).join("\n");
|
|
222
|
-
const note = token.note ? `${pad}// ${token.note}
|
|
358
|
+
const note = !custom && token.note ? `${pad}// ${token.note}
|
|
223
359
|
` : "";
|
|
224
360
|
return `${note}${pad}{
|
|
225
361
|
${body}
|
|
226
362
|
${pad}},`;
|
|
227
363
|
}
|
|
228
|
-
function renderPaletteEntry(entry) {
|
|
364
|
+
function renderPaletteEntry(entry, custom = false) {
|
|
365
|
+
if (custom) return ` ${JSON.stringify(entry)},`;
|
|
229
366
|
return ` { name: ${jsStringLiteral(entry.name)}, value: ${jsStringLiteral(entry.value)} },`;
|
|
230
367
|
}
|
|
231
368
|
function renderUiTokenManifestFile(manifest, provenance) {
|
|
232
369
|
const tokensCssPath = normalizeProvenancePath(provenance.tokensCssPath);
|
|
233
370
|
const colorsCssPath = normalizeProvenancePath(provenance.colorsCssPath);
|
|
234
371
|
const sourceOfTruth = tokensCssPath === colorsCssPath ? `\`${tokensCssPath}\`` : `\`${tokensCssPath}\` and \`${colorsCssPath}\``;
|
|
235
|
-
const
|
|
236
|
-
const
|
|
237
|
-
const
|
|
238
|
-
const
|
|
239
|
-
const
|
|
240
|
-
|
|
372
|
+
const custom = manifest.groups !== void 0;
|
|
373
|
+
const paletteLines = manifest.paletteColors.map((entry) => renderPaletteEntry(entry, custom)).join("\n");
|
|
374
|
+
const colorLines = manifest.colorTokens.map((t) => renderTokenDefObject(t, 2, custom)).join("\n");
|
|
375
|
+
const spacingLines = manifest.spacingTokens.map((t) => renderTokenDefObject(t, 2, custom)).join("\n");
|
|
376
|
+
const fontLines = manifest.fontTokens.map((t) => renderTokenDefObject(t, 2, custom)).join("\n");
|
|
377
|
+
const sizeLines = manifest.sizeTokens.map((t) => renderTokenDefObject(t, 2, custom)).join("\n");
|
|
378
|
+
const rendered = `/**
|
|
241
379
|
* Design-token manifest for configured UI tokens.
|
|
242
380
|
*
|
|
243
381
|
* GENERATED \u2014 do not hand-edit. Run \`zudo-sg gen-token-manifest\` after changing
|
|
@@ -329,6 +467,54 @@ ${fontLines}
|
|
|
329
467
|
export const UI_SIZE_TOKENS: readonly TokenDef[] = [
|
|
330
468
|
${sizeLines}
|
|
331
469
|
];
|
|
470
|
+
`;
|
|
471
|
+
if (!custom) return rendered;
|
|
472
|
+
return `/**
|
|
473
|
+
* Design-token manifest generated by \`zudo-sg gen-token-manifest\`.
|
|
474
|
+
* Run \`zudo-sg gen-token-manifest --check\` to detect drift.
|
|
475
|
+
* CSS declarations in ${sourceOfTruth} supply default values.
|
|
476
|
+
* Host \`tokens.spec\` supplies ordered groups and presentation metadata.
|
|
477
|
+
*/
|
|
478
|
+
import type { TokenDef } from "@takazudo/zdtp";
|
|
479
|
+
import type { GeneratedTokenGroups } from "@takazudo/zudo-sg/config";
|
|
480
|
+
|
|
481
|
+
/** Number rows are a portable tier-model extension of zdtp's TokenDef. */
|
|
482
|
+
export type HostGeneratedToken = TokenDef & { valueKind?: "number"; note?: string };
|
|
483
|
+
|
|
484
|
+
/** Palette entries preserve explicit host CSS names and group identity. */
|
|
485
|
+
export interface UiPaletteColor {
|
|
486
|
+
name: string;
|
|
487
|
+
value: string;
|
|
488
|
+
cssVar: string;
|
|
489
|
+
id: string;
|
|
490
|
+
label: string;
|
|
491
|
+
group: string;
|
|
492
|
+
readonly?: boolean;
|
|
493
|
+
note?: string;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
export const UI_PALETTE_COLORS: readonly UiPaletteColor[] = [
|
|
497
|
+
${paletteLines}
|
|
498
|
+
];
|
|
499
|
+
|
|
500
|
+
export const UI_COLOR_TOKENS: readonly HostGeneratedToken[] = [
|
|
501
|
+
${colorLines}
|
|
502
|
+
];
|
|
503
|
+
|
|
504
|
+
export const UI_SPACING_TOKENS: readonly HostGeneratedToken[] = [
|
|
505
|
+
${spacingLines}
|
|
506
|
+
];
|
|
507
|
+
|
|
508
|
+
export const UI_FONT_TOKENS: readonly HostGeneratedToken[] = [
|
|
509
|
+
${fontLines}
|
|
510
|
+
];
|
|
511
|
+
|
|
512
|
+
export const UI_SIZE_TOKENS: readonly HostGeneratedToken[] = [
|
|
513
|
+
${sizeLines}
|
|
514
|
+
];
|
|
515
|
+
|
|
516
|
+
/** Ordered groups for all five categories; omitted categories are empty. */
|
|
517
|
+
export const UI_TOKEN_GROUPS: GeneratedTokenGroups = ${JSON.stringify(manifest.groups, null, 2)};
|
|
332
518
|
`;
|
|
333
519
|
}
|
|
334
520
|
export {
|
package/dist/config/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { componentDocsCollectionName } from "../registry/component-docs.js";
|
|
2
2
|
import { type SgRoutes } from "../sg-routes.js";
|
|
3
|
+
import type { HostTokensSpec } from "../token-spec.js";
|
|
4
|
+
export type { HostTokensSpec, HostTokenGroupSpec, HostTokenSpec, TokenPreview, TokenControl, GeneratedTokenGroups, GeneratedTokenGroup } from "../token-spec.js";
|
|
3
5
|
export declare const ROUTES_PLUGIN_NAME = "@takazudo/zudo-sg/plugins/routes";
|
|
4
6
|
export declare const PREVIEW_CSS_PLUGIN_NAME = "@takazudo/zudo-sg/plugins/preview-css";
|
|
5
7
|
export declare const ZDTP_APPLY_PROXY_PLUGIN_NAME = "@takazudo/zudo-sg/plugins/zdtp-apply-proxy";
|
|
@@ -44,18 +46,32 @@ export interface ZudoSgComposeOptions {
|
|
|
44
46
|
tokens?: {
|
|
45
47
|
manifestOut?: string;
|
|
46
48
|
cssFiles?: readonly string[];
|
|
49
|
+
spec?: HostTokensSpec;
|
|
47
50
|
};
|
|
48
51
|
/**
|
|
49
52
|
* `@takazudo/zudo-sg/plugins/zdtp-apply-proxy` options
|
|
50
53
|
* (`{ routingFile, writeRoot, tabsModule? }`). Omitted → the plugin is still
|
|
51
54
|
* listed (the engine's preview token panel island imports its virtual
|
|
52
|
-
* module) but runs disabled: no tabs, no Apply endpoint.
|
|
55
|
+
* module) but runs disabled: no tabs, no Apply endpoint. `routingFile` and
|
|
56
|
+
* `writeRoot` are optional TOGETHER — `{ tabsModule }` alone is valid (tabs
|
|
57
|
+
* without the dev-only Apply write sandbox); exactly one of the two is not.
|
|
53
58
|
*/
|
|
54
59
|
zdtpApplyProxy?: {
|
|
55
60
|
routingFile: string;
|
|
56
61
|
writeRoot: string;
|
|
57
62
|
tabsModule?: string;
|
|
63
|
+
} | {
|
|
64
|
+
routingFile?: undefined;
|
|
65
|
+
writeRoot?: undefined;
|
|
66
|
+
tabsModule?: string;
|
|
58
67
|
};
|
|
68
|
+
/**
|
|
69
|
+
* Append the engine's header trigger for the preview token panel to the
|
|
70
|
+
* zudo-doc routes plugin's `headerRightItems`. Defaults to true. Unlike
|
|
71
|
+
* `chromeDefaults` this is unconditional: a host with its own `headerNav`
|
|
72
|
+
* still gets the trigger.
|
|
73
|
+
*/
|
|
74
|
+
headerTokenTrigger?: boolean;
|
|
59
75
|
/** Extra keys of `zudo-sg.config.mjs` (e.g. `barrelIndex`) are CLI-only and ignored here. */
|
|
60
76
|
[key: string]: unknown;
|
|
61
77
|
}
|
|
@@ -63,6 +79,22 @@ export interface ZudoSgFragment {
|
|
|
63
79
|
plugins: ZudoSgPluginDescriptor[];
|
|
64
80
|
collections: ZudoSgCollection[];
|
|
65
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* The header-right item `withZudoSg()` appends to the zudo-doc routes plugin.
|
|
84
|
+
*
|
|
85
|
+
* Exported because a host that renders its OWN `<header>` (a host-owned
|
|
86
|
+
* `pages/index.tsx` calling `HeaderWithDefaults` with `settings.headerRightItems`)
|
|
87
|
+
* must add this item to those settings itself. zfb's client router PERSISTS the
|
|
88
|
+
* `<header>` node across a swap — the live header replaces the incoming one — so
|
|
89
|
+
* a session that starts on a trigger-less host page keeps that header for every
|
|
90
|
+
* subsequent SPA navigation, and the trigger never appears on the engine routes.
|
|
91
|
+
* `withZudoSg()` detects an item already carrying the button id and does not
|
|
92
|
+
* append a second one.
|
|
93
|
+
*/
|
|
94
|
+
export declare const HEADER_TOKEN_TRIGGER_ITEM: {
|
|
95
|
+
type: "html";
|
|
96
|
+
html: string;
|
|
97
|
+
};
|
|
66
98
|
/** Returns the engine's zfb plugin descriptors and content collections. */
|
|
67
99
|
export declare function zudoSg(options: ZudoSgComposeOptions): ZudoSgFragment;
|
|
68
100
|
/**
|
package/dist/config/index.js
CHANGED
|
@@ -9,6 +9,7 @@ const ROUTES_PLUGIN_NAME = "@takazudo/zudo-sg/plugins/routes";
|
|
|
9
9
|
const PREVIEW_CSS_PLUGIN_NAME = "@takazudo/zudo-sg/plugins/preview-css";
|
|
10
10
|
const ZDTP_APPLY_PROXY_PLUGIN_NAME = "@takazudo/zudo-sg/plugins/zdtp-apply-proxy";
|
|
11
11
|
const ZUDO_DOC_ROUTES_PLUGIN_NAME = "@takazudo/zudo-doc/plugins/routes";
|
|
12
|
+
const AFTER_NAVIGATE_EVENT = "zfb:after-swap";
|
|
12
13
|
const COMPONENT_DOCS_COLLECTION_BASE = COMPONENT_DOCS_COLLECTION;
|
|
13
14
|
function definedOnly(record) {
|
|
14
15
|
return Object.fromEntries(Object.entries(record).filter(([, value]) => value !== void 0));
|
|
@@ -46,6 +47,36 @@ function withStyleguideChromeDefaults(plugin, routes) {
|
|
|
46
47
|
}
|
|
47
48
|
};
|
|
48
49
|
}
|
|
50
|
+
const HEADER_TOKEN_TRIGGER_ID = "sg-preview-tokens-trigger";
|
|
51
|
+
const PREVIEW_TOKEN_PANEL_EVENT = "toggle-preview-token-panel";
|
|
52
|
+
const ENGINE_ROUTE_ATTR = "data-sg-engine-route";
|
|
53
|
+
const TRIGGER_INSTALLED_FLAG = "__sgPreviewTokensTriggerInstalled";
|
|
54
|
+
const SLIDERS_GLYPH = '<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><line x1="4" y1="6" x2="20" y2="6"></line><line x1="4" y1="12" x2="20" y2="12"></line><line x1="4" y1="18" x2="20" y2="18"></line><circle cx="9" cy="6" r="2.4" fill="currentColor" stroke="none"></circle><circle cx="15" cy="12" r="2.4" fill="currentColor" stroke="none"></circle><circle cx="8" cy="18" r="2.4" fill="currentColor" stroke="none"></circle></svg>';
|
|
55
|
+
const HEADER_TOKEN_TRIGGER_HTML = `<button id="${HEADER_TOKEN_TRIGGER_ID}" type="button" hidden class="flex items-center justify-center text-muted transition-colors hover:text-fg cursor-pointer" aria-label="Open component tokens panel" title="Component tokens" onclick="window.dispatchEvent(new CustomEvent('${PREVIEW_TOKEN_PANEL_EVENT}'))">` + SLIDERS_GLYPH + `</button><script>(function(){if(window.${TRIGGER_INSTALLED_FLAG})return;window.${TRIGGER_INSTALLED_FLAG}=true;function sync(){var btn=document.getElementById(${JSON.stringify(HEADER_TOKEN_TRIGGER_ID)});if(!btn)return;btn.hidden=!document.querySelector(${JSON.stringify(`[${ENGINE_ROUTE_ATTR}]`)});}sync();if(document.readyState==="loading")document.addEventListener("DOMContentLoaded",sync);document.addEventListener(${JSON.stringify(AFTER_NAVIGATE_EVENT)},sync);})();</script>`;
|
|
56
|
+
const HEADER_TOKEN_TRIGGER_ITEM = {
|
|
57
|
+
type: "html",
|
|
58
|
+
html: HEADER_TOKEN_TRIGGER_HTML
|
|
59
|
+
};
|
|
60
|
+
function withHeaderTokenTrigger(plugin) {
|
|
61
|
+
if (!isRecord(plugin) || plugin.name !== ZUDO_DOC_ROUTES_PLUGIN_NAME) return plugin;
|
|
62
|
+
const options = isRecord(plugin.options) ? plugin.options : {};
|
|
63
|
+
const settings = isRecord(options.settings) ? options.settings : {};
|
|
64
|
+
const headerRightItems = Array.isArray(settings.headerRightItems) ? settings.headerRightItems : [];
|
|
65
|
+
const alreadyInstalled = headerRightItems.some(
|
|
66
|
+
(item) => isRecord(item) && item.type === "html" && typeof item.html === "string" && item.html.includes(HEADER_TOKEN_TRIGGER_ID)
|
|
67
|
+
);
|
|
68
|
+
if (alreadyInstalled) return plugin;
|
|
69
|
+
return {
|
|
70
|
+
...plugin,
|
|
71
|
+
options: {
|
|
72
|
+
...options,
|
|
73
|
+
settings: {
|
|
74
|
+
...settings,
|
|
75
|
+
headerRightItems: [...headerRightItems, HEADER_TOKEN_TRIGGER_ITEM]
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}
|
|
49
80
|
function zudoSg(options) {
|
|
50
81
|
if (!options || typeof options !== "object") {
|
|
51
82
|
throw new Error("[zudo-sg] zudoSg(options) requires an options object (the zudo-sg.config.mjs shape)");
|
|
@@ -88,14 +119,16 @@ function withZudoSg(presetFragment, options) {
|
|
|
88
119
|
const sg = zudoSg(options);
|
|
89
120
|
const presetPlugins = [...presetFragment.plugins ?? []];
|
|
90
121
|
const pluginsWithChrome = options.chromeDefaults === false ? presetPlugins : presetPlugins.map((plugin) => withStyleguideChromeDefaults(plugin, resolveSgRoutes(options.routes)));
|
|
122
|
+
const pluginsWithTrigger = options.headerTokenTrigger === false ? pluginsWithChrome : pluginsWithChrome.map(withHeaderTokenTrigger);
|
|
91
123
|
return {
|
|
92
124
|
...presetFragment,
|
|
93
|
-
plugins: [...
|
|
125
|
+
plugins: [...pluginsWithTrigger, ...sg.plugins],
|
|
94
126
|
collections: [...presetFragment.collections ?? [], ...sg.collections]
|
|
95
127
|
};
|
|
96
128
|
}
|
|
97
129
|
export {
|
|
98
130
|
COMPONENT_DOCS_COLLECTION_BASE,
|
|
131
|
+
HEADER_TOKEN_TRIGGER_ITEM,
|
|
99
132
|
PREVIEW_CSS_PLUGIN_NAME,
|
|
100
133
|
ROUTES_PLUGIN_NAME,
|
|
101
134
|
ZDTP_APPLY_PROXY_PLUGIN_NAME,
|
package/dist/plugins/routes.js
CHANGED
|
@@ -173,10 +173,9 @@ function buildRegistryModuleSource(registryModule) {
|
|
|
173
173
|
}
|
|
174
174
|
function buildTokensModuleSource(tokensManifestModule) {
|
|
175
175
|
if (tokensManifestModule === null) return "export const tokensManifest = null;\n";
|
|
176
|
-
const
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
export const tokensManifest = { ${fields.join(", ")} };
|
|
176
|
+
const fields = Object.entries(TOKENS_MANIFEST_EXPORTS).map(([field, name]) => `${field}: manifest.${name}`);
|
|
177
|
+
return `import * as manifest from ${JSON.stringify(toForwardSlash(tokensManifestModule))};
|
|
178
|
+
export const tokensManifest = { ${fields.join(", ")}, groups: "UI_TOKEN_GROUPS" in manifest ? manifest.UI_TOKEN_GROUPS : undefined };
|
|
180
179
|
`;
|
|
181
180
|
}
|
|
182
181
|
function resolvePackageRoot() {
|
|
@@ -7,14 +7,19 @@ export declare const PLUGIN_NAME = "@takazudo/zudo-sg/plugins/zdtp-apply-proxy";
|
|
|
7
7
|
export declare const VIRTUAL_MODULE_ID = "virtual:zudo-sg-preview-token-panel";
|
|
8
8
|
/** Same-origin path the preview panel POSTs its apply diff to. */
|
|
9
9
|
export declare const APPLY_PATH = "/__zdtp/apply";
|
|
10
|
-
export
|
|
10
|
+
export type ZdtpApplyProxyOptions = {
|
|
11
11
|
/** Project-root-relative routing JSON (e.g. `./zdtp-panel-routing.json`). */
|
|
12
12
|
routingFile: string;
|
|
13
13
|
/** Project-root-relative write sandbox directory (e.g. `./packages/demo-ui/styles`). */
|
|
14
14
|
writeRoot: string;
|
|
15
15
|
/** Project-root-relative module exporting `tabs` (the manifest-derived zdtp tab set). */
|
|
16
16
|
tabsModule?: string;
|
|
17
|
-
}
|
|
17
|
+
} | {
|
|
18
|
+
routingFile?: undefined;
|
|
19
|
+
writeRoot?: undefined;
|
|
20
|
+
/** Project-root-relative module exporting `tabs` (the manifest-derived zdtp tab set). */
|
|
21
|
+
tabsModule?: string;
|
|
22
|
+
};
|
|
18
23
|
export type ResolvedZdtpApplyProxyOptions = {
|
|
19
24
|
enabled: true;
|
|
20
25
|
routingFile: string;
|
package/dist/safelist.css
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/* generated by gen-safelist.mjs — do not edit by hand */
|
|
2
|
-
@source inline("-components [--check] [--nested] [--skip-barrel] [data-sg-card] [data-sg-catalog] [data-sg-empty] [data-sg-section] [data-sg-tile] [options] [slug] [zudo-sg] a accent accent-0 accent-1 accent-2 accent-3 accent/state across add adjusted after alias allow-forms allow-same-origin allow-scripts alphabetical alphabetically already always among an and any anything appear application/json apply-css-vars are aria-activedescendant aria-controls aria-describedby aria-details aria-expanded aria-hidden aria-label aria-labelledby aria-live aria-orientation aria-owns aria-pressed aria-selected array as aside assumes at authored back bar barrel barrel-export base be because before below beneath bg bg-[var(--sg-accent)] bg-[var(--sg-bg)] bg-[var(--sg-surface)] bg-[var(--sg-surface-2)] bg-bg block body bogus boolean border border-[color:var(--sg-accent)] border-[color:var(--sg-border)] border-[color:var(--sg-border-strong)] border-b border-t border-transparent both build builds but button by cache-control cannot canvas carries cascading catalog categories category caution change changing checkbox children circle clamp classes clear-css-vars clickable client code codegen collapsing collection color colors command commit compact compare compile compiled component components components2026 config configured confirm const contain content-type copy count counts css cursor-pointer custom-property
|
|
2
|
+
@source inline("-components [--check] [--nested] [--skip-barrel] [data-sg-card] [data-sg-catalog] [data-sg-empty] [data-sg-section] [data-sg-tile] [options] [slug] [zudo-sg] a accent accent-0 accent-1 accent-2 accent-3 accent/state accept across add adjusted after alias all allow-forms allow-same-origin allow-scripts alphabetical alphabetically already always among an and any anything appear application/json apply-css-vars are arguments aria-activedescendant aria-controls aria-describedby aria-details aria-expanded aria-hidden aria-label aria-labelledby aria-live aria-orientation aria-owns aria-pressed aria-selected array arrays as aside assumes async at authored await back bar barrel barrel-export base be because before below beneath bg bg-[var(--sg-accent)] bg-[var(--sg-bg)] bg-[var(--sg-surface)] bg-[var(--sg-surface-2)] bg-bg block body bogus boolean border border-[color:var(--sg-accent)] border-[color:var(--sg-border)] border-[color:var(--sg-border-strong)] border-b border-t border-transparent both break build builds but button by cache-control cannot canvas carries cascading case catalog catch categories category caution change changing checkbox children circle clamp class classes clear-css-vars clickable client code codegen collapsing collection collides color colors command commit compact compare compile compiled component components components2026 config configured confirm const contain content-type continue control copy count counts css cursor-pointer custom custom-property danger dark dashboard dashboards data-category data-copied data-keywords data-name data-sg-card data-sg-catalog data-sg-catalog-intro data-sg-code-panel-hidden data-sg-code-panel-resizer data-sg-empty data-sg-engine-route data-sg-injected-css data-sg-preview-css data-sg-preview-doc data-sg-preview-loading data-sg-preview-scope data-sg-section data-sg-stage-grid data-sg-tile data-sg-tile-size data-sg-variant-root data-theme data-zudo-sg-tokens-empty date debugger declaration declarations declare declared default defaults delete demo derived describe description descriptors design design-token desktop detail detect dev different differs digit directory disabled discovered display distinct div do doc doc-chrome does drift driven dual-scheme duplicate duration each edit editing edits either el element else empty en endpoint engine entries entry entrypoint enum equivalent eval every exists expected explicit export exported exports exposes expressions extends extension failed fails false family fg field file files filled finally find finite first first-authored five fixed flag flex flex-1 flex-col flex-wrap focus-visible:-outline-offset-2 focus-visible:outline focus-visible:outline-2 focus-visible:outline-[color:var(--sg-focus)] focus-visible:outline-offset-2 follow followed follows font font-bold font-family font-medium font-semibold font-size font-size-lh font-weight for form found frame frames free-form from frost full function g gap-hsp-2xs gap-hsp-3xs gap-hsp-md gap-hsp-sm gap-hsp-xs gap-vsp-2xs gap-vsp-lg gap-vsp-md gap-x-hsp-xl gap-y-vsp-xl gate gen-registry gen-token-manifest gen:sg-registry generated get give glob-relative grid grid-cols-1 grid-cols-[repeat(auto-fit,minmax(min(18rem,100%),1fr))] group groups guards h-[1.5rem] h-full h1 h2 h3 hand handle hands has have head header headers height here hex hidden hold host hover:text-[color:var(--sg-fg)] hover:text-fg hsp html human-friendly id if iframe iframes implements import important in include including inert info init inject inline-block inline-flex input inserting inserts inside installed instanceof instead interface into intro invalid inventory is isolated it items-center items-start its itself justify-between justify-center kebab-case keeps key key-enumeration keyboard keydown keyed kind known label large layout lazy leading leading-normal left length let lh light like line line-beauty-accent line-beauty-accent-dark line-beauty-hover line-beauty-hover-dark line-height line-laser-accent line-laser-accent-dark line-laser-hover line-laser-hover-dark line-meeting-accent line-meeting-accent-dark line-meeting-hover line-meeting-hover-dark line-process-accent line-process-accent-dark line-process-hover line-process-hover-dark line-vacuum-accent line-vacuum-accent-dark line-vacuum-hover line-vacuum-hover-dark link lint:tokens list listed lists live load loading m-0 m21 makes manifest map marker markers match matching material max-w-[56rem] may mb-vsp-2xs mb-vsp-lg mb-vsp-sm mb-vsp-xl message meta metadata min-h-0 mirroring missing mobile mode mode-dependent mode-independent model module ms ms-auto mt-vsp-2xs mt-vsp-3xs mt-vsp-xl mt-vsp-xs must mx-auto name name/value named named-export names namespace navigation needs neutral-0 neutral-1 neutral-2 neutral-3 never new new-component new:component no no-store node:crypto node:fs node:fs/promises node:module node:path node:url noindex non-empty none not note nowhere null number object of off oklch omit omitted on once one one-sentence only option options opts or order ordered other out outline-none overflow-auto overflow-hidden overflow-x-auto overriding p p-hsp-2xs p-hsp-md p-hsp-sm package pages pairs palette palette- panel panels parse parsed parser pass passes path per-element per-variant pick pill placeholders plain plugin plugins pnpm polite polyline portable positive postcss pre preact-render-to-string preact/hooks preact/jsx-runtime presentation preserve preview previews primary private property protected pt-vsp-xl public pushes px px-hsp-2xs px-hsp-md px-hsp-sm px-hsp-xs py-vsp-2xs py-vsp-3xs py-vsp-xs radius rail ramp ramps range raw re-executed re-run read-only readonly ready real recover rect reference references regenerated region registration relative rem rem-aware rem-based renamed/removed render rendered renders replace require required requires resolve resolved return returns rhythm robots root-absolute round rounded rounded-full rounded-md rounded-sm route router routes routes-src row rows run runtime s same saved scaffold scaffolds screen scrim script search secondary section segment segments select semantic separator set settings sg-catalog-tile-size sg-chip sg-chip-row sg-code-panel sg-code-panel-hidden sg-code-panel-resizer sg-code-panel-width sg-copy-btn sg-filter sg-filter-row sg-gallery-section sg-grid sg-injected- sg-preview-design-token-panel-modal sg-preview-design-tokens sg-preview-design-tokens/v1 sg-preview-tokens-trigger sg-preview-tweak sg-registry sg-search-clear sg-search-field sg-search-input sg-seg sg-seg-btn sg-thumb sg-thumb-inner sg-thumb-note sg-tile sg-tile-count sg-tile-desc sg-tile-meta sg-tile-title sg-workbench-toolbar sg:height sg:ready sgt- shadow shape shared show shown shrink-0 sidebar sidebar- single-axis site size skipped skips slider slug so solid sorts source spacing span spec specimen stacked starting state state-danger state-danger-dark state-info state-info-dark state-success state-success-dark state-warning state-warning-dark static stay step still story string strings stroke-linecap stroke-linejoin stroke-width style stylesheet super supplies supply support supported surface surfaces svg swaps swatch switch tab tablet tablist tabs tabular-nums text text-2xl text-[color:var(--sg-accent)] text-[color:var(--sg-fg)] text-[color:var(--sg-muted)] text-[color:var(--sg-on-accent)] text-caption text-fg text-heading text-muted text-right text-sm text-small text-xl text-xs text/icons textarea that the their them theme then these this three-tier throw tier tier-model tile time tip title to toggle toggle-design-token-panel toggle-preview-token-panel token tokens total tracking-wide transition-colors true try tsx tweaks twice two type typechecks typeof ui- ui-color ui-defaults-dark ui-defaults-light ui-defaults-shared undefined under underline underline-offset-2 unique unit unitless units unknown unsupported unwired up uppercase us use used uses utf-8 utf8 valid value values var variant variants vertical via viewport views virtual:zudo-doc-chrome-bindings virtual:zudo-doc-route-context virtual:zudo-sg-context virtual:zudo-sg-preview-token-panel virtual:zudo-sg-registry virtual:zudo-sg-tokens visible visit void vs vsp w-[2.5rem] w-[5rem] warning was weight were what when which while whole whose will window with without would written yield you your zd-content zdtp-preview-prehydrate zfb zfb:after-swap zudo-doc zudo-doc-sidebar-width zudo-sg zudo-sg-token-tweak-bridge");
|
|
@@ -3,6 +3,7 @@ import { TokenDashboard } from "@takazudo/zdtp/dashboard";
|
|
|
3
3
|
import { buildDashboardPreviewOverrides, UI_DASHBOARD_PREVIEW_TEXT } from "./ui-token-tabs.js";
|
|
4
4
|
function createTokenDashboards(manifest, tabs, options = {}) {
|
|
5
5
|
const dashboardPreviewOverrides = buildDashboardPreviewOverrides(manifest);
|
|
6
|
+
const previewText = manifest.groups ? "Design tokens give an interface a shared rhythm across pages and themes. Compare the declared values, scale, color, and shape in these samples." : UI_DASHBOARD_PREVIEW_TEXT;
|
|
6
7
|
return /* @__PURE__ */ jsxs("section", { class: "mb-vsp-xl flex flex-col gap-vsp-lg", style: options.chromeStyle, children: [
|
|
7
8
|
/* @__PURE__ */ jsxs("div", { class: "max-w-[56rem]", children: [
|
|
8
9
|
/* @__PURE__ */ jsx("h2", { class: "mb-vsp-2xs text-xl font-semibold text-[color:var(--sg-fg)]", children: "Declared defaults" }),
|
|
@@ -22,7 +23,7 @@ function createTokenDashboards(manifest, tabs, options = {}) {
|
|
|
22
23
|
title: "UI tokens \u2014 mode-dependent defaults (light)",
|
|
23
24
|
tabs,
|
|
24
25
|
previewOverrides: dashboardPreviewOverrides,
|
|
25
|
-
previewText
|
|
26
|
+
previewText
|
|
26
27
|
}
|
|
27
28
|
),
|
|
28
29
|
/* @__PURE__ */ jsx(
|
|
@@ -35,7 +36,7 @@ function createTokenDashboards(manifest, tabs, options = {}) {
|
|
|
35
36
|
title: "UI tokens \u2014 mode-dependent defaults (dark)",
|
|
36
37
|
tabs,
|
|
37
38
|
previewOverrides: dashboardPreviewOverrides,
|
|
38
|
-
previewText
|
|
39
|
+
previewText
|
|
39
40
|
}
|
|
40
41
|
),
|
|
41
42
|
/* @__PURE__ */ jsx(
|
|
@@ -47,7 +48,7 @@ function createTokenDashboards(manifest, tabs, options = {}) {
|
|
|
47
48
|
title: "UI tokens \u2014 shared defaults (mode-independent)",
|
|
48
49
|
tabs,
|
|
49
50
|
previewOverrides: dashboardPreviewOverrides,
|
|
50
|
-
previewText
|
|
51
|
+
previewText
|
|
51
52
|
}
|
|
52
53
|
)
|
|
53
54
|
] });
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
*/
|
|
13
13
|
import type { TabConfig, TokenDef } from "@takazudo/zdtp";
|
|
14
14
|
import type { DashboardPreviewKind } from "@takazudo/zdtp/dashboard";
|
|
15
|
+
import type { GeneratedTokenGroups } from "../token-spec.js";
|
|
15
16
|
/**
|
|
16
17
|
* Tier-1 raw palette color — a plain name/value descriptor (NOT `TokenDef`)
|
|
17
18
|
* because zdtp's `TokenDef.control` has no `"color"` option; this module
|
|
@@ -22,6 +23,12 @@ export interface PaletteColor {
|
|
|
22
23
|
name: string;
|
|
23
24
|
/** Raw color value (e.g. an oklch() string). */
|
|
24
25
|
value: string;
|
|
26
|
+
cssVar?: string;
|
|
27
|
+
id?: string;
|
|
28
|
+
label?: string;
|
|
29
|
+
group?: string;
|
|
30
|
+
readonly?: boolean;
|
|
31
|
+
note?: string;
|
|
25
32
|
}
|
|
26
33
|
/**
|
|
27
34
|
* The shape a host's generated design-token manifest must provide. A host
|
|
@@ -29,12 +36,17 @@ export interface PaletteColor {
|
|
|
29
36
|
* module's export names are) before calling `buildUiTokenTabs` /
|
|
30
37
|
* `buildDashboardPreviewOverrides` / `createTokenDashboards`.
|
|
31
38
|
*/
|
|
39
|
+
type HostToken = TokenDef & {
|
|
40
|
+
valueKind?: "number";
|
|
41
|
+
note?: string;
|
|
42
|
+
};
|
|
32
43
|
export interface UiDesignTokensManifest {
|
|
33
44
|
paletteColors: readonly PaletteColor[];
|
|
34
|
-
colorTokens: readonly
|
|
35
|
-
spacingTokens: readonly
|
|
36
|
-
fontTokens: readonly
|
|
37
|
-
sizeTokens: readonly
|
|
45
|
+
colorTokens: readonly HostToken[];
|
|
46
|
+
spacingTokens: readonly HostToken[];
|
|
47
|
+
fontTokens: readonly HostToken[];
|
|
48
|
+
sizeTokens: readonly HostToken[];
|
|
49
|
+
groups?: GeneratedTokenGroups;
|
|
38
50
|
}
|
|
39
51
|
/**
|
|
40
52
|
* Shared tab data consumed by both a host's runtime preview panel and its
|
|
@@ -51,3 +63,4 @@ export declare function buildUiTokenTabs(manifest: UiDesignTokensManifest): TabC
|
|
|
51
63
|
export declare function buildDashboardPreviewOverrides(manifest: UiDesignTokensManifest): Readonly<Record<string, DashboardPreviewKind>>;
|
|
52
64
|
/** Fixed specimen text shared by the light and dark dashboard instances. */
|
|
53
65
|
export declare const UI_DASHBOARD_PREVIEW_TEXT: string;
|
|
66
|
+
export {};
|
|
@@ -4,13 +4,14 @@ function toTierItem(t, opts) {
|
|
|
4
4
|
kind = { kind: "select", options: t.options ?? [] };
|
|
5
5
|
} else if (t.control === "text") {
|
|
6
6
|
kind = { kind: "text" };
|
|
7
|
-
} else if (opts?.numberKind) {
|
|
7
|
+
} else if (t.valueKind === "number" || opts?.numberKind) {
|
|
8
8
|
kind = { kind: "number", step: t.step, unit: t.unit };
|
|
9
9
|
} else {
|
|
10
10
|
kind = {
|
|
11
11
|
kind: "length",
|
|
12
12
|
step: t.step,
|
|
13
|
-
unit: t.unit
|
|
13
|
+
unit: t.unit,
|
|
14
|
+
...t.units ? { units: t.units } : {}
|
|
14
15
|
};
|
|
15
16
|
}
|
|
16
17
|
const item = {
|
|
@@ -134,7 +135,39 @@ function buildSizeTab(sizeTokens) {
|
|
|
134
135
|
]
|
|
135
136
|
};
|
|
136
137
|
}
|
|
138
|
+
function buildHostTabs(manifest, groups) {
|
|
139
|
+
const categories = ["color", "palette", "spacing", "font", "size"];
|
|
140
|
+
const tokenSets = {
|
|
141
|
+
color: manifest.colorTokens,
|
|
142
|
+
spacing: manifest.spacingTokens,
|
|
143
|
+
font: manifest.fontTokens,
|
|
144
|
+
size: manifest.sizeTokens
|
|
145
|
+
};
|
|
146
|
+
return categories.flatMap((category) => {
|
|
147
|
+
const definitions = groups[category];
|
|
148
|
+
if (!definitions?.length) return [];
|
|
149
|
+
const tiers = definitions.map((group) => {
|
|
150
|
+
const items = category === "palette" ? manifest.paletteColors.filter((color) => color.group === group.id).map((color) => ({
|
|
151
|
+
id: color.id ?? `palette-${color.name}`,
|
|
152
|
+
cssVar: color.cssVar ?? `--palette-${color.name}`,
|
|
153
|
+
label: color.label ?? `palette-${color.name}`,
|
|
154
|
+
default: color.value,
|
|
155
|
+
type: { kind: "color", ...color.value.trim().startsWith("oklch(") ? { format: "oklch" } : {} },
|
|
156
|
+
...color.readonly ? { readonly: true } : {}
|
|
157
|
+
})) : tokenSets[category].filter((token) => token.group === group.id).map((token) => toTierItem(token));
|
|
158
|
+
return {
|
|
159
|
+
id: group.id,
|
|
160
|
+
label: group.label,
|
|
161
|
+
items,
|
|
162
|
+
...group.preview ? { preview: group.preview } : {},
|
|
163
|
+
...group.previewBase ? { previewBase: group.previewBase } : {}
|
|
164
|
+
};
|
|
165
|
+
});
|
|
166
|
+
return [{ id: `ui-${category}`, label: category[0].toUpperCase() + category.slice(1), tiers }];
|
|
167
|
+
});
|
|
168
|
+
}
|
|
137
169
|
function buildUiTokenTabs(manifest) {
|
|
170
|
+
if (manifest.groups) return buildHostTabs(manifest, manifest.groups);
|
|
138
171
|
return [
|
|
139
172
|
buildColorTab(manifest.colorTokens),
|
|
140
173
|
buildPaletteTab(manifest.paletteColors),
|
|
@@ -146,8 +179,10 @@ function buildUiTokenTabs(manifest) {
|
|
|
146
179
|
function buildDashboardPreviewOverrides(manifest) {
|
|
147
180
|
const overrides = {};
|
|
148
181
|
for (const token of manifest.colorTokens) overrides[token.cssVar] = "color";
|
|
149
|
-
|
|
150
|
-
|
|
182
|
+
if (!manifest.groups) {
|
|
183
|
+
for (const token of manifest.sizeTokens) {
|
|
184
|
+
if (token.group === "shadow") overrides[token.cssVar] = "shadow";
|
|
185
|
+
}
|
|
151
186
|
}
|
|
152
187
|
return overrides;
|
|
153
188
|
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/** Plain-data host vocabulary for `tokens.spec` in zudo-sg.config.mjs. */
|
|
2
|
+
export type TokenCategory = "palette" | "color" | "spacing" | "font" | "size";
|
|
3
|
+
export type TokenPreview = "size" | "line-height" | "family" | "weight" | "bar" | "radius" | "duration";
|
|
4
|
+
export type TokenControl = "slider" | "text" | "select";
|
|
5
|
+
export interface HostTokenSpec {
|
|
6
|
+
/** Declared CSS custom property; its CSS declaration supplies `default`. */
|
|
7
|
+
cssVar: string;
|
|
8
|
+
id?: string;
|
|
9
|
+
label?: string;
|
|
10
|
+
control?: TokenControl;
|
|
11
|
+
/** Unitless number rows for the portable tier model; defaults to length rows. */
|
|
12
|
+
valueKind?: "number";
|
|
13
|
+
step?: number;
|
|
14
|
+
unit?: string;
|
|
15
|
+
units?: string[];
|
|
16
|
+
options?: string[];
|
|
17
|
+
readonly?: boolean;
|
|
18
|
+
pill?: {
|
|
19
|
+
value: string;
|
|
20
|
+
customDefault: string;
|
|
21
|
+
};
|
|
22
|
+
note?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface HostTokenGroupSpec {
|
|
25
|
+
id: string;
|
|
26
|
+
label: string;
|
|
27
|
+
tokens: HostTokenSpec[];
|
|
28
|
+
/** Omitted means plain rows, with no inferred demo preview. */
|
|
29
|
+
preview?: TokenPreview;
|
|
30
|
+
previewBase?: string;
|
|
31
|
+
}
|
|
32
|
+
/** Each supplied category is an ordered array of groups. Missing categories are empty. */
|
|
33
|
+
export type HostTokensSpec = Partial<Record<TokenCategory, HostTokenGroupSpec[]>>;
|
|
34
|
+
/** Portable generated metadata for consumers of a host manifest. */
|
|
35
|
+
export interface GeneratedTokenGroup {
|
|
36
|
+
id: string;
|
|
37
|
+
label: string;
|
|
38
|
+
preview?: TokenPreview;
|
|
39
|
+
previewBase?: string;
|
|
40
|
+
}
|
|
41
|
+
export type GeneratedTokenGroups = Record<TokenCategory, GeneratedTokenGroup[]>;
|
|
File without changes
|
package/package.json
CHANGED
package/routes-src/_chrome.tsx
CHANGED
|
@@ -75,7 +75,19 @@ export function chromeProps({ pageTitle, path, extraHead, activeSlug, hideSideba
|
|
|
75
75
|
),
|
|
76
76
|
header: <HeaderWithDefaults {...headerProps} />,
|
|
77
77
|
footer: <FooterWithDefaults lang={locale} />,
|
|
78
|
-
|
|
78
|
+
// Marker for the header trigger's visibility script (sibling issue #814):
|
|
79
|
+
// `document.querySelector("[data-sg-engine-route]")` after every
|
|
80
|
+
// navigation. It sits in bodyEnd, not the header, because the header
|
|
81
|
+
// carries `data-zfb-transition-persist` — the client router lifts it
|
|
82
|
+
// whole across a swap, so a marker there would go stale after navigating
|
|
83
|
+
// to a docs page. bodyEnd has no persist key, so it is discarded and
|
|
84
|
+
// freshly re-rendered per route like the rest of the body.
|
|
85
|
+
bodyEnd: (
|
|
86
|
+
<>
|
|
87
|
+
<BodyEndIslands basePath={ctx.base} />
|
|
88
|
+
<div hidden data-sg-engine-route />
|
|
89
|
+
</>
|
|
90
|
+
),
|
|
79
91
|
navNodes,
|
|
80
92
|
sidebarToggle: Boolean(settings.sidebarToggle),
|
|
81
93
|
enableClientRouter: Boolean(settings.dynamicPageTransition),
|
|
@@ -40,7 +40,10 @@ export default function ComponentsPreviewRoute(): JSX.Element {
|
|
|
40
40
|
}) as unknown as VNode;
|
|
41
41
|
|
|
42
42
|
return (
|
|
43
|
-
|
|
43
|
+
// Chrome-free document (no header, no client router), so the persisted-vs-
|
|
44
|
+
// swapped distinction in ./_chrome.tsx doesn't apply here — the marker is
|
|
45
|
+
// still emitted for route-family completeness (issue #815 AC).
|
|
46
|
+
<html lang="en" data-sg-preview-doc data-sg-engine-route>
|
|
44
47
|
<head>
|
|
45
48
|
<meta charset="utf-8" />
|
|
46
49
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|