@astryxdesign/cli 0.6.6-canary.e1dda17 → 0.6.6-canary.ee02ce2

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 (68) hide show
  1. package/README.md +83 -83
  2. package/api/build/_adapter.d.mts +15 -0
  3. package/api/build/_adapter.mjs +22 -0
  4. package/api/build/build.doc.mjs +1 -1
  5. package/api/build/build.type.d.mts +4 -0
  6. package/api/build/build.type.mjs +1 -0
  7. package/api/build/help/help.mjs +1 -1
  8. package/api/build/kit/kit.mjs +12 -1
  9. package/api/doctor/_adapter.d.mts +7 -0
  10. package/api/doctor/_adapter.mjs +48 -0
  11. package/api/doctor/doctor.mjs +5 -3
  12. package/api/doctor/theme-checks.d.mts +12 -0
  13. package/api/doctor/theme-checks.mjs +115 -1
  14. package/api/doctor/theme-checks.test.mjs +142 -1
  15. package/api/init/run/run.mjs +1 -0
  16. package/api/layout/check/check.d.mts +1 -0
  17. package/api/layout/check/check.mjs +1 -0
  18. package/api/layout/expand/expand.d.mts +1 -0
  19. package/api/layout/expand/expand.mjs +1 -0
  20. package/api/layout/grammar/grammar.d.mts +1 -0
  21. package/api/layout/grammar/grammar.mjs +1 -0
  22. package/api/layout/layoutCheck.doc.mjs +1 -1
  23. package/api/layout/layoutExpand.doc.mjs +1 -1
  24. package/api/layout/layoutGrammar.doc.mjs +1 -1
  25. package/api/template/copy/copy.mjs +12 -0
  26. package/api/template/template.doc.mjs +1 -1
  27. package/api/template/template.type.d.mts +3 -0
  28. package/api/template/template.type.mjs +3 -0
  29. package/api/theme/build/build.d.mts +70 -0
  30. package/api/theme/build/build.mjs +205 -41
  31. package/api/theme/build/font-warning.d.mts +11 -0
  32. package/api/theme/build/font-warning.mjs +28 -3
  33. package/assets/docs/author-a-theme.doc.mjs +4 -4
  34. package/assets/docs/styling-overview.doc.mjs +211 -0
  35. package/assets/docs/theme.doc.dense.mjs +1 -1
  36. package/assets/docs/theme.doc.mjs +5 -5
  37. package/assets/docs/theme.doc.zh.mjs +1 -1
  38. package/assets/docs/use-a-theme.doc.mjs +159 -47
  39. package/assets/templates/pages/table-comparison/template.doc.mjs +1 -1
  40. package/authoring/doctypes/template/type.ts +1 -0
  41. package/clients/cli/commands/build-theme.adaptations.test.mjs +1 -1
  42. package/clients/cli/commands/build-theme.ascii-output.test.mjs +11 -1
  43. package/clients/cli/commands/build-theme.batch-report.test.mjs +335 -0
  44. package/clients/cli/commands/build-theme.font-warning.test.mjs +36 -7
  45. package/clients/cli/commands/build-theme.import-path.test.mjs +3 -3
  46. package/clients/cli/commands/build-theme.mjs +68 -18
  47. package/clients/cli/commands/build-theme.watch.test.mjs +33 -0
  48. package/clients/cli/commands/build.mjs +1 -0
  49. package/clients/cli/commands/docs.test.mjs +1 -1
  50. package/clients/cli/commands/doctor.doc.mjs +1 -1
  51. package/clients/cli/commands/import-hint-correctness.test.mjs +23 -0
  52. package/clients/cli/commands/layout-check.doc.mjs +1 -0
  53. package/clients/cli/commands/layout-expand.doc.mjs +1 -0
  54. package/clients/cli/commands/layout-grammar.doc.mjs +1 -0
  55. package/clients/cli/commands/layout.deprecation-lifecycle.test.mjs +140 -0
  56. package/clients/cli/commands/layout.doc.mjs +1 -0
  57. package/clients/cli/commands/layout.mjs +6 -11
  58. package/clients/cli/commands/template.mjs +4 -3
  59. package/clients/cli/commands/theme-build.doc.mjs +3 -1
  60. package/clients/cli/index.mjs +1 -1
  61. package/clients/cli/lib/define-command.mjs +4 -0
  62. package/foundation/agent-docs/agent-docs.mjs +4 -1
  63. package/foundation/agent-docs/agent-docs.test.mjs +18 -0
  64. package/foundation/discovery/template-needs.d.mts +31 -0
  65. package/foundation/discovery/template-needs.mjs +156 -0
  66. package/foundation/discovery/template-needs.test.mjs +203 -0
  67. package/foundation/response/response-types.doc.mjs +4 -4
  68. package/package.json +9 -9
