@astryxdesign/cli 0.7.14 → 0.7.15-canary.g06b7e61

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 (203) hide show
  1. package/CHANGELOG.md +3 -3
  2. package/README.md +63 -63
  3. package/api/build/_adapter.d.mts +4 -0
  4. package/api/build/_adapter.mjs +28 -2
  5. package/api/build/blocks/blocks.d.mts +10 -1
  6. package/api/build/blocks/blocks.mjs +84 -7
  7. package/api/build/build.mjs +6 -1
  8. package/api/build/tree.d.mts +4 -0
  9. package/api/build/tree.mjs +9 -2
  10. package/api/doctor/_adapter.d.mts +3 -1
  11. package/api/doctor/_adapter.mjs +14 -1
  12. package/api/doctor/_authoring-audit.d.mts +42 -0
  13. package/api/doctor/_authoring-audit.mjs +106 -0
  14. package/api/doctor/doctor.d.mts +7 -0
  15. package/api/doctor/doctor.mjs +24 -39
  16. package/api/doctor/theme-checks.mjs +56 -21
  17. package/api/integration/add-helpers.mjs +5 -0
  18. package/api/integration/add-theme.mjs +15 -110
  19. package/api/integration/validate-integration.mjs +17 -3
  20. package/api/integration/validateIntegration.doc.mjs +1 -1
  21. package/api/search/_adapter.mjs +124 -3
  22. package/api/search/_candidate-score.mjs +63 -9
  23. package/api/search/_entries.d.mts +10 -0
  24. package/api/search/_entries.mjs +68 -1
  25. package/api/search/_gather-templates.d.mts +11 -0
  26. package/api/search/_gather-templates.mjs +22 -2
  27. package/api/search/_words.mjs +26 -6
  28. package/api/swizzle/copy/copy.mjs +1 -1
  29. package/api/theme/_adapter.d.mts +37 -5
  30. package/api/theme/_adapter.mjs +381 -57
  31. package/api/theme/_fork.d.mts +90 -0
  32. package/api/theme/_fork.mjs +246 -0
  33. package/api/theme/build/build.d.mts +40 -2
  34. package/api/theme/build/build.mjs +477 -66
  35. package/api/theme/eject/eject.mjs +36 -15
  36. package/api/theme/list/list.mjs +3 -6
  37. package/api/theme/palette/generate/generator.d.mts +13 -0
  38. package/api/theme/palette/generate/generator.mjs +32 -2
  39. package/api/theme/targets/targets.d.mts +8 -0
  40. package/api/theme/targets/targets.mjs +24 -4
  41. package/api/theme/template/template.mjs +48 -2
  42. package/api/theme/theme.type.d.mts +8 -0
  43. package/api/theme/theme.type.mjs +5 -1
  44. package/api/theme/themeBuild.doc.mjs +7 -4
  45. package/api/theme/themeEject.doc.mjs +3 -3
  46. package/api/theme/themeRemove.doc.mjs +5 -2
  47. package/api/theme/themeTargets.doc.mjs +1 -1
  48. package/api/theme/themeTemplate.doc.mjs +2 -2
  49. package/api/theme/themeUse.doc.mjs +8 -2
  50. package/api/theme-edit/_adapter.d.mts +46 -3
  51. package/api/theme-edit/_adapter.mjs +496 -112
  52. package/api/theme-edit/_catalog.d.mts +1 -6
  53. package/api/theme-edit/_catalog.mjs +5 -268
  54. package/api/theme-edit/_check.d.mts +9 -4
  55. package/api/theme-edit/_check.mjs +1232 -229
  56. package/api/theme-edit/_color.d.mts +19 -0
  57. package/api/theme-edit/_color.mjs +280 -34
  58. package/api/theme-edit/_compiler.d.mts +3 -1
  59. package/api/theme-edit/_compiler.mjs +52 -13
  60. package/api/theme-edit/_context.d.mts +4 -1
  61. package/api/theme-edit/_context.mjs +126 -13
  62. package/api/theme-edit/_css.d.mts +84 -0
  63. package/api/theme-edit/_css.mjs +700 -0
  64. package/api/theme-edit/_edit.d.mts +9 -3
  65. package/api/theme-edit/_edit.mjs +806 -103
  66. package/api/theme-edit/_how-commands.d.mts +38 -7
  67. package/api/theme-edit/_how-commands.mjs +64 -45
  68. package/api/theme-edit/_how-question.d.mts +33 -0
  69. package/api/theme-edit/_how-question.mjs +2553 -381
  70. package/api/theme-edit/_how.mjs +402 -31
  71. package/api/theme-edit/_overview.mjs +2 -7
  72. package/api/theme-edit/_palette.d.mts +60 -13
  73. package/api/theme-edit/_palette.mjs +826 -295
  74. package/api/theme-edit/_parts.d.mts +42 -10
  75. package/api/theme-edit/_parts.mjs +280 -69
  76. package/api/theme-edit/_png.d.mts +4 -4
  77. package/api/theme-edit/_png.mjs +4 -2
  78. package/api/theme-edit/_preview-app.d.mts +14 -0
  79. package/api/theme-edit/_preview-app.mjs +1675 -235
  80. package/api/theme-edit/_preview.d.mts +7 -16
  81. package/api/theme-edit/_preview.mjs +79 -86
  82. package/api/theme-edit/_project.d.mts +32 -2
  83. package/api/theme-edit/_project.mjs +80 -19
  84. package/api/theme-edit/_settings.d.mts +199 -52
  85. package/api/theme-edit/_settings.mjs +1422 -217
  86. package/api/theme-edit/_tables.d.mts +19 -6
  87. package/api/theme-edit/_tables.mjs +150 -92
  88. package/api/theme-edit/theme-edit.type.d.mts +20 -1
  89. package/api/theme-edit/theme-edit.type.mjs +6 -3
  90. package/api/theme-edit/themeEditHow.doc.mjs +6 -0
  91. package/api/theme-edit/themeEditNew.doc.mjs +1 -1
  92. package/api/theme-edit/themeEditPreviewAdd.doc.mjs +1 -1
  93. package/api/theme-edit/themeEditPreviewApp.doc.mjs +1 -1
  94. package/api/theme-edit/themeEditPreviewList.doc.mjs +2 -2
  95. package/api/theme-edit/themeEditPreviewRemove.doc.mjs +5 -1
  96. package/api/theme-edit/themeEditSet.doc.mjs +1 -1
  97. package/api/theme-edit/themeEditUndo.doc.mjs +1 -1
  98. package/api/upgrade/_adapter.d.mts +1 -0
  99. package/assets/codemods/run-codemod.mjs +61 -0
  100. package/assets/codemods/runner.mjs +5 -4
  101. package/assets/codemods/transforms/v0.0.14/rename-status-variants.mjs +3 -0
  102. package/assets/codemods/transforms/v0.1.8/rename-avatar-size-scale.mjs +5 -1
  103. package/assets/codemods/transforms/v0.6.4/migrate-native-picker-to-presentation.mjs +3 -0
  104. package/assets/codemods/transforms/v0.7.0/migrate-deprecated-theme-surface.mjs +4 -0
  105. package/assets/codemods/transforms/v0.7.0/rename-empty-search-results-text.mjs +17 -12
  106. package/assets/codemods/transforms/v0.7.2/migrate-list-edge-compensation-to-edge.mjs +3 -0
  107. package/assets/codemods/transforms/v0.7.5/migrate-codeblock-tokenizer-to-language.mjs +3 -0
  108. package/assets/codemods/transforms/v0.7.8/promote-tokenizer-presentation.mjs +3 -0
  109. package/assets/docs/tree/calendars.doc.mjs +1 -3
  110. package/assets/docs/tree/checks.doc.mjs +22 -1
  111. package/assets/docs/tree/publishing.doc.mjs +1 -0
  112. package/assets/docs/tree/tokens-and-setup.doc.mjs +39 -3
  113. package/assets/docs.generated.json +2 -1
  114. package/assets/preview-app/next.config.mjs +7 -1
  115. package/assets/self-audit.generated.json +1 -0
  116. package/assets/templates/blocks/components/Theme/useThemeNameHookUsage.doc.mjs +14 -0
  117. package/assets/templates/blocks/components/Theme/useThemeNameHookUsage.tsx +31 -0
  118. package/assets/templates/components.generated.json +1 -1
  119. package/authoring/integration/integration.doc.mjs +8 -0
  120. package/authoring/integration/schema.d.mts +8 -0
  121. package/authoring/integration/schema.mjs +1 -0
  122. package/authoring/integration/type.ts +9 -0
  123. package/clients/cli/bin/astryx.mjs +19 -15
  124. package/clients/cli/build-id.generated.json +1 -0
  125. package/clients/cli/commands/ensure-core-built.mjs +12 -5
  126. package/clients/cli/commands/experimental/index.mjs +10 -10
  127. package/clients/cli/commands/experimental/theme.mjs +200 -81
  128. package/clients/cli/commands/experimental-theme-compile.doc.mjs +3 -3
  129. package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +1 -1
  130. package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +3 -3
  131. package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +1 -2
  132. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +1 -1
  133. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +2 -2
  134. package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
  135. package/clients/cli/commands/experimental-theme-eject.doc.mjs +3 -3
  136. package/clients/cli/commands/experimental-theme-preview-add.doc.mjs +1 -1
  137. package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
  138. package/clients/cli/commands/experimental-theme-preview-list.doc.mjs +1 -1
  139. package/clients/cli/commands/experimental-theme-preview-remove.doc.mjs +1 -1
  140. package/clients/cli/commands/experimental-theme-remove.doc.mjs +1 -1
  141. package/clients/cli/commands/experimental-theme-template.doc.mjs +4 -3
  142. package/clients/cli/commands/integration.mjs +8 -0
  143. package/clients/cli/commands/manifest.mjs +5 -2
  144. package/clients/cli/commands/theme-build.doc.mjs +2 -2
  145. package/clients/cli/commands/theme-list.doc.mjs +1 -1
  146. package/clients/cli/commands/theme-template.doc.mjs +1 -1
  147. package/clients/cli/commands/theme.mjs +439 -66
  148. package/clients/cli/index.mjs +27 -6
  149. package/clients/cli/lib/cli-error.mjs +118 -3
  150. package/clients/cli/lib/manifest.mjs +37 -0
  151. package/clients/cli/lib/resolve-theme.mjs +2 -1
  152. package/clients/cli/manifest.generated.json +1 -0
  153. package/foundation/config/project.mjs +34 -8
  154. package/foundation/config/theme-state.d.mts +16 -0
  155. package/foundation/config/theme-state.mjs +84 -13
  156. package/foundation/discovery/module-exports.mjs +16 -2
  157. package/foundation/discovery/stored-self-audit.d.mts +31 -0
  158. package/foundation/discovery/stored-self-audit.mjs +119 -0
  159. package/foundation/discovery/template-adapter.d.mts +48 -2
  160. package/foundation/discovery/template-adapter.mjs +51 -19
  161. package/foundation/discovery/template-needs.d.mts +19 -0
  162. package/foundation/discovery/template-needs.mjs +50 -16
  163. package/foundation/discovery/template-source-tree.d.mts +7 -0
  164. package/foundation/discovery/template-source-tree.mjs +15 -0
  165. package/foundation/discovery/theme-discovery.d.mts +2 -1
  166. package/foundation/discovery/theme-discovery.mjs +16 -10
  167. package/foundation/discovery/theme-imports.d.mts +16 -0
  168. package/foundation/discovery/theme-imports.mjs +30 -2
  169. package/foundation/discovery/theme-module-extensions.d.mts +18 -0
  170. package/foundation/discovery/theme-module-extensions.mjs +30 -0
  171. package/foundation/doc-compiler/import.mjs +22 -15
  172. package/foundation/doc-compiler/stored-docs.d.mts +18 -12
  173. package/foundation/doc-compiler/stored-docs.mjs +52 -19
  174. package/foundation/env/private-dir.d.mts +17 -0
  175. package/foundation/env/private-dir.mjs +42 -0
  176. package/foundation/fs/gather-cache.d.mts +108 -0
  177. package/foundation/fs/gather-cache.mjs +783 -0
  178. package/foundation/fs/jiti-cache.d.mts +21 -0
  179. package/foundation/fs/jiti-cache.mjs +66 -0
  180. package/foundation/fs/module-loader.mjs +14 -3
  181. package/foundation/fs/read-record.d.mts +31 -1
  182. package/foundation/fs/read-record.mjs +100 -7
  183. package/foundation/integrations/autolink.d.mts +1 -24
  184. package/foundation/integrations/autolink.mjs +7 -60
  185. package/foundation/integrations/declared-dependencies.d.mts +27 -0
  186. package/foundation/integrations/declared-dependencies.mjs +73 -0
  187. package/foundation/integrations/integrations.d.mts +8 -0
  188. package/foundation/integrations/integrations.mjs +4 -0
  189. package/foundation/integrations/may-have-integrations.d.mts +8 -0
  190. package/foundation/integrations/may-have-integrations.mjs +47 -0
  191. package/foundation/integrations/validate-contributions.d.mts +62 -1
  192. package/foundation/integrations/validate-contributions.mjs +476 -40
  193. package/foundation/release/cache.d.mts +32 -4
  194. package/foundation/release/cache.mjs +105 -16
  195. package/foundation/release/folder-lock.d.mts +28 -0
  196. package/foundation/release/folder-lock.mjs +205 -0
  197. package/foundation/release/lock-lease.d.mts +2 -1
  198. package/foundation/release/lock-lease.mjs +7 -2
  199. package/foundation/response/error-codes.doc.mjs +1 -1
  200. package/foundation/response/response-types.doc.mjs +5 -5
  201. package/package.json +8 -6
  202. package/api/theme-edit/_css-properties.d.mts +0 -10
  203. package/api/theme-edit/_css-properties.mjs +0 -556
