@astryxdesign/cli 0.7.15 → 0.7.16-canary.g8514aae
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 +5 -3
- package/api/component/_adapter.d.mts +1 -1
- package/api/component/_adapter.mjs +28 -1
- package/api/doctor/_adapter.d.mts +17 -0
- package/api/doctor/_adapter.mjs +35 -0
- package/api/doctor/doctor.mjs +18 -4
- package/api/integration/validate-integration.mjs +1 -1
- package/api/theme/_adapter.d.mts +5 -2
- package/api/theme/_adapter.mjs +43 -12
- package/api/theme/build/build.d.mts +1 -21
- package/api/theme/build/build.mjs +149 -37
- package/api/theme/eject/eject.mjs +22 -1
- package/api/theme/template/template.d.mts +19 -0
- package/api/theme/template/template.mjs +91 -19
- package/api/theme/theme.type.d.mts +5 -1
- package/api/theme/theme.type.mjs +2 -1
- package/api/theme/themeBuild.doc.mjs +3 -3
- package/api/theme/themeEject.doc.mjs +1 -1
- package/api/theme/themeTemplate.doc.mjs +9 -3
- package/api/theme-edit/_adapter.d.mts +21 -0
- package/api/theme-edit/_adapter.mjs +176 -22
- package/api/theme-edit/_check.d.mts +7 -0
- package/api/theme-edit/_check.mjs +1050 -173
- package/api/theme-edit/_color.d.mts +2 -8
- package/api/theme-edit/_color.mjs +292 -219
- package/api/theme-edit/_compiler.d.mts +1 -0
- package/api/theme-edit/_compiler.mjs +20 -1
- package/api/theme-edit/_context.d.mts +21 -0
- package/api/theme-edit/_context.mjs +235 -12
- package/api/theme-edit/_css.d.mts +50 -1
- package/api/theme-edit/_css.mjs +310 -28
- package/api/theme-edit/_edit.d.mts +9 -0
- package/api/theme-edit/_edit.mjs +907 -123
- package/api/theme-edit/_how-commands.d.mts +11 -26
- package/api/theme-edit/_how-commands.mjs +30 -2
- package/api/theme-edit/_how-question.d.mts +7 -0
- package/api/theme-edit/_how-question.mjs +1304 -176
- package/api/theme-edit/_how.mjs +144 -30
- package/api/theme-edit/_palette.d.mts +6 -0
- package/api/theme-edit/_palette.mjs +164 -62
- package/api/theme-edit/_parts.d.mts +16 -0
- package/api/theme-edit/_parts.mjs +49 -1
- package/api/theme-edit/_png.mjs +19 -14
- package/api/theme-edit/_preview-app.mjs +514 -27
- package/api/theme-edit/_preview.d.mts +11 -0
- package/api/theme-edit/_preview.mjs +245 -24
- package/api/theme-edit/_project.d.mts +11 -0
- package/api/theme-edit/_project.mjs +35 -9
- package/api/theme-edit/_settings.d.mts +122 -5
- package/api/theme-edit/_settings.mjs +1363 -71
- package/api/theme-edit/_tables.d.mts +19 -0
- package/api/theme-edit/_tables.mjs +205 -149
- package/api/theme-edit/_vet.d.mts +42 -0
- package/api/theme-edit/_vet.mjs +144 -0
- package/api/theme-edit/theme-edit.type.d.mts +2 -1
- package/api/theme-edit/theme-edit.type.mjs +1 -1
- package/api/theme-edit/themeEditNew.doc.mjs +1 -1
- package/api/theme-edit/themeEditShow.doc.mjs +11 -3
- package/assets/docs/tree/single-component.doc.mjs +11 -2
- package/assets/docs/tree/tokens-and-setup.doc.mjs +39 -3
- package/assets/docs.generated.json +2 -2
- package/assets/preview-app/next.config.mjs +7 -1
- package/assets/preview-app/src/app/globals.css +1 -0
- package/assets/self-audit.generated.json +1 -1
- package/assets/templates/blocks/components/Table/ColumnsVirtualizationHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Table/ColumnsVirtualizationHookUsage.tsx +53 -0
- package/assets/templates/blocks/components/Table/InfiniteScrollHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Table/InfiniteScrollHookUsage.tsx +33 -0
- package/assets/templates/components.generated.json +1 -1
- package/authoring/doctypes/_schema.d.mts +52 -5
- package/authoring/doctypes/_schema.mjs +62 -7
- package/authoring/doctypes/base/type.ts +10 -0
- package/authoring/doctypes/component/component.doc.mjs +1 -1
- package/authoring/doctypes/function/function.doc.mjs +6 -0
- package/authoring/doctypes/function/type.ts +3 -0
- package/authoring/doctypes/legacy.mjs +5 -1
- package/authoring/index.d.ts +1 -0
- package/clients/cli/build-id.generated.json +1 -1
- package/clients/cli/commands/doctor.doc.mjs +2 -2
- package/clients/cli/commands/experimental/theme.mjs +188 -37
- package/clients/cli/commands/experimental-theme-compile.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +2 -2
- 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-eject.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-template.doc.mjs +2 -2
- package/clients/cli/commands/theme-build.doc.mjs +2 -2
- package/clients/cli/commands/theme-eject.doc.mjs +1 -1
- package/clients/cli/commands/theme-template.doc.mjs +3 -1
- package/clients/cli/commands/theme.mjs +89 -6
- package/clients/cli/formatters/index.mjs +7 -4
- package/clients/cli/lib/cli-error.mjs +9 -3
- package/clients/cli/lib/component-format.mjs +27 -9
- package/clients/cli/lib/json-shim.mjs +40 -2
- package/clients/cli/manifest.generated.json +1 -1
- package/foundation/config/project.mjs +50 -14
- package/foundation/discovery/theme-discovery.d.mts +5 -1
- package/foundation/discovery/theme-discovery.mjs +24 -3
- package/foundation/fs/gather-cache.d.mts +9 -2
- package/foundation/fs/gather-cache.mjs +36 -10
- package/foundation/fs/paths.d.mts +16 -0
- package/foundation/fs/paths.mjs +25 -0
- package/foundation/render/host-exit.d.mts +8 -0
- package/foundation/render/host-exit.mjs +11 -0
- package/foundation/render/page-host.mjs +56 -10
- package/foundation/render/page-worker.mjs +14 -0
- package/foundation/render/render-page.mjs +37 -2
- package/foundation/response/error-codes.d.mts +2 -1
- package/foundation/response/error-codes.d.ts +1 -0
- package/foundation/response/error-codes.doc.mjs +5 -0
- package/foundation/response/error-codes.mjs +3 -0
- package/foundation/response/json.d.mts +15 -0
- package/foundation/response/json.mjs +52 -1
- package/foundation/response/response-types.doc.mjs +1 -1
- package/package.json +7 -6
|
@@ -85,6 +85,8 @@ export function makeCompiler(project, parts) {
|
|
|
85
85
|
}
|
|
86
86
|
/** @param {string} tok */
|
|
87
87
|
const typeOf = tok => TYPE[tok] ?? 'other';
|
|
88
|
+
/** Whether Core defines the token. @param {string} tok */
|
|
89
|
+
const isToken = tok => Object.hasOwn(TYPE, tok);
|
|
88
90
|
|
|
89
91
|
/** @param {string} p */
|
|
90
92
|
const groupOfProp = p =>
|
|
@@ -276,7 +278,23 @@ export function makeCompiler(project, parts) {
|
|
|
276
278
|
void fed;
|
|
277
279
|
return null;
|
|
278
280
|
}
|
|
279
|
-
|
|
281
|
+
// Only a token of the same kind takes the value: a weight never goes to
|
|
282
|
+
// a line height, a line height never to a weight.
|
|
283
|
+
// Font tokens share a type across kinds (a weight and a leading are
|
|
284
|
+
// both numbers), so the kind is read from the name.
|
|
285
|
+
const kindOf = (/** @type {string} */ t) =>
|
|
286
|
+
/family/.test(t)
|
|
287
|
+
? 'family'
|
|
288
|
+
: /weight/.test(t)
|
|
289
|
+
? 'weight'
|
|
290
|
+
: /leading|line-height/.test(t)
|
|
291
|
+
? 'leading'
|
|
292
|
+
: /tracking|letter-spacing/.test(t)
|
|
293
|
+
? 'tracking'
|
|
294
|
+
: typeOf(t);
|
|
295
|
+
const reads = g
|
|
296
|
+
? partReads(target, g).filter(r => kindOf(r.token) === kindOf(token))
|
|
297
|
+
: [];
|
|
280
298
|
const v = quoteCommandArgument(value);
|
|
281
299
|
/** @type {string[]} */
|
|
282
300
|
const run = [];
|
|
@@ -539,6 +557,7 @@ export function makeCompiler(project, parts) {
|
|
|
539
557
|
return {
|
|
540
558
|
MAP,
|
|
541
559
|
typeOf,
|
|
560
|
+
isToken,
|
|
542
561
|
propsReading,
|
|
543
562
|
feeds,
|
|
544
563
|
fmtFeeds,
|
|
@@ -18,6 +18,7 @@ export function context(cwd: string): Promise<{
|
|
|
18
18
|
C: {
|
|
19
19
|
MAP: Record<string, import("./_parts.mjs").PartRecord>;
|
|
20
20
|
typeOf: (tok: string) => string;
|
|
21
|
+
isToken: (tok: string) => boolean;
|
|
21
22
|
propsReading: (tok: string) => string[];
|
|
22
23
|
feeds: (target: string, token: string) => Array<{
|
|
23
24
|
part: string;
|
|
@@ -63,7 +64,20 @@ export function context(cwd: string): Promise<{
|
|
|
63
64
|
parts: import("./_parts.mjs").PartData;
|
|
64
65
|
unchecked: string | null;
|
|
65
66
|
uncheckedCode: string | null;
|
|
67
|
+
derived: Record<string, {
|
|
68
|
+
property: string;
|
|
69
|
+
vars?: string[];
|
|
70
|
+
replaces?: boolean;
|
|
71
|
+
expand?: string;
|
|
72
|
+
}[]>;
|
|
66
73
|
}>;
|
|
74
|
+
/**
|
|
75
|
+
* Why the components did not render, with the likely cause: two copies of
|
|
76
|
+
* React (the app's and the one Core resolves) break every hook.
|
|
77
|
+
* @param {import('./_project.mjs').ThemeProject} project
|
|
78
|
+
* @param {string} message
|
|
79
|
+
*/
|
|
80
|
+
export function renderCause(project: import("./_project.mjs").ThemeProject, message: string): string;
|
|
67
81
|
/**
|
|
68
82
|
* Pictures of HTML files, on request.
|
|
69
83
|
* @param {import('./_project.mjs').ThemeProject} project
|
|
@@ -111,6 +125,13 @@ export function previewAfter(ctx: import("./_settings.mjs").Ctx, slug: string, d
|
|
|
111
125
|
cause: string;
|
|
112
126
|
} | null;
|
|
113
127
|
}>;
|
|
128
|
+
/**
|
|
129
|
+
* Record in a freshly made full sheet the build it shows.
|
|
130
|
+
* @param {string} file
|
|
131
|
+
* @param {string} slug
|
|
132
|
+
* @param {string} cwd
|
|
133
|
+
*/
|
|
134
|
+
export function stampSheet(file: string, slug: string, cwd: string): void;
|
|
114
135
|
/**
|
|
115
136
|
* The section of the sheet, in lower case, or undefined; a refusal for one
|
|
116
137
|
* that is not a section.
|
|
@@ -8,14 +8,17 @@
|
|
|
8
8
|
* @position api/theme-edit — imported only by the adapter's operation helpers
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
+
import {createHash} from 'node:crypto';
|
|
11
12
|
import * as fs from 'node:fs';
|
|
12
13
|
import {createRequire} from 'node:module';
|
|
13
14
|
import * as path from 'node:path';
|
|
15
|
+
import {pathToFileURL} from 'node:url';
|
|
14
16
|
import {AstryxError} from '../error.mjs';
|
|
15
17
|
import {isOutsideProject} from '../../foundation/env/project-scope.mjs';
|
|
16
18
|
import {
|
|
17
19
|
CLOSEST_OPEN_FONT,
|
|
18
20
|
FONT_ROLES,
|
|
21
|
+
FONTS,
|
|
19
22
|
OPEN_FONTS,
|
|
20
23
|
isDesktopFamily,
|
|
21
24
|
oneSystemOf,
|
|
@@ -33,6 +36,7 @@ import {
|
|
|
33
36
|
nearest,
|
|
34
37
|
refuse,
|
|
35
38
|
themeFiles,
|
|
39
|
+
refuseThemesNotFolder,
|
|
36
40
|
} from './_settings.mjs';
|
|
37
41
|
import {SHOWCASE_GROUPS, renderPreview, screenshot} from './_preview.mjs';
|
|
38
42
|
import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
|
|
@@ -45,7 +49,10 @@ const E = ERROR_CODES;
|
|
|
45
49
|
* @param {string} cwd
|
|
46
50
|
*/
|
|
47
51
|
export function requireProject(cwd) {
|
|
48
|
-
if (!isOutsideProject(cwd))
|
|
52
|
+
if (!isOutsideProject(cwd)) {
|
|
53
|
+
refuseWorkspaceRoot(cwd);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
49
56
|
const pkg = path.join(cwd, 'package.json');
|
|
50
57
|
// Yarn Plug'n'Play has no node_modules for the editor to read Core from.
|
|
51
58
|
if (fs.existsSync(path.join(cwd, '.pnp.cjs')))
|
|
@@ -86,6 +93,7 @@ export function requireProject(cwd) {
|
|
|
86
93
|
*/
|
|
87
94
|
export async function context(cwd) {
|
|
88
95
|
requireProject(cwd);
|
|
96
|
+
refuseThemesNotFolder(cwd);
|
|
89
97
|
const project = await openProject(cwd);
|
|
90
98
|
/** @type {import('./_parts.mjs').PartData} */
|
|
91
99
|
let parts;
|
|
@@ -114,22 +122,143 @@ export async function context(cwd) {
|
|
|
114
122
|
parts,
|
|
115
123
|
unchecked,
|
|
116
124
|
uncheckedCode,
|
|
125
|
+
derived: await derivedVars(project.coreDir),
|
|
117
126
|
};
|
|
118
127
|
}
|
|
119
128
|
|
|
129
|
+
/**
|
|
130
|
+
* Core's registry of the variables a part's plain border-radius or padding
|
|
131
|
+
* also writes (a card's inner corners), or empty on a Core without it.
|
|
132
|
+
* @param {string} coreDir
|
|
133
|
+
* @returns {Promise<Record<string, Array<{property: string, vars?: string[], replaces?: boolean, expand?: string}>>>}
|
|
134
|
+
*/
|
|
135
|
+
async function derivedVars(coreDir) {
|
|
136
|
+
const file = path.join(coreDir, 'dist', 'theme', 'derivedVarRegistry.js');
|
|
137
|
+
if (!fs.existsSync(file)) return {};
|
|
138
|
+
try {
|
|
139
|
+
const mod = await import(pathToFileURL(file).href);
|
|
140
|
+
return mod.derivedVarRegistry ?? {};
|
|
141
|
+
} catch {
|
|
142
|
+
return {};
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
120
146
|
/** @param {unknown} e */
|
|
121
147
|
const isRenderFailure = e =>
|
|
122
148
|
e instanceof AstryxError &&
|
|
123
149
|
(e.code === E.ERR_RENDER_FAILED ||
|
|
124
150
|
e.code === E.ERR_RENDER_MISSING_DEPENDENCY);
|
|
125
151
|
|
|
152
|
+
/**
|
|
153
|
+
* Refuse a workspace root, or a folder under it with no package.json of its
|
|
154
|
+
* own (apps/), that does not use Core itself: Core hoisted to the root's
|
|
155
|
+
* node_modules resolves there too, but the theme belongs in an app. The
|
|
156
|
+
* workspace's apps that use Core are named, each with the `cd` to run from.
|
|
157
|
+
* @param {string} cwd
|
|
158
|
+
*/
|
|
159
|
+
function refuseWorkspaceRoot(cwd) {
|
|
160
|
+
const start = path.resolve(cwd);
|
|
161
|
+
let dir = start;
|
|
162
|
+
// The nearest package.json at or above cwd.
|
|
163
|
+
while (!fs.existsSync(path.join(dir, 'package.json'))) {
|
|
164
|
+
const up = path.dirname(dir);
|
|
165
|
+
if (up === dir) return;
|
|
166
|
+
dir = up;
|
|
167
|
+
}
|
|
168
|
+
const json = readJson(path.join(dir, 'package.json'));
|
|
169
|
+
const patterns = workspacePatterns(dir, json);
|
|
170
|
+
if (!patterns.length || usesCore(json)) return;
|
|
171
|
+
const apps = workspaceApps(dir, patterns)
|
|
172
|
+
.map(a => path.relative(start, a) || '.')
|
|
173
|
+
.sort();
|
|
174
|
+
throw new AstryxError(
|
|
175
|
+
`${path.relative(start, dir) || 'This folder'} is a workspace root${dir === start ? '' : ` (${path.relative(dir, start)} has no package.json of its own)`}, not an app: a theme belongs in an app that uses @astryxdesign/core.${apps.length ? ` The workspace's apps that use it: ${apps.join(', ')}.` : ' None of its packages lists @astryxdesign/core.'} Run the command from the app. Nothing was written.`,
|
|
176
|
+
apps.length
|
|
177
|
+
? apps.slice(0, 4).map(a => ({
|
|
178
|
+
name: `cd ${a}`,
|
|
179
|
+
reason: 'run the command from this app',
|
|
180
|
+
}))
|
|
181
|
+
: [{name: 'npm install @astryxdesign/core', reason: 'in the app'}],
|
|
182
|
+
E.ERR_PROJECT_REQUIRED,
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** @param {string} file */
|
|
187
|
+
function readJson(file) {
|
|
188
|
+
try {
|
|
189
|
+
return JSON.parse(fs.readFileSync(file, 'utf8').replace(/^\uFEFF/, ''));
|
|
190
|
+
} catch {
|
|
191
|
+
return null;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** Whether a package.json lists @astryxdesign/core itself. */
|
|
196
|
+
function usesCore(/** @type {any} */ json) {
|
|
197
|
+
return ['dependencies', 'devDependencies', 'peerDependencies'].some(
|
|
198
|
+
k => json?.[k] && '@astryxdesign/core' in json[k],
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* The workspace patterns of a package (npm and yarn `workspaces`, pnpm's
|
|
204
|
+
* pnpm-workspace.yaml), or none.
|
|
205
|
+
* @param {string} dir
|
|
206
|
+
* @param {any} json
|
|
207
|
+
* @returns {string[]}
|
|
208
|
+
*/
|
|
209
|
+
function workspacePatterns(dir, json) {
|
|
210
|
+
const ws = Array.isArray(json?.workspaces)
|
|
211
|
+
? json.workspaces
|
|
212
|
+
: Array.isArray(json?.workspaces?.packages)
|
|
213
|
+
? json.workspaces.packages
|
|
214
|
+
: [];
|
|
215
|
+
const yaml = path.join(dir, 'pnpm-workspace.yaml');
|
|
216
|
+
const pnpm = fs.existsSync(yaml)
|
|
217
|
+
? [
|
|
218
|
+
...fs
|
|
219
|
+
.readFileSync(yaml, 'utf8')
|
|
220
|
+
.matchAll(/^\s*-\s*['"]?([^'"\n#]+?)['"]?\s*$/gm),
|
|
221
|
+
].map(m => m[1])
|
|
222
|
+
: [];
|
|
223
|
+
return [...ws, ...pnpm].filter(
|
|
224
|
+
p => typeof p === 'string' && !p.startsWith('!'),
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* The folders a workspace's patterns name (`apps/*`, `packages/web`) whose
|
|
230
|
+
* package.json lists Core.
|
|
231
|
+
* @param {string} root
|
|
232
|
+
* @param {string[]} patterns
|
|
233
|
+
* @returns {string[]}
|
|
234
|
+
*/
|
|
235
|
+
function workspaceApps(root, patterns) {
|
|
236
|
+
/** @type {string[]} */
|
|
237
|
+
const out = [];
|
|
238
|
+
for (const p of patterns) {
|
|
239
|
+
const clean = p.replace(/\/\*\*?$/, '');
|
|
240
|
+
const base = path.join(root, clean);
|
|
241
|
+
const dirs = /\*$/.test(p)
|
|
242
|
+
? fs.existsSync(base)
|
|
243
|
+
? fs
|
|
244
|
+
.readdirSync(base, {withFileTypes: true})
|
|
245
|
+
.filter(d => d.isDirectory())
|
|
246
|
+
.map(d => path.join(base, d.name))
|
|
247
|
+
: []
|
|
248
|
+
: [base];
|
|
249
|
+
for (const d of dirs)
|
|
250
|
+
if (usesCore(readJson(path.join(d, 'package.json')))) out.push(d);
|
|
251
|
+
}
|
|
252
|
+
return [...new Set(out)];
|
|
253
|
+
}
|
|
254
|
+
|
|
126
255
|
/**
|
|
127
256
|
* Why the components did not render, with the likely cause: two copies of
|
|
128
257
|
* React (the app's and the one Core resolves) break every hook.
|
|
129
258
|
* @param {import('./_project.mjs').ThemeProject} project
|
|
130
259
|
* @param {string} message
|
|
131
260
|
*/
|
|
132
|
-
function renderCause(project, message) {
|
|
261
|
+
export function renderCause(project, message) {
|
|
133
262
|
/** @param {(id: string) => string} resolve */
|
|
134
263
|
const reactOf = resolve => {
|
|
135
264
|
try {
|
|
@@ -141,10 +270,15 @@ function renderCause(project, message) {
|
|
|
141
270
|
const app = reactOf(project.req.resolve);
|
|
142
271
|
let core = null;
|
|
143
272
|
try {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
)
|
|
273
|
+
// Core's exports keep its package.json private: its folder is found by
|
|
274
|
+
// walking up from the entry the app resolves.
|
|
275
|
+
let dir = path.dirname(project.req.resolve('@astryxdesign/core'));
|
|
276
|
+
while (!fs.existsSync(path.join(dir, 'package.json'))) {
|
|
277
|
+
const up = path.dirname(dir);
|
|
278
|
+
if (up === dir) throw new Error('no package.json');
|
|
279
|
+
dir = up;
|
|
280
|
+
}
|
|
281
|
+
core = reactOf(createRequire(path.join(dir, 'package.json')).resolve);
|
|
148
282
|
} catch {
|
|
149
283
|
// No Core package file: nothing to compare.
|
|
150
284
|
}
|
|
@@ -219,6 +353,18 @@ export function fontNotes(ctx, data) {
|
|
|
219
353
|
: `${family} is not installed, so it does not load: the previews and the app show the next font in the stack. Install it: ${installLine(ctx.project.cwd, [pkg])}. Then the preview imports it on the next set or show, and the app imports it once: import '${pkg}'; Until then, the closest font that needs no install is ${near}: ${P} set ${data.name} font ${near}`,
|
|
220
354
|
);
|
|
221
355
|
}
|
|
356
|
+
// A family the editor's own presets lead with, where the preset gets no
|
|
357
|
+
// note (Comic Sans MS, of comic), is no more a font to load typed by name.
|
|
358
|
+
const presetFamily = (/** @type {string} */ family) => {
|
|
359
|
+
const f = family.replace(/["']/g, '').trim().toLowerCase();
|
|
360
|
+
// A one-system font keeps its note, preset or not.
|
|
361
|
+
if (oneSystemOf(family.replace(/["']/g, '').trim())) return false;
|
|
362
|
+
return Object.entries(FONTS).some(
|
|
363
|
+
([k, [first]]) =>
|
|
364
|
+
(SYSTEM_FONTS.includes(k) || k === 'comic' || k === 'rounded') &&
|
|
365
|
+
first.replace(/["']/g, '').trim().toLowerCase() === f,
|
|
366
|
+
);
|
|
367
|
+
};
|
|
222
368
|
for (const s of data.settings) {
|
|
223
369
|
if (
|
|
224
370
|
s.thing !== 'font' ||
|
|
@@ -228,7 +374,8 @@ export function fontNotes(ctx, data) {
|
|
|
228
374
|
fontOf(s.value).pkg ||
|
|
229
375
|
packages.some(x => x.of === s) ||
|
|
230
376
|
s.value === 'rounded' ||
|
|
231
|
-
s.value === 'comic'
|
|
377
|
+
s.value === 'comic' ||
|
|
378
|
+
presetFamily(fontOf(s.value).family)
|
|
232
379
|
)
|
|
233
380
|
continue;
|
|
234
381
|
const family = fontOf(s.value).family.replace(/["']/g, '').toLowerCase();
|
|
@@ -314,8 +461,17 @@ export function styledChanges(before, after) {
|
|
|
314
461
|
`typography ${role}: ${
|
|
315
462
|
x
|
|
316
463
|
? Object.entries(x)
|
|
317
|
-
.map(
|
|
318
|
-
|
|
464
|
+
.map(
|
|
465
|
+
([k, v]) =>
|
|
466
|
+
`${k} ${
|
|
467
|
+
v && typeof v === 'object'
|
|
468
|
+
? Object.entries(v)
|
|
469
|
+
.map(([a, b]) => `${a}: ${b}`)
|
|
470
|
+
.join(', ')
|
|
471
|
+
: v
|
|
472
|
+
}`,
|
|
473
|
+
)
|
|
474
|
+
.join('; ')
|
|
319
475
|
: '(removed)'
|
|
320
476
|
}`,
|
|
321
477
|
);
|
|
@@ -356,7 +512,7 @@ export async function previewAfter(ctx, slug, data, png) {
|
|
|
356
512
|
const f = themeFiles(ctx.project.cwd, slug);
|
|
357
513
|
// The sheet of every component is made by show only: after a change it
|
|
358
514
|
// says, at its top, that it shows the theme as it was.
|
|
359
|
-
const sheetStale = markSheetStale(f.sheet, slug);
|
|
515
|
+
const sheetStale = markSheetStale(f.sheet, slug, ctx.project.cwd);
|
|
360
516
|
const shots =
|
|
361
517
|
png && preview
|
|
362
518
|
? await pictures(
|
|
@@ -380,19 +536,86 @@ export async function previewAfter(ctx, slug, data, png) {
|
|
|
380
536
|
|
|
381
537
|
const STALE_MARK = '<!-- astryx: sheet older than the theme -->';
|
|
382
538
|
|
|
539
|
+
/** The build a full sheet was made from, recorded in the sheet. */
|
|
540
|
+
const SHEET_STAMP = /<!-- astryx: sheet of build ([0-9a-f]{16}) -->/;
|
|
541
|
+
|
|
542
|
+
/** @param {string} s */
|
|
543
|
+
const escapeForRegExp = s => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
544
|
+
|
|
545
|
+
/**
|
|
546
|
+
* A hash of a theme's built stylesheet and module, or null when either is
|
|
547
|
+
* missing.
|
|
548
|
+
* @param {string} cwd
|
|
549
|
+
* @param {string} slug
|
|
550
|
+
*/
|
|
551
|
+
function buildHash(cwd, slug) {
|
|
552
|
+
const f = themeFiles(cwd, slug);
|
|
553
|
+
try {
|
|
554
|
+
return createHash('sha256')
|
|
555
|
+
.update(fs.readFileSync(f.css))
|
|
556
|
+
.update('\0')
|
|
557
|
+
.update(fs.readFileSync(f.js))
|
|
558
|
+
.digest('hex')
|
|
559
|
+
.slice(0, 16);
|
|
560
|
+
} catch {
|
|
561
|
+
return null;
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
/**
|
|
566
|
+
* Record in a freshly made full sheet the build it shows.
|
|
567
|
+
* @param {string} file
|
|
568
|
+
* @param {string} slug
|
|
569
|
+
* @param {string} cwd
|
|
570
|
+
*/
|
|
571
|
+
export function stampSheet(file, slug, cwd) {
|
|
572
|
+
const hash = buildHash(cwd, slug);
|
|
573
|
+
if (!hash) return;
|
|
574
|
+
try {
|
|
575
|
+
const html = fs.readFileSync(file, 'utf8').replace(SHEET_STAMP, '');
|
|
576
|
+
// At the end: a comment before the doctype would put the page in
|
|
577
|
+
// quirks mode.
|
|
578
|
+
writeWhole(
|
|
579
|
+
file,
|
|
580
|
+
`${html.trimEnd()}\n<!-- astryx: sheet of build ${hash} -->\n`,
|
|
581
|
+
);
|
|
582
|
+
} catch (e) {
|
|
583
|
+
if (/** @type {any} */ (e)?.lockLost) throw e;
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
|
|
383
587
|
/**
|
|
384
588
|
* Put a notice at the top of a sheet the last change made out of date
|
|
385
|
-
* (once)
|
|
589
|
+
* (once), or take it off a sheet made from the build there is now.
|
|
590
|
+
* Returns whether the sheet is out of date.
|
|
386
591
|
* @param {string} file
|
|
387
592
|
* @param {string} slug
|
|
593
|
+
* @param {string} cwd
|
|
388
594
|
*/
|
|
389
|
-
function markSheetStale(file, slug) {
|
|
595
|
+
function markSheetStale(file, slug, cwd) {
|
|
390
596
|
let html;
|
|
391
597
|
try {
|
|
392
598
|
html = fs.readFileSync(file, 'utf8');
|
|
393
599
|
} catch {
|
|
394
600
|
return false;
|
|
395
601
|
}
|
|
602
|
+
// A sheet made from the build there is now (a change, then its undo)
|
|
603
|
+
// shows the theme as it is: no banner, and the result says nothing.
|
|
604
|
+
const made = SHEET_STAMP.exec(html)?.[1];
|
|
605
|
+
if (made && made === buildHash(cwd, slug)) {
|
|
606
|
+
if (html.includes(STALE_MARK)) {
|
|
607
|
+
const clean = html.replace(
|
|
608
|
+
new RegExp(`${escapeForRegExp(STALE_MARK)}<div[^>]*>[\\s\\S]*?</div>`),
|
|
609
|
+
'',
|
|
610
|
+
);
|
|
611
|
+
try {
|
|
612
|
+
writeWhole(file, clean);
|
|
613
|
+
} catch (e) {
|
|
614
|
+
if (/** @type {any} */ (e)?.lockLost) throw e;
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
return false;
|
|
618
|
+
}
|
|
396
619
|
if (html.includes(STALE_MARK)) return true;
|
|
397
620
|
const banner = `${STALE_MARK}<div style="position:sticky;top:0;z-index:9999;padding:8px 12px;background:#fff3cd;color:#3d2c00;font:14px system-ui,sans-serif;border-bottom:1px solid #e0c870">This sheet shows ${slug} as it was before the last change. Run ${P} show ${slug} to make it again.</div>`;
|
|
398
621
|
const at = html.search(/<body[^>]*>/i);
|
|
@@ -8,6 +8,29 @@
|
|
|
8
8
|
* @returns {ReadonlySet<string>}
|
|
9
9
|
*/
|
|
10
10
|
export function cssProperties(): ReadonlySet<string>;
|
|
11
|
+
/**
|
|
12
|
+
* Every longhand a shorthand sets, through shorthands inside it (border
|
|
13
|
+
* sets border-color, so border-top-color), as MDN's data lists them; empty
|
|
14
|
+
* for a property that is no shorthand.
|
|
15
|
+
* @param {string} prop
|
|
16
|
+
* @returns {Set<string>}
|
|
17
|
+
*/
|
|
18
|
+
export function longhandsOf(prop: string): Set<string>;
|
|
19
|
+
/**
|
|
20
|
+
* Whether setting `a` sets `b` too: `b` is one of `a`'s longhands, or a
|
|
21
|
+
* shorthand whose every longhand `a` sets (border covers border-top).
|
|
22
|
+
* overflow-wrap is no part of overflow, nor transform-origin of transform.
|
|
23
|
+
* @param {string} a
|
|
24
|
+
* @param {string} b
|
|
25
|
+
*/
|
|
26
|
+
export function coversProperty(a: string, b: string): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* The value as it reads when each variable is unset: every `var(--x, f)`
|
|
29
|
+
* replaced by its fallback `f`; null when no var() has one.
|
|
30
|
+
* @param {string} value
|
|
31
|
+
* @returns {string | null}
|
|
32
|
+
*/
|
|
33
|
+
export function withFallbacks(value: string): string | null;
|
|
11
34
|
/**
|
|
12
35
|
* Whether a value matches a property's grammar, as css-tree reads it. A
|
|
13
36
|
* var() or env() can hold anything, so the value matches when some
|
|
@@ -29,7 +52,8 @@ export function matchType(type: string, value: string): any | null;
|
|
|
29
52
|
/**
|
|
30
53
|
* Whether a value that matches a property's grammar is still below a range
|
|
31
54
|
* the specs set and css-tree's data does not carry: a `<line-width>` (a
|
|
32
|
-
* border or outline width) and a duration are never negative
|
|
55
|
+
* border or outline width) and a duration are never negative, nor is any
|
|
56
|
+
* number the current specifications' grammar ranges at 0 or more.
|
|
33
57
|
* @param {string} property
|
|
34
58
|
* @param {string} value
|
|
35
59
|
*/
|
|
@@ -51,6 +75,12 @@ export function numbersIn(ast: any): Array<{
|
|
|
51
75
|
* @returns {string[]}
|
|
52
76
|
*/
|
|
53
77
|
export function keywordsOf(prop: string): string[];
|
|
78
|
+
/**
|
|
79
|
+
* The CSS generic font families (serif, math, ui-rounded …), as the
|
|
80
|
+
* grammar's `<generic-family>` type lists them; non-standard ones left out.
|
|
81
|
+
* @returns {string[]}
|
|
82
|
+
*/
|
|
83
|
+
export function genericFamilies(): string[];
|
|
54
84
|
/**
|
|
55
85
|
* A value the property takes, to put in a suggestion: its initial value
|
|
56
86
|
* from MDN's data (a shorthand's first longhand's).
|
|
@@ -58,6 +88,25 @@ export function keywordsOf(prop: string): string[];
|
|
|
58
88
|
* @returns {string | null}
|
|
59
89
|
*/
|
|
60
90
|
export function initialOf(prop: string): string | null;
|
|
91
|
+
/**
|
|
92
|
+
* One CSS number, percentage or dimension, read by css-tree's tokenizer as
|
|
93
|
+
* the browser reads it (`1.5e0`, `+1.5`, `15E-1`, `1.5EM`; never `50.%`),
|
|
94
|
+
* or null for anything else.
|
|
95
|
+
* @param {string} value
|
|
96
|
+
* @returns {{value: number, unit: string} | null}
|
|
97
|
+
*/
|
|
98
|
+
export function cssNumber(value: string): {
|
|
99
|
+
value: number;
|
|
100
|
+
unit: string;
|
|
101
|
+
} | null;
|
|
102
|
+
/**
|
|
103
|
+
* A value split at `sep` outside brackets: `a(b, c), d` by `,` is
|
|
104
|
+
* [`a(b, c)`, ` d`]. A space separator also splits runs of spaces.
|
|
105
|
+
* @param {string} v
|
|
106
|
+
* @param {',' | ' ' | '/'} sep
|
|
107
|
+
* @returns {string[]}
|
|
108
|
+
*/
|
|
109
|
+
export function splitTop(v: string, sep: "," | " " | "/"): string[];
|
|
61
110
|
/**
|
|
62
111
|
* The parts of a CSS `font` value, by the longhand each sets, as written:
|
|
63
112
|
* `italic small-caps 700 1rem/1 Arial` gives font-style, font-variant-caps,
|