@astryxdesign/cli 0.7.15-canary.gea16e8d → 0.7.15

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 (134) hide show
  1. package/CHANGELOG.md +353 -3
  2. package/README.md +63 -63
  3. package/api/build/_adapter.d.mts +4 -0
  4. package/api/build/_adapter.mjs +28 -2
  5. package/api/build/blocks/blocks.d.mts +10 -1
  6. package/api/build/blocks/blocks.mjs +84 -7
  7. package/api/build/build.mjs +6 -1
  8. package/api/build/tree.d.mts +4 -0
  9. package/api/build/tree.mjs +9 -2
  10. package/api/doctor/_adapter.d.mts +2 -1
  11. package/api/doctor/_adapter.mjs +6 -1
  12. package/api/doctor/doctor.mjs +2 -2
  13. package/api/doctor/theme-checks.mjs +56 -21
  14. package/api/integration/add-helpers.mjs +5 -0
  15. package/api/integration/add-theme.mjs +15 -110
  16. package/api/integration/validate-integration.mjs +17 -3
  17. package/api/integration/validateIntegration.doc.mjs +1 -1
  18. package/api/theme/_adapter.d.mts +37 -5
  19. package/api/theme/_adapter.mjs +363 -50
  20. package/api/theme/_fork.d.mts +90 -0
  21. package/api/theme/_fork.mjs +246 -0
  22. package/api/theme/build/build.d.mts +25 -1
  23. package/api/theme/build/build.mjs +352 -41
  24. package/api/theme/eject/eject.mjs +36 -15
  25. package/api/theme/list/list.mjs +3 -6
  26. package/api/theme/palette/generate/generator.d.mts +13 -0
  27. package/api/theme/palette/generate/generator.mjs +32 -2
  28. package/api/theme/targets/targets.mjs +10 -3
  29. package/api/theme/template/template.mjs +48 -2
  30. package/api/theme/theme.type.d.mts +8 -0
  31. package/api/theme/theme.type.mjs +5 -1
  32. package/api/theme/themeBuild.doc.mjs +2 -2
  33. package/api/theme/themeRemove.doc.mjs +5 -2
  34. package/api/theme/themeTemplate.doc.mjs +2 -2
  35. package/api/theme/themeUse.doc.mjs +8 -2
  36. package/api/theme-edit/_adapter.mjs +157 -36
  37. package/api/theme-edit/_catalog.d.mts +1 -6
  38. package/api/theme-edit/_catalog.mjs +5 -268
  39. package/api/theme-edit/_check.d.mts +3 -1
  40. package/api/theme-edit/_check.mjs +733 -308
  41. package/api/theme-edit/_color.d.mts +19 -0
  42. package/api/theme-edit/_color.mjs +277 -33
  43. package/api/theme-edit/_compiler.d.mts +1 -0
  44. package/api/theme-edit/_compiler.mjs +25 -0
  45. package/api/theme-edit/_context.d.mts +2 -0
  46. package/api/theme-edit/_context.mjs +83 -9
  47. package/api/theme-edit/_css.d.mts +84 -0
  48. package/api/theme-edit/_css.mjs +700 -0
  49. package/api/theme-edit/_edit.mjs +370 -85
  50. package/api/theme-edit/_how-commands.d.mts +5 -0
  51. package/api/theme-edit/_how-commands.mjs +20 -13
  52. package/api/theme-edit/_how-question.d.mts +29 -0
  53. package/api/theme-edit/_how-question.mjs +1573 -182
  54. package/api/theme-edit/_how.mjs +306 -22
  55. package/api/theme-edit/_overview.mjs +2 -7
  56. package/api/theme-edit/_palette.d.mts +27 -5
  57. package/api/theme-edit/_palette.mjs +231 -97
  58. package/api/theme-edit/_parts.d.mts +42 -10
  59. package/api/theme-edit/_parts.mjs +224 -69
  60. package/api/theme-edit/_preview-app.d.mts +8 -0
  61. package/api/theme-edit/_preview-app.mjs +549 -96
  62. package/api/theme-edit/_preview.d.mts +7 -16
  63. package/api/theme-edit/_preview.mjs +77 -84
  64. package/api/theme-edit/_project.d.mts +20 -1
  65. package/api/theme-edit/_project.mjs +43 -13
  66. package/api/theme-edit/_settings.d.mts +96 -20
  67. package/api/theme-edit/_settings.mjs +646 -141
  68. package/api/theme-edit/_tables.d.mts +18 -12
  69. package/api/theme-edit/_tables.mjs +144 -147
  70. package/api/theme-edit/theme-edit.type.d.mts +10 -1
  71. package/api/theme-edit/theme-edit.type.mjs +3 -1
  72. package/api/theme-edit/themeEditNew.doc.mjs +1 -1
  73. package/api/theme-edit/themeEditPreviewAdd.doc.mjs +1 -1
  74. package/api/theme-edit/themeEditPreviewApp.doc.mjs +1 -1
  75. package/api/theme-edit/themeEditPreviewList.doc.mjs +2 -2
  76. package/api/theme-edit/themeEditSet.doc.mjs +1 -1
  77. package/api/theme-edit/themeEditUndo.doc.mjs +1 -1
  78. package/assets/docs/tree/checks.doc.mjs +22 -1
  79. package/assets/docs/tree/publishing.doc.mjs +1 -0
  80. package/assets/docs.generated.json +2 -2
  81. package/assets/self-audit.generated.json +1 -1
  82. package/authoring/integration/integration.doc.mjs +8 -0
  83. package/authoring/integration/schema.d.mts +8 -0
  84. package/authoring/integration/schema.mjs +1 -0
  85. package/authoring/integration/type.ts +9 -0
  86. package/clients/cli/build-id.generated.json +1 -1
  87. package/clients/cli/commands/experimental/index.mjs +10 -10
  88. package/clients/cli/commands/experimental/theme.mjs +22 -3
  89. package/clients/cli/commands/experimental-theme-compile.doc.mjs +2 -2
  90. package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +3 -3
  91. package/clients/cli/commands/experimental-theme-preview-add.doc.mjs +1 -1
  92. package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
  93. package/clients/cli/commands/integration.mjs +8 -0
  94. package/clients/cli/commands/theme-build.doc.mjs +2 -2
  95. package/clients/cli/commands/theme-list.doc.mjs +1 -1
  96. package/clients/cli/commands/theme-template.doc.mjs +1 -1
  97. package/clients/cli/commands/theme.mjs +325 -48
  98. package/clients/cli/index.mjs +18 -3
  99. package/clients/cli/lib/cli-error.mjs +118 -3
  100. package/clients/cli/manifest.generated.json +1 -1
  101. package/foundation/config/project.mjs +34 -8
  102. package/foundation/config/theme-state.d.mts +16 -0
  103. package/foundation/config/theme-state.mjs +84 -13
  104. package/foundation/discovery/template-needs.d.mts +13 -0
  105. package/foundation/discovery/template-needs.mjs +30 -15
  106. package/foundation/discovery/theme-discovery.mjs +14 -2
  107. package/foundation/discovery/theme-imports.d.mts +16 -0
  108. package/foundation/discovery/theme-imports.mjs +30 -2
  109. package/foundation/doc-compiler/import.mjs +10 -4
  110. package/foundation/fs/gather-cache.mjs +82 -23
  111. package/foundation/fs/jiti-cache.d.mts +21 -0
  112. package/foundation/fs/jiti-cache.mjs +66 -0
  113. package/foundation/fs/module-loader.mjs +7 -2
  114. package/foundation/integrations/autolink.d.mts +1 -24
  115. package/foundation/integrations/autolink.mjs +7 -60
  116. package/foundation/integrations/declared-dependencies.d.mts +27 -0
  117. package/foundation/integrations/declared-dependencies.mjs +73 -0
  118. package/foundation/integrations/integrations.d.mts +8 -0
  119. package/foundation/integrations/integrations.mjs +4 -0
  120. package/foundation/integrations/may-have-integrations.d.mts +8 -0
  121. package/foundation/integrations/may-have-integrations.mjs +47 -0
  122. package/foundation/integrations/validate-contributions.d.mts +62 -1
  123. package/foundation/integrations/validate-contributions.mjs +452 -29
  124. package/foundation/release/cache.d.mts +21 -2
  125. package/foundation/release/cache.mjs +48 -8
  126. package/foundation/release/folder-lock.d.mts +7 -0
  127. package/foundation/release/folder-lock.mjs +60 -26
  128. package/foundation/release/lock-lease.d.mts +2 -1
  129. package/foundation/release/lock-lease.mjs +7 -2
  130. package/foundation/response/error-codes.doc.mjs +1 -1
  131. package/foundation/response/response-types.doc.mjs +5 -5
  132. package/package.json +6 -6
  133. package/api/theme-edit/_css-properties.d.mts +0 -10
  134. package/api/theme-edit/_css-properties.mjs +0 -556
@@ -20,9 +20,14 @@ import {
20
20
  HOW,
21
21
  OPEN_FONTS,
22
22
  COMMON_STATES,
23
+ COLOR_PROPS,
24
+ GROUPS,
25
+ isSystemFamily,
23
26
  } from './_tables.mjs';
24
27
  import {PALETTE_DIALS, isGraySeed, seedOf} from './_palette.mjs';
25
- import {COLOR_PROPS} from './_tables.mjs';
28
+ import {focusStateOf} from './_settings.mjs';
29
+ import {levenshteinDistance} from '../../foundation/text/levenshtein.mjs';
30
+ import {cssProperties, keywordsOf, matchValue} from './_css.mjs';
26
31
 
27
32
  /** @typedef {import('./_how-commands.mjs').Step} Step */
28
33
 
@@ -88,12 +93,21 @@ const TRANSLATE = /** @type {Array<[RegExp, string]>} */ (
88
93
  ])
89
94
  );
90
95
 
