@astryxdesign/cli 0.7.15 → 0.7.16-canary.g9b5ad42

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 (81) hide show
  1. package/README.md +5 -3
  2. package/api/doctor/_adapter.d.mts +17 -0
  3. package/api/doctor/_adapter.mjs +35 -0
  4. package/api/doctor/doctor.mjs +18 -4
  5. package/api/integration/validate-integration.mjs +1 -1
  6. package/api/theme/_adapter.d.mts +5 -2
  7. package/api/theme/_adapter.mjs +43 -12
  8. package/api/theme/build/build.d.mts +1 -21
  9. package/api/theme/build/build.mjs +149 -37
  10. package/api/theme/eject/eject.mjs +22 -1
  11. package/api/theme/template/template.d.mts +2 -0
  12. package/api/theme/template/template.mjs +41 -12
  13. package/api/theme/theme.type.d.mts +4 -0
  14. package/api/theme/theme.type.mjs +2 -1
  15. package/api/theme/themeBuild.doc.mjs +3 -3
  16. package/api/theme/themeEject.doc.mjs +1 -1
  17. package/api/theme/themeTemplate.doc.mjs +9 -3
  18. package/api/theme-edit/_adapter.d.mts +10 -0
  19. package/api/theme-edit/_adapter.mjs +76 -5
  20. package/api/theme-edit/_check.mjs +181 -50
  21. package/api/theme-edit/_color.d.mts +2 -8
  22. package/api/theme-edit/_color.mjs +126 -55
  23. package/api/theme-edit/_compiler.d.mts +1 -0
  24. package/api/theme-edit/_compiler.mjs +3 -0
  25. package/api/theme-edit/_context.d.mts +7 -0
  26. package/api/theme-edit/_context.mjs +34 -1
  27. package/api/theme-edit/_css.d.mts +21 -1
  28. package/api/theme-edit/_css.mjs +172 -13
  29. package/api/theme-edit/_edit.d.mts +9 -0
  30. package/api/theme-edit/_edit.mjs +377 -48
  31. package/api/theme-edit/_how-commands.d.mts +7 -26
  32. package/api/theme-edit/_how-commands.mjs +27 -1
  33. package/api/theme-edit/_how-question.mjs +330 -12
  34. package/api/theme-edit/_how.mjs +68 -26
  35. package/api/theme-edit/_palette.mjs +10 -0
  36. package/api/theme-edit/_parts.d.mts +16 -0
  37. package/api/theme-edit/_parts.mjs +49 -1
  38. package/api/theme-edit/_preview-app.mjs +176 -9
  39. package/api/theme-edit/_preview.mjs +7 -3
  40. package/api/theme-edit/_project.d.mts +11 -0
  41. package/api/theme-edit/_project.mjs +35 -9
  42. package/api/theme-edit/_settings.d.mts +46 -5
  43. package/api/theme-edit/_settings.mjs +217 -25
  44. package/api/theme-edit/theme-edit.type.d.mts +2 -1
  45. package/api/theme-edit/theme-edit.type.mjs +1 -1
  46. package/api/theme-edit/themeEditNew.doc.mjs +1 -1
  47. package/api/theme-edit/themeEditShow.doc.mjs +1 -1
  48. package/assets/docs/tree/tokens-and-setup.doc.mjs +39 -3
  49. package/assets/docs.generated.json +2 -2
  50. package/assets/preview-app/next.config.mjs +7 -1
  51. package/assets/self-audit.generated.json +1 -1
  52. package/assets/templates/blocks/components/Table/ColumnsVirtualizationHookUsage.doc.mjs +14 -0
  53. package/assets/templates/blocks/components/Table/ColumnsVirtualizationHookUsage.tsx +53 -0
  54. package/assets/templates/blocks/components/Table/InfiniteScrollHookUsage.doc.mjs +14 -0
  55. package/assets/templates/blocks/components/Table/InfiniteScrollHookUsage.tsx +33 -0
  56. package/assets/templates/components.generated.json +1 -1
  57. package/clients/cli/build-id.generated.json +1 -1
  58. package/clients/cli/commands/doctor.doc.mjs +2 -2
  59. package/clients/cli/commands/experimental/theme.mjs +113 -34
  60. package/clients/cli/commands/experimental-theme-compile.doc.mjs +1 -1
  61. package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +1 -1
  62. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +1 -1
  63. package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
  64. package/clients/cli/commands/experimental-theme-eject.doc.mjs +1 -1
  65. package/clients/cli/commands/experimental-theme-template.doc.mjs +1 -1
  66. package/clients/cli/commands/theme-build.doc.mjs +2 -2
  67. package/clients/cli/commands/theme-eject.doc.mjs +1 -1
  68. package/clients/cli/commands/theme-template.doc.mjs +3 -1
  69. package/clients/cli/commands/theme.mjs +85 -5
  70. package/clients/cli/manifest.generated.json +1 -1
  71. package/foundation/config/project.mjs +50 -14
  72. package/foundation/fs/gather-cache.d.mts +9 -2
  73. package/foundation/fs/gather-cache.mjs +36 -10
  74. package/foundation/fs/paths.d.mts +16 -0
  75. package/foundation/fs/paths.mjs +25 -0
  76. package/foundation/response/error-codes.d.mts +2 -1
  77. package/foundation/response/error-codes.d.ts +1 -0
  78. package/foundation/response/error-codes.doc.mjs +5 -0
  79. package/foundation/response/error-codes.mjs +3 -0
  80. package/foundation/response/response-types.doc.mjs +1 -1
  81. package/package.json +7 -6
