create-ailk 0.47.0 → 0.48.1

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 +192 -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 +807 -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 +42 -41
  59. package/dist/site-chrome.js +51 -70
  60. package/dist/site-fonts.d.ts +14 -14
  61. package/dist/site-fonts.js +9 -4
  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,378 @@
1
+ /**
2
+ * `create-ailk compare-look` (#12476 D6, spec
3
+ * docs/specs/12476-import-each-live-site-s-spec.md): before-and-after
4
+ * captures of whole pages, for a change to a site's look — the design-record
5
+ * import first, any later look change after it.
6
+ *
7
+ * `compare-chrome` reads the header and footer only, so a changed colour,
8
+ * face or section layout in the page body passes it. This captures each
9
+ * path's whole page at each of `VIEWPORTS` (1440 and 390 wide), in each
10
+ * colour scheme (`light`, `dark`), each in a fresh signed-out context opened
11
+ * with that scheme: the response status, the design render stamp
12
+ * (`meta[name="ailk-design-source"]`, D7) and a full-page screenshot taken
13
+ * once the fonts are ready. Only a 200 is captured: any other status, or a
14
+ * page that fails, is recorded as not captured. `--capture` writes them;
15
+ * `--against` captures again and compares pixels by `diffPixels` at
16
+ * `--tolerance` (default 0). With `--expect-source` every after-shot must carry the stamp.
17
+ *
18
+ * Pure module: no `import.meta.url`, so jest imports it directly; the browser
19
+ * is injected, and the page is reached only through the `LookPage` slice.
20
+ */
21
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
22
+ import { join } from "node:path";
23
+ import { parseArgs } from "node:util";
24
+ import { decodePng, diffPixels, PLAYWRIGHT_INSTALL_HINT, VIEWPORTS } from "./lib/render-comparison.js";
25
+ import { printable } from "./look-settings.js";
26
+ import { ParseError } from "./parse-args.js";
27
+ /** A refusal before anything is rendered: exit 2. */
28
+ export class CompareLookRefusedError extends Error {
29
+ name = "CompareLookRefusedError";
30
+ }
31
+ /** The two colour schemes every page is captured in, light first. */
32
+ export const COLOR_SCHEMES = ["light", "dark"];
33
+ const NAVIGATION_TIMEOUT_MS = 60_000;
34
+ /** The page's design render stamp (D7): the `<head>` meta, or nulls. */
35
+ export const DESIGN_STAMP_EXPRESSION = '(() => { const meta = document.querySelector(\'meta[name="ailk-design-source"]\'); ' +
36
+ 'return { source: meta ? meta.getAttribute("content") : null, ' +
37
+ 'version: meta ? meta.getAttribute("data-version") : null }; })()';
38
+ /** How long a page's fonts may take before the shot is taken anyway. */
39
+ const FONTS_TIMEOUT_MS = 15_000;
40
+ /** Resolves once every face the page uses is loaded, or after `FONTS_TIMEOUT_MS`. */
41
+ export const FONTS_READY_EXPRESSION = `Promise.race([document.fonts.ready, new Promise((r) => setTimeout(r, ${FONTS_TIMEOUT_MS}))]).then(() => true)`;
42
+ function asStamp(value) {
43
+ const stamp = (value ?? {});
44
+ return {
45
+ source: typeof stamp.source === "string" ? stamp.source : null,
46
+ version: typeof stamp.version === "string" ? stamp.version : null,
47
+ };
48
+ }
49
+ /** Whether `path` is a path on any origin it is joined to: `/`-rooted, not `//`, resolving to itself. */
50
+ function isSitePath(path) {
51
+ if (!/^\/(?!\/)/.test(path))
52
+ return false;
53
+ const probe = "https://origin.invalid";
54
+ try {
55
+ const url = new URL(path, probe);
56
+ return url.origin === probe && url.pathname === path;
57
+ }
58
+ catch {
59
+ return false;
60
+ }
61
+ }
62
+ /** A shot's key and file stem: the path's place in the capture's own order, the viewport and the scheme. */
63
+ const shotKey = (index, viewport, scheme) => `page-${index + 1}--${viewport}--${scheme}`;
64
+ /** Every path at every viewport in every scheme, each in a fresh signed-out context. */
65
+ async function captureAll(chromium, origin, paths, dir) {
66
+ mkdirSync(dir, { recursive: true });
67
+ const browser = await chromium.launch();
68
+ const shots = [];
69
+ try {
70
+ for (const [index, path] of paths.entries()) {
71
+ for (const viewport of VIEWPORTS) {
72
+ for (const scheme of COLOR_SCHEMES) {
73
+ const context = await browser.newContext({ colorScheme: scheme });
74
+ const shot = { path, viewport: viewport.name, scheme, status: null, stamp: asStamp(null), shot: null };
75
+ try {
76
+ const page = await context.newPage();
77
+ await page.setViewportSize({ width: viewport.width, height: viewport.height });
78
+ // The site's own JavaScript can choose an error's text: D2's printing rule applies (SEC: no site value forges a line).
79
+ const firstLine = (err) => printable(err instanceof Error ? (err.message.split("\n")[0] ?? "") : String(err));
80
+ try {
81
+ const response = await page.goto(origin + path, { waitUntil: "networkidle", timeout: NAVIGATION_TIMEOUT_MS });
82
+ if (response === null)
83
+ shot.error = "no response";
84
+ else if (new URL(response.url()).origin !== origin)
85
+ shot.error = "redirected off-origin";
86
+ else
87
+ shot.status = response.status();
88
+ }
89
+ catch (err) {
90
+ shot.error = `navigation failed: ${firstLine(err)}`;
91
+ }
92
+ // Only a 200 is a page: an error page or a mistyped path is never captured as equal.
93
+ if (shot.error === undefined && shot.status !== 200)
94
+ shot.error = `status ${shot.status}, expected 200`;
95
+ if (shot.error === undefined) {
96
+ // One shot that fails is recorded as not captured; the capture goes on.
97
+ try {
98
+ await page.evaluate(FONTS_READY_EXPRESSION);
99
+ shot.stamp = asStamp(await page.evaluate(DESIGN_STAMP_EXPRESSION));
100
+ const name = `${shotKey(index, viewport.name, scheme)}.png`;
101
+ writeFileSync(join(dir, name), await page.screenshot({ fullPage: true, animations: "disabled" }));
102
+ shot.shot = name;
103
+ }
104
+ catch (err) {
105
+ shot.error = `capture failed: ${firstLine(err)}`;
106
+ }
107
+ }
108
+ }
109
+ finally {
110
+ await context.close();
111
+ }
112
+ shots.push(shot);
113
+ }
114
+ }
115
+ }
116
+ }
117
+ finally {
118
+ await browser.close();
119
+ }
120
+ return shots;
121
+ }
122
+ /** Why two screenshots differ, or null when they are equal at `tolerance`. */
123
+ function pixelDifference(before, after, tolerance) {
124
+ const a = decodePng(before);
125
+ const b = decodePng(after);
126
+ // Never equal by omission: a PNG the decoder cannot read is a difference.
127
+ if (!a.ok || !b.ok)
128
+ return `unsupported-png (${!a.ok ? "before" : "after"})`;
129
+ const differing = diffPixels(a.image, b.image);
130
+ if (differing === "size-differs") {
131
+ return `screenshot size ${a.image.width}×${a.image.height} → ${b.image.width}×${b.image.height}`;
132
+ }
133
+ const share = differing / (a.image.width * a.image.height);
134
+ return share > tolerance ? `${differing} pixels differ (${(share * 100).toFixed(4)}%)` : null;
135
+ }
136
+ const showStamp = (s) => s === null ? "—" : `${s.source === null ? "(missing)" : printable(s.source)}${s.version === null ? "" : ` v${printable(String(s.version))}`}`;
137
+ /** Captures or compares (D6); answers the exit code: 0 all equal, 1 a difference or a page that did not load. */
138
+ export async function compareLook(o) {
139
+ const line = o.onLine ?? (() => { });
140
+ if ((o.capture === undefined) === (o.against === undefined)) {
141
+ throw new CompareLookRefusedError("compare-look: pass exactly one of --capture <dir> and --against <dir>");
142
+ }
143
+ let url;
144
+ try {
145
+ url = new URL(o.origin);
146
+ }
147
+ catch {
148
+ throw new CompareLookRefusedError(`compare-look: --origin ${o.origin} is not a URL`);
149
+ }
150
+ if (!/^https?:$/.test(url.protocol)) {
151
+ throw new CompareLookRefusedError("compare-look: --origin must be an http(s) URL");
152
+ }
153
+ const origin = url.origin;
154
+ if (o.paths.length === 0)
155
+ throw new CompareLookRefusedError("compare-look: pass at least one --path");
156
+ if (new Set(o.paths).size !== o.paths.length)
157
+ throw new CompareLookRefusedError("compare-look: a --path is given twice");
158
+ for (const path of o.paths) {
159
+ if (!isSitePath(path))
160
+ throw new CompareLookRefusedError(`compare-look: --path ${path} is not a site path`);
161
+ }
162
+ let before;
163
+ if (o.against !== undefined) {
164
+ // Only the capture's own origin and paths are compared: a path left out,
165
+ // or another origin, would be a shot never compared.
166
+ const captureFile = join(o.against, "capture.json");
167
+ if (!existsSync(captureFile))
168
+ throw new CompareLookRefusedError(`compare-look: no capture at ${o.against}`);
169
+ try {
170
+ before = JSON.parse(readFileSync(captureFile, "utf8"));
171
+ }
172
+ catch {
173
+ throw new CompareLookRefusedError(`compare-look: ${captureFile} is not a capture`);
174
+ }
175
+ if (typeof before !== "object" || before === null || !Array.isArray(before.shots)) {
176
+ throw new CompareLookRefusedError(`compare-look: ${captureFile} is not a capture`);
177
+ }
178
+ if (before.origin !== origin) {
179
+ throw new CompareLookRefusedError(`compare-look: the capture is of ${String(before.origin)}, not ${origin}`);
180
+ }
181
+ if (JSON.stringify(before.paths) !== JSON.stringify(o.paths)) {
182
+ throw new CompareLookRefusedError(`compare-look: pass the capture's paths, in its order: ${JSON.stringify(before.paths)}`);
183
+ }
184
+ }
185
+ if (o.chromium === undefined) {
186
+ throw new CompareLookRefusedError(`compare-look: Playwright's Chromium was not found; install it: ${PLAYWRIGHT_INSTALL_HINT}`);
187
+ }
188
+ if (o.capture !== undefined) {
189
+ const shots = await captureAll(o.chromium, origin, o.paths, o.capture);
190
+ const file = { origin, paths: [...o.paths], at: (o.now ?? (() => new Date()))().toISOString(), shots };
191
+ writeFileSync(join(o.capture, "capture.json"), `${JSON.stringify(file, null, 2)}\n`);
192
+ let failed = 0;
193
+ for (const s of shots) {
194
+ if (s.shot === null)
195
+ failed += 1;
196
+ line(`${s.shot === null ? "NOT CAPTURED" : "captured"} ${s.path} @ ${s.viewport} ${s.scheme} — ` +
197
+ (s.error ?? `status ${s.status} · stamp ${showStamp(s.stamp)}`));
198
+ }
199
+ return { exitCode: failed === 0 ? 0 : 1 };
200
+ }
201
+ const beforeDir = o.against;
202
+ const out = o.out ?? join(beforeDir, "comparison");
203
+ const afterDir = join(out, "after");
204
+ const shotsDir = join(out, "shots");
205
+ mkdirSync(shotsDir, { recursive: true });
206
+ const after = await captureAll(o.chromium, origin, o.paths, afterDir);
207
+ const tolerance = o.tolerance ?? 0;
208
+ const differences = [];
209
+ const stamps = [];
210
+ const keyOf = (s) => shotKey(o.paths.indexOf(s.path), s.viewport, s.scheme);
211
+ const thenByKey = new Map(before.shots.map((s) => [keyOf(s), s]));
212
+ const nowKeys = new Set(after.map(keyOf));
213
+ for (const then of before.shots) {
214
+ if (!nowKeys.has(keyOf(then))) {
215
+ differences.push({ path: then.path, viewport: then.viewport, scheme: then.scheme, detail: "only before" });
216
+ }
217
+ }
218
+ for (const now of after) {
219
+ const key = keyOf(now);
220
+ const at = { path: now.path, viewport: now.viewport, scheme: now.scheme };
221
+ const then = thenByKey.get(key);
222
+ stamps.push({ ...at, before: then?.stamp ?? null, after: now.stamp });
223
+ if (then === undefined) {
224
+ differences.push({ ...at, detail: "only after" });
225
+ continue;
226
+ }
227
+ if (then.shot === null || now.shot === null) {
228
+ differences.push({
229
+ ...at,
230
+ detail: `did not load: ${then.shot === null ? `before — ${then.error ?? "no screenshot"}` : `after — ${now.error ?? "no screenshot"}`}`,
231
+ });
232
+ continue;
233
+ }
234
+ if (o.expect !== undefined) {
235
+ const ok = now.stamp.source === o.expect.source && (o.expect.version === undefined || now.stamp.version === o.expect.version);
236
+ if (!ok) {
237
+ differences.push({
238
+ ...at,
239
+ detail: `expected stamp ${o.expect.source}${o.expect.version === undefined ? "" : ` v${o.expect.version}`}, rendered ${showStamp(now.stamp)}`,
240
+ });
241
+ }
242
+ }
243
+ // Both screenshots are named as this run names them, never by a name the capture's JSON holds.
244
+ let beforePng;
245
+ try {
246
+ beforePng = readFileSync(join(beforeDir, `${key}.png`));
247
+ }
248
+ catch {
249
+ differences.push({ ...at, detail: "the capture's screenshot is missing" });
250
+ continue;
251
+ }
252
+ const afterPng = readFileSync(join(afterDir, `${key}.png`));
253
+ const detail = pixelDifference(beforePng, afterPng, tolerance);
254
+ if (detail === null)
255
+ continue;
256
+ differences.push({ ...at, detail });
257
+ writeFileSync(join(shotsDir, `${key}--before.png`), beforePng);
258
+ writeFileSync(join(shotsDir, `${key}--after.png`), afterPng);
259
+ }
260
+ const pass = differences.length === 0;
261
+ const report = { origin, against: beforeDir, tolerance, paths: o.paths, expect: o.expect ?? null, pass, differences, stamps };
262
+ writeFileSync(join(out, "comparison.json"), `${JSON.stringify(report, null, 2)}\n`);
263
+ writeFileSync(join(out, "comparison.md"), comparisonMarkdown(report));
264
+ for (const d of differences)
265
+ line(`DIFFERS ${d.path} @ ${d.viewport} ${d.scheme} — ${d.detail}`);
266
+ line(`${pass ? "PASS" : "FAIL"}: ${differences.length} difference(s); evidence in ${out}`);
267
+ return { exitCode: pass ? 0 : 1 };
268
+ }
269
+ function comparisonMarkdown(report) {
270
+ return [
271
+ `# Look comparison — ${report.origin}`,
272
+ "",
273
+ `**${report.pass ? "PASS" : "FAIL"}** — ${report.differences.length} difference(s) at tolerance ${report.tolerance}.`,
274
+ "",
275
+ "## Differences",
276
+ "",
277
+ ...(report.differences.length === 0
278
+ ? ["None."]
279
+ : report.differences.map((d) => `- \`${d.path}\` · ${d.viewport} · ${d.scheme} — ${d.detail}`)),
280
+ "",
281
+ "## Design render stamp",
282
+ "",
283
+ "| Path | Viewport | Scheme | Before | After |",
284
+ "| --- | --- | --- | --- | --- |",
285
+ ...report.stamps.map((s) => `| \`${s.path}\` | ${s.viewport} | ${s.scheme} | ${showStamp(s.before)} | ${showStamp(s.after)} |`),
286
+ "",
287
+ ].join("\n");
288
+ }
289
+ export const COMPARE_LOOK_HELP = `create-ailk compare-look — before-and-after captures of whole pages, light and dark.
290
+
291
+ Usage:
292
+ create-ailk compare-look [<dir>] --origin <url> --path <path> [--path <path> …] --capture <dir>
293
+ create-ailk compare-look [<dir>] --origin <url> --path <path> [--path <path> …] --against <dir> [--out <dir>] [--tolerance <share>] [--expect-source record --expect-version <n> | --expect-source files]
294
+
295
+ Arguments:
296
+ <dir> A checkout whose Playwright runs the browser. Defaults to the current dir.
297
+
298
+ Options:
299
+ --origin <url> The live site.
300
+ --path <path> A site path to capture; repeat for each.
301
+ --capture <dir> Record each whole page at 1440 and 390 wide, light and dark.
302
+ --against <dir> Capture again and compare with that capture.
303
+ --out <dir> Where comparison.json, comparison.md, after/ and shots/ go. Default <against>/comparison.
304
+ --tolerance <share> The share of a screenshot's pixels that may differ. Default 0.
305
+ --expect-source <src> Every page must render its look from <src>: record (with --expect-version) or files.
306
+ --expect-version <n> The design record version every page must render.
307
+ -h, --help Show this help.
308
+
309
+ Only a 200 page is captured; full-page screenshots are compared, after the page's fonts are ready.
310
+ Needs Playwright's Chromium: ${PLAYWRIGHT_INSTALL_HINT}.
311
+ The runbook is docs/internal/runbooks/site-design-import.md.
312
+ Exit 0 when every shot is the same, 1 when one is not or a page did not load,
313
+ 2 on a refusal.
314
+ `;
315
+ export function parseCompareLookArgs(argv) {
316
+ let parsed;
317
+ try {
318
+ parsed = parseArgs({
319
+ args: argv,
320
+ strict: true,
321
+ allowPositionals: true,
322
+ options: {
323
+ origin: { type: "string" },
324
+ path: { type: "string", multiple: true },
325
+ capture: { type: "string" },
326
+ against: { type: "string" },
327
+ out: { type: "string" },
328
+ tolerance: { type: "string" },
329
+ "expect-source": { type: "string" },
330
+ "expect-version": { type: "string" },
331
+ help: { type: "boolean", default: false, short: "h" },
332
+ },
333
+ });
334
+ }
335
+ catch (err) {
336
+ throw new ParseError(`compare-look: ${err.message}`);
337
+ }
338
+ const [target, ...rest] = parsed.positionals;
339
+ if (rest.length > 0) {
340
+ throw new ParseError(`compare-look takes at most one directory, got ${parsed.positionals.length} arguments`);
341
+ }
342
+ const raw = parsed.values.tolerance;
343
+ const tolerance = raw === undefined ? undefined : Number(raw);
344
+ if (tolerance !== undefined && (raw.trim() === "" || Number.isNaN(tolerance) || tolerance < 0 || tolerance > 1)) {
345
+ throw new ParseError("compare-look: --tolerance must be a number from 0 to 1");
346
+ }
347
+ const source = parsed.values["expect-source"];
348
+ const version = parsed.values["expect-version"];
349
+ if (source !== undefined && source !== "record" && source !== "files") {
350
+ throw new ParseError("compare-look: --expect-source is record or files");
351
+ }
352
+ if (source === "record" && version === undefined) {
353
+ throw new ParseError("compare-look: --expect-source record needs --expect-version");
354
+ }
355
+ if (version !== undefined && source !== "record") {
356
+ throw new ParseError("compare-look: --expect-version goes with --expect-source record");
357
+ }
358
+ if (version !== undefined && !/^[1-9][0-9]{0,9}$/.test(version)) {
359
+ throw new ParseError("compare-look: --expect-version must be a version number");
360
+ }
361
+ if (source !== undefined && parsed.values.capture !== undefined) {
362
+ throw new ParseError("compare-look: --expect-source goes with --against");
363
+ }
364
+ const help = parsed.values.help === true;
365
+ if (!help && parsed.values.origin === undefined)
366
+ throw new ParseError("compare-look: --origin is required");
367
+ return {
368
+ target,
369
+ origin: parsed.values.origin,
370
+ paths: parsed.values.path ?? [],
371
+ capture: parsed.values.capture,
372
+ against: parsed.values.against,
373
+ out: parsed.values.out,
374
+ tolerance,
375
+ expect: source === undefined ? undefined : { source, ...(version !== undefined && { version }) },
376
+ help,
377
+ };
378
+ }
package/dist/copy.js CHANGED
@@ -63,7 +63,7 @@ export function buildScaffoldMarkers(projectName) {
63
63
  // (`https://x.com/{{COMPANY_HANDLE}}`, #5469 D5) — a placeholder the
64
64
  // site owner replaces, never the kit vendor's own handle.
65
65
  COMPANY_HANDLE: "yourcompany",
66
- // Stamped into each DESIGN.md header so an installed scaffold records the
66
+ // Stamped into the overlay's design.yaml so an installed scaffold records the
67
67
  // create-ailk it was generated by (#6460).
68
68
  CREATE_AILK_VERSION,
69
69
  };
