@astryxdesign/cli 0.7.15 → 0.7.16-canary.g9b5ad42

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 (81) hide show
  1. package/README.md +5 -3
  2. package/api/doctor/_adapter.d.mts +17 -0
  3. package/api/doctor/_adapter.mjs +35 -0
  4. package/api/doctor/doctor.mjs +18 -4
  5. package/api/integration/validate-integration.mjs +1 -1
  6. package/api/theme/_adapter.d.mts +5 -2
  7. package/api/theme/_adapter.mjs +43 -12
  8. package/api/theme/build/build.d.mts +1 -21
  9. package/api/theme/build/build.mjs +149 -37
  10. package/api/theme/eject/eject.mjs +22 -1
  11. package/api/theme/template/template.d.mts +2 -0
  12. package/api/theme/template/template.mjs +41 -12
  13. package/api/theme/theme.type.d.mts +4 -0
  14. package/api/theme/theme.type.mjs +2 -1
  15. package/api/theme/themeBuild.doc.mjs +3 -3
  16. package/api/theme/themeEject.doc.mjs +1 -1
  17. package/api/theme/themeTemplate.doc.mjs +9 -3
  18. package/api/theme-edit/_adapter.d.mts +10 -0
  19. package/api/theme-edit/_adapter.mjs +76 -5
  20. package/api/theme-edit/_check.mjs +181 -50
  21. package/api/theme-edit/_color.d.mts +2 -8
  22. package/api/theme-edit/_color.mjs +126 -55
  23. package/api/theme-edit/_compiler.d.mts +1 -0
  24. package/api/theme-edit/_compiler.mjs +3 -0
  25. package/api/theme-edit/_context.d.mts +7 -0
  26. package/api/theme-edit/_context.mjs +34 -1
  27. package/api/theme-edit/_css.d.mts +21 -1
  28. package/api/theme-edit/_css.mjs +172 -13
  29. package/api/theme-edit/_edit.d.mts +9 -0
  30. package/api/theme-edit/_edit.mjs +377 -48
  31. package/api/theme-edit/_how-commands.d.mts +7 -26
  32. package/api/theme-edit/_how-commands.mjs +27 -1
  33. package/api/theme-edit/_how-question.mjs +330 -12
  34. package/api/theme-edit/_how.mjs +68 -26
  35. package/api/theme-edit/_palette.mjs +10 -0
  36. package/api/theme-edit/_parts.d.mts +16 -0
  37. package/api/theme-edit/_parts.mjs +49 -1
  38. package/api/theme-edit/_preview-app.mjs +176 -9
  39. package/api/theme-edit/_preview.mjs +7 -3
  40. package/api/theme-edit/_project.d.mts +11 -0
  41. package/api/theme-edit/_project.mjs +35 -9
  42. package/api/theme-edit/_settings.d.mts +46 -5
  43. package/api/theme-edit/_settings.mjs +217 -25
  44. package/api/theme-edit/theme-edit.type.d.mts +2 -1
  45. package/api/theme-edit/theme-edit.type.mjs +1 -1
  46. package/api/theme-edit/themeEditNew.doc.mjs +1 -1
  47. package/api/theme-edit/themeEditShow.doc.mjs +1 -1
  48. package/assets/docs/tree/tokens-and-setup.doc.mjs +39 -3
  49. package/assets/docs.generated.json +2 -2
  50. package/assets/preview-app/next.config.mjs +7 -1
  51. package/assets/self-audit.generated.json +1 -1
  52. package/assets/templates/blocks/components/Table/ColumnsVirtualizationHookUsage.doc.mjs +14 -0
  53. package/assets/templates/blocks/components/Table/ColumnsVirtualizationHookUsage.tsx +53 -0
  54. package/assets/templates/blocks/components/Table/InfiniteScrollHookUsage.doc.mjs +14 -0
  55. package/assets/templates/blocks/components/Table/InfiniteScrollHookUsage.tsx +33 -0
  56. package/assets/templates/components.generated.json +1 -1
  57. package/clients/cli/build-id.generated.json +1 -1
  58. package/clients/cli/commands/doctor.doc.mjs +2 -2
  59. package/clients/cli/commands/experimental/theme.mjs +113 -34
  60. package/clients/cli/commands/experimental-theme-compile.doc.mjs +1 -1
  61. package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +1 -1
  62. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +1 -1
  63. package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
  64. package/clients/cli/commands/experimental-theme-eject.doc.mjs +1 -1
  65. package/clients/cli/commands/experimental-theme-template.doc.mjs +1 -1
  66. package/clients/cli/commands/theme-build.doc.mjs +2 -2
  67. package/clients/cli/commands/theme-eject.doc.mjs +1 -1
  68. package/clients/cli/commands/theme-template.doc.mjs +3 -1
  69. package/clients/cli/commands/theme.mjs +85 -5
  70. package/clients/cli/manifest.generated.json +1 -1
  71. package/foundation/config/project.mjs +50 -14
  72. package/foundation/fs/gather-cache.d.mts +9 -2
  73. package/foundation/fs/gather-cache.mjs +36 -10
  74. package/foundation/fs/paths.d.mts +16 -0
  75. package/foundation/fs/paths.mjs +25 -0
  76. package/foundation/response/error-codes.d.mts +2 -1
  77. package/foundation/response/error-codes.d.ts +1 -0
  78. package/foundation/response/error-codes.doc.mjs +5 -0
  79. package/foundation/response/error-codes.mjs +3 -0
  80. package/foundation/response/response-types.doc.mjs +1 -1
  81. package/package.json +7 -6
