@astryxdesign/cli 0.7.16-canary.gca36b56 → 0.7.16-canary.ge41a6d8

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.
@@ -111,7 +111,7 @@ dataTokens dataTokens theme/MediaTheme.doc.mjs theme/domainTokens/dataTokens.ts
111
111
  dayCellUtils dayCellUtils Calendar/Calendar.doc.mjs Calendar/dayCellUtils.ts
112
112
  declarationBoundary declarationBoundary theme/MediaTheme.doc.mjs theme/declarationBoundary.ts
113
113
  defaultIcons defaultIcons Icon/Icon.doc.mjs Icon/defaultIcons.tsx
114
- defineSyntaxTheme defineSyntaxTheme theme/MediaTheme.doc.mjs theme/syntax/defineSyntaxTheme.ts
114
+ defineSyntaxTheme defineSyntaxTheme theme/syntax/useSyntaxTheme.doc.mjs theme/syntax/defineSyntaxTheme.ts
115
115
  defineTheme defineTheme theme/MediaTheme.doc.mjs theme/defineTheme.ts
116
116
  derivedVarRegistry derivedVarRegistry theme/MediaTheme.doc.mjs theme/derivedVarRegistry.ts
117
117
  dockerfile dockerfile CodeBlock/CodeBlock.doc.mjs CodeBlock/languages/dockerfile.ts
@@ -191,7 +191,7 @@ popoverOperations popoverOperations Layer/Layer.doc.mjs Layer/popoverOperations.
191
191
  powerSearchSheetUtils powerSearchSheetUtils PowerSearch/PowerSearch.doc.mjs PowerSearch/powerSearchSheetUtils.ts
192
192
  powershell powershell CodeBlock/CodeBlock.doc.mjs CodeBlock/languages/powershell.ts
193
193
  preserveAnimations preserveAnimations Layer/Layer.doc.mjs Layer/preserveAnimations.ts
194
- presets presets theme/MediaTheme.doc.mjs theme/syntax/presets.ts
194
+ presets presets theme/syntax/useSyntaxTheme.doc.mjs theme/syntax/presets.ts
195
195
  pressGroupContext pressGroupContext hooks/useAnimatedLayout.doc.mjs hooks/pressGroupContext.ts
196
196
  protocol protocol Markdown/Markdown.doc.mjs Markdown/plugins/protocol.ts
197
197
  publicContext publicContext i18n/InternationalizationProvider.doc.mjs i18n/publicContext.ts
@@ -42,7 +42,7 @@ import * as preview from './_preview-app.mjs';
42
42
  import {AstryxError} from '../error.mjs';
43
43
  import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
44
44
  import {findPackageRoot} from '../../foundation/fs/paths.mjs';
45
- import {coreApp} from './_context.mjs';
45
+ import {context, coreApp} from './_context.mjs';
46
46
  import {isOutsideProject} from '../../foundation/env/project-scope.mjs';
47
47
  import {withFolderLock} from '../../foundation/release/folder-lock.mjs';
