@astryxdesign/cli 0.7.15-canary.gf890983 → 0.7.15
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 +353 -3
- package/api/doctor/_adapter.d.mts +2 -1
- package/api/doctor/_adapter.mjs +6 -1
- package/api/doctor/doctor.mjs +2 -2
- 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/theme/_adapter.d.mts +37 -5
- package/api/theme/_adapter.mjs +363 -50
- package/api/theme/_fork.d.mts +90 -0
- package/api/theme/_fork.mjs +246 -0
- package/api/theme/build/build.d.mts +25 -1
- package/api/theme/build/build.mjs +352 -41
- 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.mjs +10 -3
- 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 +2 -2
- package/api/theme/themeRemove.doc.mjs +5 -2
- package/api/theme/themeTemplate.doc.mjs +2 -2
- package/api/theme/themeUse.doc.mjs +8 -2
- package/api/theme-edit/_adapter.mjs +157 -36
- package/api/theme-edit/_catalog.d.mts +1 -6
- package/api/theme-edit/_catalog.mjs +5 -268
- package/api/theme-edit/_check.d.mts +3 -1
- package/api/theme-edit/_check.mjs +733 -308
- package/api/theme-edit/_color.d.mts +19 -0
- package/api/theme-edit/_color.mjs +277 -33
- package/api/theme-edit/_compiler.d.mts +1 -0
- package/api/theme-edit/_compiler.mjs +25 -0
- package/api/theme-edit/_context.d.mts +2 -0
- package/api/theme-edit/_context.mjs +83 -9
- package/api/theme-edit/_css.d.mts +84 -0
- package/api/theme-edit/_css.mjs +700 -0
- package/api/theme-edit/_edit.mjs +370 -85
- package/api/theme-edit/_how-commands.d.mts +5 -0
- package/api/theme-edit/_how-commands.mjs +20 -13
- package/api/theme-edit/_how-question.d.mts +29 -0
- package/api/theme-edit/_how-question.mjs +1573 -182
- package/api/theme-edit/_how.mjs +306 -22
- package/api/theme-edit/_overview.mjs +2 -7
- package/api/theme-edit/_palette.d.mts +27 -5
- package/api/theme-edit/_palette.mjs +231 -97
- package/api/theme-edit/_parts.d.mts +42 -10
- package/api/theme-edit/_parts.mjs +224 -69
- package/api/theme-edit/_preview-app.d.mts +8 -0
- package/api/theme-edit/_preview-app.mjs +549 -96
- package/api/theme-edit/_preview.d.mts +7 -16
- package/api/theme-edit/_preview.mjs +77 -84
- package/api/theme-edit/_project.d.mts +20 -1
- package/api/theme-edit/_project.mjs +43 -13
- package/api/theme-edit/_settings.d.mts +96 -20
- package/api/theme-edit/_settings.mjs +646 -141
- package/api/theme-edit/_tables.d.mts +18 -12
- package/api/theme-edit/_tables.mjs +144 -147
- package/api/theme-edit/theme-edit.type.d.mts +10 -1
- package/api/theme-edit/theme-edit.type.mjs +3 -1
- 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/themeEditSet.doc.mjs +1 -1
- package/api/theme-edit/themeEditUndo.doc.mjs +1 -1
- package/assets/docs/tree/publishing.doc.mjs +1 -0
- package/assets/docs.generated.json +2 -2
- package/assets/self-audit.generated.json +1 -1
- package/clients/cli/build-id.generated.json +1 -1
- package/clients/cli/commands/experimental/index.mjs +10 -10
- package/clients/cli/commands/experimental/theme.mjs +22 -3
- package/clients/cli/commands/experimental-theme-compile.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor-new.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/integration.mjs +8 -0
- 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 +325 -48
- package/clients/cli/index.mjs +18 -3
- package/clients/cli/lib/cli-error.mjs +118 -3
- package/clients/cli/manifest.generated.json +1 -1
- 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/template-needs.d.mts +13 -0
- package/foundation/discovery/template-needs.mjs +30 -15
- package/foundation/discovery/theme-discovery.mjs +14 -2
- package/foundation/discovery/theme-imports.d.mts +16 -0
- package/foundation/discovery/theme-imports.mjs +30 -2
- package/foundation/doc-compiler/import.mjs +10 -4
- package/foundation/fs/gather-cache.mjs +82 -23
- package/foundation/fs/jiti-cache.d.mts +21 -0
- package/foundation/fs/jiti-cache.mjs +66 -0
- package/foundation/fs/module-loader.mjs +7 -2
- 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/may-have-integrations.d.mts +8 -0
- package/foundation/integrations/may-have-integrations.mjs +47 -0
- package/foundation/release/cache.d.mts +21 -2
- package/foundation/release/cache.mjs +48 -8
- package/foundation/release/folder-lock.d.mts +7 -0
- package/foundation/release/folder-lock.mjs +60 -26
- 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 +4 -4
- package/package.json +6 -6
- package/api/theme-edit/_css-properties.d.mts +0 -10
- package/api/theme-edit/_css-properties.mjs +0 -556
|
@@ -9,17 +9,34 @@
|
|
|
9
9
|
* @position api/theme-edit — checks over the part data
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
import
|
|
12
|
+
import * as fs from 'node:fs';
|
|
13
|
+
import * as path from 'node:path';
|
|
13
14
|
import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
|
|
15
|
+
import {baseThemeFile} from './_project.mjs';
|
|
14
16
|
import {levenshteinDistance} from '../../foundation/text/levenshtein.mjs';
|
|
15
|
-
import {
|
|
17
|
+
import {
|
|
18
|
+
MATH_FUNCTION,
|
|
19
|
+
belowRange,
|
|
20
|
+
fontShorthandParts,
|
|
21
|
+
cssProperties,
|
|
22
|
+
grammarText,
|
|
23
|
+
initialOf,
|
|
24
|
+
keywordsOf,
|
|
25
|
+
matchType,
|
|
26
|
+
matchValue,
|
|
27
|
+
numbersIn,
|
|
28
|
+
propertyGrammar,
|
|
29
|
+
takesPercentage,
|
|
30
|
+
} from './_css.mjs';
|
|
16
31
|
import {
|
|
17
32
|
AUTO_SPREAD,
|
|
33
|
+
COLOR_PROP_PARTS,
|
|
18
34
|
COLOR_PROPS,
|
|
19
35
|
COMMON_STATES,
|
|
20
36
|
CORNERS,
|
|
21
37
|
DIALS,
|
|
22
38
|
FAMILIES,
|
|
39
|
+
FONT_ROLES,
|
|
23
40
|
FONTS,
|
|
24
41
|
GROUPS,
|
|
25
42
|
HEADING_TRACKING,
|
|
@@ -27,6 +44,7 @@ import {
|
|
|
27
44
|
LIKE,
|
|
28
45
|
HOW,
|
|
29
46
|
OPEN_FONTS,
|
|
47
|
+
CSS_WIDE,
|
|
30
48
|
CSS_WIDE_KEYWORDS,
|
|
31
49
|
P,
|
|
32
50
|
SPACING,
|
|
@@ -42,6 +60,8 @@ import {
|
|
|
42
60
|
isSafeValue,
|
|
43
61
|
isSize,
|
|
44
62
|
parseColor,
|
|
63
|
+
mixSide,
|
|
64
|
+
splitTop,
|
|
45
65
|
} from './_color.mjs';
|
|
46
66
|
import {
|
|
47
67
|
PALETTE_DIALS,
|
|
@@ -60,6 +80,9 @@ import {
|
|
|
60
80
|
refuse,
|
|
61
81
|
lengthPx,
|
|
62
82
|
radiusAt,
|
|
83
|
+
radiusTokenOf,
|
|
84
|
+
focusStateOf,
|
|
85
|
+
valueProblem,
|
|
63
86
|
} from './_settings.mjs';
|
|
64
87
|
import {quoteCommandArgument} from '../../foundation/env/package-manager.mjs';
|
|
65
88
|
|
|
@@ -81,6 +104,17 @@ function tokenPx(base, token) {
|
|
|
81
104
|
return lengthPx(v);
|
|
82
105
|
}
|
|
83
106
|
|
|
107
|
+
/**
|
|
108
|
+
* A `set` (or `undo`) command for a setting, with its scope, to suggest.
|
|
109
|
+
* @param {string} slug
|
|
110
|
+
* @param {string} thing
|
|
111
|
+
* @param {string} value
|
|
112
|
+
* @param {{on?: string, when?: string, state?: string, mode?: string, only?: boolean}} s
|
|
113
|
+
* @param {boolean} [unset]
|
|
114
|
+
*/
|
|
115
|
+
const setLine = (slug, thing, value, s, unset = false) =>
|
|
116
|
+
`${P} ${unset ? 'undo' : 'set'} ${slug} ${thing}${value ? ` ${quoteCommandArgument(value)}` : ''}${s.on ? ` --on ${s.on}` : ''}${s.when ? ` --when ${s.when}` : ''}${s.state ? ` --state ${s.state}` : ''}${s.mode ? ` --mode ${s.mode}` : ''}${s.only ? ' --only' : ''}`;
|
|
117
|
+
|
|
84
118
|
/** @param {string} v */
|
|
85
119
|
const cornerPxOf = v =>
|
|
86
120
|
CORNERS.find(([n]) => n === v)?.[1] ?? lengthPx(v) ?? Number.NaN;
|
|
@@ -182,7 +216,12 @@ export function storedProblems(ctx, slug, data, skip = '') {
|
|
|
182
216
|
const scope = why => ({setting: s, why, scope: true});
|
|
183
217
|
const problem = (() => {
|
|
184
218
|
const t = s.on ? ctx.project.target.get(s.on) : null;
|
|
185
|
-
if (
|
|
219
|
+
if (
|
|
220
|
+
s.on &&
|
|
221
|
+
!t &&
|
|
222
|
+
!FAMILIES[s.on] &&
|
|
223
|
+
!(s.thing === 'font' && FONT_ROLES.includes(s.on))
|
|
224
|
+
)
|
|
186
225
|
return scope(`there is no part or group "${s.on}"`);
|
|
187
226
|
if (s.source === 'dial' && s.on && WHOLE_ONLY.includes(s.thing))
|
|
188
227
|
return scope(`${s.thing} applies to the whole theme, not to ${s.on}`);
|
|
@@ -212,6 +251,7 @@ export function storedProblems(ctx, slug, data, skip = '') {
|
|
|
212
251
|
TOKENS,
|
|
213
252
|
ctx.C.typeOf,
|
|
214
253
|
slug,
|
|
254
|
+
ctx.C.propsReading(s.thing),
|
|
215
255
|
);
|
|
216
256
|
checkCycle(s.thing, s.value, TOKENS, data);
|
|
217
257
|
} catch (e) {
|
|
@@ -264,8 +304,17 @@ function groupOfPropType(prop) {
|
|
|
264
304
|
* @param {Record<string, unknown>} TOKENS
|
|
265
305
|
* @param {(token: string) => string} typeOf
|
|
266
306
|
* @param {string} slug
|
|
307
|
+
* @param {string[]} [readers] the CSS properties that read the token
|
|
267
308
|
*/
|
|
268
|
-
function checkTypedValue(
|
|
309
|
+
function checkTypedValue(
|
|
310
|
+
type,
|
|
311
|
+
value,
|
|
312
|
+
name,
|
|
313
|
+
TOKENS,
|
|
314
|
+
typeOf,
|
|
315
|
+
slug,
|
|
316
|
+
readers = [],
|
|
317
|
+
) {
|
|
269
318
|
/** @param {string} what @param {string} example */
|
|
270
319
|
const bad = (what, example) =>
|
|
271
320
|
refuse(
|
|
@@ -283,6 +332,24 @@ function checkTypedValue(type, value, name, TOKENS, typeOf, slug) {
|
|
|
283
332
|
],
|
|
284
333
|
},
|
|
285
334
|
);
|
|
335
|
+
// A CSS-wide keyword on a token is no value: whatever reads the token
|
|
336
|
+
// gets none, and drops its declaration (a font list falls back to the
|
|
337
|
+
// browser's default font). On a part property it keeps its meaning.
|
|
338
|
+
const keyword = value
|
|
339
|
+
.split(',')
|
|
340
|
+
.map(x => x.trim().toLowerCase())
|
|
341
|
+
.find(x => CSS_WIDE.includes(x));
|
|
342
|
+
if (keyword)
|
|
343
|
+
refuse(
|
|
344
|
+
E.ERR_THEME_BAD_VALUE,
|
|
345
|
+
`"${keyword}" is a CSS keyword, not a value: on ${name} it leaves the token empty, so what reads it drops its style. Give a value such as ${exampleOf(type, name)}, or undo ${name} to go back to the base theme's.`,
|
|
346
|
+
{
|
|
347
|
+
run: [
|
|
348
|
+
`${P} set ${slug} ${name} ${quoteCommandArgument(exampleOf(type, name))}`,
|
|
349
|
+
`${P} undo ${slug} ${name}`,
|
|
350
|
+
],
|
|
351
|
+
},
|
|
352
|
+
);
|
|
286
353
|
// A var() naming a design token must name one of the same kind; the
|
|
287
354
|
// app's own variables are its business.
|
|
288
355
|
const ref = /^var\(\s*(--[a-z0-9-]+)\s*(,.*)?\)$/i.exec(value.trim());
|
|
@@ -301,6 +368,16 @@ function checkTypedValue(type, value, name, TOKENS, typeOf, slug) {
|
|
|
301
368
|
}
|
|
302
369
|
if (type === 'color' && !isFixedColor(value)) bad('a color', '#1f2937');
|
|
303
370
|
if (type === 'size' && !isSize(value, name)) bad('a size', '6px');
|
|
371
|
+
// A percentage reaches every property that reads the token; one that
|
|
372
|
+
// takes none (a border or outline width, an outline offset) drops it.
|
|
373
|
+
if (type === 'size' && /%/.test(value.replace(/var\([^)]*\)/g, ''))) {
|
|
374
|
+
const strict = readers.filter(p => !takesPercentage(p));
|
|
375
|
+
if (strict.length)
|
|
376
|
+
bad(
|
|
377
|
+
`a length with no percentage (${strict.slice(0, 3).join(', ')} read${strict.length === 1 ? 's' : ''} it, and take${strict.length === 1 ? 's' : ''} none)`,
|
|
378
|
+
'1px',
|
|
379
|
+
);
|
|
380
|
+
}
|
|
304
381
|
if (type === 'number' && !isNumber(value, name))
|
|
305
382
|
bad('a number', /weight/.test(name) ? '600' : '1.4');
|
|
306
383
|
if (type === 'time' && !isTime(value)) bad('a time up to 60s', '150ms');
|
|
@@ -312,9 +389,7 @@ function checkTypedValue(type, value, name, TOKENS, typeOf, slug) {
|
|
|
312
389
|
bad('a shadow', '0 2px 4px rgb(0 0 0 / 0.2)');
|
|
313
390
|
if (
|
|
314
391
|
/^--focus-outline-style$/.test(name) &&
|
|
315
|
-
|
|
316
|
-
value.trim(),
|
|
317
|
-
)
|
|
392
|
+
!matchValue('outline-style', value.trim())
|
|
318
393
|
)
|
|
319
394
|
bad('an outline style', 'solid');
|
|
320
395
|
}
|
|
@@ -329,10 +404,14 @@ function checkTypedValue(type, value, name, TOKENS, typeOf, slug) {
|
|
|
329
404
|
*/
|
|
330
405
|
function isFixedColor(value) {
|
|
331
406
|
const v = value.trim().toLowerCase();
|
|
332
|
-
if (
|
|
333
|
-
return false;
|
|
407
|
+
if (CSS_WIDE.includes(v)) return false;
|
|
334
408
|
if (/^var\(/.test(v)) return true;
|
|
335
409
|
if (SYSTEM_COLORS.includes(v)) return true;
|
|
410
|
+
// Percentages that add up to 0 leave color-mix() no color.
|
|
411
|
+
const zeroMix = (/** @type {string[]} */ colors) => {
|
|
412
|
+
const pcts = colors.map(c => mixSide(c).pct);
|
|
413
|
+
return pcts.every(p => p != null) && pcts.every(p => p === 0);
|
|
414
|
+
};
|
|
336
415
|
const inner = (/** @type {string} */ fn) =>
|
|
337
416
|
splitTop(v.slice(fn.length + 1, -1), ',').map(x => x.trim());
|
|
338
417
|
// Each mode's value, and each mixed color, must be a color itself.
|
|
@@ -345,12 +424,17 @@ function isFixedColor(value) {
|
|
|
345
424
|
return (
|
|
346
425
|
/^in\s+[a-z-]+/.test(space ?? '') &&
|
|
347
426
|
colors.length === 2 &&
|
|
348
|
-
colors
|
|
427
|
+
!zeroMix(colors) &&
|
|
428
|
+
colors.every(c => isFixedColor(mixSide(c).color))
|
|
349
429
|
);
|
|
350
430
|
}
|
|
351
431
|
if (!isColorValue(v)) return false;
|
|
352
|
-
// A relative color
|
|
353
|
-
|
|
432
|
+
// A relative color is read by the browser (the grammar the editor reads
|
|
433
|
+
// does not know it); channels with math or variables must still read as
|
|
434
|
+
// a color, typed as the browser types them.
|
|
435
|
+
if (/\bfrom\b/.test(v)) return true;
|
|
436
|
+
if (MATH_FUNCTION.test(v) || /\b(var|env)\(/.test(v))
|
|
437
|
+
return matchType('color', v) != null;
|
|
354
438
|
if (/^(rgb|rgba|hsl|hsla|hwb|lab|lch|oklab|oklch)\(/.test(v))
|
|
355
439
|
return parseColor(v) != null;
|
|
356
440
|
if (/^color\(/.test(v))
|
|
@@ -384,142 +468,53 @@ const SYSTEM_COLORS = [
|
|
|
384
468
|
];
|
|
385
469
|
|
|
386
470
|
/**
|
|
387
|
-
* Whether a value is a time the browser takes, at most a minute
|
|
471
|
+
* Whether a value is a time the browser takes, at most a minute and never
|
|
472
|
+
* negative (the grammar has no range).
|
|
388
473
|
* @param {string} value
|
|
389
474
|
*/
|
|
390
475
|
function isTime(value) {
|
|
391
|
-
const
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
476
|
+
const ast = matchType('time', value.trim());
|
|
477
|
+
return (
|
|
478
|
+
ast != null &&
|
|
479
|
+
numbersIn(ast).every(
|
|
480
|
+
n =>
|
|
481
|
+
!['s', 'ms'].includes(n.unit) ||
|
|
482
|
+
(n.value >= 0 && n.value * (n.unit === 's' ? 1000 : 1) <= 60_000),
|
|
483
|
+
)
|
|
484
|
+
);
|
|
397
485
|
}
|
|
398
486
|
|
|
399
487
|
/**
|
|
400
|
-
* Whether a value is an easing the browser takes
|
|
401
|
-
*
|
|
402
|
-
*
|
|
488
|
+
* Whether a value is an easing the browser takes. The grammar has no range
|
|
489
|
+
* for a step count: steps() needs at least one step, and two with
|
|
490
|
+
* `jump-none`.
|
|
403
491
|
* @param {string} value
|
|
404
492
|
*/
|
|
405
493
|
function isEasing(value) {
|
|
406
|
-
const
|
|
407
|
-
if (
|
|
408
|
-
|
|
409
|
-
)
|
|
410
|
-
return true;
|
|
411
|
-
const m = /^(cubic-bezier|steps|linear)\((.*)\)$/.exec(v);
|
|
412
|
-
if (!m) return false;
|
|
413
|
-
const args = splitTop(m[2], ',').map(x => x.trim());
|
|
414
|
-
if (args.some(a => /var\(/.test(a))) return true;
|
|
415
|
-
const num = (/** @type {string} */ a) => /^[+-]?\d*\.?\d+$/.test(a);
|
|
416
|
-
if (m[1] === 'cubic-bezier')
|
|
417
|
-
return (
|
|
418
|
-
args.length === 4 &&
|
|
419
|
-
args.every(num) &&
|
|
420
|
-
[0, 2].every(i => Number(args[i]) >= 0 && Number(args[i]) <= 1)
|
|
421
|
-
);
|
|
422
|
-
if (m[1] === 'steps')
|
|
423
|
-
return (
|
|
424
|
-
/^\d+$/.test(args[0] ?? '') &&
|
|
425
|
-
Number(args[0]) >= 1 &&
|
|
426
|
-
args.length <= 2 &&
|
|
427
|
-
(args.length === 1 ||
|
|
428
|
-
/^(jump-start|jump-end|jump-none|jump-both|start|end)$/.test(
|
|
429
|
-
args[1],
|
|
430
|
-
)) &&
|
|
431
|
-
!(args[1] === 'jump-none' && Number(args[0]) < 2)
|
|
432
|
-
);
|
|
433
|
-
return args.length >= 2 && args.every(a => /^[+-]?\d*\.?\d+(\s|$)/.test(a));
|
|
494
|
+
const ast = matchType('easing-function', value.trim());
|
|
495
|
+
if (!ast) return false;
|
|
496
|
+
const count = numbersIn(ast).find(n => n.fn === 'steps');
|
|
497
|
+
return !count || count.value >= (/jump-none/i.test(value) ? 2 : 1);
|
|
434
498
|
}
|
|
435
499
|
|
|
436
|
-
/**
|
|
437
|
-
|
|
438
|
-
* of words that do not start with a digit, or a var().
|
|
439
|
-
* @param {string} value
|
|
440
|
-
*/
|
|
441
|
-
function isFamilyList(value) {
|
|
442
|
-
return splitTop(value.trim(), ',').every(f => {
|
|
443
|
-
const t = f.trim();
|
|
444
|
-
return (
|
|
445
|
-
/^"[^"]+"$/.test(t) ||
|
|
446
|
-
/^'[^']+'$/.test(t) ||
|
|
447
|
-
/^var\(/i.test(t) ||
|
|
448
|
-
/^[\p{L}_-][\p{L}\p{N}_-]*(\s+[\p{L}_-][\p{L}\p{N}_-]*)*$/u.test(t)
|
|
449
|
-
);
|
|
450
|
-
});
|
|
451
|
-
}
|
|
500
|
+
/** Whether a value is a font family list. @param {string} value */
|
|
501
|
+
const isFamilyList = value => matchValue('font-family', value.trim()) != null;
|
|
452
502
|
|
|
453
503
|
/**
|
|
454
|
-
* Whether a value is a shadow list
|
|
455
|
-
*
|
|
504
|
+
* Whether a value is a shadow list. The grammar has no range for the blur
|
|
505
|
+
* (the third length), which is never negative.
|
|
456
506
|
* @param {string} value
|
|
457
507
|
*/
|
|
458
508
|
function isShadow(value) {
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
if (
|
|
464
|
-
layers.length === 1 &&
|
|
465
|
-
splitTop(v, ' ').length === 1 &&
|
|
466
|
-
!/^var\(/i.test(v)
|
|
467
|
-
)
|
|
468
|
-
return false;
|
|
469
|
-
return layers.every(layer => {
|
|
470
|
-
const words = splitTop(layer.trim(), ' ');
|
|
471
|
-
// One var() stacks a shadow token in the list.
|
|
472
|
-
if (words.length === 1 && /^var\(/i.test(words[0])) return true;
|
|
473
|
-
const insets = words.filter(w => w.toLowerCase() === 'inset').length;
|
|
474
|
-
const nums = words.filter(w =>
|
|
475
|
-
/^[+-]?\d*\.?\d+(px|rem|em|pt|pc|cm|mm|in|vw|vh|vmin|vmax|ch|ex|lh)?$|^(calc|min|max|clamp)\(/i.test(
|
|
476
|
-
w,
|
|
477
|
-
),
|
|
478
|
-
);
|
|
479
|
-
const vars = words.filter(w => /^var\(/i.test(w));
|
|
480
|
-
const rest = words.filter(
|
|
481
|
-
w =>
|
|
482
|
-
!nums.includes(w) && !vars.includes(w) && w.toLowerCase() !== 'inset',
|
|
483
|
-
);
|
|
484
|
-
// A blur (the third length) is never negative.
|
|
485
|
-
if (nums.length >= 3 && nums[2].startsWith('-')) return false;
|
|
486
|
-
// A var() fills a length or the color, whichever is missing.
|
|
487
|
-
const color = rest.length ? 0 : Math.min(1, vars.length);
|
|
488
|
-
const lengths = nums.length + vars.length - color;
|
|
489
|
-
return (
|
|
490
|
-
insets <= 1 &&
|
|
491
|
-
lengths >= 2 &&
|
|
492
|
-
lengths <= 4 &&
|
|
493
|
-
rest.length <= 1 &&
|
|
494
|
-
rest.every(w => isFixedColor(w))
|
|
509
|
+
if (!matchValue('box-shadow', value.trim())) return false;
|
|
510
|
+
return splitTop(value.trim(), ',').every(layer => {
|
|
511
|
+
const lengths = splitTop(layer.trim(), ' ').filter(w =>
|
|
512
|
+
/^[+-]?\d*\.?\d+[a-z]*$/i.test(w),
|
|
495
513
|
);
|
|
514
|
+
return !(lengths[2] ?? '').startsWith('-');
|
|
496
515
|
});
|
|
497
516
|
}
|
|
498
517
|
|
|
499
|
-
/**
|
|
500
|
-
* A value split at `sep` outside brackets: `a(b, c), d` by `,` is
|
|
501
|
-
* [`a(b, c)`, ` d`]. A space separator also splits runs of spaces.
|
|
502
|
-
* @param {string} v
|
|
503
|
-
* @param {',' | ' '} sep
|
|
504
|
-
* @returns {string[]}
|
|
505
|
-
*/
|
|
506
|
-
function splitTop(v, sep) {
|
|
507
|
-
/** @type {string[]} */
|
|
508
|
-
const out = [];
|
|
509
|
-
let depth = 0;
|
|
510
|
-
let cur = '';
|
|
511
|
-
for (const c of v) {
|
|
512
|
-
if (c === '(') depth++;
|
|
513
|
-
if (c === ')') depth--;
|
|
514
|
-
if (depth === 0 && (sep === ' ' ? /\s/.test(c) : c === sep)) {
|
|
515
|
-
if (cur.trim() || sep === ',') out.push(cur);
|
|
516
|
-
cur = '';
|
|
517
|
-
} else cur += c;
|
|
518
|
-
}
|
|
519
|
-
if (cur.trim() || sep === ',') out.push(cur);
|
|
520
|
-
return out.filter(x => sep === ',' || x.trim());
|
|
521
|
-
}
|
|
522
|
-
|
|
523
518
|
/**
|
|
524
519
|
* Refuse a value that would read the token itself, through other tokens.
|
|
525
520
|
* @param {string} thing
|
|
@@ -564,96 +559,15 @@ function checkCycle(thing, value, TOKENS, data) {
|
|
|
564
559
|
);
|
|
565
560
|
}
|
|
566
561
|
|
|
567
|
-
const require = createRequire(import.meta.url);
|
|
568
|
-
/** @type {any} */
|
|
569
|
-
let tree = null;
|
|
570
|
-
/** css-tree, loaded on first use. */
|
|
571
|
-
const csstree = () => (tree ??= require('css-tree'));
|
|
572
|
-
|
|
573
|
-
/** What a var() or env() may stand for while the rest of a value is matched. */
|
|
574
|
-
const VAR_STANDS_FOR = ['0', '1px', '1ms', 'red', 'ease', 'serif', '0 0 red'];
|
|
575
|
-
|
|
576
|
-
/**
|
|
577
|
-
* Whether a value matches a property's grammar as css-tree reads it (the
|
|
578
|
-
* browser's grammar, from MDN's data). A var() or env() can hold anything,
|
|
579
|
-
* so the value matches when some ordinary value in its place does.
|
|
580
|
-
* @param {string} prop
|
|
581
|
-
* @param {string} value
|
|
582
|
-
*/
|
|
583
|
-
function matchesProperty(prop, value) {
|
|
584
|
-
const {lexer, parse} = csstree();
|
|
585
|
-
const vars =
|
|
586
|
-
value.match(/(?:var|env)\([^()]*(?:\([^()]*\)[^()]*)*\)/gi) ?? [];
|
|
587
|
-
/** @param {string} v */
|
|
588
|
-
const tryOne = v => {
|
|
589
|
-
try {
|
|
590
|
-
return !lexer.matchProperty(prop, parse(v, {context: 'value'})).error;
|
|
591
|
-
} catch {
|
|
592
|
-
return false;
|
|
593
|
-
}
|
|
594
|
-
};
|
|
595
|
-
if (vars.length > 3) return false;
|
|
596
|
-
/** @param {string} v @param {number} i @returns {boolean} */
|
|
597
|
-
const fill = (v, i) =>
|
|
598
|
-
i === vars.length
|
|
599
|
-
? tryOne(v)
|
|
600
|
-
: VAR_STANDS_FOR.some(stand => fill(v.replace(vars[i], stand), i + 1));
|
|
601
|
-
return fill(value, 0);
|
|
602
|
-
}
|
|
603
|
-
|
|
604
|
-
/**
|
|
605
|
-
* The keywords a property's grammar takes, through the types it names.
|
|
606
|
-
* @param {string} prop
|
|
607
|
-
* @returns {string[]}
|
|
608
|
-
*/
|
|
609
|
-
function keywordsOf(prop) {
|
|
610
|
-
const t = csstree();
|
|
611
|
-
const seen = new Set();
|
|
612
|
-
/** @type {Set<string>} */
|
|
613
|
-
const words = new Set();
|
|
614
|
-
/** @param {any} syntax */
|
|
615
|
-
const walk = syntax => {
|
|
616
|
-
if (!syntax) return;
|
|
617
|
-
t.definitionSyntax.walk(syntax, (/** @type {any} */ n) => {
|
|
618
|
-
if (n.type === 'Keyword') {
|
|
619
|
-
if (!n.name.startsWith('-')) words.add(n.name);
|
|
620
|
-
} else if (n.type === 'Type' && !seen.has(n.name)) {
|
|
621
|
-
seen.add(n.name);
|
|
622
|
-
walk(t.lexer.types[n.name]?.syntax);
|
|
623
|
-
}
|
|
624
|
-
});
|
|
625
|
-
};
|
|
626
|
-
walk(t.lexer.properties[prop]?.syntax);
|
|
627
|
-
return [...words];
|
|
628
|
-
}
|
|
629
|
-
|
|
630
562
|
/**
|
|
631
|
-
*
|
|
632
|
-
*
|
|
633
|
-
* @param {string}
|
|
634
|
-
* @returns {string | null}
|
|
635
|
-
*/
|
|
636
|
-
function initialOf(prop) {
|
|
637
|
-
const mdn = /** @type {Record<string, {initial?: string | string[]}>} */ (
|
|
638
|
-
createRequire(require.resolve('css-tree/package.json'))(
|
|
639
|
-
'mdn-data/css/properties.json',
|
|
640
|
-
)
|
|
641
|
-
);
|
|
642
|
-
const initial = mdn[prop]?.initial;
|
|
643
|
-
if (Array.isArray(initial)) return initial[0] ? initialOf(initial[0]) : null;
|
|
644
|
-
return typeof initial === 'string' && matchesProperty(prop, initial)
|
|
645
|
-
? initial
|
|
646
|
-
: null;
|
|
647
|
-
}
|
|
648
|
-
|
|
649
|
-
/**
|
|
650
|
-
* A property's grammar as text, cut at a whole term when it is long.
|
|
651
|
-
* @param {any} syntax
|
|
563
|
+
* The CSS color name nearest a word typed as a color (`banan` is not one,
|
|
564
|
+
* `rd` is red), or null when none is near.
|
|
565
|
+
* @param {string} v
|
|
652
566
|
*/
|
|
653
|
-
function
|
|
654
|
-
const
|
|
655
|
-
if (
|
|
656
|
-
return
|
|
567
|
+
function nearestColorName(v) {
|
|
568
|
+
const w = v.trim().toLowerCase();
|
|
569
|
+
if (!/^[a-z]+$/.test(w)) return null;
|
|
570
|
+
return nearest(w, COLOR_NAMES)[0] ?? null;
|
|
657
571
|
}
|
|
658
572
|
|
|
659
573
|
/**
|
|
@@ -666,14 +580,34 @@ function grammarText(syntax) {
|
|
|
666
580
|
*/
|
|
667
581
|
function propertyProblem(prop, value) {
|
|
668
582
|
const v = value.trim();
|
|
669
|
-
const known =
|
|
670
|
-
if (!known || COLOR_PROPS.test(prop)
|
|
583
|
+
const known = propertyGrammar(prop);
|
|
584
|
+
if (!known || COLOR_PROPS.test(prop)) return null;
|
|
585
|
+
if (matchValue(prop, v))
|
|
586
|
+
return belowRange(prop, v)
|
|
587
|
+
? {takes: 'a value of 0 or more', near: null}
|
|
588
|
+
: null;
|
|
589
|
+
// Only keywords the property takes on their own are offered; the same
|
|
590
|
+
// word without its dashes or a trailing -ed/-s comes first (no-wrap is
|
|
591
|
+
// nowrap, underlined is underline), then the nearest in spelling.
|
|
592
|
+
const own = keywordsOf(prop).filter(k => matchValue(prop, k));
|
|
593
|
+
const typed = v.toLowerCase();
|
|
594
|
+
const bare = (/** @type {string} */ w) => w.replace(/[-\s]/g, '');
|
|
671
595
|
const near = /^[a-z-]+$/i.test(v)
|
|
672
|
-
? (
|
|
596
|
+
? (own.find(k => bare(k) === bare(typed)) ??
|
|
597
|
+
own.find(k => typed.replace(/(ed|d|s)$/, '') === k) ??
|
|
598
|
+
nearest(typed, own)[0] ??
|
|
599
|
+
null)
|
|
673
600
|
: null;
|
|
601
|
+
// A value that works, for the suggestion: a keyword near the one typed,
|
|
602
|
+
// the property's initial value, or an example of its kind; each checked.
|
|
603
|
+
const example = exampleOf(groupOfPropType(prop), prop);
|
|
604
|
+
const initial = initialOf(prop);
|
|
674
605
|
return {
|
|
675
|
-
takes: `a value its CSS grammar takes (${grammarText(known
|
|
676
|
-
near:
|
|
606
|
+
takes: `a value its CSS grammar takes (${grammarText(known)})`,
|
|
607
|
+
near:
|
|
608
|
+
near ??
|
|
609
|
+
(initial && matchValue(prop, initial) ? initial : null) ??
|
|
610
|
+
(matchValue(prop, example) ? example : null),
|
|
677
611
|
};
|
|
678
612
|
}
|
|
679
613
|
|
|
@@ -721,7 +655,27 @@ const DIAL_WORDS = /** @type {Record<string, Record<string, string>>} */ ({
|
|
|
721
655
|
});
|
|
722
656
|
|
|
723
657
|
/**
|
|
724
|
-
|
|
658
|
+
/**
|
|
659
|
+
* Whether the base theme's own part styles read a token (`var(--x)`), which
|
|
660
|
+
* the editor's record of Core's parts does not cover.
|
|
661
|
+
* @param {import('./_settings.mjs').Ctx} ctx
|
|
662
|
+
* @param {string} like
|
|
663
|
+
* @param {string} token
|
|
664
|
+
*/
|
|
665
|
+
function baseReads(ctx, like, token) {
|
|
666
|
+
try {
|
|
667
|
+
return new RegExp(`var\\(${token}[,)]`).test(
|
|
668
|
+
fs.readFileSync(baseThemeFile(ctx.project, like), 'utf8'),
|
|
669
|
+
);
|
|
670
|
+
} catch {
|
|
671
|
+
return false;
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
/**
|
|
676
|
+
* Check one setting and give it back ready to store, or refuse. What it
|
|
677
|
+
* accepts, the settings loader takes too: the loader's own check runs last,
|
|
678
|
+
* so a saved setting never blocks the theme.
|
|
725
679
|
* @param {import('./_settings.mjs').Ctx} ctx
|
|
726
680
|
* @param {string} slug
|
|
727
681
|
* @param {import('./_settings.mjs').ThemeData} data
|
|
@@ -740,6 +694,37 @@ export function checkSetting(
|
|
|
740
694
|
flags,
|
|
741
695
|
unset = false,
|
|
742
696
|
) {
|
|
697
|
+
const s = checkOne(ctx, slug, data, thing, value, flags, unset);
|
|
698
|
+
const why = unset ? null : valueProblem(s);
|
|
699
|
+
if (why)
|
|
700
|
+
refuse(
|
|
701
|
+
E.ERR_THEME_BAD_VALUE,
|
|
702
|
+
/cannot be a CSS value$/.test(why)
|
|
703
|
+
? `${why}: it has a ; { } < > or a newline, a comment, !important, or an unclosed bracket or quote, so the browser would drop it.`
|
|
704
|
+
: `${why}.`,
|
|
705
|
+
{
|
|
706
|
+
run: [
|
|
707
|
+
s.thing === 'font'
|
|
708
|
+
? `${P} set ${slug} font inter${s.on ? ` --on ${s.on}` : ''}`
|
|
709
|
+
: `${HOW} ${s.thing}`,
|
|
710
|
+
],
|
|
711
|
+
},
|
|
712
|
+
);
|
|
713
|
+
return s;
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
/**
|
|
717
|
+
* The checks of one setting, before the loader's (see checkSetting).
|
|
718
|
+
* @param {import('./_settings.mjs').Ctx} ctx
|
|
719
|
+
* @param {string} slug
|
|
720
|
+
* @param {import('./_settings.mjs').ThemeData} data
|
|
721
|
+
* @param {string} thing
|
|
722
|
+
* @param {string | undefined} value
|
|
723
|
+
* @param {SetFlags} flags
|
|
724
|
+
* @param {boolean} unset
|
|
725
|
+
* @returns {import('./_settings.mjs').Setting}
|
|
726
|
+
*/
|
|
727
|
+
function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
743
728
|
const {C} = ctx;
|
|
744
729
|
const TARGET = ctx.project.target;
|
|
745
730
|
const TOKENS = ctx.project.core.tokenDefaults;
|
|
@@ -772,14 +757,30 @@ export function checkSetting(
|
|
|
772
757
|
run: [`${P} ${unset ? 'undo' : 'set'} --help`],
|
|
773
758
|
});
|
|
774
759
|
// A value pasted over several lines is one value.
|
|
775
|
-
const v = (value ?? '')
|
|
760
|
+
const v = (value ?? '')
|
|
761
|
+
.replace(/\s*[\r\n]+\s*/g, ' ')
|
|
762
|
+
.replace(/\t+/g, ' ')
|
|
763
|
+
.trim();
|
|
776
764
|
// A var() that misspells a design token would read nothing.
|
|
777
765
|
if (!unset)
|
|
778
|
-
for (const [, name] of v.matchAll(
|
|
766
|
+
for (const [, name, comma] of v.matchAll(
|
|
767
|
+
/var\(\s*(--[a-z0-9-]+)\s*(,)?/gi,
|
|
768
|
+
)) {
|
|
779
769
|
if (name in TOKENS || name.startsWith('--_')) continue;
|
|
780
770
|
const near = nearest(name, Object.keys(TOKENS)).filter(
|
|
781
771
|
n => levenshteinDistance(n, name) <= 2,
|
|
782
772
|
);
|
|
773
|
+
// Without a fallback, a variable no design token names reads
|
|
774
|
+
// nothing; var(--x, <value>) falls back to the value.
|
|
775
|
+
if (!near.length && !comma && !DIALS[thing])
|
|
776
|
+
refuse(
|
|
777
|
+
E.ERR_THEME_UNKNOWN_TOKEN,
|
|
778
|
+
`${name} is not a design token, so var(${name}) would read nothing. Give a fallback (var(${name}, <value>)) for a variable your app sets, or use a design token.`,
|
|
779
|
+
{
|
|
780
|
+
didYouMean: nearest(name, Object.keys(TOKENS)).slice(0, 3),
|
|
781
|
+
run: [`${HOW} --list tokens`],
|
|
782
|
+
},
|
|
783
|
+
);
|
|
783
784
|
if (near.length)
|
|
784
785
|
refuse(
|
|
785
786
|
E.ERR_THEME_UNKNOWN_TOKEN,
|
|
@@ -821,11 +822,27 @@ export function checkSetting(
|
|
|
821
822
|
refuse(
|
|
822
823
|
E.ERR_THEME_BAD_VALUE,
|
|
823
824
|
`--mode takes light or dark, not "${flags.mode}".`,
|
|
824
|
-
{
|
|
825
|
+
{
|
|
826
|
+
didYouMean: nearest(mode, ['light', 'dark']),
|
|
827
|
+
// The same setting for both modes runs as printed; the mode it
|
|
828
|
+
// probably meant is the did-you-mean.
|
|
829
|
+
run: [setLine(slug, thing, v, {...s, mode: undefined}, unset)],
|
|
830
|
+
},
|
|
825
831
|
);
|
|
826
832
|
s.mode = mode;
|
|
827
833
|
}
|
|
828
834
|
const onFlag = s.on ? ` --on ${s.on}` : '';
|
|
835
|
+
// A value that already gives both modes takes no --mode.
|
|
836
|
+
if (s.mode && !unset && /^\s*light-dark\(/i.test(v ?? ''))
|
|
837
|
+
refuse(
|
|
838
|
+
E.ERR_THEME_NO_MODE,
|
|
839
|
+
`"${v}" already gives both modes, so it takes no --mode; drop --mode, or give the ${s.mode} color alone.`,
|
|
840
|
+
{
|
|
841
|
+
run: [
|
|
842
|
+
`${P} set ${slug} ${thing} ${quoteCommandArgument(String(v))}${s.on ? ` --on ${s.on}` : ''}${s.when ? ` --when ${s.when}` : ''}${s.state ? ` --state ${s.state}` : ''}`,
|
|
843
|
+
],
|
|
844
|
+
},
|
|
845
|
+
);
|
|
829
846
|
// A setting saved for a mode the theme no longer has can still be removed.
|
|
830
847
|
if (s.mode && data.mode !== 'both' && !unset)
|
|
831
848
|
refuse(
|
|
@@ -858,8 +875,7 @@ export function checkSetting(
|
|
|
858
875
|
},
|
|
859
876
|
);
|
|
860
877
|
}
|
|
861
|
-
const isRole =
|
|
862
|
-
thing === 'font' && ['body', 'heading', 'code'].includes(s.on ?? '');
|
|
878
|
+
const isRole = thing === 'font' && FONT_ROLES.includes(s.on ?? '');
|
|
863
879
|
if (s.on && !isRole && !FAMILIES[s.on]) {
|
|
864
880
|
const t = TARGET.get(s.on);
|
|
865
881
|
if (!t) {
|
|
@@ -919,8 +935,139 @@ export function checkSetting(
|
|
|
919
935
|
refuse(
|
|
920
936
|
E.ERR_THEME_UNKNOWN_STATE,
|
|
921
937
|
`"${s.state}" is not a state of ${s.on}. States: ${states.join(', ')}.`,
|
|
922
|
-
{
|
|
938
|
+
{
|
|
939
|
+
didYouMean: nearest(s.state, states),
|
|
940
|
+
run: [
|
|
941
|
+
setLine(
|
|
942
|
+
slug,
|
|
943
|
+
thing,
|
|
944
|
+
v,
|
|
945
|
+
{...s, state: nearest(s.state, states)[0] ?? 'hover'},
|
|
946
|
+
unset,
|
|
947
|
+
),
|
|
948
|
+
],
|
|
949
|
+
},
|
|
950
|
+
);
|
|
951
|
+
}
|
|
952
|
+
// A part whose styled element is a wrapper (a text input's box) shows
|
|
953
|
+
// focus only through focus-within: focus or focus-visible there would
|
|
954
|
+
// never apply. Named the way `how` names it.
|
|
955
|
+
if (!unset && s.on && (s.state === 'focus' || s.state === 'focus-visible')) {
|
|
956
|
+
const parts = partsOf(ctx, s).filter(t => focusStateOf(ctx, t));
|
|
957
|
+
if (
|
|
958
|
+
parts.length &&
|
|
959
|
+
parts.every(t => focusStateOf(ctx, t) === 'focus-within')
|
|
960
|
+
)
|
|
961
|
+
refuse(
|
|
962
|
+
E.ERR_THEME_NO_EFFECT,
|
|
963
|
+
`${s.on} shows focus on its box, around the field itself, so ${s.state} never applies there; focus-within does (the box while the field inside has focus).`,
|
|
964
|
+
{
|
|
965
|
+
didYouMean: ['focus-within'],
|
|
966
|
+
run: [setLine(slug, thing, v, {...s, state: 'focus-within'}, unset)],
|
|
967
|
+
},
|
|
968
|
+
);
|
|
969
|
+
}
|
|
970
|
+
// A state that depends on the element applies only where it can: focus
|
|
971
|
+
// where Core's own styles key on it, disabled on a part whose component
|
|
972
|
+
// takes a disabled prop (Core marks it with aria-disabled, which the
|
|
973
|
+
// theme's selector matches too), never on a part with no styles of its
|
|
974
|
+
// own.
|
|
975
|
+
if (
|
|
976
|
+
!unset &&
|
|
977
|
+
!ctx.unchecked &&
|
|
978
|
+
s.on &&
|
|
979
|
+
s.state &&
|
|
980
|
+
['disabled', 'focus', 'focus-visible', 'focus-within', 'active'].includes(
|
|
981
|
+
s.state,
|
|
982
|
+
)
|
|
983
|
+
) {
|
|
984
|
+
const parts = partsOf(ctx, s);
|
|
985
|
+
const own = (/** @type {string} */ t) => ctx.C.MAP[t]?.own ?? {};
|
|
986
|
+
const keys = (/** @type {string} */ t, /** @type {string} */ st) =>
|
|
987
|
+
JSON.stringify(own(t)).includes(`:${st}`);
|
|
988
|
+
const states = (/** @type {string} */ t) =>
|
|
989
|
+
ctx.project.target.get(t)?.states ?? [];
|
|
990
|
+
// The part's component, or the one named like the part (tab is Tab,
|
|
991
|
+
// under TabList), takes a disabled prop.
|
|
992
|
+
const disables = (/** @type {string} */ t) => {
|
|
993
|
+
const comps = /** @type {Record<string, any>} */ (
|
|
994
|
+
ctx.project.components ?? {}
|
|
995
|
+
);
|
|
996
|
+
const pascal = t.replace(/(^|-)([a-z0-9])/g, (_, __, c) =>
|
|
997
|
+
c.toUpperCase(),
|
|
998
|
+
);
|
|
999
|
+
// Or its built module sets aria-disabled (a tab takes it through its
|
|
1000
|
+
// other props): what Core renders, read from Core itself.
|
|
1001
|
+
const marks = (/** @type {string} */ n) => {
|
|
1002
|
+
const at = comps[n]?.importPath?.split('/').pop();
|
|
1003
|
+
const file =
|
|
1004
|
+
at && ctx.project.coreDir
|
|
1005
|
+
? path.join(ctx.project.coreDir, 'dist', at, `${n}.js`)
|
|
1006
|
+
: null;
|
|
1007
|
+
try {
|
|
1008
|
+
return file
|
|
1009
|
+
? fs.readFileSync(file, 'utf8').includes('aria-disabled')
|
|
1010
|
+
: false;
|
|
1011
|
+
} catch {
|
|
1012
|
+
return false;
|
|
1013
|
+
}
|
|
1014
|
+
};
|
|
1015
|
+
return [ctx.project.target.get(t)?.component, pascal].some(
|
|
1016
|
+
n =>
|
|
1017
|
+
n != null &&
|
|
1018
|
+
(Object.keys(comps[n]?.props ?? {}).some(p => /disabled/i.test(p)) ||
|
|
1019
|
+
marks(n)),
|
|
923
1020
|
);
|
|
1021
|
+
};
|
|
1022
|
+
// A part Core never styles in focus is not what takes focus (the
|
|
1023
|
+
// focusable element is inside it, or beside it).
|
|
1024
|
+
const focusable = (/** @type {string} */ t) =>
|
|
1025
|
+
/:focus(?!-within)/.test(JSON.stringify(own(t)));
|
|
1026
|
+
const dead = parts.filter(
|
|
1027
|
+
t =>
|
|
1028
|
+
!states(t).includes(/** @type {string} */ (s.state)) &&
|
|
1029
|
+
(Object.keys(own(t)).length === 0 ||
|
|
1030
|
+
((s.state === 'focus' || s.state === 'focus-visible') &&
|
|
1031
|
+
!focusable(t)) ||
|
|
1032
|
+
(s.state === 'disabled' &&
|
|
1033
|
+
!keys(t, 'disabled') &&
|
|
1034
|
+
!JSON.stringify(own(t)).includes('aria-disabled') &&
|
|
1035
|
+
!disables(t)) ||
|
|
1036
|
+
(s.state === 'active' && !keys(t, 'active')) ||
|
|
1037
|
+
// focus-within on a part Core never styles that way: nothing
|
|
1038
|
+
// focusable is inside it (a switch's input sits beside its track).
|
|
1039
|
+
(s.state === 'focus-within' &&
|
|
1040
|
+
!keys(t, 'focus-within') &&
|
|
1041
|
+
!focusable(t))),
|
|
1042
|
+
);
|
|
1043
|
+
if (parts.length && dead.length === parts.length) {
|
|
1044
|
+
const bare = Object.keys(own(dead[0])).length === 0;
|
|
1045
|
+
const within = keys(dead[0], 'focus-within');
|
|
1046
|
+
refuse(
|
|
1047
|
+
E.ERR_THEME_NO_EFFECT,
|
|
1048
|
+
bare
|
|
1049
|
+
? `${s.on} has no styles of its own (its looks come from the parts inside it), so --state ${s.state} never applies on it.`
|
|
1050
|
+
: s.state === 'active'
|
|
1051
|
+
? `Core never styles ${s.on} while it is pressed, so --state active never applies on it.`
|
|
1052
|
+
: s.state === 'disabled'
|
|
1053
|
+
? `${s.on} is never marked disabled (its component takes no disabled prop, and Core never styles it disabled), so --state disabled never applies on it.`
|
|
1054
|
+
: s.state === 'focus-within'
|
|
1055
|
+
? `nothing inside ${s.on} takes focus (what takes focus sits beside it), so --state focus-within never applies on it.`
|
|
1056
|
+
: `${s.on} never takes focus itself (what takes focus is inside it or beside it), so --state ${s.state} never applies on it.${within ? ' focus-within does: the part while something inside it has focus.' : ''}`,
|
|
1057
|
+
{
|
|
1058
|
+
...(within && !bare && /^focus/.test(s.state)
|
|
1059
|
+
? {didYouMean: ['focus-within']}
|
|
1060
|
+
: {}),
|
|
1061
|
+
run: [
|
|
1062
|
+
within && !bare && /^focus/.test(s.state)
|
|
1063
|
+
? setLine(slug, thing, v, {...s, state: 'focus-within'}, unset)
|
|
1064
|
+
: bare
|
|
1065
|
+
? `${HOW} --list parts ${s.on.split('-')[0]}`
|
|
1066
|
+
: `${HOW} ${quoteCommandArgument(s.on)}`,
|
|
1067
|
+
],
|
|
1068
|
+
},
|
|
1069
|
+
);
|
|
1070
|
+
}
|
|
924
1071
|
}
|
|
925
1072
|
// On a group, a variant or state must belong to at least one member.
|
|
926
1073
|
if (s.on && FAMILIES[s.on] && (s.when || s.state)) {
|
|
@@ -954,6 +1101,19 @@ export function checkSetting(
|
|
|
954
1101
|
);
|
|
955
1102
|
}
|
|
956
1103
|
const step = v === 'more' || v === 'less';
|
|
1104
|
+
// more/less step a dial with a scale; on a dial of named looks, they name
|
|
1105
|
+
// nothing, so the answer is what the dial takes, not one of its values.
|
|
1106
|
+
if (
|
|
1107
|
+
step &&
|
|
1108
|
+
!unset &&
|
|
1109
|
+
DIALS[thing] &&
|
|
1110
|
+
!['corners', 'spacing', 'text-size', 'vibrancy'].includes(thing)
|
|
1111
|
+
)
|
|
1112
|
+
refuse(
|
|
1113
|
+
E.ERR_THEME_BAD_VALUE,
|
|
1114
|
+
`"${v}" steps a dial with a scale (corners, spacing, text-size, vibrancy); ${thing} takes one of ${DIALS[thing].values.replace(/\|/g, ', ')}.`,
|
|
1115
|
+
{run: [`${HOW} ${thing}`]},
|
|
1116
|
+
);
|
|
957
1117
|
if (DIALS[thing]) {
|
|
958
1118
|
s.source = 'dial';
|
|
959
1119
|
if (['surfaces', 'buttons', 'type'].includes(thing)) {
|
|
@@ -991,7 +1151,23 @@ export function checkSetting(
|
|
|
991
1151
|
`${thing} takes ${DIALS[thing].values}, not "${v}".`,
|
|
992
1152
|
{
|
|
993
1153
|
didYouMean: near,
|
|
994
|
-
run: near[0]
|
|
1154
|
+
run: near[0]
|
|
1155
|
+
? [`${P} set ${slug} ${thing} ${near[0]}`]
|
|
1156
|
+
: // A corner word or a size is the corners dial: on the
|
|
1157
|
+
// buttons for `buttons`, for the whole theme otherwise.
|
|
1158
|
+
CORNERS.some(([n]) => lower.replace(/s$/, '') === n) ||
|
|
1159
|
+
lengthPx(lower) != null
|
|
1160
|
+
? [
|
|
1161
|
+
setLine(
|
|
1162
|
+
slug,
|
|
1163
|
+
'corners',
|
|
1164
|
+
CORNERS.find(
|
|
1165
|
+
([n]) => lower.replace(/s$/, '') === n,
|
|
1166
|
+
)?.[0] ?? lower,
|
|
1167
|
+
thing === 'buttons' ? {on: 'button'} : {},
|
|
1168
|
+
),
|
|
1169
|
+
]
|
|
1170
|
+
: [`${HOW} ${thing}`],
|
|
995
1171
|
},
|
|
996
1172
|
);
|
|
997
1173
|
}
|
|
@@ -1042,6 +1218,17 @@ export function checkSetting(
|
|
|
1042
1218
|
...Object.keys(HEADING_WEIGHTS),
|
|
1043
1219
|
...Object.keys(HEADING_TRACKING),
|
|
1044
1220
|
]),
|
|
1221
|
+
run: [
|
|
1222
|
+
setLine(
|
|
1223
|
+
slug,
|
|
1224
|
+
'headings',
|
|
1225
|
+
nearest(v, [
|
|
1226
|
+
...Object.keys(HEADING_WEIGHTS),
|
|
1227
|
+
...Object.keys(HEADING_TRACKING),
|
|
1228
|
+
])[0] ?? Object.keys(HEADING_WEIGHTS)[0],
|
|
1229
|
+
s,
|
|
1230
|
+
),
|
|
1231
|
+
],
|
|
1045
1232
|
},
|
|
1046
1233
|
);
|
|
1047
1234
|
return s;
|
|
@@ -1052,7 +1239,7 @@ export function checkSetting(
|
|
|
1052
1239
|
// The value in effect for the target: its own setting, else the
|
|
1053
1240
|
// whole-theme one, else the starting point.
|
|
1054
1241
|
// Same target: the part, and the same variant and state.
|
|
1055
|
-
const
|
|
1242
|
+
const latest = (/** @type {string} */ on) =>
|
|
1056
1243
|
[...data.settings].reverse().find(
|
|
1057
1244
|
x =>
|
|
1058
1245
|
x.thing === thing &&
|
|
@@ -1062,12 +1249,41 @@ export function checkSetting(
|
|
|
1062
1249
|
// A member set alone (--only) is not the member as the group
|
|
1063
1250
|
// spreads it.
|
|
1064
1251
|
Boolean(x.only) === (on === s.on ? Boolean(s.only) : false),
|
|
1065
|
-
)
|
|
1066
|
-
|
|
1252
|
+
);
|
|
1253
|
+
const own = (/** @type {string} */ on) => latest(on)?.value;
|
|
1254
|
+
// A member covered by a later group setting shows the group's value
|
|
1255
|
+
// (the later one wins, as the build applies them).
|
|
1067
1256
|
const fam = s.on ? familyOf(s.on) : null;
|
|
1257
|
+
// For a variant or state with no setting of its own, the part's
|
|
1258
|
+
// plain setting applies there too.
|
|
1259
|
+
const plainOn = (/** @type {string} */ on) =>
|
|
1260
|
+
[...data.settings]
|
|
1261
|
+
.reverse()
|
|
1262
|
+
.find(
|
|
1263
|
+
x =>
|
|
1264
|
+
x.thing === thing &&
|
|
1265
|
+
(x.on ?? '') === on &&
|
|
1266
|
+
!x.when &&
|
|
1267
|
+
!x.state &&
|
|
1268
|
+
!x.only === !(on === s.on && s.only),
|
|
1269
|
+
);
|
|
1270
|
+
const mine =
|
|
1271
|
+
latest(s.on ?? '') ??
|
|
1272
|
+
(s.on && (s.when || s.state) ? plainOn(s.on) : undefined);
|
|
1273
|
+
// With --only too: the member shows its group's value until it has one
|
|
1274
|
+
// of its own, as corners step.
|
|
1275
|
+
const group =
|
|
1276
|
+
fam && fam !== s.on
|
|
1277
|
+
? (latest(fam) ?? (s.when || s.state ? plainOn(fam) : undefined))
|
|
1278
|
+
: undefined;
|
|
1279
|
+
const shown =
|
|
1280
|
+
mine && group
|
|
1281
|
+
? data.settings.indexOf(group) > data.settings.indexOf(mine)
|
|
1282
|
+
? group
|
|
1283
|
+
: mine
|
|
1284
|
+
: (mine ?? group);
|
|
1068
1285
|
const cur =
|
|
1069
|
-
|
|
1070
|
-
(fam && fam !== s.on && !s.only ? own(fam) : undefined) ??
|
|
1286
|
+
shown?.value ??
|
|
1071
1287
|
// A part's own radius (a number) already counts a whole-theme
|
|
1072
1288
|
// setting.
|
|
1073
1289
|
(s.on && typeof def !== 'number' ? own('') : undefined) ??
|
|
@@ -1078,13 +1294,36 @@ export function checkSetting(
|
|
|
1078
1294
|
Math.max(0, Math.min(L.length - 1, at + (v === 'more' ? 1 : -1)))
|
|
1079
1295
|
][0];
|
|
1080
1296
|
// A size between rungs steps to the next rung that way, never past it.
|
|
1081
|
-
const px =
|
|
1297
|
+
const px =
|
|
1298
|
+
typeof cur === 'number'
|
|
1299
|
+
? cur
|
|
1300
|
+
: (lengthPx(cur) ??
|
|
1301
|
+
(/^\d*\.?\d+$/.test(String(cur)) ? Number(cur) : Number.NaN));
|
|
1082
1302
|
if (Number.isNaN(px)) return L[0][0];
|
|
1083
1303
|
const next =
|
|
1084
1304
|
v === 'more'
|
|
1085
1305
|
? L.find(([, n]) => n > px + 0.01)
|
|
1086
1306
|
: [...L].reverse().find(([, n]) => n < px - 0.01);
|
|
1087
|
-
|
|
1307
|
+
// Past the last step that way, a step would go back: give a size.
|
|
1308
|
+
if (!next) {
|
|
1309
|
+
const edge = /** @type {[string, number]} */ (
|
|
1310
|
+
v === 'more' ? L[L.length - 1] : L[0]
|
|
1311
|
+
);
|
|
1312
|
+
const example = String(cur).replace(
|
|
1313
|
+
/\d*\.?\d+/,
|
|
1314
|
+
String(Math.max(0, Math.round(px + (v === 'more' ? 2 : -2)))),
|
|
1315
|
+
);
|
|
1316
|
+
refuse(
|
|
1317
|
+
E.ERR_THEME_BAD_VALUE,
|
|
1318
|
+
`${thing} is ${typeof cur === 'number' ? `${cur}px` : cur}, already ${v === 'more' ? 'above' : 'below'} its ${v === 'more' ? 'largest' : 'smallest'} step (${edge[0]}, ${edge[1]}px), so "${v}" has nowhere to go. Give an exact size.`,
|
|
1319
|
+
{
|
|
1320
|
+
run: [
|
|
1321
|
+
`${P} set ${slug} ${thing} ${quoteCommandArgument(example)}${s.on ? ` --on ${s.on}` : ''}`,
|
|
1322
|
+
],
|
|
1323
|
+
},
|
|
1324
|
+
);
|
|
1325
|
+
}
|
|
1326
|
+
return next[0];
|
|
1088
1327
|
};
|
|
1089
1328
|
if (PALETTE_DIALS.includes(thing) && (s.on || s.mode)) {
|
|
1090
1329
|
const token = paletteToken(thing);
|
|
@@ -1124,11 +1363,8 @@ export function checkSetting(
|
|
|
1124
1363
|
refuse(
|
|
1125
1364
|
E.ERR_THEME_NO_MODE,
|
|
1126
1365
|
`${thing} is not a color, so it is the same in light and dark; drop --mode.`,
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
`${P} set ${slug} ${thing} ${quoteCommandArgument(v)}${onFlag}`,
|
|
1130
|
-
],
|
|
1131
|
-
},
|
|
1366
|
+
// The same scope, every other flag kept.
|
|
1367
|
+
{run: [setLine(slug, thing, v, {...s, mode: undefined})]},
|
|
1132
1368
|
);
|
|
1133
1369
|
if (thing === 'corners') {
|
|
1134
1370
|
if (s.on) refuseInvisibleCorners(ctx, slug, s, data);
|
|
@@ -1143,30 +1379,37 @@ export function checkSetting(
|
|
|
1143
1379
|
light: /** @type {Record<string, string>} */ ({}),
|
|
1144
1380
|
dark: /** @type {Record<string, string>} */ ({}),
|
|
1145
1381
|
};
|
|
1146
|
-
const token =
|
|
1147
|
-
(s.on
|
|
1148
|
-
|
|
1149
|
-
partDefault(
|
|
1150
|
-
ctx,
|
|
1151
|
-
partsOf(ctx, s)[0] ?? s.on,
|
|
1152
|
-
'borderRadius',
|
|
1153
|
-
s.when,
|
|
1154
|
-
) ?? '',
|
|
1155
|
-
)?.[1]
|
|
1156
|
-
: null) ?? '--radius-element';
|
|
1382
|
+
const token = s.on
|
|
1383
|
+
? radiusTokenOf(ctx, partsOf(ctx, s)[0] ?? s.on, s.when)
|
|
1384
|
+
: '--radius-element';
|
|
1157
1385
|
// What the part shows: a setting on it or on its group (the later
|
|
1158
1386
|
// one wins), else a whole-theme setting, else the base theme.
|
|
1159
1387
|
const fam = s.on ? familyOf(s.on) : null;
|
|
1388
|
+
// A setting reaches the part when it is on the part itself, on its
|
|
1389
|
+
// group, or spread from a member (pill on text-input reaches the
|
|
1390
|
+
// whole inputs group). One for the same variant and state wins,
|
|
1391
|
+
// else the part's plain one (it applies there too).
|
|
1392
|
+
const part = partsOf(ctx, s)[0] ?? s.on;
|
|
1393
|
+
const reaches = (/** @type {import('./_settings.mjs').Setting} */ x) =>
|
|
1394
|
+
x.thing === 'corners' &&
|
|
1395
|
+
x.on &&
|
|
1396
|
+
(x.on === s.on ||
|
|
1397
|
+
(fam && fam !== s.on && x.on === fam && !x.only) ||
|
|
1398
|
+
(!x.only && partsOf(ctx, x).includes(part)));
|
|
1160
1399
|
const onPart = s.on
|
|
1161
|
-
? [...data.settings]
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1400
|
+
? ([...data.settings]
|
|
1401
|
+
.reverse()
|
|
1402
|
+
.find(
|
|
1403
|
+
x =>
|
|
1404
|
+
reaches(x) &&
|
|
1405
|
+
(x.when ?? '') === (s.when ?? '') &&
|
|
1406
|
+
(x.state ?? '') === (s.state ?? ''),
|
|
1407
|
+
) ??
|
|
1408
|
+
(s.when || s.state
|
|
1409
|
+
? [...data.settings]
|
|
1410
|
+
.reverse()
|
|
1411
|
+
.find(x => reaches(x) && !x.when && !x.state)
|
|
1412
|
+
: undefined))
|
|
1170
1413
|
: undefined;
|
|
1171
1414
|
// A step on a member set alone stays on that member alone.
|
|
1172
1415
|
if (onPart && onPart.on === s.on && onPart.only && !s.only)
|
|
@@ -1176,15 +1419,34 @@ export function checkSetting(
|
|
|
1176
1419
|
.find(x => x.thing === 'corners' && !x.on);
|
|
1177
1420
|
const isRung = (/** @type {string} */ x) =>
|
|
1178
1421
|
CORNERS.some(([n]) => n === x);
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1422
|
+
// An exact border-radius on the part wins over any corners dial:
|
|
1423
|
+
// that is what it shows, and a step starts from it.
|
|
1424
|
+
const exactRadius = s.on
|
|
1425
|
+
? [...data.settings]
|
|
1426
|
+
.reverse()
|
|
1427
|
+
.find(
|
|
1428
|
+
x =>
|
|
1429
|
+
x.source === 'property' &&
|
|
1430
|
+
x.thing === 'border-radius' &&
|
|
1431
|
+
x.on &&
|
|
1432
|
+
partsOf(ctx, x).includes(part) &&
|
|
1433
|
+
(x.when ?? '') === (s.when ?? '') &&
|
|
1434
|
+
(x.state ?? '') === (s.state ?? ''),
|
|
1435
|
+
)
|
|
1436
|
+
: undefined;
|
|
1437
|
+
const exactPx = exactRadius ? lengthPx(exactRadius.value) : null;
|
|
1438
|
+
const shown =
|
|
1439
|
+
exactPx != null
|
|
1440
|
+
? exactPx
|
|
1441
|
+
: onPart
|
|
1442
|
+
? isRung(onPart.value) || cornerPxOf(onPart.value) >= 1000
|
|
1443
|
+
? radiusAt(base, onPart.value, token)
|
|
1444
|
+
: cornerPxOf(onPart.value)
|
|
1445
|
+
: whole
|
|
1446
|
+
? radiusAt(base, whole.value, token)
|
|
1447
|
+
: // The base theme's radius; one it does not give in px (a var()
|
|
1448
|
+
// chain) counts as medium's.
|
|
1449
|
+
(tokenPx(base, token) ?? radiusAt(base, 'medium', token));
|
|
1188
1450
|
const rungs = CORNERS.map(
|
|
1189
1451
|
([n]) => /** @type {const} */ ([n, radiusAt(base, n, token)]),
|
|
1190
1452
|
);
|
|
@@ -1192,13 +1454,18 @@ export function checkSetting(
|
|
|
1192
1454
|
v === 'more'
|
|
1193
1455
|
? rungs.find(([, n]) => n > shown + 0.01)
|
|
1194
1456
|
: [...rungs].reverse().find(([, n]) => n < shown - 0.01);
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1457
|
+
// No rung that way: nothing is written, as for spacing.
|
|
1458
|
+
if (!next && !Number.isNaN(shown))
|
|
1459
|
+
refuse(
|
|
1460
|
+
E.ERR_THEME_NO_EFFECT,
|
|
1461
|
+
`corners is already at the ${v === 'more' ? 'roundest' : 'squarest'} rung ${s.on ? `on ${s.on}` : 'for the theme'}, so ${v} has nowhere to go.`,
|
|
1462
|
+
{
|
|
1463
|
+
run: [
|
|
1464
|
+
setLine(slug, 'corners', v === 'more' ? 'less' : 'more', s),
|
|
1465
|
+
],
|
|
1466
|
+
},
|
|
1467
|
+
);
|
|
1468
|
+
s.value = next ? next[0] : 'medium';
|
|
1202
1469
|
} else {
|
|
1203
1470
|
// A rung in any case, a size in px written any way: the plain form.
|
|
1204
1471
|
const lower = v.toLowerCase();
|
|
@@ -1207,12 +1474,31 @@ export function checkSetting(
|
|
|
1207
1474
|
else if (px) s.value = `${Number(px[1])}px`;
|
|
1208
1475
|
else if (lower === '0') s.value = 'square';
|
|
1209
1476
|
else {
|
|
1210
|
-
// What it most likely means, as a value corners takes
|
|
1211
|
-
|
|
1477
|
+
// What it most likely means, as a value corners takes: a simple
|
|
1478
|
+
// calc() of px is worked out.
|
|
1479
|
+
const calc =
|
|
1480
|
+
/^calc\(\s*(\d*\.?\d+)px\s*([*/+-])\s*(\d*\.?\d+)(px)?\s*\)$/.exec(
|
|
1481
|
+
lower,
|
|
1482
|
+
);
|
|
1483
|
+
const calcPx = calc
|
|
1484
|
+
? {
|
|
1485
|
+
'*': Number(calc[1]) * Number(calc[3]),
|
|
1486
|
+
'/': Number(calc[1]) / Number(calc[3]),
|
|
1487
|
+
'+': Number(calc[1]) + Number(calc[3]),
|
|
1488
|
+
'-': Number(calc[1]) - Number(calc[3]),
|
|
1489
|
+
}[/** @type {'*' | '/' | '+' | '-'} */ (calc[2])]
|
|
1490
|
+
: null;
|
|
1491
|
+
const len =
|
|
1492
|
+
calcPx != null && Number.isFinite(calcPx)
|
|
1493
|
+
? calcPx
|
|
1494
|
+
: lengthPx(lower);
|
|
1212
1495
|
const pct = /^(\d+(?:\.\d+)?)%$/.exec(lower);
|
|
1496
|
+
// A radius below zero means none: square.
|
|
1213
1497
|
const meant =
|
|
1214
1498
|
len != null
|
|
1215
|
-
?
|
|
1499
|
+
? len <= 0
|
|
1500
|
+
? 'square'
|
|
1501
|
+
: `${Math.round(len * 100) / 100}px`
|
|
1216
1502
|
: pct
|
|
1217
1503
|
? Number(pct[1]) >= 50
|
|
1218
1504
|
? 'pill'
|
|
@@ -1226,9 +1512,8 @@ export function checkSetting(
|
|
|
1226
1512
|
`corners takes ${DIALS.corners.values}, not "${v}".`,
|
|
1227
1513
|
{
|
|
1228
1514
|
...(meant ? {didYouMean: [meant]} : {}),
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
],
|
|
1515
|
+
// The same scope, flags included.
|
|
1516
|
+
run: [setLine(slug, 'corners', meant ?? 'medium', s)],
|
|
1232
1517
|
},
|
|
1233
1518
|
);
|
|
1234
1519
|
}
|
|
@@ -1242,7 +1527,11 @@ export function checkSetting(
|
|
|
1242
1527
|
`spacing does not change in a state; drop --state.`,
|
|
1243
1528
|
{
|
|
1244
1529
|
run: [
|
|
1245
|
-
|
|
1530
|
+
setLine(slug, 'spacing', v || 'roomy', {
|
|
1531
|
+
...s,
|
|
1532
|
+
state: undefined,
|
|
1533
|
+
mode: undefined,
|
|
1534
|
+
}),
|
|
1246
1535
|
],
|
|
1247
1536
|
},
|
|
1248
1537
|
);
|
|
@@ -1264,7 +1553,27 @@ export function checkSetting(
|
|
|
1264
1553
|
{run: [`${P} set ${slug} padding 8px${onFlag}`]},
|
|
1265
1554
|
);
|
|
1266
1555
|
}
|
|
1556
|
+
// A scale typed as a number (x0.75, 0.75, 75%) names the rung nearest
|
|
1557
|
+
// that factor.
|
|
1558
|
+
const factor = /^x?(\d*\.?\d+)(%)?$/i.exec(v);
|
|
1559
|
+
const nearFactor = factor
|
|
1560
|
+
? SPACING.reduce((a, b) =>
|
|
1561
|
+
Math.abs(b[1] - Number(factor[1]) / (factor[2] ? 100 : 1)) <
|
|
1562
|
+
Math.abs(a[1] - Number(factor[1]) / (factor[2] ? 100 : 1))
|
|
1563
|
+
? b
|
|
1564
|
+
: a,
|
|
1565
|
+
)[0]
|
|
1566
|
+
: null;
|
|
1267
1567
|
if (step) s.value = ladder(SPACING, 'medium');
|
|
1568
|
+
else if (!SPACING.some(([n]) => n === v) && nearFactor)
|
|
1569
|
+
refuse(
|
|
1570
|
+
E.ERR_THEME_BAD_VALUE,
|
|
1571
|
+
`spacing takes ${DIALS.spacing.values}, not "${v}"; the rung nearest that scale is ${nearFactor} (x${SPACING.find(([n]) => n === nearFactor)?.[1]}).`,
|
|
1572
|
+
{
|
|
1573
|
+
didYouMean: [nearFactor],
|
|
1574
|
+
run: [setLine(slug, 'spacing', nearFactor, s)],
|
|
1575
|
+
},
|
|
1576
|
+
);
|
|
1268
1577
|
else if (!SPACING.some(([n]) => n === v))
|
|
1269
1578
|
refuse(
|
|
1270
1579
|
E.ERR_THEME_BAD_VALUE,
|
|
@@ -1274,6 +1583,17 @@ export function checkSetting(
|
|
|
1274
1583
|
v,
|
|
1275
1584
|
SPACING.map(([n]) => n),
|
|
1276
1585
|
),
|
|
1586
|
+
run: [
|
|
1587
|
+
setLine(
|
|
1588
|
+
slug,
|
|
1589
|
+
'spacing',
|
|
1590
|
+
nearest(
|
|
1591
|
+
v,
|
|
1592
|
+
SPACING.map(([n]) => n),
|
|
1593
|
+
)[0] ?? 'roomy',
|
|
1594
|
+
s,
|
|
1595
|
+
),
|
|
1596
|
+
],
|
|
1277
1597
|
},
|
|
1278
1598
|
);
|
|
1279
1599
|
} else if (thing === 'text-size') {
|
|
@@ -1291,7 +1611,21 @@ export function checkSetting(
|
|
|
1291
1611
|
refuse(
|
|
1292
1612
|
E.ERR_THEME_BAD_VALUE,
|
|
1293
1613
|
`text-size takes ${DIALS['text-size'].values} (a number is the body size in pixels, 10 to 32), not "${v}".`,
|
|
1294
|
-
|
|
1614
|
+
(() => {
|
|
1615
|
+
// A rung in other letter case (Medium) or with px is that rung.
|
|
1616
|
+
const near =
|
|
1617
|
+
TEXT_SIZE.find(([n]) => n === v.trim().toLowerCase())?.[0] ??
|
|
1618
|
+
nearest(
|
|
1619
|
+
v.trim().toLowerCase(),
|
|
1620
|
+
TEXT_SIZE.map(([n]) => n),
|
|
1621
|
+
)[0];
|
|
1622
|
+
return near
|
|
1623
|
+
? {
|
|
1624
|
+
didYouMean: [near],
|
|
1625
|
+
run: [`${P} set ${slug} text-size ${near}`],
|
|
1626
|
+
}
|
|
1627
|
+
: {run: [`${P} set ${slug} text-size 16`]};
|
|
1628
|
+
})(),
|
|
1295
1629
|
);
|
|
1296
1630
|
else if (!TEXT_SIZE.some(([n]) => n === v))
|
|
1297
1631
|
s.value = String(Number(v.trim()));
|
|
@@ -1398,32 +1732,90 @@ export function checkSetting(
|
|
|
1398
1732
|
],
|
|
1399
1733
|
},
|
|
1400
1734
|
);
|
|
1401
|
-
if (s.on && !isRole)
|
|
1735
|
+
if (s.on && !isRole) {
|
|
1736
|
+
// A CSS font shorthand goes to its longhands, each a command that
|
|
1737
|
+
// works; a value that is neither gets a family that works.
|
|
1738
|
+
// Every part of a font shorthand (or a lone keyword: bold) goes to
|
|
1739
|
+
// its own longhand; a family list is a family list.
|
|
1740
|
+
const parts = fontShorthandParts(v);
|
|
1741
|
+
const family = !parts && matchValue('font-family', v);
|
|
1742
|
+
const example = `${P} set ${slug} font-family ${quoteCommandArgument(exampleOf('font', 'font-family'))} --on ${s.on}`;
|
|
1743
|
+
const runs = parts
|
|
1744
|
+
? parts.system
|
|
1745
|
+
? [example]
|
|
1746
|
+
: Object.entries(parts).map(
|
|
1747
|
+
([k, x]) =>
|
|
1748
|
+
`${P} set ${slug} ${k} ${quoteCommandArgument(x)} --on ${s.on}`,
|
|
1749
|
+
)
|
|
1750
|
+
: family
|
|
1751
|
+
? [
|
|
1752
|
+
`${P} set ${slug} font-family ${quoteCommandArgument(v)} --on ${s.on}`,
|
|
1753
|
+
]
|
|
1754
|
+
: [example];
|
|
1402
1755
|
refuse(
|
|
1403
1756
|
E.ERR_THEME_BAD_VALUE,
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
],
|
|
1409
|
-
},
|
|
1757
|
+
parts?.system
|
|
1758
|
+
? `font --on takes body, heading, or code, and "${v}" is a system font keyword of the CSS font shorthand, which sets every part of the font at once. For one part's font use font-family with a family.`
|
|
1759
|
+
: `font --on takes body, heading, or code. For one part's font use font-family${parts ? ', and the other parts of the font shorthand one by one' : ''}.`,
|
|
1760
|
+
{run: runs},
|
|
1410
1761
|
);
|
|
1762
|
+
}
|
|
1411
1763
|
if (step)
|
|
1412
1764
|
refuse(
|
|
1413
1765
|
E.ERR_THEME_BAD_VALUE,
|
|
1414
1766
|
'font takes a preset or a family name, not a step.',
|
|
1415
|
-
{
|
|
1767
|
+
{
|
|
1768
|
+
fix: `the values are ${DIALS.font.values}`,
|
|
1769
|
+
run: [`${P} set ${slug} font inter`, `${HOW} font`],
|
|
1770
|
+
},
|
|
1416
1771
|
);
|
|
1417
1772
|
// A family list: names, quoted or not, split by commas; nothing that
|
|
1418
1773
|
// could end the CSS declaration or the preview's style block. A
|
|
1419
1774
|
// preset typed in another case or spacing is the preset.
|
|
1420
1775
|
s.value = v.trim();
|
|
1776
|
+
// A function (var(), env()) is no family name: the dial would quote
|
|
1777
|
+
// it as one. The role's token takes it as written.
|
|
1778
|
+
if (/[a-z-]+\(/i.test(s.value)) {
|
|
1779
|
+
const role = s.on && FONT_ROLES.includes(s.on) ? s.on : 'body';
|
|
1780
|
+
refuse(
|
|
1781
|
+
E.ERR_THEME_BAD_VALUE,
|
|
1782
|
+
`font takes a preset or family names, not "${s.value}". To make ${s.on ? `the ${role} font` : 'a font'} read another token, set the token itself.`,
|
|
1783
|
+
{
|
|
1784
|
+
// The token's own rules decide: a value it refuses too is never
|
|
1785
|
+
// offered; a family name is.
|
|
1786
|
+
run: (() => {
|
|
1787
|
+
try {
|
|
1788
|
+
checkSetting(
|
|
1789
|
+
ctx,
|
|
1790
|
+
slug,
|
|
1791
|
+
data,
|
|
1792
|
+
`--font-family-${role}`,
|
|
1793
|
+
s.value,
|
|
1794
|
+
{},
|
|
1795
|
+
);
|
|
1796
|
+
return [
|
|
1797
|
+
`${P} set ${slug} --font-family-${role} ${quoteCommandArgument(s.value)}`,
|
|
1798
|
+
];
|
|
1799
|
+
} catch {
|
|
1800
|
+
return [`${P} set ${slug} font inter`, `${HOW} font`];
|
|
1801
|
+
}
|
|
1802
|
+
})(),
|
|
1803
|
+
},
|
|
1804
|
+
);
|
|
1805
|
+
}
|
|
1421
1806
|
// A font package names its preset: @fontsource/inter is inter.
|
|
1422
1807
|
const fromPackage = /^@fontsource(?:-variable)?\/([a-z0-9-]+)$/i.exec(
|
|
1423
1808
|
s.value,
|
|
1424
1809
|
)?.[1];
|
|
1425
1810
|
if (fromPackage && OPEN_FONTS[fromPackage.toLowerCase()])
|
|
1426
1811
|
s.value = fromPackage.toLowerCase();
|
|
1812
|
+
// A preset's package name (geist-sans for geist) is that preset.
|
|
1813
|
+
const byPackage = Object.keys(OPEN_FONTS).find(
|
|
1814
|
+
k =>
|
|
1815
|
+
OPEN_FONTS[k].pkg.split('/')[1] ===
|
|
1816
|
+
(fromPackage ?? s.value).toLowerCase(),
|
|
1817
|
+
);
|
|
1818
|
+
if (byPackage) s.value = byPackage;
|
|
1427
1819
|
const key = s.value.toLowerCase().replace(/[\s_-]+/g, '');
|
|
1428
1820
|
const preset = [...Object.keys(FONTS), ...Object.keys(OPEN_FONTS)].find(
|
|
1429
1821
|
k => k.toLowerCase().replace(/[\s_-]+/g, '') === key,
|
|
@@ -1563,8 +1955,17 @@ export function checkSetting(
|
|
|
1563
1955
|
refuse(
|
|
1564
1956
|
E.ERR_THEME_BAD_VALUE,
|
|
1565
1957
|
`"more"/"less" work only on dials (${Object.keys(DIALS).join(', ')}). Give ${thing} a ${type} value.`,
|
|
1958
|
+
{run: [setLine(slug, thing, exampleOf(type, thing), s)]},
|
|
1566
1959
|
);
|
|
1567
|
-
checkTypedValue(
|
|
1960
|
+
checkTypedValue(
|
|
1961
|
+
type,
|
|
1962
|
+
v,
|
|
1963
|
+
thing,
|
|
1964
|
+
TOKENS,
|
|
1965
|
+
C.typeOf,
|
|
1966
|
+
slug,
|
|
1967
|
+
C.propsReading(thing),
|
|
1968
|
+
);
|
|
1568
1969
|
checkCycle(thing, v, TOKENS, data);
|
|
1569
1970
|
// With no part data, what reads the token is unknown: save, unchecked.
|
|
1570
1971
|
if (ctx.unchecked) return s;
|
|
@@ -1630,7 +2031,7 @@ export function checkSetting(
|
|
|
1630
2031
|
also: r0.also,
|
|
1631
2032
|
});
|
|
1632
2033
|
} else if (hard.length)
|
|
1633
|
-
s.note = `
|
|
2034
|
+
s.note = `the editor's render of ${hard.map(([t]) => t).join(', ')} did not read ${thing} (each part is rendered once, with its default props, so a variant that reads it may be missed); it is set as asked`;
|
|
1634
2035
|
if (!s.note && recorded.length) {
|
|
1635
2036
|
const fed = C.feeds(recorded[0][0], thing);
|
|
1636
2037
|
if (fed.length) s.note = `feeds ${C.fmtFeeds(fed, recorded[0][0])}`;
|
|
@@ -1656,6 +2057,8 @@ export function checkSetting(
|
|
|
1656
2057
|
// name a token `set` refuses.
|
|
1657
2058
|
if (r && fed.length)
|
|
1658
2059
|
s.note = `no part reads ${thing} itself, but ${fed.slice(0, 4).join(', ')} ${fed.length > 1 ? 'are' : 'is'} built from it, so the change shows wherever ${fed.length > 1 ? 'those are' : 'that is'} used${fed.some(k => k.startsWith('--color-syntax-')) ? ' (such as diff rows in code blocks)' : ''}`;
|
|
2060
|
+
else if (r && data.like && baseReads(ctx, data.like, thing))
|
|
2061
|
+
s.note = `the ${data.like} theme's own part styles read ${thing}, so the change shows where they use it`;
|
|
1659
2062
|
else if (r && dialWrites(thing))
|
|
1660
2063
|
s.note = `no part of this Core reads ${thing}, and no token it feeds is read, so it changes nothing you see now; it is set as asked because a dial writes it too`;
|
|
1661
2064
|
// The editor's record of what parts read comes from one render of
|
|
@@ -1668,7 +2071,22 @@ export function checkSetting(
|
|
|
1668
2071
|
return s;
|
|
1669
2072
|
}
|
|
1670
2073
|
const prop = kebab(thing);
|
|
1671
|
-
|
|
2074
|
+
// A dial typed in other letters (Font, FONT) is the dial, not the CSS
|
|
2075
|
+
// property of the same name.
|
|
2076
|
+
if (thing !== thing.toLowerCase() && DIALS[thing.toLowerCase()])
|
|
2077
|
+
refuse(
|
|
2078
|
+
E.ERR_THEME_UNKNOWN_THING,
|
|
2079
|
+
`"${thing}" is not a dial, a token, or a CSS property. The dial for that is ${thing.toLowerCase()}.`,
|
|
2080
|
+
{
|
|
2081
|
+
didYouMean: [thing.toLowerCase()],
|
|
2082
|
+
run: [
|
|
2083
|
+
unset
|
|
2084
|
+
? `${P} undo ${slug} ${thing.toLowerCase()}${s.on ? ` --on ${s.on}` : ''}`
|
|
2085
|
+
: `${P} set ${slug} ${thing.toLowerCase()} ${quoteCommandArgument(v || 'inter')}${s.on ? ` --on ${s.on}` : ''}`,
|
|
2086
|
+
],
|
|
2087
|
+
},
|
|
2088
|
+
);
|
|
2089
|
+
if (cssProperties().has(prop)) {
|
|
1672
2090
|
if (!s.on)
|
|
1673
2091
|
refuse(
|
|
1674
2092
|
E.ERR_MISSING_ARGUMENT,
|
|
@@ -1683,9 +2101,8 @@ export function checkSetting(
|
|
|
1683
2101
|
s.source = 'property';
|
|
1684
2102
|
s.thing = prop;
|
|
1685
2103
|
if (unset) return s;
|
|
1686
|
-
// Text, headings and links take their color from the color prop
|
|
1687
|
-
|
|
1688
|
-
const textParts = ['text', 'heading', 'link'];
|
|
2104
|
+
// Text, headings and links take their color from the color prop.
|
|
2105
|
+
const textParts = COLOR_PROP_PARTS;
|
|
1689
2106
|
if (
|
|
1690
2107
|
(prop === 'color' || prop === '-webkit-text-fill-color') &&
|
|
1691
2108
|
partsOf(ctx, s).some(t => textParts.includes(t))
|
|
@@ -1770,6 +2187,7 @@ export function checkSetting(
|
|
|
1770
2187
|
refuse(
|
|
1771
2188
|
E.ERR_THEME_BAD_VALUE,
|
|
1772
2189
|
`"more"/"less" work only on dials. Give ${prop} an exact CSS value.`,
|
|
2190
|
+
{run: [`${HOW} ${prop}`]},
|
|
1773
2191
|
);
|
|
1774
2192
|
const grammar = propertyProblem(prop, v);
|
|
1775
2193
|
if (grammar)
|
|
@@ -1782,12 +2200,17 @@ export function checkSetting(
|
|
|
1782
2200
|
: {}),
|
|
1783
2201
|
run: grammar.near
|
|
1784
2202
|
? [
|
|
1785
|
-
|
|
2203
|
+
// The same scope, --only included.
|
|
2204
|
+
setLine(slug, prop, grammar.near, s),
|
|
1786
2205
|
]
|
|
1787
2206
|
: [`${HOW} ${prop}`],
|
|
1788
2207
|
},
|
|
1789
2208
|
);
|
|
1790
|
-
if (
|
|
2209
|
+
if (
|
|
2210
|
+
COLOR_PROPS.test(prop) &&
|
|
2211
|
+
!CSS_WIDE.includes(v.trim().toLowerCase()) &&
|
|
2212
|
+
(!isColorValue(v) || !isFixedColor(v))
|
|
2213
|
+
) {
|
|
1791
2214
|
refuse(
|
|
1792
2215
|
E.ERR_THEME_BAD_VALUE,
|
|
1793
2216
|
`${prop} takes a color; "${v}" is not one.${/gradient/.test(v) ? ' Gradients go in background.' : ''}`,
|
|
@@ -1796,11 +2219,14 @@ export function checkSetting(
|
|
|
1796
2219
|
? [
|
|
1797
2220
|
`${P} set ${slug} background ${quoteCommandArgument(v)} --on ${s.on}`,
|
|
1798
2221
|
]
|
|
1799
|
-
: [
|
|
2222
|
+
: [
|
|
2223
|
+
`${P} set ${slug} ${prop} ${quoteCommandArgument(nearestColorName(v) ?? exampleOf('color', prop))} --on ${s.on}${s.when ? ` --when ${s.when}` : ''}${s.state ? ` --state ${s.state}` : ''}${s.mode ? ` --mode ${s.mode}` : ''}`,
|
|
2224
|
+
],
|
|
1800
2225
|
},
|
|
1801
2226
|
);
|
|
1802
2227
|
}
|
|
1803
|
-
|
|
2228
|
+
// Every scope flag but --mode carries into the runs.
|
|
2229
|
+
const whenFlag = `${s.when ? ` --when ${s.when}` : ''}${s.state ? ` --state ${s.state}` : ''}${s.only ? ' --only' : ''}`;
|
|
1804
2230
|
if (
|
|
1805
2231
|
s.mode &&
|
|
1806
2232
|
!COLOR_PROPS.test(prop) &&
|
|
@@ -1862,7 +2288,7 @@ export function checkSetting(
|
|
|
1862
2288
|
const meant = kebab(String(thing).trim().replace(/:$/, ''))
|
|
1863
2289
|
.replace(/[_\s]+/g, '-')
|
|
1864
2290
|
.replace(/-+/g, '-');
|
|
1865
|
-
if (meant !== prop &&
|
|
2291
|
+
if (meant !== prop && cssProperties().has(meant))
|
|
1866
2292
|
refuse(
|
|
1867
2293
|
E.ERR_THEME_UNKNOWN_THING,
|
|
1868
2294
|
`"${thing}" is not a dial, a token, or a CSS property; the property is ${meant}.`,
|
|
@@ -1919,7 +2345,7 @@ export function checkSetting(
|
|
|
1919
2345
|
[`${HOW} --list properties`, `${HOW} --list dials`],
|
|
1920
2346
|
didYouMean: hint
|
|
1921
2347
|
? []
|
|
1922
|
-
: nearest(prop, [...Object.keys(DIALS), ...
|
|
2348
|
+
: nearest(prop, [...Object.keys(DIALS), ...cssProperties()]),
|
|
1923
2349
|
},
|
|
1924
2350
|
);
|
|
1925
2351
|
}
|
|
@@ -1952,9 +2378,8 @@ function refuseInvisibleCorners(ctx, slug, s, data) {
|
|
|
1952
2378
|
`${s.on} has no background, border or shadow of its own, so rounding its corners changes nothing you see.${kids.length ? ` Parts inside it that do show an edge: ${kids.join(', ')}.` : ''}`,
|
|
1953
2379
|
{
|
|
1954
2380
|
run: kids.length
|
|
1955
|
-
? kids.map(
|
|
1956
|
-
k
|
|
1957
|
-
`${P} set ${slug} corners ${quoteCommandArgument(s.value || 'round')} --on ${k}`,
|
|
2381
|
+
? kids.map(k =>
|
|
2382
|
+
setLine(slug, 'corners', s.value || 'round', {...s, on: k}),
|
|
1958
2383
|
)
|
|
1959
2384
|
: [`${HOW} ${s.on}`],
|
|
1960
2385
|
},
|