@@ -51,6 +51,14 @@ export function refuse(code: string, message: string, extra?: {
51
51
  fix?: string;
52
52
  also?: string[];
53
53
  }): never;
54
+ /**
55
+ * A theme name as typed, read the way the editor reads it: a path to its
56
+ * folder or a file in it (t.theme.ts, Brand.settings.json), in any case,
57
+ * names the theme. The result may still need slugFor.
58
+ * @param {unknown} s
59
+ * @returns {string}
60
+ */
61
+ export function typedThemeName(s: unknown): string;
54
62
  /**
55
63
  * The settings of a theme, or a refusal naming the command that makes it.
56
64
  * @param {string} cwd
@@ -178,9 +186,10 @@ export function compileTheme(ctx: Ctx, data: ThemeData, base: {
178
186
  * Settings whose effect a later or stronger setting hides, with why: `type`
179
187
  * loses heading weight and tracking to `headings`.
180
188
  * @param {ThemeData} data
189
+ * @param {Ctx | null} [ctx] with it, a later setting that reaches the parts through a spread counts too
181
190
  * @returns {Map<Setting, string>}
182
191
  */
183
- export function maskedSettings(data: ThemeData): Map<Setting, string>;
192
+ export function maskedSettings(data: ThemeData, ctx?: Ctx | null): Map<Setting, string>;
184
193
  /**
185
194
  * A plain part setting can lose to a more specific rule for the same part
186
195
  * and property, such as a base theme's `.astryx-heading[data-level="1"]
@@ -299,12 +308,38 @@ export function radiusTokenOf(ctx: Ctx, part: string, when?: string): string;
299
308
  export function clearNewMarker(dir: string): void;
300
309
  /**
301
310
  * The pseudo key a state writes in a part's styles. Core marks a disabled
302
- * button, link, tab or menu item with aria-disabled (it stays focusable),
303
- * and its own styles match both forms: so does the theme.
311
+ * button, link or tab with aria-disabled (it stays focusable). A form
312
+ * control styled on a wrapper (a typeahead, a complex selector) has its
313
+ * input or button inside marked, so it also matches a disabled form
314
+ * control inside it (never a list row); an action part that holds
315
+ * children (a button group, a segmented control) never does, so one
316
+ * disabled child never makes the whole part look disabled.
304
317
  * @param {string} state
318
+ * @param {boolean} [wrapsControl]
305
319
  * @returns {string}
306
320
  */
307
- export function stateKey(state: string): string;
321
+ export function stateKey(state: string, wrapsControl?: boolean): string;
322
+ /**
323
+ * The component docs of a part: its own component's, and the one named like
324
+ * the part (tab is Tab, under TabList), each with its name, for the ones the
325
+ * project has.
326
+ * @param {Ctx} ctx
327
+ * @param {string} part
328
+ * @returns {Array<{name: string, doc: any}>}
329
+ */
330
+ export function partComponentDocs(ctx: Ctx, part: string): Array<{
331
+ name: string;
332
+ doc: any;
333
+ }>;
334
+ /**
335
+ * Whether a part's styled element wraps one control: its component (or the
336
+ * one named like the part) is a form control (Core's own category) that
337
+ * takes a disabled prop. An action part that holds children (a button
338
+ * group) never does.
339
+ * @param {Ctx} ctx
340
+ * @param {string} target
341
+ */
342
+ export function wrapsOneControl(ctx: Ctx, target: string): boolean;
308
343
  /**
309
344
  * The whole-theme radius tokens a generated settings module writes, or null
310
345
  * when it writes none.
@@ -400,7 +435,7 @@ export function fontPackages(ctx: Ctx, data: ThemeData): {
400
435
  installed: boolean;
401
436
  of: Setting;
402
437
  }[];
403
- /** @typedef {{project: import('./_project.mjs').ThemeProject, C: import('./_compiler.mjs').Compiler, unchecked?: string | null, uncheckedCode?: string | null, wrote?: Map<string, string | null>, base?: {light: Record<string, string>, dark: Record<string, string>, components?: Record<string, any>}, keepStops?: Record<string, Record<'light' | 'dark', {family: string, stop: number, alpha?: string}>> | null, keepRadii?: Record<string, string> | null}} Ctx */
438
+ /** @typedef {{project: import('./_project.mjs').ThemeProject, C: import('./_compiler.mjs').Compiler, unchecked?: string | null, uncheckedCode?: string | null, wrote?: Map<string, string | null>, base?: {light: Record<string, string>, dark: Record<string, string>, components?: Record<string, any>}, keepStops?: Record<string, Record<'light' | 'dark', {family: string, stop: number, alpha?: string}>> | null, keepRadii?: Record<string, string> | null, derived?: Record<string, Array<{property: string, vars?: string[], replaces?: boolean, expand?: string}>>}} Ctx */
404
439
  /** @typedef {import('./_parts.mjs').PaintSide} PaintSide */