48
48
  import {
@@ -58,7 +58,12 @@ import {
58
58
  writeAppCopyAt,
59
59
  } from './_preview.mjs';
60
60
  import {humanWarn} from '../../foundation/response/json.mjs';
61
- import {folderIsEmpty, setAfterBuild, typedThemeName} from './_settings.mjs';
61
+ import {
62
+ folderIsEmpty,
63
+ loadTheme,
64
+ setAfterBuild,
65
+ typedThemeName,
66
+ } from './_settings.mjs';
62
67
 
63
68
  // Every build of a theme writes its app copy (src/themes/<theme>/).
64
69
  setAfterBuild(writeAppCopy);
@@ -683,10 +688,43 @@ export function editorThemeRefusal(err, cwd) {
683
688
  const word = named ? typedThemeName(named[1] ?? named[2]) : '';
684
689
  const slug = word ? editorThemeOf(root, word) : null;
685
690
  if (!slug) return null;
691
+ // The command that refused: list, add, use, remove or eject.
692
+ const verb =
693
+ process.argv
694
+ .slice(2)
695
+ .find(a => ['list', 'add', 'use', 'remove', 'eject'].includes(a)) ?? null;
696
+ // eject copies a theme package's source into the app; an editor theme's
697
+ // source is the app's already.
698
+ if (verb === 'eject')
699
+ return new AstryxError(
700
+ `${slug} is a theme the editor made: its source is yours already, themes/${slug}/${slug}.theme.ts (your edits there survive every change), and the editor changes the rest. eject copies a theme package's source into the app, so it has nothing to do for ${slug}.`,
701
+ [
702
+ {
703
+ name: runLine(cwd, `experimental theme editor show ${slug}`),
704
+ reason: 'the theme as it is now',
705
+ },
706
+ ],
707
+ ERROR_CODES.ERR_UNKNOWN_THEME,
708
+ );
709
+ const copyThere = !folderIsEmpty(path.join(root, LOCAL_THEME_ROOT, slug));
710
+ // A path to the theme ("themes/d", "src/themes/d"): the commands take its
711
+ // name.
712
+ const typed = named ? (named[1] ?? named[2]) : '';
713
+ if (copyThere && verb && typed !== slug)
714
+ return new AstryxError(
715
+ `"${typed}" is ${/[\\/]|\.[a-z]+$/i.test(typed) ? 'a path' : "not the theme's name"}; the theme commands take the theme's name: ${slug}.`,
716
+ [
717
+ {
718
+ name: runLine(cwd, `theme ${verb} ${slug}`),
719
+ reason: 'the same, by name',
720
+ },
721
+ ],
722
+ ERROR_CODES.ERR_UNKNOWN_THEME,
723
+ );
686
724
  // A local theme of that name (a fork in the app's own themes folder) is
687
725
  // one the stable commands take: their own message stands.
688
726
  // A folder of only system files (or empty) holds no theme: as absent.
689
- if (!folderIsEmpty(path.join(root, LOCAL_THEME_ROOT, slug))) return null;
727
+ if (copyThere) return null;
690
728
  // No app copy yet (a theme made before the editor wrote one, or the
691
729
  // copy removed): the next build writes it, then the same steps every
692
730
  // place gives (`wiring` of new and show).
@@ -946,7 +984,20 @@ export async function editorThemeHold(files, {cwd}) {
946
984
  // (src/themes/<theme>/), under the same lock; a check writes nothing.
947
985
  if (!process.argv.includes('--check')) {
948
986
  try {
949
- writeAppCopyAt(root, slug, null);
987
+ // The same whole copy the editor's build writes, its font
988
+ // stylesheets from the theme's settings.
989
+ // A copy without its font stylesheet (missing): from the theme.
990
+ if (
991
+ !fs.existsSync(
992
+ path.join(root, 'src', 'themes', slug, `${slug}.fonts.css`),
993
+ )
994
+ )
995
+ try {
996
+ writeAppCopy(await context(root), slug, loadTheme(root, slug));
997
+ } catch {
998
+ writeAppCopyAt(root, slug, null);
999
+ }
1000
+ else writeAppCopyAt(root, slug, null);
950
1001
  // The first write of the app copy is named once (the compile's
951
1002
  // own JSON envelope is the stable command's).
952
1003
  const wrote = takeFirstAppCopy(root, slug);
@@ -104,27 +104,6 @@ export function unknownVarRef(v: string, TOKENS: Record<string, unknown>, thing:
104
104
  * @returns {string | null}
105
105
  */
106
106
  export function fontFileReason(value: string): string | null;
107
- /**
108
- * A value with every Unicode space (no-break, thin, ideographic…) as a plain
109
- * space and zero-width and format characters dropped, for every value type:
110
- * the browser reads only a plain space as one.
111
- * @param {string} v
112
- */
113
- export function normalValueText(v: string): string;
114
- /**
115
- * The thing and value a setting was typed as, put right before any check: a
116
- * declaration pasted whole or split (`accent: #e11d48`, `--color-accent=red`,
117
- * `font:inter`, `accent:` with the value next), a token typed with an em or
118
- * en dash (`—color-accent`) or as `var(--color-accent)`, and the value's
119
- * Unicode spaces. A thing it cannot read is left as typed.
120
- * @param {string} thing
121
- * @param {string | undefined} value
122
- * @returns {{thing: string, value: string | undefined}}
123
- */
124
- export function normalizeEntry(thing: string, value: string | undefined): {
125
- thing: string;
126
- value: string | undefined;
127
- };
128
107
  export function setLine(slug: string, thing: string, value: string, s: {
129
108
  on?: string;
130
109
  when?: string;
@@ -141,6 +120,11 @@ export type SetFlags = {
141
120
  mode?: string | undefined;
142
121
  only?: boolean | undefined;
143
122
  };
123
+ import { familiesOf } from './_normal.mjs';
124
+ import { familyPieces } from './_normal.mjs';
125
+ import { normalValueText } from './_normal.mjs';
126
+ import { normalizeEntry } from './_normal.mjs';
127
+ import { withoutDebris } from './_normal.mjs';
144
128
  import { lengthPx } from './_settings.mjs';
145
129
  import { familySpaces } from './_settings.mjs';
146
- export { lengthPx, familySpaces };
130
+ export { familiesOf, familyPieces, normalValueText, normalizeEntry, withoutDebris, lengthPx, familySpaces };
@@ -102,6 +102,21 @@ import {
102
102
  cssFamily,
103
103
  familySpaces,
104
104
  } from './_settings.mjs';
105
+ import {
106
+ familiesOf,
107
+ familyPieces,
108
+ normalValueText,
109
+ normalizeEntry,
110
+ withoutDebris,
111
+ } from './_normal.mjs';
112
+
113
+ export {
114
+ familiesOf,
115
+ familyPieces,
116
+ normalValueText,
117
+ normalizeEntry,
118
+ withoutDebris,
119
+ };
105
120
  import {quoteCommandArgument} from '../../foundation/env/package-manager.mjs';
106
121
 
107
122
  export {lengthPx};
@@ -235,8 +250,16 @@ function matchingParen(text, open) {
235
250
  * @returns {number | null}
236
251
  */
237
252
  function textSizePx(v) {
253
+ // Paste debris around the size (quotes, `!important`, a trailing `;` or
254
+ // `,`) is not part of it.
255
+ const bare = withoutDebris(
256
+ String(v)
257
+ .replace(/^\s*(["'])(.*)\1\s*$/, '$2')
258
+ .replace(/\s*!\s*important\s*/i, '')
259
+ .replace(/[;,]+\s*$/, ''),
260
+ );
238
261
  const m = /^\+?(\d*\.?\d+(?:e[+-]?\d+)?)(px|rem|em|pt|%)?$/i.exec(
239
- typedPlain(v)
262
+ typedPlain(bare)
240
263
  .replace(/(\d)\.(?=[a-z%]*$)/i, '$1')
241
264
  .replace(/\s+/g, '')
242
265
  .replace(/^(\d+),(\d+)/, '$1.$2'),
@@ -344,13 +367,12 @@ function valueMeant(type, value) {
344
367
  if (type === 'font' || type === 'font-family') {
345
368
  // A comma left out between families (`"Open Sans" serif`), read with
346
369
  // css-tree.
370
+ // The stack read as families (a trailing comma, a stack wrapped in one
371
+ // more pair of quotes), each quoted as CSS needs it.
372
+ const fams = familiesOf(p);
373
+ if (fams?.length) out.push(fams.map(f => cssFamily(f, true)).join(', '));
347
374
  const listed = familyListMeant(p);
348
- if (listed) out.push(listed);
349
- // Each family quoted as CSS needs it, only when no family holds a
350
- // quote inside (the pieces are whole names).
351
- const pieces = p.split(',').map(f => f.trim().replace(/^["']|["']$/g, ''));
352
- if (!listed && pieces.every(f => !/["'\\]/.test(f)))
353
- out.push(pieces.map(f => cssFamily(f, true)).join(', '));
375
+ if (listed && !fams?.length) out.push(listed);
354
376
  }
355
377
  return [...new Set(out)].filter(x => x && x !== value.trim());
356
378
  }
@@ -649,12 +671,38 @@ export function storedProblems(ctx, slug, data, skip = '') {
649
671
  for (const s of data.settings) {
650
672
  if (replaced(s) || typeof s.value !== 'string') continue;
651
673
  const clean = normalValueText(s.value);
652
- if (clean !== s.value)
674
+ if (clean !== s.value) {
675
+ // Name what is wrong: invisible spaces, or quotes around the value
676
+ // CSS does not read (a curly quote inside a quoted string is fine,
677
+ // and is left as it is).
678
+ const spaces =
679
+ clean.replace(/["']/g, '') !==
680
+ s.value.replace(
681
+ /[\u2018-\u201F\u00AB\u00BB\u2039\u203A\uFF02\uFF07`"']/g,
682
+ '',
683
+ );
684
+ const quotes =
685
+ /[\u2018-\u201F\u00AB\u00BB\u2039\u203A\uFF02\uFF07`]/.test(s.value) &&
686
+ clean.replace(
687
+ /[\u00A0\u1680\u2000-\u200A\u202F\u205F\u3000\u200B-\u200D\u2060\uFEFF]/g,
688
+ '',
689
+ ) !==
690
+ s.value.replace(
691
+ /[\u00A0\u1680\u2000-\u200A\u202F\u205F\u3000\u200B-\u200D\u2060\uFEFF]/g,
692
+ '',
693
+ );
694
+ const why = [
695
+ spaces &&
696
+ 'a no-break, thin or zero-width space, which the browser does not read as a space',
697
+ quotes &&
698
+ 'curly or other quotes around a value, where CSS reads only straight ones',
699
+ ].filter(Boolean);
653
700
  found.push({
654
701
  setting: s,
655
- why: `${s.thing} holds a no-break, thin or zero-width space, which the browser does not read as a space`,
702
+ why: `${s.thing} holds ${why.join(', and ') || 'characters the browser does not read as written'}`,
656
703
  fix: clean,
657
704
  });
705
+ }
658
706
  }
659
707
  for (const s of data.settings) {
660
708
  if (s.source !== 'token' || s.thing === skipThing || !(s.thing in TOKENS))
@@ -792,6 +840,18 @@ function checkTypedValue(
792
840
  `${P} set ${slug} ${name} ${quoteCommandArgument(exampleOf(type, name))}`,
793
841
  ],
794
842
  });
843
+ // An empty family (`""`, a trailing comma) or one quoted name holding
844
+ // commas is a broken stack: the browser drops the fallback after it.
845
+ const pieces = familyPieces(value);
846
+ if (
847
+ pieces &&
848
+ (pieces.some(f => !f.name) ||
849
+ pieces.some(f => f.quoted && f.name.includes(',')))
850
+ )
851
+ bad(
852
+ 'a font family list with a name for each family',
853
+ exampleOf(type, name),
854
+ );
795
855
  }
796
856
  if (!isSafeValue(value))
797
857
  refuse(
@@ -1628,18 +1688,32 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
1628
1688
  .toLowerCase();
1629
1689
  if (flags.only) s.only = true;
1630
1690
  if (flags.mode) {
1631
- const mode = flags.mode.toLowerCase();
1632
- if (mode !== 'light' && mode !== 'dark')
1691
+ // Read as any value is: invisible or no-break spaces, quotes around
1692
+ // it, a trailing colon (`'dark '`, `“dark”`, `dark:`).
1693
+ const mode = withoutDebris(normalValueText(String(flags.mode)))
1694
+ .trim()
1695
+ .replace(/^(["'])(.*)\1$/, '$2')
1696
+ .replace(/:+$/, '')
1697
+ .trim()
1698
+ .toLowerCase();
1699
+ if (mode !== 'light' && mode !== 'dark') {
1700
+ const near = nearest(mode, ['light', 'dark']);
1633
1701
  refuse(
1634
1702
  E.ERR_THEME_BAD_VALUE,
1635
1703
  `--mode takes light or dark, not "${flags.mode}".`,
1636
1704
  {
1637
- didYouMean: nearest(mode, ['light', 'dark']),
1638
- // The same setting for both modes runs as printed; the mode it
1639
- // probably meant is the did-you-mean.
1640
- run: [setLine(slug, thing, v, {...s, mode: undefined}, unset)],
1705
+ didYouMean: near,
1706
+ // The mode it is nearest keeps --mode; only with none near is the
1707
+ // same setting for both modes offered.
1708
+ run: [
1709
+ ...(near.length === 1
1710
+ ? [setLine(slug, thing, v, {...s, mode: near[0]}, unset)]
1711
+ : []),
1712
+ setLine(slug, thing, v, {...s, mode: undefined}, unset),
1713
+ ],
1641
1714
  },
1642
1715
  );
1716
+ }
1643
1717
  s.mode = mode;
1644
1718
  }
1645
1719
  const onFlag = s.on ? ` --on ${s.on}` : '';
@@ -3848,74 +3922,6 @@ export function fontFileReason(value) {
3848
3922
  : null;
3849
3923
  }
3850
3924
 
3851
- /**
3852
- * A value with every Unicode space (no-break, thin, ideographic…) as a plain
3853
- * space and zero-width and format characters dropped, for every value type:
3854
- * the browser reads only a plain space as one.
3855
- * @param {string} v
3856
- */
3857
- export function normalValueText(v) {
3858
- // Curly quotes (a word processor's, a phone's) are the straight ones CSS
3859
- // reads.
3860
- const straight = v
3861
- .replace(/[\u2018\u2019\u201A\u201B]/g, "'")
3862
- .replace(/[\u201C\u201D\u201E\u201F]/g, '"');
3863
- // A quoted CSS string (`content: "a\u00A0b"`) keeps what is inside it.
3864
- return straight
3865
- .split(/("(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*')/)
3866
- .map((part, i) =>
3867
- i % 2
3868
- ? part
3869
- : part
3870
- .replace(/[\u200B-\u200D\u2060\uFEFF]/g, '')
3871
- .replace(/[\u00A0\u1680\u2000-\u200A\u202F\u205F\u3000]/g, ' '),
3872
- )
3873
- .join('');
3874
- }
3875
-
3876
- /**
3877
- * The thing and value a setting was typed as, put right before any check: a
3878
- * declaration pasted whole or split (`accent: #e11d48`, `--color-accent=red`,
3879
- * `font:inter`, `accent:` with the value next), a token typed with an em or
3880
- * en dash (`—color-accent`) or as `var(--color-accent)`, and the value's
3881
- * Unicode spaces. A thing it cannot read is left as typed.
3882
- * @param {string} thing
3883
- * @param {string | undefined} value
3884
- * @returns {{thing: string, value: string | undefined}}
3885
- */
3886
- export function normalizeEntry(thing, value) {
3887
- let t = normalValueText(String(thing ?? '')).trim();
3888
- let v = value == null ? value : normalValueText(String(value));
3889
- // A pasted declaration (the whole of it in the thing, or the thing with
3890
- // its colon and the value next): its `;` and `!important` go with it.
3891
- let pasted = false;
3892
- if (v == null || v.trim() === '') {
3893
- const m = /^(\S+?)\s*[:=]\s*(.+?)\s*;?\s*$/.exec(t);
3894
- if (m && !/^https?$/i.test(m[1])) {
3895
- t = m[1];
3896
- v = m[2];
3897
- pasted = true;
3898
- }
3899
- }
3900
- // A thing ending in its colon or equals sign, the value given next.
3901
- if (/\s*[:=]+$/.test(t)) {
3902
- t = t.replace(/\s*[:=]+$/, '');
3903
- pasted = true;
3904
- }
3905
- // Dash-like characters where a token's two dashes go (an em or en dash,
3906
- // a non-breaking hyphen, a minus sign, a full-width hyphen, alone or
3907
- // mixed with hyphens): `--`.
3908
- t = t.replace(/^[-\u2010-\u2015\u2212\uFE58\uFE63\uFF0D]+/, run =>
3909
- /[^-]/.test(run) ? '--' : run,
3910
- );
3911
- // A token typed as a var() reference.
3912
- const ref = /^var\(\s*(--[a-z0-9-]+)\s*\)$/i.exec(t);
3913
- if (ref) t = ref[1];
3914
- if (pasted && typeof v === 'string')
3915
- v = v.replace(/\s*!\s*important\s*;?\s*$/i, '').replace(/;+\s*$/, '');
3916
- return {thing: t, value: v};
3917
- }
3918
-
3919
3925
  /**
3920
3926
  * A word as a suggested command quotes it, without the quotes.
3921
3927
  * @param {string} word
@@ -9,6 +9,7 @@
9
9
  * @position api/theme-edit — imported only by _adapter.mjs
10
10
  */
11
11
 
12
+ import {THEME_SLUG_RE} from '../../foundation/discovery/theme-discovery.mjs';
12
13
  import * as fs from 'node:fs';
13
14
  import {coversProperty} from './_css.mjs';
14
15
  import * as path from 'node:path';
@@ -83,6 +84,7 @@ import {
83
84
  refuseLinks,
84
85
  usableNewName,
85
86
  FOLDER_JUNK,
87
+ folderIsEmpty,
86
88
  dialValueFits,
87
89
  holdAfterBuild,
88
90
  } from './_settings.mjs';
@@ -111,6 +113,7 @@ import {
111
113
  renderSheet,
112
114
  previewIsCurrent,
113
115
  takeFirstAppCopy,
116
+ appCopyStale,
114
117
  writeAppCopy,
115
118
  } from './_preview.mjs';
116
119
  import {appWiring, refreshPreviewRoute, seeLine} from './_preview-app.mjs';
@@ -360,6 +363,16 @@ export async function themeEditNew(name, options = {}) {
360
363
  },
361
364
  );
362
365
  }
366
+ // A name the theme commands' own discovery skips ("a--b", "b-") would
367
+ // make an app copy no `theme add`, `theme list` or doctor takes.
368
+ if (!THEME_SLUG_RE.test(name)) {
369
+ const cleaned = name.replace(/-{2,}/g, '-').replace(/-+$/, '');
370
+ refuse(
371
+ E.ERR_INVALID_ARGUMENT,
372
+ `"${name}" is not a theme name the theme commands take: a dash only between letters or digits (no two in a row, none at the end), so its app copy in src/themes/ would be skipped by theme add, theme list and doctor.${dropped}`,
373
+ {run: [again(usableNewName(cwd, cleaned))]},
374
+ );
375
+ }
363
376
  // A built-in theme's name would collide with the theme of that name the
364
377
  // app may also use.
365
378
  if (LIKE.includes(name))
@@ -426,7 +439,8 @@ export async function themeEditNew(name, options = {}) {
426
439
  const holdsOther =
427
440
  fs.existsSync(f.dir) &&
428
441
  !left &&
429
- fs.readdirSync(f.dir).some(n => !FOLDER_JUNK.has(n));
442
+ // Empty folders (an empty tokens/) hold nothing of anyone's.
443
+ !folderIsEmpty(f.dir);
430
444
  if (holdsOther)
431
445
  refuse(
432
446
  E.ERR_FILE_EXISTS,
@@ -855,6 +869,8 @@ async function previewAndRoute(ctx, slug, data, png, focus = 'overview') {
855
869
  ),
856
870
  // The first time the theme's app copy is written, its files are named.
857
871
  ...(wrote ? {appCopy: {wrote}} : {}),
872
+ // A copy a file of yours kept from being written: said, never a quiet ok.
873
+ ...appCopyStale(ctx.project.cwd, slug),
858
874
  };
859
875
  }
860
876
 
@@ -903,6 +919,23 @@ function refuseStoredTokens(ctx, slug, data, skip) {
903
919
  const found = bad.length === 1 ? bad[0] : null;
904
920
  // A clean value is offered only when set takes it, so the line works.
905
921
  const takes = (/** @type {typeof found} */ b) => {
922
+ if (!b?.fix) return true;
923
+ // A value whose only fault was curly quotes around it: without them,
924
+ // when set takes that (`“#e11d48”` is #e11d48).
925
+ const bare = /^(["'])(.*)\1$/.exec(b.fix)?.[2];
926
+ if (
927
+ bare &&
928
+ b.setting.source === 'token' &&
929
+ !/font|content/.test(b.setting.thing)
930
+ ) {
931
+ const was = b.fix;
932
+ b.fix = bare;
933
+ if (takesOne(b)) return true;
934
+ b.fix = was;
935
+ }
936
+ return takesOne(b);
937
+ };
938
+ const takesOne = (/** @type {typeof found} */ b) => {
906
939
  if (!b?.fix) return true;
907
940
  try {
908
941
  checkSetting(
@@ -1045,9 +1078,23 @@ async function change(sub, slug, thing, value, options) {
1045
1078
  try {
1046
1079
  return await changeOnce(sub, slug, thing, value, options, seen, typedThing);
1047
1080
  } catch (e) {
1048
- // A theme name one letter off an existing theme: the same command with
1049
- // that name comes first, before making a theme of the typo.
1050
- if (e instanceof AstryxError && e.code === E.ERR_UNKNOWN_THEME) {
1081
+ // A theme name one letter off an existing theme, or typed in other
1082
+ // letters or as a path (T, ./t, themes/t): the same command with that
1083
+ // name comes first, never a bare look at the theme that drops the change.
1084
+ const named =
1085
+ e instanceof AstryxError &&
1086
+ (e.code === E.ERR_UNKNOWN_THEME ||
1087
+ (e.code === E.ERR_INVALID_ARGUMENT &&
1088
+ (e.suggestions ?? []).some(
1089
+ x =>
1090
+ x.reason === 'did you mean' &&
1091
+ slugOk(x.name) &&
1092
+ x.name !== slug &&
1093
+ fs.existsSync(
1094
+ themeFiles(options.cwd ?? process.cwd(), x.name).settings,
1095
+ ),
1096
+ )));
1097
+ if (named) {
1051
1098
  const near = (e.suggestions ?? []).find(x => x.reason === 'did you mean');
1052
1099
  if (near && slugOk(near.name)) {
1053
1100
  const flags = [
@@ -1067,7 +1114,9 @@ async function change(sub, slug, thing, value, options) {
1067
1114
  name: `${P} ${sub} ${near.name}${words.length ? ` ${words.join(' ')}` : ''}`,
1068
1115
  reason: `do this instead: ${near.name} is a theme here`,
1069
1116
  },
1070
- ...(e.suggestions ?? []).filter(x => x !== near),
1117
+ ...(e.suggestions ?? []).filter(
1118
+ x => x !== near && x.name !== `${P} show ${near.name}`,
1119
+ ),
1071
1120
  ];
1072
1121
  }
1073
1122
  throw e;
@@ -1377,6 +1426,15 @@ async function changeOnce(
1377
1426
  ]
1378
1427
  : []),
1379
1428
  ...otherModeNotes(data),
1429
+ // Back to both modes: a mode the app's <Theme> was given for the
1430
+ // one-mode theme pins it still.
1431
+ ...(s.thing === 'mode' &&
1432
+ data.mode === 'both' &&
1433
+ (before === 'light-only' || before === 'dark-only')
1434
+ ? [
1435
+ `if the app's <Theme> was given mode="${before === 'light-only' ? 'light' : 'dark'}" for ${slug}, take it out: with it the app stays ${before === 'light-only' ? 'light' : 'dark'}, whatever the system asks for`,
1436
+ ]
1437
+ : []),
1380
1438
  // Core has no mode inside a theme: the app's <Theme> is given it.
1381
1439
  ...(s.thing === 'mode' &&
1382
1440
  (data.mode === 'light-only' || data.mode === 'dark-only')
@@ -1773,7 +1831,7 @@ async function changeOnce(
1773
1831
  )
1774
1832
  .join(
1775
1833
  ', ',
1776
- )}${ownPartHits.length > 3 ? ` and ${ownPartHits.length - 3} more` : ''}, and your own source wins over the settings, so this does not show there; change it in ${slug}.theme.ts${ownHitDirect ? `, or take this back with \`${P} undo ${slug} ${undoArgs(s)}\`` : ''}`,
1834
+ )}${ownPartHits.length > 3 ? ` and ${ownPartHits.length - 3} more` : ''}, and your own source wins over the settings, so this does not show ${/^padding(-|$)/.test(s.thing) && ownPartHits.every(h => /^padding-/.test(h.prop)) ? 'on the sides that sets; its other sides take this setting' : 'there'}; change it in ${slug}.theme.ts${ownHitDirect ? `, or take this back with \`${P} undo ${slug} ${undoArgs(s)}\`` : ''}`,
1777
1835
  ]
1778
1836
  : []),
1779
1837
  ...(ownOverToken
@@ -2443,6 +2501,7 @@ export async function themeEditShow(theme, options = {}) {
2443
2501
  const wrote = takeFirstAppCopy(cwd, theme);
2444
2502
  return wrote ? {appCopy: {wrote}} : {};
2445
2503
  })(),
2504
+ ...appCopyStale(cwd, theme),
2446
2505
  colorFiles: pal ? colorFiles(theme) : null,
2447
2506
  },
2448
2507
  };