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.
Files changed (144) 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 +5 -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 +29 -4
  98. package/templates/apps/api/CLAUDE.md +7 -4
  99. package/templates/apps/api/src/__tests__/vercel-handler.test.ts +176 -2
  100. package/templates/apps/api/src/lib/__mocks__/prisma.ts +30 -4
  101. package/templates/apps/api/src/vercel-handler.ts +32 -2
  102. package/templates/apps/mcp/.env.example +8 -0
  103. package/templates/apps/mcp/CLAUDE.md +5 -3
  104. package/templates/apps/web/.env.example +10 -3
  105. package/templates/apps/web/CLAUDE.md +31 -4
  106. package/templates/apps/web/app/[locale]/layout.tsx +141 -77
  107. package/templates/apps/web/app/llms.txt/__tests__/site-listing.test.ts +13 -3
  108. package/templates/apps/web/app/not-found.tsx +11 -11
  109. package/templates/apps/web/auth.ts +48 -35
  110. package/templates/apps/web/jest.config.cjs +5 -0
  111. package/templates/apps/web/lib/__tests__/hub-site-config.test.ts +542 -10
  112. package/templates/apps/web/lib/__tests__/library-fonts.test.ts +35 -0
  113. package/templates/apps/web/lib/__tests__/page-chrome-navigation.test.ts +233 -0
  114. package/templates/apps/web/lib/__tests__/page-chrome.test.ts +123 -26
  115. package/templates/apps/web/lib/__tests__/section-look.test.ts +150 -0
  116. package/templates/apps/web/lib/__tests__/site-identity-feature-list.test.ts +19 -1
  117. package/templates/apps/web/lib/__tests__/site-navigation.test.ts +288 -0
  118. package/templates/apps/web/lib/__tests__/site-theme.test.ts +81 -289
  119. package/templates/apps/web/lib/deck-page.ts +3 -10
  120. package/templates/apps/web/lib/deploy-fonts.ts +12 -0
  121. package/templates/apps/web/lib/hub-site-config.ts +237 -29
  122. package/templates/apps/web/lib/library-fonts.ts +41 -0
  123. package/templates/apps/web/lib/mcp-oauth.ts +11 -4
  124. package/templates/apps/web/lib/page-chrome.ts +105 -20
  125. package/templates/apps/web/lib/section-look.ts +28 -0
  126. package/templates/apps/web/lib/site-design.ts +205 -0
  127. package/templates/apps/web/lib/site-navigation.ts +208 -0
  128. package/templates/apps/web/lib/site-theme-head.ts +98 -13
  129. package/templates/apps/web/lib/site-theme.ts +40 -62
  130. package/templates/apps/web/messages/en.json +0 -6
  131. package/templates/apps/web/next.config.mjs +213 -11
  132. package/templates/apps/web/package.json +2 -0
  133. package/templates/apps/web/site-pages.config.tsx +4 -2
  134. package/templates/content/_site.mdx +0 -26
  135. package/templates/design.yaml +75 -0
  136. package/templates/project.yaml +14 -0
  137. package/versions.json +52 -51
  138. package/site-templates/marketing-site/DESIGN.md +0 -259
  139. package/site-templates/marketing-site-free/DESIGN.md +0 -259
  140. package/site-templates/saas-product/DESIGN.md +0 -259
  141. package/templates/apps/web/lib/__tests__/deck-page.test.ts +0 -288
  142. package/templates/apps/web/lib/__tests__/site-theme-head.test.ts +0 -70
  143. package/templates/apps/web/lib/site-chrome.ts +0 -46
  144. package/templates/apps/web/lib/site-fonts.ts +0 -15
@@ -1,14 +1,14 @@
1
1
  /**
2
2
  * The design package (#6812, spec docs/specs/6812-the-design-package-design-md-spec.md
3
- * D1/D2/D3/D5): a design is read from ONE file, `<dir>/DESIGN.md`, whose
4
- * frontmatter is its whole authored schema.
3
+ * D1/D2/D3/D5): a design is read from ONE file, `<dir>/design.yaml` (#12468 —
4
+ * the YAML its DESIGN.md header once held, renamed), which is its whole
5
+ * authored schema.
5
6
  *
6
- * The dials decision: a design's authored data is its DESIGN.md frontmatter alone
7
- * (Sam Henry, 2026-09-26, rel-023 plan §8). There is no separate dial file;
8
- * the Markdown body is generated from the frontmatter in marked regions
9
- * (`scripts/build-design-md.mjs`).
7
+ * The dials decision: a design's authored data is that one file alone
8
+ * (Sam Henry, 2026-09-26, rel-023 plan §8). A `DESIGN.md` beside it is
9
+ * impeccable's guide to the design, never read here (#12468).
10
10
  *
11
- * `readDesignPackage` parses the frontmatter with a dependency-free subset of
11
+ * `readDesignPackage` parses `design.yaml` with a dependency-free subset of
12
12
  * YAML 1.2 (D5) — `create-ailk` ships exactly one runtime dependency (`tar`,
13
13
  * § 1.5), and this reader runs at scaffold time, so it cannot import the
14
14
  * `yaml` package used elsewhere in this repo's build scripts. The subset
@@ -18,63 +18,15 @@
18
18
  */
19
19
  import { existsSync, readFileSync } from "node:fs";
20
20
  import { join } from "node:path";
21
- import { TemplateLayoutError, validateTemplateLayout, } from "./site-chrome.js";
21
+ import { BREAK_OR_CONTROL_REGEX, BUTTON_SHAPE_VALUES, CHECKMARKS_VALUES, COLOR_KEYS_BAND, COLOR_KEYS_DARK, COLOR_KEYS_LIGHT, COLOR_VALUE_REGEX, COMPILED_TYPE_ROLES, COPY_DENSITY_VALUES, CORNERS_VALUES, CSS_LENGTH_REGEX, DARK_INK_VALUES, DESCRIPTION_MAX, DIAL_MAP_MAX, DIAL_NAME_REGEX, EYEBROW_CASE_VALUES, FIGURES_VALUES, FONT_FAMILY_REGEX, FONT_SIZE_MOBILE_ROLES, FONT_SOURCE_ROLES, FONT_SOURCE_VALUES, FONT_STACK_LENGTH_MAX, FONT_STACK_MAX, GOOGLE_FAMILY_REGEX, GROUND_HEX_REGEX, LAYOUT_OPTIONAL_KEYS, LAYOUT_REQUIRED_KEYS, LINE_HEIGHT_MOBILE_ROLES, LOOK_FIELDS_PER_SECTION_MAX, NAME_MAX, PLACEHOLDERS_VALUES, SECTION_NAME_REGEX, SECTION_PAGE_TYPES, SECTION_PAGE_TYPES_MAX, SECTION_TOKEN_REGEX, SECTIONS_PER_PAGE_MAX, SETTINGS_KEYS, SETTINGS_REQUIRED_KEYS, SETTINGS_VERSION_MAX, TYPE_SCALE_VALUES, TYPE_SIZE_REGEX, TYPOGRAPHY_ROLE_KEYS, TYPOGRAPHY_ROLES_MAX, } from "./generated/design-settings.js";
22
+ import { RETIRED_LAYOUT_KEYS, TemplateLayoutError, validateTemplateLayout, } from "./site-chrome.js";
22
23
  // ── Public types ─────────────────────────────────────────────────────────────