@@ -49,11 +49,14 @@ import {
49
49
  getCliInvocation,
50
50
  quoteCommandArgument,
51
51
  } from '../../foundation/env/package-manager.mjs';
52
- import {LIKE, P} from './_tables.mjs';
53
- import {camel} from './_settings.mjs';
52
+ import {DIALS, LIKE, P} from './_tables.mjs';
53
+ import {colorProblem} from './_color.mjs';
54
+ import {SHOWCASE_GROUPS} from './_preview.mjs';
55
+ import {camel, typedThemeName} from './_settings.mjs';
54
56
  import {LOCAL_THEME_ROOT} from '../../foundation/config/theme-state.mjs';
55
57
 
56
58
  export {parsePoints} from './_how.mjs';
59
+ export {newFlagList} from './_edit.mjs';
57
60
  import {themeEditHow as howAt} from './_how.mjs';
58
61
 
59
62
  /**
@@ -90,6 +93,35 @@ export async function themeEditHow(subject, options = {}) {
90
93
  /** The built-in themes a theme can build on (`--like`). */
91
94
  export const builtInThemes = () => [...LIKE];
92
95
 
96
+ /** The sections `show --section` takes. */
97
+ export const showSections = () => [...SHOWCASE_GROUPS];
98
+
99
+ /**
100
+ * Whether a value fits what a dial takes, read from the dial's own list of
101
+ * values: a named rung in any case, or a value of the kind it names (a size,
102
+ * a color, a number). `set` still checks the value in full.
103
+ * @param {string} dial
104
+ * @param {string} value
105
+ */
106
+ export function dialValueFits(dial, value) {
107
+ const spec = DIALS[/** @type {keyof typeof DIALS} */ (dial)]?.values;
108
+ if (!spec) return false;
109
+ const v = String(value).trim();
110
+ if (v === '') return false;
111
+ return spec.split('|').some(option => {
112
+ if (!option.startsWith('<') && !option.startsWith('"'))
113
+ return option === v.toLowerCase();
114
+ if (option.startsWith('"')) return true;
115
+ if (option.includes('size')) return /^\d*\.?\d+(px|rem|em)$/.test(v);
116
+ // A color by the editor's own color check (a bare word only when it
117
+ // names a color).
118
+ if (option === '<color>') return colorProblem(v) == null;
119
+ if (option === '<0-100>') return /^\d{1,3}$/.test(v) && Number(v) <= 100;
120
+ if (option === '<number>') return /^\d*\.?\d+$/.test(v);
121
+ return false;
122
+ });
123
+ }
124
+
93
125
  /**
94
126
  * The project a command acts on: the Astryx project at or above `cwd`, found
95
127
  * as `upgrade` finds it (the nearest package that declares an Astryx package
@@ -577,16 +609,32 @@ export function editorThemeRefusal(err, cwd) {
577
609
  )
578
610
  return null;
579
611
  const root = projectRoot(cwd);
580
- const named = /"([a-z][a-z0-9-]*)"|'([a-z][a-z0-9-]*)'/.exec(err.message);
581
- const slug = named ? editorThemeOf(root, named[1] ?? named[2]) : null;
612
+ // The name as typed, read the way the editor reads a theme name: a path
613
+ // to its folder or a file in it, in any case, names the theme.
614
+ const named = /"([^"]+)"|'([^']+)'/.exec(err.message);
615
+ const word = named ? typedThemeName(named[1] ?? named[2]) : '';
616
+ const slug = word ? editorThemeOf(root, word) : null;
582
617
  if (!slug) return null;
583
618
  // A local theme of that name (a fork in the app's own themes folder) is
584
619
  // one the stable commands take: their own message stands.
585
620
  if (fs.existsSync(path.join(root, LOCAL_THEME_ROOT, slug))) return null;
586
621
  const id = `${camel(slug)}Theme`;
587
622
  const key = /^[a-z][a-z0-9]*$/i.test(slug) ? slug : JSON.stringify(slug);
623
+ // The paths from the folder of the app's generated themes module (where
624
+ // a file that merges themes sits), else from the app root.
625
+ const generated = path.join(root, 'src', 'astryx-themes.ts');
626
+ const from = fs.existsSync(generated) ? path.dirname(generated) : root;
627
+ let rel = path
628
+ .relative(from, path.join(root, 'themes', slug))
629
+ .split(path.sep)
630
+ .join('/');
631
+ if (!rel.startsWith('.')) rel = `./${rel}`;
632
+ const where =
633
+ from === root
634
+ ? 'in a file of your own at the app root'
635
+ : `in a file of your own beside ${path.relative(root, generated).split(path.sep).join('/')} (from another folder, change the paths to match)`;
588
636
  return new AstryxError(
589
- `${slug} is a theme the editor made (themes/${slug}/), not a theme package, so list, add, use, remove and eject do not take it. To use it, import its module and its stylesheet in a file of your own (import {${id}} from './themes/${slug}/${slug}.js'; import './themes/${slug}/${slug}.css';) and merge it into the themes there ({...themes, ${key}: ${id}}); do not add it to src/astryx-themes.ts, which add, use and remove write again. Change it with the editor.`,
637
+ `${slug} is a theme the editor made (themes/${slug}/), not a theme package, so list, add, use, remove and eject do not take it. To use it, import its module and its stylesheet ${where} (import {${id}} from '${rel}/${slug}.js'; import '${rel}/${slug}.css';) and merge it into the themes there ({...themes, ${key}: ${id}}); do not add it to src/astryx-themes.ts, which add, use and remove write again. Change it with the editor.`,
590
638
  [
591
639
  {
592
640
  name: runLine(cwd, `experimental theme editor show ${slug}`),
@@ -613,6 +661,20 @@ export async function editorCompileProblem(files, {cwd, check, family}) {
613
661
  if (!at || !editorOwnFile(at.slug, file)) continue;
614
662
  const {root, slug} = at;
615
663
  const source = `themes/${slug}/${slug}.theme.ts`;
664
+ // An editor theme is built from its project's root, as every editor
665
+ // command runs there: from a subfolder the build would write outside
666
+ // its working folder. The run names the root.
667
+ if (path.resolve(cwd) !== path.resolve(root))
668
+ return new AstryxError(
669
+ `${slug} is a theme the editor made; compile it from the app root (${path.relative(cwd, root) || '.'}), where the editor builds it.`,
670
+ [
671
+ {
672
+ name: `cd ${quoteCommandArgument(path.relative(cwd, root) || '.')} && ${runLine(root, `experimental theme compile ${source}${check ? ' --check' : ''}`)}`,
673
+ reason: 'do this instead',
674
+ },
675
+ ],
676
+ ERROR_CODES.ERR_INVALID_ARGUMENT,
677
+ );
616
678
  if (/\.settings\.(ts|json)$/.test(file))
617
679
  return new AstryxError(
618
680
  `${file} is the editor's own settings for ${slug}, not a theme source; compile the theme source.`,
@@ -661,6 +723,15 @@ export async function editorCompileProblem(files, {cwd, check, family}) {
661
723
  if (e instanceof AstryxError) return e;
662
724
  throw e;
663
725
  }
726
+ // An own change to the theme source is what compile builds (and what
727
+ // --check compares): never a reason to refuse it.
728
+ if (
729
+ why &&
730
+ /\.theme\.ts (or a module it imports )?changed since the last build$/.test(
731
+ why,
732
+ )
733
+ )
734
+ why = null;
664
735
  if (why && !check)
665
736
  return new AstryxError(
666
737
  `${slug}'s generated settings do not match its settings (${why}), so compile would build the old ones. The editor builds it from its settings.`,
@@ -12,10 +12,11 @@
12
12
  import * as fs from 'node:fs';
13
13
  import * as path from 'node:path';
14
14
  import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
15
- import {baseThemeFile} from './_project.mjs';
15
+ import {baseInstalled, baseThemeFile} from './_project.mjs';
16
16
  import {levenshteinDistance} from '../../foundation/text/levenshtein.mjs';
17
17
  import {
18
18
  MATH_FUNCTION,
19
+ cssNumber,
19
20
  belowRange,
20
21
  fontShorthandParts,
21
22
  cssProperties,
@@ -28,6 +29,7 @@ import {
28
29
  propertyGrammar,
29
30
  takesPercentage,
30
31
  } from './_css.mjs';
32
+ import {multipliedTokens} from './_parts.mjs';
31
33
  import {
32
34
  AUTO_SPREAD,
33
35
  COLOR_PROP_PARTS,
@@ -83,6 +85,7 @@ import {
83
85
  radiusTokenOf,
84
86
  focusStateOf,
85
87
  valueProblem,
88
+ partComponentDocs,
86
89
  } from './_settings.mjs';
87
90
  import {quoteCommandArgument} from '../../foundation/env/package-manager.mjs';
88
91
 
@@ -223,6 +226,22 @@ export function storedProblems(ctx, slug, data, skip = '') {
223
226
  !(s.thing === 'font' && FONT_ROLES.includes(s.on))
224
227
  )
225
228
  return scope(`there is no part or group "${s.on}"`);
229
+ // A token that is no design token, or a part property that is no
230
+ // CSS property or names no part, styles nothing: reported, never
231
+ // built.
232
+ if (s.source === 'token' && !(s.thing in TOKENS))
233
+ return {setting: s, why: `${s.thing} is not a design token`};
234
+ if (s.source === 'property' && !s.on)
235
+ return {
236
+ setting: s,
237
+ why: `${s.thing} is a CSS property, so it needs a part (--on)`,
238
+ };
239
+ if (
240
+ s.source === 'property' &&
241
+ !s.thing.startsWith('--') &&
242
+ !cssProperties().has(s.thing)
243
+ )
244
+ return {setting: s, why: `${s.thing} is not a CSS property`};
226
245
  if (s.source === 'dial' && s.on && WHOLE_ONLY.includes(s.thing))
227
246
  return scope(`${s.thing} applies to the whole theme, not to ${s.on}`);
228
247
  if (s.mode && s.source === 'dial' && !PALETTE_DIALS.includes(s.thing))
@@ -252,6 +271,7 @@ export function storedProblems(ctx, slug, data, skip = '') {
252
271
  ctx.C.typeOf,
253
272
  slug,
254
273
  ctx.C.propsReading(s.thing),
274
+ multipliedTokens(ctx.project).has(s.thing),
255
275
  );
256
276
  checkCycle(s.thing, s.value, TOKENS, data);
257
277
  } catch (e) {
@@ -305,6 +325,7 @@ function groupOfPropType(prop) {
305
325
  * @param {(token: string) => string} typeOf
306
326
  * @param {string} slug
307
327
  * @param {string[]} [readers] the CSS properties that read the token
328
+ * @param {boolean} [multiplied] whether Core multiplies the token by a size
308
329
  */
