@astryxdesign/cli 0.7.14-canary.g05da5aa → 0.7.14-canary.gdcc8823

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 (65) hide show
  1. package/api/theme-edit/_check.mjs +193 -26
  2. package/api/theme-edit/_context.d.mts +14 -4
  3. package/api/theme-edit/_context.mjs +107 -18
  4. package/api/theme-edit/_edit.d.mts +3 -1
  5. package/api/theme-edit/_edit.mjs +112 -40
  6. package/api/theme-edit/_how.d.mts +17 -6
  7. package/api/theme-edit/_how.mjs +222 -48
  8. package/api/theme-edit/_overview.d.mts +9 -0
  9. package/api/theme-edit/_overview.mjs +295 -0
  10. package/api/theme-edit/_palette.d.mts +14 -4
  11. package/api/theme-edit/_palette.mjs +117 -46
  12. package/api/theme-edit/_preview-app.d.mts +8 -6
  13. package/api/theme-edit/_preview-app.mjs +271 -45
  14. package/api/theme-edit/_preview.d.mts +32 -5
  15. package/api/theme-edit/_preview.mjs +292 -23
  16. package/api/theme-edit/_settings.d.mts +11 -3
  17. package/api/theme-edit/_settings.mjs +82 -10
  18. package/api/theme-edit/_tables.d.mts +5 -5
  19. package/api/theme-edit/_tables.mjs +31 -24
  20. package/api/theme-edit/theme-edit.type.d.mts +61 -48
  21. package/api/theme-edit/theme-edit.type.mjs +29 -25
  22. package/api/theme-edit/themeEditHow.doc.mjs +6 -5
  23. package/api/theme-edit/themeEditNew.doc.mjs +13 -3
  24. package/api/theme-edit/themeEditPreviewAdd.doc.mjs +1 -1
  25. package/api/theme-edit/themeEditSet.doc.mjs +6 -6
  26. package/api/theme-edit/themeEditShow.doc.mjs +4 -4
  27. package/api/theme-edit/themeEditUndo.doc.mjs +2 -2
  28. package/assets/docs/tree/icon-sets.doc.mjs +3 -3
  29. package/assets/icons/definitions/bookmarkAdd.doc.mjs +9 -0
  30. package/assets/icons/definitions/documentSearch.doc.mjs +9 -0
  31. package/assets/icons/definitions/keyboard.doc.mjs +9 -0
  32. package/assets/icons/definitions/paintBrush.doc.mjs +9 -0
  33. package/assets/icons/definitions/wallet.doc.mjs +9 -0
  34. package/assets/templates/blocks/components/ButtonGroup/ButtonGroupShowcase.doc.mjs +1 -1
  35. package/assets/templates/blocks/components/Lightbox/LightboxGallery.tsx +1 -1
  36. package/assets/templates/pages/gallery-hero/page.tsx +8 -2
  37. package/assets/templates/pages/settings-dialog/template.doc.mjs +3 -3
  38. package/assets/templates/pages/side-gallery/page.tsx +1 -1
  39. package/assets/templates/pages/table-filter/template.doc.mjs +2 -2
  40. package/assets/templates/pages/theme-showcase/page.tsx +11 -3
  41. package/assets/templates/pages/theme-showcase/template.doc.mjs +1 -1
  42. package/clients/cli/commands/experimental/theme.mjs +124 -27
  43. package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +10 -6
  44. package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +103 -3
  45. package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +12 -7
  46. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +5 -5
  47. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +3 -3
  48. package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
  49. package/clients/cli/commands/experimental-theme-preview-add.doc.mjs +1 -1
  50. package/clients/cli/commands/experimental-theme.doc.mjs +1 -2
  51. package/clients/cli/commands/theme.mjs +41 -6
  52. package/clients/cli/index.mjs +0 -1
  53. package/foundation/discovery/template-adapter.mjs +5 -3
  54. package/foundation/discovery/template-icons.d.mts +13 -0
  55. package/foundation/discovery/template-icons.mjs +76 -0
  56. package/foundation/fs/import-url.d.mts +5 -4
  57. package/foundation/fs/import-url.mjs +5 -4
  58. package/foundation/fs/module-loader.mjs +6 -3
  59. package/foundation/response/error-codes.d.mts +2 -1
  60. package/foundation/response/error-codes.doc.mjs +6 -0
  61. package/foundation/response/error-codes.mjs +5 -0
  62. package/foundation/response/response-types.doc.mjs +4 -4
  63. package/package.json +6 -7
  64. package/clients/cli/commands/experimental-theme-palette-generate.doc.mjs +0 -73
  65. package/clients/cli/commands/experimental-theme-palette.doc.mjs +0 -37
