@astryxdesign/cli 0.7.14-canary.gfb823d9 → 0.7.14
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 +197 -0
- package/api/component/_adapter.d.mts +15 -0
- package/api/component/_adapter.mjs +76 -0
- package/api/component/component.mjs +8 -1
- package/api/search/_named-keywords.d.mts +31 -0
- package/api/search/_named-keywords.mjs +177 -0
- package/api/search/search-index.mjs +8 -1
- package/api/search/search.d.mts +6 -1
- package/api/search/search.mjs +49 -8
- package/api/theme/_adapter.d.mts +33 -0
- package/api/theme/_adapter.mjs +352 -16
- package/api/theme/build/build.mjs +261 -10
- package/api/theme/eject/eject.mjs +13 -1
- package/api/theme/list/list.mjs +11 -2
- package/api/theme/palette/generate/color.d.mts +2 -0
- package/api/theme/palette/generate/color.mjs +1 -1
- package/api/theme/template/template.mjs +139 -6
- package/api/theme/theme.type.d.mts +15 -1
- package/api/theme/theme.type.mjs +9 -3
- package/api/theme/themeAdd.doc.mjs +1 -1
- package/api/theme/themeBuild.doc.mjs +10 -2
- package/api/theme/themeEject.doc.mjs +2 -2
- package/api/theme/themeListAvailable.doc.mjs +1 -1
- package/api/theme/themeRemove.doc.mjs +1 -1
- package/api/theme/themeTemplate.doc.mjs +8 -0
- package/api/theme/themeUse.doc.mjs +1 -1
- package/api/theme-edit/_adapter.d.mts +36 -2
- package/api/theme-edit/_adapter.mjs +340 -12
- package/api/theme-edit/_check.d.mts +28 -25
- package/api/theme-edit/_check.mjs +876 -308
- package/api/theme-edit/_color.d.mts +53 -4
- package/api/theme-edit/_color.mjs +406 -79
- package/api/theme-edit/_compiler.d.mts +14 -6
- package/api/theme-edit/_compiler.mjs +89 -59
- package/api/theme-edit/_context.d.mts +28 -8
- package/api/theme-edit/_context.mjs +142 -19
- package/api/theme-edit/_edit.d.mts +3 -1
- package/api/theme-edit/_edit.mjs +746 -76
- package/api/theme-edit/_how-commands.d.mts +91 -0
- package/api/theme-edit/_how-commands.mjs +269 -0
- package/api/theme-edit/_how-question.d.mts +57 -0
- package/api/theme-edit/_how-question.mjs +2574 -0
- package/api/theme-edit/_how.d.mts +27 -8
- package/api/theme-edit/_how.mjs +776 -175
- package/api/theme-edit/_overview.d.mts +9 -0
- package/api/theme-edit/_overview.mjs +296 -0
- package/api/theme-edit/_palette.d.mts +155 -15
- package/api/theme-edit/_palette.mjs +1446 -262
- package/api/theme-edit/_parts.mjs +61 -5
- package/api/theme-edit/_png.d.mts +18 -6
- package/api/theme-edit/_png.mjs +135 -25
- package/api/theme-edit/_preview-app.d.mts +32 -11
- package/api/theme-edit/_preview-app.mjs +1976 -285
- package/api/theme-edit/_preview.d.mts +39 -8
- package/api/theme-edit/_preview.mjs +367 -41
- package/api/theme-edit/_settings.d.mts +147 -11
- package/api/theme-edit/_settings.mjs +908 -99
- package/api/theme-edit/_tables.d.mts +4 -16
- package/api/theme-edit/_tables.mjs +51 -117
- package/api/theme-edit/theme-edit.type.d.mts +102 -66
- package/api/theme-edit/theme-edit.type.mjs +58 -40
- package/api/theme-edit/themeEditHow.doc.mjs +17 -6
- package/api/theme-edit/themeEditNew.doc.mjs +21 -5
- package/api/theme-edit/themeEditPreviewAdd.doc.mjs +18 -5
- package/api/theme-edit/themeEditPreviewApp.doc.mjs +12 -9
- package/api/theme-edit/themeEditPreviewList.doc.mjs +11 -2
- package/api/theme-edit/themeEditPreviewRemove.doc.mjs +29 -3
- package/api/theme-edit/themeEditSet.doc.mjs +14 -8
- package/api/theme-edit/themeEditShow.doc.mjs +10 -5
- package/api/theme-edit/themeEditUndo.doc.mjs +9 -4
- package/assets/discover/official-packages.json +4 -0
- package/assets/docs/tree/icon-sets.doc.mjs +3 -3
- package/assets/docs.generated.json +1 -0
- package/assets/icons/definitions/bookmarkAdd.doc.mjs +9 -0
- package/assets/icons/definitions/documentSearch.doc.mjs +9 -0
- package/assets/icons/definitions/keyboard.doc.mjs +9 -0
- package/assets/icons/definitions/paintBrush.doc.mjs +9 -0
- package/assets/icons/definitions/wallet.doc.mjs +9 -0
- package/assets/preview-app/gitignore +3 -0
- package/assets/templates/blocks/components/ButtonGroup/ButtonGroupShowcase.doc.mjs +1 -1
- package/assets/templates/blocks/components/Lightbox/LightboxGallery.tsx +1 -1
- package/assets/templates/components.generated.json +1 -0
- package/assets/templates/pages/gallery-hero/page.tsx +8 -2
- package/assets/templates/pages/settings-dialog/template.doc.mjs +3 -3
- package/assets/templates/pages/side-gallery/page.tsx +1 -1
- package/assets/templates/pages/table-filter/template.doc.mjs +2 -2
- package/assets/templates/pages/theme-showcase/template.doc.mjs +1 -1
- package/clients/cli/bin/astryx.mjs +37 -5
- package/clients/cli/commands/experimental/theme.mjs +422 -57
- package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +22 -9
- package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +103 -4
- package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +13 -8
- package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +5 -5
- package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +5 -5
- package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-preview-add.doc.mjs +3 -2
- package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +2 -8
- package/clients/cli/commands/experimental-theme-preview-list.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-preview-remove.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-targets.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme.doc.mjs +3 -4
- package/clients/cli/commands/theme-build.doc.mjs +1 -1
- package/clients/cli/commands/theme-eject.doc.mjs +3 -3
- package/clients/cli/commands/theme-remove.doc.mjs +2 -2
- package/clients/cli/commands/theme-template.doc.mjs +11 -4
- package/clients/cli/commands/theme.mjs +145 -46
- package/clients/cli/commands.generated.json +1 -0
- package/clients/cli/index.mjs +96 -5
- package/clients/cli/lib/json-shim.mjs +29 -1
- package/foundation/config/project.d.mts +16 -2
- package/foundation/config/project.mjs +40 -6
- package/foundation/config/theme-state.d.mts +9 -0
- package/foundation/config/theme-state.mjs +20 -1
- package/foundation/discovery/template-adapter.d.mts +12 -1
- package/foundation/discovery/template-adapter.mjs +29 -4
- package/foundation/discovery/template-icons.d.mts +13 -0
- package/foundation/discovery/template-icons.mjs +76 -0
- package/foundation/discovery/template-needs.d.mts +7 -0
- package/foundation/discovery/template-needs.mjs +117 -8
- package/foundation/discovery/template-source-tree.d.mts +5 -1
- package/foundation/discovery/template-source-tree.mjs +6 -4
- package/foundation/discovery/theme-discovery.d.mts +14 -3
- package/foundation/discovery/theme-discovery.mjs +45 -12
- package/foundation/doc-compiler/import.mjs +68 -3
- package/foundation/doc-compiler/stored-docs.d.mts +27 -0
- package/foundation/doc-compiler/stored-docs.mjs +65 -0
- package/foundation/fs/fs-error.d.mts +17 -0
- package/foundation/fs/fs-error.mjs +34 -0
- package/foundation/response/error-codes.d.mts +3 -1
- package/foundation/response/error-codes.doc.mjs +13 -1
- package/foundation/response/error-codes.mjs +11 -1
- package/foundation/response/response-types.doc.mjs +6 -6
- package/package.json +6 -7
- package/clients/cli/commands/experimental-theme-palette-generate.doc.mjs +0 -73
- package/clients/cli/commands/experimental-theme-palette.doc.mjs +0 -37
|
@@ -3,11 +3,13 @@
|
|
|
3
3
|
|
|
4
4
|
/** @typedef {{token: string, props: string[], when: string[]}} Read */
|
|
5
5
|
/** @typedef {{message: string, run: string[], also: string[], soft?: boolean}} CheckFailure */
|
|
6
|
+
/** @typedef {import('./_parts.mjs').PartData} PartData */
|
|
7
|
+
/** @typedef {import('./_parts.mjs').TextPair} TextPair */
|
|
6
8
|
/**
|
|
7
9
|
* @param {import('./_project.mjs').ThemeProject} project
|
|
8
|
-
* @param {
|
|
10
|
+
* @param {PartData} parts
|
|
9
11
|
*/
|
|
10
|
-
export function makeCompiler(project: import("./_project.mjs").ThemeProject, parts:
|
|
12
|
+
export function makeCompiler(project: import("./_project.mjs").ThemeProject, parts: PartData): {
|
|
11
13
|
MAP: Record<string, import("./_parts.mjs").PartRecord>;
|
|
12
14
|
typeOf: (tok: string) => string;
|
|
13
15
|
feeds: (target: string, token: string) => Array<{
|
|
@@ -19,7 +21,7 @@ export function makeCompiler(project: import("./_project.mjs").ThemeProject, par
|
|
|
19
21
|
part: string;
|
|
20
22
|
prop: string;
|
|
21
23
|
when: string;
|
|
22
|
-
}
|
|
24
|
+
}>>, target?: string) => string;
|
|
23
25
|
showsCorners: (target: string) => boolean;
|
|
24
26
|
groupOfToken: (t: string) => string | null;
|
|
25
27
|
groupOfProp: (p: string) => string | null;
|
|
@@ -29,11 +31,14 @@ export function makeCompiler(project: import("./_project.mjs").ThemeProject, par
|
|
|
29
31
|
allReads: (target: string) => Set<string>;
|
|
30
32
|
anyReader: (tok: string) => string[];
|
|
31
33
|
checkTokenOn: (theme: string, target: string, token: string, value: string, P: string) => CheckFailure | null;
|
|
32
|
-
checkTokenGlobal: (token: string,
|
|
34
|
+
checkTokenGlobal: (token: string, _P: string) => CheckFailure | null;
|
|
33
35
|
variantValues: (target: string) => Record<string, string[]>;
|
|
34
|
-
contrast: (value: (pair:
|
|
35
|
-
parseColor: (v: unknown) => number
|
|
36
|
+
contrast: (value: (pair: TextPair, side: "fg" | "bg", mode: string) => string | null | undefined, baseValue: (pair: TextPair, side: "fg" | "bg", mode: string) => string | null | undefined, modes: string[], { parseColor, ratio, alphaOf, compositeOver, page }: {
|
|
37
|
+
parseColor: (v: unknown) => [number, number, number] | null;
|
|
36
38
|
ratio: (a: number[], b: number[]) => number;
|
|
39
|
+
alphaOf: (v: unknown) => number;
|
|
40
|
+
compositeOver: (over: [number, number, number], alpha: number, under: [number, number, number]) => [number, number, number];
|
|
41
|
+
page: (mode: string) => string | null | undefined;
|
|
37
42
|
}) => {
|
|
38
43
|
problems: {
|
|
39
44
|
part: string;
|
|
@@ -44,6 +49,7 @@ export function makeCompiler(project: import("./_project.mjs").ThemeProject, par
|
|
|
44
49
|
bgPart: string | null;
|
|
45
50
|
bg: string;
|
|
46
51
|
}[];
|
|
52
|
+
more: number;
|
|
47
53
|
unchecked: string[];
|
|
48
54
|
};
|
|
49
55
|
};
|
|
@@ -60,4 +66,6 @@ export type CheckFailure = {
|
|
|
60
66
|
also: string[];
|
|
61
67
|
soft?: boolean;
|
|
62
68
|
};
|
|
69
|
+
export type PartData = import("./_parts.mjs").PartData;
|
|
70
|
+
export type TextPair = import("./_parts.mjs").TextPair;
|
|
63
71
|
export type Compiler = ReturnType<typeof makeCompiler>;
|
|
@@ -11,33 +11,26 @@
|
|
|
11
11
|
|
|
12
12
|
import {DIRECT, GROUPS, HOW} from './_tables.mjs';
|
|
13
13
|
|
|
14
|
-
/**
|
|
15
|
-
* Whether a color is see-through: its contrast depends on what is under it,
|
|
16
|
-
* so it is not judged alone.
|
|
17
|
-
* @param {unknown} v
|
|
18
|
-
*/
|
|
19
|
-
function hasAlpha(v) {
|
|
20
|
-
const s = String(v ?? '').trim();
|
|
21
|
-
const h = /^#(?:[0-9a-f]{4}|[0-9a-f]{8})$/i.exec(s);
|
|
22
|
-
if (h) return s.length === 5 ? !/f$/i.test(s) : !/ff$/i.test(s);
|
|
23
|
-
const m = /\/\s*([\d.]+%?)\s*\)$|^rgba\([^)]*,\s*([\d.]+)\s*\)$/i.exec(s);
|
|
24
|
-
if (!m) return /^transparent$/i.test(s);
|
|
25
|
-
const a = m[1] ?? m[2];
|
|
26
|
-
return a.endsWith('%') ? parseFloat(a) < 100 : parseFloat(a) < 1;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
14
|
/** Only these token types may differ between light and dark. */
|
|
30
15
|
export const MODAL = new Set(['color', 'shadow']);
|
|
31
16
|
|
|
32
17
|
/** Tokens a component may read only in some states: never refused globally. */
|
|
33
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Tokens no catalog part is recorded reading, though Core reads them: code
|
|
20
|
+
* highlighting, the display text sizes and the colored icons read them only
|
|
21
|
+
* under a variant or in a global stylesheet. Never refused as unread.
|
|
22
|
+
*/
|
|
23
|
+
const SOFT =
|
|
24
|
+
/^--(color-data|color-syntax|syntax|duration|ease|z-|layer|breakpoint|text-display-\d|color-icon-[a-z]+$)/;
|
|
34
25
|
|
|
35
26
|
/** @typedef {{token: string, props: string[], when: string[]}} Read */
|
|
36
27
|
/** @typedef {{message: string, run: string[], also: string[], soft?: boolean}} CheckFailure */
|
|
28
|
+
/** @typedef {import('./_parts.mjs').PartData} PartData */
|
|
29
|
+
/** @typedef {import('./_parts.mjs').TextPair} TextPair */
|
|
37
30
|
|
|
38
31
|
/**
|
|
39
32
|
* @param {import('./_project.mjs').ThemeProject} project
|
|
40
|
-
* @param {
|
|
33
|
+
* @param {PartData} parts
|
|
41
34
|
*/
|
|
42
35
|
export function makeCompiler(project, parts) {
|
|
43
36
|
const {core} = project;
|
|
@@ -69,7 +62,7 @@ export function makeCompiler(project, parts) {
|
|
|
69
62
|
if (TYPE[k]) continue;
|
|
70
63
|
if (/^--color-|^--syntax-/.test(k)) TYPE[k] = 'color';
|
|
71
64
|
else if (/^--font-family/.test(k)) TYPE[k] = 'font';
|
|
72
|
-
else if (/^--font-weight
|
|
65
|
+
else if (/^--font-weight|^--text-.*-weight$/.test(k)) TYPE[k] = 'number';
|
|
73
66
|
else if (/^--shadow/.test(k)) TYPE[k] = 'shadow';
|
|
74
67
|
else if (/^--focus-outline-color/.test(k)) TYPE[k] = 'color';
|
|
75
68
|
else if (
|
|
@@ -219,13 +212,18 @@ export function makeCompiler(project, parts) {
|
|
|
219
212
|
return out;
|
|
220
213
|
}
|
|
221
214
|
|
|
222
|
-
/**
|
|
223
|
-
|
|
215
|
+
/**
|
|
216
|
+
* One line for where a token feeds. A part inside `target` (a button in a
|
|
217
|
+
* toast) is named as inside it, so the line never reads as every button.
|
|
218
|
+
* @param {ReturnType<typeof feeds>} list
|
|
219
|
+
* @param {string} [target]
|
|
220
|
+
*/
|
|
221
|
+
const fmtFeeds = (list, target) =>
|
|
224
222
|
[
|
|
225
223
|
...new Set(
|
|
226
224
|
list.map(
|
|
227
225
|
f =>
|
|
228
|
-
`${f.prop}${f.part ? ` on ${f.part}` : ''}${f.when ? ` (when ${f.when})` : ''}`,
|
|
226
|
+
`${f.prop}${f.part ? ` on ${f.part}${target && f.part !== target ? ` inside ${target}` : ''}` : ''}${f.when ? ` (when ${f.when})` : ''}`,
|
|
229
227
|
),
|
|
230
228
|
),
|
|
231
229
|
]
|
|
@@ -266,17 +264,11 @@ export function makeCompiler(project, parts) {
|
|
|
266
264
|
: g === 'background'
|
|
267
265
|
? ['background-color', 'background', 'background-image']
|
|
268
266
|
: null;
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
run: [
|
|
275
|
-
`${P} set ${theme} ${direct} ${quote(value)} --on ${target} # sets its ${g} directly`,
|
|
276
|
-
`${HOW} ${target}`,
|
|
277
|
-
],
|
|
278
|
-
also: [],
|
|
279
|
-
};
|
|
267
|
+
// The part reads the token the user named: it is set as asked, and
|
|
268
|
+
// the result names what it feeds.
|
|
269
|
+
void wanted;
|
|
270
|
+
void fed;
|
|
271
|
+
return null;
|
|
280
272
|
}
|
|
281
273
|
const reads = g ? partReads(target, g) : [];
|
|
282
274
|
const v = quote(value);
|
|
@@ -291,9 +283,23 @@ export function makeCompiler(project, parts) {
|
|
|
291
283
|
`${P} set ${theme} ${r.token} ${v} --on ${target}${fmtWhen(r.when) ? ` #${fmtWhen(r.when)}` : ''}`,
|
|
292
284
|
),
|
|
293
285
|
);
|
|
294
|
-
|
|
286
|
+
// The property that takes this kind of value: a size goes to
|
|
287
|
+
// font-size, never to font-weight.
|
|
288
|
+
const direct =
|
|
289
|
+
g === 'font'
|
|
290
|
+
? /-(size)$|font-size-/.test(token)
|
|
291
|
+
? 'font-size'
|
|
292
|
+
: /-leading$/.test(token)
|
|
293
|
+
? 'line-height'
|
|
294
|
+
: /-tracking$/.test(token)
|
|
295
|
+
? 'letter-spacing'
|
|
296
|
+
: /family/.test(token)
|
|
297
|
+
? 'font-family'
|
|
298
|
+
: 'font-weight'
|
|
299
|
+
: g && DIRECT[g];
|
|
300
|
+
if (direct)
|
|
295
301
|
run.push(
|
|
296
|
-
`${P} set ${theme} ${
|
|
302
|
+
`${P} set ${theme} ${direct} ${v} --on ${target} # sets it directly, whatever token it uses`,
|
|
297
303
|
);
|
|
298
304
|
const kids = g
|
|
299
305
|
? (MAP[target]?.contains ?? [])
|
|
@@ -326,10 +332,10 @@ export function makeCompiler(project, parts) {
|
|
|
326
332
|
/**
|
|
327
333
|
* Whether a whole-theme token is read by any part.
|
|
328
334
|
* @param {string} token
|
|
329
|
-
* @param {string}
|
|
335
|
+
* @param {string} _P the command prefix (unused: the result is a note)
|
|
330
336
|
* @returns {CheckFailure | null}
|
|
331
337
|
*/
|
|
332
|
-
function checkTokenGlobal(token,
|
|
338
|
+
function checkTokenGlobal(token, _P) {
|
|
333
339
|
if (anyReader(token).length || SOFT.test(token)) return null;
|
|
334
340
|
const g = groupOfToken(token);
|
|
335
341
|
const near = g
|
|
@@ -340,15 +346,8 @@ export function makeCompiler(project, parts) {
|
|
|
340
346
|
: [];
|
|
341
347
|
return {
|
|
342
348
|
message: `No component reads ${token}, so setting it changes nothing.${near.length ? ` Tokens components do read for ${g}: ${near.join(', ')}.` : ''}`,
|
|
343
|
-
run:
|
|
344
|
-
|
|
345
|
-
: [`${HOW} "<what you want>"`],
|
|
346
|
-
also:
|
|
347
|
-
g === 'shadow'
|
|
348
|
-
? [
|
|
349
|
-
`shadows are set per part: ${P} set <theme> box-shadow "0 2px 6px rgb(0 0 0 / 0.3)" --on card`,
|
|
350
|
-
]
|
|
351
|
-
: [],
|
|
349
|
+
run: [`${HOW} ${quote(token)}`],
|
|
350
|
+
also: [],
|
|
352
351
|
};
|
|
353
352
|
}
|
|
354
353
|
|
|
@@ -378,12 +377,37 @@ export function makeCompiler(project, parts) {
|
|
|
378
377
|
* in each mode, below 4.5:1 now but not as low in the base theme. Also
|
|
379
378
|
* the values this theme set that have no fixed color to check (a
|
|
380
379
|
* `color-mix()`, a `var()`), so the result can say what it skipped.
|
|
381
|
-
* @param {(pair:
|
|
382
|
-
* @param {(pair:
|
|
380
|
+
* @param {(pair: TextPair, side: 'fg' | 'bg', mode: string) => string | null | undefined} value
|
|
381
|
+
* @param {(pair: TextPair, side: 'fg' | 'bg', mode: string) => string | null | undefined} baseValue
|
|
383
382
|
* @param {string[]} modes
|
|
384
|
-
* @param {{parseColor: (v: unknown) => number
|
|
383
|
+
* @param {{parseColor: (v: unknown) => [number, number, number] | null, ratio: (a: number[], b: number[]) => number, alphaOf: (v: unknown) => number, compositeOver: (over: [number, number, number], alpha: number, under: [number, number, number]) => [number, number, number], page: (mode: string) => string | null | undefined}} helpers
|
|
384
|
+
* `page` is the page color in a mode: a see-through background is drawn
|
|
385
|
+
* over it, and see-through text over that background, before measuring.
|
|
385
386
|
*/
|
|
386
|
-
function contrast(
|
|
387
|
+
function contrast(
|
|
388
|
+
value,
|
|
389
|
+
baseValue,
|
|
390
|
+
modes,
|
|
391
|
+
{parseColor, ratio, alphaOf, compositeOver, page},
|
|
392
|
+
) {
|
|
393
|
+
/**
|
|
394
|
+
* The opaque colors the eye sees for a pair, or null with no fixed color.
|
|
395
|
+
* @param {unknown} fg @param {unknown} bg @param {string} m
|
|
396
|
+
*/
|
|
397
|
+
const drawn = (fg, bg, m) => {
|
|
398
|
+
/** @type {[number, number, number]} */
|
|
399
|
+
const ground =
|
|
400
|
+
parseColor(page(m)) ?? (m === 'dark' ? [0, 0, 0] : [255, 255, 255]);
|
|
401
|
+
const bgAlpha = alphaOf(bg);
|
|
402
|
+
const back = parseColor(bg);
|
|
403
|
+
const under =
|
|
404
|
+
bgAlpha === 0
|
|
405
|
+
? ground
|
|
406
|
+
: back && compositeOver(back, bgAlpha, ground);
|
|
407
|
+
const top = parseColor(fg);
|
|
408
|
+
if (!under || !top) return null;
|
|
409
|
+
return [compositeOver(top, alphaOf(fg), under), under];
|
|
410
|
+
};
|
|
387
411
|
/** @type {Array<{part: string, mode: string, ratio: number, sample: string, fg: string, bgPart: string | null, bg: string}>} */
|
|
388
412
|
const out = [];
|
|
389
413
|
const seen = new Set();
|
|
@@ -400,23 +424,25 @@ export function makeCompiler(project, parts) {
|
|
|
400
424
|
const fg = value(p, 'fg', m);
|
|
401
425
|
const bg = value(p, 'bg', m);
|
|
402
426
|
if (/gradient|url\(/.test(String(bg))) continue;
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
const b = parseColor(bg);
|
|
406
|
-
if (!a || !b) {
|
|
427
|
+
const pair = drawn(fg, bg, m);
|
|
428
|
+
if (!pair) {
|
|
407
429
|
for (const [v, side] of /** @type {const} */ ([
|
|
408
430
|
[fg, 'fg'],
|
|
409
431
|
[bg, 'bg'],
|
|
410
432
|
]))
|
|
411
|
-
if (
|
|
433
|
+
if (
|
|
434
|
+
v &&
|
|
435
|
+
!parseColor(v) &&
|
|
436
|
+
alphaOf(v) !== 0 &&
|
|
437
|
+
v !== baseValue(p, side, m)
|
|
438
|
+
)
|
|
412
439
|
unchecked.add(String(v));
|
|
413
440
|
continue;
|
|
414
441
|
}
|
|
415
|
-
const r = ratio(
|
|
442
|
+
const r = ratio(pair[0], pair[1]);
|
|
416
443
|
if (r >= 4.5) continue;
|
|
417
|
-
const
|
|
418
|
-
|
|
419
|
-
if (a0 && b0 && ratio(a0, b0) <= r + 0.05) continue;
|
|
444
|
+
const was = drawn(baseValue(p, 'fg', m), baseValue(p, 'bg', m), m);
|
|
445
|
+
if (was && ratio(was[0], was[1]) <= r + 0.05) continue;
|
|
420
446
|
const key = `${p.text}|${fg}|${bg}|${m}`;
|
|
421
447
|
if (seen.has(key)) continue;
|
|
422
448
|
seen.add(key);
|
|
@@ -431,7 +457,11 @@ export function makeCompiler(project, parts) {
|
|
|
431
457
|
});
|
|
432
458
|
}
|
|
433
459
|
}
|
|
434
|
-
return {
|
|
460
|
+
return {
|
|
461
|
+
problems: out.slice(0, 8),
|
|
462
|
+
more: Math.max(0, out.length - 8),
|
|
463
|
+
unchecked: [...unchecked],
|
|
464
|
+
};
|
|
435
465
|
}
|
|
436
466
|
|
|
437
467
|
/**
|
|
@@ -7,7 +7,12 @@
|
|
|
7
7
|
* @param {string} cwd
|
|
8
8
|
*/
|
|
9
9
|
export function requireProject(cwd: string): void;
|
|
10
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* The project, its part data and the compiler. When the components cannot
|
|
12
|
+
* be rendered, the part data is empty and `unchecked` says why: changes are
|
|
13
|
+
* then saved without the checks that need it, and say so.
|
|
14
|
+
* @param {string} cwd
|
|
15
|
+
*/
|
|
11
16
|
export function context(cwd: string): Promise<{
|
|
12
17
|
project: import("./_project.mjs").ThemeProject;
|
|
13
18
|
C: {
|
|
@@ -22,7 +27,7 @@ export function context(cwd: string): Promise<{
|
|
|
22
27
|
part: string;
|
|
23
28
|
prop: string;
|
|
24
29
|
when: string;
|
|
25
|
-
}
|
|
30
|
+
}>>, target?: string) => string;
|
|
26
31
|
showsCorners: (target: string) => boolean;
|
|
27
32
|
groupOfToken: (t: string) => string | null;
|
|
28
33
|
groupOfProp: (p: string) => string | null;
|
|
@@ -32,11 +37,14 @@ export function context(cwd: string): Promise<{
|
|
|
32
37
|
allReads: (target: string) => Set<string>;
|
|
33
38
|
anyReader: (tok: string) => string[];
|
|
34
39
|
checkTokenOn: (theme: string, target: string, token: string, value: string, P: string) => CheckFailure | null;
|
|
35
|
-
checkTokenGlobal: (token: string,
|
|
40
|
+
checkTokenGlobal: (token: string, _P: string) => CheckFailure | null;
|
|
36
41
|
variantValues: (target: string) => Record<string, string[]>;
|
|
37
|
-
contrast: (value: (pair:
|
|
38
|
-
parseColor: (v: unknown) => number
|
|
42
|
+
contrast: (value: (pair: TextPair, side: "fg" | "bg", mode: string) => string | null | undefined, baseValue: (pair: TextPair, side: "fg" | "bg", mode: string) => string | null | undefined, modes: string[], { parseColor, ratio, alphaOf, compositeOver, page }: {
|
|
43
|
+
parseColor: (v: unknown) => [number, number, number] | null;
|
|
39
44
|
ratio: (a: number[], b: number[]) => number;
|
|
45
|
+
alphaOf: (v: unknown) => number;
|
|
46
|
+
compositeOver: (over: [number, number, number], alpha: number, under: [number, number, number]) => [number, number, number];
|
|
47
|
+
page: (mode: string) => string | null | undefined;
|
|
40
48
|
}) => {
|
|
41
49
|
problems: {
|
|
42
50
|
part: string;
|
|
@@ -47,10 +55,12 @@ export function context(cwd: string): Promise<{
|
|
|
47
55
|
bgPart: string | null;
|
|
48
56
|
bg: string;
|
|
49
57
|
}[];
|
|
58
|
+
more: number;
|
|
50
59
|
unchecked: string[];
|
|
51
60
|
};
|
|
52
61
|
};
|
|
53
62
|
parts: import("./_parts.mjs").PartData;
|
|
63
|
+
unchecked: string | null;
|
|
54
64
|
}>;
|
|
55
65
|
/**
|
|
56
66
|
* Pictures of HTML files, on request.
|
|
@@ -90,9 +100,19 @@ export function styledChanges(before: any, after: any): string[];
|
|
|
90
100
|
* @param {boolean} png
|
|
91
101
|
*/
|
|
92
102
|
export function previewAfter(ctx: import("./_settings.mjs").Ctx, slug: string, data: import("./_settings.mjs").ThemeData, png: boolean): Promise<{
|
|
93
|
-
preview: string;
|
|
103
|
+
preview: string | null;
|
|
94
104
|
pictures: string[];
|
|
95
105
|
pictureProblem: string | null;
|
|
106
|
+
notChecked: {
|
|
107
|
+
code: import("../../foundation/response/error-codes.mjs").ErrorCode;
|
|
108
|
+
cause: string;
|
|
109
|
+
} | null;
|
|
96
110
|
}>;
|
|
97
|
-
/**
|
|
98
|
-
|
|
111
|
+
/**
|
|
112
|
+
* The section of the sheet, in lower case, or undefined; a refusal for one
|
|
113
|
+
* that is not a section.
|
|
114
|
+
* @param {string | undefined} section
|
|
115
|
+
* @param {string} [theme] the theme the suggestions name
|
|
116
|
+
* @returns {string | undefined}
|
|
117
|
+
*/
|
|
118
|
+
export function checkSection(section: string | undefined, theme?: string): string | undefined;
|
|
@@ -8,6 +8,9 @@
|
|
|
8
8
|
* @position api/theme-edit — imported only by the adapter's operation helpers
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
+
import * as fs from 'node:fs';
|
|
12
|
+
import {createRequire} from 'node:module';
|
|
13
|
+
import * as path from 'node:path';
|
|
11
14
|
import {AstryxError} from '../error.mjs';
|
|
12
15
|
import {isOutsideProject} from '../../foundation/env/project-scope.mjs';
|
|
13
16
|
import {CLOSEST_OPEN_FONT, OPEN_FONTS, P, SYSTEM_FONTS} from './_tables.mjs';
|
|
@@ -34,6 +37,21 @@ const E = ERROR_CODES;
|
|
|
34
37
|
*/
|
|
35
38
|
export function requireProject(cwd) {
|
|
36
39
|
if (!isOutsideProject(cwd)) return;
|
|
40
|
+
const pkg = path.join(cwd, 'package.json');
|
|
41
|
+
// Yarn Plug'n'Play has no node_modules for the editor to read Core from.
|
|
42
|
+
if (fs.existsSync(path.join(cwd, '.pnp.cjs')))
|
|
43
|
+
throw new AstryxError(
|
|
44
|
+
"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
|
+
[],
|
|
46
|
+
E.ERR_PROJECT_REQUIRED,
|
|
47
|
+
);
|
|
48
|
+
// A package.json with no Core: an app (or a workspace root) that needs it.
|
|
49
|
+
if (fs.existsSync(pkg))
|
|
50
|
+
throw new AstryxError(
|
|
51
|
+
`@astryxdesign/core is not installed in this app (package.json here does not use it). astryx experimental theme checks every change against the installed Core: install it, or run the command from the package that uses it. Nothing was written.`,
|
|
52
|
+
[{name: 'npm install @astryxdesign/core', reason: 'do this first'}],
|
|
53
|
+
E.ERR_PROJECT_REQUIRED,
|
|
54
|
+
);
|
|
37
55
|
throw new AstryxError(
|
|
38
56
|
'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.',
|
|
39
57
|
[],
|
|
@@ -41,14 +59,79 @@ export function requireProject(cwd) {
|
|
|
41
59
|
);
|
|
42
60
|
}
|
|
43
61
|
|
|
44
|
-
/**
|
|
62
|
+
/**
|
|
63
|
+
* The project, its part data and the compiler. When the components cannot
|
|
64
|
+
* be rendered, the part data is empty and `unchecked` says why: changes are
|
|
65
|
+
* then saved without the checks that need it, and say so.
|
|
66
|
+
* @param {string} cwd
|
|
67
|
+
*/
|
|
45
68
|
export async function context(cwd) {
|
|
46
69
|
requireProject(cwd);
|
|
47
70
|
const project = await openProject(cwd);
|
|
48
|
-
|
|
49
|
-
|
|
71
|
+
/** @type {import('./_parts.mjs').PartData} */
|
|
72
|
+
let parts;
|
|
73
|
+
/** @type {string | null} */
|
|
74
|
+
let unchecked = null;
|
|
75
|
+
try {
|
|
76
|
+
parts = await partData(project);
|
|
77
|
+
} catch (e) {
|
|
78
|
+
if (!isRenderFailure(e)) throw e;
|
|
79
|
+
unchecked = renderCause(project, /** @type {Error} */ (e).message);
|
|
80
|
+
parts = {
|
|
81
|
+
version: 0,
|
|
82
|
+
coreKey: project.coreKey,
|
|
83
|
+
map: {},
|
|
84
|
+
pairs: [],
|
|
85
|
+
rendered: 0,
|
|
86
|
+
items: 0,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
return {project, C: makeCompiler(project, parts), parts, unchecked};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** @param {unknown} e */
|
|
93
|
+
const isRenderFailure = e =>
|
|
94
|
+
e instanceof AstryxError &&
|
|
95
|
+
(e.code === E.ERR_RENDER_FAILED ||
|
|
96
|
+
e.code === E.ERR_RENDER_MISSING_DEPENDENCY);
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Why the components did not render, with the likely cause: two copies of
|
|
100
|
+
* React (the app's and the one Core resolves) break every hook.
|
|
101
|
+
* @param {import('./_project.mjs').ThemeProject} project
|
|
102
|
+
* @param {string} message
|
|
103
|
+
*/
|
|
104
|
+
function renderCause(project, message) {
|
|
105
|
+
/** @param {(id: string) => string} resolve */
|
|
106
|
+
const reactOf = resolve => {
|
|
107
|
+
try {
|
|
108
|
+
return fs.realpathSync(path.dirname(resolve('react/package.json')));
|
|
109
|
+
} catch {
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
const app = reactOf(project.req.resolve);
|
|
114
|
+
let core = null;
|
|
115
|
+
try {
|
|
116
|
+
core = reactOf(
|
|
117
|
+
createRequire(project.req.resolve('@astryxdesign/core/package.json'))
|
|
118
|
+
.resolve,
|
|
119
|
+
);
|
|
120
|
+
} catch {
|
|
121
|
+
// No Core package file: nothing to compare.
|
|
122
|
+
}
|
|
123
|
+
return app && core && app !== core
|
|
124
|
+
? `${message} The likely cause: two copies of React, the app's (${app}) and the one Core resolves (${core}). Make Core resolve the app's React.`
|
|
125
|
+
: message;
|
|
50
126
|
}
|
|
51
127
|
|
|
128
|
+
/**
|
|
129
|
+
* The "saved, not checked" report of a change, or null when it was checked.
|
|
130
|
+
* @param {string | null} cause
|
|
131
|
+
*/
|
|
132
|
+
const notChecked = cause =>
|
|
133
|
+
cause ? {code: E.ERR_THEME_NOT_CHECKED, cause} : null;
|
|
134
|
+
|
|
52
135
|
/**
|
|
53
136
|
* Pictures of HTML files, on request.
|
|
54
137
|
* @param {import('./_project.mjs').ThemeProject} project
|
|
@@ -85,10 +168,17 @@ export function fontNotes(ctx, data) {
|
|
|
85
168
|
/** @type {string[]} */
|
|
86
169
|
const notes = [];
|
|
87
170
|
for (const {pkg, family, installed} of fontPackages(ctx, data)) {
|
|
171
|
+
const fallbacks =
|
|
172
|
+
Object.values(OPEN_FONTS).find(f => f.pkg === pkg)?.fallbacks ?? '';
|
|
173
|
+
const near = /monospace/.test(fallbacks)
|
|
174
|
+
? 'mono'
|
|
175
|
+
: /serif/.test(fallbacks.replace('sans-serif', ''))
|
|
176
|
+
? 'serif'
|
|
177
|
+
: 'system';
|
|
88
178
|
notes.push(
|
|
89
179
|
installed
|
|
90
|
-
?
|
|
91
|
-
: `${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}'
|
|
180
|
+
? `${family} is installed (${pkg}), so the previews load it; the app loads it with one import: import '${pkg}';`
|
|
181
|
+
: `${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}`,
|
|
92
182
|
);
|
|
93
183
|
}
|
|
94
184
|
for (const s of data.settings) {
|
|
@@ -177,24 +267,57 @@ export function styledChanges(before, after) {
|
|
|
177
267
|
* @param {boolean} png
|
|
178
268
|
*/
|
|
179
269
|
export async function previewAfter(ctx, slug, data, png) {
|
|
180
|
-
|
|
270
|
+
/** @type {string | null} */
|
|
271
|
+
let preview = null;
|
|
272
|
+
let cause = ctx.unchecked ?? null;
|
|
273
|
+
try {
|
|
274
|
+
preview = await renderPreview(ctx, slug, data);
|
|
275
|
+
} catch (e) {
|
|
276
|
+
// The change is already saved: any failure here leaves it unchecked.
|
|
277
|
+
cause ??= isRenderFailure(e)
|
|
278
|
+
? renderCause(ctx.project, /** @type {Error} */ (e).message)
|
|
279
|
+
: `checking it failed: ${e instanceof Error ? e.message : String(e)}`;
|
|
280
|
+
}
|
|
181
281
|
const f = themeFiles(ctx.project.cwd, slug);
|
|
182
|
-
const shots =
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
282
|
+
const shots =
|
|
283
|
+
png && preview
|
|
284
|
+
? await pictures(
|
|
285
|
+
ctx.project,
|
|
286
|
+
[{html: f.preview, png: f.previewPng}],
|
|
287
|
+
modesOf(data),
|
|
288
|
+
)
|
|
289
|
+
: {files: [], problem: null};
|
|
290
|
+
return {
|
|
291
|
+
preview,
|
|
292
|
+
pictures: shots.files,
|
|
293
|
+
pictureProblem: shots.problem,
|
|
294
|
+
notChecked: notChecked(cause),
|
|
295
|
+
};
|
|
190
296
|
}
|
|
191
297
|
|
|
192
|
-
/**
|
|
193
|
-
|
|
194
|
-
|
|
298
|
+
/**
|
|
299
|
+
* The section of the sheet, in lower case, or undefined; a refusal for one
|
|
300
|
+
* that is not a section.
|
|
301
|
+
* @param {string | undefined} section
|
|
302
|
+
* @param {string} [theme] the theme the suggestions name
|
|
303
|
+
* @returns {string | undefined}
|
|
304
|
+
*/
|
|
305
|
+
export function checkSection(section, theme = 'my') {
|
|
306
|
+
if (section === '')
|
|
307
|
+
refuse(E.ERR_MISSING_ARGUMENT, '--section was given no value.', {
|
|
308
|
+
run: [`${P} show ${theme} --section ${SHOWCASE_GROUPS[0]}`],
|
|
309
|
+
});
|
|
310
|
+
const s = section?.toLowerCase();
|
|
311
|
+
if (s != null && !SHOWCASE_GROUPS.includes(s))
|
|
195
312
|
refuse(
|
|
196
313
|
E.ERR_INVALID_ARGUMENT,
|
|
197
|
-
`--
|
|
198
|
-
{
|
|
314
|
+
`--section takes ${SHOWCASE_GROUPS.join(', ')}, not "${section}".`,
|
|
315
|
+
{
|
|
316
|
+
didYouMean: nearest(s, SHOWCASE_GROUPS),
|
|
317
|
+
run: [
|
|
318
|
+
`${P} show ${theme} --section ${nearest(s, SHOWCASE_GROUPS)[0] ?? SHOWCASE_GROUPS[0]}`,
|
|
319
|
+
],
|
|
320
|
+
},
|
|
199
321
|
);
|
|
322
|
+
return s;
|
|
200
323
|
}
|
|
@@ -5,7 +5,9 @@
|
|
|
5
5
|
* @typedef {import('./theme-edit.type.mjs').ThemeEditChangeOptions} ChangeOptions
|
|
6
6
|
*/
|
|
7
7
|
/**
|
|
8
|
-
* Start a theme in themes/<name>/, optionally on a built-in theme
|
|
8
|
+
* Start a theme in themes/<name>/, optionally on a built-in theme, with any
|
|
9
|
+
* dial settings applied in the same build. Each setting is checked as `set`
|
|
10
|
+
* checks it, before anything is written.
|
|
9
11
|
* @experimental
|
|
10
12
|
* @param {string} name
|
|
11
13
|
* @param {import('./theme-edit.type.mjs').ThemeEditNewOptions} [options]
|