@astryxdesign/cli 0.7.16 → 0.7.17-canary.gb36275e
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/README.md +13 -23
- package/api/build/_adapter.d.mts +5 -0
- package/api/build/_adapter.mjs +49 -34
- package/api/build/blocks/blocks.d.mts +7 -5
- package/api/build/blocks/blocks.mjs +113 -26
- package/api/build/build.doc.mjs +2 -1
- package/api/build/kit/rank.mjs +59 -12
- package/api/build/kit/weights.d.mts +16 -3
- package/api/build/kit/weights.json +1 -1
- package/api/build/kit/weights.mjs +238 -31
- package/api/build/kit/word-model.d.mts +23 -0
- package/api/build/kit/word-model.mjs +46 -0
- package/api/build/kit/words.d.mts +42 -0
- package/api/build/kit/words.mjs +82 -1
- package/api/component/__fixtures__/resolutions/modules.txt +4 -5
- package/api/component/list/list.d.mts +1 -1
- package/api/component/list/list.mjs +46 -5
- package/api/discover/_adapter.d.mts +1 -1
- package/api/docs/_adapter.d.mts +26 -2
- package/api/docs/_adapter.mjs +217 -5
- package/api/docs/docs.d.mts +3 -0
- package/api/docs/docs.doc.mjs +7 -1
- package/api/docs/docs.mjs +12 -0
- package/api/docs/docs.type.d.mts +5 -0
- package/api/docs/docs.type.mjs +2 -0
- package/api/docs/node/node.mjs +1 -1
- package/api/doctor/_adapter.d.mts +27 -5
- package/api/doctor/_adapter.mjs +77 -6
- package/api/doctor/built-checks.mjs +38 -13
- package/api/doctor/doctor.d.mts +4 -3
- package/api/doctor/doctor.mjs +14 -7
- package/api/doctor/theme-checks.mjs +121 -17
- package/api/render/_adapter.mjs +531 -192
- package/api/render/render.doc.mjs +11 -3
- package/api/render/render.type.d.mts +30 -0
- package/api/render/render.type.mjs +19 -0
- package/api/search/ORDERING.md +1 -1
- package/api/search/_candidate-score.mjs +51 -32
- package/api/search/_fit-order.mjs +3 -3
- package/api/search/_result.d.mts +5 -5
- package/api/search/_score.d.mts +6 -1
- package/api/search/_score.mjs +15 -3
- package/api/search/search.d.mts +1 -1
- package/api/theme/_adapter.mjs +10 -0
- package/api/theme/build/build.d.mts +47 -0
- package/api/theme/build/build.mjs +147 -25
- package/api/theme/theme.type.d.mts +10 -0
- package/api/theme/theme.type.mjs +7 -1
- package/api/theme-edit/_adapter.d.mts +48 -0
- package/api/theme-edit/_adapter.mjs +675 -42
- package/api/theme-edit/_check.d.mts +28 -22
- package/api/theme-edit/_check.mjs +1481 -252
- package/api/theme-edit/_color.d.mts +9 -0
- package/api/theme-edit/_color.mjs +41 -1
- package/api/theme-edit/_compiler.mjs +9 -0
- package/api/theme-edit/_context.mjs +60 -3
- package/api/theme-edit/_css.mjs +21 -1
- package/api/theme-edit/_edit.d.mts +22 -0
- package/api/theme-edit/_edit.mjs +1196 -88
- package/api/theme-edit/_how-commands.d.mts +57 -0
- package/api/theme-edit/_how-commands.mjs +536 -1
- package/api/theme-edit/_how-question.d.mts +65 -0
- package/api/theme-edit/_how-question.mjs +4401 -225
- package/api/theme-edit/_how.mjs +104 -4
- package/api/theme-edit/_marks.d.mts +31 -5
- package/api/theme-edit/_marks.mjs +57 -5
- package/api/theme-edit/_normal.d.mts +153 -0
- package/api/theme-edit/_normal.mjs +661 -0
- package/api/theme-edit/_palette.mjs +10 -4
- package/api/theme-edit/_parts.d.mts +8 -0
- package/api/theme-edit/_parts.mjs +103 -2
- package/api/theme-edit/_preview-app.d.mts +7 -1
- package/api/theme-edit/_preview-app.mjs +205 -17
- package/api/theme-edit/_preview.d.mts +64 -8
- package/api/theme-edit/_preview.mjs +447 -89
- package/api/theme-edit/_settings.d.mts +176 -5
- package/api/theme-edit/_settings.mjs +1936 -128
- package/api/theme-edit/_tables.d.mts +6 -0
- package/api/theme-edit/_tables.mjs +32 -1
- package/api/theme-edit/theme-edit.type.d.mts +10 -1
- package/api/theme-edit/theme-edit.type.mjs +4 -1
- package/api/theme-edit/themeEditPreviewApp.doc.mjs +3 -3
- package/assets/codemods/run-codemod.mjs +73 -6
- package/assets/codemods/transforms/next/index.mjs +11 -1
- package/assets/codemods/transforms/next/migrate-item-swipe-actions-to-swipe.mjs +394 -0
- package/assets/docs/author-a-theme.doc.mjs +1 -0
- package/assets/docs/theme.doc.dense.mjs +2 -2
- package/assets/docs/theme.doc.mjs +1 -1
- package/assets/docs/tree/check-your-docs.doc.mjs +1 -1
- package/assets/docs/tree/cli-command.doc.mjs +2 -3
- package/assets/docs/tree/render-pages.doc.mjs +43 -2
- package/assets/docs/tree/template-doc-overview.doc.mjs +1 -1
- package/assets/docs/tree/test-in-an-app.doc.mjs +1 -1
- package/assets/docs/use-a-theme.doc.mjs +1 -1
- package/assets/docs.generated.json +2 -2
- package/assets/self-audit.generated.json +1 -1
- package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.tsx +38 -0
- package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.tsx +36 -0
- package/assets/templates/components.generated.json +1 -1
- package/assets/templates/pages/ai-chat/template.doc.mjs +5 -4
- package/assets/templates/pages/ai-chat-landing/template.doc.mjs +2 -1
- package/assets/templates/pages/blank/template.doc.mjs +1 -1
- package/assets/templates/pages/canvas-editor/template.doc.mjs +4 -2
- package/assets/templates/pages/centered-hero/template.doc.mjs +9 -1
- package/assets/templates/pages/classic-gallery/template.doc.mjs +1 -1
- package/assets/templates/pages/contact-form/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard/template.doc.mjs +3 -2
- package/assets/templates/pages/dashboard-alert-rail/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard-cohort-funnel/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard-composition/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard-progress/template.doc.mjs +6 -3
- package/assets/templates/pages/detail-page/template.doc.mjs +10 -3
- package/assets/templates/pages/documentation/template.doc.mjs +4 -1
- package/assets/templates/pages/documentation-design/template.doc.mjs +7 -1
- package/assets/templates/pages/documentation-technical/template.doc.mjs +7 -1
- package/assets/templates/pages/editor/template.doc.mjs +2 -8
- package/assets/templates/pages/file-explorer/template.doc.mjs +1 -1
- package/assets/templates/pages/form-two-column/template.doc.mjs +4 -3
- package/assets/templates/pages/form-wizard/template.doc.mjs +5 -3
- package/assets/templates/pages/gallery-hero/template.doc.mjs +4 -2
- package/assets/templates/pages/ide/page.tsx +24 -2
- package/assets/templates/pages/kanban-board/template.doc.mjs +1 -9
- package/assets/templates/pages/library/template.doc.mjs +4 -1
- package/assets/templates/pages/login/template.doc.mjs +2 -1
- package/assets/templates/pages/login-card/template.doc.mjs +2 -1
- package/assets/templates/pages/login-split/template.doc.mjs +2 -1
- package/assets/templates/pages/login-sso/template.doc.mjs +4 -2
- package/assets/templates/pages/mixed-gallery/template.doc.mjs +2 -1
- package/assets/templates/pages/product-detail/template.doc.mjs +4 -2
- package/assets/templates/pages/product-gallery/template.doc.mjs +2 -1
- package/assets/templates/pages/settings-dialog/template.doc.mjs +2 -1
- package/assets/templates/pages/settings-sidebar/template.doc.mjs +2 -1
- package/assets/templates/pages/shell-nav/template.doc.mjs +4 -2
- package/assets/templates/pages/shell-side-nav/template.doc.mjs +5 -3
- package/assets/templates/pages/shell-top-nav/template.doc.mjs +2 -1
- package/assets/templates/pages/side-gallery/template.doc.mjs +9 -1
- package/assets/templates/pages/table-filter/template.doc.mjs +9 -8
- package/assets/templates/pages/table-grouped/template.doc.mjs +4 -2
- package/assets/templates/pages/table-page/template.doc.mjs +5 -4
- package/assets/templates/pages/table-tree/template.doc.mjs +6 -3
- package/assets/templates/pages/theme-showcase/template.doc.mjs +2 -9
- package/assets/templates/pages/work-item-detail/template.doc.mjs +1 -0
- package/authoring/debug/parse.d.mts +3 -3
- package/authoring/doctypes/_schema.d.mts +3 -3
- package/authoring/doctypes/command/command.doc.mjs +1 -1
- package/authoring/doctypes/template/template.doc.mjs +1 -1
- package/authoring/doctypes/template/type.ts +9 -0
- package/clients/cli/bin/astryx.mjs +6 -9
- package/clients/cli/build-id.generated.json +1 -1
- package/clients/cli/commands/component.doc.mjs +1 -1
- package/clients/cli/commands/component.mjs +20 -2
- package/clients/cli/commands/docs.doc.mjs +7 -1
- package/clients/cli/commands/docs.mjs +3 -1
- package/clients/cli/commands/doctor.mjs +22 -14
- package/clients/cli/commands/experimental/render.mjs +32 -1
- package/clients/cli/commands/experimental/theme.mjs +65 -14
- package/clients/cli/commands/experimental-render.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-compile.doc.mjs +3 -3
- package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
- package/clients/cli/commands/search.doc.mjs +2 -1
- package/clients/cli/commands/search.mjs +6 -1
- package/clients/cli/commands/template.mjs +4 -2
- package/clients/cli/commands/theme-build.doc.mjs +5 -1
- package/clients/cli/commands/theme.doc.mjs +1 -1
- package/clients/cli/commands/theme.mjs +153 -5
- package/clients/cli/commands/upgrade.mjs +42 -7
- package/clients/cli/index.mjs +1 -1
- package/clients/cli/lib/component-format.mjs +205 -98
- package/clients/cli/lib/hook-format.mjs +9 -19
- package/clients/cli/manifest.generated.json +1 -1
- package/foundation/agent-docs/agent-docs.mjs +1 -1
- package/foundation/config/theme-state.d.mts +13 -1
- package/foundation/config/theme-state.mjs +47 -7
- package/foundation/discovery/component-discovery.d.mts +11 -0
- package/foundation/discovery/component-discovery.mjs +27 -2
- package/foundation/discovery/component-replacement.mjs +130 -1
- package/foundation/discovery/entry-name-files.d.mts +43 -0
- package/foundation/discovery/entry-name-files.mjs +264 -0
- package/foundation/discovery/hook-discovery.d.mts +8 -2
- package/foundation/discovery/hook-discovery.mjs +20 -7
- package/foundation/discovery/package-exports.d.mts +10 -0
- package/foundation/discovery/package-exports.mjs +56 -3
- package/foundation/discovery/runner-allowlist.d.mts +1 -0
- package/foundation/discovery/runner-allowlist.mjs +2 -0
- package/foundation/discovery/template-adapter.d.mts +52 -0
- package/foundation/discovery/template-adapter.mjs +173 -10
- package/foundation/discovery/theme-imports.d.mts +14 -0
- package/foundation/discovery/theme-imports.mjs +43 -1
- package/foundation/doc-compiler/import.mjs +7 -1
- package/foundation/doc-compiler/parse-readable.mjs +4 -1
- package/foundation/doc-compiler/stored-docs.d.mts +22 -0
- package/foundation/doc-compiler/stored-docs.mjs +49 -0
- package/foundation/fs/cache-eviction.d.mts +21 -0
- package/foundation/fs/cache-eviction.mjs +73 -0
- package/foundation/fs/gather-cache.d.mts +25 -4
- package/foundation/fs/gather-cache.mjs +163 -53
- package/foundation/fs/jiti-cache.d.mts +19 -1
- package/foundation/fs/jiti-cache.mjs +130 -6
- package/foundation/fs/kept-tree.d.mts +60 -0
- package/foundation/fs/kept-tree.mjs +154 -0
- package/foundation/fs/module-loader.d.mts +18 -2
- package/foundation/fs/module-loader.mjs +92 -20
- package/foundation/identity/provider-identity.d.mts +6 -0
- package/foundation/identity/provider-identity.mjs +10 -1
- package/foundation/render/embedded-imports.d.mts +5 -4
- package/foundation/render/embedded-imports.mjs +7 -16
- package/foundation/render/file-header.d.mts +66 -0
- package/foundation/render/file-header.mjs +118 -0
- package/foundation/render/host-answer.d.mts +18 -0
- package/foundation/render/host-answer.mjs +46 -0
- package/foundation/render/host-exit.d.mts +1 -0
- package/foundation/render/host-exit.mjs +6 -1
- package/foundation/render/html-reader.d.mts +55 -2
- package/foundation/render/html-reader.mjs +145 -26
- package/foundation/render/markup-edits.d.mts +57 -0
- package/foundation/render/markup-edits.mjs +182 -0
- package/foundation/render/page-host.mjs +29 -12
- package/foundation/render/page-worker.mjs +83 -13
- package/foundation/render/render-page.d.mts +34 -2
- package/foundation/render/render-page.mjs +210 -29
- package/foundation/render/source-block.d.mts +73 -6
- package/foundation/render/source-block.mjs +170 -19
- package/foundation/render/ts-paths.d.mts +53 -6
- package/foundation/render/ts-paths.mjs +286 -41
- package/foundation/response/error-codes.d.mts +3 -1
- package/foundation/response/error-codes.d.ts +1 -0
- package/foundation/response/error-codes.doc.mjs +12 -1
- package/foundation/response/error-codes.mjs +10 -0
- package/foundation/text/string-utils.d.mts +3 -2
- package/foundation/text/string-utils.mjs +16 -3
- package/foundation/text/suggest-order.d.mts +9 -0
- package/foundation/text/suggest-order.mjs +13 -0
- package/host/index.mjs +8 -6
- package/package.json +6 -6
|
@@ -142,6 +142,10 @@ export type PartRecord = {
|
|
|
142
142
|
tokens: Record<string, string[]>;
|
|
143
143
|
values: string[];
|
|
144
144
|
}>;
|
|
145
|
+
/**
|
|
146
|
+
* - property -> the value under each condition, private variables resolved
|
|
147
|
+
*/
|
|
148
|
+
at?: Record<string, Record<string, string>> | undefined;
|
|
145
149
|
/**
|
|
146
150
|
* - tokens read by unnamed elements inside the part -> properties
|
|
147
151
|
*/
|
|
@@ -154,6 +158,10 @@ export type PartRecord = {
|
|
|
154
158
|
* - parts rendered inside it
|
|
155
159
|
*/
|
|
156
160
|
contains: string[];
|
|
161
|
+
/**
|
|
162
|
+
* - state -> property -> the token Core paints it with as an inline style in that state, which outranks any theme rule
|
|
163
|
+
*/
|
|
164
|
+
inline?: Record<string, Record<string, string>> | undefined;
|
|
157
165
|
};
|
|
158
166
|
export type PaintSide = {
|
|
159
167
|
target: string | null;
|
|
@@ -31,14 +31,16 @@ import {
|
|
|
31
31
|
import {SAMPLE_PAGE, elementNames, pageSource} from './_catalog.mjs';
|
|
32
32
|
|
|
33
33
|
/** Bump when the shape of the cached part data changes. */
|
|
34
|
-
const PART_DATA_VERSION =
|
|
34
|
+
const PART_DATA_VERSION = 6;
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
37
|
* @typedef {object} PartRecord
|
|
38
38
|
* @property {Record<string, {tokens: Record<string, string[]>, values: string[]}>} own - property -> tokens (with conditions) and raw values
|
|
39
|
+
* @property {Record<string, Record<string, string>>} [at] - property -> the value under each condition, private variables resolved
|
|
39
40
|
* @property {Record<string, string[]>} inside - tokens read by unnamed elements inside the part -> properties
|
|
40
41
|
* @property {Record<string, string[]>} attrs - data attributes seen on the part
|
|
41
42
|
* @property {string[]} contains - parts rendered inside it
|
|
43
|
+
* @property {Record<string, Record<string, string>>} [inline] - state -> property -> the token Core paints it with as an inline style in that state, which outranks any theme rule
|
|
42
44
|
*/
|
|
43
45
|
|
|
44
46
|
/**
|
|
@@ -473,6 +475,79 @@ export async function partData(project) {
|
|
|
473
475
|
return data;
|
|
474
476
|
}
|
|
475
477
|
|
|
478
|
+
/**
|
|
479
|
+
* Add the paint Core writes as an inline style when it sets a theme state
|
|
480
|
+
* at run time (a table row's selection wash, set by the selection plugin
|
|
481
|
+
* beside the row's `selected` state): something the server render never
|
|
482
|
+
* shows. A built module under a component's folder that writes a state's
|
|
483
|
+
* attribute (`themeDataAttributes({selected: 'selected'})`) and an inline
|
|
484
|
+
* property from a color token (`el.style.backgroundColor = …` with
|
|
485
|
+
* `colorVars['--color-accent-muted']`) paints that state with it, on each
|
|
486
|
+
* of the component's targets that lists the state.
|
|
487
|
+
* @param {import('./_project.mjs').ThemeProject} project
|
|
488
|
+
* @param {Record<string, PartRecord>} map
|
|
489
|
+
*/
|
|
490
|
+
function addInlineStatePaint(project, map) {
|
|
491
|
+
const dist = path.join(project.coreDir, 'dist');
|
|
492
|
+
/** @param {string} dir @returns {string[]} */
|
|
493
|
+
const modules = dir => {
|
|
494
|
+
let entries;
|
|
495
|
+
try {
|
|
496
|
+
entries = fs.readdirSync(dir, {withFileTypes: true});
|
|
497
|
+
} catch {
|
|
498
|
+
return [];
|
|
499
|
+
}
|
|
500
|
+
return entries.flatMap(e =>
|
|
501
|
+
e.isDirectory()
|
|
502
|
+
? modules(path.join(dir, e.name))
|
|
503
|
+
: e.name.endsWith('.js')
|
|
504
|
+
? [path.join(dir, e.name)]
|
|
505
|
+
: [],
|
|
506
|
+
);
|
|
507
|
+
};
|
|
508
|
+
for (const [name, info] of Object.entries(project.components)) {
|
|
509
|
+
const folder = info.importPath?.split('/').pop();
|
|
510
|
+
if (!folder || folder !== name) continue;
|
|
511
|
+
const withStates = info.targets.filter(t => t.states.length);
|
|
512
|
+
if (!withStates.length) continue;
|
|
513
|
+
for (const file of modules(path.join(dist, folder))) {
|
|
514
|
+
const source = fs.readFileSync(file, 'utf8');
|
|
515
|
+
const states = [
|
|
516
|
+
...source.matchAll(
|
|
517
|
+
/themeDataAttributes\(\{\s*([\w-]+):\s*'\1'\s*\}\)/g,
|
|
518
|
+
),
|
|
519
|
+
].map(m => m[1]);
|
|
520
|
+
if (!states.length) continue;
|
|
521
|
+
const props = [
|
|
522
|
+
...source.matchAll(/\.style\.([a-z][A-Za-z]*)\s*=(?!=)/g),
|
|
523
|
+
].map(m => m[1].replace(/[A-Z]/g, c => `-${c.toLowerCase()}`));
|
|
524
|
+
const colorTokens = [
|
|
525
|
+
...source.matchAll(/colorVars\[['"](--color-[\w-]+)['"]\]/g),
|
|
526
|
+
].map(m => m[1]);
|
|
527
|
+
if (!props.length || colorTokens.length !== 1) continue;
|
|
528
|
+
for (const t of withStates) {
|
|
529
|
+
const key = t.className.replace(/^astryx-/, '');
|
|
530
|
+
const rec = map[key];
|
|
531
|
+
if (!rec) continue;
|
|
532
|
+
for (const state of states.filter(st => t.states.includes(st)))
|
|
533
|
+
for (const prop of props) {
|
|
534
|
+
(rec.inline ??= {})[state] = {
|
|
535
|
+
...rec.inline?.[state],
|
|
536
|
+
[prop]: colorTokens[0],
|
|
537
|
+
};
|
|
538
|
+
const own = (rec.own[prop] ??= {tokens: {}, values: []});
|
|
539
|
+
own.tokens[colorTokens[0]] = [
|
|
540
|
+
...new Set([
|
|
541
|
+
...(own.tokens[colorTokens[0]] ?? []),
|
|
542
|
+
`${state}=${state}`,
|
|
543
|
+
]),
|
|
544
|
+
];
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
|
|
476
551
|
/**
|
|
477
552
|
* Build the part data: render the catalog, then walk its markup.
|
|
478
553
|
* @param {import('./_project.mjs').ThemeProject} project
|
|
@@ -497,6 +572,7 @@ async function buildPartData(project) {
|
|
|
497
572
|
}
|
|
498
573
|
const tokens = new Set(Object.keys(project.core.tokenDefaults ?? {}));
|
|
499
574
|
const result = walkMarkup(markup, declarations(css), tokens);
|
|
575
|
+
addInlineStatePaint(project, result.map);
|
|
500
576
|
return {
|
|
501
577
|
version: PART_DATA_VERSION,
|
|
502
578
|
coreKey: project.coreKey,
|
|
@@ -666,6 +742,24 @@ function expand(v, env, tokens, seen = new Set(), depth = 0) {
|
|
|
666
742
|
return out;
|
|
667
743
|
}
|
|
668
744
|
|
|
745
|
+
/**
|
|
746
|
+
* A value with the private variables set on the element or its ancestors
|
|
747
|
+
* put in (a variable with no fallback only), so it reads public tokens and
|
|
748
|
+
* literal values alone where it can.
|
|
749
|
+
* @param {string} v
|
|
750
|
+
* @param {Record<string, string>} env
|
|
751
|
+
* @param {Set<string>} tokens
|
|
752
|
+
* @param {number} [depth]
|
|
753
|
+
* @returns {string}
|
|
754
|
+
*/
|
|
755
|
+
function resolvePrivate(v, env, tokens, depth = 0) {
|
|
756
|
+
if (depth > 8) return v;
|
|
757
|
+
const out = v.replace(/var\((--[a-zA-Z0-9_-]+)\)/g, (m, name) =>
|
|
758
|
+
!tokens.has(name) && env[name] != null ? env[name] : m,
|
|
759
|
+
);
|
|
760
|
+
return out === v ? v : resolvePrivate(out, env, tokens, depth + 1);
|
|
761
|
+
}
|
|
762
|
+
|
|
669
763
|
/**
|
|
670
764
|
* Walk server-rendered markup: for each element, its classes' declarations
|
|
671
765
|
* become what its part reads; text records the color pair it sits on.
|
|
@@ -675,7 +769,7 @@ function expand(v, env, tokens, seen = new Set(), depth = 0) {
|
|
|
675
769
|
* @returns {{map: Record<string, PartRecord>, pairs: TextPair[]}}
|
|
676
770
|
*/
|
|
677
771
|
export function walkMarkup(html, decls, tokens) {
|
|
678
|
-
/** @type {Record<string, {own: Record<string, {tokens: Record<string, Set<string>>, values: Set<string>}>, inside: Record<string, Set<string>>, attrs: Record<string, Set<string>>, contains: Set<string>}>} */
|
|
772
|
+
/** @type {Record<string, {own: Record<string, {tokens: Record<string, Set<string>>, values: Set<string>}>, at: Record<string, Record<string, string>>, inside: Record<string, Set<string>>, attrs: Record<string, Set<string>>, contains: Set<string>}>} */
|
|
679
773
|
const map = {};
|
|
680
774
|
/** @type {Array<{env: Record<string, string>, target: string | null, fg: PaintSide | null, bg: PaintSide | null}>} */
|
|
681
775
|
const stack = [{env: {}, target: null, fg: null, bg: null}];
|
|
@@ -726,6 +820,7 @@ export function walkMarkup(html, decls, tokens) {
|
|
|
726
820
|
if (target) {
|
|
727
821
|
const T = (map[target] ??= {
|
|
728
822
|
own: {},
|
|
823
|
+
at: {},
|
|
729
824
|
inside: {},
|
|
730
825
|
attrs: {},
|
|
731
826
|
contains: new Set(),
|
|
@@ -742,6 +837,11 @@ export function walkMarkup(html, decls, tokens) {
|
|
|
742
837
|
const cond = [cond0, d.cond].filter(Boolean).join(' ');
|
|
743
838
|
if (ownsTarget) {
|
|
744
839
|
const P = (T.own[d.prop] ??= {tokens: {}, values: new Set()});
|
|
840
|
+
(T.at[d.prop] ??= {})[cond || 'always'] ??= resolvePrivate(
|
|
841
|
+
d.value,
|
|
842
|
+
env,
|
|
843
|
+
tokens,
|
|
844
|
+
);
|
|
745
845
|
P.values.add(
|
|
746
846
|
d.value.length > 80 ? `${d.value.slice(0, 80)}...` : d.value,
|
|
747
847
|
);
|
|
@@ -792,6 +892,7 @@ export function walkMarkup(html, decls, tokens) {
|
|
|
792
892
|
},
|
|
793
893
|
]),
|
|
794
894
|
),
|
|
895
|
+
at: v.at,
|
|
795
896
|
inside: Object.fromEntries(
|
|
796
897
|
Object.entries(v.inside).map(([k, s]) => [k, [...s]]),
|
|
797
898
|
),
|
|
@@ -68,12 +68,18 @@ export function refreshPreviewRoute(cwd: string, slug: string): Promise<{
|
|
|
68
68
|
* @param {'colors' | 'components' | 'overview'} focus
|
|
69
69
|
* @param {{code: string, cause: string} | null} [notChecked] why the change
|
|
70
70
|
* could not be rendered
|
|
71
|
+
* @param {{pictureProblem?: string | null, stale?: string[]}} [extra] this
|
|
72
|
+
* result's picture problem (what kept --png from taking pictures) and its
|
|
73
|
+
* previewStale entries (an in-app preview changed by hand)
|
|
71
74
|
* @returns {string}
|
|
72
75
|
*/
|
|
73
76
|
export function seeLine(cwd: string, slug: string, focus: "colors" | "components" | "overview", notChecked?: {
|
|
74
77
|
code: string;
|
|
75
78
|
cause: string;
|
|
76
|
-
} | null
|
|
79
|
+
} | null, extra?: {
|
|
80
|
+
pictureProblem?: string | null;
|
|
81
|
+
stale?: string[];
|
|
82
|
+
}): string;
|
|
77
83
|
/**
|
|
78
84
|
* Add pages to the in-app theme preview, and write the preview route the
|
|
79
85
|
* first time. With a description, the build ranking picks the template
|
|
@@ -999,7 +999,12 @@ function checkPlacement(cwd, dir, where, retry) {
|
|
|
999
999
|
if (served && app !== served)
|
|
1000
1000
|
refuse(
|
|
1001
1001
|
E.ERR_INVALID_ARGUMENT,
|
|
1002
|
-
|
|
1002
|
+
// Next serves the root app/ when both are there: a preview in src/app/
|
|
1003
|
+
// under a root app/ is not served, and a new root app/ beside the
|
|
1004
|
+
// app's src/app/ would hide the whole app.
|
|
1005
|
+
path.resolve(app) === path.join(path.resolve(cwd), 'app')
|
|
1006
|
+
? `${where} would make ${shown(cwd, app)}/ beside ${shown(cwd, served)}/, and Next serves the root app/ when both are there, so the whole app in ${shown(cwd, served)}/ would stop being served.`
|
|
1007
|
+
: `${where} is in ${shown(cwd, app)}/, and Next serves ${shown(cwd, served)}/ instead when both are there.`,
|
|
1003
1008
|
{
|
|
1004
1009
|
run: fs.existsSync(path.join(dir, PREVIEW_DATA))
|
|
1005
1010
|
? [
|
|
@@ -1098,11 +1103,30 @@ function previewDir(cwd, where, opts = {}) {
|
|
|
1098
1103
|
checkFolderName(where, '--path', retry);
|
|
1099
1104
|
/** @type {string} */
|
|
1100
1105
|
let dir;
|
|
1106
|
+
// A --path read from the folder the command ran in; one that names a
|
|
1107
|
+
// preview from the project root (as every printed folder is) is read
|
|
1108
|
+
// from there, so a printed tip works from a subfolder too.
|
|
1109
|
+
const fromRoot = (() => {
|
|
1110
|
+
// The --path as given from the subfolder the command ran in, rebased
|
|
1111
|
+
// onto the project root by the caller: when that names no folder and
|
|
1112
|
+
// the path without the subfolder names a preview, that one.
|
|
1113
|
+
const sub = path.relative(cwd, process.cwd());
|
|
1114
|
+
if (!sub || sub.startsWith('..') || path.isAbsolute(where)) return null;
|
|
1115
|
+
const given = path.normalize(where);
|
|
1116
|
+
if (!given.startsWith(sub + path.sep)) return null;
|
|
1117
|
+
const there = path.resolve(cwd, given.slice(sub.length + 1));
|
|
1118
|
+
return !fs.existsSync(path.resolve(cwd, where)) &&
|
|
1119
|
+
fs.existsSync(path.join(there, PREVIEW_DATA))
|
|
1120
|
+
? there
|
|
1121
|
+
: null;
|
|
1122
|
+
})();
|
|
1101
1123
|
try {
|
|
1102
|
-
dir =
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1124
|
+
dir =
|
|
1125
|
+
fromRoot ??
|
|
1126
|
+
assertWithin(path.resolve(cwd, where), cwd, {
|
|
1127
|
+
allowAbsolute: true,
|
|
1128
|
+
label: '--path',
|
|
1129
|
+
});
|
|
1106
1130
|
} catch (e) {
|
|
1107
1131
|
if (e instanceof PathSafetyError)
|
|
1108
1132
|
refuse(
|
|
@@ -1324,7 +1348,7 @@ export function appWiring(ctx, slug, data) {
|
|
|
1324
1348
|
return [
|
|
1325
1349
|
...(blocker
|
|
1326
1350
|
? [
|
|
1327
|
-
|
|
1351
|
+
`the app copy in src/themes/${slug}/ was not updated: ${blocker}; the steps by hand:`,
|
|
1328
1352
|
]
|
|
1329
1353
|
: []),
|
|
1330
1354
|
`in ${where}, import the theme and its stylesheets: import {Theme} from '@astryxdesign/core/theme'; import {${name}} from '${ti.module.replace(/\.js$/, '')}'; ${ti.css.map(c => `import '${c}';`).join(' ')}`,
|
|
@@ -1501,7 +1525,7 @@ function planStarterApp(cwd, where, extra, dependencies, slug = null) {
|
|
|
1501
1525
|
if (e instanceof PathSafetyError)
|
|
1502
1526
|
refuse(
|
|
1503
1527
|
E.ERR_PATH_TRAVERSAL,
|
|
1504
|
-
`${where} is outside the
|
|
1528
|
+
`${where} is outside the project; make the app inside the project folder.`,
|
|
1505
1529
|
{run: [again(null)]},
|
|
1506
1530
|
);
|
|
1507
1531
|
throw e;
|
|
@@ -3205,8 +3229,15 @@ function dirFlag(cwd, dir) {
|
|
|
3205
3229
|
*/
|
|
3206
3230
|
export async function refreshPreviewRoute(cwd, slug) {
|
|
3207
3231
|
const at = previewDir(cwd, undefined, {optional: true});
|
|
3232
|
+
// The same previews `see` names: the usual folder, the recorded ones,
|
|
3233
|
+
// and any in the routes folders that wear the theme (a folder renamed by
|
|
3234
|
+
// hand, or one whose record was lost).
|
|
3208
3235
|
const dirs = [
|
|
3209
|
-
...new Set([
|
|
3236
|
+
...new Set([
|
|
3237
|
+
...(at ? [at.dir] : []),
|
|
3238
|
+
...recordedPreviews(cwd, slug),
|
|
3239
|
+
...previewsIn(cwd),
|
|
3240
|
+
]),
|
|
3210
3241
|
];
|
|
3211
3242
|
let changed = false;
|
|
3212
3243
|
/** @type {string[]} */
|
|
@@ -3244,7 +3275,7 @@ export async function refreshPreviewRoute(cwd, slug) {
|
|
|
3244
3275
|
stale.push(
|
|
3245
3276
|
standIn
|
|
3246
3277
|
? `${shown(cwd, file)} (changed by hand, so it is kept; the theme has no generated colors now, so ${standIn}, which the page imports, holds an empty stand-in that keeps the app building. Give the page another name if you want to keep your changes, then run ${PREVIEW} add)`
|
|
3247
|
-
: shown(cwd, file),
|
|
3278
|
+
: `${shown(cwd, file)} (changed by hand, so it does not follow this change: move it out of ${shownDir(cwd, dir)}/, keeping your copy elsewhere in the app and importing nothing from the preview folder, then run ${PREVIEW} add${dirFlag(cwd, dir)} to write it again)`,
|
|
3248
3279
|
);
|
|
3249
3280
|
return false;
|
|
3250
3281
|
}
|
|
@@ -3260,7 +3291,20 @@ export async function refreshPreviewRoute(cwd, slug) {
|
|
|
3260
3291
|
`${shownDir(cwd, dir)}/ (${slug} has generated colors now; ${PREVIEW} add${dirFlag(cwd, dir)} adds its Colors page)`,
|
|
3261
3292
|
);
|
|
3262
3293
|
if (!writes.length) continue;
|
|
3263
|
-
|
|
3294
|
+
// A route that cannot be written (its permissions, a folder in its
|
|
3295
|
+
// place) does not follow this change: said, never a quiet ok.
|
|
3296
|
+
try {
|
|
3297
|
+
commitPreview(cwd, dir, data, writes, [], `${EDITOR} show ${slug}`);
|
|
3298
|
+
} catch (e) {
|
|
3299
|
+
const code =
|
|
3300
|
+
/\b(E[A-Z]{2,})\b/.exec(
|
|
3301
|
+
`${/** @type {any} */ (e)?.code ?? ''} ${e instanceof Error ? e.message : ''}`,
|
|
3302
|
+
)?.[1] ?? 'it could not be written';
|
|
3303
|
+
stale.push(
|
|
3304
|
+
`${shownDir(cwd, dir)}/ (could not be written: ${code}, so the in-app preview does not follow this change; fix its permissions, then ${PREVIEW} add${dirFlag(cwd, dir)} writes it again)`,
|
|
3305
|
+
);
|
|
3306
|
+
continue;
|
|
3307
|
+
}
|
|
3264
3308
|
changed = true;
|
|
3265
3309
|
}
|
|
3266
3310
|
return {changed, stale};
|
|
@@ -3339,11 +3383,53 @@ function routesOf(cwd, at) {
|
|
|
3339
3383
|
function previewPath(cwd, at) {
|
|
3340
3384
|
const app = routesOf(cwd, at);
|
|
3341
3385
|
if (!app) return null;
|
|
3386
|
+
// A folder Next does not serve (_private, @slot, an intercepting route):
|
|
3387
|
+
// no URL, as add refuses it.
|
|
3388
|
+
if (unservedWhy(cwd, at.dir)) return null;
|
|
3342
3389
|
const segs = urlSegments(app, at.dir);
|
|
3343
3390
|
if (segs.some(seg => /^\[.+\]$/.test(seg))) return null;
|
|
3344
3391
|
const base = nextBasePath(cwd);
|
|
3345
3392
|
if (base == null) return null;
|
|
3346
|
-
|
|
3393
|
+
// A folder named %5F… is served at the decoded name (`_x`), encoded as a
|
|
3394
|
+
// URL segment needs it.
|
|
3395
|
+
const decoded = (/** @type {string} */ seg) => {
|
|
3396
|
+
try {
|
|
3397
|
+
return decodeURIComponent(seg);
|
|
3398
|
+
} catch {
|
|
3399
|
+
return seg;
|
|
3400
|
+
}
|
|
3401
|
+
};
|
|
3402
|
+
return `${base}/${segs.map(seg => encodeURIComponent(decoded(seg))).join('/')}`;
|
|
3403
|
+
}
|
|
3404
|
+
|
|
3405
|
+
/**
|
|
3406
|
+
* Why a preview folder found in the routes folder is not served, or null.
|
|
3407
|
+
* @param {string} cwd
|
|
3408
|
+
* @param {string} dir
|
|
3409
|
+
* @returns {string | null}
|
|
3410
|
+
*/
|
|
3411
|
+
function unservedWhy(cwd, dir) {
|
|
3412
|
+
const app = routesOf(cwd, {dir, app: null});
|
|
3413
|
+
if (!app) return null;
|
|
3414
|
+
// The same rules add keeps: src/app/ while app/ is what Next serves, and
|
|
3415
|
+
// a next.config whose page extensions leave out page.tsx.
|
|
3416
|
+
const served = [path.join(cwd, 'app'), path.join(cwd, 'src', 'app')].find(
|
|
3417
|
+
r => fs.existsSync(r) && fs.statSync(r).isDirectory(),
|
|
3418
|
+
);
|
|
3419
|
+
if (served && path.resolve(app) !== path.resolve(served))
|
|
3420
|
+
return `Next serves ${shown(cwd, served)}/ instead of ${shown(cwd, app)}/ when both are there`;
|
|
3421
|
+
try {
|
|
3422
|
+
const exts = readNextConfig(cwd).pageExtensions;
|
|
3423
|
+
if (exts && !exts.includes('tsx'))
|
|
3424
|
+
return `next.config sets pageExtensions to ${exts.join(', ')}, so Next does not serve page.tsx`;
|
|
3425
|
+
} catch {
|
|
3426
|
+
// A config this cannot read is not a reason to hide the URL.
|
|
3427
|
+
}
|
|
3428
|
+
// A [param] folder is served, with a value for it; only _private, @slot
|
|
3429
|
+
// and intercepting folders are not.
|
|
3430
|
+
const segs = path.relative(app, dir).split(path.sep);
|
|
3431
|
+
if (!segs.some(x => /^[_@]/.test(x) || INTERCEPT.test(x))) return null;
|
|
3432
|
+
return unroutedSegment(app, dir);
|
|
3347
3433
|
}
|
|
3348
3434
|
|
|
3349
3435
|
/**
|
|
@@ -3374,13 +3460,26 @@ function pageUrls(cwd, at, ids) {
|
|
|
3374
3460
|
* @param {'colors' | 'components' | 'overview'} focus
|
|
3375
3461
|
* @param {{code: string, cause: string} | null} [notChecked] why the change
|
|
3376
3462
|
* could not be rendered
|
|
3463
|
+
* @param {{pictureProblem?: string | null, stale?: string[]}} [extra] this
|
|
3464
|
+
* result's picture problem (what kept --png from taking pictures) and its
|
|
3465
|
+
* previewStale entries (an in-app preview changed by hand)
|
|
3377
3466
|
* @returns {string}
|
|
3378
3467
|
*/
|
|
3379
|
-
export function seeLine(cwd, slug, focus, notChecked = null) {
|
|
3468
|
+
export function seeLine(cwd, slug, focus, notChecked = null, extra = {}) {
|
|
3380
3469
|
/** @type {string[]} */
|
|
3381
3470
|
const urls = [];
|
|
3382
3471
|
/** Previews whose URL depends on the app's routing. @type {string[]} */
|
|
3383
3472
|
const unplain = [];
|
|
3473
|
+
/** Previews in a folder Next does not serve. @type {string[]} */
|
|
3474
|
+
const unserved = [];
|
|
3475
|
+
/** Their folders, as --path takes them. @type {string[]} */
|
|
3476
|
+
const unservedDirs = [];
|
|
3477
|
+
/** @type {string[]} */
|
|
3478
|
+
const stale = extra.stale ?? [];
|
|
3479
|
+
/** Previews whose route was changed by hand. @type {string[]} */
|
|
3480
|
+
const handEdited = [];
|
|
3481
|
+
/** Previews whose record is damaged. @type {string[]} */
|
|
3482
|
+
const damaged = [];
|
|
3384
3483
|
// The previews recorded for the theme, and any found in the routes
|
|
3385
3484
|
// folders that wear it (a folder renamed by hand), as remove finds them.
|
|
3386
3485
|
const dirs = [
|
|
@@ -3391,10 +3490,33 @@ export function seeLine(cwd, slug, focus, notChecked = null) {
|
|
|
3391
3490
|
let data;
|
|
3392
3491
|
try {
|
|
3393
3492
|
data = JSON.parse(fs.readFileSync(path.join(dir, PREVIEW_DATA), 'utf8'));
|
|
3394
|
-
} catch {
|
|
3493
|
+
} catch (e) {
|
|
3494
|
+
// A record that is there but damaged: the preview commands refuse
|
|
3495
|
+
// it until it is fixed, so no add tip, the repair instead.
|
|
3496
|
+
if (
|
|
3497
|
+
fs.existsSync(path.join(dir, PREVIEW_DATA)) &&
|
|
3498
|
+
!(/** @type {any} */ (e)?.code)
|
|
3499
|
+
)
|
|
3500
|
+
damaged.push(shownDir(cwd, dir));
|
|
3395
3501
|
continue;
|
|
3396
3502
|
}
|
|
3397
3503
|
if (data?.theme !== slug) continue;
|
|
3504
|
+
const why = unservedWhy(cwd, dir);
|
|
3505
|
+
if (why) {
|
|
3506
|
+
unserved.push(`${shownDir(cwd, dir)}/ (${why})`);
|
|
3507
|
+
unservedDirs.push(shownDir(cwd, dir));
|
|
3508
|
+
continue;
|
|
3509
|
+
}
|
|
3510
|
+
if (
|
|
3511
|
+
stale.some(
|
|
3512
|
+
f =>
|
|
3513
|
+
f.startsWith(`${shownDir(cwd, dir)}/`) &&
|
|
3514
|
+
/changed by hand|could not be written/.test(f),
|
|
3515
|
+
)
|
|
3516
|
+
) {
|
|
3517
|
+
handEdited.push(shownDir(cwd, dir));
|
|
3518
|
+
continue;
|
|
3519
|
+
}
|
|
3398
3520
|
const ids = Array.isArray(data?.pages)
|
|
3399
3521
|
? data.pages.map((/** @type {any} */ x) => String(x?.id))
|
|
3400
3522
|
: [];
|
|
@@ -3408,16 +3530,56 @@ export function seeLine(cwd, slug, focus, notChecked = null) {
|
|
|
3408
3530
|
);
|
|
3409
3531
|
}
|
|
3410
3532
|
const f = themeFiles(cwd, slug);
|
|
3533
|
+
// What keeps --png from taking pictures, when this result's own picture
|
|
3534
|
+
// run failed (a file of yours named like a picture).
|
|
3535
|
+
// A command that only takes pictures, whatever this one was (an undo run
|
|
3536
|
+
// again undoes another change; new refuses a theme that exists).
|
|
3537
|
+
const pngNote = extra.pictureProblem
|
|
3538
|
+
? `--png took no pictures: ${extra.pictureProblem}`
|
|
3539
|
+
: `${EDITOR} show ${slug} --png takes pictures in ${shownDir(cwd, f.dir)}/ with no dev server (it needs a Playwright or a Chrome)`;
|
|
3411
3540
|
const own = notChecked
|
|
3412
3541
|
? /could not be written/.test(notChecked.cause)
|
|
3413
3542
|
? `the change is saved, but ${notChecked.cause}; --png takes no pictures until that is fixed`
|
|
3414
3543
|
: `the change is saved, but the components could not be rendered here (${notChecked.cause}), so ${shown(cwd, f.preview)} still shows the theme as it was and --png takes no pictures until that is fixed`
|
|
3415
|
-
: `look without changing your app: open or screenshot ${shown(cwd, f.preview)} (one self-contained page, current after this change; ${EDITOR} show ${slug} also writes ${shown(cwd, f.sheet)}, every component), or
|
|
3544
|
+
: `look without changing your app: open or screenshot ${shown(cwd, f.preview)} (one self-contained page, current after this change; ${EDITOR} show ${slug} also writes ${shown(cwd, f.sheet)}, every component), or ${pngNote}`;
|
|
3545
|
+
const edited = handEdited.length
|
|
3546
|
+
? `; the in-app preview in ${handEdited.slice(0, 2).join(', ')}/ ${stale.some(f => /could not be written/.test(f)) && !stale.some(f => /changed by hand/.test(f)) ? 'could not be written' : 'was changed by hand'}, so it does not follow this change (previewStale says what to move out, then ${PREVIEW} add writes it again)`
|
|
3547
|
+
: '';
|
|
3416
3548
|
if (urls.length)
|
|
3417
|
-
return `${own}; in the running app: open ${urls.slice(0, 2).join(' or ')}`;
|
|
3549
|
+
return `${own}; in the running app: open ${urls.slice(0, 2).join(' or ')}${edited}`;
|
|
3418
3550
|
if (unplain.length)
|
|
3419
|
-
return `${own}; the in-app preview is in ${unplain.slice(0, 2).join(', ')}, at a URL that depends on the app's routing`;
|
|
3420
|
-
|
|
3551
|
+
return `${own}; the in-app preview is in ${unplain.slice(0, 2).join(', ')}, at a URL that depends on the app's routing${edited}`;
|
|
3552
|
+
if (unserved.length) {
|
|
3553
|
+
// What fixes it, by why it is not served: add's own answer for each.
|
|
3554
|
+
const why = unserved.join(' ');
|
|
3555
|
+
const fix = /Next serves .* when both are there/.test(why)
|
|
3556
|
+
? `${PREVIEW} remove --path ${quoteCommandArgument(unservedDirs[0])}, then ${PREVIEW} add --theme ${slug} puts it in the folder Next serves`
|
|
3557
|
+
: /pageExtensions/.test(why)
|
|
3558
|
+
? `add "tsx" to pageExtensions in next.config so Next serves the preview's page.tsx`
|
|
3559
|
+
: `move it back into a folder Next routes, or make one there with ${PREVIEW} add --theme ${slug} --path <a routed folder>`;
|
|
3560
|
+
return `${own}; the in-app preview is in ${unserved.slice(0, 2).join(', ')}, which the app does not serve: ${fix}${edited}`;
|
|
3561
|
+
}
|
|
3562
|
+
if (edited) return `${own}${edited}`;
|
|
3563
|
+
if (damaged.length)
|
|
3564
|
+
return `${own}; the in-app preview in ${damaged.slice(0, 2).join(', ')}/ has a damaged ${PREVIEW_DATA}, so it does not follow this change: fix it by hand, or give the folder a new name that starts with _ and run ${PREVIEW} add${editorThemeCount(cwd) > 1 ? ` --theme ${slug}` : ''}`;
|
|
3565
|
+
// With more than one editor theme, a bare add may wear another one.
|
|
3566
|
+
const many = editorThemeCount(cwd) > 1;
|
|
3567
|
+
return `${own}; to see it inside your app, ${PREVIEW} add${many ? ` --theme ${slug}` : ''} puts the preview pages there, each at its own URL`;
|
|
3568
|
+
}
|
|
3569
|
+
|
|
3570
|
+
/**
|
|
3571
|
+
* How many editor themes the project has.
|
|
3572
|
+
* @param {string} cwd
|
|
3573
|
+
*/
|
|
3574
|
+
function editorThemeCount(cwd) {
|
|
3575
|
+
const root = themeFiles(cwd, 'x').root;
|
|
3576
|
+
try {
|
|
3577
|
+
return fs
|
|
3578
|
+
.readdirSync(root)
|
|
3579
|
+
.filter(d => fs.existsSync(themeFiles(cwd, d).settings)).length;
|
|
3580
|
+
} catch {
|
|
3581
|
+
return 0;
|
|
3582
|
+
}
|
|
3421
3583
|
}
|
|
3422
3584
|
|
|
3423
3585
|
/**
|
|
@@ -4608,6 +4770,8 @@ export async function themeEditPreviewApp(dir, options = {}) {
|
|
|
4608
4770
|
from.sheet,
|
|
4609
4771
|
from.previewPng,
|
|
4610
4772
|
from.sheetPng,
|
|
4773
|
+
// The record of pictures, none of which come along.
|
|
4774
|
+
from.pictures,
|
|
4611
4775
|
].map(f => path.basename(f)),
|
|
4612
4776
|
);
|
|
4613
4777
|
// The whole folder, tokens/ included, as bytes: a font or a picture
|
|
@@ -4622,6 +4786,12 @@ export async function themeEditPreviewApp(dir, options = {}) {
|
|
|
4622
4786
|
else if (
|
|
4623
4787
|
entry.isFile() &&
|
|
4624
4788
|
!(rel === '' && skip.has(entry.name)) &&
|
|
4789
|
+
// No picture or preview page of any kind (dark pictures, section
|
|
4790
|
+
// sheets): the new app builds its own.
|
|
4791
|
+
!(
|
|
4792
|
+
rel === '' &&
|
|
4793
|
+
/^(preview|sheet)(-[a-z0-9-]+)?\.(html|png)$/.test(entry.name)
|
|
4794
|
+
) &&
|
|
4625
4795
|
// A temp file a stopped command left is no part of the theme.
|
|
4626
4796
|
!isEditorTemp(entry.name)
|
|
4627
4797
|
)
|
|
@@ -4994,6 +5164,24 @@ async function removePreview(page, options, box) {
|
|
|
4994
5164
|
const retry = (/** @type {string | null} */ p) =>
|
|
4995
5165
|
`${PREVIEW} remove${page != null ? ` ${quoteCommandArgument(page)}` : ''}${p == null ? '' : ` --path ${quoteCommandArgument(p)}`}`;
|
|
4996
5166
|
const at = previewDir(cwd, options.path, {retry});
|
|
5167
|
+
// A file given for the preview's folder: its folder when the file is a
|
|
5168
|
+
// preview's own, else the previews there are (as add refuses a file).
|
|
5169
|
+
if (fs.existsSync(at.dir) && !fs.statSync(at.dir).isDirectory()) {
|
|
5170
|
+
const parent = path.dirname(at.dir);
|
|
5171
|
+
const own = fs.existsSync(path.join(parent, PREVIEW_DATA));
|
|
5172
|
+
const others = previewsIn(cwd);
|
|
5173
|
+
refuse(
|
|
5174
|
+
E.ERR_INVALID_ARGUMENT,
|
|
5175
|
+
`${shown(cwd, at.dir)} is a file; a preview is a folder${own ? `, and this file is in the preview ${shownDir(cwd, parent)}/` : ''}.`,
|
|
5176
|
+
{
|
|
5177
|
+
run: own
|
|
5178
|
+
? [retry(shownDir(cwd, parent))]
|
|
5179
|
+
: others.length
|
|
5180
|
+
? others.slice(0, 3).map(d => retry(shownDir(cwd, d)))
|
|
5181
|
+
: [`${PREVIEW} list`],
|
|
5182
|
+
},
|
|
5183
|
+
);
|
|
5184
|
+
}
|
|
4997
5185
|
// The pages a stopped change was removing, read before it is finished.
|
|
4998
5186
|
/** @type {string[]} */
|
|
4999
5187
|
let removing = [];
|
|
@@ -152,7 +152,7 @@ export function previewRouteSource({ pages, theme, by, }: {
|
|
|
152
152
|
* @param {string} html absolute
|
|
153
153
|
* @param {string} png absolute
|
|
154
154
|
* @param {'light' | 'dark'} mode
|
|
155
|
-
* @returns {Promise<{ok: true, file: string, cut?: boolean} | {ok: false, reason: string}>} `cut` when the picture is of the window, not the whole page
|
|
155
|
+
* @returns {Promise<{ok: true, file: string, cut?: boolean} | {ok: false, reason: string, stopped?: string}>} `cut` when the picture is of the window, not the whole page
|
|
156
156
|
*/
|
|
157
157
|
export function screenshot(project: import("./_project.mjs").ThemeProject, html: string, png: string, mode: "light" | "dark"): Promise<{
|
|
158
158
|
ok: true;
|
|
@@ -161,7 +161,17 @@ export function screenshot(project: import("./_project.mjs").ThemeProject, html:
|
|
|
161
161
|
} | {
|
|
162
162
|
ok: false;
|
|
163
163
|
reason: string;
|
|
164
|
+
stopped?: string;
|
|
164
165
|
}>;
|
|
166
|
+
/**
|
|
167
|
+
* The font stylesheets a theme's app copy imports, from the fonts the theme
|
|
168
|
+
* loads now (an installed font package, the base theme's fonts).
|
|
169
|
+
* @param {import('./_settings.mjs').Ctx} ctx
|
|
170
|
+
* @param {string} slug
|
|
171
|
+
* @param {import('./_settings.mjs').ThemeData} data
|
|
172
|
+
* @returns {string[]}
|
|
173
|
+
*/
|
|
174
|
+
export function copyFontsCss(ctx: import("./_settings.mjs").Ctx, slug: string, data: import("./_settings.mjs").ThemeData): string[];
|
|
165
175
|
/**
|
|
166
176
|
* The app's copy of an editor theme: a standard local theme in
|
|
167
177
|
* src/themes/<theme>/ (a descriptor, a source that re-exports the built
|
|
@@ -178,6 +188,17 @@ export function screenshot(project: import("./_project.mjs").ThemeProject, html:
|
|
|
178
188
|
* @returns {string | null}
|
|
179
189
|
*/
|
|
180
190
|
export function writeAppCopy(ctx: import("./_settings.mjs").Ctx, slug: string, data: import("./_settings.mjs").ThemeData): string | null;
|
|
191
|
+
/**
|
|
192
|
+
* Why a theme's app copy is behind its build, or null when it is current:
|
|
193
|
+
* something in its way (appCopyStale), a copy file missing, or a file
|
|
194
|
+
* whose content is not what the editor would write now.
|
|
195
|
+
* @param {string} cwd
|
|
196
|
+
* @param {string} slug
|
|
197
|
+
* @param {string[] | null} [fontsCss] the font stylesheets the copy should
|
|
198
|
+
* import now (null: the copy's own)
|
|
199
|
+
* @returns {string | null}
|
|
200
|
+
*/
|
|
201
|
+
export function appCopyBehind(cwd: string, slug: string, fontsCss?: string[] | null): string | null;
|
|
181
202
|
/**
|
|
182
203
|
* {@link writeAppCopy} with the font stylesheets given, or null to keep the
|
|
183
204
|
* copy's own (a compile, which changes no setting).
|
|
@@ -188,13 +209,24 @@ export function writeAppCopy(ctx: import("./_settings.mjs").Ctx, slug: string, d
|
|
|
188
209
|
*/
|
|
189
210
|
export function writeAppCopyAt(cwd: string, slug: string, fontsCss: string[] | null): string | null;
|
|
190
211
|
/**
|
|
191
|
-
*
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
|
|
197
|
-
|
|
212
|
+
* The note for a copy a file of yours keeps from being written, as a
|
|
213
|
+
* result field: `{appCopyStale}` when one does, else nothing.
|
|
214
|
+
* @param {string} cwd
|
|
215
|
+
* @param {string} slug
|
|
216
|
+
* @returns {{appCopyStale?: string}}
|
|
217
|
+
*/
|
|
218
|
+
export function appCopyStale(cwd: string, slug: string): {
|
|
219
|
+
appCopyStale?: string;
|
|
220
|
+
};
|
|
221
|
+
/**
|
|
222
|
+
* Why the editor will not write a theme's app copy, or null when it will.
|
|
223
|
+
* Only a file of yours AT one of the copy's names stops it: a descriptor,
|
|
224
|
+
* source or font stylesheet without the editor's mark, or any copy file
|
|
225
|
+
* while the descriptor is not the editor's. Other files there (a note, a
|
|
226
|
+
* swap file, desktop.ini) are left as they are and the copy is written
|
|
227
|
+
* around them. Built bytes are not compared, so a stable rebuild of the
|
|
228
|
+
* copy leaves it the editor's. The one test the copy's writer, the change
|
|
229
|
+
* results and `wiring` use. Returns the file in the way.
|
|
198
230
|
* @param {string} cwd
|
|
199
231
|
* @param {string} slug
|
|
200
232
|
* @returns {string | null}
|
|
@@ -208,6 +240,30 @@ export function appCopyBlocker(cwd: string, slug: string): string | null;
|
|
|
208
240
|
* @returns {string[] | null}
|
|
209
241
|
*/
|
|
210
242
|
export function takeFirstAppCopy(cwd: string, slug: string): string[] | null;
|
|
243
|
+
/**
|
|
244
|
+
* Run a browser for a picture without blocking this process: a stop that
|
|
245
|
+
* reaches it (SIGINT, SIGTERM) stops the browser too, and is reported.
|
|
246
|
+
* Bounded to 60 seconds, as a picture run always was.
|
|
247
|
+
* @param {string} bin
|
|
248
|
+
* @param {string[]} args
|
|
249
|
+
* @param {number} [bound] milliseconds before the browser is stopped
|
|
250
|
+
* @returns {Promise<{status: number | null, signal: string | null, stderr: string, error?: Error, stoppedBy?: string, timedOut?: boolean}>}
|
|
251
|
+
*/
|
|
252
|
+
export function runBrowser(bin: string, args: string[], bound?: number): Promise<{
|
|
253
|
+
status: number | null;
|
|
254
|
+
signal: string | null;
|
|
255
|
+
stderr: string;
|
|
256
|
+
error?: Error;
|
|
257
|
+
stoppedBy?: string;
|
|
258
|
+
timedOut?: boolean;
|
|
259
|
+
}>;
|
|
260
|
+
/**
|
|
261
|
+
* The first stderr line that says something about the picture: Chrome's
|
|
262
|
+
* startup warnings (dbus, GPU, sandbox notices) come first on Linux and
|
|
263
|
+
* say nothing about why no picture was written.
|
|
264
|
+
* @param {string} text
|
|
265
|
+
*/
|
|
266
|
+
export function meaningfulLine(text: string): string;
|
|
211
267
|
/** The groups of the theme-building page, in order. */
|
|
212
268
|
export const SHOWCASE_GROUPS: string[];
|
|
213
269
|
export { APP_COPY_MARK } from "./_marks.mjs";
|