@astryxdesign/cli 0.7.16-canary.ge95b87c → 0.7.16

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 (120) hide show
  1. package/CHANGELOG.md +369 -0
  2. package/README.md +1 -1
  3. package/api/build/_adapter.d.mts +9 -0
  4. package/api/build/_adapter.mjs +24 -0
  5. package/api/build/kit/shell.weights.json +1 -0
  6. package/api/build/kit/shellcall.d.mts +26 -0
  7. package/api/build/kit/shellcall.mjs +87 -0
  8. package/api/build/kit/start.mjs +67 -4
  9. package/api/build/kit/weights.d.mts +15 -0
  10. package/api/build/kit/weights.mjs +27 -0
  11. package/api/component/__fixtures__/resolutions/modules.txt +1 -1
  12. package/api/doctor/_adapter.d.mts +3 -2
  13. package/api/doctor/_adapter.mjs +7 -1
  14. package/api/doctor/doctor.d.mts +8 -0
  15. package/api/doctor/doctor.mjs +53 -8
  16. package/api/doctor/theme-checks.mjs +157 -8
  17. package/api/icon/_adapter.d.mts +7 -3
  18. package/api/icon/_adapter.mjs +12 -3
  19. package/api/icon/icon.type.d.mts +15 -0
  20. package/api/icon/icon.type.mjs +10 -3
  21. package/api/icon/iconUse.doc.mjs +19 -5
  22. package/api/icon/list/list.mjs +7 -1
  23. package/api/icon/use/use.d.mts +8 -5
  24. package/api/icon/use/use.mjs +95 -13
  25. package/api/init/run/run.mjs +1 -0
  26. package/api/template/template.type.d.mts +6 -2
  27. package/api/template/template.type.mjs +2 -1
  28. package/api/theme/_adapter.mjs +16 -2
  29. package/api/theme/build/build.d.mts +10 -6
  30. package/api/theme/build/build.mjs +42 -29
  31. package/api/theme/generateTonalPalette.doc.mjs +2 -2
  32. package/api/theme/palette/generate/generator.mjs +141 -2
  33. package/api/theme/theme.type.d.mts +39 -0
  34. package/api/theme/theme.type.mjs +21 -0
  35. package/api/theme/themeBuild.doc.mjs +1 -1
  36. package/api/theme/themePaletteGenerate.doc.mjs +1 -1
  37. package/api/theme-edit/_adapter.d.mts +1 -0
  38. package/api/theme-edit/_adapter.mjs +79 -21
  39. package/api/theme-edit/_check.d.mts +25 -2
  40. package/api/theme-edit/_check.mjs +251 -61
  41. package/api/theme-edit/_context.d.mts +2 -1
  42. package/api/theme-edit/_context.mjs +19 -1
  43. package/api/theme-edit/_edit.d.mts +16 -0
  44. package/api/theme-edit/_edit.mjs +360 -59
  45. package/api/theme-edit/_how-question.d.mts +8 -0
  46. package/api/theme-edit/_how-question.mjs +169 -22
  47. package/api/theme-edit/_marks.d.mts +13 -0
  48. package/api/theme-edit/_marks.mjs +15 -0
  49. package/api/theme-edit/_palette.d.mts +27 -0
  50. package/api/theme-edit/_palette.mjs +112 -8
  51. package/api/theme-edit/_preview-app.d.mts +46 -1
  52. package/api/theme-edit/_preview-app.mjs +367 -36
  53. package/api/theme-edit/_preview.d.mts +55 -0
  54. package/api/theme-edit/_preview.mjs +231 -6
  55. package/api/theme-edit/_project.d.mts +4 -0
  56. package/api/theme-edit/_project.mjs +27 -6
  57. package/api/theme-edit/_settings.d.mts +61 -2
  58. package/api/theme-edit/_settings.mjs +317 -115
  59. package/api/theme-edit/_tables.mjs +1 -1
  60. package/api/theme-edit/theme-edit.type.d.mts +30 -2
  61. package/api/theme-edit/theme-edit.type.mjs +10 -2
  62. package/api/theme-edit/themeEditPreviewApp.doc.mjs +1 -1
  63. package/assets/docs/author-a-theme.doc.mjs +1 -1
  64. package/assets/docs/theme.doc.dense.mjs +1 -1
  65. package/assets/docs/theme.doc.mjs +1 -1
  66. package/assets/docs/theme.doc.zh.mjs +4 -3
  67. package/assets/docs/tree/define-the-theme.doc.mjs +1 -1
  68. package/assets/docs/tree/icon-sets.doc.mjs +63 -8
  69. package/assets/docs.generated.json +2 -2
  70. package/assets/self-audit.generated.json +1 -1
  71. package/assets/templates/blocks/components/Outline/useOutlineFromDOMHookUsage.doc.mjs +21 -0
  72. package/assets/templates/blocks/components/Outline/useOutlineFromDOMHookUsage.tsx +62 -0
  73. package/assets/templates/components.generated.json +1 -1
  74. package/assets/templates/pages/ai-chat/page.tsx +20 -2
  75. package/assets/templates/themes/neutral/neutralPalettes.generated.receipt.json +2 -0
  76. package/authoring/config/config.doc.mjs +8 -0
  77. package/authoring/config/parse.d.mts +1 -0
  78. package/authoring/config/parse.mjs +12 -0
  79. package/authoring/config/type.ts +8 -0
  80. package/authoring/doctypes/icon-set/icon-set-data.doc.mjs +3 -3
  81. package/clients/cli/build-id.generated.json +1 -1
  82. package/clients/cli/commands/experimental/icon.mjs +61 -6
  83. package/clients/cli/commands/experimental/theme.mjs +9 -2
  84. package/clients/cli/commands/experimental-icon-use.doc.mjs +12 -5
  85. package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +2 -2
  86. package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +1 -1
  87. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +2 -2
  88. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +1 -1
  89. package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
  90. package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
  91. package/clients/cli/commands/theme.doc.mjs +7 -2
  92. package/clients/cli/commands/theme.mjs +41 -18
  93. package/clients/cli/commands.generated.json +1 -1
  94. package/clients/cli/index.mjs +25 -5
  95. package/clients/cli/manifest.generated.json +1 -1
  96. package/foundation/agent-docs/agent-docs.mjs +1 -1
  97. package/foundation/config/config-writer.d.mts +23 -0
  98. package/foundation/config/config-writer.mjs +150 -56
  99. package/foundation/config/project.mjs +43 -2
  100. package/foundation/discovery/component-discovery.mjs +6 -5
  101. package/foundation/discovery/icon-set-checks.mjs +164 -48
  102. package/foundation/discovery/icon-set-discovery.d.mts +38 -5
  103. package/foundation/discovery/icon-set-discovery.mjs +50 -6
  104. package/foundation/discovery/icon-set-theme-maps.d.mts +59 -0
  105. package/foundation/discovery/icon-set-theme-maps.mjs +95 -0
  106. package/foundation/discovery/icon-set-writer.d.mts +2 -3
  107. package/foundation/discovery/icon-set-writer.mjs +57 -16
  108. package/foundation/discovery/template-icons.d.mts +27 -10
  109. package/foundation/discovery/template-icons.mjs +142 -26
  110. package/foundation/discovery/theme-discovery.d.mts +25 -0
  111. package/foundation/discovery/theme-discovery.mjs +48 -7
  112. package/foundation/fs/gather-cache.mjs +6 -2
  113. package/foundation/integrations/autolink.d.mts +4 -2
  114. package/foundation/integrations/autolink.mjs +4 -2
  115. package/foundation/integrations/cli-requirement.d.mts +16 -5
  116. package/foundation/integrations/cli-requirement.mjs +27 -6
  117. package/foundation/integrations/may-have-integrations.mjs +5 -2
  118. package/foundation/integrations/missing-dependency.d.mts +9 -0
  119. package/foundation/integrations/missing-dependency.mjs +100 -0
  120. package/package.json +6 -6
