@astryxdesign/cli 0.7.14 → 0.7.15-canary.g06b7e61
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +3 -3
- package/README.md +63 -63
- package/api/build/_adapter.d.mts +4 -0
- package/api/build/_adapter.mjs +28 -2
- package/api/build/blocks/blocks.d.mts +10 -1
- package/api/build/blocks/blocks.mjs +84 -7
- package/api/build/build.mjs +6 -1
- package/api/build/tree.d.mts +4 -0
- package/api/build/tree.mjs +9 -2
- package/api/doctor/_adapter.d.mts +3 -1
- package/api/doctor/_adapter.mjs +14 -1
- package/api/doctor/_authoring-audit.d.mts +42 -0
- package/api/doctor/_authoring-audit.mjs +106 -0
- package/api/doctor/doctor.d.mts +7 -0
- package/api/doctor/doctor.mjs +24 -39
- package/api/doctor/theme-checks.mjs +56 -21
- package/api/integration/add-helpers.mjs +5 -0
- package/api/integration/add-theme.mjs +15 -110
- package/api/integration/validate-integration.mjs +17 -3
- package/api/integration/validateIntegration.doc.mjs +1 -1
- package/api/search/_adapter.mjs +124 -3
- package/api/search/_candidate-score.mjs +63 -9
- package/api/search/_entries.d.mts +10 -0
- package/api/search/_entries.mjs +68 -1
- package/api/search/_gather-templates.d.mts +11 -0
- package/api/search/_gather-templates.mjs +22 -2
- package/api/search/_words.mjs +26 -6
- package/api/swizzle/copy/copy.mjs +1 -1
- package/api/theme/_adapter.d.mts +37 -5
- package/api/theme/_adapter.mjs +381 -57
- package/api/theme/_fork.d.mts +90 -0
- package/api/theme/_fork.mjs +246 -0
- package/api/theme/build/build.d.mts +40 -2
- package/api/theme/build/build.mjs +477 -66
- package/api/theme/eject/eject.mjs +36 -15
- package/api/theme/list/list.mjs +3 -6
- package/api/theme/palette/generate/generator.d.mts +13 -0
- package/api/theme/palette/generate/generator.mjs +32 -2
- package/api/theme/targets/targets.d.mts +8 -0
- package/api/theme/targets/targets.mjs +24 -4
- package/api/theme/template/template.mjs +48 -2
- package/api/theme/theme.type.d.mts +8 -0
- package/api/theme/theme.type.mjs +5 -1
- package/api/theme/themeBuild.doc.mjs +7 -4
- package/api/theme/themeEject.doc.mjs +3 -3
- package/api/theme/themeRemove.doc.mjs +5 -2
- package/api/theme/themeTargets.doc.mjs +1 -1
- package/api/theme/themeTemplate.doc.mjs +2 -2
- package/api/theme/themeUse.doc.mjs +8 -2
- package/api/theme-edit/_adapter.d.mts +46 -3
- package/api/theme-edit/_adapter.mjs +496 -112
- package/api/theme-edit/_catalog.d.mts +1 -6
- package/api/theme-edit/_catalog.mjs +5 -268
- package/api/theme-edit/_check.d.mts +9 -4
- package/api/theme-edit/_check.mjs +1232 -229
- package/api/theme-edit/_color.d.mts +19 -0
- package/api/theme-edit/_color.mjs +280 -34
- package/api/theme-edit/_compiler.d.mts +3 -1
- package/api/theme-edit/_compiler.mjs +52 -13
- package/api/theme-edit/_context.d.mts +4 -1
- package/api/theme-edit/_context.mjs +126 -13
- package/api/theme-edit/_css.d.mts +84 -0
- package/api/theme-edit/_css.mjs +700 -0
- package/api/theme-edit/_edit.d.mts +9 -3
- package/api/theme-edit/_edit.mjs +806 -103
- package/api/theme-edit/_how-commands.d.mts +38 -7
- package/api/theme-edit/_how-commands.mjs +64 -45
- package/api/theme-edit/_how-question.d.mts +33 -0
- package/api/theme-edit/_how-question.mjs +2553 -381
- package/api/theme-edit/_how.mjs +402 -31
- package/api/theme-edit/_overview.mjs +2 -7
- package/api/theme-edit/_palette.d.mts +60 -13
- package/api/theme-edit/_palette.mjs +826 -295
- package/api/theme-edit/_parts.d.mts +42 -10
- package/api/theme-edit/_parts.mjs +280 -69
- package/api/theme-edit/_png.d.mts +4 -4
- package/api/theme-edit/_png.mjs +4 -2
- package/api/theme-edit/_preview-app.d.mts +14 -0
- package/api/theme-edit/_preview-app.mjs +1675 -235
- package/api/theme-edit/_preview.d.mts +7 -16
- package/api/theme-edit/_preview.mjs +79 -86
- package/api/theme-edit/_project.d.mts +32 -2
- package/api/theme-edit/_project.mjs +80 -19
- package/api/theme-edit/_settings.d.mts +199 -52
- package/api/theme-edit/_settings.mjs +1422 -217
- package/api/theme-edit/_tables.d.mts +19 -6
- package/api/theme-edit/_tables.mjs +150 -92
- package/api/theme-edit/theme-edit.type.d.mts +20 -1
- package/api/theme-edit/theme-edit.type.mjs +6 -3
- package/api/theme-edit/themeEditHow.doc.mjs +6 -0
- package/api/theme-edit/themeEditNew.doc.mjs +1 -1
- package/api/theme-edit/themeEditPreviewAdd.doc.mjs +1 -1
- package/api/theme-edit/themeEditPreviewApp.doc.mjs +1 -1
- package/api/theme-edit/themeEditPreviewList.doc.mjs +2 -2
- package/api/theme-edit/themeEditPreviewRemove.doc.mjs +5 -1
- package/api/theme-edit/themeEditSet.doc.mjs +1 -1
- package/api/theme-edit/themeEditUndo.doc.mjs +1 -1
- package/api/upgrade/_adapter.d.mts +1 -0
- package/assets/codemods/run-codemod.mjs +61 -0
- package/assets/codemods/runner.mjs +5 -4
- package/assets/codemods/transforms/v0.0.14/rename-status-variants.mjs +3 -0
- package/assets/codemods/transforms/v0.1.8/rename-avatar-size-scale.mjs +5 -1
- package/assets/codemods/transforms/v0.6.4/migrate-native-picker-to-presentation.mjs +3 -0
- package/assets/codemods/transforms/v0.7.0/migrate-deprecated-theme-surface.mjs +4 -0
- package/assets/codemods/transforms/v0.7.0/rename-empty-search-results-text.mjs +17 -12
- package/assets/codemods/transforms/v0.7.2/migrate-list-edge-compensation-to-edge.mjs +3 -0
- package/assets/codemods/transforms/v0.7.5/migrate-codeblock-tokenizer-to-language.mjs +3 -0
- package/assets/codemods/transforms/v0.7.8/promote-tokenizer-presentation.mjs +3 -0
- package/assets/docs/tree/calendars.doc.mjs +1 -3
- package/assets/docs/tree/checks.doc.mjs +22 -1
- package/assets/docs/tree/publishing.doc.mjs +1 -0
- package/assets/docs/tree/tokens-and-setup.doc.mjs +39 -3
- package/assets/docs.generated.json +2 -1
- package/assets/preview-app/next.config.mjs +7 -1
- package/assets/self-audit.generated.json +1 -0
- package/assets/templates/blocks/components/Theme/useThemeNameHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Theme/useThemeNameHookUsage.tsx +31 -0
- package/assets/templates/components.generated.json +1 -1
- package/authoring/integration/integration.doc.mjs +8 -0
- package/authoring/integration/schema.d.mts +8 -0
- package/authoring/integration/schema.mjs +1 -0
- package/authoring/integration/type.ts +9 -0
- package/clients/cli/bin/astryx.mjs +19 -15
- package/clients/cli/build-id.generated.json +1 -0
- package/clients/cli/commands/ensure-core-built.mjs +12 -5
- package/clients/cli/commands/experimental/index.mjs +10 -10
- package/clients/cli/commands/experimental/theme.mjs +200 -81
- package/clients/cli/commands/experimental-theme-compile.doc.mjs +3 -3
- package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +3 -3
- package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +1 -2
- package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-eject.doc.mjs +3 -3
- package/clients/cli/commands/experimental-theme-preview-add.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-preview-list.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-preview-remove.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-remove.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-template.doc.mjs +4 -3
- package/clients/cli/commands/integration.mjs +8 -0
- package/clients/cli/commands/manifest.mjs +5 -2
- package/clients/cli/commands/theme-build.doc.mjs +2 -2
- package/clients/cli/commands/theme-list.doc.mjs +1 -1
- package/clients/cli/commands/theme-template.doc.mjs +1 -1
- package/clients/cli/commands/theme.mjs +439 -66
- package/clients/cli/index.mjs +27 -6
- package/clients/cli/lib/cli-error.mjs +118 -3
- package/clients/cli/lib/manifest.mjs +37 -0
- package/clients/cli/lib/resolve-theme.mjs +2 -1
- package/clients/cli/manifest.generated.json +1 -0
- package/foundation/config/project.mjs +34 -8
- package/foundation/config/theme-state.d.mts +16 -0
- package/foundation/config/theme-state.mjs +84 -13
- package/foundation/discovery/module-exports.mjs +16 -2
- package/foundation/discovery/stored-self-audit.d.mts +31 -0
- package/foundation/discovery/stored-self-audit.mjs +119 -0
- package/foundation/discovery/template-adapter.d.mts +48 -2
- package/foundation/discovery/template-adapter.mjs +51 -19
- package/foundation/discovery/template-needs.d.mts +19 -0
- package/foundation/discovery/template-needs.mjs +50 -16
- package/foundation/discovery/template-source-tree.d.mts +7 -0
- package/foundation/discovery/template-source-tree.mjs +15 -0
- package/foundation/discovery/theme-discovery.d.mts +2 -1
- package/foundation/discovery/theme-discovery.mjs +16 -10
- package/foundation/discovery/theme-imports.d.mts +16 -0
- package/foundation/discovery/theme-imports.mjs +30 -2
- package/foundation/discovery/theme-module-extensions.d.mts +18 -0
- package/foundation/discovery/theme-module-extensions.mjs +30 -0
- package/foundation/doc-compiler/import.mjs +22 -15
- package/foundation/doc-compiler/stored-docs.d.mts +18 -12
- package/foundation/doc-compiler/stored-docs.mjs +52 -19
- package/foundation/env/private-dir.d.mts +17 -0
- package/foundation/env/private-dir.mjs +42 -0
- package/foundation/fs/gather-cache.d.mts +108 -0
- package/foundation/fs/gather-cache.mjs +783 -0
- package/foundation/fs/jiti-cache.d.mts +21 -0
- package/foundation/fs/jiti-cache.mjs +66 -0
- package/foundation/fs/module-loader.mjs +14 -3
- package/foundation/fs/read-record.d.mts +31 -1
- package/foundation/fs/read-record.mjs +100 -7
- package/foundation/integrations/autolink.d.mts +1 -24
- package/foundation/integrations/autolink.mjs +7 -60
- package/foundation/integrations/declared-dependencies.d.mts +27 -0
- package/foundation/integrations/declared-dependencies.mjs +73 -0
- package/foundation/integrations/integrations.d.mts +8 -0
- package/foundation/integrations/integrations.mjs +4 -0
- package/foundation/integrations/may-have-integrations.d.mts +8 -0
- package/foundation/integrations/may-have-integrations.mjs +47 -0
- package/foundation/integrations/validate-contributions.d.mts +62 -1
- package/foundation/integrations/validate-contributions.mjs +476 -40
- package/foundation/release/cache.d.mts +32 -4
- package/foundation/release/cache.mjs +105 -16
- package/foundation/release/folder-lock.d.mts +28 -0
- package/foundation/release/folder-lock.mjs +205 -0
- package/foundation/release/lock-lease.d.mts +2 -1
- package/foundation/release/lock-lease.mjs +7 -2
- package/foundation/response/error-codes.doc.mjs +1 -1
- package/foundation/response/response-types.doc.mjs +5 -5
- package/package.json +8 -6
- package/api/theme-edit/_css-properties.d.mts +0 -10
- package/api/theme-edit/_css-properties.mjs +0 -556
|
@@ -9,16 +9,34 @@
|
|
|
9
9
|
* @position api/theme-edit — checks over the part data
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
+
import * as fs from 'node:fs';
|
|
13
|
+
import * as path from 'node:path';
|
|
12
14
|
import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
|
|
15
|
+
import {baseThemeFile} from './_project.mjs';
|
|
13
16
|
import {levenshteinDistance} from '../../foundation/text/levenshtein.mjs';
|
|
14
|
-
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';
|
|
15
31
|
import {
|
|
16
32
|
AUTO_SPREAD,
|
|
33
|
+
COLOR_PROP_PARTS,
|
|
17
34
|
COLOR_PROPS,
|
|
18
35
|
COMMON_STATES,
|
|
19
36
|
CORNERS,
|
|
20
37
|
DIALS,
|
|
21
38
|
FAMILIES,
|
|
39
|
+
FONT_ROLES,
|
|
22
40
|
FONTS,
|
|
23
41
|
GROUPS,
|
|
24
42
|
HEADING_TRACKING,
|
|
@@ -26,6 +44,8 @@ import {
|
|
|
26
44
|
LIKE,
|
|
27
45
|
HOW,
|
|
28
46
|
OPEN_FONTS,
|
|
47
|
+
CSS_WIDE,
|
|
48
|
+
CSS_WIDE_KEYWORDS,
|
|
29
49
|
P,
|
|
30
50
|
SPACING,
|
|
31
51
|
TEXT_SIZE,
|
|
@@ -40,6 +60,8 @@ import {
|
|
|
40
60
|
isSafeValue,
|
|
41
61
|
isSize,
|
|
42
62
|
parseColor,
|
|
63
|
+
mixSide,
|
|
64
|
+
splitTop,
|
|
43
65
|
} from './_color.mjs';
|
|
44
66
|
import {
|
|
45
67
|
PALETTE_DIALS,
|
|
@@ -55,9 +77,47 @@ import {
|
|
|
55
77
|
nearest,
|
|
56
78
|
partDefault,
|
|
57
79
|
partsOf,
|
|
58
|
-
q,
|
|
59
80
|
refuse,
|
|
81
|
+
lengthPx,
|
|
82
|
+
radiusAt,
|
|
83
|
+
radiusTokenOf,
|
|
84
|
+
focusStateOf,
|
|
85
|
+
valueProblem,
|
|
60
86
|
} from './_settings.mjs';
|
|
87
|
+
import {quoteCommandArgument} from '../../foundation/env/package-manager.mjs';
|
|
88
|
+
|
|
89
|
+
export {lengthPx};
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* A token's value in px, following var() references through the tokens.
|
|
93
|
+
* @param {{light: Record<string, string>}} base
|
|
94
|
+
* @param {string} token
|
|
95
|
+
* @returns {number | null}
|
|
96
|
+
*/
|
|
97
|
+
function tokenPx(base, token) {
|
|
98
|
+
let v = base.light[token] ?? '';
|
|
99
|
+
for (let i = 0; i < 5; i++) {
|
|
100
|
+
const ref = /^\s*var\((--[\w-]+)\)\s*$/.exec(v);
|
|
101
|
+
if (!ref) break;
|
|
102
|
+
v = base.light[ref[1]] ?? '';
|
|
103
|
+
}
|
|
104
|
+
return lengthPx(v);
|
|
105
|
+
}
|
|
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
|
+
|
|
118
|
+
/** @param {string} v */
|
|
119
|
+
const cornerPxOf = v =>
|
|
120
|
+
CORNERS.find(([n]) => n === v)?.[1] ?? lengthPx(v) ?? Number.NaN;
|
|
61
121
|
|
|
62
122
|
const E = ERROR_CODES;
|
|
63
123
|
|
|
@@ -131,10 +191,55 @@ const COLOR_DIAL_WORDS = (() => {
|
|
|
131
191
|
* @param {string} slug
|
|
132
192
|
* @param {import('./_settings.mjs').ThemeData} data
|
|
133
193
|
* @param {string} [skip]
|
|
134
|
-
* @returns {{setting: import('./_settings.mjs').Setting, why: string}
|
|
194
|
+
* @returns {Array<{setting: import('./_settings.mjs').Setting, why: string, scope?: boolean}>} every saved setting the editor no longer accepts
|
|
135
195
|
*/
|
|
136
|
-
export function
|
|
196
|
+
export function storedProblems(ctx, slug, data, skip = '') {
|
|
197
|
+
/** @type {Array<{setting: import('./_settings.mjs').Setting, why: string, scope?: boolean}>} */
|
|
198
|
+
const found = [];
|
|
137
199
|
const TOKENS = ctx.project.core.tokenDefaults;
|
|
200
|
+
// Where each saved setting applies names a real part, group, state and
|
|
201
|
+
// variant of this Core, as `set` checks them.
|
|
202
|
+
const WHOLE_ONLY = [
|
|
203
|
+
'surfaces',
|
|
204
|
+
'buttons',
|
|
205
|
+
'base',
|
|
206
|
+
'mode',
|
|
207
|
+
'vibrancy',
|
|
208
|
+
'text-size',
|
|
209
|
+
'headings',
|
|
210
|
+
'type',
|
|
211
|
+
...PALETTE_DIALS,
|
|
212
|
+
];
|
|
213
|
+
for (const s of data.settings) {
|
|
214
|
+
if (s.thing === skip) continue;
|
|
215
|
+
/** @param {string} why */
|
|
216
|
+
const scope = why => ({setting: s, why, scope: true});
|
|
217
|
+
const problem = (() => {
|
|
218
|
+
const t = s.on ? ctx.project.target.get(s.on) : null;
|
|
219
|
+
if (
|
|
220
|
+
s.on &&
|
|
221
|
+
!t &&
|
|
222
|
+
!FAMILIES[s.on] &&
|
|
223
|
+
!(s.thing === 'font' && FONT_ROLES.includes(s.on))
|
|
224
|
+
)
|
|
225
|
+
return scope(`there is no part or group "${s.on}"`);
|
|
226
|
+
if (s.source === 'dial' && s.on && WHOLE_ONLY.includes(s.thing))
|
|
227
|
+
return scope(`${s.thing} applies to the whole theme, not to ${s.on}`);
|
|
228
|
+
if (s.mode && s.source === 'dial' && !PALETTE_DIALS.includes(s.thing))
|
|
229
|
+
return scope(`${s.thing} is the same in light and dark`);
|
|
230
|
+
if (t && s.state && ![...t.states, ...COMMON_STATES].includes(s.state))
|
|
231
|
+
return scope(`"${s.state}" is not a state of ${s.on}`);
|
|
232
|
+
if (t && s.when) {
|
|
233
|
+
const [prop, value] = String(s.when).split(':');
|
|
234
|
+
const values = ctx.C.variantValues(/** @type {string} */ (s.on));
|
|
235
|
+
if (!(prop in values)) return scope(`${s.on} has no prop "${prop}"`);
|
|
236
|
+
if (values[prop].length && !values[prop].includes(value))
|
|
237
|
+
return scope(`${s.on} has no ${prop} "${value}"`);
|
|
238
|
+
}
|
|
239
|
+
return null;
|
|
240
|
+
})();
|
|
241
|
+
if (problem) found.push(problem);
|
|
242
|
+
}
|
|
138
243
|
for (const s of data.settings) {
|
|
139
244
|
if (s.source !== 'token' || s.thing === skip || !(s.thing in TOKENS))
|
|
140
245
|
continue;
|
|
@@ -146,19 +251,20 @@ export function storedTokenProblem(ctx, slug, data, skip = '') {
|
|
|
146
251
|
TOKENS,
|
|
147
252
|
ctx.C.typeOf,
|
|
148
253
|
slug,
|
|
254
|
+
ctx.C.propsReading(s.thing),
|
|
149
255
|
);
|
|
150
256
|
checkCycle(s.thing, s.value, TOKENS, data);
|
|
151
257
|
} catch (e) {
|
|
152
|
-
|
|
258
|
+
found.push({
|
|
153
259
|
setting: s,
|
|
154
260
|
why:
|
|
155
261
|
e instanceof Error
|
|
156
262
|
? e.message.replace(/ Nothing was changed\.$/, '')
|
|
157
263
|
: String(e),
|
|
158
|
-
};
|
|
264
|
+
});
|
|
159
265
|
}
|
|
160
266
|
}
|
|
161
|
-
return
|
|
267
|
+
return found;
|
|
162
268
|
}
|
|
163
269
|
|
|
164
270
|
/**
|
|
@@ -198,20 +304,51 @@ function groupOfPropType(prop) {
|
|
|
198
304
|
* @param {Record<string, unknown>} TOKENS
|
|
199
305
|
* @param {(token: string) => string} typeOf
|
|
200
306
|
* @param {string} slug
|
|
307
|
+
* @param {string[]} [readers] the CSS properties that read the token
|
|
201
308
|
*/
|
|
202
|
-
function checkTypedValue(
|
|
309
|
+
function checkTypedValue(
|
|
310
|
+
type,
|
|
311
|
+
value,
|
|
312
|
+
name,
|
|
313
|
+
TOKENS,
|
|
314
|
+
typeOf,
|
|
315
|
+
slug,
|
|
316
|
+
readers = [],
|
|
317
|
+
) {
|
|
203
318
|
/** @param {string} what @param {string} example */
|
|
204
319
|
const bad = (what, example) =>
|
|
205
320
|
refuse(
|
|
206
321
|
E.ERR_THEME_BAD_VALUE,
|
|
207
322
|
`${name} is ${what}; "${value}" is not one.`,
|
|
208
|
-
{run: [`${P} set ${slug} ${name} ${
|
|
323
|
+
{run: [`${P} set ${slug} ${name} ${quoteCommandArgument(example)}`]},
|
|
209
324
|
);
|
|
210
325
|
if (!isSafeValue(value))
|
|
211
326
|
refuse(
|
|
212
327
|
E.ERR_THEME_BAD_VALUE,
|
|
213
328
|
`"${value}" cannot be a CSS value: it has a ; { } < > or a newline, a comment, !important, or an unclosed bracket or quote.`,
|
|
214
|
-
{
|
|
329
|
+
{
|
|
330
|
+
run: [
|
|
331
|
+
`${P} set ${slug} ${name} ${quoteCommandArgument(exampleOf(type, name))}`,
|
|
332
|
+
],
|
|
333
|
+
},
|
|
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
|
+
},
|
|
215
352
|
);
|
|
216
353
|
// A var() naming a design token must name one of the same kind; the
|
|
217
354
|
// app's own variables are its business.
|
|
@@ -231,6 +368,16 @@ function checkTypedValue(type, value, name, TOKENS, typeOf, slug) {
|
|
|
231
368
|
}
|
|
232
369
|
if (type === 'color' && !isFixedColor(value)) bad('a color', '#1f2937');
|
|
233
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
|
+
}
|
|
234
381
|
if (type === 'number' && !isNumber(value, name))
|
|
235
382
|
bad('a number', /weight/.test(name) ? '600' : '1.4');
|
|
236
383
|
if (type === 'time' && !isTime(value)) bad('a time up to 60s', '150ms');
|
|
@@ -242,9 +389,7 @@ function checkTypedValue(type, value, name, TOKENS, typeOf, slug) {
|
|
|
242
389
|
bad('a shadow', '0 2px 4px rgb(0 0 0 / 0.2)');
|
|
243
390
|
if (
|
|
244
391
|
/^--focus-outline-style$/.test(name) &&
|
|
245
|
-
|
|
246
|
-
value.trim(),
|
|
247
|
-
)
|
|
392
|
+
!matchValue('outline-style', value.trim())
|
|
248
393
|
)
|
|
249
394
|
bad('an outline style', 'solid');
|
|
250
395
|
}
|
|
@@ -259,10 +404,14 @@ function checkTypedValue(type, value, name, TOKENS, typeOf, slug) {
|
|
|
259
404
|
*/
|
|
260
405
|
function isFixedColor(value) {
|
|
261
406
|
const v = value.trim().toLowerCase();
|
|
262
|
-
if (
|
|
263
|
-
return false;
|
|
407
|
+
if (CSS_WIDE.includes(v)) return false;
|
|
264
408
|
if (/^var\(/.test(v)) return true;
|
|
265
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
|
+
};
|
|
266
415
|
const inner = (/** @type {string} */ fn) =>
|
|
267
416
|
splitTop(v.slice(fn.length + 1, -1), ',').map(x => x.trim());
|
|
268
417
|
// Each mode's value, and each mixed color, must be a color itself.
|
|
@@ -275,12 +424,17 @@ function isFixedColor(value) {
|
|
|
275
424
|
return (
|
|
276
425
|
/^in\s+[a-z-]+/.test(space ?? '') &&
|
|
277
426
|
colors.length === 2 &&
|
|
278
|
-
colors
|
|
427
|
+
!zeroMix(colors) &&
|
|
428
|
+
colors.every(c => isFixedColor(mixSide(c).color))
|
|
279
429
|
);
|
|
280
430
|
}
|
|
281
431
|
if (!isColorValue(v)) return false;
|
|
282
|
-
// A relative color
|
|
283
|
-
|
|
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;
|
|
284
438
|
if (/^(rgb|rgba|hsl|hsla|hwb|lab|lch|oklab|oklch)\(/.test(v))
|
|
285
439
|
return parseColor(v) != null;
|
|
286
440
|
if (/^color\(/.test(v))
|
|
@@ -314,142 +468,53 @@ const SYSTEM_COLORS = [
|
|
|
314
468
|
];
|
|
315
469
|
|
|
316
470
|
/**
|
|
317
|
-
* 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).
|
|
318
473
|
* @param {string} value
|
|
319
474
|
*/
|
|
320
475
|
function isTime(value) {
|
|
321
|
-
const
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
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
|
+
);
|
|
327
485
|
}
|
|
328
486
|
|
|
329
487
|
/**
|
|
330
|
-
* Whether a value is an easing the browser takes
|
|
331
|
-
*
|
|
332
|
-
*
|
|
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`.
|
|
333
491
|
* @param {string} value
|
|
334
492
|
*/
|
|
335
493
|
function isEasing(value) {
|
|
336
|
-
const
|
|
337
|
-
if (
|
|
338
|
-
|
|
339
|
-
)
|
|
340
|
-
return true;
|
|
341
|
-
const m = /^(cubic-bezier|steps|linear)\((.*)\)$/.exec(v);
|
|
342
|
-
if (!m) return false;
|
|
343
|
-
const args = splitTop(m[2], ',').map(x => x.trim());
|
|
344
|
-
if (args.some(a => /var\(/.test(a))) return true;
|
|
345
|
-
const num = (/** @type {string} */ a) => /^[+-]?\d*\.?\d+$/.test(a);
|
|
346
|
-
if (m[1] === 'cubic-bezier')
|
|
347
|
-
return (
|
|
348
|
-
args.length === 4 &&
|
|
349
|
-
args.every(num) &&
|
|
350
|
-
[0, 2].every(i => Number(args[i]) >= 0 && Number(args[i]) <= 1)
|
|
351
|
-
);
|
|
352
|
-
if (m[1] === 'steps')
|
|
353
|
-
return (
|
|
354
|
-
/^\d+$/.test(args[0] ?? '') &&
|
|
355
|
-
Number(args[0]) >= 1 &&
|
|
356
|
-
args.length <= 2 &&
|
|
357
|
-
(args.length === 1 ||
|
|
358
|
-
/^(jump-start|jump-end|jump-none|jump-both|start|end)$/.test(
|
|
359
|
-
args[1],
|
|
360
|
-
)) &&
|
|
361
|
-
!(args[1] === 'jump-none' && Number(args[0]) < 2)
|
|
362
|
-
);
|
|
363
|
-
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);
|
|
364
498
|
}
|
|
365
499
|
|
|
366
|
-
/**
|
|
367
|
-
|
|
368
|
-
* of words that do not start with a digit, or a var().
|
|
369
|
-
* @param {string} value
|
|
370
|
-
*/
|
|
371
|
-
function isFamilyList(value) {
|
|
372
|
-
return splitTop(value.trim(), ',').every(f => {
|
|
373
|
-
const t = f.trim();
|
|
374
|
-
return (
|
|
375
|
-
/^"[^"]+"$/.test(t) ||
|
|
376
|
-
/^'[^']+'$/.test(t) ||
|
|
377
|
-
/^var\(/i.test(t) ||
|
|
378
|
-
/^[\p{L}_-][\p{L}\p{N}_-]*(\s+[\p{L}_-][\p{L}\p{N}_-]*)*$/u.test(t)
|
|
379
|
-
);
|
|
380
|
-
});
|
|
381
|
-
}
|
|
500
|
+
/** Whether a value is a font family list. @param {string} value */
|
|
501
|
+
const isFamilyList = value => matchValue('font-family', value.trim()) != null;
|
|
382
502
|
|
|
383
503
|
/**
|
|
384
|
-
* Whether a value is a shadow list
|
|
385
|
-
*
|
|
504
|
+
* Whether a value is a shadow list. The grammar has no range for the blur
|
|
505
|
+
* (the third length), which is never negative.
|
|
386
506
|
* @param {string} value
|
|
387
507
|
*/
|
|
388
508
|
function isShadow(value) {
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
if (
|
|
394
|
-
layers.length === 1 &&
|
|
395
|
-
splitTop(v, ' ').length === 1 &&
|
|
396
|
-
!/^var\(/i.test(v)
|
|
397
|
-
)
|
|
398
|
-
return false;
|
|
399
|
-
return layers.every(layer => {
|
|
400
|
-
const words = splitTop(layer.trim(), ' ');
|
|
401
|
-
// One var() stacks a shadow token in the list.
|
|
402
|
-
if (words.length === 1 && /^var\(/i.test(words[0])) return true;
|
|
403
|
-
const insets = words.filter(w => w.toLowerCase() === 'inset').length;
|
|
404
|
-
const nums = words.filter(w =>
|
|
405
|
-
/^[+-]?\d*\.?\d+(px|rem|em|pt|pc|cm|mm|in|vw|vh|vmin|vmax|ch|ex|lh)?$|^(calc|min|max|clamp)\(/i.test(
|
|
406
|
-
w,
|
|
407
|
-
),
|
|
408
|
-
);
|
|
409
|
-
const vars = words.filter(w => /^var\(/i.test(w));
|
|
410
|
-
const rest = words.filter(
|
|
411
|
-
w =>
|
|
412
|
-
!nums.includes(w) && !vars.includes(w) && w.toLowerCase() !== 'inset',
|
|
413
|
-
);
|
|
414
|
-
// A blur (the third length) is never negative.
|
|
415
|
-
if (nums.length >= 3 && nums[2].startsWith('-')) return false;
|
|
416
|
-
// A var() fills a length or the color, whichever is missing.
|
|
417
|
-
const color = rest.length ? 0 : Math.min(1, vars.length);
|
|
418
|
-
const lengths = nums.length + vars.length - color;
|
|
419
|
-
return (
|
|
420
|
-
insets <= 1 &&
|
|
421
|
-
lengths >= 2 &&
|
|
422
|
-
lengths <= 4 &&
|
|
423
|
-
rest.length <= 1 &&
|
|
424
|
-
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),
|
|
425
513
|
);
|
|
514
|
+
return !(lengths[2] ?? '').startsWith('-');
|
|
426
515
|
});
|
|
427
516
|
}
|
|
428
517
|
|
|
429
|
-
/**
|
|
430
|
-
* A value split at `sep` outside brackets: `a(b, c), d` by `,` is
|
|
431
|
-
* [`a(b, c)`, ` d`]. A space separator also splits runs of spaces.
|
|
432
|
-
* @param {string} v
|
|
433
|
-
* @param {',' | ' '} sep
|
|
434
|
-
* @returns {string[]}
|
|
435
|
-
*/
|
|
436
|
-
function splitTop(v, sep) {
|
|
437
|
-
/** @type {string[]} */
|
|
438
|
-
const out = [];
|
|
439
|
-
let depth = 0;
|
|
440
|
-
let cur = '';
|
|
441
|
-
for (const c of v) {
|
|
442
|
-
if (c === '(') depth++;
|
|
443
|
-
if (c === ')') depth--;
|
|
444
|
-
if (depth === 0 && (sep === ' ' ? /\s/.test(c) : c === sep)) {
|
|
445
|
-
if (cur.trim() || sep === ',') out.push(cur);
|
|
446
|
-
cur = '';
|
|
447
|
-
} else cur += c;
|
|
448
|
-
}
|
|
449
|
-
if (cur.trim() || sep === ',') out.push(cur);
|
|
450
|
-
return out.filter(x => sep === ',' || x.trim());
|
|
451
|
-
}
|
|
452
|
-
|
|
453
518
|
/**
|
|
454
519
|
* Refuse a value that would read the token itself, through other tokens.
|
|
455
520
|
* @param {string} thing
|
|
@@ -495,7 +560,122 @@ function checkCycle(thing, value, TOKENS, data) {
|
|
|
495
560
|
}
|
|
496
561
|
|
|
497
562
|
/**
|
|
498
|
-
*
|
|
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
|
|
566
|
+
*/
|
|
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;
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
/**
|
|
574
|
+
* Why a value is not one the property takes, or null. Colors are checked
|
|
575
|
+
* by the editor's own color check; a property css-tree has no grammar for
|
|
576
|
+
* is not checked.
|
|
577
|
+
* @param {string} prop
|
|
578
|
+
* @param {string} value
|
|
579
|
+
* @returns {{takes: string, near: string | null} | null}
|
|
580
|
+
*/
|
|
581
|
+
function propertyProblem(prop, value) {
|
|
582
|
+
const v = value.trim();
|
|
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, '');
|
|
595
|
+
const near = /^[a-z-]+$/i.test(v)
|
|
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)
|
|
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);
|
|
605
|
+
return {
|
|
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),
|
|
611
|
+
};
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
/** Words people use for a dial's values, by dial. */
|
|
615
|
+
const DIAL_WORDS = /** @type {Record<string, Record<string, string>>} */ ({
|
|
616
|
+
surfaces: {
|
|
617
|
+
elevated: 'raised',
|
|
618
|
+
elevation: 'raised',
|
|
619
|
+
shadow: 'raised',
|
|
620
|
+
shadows: 'raised',
|
|
621
|
+
lifted: 'raised',
|
|
622
|
+
frosted: 'glass',
|
|
623
|
+
blur: 'glass',
|
|
624
|
+
blurred: 'glass',
|
|
625
|
+
translucent: 'glass',
|
|
626
|
+
bordered: 'outlined',
|
|
627
|
+
border: 'outlined',
|
|
628
|
+
borders: 'outlined',
|
|
629
|
+
lined: 'outlined',
|
|
630
|
+
outline: 'outlined',
|
|
631
|
+
plain: 'flat',
|
|
632
|
+
minimal: 'flat',
|
|
633
|
+
},
|
|
634
|
+
buttons: {
|
|
635
|
+
uppercase: 'caps',
|
|
636
|
+
upper: 'caps',
|
|
637
|
+
allcaps: 'caps',
|
|
638
|
+
capitals: 'caps',
|
|
639
|
+
tint: 'soft',
|
|
640
|
+
tinted: 'soft',
|
|
641
|
+
subtle: 'soft',
|
|
642
|
+
outlined: 'outline',
|
|
643
|
+
bordered: 'outline',
|
|
644
|
+
ghost: 'outline',
|
|
645
|
+
filled: 'solid',
|
|
646
|
+
fill: 'solid',
|
|
647
|
+
},
|
|
648
|
+
mode: {
|
|
649
|
+
auto: 'both',
|
|
650
|
+
system: 'both',
|
|
651
|
+
default: 'both',
|
|
652
|
+
light: 'light-only',
|
|
653
|
+
dark: 'dark-only',
|
|
654
|
+
},
|
|
655
|
+
});
|
|
656
|
+
|
|
657
|
+
/**
|
|
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.
|
|
499
679
|
* @param {import('./_settings.mjs').Ctx} ctx
|
|
500
680
|
* @param {string} slug
|
|
501
681
|
* @param {import('./_settings.mjs').ThemeData} data
|
|
@@ -514,6 +694,37 @@ export function checkSetting(
|
|
|
514
694
|
flags,
|
|
515
695
|
unset = false,
|
|
516
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) {
|
|
517
728
|
const {C} = ctx;
|
|
518
729
|
const TARGET = ctx.project.target;
|
|
519
730
|
const TOKENS = ctx.project.core.tokenDefaults;
|
|
@@ -529,7 +740,7 @@ export function checkSetting(
|
|
|
529
740
|
`Give the token and its value as two words: ${name} ${rest.join('=')}.`,
|
|
530
741
|
{
|
|
531
742
|
run: [
|
|
532
|
-
`${P} ${unset ? 'undo' : 'set'} ${slug} ${name}${unset ? '' : ` ${
|
|
743
|
+
`${P} ${unset ? 'undo' : 'set'} ${slug} ${name}${unset ? '' : ` ${quoteCommandArgument(rest.join('='))}`}`,
|
|
533
744
|
],
|
|
534
745
|
},
|
|
535
746
|
);
|
|
@@ -545,14 +756,31 @@ export function checkSetting(
|
|
|
545
756
|
refuse(E.ERR_MISSING_ARGUMENT, `--${k} was given no value.`, {
|
|
546
757
|
run: [`${P} ${unset ? 'undo' : 'set'} --help`],
|
|
547
758
|
});
|
|
548
|
-
|
|
759
|
+
// A value pasted over several lines is one value.
|
|
760
|
+
const v = (value ?? '')
|
|
761
|
+
.replace(/\s*[\r\n]+\s*/g, ' ')
|
|
762
|
+
.replace(/\t+/g, ' ')
|
|
763
|
+
.trim();
|
|
549
764
|
// A var() that misspells a design token would read nothing.
|
|
550
765
|
if (!unset)
|
|
551
|
-
for (const [, name] of v.matchAll(
|
|
766
|
+
for (const [, name, comma] of v.matchAll(
|
|
767
|
+
/var\(\s*(--[a-z0-9-]+)\s*(,)?/gi,
|
|
768
|
+
)) {
|
|
552
769
|
if (name in TOKENS || name.startsWith('--_')) continue;
|
|
553
770
|
const near = nearest(name, Object.keys(TOKENS)).filter(
|
|
554
771
|
n => levenshteinDistance(n, name) <= 2,
|
|
555
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
|
+
);
|
|
556
784
|
if (near.length)
|
|
557
785
|
refuse(
|
|
558
786
|
E.ERR_THEME_UNKNOWN_TOKEN,
|
|
@@ -574,6 +802,16 @@ export function checkSetting(
|
|
|
574
802
|
);
|
|
575
803
|
/** @type {import('./_settings.mjs').Setting} */
|
|
576
804
|
const s = {thing, value: v, source: 'dial'};
|
|
805
|
+
// A flag given only spaces names nothing; it is never read as absent.
|
|
806
|
+
for (const k of /** @type {const} */ (['on', 'when', 'state', 'mode']))
|
|
807
|
+
if (typeof flags[k] === 'string' && flags[k].trim() === '')
|
|
808
|
+
refuse(E.ERR_MISSING_ARGUMENT, `--${k} is empty.`, {
|
|
809
|
+
run: [
|
|
810
|
+
k === 'mode'
|
|
811
|
+
? `${P} set ${slug} ${thing} ${quoteCommandArgument(v || '#1f2937')}`
|
|
812
|
+
: `${HOW} --list parts`,
|
|
813
|
+
],
|
|
814
|
+
});
|
|
577
815
|
if (flags.on) s.on = flags.on.trim();
|
|
578
816
|
if (flags.when) s.when = flags.when.trim();
|
|
579
817
|
if (flags.state) s.state = flags.state.trim();
|
|
@@ -584,17 +822,33 @@ export function checkSetting(
|
|
|
584
822
|
refuse(
|
|
585
823
|
E.ERR_THEME_BAD_VALUE,
|
|
586
824
|
`--mode takes light or dark, not "${flags.mode}".`,
|
|
587
|
-
{
|
|
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
|
+
},
|
|
588
831
|
);
|
|
589
832
|
s.mode = mode;
|
|
590
833
|
}
|
|
591
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
|
+
);
|
|
592
846
|
// A setting saved for a mode the theme no longer has can still be removed.
|
|
593
847
|
if (s.mode && data.mode !== 'both' && !unset)
|
|
594
848
|
refuse(
|
|
595
849
|
E.ERR_THEME_NO_MODE,
|
|
596
850
|
`This theme is ${data.mode}; --mode is for themes with both modes.`,
|
|
597
|
-
{run: [`${P} set ${slug} ${thing} ${
|
|
851
|
+
{run: [`${P} set ${slug} ${thing} ${quoteCommandArgument(v)}${onFlag}`]},
|
|
598
852
|
);
|
|
599
853
|
if ((s.when || s.state) && !s.on)
|
|
600
854
|
refuse(E.ERR_MISSING_ARGUMENT, '--when and --state need --on <part>.', {
|
|
@@ -615,28 +869,41 @@ export function checkSetting(
|
|
|
615
869
|
{
|
|
616
870
|
run: [
|
|
617
871
|
unset
|
|
618
|
-
? `${P} undo ${slug} ${thing}${v ? ` ${
|
|
619
|
-
: `${P} set ${slug} ${thing} ${
|
|
872
|
+
? `${P} undo ${slug} ${thing}${v ? ` ${quoteCommandArgument(v)}` : ''} --on ${s.on}`
|
|
873
|
+
: `${P} set ${slug} ${thing} ${quoteCommandArgument(v)} --on ${s.on}`,
|
|
620
874
|
],
|
|
621
875
|
},
|
|
622
876
|
);
|
|
623
877
|
}
|
|
624
|
-
const isRole =
|
|
625
|
-
thing === 'font' && ['body', 'heading', 'code'].includes(s.on ?? '');
|
|
878
|
+
const isRole = thing === 'font' && FONT_ROLES.includes(s.on ?? '');
|
|
626
879
|
if (s.on && !isRole && !FAMILIES[s.on]) {
|
|
627
880
|
const t = TARGET.get(s.on);
|
|
628
881
|
if (!t) {
|
|
882
|
+
// Another case of a part or group: that one, as a working command.
|
|
883
|
+
const lower = s.on.toLowerCase();
|
|
884
|
+
if (TARGET.has(lower) || FAMILIES[lower])
|
|
885
|
+
refuse(
|
|
886
|
+
E.ERR_THEME_UNKNOWN_PART,
|
|
887
|
+
`"${s.on}" is not a part you can style; part names are lower case: ${lower}.`,
|
|
888
|
+
{
|
|
889
|
+
didYouMean: [lower],
|
|
890
|
+
run: [
|
|
891
|
+
`${P} ${unset ? 'undo' : 'set'} ${slug} ${thing}${v ? ` ${quoteCommandArgument(v)}` : ''} --on ${lower}${s.when ? ` --when ${s.when}` : ''}${s.state ? ` --state ${s.state}` : ''}${s.mode ? ` --mode ${s.mode}` : ''}`,
|
|
892
|
+
],
|
|
893
|
+
},
|
|
894
|
+
);
|
|
629
895
|
refuse(
|
|
630
896
|
E.ERR_THEME_UNKNOWN_PART,
|
|
631
897
|
`"${s.on}" is not a part you can style.`,
|
|
632
898
|
{
|
|
633
|
-
|
|
899
|
+
// A plural or another case names the part it means.
|
|
900
|
+
didYouMean: nearest(s.on.toLowerCase().replace(/s$/, ''), [
|
|
634
901
|
...TARGET.keys(),
|
|
635
902
|
...Object.keys(FAMILIES),
|
|
636
903
|
]),
|
|
637
904
|
run: [
|
|
638
|
-
`${HOW} --list parts ${s.on.split('-')[0]}`,
|
|
639
|
-
`${HOW} ${
|
|
905
|
+
`${HOW} --list parts ${s.on.toLowerCase().replace(/s$/, '').split('-')[0]}`,
|
|
906
|
+
`${HOW} ${quoteCommandArgument(s.on)}`,
|
|
640
907
|
],
|
|
641
908
|
},
|
|
642
909
|
);
|
|
@@ -668,9 +935,140 @@ export function checkSetting(
|
|
|
668
935
|
refuse(
|
|
669
936
|
E.ERR_THEME_UNKNOWN_STATE,
|
|
670
937
|
`"${s.state}" is not a state of ${s.on}. States: ${states.join(', ')}.`,
|
|
671
|
-
{
|
|
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
|
+
},
|
|
672
968
|
);
|
|
673
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)),
|
|
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
|
+
}
|
|
1071
|
+
}
|
|
674
1072
|
// On a group, a variant or state must belong to at least one member.
|
|
675
1073
|
if (s.on && FAMILIES[s.on] && (s.when || s.state)) {
|
|
676
1074
|
const members =
|
|
@@ -703,6 +1101,19 @@ export function checkSetting(
|
|
|
703
1101
|
);
|
|
704
1102
|
}
|
|
705
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
|
+
);
|
|
706
1117
|
if (DIALS[thing]) {
|
|
707
1118
|
s.source = 'dial';
|
|
708
1119
|
if (['surfaces', 'buttons', 'type'].includes(thing)) {
|
|
@@ -712,7 +1123,7 @@ export function checkSetting(
|
|
|
712
1123
|
`${thing} moves every part it covers; drop --on. For one part, set CSS properties --on <part>.`,
|
|
713
1124
|
{
|
|
714
1125
|
run: [
|
|
715
|
-
`${P} set ${slug} ${thing} ${
|
|
1126
|
+
`${P} set ${slug} ${thing} ${quoteCommandArgument(v || DIALS[thing].values.split('|')[0])}`,
|
|
716
1127
|
],
|
|
717
1128
|
},
|
|
718
1129
|
);
|
|
@@ -720,19 +1131,43 @@ export function checkSetting(
|
|
|
720
1131
|
refuse(
|
|
721
1132
|
E.ERR_THEME_NO_MODE,
|
|
722
1133
|
`${thing} is the same in light and dark; drop --mode.`,
|
|
723
|
-
{run: [`${P} set ${slug} ${thing} ${
|
|
1134
|
+
{run: [`${P} set ${slug} ${thing} ${quoteCommandArgument(v)}`]},
|
|
724
1135
|
);
|
|
725
1136
|
if (unset) return s;
|
|
726
1137
|
const ok = DIALS[thing].values.split('|');
|
|
727
1138
|
const lower = v.toLowerCase();
|
|
728
1139
|
if (!ok.includes(v)) {
|
|
729
|
-
|
|
1140
|
+
// A word that means one of the values names it; a word close in
|
|
1141
|
+
// spelling only, the nearest; anything else, no guess (never the
|
|
1142
|
+
// first value, which may be the opposite).
|
|
1143
|
+
const meant = DIAL_WORDS[thing]?.[lower];
|
|
1144
|
+
const near = ok.includes(lower)
|
|
1145
|
+
? [lower]
|
|
1146
|
+
: meant
|
|
1147
|
+
? [meant]
|
|
1148
|
+
: nearest(lower, ok);
|
|
730
1149
|
refuse(
|
|
731
1150
|
E.ERR_THEME_BAD_VALUE,
|
|
732
1151
|
`${thing} takes ${DIALS[thing].values}, not "${v}".`,
|
|
733
1152
|
{
|
|
734
1153
|
didYouMean: near,
|
|
735
|
-
run:
|
|
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}`],
|
|
736
1171
|
},
|
|
737
1172
|
);
|
|
738
1173
|
}
|
|
@@ -755,7 +1190,7 @@ export function checkSetting(
|
|
|
755
1190
|
'headings is the same in light and dark; drop --mode.',
|
|
756
1191
|
{
|
|
757
1192
|
run: [
|
|
758
|
-
`${P} ${unset ? 'undo' : 'set'} ${slug} headings${v ? ` ${
|
|
1193
|
+
`${P} ${unset ? 'undo' : 'set'} ${slug} headings${v ? ` ${quoteCommandArgument(v)}` : ''}`,
|
|
759
1194
|
],
|
|
760
1195
|
},
|
|
761
1196
|
);
|
|
@@ -783,33 +1218,116 @@ export function checkSetting(
|
|
|
783
1218
|
...Object.keys(HEADING_WEIGHTS),
|
|
784
1219
|
...Object.keys(HEADING_TRACKING),
|
|
785
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
|
+
],
|
|
786
1232
|
},
|
|
787
1233
|
);
|
|
788
1234
|
return s;
|
|
789
1235
|
}
|
|
790
1236
|
if (unset) return s;
|
|
791
|
-
/** @param {Array<[string, number]>} L @param {string} def */
|
|
1237
|
+
/** @param {Array<[string, number]>} L @param {string | number} def */
|
|
792
1238
|
const ladder = (L, def) => {
|
|
793
1239
|
// The value in effect for the target: its own setting, else the
|
|
794
1240
|
// whole-theme one, else the starting point.
|
|
795
|
-
|
|
1241
|
+
// Same target: the part, and the same variant and state.
|
|
1242
|
+
const latest = (/** @type {string} */ on) =>
|
|
1243
|
+
[...data.settings].reverse().find(
|
|
1244
|
+
x =>
|
|
1245
|
+
x.thing === thing &&
|
|
1246
|
+
(x.on ?? '') === on &&
|
|
1247
|
+
(x.when ?? '') === (on ? (s.when ?? '') : '') &&
|
|
1248
|
+
(x.state ?? '') === (on ? (s.state ?? '') : '') &&
|
|
1249
|
+
// A member set alone (--only) is not the member as the group
|
|
1250
|
+
// spreads it.
|
|
1251
|
+
Boolean(x.only) === (on === s.on ? Boolean(s.only) : false),
|
|
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).
|
|
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) =>
|
|
796
1260
|
[...data.settings]
|
|
797
1261
|
.reverse()
|
|
798
|
-
.find(
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
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);
|
|
1285
|
+
const cur =
|
|
1286
|
+
shown?.value ??
|
|
1287
|
+
// A part's own radius (a number) already counts a whole-theme
|
|
1288
|
+
// setting.
|
|
1289
|
+
(s.on && typeof def !== 'number' ? own('') : undefined) ??
|
|
1290
|
+
def;
|
|
1291
|
+
const at = L.findIndex(([n]) => n === cur);
|
|
1292
|
+
if (at >= 0)
|
|
1293
|
+
return L[
|
|
1294
|
+
Math.max(0, Math.min(L.length - 1, at + (v === 'more' ? 1 : -1)))
|
|
1295
|
+
][0];
|
|
1296
|
+
// A size between rungs steps to the next rung that way, never past it.
|
|
1297
|
+
const px =
|
|
1298
|
+
typeof cur === 'number'
|
|
1299
|
+
? cur
|
|
1300
|
+
: (lengthPx(cur) ??
|
|
1301
|
+
(/^\d*\.?\d+$/.test(String(cur)) ? Number(cur) : Number.NaN));
|
|
1302
|
+
if (Number.isNaN(px)) return L[0][0];
|
|
1303
|
+
const next =
|
|
1304
|
+
v === 'more'
|
|
1305
|
+
? L.find(([, n]) => n > px + 0.01)
|
|
1306
|
+
: [...L].reverse().find(([, n]) => n < px - 0.01);
|
|
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
|
+
);
|
|
805
1325
|
}
|
|
806
|
-
return
|
|
807
|
-
Math.max(0, Math.min(L.length - 1, i + (v === 'more' ? 1 : -1)))
|
|
808
|
-
][0];
|
|
1326
|
+
return next[0];
|
|
809
1327
|
};
|
|
810
1328
|
if (PALETTE_DIALS.includes(thing) && (s.on || s.mode)) {
|
|
811
1329
|
const token = paletteToken(thing);
|
|
812
|
-
const value =
|
|
1330
|
+
const value = quoteCommandArgument(v || '#7c3aed');
|
|
813
1331
|
/** @type {string[]} */
|
|
814
1332
|
let run = [
|
|
815
1333
|
`${P} set ${slug} ${token} ${value}${onFlag}${s.mode ? ` --mode ${s.mode}` : ''}`,
|
|
@@ -845,33 +1363,217 @@ export function checkSetting(
|
|
|
845
1363
|
refuse(
|
|
846
1364
|
E.ERR_THEME_NO_MODE,
|
|
847
1365
|
`${thing} is not a color, so it is the same in light and dark; drop --mode.`,
|
|
848
|
-
|
|
1366
|
+
// The same scope, every other flag kept.
|
|
1367
|
+
{run: [setLine(slug, thing, v, {...s, mode: undefined})]},
|
|
849
1368
|
);
|
|
850
1369
|
if (thing === 'corners') {
|
|
851
1370
|
if (s.on) refuseInvisibleCorners(ctx, slug, s, data);
|
|
852
1371
|
// With no corners setting yet, a step starts from the base theme's
|
|
853
1372
|
// own radius.
|
|
854
1373
|
if (step) {
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
:
|
|
861
|
-
|
|
862
|
-
|
|
1374
|
+
// A step moves to the next rung the part SHOWS bigger or smaller:
|
|
1375
|
+
// each rung is measured as the build writes it for the radius token
|
|
1376
|
+
// the part reads (a card reads the container radius), and so is
|
|
1377
|
+
// what the part shows now.
|
|
1378
|
+
const base = ctx.base ?? {
|
|
1379
|
+
light: /** @type {Record<string, string>} */ ({}),
|
|
1380
|
+
dark: /** @type {Record<string, string>} */ ({}),
|
|
1381
|
+
};
|
|
1382
|
+
const token = s.on
|
|
1383
|
+
? radiusTokenOf(ctx, partsOf(ctx, s)[0] ?? s.on, s.when)
|
|
1384
|
+
: '--radius-element';
|
|
1385
|
+
// What the part shows: a setting on it or on its group (the later
|
|
1386
|
+
// one wins), else a whole-theme setting, else the base theme.
|
|
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)));
|
|
1399
|
+
const onPart = s.on
|
|
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))
|
|
1413
|
+
: undefined;
|
|
1414
|
+
// A step on a member set alone stays on that member alone.
|
|
1415
|
+
if (onPart && onPart.on === s.on && onPart.only && !s.only)
|
|
1416
|
+
s.only = true;
|
|
1417
|
+
const whole = [...data.settings]
|
|
1418
|
+
.reverse()
|
|
1419
|
+
.find(x => x.thing === 'corners' && !x.on);
|
|
1420
|
+
const isRung = (/** @type {string} */ x) =>
|
|
1421
|
+
CORNERS.some(([n]) => n === x);
|
|
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));
|
|
1450
|
+
const rungs = CORNERS.map(
|
|
1451
|
+
([n]) => /** @type {const} */ ([n, radiusAt(base, n, token)]),
|
|
1452
|
+
);
|
|
1453
|
+
const next =
|
|
1454
|
+
v === 'more'
|
|
1455
|
+
? rungs.find(([, n]) => n > shown + 0.01)
|
|
1456
|
+
: [...rungs].reverse().find(([, n]) => n < shown - 0.01);
|
|
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';
|
|
1469
|
+
} else {
|
|
1470
|
+
// A rung in any case, a size in px written any way: the plain form.
|
|
1471
|
+
const lower = v.toLowerCase();
|
|
1472
|
+
const px = /^(\d+(?:\.\d+)?|\.\d+)px$/.exec(lower);
|
|
1473
|
+
if (CORNERS.some(([n]) => n === lower)) s.value = lower;
|
|
1474
|
+
else if (px) s.value = `${Number(px[1])}px`;
|
|
1475
|
+
else if (lower === '0') s.value = 'square';
|
|
1476
|
+
else {
|
|
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);
|
|
1495
|
+
const pct = /^(\d+(?:\.\d+)?)%$/.exec(lower);
|
|
1496
|
+
// A radius below zero means none: square.
|
|
1497
|
+
const meant =
|
|
1498
|
+
len != null
|
|
1499
|
+
? len <= 0
|
|
1500
|
+
? 'square'
|
|
1501
|
+
: `${Math.round(len * 100) / 100}px`
|
|
1502
|
+
: pct
|
|
1503
|
+
? Number(pct[1]) >= 50
|
|
1504
|
+
? 'pill'
|
|
1505
|
+
: null
|
|
1506
|
+
: (nearest(
|
|
1507
|
+
lower,
|
|
1508
|
+
CORNERS.map(([n]) => n),
|
|
1509
|
+
)[0] ?? null);
|
|
1510
|
+
refuse(
|
|
1511
|
+
E.ERR_THEME_BAD_VALUE,
|
|
1512
|
+
`corners takes ${DIALS.corners.values}, not "${v}".`,
|
|
1513
|
+
{
|
|
1514
|
+
...(meant ? {didYouMean: [meant]} : {}),
|
|
1515
|
+
// The same scope, flags included.
|
|
1516
|
+
run: [setLine(slug, 'corners', meant ?? 'medium', s)],
|
|
1517
|
+
},
|
|
1518
|
+
);
|
|
1519
|
+
}
|
|
1520
|
+
}
|
|
1521
|
+
} else if (thing === 'spacing') {
|
|
1522
|
+
// Spacing scales the space tokens a part reads; a state does not
|
|
1523
|
+
// change them, and a part that reads none shows nothing.
|
|
1524
|
+
if (s.state)
|
|
863
1525
|
refuse(
|
|
864
|
-
E.
|
|
865
|
-
`
|
|
1526
|
+
E.ERR_THEME_NO_EFFECT,
|
|
1527
|
+
`spacing does not change in a state; drop --state.`,
|
|
866
1528
|
{
|
|
867
|
-
|
|
868
|
-
v,
|
|
869
|
-
|
|
870
|
-
|
|
1529
|
+
run: [
|
|
1530
|
+
setLine(slug, 'spacing', v || 'roomy', {
|
|
1531
|
+
...s,
|
|
1532
|
+
state: undefined,
|
|
1533
|
+
mode: undefined,
|
|
1534
|
+
}),
|
|
1535
|
+
],
|
|
871
1536
|
},
|
|
872
1537
|
);
|
|
873
|
-
|
|
1538
|
+
if (s.on && !ctx.unchecked) {
|
|
1539
|
+
// The tokens reach the parts inside it too.
|
|
1540
|
+
const reads = (/** @type {string} */ t) =>
|
|
1541
|
+
Object.values(ctx.C.MAP[t]?.own ?? {}).some(p =>
|
|
1542
|
+
Object.keys(p.tokens ?? {}).some(x =>
|
|
1543
|
+
/^--(spacing-|size-element-)/.test(x),
|
|
1544
|
+
),
|
|
1545
|
+
);
|
|
1546
|
+
const spaced = partsOf(ctx, s).filter(
|
|
1547
|
+
t => reads(t) || (ctx.C.MAP[t]?.contains ?? []).some(reads),
|
|
1548
|
+
);
|
|
1549
|
+
if (!spaced.length)
|
|
1550
|
+
refuse(
|
|
1551
|
+
E.ERR_THEME_NO_EFFECT,
|
|
1552
|
+
`${s.on} reads no spacing or control size, so spacing changes nothing you see there. For space around it, set margin or padding on it.`,
|
|
1553
|
+
{run: [`${P} set ${slug} padding 8px${onFlag}`]},
|
|
1554
|
+
);
|
|
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;
|
|
874
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
|
+
);
|
|
875
1577
|
else if (!SPACING.some(([n]) => n === v))
|
|
876
1578
|
refuse(
|
|
877
1579
|
E.ERR_THEME_BAD_VALUE,
|
|
@@ -881,6 +1583,17 @@ export function checkSetting(
|
|
|
881
1583
|
v,
|
|
882
1584
|
SPACING.map(([n]) => n),
|
|
883
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
|
+
],
|
|
884
1597
|
},
|
|
885
1598
|
);
|
|
886
1599
|
} else if (thing === 'text-size') {
|
|
@@ -898,14 +1611,28 @@ export function checkSetting(
|
|
|
898
1611
|
refuse(
|
|
899
1612
|
E.ERR_THEME_BAD_VALUE,
|
|
900
1613
|
`text-size takes ${DIALS['text-size'].values} (a number is the body size in pixels, 10 to 32), not "${v}".`,
|
|
901
|
-
|
|
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
|
+
})(),
|
|
902
1629
|
);
|
|
903
1630
|
else if (!TEXT_SIZE.some(([n]) => n === v))
|
|
904
1631
|
s.value = String(Number(v.trim()));
|
|
905
1632
|
} else if (PALETTE_DIALS.includes(thing)) {
|
|
906
1633
|
if (step)
|
|
907
1634
|
refuse(E.ERR_THEME_BAD_VALUE, `${thing} takes a color, not a step.`, {
|
|
908
|
-
run: [`${P} set ${slug} ${thing}
|
|
1635
|
+
run: [`${P} set ${slug} ${thing} ${quoteCommandArgument('#7c3aed')}`],
|
|
909
1636
|
});
|
|
910
1637
|
const problem = colorProblem(v);
|
|
911
1638
|
if (problem) {
|
|
@@ -933,7 +1660,9 @@ export function checkSetting(
|
|
|
933
1660
|
`"${v}" ${problem.message}.${problem.kind === 'unknown' || problem.kind === 'malformed' ? ' Give a hex, a color name, or an rgb(), hsl(), hwb(), lab(), lch(), oklab(), oklch() or color() color.' : ''}`,
|
|
934
1661
|
{
|
|
935
1662
|
didYouMean: better ? [better] : near,
|
|
936
|
-
run: [
|
|
1663
|
+
run: [
|
|
1664
|
+
`${P} set ${slug} ${thing} ${quoteCommandArgument(better ?? '#7c3aed')}`,
|
|
1665
|
+
],
|
|
937
1666
|
},
|
|
938
1667
|
);
|
|
939
1668
|
}
|
|
@@ -942,7 +1671,7 @@ export function checkSetting(
|
|
|
942
1671
|
refuse(
|
|
943
1672
|
E.ERR_THEME_BAD_VALUE,
|
|
944
1673
|
'vibrancy applies to every generated color of the theme; drop --on.',
|
|
945
|
-
{run: [`${P} set ${slug} vibrancy ${
|
|
1674
|
+
{run: [`${P} set ${slug} vibrancy ${quoteCommandArgument(v)}`]},
|
|
946
1675
|
);
|
|
947
1676
|
if (step) {
|
|
948
1677
|
const saved = [...data.settings]
|
|
@@ -990,7 +1719,7 @@ export function checkSetting(
|
|
|
990
1719
|
colors.length
|
|
991
1720
|
? 'vibrancy sets how saturated the generated colors are, and every color this theme sets is a gray, so it would change nothing. Set a color first.'
|
|
992
1721
|
: 'vibrancy sets how saturated the generated colors are, and this theme sets no color yet. Set one first.',
|
|
993
|
-
{run: [`${P} set ${slug} accent
|
|
1722
|
+
{run: [`${P} set ${slug} accent ${quoteCommandArgument('#7c3aed')}`]},
|
|
994
1723
|
);
|
|
995
1724
|
} else if (thing === 'font') {
|
|
996
1725
|
if (s.when || s.state)
|
|
@@ -999,26 +1728,94 @@ export function checkSetting(
|
|
|
999
1728
|
'font sets a role (body, heading, code) for the whole theme; it takes no --when or --state. For one part use font-family.',
|
|
1000
1729
|
{
|
|
1001
1730
|
run: [
|
|
1002
|
-
`${P} set ${slug} font-family ${
|
|
1731
|
+
`${P} set ${slug} font-family ${quoteCommandArgument(v)} --on heading${s.when ? ` --when ${s.when}` : ''}${s.state ? ` --state ${s.state}` : ''}`,
|
|
1003
1732
|
],
|
|
1004
1733
|
},
|
|
1005
1734
|
);
|
|
1006
|
-
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];
|
|
1007
1755
|
refuse(
|
|
1008
1756
|
E.ERR_THEME_BAD_VALUE,
|
|
1009
|
-
|
|
1010
|
-
|
|
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},
|
|
1011
1761
|
);
|
|
1762
|
+
}
|
|
1012
1763
|
if (step)
|
|
1013
1764
|
refuse(
|
|
1014
1765
|
E.ERR_THEME_BAD_VALUE,
|
|
1015
1766
|
'font takes a preset or a family name, not a step.',
|
|
1016
|
-
{
|
|
1767
|
+
{
|
|
1768
|
+
fix: `the values are ${DIALS.font.values}`,
|
|
1769
|
+
run: [`${P} set ${slug} font inter`, `${HOW} font`],
|
|
1770
|
+
},
|
|
1017
1771
|
);
|
|
1018
1772
|
// A family list: names, quoted or not, split by commas; nothing that
|
|
1019
1773
|
// could end the CSS declaration or the preview's style block. A
|
|
1020
1774
|
// preset typed in another case or spacing is the preset.
|
|
1021
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
|
+
}
|
|
1806
|
+
// A font package names its preset: @fontsource/inter is inter.
|
|
1807
|
+
const fromPackage = /^@fontsource(?:-variable)?\/([a-z0-9-]+)$/i.exec(
|
|
1808
|
+
s.value,
|
|
1809
|
+
)?.[1];
|
|
1810
|
+
if (fromPackage && OPEN_FONTS[fromPackage.toLowerCase()])
|
|
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;
|
|
1022
1819
|
const key = s.value.toLowerCase().replace(/[\s_-]+/g, '');
|
|
1023
1820
|
const preset = [...Object.keys(FONTS), ...Object.keys(OPEN_FONTS)].find(
|
|
1024
1821
|
k => k.toLowerCase().replace(/[\s_-]+/g, '') === key,
|
|
@@ -1028,6 +1825,34 @@ export function checkSetting(
|
|
|
1028
1825
|
// (O'Reilly Sans); the dial quotes it when it writes it.
|
|
1029
1826
|
const family = (/** @type {string} */ f) =>
|
|
1030
1827
|
/^"[^"]+"$/.test(f) || /^'[^']+'$/.test(f) || /^[^"',\s][^"]*$/.test(f);
|
|
1828
|
+
// A CSS-wide keyword inside a family list makes the browser drop
|
|
1829
|
+
// the whole declaration.
|
|
1830
|
+
const keyword = s.value
|
|
1831
|
+
.split(',')
|
|
1832
|
+
.map(f =>
|
|
1833
|
+
f
|
|
1834
|
+
.trim()
|
|
1835
|
+
.replace(/^["']|["']$/g, '')
|
|
1836
|
+
.toLowerCase(),
|
|
1837
|
+
)
|
|
1838
|
+
.find(f => CSS_WIDE_KEYWORDS.includes(f));
|
|
1839
|
+
if (keyword)
|
|
1840
|
+
refuse(
|
|
1841
|
+
E.ERR_THEME_BAD_VALUE,
|
|
1842
|
+
`"${keyword}" is a CSS keyword, not a font: inside a font list it makes the browser drop the whole font. Give a preset or a family name; to go back to the base theme's font, undo the font setting.`,
|
|
1843
|
+
{
|
|
1844
|
+
run: [
|
|
1845
|
+
`${P} set ${slug} font system${s.on ? ` --on ${s.on}` : ''}`,
|
|
1846
|
+
`${P} undo ${slug} font${s.on ? ` --on ${s.on}` : ''}`,
|
|
1847
|
+
],
|
|
1848
|
+
},
|
|
1849
|
+
);
|
|
1850
|
+
if (s.value.split(',').some(f => f.trim().length > 100))
|
|
1851
|
+
refuse(
|
|
1852
|
+
E.ERR_THEME_BAD_VALUE,
|
|
1853
|
+
'A font family name is at most 100 characters.',
|
|
1854
|
+
{run: [`${P} set ${slug} font inter`]},
|
|
1855
|
+
);
|
|
1031
1856
|
if (
|
|
1032
1857
|
!s.value ||
|
|
1033
1858
|
/[;{}<>\\\n]/.test(s.value) ||
|
|
@@ -1043,27 +1868,50 @@ export function checkSetting(
|
|
|
1043
1868
|
refuse(
|
|
1044
1869
|
E.ERR_THEME_BAD_VALUE,
|
|
1045
1870
|
'base applies to the whole theme; drop --on.',
|
|
1046
|
-
{run: [`${P} set ${slug} base ${
|
|
1871
|
+
{run: [`${P} set ${slug} base ${quoteCommandArgument(v)}`]},
|
|
1047
1872
|
);
|
|
1048
|
-
if (![...LIKE, 'none'].includes(v))
|
|
1873
|
+
if (![...LIKE, 'none'].includes(v)) {
|
|
1874
|
+
// `NEUTRAL`, `base=neutral`, `None`: the base meant.
|
|
1875
|
+
const meant = v
|
|
1876
|
+
.toLowerCase()
|
|
1877
|
+
.replace(/^base\s*[=:]\s*/, '')
|
|
1878
|
+
.trim();
|
|
1879
|
+
const near = [...LIKE, 'none'].includes(meant)
|
|
1880
|
+
? [meant]
|
|
1881
|
+
: nearest(meant, [...LIKE, 'none']);
|
|
1049
1882
|
refuse(
|
|
1050
1883
|
E.ERR_THEME_BAD_VALUE,
|
|
1051
1884
|
`base takes ${DIALS.base.values}, not "${v}".`,
|
|
1052
|
-
{
|
|
1885
|
+
{
|
|
1886
|
+
didYouMean: near,
|
|
1887
|
+
run: near[0] ? [`${P} set ${slug} base ${near[0]}`] : [],
|
|
1888
|
+
},
|
|
1053
1889
|
);
|
|
1890
|
+
}
|
|
1054
1891
|
} else if (thing === 'mode') {
|
|
1055
1892
|
if (s.on)
|
|
1056
1893
|
refuse(
|
|
1057
1894
|
E.ERR_THEME_BAD_VALUE,
|
|
1058
1895
|
'mode applies to the whole theme; drop --on.',
|
|
1059
|
-
{run: [`${P} set ${slug} mode ${
|
|
1896
|
+
{run: [`${P} set ${slug} mode ${quoteCommandArgument(v)}`]},
|
|
1060
1897
|
);
|
|
1061
|
-
if (!['both', 'light-only', 'dark-only'].includes(v))
|
|
1898
|
+
if (!['both', 'light-only', 'dark-only'].includes(v)) {
|
|
1899
|
+
const lower = v.toLowerCase().replace(/^mode\s*[=:]\s*/, '');
|
|
1900
|
+
const meant =
|
|
1901
|
+
DIAL_WORDS.mode[lower] ??
|
|
1902
|
+
(['both', 'light-only', 'dark-only'].includes(lower) ? lower : null);
|
|
1903
|
+
const near = meant
|
|
1904
|
+
? [meant]
|
|
1905
|
+
: nearest(lower, ['both', 'light-only', 'dark-only']);
|
|
1062
1906
|
refuse(
|
|
1063
1907
|
E.ERR_THEME_BAD_VALUE,
|
|
1064
1908
|
`mode takes both, light-only, or dark-only, not "${v}".`,
|
|
1065
|
-
{
|
|
1909
|
+
{
|
|
1910
|
+
didYouMean: near,
|
|
1911
|
+
run: near[0] ? [`${P} set ${slug} mode ${near[0]}`] : [],
|
|
1912
|
+
},
|
|
1066
1913
|
);
|
|
1914
|
+
}
|
|
1067
1915
|
}
|
|
1068
1916
|
return s;
|
|
1069
1917
|
}
|
|
@@ -1072,7 +1920,7 @@ export function checkSetting(
|
|
|
1072
1920
|
refuse(
|
|
1073
1921
|
E.ERR_THEME_PRIVATE_TOKEN,
|
|
1074
1922
|
`"${thing}" is private to a component; themes cannot set it.`,
|
|
1075
|
-
{run: [`${HOW} ${
|
|
1923
|
+
{run: [`${HOW} ${quoteCommandArgument(thing)}`]},
|
|
1076
1924
|
);
|
|
1077
1925
|
if (!(thing in TOKENS)) {
|
|
1078
1926
|
refuse(E.ERR_THEME_UNKNOWN_TOKEN, `"${thing}" is not a design token.`, {
|
|
@@ -1097,7 +1945,7 @@ export function checkSetting(
|
|
|
1097
1945
|
run: [
|
|
1098
1946
|
unset
|
|
1099
1947
|
? `${P} undo ${slug} ${thing}${onFlag}`
|
|
1100
|
-
: `${P} set ${slug} ${thing} ${
|
|
1948
|
+
: `${P} set ${slug} ${thing} ${quoteCommandArgument(v)}${onFlag}`,
|
|
1101
1949
|
],
|
|
1102
1950
|
},
|
|
1103
1951
|
);
|
|
@@ -1107,8 +1955,17 @@ export function checkSetting(
|
|
|
1107
1955
|
refuse(
|
|
1108
1956
|
E.ERR_THEME_BAD_VALUE,
|
|
1109
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)]},
|
|
1110
1959
|
);
|
|
1111
|
-
checkTypedValue(
|
|
1960
|
+
checkTypedValue(
|
|
1961
|
+
type,
|
|
1962
|
+
v,
|
|
1963
|
+
thing,
|
|
1964
|
+
TOKENS,
|
|
1965
|
+
C.typeOf,
|
|
1966
|
+
slug,
|
|
1967
|
+
C.propsReading(thing),
|
|
1968
|
+
);
|
|
1112
1969
|
checkCycle(thing, v, TOKENS, data);
|
|
1113
1970
|
// With no part data, what reads the token is unknown: save, unchecked.
|
|
1114
1971
|
if (ctx.unchecked) return s;
|
|
@@ -1174,7 +2031,7 @@ export function checkSetting(
|
|
|
1174
2031
|
also: r0.also,
|
|
1175
2032
|
});
|
|
1176
2033
|
} else if (hard.length)
|
|
1177
|
-
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`;
|
|
1178
2035
|
if (!s.note && recorded.length) {
|
|
1179
2036
|
const fed = C.feeds(recorded[0][0], thing);
|
|
1180
2037
|
if (fed.length) s.note = `feeds ${C.fmtFeeds(fed, recorded[0][0])}`;
|
|
@@ -1200,6 +2057,8 @@ export function checkSetting(
|
|
|
1200
2057
|
// name a token `set` refuses.
|
|
1201
2058
|
if (r && fed.length)
|
|
1202
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`;
|
|
1203
2062
|
else if (r && dialWrites(thing))
|
|
1204
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`;
|
|
1205
2064
|
// The editor's record of what parts read comes from one render of
|
|
@@ -1212,14 +2071,29 @@ export function checkSetting(
|
|
|
1212
2071
|
return s;
|
|
1213
2072
|
}
|
|
1214
2073
|
const prop = kebab(thing);
|
|
1215
|
-
|
|
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)) {
|
|
1216
2090
|
if (!s.on)
|
|
1217
2091
|
refuse(
|
|
1218
2092
|
E.ERR_MISSING_ARGUMENT,
|
|
1219
2093
|
`${prop} is a CSS property, so it needs --on <part|group>. For the whole theme use a dial or a token.`,
|
|
1220
2094
|
{
|
|
1221
2095
|
run: [
|
|
1222
|
-
`${P} set ${slug} ${prop} ${
|
|
2096
|
+
`${P} set ${slug} ${prop} ${quoteCommandArgument(v || exampleOf(groupOfPropType(prop), prop))} --on card`,
|
|
1223
2097
|
`${HOW} "${prop}"`,
|
|
1224
2098
|
],
|
|
1225
2099
|
},
|
|
@@ -1227,8 +2101,36 @@ export function checkSetting(
|
|
|
1227
2101
|
s.source = 'property';
|
|
1228
2102
|
s.thing = prop;
|
|
1229
2103
|
if (unset) return s;
|
|
2104
|
+
// Text, headings and links take their color from the color prop.
|
|
2105
|
+
const textParts = COLOR_PROP_PARTS;
|
|
2106
|
+
if (
|
|
2107
|
+
(prop === 'color' || prop === '-webkit-text-fill-color') &&
|
|
2108
|
+
partsOf(ctx, s).some(t => textParts.includes(t))
|
|
2109
|
+
) {
|
|
2110
|
+
if (partsOf(ctx, s).every(t => textParts.includes(t))) {
|
|
2111
|
+
const named = /^color:([\w-]+)$/.exec(s.when ?? '')?.[1];
|
|
2112
|
+
refuse(
|
|
2113
|
+
E.ERR_THEME_NO_EFFECT,
|
|
2114
|
+
`${s.on} takes its color from the color prop, which Core sets after part styles, so a color set on ${s.on} never shows. Set the text color token instead.`,
|
|
2115
|
+
{
|
|
2116
|
+
run: [
|
|
2117
|
+
`${P} set ${slug} --color-text-${named ?? 'primary'} ${quoteCommandArgument(v || '#1f2937')}${s.mode ? ` --mode ${s.mode}` : ''}`,
|
|
2118
|
+
...(named
|
|
2119
|
+
? []
|
|
2120
|
+
: [
|
|
2121
|
+
`${P} set ${slug} --color-text-secondary ${quoteCommandArgument(v || '#1f2937')}${s.mode ? ` --mode ${s.mode}` : ''}`,
|
|
2122
|
+
]),
|
|
2123
|
+
],
|
|
2124
|
+
},
|
|
2125
|
+
);
|
|
2126
|
+
}
|
|
2127
|
+
s.note = `text, heading and link inside ${s.on} keep the color their color prop gives; set --color-text-primary for those`;
|
|
2128
|
+
}
|
|
1230
2129
|
// One mode on a part whose variants each read their own value: the
|
|
1231
2130
|
// other mode cannot keep each variant's value in one rule.
|
|
2131
|
+
// With a state, the other mode would take one variant's value for
|
|
2132
|
+
// every variant, so any part whose variants read their own value needs
|
|
2133
|
+
// the variant named.
|
|
1232
2134
|
if (s.mode && !s.when) {
|
|
1233
2135
|
const g = C.groupOfProp(
|
|
1234
2136
|
prop === 'background' ? 'background-color' : prop,
|
|
@@ -1237,20 +2139,38 @@ export function checkSetting(
|
|
|
1237
2139
|
const reads = g
|
|
1238
2140
|
? C.partReads(t, g).filter(r => r.props.includes(prop))
|
|
1239
2141
|
: [];
|
|
1240
|
-
const
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
2142
|
+
const variantsOf = (
|
|
2143
|
+
/** @type {(w: string) => string | undefined} */ pick,
|
|
2144
|
+
) => [
|
|
2145
|
+
...new Set(
|
|
2146
|
+
reads
|
|
2147
|
+
.flatMap(r => r.when)
|
|
2148
|
+
.map(pick)
|
|
2149
|
+
.filter(Boolean),
|
|
2150
|
+
),
|
|
2151
|
+
];
|
|
2152
|
+
// Resting reads keyed by the variant alone, and reads in the state.
|
|
2153
|
+
const rest = variantsOf(w => /^variant=([\w-]+)$/.exec(w)?.[1]);
|
|
2154
|
+
const inState = s.state
|
|
2155
|
+
? variantsOf(w =>
|
|
2156
|
+
w.includes(`:${s.state}`)
|
|
2157
|
+
? /(?:^|,)variant=([\w-]+)/.exec(w)?.[1]
|
|
2158
|
+
: undefined,
|
|
2159
|
+
)
|
|
2160
|
+
: [];
|
|
2161
|
+
// A state that does not change this property shows each variant's
|
|
2162
|
+
// resting value, so that is what the other mode must keep.
|
|
2163
|
+
const variants = inState.length ? inState : rest;
|
|
2164
|
+
const perVariant = inState.length
|
|
2165
|
+
? true
|
|
2166
|
+
: rest.length > 0 && !reads.some(r => r.when.includes(''));
|
|
2167
|
+
if (reads.length && variants.length && perVariant)
|
|
1248
2168
|
refuse(
|
|
1249
2169
|
E.ERR_THEME_NO_MODE,
|
|
1250
|
-
`Each variant of ${t} has its own ${prop}, so one mode cannot be set for all of them at once
|
|
2170
|
+
`Each variant of ${t} has its own ${prop}${s.state ? ` when ${s.state}` : ''}, so one mode cannot be set for all of them at once: the other mode would take one variant's color for every variant. Name the variant.`,
|
|
1251
2171
|
{
|
|
1252
2172
|
run: [
|
|
1253
|
-
`${P} set ${slug} ${prop} ${
|
|
2173
|
+
`${P} set ${slug} ${prop} ${quoteCommandArgument(v)} --on ${s.on} --when variant:${variants[0]}${s.state ? ` --state ${s.state}` : ''} --mode ${s.mode}`,
|
|
1254
2174
|
],
|
|
1255
2175
|
},
|
|
1256
2176
|
);
|
|
@@ -1267,19 +2187,46 @@ export function checkSetting(
|
|
|
1267
2187
|
refuse(
|
|
1268
2188
|
E.ERR_THEME_BAD_VALUE,
|
|
1269
2189
|
`"more"/"less" work only on dials. Give ${prop} an exact CSS value.`,
|
|
2190
|
+
{run: [`${HOW} ${prop}`]},
|
|
1270
2191
|
);
|
|
1271
|
-
|
|
2192
|
+
const grammar = propertyProblem(prop, v);
|
|
2193
|
+
if (grammar)
|
|
2194
|
+
refuse(
|
|
2195
|
+
E.ERR_THEME_BAD_VALUE,
|
|
2196
|
+
`${prop} takes ${grammar.takes}; "${v}" is not one.`,
|
|
2197
|
+
{
|
|
2198
|
+
...(grammar.near && /^[a-z-]+$/i.test(v)
|
|
2199
|
+
? {didYouMean: [grammar.near]}
|
|
2200
|
+
: {}),
|
|
2201
|
+
run: grammar.near
|
|
2202
|
+
? [
|
|
2203
|
+
// The same scope, --only included.
|
|
2204
|
+
setLine(slug, prop, grammar.near, s),
|
|
2205
|
+
]
|
|
2206
|
+
: [`${HOW} ${prop}`],
|
|
2207
|
+
},
|
|
2208
|
+
);
|
|
2209
|
+
if (
|
|
2210
|
+
COLOR_PROPS.test(prop) &&
|
|
2211
|
+
!CSS_WIDE.includes(v.trim().toLowerCase()) &&
|
|
2212
|
+
(!isColorValue(v) || !isFixedColor(v))
|
|
2213
|
+
) {
|
|
1272
2214
|
refuse(
|
|
1273
2215
|
E.ERR_THEME_BAD_VALUE,
|
|
1274
2216
|
`${prop} takes a color; "${v}" is not one.${/gradient/.test(v) ? ' Gradients go in background.' : ''}`,
|
|
1275
2217
|
{
|
|
1276
2218
|
run: /gradient/.test(v)
|
|
1277
|
-
? [
|
|
1278
|
-
|
|
2219
|
+
? [
|
|
2220
|
+
`${P} set ${slug} background ${quoteCommandArgument(v)} --on ${s.on}`,
|
|
2221
|
+
]
|
|
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
|
+
],
|
|
1279
2225
|
},
|
|
1280
2226
|
);
|
|
1281
2227
|
}
|
|
1282
|
-
|
|
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' : ''}`;
|
|
1283
2230
|
if (
|
|
1284
2231
|
s.mode &&
|
|
1285
2232
|
!COLOR_PROPS.test(prop) &&
|
|
@@ -1297,22 +2244,63 @@ export function checkSetting(
|
|
|
1297
2244
|
{
|
|
1298
2245
|
run: alt
|
|
1299
2246
|
? [
|
|
1300
|
-
`${P} set ${slug} ${prop} ${
|
|
1301
|
-
`${P} set ${slug} ${alt}
|
|
2247
|
+
`${P} set ${slug} ${prop} ${quoteCommandArgument(v.replace(/#[0-9a-f]{3,8}|rgba?\([^)]*\)/i, 'currentcolor'))} --on ${s.on}${whenFlag} # the shape, both modes`,
|
|
2248
|
+
`${P} set ${slug} ${alt} ${quoteCommandArgument(/#[0-9a-f]{3,8}\b|rgba?\([^)]*\)|hsla?\([^)]*\)/i.exec(v)?.[0] ?? '#1f2937')} --on ${s.on}${whenFlag} --mode ${s.mode} # then the color per mode`,
|
|
1302
2249
|
]
|
|
1303
2250
|
: [
|
|
1304
|
-
`${P} set ${slug} ${prop} ${
|
|
2251
|
+
`${P} set ${slug} ${prop} ${quoteCommandArgument(v)} --on ${s.on}${whenFlag} # both modes`,
|
|
1305
2252
|
],
|
|
1306
2253
|
},
|
|
1307
2254
|
);
|
|
1308
2255
|
}
|
|
2256
|
+
// In a state, the other mode keeps the state's own value there (or a
|
|
2257
|
+
// value set for both modes); with none to keep, the setting would
|
|
2258
|
+
// change that mode too. Without a state, the other mode keeps the
|
|
2259
|
+
// part's plain color.
|
|
1309
2260
|
if (
|
|
1310
2261
|
s.mode &&
|
|
1311
|
-
|
|
2262
|
+
s.state &&
|
|
2263
|
+
!partsOf(ctx, s).every(t =>
|
|
2264
|
+
partDefault(ctx, t, camel(prop), s.when, s.state),
|
|
2265
|
+
) &&
|
|
2266
|
+
!data.settings.some(
|
|
2267
|
+
x =>
|
|
2268
|
+
x.thing === prop &&
|
|
2269
|
+
x.on === s.on &&
|
|
2270
|
+
x.when === s.when &&
|
|
2271
|
+
x.state === s.state &&
|
|
2272
|
+
x.mode !== s.mode,
|
|
2273
|
+
)
|
|
1312
2274
|
)
|
|
1313
|
-
|
|
2275
|
+
refuse(
|
|
2276
|
+
E.ERR_THEME_NO_MODE,
|
|
2277
|
+
`${s.on} has no ${prop}${s.state ? ` when ${s.state}` : ''}${s.when ? ` for ${s.when}` : ''} of its own for the ${s.mode === 'light' ? 'dark' : 'light'} mode to keep, so a ${s.mode}-only value would change it too. Set it for both modes.`,
|
|
2278
|
+
{
|
|
2279
|
+
run: [
|
|
2280
|
+
`${P} set ${slug} ${prop} ${quoteCommandArgument(v)} --on ${s.on}${s.when ? ` --when ${s.when}` : ''}${s.state ? ` --state ${s.state}` : ''}`,
|
|
2281
|
+
],
|
|
2282
|
+
},
|
|
2283
|
+
);
|
|
1314
2284
|
return s;
|
|
1315
2285
|
}
|
|
2286
|
+
// A property written with _ or spaces, a trailing colon, or in camel
|
|
2287
|
+
// case: the property meant.
|
|
2288
|
+
const meant = kebab(String(thing).trim().replace(/:$/, ''))
|
|
2289
|
+
.replace(/[_\s]+/g, '-')
|
|
2290
|
+
.replace(/-+/g, '-');
|
|
2291
|
+
if (meant !== prop && cssProperties().has(meant))
|
|
2292
|
+
refuse(
|
|
2293
|
+
E.ERR_THEME_UNKNOWN_THING,
|
|
2294
|
+
`"${thing}" is not a dial, a token, or a CSS property; the property is ${meant}.`,
|
|
2295
|
+
{
|
|
2296
|
+
didYouMean: [meant],
|
|
2297
|
+
run: [
|
|
2298
|
+
unset
|
|
2299
|
+
? `${P} undo ${slug} ${meant}${onFlag}`
|
|
2300
|
+
: `${P} set ${slug} ${meant} ${quoteCommandArgument(v || exampleOf(groupOfPropType(meant), meant))}${onFlag || ' --on card'}`,
|
|
2301
|
+
],
|
|
2302
|
+
},
|
|
2303
|
+
);
|
|
1316
2304
|
const hint =
|
|
1317
2305
|
/** @type {((v: string, on: string | undefined) => string[]) | undefined} */ (
|
|
1318
2306
|
THING_HINTS[thing.toLowerCase()]
|
|
@@ -1329,7 +2317,7 @@ export function checkSetting(
|
|
|
1329
2317
|
run: aliases.map(d =>
|
|
1330
2318
|
unset
|
|
1331
2319
|
? `${P} undo ${slug} ${d}${onFlag}`
|
|
1332
|
-
: `${P} set ${slug} ${d} ${
|
|
2320
|
+
: `${P} set ${slug} ${d} ${quoteCommandArgument(valueFor(d, v))}${onFlag}`,
|
|
1333
2321
|
),
|
|
1334
2322
|
},
|
|
1335
2323
|
);
|
|
@@ -1337,12 +2325,27 @@ export function checkSetting(
|
|
|
1337
2325
|
E.ERR_THEME_UNKNOWN_THING,
|
|
1338
2326
|
`"${thing}" is not a dial, a token, or a CSS property.`,
|
|
1339
2327
|
{
|
|
2328
|
+
// A hint names this theme and the part (card when none is given),
|
|
2329
|
+
// and a corners value corners takes.
|
|
1340
2330
|
run: hint
|
|
1341
|
-
? hint(
|
|
1342
|
-
|
|
2331
|
+
? hint(
|
|
2332
|
+
/corners/.test(String(hint('', '')))
|
|
2333
|
+
? CORNERS.some(([n]) => n === v) || /^\d+(\.\d+)?px$/.test(v)
|
|
2334
|
+
? v
|
|
2335
|
+
: ''
|
|
2336
|
+
: v,
|
|
2337
|
+
s.on,
|
|
2338
|
+
).map(x =>
|
|
2339
|
+
x
|
|
2340
|
+
.replace(/<theme>/g, slug)
|
|
2341
|
+
.replace(/<part>/g, 'card')
|
|
2342
|
+
.replace(/"([^"]*)"/g, (_, q) => quoteCommandArgument(q)),
|
|
2343
|
+
)
|
|
2344
|
+
: // A list that answers, not a question the parser may not match.
|
|
2345
|
+
[`${HOW} --list properties`, `${HOW} --list dials`],
|
|
1343
2346
|
didYouMean: hint
|
|
1344
2347
|
? []
|
|
1345
|
-
: nearest(prop, [...Object.keys(DIALS), ...
|
|
2348
|
+
: nearest(prop, [...Object.keys(DIALS), ...cssProperties()]),
|
|
1346
2349
|
},
|
|
1347
2350
|
);
|
|
1348
2351
|
}
|
|
@@ -1375,8 +2378,8 @@ function refuseInvisibleCorners(ctx, slug, s, data) {
|
|
|
1375
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(', ')}.` : ''}`,
|
|
1376
2379
|
{
|
|
1377
2380
|
run: kids.length
|
|
1378
|
-
? kids.map(
|
|
1379
|
-
|
|
2381
|
+
? kids.map(k =>
|
|
2382
|
+
setLine(slug, 'corners', s.value || 'round', {...s, on: k}),
|
|
1380
2383
|
)
|
|
1381
2384
|
: [`${HOW} ${s.on}`],
|
|
1382
2385
|
},
|