@astryxdesign/cli 0.7.14-canary.gfb823d9 → 0.7.14

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 (135) hide show
  1. package/CHANGELOG.md +197 -0
  2. package/api/component/_adapter.d.mts +15 -0
  3. package/api/component/_adapter.mjs +76 -0
  4. package/api/component/component.mjs +8 -1
  5. package/api/search/_named-keywords.d.mts +31 -0
  6. package/api/search/_named-keywords.mjs +177 -0
  7. package/api/search/search-index.mjs +8 -1
  8. package/api/search/search.d.mts +6 -1
  9. package/api/search/search.mjs +49 -8
  10. package/api/theme/_adapter.d.mts +33 -0
  11. package/api/theme/_adapter.mjs +352 -16
  12. package/api/theme/build/build.mjs +261 -10
  13. package/api/theme/eject/eject.mjs +13 -1
  14. package/api/theme/list/list.mjs +11 -2
  15. package/api/theme/palette/generate/color.d.mts +2 -0
  16. package/api/theme/palette/generate/color.mjs +1 -1
  17. package/api/theme/template/template.mjs +139 -6
  18. package/api/theme/theme.type.d.mts +15 -1
  19. package/api/theme/theme.type.mjs +9 -3
  20. package/api/theme/themeAdd.doc.mjs +1 -1
  21. package/api/theme/themeBuild.doc.mjs +10 -2
  22. package/api/theme/themeEject.doc.mjs +2 -2
  23. package/api/theme/themeListAvailable.doc.mjs +1 -1
  24. package/api/theme/themeRemove.doc.mjs +1 -1
  25. package/api/theme/themeTemplate.doc.mjs +8 -0
  26. package/api/theme/themeUse.doc.mjs +1 -1
  27. package/api/theme-edit/_adapter.d.mts +36 -2
  28. package/api/theme-edit/_adapter.mjs +340 -12
  29. package/api/theme-edit/_check.d.mts +28 -25
  30. package/api/theme-edit/_check.mjs +876 -308
  31. package/api/theme-edit/_color.d.mts +53 -4
  32. package/api/theme-edit/_color.mjs +406 -79
  33. package/api/theme-edit/_compiler.d.mts +14 -6
  34. package/api/theme-edit/_compiler.mjs +89 -59
  35. package/api/theme-edit/_context.d.mts +28 -8
  36. package/api/theme-edit/_context.mjs +142 -19
  37. package/api/theme-edit/_edit.d.mts +3 -1
  38. package/api/theme-edit/_edit.mjs +746 -76
  39. package/api/theme-edit/_how-commands.d.mts +91 -0
  40. package/api/theme-edit/_how-commands.mjs +269 -0
  41. package/api/theme-edit/_how-question.d.mts +57 -0
  42. package/api/theme-edit/_how-question.mjs +2574 -0
  43. package/api/theme-edit/_how.d.mts +27 -8
  44. package/api/theme-edit/_how.mjs +776 -175
  45. package/api/theme-edit/_overview.d.mts +9 -0
  46. package/api/theme-edit/_overview.mjs +296 -0
  47. package/api/theme-edit/_palette.d.mts +155 -15
  48. package/api/theme-edit/_palette.mjs +1446 -262
  49. package/api/theme-edit/_parts.mjs +61 -5
  50. package/api/theme-edit/_png.d.mts +18 -6
  51. package/api/theme-edit/_png.mjs +135 -25
  52. package/api/theme-edit/_preview-app.d.mts +32 -11
  53. package/api/theme-edit/_preview-app.mjs +1976 -285
  54. package/api/theme-edit/_preview.d.mts +39 -8
  55. package/api/theme-edit/_preview.mjs +367 -41
  56. package/api/theme-edit/_settings.d.mts +147 -11
  57. package/api/theme-edit/_settings.mjs +908 -99
  58. package/api/theme-edit/_tables.d.mts +4 -16
  59. package/api/theme-edit/_tables.mjs +51 -117
  60. package/api/theme-edit/theme-edit.type.d.mts +102 -66
  61. package/api/theme-edit/theme-edit.type.mjs +58 -40
  62. package/api/theme-edit/themeEditHow.doc.mjs +17 -6
  63. package/api/theme-edit/themeEditNew.doc.mjs +21 -5
  64. package/api/theme-edit/themeEditPreviewAdd.doc.mjs +18 -5
  65. package/api/theme-edit/themeEditPreviewApp.doc.mjs +12 -9
  66. package/api/theme-edit/themeEditPreviewList.doc.mjs +11 -2
  67. package/api/theme-edit/themeEditPreviewRemove.doc.mjs +29 -3
  68. package/api/theme-edit/themeEditSet.doc.mjs +14 -8
  69. package/api/theme-edit/themeEditShow.doc.mjs +10 -5
  70. package/api/theme-edit/themeEditUndo.doc.mjs +9 -4
  71. package/assets/discover/official-packages.json +4 -0
  72. package/assets/docs/tree/icon-sets.doc.mjs +3 -3
  73. package/assets/docs.generated.json +1 -0
  74. package/assets/icons/definitions/bookmarkAdd.doc.mjs +9 -0
  75. package/assets/icons/definitions/documentSearch.doc.mjs +9 -0
  76. package/assets/icons/definitions/keyboard.doc.mjs +9 -0
  77. package/assets/icons/definitions/paintBrush.doc.mjs +9 -0
  78. package/assets/icons/definitions/wallet.doc.mjs +9 -0
  79. package/assets/preview-app/gitignore +3 -0
  80. package/assets/templates/blocks/components/ButtonGroup/ButtonGroupShowcase.doc.mjs +1 -1
  81. package/assets/templates/blocks/components/Lightbox/LightboxGallery.tsx +1 -1
  82. package/assets/templates/components.generated.json +1 -0
  83. package/assets/templates/pages/gallery-hero/page.tsx +8 -2
  84. package/assets/templates/pages/settings-dialog/template.doc.mjs +3 -3
  85. package/assets/templates/pages/side-gallery/page.tsx +1 -1
  86. package/assets/templates/pages/table-filter/template.doc.mjs +2 -2
  87. package/assets/templates/pages/theme-showcase/template.doc.mjs +1 -1
  88. package/clients/cli/bin/astryx.mjs +37 -5
  89. package/clients/cli/commands/experimental/theme.mjs +422 -57
  90. package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +22 -9
  91. package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +103 -4
  92. package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +13 -8
  93. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +5 -5
  94. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +5 -5
  95. package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
  96. package/clients/cli/commands/experimental-theme-preview-add.doc.mjs +3 -2
  97. package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +2 -8
  98. package/clients/cli/commands/experimental-theme-preview-list.doc.mjs +2 -2
  99. package/clients/cli/commands/experimental-theme-preview-remove.doc.mjs +2 -2
  100. package/clients/cli/commands/experimental-theme-targets.doc.mjs +1 -1
  101. package/clients/cli/commands/experimental-theme.doc.mjs +3 -4
  102. package/clients/cli/commands/theme-build.doc.mjs +1 -1
  103. package/clients/cli/commands/theme-eject.doc.mjs +3 -3
  104. package/clients/cli/commands/theme-remove.doc.mjs +2 -2
  105. package/clients/cli/commands/theme-template.doc.mjs +11 -4
  106. package/clients/cli/commands/theme.mjs +145 -46
  107. package/clients/cli/commands.generated.json +1 -0
  108. package/clients/cli/index.mjs +96 -5
  109. package/clients/cli/lib/json-shim.mjs +29 -1
  110. package/foundation/config/project.d.mts +16 -2
  111. package/foundation/config/project.mjs +40 -6
  112. package/foundation/config/theme-state.d.mts +9 -0
  113. package/foundation/config/theme-state.mjs +20 -1
  114. package/foundation/discovery/template-adapter.d.mts +12 -1
  115. package/foundation/discovery/template-adapter.mjs +29 -4
  116. package/foundation/discovery/template-icons.d.mts +13 -0
  117. package/foundation/discovery/template-icons.mjs +76 -0
  118. package/foundation/discovery/template-needs.d.mts +7 -0
  119. package/foundation/discovery/template-needs.mjs +117 -8
  120. package/foundation/discovery/template-source-tree.d.mts +5 -1
  121. package/foundation/discovery/template-source-tree.mjs +6 -4
  122. package/foundation/discovery/theme-discovery.d.mts +14 -3
  123. package/foundation/discovery/theme-discovery.mjs +45 -12
  124. package/foundation/doc-compiler/import.mjs +68 -3
  125. package/foundation/doc-compiler/stored-docs.d.mts +27 -0
  126. package/foundation/doc-compiler/stored-docs.mjs +65 -0
  127. package/foundation/fs/fs-error.d.mts +17 -0
  128. package/foundation/fs/fs-error.mjs +34 -0
  129. package/foundation/response/error-codes.d.mts +3 -1
  130. package/foundation/response/error-codes.doc.mjs +13 -1
  131. package/foundation/response/error-codes.mjs +11 -1
  132. package/foundation/response/response-types.doc.mjs +6 -6
  133. package/package.json +6 -7
  134. package/clients/cli/commands/experimental-theme-palette-generate.doc.mjs +0 -73
  135. package/clients/cli/commands/experimental-theme-palette.doc.mjs +0 -37