@@ -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,25 +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 { ${exportName} } from '${jsImport}';
2960
- import '${cssImport}';
2961
-
2962
- <Theme theme={${exportName}}>
2963
- <App />
2964
- </Theme>
2965
-
2966
- Or with a <link> tag:
2967
-
2968
- import { ${exportName} } from '${jsImport}';
2969
-
2970
- <link rel="stylesheet" href="${cssImport}" />
2971
- <Theme theme={${exportName}}>
2972
- <App />
2973
- </Theme>
2974
- `);
2975
2967
 
2976
2968
  // Fonts the theme names but nothing loads (#5015). Resolved tokens and
2977
2969
  // component overrides carry the final font-family values on both load
@@ -2985,15 +2977,27 @@ Or with a <link> tag:
2985
2977
  // permanently in violation of its own "compiles with no warnings" guard).
2986
2978
  // Adaptation rules are resolved theme writes in their own right, so a family
2987
2979
  // named only inside one needs the same notice as one named at the root.
2980
+ /** @type {string[]} */
2981
+ const fontNotices = [];
2988
2982
  for (const family of unloadedFonts) {
2989
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)`;
2990
2984
  noticeMessages.push(msg);
2991
- logger.log(` note: ${msg}`);
2992
- }
2993
- if (unloadedFonts.length > 0) {
2994
- logger.log(formatFontLoadingHelp(themeDef.name, unloadedFonts));
2985
+ fontNotices.push(msg);
2995
2986
  }
2996
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
+
2997
3001
  return {
2998
3002
  type: 'theme.build',
2999
3003
  data: {
@@ -3016,6 +3020,166 @@ Or with a <link> tag:
3016
3020
  };
3017
3021
  }
3018
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
+
3019
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>} */
3020
3184
  export async function themeBuild(file, options = {}, ctx = {}) {
3021
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):
@@ -14,10 +14,10 @@ export const docs = {
14
14
  id: 'creating-a-custom-theme',
15
15
  title: 'Custom themes',
16
16
  content: [
17
- {type: 'prose', text: "Start from a bundled theme or one contributed by an installed integration, or write one from scratch with defineTheme. `theme list` names each owner; when packages share a slug, pass `--package`. Only override tokens that differ from defaults; omitted tokens use the design system defaults."},
18
- {type: 'code', lang: 'bash', label: 'Browse, then copy a theme in as editable source', code: 'astryx theme list\nastryx theme add stone\nastryx theme add ocean --package @acme/themes'},
17
+ {type: 'prose', text: "Use an installed built theme as the base for ordinary customization. Import it into your source and pass it as `extends` to `defineTheme({extends: importedTheme, ...})`. Build the result, then add the local slug. Only eject when you need to own and maintain a full source fork."},
18
+ {type: 'code', lang: 'bash', label: 'Add to use, eject to fork', code: 'astryx theme list\nastryx theme add stone --import\nastryx theme eject stone\nastryx theme build src/themes/stone/stoneTheme.ts\nastryx theme add stone --import'},
19
19
  {type: 'prose', text: "For an annotated map of the whole surface (every defineTheme field, the token families, and the component override syntax, each with the CLI command that prints its reference), run `astryx theme template`. It writes `theme.template.ts` into your project to read and copy from (`astryx init --features theme` writes it as part of project setup)."},
20
- {type: 'prose', text: 'To apply a theme you created, see {@link generic:use-a-theme}. To generate colors from seed values, see the Palette section below.'},
20
+ {type: 'prose', text: 'To apply a theme you created, see {@link generic:use-a-theme}. To generate colors from seed values, see the Palette section below. Use `theme eject` only when you want an independent source fork that no longer receives the package owner\u2019s updates.'},
21
21
  ],
22
22
  },