309
330
  function checkTypedValue(
310
331
  type,
@@ -314,6 +335,7 @@ function checkTypedValue(
314
335
  typeOf,
315
336
  slug,
316
337
  readers = [],
338
+ multiplied = false,
317
339
  ) {
318
340
  /** @param {string} what @param {string} example */
319
341
  const bad = (what, example) =>
@@ -380,6 +402,33 @@ function checkTypedValue(
380
402
  }
381
403
  if (type === 'number' && !isNumber(value, name))
382
404
  bad('a number', /weight/.test(name) ? '600' : '1.4');
405
+ // A token Core's stylesheet multiplies by a size inside calc() (the line
406
+ // heights) takes a number with no unit: there a length, a percentage or
407
+ // normal is invalid.
408
+ const coreDefault = String(TOKENS[name] ?? '').trim();
409
+ const v0 = value.trim();
410
+ const read = cssNumber(v0);
411
+ if (
412
+ type === 'number' &&
413
+ multiplied &&
414
+ !/^var\(--[a-z0-9-]+\)$/i.test(v0) &&
415
+ read?.unit !== '' &&
416
+ !(MATH_FUNCTION.test(v0) && matchType('number', v0) != null)
417
+ ) {
418
+ const unitless =
419
+ read?.unit === 'em'
420
+ ? String(read.value)
421
+ : read?.unit === '%'
422
+ ? String(read.value / 100)
423
+ : coreDefault;
424
+ refuse(
425
+ E.ERR_THEME_BAD_VALUE,
426
+ `${name} takes a number with no unit: Core multiplies it by a text size inside calc() (field heights, dialog headers, code blocks), where "${value}" is invalid. ${unitless === coreDefault ? `Core's own value is ${coreDefault}.` : `${unitless} is the same line height as a number.`}`,
427
+ {
428
+ run: [`${P} set ${slug} ${name} ${quoteCommandArgument(unitless)}`],
429
+ },
430
+ );
431
+ }
383
432
  if (type === 'time' && !isTime(value)) bad('a time up to 60s', '150ms');
384
433
  if (type === 'easing' && !isEasing(value))
385
434
  bad('an easing', 'cubic-bezier(0.2, 0, 0, 1)');
@@ -408,9 +457,13 @@ function isFixedColor(value) {
408
457
  if (/^var\(/.test(v)) return true;
409
458
  if (SYSTEM_COLORS.includes(v)) return true;
410
459
  // Percentages that add up to 0 leave color-mix() no color.
460
+ // A share is 0% to 100%.
411
461
  const zeroMix = (/** @type {string[]} */ colors) => {
412
462
  const pcts = colors.map(c => mixSide(c).pct);
413
- return pcts.every(p => p != null) && pcts.every(p => p === 0);
463
+ return (
464
+ pcts.some(p => p != null && (p < 0 || p > 100)) ||
465
+ (pcts.every(p => p != null) && pcts.every(p => p === 0))
466
+ );
414
467
  };
415
468
  const inner = (/** @type {string} */ fn) =>
416
469
  splitTop(v.slice(fn.length + 1, -1), ',').map(x => x.trim());
@@ -584,7 +637,10 @@ function propertyProblem(prop, value) {
584
637
  if (!known || COLOR_PROPS.test(prop)) return null;
585
638
  if (matchValue(prop, v))
586
639
  return belowRange(prop, v)
587
- ? {takes: 'a value of 0 or more', near: null}
640
+ ? {
641
+ takes: 'a value of 0 or more',
642
+ near: v.replace(/(^|[\s(,/])-(?=\.?\d)/g, '$1'),
643
+ }
588
644
  : null;
589
645
  // Only keywords the property takes on their own are offered; the same
590
646
  // word without its dashes or a trailing -ed/-s comes first (no-wrap is
@@ -990,16 +1046,10 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
990
1046
  // The part's component, or the one named like the part (tab is Tab,
991
1047
  // under TabList), takes a disabled prop.
992
1048
  const disables = (/** @type {string} */ t) => {
993
- const comps = /** @type {Record<string, any>} */ (
994
- ctx.project.components ?? {}
995
- );
996
- const pascal = t.replace(/(^|-)([a-z0-9])/g, (_, __, c) =>
997
- c.toUpperCase(),
998
- );
999
1049
  // Or its built module sets aria-disabled (a tab takes it through its
1000
1050
  // other props): what Core renders, read from Core itself.
1001
- const marks = (/** @type {string} */ n) => {
1002
- const at = comps[n]?.importPath?.split('/').pop();
1051
+ const marks = (/** @type {string} */ n, /** @type {any} */ doc) => {
1052
+ const at = doc?.importPath?.split('/').pop();
1003
1053
  const file =
1004
1054
  at && ctx.project.coreDir
1005
1055
  ? path.join(ctx.project.coreDir, 'dist', at, `${n}.js`)
@@ -1012,13 +1062,18 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
1012
1062
  return false;
1013
1063
  }
1014
1064
  };
1015
- return [ctx.project.target.get(t)?.component, pascal].some(
1016
- n =>
1017
- n != null &&
1018
- (Object.keys(comps[n]?.props ?? {}).some(p => /disabled/i.test(p)) ||
1019
- marks(n)),
1065
+ return partComponentDocs(ctx, t).some(
1066
+ ({name, doc}) =>
1067
+ Object.keys(doc.props ?? {}).some(p => /disabled/i.test(p)) ||
1068
+ marks(name, doc),
1020
1069
  );
1021
1070
  };
1071
+ // A part whose component takes children holds content that can take
1072
+ // focus, so focus-within applies there (a dialog, a section, a field).
1073
+ const holdsContent = (/** @type {string} */ t) =>
1074
+ partComponentDocs(ctx, t).some(
1075
+ ({doc}) => 'children' in (doc.props ?? {}),
1076
+ );
1022
1077
  // A part Core never styles in focus is not what takes focus (the
1023
1078
  // focusable element is inside it, or beside it).
1024
1079
  const focusable = (/** @type {string} */ t) =>
@@ -1038,7 +1093,8 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
1038
1093
  // focusable is inside it (a switch's input sits beside its track).
1039
1094
  (s.state === 'focus-within' &&
1040
1095
  !keys(t, 'focus-within') &&
1041
- !focusable(t))),
1096
+ !focusable(t) &&
1097
+ !holdsContent(t))),
1042
1098
  );
1043
1099
  if (parts.length && dead.length === parts.length) {
1044
1100
  const bare = Object.keys(own(dead[0])).length === 0;
@@ -1069,6 +1125,37 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
1069
1125
  );
1070
1126
  }
1071
1127
  }
1128
+ // Core expands a part's padding into its container tokens from a plain
1129
+ // padding only, so in a state that padding never reaches what sits edge
1130
+ // to edge inside it: refused, judged on the part named (a group member
1131
+ // spreads; when only another member is the reason, --only keeps it to
1132
+ // the part named).
1133
+ if (!unset && s.on && s.state && ctx.derived) {
1134
+ const prop =
1135
+ /^padding/.test(thing) || thing === 'spacing' ? 'padding' : null;
1136
+ const expands = (/** @type {string} */ t) =>
1137
+ (ctx.derived?.[t] ?? []).some(
1138
+ d => d.property === prop && d.expand === 'container',
1139
+ );
1140
+ const named = ctx.project.target.get(s.on) ? s.on : null;
1141
+ const hit = prop
1142
+ ? named && expands(named)
1143
+ ? named
1144
+ : partsOf(ctx, s).find(expands)
1145
+ : undefined;
1146
+ if (hit)
1147
+ refuse(
1148
+ E.ERR_THEME_NO_EFFECT,
1149
+ `Core sets ${hit}'s inner padding (what sits edge to edge inside it) from a plain padding setting only, so with --state ${s.state} it would stay behind.`,
1150
+ {
1151
+ run: [
1152
+ named && !expands(named) && !s.only
1153
+ ? setLine(slug, thing, v, {...s, only: true})
1154
+ : setLine(slug, thing, v, {...s, state: undefined}),
1155
+ ],
1156
+ },
1157
+ );
1158
+ }
1072
1159
  // On a group, a variant or state must belong to at least one member.
1073
1160
  if (s.on && FAMILIES[s.on] && (s.when || s.state)) {
1074
1161
  const members =
@@ -1209,28 +1296,36 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
1209
1296
  }
1210
1297
  if (HEADING_WEIGHTS[v] !== undefined) s.axis = 'weight';
1211
1298
  else if (HEADING_TRACKING[v] !== undefined) s.axis = 'tracking';
1212
- else
1299
+ else {
1300
+ // The word meant: in other letters (BOLD), or the rung nearest a
1301
+ // weight number (800 is heavy); never a rung the other way.
1302
+ const lower = v.trim().toLowerCase();
1303
+ const words = [
1304
+ ...Object.keys(HEADING_WEIGHTS),
1305
+ ...Object.keys(HEADING_TRACKING),
1306
+ ];
1307
+ const weight = /^\d+(\.\d+)?$/.test(lower) ? Number(lower) : null;
1308
+ const meant =
1309
+ words.find(w => w === lower) ??
1310
+ (weight != null
1311
+ ? Object.entries(HEADING_WEIGHTS).reduce((a, b) =>
1312
+ Math.abs(Number(b[1]) - weight) <
1313
+ Math.abs(Number(a[1]) - weight)
1314
+ ? b
1315
+ : a,
1316
+ )[0]
1317
+ : nearest(lower, words)[0]);
1213
1318
  refuse(
1214
1319
  E.ERR_THEME_BAD_VALUE,
1215
- `headings takes ${DIALS.headings.values}, not "${v}".`,
1320
+ `headings takes ${DIALS.headings.values}, not "${v}".${weight != null && meant ? ` ${meant} sets weight ${HEADING_WEIGHTS[meant]}.` : ''}`,
1216
1321
  {
1217
- didYouMean: nearest(v, [
1218
- ...Object.keys(HEADING_WEIGHTS),
1219
- ...Object.keys(HEADING_TRACKING),
1220
- ]),
1221
- run: [
1222
- setLine(
1223
- slug,
1224
- 'headings',
1225
- nearest(v, [
1226
- ...Object.keys(HEADING_WEIGHTS),
1227
- ...Object.keys(HEADING_TRACKING),
1228
- ])[0] ?? Object.keys(HEADING_WEIGHTS)[0],
1229
- s,
1230
- ),
1231
- ],
1322
+ didYouMean: meant ? [meant] : [],
1323
+ run: meant
1324
+ ? [setLine(slug, 'headings', meant, s)]
1325
+ : [`${HOW} headings`],
1232
1326
  },
1233
1327
  );
1328
+ }
1234
1329
  return s;
1235
1330
  }
