create-ailk 0.47.0 → 0.48.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 (137) hide show
  1. package/README.md +180 -43
  2. package/component-catalog.json +223 -285
  3. package/component-catalog.md +1 -1
  4. package/dist/apply-design.d.ts +26 -68
  5. package/dist/apply-design.js +150 -322
  6. package/dist/cli.js +152 -17
  7. package/dist/compare-chrome.d.ts +108 -0
  8. package/dist/compare-chrome.js +481 -0
  9. package/dist/compare-look.d.ts +94 -0
  10. package/dist/compare-look.js +378 -0
  11. package/dist/copy.js +1 -1
  12. package/dist/design-compile.d.ts +17 -21
  13. package/dist/design-compile.js +32 -56
  14. package/dist/design-files.d.ts +93 -0
  15. package/dist/design-files.js +312 -0
  16. package/dist/design-home.d.ts +4 -2
  17. package/dist/design-home.js +88 -6
  18. package/dist/design-names.d.ts +13 -0
  19. package/dist/design-names.js +76 -0
  20. package/dist/design-package.d.ts +46 -56
  21. package/dist/design-package.js +285 -288
  22. package/dist/design-presets.d.ts +41 -0
  23. package/dist/design-presets.js +83 -4
  24. package/dist/design-scaffold.d.ts +12 -2
  25. package/dist/design-scaffold.js +72 -34
  26. package/dist/generated/design-settings.d.ts +56 -0
  27. package/dist/generated/design-settings.js +237 -0
  28. package/dist/index.d.ts +1 -1
  29. package/dist/index.js +2 -2
  30. package/dist/inventory.d.ts +3 -2
  31. package/dist/inventory.js +10 -4
  32. package/dist/lib/design-checks.d.ts +46 -0
  33. package/dist/lib/design-checks.js +79 -1
  34. package/dist/lib/env-catalog.js +1 -1
  35. package/dist/lib/module-license-gate.d.ts +1 -1
  36. package/dist/lib/module-license-gate.js +1 -1
  37. package/dist/lib/render-verdict.d.ts +13 -1
  38. package/dist/lib/render-verdict.js +41 -1
  39. package/dist/look-hub.d.ts +44 -0
  40. package/dist/look-hub.js +130 -0
  41. package/dist/look-record.d.ts +35 -0
  42. package/dist/look-record.js +85 -0
  43. package/dist/look-samples.d.ts +66 -0
  44. package/dist/look-samples.js +456 -0
  45. package/dist/look-settings.d.ts +53 -0
  46. package/dist/look-settings.js +363 -0
  47. package/dist/module-architecture.js +12 -0
  48. package/dist/parse-args.d.ts +10 -6
  49. package/dist/parse-args.js +26 -13
  50. package/dist/programmatic.d.ts +1 -19
  51. package/dist/programmatic.js +65 -103
  52. package/dist/retired-design-bodies.d.ts +29 -0
  53. package/dist/retired-design-bodies.js +51 -0
  54. package/dist/seed-flows.d.ts +1 -1
  55. package/dist/seed-flows.js +12 -14
  56. package/dist/seed-workspace.d.ts +4 -1
  57. package/dist/seed-workspace.js +139 -17
  58. package/dist/site-chrome.d.ts +41 -41
  59. package/dist/site-chrome.js +50 -70
  60. package/dist/site-fonts.d.ts +10 -14
  61. package/dist/site-fonts.js +5 -1
  62. package/dist/starter-grid.d.ts +2 -2
  63. package/dist/strip-look-copies.d.ts +67 -0
  64. package/dist/strip-look-copies.js +591 -0
  65. package/dist/template-manifest.d.ts +6 -14
  66. package/dist/template-manifest.js +0 -9
  67. package/dist/template-record.d.ts +3 -1
  68. package/dist/template-record.js +3 -1
  69. package/dist/topology.d.ts +15 -0
  70. package/dist/topology.js +60 -0
  71. package/dist/update.d.ts +57 -1
  72. package/dist/update.js +742 -13
  73. package/package.json +3 -4
  74. package/site-templates/aliases/hub.TEMPLATE-MANIFEST.json +2 -31
  75. package/site-templates/designs/minimalism/DESIGN.md +163 -297
  76. package/site-templates/designs/minimalism/LOOK.md +42 -0
  77. package/site-templates/designs/minimalism/design.yaml +167 -0
  78. package/site-templates/designs/standard/DESIGN.md +145 -149
  79. package/site-templates/designs/standard/LOOK.md +42 -0
  80. package/site-templates/designs/standard/design.yaml +72 -0
  81. package/site-templates/marketing-site/TEMPLATE-MANIFEST.json +2 -31
  82. package/site-templates/marketing-site/TEMPLATE-MANIFEST.md +1 -25
  83. package/site-templates/marketing-site-free/TEMPLATE-MANIFEST.json +2 -31
  84. package/site-templates/marketing-site-free/TEMPLATE-MANIFEST.md +1 -25
  85. package/site-templates/shapes/local-business-service/TEMPLATE-MANIFEST.json +2 -31
  86. package/site-templates/shapes/local-business-service/TEMPLATE-MANIFEST.md +1 -25
  87. package/site-templates/shapes/organization-service/TEMPLATE-MANIFEST.json +2 -31
  88. package/site-templates/shapes/organization-service/TEMPLATE-MANIFEST.md +1 -25
  89. package/site-templates/shapes/person-service/TEMPLATE-MANIFEST.json +2 -31
  90. package/site-templates/shapes/person-service/TEMPLATE-MANIFEST.md +1 -25
  91. package/site-templates/shapes/person-service/content/_site.mdx +0 -26
  92. package/templates/.claude/rules/extending.md +3 -2
  93. package/templates/.env.example +11 -4
  94. package/templates/CLAUDE.md +1 -1
  95. package/templates/DESIGN.md +145 -149
  96. package/templates/README.md +15 -16
  97. package/templates/apps/api/.env.example +11 -4
  98. package/templates/apps/api/CLAUDE.md +6 -4
  99. package/templates/apps/api/src/lib/__mocks__/prisma.ts +15 -5
  100. package/templates/apps/mcp/CLAUDE.md +4 -2
  101. package/templates/apps/web/.env.example +10 -3
  102. package/templates/apps/web/CLAUDE.md +14 -3
  103. package/templates/apps/web/app/[locale]/layout.tsx +53 -50
  104. package/templates/apps/web/app/not-found.tsx +11 -11
  105. package/templates/apps/web/auth.ts +48 -35
  106. package/templates/apps/web/jest.config.cjs +5 -0
  107. package/templates/apps/web/lib/__tests__/hub-site-config.test.ts +179 -31
  108. package/templates/apps/web/lib/__tests__/library-fonts.test.ts +35 -0
  109. package/templates/apps/web/lib/__tests__/page-chrome-navigation.test.ts +71 -32
  110. package/templates/apps/web/lib/__tests__/page-chrome.test.ts +123 -26
  111. package/templates/apps/web/lib/__tests__/section-look.test.ts +150 -0
  112. package/templates/apps/web/lib/__tests__/site-theme.test.ts +81 -289
  113. package/templates/apps/web/lib/deck-page.ts +3 -10
  114. package/templates/apps/web/lib/deploy-fonts.ts +12 -0
  115. package/templates/apps/web/lib/hub-site-config.ts +97 -14
  116. package/templates/apps/web/lib/library-fonts.ts +41 -0
  117. package/templates/apps/web/lib/mcp-oauth.ts +11 -4
  118. package/templates/apps/web/lib/page-chrome.ts +52 -34
  119. package/templates/apps/web/lib/section-look.ts +28 -0
  120. package/templates/apps/web/lib/site-design.ts +205 -0
  121. package/templates/apps/web/lib/site-theme-head.ts +98 -13
  122. package/templates/apps/web/lib/site-theme.ts +40 -62
  123. package/templates/apps/web/messages/en.json +0 -6
  124. package/templates/apps/web/next.config.mjs +195 -6
  125. package/templates/apps/web/package.json +2 -0
  126. package/templates/apps/web/site-pages.config.tsx +4 -2
  127. package/templates/content/_site.mdx +0 -26
  128. package/templates/design.yaml +75 -0
  129. package/templates/project.yaml +14 -0
  130. package/versions.json +52 -51
  131. package/site-templates/marketing-site/DESIGN.md +0 -259
  132. package/site-templates/marketing-site-free/DESIGN.md +0 -259
  133. package/site-templates/saas-product/DESIGN.md +0 -259
  134. package/templates/apps/web/lib/__tests__/deck-page.test.ts +0 -288
  135. package/templates/apps/web/lib/__tests__/site-theme-head.test.ts +0 -70
  136. package/templates/apps/web/lib/site-chrome.ts +0 -46
  137. package/templates/apps/web/lib/site-fonts.ts +0 -15
