@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
@@ -77,12 +77,21 @@ import {
77
77
  PHONE_TYPE,
78
78
  refreshSourceStamp,
79
79
  sourceChangedReason,
80
+ builtPairs,
81
+ ownPairMessage,
80
82
  freeThemeName,
81
83
  refuseLinks,
82
84
  usableNewName,
85
+ FOLDER_JUNK,
83
86
  dialValueFits,
87
+ holdAfterBuild,
84
88
  } from './_settings.mjs';
85
- import {checkSetting, exampleOf, storedProblems} from './_check.mjs';
89
+ import {
90
+ checkSetting,
91
+ exampleOf,
92
+ normalizeEntry,
93
+ storedProblems,
94
+ } from './_check.mjs';
86
95
  import {MODAL} from './_compiler.mjs';
87
96
  import {
88
97
  PALETTE_DIALS,
@@ -97,8 +106,14 @@ import {
97
106
  isGraySeed,
98
107
  seedOf,
99
108
  } from './_palette.mjs';
100
- import {renderPreview, renderSheet} from './_preview.mjs';
101
- import {refreshPreviewRoute} from './_preview-app.mjs';
109
+ import {
110
+ renderPreview,
111
+ renderSheet,
112
+ previewIsCurrent,
113
+ takeFirstAppCopy,
114
+ writeAppCopy,
115
+ } from './_preview.mjs';
116
+ import {appWiring, refreshPreviewRoute, seeLine} from './_preview-app.mjs';
102
117
  import {baseInstalled, baseResolved, installLine} from './_project.mjs';
103
118
  import {reactMissing} from './_parts.mjs';
104
119
  import {
@@ -125,9 +140,6 @@ const E = ERROR_CODES;
125
140
  */
126
141
  /** The marker a `new` writes first and removes last. */
127
142
 
128
- /** Files a system or a tool puts in any folder; a folder of only these is empty. */
129
- const FOLDER_JUNK = new Set(['.DS_Store', '.gitkeep', 'Thumbs.db']);
130
-
131
143
  /**
132
144
  * A folder the editor made but that has no settings: a stopped `new` left
133
145
  * its marker, or the settings were removed beside the editor's generated
@@ -592,6 +604,8 @@ export async function themeEditNew(name, options = {}) {
592
604
  notes,
593
605
  problems: r.problems,
594
606
  ...p,
607
+ // How to use the theme in this app: theme add <theme> for its app copy.
608
+ wiring: appWiring(ctx, name, data),
595
609
  },
596
610
  };
597
611
  }
@@ -791,6 +805,23 @@ function unquoteWord(word) {
791
805
  return m ? m[1].replace(/'\\''/g, "'") : word;
792
806
  }
793
807
 
808
+ /**
809
+ * The preview page most about a change: Colors for a color (a color dial
810
+ * or a color token), Components for a part setting, else Overview.
811
+ * @param {{thing: string, on?: string | null}} s
812
+ * @returns {'colors' | 'components' | 'overview'}
813
+ */
814
+ function changeFocus(s) {
815
+ if (s.on) return 'components';
816
+ if (
817
+ PALETTE_DIALS.includes(s.thing) ||
818
+ s.thing === 'vibrancy' ||
819
+ /^--color-/.test(s.thing)
820
+ )
821
+ return 'colors';
822
+ return 'overview';
823
+ }
824
+
794
825
  /**
795
826
  * The preview after a change, with the in-app preview route kept in step:
796
827
  * its imports follow the theme, such as the stylesheet of a font package
@@ -799,10 +830,32 @@ function unquoteWord(word) {
799
830
  * @param {string} slug
800
831
  * @param {import('./_settings.mjs').ThemeData} data
801
832
  * @param {boolean} png
833
+ * @param {'colors' | 'components' | 'overview'} [focus] the preview page
834
+ * most about the change: Colors for a color, Components for a part
802
835
  */
803
- async function previewAndRoute(ctx, slug, data, png) {
836
+ async function previewAndRoute(ctx, slug, data, png, focus = 'overview') {
804
837
  const p = await previewAfter(ctx, slug, data, png);
805
- return {...p, previewStale: await keepPreviewRoute(ctx, slug)};
838
+ const wrote = takeFirstAppCopy(ctx.project.cwd, slug);
839
+ return {
840
+ ...p,
841
+ previewStale: await keepPreviewRoute(ctx, slug),
842
+ // How to see the change: the page about it, at its own URL.
843
+ // A page not written this time (preview null) still shows the theme
844
+ // as it was; checks that failed with the page written do not.
845
+ see: seeLine(
846
+ ctx.project.cwd,
847
+ slug,
848
+ focus,
849
+ p.preview == null
850
+ ? (p.notChecked ?? {
851
+ code: 'ERR_THEME_NOT_CHECKED',
852
+ cause: 'no preview was rendered',
853
+ })
854
+ : null,
855
+ ),
856
+ // The first time the theme's app copy is written, its files are named.
857
+ ...(wrote ? {appCopy: {wrote}} : {}),
858
+ };
806
859
  }
807
860
 
808
861
  /**
@@ -847,7 +900,31 @@ export async function themeEditSet(theme, thing, value, options = {}) {
847
900
  function refuseStoredTokens(ctx, slug, data, skip) {
848
901
  const bad = storedProblems(ctx, slug, data, skip);
849
902
  if (!bad.length) return;
850
- const one = bad.length === 1 ? bad[0] : null;
903
+ const found = bad.length === 1 ? bad[0] : null;
904
+ // A clean value is offered only when set takes it, so the line works.
905
+ const takes = (/** @type {typeof found} */ b) => {
906
+ if (!b?.fix) return true;
907
+ try {
908
+ checkSetting(
909
+ ctx,
910
+ slug,
911
+ {...data, settings: data.settings.filter(x => x !== b.setting)},
912
+ b.setting.thing,
913
+ b.fix,
914
+ {
915
+ on: b.setting.on,
916
+ when: b.setting.when,
917
+ state: b.setting.state,
918
+ mode: b.setting.mode,
919
+ },
920
+ false,
921
+ );
922
+ return true;
923
+ } catch {
924
+ return false;
925
+ }
926
+ };
927
+ const one = found && takes(found) ? found : null;
851
928
  refuse(
852
929
  E.ERR_THEME_INVALID,
853
930
  `themes/${slug}/${slug}.settings.json: ${bad
@@ -868,14 +945,61 @@ function refuseStoredTokens(ctx, slug, data, skip) {
868
945
  one.setting.source === 'token' &&
869
946
  ctx.C.isToken(one.setting.thing)
870
947
  ? [
871
- `${P} set ${slug} ${one.setting.thing} ${quoteCommandArgument(exampleOf(ctx.C.typeOf(one.setting.thing), one.setting.thing))}`,
948
+ // The value the check suggests for this value, else a stock
949
+ // one of the token's type.
950
+ `${P} set ${slug} ${one.setting.thing} ${quoteCommandArgument(one.fix ?? exampleOf(ctx.C.typeOf(one.setting.thing), one.setting.thing))}`,
872
951
  ]
873
- : []),
952
+ : one && one.fix && one.setting.source === 'dial'
953
+ ? [
954
+ `${P} set ${slug} ${one.setting.thing} ${quoteCommandArgument(one.fix)}`,
955
+ ]
956
+ : []),
874
957
  ],
875
958
  },
876
959
  );
877
960
  }
878
961
 
962
+ /**
963
+ * For `compile`: the refusal `show` gives for saved settings the editor no
964
+ * longer accepts (naming the undo that removes each), or null.
965
+ * @param {string} root
966
+ * @param {string} slug
967
+ * @returns {Promise<import('../error.mjs').AstryxError | null>}
968
+ */
969
+ export async function editorStoredRefusal(root, slug) {
970
+ try {
971
+ const ctx = await context(root);
972
+ refuseStoredTokens(ctx, slug, loadTheme(root, slug));
973
+ return null;
974
+ } catch (e) {
975
+ if (e instanceof AstryxError) return e;
976
+ throw e;
977
+ }
978
+ }
979
+
980
+ /**
981
+ * For `compile`: the refusal of [light, dark] pairs on tokens that are not
982
+ * colors in what the theme builds now, or null.
983
+ * @param {string} root
984
+ * @param {string} slug
985
+ * @returns {Promise<import('../error.mjs').AstryxError | null>}
986
+ */
987
+ export async function editorPairRefusal(root, slug) {
988
+ const ctx = await context(root);
989
+ const names = await builtPairs(ctx, slug);
990
+ if (!names.length) return null;
991
+ return new AstryxError(
992
+ ownPairMessage(slug, names),
993
+ [
994
+ {
995
+ name: `grep -n -- ${quoteCommandArgument(names[0])} ${quoteCommandArgument(`themes/${slug}/${slug}.theme.ts`)}`,
996
+ reason: 'see where the file sets it',
997
+ },
998
+ ],
999
+ ERROR_CODES.ERR_THEME_INVALID,
1000
+ );
1001
+ }
1002
+
879
1003
  /**
880
1004
  * A note for type scale steps that land outside 9 to 200 pixels.
881
1005
  * @param {Record<string, string>} res resolved light tokens
@@ -906,10 +1030,20 @@ function extremeSteps(res) {
906
1030
  * @returns {Promise<import('./theme-edit.type.mjs').ThemeEditChangeResponse>}
907
1031
  */
908
1032
  async function change(sub, slug, thing, value, options) {
1033
+ // As typed: an undo of a saved entry written in a form the cleanup below
1034
+ // repairs (`Corners`, `var(--radius-page)`) removes that exact entry.
1035
+ const typedThing = thing;
1036
+ // How it was typed, put right before anything reads it (a pasted
1037
+ // declaration, a dash, a var(), invisible spaces).
1038
+ if (typeof thing === 'string') {
1039
+ const entry = normalizeEntry(thing, value);
1040
+ thing = entry.thing;
1041
+ value = entry.value;
1042
+ }
909
1043
  /** @type {{ctx?: import('./_settings.mjs').Ctx, data?: import('./_settings.mjs').ThemeData}} */
910
1044
  const seen = {};
911
1045
  try {
912
- return await changeOnce(sub, slug, thing, value, options, seen);
1046
+ return await changeOnce(sub, slug, thing, value, options, seen, typedThing);
913
1047
  } catch (e) {
914
1048
  // A theme name one letter off an existing theme: the same command with
915
1049
  // that name comes first, before making a theme of the typo.
@@ -953,13 +1087,22 @@ async function change(sub, slug, thing, value, options) {
953
1087
  * the context and the theme as loaded, for checking a refusal's suggestions
954
1088
  * @returns {Promise<import('./theme-edit.type.mjs').ThemeEditChangeResponse>}
955
1089
  */
956
- async function changeOnce(sub, slug, thing, value, options, seen) {
1090
+ async function changeOnce(
1091
+ sub,
1092
+ slug,
1093
+ thing,
1094
+ value,
1095
+ options,
1096
+ seen,
1097
+ typedThing = thing,
1098
+ ) {
957
1099
  const {cwd = process.cwd(), png = false} = options;
958
1100
  requireProject(cwd);
959
1101
  // The setting this command changes or removes may be the bad one; any
960
1102
  // other bad setting still refuses (or is left out when this fixes one).
961
1103
  const target = /** @type {Partial<import('./_settings.mjs').Setting>} */ ({
962
- thing,
1104
+ // An undo may name a saved entry exactly as written.
1105
+ thing: sub === 'undo' ? typedThing : thing,
963
1106
  on: options.on,
964
1107
  when: options.when,
965
1108
  state: options.state,
@@ -1016,10 +1159,63 @@ async function changeOnce(sub, slug, thing, value, options, seen) {
1016
1159
  /** @type {import('./_settings.mjs').Ctx} */ (ctx).base = base;
1017
1160
  seen.ctx = ctx;
1018
1161
  seen.data = structuredClone(data);
1162
+ // The saved entry an undo names exactly as written (thing and scope, in
1163
+ // their own letters), when the editor would read it as another setting
1164
+ // or refuse it: that entry is removed, never a valid neighbor the
1165
+ // cleaned name also matches.
1166
+ const exactIdx =
1167
+ sub === 'undo'
1168
+ ? data.settings.findIndex(
1169
+ x =>
1170
+ x.thing === typedThing &&
1171
+ (x.on ?? null) === (flags.on ?? null) &&
1172
+ (x.when ?? null) === (flags.when ?? null) &&
1173
+ (x.state ?? null) === (flags.state ?? null) &&
1174
+ (x.mode ?? null) === (flags.mode ?? null) &&
1175
+ Boolean(x.only) === Boolean(flags.only),
1176
+ )
1177
+ : -1;
1178
+ let rawIdx = -1;
1179
+ if (exactIdx >= 0) {
1180
+ // Only an entry the editor would not save as written: one it refuses,
1181
+ // or reads as another name, part or state.
1182
+ const entry = data.settings[exactIdx];
1183
+ let read = null;
1184
+ try {
1185
+ read = checkSetting(
1186
+ ctx,
1187
+ slug,
1188
+ data,
1189
+ normalizeEntry(entry.thing, '').thing,
1190
+ undefined,
1191
+ {
1192
+ on: entry.on,
1193
+ when: entry.when,
1194
+ state: entry.state,
1195
+ mode: entry.mode,
1196
+ only: entry.only,
1197
+ },
1198
+ true,
1199
+ );
1200
+ } catch {
1201
+ // Refused as written.
1202
+ }
1203
+ if (
1204
+ !read ||
1205
+ read.thing !== entry.thing ||
1206
+ (read.on ?? null) !== (entry.on ?? null) ||
1207
+ (read.state ?? null) !== (entry.state ?? null) ||
1208
+ (read.when ?? null) !== (entry.when ?? null)
1209
+ )
1210
+ rawIdx = exactIdx;
1211
+ }
1019
1212
  /** @type {import('./_settings.mjs').Setting} */
1020
1213
  let s;
1021
1214
  try {
1022
- s = checkSetting(ctx, slug, data, thing, value, flags, sub === 'undo');
1215
+ s =
1216
+ rawIdx >= 0
1217
+ ? data.settings[rawIdx]
1218
+ : checkSetting(ctx, slug, data, thing, value, flags, sub === 'undo');
1023
1219
  } catch (e) {
1024
1220
  // A stored setting this Core no longer knows (a renamed part or
1025
1221
  // property, or a hand edit) can still be removed.
@@ -1181,6 +1377,13 @@ async function changeOnce(sub, slug, thing, value, options, seen) {
1181
1377
  ]
1182
1378
  : []),
1183
1379
  ...otherModeNotes(data),
1380
+ // Core has no mode inside a theme: the app's <Theme> is given it.
1381
+ ...(s.thing === 'mode' &&
1382
+ (data.mode === 'light-only' || data.mode === 'dark-only')
1383
+ ? [
1384
+ `the app shows ${slug} in ${data.mode === 'light-only' ? 'light' : 'dark'} mode when its <Theme> is given mode="${data.mode === 'light-only' ? 'light' : 'dark'}" (<Theme theme={…} mode="${data.mode === 'light-only' ? 'light' : 'dark'}">), as the preview does; the theme keeps both halves of its colors, so a toast or a lightbox Core draws in the other mode stays readable`,
1385
+ ]
1386
+ : []),
1184
1387
  // The colors are made again for the new base or mode: their
1185
1388
  // shade notes follow.
1186
1389
  ...data.settings
@@ -1207,7 +1410,8 @@ async function changeOnce(sub, slug, thing, value, options, seen) {
1207
1410
  };
1208
1411
  }
1209
1412
  const k = keyOf(s);
1210
- const prevIdx = data.settings.findIndex(x => keyOf(x) === k);
1413
+ const prevIdx =
1414
+ rawIdx >= 0 ? rawIdx : data.settings.findIndex(x => keyOf(x) === k);
1211
1415
  /** @type {string | null} */
1212
1416
  let vibrancyGone = null;
1213
1417
  const prev = prevIdx >= 0 ? data.settings[prevIdx] : null;
@@ -1333,7 +1537,7 @@ async function changeOnce(sub, slug, thing, value, options, seen) {
1333
1537
  : [];
1334
1538
  const r = await commitTheme(ctx, slug, data, {history: true});
1335
1539
  const compiledAfter = compileTheme(ctx, data, base);
1336
- const styled = styledChanges(compiledBefore, compiledAfter);
1540
+ const styled = styledChanges(compiledBefore, compiledAfter, base);
1337
1541
  const parts = partsOf(ctx, s);
1338
1542
  // Exact whole-theme tokens that win over what this dial writes: the dial
1339
1543
  // changes them only in a theme without them.
@@ -1441,9 +1645,9 @@ async function changeOnce(sub, slug, thing, value, options, seen) {
1441
1645
  // On parts: every property or token this change writes on a part's
1442
1646
  // plain or variant rule (a dial's too, and each member of a group) that
1443
1647
  // the own source sets on that same rule.
1444
- /** @type {Array<{target: string, key: string, prop: string, value: string | null}>} */
1648
+ /** @type {Array<{target: string, key: string, state?: string | null, prop: string, value: string | null}>} */
1445
1649
  const ownPartHits = [];
1446
- if (sub === 'set' && s.on && !s.state) {
1650
+ if (sub === 'set' && s.on) {
1447
1651
  const a = /** @type {any} */ (compiledBefore)?.components ?? {};
1448
1652
  const b = /** @type {any} */ (compiledAfter)?.components ?? {};
1449
1653
  for (const target of new Set([...Object.keys(a), ...Object.keys(b)]))
@@ -1454,26 +1658,40 @@ async function changeOnce(sub, slug, thing, value, options, seen) {
1454
1658
  if (key !== 'base' && !key.startsWith('variant:')) continue;
1455
1659
  const x = a[target]?.[key] ?? {};
1456
1660
  const y = b[target]?.[key] ?? {};
1457
- /** @type {Map<string, string | null> | null} */
1458
- let own = null;
1459
- for (const prop of new Set([...Object.keys(x), ...Object.keys(y)])) {
1460
- if (
1461
- prop.startsWith(':') ||
1462
- JSON.stringify(x[prop]) === JSON.stringify(y[prop])
1463
- )
1464
- continue;
1465
- const css = prop.startsWith('--')
1466
- ? prop
1467
- : prop.replace(/[A-Z]/g, c => `-${c.toLowerCase()}`);
1468
- own ??= ownPartTokens(cwd, slug, target, key);
1469
- if (own.has(css))
1470
- ownPartHits.push({
1471
- target,
1472
- key,
1473
- prop: css,
1474
- value: own.get(css) ?? null,
1475
- });
1476
- }
1661
+ /**
1662
+ * The changed properties of one rule (or a state block in it)
1663
+ * the own source sets there too.
1664
+ * @param {any} xs @param {any} ys @param {string | null} state
1665
+ */
1666
+ const compare = (xs, ys, state) => {
1667
+ /** @type {Map<string, string | null> | null} */
1668
+ let own = null;
1669
+ for (const prop of new Set([
1670
+ ...Object.keys(xs ?? {}),
1671
+ ...Object.keys(ys ?? {}),
1672
+ ])) {
1673
+ if (JSON.stringify(xs?.[prop]) === JSON.stringify(ys?.[prop]))
1674
+ continue;
1675
+ if (prop.startsWith(':')) {
1676
+ // A state block (`:hover`) in the rule.
1677
+ if (!state) compare(xs?.[prop], ys?.[prop], prop);
1678
+ continue;
1679
+ }
1680
+ const css = prop.startsWith('--')
1681
+ ? prop
1682
+ : prop.replace(/[A-Z]/g, c => `-${c.toLowerCase()}`);
1683
+ own ??= ownPartTokens(cwd, slug, target, key, state);
1684
+ if (own.has(css))
1685
+ ownPartHits.push({
1686
+ target,
1687
+ key,
1688
+ state,
1689
+ prop: css,
1690
+ value: own.get(css) ?? null,
1691
+ });
1692
+ }
1693
+ };
1694
+ compare(x, y, null);
1477
1695
  }
1478
1696
  }
1479
1697
  // A part dial writes its property on each part it reaches: the own
@@ -1497,6 +1715,31 @@ async function changeOnce(sub, slug, thing, value, options, seen) {
1497
1715
  !ownPartHits.some(h => h.target === target && h.prop === prop)
1498
1716
  )
1499
1717
  ownPartHits.push({target, key: s.when ?? 'base', prop, value});
1718
+ // A padding the own source sets on a rule wins over every padding setting
1719
+ // there (the editor writes none), whichever sides each names.
1720
+ if (
1721
+ sub === 'set' &&
1722
+ s.source === 'property' &&
1723
+ s.on &&
1724
+ /^padding(-|$)/.test(s.thing)
1725
+ )
1726
+ for (const target of partsOf(ctx, s)) {
1727
+ const state = s.state ? `:${s.state}` : null;
1728
+ for (const [prop, value] of ownPartTokens(
1729
+ cwd,
1730
+ slug,
1731
+ target,
1732
+ s.when ?? 'base',
1733
+ state,
1734
+ ))
1735
+ if (
1736
+ /^padding(-|$)/.test(prop) &&
1737
+ !ownPartHits.some(h => h.target === target && h.prop === prop)
1738
+ ) {
1739
+ ownPartHits.push({target, key: s.when ?? 'base', state, prop, value});
1740
+ break;
1741
+ }
1742
+ }
1500
1743
  // A direct setting on exactly the rule the own source sets: its undo
1501
1744
  // takes it back (anything else the file wins over either way).
1502
1745
  const ownHitDirect =
@@ -1504,7 +1747,8 @@ async function changeOnce(sub, slug, thing, value, options, seen) {
1504
1747
  (s.source === 'token' || s.source === 'property') &&
1505
1748
  ownPartHits[0].target === s.on &&
1506
1749
  ownPartHits[0].prop === s.thing &&
1507
- ownPartHits[0].key === (s.when ?? 'base');
1750
+ ownPartHits[0].key === (s.when ?? 'base') &&
1751
+ (ownPartHits[0].state ?? null) === (s.state ? `:${s.state}` : null);
1508
1752
  const ownOverToken =
1509
1753
  sub !== 'set' || s.when || s.state || s.on
1510
1754
  ? null
@@ -1525,7 +1769,7 @@ async function changeOnce(sub, slug, thing, value, options, seen) {
1525
1769
  .slice(0, 3)
1526
1770
  .map(
1527
1771
  h =>
1528
- `${h.prop} on ${h.target}${h.key === 'base' ? '' : ` when ${h.key}`} itself${h.value != null ? ` (${h.value})` : ''}`,
1772
+ `${h.prop} on ${h.target}${h.state ? ` ${h.state}` : ''}${h.key === 'base' ? '' : ` when ${h.key}`} itself${h.value != null ? ` (${h.value})` : ''}`,
1529
1773
  )
1530
1774
  .join(
1531
1775
  ', ',
@@ -1770,18 +2014,24 @@ async function changeOnce(sub, slug, thing, value, options, seen) {
1770
2014
  notes.push(
1771
2015
  'text below the base size keeps its standard sizes, so small text stays readable',
1772
2016
  );
1773
- // A change that changed nothing writes nothing, the preview included.
2017
+ // A change that changed nothing writes nothing, the preview included,
2018
+ // once preview.html was rendered from the theme as it is now (a retry
2019
+ // after a render that failed renders it).
1774
2020
  const f0 = themeFiles(cwd, slug);
1775
2021
  const p =
1776
- r.unchanged && !png && fs.existsSync(f0.preview)
2022
+ r.unchanged &&
2023
+ !png &&
2024
+ fs.existsSync(f0.preview) &&
2025
+ previewIsCurrent(ctx, slug, data)
1777
2026
  ? {
1778
2027
  preview: shown(cwd, f0.preview),
1779
2028
  pictures: [],
1780
2029
  pictureProblem: null,
1781
2030
  notChecked: null,
1782
2031
  previewStale: [],
2032
+ see: seeLine(cwd, slug, changeFocus(s)),
1783
2033
  }
1784
- : await previewAndRoute(ctx, slug, data, png);
2034
+ : await previewAndRoute(ctx, slug, data, png, changeFocus(s));
1785
2035
  return {
1786
2036
  type: sub === 'set' ? 'themeEdit.set' : 'themeEdit.undo',
1787
2037
  data: {
@@ -1872,6 +2122,9 @@ export async function themeEditShow(theme, options = {}) {
1872
2122
  const section = checkSection(options.section, theme);
1873
2123
  const data = loadTheme(cwd, theme);
1874
2124
  const ctx = await context(cwd);
2125
+ // The app copy is written once show succeeds (at its end), never by a
2126
+ // build a later refusal puts back.
2127
+ holdAfterBuild(ctx);
1875
2128
  refuseStoredTokens(ctx, theme, data);
1876
2129
  // Without React, show still lists the settings and builds the theme, as
1877
2130
  // set does; only the pages, pictures and the checks that render are
@@ -2012,6 +2265,8 @@ export async function themeEditShow(theme, options = {}) {
2012
2265
  await buildTheme(ctx, theme, data);
2013
2266
  return resolvedTokens(ctx, theme);
2014
2267
  });
2268
+ const ownOverNotes = ownOverSettingNotes(cwd, theme, data);
2269
+ const ownMasked = ownOverNotes.map(n => n.slice(0, n.indexOf(': ')));
2015
2270
  const checked = await contrastProblems(ctx, data, res);
2016
2271
  // What cannot be measured is a note, not a problem.
2017
2272
  const problems = checked.filter(x => !x.startsWith('not checked'));
@@ -2074,6 +2329,14 @@ export async function themeEditShow(theme, options = {}) {
2074
2329
  modes,
2075
2330
  )
2076
2331
  : {files: [], problem: null};
2332
+ // The app copy follows the build there now, also when the build was
2333
+ // current and only the copy is missing (a theme made before it existed).
2334
+ if (!readOnly)
2335
+ try {
2336
+ writeAppCopy(ctx, theme, data);
2337
+ } catch (e) {
2338
+ if (/** @type {any} */ (e)?.lockLost) throw e;
2339
+ }
2077
2340
  return {
2078
2341
  type: 'themeEdit.show',
2079
2342
  data: {
@@ -2131,7 +2394,13 @@ export async function themeEditShow(theme, options = {}) {
2131
2394
  `${brokenSource}, so settings cannot take effect; put back the import, extends and name lines in ${theme}.theme.ts${/no longer names the theme/.test(brokenSource) ? ` (a copy of another theme's source still names that theme: change its name to '${theme}')` : ''}`,
2132
2395
  ]
2133
2396
  : []),
2134
- ...checked.filter(x => x.startsWith('not checked')),
2397
+ // A setting the theme file wins over is not live: no contrast
2398
+ // caveat for it (its own note says it does not show).
2399
+ ...checked.filter(
2400
+ x =>
2401
+ x.startsWith('not checked') &&
2402
+ !ownMasked.some(d => x.includes(` for ${d},`)),
2403
+ ),
2135
2404
  ...fontNotes(ctx, data),
2136
2405
  ...ownSourceMaskNotes(
2137
2406
  ctx,
@@ -2140,7 +2409,7 @@ export async function themeEditShow(theme, options = {}) {
2140
2409
  data,
2141
2410
  await baseResolved(ctx.project, data.like),
2142
2411
  ),
2143
- ...ownOverSettingNotes(cwd, theme, data),
2412
+ ...ownOverNotes,
2144
2413
  ...ownPhoneNotes(cwd, theme, data),
2145
2414
  ],
2146
2415
  // A size, number or font is the same in both modes: one value.
@@ -2167,6 +2436,13 @@ export async function themeEditShow(theme, options = {}) {
2167
2436
  skipped: sheet.skipped,
2168
2437
  pictures: shots.files,
2169
2438
  pictureProblem: shots.problem,
2439
+ // How to use the theme in this app: theme add <theme> for its app copy.
2440
+ wiring: appWiring(ctx, theme, data),
2441
+ ...(() => {
2442
+ // The first time the theme's app copy is written, its files.
2443
+ const wrote = takeFirstAppCopy(cwd, theme);
2444
+ return wrote ? {appCopy: {wrote}} : {};
2445
+ })(),
2170
2446
  colorFiles: pal ? colorFiles(theme) : null,
2171
2447
  },
2172
2448
  };
@@ -2226,17 +2502,17 @@ function nowApplies(ctx, data, removed, base) {
2226
2502
  // On a part, the same for what the own source sets on that part's rule.
2227
2503
  if (
2228
2504
  (removed.source === 'token' || removed.source === 'property') &&
2229
- removed.on &&
2230
- !removed.state
2505
+ removed.on
2231
2506
  ) {
2232
2507
  const own = ownPartTokens(
2233
2508
  ctx.project.cwd,
2234
2509
  data.name,
2235
2510
  removed.on,
2236
2511
  removed.when ?? 'base',
2512
+ removed.state ? `:${removed.state}` : null,
2237
2513
  );
2238
2514
  if (own.has(removed.thing))
2239
- return `${removed.thing} = ${own.get(removed.thing) ?? 'its value'} on ${removed.on}${removed.when ? ` when ${removed.when}` : ''} (set in ${data.name}.theme.ts)`;
2515
+ return `${removed.thing} = ${own.get(removed.thing) ?? 'its value'} on ${removed.on}${removed.state ? ` :${removed.state}` : ''}${removed.when ? ` when ${removed.when}` : ''} (set in ${data.name}.theme.ts)`;
2240
2516
  }
2241
2517
  // A role font removed under an exact --font-family-<role>: that token is
2242
2518
  // what shows there.
@@ -2432,9 +2708,12 @@ function dialTouched(ctx, data, s, base) {
2432
2708
  }
2433
2709
 
2434
2710
  /**
2435
- * The family and weight tokens the theme's own source sets that phones do
2436
- * not show: on top of a base theme, its phone rule puts its own type back
2437
- * there (a Core limit), unless an exact setting is repeated after it.
2711
+ * The family and weight tokens the theme's own source sets as plain tokens
2712
+ * that phones do not show: on top of a base theme, its rule for those
2713
+ * screens sets its type again (a rule wins over plain tokens, by Core's
2714
+ * contract), unless an exact setting is repeated after it. The note names
2715
+ * the fix within that contract: the theme's typography, or a same-screens
2716
+ * rule.
2438
2717
  * @param {string} cwd
2439
2718
  * @param {string} slug
2440
2719
  * @param {import('./_settings.mjs').ThemeData} data
@@ -2451,8 +2730,11 @@ function ownPhoneNotes(cwd, slug, data) {
2451
2730
  k => PHONE_TYPE.test(k) && !exact.has(k),
2452
2731
  );
2453
2732
  if (!lost.length) return [];
2733
+ const families = lost.filter(k => /^--font-family-/.test(k));
2734
+ const role =
2735
+ /^--font-family-([a-z]+)$/.exec(families[0] ?? '')?.[1] ?? 'body';
2454
2736
  return [
2455
- `on ${PHONES}, the base theme's type shows for ${lost.slice(0, 4).join(', ')}${lost.length > 4 ? ` and ${lost.length - 4} more` : ''}, which ${slug}.theme.ts sets: the base theme sets its type again there, after your file (a Core limit); wide screens show your file's`,
2737
+ `on ${PHONES}, the base theme's type shows for ${lost.slice(0, 4).join(', ')}${lost.length > 4 ? ` and ${lost.length - 4} more` : ''}, which ${slug}.theme.ts sets as plain tokens: the base theme's rule for those screens sets its type again, and a rule wins over plain tokens there. To keep yours on every screen, set ${lost.length > 1 ? 'them' : 'it'} on the theme's typography in ${slug}.theme.ts (such as typography: {${role}: {family: ...}}, which that rule then keeps), or in a rule for the same screens`,
2456
2738
  ];
2457
2739
  }
2458
2740
 
@@ -2473,7 +2755,7 @@ function ownOverSettingNotes(cwd, slug, data) {
2473
2755
  /** @type {string[]} */
2474
2756
  const out = [];
2475
2757
  for (const x of data.settings) {
2476
- if (x.state || (x.source !== 'token' && x.source !== 'property')) continue;
2758
+ if (x.source !== 'token' && x.source !== 'property') continue;
2477
2759
  if (!x.on) {
2478
2760
  if (x.source === 'token' && !x.when && topKeys.has(x.thing))
2479
2761
  out.push(
@@ -2481,13 +2763,21 @@ function ownOverSettingNotes(cwd, slug, data) {
2481
2763
  );
2482
2764
  continue;
2483
2765
  }
2484
- const key = `${x.on}\0${x.when ?? 'base'}`;
2766
+ const state = x.state ? `:${x.state}` : null;
2767
+ const key = `${x.on}\0${x.when ?? 'base'}\0${state ?? ''}`;
2485
2768
  if (!parts.has(key))
2486
- parts.set(key, ownPartTokens(cwd, slug, x.on, x.when ?? 'base'));
2769
+ parts.set(key, ownPartTokens(cwd, slug, x.on, x.when ?? 'base', state));
2487
2770
  const own = /** @type {Map<string, string | null>} */ (parts.get(key));
2488
- if (own.has(x.thing))
2771
+ // A padding the own source sets on the rule wins over every padding
2772
+ // setting there, whichever sides each names.
2773
+ const shown = own.has(x.thing)
2774
+ ? x.thing
2775
+ : /^padding(-|$)/.test(x.thing)
2776
+ ? [...own.keys()].find(k => /^padding(-|$)/.test(k))
2777
+ : undefined;
2778
+ if (shown)
2489
2779
  out.push(
2490
- `${describe(x)}: ${slug}.theme.ts sets ${x.thing} on ${x.on}${x.when ? ` when ${x.when}` : ''} itself${own.get(x.thing) != null ? ` (${own.get(x.thing)})` : ''}, so this setting does not show there`,
2780
+ `${describe(x)}: ${slug}.theme.ts sets ${shown} on ${x.on}${state ? ` ${state}` : ''}${x.when ? ` when ${x.when}` : ''} itself${own.get(shown) != null ? ` (${own.get(shown)})` : ''}, so this setting does not show there`,
2491
2781
  );
2492
2782
  }
2493
2783
  return out;
@@ -2990,7 +3280,18 @@ export async function themeEditUndo(theme, options = {}) {
2990
3280
  );
2991
3281
  if (current && current.mode !== prev.mode)
2992
3282
  undone.push(`mode ${current.mode} is back to ${prev.mode}`);
2993
- const p = await previewAndRoute(ctx, theme, prev, png);
3283
+ // The page most about what the step reverted: Colors for a color,
3284
+ // Components for a part setting, else Overview.
3285
+ const touched = [
3286
+ ...[...was].filter(([k, s]) => now.get(k)?.value !== s.value),
3287
+ ...[...now].filter(([k]) => !was.has(k)),
3288
+ ].map(([, s]) => changeFocus(s));
3289
+ const focus = touched.includes('colors')
3290
+ ? 'colors'
3291
+ : touched.includes('components')
3292
+ ? 'components'
3293
+ : 'overview';
3294
+ const p = await previewAndRoute(ctx, theme, prev, png, focus);
2994
3295
  return {
2995
3296
  type: 'themeEdit.undo',
2996
3297
  data: {