1236
1331
  if (unset) return s;
@@ -1309,17 +1404,26 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
1309
1404
  const edge = /** @type {[string, number]} */ (
1310
1405
  v === 'more' ? L[L.length - 1] : L[0]
1311
1406
  );
1407
+ // The example stays inside what the dial takes (text-size: 10 to
1408
+ // 32); at that end, the exact token takes the size instead.
1409
+ const [lo, hi] = thing === 'text-size' ? [10, 32] : [0, Infinity];
1410
+ const want = Math.round(px + (v === 'more' ? 2 : -2));
1411
+ const atEnd = v === 'more' ? px >= hi : px <= lo;
1312
1412
  const example = String(cur).replace(
1313
1413
  /\d*\.?\d+/,
1314
- String(Math.max(0, Math.round(px + (v === 'more' ? 2 : -2)))),
1414
+ String(Math.max(lo, Math.min(hi, want))),
1315
1415
  );
1316
1416
  refuse(
1317
1417
  E.ERR_THEME_BAD_VALUE,
1318
- `${thing} is ${typeof cur === 'number' ? `${cur}px` : cur}, already ${v === 'more' ? 'above' : 'below'} its ${v === 'more' ? 'largest' : 'smallest'} step (${edge[0]}, ${edge[1]}px), so "${v}" has nowhere to go. Give an exact size.`,
1418
+ `${thing} is ${typeof cur === 'number' ? `${cur}px` : cur}, already ${v === 'more' ? 'above' : 'below'} its ${v === 'more' ? 'largest' : 'smallest'} step (${edge[0]}, ${edge[1]}px), so "${v}" has nowhere to go.${atEnd ? ` It is also the ${v === 'more' ? 'largest' : 'smallest'} size ${thing} takes (${lo} to ${hi}); the base font size token takes any size.` : ' Give an exact size.'}`,
1319
1419
  {
1320
- run: [
1321
- `${P} set ${slug} ${thing} ${quoteCommandArgument(example)}${s.on ? ` --on ${s.on}` : ''}`,
1322
- ],
1420
+ run: atEnd
1421
+ ? [
1422
+ `${P} set ${slug} --font-size-base ${quoteCommandArgument(`${Math.max(1, want)}px`)}`,
1423
+ ]
1424
+ : [
1425
+ `${P} set ${slug} ${thing} ${quoteCommandArgument(example)}${s.on ? ` --on ${s.on}` : ''}`,
1426
+ ],
1323
1427
  },
1324
1428
  );