@@ -36,7 +36,13 @@ import {
36
36
  } from './_tables.mjs';
37
37
  import {isColorValue, isNumber, isSize} from './_color.mjs';
38
38
  import {MODAL} from './_compiler.mjs';
39
- import {PALETTE_DIALS, paletteToken, seedOf} from './_palette.mjs';
39
+ import {
40
+ PALETTE_DIALS,
41
+ PALETTE_TOKENS,
42
+ VIBRANCY_DEFAULT,
43
+ paletteToken,
44
+ seedOf,
45
+ } from './_palette.mjs';
40
46
  import {
41
47
  camel,
42
48
  kebab,
@@ -145,13 +151,13 @@ export function checkSetting(
145
151
  if (!fam || FAMILIES[/** @type {string} */ (s.on)])
146
152
  refuse(
147
153
  E.ERR_INVALID_ARGUMENT,
148
- '--only is for one member of a family, such as text-input (how --list families).',
149
- {run: [`${HOW} --list families`]},
154
+ '--only is for one member of a group, such as text-input (how --list groups).',
155
+ {run: [`${HOW} --list groups`]},
150
156
  );
151
157
  if (!AUTO_SPREAD.includes(/** @type {string} */ (fam)))
152
158
  refuse(
153
159
  E.ERR_INVALID_ARGUMENT,
154
- `${s.on} is styled on its own already: only ${AUTO_SPREAD.join(' and ')} spread to their family, so drop --only.`,
160
+ `${s.on} is styled on its own already: only ${AUTO_SPREAD.join(' and ')} spread to their group, so drop --only.`,
155
161
  {
156
162
  run: [
157
163
  unset
@@ -296,7 +302,7 @@ export function checkSetting(
296
302
  const token = paletteToken(thing);
297
303
  refuse(
298
304
  E.ERR_THEME_BAD_VALUE,
299
- `${thing} grows one palette for the whole theme, light and dark from one color; drop ${s.on ? '--on' : '--mode'}. For an exact color on one part or in one mode, set the token itself.`,
305
+ `${thing} generates the colors of the whole theme, light and dark from one color; drop ${s.on ? '--on' : '--mode'}. For an exact color on one part or in one mode, set the token itself.`,
300
306
  {
301
307
  run: [
302
308
  `${P} set ${slug} ${token} ${q(v || '#7c3aed')}${onFlag}${s.mode ? ` --mode ${s.mode}` : ''}`,
@@ -362,11 +368,43 @@ export function checkSetting(
362
368
  if (!seedOf(v))
363
369
  refuse(
364
370
  E.ERR_THEME_BAD_VALUE,
365
- `"${v}" has no fixed color, so the palette cannot grow from it.`,
371
+ `"${v}" has no fixed color, so no shades can be generated from it.`,
366
372
  {
367
373
  fix: 'give a hex, a color name, or an rgb(), hsl(), hwb(), lab(), lch(), oklab() or oklch() color',
368
374
  },
369
375
  );
376
+ } else if (thing === 'vibrancy') {
377
+ if (s.on)
378
+ refuse(
379
+ E.ERR_THEME_BAD_VALUE,
380
+ 'vibrancy applies to every generated color of the theme; drop --on.',
381
+ {run: [`${P} set ${slug} vibrancy ${q(v)}`]},
382
+ );
383
+ if (step) {
384
+ const cur = Number(
385
+ [...data.settings].reverse().find(x => x.thing === 'vibrancy')
386
+ ?.value ?? VIBRANCY_DEFAULT,
387
+ );
388
+ s.value = String(
389
+ Math.max(0, Math.min(100, cur + (v === 'more' ? 10 : -10))),
390
+ );
391
+ } else if (!/^\d{1,3}$/.test(v) || Number(v) > 100)
392
+ refuse(
393
+ E.ERR_THEME_BAD_VALUE,
394
+ `vibrancy takes a whole number from 0 (gray) to 100 (most vivid), or more or less, not "${v}".`,
395
+ {run: [`${P} set ${slug} vibrancy 60`]},
396
+ );
397
+ else s.value = String(Number(v));
398
+ if (
399
+ !data.settings.some(
400
+ x => x.source === 'dial' && PALETTE_DIALS.includes(x.thing),
401
+ )
402
+ )
403
+ refuse(
404
+ E.ERR_THEME_NO_EFFECT,
405
+ 'vibrancy sets how saturated the generated colors are, and this theme sets no color yet. Set one first.',
406
+ {run: [`${P} set ${slug} accent "#7c3aed"`]},
407
+ );
370
408
  } else if (thing === 'font') {
371
409
  if (s.on && !isRole)
372
410
  refuse(
@@ -439,6 +477,8 @@ export function checkSetting(
439
477
  `"more"/"less" work only on dials (${Object.keys(DIALS).join(', ')}). Give ${thing} a ${type} value.`,
440
478
  );
441
479
  checkTypedValue(type, v, thing);
480
+ // With no part data, what reads the token is unknown: save, unchecked.
481
+ if (ctx.unchecked) return s;
442
482
  const parts = partsOf(ctx, s);
443
483
  if (parts.length) {
444
484
  const results = parts.map(
@@ -453,8 +493,8 @@ export function checkSetting(
453
493
  const spread = Boolean(
454
494
  FAMILIES[s.on ?? ''] || (familyOf(s.on ?? '') && parts.length > 1),
455
495
  );
456
- // A part with no record is judged by its family: refused when no
457
- // member that has a record reads the token, as the family form is.
496
+ // A part with no record is judged by its group: refused when no
497
+ // member that has a record reads the token, as the group form is.
458
498
  const fam = s.on ? familyOf(s.on) : null;
459
499
  if (!recorded.length && fam && !spread) {
460
500
  const siblings = FAMILIES[fam].filter(t => C.MAP[t]);
@@ -471,7 +511,7 @@ export function checkSetting(
471
511
  );
472
512
  refuse(
473
513
  E.ERR_THEME_NO_EFFECT,
474
- `No part of the ${fam} family reads ${thing}, so ${s.on} cannot either. ${r.message}`,
514
+ `No part of the ${fam} group reads ${thing}, so ${s.on} cannot either. ${r.message}`,
475
515
  {
476
516
  run: r.run.map(x =>
477
517
  x.replace(`--on ${famResults[0][0]}`, `--on ${s.on}`),
@@ -481,7 +521,7 @@ export function checkSetting(
481
521
  );
482
522
  }
483
523
  if (famResults.length)
484
- s.note = `${s.on} has no compiled record; checked against the ${fam} family, where ${famResults
524
+ s.note = `${s.on} has no compiled record; checked against the ${fam} group, where ${famResults
485
525
  .filter(([, r]) => !r)
486
526
  .map(([t]) => t)
487
527
  .join(', ')} read ${thing}`;
@@ -509,7 +549,11 @@ export function checkSetting(
509
549
  ).message;
510
550
  } else {
511
551
  const r = C.checkTokenGlobal(thing, P);
512
- if (r)
552
+ // A token a dial writes is always accepted, so a dial's notes never
553
+ // name a token `set` refuses.
554
+ if (r && dialWrites(thing))
555
+ s.note = `no part reads ${thing} directly in this Core; a dial writes it too, so it is set as asked`;
556
+ else if (r)
513
557
  refuse(E.ERR_THEME_NO_EFFECT, r.message, {run: r.run, also: r.also});
514
558
  }
515
559
  return s;
@@ -519,7 +563,7 @@ export function checkSetting(
519
563
  if (!s.on)
520
564
  refuse(
521
565
  E.ERR_MISSING_ARGUMENT,
522
- `${prop} is a CSS property, so it needs --on <part|family>. For the whole theme use a dial or a token.`,
566
+ `${prop} is a CSS property, so it needs --on <part|group>. For the whole theme use a dial or a token.`,
523
567
  {
524
568
  run: [
525
569
  `${P} set ${slug} ${prop} ${q(v || '<value>')} --on <part>`,
@@ -607,6 +651,7 @@ export function checkSetting(
607
651
  * @param {import('./_settings.mjs').Setting} s
608
652
  */
609
653
  function refuseInvisibleCorners(ctx, slug, s) {
654
+ if (ctx.unchecked) return;
610
655
  const parts = partsOf(ctx, s);
611
656
  if (!parts.length || parts.some(t => ctx.C.showsCorners(t))) return;
612
657
  const kids = (ctx.C.MAP[parts[0]]?.contains ?? [])
@@ -625,6 +670,18 @@ function refuseInvisibleCorners(ctx, slug, s) {
625
670
  );
626
671
  }
627
672
 
673
+ /**
674
+ * Whether a dial writes the token: a color, a heading weight (type,
675
+ * headings), a radius (corners), a spacing or control size (spacing), or a
676
+ * font size (type, text-size).
677
+ * @param {string} token
678
+ */
679
+ const dialWrites = token =>
680
+ PALETTE_TOKENS.has(token) ||
681
+ /^--(text-(heading|display)-\d-weight|radius-|spacing-|size-element-|font-size-)/.test(
682
+ token,
683
+ );
684
+
628
685
  /**
629
686
  * Answer a plain-words question with exact commands: the parts it names,
630
687
  * the aspects it asks about, and what each part really reads for them.
@@ -637,22 +694,38 @@ export function answerHow(ctx, question) {
637
694
  const TARGET = ctx.project.target;
638
695
  const TOKENS = ctx.project.core.tokenDefaults;
639
696
  const text = question.toLowerCase();
697
+ /** @type {Array<string | null>} */
698
+ let intents = INTENTS.filter(([, re]) => re.test(text)).map(([g]) => g);
699
+ // "pill" is a corner shape when the question is about corners.
700
+ const partText = intents.includes('corners')
701
+ ? text.replace(/\bpills?\b/g, '')
702
+ : text;
640
703
  /** @type {string[]} */
641
- const parts = [];
704
+ let parts = [];
642
705
  for (const [re, ts] of PART_WORDS)
643
- if (re.test(text))
706
+ if (re.test(partText))
644
707
  for (const t of ts) if (!parts.includes(t)) parts.push(t);
645
- /** @type {Array<string | null>} */
646
- let intents = INTENTS.filter(([, re]) => re.test(text)).map(([g]) => g);
708
+ // A variant of a part ("secondary button") answers for the part.
709
+ parts = parts.filter(p => !parts.some(x => x.startsWith(`${p}:`)));
710
+ const whiteText =
711
+ /\bwhite (text|labels?|writing|words)\b|\b(text|labels?|writing|words) (in |is |are )?white\b/.test(
712
+ text,
713
+ );
647
714
  if (
648
715
  intents.includes('text') &&
649
716
  intents.includes('background') &&
650
- !/background|fill|gradient|glossy/.test(text)
717
+ !/background|fill|gradient|glossy/.test(text) &&
718
+ !(/\bwhite\b/.test(text) && !whiteText)
651
719
  )
652
720
  intents = intents.filter(g => g !== 'background');
653
721
  if (!intents.length && parts.length) intents = [null];
654
722
  const design = Object.keys(DESIGN).filter(w => text.includes(w));
655
723
  const tracking = /letter ?spacing|tracking|kerning/.test(text);
724
+ // Letter spacing is a font answer, so a spacing intent it raised goes.
725
+ if (tracking && intents.includes('font'))
726
+ intents = intents.filter(g => g !== 'spacing');
727
+ const weight = /\b(bold|weight|heav\w*|light(er)?|thin)\b/.test(text);
728
+ const px = /\b(\d+(?:\.\d+)?px)\b/.exec(text)?.[1];
656
729
  /** @type {Array<{text: string, commands: string[]}>} */
657
730
  const results = [];
658
731
  /** @param {string | null} g */
@@ -666,14 +739,33 @@ export function answerHow(ctx, question) {
666
739
  if (g === 'font' && tracking)
667
740
  return /tight/.test(text) ? '-0.02em' : '0.04em';
668
741
  if (g === 'font' && /bold|heav/.test(text)) return '700';
669
- if (g === 'text' && /white/.test(text)) return '"#ffffff"';
742
+ if (g === 'font' && /\b(light(er)?|thin)\b/.test(text)) return '300';
743
+ if (g === 'text' && whiteText) return '"#ffffff"';
744
+ if (g === 'text' && /\baccent (text|labels?)\b/.test(text))
745
+ return '"var(--color-text-accent)"';
746
+ if (g === 'background' && /\bwhite\b/.test(text) && !whiteText)
747
+ return '"#ffffff"';
670
748
  return '<value>';
671
749
  };
672
750
  for (const raw of parts.slice(0, 3)) {
673
- const [part, wp, wv] = raw.split(':');
674
- const when = wp ? ` --when ${wp}:${wv}` : '';
751
+ let [part, wp, wv] = raw.split(':');
752
+ const named = Boolean(wp);
675
753
  const one = FAMILIES[part] ? FAMILIES[part][0] : part;
676
754
  if (!TARGET.has(one)) continue;
755
+ // A size in the question ("small buttons") is a --when condition.
756
+ if (!wp) {
757
+ const sizes = C.variantValues(one).size ?? [];
758
+ const word = /\b(small|sm)\b/.test(text)
759
+ ? ['sm', 'small']
760
+ : /\b(large|lg|big)\b/.test(text)
761
+ ? ['lg', 'large']
762
+ : /\b(medium|md)\b/.test(text)
763
+ ? ['md', 'medium']
764
+ : [];
765
+ const hit = word.find(w => sizes.includes(w));
766
+ if (hit) [wp, wv] = ['size', hit];
767
+ }
768
+ const when = wp ? ` --when ${wp}:${wv}` : '';
677
769
  // A part with variants: a change without --when reaches every variant.
678
770
  const variants = Object.entries(C.variantValues(one)).filter(
679
771
  ([p, vals]) =>
@@ -687,12 +779,47 @@ export function answerHow(ctx, question) {
687
779
  });
688
780
  continue;
689
781
  }
782
+ if (g === 'corners' && !named) {
783
+ // Each clause with its own size ("small 6px, large stay pill").
784
+ const sizes = C.variantValues(one).size ?? [];
785
+ const clauses = text
786
+ .split(/,|;|\bbut\b|\band\b/)
787
+ .map(c => {
788
+ const size = /\b(small|sm)\b/.test(c)
789
+ ? 'sm'
790
+ : /\b(large|lg|big)\b/.test(c)
791
+ ? 'lg'
792
+ : /\b(medium|md)\b/.test(c)
793
+ ? 'md'
794
+ : null;
795
+ const value =
796
+ /\b(\d+(?:\.\d+)?px)\b/.exec(c)?.[1] ??
797
+ (/pill|circ/.test(c)
798
+ ? 'pill'
799
+ : /sharp|square/.test(c)
800
+ ? 'square'
801
+ : null);
802
+ return {size, value};
803
+ })
804
+ .filter(c => c.size && sizes.includes(c.size) && c.value);
805
+ if (clauses.length > 1) {
806
+ results.push({
807
+ text: `corners on ${part}, by size`,
808
+ commands: clauses.map(c =>
809
+ /px$/.test(/** @type {string} */ (c.value))
810
+ ? `${P} set <theme> border-radius ${c.value} --on ${part} --when size:${c.size}`
811
+ : `${P} set <theme> corners ${c.value} --on ${part} --when size:${c.size}`,
812
+ ),
813
+ });
814
+ continue;
815
+ }
816
+ }
690
817
  if (g === 'corners') {
691
818
  results.push({
692
819
  text: `corners on ${part}${when ? ` (${wp} ${wv})` : ''}`,
693
820
  commands: [
694
821
  `${P} set <theme> corners ${/pill|circ/.test(text) ? 'pill' : /sharp|square/.test(text) ? 'square' : 'round'} --on ${part}${when}`,
695
- `${P} set <theme> border-radius 6px --on ${part}${when}`,
822
+ `${P} set <theme> border-radius ${px ?? '6px'} --on ${part}${when}`,
696
823
  ],
697
824
  });
698
825
  continue;
@@ -725,12 +852,24 @@ export function answerHow(ctx, question) {
725
852
  text: `room inside ${part}`,
726
853
  commands: [
727
854
  `${P} set <theme> spacing ${/dense|compact|tight|cramped/.test(text) ? 'compact' : 'roomy'} --on ${part}`,
728
- `${P} set <theme> padding 12px --on ${part}${when}`,
855
+ `${P} set <theme> padding ${px ?? '12px'} --on ${part}${when}`,
729
856
  ],
730
857
  });
731
858
  continue;
732
859
  }
733
860
  const group = g === 'spacing' ? 'font' : g;
861
+ if (group === 'font' && tracking && weight)
862
+ results.push({
863
+ text: `${part} weight: font-weight on the part${part === 'heading' ? ', or the headings dial for every heading' : ''}`,
864
+ commands: [
865
+ `${P} set <theme> font-weight ${/\b(light(er)?|thin)\b/.test(text) ? 300 : 700} --on ${part}${when}`,
866
+ ...(part === 'heading'
867
+ ? [
868
+ `${P} set <theme> headings ${/\b(light(er)?|thin)\b/.test(text) ? 'light' : 'bold'}`,
869
+ ]
870
+ : []),
871
+ ],
872
+ });
734
873
  const reads = C.partReads(one, group);
735
874
  const filtered = wv
736
875
  ? reads.filter(
@@ -739,7 +878,22 @@ export function answerHow(ctx, question) {
739
878
  r.when.includes(''),
740
879
  )
741
880
  : reads;
742
- const list = (filtered.length ? filtered : reads).slice(0, 4);
881
+ // Weight and tracking questions name only the tokens for them.
882
+ const aspect =
883
+ group === 'font' && tracking
884
+ ? /letter|tracking/
885
+ : group === 'font' && weight
886
+ ? /weight/
887
+ : null;
888
+ const fitting = aspect
889
+ ? (filtered.length ? filtered : reads).filter(r => aspect.test(r.token))
890
+ : filtered.length
891
+ ? filtered
892
+ : reads;
893
+ // Text with no color token of its own takes the page's text color.
894
+ const inherited =
895
+ !fitting.length && group === 'text' ? '--color-text-primary' : null;
896
+ const list = fitting.slice(0, 4);
743
897
  const direct =
744
898
  group === 'font' && tracking
745
899
  ? 'letter-spacing'
@@ -752,9 +906,12 @@ export function answerHow(ctx, question) {
752
906
  (group === 'text' || group === 'background' || group === 'border') &&
753
907
  !/gradient|inset/.test(V(group));
754
908
  results.push({
755
- text: `${part} ${group}${when ? ` (${wp} ${wv})` : ''}: ${list.length ? `comes from ${list.map(r => r.token + C.fmtWhen(r.when) + C.statusNote(one, r.token)).join(', ')}` : 'no token; set the property directly'}`,
909
+ text: `${part} ${aspect ? (tracking ? 'letter spacing' : 'weight') : group}${when ? ` (${wp} ${wv})` : ''}: ${list.length ? `comes from ${list.map(r => r.token + C.fmtWhen(r.when) + C.statusNote(one, r.token)).join(', ')}` : inherited ? `inherits the page's text color (${inherited} for the whole theme); set the property for this part alone` : 'no token of its own; set the property directly'}`,
756
910
  commands: [
757
911
  `${P} set <theme> ${direct} ${V(group)} --on ${part}${when} # direct: always works`,
912
+ ...(inherited
913
+ ? [`${P} set <theme> ${inherited} ${V(group)} # the whole theme`]
914
+ : []),
758
915
  ...(tokenRoute
759
916
  ? list
760
917
  .slice(0, 2)
@@ -816,12 +973,14 @@ export function answerHow(ctx, question) {
816
973
  text: DIALS[dial].help,
817
974
  commands: DIALS[dial].examples.map(e => `${P} ${e}`),
818
975
  });
976
+ // Text and background colors come from their tokens first; the brand
977
+ // color after.
978
+ results.push(...wholeThemeTokens(ctx, g));
819
979
  if (g === 'background' || g === 'text')
820
980
  results.push({
821
981
  text: DIALS.accent.help,
822
982
  commands: DIALS.accent.examples.map(e => `${P} ${e}`),
823
983
  });
824
- results.push(...wholeThemeTokens(ctx, g));
825
984
  }
826
985
  }
827
986
  if (!results.length) {
@@ -834,10 +993,18 @@ export function answerHow(ctx, question) {
834
993
  }
835
994
  }
836
995
  void TOKENS;
996
+ const seen = new Set();
837
997
  return {
838
998
  parts,
839
999
  aspects: /** @type {string[]} */ (intents.filter(Boolean)),
840
- results: results.slice(0, 10),
1000
+ results: results
1001
+ .filter(r => {
1002
+ const key = `${r.text}\n${r.commands.join('\n')}`;
1003
+ if (seen.has(key)) return false;
1004
+ seen.add(key);
1005
+ return true;
1006
+ })
1007
+ .slice(0, 10),
841
1008
  };
842
1009
  }
843
1010
 
@@ -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: {
@@ -51,6 +56,7 @@ export function context(cwd: string): Promise<{
51
56
  };
52
57
  };
53
58
  parts: import("./_parts.mjs").PartData;
59
+ unchecked: string | null;
54
60
  }>;
55
61
  /**
56
62
  * Pictures of HTML files, on request.
@@ -90,9 +96,13 @@ export function styledChanges(before: any, after: any): string[];
90
96
  * @param {boolean} png
91
97
  */
92
98
  export function previewAfter(ctx: import("./_settings.mjs").Ctx, slug: string, data: import("./_settings.mjs").ThemeData, png: boolean): Promise<{
93
- preview: string;
99
+ preview: string | null;
94
100
  pictures: string[];
95
101
  pictureProblem: string | null;
102
+ notChecked: {
103
+ code: import("../../foundation/response/error-codes.mjs").ErrorCode;
104
+ cause: string;
105
+ } | null;
96
106
  }>;
97
- /** @param {string | undefined} group */
98
- export function checkGroup(group: string | undefined): void;
107
+ /** @param {string | undefined} section a section of the sheet */
108
+ export function checkSection(section: string | undefined): void;
@@ -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';
@@ -41,14 +44,79 @@ export function requireProject(cwd) {
41
44
  );
42
45
  }
43
46
 
44
- /** @param {string} cwd */
47
+ /**
48
+ * The project, its part data and the compiler. When the components cannot
49
+ * be rendered, the part data is empty and `unchecked` says why: changes are
50
+ * then saved without the checks that need it, and say so.
51
+ * @param {string} cwd
52
+ */
45
53
  export async function context(cwd) {
46
54
  requireProject(cwd);
47
55
  const project = await openProject(cwd);
48
- const parts = await partData(project);
49
- return {project, C: makeCompiler(project, parts), parts};
56
+ /** @type {import('./_parts.mjs').PartData} */
57
+ let parts;
58
+ /** @type {string | null} */
59
+ let unchecked = null;
60
+ try {
61
+ parts = await partData(project);
62
+ } catch (e) {
63
+ if (!isRenderFailure(e)) throw e;
64
+ unchecked = renderCause(project, /** @type {Error} */ (e).message);
65
+ parts = {
66
+ version: 0,
67
+ coreKey: project.coreKey,
68
+ map: {},
69
+ pairs: [],
70
+ rendered: 0,
71
+ items: 0,
72
+ };
73
+ }
74
+ return {project, C: makeCompiler(project, parts), parts, unchecked};
75
+ }
76
+
77
+ /** @param {unknown} e */
78
+ const isRenderFailure = e =>
79
+ e instanceof AstryxError &&
80
+ (e.code === E.ERR_RENDER_FAILED ||
81
+ e.code === E.ERR_RENDER_MISSING_DEPENDENCY);
82
+
83
+ /**
84
+ * Why the components did not render, with the likely cause: two copies of
85
+ * React (the app's and the one Core resolves) break every hook.
86
+ * @param {import('./_project.mjs').ThemeProject} project
87
+ * @param {string} message
88
+ */
89
+ function renderCause(project, message) {
90
+ /** @param {(id: string) => string} resolve */
91
+ const reactOf = resolve => {
92
+ try {
93
+ return fs.realpathSync(path.dirname(resolve('react/package.json')));
94
+ } catch {
95
+ return null;
96
+ }
97
+ };
98
+ const app = reactOf(project.req.resolve);
99
+ let core = null;
100
+ try {
101
+ core = reactOf(
102
+ createRequire(project.req.resolve('@astryxdesign/core/package.json'))
103
+ .resolve,
104
+ );
105
+ } catch {
106
+ // No Core package file: nothing to compare.
107
+ }
108
+ return app && core && app !== core
109
+ ? `${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.`
110
+ : message;
50
111
  }
51
112
 
113
+ /**
114
+ * The "saved, not checked" report of a change, or null when it was checked.
115
+ * @param {string | null} cause
116
+ */
117
+ const notChecked = cause =>
118
+ cause ? {code: E.ERR_THEME_NOT_CHECKED, cause} : null;
119
+
52
120
  /**
53
121
  * Pictures of HTML files, on request.
54
122
  * @param {import('./_project.mjs').ThemeProject} project
@@ -85,10 +153,17 @@ export function fontNotes(ctx, data) {
85
153
  /** @type {string[]} */
86
154
  const notes = [];
87
155
  for (const {pkg, family, installed} of fontPackages(ctx, data)) {
156
+ const fallbacks =
157
+ Object.values(OPEN_FONTS).find(f => f.pkg === pkg)?.fallbacks ?? '';
158
+ const near = /monospace/.test(fallbacks)
159
+ ? 'mono'
160
+ : /serif/.test(fallbacks.replace('sans-serif', ''))
161
+ ? 'serif'
162
+ : 'system';
88
163
  notes.push(
89
164
  installed
90
165
  ? `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}';`,
166
+ : `${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
167
  );
93
168
  }
94
169
  for (const s of data.settings) {
@@ -177,24 +252,38 @@ export function styledChanges(before, after) {
177
252
  * @param {boolean} png
178
253
  */
179
254
  export async function previewAfter(ctx, slug, data, png) {
180
- const preview = await renderPreview(ctx, slug, data);
255
+ /** @type {string | null} */
256
+ let preview = null;
257
+ let cause = ctx.unchecked ?? null;
258
+ try {
259
+ preview = await renderPreview(ctx, slug, data);
260
+ } catch (e) {
261
+ if (!isRenderFailure(e)) throw e;
262
+ cause ??= renderCause(ctx.project, /** @type {Error} */ (e).message);
263
+ }
181
264
  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};
265
+ const shots =
266
+ png && preview
267
+ ? await pictures(
268
+ ctx.project,
269
+ [{html: f.preview, png: f.previewPng}],
270
+ modesOf(data),
271
+ )
272
+ : {files: [], problem: null};
273
+ return {
274
+ preview,
275
+ pictures: shots.files,
276
+ pictureProblem: shots.problem,
277
+ notChecked: notChecked(cause),
278
+ };
190
279
  }
191
280
 
192
- /** @param {string | undefined} group */
193
- export function checkGroup(group) {
194
- if (group != null && !SHOWCASE_GROUPS.includes(group))
281
+ /** @param {string | undefined} section a section of the sheet */
282
+ export function checkSection(section) {
283
+ if (section != null && !SHOWCASE_GROUPS.includes(section))
195
284
  refuse(
196
285
  E.ERR_INVALID_ARGUMENT,
197
- `--group takes ${SHOWCASE_GROUPS.join(', ')}, not "${group}".`,
198
- {didYouMean: nearest(group, SHOWCASE_GROUPS)},
286
+ `--section takes ${SHOWCASE_GROUPS.join(', ')}, not "${section}".`,
287
+ {didYouMean: nearest(section, SHOWCASE_GROUPS)},
199
288
  );
200
289
  }
@@ -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]