@@ -2,8 +2,8 @@
2
2
  // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
3
 
4
4
  /**
5
- * Items of the theme-building page: each component once per variant, the
6
- * hand-made extras, overlays open, the sample page, and template pages
5
+ * Items of the theme-building page: each component once per variant
6
+ * (overlays open), the sample page, and template pages
7
7
  * whose packages the project has.
8
8
  * @param {import('./_project.mjs').ThemeProject} project
9
9
  * @param {string | undefined} group only this group
@@ -124,31 +124,22 @@ export function previewRouteSource({ pages, theme, by, }: {
124
124
  }): string;
125
125
  /**
126
126
  * A PNG of an HTML file, with a Playwright the project has installed, else
127
- * a Chrome or Chromium found on the machine. Null with a reason when neither
128
- * is there.
127
+ * a Chrome or Chromium found on the machine. Not ok with a reason when
128
+ * neither is there, or when one is there and fails: the reason then names
129
+ * its error.
129
130
  * @param {import('./_project.mjs').ThemeProject} project
130
131
  * @param {string} html absolute
131
132
  * @param {string} png absolute
132
133
  * @param {'light' | 'dark'} mode
133
- * @returns {Promise<{ok: true, file: string} | {ok: false, reason: string}>}
134
+ * @returns {Promise<{ok: true, file: string, cut?: boolean} | {ok: false, reason: string}>} `cut` when the picture is of the window, not the whole page
134
135
  */