23
- /** The closed colour key set (D3) — 13 required, 5 optional dark fallbacks. */
24
- export const DESIGN_COLOR_KEYS_REQUIRED = [
25
- "bg",
26
- "fg",
27
- "surface",
28
- "surface-secondary",
29
- "border",
30
- "text-muted",
31
- "brand",
32
- "fg-on-brand",
33
- "accent",
34
- "bg-dark",
35
- "fg-dark",
36
- "border-dark",
37
- "brand-dark",
38
- ];
39
- export const DESIGN_COLOR_KEYS_OPTIONAL = [
40
- "surface-dark",
41
- "surface-secondary-dark",
42
- "text-muted-dark",
43
- "fg-on-brand-dark",
44
- "accent-dark",
45
- ];
46
- /** Duplicated from `SiteThemeSchema`'s colour regex (D3) — proven equal by test. */
47
- export const DESIGN_COLOR_REGEX = /^(#([0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})|rgb\(.+\)|rgba\(.+\)|hsl\(.+\)|hsla\(.+\)|var\(--[^)]+\))$/;
48
- /** The closed font-source enum (#7720 D1) — a Google Fonts family, self-hosted at build by next/font. */
49
- export const DESIGN_FONT_SOURCE_VALUES = ["google"];
50
- /** Duplicated from site-config's `FONT_FAMILY_REGEX` (#7720 D1) — proven equal by test. */
51
- export const DESIGN_FONT_STACK_ENTRY_REGEX = /^(?:[A-Za-z0-9 ._-]+|'[A-Za-z0-9 ._-]+'|"[A-Za-z0-9 ._-]+")$/;
52
- /**
53
- * #7739 D1.3 — a type size a `typeScale: design` package compiles: a plain
54
- * length in rem, px or em. Duplicated from site-config's `TYPE_SIZE_REGEX` —
55
- * proven equal by test.
56
- */
57
- export const DESIGN_TYPE_SIZE_REGEX = /^(?:\d+|\d*\.\d+)(?:rem|px|em)$/;
58
- /** Duplicated from `SiteThemeSchema`'s enums (D3) — proven equal by test. */
59
- export const DESIGN_CORNERS_VALUES = ["rounded", "square"];
60
- export const DESIGN_EYEBROW_CASE_VALUES = ["upper", "sentence"];
61
- export const DESIGN_PLACEHOLDERS_VALUES = ["outline", "fill"];
62
- export const DESIGN_CHECKMARKS_VALUES = ["circle", "plain"];
63
- /** #7741 D7 — the button shape. */
64
- export const DESIGN_BUTTON_SHAPE_VALUES = ["control", "pill"];
65
- export const DESIGN_DARK_INK_VALUES = ["fg", "accent"];
66
- export const DESIGN_FIGURES_VALUES = ["platform", "display"];
67
- /**
68
- * #7739 D1 — whether the compile writes the design's own type roles into the
69
- * theme. A compile instruction, not a runtime setting: never written into `theme:`.
70
- */
71
- export const DESIGN_TYPE_SCALE_VALUES = ["platform", "design"];
72
- /** The closed copy-density enum (spec 6892 D4). */
73
- export const DESIGN_COPY_DENSITY_VALUES = ["standard", "sparse"];
24
+ /** A look's light set of colour keys, under the name `update.ts` imports — the generated list, not a copy. */
25
+ export { COLOR_KEYS_LIGHT as DESIGN_COLOR_KEYS_LIGHT } from "./generated/design-settings.js";
74
26
  /**
75
27
  * Thrown by `readDesignPackage` on any malformed package (D2) — never thrown
76
28
  * after a write; every refusal happens before any I/O beyond reading
77
- * `DESIGN.md` itself.
29
+ * `design.yaml` itself.
78
30
  */
79
31
  export class DesignPackageError extends Error {
80
32
  file;
@@ -86,13 +38,16 @@ export class DesignPackageError extends Error {
86
38
  this.field = field;
87
39
  }
88
40
  }
41
+ // ── The YAML-subset parser (D5) ─────────────────────────────────────────────
42
+ /** A design's one settings file (#12468). */
43
+ const SETTINGS_FILE = "design.yaml";
89
44
  function refuse(file, field, reason) {
90
45
  throw new DesignPackageError(file, field, reason);
91
46
  }
92
- function refuseFrontmatter(file, lineNo, reason) {
93
- refuse(file, "frontmatter", `line ${lineNo}: ${reason}`);
47
+ function refuseLine(file, lineNo, reason) {
48
+ refuse(file, SETTINGS_FILE, `line ${lineNo}: ${reason}`);
94
49
  }
95
- /** Split frontmatter text into significant lines, refusing tabs as we go. */
50
+ /** Split settings text into significant lines, refusing tabs as we go. */
96
51
  function toSignificantLines(text, file) {
97
52
  const lines = [];
98
53
  const rawLines = text.split("\n");
@@ -100,9 +55,9 @@ function toSignificantLines(text, file) {
100
55
  const lineNo = i + 1;
101
56
  const raw = rawLines[i] ?? "";
102
57
  if (raw.includes("\t")) {
103
- refuseFrontmatter(file, lineNo, "tabs are not allowed");
58
+ refuseLine(file, lineNo, "tabs are not allowed");
104
59
  }
105
- const trimmed = raw.replace(/\s+$/, "");
60
+ const trimmed = raw.trimEnd();
106
61
  if (trimmed === "")
107
62
  continue;
108
63
  const indent = /^ */.exec(trimmed)[0].length;
@@ -114,10 +69,12 @@ function toSignificantLines(text, file) {
114
69
  return lines;
115
70
  }
116
71
  const KEY_RE = /^([A-Za-z0-9_-]+):(.*)$/;
72
+ /** Keys that could name a prototype — refused at any depth (#12468 SEC-12468-5), as `update.ts`'s `UNSAFE_KEYS`. */
73
+ const PROTOTYPE_KEYS = new Set(["__proto__", "constructor", "prototype"]);
117
74
  function parseDoubleQuoted(raw, lineNo, file) {
118
75
  const m = /^"((?:\\.|[^"\\])*)"$/.exec(raw);
119
76
  if (!m) {
120
- refuseFrontmatter(file, lineNo, "unterminated or malformed double-quoted string");
77
+ refuseLine(file, lineNo, "unterminated or malformed double-quoted string");
121
78
  }
122
79
  const body = m[1] ?? "";
123
80
  let result = "";
@@ -130,7 +87,7 @@ function parseDoubleQuoted(raw, lineNo, file) {
130
87
  i += 1;
131
88
  }
132
89
  else {
133
- refuseFrontmatter(file, lineNo, `unsupported escape "\\${next ?? ""}"`);
90
+ refuseLine(file, lineNo, `unsupported escape "\\${next ?? ""}"`);
134
91
  }
135
92
  }
136
93
  else {
@@ -142,7 +99,7 @@ function parseDoubleQuoted(raw, lineNo, file) {
142
99
  function parseSingleQuoted(raw, lineNo, file) {
143
100
  const m = /^'((?:''|[^'])*)'$/.exec(raw);
144
101
  if (!m) {
145
- refuseFrontmatter(file, lineNo, "unterminated or malformed single-quoted string");
102
+ refuseLine(file, lineNo, "unterminated or malformed single-quoted string");
146
103
  }
147
104
  return (m[1] ?? "").replace(/''/g, "'");
148
105
  }
