@astryxdesign/cli 0.7.16 → 0.7.17-canary.g9a957aa

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 (229) hide show
  1. package/README.md +12 -23
  2. package/api/build/_adapter.d.mts +5 -0
  3. package/api/build/_adapter.mjs +49 -34
  4. package/api/build/blocks/blocks.d.mts +7 -5
  5. package/api/build/blocks/blocks.mjs +113 -26
  6. package/api/build/build.doc.mjs +2 -1
  7. package/api/build/kit/rank.mjs +47 -9
  8. package/api/build/kit/weights.d.mts +16 -3
  9. package/api/build/kit/weights.json +1 -1
  10. package/api/build/kit/weights.mjs +238 -31
  11. package/api/build/kit/word-model.d.mts +23 -0
  12. package/api/build/kit/word-model.mjs +46 -0
  13. package/api/build/kit/words.d.mts +32 -0
  14. package/api/build/kit/words.mjs +49 -1
  15. package/api/component/__fixtures__/resolutions/modules.txt +4 -5
  16. package/api/component/list/list.d.mts +1 -1
  17. package/api/component/list/list.mjs +48 -5
  18. package/api/discover/_adapter.d.mts +1 -1
  19. package/api/docs/_adapter.d.mts +26 -2
  20. package/api/docs/_adapter.mjs +217 -5
  21. package/api/docs/docs.d.mts +3 -0
  22. package/api/docs/docs.doc.mjs +7 -1
  23. package/api/docs/docs.mjs +12 -0
  24. package/api/docs/docs.type.d.mts +5 -0
  25. package/api/docs/docs.type.mjs +2 -0
  26. package/api/docs/node/node.mjs +1 -1
  27. package/api/doctor/_adapter.d.mts +27 -5
  28. package/api/doctor/_adapter.mjs +77 -6
  29. package/api/doctor/built-checks.mjs +38 -13
  30. package/api/doctor/doctor.d.mts +4 -3
  31. package/api/doctor/doctor.mjs +14 -7
  32. package/api/doctor/theme-checks.mjs +121 -17
  33. package/api/render/_adapter.mjs +491 -186
  34. package/api/render/render.doc.mjs +10 -3
  35. package/api/render/render.type.d.mts +30 -0
  36. package/api/render/render.type.mjs +19 -0
  37. package/api/search/ORDERING.md +1 -1
  38. package/api/search/_candidate-score.mjs +51 -32
  39. package/api/search/_fit-order.mjs +3 -3
  40. package/api/search/_result.d.mts +5 -5
  41. package/api/search/_score.d.mts +6 -1
  42. package/api/search/_score.mjs +15 -3
  43. package/api/search/search.d.mts +1 -1
  44. package/api/theme/_adapter.mjs +10 -0
  45. package/api/theme/build/build.d.mts +38 -0
  46. package/api/theme/build/build.mjs +144 -24
  47. package/api/theme/theme.type.d.mts +10 -0
  48. package/api/theme/theme.type.mjs +7 -1
  49. package/api/theme-edit/_adapter.d.mts +35 -0
  50. package/api/theme-edit/_adapter.mjs +477 -41
  51. package/api/theme-edit/_check.d.mts +28 -22
  52. package/api/theme-edit/_check.mjs +1077 -200
  53. package/api/theme-edit/_compiler.mjs +9 -0
  54. package/api/theme-edit/_context.mjs +60 -3
  55. package/api/theme-edit/_css.mjs +21 -1
  56. package/api/theme-edit/_edit.d.mts +22 -0
  57. package/api/theme-edit/_edit.mjs +932 -82
  58. package/api/theme-edit/_how-commands.d.mts +49 -0
  59. package/api/theme-edit/_how-commands.mjs +386 -1
  60. package/api/theme-edit/_how-question.d.mts +56 -0
  61. package/api/theme-edit/_how-question.mjs +3509 -168
  62. package/api/theme-edit/_how.mjs +104 -4
  63. package/api/theme-edit/_marks.d.mts +31 -5
  64. package/api/theme-edit/_marks.mjs +57 -5
  65. package/api/theme-edit/_normal.d.mts +137 -0
  66. package/api/theme-edit/_normal.mjs +612 -0
  67. package/api/theme-edit/_palette.mjs +10 -4
  68. package/api/theme-edit/_parts.d.mts +4 -0
  69. package/api/theme-edit/_parts.mjs +28 -2
  70. package/api/theme-edit/_preview-app.d.mts +7 -1
  71. package/api/theme-edit/_preview-app.mjs +191 -15
  72. package/api/theme-edit/_preview.d.mts +64 -8
  73. package/api/theme-edit/_preview.mjs +401 -83
  74. package/api/theme-edit/_settings.d.mts +139 -5
  75. package/api/theme-edit/_settings.mjs +1659 -112
  76. package/api/theme-edit/_tables.mjs +17 -1
  77. package/api/theme-edit/theme-edit.type.d.mts +10 -1
  78. package/api/theme-edit/theme-edit.type.mjs +4 -1
  79. package/api/theme-edit/themeEditPreviewApp.doc.mjs +2 -2
  80. package/assets/codemods/run-codemod.mjs +73 -6
  81. package/assets/codemods/transforms/next/index.mjs +11 -1
  82. package/assets/codemods/transforms/next/migrate-item-swipe-actions-to-swipe.mjs +394 -0
  83. package/assets/docs/author-a-theme.doc.mjs +1 -0
  84. package/assets/docs/theme.doc.dense.mjs +2 -2
  85. package/assets/docs/theme.doc.mjs +1 -1
  86. package/assets/docs/tree/check-your-docs.doc.mjs +1 -1
  87. package/assets/docs/tree/cli-command.doc.mjs +2 -3
  88. package/assets/docs/tree/render-pages.doc.mjs +43 -2
  89. package/assets/docs/tree/template-doc-overview.doc.mjs +1 -1
  90. package/assets/docs/tree/test-in-an-app.doc.mjs +1 -1
  91. package/assets/docs/use-a-theme.doc.mjs +1 -1
  92. package/assets/docs.generated.json +2 -2
  93. package/assets/self-audit.generated.json +1 -1
  94. package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.doc.mjs +14 -0
  95. package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.tsx +38 -0
  96. package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.doc.mjs +14 -0
  97. package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.tsx +36 -0
  98. package/assets/templates/components.generated.json +1 -1
  99. package/assets/templates/pages/ai-chat/template.doc.mjs +8 -4
  100. package/assets/templates/pages/ai-chat-landing/template.doc.mjs +2 -1
  101. package/assets/templates/pages/blank/template.doc.mjs +1 -1
  102. package/assets/templates/pages/canvas-editor/template.doc.mjs +4 -2
  103. package/assets/templates/pages/centered-hero/template.doc.mjs +9 -1
  104. package/assets/templates/pages/classic-gallery/template.doc.mjs +1 -1
  105. package/assets/templates/pages/contact-form/template.doc.mjs +2 -1
  106. package/assets/templates/pages/dashboard/template.doc.mjs +3 -2
  107. package/assets/templates/pages/dashboard-alert-rail/template.doc.mjs +2 -1
  108. package/assets/templates/pages/dashboard-cohort-funnel/template.doc.mjs +2 -1
  109. package/assets/templates/pages/dashboard-composition/template.doc.mjs +2 -1
  110. package/assets/templates/pages/dashboard-progress/template.doc.mjs +6 -3
  111. package/assets/templates/pages/detail-page/template.doc.mjs +10 -3
  112. package/assets/templates/pages/documentation/template.doc.mjs +4 -1
  113. package/assets/templates/pages/documentation-design/template.doc.mjs +7 -1
  114. package/assets/templates/pages/documentation-technical/template.doc.mjs +7 -1
  115. package/assets/templates/pages/editor/template.doc.mjs +1 -7
  116. package/assets/templates/pages/file-explorer/template.doc.mjs +1 -1
  117. package/assets/templates/pages/form-two-column/template.doc.mjs +4 -3
  118. package/assets/templates/pages/form-wizard/template.doc.mjs +5 -3
  119. package/assets/templates/pages/gallery-hero/template.doc.mjs +4 -2
  120. package/assets/templates/pages/ide/page.tsx +24 -2
  121. package/assets/templates/pages/library/template.doc.mjs +4 -1
  122. package/assets/templates/pages/login/template.doc.mjs +2 -1
  123. package/assets/templates/pages/login-card/template.doc.mjs +2 -1
  124. package/assets/templates/pages/login-split/template.doc.mjs +2 -1
  125. package/assets/templates/pages/login-sso/template.doc.mjs +4 -2
  126. package/assets/templates/pages/mixed-gallery/template.doc.mjs +2 -1
  127. package/assets/templates/pages/product-detail/template.doc.mjs +4 -2
  128. package/assets/templates/pages/product-gallery/template.doc.mjs +2 -1
  129. package/assets/templates/pages/settings-dialog/template.doc.mjs +2 -1
  130. package/assets/templates/pages/settings-sidebar/template.doc.mjs +2 -1
  131. package/assets/templates/pages/shell-nav/template.doc.mjs +4 -2
  132. package/assets/templates/pages/shell-side-nav/template.doc.mjs +5 -3
  133. package/assets/templates/pages/shell-top-nav/template.doc.mjs +2 -1
  134. package/assets/templates/pages/side-gallery/template.doc.mjs +9 -1
  135. package/assets/templates/pages/table-filter/template.doc.mjs +9 -8
  136. package/assets/templates/pages/table-grouped/template.doc.mjs +4 -2
  137. package/assets/templates/pages/table-page/template.doc.mjs +5 -4
  138. package/assets/templates/pages/table-tree/template.doc.mjs +6 -3
  139. package/assets/templates/pages/theme-showcase/template.doc.mjs +2 -1
  140. package/assets/templates/pages/work-item-detail/template.doc.mjs +1 -0
  141. package/authoring/debug/parse.d.mts +3 -3
  142. package/authoring/doctypes/_schema.d.mts +3 -3
  143. package/authoring/doctypes/command/command.doc.mjs +1 -1
  144. package/authoring/doctypes/template/template.doc.mjs +1 -1
  145. package/authoring/doctypes/template/type.ts +9 -0
  146. package/clients/cli/bin/astryx.mjs +6 -9
  147. package/clients/cli/build-id.generated.json +1 -1
  148. package/clients/cli/commands/component.doc.mjs +1 -1
  149. package/clients/cli/commands/component.mjs +20 -2
  150. package/clients/cli/commands/docs.doc.mjs +7 -1
  151. package/clients/cli/commands/docs.mjs +3 -1
  152. package/clients/cli/commands/doctor.mjs +22 -14
  153. package/clients/cli/commands/experimental/render.mjs +32 -1
  154. package/clients/cli/commands/experimental/theme.mjs +27 -2
  155. package/clients/cli/commands/experimental-render.doc.mjs +2 -2
  156. package/clients/cli/commands/experimental-theme-compile.doc.mjs +3 -3
  157. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +1 -1
  158. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +1 -1
  159. package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
  160. package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
  161. package/clients/cli/commands/search.doc.mjs +2 -1
  162. package/clients/cli/commands/search.mjs +6 -1
  163. package/clients/cli/commands/template.mjs +4 -2
  164. package/clients/cli/commands/theme-build.doc.mjs +5 -1
  165. package/clients/cli/commands/theme.doc.mjs +1 -1
  166. package/clients/cli/commands/theme.mjs +138 -3
  167. package/clients/cli/commands/upgrade.mjs +42 -7
  168. package/clients/cli/index.mjs +1 -1
  169. package/clients/cli/lib/component-format.mjs +205 -98
  170. package/clients/cli/lib/hook-format.mjs +9 -19
  171. package/clients/cli/manifest.generated.json +1 -1
  172. package/foundation/agent-docs/agent-docs.mjs +1 -1
  173. package/foundation/config/theme-state.d.mts +13 -1
  174. package/foundation/config/theme-state.mjs +47 -7
  175. package/foundation/discovery/component-discovery.d.mts +11 -0
  176. package/foundation/discovery/component-discovery.mjs +27 -2
  177. package/foundation/discovery/component-replacement.mjs +130 -1
  178. package/foundation/discovery/entry-name-files.d.mts +43 -0
  179. package/foundation/discovery/entry-name-files.mjs +264 -0
  180. package/foundation/discovery/hook-discovery.d.mts +8 -2
  181. package/foundation/discovery/hook-discovery.mjs +20 -7
  182. package/foundation/discovery/runner-allowlist.d.mts +1 -0
  183. package/foundation/discovery/runner-allowlist.mjs +2 -0
  184. package/foundation/discovery/template-adapter.d.mts +52 -0
  185. package/foundation/discovery/template-adapter.mjs +169 -0
  186. package/foundation/discovery/theme-imports.d.mts +14 -0
  187. package/foundation/discovery/theme-imports.mjs +43 -1
  188. package/foundation/doc-compiler/import.mjs +7 -1
  189. package/foundation/doc-compiler/parse-readable.mjs +4 -1
  190. package/foundation/doc-compiler/stored-docs.d.mts +22 -0
  191. package/foundation/doc-compiler/stored-docs.mjs +49 -0
  192. package/foundation/fs/cache-eviction.d.mts +21 -0
  193. package/foundation/fs/cache-eviction.mjs +73 -0
  194. package/foundation/fs/gather-cache.d.mts +25 -4
  195. package/foundation/fs/gather-cache.mjs +138 -52
  196. package/foundation/fs/jiti-cache.d.mts +19 -1
  197. package/foundation/fs/jiti-cache.mjs +130 -6
  198. package/foundation/fs/kept-tree.d.mts +60 -0
  199. package/foundation/fs/kept-tree.mjs +154 -0
  200. package/foundation/fs/module-loader.d.mts +18 -2
  201. package/foundation/fs/module-loader.mjs +92 -20
  202. package/foundation/identity/provider-identity.d.mts +6 -0
  203. package/foundation/identity/provider-identity.mjs +10 -1
  204. package/foundation/render/file-header.d.mts +66 -0
  205. package/foundation/render/file-header.mjs +118 -0
  206. package/foundation/render/host-answer.d.mts +18 -0
  207. package/foundation/render/host-answer.mjs +46 -0
  208. package/foundation/render/host-exit.d.mts +1 -0
  209. package/foundation/render/host-exit.mjs +6 -1
  210. package/foundation/render/html-reader.d.mts +55 -2
  211. package/foundation/render/html-reader.mjs +145 -26
  212. package/foundation/render/markup-edits.d.mts +57 -0
  213. package/foundation/render/markup-edits.mjs +182 -0
  214. package/foundation/render/page-host.mjs +29 -12
  215. package/foundation/render/page-worker.mjs +79 -10
  216. package/foundation/render/render-page.d.mts +34 -2
  217. package/foundation/render/render-page.mjs +210 -29
  218. package/foundation/render/source-block.d.mts +73 -6
  219. package/foundation/render/source-block.mjs +170 -19
  220. package/foundation/render/ts-paths.d.mts +4 -1
  221. package/foundation/render/ts-paths.mjs +7 -3
  222. package/foundation/response/error-codes.d.mts +2 -1
  223. package/foundation/response/error-codes.doc.mjs +7 -1
  224. package/foundation/response/error-codes.mjs +7 -0
  225. package/foundation/text/string-utils.d.mts +3 -2
  226. package/foundation/text/string-utils.mjs +16 -3
  227. package/foundation/text/suggest-order.d.mts +9 -0
  228. package/foundation/text/suggest-order.mjs +13 -0
  229. package/package.json +6 -6
@@ -26,16 +26,17 @@ import {
26
26
  wordTable,
27
27
  } from './_tables.mjs';
28
28
  import {PALETTE_DIALS, isGraySeed, seedOf} from './_palette.mjs';
29
- import {focusStateOf} from './_settings.mjs';
29
+ import {focusStateOf, partRuleTokens} from './_settings.mjs';
30
30
  import {levenshteinDistance} from '../../foundation/text/levenshtein.mjs';
31
- import {cssProperties, keywordsOf, matchValue} from './_css.mjs';
31
+ import {cssProperties, keywordsOf, matchValue, splitTop} from './_css.mjs';
32
32
 
33
33
  /** @typedef {import('./_how-commands.mjs').Step} Step */
34
+ /** @typedef {import('./_how-commands.mjs').MeasureIntent} MeasureIntent */
34
35
 
35
36
  /**
36
37
  * One answer: what it does, and the ways to do it. Each option is a list of
37
38
  * steps run in order; most options are one step.
38
- * @typedef {{text: string, options: Step[][], sequence?: boolean, lookup?: string}} Draft
39
+ * @typedef {{text: string, options: Step[][], sequence?: boolean, lookup?: string, intent?: MeasureIntent}} Draft
39
40
  */
40
41
 
