@astryxdesign/cli 0.7.15 → 0.7.16-canary.g8514aae

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 (116) hide show
  1. package/README.md +5 -3
  2. package/api/component/_adapter.d.mts +1 -1
  3. package/api/component/_adapter.mjs +28 -1
  4. package/api/doctor/_adapter.d.mts +17 -0
  5. package/api/doctor/_adapter.mjs +35 -0
  6. package/api/doctor/doctor.mjs +18 -4
  7. package/api/integration/validate-integration.mjs +1 -1
  8. package/api/theme/_adapter.d.mts +5 -2
  9. package/api/theme/_adapter.mjs +43 -12
  10. package/api/theme/build/build.d.mts +1 -21
  11. package/api/theme/build/build.mjs +149 -37
  12. package/api/theme/eject/eject.mjs +22 -1
  13. package/api/theme/template/template.d.mts +19 -0
  14. package/api/theme/template/template.mjs +91 -19
  15. package/api/theme/theme.type.d.mts +5 -1
  16. package/api/theme/theme.type.mjs +2 -1
  17. package/api/theme/themeBuild.doc.mjs +3 -3
  18. package/api/theme/themeEject.doc.mjs +1 -1
  19. package/api/theme/themeTemplate.doc.mjs +9 -3
  20. package/api/theme-edit/_adapter.d.mts +21 -0
  21. package/api/theme-edit/_adapter.mjs +176 -22
  22. package/api/theme-edit/_check.d.mts +7 -0
  23. package/api/theme-edit/_check.mjs +1050 -173
  24. package/api/theme-edit/_color.d.mts +2 -8
  25. package/api/theme-edit/_color.mjs +292 -219
  26. package/api/theme-edit/_compiler.d.mts +1 -0
  27. package/api/theme-edit/_compiler.mjs +20 -1
  28. package/api/theme-edit/_context.d.mts +21 -0
  29. package/api/theme-edit/_context.mjs +235 -12
  30. package/api/theme-edit/_css.d.mts +50 -1
  31. package/api/theme-edit/_css.mjs +310 -28
  32. package/api/theme-edit/_edit.d.mts +9 -0
  33. package/api/theme-edit/_edit.mjs +907 -123
  34. package/api/theme-edit/_how-commands.d.mts +11 -26
  35. package/api/theme-edit/_how-commands.mjs +30 -2
  36. package/api/theme-edit/_how-question.d.mts +7 -0
  37. package/api/theme-edit/_how-question.mjs +1304 -176
  38. package/api/theme-edit/_how.mjs +144 -30
  39. package/api/theme-edit/_palette.d.mts +6 -0
  40. package/api/theme-edit/_palette.mjs +164 -62
  41. package/api/theme-edit/_parts.d.mts +16 -0
  42. package/api/theme-edit/_parts.mjs +49 -1
  43. package/api/theme-edit/_png.mjs +19 -14
  44. package/api/theme-edit/_preview-app.mjs +514 -27
  45. package/api/theme-edit/_preview.d.mts +11 -0
  46. package/api/theme-edit/_preview.mjs +245 -24
  47. package/api/theme-edit/_project.d.mts +11 -0
  48. package/api/theme-edit/_project.mjs +35 -9
  49. package/api/theme-edit/_settings.d.mts +122 -5
  50. package/api/theme-edit/_settings.mjs +1363 -71
  51. package/api/theme-edit/_tables.d.mts +19 -0
  52. package/api/theme-edit/_tables.mjs +205 -149
  53. package/api/theme-edit/_vet.d.mts +42 -0
  54. package/api/theme-edit/_vet.mjs +144 -0
  55. package/api/theme-edit/theme-edit.type.d.mts +2 -1
  56. package/api/theme-edit/theme-edit.type.mjs +1 -1
  57. package/api/theme-edit/themeEditNew.doc.mjs +1 -1
  58. package/api/theme-edit/themeEditShow.doc.mjs +11 -3
  59. package/assets/docs/tree/single-component.doc.mjs +11 -2
  60. package/assets/docs/tree/tokens-and-setup.doc.mjs +39 -3
  61. package/assets/docs.generated.json +2 -2
  62. package/assets/preview-app/next.config.mjs +7 -1
  63. package/assets/preview-app/src/app/globals.css +1 -0
  64. package/assets/self-audit.generated.json +1 -1
  65. package/assets/templates/blocks/components/Table/ColumnsVirtualizationHookUsage.doc.mjs +14 -0
  66. package/assets/templates/blocks/components/Table/ColumnsVirtualizationHookUsage.tsx +53 -0
  67. package/assets/templates/blocks/components/Table/InfiniteScrollHookUsage.doc.mjs +14 -0
  68. package/assets/templates/blocks/components/Table/InfiniteScrollHookUsage.tsx +33 -0
  69. package/assets/templates/components.generated.json +1 -1
  70. package/authoring/doctypes/_schema.d.mts +52 -5
  71. package/authoring/doctypes/_schema.mjs +62 -7
  72. package/authoring/doctypes/base/type.ts +10 -0
  73. package/authoring/doctypes/component/component.doc.mjs +1 -1
  74. package/authoring/doctypes/function/function.doc.mjs +6 -0
  75. package/authoring/doctypes/function/type.ts +3 -0
  76. package/authoring/doctypes/legacy.mjs +5 -1
  77. package/authoring/index.d.ts +1 -0
  78. package/clients/cli/build-id.generated.json +1 -1
  79. package/clients/cli/commands/doctor.doc.mjs +2 -2
  80. package/clients/cli/commands/experimental/theme.mjs +188 -37
  81. package/clients/cli/commands/experimental-theme-compile.doc.mjs +2 -2
  82. package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +1 -1
  83. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +2 -2
  84. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +1 -1
  85. package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
  86. package/clients/cli/commands/experimental-theme-eject.doc.mjs +1 -1
  87. package/clients/cli/commands/experimental-theme-template.doc.mjs +2 -2
  88. package/clients/cli/commands/theme-build.doc.mjs +2 -2
  89. package/clients/cli/commands/theme-eject.doc.mjs +1 -1
  90. package/clients/cli/commands/theme-template.doc.mjs +3 -1
  91. package/clients/cli/commands/theme.mjs +89 -6
  92. package/clients/cli/formatters/index.mjs +7 -4
  93. package/clients/cli/lib/cli-error.mjs +9 -3
  94. package/clients/cli/lib/component-format.mjs +27 -9
  95. package/clients/cli/lib/json-shim.mjs +40 -2
  96. package/clients/cli/manifest.generated.json +1 -1
  97. package/foundation/config/project.mjs +50 -14
  98. package/foundation/discovery/theme-discovery.d.mts +5 -1
  99. package/foundation/discovery/theme-discovery.mjs +24 -3
  100. package/foundation/fs/gather-cache.d.mts +9 -2
  101. package/foundation/fs/gather-cache.mjs +36 -10
  102. package/foundation/fs/paths.d.mts +16 -0
  103. package/foundation/fs/paths.mjs +25 -0
  104. package/foundation/render/host-exit.d.mts +8 -0
  105. package/foundation/render/host-exit.mjs +11 -0
  106. package/foundation/render/page-host.mjs +56 -10
  107. package/foundation/render/page-worker.mjs +14 -0
  108. package/foundation/render/render-page.mjs +37 -2
  109. package/foundation/response/error-codes.d.mts +2 -1
  110. package/foundation/response/error-codes.d.ts +1 -0
  111. package/foundation/response/error-codes.doc.mjs +5 -0
  112. package/foundation/response/error-codes.mjs +3 -0
  113. package/foundation/response/json.d.mts +15 -0
  114. package/foundation/response/json.mjs +52 -1
  115. package/foundation/response/response-types.doc.mjs +1 -1
  116. package/package.json +7 -6