@@ -55,31 +55,60 @@ export function renderSheet(ctx: import("./_settings.mjs").Ctx, slug: string, da
55
55
  * The source of the preview's components page: every component grouped,
56
56
  * each variant side by side, overlays open. Template pages are pages of
57
57
  * their own (`preview add --template`), so they are not on it.
58
+ * Under each cell, one line: the command that changes the component most,
59
+ * from what its part reads (`how <part>`).
58
60
  * @param {import('./_project.mjs').ThemeProject} project
61
+ * @param {{theme?: string | null, C?: import('./_compiler.mjs').Compiler}} [options]
59
62
  * @returns {{source: string, components: number}}
60
63
  */
61
- export function componentsPageSource(project: import("./_project.mjs").ThemeProject): {
64
+ export function componentsPageSource(project: import("./_project.mjs").ThemeProject, { theme, C }?: {
65
+ theme?: string | null;
66
+ C?: import("./_compiler.mjs").Compiler;
67
+ }): {
62
68
  source: string;
63
69
  components: number;
64
70
  };
65
71
  /**
66
- * The source of the preview's overview page: the content of the sample app
67
- * page. The preview route is the app shell, so the page has no shell of its
68
- * own.
72
+ * The source of the preview's Overview page: the theme at a glance, built
73
+ * to show what themes most often break (see _overview.mjs). A header names
74
+ * the theme, its fonts and its main colors; each section renders inside a
75
+ * boundary, so one part that throws never blanks the page. The preview
76
+ * route is the app shell, so the page has no shell of its own.
69
77
  * @param {import('./_project.mjs').ThemeProject} project
78
+ * @param {{theme?: string | null}} [options]
70
79
  * @returns {string}
71
80
  */
72
- export function overviewPageSource(project: import("./_project.mjs").ThemeProject): string;
81
+ export function overviewPageSource(project: import("./_project.mjs").ThemeProject, { theme }?: {
82
+ theme?: string | null;
83
+ }): string;
84
+ /**
85
+ * The source of the preview's Colors page: each generated color's shades in
86
+ * light and dark, with the shade number, the hex, and the tokens that use
87
+ * it. The shades come from the theme's generated color module, so the page
88
+ * follows every change; `uses` and `seeds` are written in by the editor.
89
+ * With no generated colors, the page says how to set one.
90
+ * @param {{slug: string, module: string | null, seeds: Record<string, string>, uses: Record<string, Record<'light' | 'dark', Record<string, string[]>>>}} colors
91
+ * `module`: the import of the generated colors from the page, or null.
92
+ * @returns {string}
93
+ */
94
+ export function colorsPageSource({ slug, module, seeds, uses }: {
95
+ slug: string;
96
+ module: string | null;
97
+ seeds: Record<string, string>;
98
+ uses: Record<string, Record<"light" | "dark", Record<string, string[]>>>;
99
+ }): string;
73
100
  /**
74
101
  * The source of the preview route: an app shell with a side nav item per
75
102
  * preview page, a top bar with the theme name and, with a theme, a
76
103
  * light/dark/system switch, and the selected page in the content area. It is a normal page of
77
104
  * the app, so it keeps the app's layout, global CSS and providers.
78
- * @param {{pages: Array<{id: string, label: string, file: string}>, theme: {name: string, module: string, css: string[]} | null}} spec
79
- * `file` relative to the route folder, without extension; no theme: the app's own theme
105
+ * @param {{pages: Array<{id: string, label: string, file: string}>, theme: {name: string, module: string, css: string[], mode?: 'system' | 'light' | 'dark'} | null, by?: string}} spec
106
+ * `file` relative to the route folder, without extension; no theme: the
107
+ * app's own theme. A theme with one mode starts in it, with no switch.
108
+ * `by`: the command that wrote the route, for its header.
80
109
  * @returns {string}
81
110
  */
82
- export function previewRouteSource({ pages, theme }: {
111
+ export function previewRouteSource({ pages, theme, by, }: {
83
112
  pages: Array<{
84
113
  id: string;
85
114
  label: string;
@@ -89,7 +118,9 @@ export function previewRouteSource({ pages, theme }: {
89
118
  name: string;
90
119
  module: string;
91
120
  css: string[];
121
+ mode?: "system" | "light" | "dark";
92
122
  } | null;
123
+ by?: string;
93
124
  }): string;
94
125
  /**
95
126
  * A PNG of an HTML file, with a Playwright the project has installed, else
@@ -25,8 +25,11 @@ import {
25
25
  pageSource,
26
26
  } from './_catalog.mjs';
27
27
  import {renderDir, renderGenerated} from './_parts.mjs';
28
+ import {OVERVIEW_SECTIONS} from './_overview.mjs';
28
29
  import {fontPackages, modesOf, themeFiles, shown} from './_settings.mjs';
30
+ import {writeWhole} from './_palette.mjs';
29
31
  import {importPathOf, installLine} from './_project.mjs';
32
+ import {DIRECT} from './_tables.mjs';
30
33
 
31
34
  const TEMPLATES_DIR = path.resolve(
32
35
  path.dirname(fileURLToPath(import.meta.url)),
@@ -46,7 +49,7 @@ export const SHOWCASE_GROUPS = [
46
49
  'pages',
47
50
  ];
48
51
 
49
- /** What each group holds, for help and `--group`. */
52
+ /** What each section of the sheet holds, for help and `show --section`. */
50
53
  export const SHOWCASE_GROUP_HELP = {
51
54
  actions: 'buttons and links',
52
55
  inputs: 'text, number, date and time fields, forms',
@@ -303,7 +306,8 @@ export async function renderPreview(ctx, slug, data) {
303
306
  });
304
307
  const {html} = await renderGenerated(project, `preview-${slug}.mjs`, source);
305
308
  const out = themeFiles(project.cwd, slug).preview;
306
- fs.writeFileSync(out, html);
309
+ // Written whole and renamed in, never through a link.
310
+ writeWhole(out, html);
307
311
  return shown(project.cwd, out);
308
312
  }
309
313
 
@@ -331,9 +335,16 @@ export async function renderSheet(ctx, slug, data, options = {}) {
331
335
  source,
332
336
  templateFiles(imports),
333
337
  );
334
- const out = options.out ?? themeFiles(project.cwd, slug).sheet;
338
+ // One section goes to its own file, so the full sheet stays whole.
339
+ const full = themeFiles(project.cwd, slug).sheet;
340
+ const out =
341
+ options.out ??
342
+ (options.group
343
+ ? path.join(path.dirname(full), `sheet-${options.group}.html`)
344
+ : full);
335
345
  fs.mkdirSync(path.dirname(out), {recursive: true});
336
- fs.writeFileSync(out, html);
346
+ // Written whole and renamed in, never through a link.
347
+ writeWhole(out, html);
337
348
  return {
338
349
  file: shown(project.cwd, out),
339
350
  components: new Set(items.map(i => i.name)).size,
@@ -549,6 +560,42 @@ function withSources(project, v) {
549
560
  return v;
550
561
  }
551
562
 
563
+ /** Controlled parts a sample gives a value: they call onChange on a click. */
564
+ const CONTROLLED = new Set([
565
+ 'TabList',
566
+ 'SegmentedControl',
567
+ 'RadioList',
568
+ 'Switch',
569
+ 'CheckboxInput',
570
+ 'Selector',
571
+ 'TextInput',
572
+ 'TextArea',
573
+ 'NumberInput',
574
+ ]);
575
+
576
+ /**
577
+ * A copy of an element tree in which every controlled part with a value and
578
+ * no onChange gets one that does nothing, so a click on it never throws.
579
+ * @param {unknown} v
580
+ * @returns {unknown}
581
+ */
582
+ function withHandlers(v) {
583
+ if (Array.isArray(v)) return v.map(withHandlers);
584
+ if (isElement(v)) {
585
+ const props = Object.fromEntries(
586
+ Object.entries(v.props ?? {}).map(([k, x]) => [k, withHandlers(x)]),
587
+ );
588
+ if (CONTROLLED.has(v.__element) && 'value' in props && !props.onChange)
589
+ props.onChange = {__code: '() => {}'};
590
+ return {
591
+ ...v,
592
+ props,
593
+ ...(v.children === undefined ? {} : {children: withHandlers(v.children)}),
594
+ };
595
+ }
596
+ return v;
597
+ }
598
+
552
599
  /**
553
600
  * Whether an element tree uses the page's sample search source.
554
601
  * @param {unknown} v
@@ -560,6 +607,69 @@ const usesSource = v =>
560
607
  : Boolean(v && typeof v === 'object') &&
561
608
  Object.values(/** @type {object} */ (v)).some(usesSource);
562
609
 
610
+ /** The heading of each group on the components page. */
611
+ const GROUP_TITLES = /** @type {Record<string, string>} */ ({
612
+ data: 'data display',
613
+ overlays: 'overlays (shown open)',
614
+ });
615
+
616
+ /**
617
+ * A cell with the component's name. A cell whose parts show nothing on
618
+ * their own (no size and no text) says so, so no cell is blank.
619
+ */
620
+ const CELL = [
621
+ 'function Cell({name, children}: {name: string, children: React.ReactNode}) {',
622
+ ' const ref = React.useRef<HTMLDivElement>(null);',
623
+ ' const [empty, setEmpty] = React.useState(false);',
624
+ ' React.useEffect(() => {',
625
+ " const row = ref.current?.querySelector('.tp-row');",
626
+ ' if (!row) return;',
627
+ " const shown = Array.from(row.querySelectorAll('.tp-item > :not(.tp-label)')).some(el => {",
628
+ ' const box = el.getBoundingClientRect();',
629
+ " return (box.width > 2 && box.height > 2) || (el.textContent ?? '').trim() !== '';",
630
+ ' });',
631
+ ' setEmpty(!shown);',
632
+ ' }, []);',
633
+ ' return (',
634
+ ' <div ref={ref} className="tp-cell">',
635
+ ' <div className="tp-name">{name}</div>',
636
+ ' {children}',
637
+ ' {empty ? <div className="tp-note">{name} shows nothing on its own here: it needs content or a trigger</div> : null}',
638
+ ' </div>',
639
+ ' );',
640
+ '}',
641
+ ];
642
+
643
+ /**
644
+ * The command that changes a component most, from what its main part reads:
645
+ * its background, else its border, else its text color, else its corners;
646
+ * `how <part>` when it reads none of them.
647
+ * @param {import('./_project.mjs').ThemeProject} project
648
+ * @param {import('./_compiler.mjs').Compiler} C
649
+ * @param {string} name
650
+ * @param {string | null} theme
651
+ * @returns {string | null}
652
+ */
653
+ function changeLine(project, C, name, theme) {
654
+ const keys = project.targets
655
+ .filter(t => t.component === name)
656
+ .map(t => t.key);
657
+ const kebabName = name.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();
658
+ const part = keys.includes(kebabName) ? kebabName : keys[0];
659
+ if (!part) return null;
660
+ const P = 'astryx experimental theme editor';
661
+ const t = theme ?? '<theme>';
662
+ for (const [aspect, value] of /** @type {const} */ ([
663
+ ['background', '"<color>"'],
664
+ ['border', '"1px solid <color>"'],
665
+ ['text', '"<color>"'],
666
+ ]))
667
+ if (C.partReads(part, aspect).length)
668
+ return `${P} set ${t} ${DIRECT[aspect]} ${value} --on ${part}`;
669
+ if (C.showsCorners(part)) return `${P} set ${t} corners round --on ${part}`;
670
+ return `${P} how ${part}`;
671
+ }
672
+
563
673
  /** Layers that stay closed until a person opens them, and a frame with no content: on the page they show nothing. */
564
674
  const PAGE_SKIP = new Set([
565
675
  'AspectRatio',
@@ -573,15 +683,18 @@ const PAGE_SKIP = new Set([
573
683
  * The source of the preview's components page: every component grouped,
574
684
  * each variant side by side, overlays open. Template pages are pages of
575
685
  * their own (`preview add --template`), so they are not on it.
686
+ * Under each cell, one line: the command that changes the component most,
687
+ * from what its part reads (`how <part>`).
576
688
  * @param {import('./_project.mjs').ThemeProject} project
689
+ * @param {{theme?: string | null, C?: import('./_compiler.mjs').Compiler}} [options]
577
690
  * @returns {{source: string, components: number}}
578
691
  */
579
- export function componentsPageSource(project) {
692
+ export function componentsPageSource(project, {theme = null, C} = {}) {
580
693
  const items = showcaseItems(project, undefined)
581
694
  .items.filter(it => it.group !== 'pages' && !PAGE_SKIP.has(it.name))
582
695
  .map(it => ({
583
696
  ...it,
584
- tree: withSources(project, withCoreNames(project, it.tree)),
697
+ tree: withHandlers(withSources(project, withCoreNames(project, it.tree))),
585
698
  }))
586
699
  .filter(it => it.tree !== undefined);
587
700
  /** @type {Map<string, Map<string, import('./_catalog.mjs').CatalogItem[]>>} */
@@ -605,13 +718,14 @@ export function componentsPageSource(project) {
605
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>`,
606
719
  )
607
720
  .join('\n');
608
- return ` <div className="tp-cell">\n <div className="tp-name">${name}</div>\n <div className="tp-row">\n${body}\n </div>\n </div>`;
721
+ const line = C ? changeLine(project, C, name, theme) : null;
722
+ return ` <Cell name=${JSON.stringify(name)}>\n <div className="tp-row">\n${body}\n </div>${line ? `\n <code className="tp-cmd">{${JSON.stringify(line)}}</code>` : ''}\n </Cell>`;
609
723
  })
610
724
  .join('\n');
611
- return ` <section>\n <h2 className="tp-group">${g}</h2>\n <div className="tp-grid">\n${cells}\n </div>\n </section>`;
725
+ return ` <section>\n <h2 className="tp-group">${GROUP_TITLES[g] ?? g}</h2>\n <div className="tp-grid">\n${cells}\n </div>\n </section>`;
612
726
  })
613
727
  .join('\n');
614
- 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-note{font:11px ui-monospace,monospace;opacity:.6;padding:6px 8px;border:1px dashed #8886}`;
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}`;
615
729
  const source = [
616
730
  '// Written by `astryx experimental theme preview add`: every component grouped, each variant side by side, overlays open.',
617
731
  "'use client';",
@@ -624,6 +738,8 @@ export function componentsPageSource(project) {
624
738
  '',
625
739
  ...SAFE,
626
740
  '',
741
+ ...CELL,
742
+ '',
627
743
  ...(usesSource(items) ? [...SAMPLE_SOURCE, ''] : []),
628
744
  'export default function ComponentsPage() {',
629
745
  ' return (',
@@ -639,33 +755,218 @@ export function componentsPageSource(project) {
639
755
  }
640
756
 
641
757
  /**
642
- * The source of the preview's overview page: the content of the sample app
643
- * page. The preview route is the app shell, so the page has no shell of its
644
- * own.
758
+ * The source of the preview's Overview page: the theme at a glance, built
759
+ * to show what themes most often break (see _overview.mjs). A header names
760
+ * the theme, its fonts and its main colors; each section renders inside a
761
+ * boundary, so one part that throws never blanks the page. The preview
762
+ * route is the app shell, so the page has no shell of its own.
645
763
  * @param {import('./_project.mjs').ThemeProject} project
764
+ * @param {{theme?: string | null}} [options]
646
765
  * @returns {string}
647
766
  */
648
- export function overviewPageSource(project) {
649
- const content = /** @type {unknown[]} */ (SAMPLE_PAGE.children)[0];
650
- const page = withCoreNames(project, {
651
- __element: 'Layout',
652
- props: {
653
- content: {
654
- __element: 'LayoutContent',
655
- props: {padding: 4},
656
- children: [content],
657
- },
658
- },
659
- });
767
+ export function overviewPageSource(project, {theme = null} = {}) {
768
+ const sections = OVERVIEW_SECTIONS.map(x => ({
769
+ title: x.title,
770
+ tree: /** @type {import('./_catalog.mjs').Tree | undefined} */ (
771
+ withHandlers(withCoreNames(project, x.tree))
772
+ ),
773
+ })).filter(x => x.tree !== undefined);
774
+ const body = sections
775
+ .map(
776
+ x =>
777
+ ` <section className="tp-section">\n <h2 className="tp-group">${x.title}</h2>\n <Safe name=${JSON.stringify(x.title)}>\n ${jsx(/** @type {any} */ (x.tree), 5)}\n </Safe>\n </section>`,
778
+ )
779
+ .join('\n');
780
+ const css =
781
+ '.tp-page{display:grid;gap:20px;padding:24px 24px 160px;color:var(--color-text-primary)}' +
782
+ '.tp-group{font:600 13px ui-monospace,monospace;margin:0 0 10px;opacity:.7;text-transform:uppercase;letter-spacing:.04em}' +
783
+ '.tp-head{display:flex;flex-wrap:wrap;gap:16px;align-items:end;justify-content:space-between}' +
784
+ '.tp-swatches{display:flex;flex-wrap:wrap;gap:8px}' +
785
+ '.tp-swatch{display:grid;gap:4px;font:11px ui-monospace,monospace;color:var(--color-text-secondary)}' +
786
+ '.tp-chip{width:56px;height:36px;border-radius:var(--radius-element);border:1px solid var(--color-border)}' +
787
+ '.tp-note{font:11px ui-monospace,monospace;opacity:.6;padding:6px 8px;border:1px dashed #8886}';
660
788
  return [
661
- '// Written by `astryx experimental theme preview add`: a sample app page.',
789
+ '// Written by `astryx experimental theme preview add`: the theme at a glance, built to show what themes most often break.',
662
790
  "'use client';",
663
791
  '',
664
792
  "import * as React from 'react';",
665
- ...componentTable(project, page),
793
+ ...componentTable(
794
+ project,
795
+ sections.map(x => x.tree),
796
+ ),
797
+ '',
798
+ ...SAFE,
799
+ '',
800
+ '/** The main colors, as the theme resolves them. */',
801
+ 'const SWATCHES = [',
802
+ ...[
803
+ ['accent', '--color-accent'],
804
+ ['neutral', '--color-background-surface'],
805
+ ['text', '--color-text-primary'],
806
+ ['info', '--color-info'],
807
+ ['success', '--color-success'],
808
+ ['warning', '--color-warning'],
809
+ ['danger', '--color-error'],
810
+ ].map(
811
+ ([n, t]) =>
812
+ ` {name: ${JSON.stringify(n)}, token: ${JSON.stringify(t)}},`,
813
+ ),
814
+ '];',
815
+ '',
816
+ '/** The first family of the body and heading fonts, read from the theme. */',
817
+ 'function FontNames() {',
818
+ ' const ref = React.useRef<HTMLDivElement>(null);',
819
+ " const [fonts, setFonts] = React.useState('');",
820
+ ' React.useEffect(() => {',
821
+ ' if (!ref.current) return;',
822
+ ' const style = getComputedStyle(ref.current);',
823
+ " const first = (token: string) => style.getPropertyValue(token).split(',')[0].replace(/[\"']/g, '').trim() || 'default';",
824
+ " setFonts(`Body: ${first('--font-family-body')}. Headings: ${first('--font-family-heading')}.`);",
825
+ ' }, []);',
826
+ ' return (',
827
+ " <div ref={ref} style={{color: 'var(--color-text-secondary)', fontSize: 13}}>",
828
+ ' {fonts}',
829
+ ' </div>',
830
+ ' );',
831
+ '}',
666
832
  '',
667
833
  'export default function OverviewPage() {',
668
- ` return ${jsx(/** @type {any} */ (page), 1)};`,
834
+ ' return (',
835
+ ' <div className="tp-page">',
836
+ ` <style>{${JSON.stringify(css)}}</style>`,
837
+ ' <header className="tp-head">',
838
+ ' <div>',
839
+ ` <h1 style={{margin: 0, fontSize: 28}}>{${JSON.stringify(theme ? `${theme} at a glance` : 'The theme at a glance')}}</h1>`,
840
+ ' <FontNames />',
841
+ ' </div>',
842
+ ' <div className="tp-swatches">',
843
+ ' {SWATCHES.map(s => (',
844
+ ' <div key={s.name} className="tp-swatch" title={s.token}>',
845
+ ' <div className="tp-chip" style={{background: `var(${s.token})`}} />',
846
+ ' {s.name}',
847
+ ' </div>',
848
+ ' ))}',
849
+ ' <div className="tp-swatch" style={{alignSelf: \'center\'}}>Every shade: the Colors page</div>',
850
+ ' </div>',
851
+ ' </header>',
852
+ body,
853
+ ' </div>',
854
+ ' );',
855
+ '}',
856
+ '',
857
+ ].join('\n');
858
+ }
859
+
860
+ /**
861
+ * The source of the preview's Colors page: each generated color's shades in
862
+ * light and dark, with the shade number, the hex, and the tokens that use
863
+ * it. The shades come from the theme's generated color module, so the page
864
+ * follows every change; `uses` and `seeds` are written in by the editor.
865
+ * With no generated colors, the page says how to set one.
866
+ * @param {{slug: string, module: string | null, seeds: Record<string, string>, uses: Record<string, Record<'light' | 'dark', Record<string, string[]>>>}} colors
867
+ * `module`: the import of the generated colors from the page, or null.
868
+ * @returns {string}
869
+ */
870
+ export function colorsPageSource({slug, module, seeds, uses}) {
871
+ const head = [
872
+ "// Written by `astryx experimental theme preview add`: the theme's generated colors.",
873
+ '// `astryx experimental theme editor set` rewrites it with every change.',
874
+ "'use client';",
875
+ '',
876
+ "import * as React from 'react';",
877
+ ];
878
+ const text = {color: 'var(--color-text-primary)'};
879
+ const page = {
880
+ padding: 32,
881
+ display: 'grid',
882
+ gap: 32,
883
+ fontFamily: 'var(--font-family-body)',
884
+ ...text,
885
+ };
886
+ if (!module)
887
+ return [
888
+ ...head,
889
+ '',
890
+ 'export default function ColorsPage() {',
891
+ ' return (',
892
+ ` <div style={${JSON.stringify(page)}}>`,
893
+ ' <p style={{margin: 0}}>',
894
+ ` {${JSON.stringify(`This theme sets no color yet. Set one, and its shades show here: astryx experimental theme editor set ${slug} accent "#7c3aed"`)}}`,
895
+ ' </p>',
896
+ ' </div>',
897
+ ' );',
898
+ '}',
899
+ '',
900
+ ].join('\n');
901
+ return [
902
+ ...head,
903
+ `import {palette} from ${JSON.stringify(module)};`,
904
+ '',
905
+ "type Mode = 'light' | 'dark';",
906
+ 'type Ramp = Readonly<Record<string, string>>;',
907
+ '',
908
+ `const SEEDS: Record<string, string> = ${JSON.stringify(seeds)};`,
909
+ '// The tokens that use each shade, by color, mode and shade.',
910
+ `const USES: Record<string, Partial<Record<Mode, Record<string, string[]>>>> = ${JSON.stringify(uses)};`,
911
+ 'const COLORS = Object.entries(palette) as Array<[string, Readonly<Partial<Record<Mode, Ramp>>>]>;',
912
+ "const MODES: Mode[] = ['light', 'dark'];",
913
+ '',
914
+ 'export default function ColorsPage() {',
915
+ ' return (',
916
+ ` <div style={${JSON.stringify(page)}}>`,
917
+ ' <div>',
918
+ ' <h1 style={{margin: 0, fontSize: 28}}>Colors</h1>',
919
+ " <p style={{margin: '8px 0 0', color: 'var(--color-text-secondary)'}}>",
920
+ ` {${JSON.stringify(`Each color is generated from one seed, light and dark. An outlined shade is one a token uses. Change one with: astryx experimental theme editor set ${slug} accent <color>`)}}`,
921
+ ' </p>',
922
+ ' </div>',
923
+ ' {COLORS.map(([name, ramps]) => (',
924
+ " <section key={name} style={{display: 'grid', gap: 12}}>",
925
+ " <h2 style={{margin: 0, fontSize: 20, textTransform: 'capitalize'}}>",
926
+ ' {name}',
927
+ ' {SEEDS[name] ? (',
928
+ " <span style={{marginLeft: 8, fontSize: 14, fontWeight: 400, color: 'var(--color-text-secondary)'}}>",
929
+ ' from {SEEDS[name]}',
930
+ ' </span>',
931
+ ' ) : null}',
932
+ ' </h2>',
933
+ ' {MODES.filter(mode => ramps[mode]).map(mode => (',
934
+ " <div key={mode} style={{display: 'grid', gap: 6}}>",
935
+ " <div style={{fontSize: 13, fontWeight: 600, textTransform: 'capitalize'}}>{mode}</div>",
936
+ " <div style={{display: 'grid', gridTemplateColumns: 'repeat(7, minmax(0, 1fr))', gap: 8}}>",
937
+ ' {Object.entries(ramps[mode] ?? {}).map(([shade, hex]) => {',
938
+ ' const tokens = USES[name]?.[mode]?.[shade] ?? [];',
939
+ ' return (',
940
+ ' <div',
941
+ ' key={shade}',
942
+ " title={tokens.join(', ')}",
943
+ ' style={{',
944
+ " border: tokens.length ? '2px solid var(--color-text-primary)' : '1px solid var(--color-border)',",
945
+ ' borderRadius: 8,',
946
+ " overflow: 'hidden',",
947
+ " background: 'var(--color-background-card)',",
948
+ ' }}>',
949
+ ' <div style={{background: hex, height: 48}} />',
950
+ " <div style={{padding: 6, fontSize: 11, lineHeight: 1.4, fontFamily: 'ui-monospace, monospace'}}>",
951
+ ' <div>',
952
+ ' <strong>{shade}</strong> {hex}',
953
+ ' </div>',
954
+ ' {tokens.map(t => (',
955
+ " <div key={t} style={{color: 'var(--color-text-secondary)', overflowWrap: 'anywhere'}}>",
956
+ ' {t}',
957
+ ' </div>',
958
+ ' ))}',
959
+ ' </div>',
960
+ ' </div>',
961
+ ' );',
962
+ ' })}',
963
+ ' </div>',
964
+ ' </div>',
965
+ ' ))}',
966
+ ' </section>',
967
+ ' ))}',
968
+ ' </div>',
969
+ ' );',
669
970
  '}',
670
971
  '',
671
972
  ].join('\n');
@@ -676,22 +977,33 @@ export function overviewPageSource(project) {
676
977
  * preview page, a top bar with the theme name and, with a theme, a
677
978
  * light/dark/system switch, and the selected page in the content area. It is a normal page of
678
979
  * the app, so it keeps the app's layout, global CSS and providers.
679
- * @param {{pages: Array<{id: string, label: string, file: string}>, theme: {name: string, module: string, css: string[]} | null}} spec
680
- * `file` relative to the route folder, without extension; no theme: the app's own theme
980
+ * @param {{pages: Array<{id: string, label: string, file: string}>, theme: {name: string, module: string, css: string[], mode?: 'system' | 'light' | 'dark'} | null, by?: string}} spec
981
+ * `file` relative to the route folder, without extension; no theme: the
982
+ * app's own theme. A theme with one mode starts in it, with no switch.
983
+ * `by`: the command that wrote the route, for its header.
681
984
  * @returns {string}
682
985
  */
683
- export function previewRouteSource({pages, theme}) {
986
+ export function previewRouteSource({
987
+ pages,
988
+ theme,
989
+ by = 'astryx experimental theme preview add',
990
+ }) {
684
991
  const name = theme?.name ?? 'app theme';
685
- const mode = theme
686
- ? [
687
- ' <SegmentedControl label="Color mode" size="sm" value={mode} onChange={v => setMode(v as Mode)}>',
688
- ' <SegmentedControlItem value="light" label="Light" />',
689
- ' <SegmentedControlItem value="dark" label="Dark" />',
690
- ' <SegmentedControlItem value="system" label="System" />',
691
- ' </SegmentedControl>',
692
- ]
693
- : [];
992
+ const oneMode = theme?.mode && theme.mode !== 'system' ? theme.mode : null;
993
+ const mode =
994
+ theme && !oneMode
995
+ ? [
996
+ ' <SegmentedControl label="Color mode" size="sm" value={mode} onChange={v => setMode(v as Mode)}>',
997
+ ' <SegmentedControlItem value="light" label="Light" />',
998
+ ' <SegmentedControlItem value="dark" label="Dark" />',
999
+ ' <SegmentedControlItem value="system" label="System" />',
1000
+ ' </SegmentedControl>',
1001
+ ]
1002
+ : [];
1003
+ // The frame fills the viewport with the theme's own page background, so
1004
+ // no root-layout background shows at the edges or on overscroll.
694
1005
  const shell = [
1006
+ ' <div style={FRAME}>',
695
1007
  ' <AppShell',
696
1008
  ' height="fill"',
697
1009
  ' topNav={',
@@ -708,9 +1020,10 @@ export function previewRouteSource({pages, theme}) {
708
1020
  ' }>',
709
1021
  ' <current.Page />',
710
1022
  ' </AppShell>',
1023
+ ' </div>',
711
1024
  ];
712
1025
  return [
713
- '// Written by `astryx experimental theme preview add`. `preview add`, `preview remove` and',
1026
+ `// Written by \`${by}\`. \`preview add\`, \`preview remove\` and`,
714
1027
  '// theme-preview.json keep it: edit the list with those commands, not by hand.',
715
1028
  "'use client';",
716
1029
  '',
@@ -731,6 +1044,15 @@ export function previewRouteSource({pages, theme}) {
731
1044
  ),
732
1045
  '',
733
1046
  ...(theme ? ["type Mode = 'light' | 'dark' | 'system';", ''] : []),
1047
+ 'const FRAME: React.CSSProperties = {',
1048
+ " position: 'fixed',",
1049
+ ' inset: 0,',
1050
+ " overflow: 'auto',",
1051
+ " overscrollBehavior: 'none',",
1052
+ " background: 'var(--color-background-body)',",
1053
+ " color: 'var(--color-text-primary)',",
1054
+ '};',
1055
+ '',
734
1056
  'const PAGES = [',
735
1057
  ...pages.map(
736
1058
  (p, i) =>
@@ -741,7 +1063,11 @@ export function previewRouteSource({pages, theme}) {
741
1063
  'export default function ThemePreviewPage() {',
742
1064
  ' const [page, setPage] = React.useState(PAGES[0]?.id);',
743
1065
  ...(theme
744
- ? [" const [mode, setMode] = React.useState<Mode>('system');"]
1066
+ ? [
1067
+ oneMode
1068
+ ? ` const mode: Mode = ${JSON.stringify(oneMode)};`
1069
+ : " const [mode, setMode] = React.useState<Mode>('system');",
1070
+ ]
745
1071
  : []),
746
1072
  ' const current = PAGES.find(p => p.id === page) ?? PAGES[0];',
747
1073
  ' return (',