@astryxdesign/cli 0.7.13 → 0.7.14-canary.108f354
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 +18 -18
- package/api/component/__fixtures__/resolutions/modules.txt +1 -1
- package/api/doctor/doctor.mjs +3 -7
- package/api/experimental.d.mts +2 -0
- package/api/experimental.mjs +12 -0
- package/api/icon/_adapter.d.mts +10 -0
- package/api/icon/_adapter.mjs +31 -2
- package/api/icon/_authoring.d.mts +2 -1
- package/api/icon/_authoring.mjs +91 -6
- package/api/icon/_options.mjs +1 -0
- package/api/icon/_records.d.mts +18 -0
- package/api/icon/_records.mjs +26 -0
- package/api/icon/add/add.mjs +7 -1
- package/api/icon/definitions/definitions.d.mts +12 -0
- package/api/icon/definitions/definitions.mjs +83 -0
- package/api/icon/icon.doc.mjs +5 -4
- package/api/icon/icon.mjs +5 -16
- package/api/icon/icon.type.d.mts +29 -2
- package/api/icon/icon.type.mjs +17 -3
- package/api/icon/iconAdd.doc.mjs +1 -1
- package/api/icon/iconMap.doc.mjs +2 -2
- package/api/icon/iconNewSet.doc.mjs +8 -2
- package/api/icon/map/map.mjs +21 -2
- package/api/icon/new-set/new-set.mjs +14 -2
- package/api/icon/search/search.mjs +2 -15
- package/api/icon/use/use.mjs +4 -3
- package/api/integration/validate-integration.mjs +6 -1
- package/api/integration/validate-integration.type.d.mts +12 -0
- package/api/integration/validate-integration.type.mjs +5 -0
- package/api/theme-edit/_adapter.d.mts +116 -0
- package/api/theme-edit/_adapter.mjs +1683 -0
- package/api/theme-edit/_catalog.d.mts +59 -0
- package/api/theme-edit/_catalog.mjs +564 -0
- package/api/theme-edit/_check.d.mts +49 -0
- package/api/theme-edit/_check.mjs +845 -0
- package/api/theme-edit/_color.d.mts +29 -0
- package/api/theme-edit/_color.mjs +300 -0
- package/api/theme-edit/_compiler.d.mts +61 -0
- package/api/theme-edit/_compiler.mjs +522 -0
- package/api/theme-edit/_css-properties.d.mts +10 -0
- package/api/theme-edit/_css-properties.mjs +556 -0
- package/api/theme-edit/_parts.d.mts +111 -0
- package/api/theme-edit/_parts.mjs +409 -0
- package/api/theme-edit/_png.d.mts +40 -0
- package/api/theme-edit/_png.mjs +187 -0
- package/api/theme-edit/_preview.d.mts +121 -0
- package/api/theme-edit/_preview.mjs +720 -0
- package/api/theme-edit/_project.d.mts +83 -0
- package/api/theme-edit/_project.mjs +289 -0
- package/api/theme-edit/_settings.d.mts +222 -0
- package/api/theme-edit/_settings.mjs +861 -0
- package/api/theme-edit/_tables.d.mts +132 -0
- package/api/theme-edit/_tables.mjs +700 -0
- package/api/theme-edit/theme-edit.d.mts +93 -0
- package/api/theme-edit/theme-edit.mjs +145 -0
- package/api/theme-edit/theme-edit.type.d.mts +413 -0
- package/api/theme-edit/theme-edit.type.mjs +233 -0
- package/api/theme-edit/themeEditHow.doc.d.mts +6 -0
- package/api/theme-edit/themeEditHow.doc.mjs +88 -0
- package/api/theme-edit/themeEditNew.doc.d.mts +6 -0
- package/api/theme-edit/themeEditNew.doc.mjs +89 -0
- package/api/theme-edit/themeEditPreviewAdd.doc.d.mts +6 -0
- package/api/theme-edit/themeEditPreviewAdd.doc.mjs +100 -0
- package/api/theme-edit/themeEditPreviewApp.doc.d.mts +6 -0
- package/api/theme-edit/themeEditPreviewApp.doc.mjs +84 -0
- package/api/theme-edit/themeEditPreviewList.doc.d.mts +6 -0
- package/api/theme-edit/themeEditPreviewList.doc.mjs +53 -0
- package/api/theme-edit/themeEditPreviewRemove.doc.d.mts +6 -0
- package/api/theme-edit/themeEditPreviewRemove.doc.mjs +66 -0
- package/api/theme-edit/themeEditSet.doc.d.mts +6 -0
- package/api/theme-edit/themeEditSet.doc.mjs +165 -0
- package/api/theme-edit/themeEditShow.doc.d.mts +6 -0
- package/api/theme-edit/themeEditShow.doc.mjs +86 -0
- package/api/theme-edit/themeEditUndo.doc.d.mts +6 -0
- package/api/theme-edit/themeEditUndo.doc.mjs +124 -0
- package/assets/docs/color.doc.mjs +5 -5
- package/assets/docs/tree/icon-sets.doc.mjs +6 -2
- package/assets/docs/tree/tokens-border.doc.mjs +1 -1
- package/assets/docs/tree/tokens-color.doc.mjs +2 -2
- package/assets/docs/tree/tokens-data.doc.mjs +2 -2
- package/assets/docs/tree/tokens-duration.doc.mjs +1 -1
- package/assets/docs/tree/tokens-ease.doc.mjs +1 -1
- package/assets/docs/tree/tokens-focus.doc.mjs +1 -1
- package/assets/docs/tree/tokens-font-weight.doc.mjs +1 -1
- package/assets/docs/tree/tokens-radius.doc.mjs +1 -1
- package/assets/docs/tree/tokens-shadow.doc.mjs +1 -1
- package/assets/docs/tree/tokens-size.doc.mjs +1 -1
- package/assets/docs/tree/tokens-spacing.doc.mjs +1 -1
- package/assets/docs/tree/tokens-syntax.doc.mjs +1 -1
- package/assets/docs/tree/tokens-text-size.doc.mjs +1 -1
- package/assets/docs/tree/tokens-type-scale.doc.mjs +1 -1
- package/assets/docs/tree/tokens-typography.doc.mjs +1 -1
- package/assets/icons/definitions/bank.doc.mjs +1 -1
- package/assets/icons/definitions/save.doc.mjs +1 -1
- package/assets/preview-app/README.md +6 -0
- package/assets/preview-app/css.d.ts +5 -0
- package/assets/preview-app/gitignore +1 -0
- package/assets/preview-app/next.config.mjs +6 -0
- package/assets/preview-app/package.json +23 -0
- package/assets/preview-app/src/app/globals.css +5 -0
- package/assets/preview-app/src/app/layout.tsx +21 -0
- package/assets/preview-app/src/app/page.tsx +94 -0
- package/assets/preview-app/src/app/providers.tsx +16 -0
- package/assets/preview-app/tsconfig.json +27 -0
- package/assets/templates/blocks/components/InternationalizationProvider/InternationalizationProvider01ShippedLocale.doc.mjs +2 -1
- package/assets/templates/blocks/components/InternationalizationProvider/InternationalizationProvider02Overrides.doc.mjs +2 -1
- package/assets/templates/blocks/components/InternationalizationProvider/InternationalizationProvider03RtlDirection.doc.mjs +2 -1
- package/assets/templates/blocks/components/InternationalizationProvider/InternationalizationProvider04Calendar.doc.mjs +2 -1
- package/assets/templates/blocks/components/Text/useTruncationHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Text/useTruncationHookUsage.tsx +112 -0
- package/authoring/doctypes/_schema.d.mts +1 -0
- package/authoring/doctypes/_schema.mjs +1 -0
- package/authoring/doctypes/command/command.doc.mjs +7 -0
- package/authoring/doctypes/command/type.ts +3 -0
- package/authoring/doctypes/icon-set/parse.d.mts +7 -0
- package/authoring/doctypes/icon-set/parse.mjs +18 -8
- package/clients/cli/commands/doctor.mjs +33 -3
- package/clients/cli/commands/experimental/icon.mjs +67 -14
- package/clients/cli/commands/experimental/index.mjs +2 -0
- package/clients/cli/commands/experimental/theme.mjs +684 -0
- package/clients/cli/commands/experimental-icon-new-set.doc.mjs +7 -1
- package/clients/cli/commands/experimental-icon.doc.mjs +3 -2
- package/clients/cli/commands/experimental-theme-add.doc.mjs +78 -0
- package/clients/cli/commands/experimental-theme-compile.doc.mjs +97 -0
- package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +84 -0
- package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +66 -0
- package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +121 -0
- package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +66 -0
- package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +104 -0
- package/clients/cli/commands/experimental-theme-editor.doc.mjs +49 -0
- package/clients/cli/commands/experimental-theme-eject.doc.mjs +71 -0
- package/clients/cli/commands/experimental-theme-list.doc.mjs +49 -0
- package/clients/cli/commands/experimental-theme-palette-generate.doc.mjs +73 -0
- package/clients/cli/commands/experimental-theme-palette.doc.mjs +37 -0
- package/clients/cli/commands/experimental-theme-preview-add.doc.mjs +86 -0
- package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +66 -0
- package/clients/cli/commands/experimental-theme-preview-list.doc.mjs +48 -0
- package/clients/cli/commands/experimental-theme-preview-remove.doc.mjs +59 -0
- package/clients/cli/commands/experimental-theme-preview.doc.mjs +40 -0
- package/clients/cli/commands/experimental-theme-remove.doc.mjs +55 -0
- package/clients/cli/commands/experimental-theme-targets.doc.mjs +61 -0
- package/clients/cli/commands/experimental-theme-template.doc.mjs +61 -0
- package/clients/cli/commands/experimental-theme-use.doc.mjs +55 -0
- package/clients/cli/commands/experimental-theme.doc.mjs +57 -0
- package/clients/cli/commands/experimental.doc.mjs +10 -3
- package/clients/cli/commands/theme.mjs +101 -34
- package/clients/cli/index.mjs +18 -0
- package/clients/cli/lib/define-command.mjs +3 -0
- package/foundation/discovery/icon-set-checks.d.mts +16 -1
- package/foundation/discovery/icon-set-checks.mjs +68 -7
- package/foundation/discovery/icon-set-discovery.d.mts +21 -6
- package/foundation/discovery/icon-set-discovery.mjs +17 -8
- package/foundation/discovery/template-icon-meanings.d.mts +39 -0
- package/foundation/discovery/template-icon-meanings.mjs +95 -0
- package/foundation/discovery/theming-targets.d.mts +6 -0
- package/foundation/discovery/theming-targets.mjs +33 -0
- package/foundation/response/error-codes.d.mts +12 -1
- package/foundation/response/error-codes.doc.mjs +66 -0
- package/foundation/response/error-codes.mjs +55 -0
- package/foundation/response/response-types.doc.mjs +55 -0
- package/foundation/text/template-meanings-line.d.mts +16 -0
- package/foundation/text/template-meanings-line.mjs +37 -0
- package/foundation/xle/browser.d.mts +2 -2
- package/package.json +6 -6
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
|
|
2
|
+
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The install line for packages, in the project's package manager.
|
|
6
|
+
* @param {string} cwd
|
|
7
|
+
* @param {string[]} packages
|
|
8
|
+
*/
|
|
9
|
+
export function installLine(cwd: string, packages: string[]): string;
|
|
10
|
+
/**
|
|
11
|
+
* The project in `cwd`. Refuses when Core is not installed there, since the
|
|
12
|
+
* generated theme imports it.
|
|
13
|
+
* @param {string} cwd
|
|
14
|
+
* @returns {Promise<ThemeProject>}
|
|
15
|
+
*/
|
|
16
|
+
export function openProject(cwd: string): Promise<ThemeProject>;
|
|
17
|
+
/**
|
|
18
|
+
* The module a component (or a sub-component) is imported from, or null
|
|
19
|
+
* when Core has no module for it.
|
|
20
|
+
* @param {ThemeProject} project
|
|
21
|
+
* @param {string} name
|
|
22
|
+
* @returns {string | null}
|
|
23
|
+
*/
|
|
24
|
+
export function importPathOf(project: ThemeProject, name: string): string | null;
|
|
25
|
+
/**
|
|
26
|
+
* The built-in theme package for a base, or a refusal naming its install line.
|
|
27
|
+
* @param {ThemeProject} project
|
|
28
|
+
* @param {string} like
|
|
29
|
+
* @returns {string} the resolved built module
|
|
30
|
+
*/
|
|
31
|
+
export function baseThemeFile(project: ThemeProject, like: string): string;
|
|
32
|
+
/**
|
|
33
|
+
* Resolved tokens of the base theme in both modes.
|
|
34
|
+
* @param {ThemeProject} project
|
|
35
|
+
* @param {string | undefined} like
|
|
36
|
+
* @returns {Promise<{light: Record<string, string>, dark: Record<string, string>}>}
|
|
37
|
+
*/
|
|
38
|
+
export function baseResolved(project: ThemeProject, like: string | undefined): Promise<{
|
|
39
|
+
light: Record<string, string>;
|
|
40
|
+
dark: Record<string, string>;
|
|
41
|
+
}>;
|
|
42
|
+
export type ThemeProject = {
|
|
43
|
+
cwd: string;
|
|
44
|
+
/**
|
|
45
|
+
* - The folder of the installed Core package.
|
|
46
|
+
*/
|
|
47
|
+
coreDir: string;
|
|
48
|
+
coreVersion: string;
|
|
49
|
+
/**
|
|
50
|
+
* - The Core version plus a fingerprint of its stylesheet.
|
|
51
|
+
*/
|
|
52
|
+
coreKey: string;
|
|
53
|
+
/**
|
|
54
|
+
* - node_modules/.cache/astryx-theme/<coreKey>
|
|
55
|
+
*/
|
|
56
|
+
cacheDir: string;
|
|
57
|
+
/**
|
|
58
|
+
* - Core's theme module.
|
|
59
|
+
*/
|
|
60
|
+
core: any;
|
|
61
|
+
/**
|
|
62
|
+
* - Resolves packages from the project.
|
|
63
|
+
*/
|
|
64
|
+
req: NodeJS.Require;
|
|
65
|
+
targets: import("../../foundation/discovery/theming-targets.mjs").ThemingTarget[];
|
|
66
|
+
target: Map<string, import("../../foundation/discovery/theming-targets.mjs").ThemingTarget>;
|
|
67
|
+
components: Record<string, ComponentInfo>;
|
|
68
|
+
};
|
|
69
|
+
export type ComponentInfo = {
|
|
70
|
+
importPath: string;
|
|
71
|
+
/**
|
|
72
|
+
* - The doc's category, such as Action or Overlay.
|
|
73
|
+
*/
|
|
74
|
+
category: string;
|
|
75
|
+
/**
|
|
76
|
+
* - Playground defaults, or null.
|
|
77
|
+
*/
|
|
78
|
+
defaults: unknown;
|
|
79
|
+
targets: Array<{
|
|
80
|
+
className: string;
|
|
81
|
+
values: Record<string, string[]>;
|
|
82
|
+
}>;
|
|
83
|
+
};
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file The project `astryx experimental theme` works in: its installed
|
|
5
|
+
* Core (the theme module, its token defaults and groups, its theming
|
|
6
|
+
* targets and component docs), the cache folder, and the built-in themes it
|
|
7
|
+
* can build on. Everything is read from the installed packages, so the
|
|
8
|
+
* checks always match the Core the app runs.
|
|
9
|
+
*
|
|
10
|
+
* @position api/theme-edit — the subject's access to installed packages
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import * as fs from 'node:fs';
|
|
14
|
+
import * as path from 'node:path';
|
|
15
|
+
import {createHash} from 'node:crypto';
|
|
16
|
+
import {createRequire} from 'node:module';
|
|
17
|
+
import {pathToFileURL} from 'node:url';
|
|
18
|
+
import {AstryxError} from '../error.mjs';
|
|
19
|
+
import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
|
|
20
|
+
import {loadComponentDoc} from '../../foundation/discovery/component-loader.mjs';
|
|
21
|
+
import {collectThemingTargets} from '../../foundation/discovery/theming-targets.mjs';
|
|
22
|
+
import {resolveImportPath} from '../../foundation/discovery/component-discovery.mjs';
|
|
23
|
+
import {detectPackageManager} from '../../foundation/env/package-manager.mjs';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @typedef {object} ThemeProject
|
|
27
|
+
* @property {string} cwd
|
|
28
|
+
* @property {string} coreDir - The folder of the installed Core package.
|
|
29
|
+
* @property {string} coreVersion
|
|
30
|
+
* @property {string} coreKey - The Core version plus a fingerprint of its stylesheet.
|
|
31
|
+
* @property {string} cacheDir - node_modules/.cache/astryx-theme/<coreKey>
|
|
32
|
+
* @property {any} core - Core's theme module.
|
|
33
|
+
* @property {NodeJS.Require} req - Resolves packages from the project.
|
|
34
|
+
* @property {import('../../foundation/discovery/theming-targets.mjs').ThemingTarget[]} targets
|
|
35
|
+
* @property {Map<string, import('../../foundation/discovery/theming-targets.mjs').ThemingTarget>} target
|
|
36
|
+
* @property {Record<string, ComponentInfo>} components
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @typedef {object} ComponentInfo
|
|
41
|
+
* @property {string} importPath
|
|
42
|
+
* @property {string} category - The doc's category, such as Action or Overlay.
|
|
43
|
+
* @property {unknown} defaults - Playground defaults, or null.
|
|
44
|
+
* @property {Array<{className: string, values: Record<string, string[]>}>} targets
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
/** @type {Map<string, ThemeProject>} */
|
|
48
|
+
const projects = new Map();
|
|
49
|
+
|
|
50
|
+
/** Bump when the shape of the cached component docs changes. */
|
|
51
|
+
const DOCS_VERSION = 1;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* The nearest folder at or above `dir` that holds node_modules.
|
|
55
|
+
* @param {string} dir
|
|
56
|
+
* @returns {string | null}
|
|
57
|
+
*/
|
|
58
|
+
function nodeModulesRoot(dir) {
|
|
59
|
+
for (let d = path.resolve(dir); ; d = path.dirname(d)) {
|
|
60
|
+
if (fs.existsSync(path.join(d, 'node_modules'))) return d;
|
|
61
|
+
if (path.dirname(d) === d) return null;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* The install line for packages, in the project's package manager.
|
|
67
|
+
* @param {string} cwd
|
|
68
|
+
* @param {string[]} packages
|
|
69
|
+
*/
|
|
70
|
+
export function installLine(cwd, packages) {
|
|
71
|
+
const pm = detectPackageManager(cwd);
|
|
72
|
+
return `${pm === 'npm' || pm === 'npx' ? 'npm install' : `${pm} add`} ${packages.join(' ')}`;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** @param {string} type @returns {string[]} */
|
|
76
|
+
const literals = type =>
|
|
77
|
+
[...String(type ?? '').matchAll(/'([^']+)'/g)].map(m => m[1]);
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Every component doc under Core's src folder: playground defaults and the
|
|
81
|
+
* variant values of each theming target.
|
|
82
|
+
* @param {string} coreDir
|
|
83
|
+
* @returns {Promise<Record<string, ComponentInfo>>}
|
|
84
|
+
*/
|
|
85
|
+
async function readComponents(coreDir) {
|
|
86
|
+
/** @type {Record<string, ComponentInfo>} */
|
|
87
|
+
const out = {};
|
|
88
|
+
/** @param {string} dir */
|
|
89
|
+
const scan = async dir => {
|
|
90
|
+
for (const entry of fs.readdirSync(dir, {withFileTypes: true})) {
|
|
91
|
+
const full = path.join(dir, entry.name);
|
|
92
|
+
if (entry.isDirectory()) {
|
|
93
|
+
if (entry.name !== 'node_modules' && entry.name !== '__tests__')
|
|
94
|
+
await scan(full);
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
if (!entry.name.endsWith('.doc.mjs')) continue;
|
|
98
|
+
/** @type {any} */
|
|
99
|
+
let doc;
|
|
100
|
+
try {
|
|
101
|
+
doc = await loadComponentDoc(full);
|
|
102
|
+
} catch {
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
if (!doc || typeof doc.name !== 'string') continue;
|
|
106
|
+
/** @type {Record<string, any>} */
|
|
107
|
+
const props = Object.fromEntries(
|
|
108
|
+
(Array.isArray(doc.props) ? doc.props : []).map(
|
|
109
|
+
(/** @type {any} */ p) => [p.name, p],
|
|
110
|
+
),
|
|
111
|
+
);
|
|
112
|
+
out[doc.name] = {
|
|
113
|
+
importPath: resolveImportPath(coreDir, doc.name),
|
|
114
|
+
category: typeof doc.category === 'string' ? doc.category : '',
|
|
115
|
+
defaults: doc.playground?.defaults ?? null,
|
|
116
|
+
targets: (doc.theming?.targets ?? []).map((/** @type {any} */ t) => ({
|
|
117
|
+
className: t.className,
|
|
118
|
+
values: Object.fromEntries(
|
|
119
|
+
(t.visualProps ?? []).map((/** @type {string} */ v) => {
|
|
120
|
+
const p = props[v];
|
|
121
|
+
const vals = p
|
|
122
|
+
? literals(p.type).length
|
|
123
|
+
? literals(p.type)
|
|
124
|
+
: p.type === 'boolean'
|
|
125
|
+
? ['true', 'false']
|
|
126
|
+
: []
|
|
127
|
+
: [];
|
|
128
|
+
return [v, vals];
|
|
129
|
+
}),
|
|
130
|
+
),
|
|
131
|
+
})),
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
const src = path.join(coreDir, 'src');
|
|
136
|
+
if (fs.existsSync(src)) await scan(src);
|
|
137
|
+
return out;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* The project in `cwd`. Refuses when Core is not installed there, since the
|
|
142
|
+
* generated theme imports it.
|
|
143
|
+
* @param {string} cwd
|
|
144
|
+
* @returns {Promise<ThemeProject>}
|
|
145
|
+
*/
|
|
146
|
+
export async function openProject(cwd) {
|
|
147
|
+
const key = path.resolve(cwd);
|
|
148
|
+
const known = projects.get(key);
|
|
149
|
+
if (known) return known;
|
|
150
|
+
const req = createRequire(path.join(key, 'noop.js'));
|
|
151
|
+
/** @type {string} */
|
|
152
|
+
let themeFile;
|
|
153
|
+
try {
|
|
154
|
+
themeFile = req.resolve('@astryxdesign/core/theme');
|
|
155
|
+
} catch {
|
|
156
|
+
throw new AstryxError(
|
|
157
|
+
'@astryxdesign/core is not installed here. astryx experimental theme writes a theme that imports it, and checks every change against it, so run it in an app that has Core installed.',
|
|
158
|
+
[
|
|
159
|
+
{
|
|
160
|
+
name: installLine(key, ['@astryxdesign/core']),
|
|
161
|
+
reason: 'install Core',
|
|
162
|
+
},
|
|
163
|
+
],
|
|
164
|
+
ERROR_CODES.ERR_PROJECT_REQUIRED,
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
let coreDir = path.dirname(themeFile);
|
|
168
|
+
while (
|
|
169
|
+
!fs.existsSync(path.join(coreDir, 'package.json')) &&
|
|
170
|
+
path.dirname(coreDir) !== coreDir
|
|
171
|
+
)
|
|
172
|
+
coreDir = path.dirname(coreDir);
|
|
173
|
+
const coreVersion =
|
|
174
|
+
JSON.parse(fs.readFileSync(path.join(coreDir, 'package.json'), 'utf8'))
|
|
175
|
+
.version ?? '0.0.0';
|
|
176
|
+
let fingerprint = 'nocss';
|
|
177
|
+
try {
|
|
178
|
+
fingerprint = createHash('sha256')
|
|
179
|
+
.update(fs.readFileSync(req.resolve('@astryxdesign/core/astryx.css')))
|
|
180
|
+
.digest('hex')
|
|
181
|
+
.slice(0, 12);
|
|
182
|
+
} catch {
|
|
183
|
+
// No stylesheet: the part data is empty, and the version alone keys it.
|
|
184
|
+
}
|
|
185
|
+
const coreKey = `${coreVersion}-${fingerprint}`;
|
|
186
|
+
const root = nodeModulesRoot(key) ?? key;
|
|
187
|
+
const core = await import(pathToFileURL(themeFile).href);
|
|
188
|
+
const cacheDir = path.join(
|
|
189
|
+
root,
|
|
190
|
+
'node_modules',
|
|
191
|
+
'.cache',
|
|
192
|
+
'astryx-theme',
|
|
193
|
+
coreKey,
|
|
194
|
+
);
|
|
195
|
+
// Reading every component doc takes a second; it is fixed per Core install.
|
|
196
|
+
const docsFile = path.join(cacheDir, 'docs.json');
|
|
197
|
+
/** @type {{version: number, targets: ThemeProject['targets'], components: ThemeProject['components']} | null} */
|
|
198
|
+
let docs = null;
|
|
199
|
+
try {
|
|
200
|
+
const cached = JSON.parse(fs.readFileSync(docsFile, 'utf8'));
|
|
201
|
+
if (cached.version === DOCS_VERSION) docs = cached;
|
|
202
|
+
} catch {
|
|
203
|
+
// Not cached yet.
|
|
204
|
+
}
|
|
205
|
+
if (!docs) {
|
|
206
|
+
docs = {
|
|
207
|
+
version: DOCS_VERSION,
|
|
208
|
+
targets: await collectThemingTargets(path.join(coreDir, 'src')),
|
|
209
|
+
components: await readComponents(coreDir),
|
|
210
|
+
};
|
|
211
|
+
try {
|
|
212
|
+
fs.mkdirSync(cacheDir, {recursive: true});
|
|
213
|
+
fs.writeFileSync(docsFile, JSON.stringify(docs));
|
|
214
|
+
} catch {
|
|
215
|
+
// A read-only node_modules: read the docs again next time.
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
const {targets, components} = docs;
|
|
219
|
+
const project = {
|
|
220
|
+
cwd: key,
|
|
221
|
+
coreDir,
|
|
222
|
+
coreVersion,
|
|
223
|
+
coreKey,
|
|
224
|
+
cacheDir,
|
|
225
|
+
core,
|
|
226
|
+
req,
|
|
227
|
+
targets,
|
|
228
|
+
target: new Map(targets.map(t => [t.key, t])),
|
|
229
|
+
components,
|
|
230
|
+
};
|
|
231
|
+
projects.set(key, project);
|
|
232
|
+
return project;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* The module a component (or a sub-component) is imported from, or null
|
|
237
|
+
* when Core has no module for it.
|
|
238
|
+
* @param {ThemeProject} project
|
|
239
|
+
* @param {string} name
|
|
240
|
+
* @returns {string | null}
|
|
241
|
+
*/
|
|
242
|
+
export function importPathOf(project, name) {
|
|
243
|
+
const spec =
|
|
244
|
+
project.components[name]?.importPath ??
|
|
245
|
+
resolveImportPath(project.coreDir, name);
|
|
246
|
+
return spec && spec !== '@astryxdesign/core' ? spec : null;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* The built-in theme package for a base, or a refusal naming its install line.
|
|
251
|
+
* @param {ThemeProject} project
|
|
252
|
+
* @param {string} like
|
|
253
|
+
* @returns {string} the resolved built module
|
|
254
|
+
*/
|
|
255
|
+
export function baseThemeFile(project, like) {
|
|
256
|
+
const pkg = `@astryxdesign/theme-${like}`;
|
|
257
|
+
try {
|
|
258
|
+
return project.req.resolve(`${pkg}/built`);
|
|
259
|
+
} catch {
|
|
260
|
+
throw new AstryxError(
|
|
261
|
+
`The ${like} theme is not installed, so a theme cannot build on it. Install ${pkg}, or build on no theme. Nothing was changed.`,
|
|
262
|
+
[{name: installLine(project.cwd, [pkg]), reason: 'install it'}],
|
|
263
|
+
ERROR_CODES.ERR_UNKNOWN_THEME,
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Resolved tokens of the base theme in both modes.
|
|
270
|
+
* @param {ThemeProject} project
|
|
271
|
+
* @param {string | undefined} like
|
|
272
|
+
* @returns {Promise<{light: Record<string, string>, dark: Record<string, string>}>}
|
|
273
|
+
*/
|
|
274
|
+
export async function baseResolved(project, like) {
|
|
275
|
+
const {core} = project;
|
|
276
|
+
let theme = core.defineTheme({name: 'astryx-defaults'});
|
|
277
|
+
if (like) {
|
|
278
|
+
const m = await import(pathToFileURL(baseThemeFile(project, like)).href);
|
|
279
|
+
theme =
|
|
280
|
+
m[`${like}Theme`] ??
|
|
281
|
+
Object.values(m).find(
|
|
282
|
+
v => v && typeof v === 'object' && typeof v.name === 'string',
|
|
283
|
+
);
|
|
284
|
+
}
|
|
285
|
+
return {
|
|
286
|
+
light: core.resolveThemeTokens(theme, {mode: 'light'}),
|
|
287
|
+
dark: core.resolveThemeTokens(theme, {mode: 'dark'}),
|
|
288
|
+
};
|
|
289
|
+
}
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
// @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
|
|
2
|
+
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The files of one theme, absolute.
|
|
6
|
+
* @param {string} cwd
|
|
7
|
+
* @param {string} slug
|
|
8
|
+
*/
|
|
9
|
+
export function themeFiles(cwd: string, slug: string): {
|
|
10
|
+
root: string;
|
|
11
|
+
dir: string;
|
|
12
|
+
settings: string;
|
|
13
|
+
ts: string;
|
|
14
|
+
settingsTs: string;
|
|
15
|
+
js: string;
|
|
16
|
+
css: string;
|
|
17
|
+
history: string;
|
|
18
|
+
preview: string;
|
|
19
|
+
sheet: string;
|
|
20
|
+
previewPng: string;
|
|
21
|
+
sheetPng: string;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Up to `n` names close to `x`.
|
|
25
|
+
* @param {string} x
|
|
26
|
+
* @param {Iterable<string>} list
|
|
27
|
+
* @param {number} [n]
|
|
28
|
+
*/
|
|
29
|
+
export function nearest(x: string, list: Iterable<string>, n?: number): string[];
|
|
30
|
+
/**
|
|
31
|
+
* A refusal: nothing was changed, and the suggestions lead with the command
|
|
32
|
+
* that does what the person wanted.
|
|
33
|
+
* @param {string} code
|
|
34
|
+
* @param {string} message
|
|
35
|
+
* @param {{run?: string[], didYouMean?: string[], fix?: string, also?: string[]}} [extra]
|
|
36
|
+
* @returns {never}
|
|
37
|
+
*/
|
|
38
|
+
export function refuse(code: string, message: string, extra?: {
|
|
39
|
+
run?: string[];
|
|
40
|
+
didYouMean?: string[];
|
|
41
|
+
fix?: string;
|
|
42
|
+
also?: string[];
|
|
43
|
+
}): never;
|
|
44
|
+
/**
|
|
45
|
+
* The settings of a theme, or a refusal naming the command that makes it.
|
|
46
|
+
* @param {string} cwd
|
|
47
|
+
* @param {string} slug
|
|
48
|
+
* @returns {ThemeData}
|
|
49
|
+
*/
|
|
50
|
+
export function loadTheme(cwd: string, slug: string): ThemeData;
|
|
51
|
+
/** One line for a setting. @param {Setting} s */
|
|
52
|
+
export function describe(s: Setting): string;
|
|
53
|
+
/**
|
|
54
|
+
* The parts a setting styles: the family when `--on` names one, the whole
|
|
55
|
+
* family of an always-alike member unless `--only`, else the one part.
|
|
56
|
+
* @param {Ctx} ctx
|
|
57
|
+
* @param {Pick<Setting, 'on' | 'only' | 'thing'>} s
|
|
58
|
+
* @returns {string[]}
|
|
59
|
+
*/
|
|
60
|
+
export function partsOf(ctx: Ctx, s: Pick<Setting, "on" | "only" | "thing">): string[];
|
|
61
|
+
/**
|
|
62
|
+
* The family and fallbacks a font value means: a preset, an open font, a
|
|
63
|
+
* whole stack with commas, or one family name.
|
|
64
|
+
* @param {string} value
|
|
65
|
+
* @returns {{family: string, fallbacks: string, pkg: string | null}}
|
|
66
|
+
*/
|
|
67
|
+
export function fontOf(value: string): {
|
|
68
|
+
family: string;
|
|
69
|
+
fallbacks: string;
|
|
70
|
+
pkg: string | null;
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* The settings, as a `defineTheme` object.
|
|
74
|
+
* @param {Ctx} ctx
|
|
75
|
+
* @param {ThemeData} data
|
|
76
|
+
* @param {{light: Record<string, string>, dark: Record<string, string>}} base
|
|
77
|
+
* @returns {any}
|
|
78
|
+
*/
|
|
79
|
+
export function compileTheme(ctx: Ctx, data: ThemeData, base: {
|
|
80
|
+
light: Record<string, string>;
|
|
81
|
+
dark: Record<string, string>;
|
|
82
|
+
}): any;
|
|
83
|
+
/**
|
|
84
|
+
* A plain part setting can lose to a more specific rule for the same part
|
|
85
|
+
* and property, such as a base theme's `.astryx-heading[data-level="1"]
|
|
86
|
+
* {font-weight}`. Find those rules in the built stylesheet.
|
|
87
|
+
* @param {string} cssText
|
|
88
|
+
* @param {any} theme
|
|
89
|
+
* @returns {Array<{target: string, key: string, prop: string, value: string}>}
|
|
90
|
+
*/
|
|
91
|
+
export function findOverrides(cssText: string, theme: any): Array<{
|
|
92
|
+
target: string;
|
|
93
|
+
key: string;
|
|
94
|
+
prop: string;
|
|
95
|
+
value: string;
|
|
96
|
+
}>;
|
|
97
|
+
/**
|
|
98
|
+
* Generate the theme source, build it with the theme build, then repeat any
|
|
99
|
+
* part setting a more specific rule would beat and build again.
|
|
100
|
+
* @param {Ctx} ctx
|
|
101
|
+
* @param {string} slug
|
|
102
|
+
* @param {ThemeData} data
|
|
103
|
+
* @returns {Promise<{warnings: string[], lifted: string[]}>}
|
|
104
|
+
*/
|
|
105
|
+
export function buildTheme(ctx: Ctx, slug: string, data: ThemeData): Promise<{
|
|
106
|
+
warnings: string[];
|
|
107
|
+
lifted: string[];
|
|
108
|
+
}>;
|
|
109
|
+
/**
|
|
110
|
+
* Resolved tokens of the built theme in both modes.
|
|
111
|
+
* @param {Ctx} ctx
|
|
112
|
+
* @param {string} slug
|
|
113
|
+
* @returns {Promise<{light: Record<string, string>, dark: Record<string, string>}>}
|
|
114
|
+
*/
|
|
115
|
+
export function resolvedTokens(ctx: Ctx, slug: string): Promise<{
|
|
116
|
+
light: Record<string, string>;
|
|
117
|
+
dark: Record<string, string>;
|
|
118
|
+
}>;
|
|
119
|
+
/**
|
|
120
|
+
* Contrast problems this theme caused: text below 4.5:1 that was not as low
|
|
121
|
+
* in the base theme. A part's own color or background setting, or a token
|
|
122
|
+
* set on that part, counts for that part.
|
|
123
|
+
* @param {Ctx} ctx
|
|
124
|
+
* @param {ThemeData} data
|
|
125
|
+
* @param {{light: Record<string, string>, dark: Record<string, string>}} res
|
|
126
|
+
* @returns {Promise<string[]>}
|
|
127
|
+
*/
|
|
128
|
+
export function contrastProblems(ctx: Ctx, data: ThemeData, res: {
|
|
129
|
+
light: Record<string, string>;
|
|
130
|
+
dark: Record<string, string>;
|
|
131
|
+
}): Promise<string[]>;
|
|
132
|
+
/**
|
|
133
|
+
* Write the settings, build, and on a failed build put back what was there.
|
|
134
|
+
* Returns what changed in the resolved tokens and the lifted keys that are
|
|
135
|
+
* new since the last build.
|
|
136
|
+
* @param {Ctx} ctx
|
|
137
|
+
* @param {string} slug
|
|
138
|
+
* @param {ThemeData} data
|
|
139
|
+
* @param {{history: boolean}} options
|
|
140
|
+
*/
|
|
141
|
+
export function commitTheme(ctx: Ctx, slug: string, data: ThemeData, { history }: {
|
|
142
|
+
history: boolean;
|
|
143
|
+
}): Promise<{
|
|
144
|
+
changed: string[];
|
|
145
|
+
res: {
|
|
146
|
+
light: Record<string, string>;
|
|
147
|
+
dark: Record<string, string>;
|
|
148
|
+
};
|
|
149
|
+
problems: string[];
|
|
150
|
+
warnings: string[];
|
|
151
|
+
lifted: string[];
|
|
152
|
+
}>;
|
|
153
|
+
/** @param {Ctx} ctx @param {ThemeData} data */
|
|
154
|
+
export function fontPackages(ctx: Ctx, data: ThemeData): {
|
|
155
|
+
pkg: string;
|
|
156
|
+
installed: boolean;
|
|
157
|
+
}[];
|
|
158
|
+
export function slugOk(s: string): boolean;
|
|
159
|
+
export function kebab(s: string): string;
|
|
160
|
+
export function camel(s: string): string;
|
|
161
|
+
export function q(v: unknown): string;
|
|
162
|
+
export function shown(cwd: string, f: string): string;
|
|
163
|
+
export function keyOf(s: Setting): string;
|
|
164
|
+
export function modesOf(d: ThemeData): Array<"light" | "dark">;
|
|
165
|
+
export function cornerPx(v: string): number;
|
|
166
|
+
export function textPx(v: string): number;
|
|
167
|
+
/**
|
|
168
|
+
* One setting the CLI owns.
|
|
169
|
+
*/
|
|
170
|
+
export type Setting = {
|
|
171
|
+
/**
|
|
172
|
+
* - A dial, a token (`--color-accent`), or a CSS property.
|
|
173
|
+
*/
|
|
174
|
+
thing: string;
|
|
175
|
+
value: string;
|
|
176
|
+
source: "dial" | "token" | "property";
|
|
177
|
+
/**
|
|
178
|
+
* - A part, a family, or a typography role (font).
|
|
179
|
+
*/
|
|
180
|
+
on?: string | undefined;
|
|
181
|
+
/**
|
|
182
|
+
* - `<prop>:<value>`.
|
|
183
|
+
*/
|
|
184
|
+
when?: string | undefined;
|
|
185
|
+
state?: string | undefined;
|
|
186
|
+
mode?: "light" | "dark" | undefined;
|
|
187
|
+
only?: boolean | undefined;
|
|
188
|
+
/**
|
|
189
|
+
* - For the `headings` dial: `weight` or `tracking`.
|
|
190
|
+
*/
|
|
191
|
+
axis?: string | undefined;
|
|
192
|
+
note?: string | undefined;
|
|
193
|
+
};
|
|
194
|
+
/**
|
|
195
|
+
* The settings file.
|
|
196
|
+
*/
|
|
197
|
+
export type ThemeData = {
|
|
198
|
+
name: string;
|
|
199
|
+
/**
|
|
200
|
+
* - The built-in theme it builds on.
|
|
201
|
+
*/
|
|
202
|
+
like?: string | undefined;
|
|
203
|
+
mode: "both" | "light-only" | "dark-only";
|
|
204
|
+
settings: Setting[];
|
|
205
|
+
/**
|
|
206
|
+
* - Variant keys the last build repeated a part setting on.
|
|
207
|
+
*/
|
|
208
|
+
lifted?: string[] | undefined;
|
|
209
|
+
};
|
|
210
|
+
export type Ctx = {
|
|
211
|
+
project: import("./_project.mjs").ThemeProject;
|
|
212
|
+
C: import("./_compiler.mjs").Compiler;
|
|
213
|
+
};
|
|
214
|
+
/**
|
|
215
|
+
* What a part reads for a property when the theme does not set it, so a
|
|
216
|
+
* one-mode component setting keeps the other mode as it was.
|
|
217
|
+
* @param {Ctx} ctx
|
|
218
|
+
* @param {string} target
|
|
219
|
+
* @param {string} prop camelCase or kebab-case
|
|
220
|
+
* @param {string | undefined} when
|
|
221
|
+
*/
|
|
222
|
+
export function partDefault(ctx: Ctx, target: string, prop: string, when: string | undefined): string | null;
|