@@ -1,6 +1,14 @@
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
+ * An exact relative amount the words give ("half", "double", "twice",
6
+ * "triple", "a third", "a quarter", "50%", "x0.8"), as a factor of the
7
+ * theme's current value; null when the words give only a direction.
8
+ * @param {string} text
9
+ * @returns {number | null}
10
+ */
11
+ export function exactFactor(text: string): number | null;
4
12
  /**
5
13
  * The part or group a plain word names, as how reads it (`checkboxes` is
6
14
  * the checks group, `panels` the containers), or null.
@@ -553,6 +553,35 @@ function scaled(v, f) {
553
553
  return `${m[2] === 'px' ? Math.round(n) : Number(n.toFixed(3))}${m[2]}`;
554
554
  }
555
555
 
556
+ /**
557
+ * The part a clause measures against ("cards twice the padding of
558
+ * buttons": buttons), by clause.
559
+ * @type {WeakMap<object, string>}
560
+ */
561
+ const compared = new WeakMap();
562
+
563
+ /**
564
+ * An exact relative amount the words give ("half", "double", "twice",
565
+ * "triple", "a third", "a quarter", "50%", "x0.8"), as a factor of the
566
+ * theme's current value; null when the words give only a direction.
567
+ * @param {string} text
568
+ * @returns {number | null}
569
+ */
570
+ export function exactFactor(text) {
571
+ const t = text.toLowerCase();
572
+ if (/\b(half|halve|halved)\b/.test(t)) return 0.5;
573
+ if (/\b(double|doubled|twice)\b/.test(t)) return 2;
574
+ if (/\b(triple|tripled|three times)\b/.test(t)) return 3;
575
+ if (/\ba third\b/.test(t)) return 1 / 3;
576
+ if (/\ba quarter\b/.test(t)) return 0.25;
577
+ const pct = /\b(\d{1,3})\s?%\s*(?:strength|of|as)\b/.exec(t);
578
+ if (pct && Number(pct[1]) > 0) return Number(pct[1]) / 100;
579
+ const times = /\bx\s?(\d*\.?\d+)\b/.exec(t);
580
+ if (times && Number(times[1]) > 0 && Number(times[1]) <= 4)
581
+ return Number(times[1]);
582
+ return null;
583
+ }
584
+
556
585
  /**
557
586
  * @typedef {{on: string, when?: string, role?: string, level?: string}} PartRef
558
587
  */
@@ -1525,6 +1554,54 @@ export function draftAnswer(ctx, env, question) {
1525
1554
  '$2 $4 in $1 mode',
1526
1555
  )
