@astryxdesign/cli 0.6.6-canary.c4df65c → 0.6.6-canary.cc0df20

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 (32) hide show
  1. package/api/theme/build/build.d.mts +70 -0
  2. package/api/theme/build/build.mjs +205 -43
  3. package/api/theme/build/font-warning.d.mts +11 -0
  4. package/api/theme/build/font-warning.mjs +28 -3
  5. package/assets/docs/author-a-theme.doc.mjs +12 -7
  6. package/assets/docs/theme.doc.zh.mjs +1 -1
  7. package/assets/docs/tree/layout.doc.mjs +20 -0
  8. package/assets/docs/use-a-theme.doc.mjs +6 -3
  9. package/assets/templates/pages/incident-console/page.tsx +1 -1
  10. package/clients/cli/commands/blog.mjs +3 -3
  11. package/clients/cli/commands/build-theme.adaptations.test.mjs +1 -1
  12. package/clients/cli/commands/build-theme.ascii-output.test.mjs +11 -1
  13. package/clients/cli/commands/build-theme.batch-report.test.mjs +335 -0
  14. package/clients/cli/commands/build-theme.font-warning.test.mjs +36 -7
  15. package/clients/cli/commands/build-theme.import-path.test.mjs +3 -3
  16. package/clients/cli/commands/build-theme.mjs +64 -16
  17. package/clients/cli/commands/build-theme.watch.test.mjs +33 -0
  18. package/clients/cli/commands/docs.test.mjs +2 -1
  19. package/clients/cli/commands/doctor.test.mjs +17 -1
  20. package/clients/cli/commands/import-hint-correctness.test.mjs +23 -0
  21. package/clients/cli/commands/search.test.mjs +6 -2
  22. package/clients/cli/commands/swizzle.routing.test.mjs +2 -1
  23. package/clients/cli/commands/template.mjs +2 -2
  24. package/clients/cli/commands/theme-add-lifecycle.test.mjs +9 -6
  25. package/clients/cli/commands/theme-build.doc.mjs +3 -1
  26. package/clients/cli/commands/upgrade.config-ordering.test.mjs +2 -1
  27. package/clients/cli/index.mjs +1 -1
  28. package/clients/cli/lib/component-format.test.mjs +1 -1
  29. package/foundation/env/package-manager.d.mts +28 -8
  30. package/foundation/env/package-manager.mjs +49 -10
  31. package/foundation/env/package-manager.test.mjs +93 -1
  32. package/package.json +9 -9
@@ -71,6 +71,46 @@ export function validateComponentOverridesAgainstRegistry(themeDef: {
71
71
  propsByKey: Record<string, string[]>;
72
72
  deprecatedByKey: Record<string, string>;
73
73
  }): string[];
74
+ /**
75
+ * Print the install snippet and font guidance once for a batch: the first
76
+ * theme as the full example, one import line per built theme, and one font
77
+ * recipe naming every family the themes do not load.
78
+ * @param {ThemeBuildTrailer[]} trailers
79
+ */
80
+ export function printBatchTrailer(trailers: ThemeBuildTrailer[]): void;
81
+ /**
82
+ * Print what a short report keeps after its one line per theme: one line
83
+ * naming the fonts the themes do not load, and, when the caller chose no
84
+ * detail level, where the install example and font recipe are.
85
+ * @param {ThemeBuildTrailer[]} trailers
86
+ * @param {{hint?: boolean}} [options]
87
+ */
88
+ export function printCompactTrailer(trailers: ThemeBuildTrailer[], { hint }?: {
89
+ hint?: boolean;
90
+ }): void;
91
+ /**
92
+ * Build one theme for a batch or compact CLI report. Same build, outputs, and
93
+ * receipt as {@link themeBuild}; the install snippet and font guidance come
94
+ * back as `trailer` instead of being printed, and `compact` leaves out the
95
+ * per-file progress lines. CLI-internal: not exported from the API entry.
96
+ * @param {string} file
97
+ * @param {{out?: string, check?: boolean, iconsSpecifier?: string}} [options]
98
+ * @param {{cwd?: string}} [ctx]
99
+ * @param {{compact?: boolean}} [report]
100
+ * @returns {Promise<{receipt: import('../theme.type.mjs').ThemeBuildResponse | import('../theme.type.mjs').ThemeBuildCheckResponse | null, trailer: ThemeBuildTrailer | null}>}
101
+ */
102
+ export function themeBuildForReport(file: string, options?: {
103
+ out?: string;
104
+ check?: boolean;
105
+ iconsSpecifier?: string;
106
+ }, ctx?: {
107
+ cwd?: string;
108
+ }, { compact }?: {
109
+ compact?: boolean;
110
+ }): Promise<{
111
+ receipt: import("../theme.type.mjs").ThemeBuildResponse | import("../theme.type.mjs").ThemeBuildCheckResponse | null;
112
+ trailer: ThemeBuildTrailer | null;
113
+ }>;
74
114
  /** @param {string} file @param {{out?: string, check?: boolean, iconsSpecifier?: string}} [options] @param {{cwd?: string}} [ctx] @returns {Promise<import('../theme.type.mjs').ThemeBuildResponse | import('../theme.type.mjs').ThemeBuildCheckResponse | null>} */