@@ -0,0 +1,205 @@
1
+ /**
2
+ * The site's look from its hub design record (#12473 D2, spec
3
+ * docs/specs/12473-a-site-renders-its-colours-spec.md).
4
+ *
5
+ * `readSiteDesign()` reads the `design` member #12470 puts on the hub read
6
+ * (`readHubSite()`, one request, one cache entry, purged by the `site-config`
7
+ * revalidate event) and answers what a request renders from it: the theme
8
+ * compiled from the hub's worked-out `settings`, the record's brand colours
9
+ * worked out over that theme (`brandColorsToSiteBrand`, #12506 D5 — the rule
10
+ * the Admin's Mood board shows) and its fonts mapped onto the brand pair, the
11
+ * layout knobs and the faces. The brand colours and fonts the record leaves
12
+ * out are `_site.mdx`'s `brand:`; nothing else falls back to a file (#12477
13
+ * D1): with no `settings` there is no theme, no layout and no face. It answers
14
+ * `null` — every page renders the base look (`@working-theory/theme`'s
15
+ * defaults under `_site.mdx`'s `brand:`, with `BASE_SITE_LAYOUT`) — with no
16
+ * record, a record whose `settings` is `null` and whose brand sets no colours
17
+ * or fonts, no hub read, or a failed read with nothing held.
18
+ *
19
+ * It reads only `design.settings` and `record.brand.colors` / `.fonts`; never
20
+ * `look`, `from`, `changes`, the record's stored `settings`, `chrome`
21
+ * (#12470's `withDesignChrome`), `brand.logo`, or a settings free-text field.
22
+ * The site never works a look out itself.
23
+ *
24
+ * All or nothing: every check and translation runs inside one `try`, so a
25
+ * record that fails any of it renders the base look, with one warning per
26
+ * record version.
27
+ */
28
+
29
+ import {
30
+ brandColorsToSiteBrand,
31
+ compileDesignFonts,
32
+ compileDesignLayout,
33
+ compileDesignTheme,
34
+ hubBrandToSiteBrand,
35
+ resolveFontStack,
36
+ type SiteBrand,
37
+ type SiteDesignFonts,
38
+ type SiteLayoutKnobs,
39
+ } from "@working-theory/theme";
40
+ import { designSettingsSchema, siteDesignSchema, type CompiledTheme } from "@working-theory/validation";
41
+ import { cache } from "react";
42
+
43
+ import { DEPLOY_FACES } from "./deploy-fonts";
44
+ import { readHubSite } from "./hub-site-config";
45
+ import { LIBRARY_FACES, type BuiltFace } from "./library-fonts";
46
+ import { loadSiteThemeBlocks } from "./site-theme";
47
+ import { recordThemeHead, warnRecordNotRendered } from "./site-theme-head";
48
+
49
+ export type { SiteLayoutKnobs };
50
+
51
+ /**
52
+ * The layout knobs' shape the retired generated `site-chrome.ts` declared,
53
+ * kept here for readers typed against it (#12477 D1), and what each knob does:
54
+ * - nav: "mark-only" → Nav renders the brand mark + right-hand controls
55
+ * only (no nav links).
56
+ * - footer: "centered" → Footer renders its existing centered variant.
57
+ * - announcementBanner: false → the home-only announcement Banner is not
58
+ * mounted (the cookie-consent Banner is unaffected — it is not an
59
+ * announcement).
60
+ * - home: "deck" → the locale-root route mounts MarketingShell with
61
+ * snap="mandatory" + deckHero (spec 5426 D7); every other route is
62
+ * unaffected.
63
+ * - innerPages: "bare" → every non-home page renders the bare header and
64
+ * the one-bar footer.
65
+ * - deckPresentation → the deck home presents slide by slide: fitted slides, slide anchors, the mark follows the ground
66
+ * - deckAnchors: "bare" → the presenting deck names its slides #<id> instead of #slide-<id>
67
+ * - chromeStyle: "minimal" → the deck's closing slide is the wordmark,
68
+ * contact lines and one legal line; the consent bar is a hairline bar on
69
+ * the page ground; the 404 renders in the site's theme.
70
+ * - closingFooterPaths → each listed inner page ends on the closing footer
71
+ * (the wordmark, contact lines and legal line) instead of its usual footer.
72
+ */
73
+ export interface SiteChrome {
74
+ nav: "full" | "mark-only" | "bare" | "none";
75
+ footer: "columns" | "centered" | "closing" | "none";
76
+ announcementBanner: boolean;
77
+ home: "default" | "deck";
78
+ innerPages?: "bare";
79
+ deckPresentation?: true;
80
+ deckAnchors?: "bare";
81
+ chromeStyle?: "minimal";
82
+ closingFooterPaths?: readonly string[];
83
+ }
84
+
85
+ /**
86
+ * The base look's layout knobs (#12477 D1): what every reader takes when no
87
+ * record carries a layout — `design?.layout ?? BASE_SITE_LAYOUT`.
88
+ */
89
+ export const BASE_SITE_LAYOUT: Readonly<SiteLayoutKnobs> = Object.freeze({
90
+ nav: "full",
91
+ footer: "columns",
92
+ announcementBanner: false,
93
+ home: "default",
94
+ });
95
+
96
+ /** What a request renders from the hub design record. */
97
+ export interface RenderedDesign {
98
+ /** The record's saved version. */
99
+ version: number;
100
+ /** The worked-out settings compiled; `undefined` without settings. */
101
+ theme: CompiledTheme | undefined;
102
+ /** The record's brand colours worked out over `theme` and its fonts mapped, each part else `_site.mdx`'s `brand:`; font stacks name the built faces. */
103
+ brand: SiteBrand | undefined;
104
+ /** The worked-out settings' layout; `undefined` without settings, so `BASE_SITE_LAYOUT` applies. */
105
+ layout: SiteLayoutKnobs | undefined;
106
+ /** The worked-out settings' sourced faces, naming the built faces; else none. */
107
+ faces: SiteDesignFonts;
108
+ /** The `<html>` class: the built faces the rendered font stacks use. */
109
+ fontClassName: string;
110
+ }
111
+
112
+ /** The largest settings and brand, as JSON characters, this site compiles (S8). */
113
+ const DESIGN_JSON_MAX = 65_536;
114
+
115
+ /** Every built face, by family: the library's, then the ones the last deploy built. */
116
+ const BUILT_FACES: ReadonlyMap<string, BuiltFace> = new Map([...LIBRARY_FACES, ...DEPLOY_FACES]);
117
+ const BUILT_VARIABLES: ReadonlyMap<string, string> = new Map(
118
+ [...BUILT_FACES].map(([family, face]) => [family, `var(${face.variable})`]),
119
+ );
120
+
121
+ /** `stack` with each built family named by its variable. */
122
+ const resolved = (stack: string): string => resolveFontStack(stack, BUILT_VARIABLES);
123
+
124
+ /** The classes of the built faces `stacks` use. */
125
+ function classesFor(stacks: readonly string[]): string {
126
+ return [...BUILT_FACES.values()]
127
+ .filter((face) => stacks.some((stack) => stack.includes(`var(${face.variable})`)))
128
+ .map((face) => face.className)
129
+ .join(" ");
130
+ }
131
+
132
+ /** A stack holding a newline or an odd count of either quote would open a CSS string (S15). */
133
+ function assertBalancedStack(stack: string | undefined): void {
134
+ if (stack === undefined) return;
135
+ const count = (quote: string) => stack.split(quote).length - 1;
136
+ if (/[\r\n]/.test(stack) || count("'") % 2 !== 0 || count('"') % 2 !== 0) {
137
+ throw new TypeError("a font stack would open a CSS string");
138
+ }
139
+ }
140
+
141
+ export const readSiteDesign = cache(async (): Promise<RenderedDesign | null> => {
142
+ const design = (await readHubSite())?.design ?? null;
143
+ if (design === null) return null;
144
+ const { settings, record } = design;
145
+ const recordColors = record.brand?.colors;
146
+ const recordFonts = hubBrandToSiteBrand({ fonts: record.brand?.fonts }).fonts;
147
+ if (settings === null && recordColors === undefined && recordFonts === undefined) {
148
+ return null;
149
+ }
150
+ try {
151
+ if (JSON.stringify({ settings, brand: record.brand }).length > DESIGN_JSON_MAX) {
152
+ throw new RangeError("the design is over the bound this site compiles");
153
+ }
154
+ // S11 — checked again with the validation this build ships: the cached
155
+ // entry may have been parsed under an older grammar.
156
+ if (settings !== null) designSettingsSchema.parse(settings);
157
+ siteDesignSchema.parse(record);
158
+ for (const stack of [
159
+ settings?.typography["display"]?.fontFamily,
160
+ settings?.typography["body"]?.fontFamily,
161
+ record.brand?.fonts?.primary,
162
+ record.brand?.fonts?.secondary,
163
+ ]) {
164
+ assertBalancedStack(stack);
165
+ }
166
+
167
+ const file = loadSiteThemeBlocks();
168
+ const theme = settings !== null ? compileDesignTheme(settings) : undefined;
169
+ // #12506 D5 — a person's colours worked out over the theme this request
170
+ // renders, so each mode's brand reads on its ground; none set, or none
171
+ // usable (no hex value), keeps the file's.
172
+ const colors = brandColorsToSiteBrand(recordColors, theme) ?? file.brand?.colors;
173
+ const pair = recordFonts ?? file.brand?.fonts;
174
+ const fonts = pair && { display: resolved(pair.display), body: resolved(pair.body) };
175
+ const brand: SiteBrand | undefined =
176
+ colors || fonts ? { ...(colors && { colors }), ...(fonts && { fonts }) } : undefined;
177
+
178
+ let faces: SiteDesignFonts = { className: "", families: {} };
179
+ if (settings !== null) {
180
+ const compiled = compileDesignFonts(settings);
181
+ const families: { display?: string; body?: string } = {};
182
+ for (const role of ["display", "body"] as const) {
183
+ const face = compiled?.[role];
184
+ if (face) families[role] = resolved(face.fallback === "" ? face.family : `${face.family}, ${face.fallback}`);
185
+ }
186
+ faces = { className: classesFor(Object.values(families)), families };
187
+ }
188
+
189
+ const rendered: RenderedDesign = {
190
+ version: design.version,
191
+ theme,
192
+ brand,
193
+ layout: settings !== null ? compileDesignLayout(settings.layout) : undefined,
194
+ faces,
195
+ fontClassName: fonts ? classesFor([fonts.display, fonts.body]) : faces.className,
196
+ };
197
+ // S13 — the one function that writes record CSS refuses a `<`; called
198
+ // here so a refusal renders the whole request on the base look.
199
+ recordThemeHead(rendered);
200
+ return rendered;
201
+ } catch (error) {
202
+ warnRecordNotRendered(design.version, error);
203
+ return null;
204
+ }
205
+ });
@@ -5,29 +5,114 @@
5
5
  * `chromeStyle: minimal` 404 (`app/not-found.tsx`), which renders its own
