@astryxdesign/cli 0.7.14-canary.gfb823d9 → 0.7.14

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 (135) hide show
  1. package/CHANGELOG.md +197 -0
  2. package/api/component/_adapter.d.mts +15 -0
  3. package/api/component/_adapter.mjs +76 -0
  4. package/api/component/component.mjs +8 -1
  5. package/api/search/_named-keywords.d.mts +31 -0
  6. package/api/search/_named-keywords.mjs +177 -0
  7. package/api/search/search-index.mjs +8 -1
  8. package/api/search/search.d.mts +6 -1
  9. package/api/search/search.mjs +49 -8
  10. package/api/theme/_adapter.d.mts +33 -0
  11. package/api/theme/_adapter.mjs +352 -16
  12. package/api/theme/build/build.mjs +261 -10
  13. package/api/theme/eject/eject.mjs +13 -1
  14. package/api/theme/list/list.mjs +11 -2
  15. package/api/theme/palette/generate/color.d.mts +2 -0
  16. package/api/theme/palette/generate/color.mjs +1 -1
  17. package/api/theme/template/template.mjs +139 -6
  18. package/api/theme/theme.type.d.mts +15 -1
  19. package/api/theme/theme.type.mjs +9 -3
  20. package/api/theme/themeAdd.doc.mjs +1 -1
  21. package/api/theme/themeBuild.doc.mjs +10 -2
  22. package/api/theme/themeEject.doc.mjs +2 -2
  23. package/api/theme/themeListAvailable.doc.mjs +1 -1
  24. package/api/theme/themeRemove.doc.mjs +1 -1
  25. package/api/theme/themeTemplate.doc.mjs +8 -0
  26. package/api/theme/themeUse.doc.mjs +1 -1
  27. package/api/theme-edit/_adapter.d.mts +36 -2
  28. package/api/theme-edit/_adapter.mjs +340 -12
  29. package/api/theme-edit/_check.d.mts +28 -25
  30. package/api/theme-edit/_check.mjs +876 -308
  31. package/api/theme-edit/_color.d.mts +53 -4
  32. package/api/theme-edit/_color.mjs +406 -79
  33. package/api/theme-edit/_compiler.d.mts +14 -6
  34. package/api/theme-edit/_compiler.mjs +89 -59
  35. package/api/theme-edit/_context.d.mts +28 -8
  36. package/api/theme-edit/_context.mjs +142 -19
  37. package/api/theme-edit/_edit.d.mts +3 -1
  38. package/api/theme-edit/_edit.mjs +746 -76
  39. package/api/theme-edit/_how-commands.d.mts +91 -0
  40. package/api/theme-edit/_how-commands.mjs +269 -0
  41. package/api/theme-edit/_how-question.d.mts +57 -0
  42. package/api/theme-edit/_how-question.mjs +2574 -0
  43. package/api/theme-edit/_how.d.mts +27 -8
  44. package/api/theme-edit/_how.mjs +776 -175
  45. package/api/theme-edit/_overview.d.mts +9 -0
  46. package/api/theme-edit/_overview.mjs +296 -0
  47. package/api/theme-edit/_palette.d.mts +155 -15
  48. package/api/theme-edit/_palette.mjs +1446 -262
  49. package/api/theme-edit/_parts.mjs +61 -5
  50. package/api/theme-edit/_png.d.mts +18 -6
  51. package/api/theme-edit/_png.mjs +135 -25
  52. package/api/theme-edit/_preview-app.d.mts +32 -11
  53. package/api/theme-edit/_preview-app.mjs +1976 -285
  54. package/api/theme-edit/_preview.d.mts +39 -8
  55. package/api/theme-edit/_preview.mjs +367 -41
  56. package/api/theme-edit/_settings.d.mts +147 -11
  57. package/api/theme-edit/_settings.mjs +908 -99
  58. package/api/theme-edit/_tables.d.mts +4 -16
  59. package/api/theme-edit/_tables.mjs +51 -117
  60. package/api/theme-edit/theme-edit.type.d.mts +102 -66
  61. package/api/theme-edit/theme-edit.type.mjs +58 -40
  62. package/api/theme-edit/themeEditHow.doc.mjs +17 -6
  63. package/api/theme-edit/themeEditNew.doc.mjs +21 -5
  64. package/api/theme-edit/themeEditPreviewAdd.doc.mjs +18 -5
  65. package/api/theme-edit/themeEditPreviewApp.doc.mjs +12 -9
  66. package/api/theme-edit/themeEditPreviewList.doc.mjs +11 -2
  67. package/api/theme-edit/themeEditPreviewRemove.doc.mjs +29 -3
  68. package/api/theme-edit/themeEditSet.doc.mjs +14 -8
  69. package/api/theme-edit/themeEditShow.doc.mjs +10 -5
  70. package/api/theme-edit/themeEditUndo.doc.mjs +9 -4
  71. package/assets/discover/official-packages.json +4 -0
  72. package/assets/docs/tree/icon-sets.doc.mjs +3 -3
  73. package/assets/docs.generated.json +1 -0
  74. package/assets/icons/definitions/bookmarkAdd.doc.mjs +9 -0
  75. package/assets/icons/definitions/documentSearch.doc.mjs +9 -0
  76. package/assets/icons/definitions/keyboard.doc.mjs +9 -0
  77. package/assets/icons/definitions/paintBrush.doc.mjs +9 -0
  78. package/assets/icons/definitions/wallet.doc.mjs +9 -0
  79. package/assets/preview-app/gitignore +3 -0
  80. package/assets/templates/blocks/components/ButtonGroup/ButtonGroupShowcase.doc.mjs +1 -1
  81. package/assets/templates/blocks/components/Lightbox/LightboxGallery.tsx +1 -1
  82. package/assets/templates/components.generated.json +1 -0
  83. package/assets/templates/pages/gallery-hero/page.tsx +8 -2
  84. package/assets/templates/pages/settings-dialog/template.doc.mjs +3 -3
  85. package/assets/templates/pages/side-gallery/page.tsx +1 -1
  86. package/assets/templates/pages/table-filter/template.doc.mjs +2 -2
  87. package/assets/templates/pages/theme-showcase/template.doc.mjs +1 -1
  88. package/clients/cli/bin/astryx.mjs +37 -5
  89. package/clients/cli/commands/experimental/theme.mjs +422 -57
  90. package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +22 -9
  91. package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +103 -4
  92. package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +13 -8
  93. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +5 -5
  94. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +5 -5
  95. package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
  96. package/clients/cli/commands/experimental-theme-preview-add.doc.mjs +3 -2
  97. package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +2 -8
  98. package/clients/cli/commands/experimental-theme-preview-list.doc.mjs +2 -2
  99. package/clients/cli/commands/experimental-theme-preview-remove.doc.mjs +2 -2
  100. package/clients/cli/commands/experimental-theme-targets.doc.mjs +1 -1
  101. package/clients/cli/commands/experimental-theme.doc.mjs +3 -4
  102. package/clients/cli/commands/theme-build.doc.mjs +1 -1
  103. package/clients/cli/commands/theme-eject.doc.mjs +3 -3
  104. package/clients/cli/commands/theme-remove.doc.mjs +2 -2
  105. package/clients/cli/commands/theme-template.doc.mjs +11 -4
  106. package/clients/cli/commands/theme.mjs +145 -46
  107. package/clients/cli/commands.generated.json +1 -0
  108. package/clients/cli/index.mjs +96 -5
  109. package/clients/cli/lib/json-shim.mjs +29 -1
  110. package/foundation/config/project.d.mts +16 -2
  111. package/foundation/config/project.mjs +40 -6
  112. package/foundation/config/theme-state.d.mts +9 -0
  113. package/foundation/config/theme-state.mjs +20 -1
  114. package/foundation/discovery/template-adapter.d.mts +12 -1
  115. package/foundation/discovery/template-adapter.mjs +29 -4
  116. package/foundation/discovery/template-icons.d.mts +13 -0
  117. package/foundation/discovery/template-icons.mjs +76 -0
  118. package/foundation/discovery/template-needs.d.mts +7 -0
  119. package/foundation/discovery/template-needs.mjs +117 -8
  120. package/foundation/discovery/template-source-tree.d.mts +5 -1
  121. package/foundation/discovery/template-source-tree.mjs +6 -4
  122. package/foundation/discovery/theme-discovery.d.mts +14 -3
  123. package/foundation/discovery/theme-discovery.mjs +45 -12
  124. package/foundation/doc-compiler/import.mjs +68 -3
  125. package/foundation/doc-compiler/stored-docs.d.mts +27 -0
  126. package/foundation/doc-compiler/stored-docs.mjs +65 -0
  127. package/foundation/fs/fs-error.d.mts +17 -0
  128. package/foundation/fs/fs-error.mjs +34 -0
  129. package/foundation/response/error-codes.d.mts +3 -1
  130. package/foundation/response/error-codes.doc.mjs +13 -1
  131. package/foundation/response/error-codes.mjs +11 -1
  132. package/foundation/response/response-types.doc.mjs +6 -6
  133. package/package.json +6 -7
  134. package/clients/cli/commands/experimental-theme-palette-generate.doc.mjs +0 -73
  135. package/clients/cli/commands/experimental-theme-palette.doc.mjs +0 -37