@@ -28,8 +28,14 @@ import {
28
28
  familyOf,
29
29
  } from './_tables.mjs';
30
30
  import {colorsAt, decodePng, mainColors} from './_png.mjs';
31
- import {baseThemeFile, installLine} from './_project.mjs';
32
- import {loadTheme, nearest, refuse, themeSourceProblem} from './_settings.mjs';
31
+ import {baseInstalled, installLine} from './_project.mjs';
32
+ import {
33
+ editedThemes,
34
+ loadTheme,
35
+ nearest,
36
+ refuse,
37
+ themeSourceProblem,
38
+ } from './_settings.mjs';
33
39
  import {ASPECTS, checkSetting} from './_check.mjs';
34
40
  import {MODAL} from './_compiler.mjs';
35
41
  import {PALETTE_DIALS, mappingRows, paletteFiles} from './_palette.mjs';
@@ -182,7 +188,25 @@ function withPrefix(value, cwd) {
182
188
  */
183
189
  async function answer(subject, options, cwd) {
184
190
  const {list, at = [], count} = options;
185
- const t = (subject ?? '').trim();
191
+ // "½rem": a fraction is a number before anything reads the question.
192
+ const t = (subject ?? '')
193
+ .trim()
194
+ .replace(/(\d*)(?:½|1\u20442)/g, (_, n) => `${n ? Number(n) + 0.5 : '0.5'}`)
195
+ .replace(
196
+ /(\d*)(?:¼|1\u20444)/g,
197
+ (_, n) => `${n ? Number(n) + 0.25 : '0.25'}`,
198
+ )
199
+ .replace(
200
+ /(\d*)(?:¾|3\u20444)/g,
201
+ (_, n) => `${n ? Number(n) + 0.75 : '0.75'}`,
202
+ );
203
+ // "explain spacing", "tell me about the accent": the lookup of what is
204
+ // named, never a change.
205
+ const explain =
206
+ /^(?:explain|describe|tell me about)\s+(?:the |my )?([a-z][a-z -]*?)\s*$/i.exec(
207
+ t,
208
+ );
209
+ if (explain && explain[1] !== t) return answer(explain[1], options, cwd);
186
210
  // --theme names a theme whatever the subject, so a bad one is refused
187
211
  // for a picture and a list too.
188
212
  if (options.theme === '')
@@ -246,6 +270,22 @@ async function answer(subject, options, cwd) {
246
270
  },
247
271
  );
248
272
  }