135
136
  export function screenshot(project: import("./_project.mjs").ThemeProject, html: string, png: string, mode: "light" | "dark"): Promise<{
136
137
  ok: true;
137
138
  file: string;
139
+ cut?: boolean;
138
140
  } | {
139
141
  ok: false;
140
142
  reason: string;
141
143
  }>;
142
144
  /** The groups of the theme-building page, in order. */
143
145
  export const SHOWCASE_GROUPS: string[];
144
- export namespace SHOWCASE_GROUP_HELP {
145
- let actions: string;
146
- let inputs: string;
147
- let selection: string;
148
- let navigation: string;
149
- let feedback: string;
150
- let data: string;
151
- let containers: string;
152
- let overlays: string;
153
- let pages: string;
154
- }
@@ -17,19 +17,24 @@ import * as path from 'node:path';
17
17
  import {spawnSync} from 'node:child_process';
18
18
  import {fileURLToPath, pathToFileURL} from 'node:url';
19
19
  import {
20
- EXTRA,
21
- OPEN_OVERLAYS,
22
20
  SAMPLE_PAGE,
23
21
  SHEET_ORDER,
24
22
  elementNames,
25
23
  pageSource,
26
24
  } from './_catalog.mjs';
27
- import {renderDir, renderGenerated} from './_parts.mjs';
25
+ import {
26
+ catalogVariants,
27
+ isItemOf,
28
+ renderDir,
29
+ renderGenerated,
30
+ } from './_parts.mjs';
28
31
  import {OVERVIEW_SECTIONS} from './_overview.mjs';