@@ -157,39 +114,39 @@ const LEADING_ZERO_INT_RE = /^-?0[0-9]+$/;
157
114
  const LEADING_DOT_FLOAT_RE = /^[+-]?\.[0-9]+$/;
158
115
  function parsePlainScalar(raw, lineNo, file) {
159
116
  if (raw.includes(": ") || raw.includes(" #") || raw.startsWith("#")) {
160
- refuseFrontmatter(file, lineNo, 'a plain scalar must not contain ": " or " #"');
117
+ refuseLine(file, lineNo, 'a plain scalar must not contain ": " or " #"');
161
118
  }
162
119
  if (raw === "true")
163
120
  return true;
164
121
  if (raw === "false")
165
122
  return false;
166
123
  if (RESERVED_BOOLEAN_CASE_RE.test(raw)) {
167
- refuseFrontmatter(file, lineNo, `"${raw}" is a reserved boolean literal — use lowercase true/false, or quote it`);
124
+ refuseLine(file, lineNo, `"${raw}" is a reserved boolean literal — use lowercase true/false, or quote it`);
168
125
  }
169
126
  if (RESERVED_NULL_RE.test(raw)) {
170
- refuseFrontmatter(file, lineNo, `"${raw}" is a reserved null literal — quote it if a string is meant`);
127
+ refuseLine(file, lineNo, `"${raw}" is a reserved null literal — quote it if a string is meant`);
171
128
  }
172
129
  if (RESERVED_INF_NAN_RE.test(raw)) {
173
- refuseFrontmatter(file, lineNo, `"${raw}" is a reserved inf/nan literal — quote it if a string is meant`);
130
+ refuseLine(file, lineNo, `"${raw}" is a reserved inf/nan literal — quote it if a string is meant`);
174
131
  }
175
132
  if (HEX_OCTAL_RE.test(raw)) {
176
- refuseFrontmatter(file, lineNo, `"${raw}" is a hex/octal literal, not supported — quote it if a string is meant`);
133
+ refuseLine(file, lineNo, `"${raw}" is a hex/octal literal, not supported — quote it if a string is meant`);
177
134
  }
178
135
  if (raw.startsWith("+")) {
179
- refuseFrontmatter(file, lineNo, `"${raw}" has a leading "+", not supported — quote it if a string is meant`);
136
+ refuseLine(file, lineNo, `"${raw}" has a leading "+", not supported — quote it if a string is meant`);
180
137
  }
181
138
  if (INT_RE.test(raw))
182
139
  return Number(raw);
183
140
  if (FLOAT_RE.test(raw))
184
141
  return Number(raw);
185
142
  if (EXPONENT_RE.test(raw)) {
186
- refuseFrontmatter(file, lineNo, `"${raw}" is an exponent-form number, not supported — quote it if a string is meant`);
143
+ refuseLine(file, lineNo, `"${raw}" is an exponent-form number, not supported — quote it if a string is meant`);
187
144
  }
188
145
  if (LEADING_ZERO_INT_RE.test(raw)) {
189
- refuseFrontmatter(file, lineNo, `"${raw}" is a leading-zero integer, not supported — quote it if a string is meant`);
146
+ refuseLine(file, lineNo, `"${raw}" is a leading-zero integer, not supported — quote it if a string is meant`);
190
147
  }
191
148
  if (LEADING_DOT_FLOAT_RE.test(raw)) {
192
- refuseFrontmatter(file, lineNo, `"${raw}" is a bare leading-dot float, not supported — quote it, or add a leading 0 before the "."`);
149
+ refuseLine(file, lineNo, `"${raw}" is a bare leading-dot float, not supported — quote it, or add a leading 0 before the "."`);
193
150
  }
194
151
  return raw;
195
152
  }
