@astryxdesign/cli 0.7.15-canary.gf890983 → 0.7.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. package/CHANGELOG.md +353 -3
  2. package/api/doctor/_adapter.d.mts +2 -1
  3. package/api/doctor/_adapter.mjs +6 -1
  4. package/api/doctor/doctor.mjs +2 -2
  5. package/api/doctor/theme-checks.mjs +56 -21
  6. package/api/integration/add-helpers.mjs +5 -0
  7. package/api/integration/add-theme.mjs +15 -110
  8. package/api/theme/_adapter.d.mts +37 -5
  9. package/api/theme/_adapter.mjs +363 -50
  10. package/api/theme/_fork.d.mts +90 -0
  11. package/api/theme/_fork.mjs +246 -0
  12. package/api/theme/build/build.d.mts +25 -1
  13. package/api/theme/build/build.mjs +352 -41
  14. package/api/theme/eject/eject.mjs +36 -15
  15. package/api/theme/list/list.mjs +3 -6
  16. package/api/theme/palette/generate/generator.d.mts +13 -0
  17. package/api/theme/palette/generate/generator.mjs +32 -2
  18. package/api/theme/targets/targets.mjs +10 -3
  19. package/api/theme/template/template.mjs +48 -2
  20. package/api/theme/theme.type.d.mts +8 -0
  21. package/api/theme/theme.type.mjs +5 -1
  22. package/api/theme/themeBuild.doc.mjs +2 -2
  23. package/api/theme/themeRemove.doc.mjs +5 -2
  24. package/api/theme/themeTemplate.doc.mjs +2 -2
  25. package/api/theme/themeUse.doc.mjs +8 -2
  26. package/api/theme-edit/_adapter.mjs +157 -36
  27. package/api/theme-edit/_catalog.d.mts +1 -6
  28. package/api/theme-edit/_catalog.mjs +5 -268
  29. package/api/theme-edit/_check.d.mts +3 -1
  30. package/api/theme-edit/_check.mjs +733 -308
  31. package/api/theme-edit/_color.d.mts +19 -0
  32. package/api/theme-edit/_color.mjs +277 -33
  33. package/api/theme-edit/_compiler.d.mts +1 -0
  34. package/api/theme-edit/_compiler.mjs +25 -0
  35. package/api/theme-edit/_context.d.mts +2 -0
  36. package/api/theme-edit/_context.mjs +83 -9
  37. package/api/theme-edit/_css.d.mts +84 -0
  38. package/api/theme-edit/_css.mjs +700 -0
  39. package/api/theme-edit/_edit.mjs +370 -85
  40. package/api/theme-edit/_how-commands.d.mts +5 -0
  41. package/api/theme-edit/_how-commands.mjs +20 -13
  42. package/api/theme-edit/_how-question.d.mts +29 -0
  43. package/api/theme-edit/_how-question.mjs +1573 -182
  44. package/api/theme-edit/_how.mjs +306 -22
  45. package/api/theme-edit/_overview.mjs +2 -7
  46. package/api/theme-edit/_palette.d.mts +27 -5
  47. package/api/theme-edit/_palette.mjs +231 -97
  48. package/api/theme-edit/_parts.d.mts +42 -10
  49. package/api/theme-edit/_parts.mjs +224 -69
  50. package/api/theme-edit/_preview-app.d.mts +8 -0
  51. package/api/theme-edit/_preview-app.mjs +549 -96
  52. package/api/theme-edit/_preview.d.mts +7 -16
  53. package/api/theme-edit/_preview.mjs +77 -84
  54. package/api/theme-edit/_project.d.mts +20 -1
  55. package/api/theme-edit/_project.mjs +43 -13
  56. package/api/theme-edit/_settings.d.mts +96 -20
  57. package/api/theme-edit/_settings.mjs +646 -141
  58. package/api/theme-edit/_tables.d.mts +18 -12
  59. package/api/theme-edit/_tables.mjs +144 -147
  60. package/api/theme-edit/theme-edit.type.d.mts +10 -1
  61. package/api/theme-edit/theme-edit.type.mjs +3 -1
  62. package/api/theme-edit/themeEditNew.doc.mjs +1 -1
  63. package/api/theme-edit/themeEditPreviewAdd.doc.mjs +1 -1
  64. package/api/theme-edit/themeEditPreviewApp.doc.mjs +1 -1
  65. package/api/theme-edit/themeEditPreviewList.doc.mjs +2 -2
  66. package/api/theme-edit/themeEditSet.doc.mjs +1 -1
  67. package/api/theme-edit/themeEditUndo.doc.mjs +1 -1
  68. package/assets/docs/tree/publishing.doc.mjs +1 -0
  69. package/assets/docs.generated.json +2 -2
  70. package/assets/self-audit.generated.json +1 -1
  71. package/clients/cli/build-id.generated.json +1 -1
  72. package/clients/cli/commands/experimental/index.mjs +10 -10
  73. package/clients/cli/commands/experimental/theme.mjs +22 -3
  74. package/clients/cli/commands/experimental-theme-compile.doc.mjs +2 -2
  75. package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +3 -3
  76. package/clients/cli/commands/experimental-theme-preview-add.doc.mjs +1 -1
  77. package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
  78. package/clients/cli/commands/integration.mjs +8 -0
  79. package/clients/cli/commands/theme-build.doc.mjs +2 -2
  80. package/clients/cli/commands/theme-list.doc.mjs +1 -1
  81. package/clients/cli/commands/theme-template.doc.mjs +1 -1
  82. package/clients/cli/commands/theme.mjs +325 -48
  83. package/clients/cli/index.mjs +18 -3
  84. package/clients/cli/lib/cli-error.mjs +118 -3
  85. package/clients/cli/manifest.generated.json +1 -1
  86. package/foundation/config/project.mjs +34 -8
  87. package/foundation/config/theme-state.d.mts +16 -0
  88. package/foundation/config/theme-state.mjs +84 -13
  89. package/foundation/discovery/template-needs.d.mts +13 -0
  90. package/foundation/discovery/template-needs.mjs +30 -15
  91. package/foundation/discovery/theme-discovery.mjs +14 -2
  92. package/foundation/discovery/theme-imports.d.mts +16 -0
  93. package/foundation/discovery/theme-imports.mjs +30 -2
  94. package/foundation/doc-compiler/import.mjs +10 -4
  95. package/foundation/fs/gather-cache.mjs +82 -23
  96. package/foundation/fs/jiti-cache.d.mts +21 -0
  97. package/foundation/fs/jiti-cache.mjs +66 -0
  98. package/foundation/fs/module-loader.mjs +7 -2
  99. package/foundation/integrations/autolink.d.mts +1 -24
  100. package/foundation/integrations/autolink.mjs +7 -60
  101. package/foundation/integrations/declared-dependencies.d.mts +27 -0
  102. package/foundation/integrations/declared-dependencies.mjs +73 -0
  103. package/foundation/integrations/may-have-integrations.d.mts +8 -0
  104. package/foundation/integrations/may-have-integrations.mjs +47 -0
  105. package/foundation/release/cache.d.mts +21 -2
  106. package/foundation/release/cache.mjs +48 -8
  107. package/foundation/release/folder-lock.d.mts +7 -0
  108. package/foundation/release/folder-lock.mjs +60 -26
  109. package/foundation/release/lock-lease.d.mts +2 -1
  110. package/foundation/release/lock-lease.mjs +7 -2
  111. package/foundation/response/error-codes.doc.mjs +1 -1
  112. package/foundation/response/response-types.doc.mjs +4 -4
  113. package/package.json +6 -6
  114. package/api/theme-edit/_css-properties.d.mts +0 -10
  115. package/api/theme-edit/_css-properties.mjs +0 -556