273
+ // "how b make buttons pill": a first word typed as its own argument that
274
+ // names an existing theme, with more words after it, is the theme, as for
275
+ // set, show and undo. A quoted question ("how 'accent red'") is one
276
+ // argument: its first word is never a theme.
277
+ const argv = /** @type {string[] | undefined} */ (options.words);
278
+ if (
279
+ !options.theme &&
280
+ argv &&
281
+ argv.length >= 2 &&
282
+ editedThemes(cwd).includes(argv[0])
283
+ )
284
+ return answer(
285
+ argv.slice(1).join(' '),
286
+ {...options, words: undefined, theme: argv[0]},
287
+ cwd,
288
+ );
249
289
  const ctx = await context(cwd);
250
290
  const {C} = ctx;
251
291
  const env = await howTheme(ctx, cwd, options.theme);
@@ -332,14 +372,8 @@ async function answer(subject, options, cwd) {
332
372
  const d = DIALS[key];
333
373
  // A base is named only when it is installed here; the others are
334
374
  // listed with the line that installs them.
335
- const installed = (/** @type {string} */ b) => {
336
- try {
337
- baseThemeFile(ctx.project, b);
338
- return true;
339
- } catch {
340
- return false;
341
- }
342
- };
375
+ const installed = (/** @type {string} */ b) =>
376
+ baseInstalled(ctx.project, b);
343
377
  const missing = key === 'base' ? LIKE.filter(b => !installed(b)) : [];
344
378
  return {
345
379
  kind: 'setting',
@@ -459,7 +493,7 @@ async function answer(subject, options, cwd) {
459
493
  };
460
494
  }
461
495
  // A question about the tool itself gets the command that answers it.
462
- const tool = toolAnswer(t, env);
496
+ const tool = toolAnswer(t, env, ctx.project.target);
463
497
  if (tool === 'list') {
464
498
  const kind =
465
499
  /\b(dials?|tokens?|parts?|groups?|properties|property)\b/i
@@ -650,21 +684,22 @@ function partAnswer(ctx, env, subject, key, unknown, themeFields) {
650
684
  const group = familyOf(key);
651
685
  // Only the states set takes on this part (it refuses one that never
652
686
  // applies there).
687
+ // Only the states set takes on this part: a state is dropped when the
688
+ // same change without it passes and with it is refused.
689
+ const takes = (/** @type {string | undefined} */ st) => {
690
+ try {
691
+ checkSetting(ctx, env.slug, env.data, 'opacity', '1', {
692
+ on: key,
693
+ ...(st ? {state: st} : {}),
694
+ });
695
+ return true;
696
+ } catch {
697
+ return false;
698
+ }
699
+ };
700
+ const plainOk = takes(undefined);
653
701
  const states = [...new Set([...target.states, ...COMMON_STATES])].filter(
654
- st => {
655
- try {
656
- checkSetting(ctx, env.slug, env.data, 'opacity', '1', {
657
- on: key,
658
- state: st,
659
- });
660
- return true;
661
- } catch (e) {
662
- return !(
663
- /** @type {any} */ (e)?.code === 'ERR_THEME_NO_EFFECT' &&
664
- /--state/.test(String(/** @type {any} */ (e)?.message))
665
- );
666
- }
667
- },
702
+ st => !plainOk || takes(st),
668
703
  );
669
704
  const reads = Object.fromEntries(
670
705
  Object.keys(GROUPS).map(g => [
@@ -845,8 +880,11 @@ function tokenAnswer(ctx, env, subject, key, unknown, themeFields) {
845
880
  const {C} = ctx;
846
881
  const readers = C.anyReader(key);
847
882
  const type = C.typeOf(key);
883
+ // The theme's own value (its settings applied), else the base theme's.
848
884
  const now =
849
- env.base.light[key] ?? String(ctx.project.core.tokenDefaults[key]);
885
+ env.own?.light[key] ??
886
+ env.base.light[key] ??
887
+ String(ctx.project.core.tokenDefaults[key]);
850
888
  const value = exampleForToken(type, key, now);
851
889
  const {commands, refused} = value
852
890
  ? checked(env, [
@@ -937,9 +975,10 @@ function colorsAnswer(env, dialCommands) {
937
975
  * the caller lists the kind the question names.
938
976
  * @param {string} t
939
977
  * @param {import('./_how-commands.mjs').HowTheme} env
978
+ * @param {Map<string, unknown>} targets the parts Core styles
940
979
  * @returns {Array<{text: string, commands: string[]}> | 'list' | null}
941
980
  */
942
- function toolAnswer(t, env) {
981
+ function toolAnswer(t, env, targets) {
943
982
  const q = t
944
983
  .trim()
945
984
  .toLowerCase()
@@ -1011,7 +1050,82 @@ function toolAnswer(t, env) {
1011
1050
  commands: [`${P} new ${env.slug}-2 --like ${env.data.like ?? 'none'}`],
1012
1051
  },
1013
1052
  ];
1014
- if (/\b(version|which cli|what cli)\b/.test(q))
1053
+ // Screen-size, print and device conditions: the editor has none.
1054
+ if (
1055
+ /\bmedia quer|^(on|for) (mobile|phones?|tablets?|desktops?|print)$|^(print|printing|print styles?)$/.test(
1056
+ q,
1057
+ )
1058
+ )
1059
+ return [
1060
+ {
1061
+ text: 'the theme editor has no screen-size, print or device conditions: every setting applies on every screen; a media query needs your own CSS',
1062
+ commands: [`${HOW} --help`],
1063
+ },
1064
+ ];
1065
+ // Questions about what is set now, or the choices: a lookup, never a
1066
+ // write.
1067
+ const asks =
1068
+ /^(how (round|big|small|large|thick|dark|light|bold|wide|tall) (is|are)|what (is|are) the (current|available)|which \w+ (does|do|is|are)|what (font|color|colour|radius|accent) (does|do|is|are)|what (values|options|choices))\b|\b(right now|currently|at the moment)\??$|\bnow\?$/.exec(
1069
+ q,
1070
+ );
1071
+ // "is my theme valid", "how many dials", "list every change".
1072
+ if (
1073
+ /^(is|are) (my|the|this) theme (valid|ok|okay|broken|working)\b|^(check|validate) (my|the) theme\b/.test(
1074
+ q,
1075
+ )
1076
+ )
1077
+ return [
1078
+ {
1079
+ text: `show builds ${env.slug} and says what is wrong with it, if anything`,
1080
+ commands: [`${P} show ${env.slug}`],
1081
+ },
1082
+ ];
1083
+ if (
1084
+ /^how many (dials|settings|tokens|parts)\b|^(list|show) (every|all|each) (dial|setting|token|part)s?\b/.test(
1085
+ q,
1086
+ )
1087
+ )
1088
+ return 'list';
1089
+ if (/^(list|show) (every|all|my) (changes?|edits?|settings)\b/.test(q))
1090
+ return [
1091
+ {
1092
+ text: `show lists every setting ${env.slug} has`,
1093
+ commands: [`${P} show ${env.slug}`],
1094
+ },
1095
+ ];
1096
+ if (
1097
+ asks ||
1098
+ /^which parts (are|does|do)\b/.test(q) ||
1099
+ (/^why (is|are|does|do)\b/.test(q) && !/\bnot\b|n'?t\b/.test(q))
1100
+ ) {
1101
+ // The part or setting the question names gets its own lookup.
1102
+ const named = q
1103
+ .split(/[^a-z-]+/)
1104
+ .find(
1105
+ w =>
1106
+ w.length > 2 &&
1107
+ (targets.has(w) ||
1108
+ targets.has(w.replace(/s$/, '')) ||
1109
+ ['inputs', 'checks'].includes(w)),
1110
+ );
1111
+ const key =
1112
+ named && !targets.has(named) && !['inputs', 'checks'].includes(named)
1113
+ ? named.replace(/s$/, '')
1114
+ : named;
1115
+ return [
1116
+ {
1117
+ text: key
1118
+ ? `how ${key} says what ${key} reads and what sets it; show lists what ${env.slug} sets now`
1119
+ : `show lists what ${env.slug} sets now; how <part> or how <setting> says what a part reads and the values a setting takes`,
1120
+ commands: [...(key ? [`${HOW} ${key}`] : []), `${P} show ${env.slug}`],
1121
+ },
1122
+ ];
1123
+ }
1124
+ if (
1125
+ /\b((astryx|cli) version|version of (the )?(cli|astryx)|which cli|what cli)\b/.test(
1126
+ q,
1127
+ )
1128
+ )
1015
1129
  return [{text: 'the CLI says its version', commands: ['astryx --version']}];
1016
1130
  if (/\bwhere (are|is|do) .*\b(stored|saved|kept|live|files?)\b/.test(q))
1017
1131
  return [
@@ -1070,7 +1184,7 @@ function wholeThemeTokens(ctx, env, aspect) {
1070
1184
  /** @type {string[]} */
1071
1185
  let commands = [];
1072
1186
  for (const tok of toks) {
1073
- const now = env.base.light[tok] ?? '';
1187
+ const now = env.own?.light[tok] ?? env.base.light[tok] ?? '';
1074
1188
  if (parseFloat(now) >= 999) continue;
1075
1189
  const value = exampleForToken(C.typeOf(tok), tok, now);
1076
1190
  if (!value) continue;
@@ -175,6 +175,7 @@ export function mappingRows(dial: string): string[];
175
175
  * @returns {string[]}
176
176
  */
177
177
  export function paletteNotes(pal: PaletteMapping | null, dial: string, slug: string, modes?: Mode[]): string[];
178
+ export function isEditorTemp(name: string): boolean;
178
179
  /** @typedef {'light' | 'dark'} Mode */
179
180
  /** @typedef {import('./_settings.mjs').Setting} Setting */
180
181
  /** @typedef {import('../theme/theme.type.mjs').TonalPaletteCandidate} Candidate */
@@ -210,6 +211,7 @@ export function paletteNotes(pal: PaletteMapping | null, dial: string, slug: str
210
211
  * @property {ContrastCheck[]} contrast
211
212
  * @property {number} vibrancy - The generator's vibrancy, 0 to 100.
212
213
  * @property {Record<string, Partial<Record<Mode, string>>>} exact - Main tokens the theme sets exactly, the value per mode: the dial's fill gives way to them.
214
+ * @property {Record<string, string>} [unread] - Main tokens the theme sets exactly to a value the editor cannot read as one color in some mode, as written: the text on them is not picked for that value.
213
215
  * @property {string[]} notes - What the config writer kept or replaced of a hand edit.
214
216
  * @property {Record<string, Partial<Record<Mode, StopRef>>> | null} lift - Lifted secondary text per background token of LIFT_PARTS (the accent tint, the neutral track), per mode, from the neutral color; null without one.
215
217
  */
@@ -330,6 +332,10 @@ export type PaletteMapping = {
330
332
  * - Main tokens the theme sets exactly, the value per mode: the dial's fill gives way to them.
331
333
  */
332
334
  exact: Record<string, Partial<Record<Mode, string>>>;
335
+ /**
336
+ * - Main tokens the theme sets exactly to a value the editor cannot read as one color in some mode, as written: the text on them is not picked for that value.
337
+ */
338
+ unread?: Record<string, string> | undefined;
333
339
  /**
334
340
  * - What the config writer kept or replaced of a hand edit.
335
341
  */
@@ -45,7 +45,8 @@ import {
45
45
  parseColor,
46
46
  ratio,
47
47
  } from './_color.mjs';
48
- import {P} from './_tables.mjs';
48
+ import {splitTop} from './_css.mjs';
49
+ import {P, wordTable} from './_tables.mjs';
49
50
  import {quoteCommandArgument} from '../../foundation/env/package-manager.mjs';
50
51
  import {sha256} from '../../foundation/render/source-block.mjs';
51
52
 
@@ -114,7 +115,8 @@ const STARTED_AT = Date.now() - process.uptime() * 1000;
114
115
  /**
115
116
  * Remove the editor's own temp files a stopped command left in a folder:
116
117
  * only names the editor makes (`.<name>.astryx-<pid>-<random>.tmp`) whose
117
- * process is gone, or that are older than ten minutes. Links are never
118
+ * process is gone, or that are older than ten minutes, and a build's
119
+ * `.<name>.tmp-<id>` older than ten minutes. Links are never
118
120
  * followed. A theme folder holds a few files, so every write looks.
119
121
  * @param {string} dir
120
122
  */
@@ -126,6 +128,20 @@ function sweepTemps(dir) {
126
128
  return;
127
129
  }
128
130
  for (const n of names) {
131
+ // A build's own temp (`.<name>.tmp-<id>`) names no process: one older
132
+ // than ten minutes is a leftover of a command stopped mid-build (a
133
+ // build renames it in moments).
134
+ if (/^\..+\.tmp-[\w-]+$/.test(n)) {
135
+ const p = path.join(dir, n);
136
+ try {
137
+ const st = fs.lstatSync(p);
138
+ if (st.isFile() && Date.now() - st.mtimeMs >= 10 * 60_000)
139
+ fs.rmSync(p, {force: true});
140
+ } catch {
141
+ // Gone already.
142
+ }
143
+ continue;
144
+ }
129
145
  const m = /^\..+\.astryx-(\d+)-[a-z0-9]+\.tmp$/.exec(n);
130
146
  if (!m) continue;
131
147
  const p = path.join(dir, n);
@@ -171,6 +187,15 @@ export function removeEmptyFolder(dir, opts = {}) {
171
187
  }
172
188
  }
173
189
 
190
+ /**
191
+ * Whether a file name is one of the editor's own temp files: a whole-file
192
+ * write's `.<name>.astryx-<pid>-<random>.tmp`, or a build's
193
+ * `.<name>.tmp-<id>`. A command stopped part way can leave one behind.
194
+ * @param {string} name
195
+ */
196
+ export const isEditorTemp = name =>
197
+ /^\..+\.(astryx-\d+-[a-z0-9]+\.tmp|tmp-[\w-]+)$/.test(name);
198
+
174
199
  /**
175
200
  * A temp file beside `file` for a whole write, named so only the editor
176
201
  * makes such names: `.<name>.astryx-<pid>-<random>.tmp`. The write that
@@ -222,6 +247,7 @@ export function tempFor(file) {
222
247
  * @property {ContrastCheck[]} contrast
223
248
  * @property {number} vibrancy - The generator's vibrancy, 0 to 100.
224
249
  * @property {Record<string, Partial<Record<Mode, string>>>} exact - Main tokens the theme sets exactly, the value per mode: the dial's fill gives way to them.
250
+ * @property {Record<string, string>} [unread] - Main tokens the theme sets exactly to a value the editor cannot read as one color in some mode, as written: the text on them is not picked for that value.
225
251
  * @property {string[]} notes - What the config writer kept or replaced of a hand edit.
226
252
  * @property {Record<string, Partial<Record<Mode, StopRef>>> | null} lift - Lifted secondary text per background token of LIFT_PARTS (the accent tint, the neutral track), per mode, from the neutral color; null without one.
227
253
  */
@@ -256,12 +282,14 @@ function dialVibrancy(settings) {
256
282
  }
257
283
 
258
284
  /** The Core token word of each status family. */
259
- const STATUS_TOKEN = /** @type {Record<string, string>} */ ({
260
- success: 'success',
261
- warning: 'warning',
262
- danger: 'error',
263
- info: 'info',
264
- });
285
+ const STATUS_TOKEN = wordTable(
286
+ /** @type {Record<string, string>} */ ({
287
+ success: 'success',
288
+ warning: 'warning',
289
+ danger: 'error',
290
+ info: 'info',
291
+ }),
292
+ );
265
293
 
266
294
  /**
267
295
  * The main token a color dial feeds: the exact-token escape hatch for it.
@@ -348,31 +376,35 @@ const officialStops = token =>
348
376
  * tinted gray never tints the page. A layout without one of these stops
349
377
  * uses the nearest one it has.
350
378
  */
351
- const NEUTRAL_STOPS = Object.fromEntries(
352
- [
353
- '--color-background-surface',
354
- '--color-background-card',
355
- '--color-background-popover',
356
- '--color-background-muted',
357
- '--color-text-primary',
358
- '--color-text-secondary',
359
- '--color-text-disabled',
360
- '--color-icon-primary',
361
- '--color-icon-secondary',
362
- '--color-icon-disabled',
363
- '--color-border-emphasized',
364
- '--color-skeleton',
365
- ].map(t => [t, officialStops(t)]),
379
+ const NEUTRAL_STOPS = wordTable(
380
+ Object.fromEntries(
381
+ [
382
+ '--color-background-surface',
383
+ '--color-background-card',
384
+ '--color-background-popover',
385
+ '--color-background-muted',
386
+ '--color-text-primary',
387
+ '--color-text-secondary',
388
+ '--color-text-disabled',
389
+ '--color-icon-primary',
390
+ '--color-icon-secondary',
391
+ '--color-icon-disabled',
392
+ '--color-border-emphasized',
393
+ '--color-skeleton',
394
+ ].map(t => [t, officialStops(t)]),
395
+ ),
366
396
  );
367
397
  /** Neutral tints: a stop with an opacity, `[[stop, alpha], [stop, alpha]]`. */
368
- const NEUTRAL_TINTS = Object.fromEntries(
369
- ['--color-border', '--color-overlay-hover', '--color-overlay-pressed'].map(
370
- t => [
371
- t,
372
- /** @type {[[number, string], [number, string]]} */ (
373
- OFFICIAL.stops[t].map(x => [x.stop, String(x.alpha)])
374
- ),
375
- ],
398
+ const NEUTRAL_TINTS = wordTable(
399
+ Object.fromEntries(
400
+ ['--color-border', '--color-overlay-hover', '--color-overlay-pressed'].map(
401
+ t => [
402
+ t,
403
+ /** @type {[[number, string], [number, string]]} */ (
404
+ OFFICIAL.stops[t].map(x => [x.stop, String(x.alpha)])
405
+ ),
406
+ ],
407
+ ),
376
408
  ),
377
409
  );
378
410
  /**
@@ -426,20 +458,24 @@ const BORDER = /** @type {[number, number]} */ ([80, 65]);
426
458
  * first in both modes on warning. Without a neutral color, black and white.
427
459
  */
428
460
  const [ON_LIGHT, ON_DARK] = officialStops('--color-on-accent');
429
- const ON_FILL = /** @type {Record<Mode, [number, number]>} */ ({
430
- light: [ON_LIGHT, ON_DARK],
431
- dark: [ON_DARK, ON_LIGHT],
432
- });
461
+ const ON_FILL = wordTable(
462
+ /** @type {Record<Mode, [number, number]>} */ ({
463
+ light: [ON_LIGHT, ON_DARK],
464
+ dark: [ON_DARK, ON_LIGHT],
465
+ }),
466
+ );
433
467
  /** A layout needs this many stops between black and white to map every token. */
434
468
  const MIN_INNER_STOPS = 5;
435
469
  /** The widest gap between two stops that still maps every token near its stop. */
436
470
  const MAX_STOP_GAP = 25;
437
471
 
438
472
  /** Text on surfaces darkens in light mode and lightens in dark mode. */
439
- const TOWARD_CONTRAST = /** @type {Record<Mode, 1 | -1>} */ ({
440
- light: -1,
441
- dark: 1,
442
- });
473
+ const TOWARD_CONTRAST = wordTable(
474
+ /** @type {Record<Mode, 1 | -1>} */ ({
475
+ light: -1,
476
+ dark: 1,
477
+ }),
478
+ );
443
479
 
444
480
  /** @param {string} slug */
445
481
  export function paletteFiles(slug) {
@@ -735,11 +771,12 @@ function tools(candidate, data, base) {
735
771
  };
736
772
  const neutral = Boolean(/** @type {any} */ (candidate.palette).neutral);
737
773
  /**
738
- * The exact whole-theme color a token setting gives in a mode, or null.
774
+ * The whole-theme value a token setting gives in a mode, as written, or
775
+ * undefined.
739
776
  * @param {string} token @param {Mode} m
740
777
  */
741
- const exactOf = (token, m) => {
742
- const v = [...data.settings]
778
+ const settingOf = (token, m) =>
779
+ [...data.settings]
743
780
  .reverse()
744
781
  .find(
745
782
  s =>
@@ -750,29 +787,60 @@ function tools(candidate, data, base) {
750
787
  !s.state &&
751
788
  (!s.mode || s.mode === m),
752
789
  )?.value;
790
+ /**
791
+ * The fixed color a value gives in a mode, as written when it is one
792
+ * already, or null: `light-dark()` takes its side for the mode, and a
793
+ * `var()` reads the theme's own setting, else the base theme's value.
794
+ * @param {unknown} value @param {Mode} m @param {Set<string>} [seen]
795
+ * @returns {string | null}
796
+ */
797
+ const colorIn = (value, m, seen = new Set()) => {
798
+ const v = String(value ?? '').trim();
799
+ if (!v) return null;
800
+ if (parseColor(v)) return v;
801
+ const fn = /^([a-z-]+)\((.*)\)$/is.exec(v);
802
+ if (!fn) return null;
803
+ const name = fn[1].toLowerCase();
804
+ if (name === 'light-dark') {
805
+ const halves = splitTop(fn[2], ',');
806
+ return halves.length === 2
807
+ ? colorIn(halves[m === 'dark' ? 1 : 0], m, seen)
808
+ : null;
809
+ }
810
+ if (name !== 'var') {
811
+ // A color function of tokens (a color-mix() of two) reads each one.
812
+ const put = v.replace(
813
+ /var\(\s*(--[a-z0-9-]+)\s*\)/gi,
814
+ (whole, t) => colorIn(`var(${t})`, m, new Set(seen)) ?? whole,
815
+ );
816
+ return put !== v && parseColor(put) ? put : null;
817
+ }
818
+ const [ref, ...rest] = splitTop(fn[2], ',');
819
+ const t = ref.trim();
820
+ if (!/^--[a-z0-9-]+$/i.test(t) || seen.has(t)) return null;
821
+ seen.add(t);
822
+ const own = settingOf(t, m);
823
+ const read =
824
+ own != null ? colorIn(own, m, seen) : colorIn(base?.[m]?.[t], m, seen);
825
+ return read ?? (rest.length ? colorIn(rest.join(','), m, seen) : null);
826
+ };
827
+ /**
828
+ * The exact whole-theme color a token setting gives in a mode, or null.
829
+ * @param {string} token @param {Mode} m
830
+ */
831
+ const exactOf = (token, m) => {
832
+ const v = colorIn(settingOf(token, m), m);
753
833
  const rgb = v == null ? null : parseColor(v);
754
- return rgb && alphaOf(v) >= 1 ? hex(rgb) : null;
834
+ return rgb && v != null && alphaOf(v) >= 1 ? hex(rgb) : null;
755
835
  };
756
836
  /**
757
837
  * The exact whole-theme color a token setting gives in a mode, see-through
758
- * or not, as written (a hex keeps its alpha digits); null when there is
759
- * none or it is not a fixed color.
838
+ * or not, as written (a hex keeps its alpha digits; a `light-dark()` or a
839
+ * `var()` gives the color it reads in the mode); null when there is none
840
+ * or it is not a fixed color.
760
841
  * @param {string} token @param {Mode} m
761
842
  */
762
- const rawOf = (token, m) => {
763
- const v = [...data.settings]
764
- .reverse()
765
- .find(
766
- s =>
767
- s.source === 'token' &&
768
- s.thing === token &&
769
- !s.on &&
770
- !s.when &&
771
- !s.state &&
772
- (!s.mode || s.mode === m),
773
- )?.value;
774
- return v != null && parseColor(v) ? String(v).trim() : null;
775
- };
843
+ const rawOf = (token, m) => colorIn(settingOf(token, m), m);
776
844
  /**
777
845
  * Which column of a `[light, dark]` mapping a mode takes: the light one
778
846
  * on a light page and the dark one on a dark page, by the page the theme
@@ -873,6 +941,7 @@ function tools(candidate, data, base) {
873
941
  at,
874
942
  ref,
875
943
  exactOf,
944
+ settingOf,
876
945
  rawOf,
877
946
  side,
878
947
  solid,
@@ -1123,6 +1192,16 @@ function planPalette(cwd, slug, data, base) {
1123
1192
  families.push(family);
1124
1193
  }
1125
1194
  if (!families.length) return null;
1195
+ // The editor's colors stand in the order of their settings, wherever they
1196
+ // sit among a config's own families, so a step back writes the same file.
1197
+ const slots = families
1198
+ .map((f, i) => (PALETTE_DIALS.includes(f?.id) ? i : -1))
1199
+ .filter(i => i >= 0);
1200
+ const inOrder = fams
1201
+ .map(x => families.find(f => f?.id === x.id))
1202
+ .filter(Boolean);
1203
+ if (inOrder.length === slots.length)
1204
+ slots.forEach((i, k) => (families[i] = inOrder[k]));
1126
1205
  config.families = families;
1127
1206
  const dead = deadKeys(config);
1128
1207
  if (dead.length)
@@ -1725,7 +1804,7 @@ export function paletteMapping(cwd, slug, data, base, tokenDefaults) {
1725
1804
  const {config} = plan;
1726
1805
  const candidate = generate(config, paletteFiles(slug).config);
1727
1806
  const t = tools(candidate, data, base);
1728
- const {stops, at, ref, exactOf, rawOf, side, solid, surfaces} = t;
1807
+ const {stops, at, ref, exactOf, rawOf, settingOf, side, solid, surfaces} = t;
1729
1808
  const modes = modesOf(data);
1730
1809
  /** @type {PaletteMapping['tokens']} */
1731
1810
  const tokens = {};
@@ -1733,6 +1812,8 @@ export function paletteMapping(cwd, slug, data, base, tokenDefaults) {
1733
1812
  const checks = [];
1734
1813
  /** @type {PaletteMapping['exact']} */
1735
1814
  const exact = {};
1815
+ /** @type {Record<string, string>} */
1816
+ const unread = {};
1736
1817
  const has = (/** @type {string} */ k) => k in tokenDefaults;
1737
1818
  /** A token the theme sets exactly in any mode: no check speaks for it. @param {string} k */
1738
1819
  const setExactly = k =>
@@ -1877,8 +1958,22 @@ export function paletteMapping(cwd, slug, data, base, tokenDefaults) {
1877
1958
  for (const m of modes) {
1878
1959
  const v = rawOf(names.fill, m);
1879
1960
  if (v) exactFill[m] = v;
1961
+ else if (settingOf(names.fill, m) != null)
1962
+ unread[names.fill] = String(settingOf(names.fill, m)).trim();
1880
1963
  }
1881
- if (Object.keys(exactFill).length) exact[names.fill] = exactFill;
1964
+ if (Object.keys(exactFill).length)
1965
+ exact[names.fill] = Object.fromEntries(
1966
+ Object.entries(exactFill).map(([m, v]) => {
1967
+ // A var() is named with the color it reads, so the note says
1968
+ // which color the text was picked for.
1969
+ const written = String(
1970
+ settingOf(names.fill, /** @type {Mode} */ (m)) ?? '',
1971
+ ).trim();
1972
+ const rgb = parseColor(v);
1973
+ const color = rgb && alphaOf(v) >= 1 ? hex(rgb) : v;
1974
+ return [m, /var\(/i.test(written) ? `${written} = ${color}` : v];
1975
+ }),
1976
+ );
1882
1977
 
1883
1978
  /** @type {Partial<Record<Mode, StopRef>>} */
1884
1979
  const fill = {};
@@ -2221,6 +2316,7 @@ export function paletteMapping(cwd, slug, data, base, tokenDefaults) {
2221
2316
  lift,
2222
2317
  vibrancy: config.vibrancy ?? VIBRANCY_DEFAULT,
2223
2318
  exact,
2319
+ unread,
2224
2320
  notes: [
2225
2321
  ...plan.notes,
2226
2322
  ...(paletteEdited(cwd, slug)
@@ -2350,7 +2446,13 @@ export function paletteNotes(pal, dial, slug, modes = ['light', 'dark']) {
2350
2446
  notes.push(
2351
2447
  `${token} uses your exact setting (${shown}), not the generated ${dial} shade: an exact setting wins${dial === 'neutral' ? '' : '; the text on it is picked to read on your color'}${dial === 'accent' ? ', and the focus ring keeps following it' : ''}`,
2352
2448
  );
2353
- } else if (main) {
2449
+ }
2450
+ const unread = pal.unread?.[token];
2451
+ if (unread) {
2452
+ notes.push(
2453
+ `${token} keeps your exact setting (${unread}), which the editor cannot read as one color${exact ? ' in every mode' : ''}: an exact setting wins, so the generated ${dial} shade does not show${dial === 'neutral' ? '' : ' there, and the text on it is not checked against your color: set a fixed color, or set the text color on it exactly'}`,
2454
+ );
2455
+ } else if (!exact && main) {
2354
2456
  /** @param {Mode} m */
2355
2457
  const part = m =>
2356
2458
  main[m].exact
@@ -13,6 +13,14 @@
13
13
  * @returns {Record<string, unknown> | null}
14
14
  */
15
15
  export function demoProps(project: import("./_project.mjs").ThemeProject, name: string): Record<string, unknown> | null;
16
+ /**
17
+ * Whether a part works only inside its parent: its parent lists it as an
18
+ * item, or it is a piece of its parent by name (TableBody of Table) and
19
+ * its doc gives no playground of its own.
20
+ * @param {import('./_project.mjs').ThemeProject} project
21
+ * @param {string} name
22
+ */
23
+ export function needsParent(project: import("./_project.mjs").ThemeProject, name: string): boolean;
16
24
  /**
17
25
  * Whether a part's parent lists it as an item of its children.
18
26
  * @param {import('./_project.mjs').ThemeProject} project
@@ -77,6 +85,14 @@ export function renderGenerated(project: import("./_project.mjs").ThemeProject,
77
85
  * @returns {Promise<PartData>}
78
86
  */
79
87
  export function partData(project: import("./_project.mjs").ThemeProject): Promise<PartData>;
88
+ /**
89
+ * The tokens Core's stylesheet multiplies by another value inside calc()
90
+ * (`var(--text-body-size) * var(--text-body-leading)`): a unit there makes
91
+ * the declaration invalid. Empty with no stylesheet.
92
+ * @param {any} project
93
+ * @returns {Set<string>}
94
+ */
95
+ export function multipliedTokens(project: any): Set<string>;
80
96
  /**
81
97
  * Atomic class -> its declarations, with the condition (pseudo-class,
82
98
  * attribute) each one applies under.