41
42
  /**
@@ -102,6 +103,9 @@ const TRANSLATE = /** @type {Array<[RegExp, string]>} */ (
102
103
  */
103
104
  const DESIGN_WORDS = [
104
105
  'leading',
106
+ // A part's name, never a near miss of "radius".
107
+ 'radio',
108
+ 'radios',
105
109
  'header',
106
110
  'headers',
107
111
  'input',
@@ -356,6 +360,13 @@ const SHADED = wordTable(
356
360
 
357
361
  /** The color tokens a word for a color the theme uses names. */
358
362
  const THEME_COLOR_WORDS = /** @type {Array<[RegExp, string, string]>} */ ([
363
+ // "a light tint of the accent": the accent mixed with see-through, so the
364
+ // fill beneath shows (never the full accent).
365
+ [
366
+ /\b(?:light|soft|pale|subtle|faint) (?:tint|wash) of (?:the )?(?:accent|brand|primary)(?: colou?r)?\b/,
367
+ 'color-mix(in srgb, var(--color-accent) 15%, transparent)',
368
+ 'var(--color-text-accent)',
369
+ ],
359
370
  [
360
371
  /\b(accent|brand|primary) colou?r(ed)?\b|\bin (the )?accent\b|\baccent\b/,
361
372
  'var(--color-accent)',
@@ -498,7 +509,7 @@ const tallIn = c =>
498
509
 
499
510
  /** A length tied to a radius word ("8px radius", "radius: 8px"). @param {string} c */
500
511
  const radiusIn = c =>
501
- /(-?\d*\.?\d+(?:px|rem|em|%)?)\s*(?:border[\s-]+)?(?:radius|corners?)\b|\b(?:radius|corners?|rounded)\s*(?:values?\s+)?(?:are|is|of|at)?\s*:?\s*(?:to\s+)?(?:about\s+|around\s+)?(-?\d*\.?\d+(?:px|rem|em|%)?)(?:\b|(?<=%))/
512
+ /(-?\d*\.?\d+(?:px|rem|em|%)?)\s*(?:border[\s-]+)?(?:radius|corners?)\b|\b(?:radius|corners?|rounded)\s*(?:values?\s+)?(?:are|is|of|at)?\s*:?\s*(?:to\s+)?(?:about\s+|around\s+)?(-?\d*\.?\d+(?:px|rem|em|%)?)(?:\b|(?<=%))(?!\s*(?:more\s+)?(?:steps?|sizes?|notches?|levels?)\b)/
502
513
  .exec(c)
503
514
  ?.slice(1)
504
515
  .find(Boolean) ?? null;
@@ -515,6 +526,187 @@ function shift(color, amount) {
515
526
  return hex(rgb.map(c => c + (to - c) * a));
516
527
  }
517
528
 
529
+ /**
530
+ * Warmer or cooler: mix in a warm (amber) or cool (blue) tint and keep the
531
+ * color's lightness, so the hue moves and the light/dark does not.
532
+ * @param {string} color @param {'warm' | 'cool'} way @param {number} amount 0 to 1
533
+ */
534
+ export function tempShift(color, way, amount) {
535
+ const rgb = parseColor(color);
536
+ if (!rgb) return null;
537
+ const tint = way === 'warm' ? [255, 170, 80] : [80, 150, 255];
538
+ const mixed = rgb.slice(0, 3).map((x, i) => x + (tint[i] - x) * amount);
539
+ const lum = (/** @type {number[]} */ v) =>
540
+ 0.2126 * v[0] + 0.7152 * v[1] + 0.0722 * v[2];
541
+ const k = lum(mixed) > 0 ? lum(rgb) / lum(mixed) : 1;
542
+ const out = mixed.map(x => Math.max(0, Math.min(255, x * k)));
543
+ // Clipped at white: pull the brightest channel back so the hue still shows.
544
+ return hex(out);
545
+ }
546
+
547
+ /**
548
+ * The overlay made lighter or darker: only its alpha moves, by the amount
549
+ * asked (a step is a quarter), and it never turns fully opaque or vanishes.
550
+ * @param {string} now @param {{text: string, dir: string | null, neg: boolean}} c
551
+ */
552
+ function overlayAlpha(now, c) {
553
+ const rgb = parseColor(now);
554
+ if (!rgb) return null;
555
+ const m = /^#[0-9a-f]{6}([0-9a-f]{2})$/i.exec(String(now).trim());
556
+ const fn = /\/\s*([\d.]+%?)\s*\)$/.exec(String(now).trim())?.[1];
557
+ const a = m
558
+ ? parseInt(m[1], 16) / 255
559
+ : fn
560
+ ? fn.endsWith('%')
561
+ ? Number.parseFloat(fn) / 100
562
+ : Number(fn)
563
+ : 1;
564
+ const darker =
565
+ c.dir === 'more' && !c.neg && !/\blight(er|en)?\b/.test(c.text);
566
+ const amount = colorAmount(c.text, 0.25);
567
+ const next = Math.max(
568
+ 0.05,
569
+ Math.min(0.9, darker ? a * (1 + amount) : a * (1 - amount)),
570
+ );
571
+ const byte = Math.round(next * 255)
572
+ .toString(16)
573
+ .padStart(2, '0');
574
+ return `${hex(rgb.slice(0, 3))}${byte}`;
575
+ }
576
+
577
+ /**
578
+ * A box-shadow with each layer's blur scaled (the third length); offsets,
579
+ * spread, inset and color stay. Null when no layer has a blur to scale.
580
+ * @param {string} shadow @param {number} f
581
+ */
582
+ export function blurScaled(shadow, f) {
583
+ const layers = String(shadow).split(/,(?![^(]*\))/);
584
+ let changed = false;
585
+ const out = layers.map(layer => {
586
+ // The lengths outside any function (a color's numbers are not
587
+ // lengths): the third is the blur.
588
+ let depth = 0;
589
+ let count = 0;
590
+ let res = '';
591
+ const re = /[()]|-?\d*\.?\d+(?:px|rem|em)?(?![\w.%])/g;
592
+ let last = 0;
593
+ for (let m = re.exec(layer); m; m = re.exec(layer)) {
594
+ const tok = m[0];
595
+ if (tok === '(') depth++;
596
+ else if (tok === ')') depth--;
597
+ else if (
598
+ (depth === 0 && /^-?\d/.test(tok)) ||
599
+ (depth === 0 && /^-?\./.test(tok))
600
+ ) {
601
+ const before = layer[m.index - 1];
602
+ if (m.index === 0 || /\s/.test(before ?? ' ')) {
603
+ count++;
604
+ if (count === 3) {
605
+ const n = /^(-?\d*\.?\d+)(px|rem|em)?$/.exec(tok);
606
+ if (n) {
607
+ const unit = n[2] ?? 'px';
608
+ const v = Number(n[1]) * f;
609
+ res +=
610
+ layer.slice(last, m.index) +
611
+ `${Number(v.toFixed(unit === 'px' ? 2 : 3))}${unit}`;
612
+ last = m.index + tok.length;
613
+ changed = true;
614
+ }
615
+ }
616
+ }
617
+ }
618
+ }
619
+ return res + layer.slice(last);
620
+ });
621
+ return changed ? out.join(',') : null;
622
+ }
623
+
624
+ /**
625
+ * The share a color amount gives ("30% lighter", "half as dark"): a
626
+ * number from 0 to 0.9, or the fallback.
627
+ * @param {string} text @param {number} fallback
628
+ */
629
+ export function colorAmount(text, fallback) {
630
+ const pct = /(\d{1,3}(?:\.\d+)?)\s?%/.exec(text);
631
+ if (pct) return Math.min(0.9, Number(pct[1]) / 100);
632
+ if (/\b(a (little|bit|touch)|slightly|a tad)\b/.test(text))
633
+ return fallback / 2;
634
+ if (/\b(much|a lot|way|far)\b/.test(text)) return Math.min(0.9, fallback * 2);
635
+ return fallback;
636
+ }
637
+
638
+ /**
639
+ * {@link shift} that keeps a see-through color see-through: its alpha
640
+ * stays, only its hue moves.
641
+ * @param {string} color @param {number} amount
642
+ */
643
+ export function shiftKeepAlpha(color, amount) {
644
+ // rgb()/rgba()/hsl()/hwb()/lab()/oklch() with an alpha: the same color as
645
+ // #rrggbbaa, so its alpha stays too.
646
+ const fn =
647
+ /^(?:rgba?|hsla?|hwb|lab|lch|oklab|oklch)\((.*)\)$/i.exec(
648
+ String(color).trim(),
649
+ )?.[1] ?? null;
650
+ if (fn) {
651
+ const alphaText =
652
+ /\/\s*([\d.]+%?)\s*$/.exec(fn)?.[1] ??
653
+ (/^\s*rgba|^\s*hsla/i.test(String(color).trim())
654
+ ? /,\s*([\d.]+%?)\s*$/.exec(fn)?.[1]
655
+ : undefined);
656
+ const rgb = parseColor(color);
657
+ if (alphaText && rgb) {
658
+ const a = alphaText.endsWith('%')
659
+ ? Number.parseFloat(alphaText) / 100
660
+ : Number(alphaText);
661
+ if (a >= 0 && a < 1) {
662
+ const byte = Math.max(0, Math.min(255, Math.round(a * 255)));
663
+ return shiftKeepAlpha(
664
+ `${hex(rgb.slice(0, 3))}${byte.toString(16).padStart(2, '0')}`,
665
+ amount,
666
+ );
667
+ }
668
+ }
669
+ }
670
+ const m = /^#([0-9a-f]{6})([0-9a-f]{2})$/i.exec(String(color).trim());
671
+ if (!m) return shift(color, amount);
672
+ // A see-through ink: lighter means less of a dark ink (fainter) or more
673
+ // of a light one (stronger); its hue stays.
674
+ const rgb = parseColor(`#${m[1]}`) ?? [0, 0, 0];
675
+ const darkInk = rgb[0] + rgb[1] + rgb[2] < 382;
676
+ const k = Math.min(0.9, Math.abs(amount) * 2.5);
677
+ const f = amount > 0 === darkInk ? 1 - k : 1 + k;
678
+ const a = Math.max(1, Math.min(255, Math.round(parseInt(m[2], 16) * f)));
679
+ return `#${m[1]}${a.toString(16).padStart(2, '0')}`;
680
+ }
681
+
682
+ /**
683
+ * The color token a part reads at rest for a group (its fill or its text):
684
+ * the variant asked for, else its main variant (primary, accent), else any
685
+ * read at rest; never a pressed or hover overlay.
686
+ * @param {Array<{token: string, when: string[]}>} reads
687
+ * @param {string} [when] a variant asked for, `variant:primary`
688
+ * @returns {string | null}
689
+ */
690
+ export function restColorRead(reads, when) {
691
+ const rest = reads.filter(
692
+ r =>
693
+ /^--color-/.test(r.token) &&
694
+ !/overlay|transparent|tint/.test(r.token) &&
695
+ r.when.some(w => !w.includes(':')),
696
+ );
697
+ const asked = when ? when.replace(':', '=') : null;
698
+ return (
699
+ (
700
+ (asked ? rest.find(r => r.when.includes(asked)) : null) ??
701
+ rest.find(r =>
702
+ r.when.some(w => w === '' || /=(primary|accent)$/.test(w)),
703
+ ) ??
704
+ rest[0] ??
705
+ null
706
+ )?.token ?? null
707
+ );
708
+ }
709
+
518
710
  /**
519
711
  * A color made stronger or fainter: a see-through color (#00000014) keeps
520
712
  * its hue and scales its alpha; an opaque one moves toward black or white.
@@ -550,9 +742,177 @@ function scaled(v, f) {
550
742
  const m = /^(\d*\.?\d+)(px|rem|em)$/.exec(String(v ?? '').trim());
551
743
  if (!m) return null;
552
744
  const n = Number(m[1]) * f;
553
- return `${m[2] === 'px' ? Math.round(n) : Number(n.toFixed(3))}${m[2]}`;
745
+ // A fraction of a pixel is a real length (hi-dpi screens draw it): kept
746
+ // to 0.01px, never rounded away to the same value or to 0.
747
+ return `${m[2] === 'px' ? Number(n.toFixed(2)) : Number(n.toFixed(3))}${m[2]}`;
748
+ }
749
+
750
+ /**
751
+ * The question without its amount words ("3 times", "2x", "x2", "×2",
752
+ * "+50%", "50 percent", "by a factor of 2"), so a number in them is never
753
+ * read as a length.
754
+ * @param {string} text
755
+ */
756
+ function withoutAmount(text) {
757
+ return text
758
+ .replace(/\bby a factor of \d*\.?\d+\b/g, ' ')
759
+ .replace(
760
+ /\b(scale|multiply)\b([^.]*?)\bby \d*\.?\d+\b(?!\s*(px|rem|em|%))/g,
761
+ '$1$2',
762
+ )
763
+ .replace(/\b\d*\.?\d+(?:px)?\s*(?:times|x|×)(?=\s|$|\b)/g, ' ')
764
+ .replace(/(^|\s)[x×]\s?\d*\.?\d+\b/g, ' ')
765
+ .replace(/(^|[\s(])[+-]\s?\d{1,3}(?:\.\d+)?(?:px)?\s?(%|percent\b)/g, ' ')
766
+ .replace(/(?:^|\s)0?\.\d+(?:px)?\s+(?=(the|of)\b)/g, ' ')
767
+ .replace(
768
+ /\b\d{1,3}(?:\.\d+)?(?:px)?\s?(%|percent\b)\s*(?=(bigger|larger|more|wider|taller|thicker|higher|roomier|smaller|less|tighter|narrower|thinner|shorter|lower|transparent|opaque|strength|of|as)\b)/g,
769
+ ' ',
770
+ );
771
+ }
772
+
773
+ /**
774
+ * Scale each side of a box value (`4px 8px` by 2 is `8px 16px`); a 0 side
775
+ * stays 0. Null when a side is not a length this scales.
776
+ * @param {string} v @param {number} f
777
+ */
778
+ function scaledBox(v, f) {
779
+ const sides = String(v ?? '')
780
+ .trim()
781
+ .split(/\s+/);
782
+ if (!sides.length || sides.length > 4) return null;
783
+ const out = sides.map(x => (/^0(px|rem|em)?$/.test(x) ? x : scaled(x, f)));
784
+ return out.every(Boolean) ? out.join(' ') : null;
785
+ }
786
+
787
+ /**
788
+ * "half the radius on buttons and cards on hover": two parts joined by
789
+ * "and" share everything around them (the ask before, the value and state
790
+ * after), so each piece is the whole ask for its part: "half the radius on
791
+ * buttons on hover and half the radius on cards on hover". Within one
792
+ * sentence or comma piece, once.
793
+ * @param {string} q
794
+ * @param {Array<[RegExp, PartRef]>} partWords
795
+ * @returns {string}
796
+ */
797
+ function sharedAsk(q, partWords) {
798
+ return (
799
+ q
800
+ // The same breaks clausesOf splits at: a full stop only before a space
801
+ // or the end (never inside 0.5rem), a comma only outside parentheses.
802
+ .split(/([;\n]|,(?![^(]*\))|\.(?=\s|$))/)
803
+ .map(seg => {
804
+ const m = /\s+and\s+/.exec(seg);
805
+ if (!m || /\band\b/.test(seg.slice(m.index + m[0].length))) return seg;
806
+ // "everything rounder except buttons and cards": both are excepted,
807
+ // from one ask.
808
+ if (/\bexcept\b/.test(seg.slice(0, m.index))) return seg;
809
+ // "the card and dialog corners match": one ask about both.
810
+ if (/\b(match|equally|alike|the same)\b/.test(seg)) return seg;
811
+ const left = seg.slice(0, m.index);
812
+ const right = seg.slice(m.index + m[0].length);
813
+ for (const [re] of partWords) {
814
+ const l = new RegExp(`(?:${re.source})\\s*$`).exec(left);
815
+ if (!l) continue;
816
+ for (const [re2] of partWords) {
817
+ const r = new RegExp(`^\\s*(?:${re2.source})`).exec(right);
818
+ if (!r) continue;
819
+ const lead = left.slice(0, l.index);
820
+ const tail = right.slice(r[0].length);
821
+ // Only when something is shared: an ask on one side.
822
+ if (!lead.trim() && !tail.trim()) return seg;
823
+ // "the text bigger on buttons and cards red": the second part
824
+ // has an ask of its own (a color, an aspect), so only the first
825
+ // takes the ask before; nothing is shared.
826
+ const tailAsk = tail
827
+ .replace(
828
+ /\b(?:on|when|while|in)\s+(?:hover|focus|press(?:ed)?|active|disabled|selected|dark mode|light mode)\b|\bto\s+\S+/g,
829
+ ' ',
830
+ )
831
+ .trim();
832
+ if (
833
+ tailAsk &&
834
+ (colorsIn(tailAsk).length || aspectsOf(tailAsk).length) &&
835
+ (colorsIn(lead).length || aspectsOf(lead).length)
836
+ )
837
+ return seg;
838
+ return `${lead}${l[0].trim()}${tail} and ${lead}${r[0].trim()}${tail}`;
839
+ }
840
+ }
841
+ return seg;
842
+ })
843
+ .join('')
844
+ );
845
+ }
846
+
847
+ /** The families each kind of ask may change. @type {Record<string, string[]>} */
848
+ const ASPECT_FAMILIES = {
849
+ background: ['color', 'opacity'],
850
+ text: ['color'],
851
+ corners: ['radius'],
852
+ spacing: ['space'],
853
+ size: ['space', 'fontsize', 'border', 'radius'],
854
+ border: ['border', 'color'],
855
+ weight: ['weight'],
856
+ opacity: ['opacity', 'color'],
857
+ shadow: ['shadow', 'border', 'color'],
858
+ fontsize: ['fontsize'],
859
+ };
860
+
861
+ /** A step count: "two steps bigger", "3 sizes smaller", "two notches rounder". */
862
+ const STEP_COUNT =
863
+ /\b(two|three|four|five|2|3|4|5)\s+(?:more\s+)?(?:steps?|sizes?|notches?|levels?|(?:spacing\s+)?units?)\b/;
864
+ /** @type {Record<string, number>} */
865
+ const WORD_NUMBERS = {two: 2, three: 3, four: 4, five: 5};
866
+
867
+ /**
868
+ * A color with its hue moved toward a target hue by up to `step` degrees;
869
+ * lightness and saturation stay. Null for a color that does not read, or
870
+ * a gray (no hue to move).
871
+ * @param {string} color
872
+ * @param {number} target degrees
873
+ * @param {number} step degrees
874
+ */
875
+ export function hueToward(color, target, step) {
876
+ const rgb = parseColor(color);
877
+ if (!rgb) return null;
878
+ const [r, g, b] = rgb.map(v => v / 255);
879
+ const max = Math.max(r, g, b);
880
+ const min = Math.min(r, g, b);
881
+ const l = (max + min) / 2;
882
+ const dlt = max - min;
883
+ if (dlt < 0.04) return null;
884
+ const sat = dlt / (1 - Math.abs(2 * l - 1));
885
+ let h =
886
+ max === r
887
+ ? ((g - b) / dlt) % 6
888
+ : max === g
889
+ ? (b - r) / dlt + 2
890
+ : (r - g) / dlt + 4;
891
+ h = (h * 60 + 360) % 360;
892
+ let diff = ((target - h + 540) % 360) - 180;
893
+ if (Math.abs(diff) > step) diff = Math.sign(diff) * step;
894
+ const nh = (h + diff + 360) % 360;
895
+ const cc = (1 - Math.abs(2 * l - 1)) * sat;
896
+ const x = cc * (1 - Math.abs(((nh / 60) % 2) - 1));
897
+ const m = l - cc / 2;
898
+ const [r1, g1, b1] =
899
+ nh < 60
900
+ ? [cc, x, 0]
901
+ : nh < 120
902
+ ? [x, cc, 0]
903
+ : nh < 180
904
+ ? [0, cc, x]
905
+ : nh < 240
906
+ ? [0, x, cc]
907
+ : nh < 300
908
+ ? [x, 0, cc]
909
+ : [cc, 0, x];
910
+ return hex([r1 + m, g1 + m, b1 + m].map(v => Math.round(v * 255)));
554
911
  }
555
912
 
913
+ /** A keep step for a part the change does not reach. */
914
+ const UNTOUCHED = /** @type {const} */ ('untouched');
915
+
556
916
  /**
557
917
  * The part a clause measures against ("cards twice the padding of
558
918
  * buttons": buttons), by clause.
@@ -568,22 +928,101 @@ const compared = new WeakMap();
568
928
  * @returns {number | null}
569
929
  */
570
930
  export function exactFactor(text) {
571
- const t = text.toLowerCase();
572
- if (/\b(half|halve|halved)\b/.test(t)) return 0.5;
931
+ const t = text
932
+ .toLowerCase()
933
+ .replace(/½/g, ' 1/2 ')
934
+ .replace(/¼/g, ' 1/4 ')
935
+ .replace(/⅓/g, ' 1/3 ')
936
+ .replace(/×/g, ' x ')
937
+ .replace(/(\d)(?:px)?\s*percent\b/g, '$1%')
938
+ .replace(/(\d)px(?=\s*(?:%|times|x\b))/g, '$1')
939
+ .replace(/\s+/g, ' ');
940
+ const SHRINK = /^(smaller|less|tighter|narrower|thinner|shorter|lower)$/;
941
+ const GROW = /^(bigger|larger|more|wider|taller|thicker|higher|roomier)$/;
942
+ /** A change by a share: "a quarter bigger", "+50%", "cut by a third". @param {number} share @param {boolean} down */
943
+ const by = (share, down) => {
944
+ const f = down ? 1 - share : 1 + share;
945
+ return f >= 0 ? f : null;
946
+ };
947
+ const fraction = (/** @type {string} */ w) =>
948
+ ({
949
+ half: 0.5,
950
+ 'a half': 0.5,
951
+ 'a third': 1 / 3,
952
+ 'a quarter': 0.25,
953
+ '1/2': 0.5,
954
+ '1/3': 1 / 3,
955
+ '1/4': 0.25,
956
+ })[w] ?? null;
957
+ // "half again as big": one and a half; "a third again": four thirds.
958
+ if (/\bhalf again\b/.test(t)) return 1.5;
959
+ const again = /\b(a third|a quarter|1\/3|1\/4) again\b/.exec(t);
960
+ if (again) return /third|3/.test(again[1]) ? 4 / 3 : 1.25;
961
+ // "a quarter bigger", "a third smaller", "cut by a third", "reduce by half".
962
+ const share =
963
+ /\b(a half|half|a third|a quarter|1\/2|1\/3|1\/4)\s+(bigger|larger|more|wider|taller|thicker|higher|smaller|less|tighter|narrower|thinner|shorter|lower)\b/.exec(
964
+ t,
965
+ );
966
+ if (share) {
967
+ const f = fraction(share[1]);
968
+ if (f != null) return by(f, SHRINK.test(share[2]));
969
+ }
970
+ const cut =
971
+ /\b(cut|reduce|lower|shrink|decrease|increase|raise|grow)\b[^.]*?\bby (a half|half|a third|a quarter|1\/2|1\/3|1\/4)\b/.exec(
972
+ t,
973
+ );
974
+ if (cut) {
975
+ const f = fraction(cut[2]);
976
+ if (f != null) return by(f, !/^(increase|raise|grow)$/.test(cut[1]));
977
+ }
978
+ // "+50%", "-25%", "50% bigger", "100% smaller".
979
+ const signed = /(^|[\s(])([+-])\s?(\d{1,3}(?:\.\d+)?)\s?%/.exec(t);
980
+ if (signed) return by(Number(signed[3]) / 100, signed[2] === '-');
981
+ const pctBy =
982
+ /\b(\d{1,3}(?:\.\d+)?)\s?%\s*(bigger|larger|more|wider|taller|thicker|higher|roomier|smaller|less|tighter|narrower|thinner|shorter|lower)\b/.exec(
983
+ t,
984
+ );
985
+ if (pctBy && Number(pctBy[1]) > 0)
986
+ return by(Number(pctBy[1]) / 100, SHRINK.test(pctBy[2]));
987
+ const pct = /\b(\d{1,3}(?:\.\d+)?)\s?%\s*(?:strength|of|as)\b/.exec(t);
988
+ if (pct && Number(pct[1]) > 0) return Number(pct[1]) / 100;
989
+ if (/\b(half|halve|halved|1\/2)\b/.test(t)) return 0.5;
990
+ // "½ the padding" (read as 0.5 the padding).
991
+ const lead = /(?:^|\s)(0?\.\d+)(?:px)?\s+(?:the|of)\b/.exec(t);
992
+ if (lead) return Number(lead[1]);
573
993
  if (/\b(double|doubled|twice)\b/.test(t)) return 2;
574
994
  if (/\b(triple|tripled|three times)\b/.test(t)) return 3;
575
- if (/\ba third\b/.test(t)) return 1 / 3;
576
- if (/\ba quarter\b/.test(t)) return 0.25;
577
- const pct = /\b(\d{1,3})\s?%\s*(?:strength|of|as)\b/.exec(t);
578
- if (pct && Number(pct[1]) > 0) return Number(pct[1]) / 100;
579
- const times = /\bx\s?(\d*\.?\d+)\b/.exec(t);
580
- if (times && Number(times[1]) > 0 && Number(times[1]) <= 4)
995
+ if (/\b(quadruple|quadrupled|four times)\b/.test(t)) return 4;
996
+ if (/\b(a third|1\/3)\b/.test(t)) return 1 / 3;
997
+ if (/\b(a quarter|1\/4)\b/.test(t)) return 0.25;
998
+ // "by a factor of 2", "scale … by 1.5", "multiply … by 2".
999
+ const factor =
1000
+ /\bby a factor of (\d*\.?\d+)\b/.exec(t) ??
1001
+ /\b(?:scale|multiply)\b[^.]*?\bby (\d*\.?\d+)\b(?!\s*(?:px|rem|em|%))/.exec(
1002
+ t,
1003
+ );
1004
+ if (factor && Number(factor[1]) >= 0 && Number(factor[1]) <= 10)
1005
+ return Number(factor[1]);
1006
+ // "16 x 16", "24x24px": a size, never a factor.
1007
+ if (/\b\d*\.?\d+(?:px|rem|em)?\s*[x×]\s*\d*\.?\d+\b/.test(t)) return null;
1008
+ // "3 times bigger", "2 times smaller", "4 times", "2x", "1.5x", "x2".
1009
+ const nTimes =
1010
+ /\b(\d*\.?\d+)(?:px)?\s*(?:times|x)\b(?:\s+(bigger|larger|more|wider|taller|thicker|as|smaller|less|thinner|narrower))?/.exec(
1011
+ t,
1012
+ );
1013
+ if (nTimes && Number(nTimes[1]) >= 0 && Number(nTimes[1]) <= 20) {
1014
+ const n = Number(nTimes[1]);
1015
+ return nTimes[2] && SHRINK.test(nTimes[2]) ? (n > 0 ? 1 / n : null) : n;
1016
+ }
1017
+ const times = /(?:^|\s)x\s?(\d*\.?\d+)\b/.exec(t);
1018
+ if (times && Number(times[1]) >= 0 && Number(times[1]) <= 20)
581
1019
  return Number(times[1]);
1020
+ void GROW;
582
1021
  return null;
583
1022
  }
584
1023
 
585
1024
  /**
586
- * @typedef {{on: string, when?: string, role?: string, level?: string}} PartRef
1025
+ * @typedef {{on: string, when?: string, role?: string, level?: string, missing?: string}} PartRef
587
1026
  */
588
1027
 
589
1028
  /**
@@ -624,15 +1063,23 @@ const OVERRIDES = [
624
1063
  {on: 'dropdown-menu-item'},
625
1064
  ],
626
1065
  [/\b(nav(igation)? (links?|items?))\b/, {on: 'top-nav-item'}],
627
- [/\b((dropdown |context )?menus?)\b/, {on: 'dropdown-menu'}],
628
- [/\bfooters?\b/, {on: 'layout-footer'}],
1066
+ // A context menu is its own part in Core (its items are the dropdown
1067
+ // menu's items, which it reuses).
1068
+ [/\b(context ?menus?|right[- ]click menus?)\b/, {on: 'context-menu'}],
1069
+ [/\b((dropdown )?menus?)\b/, {on: 'dropdown-menu'}],
1070
+ // A part's own header or footer ("dialog header", "card footer") is that
1071
+ // part's, never the app's top bar or footer.
1072
+ [
1073
+ /(?<!\b(?:dialog|modal|card|drawer|sheet|popover|panel|section|table|menu)s? )\bfooters?\b/,
1074
+ {on: 'layout-footer'},
1075
+ ],
629
1076
  [/\b(side ?nav|sidebar|side ?panel)\b/, {on: 'side-nav'}],
630
1077
  [
631
1078
  /\b(app (name|title)|logo|site title|product name)\b/,
632
1079
  {on: 'top-nav-heading'},
633
1080
  ],
634
1081
  [
635
- /\b(header|top ?bar|title ?bar|nav ?bar|app ?bar|masthead)\b/,
1082
+ /(?<!\b(?:dialog|modal|card|drawer|sheet|popover|panel|section|table|menu)s? )\b(header|top ?bar|title ?bar|nav ?bar|app ?bar|masthead)\b/,
636
1083
  {on: 'app-shell-header'},
637
1084
  ],
638
1085
  [/\b(page|app background|whole background|body background)\b/, {on: 'page'}],
@@ -659,16 +1106,22 @@ const OVERRIDES = [
659
1106
  [/\b(checkbox(es)?|check ?marks?)\b/, {on: 'checks'}],
660
1107
  // "switch off", "switch the buttons to" are the verb, not the part.
661
1108
  [
662
- /\b(toggles?|switch(es)?(?! (off|on|to|the|out|it|them|over|back|from)\b))\b/,
1109
+ /\b(toggles?|switch(?:e?s)?(?! (off|on|to|the|out|it|them|over|back|from)\b))\b/,
663
1110
  {on: 'switch'},
664
1111
  ],
665
1112
  [/\b((table )?cells?)\b/, {on: 'table-cell'}],
666
1113
  [/\b(table rows?|rows?|tables?)\b/, {on: 'table-row'}],
667
1114
  [/\b(badges?|chips?|tags?)\b/, {on: 'badge'}],
668
- [/\bh([1-4])\b/, {on: 'heading'}],
1115
+ [/\bh([1-6])\b/, {on: 'heading'}],
669
1116
  [/\b(headings?|titles?)\b/, {on: 'heading'}],
670
1117
  [/\b(modals?|popups?)\b/, {on: 'dialog'}],
671
1118
  [/\bcode\b/, {on: 'code', role: 'code'}],
1119
+ // Small, secondary and supporting text, captions and fine print: the
1120
+ // supporting text style, not the base size.
1121
+ [
1122
+ /\b((?:small|secondary|supporting|helper|hint|caption|muted) (?:text|copy)|fine print|captions?)\b/,
1123
+ {on: 'body', role: 'supporting'},
1124
+ ],
672
1125
  [/\bbody( text)?\b/, {on: 'body', role: 'body'}],
673
1126
  ];
674
1127
 
@@ -739,7 +1192,7 @@ function partLexicon(ctx) {
739
1192
  .filter(key => key.includes('-') || !other(key))
740
1193
  .sort((x, y) => y.length - x.length)
741
1194
  .map(key => [
742
- new RegExp(`\\b${key.replace(/-/g, '[\\s-]?')}s?\\b`),
1195
+ new RegExp(`\\b${key.replace(/-/g, '[\\s-]?')}(?:e?s)?\\b`),
743
1196
  {on: key},
744
1197
  ]);
745
1198
  // Near misses are corrected to one-word part names and design words.
@@ -752,10 +1205,82 @@ function partLexicon(ctx) {
752
1205
  .flatMap(key => [key, `${key}s`]),
753
1206
  ]),
754
1207
  ];
1208
+ // Every group the editor knows, by its own name ("checks", "inputs"),
1209
+ // read from its groups table: set --on <group> takes the same words.
1210
+ /** @type {Array<[RegExp, PartRef]>} */
1211
+ const groups = Object.keys(FAMILIES).map(name => [
1212
+ new RegExp(`\\b${name.replace(/s$/, '')}s?\\b`),
1213
+ {on: name},
1214
+ ]);
1215
+ // A part's own sub-part named in words ("dialog header", "date range
1216
+ // input", "number inputs") is that catalog part, before any phrase of
1217
+ // one of its words. A sub-part Core does not have ("card header") is the
1218
+ // whole part, said in the answer.
1219
+ const keys = new Set(project.target.keys());
1220
+ /** @type {Array<[RegExp, PartRef]>} */
1221
+ const subParts = [];
1222
+ for (const key of keys) {
1223
+ if (key.includes('-')) continue;
1224
+ // "dialog close icon / button", "drawer header title": those parts.
1225
+ for (const [phrase, part] of [
1226
+ ['close (?:icon|button|x)', `${key}-header-close-icon`],
1227
+ ['header title', `${key}-header-title-block`],
1228
+ ])
1229
+ if (keys.has(part))
1230
+ subParts.push([
1231
+ new RegExp(`\\b${key}s?(?:'s)?\\s+${phrase}s?\\b`),
1232
+ {on: part},
1233
+ ]);
1234
+ for (const sub of ['header', 'footer', 'title']) {
1235
+ const real =
1236
+ sub === 'title' && keys.has(`${key}-header-title-block`)
1237
+ ? `${key}-header-title-block`
1238
+ : keys.has(`${key}-${sub}`)
1239
+ ? `${key}-${sub}`
1240
+ : null;
1241
+ // A phrase an override reads whole ("table header") keeps it.
1242
+ const phrase = `${key} ${sub}`;
1243
+ if (OVERRIDES.some(([re]) => re.exec(phrase)?.[0] === phrase)) continue;
1244
+ subParts.push([
1245
+ new RegExp(`\\b${key}s?[\\s-]${sub}s?\\b`),
1246
+ real ? {on: real} : {on: key, missing: `${key} ${sub}`},
1247
+ ]);
1248
+ }
1249
+ }
755
1250
  const lex = {
756
1251
  parts: [
1252
+ ...subParts,
1253
+ // A catalog name of two or more words said in full ("toggle
1254
+ // buttons", "code block header", "hover card") is that part.
1255
+ ...derived.filter(
1256
+ ([, x]) =>
1257
+ x.on.includes('-') &&
1258
+ // A phrase an override already reads whole ("progress bar",
1259
+ // "table header") keeps the override's part.
1260
+ !OVERRIDES.some(([re]) => {
1261
+ const phrase = x.on.replace(/-/g, ' ');
1262
+ return re.exec(phrase)?.[0] === phrase;
1263
+ }),
1264
+ ),
1265
+ /** @type {[RegExp, PartRef]} */ ([
1266
+ /\bselect(?:ion)?[\s-]?(?:box|menu|field|dropdown)(?:e?s)?\b/,
1267
+ {on: 'selector'},
1268
+ ]),
1269
+ // "inline code", "block quote": those parts, read whole (so their
1270
+ // first word is never a padding side).
1271
+ /** @type {[RegExp, PartRef]} */ ([/\binline[\s-]code\b/, {on: 'code'}]),
1272
+ /** @type {[RegExp, PartRef]} */ ([
1273
+ /\bblock[\s-]?quotes?\b/,
1274
+ {on: 'blockquote'},
1275
+ ]),
1276
+ // "date pickers": Core's date input.
1277
+ /** @type {[RegExp, PartRef]} */ ([
1278
+ /\bdate ?pickers?\b/,
1279
+ {on: 'date-input'},
1280
+ ]),
757
1281
  ...OVERRIDES,
758
1282
  ...derived,
1283
+ ...groups,
759
1284
  // "smaller labels on form fields": a field's label.
760
1285
  /** @type {[RegExp, PartRef]} */ ([
761
1286
  /(?<!\b(?:button|tab|badge|chip|nav|menu|link|checkbox|switch|radio)s? )\b(field |form |input )?labels?\b/,
@@ -805,7 +1330,7 @@ const STATE_WORDS = /** @type {Array<[RegExp, string]>} */ ([
805
1330
  * One clause, read.
806
1331
  * @typedef {object} Clause
807
1332
  * @property {string} text
808
- * @property {Array<{on: string, when?: string, role?: string, level?: string}>} parts
1333
+ * @property {Array<{on: string, when?: string, role?: string, level?: string, missing?: string}>} parts
809
1334
  * @property {string[]} aspects
810
1335
  * @property {boolean} neg
811
1336
  * @property {'more' | 'less' | null} dir
@@ -995,9 +1520,12 @@ const FONT_NAMES = [...Object.keys(OPEN_FONTS), ...Object.keys(FONTS)]
995
1520
  */
996
1521
  function clausesOf(q, partWords) {
997
1522
  // "swap X and Y" is one ask.
998
- const pieces = (/\bswap\b/.test(q) ? q.replace(/\band\b/g, '&') : q)
1523
+ const pieces = (
1524
+ /\bswap\b/.test(q) ? q.replace(/\band\b/g, '&') : sharedAsk(q, partWords)
1525
+ )
999
1526
  .split(
1000
- /;|\.(?=\s|$)|,(?![^(]*\))|\b(?:and|with|but|then|plus|also|y|et|und|и)\b|\bwhile\b|(?=\bexcept\b)/,
1527
+ // A font stack ("Georgia, serif") is one value, not two asks.
1528
+ /;|\.(?=\s|$)|,(?![^(]*\))(?!\s*(?:serif|sans-serif|monospace|system-ui|cursive|fantasy|ui-[a-z-]+)\b)|\b(?:and|with|but|then|plus|also|y|et|und|и)\b|\bwhile\b|(?=\bexcept\b)/,
1001
1529
  )
1002
1530
  .map(s => s.trim())
1003
1531
  .filter(Boolean);
@@ -1006,6 +1534,11 @@ function clausesOf(q, partWords) {
1006
1534
  const parts = [];
1007
1535
  // A property name is not a part: "backdrop-filter" names no backdrop.
1008
1536
  let rest = ` ${text} `
1537
+ // "3 steps rounder": a count, never the stepper part.
1538
+ .replace(
1539
+ /\b(?:two|three|four|five|\d+)\s+(?:more\s+)?(?:steps?|notches?|levels?)\b/g,
1540
+ ' ',
1541
+ )
1009
1542
  // "when I tab to a link": the key, not the tab part.
1010
1543
  .replace(/\b(i |we |you )?tab(bing)? (to|through|into)\b/g, ' ')
1011
1544
  .replace(/\bvar\([^)]*\)|--[a-z][\w-]*/g, ' ')
@@ -1017,7 +1550,7 @@ function clausesOf(q, partWords) {
1017
1550
  const m = re.exec(rest);
1018
1551
  if (!m) continue;
1019
1552
  const p = {...part};
1020
- if (p.on === 'heading' && /^h[1-4]$/.test(m[0])) p.level = m[1];
1553
+ if (p.on === 'heading' && /^h[1-6]$/.test(m[0])) p.level = m[1];
1021
1554
  // "the error banner": one status of the banner.
1022
1555
  const status =
1023
1556
  /\b(error|danger|warning|success|info)\s+(banners?|alerts?|notices?)\b/.exec(
@@ -1034,7 +1567,7 @@ function clausesOf(q, partWords) {
1034
1567
  /\b(round\w*|corners?|radius|shadows?|borders?|padding|bold\w*|bigger|smaller|taller|wider)\b/;
1035
1568
  if (!parts.length && shapeAsk.test(text))
1036
1569
  for (const w of NOT_PART_WORDS)
1037
- if (new RegExp(`\\b${w}s?\\b`).test(text)) {
1570
+ if (new RegExp(`\\b${w}s?\\b`).test(rest)) {
1038
1571
  parts.push({on: w});
1039
1572
  break;
1040
1573
  }
@@ -1044,11 +1577,38 @@ function clausesOf(q, partWords) {
1044
1577
  if (parts[i].on === 'badge' && !/\b(badges?|chips?|tags?)\b/.test(text))
1045
1578
  parts.splice(i, 1);
1046
1579
  // "Space Grotesk headings": a font's name is a font, never its words.
1047
- const aspects = aspectsOf(
1580
+ const aspects0 = aspectsOf(
1048
1581
  text
1049
1582
  .replace(new RegExp(`\\b(${FONT_NAMES})\\b`, 'g'), ' font ')
1050
1583
  .replace(/\bspace (mono|grotesk|grotesque)\b/g, ' font '),
1051
1584
  );
1585
+ // "padding 3 times bigger", "half the border width": the comparative
1586
+ // goes with the amount of the thing named, never a size change too.
1587
+ // "more transparent", "less opaque": the part's opacity, never its
1588
+ // background made transparent too.
1589
+ const seeThrough =
1590
+ /\b(more|less) (transparent|translucent|see-through|opaque)\b/.test(
1591
+ text,
1592
+ ) && parts.length > 0;
1593
+ const aspects = seeThrough
1594
+ ? ['opacity']
1595
+ : exactFactor(text) != null && aspects0.length > 1
1596
+ ? (() => {
1597
+ // An amount goes with the measured thing it names (padding,
1598
+ // corners, a font size…), never a size or motion change too.
1599
+ const SCALAR = [
1600
+ 'spacing',
1601
+ 'corners',
1602
+ 'fontsize',
1603
+ 'leading',
1604
+ 'tracking',
1605
+ 'opacity',
1606
+ 'border',
1607
+ ];
1608
+ const named = aspects0.filter(a => SCALAR.includes(a));
1609
+ return named.length ? named : aspects0.filter(a => a !== 'size');
1610
+ })()
1611
+ : aspects0;
1052
1612
  // "orange not red" negates a color, not the change.
1053
1613
  const hue = Object.keys(HUES).join('|');
1054
1614
  const negText = text.replace(
@@ -1080,21 +1640,26 @@ function clausesOf(q, partWords) {
1080
1640
  /\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/;
1081
1641
  const tooMore =
1082
1642
  /\btoo (small|cramped|tight|crowded|faded|light|thin|sharp|square|boxy|pointy|subtle|weak|narrow|dim|low|short)\b/;
1083
- const dir = /\bnot (\w+ ){0,2}enough\b/.test(text)
1084
- ? 'more'
1085
- : /\bnot (so|as|that|too) (much|many)\b/.test(text) || tooLess.test(text)
1086
- ? 'less'
1087
- : tooMore.test(text)
1088
- ? 'more'
1089
- : /\b(less|fewer|smaller|lower|reduce|decrease|shrink|minimi[sz]e|scale down|trim|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(
1090
- text,
1091
- )
1092
- ? 'less'
1093
- : /\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(
1643
+ // "half again", "a third again": more by that share, never less.
1644
+ const dir =
1645
+ /\bnot (\w+ ){0,2}enough\b|\b(half|a third|a quarter|1\/2|1\/3|1\/4) again\b/.test(
1646
+ text,
1647
+ )
1648
+ ? 'more'
1649
+ : /\bnot (so|as|that|too) (much|many)\b/.test(text) ||
1650
+ tooLess.test(text)
1651
+ ? 'less'
1652
+ : tooMore.test(text)
1653
+ ? 'more'
1654
+ : /\b(less|fewer|smaller|lower|reduce|decrease|shrink|minimi[sz]e|scale down|trim|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(
1094
1655
  text,
1095
1656
  )
1096
- ? 'more'
1097
- : null;
1657
+ ? 'less'
1658
+ : /\b(more|bigger|larger|higher|increase|stronger|thicker|wider|taller|rounder|roomier|airy|spacious|bolder|heavier|darker|darken|warmer|cooler|loosen|open up|twice|double|a bit|a little|slightly|much)\b/.test(
1659
+ text,
1660
+ )
1661
+ ? 'more'
1662
+ : null;
1098
1663
  /** @type {Record<string, string>} */
1099
1664
  const decl = {};
1100
1665
  for (const m of text.matchAll(
@@ -1107,8 +1672,20 @@ function clausesOf(q, partWords) {
1107
1672
  )
1108
1673
  decl[m[1]] = m[2].trim();
1109
1674
  let state = null;
1675
+ // A part whose name has a state word ("hover card") is the part, not
1676
+ // the state: read the state from the words left once parts are taken.
1677
+ const stateText = parts
1678
+ .filter(x => /hover|focus|active|disabled|selected|checked/.test(x.on))
1679
+ .reduce(
1680
+ (t, x) =>
1681
+ t.replace(
1682
+ new RegExp(`\\b${x.on.replace(/-/g, '[\\s-]?')}s?\\b`, 'g'),
1683
+ ' ',
1684
+ ),
1685
+ text,
1686
+ );
1110
1687
  for (const [re, s] of STATE_WORDS)
1111
- if (re.test(text)) {
1688
+ if (re.test(stateText)) {
1112
1689
  state = s;
1113
1690
  break;
1114
1691
  }
@@ -1123,8 +1700,10 @@ function clausesOf(q, partWords) {
1123
1700
  )
1124
1701
  ? 'light'
1125
1702
  : null;
1703
+ // "except ghost", "except in the nav": an except clause without a part
1704
+ // is one too (a variant, or a place the answer says it cannot keep).
1126
1705
  const except =
1127
- parts.length > 0 &&
1706
+ (parts.length > 0 || /^except\b/.test(text)) &&
1128
1707
  (/^except\b/.test(text) ||
1129
1708
  (neg &&
1130
1709
  aspects.length === 0 &&
@@ -1141,7 +1720,8 @@ function clausesOf(q, partWords) {
1141
1720
  // A typed clamp() or calc() is a length, kept whole.
1142
1721
  lengths: [
1143
1722
  ...(text.match(/\b(?:clamp|calc|min|max)\([^)]*\)/g) ?? []),
1144
- ...lengthsIn(text),
1723
+ // "3 times bigger": the 3 is an amount, never a length.
1724
+ ...lengthsIn(withoutAmount(text)),
1145
1725
  ],
1146
1726
  state,
1147
1727
  mode,
@@ -1570,11 +2150,12 @@ export function draftAnswer(ctx, env, question) {
1570
2150
  // The clause the word is in: from the last break before it (a comma,
1571
2151
  // semicolon, full stop or new line) to the next one after it.
1572
2152
  const head = String(all).slice(0, at);
1573
- const from =
1574
- Math.max(...[',', ';', '.', '\n'].map(b => head.lastIndexOf(b))) + 1;
2153
+ // A full stop breaks only before a space or the end (never 1.5rem).
2154
+ const breaks = [...head.matchAll(/[,;\n]|\.(?=\s|$)/g)];
2155
+ const from = breaks.length ? (breaks.at(-1)?.index ?? -1) + 1 : 0;
1575
2156
  const clause = String(all)
1576
2157
  .slice(from)
1577
- .split(/[,;.\n]/)[0];
2158
+ .split(/[,;\n]|\.(?=\s|$)/)[0];
1578
2159
  const text =
1579
2160
  /\b(bold(er)?|bigger|smaller|larger|font|weight|size|serif|sans|italic|heavier|lighter|thinner|uppercase|letter[- ]?spacing|tracking|line[- ]?height)\b/i.test(
1580
2161
  clause,
@@ -1587,7 +2168,7 @@ export function draftAnswer(ctx, env, question) {
1587
2168
  // A place ("not in the header") is the header part too.
1588
2169
  const before = String(all).slice(Math.max(0, at - 16), at);
1589
2170
  const owned =
1590
- /\b(table|column|accordion|card|dialog|modal|page|section|app|site|product|top ?nav)\s+$/i.test(
2171
+ /\b(table|column|accordion|card|dialog|modal|page|section|app|site|product|top ?nav|block|drawer|popover|panel|header)\s+$/i.test(
1591
2172
  before,
1592
2173
  ) || /\b(in|on|inside|into|across|of)\s+(the\s+|my\s+)?$/i.test(before);
1593
2174
  return text && !surface && !owned
@@ -1644,6 +2225,211 @@ export function draftAnswer(ctx, env, question) {
1644
2225
  'make the $1 sharper',
1645
2226
  )
1646
2227
  .replace(/\bzero out (?:the )?([a-z ]+?)(?=$|[,;.])/gi, '$1 0')
2228
+ // Zero, none or no in any position is that property at 0 (or none):
2229
+ // "zero border on cards", "card corners zero", "opacity zero", "remove
2230
+ // the top padding", "padding left zero"; a shadow at 0 is no shadow.
2231
+ .replace(
2232
+ /\b(?:no|remove|get rid of|zero|drop)\s+(?:the\s+|all\s+)?(top|bottom|left|right|horizontal|vertical|side)\s+(padding|margin|spacing)\b/gi,
2233
+ '$1 $2 0',
2234
+ )
2235
+ .replace(
2236
+ /\b(?:no|remove|get rid of|drop)\s+(?:the\s+|all\s+)?(padding|margin)\s+(?:on\s+|at\s+)?(?:the\s+)?(top|bottom|left|right)\b/gi,
2237
+ '$2 $1 0',
2238
+ )
2239
+ .replace(
2240
+ /\bzero\s+(?:the\s+)?((?:border(?:[- ]?(?:width|radius))?|shadows?|drop shadows?|opacity|radius|corners?|corner radius|letter[- ]?spacing|tracking|padding|gaps?|margins?|spacing)\b)/gi,
2241
+ '$1 0',
2242
+ )
2243
+ .replace(/\b(?:to\s+)?zero\b(?![- ](?:state|width|height))/gi, m =>
2244
+ /^to/i.test(m) ? 'to 0' : '0',
2245
+ )
2246
+ .replace(
2247
+ /\b((?:drop )?shadows?)\s+(?:to\s+)?0(?![.\d]|px|rem|\s+\d)/gi,
2248
+ 'no $1',
2249
+ )
2250
+ .replace(
2251
+ /\b(padding|margin)[- ](top|bottom|left|right)\s+(?:to\s+)?0(?![.\d])/gi,
2252
+ '$1-$2 0',
2253
+ )
2254
+ // One amount reader: every way of saying a share becomes the forms
2255
+ // exactFactor reads ("N% bigger", "N% of"). "up 20%" is 20% more, never
2256
+ // 20%; "2/3" and "two thirds" are that share of now; "twice as small"
2257
+ // is half.
2258
+ .replace(
2259
+ /\b(?:went |go(?:es)? |goes |going )?up (?:by )?(\d{1,3}(?:\.\d+)?)\s?(?:%|percent\b)/gi,
2260
+ '$1% bigger',
2261
+ )
2262
+ .replace(
2263
+ /\b(?:went |go(?:es)? |goes |going )?down (?:by )?(\d{1,3}(?:\.\d+)?)\s?(?:%|percent\b)/gi,
2264
+ '$1% smaller',
2265
+ )
2266
+ .replace(
2267
+ /\b(increas(?:e|es|ed|ing)|rais(?:e|es|ed|ing)|grow(?:s|n|ing)?|bump(?:ed)?(?: up)?|enlarg(?:e|ed)|boost(?:ed)?|decreas(?:e|es|ed|ing)|reduc(?:e|es|ed|ing)|lower(?:ed)?|shrink(?:s|ing)?|shrunk|cut|trim(?:med)?)\b((?:\s+(?!by\b)[a-z-]+){0,5}?)\s+(?:by\s+)?(\d{1,3}(?:\.\d+)?)\s?(?:%|percent\b)(?!\s*(?:of|as|bigger|smaller|larger|more|less)\b)/gi,
2268
+ (_m, verb, what, n) =>
2269
+ `make${what} ${n}% ${/^(decreas|reduc|lower|shrink|shrunk|cut|trim)/i.test(verb) ? 'smaller' : 'bigger'}`,
2270
+ )
2271
+ // "2 spacing units more": a count of steps, not a value.
2272
+ .replace(
2273
+ /\b(\d{1,2}|two|three|four|five) spacing units? (more|less|bigger|smaller)\b/gi,
2274
+ '$1 steps $2',
2275
+ )
2276
+ // "2 spacing units": that many of the spacing unit token, so it follows
2277
+ // the spacing dial.
2278
+ .replace(
2279
+ /\b(\d{1,2}(?:\.\d+)?|two|three|four|five|six|eight) spacing units?\b/gi,
2280
+ (_m, n) =>
2281
+ `calc(${{two: 2, three: 3, four: 4, five: 5, six: 6, eight: 8}[String(n).toLowerCase()] ?? n} * var(--spacing-1))`,
2282
+ )
2283
+ // "a semi-transparent button background", "the badge background 30%
2284
+ // transparent": the fill's own color with that alpha (never the whole
2285
+ // part's opacity, never an overlay).
2286
+ .replace(
2287
+ /\b(?:semi[- ]?transparent|translucent|see[- ]through|half[- ]transparent)\s+((?:[a-z]+\s+){0,2})(background|fill)\b/gi,
2288
+ '$1background alpha 0.5',
2289
+ )
2290
+ .replace(
2291
+ /\b(background|fill)\s+(?:semi[- ]?transparent|translucent|see[- ]through|half[- ]transparent)\b/gi,
2292
+ 'background alpha 0.5',
2293
+ )
2294
+ .replace(
2295
+ /\b(background|fill)\s+(\d{1,2})\s?%\s+transparent\b/gi,
2296
+ (_m, _b, n) =>
2297
+ `background alpha ${Number((1 - Number(n) / 100).toFixed(2))}`,
2298
+ )
2299
+ // See-through amounts are opacity amounts, never no fill: "semi
2300
+ // transparent" and "half transparent" are opacity 0.5, "10% transparent"
2301
+ // is opacity 0.9, "50% opacity" and "80% opaque" are that opacity.
2302
+ .replace(
2303
+ /\b(?:semi|half)[- ]?(?:transparent|see[- ]?through|translucent)\b/gi,
2304
+ 'opacity 0.5',
2305
+ )
2306
+ .replace(
2307
+ /\b(\d{1,3}(?:\.\d+)?)\s?(?:%|percent\b)\s*(?:transparent|see[- ]?through|translucent|transparency)\b/gi,
2308
+ (m, n) =>
2309
+ Number(n) <= 100
2310
+ ? `opacity ${Number((1 - Number(n) / 100).toFixed(3))}`
2311
+ : m,
2312
+ )
2313
+ .replace(
2314
+ /\b(backgrounds?|bg|fills?)\s+(?:at\s+)?(\d{1,3}(?:\.\d+)?)\s?(?:%|percent\b)\s*(?:opacity|opaque)\b/gi,
2315
+ (m, layer, n) =>
2316
+ Number(n) <= 100
2317
+ ? `${layer} opacity ${Number((Number(n) / 100).toFixed(3))}`
2318
+ : m,
2319
+ )
2320
+ // "5% gray", "20% blue": that color at that alpha, a fill kept.
2321
+ .replace(
2322
+ /\b(\d{1,3}(?:\.\d+)?)\s?%\s+((?:light |dark )?(?:gr[ae]y|black|white|blue|red|green|yellow|orange|purple|pink|teal|cyan|indigo|violet|brown|navy)|#[0-9a-f]{3,8})\b(?!\s*(?:lighter|darker|more|less|bigger|smaller))/gi,
2323
+ (m, n, color) =>
2324
+ Number(n) <= 100
2325
+ ? `color-mix(in srgb, ${color.replace(/\s+/g, '').replace('grey', 'gray')} ${n}%, transparent)`
2326
+ : m,
2327
+ )
2328
+ .replace(/\bhalf as much again\b/gi, 'half again')
2329
+ // "card padding +4px", "radius -2px": a change by that length.
2330
+ .replace(
2331
+ /(?<!letter[- ]|line[- ])\b(padding|gaps?|radius|corners|font[- ]size|text[- ]size|spacing)\s+([+-])\s?(\d*\.?\d+)(px|rem|em)\b/gi,
2332
+ (_m, what, sign, n, unit) =>
2333
+ `${what} by ${n}${unit} ${sign === '-' ? 'less' : 'more'}`,
2334
+ )
2335
+ // "h1 twice as big as body text", "h3 the same size as h2", "h2 half
2336
+ // the size of h1": the other's size token times the amount, so it
2337
+ // follows that size.
2338
+ .replace(
2339
+ /\b(h[1-6])\s+(?:text\s+)?(?:(?:(twice|double|half|triple|three times|\d*\.?\d+\s?(?:x|times))\s+as\s+(?:big|large)\s+as)|(?:the\s+)?(same)\s+size\s+as|(?:(twice|double|half|triple)\s+the\s+size\s+of))\s+(?:the\s+)?(h[1-6]|body(?:\s+text)?|base\s+text)\b/gi,
2340
+ (m, level, amount, same, amount2, other) => {
2341
+ const f = same ? 1 : exactFactor(String(amount ?? amount2));
2342
+ if (f == null || f <= 0) return m;
2343
+ const tok = /^h/i.test(other)
2344
+ ? `--text-heading-${other.slice(1)}-size`
2345
+ : '--text-body-size';
2346
+ return f === 1
2347
+ ? `${level} font size var(${tok})`
2348
+ : `${level} font size calc(${Number(f.toFixed(3))} * var(${tok}))`;
2349
+ },
2350
+ )
2351
+ // "the nav links bolder and the active one blue": "the active one" is
2352
+ // the same parts in that state.
2353
+ .replace(
2354
+ /\b((?:[a-z]+ )?[a-z]+s)\b([^,;.\n]*?)\band the (active|selected|current|disabled|hovered|focused|checked|open) ones?\b/gi,
2355
+ '$1$2and the $3 $1',
2356
+ )
2357
+ // "the overlay behind dialogs": the overlay; the dialog is where it is.
2358
+ .replace(
2359
+ /\b(overlay|backdrop|scrim)\s+(?:behind|under|beneath|below|for|of|around)\s+(?:the\s+|a\s+)?(?:dialogs?|modals?|drawers?|sheets?)\b/gi,
2360
+ '$1',
2361
+ )
2362
+ // "the shadow sharper": less blur on the shadow, never sharper corners.
2363
+ .replace(
2364
+ /\b((?:drop |box )?shadows?)\s+((?:a (?:bit|little|touch) |slightly |much )?)sharper\b/gi,
2365
+ '$1 $2less blur',
2366
+ )
2367
+ .replace(/\bsharper\s+((?:drop |box )?shadows?)\b/gi, '$1 less blur')
2368
+ // "body text thinner": a thinner stroke, so a lighter weight; never the
2369
+ // border width.
2370
+ .replace(
2371
+ /\b(text|font|type(?:face)?|copy|letters|lettering|writing|headings?|labels?)\s+((?:a (?:bit|little|touch) |slightly |much )?)thinner\b/gi,
2372
+ '$1 weight $2lighter',
2373
+ )
2374
+ // "h1 800": a bare 100-900 after a heading level is its weight.
2375
+ .replace(
2376
+ /\b(h[1-6])\s+([1-9]00)(?:\s+weight)?\b(?!\s*(?:px|rem|em|%|ms)\b)/gi,
2377
+ '$1 weight $2',
2378
+ )
2379
+ // "h1 800 and the other headings 600": "the other headings" are the
2380
+ // levels not named, each with that ask.
2381
+ .replace(
2382
+ /(?:,\s*|\s+)(?:and\s+)?(?:all\s+)?(?:the\s+)?(?:other|rest of the|remaining)\s+(?:heading levels|headings)\b([^,;.\n]*)/gi,
2383
+ (m, rest, at, all) => {
2384
+ const named = new Set(
2385
+ [...String(all).matchAll(/\bh([1-6])\b/gi)].map(x => Number(x[1])),
2386
+ );
2387
+ if (!named.size || !String(rest).trim()) return m;
2388
+ const ask = String(rest)
2389
+ .trim()
2390
+ .replace(/^(?:weight\s+)?([1-9]00)(?:\s+weight)?$/i, 'weight $1');
2391
+ const levels = [1, 2, 3, 4, 5, 6].filter(n => !named.has(n));
2392
+ return levels.length
2393
+ ? `, ${levels.map(n => `h${n} ${ask}`).join(', ')}`
2394
+ : m;
2395
+ },
2396
+ )
2397
+ // "h2 through h4 bold": the ask for each level in the range.
2398
+ .replace(
2399
+ /\b(?:headings?\s+)?h([1-6])\s*(?:through|thru|to|until|-|\u2013)\s*h([1-6])\b([^,;.\n]*)/gi,
2400
+ (m, a, b, rest) => {
2401
+ const [lo, hi] = [Number(a), Number(b)].sort((x, y) => x - y);
2402
+ if (lo === hi || !rest.trim()) return m;
2403
+ return Array.from(
2404
+ {length: hi - lo + 1},
2405
+ (_, i) => `h${lo + i}${rest}`,
2406
+ ).join(', ');
2407
+ },
2408
+ )
2409
+ // No letter spacing is letter spacing 0.
2410
+ .replace(
2411
+ /\b(?:no|remove|without|get rid of|drop)\s+(?:the\s+|all\s+|any\s+)?(?:extra\s+)?(letter[- ]?spacing|tracking)\b/gi,
2412
+ '$1 0',
2413
+ )
2414
+ .replace(
2415
+ /\b(?:twice|two times) as (small|thin|narrow|short|tight)\b/gi,
2416
+ '50% of now',
2417
+ )
2418
+ .replace(
2419
+ /\b(two|three|four|five|2|3|4|5) (thirds|quarters|fourths|fifths)\b(?:\s+of)?/gi,
2420
+ (_m, n, d) => {
2421
+ const num = WORD_NUMBERS[String(n).toLowerCase()] ?? Number(n);
2422
+ /** @type {Record<string, number>} */
2423
+ const DENS = {thirds: 3, quarters: 4, fourths: 4, fifths: 5};
2424
+ const den = DENS[String(d).toLowerCase()] ?? 1;
2425
+ return num < den ? `${Number(((num / den) * 100).toFixed(3))}% of` : _m;
2426
+ },
2427
+ )
2428
+ .replace(/(?<![\d./#-])([1-9])\/([2-9])(?![\d./])(?:\s+of)?/g, (m, n, d) =>
2429
+ Number(n) < Number(d)
2430
+ ? `${Number(((Number(n) / Number(d)) * 100).toFixed(3))}% of`
2431
+ : m,
2432
+ )
1647
2433
  .replace(/\bflatten (?:the )?([a-z]+)/gi, 'make the $1 flat')
1648
2434
  .replace(/\b([a-z][a-z -]*?)\s*\+\+/gi, 'more $1')
1649
2435
  .replace(/\b([a-z][a-z -]*?)\s*--(?![a-z])/gi, 'less $1')
@@ -1844,7 +2630,7 @@ export function draftAnswer(ctx, env, question) {
1844
2630
  // "don't touch the buttons", "leave the corners": an exclusion. It writes
1845
2631
  // nothing, and it gives nothing to the clause after it.
1846
2632
  const EXCLUDE =
1847
- /^\s*(?:don'?t (?:touch|change)|do not (?:touch|change)|leave(?! (?:the )?(?:dark|light) mode\b)|keep (?:the )?[\w -]+ (?:alone|as is|as it is|unchanged|untouched|the same))\b/i;
2633
+ /^\s*(?:(?:please )?(?:don'?t|do not|never) (?:touch|change|make)|[\w -]+ (?:should|must|shall)(?:n'?t| not) (?:be|get|look|become)\b(?! (?:so|too|this|that) \w)|leave(?! (?:the )?(?:dark|light) mode\b)|keep (?:the )?[\w -]+ (?:alone|as is|as it is|unchanged|untouched|the same))\b/i;
1848
2634
  const blocked = (/** @type {string} */ x) =>
1849
2635
  EXCLUDE.test(x) ||
1850
2636
  (!/^\s*(?:please )?(?:can|could) (?:the|my|our|all) [\w -]+ be\b|^\s*(?:can|could) i (?:get|have)\b/i.test(
@@ -1920,9 +2706,17 @@ export function draftAnswer(ctx, env, question) {
1920
2706
  'more saturated',
1921
2707
  )
1922
2708
  .replace(
1923
- /(?<![-\w])(?:more )?(?:muted|pastel|duller|subdued|desaturated)(?![-\w])/gi,
2709
+ // "muted ones", "the muted card": the muted variant, not a color ask.
2710
+ /(?<![-\w])(?:more )?(?:muted|pastel|duller|subdued|desaturated)(?![-\w])(?! (?:ones?|cards?|buttons?|badges?|variant)\b)/gi,
1924
2711
  'less saturated',
1925
2712
  )
2713
+ // "less sharp", "less thick", "less round": the opposite word.
2714
+ .replace(/\bless (?:sharp|square|angular|boxy)\b/gi, 'rounder')
2715
+ .replace(/\bless (?:round(?:ed)?|curved|soft)\b/gi, 'sharper')
2716
+ .replace(/\bless thick\b/gi, 'thinner')
2717
+ .replace(/\bless (?:big|large)\b/gi, 'smaller')
2718
+ .replace(/\bless (?:small|tiny)\b/gi, 'bigger')
2719
+ .replace(/\bless dark\b/gi, 'lighter')
1926
2720
  // "less light", "less heavy", "less tight", "less thin": one step back on
1927
2721
  // the same aspect.
1928
2722
  .replace(
@@ -2026,6 +2820,12 @@ export function draftAnswer(ctx, env, question) {
2026
2820
  // "dropdown shadow": the dropdown's menu, the part that floats.
2027
2821
  .replace(/\bdropdowns? (?=shadows?|elevation)/gi, 'dropdown-menu ')
2028
2822
  // "½rem": a fraction is a number.
2823
+ // A lone "½" with no unit after it is a share of now ("card padding
2824
+ // ½"), never 0.5px.
2825
+ .replace(
2826
+ /(\d*)(?:½|1\u20442)(?!\s*(?:rem|px|em|%|x\b|×|times\b))/g,
2827
+ (_, n) => (n ? `${n}½` : ' half '),
2828
+ )
2029
2829
  .replace(/(\d*)(?:½|1\u20442)/g, (_, n) => `${n ? Number(n) + 0.5 : '0.5'}`)
2030
2830
  .replace(
2031
2831
  /(\d*)(?:¼|1\u20444)/g,
@@ -2174,7 +2974,8 @@ export function draftAnswer(ctx, env, question) {
2174
2974
  .replace(/\bwhy (?:is|are|isn'?t|aren'?t)\b(.*?)\bnot\s+/gi, 'make$1 ')
2175
2975
  // "button padding 8", "radius 10": a bare number there is pixels.
2176
2976
  .replace(
2177
- /\b(padding|radius|corners|gap|margin)(\s*:?\s*)(\d+(?:\.\d+)?)(?![\d.%\w])/gi,
2977
+ // (Never a count: "padding 2 steps more", "corners 3 notches".)
2978
+ /\b(padding|radius|corners|gap|margin)(\s*:?\s*)(\d+(?:\.\d+)?)(?![\d.%\w])(?!\s*(?:more\s+)?(?:steps?|sizes?|notches?|levels?|units?|spacing units?|x\b|×))/gi,
2178
2979
  '$1$2$3px',
2179
2980
  )
2180
2981
  .toLowerCase()
@@ -2277,6 +3078,86 @@ export function draftAnswer(ctx, env, question) {
2277
3078
  // "flat cards, not flat buttons": the second part stays as it is.
2278
3079
  .replace(/^(.*\b(\w{3,})\b.*?),\s*(?:but )?not \2 [a-z ]+$/, '$1')
2279
3080
  .replace(/\b(everything|everywhere|all) but\b/g, '$1 except')
3081
+ // Other words for except: "besides cards", "save for cards", "but keep
3082
+ // cards as they are", "cards excepted", "without changing buttons".
3083
+ .replace(
3084
+ /\b(?:besides|save for|apart from|other than|excluding|with the exception of|without (?:changing|touching|affecting))\s+/gi,
3085
+ 'except ',
3086
+ )
3087
+ .replace(
3088
+ /[,;]?\s*but (?:keep|leave) (?:the |my )?([a-z][a-z -]*?) (?:as (?:they are|it is|is)|alone|the same|unchanged|untouched)\b/gi,
3089
+ ' except $1',
3090
+ )
3091
+ .replace(/[,;]?\s*(?:the |my )?([a-z][a-z -]*?) excepted\b/gi, ' except $1')
3092
+ // "as well as" is "and"; "compared to", "relative to", "versus" compare.
3093
+ .replace(/\bas well as\b/gi, 'and')
3094
+ // "h2 to h4", "h2-h4": heading levels 2 to 4.
3095
+ .replace(/\bh([1-6])\s*(?:-|–|to|through)\s*h([1-6])\b/gi, 'headings $1-$2')
3096
+ .replace(
3097
+ /\b(?:compared (?:to|with)|relative to|versus|vs\.?)\s+/gi,
3098
+ 'than ',
3099
+ )
3100
+ // "don't let the text get smaller", "keep the text from getting
3101
+ // smaller", "I don't want bigger cards": prohibitions.
3102
+ .replace(
3103
+ /\b(?:don'?t|do not|never) let (?:the |my )?([a-z][a-z -]*?) (?:get|become|look|be) (\w+er)\b/gi,
3104
+ "don't make $1 $2",
3105
+ )
3106
+ .replace(
3107
+ /\bkeep (?:the |my )?([a-z][a-z -]*?) from (?:getting|becoming|looking) (\w+er)\b/gi,
3108
+ "don't make $1 $2",
3109
+ )
3110
+ .replace(
3111
+ /\bi (?:don'?t|do not) want (?:the |my )?(\w+er) ([a-z][a-z -]*)/gi,
3112
+ "don't make $2 $1",
3113
+ )
3114
+ // "make everything rounder; never round the inputs", "… and don't
3115
+ // change the cards": after an ask, the part keeps what it has.
3116
+ .replace(
3117
+ /\s*(?:[;.,]|\band\b|\bbut\b)\s*(?:but\s+)?(?:never|don'?t|do not) (?:round|change|touch|make) (?:the |my )?([a-z][a-z -]*?)(?: rounder| bigger| smaller| bolder| darker| lighter)?\s*$/gi,
3118
+ ' except $1',
3119
+ )
3120
+ // "never round the inputs": a prohibition of rounding them.
3121
+ .replace(
3122
+ /\bnever round (?:the |my )?([a-z][a-z -]*)/gi,
3123
+ 'never make $1 rounder',
3124
+ )
3125
+ // "buttons shouldn't be so small": an ask the other way.
3126
+ .replace(
3127
+ /\b([a-z][a-z -]*?) (?:shouldn'?t|should not) be (?:so|this|that|too) (small|big|large|round|rounded|dark|light|thin|thick|tight|cramped)\b/gi,
3128
+ (_m, part, adj) =>
3129
+ `make ${part} ${/** @type {Record<string, string>} */ ({small: 'bigger', big: 'smaller', large: 'smaller', round: 'sharper', rounded: 'sharper', dark: 'lighter', light: 'darker', thin: 'thicker', thick: 'thinner', tight: 'roomier', cramped: 'roomier'})[adj.toLowerCase()]}`,
3130
+ )
3131
+ // "remove the padding and border from cards": two removals.
3132
+ .replace(
3133
+ /\b(remove|drop|get rid of) (?:the )?(\w+) and (?:the )?(\w+) (?:from|on) (?:the |my )?([a-z][a-z -]*)/gi,
3134
+ 'no $2 on $4 and no $3 on $4',
3135
+ )
3136
+ // "black on secondary buttons": a color on a variant is its text.
3137
+ .replace(
3138
+ /\b(black|white|#[0-9a-f]{3,8}|red|blue|green|gray|grey) on (?:the )?(primary|secondary|ghost|destructive) buttons?\b/gi,
3139
+ '$1 text on $2 buttons',
3140
+ )
3141
+ // "inputs with errors", "inputs that have an error": the error status.
3142
+ .replace(
3143
+ /\b([a-z]+s?) (?:with|that have|that has|showing) (?:an )?(?:errors?|error states?)\b/g,
3144
+ '$1 in error state',
3145
+ )
3146
+ // "white text on primary": a variant of the buttons.
3147
+ .replace(
3148
+ /\b(on|for) (?:the )?(primary|secondary|ghost|destructive)\b(?! (?:ones?|buttons?|badges?|chips?|links?|tags?)\b)/g,
3149
+ '$1 $2 buttons',
3150
+ )
3151
+ // "dialog header and footer": both are the dialog's.
3152
+ .replace(
3153
+ /\b([a-z]+) (header|footer|title)s? and (header|footer|title)s?\b/g,
3154
+ '$1 $2 and $1 $3',
3155
+ )
3156
+ // "all buttons except primary ones rounder": the ask before the except.
3157
+ .replace(
3158
+ /^(.*?)\s+except\s+((?:the\s+)?(?:primary|secondary|ghost|destructive|danger)(?:\s+ones?|\s+buttons?)?)\s+(?!and\b|or\b|buttons?\b|ones?\b)(\S.*)$/i,
3159
+ '$1 $3 except $2',
3160
+ )
2280
3161
  .replace(
2281
3162
  /\b(apart from|other than|excluding|but not (on|in|for)|but not)\b/g,
2282
3163
  'except',
@@ -2286,12 +3167,18 @@ export function draftAnswer(ctx, env, question) {
2286
3167
  // "cramped on mobile": the editor has no media conditions; the rest of
2287
3168
  // the ask is answered, with a note.
2288
3169
  const MEDIA_RE = new RegExp(
2289
- String.raw`(?<!\bno |\bnot )\b(?:below|above|under|over|wider than|narrower than)\s+(?:\d{3,}px|\d+em)\b|\b(?:screens?|viewports?|windows?) (?:below|above|under|over|less than|more than|wider than|narrower than)\s+\d+(?:px|em|rem)\b|\b(?:on|for) (?:mobile|phones?|tablets?|desktops?|touch(?: screens?)?|small screens?|large screens?|wide screens?|landscape|portrait)\b|\b(?:when )?print(?:ing)?\b|\b(?:the )?print version\b`,
3170
+ String.raw`(?<!\bno |\bnot )\b(?:below|above|under|over|wider than|narrower than)\s+(?:\d{3,}px|\d+em)\b|\b(?:screens?|viewports?|windows?) (?:below|above|under|over|less than|more than|wider than|narrower than)\s+\d+(?:px|em|rem)\b|\b(?:on|for) (?:mobile|phones?|tablets?|desktops?|touch(?: screens?)?|small screens?|large screens?|wide screens?|landscape|portrait)\b|(?<!\bfine )\b(?:when )?print(?:ing)?\b|\b(?:the )?print version\b`,
2290
3171
  'g',
2291
3172
  );
2292
3173
  const media = MEDIA_RE.test(q);
2293
3174
  if (media) q = q.replace(MEDIA_RE, ' ').replace(/\s+/g, ' ').trim();
2294
3175
  const clauses = clausesOf(q, lex.parts);
3176
+ /** Parts a prohibition in the question keeps as they are. @type {string[]} */
3177
+ const prohibited = [];
3178
+ /** Parts a symmetric "match" ask already answered for. @type {Set<string>} */
3179
+ const symDone = new Set();
3180
+ /** Places the question names that the editor cannot keep apart. @type {string[]} */
3181
+ const placeNotes = [];
2295
3182
  // "checkboxes green": the color a checked box fills with.
2296
3183
  for (const c of clauses)
2297
3184
  if (
@@ -2412,35 +3299,214 @@ export function draftAnswer(ctx, env, question) {
2412
3299
  }
2413
3300
  // "cards and dialogs with no shadow", "tooltips and toasts black": parts
2414
3301
  // listed before the ask all take it.
2415
- for (let i = 0; i < clauses.length - 1; i++) {
2416
- const c = clauses[i];
2417
- const onlyParts = (/** @type {Clause} */ x) =>
2418
- x.parts.length &&
2419
- !x.aspects.length &&
2420
- !x.colors.length &&
2421
- !x.lengths.length &&
2422
- !x.except &&
2423
- !x.dir &&
2424
- !lex.parts
2425
- .reduce((t, [re]) => t.replace(re, ' '), ` ${x.text} `)
2426
- .replace(/\b(the|a|an|all|every|both|my|our)\b/g, ' ')
2427
- .trim();
2428
- if (!onlyParts(c)) continue;
2429
- let j = i + 1;
2430
- while (j < clauses.length && onlyParts(clauses[j])) j++;
2431
- const ask = clauses[j];
3302
+ // "headings twice as big", "dialog text twice as big": size words on
3303
+ // headings or on a part's text are the text size.
3304
+ for (const c of clauses)
2432
3305
  if (
2433
- !ask ||
2434
- ask.except ||
2435
- !(
2436
- ask.aspects.length ||
2437
- ask.colors.length ||
2438
- ask.lengths.length ||
2439
- ask.dir
2440
- )
3306
+ (!c.aspects.length ||
3307
+ (c.aspects.length === 1 &&
3308
+ c.aspects[0] === 'text' &&
3309
+ !c.colors.length)) &&
3310
+ c.parts.length &&
3311
+ /\b(big|bigger|small|smaller|large|larger)\b/.test(c.text) &&
3312
+ (c.parts.some(x => x.on === 'heading') || /\btext\b/.test(c.text))
2441
3313
  )
2442
- continue;
2443
- const listed = clauses.slice(i, j).flatMap(x => x.parts);
3314
+ c.aspects = ['fontsize'];
3315
+ // "2 steps more on cards" (from "2 spacing units more"): the spacing.
3316
+ for (const c of clauses)
3317
+ if (
3318
+ !c.aspects.length &&
3319
+ c.parts.length &&
3320
+ STEP_COUNT.test(c.text) &&
3321
+ /\b(more|less)\b/.test(c.text)
3322
+ )
3323
+ c.aspects = ['spacing'];
3324
+ // "bold, uppercase and 14px": a bare size in a list of text changes is
3325
+ // the text size.
3326
+ for (let i = 1; i < clauses.length; i++) {
3327
+ const c = clauses[i];
3328
+ if (
3329
+ !c.aspects.length &&
3330
+ c.lengths.length === 1 &&
3331
+ /^\s*(?:and\s+)?\d*\.?\d+(?:px|rem|em|pt)\s*$/.test(c.text) &&
3332
+ clauses
3333
+ .slice(0, i)
3334
+ .some(x =>
3335
+ x.aspects.some(a =>
3336
+ ['weight', 'case', 'fontsize', 'text', 'family', 'font'].includes(
3337
+ a,
3338
+ ),
3339
+ ),
3340
+ )
3341
+ )
3342
+ c.aspects = ['fontsize'];
3343
+ }
3344
+ // An elided clause ("… and darker when pressed", "… and black on
3345
+ // secondary buttons", "all caps and smaller", "and half on ghost ones")
3346
+ // takes what it leaves out from the clause before: its part, and the
3347
+ // kind of change when it names none.
3348
+ for (let i = 1; i < clauses.length; i++) {
3349
+ const c = clauses[i];
3350
+ const prev = clauses[i - 1];
3351
+ if (c.except || prev.except || !prev.parts.length) continue;
3352
+ // Only a clause joined by "and" to the one before, with words of its
3353
+ // own beside a value ("4px" alone is the value of the clause before).
3354
+ if (
3355
+ !new RegExp(
3356
+ `\\band\\s+${c.text.trim().replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}`,
3357
+ ).test(q) ||
3358
+ /^\s*(?:at least\s+|about\s+)?\d*\.?\d+(?:px|rem|em|%)?\s*$/.test(c.text)
3359
+ )
3360
+ continue;
3361
+ const ownParts = c.parts.length > 0;
3362
+ const hasAsk =
3363
+ c.dir ||
3364
+ c.colors.length ||
3365
+ c.lengths.length ||
3366
+ exactFactor(c.text) != null;
3367
+ if (!hasAsk) continue;
3368
+ if (!c.parts.length) {
3369
+ const own = /\b(primary|secondary|ghost|destructive|muted)\b/.exec(
3370
+ c.text,
3371
+ )?.[1];
3372
+ c.parts = prev.parts.map(x => ({
3373
+ ...x,
3374
+ ...(own ? {when: `variant:${own}`} : {}),
3375
+ }));
3376
+ }
3377
+ if (!c.aspects.length && !ownParts) {
3378
+ const textish = prev.aspects.some(a =>
3379
+ ['text', 'case', 'fontsize', 'weight', 'family'].includes(a),
3380
+ );
3381
+ c.aspects = c.colors.length
3382
+ ? prev.aspects.includes('text')
3383
+ ? ['text']
3384
+ : [...prev.aspects]
3385
+ : textish && /\b(smaller|bigger|larger|tiny|huge)\b/.test(c.text)
3386
+ ? ['fontsize']
3387
+ : textish && /\b(lighter|darker)\b/.test(c.text)
3388
+ ? ['text']
3389
+ : [...prev.aspects];
3390
+ } else if (
3391
+ !ownParts &&
3392
+ c.aspects.length === 1 &&
3393
+ c.aspects[0] === 'size' &&
3394
+ !/\b(padding|room|spac)/.test(c.text) &&
3395
+ prev.aspects.some(a =>
3396
+ ['text', 'case', 'fontsize', 'weight', 'family'].includes(a),
3397
+ )
3398
+ )
3399
+ c.aspects = ['fontsize'];
3400
+ else if (
3401
+ !ownParts &&
3402
+ c.colors.length &&
3403
+ c.aspects.length === 1 &&
3404
+ c.aspects[0] === 'background' &&
3405
+ prev.aspects.includes('text') &&
3406
+ !/\b(background|bg|fill)\b/.test(c.text)
3407
+ )
3408
+ c.aspects = ['text'];
3409
+ }
3410
+ // An icon's color is its text color ("the close icon red").
3411
+ for (const c of clauses)
3412
+ if (
3413
+ c.parts.some(x => /-icon$/.test(x.on)) &&
3414
+ (c.aspects.includes('background') ||
3415
+ (!c.aspects.length && c.colors.length)) &&
3416
+ !/\b(background|bg|fill(ed)?)\b/.test(c.text)
3417
+ )
3418
+ c.aspects = c.aspects.length
3419
+ ? c.aspects.map(x => (x === 'background' ? 'text' : x))
3420
+ : ['text'];
3421
+ // "buttons inside cards", "links in the sidebar": the editor themes a
3422
+ // part everywhere; the place is said, never changed.
3423
+ for (const c of clauses) {
3424
+ const place =
3425
+ /\b(?:inside|within|in(?! (?:dark|light)\b))\s+(?:the\s+|a\s+|an\s+|my\s+)?([a-z][a-z -]*)$/.exec(
3426
+ c.text.replace(/\s+(?:on|when) \w+$/, ''),
3427
+ );
3428
+ if (!place || c.parts.length < 2) continue;
3429
+ const at = c.text.indexOf(place[0]);
3430
+ const inPlace = c.parts.filter(x =>
3431
+ lex.parts.some(
3432
+ ([re, y]) => y.on === x.on && (re.exec(c.text)?.index ?? -1) >= at,
3433
+ ),
3434
+ );
3435
+ if (!inPlace.length || inPlace.length === c.parts.length) continue;
3436
+ c.parts = c.parts.filter(x => !inPlace.includes(x));
3437
+ placeNotes.push(
3438
+ `the editor themes ${c.parts.map(x => x.on).join(', ')} everywhere: it cannot keep ${inPlace.map(x => x.on).join(', ')} apart, so this applies to every ${c.parts.map(x => x.on).join(', ')} (${inPlace.map(x => x.on).join(', ')} is not changed)`,
3439
+ );
3440
+ }
3441
+ // "except buttons and cards": the parts listed after an except clause are
3442
+ // excepted too.
3443
+ for (let i = 0; i < clauses.length - 1; i++) {
3444
+ if (!clauses[i].except) continue;
3445
+ while (
3446
+ i + 1 < clauses.length &&
3447
+ clauses[i + 1].parts.length &&
3448
+ !clauses[i + 1].aspects.length &&
3449
+ !clauses[i + 1].colors.length &&
3450
+ !clauses[i + 1].lengths.length &&
3451
+ !clauses[i + 1].dir &&
3452
+ !clauses[i + 1].except
3453
+ ) {
3454
+ clauses[i].parts.push(...clauses[i + 1].parts);
3455
+ clauses.splice(i + 1, 1);
3456
+ }
3457
+ }
3458
+ // The same for a part-only clause the reading put before the except
3459
+ // clause though the question says it after "except".
3460
+ {
3461
+ const exceptAt = q.search(/\bexcept\b/);
3462
+ const ex = clauses.find(x => x.except);
3463
+ if (ex && exceptAt >= 0)
3464
+ for (let i = clauses.length - 1; i >= 0; i--) {
3465
+ const x = clauses[i];
3466
+ if (
3467
+ x !== ex &&
3468
+ !x.except &&
3469
+ x.parts.length &&
3470
+ !x.aspects.length &&
3471
+ !x.colors.length &&
3472
+ !x.lengths.length &&
3473
+ !x.dir &&
3474
+ q.indexOf(x.text) > exceptAt
3475
+ ) {
3476
+ ex.parts.push(...x.parts);
3477
+ clauses.splice(i, 1);
3478
+ }
3479
+ }
3480
+ }
3481
+ for (let i = 0; i < clauses.length - 1; i++) {
3482
+ const c = clauses[i];
3483
+ const onlyParts = (/** @type {Clause} */ x) =>
3484
+ x.parts.length &&
3485
+ !x.aspects.length &&
3486
+ !x.colors.length &&
3487
+ !x.lengths.length &&
3488
+ !x.except &&
3489
+ !x.dir &&
3490
+ !lex.parts
3491
+ .reduce((t, [re]) => t.replace(re, ' '), ` ${x.text} `)
3492
+ .replace(/\b(the|a|an|all|every|both|my|our)\b/g, ' ')
3493
+ .trim();
3494
+ if (!onlyParts(c)) continue;
3495
+ let j = i + 1;
3496
+ while (j < clauses.length && onlyParts(clauses[j])) j++;
3497
+ const ask = clauses[j];
3498
+ if (
3499
+ !ask ||
3500
+ ask.except ||
3501
+ !(
3502
+ ask.aspects.length ||
3503
+ ask.colors.length ||
3504
+ ask.lengths.length ||
3505
+ ask.dir
3506
+ )
3507
+ )
3508
+ continue;
3509
+ const listed = clauses.slice(i, j).flatMap(x => x.parts);
2444
3510
  ask.parts = [...listed.map(p => ({...p})), ...ask.parts];
2445
3511
  for (const x of clauses.slice(i, j)) {
2446
3512
  x.parts = [];
@@ -2997,16 +4063,29 @@ export function draftAnswer(ctx, env, question) {
2997
4063
  if (st.mode) return true;
2998
4064
  if (st.verb !== 'set') return false;
2999
4065
  if (st.thing.startsWith('--')) return C.typeOf(st.thing) === 'color';
4066
+ // A gradient goes per mode too, as a background image (the other
4067
+ // mode keeps its background color).
4068
+ if (/^background(-image)?$/.test(st.thing) && gradientOnly(st.value))
4069
+ return true;
3000
4070
  if (st.thing === 'background')
3001
4071
  return (
3002
4072
  parseColor(st.value ?? '') != null || /^var\(/.test(st.value ?? '')
3003
4073
  );
3004
4074
  return COLOR_PROPS.test(st.thing);
3005
4075
  };
4076
+ /** @param {string | undefined} v */
4077
+ const gradientOnly = v =>
4078
+ /gradient\(/i.test(v ?? '') && !/url\(|light-dark\(/i.test(v ?? '');
3006
4079
  const options = d.options
3007
4080
  .filter(o => o.every(modal))
3008
4081
  .map(o =>
3009
- o.map(st => (st.mode ? st : {...st, mode: c.mode ?? undefined})),
4082
+ o.map(st => {
4083
+ const one =
4084
+ st.thing === 'background' && gradientOnly(st.value)
4085
+ ? {...st, thing: 'background-image'}
4086
+ : st;
4087
+ return one.mode ? one : {...one, mode: c.mode ?? undefined};
4088
+ }),
3010
4089
  );
3011
4090
  if (options.length) return {...d, options};
3012
4091
  return {
@@ -3016,9 +4095,84 @@ export function draftAnswer(ctx, env, question) {
3016
4095
  };
3017
4096
  /** @type {Clause | null} */
3018
4097
  let clauseNow = null;
4098
+ /**
4099
+ * What a clause asks for, as the measured check reads it.
4100
+ * @param {Clause} c0
4101
+ * @param {string[]} keep parts (or `part@when|state|` prefixes) kept as they are
4102
+ * @returns {import('./_how-commands.mjs').MeasureIntent}
4103
+ */
4104
+ const intentOf = (c0, keep) => {
4105
+ const comparing =
4106
+ /\b(than(?!\s+-?\d)|as \w+ as(?!\s+-?\d)|same|match(?:es|ing)?|equal(?:ly)?|like the|compared to|versus|vs)\b/.test(
4107
+ c0.text,
4108
+ );
4109
+ const aspects = [
4110
+ ...c0.aspects,
4111
+ ...(/\bshadows?\b/.test(c0.text) ? ['shadow'] : []),
4112
+ ...(/\b(corners?|radius)\b/.test(c0.text) ? ['corners'] : []),
4113
+ ...(/\bborders?\b/.test(c0.text) ? ['border'] : []),
4114
+ ...(/\b(padding|gap|spacing)\b/.test(c0.text) ? ['spacing'] : []),
4115
+ ];
4116
+ const known = aspects.length && aspects.every(a => ASPECT_FAMILIES[a]);
4117
+ // "lighter" or "darker" with no size word asks for a color only.
4118
+ const colorOnly =
4119
+ /\b(lighter|lighten|darker|darken|brighter|paler|deeper)\b/.test(
4120
+ c0.text,
4121
+ ) &&
4122
+ !/\b(thick|thin|width|wide|bigger|smaller|weight|bold|font|text size|shadow|heav|headings?|up)\w*/.test(
4123
+ c0.text,
4124
+ );
4125
+ return {
4126
+ families: colorOnly
4127
+ ? ['color']
4128
+ : known
4129
+ ? [...new Set(aspects.flatMap(a => ASPECT_FAMILIES[a]))]
4130
+ : [],
4131
+ // A value after "than" is a bound, not the value to write.
4132
+ typed: [...c0.colors, ...c0.lengths].filter(
4133
+ v =>
4134
+ !new RegExp(
4135
+ `\\bthan\\s+${v.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}`,
4136
+ 'i',
4137
+ ).test(c0.text),
4138
+ ),
4139
+ opacityDir:
4140
+ /\bmore (transparent|translucent|see-through)\b|\bless opaque\b/.test(
4141
+ c0.text,
4142
+ )
4143
+ ? 'less'
4144
+ : /\bless (transparent|translucent)\b|\bmore opaque\b/.test(c0.text)
4145
+ ? 'more'
4146
+ : null,
4147
+ dir: comparing ? null : c0.dir,
4148
+ zero:
4149
+ !comparing &&
4150
+ Boolean(c0.neg) &&
4151
+ /\b(no|remove|without|zero|none|get rid of|drop)\b/.test(c0.text) &&
4152
+ !/\b(not too|isn'?t|aren'?t|subtle|thinner|smaller|less)\b/.test(
4153
+ c0.text,
4154
+ ),
4155
+ lighter:
4156
+ comparing || /\bcontrast\b/.test(c0.text)
4157
+ ? null
4158
+ : /\b(lighter|lighten|brighter|paler)\b/.test(c0.text)
4159
+ ? true
4160
+ : /\b(darker|darken|deeper)\b/.test(c0.text)
4161
+ ? false
4162
+ : null,
4163
+ subjects: c0.parts.map(x => x.on),
4164
+ keep: [...keep, ...prohibited],
4165
+ mode: /** @type {'light' | 'dark' | null} */ (c0.mode ?? null),
4166
+ bound: /\bthan\s+-?\d/.test(c0.text),
4167
+ };
4168
+ };
3019
4169
  /** @param {Draft} input */
3020
4170
  const push = input => {
3021
4171
  const d = withMode(input, clauseNow);
4172
+ // The measured check runs on the final commands (_how.mjs): each draft
4173
+ // carries what its clause asks for.
4174
+ if (clauseNow && !clauseNow.except && !d.intent)
4175
+ d.intent = intentOf(clauseNow, []);
3022
4176
  // A step given twice in one option runs once.
3023
4177
  const options = d.options
3024
4178
  .map(o =>
@@ -3028,7 +4182,30 @@ export function draftAnswer(ctx, env, question) {
3028
4182
  ),
3029
4183
  )
3030
4184
  .filter(o => o.length);
4185
+ // "two steps bigger", "3 steps rounder", "two sizes bigger": a dial
4186
+ // step given N times, in order (each step moves from the one before).
4187
+ const stepCount = STEP_COUNT.exec(clauseNow?.text ?? '');
4188
+ const n = stepCount
4189
+ ? (WORD_NUMBERS[stepCount[1]] ?? Number(stepCount[1]))
4190
+ : 1;
4191
+ if (
4192
+ n > 1 &&
4193
+ options.length &&
4194
+ options[0].length === 1 &&
4195
+ options[0][0].verb === 'set' &&
4196
+ (options[0][0].value === 'more' || options[0][0].value === 'less')
4197
+ ) {
4198
+ options[0] = Array.from({length: n}, () => ({...options[0][0]}));
4199
+ d.sequence = true;
4200
+ d.text = d.text.replace(/\bone step\b/, `${n} steps, in order`);
4201
+ if (!/\bsteps, in order\b/.test(d.text))
4202
+ d.text = `${d.text} (${n} steps, in order)`;
4203
+ }
3031
4204
  // The caller reads what was kept.
4205
+ // A sub-part Core does not have: the answer is for the whole part.
4206
+ const missing = clauseNow?.parts.find(x => x.missing);
4207
+ if (missing && !d.text.startsWith('Core has no'))
4208
+ d.text = `Core has no ${missing.missing} part of its own, so this is for the whole ${missing.on}: ${d.text}`;
3032
4209
  input.text = d.text;
3033
4210
  input.options = options;
3034
4211
  drafts.push({
@@ -3036,6 +4213,7 @@ export function draftAnswer(ctx, env, question) {
3036
4213
  options,
3037
4214
  ...(d.sequence && options.length ? {sequence: true} : {}),
3038
4215
  ...(d.lookup ? {lookup: d.lookup} : {}),
4216
+ ...(d.intent ? {intent: d.intent} : {}),
3039
4217
  });
3040
4218
  };
3041
4219
  const set = (
@@ -3082,6 +4260,17 @@ export function draftAnswer(ctx, env, question) {
3082
4260
  }
3083
4261
  return c.colors[0] ?? null;
3084
4262
  };
4263
+ // "primary buttons red and the secondary blue": a clause that names its
4264
+ // own variant keeps it, never the variant of the clause before.
4265
+ for (const c of clauses) {
4266
+ const own = /\b(primary|secondary|ghost|destructive|danger)\b/.exec(
4267
+ c.text,
4268
+ )?.[1];
4269
+ if (!own) continue;
4270
+ const want = `variant:${own === 'danger' ? 'destructive' : own}`;
4271
+ for (const p of c.parts)
4272
+ if (p.when?.startsWith('variant:') && p.when !== want) p.when = want;
4273
+ }
3085
4274
  /** @type {Array<{clause: Clause, steps: Step[]}>} */
3086
4275
  const tops = [];
3087
4276
  const recordTop = (/** @type {Clause} */ c, /** @type {Step[]} */ steps) => {
@@ -3090,6 +4279,23 @@ export function draftAnswer(ctx, env, question) {
3090
4279
 
3091
4280
  for (const c of clauses) {
3092
4281
  clauseNow = c;
4282
+ // "but don't make buttons rounder": a prohibition inside the question
4283
+ // changes nothing; it says what stays.
4284
+ if (
4285
+ /^\s*(?:(?:but|and)\s+)?(?:please\s+)?(?:don'?t|do not|never)\s+make\b|\b(?:should|must|shall)(?:n'?t| not)\s+(?:be|get|look|become)\b/.test(
4286
+ c.text,
4287
+ )
4288
+ ) {
4289
+ for (const p of c.parts) {
4290
+ seenPart(p.on);
4291
+ prohibited.push(p.on);
4292
+ }
4293
+ push({
4294
+ text: `"${c.text.trim()}" asks for no change, so nothing is set there; ${c.parts.map(p => p.on).join(', ') || 'it'} stays as it is`,
4295
+ options: [],
4296
+ });
4297
+ continue;
4298
+ }
3093
4299
  // "reset the corners to default", "revert the font": take back what the
3094
4300
  // theme sets for it, as undo does.
3095
4301
  const back = resetAnswer(c);
@@ -3101,28 +4307,118 @@ export function draftAnswer(ctx, env, question) {
3101
4307
  if (c.except) {
3102
4308
  const prior = tops[tops.length - 1];
3103
4309
  if (!prior) continue;
3104
- for (const p of c.parts) {
4310
+ const priorOn = prior.steps.find(st => st.on)?.on ?? null;
4311
+ // "except primary ones", "except ghost": a variant of the part being
4312
+ // changed.
4313
+ const variant =
4314
+ /\b(primary|secondary|ghost|destructive|danger|muted|small|large|transparent|success|warning|info|neutral|error|outline|outlined|default|blue|green|red|gray|orange|purple|teal|pink|cyan)\b/.exec(
4315
+ c.text,
4316
+ )?.[1];
4317
+ const when = variant
4318
+ ? variant === 'small'
4319
+ ? 'size:sm'
4320
+ : variant === 'large'
4321
+ ? 'size:lg'
4322
+ : variantKey(
4323
+ priorOn,
4324
+ variant === 'danger' ? 'destructive' : variant,
4325
+ )
4326
+ : undefined;
4327
+ // "except on hover": that state of the part being changed.
4328
+ const exceptState =
4329
+ /\b(?:on |when )(hover(?:ed)?|focus(?:ed)?|pressed|active|disabled)\b/.exec(
4330
+ c.text,
4331
+ )?.[1];
4332
+ /** @type {Array<{on: string, when?: string, state?: string}>} */
4333
+ const excepted = [
4334
+ // "the primary button and cards": the variant names the first part.
4335
+ ...c.parts.map((x, i) =>
4336
+ i === 0 && when && !x.when ? {...x, when} : x,
4337
+ ),
4338
+ ...(!c.parts.length && when && priorOn ? [{on: priorOn, when}] : []),
4339
+ ...(!c.parts.length && !when && exceptState && priorOn
4340
+ ? [
4341
+ {
4342
+ on: priorOn,
4343
+ state: exceptState
4344
+ .replace(/ed$/, '')
4345
+ .replace(/^press$/, 'active'),
4346
+ },
4347
+ ]
4348
+ : []),
4349
+ ];
4350
+ if (!excepted.length) {
4351
+ // "except in the nav": a place, not a part.
4352
+ push({
4353
+ text: `"${c.text}" names no part the editor can keep apart, so ${prior.clause.text} applies everywhere`,
4354
+ options: [],
4355
+ });
4356
+ continue;
4357
+ }
4358
+ /** @type {Step[]} */
4359
+ const keeps = [];
4360
+ /** @type {string[]} */
4361
+ const said = [];
4362
+ for (const p of excepted) {
3105
4363
  seenPart(p.on);
3106
- const keep = prior.steps
3107
- .map(st => keepAsIs(st, p))
3108
- .filter(x => x != null);
3109
- if (!keep.length) {
3110
- push({
3111
- text: `${p.on} keeps what it has: a setting --on ${p.on} wins over a whole-theme one there, but this change has no setting for ${p.on} to keep`,
3112
- options: [],
3113
- lookup: `${HOW} ${p.on}`,
3114
- });
4364
+ const name = `${p.on}${p.when ? ` (${p.when.replace(':', ' ')})` : ''}${p.state ? ` when ${p.state}` : ''}`;
4365
+ // A part the words do not tell apart from the part being changed.
4366
+ if (!p.when && !p.state && p.on === priorOn) {
4367
+ said.push(
4368
+ `${name} is the part being changed, so it cannot be kept apart`,
4369
+ );
3115
4370
  continue;
3116
4371
  }
3117
- push({
3118
- text: `${prior.clause.text}, except ${p.on}, which keeps what it has now`,
3119
- options: [[...prior.steps, .../** @type {Step[]} */ (keep)]],
3120
- sequence: true,
3121
- });
3122
- // The whole ask comes first, before the change alone.
3123
- drafts.unshift(/** @type {Draft} */ (drafts.pop()));
3124
- tops.pop();
4372
+ const keep = prior.steps.map(st => keepAsIs(st, p));
4373
+ if (keep.every(k => k === UNTOUCHED || k == null)) {
4374
+ said.push(
4375
+ keep.some(k => k === UNTOUCHED)
4376
+ ? `${name} reads none of what changes, so it keeps what it has`
4377
+ : `${name} has nothing this change sets to keep`,
4378
+ );
4379
+ continue;
4380
+ }
4381
+ // A group whose members have different values now: each member
4382
+ // keeps its own.
4383
+ const members = FAMILIES[p.on] ?? null;
4384
+ if (members && !p.when && !p.state) {
4385
+ const per = members.map(m => ({
4386
+ m,
4387
+ ks: prior.steps.map(st => keepAsIs(st, {on: m})),
4388
+ }));
4389
+ const same = (/** @type {any} */ a, /** @type {any} */ b) =>
4390
+ JSON.stringify(a?.value ?? null) ===
4391
+ JSON.stringify(b?.value ?? null);
4392
+ const differs = per.some(x => x.ks.some((k, i) => !same(k, keep[i])));
4393
+ if (differs) {
4394
+ for (const x of per)
4395
+ for (const k of x.ks)
4396
+ if (k && k !== UNTOUCHED)
4397
+ keeps.push({.../** @type {Step} */ (k), on: x.m, only: true});
4398
+ said.push(`${name} keeps what each of them has now`);
4399
+ continue;
4400
+ }
4401
+ }
4402
+ for (const k of keep)
4403
+ if (k && k !== UNTOUCHED) keeps.push(/** @type {Step} */ (k));
4404
+ said.push(`${name} keeps what it has now`);
3125
4405
  }
4406
+ push({
4407
+ text: `${prior.clause.text}, except ${said.join('; ')}`,
4408
+ options: [[...prior.steps, ...keeps]],
4409
+ sequence: true,
4410
+ intent: intentOf(
4411
+ prior.clause,
4412
+ excepted.map(p =>
4413
+ p.when || p.state
4414
+ ? `${p.on}@${p.when ?? 'base'}|${p.state ? `:${p.state}` : ''}|`
4415
+ : p.on,
4416
+ ),
4417
+ ),
4418
+ });
4419
+ // The whole ask comes first, before the change alone.
4420
+ drafts.unshift(/** @type {Draft} */ (drafts.pop()));
4421
+ tops.pop();
3126
4422
  continue;
3127
4423
  }
3128
4424
  // A color the theme generates, named by its role ("error background",
@@ -3153,6 +4449,395 @@ export function draftAnswer(ctx, env, question) {
3153
4449
  });
3154
4450
  continue;
3155
4451
  }
4452
+ // "primary button text the same color as secondary button text",
4453
+ // "secondary buttons the same color as primary buttons": one variant
4454
+ // takes the other variant's own color (the token that variant reads),
4455
+ // so it follows both modes; the other variant is not changed.
4456
+ {
4457
+ const vv =
4458
+ /\b([a-z]+) ([a-z]+?)s?( text| background| border)? (?:the )?same colou?r as (?:the )?([a-z]+) ([a-z]+?)s?( text| background| border)?\b/.exec(
4459
+ c.text,
4460
+ );
4461
+ const part = vv && c.parts.length ? c.parts[0].on : null;
4462
+ if (vv && part && vv[1] !== vv[4]) {
4463
+ const what = (vv[3] ?? vv[6] ?? '').trim();
4464
+ const prop =
4465
+ what === 'text'
4466
+ ? 'color'
4467
+ : what === 'border'
4468
+ ? 'border-color'
4469
+ : 'background-color';
4470
+ const group =
4471
+ prop === 'color'
4472
+ ? 'text'
4473
+ : prop === 'border-color'
4474
+ ? 'border'
4475
+ : 'background';
4476
+ const k1 = variantKey(part, vv[1]);
4477
+ const k2 = variantKey(part, vv[4]);
4478
+ const w2 = k2.replace(':', '=');
4479
+ const read = C.partReads(one(part), group).find(
4480
+ r =>
4481
+ r.props.includes(prop) &&
4482
+ r.when.includes(w2) &&
4483
+ !/overlay|tint/.test(r.token),
4484
+ );
4485
+ if (read) {
4486
+ seenPart(part);
4487
+ const d = {
4488
+ text: `${part} (${vv[1]}) takes the ${prop} ${vv[4]} ${part}s have: var(${read.token}); ${vv[4]} is not changed`,
4489
+ options: [[set(prop, `var(${read.token})`, {on: part, when: k1})]],
4490
+ };
4491
+ push(d);
4492
+ recordTop(c, d.options[0] ?? []);
4493
+ continue;
4494
+ }
4495
+ }
4496
+ }
4497
+ // "background alpha 0.5": the part's own fill at that alpha, in each
4498
+ // mode from its own color.
4499
+ {
4500
+ const al = /\bbackground alpha (0?\.\d+|1)\b/.exec(c.text);
4501
+ if (al && c.parts.length) {
4502
+ const a = Number(al[1]);
4503
+ for (const p of c.parts) {
4504
+ seenPart(p.on);
4505
+ const {noState: _n, ...f} = flagsFor(c, p);
4506
+ // The fill the part shows at rest (its own value, else the token
4507
+ // its plain rule reads, never an overlay), mixed with
4508
+ // transparent: it follows both modes.
4509
+ const own = partValue(p.on, 'background-color');
4510
+ const tok = own
4511
+ ? null
4512
+ : restColorRead(C.partReads(one(p.on), 'background'));
4513
+ const base = own ?? (tok ? `var(${tok})` : null);
4514
+ const d = {
4515
+ text: base
4516
+ ? `${p.on}'s own fill (${base}) at ${a} alpha, in both modes`
4517
+ : `${p.on} has no fill of its own to make see-through`,
4518
+ options: base
4519
+ ? [
4520
+ [
4521
+ set(
4522
+ 'background-color',
4523
+ `color-mix(in srgb, ${base} ${Math.round(a * 100)}%, transparent)`,
4524
+ f,
4525
+ ),
4526
+ ],
4527
+ ]
4528
+ : [],
4529
+ };
4530
+ push(d);
4531
+ recordTop(c, d.options[0] ?? []);
4532
+ }
4533
+ continue;
4534
+ }
4535
+ }
4536
+ // "card padding bigger than 4px": past that bound, measured from now;
4537
+ // nothing when the part is already past it.
4538
+ {
4539
+ const bound =
4540
+ /\b(bigger|larger|more|wider|roomier|smaller|less|tighter|narrower|rounder|sharper)\s+than\s+(\d*\.?\d+)(px|rem)\b/.exec(
4541
+ c.text,
4542
+ );
4543
+ const prop = /\bgap\b/.test(c.text)
4544
+ ? 'gap'
4545
+ : /\b(padding|spacing|room)\b/.test(c.text)
4546
+ ? 'padding'
4547
+ : /\b(radius|corners?|rounder|sharper)\b/.test(c.text)
4548
+ ? 'border-radius'
4549
+ : null;
4550
+ if (bound && prop && c.parts.length) {
4551
+ const up = /^(bigger|larger|more|wider|roomier|rounder)$/.test(
4552
+ bound[1],
4553
+ );
4554
+ const limit = Number(bound[2]) * (bound[3] === 'rem' ? 16 : 1);
4555
+ for (const p of c.parts) {
4556
+ seenPart(p.on);
4557
+ const now = partPropNow(p.on, prop);
4558
+ const m = /^(\d*\.?\d+)(px|rem)?/.exec(String(now ?? ''));
4559
+ const nowPx = m ? Number(m[1]) * (m[2] === 'rem' ? 16 : 1) : null;
4560
+ const {noState: _n, ...f} = flagsFor(c, p);
4561
+ if (nowPx != null && (up ? nowPx > limit : nowPx < limit)) {
4562
+ push({
4563
+ text: `${p.on} has ${prop} ${now} now, already ${bound[1]} than ${bound[2]}${bound[3]}; nothing to change`,
4564
+ options: [],
4565
+ });
4566
+ continue;
4567
+ }
4568
+ const v = `${Math.max(0, Math.round(up ? limit * 1.25 : limit * 0.8))}px`;
4569
+ const d = {
4570
+ text: `${prop} on ${p.on} ${bound[1]} than ${bound[2]}${bound[3]}: ${v}${now ? ` (now ${now})` : ''}`,
4571
+ options: [[set(prop, v, f)]],
4572
+ };
4573
+ push(d);
4574
+ recordTop(c, d.options[0] ?? []);
4575
+ }
4576
+ continue;
4577
+ }
4578
+ }
4579
+ // "avatars 24x24px", "icons 16 x 16": a size of that width and height.
4580
+ {
4581
+ const pair =
4582
+ /\b(\d*\.?\d+)(px|rem|em)?\s*[x×]\s*(\d*\.?\d+)(px|rem|em)?\b/.exec(
4583
+ c.text,
4584
+ );
4585
+ if (
4586
+ pair &&
4587
+ c.parts.length &&
4588
+ !/\b(padding|gap|margin|spacing|radius|corners?|border|shadow|outline)\b/.test(
4589
+ c.text,
4590
+ )
4591
+ ) {
4592
+ const unit = pair[4] ?? pair[2] ?? 'px';
4593
+ const w = `${pair[1]}${pair[2] ?? unit}`;
4594
+ const h = `${pair[3]}${unit}`;
4595
+ for (const p of c.parts) {
4596
+ seenPart(p.on);
4597
+ const {noState: _n, ...f} = flagsFor(c, p);
4598
+ const d = {
4599
+ text: `${p.on} ${w} by ${h}: its width and height`,
4600
+ options: [[set('width', w, f), set('height', h, f)]],
4601
+ sequence: true,
4602
+ };
4603
+ push(d);
4604
+ recordTop(c, d.options[0] ?? []);
4605
+ }
4606
+ continue;
4607
+ }
4608
+ }
4609
+ // The parts the clause names, in the order the words name them.
4610
+ const inOrder = () =>
4611
+ [
4612
+ ...new Set([
4613
+ ...c.parts.map(x => x.on),
4614
+ ...lex.parts.filter(([re]) => re.test(c.text)).map(([, x]) => x.on),
4615
+ ]),
4616
+ ]
4617
+ .map(on => ({
4618
+ on,
4619
+ at: Math.min(
4620
+ ...lex.parts
4621
+ .filter(([, x]) => x.on === on)
4622
+ .map(([re]) => re.exec(c.text)?.index ?? Infinity),
4623
+ ),
4624
+ }))
4625
+ .sort((x, y) => x.at - y.at)
4626
+ .map(x => x.on);
4627
+ /** The color property a side of a comparison names. @param {string} t */
4628
+ const colorProp = t =>
4629
+ /\b(text|labels?|font|words?)\b/.test(t)
4630
+ ? 'color'
4631
+ : /\bborders?\b/.test(t)
4632
+ ? 'border-color'
4633
+ : /\b(background|fill|bg)\b/.test(t)
4634
+ ? 'background-color'
4635
+ : null;
4636
+ // "button text the same color as the card text", "input border the
4637
+ // same color as the button background", "dialog background match the
4638
+ // card background": that color property of the other part, onto the
4639
+ // first part's property the words name; the other part is not changed.
4640
+ {
4641
+ const cmp =
4642
+ /\b(?:(?:the )?same colou?r as|match(?:es|ing)?|colou?red like)\s+(?:the\s+|my\s+)?/.exec(
4643
+ c.text,
4644
+ );
4645
+ const ordered = cmp ? inOrder() : [];
4646
+ const left = cmp ? c.text.slice(0, cmp.index) : '';
4647
+ const right = cmp ? c.text.slice((cmp.index ?? 0) + cmp[0].length) : '';
4648
+ const subjectProp = cmp ? colorProp(left) : null;
4649
+ if (
4650
+ cmp &&
4651
+ ordered.length >= 2 &&
4652
+ (subjectProp || /colou?r/.test(cmp[0]))
4653
+ ) {
4654
+ const sp = subjectProp ?? 'background-color';
4655
+ const rp =
4656
+ colorProp(right) ?? (sp === 'color' ? 'color' : 'background-color');
4657
+ const [subjectOn, sourceOn] = ordered;
4658
+ const value = partPropNow(sourceOn, rp, true);
4659
+ if (value) {
4660
+ seenPart(subjectOn);
4661
+ seenPart(sourceOn);
4662
+ const d = {
4663
+ text: `${subjectOn}'s ${sp} takes ${sourceOn}'s ${rp}: ${value} (${sourceOn} is not changed)`,
4664
+ options: [[set(sp, value, {on: subjectOn})]],
4665
+ };
4666
+ push(d);
4667
+ recordTop(c, d.options[0] ?? []);
4668
+ continue;
4669
+ }
4670
+ }
4671
+ }
4672
+ // "the card and dialog corners match", "cards and dialogs equally
4673
+ // round", "buttons and inputs the same height": the second part takes
4674
+ // the first part's value, so they match; nothing new is written.
4675
+ {
4676
+ const sym =
4677
+ /\b(match|equally|alike|the same(?! \w+ as\b)(?: \w+)?)\s*$|\b(?:equally|the same) (round(?:ed)?|tall|high|padd(?:ed|ing)|big|bold)\b/.exec(
4678
+ c.text,
4679
+ );
4680
+ // The parts of the whole sentence ("the card and dialog corners
4681
+ // match" reads "the card" as a clause of its own).
4682
+ const sentence =
4683
+ q.split(/[;.\n]/).find(x => x.includes(c.text.trim())) ?? c.text;
4684
+ const ordered =
4685
+ sym && !/\b(as|than)\b/.test(sentence)
4686
+ ? lex.parts
4687
+ .map(([re, x]) => ({
4688
+ on: x.on,
4689
+ at: re.exec(sentence)?.index ?? -1,
4690
+ }))
4691
+ .filter(x => x.at >= 0)
4692
+ .sort((x, y) => x.at - y.at)
4693
+ .map(x => x.on)
4694
+ .filter((on, i, all) => all.indexOf(on) === i)
4695
+ : [];
4696
+ const prop = /round|corner|radius/.test(c.text)
4697
+ ? 'border-radius'
4698
+ : /\bpadd/.test(c.text)
4699
+ ? 'padding'
4700
+ : /\b(tall|height|high)\b/.test(c.text)
4701
+ ? 'height'
4702
+ : /\bcolou?r|\bborders?\b/.test(c.text)
4703
+ ? (colorProp(c.text) ?? 'background-color')
4704
+ : null;
4705
+ if (sym && ordered.length === 2 && prop) {
4706
+ const [sourceOn, subjectOn] = ordered;
4707
+ const value = partPropNow(sourceOn, prop, true);
4708
+ const has = partPropNow(subjectOn, prop, true);
4709
+ if (value) {
4710
+ seenPart(subjectOn);
4711
+ seenPart(sourceOn);
4712
+ const d =
4713
+ has && has === value
4714
+ ? {
4715
+ text: `${sourceOn} and ${subjectOn} already have the same ${prop} (${value}), so nothing changes`,
4716
+ options: [],
4717
+ }
4718
+ : {
4719
+ text: `${subjectOn} takes ${sourceOn}'s ${prop} so they match: ${value} (${sourceOn} is not changed)`,
4720
+ options: [[set(prop, value, {on: subjectOn})]],
4721
+ };
4722
+ push(d);
4723
+ recordTop(c, d.options[0] ?? []);
4724
+ // The clause that only named the first part asks nothing more.
4725
+ symDone.add(sourceOn);
4726
+ continue;
4727
+ }
4728
+ // Nothing to copy from: say so, never a new value for both.
4729
+ seenPart(subjectOn);
4730
+ seenPart(sourceOn);
4731
+ push({
4732
+ text: `${sourceOn} has no ${prop} of its own that how can read, so it cannot copy it onto ${subjectOn}; give the value for both (for example "${prop} 40px on ${sourceOn} and ${subjectOn}")`,
4733
+ options: [],
4734
+ });
4735
+ symDone.add(sourceOn);
4736
+ continue;
4737
+ }
4738
+ }
4739
+ // "cards as round as buttons", "card padding the same as button
4740
+ // padding", "make the cards match the buttons' corners", "inputs as
4741
+ // tall as buttons": the part named first takes the other part's value
4742
+ // of that property now, written out; the other part is not changed.
4743
+ {
4744
+ const measure =
4745
+ /\bas (round(?:ed)?|tall|high|bold|big|large) as\b|\bsame (corners?|radius|roundness|padding|height|font size|text size|weight) as\b|\b(?:match(?:es|ing)?|(?<!\b(?:i'?d|i|would|we'?d|you'?d)\s)like)\b[^.]*?\b(corners?|radius|padding|height)\b|\b(corners?|radius|padding|height)\b[^.]*?\b(?:bigger|larger|more|smaller|less|tighter|rounder|squarer) than\b|\b(rounder|squarer|sharper) than\b|\b(corners?|radius|padding|height)\b[^.]*?\b(?:the )?same as\b/.exec(
4746
+ c.text,
4747
+ );
4748
+ const word = measure ? (measure.slice(1).find(Boolean) ?? '') : '';
4749
+ const prop = /round|corner|radius/.test(word)
4750
+ ? 'border-radius'
4751
+ : /padding/.test(word)
4752
+ ? 'padding'
4753
+ : /tall|high|height/.test(word)
4754
+ ? 'height'
4755
+ : /bold|weight/.test(word)
4756
+ ? 'font-weight'
4757
+ : /big|large|size/.test(word)
4758
+ ? 'font-size'
4759
+ : null;
4760
+ // The parts as the words name them (the comparison's own part may have
4761
+ // been taken out of the clause's parts already).
4762
+ const named = [
4763
+ ...new Set([
4764
+ ...c.parts.map(x => x.on),
4765
+ ...lex.parts.filter(([re]) => re.test(c.text)).map(([, x]) => x.on),
4766
+ ]),
4767
+ ]
4768
+ .map(on => ({
4769
+ on,
4770
+ at: Math.min(
4771
+ ...lex.parts
4772
+ .filter(([, x]) => x.on === on)
4773
+ .map(([re]) => re.exec(c.text)?.index ?? Infinity),
4774
+ ),
4775
+ }))
4776
+ .sort((x, y) => x.at - y.at);
4777
+ const sourceOn =
4778
+ named.length >= 2 ? named[1].on : (compared.get(c) ?? null);
4779
+ const subjectOn = named[0]?.on ?? null;
4780
+ if (prop && subjectOn && sourceOn && subjectOn !== sourceOn) {
4781
+ const now = partPropNow(sourceOn, prop);
4782
+ // "twice as round as inputs": that amount of the other part's;
4783
+ // else the other part's own value, or the token it reads (so the
4784
+ // copy follows it).
4785
+ // "card padding bigger than button padding": a step past the other
4786
+ // part's value, never a copy of it.
4787
+ const past =
4788
+ /\b(bigger|larger|more|rounder|smaller|less|tighter|squarer|sharper) than\b/.exec(
4789
+ c.text,
4790
+ )?.[1];
4791
+ const pastFactor = past
4792
+ ? /^(smaller|less|tighter|squarer|sharper)$/.test(past)
4793
+ ? 0.8
4794
+ : 1.25
4795
+ : null;
4796
+ // "4px rounder than buttons": the other part's value and that much.
4797
+ const delta = past
4798
+ ? (c.lengths.find(l => /(px|rem|em)$/.test(l)) ?? null)
4799
+ : null;
4800
+ const factor = delta ? null : (exactFactor(c.text) ?? pastFactor);
4801
+ const value = delta
4802
+ ? `calc(${partPropNow(sourceOn, prop, true)} ${pastFactor && pastFactor < 1 ? '-' : '+'} ${delta})`
4803
+ : now && factor
4804
+ ? scaledBox(now, factor)
4805
+ : past
4806
+ ? null
4807
+ : partPropNow(sourceOn, prop, true);
4808
+ if (!value) {
4809
+ // Nothing to measure against: said, never a step on both.
4810
+ seenPart(subjectOn);
4811
+ seenPart(sourceOn);
4812
+ push({
4813
+ text: `${sourceOn} has no ${prop} of its own that how can read, so ${subjectOn} cannot take it; give the value (for example "${prop} 16px on ${subjectOn}")`,
4814
+ options: [],
4815
+ });
4816
+ continue;
4817
+ }
4818
+ if (value) {
4819
+ seenPart(subjectOn);
4820
+ seenPart(sourceOn);
4821
+ // The subject's own variant and the clause's state stay.
4822
+ const sub = c.parts.find(x => x.on === subjectOn);
4823
+ const sflags = {
4824
+ on: subjectOn,
4825
+ ...(sub?.when ? {when: sub.when} : {}),
4826
+ ...(c.state ? {state: c.state} : {}),
4827
+ };
4828
+ const d = {
4829
+ text:
4830
+ past && !exactFactor(c.text)
4831
+ ? `${subjectOn} ${prop} ${delta ?? 'a step'} ${pastFactor && pastFactor > 1 ? 'past' : 'under'} ${sourceOn}'s: ${value} (${sourceOn} has ${now} now and is not changed)`
4832
+ : `${subjectOn} takes ${factor ? `${factor} times ` : ''}${sourceOn}'s ${prop}: ${value} (${sourceOn} has ${now} now and is not changed)`,
4833
+ options: [[set(prop, value, sflags)]],
4834
+ };
4835
+ push(d);
4836
+ recordTop(c, d.options[0] ?? []);
4837
+ continue;
4838
+ }
4839
+ }
4840
+ }
3156
4841
  // "cards the same radius as buttons": the first part takes the second
3157
4842
  // part's value, read from the token the second part reads.
3158
4843
  const same = /\b(?:the )?same (\w+(?: \w+)?) as (?:the )?([a-z-]+)\b/.exec(
@@ -3234,6 +4919,23 @@ export function draftAnswer(ctx, env, question) {
3234
4919
  continue;
3235
4920
  }
3236
4921
  }
4922
+ // "card radius 50%": a percent radius in CSS is a share of the box's
4923
+ // own size (an oval), not of the radius now. With "of now" or a
4924
+ // direction it is a factor (read above); alone it is refused with the
4925
+ // exact command that works.
4926
+ const pctRadius =
4927
+ /\b(?:radius|corners?|rounding)\b(?:\s+(?:to|at|of))?\s+(\d{1,3}(?:\.\d+)?)\s?%(?!\s*(?:of|as|bigger|smaller|larger|more|less|rounder|sharper)\b)/.exec(
4928
+ c.text,
4929
+ );
4930
+ if (pctRadius && !c.dir && exactFactor(c.text) == null && c.parts[0]) {
4931
+ const n = pctRadius[1];
4932
+ push({
4933
+ text: `a ${n}% radius in CSS is a share of the ${c.parts[0].on}'s own width and height (an oval or a circle), not ${n}% of the radius now; for ${n}% of the radius now: ${HOW} '${c.parts[0].on} radius ${n}% of now'; for a pill: ${P} set ${env.slug} corners pill --on ${c.parts[0].on}`,
4934
+ options: [],
4935
+ lookup: `${HOW} '${c.parts[0].on} radius ${n}% of now'`,
4936
+ });
4937
+ continue;
4938
+ }
3237
4939
  // "decrease the radius by 2px", "add 8px to the padding": a change from
3238
4940
  // the value now, never the new value itself.
3239
4941
  // "shrink headings by 20%": a change by a share, from the value now.
@@ -3296,13 +4998,29 @@ export function draftAnswer(ctx, env, question) {
3296
4998
  if (cornerAsk && c.parts.length) {
3297
4999
  const on = c.parts[0].on;
3298
5000
  const read = C.partReads(one(on), 'corners')[0];
5001
+ // The clause's state and variant ("on hover", "primary") are kept,
5002
+ // and the move starts from that state's own radius.
5003
+ const {noState: _ns, ...pf} = flagsFor(c, c.parts[0]);
5004
+ const scopedRadius =
5005
+ pf.state || pf.when
5006
+ ? ([...env.data.settings]
5007
+ .reverse()
5008
+ .find(
5009
+ st =>
5010
+ st.thing === 'border-radius' &&
5011
+ st.on === on &&
5012
+ (st.state ?? null) === (pf.state ?? null) &&
5013
+ (st.when ?? null) === (pf.when ?? null) &&
5014
+ !st.mode,
5015
+ )?.value ?? null)
5016
+ : null;
3299
5017
  // A radius the theme set on the part in px moves from that value.
3300
- const ownRadius = partValue(on, 'border-radius');
5018
+ const ownRadius = scopedRadius ?? partValue(on, 'border-radius');
3301
5019
  if (ownRadius && /^\d*\.?\d+px$/.test(ownRadius)) {
3302
5020
  const next = Math.max(0, parseFloat(ownRadius) + (down ? -n : n));
3303
5021
  const d = {
3304
5022
  text: `${on}'s corners ${down ? 'down' : 'up'} by ${n}px: from ${ownRadius} to ${next}px`,
3305
- options: [[set('border-radius', `${next}px`, {on})]],
5023
+ options: [[set('border-radius', `${next}px`, pf)]],
3306
5024
  };
3307
5025
  push(d);
3308
5026
  recordTop(c, d.options[0] ?? []);
@@ -3316,7 +5034,7 @@ export function draftAnswer(ctx, env, question) {
3316
5034
  set(
3317
5035
  'border-radius',
3318
5036
  `max(0px, calc(var(${read.token}) ${down ? '-' : '+'} ${n}px))`,
3319
- {on},
5037
+ pf,
3320
5038
  ),
3321
5039
  ],
3322
5040
  ],
@@ -3341,6 +5059,59 @@ export function draftAnswer(ctx, env, question) {
3341
5059
  recordTop(c, d.options[0] ?? []);
3342
5060
  continue;
3343
5061
  }
5062
+ // Padding, gap or text size moved by a length: the value now plus or
5063
+ // minus it, each side on its own, exact.
5064
+ if (c.parts.length) {
5065
+ const on = c.parts[0].on;
5066
+ const {noState: _ns2, ...pf} = flagsFor(c, c.parts[0]);
5067
+ const prop = /\b(gaps?|between)\b/.test(c.text)
5068
+ ? 'gap'
5069
+ : c.aspects.includes('fontsize') ||
5070
+ /\b(font|text)[- ]size\b/.test(c.text)
5071
+ ? 'font-size'
5072
+ : c.aspects.includes('spacing') || /\bpadding\b/.test(c.text)
5073
+ ? 'padding'
5074
+ : null;
5075
+ const level = /^level:([1-6])$/.exec(pf.when ?? '')?.[1];
5076
+ const now = !prop
5077
+ ? null
5078
+ : prop === 'font-size' && on === 'heading' && level
5079
+ ? (partValue(on, 'font-size') ??
5080
+ current(`--text-heading-${level}-size`))
5081
+ : prop === 'gap'
5082
+ ? (partValue(on, 'gap') ??
5083
+ (() => {
5084
+ const r = C.partReads(one(on), 'spacing').find(x =>
5085
+ x.props.some(q => /gap/.test(q)),
5086
+ );
5087
+ return r ? current(r.token) : null;
5088
+ })())
5089
+ : prop === 'padding'
5090
+ ? (partValue(on, 'padding') ?? paddingBoxNow(on))
5091
+ : partPropNow(on, prop);
5092
+ /** @param {string} v */
5093
+ const toPx = v => {
5094
+ const m = /^(\d*\.?\d+)(px|rem|em)$/.exec(v);
5095
+ return m ? Number(m[1]) * (m[2] === 'px' ? 1 : 16) : null;
5096
+ };
5097
+ const sides = now ? String(now).trim().split(/\s+/) : [];
5098
+ const moved = sides.map(x => {
5099
+ const px = toPx(x);
5100
+ return px == null
5101
+ ? null
5102
+ : `${Math.max(0, Math.round((px + (down ? -n : n)) * 100) / 100)}px`;
5103
+ });
5104
+ if (prop && sides.length && sides.length <= 4 && moved.every(Boolean)) {
5105
+ const next = moved.join(' ');
5106
+ const d = {
5107
+ text: `${prop}${pf.when || pf.state ? ` on ${on} (${[pf.when, pf.state].filter(Boolean).join(', ')})` : ` on ${on}`} ${down ? 'down' : 'up'} by ${n}px: from ${now} to ${next}`,
5108
+ options: [[set(prop, next, pf)]],
5109
+ };
5110
+ push(d);
5111
+ recordTop(c, d.options[0] ?? []);
5112
+ continue;
5113
+ }
5114
+ }
3344
5115
  push({
3345
5116
  text: `set takes the new value, not a change by ${n}px; look up what it is now, then set it ${down ? 'minus' : 'plus'} ${n}px`,
3346
5117
  options: [],
@@ -3498,14 +5269,44 @@ export function draftAnswer(ctx, env, question) {
3498
5269
  if (
3499
5270
  named &&
3500
5271
  !named.bad &&
5272
+ // A percent padding or gap is an amount of the one there now ("50%
5273
+ // bigger", "150%"), answered below: a CSS percent padding is half the
5274
+ // container's width.
5275
+ !(
5276
+ /^(padding|gap|row-gap|column-gap)$/.test(named.prop) &&
5277
+ /^\d*\.?\d+%$/.test(String(named.value).trim())
5278
+ ) &&
5279
+ // "padding 3 times bigger", "25% darker": an amount of what is there,
5280
+ // never the number as a value.
5281
+ !(
5282
+ exactFactor(c.text) != null &&
5283
+ withoutAmount(c.text) !== c.text.replace(/\s+/g, ' ')
5284
+ ) &&
5285
+ !(
5286
+ exactFactor(c.text) != null &&
5287
+ /^\d*\.?\d+%?$/.test(String(named.value).trim())
5288
+ ) &&
5289
+ !(
5290
+ /^\d*\.?\d+%$/.test(String(named.value).trim()) &&
5291
+ /\b(darker|lighter|brighter|bigger|smaller|larger)\b/.test(c.text)
5292
+ ) &&
3501
5293
  // A divider's thickness and color are its border tokens.
3502
5294
  !c.parts.some(p => p.on === 'divider') &&
3503
5295
  c.parts.length &&
3504
5296
  c.parts.every(p => TARGET.has(one(p.on)) || FAMILIES[p.on])
3505
5297
  ) {
5298
+ // "horizontal padding 20px", "padding top 12px": only those sides.
5299
+ const side = named.prop === 'padding' ? sideIn(c) : null;
5300
+ const prop = !side
5301
+ ? named.prop
5302
+ : /^(left|right|top|bottom)$/.test(side)
5303
+ ? `padding-${side}`
5304
+ : /^(vertical|block)/.test(side)
5305
+ ? 'padding-block'
5306
+ : 'padding-inline';
3506
5307
  const steps = c.parts.slice(0, 3).map(p => {
3507
5308
  const {noState: _n, ...f} = flagsFor(c, p);
3508
- return {p, f, st: set(named.prop, named.value, {...f, ...modeOf(c)})};
5309
+ return {p, f, st: set(prop, named.value, {...f, ...modeOf(c)})};
3509
5310
  });
3510
5311
  // A property set cannot use on a part (a heading's color comes from
3511
5312
  // its prop) is answered the usual way, which says why.
@@ -3513,7 +5314,7 @@ export function draftAnswer(ctx, env, question) {
3513
5314
  for (const {p, f, st} of steps) {
3514
5315
  seenPart(p.on);
3515
5316
  const d = {
3516
- text: `${named.prop} on ${p.on}${f.state ? ` when ${f.state}` : ''}, as you wrote it`,
5317
+ text: `${prop} on ${p.on}${f.state ? ` when ${f.state}` : ''}, as you wrote it`,
3517
5318
  options: [[st]],
3518
5319
  };
3519
5320
  push(d);
@@ -3685,26 +5486,251 @@ export function draftAnswer(ctx, env, question) {
3685
5486
  };
3686
5487
  }
3687
5488
 
5489
+ /**
5490
+ * A token's value now with every var() it reads written out.
5491
+ * @param {string} token
5492
+ */
5493
+ function resolvedValue(token) {
5494
+ let v = String(current(token) || '');
5495
+ for (let i = 0; i < 6 && /var\(/.test(v); i++)
5496
+ v = v.replace(
5497
+ /var\(\s*(--[a-z0-9-]+)\s*(?:,\s*([^()]*))?\)/gi,
5498
+ (_, t, fb) => String(current(t) || fb || ''),
5499
+ );
5500
+ return v.trim() || null;
5501
+ }
5502
+
5503
+ /**
5504
+ * A part's padding box now from the base theme's rule, else from the
5505
+ * token Core reads for each side (a button is 8px block, 12px inline).
5506
+ * @param {string} part
5507
+ * @returns {string | null}
5508
+ */
5509
+ function paddingBoxNow(part) {
5510
+ const rule = partRuleTokens(
5511
+ ctx.project.cwd,
5512
+ env.slug,
5513
+ env.data.like,
5514
+ one(part),
5515
+ ).get('padding');
5516
+ if (rule) {
5517
+ const resolved = String(rule).replace(
5518
+ /var\(\s*(--[a-z0-9-]+)\s*(?:,[^)]*)?\)/gi,
5519
+ (m, t) => current(t) || m,
5520
+ );
5521
+ if (scaledBox(resolved, 1)) return resolved;
5522
+ }
5523
+ const reads = C.partReads(one(part), 'spacing').filter(r =>
5524
+ r.props.some(q => /^padding/.test(q)),
5525
+ );
5526
+ /** @param {RegExp} re */
5527
+ const sideTok = re =>
5528
+ reads.find(r => r.props.some(x => re.test(x)))?.token ?? null;
5529
+ const toks = [
5530
+ sideTok(/^padding-(block(-start)?|top)$/),
5531
+ sideTok(/^padding-(inline(-end)?|right)$/),
5532
+ sideTok(/^padding-(block(-end)?|bottom)$/),
5533
+ sideTok(/^padding-(inline(-start)?|left)$/),
5534
+ ];
5535
+ if (toks.some(Boolean)) {
5536
+ const box = toks.map(tk => (tk ? current(tk) || '0px' : '0px'));
5537
+ return box[0] === box[2] && box[1] === box[3]
5538
+ ? box[0] === box[1]
5539
+ ? box[0]
5540
+ : `${box[0]} ${box[1]}`
5541
+ : box.join(' ');
5542
+ }
5543
+ return partPropNow(part, 'padding');
5544
+ }
5545
+
5546
+ /**
5547
+ * A part's value of a property now: its own setting, else the token its
5548
+ * plain rule reads for it, written out.
5549
+ * @param {string} part
5550
+ * @param {string} prop
5551
+ * @param {boolean} [live] the token itself (`var(--x)`) when the part has
5552
+ * no setting of its own, so the copy follows it
5553
+ * @returns {string | null}
5554
+ */
5555
+ function partPropNow(part, prop, live = false) {
5556
+ const own = partValue(part, prop);
5557
+ if (own) return own;
5558
+ // A color: the text color (or fill) the part shows at rest.
5559
+ if (
5560
+ prop === 'color' ||
5561
+ prop === 'background-color' ||
5562
+ prop === 'border-color'
5563
+ ) {
5564
+ const group =
5565
+ prop === 'color'
5566
+ ? 'text'
5567
+ : prop === 'border-color'
5568
+ ? 'border'
5569
+ : 'background';
5570
+ // A part with no text color of its own shows the main text color.
5571
+ const token =
5572
+ restColorRead(C.partReads(one(part), group)) ??
5573
+ (group === 'text' ? '--color-text-primary' : null);
5574
+ if (!token) return null;
5575
+ return live ? `var(${token})` : resolvedValue(token);
5576
+ }
5577
+ // The part's plain rule as built (both sides of a two-value padding).
5578
+ if (prop === 'padding') {
5579
+ const rule = partRuleTokens(
5580
+ ctx.project.cwd,
5581
+ env.slug,
5582
+ env.data.like,
5583
+ one(part),
5584
+ ).get('padding');
5585
+ if (rule)
5586
+ return live
5587
+ ? String(rule)
5588
+ : String(rule).replace(
5589
+ /var\(\s*(--[a-z0-9-]+)\s*(?:,[^)]*)?\)/gi,
5590
+ (m, t) => resolvedValue(t) || m,
5591
+ );
5592
+ }
5593
+ const group = /** @type {Record<string, string>} */ ({
5594
+ 'border-radius': 'corners',
5595
+ padding: 'spacing',
5596
+ height: 'spacing',
5597
+ 'font-size': 'font',
5598
+ 'font-weight': 'font',
5599
+ })[prop];
5600
+ if (!group) return null;
5601
+ const want =
5602
+ prop === 'padding'
5603
+ ? /^padding/
5604
+ : prop === 'height'
5605
+ ? /^(min-)?(block-size|height)$/
5606
+ : new RegExp(`^${prop}$`);
5607
+ const reads = C.partReads(one(part), group).filter(
5608
+ r => group === 'corners' || r.props.some(x => want.test(x)),
5609
+ );
5610
+ const read =
5611
+ reads.find(r => r.when.includes('')) ??
5612
+ reads.find(r => r.when.some(w => /=(primary|md|medium)$/.test(w))) ??
5613
+ reads[0];
5614
+ if (!read) return null;
5615
+ return live ? `var(${read.token})` : resolvedValue(read.token);
5616
+ }
5617
+
5618
+ /**
5619
+ * The side word of a padding ask ("top", "horizontal", "block"), read with
5620
+ * the clause's part names taken out ("code block", "top nav" are parts,
5621
+ * not sides).
5622
+ * @param {Clause} c
5623
+ * @returns {string | undefined}
5624
+ */
5625
+ function sideIn(c) {
5626
+ const ons = new Set(c.parts.map(x => x.on));
5627
+ const text = lex.parts
5628
+ .filter(([, x]) => ons.has(x.on))
5629
+ .reduce((t, [re]) => t.replace(new RegExp(re.source, 'g'), ' '), c.text);
5630
+ // left/right/top/bottom/sides name a side anywhere; inline, block,
5631
+ // horizontal and vertical only beside the padding or margin they
5632
+ // qualify ("inline padding", "padding-inline", "padding 8px vertical"),
5633
+ // never as a word of a part's name ("inline code", "block quote").
5634
+ const plain = /\b(left|right|top|bottom|sides)\b/.exec(text)?.[1];
5635
+ if (plain) return plain;
5636
+ const axis =
5637
+ /\b(horizontal(?:ly)?|vertical(?:ly)?|inline|block)[\s-]+(?:padding|margin)\b/.exec(
5638
+ text,
5639
+ )?.[1] ??
5640
+ /\b(?:padding|margin)[\s-]+(?:(?:of\s+)?-?\d*\.?\d+(?:px|rem|em)?\s+)?(?:on\s+the\s+)?(horizontal(?:ly)?|vertical(?:ly)?|inline|block)\b/.exec(
5641
+ text,
5642
+ )?.[1];
5643
+ return axis;
5644
+ }
5645
+
5646
+ /**
5647
+ * The `key:value` a part names a variant word by ("success" on a badge
5648
+ * is `variant:success`, or the part's own key for it), read from the
5649
+ * rules the part has; `variant:<word>` when none says.
5650
+ * @param {string | null} part
5651
+ * @param {string} word
5652
+ */
5653
+ function variantKey(part, word) {
5654
+ if (part)
5655
+ for (const g of Object.keys(GROUPS))
5656
+ for (const r of C.partReads(one(part), g) ?? [])
5657
+ for (const w of r.when ?? []) {
5658
+ const m = new RegExp(`(?:^|\\s)([a-z]+)=${word}(?:\\s|$)`).exec(w);
5659
+ if (m) return `${m[1]}:${word}`;
5660
+ }
5661
+ return `variant:${word}`;
5662
+ }
5663
+
5664
+ /**
5665
+ * Whether a part reads a token in any of its rules.
5666
+ * @param {string} part
5667
+ * @param {string} token
5668
+ */
5669
+ function partReadsToken(part, token) {
5670
+ return Object.keys(GROUPS).some(g =>
5671
+ C.partReads(one(part), g).some(r => r.token === token),
5672
+ );
5673
+ }
5674
+
3688
5675
  /**
3689
5676
  * The step that keeps one part as it is now when a step changes the whole
3690
5677
  * theme (or a group the part is in), or null when none can.
3691
5678
  * @param {Step} st
3692
- * @param {{on: string, when?: string}} p
3693
- * @returns {Step | null}
5679
+ * @param {{on: string, when?: string, state?: string}} p
5680
+ * @returns {Step | null | typeof UNTOUCHED}
3694
5681
  */
3695
5682
  function keepAsIs(st, p) {
3696
- const flags = {on: p.on, ...(p.when ? {when: p.when} : {})};
5683
+ const flags = {
5684
+ on: p.on,
5685
+ ...(p.when ? {when: p.when} : {}),
5686
+ ...(p.state ? {state: p.state} : {}),
5687
+ };
5688
+ // A token the part never reads does not change it: nothing to keep.
5689
+ // (Only tokens a part never inherits: a text token reaches every part's
5690
+ // text through inheritance.)
5691
+ if (/^--(spacing|size)-/.test(st.thing) && !partReadsToken(p.on, st.thing))
5692
+ return UNTOUCHED;
5693
+ // A radius token reaches a part through its own variables too: pin the
5694
+ // radius it has now, as for the corners dial.
5695
+ if (/^--radius-/.test(st.thing))
5696
+ return keepAsIs({...st, thing: 'corners'}, p);
5697
+ // "all text bigger except buttons": the part's text size now.
5698
+ if (
5699
+ st.thing === 'text-size' ||
5700
+ st.thing === '--font-size-base' ||
5701
+ /^--text-[a-z-]+-size$/.test(st.thing)
5702
+ ) {
5703
+ const now = partPropNow(p.on, 'font-size');
5704
+ return now
5705
+ ? set('font-size', now, {
5706
+ ...flags,
5707
+ ...(p.state ? {state: p.state} : {}),
5708
+ })
5709
+ : null;
5710
+ }
3697
5711
  if (st.on && st.on !== p.on && !(FAMILIES[st.on] ?? []).includes(one(p.on)))
3698
5712
  return null;
3699
- if (st.thing === 'corners') {
3700
- const read = C.partReads(one(p.on), 'corners').find(r =>
3701
- r.when.includes(''),
3702
- );
5713
+ if (st.thing === 'corners' || st.thing === 'border-radius') {
5714
+ // What the part has now: its own setting, else the token it reads
5715
+ // (its plain rule first, else any rule's), never another token.
5716
+ const reads = C.partReads(one(p.on), 'corners');
5717
+ const read = reads.find(r => r.when.includes('')) ?? reads[0];
5718
+ // The base theme's own radius for the part, written out, comes before
5719
+ // the token it reads.
5720
+ const baseOwn = /** @type {any} */ (env.base).components?.[one(p.on)]
5721
+ ?.base?.borderRadius;
3703
5722
  return set(
3704
5723
  'border-radius',
3705
- read
3706
- ? current(read.token) || `var(${read.token})`
3707
- : current('--radius-element'),
5724
+ partValue(p.on, 'border-radius') ??
5725
+ (baseOwn
5726
+ ? String(baseOwn).replace(
5727
+ /var\(\s*(--[a-z0-9-]+)\s*(?:,[^)]*)?\)/gi,
5728
+ (m, t) => resolvedValue(t) || m,
5729
+ )
5730
+ : null) ??
5731
+ (read
5732
+ ? current(read.token) || `var(${read.token})`
5733
+ : current('--radius-element')),
3708
5734
  flags,
3709
5735
  );
3710
5736
  }
@@ -3720,18 +5746,35 @@ export function draftAnswer(ctx, env, question) {
3720
5746
  /^--shadow-/.test(st.thing) ||
3721
5747
  st.thing === 'box-shadow' ||
3722
5748
  st.thing === 'surfaces'
3723
- )
3724
- return set('box-shadow', 'none', flags);
5749
+ ) {
5750
+ // The shadow it has now, written out (the tokens it reads may be set
5751
+ // to none in the same answer).
5752
+ // Its shadow at rest; none when it has none.
5753
+ const read = C.partReads(one(p.on), 'shadow').find(
5754
+ r => /^--shadow-/.test(r.token) && r.when.some(w => !w.includes(':')),
5755
+ );
5756
+ const now =
5757
+ partValue(p.on, 'box-shadow') ??
5758
+ (read ? resolvedValue(read.token) : 'none');
5759
+ return now ? set('box-shadow', now, flags) : null;
5760
+ }
3725
5761
  if (
3726
5762
  st.thing === 'headings' ||
3727
5763
  st.thing === '--text-body-weight' ||
3728
5764
  st.thing === 'font-weight'
3729
- )
3730
- return set(
3731
- 'font-weight',
3732
- String(current('--text-body-weight') || '400'),
3733
- flags,
5765
+ ) {
5766
+ // The weight it has now: its own, else the token it reads for it.
5767
+ const read = C.partReads(one(p.on), 'font').find(r =>
5768
+ r.props.includes('font-weight'),
3734
5769
  );
5770
+ // Its own weight, else the token it reads, else the body weight it
5771
+ // inherits now.
5772
+ const now =
5773
+ partValue(p.on, 'font-weight') ??
5774
+ (read ? resolvedValue(read.token) : null) ??
5775
+ String(current('--text-body-weight') || '400');
5776
+ return set('font-weight', now, flags);
5777
+ }
3735
5778
  const group = /** @type {Record<string, string>} */ ({
3736
5779
  background: 'background',
3737
5780
  'background-color': 'background',
@@ -3741,7 +5784,14 @@ export function draftAnswer(ctx, env, question) {
3741
5784
  })[st.thing];
3742
5785
  if (group) {
3743
5786
  const want = p.when?.replace(':', '=');
5787
+ // A state kept: the token the part reads in that state, else at rest.
5788
+ const inState = p.state
5789
+ ? C.partReads(one(p.on), group).find(r =>
5790
+ r.when.some(w => w.includes(`:${p.state}`) && !/::before/.test(w)),
5791
+ )
5792
+ : null;
3744
5793
  const read =
5794
+ inState ??
3745
5795
  C.partReads(one(p.on), group).find(r =>
3746
5796
  want ? r.when.includes(want) : r.when.includes(''),
3747
5797
  ) ??
@@ -3751,6 +5801,25 @@ export function draftAnswer(ctx, env, question) {
3751
5801
  r.when.some(w => w.includes(p.when?.replace(':', '=') ?? ''))
3752
5802
  : r.when.includes(''),
3753
5803
  );
5804
+ // Never an overlay layer (a pressed or hover tint over the fill): the
5805
+ // variant's own fill, else none.
5806
+ if (read && /overlay|tint/.test(read.token) && !p.state) {
5807
+ // Only the variant's own fill (a transparent card has none).
5808
+ const wantWhen = p.when?.replace(':', '=');
5809
+ const own = wantWhen
5810
+ ? (C.partReads(one(p.on), group).find(
5811
+ r =>
5812
+ r.when.includes(wantWhen) &&
5813
+ /^--color-/.test(r.token) &&
5814
+ !/overlay|tint/.test(r.token),
5815
+ )?.token ?? null)
5816
+ : restColorRead(C.partReads(one(p.on), group));
5817
+ return set(
5818
+ st.thing === 'border' ? 'border-color' : st.thing,
5819
+ own ? `var(${own})` : 'transparent',
5820
+ flags,
5821
+ );
5822
+ }
3754
5823
  if (read)
3755
5824
  return set(
3756
5825
  st.thing === 'border' ? 'border-color' : st.thing,
@@ -3787,6 +5856,26 @@ export function draftAnswer(ctx, env, question) {
3787
5856
  const where = on
3788
5857
  ? ` on ${on}${f.when ? ` (${f.when.replace(':', ' ')})` : ''}${f.state ? ` when ${f.state}` : ''}`
3789
5858
  : ' for the whole theme';
5859
+ /**
5860
+ * What a part has now for a property in this clause's state or variant
5861
+ * ("on hover"): that scope's own setting, else the plain one.
5862
+ */
5863
+ const nowIn = (/** @type {string} */ part, /** @type {string} */ prop) => {
5864
+ if (f.state || f.when) {
5865
+ const scoped = [...env.data.settings]
5866
+ .reverse()
5867
+ .find(
5868
+ st =>
5869
+ st.thing === prop &&
5870
+ st.on === part &&
5871
+ (st.state ?? null) === (f.state ?? null) &&
5872
+ (st.when ?? null) === (f.when ?? null) &&
5873
+ !st.mode,
5874
+ );
5875
+ if (scoped) return scoped.value;
5876
+ }
5877
+ return partValue(part, prop);
5878
+ };
3790
5879
  const undo = (/** @type {string[]} */ things) =>
3791
5880
  existing(things, on).map(s => [
3792
5881
  /** @type {Step} */ ({
@@ -3800,12 +5889,98 @@ export function draftAnswer(ctx, env, question) {
3800
5889
  ]);
3801
5890
  if (on === 'focus-ring') {
3802
5891
  const ringColor = colorFor(c, 'fill');
5892
+ // "focus ring color like the links": the part after "like" (or "the
5893
+ // same as", "match") gives the ring its color; it is not a scope.
5894
+ const likeAt =
5895
+ /\b(?:like|same(?: colou?r)? as|(?:to )?match(?:es|ing)?)\s+(?:the\s+|my\s+)?/.exec(
5896
+ c.text,
5897
+ );
5898
+ /** @param {string} part */
5899
+ const partAt = part =>
5900
+ Math.min(
5901
+ ...lex.parts
5902
+ .filter(([, x]) => x.on === part)
5903
+ .map(([re]) => re.exec(c.text)?.index ?? Infinity),
5904
+ );
5905
+ const like = likeAt
5906
+ ? (c.parts
5907
+ .map(x => x.on)
5908
+ .find(
5909
+ x =>
5910
+ x &&
5911
+ x !== 'focus-ring' &&
5912
+ partAt(x) >= (likeAt.index ?? 0) + likeAt[0].length - 1,
5913
+ ) ?? null)
5914
+ : null;
3803
5915
  // "focus ring on inputs only": the ring's tokens set on that part or
3804
5916
  // group, so the other parts keep theirs.
3805
5917
  const scope =
3806
- c.parts.map(x => x.on).find(x => x && x !== 'focus-ring') ?? null;
5918
+ c.parts
5919
+ .map(x => x.on)
5920
+ .find(x => x && x !== 'focus-ring' && x !== like) ?? null;
5921
+ if (like) {
5922
+ // The color the part shows: its fill, or its text for a part with
5923
+ // no fill of its own (a link).
5924
+ // Its plain look: the main variant (primary, accent) at rest, else
5925
+ // any read at rest.
5926
+ /** @param {Array<{token: string, when: string[]}>} reads */
5927
+ const atRest = reads => {
5928
+ const rest = reads.filter(
5929
+ r =>
5930
+ /^--color-/.test(r.token) &&
5931
+ !/overlay|transparent|tint/.test(r.token) &&
5932
+ r.when.some(w => !w.includes(':')),
5933
+ );
5934
+ return (
5935
+ rest.find(r =>
5936
+ r.when.some(w => w === '' || /=(primary|accent)$/.test(w)),
5937
+ ) ??
5938
+ rest[0] ??
5939
+ null
5940
+ );
5941
+ };
5942
+ const fill = atRest(C.partReads(one(like), 'background'));
5943
+ const text = atRest(C.partReads(one(like), 'text'));
5944
+ const read = like === 'link' || !fill ? (text ?? fill) : fill;
5945
+ if (read)
5946
+ return {
5947
+ text: `the focus ring's color${scope ? ` on ${scope} only` : ''}, from ${like}: --focus-outline-color reads ${read.token} (now ${current(read.token) || 'unset'}), so it follows ${like}'s color`,
5948
+ options: [
5949
+ [
5950
+ set('--focus-outline-color', `var(${read.token})`, {
5951
+ ...modeOf(c),
5952
+ ...(scope ? {on: scope} : {}),
5953
+ }),
5954
+ ],
5955
+ ],
5956
+ };
5957
+ }
3807
5958
  const sc = scope ? {on: scope} : {};
3808
5959
  const scoped = scope ? ` on ${scope} only` : '';
5960
+ // "the focus ring lighter / darker": its color, from the color it has
5961
+ // now in each mode; never its width.
5962
+ if (
5963
+ !like &&
5964
+ !ringColor &&
5965
+ /\b(lighter|lighten|darker|darken|brighter|paler)\b/.test(c.text) &&
5966
+ !/\b(thick|thin|width|wide|bigger|smaller)\w*/.test(c.text)
5967
+ ) {
5968
+ const lighter = /\b(lighter|lighten|brighter|paler)\b/.test(c.text);
5969
+ const steps = perMode(
5970
+ '--focus-outline-color',
5971
+ '--focus-outline-color',
5972
+ sc,
5973
+ now => shiftKeepAlpha(now, lighter ? 0.2 : -0.2) ?? now,
5974
+ c,
5975
+ );
5976
+ if (steps.length)
5977
+ return {
5978
+ text: `the focus ring's color${scoped}, ${lighter ? 'lighter' : 'darker'}: --focus-outline-color${modesSaid(steps)}`,
5979
+ options: [steps],
5980
+ sequence: steps.length > 1,
5981
+ };
5982
+ }
5983
+
3809
5984
  if (ringColor && c.lengths[0] && !c.neg)
3810
5985
  return {
3811
5986
  text: `the focus ring's width and color${scoped}: --focus-outline-width and --focus-outline-color`,
@@ -3870,8 +6045,59 @@ export function draftAnswer(ctx, env, question) {
3870
6045
  if (on === 'page') {
3871
6046
  const color = colorFor(c, 'fill');
3872
6047
  // "the page background lighter": the whole-theme answer, per mode.
3873
- if (!color)
3874
- return a === 'background' && c.dir ? answerFor(c, null, a) : null;
6048
+ if (!color && a === 'background' && c.dir) return answerFor(c, null, a);
6049
+ // "page background", "a gradient on the page": the token for a color,
6050
+ // and the app shell (the part that paints the page) for a color or
6051
+ // a gradient, with example values to change.
6052
+ if (!color) {
6053
+ // Example values to change, one per mode the theme shows: a light
6054
+ // page in light mode and a dark one in dark mode, so text stays
6055
+ // readable in both.
6056
+ const gradient = /\bgradient\b/.test(c.text);
6057
+ const PAGE = {
6058
+ light: gradient
6059
+ ? 'linear-gradient(180deg, #f5f7fa, #e4ebf5)'
6060
+ : '#f5f7fa',
6061
+ dark: gradient
6062
+ ? 'linear-gradient(180deg, #14171c, #1c222b)'
6063
+ : '#14171c',
6064
+ };
6065
+ /** @type {('light' | 'dark')[]} */
6066
+ const shown =
6067
+ env.data.mode === 'dark-only'
6068
+ ? ['dark']
6069
+ : env.data.mode === 'light-only'
6070
+ ? ['light']
6071
+ : c.mode === 'light' || c.mode === 'dark'
6072
+ ? [c.mode]
6073
+ : ['light', 'dark'];
6074
+ const perMode = modal;
6075
+ /** @param {'light' | 'dark'} m */
6076
+ const flagsFor = m => (perMode ? {mode: m} : {});
6077
+ return {
6078
+ text: `the page background: background on app-shell (the page behind your parts, in every AppShell variant) for a color or a gradient; --color-background-body for the body color${perMode && shown.length > 1 ? ' (one value for each mode, so text stays readable in both)' : ''}`,
6079
+ options: [
6080
+ ...(gradient
6081
+ ? []
6082
+ : [
6083
+ shown.map(m =>
6084
+ set('--color-background-body', PAGE[m], flagsFor(m)),
6085
+ ),
6086
+ ]),
6087
+ shown.map(m =>
6088
+ set(
6089
+ perMode
6090
+ ? gradient
6091
+ ? 'background-image'
6092
+ : 'background-color'
6093
+ : 'background',
6094
+ PAGE[m],
6095
+ {on: 'app-shell', ...flagsFor(m)},
6096
+ ),
6097
+ ),
6098
+ ],
6099
+ };
6100
+ }
3875
6101
  return {
3876
6102
  text: `the page background: --color-background-body${c.mode && modal ? ` in ${c.mode} mode` : ''}`,
3877
6103
  options: [
@@ -3974,6 +6200,28 @@ export function draftAnswer(ctx, env, question) {
3974
6200
  text: 'the divider color: --color-border, on the divider only',
3975
6201
  options: [[set('--color-border', color, {on, ...modeOf(c)})]],
3976
6202
  };
6203
+ // "the divider lighter / darker": its color, never its thickness.
6204
+ if (
6205
+ !c.lengths[0] &&
6206
+ /\b(darker|lighter|darken|lighten)\b/.test(c.text) &&
6207
+ !/\b(thick|thin|width)/.test(c.text)
6208
+ ) {
6209
+ const lighter = /\blight(er|en)?\b/.test(c.text);
6210
+ const amount = colorAmount(c.text, 0.2);
6211
+ const steps = perMode(
6212
+ '--color-border',
6213
+ '--color-border',
6214
+ {on},
6215
+ now => shiftKeepAlpha(now, lighter ? amount : -amount),
6216
+ c,
6217
+ );
6218
+ if (steps.length)
6219
+ return {
6220
+ text: `a ${lighter ? 'lighter' : 'darker'} divider: --color-border, on the divider only${modesSaid(steps)}`,
6221
+ options: [steps],
6222
+ sequence: steps.length > 1,
6223
+ };
6224
+ }
3977
6225
  const len =
3978
6226
  c.lengths[0] ??
3979
6227
  (c.dir === 'less'
@@ -3997,13 +6245,13 @@ export function draftAnswer(ctx, env, question) {
3997
6245
  '--color-overlay',
3998
6246
  '--color-overlay',
3999
6247
  {},
4000
- (now, m) => stronger(now, c.dir === 'more' ? 1.5 : 0.6, m),
6248
+ now => overlayAlpha(now, c),
4001
6249
  c,
4002
6250
  )
4003
6251
  : [];
4004
6252
  if (!steps.length) return null;
4005
6253
  return {
4006
- text: `the dimmed layer behind dialogs and drawers: --color-overlay${typed ? '' : modesSaid(steps)}`,
6254
+ text: `the dimmed layer behind dialogs and drawers: --color-overlay${typed ? '' : `, its alpha only${modesSaid(steps)}`}`,
4007
6255
  options: [steps],
4008
6256
  sequence: steps.length > 1,
4009
6257
  };
@@ -4014,6 +6262,8 @@ export function draftAnswer(ctx, env, question) {
4014
6262
  a === 'background' &&
4015
6263
  on &&
4016
6264
  !f.state &&
6265
+ // A region of a part (a dialog's header) takes a fill of its own.
6266
+ !/-(header|footer|title-block)$/.test(on) &&
4017
6267
  !/\b(stripe[sd]?|striped|zebra)\b/.test(c.text) &&
4018
6268
  C.MAP[one(on)] &&
4019
6269
  !Object.keys(C.MAP[one(on)].own ?? {}).some(k =>
@@ -4043,6 +6293,48 @@ export function draftAnswer(ctx, env, question) {
4043
6293
  options: [[set('--text-body-weight', v)]],
4044
6294
  };
4045
6295
  }
6296
+ // Supporting text (small, secondary, captions, fine print): its own
6297
+ // size, weight and color tokens.
6298
+ if (p?.role === 'supporting') {
6299
+ // "the fine print smaller": a size of text is its text size.
6300
+ if (a === 'fontsize' || a === 'size') {
6301
+ const tok = '--text-supporting-size';
6302
+ const now = current(tok);
6303
+ const px = /\b(\d+(?:\.\d+)?)\s?px\b/.exec(c.text)?.[1];
6304
+ const factor =
6305
+ exactFactor(c.text) ??
6306
+ (c.dir === 'less' ? 1 / 1.125 : c.dir ? 1.125 : null);
6307
+ const v = px ? `${px}px` : factor != null ? scaled(now, factor) : null;
6308
+ return v
6309
+ ? {
6310
+ text: `the supporting text size (small and secondary text, captions): ${tok} ${v} (now ${now})`,
6311
+ options: [[set(tok, v)]],
6312
+ }
6313
+ : null;
6314
+ }
6315
+ if (a === 'weight') {
6316
+ const v =
6317
+ weightIn(c) ??
6318
+ (/\b(light(er)?|thin(ner)?)\b/.test(c.text) || c.dir === 'less'
6319
+ ? '300'
6320
+ : '600');
6321
+ return {
6322
+ text: `the supporting text weight: --text-supporting-weight (now ${current('--text-supporting-weight')})`,
6323
+ options: [[set('--text-supporting-weight', v)]],
6324
+ };
6325
+ }
6326
+ if (a === 'text') {
6327
+ const color = colorFor(c, 'text');
6328
+ if (color)
6329
+ return {
6330
+ text: 'the secondary text color: --color-text-secondary',
6331
+ options: [[set('--color-text-secondary', color, modeOf(c))]],
6332
+ };
6333
+ }
6334
+ // Anything else ("secondary text is too low contrast"): as asked of
6335
+ // the whole theme, which reads the secondary text words itself.
6336
+ return wholeTheme({...c, parts: []}, a);
6337
+ }
4046
6338
  if (p?.role && (a === 'family' || a === 'fontsize')) {
4047
6339
  if (a === 'family') {
4048
6340
  const font = fontIn(c, question);
@@ -4084,6 +6376,93 @@ export function draftAnswer(ctx, env, question) {
4084
6376
  }
4085
6377
  if (p?.role === 'body' && a !== 'leading')
4086
6378
  return wholeTheme({...c, parts: []}, a);
6379
+ // An exact amount ("half", "double", "a third", "3 times", "25%
6380
+ // bigger") of a part's scalar value: that factor of what the part has
6381
+ // now (its own setting, else the token it reads), never a step.
6382
+ {
6383
+ const typed = on && !compared.get(c) ? exactFactor(c.text) : null;
6384
+ // "a bit more transparent": a step of the opacity there now.
6385
+ const seeStep =
6386
+ typed == null && a === 'opacity' && on
6387
+ ? /\bmore (transparent|translucent|see-through)\b|\bless opaque\b/.test(
6388
+ c.text,
6389
+ )
6390
+ ? 0.8
6391
+ : /\bless (transparent|translucent)\b|\bmore opaque\b/.test(c.text)
6392
+ ? 1.25
6393
+ : null
6394
+ : null;
6395
+ const amount = typed ?? seeStep;
6396
+ const borderWidth =
6397
+ a === 'border' &&
6398
+ /\b(border[- ]width|thick(er|ness)?|thin(ner)?)\b/.test(c.text);
6399
+ const prop =
6400
+ amount == null
6401
+ ? null
6402
+ : borderWidth
6403
+ ? 'border-width'
6404
+ : a === 'fontsize'
6405
+ ? 'font-size'
6406
+ : a === 'leading'
6407
+ ? 'line-height'
6408
+ : a === 'tracking'
6409
+ ? 'letter-spacing'
6410
+ : a === 'opacity'
6411
+ ? 'opacity'
6412
+ : a === 'size' && /\b(width|wider|narrower)\b/.test(c.text)
6413
+ ? 'max-width'
6414
+ : null;
6415
+ // "50% more transparent": the opacity loses that share; "less opaque"
6416
+ // already reads as a factor below 1.
6417
+ const opacityAmount =
6418
+ prop === 'opacity' &&
6419
+ typed != null &&
6420
+ /\bmore (transparent|translucent|see-through)\b|\bless opaque\b/.test(
6421
+ c.text,
6422
+ ) &&
6423
+ typed > 1
6424
+ ? 2 - typed
6425
+ : amount;
6426
+ // Every heading level scales from its own size (the font-size case).
6427
+ if (
6428
+ prop &&
6429
+ on &&
6430
+ opacityAmount != null &&
6431
+ !(prop === 'font-size' && on === 'heading' && !p?.level)
6432
+ ) {
6433
+ const amount = opacityAmount;
6434
+ const part = /** @type {string} */ (on);
6435
+ const group = C.groupOfProp(prop);
6436
+ const read = group
6437
+ ? C.partReads(one(part), group).find(r =>
6438
+ r.props.some(x => x === prop || x.startsWith(`${prop}-`)),
6439
+ )
6440
+ : null;
6441
+ const now =
6442
+ nowIn(part, prop) ??
6443
+ (prop === 'max-width' ? nowIn(part, 'width') : null) ??
6444
+ (read?.token ? current(read.token) : null);
6445
+ const n = Number(now);
6446
+ const value =
6447
+ now == null
6448
+ ? null
6449
+ : /^\d*\.?\d+$/.test(String(now).trim())
6450
+ ? String(
6451
+ Number(
6452
+ (prop === 'opacity'
6453
+ ? Math.min(1, n * amount)
6454
+ : n * amount
6455
+ ).toFixed(3),
6456
+ ),
6457
+ )
6458
+ : scaled(String(now), amount);
6459
+ if (value)
6460
+ return {
6461
+ text: `${prop}${where}: ${value} (now ${now})`,
6462
+ options: [[set(prop, value, f)]],
6463
+ };
6464
+ }
6465
+ }
4087
6466
  switch (a) {
4088
6467
  case 'underline': {
4089
6468
  if (!on) return null;
@@ -4094,20 +6473,42 @@ export function draftAnswer(ctx, env, question) {
4094
6473
  };
4095
6474
  }
4096
6475
  case 'leading': {
6476
+ // An amount ("1.5x", "half") or a percent ("150%": of the line
6477
+ // height there now) is a factor, never a typed number.
6478
+ const pctLeading = /\b(\d{1,3}(?:\.\d+)?)(?:px)?\s?%/.exec(c.text);
6479
+ const leadFactor =
6480
+ exactFactor(c.text) ??
6481
+ (pctLeading ? Number(pctLeading[1]) / 100 : null);
4097
6482
  const n =
4098
- /\b(normal)\b/.exec(c.text)?.[1] ??
4099
- /\b(\d(?:\.\d+)?)\b(?!\s*(px|rem|em|%))/.exec(c.text)?.[1];
6483
+ leadFactor != null
6484
+ ? null
6485
+ : (/\b(normal)\b/.exec(c.text)?.[1] ??
6486
+ /(?:^|\s)(\d(?:\.\d+)?)(?![\d.]|\s*(px|rem|em|%|x\b|times\b))/.exec(
6487
+ c.text,
6488
+ )?.[1]);
4100
6489
  const tok =
4101
6490
  !on || on === 'body' || p?.role === 'body'
4102
6491
  ? '--text-body-leading'
4103
6492
  : null;
4104
- const now = tok ? current(tok) : null;
6493
+ // What it is now: the token, else the part's own line height.
6494
+ // A part with no line height of its own reads the body's.
6495
+ const now = tok
6496
+ ? current(tok)
6497
+ : on
6498
+ ? (nowIn(on, 'line-height') ??
6499
+ ('--text-body-leading' in TOKENS
6500
+ ? current('--text-body-leading')
6501
+ : null))
6502
+ : null;
6503
+ const numeric = now != null && /^\d*\.?\d+$/.test(String(now).trim());
4105
6504
  const value =
4106
6505
  n ??
4107
- (now && /^\d*\.?\d+$/.test(now)
6506
+ (numeric
4108
6507
  ? String(
4109
6508
  Number(
4110
- (Number(now) * (c.dir === 'less' ? 0.9 : 1.1)).toFixed(2),
6509
+ (
6510
+ Number(now) * (leadFactor ?? (c.dir === 'less' ? 0.9 : 1.1))
6511
+ ).toFixed(2),
4111
6512
  ),
4112
6513
  )
4113
6514
  : c.dir === 'less'
@@ -4119,17 +6520,24 @@ export function draftAnswer(ctx, env, question) {
4119
6520
  options: [[set(tok, value)]],
4120
6521
  };
4121
6522
  return {
4122
- text: `line height${where}`,
6523
+ text: `line height${where}${numeric && !n ? ` (now ${now})` : ''}`,
4123
6524
  options: [[set('line-height', value, f)]],
4124
6525
  };
4125
6526
  }
4126
6527
  case 'corners': {
4127
6528
  const tall = tallIn(c.text);
4128
6529
  const tied = radiusIn(c.text);
6530
+ // "1.5 times bigger": an amount, never a radius.
6531
+ // A percent with an amount ("50% of now", "20% bigger") is an
6532
+ // amount too: a CSS percent radius is an ellipse.
4129
6533
  const typedPx =
4130
- (tied && /^-?\d*\.?\d+$/.test(tied) ? `${tied}px` : tied) ??
4131
- c.lengths.find(l => l !== tall) ??
4132
- null;
6534
+ /\b\d*\.?\d+(px)?\s*(times|x)\s/.test(c.text) ||
6535
+ (exactFactor(c.text) != null &&
6536
+ !c.lengths.some(l => l !== tall && !/%$/.test(l)))
6537
+ ? null
6538
+ : ((tied && /^-?\d*\.?\d+$/.test(tied) ? `${tied}px` : tied) ??
6539
+ c.lengths.find(l => l !== tall) ??
6540
+ null);
4133
6541
  // A radius of 0 is square.
4134
6542
  const px = typedPx && parseFloat(typedPx) === 0 ? null : typedPx;
4135
6543
  const zero = Boolean(typedPx) && !px;
@@ -4140,21 +6548,68 @@ export function draftAnswer(ctx, env, question) {
4140
6548
  const cornerFactor =
4141
6549
  !typedPx &&
4142
6550
  on &&
4143
- !/\b(as|than)\s+(the\s+)?\w+\s*$|\bas \w+ as\b/.test(c.text)
6551
+ // "half as round" is an amount; "as round as buttons" compares.
6552
+ !compared.get(c) &&
6553
+ !/\b(as|than)\s+(the\s+)?\w+\s*$|\bas \w+ as\b/.test(
6554
+ c.text.replace(/\bas (round|rounded|sharp|curved)\s*$/, ''),
6555
+ )
4144
6556
  ? exactFactor(c.text)
4145
6557
  : null;
4146
- if (cornerFactor) {
6558
+ // A part with a radius of its own: the dial does not move it (the
6559
+ // exact setting wins), so a step of that radius, said to be one.
6560
+ const ownRadius =
6561
+ on &&
6562
+ !typedPx &&
6563
+ cornerFactor == null &&
6564
+ c.dir &&
6565
+ !c.neg &&
6566
+ // (A state rule of the dial still applies over a plain radius.)
6567
+ !f.state
6568
+ ? partValue(on, 'border-radius')
6569
+ : null;
6570
+ const ownStep = ownRadius
6571
+ ? scaledBox(ownRadius, c.dir === 'less' ? 0.8 : 1.25)
6572
+ : null;
6573
+ if (ownStep)
6574
+ return {
6575
+ text: `corners${where}: border-radius ${ownStep} (now ${ownRadius}; a step, since your exact radius there wins over the corners dial)`,
6576
+ options: [[set('border-radius', ownStep, f)]],
6577
+ };
6578
+ if (cornerFactor != null) {
4147
6579
  const part = /** @type {string} */ (on);
4148
6580
  const read = C.partReads(one(part), 'corners')[0];
6581
+ // Else the part's plain rule as built (the base theme's radius
6582
+ // for it), its tokens read in this theme.
6583
+ const rule = partRuleTokens(
6584
+ ctx.project.cwd,
6585
+ env.slug,
6586
+ env.data.like,
6587
+ one(part),
6588
+ ).get('border-radius');
6589
+ const ruleNow = rule
6590
+ ? String(rule).replace(
6591
+ /var\(\s*(--[a-z0-9-]+)\s*(?:,[^)]*)?\)/gi,
6592
+ (_, t) => current(t) || _,
6593
+ )
6594
+ : null;
4149
6595
  const now =
4150
- partValue(part, 'border-radius') ??
4151
- (read?.token ? current(read.token) : null);
6596
+ nowIn(part, 'border-radius') ??
6597
+ (read?.token ? current(read.token) : null) ??
6598
+ (ruleNow && scaled(ruleNow, 1) ? ruleNow : null);
4152
6599
  const value = now ? scaled(now, cornerFactor) : null;
4153
6600
  if (value)
4154
6601
  return {
4155
6602
  text: `corners${where}: border-radius ${value} (now ${now})`,
4156
6603
  options: [[set('border-radius', value, f)]],
4157
6604
  };
6605
+ // Nothing this can read: a step its way, said to be a step.
6606
+ if (cornerFactor !== 1)
6607
+ return {
6608
+ text: `corners${where}: corners ${cornerFactor < 1 ? 'less' : 'more'} (one step, not an exact amount: ${part} has no radius this can read; give one, such as border-radius 6px)`,
6609
+ options: [
6610
+ [set('corners', cornerFactor < 1 ? 'less' : 'more', f)],
6611
+ ],
6612
+ };
4158
6613
  }
4159
6614
  // "revert the rounded corners": take back what the theme sets.
4160
6615
  if (/\b(revert|undo|take back)\b/.test(c.text)) {
@@ -4199,6 +6654,31 @@ export function draftAnswer(ctx, env, question) {
4199
6654
  ? 'more'
4200
6655
  : 'round');
4201
6656
  if (!value) return null;
6657
+ // "double the corner radius everywhere", "double --radius-element":
6658
+ // each radius token (or the one named) from its value now, exactly.
6659
+ const wholeFactor = !on && !px ? exactFactor(c.text) : null;
6660
+ if (wholeFactor != null) {
6661
+ const named = /--radius-[a-z]+/.exec(c.text)?.[0];
6662
+ const toks = named
6663
+ ? [named]
6664
+ : [
6665
+ '--radius-inner',
6666
+ '--radius-element',
6667
+ '--radius-container',
6668
+ '--radius-page',
6669
+ ];
6670
+ const steps = toks.flatMap(tk => {
6671
+ const nowTk = current(tk);
6672
+ const next = nowTk ? scaled(nowTk, wholeFactor) : null;
6673
+ return next ? [set(tk, next)] : [];
6674
+ });
6675
+ if (steps.length)
6676
+ return {
6677
+ text: `corners for the whole theme: ${toks.map(tk => `${tk} ${current(tk)}`).join(', ')}, each ×${Number(wholeFactor.toFixed(3))}`,
6678
+ options: [steps],
6679
+ sequence: steps.length > 1,
6680
+ };
6681
+ }
4202
6682
  if (!on) {
4203
6683
  // The corners dial takes pixels: a rem or em size is converted at
4204
6684
  // 16px to the rem.
@@ -4292,6 +6772,36 @@ export function draftAnswer(ctx, env, question) {
4292
6772
  text: `no shadow${where}`,
4293
6773
  options: [...undo(['box-shadow']), [set('box-shadow', 'none', f)]],
4294
6774
  };
6775
+ // "a sharper shadow" (read as less blur), "a softer shadow" on a
6776
+ // part: the blur of the shadow it has now, scaled; offsets, spread
6777
+ // and color stay.
6778
+ if (
6779
+ on &&
6780
+ (/\b(less|more) blur\b/.test(c.text) || /\bsofter\b/.test(shadowText))
6781
+ ) {
6782
+ const sharpen = /\bless blur\b/.test(c.text);
6783
+ const tok =
6784
+ C.partReads(one(on), 'shadow').find(r => /^--shadow-/.test(r.token))
6785
+ ?.token ??
6786
+ C.partReads(one(on), 'elevation').find(r =>
6787
+ /^--shadow-/.test(r.token),
6788
+ )?.token ??
6789
+ null;
6790
+ const own = partValue(on, 'box-shadow');
6791
+ const nowShadow = own ?? (tok ? current(tok) : null);
6792
+ const factor = exactFactor(c.text) ?? (sharpen ? 0.5 : 2);
6793
+ const blurred = nowShadow ? blurScaled(nowShadow, factor) : null;
6794
+ if (blurred)
6795
+ return {
6796
+ text: `a ${sharpen ? 'sharper' : 'softer'} shadow${where}: its blur ×${Number(factor.toFixed(2))}, offsets, spread and color kept (now ${nowShadow})`,
6797
+ options: [[set('box-shadow', blurred, f)]],
6798
+ };
6799
+ if (sharpen)
6800
+ return {
6801
+ text: `${on} has no shadow now${tok || own ? ' with a blur' : ''} to make sharper`,
6802
+ options: [],
6803
+ };
6804
+ }
4295
6805
  const design = Object.keys(DESIGN).find(
4296
6806
  d =>
4297
6807
  ['bevel', 'raised', 'sunken'].includes(d) &&
@@ -4314,6 +6824,13 @@ export function draftAnswer(ctx, env, question) {
4314
6824
  const outline =
4315
6825
  /\boutlines?\b/.test(c.text) && !/\bborders?\b/.test(c.text);
4316
6826
  if (!on) {
6827
+ // "the scrollbar thinner": Core has no scrollbar part; the border
6828
+ // width is not it.
6829
+ if (/\bscroll ?bars?\b/.test(c.text))
6830
+ return {
6831
+ text: 'Core has no scrollbar part, so the editor cannot change its width or color; scrollbar-width and scrollbar-color need your own CSS',
6832
+ options: [],
6833
+ };
4317
6834
  const color = colorFor(c, 'fill');
4318
6835
  if (c.neg)
4319
6836
  return {
@@ -4353,6 +6870,16 @@ export function draftAnswer(ctx, env, question) {
4353
6870
  }
4354
6871
  : null;
4355
6872
  }
6873
+ // An amount ("double", "half") of the width there now.
6874
+ const bwFactor = c.lengths[0] ? null : exactFactor(c.text);
6875
+ const bwNow = current('--border-width');
6876
+ const bwExact =
6877
+ bwFactor != null && bwNow ? scaled(bwNow, bwFactor) : null;
6878
+ if (bwExact)
6879
+ return {
6880
+ text: `the border width of the whole theme: --border-width ${bwExact} (now ${bwNow})`,
6881
+ options: [[set('--border-width', bwExact)]],
6882
+ };
4356
6883
  if (c.lengths[0] || c.dir)
4357
6884
  return {
4358
6885
  text: 'the border width of the whole theme: --border-width',
@@ -4385,6 +6912,13 @@ export function draftAnswer(ctx, env, question) {
4385
6912
  }
4386
6913
  : null;
4387
6914
  }
6915
+ // "remove the top border", "no border on the right side": that side.
6916
+ const borderSide = /\b(top|bottom|left|right)\b/.exec(c.text)?.[1];
6917
+ if (c.neg && borderSide && !outline)
6918
+ return {
6919
+ text: `no ${borderSide} border${where}: border-${borderSide} none (the other sides keep theirs)`,
6920
+ options: [[set(`border-${borderSide}`, 'none', f)]],
6921
+ };
4388
6922
  if (c.neg)
4389
6923
  return {
4390
6924
  text: `no ${outline ? 'outline' : 'border'}${where}`,
@@ -4401,6 +6935,48 @@ export function draftAnswer(ctx, env, question) {
4401
6935
  ],
4402
6936
  };
4403
6937
  const color = colorFor(c, 'fill');
6938
+ // "the card border darker", "input borders a bit lighter": the
6939
+ // border's color, from the one the part shows now, never its width.
6940
+ if (
6941
+ !color &&
6942
+ !c.lengths[0] &&
6943
+ /\b(darker|lighter|darken|lighten)\b/.test(c.text) &&
6944
+ !/\b(thick|thin|width|wider)/.test(c.text)
6945
+ ) {
6946
+ const lighter = /\blight(er|en)?\b/.test(c.text);
6947
+ const amount = colorAmount(c.text, 0.2);
6948
+ const ownBorder = partValue(on, 'border-color');
6949
+ if (ownBorder && parseColor(ownBorder)) {
6950
+ const v = shiftKeepAlpha(ownBorder, lighter ? amount : -amount);
6951
+ if (v)
6952
+ return {
6953
+ text: `the border color${where}: ${v} (now ${ownBorder})`,
6954
+ options: [[set('border-color', v, f)]],
6955
+ };
6956
+ }
6957
+ const read =
6958
+ restColorRead(C.partReads(one(on), 'border'), f.when) ??
6959
+ '--color-border';
6960
+ // The token the border reads, on this part only: one value per
6961
+ // mode holds for every variant that reads it.
6962
+ const steps = perMode(
6963
+ read,
6964
+ read,
6965
+ {
6966
+ on,
6967
+ ...(f.state ? {state: f.state} : {}),
6968
+ ...(f.when ? {when: f.when} : {}),
6969
+ },
6970
+ now => shiftKeepAlpha(now, lighter ? amount : -amount),
6971
+ c,
6972
+ );
6973
+ if (steps.length)
6974
+ return {
6975
+ text: `a ${lighter ? 'lighter' : 'darker'} border color${where}: ${read}, on ${on} only${modesSaid(steps)}`,
6976
+ options: [steps],
6977
+ sequence: steps.length > 1,
6978
+ };
6979
+ }
4404
6980
  const width =
4405
6981
  c.lengths[0] ??
4406
6982
  (/\b(thick(er)?)\b/.test(c.text) || c.dir === 'more'
@@ -4408,7 +6984,13 @@ export function draftAnswer(ctx, env, question) {
4408
6984
  : /\bthin(ner)?\b/.test(c.text) || c.dir === 'less'
4409
6985
  ? '1px'
4410
6986
  : null);
4411
- const style = /\b(dashed|dotted|double)\b/.exec(c.text)?.[1] ?? null;
6987
+ // "double the border width" is an amount, not the double style.
6988
+ const style =
6989
+ /\b(dashed|dotted)\b/.exec(c.text)?.[1] ??
6990
+ (/\bdouble\b/.test(c.text) &&
6991
+ !/\bdouble (the |its |their )?(border|width|thickness)\b/.test(c.text)
6992
+ ? 'double'
6993
+ : null);
4412
6994
  const side = /\b(top|bottom|left|right)\b/.exec(c.text)?.[1];
4413
6995
  const prop = side ? `border-${side}` : 'border';
4414
6996
  const own = C.MAP[one(on)]?.own ?? {};
@@ -4445,12 +7027,23 @@ export function draftAnswer(ctx, env, question) {
4445
7027
  };
4446
7028
  }
4447
7029
  case 'spacing': {
4448
- const px = c.lengths[0];
7030
+ // A percent is an amount of the padding there now ("50% bigger",
7031
+ // "150%"), never a CSS percent padding (half the container's width).
7032
+ const pctLength =
7033
+ c.lengths.find(l => /%$/.test(l)) ??
7034
+ /\b(\d{1,3}(?:\.\d+)?)\s?%/.exec(c.text)?.[0] ??
7035
+ null;
7036
+ // "3 times bigger": the 3 is an amount, not a length.
7037
+ const px = exactFactor(c.text)
7038
+ ? null
7039
+ : c.lengths.find(l => !/%$/.test(l));
4449
7040
  const gap = /\b(gaps?|between)\b/.test(c.text);
4450
7041
  const value =
4451
7042
  /\b(dense|compact)\b/.test(c.text) && !c.dir
4452
7043
  ? 'compact'
4453
- : c.neg && /\b(padding|space|gap|margin)\b/.test(c.text)
7044
+ : (c.neg || /\b(zero|no|none|without)\b/.test(c.text)) &&
7045
+ /\b(padding|spac(e|es|ing)|gaps?|margins?)\b/.test(c.text) &&
7046
+ !/\bno (more|less)\b/.test(c.text)
4454
7047
  ? null
4455
7048
  : /\b(cramped|crowded|airy|spacious|roomy)\b/.test(c.text) ||
4456
7049
  c.dir === 'more'
@@ -4461,28 +7054,215 @@ export function draftAnswer(ctx, env, question) {
4461
7054
  if (!on)
4462
7055
  return value
4463
7056
  ? {
4464
- text: 'room in the whole theme: the spacing dial (padding, gaps and control heights together)',
7057
+ text: `room in the whole theme: the spacing dial (padding, gaps and control heights together)${exactFactor(c.text) != null ? '; one step, not the exact amount asked: give a value for a token (--spacing-4 24px) for that' : ''}`,
4465
7058
  options: [[set('spacing', value)]],
4466
7059
  }
4467
7060
  : null;
4468
- if (px) {
4469
- const box = boxIn(c.text) ?? px;
7061
+ // "24x24px", "24 x 16px": a size, width by height, is an exact
7062
+ // value: padding block (the height) then inline (the width).
7063
+ const dims =
7064
+ /\b(\d*\.?\d+)(px|rem|em)?\s*[x\u00d7]\s*(\d*\.?\d+)(px|rem|em)\b/.exec(
7065
+ c.text,
7066
+ );
7067
+ if (dims) {
7068
+ const unit = dims[4];
7069
+ const w = `${Number(dims[1])}${dims[2] ?? unit}`;
7070
+ const h = `${Number(dims[3])}${unit}`;
7071
+ const box = w === h ? w : `${h} ${w}`;
4470
7072
  return {
4471
- text: `${gap ? 'the gap' : 'padding'}${where}: ${box}`,
7073
+ text: `${gap ? 'the gap' : 'padding'}${where}: ${box}${w === h ? '' : ` (${h} top and bottom, ${w} left and right)`}`,
4472
7074
  options: [[set(gap ? 'gap' : 'padding', box, f)]],
4473
7075
  };
4474
7076
  }
4475
7077
  // "double the padding on cards": an exact amount of the padding the
4476
7078
  // part has now, when the theme sets one; else the dial's step, and
4477
7079
  // the answer says the amount is a step.
4478
- const padFactor = exactFactor(c.text);
7080
+ const padFactor =
7081
+ exactFactor(c.text) ??
7082
+ (pctLength && Number.parseFloat(pctLength) > 0
7083
+ ? Number.parseFloat(pctLength) / 100
7084
+ : null);
7085
+ /**
7086
+ * The padding (or gap) a part has now: its own setting, else the
7087
+ * token it reads, resolved in this theme.
7088
+ * @param {string} part
7089
+ */
7090
+ const padNow = part => {
7091
+ const own = nowIn(part, gap ? 'gap' : 'padding');
7092
+ if (own) return own;
7093
+ // Own side settings (padding-inline 20px) on top of what the part
7094
+ // has for the rest: one box, each side as it is now.
7095
+ if (!gap) {
7096
+ const block = nowIn(part, 'padding-block');
7097
+ const inline = nowIn(part, 'padding-inline');
7098
+ const sideOf = (/** @type {string} */ k) =>
7099
+ nowIn(part, `padding-${k}`);
7100
+ const sides = ['top', 'right', 'bottom', 'left'].map(sideOf);
7101
+ if (block || inline || sides.some(Boolean)) {
7102
+ const rest = padNow0(part);
7103
+ const restSides = rest
7104
+ ? (() => {
7105
+ const v = String(rest).trim().split(/\s+/);
7106
+ return [
7107
+ v[0],
7108
+ v[1] ?? v[0],
7109
+ v[2] ?? v[0],
7110
+ v[3] ?? v[1] ?? v[0],
7111
+ ];
7112
+ })()
7113
+ : null;
7114
+ if (restSides) {
7115
+ const [bt, bi] = [block, inline].map(x =>
7116
+ x ? String(x).trim().split(/\s+/) : null,
7117
+ );
7118
+ const box = [
7119
+ sides[0] ?? bt?.[0] ?? restSides[0],
7120
+ sides[1] ?? bi?.[1] ?? bi?.[0] ?? restSides[1],
7121
+ sides[2] ?? bt?.[1] ?? bt?.[0] ?? restSides[2],
7122
+ sides[3] ?? bi?.[0] ?? restSides[3],
7123
+ ];
7124
+ const out =
7125
+ box[0] === box[2] && box[1] === box[3]
7126
+ ? box[0] === box[1]
7127
+ ? box[0]
7128
+ : `${box[0]} ${box[1]}`
7129
+ : box.join(' ');
7130
+ return out;
7131
+ }
7132
+ }
7133
+ }
7134
+ return padNow0(part);
7135
+ };
7136
+ /** padNow without the part's own setting. @param {string} part */
7137
+ const padNow0 = part => {
7138
+ // The part's plain rule in the theme as built (the base theme's
7139
+ // card padding), its tokens read in this theme.
7140
+ const ruleMap = partRuleTokens(
7141
+ ctx.project.cwd,
7142
+ env.slug,
7143
+ env.data.like,
7144
+ one(part),
7145
+ );
7146
+ const rule = ruleMap.get(gap ? 'gap' : 'padding');
7147
+ /** A rule value with its tokens read in this theme. @param {unknown} x */
7148
+ const inTheme = x =>
7149
+ String(x).replace(
7150
+ /var\(\s*(--[a-z0-9-]+)\s*(?:,[^)]*)?\)/gi,
7151
+ (m, t) => current(t) || m,
7152
+ );
7153
+ // The base theme's own block and inline padding on the part (butter
7154
+ // writes those, not the shorthand), each side as built.
7155
+ const ruleBlock = gap ? null : ruleMap.get('padding-block');
7156
+ const ruleInline = gap ? null : ruleMap.get('padding-inline');
7157
+ if (rule) {
7158
+ const resolved = String(rule).replace(
7159
+ /var\(\s*(--[a-z0-9-]+)\s*(?:,[^)]*)?\)/gi,
7160
+ (_, t) => current(t) || _,
7161
+ );
7162
+ if (scaledBox(resolved, 1)) return resolved;
7163
+ }
7164
+ const reads = C.partReads(one(part), 'spacing').filter(r =>
7165
+ r.props.some(p => (gap ? /gap/ : /^padding/).test(p)),
7166
+ );
7167
+ // Each side from the token Core reads for it (a button's block and
7168
+ // inline padding differ; a badge has no block padding): one box.
7169
+ if (!gap) {
7170
+ /** @param {RegExp} re */
7171
+ const sideTok = re =>
7172
+ reads.find(r => r.props.some(x => re.test(x)))?.token ?? null;
7173
+ const toks = [
7174
+ sideTok(/^padding-(block(-start)?|top)$/),
7175
+ sideTok(/^padding-(inline(-end)?|right)$/),
7176
+ sideTok(/^padding-(block(-end)?|bottom)$/),
7177
+ sideTok(/^padding-(inline(-start)?|left)$/),
7178
+ ];
7179
+ if (toks.some(Boolean) || ruleBlock || ruleInline) {
7180
+ const [bw, iw] = [ruleBlock, ruleInline].map(x =>
7181
+ x ? splitTop(inTheme(x).trim(), ' ') : null,
7182
+ );
7183
+ const box = toks.map(tk => (tk ? current(tk) || '0px' : '0px'));
7184
+ if (bw) [box[0], box[2]] = [bw[0], bw[1] ?? bw[0]];
7185
+ if (iw) [box[3], box[1]] = [iw[0], iw[1] ?? iw[0]];
7186
+ return box[0] === box[2] && box[1] === box[3]
7187
+ ? box[0] === box[1]
7188
+ ? box[0]
7189
+ : `${box[0]} ${box[1]}`
7190
+ : box.join(' ');
7191
+ }
7192
+ }
7193
+ const read =
7194
+ reads.find(r => /^--spacing-/.test(r.token)) ?? reads[0] ?? null;
7195
+ return read?.token ? current(read.token) : null;
7196
+ };
7197
+ // "padding top 12px", "more padding on the left", "horizontal
7198
+ // padding 20px": only those sides.
7199
+ const sideWord = gap ? null : sideIn(c);
7200
+ if (sideWord) {
7201
+ const sideProp = /^(left|right|top|bottom)$/.test(sideWord)
7202
+ ? `padding-${sideWord}`
7203
+ : /^(vertical|block)/.test(sideWord)
7204
+ ? 'padding-block'
7205
+ : 'padding-inline';
7206
+ // Each side's own value now: the side setting, else that side of
7207
+ // the box the part has now (a button is 8px 16px: its left is 16px).
7208
+ const box = String(padNow(on) ?? '')
7209
+ .trim()
7210
+ .split(/\s+/)
7211
+ .filter(Boolean);
7212
+ const sides4 = box.length
7213
+ ? [
7214
+ box[0],
7215
+ box[1] ?? box[0],
7216
+ box[2] ?? box[0],
7217
+ box[3] ?? box[1] ?? box[0],
7218
+ ]
7219
+ : null;
7220
+ const boxSide = sides4
7221
+ ? sideProp === 'padding-top'
7222
+ ? sides4[0]
7223
+ : sideProp === 'padding-right'
7224
+ ? sides4[1]
7225
+ : sideProp === 'padding-bottom'
7226
+ ? sides4[2]
7227
+ : sideProp === 'padding-left'
7228
+ ? sides4[3]
7229
+ : sideProp === 'padding-block'
7230
+ ? sides4[0] === sides4[2]
7231
+ ? sides4[0]
7232
+ : `${sides4[0]} ${sides4[2]}`
7233
+ : sides4[3] === sides4[1]
7234
+ ? sides4[1]
7235
+ : `${sides4[3]} ${sides4[1]}`
7236
+ : null;
7237
+ const nowSide = partValue(on, sideProp) ?? boxSide ?? null;
7238
+ // No, zero or none on a side: that side 0.
7239
+ if (!value && !px && !exactFactor(c.text))
7240
+ return {
7241
+ text: `no padding on ${sideWord === 'sides' ? 'the sides' : `the ${sideWord}`}${where}`,
7242
+ options: [[set(sideProp, '0px', f)]],
7243
+ };
7244
+ const factor = exactFactor(c.text) ?? (value === 'less' ? 0.8 : 1.25);
7245
+ const sideValue = px ?? (nowSide ? scaledBox(nowSide, factor) : null);
7246
+ if (sideValue)
7247
+ return {
7248
+ text: `padding on ${sideWord === 'sides' ? 'the sides' : `the ${sideWord}`}${where}: ${sideProp} ${sideValue}${!px && nowSide ? ` (now ${nowSide})` : ''}`,
7249
+ options: [[set(sideProp, sideValue, f)]],
7250
+ };
7251
+ }
7252
+ if (px) {
7253
+ const box = boxIn(c.text) ?? px;
7254
+ return {
7255
+ text: `${gap ? 'the gap' : 'padding'}${where}: ${box}`,
7256
+ options: [[set(gap ? 'gap' : 'padding', box, f)]],
7257
+ };
7258
+ }
4479
7259
  // A comparison ("twice the padding of buttons"): the amount is of
4480
7260
  // the other part's padding, when the theme sets one; else a step,
4481
7261
  // and the answer says so.
4482
7262
  const versus = compared.get(c) ?? null;
4483
- if (padFactor && versus) {
4484
- const now = partValue(versus, gap ? 'gap' : 'padding');
4485
- const exact = now ? scaled(now, padFactor) : null;
7263
+ if (padFactor != null && versus) {
7264
+ const now = padNow(versus);
7265
+ const exact = now ? scaledBox(now, padFactor) : null;
4486
7266
  return exact
4487
7267
  ? {
4488
7268
  text: `${gap ? 'the gap' : 'padding'}${where}: ${exact} (${versus} has ${now})`,
@@ -4493,30 +7273,72 @@ export function draftAnswer(ctx, env, question) {
4493
7273
  options: [[set('spacing', value ?? 'more', f)]],
4494
7274
  };
4495
7275
  }
4496
- if (padFactor) {
4497
- const now = partValue(on, gap ? 'gap' : 'padding');
4498
- const value = now ? scaled(now, padFactor) : null;
7276
+ if (padFactor != null) {
7277
+ const now = padNow(on);
7278
+ const value = now ? scaledBox(now, padFactor) : null;
4499
7279
  if (value)
4500
7280
  return {
4501
7281
  text: `${gap ? 'the gap' : 'padding'}${where}: ${value} (now ${now})`,
4502
7282
  options: [[set(gap ? 'gap' : 'padding', value, f)]],
4503
7283
  };
4504
7284
  }
7285
+ // No amount, and the part has an exact padding of its own: the dial
7286
+ // does not move it (an exact setting wins), so a step of that
7287
+ // padding, said to be a step.
7288
+ const exactPad = !gap && value ? partValue(on, 'padding') : null;
7289
+ const stepped = exactPad
7290
+ ? scaledBox(exactPad, value === 'less' ? 0.8 : 1.25)
7291
+ : null;
7292
+ if (stepped)
7293
+ return {
7294
+ text: `padding${where}: ${stepped} (now ${exactPad}; a step, since your exact padding there wins over the spacing dial: give an amount, such as double or 24px, for an exact one)`,
7295
+ options: [[set('padding', stepped, f)]],
7296
+ };
7297
+ // An amount with nothing there now to take it of: a step its way,
7298
+ // said to be a step.
7299
+ if (padFactor && padFactor !== 1)
7300
+ return {
7301
+ text: `room inside ${on}: spacing ${padFactor < 1 ? 'less' : 'more'} (one step, not an exact amount: ${on} has no ${gap ? 'gap' : 'padding'} this can read; give a value, such as 8px, for one)`,
7302
+ options: [[set('spacing', padFactor < 1 ? 'less' : 'more', {on})]],
7303
+ };
4505
7304
  if (!value)
4506
7305
  return {
4507
- text: `no padding${where}`,
4508
- options: [[set('padding', '0px', f)]],
7306
+ text: `no ${gap ? 'gap' : 'padding'}${where}`,
7307
+ options: [[set(gap ? 'gap' : 'padding', '0px', f)]],
4509
7308
  };
7309
+ // A step in one state or variant ("on hover") stays there.
7310
+ const stepFlags = {
7311
+ on,
7312
+ ...(f.state ? {state: f.state} : {}),
7313
+ ...(f.when ? {when: f.when} : {}),
7314
+ };
7315
+ const stepOk = env.check([set('spacing', value, stepFlags)]).ok;
7316
+ // The dial takes no state: a step of the padding there now, in that
7317
+ // state, said to be a step.
7318
+ if (!stepOk && (f.state || f.when)) {
7319
+ const nowPad = padNow(on);
7320
+ const stepped = nowPad
7321
+ ? scaledBox(nowPad, value === 'less' ? 0.8 : 1.25)
7322
+ : null;
7323
+ if (stepped)
7324
+ return {
7325
+ text: `${gap ? 'the gap' : 'padding'}${where}: ${stepped} (now ${nowPad}; a step: give an amount, such as double or 24px, for an exact one)`,
7326
+ options: [[set(gap ? 'gap' : 'padding', stepped, f)]],
7327
+ };
7328
+ }
4510
7329
  return {
4511
- text: `room inside ${on}: spacing ${value} (padding, gaps and heights inside it)`,
4512
- options: [[set('spacing', value, {on})]],
7330
+ text: `room inside ${on}: spacing ${value} (padding, gaps and heights inside it; one step${padFactor ? ', not an exact amount: give a value, such as 24px, for one' : ''})`,
7331
+ options: [[set('spacing', value, stepOk ? stepFlags : {on})]],
4513
7332
  };
4514
7333
  }
4515
7334
  case 'tracking': {
4516
7335
  const tight =
4517
7336
  c.dir === 'less' ||
4518
7337
  /\b(tight(en|er)?|narrow(er)?|less|condensed)\b/.test(c.text);
4519
- const typedTrack = c.lengths.find(l => /em$/.test(l)) ?? c.lengths[0];
7338
+ const typedTrack =
7339
+ c.lengths.find(l => /em$/.test(l)) ??
7340
+ c.lengths[0] ??
7341
+ (/(?:^|\s)0(?![.\d%])/.test(c.text) ? '0' : undefined);
4520
7342
  const value = typedTrack ?? (tight ? '-0.02em' : '0.04em');
4521
7343
  if (!on || on === 'heading')
4522
7344
  return {
@@ -4614,7 +7436,20 @@ export function draftAnswer(ctx, env, question) {
4614
7436
  const family = FONTS[font]?.[0] ?? OPEN_FONTS[font]?.family ?? font;
4615
7437
  return {
4616
7438
  text: `the font${where}: font-family`,
4617
- options: [[set('font-family', family, f)]],
7439
+ options: [
7440
+ [
7441
+ set(
7442
+ 'font-family',
7443
+ // A stack given with the family ("Inter, sans-serif") whole.
7444
+ (g => (g ? `${family}, ${g[1]}` : family))(
7445
+ /,\s*(serif|sans-serif|monospace|system-ui|cursive)\b/.exec(
7446
+ c.text,
7447
+ ),
7448
+ ),
7449
+ f,
7450
+ ),
7451
+ ],
7452
+ ],
4618
7453
  };
4619
7454
  }
4620
7455
  case 'fontsize': {
@@ -4626,7 +7461,53 @@ export function draftAnswer(ctx, env, question) {
4626
7461
  };
4627
7462
  const px = c.lengths[0];
4628
7463
  const f2 = /\bmuch\b/.test(c.text) ? 1.5 : 1.25;
4629
- const factor = c.dir === 'less' ? 1 / f2 : f2;
7464
+ // An exact amount ("double", "half") of the size there now.
7465
+ const factor = exactFactor(c.text) ?? (c.dir === 'less' ? 1 / f2 : f2);
7466
+ // "headings 20% bigger", "headings twice as big": every heading
7467
+ // level from its own size, so the steps between them stay.
7468
+ // "headings 2-4 bigger", "h2 to h4": those levels only.
7469
+ const range =
7470
+ /\b(?:h|headings?\s*(?:levels?\s*)?)?([1-6])\s*(?:-|–|to|through)\s*h?([1-6])\b/.exec(
7471
+ c.text,
7472
+ );
7473
+ if (on === 'heading' && (!p?.level || range) && !f.state && !f.when) {
7474
+ const pct = /(\d{1,3}(?:\.\d+)?)\s?%/.exec(c.text);
7475
+ const amount =
7476
+ exactFactor(c.text) ??
7477
+ (pct
7478
+ ? c.dir === 'less'
7479
+ ? 1 - Number(pct[1]) / 100
7480
+ : 1 + Number(pct[1]) / 100
7481
+ : range && c.dir
7482
+ ? c.dir === 'less'
7483
+ ? 1 / f2
7484
+ : f2
7485
+ : null);
7486
+ if (amount && !(px && !pct && !exactFactor(c.text))) {
7487
+ const levels = Object.keys(TOKENS)
7488
+ .filter(t => /^--text-heading-\d-size$/.test(t))
7489
+ .filter(t => {
7490
+ if (!range) return true;
7491
+ const n = Number(/(\d)/.exec(t)?.[1]);
7492
+ const [lo, hi] = [Number(range[1]), Number(range[2])].sort();
7493
+ return n >= lo && n <= hi;
7494
+ })
7495
+ .sort();
7496
+ const steps = levels
7497
+ .map(t => {
7498
+ const now = resolvedValue(t);
7499
+ const v = now ? scaledBox(now, amount) : null;
7500
+ return v ? set(t, v) : null;
7501
+ })
7502
+ .filter(st => st != null);
7503
+ if (steps.length)
7504
+ return {
7505
+ text: `every heading level ${amount > 1 ? 'bigger' : 'smaller'} from its own size (x${Number(amount.toFixed(3))}): ${levels.join(', ')}`,
7506
+ options: [/** @type {Step[]} */ (steps)],
7507
+ sequence: true,
7508
+ };
7509
+ }
7510
+ }
4630
7511
  // An exact --font-size-base wins over the text-size dial, so the
4631
7512
  // dial would change nothing there: step that token instead.
4632
7513
  const pinned = on
@@ -4672,7 +7553,7 @@ export function draftAnswer(ctx, env, question) {
4672
7553
  }
4673
7554
  if (!on)
4674
7555
  return {
4675
- text: 'the base text size: text-size (every heading scales from it)',
7556
+ text: `the base text size: text-size (every heading scales from it)${!px && exactFactor(c.text) != null ? '; one step, not the exact amount asked: give a size (text-size 18) for that' : ''}`,
4676
7557
  options: [
4677
7558
  [
4678
7559
  set(
@@ -4789,6 +7670,7 @@ export function draftAnswer(ctx, env, question) {
4789
7670
  const tok =
4790
7671
  C.partReads(one(on), 'background').find(r => r.when.includes(''))
4791
7672
  ?.token ??
7673
+ C.partReads(one(on), 'background')[0]?.token ??
4792
7674
  (FAMILIES.containers.includes(one(on))
4793
7675
  ? '--color-background-card'
4794
7676
  : null);
@@ -4831,6 +7713,35 @@ export function draftAnswer(ctx, env, question) {
4831
7713
  text: `opacity${where}: ${typedOpacity}`,
4832
7714
  options: [[set('opacity', typedOpacity, f)]],
4833
7715
  };
7716
+ // "more opaque", "less see-through": opacity up from what the part
7717
+ // has now, never down.
7718
+ if (
7719
+ on &&
7720
+ /\b(more opaque|less (?:transparent|see[- ]?through|translucent)|opaquer)\b/.test(
7721
+ c.text,
7722
+ )
7723
+ ) {
7724
+ const nowOp = Number(partValue(on, 'opacity') ?? 1);
7725
+ return nowOp >= 1 || Number.isNaN(nowOp)
7726
+ ? {
7727
+ text: `${on} is fully opaque now (opacity 1): there is no more opaque to go`,
7728
+ options: [],
7729
+ }
7730
+ : {
7731
+ text: `more opaque${where}: opacity ${Number(Math.min(1, nowOp + (1 - nowOp) / 2).toFixed(2))} (now ${nowOp})`,
7732
+ options: [
7733
+ [
7734
+ set(
7735
+ 'opacity',
7736
+ String(
7737
+ Number(Math.min(1, nowOp + (1 - nowOp) / 2).toFixed(2)),
7738
+ ),
7739
+ f,
7740
+ ),
7741
+ ],
7742
+ ],
7743
+ };
7744
+ }
4834
7745
  const pct = /\b(\d{1,3})%/.exec(withoutFunctions(c.text))?.[1];
4835
7746
  if (pct && on)
4836
7747
  return Number(pct) > 100
@@ -4892,7 +7803,11 @@ export function draftAnswer(ctx, env, question) {
4892
7803
  tallIn(c.text) ??
4893
7804
  (/\b(taller|shorter|height|bigger|larger|tap targets?|touch targets?)\b/.test(
4894
7805
  c.text,
4895
- ) && !/\b(wider|narrower|width)\b/.test(c.text)
7806
+ ) &&
7807
+ !(
7808
+ /\b(wider|narrower|width)\b/.test(c.text) &&
7809
+ !/\bborder[- ]width\b/.test(c.text)
7810
+ )
4896
7811
  ? c.lengths[0]
4897
7812
  : null);
4898
7813
  if (tall)
@@ -4914,7 +7829,83 @@ export function draftAnswer(ctx, env, question) {
4914
7829
  ],
4915
7830
  ],
4916
7831
  };
4917
- if (/\b(wider|narrower|width)\b/.test(c.text)) {
7832
+ if (
7833
+ /\b(wider|narrower|width|wide)\b/.test(c.text) &&
7834
+ !/\bborder[- ]width\b/.test(c.text)
7835
+ ) {
7836
+ // "the sidebar wider", "20% wider": from the width the part has
7837
+ // now (its own setting, else its rule in the base theme), never a
7838
+ // made-up width.
7839
+ if (!c.lengths[0]) {
7840
+ const rule = partRuleTokens(
7841
+ ctx.project.cwd,
7842
+ env.slug,
7843
+ env.data.like,
7844
+ one(on),
7845
+ );
7846
+ /** @param {string} k */
7847
+ const widthNow = k =>
7848
+ partValue(on, k) ??
7849
+ rule.get(k) ??
7850
+ rule.get(
7851
+ k === 'width'
7852
+ ? 'inline-size'
7853
+ : k === 'max-width'
7854
+ ? 'max-inline-size'
7855
+ : 'min-inline-size',
7856
+ ) ??
7857
+ null;
7858
+ const wProp = ['width', 'max-width', 'min-width'].find(
7859
+ k =>
7860
+ widthNow(k) != null &&
7861
+ scaled(
7862
+ String(widthNow(k))
7863
+ .replace(
7864
+ /var\(\s*(--[a-z0-9-]+)\s*(?:,[^)]*)?\)/gi,
7865
+ (m, t) => current(t) || m,
7866
+ )
7867
+ .trim(),
7868
+ 1,
7869
+ ),
7870
+ );
7871
+ const wNow = wProp ? String(widthNow(wProp)) : null;
7872
+ const wFactor =
7873
+ exactFactor(c.text) ??
7874
+ (/\bnarrower\b/.test(c.text) || c.dir === 'less'
7875
+ ? /\b(a (bit|little|touch)|slightly)\b/.test(c.text)
7876
+ ? 0.9
7877
+ : 0.8
7878
+ : /\b(a (bit|little|touch)|slightly)\b/.test(c.text)
7879
+ ? 1.1
7880
+ : 1.25);
7881
+ const resolved = wNow
7882
+ ? wNow.replace(
7883
+ /var\(\s*(--[a-z0-9-]+)\s*(?:,[^)]*)?\)/gi,
7884
+ (m, t) => current(t) || m,
7885
+ )
7886
+ : null;
7887
+ const wNew = resolved ? scaled(resolved.trim(), wFactor) : null;
7888
+ if (wProp && wNew)
7889
+ return {
7890
+ text: `the width${where}: ${wProp} ${wNew} (now ${resolved})`,
7891
+ options: [[set(wProp, wNew, f)]],
7892
+ };
7893
+ if (
7894
+ /\b(wider|narrower)\b/.test(c.text) ||
7895
+ exactFactor(c.text) != null
7896
+ )
7897
+ return {
7898
+ text: `${on} has no width of its own to scale (it takes the width its content and container give it); give a width, such as max-width 480px`,
7899
+ options: [],
7900
+ };
7901
+ }
7902
+ // An amount ("20% wider", "twice as wide") with no width there to
7903
+ // take it of: said so, never a made-up cap.
7904
+ if (!c.lengths[0] && exactFactor(c.text) != null)
7905
+ return {
7906
+ text: `${on} has no width of its own to scale (it takes the width its content and container give it); give a width, such as max-width 480px`,
7907
+ options: [],
7908
+ };
4918
7909
  const w =
4919
7910
  c.lengths[0] ??
4920
7911
  (/\bnarrower\b/.test(c.text) || c.dir === 'less'
@@ -5083,13 +8074,77 @@ export function draftAnswer(ctx, env, question) {
5083
8074
  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` : ''}`,
5084
8075
  options: [[set('--color-text-accent', color, modeOf(c))]],
5085
8076
  };
8077
+ // "card text lighter", "a bit darker": from the text color the part
8078
+ // shows now (its own, else the token it reads at rest).
8079
+ if (!color && c.dir && /\b(light|dark)(er)?\b/.test(c.text)) {
8080
+ const lighter = /\blight(er)?\b/.test(c.text);
8081
+ const amount = colorAmount(c.text, 0.2);
8082
+ const own = partValue(on, 'color');
8083
+ if (own && parseColor(own)) {
8084
+ const v = shiftKeepAlpha(own, lighter ? amount : -amount);
8085
+ if (v)
8086
+ return {
8087
+ text: `text color${where}: ${v} (now ${own})`,
8088
+ options: [[set('color', v, f)]],
8089
+ };
8090
+ }
8091
+ // A link's color comes from its color prop: the accent text token
8092
+ // it reads, made lighter or darker (it also colors other accent
8093
+ // text).
8094
+ if (on === 'link') {
8095
+ const steps = perMode(
8096
+ '--color-text-accent',
8097
+ '--color-text-accent',
8098
+ f.state ? {on, state: f.state} : {},
8099
+ now => shiftKeepAlpha(now, lighter ? amount : -amount),
8100
+ c,
8101
+ );
8102
+ if (steps.length)
8103
+ return {
8104
+ text: `${lighter ? 'lighter' : 'darker'} links: --color-text-accent, the token a link reads (it also colors other accent text)${modesSaid(steps)}`,
8105
+ options: [steps],
8106
+ sequence: steps.length > 1,
8107
+ };
8108
+ }
8109
+ // A part that takes its color from a prop (a heading): the text
8110
+ // token on that part, as "red h1" sets it.
8111
+ const viaToken = !env.check([set('color', '#808080', f)]).ok;
8112
+ // A part with no text color of its own shows the main text color.
8113
+ const read =
8114
+ restColorRead(C.partReads(one(on), 'text'), f.when) ??
8115
+ '--color-text-primary';
8116
+ if (read) {
8117
+ const steps = perMode(
8118
+ read,
8119
+ viaToken ? '--color-text-primary' : 'color',
8120
+ viaToken ? {...f, on} : f,
8121
+ now => shiftKeepAlpha(now, lighter ? amount : -amount),
8122
+ c,
8123
+ );
8124
+ if (steps.length)
8125
+ return {
8126
+ text: `${lighter ? 'lighter' : 'darker'} text${where}, from ${read}${modesSaid(steps)}`,
8127
+ options: [steps],
8128
+ sequence: steps.length > 1,
8129
+ };
8130
+ }
8131
+ }
5086
8132
  if (!color) return null;
5087
8133
  // A part that takes its color from a prop (a heading): the text
5088
8134
  // token, on that part only.
5089
8135
  if (!env.check([set('color', color, f)]).ok)
5090
8136
  return {
5091
8137
  text: `the text color${where}: --color-text-primary on ${on} only (${on} takes its color from a prop, so a color property never shows)`,
5092
- options: [[set('--color-text-primary', color, {on, ...modeOf(c)})]],
8138
+ options: [
8139
+ [
8140
+ set('--color-text-primary', color, {
8141
+ on,
8142
+ // "red h1": that level only.
8143
+ ...(f.when ? {when: f.when} : {}),
8144
+ ...modeOf(c),
8145
+ }),
8146
+ ],
8147
+ ],
5093
8148
  };
5094
8149
  return {
5095
8150
  text: `text color${where}: color`,
@@ -5158,6 +8213,23 @@ export function draftAnswer(ctx, env, question) {
5158
8213
  text: `the page background: --color-background-body${c.mode && modal ? ` in ${c.mode} mode` : ''}`,
5159
8214
  options: [[set('--color-background-body', color, modeOf(c))]],
5160
8215
  };
8216
+ const temp = /\b(warm(er)?|cool(er)?)\b/.exec(c.text)?.[1];
8217
+ if (temp) {
8218
+ const way = /^warm/.test(temp) ? 'warm' : 'cool';
8219
+ const steps = perMode(
8220
+ '--color-background-body',
8221
+ '--color-background-body',
8222
+ {},
8223
+ now => tempShift(now, way, colorAmount(c.text, 0.12)),
8224
+ c,
8225
+ );
8226
+ if (steps.length)
8227
+ return {
8228
+ text: `a ${way}er page background: --color-background-body, its hue toward ${way === 'warm' ? 'amber' : 'blue'} at the same lightness${modesSaid(steps)}`,
8229
+ options: [steps],
8230
+ sequence: steps.length > 1,
8231
+ };
8232
+ }
5161
8233
  if (!c.dir) return null;
5162
8234
  const lighter = /\blight(er)?|brighter\b/.test(c.text);
5163
8235
  const steps = perMode(
@@ -5251,26 +8323,75 @@ export function draftAnswer(ctx, env, question) {
5251
8323
  if (!color && c.dir) {
5252
8324
  const lighter = /\blight(er)?\b/.test(c.text);
5253
8325
  const reads = C.partReads(one(on), 'background');
8326
+ // "card background warmer": its hue toward warm or cool, at the
8327
+ // same lightness.
8328
+ const temp = /\b(warm(er)?|cool(er)?)\b/.exec(c.text)?.[1];
8329
+ const tempRead = temp
8330
+ ? (restColorRead(reads, f.when) ??
8331
+ (FAMILIES.containers.includes(one(on))
8332
+ ? '--color-background-card'
8333
+ : null))
8334
+ : null;
8335
+ if (temp && tempRead) {
8336
+ const way = /^warm/.test(temp) ? 'warm' : 'cool';
8337
+ const steps = perMode(
8338
+ tempRead,
8339
+ 'background',
8340
+ f,
8341
+ now => tempShift(now, way, colorAmount(c.text, 0.12)),
8342
+ c,
8343
+ );
8344
+ if (steps.length)
8345
+ return {
8346
+ text: `a ${way}er background${where}, from ${tempRead}: its hue toward ${way === 'warm' ? 'amber' : 'blue'} at the same lightness${modesSaid(steps)}`,
8347
+ options: [steps],
8348
+ sequence: steps.length > 1,
8349
+ };
8350
+ }
8351
+ // The fill the part shows at rest (its main variant, or the one
8352
+ // asked for), never its pressed overlay.
5254
8353
  const read = C.MAP[one(on)]
5255
- ? (reads.find(r => r.when.includes(''))?.token ??
8354
+ ? (restColorRead(reads, f.when) ??
5256
8355
  (FAMILIES.containers.includes(one(on))
5257
8356
  ? '--color-background-card'
5258
- : reads[0]?.token))
8357
+ : null))
5259
8358
  : null;
8359
+ // The amount asked ("20% darker", "a bit lighter"), else a step.
8360
+ const pct = /(\d{1,3})\s?%/.exec(c.text);
8361
+ const amount = colorAmount(c.text, 0.12);
8362
+ // A fill of the theme's own on the part comes first.
8363
+ const ownFill =
8364
+ partValue(on, 'background-color') ?? partValue(on, 'background');
8365
+ const ownShifted =
8366
+ ownFill && parseColor(ownFill)
8367
+ ? shiftKeepAlpha(ownFill, lighter ? amount : -amount)
8368
+ : null;
8369
+ if (ownShifted && !f.state)
8370
+ return {
8371
+ text: `${lighter ? 'a lighter' : 'a darker'} background${where}: ${ownShifted} (now ${ownFill})`,
8372
+ options: [[set('background-color', ownShifted, f)]],
8373
+ };
5260
8374
  // A part with no recorded fill: what its color is now is unknown,
5261
8375
  // so a brightness filter makes it darker or lighter from there.
8376
+ // The amount asked holds there too: "20% darker" is brightness 0.8.
5262
8377
  if (!read || f.state)
5263
8378
  return {
5264
- text: `${lighter ? 'a lighter' : 'a darker'} ${on}${where}: a brightness filter, from whatever color it has now`,
8379
+ text: `${lighter ? 'a lighter' : 'a darker'} ${on}${where}: a brightness filter, from whatever color it has now${pct ? ` (${lighter ? '+' : '-'}${pct[1]}%)` : ''}`,
5265
8380
  options: [
5266
- [set('filter', `brightness(${lighter ? 1.15 : 0.85})`, f)],
8381
+ [
8382
+ set(
8383
+ 'filter',
8384
+ `brightness(${pct ? Number((lighter ? 1 + amount : 1 - amount).toFixed(2)) : lighter ? 1.15 : 0.85})`,
8385
+ f,
8386
+ ),
8387
+ ],
5267
8388
  ],
5268
8389
  };
5269
8390
  const steps = perMode(
5270
8391
  read,
5271
8392
  'background',
5272
8393
  f,
5273
- now => shift(now, lighter ? 0.12 : -0.12),
8394
+ now => shiftKeepAlpha(now, lighter ? amount : -amount),
5274
8395
  c,
5275
8396
  );
5276
8397
  if (steps.length)
@@ -5610,6 +8731,17 @@ export function draftAnswer(ctx, env, question) {
5610
8731
  if (!found.some(x => x.dial === dial))
5611
8732
  found.push({at: m.index ?? 0, dial, token});
5612
8733
  if (!found.length) return null;
8734
+ // "the accent cooler": warm and cool name a direction for the color
8735
+ // named, never the neutral besides it.
8736
+ if (
8737
+ found.length > 1 &&
8738
+ found.some(x => x.dial === 'neutral') &&
8739
+ !/\b(neutrals?|gr[ae]ys?)\b/.test(t)
8740
+ )
8741
+ found.splice(
8742
+ found.findIndex(x => x.dial === 'neutral'),
8743
+ 1,
8744
+ );
5613
8745
  found.sort((x, y) => x.at - y.at);
5614
8746
  seenAspect('colors');
5615
8747
  // Each color written in the clause, where it is.
@@ -5670,6 +8802,8 @@ export function draftAnswer(ctx, env, question) {
5670
8802
  ],
5671
8803
  }
5672
8804
  : {text: 'no setting is a second brand color', options: []};
8805
+ /** @type {Step | null} */
8806
+ let darkStep = null;
5673
8807
  let color =
5674
8808
  given &&
5675
8809
  !(
@@ -5678,6 +8812,29 @@ export function draftAnswer(ctx, env, question) {
5678
8812
  )
5679
8813
  ? given
5680
8814
  : null;
8815
+ // "a cooler / warmer accent": its hue moves toward blue or orange; its
8816
+ // lightness and strength stay.
8817
+ if (
8818
+ dial !== 'neutral' &&
8819
+ !color &&
8820
+ /\b(warm(er)?|cool(er)?)\b/.test(t) &&
8821
+ token
8822
+ ) {
8823
+ const warm =
8824
+ /\btoo cool\b|\bwarm(er)?\b/.test(t) && !/\btoo warm\b/.test(t);
8825
+ const now = String(current(token, 'light') || '');
8826
+ const moved = now ? hueToward(now, warm ? 30 : 220, 25) : null;
8827
+ if (!moved && now)
8828
+ return {
8829
+ text: `${dial} is a gray now (${now}), with no hue to move ${warm ? 'warmer' : 'cooler'}; give a color for it (for example "${dial} ${warm ? '#ea580c' : '#2563eb'}")`,
8830
+ options: [],
8831
+ };
8832
+ if (moved)
8833
+ return {
8834
+ text: `${dial}, ${warm ? 'warmer' : 'cooler'}: its hue moves toward ${warm ? 'orange' : 'blue'} (now ${now}); its lightness and strength stay, and the neutral grays are not changed`,
8835
+ options: [[set(dial, moved)]],
8836
+ };
8837
+ }
5681
8838
  if (dial === 'neutral' && !color)
5682
8839
  // "too warm" asks for cooler, "too cool" for warmer.
5683
8840
  color = /\btoo warm\b|\bcool(er)?\b/.test(t)
@@ -5717,6 +8874,15 @@ export function draftAnswer(ctx, env, question) {
5717
8874
  };
5718
8875
  }
5719
8876
  color = shift(current(token, 'light'), lighter ? 0.2 : -0.2);
8877
+ // The dark half the editor generates from that seed can move the
8878
+ // other way; the dark token is stepped the asked way from its own
8879
+ // value, in the same answer.
8880
+ if (modal && color && dial !== 'neutral' && dial !== 'secondary') {
8881
+ const darkNow = String(current(token, 'dark') || '');
8882
+ const darkNext = darkNow ? shift(darkNow, lighter ? 0.2 : -0.2) : null;
8883
+ if (darkNext && darkNext.toLowerCase() !== darkNow.toLowerCase())
8884
+ darkStep = set(token, darkNext, {mode: 'dark'});
8885
+ }
5720
8886
  }
5721
8887
  if (!color)
5722
8888
  return {
@@ -5730,8 +8896,11 @@ export function draftAnswer(ctx, env, question) {
5730
8896
  options: [[set(token, color, modeOf(c))]],
5731
8897
  };
5732
8898
  return {
5733
- text: `${dial}: the editor makes its light and dark shades from ${color}`,
5734
- options: [[set(dial, color)], [set(token, color)]],
8899
+ text: `${dial}: the editor makes its light and dark shades from ${color}${darkStep ? `, and the dark ${token} steps from its own value the same way` : ''}`,
8900
+ options: darkStep
8901
+ ? [[set(dial, color), darkStep]]
8902
+ : [[set(dial, color)], [set(token, color)]],
8903
+ ...(darkStep ? {sequence: true} : {}),
5735
8904
  };
5736
8905
  }
5737
8906
 
@@ -5867,6 +9036,151 @@ export function draftAnswer(ctx, env, question) {
5867
9036
  // A confidence gate: a question, a "tell me", a "but not too" or a typo
5868
9037
  // read as a direction leaves how unsure which way to go; a wrong write is
5869
9038
  // worse than none, so it gives the lookup and asks for the ask.
9039
+ // The intent check: a part the question only compares against ("than
9040
+ // buttons", "as round as inputs", "the same color as the card") is never
9041
+ // changed. A command that would change it is dropped, and the answer
9042
+ // says so; never a wrong command.
9043
+ {
9044
+ /** @type {Set<string>} */
9045
+ const refs = new Set();
9046
+ /** @type {Set<string>} */
9047
+ const subjects = new Set();
9048
+ for (const c of clauses) {
9049
+ // "I would like …" is a wish, never a comparison.
9050
+ // Only comparison forms: "than", "as round as", "the same … as",
9051
+ // "match", "equal to", "rounded like buttons", "like the buttons
9052
+ // are". "Form controls like inputs and checkboxes" names examples of
9053
+ // the subject; "use red as the button background" gives a value for
9054
+ // that part; "such as" lists examples.
9055
+ const cmp =
9056
+ /\b(?:than|as \w+ as|match(?:es|ing)?|equal to|(?:the )?same (?:\w+ )?as|(?:(?:\w+(?:er|ed|ish|ly))|round|bold|dark|light|big|small|thick|thin|tall|wide|look|looks|styled|exactly|just) like(?= (?:the |my )?\w+(?: \w+)? (?:are|is|do|does|have|has)\b)?|like (?=(?:the |my )\w+(?: \w+)? (?:are|is|do|does|have|has)\b))\s+(?:the\s+|my\s+)?/.exec(
9057
+ lex.parts
9058
+ .reduce(
9059
+ // A part's name is never a comparative ("the container like
9060
+ // dialogs", "a header like cards"): masked, same length.
9061
+ (t, [re]) =>
9062
+ t.replace(new RegExp(re.source, 'g'), m =>
9063
+ 'x'.repeat(m.length),
9064
+ ),
9065
+ c.text,
9066
+ )
9067
+ .replace(/\b(?:i|we|you)(?: would|'d)? like(?: to| for)?\b/g, m =>
9068
+ ' '.repeat(m.length),
9069
+ ),
9070
+ );
9071
+ if (!cmp) continue;
9072
+ const after = (cmp.index ?? 0) + cmp[0].length;
9073
+ for (const [re, x] of lex.parts) {
9074
+ const m = re.exec(c.text);
9075
+ if (!m) continue;
9076
+ if (m.index >= after - 1) refs.add(x.on);
9077
+ else subjects.add(x.on);
9078
+ }
9079
+ }
9080
+ for (const sub of subjects) refs.delete(sub);
9081
+ for (const d of result)
9082
+ if (d.intent && refs.size)
9083
+ d.intent = {...d.intent, keep: [...d.intent.keep, ...refs]};
9084
+ if (refs.size)
9085
+ for (const d of result) {
9086
+ const before = d.options.map(o => o.length);
9087
+ d.options = d.options
9088
+ .map(o =>
9089
+ o.filter(
9090
+ st =>
9091
+ !(st.on && refs.has(st.on)) &&
9092
+ // The page is its body background token.
9093
+ !(
9094
+ refs.has('page') &&
9095
+ !st.on &&
9096
+ st.thing === '--color-background-body'
9097
+ ),
9098
+ ),
9099
+ )
9100
+ .filter(o => o.length);
9101
+ if (d.options.map(o => o.length).join() !== before.join())
9102
+ d.text = `${d.text} (${[...refs].join(', ')} is only what the ask compares against, so it is not changed)`;
9103
+ }
9104
+ }
9105
+ // A question about what a part has now ("how much padding do buttons
9106
+ // have", "how rounded are cards", "what color is the button"): its value
9107
+ // now, as show reads it; never a change.
9108
+ const asked = valueAsked(question);
9109
+ // "how rounded are cards? make them 12px": the value now, then the ask.
9110
+ const followAsk = asked
9111
+ ? (/\?\s*(\S[\s\S]*)$/.exec(question)?.[1] ?? '')
9112
+ : '';
9113
+ if (asked && followAsk && isAsk(followAsk)) {
9114
+ const named0 = lex.parts
9115
+ .map(([re, x]) => ({
9116
+ at: re.exec(question.toLowerCase())?.index ?? -1,
9117
+ on: x.on,
9118
+ }))
9119
+ .filter(x => x.at >= 0)
9120
+ .sort((x, y) => x.at - y.at)[0]?.on;
9121
+ const now0 = named0 ? partPropNow(named0, asked) : null;
9122
+ const rest = draftAnswer(
9123
+ ctx,
9124
+ env,
9125
+ named0
9126
+ ? followAsk.replace(
9127
+ /\b(them|it|those|these)\b/i,
9128
+ `${named0} ${asked === 'border-radius' ? 'corners' : asked.replace(/-color$/, '').replace('-', ' ')}`,
9129
+ )
9130
+ : followAsk,
9131
+ );
9132
+ return {
9133
+ parts: rest.parts,
9134
+ aspects: rest.aspects,
9135
+ drafts: [
9136
+ ...(named0 && now0
9137
+ ? [{text: `${named0} has ${asked} ${now0} now`, options: []}]
9138
+ : []),
9139
+ ...rest.drafts,
9140
+ ],
9141
+ };
9142
+ }
9143
+ if (asked) {
9144
+ const named = lex.parts
9145
+ .map(([re, x]) => ({
9146
+ at: re.exec(question.toLowerCase())?.index ?? -1,
9147
+ on: x.on,
9148
+ }))
9149
+ .filter(x => x.at >= 0)
9150
+ .sort((x, y) => x.at - y.at)[0]?.on;
9151
+ const now = named ? partPropNow(named, asked) : null;
9152
+ result.splice(0, result.length, {
9153
+ text: named
9154
+ ? now
9155
+ ? `${named} has ${asked} ${now} now (nothing is changed); to change it, ask for the change ("${asked === 'color' ? `${named} text red` : `${named} ${asked} 12px`}")`
9156
+ : `${named} has no ${asked} of its own that how can read; ${HOW} ${named} lists what it reads`
9157
+ : `how changes a theme; ${P} show ${env.slug} lists what it has now`,
9158
+ options: [],
9159
+ lookup: named ? `${HOW} ${named}` : `${P} show ${env.slug}`,
9160
+ });
9161
+ return {parts: partsSeen, aspects: aspectsSeen, drafts: result};
9162
+ }
9163
+ // "don't make the cards bigger", "buttons should not be rounder": a
9164
+ // prohibition changes nothing; it says what stays.
9165
+ if (segments.length && segments.every(x => EXCLUDE.test(x))) {
9166
+ result.splice(0, result.length, {
9167
+ text: 'nothing to change: you asked for it not to change, so it stays as it is; ask for the change you want instead',
9168
+ options: [],
9169
+ lookup: partsSeen[0] ? `${HOW} ${partsSeen[0]}` : `${P} show ${env.slug}`,
9170
+ });
9171
+ return {parts: partsSeen, aspects: aspectsSeen, drafts: result};
9172
+ }
9173
+ for (const n of placeNotes) result.push({text: n, options: []});
9174
+ // A lookup for a part a "match" ask already answered for adds nothing.
9175
+ for (let i = result.length - 1; i >= 0; i--) {
9176
+ const d = result[i];
9177
+ if (
9178
+ !d.options.length &&
9179
+ d.lookup &&
9180
+ [...symDone].some(on => d.lookup === `${HOW} ${on}`)
9181
+ )
9182
+ result.splice(i, 1);
9183
+ }
5870
9184
  const unsure = gateAll;
5871
9185
  if (unsure && result.some(d => d.options.some(o => o.length))) {
5872
9186
  const part = partsSeen[0];
@@ -5884,6 +9198,33 @@ export function draftAnswer(ctx, env, question) {
5884
9198
  return {parts: partsSeen, aspects: aspectsSeen, drafts: result};
5885
9199
  }
5886
9200
 
9201
+ /**
9202
+ * The property a question asks the value of ("how much padding …", "how
9203
+ * rounded are …", "what color is …"), or null when it is not one.
9204
+ * @param {string} q
9205
+ * @returns {string | null}
9206
+ */
9207
+ export function valueAsked(q) {
9208
+ // Only the question part ("how rounded are cards? make them 12px").
9209
+ const t = q.toLowerCase().trim().split('?')[0];
9210
+ if (
9211
+ !/^(?:how (?:much|many|big|round(?:ed)?|thick|wide|tall|bold|dark|light)|what(?:'s| is)?(?: the)? (?:colou?r|size|padding|gap|spacing|radius|corner radius|font|weight|font size|shadow|border)|which colou?r)\b/.test(
9212
+ t,
9213
+ )
9214
+ )
9215
+ return null;
9216
+ if (/\b(round|rounded|radius|corners?)\b/.test(t)) return 'border-radius';
9217
+ if (/\bgap\b/.test(t)) return 'gap';
9218
+ if (/\b(padding|spacing|space|room)\b/.test(t)) return 'padding';
9219
+ if (/\bshadow\b/.test(t)) return 'box-shadow';
9220
+ if (/\b(background|fill|bg)\b/.test(t)) return 'background-color';
9221
+ if (/\bborder\b/.test(t)) return 'border-width';
9222
+ if (/\bfont size|text size|how big\b/.test(t)) return 'font-size';
9223
+ if (/\b(bold|weight)\b/.test(t)) return 'font-weight';
9224
+ if (/\b(colou?r|dark|light)\b/.test(t)) return 'color';
9225
+ return null;
9226
+ }
9227
+
5887
9228
  /** Words for the operating system's own font. */
5888
9229
  const OS_FONT =
5889
9230
  /^(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;