@@ -3,11 +3,13 @@
3
3
 
4
4
  /** @typedef {{token: string, props: string[], when: string[]}} Read */
5
5
  /** @typedef {{message: string, run: string[], also: string[], soft?: boolean}} CheckFailure */
6
+ /** @typedef {import('./_parts.mjs').PartData} PartData */
7
+ /** @typedef {import('./_parts.mjs').TextPair} TextPair */
6
8
  /**
7
9
  * @param {import('./_project.mjs').ThemeProject} project
8
- * @param {import('./_parts.mjs').PartData} parts
10
+ * @param {PartData} parts
9
11
  */
10
- export function makeCompiler(project: import("./_project.mjs").ThemeProject, parts: import("./_parts.mjs").PartData): {
12
+ export function makeCompiler(project: import("./_project.mjs").ThemeProject, parts: PartData): {
11
13
  MAP: Record<string, import("./_parts.mjs").PartRecord>;
12
14
  typeOf: (tok: string) => string;
13
15
  feeds: (target: string, token: string) => Array<{
@@ -19,7 +21,7 @@ export function makeCompiler(project: import("./_project.mjs").ThemeProject, par
19
21
  part: string;
20
22
  prop: string;
21
23
  when: string;
22
- }>>) => string;
24
+ }>>, target?: string) => string;
23
25
  showsCorners: (target: string) => boolean;
