@astryxdesign/cli 0.7.15-canary.gf890983 → 0.7.15
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.
- package/CHANGELOG.md +353 -3
- package/api/doctor/_adapter.d.mts +2 -1
- package/api/doctor/_adapter.mjs +6 -1
- package/api/doctor/doctor.mjs +2 -2
- package/api/doctor/theme-checks.mjs +56 -21
- package/api/integration/add-helpers.mjs +5 -0
- package/api/integration/add-theme.mjs +15 -110
- package/api/theme/_adapter.d.mts +37 -5
- package/api/theme/_adapter.mjs +363 -50
- package/api/theme/_fork.d.mts +90 -0
- package/api/theme/_fork.mjs +246 -0
- package/api/theme/build/build.d.mts +25 -1
- package/api/theme/build/build.mjs +352 -41
- package/api/theme/eject/eject.mjs +36 -15
- package/api/theme/list/list.mjs +3 -6
- package/api/theme/palette/generate/generator.d.mts +13 -0
- package/api/theme/palette/generate/generator.mjs +32 -2
- package/api/theme/targets/targets.mjs +10 -3
- package/api/theme/template/template.mjs +48 -2
- package/api/theme/theme.type.d.mts +8 -0
- package/api/theme/theme.type.mjs +5 -1
- package/api/theme/themeBuild.doc.mjs +2 -2
- package/api/theme/themeRemove.doc.mjs +5 -2
- package/api/theme/themeTemplate.doc.mjs +2 -2
- package/api/theme/themeUse.doc.mjs +8 -2
- package/api/theme-edit/_adapter.mjs +157 -36
- package/api/theme-edit/_catalog.d.mts +1 -6
- package/api/theme-edit/_catalog.mjs +5 -268
- package/api/theme-edit/_check.d.mts +3 -1
- package/api/theme-edit/_check.mjs +733 -308
- package/api/theme-edit/_color.d.mts +19 -0
- package/api/theme-edit/_color.mjs +277 -33
- package/api/theme-edit/_compiler.d.mts +1 -0
- package/api/theme-edit/_compiler.mjs +25 -0
- package/api/theme-edit/_context.d.mts +2 -0
- package/api/theme-edit/_context.mjs +83 -9
- package/api/theme-edit/_css.d.mts +84 -0
- package/api/theme-edit/_css.mjs +700 -0
- package/api/theme-edit/_edit.mjs +370 -85
- package/api/theme-edit/_how-commands.d.mts +5 -0
- package/api/theme-edit/_how-commands.mjs +20 -13
- package/api/theme-edit/_how-question.d.mts +29 -0
- package/api/theme-edit/_how-question.mjs +1573 -182
- package/api/theme-edit/_how.mjs +306 -22
- package/api/theme-edit/_overview.mjs +2 -7
- package/api/theme-edit/_palette.d.mts +27 -5
- package/api/theme-edit/_palette.mjs +231 -97
- package/api/theme-edit/_parts.d.mts +42 -10
- package/api/theme-edit/_parts.mjs +224 -69
- package/api/theme-edit/_preview-app.d.mts +8 -0
- package/api/theme-edit/_preview-app.mjs +549 -96
- package/api/theme-edit/_preview.d.mts +7 -16
- package/api/theme-edit/_preview.mjs +77 -84
- package/api/theme-edit/_project.d.mts +20 -1
- package/api/theme-edit/_project.mjs +43 -13
- package/api/theme-edit/_settings.d.mts +96 -20
- package/api/theme-edit/_settings.mjs +646 -141
- package/api/theme-edit/_tables.d.mts +18 -12
- package/api/theme-edit/_tables.mjs +144 -147
- package/api/theme-edit/theme-edit.type.d.mts +10 -1
- package/api/theme-edit/theme-edit.type.mjs +3 -1
- package/api/theme-edit/themeEditNew.doc.mjs +1 -1
- package/api/theme-edit/themeEditPreviewAdd.doc.mjs +1 -1
- package/api/theme-edit/themeEditPreviewApp.doc.mjs +1 -1
- package/api/theme-edit/themeEditPreviewList.doc.mjs +2 -2
- package/api/theme-edit/themeEditSet.doc.mjs +1 -1
- package/api/theme-edit/themeEditUndo.doc.mjs +1 -1
- package/assets/docs/tree/publishing.doc.mjs +1 -0
- package/assets/docs.generated.json +2 -2
- package/assets/self-audit.generated.json +1 -1
- package/clients/cli/build-id.generated.json +1 -1
- package/clients/cli/commands/experimental/index.mjs +10 -10
- package/clients/cli/commands/experimental/theme.mjs +22 -3
- package/clients/cli/commands/experimental-theme-compile.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +3 -3
- package/clients/cli/commands/experimental-theme-preview-add.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
- package/clients/cli/commands/integration.mjs +8 -0
- package/clients/cli/commands/theme-build.doc.mjs +2 -2
- package/clients/cli/commands/theme-list.doc.mjs +1 -1
- package/clients/cli/commands/theme-template.doc.mjs +1 -1
- package/clients/cli/commands/theme.mjs +325 -48
- package/clients/cli/index.mjs +18 -3
- package/clients/cli/lib/cli-error.mjs +118 -3
- package/clients/cli/manifest.generated.json +1 -1
- package/foundation/config/project.mjs +34 -8
- package/foundation/config/theme-state.d.mts +16 -0
- package/foundation/config/theme-state.mjs +84 -13
- package/foundation/discovery/template-needs.d.mts +13 -0
- package/foundation/discovery/template-needs.mjs +30 -15
- package/foundation/discovery/theme-discovery.mjs +14 -2
- package/foundation/discovery/theme-imports.d.mts +16 -0
- package/foundation/discovery/theme-imports.mjs +30 -2
- package/foundation/doc-compiler/import.mjs +10 -4
- package/foundation/fs/gather-cache.mjs +82 -23
- package/foundation/fs/jiti-cache.d.mts +21 -0
- package/foundation/fs/jiti-cache.mjs +66 -0
- package/foundation/fs/module-loader.mjs +7 -2
- package/foundation/integrations/autolink.d.mts +1 -24
- package/foundation/integrations/autolink.mjs +7 -60
- package/foundation/integrations/declared-dependencies.d.mts +27 -0
- package/foundation/integrations/declared-dependencies.mjs +73 -0
- package/foundation/integrations/may-have-integrations.d.mts +8 -0
- package/foundation/integrations/may-have-integrations.mjs +47 -0
- package/foundation/release/cache.d.mts +21 -2
- package/foundation/release/cache.mjs +48 -8
- package/foundation/release/folder-lock.d.mts +7 -0
- package/foundation/release/folder-lock.mjs +60 -26
- package/foundation/release/lock-lease.d.mts +2 -1
- package/foundation/release/lock-lease.mjs +7 -2
- package/foundation/response/error-codes.doc.mjs +1 -1
- package/foundation/response/response-types.doc.mjs +4 -4
- package/package.json +6 -6
- package/api/theme-edit/_css-properties.d.mts +0 -10
- 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
|
|
6
|
-
*
|
|
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.
|
|
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 {
|
|
25
|
+
import {
|
|
26
|
+
catalogVariants,
|
|
27
|
+
isItemOf,
|
|
28
|
+
renderDir,
|
|
29
|
+
renderGenerated,
|
|
30
|
+
} from './_parts.mjs';
|
|
28
31
|
import {OVERVIEW_SECTIONS} from './_overview.mjs';
|
|
29
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
|
|
94
|
-
*
|
|
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
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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
|
|
117
|
-
continue;
|
|
105
|
+
if (!g) continue;
|
|
118
106
|
const inParent = inParentOf(project, name);
|
|
119
107
|
if (inParent === null) continue;
|
|
120
|
-
const
|
|
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:
|
|
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
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
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
|
-
|
|
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 >
|
|
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
|
-
|
|
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(
|
|
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';",
|
|
@@ -1085,15 +1051,26 @@ 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.
|
|
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
|
|
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.`,
|
|
@@ -50,6 +50,7 @@ export function baseResolved(project: ThemeProject, like: string | undefined): P
|
|
|
50
50
|
dark: Record<string, string>;
|
|
51
51
|
components: Record<string, any>;
|
|
52
52
|
}>;
|
|
53
|
+
export function literals(type: string): string[];
|
|
53
54
|
export type ThemeProject = {
|
|
54
55
|
cwd: string;
|
|
55
56
|
/**
|
|
@@ -94,19 +95,37 @@ export type ComponentInfo = {
|
|
|
94
95
|
component: string;
|
|
95
96
|
props: Record<string, unknown>;
|
|
96
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;
|
|
97
106
|
/**
|
|
98
107
|
* - The component it is a part of, or null.
|
|
99
108
|
*/
|
|
100
109
|
subComponentOf: string | null;
|
|
101
110
|
/**
|
|
102
|
-
* -
|
|
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.
|
|
103
116
|
*/
|
|
104
117
|
props: Record<string, {
|
|
105
118
|
type: string;
|
|
106
119
|
required: boolean;
|
|
120
|
+
slots: Array<{
|
|
121
|
+
__element: string;
|
|
122
|
+
props?: Record<string, unknown>;
|
|
123
|
+
children?: unknown;
|
|
124
|
+
}>;
|
|
107
125
|
}>;
|
|
108
126
|
targets: Array<{
|
|
109
127
|
className: string;
|
|
128
|
+
states: string[];
|
|
110
129
|
values: Record<string, string[]>;
|
|
111
130
|
}>;
|
|
112
131
|
};
|
|
@@ -43,16 +43,19 @@ import {findProjectCoreDir} from '../../foundation/fs/paths.mjs';
|
|
|
43
43
|
* @property {string} category - The doc's category, such as Action or Overlay.
|
|
44
44
|
* @property {unknown} defaults - Playground defaults, or null.
|
|
45
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.
|
|
46
48
|
* @property {string | null} subComponentOf - The component it is a part of, or null.
|
|
47
|
-
* @property {
|
|
48
|
-
* @property {
|
|
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
|
|
49
52
|
*/
|
|
50
53
|
|
|
51
54
|
/** @type {Map<string, ThemeProject>} */
|
|
52
55
|
const projects = new Map();
|
|
53
56
|
|
|
54
57
|
/** Bump when the shape of the cached component docs changes. */
|
|
55
|
-
const DOCS_VERSION =
|
|
58
|
+
const DOCS_VERSION = 5;
|
|
56
59
|
|
|
57
60
|
/**
|
|
58
61
|
* The theme editor's cache folder for a project: the `.cache/astryx-theme`
|
|
@@ -102,7 +105,7 @@ export function installLine(cwd, packages) {
|
|
|
102
105
|
}
|
|
103
106
|
|
|
104
107
|
/** @param {string} type @returns {string[]} */
|
|
105
|
-
const literals = type =>
|
|
108
|
+
export const literals = type =>
|
|
106
109
|
[...String(type ?? '').matchAll(/'([^']+)'/g)].map(m => m[1]);
|
|
107
110
|
|
|
108
111
|
/**
|
|
@@ -132,33 +135,59 @@ async function readComponents(coreDir) {
|
|
|
132
135
|
continue;
|
|
133
136
|
}
|
|
134
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;
|
|
135
146
|
/** @type {Record<string, any>} */
|
|
136
147
|
const props = Object.fromEntries(
|
|
137
|
-
(Array.isArray(
|
|
138
|
-
|
|
139
|
-
|
|
148
|
+
(Array.isArray(own) ? own : []).map((/** @type {any} */ p) => [
|
|
149
|
+
p.name,
|
|
150
|
+
p,
|
|
151
|
+
]),
|
|
140
152
|
);
|
|
141
153
|
out[doc.name] = {
|
|
142
154
|
importPath: resolveImportPath(coreDir, doc.name),
|
|
143
155
|
category: typeof doc.category === 'string' ? doc.category : '',
|
|
144
|
-
defaults:
|
|
156
|
+
defaults: pg?.defaults ?? null,
|
|
145
157
|
wrapper:
|
|
146
|
-
typeof
|
|
158
|
+
typeof pg?.wrapper?.component === 'string'
|
|
147
159
|
? {
|
|
148
|
-
component:
|
|
149
|
-
props:
|
|
160
|
+
component: pg.wrapper.component,
|
|
161
|
+
props: pg.wrapper.props ?? {},
|
|
150
162
|
}
|
|
151
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
|
+
),
|
|
152
175
|
subComponentOf:
|
|
153
176
|
typeof doc.subComponentOf === 'string' ? doc.subComponentOf : null,
|
|
177
|
+
keywords: Array.isArray(doc.keywords) ? doc.keywords.map(String) : [],
|
|
154
178
|
props: Object.fromEntries(
|
|
155
179
|
Object.entries(props).map(([n, p]) => [
|
|
156
180
|
n,
|
|
157
|
-
{
|
|
181
|
+
{
|
|
182
|
+
type: String(p.type ?? ''),
|
|
183
|
+
required: p.required === true,
|
|
184
|
+
slots: Array.isArray(p.slotElements) ? p.slotElements : [],
|
|
185
|
+
},
|
|
158
186
|
]),
|
|
159
187
|
),
|
|
160
188
|
targets: (doc.theming?.targets ?? []).map((/** @type {any} */ t) => ({
|
|
161
189
|
className: t.className,
|
|
190
|
+
states: Array.isArray(t.states) ? t.states.map(String) : [],
|
|
162
191
|
values: Object.fromEntries(
|
|
163
192
|
(t.visualProps ?? []).map((/** @type {string} */ v) => {
|
|
164
193
|
const p = props[v];
|
|
@@ -328,11 +357,12 @@ export async function baseResolved(project, like) {
|
|
|
328
357
|
v => v && typeof v === 'object' && typeof v.name === 'string',
|
|
329
358
|
);
|
|
330
359
|
}
|
|
331
|
-
|
|
360
|
+
const out = {
|
|
332
361
|
light: core.resolveThemeTokens(theme, {mode: 'light'}),
|
|
333
362
|
dark: core.resolveThemeTokens(theme, {mode: 'dark'}),
|
|
334
363
|
// The base theme's own part styles (neutral's pale destructive button),
|
|
335
364
|
// which a one-mode setting keeps in the other mode.
|
|
336
365
|
components: theme.components ?? {},
|
|
337
366
|
};
|
|
367
|
+
return out;
|
|
338
368
|
}
|