91
- /** Words a near miss is corrected to (one or two letters off). */
92
- const VOCAB = [
93
- 'button',
94
- 'buttons',
95
- 'card',
96
- 'cards',
96
+ /**
97
+ * Words a near miss is corrected to (one or two letters off), besides the
98
+ * one-word target names Core's catalog gives (partLexicon): design words,
99
+ * and the words the part overrides read.
100
+ */
101
+ const DESIGN_WORDS = [
102
+ 'leading',
103
+ 'header',
104
+ 'headers',
105
+ 'input',
106
+ 'inputs',
107
+ 'checkbox',
108
+ 'toggle',
109
+ 'sidebar',
110
+ 'progress',
97
111
  'shadow',
98
112
  'shadows',
99
113
  'border',
@@ -105,24 +119,6 @@ const VOCAB = [
105
119
  'radius',
106
120
  'padding',
107
121
  'spacing',
108
- 'header',
109
- 'banner',
110
- 'input',
111
- 'inputs',
112
- 'dialog',
113
- 'dialogs',
114
- 'tooltip',
115
- 'heading',
116
- 'headings',
117
- 'checkbox',
118
- 'switch',
119
- 'toggle',
120
- 'table',
121
- 'badge',
122
- 'badges',
123
- 'avatar',
124
- 'avatars',
125
- 'sidebar',
126
122
  'gradient',
127
123
  'color',
128
124
  'colour',
@@ -136,11 +132,6 @@ const VOCAB = [
136
132
  'compact',
137
133
  'accent',
138
134
  'remove',
139
- 'shadows',
140
- 'rounded',
141
- 'headers',
142
- 'tables',
143
- 'progress',
144
135
  'outline',
145
136
  ];
146
137
 
@@ -158,10 +149,19 @@ const SHORT = /** @type {Record<string, string>} */ ({
158
149
  txt: 'text',
159
150
  clr: 'color',
160
151
  shdw: 'shadow',
152
+ fnot: 'font',
153
+ fnt: 'font',
161
154
  });
162
155
 
163
156
  /** Plain words that are never corrected, though one letter off a VOCAB word. */
164
157
  const KEEP = new Set([
158
+ 'lines',
159
+ 'block',
160
+ 'blocks',
161
+ 'blank',
162
+ 'blur',
163
+ 'shadowy',
164
+ 'times',
165
165
  'remote',
166
166
  'reverse',
167
167
  'access',
@@ -173,23 +173,17 @@ const KEEP = new Set([
173
173
  'agent',
174
174
  'tighter',
175
175
  'tight',
176
- 'lighter',
177
176
  'brighter',
178
177
  'wider',
179
178
  'danger',
180
179
  'orange',
181
180
  'ranger',
182
181
  'rows',
183
- 'darker',
184
182
  'thinner',
185
183
  'rounds',
186
184
  'should',
187
- 'button',
188
- 'buttons',
189
- 'color',
190
185
  'colors',
191
186
  'italics',
192
- 'border',
193
187
  'fonts',
194
188
  'title',
195
189
  'titles',
@@ -199,7 +193,6 @@ const KEEP = new Set([
199
193
  'muted',
200
194
  'filled',
201
195
  'spaced',
202
- 'wider',
203
196
  'bolder',
204
197
  'cord',
205
198
  'board',
@@ -210,9 +203,7 @@ const KEEP = new Set([
210
203
  'later',
211
204
  'darken',
212
205
  'ladder',
213
- 'header',
214
206
  'leader',
215
- 'bigger',
216
207
  'cars',
217
208
  'care',
218
209
  'hard',
@@ -220,58 +211,80 @@ const KEEP = new Set([
220
211
  'bottom',
221
212
  'botton',
222
213
  'inside',
223
- 'tables',
224
- 'colors',
225
214
  'colours',
226
215
  'sitch',
227
216
  'witch',
228
- 'border',
229
217
  'sharper',
230
- 'shadows',
231
- 'smaller',
232
218
  'taller',
233
219
  ]);
234
220
 
235
221
  /**
236
- * Edit distance where two swapped letters count as one edit, capped at 3.
237
- * @param {string} a @param {string} b
222
+ * A word with a near miss corrected: two swapped letters count as one edit.
223
+ * @param {string} w
224
+ * @param {string[]} vocab
238
225
  */
239
- function distance(a, b) {
240
- if (Math.abs(a.length - b.length) > 2) return 3;
241
- /** @type {number[][]} */
242
- const d = Array.from({length: a.length + 1}, (_, i) =>
243
- Array.from({length: b.length + 1}, (_, j) =>
244
- i === 0 ? j : j === 0 ? i : 0,
245
- ),
246
- );
247
- for (let i = 1; i <= a.length; i++)
248
- for (let j = 1; j <= b.length; j++) {
249
- d[i][j] = Math.min(
250
- d[i - 1][j] + 1,
251
- d[i][j - 1] + 1,
252
- d[i - 1][j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1),
253
- );
254
- if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1])
255
- d[i][j] = Math.min(d[i][j], d[i - 2][j - 2] + 1);
256
- }
257
- return Math.min(3, d[a.length][b.length]);
258
- }
259
-
260
- /** @param {string} w */
261
- function corrected(w) {
226
+ function corrected(w, vocab) {
262
227
  if (SHORT[w]) return SHORT[w];
263
- if (w.length < 5 || KEEP.has(w) || VOCAB.includes(w) || !/^[a-z]+$/.test(w))
228
+ // A state word ("selected") is read as a state, never corrected.
229
+ if (
230
+ w.length < 5 ||
231
+ KEEP.has(w) ||
232
+ vocab.includes(w) ||
233
+ !/^[a-z]+$/.test(w) ||
234
+ STATE_WORDS.some(([re]) => re.test(w))
235
+ )
264
236
  return w;
265
237
  const limit = w.length >= 8 ? 2 : 1;
266
238
  let best = w;
267
239
  let bestD = limit + 1;
268
- for (const v of VOCAB) {
269
- const d = distance(w, v);
240
+ for (const v of vocab) {
241
+ const d = levenshteinDistance(w, v, 2, {swaps: true});
270
242
  if (d < bestD) [best, bestD] = [v, d];
271
243
  }
272
244
  return bestD <= limit ? best : w;
273
245
  }
274
246
 
247
+ /** A stop on a gray family: "gray-50", "slate 100", "zinc-900". */
248
+ const GRAY_STOP =
249
+ /\b(gr[ae]y|slate|zinc|neutral|stone)[\s-]?(50|[1-9]00|950)\b/g;
250
+
251
+ /**
252
+ * The color at a stop of a gray family, in OKLCH: the lightness the common
253
+ * 50-950 gray scales give each stop, with the family's slight hue.
254
+ * @param {string} family @param {number} stop
255
+ */
256
+ function grayStop(family, stop) {
257
+ const L = /** @type {Record<number, number>} */ ({
258
+ 50: 0.985,
259
+ 100: 0.967,
260
+ 200: 0.928,
261
+ 300: 0.872,
262
+ 400: 0.707,
263
+ 500: 0.551,
264
+ 600: 0.446,
265
+ 700: 0.373,
266
+ 800: 0.278,
267
+ 900: 0.21,
268
+ 950: 0.13,
269
+ })[stop];
270
+ // Grays are near neutral at the light and dark ends, tinted most in
271
+ // the middle.
272
+ const [base, hue] = /** @type {Record<string, [number, number]>} */ ({
273
+ gray: [0.03, 264],
274
+ grey: [0.03, 264],
275
+ slate: [0.05, 257],
276
+ zinc: [0.015, 286],
277
+ neutral: [0, 0],
278
+ stone: [0.012, 56],
279
+ })[family];
280
+ const chroma = Number(
281
+ (base * Math.min(1, 2 * Math.min(L, 1 - L))).toFixed(4),
282
+ );
283
+ return hex(
284
+ /** @type {number[]} */ (parseColor(`oklch(${L} ${chroma} ${hue})`)),
285
+ );
286
+ }
287
+
275
288
  /** Hues people name, as fills a part can take. */
276
289
  const HUES = /** @type {Record<string, string>} */ ({
277
290
  red: '#dc2626',
@@ -288,6 +301,7 @@ const HUES = /** @type {Record<string, string>} */ ({
288
301
  navy: '#1e3a8a',
289
302
  indigo: '#4f46e5',
290
303
  purple: '#7c3aed',
304
+ charcoal: '#333333',
291
305
  violet: '#7c3aed',
292
306
  pink: '#db2777',
293
307
  magenta: '#c026d3',
@@ -341,18 +355,29 @@ const THEME_COLOR_WORDS = /** @type {Array<[RegExp, string, string]>} */ ([
341
355
  function colorsIn(c) {
342
356
  /** @type {Array<[number, string, boolean?]>} */
343
357
  const found = [];
358
+ // "gray-50", "zinc 900": a stop on a gray family, by its lightness.
359
+ for (const m of c.matchAll(GRAY_STOP))
360
+ found.push([m.index ?? 0, grayStop(m[1], Number(m[2])), true]);
344
361
  const re =
345
- /#[0-9a-f]{3,8}\b|\b(?:rgba?|hsla?|hwb|lab|lch|oklab|oklch)\([^)]*\)|\b(?:(light|pale|dark)\s+)?([a-z]+)\b/g;
346
- for (const m of c.matchAll(re)) {
347
- const before = c.slice(Math.max(0, (m.index ?? 0) - 5), m.index);
348
- if (/\bnot\s*$|\bno\s*$/.test(before)) continue;
362
+ /#[0-9a-f]{3,8}\b|\b(?:rgba?|hsla?|hwb|lab|lch|oklab|oklch|color-mix)\([^)]*\)|\b(?:(light|pale|dark|subtle|soft)\s+)?([a-z]+)\b/g;
363
+ for (const m of c
364
+ .replace(GRAY_STOP, s => ' '.repeat(s.length))
365
+ .matchAll(re)) {
366
+ const before = c.slice(Math.max(0, (m.index ?? 0) - 12), m.index);
367
+ // "charcoal text instead of black": the color after "instead of" is
368
+ // the one to move away from.
369
+ if (/\bnot\s*$|\bno\s*$|\binstead of\s*$|\brather than\s*$/.test(before))
370
+ continue;
349
371
  const whole = m[0];
350
372
  if (whole.startsWith('#') || whole.includes('(')) {
351
373
  // A typed hex color keeps the case it is written in, as set stores it.
352
- if (parseColor(whole)) found.push([m.index ?? 0, whole, true]);
374
+ // A color-mix() is kept as typed; set checks it.
375
+ if (parseColor(whole) || /^color-mix\(/.test(whole))
376
+ found.push([m.index ?? 0, whole, true]);
353
377
  continue;
354
378
  }
355
- const [shade, word] = [m[1], m[2]];
379
+ const shade = m[1] === 'subtle' || m[1] === 'soft' ? 'pale' : m[1];
380
+ const word = m[2];
356
381
  if (shade && SHADED[shade]?.[word]) {
357
382
  found.push([m.index ?? 0, SHADED[shade][word]]);
358
383
  continue;
@@ -411,7 +436,6 @@ const NOT_COLORS = new Set([
411
436
  'gold',
412
437
  'silver',
413
438
  'salmon',
414
- 'tomato',
415
439
  'thistle',
416
440
  'orchid',
417
441
  'wheat',
@@ -498,15 +522,9 @@ function stronger(color, f, mode) {
498
522
  function weightIn(c) {
499
523
  const n = /\b([1-9]00)\b(?!\s*(px|ms|%))/.exec(c.text)?.[1];
500
524
  if (n) return n;
501
- const w = /\b(semibold|semi-bold|medium|regular|normal)\b/.exec(c.text)?.[1];
525
+ const w = /\b(semi-?bold|medium|regular|normal)\b/.exec(c.text)?.[1];
502
526
  return w
503
- ? /** @type {Record<string, string>} */ ({
504
- semibold: '600',
505
- 'semi-bold': '600',
506
- medium: '500',
507
- regular: '400',
508
- normal: '400',
509
- })[w]
527
+ ? HEADING_WEIGHTS[w === 'normal' ? 'regular' : w.replace('-', '')]
510
528
  : null;
511
529
  }
512
530
 
@@ -519,11 +537,25 @@ function scaled(v, f) {
519
537
  }
520
538
 
521
539
  /**
522
- * Words for parts, longest phrase first. Each gives the part (or group),
523
- * and maybe a `--when` condition, a heading level or a font role.
524
- * @type {Array<[RegExp, {on: string, when?: string, role?: string, level?: string}]>}
540
+ * @typedef {{on: string, when?: string, role?: string, level?: string}} PartRef
541
+ */
542
+
543
+ /**
544
+ * Phrases for parts that Core's catalog cannot give: groups, variants,
545
+ * font roles, phrases of several words, and words two components share.
546
+ * They are read before the catalog's names and doc keywords
547
+ * (partLexicon), longest phrase first.
548
+ * @type {Array<[RegExp, PartRef]>}
525
549
  */
526
- const PARTS = [
550
+ const OVERRIDES = [
551
+ [/\bdividers?\b/, {on: 'divider'}],
552
+ [
553
+ /\baccordions? (headers?|triggers?|titles?|headings?)\b/,
554
+ {on: 'collapsible-trigger'},
555
+ ],
556
+ [/\baccordions?\b/, {on: 'collapsible'}],
557
+ [/\bcombo ?box(es)?\b/, {on: 'complex-selector'}],
558
+ [/\bnotifications?\b/, {on: 'toast'}],
527
559
  [/\b(focus (ring|outline)s?)\b/, {on: 'focus-ring'}],
528
560
  [/\b((modal |dialog )?(overlay|scrim|backdrop))\b/, {on: 'overlay'}],
529
561
  [/\bicons?\b/, {on: 'icons'}],
@@ -546,6 +578,8 @@ const PARTS = [
546
578
  {on: 'dropdown-menu-item'},
547
579
  ],
548
580
  [/\b(nav(igation)? (links?|items?))\b/, {on: 'top-nav-item'}],
581
+ [/\b((dropdown |context )?menus?)\b/, {on: 'dropdown-menu'}],
582
+ [/\bfooters?\b/, {on: 'layout-footer'}],
549
583
  [/\b(side ?nav|sidebar|side ?panel)\b/, {on: 'side-nav'}],
550
584
  [
551
585
  /\b(app (name|title)|logo|site title|product name)\b/,
@@ -564,13 +598,11 @@ const PARTS = [
564
598
  /\b(danger|destructive|delete) (buttons?|ones?|variant)\b/,
565
599
  {on: 'button', when: 'variant:destructive'},
566
600
  ],
567
- [/\bbuttons?\b/, {on: 'button'}],
568
- [/\bcards?\b/, {on: 'card'}],
569
601
  [/\b(panels?|windows?|boxes|tiles?|containers?)\b/, {on: 'containers'}],
570
602
  [/\b(banners?|alerts?|notices?|announcements?)\b/, {on: 'banner'}],
571
603
  [/\b(text ?areas?|multi-?line (inputs?|fields?))\b/, {on: 'text-area'}],
572
604
  [
573
- /\b(select (dropdowns?|menus?|box(es)?|inputs?)|selects|dropdowns?|pickers?)\b/,
605
+ /\b(select (dropdowns?|menus?|box(es)?|inputs?)|selects|dropdowns?|pickers?|select(?! (the|a|an|all|any|one|which|what|it|them)\b))\b/,
574
606
  {on: 'selector'},
575
607
  ],
576
608
  [/\b(skeletons?( loaders?)?|loading placeholders?)\b/, {on: 'skeleton'}],
@@ -586,20 +618,82 @@ const PARTS = [
586
618
  ],
587
619
  [/\b((table )?cells?)\b/, {on: 'table-cell'}],
588
620
  [/\b(table rows?|rows?|tables?)\b/, {on: 'table-row'}],
589
- [/\btabs?\b/, {on: 'tab'}],
590
621
  [/\b(badges?|chips?|tags?)\b/, {on: 'badge'}],
591
622
  [/\bh([1-4])\b/, {on: 'heading'}],
592
623
  [/\b(headings?|titles?)\b/, {on: 'heading'}],
593
- [/\b(dialogs?|modals?|popups?)\b/, {on: 'dialog'}],
594
- [/\btooltips?\b/, {on: 'tooltip'}],
595
- [/\bpopovers?\b/, {on: 'popover'}],
596
- [/\btoasts?\b/, {on: 'toast'}],
597
- [/\bavatars?\b/, {on: 'avatar'}],
598
- [/\blinks?\b/, {on: 'link'}],
624
+ [/\b(modals?|popups?)\b/, {on: 'dialog'}],
599
625
  [/\bcode\b/, {on: 'code', role: 'code'}],
600
626
  [/\bbody( text)?\b/, {on: 'body', role: 'body'}],
601
627
  ];
602
628
 
629
+ /**
630
+ * Target names in Core's catalog that are plain words a question uses for
631
+ * something else ("more padding", "align the text").
632
+ */
633
+ const NOT_PART_WORDS = new Set([
634
+ 'center',
635
+ 'grid',
636
+ 'item',
637
+ 'layout',
638
+ 'list',
639
+ 'outline',
640
+ 'section',
641
+ 'stack',
642
+ 'step',
643
+ 'token',
644
+ ]);
645
+
646
+ /** A word without its plural ending. @param {string} w */
647
+ const singular = w =>
648
+ /(x|ch|sh|ss)es$/.test(w)
649
+ ? w.slice(0, -2)
650
+ : /[^s]s$/.test(w)
651
+ ? w.slice(0, -1)
652
+ : w;
653
+
654
+ /** @type {WeakMap<object, {parts: Array<[RegExp, PartRef]>, vocab: string[]}>} */
655
+ const lexicons = new WeakMap();
656
+
657
+ /**
658
+ * The words for parts: the overrides, then every theming target's name read
659
+ * from Core's catalog, longest first; and the words a near miss is
660
+ * corrected to.
661
+ * @param {import('./_settings.mjs').Ctx} ctx
662
+ */
663
+ function partLexicon(ctx) {
664
+ const {project} = ctx;
665
+ const known = lexicons.get(project);
666
+ if (known) return known;
667
+ // A one-word name how reads as something else is never a part's name:
668
+ // "text" is an aspect, "overlay" and "code" have overrides.
669
+ const other = (/** @type {string} */ w) =>
670
+ NOT_PART_WORDS.has(w) ||
671
+ aspectsOf(w).includes(w) ||
672
+ Object.hasOwn(DIALS, w) ||
673
+ OVERRIDES.some(([re]) => re.test(` ${w} `) || re.test(` ${w}s `));
674
+ /** @type {Array<[RegExp, PartRef]>} */
675
+ const derived = [...project.target.keys()]
676
+ .filter(key => key.includes('-') || !other(key))
677
+ .sort((x, y) => y.length - x.length)
678
+ .map(key => [
679
+ new RegExp(`\\b${key.replace(/-/g, '[\\s-]?')}s?\\b`),
680
+ {on: key},
681
+ ]);
682
+ // Near misses are corrected to one-word part names and design words.
683
+ const vocab = [
684
+ ...new Set([
685
+ ...DESIGN_WORDS,
686
+ ...Object.keys(HUES).filter(w => w.length >= 5),
687
+ ...[...project.target.keys()]
688
+ .filter(key => !key.includes('-'))
689
+ .flatMap(key => [key, `${key}s`]),
690
+ ]),
691
+ ];
692
+ const lex = {parts: [...OVERRIDES, ...derived], vocab};
693
+ lexicons.set(project, lex);
694
+ return lex;
695
+ }
696
+
603
697
  /** Words for a color the theme generates. */
604
698
  const ROLE_WORDS =
605
699
  /\b(accent|brand|primary colou?r|main colou?r|key colou?r|errors?|danger|destructive|success|positive|warnings?|caution|info|notices?|neutrals?)\b|\bprimary\s*:?\s*(?=#|rgb|hsl|oklch)/;
@@ -614,8 +708,21 @@ const STATE_WORDS = /** @type {Array<[RegExp, string]>} */ ([
614
708
  /\b(selected|active (tab|nav|item|link|page))\b|\bactive\b(?=.*\b(nav|tab|item)\b)/,
615
709
  'selected',
616
710
  ],
617
- [/\b(pressed|clicked|tapped|on press|on click)\b/, 'active'],
711
+ [
712
+ /\b(press(ed|es)?|click(ed|s)?|tap(ped|s)?(?! targets?)|on press|on click|when i click)\b/,
713
+ 'active',
714
+ ],
715
+ [/\b(typing|type in|tab to|tabbing|keyboard focus)\b/, 'focus'],
716
+ [/\b(after i check|once checked|i check)\b/, 'checked'],
717
+ [/\b(picked|chosen|choose|pick)\b/, 'selected'],
618
718
  [/\b(invalid|errors? state|has an error|with an error)\b/, 'invalid'],
719
+ // Words for states a part may not have: the answer says so.
720
+ [/\bread-?only\b/, 'readonly'],
721
+ [
722
+ /\bloading\b(?! (bars?|placeholders?|skeletons?|spinners?|states?|indicators?))/,
723
+ 'loading',
724
+ ],
725
+ [/\b(unchecked|not checked|unticked)\b/, 'unchecked'],
619
726
  ]);
620
727
 
621
728
  /**
@@ -634,6 +741,7 @@ const STATE_WORDS = /** @type {Array<[RegExp, string]>} */ ([
634
741
  * @property {boolean} except - "but not on X": X keeps what the clause before does
635
742
  * @property {Record<string, string>} decl - CSS written as `prop: value`
636
743
  * @property {string[]} [quoted] - family names the clause writes in quotes
744
+ * @property {{prop: string, value: string, bad?: string} | null} named - a CSS property the clause names, with its value as typed
637
745
  */
638
746
 
639
747
  /**
@@ -660,7 +768,7 @@ function aspectsOf(text) {
660
768
  )
661
769
  add('corners');
662
770
  if (
663
- /\b(shadows?|elevat\w*|depth|raised|lifts?|lifted|lifting|glow\w*|bevel\w*|sunken|inset|flat)\b/.test(
771
+ /\b(shadows?|shadowy|elevat\w*|depth|raised|lifts?|lifted|lifting|glow\w*|bevel\w*|sunken|inset|flat)\b/.test(
664
772
  c,
665
773
  )
666
774
  )
@@ -688,7 +796,9 @@ function aspectsOf(text) {
688
796
  if (/\bitalics?\b/.test(c)) add('italic');
689
797
  if (
690
798
  /\b(bold(er)?|unbold\w*|weight|heav(y|ier)|semibold)\b/.test(c) ||
691
- /\bthin(ner)? (font|text|type|letters|headings?|labels?)\b/.test(c) ||
799
+ /\bthin(ner)? (body |button |heading |label )?(font|text|type|letters|headings?|labels?|copy)\b/.test(
800
+ c,
801
+ ) ||
692
802
  (/\blight(er)?\b/.test(c) &&
693
803
  /\b(headings?|titles?|font|weight)\b/.test(c) &&
694
804
  !/\b(text|colou?r|mode|background|bg)\b/.test(c))
@@ -712,6 +822,9 @@ function aspectsOf(text) {
712
822
  (/\b(bigger|larger|smaller)\b/.test(c) &&
713
823
  /\b(text|font|headings?|titles?|h[1-6]|body)\b/.test(c)) ||
714
824
  /\b\d+(px|rem) (text|font|labels?|type)\b/.test(c) ||
825
+ /\b(text|font|headings?|titles?|labels?|h[1-6])\s+\d+(\.\d+)?(px|rem|em|pt)\b/.test(
826
+ c,
827
+ ) ||
715
828
  /\b(text|font|type)( is)? (way |far |much )?too (small|tiny|big|large)\b|\btoo (small|tiny) to read\b/.test(
716
829
  c,
717
830
  ) ||
@@ -725,7 +838,12 @@ function aspectsOf(text) {
725
838
  (/\b(thick(er)?|thin(ner)?)\b/.test(c) &&
726
839
  /\b(progress|underline|indicator)/.test(c))) &&
727
840
  !a.includes('fontsize') &&
728
- !a.includes('tracking')
841
+ !a.includes('tracking') &&
842
+ // "a bigger shadow" is a stronger shadow, not a bigger part.
843
+ !(
844
+ a.includes('shadow') &&
845
+ !/\b(taller|shorter|wider|narrower|width|height|tall)\b/.test(c)
846
+ )
729
847
  )
730
848
  add('size');
731
849
  if (
@@ -734,19 +852,36 @@ function aspectsOf(text) {
734
852
  )
735
853
  add('family');
736
854
  if (!a.length && /\b(thick(er)?|thin(ner)?)\b/.test(c)) add('border');
855
+ // "faster hover transitions", "fade in slower": motion, not opacity.
737
856
  if (
738
- /\b(faded|fade|opacity|see-through|washed out)\b/.test(c) ||
739
- (/\d+%/.test(
740
- c.replace(/\b(?:rgba?|hsla?|hwb|lab|lch|oklab|oklch)\([^)]*\)/g, ''),
857
+ /\b(transitions?|animations?|animate[sd]?|fade[sd]? (in|out)|motion)\b/.test(
858
+ c,
741
859
  ) &&
860
+ /\b(fast(er)?|slow(er)?|quick(er)?|snappier|speed|duration|\d+m?s|off|no|none|disable|stop|remove)\b/.test(
861
+ c,
862
+ )
863
+ ) {
864
+ a.splice(0, a.length);
865
+ add('motion');
866
+ return a;
867
+ }
868
+ if (
869
+ /\b(faded|fade|opacity|see-through|washed out)\b/.test(c) ||
870
+ // A percent is an opacity only beside an opacity word, never inside a
871
+ // function or after a color ("#2563eb 0%" is a gradient stop).
872
+ (/\d+%/.test(withoutFunctions(c)) &&
873
+ /\b(transparent|translucent|opaque|alpha|visible)\b/.test(c) &&
742
874
  !a.includes('corners'))
743
875
  )
744
876
  add('opacity');
745
- if (/\b(scales? (down|up)|shrinks?|grows?)\b/.test(c)) add('scale');
877
+ if (/\b(scales? (down|up)|shrinks?|grows?|scale\s*:?\s*0?\.\d+)\b/.test(c))
878
+ add('scale');
746
879
  if (
747
880
  (/\b(text|writing|words|labels?|font colou?r|readable|links?|body copy)\b/.test(
748
881
  c,
749
882
  ) ||
883
+ // "heading color red": a part that is only text has a text color.
884
+ /\b(headings?|titles?|h[1-6]) colou?rs?\b/.test(c) ||
750
885
  /\b(buttons?|links?) colou?r\b/.test(c)) &&
751
886
  !a.some(x =>
752
887
  ['case', 'italic', 'weight', 'family', 'fontsize', 'tracking'].includes(
@@ -773,9 +908,10 @@ const FONT_NAMES = [...Object.keys(OPEN_FONTS), ...Object.keys(FONTS)]
773
908
  /**
774
909
  * Read a question into clauses.
775
910
  * @param {string} q lower-case, translated, corrected
911
+ * @param {Array<[RegExp, PartRef]>} partWords
776
912
  * @returns {Clause[]}
777
913
  */
778
- function clausesOf(q) {
914
+ function clausesOf(q, partWords) {
779
915
  // "swap X and Y" is one ask.
780
916
  const pieces = (/\bswap\b/.test(q) ? q.replace(/\band\b/g, '&') : q)
781
917
  .split(
@@ -786,9 +922,16 @@ function clausesOf(q) {
786
922
  return pieces.map(text => {
787
923
  /** @type {Clause['parts']} */
788
924
  const parts = [];
789
- let rest = ` ${text} `;
925
+ // A property name is not a part: "backdrop-filter" names no backdrop.
926
+ let rest = ` ${text} `
927
+ // "when I tab to a link": the key, not the tab part.
928
+ .replace(/\b(i |we |you )?tab(bing)? (to|through|into)\b/g, ' ')
929
+ .replace(/\bvar\([^)]*\)|--[a-z][\w-]*/g, ' ')
930
+ .replace(/\b[a-z]+(?:-[a-z]+)+\b/g, m =>
931
+ cssProperties().has(m) ? ' ' : m,
932
+ );
790
933
  const cornerWords = /\b(round|corner|radius|shape|circular)/.test(text);
791
- for (const [re, part] of PARTS) {
934
+ for (const [re, part] of partWords) {
792
935
  const m = re.exec(rest);
793
936
  if (!m) continue;
794
937
  const p = {...part};
@@ -803,12 +946,27 @@ function clausesOf(q) {
803
946
  parts.push(p);
804
947
  rest = rest.replace(re, ' ');
805
948
  }
949
+ // "list rounder": a catalog name that is also a plain word is the part
950
+ // when the clause names no other part and asks for a shape change.
951
+ const shapeAsk =
952
+ /\b(round\w*|corners?|radius|shadows?|borders?|padding|bold\w*|bigger|smaller|taller|wider)\b/;
953
+ if (!parts.length && shapeAsk.test(text))
954
+ for (const w of NOT_PART_WORDS)
955
+ if (new RegExp(`\\b${w}s?\\b`).test(text)) {
956
+ parts.push({on: w});
957
+ break;
958
+ }
806
959
  // "pill" names a corner shape, not a badge, when the clause is about shape.
807
960
  if (cornerWords || /\bpill( shaped)?\b/.test(text))
808
961
  for (let i = parts.length - 1; i >= 0; i--)
809
962
  if (parts[i].on === 'badge' && !/\b(badges?|chips?|tags?)\b/.test(text))
810
963
  parts.splice(i, 1);
811
- const aspects = aspectsOf(text);
964
+ // "Space Grotesk headings": a font's name is a font, never its words.
965
+ const aspects = aspectsOf(
966
+ text
967
+ .replace(new RegExp(`\\b(${FONT_NAMES})\\b`, 'g'), ' font ')
968
+ .replace(/\bspace (mono|grotesk|grotesque)\b/g, ' font '),
969
+ );
812
970
  // "orange not red" negates a color, not the change.
813
971
  const hue = Object.keys(HUES).join('|');
814
972
  const negText = text.replace(
@@ -818,17 +976,26 @@ function clausesOf(q) {
818
976
  ),
819
977
  ' ',
820
978
  );
979
+ // "shouldn't links be underlined?": a question that asks for it.
980
+ const askedFor =
981
+ /^(shouldn'?t|wouldn'?t|isn'?t|aren'?t|can'?t|couldn'?t) .*\?$/.test(
982
+ text.trim(),
983
+ ) ||
984
+ (/^(shouldn'?t|wouldn'?t|isn'?t|aren'?t)\b/.test(text.trim()) &&
985
+ /\?/.test(text));
821
986
  const neg =
987
+ !askedFor &&
822
988
  /\b(no|not|nothing|none of|don'?t|do not|never|without|remove|removing|get rid of|lose|drop|ditch|nix|scrap|kill|none|shouldn'?t|should not|mustn'?t|turn off|turn (the|it|them) off|switch off|stop|unbold\w*|unround\w*|disable|(?:revert|undo|take back) (?:the|those|that|these|my|our|all)|(?:shadows?|borders?|underlines?|outlines?|gradients?|uppercase|caps) (?:off|out|gone))\b/.test(
823
989
  negText
824
990
  .replace(/\bdisabled\b/g, ' ')
825
991
  // "not round enough" asks for more; "not so much" for less.
826
992
  .replace(/\bnot (\w+ ){0,2}enough\b/g, ' ')
827
993
  .replace(/\bnot (so|as|that|too) (much|many)\b/g, ' '),
828
- ) && !/\bno (wait|longer)\b/.test(negText);
994
+ ) &&
995
+ !/\bno (wait|longer)\b/.test(negText);
829
996
  // "too X" asks for less X: too sharp is rounder, too heavy is lighter.
830
997
  const tooLess =
831
- /\btoo (big|large|round|rounded|bold|heavy|thick|dark|spacious|airy|bright|loud|strong|harsh|much|wide|tall)\b/;
998
+ /\btoo (big|large|round|rounded|roundy|bubbly|shadowy|bold|heavy|thick|dark|spacious|airy|bright|loud|strong|harsh|aggressive|intense|garish|saturated|much|wide|tall)\b/;
832
999
  const tooMore =
833
1000
  /\btoo (small|cramped|tight|crowded|faded|light|thin|sharp|square|boxy|pointy|subtle|weak|narrow|dim|low|short)\b/;
834
1001
  const dir = /\bnot (\w+ ){0,2}enough\b/.test(text)
@@ -837,11 +1004,11 @@ function clausesOf(q) {
837
1004
  ? 'less'
838
1005
  : tooMore.test(text)
839
1006
  ? 'more'
840
- : /\b(less|fewer|smaller|lower|reduce|softer|lighter|thinner|narrower|shorter|tight(er)?|dense(r)?|denser|compact|sharper|squarer|subtler|tone down|dimmer)\b/.test(
1007
+ : /\b(less|fewer|smaller|lower|reduce|softer|lighter|lighten|thinner|narrower|shorter|tight(en|er)?|dense(r)?|denser|compact|sharper|squarer|subtler|tone down|dimmer|halve|half|halved|least|minimum|min|minimal|barely|as little)\b|\bcut\b.*\bin half\b|\bx ?0?\.\d+\b|\b(knock|turn|dial|bring|tone)\b.*\bdown\b/.test(
841
1008
  text,
842
1009
  )
843
1010
  ? 'less'
844
- : /\b(more|bigger|larger|higher|increase|stronger|thicker|wider|taller|rounder|roomier|airy|spacious|bolder|heavier|darker|a bit|a little|slightly|much)\b/.test(
1011
+ : /\b(more|bigger|larger|higher|increase|stronger|thicker|wider|taller|rounder|roomier|airy|spacious|bolder|heavier|darker|darken|loosen|open up|twice|double|a bit|a little|slightly|much)\b/.test(
845
1012
  text,
846
1013
  )
847
1014
  ? 'more'
@@ -864,10 +1031,14 @@ function clausesOf(q) {
864
1031
  break;
865
1032
  }
866
1033
  const mode =
867
- /\bdark( mode| theme)?\b/.test(text) &&
868
- /\b(mode|theme|in dark)\b/.test(text)
1034
+ (/\bdark( mode| theme)?\b/.test(text) &&
1035
+ /\b(mode|theme|in dark)\b/.test(text)) ||
1036
+ // Only mode phrases: "all day" or "the selected day" is no mode.
1037
+ /\bnight (mode|theme)\b|\bat night\b|\boled\b|^dark\s*:/.test(text)
869
1038
  ? 'dark'
870
- : /\blight (mode|theme)\b/.test(text)
1039
+ : /\blight (mode|theme)\b|\bday ?time\b|\bday (mode|theme)\b|\bin the day\b|^light\s*:/.test(
1040
+ text,
1041
+ )
871
1042
  ? 'light'
872
1043
  : null;
873
1044
  const except =
@@ -880,11 +1051,16 @@ function clausesOf(q) {
880
1051
  text,
881
1052
  parts,
882
1053
  aspects,
1054
+ named: namedProperty(text),
883
1055
  neg,
884
1056
  dir,
885
1057
  colors: colorsIn(text),
886
1058
  bad: badHex(text),
887
- lengths: lengthsIn(text),
1059
+ // A typed clamp() or calc() is a length, kept whole.
1060
+ lengths: [
1061
+ ...(text.match(/\b(?:clamp|calc|min|max)\([^)]*\)/g) ?? []),
1062
+ ...lengthsIn(text),
1063
+ ],
888
1064
  state,
889
1065
  mode,
890
1066
  except,
@@ -893,6 +1069,309 @@ function clausesOf(q) {
893
1069
  });
894
1070
  }
895
1071
 
1072
+ /**
1073
+ * A CSS property the clause names, with its value kept whole ("caret-color
1074
+ * #2563eb", "transition: background-color 150ms ease", "border-radius 12px
1075
+ * 12px 0 0"). The value runs to the end of the clause or the part it is
1076
+ * for, and is the longest start of it the property's grammar accepts.
1077
+ * Plain words that are also properties ("color", "padding") count only
1078
+ * with a colon; the aspect words read those.
1079
+ * @param {string} text
1080
+ * @returns {{prop: string, value: string, bad?: string} | null}
1081
+ */
1082
+ export function namedProperty(text) {
1083
+ const props = cssProperties();
1084
+ const flat = text.replace(/\u2e34/g, ',');
1085
+ for (const m of flat.matchAll(
1086
+ /\b((?:border|outline)(?: (?:top|right|bottom|left))? (?:colou?r|width|style)|(?:min|max) (?:height|width)|line height|letter spacing|font (?:size|weight)|radius|[a-z]+(?:-[a-z]+)+|[a-z]+)(\s*:)?\s*/g,
1087
+ )) {
1088
+ const prop =
1089
+ PROPERTY_WORDS[m[1]] ??
1090
+ (/^(border|outline)( (top|right|bottom|left))? (colou?r|width|style)$/.test(
1091
+ m[1],
1092
+ )
1093
+ ? m[1].replace(/colour/, 'color').replace(/ /g, '-')
1094
+ : m[1]);
1095
+ // A property word right after another one ("border width") is part of
1096
+ // it, never a property of its own.
1097
+ if (
1098
+ /\b(border|outline)\s*$/.test(flat.slice(0, m.index ?? 0)) &&
1099
+ !m[1].startsWith('border') &&
1100
+ m[1] !== 'radius'
1101
+ )
1102
+ continue;
1103
+ if (!props.has(prop)) continue;
1104
+ // A plain word ("background", "padding") without a colon is a property
1105
+ // only before a value that is typed, not described.
1106
+ const plain = !m[2] && !/[- ]/.test(m[1]);
1107
+ // Without a colon, only these plain words name a property; others
1108
+ // ("inset", "fill") are design words.
1109
+ if (plain && !PLAIN_PROPERTIES.has(prop)) continue;
1110
+ // "shadow opacity", "border opacity": a layer's alpha, not the part's.
1111
+ if (
1112
+ prop === 'opacity' &&
1113
+ /\b(shadows?|backgrounds?|bg|borders?|outlines?)\s*$/.test(
1114
+ flat.slice(0, m.index ?? 0),
1115
+ )
1116
+ )
1117
+ continue;
1118
+ const rest = flat
1119
+ .slice((m.index ?? 0) + m[0].length)
1120
+ .replace(/^(?:to|of|is|=)\s+/, '')
1121
+ .replace(
1122
+ /\s+(?:on|for|in|when|while|if)\s+(?:the\s+|all\s+|every\s+)?[a-z][\w-]*.*$/,
1123
+ '',
1124
+ )
1125
+ .trim();
1126
+ const tokens = valueWords(rest);
1127
+ // "padding NaNpx": a length the property cannot take.
1128
+ if (
1129
+ tokens[0] &&
1130
+ /^(?:nan|[\d.]+[a-z]*)(px|rem|em)$/.test(tokens[0]) &&
1131
+ !matchValue(prop, tokens[0])
1132
+ )
1133
+ return {prop, value: '', bad: tokens[0]};
1134
+ if (
1135
+ plain &&
1136
+ (!/^(?:[-.\d#]|[a-z-]+\(|transparent\b|none\b|normal\b|currentcolor\b)/.test(
1137
+ rest,
1138
+ ) ||
1139
+ // "a #e5e7eb border" has no width: the border answer gives one.
1140
+ (prop === 'border' && /^#/.test(rest)))
1141
+ )
1142
+ continue;
1143
+ // "border 0 0 2px": lengths alone on a border are its widths, all kept.
1144
+ const lengths = tokens.filter(t => /^(0|\d*\.?\d+(px|rem|em))$/.test(t));
1145
+ if (
1146
+ /^(border|outline)$/.test(prop) &&
1147
+ lengths.length > 1 &&
1148
+ lengths.length === tokens.length &&
1149
+ matchValue(`${prop}-width`, tokens.join(' '))
1150
+ )
1151
+ return {prop: `${prop}-width`, value: tokens.join(' ')};
1152
+ for (let n = tokens.length; n > 0; n--) {
1153
+ const value = tokens
1154
+ .slice(0, n)
1155
+ .join(' ')
1156
+ .replace(/[.;,]+$/, '');
1157
+ // A font size of 0 hides the text.
1158
+ if (prop === 'font-size' && /^0(px|rem|em)?$/.test(value))
1159
+ return {prop, value: '', bad: value};
1160
+ if (!value || !matchValue(prop, value)) continue;
1161
+ // A value that drops typed words is not the one asked for: "border
1162
+ // 0 0 2px" is not "border 0".
1163
+ if (n < tokens.length && /^[-.\d#]/.test(tokens[n] ?? '')) break;
1164
+ return completeShorthand(prop, value);
1165
+ }
1166
+ }
1167
+ return null;
1168
+ }
1169
+
1170
+ /**
1171
+ * A shorthand value made complete, so it does what was asked: a border or
1172
+ * outline with no line style draws nothing, and a text-decoration with
1173
+ * only a color takes the underline away. Lengths alone are the width, a
1174
+ * color alone is the color, and a width with a color gets a solid line.
1175
+ * @param {string} prop
1176
+ * @param {string} value
1177
+ * @returns {{prop: string, value: string}}
1178
+ */
1179
+ function completeShorthand(prop, value) {
1180
+ const words = valueWords(value);
1181
+ const isLength = (/** @type {string} */ w) =>
1182
+ /^(0|-?\d*\.?\d+(px|rem|em|pt)|thin|medium|thick)$/.test(w) ||
1183
+ /^(calc|var)\(/.test(w);
1184
+ const isColor = (/** @type {string} */ w) =>
1185
+ Boolean(parseColor(w)) ||
1186
+ /^(var|color-mix|light-dark)\(/.test(w) ||
1187
+ w === 'transparent' ||
1188
+ w === 'currentcolor';
1189
+ const styled = words.some(w =>
1190
+ /^(none|hidden|solid|dashed|dotted|double|groove|ridge|inset|outset|auto)$/.test(
1191
+ w,
1192
+ ),
1193
+ );
1194
+ // "border 0" takes the border away, as typed.
1195
+ if (/^(border|outline)$/.test(prop) && value === '0') return {prop, value};
1196
+ if (/^(border|outline)(-(top|right|bottom|left))?$/.test(prop) && !styled) {
1197
+ if (words.every(isLength))
1198
+ return {
1199
+ prop:
1200
+ prop === 'outline'
1201
+ ? 'outline-width'
1202
+ : `${prop.replace(/-(top|right|bottom|left)$/, '')}${/-(top|right|bottom|left)$/.test(prop) ? prop.slice(prop.lastIndexOf('-')) : ''}-width`,
1203
+ value,
1204
+ };
1205
+ if (words.every(isColor)) return {prop: `${prop}-color`, value};
1206
+ if (words.length === 2 && words.some(isLength) && words.some(isColor)) {
1207
+ const len = /** @type {string} */ (words.find(isLength));
1208
+ const col = /** @type {string} */ (words.find(isColor));
1209
+ return {prop, value: `${len} solid ${col}`};
1210
+ }
1211
+ }
1212
+ if (prop === 'text-decoration' && words.every(isColor))
1213
+ return {prop: 'text-decoration-color', value};
1214
+ return {prop, value};
1215
+ }
1216
+
1217
+ /** Plain words that name a property without a colon, before a typed value. */
1218
+ const PLAIN_PROPERTIES = new Set([
1219
+ 'background',
1220
+ 'opacity',
1221
+ 'border',
1222
+ 'border-radius',
1223
+ 'border-color',
1224
+ 'padding',
1225
+ 'margin',
1226
+ 'gap',
1227
+ 'filter',
1228
+ 'width',
1229
+ 'height',
1230
+ 'min-height',
1231
+ 'max-height',
1232
+ 'min-width',
1233
+ 'max-width',
1234
+ 'line-height',
1235
+ 'letter-spacing',
1236
+ 'font-size',
1237
+ 'font-weight',
1238
+ 'outline',
1239
+ 'transition',
1240
+ 'transform',
1241
+ ]);
1242
+
1243
+ /** Words people write for a CSS property. */
1244
+ const PROPERTY_WORDS = /** @type {Record<string, string>} */ ({
1245
+ radius: 'border-radius',
1246
+ 'min height': 'min-height',
1247
+ 'max height': 'max-height',
1248
+ 'min width': 'min-width',
1249
+ 'max width': 'max-width',
1250
+ 'line height': 'line-height',
1251
+ 'letter spacing': 'letter-spacing',
1252
+ 'font size': 'font-size',
1253
+ 'font weight': 'font-weight',
1254
+ 'border color': 'border-color',
1255
+ 'border colour': 'border-color',
1256
+ });
1257
+
1258
+ /**
1259
+ * The words of a value, with each function call kept whole, nested calls
1260
+ * included ("linear-gradient(135deg, rgba(0,0,0,.1) 0%, #fff 100%)").
1261
+ * @param {string} rest
1262
+ * @returns {string[]}
1263
+ */
1264
+ function valueWords(rest) {
1265
+ /** @type {string[]} */
1266
+ const out = [];
1267
+ let word = '';
1268
+ let depth = 0;
1269
+ for (const ch of rest) {
1270
+ if (ch === '(') depth++;
1271
+ if (ch === ')') depth = Math.max(0, depth - 1);
1272
+ if (/\s/.test(ch) && !depth) {
1273
+ if (word) out.push(word);
1274
+ word = '';
1275
+ } else word += ch;
1276
+ }
1277
+ if (word) out.push(word);
1278
+ return out;
1279
+ }
1280
+
1281
+ /**
1282
+ * Text with every CSS function call taken out, nested calls included.
1283
+ * @param {string} text
1284
+ */
1285
+ function withoutFunctions(text) {
1286
+ let out = '';
1287
+ let depth = 0;
1288
+ for (let i = 0; i < text.length; i++) {
1289
+ const ch = text[i];
1290
+ if (ch === '(' && (depth || /[\w-]$/.test(out))) {
1291
+ if (!depth) out = out.replace(/[\w-]+$/, '');
1292
+ depth++;
1293
+ } else if (ch === ')' && depth) depth--;
1294
+ else if (!depth) out += ch;
1295
+ }
1296
+ return out;
1297
+ }
1298
+
1299
+ /** The settings each aspect names, for a reset; `*` matches a prefix. */
1300
+ const RESET_THINGS = /** @type {Record<string, string[]>} */ ({
1301
+ corners: ['corners', 'border-radius', '--radius-*'],
1302
+ spacing: ['spacing', 'padding', 'gap', 'margin', '--spacing-*'],
1303
+ family: ['font', 'font-family', '--font-family-*'],
1304
+ background: ['background', 'background-color'],
1305
+ text: ['color', '--color-text-*'],
1306
+ shadow: ['box-shadow', 'surfaces', '--shadow-*'],
1307
+ border: [
1308
+ 'border',
1309
+ 'border-width',
1310
+ 'border-color',
1311
+ '--border-width',
1312
+ '--color-border',
1313
+ ],
1314
+ weight: ['headings', 'font-weight', '--text-body-weight'],
1315
+ fontsize: ['text-size', 'type', 'font-size'],
1316
+ leading: ['line-height', '--text-body-leading'],
1317
+ tracking: ['letter-spacing'],
1318
+ });
1319
+
1320
+ /** Words for a color the theme generates: the word, its dial, its token. */
1321
+ const ROLE_DIALS = /** @type {Array<[RegExp, string, string]>} */ ([
1322
+ [/\b(accent|brand|primary colou?r)\b/, 'accent', '--color-accent'],
1323
+ [/\b(danger|errors?)\b/, 'danger', '--color-error'],
1324
+ [/\bsuccess\b/, 'success', '--color-success'],
1325
+ [/\bwarnings?\b/, 'warning', '--color-warning'],
1326
+ [/\binfo\b/, 'info', '--color-info'],
1327
+ [/\b(neutrals?|grays?|greys?)\b/, 'neutral', '--color-neutral'],
1328
+ ]);
1329
+
1330
+ /** Number words, longest phrase first. */
1331
+ const NUMBER_WORDS = /** @type {Record<string, number>} */ ({
1332
+ zero: 0,
1333
+ one: 1,
1334
+ two: 2,
1335
+ three: 3,
1336
+ four: 4,
1337
+ five: 5,
1338
+ six: 6,
1339
+ seven: 7,
1340
+ eight: 8,
1341
+ nine: 9,
1342
+ ten: 10,
1343
+ eleven: 11,
1344
+ twelve: 12,
1345
+ thirteen: 13,
1346
+ fourteen: 14,
1347
+ fifteen: 15,
1348
+ sixteen: 16,
1349
+ seventeen: 17,
1350
+ eighteen: 18,
1351
+ nineteen: 19,
1352
+ twenty: 20,
1353
+ thirty: 30,
1354
+ forty: 40,
1355
+ fifty: 50,
1356
+ sixty: 60,
1357
+ seventy: 70,
1358
+ eighty: 80,
1359
+ ninety: 90,
1360
+ hundred: 100,
1361
+ });
1362
+ const NUMBER_WORDS_RE = new RegExp(
1363
+ `\\b(?:(?:one|a) and a half|half an?|an? quarter(?: of an?)?|an? half|(?:twenty|thirty|forty|fifty|sixty|seventy|eighty|ninety)[- ](?:one|two|three|four|five|six|seven|eight|nine)|${Object.keys(NUMBER_WORDS).join('|')})\\b(?=\\s*(?:-|\\s)?\\s*(?:px|pixels?|rem|em|pt|percent|%|radius|corners?|line height|times|x\\b|\\w+ (?:tall|wide|thick)|tall|wide|thick))`,
1364
+ 'gi',
1365
+ );
1366
+ /** A number phrase as digits. @param {string} m */
1367
+ function numberWord(m) {
1368
+ const w = m.toLowerCase().replace(/-/g, ' ');
1369
+ if (/and a half/.test(w)) return '1.5';
1370
+ if (/^(half|a half|an half)/.test(w)) return '0.5';
1371
+ if (/quarter/.test(w)) return '0.25';
1372
+ return String(w.split(' ').reduce((n, x) => n + (NUMBER_WORDS[x] ?? 0), 0));
1373
+ }
1374
+
896
1375
  /**
897
1376
  * Whether a few words name a color or a font, for "swap A for B".
898
1377
  * @param {string} words lower-case
@@ -923,6 +1402,7 @@ export function draftAnswer(ctx, env, question) {
923
1402
  const {C} = ctx;
924
1403
  const TARGET = ctx.project.target;
925
1404
  const TOKENS = ctx.project.core.tokenDefaults;
1405
+ const lex = partLexicon(ctx);
926
1406
  /** Family names written in quotes, kept as typed: qq<n>qq in the text. */
927
1407
  const quoted = /** @type {string[]} */ ([]);
928
1408
  let q = question
@@ -971,11 +1451,13 @@ export function draftAnswer(ctx, env, question) {
971
1451
  // of "IBM Plex Sans" is not the French "without".
972
1452
  .replace(/\bJetBrains\b/g, 'Jetbrains')
973
1453
  .replace(/(?<=\b[A-Z][\w-]*\s)Sans\b/g, 'Sanz')
1454
+ .replace(/\bNaN/g, 'nan')
974
1455
  .replace(/([a-z])([A-Z])/g, '$1 $2')
975
1456
  .replace(/[{}"`]/g, ' ')
976
1457
  .replace(/(?<=[a-z])\.(?=[a-z])/gi, ' ')
977
1458
  .replace(/(?<![\w-])\.(?=[a-z])/gi, ' ')
978
1459
  .replace(/\s*=\s*/g, ' ')
1460
+ .replace(/\bon\s*:\s*/g, 'on ')
979
1461
  // Near-white and near-black are their own colors.
980
1462
  .replace(/\boff[- ]?white\b/gi, '#fafafa')
981
1463
  .replace(/\boff[- ]?black\b/gi, '#111111')
@@ -985,6 +1467,45 @@ export function draftAnswer(ctx, env, question) {
985
1467
  /\bmatch\s+(?:the\s+)?(.+?)\s+to\s+(?:the\s+)?[a-z][a-z -]*?(?=\s*[(,;.]|\s*$)/gi,
986
1468
  '$1',
987
1469
  )
1470
+ // "no more than 2px": a limit, the number itself.
1471
+ .replace(/\b(?:no|not) more than\s+|\bat most\s+|\bmax(?:imum)? of\s+/g, '')
1472
+ // Numbers written as words are numbers.
1473
+ .replace(NUMBER_WORDS_RE, m => numberWord(m))
1474
+ // "8 or so px", "about 8 px": the number.
1475
+ .replace(/\b(\d+(?:\.\d+)?)\s+or so\s+(?=px|rem|em|pixels?)/g, '$1 ')
1476
+ // "0.5 rem", "14 px": a number and its unit are one length.
1477
+ .replace(/\b(\d+(?:\.\d+)?)\s+(px|rem|em|pt|vh|vw|ch)\b/gi, '$1$2')
1478
+ // Typography words for the properties they name.
1479
+ .replace(
1480
+ /\btabular (numbers|numerals|figures|nums)\b/g,
1481
+ 'font-variant-numeric: tabular-nums',
1482
+ )
1483
+ .replace(
1484
+ /\bbalance (?:the )?(?:(\w+) )?(?:line breaks|lines|wrapping)\b/g,
1485
+ '$1 text-wrap: balance',
1486
+ )
1487
+ // "hover does nothing visible": the effect is too subtle.
1488
+ .replace(
1489
+ /\b(?:does|do) nothing(?: visible)?\b|\bnothing happens\b/g,
1490
+ 'is too subtle',
1491
+ )
1492
+ // "I can barely see the borders": too faint.
1493
+ .replace(
1494
+ /\b(?:i )?(?:can )?(?:barely|hardly) see (?:the )?(\w+)/g,
1495
+ '$1 too faint',
1496
+ )
1497
+ // "11pt": points as pixels (a point is 4/3 of a pixel).
1498
+ .replace(
1499
+ /\b(\d+(?:\.\d+)?)pt\b/gi,
1500
+ (_, n) => `${Math.round((Number(n) * 4) / 3)}px`,
1501
+ )
1502
+ // "a 1px border instead of a shadow": no shadow, and the border.
1503
+ .replace(
1504
+ /^(.*?)\binstead of (?:a |an |the )?([a-z]+(?: [a-z]+)?)\b/gim,
1505
+ (m, a, b) => (a.trim() ? `no ${b} ; ${a}` : m),
1506
+ )
1507
+ // "why are my headings not bold": the complaint asks for bold.
1508
+ .replace(/\bwhy (?:is|are|isn'?t|aren'?t)\b(.*?)\bnot\s+/gi, 'make$1 ')
988
1509
  // "button padding 8", "radius 10": a bare number there is pixels.
989
1510
  .replace(
990
1511
  /\b(padding|radius|corners|gap|margin)(\s*:?\s*)(\d+(?:\.\d+)?)(?![\d.%\w])/gi,
@@ -1000,7 +1521,7 @@ export function draftAnswer(ctx, env, question) {
1000
1521
  // "12 pixels", "8 px" are lengths.
1001
1522
  .replace(/\b(\d+(?:\.\d+)?)\s*(?:pixels?|px)\b/g, '$1px')
1002
1523
  // A drop shadow is a shadow, not a "drop".
1003
- .replace(/\bdrop[- ]shadows?\b/g, 'shadow')
1524
+ .replace(/\bdrop[- ]shadows?\b(?!\s*\()/g, 'shadow')
1004
1525
  // "x 0, y 4, blur 6, spread -1, rgba(...)": one shadow value.
1005
1526
  .replace(
1006
1527
  /\bx\s*:?\s*(-?\d+)(?:px)?\s*,?\s*y\s*:?\s*(-?\d+)(?:px)?(?:\s*,?\s*blur\s*:?\s*(-?\d+)(?:px)?)?(?:\s*,?\s*spread\s*:?\s*(-?\d+)(?:px)?)?\s*,?\s*(#[0-9a-f]{3,8}|(?:rgba?|hsla?)\([^)]*\))/g,
@@ -1012,7 +1533,26 @@ export function draftAnswer(ctx, env, question) {
1012
1533
  )
1013
1534
  // A shadow's layers stay one value: the comma between them is not a
1014
1535
  // clause break.
1015
- .replace(/\)\s*,\s*(?=(?:inset\s+)?-?\d)/g, ')\u2e34 ')
1536
+ .replace(
1537
+ /(\)|#[0-9a-f]{3,8}\b)\s*,\s*(?=(?:inset\s+)?-?\d+(?:px)?\s+-?\d)/g,
1538
+ '$1\u2e34 ',
1539
+ )
1540
+ // "font-family: Georgia, serif": the font list is one value.
1541
+ .replace(
1542
+ /(\bfont[- ]family\s*:?\s*[^,;]+?)\s*,\s*(?=(?:serif|sans-serif|monospace|system-ui|cursive|ui-monospace|ui-sans-serif|ui-serif)\b)/g,
1543
+ '$1\u2e34 ',
1544
+ )
1545
+ // "rounder? or maybe not. actually yes": the ask stands.
1546
+ .replace(
1547
+ /[?.!]?\s*\b(?:or )?maybe not\b[.?!,]*\s*(?:actually|ok(?:ay)?|no wait)?,?\s*(?:yes|do it)\b[.!]*/g,
1548
+ '. ',
1549
+ )
1550
+ // "the gray text fails contrast": gray text is the secondary text,
1551
+ // when no color is typed for it.
1552
+ .replace(
1553
+ /\b(gr[ae]y|muted) text\b(?![^;,]*(#[0-9a-f]{3}|\brgb|\bhsl))/g,
1554
+ 'secondary text',
1555
+ )
1016
1556
  // "replace the shadow on cards with a border": no shadow, and a border.
1017
1557
  .replace(
1018
1558
  /\b(?:replace|swap)\s+(?:out\s+)?(?:the\s+)?((?:shadows?|borders?|gradients?|underlines?|outlines?)\b[^,;]*?)\s+(?:with|for)\s+/g,
@@ -1045,7 +1585,12 @@ export function draftAnswer(ctx, env, question) {
1045
1585
  // "bordes redondeados": rounded edges are corners.
1046
1586
  .replace(/\bborders?\s+rounded\b/g, 'rounded corners')
1047
1587
  .replace(/\bbutton-s\b/g, 'buttons')
1048
- .replace(/[a-z]+/g, w => corrected(w))
1588
+ .replace(/[a-z]+/g, w => corrected(w, lex.vocab))
1589
+ // "buttons, but not bold": the "not" is about the buttons.
1590
+ .replace(
1591
+ /,?\s*\bbut not\s+(?=(bold|italic|uppercase|rounded|round|shadowed|underlined|bordered|faded|dark|light|bright|big|small|too \w+)\b)/g,
1592
+ ' not ',
1593
+ )
1049
1594
  .replace(/\b(everything|everywhere|all) but\b/g, '$1 except')
1050
1595
  .replace(
1051
1596
  /\b(apart from|other than|excluding|but not (on|in|for)|but not)\b/g,
@@ -1053,7 +1598,7 @@ export function draftAnswer(ctx, env, question) {
1053
1598
  )
1054
1599
  .replace(/\s+/g, ' ')
1055
1600
  .trim();
1056
- const clauses = clausesOf(q);
1601
+ const clauses = clausesOf(q, lex.parts);
1057
1602
  for (const c of clauses) {
1058
1603
  c.quoted = [...c.text.matchAll(/qq(\d+)qq/g)].map(
1059
1604
  m => quoted[Number(m[1])],
@@ -1094,18 +1639,119 @@ export function draftAnswer(ctx, env, question) {
1094
1639
  c.parts = clauses[i - 1].parts.map(p => ({...p}));
1095
1640
  }
1096
1641
  }
1097
- // "success badge": a variant word right before the part.
1642
+ // "success badge", "error toasts": a value of the part's variant, type
1643
+ // or status right before the part.
1098
1644
  for (const c of clauses)
1099
1645
  for (const p of c.parts) {
1100
- if (p.when || !C.MAP[p.on]) continue;
1101
- const own = JSON.stringify(C.MAP[p.on].own ?? {});
1102
- const noun = PARTS.find(([, x]) => x.on === p.on && !x.when)?.[0];
1103
- for (const m of c.text.matchAll(/\b([a-z]+)\s+([a-z]+)\b/g))
1104
- if (own.includes(`variant=${m[1]}"`) && noun?.test(m[2])) {
1105
- p.when = `variant:${m[1]}`;
1646
+ const member = FAMILIES[p.on] ? FAMILIES[p.on][0] : p.on;
1647
+ if (p.when || !C.MAP[member]) continue;
1648
+ const vals = C.variantValues(member);
1649
+ const nouns = lex.parts.filter(([, x]) => x.on === p.on && !x.when);
1650
+ for (const m of c.text.matchAll(/\b([a-z]+)\s+([a-z]+)\b/g)) {
1651
+ const key = ['variant', 'type', 'status', 'tone', 'color'].find(k =>
1652
+ (vals[k] ?? []).includes(m[1]),
1653
+ );
1654
+ if (key && nouns.some(([re]) => re.test(` ${m[2]} `))) {
1655
+ p.when = `${key}:${m[1]}`;
1106
1656
  break;
1107
1657
  }
1658
+ }
1659
+ }
1660
+ // "cards and dialogs with no shadow", "tooltips and toasts black": parts
1661
+ // listed before the ask all take it.
1662
+ for (let i = 0; i < clauses.length - 1; i++) {
1663
+ const c = clauses[i];
1664
+ const onlyParts = (/** @type {Clause} */ x) =>
1665
+ x.parts.length &&
1666
+ !x.aspects.length &&
1667
+ !x.colors.length &&
1668
+ !x.lengths.length &&
1669
+ !x.except &&
1670
+ !x.dir &&
1671
+ !lex.parts
1672
+ .reduce((t, [re]) => t.replace(re, ' '), ` ${x.text} `)
1673
+ .replace(/\b(the|a|an|all|every|both|my|our)\b/g, ' ')
1674
+ .trim();
1675
+ if (!onlyParts(c)) continue;
1676
+ let j = i + 1;
1677
+ while (j < clauses.length && onlyParts(clauses[j])) j++;
1678
+ const ask = clauses[j];
1679
+ if (
1680
+ !ask ||
1681
+ ask.except ||
1682
+ !(
1683
+ ask.aspects.length ||
1684
+ ask.colors.length ||
1685
+ ask.lengths.length ||
1686
+ ask.dir
1687
+ )
1688
+ )
1689
+ continue;
1690
+ const listed = clauses.slice(i, j).flatMap(x => x.parts);
1691
+ ask.parts = [...listed.map(p => ({...p})), ...ask.parts];
1692
+ for (const x of clauses.slice(i, j)) {
1693
+ x.parts = [];
1694
+ x.text = '';
1695
+ }
1696
+ i = j;
1697
+ }
1698
+ // "less padding on cards but more on buttons": a part with only a
1699
+ // direction takes the aspect of the clause before it.
1700
+ for (let i = 1; i < clauses.length; i++) {
1701
+ const c = clauses[i];
1702
+ const prev = clauses[i - 1];
1703
+ if (
1704
+ c.parts.length &&
1705
+ c.dir &&
1706
+ !c.aspects.length &&
1707
+ !c.colors.length &&
1708
+ prev.aspects.length
1709
+ )
1710
+ c.aspects = [...prev.aspects];
1711
+ }
1712
+ // "thicker focus outline, 4px": a clause that is only a length is the
1713
+ // value of the clause before it, and the typed value wins over the
1714
+ // direction word.
1715
+ for (let i = 1; i < clauses.length; i++) {
1716
+ const c = clauses[i];
1717
+ const prev = clauses[i - 1];
1718
+ if (
1719
+ c.lengths.length &&
1720
+ !c.parts.length &&
1721
+ !c.aspects.length &&
1722
+ !c.colors.length &&
1723
+ prev.aspects.length &&
1724
+ c.text
1725
+ .replace(
1726
+ /\b(at least|at most|about|around|roughly|or so|min(imum)?|max(imum)?)\b/g,
1727
+ '',
1728
+ )
1729
+ .replace(/-?\d*\.?\d+(px|rem|em)/g, '')
1730
+ .trim() === ''
1731
+ ) {
1732
+ prev.lengths = [...c.lengths, ...prev.lengths];
1733
+ prev.dir = null;
1734
+ prev.text = `${prev.text} ${c.lengths.join(' ')}`;
1735
+ c.lengths = [];
1736
+ c.text = '';
1737
+ }
1738
+ }
1739
+ // "every part bold except body text": the body is left as it is, so the
1740
+ // bold goes to the headings, not the body's weight.
1741
+ for (let i = 0; i < clauses.length - 1; i++) {
1742
+ const c = clauses[i];
1743
+ const next = clauses[i + 1];
1744
+ if (
1745
+ !c.parts.length &&
1746
+ c.aspects.includes('weight') &&
1747
+ next.except &&
1748
+ next.parts.some(p => p.on === 'body')
1749
+ ) {
1750
+ c.parts = [{on: 'heading'}];
1751
+ next.parts = [];
1752
+ next.text = '';
1108
1753
  }
1754
+ }
1109
1755
  // "no shadows on cards and dialogs": a clause that only names a part
1110
1756
  // takes the ask of the clause before it.
1111
1757
  for (let i = 1; i < clauses.length; i++) {
@@ -1119,7 +1765,8 @@ export function draftAnswer(ctx, env, question) {
1119
1765
  !c.except &&
1120
1766
  prev.aspects.length &&
1121
1767
  prev.parts.length &&
1122
- !PARTS.reduce((t, [re]) => t.replace(re, ' '), ` ${c.text} `)
1768
+ !lex.parts
1769
+ .reduce((t, [re]) => t.replace(re, ' '), ` ${c.text} `)
1123
1770
  .replace(/\b(the|a|an|all|every|on|for|too|both)\b/g, ' ')
1124
1771
  .trim()
1125
1772
  ) {
@@ -1129,6 +1776,97 @@ export function draftAnswer(ctx, env, question) {
1129
1776
  c.text = `${prev.text.replace(/\bon\b.*$/, '')} ${c.text}`;
1130
1777
  }
1131
1778
  }
1779
+ // "the cards and the dialogs both need 16px radius": a clause that only
1780
+ // names a part, before one that says what to change, takes that ask
1781
+ // ("h1, h2, h3 { … }": read from the last, so each takes it in turn).
1782
+ for (let i = clauses.length - 2; i >= 0; i--) {
1783
+ const c = clauses[i];
1784
+ const next = clauses[i + 1];
1785
+ if (
1786
+ c.parts.length &&
1787
+ !c.aspects.length &&
1788
+ !c.colors.length &&
1789
+ !c.lengths.length &&
1790
+ !c.except &&
1791
+ next.aspects.length &&
1792
+ next.parts.length &&
1793
+ !lex.parts
1794
+ .reduce((t, [re]) => t.replace(re, ' '), ` ${c.text} `)
1795
+ .replace(/\b(the|a|an|all|every|on|for|both)\b/g, ' ')
1796
+ .trim()
1797
+ ) {
1798
+ const parts = c.parts;
1799
+ Object.assign(c, {...next, parts, text: next.text});
1800
+ }
1801
+ }
1802
+ // "BORDER-RADIUS: 8PX; ON: CARD": a clause that is only "on <part>" names
1803
+ // the part of the clause before it.
1804
+ for (let i = 1; i < clauses.length; i++) {
1805
+ const c = clauses[i];
1806
+ if (
1807
+ c.parts.length &&
1808
+ !c.aspects.length &&
1809
+ /^on\b/.test(c.text) &&
1810
+ !clauses[i - 1].parts.length
1811
+ ) {
1812
+ clauses[i - 1].parts = c.parts;
1813
+ c.parts = [];
1814
+ c.text = '';
1815
+ }
1816
+ }
1817
+ // "buttons feel heavy, lighten them up", "the hierarchy is flat, headings
1818
+ // need more weight": a clause that only describes the problem, before
1819
+ // one that says what to do, asks for nothing itself; the fix takes its
1820
+ // part and aspect when it names none.
1821
+ for (let i = 0; i < clauses.length - 1; i++) {
1822
+ const c = clauses[i];
1823
+ const next = clauses[i + 1];
1824
+ const describes =
1825
+ /\b(is|are|feels?|looks|seems?|fails?)\b/.test(c.text) &&
1826
+ /\b(too|so|very|really|kind of|feels?|seems?|fails?|cramped|flat|heavy|crowded|cluttered|busy|boring|bland|dull|harsh|loud|weak|hard|ugly|off)\b/.test(
1827
+ c.text,
1828
+ ) &&
1829
+ !/\d/.test(c.text) &&
1830
+ !/^(make|set|use|give|add|remove|change|put)\b/.test(c.text) &&
1831
+ !/#[0-9a-f]{3,8}\b|\(/.test(c.text) &&
1832
+ !c.lengths.length;
1833
+ if (!describes || !(next.aspects.length || next.dir) || next.colors.length)
1834
+ continue;
1835
+ if (!next.aspects.length)
1836
+ next.aspects = c.aspects.filter(
1837
+ a => a !== 'shadow' || !/\bflat\b/.test(c.text),
1838
+ );
1839
+ if (!next.parts.length) next.parts = c.parts.map(p => ({...p}));
1840
+ next.text =
1841
+ `${next.text} ${c.text.replace(/\b(is|are|feels?|looks?|seems?)\b.*$/, '')}`.trim();
1842
+ if (/\bcontrast\b/.test(c.text)) next.text += ' contrast';
1843
+ c.text = '';
1844
+ c.parts = [];
1845
+ c.aspects = [];
1846
+ c.colors = [];
1847
+ }
1848
+ // "Arial everywhere", "code blocks should use Menlo": a family named with
1849
+ // its capitals is a font ask; so is the system font by name.
1850
+ for (const c of clauses)
1851
+ if (
1852
+ !c.aspects.includes('family') &&
1853
+ (systemFamilyIn(c.text, question) || OS_FONT.test(c.text))
1854
+ )
1855
+ c.aspects.push('family');
1856
+ // "make the divider 2px": a divider's length is its thickness.
1857
+ for (const c of clauses)
1858
+ if (
1859
+ c.parts.some(p => p.on === 'divider') &&
1860
+ !c.aspects.length &&
1861
+ c.lengths.length
1862
+ )
1863
+ c.aspects = ['size'];
1864
+ // "shadow opacity 0.2": the layer's alpha is the ask, not the layer.
1865
+ for (const c of clauses)
1866
+ if (
1867
+ /\b(shadows?|backgrounds?|bg|borders?|outlines?)\s+opacity\b/.test(c.text)
1868
+ )
1869
+ c.aspects = ['opacity'];
1132
1870
  // "the table ... a header" is the table's header row.
1133
1871
  if (/\b(tables?|rows?|zebra)\b/.test(q))
1134
1872
  for (const c of clauses)
@@ -1163,7 +1901,7 @@ export function draftAnswer(ctx, env, question) {
1163
1901
  // purple"), or one for the other mode ("in light mode … in dark mode").
1164
1902
  (!prev.colors.length ||
1165
1903
  prev.neg ||
1166
- /\b(hate|dislike|not a fan|tired of|sick of)\b/.test(prev.text) ||
1904
+ /\b(hate|dislike|not a fan|tired of|sick of|too)\b/.test(prev.text) ||
1167
1905
  Boolean(c.mode && prev.mode && c.mode !== prev.mode)) &&
1168
1906
  !prev.parts.length
1169
1907
  ) {
@@ -1174,7 +1912,20 @@ export function draftAnswer(ctx, env, question) {
1174
1912
  )
1175
1913
  ? 'accent'
1176
1914
  : null);
1177
- if (role) c.text = `${role} ${c.text}`;
1915
+ if (role) {
1916
+ c.text = `${role} ${c.text}`;
1917
+ // "the danger red is too bright, use #b91c1c": the typed color is
1918
+ // the target, so the clause before it asks for nothing of its own.
1919
+ if (
1920
+ !/#[0-9a-f]{3,8}\b/.test(prev.text) &&
1921
+ prev.dir &&
1922
+ !prev.parts.length
1923
+ ) {
1924
+ prev.text = '';
1925
+ prev.colors = [];
1926
+ prev.aspects = [];
1927
+ }
1928
+ }
1178
1929
  }
1179
1930
  }
1180
1931
  // "nav items" in a question about the sidebar are the side nav's; an
@@ -1199,7 +1950,12 @@ export function draftAnswer(ctx, env, question) {
1199
1950
  /\b(darker|lighter|brighter|colou?r(ed)?)\b/.test(c.text) ||
1200
1951
  (!c.neg && toneIn(c.text)))
1201
1952
  )
1202
- c.aspects.push('background');
1953
+ c.aspects.push(
1954
+ // "headings red": a part that is only text has a text color.
1955
+ c.parts.every(p => ['heading', 'link'].includes(p.on))
1956
+ ? 'text'
1957
+ : 'background',
1958
+ );
1203
1959
  };
1204
1960
  fillAspect();
1205
1961
  for (let i = 0; i < clauses.length; i++) {
@@ -1252,6 +2008,38 @@ export function draftAnswer(ctx, env, question) {
1252
2008
  (!c.parts.length || (!prev.parts.length && !prev.aspects.length))
1253
2009
  )
1254
2010
  c.mode = prev.mode;
2011
+ // "on focus, inputs get a 2px outline": a clause that only names a state
2012
+ // gives it to the clause after it.
2013
+ if (
2014
+ !c.state &&
2015
+ prev?.state &&
2016
+ !prev.parts.length &&
2017
+ !prev.aspects.length &&
2018
+ c.parts.length
2019
+ )
2020
+ c.state = prev.state;
2021
+ }
2022
+ // "when hovering a card, lift it with a bigger shadow": a clause that only
2023
+ // names a part and a state, beside clauses that say what to change, asks
2024
+ // for nothing of its own.
2025
+ for (const c of clauses)
2026
+ if (
2027
+ c.parts.length &&
2028
+ c.state &&
2029
+ !c.aspects.length &&
2030
+ !c.colors.length &&
2031
+ !c.lengths.length &&
2032
+ clauses.some(o => o !== c && o.aspects.length)
2033
+ ) {
2034
+ c.parts = [];
2035
+ c.text = '';
2036
+ }
2037
+ // "only in dark mode, …": a clause that only names a mode scopes every
2038
+ // clause after it.
2039
+ for (let i = 0; i < clauses.length; i++) {
2040
+ const c = clauses[i];
2041
+ if (c.mode && !c.parts.length && !c.aspects.length && !c.colors.length)
2042
+ for (const o of clauses.slice(i + 1)) o.mode ??= c.mode;
1255
2043
  }
1256
2044
  // The tab's text is on the tab, not on its underline.
1257
2045
  for (const c of clauses)
@@ -1328,12 +2116,8 @@ export function draftAnswer(ctx, env, question) {
1328
2116
  const stateFor = (on, word) => {
1329
2117
  const t = TARGET.get(one(on));
1330
2118
  const states = [...(t?.states ?? []), ...COMMON_STATES];
1331
- if (word === 'focus') {
1332
- const conds = JSON.stringify(C.MAP[one(on)]?.own ?? {});
1333
- for (const s of ['focus-within', 'focus-visible', 'focus'])
1334
- if (conds.includes(`:${s}`)) return s;
1335
- return 'focus-visible';
1336
- }
2119
+ if (word === 'focus')
2120
+ return focusStateOf(/** @type {any} */ ({C}), one(on)) ?? 'focus-visible';
1337
2121
  if (word === 'invalid') return null;
1338
2122
  return states.includes(word) ? word : null;
1339
2123
  };
@@ -1478,6 +2262,14 @@ export function draftAnswer(ctx, env, question) {
1478
2262
 
1479
2263
  for (const c of clauses) {
1480
2264
  clauseNow = c;
2265
+ // "reset the corners to default", "revert the font": take back what the
2266
+ // theme sets for it, as undo does.
2267
+ const back = resetAnswer(c);
2268
+ if (back) {
2269
+ push(back);
2270
+ recordTop(c, back.options[0] ?? []);
2271
+ continue;
2272
+ }
1481
2273
  if (c.except) {
1482
2274
  const prior = tops[tops.length - 1];
1483
2275
  if (!prior) continue;
@@ -1523,6 +2315,158 @@ export function draftAnswer(ctx, env, question) {
1523
2315
  }
1524
2316
  for (const a of c.aspects) seenAspect(a);
1525
2317
  for (const p of c.parts) seenPart(p.on);
2318
+ if (c.named?.bad) {
2319
+ push({
2320
+ text:
2321
+ c.named.prop === 'font-size'
2322
+ ? 'a font size of 0 hides the text; give a size above 0'
2323
+ : `"${c.named.bad}" is not a value ${c.named.prop} takes; give a length such as 16px`,
2324
+ options: [],
2325
+ });
2326
+ continue;
2327
+ }
2328
+ // "cards the same radius as buttons": the first part takes the second
2329
+ // part's value, read from the token the second part reads.
2330
+ const same = /\b(?:the )?same (\w+(?: \w+)?) as (?:the )?([a-z-]+)\b/.exec(
2331
+ c.text,
2332
+ );
2333
+ // "buttons twice as round as inputs": the part after "as" is only the
2334
+ // measure; the first part is the one that changes.
2335
+ const asAs = /\bas \w+ as (?:the )?([a-z-]+)/.exec(c.text);
2336
+ if (asAs && c.parts.length >= 2) {
2337
+ const after = (/** @type {{on: string}} */ p) =>
2338
+ lex.parts.some(
2339
+ ([re, x]) =>
2340
+ x.on === p.on && (re.exec(c.text)?.index ?? -1) > (asAs.index ?? 0),
2341
+ );
2342
+ c.parts = c.parts.filter(p => !after(p));
2343
+ }
2344
+ // "focus ring the same color as the danger color": a role's token.
2345
+ const role = same ? ROLE_DIALS.find(([re]) => re.test(same[0])) : null;
2346
+ if (same && role && c.parts.length === 1) {
2347
+ const target = c.parts[0];
2348
+ const d =
2349
+ target.on === 'focus-ring'
2350
+ ? {
2351
+ text: `the focus ring takes the ${role[1]} color: --focus-outline-color reads ${role[2]}`,
2352
+ options: [[set('--focus-outline-color', `var(${role[2]})`)]],
2353
+ }
2354
+ : {
2355
+ text: `${target.on} takes the ${role[1]} color`,
2356
+ options: [
2357
+ [set('background', `var(${role[2]})`, {on: target.on})],
2358
+ ],
2359
+ };
2360
+ seenPart(target.on);
2361
+ push(d);
2362
+ recordTop(c, d.options[0] ?? []);
2363
+ continue;
2364
+ }
2365
+ if (same && c.parts.length >= 2) {
2366
+ // The part named first takes the value; the order is the question's.
2367
+ const at = (/** @type {{on: string}} */ p) =>
2368
+ Math.min(
2369
+ ...lex.parts
2370
+ .filter(([, x]) => x.on === p.on)
2371
+ .map(([re]) => re.exec(c.text)?.index ?? Infinity),
2372
+ );
2373
+ const [target, source] = [...c.parts].sort((x, y) => at(x) - at(y));
2374
+ const group =
2375
+ /** @type {Record<string, string>} */ ({
2376
+ corners: 'corners',
2377
+ radius: 'corners',
2378
+ color: 'background',
2379
+ background: 'background',
2380
+ border: 'border',
2381
+ shadow: 'shadow',
2382
+ padding: 'spacing',
2383
+ spacing: 'spacing',
2384
+ font: 'font',
2385
+ })[same[1].split(' ').pop() ?? ''] ??
2386
+ c.aspects.map(a => (a === 'family' ? 'font' : a)).find(a => GROUPS[a]);
2387
+ const reads = group ? C.partReads(one(source.on), group) : [];
2388
+ const read = reads.find(r => r.when.includes('')) ?? reads[0];
2389
+ const prop = read?.props[0];
2390
+ if (read && prop) {
2391
+ seenPart(target.on);
2392
+ seenPart(source.on);
2393
+ const d = {
2394
+ text: `${target.on} takes ${source.on}'s ${prop}: ${source.on} reads ${read.token} for it`,
2395
+ options: [[set(prop, `var(${read.token})`, {on: target.on})]],
2396
+ };
2397
+ push(d);
2398
+ recordTop(c, d.options[0] ?? []);
2399
+ continue;
2400
+ }
2401
+ }
2402
+ // "… and set --border-width 2px": a real token typed in a clause.
2403
+ // The value runs to the clause end ("--shadow-high 0 4px 12px black").
2404
+ const tok = /(?:^|\s)(--[a-z][a-z0-9-]*)\s*:?\s+([^;]+?)\s*$/.exec(c.text);
2405
+ if (tok && Object.hasOwn(TOKENS, tok[1])) {
2406
+ const d = {
2407
+ text: `the token ${tok[1]}, as you wrote it`,
2408
+ options: [
2409
+ [
2410
+ set(
2411
+ tok[1],
2412
+ tok[2].replace(/\s+(on|for|in|everywhere)\b.*$/, ''),
2413
+ modeOf(c),
2414
+ ),
2415
+ ],
2416
+ ],
2417
+ };
2418
+ push(d);
2419
+ recordTop(c, d.options[0] ?? []);
2420
+ continue;
2421
+ }
2422
+ // "error text red", "labels smaller": text that belongs to parts how
2423
+ // cannot pick alone is a lookup, never the whole theme's text.
2424
+ if (
2425
+ !c.parts.length &&
2426
+ /\b(error (text|messages?)|(field |form |input )?labels?)\b/.test(c.text)
2427
+ ) {
2428
+ const which = /\berror\b/.test(c.text) ? 'error text' : 'labels';
2429
+ push({
2430
+ text: `${which} belong to the parts that show them (an input's error message, a field's label); name the part, or look it up`,
2431
+ options: [],
2432
+ lookup: `${HOW} --list parts ${which === 'labels' ? 'label' : 'error'}`,
2433
+ });
2434
+ continue;
2435
+ }
2436
+ // A CSS property named with its value is set as named, on each part.
2437
+ const named = c.named;
2438
+ if (
2439
+ named &&
2440
+ !named.bad &&
2441
+ // A divider's thickness and color are its border tokens.
2442
+ !c.parts.some(p => p.on === 'divider') &&
2443
+ c.parts.length &&
2444
+ c.parts.every(p => TARGET.has(one(p.on)) || FAMILIES[p.on])
2445
+ ) {
2446
+ const steps = c.parts.slice(0, 3).map(p => {
2447
+ const {noState: _n, ...f} = flagsFor(c, p);
2448
+ return {p, f, st: set(named.prop, named.value, {...f, ...modeOf(c)})};
2449
+ });
2450
+ // A property set cannot use on a part (a heading's color comes from
2451
+ // its prop) is answered the usual way, which says why.
2452
+ if (steps.every(({st}) => env.check([st]).ok)) {
2453
+ for (const {p, f, st} of steps) {
2454
+ seenPart(p.on);
2455
+ const d = {
2456
+ text: `${named.prop} on ${p.on}${f.state ? ` when ${f.state}` : ''}, as you wrote it`,
2457
+ options: [[st]],
2458
+ };
2459
+ push(d);
2460
+ recordTop(c, d.options[0] ?? []);
2461
+ }
2462
+ continue;
2463
+ }
2464
+ if (named.prop === 'color')
2465
+ c.aspects = [
2466
+ 'text',
2467
+ ...c.aspects.filter(x => x !== 'background' && x !== 'text'),
2468
+ ];
2469
+ }
1526
2470
  // A hover effect with nothing more said: a slightly darker part.
1527
2471
  if (c.parts.length && !c.aspects.length && c.state === 'hover' && !c.neg)
1528
2472
  c.aspects.push('background');
@@ -1537,6 +2481,20 @@ export function draftAnswer(ctx, env, question) {
1537
2481
  });
1538
2482
  continue;
1539
2483
  }
2484
+ // "combobox rounder": a word a component's doc lists, as the subject of
2485
+ // a shape change with no part named, is a part how cannot name; it is
2486
+ // never a whole-theme change.
2487
+ const unknown = !c.parts.length && unknownPart(c.text);
2488
+ if (unknown) {
2489
+ push({
2490
+ text: `no part is called "${unknown.word}"${unknown.parts.length ? `; the closest parts: ${unknown.parts.join(', ')}` : ''}. Name one of them, or list the parts`,
2491
+ options: [],
2492
+ lookup: unknown.parts.length
2493
+ ? `${HOW} ${unknown.parts[0]}`
2494
+ : `${HOW} --list parts`,
2495
+ });
2496
+ continue;
2497
+ }
1540
2498
  const targets = c.parts.length ? c.parts : [null];
1541
2499
  for (const p of targets.slice(0, 3)) {
1542
2500
  for (const a of c.aspects.slice(0, 3)) {
@@ -1576,6 +2534,97 @@ export function draftAnswer(ctx, env, question) {
1576
2534
  }
1577
2535
  }
1578
2536
 
2537
+ /**
2538
+ * The undo steps for a clause that asks to go back to the base value of a
2539
+ * setting the theme has ("reset the corners", "the accent back to what it
2540
+ * was", "clear the card background override"), or null when it does not
2541
+ * ask that.
2542
+ * @param {Clause} c
2543
+ * @returns {Draft | null}
2544
+ */
2545
+ function resetAnswer(c) {
2546
+ // "go back to the neutral theme", "start over": every setting.
2547
+ if (
2548
+ /\b(back to|reset to|revert to|restore) (the )?(neutral|base|original|default|plain) theme\b|\bstart over\b|\breset (the )?(whole )?theme\b/.test(
2549
+ c.text,
2550
+ )
2551
+ ) {
2552
+ const all = env.data.settings;
2553
+ return all.length
2554
+ ? {
2555
+ text: `take back every setting ${env.slug} has, one undo each, to its base theme (${env.data.like ?? 'none'})`,
2556
+ options: [
2557
+ all.map(
2558
+ st =>
2559
+ /** @type {Step} */ ({
2560
+ verb: 'undo',
2561
+ thing: st.thing,
2562
+ ...(st.on ? {on: st.on} : {}),
2563
+ ...(st.when ? {when: st.when} : {}),
2564
+ ...(st.state ? {state: st.state} : {}),
2565
+ ...(st.mode ? {mode: st.mode} : {}),
2566
+ }),
2567
+ ),
2568
+ ],
2569
+ sequence: all.length > 1,
2570
+ }
2571
+ : {
2572
+ text: `${env.slug} sets nothing, so it is its base theme as it is`,
2573
+ options: [],
2574
+ };
2575
+ }
2576
+ if (
2577
+ !/\b(reset|revert|restore|back to|default|original|what it was|standard|clear|no custom|remove the override|(remove|clear|drop|delete) (my |the )?(\w+ )?overrides?|by mistake|by accident|accidentally|put .* back|.* back to normal)\b/.test(
2578
+ c.text,
2579
+ ) ||
2580
+ /\bby default\b|\bthe last change\b|\beverything\b/.test(c.text) ||
2581
+ (c.colors.length > 0 &&
2582
+ !/\b(by mistake|by accident|accidentally)\b/.test(c.text)) ||
2583
+ OS_FONT.test(c.text)
2584
+ )
2585
+ return null;
2586
+ const role = ROLE_DIALS.find(([re]) => re.test(c.text));
2587
+ const things = [
2588
+ ...c.aspects.flatMap(a => RESET_THINGS[a] ?? []),
2589
+ ...(role ? [role[1], role[2]] : []),
2590
+ ];
2591
+ const on = c.parts[0]?.on;
2592
+ // "revert the cards to default": every setting on that part.
2593
+ if (!things.length && !on) return null;
2594
+ const matches = env.data.settings.filter(
2595
+ st =>
2596
+ (!things.length ||
2597
+ things.includes(st.thing) ||
2598
+ things.some(
2599
+ t => t.endsWith('*') && st.thing.startsWith(t.slice(0, -1)),
2600
+ )) &&
2601
+ (st.on ?? '') === (on ?? ''),
2602
+ );
2603
+ const what = role ? role[1] : (c.aspects[0] ?? 'everything');
2604
+ if (!matches.length)
2605
+ return {
2606
+ text: `${env.slug} sets nothing for ${what}${on ? ` on ${on}` : ''}, so it already uses the base value`,
2607
+ options: [],
2608
+ };
2609
+ return {
2610
+ text: `take back what ${env.slug} sets for ${what}${on ? ` on ${on}` : ''}: undo restores the base value`,
2611
+ options: [
2612
+ matches.map(
2613
+ st =>
2614
+ /** @type {Step} */ ({
2615
+ verb: 'undo',
2616
+ thing: st.thing,
2617
+ ...(st.on ? {on: st.on} : {}),
2618
+ ...(st.when ? {when: st.when} : {}),
2619
+ ...(st.state ? {state: st.state} : {}),
2620
+ ...(st.mode ? {mode: st.mode} : {}),
2621
+ }),
2622
+ ),
2623
+ ],
2624
+ sequence: matches.length > 1,
2625
+ };
2626
+ }
2627
+
1579
2628
  /**
1580
2629
  * The step that keeps one part as it is now when a step changes the whole
1581
2630
  * theme (or a group the part is in), or null when none can.
@@ -1757,6 +2806,96 @@ export function draftAnswer(ctx, env, question) {
1757
2806
  ],
1758
2807
  };
1759
2808
  }
2809
+ if (a === 'motion') {
2810
+ // "turn off all animations", "no transition on links".
2811
+ if (c.neg || /\b(off|none)\b/.test(c.text)) {
2812
+ if (on)
2813
+ return {
2814
+ text: `no transition${where}`,
2815
+ options: [[set('transition', 'none', f)]],
2816
+ };
2817
+ return {
2818
+ text: 'no motion: every shared duration token at 0ms',
2819
+ options: [
2820
+ Object.keys(TOKENS)
2821
+ .filter(t => /^--duration-/.test(t))
2822
+ .map(t => set(t, '0ms')),
2823
+ ],
2824
+ sequence: true,
2825
+ };
2826
+ }
2827
+ const typedMs = /\b(\d+)ms\b/.exec(c.text)?.[1];
2828
+ if (typedMs && !on)
2829
+ return {
2830
+ text: `every motion at ${typedMs}ms: the shared duration tokens`,
2831
+ options: [
2832
+ ['--duration-fast', '--duration-medium', '--duration-slow']
2833
+ .filter(t => t in TOKENS)
2834
+ .map(t => set(t, `${typedMs}ms`)),
2835
+ ],
2836
+ sequence: true,
2837
+ };
2838
+ const slower = /\b(slow(er)?|longer)\b/.test(c.text);
2839
+ const ms =
2840
+ /\b(\d+)ms\b/.exec(c.text)?.[1] ??
2841
+ (/\b(\d*\.?\d+)s\b/.exec(c.text)?.[1] &&
2842
+ String(Number(/\b(\d*\.?\d+)s\b/.exec(c.text)?.[1]) * 1000));
2843
+ const own = on ? (C.MAP[one(on)]?.own ?? {}) : {};
2844
+ const moves = Object.keys(own).some(k =>
2845
+ /^(transition|animation)-duration$/.test(k),
2846
+ );
2847
+ if (on && !moves)
2848
+ return {
2849
+ text: `${on} has no motion of its own that set can change; the theme's motion speeds are the --duration-* tokens, which every part shares`,
2850
+ options: [],
2851
+ lookup: `${HOW} --duration-medium`,
2852
+ };
2853
+ if (!on) {
2854
+ const scale = slower ? 1.5 : 0.6;
2855
+ return {
2856
+ text: `${slower ? 'slower' : 'faster'} motion everywhere: the shared duration tokens`,
2857
+ options: [
2858
+ ['--duration-fast', '--duration-medium', '--duration-slow']
2859
+ .filter(t => t in TOKENS)
2860
+ .map(t =>
2861
+ set(t, `${Math.round(parseFloat(current(t)) * scale)}ms`),
2862
+ ),
2863
+ ],
2864
+ sequence: true,
2865
+ };
2866
+ }
2867
+ return {
2868
+ text: `${slower ? 'slower' : 'faster'} transitions${where}: transition-duration`,
2869
+ options: [
2870
+ [set('transition-duration', `${ms ?? (slower ? 300 : 100)}ms`, f)],
2871
+ ],
2872
+ };
2873
+ }
2874
+ // A divider draws with the border tokens: its thickness and color.
2875
+ if (
2876
+ on === 'divider' &&
2877
+ ['border', 'size', 'background', 'text'].includes(a)
2878
+ ) {
2879
+ const color = colorFor(c, 'fill');
2880
+ if (color && (a === 'background' || a === 'text' || a === 'border'))
2881
+ return {
2882
+ text: 'the divider color: --color-border, on the divider only',
2883
+ options: [[set('--color-border', color, {on, ...modeOf(c)})]],
2884
+ };
2885
+ const len =
2886
+ c.lengths[0] ??
2887
+ (c.dir === 'less'
2888
+ ? '1px'
2889
+ : c.dir || /\bthick/.test(c.text)
2890
+ ? '2px'
2891
+ : null);
2892
+ return len
2893
+ ? {
2894
+ text: 'the divider thickness: --border-width, on the divider only',
2895
+ options: [[set('--border-width', len, {on})]],
2896
+ }
2897
+ : null;
2898
+ }
1760
2899
  if (on === 'overlay') {
1761
2900
  const typed = colorFor(c, 'fill');
1762
2901
  const steps = typed
@@ -1777,6 +2916,26 @@ export function draftAnswer(ctx, env, question) {
1777
2916
  sequence: steps.length > 1,
1778
2917
  };
1779
2918
  }
2919
+ // A part that reads no fill or text color token ("spinner in the accent
2920
+ // color") gets no fill it never had.
2921
+ if (
2922
+ a === 'background' &&
2923
+ on &&
2924
+ !f.state &&
2925
+ !/\b(stripe[sd]?|striped|zebra)\b/.test(c.text) &&
2926
+ C.MAP[one(on)] &&
2927
+ !Object.keys(C.MAP[one(on)].own ?? {}).some(k =>
2928
+ /^(background|background-color|background-image|color|fill|stroke|border-color|border|outline-color)$/.test(
2929
+ k,
2930
+ ),
2931
+ ) &&
2932
+ !/\b(background|bg|fill(ed)?|gradient)\b/.test(c.text)
2933
+ )
2934
+ return {
2935
+ text: `${on} reads no fill or text color token that set can change; its color comes from its own props`,
2936
+ options: [],
2937
+ lookup: `${HOW} ${on}`,
2938
+ };
1780
2939
  if (p?.role === 'body' && a === 'weight') {
1781
2940
  const v =
1782
2941
  weightIn(c) ??
@@ -1838,7 +2997,9 @@ export function draftAnswer(ctx, env, question) {
1838
2997
  };
1839
2998
  }
1840
2999
  case 'leading': {
1841
- const n = /\b(\d(?:\.\d+)?)\b(?!\s*(px|rem|em|%))/.exec(c.text)?.[1];
3000
+ const n =
3001
+ /\b(normal)\b/.exec(c.text)?.[1] ??
3002
+ /\b(\d(?:\.\d+)?)\b(?!\s*(px|rem|em|%))/.exec(c.text)?.[1];
1842
3003
  const tok =
1843
3004
  !on || on === 'body' || p?.role === 'body'
1844
3005
  ? '--text-body-leading'
@@ -1902,7 +3063,7 @@ export function draftAnswer(ctx, env, question) {
1902
3063
  const shape =
1903
3064
  zero || c.neg || /\b(square(d)?|sharp)\b/.test(shapeText)
1904
3065
  ? 'square'
1905
- : /\b(pill|circular(?! (font|typeface))|circles?|fully round)\b/.test(
3066
+ : /\b(pill|circular(?! (font|typeface))|circles?|fully round|max(imum)? round\w*|most round\w*|as round as possible)\b/.test(
1906
3067
  shapeText,
1907
3068
  )
1908
3069
  ? 'pill'
@@ -2202,9 +3363,9 @@ export function draftAnswer(ctx, env, question) {
2202
3363
  };
2203
3364
  }
2204
3365
  case 'tracking': {
2205
- const tight = /\b(tight(er)?|narrow(er)?|less|condensed)\b/.test(
2206
- c.text,
2207
- );
3366
+ const tight =
3367
+ c.dir === 'less' ||
3368
+ /\b(tight(en|er)?|narrow(er)?|less|condensed)\b/.test(c.text);
2208
3369
  const typedTrack = c.lengths.find(l => /em$/.test(l)) ?? c.lengths[0];
2209
3370
  const value = typedTrack ?? (tight ? '-0.02em' : '0.04em');
2210
3371
  if (!on || on === 'heading')
@@ -2280,6 +3441,12 @@ export function draftAnswer(ctx, env, question) {
2280
3441
  };
2281
3442
  }
2282
3443
  case 'fontsize': {
3444
+ // A size of 0 hides the text: refused by name, never made bigger.
3445
+ if (/\b(font|text) size\s*:?\s*0(px|rem|em)?\b(?!\.)/.test(c.text))
3446
+ return {
3447
+ text: 'a font size of 0 hides the text; give a size above 0',
3448
+ options: [],
3449
+ };
2283
3450
  const px = c.lengths[0];
2284
3451
  const f2 = /\bmuch\b/.test(c.text) ? 1.5 : 1.25;
2285
3452
  const factor = c.dir === 'less' ? 1 / f2 : f2;
@@ -2291,7 +3458,11 @@ export function draftAnswer(ctx, env, question) {
2291
3458
  set(
2292
3459
  'text-size',
2293
3460
  px
2294
- ? String(parseFloat(px))
3461
+ ? String(
3462
+ /r?em$/.test(px)
3463
+ ? Math.round(parseFloat(px) * 16 * 100) / 100
3464
+ : parseFloat(px),
3465
+ )
2295
3466
  : c.dir === 'less'
2296
3467
  ? 'less'
2297
3468
  : 'more',
@@ -2341,6 +3512,13 @@ export function draftAnswer(ctx, env, question) {
2341
3512
  };
2342
3513
  }
2343
3514
  case 'case': {
3515
+ if (/\bsmall caps\b/.test(c.text) && on)
3516
+ return {
3517
+ text: `small caps${where}: font-variant-caps`,
3518
+ options: [
3519
+ [set('font-variant-caps', c.neg ? 'normal' : 'small-caps', f)],
3520
+ ],
3521
+ };
2344
3522
  const value = c.neg
2345
3523
  ? 'none'
2346
3524
  : /\blower/.test(c.text)
@@ -2367,7 +3545,71 @@ export function draftAnswer(ctx, env, question) {
2367
3545
  }
2368
3546
  : null;
2369
3547
  case 'opacity': {
2370
- const pct = /\b(\d{1,3})%/.exec(c.text)?.[1];
3548
+ const layer =
3549
+ /\b(shadows?|backgrounds?|bg|borders?|outlines?)\s+opacity\b/.exec(
3550
+ c.text,
3551
+ )?.[1];
3552
+ const alpha =
3553
+ /\bopacity\s*:?\s*(0?\.\d+|0|1)\b(?!%)/.exec(c.text)?.[1] ??
3554
+ (Number(/\b(\d{1,3})%/.exec(withoutFunctions(c.text))?.[1] ?? NaN) /
3555
+ 100 ||
3556
+ null);
3557
+ // "shadow opacity 0.2": the layer's own alpha, never the part's.
3558
+ if (layer && on) {
3559
+ const a =
3560
+ alpha == null ? (c.dir === 'less' ? 0.08 : 0.2) : Number(alpha);
3561
+ if (/^shadow/.test(layer))
3562
+ return {
3563
+ text: `a shadow at ${a} alpha${where}`,
3564
+ options: [[set('box-shadow', `0 1px 3px rgb(0 0 0 / ${a})`, f)]],
3565
+ };
3566
+ if (/^(background|bg)/.test(layer)) {
3567
+ const tok =
3568
+ C.partReads(one(on), 'background').find(r => r.when.includes(''))
3569
+ ?.token ??
3570
+ (FAMILIES.containers.includes(one(on))
3571
+ ? '--color-background-card'
3572
+ : null);
3573
+ return tok
3574
+ ? {
3575
+ text: `the background at ${Math.round(a * 100)}%${where}, see-through to what is behind it`,
3576
+ options: [
3577
+ [
3578
+ set(
3579
+ 'background-color',
3580
+ `color-mix(in srgb, var(${tok}) ${Math.round(a * 100)}%, transparent)`,
3581
+ f,
3582
+ ),
3583
+ ],
3584
+ ],
3585
+ }
3586
+ : {
3587
+ text: `${on} has no background color of its own to make see-through`,
3588
+ options: [],
3589
+ };
3590
+ }
3591
+ return {
3592
+ text: `the border at ${Math.round(a * 100)}%${where}`,
3593
+ options: [
3594
+ [
3595
+ set(
3596
+ 'border-color',
3597
+ `color-mix(in srgb, var(--color-border) ${Math.round(a * 100)}%, transparent)`,
3598
+ f,
3599
+ ),
3600
+ ],
3601
+ ],
3602
+ };
3603
+ }
3604
+ const typedOpacity = /\bopacity\s*:?\s*(0?\.\d+|0|1)\b(?!%)/.exec(
3605
+ c.text,
3606
+ )?.[1];
3607
+ if (typedOpacity && on)
3608
+ return {
3609
+ text: `opacity${where}: ${typedOpacity}`,
3610
+ options: [[set('opacity', typedOpacity, f)]],
3611
+ };
3612
+ const pct = /\b(\d{1,3})%/.exec(withoutFunctions(c.text))?.[1];
2371
3613
  if (pct && on)
2372
3614
  return Number(pct) > 100
2373
3615
  ? {text: `opacity runs from 0% to 100%, not ${pct}%`, options: []}
@@ -2395,6 +3637,12 @@ export function draftAnswer(ctx, env, question) {
2395
3637
  : null;
2396
3638
  }
2397
3639
  case 'scale':
3640
+ // "should not shrink when pressed": no scale.
3641
+ if (on && c.neg)
3642
+ return {
3643
+ text: `${on} keeps its size${where}: transform none`,
3644
+ options: [[set('transform', 'none', f)]],
3645
+ };
2398
3646
  return on
2399
3647
  ? {
2400
3648
  text: `${on} scales${where}: transform`,
@@ -2402,9 +3650,11 @@ export function draftAnswer(ctx, env, question) {
2402
3650
  [
2403
3651
  set(
2404
3652
  'transform',
2405
- /\b(up|grows?)\b/.test(c.text)
2406
- ? 'scale(1.03)'
2407
- : 'scale(0.97)',
3653
+ /\bscale\s*:?\s*(0?\.\d+|1(\.\d+)?)\b/.test(c.text)
3654
+ ? `scale(${/\bscale\s*:?\s*(0?\.\d+|1(?:\.\d+)?)\b/.exec(c.text)?.[1]})`
3655
+ : /\b(up|grows?)\b/.test(c.text)
3656
+ ? 'scale(1.03)'
3657
+ : 'scale(0.97)',
2408
3658
  f,
2409
3659
  ),
2410
3660
  ],
@@ -2418,7 +3668,11 @@ export function draftAnswer(ctx, env, question) {
2418
3668
  return answerFor(c, p, 'fontsize');
2419
3669
  const tall =
2420
3670
  tallIn(c.text) ??
2421
- (/\b(taller|shorter|height)\b/.test(c.text) ? c.lengths[0] : null);
3671
+ (/\b(taller|shorter|height|bigger|larger|tap targets?|touch targets?)\b/.test(
3672
+ c.text,
3673
+ ) && !/\b(wider|narrower|width)\b/.test(c.text)
3674
+ ? c.lengths[0]
3675
+ : null);
2422
3676
  if (tall)
2423
3677
  return {
2424
3678
  text: `the height${where}: min-height ${tall}`,
@@ -2474,7 +3728,13 @@ export function draftAnswer(ctx, env, question) {
2474
3728
  };
2475
3729
  }
2476
3730
  case 'text': {
2477
- const color = colorFor(c, 'text');
3731
+ // "dim the white text": the color word names the text to change,
3732
+ // not the color to give it.
3733
+ const recolor =
3734
+ /\b(dim|dimmer|soften|darken|lighten|brighten|tone down)\b/.test(
3735
+ c.text,
3736
+ ) && !/#[0-9a-f]{3,8}\b|\(/.test(c.text);
3737
+ const color = recolor ? null : colorFor(c, 'text');
2478
3738
  const tok = /\bsecondary\b/.test(c.text)
2479
3739
  ? '--color-text-secondary'
2480
3740
  : '--color-text-primary';
@@ -2545,12 +3805,17 @@ export function draftAnswer(ctx, env, question) {
2545
3805
  }
2546
3806
  // More contrast moves text away from its page: darker on light,
2547
3807
  // lighter on dark. Less contrast moves it toward the page.
3808
+ // "knock the contrast down" asks for less contrast.
3809
+ const down = c.dir === 'less' && /\bcontrast\b/.test(c.text);
2548
3810
  const more =
2549
- /\b(darker|too light|can'?t read|hard to read|unreadable|(more|better|higher|low|fails?|failing|enough) contrast|contrast)\b/.test(
3811
+ !down &&
3812
+ /\b(darker|darken|too light|can'?t read|hard to read|unreadable|(more|better|higher|low|fails?|failing|enough) contrast|contrast)\b/.test(
2550
3813
  c.text,
2551
- ) && !/\bless contrast\b/.test(c.text);
3814
+ ) &&
3815
+ !/\bless contrast\b/.test(c.text);
2552
3816
  const less =
2553
- /\b(less bright|dimmer|softer|lighter|less contrast|too dark)\b/.test(
3817
+ down ||
3818
+ /\b(less bright|dim|dimmer|soften|softer|lighter|less contrast|too dark)\b/.test(
2554
3819
  c.text,
2555
3820
  );
2556
3821
  if (!more && !less) return null;
@@ -2583,12 +3848,27 @@ export function draftAnswer(ctx, env, question) {
2583
3848
  // A link's color comes from its color prop, so no part style
2584
3849
  // reaches it: the accent text token is what a link reads, in every
2585
3850
  // state.
3851
+ // A link's color in one state: the token, scoped to that state.
3852
+ if (on === 'link' && color && f.state)
3853
+ return {
3854
+ text: `the link color${where}: --color-text-accent on links in that state`,
3855
+ options: [
3856
+ [set('--color-text-accent', color, {...f, ...modeOf(c)})],
3857
+ ],
3858
+ };
2586
3859
  if (on === 'link' && color)
2587
3860
  return {
2588
3861
  text: `the link color: --color-text-accent, the token a link reads (it also colors other accent text)${f.state ? `; a link has no color of its own for ${f.state}, so this changes it in every state` : ''}`,
2589
3862
  options: [[set('--color-text-accent', color, modeOf(c))]],
2590
3863
  };
2591
3864
  if (!color) return null;
3865
+ // A part that takes its color from a prop (a heading): the text
3866
+ // token, on that part only.
3867
+ if (!env.check([set('color', color, f)]).ok)
3868
+ return {
3869
+ text: `the text color${where}: --color-text-primary on ${on} only (${on} takes its color from a prop, so a color property never shows)`,
3870
+ options: [[set('--color-text-primary', color, {on, ...modeOf(c)})]],
3871
+ };
2592
3872
  return {
2593
3873
  text: `text color${where}: color`,
2594
3874
  options: [[set('color', color, {...f, ...modeOf(c)})]],
@@ -2708,8 +3988,14 @@ export function draftAnswer(ctx, env, question) {
2708
3988
  ],
2709
3989
  };
2710
3990
  // "from #f58529 to #dd2a7b": the gradient written in the question.
2711
- const ends = /\bfrom\s+(\S+)\s+(?:to|into)\s+(\S+)/.exec(c.text);
2712
- if (design && ends && parseColor(ends[1]) && parseColor(ends[2]))
3991
+ // "from #a to #b", "#a 0% to #b 100%": the stops as typed.
3992
+ const ends =
3993
+ /\bfrom\s+(\S+)\s+(?:to|into)\s+(\S+)/.exec(c.text) ??
3994
+ /(#[0-9a-f]{3,8}(?:\s+\d+%)?)\s+(?:to|into)\s+(#[0-9a-f]{3,8}(?:\s+\d+%)?)/.exec(
3995
+ c.text,
3996
+ );
3997
+ const stop = (/** @type {string} */ x) => parseColor(x.split(/\s+/)[0]);
3998
+ if (design && ends && stop(ends[1]) && stop(ends[2]))
2713
3999
  return {
2714
4000
  text: `a gradient from ${ends[1]} to ${ends[2]}${where}`,
2715
4001
  options: [
@@ -2884,7 +4170,20 @@ export function draftAnswer(ctx, env, question) {
2884
4170
  };
2885
4171
  if (/\b(dark|light)\b/.test(t) && /\b(mode|theme|only)\b/.test(t))
2886
4172
  seenAspect('mode');
2887
- if (/\bdark[- ]?(mode|theme)? only\b|\bonly dark\b|\bdark-only\b/.test(t))
4173
+ if (
4174
+ /\bdark[- ]?(mode|theme)? only\b|\bonly dark\b|\bdark-only\b|\bdark by default\b|\bdefault(s)? to dark\b|\balways dark\b/.test(
4175
+ t,
4176
+ ) &&
4177
+ // "in dark mode only, cards #111111": the mode scopes the other ask.
4178
+ // "dark only" with no "mode" word describes the theme's look.
4179
+ (/\balways dark\b|\b(theme|app)\b/.test(t) ||
4180
+ !/\bmode\b|\bin dark\b/.test(t) ||
4181
+ !clauses.some(
4182
+ o =>
4183
+ o.text !== c.text &&
4184
+ (o.parts.length || o.colors.length || o.aspects.length),
4185
+ ))
4186
+ )
2888
4187
  return {
2889
4188
  text: 'a theme with only a dark mode: mode dark-only',
2890
4189
  options: [[set('mode', 'dark-only')]],
@@ -2964,9 +4263,9 @@ export function draftAnswer(ctx, env, question) {
2964
4263
  ) {
2965
4264
  seenAspect('colors');
2966
4265
  return {
2967
- text: 'Every shade of every color, light and dark, with the tokens that use each, is on the Colors page of the in-app preview. It changes with every set.',
4266
+ text: `Every shade of every color, light and dark, with the tokens that use each, is on the Colors page of the in-app preview. It changes with every set.${env.previewDamage ? ` The preview cannot be changed now: ${env.previewDamage}` : ''}`,
2968
4267
  options: [],
2969
- ...(env.exists
4268
+ ...(env.exists && !env.previewDamage
2970
4269
  ? {
2971
4270
  lookup: `astryx experimental theme preview add --theme ${env.slug}`,
2972
4271
  }
@@ -3151,7 +4450,12 @@ export function draftAnswer(ctx, env, question) {
3151
4450
  if (c.dir && color && (color === NATURAL[dial] || color === HUES.amber))
3152
4451
  color = null;
3153
4452
  if (!color && c.dir && !/\btoo (warm|cool)\b/.test(t)) {
3154
- const lighter = /\b(light(er)?|brighter|paler)\b/.test(t);
4453
+ // "too dark" asks for lighter, "too bright" for darker.
4454
+ const lighter =
4455
+ /\btoo dark\b/.test(t) ||
4456
+ /\b(light(er)?|brighter|paler)\b/.test(
4457
+ t.replace(/\btoo (light|bright|pale)\b/g, ' '),
4458
+ );
3155
4459
  if (c.mode && modal) {
3156
4460
  const steps = perMode(
3157
4461
  token,
@@ -3184,6 +4488,35 @@ export function draftAnswer(ctx, env, question) {
3184
4488
  };
3185
4489
  }
3186
4490
 
4491
+ /**
4492
+ * A part word how cannot name: the clause starts with a word a component
4493
+ * doc lists as a keyword, or a near catalog name, and asks for a shape
4494
+ * change. Gives the word and the parts of the components that list it.
4495
+ * @param {string} text
4496
+ * @returns {{word: string, parts: string[]} | null}
4497
+ */
4498
+ function unknownPart(text) {
4499
+ const m =
4500
+ /^(?:the |a |an |my |our |all |every )?([a-z]+)\b(?: [a-z]+)? (?:rounder|rounded|bolder|bold|bigger|smaller|taller|wider|darker|lighter|padding|shadow|border|corners?|radius)\b/.exec(
4501
+ text,
4502
+ );
4503
+ if (!m) return null;
4504
+ const word = singular(m[1]);
4505
+ // A word how reads as a change ("border radius") is not a part.
4506
+ if (aspectsOf(word).length || aspectsOf(m[1]).length) return null;
4507
+ const owners = Object.values(ctx.project.components)
4508
+ .filter(info =>
4509
+ (info.keywords ?? []).some(
4510
+ k => singular(String(k).toLowerCase()) === word,
4511
+ ),
4512
+ )
4513
+ .map(info => info.targets[0]?.className.replace(/^astryx-/, ''))
4514
+ .filter(t => t && TARGET.has(t));
4515
+ return owners.length
4516
+ ? {word, parts: [...new Set(owners)].slice(0, 4)}
4517
+ : null;
4518
+ }
4519
+
3187
4520
  /**
3188
4521
  * The tokens a part reads for an aspect, for the answer's text.
3189
4522
  * @param {string} on @param {string} a
@@ -3198,20 +4531,7 @@ export function draftAnswer(ctx, env, question) {
3198
4531
  case: 'font',
3199
4532
  italic: 'font',
3200
4533
  })[a] ?? a;
3201
- if (
3202
- !C.MAP[one(on)] ||
3203
- ![
3204
- 'text',
3205
- 'background',
3206
- 'border',
3207
- 'corners',
3208
- 'shadow',
3209
- 'spacing',
3210
- 'font',
3211
- 'size',
3212
- ].includes(group)
3213
- )
3214
- return '';
4534
+ if (!C.MAP[one(on)] || !Object.hasOwn(GROUPS, group)) return '';
3215
4535
  // Reads that always apply first; partReads sorts them so.
3216
4536
  const toks = C.partReads(one(on), group)
3217
4537
  .map(r => r.token)
@@ -3242,7 +4562,12 @@ export function draftAnswer(ctx, env, question) {
3242
4562
  for (const {clause, steps} of tops)
3243
4563
  for (const st of steps) {
3244
4564
  const prior = last.get(idOf(st));
3245
- if (prior && prior.clause !== clause && prior.step.value !== st.value)
4565
+ if (
4566
+ prior &&
4567
+ prior.clause !== clause &&
4568
+ prior.step.value !== st.value &&
4569
+ (prior.clause.mode ?? '') === (clause.mode ?? '')
4570
+ )
3246
4571
  clashes.push([prior.step, st]);
3247
4572
  last.delete(idOf(st));
3248
4573
  last.set(idOf(st), {step: st, clause});
@@ -3284,6 +4609,53 @@ export function draftAnswer(ctx, env, question) {
3284
4609
  return {parts: partsSeen, aspects: aspectsSeen, drafts: result};
3285
4610
  }
3286
4611
 
4612
+ /** Words for the operating system's own font. */
4613
+ const OS_FONT =
4614
+ /^(mac|macos|apple|windows|ios|android|os)$|\b(mac|macos|apple|windows|ios|android|os|system)('s)?( default| own| native)?( ui)? (font|typeface)\b|\bdefault (mac|apple|windows|system|os) (font|typeface)\b/i;
4615
+
4616
+ /**
4617
+ * A family a clean machine already has (the editor's font check reads the
4618
+ * same list), named in the clause and written with its capitals in the
4619
+ * question, as typed there.
4620
+ * @param {string} c the clause, lower-case
4621
+ * @param {string} question
4622
+ */
4623
+ function systemFamilyIn(c, question) {
4624
+ const generic = new Set(keywordsOf('font-family'));
4625
+ const words = [...question.matchAll(/[A-Za-z][\w-]*/g)];
4626
+ /** @type {string | null} */
4627
+ let best = null;
4628
+ // The longest run of words, starting with a capital, that names one.
4629
+ for (let i = 0; i < words.length; i++) {
4630
+ if (!/^[A-Z]/.test(words[i][0])) continue;
4631
+ for (let n = Math.min(4, words.length - i); n >= 1; n--) {
4632
+ const run = words.slice(i, i + n);
4633
+ const gap = run.every(
4634
+ (w, k) =>
4635
+ k === 0 ||
4636
+ /^\s+$/.test(
4637
+ question.slice(
4638
+ /** @type {number} */ (run[k - 1].index) + run[k - 1][0].length,
4639
+ w.index,
4640
+ ),
4641
+ ),
4642
+ );
4643
+ if (!gap) continue;
4644
+ const name = run.map(w => w[0]).join(' ');
4645
+ const low = name.toLowerCase();
4646
+ if (
4647
+ generic.has(low) ||
4648
+ !new RegExp(`\\b${low}\\b`).test(c) ||
4649
+ !isSystemFamily(name)
4650
+ )
4651
+ continue;
4652
+ if (!best || name.length > best.length) best = name;
4653
+ break;
4654
+ }
4655
+ }
4656
+ return best;
4657
+ }
4658
+
3287
4659
  /**
3288
4660
  * A font a clause names: a preset, an open font, or a family written with
3289
4661
  * capitals in the question.
@@ -3320,19 +4692,33 @@ function fontIn(cl, question) {
3320
4692
  // A name as typed, up to four words ("Source Sans 3", "Roboto Slab"):
3321
4693
  // after "use" or "font", or before "font"; one this clause names.
3322
4694
  const GENERIC =
3323
- /^(a|an|the|my|our|this|that|any|some|same|another|different|new|nice|modern|bold|light|thin|heavy|big|small|serif|sans|sans-serif|mono|monospace|system|default|body|heading|headings|code|for|on|in)$/i;
4695
+ /^(a|an|the|my|our|this|that|any|some|same|another|different|new|nice|modern|bold|light|thin|heavy|big|small|serif|sans|sans-serif|mono|monospace|system|default|body|heading|headings|code|for|on|in|dark|light|night)$/i;
3324
4696
  const NAME =
3325
4697
  "([A-Z][\\w-]*(?:'[\\w-]+)*(?: (?:[A-Z][\\w-]*(?:'[\\w-]+)*|\\d+)){0,3})";
3326
4698
  /** @type {string | undefined} */
3327
4699
  let typed;
3328
4700
  for (const re of [
3329
- new RegExp(`\\b(?:[Uu]se|[Ff]ont|[Tt]ypeface)s?:?\\s+["']?${NAME}`, 'g'),
4701
+ new RegExp(
4702
+ `\\b(?:[Uu]se|[Ff]ont|[Tt]ypeface|[Tt]o|in)s?:?\\s+["']?${NAME}`,
4703
+ 'g',
4704
+ ),
3330
4705
  new RegExp(`\\b${NAME}\\s+(?:font|typeface)\\b`, 'g'),
4706
+ // "Plus Jakarta Sans as the main font", "Arial everywhere", "Fira
4707
+ // Code for monospace".
4708
+ new RegExp(
4709
+ `(?:^|[\\s,;:])${NAME}\\s+(?:as|for|everywhere|throughout|across)\\b`,
4710
+ 'g',
4711
+ ),
3331
4712
  ]) {
3332
4713
  for (const m of question.matchAll(re)) {
3333
4714
  const name = m[1].replace(/ (Font|Typeface)$/, '');
3334
- if (GENERIC.test(name.split(' ')[0])) continue;
3335
- if (c.includes(name.toLowerCase())) {
4715
+ if (GENERIC.test(name.split(' ')[0]) || OS_FONT.test(name)) continue;
4716
+ // "Plus Jakarta Sans": a clause break word may start the name.
4717
+ const low = name.toLowerCase();
4718
+ if (
4719
+ c.includes(low) ||
4720
+ (low.split(' ').length > 2 && c.includes(low.replace(/^\S+ /, '')))
4721
+ ) {
3336
4722
  typed = name;
3337
4723
  break;
3338
4724
  }
@@ -3347,6 +4733,11 @@ function fontIn(cl, question) {
3347
4733
  )
3348
4734
  return typed;
3349
4735
  if (known) return known;
4736
+ // "the default Mac font": the system font.
4737
+ if (OS_FONT.test(c)) return 'system';
4738
+ // A family every machine has, named with its capitals ("use Menlo").
4739
+ const local = systemFamilyIn(c, question);
4740
+ if (local) return local;
3350
4741
  if (/\bmono(space|spaced)?\b/.test(c)) return 'mono';
3351
4742
  if (/\bsans(-serif)?\b/.test(c)) return 'system';
3352
4743
  if (/\bserif\b/.test(c)) return 'serif';