create-ailk 0.46.6 → 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.
- package/README.md +180 -43
- package/component-catalog.json +223 -285
- package/component-catalog.md +1 -1
- package/dist/apply-design.d.ts +26 -68
- package/dist/apply-design.js +150 -322
- package/dist/cli.js +152 -17
- package/dist/compare-chrome.d.ts +108 -0
- package/dist/compare-chrome.js +481 -0
- package/dist/compare-look.d.ts +94 -0
- package/dist/compare-look.js +378 -0
- package/dist/copy.js +1 -1
- package/dist/design-compile.d.ts +17 -21
- package/dist/design-compile.js +32 -56
- package/dist/design-files.d.ts +93 -0
- package/dist/design-files.js +312 -0
- package/dist/design-home.d.ts +4 -2
- package/dist/design-home.js +88 -6
- package/dist/design-names.d.ts +13 -0
- package/dist/design-names.js +76 -0
- package/dist/design-package.d.ts +46 -56
- package/dist/design-package.js +285 -288
- package/dist/design-presets.d.ts +41 -0
- package/dist/design-presets.js +83 -4
- package/dist/design-scaffold.d.ts +12 -2
- package/dist/design-scaffold.js +72 -34
- package/dist/generated/design-settings.d.ts +56 -0
- package/dist/generated/design-settings.js +237 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/dist/inventory.d.ts +3 -2
- package/dist/inventory.js +10 -4
- package/dist/lib/design-checks.d.ts +46 -0
- package/dist/lib/design-checks.js +79 -1
- package/dist/lib/env-catalog.js +5 -1
- package/dist/lib/module-license-gate.d.ts +1 -1
- package/dist/lib/module-license-gate.js +1 -1
- package/dist/lib/render-verdict.d.ts +13 -1
- package/dist/lib/render-verdict.js +41 -1
- package/dist/look-hub.d.ts +44 -0
- package/dist/look-hub.js +130 -0
- package/dist/look-record.d.ts +35 -0
- package/dist/look-record.js +85 -0
- package/dist/look-samples.d.ts +66 -0
- package/dist/look-samples.js +456 -0
- package/dist/look-settings.d.ts +53 -0
- package/dist/look-settings.js +363 -0
- package/dist/module-architecture.js +12 -0
- package/dist/parse-args.d.ts +10 -6
- package/dist/parse-args.js +26 -13
- package/dist/programmatic.d.ts +1 -19
- package/dist/programmatic.js +65 -103
- package/dist/retired-design-bodies.d.ts +29 -0
- package/dist/retired-design-bodies.js +51 -0
- package/dist/seed-flows.d.ts +1 -1
- package/dist/seed-flows.js +12 -14
- package/dist/seed-workspace.d.ts +4 -1
- package/dist/seed-workspace.js +139 -17
- package/dist/site-chrome.d.ts +41 -41
- package/dist/site-chrome.js +50 -70
- package/dist/site-fonts.d.ts +10 -14
- package/dist/site-fonts.js +5 -1
- package/dist/starter-grid.d.ts +2 -2
- package/dist/strip-look-copies.d.ts +67 -0
- package/dist/strip-look-copies.js +591 -0
- package/dist/template-manifest.d.ts +6 -14
- package/dist/template-manifest.js +0 -9
- package/dist/template-record.d.ts +3 -1
- package/dist/template-record.js +3 -1
- package/dist/topology.d.ts +15 -0
- package/dist/topology.js +60 -0
- package/dist/update.d.ts +57 -1
- package/dist/update.js +742 -13
- package/package.json +3 -4
- package/site-templates/aliases/hub.TEMPLATE-MANIFEST.json +2 -31
- package/site-templates/designs/minimalism/DESIGN.md +163 -297
- package/site-templates/designs/minimalism/LOOK.md +42 -0
- package/site-templates/designs/minimalism/design.yaml +167 -0
- package/site-templates/designs/standard/DESIGN.md +145 -149
- package/site-templates/designs/standard/LOOK.md +42 -0
- package/site-templates/designs/standard/design.yaml +72 -0
- package/site-templates/marketing-site/TEMPLATE-MANIFEST.json +2 -31
- package/site-templates/marketing-site/TEMPLATE-MANIFEST.md +1 -25
- package/site-templates/marketing-site-free/TEMPLATE-MANIFEST.json +2 -31
- package/site-templates/marketing-site-free/TEMPLATE-MANIFEST.md +1 -25
- package/site-templates/shapes/local-business-service/TEMPLATE-MANIFEST.json +2 -31
- package/site-templates/shapes/local-business-service/TEMPLATE-MANIFEST.md +1 -25
- package/site-templates/shapes/organization-service/TEMPLATE-MANIFEST.json +2 -31
- package/site-templates/shapes/organization-service/TEMPLATE-MANIFEST.md +1 -25
- package/site-templates/shapes/person-service/TEMPLATE-MANIFEST.json +2 -31
- package/site-templates/shapes/person-service/TEMPLATE-MANIFEST.md +1 -25
- package/site-templates/shapes/person-service/content/_site.mdx +0 -26
- package/templates/.claude/rules/extending.md +3 -2
- package/templates/.env.example +11 -4
- package/templates/CLAUDE.md +1 -1
- package/templates/DESIGN.md +145 -149
- package/templates/README.md +15 -16
- package/templates/apps/api/.env.example +29 -4
- package/templates/apps/api/CLAUDE.md +7 -4
- package/templates/apps/api/src/__tests__/vercel-handler.test.ts +176 -2
- package/templates/apps/api/src/lib/__mocks__/prisma.ts +30 -4
- package/templates/apps/api/src/vercel-handler.ts +32 -2
- package/templates/apps/mcp/.env.example +8 -0
- package/templates/apps/mcp/CLAUDE.md +5 -3
- package/templates/apps/web/.env.example +10 -3
- package/templates/apps/web/CLAUDE.md +31 -4
- package/templates/apps/web/app/[locale]/layout.tsx +141 -77
- package/templates/apps/web/app/llms.txt/__tests__/site-listing.test.ts +13 -3
- package/templates/apps/web/app/not-found.tsx +11 -11
- package/templates/apps/web/auth.ts +48 -35
- package/templates/apps/web/jest.config.cjs +5 -0
- package/templates/apps/web/lib/__tests__/hub-site-config.test.ts +542 -10
- package/templates/apps/web/lib/__tests__/library-fonts.test.ts +35 -0
- package/templates/apps/web/lib/__tests__/page-chrome-navigation.test.ts +233 -0
- package/templates/apps/web/lib/__tests__/page-chrome.test.ts +123 -26
- package/templates/apps/web/lib/__tests__/section-look.test.ts +150 -0
- package/templates/apps/web/lib/__tests__/site-identity-feature-list.test.ts +19 -1
- package/templates/apps/web/lib/__tests__/site-navigation.test.ts +288 -0
- package/templates/apps/web/lib/__tests__/site-theme.test.ts +81 -289
- package/templates/apps/web/lib/deck-page.ts +3 -10
- package/templates/apps/web/lib/deploy-fonts.ts +12 -0
- package/templates/apps/web/lib/hub-site-config.ts +237 -29
- package/templates/apps/web/lib/library-fonts.ts +41 -0
- package/templates/apps/web/lib/mcp-oauth.ts +11 -4
- package/templates/apps/web/lib/page-chrome.ts +105 -20
- package/templates/apps/web/lib/section-look.ts +28 -0
- package/templates/apps/web/lib/site-design.ts +205 -0
- package/templates/apps/web/lib/site-navigation.ts +208 -0
- package/templates/apps/web/lib/site-theme-head.ts +98 -13
- package/templates/apps/web/lib/site-theme.ts +40 -62
- package/templates/apps/web/messages/en.json +0 -6
- package/templates/apps/web/next.config.mjs +213 -11
- package/templates/apps/web/package.json +2 -0
- package/templates/apps/web/site-pages.config.tsx +4 -2
- package/templates/content/_site.mdx +0 -26
- package/templates/design.yaml +75 -0
- package/templates/project.yaml +14 -0
- package/versions.json +52 -51
- package/site-templates/marketing-site/DESIGN.md +0 -259
- package/site-templates/marketing-site-free/DESIGN.md +0 -259
- package/site-templates/saas-product/DESIGN.md +0 -259
- package/templates/apps/web/lib/__tests__/deck-page.test.ts +0 -288
- package/templates/apps/web/lib/__tests__/site-theme-head.test.ts +0 -70
- package/templates/apps/web/lib/site-chrome.ts +0 -46
- package/templates/apps/web/lib/site-fonts.ts +0 -15
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Section look — registers the site's look for its sections with
|
|
3
|
+
* `@working-theory/page-renderer` (#12474 D3), so a section a page does not
|
|
4
|
+
* set a look field for takes the look's value for its page type, and a change
|
|
5
|
+
* of look in the hub reaches every such page with no page written and no
|
|
6
|
+
* deploy.
|
|
7
|
+
*
|
|
8
|
+
* The reader answers the hub's worked-out `settings.sections` of the site's
|
|
9
|
+
* design record (#12470 D7, D8) — never `design.record`, whose `settings` a
|
|
10
|
+
* library-look record does not hold. It is `undefined` when the hub read has
|
|
11
|
+
* no design, or no worked-out settings, or no `sections`: the pages then
|
|
12
|
+
* render as stored. `readHubSite()` is `cache()`-shared within a request and
|
|
13
|
+
* refreshed by the `site-config` purge every design save sends, so the reader
|
|
14
|
+
* adds no read.
|
|
15
|
+
*
|
|
16
|
+
* Registration happens at module load, and only on a hub-connected site
|
|
17
|
+
* (`hubConnected()`); a site that is not registers nothing and makes no call.
|
|
18
|
+
* `app/[locale]/layout.tsx` imports this module beside the other
|
|
19
|
+
* registrations.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import { setSectionLookReader } from "@working-theory/page-renderer";
|
|
23
|
+
|
|
24
|
+
import { hubConnected, readHubSite } from "./hub-site-config";
|
|
25
|
+
|
|
26
|
+
if (hubConnected()) {
|
|
27
|
+
setSectionLookReader(async () => (await readHubSite())?.design?.settings?.sections ?? undefined);
|
|
28
|
+
}
|
|
@@ -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
|
+
});
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A site's navigation from its hub (#12401, spec
|
|
3
|
+
* docs/specs/12401-a-site-renders-its-header-spec.md D2, D3).
|
|
4
|
+
*
|
|
5
|
+
* `navigationChrome` turns the workspace's navigation record (#12400 D1) into
|
|
6
|
+
* the props the locale layout hands `Nav` and `Footer` — the components'
|
|
7
|
+
* names and props do not change. It is pure: no I/O, and no environment read
|
|
8
|
+
* beyond the three its path helpers make (the docs base, the services base
|
|
9
|
+
* and the route-family renames `pagePath` applies).
|
|
10
|
+
*
|
|
11
|
+
* - A `page` target links to the page's public path on this site:
|
|
12
|
+
* `pagePath` puts a service at the services base and applies the
|
|
13
|
+
* route-family renames, and `toPublicDocsHref` moves `/docs` to the docs
|
|
14
|
+
* path. A `path` or `url` target is used as stored — the record holds the
|
|
15
|
+
* address a visitor sees. No locale prefix is added: the chrome adds it.
|
|
16
|
+
* - A label is the visitor's locale's text when the record has one, else its
|
|
17
|
+
* default text. Every key made here contains a dot and no `nav` message key
|
|
18
|
+
* does, so a record label never replaces a translated one; keys are by
|
|
19
|
+
* position, so two links with the same label stay two links.
|
|
20
|
+
* - Order is the record's; nothing is added, merged or sorted. The hub has
|
|
21
|
+
* already left out every item whose page is not live (#12400 D5).
|
|
22
|
+
* - Every address it emits is checked before it returns, by the record's own
|
|
23
|
+
* target rules: a site path or an `http:`/`https:` URL. Anything else throws, so
|
|
24
|
+
* `safeNavigationChrome` answers `null` and the site's own files render.
|
|
25
|
+
*
|
|
26
|
+
* It imports no site module but `docs-path` and `services-path`, so it closes
|
|
27
|
+
* no import cycle (#12385).
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
import { pagePath } from "@working-theory/templates/routes";
|
|
31
|
+
import type { NavItem } from "@working-theory/ui";
|
|
32
|
+
import {
|
|
33
|
+
siteNavigationTargetSchema,
|
|
34
|
+
type SiteNavigation,
|
|
35
|
+
type SiteNavigationLabel,
|
|
36
|
+
type SiteNavigationLink,
|
|
37
|
+
type SiteNavigationTarget,
|
|
38
|
+
} from "@working-theory/validation";
|
|
39
|
+
|
|
40
|
+
import { toPublicDocsHref } from "./docs-path";
|
|
41
|
+
import { SERVICES_PATH } from "./services-path";
|
|
42
|
+
|
|
43
|
+
type NavFlyoutFeature = NonNullable<NavItem["flyout"]>["features"][number];
|
|
44
|
+
|
|
45
|
+
/** A link with a label already in the visitor's locale. */
|
|
46
|
+
export interface NavigationLink {
|
|
47
|
+
label: string;
|
|
48
|
+
href: string;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** What the layout puts into `Nav` and `Footer` from a record. */
|
|
52
|
+
export interface NavigationChrome {
|
|
53
|
+
/** `Nav`'s and `Footer`'s `navItems`. */
|
|
54
|
+
navItems: NavItem[];
|
|
55
|
+
/** `Footer`'s `columns`. */
|
|
56
|
+
columns: {
|
|
57
|
+
heading: string;
|
|
58
|
+
headingKey: string;
|
|
59
|
+
items: { labelKey: string; path: string; label: string }[];
|
|
60
|
+
}[];
|
|
61
|
+
/** Every label, heading and description, merged into the layout's label map. */
|
|
62
|
+
labels: Record<string, string>;
|
|
63
|
+
/** The signed-out header's button. */
|
|
64
|
+
button?: NavigationLink;
|
|
65
|
+
signIn?: "link" | "hidden";
|
|
66
|
+
/** The bottom bar's links, before the cookie-settings link. */
|
|
67
|
+
legalLinks: NavigationLink[];
|
|
68
|
+
/** The closing footer's locality line and actions. */
|
|
69
|
+
closing?: { locality?: string; actions: NavigationLink[] };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Whether an emitted address passes the record's own target rules — a site
|
|
74
|
+
* path (one leading `/` not followed by `/` or a backslash, no whitespace or
|
|
75
|
+
* backslash), else an `http:`/`https:` URL with no user or password — the
|
|
76
|
+
* schema's checks, shared rather than restated.
|
|
77
|
+
*/
|
|
78
|
+
function isSafeAddress(address: string): boolean {
|
|
79
|
+
return siteNavigationTargetSchema.safeParse(
|
|
80
|
+
address.startsWith("/") ? { kind: "path", path: address } : { kind: "url", href: address },
|
|
81
|
+
).success;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* The record's header and footer as the layout's chrome props, for the
|
|
86
|
+
* visitor's `locale`. Throws on an address that is neither a site path nor an
|
|
87
|
+
* `http:`/`https:` URL.
|
|
88
|
+
*/
|
|
89
|
+
export function navigationChrome(record: SiteNavigation, locale: string): NavigationChrome {
|
|
90
|
+
const wanted = locale.toLowerCase();
|
|
91
|
+
const labels: Record<string, string> = {};
|
|
92
|
+
const emitted: string[] = [];
|
|
93
|
+
|
|
94
|
+
const text = (label: SiteNavigationLabel): string => {
|
|
95
|
+
for (const [code, value] of Object.entries(label.byLocale ?? {})) {
|
|
96
|
+
if (code.toLowerCase() === wanted) return value;
|
|
97
|
+
}
|
|
98
|
+
return label.text;
|
|
99
|
+
};
|
|
100
|
+
const addressOf = (target: SiteNavigationTarget): string => {
|
|
101
|
+
const address =
|
|
102
|
+
target.kind === "page"
|
|
103
|
+
? toPublicDocsHref(pagePath({ type: target.address.type, slug: target.address.slug }, SERVICES_PATH))
|
|
104
|
+
: target.kind === "path"
|
|
105
|
+
? target.path
|
|
106
|
+
: target.href;
|
|
107
|
+
emitted.push(address);
|
|
108
|
+
return address;
|
|
109
|
+
};
|
|
110
|
+
const linkOf = (link: SiteNavigationLink): NavigationLink => ({
|
|
111
|
+
label: text(link.label),
|
|
112
|
+
href: addressOf(link.target),
|
|
113
|
+
});
|
|
114
|
+
const keyed = (key: string, link: SiteNavigationLink): NavFlyoutFeature => {
|
|
115
|
+
labels[key] = text(link.label);
|
|
116
|
+
const feature: NavFlyoutFeature = { labelKey: key, path: addressOf(link.target) };
|
|
117
|
+
if (link.description !== undefined) {
|
|
118
|
+
labels[`${key}.d`] = text(link.description);
|
|
119
|
+
feature.descKey = `${key}.d`;
|
|
120
|
+
}
|
|
121
|
+
return feature;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const navItems = record.header.items.map((item, i): NavItem => {
|
|
125
|
+
const key = `rec.h${i}`;
|
|
126
|
+
labels[key] = text(item.label);
|
|
127
|
+
if (item.kind === "link") return { labelKey: key, path: addressOf(item.target) };
|
|
128
|
+
const [only] = item.groups;
|
|
129
|
+
if (item.groups.length === 1 && only !== undefined && only.heading === undefined) {
|
|
130
|
+
const features = only.links.map((link, l) => keyed(`${key}.g0.l${l}`, link));
|
|
131
|
+
const described = features.some((feature) => feature.descKey !== undefined);
|
|
132
|
+
return {
|
|
133
|
+
labelKey: key,
|
|
134
|
+
flyout: described
|
|
135
|
+
? { features, presentation: "grid", width: "panel" }
|
|
136
|
+
: { features, presentation: "list", width: "trigger" },
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
const groups = item.groups.map((group, g) => {
|
|
140
|
+
const headingKey = `${key}.g${g}`;
|
|
141
|
+
labels[headingKey] = group.heading === undefined ? "" : text(group.heading);
|
|
142
|
+
return {
|
|
143
|
+
headingKey,
|
|
144
|
+
items: group.links.map((link, l) => keyed(`${headingKey}.l${l}`, link)),
|
|
145
|
+
};
|
|
146
|
+
});
|
|
147
|
+
return {
|
|
148
|
+
labelKey: key,
|
|
149
|
+
flyout: { features: groups.flatMap((group) => group.items), groups, width: "panel" },
|
|
150
|
+
};
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
const columns = record.footer.columns.map((column, c) => {
|
|
154
|
+
const headingKey = `rec.f${c}`;
|
|
155
|
+
const heading = text(column.heading);
|
|
156
|
+
labels[headingKey] = heading;
|
|
157
|
+
return {
|
|
158
|
+
heading,
|
|
159
|
+
headingKey,
|
|
160
|
+
items: column.links.map((link, l) => {
|
|
161
|
+
const labelKey = `${headingKey}.l${l}`;
|
|
162
|
+
const label = text(link.label);
|
|
163
|
+
labels[labelKey] = label;
|
|
164
|
+
return { labelKey, path: addressOf(link.target), label };
|
|
165
|
+
}),
|
|
166
|
+
};
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
const { button, signIn } = record.header;
|
|
170
|
+
const { closing } = record.footer;
|
|
171
|
+
const chrome: NavigationChrome = {
|
|
172
|
+
navItems,
|
|
173
|
+
columns,
|
|
174
|
+
labels,
|
|
175
|
+
legalLinks: (record.footer.bottomBar?.links ?? []).map(linkOf),
|
|
176
|
+
...(button !== undefined ? { button: linkOf(button) } : {}),
|
|
177
|
+
...(signIn !== undefined ? { signIn } : {}),
|
|
178
|
+
...(closing !== undefined
|
|
179
|
+
? {
|
|
180
|
+
closing: {
|
|
181
|
+
...(closing.location !== undefined ? { locality: closing.location } : {}),
|
|
182
|
+
actions: closing.buttons.map(linkOf),
|
|
183
|
+
},
|
|
184
|
+
}
|
|
185
|
+
: {}),
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
for (const address of emitted) {
|
|
189
|
+
if (!isSafeAddress(address)) throw new TypeError("navigation address refused");
|
|
190
|
+
}
|
|
191
|
+
return chrome;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* `navigationChrome`, or `null` when it throws — with one warning naming the
|
|
196
|
+
* error's kind, never a value — so a record that cannot be rendered never
|
|
197
|
+
* throws into a page and the site's own files render.
|
|
198
|
+
*/
|
|
199
|
+
export function safeNavigationChrome(record: SiteNavigation, locale: string): NavigationChrome | null {
|
|
200
|
+
try {
|
|
201
|
+
return navigationChrome(record, locale);
|
|
202
|
+
} catch (err) {
|
|
203
|
+
console.warn(
|
|
204
|
+
`[site-navigation] record not rendered (${err instanceof Error ? err.name : typeof err})`,
|
|
205
|
+
);
|
|
206
|
+
return null;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
@@ -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
|
-
*
|
|
9
|
-
* the
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
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 {
|
|
24
|
+
import {
|
|
25
|
+
applyDesignFonts,
|
|
26
|
+
matchedGround,
|
|
27
|
+
siteBrandToBrandTokens,
|
|
28
|
+
siteThemeScopedDarkCss,
|
|
29
|
+
siteThemeShapeCss,
|
|
30
|
+
themeToCssVarsBothModes,
|
|
31
|
+
} from "@working-theory/theme";
|
|
16
32
|
|
|
17
|
-
import {
|
|
18
|
-
import { loadSiteBrandTokens
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
32
|
-
|
|
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
|
}
|