405
440
  /** @typedef {import('./_parts.mjs').TextPair} TextPair */
406
441
  /** What a theme name may be, in words. */
@@ -489,6 +524,12 @@ export type Ctx = {
489
524
  alpha?: string;
490
525
  }>> | null;
491
526
  keepRadii?: Record<string, string> | null;
527
+ derived?: Record<string, Array<{
528
+ property: string;
529
+ vars?: string[];
530
+ replaces?: boolean;
531
+ expand?: string;
532
+ }>>;
492
533
  };
493
534
  export type PaintSide = import("./_parts.mjs").PaintSide;
494
535
  export type TextPair = import("./_parts.mjs").TextPair;
@@ -15,6 +15,7 @@ import * as fs from 'node:fs';
15
15
  import postcss from 'postcss';
16
16
  import {createRequire} from 'node:module';
17
17
  import * as path from 'node:path';
18
+ import {themeFileImports} from '../../foundation/discovery/theme-discovery.mjs';
18
19
  import {pathToFileURL} from 'node:url';
19
20
  import {cliVersion} from '../../foundation/release/run-context.mjs';
20
21
  import {AstryxError} from '../error.mjs';
@@ -97,7 +98,7 @@ import {quoteCommandArgument} from '../../foundation/env/package-manager.mjs';
97
98
  /** What lifted secondary text sits on: the contrast check measures it there. */
98
99
  const LIFT_GROUND_TOKENS = new Set(LIFT_PARTS.map(([, , g]) => g));
99
100
 
100
- /** @typedef {{project: import('./_project.mjs').ThemeProject, C: import('./_compiler.mjs').Compiler, unchecked?: string | null, uncheckedCode?: string | null, wrote?: Map<string, string | null>, base?: {light: Record<string, string>, dark: Record<string, string>, components?: Record<string, any>}, keepStops?: Record<string, Record<'light' | 'dark', {family: string, stop: number, alpha?: string}>> | null, keepRadii?: Record<string, string> | null}} Ctx */
101
+ /** @typedef {{project: import('./_project.mjs').ThemeProject, C: import('./_compiler.mjs').Compiler, unchecked?: string | null, uncheckedCode?: string | null, wrote?: Map<string, string | null>, base?: {light: Record<string, string>, dark: Record<string, string>, components?: Record<string, any>}, keepStops?: Record<string, Record<'light' | 'dark', {family: string, stop: number, alpha?: string}>> | null, keepRadii?: Record<string, string> | null, derived?: Record<string, Array<{property: string, vars?: string[], replaces?: boolean, expand?: string}>>}} Ctx */
101
102
  /** @typedef {import('./_parts.mjs').PaintSide} PaintSide */
102
103
  /** @typedef {import('./_parts.mjs').TextPair} TextPair */
103
104
 
@@ -259,6 +260,25 @@ export function refuse(code, message, extra = {}) {
259
260
  throw new AstryxError(`${message} ${tail}`, suggestions, code);
260
261
  }
261
262
 
263
+ /**
264
+ * A theme name as typed, read the way the editor reads it: a path to its
265
+ * folder or a file in it (t.theme.ts, Brand.settings.json), in any case,
266
+ * names the theme. The result may still need slugFor.
267
+ * @param {unknown} s
268
+ * @returns {string}
269
+ */
270
+ export function typedThemeName(s) {
271
+ return String(s ?? '')
272
+ .trim()
273
+ .toLowerCase()
274
+ .replace(/^.*themes[\\/]/, '')
275
+ .replace(/[\\/].*$/, '')
276
+ .replace(
277
+ /\.(theme\.ts|settings\.(json|ts)|history\.json|css\.d\.ts|d\.ts|css|js|ts)$/,
278
+ '',
279
+ );
280
+ }
281
+
262
282
  /**
263
283
  * The settings of a theme, or a refusal naming the command that makes it.
264
284
  * @param {string} cwd
@@ -277,15 +297,7 @@ export function loadTheme(
277
297
  // A path or a capital letter typed for a theme that exists names it.
278
298
  // A file name typed for the theme (t.theme.ts, Brand.settings.json)
279
299
  // names the theme.
280
- const plain = String(slug ?? '')
281
- .trim()
282
- .toLowerCase()
283
- .replace(/^.*themes[\\/]/, '')
284
- .replace(/[\\/].*$/, '')
285
- .replace(
286
- /\.(theme\.ts|settings\.(json|ts)|history\.json|css\.d\.ts|d\.ts|css|js|ts)$/,
287
- '',
288
- );
300
+ const plain = typedThemeName(slug);
289
301
  const fixed = slugFor(plain);
290
302
  const same = fs.existsSync(themeFiles(cwd, fixed).settings) ? fixed : null;
291
303
  // A list where one theme goes (t,u or "t;u"): one theme at a time,
@@ -348,7 +360,7 @@ export function loadTheme(
348
360
  ERROR_CODES.ERR_UNKNOWN_THEME,
349
361
  stopped
350
362
  ? `themes/${slug} was left by a \`new\` that was stopped part way, so it has no settings yet. Run new again to finish it; files you added there are kept.`
351
- : `themes/${slug} has lost its settings (${slug}.settings.json is gone), but the editor made it. Run new to make it again: your own files there are kept${fs.existsSync(f.history) ? `, and \`undo ${slug}\` then steps back to the earlier settings` : ''}.`,
363
+ : `themes/${slug} has lost its settings (${slug}.settings.json is gone), but the editor made it. Run new to make it again: your own files there are kept${fs.existsSync(f.history) ? `, and \`undo ${slug}\` then steps back to the settings from before the last change (the last change itself is not kept)` : ''}.`,
352
364
  {run: [`${P} new ${slug}`]},
353
365
  );
354
366
  if (!same && (other || LIKE.includes(slug)))
@@ -723,7 +735,11 @@ export {modesOf};
723
735
  * @returns {number | null}
724
736
  */