24
26
  groupOfToken: (t: string) => string | null;
25
27
  groupOfProp: (p: string) => string | null;
@@ -29,11 +31,14 @@ export function makeCompiler(project: import("./_project.mjs").ThemeProject, par
29
31
  allReads: (target: string) => Set<string>;
30
32
  anyReader: (tok: string) => string[];
31
33
  checkTokenOn: (theme: string, target: string, token: string, value: string, P: string) => CheckFailure | null;
32
- checkTokenGlobal: (token: string, P: string) => CheckFailure | null;
34
+ checkTokenGlobal: (token: string, _P: string) => CheckFailure | null;
33
35
  variantValues: (target: string) => Record<string, string[]>;
34
- contrast: (value: (pair: import("./_parts.mjs").TextPair, side: "fg" | "bg", mode: string) => string | null | undefined, baseValue: (pair: import("./_parts.mjs").TextPair, side: "fg" | "bg", mode: string) => string | null | undefined, modes: string[], { parseColor, ratio }: {
35
- parseColor: (v: unknown) => number[] | null;
36
+ contrast: (value: (pair: TextPair, side: "fg" | "bg", mode: string) => string | null | undefined, baseValue: (pair: TextPair, side: "fg" | "bg", mode: string) => string | null | undefined, modes: string[], { parseColor, ratio, alphaOf, compositeOver, page }: {
37
+ parseColor: (v: unknown) => [number, number, number] | null;
36
38
  ratio: (a: number[], b: number[]) => number;
39
+ alphaOf: (v: unknown) => number;
40
+ compositeOver: (over: [number, number, number], alpha: number, under: [number, number, number]) => [number, number, number];
41
+ page: (mode: string) => string | null | undefined;
37
42
  }) => {
38
43
  problems: {
39
44
  part: string;
@@ -44,6 +49,7 @@ export function makeCompiler(project: import("./_project.mjs").ThemeProject, par
44
49
  bgPart: string | null;
45
50
  bg: string;
46
51
  }[];
52
+ more: number;
47
53
  unchecked: string[];
48
54
  };
49
55
  };
@@ -60,4 +66,6 @@ export type CheckFailure = {
60
66
  also: string[];
61
67
  soft?: boolean;
62
68
  };
69
+ export type PartData = import("./_parts.mjs").PartData;
70
+ export type TextPair = import("./_parts.mjs").TextPair;
63
71
  export type Compiler = ReturnType<typeof makeCompiler>;
@@ -11,33 +11,26 @@
11
11
 
12
12
  import {DIRECT, GROUPS, HOW} from './_tables.mjs';
13
13
 
14
- /**
15
- * Whether a color is see-through: its contrast depends on what is under it,
16
- * so it is not judged alone.
17
- * @param {unknown} v
18
- */
19
- function hasAlpha(v) {
20
- const s = String(v ?? '').trim();
21
- const h = /^#(?:[0-9a-f]{4}|[0-9a-f]{8})$/i.exec(s);
22
- if (h) return s.length === 5 ? !/f$/i.test(s) : !/ff$/i.test(s);
23
- const m = /\/\s*([\d.]+%?)\s*\)$|^rgba\([^)]*,\s*([\d.]+)\s*\)$/i.exec(s);
24
- if (!m) return /^transparent$/i.test(s);
25
- const a = m[1] ?? m[2];
26
- return a.endsWith('%') ? parseFloat(a) < 100 : parseFloat(a) < 1;
27
- }
28
-
29
14
  /** Only these token types may differ between light and dark. */
30
15
  export const MODAL = new Set(['color', 'shadow']);
31
16
 
32
17
  /** Tokens a component may read only in some states: never refused globally. */
33
- const SOFT = /^--(color-data|syntax|duration|ease|z-|layer|breakpoint)/;
18
+ /**
19
+ * Tokens no catalog part is recorded reading, though Core reads them: code
20
+ * highlighting, the display text sizes and the colored icons read them only
21
+ * under a variant or in a global stylesheet. Never refused as unread.
22
+ */
23
+ const SOFT =
24
+ /^--(color-data|color-syntax|syntax|duration|ease|z-|layer|breakpoint|text-display-\d|color-icon-[a-z]+$)/;
34
25
 
35
26
  /** @typedef {{token: string, props: string[], when: string[]}} Read */
36
27
  /** @typedef {{message: string, run: string[], also: string[], soft?: boolean}} CheckFailure */
28
+ /** @typedef {import('./_parts.mjs').PartData} PartData */
29
+ /** @typedef {import('./_parts.mjs').TextPair} TextPair */
37
30
 
38
31
  /**
39
32
  * @param {import('./_project.mjs').ThemeProject} project
40
- * @param {import('./_parts.mjs').PartData} parts
33
+ * @param {PartData} parts
41
34
  */
42
35
  export function makeCompiler(project, parts) {
43
36
  const {core} = project;
@@ -69,7 +62,7 @@ export function makeCompiler(project, parts) {
69
62
  if (TYPE[k]) continue;
70
63
  if (/^--color-|^--syntax-/.test(k)) TYPE[k] = 'color';
71
64
  else if (/^--font-family/.test(k)) TYPE[k] = 'font';
72
- else if (/^--font-weight/.test(k)) TYPE[k] = 'number';
65
+ else if (/^--font-weight|^--text-.*-weight$/.test(k)) TYPE[k] = 'number';
73
66
  else if (/^--shadow/.test(k)) TYPE[k] = 'shadow';
74
67
  else if (/^--focus-outline-color/.test(k)) TYPE[k] = 'color';
75
68
  else if (
@@ -219,13 +212,18 @@ export function makeCompiler(project, parts) {
219
212
  return out;
220
213
  }
221
214
 
222
- /** One line for where a token feeds. @param {ReturnType<typeof feeds>} list */
223
- const fmtFeeds = list =>
215
+ /**
216
+ * One line for where a token feeds. A part inside `target` (a button in a
217
+ * toast) is named as inside it, so the line never reads as every button.
218
+ * @param {ReturnType<typeof feeds>} list
219
+ * @param {string} [target]
220
+ */
221
+ const fmtFeeds = (list, target) =>
224
222
  [
225
223
  ...new Set(
226
224
  list.map(
227
225
  f =>
228
- `${f.prop}${f.part ? ` on ${f.part}` : ''}${f.when ? ` (when ${f.when})` : ''}`,
226
+ `${f.prop}${f.part ? ` on ${f.part}${target && f.part !== target ? ` inside ${target}` : ''}` : ''}${f.when ? ` (when ${f.when})` : ''}`,
229
227
  ),
230
228
  ),
231
229
  ]
@@ -266,17 +264,11 @@ export function makeCompiler(project, parts) {
266
264
  : g === 'background'
267
265
  ? ['background-color', 'background', 'background-image']
268
266
  : null;
269
- if (!wanted || !fed.length || fed.some(f => wanted.includes(f.prop)))
270
- return null;
271
- const direct = g === 'text' ? 'color' : 'background-color';
272
- return {
273
- message: `${target} reads ${token} only for ${fmtFeeds(fed)}, not for its ${g}, so this would not change what you expect.`,
274
- run: [
275
- `${P} set ${theme} ${direct} ${quote(value)} --on ${target} # sets its ${g} directly`,
276
- `${HOW} ${target}`,
277
- ],
278
- also: [],
279
- };
267
+ // The part reads the token the user named: it is set as asked, and
268
+ // the result names what it feeds.
269
+ void wanted;
270
+ void fed;
271
+ return null;
280
272
  }
281
273
  const reads = g ? partReads(target, g) : [];
282
274
  const v = quote(value);
@@ -291,9 +283,23 @@ export function makeCompiler(project, parts) {
291
283
  `${P} set ${theme} ${r.token} ${v} --on ${target}${fmtWhen(r.when) ? ` #${fmtWhen(r.when)}` : ''}`,
292
284
  ),
293
285
  );
294
- if (g && DIRECT[g])
286
+ // The property that takes this kind of value: a size goes to
287
+ // font-size, never to font-weight.
288
+ const direct =
289
+ g === 'font'
290
+ ? /-(size)$|font-size-/.test(token)
291
+ ? 'font-size'
292
+ : /-leading$/.test(token)
293
+ ? 'line-height'
294
+ : /-tracking$/.test(token)
295
+ ? 'letter-spacing'
296
+ : /family/.test(token)
297
+ ? 'font-family'
298
+ : 'font-weight'
299
+ : g && DIRECT[g];
300
+ if (direct)
295
301
  run.push(
296
- `${P} set ${theme} ${DIRECT[g]} ${v} --on ${target} # sets it directly, whatever token it uses`,
302
+ `${P} set ${theme} ${direct} ${v} --on ${target} # sets it directly, whatever token it uses`,
297
303
  );
298
304
  const kids = g
299
305
  ? (MAP[target]?.contains ?? [])
@@ -326,10 +332,10 @@ export function makeCompiler(project, parts) {
326
332
  /**
327
333
  * Whether a whole-theme token is read by any part.
328
334
  * @param {string} token
329
- * @param {string} P
335
+ * @param {string} _P the command prefix (unused: the result is a note)
330
336
  * @returns {CheckFailure | null}
331
337
  */
332
- function checkTokenGlobal(token, P) {
338
+ function checkTokenGlobal(token, _P) {
333
339
  if (anyReader(token).length || SOFT.test(token)) return null;
334
340
  const g = groupOfToken(token);
335
341
  const near = g
@@ -340,15 +346,8 @@ export function makeCompiler(project, parts) {
340
346
  : [];
341
347
  return {
342
348
  message: `No component reads ${token}, so setting it changes nothing.${near.length ? ` Tokens components do read for ${g}: ${near.join(', ')}.` : ''}`,
343
- run: near.length
344
- ? near.slice(0, 3).map(t => `${P} set <theme> ${t} <value>`)
345
- : [`${HOW} "<what you want>"`],
346
- also:
347
- g === 'shadow'
348
- ? [
349
- `shadows are set per part: ${P} set <theme> box-shadow "0 2px 6px rgb(0 0 0 / 0.3)" --on card`,
350
- ]
351
- : [],
349
+ run: [`${HOW} ${quote(token)}`],
350
+ also: [],
352
351
  };
353
352
  }
354
353
 
@@ -378,12 +377,37 @@ export function makeCompiler(project, parts) {
378
377
  * in each mode, below 4.5:1 now but not as low in the base theme. Also
379
378
  * the values this theme set that have no fixed color to check (a
380
379
  * `color-mix()`, a `var()`), so the result can say what it skipped.
381
- * @param {(pair: import('./_parts.mjs').TextPair, side: 'fg' | 'bg', mode: string) => string | null | undefined} value
382
- * @param {(pair: import('./_parts.mjs').TextPair, side: 'fg' | 'bg', mode: string) => string | null | undefined} baseValue
380
+ * @param {(pair: TextPair, side: 'fg' | 'bg', mode: string) => string | null | undefined} value
381
+ * @param {(pair: TextPair, side: 'fg' | 'bg', mode: string) => string | null | undefined} baseValue
383
382
  * @param {string[]} modes
384
- * @param {{parseColor: (v: unknown) => number[] | null, ratio: (a: number[], b: number[]) => number}} helpers
383
+ * @param {{parseColor: (v: unknown) => [number, number, number] | null, ratio: (a: number[], b: number[]) => number, alphaOf: (v: unknown) => number, compositeOver: (over: [number, number, number], alpha: number, under: [number, number, number]) => [number, number, number], page: (mode: string) => string | null | undefined}} helpers
384
+ * `page` is the page color in a mode: a see-through background is drawn
385
+ * over it, and see-through text over that background, before measuring.
385
386
  */
386
- function contrast(value, baseValue, modes, {parseColor, ratio}) {
387
+ function contrast(
388
+ value,
389
+ baseValue,
390
+ modes,
391
+ {parseColor, ratio, alphaOf, compositeOver, page},
392
+ ) {
393
+ /**
394
+ * The opaque colors the eye sees for a pair, or null with no fixed color.
395
+ * @param {unknown} fg @param {unknown} bg @param {string} m
396
+ */
397
+ const drawn = (fg, bg, m) => {
398
+ /** @type {[number, number, number]} */
399
+ const ground =
400
+ parseColor(page(m)) ?? (m === 'dark' ? [0, 0, 0] : [255, 255, 255]);
401
+ const bgAlpha = alphaOf(bg);
402
+ const back = parseColor(bg);
403
+ const under =
404
+ bgAlpha === 0
405
+ ? ground
406
+ : back && compositeOver(back, bgAlpha, ground);
407
+ const top = parseColor(fg);
408
+ if (!under || !top) return null;
409
+ return [compositeOver(top, alphaOf(fg), under), under];
410
+ };
387
411
  /** @type {Array<{part: string, mode: string, ratio: number, sample: string, fg: string, bgPart: string | null, bg: string}>} */
388
412
  const out = [];
389
413
  const seen = new Set();
@@ -400,23 +424,25 @@ export function makeCompiler(project, parts) {
400
424
  const fg = value(p, 'fg', m);
401
425
  const bg = value(p, 'bg', m);
402
426
  if (/gradient|url\(/.test(String(bg))) continue;
403
- if (hasAlpha(fg) || hasAlpha(bg)) continue;
404
- const a = parseColor(fg);
405
- const b = parseColor(bg);
406
- if (!a || !b) {
427
+ const pair = drawn(fg, bg, m);
428
+ if (!pair) {
407
429
  for (const [v, side] of /** @type {const} */ ([
408
430
  [fg, 'fg'],
409
431
  [bg, 'bg'],
410
432
  ]))
411
- if (v && !parseColor(v) && v !== baseValue(p, side, m))
433
+ if (
434
+ v &&
435
+ !parseColor(v) &&
436
+ alphaOf(v) !== 0 &&
437
+ v !== baseValue(p, side, m)
438
+ )
412
439
  unchecked.add(String(v));
413
440
  continue;
414
441
  }
415
- const r = ratio(a, b);
442
+ const r = ratio(pair[0], pair[1]);
416
443
  if (r >= 4.5) continue;
417
- const a0 = parseColor(baseValue(p, 'fg', m));
418
- const b0 = parseColor(baseValue(p, 'bg', m));
419
- if (a0 && b0 && ratio(a0, b0) <= r + 0.05) continue;
444
+ const was = drawn(baseValue(p, 'fg', m), baseValue(p, 'bg', m), m);
445
+ if (was && ratio(was[0], was[1]) <= r + 0.05) continue;
420
446
  const key = `${p.text}|${fg}|${bg}|${m}`;
421
447
  if (seen.has(key)) continue;
422
448
  seen.add(key);
@@ -431,7 +457,11 @@ export function makeCompiler(project, parts) {
431
457
  });
432
458
  }
433
459
  }
434
- return {problems: out.slice(0, 8), unchecked: [...unchecked]};
460
+ return {
461
+ problems: out.slice(0, 8),
462
+ more: Math.max(0, out.length - 8),
463
+ unchecked: [...unchecked],
464
+ };
435
465
  }
436
466
 
437
467
  /**
@@ -7,7 +7,12 @@
7
7
  * @param {string} cwd
8
8
  */
9
9
  export function requireProject(cwd: string): void;
10
- /** @param {string} cwd */
10
+ /**
11
+ * The project, its part data and the compiler. When the components cannot
12
+ * be rendered, the part data is empty and `unchecked` says why: changes are
13
+ * then saved without the checks that need it, and say so.
14
+ * @param {string} cwd
15
+ */
11
16
  export function context(cwd: string): Promise<{
12
17
  project: import("./_project.mjs").ThemeProject;
13
18
  C: {
@@ -22,7 +27,7 @@ export function context(cwd: string): Promise<{
22
27
  part: string;
23
28
  prop: string;
24
29
  when: string;
25
- }>>) => string;
30
+ }>>, target?: string) => string;
26
31
  showsCorners: (target: string) => boolean;
27
32
  groupOfToken: (t: string) => string | null;
28
33
  groupOfProp: (p: string) => string | null;
@@ -32,11 +37,14 @@ export function context(cwd: string): Promise<{
32
37
  allReads: (target: string) => Set<string>;
33
38
  anyReader: (tok: string) => string[];
34
39
  checkTokenOn: (theme: string, target: string, token: string, value: string, P: string) => CheckFailure | null;
35
- checkTokenGlobal: (token: string, P: string) => CheckFailure | null;
40
+ checkTokenGlobal: (token: string, _P: string) => CheckFailure | null;
36
41
  variantValues: (target: string) => Record<string, string[]>;
37
- contrast: (value: (pair: import("./_parts.mjs").TextPair, side: "fg" | "bg", mode: string) => string | null | undefined, baseValue: (pair: import("./_parts.mjs").TextPair, side: "fg" | "bg", mode: string) => string | null | undefined, modes: string[], { parseColor, ratio }: {
38
- parseColor: (v: unknown) => number[] | null;
42
+ contrast: (value: (pair: TextPair, side: "fg" | "bg", mode: string) => string | null | undefined, baseValue: (pair: TextPair, side: "fg" | "bg", mode: string) => string | null | undefined, modes: string[], { parseColor, ratio, alphaOf, compositeOver, page }: {
43
+ parseColor: (v: unknown) => [number, number, number] | null;
39
44
  ratio: (a: number[], b: number[]) => number;
45
+ alphaOf: (v: unknown) => number;
46
+ compositeOver: (over: [number, number, number], alpha: number, under: [number, number, number]) => [number, number, number];
47
+ page: (mode: string) => string | null | undefined;
40
48
  }) => {
41
49
  problems: {
42
50
  part: string;
@@ -47,10 +55,12 @@ export function context(cwd: string): Promise<{
47
55
  bgPart: string | null;
48
56
  bg: string;
49
57
  }[];
58
+ more: number;
50
59
  unchecked: string[];
51
60
  };
52
61
  };
53
62
  parts: import("./_parts.mjs").PartData;
63
+ unchecked: string | null;
54
64
  }>;
55
65
  /**
56
66
  * Pictures of HTML files, on request.
@@ -90,9 +100,19 @@ export function styledChanges(before: any, after: any): string[];
90
100
  * @param {boolean} png
91
101
  */
92
102
  export function previewAfter(ctx: import("./_settings.mjs").Ctx, slug: string, data: import("./_settings.mjs").ThemeData, png: boolean): Promise<{
93
- preview: string;
103
+ preview: string | null;
94
104
  pictures: string[];
95
105
  pictureProblem: string | null;
106
+ notChecked: {
107
+ code: import("../../foundation/response/error-codes.mjs").ErrorCode;
108
+ cause: string;
109
+ } | null;
96
110
  }>;
97
- /** @param {string | undefined} group */
98
- export function checkGroup(group: string | undefined): void;
111
+ /**
112
+ * The section of the sheet, in lower case, or undefined; a refusal for one
113
+ * that is not a section.
114
+ * @param {string | undefined} section
115
+ * @param {string} [theme] the theme the suggestions name
116
+ * @returns {string | undefined}
117
+ */
118
+ export function checkSection(section: string | undefined, theme?: string): string | undefined;
@@ -8,6 +8,9 @@
8
8
  * @position api/theme-edit — imported only by the adapter's operation helpers
9
9
  */
10
10
 
11
+ import * as fs from 'node:fs';
12
+ import {createRequire} from 'node:module';
13
+ import * as path from 'node:path';
11
14
  import {AstryxError} from '../error.mjs';
12
15
  import {isOutsideProject} from '../../foundation/env/project-scope.mjs';
13
16
  import {CLOSEST_OPEN_FONT, OPEN_FONTS, P, SYSTEM_FONTS} from './_tables.mjs';
@@ -34,6 +37,21 @@ const E = ERROR_CODES;
34
37
  */
35
38
  export function requireProject(cwd) {
36
39
  if (!isOutsideProject(cwd)) return;
40
+ const pkg = path.join(cwd, 'package.json');
41
+ // Yarn Plug'n'Play has no node_modules for the editor to read Core from.
42
+ if (fs.existsSync(path.join(cwd, '.pnp.cjs')))
43
+ throw new AstryxError(
44
+ "This app uses Yarn Plug'n'Play, which astryx experimental theme does not support: it reads the installed Core from node_modules. Set `nodeLinker: node-modules` in .yarnrc.yml and run yarn install. Nothing was written.",
45
+ [],
46
+ E.ERR_PROJECT_REQUIRED,
47
+ );
48
+ // A package.json with no Core: an app (or a workspace root) that needs it.
49
+ if (fs.existsSync(pkg))
50
+ throw new AstryxError(
51
+ `@astryxdesign/core is not installed in this app (package.json here does not use it). astryx experimental theme checks every change against the installed Core: install it, or run the command from the package that uses it. Nothing was written.`,
52
+ [{name: 'npm install @astryxdesign/core', reason: 'do this first'}],
53
+ E.ERR_PROJECT_REQUIRED,
54
+ );
37
55
  throw new AstryxError(
38
56
  'No package.json found. astryx experimental theme works inside an app project, which it writes the theme into and whose installed Core it checks every change against. Nothing was written.',
39
57
  [],
@@ -41,14 +59,79 @@ export function requireProject(cwd) {
41
59
  );
42
60
  }
43
61
 
44
- /** @param {string} cwd */
62
+ /**
63
+ * The project, its part data and the compiler. When the components cannot
64
+ * be rendered, the part data is empty and `unchecked` says why: changes are
65
+ * then saved without the checks that need it, and say so.
66
+ * @param {string} cwd
67
+ */
45
68
  export async function context(cwd) {
46
69
  requireProject(cwd);
47
70
  const project = await openProject(cwd);
48
- const parts = await partData(project);
49
- return {project, C: makeCompiler(project, parts), parts};
71
+ /** @type {import('./_parts.mjs').PartData} */
72
+ let parts;
73
+ /** @type {string | null} */
74
+ let unchecked = null;
75
+ try {
76
+ parts = await partData(project);
77
+ } catch (e) {
78
+ if (!isRenderFailure(e)) throw e;
79
+ unchecked = renderCause(project, /** @type {Error} */ (e).message);
80
+ parts = {
81
+ version: 0,
82
+ coreKey: project.coreKey,
83
+ map: {},
84
+ pairs: [],
85
+ rendered: 0,
86
+ items: 0,
87
+ };
88
+ }
89
+ return {project, C: makeCompiler(project, parts), parts, unchecked};
90
+ }
91
+
92
+ /** @param {unknown} e */
93
+ const isRenderFailure = e =>
94
+ e instanceof AstryxError &&
95
+ (e.code === E.ERR_RENDER_FAILED ||
96
+ e.code === E.ERR_RENDER_MISSING_DEPENDENCY);
97
+
98
+ /**
99
+ * Why the components did not render, with the likely cause: two copies of
100
+ * React (the app's and the one Core resolves) break every hook.
101
+ * @param {import('./_project.mjs').ThemeProject} project
102
+ * @param {string} message
103
+ */
104
+ function renderCause(project, message) {
105
+ /** @param {(id: string) => string} resolve */
106
+ const reactOf = resolve => {
107
+ try {
108
+ return fs.realpathSync(path.dirname(resolve('react/package.json')));
109
+ } catch {
110
+ return null;
111
+ }
112
+ };
113
+ const app = reactOf(project.req.resolve);
114
+ let core = null;
115
+ try {
116
+ core = reactOf(
117
+ createRequire(project.req.resolve('@astryxdesign/core/package.json'))
118
+ .resolve,
119
+ );
120
+ } catch {
121
+ // No Core package file: nothing to compare.
122
+ }
123
+ return app && core && app !== core
124
+ ? `${message} The likely cause: two copies of React, the app's (${app}) and the one Core resolves (${core}). Make Core resolve the app's React.`
125
+ : message;
50
126
  }
51
127
 
128
+ /**
129
+ * The "saved, not checked" report of a change, or null when it was checked.
130
+ * @param {string | null} cause
131
+ */
132
+ const notChecked = cause =>
133
+ cause ? {code: E.ERR_THEME_NOT_CHECKED, cause} : null;
134
+
52
135
  /**
53
136
  * Pictures of HTML files, on request.
54
137
  * @param {import('./_project.mjs').ThemeProject} project
@@ -85,10 +168,17 @@ export function fontNotes(ctx, data) {
85
168
  /** @type {string[]} */
86
169
  const notes = [];
87
170
  for (const {pkg, family, installed} of fontPackages(ctx, data)) {
171
+ const fallbacks =
172
+ Object.values(OPEN_FONTS).find(f => f.pkg === pkg)?.fallbacks ?? '';
173
+ const near = /monospace/.test(fallbacks)
174
+ ? 'mono'
175
+ : /serif/.test(fallbacks.replace('sans-serif', ''))
176
+ ? 'serif'
177
+ : 'system';
88
178
  notes.push(
89
179
  installed
90
- ? `the app loads this font with one import: import '${pkg}';`
91
- : `${family} is not installed, so it does not load: the previews and the app show the next font in the stack. Install it: ${installLine(ctx.project.cwd, [pkg])}. Then the preview imports it on the next set or show, and the app imports it once: import '${pkg}';`,
180
+ ? `${family} is installed (${pkg}), so the previews load it; the app loads it with one import: import '${pkg}';`
181
+ : `${family} is not installed, so it does not load: the previews and the app show the next font in the stack. Install it: ${installLine(ctx.project.cwd, [pkg])}. Then the preview imports it on the next set or show, and the app imports it once: import '${pkg}'; Until then, the closest font that needs no install is ${near}: ${P} set ${data.name} font ${near}`,
92
182
  );
93
183
  }
94
184
  for (const s of data.settings) {
@@ -177,24 +267,57 @@ export function styledChanges(before, after) {
177
267
  * @param {boolean} png
178
268
  */
179
269
  export async function previewAfter(ctx, slug, data, png) {
180
- const preview = await renderPreview(ctx, slug, data);
270
+ /** @type {string | null} */
271
+ let preview = null;
272
+ let cause = ctx.unchecked ?? null;
273
+ try {
274
+ preview = await renderPreview(ctx, slug, data);
275
+ } catch (e) {
276
+ // The change is already saved: any failure here leaves it unchecked.
277
+ cause ??= isRenderFailure(e)
278
+ ? renderCause(ctx.project, /** @type {Error} */ (e).message)
279
+ : `checking it failed: ${e instanceof Error ? e.message : String(e)}`;
280
+ }
181
281
  const f = themeFiles(ctx.project.cwd, slug);
182
- const shots = png
183
- ? await pictures(
184
- ctx.project,
185
- [{html: f.preview, png: f.previewPng}],
186
- modesOf(data),
187
- )
188
- : {files: [], problem: null};
189
- return {preview, pictures: shots.files, pictureProblem: shots.problem};
282
+ const shots =
283
+ png && preview
284
+ ? await pictures(
285
+ ctx.project,
286
+ [{html: f.preview, png: f.previewPng}],
287
+ modesOf(data),
288
+ )
289
+ : {files: [], problem: null};
290
+ return {
291
+ preview,
292
+ pictures: shots.files,
293
+ pictureProblem: shots.problem,
294
+ notChecked: notChecked(cause),
295
+ };
190
296
  }
191
297
 
192
- /** @param {string | undefined} group */
193
- export function checkGroup(group) {
194
- if (group != null && !SHOWCASE_GROUPS.includes(group))
298
+ /**
299
+ * The section of the sheet, in lower case, or undefined; a refusal for one
300
+ * that is not a section.
301
+ * @param {string | undefined} section
302
+ * @param {string} [theme] the theme the suggestions name
303
+ * @returns {string | undefined}
304
+ */
305
+ export function checkSection(section, theme = 'my') {
306
+ if (section === '')
307
+ refuse(E.ERR_MISSING_ARGUMENT, '--section was given no value.', {
308
+ run: [`${P} show ${theme} --section ${SHOWCASE_GROUPS[0]}`],
309
+ });
310
+ const s = section?.toLowerCase();
311
+ if (s != null && !SHOWCASE_GROUPS.includes(s))
195
312
  refuse(
196
313
  E.ERR_INVALID_ARGUMENT,
197
- `--group takes ${SHOWCASE_GROUPS.join(', ')}, not "${group}".`,
198
- {didYouMean: nearest(group, SHOWCASE_GROUPS)},
314
+ `--section takes ${SHOWCASE_GROUPS.join(', ')}, not "${section}".`,
315
+ {
316
+ didYouMean: nearest(s, SHOWCASE_GROUPS),
317
+ run: [
318
+ `${P} show ${theme} --section ${nearest(s, SHOWCASE_GROUPS)[0] ?? SHOWCASE_GROUPS[0]}`,
319
+ ],
320
+ },
199
321
  );
322
+ return s;
200
323
  }
@@ -5,7 +5,9 @@
5
5
  * @typedef {import('./theme-edit.type.mjs').ThemeEditChangeOptions} ChangeOptions
6
6
  */
7
7
  /**
8
- * Start a theme in themes/<name>/, optionally on a built-in theme.
8
+ * Start a theme in themes/<name>/, optionally on a built-in theme, with any
9
+ * dial settings applied in the same build. Each setting is checked as `set`
10
+ * checks it, before anything is written.
9
11
  * @experimental
10
12
  * @param {string} name
11
13
  * @param {import('./theme-edit.type.mjs').ThemeEditNewOptions} [options]