1527
1556
  .replace(/^\s*(dark|light) mode only\s*:\s*/i, 'in $1 mode: ')
1557
+ // "cards with twice the padding of buttons": one comparison, not two
1558
+ // asks.
1559
+ .replace(
1560
+ /\bwith\s+(?=(?:twice|double|half|triple|three times)\s+(?:the\s+)?\w+\s+(?:of|than|as)\b)/gi,
1561
+ '',
1562
+ )
1563
+ // "just the headers bolder", "only the titles bigger": a scope, not a
1564
+ // break between asks.
1565
+ .replace(/(?<![-\w])(?:just|only)\s+(?=(?:the|my)\s+\w+\s+\w)/gi, '')
1566
+ // "headers bolder", "titles bigger": with a text word and no surface
1567
+ // word, the headings' type; with a surface word ("header background"),
1568
+ // the app header part.
1569
+ .replace(/\b(headers?|titles?)\b/gi, (m, _w, at, all) => {
1570
+ // The clause the word is in: from the last break before it (a comma,
1571
+ // semicolon, full stop or new line) to the next one after it.
1572
+ const head = String(all).slice(0, at);
1573
+ const from =
1574
+ Math.max(...[',', ';', '.', '\n'].map(b => head.lastIndexOf(b))) + 1;
1575
+ const clause = String(all)
1576
+ .slice(from)
1577
+ .split(/[,;.\n]/)[0];
1578
+ const text =
1579
+ /\b(bold(er)?|bigger|smaller|larger|font|weight|size|serif|sans|italic|heavier|lighter|thinner|uppercase|letter[- ]?spacing|tracking|line[- ]?height)\b/i.test(
1580
+ clause,
1581
+ );
1582
+ const surface =
1583
+ /\b(background|bg|bar|border|sticky|height|shadow|color of the bar|padding|fixed)\b/i.test(
1584
+ clause,
1585
+ );
1586
+ // "table header", "accordion header", "card title": that part's own.
1587
+ // A place ("not in the header") is the header part too.
1588
+ const before = String(all).slice(Math.max(0, at - 16), at);
1589
+ const owned =
1590
+ /\b(table|column|accordion|card|dialog|modal|page|section|app|site|product|top ?nav)\s+$/i.test(
1591
+ before,
1592
+ ) || /\b(in|on|inside|into|across|of)\s+(the\s+|my\s+)?$/i.test(before);
1593
+ return text && !surface && !owned
1594
+ ? /s$/i.test(m)
1595
+ ? 'headings'
1596
+ : 'heading'
1597
+ : m;
1598
+ })
1599
+ // "focus ring on inputs only, at half strength": an amount alone after a
1600
+ // comma belongs to the ask before it.
1601
+ .replace(
1602
+ /,\s*(?=(?:at|with|by|to)?\s*(?:about\s+)?(?:half|double|twice|triple|a third|a quarter|\d{1,3}\s?%)(?:\s+(?:the\s+)?(?:strength|width|size|thickness|weight|intensity|as (?:much|strong|thick|wide)))?\s*(?:[;.\n]|$))/gi,
1603
+ ' ',
1604
+ )
1528
1605
  // "I need: 1. accent red 2. pill badges": inline list numbers are breaks,
1529
1606
  // not values.