@@ -13,7 +13,7 @@
13
13
  import * as fs from 'node:fs';
14
14
  import * as path from 'node:path';
15
15
  import {AstryxError} from '../error.mjs';
16
- import {CSS_PROPERTIES} from './_css-properties.mjs';
16
+ import {cssProperties} from './_css.mjs';
17
17
  import {
18
18
  AUTO_SPREAD,
19
19
  COLOR_PROPS,
@@ -30,7 +30,7 @@ import {
30
30
  import {colorsAt, decodePng, mainColors} from './_png.mjs';
31
31
  import {baseThemeFile, installLine} from './_project.mjs';
32
32
  import {loadTheme, nearest, refuse, themeSourceProblem} from './_settings.mjs';
33
- import {ASPECTS} from './_check.mjs';
33
+ import {ASPECTS, checkSetting} from './_check.mjs';
34
34
  import {MODAL} from './_compiler.mjs';
35
35
  import {PALETTE_DIALS, mappingRows, paletteFiles} from './_palette.mjs';
36
36
  import {requireProject, context} from './_context.mjs';
@@ -71,13 +71,15 @@ const PICTURE_NAME = /\.(png|jpe?g|gif|webp|bmp|avif|heic|tiff?|svg)$/i;
71
71
  * @param {string} cwd
72
72
  */
73
73
  export function isPicture(subject, cwd) {
74
- if (!subject || /\s/.test(subject.trim())) return false;
75
- if (PICTURE_NAME.test(subject)) return true;
74
+ if (!subject) return false;
75
+ // A file that exists is a picture whatever its name: macOS names every
76
+ // screenshot "Screenshot … at 1.23.45 PM.png".
76
77
  try {
77
- return fs.statSync(path.resolve(cwd, subject)).isFile();
78
+ if (fs.statSync(path.resolve(cwd, subject.trim())).isFile()) return true;
78
79
  } catch {
79
- return false;
80
+ // Not a file here.
80
81
  }
82
+ return !/\s/.test(subject.trim()) && PICTURE_NAME.test(subject);
81
83
  }
82
84
 
83
85
  /**
@@ -196,6 +198,7 @@ async function answer(subject, options, cwd) {
196
198
  refuse(
197
199
  E.ERR_THEME_INVALID,
198
200
  `${broken}, so settings cannot take effect and no command here would change the theme. Put back the import, extends and name lines in themes/${options.theme}/${options.theme}.theme.ts, then ask again.`,
201
+ {run: [`${P} show ${options.theme}`]},
199
202
  );
200
203
  }
201
204
  if (list != null) {
@@ -203,6 +206,7 @@ async function answer(subject, options, cwd) {
203
206
  refuse(
204
207
  E.ERR_INVALID_ARGUMENT,
205
208
  '--at reads a picture; --list lists names, so drop one of them.',
209
+ {run: [`${HOW} --list ${quoteCommandArgument(String(list))}`]},
206
210
  );
207
211
  const kind = listKind(list);
208
212
  if (kind === 'kinds')
@@ -363,7 +367,7 @@ async function answer(subject, options, cwd) {
363
367
  Object.hasOwn(ctx.project.core.tokenDefaults, key)
364
368
  )
365
369
  return tokenAnswer(ctx, env, t, key, unknown, themeFields);
366
- if (CSS_PROPERTIES.has(key)) {
370
+ if (cssProperties().has(key)) {
367
371
  const setters = Object.keys(C.MAP).filter(p => key in C.MAP[p].own);
368
372
  const value = exampleForProperty(key);
369
373
  const {commands, refused} = value
@@ -390,11 +394,94 @@ async function answer(subject, options, cwd) {
390
394
  };
391
395
  }
392
396
  // "What does --color-accent do", "what's the variable for card padding":
397
+ // "--focus-outline-width: 3px": a token typed with a value is set exactly,
398
+ // or refused with the nearest names; never another token.
399
+ const typedToken =
400
+ /^\s*(--[a-z][a-z0-9-]*)\s*(?::|\s+to\s+|\s+)\s*([^;]+?)\s*;?\s*(?:\bin (light|dark) mode\b.*)?$/i.exec(
401
+ t.replace(/^\s*(?:change|set|make|token)\s+/i, ' '),
402
+ );
403
+ if (
404
+ typedToken &&
405
+ (Object.hasOwn(
406
+ ctx.project.core.tokenDefaults,
407
+ typedToken[1].toLowerCase(),
408
+ ) ||
409
+ nearest(
410
+ typedToken[1].toLowerCase(),
411
+ Object.keys(ctx.project.core.tokenDefaults),
412
+ ).length > 0) &&
413
+ !/^--(on|when|state|mode|theme|list|at)$/.test(typedToken[1]) &&
414
+ // "what does --color-accent do" is a lookup.
415
+ !/^\s*(what|which|where|how|is|are|does|do|explain|why)\b/i.test(t) &&
416
+ !/^(do|does|mean|means|for|control|controls)\b/i.test(typedToken[2].trim())
417
+ ) {
418
+ const token = typedToken[1].toLowerCase();
419
+ const mode = /\bin (light|dark) mode\b/i.exec(t)?.[1]?.toLowerCase();
420
+ const defaults = ctx.project.core.tokenDefaults;
421
+ const near = nearest(token, Object.keys(defaults));
422
+ // A token that does not exist is refused with the nearest real names;
423
+ // a flag-like word with none near is read as words.
424
+ if (!Object.hasOwn(defaults, token) && near.length)
425
+ return refuse(E.ERR_INVALID_ARGUMENT, `There is no token ${token}.`, {
426
+ run: near.map(k => `${HOW} ${k}`),
427
+ });
428
+ // Quotes come off only when the whole value is one quoted string: a
429
+ // font stack keeps its quoted family.
430
+ const typedValue = typedToken[2].trim();
431
+ const value = /^(["'])([^"']*)\1$/.test(typedValue)
432
+ ? typedValue.slice(1, -1)
433
+ : typedValue;
434
+ const {commands, refused} = checked(env, [
435
+ [
436
+ {
437
+ verb: 'set',
438
+ thing: token,
439
+ value,
440
+ ...(mode && env.data.mode === 'both' ? {mode} : {}),
441
+ },
442
+ ],
443
+ ]);
444
+ return {
445
+ kind: 'question',
446
+ subject: t,
447
+ understood: {parts: [], aspects: []},
448
+ ...themeFields,
449
+ results: [
450
+ {
451
+ text: commands.length
452
+ ? `the token ${token}, as you wrote it`
453
+ : `${token} ${value}: ${refused[0]?.why ?? 'no command does it'}`,
454
+ commands,
455
+ ...(refused.length ? {refused} : {}),
456
+ },
457
+ ],
458
+ ...unknown,
459
+ };
460
+ }
461
+ // A question about the tool itself gets the command that answers it.
462
+ const tool = toolAnswer(t, env);
463
+ if (tool === 'list') {
464
+ const kind =
465
+ /\b(dials?|tokens?|parts?|groups?|properties|property)\b/i
466
+ .exec(t)?.[1]
467
+ ?.toLowerCase() ?? 'kinds';
468
+ return answer('', {...options, list: kind}, cwd);
469
+ }
470
+ if (tool)
471
+ return {
472
+ kind: 'question',
473
+ subject: t,
474
+ understood: {parts: [], aspects: []},
475
+ ...themeFields,
476
+ results: tool,
477
+ ...unknown,
478
+ };
393
479
  // a question about what something is gets the lookup, not a change.
394
480
  if (
395
- /^\s*(what|which|where)\b.*\b(variables?|tokens?|do|does|means?|controls?|for)\b|^\s*what('s| is) the (css )?(variable|token|property)/i.test(
481
+ (/^\s*(what|which|where)\b.*\b(variables?|tokens?|do|does|means?|controls?|for)\b|^\s*what('s| is) the (css )?(variable|token|property)/i.test(
396
482
  t,
397
- ) &&
483
+ ) ||
484
+ /^\s*(is there|are there|explain|what is|what's|what are)\b/i.test(t)) &&
398
485
  !/\b(command|make|makes|set|change)\b/i.test(t)
399
486
  ) {
400
487
  const tok = /--[a-z0-9-]+/i.exec(t)?.[0]?.toLowerCase();
@@ -432,6 +519,18 @@ async function answer(subject, options, cwd) {
432
519
  results,
433
520
  ...unknown,
434
521
  };
522
+ // "which token sets the page background?": the token the answer would
523
+ // set, looked up.
524
+ const token = q.parts.includes('page')
525
+ ? '--color-background-body'
526
+ : q.drafts
527
+ .flatMap(d => d.options.flat())
528
+ .find(st => st.thing.startsWith('--'))?.thing;
529
+ if (token && Object.hasOwn(ctx.project.core.tokenDefaults, token))
530
+ return {
531
+ ...tokenAnswer(ctx, env, token, token, unknown, themeFields),
532
+ subject: t,
533
+ };
435
534
  }
436
535
  const h = draftAnswer(ctx, env, t);
437
536
  const results = finish(env, h.drafts);
@@ -522,7 +621,7 @@ function lookupKey(t, ctx) {
522
621
  ctx.project.target.has(x) ||
523
622
  ASPECTS.includes(x) ||
524
623
  Object.hasOwn(DIALS, x) ||
525
- CSS_PROPERTIES.has(x) ||
624
+ cssProperties().has(x) ||
526
625
  x === 'colors' ||
527
626
  x === 'palette';
528
627
  if (known(k)) return k;
@@ -549,7 +648,24 @@ function partAnswer(ctx, env, subject, key, unknown, themeFields) {
549
648
  ctx.project.target.get(key)
550
649
  );
551
650
  const group = familyOf(key);
552
- const states = [...new Set([...target.states, ...COMMON_STATES])];
651
+ // Only the states set takes on this part (it refuses one that never
652
+ // applies there).
653
+ 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
+ },
668
+ );
553
669
  const reads = Object.fromEntries(
554
670
  Object.keys(GROUPS).map(g => [
555
671
  g,
@@ -815,6 +931,126 @@ function colorsAnswer(env, dialCommands) {
815
931
  ];
816
932
  }
817
933
 
934
+ /**
935
+ * The answer to a question about the tool itself: help, a list, how to see
936
+ * a change, or the difference between two things it names. 'list' means
937
+ * the caller lists the kind the question names.
938
+ * @param {string} t
939
+ * @param {import('./_how-commands.mjs').HowTheme} env
940
+ * @returns {Array<{text: string, commands: string[]}> | 'list' | null}
941
+ */
942
+ function toolAnswer(t, env) {
943
+ const q = t
944
+ .trim()
945
+ .toLowerCase()
946
+ .replace(/[?.!]+$/, '');
947
+ if (
948
+ /^(help|usage|\?|how does (this|it) work|what can (i|you) (ask|do))$/.test(
949
+ q,
950
+ )
951
+ )
952
+ return [
953
+ {
954
+ text: 'how answers a part, a setting, a plain-words question or a PNG picture with the commands that make the change; set makes it, show lists what a theme sets',
955
+ commands: [`${HOW} --help`, `${HOW} --list kinds`],
956
+ },
957
+ ];
958
+ if (
959
+ /^(list|show)( me)? (all|every|the)? ?(the )?(dials?|tokens?|parts?|groups?|properties)\b/.test(
960
+ q,
961
+ )
962
+ )
963
+ return 'list';
964
+ if (/\b(see|view|preview|check) (my |the )?(changes?|theme|edits?)\b/.test(q))
965
+ return [
966
+ {
967
+ text: `show lists what ${env.slug} sets; a preview page shows the theme in the app`,
968
+ commands: [
969
+ `${P} show ${env.slug}`,
970
+ `${PREVIEW} add --theme ${env.slug}`,
971
+ ],
972
+ },
973
+ ];
974
+ // Questions about the theme's files and life.
975
+ if (
976
+ /\b(use|import|apply|add|load) (this|the|my) theme (in|to|into) (my|the) app\b/.test(
977
+ q,
978
+ )
979
+ )
980
+ return [
981
+ {
982
+ text: `the theme is a module in themes/${env.slug}/; show names it and its files, and the theme docs say how an app loads a theme`,
983
+ commands: [`${P} show ${env.slug}`, 'astryx docs theme'],
984
+ },
985
+ ];
986
+ if (/\brename\b/.test(q))
987
+ return [
988
+ {
989
+ text: 'no command renames a theme: make a new one, set what you need on it, and remove the old folder',
990
+ commands: [
991
+ `${P} new ${env.slug}-2 --like ${env.data.like ?? 'none'}`,
992
+ `${P} show ${env.slug}`,
993
+ ],
994
+ },
995
+ ];
996
+ if (
997
+ /\b(what|which) (changed|did i change|have i changed)\b|\bwhat (is|does) (my|this|the) theme set\b/.test(
998
+ q,
999
+ )
1000
+ )
1001
+ return [
1002
+ {
1003
+ text: `show lists every setting ${env.slug} has, in the order they were made`,
1004
+ commands: [`${P} show ${env.slug}`],
1005
+ },
1006
+ ];
1007
+ if (/\b(second|another|new|other) theme\b/.test(q))
1008
+ return [
1009
+ {
1010
+ text: 'new makes a theme beside the ones you have; how and set take --theme to pick one',
1011
+ commands: [`${P} new ${env.slug}-2 --like ${env.data.like ?? 'none'}`],
1012
+ },
1013
+ ];
1014
+ if (/\b(version|which cli|what cli)\b/.test(q))
1015
+ return [{text: 'the CLI says its version', commands: ['astryx --version']}];
1016
+ if (/\bwhere (are|is|do) .*\b(stored|saved|kept|live|files?)\b/.test(q))
1017
+ return [
1018
+ {
1019
+ text: `everything is in themes/${env.slug}/: the settings file is the source, and the CSS and module are built from it`,
1020
+ commands: [`${P} show ${env.slug}`],
1021
+ },
1022
+ ];
1023
+ if (
1024
+ /\b(edit|change) (the )?(css|module|theme)?( files?)? by hand\b|\bhand[- ]edit/.test(
1025
+ q,
1026
+ )
1027
+ )
1028
+ return [
1029
+ {
1030
+ text: `the CSS and module in themes/${env.slug}/ are built from the settings file, so a hand edit is lost at the next set; make the change with set`,
1031
+ commands: [`${HOW} --help`],
1032
+ },
1033
+ ];
1034
+ const diff = /\bdifference between (.+?) and (.+)$/.exec(q);
1035
+ if (diff) {
1036
+ const props = cssProperties();
1037
+ return [diff[1], diff[2]].map(x => {
1038
+ const w = x.trim().replace(/^(the|a) /, '');
1039
+ return {
1040
+ text: Object.hasOwn(DIALS, w)
1041
+ ? `${w} is a dial: ${DIALS[w].help}`
1042
+ : props.has(w)
1043
+ ? `${w} is a CSS property: set it on one part with --on`
1044
+ : w.startsWith('--')
1045
+ ? `${w} is a token: one value the whole theme reads`
1046
+ : `what ${w} is`,
1047
+ commands: [`${HOW} ${w}`],
1048
+ };
1049
+ });
1050
+ }
1051
+ return null;
1052
+ }
1053
+
818
1054
  /**
819
1055
  * The tokens most parts read for one aspect, for a whole-theme change.
820
1056
  * @param {import('./_settings.mjs').Ctx} ctx
@@ -829,17 +1065,22 @@ function wholeThemeTokens(ctx, env, aspect) {
829
1065
  .sort((a, b) => C.anyReader(b).length - C.anyReader(a).length)
830
1066
  .slice(0, 6);
831
1067
  if (!toks.length) return [];
832
- const value = exampleForToken(
833
- C.typeOf(toks[0]),
834
- toks[0],
835
- env.base.light[toks[0]] ?? '',
836
- );
1068
+ // The example uses the most read token whose example changes what shows:
1069
+ // a fully round corner (9999px) scaled up stays fully round.
1070
+ /** @type {string[]} */
1071
+ let commands = [];
1072
+ for (const tok of toks) {
1073
+ const now = env.base.light[tok] ?? '';
1074
+ if (parseFloat(now) >= 999) continue;
1075
+ const value = exampleForToken(C.typeOf(tok), tok, now);
1076
+ if (!value) continue;
1077
+ commands = checked(env, [[{verb: 'set', thing: tok, value}]]).commands;
1078
+ if (commands.length) break;
1079
+ }
837
1080
  return [
838
1081
  {
839
1082
  text: `whole-theme tokens for ${aspect}, most used first: ${toks.map(k => `${k} (${C.anyReader(k).length} parts)`).join(', ')}`,
840
- commands: value
841
- ? checked(env, [[{verb: 'set', thing: toks[0], value}]]).commands
842
- : [`${HOW} ${toks[0]}`],
1083
+ commands: commands.length ? commands : [`${HOW} ${toks[0]}`],
843
1084
  },
844
1085
  ];
845
1086
  }
@@ -911,7 +1152,7 @@ async function listItems(kind, filter, cwd) {
911
1152
  };
912
1153
  if (kind === 'properties') {
913
1154
  const props = filter
914
- ? [...CSS_PROPERTIES].filter(x => f(x)).slice(0, 60)
1155
+ ? [...cssProperties()].filter(x => f(x)).slice(0, 60)
915
1156
  : COMMON_PROPERTIES;
916
1157
  return {list: kind, items: props.map(name => ({name})), common: !filter};
917
1158
  }
@@ -939,6 +1180,37 @@ async function listItems(kind, filter, cwd) {
939
1180
  for (const s of x.states) if (!e.states.includes(s)) e.states.push(s);
940
1181
  byKey.set(x.key, e);
941
1182
  }
1183
+ // A filter no part name holds lists the closest names, never nothing.
1184
+ if (!byKey.size && filter) {
1185
+ const word = filter.toLowerCase().replace(/s$/, '');
1186
+ // The parts of components whose doc lists the word, else the names
1187
+ // nearest it.
1188
+ const owners = Object.entries(ctx.project.components)
1189
+ .filter(([, info]) =>
1190
+ (info.keywords ?? []).some(
1191
+ k => k.toLowerCase().replace(/s$/, '') === word,
1192
+ ),
1193
+ )
1194
+ .map(([name]) => name);
1195
+ const close = new Set(
1196
+ owners.length
1197
+ ? ctx.project.targets
1198
+ .filter(x => owners.includes(x.component))
1199
+ .map(x => x.key)
1200
+ : nearest(
1201
+ word,
1202
+ ctx.project.targets.map(x => x.key),
1203
+ 5,
1204
+ ),
1205
+ );
1206
+ for (const x of ctx.project.targets) {
1207
+ if (!close.has(x.key)) continue;
1208
+ const e = byKey.get(x.key) ?? {key: x.key, components: [], states: []};
1209
+ if (!e.components.includes(x.component)) e.components.push(x.component);
1210
+ for (const st of x.states) if (!e.states.includes(st)) e.states.push(st);
1211
+ byKey.set(x.key, e);
1212
+ }
1213
+ }
942
1214
  return {
943
1215
  list: kind,
944
1216
  items: [...byKey.values()].map(x => ({
@@ -991,6 +1263,7 @@ export function parsePoints(at) {
991
1263
  refuse(
992
1264
  E.ERR_INVALID_ARGUMENT,
993
1265
  `--at reads at most ${MAX_POINTS} points; it got ${points.length}.`,
1266
+ {run: [example]},
994
1267
  );
995
1268
  return points;
996
1269
  }
@@ -1014,6 +1287,7 @@ function pictureColors(file, cwd, at, count) {
1014
1287
  refuse(
1015
1288
  E.ERR_INVALID_ARGUMENT,
1016
1289
  'A count lists main colors; --at reads points. Give one of them.',
1290
+ {run: [`${HOW} ${quoteCommandArgument(file)} ${count}`]},
1017
1291
  );
1018
1292
  if (count != null && (!Number.isInteger(count) || count <= 0))
1019
1293
  refuse(
@@ -1034,6 +1308,7 @@ function pictureColors(file, cwd, at, count) {
1034
1308
  refuse(
1035
1309
  E.ERR_INVALID_ARGUMENT,
1036
1310
  `${file} is a ${other[0]} picture; how reads PNG only. Save or convert it as PNG.`,
1311
+ {run: [`${HOW} --list`]},
1037
1312
  );
1038
1313
  /** @type {import('./_png.mjs').Picture} */
1039
1314
  let pic;
@@ -1042,7 +1317,7 @@ function pictureColors(file, cwd, at, count) {
1042
1317
  } catch (e) {
1043
1318
  throw new AstryxError(
1044
1319
  `Could not read ${file} as a PNG picture: ${e instanceof Error ? e.message : String(e)}.`,
1045
- [],
1320
+ [{name: `${HOW} --list`, reason: 'what how reads'}],
1046
1321
  E.ERR_INVALID_ARGUMENT,
1047
1322
  );
1048
1323
  }
@@ -1059,6 +1334,7 @@ function pictureColors(file, cwd, at, count) {
1059
1334
  .join(
1060
1335
  '; ',
1061
1336
  )} ${outside.length > 1 ? 'are' : 'is'} outside the picture, which is ${pic.width}x${pic.height} (x from 0 to ${pic.width - 1}, y from 0 to ${pic.height - 1}).`,
1337
+ {run: [`${HOW} ${quoteCommandArgument(file)} --at 0,0`]},
1062
1338
  );
1063
1339
  return {
1064
1340
  file,
@@ -1068,11 +1344,19 @@ function pictureColors(file, cwd, at, count) {
1068
1344
  points: colorsAt(pic, points),
1069
1345
  };
1070
1346
  }
1347
+ const colors = mainColors(pic, count ?? 14);
1348
+ // Every pixel see-through: no color shows, as with a 0-pixel picture.
1349
+ if (!colors.length)
1350
+ throw new AstryxError(
1351
+ `Could not read ${file} as a PNG picture: every pixel is fully see-through, so it has no visible colors.`,
1352
+ [{name: `${HOW} --list`, reason: 'what how reads'}],
1353
+ E.ERR_INVALID_ARGUMENT,
1354
+ );
1071
1355
  return {
1072
1356
  file,
1073
1357
  width: pic.width,
1074
1358
  height: pic.height,
1075
- colors: mainColors(pic, count ?? 14),
1359
+ colors,
1076
1360
  points: null,
1077
1361
  };
1078
1362
  }
@@ -14,14 +14,9 @@
14
14
  * @position api/theme-edit — imported by _preview.mjs
15
15
  */
16
16
 
17
- /** @typedef {import('./_catalog.mjs').Tree} Tree */
17
+ import {h} from './_catalog.mjs';
18
18
 
19
- /** @param {string} name @param {Record<string, unknown>} [props] @param {...unknown} children @returns {Tree} */
20
- const h = (name, props = {}, ...children) => ({
21
- __element: name,
22
- props,
23
- ...(children.length ? {children} : {}),
24
- });
19
+ /** @typedef {import('./_catalog.mjs').Tree} Tree */
25
20
 
26
21
  const noop = {__code: '() => {}'};
27
22
  const STATUSES = ['info', 'success', 'warning', 'error'];
@@ -9,6 +9,23 @@
9
9
  * @param {string | Buffer} text
10
10
  */
11
11
  export function writeWhole(file: string, text: string | Buffer): void;
12
+ /**
13
+ * A command stopped long enough for another to take its lock (Ctrl-Z, a
14
+ * sleeping computer, a debugger) writes nothing more: refuse. Called right
15
+ * before each write.
16
+ */
17
+ export function refuseIfLockLost(): void;
18
+ /** Whether this command still holds its lock (true outside a lock). */
19
+ export function lockHeld(): boolean;
20
+ /**
21
+ * Remove `dir` when it is empty; with `deep`, the empty folders under it
22
+ * first. A folder with a file in it stays.
23
+ * @param {string} dir
24
+ * @param {{deep?: boolean}} [opts]
25
+ */
26
+ export function removeEmptyFolder(dir: string, opts?: {
27
+ deep?: boolean;
28
+ }): void;
12
29
  /**
13
30
  * A temp file beside `file` for a whole write, named so only the editor
14
31
  * makes such names: `.<name>.astryx-<pid>-<random>.tmp`. The write that
@@ -203,14 +220,19 @@ export const VIBRANCY_DEFAULT: 50;
203
220
  export function paletteToken(dial: string): string;
204
221
  /**
205
222
  * The parts whose secondary text the official neutral theme lifts, with
206
- * the block it lifts it in and what the text sits on: the accent tint
207
- * under selected items and tree rows, a dropzone and numbered citations;
208
- * the translucent neutral track (`--color-neutral`) under segmented-control
209
- * labels.
223
+ * the block it lifts it in and what the text sits on: the accent tint,
224
+ * except under segmented-control labels, which sit on the translucent
225
+ * neutral track (`--color-neutral`).
210
226
  */
211
- export const LIFT_PARTS: Array<[string, string, string]>;
227
+ export const LIFT_PARTS: [string, string, string][];
212
228
  export function paletteImport(slug: string): string;
213
229
  export function isGraySeed(seed: string | null): boolean;
230
+ /**
231
+ * The first line of the empty palette module the preview writes for a
232
+ * Colors page it keeps (changed by hand) once the theme has no colors, so
233
+ * the app still builds. The editor replaces it freely.
234
+ */
235
+ export const PALETTE_STAND_IN: "// A stand-in for a preview page that imports this file: the theme has no generated colors.";
214
236
  /** Every token a color dial can point at a generated shade. */
215
237
  export const PALETTE_TOKENS: Set<string>;
216
238
  /**