1325
1429
  }
@@ -1469,9 +1573,12 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
1469
1573
  } else {
1470
1574
  // A rung in any case, a size in px written any way: the plain form.
1471
1575
  const lower = v.toLowerCase();
1472
- const px = /^(\d+(?:\.\d+)?|\.\d+)px$/.exec(lower);
1576
+ // Any CSS number in px (2e1px, +4px), the shared length parse.
1577
+ const pxLen = /px$/.test(lower) ? lengthPx(lower) : null;
1473
1578
  if (CORNERS.some(([n]) => n === lower)) s.value = lower;
1474
- else if (px) s.value = `${Number(px[1])}px`;
1579
+ else if (pxLen != null && pxLen >= 0)
1580
+ s.value =
1581
+ pxLen >= 1000 ? 'pill' : `${Math.round(pxLen * 10000) / 10000}px`;
1475
1582
  else if (lower === '0') s.value = 'square';
1476
1583
  else {
1477
1584
  // What it most likely means, as a value corners takes: a simple
@@ -1741,7 +1848,7 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
1741
1848
  const family = !parts && matchValue('font-family', v);
1742
1849
  const example = `${P} set ${slug} font-family ${quoteCommandArgument(exampleOf('font', 'font-family'))} --on ${s.on}`;
1743
1850
  const runs = parts
1744
- ? parts.system
1851
+ ? parts.system || parts.repeat
1745
1852
  ? [example]
1746
1853
  : Object.entries(parts).map(
1747
1854
  ([k, x]) =>
@@ -1754,9 +1861,11 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
1754
1861
  : [example];
1755
1862
  refuse(
1756
1863
  E.ERR_THEME_BAD_VALUE,
1757
- parts?.system
1758
- ? `font --on takes body, heading, or code, and "${v}" is a system font keyword of the CSS font shorthand, which sets every part of the font at once. For one part's font use font-family with a family.`
1759
- : `font --on takes body, heading, or code. For one part's font use font-family${parts ? ', and the other parts of the font shorthand one by one' : ''}.`,
1864
+ parts?.repeat
1865
+ ? `font --on takes body, heading, or code, and "${v}" ${parts.part?.includes(',') ? `gives ${parts.repeat} more times than the parts that take it (${parts.part})` : `gives ${parts.part ?? 'one part of the font'} twice (${parts.repeat} is the second)`}, which no CSS font value does. For one part's font use font-family with a family, and set each other part of the font once.`
1866
+ : parts?.system
1867
+ ? `font --on takes body, heading, or code, and "${v}" is a system font keyword of the CSS font shorthand, which sets every part of the font at once. For one part's font use font-family with a family.`
1868
+ : `font --on takes body, heading, or code. For one part's font use font-family${parts ? ', and the other parts of the font shorthand one by one' : ''}.`,
1760
1869
  {run: runs},
1761
1870
  );
1762
1871
  }
@@ -1876,15 +1985,26 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
1876
1985
  .toLowerCase()
1877
1986
  .replace(/^base\s*[=:]\s*/, '')
1878
1987
  .trim();
1988
+ // The base named in other letters is the one meant; a guess is only
1989
+ // among the bases installed here (and none).
1879
1990
  const near = [...LIKE, 'none'].includes(meant)
1880
1991
  ? [meant]
1881
- : nearest(meant, [...LIKE, 'none']);
1992
+ : nearest(meant, [
1993
+ ...LIKE.filter(b => baseInstalled(ctx.project, b)),
1994
+ 'none',
1995
+ ]);
1882
1996
  refuse(
1883
1997
  E.ERR_THEME_BAD_VALUE,
1884
1998
  `base takes ${DIALS.base.values}, not "${v}".`,
1885
1999
  {
1886
2000
  didYouMean: near,
1887
- run: near[0] ? [`${P} set ${slug} base ${near[0]}`] : [],
2001
+ // With nothing near, every base that works here, none first.
2002
+ run: near[0]
2003
+ ? [`${P} set ${slug} base ${near[0]}`]
2004
+ : [
2005
+ 'none',
2006
+ ...LIKE.filter(b => baseInstalled(ctx.project, b)),
2007
+ ].map(b => `${P} set ${slug} base ${b}`),
1888
2008
  },
1889
2009
  );
1890
2010
  }
@@ -1965,6 +2085,7 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
1965
2085
  C.typeOf,
1966
2086
  slug,
1967
2087
  C.propsReading(thing),
2088
+ multipliedTokens(ctx.project).has(thing),
1968
2089
  );