@@ -199,7 +156,7 @@ function parseScalar(raw, lineNo, file) {
199
156
  if (raw.startsWith("'"))
200
157
  return parseSingleQuoted(raw, lineNo, file);
201
158
  if (/^[[{&*!|>]/.test(raw)) {
202
- refuseFrontmatter(file, lineNo, "flow collections, anchors, aliases, tags and block scalars are not supported");
159
+ refuseLine(file, lineNo, "flow collections, anchors, aliases, tags and block scalars are not supported");
203
160
  }
204
161
  return parsePlainScalar(raw, lineNo, file);
205
162
  }
@@ -221,23 +178,23 @@ function parseScalarSequence(lines, pos, file) {
221
178
  while (pos.i < lines.length && lines[pos.i].indent >= itemIndent) {
222
179
  const line = lines[pos.i];
223
180
  if (line.indent > itemIndent) {
224
- refuseFrontmatter(file, line.lineNo, "a sequence item must be a single scalar — nested blocks are not supported");
181
+ refuseLine(file, line.lineNo, "a sequence item must be a single scalar — nested blocks are not supported");
225
182
  }
226
183
  if (line.content === "-") {
227
- refuseFrontmatter(file, line.lineNo, "a sequence item has no value");
184
+ refuseLine(file, line.lineNo, "a sequence item has no value");
228
185
  }
229
186
  if (!line.content.startsWith("- ")) {
230
- refuseFrontmatter(file, line.lineNo, `expected a "- " sequence item, got "${line.content}"`);
187
+ refuseLine(file, line.lineNo, `expected a "- " sequence item, got "${line.content}"`);
231
188
  }
232
189
  const raw = line.content.slice(2);
233
190
  if (raw === "" || raw.startsWith(" ")) {
234
- refuseFrontmatter(file, line.lineNo, 'expected a single space after "-"');
191
+ refuseLine(file, line.lineNo, 'expected a single space after "-"');
235
192
  }
236
193
  if (raw === "-" || raw.startsWith("- ") || raw === "?" || raw.startsWith("? ")) {
237
- refuseFrontmatter(file, line.lineNo, "a sequence item must be a scalar — nested collections are not supported");
194
+ refuseLine(file, line.lineNo, "a sequence item must be a scalar — nested collections are not supported");
238
195
  }
239
196
  if (!/^["']/.test(raw) && raw.endsWith(":")) {
240
- refuseFrontmatter(file, line.lineNo, "a sequence item must be a scalar — mappings are not supported");
197
+ refuseLine(file, line.lineNo, "a sequence item must be a scalar — mappings are not supported");
241
198
  }
242
199
  items.push(parseScalar(raw, line.lineNo, file));
243
200
  pos.i += 1;
@@ -253,16 +210,19 @@ function parseMapping(lines, pos, indent, file, path) {
253
210
  while (pos.i < lines.length && lines[pos.i].indent === indent) {
254
211
  const line = lines[pos.i];
255
212
  if (line.content === "-" || line.content.startsWith("- ")) {
256
- refuseFrontmatter(file, line.lineNo, "sequences are not supported");
213
+ refuseLine(file, line.lineNo, "sequences are not supported");
257
214
  }
258
215
  const m = KEY_RE.exec(line.content);
259
216
  if (!m) {
260
- refuseFrontmatter(file, line.lineNo, `expected "key: value", got "${line.content}"`);
217
+ refuseLine(file, line.lineNo, `expected "key: value", got "${line.content}"`);
261
218
  }
262
219
  const key = m[1];
263
220
  const rawRest = m[2];
221
+ if (PROTOTYPE_KEYS.has(key)) {
222
+ refuseLine(file, line.lineNo, `key "${key}" is not allowed`);
223
+ }
264
224
  if (Object.hasOwn(result, key)) {
265
- refuseFrontmatter(file, line.lineNo, `duplicate key "${key}"`);
225
+ refuseLine(file, line.lineNo, `duplicate key "${key}"`);
266
226
  }
267
227
  pos.i += 1;
268
228
  const keyPath = path === "" ? key : `${path}.${key}`;
@@ -277,50 +237,64 @@ function parseMapping(lines, pos, indent, file, path) {
277
237
  }
278
238
  if (next !== undefined && next.indent > indent) {
279
239
  if (next.indent !== indent + 2) {
280
- refuseFrontmatter(file, next.lineNo, `bad indentation — expected ${indent + 2} spaces, got ${next.indent}`);
240
+ refuseLine(file, next.lineNo, `bad indentation — expected ${indent + 2} spaces, got ${next.indent}`);
281
241
  }
282
242
  result[key] = parseMapping(lines, pos, next.indent, file, keyPath);
283
243
  }
284
244
  else {
285
- refuseFrontmatter(file, line.lineNo, `"${key}" has an empty value`);
245
+ refuseLine(file, line.lineNo, `"${key}" has an empty value`);
286
246
  }
287
247
  continue;
288
248
  }
289
249
  if (!rawRest.startsWith(" ")) {
290
- refuseFrontmatter(file, line.lineNo, 'expected a single space after ":"');
250
+ refuseLine(file, line.lineNo, 'expected a single space after ":"');
291
251
  }
292
252
  const rest = rawRest.slice(1);
293
253
  if (rest === "" || rest.startsWith(" ")) {
294
- refuseFrontmatter(file, line.lineNo, `"${key}" has an empty value`);
254
+ refuseLine(file, line.lineNo, `"${key}" has an empty value`);
295
255
  }
296
256
  result[key] = parseScalar(rest, line.lineNo, file);
297
257
  const next = lines[pos.i];
298
258
  if (next !== undefined && next.indent > indent) {
299
- refuseFrontmatter(file, next.lineNo, `unexpected indentation after "${key}"'s scalar value`);
259
+ refuseLine(file, next.lineNo, `unexpected indentation after "${key}"'s scalar value`);
300
260
  }
301
261
  }
302
262
  return result;
303
263
  }
304
- /** Parse `<dir>/DESIGN.md`'s frontmatter into a plain object tree (D5). */
305
- function parseFrontmatter(text, file) {
306
- const m = /^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n[\s\S]*)?$/.exec(text);
307
- if (!m) {
308
- refuse(file, "frontmatter", "no closing --- found");
264
+ /**
265
+ * Parse `<dir>/design.yaml` — a bare YAML mapping — into a plain object tree
266
+ * (D5), with every refusal this reader's subset makes. `update` also reads a
267
+ * `theme:` block create-ailk wrote through it (#12500 D7).
268
+ */
269
+ export function parseSettings(text, file) {
270
+ const first = text.split("\n").map((line) => line.trim()).find((line) => line !== "" && !line.startsWith("#"));
271
+ if (first === "---") {
272
+ refuse(file, SETTINGS_FILE, "holds Markdown frontmatter — design.yaml is the bare YAML mapping");
309
273
  }
310
- const lines = toSignificantLines(m[1] ?? "", file);
274
+ const lines = toSignificantLines(text, file);
311
275
  const pos = { i: 0 };
312
276
  const result = parseMapping(lines, pos, 0, file, "");
313
277
  if (pos.i < lines.length) {
314
278
  const stray = lines[pos.i];
315
- refuseFrontmatter(file, stray.lineNo, "unexpected indentation at the top level");
279
+ refuseLine(file, stray.lineNo, "unexpected indentation at the top level");
316
280
  }
317
281
  return result;
318
282
  }
319
283
  // ── Group validators (D2/D3) ────────────────────────────────────────────────
320
- function requireString(value, file, field) {
284
+ //
285
+ // Every list, grammar and bound below is read from `generated/design-settings.ts`,
286
+ // which is generated from `@working-theory/validation`'s `designSettingsSchema`
287
+ // (#12470 D1): this reader and that schema accept and refuse the same files,
288
+ // naming the same field (`design-settings-schema.test.ts`).
289
+ function requireText(value, file, field, max) {
321
290
  if (typeof value !== "string" || value.length === 0) {
322
291
  refuse(file, field, "must be a non-empty string");
323
292
  }
293
+ if (value.length > max)
294
+ refuse(file, field, `must be at most ${max} characters`);
295
+ if (BREAK_OR_CONTROL_REGEX.test(value)) {
296
+ refuse(file, field, "must be one line: no control, line-break or direction-override character");
297
+ }
324
298
  return value;
325
299
  }
326
300
  function requireObject(value, file, field) {
@@ -329,73 +303,93 @@ function requireObject(value, file, field) {
329
303
  }
330
304
  return value;
331
305
  }
306
+ function isOneOf(values, value) {
307
+ return typeof value === "string" && values.includes(value);
308
+ }
309
+ /** A map's keys against a name grammar and its size against its bounds. */
310
+ function requireNamedMap(raw, file, field, name, min, max) {
311
+ const obj = requireObject(raw, file, field);
312
+ for (const key of Object.keys(obj)) {
313
+ if (!name.test(key))
314
+ refuse(file, `${field}.${key}`, `is not a name matching ${name.source}`);
315
+ }
316
+ const size = Object.keys(obj).length;
317
+ if (size < min || size > max) {
318
+ refuse(file, field, min === 0 ? `must hold at most ${max} entries` : `must hold ${min} to ${max} entries`);
319
+ }
320
+ return obj;
321
+ }
332
322
  function validateColors(raw, file) {
333
323
  const obj = requireObject(raw, file, "colors");
334
- const allowed = new Set([...DESIGN_COLOR_KEYS_REQUIRED, ...DESIGN_COLOR_KEYS_OPTIONAL]);
324
+ const required = [...COLOR_KEYS_LIGHT, ...COLOR_KEYS_DARK];
325
+ const allowed = new Set([...required, ...COLOR_KEYS_BAND]);
335
326
  for (const key of Object.keys(obj)) {
336
327
  if (!allowed.has(key)) {
337
328
  refuse(file, `colors.${key}`, "is not a recognized colour key");
338
329
  }
339
330
  }
340
- for (const key of DESIGN_COLOR_KEYS_REQUIRED) {
341
- if (!(key in obj)) {
342
- refuse(file, `colors.${key}`, "is required");
331
+ for (const key of required) {
332
+ if (!Object.hasOwn(obj, key)) {
333
+ refuse(file, `colors.${key}`, "is required — every look has a light and a dark version (#12500)");
343
334
  }
344
335
  }
345
336
  const result = {};
346
337
  for (const key of Object.keys(obj)) {
347
338
  const value = obj[key];
348
- if (typeof value !== "string" || !DESIGN_COLOR_REGEX.test(value)) {
339
+ if (typeof value !== "string" || !COLOR_VALUE_REGEX.test(value)) {
349
340
  refuse(file, `colors.${key}`, "must be a hex/rgb()/rgba()/hsl()/hsla()/var(--…) colour string");
350
341
  }
351
342
  result[key] = value;
352
343
  }
344
+ if (COLOR_KEYS_BAND.some((key) => Object.hasOwn(obj, key))) {
345
+ const missing = COLOR_KEYS_BAND.find((key) => !Object.hasOwn(obj, key));
346
+ if (missing !== undefined) {
347
+ refuse(file, `colors.${missing}`, "is required — the band set is all nine -band keys or none (#12500)");
348
+ }
349
+ }
350
+ const matching = COLOR_KEYS_LIGHT.every((key) => result[key] === result[`${key}-dark`]);
351
+ if (matching && !GROUND_HEX_REGEX.test(result["bg"])) {
352
+ refuse(file, "colors.bg", "must be a 3- or 6-digit hex colour when the light and dark sets match, so the look has a ground (#12500)");
353
+ }
353
354
  return result;
354
355
  }
355
- const TYPOGRAPHY_ROLE_KEYS = [
356
- "fontFamily",
357
- "fontSize",
358
- "fontWeight",
359
- "lineHeight",
360
- "letterSpacing",
361
- "fontSource",
362
- "lineHeightMobile",
363
- "fontSizeMobile",
364
- ];
365
- /** The roles with a phone size (#7739 D1.2). */
366
- const FONT_SIZE_MOBILE_ROLES = ["display", "heading-section", "heading-item"];
367
- /** The roles `typeScale: design` compiles (#7739 D1.3, D2.2). */
368
- const COMPILED_TYPE_ROLES = ["display", "heading-section", "heading-item", "body", "eyebrow"];
369
- /** The roles with a runtime font slot (`--font-display` / `--font-body`, #7720 D1). */
370
- const FONT_SOURCE_ROLES = ["display", "body"];
371
- /** A Google Fonts family name, as next/font/google exports it with spaces → `_`. */
372
- const GOOGLE_FAMILY_RE = /^[A-Za-z][A-Za-z0-9 ]*$/;
356
+ function validateVersion(value, file) {
357
+ if (typeof value !== "number" || !Number.isInteger(value) || value < 1 || value > SETTINGS_VERSION_MAX) {
358
+ refuse(file, "version", `must be a whole number from 1 to ${SETTINGS_VERSION_MAX} — the design's own version (#12500)`);
359
+ }
360
+ return value;
361
+ }
362
+ /**
363
+ * One family of a stack with the spaces around it removed — spaces only, so a
364
+ * tab or line break at its edge stays and is refused; an index walk, never a
365
+ * regex that a run of spaces could make slow (validation's `stackFamily`).
366
+ */
367
+ function stackFamily(family) {
368
+ let start = 0;
369
+ let end = family.length;
370
+ while (start < end && family.charCodeAt(start) === 32)
371
+ start += 1;
372
+ while (end > start && family.charCodeAt(end - 1) === 32)
373
+ end -= 1;
374
+ return family.slice(start, end);
375
+ }
373
376
  /** One stack entry, trimmed, with one matching pair of `'` or `"` removed. */
374
377
  export function unquoteFamily(entry) {
375
378
  const trimmed = entry.trim();
376
379
  const m = /^(['"])(.*)\1$/.exec(trimmed);
377
380
  return m ? m[2] : trimmed;
378
381
  }
379
- /**
380
- * #7720 D1.2 — a `fontSource` names the role's first family as the face to
381
- * load; the rest of the stack is written into CSS and TypeScript source as
382
- * the fallback, so both are constrained here.
383
- */
384
- function validateFontSource(role, file, roleName) {
385
- const field = `typography.${roleName}.fontSource`;
386
- if (!FONT_SOURCE_ROLES.includes(roleName)) {
387
- refuse(file, field, "only the display and body roles reach a runtime font slot");
388
- }
389
- if (role.fontFamily === undefined) {
390
- refuse(file, field, "needs fontFamily on the same role");
391
- }
392
- const [first = "", ...rest] = role.fontFamily.split(",");
393
- if (!GOOGLE_FAMILY_RE.test(unquoteFamily(first))) {
394
- refuse(file, field, "the first family must be a Google Fonts family name");
382
+ function requireCssLength(value, file, field) {
383
+ if (typeof value !== "string" || !CSS_LENGTH_REGEX.test(value)) {
384
+ refuse(file, field, "must be a CSS length: 0, or a number in rem, px, em, %, vw, vh or ch");
395
385
  }
396
- if (!rest.every((entry) => DESIGN_FONT_STACK_ENTRY_REGEX.test(entry.trim()))) {
397
- refuse(file, field, "fallback entries must be bare or singly-quoted family names");
386
+ return value;
387
+ }
388
+ function requireLineHeight(value, file, field) {
389
+ if (typeof value !== "number" || !(value > 0) || value > 10) {
390
+ refuse(file, field, "must be a number above 0 and at most 10");
398
391
  }
392
+ return value;
399
393
  }
400
394
  function validateTypographyRole(raw, file, role) {
401
395
  const obj = requireObject(raw, file, `typography.${role}`);
@@ -407,105 +401,94 @@ function validateTypographyRole(raw, file, role) {
407
401
  if (!("fontSize" in obj)) {
408
402
  refuse(file, `typography.${role}.fontSize`, "is required");
409
403
  }
410
- const result = { fontSize: "" };
411
- for (const [key, value] of Object.entries(obj)) {
412
- const field = `typography.${role}.${key}`;
413
- if (key === "fontFamily" ||
414
- key === "fontSize" ||
415
- key === "letterSpacing" ||
416
- key === "fontSizeMobile") {
417
- if (typeof value !== "string")
418
- refuse(file, field, "must be a string");
419
- if (key === "fontFamily")
420
- result.fontFamily = value;
421
- else if (key === "fontSize")
422
- result.fontSize = value;
423
- else if (key === "letterSpacing")
424
- result.letterSpacing = value;
425
- else {
426
- if (!FONT_SIZE_MOBILE_ROLES.includes(role)) {
427
- refuse(file, field, "only the display, heading-section and heading-item roles have a phone size");
428
- }
429
- result.fontSizeMobile = value;
430
- }
404
+ const field = (key) => `typography.${role}.${key}`;
405
+ const result = { fontSize: requireCssLength(obj.fontSize, file, field("fontSize")) };
406
+ if ("fontFamily" in obj) {
407
+ const value = obj.fontFamily;
408
+ const families = typeof value === "string" && value.length <= FONT_STACK_LENGTH_MAX ? value.split(",") : [];
409
+ if (typeof value !== "string" ||
410
+ value.length > FONT_STACK_LENGTH_MAX ||
411
+ families.length > FONT_STACK_MAX ||
412
+ !families.every((family) => FONT_FAMILY_REGEX.test(stackFamily(family)))) {
413
+ refuse(file, field("fontFamily"), "must be a font-family stack: at most 512 characters, 1 to 8 names, each bare or in one kind of quote");
431
414
  }
432
- else if (key === "fontWeight" || key === "lineHeight") {
433
- if (typeof value !== "number")
434
- refuse(file, field, "must be a number");
435
- if (key === "fontWeight")
436
- result.fontWeight = value;
437
- else
438
- result.lineHeight = value;
439
- }
440
- else if (key === "fontSource") {
441
- if (typeof value !== "string" ||
442
- !DESIGN_FONT_SOURCE_VALUES.includes(value)) {
443
- refuse(file, field, `must be one of ${DESIGN_FONT_SOURCE_VALUES.join(", ")}`);
444
- }
445
- result.fontSource = value;
446
- }
447
- else if (key === "lineHeightMobile") {
448
- if (typeof value !== "number")
449
- refuse(file, field, "must be a number");
450
- if (!(value > 0))
451
- refuse(file, field, "must be greater than 0");
452
- if (role !== "display")
453
- refuse(file, field, "only the display role has a mobile line-height");
454
- result.lineHeightMobile = value;
455
- }
456
- }
457
- // The leading pair compiles into `theme:` (#7720 D2), whose schema takes
458
- // only positive line-heights — refuse here, before a site reads it.
459
- if (result.lineHeightMobile !== undefined &&
460
- result.lineHeight !== undefined &&
461
- !(result.lineHeight > 0)) {
462
- refuse(file, `typography.${role}.lineHeight`, "must be greater than 0 when lineHeightMobile is declared");
463
- }
464
- if (result.fontSource !== undefined)
465
- validateFontSource(result, file, role);
415
+ result.fontFamily = value;
416
+ }
417
+ if ("fontWeight" in obj) {
418
+ const value = obj.fontWeight;
419
+ if (typeof value !== "number" || !Number.isInteger(value) || value < 1 || value > 1000) {
420
+ refuse(file, field("fontWeight"), "must be an integer from 1 to 1000");
421
+ }
422
+ result.fontWeight = value;
423
+ }
424
+ if ("lineHeight" in obj)
425
+ result.lineHeight = requireLineHeight(obj.lineHeight, file, field("lineHeight"));
426
+ if ("letterSpacing" in obj) {
427
+ result.letterSpacing =
428
+ obj.letterSpacing === "normal" ? "normal" : requireCssLength(obj.letterSpacing, file, field("letterSpacing"));
429
+ }
430
+ if ("fontSource" in obj) {
431
+ if (!isOneOf(FONT_SOURCE_VALUES, obj.fontSource)) {
432
+ refuse(file, field("fontSource"), `must be one of ${FONT_SOURCE_VALUES.join(", ")}`);
433
+ }
434
+ result.fontSource = obj.fontSource;
435
+ }
436
+ if ("lineHeightMobile" in obj) {
437
+ result.lineHeightMobile = requireLineHeight(obj.lineHeightMobile, file, field("lineHeightMobile"));
438
+ }
439
+ if ("fontSizeMobile" in obj) {
440
+ result.fontSizeMobile = requireCssLength(obj.fontSizeMobile, file, field("fontSizeMobile"));
441
+ }
442
+ // The role rules (#7720 D1, #7739 D1.2): which roles carry a font slot, a
443
+ // mobile leading and a phone size.
444
+ if (result.fontSource !== undefined) {
445
+ if (!FONT_SOURCE_ROLES.includes(role)) {
446
+ refuse(file, field("fontSource"), "only the display and body roles reach a runtime font slot");
447
+ }
448
+ if (result.fontFamily === undefined)
449
+ refuse(file, field("fontSource"), "needs fontFamily on the same role");
450
+ if (!GOOGLE_FAMILY_REGEX.test(unquoteFamily(result.fontFamily.split(",")[0] ?? ""))) {
451
+ refuse(file, field("fontSource"), "the first family must be a Google Fonts family name");
452
+ }
453
+ }
454
+ if (result.lineHeightMobile !== undefined && !LINE_HEIGHT_MOBILE_ROLES.includes(role)) {
455
+ refuse(file, field("lineHeightMobile"), "only the display role has a mobile line-height");
456
+ }
457
+ if (result.fontSizeMobile !== undefined && !FONT_SIZE_MOBILE_ROLES.includes(role)) {
458
+ refuse(file, field("fontSizeMobile"), "only the display, heading-section and heading-item roles have a phone size");
459
+ }
466
460
  return result;
467
461
  }
468
462
  function validateTypography(raw, file) {
469
- const obj = requireObject(raw, file, "typography");
463
+ const obj = requireNamedMap(raw, file, "typography", DIAL_NAME_REGEX, 1, TYPOGRAPHY_ROLES_MAX);
470
464
  const result = {};
471
465
  for (const [role, value] of Object.entries(obj)) {
472
466
  result[role] = validateTypographyRole(value, file, role);
473
467
  }
474
468
  return result;
475
469
  }
476
- function validateStringMap(raw, file, field) {
477
- const obj = requireObject(raw, file, field);
470
+ function validateLengthMap(raw, file, field) {
471
+ const obj = requireNamedMap(raw, file, field, DIAL_NAME_REGEX, 0, DIAL_MAP_MAX);
478
472
  const result = {};
479
473
  for (const [key, value] of Object.entries(obj)) {
480
- if (typeof value !== "string") {
481
- refuse(file, `${field}.${key}`, "must be a string");
482
- }
483
- result[key] = value;
474
+ result[key] = requireCssLength(value, file, `${field}.${key}`);
484
475
  }
485
476
  return result;
486
477
  }
487
- const LAYOUT_KEYS = ["nav", "footer", "announcementBanner", "home"];
488
- /** Every key a package's `layout` may carry — #7719 D3 adds the optional `deckGrounds` (a deck home only),
489
- * #7721 D1 the optional `innerPages`, #7740 D1 the optional `deckPresentation` (a deck home only), #8773 the optional `deckAnchors` (a presenting deck only),
490
- * #7742 D1 the optional `colorMode` and `chromeStyle`, #7797 D1 the optional `closingFooterPaths`. */
491
- const ALLOWED_LAYOUT_KEYS = new Set([
492
- ...LAYOUT_KEYS,
493
- "deckGrounds",
494
- "innerPages",
495
- "deckPresentation",
496
- "deckAnchors",
497
- "colorMode",
498
- "chromeStyle",
499
- "closingFooterPaths",
500
- ]);
478
+ /** Every key a package's `layout` may carry. A retired key (`RETIRED_LAYOUT_KEYS`, #12500) is refused with its reason. */
479
+ const ALLOWED_LAYOUT_KEYS = new Set([...LAYOUT_REQUIRED_KEYS, ...LAYOUT_OPTIONAL_KEYS]);
501
480
  function validateLayout(raw, file) {
502
481
  const obj = requireObject(raw, file, "layout");
503
482
  for (const key of Object.keys(obj)) {
483
+ const retired = Object.hasOwn(RETIRED_LAYOUT_KEYS, key) ? RETIRED_LAYOUT_KEYS[key] : undefined;
484
+ if (retired !== undefined) {
485
+ refuse(file, `layout.${key}`, retired);
486
+ }
504
487
  if (!ALLOWED_LAYOUT_KEYS.has(key)) {
505
488
  refuse(file, `layout.${key}`, "is not a recognized layout key");
506
489
  }
507
490
  }
508
- for (const key of LAYOUT_KEYS) {
491
+ for (const key of LAYOUT_REQUIRED_KEYS) {
509
492
  if (!(key in obj)) {
510
493
  refuse(file, `layout.${key}`, "is required");
511
494
  }
@@ -516,7 +499,7 @@ function validateLayout(raw, file) {
516
499
  }
517
500
  catch (error) {
518
501
  if (error instanceof TemplateLayoutError) {
519
- const match = /: (layout\.[A-Za-z]+) must /.exec(error.message);
502
+ const match = /: (layout\.[A-Za-z]+(?:\.\d+)?) must /.exec(error.message);
520
503
  refuse(file, match?.[1] ?? "layout", error.message);
521
504
  }
522
505
  throw error;
@@ -524,14 +507,13 @@ function validateLayout(raw, file) {
524
507
  // #7721 D1 — a read package holds `innerPages` only as "bare", the
525
508
  // `ResolvedSiteChrome` shape; an explicit "default" is the absent key.
526
509
  // #7740 D1 — and `deckPresentation` only as `true`.
527
- // #7742 D1 — and `colorMode` only as "light", `chromeStyle` only as "minimal".
528
- const { innerPages, deckPresentation, deckAnchors, colorMode, chromeStyle, ...rest } = validated;
510
+ // #7742 D1 — and `chromeStyle` only as "minimal".
511
+ const { innerPages, deckPresentation, deckAnchors, chromeStyle, ...rest } = validated;
529
512
  const layout = {
530
513
  ...rest,
531
514
  ...(innerPages === "bare" ? { innerPages } : {}),
532
515
  ...(deckPresentation === true ? { deckPresentation } : {}),
533
516
  ...(deckAnchors === "bare" ? { deckAnchors } : {}),
534
- ...(colorMode === "light" ? { colorMode } : {}),
535
517
  ...(chromeStyle === "minimal" ? { chromeStyle } : {}),
536
518
  };
537
519
  if (layout.deckGrounds !== undefined && layout.home !== "deck") {
@@ -540,30 +522,30 @@ function validateLayout(raw, file) {
540
522
  if (deckPresentation === true && layout.home !== "deck") {
541
523
  refuse(file, "layout.deckPresentation", "applies only to home: deck");
542
524
  }
543
- if (deckAnchors === "bare" && deckPresentation !== true) {
525
+ if (deckAnchors !== undefined && deckPresentation !== true) {
544
526
  refuse(file, "layout.deckAnchors", "applies only with deckPresentation: true");
545
527
  }
546
528
  return layout;
547
529
  }
548
530
  const TREATMENTS_ENUMS = {
549
- corners: DESIGN_CORNERS_VALUES,
550
- eyebrowCase: DESIGN_EYEBROW_CASE_VALUES,
551
- placeholders: DESIGN_PLACEHOLDERS_VALUES,
552
- checkmarks: DESIGN_CHECKMARKS_VALUES,
553
- buttonShape: DESIGN_BUTTON_SHAPE_VALUES,
554
- typeScale: DESIGN_TYPE_SCALE_VALUES,
555
- darkInk: DESIGN_DARK_INK_VALUES,
556
- figures: DESIGN_FIGURES_VALUES,
531
+ corners: CORNERS_VALUES,
532
+ eyebrowCase: EYEBROW_CASE_VALUES,
533
+ placeholders: PLACEHOLDERS_VALUES,
534
+ checkmarks: CHECKMARKS_VALUES,
535
+ buttonShape: BUTTON_SHAPE_VALUES,
536
+ typeScale: TYPE_SCALE_VALUES,
537
+ darkInk: DARK_INK_VALUES,
538
+ figures: FIGURES_VALUES,
557
539
  };
558
540
  function validateTreatments(raw, file) {
559
541
  const obj = requireObject(raw, file, "treatments");
560
542
  const result = {};
561
543
  for (const [key, value] of Object.entries(obj)) {
562
- const values = TREATMENTS_ENUMS[key];
544
+ const values = Object.hasOwn(TREATMENTS_ENUMS, key) ? TREATMENTS_ENUMS[key] : undefined;
563
545
  if (values === undefined) {
564
546
  refuse(file, `treatments.${key}`, "is not a recognized treatment");
565
547
  }
566
- if (typeof value !== "string" || !values.includes(value)) {
548
+ if (!isOneOf(values, value)) {
567
549
  refuse(file, `treatments.${key}`, `must be one of ${values.join(", ")}`);
568
550
  }
569
551
  result[key] = value;
@@ -571,10 +553,8 @@ function validateTreatments(raw, file) {
571
553
  return result;
572
554
  }
573
555
  /**
574
- * #7739 D1.3 — under `typeScale: design` the five compiled roles' sizes and
575
- * weights are written into an inline `<style>`, so each is constrained here,
576
- * after both `typography` and `treatments` have been read. Without the dial
577
- * these fields are carried as before and never compiled.
556
+ * #7739 D1.3 — under `typeScale: design` the five compiled roles' sizes are
557
+ * written into an inline `<style>`, so each is a plain length in rem, px or em.
578
558
  */
579
559
  function validateCompiledTypeScale(typography, file) {
580
560
  for (const role of COMPILED_TYPE_ROLES) {
@@ -583,25 +563,43 @@ function validateCompiledTypeScale(typography, file) {
583
563
  continue;
584
564
  for (const key of ["fontSize", "fontSizeMobile"]) {
585
565
  const value = def[key];
586
- if (value !== undefined && !DESIGN_TYPE_SIZE_REGEX.test(value)) {
566
+ if (value !== undefined && !TYPE_SIZE_REGEX.test(value)) {
587
567
  refuse(file, `typography.${role}.${key}`, "must be a length in rem, px or em");
588
568
  }
589
569
  }
590
- const weight = def.fontWeight;
591
- if (weight !== undefined && !(Number.isInteger(weight) && weight >= 1 && weight <= 1000)) {
592
- refuse(file, `typography.${role}.fontWeight`, "must be an integer from 1 to 1000");
593
- }
594
- // The display and body leadings compile too, into a schema that takes only positive ones.
595
- if ((role === "display" || role === "body") && def.lineHeight !== undefined && !(def.lineHeight > 0)) {
596
- refuse(file, `typography.${role}.lineHeight`, "must be greater than 0");
597
- }
598
570
  }
599
571
  }
572
+ /** A section look field's value: an option token, a finite number or a boolean — never CSS (SEC-12470-4). */
573
+ function isLookFieldValue(value) {
574
+ if (typeof value === "string")
575
+ return SECTION_TOKEN_REGEX.test(value);
576
+ if (typeof value === "number")
577
+ return Number.isFinite(value);
578
+ return typeof value === "boolean";
579
+ }
600
580
  function validateSections(raw, file) {
601
581
  const obj = requireObject(raw, file, "sections");
582
+ for (const pageType of Object.keys(obj)) {
583
+ if (!SECTION_PAGE_TYPES.includes(pageType)) {
584
+ refuse(file, `sections.${pageType}`, "is not a page type a look sets section settings for");
585
+ }
586
+ }
587
+ if (Object.keys(obj).length > SECTION_PAGE_TYPES_MAX) {
588
+ refuse(file, "sections", `must hold at most ${SECTION_PAGE_TYPES_MAX} page types`);
589
+ }
602
590
  const result = {};
603
591
  for (const [pageType, value] of Object.entries(obj)) {
604
- result[pageType] = requireObject(value, file, `sections.${pageType}`);
592
+ const sections = requireNamedMap(value, file, `sections.${pageType}`, SECTION_NAME_REGEX, 0, SECTIONS_PER_PAGE_MAX);
593
+ for (const [section, fields] of Object.entries(sections)) {
594
+ const path = `sections.${pageType}.${section}`;
595
+ const looks = requireNamedMap(fields, file, path, SECTION_NAME_REGEX, 0, LOOK_FIELDS_PER_SECTION_MAX);
596
+ for (const [field, look] of Object.entries(looks)) {
597
+ if (!isLookFieldValue(look)) {
598
+ refuse(file, `${path}.${field}`, "must be an option token (lower-case letters, digits, dashes), a number or a boolean");
599
+ }
600
+ }
601
+ }
602
+ result[pageType] = sections;
605
603
  }
606
604
  return result;
607
605
  }
@@ -613,51 +611,30 @@ function validateCopy(raw, file) {
613
611
  }
614
612
  }
615
613
  const density = obj["density"];
616
- if (typeof density !== "string" ||
617
- !DESIGN_COPY_DENSITY_VALUES.includes(density)) {
618
- refuse(file, "copy.density", `must be one of ${DESIGN_COPY_DENSITY_VALUES.join(", ")}`);
619
- }
620
- return { density: density };
621
- }
622
- const TOP_LEVEL_KEYS = [
623
- "name",
624
- "description",
625
- "colors",
626
- "typography",
627
- "rounded",
628
- "spacing",
629
- "layout",
630
- "treatments",
631
- "sections",
632
- "copy",
633
- ];
634
- const REQUIRED_TOP_LEVEL_KEYS = [
635
- "name",
636
- "description",
637
- "colors",
638
- "typography",
639
- "rounded",
640
- "spacing",
641
- "layout",
642
- ];
614
+ if (!isOneOf(COPY_DENSITY_VALUES, density)) {
615
+ refuse(file, "copy.density", `must be one of ${COPY_DENSITY_VALUES.join(", ")}`);
616
+ }
617
+ return { density };
618
+ }
643
619
  function validatePackage(raw, file) {
644
620
  for (const key of Object.keys(raw)) {
645
- if (!TOP_LEVEL_KEYS.includes(key)) {
621
+ if (!SETTINGS_KEYS.includes(key)) {
646
622
  refuse(file, key, "is not a recognized design-package key");
647
623
  }
648
624
  }
649
- for (const key of REQUIRED_TOP_LEVEL_KEYS) {
625
+ for (const key of SETTINGS_REQUIRED_KEYS) {
650
626
  if (!(key in raw)) {
651
627
  refuse(file, key, "is required");
652
628
  }
653
629
  }
654
630
  const pkg = {
655
- name: requireString(raw.name, file, "name"),
656
- description: requireString(raw.description, file, "description"),
631
+ name: requireText(raw.name, file, "name", NAME_MAX),
632
+ version: validateVersion(raw.version, file),
633
+ description: requireText(raw.description, file, "description", DESCRIPTION_MAX),
657
634
  colors: validateColors(raw.colors, file),
658
635
  typography: validateTypography(raw.typography, file),
659
- rounded: validateStringMap(raw.rounded, file, "rounded"),
660
- spacing: validateStringMap(raw.spacing, file, "spacing"),
636
+ rounded: validateLengthMap(raw.rounded, file, "rounded"),
637
+ spacing: validateLengthMap(raw.spacing, file, "spacing"),
661
638
  layout: validateLayout(raw.layout, file),
662
639
  sections: "sections" in raw ? validateSections(raw.sections, file) : {},
663
640
  copy: "copy" in raw ? validateCopy(raw.copy, file) : { density: "standard" },
@@ -671,18 +648,38 @@ function validatePackage(raw, file) {
671
648
  return pkg;
672
649
  }
673
650
  /**
674
- * Read and validate `<dir>/DESIGN.md`'s frontmatter into a typed
651
+ * `readDesignPackage`'s check over settings text, with no file read (#12500
652
+ * D7): `update` reads a site's moved settings as a design before it writes them.
653
+ */
654
+ export function readDesignPackageText(text, file) {
655
+ return validatePackage(parseSettings(text, file), file);
656
+ }
657
+ /**
658
+ * Read `<dir>/design.yaml`, validated exactly as `readDesignPackage` validates
659
+ * it, and answer the parsed settings object rather than the typed package
660
+ * (#12477 D3): the settings a look of a workspace's own is written to its hub
661
+ * design record with. Refuses as `readDesignPackage` does.
662
+ */
663
+ export function readDesignSettings(dir) {
664
+ const file = join(dir, SETTINGS_FILE);
665
+ if (!existsSync(file)) {
666
+ // #12468 — a DESIGN.md is impeccable's guide; it is never read as settings.
667
+ if (existsSync(join(dir, "DESIGN.md"))) {
668
+ refuse(file, SETTINGS_FILE, "DESIGN.md is a design guide, not settings — a design's settings are its design.yaml (#12468)");
669
+ }
670
+ refuse(file, SETTINGS_FILE, "file does not exist");
671
+ }
672
+ const settings = parseSettings(readFileSync(file, "utf8"), file);
673
+ validatePackage(settings, file);
674
+ return settings;
675
+ }
676
+ /**
677
+ * Read and validate `<dir>/design.yaml` into a typed
675
678
  * `DesignPackage` (D1/D2). Refuses — naming the file and the field — on any
676
679
  * malformed package: a missing file, an unknown key, a wrong type, an
677
680
  * unknown layout value. Nothing is written; this function has no side
678
681
  * effects beyond the one read.
679
682
  */
680
683
  export function readDesignPackage(dir) {
681
- const file = join(dir, "DESIGN.md");
682
- if (!existsSync(file)) {
683
- refuse(file, "DESIGN.md", "file does not exist");
684
- }
685
- const text = readFileSync(file, "utf8");
686
- const raw = parseFrontmatter(text, file);
687
- return validatePackage(raw, file);
684
+ return validatePackage(readDesignSettings(dir), join(dir, SETTINGS_FILE));
688
685
  }