@astryxdesign/cli 0.7.15 → 0.7.16-canary.g54dd64e

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 (123) 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/pack-check.mjs +13 -7
  8. package/api/integration/validate-integration.mjs +1 -1
  9. package/api/theme/_adapter.d.mts +5 -2
  10. package/api/theme/_adapter.mjs +43 -12
  11. package/api/theme/build/build.d.mts +64 -27
  12. package/api/theme/build/build.mjs +341 -69
  13. package/api/theme/eject/eject.mjs +22 -1
  14. package/api/theme/template/template.d.mts +19 -0
  15. package/api/theme/template/template.mjs +102 -25
  16. package/api/theme/theme.type.d.mts +5 -1
  17. package/api/theme/theme.type.mjs +2 -1
  18. package/api/theme/themeBuild.doc.mjs +3 -3
  19. package/api/theme/themeEject.doc.mjs +1 -1
  20. package/api/theme/themeTemplate.doc.mjs +9 -3
  21. package/api/theme-edit/_adapter.d.mts +33 -0
  22. package/api/theme-edit/_adapter.mjs +208 -31
  23. package/api/theme-edit/_check.d.mts +38 -0
  24. package/api/theme-edit/_check.mjs +1326 -211
  25. package/api/theme-edit/_color.d.mts +2 -8
  26. package/api/theme-edit/_color.mjs +292 -219
  27. package/api/theme-edit/_compiler.d.mts +1 -0
  28. package/api/theme-edit/_compiler.mjs +20 -1
  29. package/api/theme-edit/_context.d.mts +29 -0
  30. package/api/theme-edit/_context.mjs +329 -30
  31. package/api/theme-edit/_css.d.mts +60 -1
  32. package/api/theme-edit/_css.mjs +404 -28
  33. package/api/theme-edit/_edit.d.mts +9 -0
  34. package/api/theme-edit/_edit.mjs +1025 -126
  35. package/api/theme-edit/_how-commands.d.mts +11 -26
  36. package/api/theme-edit/_how-commands.mjs +30 -2
  37. package/api/theme-edit/_how-question.d.mts +7 -0
  38. package/api/theme-edit/_how-question.mjs +1304 -176
  39. package/api/theme-edit/_how.mjs +144 -30
  40. package/api/theme-edit/_overview.mjs +2 -0
  41. package/api/theme-edit/_palette.d.mts +11 -0
  42. package/api/theme-edit/_palette.mjs +194 -65
  43. package/api/theme-edit/_parts.d.mts +16 -0
  44. package/api/theme-edit/_parts.mjs +59 -7
  45. package/api/theme-edit/_png.mjs +19 -14
  46. package/api/theme-edit/_preview-app.d.mts +3 -0
  47. package/api/theme-edit/_preview-app.mjs +843 -45
  48. package/api/theme-edit/_preview.d.mts +16 -3
  49. package/api/theme-edit/_preview.mjs +310 -29
  50. package/api/theme-edit/_project.d.mts +11 -0
  51. package/api/theme-edit/_project.mjs +46 -12
  52. package/api/theme-edit/_settings.d.mts +178 -5
  53. package/api/theme-edit/_settings.mjs +2035 -86
  54. package/api/theme-edit/_tables.d.mts +24 -0
  55. package/api/theme-edit/_tables.mjs +211 -149
  56. package/api/theme-edit/_vet.d.mts +42 -0
  57. package/api/theme-edit/_vet.mjs +144 -0
  58. package/api/theme-edit/theme-edit.type.d.mts +2 -1
  59. package/api/theme-edit/theme-edit.type.mjs +1 -1
  60. package/api/theme-edit/themeEditNew.doc.mjs +1 -1
  61. package/api/theme-edit/themeEditShow.doc.mjs +11 -3
  62. package/api/upgrade/registry/registry.mjs +6 -1
  63. package/assets/docs/tree/single-component.doc.mjs +11 -2
  64. package/assets/docs/tree/tokens-and-setup.doc.mjs +39 -3
  65. package/assets/docs.generated.json +2 -2
  66. package/assets/preview-app/next.config.mjs +7 -1
  67. package/assets/preview-app/package.json +1 -0
  68. package/assets/preview-app/src/app/globals.css +1 -0
  69. package/assets/self-audit.generated.json +1 -1
  70. package/assets/templates/blocks/components/Table/ColumnsVirtualizationHookUsage.doc.mjs +14 -0
  71. package/assets/templates/blocks/components/Table/ColumnsVirtualizationHookUsage.tsx +53 -0
  72. package/assets/templates/blocks/components/Table/InfiniteScrollHookUsage.doc.mjs +14 -0
  73. package/assets/templates/blocks/components/Table/InfiniteScrollHookUsage.tsx +33 -0
  74. package/assets/templates/components.generated.json +1 -1
  75. package/assets/templates/pages/dashboard/page.tsx +1 -1
  76. package/authoring/doctypes/_schema.d.mts +52 -5
  77. package/authoring/doctypes/_schema.mjs +62 -7
  78. package/authoring/doctypes/base/type.ts +10 -0
  79. package/authoring/doctypes/component/component.doc.mjs +1 -1
  80. package/authoring/doctypes/function/function.doc.mjs +6 -0
  81. package/authoring/doctypes/function/type.ts +3 -0
  82. package/authoring/doctypes/legacy.mjs +5 -1
  83. package/authoring/index.d.ts +1 -0
  84. package/clients/cli/build-id.generated.json +1 -1
  85. package/clients/cli/commands/doctor.doc.mjs +2 -2
  86. package/clients/cli/commands/experimental/theme.mjs +190 -37
  87. package/clients/cli/commands/experimental-theme-compile.doc.mjs +2 -2
  88. package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +1 -1
  89. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +2 -2
  90. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +1 -1
  91. package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
  92. package/clients/cli/commands/experimental-theme-eject.doc.mjs +1 -1
  93. package/clients/cli/commands/experimental-theme-template.doc.mjs +2 -2
  94. package/clients/cli/commands/theme-build.doc.mjs +2 -2
  95. package/clients/cli/commands/theme-eject.doc.mjs +1 -1
  96. package/clients/cli/commands/theme-template.doc.mjs +3 -1
  97. package/clients/cli/commands/theme.mjs +168 -45
  98. package/clients/cli/formatters/index.mjs +7 -4
  99. package/clients/cli/lib/cli-error.mjs +9 -3
  100. package/clients/cli/lib/component-format.mjs +27 -9
  101. package/clients/cli/lib/json-shim.mjs +40 -2
  102. package/clients/cli/manifest.generated.json +1 -1
  103. package/clients/cli/run.mjs +49 -0
  104. package/foundation/config/project.mjs +50 -14
  105. package/foundation/discovery/theme-discovery.d.mts +5 -1
  106. package/foundation/discovery/theme-discovery.mjs +24 -3
  107. package/foundation/fs/gather-cache.d.mts +9 -2
  108. package/foundation/fs/gather-cache.mjs +79 -15
  109. package/foundation/fs/paths.d.mts +31 -0
  110. package/foundation/fs/paths.mjs +43 -10
  111. package/foundation/render/host-exit.d.mts +8 -0
  112. package/foundation/render/host-exit.mjs +11 -0
  113. package/foundation/render/page-host.mjs +56 -10
  114. package/foundation/render/page-worker.mjs +14 -0
  115. package/foundation/render/render-page.mjs +37 -2
  116. package/foundation/response/error-codes.d.mts +2 -1
  117. package/foundation/response/error-codes.d.ts +1 -0
  118. package/foundation/response/error-codes.doc.mjs +5 -0
  119. package/foundation/response/error-codes.mjs +3 -0
  120. package/foundation/response/json.d.mts +15 -0
  121. package/foundation/response/json.mjs +52 -1
  122. package/foundation/response/response-types.doc.mjs +1 -1
  123. 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;