1969
2090
  checkCycle(thing, v, TOKENS, data);
1970
2091
  // With no part data, what reads the token is unknown: save, unchecked.
@@ -2131,7 +2252,13 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
2131
2252
  // With a state, the other mode would take one variant's value for
2132
2253
  // every variant, so any part whose variants read their own value needs
2133
2254
  // the variant named.
2134
- if (s.mode && !s.when) {
2255
+ // Per-variant colors only: a value that is not a color is refused for
2256
+ // --mode below, with the reason that holds.
2257
+ if (
2258
+ s.mode &&
2259
+ !s.when &&
2260
+ (COLOR_PROPS.test(prop) || (prop === 'background' && isColorValue(v)))
2261
+ ) {
2135
2262
  const g = C.groupOfProp(
2136
2263
  prop === 'background' ? 'background-color' : prop,
2137
2264
  );
@@ -2232,8 +2359,12 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
2232
2359
  !COLOR_PROPS.test(prop) &&
2233
2360
  !(prop === 'background' && isColorValue(v))
2234
2361
  ) {
2235
- const alt =
2236
- prop === 'border' || prop.startsWith('border-')
2362
+ // A color mixed into the value (a border's) can go per mode on its
2363
+ // own; a value with none (a radius) is just set for both modes.
2364
+ const hasColor = /#[0-9a-f]{3,8}\b|rgba?\(|hsla?\(/i.test(v);
2365
+ const alt = !hasColor
2366
+ ? null
2367
+ : prop === 'border' || prop.startsWith('border-')
2237
2368
  ? 'border-color'
2238
2369
  : prop === 'background'
2239
2370
  ? 'background-color'
@@ -16,14 +16,6 @@ export function alphaOf(value: unknown): number;
16
16
  * @returns {Rgb}
17
17
  */
18
18
  export function compositeOver(over: Rgb, alpha: number, under: Rgb): Rgb;
19
- /**
20
- * A value split at `sep` outside brackets: `a(b, c), d` by `,` is
21
- * [`a(b, c)`, ` d`]. A space separator also splits runs of spaces.
22
- * @param {string} v
23
- * @param {',' | ' '} sep
24
- * @returns {string[]}
25
- */
26
- export function splitTop(v: string, sep: "," | " "): string[];
27
19
  /**
28
20
  * One side of a color-mix(): the color, and the share written before or
29
21
  * after it at the top level (null when none). A percentage inside the
@@ -77,6 +69,7 @@ export function ratio(a: number[], b: number[]): number;
77
69
  * @param {string} v
78
70
  */
79
71
  export function isSafeValue(v: string): boolean;
72
+ export { splitTop };
80
73
  /** The CSS named colors, for suggestions. */
81
74
  export const COLOR_NAMES: string[];
82
75
  export function hex(rgb: number[]): string;
@@ -88,3 +81,4 @@ export type Num = {
88
81
  unit: string;
89
82
  };
90
83
  export type Rgb = [number, number, number];
84
+ import { splitTop } from './_css.mjs';