6
6
  * `<html>`, can never drift apart.
7
7
  *
8
- * The site's own declared colours (`_site.mdx` `theme:` + `brand:`) become
9
- * the token overlay; the design's faces (#7720, the generated
10
- * `site-fonts.ts`) lie beneath `brand.fonts`; both theme modes are emitted,
11
- * the dark one gated by `[data-theme="dark"]` (#1532); the site's shape
12
- * settings (`theme.corners`, `theme.eyebrowCase`) follow so they win.
8
+ * Given the hub design record's `RenderedDesign` (`lib/site-design.ts`,
9
+ * #12473 D3), the head is built from it: its theme, its brand, its faces, its
10
+ * band and its ground. `recordThemeHead` is the one function that writes
11
+ * record CSS, and it refuses a record value holding a `<`; `siteThemeHead`
12
+ * then logs one warning and answers the base look's head.
13
+ *
14
+ * With no record, the base look (#12477 D1): `@working-theory/theme`'s
15
+ * defaults in both modes, the dark one gated by `[data-theme="dark"]`
16
+ * (#1532), under the site's own `_site.mdx` `brand:` triad — no design faces
17
+ * and no shape CSS.
18
+ *
19
+ * #12500 D3 — `ground` is the one ground a site whose light and dark palettes
20
+ * match is drawn on in every mode, worked out from the rendered overlay
21
+ * (`matchedGround`); absent when the palettes differ.
13
22
  */
14
23
 
15
- import { applyDesignFonts, themeToCssVarsBothModes } from "@working-theory/theme";
24
+ import {
25
+ applyDesignFonts,
26
+ matchedGround,
27
+ siteBrandToBrandTokens,
28
+ siteThemeScopedDarkCss,
29
+ siteThemeShapeCss,
30
+ themeToCssVarsBothModes,
31
+ } from "@working-theory/theme";
16
32
 
17
- import { siteFonts } from "./site-fonts";
18
- import { loadSiteBrandTokens, loadSiteShapeCss } from "./site-theme";
33
+ import type { RenderedDesign } from "./site-design";
34
+ import { loadSiteBrandTokens } from "./site-theme";
19
35
 
20
36
  export interface SiteThemeHead {
21
37
  /** The `<style data-ailk="theme-vars">` text. */
22
38
  css: string;
23
39
  /** The `<html>` class for the design's faces; absent when there are none. */
24
40
  fontClassName?: string;
41
+ /** The page's ground in every mode when the two palettes match (#12500 D3); absent otherwise. */
42
+ ground?: "light" | "dark";
43
+ }
44
+
45
+ const RECORD_SOURCE = "hub design record";
46
+
47
+ /** The record versions already warned about; cleared when full, so it never grows past 32 (S9). */
48
+ const warnedVersions = new Set<number>();
49
+ const WARNED_VERSIONS_MAX = 32;
50
+
51
+ /** One `[site-design] record not rendered` warning per record version, naming the error's kind only. */
52
+ export function warnRecordNotRendered(version: number, error: unknown): void {
53
+ if (warnedVersions.has(version)) return;
54
+ if (warnedVersions.size >= WARNED_VERSIONS_MAX) warnedVersions.clear();
55
+ warnedVersions.add(version);
56
+ const name = error instanceof Error ? error.name : "Error";
57
+ console.warn(`[site-design] record not rendered (${name})`);
25
58
  }
26
59
 
27
- export function siteThemeHead(): SiteThemeHead {
28
- const designFonts = applyDesignFonts(loadSiteBrandTokens(), siteFonts);
29
- const css =
60
+ /** For tests: forget the versions already warned about. */
61
+ export function __resetRecordWarningsForTests(): void {
62
+ warnedVersions.clear();
63
+ }
64
+
65
+ /**
66
+ * The theme head built from a hub design record (#12473 D3). Throws when a
67
+ * value the record supplies holds a `<` or the CSS holds `</` (S13), so
68
+ * record CSS that skipped every other check still never ends its `<style>`
69
+ * element.
70
+ */
71
+ export function recordThemeHead(design: RenderedDesign): SiteThemeHead {
72
+ const { theme, brand } = design;
73
+ const overlay = siteBrandToBrandTokens(theme, brand, RECORD_SOURCE);
74
+ const designFonts = applyDesignFonts(overlay, design.faces);
75
+ let css =
30
76
  themeToCssVarsBothModes(designFonts.tokens ? { brand: designFonts.tokens } : {}) +
31
- loadSiteShapeCss();
32
- return designFonts.className ? { css, fontClassName: designFonts.className } : { css };
77
+ siteThemeShapeCss(theme);
78
+ if (theme?.darkBands === "site") {
79
+ // #12500 D2 — the band set in place of the dark one, the brand over it.
80
+ const bandPalette = theme.colors?.band;
81
+ const band =
82
+ bandPalette === undefined
83
+ ? overlay
84
+ : siteBrandToBrandTokens(
85
+ { ...theme, colors: { light: theme.colors?.light, dark: bandPalette } },
86
+ brand,
87
+ RECORD_SOURCE,
88
+ );
89
+ if (band) css += siteThemeScopedDarkCss(theme, band);
90
+ }
91
+ // S13 — no value the record supplies may hold a `<`, and the text written
92
+ // may never hold `</`, the one sequence that ends a `<style>` element. The
93
+ // platform's own CSS carries `<` in its media ranges (`@media (width <
94
+ // 64rem)`), so the whole text is held to `</`, not to `<`.
95
+ if (JSON.stringify([theme, brand, design.faces.families]).includes("<") || css.includes("</")) {
96
+ throw new TypeError("record theme CSS could end its <style> element");
97
+ }
98
+ const ground = matchedGround(overlay);
99
+ return {
100
+ css,
101
+ ...(design.fontClassName ? { fontClassName: design.fontClassName } : {}),
102
+ ...(ground !== undefined ? { ground } : {}),
103
+ };
104
+ }
105
+
106
+ export function siteThemeHead(design: RenderedDesign | null = null): SiteThemeHead {
107
+ if (design !== null) {
108
+ try {
109
+ return recordThemeHead(design);
110
+ } catch (error) {
111
+ warnRecordNotRendered(design.version, error);
112
+ }
113
+ }
114
+ const overlay = loadSiteBrandTokens();
115
+ const css = themeToCssVarsBothModes(overlay ? { brand: overlay } : {});
116
+ const ground = matchedGround(overlay);
117
+ return { css, ...(ground !== undefined ? { ground } : {}) };
33
118
  }
@@ -1,38 +1,34 @@
1
1
  /**
2
- * Site theme — reads the `theme:` block out of `content/_site.mdx` and
3
- * translates it into the token overlay `themeToCssVarsBothModes` accepts.
2
+ * Site theme — reads the brand triad (`brand:`) out of `content/_site.mdx`
3
+ * and translates it into the token overlay `themeToCssVarsBothModes` accepts.
4
+ *
5
+ * `_site.mdx`'s `theme:` is not read (#12477 D2): a site's look is its hub
6
+ * design record's (`lib/site-design.ts`), and with none the page renders the
7
+ * base look — `@working-theory/theme`'s defaults under this triad.
4
8
  *
5
9
  * The read is a local frontmatter parse rather than
6
10
  * `@working-theory/site-config/server`'s `loadSiteConfig`, for the same
7
11
  * reason `site-brand.tsx` reads locally (see its header, and #4157 D1) and
8
12
  * one more: `architecture.yaml` forbids `apps/web` from importing that
9
13
  * subpath at all, because it pulls `node:fs` into a tree that also carries
10
- * edge routes (#1567). The `theme:` block is still validated against the
11
- * canonical schema — `SiteThemeSchema` from the package's client-safe
12
- * `/schema` entry — so the shape this app accepts and the shape the
13
- * dashboard will write are one definition, not two.
14
+ * edge routes (#1567). The `brand:` block is validated against the
15
+ * canonical schema (`BrandSchema` from `@working-theory/site-config/schema`).
14
16
  *
15
17
  * The translation itself lives in `@working-theory/theme`
16
- * (`siteThemeToBrandTokens`) — the token vocabulary is that package's own.
17
- *
18
- * The brand triad (#6820) — `brand.colors` and `brand.fonts`, a sibling of
19
- * `theme:` that applying a design never rewrites — is read in the same parse
20
- * and layered over the theme by `siteBrandToBrandTokens`.
18
+ * (`siteBrandToBrandTokens`) — the token vocabulary is that package's own.
21
19
  *
22
- * Returns `undefined` when the site declares no theme and no triad, so the
23
- * layout passes no `brand` at all and the resolver emits byte-for-byte the
24
- * CSS it emitted before this wiring existed.
20
+ * Returns `undefined` when the site declares no triad, so the layout passes
21
+ * no `brand` at all and the resolver emits `@working-theory/theme`'s defaults.
25
22
  */
26
23
 
27
24
  import { readFileSync } from "node:fs";
28
25
  import { join } from "node:path";
29
26
 
30
- import { BrandSchema, SiteThemeSchema } from "@working-theory/site-config/schema";
27
+ import { BrandSchema } from "@working-theory/site-config/schema";
31
28
  import {
32
29
  siteBrandToBrandTokens,
33
- siteThemeScopedDarkCss,
34
- siteThemeShapeCss,
35
30
  type BrandTokenOverrides,
31
+ type SiteBrand,
36
32
  } from "@working-theory/theme";
37
33
  import { parse as parseYaml } from "yaml";
38
34
  import { z } from "zod";
@@ -41,7 +37,7 @@ import { resolveContentRoot } from "./site-brand";
41
37
 
42
38
  const FRONTMATTER_RE = /^---\r?\n([\s\S]*?)\r?\n---/;
43
39
 
44
- const SOURCE = "content/_site.mdx theme";
40
+ const SOURCE = "content/_site.mdx brand";
45
41
 
46
42
  /**
47
43
  * `brand:` as this loader validates it: every key checked by name, but the
@@ -53,65 +49,47 @@ const BrandTriadSchema = BrandSchema.extend({
53
49
  }).strict();
54
50
 
55
51
  /**
56
- * The `theme:` and `brand:` values as they appear in the frontmatter, each
57
- * `undefined` when `_site.mdx` is absent, unreadable, or does not declare it.
58
- * A site with no readable config has no theme to apply, and the default
59
- * palette is the correct result — the same fallback `site-brand.tsx` takes.
52
+ * The `brand:` value as it appears in the frontmatter, `undefined` when
53
+ * `_site.mdx` is absent, unreadable, or does not declare it. A site with no
54
+ * readable config has no triad to apply, and the default palette is the
55
+ * correct result — the same fallback `site-brand.tsx` takes.
60
56
  *
61
- * "Does not declare it" covers a bare `theme:` key with nothing under it,
62
- * which YAML parses to `null`. That is the shape the most natural edit
63
- * produces — commenting out the block's children leaves the key dangling —
64
- * and it means exactly what an absent key means, so it takes the same path
65
- * rather than reaching the schema and throwing out of a Server Component.
57
+ * "Does not declare it" covers a bare `brand:` key with nothing under it,
58
+ * which YAML parses to `null`: it means exactly what an absent key means, so
59
+ * it takes the same path rather than reaching the schema and throwing out of
60
+ * a Server Component.
66
61
  */
67
- function readSiteBlocks(): { theme: unknown; brand: unknown } {
62
+ function readSiteBlocks(): { brand: unknown } {
68
63
  try {
69
64
  const raw = readFileSync(join(resolveContentRoot(), "_site.mdx"), "utf8");
70
65
  const match = FRONTMATTER_RE.exec(raw);
71
- if (!match) return { theme: undefined, brand: undefined };
66
+ if (!match) return { brand: undefined };
72
67
 
73
68
  const parsed: unknown = parseYaml(match[1] ?? "");
74
- if (!parsed || typeof parsed !== "object") {
75
- return { theme: undefined, brand: undefined };
76
- }
69
+ if (!parsed || typeof parsed !== "object") return { brand: undefined };
77
70
 
78
- const { theme, brand } = parsed as Record<string, unknown>;
79
- return { theme: theme ?? undefined, brand: brand ?? undefined };
71
+ const { brand } = parsed as Record<string, unknown>;
72
+ return { brand: brand ?? undefined };
80
73
  } catch {
81
- return { theme: undefined, brand: undefined };
74
+ return { brand: undefined };
82
75
  }
83
76
  }
84
77
 
78
+ /**
79
+ * The `brand:` block, parsed exactly as `loadSiteBrandTokens` parses it, for
80
+ * the hub design record to fall back to part by part (#12473 D2). Throws as
81
+ * that loader does.
82
+ */
83
+ export function loadSiteThemeBlocks(): { brand?: SiteBrand } {
84
+ const blocks = readSiteBlocks();
85
+ return blocks.brand !== undefined ? { brand: BrandTriadSchema.parse(blocks.brand) } : {};
86
+ }
87
+
85
88
  export function loadSiteBrandTokens(): BrandTokenOverrides | undefined {
86
89
  const blocks = readSiteBlocks();
87
- if (blocks.theme === undefined && blocks.brand === undefined) return undefined;
90
+ if (blocks.brand === undefined) return undefined;
88
91
 
89
92
  // Validation failures and unsupported colours BOTH throw, deliberately: a
90
93
  // customer who set a colour and saw no change would have been lied to.
91
- const theme =
92
- blocks.theme === undefined ? undefined : SiteThemeSchema.parse(blocks.theme);
93
- const brand =
94
- blocks.brand === undefined ? undefined : BrandTriadSchema.parse(blocks.brand);
95
- return siteBrandToBrandTokens(theme, brand, SOURCE);
96
- }
97
-
98
- /**
99
- * The site's shape settings (`theme.corners`, `theme.eyebrowCase`) as a CSS
100
- * override block for `:root`. "" when the site sets neither.
101
- *
102
- * #7719 D6 — a theme with `darkBands: "site"` also gets its own dark palette
103
- * on every dark-scoped band below the root (`siteThemeScopedDarkCss`), built
104
- * from the overlay the root rule carries (the `brand:` triad included). Only
105
- * mode-variant tokens are re-declared, so the shape settings above still
106
- * reach inside the band.
107
- * Without it the string is today's.
108
- */
109
- export function loadSiteShapeCss(): string {
110
- const { theme } = readSiteBlocks();
111
- if (theme === undefined) return "";
112
- const parsed = SiteThemeSchema.parse(theme);
113
- const shape = siteThemeShapeCss(parsed);
114
- if (parsed.darkBands !== "site") return shape;
115
- const brand = loadSiteBrandTokens();
116
- return brand ? shape + siteThemeScopedDarkCss(parsed, brand) : shape;
94
+ return siteBrandToBrandTokens(undefined, BrandTriadSchema.parse(blocks.brand), SOURCE);
117
95
  }
@@ -376,12 +376,6 @@
376
376
  "seoHeading": "SEO",
377
377
  "seoDescription": "Meta description",
378
378
  "seoOgImage": "Social share image URL",
379
- "themeHeading": "Theme",
380
- "themeLightPrimary": "Primary colour (light)",
381
- "themeLightAccent": "Accent colour (light)",
382
- "themeDarkPrimary": "Primary colour (dark)",
383
- "themeDarkAccent": "Accent colour (dark)",
384
- "themeUnconfigured": "This site uses the default theme. Colours become editable once a theme is configured for the workspace.",
385
379
  "saveButton": "Save",
386
380
  "saving": "Saving…",
387
381
  "saved": "Saved",