@astryxdesign/cli 0.7.14 → 0.7.15-canary.g06b7e61
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +3 -3
- package/README.md +63 -63
- package/api/build/_adapter.d.mts +4 -0
- package/api/build/_adapter.mjs +28 -2
- package/api/build/blocks/blocks.d.mts +10 -1
- package/api/build/blocks/blocks.mjs +84 -7
- package/api/build/build.mjs +6 -1
- package/api/build/tree.d.mts +4 -0
- package/api/build/tree.mjs +9 -2
- package/api/doctor/_adapter.d.mts +3 -1
- package/api/doctor/_adapter.mjs +14 -1
- package/api/doctor/_authoring-audit.d.mts +42 -0
- package/api/doctor/_authoring-audit.mjs +106 -0
- package/api/doctor/doctor.d.mts +7 -0
- package/api/doctor/doctor.mjs +24 -39
- package/api/doctor/theme-checks.mjs +56 -21
- package/api/integration/add-helpers.mjs +5 -0
- package/api/integration/add-theme.mjs +15 -110
- package/api/integration/validate-integration.mjs +17 -3
- package/api/integration/validateIntegration.doc.mjs +1 -1
- package/api/search/_adapter.mjs +124 -3
- package/api/search/_candidate-score.mjs +63 -9
- package/api/search/_entries.d.mts +10 -0
- package/api/search/_entries.mjs +68 -1
- package/api/search/_gather-templates.d.mts +11 -0
- package/api/search/_gather-templates.mjs +22 -2
- package/api/search/_words.mjs +26 -6
- package/api/swizzle/copy/copy.mjs +1 -1
- package/api/theme/_adapter.d.mts +37 -5
- package/api/theme/_adapter.mjs +381 -57
- package/api/theme/_fork.d.mts +90 -0
- package/api/theme/_fork.mjs +246 -0
- package/api/theme/build/build.d.mts +40 -2
- package/api/theme/build/build.mjs +477 -66
- package/api/theme/eject/eject.mjs +36 -15
- package/api/theme/list/list.mjs +3 -6
- package/api/theme/palette/generate/generator.d.mts +13 -0
- package/api/theme/palette/generate/generator.mjs +32 -2
- package/api/theme/targets/targets.d.mts +8 -0
- package/api/theme/targets/targets.mjs +24 -4
- package/api/theme/template/template.mjs +48 -2
- package/api/theme/theme.type.d.mts +8 -0
- package/api/theme/theme.type.mjs +5 -1
- package/api/theme/themeBuild.doc.mjs +7 -4
- package/api/theme/themeEject.doc.mjs +3 -3
- package/api/theme/themeRemove.doc.mjs +5 -2
- package/api/theme/themeTargets.doc.mjs +1 -1
- package/api/theme/themeTemplate.doc.mjs +2 -2
- package/api/theme/themeUse.doc.mjs +8 -2
- package/api/theme-edit/_adapter.d.mts +46 -3
- package/api/theme-edit/_adapter.mjs +496 -112
- package/api/theme-edit/_catalog.d.mts +1 -6
- package/api/theme-edit/_catalog.mjs +5 -268
- package/api/theme-edit/_check.d.mts +9 -4
- package/api/theme-edit/_check.mjs +1232 -229
- package/api/theme-edit/_color.d.mts +19 -0
- package/api/theme-edit/_color.mjs +280 -34
- package/api/theme-edit/_compiler.d.mts +3 -1
- package/api/theme-edit/_compiler.mjs +52 -13
- package/api/theme-edit/_context.d.mts +4 -1
- package/api/theme-edit/_context.mjs +126 -13
- package/api/theme-edit/_css.d.mts +84 -0
- package/api/theme-edit/_css.mjs +700 -0
- package/api/theme-edit/_edit.d.mts +9 -3
- package/api/theme-edit/_edit.mjs +806 -103
- package/api/theme-edit/_how-commands.d.mts +38 -7
- package/api/theme-edit/_how-commands.mjs +64 -45
- package/api/theme-edit/_how-question.d.mts +33 -0
- package/api/theme-edit/_how-question.mjs +2553 -381
- package/api/theme-edit/_how.mjs +402 -31
- package/api/theme-edit/_overview.mjs +2 -7
- package/api/theme-edit/_palette.d.mts +60 -13
- package/api/theme-edit/_palette.mjs +826 -295
- package/api/theme-edit/_parts.d.mts +42 -10
- package/api/theme-edit/_parts.mjs +280 -69
- package/api/theme-edit/_png.d.mts +4 -4
- package/api/theme-edit/_png.mjs +4 -2
- package/api/theme-edit/_preview-app.d.mts +14 -0
- package/api/theme-edit/_preview-app.mjs +1675 -235
- package/api/theme-edit/_preview.d.mts +7 -16
- package/api/theme-edit/_preview.mjs +79 -86
- package/api/theme-edit/_project.d.mts +32 -2
- package/api/theme-edit/_project.mjs +80 -19
- package/api/theme-edit/_settings.d.mts +199 -52
- package/api/theme-edit/_settings.mjs +1422 -217
- package/api/theme-edit/_tables.d.mts +19 -6
- package/api/theme-edit/_tables.mjs +150 -92
- package/api/theme-edit/theme-edit.type.d.mts +20 -1
- package/api/theme-edit/theme-edit.type.mjs +6 -3
- package/api/theme-edit/themeEditHow.doc.mjs +6 -0
- package/api/theme-edit/themeEditNew.doc.mjs +1 -1
- package/api/theme-edit/themeEditPreviewAdd.doc.mjs +1 -1
- package/api/theme-edit/themeEditPreviewApp.doc.mjs +1 -1
- package/api/theme-edit/themeEditPreviewList.doc.mjs +2 -2
- package/api/theme-edit/themeEditPreviewRemove.doc.mjs +5 -1
- package/api/theme-edit/themeEditSet.doc.mjs +1 -1
- package/api/theme-edit/themeEditUndo.doc.mjs +1 -1
- package/api/upgrade/_adapter.d.mts +1 -0
- package/assets/codemods/run-codemod.mjs +61 -0
- package/assets/codemods/runner.mjs +5 -4
- package/assets/codemods/transforms/v0.0.14/rename-status-variants.mjs +3 -0
- package/assets/codemods/transforms/v0.1.8/rename-avatar-size-scale.mjs +5 -1
- package/assets/codemods/transforms/v0.6.4/migrate-native-picker-to-presentation.mjs +3 -0
- package/assets/codemods/transforms/v0.7.0/migrate-deprecated-theme-surface.mjs +4 -0
- package/assets/codemods/transforms/v0.7.0/rename-empty-search-results-text.mjs +17 -12
- package/assets/codemods/transforms/v0.7.2/migrate-list-edge-compensation-to-edge.mjs +3 -0
- package/assets/codemods/transforms/v0.7.5/migrate-codeblock-tokenizer-to-language.mjs +3 -0
- package/assets/codemods/transforms/v0.7.8/promote-tokenizer-presentation.mjs +3 -0
- package/assets/docs/tree/calendars.doc.mjs +1 -3
- package/assets/docs/tree/checks.doc.mjs +22 -1
- package/assets/docs/tree/publishing.doc.mjs +1 -0
- package/assets/docs/tree/tokens-and-setup.doc.mjs +39 -3
- package/assets/docs.generated.json +2 -1
- package/assets/preview-app/next.config.mjs +7 -1
- package/assets/self-audit.generated.json +1 -0
- package/assets/templates/blocks/components/Theme/useThemeNameHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Theme/useThemeNameHookUsage.tsx +31 -0
- package/assets/templates/components.generated.json +1 -1
- package/authoring/integration/integration.doc.mjs +8 -0
- package/authoring/integration/schema.d.mts +8 -0
- package/authoring/integration/schema.mjs +1 -0
- package/authoring/integration/type.ts +9 -0
- package/clients/cli/bin/astryx.mjs +19 -15
- package/clients/cli/build-id.generated.json +1 -0
- package/clients/cli/commands/ensure-core-built.mjs +12 -5
- package/clients/cli/commands/experimental/index.mjs +10 -10
- package/clients/cli/commands/experimental/theme.mjs +200 -81
- package/clients/cli/commands/experimental-theme-compile.doc.mjs +3 -3
- package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +3 -3
- package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +1 -2
- package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-eject.doc.mjs +3 -3
- package/clients/cli/commands/experimental-theme-preview-add.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-preview-list.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-preview-remove.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-remove.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-template.doc.mjs +4 -3
- package/clients/cli/commands/integration.mjs +8 -0
- package/clients/cli/commands/manifest.mjs +5 -2
- package/clients/cli/commands/theme-build.doc.mjs +2 -2
- package/clients/cli/commands/theme-list.doc.mjs +1 -1
- package/clients/cli/commands/theme-template.doc.mjs +1 -1
- package/clients/cli/commands/theme.mjs +439 -66
- package/clients/cli/index.mjs +27 -6
- package/clients/cli/lib/cli-error.mjs +118 -3
- package/clients/cli/lib/manifest.mjs +37 -0
- package/clients/cli/lib/resolve-theme.mjs +2 -1
- package/clients/cli/manifest.generated.json +1 -0
- package/foundation/config/project.mjs +34 -8
- package/foundation/config/theme-state.d.mts +16 -0
- package/foundation/config/theme-state.mjs +84 -13
- package/foundation/discovery/module-exports.mjs +16 -2
- package/foundation/discovery/stored-self-audit.d.mts +31 -0
- package/foundation/discovery/stored-self-audit.mjs +119 -0
- package/foundation/discovery/template-adapter.d.mts +48 -2
- package/foundation/discovery/template-adapter.mjs +51 -19
- package/foundation/discovery/template-needs.d.mts +19 -0
- package/foundation/discovery/template-needs.mjs +50 -16
- package/foundation/discovery/template-source-tree.d.mts +7 -0
- package/foundation/discovery/template-source-tree.mjs +15 -0
- package/foundation/discovery/theme-discovery.d.mts +2 -1
- package/foundation/discovery/theme-discovery.mjs +16 -10
- package/foundation/discovery/theme-imports.d.mts +16 -0
- package/foundation/discovery/theme-imports.mjs +30 -2
- package/foundation/discovery/theme-module-extensions.d.mts +18 -0
- package/foundation/discovery/theme-module-extensions.mjs +30 -0
- package/foundation/doc-compiler/import.mjs +22 -15
- package/foundation/doc-compiler/stored-docs.d.mts +18 -12
- package/foundation/doc-compiler/stored-docs.mjs +52 -19
- package/foundation/env/private-dir.d.mts +17 -0
- package/foundation/env/private-dir.mjs +42 -0
- package/foundation/fs/gather-cache.d.mts +108 -0
- package/foundation/fs/gather-cache.mjs +783 -0
- package/foundation/fs/jiti-cache.d.mts +21 -0
- package/foundation/fs/jiti-cache.mjs +66 -0
- package/foundation/fs/module-loader.mjs +14 -3
- package/foundation/fs/read-record.d.mts +31 -1
- package/foundation/fs/read-record.mjs +100 -7
- package/foundation/integrations/autolink.d.mts +1 -24
- package/foundation/integrations/autolink.mjs +7 -60
- package/foundation/integrations/declared-dependencies.d.mts +27 -0
- package/foundation/integrations/declared-dependencies.mjs +73 -0
- package/foundation/integrations/integrations.d.mts +8 -0
- package/foundation/integrations/integrations.mjs +4 -0
- package/foundation/integrations/may-have-integrations.d.mts +8 -0
- package/foundation/integrations/may-have-integrations.mjs +47 -0
- package/foundation/integrations/validate-contributions.d.mts +62 -1
- package/foundation/integrations/validate-contributions.mjs +476 -40
- package/foundation/release/cache.d.mts +32 -4
- package/foundation/release/cache.mjs +105 -16
- package/foundation/release/folder-lock.d.mts +28 -0
- package/foundation/release/folder-lock.mjs +205 -0
- package/foundation/release/lock-lease.d.mts +2 -1
- package/foundation/release/lock-lease.mjs +7 -2
- package/foundation/response/error-codes.doc.mjs +1 -1
- package/foundation/response/response-types.doc.mjs +5 -5
- package/package.json +8 -6
- package/api/theme-edit/_css-properties.d.mts +0 -10
- package/api/theme-edit/_css-properties.mjs +0 -556
|
@@ -13,10 +13,19 @@ import {createRequire} from 'node:module';
|
|
|
13
13
|
import * as path from 'node:path';
|
|
14
14
|
import {AstryxError} from '../error.mjs';
|
|
15
15
|
import {isOutsideProject} from '../../foundation/env/project-scope.mjs';
|
|
16
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
CLOSEST_OPEN_FONT,
|
|
18
|
+
FONT_ROLES,
|
|
19
|
+
OPEN_FONTS,
|
|
20
|
+
isDesktopFamily,
|
|
21
|
+
oneSystemOf,
|
|
22
|
+
P,
|
|
23
|
+
SYSTEM_FONTS,
|
|
24
|
+
} from './_tables.mjs';
|
|
17
25
|
import {makeCompiler} from './_compiler.mjs';
|
|
18
26
|
import {openProject, installLine} from './_project.mjs';
|
|
19
27
|
import {partData} from './_parts.mjs';
|
|
28
|
+
import {writeWhole} from './_palette.mjs';
|
|
20
29
|
import {
|
|
21
30
|
fontOf,
|
|
22
31
|
fontPackages,
|
|
@@ -42,7 +51,12 @@ export function requireProject(cwd) {
|
|
|
42
51
|
if (fs.existsSync(path.join(cwd, '.pnp.cjs')))
|
|
43
52
|
throw new AstryxError(
|
|
44
53
|
"This app uses Yarn Plug'n'Play, which astryx experimental theme does not support: it reads the installed Core from node_modules. Set `nodeLinker: node-modules` in .yarnrc.yml and run yarn install. Nothing was written.",
|
|
45
|
-
[
|
|
54
|
+
[
|
|
55
|
+
{
|
|
56
|
+
name: 'yarn config set nodeLinker node-modules',
|
|
57
|
+
reason: 'do this first, then yarn install',
|
|
58
|
+
},
|
|
59
|
+
],
|
|
46
60
|
E.ERR_PROJECT_REQUIRED,
|
|
47
61
|
);
|
|
48
62
|
// A package.json with no Core: an app (or a workspace root) that needs it.
|
|
@@ -54,7 +68,12 @@ export function requireProject(cwd) {
|
|
|
54
68
|
);
|
|
55
69
|
throw new AstryxError(
|
|
56
70
|
'No package.json found. astryx experimental theme works inside an app project, which it writes the theme into and whose installed Core it checks every change against. Nothing was written.',
|
|
57
|
-
[
|
|
71
|
+
[
|
|
72
|
+
{
|
|
73
|
+
name: 'npm init -y',
|
|
74
|
+
reason: 'make a package.json here, then install @astryxdesign/core',
|
|
75
|
+
},
|
|
76
|
+
],
|
|
58
77
|
E.ERR_PROJECT_REQUIRED,
|
|
59
78
|
);
|
|
60
79
|
}
|
|
@@ -72,11 +91,14 @@ export async function context(cwd) {
|
|
|
72
91
|
let parts;
|
|
73
92
|
/** @type {string | null} */
|
|
74
93
|
let unchecked = null;
|
|
94
|
+
/** @type {string | null} the render error's code */
|
|
95
|
+
let uncheckedCode = null;
|
|
75
96
|
try {
|
|
76
97
|
parts = await partData(project);
|
|
77
98
|
} catch (e) {
|
|
78
99
|
if (!isRenderFailure(e)) throw e;
|
|
79
100
|
unchecked = renderCause(project, /** @type {Error} */ (e).message);
|
|
101
|
+
uncheckedCode = /** @type {any} */ (e).code ?? null;
|
|
80
102
|
parts = {
|
|
81
103
|
version: 0,
|
|
82
104
|
coreKey: project.coreKey,
|
|
@@ -86,7 +108,13 @@ export async function context(cwd) {
|
|
|
86
108
|
items: 0,
|
|
87
109
|
};
|
|
88
110
|
}
|
|
89
|
-
return {
|
|
111
|
+
return {
|
|
112
|
+
project,
|
|
113
|
+
C: makeCompiler(project, parts),
|
|
114
|
+
parts,
|
|
115
|
+
unchecked,
|
|
116
|
+
uncheckedCode,
|
|
117
|
+
};
|
|
90
118
|
}
|
|
91
119
|
|
|
92
120
|
/** @param {unknown} e */
|
|
@@ -142,6 +170,8 @@ const notChecked = cause =>
|
|
|
142
170
|
export async function pictures(project, shots, modes) {
|
|
143
171
|
/** @type {string[]} */
|
|
144
172
|
const files = [];
|
|
173
|
+
/** @type {string[]} */
|
|
174
|
+
const cut = [];
|
|
145
175
|
for (const {html, png} of shots) {
|
|
146
176
|
for (const m of modes) {
|
|
147
177
|
const out =
|
|
@@ -151,9 +181,16 @@ export async function pictures(project, shots, modes) {
|
|
|
151
181
|
const r = await screenshot(project, html, out, m);
|
|
152
182
|
if (!r.ok) return {files, problem: r.reason};
|
|
153
183
|
files.push(r.file);
|
|
184
|
+
if (r.cut) cut.push(r.file);
|
|
154
185
|
}
|
|
155
186
|
}
|
|
156
|
-
return {
|
|
187
|
+
return {
|
|
188
|
+
files,
|
|
189
|
+
// A picture of the window shows the top of a longer page only.
|
|
190
|
+
problem: cut.length
|
|
191
|
+
? `${cut.join(', ')} show${cut.length === 1 ? 's' : ''} the top 2400 pixels of the page only (Chrome takes the window, not the whole page); open the .html beside ${cut.length === 1 ? 'it' : 'them'} to see all of it, or install Playwright (${installLine(project.cwd, ['playwright'])}) for whole-page pictures`
|
|
192
|
+
: null,
|
|
193
|
+
};
|
|
157
194
|
}
|
|
158
195
|
|
|
159
196
|
/**
|
|
@@ -167,7 +204,8 @@ export async function pictures(project, shots, modes) {
|
|
|
167
204
|
export function fontNotes(ctx, data) {
|
|
168
205
|
/** @type {string[]} */
|
|
169
206
|
const notes = [];
|
|
170
|
-
|
|
207
|
+
const packages = fontPackages(ctx, data);
|
|
208
|
+
for (const {pkg, family, installed} of packages) {
|
|
171
209
|
const fallbacks =
|
|
172
210
|
Object.values(OPEN_FONTS).find(f => f.pkg === pkg)?.fallbacks ?? '';
|
|
173
211
|
const near = /monospace/.test(fallbacks)
|
|
@@ -185,16 +223,32 @@ export function fontNotes(ctx, data) {
|
|
|
185
223
|
if (
|
|
186
224
|
s.thing !== 'font' ||
|
|
187
225
|
SYSTEM_FONTS.includes(s.value) ||
|
|
226
|
+
isDesktopFamily(fontOf(s.value).family.replace(/["']/g, '')) ||
|
|
188
227
|
OPEN_FONTS[s.value] ||
|
|
189
228
|
fontOf(s.value).pkg ||
|
|
229
|
+
packages.some(x => x.of === s) ||
|
|
190
230
|
s.value === 'rounded' ||
|
|
191
231
|
s.value === 'comic'
|
|
192
232
|
)
|
|
193
233
|
continue;
|
|
194
234
|
const family = fontOf(s.value).family.replace(/["']/g, '').toLowerCase();
|
|
195
235
|
const near = CLOSEST_OPEN_FONT[family];
|
|
236
|
+
const named = fontOf(s.value).family.replace(/^["']|["']$/g, '');
|
|
237
|
+
const system = oneSystemOf(named);
|
|
238
|
+
const on = s.on ? ` --on ${s.on}` : '';
|
|
239
|
+
if (system) {
|
|
240
|
+
// A system font, on one system: the others show the next font.
|
|
241
|
+
const next =
|
|
242
|
+
fontOf(s.value).fallbacks.split(',')[0]?.trim() || 'system-ui';
|
|
243
|
+
notes.push(
|
|
244
|
+
/^(-apple-system|blinkmacsystemfont)$/.test(family)
|
|
245
|
+
? `"${named}" names the macOS interface font, which only macOS has: other systems show the next font in the stack (${next}). The system preset gives each system its own interface font: ${P} set ${data.name} font system${on}`
|
|
246
|
+
: `"${named}" ships only on ${system}: other systems show the next font in the stack (${next}).${near ? ` The closest open font, which loads everywhere, is ${near}: ${P} set ${data.name} font ${near}${on}` : ''}`,
|
|
247
|
+
);
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
196
250
|
notes.push(
|
|
197
|
-
`"${fontOf(s.value).family.replace(
|
|
251
|
+
`"${fontOf(s.value).family.replace(/^["']|["']$/g, '')}" is not a system font and no package loads it: the app must load it, or it falls back.${near ? ` The closest open font is ${near}: ${P} set ${data.name} font ${near}${s.on ? ` --on ${s.on}` : ''}` : ''}`,
|
|
198
252
|
);
|
|
199
253
|
}
|
|
200
254
|
return notes;
|
|
@@ -218,13 +272,31 @@ export function styledChanges(before, after) {
|
|
|
218
272
|
])) {
|
|
219
273
|
const x = a[target]?.[key] ?? {};
|
|
220
274
|
const y = b[target]?.[key] ?? {};
|
|
275
|
+
/** @param {string} p */
|
|
276
|
+
const cssName = p =>
|
|
277
|
+
p.startsWith('--')
|
|
278
|
+
? p
|
|
279
|
+
: p.replace(/[A-Z]/g, c => `-${c.toLowerCase()}`);
|
|
221
280
|
for (const prop of new Set([...Object.keys(x), ...Object.keys(y)])) {
|
|
222
281
|
if (JSON.stringify(x[prop]) === JSON.stringify(y[prop])) continue;
|
|
223
|
-
const
|
|
224
|
-
|
|
225
|
-
|
|
282
|
+
const where = `${target}${key === 'base' ? '' : ` ${key}`}`;
|
|
283
|
+
// A state block (`:hover`) lists each property it changes.
|
|
284
|
+
if (
|
|
285
|
+
prop.startsWith(':') &&
|
|
286
|
+
((y[prop] && typeof y[prop] === 'object') ||
|
|
287
|
+
(x[prop] && typeof x[prop] === 'object'))
|
|
288
|
+
) {
|
|
289
|
+
const xs = x[prop] ?? {};
|
|
290
|
+
const ys = y[prop] ?? {};
|
|
291
|
+
for (const p of new Set([...Object.keys(xs), ...Object.keys(ys)]))
|
|
292
|
+
if (JSON.stringify(xs[p]) !== JSON.stringify(ys[p]))
|
|
293
|
+
out.push(
|
|
294
|
+
`${where} ${prop}: ${cssName(p)} ${ys[p] === undefined ? '(removed)' : String(ys[p])}`,
|
|
295
|
+
);
|
|
296
|
+
continue;
|
|
297
|
+
}
|
|
226
298
|
out.push(
|
|
227
|
-
`${
|
|
299
|
+
`${where}: ${cssName(prop)} ${y[prop] === undefined ? '(removed)' : typeof y[prop] === 'string' ? y[prop] : JSON.stringify(y[prop])}`,
|
|
228
300
|
);
|
|
229
301
|
}
|
|
230
302
|
}
|
|
@@ -232,7 +304,7 @@ export function styledChanges(before, after) {
|
|
|
232
304
|
const ta = JSON.stringify(before?.typography ?? {});
|
|
233
305
|
const tb = JSON.stringify(after?.typography ?? {});
|
|
234
306
|
if (ta !== tb) {
|
|
235
|
-
for (const role of
|
|
307
|
+
for (const role of FONT_ROLES) {
|
|
236
308
|
const x = after?.typography?.[role];
|
|
237
309
|
if (
|
|
238
310
|
JSON.stringify(before?.typography?.[role] ?? null) !==
|
|
@@ -274,11 +346,17 @@ export async function previewAfter(ctx, slug, data, png) {
|
|
|
274
346
|
preview = await renderPreview(ctx, slug, data);
|
|
275
347
|
} catch (e) {
|
|
276
348
|
// The change is already saved: any failure here leaves it unchecked.
|
|
349
|
+
const code = /** @type {any} */ (e)?.code;
|
|
277
350
|
cause ??= isRenderFailure(e)
|
|
278
351
|
? renderCause(ctx.project, /** @type {Error} */ (e).message)
|
|
279
|
-
:
|
|
352
|
+
: ['ENOSPC', 'EACCES', 'EPERM', 'EROFS', 'EIO'].includes(code)
|
|
353
|
+
? `preview.html could not be written (${code === 'ENOSPC' ? 'the disk is full' : code}), so it still shows the theme as it was`
|
|
354
|
+
: `checking it failed: ${e instanceof Error ? e.message : String(e)}`;
|
|
280
355
|
}
|
|
281
356
|
const f = themeFiles(ctx.project.cwd, slug);
|
|
357
|
+
// The sheet of every component is made by show only: after a change it
|
|
358
|
+
// says, at its top, that it shows the theme as it was.
|
|
359
|
+
const sheetStale = markSheetStale(f.sheet, slug);
|
|
282
360
|
const shots =
|
|
283
361
|
png && preview
|
|
284
362
|
? await pictures(
|
|
@@ -292,9 +370,44 @@ export async function previewAfter(ctx, slug, data, png) {
|
|
|
292
370
|
pictures: shots.files,
|
|
293
371
|
pictureProblem: shots.problem,
|
|
294
372
|
notChecked: notChecked(cause),
|
|
373
|
+
...(sheetStale
|
|
374
|
+
? {
|
|
375
|
+
sheetStale: `sheet.html shows ${slug} as it was before this change; ${P} show ${slug} makes it again`,
|
|
376
|
+
}
|
|
377
|
+
: {}),
|
|
295
378
|
};
|
|
296
379
|
}
|
|
297
380
|
|
|
381
|
+
const STALE_MARK = '<!-- astryx: sheet older than the theme -->';
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* Put a notice at the top of a sheet the last change made out of date
|
|
385
|
+
* (once). Returns whether there is such a sheet.
|
|
386
|
+
* @param {string} file
|
|
387
|
+
* @param {string} slug
|
|
388
|
+
*/
|
|
389
|
+
function markSheetStale(file, slug) {
|
|
390
|
+
let html;
|
|
391
|
+
try {
|
|
392
|
+
html = fs.readFileSync(file, 'utf8');
|
|
393
|
+
} catch {
|
|
394
|
+
return false;
|
|
395
|
+
}
|
|
396
|
+
if (html.includes(STALE_MARK)) return true;
|
|
397
|
+
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
|
+
const at = html.search(/<body[^>]*>/i);
|
|
399
|
+
const next =
|
|
400
|
+
at < 0 ? banner + html : html.replace(/<body[^>]*>/i, m => `${m}${banner}`);
|
|
401
|
+
try {
|
|
402
|
+
// Fenced like every editor write under the theme lock.
|
|
403
|
+
writeWhole(file, next);
|
|
404
|
+
} catch (e) {
|
|
405
|
+
if (/** @type {any} */ (e)?.lockLost) throw e;
|
|
406
|
+
// Read-only: the note in the result still says so.
|
|
407
|
+
}
|
|
408
|
+
return true;
|
|
409
|
+
}
|
|
410
|
+
|
|
298
411
|
/**
|
|
299
412
|
* The section of the sheet, in lower case, or undefined; a refusal for one
|
|
300
413
|
* that is not a section.
|
|
@@ -0,0 +1,84 @@
|
|
|
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 standard CSS property names: every property css-tree's MDN data
|
|
6
|
+
* lists that is not vendor-prefixed or obsolete, plus NOT_IN_MDN_YET. A
|
|
7
|
+
* name outside it is not a CSS property, so the command refuses it.
|
|
8
|
+
* @returns {ReadonlySet<string>}
|
|
9
|
+
*/
|
|
10
|
+
export function cssProperties(): ReadonlySet<string>;
|
|
11
|
+
/**
|
|
12
|
+
* Whether a value matches a property's grammar, as css-tree reads it. A
|
|
13
|
+
* var() or env() can hold anything, so the value matches when some
|
|
14
|
+
* ordinary value in its place does. Returns the parsed value on a match, for range checks the
|
|
15
|
+
* grammar does not make.
|
|
16
|
+
* @param {string} property
|
|
17
|
+
* @param {string} value
|
|
18
|
+
* @returns {any | null}
|
|
19
|
+
*/
|
|
20
|
+
export function matchValue(property: string, value: string): any | null;
|
|
21
|
+
/**
|
|
22
|
+
* Whether a value is one value of a CSS type (`time`, `easing-function`,
|
|
23
|
+
* `length-percentage`), never a list. Returns the parsed value on a match.
|
|
24
|
+
* @param {string} type
|
|
25
|
+
* @param {string} value
|
|
26
|
+
* @returns {any | null}
|
|
27
|
+
*/
|
|
28
|
+
export function matchType(type: string, value: string): any | null;
|
|
29
|
+
/**
|
|
30
|
+
* Whether a value that matches a property's grammar is still below a range
|
|
31
|
+
* 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.
|
|
33
|
+
* @param {string} property
|
|
34
|
+
* @param {string} value
|
|
35
|
+
*/
|
|
36
|
+
export function belowRange(property: string, value: string): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Each number a matched value holds, with its unit (`''` for a plain
|
|
39
|
+
* number) and the function it sits in, in order.
|
|
40
|
+
* @param {any} ast
|
|
41
|
+
* @returns {Array<{value: number, unit: string, fn: string | null}>}
|
|
42
|
+
*/
|
|
43
|
+
export function numbersIn(ast: any): Array<{
|
|
44
|
+
value: number;
|
|
45
|
+
unit: string;
|
|
46
|
+
fn: string | null;
|
|
47
|
+
}>;
|
|
48
|
+
/**
|
|
49
|
+
* The keywords a property's grammar takes, through the types it names.
|
|
50
|
+
* @param {string} prop
|
|
51
|
+
* @returns {string[]}
|
|
52
|
+
*/
|
|
53
|
+
export function keywordsOf(prop: string): string[];
|
|
54
|
+
/**
|
|
55
|
+
* A value the property takes, to put in a suggestion: its initial value
|
|
56
|
+
* from MDN's data (a shorthand's first longhand's).
|
|
57
|
+
* @param {string} prop
|
|
58
|
+
* @returns {string | null}
|
|
59
|
+
*/
|
|
60
|
+
export function initialOf(prop: string): string | null;
|
|
61
|
+
/**
|
|
62
|
+
* The parts of a CSS `font` value, by the longhand each sets, as written:
|
|
63
|
+
* `italic small-caps 700 1rem/1 Arial` gives font-style, font-variant-caps,
|
|
64
|
+
* font-weight, font-size, line-height and font-family. A system font
|
|
65
|
+
* keyword (`caption`) is `system`. A single keyword of one longhand
|
|
66
|
+
* (`bold`) is that longhand. Null for anything else.
|
|
67
|
+
* @param {string} value
|
|
68
|
+
* @returns {Record<string, string> | null}
|
|
69
|
+
*/
|
|
70
|
+
export function fontShorthandParts(value: string): Record<string, string> | null;
|
|
71
|
+
/**
|
|
72
|
+
* A grammar as text, cut at a whole term when it is long.
|
|
73
|
+
* @param {any} syntax
|
|
74
|
+
*/
|
|
75
|
+
export function grammarText(syntax: any): any;
|
|
76
|
+
/**
|
|
77
|
+
* Whether a property's grammar takes a percentage anywhere, through the
|
|
78
|
+
* types it names (padding does; border-width and outline-offset do not).
|
|
79
|
+
* @param {string} prop
|
|
80
|
+
*/
|
|
81
|
+
export function takesPercentage(prop: string): boolean;
|
|
82
|
+
export function propertyGrammar(prop: string): any | null;
|
|
83
|
+
/** The math functions, by name, for a check of whether a value holds one. */
|
|
84
|
+
export const MATH_FUNCTION: RegExp;
|