23
23
  {
@@ -118,7 +118,7 @@ export const docs = {
118
118
  ['ocean.d.ts', 'TypeScript declarations for the theme and icon registry exports'],
119
119
  ['ocean.variants.d.ts', "(Optional) Module augmentations for custom component prop values"],
120
120
  ]},
121
- {type: 'code', lang: 'tsx', label: 'Using a custom built theme', code: "import {oceanTheme} from './themes/ocean';\nimport './themes/ocean.css';\n\n<Theme theme={oceanTheme}>\n <App />\n</Theme>"},
121
+ {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
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."},
123
123
  {type: 'prose', text: 'For the runtime vs built tradeoff, see the Runtime vs Built section of {@link generic:use-a-theme}.'},
124
124
  ],
@@ -0,0 +1,211 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file `astryx docs styling-overview`
5
+ *
6
+ * One question: "How do I set up CSS?"
7
+ * Three paths, each with its exact imports.
8
+ */
9
+
10
+ /** @type {import('@astryxdesign/cli/authoring').ReferenceDoc} */
11
+
12
+ export const docs = {
13
+ name: 'styling-overview',
14
+ title: 'Styling overview',
15
+ category: 'guide',
16
+ description:
17
+ 'How to set up CSS — exact imports for three paths: plain, Tailwind, and StyleX from source.',
18
+ keywords: [
19
+ 'styling',
20
+ 'CSS',
21
+ 'setup',
22
+ 'imports',
23
+ 'StyleX',
24
+ 'Tailwind',
25
+ 'astryx.css',
26
+ 'globals.css',
27
+ ],
28
+
29
+ sections: [
30
+ {
31
+ id: 'pick-a-path',
32
+ title: 'Pick a path',
33
+ content: [
34
+ {
35
+ type: 'table',
36
+ headers: ['Path', 'Good for', 'Build step?'],
37
+ rows: [
38
+ [
39
+ 'Plain CSS',
40
+ 'Most apps. Style with className, xstyle, or any CSS library.',
41
+ 'None.',
42
+ ],
43
+ [
44
+ 'Tailwind',
45
+ 'Apps on Tailwind v4. A CSS bridge maps utility classes to design tokens.',
46
+ "None beyond Tailwind's own.",
47
+ ],
48
+ [
49
+ 'StyleX from source',
50
+ 'Swizzled (ejected) components. Raw StyleX source needs a compiler plugin.',
51
+ 'Yes \u2014 a StyleX bundler plugin.',
52
+ ],
53
+ ],
54
+ },
55
+ {
56
+ type: 'prose',
57
+ text: 'All three resolve to the same design tokens and support theming and dark mode. You can mix them in one app.',
58
+ },
59
+ ],
60
+ },
61
+ {
62
+ id: 'plain',
63
+ title: 'Plain CSS',
64
+ content: [
65
+ {
66
+ type: 'code',
67
+ lang: 'bash',
68
+ label: 'Install',
69
+ code: 'npm install @astryxdesign/core @stylexjs/stylex @astryxdesign/theme-neutral',
70
+ },
71
+ {
72
+ type: 'code',
73
+ lang: 'css',
74
+ label: 'globals.css',
75
+ code: `@import "@astryxdesign/core/reset.css";
76
+ @import "@astryxdesign/core/astryx.css";
77
+ @import "@astryxdesign/theme-neutral/theme.css";`,
78
+ },
79
+ {
80
+ type: 'prose',
81
+ text: "Done. Components work out of the box \u2014 style them with `className`, `xstyle`, or `style`. Swap `theme-neutral` for any theme package (`astryx theme list` shows what's available).",
82
+ },
83
+ ],
84
+ },
85
+ {
86
+ id: 'tailwind',
87
+ title: 'Tailwind',
88
+ content: [
89
+ {
90
+ type: 'code',
91
+ lang: 'bash',
92
+ label: 'Install (add to an existing Tailwind v4 app)',
93
+ code: 'npm install @astryxdesign/core @stylexjs/stylex @astryxdesign/theme-neutral',
94
+ },
95
+ {
96
+ type: 'code',
97
+ lang: 'css',
98
+ label: 'globals.css',
99
+ code: `@layer reset, theme, base, astryx-base, astryx-theme, components, utilities;
100
+
101
+ @import "tailwindcss/theme.css" layer(theme);
102
+ @import "tailwindcss/preflight.css" layer(base);
103
+ @import "@astryxdesign/core/reset.css";
104
+ @import "@astryxdesign/core/astryx.css";
105
+ @import "@astryxdesign/theme-neutral/theme.css";
106
+ @import "@astryxdesign/core/tailwind-theme.css";
107
+ @import "tailwindcss/utilities.css" layer(utilities);`,
108
+ },
109
+ {
110
+ type: 'prose',
111
+ text: 'The `@layer` declaration is critical \u2014 without it, component styles outrank Tailwind utilities and `className` overrides stop working. The bridge (`tailwind-theme.css`) maps classes like `text-primary`, `bg-surface`, and `rounded-lg` to design tokens with no JS.',
112
+ },
113
+ {
114
+ type: 'prose',
115
+ text: 'For Tailwind v3, see the layer workaround in {@link generic:migration}.',
116
+ },
117
+ ],
118
+ },
119
+ {
120
+ id: 'stylex-from-source',
121
+ title: 'StyleX from source',
122
+ content: [
123
+ {
124
+ type: 'prose',
125
+ text: 'Only needed when you swizzle a component (`astryx swizzle <Component>`) or write your own StyleX. The plain path already supports `xstyle` overrides \u2014 this path is for editing component internals. Some built-in page templates also use StyleX for layout; if you scaffold one and see "Unexpected stylex.create call at runtime", add the compiler plugin for your bundler below.',
126
+ },
127
+ {
128
+ type: 'code',
129
+ lang: 'bash',
130
+ label: 'Install',
131
+ code: 'npm install @astryxdesign/core @stylexjs/stylex @astryxdesign/theme-neutral',
132
+ },
133
+ {
134
+ type: 'code',
135
+ lang: 'css',
136
+ label: 'globals.css',
137
+ code: `@layer reset, astryx-base, astryx-theme;
138
+
139
+ @import "@astryxdesign/core/reset.css";
140
+ @import "@astryxdesign/theme-neutral/theme.css";`,
141
+ },
142
+ {
143
+ type: 'prose',
144
+ text: 'No `astryx.css` \u2014 the StyleX compiler produces component styles from source. Add the plugin for your bundler:',
145
+ },
146
+ {
147
+ type: 'table',
148
+ headers: ['Bundler', 'Plugin'],
149
+ rows: [
150
+ ['Webpack', '@stylexjs/webpack-plugin'],
151
+ ['Vite / Rollup', '@stylexjs/rollup-plugin'],
152
+ ['Babel (any)', '@stylexjs/babel-plugin + @stylexjs/postcss-plugin'],
153
+ ['Next.js (keep next/font)', '@stylexswc/nextjs-plugin'],
154
+ ],
155
+ },
156
+ {
157
+ type: 'prose',
158
+ text: 'If a swizzled component renders with no styles and no error, a missing compiler is almost always why. See the StyleX Build Setup section of {@link generic:styling} for bundler config examples.',
159
+ },
160
+ ],
161
+ },
162
+ {
163
+ id: 'what-each-file-does',
164
+ title: 'What each import does',
165
+ content: [
166
+ {
167
+ type: 'table',
168
+ headers: ['Import', 'Layer', 'Purpose'],
169
+ rows: [
170
+ [
171
+ 'reset.css',
172
+ 'reset',
173
+ 'Cross-browser reset (box-sizing, margins, color-scheme). Zero specificity via :where().',
174
+ ],
175
+ [
176
+ 'astryx.css',
177
+ 'astryx-base',
178
+ 'Pre-compiled component styles. Required for plain and Tailwind. Omit when compiling from source.',
179
+ ],
180
+ [
181
+ 'theme.css',
182
+ 'astryx-theme',
183
+ 'Design tokens (colors, spacing, radius, typography) as CSS custom properties. Swap the package for a different theme.',
184
+ ],
185
+ [
186
+ 'tailwind-theme.css',
187
+ '\u2014',
188
+ 'Tailwind v4 bridge. Maps utility classes to design tokens. Pure CSS, no JS. Tailwind path only.',
189
+ ],
190
+ ],
191
+ },
192
+ ],
193
+ },
194
+ {
195
+ id: 'further-reading',
196
+ title: 'Further reading',
197
+ content: [
198
+ {
199
+ type: 'list',
200
+ style: 'unordered',
201
+ items: [
202
+ '{@link generic:styling} \u2014 xstyle, className, data-attribute selectors, design tokens in code.',
203
+ '{@link generic:styling-libraries} \u2014 Tailwind bridge details, Panda, Chakra, MUI, CSS Modules, and non-CSS token resolution.',
204
+ '{@link generic:use-a-theme} \u2014 applying themes, dark mode, nested themes. {@link generic:author-a-theme} \u2014 defineTheme, overrides, production builds.',
205
+ '{@link generic:migration} \u2014 cascade layer audit, Tailwind v3 coexistence, and foundation smoke test.',
206
+ ],
207
+ },
208
+ ],
209
+ },
210
+ ],
211
+ };
@@ -9,7 +9,7 @@ export const docsDense = {
9
9
  section: 'Wrap your app in a theme',
10
10
  title: 'Quick start',
11
11
  content: [
12
- {type: 'prose', text: 'Install a theme, wrap in `<Theme>`. {@link generic:use-a-theme} for full guide.'},
12
+ {type: 'prose', text: "Install a theme, wrap in `<Theme>` (`import {Theme} from '@astryxdesign/core'`). {@link generic:use-a-theme} for full guide."},
13
13
  ],
14
14
  },