@@ -70,6 +70,8 @@ export const OVERVIEW_SECTIONS = [
70
70
  'Popover',
71
71
  {
72
72
  isOpen: true,
73
+ // Shown open on the page: it never takes focus.
74
+ hasAutoFocus: false,
73
75
  label: 'Menu',
74
76
  placement: 'below',
75
77
  content: h(
@@ -1,6 +1,11 @@
1
1
  // @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
2
2
  // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
3
 
4
+ /**
5
+ * Give the reader of the tokens a theme's own source sets.
6
+ * @param {(cwd: string, slug: string) => Record<string, string>} read
7
+ */
8
+ export function setOwnTokenReader(read: (cwd: string, slug: string) => Record<string, string>): void;
4
9
  /**
5
10
  * Write a file whole: a temp file beside it, renamed into place, so a link
6
11
  * there is replaced, never written through, and a stopped write leaves the
@@ -175,6 +180,7 @@ export function mappingRows(dial: string): string[];
175
180
  * @returns {string[]}
176
181
  */
177
182
  export function paletteNotes(pal: PaletteMapping | null, dial: string, slug: string, modes?: Mode[]): string[];
183
+ export function isEditorTemp(name: string): boolean;
178
184
  /** @typedef {'light' | 'dark'} Mode */
179
185
  /** @typedef {import('./_settings.mjs').Setting} Setting */
180
186
  /** @typedef {import('../theme/theme.type.mjs').TonalPaletteCandidate} Candidate */
@@ -210,6 +216,7 @@ export function paletteNotes(pal: PaletteMapping | null, dial: string, slug: str
210
216
  * @property {ContrastCheck[]} contrast
211
217
  * @property {number} vibrancy - The generator's vibrancy, 0 to 100.
212
218
  * @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.
219
+ * @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
220
  * @property {string[]} notes - What the config writer kept or replaced of a hand edit.
214
221
  * @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
222
  */
@@ -330,6 +337,10 @@ export type PaletteMapping = {
330
337
  * - Main tokens the theme sets exactly, the value per mode: the dial's fill gives way to them.
331
338
  */
332
339
  exact: Record<string, Partial<Record<Mode, string>>>;
340
+ /**
341
+ * - 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.
342
+ */
343
+ unread?: Record<string, string> | undefined;
333
344
  /**
334
345
  * - What the config writer kept or replaced of a hand edit.
335
346
  */