@@ -4,25 +4,24 @@
4
4
  *
5
5
  * `compileDesignTheme` is pure and idempotent: it reads `pkg` only, never
6
6
  * mutates it, and has no I/O. The authored→runtime key map is the single
7
- * exported table `DESIGN_COLOR_MAP` below — every lossy translation (a
8
- * runtime slot the authored quartet has no direct source for) is named as a
9
- * `fallback` + `lossy` case, and the cases with no row at all are named in
10
- * `DESIGN_COMPILE_LOSSY`.
7
+ * exported table `DESIGN_COLOR_MAP` below — every row direct, since a look
8
+ * carries both its sets in full (#12500 D1) — and the lossy cases, which
9
+ * have no row, are named in `DESIGN_COMPILE_LOSSY`.
11
10
  *
12
- * This module imports nothing from `@working-theory/site-config` — the
11
+ * This module imports nothing from `@working-theory/validation` — the
13
12
  * `theme:` block's shape is reproduced structurally here so `create-ailk`
14
13
  * gains no runtime dependency (§ 1.5); the cross-package read that proves
15
- * this compiles to what `SiteThemeSchema` accepts is test-only, by relative
14
+ * this compiles to what `compiledThemeSchema` accepts is test-only, by relative
16
15
  * path, in `design-compile.test.ts`.
17
16
  */
18
- import { type DesignPackage } from "./design-package.js";
17
+ import { type DesignColors, type DesignPackage } from "./design-package.js";
19
18
  /** The nine runtime colour slots this compile emits, per mode (D4). */
20
19
  export type RuntimeColorSlot = "bg" | "bgMuted" | "surface" | "border" | "text" | "textMuted" | "primary" | "primaryFg" | "accent";
21
- /** One mode's compiled palette — the shape `SiteThemeSchema`'s partial palette accepts. */
20
+ /** One mode's compiled palette — the shape `compiledThemeSchema`'s palette accepts. */
22
21
  export type CompiledColorPalette = {
23
22
  [K in RuntimeColorSlot]: string;
24
23
  };
25
- /** `compileDesignTheme`'s return shape — a `SiteThemeSchema`-valid `theme:` block. */
24
+ /** `compileDesignTheme`'s return shape — a `compiledThemeSchema`-valid `theme:` block. */
26
25
  export interface CompiledDesignTheme {
27
26
  corners?: "rounded" | "square";
28
27
  eyebrowCase?: "upper" | "sentence";
@@ -49,10 +48,12 @@ export interface CompiledDesignTheme {
49
48
  colors: {
50
49
  light: CompiledColorPalette;
51
50
  dark: CompiledColorPalette;
51
+ /** #12500 D2 — the band palette, present only when the package carries the band set. */
52
+ band?: CompiledColorPalette;
52
53
  };
53
54
  }
54
55
  /**
55
- * The compiled type roles (#7720, #7739 D2.2) — the shape `SiteThemeSchema`'s
56
+ * The compiled type roles (#7720, #7739 D2.2) — the shape `compiledThemeSchema`'s
56
57
  * `typography` accepts. Each role is present only when it carries a field.
57
58
  */
58
59
  export interface CompiledTypography {
@@ -94,23 +95,18 @@ export interface CompiledDesignFonts {
94
95
  display?: CompiledFace;
95
96
  body?: CompiledFace;
96
97
  }
97
- /** Every authored colour key the map may read from (design-package.ts D3). */
98
- type DesignAuthoredColorKey = "bg" | "fg" | "surface" | "surface-secondary" | "border" | "text-muted" | "brand" | "fg-on-brand" | "accent" | "bg-dark" | "fg-dark" | "border-dark" | "brand-dark" | "surface-dark" | "surface-secondary-dark" | "text-muted-dark" | "fg-on-brand-dark" | "accent-dark";
99
- /** The five named lossy cases with a row (D4) — an authored key absent falls back. */
100
- export type DesignColorMapLossyCase = "L1" | "L2" | "L3" | "L4" | "L5";
98
+ /** Every authored colour key of the light and dark sets (design-package.ts D3, #12500 D1). */
99
+ type DesignAuthoredColorKey = Exclude<keyof DesignColors, `${string}-band`>;
101
100
  export interface DesignColorMapRow {
102
101
  readonly mode: "light" | "dark";
103
102
  readonly runtime: RuntimeColorSlot;
104
103
  readonly authored: DesignAuthoredColorKey;
105
- readonly fallback?: DesignAuthoredColorKey;
106
- readonly lossy?: DesignColorMapLossyCase;
107
104
  }
108
105
  /**
109
106
  * The authored→runtime key map (D4) — 18 rows, one per emitted runtime slot
110
107
  * per mode, in the overlay block's key order (bg bgMuted surface border text
111
- * textMuted primary primaryFg accent). Light rows are 1:1; dark rows are
112
- * direct for bg/border/text/primary and fall back for the other five
113
- * (L1–L5), each named.
108
+ * textMuted primary primaryFg accent). Every row is direct (#12500 D1). The
109
+ * band palette (#12500 D2) reads the dark rows with `-dark` swapped for `-band`.
114
110
  */
115
111
  export declare const DESIGN_COLOR_MAP: readonly DesignColorMapRow[];
116
112
  /**
@@ -120,11 +116,11 @@ export declare const DESIGN_COLOR_MAP: readonly DesignColorMapRow[];
120
116
  */
121
117
  export declare const DESIGN_COMPILE_LOSSY: {
122
118
  readonly L6: "accentFg, destructive and destructiveFg have no authored source and are never emitted by this compile — the partial palette inherits the platform default.";
123
- readonly L7: "typography, rounded and spacing are carried in the package and not compiled — SiteThemeSchema rejects fonts/radius/spacing by name. Three exceptions: the display role's leading pair (lineHeight, lineHeightMobile) compiles into theme.typography.display when lineHeightMobile is declared (#7720); the display/body faces a fontSource names compile to apps/web/lib/site-fonts.ts (#7720); and under treatments.typeScale: design the display, heading-section, heading-item, body and eyebrow roles' sizes, phone sizes, weights and leadings compile into theme.typography (#7739) — never their families or letterSpacing.";
119
+ readonly L7: "typography, rounded and spacing are carried in the package and not compiled — compiledThemeSchema rejects fonts/radius/spacing by name. Three exceptions: the display role's leading pair (lineHeight, lineHeightMobile) compiles into theme.typography.display when lineHeightMobile is declared (#7720); the display/body faces a fontSource names compile to apps/web/lib/site-fonts.ts (#7720); and under treatments.typeScale: design the display, heading-section, heading-item, body and eyebrow roles' sizes, phone sizes, weights and leadings compile into theme.typography (#7739) — never their families or letterSpacing.";
124
120
  readonly L8: "an absent treatments key is omitted from the compiled theme block, not defaulted.";
125
121
  };
126
122
  /**
127
- * Translate a `DesignPackage` into the `theme:` block `SiteThemeSchema.parse`
123
+ * Translate a `DesignPackage` into the `theme:` block `compiledThemeSchema.parse`
128
124
  * accepts (D4). Pure and idempotent — reads `pkg` only, mutates nothing, and
129
125
  * performs no I/O.
130
126
  */
@@ -4,15 +4,14 @@
4
4
  *
5
5
  * `compileDesignTheme` is pure and idempotent: it reads `pkg` only, never
6
6
  * mutates it, and has no I/O. The authored→runtime key map is the single
7
- * exported table `DESIGN_COLOR_MAP` below — every lossy translation (a
8
- * runtime slot the authored quartet has no direct source for) is named as a
9
- * `fallback` + `lossy` case, and the cases with no row at all are named in
10
- * `DESIGN_COMPILE_LOSSY`.
7
+ * exported table `DESIGN_COLOR_MAP` below — every row direct, since a look
8
+ * carries both its sets in full (#12500 D1) — and the lossy cases, which
9
+ * have no row, are named in `DESIGN_COMPILE_LOSSY`.
11
10
  *
12
- * This module imports nothing from `@working-theory/site-config` — the
11
+ * This module imports nothing from `@working-theory/validation` — the
13
12
  * `theme:` block's shape is reproduced structurally here so `create-ailk`
14
13
  * gains no runtime dependency (§ 1.5); the cross-package read that proves
15
- * this compiles to what `SiteThemeSchema` accepts is test-only, by relative
14
+ * this compiles to what `compiledThemeSchema` accepts is test-only, by relative
16
15
  * path, in `design-compile.test.ts`.
17
16
  */
18
17
  import { unquoteFamily } from "./design-package.js";
@@ -30,9 +29,8 @@ const COMPILED_TYPE_FIELDS = {
30
29
  /**
31
30
  * The authored→runtime key map (D4) — 18 rows, one per emitted runtime slot
32
31
  * per mode, in the overlay block's key order (bg bgMuted surface border text
33
- * textMuted primary primaryFg accent). Light rows are 1:1; dark rows are
34
- * direct for bg/border/text/primary and fall back for the other five
35
- * (L1–L5), each named.
32
+ * textMuted primary primaryFg accent). Every row is direct (#12500 D1). The
33
+ * band palette (#12500 D2) reads the dark rows with `-dark` swapped for `-band`.
36
34
  */
37
35
  export const DESIGN_COLOR_MAP = [
38
36
  { mode: "light", runtime: "bg", authored: "bg" },
@@ -45,44 +43,14 @@ export const DESIGN_COLOR_MAP = [
45
43
  { mode: "light", runtime: "primaryFg", authored: "fg-on-brand" },
46
44
  { mode: "light", runtime: "accent", authored: "accent" },
47
45
  { mode: "dark", runtime: "bg", authored: "bg-dark" },
48
- {
49
- mode: "dark",
50
- runtime: "bgMuted",
51
- authored: "surface-secondary-dark",
52
- fallback: "bg-dark",
53
- lossy: "L1",
54
- },
55
- {
56
- mode: "dark",
57
- runtime: "surface",
58
- authored: "surface-dark",
59
- fallback: "bg-dark",
60
- lossy: "L2",
61
- },
46
+ { mode: "dark", runtime: "bgMuted", authored: "surface-secondary-dark" },
47
+ { mode: "dark", runtime: "surface", authored: "surface-dark" },
62
48
  { mode: "dark", runtime: "border", authored: "border-dark" },
63
49
  { mode: "dark", runtime: "text", authored: "fg-dark" },
64
- {
65
- mode: "dark",
66
- runtime: "textMuted",
67
- authored: "text-muted-dark",
68
- fallback: "fg-dark",
69
- lossy: "L3",
70
- },
50
+ { mode: "dark", runtime: "textMuted", authored: "text-muted-dark" },
71
51
  { mode: "dark", runtime: "primary", authored: "brand-dark" },
72
- {
73
- mode: "dark",
74
- runtime: "primaryFg",
75
- authored: "fg-on-brand-dark",
76
- fallback: "bg-dark",
77
- lossy: "L4",
78
- },
79
- {
80
- mode: "dark",
81
- runtime: "accent",
82
- authored: "accent-dark",
83
- fallback: "brand-dark",
84
- lossy: "L5",
85
- },
52
+ { mode: "dark", runtime: "primaryFg", authored: "fg-on-brand-dark" },
53
+ { mode: "dark", runtime: "accent", authored: "accent-dark" },
86
54
  ];
87
55
  /**
88
56
  * The lossy cases with no row in `DESIGN_COLOR_MAP` (D4): a runtime slot
@@ -91,7 +59,7 @@ export const DESIGN_COLOR_MAP = [
91
59
  */
92
60
  export const DESIGN_COMPILE_LOSSY = {
93
61
  L6: "accentFg, destructive and destructiveFg have no authored source and are never emitted by this compile — the partial palette inherits the platform default.",
94
- L7: "typography, rounded and spacing are carried in the package and not compiled — SiteThemeSchema rejects fonts/radius/spacing by name. Three exceptions: the display role's leading pair (lineHeight, lineHeightMobile) compiles into theme.typography.display when lineHeightMobile is declared (#7720); the display/body faces a fontSource names compile to apps/web/lib/site-fonts.ts (#7720); and under treatments.typeScale: design the display, heading-section, heading-item, body and eyebrow roles' sizes, phone sizes, weights and leadings compile into theme.typography (#7739) — never their families or letterSpacing.",
62
+ L7: "typography, rounded and spacing are carried in the package and not compiled — compiledThemeSchema rejects fonts/radius/spacing by name. Three exceptions: the display role's leading pair (lineHeight, lineHeightMobile) compiles into theme.typography.display when lineHeightMobile is declared (#7720); the display/body faces a fontSource names compile to apps/web/lib/site-fonts.ts (#7720); and under treatments.typeScale: design the display, heading-section, heading-item, body and eyebrow roles' sizes, phone sizes, weights and leadings compile into theme.typography (#7739) — never their families or letterSpacing.",
95
63
  L8: "an absent treatments key is omitted from the compiled theme block, not defaulted.",
96
64
  };
97
65
  /** Whether a package names the `solid-dark` surface — in its deck grounds or any section preset (#7719 D6). */
@@ -132,7 +100,7 @@ function compileTypography(pkg) {
132
100
  };
133
101
  }
134
102
  /**
135
- * Translate a `DesignPackage` into the `theme:` block `SiteThemeSchema.parse`
103
+ * Translate a `DesignPackage` into the `theme:` block `compiledThemeSchema.parse`
136
104
  * accepts (D4). Pure and idempotent — reads `pkg` only, mutates nothing, and
137
105
  * performs no I/O.
138
106
  */
@@ -140,18 +108,26 @@ export function compileDesignTheme(pkg) {
140
108
  const colors = pkg.colors;
141
109
  const light = {};
142
110
  const dark = {};
111
+ const band = {};
112
+ // #12500 D2 — the reader takes the band set whole or not at all.
113
+ const hasBand = colors["bg-band"] !== undefined;
114
+ // Every `authored` name in DESIGN_COLOR_MAP is one of the 18 required colour
115
+ // keys (design-package.ts, #12500 D1), so `readDesignPackage` guarantees
116
+ // these reads never miss. A miss means that invariant broke — fail loudly
117
+ // rather than silently writing `undefined` into a `string` runtime slot.
118
+ const read = (key, slot) => {
119
+ const value = colors[key];
120
+ if (value === undefined) {
121
+ throw new Error(`compileDesignTheme: no colour value for ${slot} (authored "${key}")`);
122
+ }
123
+ return value;
124
+ };
143
125
  for (const row of DESIGN_COLOR_MAP) {
144
126
  const target = row.mode === "light" ? light : dark;
145
- const value = colors[row.authored] ?? (row.fallback !== undefined ? colors[row.fallback] : undefined);
146
- if (value === undefined) {
147
- // Every `authored`/`fallback` name in DESIGN_COLOR_MAP that can be
148
- // reached with no fallback names one of the 13 REQUIRED colour keys
149
- // (design-package.ts D3), so `readDesignPackage` guarantees this read
150
- // never misses. A miss means that invariant broke — fail loudly rather
151
- // than silently writing `undefined` into a `string` runtime slot.
152
- throw new Error(`compileDesignTheme: no colour value for ${row.mode}.${row.runtime} (authored "${row.authored}"${row.fallback !== undefined ? `, fallback "${row.fallback}"` : ""})`);
127
+ target[row.runtime] = read(row.authored, `${row.mode}.${row.runtime}`);
128
+ if (row.mode === "dark" && hasBand) {
129
+ band[row.runtime] = read(row.authored.replace(/-dark$/, "-band"), `band.${row.runtime}`);
153
130
  }
154
- target[row.runtime] = value;
155
131
  }
156
132
  const treatments = pkg.treatments ?? {};
157
133
  const typography = compileTypography(pkg);
@@ -168,7 +144,7 @@ export function compileDesignTheme(pkg) {
168
144
  ...(treatments.figures !== undefined && { figures: treatments.figures }),
169
145
  ...(typography !== undefined && { typography }),
170
146
  ...(darkBands && { darkBands: "site" }),
171
- colors: { light, dark },
147
+ colors: { light, dark, ...(hasBand && { band }) },
172
148
  };
173
149
  }
174
150
  /**