15
15
  {
@@ -17,13 +17,13 @@ export const docs = {
17
17
  content: [
18
18
  {
19
19
  type: 'prose',
20
- text: 'Install a theme package, wrap your app in `<Theme>`, and pick light or dark mode. For the full guide — available themes, integration themes, dark mode, nested themes, and production builds — see {@link generic:use-a-theme}.',
20
+ text: 'Install a theme, import it with the CLI, and wire the generated module once. For the full guide — available themes, integration themes, dark mode, nested themes, and production builds — see {@link generic:use-a-theme}.',
21
21
  },
22
22
  {
23
23
  type: 'code',
24
24
  lang: 'tsx',
25
- label: 'Basic theme setup',
26
- code: "import {Theme} from '@astryxdesign/core';\nimport {neutralTheme} from '@astryxdesign/theme-neutral';\n\nfunction App() {\n return (\n <Theme theme={neutralTheme}>\n <YourApp />\n </Theme>\n );\n}",
25
+ label: 'Wire the generated module once',
26
+ code: "import {Theme} from '@astryxdesign/core';\nimport {themes, defaultThemeSlug} from './astryx-themes';\n\nfunction App() {\n return (\n <Theme theme={themes[defaultThemeSlug]}>\n <YourApp />\n </Theme>\n );\n}",
27
27
  },
28
28
  ],
29
29
  },
@@ -39,7 +39,7 @@ export const docs = {
39
39
  type: 'code',
40
40
  lang: 'bash',
41
41
  label: 'Quick start',
42
- code: 'astryx theme template # annotated starter file\nastryx theme add stone # copy an existing theme\nastryx theme build ./src/themes/my-theme.ts',
42
+ code: 'astryx theme add stone --import # use an existing theme\nastryx theme eject stone # fork its source to customize\nastryx theme build src/themes/stone/stoneTheme.ts',
43
43
  },
44
44
  ],
45
45
  },
@@ -64,7 +64,7 @@ export const docs = {
64
64
  content: [
65
65
  {
66
66
  type: 'prose',
67
- text: 'Install an integration and Astryx discovers its themes automatically. Copy one into your project with `astryx theme add <name> --package <integration>`. For the full walkthrough, see {@link generic:use-a-theme}.',
67
+ text: 'Install an integration and Astryx discovers its themes automatically. Import one with `astryx theme add <name> --import --package <integration>`. Use `theme eject` only for an independent source fork. For the full walkthrough, see {@link generic:use-a-theme}.',
68
68
  },
69
69
  ],
70
70
  },