75
115
  export function themeBuild(file: string, options?: {
76
116
  out?: string;
@@ -140,6 +180,36 @@ export function themeBuildFamily(files: string[], options: {
140
180
  * validateAdaptationEnrollment)
141
181
  */
142
182
  export type ComponentValueClass = "builtin" | "enrollment" | "unresolved";
183
+ /**
184
+ * What a standalone build prints after its [ok] lines, kept as data so a
185
+ * batch can print it once for every theme.
186
+ */
187
+ export type ThemeBuildTrailer = {
188
+ /**
189
+ * The theme's name.
190
+ */
191
+ themeName: string;
192
+ /**
193
+ * The built module's theme export.
194
+ */
195
+ exportName: string;
196
+ /**
197
+ * Import specifier of the built JS module.
198
+ */
199
+ jsImport: string;
200
+ /**
201
+ * Import specifier of the built CSS.
202
+ */
203
+ cssImport: string;
204
+ /**
205
+ * Font families the theme names but does not load.
206
+ */
207
+ unloadedFonts: string[];
208
+ /**
209
+ * One notice per unloaded font family.
210
+ */
211
+ fontNotices: string[];
212
+ };
143
213
  /**
144
214
  * The bindings one Core provides: the namespaces interception spreads, the
145
215
  * functions the build calls, and why the import failed, if it did.
@@ -74,7 +74,11 @@ import {
74
74
  collectThemingTargets,
75
75
  targetValidationRegistry,
76
76
  } from '../../../foundation/discovery/theming-targets.mjs';
77
- import {collectUnloadedFonts, formatFontLoadingHelp} from './font-warning.mjs';
77
+ import {
78
+ collectUnloadedFonts,
79
+ formatBatchFontLoadingHelp,
80
+ formatFontLoadingHelp,
81
+ } from './font-warning.mjs';
78
82
  import {interceptCore} from './core-interception.mjs';
79
83
  import {generateFamilyCSS, resolveThemeFamily} from './family.mjs';
80
84
  import {resolveIconImports} from './icon-imports.mjs';
@@ -2339,6 +2343,7 @@ async function themeBuildInternal(
2339
2343
  file,
2340
2344
  options = {},
2341
2345
  {cwd = process.cwd()} = {},
2346
+ /** @type {{compact?: boolean, trailers?: ThemeBuildTrailer[]}} */ report = {},
2342
2347
  ) {
2343
2348
  const filePath = path.resolve(cwd, file);
2344
2349
 
@@ -2350,7 +2355,11 @@ async function themeBuildInternal(
2350
2355
  );
2351
2356
  }
2352
2357
 
2353
- logger.log(`\nBuilding theme from ${path.relative(cwd, filePath)}...`);
2358
+ if (!report.compact) {
2359
+ logger.log(`\nBuilding theme from ${path.relative(cwd, filePath)}...`);
2360
+ }
2361
+ // A compact report has no per-theme heading, so each warning names its file.
2362
+ const source = report.compact ? `${path.relative(cwd, filePath)}: ` : '';
2354
2363
 
2355
2364
  await selectCore(cwd);
2356
2365
 
@@ -2469,18 +2478,18 @@ async function themeBuildInternal(
2469
2478
  const noticeMessages = [];
2470
2479
  for (const w of warnings) {
2471
2480
  warningMessages.push(w);
2472
- logger.warn(` [warn] ${w}`);
2481
+ logger.warn(` [warn] ${source}${w}`);
2473
2482
  }
2474
2483
 
2475
2484
  // Validate no private vars are set directly
2476
2485
  const privateVarErrors = validatePrivateVars(themeDef);
2477
2486
  for (const e of privateVarErrors) {
2478
2487
  warningMessages.push(e);
2479
- logger.error(` [error] ${e}`);
2488
+ logger.error(` [error] ${source}${e}`);
2480
2489
  }
2481
2490
  if (privateVarErrors.length > 0) {
2482
2491
  logger.error(
2483
- `\n ${privateVarErrors.length} private var error(s). Use standard CSS properties instead.`,
2492
+ `\n ${source}${privateVarErrors.length} private var error(s). Use standard CSS properties instead.`,
2484
2493
  );
2485
2494
  }
2486
2495
 
@@ -2719,7 +2728,7 @@ async function themeBuildInternal(
2719
2728
  for (const message of droppedDeclarations) {
2720
2729
  const w = `Declaration ${message}. The generated CSS omits it; fix the value in the theme source.`;
2721
2730
  warningMessages.push(w);
2722
- logger.warn(` [warn] ${w}`);
2731
+ logger.warn(` [warn] ${source}${w}`);
2723
2732
  }
2724
2733
  const unemittedHeadingTypes = headingTypesWithoutEmittedRule(
2725
2734
  customHeadingTypes(themeDef),
@@ -2741,7 +2750,7 @@ async function themeBuildInternal(
2741
2750
  );
2742
2751
  }
2743
2752
  if (cssParts.length === 0) {
2744
- logger.log('No overrides found; nothing to build.');
2753
+ logger.log(`${source}No overrides found; nothing to build.`);
2745
2754
  return null;
2746
2755
  }
2747
2756
  // The data-token defaults are theme-independent and go in @layer
@@ -2933,19 +2942,21 @@ async function themeBuildInternal(
2933
2942
 
2934
2943
  writeBuildOutputs(writes);
2935
2944
 
2936
- logger.log(`\n[ok] ${path.relative(cwd, outPath)}`);
2937
- logger.log(`[ok] ${path.relative(cwd, cssDtsPath)}`);
2938
- logger.log(
2939
- ` ${tokenCount} token overrides, ${componentCount} component overrides`,
2940
- );
2941
- logger.log(` ${size} KB`);
2942
- logger.log(`[ok] ${path.relative(cwd, jsPath)}`);
2943
- logger.log(`[ok] ${path.relative(cwd, dtsPath)}`);
2944
- if (variantDtsPath && variantDecl) {
2945
- const augCount = (variantDecl.match(/': true;/g) || []).length;
2945
+ if (!report.compact) {
2946
+ logger.log(`\n[ok] ${path.relative(cwd, outPath)}`);
2947
+ logger.log(`[ok] ${path.relative(cwd, cssDtsPath)}`);
2946
2948
  logger.log(
2947
- `[ok] ${path.relative(cwd, variantDtsPath)} (${augCount} type augmentations)`,
2949
+ ` ${tokenCount} token overrides, ${componentCount} component overrides`,
2948
2950
  );
2951
+ logger.log(` ${size} KB`);
2952
+ logger.log(`[ok] ${path.relative(cwd, jsPath)}`);
2953
+ logger.log(`[ok] ${path.relative(cwd, dtsPath)}`);
2954
+ if (variantDtsPath && variantDecl) {
2955
+ const augCount = (variantDecl.match(/': true;/g) || []).length;
2956
+ logger.log(
2957
+ `[ok] ${path.relative(cwd, variantDtsPath)} (${augCount} type augmentations)`,
2958
+ );
2959
+ }
2949
2960
  }
2950
2961
 
2951
2962
  const relOutDir = path.relative(cwd, outDir) || '.';
@@ -2953,27 +2964,6 @@ async function themeBuildInternal(
2953
2964
  const jsImport = importSpecifier(relOutDir, baseName);
2954
2965
  const cssImport = importSpecifier(relOutDir, cssBase) + '.css';
2955
2966
  const exportName = `${toIdentifier(baseName)}Theme`;
2956
- logger.log(`
2957
- Install in your app (paths are relative to a file in src/; adjust if yours lives elsewhere):
2958
-
2959
- import { Theme } from '@astryxdesign/core';
2960
- import { ${exportName} } from '${jsImport}';
2961
- import '${cssImport}';
2962
-
2963
- <Theme theme={${exportName}}>
2964
- <App />
2965
- </Theme>
2966
-
2967
- Or with a <link> tag:
2968
-
2969
- import { Theme } from '@astryxdesign/core';
2970
- import { ${exportName} } from '${jsImport}';
2971
-
2972
- <link rel="stylesheet" href="${cssImport}" />
2973
- <Theme theme={${exportName}}>
2974
- <App />
2975
- </Theme>
2976
- `);
2977
2967
 
2978
2968
  // Fonts the theme names but nothing loads (#5015). Resolved tokens and
2979
2969
  // component overrides carry the final font-family values on both load
@@ -2987,15 +2977,27 @@ Or with a <link> tag:
2987
2977
  // permanently in violation of its own "compiles with no warnings" guard).
2988
2978
  // Adaptation rules are resolved theme writes in their own right, so a family
2989
2979
  // named only inside one needs the same notice as one named at the root.
2980
+ /** @type {string[]} */
2981
+ const fontNotices = [];
2990
2982
  for (const family of unloadedFonts) {
2991
2983
  const msg = `Font "${family}" is named by this theme but not loaded; add a <link> or @font-face in your app (recipe: astryx docs typography)`;
2992
2984
  noticeMessages.push(msg);
2993
- logger.log(` note: ${msg}`);
2994
- }
2995
- if (unloadedFonts.length > 0) {
2996
- logger.log(formatFontLoadingHelp(themeDef.name, unloadedFonts));
2985
+ fontNotices.push(msg);
2997
2986
  }
2998
2987
 
2988
+ /** @type {ThemeBuildTrailer} */
2989
+ const trailer = {
2990
+ themeName: themeDef.name,
2991
+ exportName,
2992
+ jsImport,
2993
+ cssImport,
2994
+ unloadedFonts,
2995
+ fontNotices,
2996
+ };
2997
+ // A batch or compact report prints this once for the whole run instead.
2998
+ if (report.trailers) report.trailers.push(trailer);
2999
+ else printBuildTrailer(trailer);
3000
+
2999
3001
  return {
3000
3002
  type: 'theme.build',
3001
3003
  data: {
@@ -3018,6 +3020,166 @@ Or with a <link> tag:
3018
3020
  };
3019
3021
  }
3020
3022
 
3023
+ /**
3024
+ * What a standalone build prints after its [ok] lines, kept as data so a
3025
+ * batch can print it once for every theme.
3026
+ * @typedef {object} ThemeBuildTrailer
3027
+ * @property {string} themeName The theme's name.
3028
+ * @property {string} exportName The built module's theme export.
3029
+ * @property {string} jsImport Import specifier of the built JS module.
3030
+ * @property {string} cssImport Import specifier of the built CSS.
3031
+ * @property {string[]} unloadedFonts Font families the theme names but does not load.
3032
+ * @property {string[]} fontNotices One notice per unloaded font family.
3033
+ */
3034
+
3035
+ /**
3036
+ * Print a standalone build's install snippet and font guidance.
3037
+ * @param {ThemeBuildTrailer} trailer
3038
+ */
3039
+ function printBuildTrailer(trailer) {
3040
+ logger.log(`
3041
+ Install in your app (paths are relative to a file in src/; adjust if yours lives elsewhere):
3042
+
3043
+ import { Theme } from '@astryxdesign/core';
3044
+ import { ${trailer.exportName} } from '${trailer.jsImport}';
3045
+ import '${trailer.cssImport}';
3046
+
3047
+ <Theme theme={${trailer.exportName}}>
3048
+ <App />
3049
+ </Theme>
3050
+
3051
+ Or with a <link> tag:
3052
+
3053
+ import { Theme } from '@astryxdesign/core';
3054
+ import { ${trailer.exportName} } from '${trailer.jsImport}';
3055
+
3056
+ <link rel="stylesheet" href="${trailer.cssImport}" />
3057
+ <Theme theme={${trailer.exportName}}>
3058
+ <App />
3059
+ </Theme>
3060
+ `);
3061
+ for (const msg of trailer.fontNotices) logger.log(` note: ${msg}`);
3062
+ if (trailer.unloadedFonts.length > 0) {
3063
+ logger.log(formatFontLoadingHelp(trailer.themeName, trailer.unloadedFonts));
3064
+ }
3065
+ }
3066
+
3067
+ /**
3068
+ * Print the install snippet and font guidance once for a batch: the first
3069
+ * theme as the full example, one import line per built theme, and one font
3070
+ * recipe naming every family the themes do not load.
3071
+ * @param {ThemeBuildTrailer[]} trailers
3072
+ */
3073
+ export function printBatchTrailer(trailers) {
3074
+ if (trailers.length === 0) return;
3075
+ const [first] = trailers;
3076
+ logger.log(`
3077
+ Install in your app (paths are relative to a file in src/; adjust if yours lives elsewhere):
3078
+
3079
+ import { Theme } from '@astryxdesign/core';
3080
+ import { ${first.exportName} } from '${first.jsImport}';
3081
+ import '${first.cssImport}';
3082
+
3083
+ <Theme theme={${first.exportName}}>
3084
+ <App />
3085
+ </Theme>
3086
+
3087
+ Or with a <link> tag:
3088
+
3089
+ import { Theme } from '@astryxdesign/core';
3090
+ import { ${first.exportName} } from '${first.jsImport}';
3091
+
3092
+ <link rel="stylesheet" href="${first.cssImport}" />
3093
+ <Theme theme={${first.exportName}}>
3094
+ <App />
3095
+ </Theme>
3096
+ `);
3097
+ if (trailers.length > 1) {
3098
+ logger.log('Each built theme imports the same way:');
3099
+ for (const trailer of trailers) {
3100
+ logger.log(
3101
+ ` import { ${trailer.exportName} } from '${trailer.jsImport}'; import '${trailer.cssImport}';`,
3102
+ );
3103
+ }
3104
+ }
3105
+ const fonts = groupUnloadedFonts(trailers);
3106
+ if (fonts.length > 0) logger.log(formatBatchFontLoadingHelp(fonts));
3107
+ }
3108
+
3109
+ /**
3110
+ * Print what a short report keeps after its one line per theme: one line
3111
+ * naming the fonts the themes do not load, and, when the caller chose no
3112
+ * detail level, where the install example and font recipe are.
3113
+ * @param {ThemeBuildTrailer[]} trailers
3114
+ * @param {{hint?: boolean}} [options]
3115
+ */
3116
+ export function printCompactTrailer(trailers, {hint = false} = {}) {
3117
+ if (trailers.length === 0) return;
3118
+ const fonts = groupUnloadedFonts(trailers);
3119
+ if (fonts.length > 0) {
3120
+ const named = fonts
3121
+ .map(({family, themes}) =>
3122
+ trailers.length > 1
3123
+ ? `"${family}" (${themes.join(', ')})`
3124
+ : `"${family}"`,
3125
+ )
3126
+ .join(', ');
3127
+ logger.log(
3128
+ `[note] Fonts named but not loaded: ${named}. Load them in your app (recipe: astryx docs typography).`,
3129
+ );
3130
+ }
3131
+ if (hint) {
3132
+ logger.log(
3133
+ 'Run with --detail full for the install example and font recipe.',
3134
+ );
3135
+ }
3136
+ }
3137
+
3138
+ /**
3139
+ * Each font family the themes name but do not load, with the themes that
3140
+ * name it, in first-seen order.
3141
+ * @param {ThemeBuildTrailer[]} trailers
3142
+ * @returns {Array<{family: string, themes: string[]}>}
3143
+ */
3144
+ function groupUnloadedFonts(trailers) {
3145
+ /** @type {Map<string, {family: string, themes: string[]}>} */
3146
+ const byFamily = new Map();
3147
+ for (const trailer of trailers) {
3148
+ for (const family of trailer.unloadedFonts) {
3149
+ const key = family.toLowerCase();
3150
+ const entry = byFamily.get(key) ?? {family, themes: []};
3151
+ entry.themes.push(trailer.themeName);
3152
+ byFamily.set(key, entry);
3153
+ }
3154
+ }
3155
+ return [...byFamily.values()];
3156
+ }
3157
+
3158
+ /**
3159
+ * Build one theme for a batch or compact CLI report. Same build, outputs, and
3160
+ * receipt as {@link themeBuild}; the install snippet and font guidance come
3161
+ * back as `trailer` instead of being printed, and `compact` leaves out the
3162
+ * per-file progress lines. CLI-internal: not exported from the API entry.
3163
+ * @param {string} file
3164
+ * @param {{out?: string, check?: boolean, iconsSpecifier?: string}} [options]
3165
+ * @param {{cwd?: string}} [ctx]
3166
+ * @param {{compact?: boolean}} [report]
3167
+ * @returns {Promise<{receipt: import('../theme.type.mjs').ThemeBuildResponse | import('../theme.type.mjs').ThemeBuildCheckResponse | null, trailer: ThemeBuildTrailer | null}>}
3168
+ */
3169
+ export async function themeBuildForReport(
3170
+ file,
3171
+ options = {},
3172
+ ctx = {},
3173
+ {compact = false} = {},
3174
+ ) {
3175
+ /** @type {ThemeBuildTrailer[]} */
3176
+ const trailers = [];
3177
+ const receipt = /** @type {any} */ (
3178
+ await themeBuildInternal(file, options, ctx, {compact, trailers})
3179
+ );
3180
+ return {receipt, trailer: trailers[0] ?? null};
3181
+ }
3182
+
3021
3183
  /** @param {string} file @param {{out?: string, check?: boolean, iconsSpecifier?: string}} [options] @param {{cwd?: string}} [ctx] @returns {Promise<import('../theme.type.mjs').ThemeBuildResponse | import('../theme.type.mjs').ThemeBuildCheckResponse | null>} */
3022
3184
  export async function themeBuild(file, options = {}, ctx = {}) {
3023
3185
  return /** @type {any} */ (themeBuildInternal(file, options, ctx));
@@ -38,3 +38,14 @@ export function collectUnloadedFonts(resolvedTheme: {
38
38
  * @returns {string}
39
39
  */
40
40
  export function formatFontLoadingHelp(themeName: string, families: string[]): string;
41
+ /**
42
+ * The same fix once for a batch build: each family the built themes name but
43
+ * do not load, with the themes that name it, then one recipe for all of them.
44
+ *
45
+ * @param {Array<{family: string, themes: string[]}>} entries
46
+ * @returns {string}
47
+ */
48
+ export function formatBatchFontLoadingHelp(entries: Array<{
49
+ family: string;
50
+ themes: string[];
51
+ }>): string;
@@ -202,6 +202,33 @@ export function collectUnloadedFonts(resolvedTheme) {
202
202
  */
203
203
  export function formatFontLoadingHelp(themeName, families) {
204
204
  const named = families.map(f => `"${f}"`).join(', ');
205
+ return `
206
+ [note] Theme "${themeName}" names fonts it does not load: ${named}
207
+ ${fontLoadingRecipe(families)}`;
208
+ }
209
+
210
+ /**
211
+ * The same fix once for a batch build: each family the built themes name but
212
+ * do not load, with the themes that name it, then one recipe for all of them.
213
+ *
214
+ * @param {Array<{family: string, themes: string[]}>} entries
215
+ * @returns {string}
216
+ */
217
+ export function formatBatchFontLoadingHelp(entries) {
218
+ const named = entries
219
+ .map(({family, themes}) => ` "${family}" (${themes.join(', ')})`)
220
+ .join('\n');
221
+ return `
222
+ [note] The built themes name fonts they do not load:
223
+ ${named}
224
+ ${fontLoadingRecipe(entries.map(entry => entry.family))}`;
225
+ }
226
+
227
+ /**
228
+ * @param {string[]} families
229
+ * @returns {string}
230
+ */
231
+ function fontLoadingRecipe(families) {
205
232
  const cssHref =
206
233
  'https://fonts.googleapis.com/css2?' +
207
234
  families
@@ -210,9 +237,7 @@ export function formatFontLoadingHelp(themeName, families) {
210
237
  '&display=swap';
211
238
  const first = families[0];
212
239
  const slug = first.toLowerCase().replace(/ /g, '-');
213
- return `
214
- [note] Theme "${themeName}" names fonts it does not load: ${named}
215
- The built CSS only sets font-family; load these in your app, or every
240
+ return ` The built CSS only sets font-family; load these in your app, or every
216
241
  browser quietly falls back.
217
242
 
218
243
  Google Fonts (add :wght@... axes as your theme's weights require):
@@ -34,7 +34,7 @@ export const docs = {
34
34
  {
35
35
  title: 'defineTheme',
36
36
  content: [
37
- {type: 'prose', text: "defineTheme creates a theme from token overrides and optional scale configs. Scale configs generate tokens from parameters. Explicit token overrides always take precedence over scale-generated values, token by token. localTokens accepts any valid CSS custom-property name; prefixes do not establish ownership. One caveat for the accent: overriding --color-accent in tokens re-points the reference tokens (--color-accent-muted, --color-text-accent, --color-icon-accent) but NOT --color-on-accent, which stays baked from the color.accent seed. To give each scheme its own accent with a consistent derived palette, pass a [light, dark] tuple to color.accent instead of overriding the token."},
37
+ {type: 'prose', text: "defineTheme creates a theme from token overrides and optional scale configs. Only override tokens that differ from defaults; omitted tokens use the design system defaults. Scale configs generate tokens from parameters. Explicit token overrides always take precedence over scale-generated values, token by token. localTokens accepts any valid CSS custom-property name; prefixes do not establish ownership. One caveat for the accent: overriding --color-accent in tokens re-points the reference tokens (--color-accent-muted, --color-text-accent, --color-icon-accent) but NOT --color-on-accent, which stays baked from the color.accent seed. To give each scheme its own accent with a consistent derived palette, pass a [light, dark] tuple to color.accent instead of overriding the token."},
38
38
  {type: 'code', lang: 'tsx', label: 'defineTheme with scale configs', code: "import {defineTheme} from '@astryxdesign/core/theme';\n\nconst myTheme = defineTheme({\n name: 'my-theme',\n // accent: single hex, or [light, dark] tuple to seed each scheme separately\n color: { accent: ['#7B61FF', '#9B85FF'], neutralStyle: 'cool' },\n typography: {\n scale: { base: 14, ratio: 1.2 },\n body: { family: 'Inter', fallbacks: '-apple-system, sans-serif' },\n },\n radius: { base: 4, multiplier: 1 },\n motion: { fast: 175, medium: 410, ratio: 0.75 },\n tokens: {\n // Explicit overrides take precedence over scale-generated values\n '--color-background-body': ['#FFFFFF', '#0A0A0A'],\n },\n});"},
39
39
  {type: 'table', headers: ['Config', 'Generates', 'Parameters'], rows: [
40
40
  ['color', '--color-accent, --color-background-*, --color-text-*, --color-border, etc.', 'accent? (hex or [light, dark] tuple; omit for neutral-only), neutralStyle? (warm|cool|neutral), contrast? (standard|high)'],
@@ -60,7 +60,7 @@ export const docs = {
60
60
  ['typography, motion, radius, color', 'Child config replaces base entirely (these are scale inputs, not additive).'],
61
61
  ['adaptations', 'Width-breakpoint overrides merge by fixed name. Inherited ordered rules keep their relative order; child rules append and re-resolve against the child root axes.'],
62
62
  ]},
63
- {type: 'prose', text: "Inheritance is resolved when the theme is defined, so an extended theme is flat: `astryx theme build` emits one self-contained stylesheet holding everything the child inherited, and the base theme's CSS does not need to be loaded next to it."},
63
+ {type: 'prose', text: "Inheritance is resolved when the theme is defined, so an extended theme is flat: `astryx theme build` emits one self-contained stylesheet holding everything the child inherited, and the base theme's CSS does not need to be loaded next to it. A base that is not a theme (most often an import that missed) throws when `defineTheme` runs, rather than producing a theme that silently inherits nothing."},
64
64
  {type: 'prose', text: 'For the integration-specific guidance on mapping a palette to tokens when extending, see `astryx docs cli/integrations/building-blocks/themes/define-the-theme`.'},
65
65
  ],
66
66
  },
@@ -71,7 +71,7 @@ export const docs = {
71
71
  {type: 'code', lang: 'tsx', label: 'Component overrides with standard CSS', code: "components: {\n card: {\n base: { borderRadius: '20px', padding: '24px' },\n },\n button: {\n base: {\n borderRadius: '9999px',\n textTransform: 'uppercase',\n '--button-focus-offset': '3px',\n },\n 'variant:ghost': { borderWidth: '2px', borderStyle: 'solid' },\n },\n}"},
72
72
  {type: 'prose', text: "Run `astryx theme targets` for every themeable key in the system (`astryx theme targets <Name>` to scope it, `--json` to lint a theme against it), and `astryx component <Name>` for one component's theming targets, public CSS variables, and which standard CSS properties are supported."},
73
73
  {type: 'list', style: 'do', items: ['Write standard CSS properties (borderRadius, padding); the pipeline expands them into internal vars.', 'Set public CSS vars directly when no standard property equivalent exists.']},
74
- {type: 'list', style: 'dont', items: ['Set private CSS vars (prefixed --_) directly. Use standard CSS properties instead. `astryx theme build` will error.']},
74
+ {type: 'list', style: 'dont', items: ['Set private CSS vars (prefixed --_) directly. Use standard CSS properties instead. `astryx theme build` will error.', 'Set a public CSS var the component does not define. It compiles to CSS that never applies, and the build does not warn. Take the names from `astryx component <Name>`.']},
75
75
  ],
76
76
  },
77
77
  {
@@ -94,7 +94,7 @@ export const docs = {
94
94
  ['contrast', 'more | less | no-preference'],
95
95
  ['motion', 'reduce | no-preference'],
96
96
  ]},
97
- {type: 'prose', text: "`widthBreakpoints` are fixed named start points. Defaults are 640 / 768 / 1024 / 1280 / 1536 CSS pixels. `from` includes its point; `below` excludes it."},
97
+ {type: 'prose', text: "`widthBreakpoints` are fixed named start points. Defaults are 640 / 768 / 1024 / 1280 / 1536 CSS pixels. `from` includes its point; `below` excludes it. Breakpoint configuration alone emits no CSS."},
98
98
  ],
99
99
  },
100
100
  {
@@ -103,6 +103,7 @@ export const docs = {
103
103
  content: [
104
104
  {type: 'prose', text: "Precedence follows rule order. Root theme values apply first, then every matching rule in declaration order. A later rule may deliberately restore a root value. `onDark` and `onLight` media-surface overrides apply after adaptations and win on the same leaf."},
105
105
  {type: 'prose', text: "`extends` preserves the base rule order and appends child rules. Inherited conditions use the child's effective breakpoint map. An empty child rule is a no-op, not a removal operator."},
106
+ {type: 'prose', text: "A rule may replace a theme-local token only when the exact name is already enrolled by root `localTokens` or an enrolled base. Component writes in a rule are validated exactly like root `components`: same targets, axes, and value domains. The one addition is that a rule may not be the only place a custom value is enrolled: a value that is valid only because a theme enrolls it generates unconditional type augmentation, so declare it on the root theme first and let rules restyle it. Built-in values need no root declaration. When rules can match together, their ordered portable and local token writes are validated as one effective graph; any reachable cycle fails before CSS is emitted."},
106
107
  {type: 'prose', text: 'Adaptations compile to CSS media queries with no resize listener or styling rerender. Runtime and `astryx theme build` use the same compiler, but only a built theme is present at first paint in an SSR app.'},
107
108
  ],
108
109
  },
@@ -118,8 +119,9 @@ export const docs = {
118
119
  ['ocean.d.ts', 'TypeScript declarations for the theme and icon registry exports'],
119
120
  ['ocean.variants.d.ts', "(Optional) Module augmentations for custom component prop values"],
120
121
  ]},
122
+ {type: 'prose', text: 'The `__built: true` flag tells Theme to skip runtime `<style>` injection; the CSS file handles it. Load the generated CSS wherever you load the module.'},
121
123
  {type: 'code', lang: 'tsx', label: 'Using a custom built theme', code: "import {Theme} from '@astryxdesign/core';\nimport {oceanTheme} from './themes/ocean';\nimport './themes/ocean.css';\n\n<Theme theme={oceanTheme}>\n <App />\n</Theme>"},
122
- {type: 'prose', text: "After upgrading Astryx, rerun `astryx theme build` for every custom prebuilt theme. Deploy the regenerated files together. The build also warns when the theme names font families it does not load. See {@link generic:typography} for the full recipe."},
124
+ {type: 'prose', text: "After upgrading Astryx, rerun `astryx theme build` for every custom prebuilt theme. Deploy the regenerated files together. The runtime intentionally trusts `__built: true` and will not repair stale CSS from an older build. The build also warns when the theme names font families it does not load. See {@link generic:typography} for the full recipe."},
123
125
  {type: 'prose', text: 'For the runtime vs built tradeoff, see the Runtime vs Built section of {@link generic:use-a-theme}.'},
124
126
  ],
125
127
  },
@@ -129,13 +131,15 @@ export const docs = {
129
131
  content: [
130
132
  {type: 'prose', text: "`theme build` emits an icon import when it detects a named import used by the theme's `icons:` field. It does not compile that registry module. Move the registry to a separate module and use a named import."},
131
133
  {type: 'code', lang: 'bash', label: 'Compiling the icon registry sidecar', code: "# Emit the built theme\nastryx theme build ./src/themes/ocean.ts -o dist/theme.css --icons-specifier ./icons.mjs\n\n# Compile the icon registry alongside it\nesbuild src/themes/icons.tsx --bundle --format=esm --outfile=dist/icons.mjs \\\n --external:react --external:lucide-react --jsx=automatic"},
134
+ {type: 'prose', text: 'In the example above, the generated theme imports `./icons.mjs` from `dist`. If the second command is skipped, `theme build` can still succeed, but loading or bundling the generated module fails because `dist/icons.mjs` is missing. `--icons-specifier` changes the emitted import; it does not create or verify the target file. Match the specifier to a module that resolves from the generated JS file.'},
135
+ {type: 'prose', text: 'Without `--icons-specifier`, the detected source import specifier is emitted unchanged. In the default flow without `--out`, a bundler can resolve an extensionless `./icons` to the neighboring `icons.tsx` source, but Node ESM does not perform that lookup and reports `ERR_MODULE_NOT_FOUND`. Moving the output with `--out` also changes where relative imports resolve from.'},
132
136
  {type: 'prose', text: 'Keep `react` and the icon library external so the registry does not bundle its own copies of those dependencies.'},
133
137
  ],
134
138
  },
135
139
  {
136
140
  title: 'Building a Theme Family',
137
141
  content: [
138
- {type: 'prose', text: 'Use family mode when an app switches among one base theme and its selected descendants. The build writes one keyed CSS file containing every member, plus one keyed JavaScript module and one declaration file.'},
142
+ {type: 'prose', text: 'Use family mode when an app switches among one base theme and its selected descendants. The build writes one keyed CSS file containing every member, plus one keyed JavaScript module and one declaration file, beside the root source.'},
139
143
  {type: 'code', lang: 'bash', label: 'Build one family', code: "astryx theme build --family \\\n ./src/themes/ocean.mjs \\\n ./src/themes/ocean-calm.mjs \\\n ./src/themes/ocean-calm-deep.mjs \\\n --family-key ocean-family"},
140
144
  {type: 'prose', text: 'The family stylesheet eagerly downloads every selected member so first paint is complete. Switching members changes only the theme identity; it does not add, remove, or reorder stylesheets.'},
141
145
  ],
@@ -143,9 +147,10 @@ export const docs = {
143
147
  {
144
148
  title: 'Token Utilities',
145
149
  content: [
146
- {type: 'prose', text: 'Use `tokenVar()` when a non-StyleX styling library wants a CSS variable reference, and `resolveThemeTokens()` when JavaScript needs token values for a specific theme and mode without React context.'},
150
+ {type: 'prose', text: 'Use `tokenVar()` when a non-StyleX styling library wants a CSS variable reference, and `resolveThemeTokens()` when JavaScript needs token values for a specific theme and mode without React context. Themes are registered by name when created with `defineTheme()`; call `registerTheme(theme)` for prebuilt or object-literal themes that need name-based SSR lookup.'},
147
151
  {type: 'code', lang: 'ts', label: 'CSS var references for styling-library configs', code: "import {tokenVar, tokenVars} from '@astryxdesign/core/theme/tokens';\n\nconst pandaOrEmotionTheme = {\n colors: {\n text: tokenVar('--color-text-primary'),\n surface: tokenVars['--color-background-surface'],\n },\n};"},
148
152
  {type: 'code', lang: 'ts', label: 'Resolve token values without a hook', code: "import {resolveThemeTokens} from '@astryxdesign/core/theme/tokens';\nimport {neutralTheme} from '@astryxdesign/theme-neutral';\n\nconst lightTokens = resolveThemeTokens(neutralTheme, {mode: 'light'});\nconst chartTheme = {\n textColor: lightTokens['--color-text-primary'],\n seriesColor: lightTokens['--color-data-categorical-blue'],\n};"},
153
+ {type: 'prose', text: 'The `@astryxdesign/core/theme/tokens` subpath is server-safe and does not require React. The main `@astryxdesign/core/theme` barrel also re-exports these helpers for client code that already imports theme APIs.'},
149
154
  {type: 'prose', text: 'For styling library interop patterns, see {@link generic:styling-libraries}.'},
150
155
  ],
151
156
  },
@@ -11,7 +11,7 @@ export const docsZh = {
11
11
  content: [
12
12
  {
13
13
  type: 'prose',
14
- text: '安装主题包,用 `<Theme>` 包裹应用,选择浅色或深色模式。完整指南——可用主题、集成主题、深色模式、嵌套主题和生产构建——请参阅 {@link generic:use-a-theme}。',
14
+ text: "安装主题包,用 `<Theme>`(`import {Theme} from '@astryxdesign/core'`)包裹应用,选择浅色或深色模式。完整指南——可用主题、集成主题、深色模式、嵌套主题和生产构建——请参阅 {@link generic:use-a-theme}。",
15
15
  },
16
16
  ],
17
17
  },
@@ -26,6 +26,26 @@ export const docs = {
26
26
  'SideNav',
27
27
  'TopNav',
28
28
  ],
29
+ blocks: [
30
+ {
31
+ type: 'prose',
32
+ text: "Build a layout outside-in. Settle the shell and its region budgets before any content exists, then work inward. Content-first layouts drift into a padded column of cards, because every section ends up inventing its own container.",
33
+ },
34
+ {
35
+ type: 'list',
36
+ style: 'ordered',
37
+ items: [
38
+ "Scaffold: pick the shell, budget each region, and choose navigation",
39
+ "Structure: rank the content in each region, then pick the weakest container that groups it",
40
+ "Spacing: hold one content line per region, then tune gaps and density",
41
+ "Breakpoints: decide what each region does as width changes",
42
+ ],
43
+ },
44
+ {
45
+ type: 'prose',
46
+ text: "This guide decides layout, not component APIs. Run `npx astryx build \"<idea>\"` to start from the closest template for your app type, and `npx astryx component <Name>` for a component's props.",
47
+ },
48
+ ],
29
49
  slots: {
30
50
  guides: {title: 'Guides', accepts: {kinds: ['generic']}},
31
51
  },
@@ -31,7 +31,7 @@ export const docs = {
31
31
  type: 'code',
32
32
  lang: 'tsx',
33
33
  label: 'Switch among added themes',
34
- code: "import {useState} from 'react';\nimport {themes, type ThemeSlug} from './astryx-themes';\n\nconst [slug, setSlug] = useState<ThemeSlug>('neutral');\nconst app = <Theme theme={themes[slug]}><YourApp /></Theme>;",
34
+ code: "import {useState} from 'react';\nimport {Theme} from '@astryxdesign/core';\nimport {themes, type ThemeSlug} from './astryx-themes';\n\nconst [slug, setSlug] = useState<ThemeSlug>('neutral');\nconst app = <Theme theme={themes[slug]}><YourApp /></Theme>;",
35
35
  },
36
36
  {
37
37
  type: 'prose',
@@ -179,7 +179,7 @@ export const docs = {
179
179
  ['How it works', 'useInsertionEffect injects <style> at hydration', 'Pre-compiled .css file loaded with the page'],
180
180
  ['Component overrides', 'Injected client-only', 'In static CSS: present during SSR'],
181
181
  ['SSR safe', 'Tokens yes, component overrides flash on hydration', 'Fully SSR safe: no flash'],
182
- ['Best for', 'Dev, prototyping, client-only SPAs', 'Production, SSR apps (Next.js, Remix)'],
182
+ ['Best for', 'Authoring input for `astryx theme build`', 'App wiring, in development and production'],
183
183
  ],
184
184
  },
185
185
  {
@@ -187,7 +187,8 @@ export const docs = {
187
187
  style: 'do',
188
188
  items: [
189
189
  'Use `theme add --import` for production apps; it wires the built module and CSS.',
190
- 'Use runtime themes during development for fast iteration.',
190
+ 'Import `themes` and `defaultThemeSlug` from the generated module once, and keep that wiring in development too.',
191
+ 'While you edit a local theme, run `astryx theme build --watch` so its built files stay current.',
191
192
  'Run `astryx theme build` for custom themes to get the built artifacts.',
192
193
  ],
193
194
  },
@@ -197,6 +198,8 @@ export const docs = {
197
198
  items: [
198
199
  'Use runtime themes in production SSR apps; component overrides will flash on hydration.',
199
200
  "Import /built without the CSS file; component overrides won't apply.",
201
+ 'Import package theme source into app runtime code.',
202
+ 'Hand-edit the generated theme module; `theme add`, `theme remove`, and `theme use` regenerate it.',
200
203
  ],
201
204
  },
202
205
  {
@@ -5,7 +5,7 @@
5
5
  /**
6
6
  * Incident Console — an on-call incident response tool.
7
7
  *
8
- * Frame-first layout (see `npx astryx docs layout`), distilled from
8
+ * Frame-first layout (see `npx @astryxdesign/cli docs layout`), distilled from
9
9
  * product-scale apps built with the design system:
10
10
  *
11
11
  * Frame: header | grouped incident rows (fill) | inspector 380 (resizable)