725
737
  export function lengthPx(v) {
726
- const m = /^\s*(-?\d+(?:\.\d+)?|-?\.\d+)\s*(px|rem|em)?\s*$/i.exec(String(v));
738
+ // A CSS number: a sign, digits with or without a fraction, an exponent.
739
+ const m =
740
+ /^\s*([+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?)\s*(px|rem|em)?\s*$/i.exec(
741
+ String(v),
742
+ );
727
743
  if (!m) return null;
728
744
  const n = Number(m[1]);
729
745
  return (m[2] ?? 'px').toLowerCase() === 'px' ? n : n * 16;
@@ -1000,7 +1016,7 @@ export function compileTheme(ctx, data, base) {
1000
1016
  if (tg?.states.includes(s.state) && s.when == null) b = t[s.state] ??= {};
1001
1017
  else if (tg?.states.includes(s.state))
1002
1018
  b = t[`${s.when}+${s.state}`] ??= {};
1003
- else b = b[stateKey(s.state)] ??= {};
1019
+ else b = b[stateKey(s.state, wrapsOneControl(ctx, target))] ??= {};
1004
1020
  }
1005
1021
  return b;
1006
1022
  };
@@ -1367,9 +1383,10 @@ const SMALL_STEPS = /** @type {Array<[string, number]>} */ ([
1367
1383
  * Settings whose effect a later or stronger setting hides, with why: `type`
1368
1384
  * loses heading weight and tracking to `headings`.
1369
1385
  * @param {ThemeData} data
1386
+ * @param {Ctx | null} [ctx] with it, a later setting that reaches the parts through a spread counts too
1370
1387
  * @returns {Map<Setting, string>}
1371
1388
  */
1372
- export function maskedSettings(data) {
1389
+ export function maskedSettings(data, ctx = null) {
1373
1390
  /** @type {Map<Setting, string>} */
1374
1391
  const out = new Map();
1375
1392
  const axes = new Set(
@@ -1409,6 +1426,37 @@ export function maskedSettings(data) {
1409
1426
  `${describe(later)} comes later and covers ${s.on}, so ${s.on} shows ${later.value}; set ${s.on} again to make it win`,
1410
1427
  );
1411
1428
  });
1429
+ // With the parts known: a later setting of the same thing that reaches
1430
+ // every part an earlier one styles (a member that spreads to its group,
1431
+ // the same part without --only), dial or CSS property, covers it too.
1432
+ if (ctx)
1433
+ data.settings.forEach((s, i) => {
1434
+ if (
1435
+ out.has(s) ||
1436
+ !s.on ||
1437
+ (s.source !== 'dial' && s.source !== 'property')
1438
+ )
1439
+ return;
1440
+ const mine = partsOf(ctx, s);
1441
+ if (!mine.length) return;
1442
+ const later = data.settings
1443
+ .slice(i + 1)
1444
+ .find(
1445
+ x =>
1446
+ x.thing === s.thing &&
1447
+ x.source === s.source &&
1448
+ x.on &&
1449
+ (x.when ?? '') === (s.when ?? '') &&
1450
+ (x.state ?? '') === (s.state ?? '') &&
1451
+ (x.mode ?? '') === (s.mode ?? '') &&
1452
+ mine.every(t => partsOf(ctx, x).includes(t)),
1453
+ );
1454
+ if (later)
1455
+ out.set(
1456
+ s,
1457
+ `${describe(later)} comes later and covers ${s.on}, so ${s.on} shows ${later.value}; set ${s.on} again to make it win`,
1458
+ );
1459
+ });
1412
1460
  for (const s of data.settings) {
1413
1461
  if (s.thing !== 'type' || !axes.size) continue;
1414
1462
  const T = TYPE_STYLES[s.value];
@@ -1592,6 +1640,12 @@ function settingsSource(slug, data, theme, pal, cwd = '') {
1592
1640
  [
1593
1641
  `// Generated by \`${P}\` from ${slug}.settings.json on every change: do not edit.`,
1594
1642
  `// Built from settings ${settingsStamp(data)}.`,
1643
+ // The theme source as it is when the build starts (the editor's
1644
+ // own when the build writes it), so an own change to it after the
1645
+ // build is told by content.
1646
+ ...(cwd
1647
+ ? [`// Built with ${slug}.theme.ts ${themeSourceHash(cwd, slug)}.`]
1648
+ : []),
1595
1649
  ...(like && cwd
1596
1650
  ? [
1597
1651
  `// Built on @astryxdesign/theme-${like} ${baseVersionOf(cwd, like) ?? 'unknown'}.`,
@@ -1615,6 +1669,67 @@ function settingsSource(slug, data, theme, pal, cwd = '') {
1615
1669
  );
1616
1670
  }
1617
1671
 
1672
+ /**
1673
+ * A hash of a theme's source file as the next build reads it: the file, or
1674
+ * the source the editor writes when there is none.
1675
+ * @param {string} cwd
1676
+ * @param {string} slug
1677
+ */
1678
+ function themeSourceHash(cwd, slug) {
1679
+ const f = themeFiles(cwd, slug);
1680
+ const hash = createHash('sha256');
1681
+ if (!fs.existsSync(f.ts)) {
1682
+ // The same as the file the build is about to write would hash.
1683
+ hash.update(`${path.basename(f.ts)}\0`);
1684
+ hash.update(themeModuleSource(slug));
1685
+ return hash.digest('hex').slice(0, 16);
1686
+ }
1687
+ // The theme source and every local module it reaches (an own helper
1688
+ // such as ./my-tokens), read the way theme discovery reads them; the
1689
+ // editor's generated modules change with each build and are judged by
1690
+ // their own stamps.
1691
+ const generated = new Set([f.settingsTs]);
1692
+ const seen = new Set();
1693
+ const queue = [f.ts];
1694
+ while (queue.length) {
1695
+ const file = /** @type {string} */ (queue.shift());
1696
+ if (seen.has(file)) continue;
1697
+ seen.add(file);
1698
+ hash.update(`${path.relative(f.dir, file)}\0`);
1699
+ hash.update(fs.readFileSync(file));
1700
+ /** @type {string[]} */
1701
+ let specifiers = [];
1702
+ try {
1703
+ specifiers = themeFileImports(file);
1704
+ } catch {
1705
+ // A file that does not parse is hashed as it is; the build names it.
1706
+ }
1707
+ for (const spec of specifiers) {
1708
+ if (!spec.startsWith('.')) continue;
1709
+ const base = path.resolve(path.dirname(file), spec);
1710
+ const target = [
1711
+ '',
1712
+ '.ts',
1713
+ '.tsx',
1714
+ '.mts',
1715
+ '.js',
1716
+ '.mjs',
1717
+ '/index.ts',
1718
+ '/index.js',
1719
+ ]
1720
+ .map(x => base + x)
1721
+ .find(p => fs.existsSync(p) && fs.statSync(p).isFile());
1722
+ if (
1723
+ target &&
1724
+ !generated.has(target) &&
1725
+ !path.relative(path.join(f.dir, 'tokens'), target).match(/^[^.]/)
1726
+ )
1727
+ queue.push(target);
1728
+ }
1729
+ }
1730
+ return hash.digest('hex').slice(0, 16);
1731
+ }
1732
+
1618
1733
  /**
1619
1734
  * The theme module, written once: it extends the generated settings and is
1620
1735
  * the person's own from then on, so hand edits in it survive every change.
@@ -1855,10 +1970,35 @@ export async function resolvedTokens(ctx, slug) {
1855
1970
  v => v && typeof v === 'object' && typeof v.name === 'string',
1856
1971
  );
1857
1972
  const {core} = ctx.project;
1858
- const out = {
1859
- light: core.resolveThemeTokens(t, {mode: 'light'}),
1860
- dark: core.resolveThemeTokens(t, {mode: 'dark'}),
1973
+ // A token value an own theme source gives as a number (8 for 8px)
1974
+ // reads as its text, never as a crash.
1975
+ const asText = (/** @type {Record<string, unknown>} */ m) =>
1976
+ Object.fromEntries(
1977
+ Object.entries(m ?? {}).map(([k, v]) => [
1978
+ k,
1979
+ typeof v === 'string' ? v : String(v),
1980
+ ]),
1981
+ );
1982
+ // A token value that is not text (a number in an own theme source) is
1983
+ // named, never a crash.
1984
+ const resolve = (/** @type {'light' | 'dark'} */ mode) => {
1985
+ try {
1986
+ return asText(core.resolveThemeTokens(t, {mode}));
1987
+ } catch (e) {
1988
+ const bad = Object.entries(/** @type {any} */ (t)?.tokens ?? {}).find(
1989
+ ([, v]) =>
1990
+ typeof v !== 'string' && (typeof v !== 'object' || v == null),
1991
+ );
1992
+ throw new AstryxError(
1993
+ bad
1994
+ ? `${slug}.theme.ts gives ${bad[0]} the value ${JSON.stringify(bad[1])}, which is not text: a token value is a CSS value in quotes (such as '${bad[1]}px').`
1995
+ : `${slug} could not be read: ${e instanceof Error ? e.message : String(e)}.`,
1996
+ [{name: `${P} how --list tokens`, reason: 'every token and its type'}],
1997
+ ERROR_CODES.ERR_THEME_INVALID,
1998
+ );
1999
+ }
1861
2000
  };
2001
+ const out = {light: resolve('light'), dark: resolve('dark')};
1862
2002
  // The tokens each part sets for itself (the official themes lift
1863
2003
  // secondary text on some parts), for the contrast check; kept out of the
1864
2004
  // modes so nothing that lists the resolved tokens sees it.
@@ -2050,7 +2190,7 @@ export async function contrastProblems(ctx, data, res) {
2050
2190
  })(),
2051
2191
  ...(unchecked.length
2052
2192
  ? [
2053
- `not checked: text on or in ${unchecked.slice(0, 3).join(', ')}${unchecked.length > 3 ? ` and ${unchecked.length - 3} more` : ''}, which ${unchecked.length === 1 ? 'is' : 'are'} not a fixed color`,
2193
+ `not checked: text on or in ${unchecked.slice(0, 3).join(', ')}${unchecked.length > 3 ? ` and ${unchecked.length - 3} more` : ''}, which the editor cannot read as one fixed color`,
2054
2194
  ]
2055
2195
  : []),
2056
2196
  ];
@@ -2118,7 +2258,9 @@ export function baseComponent(base, ctx, target, prop, s) {
2118
2258
  const states = ctx.project.target.get(target)?.states ?? [];
2119
2259
  b = states.includes(s.state)
2120
2260
  ? t[s.when == null ? s.state : `${s.when}+${s.state}`]
2121
- : (b?.[stateKey(s.state)] ?? b?.[`:${s.state}`]);
2261
+ : (b?.[stateKey(s.state, wrapsOneControl(ctx, target))] ??
2262
+ b?.[stateKey(s.state)] ??
2263
+ b?.[`:${s.state}`]);
2122
2264
  }
2123
2265
  const v = b?.[prop];
2124
2266
  return typeof v === 'string' ? v : null;
@@ -2184,15 +2326,60 @@ export function clearNewMarker(dir) {
2184
2326
 
2185
2327
  /**
2186
2328
  * The pseudo key a state writes in a part's styles. Core marks a disabled
2187
- * button, link, tab or menu item with aria-disabled (it stays focusable),
2188
- * and its own styles match both forms: so does the theme.
2329
+ * button, link or tab with aria-disabled (it stays focusable). A form
2330
+ * control styled on a wrapper (a typeahead, a complex selector) has its
2331
+ * input or button inside marked, so it also matches a disabled form
2332
+ * control inside it (never a list row); an action part that holds
2333
+ * children (a button group, a segmented control) never does, so one
2334
+ * disabled child never makes the whole part look disabled.
2189
2335
  * @param {string} state
2336
+ * @param {boolean} [wrapsControl]
2190
2337
  * @returns {string}
2191
2338
  */
2192
- export function stateKey(state) {
2193
- return state === 'disabled'
2194
- ? ':is(:disabled,[aria-disabled="true"])'
2195
- : `:${state}`;
2339
+ export function stateKey(state, wrapsControl = false) {
2340
+ if (state !== 'disabled') return `:${state}`;
2341
+ return wrapsControl
2342
+ ? ':is(:disabled,[aria-disabled="true"],:has(:is(input,button,select,textarea):is(:disabled,[aria-disabled="true"])))'
2343
+ : ':is(:disabled,[aria-disabled="true"])';
2344
+ }
2345
+
2346
+ /**
2347
+ * The component docs of a part: its own component's, and the one named like
2348
+ * the part (tab is Tab, under TabList), each with its name, for the ones the
2349
+ * project has.
2350
+ * @param {Ctx} ctx
2351
+ * @param {string} part
2352
+ * @returns {Array<{name: string, doc: any}>}
2353
+ */
2354
+ export function partComponentDocs(ctx, part) {
2355
+ const comps = /** @type {Record<string, any>} */ (
2356
+ ctx.project.components ?? {}
2357
+ );
2358
+ const pascal = part.replace(/(^|-)([a-z0-9])/g, (_, __, c) =>
2359
+ c.toUpperCase(),
2360
+ );
2361
+ return [ctx.project.target.get(part)?.component, pascal]
2362
+ .filter(n => n != null && comps[n])
2363
+ .map(n => ({
2364
+ name: /** @type {string} */ (n),
2365
+ doc: comps[/** @type {string} */ (n)],
2366
+ }));
2367
+ }
2368
+
2369
+ /**
2370
+ * Whether a part's styled element wraps one control: its component (or the
2371
+ * one named like the part) is a form control (Core's own category) that
2372
+ * takes a disabled prop. An action part that holds children (a button
2373
+ * group) never does.
2374
+ * @param {Ctx} ctx
2375
+ * @param {string} target
2376
+ */
2377
+ export function wrapsOneControl(ctx, target) {
2378
+ return partComponentDocs(ctx, target).some(
2379
+ ({doc: d}) =>
2380
+ /form/i.test(String(d.category ?? '')) &&
2381
+ Object.keys(d.props ?? {}).some(p => /disabled/i.test(p)),
2382
+ );
2196
2383
  }
2197
2384
 
2198
2385
  /**
@@ -2510,6 +2697,11 @@ export function staleBuild(cwd, slug, data) {
2510
2697
  if (built && now && built !== now)
2511
2698
  return `@astryxdesign/theme-${data.like} is ${now} now, and the build was made on ${built}`;
2512
2699
  }
2700
+ // An own change to <slug>.theme.ts since the build (the file says it
2701
+ // wins over the settings) is built in.
2702
+ const source = /\/\/ Built with \S+\.theme\.ts ([0-9a-f]{16})\./.exec(ts);
2703
+ if (source && fs.existsSync(f.ts) && source[1] !== themeSourceHash(cwd, slug))
2704
+ return `${slug}.theme.ts or a module it imports changed since the last build`;
2513
2705
  // By content, never by file times (an editor's re-save or a checkout
2514
2706
  // changes those): a generated module cut short, or built outputs whose
2515
2707
  // header names another CLI than the settings were written by (a build
@@ -441,7 +441,7 @@ export type ThemeEditPreviewListOptions = {
441
441
  export type ThemeEditPreviewListResponse = {
442
442
  type: "themeEdit.previewList";
443
443
  /**
444
- * - `themeMissing`: the theme the preview wears is gone, so its route does not build; `notes`: what else to know, such as the command that switches it.
444
+ * - `themeMissing`: the theme the preview wears is gone, so its route does not build; a page's `missing`: its file is gone; `notes`: what else to know, such as the command that fixes it.
445
445
  */
446
446
  data: {
447
447
  folder: string | null;
@@ -450,6 +450,7 @@ export type ThemeEditPreviewListResponse = {
450
450
  pages: Array<{
451
451
  id: string;
452
452
  label: string;
453
+ missing?: boolean;
453
454
  }>;
454
455
  notes: string[];
455
456
  };
@@ -227,7 +227,7 @@
227
227
  * @experimental May change or be removed in a patch release.
228
228
  * @typedef {object} ThemeEditPreviewListResponse
229
229
  * @property {'themeEdit.previewList'} type
230
- * @property {{folder: string | null, theme: string | null, themeMissing: boolean, pages: Array<{id: string, label: string}>, notes: string[]}} data - `themeMissing`: the theme the preview wears is gone, so its route does not build; `notes`: what else to know, such as the command that switches it.
230
+ * @property {{folder: string | null, theme: string | null, themeMissing: boolean, pages: Array<{id: string, label: string, missing?: boolean}>, notes: string[]}} data - `themeMissing`: the theme the preview wears is gone, so its route does not build; a page's `missing`: its file is gone; `notes`: what else to know, such as the command that fixes it.
231
231
  */
232
232
 
233
233
  /**
@@ -12,7 +12,7 @@ export const doc = {
12
12
  displayName: 'themeEditNew()',
13
13
  summary: 'Start a theme in themes/<theme>/, optionally on a built-in theme.',
14
14
  description:
15
- 'Makes themes/<theme>/ with <theme>.settings.json (the settings this command owns), the generated <theme>.settings.ts, <theme>.theme.ts (which extends it and is yours), and the built <theme>.css and <theme>.js (the same build as `astryx theme build`), then writes preview.html, the sample app page with the theme. --like builds on a built-in theme (neutral, stone, matcha, y2k, gothic, chocolate, butter; its package must be installed); without it the theme starts from Astryx defaults. `settings` takes any `set` dial by name ({accent: "#7c3aed", font: "inter", corners: "round", vibrancy: "60"}): the same names, values and checks as `set`, all applied in the one build, with one result that lists them. Change the base later with `astryx experimental theme editor set <theme> base <theme|none>`. Afterwards, <theme>.theme.ts is yours: it extends the generated <theme>.settings.ts, and every later change rewrites only the settings files, so your own edits in <theme>.theme.ts survive. A theme name is lowercase letters, digits and dashes. Experimental: it may change or be removed in a patch release.',
15
+ 'Makes themes/<theme>/ with <theme>.settings.json (the settings this command owns), the generated <theme>.settings.ts, <theme>.theme.ts (which extends it and is yours), and the built <theme>.css and <theme>.js (build them again with `astryx experimental theme compile themes/<theme>/<theme>.theme.ts`, which checks the editor settings first), then writes preview.html, the sample app page with the theme. --like builds on a built-in theme (neutral, stone, matcha, y2k, gothic, chocolate, butter; its package must be installed); without it the theme starts from Astryx defaults. `settings` takes any `set` dial by name ({accent: "#7c3aed", font: "inter", corners: "round", vibrancy: "60"}): the same names, values and checks as `set`, all applied in the one build, with one result that lists them. Change the base later with `astryx experimental theme editor set <theme> base <theme|none>`. Afterwards, <theme>.theme.ts is yours: it extends the generated <theme>.settings.ts, and every later change rewrites only the settings files, so your own edits in <theme>.theme.ts survive. A theme name is lowercase letters, digits and dashes. Experimental: it may change or be removed in a patch release.',
16
16
  importPath: '@astryxdesign/cli/api/experimental',
17
17
  signature: 'themeEditNew(theme: string, options?: object): Promise<object>',
18
18
  keywords: [
@@ -13,7 +13,7 @@ export const doc = {
13
13
  summary:
14
14
  'Every setting, key values, problems the theme caused, and the theme-building page with every component.',
15
15
  description:
16
- 'Lists every setting with where it applies and its source (dial, token or property), the resolved value of key tokens in each mode, the colors (the vibrancy; each color with its seed and the shade each token uses in light and dark, marked when an exact token setting wins; any shade moved so text reads), contrast problems this theme caused versus its base, font notes, and last the generated color files. Writes two self-contained HTML files: preview.html (the sample app page) and sheet.html (the theme-building page: every component grouped, each variant side by side, overlays open, and real template pages, with an auto/light/dark switch). A theme with no build is built first, and an in-app preview (`preview add`) of the theme has its route and Colors page rewritten. --section limits the sheet to one section. Experimental: it may change or be removed in a patch release.',
16
+ 'Lists every setting with where it applies and its source (dial, token or property), the resolved value of key tokens in each mode, the colors (the vibrancy; each color with its seed and the shade each token uses in light and dark, marked when an exact token setting wins; any shade moved so text reads), contrast problems this theme caused versus its base, font notes, and last the generated color files. Writes two self-contained HTML files: preview.html (the sample app page) and sheet.html (the theme-building page: every component grouped, each variant side by side, overlays open, and real template pages, with an auto/light/dark switch). A theme with no build is built first, and an in-app preview (`preview add`) of the theme has its route and Colors page rewritten. --section limits the sheet to one section. An own change to <theme>.theme.ts since the last build is built first, and the colors mark where it wins over a generated shade; a theme source that no longer builds, or a token in it that is not text, is refused (ERR_THEME_INVALID, exit 1) and the folder stays as it was. Experimental: it may change or be removed in a patch release.',
17
17
  importPath: '@astryxdesign/cli/api/experimental',
18
18
  signature: 'themeEditShow(theme: string, options?: object): Promise<object>',
19
19
  keywords: [
@@ -2,7 +2,8 @@
2
2
 
3
3
  /**
4
4
  * @file `astryx docs styling/tokens-and-setup`: using design tokens in custom
5
- * styles and configuring a StyleX compiler for swizzled components.
5
+ * styles, configuring a StyleX compiler for swizzled components, and keeping
6
+ * Next.js webpack builds small.
6
7
  */
7
8
 
8
9
  /** @type {import('@astryxdesign/cli/authoring').ReferenceDoc} */
@@ -14,8 +15,16 @@ export const docs = {
14
15
  placement: {parent: 'namespace:styling', slot: 'guides', order: 30},
15
16
  category: 'guide',
16
17
  description:
17
- 'Using design tokens in custom styles and configuring a StyleX compiler for swizzled components.',
18
- keywords: ['StyleX setup', 'swizzle', 'webpack', 'Vite', 'Next.js'],
18
+ 'Using design tokens in custom styles, configuring a StyleX compiler for swizzled components, and keeping Next.js webpack builds small.',
19
+ keywords: [
20
+ 'StyleX setup',
21
+ 'swizzle',
22
+ 'webpack',
23
+ 'Vite',
24
+ 'Next.js',
25
+ 'optimizePackageImports',
26
+ 'Server Components',
27
+ ],
19
28
 
20
29
  sections: [
21
30
  {
@@ -129,5 +138,32 @@ export default stylexPlugin({
129
138
  },
130
139
  ],
131
140
  },
141
+ {
142
+ id: 'nextjs-webpack',
143
+ title: 'Next.js with webpack',
144
+ content: [
145
+ {
146
+ type: 'prose',
147
+ text: 'If your Next.js app builds with webpack (`next build --webpack`), add `@astryxdesign/core` to `experimental.optimizePackageImports`. With webpack, a Server Component that imports from the package root would otherwise ship every client component; this keeps first load to what the page uses. Turbopack, the default bundler in Next.js 16, needs no change, and the setting is safe to keep there.',
148
+ },
149
+ {
150
+ type: 'code',
151
+ lang: 'js',
152
+ label: 'next.config.mjs',
153
+ code: `/** @type {import('next').NextConfig} */
154
+ const nextConfig = {
155
+ experimental: {
156
+ optimizePackageImports: ['@astryxdesign/core'],
157
+ },
158
+ };
159
+
160
+ export default nextConfig;`,
161
+ },
162
+ {
163
+ type: 'prose',
164
+ text: "In Server Components, also import each component from its own entry, for example `import {Button} from '@astryxdesign/core/Button'`. `{@command component <Name>}` prints that entry. Files that start with `'use client'` are not affected.",
165
+ },
166
+ ],
167
+ },
132
168
  ],
133
169
  };