1530
1607
  .replace(/(?:^|\s)\d{1,2}[.)]\s+(?=[a-z#])/gi, m =>
@@ -3083,13 +3160,20 @@ export function draftAnswer(ctx, env, question) {
3083
3160
  );
3084
3161
  // "buttons twice as round as inputs": the part after "as" is only the
3085
3162
  // measure; the first part is the one that changes.
3086
- const asAs = /\bas \w+ as (?:the )?([a-z-]+)/.exec(c.text);
3163
+ const asAs =
3164
+ /\bas \w+ as (?:the )?([a-z-]+)/.exec(c.text) ??
3165
+ // "cards twice the padding of buttons": the same, by the measure.
3166
+ /\b(?:twice|double|half|triple|three times)\s+(?:the\s+)?\w+\s+(?:of|than|as)\s+(?:the\s+)?([a-z-]+)/.exec(
3167
+ c.text,
3168
+ );
3087
3169
  if (asAs && c.parts.length >= 2) {
3088
3170
  const after = (/** @type {{on: string}} */ p) =>
3089
3171
  lex.parts.some(
3090
3172
  ([re, x]) =>
3091
3173
  x.on === p.on && (re.exec(c.text)?.index ?? -1) > (asAs.index ?? 0),
3092
3174
  );
3175
+ const other = c.parts.find(p => after(p));
3176
+ if (other) compared.set(c, other.on);
3093
3177
  c.parts = c.parts.filter(p => !after(p));
3094
3178
  }
3095
3179
  // "focus ring the same color as the danger color": a role's token.
@@ -3716,13 +3800,19 @@ export function draftAnswer(ctx, env, question) {
3716
3800
  ]);
3717
3801
  if (on === 'focus-ring') {
3718
3802
  const ringColor = colorFor(c, 'fill');
3803
+ // "focus ring on inputs only": the ring's tokens set on that part or
3804
+ // group, so the other parts keep theirs.
3805
+ const scope =
3806
+ c.parts.map(x => x.on).find(x => x && x !== 'focus-ring') ?? null;
3807
+ const sc = scope ? {on: scope} : {};
3808
+ const scoped = scope ? ` on ${scope} only` : '';
3719
3809
  if (ringColor && c.lengths[0] && !c.neg)
3720
3810
  return {
3721
- text: "the focus ring's width and color: --focus-outline-width and --focus-outline-color",
3811
+ text: `the focus ring's width and color${scoped}: --focus-outline-width and --focus-outline-color`,
3722
3812
  options: [
3723
3813
  [
3724
- set('--focus-outline-width', c.lengths[0]),
3725
- set('--focus-outline-color', ringColor, modeOf(c)),
3814
+ set('--focus-outline-width', c.lengths[0], sc),
3815
+ set('--focus-outline-color', ringColor, {...modeOf(c), ...sc}),
3726
3816
  ],
3727
3817
  ],
3728
3818
  sequence: true,
@@ -3731,45 +3821,49 @@ export function draftAnswer(ctx, env, question) {
3731
3821
  // nothing only on the ask, and say what that costs.
3732
3822
  if (c.neg || /\b(remove|hide|get rid of)\b/.test(c.text))
3733
3823
  return {
3734
- text: 'no focus ring: --focus-outline-width 0px. Keyboard users then cannot see where they are, so keep a visible focus style another way',
3735
- options: [[set('--focus-outline-width', '0px')]],
3824
+ text: `no focus ring${scoped}: --focus-outline-width 0px. Keyboard users then cannot see where they are, so keep a visible focus style another way`,
3825
+ options: [[set('--focus-outline-width', '0px', sc)]],
3736
3826
  };
3737
3827
  // "focus ring offset 2px": the gap between the part and its ring.
3738
3828
  if (/\boffset\b/.test(c.text))
3739
3829
  return c.lengths[0]
3740
3830
  ? {
3741
- text: "the focus ring's offset: --focus-outline-offset",
3742
- options: [[set('--focus-outline-offset', c.lengths[0])]],
3831
+ text: `the focus ring's offset${scoped}: --focus-outline-offset`,
3832
+ options: [[set('--focus-outline-offset', c.lengths[0], sc)]],
3743
3833
  }
3744
3834
  : null;
3745
3835
  if (
3746
3836
  (a === 'border' && !ringColor) ||
3747
3837
  a === 'size' ||
3748
3838
  a === 'spacing' ||
3749
- /\b(thick|thin|width)/.test(c.text)
3839
+ /\b(thick|thin|width|strength|stronger|weaker|bolder|subtler)/.test(
3840
+ c.text,
3841
+ )
3750
3842
  ) {
3751
- const w =
3752
- c.lengths[0] ??
3753
- scaled(
3754
- current('--focus-outline-width'),
3755
- c.dir === 'less' ? 0.5 : 1.5,
3756
- ) ??
3757
- '3px';
3843
+ // From the theme's own width there (on the part when it sets one).
3844
+ const own = scope ? partValue(scope, '--focus-outline-width') : null;
3845
+ const now = own ?? current('--focus-outline-width');
3846
+ const exact = exactFactor(c.text);
3847
+ const factor = exact ?? (c.dir === 'less' ? 0.5 : 1.5);
3848
+ const w = c.lengths[0] ?? scaled(now, factor);
3849
+ const strength = /\bstrength\b/.test(c.text) && !c.lengths[0];
3758
3850
  return {
3759
- text: `the focus ring's width${where}: --focus-outline-width`,
3760
- options: [[set('--focus-outline-width', w)]],
3851
+ text: `the focus ring's width${scoped || where}: --focus-outline-width ${w ?? ''}${!c.lengths[0] && now ? ` (now ${now})` : ''}${strength ? '; "strength" read as the width of the ring' : ''}${!c.lengths[0] && !exact && !c.dir ? '; no amount was given, so this is a guess: give a width (2px)' : ''}`,
3852
+ options: w ? [[set('--focus-outline-width', w, sc)]] : [],
3761
3853
  };
3762
3854
  }
3763
3855
  const color = colorFor(c, 'fill');
3764
3856
  if (c.neg)
3765
3857
  return {
3766
- text: 'the focus ring shows keyboard users where they are; it can be made subtle but not removed',
3767
- options: [[set('--focus-outline-width', '1px')]],
3858
+ text: `the focus ring shows keyboard users where they are; it can be made subtle but not removed${scoped}`,
3859
+ options: [[set('--focus-outline-width', '1px', sc)]],
3768
3860
  };
3769
3861
  return color
3770
3862
  ? {
3771
- text: `the focus ring's color: --focus-outline-color`,
3772
- options: [[set('--focus-outline-color', color, modeOf(c))]],
3863
+ text: `the focus ring's color${scoped}: --focus-outline-color`,
3864
+ options: [
3865
+ [set('--focus-outline-color', color, {...modeOf(c), ...sc})],
3866
+ ],
3773
3867
  }
3774
3868
  : null;
3775
3869
  }
@@ -4039,6 +4133,29 @@ export function draftAnswer(ctx, env, question) {
4039
4133
  // A radius of 0 is square.
4040
4134
  const px = typedPx && parseFloat(typedPx) === 0 ? null : typedPx;
4041
4135
  const zero = Boolean(typedPx) && !px;
4136
+ // "half the corner radius on buttons": an exact amount of the
4137
+ // radius the part has now (its own setting, else the token it reads).
4138
+ // Not a comparison with another part ("twice as round as inputs"):
4139
+ // that amount is of the other part's radius.
4140
+ const cornerFactor =
4141
+ !typedPx &&
4142
+ on &&
4143
+ !/\b(as|than)\s+(the\s+)?\w+\s*$|\bas \w+ as\b/.test(c.text)
4144
+ ? exactFactor(c.text)
4145
+ : null;
4146
+ if (cornerFactor) {
4147
+ const part = /** @type {string} */ (on);
4148
+ const read = C.partReads(one(part), 'corners')[0];
4149
+ const now =
4150
+ partValue(part, 'border-radius') ??
4151
+ (read?.token ? current(read.token) : null);
4152
+ const value = now ? scaled(now, cornerFactor) : null;
4153
+ if (value)
4154
+ return {
4155
+ text: `corners${where}: border-radius ${value} (now ${now})`,
4156
+ options: [[set('border-radius', value, f)]],
4157
+ };
4158
+ }
4042
4159
  // "revert the rounded corners": take back what the theme sets.
4043
4160
  if (/\b(revert|undo|take back)\b/.test(c.text)) {
4044
4161
  const back = existing(['corners', 'border-radius'], on);
@@ -4355,6 +4472,36 @@ export function draftAnswer(ctx, env, question) {
4355
4472
  options: [[set(gap ? 'gap' : 'padding', box, f)]],
4356
4473
  };
4357
4474
  }
4475
+ // "double the padding on cards": an exact amount of the padding the
4476
+ // part has now, when the theme sets one; else the dial's step, and
4477
+ // the answer says the amount is a step.
4478
+ const padFactor = exactFactor(c.text);
4479
+ // A comparison ("twice the padding of buttons"): the amount is of
4480
+ // the other part's padding, when the theme sets one; else a step,
4481
+ // and the answer says so.
4482
+ const versus = compared.get(c) ?? null;
4483
+ if (padFactor && versus) {
4484
+ const now = partValue(versus, gap ? 'gap' : 'padding');
4485
+ const exact = now ? scaled(now, padFactor) : null;
4486
+ return exact
4487
+ ? {
4488
+ text: `${gap ? 'the gap' : 'padding'}${where}: ${exact} (${versus} has ${now})`,
4489
+ options: [[set(gap ? 'gap' : 'padding', exact, f)]],
4490
+ }
4491
+ : {
4492
+ text: `room inside ${on}: spacing ${value ?? 'more'}; this theme sets no ${gap ? 'gap' : 'padding'} of its own on ${versus}, so this is a step, not an exact amount of ${versus}'s: give a value (24px) for one`,
4493
+ options: [[set('spacing', value ?? 'more', f)]],
4494
+ };
4495
+ }
4496
+ if (padFactor) {
4497
+ const now = partValue(on, gap ? 'gap' : 'padding');
4498
+ const value = now ? scaled(now, padFactor) : null;
4499
+ if (value)
4500
+ return {
4501
+ text: `${gap ? 'the gap' : 'padding'}${where}: ${value} (now ${now})`,
4502
+ options: [[set(gap ? 'gap' : 'padding', value, f)]],
4503
+ };
4504
+ }
4358
4505
  if (!value)
4359
4506
  return {
4360
4507
  text: `no padding${where}`,
@@ -0,0 +1,13 @@
1
+ // @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
2
+ // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
+
4
+ /**
5
+ * @file The markers the theme editor writes at the top of the files it
6
+ * generates, in one place for the editor and for doctor.
7
+ *
8
+ * @position api/theme-edit — internal
9
+ */
10
+ /** The first words of a generated settings module the editor writes. */
11
+ export const EDITOR_GENERATED_MARK: "Generated by `astryx experimental theme editor`";
12
+ /** The words on every file of a theme's app copy (src/themes/<theme>/). */
13
+ export const APP_COPY_MARK: "Written by `astryx experimental theme editor`";
@@ -0,0 +1,15 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file The markers the theme editor writes at the top of the files it
5
+ * generates, in one place for the editor and for doctor.
6
+ *
7
+ * @position api/theme-edit — internal
8
+ */
9
+
10
+ /** The first words of a generated settings module the editor writes. */
11
+ export const EDITOR_GENERATED_MARK =
12
+ 'Generated by `astryx experimental theme editor`';
13
+
14
+ /** The words on every file of a theme's app copy (src/themes/<theme>/). */
15
+ export const APP_COPY_MARK = 'Written by `astryx experimental theme editor`';
@@ -101,6 +101,33 @@ export function syncPalette(cwd: string, slug: string, data: {
101
101
  light: Record<string, string>;
102
102
  dark: Record<string, string>;
103
103
  }): string[];
104
+ /**
105
+ * The record of the files the editor wrote into a theme folder,
106
+ * `themes/<theme>/<theme>.pictures.json`: each by name, with the hash of
107
+ * what was written (its pictures and its color config). The one reader and
108
+ * writer of that record.
109
+ * @param {string} cwd
110
+ * @param {string} slug
111
+ * @returns {Record<string, string>}
112
+ */
113
+ export function readWrittenRecord(cwd: string, slug: string): Record<string, string>;
114
+ /**
115
+ * Write the record whole, or remove it when it names nothing. A record that
116
+ * cannot be written leaves nothing removed later: the safe way round.
117
+ * @param {string} cwd
118
+ * @param {string} slug
119
+ * @param {Record<string, string>} map
120
+ */
121
+ export function writeWrittenRecord(cwd: string, slug: string, map: Record<string, string>): void;
122
+ /**
123
+ * Note a file the editor wrote into a theme folder, by name with the hash
124
+ * of what it wrote, or forget it (null).
125
+ * @param {string} cwd
126
+ * @param {string} slug
127
+ * @param {string} name
128
+ * @param {string | null} hash
129
+ */
130
+ export function noteWritten(cwd: string, slug: string, name: string, hash: string | null): void;
104
131
  /**
105
132
  * Whether a theme's palette file was edited by hand. Its bytes match its
106
133
  * receipt, or its colors (read as data, so formatting, a BOM or semicolons
@@ -650,8 +650,7 @@ const strategyOf = modes =>
650
650
  modes.length > 1 ? 'light-and-dark' : `${modes[0]}-only`;
651
651
 
652
652
  /**
653
- * The fields of a config the generator never reads (such as
654
- * `darkChromaTaper`), by path.
653
+ * The fields of a config the generator never reads, by path.
655
654
  * @param {any} config
656
655
  * @returns {string[]}
657
656
  */
@@ -1043,7 +1042,10 @@ function planPalette(cwd, slug, data, base) {
1043
1042
  ? {...existing}
1044
1043
  : {};
1045
1044
  const {settings: saved, mode: savedMode} = savedSettings(cwd, slug);
1046
- const modes = modesOf(data);
1045
+ // Every theme's palette has both modes: a one-mode theme keeps both
1046
+ // halves of its colors (its mode is the one the app's <Theme> is given),
1047
+ // and a region Core draws in the other mode reads the other half.
1048
+ const modes = modesForStrategy('light-and-dark');
1047
1049
 
1048
1050
  const vibrancy = dialVibrancy(data.settings);
1049
1051
  const savedVibrancy = dialVibrancy(saved);
@@ -1372,7 +1374,12 @@ function syncPaletteFiles(cwd, slug, data, base) {
1372
1374
  const hash = fs.existsSync(abs(f.config))
1373
1375
  ? sha256(fs.readFileSync(abs(f.config)))
1374
1376
  : null;
1375
- const mine = hash != null && (data.palette === hash || saved === hash);
1377
+ // Or the config the editor recorded writing (a color change stopped
1378
+ // before its settings were saved).
1379
+ const recorded = readWrittenRecord(cwd, slug)['palette.config.json'];
1380
+ const mine =
1381
+ hash != null &&
1382
+ (data.palette === hash || saved === hash || recorded === hash);
1376
1383
  delete data.palette;
1377
1384
  if (!mine) return [];
1378
1385
  // A palette file edited by hand is never deleted: it stays, and the
@@ -1385,6 +1392,7 @@ function syncPaletteFiles(cwd, slug, data, base) {
1385
1392
  const notes = [];
1386
1393
  for (const p of [f.config, f.receipt, f.refs])
1387
1394
  fs.rmSync(abs(p), {force: true});
1395
+ noteWritten(cwd, slug, 'palette.config.json', null);
1388
1396
  if (editedPalette)
1389
1397
  notes.push(
1390
1398
  `${f.palette} was edited by hand, so it stays: the theme no longer reads it. Move it out of tokens/ to keep it as your own, or delete it`,
@@ -1433,12 +1441,75 @@ function syncPaletteFiles(cwd, slug, data, base) {
1433
1441
  );
1434
1442
  }
1435
1443
  fs.mkdirSync(path.dirname(abs(f.config)), {recursive: true});
1444
+ // Recorded before it is written: a run stopped after this leaves a config
1445
+ // the next build knows is the editor's.
1446
+ noteWritten(cwd, slug, 'palette.config.json', sha256(Buffer.from(text)));
1436
1447
  writeWhole(abs(f.config), text);
1437
1448
  data.palette = sha256(Buffer.from(text));
1438
1449
  themePaletteGenerate(f.config, {out: f.palette, overwrite: true}, {cwd});
1439
1450
  return plan.notes;
1440
1451
  }
1441
1452
 
1453
+ /**
1454
+ * The record of the files the editor wrote into a theme folder,
1455
+ * `themes/<theme>/<theme>.pictures.json`: each by name, with the hash of
1456
+ * what was written (its pictures and its color config). The one reader and
1457
+ * writer of that record.
1458
+ * @param {string} cwd
1459
+ * @param {string} slug
1460
+ * @returns {Record<string, string>}
1461
+ */
1462
+ export function readWrittenRecord(cwd, slug) {
1463
+ try {
1464
+ const json = JSON.parse(
1465
+ fs.readFileSync(writtenRecordFile(cwd, slug), 'utf8'),
1466
+ );
1467
+ return json && typeof json === 'object' && !Array.isArray(json) ? json : {};
1468
+ } catch {
1469
+ return {};
1470
+ }
1471
+ }
1472
+
1473
+ /** @param {string} cwd @param {string} slug */
1474
+ const writtenRecordFile = (cwd, slug) =>
1475
+ path.join(cwd, 'themes', slug, `${slug}.pictures.json`);
1476
+
1477
+ /**
1478
+ * Write the record whole, or remove it when it names nothing. A record that
1479
+ * cannot be written leaves nothing removed later: the safe way round.
1480
+ * @param {string} cwd
1481
+ * @param {string} slug
1482
+ * @param {Record<string, string>} map
1483
+ */
1484
+ export function writeWrittenRecord(cwd, slug, map) {
1485
+ const file = writtenRecordFile(cwd, slug);
1486
+ try {
1487
+ if (!Object.keys(map).length) fs.rmSync(file, {force: true});
1488
+ else {
1489
+ fs.mkdirSync(path.dirname(file), {recursive: true});
1490
+ writeWhole(file, `${JSON.stringify(map, null, 2)}\n`);
1491
+ }
1492
+ } catch {
1493
+ // Without the record, nothing it names is removed later.
1494
+ }
1495
+ }
1496
+
1497
+ /**
1498
+ * Note a file the editor wrote into a theme folder, by name with the hash
1499
+ * of what it wrote, or forget it (null).
1500
+ * @param {string} cwd
1501
+ * @param {string} slug
1502
+ * @param {string} name
1503
+ * @param {string | null} hash
1504
+ */
1505
+ export function noteWritten(cwd, slug, name, hash) {
1506
+ const map = readWrittenRecord(cwd, slug);
1507
+ if (hash) map[name] = hash;
1508
+ else if (name in map) delete map[name];
1509
+ else return;
1510
+ writeWrittenRecord(cwd, slug, map);
1511
+ }
1512
+
1442
1513
  /**
1443
1514
  * The value of the object literal that starts at the first `{` from
1444
1515
  * `from`, read as data: string and numeric keys, string values, nested
@@ -1832,7 +1903,8 @@ export function paletteMapping(cwd, slug, data, base, tokenDefaults) {
1832
1903
  const candidate = generate(config, paletteFiles(slug).config);
1833
1904
  const t = tools(candidate, data, base, ownSourceTokenValues(cwd, slug));
1834
1905
  const {stops, at, ref, exactOf, rawOf, settingOf, side, solid, surfaces} = t;
1835
- const modes = modesOf(data);
1906
+ // Both halves, for a one-mode theme too (see planPalette).
1907
+ const modes = modesForStrategy('light-and-dark');
1836
1908
  /** @type {PaletteMapping['tokens']} */
1837
1909
  const tokens = {};
1838
1910
  /** @type {ContrastCheck[]} */
@@ -2261,6 +2333,37 @@ export function paletteMapping(cwd, slug, data, base, tokenDefaults) {
2261
2333
  const found = {};
2262
2334
  for (const ground of new Set(LIFT_PARTS.map(([, , g]) => g))) {
2263
2335
  const {what, parts} = LIFT_GROUNDS[ground];
2336
+ /**
2337
+ * The shade the base theme itself lifts this ground's text to in a
2338
+ * mode, when it gives one: the search starts there, so a change of
2339
+ * color moves it only when that shade no longer reads.
2340
+ * @param {Mode} m
2341
+ * @returns {string | null}
2342
+ */
2343
+ const baseLift = m => {
2344
+ for (const [part, block, g] of LIFT_PARTS) {
2345
+ if (g !== ground) continue;
2346
+ const v = /** @type {any} */ (base)?.components?.[part]?.[block]?.[
2347
+ '--color-text-secondary'
2348
+ ];
2349
+ const pair = Array.isArray(v)
2350
+ ? v
2351
+ : typeof v === 'string'
2352
+ ? /^light-dark\((.*)\)$/s.exec(v.trim())?.[1]
2353
+ ? splitTop(
2354
+ /** @type {string} */ (
2355
+ /^light-dark\((.*)\)$/s.exec(v.trim())?.[1]
2356
+ ),
2357
+ ',',
2358
+ )
2359
+ : [v, v]
2360
+ : null;
2361
+ const c = pair?.[m === 'light' ? 0 : 1]?.trim();
2362
+ if (c && parseColor(c))
2363
+ return hex(/** @type {number[]} */ (parseColor(c)));
2364
+ }
2365
+ return null;
2366
+ };
2264
2367
  /** @type {Partial<Record<Mode, StopRef>>} */
2265
2368
  const byMode = {};
2266
2369
  for (const m of modes) {
@@ -2290,8 +2393,9 @@ export function paletteMapping(cwd, slug, data, base, tokenDefaults) {
2290
2393
  const keys = Object.keys(g.ramp)
2291
2394
  .map(Number)
2292
2395
  .sort((a, b) => a - b);
2396
+ const from = baseLift(m) ?? text;
2293
2397
  const start = keys.reduce((x, y) =>
2294
- perceptualDelta(g.ramp[y], text) < perceptualDelta(g.ramp[x], text)
2398
+ perceptualDelta(g.ramp[y], from) < perceptualDelta(g.ramp[x], from)
2295
2399
  ? y
2296
2400
  : x,
2297
2401
  );
@@ -2312,7 +2416,7 @@ export function paletteMapping(cwd, slug, data, base, tokenDefaults) {
2312
2416
  ? ref('neutral', m, b.stop)
2313
2417
  : {stop: b.stop, color: g.ramp[b.stop], family: 'literal'};
2314
2418
  const moved =
2315
- hex(/** @type {number[]} */ (parseColor(g.ramp[b.stop]))) !== text;
2419
+ hex(/** @type {number[]} */ (parseColor(g.ramp[b.stop]))) !== from;
2316
2420
  if (b.r < TEXT || moved)
2317
2421
  checks.push({
2318
2422
  token: '--color-text-secondary',
@@ -2326,7 +2430,7 @@ export function paletteMapping(cwd, slug, data, base, tokenDefaults) {
2326
2430
  dials: ['accent', 'neutral'],
2327
2431
  note:
2328
2432
  b.r >= TEXT
2329
- ? `--color-text-secondary on ${parts} uses ${g.ramp[b.stop]} in ${m}, not ${text}, so it reads at ${round(b.r)}:1 on ${what} and under a hover, as the official theme lifts it`
2433
+ ? `--color-text-secondary on ${parts} uses ${g.ramp[b.stop]} in ${m}, not ${from}, so it stays readable (${round(b.r)}:1) on ${what} and under a hover`
2330
2434
  : `--color-text-secondary on ${parts} reads at only ${round(b.r)}:1 in ${m} on ${what} even at ${g.ramp[b.stop]}, the most contrasting gray (needs ${TEXT}:1): pick another accent or neutral, or set --color-text-secondary on those parts exactly`,
2331
2435
  });
2332
2436
  }
@@ -1,6 +1,31 @@
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
+ * The steps that put an editor theme into the app through its app copy
6
+ * (src/themes/<theme>/): one `theme add`, which prints the one-time wiring
7
+ * of the app's theme module, and what keeps the copy in step. The one text
8
+ * every place that says how to use an editor theme gives.
9
+ * @param {string} cwd
10
+ * @param {string} slug
11
+ * @param {'light' | 'dark' | 'system'} [mode]
12
+ * @returns {string[]}
13
+ */
14
+ export function addWiring(cwd: string, slug: string, mode?: "light" | "dark" | "system"): string[];
15
+ /**
16
+ * How to use an editor theme in this app: `theme add <theme>` for the app
17
+ * copy the editor writes in src/themes/<theme>/; when a folder of the
18
+ * user's is there instead, step by step by hand: the file of the app's root
19
+ * (a Next app's root layout, else the file that renders the app), the
20
+ * imports the preview route uses for the same theme (its module, its
21
+ * stylesheet and the font stylesheets) and the Theme around the app. Then
22
+ * what builds it.
23
+ * @param {import('./_settings.mjs').Ctx} ctx
24
+ * @param {string} slug
25
+ * @param {import('./_settings.mjs').ThemeData} data
26
+ * @returns {string[]}
27
+ */
28
+ export function appWiring(ctx: import("./_settings.mjs").Ctx, slug: string, data: import("./_settings.mjs").ThemeData): string[];
4
29
  /**
5
30
  * For tests: stop the next preview changes at the step where `when`
6
31
  * returns true, as a kill would, with nothing put back. Null clears it.
@@ -30,6 +55,25 @@ export function refreshPreviewRoute(cwd: string, slug: string): Promise<{
30
55
  changed: boolean;
31
56
  stale: string[];
32
57
  }>;
58
+ /**
59
+ * One line that says how to see a theme after a change. First a look that
60
+ * changes nothing in the app: the editor's own preview.html (current after
61
+ * the change) and --png, which takes pictures with no dev server; then the
62
+ * in-app preview page most about what changed (Colors after a color,
63
+ * Components after a part, else Overview) at its own URL when there is a
64
+ * preview; adding one to the app last, as an option. A change that could
65
+ * not be rendered names why instead of the editor's page.
66
+ * @param {string} cwd
67
+ * @param {string} slug
68
+ * @param {'colors' | 'components' | 'overview'} focus
69
+ * @param {{code: string, cause: string} | null} [notChecked] why the change
70
+ * could not be rendered
71
+ * @returns {string}
72
+ */
73
+ export function seeLine(cwd: string, slug: string, focus: "colors" | "components" | "overview", notChecked?: {
74
+ code: string;
75
+ cause: string;
76
+ } | null): string;
33
77
  /**
34
78
  * Add pages to the in-app theme preview, and write the preview route the
35
79
  * first time. With a description, the build ranking picks the template
@@ -46,7 +90,8 @@ export function refreshPreviewRoute(cwd: string, slug: string): Promise<{
46
90
  export function themeEditPreviewAdd(description?: string, options?: import("./theme-edit.type.mjs").ThemeEditPreviewAddOptions): Promise<import("./theme-edit.type.mjs").ThemeEditPreviewAddResponse>;
47
91
  /**
48
92
  * Make a new starter app (Next.js app router, Core and the neutral theme,
49
- * with the Astryx packages pinned to this CLI's release) in `dir`, with the
93
+ * with the Astryx packages pinned to this CLI's release, or with `theme` to
94
+ * the versions the project has) in `dir`, with the
50
95
  * theme preview route and its default pages inside. With `theme`, the theme
51
96
  * folder is copied into the app and the pages wear it. No install runs.
52
97
  * Every check runs before the first write, so a refusal changes nothing.