29
- import {fontPackages, modesOf, themeFiles, shown} from './_settings.mjs';
32
+ import {camel, fontPackages, modesOf, themeFiles, shown} from './_settings.mjs';
30
33
  import {writeWhole} from './_palette.mjs';
31
34
  import {importPathOf, installLine} from './_project.mjs';
32
- import {DIRECT} from './_tables.mjs';
35
+ import {COLOR_PROP_PARTS, DIRECT, P} from './_tables.mjs';
36
+ import {extractImportedPackages} from '../../foundation/discovery/template-needs.mjs';
37
+ import {findNodeModulesPackage} from '../../foundation/fs/paths.mjs';
33
38
 
34
39
  const TEMPLATES_DIR = path.resolve(
35
40
  path.dirname(fileURLToPath(import.meta.url)),
@@ -49,20 +54,6 @@ export const SHOWCASE_GROUPS = [
49
54
  'pages',
50
55
  ];
51
56
 
52
- /** What each section of the sheet holds, for help and `show --section`. */
53
- export const SHOWCASE_GROUP_HELP = {
54
- actions: 'buttons and links',
55
- inputs: 'text, number, date and time fields, forms',
56
- selection: 'selectors, checkboxes, radios, switches, segmented controls',
57
- navigation: 'top and side navigation, tabs, breadcrumbs, pagination',
58
- feedback: 'banners, badges, progress, status dots, toasts',
59
- data: 'text, headings, tables, lists, code, content',
60
- containers: 'cards and layout',
61
- overlays: 'dialogs, popovers, menus and tooltips, shown open',
62
- pages:
63
- 'the sample app page and real template pages (dashboard, form, settings)',
64
- };
65
-
66
57
  /** Real template pages the theme-building page shows in full. */
67
58
  const PAGE_TEMPLATES = ['dashboard', 'contact-form', 'settings'];
68
59
 
@@ -90,8 +81,8 @@ function groupOf(name, category) {
90
81
  }
91
82
 
92
83
  /**
93
- * Items of the theme-building page: each component once per variant, the
94
- * hand-made extras, overlays open, the sample page, and template pages
84
+ * Items of the theme-building page: each component once per variant
85
+ * (overlays open), the sample page, and template pages
95
86
  * whose packages the project has.
96
87
  * @param {import('./_project.mjs').ThemeProject} project
97
88
  * @param {string | undefined} group only this group
@@ -101,39 +92,25 @@ export function showcaseItems(project, group) {
101
92
  /** @type {import('./_catalog.mjs').CatalogItem[]} */
102
93
  const items = [];
103
94
  /** @param {string} name */
104
- const groupFor = name =>
105
- groupOf(name, project.components[name]?.category ?? '');
106
- const extraNames = new Set([...EXTRA, ...OPEN_OVERLAYS].map(([n]) => n));
107
- for (const [name, list] of [...EXTRA, ...OPEN_OVERLAYS]) {
108
- const g = groupFor(name);
109
- if (g)
110
- for (const [label, tree] of list)
111
- items.push({group: g, name, label, tree});
112
- }
113
- for (const [name, info] of Object.entries(project.components)) {
114
- const defaults = /** @type {any} */ (info.defaults);
95
+ const groupFor = name => {
96
+ const info = project.components[name];
97
+ // A part with no category of its own sits with its parent.
98
+ const parent = info?.subComponentOf
99
+ ? project.components[info.subComponentOf]
100
+ : null;
101
+ return groupOf(name, info?.category || parent?.category || '');
102
+ };
103
+ for (const name of Object.keys(project.components)) {
115
104
  const g = groupFor(name);
116
- if (!g || !defaults || typeof defaults !== 'object' || extraNames.has(name))
117
- continue;
105
+ if (!g) continue;
118
106
  const inParent = inParentOf(project, name);
119
107
  if (inParent === null) continue;
120
- const values = info.targets[0]?.values ?? {};
121
- /** @type {Array<{label: string, props: Record<string, unknown>}>} */
122
- const variants = [{label: '', props: {}}];
123
- for (const p of ['variant', 'status', 'color'])
124
- for (const v of values[p] ?? [])
125
- variants.push({
126
- label: v,
127
- // A status like `{type: 'error', message?: string}` takes the
128
- // value as its `type`; the bare string breaks the component.
129
- props: {[p]: info.props?.[p]?.type.startsWith('{') ? {type: v} : v},
130
- });
131
- for (const v of variants.slice(0, 12))
108
+ for (const v of catalogVariants(project, name, 12, {shown: true}))
132
109
  items.push({
133
110
  group: g,
134
111
  name,
135
112
  label: v.label,
136
- tree: inParent({__element: name, props: {...defaults, ...v.props}}),
113
+ tree: inParent({__element: name, props: v.props}),
137
114
  });
138
115
  }
139
116
  items.push({
@@ -150,21 +127,10 @@ export function showcaseItems(project, group) {
150
127
  const file = path.join(TEMPLATES_DIR, t, 'page.tsx');
151
128
  if (!fs.existsSync(file)) continue;
152
129
  const src = fs.readFileSync(file, 'utf8');
153
- const missing = [
154
- ...src.matchAll(/^\s*(?:import|\})[^'"\n]*from\s+['"]([^'"]+)['"]/gm),
155
- ]
156
- .map(m => m[1])
157
- .filter(spec => !spec.startsWith('.') && !resolves(project, spec));
158
- if (missing.length) {
159
- const pkgs = [
160
- ...new Set(
161
- missing.map(s =>
162
- s.startsWith('@')
163
- ? s.split('/').slice(0, 2).join('/')
164
- : s.split('/')[0],
165
- ),
166
- ),
167
- ];
130
+ const pkgs = [...extractImportedPackages(src)].filter(
131
+ pkg => !findNodeModulesPackage(project.cwd, pkg),
132
+ );
133
+ if (pkgs.length) {
168
134
  skipped.push(
169
135
  `the ${t} page needs ${pkgs.join(', ')} (${installLine(project.cwd, pkgs)})`,
170
136
  );
@@ -219,23 +185,16 @@ function inParentOf(project, name) {
219
185
  const info = project.components[name];
220
186
  if (!info?.subComponentOf) return tree => tree;
221
187
  const wrapper = info.wrapper;
222
- if (!wrapper || project.components[wrapper.component]?.wrapper) return null;
188
+ // A part its parent does not list as an item, such as a heading of the
189
+ // text family, renders on its own.
190
+ if (!wrapper) return isItemOf(project, name) ? null : tree => tree;
191
+ if (project.components[wrapper.component]?.wrapper) return null;
223
192
  const props = Object.fromEntries(
224
193
  Object.entries(wrapper.props).filter(([k]) => !OPEN_PROPS.includes(k)),
225
194
  );
226
195
  return tree => ({__element: wrapper.component, props, children: [tree]});
227
196
  }
228
197
 
229
- /** @param {import('./_project.mjs').ThemeProject} project @param {string} spec */
230
- function resolves(project, spec) {
231
- try {
232
- project.req.resolve(spec);
233
- return true;
234
- } catch {
235
- return false;
236
- }
237
- }
238
-
239
198
  /**
240
199
  * Template page modules the theme-building page imports, copied beside it.
241
200
  * @param {Record<string, string>} imports
@@ -626,7 +585,7 @@ const CELL = [
626
585
  ' if (!row) return;',
627
586
  " const shown = Array.from(row.querySelectorAll('.tp-item > :not(.tp-label)')).some(el => {",
628
587
  ' const box = el.getBoundingClientRect();',
629
- " return (box.width > 2 && box.height > 2) || (el.textContent ?? '').trim() !== '';",
588
+ " return (box.width > 0 && box.height > 0 && (box.width > 2 || box.height > 2)) || (el.textContent ?? '').trim() !== '';",
630
589
  ' });',
631
590
  ' setEmpty(!shown);',
632
591
  ' }, []);',
@@ -657,7 +616,6 @@ function changeLine(project, C, name, theme) {
657
616
  const kebabName = name.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();
658
617
  const part = keys.includes(kebabName) ? kebabName : keys[0];
659
618
  if (!part) return null;
660
- const P = 'astryx experimental theme editor';
661
619
  const t = theme ?? '<theme>';
662
620
  for (const [aspect, value] of /** @type {const} */ ([
663
621
  ['background', '"<color>"'],
@@ -665,7 +623,10 @@ function changeLine(project, C, name, theme) {
665
623
  ['text', '"<color>"'],
666
624
  ]))
667
625
  if (C.partReads(part, aspect).length)
668
- return `${P} set ${t} ${DIRECT[aspect]} ${value} --on ${part}`;
626
+ // A part whose color comes from its color prop takes the text token.
627
+ return aspect === 'text' && COLOR_PROP_PARTS.includes(part)
628
+ ? `${P} set ${t} --color-text-primary ${value}`
629
+ : `${P} set ${t} ${DIRECT[aspect]} ${value} --on ${part}`;
669
630
  if (C.showsCorners(part)) return `${P} set ${t} corners round --on ${part}`;
670
631
  return `${P} how ${part}`;
671
632
  }
@@ -691,7 +652,12 @@ const PAGE_SKIP = new Set([
691
652
  */
692
653
  export function componentsPageSource(project, {theme = null, C} = {}) {
693
654
  const items = showcaseItems(project, undefined)
694
- .items.filter(it => it.group !== 'pages' && !PAGE_SKIP.has(it.name))
655
+ .items.filter(
656
+ it =>
657
+ it.group !== 'pages' &&
658
+ !PAGE_SKIP.has(it.name) &&
659
+ !project.components[it.name]?.overlay,
660
+ )
695
661
  .map(it => ({
696
662
  ...it,
697
663
  tree: withHandlers(withSources(project, withCoreNames(project, it.tree))),
@@ -715,7 +681,7 @@ export function componentsPageSource(project, {theme = null, C} = {}) {
715
681
  const body = list
716
682
  .map(
717
683
  it =>
718
- ` <div className="tp-item">${it.label ? `\n <div className="tp-label">${it.label}</div>` : ''}\n <Safe name=${JSON.stringify(name)}>\n ${jsx(/** @type {any} */ (it.tree), 7)}\n </Safe>\n </div>`,
684
+ ` <div className="${project.components[name]?.category === 'Layout' ? 'tp-item tp-fill' : 'tp-item'}">${it.label ? `\n <div className="tp-label">${it.label}</div>` : ''}\n <Safe name=${JSON.stringify(name)}>\n ${jsx(/** @type {any} */ (it.tree), 7)}\n </Safe>\n </div>`,
719
685
  )
720
686
  .join('\n');
721
687
  const line = C ? changeLine(project, C, name, theme) : null;
@@ -725,7 +691,7 @@ export function componentsPageSource(project, {theme = null, C} = {}) {
725
691
  return ` <section>\n <h2 className="tp-group">${GROUP_TITLES[g] ?? g}</h2>\n <div className="tp-grid">\n${cells}\n </div>\n </section>`;
726
692
  })
727
693
  .join('\n');
728
- const css = `.tp-group{font:600 14px ui-monospace,monospace;margin:16px 14px 0;opacity:.75}.tp-grid{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:14px;padding:14px}.tp-cell{border:1px dashed #8885;padding:10px;overflow:hidden}.tp-name{font:600 12px ui-monospace,monospace;opacity:.6;margin-bottom:8px}.tp-row{display:flex;flex-wrap:wrap;gap:10px;align-items:flex-start}.tp-label{font:10px ui-monospace,monospace;opacity:.5}.tp-cmd{display:block;margin-top:10px;font:10px ui-monospace,monospace;opacity:.75;overflow-wrap:break-word}.tp-note{font:11px ui-monospace,monospace;opacity:.6;padding:6px 8px;border:1px dashed #8886}`;
694
+ const css = `.tp-group{font:600 14px ui-monospace,monospace;margin:16px 14px 0;opacity:.75}.tp-grid{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:14px;padding:14px;align-items:start}.tp-cell{border:1px dashed #8885;padding:10px;overflow:hidden}.tp-name{font:600 12px ui-monospace,monospace;opacity:.6;margin-bottom:8px}.tp-row{display:flex;flex-wrap:wrap;gap:10px;align-items:flex-start}.tp-fill{flex:1 1 100%;max-height:300px;overflow:auto}.tp-label{font:10px ui-monospace,monospace;opacity:.5}.tp-cmd{display:block;margin-top:10px;font:10px ui-monospace,monospace;opacity:.75;overflow-wrap:break-word}.tp-note{font:11px ui-monospace,monospace;opacity:.6;padding:6px 8px;border:1px dashed #8886}`;
729
695
  const source = [
730
696
  '// Written by `astryx experimental theme preview add`: every component grouped, each variant side by side, overlays open.',
731
697
  "'use client';",
@@ -1081,19 +1047,30 @@ export function previewRouteSource({
1081
1047
  }
1082
1048
 
1083
1049
  /** @param {string} slug */
1084
- const camelName = slug => slug.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
1050
+ const camelName = camel;
1085
1051
 
1086
1052
  /**
1087
1053
  * A PNG of an HTML file, with a Playwright the project has installed, else
1088
- * a Chrome or Chromium found on the machine. Null with a reason when neither
1089
- * is there.
1054
+ * a Chrome or Chromium found on the machine. Not ok with a reason when
1055
+ * neither is there, or when one is there and fails: the reason then names
1056
+ * its error.
1090
1057
  * @param {import('./_project.mjs').ThemeProject} project
1091
1058
  * @param {string} html absolute
1092
1059
  * @param {string} png absolute
1093
1060
  * @param {'light' | 'dark'} mode
1094
- * @returns {Promise<{ok: true, file: string} | {ok: false, reason: string}>}
1061
+ * @returns {Promise<{ok: true, file: string, cut?: boolean} | {ok: false, reason: string}>} `cut` when the picture is of the window, not the whole page
1095
1062
  */
1096
1063
  export async function screenshot(project, html, png, mode) {
1064
+ /** What was found and why it could not take the picture. @type {string[]} */
1065
+ const failed = [];
1066
+ /** The first line of an error, with no path of this machine. @param {unknown} e */
1067
+ const firstLine = e =>
1068
+ String(/** @type {any} */ (e)?.message ?? e ?? '')
1069
+ .split('\n')
1070
+ .map(l => l.trim())
1071
+ .find(Boolean)
1072
+ ?.split(project.cwd)
1073
+ .join('.') ?? 'it stopped with no message';
1097
1074
  for (const pkg of ['playwright', 'playwright-core']) {
1098
1075
  /** @type {string} */
1099
1076
  let entry;
@@ -1119,8 +1096,9 @@ export async function screenshot(project, html, png, mode) {
1119
1096
  await browser.close();
1120
1097
  }
1121
1098
  return {ok: true, file: shown(project.cwd, png)};
1122
- } catch {
1123
- // This Playwright has no browser to launch: try Chrome directly.
1099
+ } catch (e) {
1100
+ // This Playwright could not launch its browser: try Chrome directly.
1101
+ failed.push(`${pkg}: ${firstLine(e)}`);
1124
1102
  }
1125
1103
  }
1126
1104
  const chrome = chromeBinary();
@@ -1139,9 +1117,24 @@ export async function screenshot(project, html, png, mode) {
1139
1117
  ],
1140
1118
  {encoding: 'utf8', timeout: 60_000},
1141
1119
  );
1120
+ // Chrome alone takes the window, not the whole page.
1142
1121
  if (r.status === 0 && fs.existsSync(png))
1143
- return {ok: true, file: shown(project.cwd, png)};
1122
+ return {ok: true, file: shown(project.cwd, png), cut: true};
1123
+ failed.push(
1124
+ `${chrome}: ${firstLine(
1125
+ r.error ??
1126
+ (r.stderr ||
1127
+ (r.signal
1128
+ ? `stopped by ${r.signal}`
1129
+ : `exit ${r.status}, and no picture was written`)),
1130
+ )}`,
1131
+ );
1144
1132
  }
1133
+ if (failed.length)
1134
+ return {
1135
+ ok: false,
1136
+ reason: `A browser was found, but it could not take the picture (${failed.join('; ')}). Give Playwright its browser (npx playwright install chromium), or check that ${chrome ?? 'Google Chrome or Chromium'} starts on this machine. The HTML preview needs neither.`,
1137
+ };
1145
1138
  return {
1146
1139
  ok: false,
1147
1140
  reason: `No browser was found to take the picture. Install Playwright with its browser (${installLine(project.cwd, ['playwright'])}, then npx playwright install chromium), or install Google Chrome or Chromium. The HTML preview needs neither.`,
@@ -1,6 +1,16 @@
1
1
  // @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
2
2
  // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
3
 
4
+ /**
5
+ * The theme editor's cache folder for a project: the `.cache/astryx-theme`
6
+ * of the node_modules that holds the Core the command reads (the
7
+ * project's own, or a workspace root's). The locks and the part-data cache
8
+ * both live here, so one command never finds two answers. Null without
9
+ * Core.
10
+ * @param {string} dir
11
+ * @returns {string | null}
12
+ */
13
+ export function themeCacheRoot(dir: string): string | null;
4
14
  /**
5
15
  * The install line for packages, in the project's package manager.
6
16
  * @param {string} cwd
@@ -33,12 +43,14 @@ export function baseThemeFile(project: ThemeProject, like: string): string;
33
43
  * Resolved tokens of the base theme in both modes.
34
44
  * @param {ThemeProject} project
35
45
  * @param {string | undefined} like
36
- * @returns {Promise<{light: Record<string, string>, dark: Record<string, string>}>}
46
+ * @returns {Promise<{light: Record<string, string>, dark: Record<string, string>, components: Record<string, any>}>}
37
47
  */
38
48
  export function baseResolved(project: ThemeProject, like: string | undefined): Promise<{
39
49
  light: Record<string, string>;
40
50
  dark: Record<string, string>;
51
+ components: Record<string, any>;
41
52
  }>;
53
+ export function literals(type: string): string[];
42
54
  export type ThemeProject = {
43
55
  cwd: string;
44
56
  /**
@@ -83,19 +95,37 @@ export type ComponentInfo = {
83
95
  component: string;
84
96
  props: Record<string, unknown>;
85
97
  } | null;
98
+ /**
99
+ * - An overlay its playground shows in place: the pages render it open.
100
+ */
101
+ opens: boolean;
102
+ /**
103
+ * - Its playground opens it over the whole page, so a page of components leaves it out.
104
+ */
105
+ overlay: boolean;
86
106
  /**
87
107
  * - The component it is a part of, or null.
88
108
  */
89
109
  subComponentOf: string | null;
90
110
  /**
91
- * - Each prop's declared type and whether it is required.
111
+ * - The doc's search keywords.
112
+ */
113
+ keywords: string[];
114
+ /**
115
+ * - Each prop's declared type, whether it is required, and the elements the doc suggests for it.
92
116
  */
93
117
  props: Record<string, {
94
118
  type: string;
95
119
  required: boolean;
120
+ slots: Array<{
121
+ __element: string;
122
+ props?: Record<string, unknown>;
123
+ children?: unknown;
124
+ }>;
96
125
  }>;
97
126
  targets: Array<{
98
127
  className: string;
128
+ states: string[];
99
129
  values: Record<string, string[]>;
100
130
  }>;
101
131
  };
@@ -21,6 +21,7 @@ import {loadComponentDoc} from '../../foundation/discovery/component-loader.mjs'
21
21
  import {collectThemingTargets} from '../../foundation/discovery/theming-targets.mjs';
22
22
  import {resolveImportPath} from '../../foundation/discovery/component-discovery.mjs';
23
23
  import {detectPackageManager} from '../../foundation/env/package-manager.mjs';
24
+ import {findProjectCoreDir} from '../../foundation/fs/paths.mjs';
24
25
 
25
26
  /**
26
27
  * @typedef {object} ThemeProject
@@ -42,16 +43,44 @@ import {detectPackageManager} from '../../foundation/env/package-manager.mjs';
42
43
  * @property {string} category - The doc's category, such as Action or Overlay.
43
44
  * @property {unknown} defaults - Playground defaults, or null.
44
45
  * @property {{component: string, props: Record<string, unknown>} | null} wrapper - The parent the playground renders it in, or null.
46
+ * @property {boolean} opens - An overlay its playground shows in place: the pages render it open.
47
+ * @property {boolean} overlay - Its playground opens it over the whole page, so a page of components leaves it out.
45
48
  * @property {string | null} subComponentOf - The component it is a part of, or null.
46
- * @property {Record<string, {type: string, required: boolean}>} props - Each prop's declared type and whether it is required.
47
- * @property {Array<{className: string, values: Record<string, string[]>}>} targets
49
+ * @property {string[]} keywords - The doc's search keywords.
50
+ * @property {Record<string, {type: string, required: boolean, slots: Array<{__element: string, props?: Record<string, unknown>, children?: unknown}>}>} props - Each prop's declared type, whether it is required, and the elements the doc suggests for it.
51
+ * @property {Array<{className: string, states: string[], values: Record<string, string[]>}>} targets
48
52
  */
49
53
 
50
54
  /** @type {Map<string, ThemeProject>} */
51
55
  const projects = new Map();
52
56
 
53
57
  /** Bump when the shape of the cached component docs changes. */
54
- const DOCS_VERSION = 2;
58
+ const DOCS_VERSION = 5;
59
+
60
+ /**
61
+ * The theme editor's cache folder for a project: the `.cache/astryx-theme`
62
+ * of the node_modules that holds the Core the command reads (the
63
+ * project's own, or a workspace root's). The locks and the part-data cache
64
+ * both live here, so one command never finds two answers. Null without
65
+ * Core.
66
+ * @param {string} dir
67
+ * @returns {string | null}
68
+ */
69
+ export function themeCacheRoot(dir) {
70
+ const core = findProjectCoreDir(dir);
71
+ if (!core) return null;
72
+ // Core read from source (a fork of the design system, packages/core) is
73
+ // in no node_modules: the cache goes in the project's own node_modules,
74
+ // never in a source folder.
75
+ const modules = path.dirname(path.dirname(core));
76
+ if (
77
+ path.basename(path.dirname(core)) === '@astryxdesign' &&
78
+ path.basename(modules) === 'node_modules'
79
+ )
80
+ return path.join(modules, '.cache', 'astryx-theme');
81
+ const own = nodeModulesRoot(dir);
82
+ return own ? path.join(own, 'node_modules', '.cache', 'astryx-theme') : null;
83
+ }
55
84
 
56
85
  /**
57
86
  * The nearest folder at or above `dir` that holds node_modules.
@@ -76,7 +105,7 @@ export function installLine(cwd, packages) {
76
105
  }
77
106
 
78
107
  /** @param {string} type @returns {string[]} */
79
- const literals = type =>
108
+ export const literals = type =>
80
109
  [...String(type ?? '').matchAll(/'([^']+)'/g)].map(m => m[1]);
81
110
 
82
111
  /**
@@ -106,33 +135,59 @@ async function readComponents(coreDir) {
106
135
  continue;
107
136
  }
108
137
  if (!doc || typeof doc.name !== 'string') continue;
138
+ // A doc for several components lists each one's props under its own
139
+ // entry.
140
+ const mine = (Array.isArray(doc.components) ? doc.components : []).find(
141
+ (/** @type {any} */ c) => c?.name === doc.name,
142
+ );
143
+ const own = Array.isArray(doc.props) ? doc.props : mine?.props;
144
+ // Its playground too: the doc's, or its own entry's.
145
+ const pg = doc.playground ?? mine?.playground;
109
146
  /** @type {Record<string, any>} */
110
147
  const props = Object.fromEntries(
111
- (Array.isArray(doc.props) ? doc.props : []).map(
112
- (/** @type {any} */ p) => [p.name, p],
113
- ),
148
+ (Array.isArray(own) ? own : []).map((/** @type {any} */ p) => [
149
+ p.name,
150
+ p,
151
+ ]),
114
152
  );
115
153
  out[doc.name] = {
116
154
  importPath: resolveImportPath(coreDir, doc.name),
117
155
  category: typeof doc.category === 'string' ? doc.category : '',
118
- defaults: doc.playground?.defaults ?? null,
156
+ defaults: pg?.defaults ?? null,
119
157
  wrapper:
120
- typeof doc.playground?.wrapper?.component === 'string'
158
+ typeof pg?.wrapper?.component === 'string'
121
159
  ? {
122
- component: doc.playground.wrapper.component,
123
- props: doc.playground.wrapper.props ?? {},
160
+ component: pg.wrapper.component,
161
+ props: pg.wrapper.props ?? {},
124
162
  }
125
163
  : null,
164
+ overlay: pg?.overlay === true,
165
+ // An overlay with an open state, unless its playground opens it as
166
+ // a real overlay over the page.
167
+ opens:
168
+ doc.category === 'Overlay' &&
169
+ pg?.overlay !== true &&
170
+ [doc, ...(Array.isArray(doc.components) ? doc.components : [])].some(
171
+ (/** @type {any} */ d) =>
172
+ Array.isArray(d?.props) &&
173
+ d.props.some((/** @type {any} */ p) => p?.name === 'isOpen'),
174
+ ),
126
175
  subComponentOf:
127
176
  typeof doc.subComponentOf === 'string' ? doc.subComponentOf : null,
177
+ keywords: Array.isArray(doc.keywords) ? doc.keywords.map(String) : [],
128
178
  props: Object.fromEntries(
129
179
  Object.entries(props).map(([n, p]) => [
130
180
  n,
131
- {type: String(p.type ?? ''), required: p.required === true},
181
+ {
182
+ type: String(p.type ?? ''),
183
+ required: p.required === true,
184
+ slots: Array.isArray(p.slotElements) ? p.slotElements : [],
185
+ },
132
186
  ]),
133
187
  ),
134
188
  targets: (doc.theming?.targets ?? []).map((/** @type {any} */ t) => ({
135
189
  className: t.className,
190
+ states: Array.isArray(t.states) ? t.states.map(String) : [],
136
191
  values: Object.fromEntries(
137
192
  (t.visualProps ?? []).map((/** @type {string} */ v) => {
138
193
  const p = props[v];
@@ -201,13 +256,15 @@ export async function openProject(cwd) {
201
256
  // No stylesheet: the part data is empty, and the version alone keys it.
202
257
  }
203
258
  const coreKey = `${coreVersion}-${fingerprint}`;
204
- const root = nodeModulesRoot(key) ?? key;
205
259
  const core = await import(pathToFileURL(themeFile).href);
206
260
  const cacheDir = path.join(
207
- root,
208
- 'node_modules',
209
- '.cache',
210
- 'astryx-theme',
261
+ themeCacheRoot(key) ??
262
+ path.join(
263
+ nodeModulesRoot(key) ?? key,
264
+ 'node_modules',
265
+ '.cache',
266
+ 'astryx-theme',
267
+ ),
211
268
  coreKey,
212
269
  );
213
270
  // Reading every component doc takes a second; it is fixed per Core install.
@@ -287,7 +344,7 @@ export function baseThemeFile(project, like) {
287
344
  * Resolved tokens of the base theme in both modes.
288
345
  * @param {ThemeProject} project
289
346
  * @param {string | undefined} like
290
- * @returns {Promise<{light: Record<string, string>, dark: Record<string, string>}>}
347
+ * @returns {Promise<{light: Record<string, string>, dark: Record<string, string>, components: Record<string, any>}>}
291
348
  */
292
349
  export async function baseResolved(project, like) {
293
350
  const {core} = project;
@@ -300,8 +357,12 @@ export async function baseResolved(project, like) {
300
357
  v => v && typeof v === 'object' && typeof v.name === 'string',
301
358
  );
302
359
  }
303
- return {
360
+ const out = {
304
361
  light: core.resolveThemeTokens(theme, {mode: 'light'}),
305
362
  dark: core.resolveThemeTokens(theme, {mode: 'dark'}),
363
+ // The base theme's own part styles (neutral's pale destructive button),
364
+ // which a one-mode setting keeps in the other mode.
365
+ components: theme.components ?? {},
306
366
  };
367
+ return out;
307
368
  }