@astryxdesign/cli 0.7.15 → 0.7.16-canary.g54dd64e
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -3
- package/api/component/_adapter.d.mts +1 -1
- package/api/component/_adapter.mjs +28 -1
- package/api/doctor/_adapter.d.mts +17 -0
- package/api/doctor/_adapter.mjs +35 -0
- package/api/doctor/doctor.mjs +18 -4
- package/api/integration/pack-check.mjs +13 -7
- package/api/integration/validate-integration.mjs +1 -1
- package/api/theme/_adapter.d.mts +5 -2
- package/api/theme/_adapter.mjs +43 -12
- package/api/theme/build/build.d.mts +64 -27
- package/api/theme/build/build.mjs +341 -69
- package/api/theme/eject/eject.mjs +22 -1
- package/api/theme/template/template.d.mts +19 -0
- package/api/theme/template/template.mjs +102 -25
- package/api/theme/theme.type.d.mts +5 -1
- package/api/theme/theme.type.mjs +2 -1
- package/api/theme/themeBuild.doc.mjs +3 -3
- package/api/theme/themeEject.doc.mjs +1 -1
- package/api/theme/themeTemplate.doc.mjs +9 -3
- package/api/theme-edit/_adapter.d.mts +33 -0
- package/api/theme-edit/_adapter.mjs +208 -31
- package/api/theme-edit/_check.d.mts +38 -0
- package/api/theme-edit/_check.mjs +1326 -211
- package/api/theme-edit/_color.d.mts +2 -8
- package/api/theme-edit/_color.mjs +292 -219
- package/api/theme-edit/_compiler.d.mts +1 -0
- package/api/theme-edit/_compiler.mjs +20 -1
- package/api/theme-edit/_context.d.mts +29 -0
- package/api/theme-edit/_context.mjs +329 -30
- package/api/theme-edit/_css.d.mts +60 -1
- package/api/theme-edit/_css.mjs +404 -28
- package/api/theme-edit/_edit.d.mts +9 -0
- package/api/theme-edit/_edit.mjs +1025 -126
- package/api/theme-edit/_how-commands.d.mts +11 -26
- package/api/theme-edit/_how-commands.mjs +30 -2
- package/api/theme-edit/_how-question.d.mts +7 -0
- package/api/theme-edit/_how-question.mjs +1304 -176
- package/api/theme-edit/_how.mjs +144 -30
- package/api/theme-edit/_overview.mjs +2 -0
- package/api/theme-edit/_palette.d.mts +11 -0
- package/api/theme-edit/_palette.mjs +194 -65
- package/api/theme-edit/_parts.d.mts +16 -0
- package/api/theme-edit/_parts.mjs +59 -7
- package/api/theme-edit/_png.mjs +19 -14
- package/api/theme-edit/_preview-app.d.mts +3 -0
- package/api/theme-edit/_preview-app.mjs +843 -45
- package/api/theme-edit/_preview.d.mts +16 -3
- package/api/theme-edit/_preview.mjs +310 -29
- package/api/theme-edit/_project.d.mts +11 -0
- package/api/theme-edit/_project.mjs +46 -12
- package/api/theme-edit/_settings.d.mts +178 -5
- package/api/theme-edit/_settings.mjs +2035 -86
- package/api/theme-edit/_tables.d.mts +24 -0
- package/api/theme-edit/_tables.mjs +211 -149
- package/api/theme-edit/_vet.d.mts +42 -0
- package/api/theme-edit/_vet.mjs +144 -0
- package/api/theme-edit/theme-edit.type.d.mts +2 -1
- package/api/theme-edit/theme-edit.type.mjs +1 -1
- package/api/theme-edit/themeEditNew.doc.mjs +1 -1
- package/api/theme-edit/themeEditShow.doc.mjs +11 -3
- package/api/upgrade/registry/registry.mjs +6 -1
- package/assets/docs/tree/single-component.doc.mjs +11 -2
- package/assets/docs/tree/tokens-and-setup.doc.mjs +39 -3
- package/assets/docs.generated.json +2 -2
- package/assets/preview-app/next.config.mjs +7 -1
- package/assets/preview-app/package.json +1 -0
- package/assets/preview-app/src/app/globals.css +1 -0
- package/assets/self-audit.generated.json +1 -1
- package/assets/templates/blocks/components/Table/ColumnsVirtualizationHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Table/ColumnsVirtualizationHookUsage.tsx +53 -0
- package/assets/templates/blocks/components/Table/InfiniteScrollHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Table/InfiniteScrollHookUsage.tsx +33 -0
- package/assets/templates/components.generated.json +1 -1
- package/assets/templates/pages/dashboard/page.tsx +1 -1
- package/authoring/doctypes/_schema.d.mts +52 -5
- package/authoring/doctypes/_schema.mjs +62 -7
- package/authoring/doctypes/base/type.ts +10 -0
- package/authoring/doctypes/component/component.doc.mjs +1 -1
- package/authoring/doctypes/function/function.doc.mjs +6 -0
- package/authoring/doctypes/function/type.ts +3 -0
- package/authoring/doctypes/legacy.mjs +5 -1
- package/authoring/index.d.ts +1 -0
- package/clients/cli/build-id.generated.json +1 -1
- package/clients/cli/commands/doctor.doc.mjs +2 -2
- package/clients/cli/commands/experimental/theme.mjs +190 -37
- package/clients/cli/commands/experimental-theme-compile.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-eject.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-template.doc.mjs +2 -2
- package/clients/cli/commands/theme-build.doc.mjs +2 -2
- package/clients/cli/commands/theme-eject.doc.mjs +1 -1
- package/clients/cli/commands/theme-template.doc.mjs +3 -1
- package/clients/cli/commands/theme.mjs +168 -45
- package/clients/cli/formatters/index.mjs +7 -4
- package/clients/cli/lib/cli-error.mjs +9 -3
- package/clients/cli/lib/component-format.mjs +27 -9
- package/clients/cli/lib/json-shim.mjs +40 -2
- package/clients/cli/manifest.generated.json +1 -1
- package/clients/cli/run.mjs +49 -0
- package/foundation/config/project.mjs +50 -14
- package/foundation/discovery/theme-discovery.d.mts +5 -1
- package/foundation/discovery/theme-discovery.mjs +24 -3
- package/foundation/fs/gather-cache.d.mts +9 -2
- package/foundation/fs/gather-cache.mjs +79 -15
- package/foundation/fs/paths.d.mts +31 -0
- package/foundation/fs/paths.mjs +43 -10
- package/foundation/render/host-exit.d.mts +8 -0
- package/foundation/render/host-exit.mjs +11 -0
- package/foundation/render/page-host.mjs +56 -10
- package/foundation/render/page-worker.mjs +14 -0
- package/foundation/render/render-page.mjs +37 -2
- package/foundation/response/error-codes.d.mts +2 -1
- package/foundation/response/error-codes.d.ts +1 -0
- package/foundation/response/error-codes.doc.mjs +5 -0
- package/foundation/response/error-codes.mjs +3 -0
- package/foundation/response/json.d.mts +15 -0
- package/foundation/response/json.mjs +52 -1
- package/foundation/response/response-types.doc.mjs +1 -1
- package/package.json +7 -6
|
@@ -9,16 +9,21 @@
|
|
|
9
9
|
* @position api/theme-edit — checks over the part data
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
+
import {AstryxError} from '../error.mjs';
|
|
12
13
|
import * as fs from 'node:fs';
|
|
13
14
|
import * as path from 'node:path';
|
|
15
|
+
import {partForWord} from './_how-question.mjs';
|
|
14
16
|
import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
|
|
15
|
-
import {baseThemeFile} from './_project.mjs';
|
|
17
|
+
import {baseInstalled, baseThemeFile, installLine} from './_project.mjs';
|
|
16
18
|
import {levenshteinDistance} from '../../foundation/text/levenshtein.mjs';
|
|
17
19
|
import {
|
|
20
|
+
withFallbacks,
|
|
18
21
|
MATH_FUNCTION,
|
|
22
|
+
cssNumber,
|
|
19
23
|
belowRange,
|
|
20
24
|
fontShorthandParts,
|
|
21
25
|
cssProperties,
|
|
26
|
+
familyListMeant,
|
|
22
27
|
grammarText,
|
|
23
28
|
initialOf,
|
|
24
29
|
keywordsOf,
|
|
@@ -28,6 +33,7 @@ import {
|
|
|
28
33
|
propertyGrammar,
|
|
29
34
|
takesPercentage,
|
|
30
35
|
} from './_css.mjs';
|
|
36
|
+
import {multipliedTokens} from './_parts.mjs';
|
|
31
37
|
import {
|
|
32
38
|
AUTO_SPREAD,
|
|
33
39
|
COLOR_PROP_PARTS,
|
|
@@ -50,7 +56,10 @@ import {
|
|
|
50
56
|
SPACING,
|
|
51
57
|
TEXT_SIZE,
|
|
52
58
|
THING_HINTS,
|
|
59
|
+
TYPE_STYLES,
|
|
53
60
|
familyOf,
|
|
61
|
+
wordTable,
|
|
62
|
+
WRAPPED_PARTS,
|
|
54
63
|
} from './_tables.mjs';
|
|
55
64
|
import {
|
|
56
65
|
COLOR_NAMES,
|
|
@@ -83,6 +92,13 @@ import {
|
|
|
83
92
|
radiusTokenOf,
|
|
84
93
|
focusStateOf,
|
|
85
94
|
valueProblem,
|
|
95
|
+
partComponentDocs,
|
|
96
|
+
themeFiles,
|
|
97
|
+
ownSourceTokenValues,
|
|
98
|
+
baseTopTokens,
|
|
99
|
+
baseComponentReads,
|
|
100
|
+
partRuleTokens,
|
|
101
|
+
cssFamily,
|
|
86
102
|
} from './_settings.mjs';
|
|
87
103
|
import {quoteCommandArgument} from '../../foundation/env/package-manager.mjs';
|
|
88
104
|
|
|
@@ -104,6 +120,21 @@ function tokenPx(base, token) {
|
|
|
104
120
|
return lengthPx(v);
|
|
105
121
|
}
|
|
106
122
|
|
|
123
|
+
/**
|
|
124
|
+
* The `type` preset nearest a scale ratio typed as a number (1.3 is
|
|
125
|
+
* editorial), or null for a number that is no ratio (16).
|
|
126
|
+
* @param {string} v
|
|
127
|
+
* @returns {string | null}
|
|
128
|
+
*/
|
|
129
|
+
function ratioPreset(v) {
|
|
130
|
+
if (!/^\d+(\.\d+)?$/.test(v)) return null;
|
|
131
|
+
const r = Number(v);
|
|
132
|
+
if (!(r > 1 && r <= 2)) return null;
|
|
133
|
+
return Object.entries(TYPE_STYLES).reduce((a, b) =>
|
|
134
|
+
Math.abs(b[1].ratio - r) < Math.abs(a[1].ratio - r) ? b : a,
|
|
135
|
+
)[0];
|
|
136
|
+
}
|
|
137
|
+
|
|
107
138
|
/**
|
|
108
139
|
* A `set` (or `undo`) command for a setting, with its scope, to suggest.
|
|
109
140
|
* @param {string} slug
|
|
@@ -112,7 +143,7 @@ function tokenPx(base, token) {
|
|
|
112
143
|
* @param {{on?: string, when?: string, state?: string, mode?: string, only?: boolean}} s
|
|
113
144
|
* @param {boolean} [unset]
|
|
114
145
|
*/
|
|
115
|
-
const setLine = (slug, thing, value, s, unset = false) =>
|
|
146
|
+
export const setLine = (slug, thing, value, s, unset = false) =>
|
|
116
147
|
`${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
148
|
|
|
118
149
|
/** @param {string} v */
|
|
@@ -121,6 +152,269 @@ const cornerPxOf = v =>
|
|
|
121
152
|
|
|
122
153
|
const E = ERROR_CODES;
|
|
123
154
|
|
|
155
|
+
/**
|
|
156
|
+
* The fallbacks of the var() calls inside a value that is not one var()
|
|
157
|
+
* alone (`calc(var(--x, 4px) * 2)`), in order. A var() with an empty
|
|
158
|
+
* fallback (`var(--x,)`) gives ''.
|
|
159
|
+
* @param {string} value
|
|
160
|
+
* @returns {Array<{fallback: string, within: string[]}>} each fallback, with
|
|
161
|
+
* the names of the functions around its var(), innermost first
|
|
162
|
+
*/
|
|
163
|
+
function innerVarFallbacks(value) {
|
|
164
|
+
const text = value.trim();
|
|
165
|
+
if (/^var\(/i.test(text) && matchingParen(text, 3) === text.length - 1)
|
|
166
|
+
return [];
|
|
167
|
+
/** @type {Array<{fallback: string, within: string[]}>} */
|
|
168
|
+
const out = [];
|
|
169
|
+
const re = /\bvar\(/gi;
|
|
170
|
+
let m;
|
|
171
|
+
while ((m = re.exec(text))) {
|
|
172
|
+
const open = m.index + m[0].length - 1;
|
|
173
|
+
const close = matchingParen(text, open);
|
|
174
|
+
if (close < 0) break;
|
|
175
|
+
const inner = text.slice(open + 1, close);
|
|
176
|
+
let depth = 0;
|
|
177
|
+
for (let i = 0; i < inner.length; i += 1) {
|
|
178
|
+
const c = inner[i];
|
|
179
|
+
if (c === '(') depth += 1;
|
|
180
|
+
else if (c === ')') depth -= 1;
|
|
181
|
+
else if (c === ',' && depth === 0) {
|
|
182
|
+
out.push({
|
|
183
|
+
fallback: inner.slice(i + 1).trim(),
|
|
184
|
+
within: enclosingFunctions(text, m.index),
|
|
185
|
+
});
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return out;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* The names of the functions whose parentheses are open at `at`, innermost
|
|
195
|
+
* first.
|
|
196
|
+
* @param {string} text
|
|
197
|
+
* @param {number} at
|
|
198
|
+
* @returns {string[]}
|
|
199
|
+
*/
|
|
200
|
+
function enclosingFunctions(text, at) {
|
|
201
|
+
/** @type {string[]} */
|
|
202
|
+
const open = [];
|
|
203
|
+
for (let i = 0; i < at; i += 1) {
|
|
204
|
+
if (text[i] === '(')
|
|
205
|
+
open.push(/([a-z-]*)$/i.exec(text.slice(0, i))?.[1] ?? '');
|
|
206
|
+
else if (text[i] === ')') open.pop();
|
|
207
|
+
}
|
|
208
|
+
return open.reverse();
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* The index of the parenthesis that closes the one at `open`, or -1.
|
|
213
|
+
* @param {string} text
|
|
214
|
+
* @param {number} open
|
|
215
|
+
*/
|
|
216
|
+
function matchingParen(text, open) {
|
|
217
|
+
let depth = 0;
|
|
218
|
+
for (let i = open; i < text.length; i += 1) {
|
|
219
|
+
if (text[i] === '(') depth += 1;
|
|
220
|
+
else if (text[i] === ')') {
|
|
221
|
+
depth -= 1;
|
|
222
|
+
if (depth === 0) return i;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
return -1;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* A text size written another way (20px, 2e1, +20, 1.25rem, 125%, `20 px`,
|
|
230
|
+
* `1,25rem`) as the body size in pixels text-size takes, kept to its 10 to
|
|
231
|
+
* 32 (a size past an end is that end); null when it reads as no size.
|
|
232
|
+
* @param {string} v
|
|
233
|
+
* @returns {number | null}
|
|
234
|
+
*/
|
|
235
|
+
function textSizePx(v) {
|
|
236
|
+
const m = /^\+?(\d*\.?\d+(?:e[+-]?\d+)?)(px|rem|em|%)?$/i.exec(
|
|
237
|
+
typedPlain(v)
|
|
238
|
+
.replace(/(\d)\.(?=[a-z%]*$)/i, '$1')
|
|
239
|
+
.replace(/\s+/g, '')
|
|
240
|
+
.replace(/^(\d+),(\d+)/, '$1.$2'),
|
|
241
|
+
);
|
|
242
|
+
if (!m) return null;
|
|
243
|
+
const unit = (m[2] ?? '').toLowerCase();
|
|
244
|
+
const n =
|
|
245
|
+
Number(m[1]) * (/r?em/.test(unit) ? 16 : unit === '%' ? 16 / 100 : 1);
|
|
246
|
+
const px = Math.round(n * 100) / 100;
|
|
247
|
+
return Math.max(10, Math.min(32, px));
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* A value as it reads once what an input method or a stylesheet adds is
|
|
252
|
+
* taken off: full-width digits, letters and signs (`18`, `#`) as their
|
|
253
|
+
* plain forms, and CSS comments.
|
|
254
|
+
* @param {string} v
|
|
255
|
+
*/
|
|
256
|
+
function typedPlain(v) {
|
|
257
|
+
return v
|
|
258
|
+
.normalize('NFKC')
|
|
259
|
+
.replace(/\/\*[\s\S]*?\*\//g, ' ')
|
|
260
|
+
.replace(/\s+/g, ' ')
|
|
261
|
+
.trim();
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* A font pasted as a declaration (`font-family: Georgia, serif;`, from
|
|
266
|
+
* devtools or a stylesheet), as the family list it names; a `font:`
|
|
267
|
+
* shorthand gives its family. Null when the value is not a pasted
|
|
268
|
+
* declaration.
|
|
269
|
+
* @param {string} v
|
|
270
|
+
* @returns {string | null}
|
|
271
|
+
*/
|
|
272
|
+
export function pastedFont(v) {
|
|
273
|
+
const plain = typedPlain(v);
|
|
274
|
+
const m = /^(font-family|font)\s*:\s*(.*)$/i.exec(plain);
|
|
275
|
+
if (!m) return null;
|
|
276
|
+
const rest = m[2]
|
|
277
|
+
.replace(/;+\s*$/, '')
|
|
278
|
+
.replace(/\s*!\s*important\s*$/i, '')
|
|
279
|
+
.replace(/;+\s*$/, '')
|
|
280
|
+
.trim();
|
|
281
|
+
if (m[1].toLowerCase() === 'font-family') return rest || null;
|
|
282
|
+
const parts = fontShorthandParts(rest);
|
|
283
|
+
return parts && typeof parts['font-family'] === 'string'
|
|
284
|
+
? parts['font-family']
|
|
285
|
+
: null;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* The values a value may have meant, when what is wrong is how it was
|
|
290
|
+
* typed: plain (full-width characters, comments and a trailing `;` gone,
|
|
291
|
+
* quotes around a whole non-font value dropped), and for a font list each
|
|
292
|
+
* family quoted as CSS needs it (`Font Awesome 6 Free`). Only values that
|
|
293
|
+
* differ from the one typed.
|
|
294
|
+
* @param {string} type
|
|
295
|
+
* @param {string} value
|
|
296
|
+
*/
|
|
297
|
+
function valueMeant(type, value) {
|
|
298
|
+
// `!important` is not part of a token's value (the theme places its
|
|
299
|
+
// rules itself): the value without it.
|
|
300
|
+
/** @type {string} */
|
|
301
|
+
let p = (
|
|
302
|
+
type === 'font' || type === 'font-family'
|
|
303
|
+
? (pastedFont(value) ?? value)
|
|
304
|
+
: typedPlain(value)
|
|
305
|
+
)
|
|
306
|
+
.replace(/;+\s*$/, '')
|
|
307
|
+
.replace(/\s*!\s*important\s*$/i, '')
|
|
308
|
+
.replace(/;+\s*$/, '')
|
|
309
|
+
.trim();
|
|
310
|
+
const q = /^(["'])(.*)\1$/.exec(p);
|
|
311
|
+
if (q && type !== 'font') p = q[2].trim();
|
|
312
|
+
const out = [p];
|
|
313
|
+
if (type === 'font' || type === 'font-family') {
|
|
314
|
+
// A comma left out between families (`"Open Sans" serif`), read with
|
|
315
|
+
// css-tree.
|
|
316
|
+
const listed = familyListMeant(p);
|
|
317
|
+
if (listed) out.push(listed);
|
|
318
|
+
// Each family quoted as CSS needs it, only when no family holds a
|
|
319
|
+
// quote inside (the pieces are whole names).
|
|
320
|
+
const pieces = p.split(',').map(f => f.trim().replace(/^["']|["']$/g, ''));
|
|
321
|
+
if (!listed && pieces.every(f => !/["'\\]/.test(f)))
|
|
322
|
+
out.push(pieces.map(f => cssFamily(f, true)).join(', '));
|
|
323
|
+
}
|
|
324
|
+
return [...new Set(out)].filter(x => x && x !== value.trim());
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* Whether a value is one length that works inside calc(): a length with a
|
|
329
|
+
* unit, a variable (with a fallback that is one too), or calc(), min(),
|
|
330
|
+
* max() or clamp() giving a length; never several values, a bare number
|
|
331
|
+
* (calc() cannot add one to a length, 0 included), a percentage or a
|
|
332
|
+
* keyword.
|
|
333
|
+
* @param {string} v
|
|
334
|
+
* @returns {boolean}
|
|
335
|
+
*/
|
|
336
|
+
function oneLength(v) {
|
|
337
|
+
const t = v.trim();
|
|
338
|
+
if (splitTop(t, ' ').length !== 1) return false;
|
|
339
|
+
const ref = /^var\(\s*--[a-z0-9-]+\s*(?:,(.*))?\)$/i.exec(t);
|
|
340
|
+
if (ref) return ref[1] == null || oneLength(ref[1]);
|
|
341
|
+
if (MATH_FUNCTION.test(t)) return matchType('length', t) != null;
|
|
342
|
+
const n = cssNumber(t);
|
|
343
|
+
return !!n && !!n.unit && n.unit !== '%';
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/** The size units a typo is read against. */
|
|
347
|
+
const SIZE_UNITS = ['px', 'rem', 'em', '%', 'vh', 'vw', 'ch'];
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* The size meant by a value one slip away from one: a space inside
|
|
351
|
+
* (`16 px`), a decimal comma (`1,5rem`), a doubled or mistyped unit
|
|
352
|
+
* (`16pxx`), a dot with no digit after it (`1.px`); null when none reads.
|
|
353
|
+
* @param {string} v
|
|
354
|
+
* @param {(x: string) => boolean} ok
|
|
355
|
+
*/
|
|
356
|
+
function sizeMeant(v, ok) {
|
|
357
|
+
const t = v.trim();
|
|
358
|
+
const n = typedPlain(t);
|
|
359
|
+
const tries = [
|
|
360
|
+
n,
|
|
361
|
+
n.replace(/(\d)\.(?=[a-z%]|$)/gi, '$1'),
|
|
362
|
+
t.replace(/(\d)\.(?=[a-z%]|$)/gi, '$1'),
|
|
363
|
+
t.replace(/\s+/g, ''),
|
|
364
|
+
t.replace(/^([+-]?\d+),(\d+)/, '$1.$2').replace(/\s+/g, ''),
|
|
365
|
+
mathSpaced(t),
|
|
366
|
+
];
|
|
367
|
+
const m = /^([+-]?\d*\.?\d+)\s*([a-z%]+)$/i.exec(
|
|
368
|
+
t.replace(/^([+-]?\d+),(\d+)/, '$1.$2'),
|
|
369
|
+
);
|
|
370
|
+
if (m) {
|
|
371
|
+
// A unit typed with a letter too many (pxx, remm, pxs).
|
|
372
|
+
const unit = [...SIZE_UNITS]
|
|
373
|
+
.sort((a, b) => b.length - a.length)
|
|
374
|
+
.find(u => m[2].toLowerCase().startsWith(u));
|
|
375
|
+
if (unit) tries.push(`${m[1]}${unit}`);
|
|
376
|
+
}
|
|
377
|
+
return tries.find(x => x !== t && ok(x)) ?? null;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* A math function with the spaces CSS needs around `+` and `-` put back
|
|
382
|
+
* (`calc(1rem+2px)` is `calc(1rem + 2px)`); the value as it is otherwise.
|
|
383
|
+
* @param {string} v
|
|
384
|
+
*/
|
|
385
|
+
function mathSpaced(v) {
|
|
386
|
+
if (!/^(calc|min|max|clamp)\(/i.test(v) || /\bvar\(/i.test(v)) return v;
|
|
387
|
+
return v.replace(/(\d(?<![\d.]e)|[%a-z)])([+-])(?=[\d.(])/gi, '$1 $2 ');
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* The number meant by a value one slip away from one: a unit on a number
|
|
392
|
+
* (`700px`), a decimal comma (`1,5`), letter O for zero (`7OO`), a weight
|
|
393
|
+
* past the range (`1001` is 1000), a math function with no spaces around
|
|
394
|
+
* `+` or `-`; null when none reads.
|
|
395
|
+
* @param {string} v
|
|
396
|
+
* @param {string} name the token
|
|
397
|
+
* @param {(x: string) => boolean} ok
|
|
398
|
+
*/
|
|
399
|
+
function numberMeant(v, name, ok) {
|
|
400
|
+
const t = v.trim();
|
|
401
|
+
const plain = typedPlain(t).replace(/(\d)\.$/, '$1');
|
|
402
|
+
const comma = plain.replace(/^([+-]?\d+),(\d+)/, '$1.$2');
|
|
403
|
+
const tries = [
|
|
404
|
+
/^[\doO.]+$/.test(plain) && /\d/.test(plain)
|
|
405
|
+
? plain.replace(/[oO]/g, '0')
|
|
406
|
+
: plain,
|
|
407
|
+
comma.replace(/^([+-]?\d*\.?\d+)\s*[a-z]+$/i, '$1'),
|
|
408
|
+
comma,
|
|
409
|
+
mathSpaced(t),
|
|
410
|
+
];
|
|
411
|
+
if (/weight/.test(name)) {
|
|
412
|
+
const n = Number(tries[1]);
|
|
413
|
+
if (Number.isFinite(n)) tries.push(String(Math.min(1000, Math.max(1, n))));
|
|
414
|
+
}
|
|
415
|
+
return tries.find(x => x !== t && ok(x)) ?? null;
|
|
416
|
+
}
|
|
417
|
+
|
|
124
418
|
/**
|
|
125
419
|
* The value to carry into a suggestion for another dial: the one given when
|
|
126
420
|
* that dial takes it, else the dial's example.
|
|
@@ -223,6 +517,32 @@ export function storedProblems(ctx, slug, data, skip = '') {
|
|
|
223
517
|
!(s.thing === 'font' && FONT_ROLES.includes(s.on))
|
|
224
518
|
)
|
|
225
519
|
return scope(`there is no part or group "${s.on}"`);
|
|
520
|
+
// A token that is no design token, or a part property that is no
|
|
521
|
+
// CSS property or names no part, styles nothing: reported, never
|
|
522
|
+
// built.
|
|
523
|
+
if (s.source === 'token' && !(s.thing in TOKENS))
|
|
524
|
+
return {setting: s, why: `${s.thing} is not a design token`};
|
|
525
|
+
if (s.source === 'property' && !s.on)
|
|
526
|
+
return {
|
|
527
|
+
setting: s,
|
|
528
|
+
why: `${s.thing} is a CSS property, so it needs a part (--on)`,
|
|
529
|
+
};
|
|
530
|
+
if (
|
|
531
|
+
s.source === 'property' &&
|
|
532
|
+
!s.thing.startsWith('--') &&
|
|
533
|
+
!cssProperties().has(s.thing)
|
|
534
|
+
)
|
|
535
|
+
return {setting: s, why: `${s.thing} is not a CSS property`};
|
|
536
|
+
// A value its CSS grammar does not take (a hand edit: padding
|
|
537
|
+
// banana) is dropped by the browser: reported by name, never built.
|
|
538
|
+
if (s.source === 'property' && !s.thing.startsWith('--')) {
|
|
539
|
+
const bad = propertyProblem(s.thing, String(s.value ?? ''));
|
|
540
|
+
if (bad)
|
|
541
|
+
return {
|
|
542
|
+
setting: s,
|
|
543
|
+
why: `${s.thing} takes ${bad.takes}, not "${String(s.value ?? '').slice(0, 60)}"`,
|
|
544
|
+
};
|
|
545
|
+
}
|
|
226
546
|
if (s.source === 'dial' && s.on && WHOLE_ONLY.includes(s.thing))
|
|
227
547
|
return scope(`${s.thing} applies to the whole theme, not to ${s.on}`);
|
|
228
548
|
if (s.mode && s.source === 'dial' && !PALETTE_DIALS.includes(s.thing))
|
|
@@ -240,9 +560,32 @@ export function storedProblems(ctx, slug, data, skip = '') {
|
|
|
240
560
|
})();
|
|
241
561
|
if (problem) found.push(problem);
|
|
242
562
|
}
|
|
563
|
+
// A font dial is checked as set checks it (a CSS keyword, a size or a
|
|
564
|
+
// whole CSS font value is no family).
|
|
565
|
+
for (const s of data.settings) {
|
|
566
|
+
if (s.source !== 'dial' || s.thing !== 'font' || s.thing === skip) continue;
|
|
567
|
+
try {
|
|
568
|
+
checkSetting(ctx, slug, data, 'font', s.value, {on: s.on});
|
|
569
|
+
} catch (e) {
|
|
570
|
+
found.push({
|
|
571
|
+
setting: s,
|
|
572
|
+
why:
|
|
573
|
+
e instanceof Error
|
|
574
|
+
? e.message.replace(/ Nothing was changed\.$/, '')
|
|
575
|
+
: String(e),
|
|
576
|
+
});
|
|
577
|
+
}
|
|
578
|
+
}
|
|
243
579
|
for (const s of data.settings) {
|
|
244
580
|
if (s.source !== 'token' || s.thing === skip || !(s.thing in TOKENS))
|
|
245
581
|
continue;
|
|
582
|
+
// A var() a hand edit put in that names no design token reads nothing,
|
|
583
|
+
// as set refuses it.
|
|
584
|
+
const bad = unknownVarRef(String(s.value ?? ''), TOKENS, s.thing);
|
|
585
|
+
if (bad) {
|
|
586
|
+
found.push({setting: s, why: bad.message});
|
|
587
|
+
continue;
|
|
588
|
+
}
|
|
246
589
|
try {
|
|
247
590
|
checkTypedValue(
|
|
248
591
|
ctx.C.typeOf(s.thing),
|
|
@@ -252,8 +595,9 @@ export function storedProblems(ctx, slug, data, skip = '') {
|
|
|
252
595
|
ctx.C.typeOf,
|
|
253
596
|
slug,
|
|
254
597
|
ctx.C.propsReading(s.thing),
|
|
598
|
+
multipliedTokens(ctx.project).has(s.thing),
|
|
255
599
|
);
|
|
256
|
-
checkCycle(s.thing, s.value, TOKENS, data);
|
|
600
|
+
checkCycle(s.thing, s.value, TOKENS, data, ctx.project.cwd, s);
|
|
257
601
|
} catch (e) {
|
|
258
602
|
found.push({
|
|
259
603
|
setting: s,
|
|
@@ -305,6 +649,7 @@ function groupOfPropType(prop) {
|
|
|
305
649
|
* @param {(token: string) => string} typeOf
|
|
306
650
|
* @param {string} slug
|
|
307
651
|
* @param {string[]} [readers] the CSS properties that read the token
|
|
652
|
+
* @param {boolean} [multiplied] whether Core multiplies the token by a size
|
|
308
653
|
*/
|
|
309
654
|
function checkTypedValue(
|
|
310
655
|
type,
|
|
@@ -314,21 +659,48 @@ function checkTypedValue(
|
|
|
314
659
|
typeOf,
|
|
315
660
|
slug,
|
|
316
661
|
readers = [],
|
|
662
|
+
multiplied = false,
|
|
317
663
|
) {
|
|
664
|
+
// The value meant, when what is wrong is how it was typed (a trailing
|
|
665
|
+
// `;`, a comment, quotes around it, full-width characters, a font name
|
|
666
|
+
// that needs quotes): the same value, if the token takes it.
|
|
667
|
+
const meant = () => {
|
|
668
|
+
for (const c of valueMeant(type, value))
|
|
669
|
+
try {
|
|
670
|
+
checkTypedValue(
|
|
671
|
+
type,
|
|
672
|
+
c,
|
|
673
|
+
name,
|
|
674
|
+
TOKENS,
|
|
675
|
+
typeOf,
|
|
676
|
+
slug,
|
|
677
|
+
readers,
|
|
678
|
+
multiplied,
|
|
679
|
+
);
|
|
680
|
+
return c;
|
|
681
|
+
} catch {
|
|
682
|
+
// Not this one.
|
|
683
|
+
}
|
|
684
|
+
return null;
|
|
685
|
+
};
|
|
318
686
|
/** @param {string} what @param {string} example */
|
|
319
687
|
const bad = (what, example) =>
|
|
320
688
|
refuse(
|
|
321
689
|
E.ERR_THEME_BAD_VALUE,
|
|
322
690
|
`${name} is ${what}; "${value}" is not one.`,
|
|
323
|
-
{
|
|
691
|
+
{
|
|
692
|
+
run: [
|
|
693
|
+
`${P} set ${slug} ${name} ${quoteCommandArgument(meant() ?? example)}`,
|
|
694
|
+
],
|
|
695
|
+
},
|
|
324
696
|
);
|
|
325
697
|
if (!isSafeValue(value))
|
|
326
698
|
refuse(
|
|
327
699
|
E.ERR_THEME_BAD_VALUE,
|
|
328
|
-
`"${value}" cannot be a CSS value: it has a ; { } < > or a newline, a comment, !important, or an unclosed bracket or quote
|
|
700
|
+
`"${value}" cannot be a CSS value: it has a ; { } < > or a newline, a comment, !important, or an unclosed bracket or quote.${/!\s*important/i.test(value) ? ' !important is not used: the theme places its own rules.' : ''}`,
|
|
329
701
|
{
|
|
330
702
|
run: [
|
|
331
|
-
`${P} set ${slug} ${name} ${quoteCommandArgument(exampleOf(type, name))}`,
|
|
703
|
+
`${P} set ${slug} ${name} ${quoteCommandArgument(meant() ?? exampleOf(type, name))}`,
|
|
332
704
|
],
|
|
333
705
|
},
|
|
334
706
|
);
|
|
@@ -350,6 +722,41 @@ function checkTypedValue(
|
|
|
350
722
|
],
|
|
351
723
|
},
|
|
352
724
|
);
|
|
725
|
+
// A var() inside a larger value (calc, max, color-mix) has a fallback of
|
|
726
|
+
// the token's kind too, checked like a whole-value var().
|
|
727
|
+
if (type !== 'other')
|
|
728
|
+
for (const {fallback, within} of innerVarFallbacks(value)) {
|
|
729
|
+
// Inside a color's channels (rgb(var(--r, 0) 0 0)) a fallback is a
|
|
730
|
+
// channel, not a color.
|
|
731
|
+
if (
|
|
732
|
+
type === 'color' &&
|
|
733
|
+
within.some(f =>
|
|
734
|
+
/^(rgba?|hsla?|hwb|lab|lch|oklab|oklch|color)$/i.test(f),
|
|
735
|
+
)
|
|
736
|
+
)
|
|
737
|
+
continue;
|
|
738
|
+
if (fallback === '')
|
|
739
|
+
refuse(
|
|
740
|
+
E.ERR_THEME_BAD_VALUE,
|
|
741
|
+
`${name} is a ${type}; the var() in "${value}" has an empty fallback, which leaves it with no value when the variable is unset.`,
|
|
742
|
+
{
|
|
743
|
+
run: [
|
|
744
|
+
`${P} set ${slug} ${name} ${quoteCommandArgument(exampleOf(type, name))}`,
|
|
745
|
+
],
|
|
746
|
+
},
|
|
747
|
+
);
|
|
748
|
+
if (!/\bvar\(/i.test(fallback) && !/^[a-z-]+\(/i.test(fallback))
|
|
749
|
+
checkTypedValue(
|
|
750
|
+
type,
|
|
751
|
+
fallback,
|
|
752
|
+
name,
|
|
753
|
+
TOKENS,
|
|
754
|
+
typeOf,
|
|
755
|
+
slug,
|
|
756
|
+
readers,
|
|
757
|
+
multiplied,
|
|
758
|
+
);
|
|
759
|
+
}
|
|
353
760
|
// A var() naming a design token must name one of the same kind; the
|
|
354
761
|
// app's own variables are its business.
|
|
355
762
|
const ref = /^var\(\s*(--[a-z0-9-]+)\s*(,.*)?\)$/i.exec(value.trim());
|
|
@@ -364,10 +771,54 @@ function checkTypedValue(
|
|
|
364
771
|
],
|
|
365
772
|
},
|
|
366
773
|
);
|
|
774
|
+
// The fallback is what shows when the variable is unset: it must be a
|
|
775
|
+
// value of the token's kind too.
|
|
776
|
+
const fallback = ref[2]?.slice(1).trim();
|
|
777
|
+
if (fallback === '' && type !== 'other')
|
|
778
|
+
refuse(
|
|
779
|
+
E.ERR_THEME_BAD_VALUE,
|
|
780
|
+
`${name} is a ${type}; "${value}" has an empty fallback, which leaves it with no value when the variable is unset.`,
|
|
781
|
+
{
|
|
782
|
+
run: [
|
|
783
|
+
`${P} set ${slug} ${name} ${quoteCommandArgument(exampleOf(type, name))}`,
|
|
784
|
+
],
|
|
785
|
+
},
|
|
786
|
+
);
|
|
787
|
+
if (fallback)
|
|
788
|
+
checkTypedValue(
|
|
789
|
+
type,
|
|
790
|
+
fallback,
|
|
791
|
+
name,
|
|
792
|
+
TOKENS,
|
|
793
|
+
typeOf,
|
|
794
|
+
slug,
|
|
795
|
+
readers,
|
|
796
|
+
multiplied,
|
|
797
|
+
);
|
|
367
798
|
return;
|
|
368
799
|
}
|
|
369
800
|
if (type === 'color' && !isFixedColor(value)) bad('a color', '#1f2937');
|
|
370
|
-
if (type === 'size' && !isSize(value, name))
|
|
801
|
+
if (type === 'size' && !isSize(value, name)) {
|
|
802
|
+
// The size meant, when one dot or sign is all that is wrong (1.px).
|
|
803
|
+
const meant = value.trim().replace(/(\d)\.(?=[a-z%]|$)/gi, '$1');
|
|
804
|
+
// A bare number is the size in px.
|
|
805
|
+
// A bare number is the size in px; a minus sign is dropped.
|
|
806
|
+
const plain = value.trim().replace(/^-(?=\d|\.\d)/, '');
|
|
807
|
+
const px = /^[+]?\d*\.?\d+(e[+-]?\d+)?$/i.test(plain)
|
|
808
|
+
? `${Number(plain)}px`
|
|
809
|
+
: /^\d*\.?\d+[a-z%]+$/i.test(plain) && plain !== value.trim()
|
|
810
|
+
? plain
|
|
811
|
+
: null;
|
|
812
|
+
const slip = sizeMeant(value, x => isSize(x, name));
|
|
813
|
+
bad(
|
|
814
|
+
'a size',
|
|
815
|
+
meant !== value.trim() && isSize(meant, name)
|
|
816
|
+
? meant
|
|
817
|
+
: px && isSize(px, name)
|
|
818
|
+
? px
|
|
819
|
+
: (slip ?? '6px'),
|
|
820
|
+
);
|
|
821
|
+
}
|
|
371
822
|
// A percentage reaches every property that reads the token; one that
|
|
372
823
|
// takes none (a border or outline width, an outline offset) drops it.
|
|
373
824
|
if (type === 'size' && /%/.test(value.replace(/var\([^)]*\)/g, ''))) {
|
|
@@ -379,7 +830,38 @@ function checkTypedValue(
|
|
|
379
830
|
);
|
|
380
831
|
}
|
|
381
832
|
if (type === 'number' && !isNumber(value, name))
|
|
382
|
-
bad(
|
|
833
|
+
bad(
|
|
834
|
+
'a number',
|
|
835
|
+
numberMeant(value, name, x => isNumber(x, name)) ??
|
|
836
|
+
(/weight/.test(name) ? '600' : '1.4'),
|
|
837
|
+
);
|
|
838
|
+
// A token Core's stylesheet multiplies by a size inside calc() (the line
|
|
839
|
+
// heights) takes a number with no unit: there a length, a percentage or
|
|
840
|
+
// normal is invalid.
|
|
841
|
+
const coreDefault = String(TOKENS[name] ?? '').trim();
|
|
842
|
+
const v0 = value.trim();
|
|
843
|
+
const read = cssNumber(v0);
|
|
844
|
+
if (
|
|
845
|
+
type === 'number' &&
|
|
846
|
+
multiplied &&
|
|
847
|
+
!/^var\(--[a-z0-9-]+\)$/i.test(v0) &&
|
|
848
|
+
read?.unit !== '' &&
|
|
849
|
+
!(MATH_FUNCTION.test(v0) && matchType('number', v0) != null)
|
|
850
|
+
) {
|
|
851
|
+
const unitless =
|
|
852
|
+
read?.unit === 'em'
|
|
853
|
+
? String(read.value)
|
|
854
|
+
: read?.unit === '%'
|
|
855
|
+
? String(read.value / 100)
|
|
856
|
+
: coreDefault;
|
|
857
|
+
refuse(
|
|
858
|
+
E.ERR_THEME_BAD_VALUE,
|
|
859
|
+
`${name} takes a number with no unit: Core multiplies it by a text size inside calc() (field heights, dialog headers, code blocks), where "${value}" is invalid. ${unitless === coreDefault ? `Core's own value is ${coreDefault}.` : `${unitless} is the same line height as a number.`}`,
|
|
860
|
+
{
|
|
861
|
+
run: [`${P} set ${slug} ${name} ${quoteCommandArgument(unitless)}`],
|
|
862
|
+
},
|
|
863
|
+
);
|
|
864
|
+
}
|
|
383
865
|
if (type === 'time' && !isTime(value)) bad('a time up to 60s', '150ms');
|
|
384
866
|
if (type === 'easing' && !isEasing(value))
|
|
385
867
|
bad('an easing', 'cubic-bezier(0.2, 0, 0, 1)');
|
|
@@ -408,9 +890,13 @@ function isFixedColor(value) {
|
|
|
408
890
|
if (/^var\(/.test(v)) return true;
|
|
409
891
|
if (SYSTEM_COLORS.includes(v)) return true;
|
|
410
892
|
// Percentages that add up to 0 leave color-mix() no color.
|
|
893
|
+
// A share is 0% to 100%.
|
|
411
894
|
const zeroMix = (/** @type {string[]} */ colors) => {
|
|
412
895
|
const pcts = colors.map(c => mixSide(c).pct);
|
|
413
|
-
return
|
|
896
|
+
return (
|
|
897
|
+
pcts.some(p => p != null && (p < 0 || p > 100)) ||
|
|
898
|
+
(pcts.every(p => p != null) && pcts.every(p => p === 0))
|
|
899
|
+
);
|
|
414
900
|
};
|
|
415
901
|
const inner = (/** @type {string} */ fn) =>
|
|
416
902
|
splitTop(v.slice(fn.length + 1, -1), ',').map(x => x.trim());
|
|
@@ -517,18 +1003,65 @@ function isShadow(value) {
|
|
|
517
1003
|
|
|
518
1004
|
/**
|
|
519
1005
|
* Refuse a value that would read the token itself, through other tokens.
|
|
1006
|
+
* A token set on a part (`--on`) overrides only inside that part: there
|
|
1007
|
+
* it reads the part's own settings first and the whole theme's after, and
|
|
1008
|
+
* a whole-theme value never reads a part's. So a loop counts only when it
|
|
1009
|
+
* closes within one scope: a part token that reads a whole-theme token
|
|
1010
|
+
* reads the inherited value, which is already resolved.
|
|
520
1011
|
* @param {string} thing
|
|
521
1012
|
* @param {string} value
|
|
522
1013
|
* @param {Record<string, unknown>} TOKENS
|
|
523
1014
|
* @param {import('./_settings.mjs').ThemeData} data
|
|
1015
|
+
* @param {string} [cwd] the project, whose `<slug>.theme.ts` tokens win
|
|
1016
|
+
* over the settings and are read too
|
|
1017
|
+
* @param {{on?: string, state?: string, when?: string}} [scope] where
|
|
1018
|
+
* the token is set; none for the whole theme
|
|
524
1019
|
*/
|
|
525
|
-
function checkCycle(thing, value, TOKENS, data) {
|
|
1020
|
+
function checkCycle(thing, value, TOKENS, data, cwd, scope = {}) {
|
|
1021
|
+
const own = cwd ? ownSourceTokenValues(cwd, data.name) : {};
|
|
1022
|
+
// The base theme's own values come under the settings: a base that maps
|
|
1023
|
+
// one token to another closes a loop too.
|
|
1024
|
+
const baseTokens = cwd ? baseTopTokens(cwd, data.like) : new Map();
|
|
1025
|
+
const on = scope.on ?? null;
|
|
1026
|
+
const settings = [...data.settings].reverse();
|
|
1027
|
+
/**
|
|
1028
|
+
* The token's value set on the part, or undefined: a setting with the
|
|
1029
|
+
* same state and variant wins over the part's plain one.
|
|
1030
|
+
* @param {string} t
|
|
1031
|
+
*/
|
|
1032
|
+
const partValue = t => {
|
|
1033
|
+
if (on == null) return undefined;
|
|
1034
|
+
const onPart = settings.filter(
|
|
1035
|
+
s => s.source === 'token' && s.thing === t && s.on === on,
|
|
1036
|
+
);
|
|
1037
|
+
const same = onPart.find(
|
|
1038
|
+
s =>
|
|
1039
|
+
(s.state ?? null) === (scope.state ?? null) &&
|
|
1040
|
+
(s.when ?? null) === (scope.when ?? null),
|
|
1041
|
+
);
|
|
1042
|
+
const set = (same ?? onPart.find(s => s.state == null && s.when == null))
|
|
1043
|
+
?.value;
|
|
1044
|
+
if (set !== undefined) return set;
|
|
1045
|
+
// Else what the part's plain rule holds as built: the own source's and
|
|
1046
|
+
// the base theme's part rules (neutral's progress-bar reads
|
|
1047
|
+
// --color-border-emphasized).
|
|
1048
|
+
if (scope.state || scope.when || !cwd) return undefined;
|
|
1049
|
+
const rule = partRule().get(t);
|
|
1050
|
+
return rule ?? undefined;
|
|
1051
|
+
};
|
|
1052
|
+
/** @type {Map<string, string | null> | null} */
|
|
1053
|
+
let rule = null;
|
|
1054
|
+
const partRule = () =>
|
|
1055
|
+
(rule ??= on
|
|
1056
|
+
? partRuleTokens(/** @type {string} */ (cwd), data.name, data.like, on)
|
|
1057
|
+
: new Map());
|
|
526
1058
|
/** @param {string} t */
|
|
527
|
-
const
|
|
1059
|
+
const globalValue = t =>
|
|
528
1060
|
String(
|
|
529
|
-
[
|
|
530
|
-
.
|
|
531
|
-
|
|
1061
|
+
(Object.hasOwn(own, t) ? own[t] : null) ??
|
|
1062
|
+
settings.find(s => s.source === 'token' && s.thing === t && !s.on)
|
|
1063
|
+
?.value ??
|
|
1064
|
+
baseTokens.get(t) ??
|
|
532
1065
|
TOKENS[t] ??
|
|
533
1066
|
'',
|
|
534
1067
|
);
|
|
@@ -537,23 +1070,40 @@ function checkCycle(thing, value, TOKENS, data) {
|
|
|
537
1070
|
/** @type {string[]} */
|
|
538
1071
|
const path = [];
|
|
539
1072
|
const seen = new Set();
|
|
540
|
-
/**
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
1073
|
+
/**
|
|
1074
|
+
* Whether `t`, read in the part (`inPart`) or the whole theme, reaches
|
|
1075
|
+
* the token being set in its own scope.
|
|
1076
|
+
* @param {string} t @param {boolean} inPart @returns {boolean}
|
|
1077
|
+
*/
|
|
1078
|
+
const reaches = (t, inPart) => {
|
|
1079
|
+
// The token being set is reached only in the scope it is set in.
|
|
1080
|
+
if (t === thing && inPart === (on != null)) return true;
|
|
1081
|
+
const part = inPart ? partValue(t) : undefined;
|
|
1082
|
+
const local = part !== undefined;
|
|
1083
|
+
const key = `${local ? 'part' : 'theme'}:${t}`;
|
|
1084
|
+
if (seen.has(key)) return false;
|
|
1085
|
+
seen.add(key);
|
|
1086
|
+
path.push(
|
|
1087
|
+
local
|
|
1088
|
+
? `${t} (on ${on})`
|
|
1089
|
+
: Object.hasOwn(own, t)
|
|
1090
|
+
? `${t} (set in ${data.name}.theme.ts)`
|
|
1091
|
+
: t,
|
|
1092
|
+
);
|
|
1093
|
+
if (
|
|
1094
|
+
refs(local ? String(part) : globalValue(t)).some(r => reaches(r, local))
|
|
1095
|
+
)
|
|
1096
|
+
return true;
|
|
547
1097
|
path.pop();
|
|
548
1098
|
return false;
|
|
549
1099
|
};
|
|
550
|
-
if (refs(value).some(reaches))
|
|
1100
|
+
if (refs(value).some(r => reaches(r, on != null)))
|
|
551
1101
|
refuse(
|
|
552
1102
|
E.ERR_THEME_BAD_VALUE,
|
|
553
1103
|
`${thing} would read itself${path.length ? ` through ${path.join(', ')}` : ''}, so it would have no value at all.`,
|
|
554
1104
|
{
|
|
555
1105
|
run: [
|
|
556
|
-
`${P} set ${data.name} ${thing} <a value that does not read ${thing}
|
|
1106
|
+
`${P} set ${data.name} ${thing} <a value that does not read ${thing}>${on != null ? ` --on ${on}` : ''}`,
|
|
557
1107
|
],
|
|
558
1108
|
},
|
|
559
1109
|
);
|
|
@@ -582,10 +1132,31 @@ function propertyProblem(prop, value) {
|
|
|
582
1132
|
const v = value.trim();
|
|
583
1133
|
const known = propertyGrammar(prop);
|
|
584
1134
|
if (!known || COLOR_PROPS.test(prop)) return null;
|
|
1135
|
+
// Each var() fallback is what shows when its variable is unset: the
|
|
1136
|
+
// value with the fallbacks in place must be one the property takes too.
|
|
1137
|
+
const unset = withFallbacks(v);
|
|
1138
|
+
if (unset != null && matchValue(prop, v) && !matchValue(prop, unset))
|
|
1139
|
+
return {
|
|
1140
|
+
takes: `a value its CSS grammar takes in each var() fallback too (${grammarText(known)})`,
|
|
1141
|
+
near: initialOf(prop),
|
|
1142
|
+
};
|
|
585
1143
|
if (matchValue(prop, v))
|
|
586
1144
|
return belowRange(prop, v)
|
|
587
|
-
? {
|
|
1145
|
+
? {
|
|
1146
|
+
takes: 'a value of 0 or more',
|
|
1147
|
+
near: v.replace(/(^|[\s(,/])-(?=\.?\d)/g, '$1'),
|
|
1148
|
+
}
|
|
588
1149
|
: null;
|
|
1150
|
+
// The same value as it was meant to be typed (a font name quoted, a
|
|
1151
|
+
// trailing `;` gone), when the property takes that.
|
|
1152
|
+
const fixed = valueMeant(prop === 'font-family' ? 'font' : 'other', v).find(
|
|
1153
|
+
c => matchValue(prop, c),
|
|
1154
|
+
);
|
|
1155
|
+
if (fixed)
|
|
1156
|
+
return {
|
|
1157
|
+
takes: `a value its CSS grammar takes (${grammarText(known)})`,
|
|
1158
|
+
near: fixed,
|
|
1159
|
+
};
|
|
589
1160
|
// Only keywords the property takes on their own are offered; the same
|
|
590
1161
|
// word without its dashes or a trailing -ed/-s comes first (no-wrap is
|
|
591
1162
|
// nowrap, underlined is underline), then the nearest in spelling.
|
|
@@ -602,57 +1173,90 @@ function propertyProblem(prop, value) {
|
|
|
602
1173
|
// the property's initial value, or an example of its kind; each checked.
|
|
603
1174
|
const example = exampleOf(groupOfPropType(prop), prop);
|
|
604
1175
|
const initial = initialOf(prop);
|
|
1176
|
+
// A bare number on a length property means px (`padding 4` → `4px`, each
|
|
1177
|
+
// number in a list too), when the property takes that.
|
|
1178
|
+
// Each bare number token gets px (a mixed list `4 8px`, `8 / 4`, an
|
|
1179
|
+
// exponent `1e1`), a unit split off by a space (`4 px`) joins its number.
|
|
1180
|
+
const joined = v.replace(/(\d)\s+(px|rem|em|%)\b/gi, '$1$2');
|
|
1181
|
+
const withPx = /\d/.test(joined)
|
|
1182
|
+
? joined.replace(
|
|
1183
|
+
/(^|[\s/(,])([+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?)(?=$|[\s/),])/gi,
|
|
1184
|
+
(_, pre, num) =>
|
|
1185
|
+
Number(num) === 0 ? `${pre}${num}` : `${pre}${num}px`,
|
|
1186
|
+
)
|
|
1187
|
+
: null;
|
|
1188
|
+
// A suggestion is offered only when the property takes it, in range too.
|
|
1189
|
+
const takes = (/** @type {string | null} */ x) =>
|
|
1190
|
+
x != null && matchValue(prop, x) != null && !belowRange(prop, x);
|
|
605
1191
|
return {
|
|
606
1192
|
takes: `a value its CSS grammar takes (${grammarText(known)})`,
|
|
607
1193
|
near:
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
(
|
|
1194
|
+
(takes(withPx) ? withPx : null) ??
|
|
1195
|
+
// Below the property's range (a negative width): the same, 0 or more.
|
|
1196
|
+
(withPx && takes(withPx.replace(/(^|[\s/(,])-(?=\.?\d)/g, '$1'))
|
|
1197
|
+
? withPx.replace(/(^|[\s/(,])-(?=\.?\d)/g, '$1')
|
|
1198
|
+
: null) ??
|
|
1199
|
+
(takes(joined) && joined !== v ? joined : null) ??
|
|
1200
|
+
// Several values on a property that takes one (padding-top with four):
|
|
1201
|
+
// the first of them, when it is one the property takes.
|
|
1202
|
+
(() => {
|
|
1203
|
+
const first = splitTop((withPx ?? joined).trim(), ' ')[0];
|
|
1204
|
+
return first && first !== v && takes(first) ? first : null;
|
|
1205
|
+
})() ??
|
|
1206
|
+
(near && takes(near) ? near : null) ??
|
|
1207
|
+
// A value with numbers never falls back to the property's reset
|
|
1208
|
+
// (padding 0 would remove what was asked for).
|
|
1209
|
+
(/\d/.test(v)
|
|
1210
|
+
? null
|
|
1211
|
+
: ((takes(initial) ? initial : null) ??
|
|
1212
|
+
(takes(example) ? example : null))),
|
|
611
1213
|
};
|
|
612
1214
|
}
|
|
613
1215
|
|
|
614
1216
|
/** Words people use for a dial's values, by dial. */
|
|
615
|
-
const DIAL_WORDS =
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
}
|
|
1217
|
+
const DIAL_WORDS = wordTable(
|
|
1218
|
+
/** @type {Record<string, Record<string, string>>} */ ({
|
|
1219
|
+
surfaces: {
|
|
1220
|
+
elevated: 'raised',
|
|
1221
|
+
elevation: 'raised',
|
|
1222
|
+
shadow: 'raised',
|
|
1223
|
+
shadows: 'raised',
|
|
1224
|
+
lifted: 'raised',
|
|
1225
|
+
frosted: 'glass',
|
|
1226
|
+
blur: 'glass',
|
|
1227
|
+
blurred: 'glass',
|
|
1228
|
+
translucent: 'glass',
|
|
1229
|
+
bordered: 'outlined',
|
|
1230
|
+
border: 'outlined',
|
|
1231
|
+
borders: 'outlined',
|
|
1232
|
+
lined: 'outlined',
|
|
1233
|
+
outline: 'outlined',
|
|
1234
|
+
plain: 'flat',
|
|
1235
|
+
minimal: 'flat',
|
|
1236
|
+
},
|
|
1237
|
+
buttons: {
|
|
1238
|
+
uppercase: 'caps',
|
|
1239
|
+
upper: 'caps',
|
|
1240
|
+
allcaps: 'caps',
|
|
1241
|
+
capitals: 'caps',
|
|
1242
|
+
tint: 'soft',
|
|
1243
|
+
tinted: 'soft',
|
|
1244
|
+
subtle: 'soft',
|
|
1245
|
+
outlined: 'outline',
|
|
1246
|
+
bordered: 'outline',
|
|
1247
|
+
ghost: 'outline',
|
|
1248
|
+
filled: 'solid',
|
|
1249
|
+
fill: 'solid',
|
|
1250
|
+
},
|
|
1251
|
+
mode: {
|
|
1252
|
+
auto: 'both',
|
|
1253
|
+
system: 'both',
|
|
1254
|
+
default: 'both',
|
|
1255
|
+
light: 'light-only',
|
|
1256
|
+
dark: 'dark-only',
|
|
1257
|
+
},
|
|
1258
|
+
}),
|
|
1259
|
+
);
|
|
656
1260
|
|
|
657
1261
|
/**
|
|
658
1262
|
/**
|
|
@@ -693,6 +1297,94 @@ export function checkSetting(
|
|
|
693
1297
|
value,
|
|
694
1298
|
flags,
|
|
695
1299
|
unset = false,
|
|
1300
|
+
) {
|
|
1301
|
+
// The font dial's value as pasted from a stylesheet (`Georgia, serif;`,
|
|
1302
|
+
// a comment, `!important`): a refusal suggests the font it names, when
|
|
1303
|
+
// set takes that.
|
|
1304
|
+
// A font pasted with its property name is the family list it names.
|
|
1305
|
+
if (
|
|
1306
|
+
!unset &&
|
|
1307
|
+
typeof value === 'string' &&
|
|
1308
|
+
(thing === 'font' ||
|
|
1309
|
+
(thing.startsWith('--') && ctx.C.typeOf(thing) === 'font'))
|
|
1310
|
+
) {
|
|
1311
|
+
const pasted = pastedFont(value);
|
|
1312
|
+
if (pasted) value = pasted;
|
|
1313
|
+
}
|
|
1314
|
+
if (thing === 'font' && !unset && typeof value === 'string') {
|
|
1315
|
+
const meant = typedPlain(value)
|
|
1316
|
+
.replace(/;+\s*$/, '')
|
|
1317
|
+
.replace(/\s*!\s*important\s*$/i, '')
|
|
1318
|
+
.replace(/;+\s*$/, '')
|
|
1319
|
+
.replace(/\s+/g, ' ')
|
|
1320
|
+
.trim();
|
|
1321
|
+
if (meant && meant !== value.trim())
|
|
1322
|
+
try {
|
|
1323
|
+
return checkSettingAsTyped(ctx, slug, data, thing, value, flags);
|
|
1324
|
+
} catch (e) {
|
|
1325
|
+
try {
|
|
1326
|
+
checkSettingAsTyped(ctx, slug, data, thing, meant, flags);
|
|
1327
|
+
} catch {
|
|
1328
|
+
throw e;
|
|
1329
|
+
}
|
|
1330
|
+
if (e instanceof AstryxError)
|
|
1331
|
+
e.suggestions = [
|
|
1332
|
+
{
|
|
1333
|
+
name: `${P} set ${slug} font ${quoteCommandArgument(meant)}${flags.on ? ` --on ${quoteCommandArgument(flags.on)}` : ''}`,
|
|
1334
|
+
reason: 'do this instead',
|
|
1335
|
+
},
|
|
1336
|
+
];
|
|
1337
|
+
throw e;
|
|
1338
|
+
}
|
|
1339
|
+
}
|
|
1340
|
+
const s = checkSettingAsTyped(ctx, slug, data, thing, value, flags, unset);
|
|
1341
|
+
// A var() with a fallback always gives a value; a name one slip from a
|
|
1342
|
+
// design token is noted as a likely typo, and the setting stands.
|
|
1343
|
+
if (!unset && typeof value === 'string' && !s.note) {
|
|
1344
|
+
const typo = fallbackVarTypo(value, ctx.project.core.tokenDefaults ?? {});
|
|
1345
|
+
if (typo) s.note = typo;
|
|
1346
|
+
}
|
|
1347
|
+
return s;
|
|
1348
|
+
}
|
|
1349
|
+
|
|
1350
|
+
/**
|
|
1351
|
+
* A note for a var() with a fallback whose name is a letter or two off a
|
|
1352
|
+
* design token (`var(--spacing-xl, 2rem)` when the token is `--spacing-x1`):
|
|
1353
|
+
* the fallback shows until it is fixed. Null when there is none.
|
|
1354
|
+
* @param {string} v
|
|
1355
|
+
* @param {Record<string, unknown>} TOKENS
|
|
1356
|
+
*/
|
|
1357
|
+
function fallbackVarTypo(v, TOKENS) {
|
|
1358
|
+
for (const [, name] of v.matchAll(/var\(\s*(--[a-z0-9-]+)\s*,/gi)) {
|
|
1359
|
+
if (name in TOKENS || name.startsWith('--_')) continue;
|
|
1360
|
+
const near = nearest(name, Object.keys(TOKENS)).filter(
|
|
1361
|
+
n => levenshteinDistance(n, name) <= 2,
|
|
1362
|
+
);
|
|
1363
|
+
if (near.length)
|
|
1364
|
+
return `${name} is not a design token, so its fallback always shows; did you mean ${near[0]}?`;
|
|
1365
|
+
}
|
|
1366
|
+
return null;
|
|
1367
|
+
}
|
|
1368
|
+
|
|
1369
|
+
/**
|
|
1370
|
+
* checkSetting for the value as typed.
|
|
1371
|
+
* @param {import('./_settings.mjs').Ctx} ctx
|
|
1372
|
+
* @param {string} slug
|
|
1373
|
+
* @param {import('./_settings.mjs').ThemeData} data
|
|
1374
|
+
* @param {string} thing
|
|
1375
|
+
* @param {string | undefined} value
|
|
1376
|
+
* @param {SetFlags} flags
|
|
1377
|
+
* @param {boolean} [unset]
|
|
1378
|
+
* @returns {import('./_settings.mjs').Setting}
|
|
1379
|
+
*/
|
|
1380
|
+
function checkSettingAsTyped(
|
|
1381
|
+
ctx,
|
|
1382
|
+
slug,
|
|
1383
|
+
data,
|
|
1384
|
+
thing,
|
|
1385
|
+
value,
|
|
1386
|
+
flags,
|
|
1387
|
+
unset = false,
|
|
696
1388
|
) {
|
|
697
1389
|
const s = checkOne(ctx, slug, data, thing, value, flags, unset);
|
|
698
1390
|
const why = unset ? null : valueProblem(s);
|
|
@@ -757,42 +1449,20 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
757
1449
|
run: [`${P} ${unset ? 'undo' : 'set'} --help`],
|
|
758
1450
|
});
|
|
759
1451
|
// 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();
|
|
1452
|
+
const v = normalValue(thing, value ?? '');
|
|
764
1453
|
// A var() that misspells a design token would read nothing.
|
|
765
|
-
if (!unset)
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
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
|
-
);
|
|
784
|
-
if (near.length)
|
|
785
|
-
refuse(
|
|
786
|
-
E.ERR_THEME_UNKNOWN_TOKEN,
|
|
787
|
-
`${name} is not a design token, so var(${name}) would read nothing.`,
|
|
788
|
-
{
|
|
789
|
-
didYouMean: near,
|
|
790
|
-
run: [
|
|
791
|
-
`${HOW} --list tokens ${near[0].replace(/^--/, '').split('-')[0]}`,
|
|
792
|
-
],
|
|
793
|
-
},
|
|
794
|
-
);
|
|
795
|
-
}
|
|
1454
|
+
if (!unset) {
|
|
1455
|
+
const bad = unknownVarRef(v, TOKENS, thing);
|
|
1456
|
+
if (bad)
|
|
1457
|
+
refuse(E.ERR_THEME_UNKNOWN_TOKEN, bad.message, {
|
|
1458
|
+
didYouMean: bad.near,
|
|
1459
|
+
run: [
|
|
1460
|
+
bad.close
|
|
1461
|
+
? `${HOW} --list tokens ${bad.near[0].replace(/^--/, '').split('-')[0]}`
|
|
1462
|
+
: `${HOW} --list tokens`,
|
|
1463
|
+
],
|
|
1464
|
+
});
|
|
1465
|
+
}
|
|
796
1466
|
// A placeholder copied from a suggestion is not a value.
|
|
797
1467
|
if (!unset && /<[a-z][\w -]*>/i.test(v))
|
|
798
1468
|
refuse(
|
|
@@ -814,7 +1484,15 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
814
1484
|
});
|
|
815
1485
|
if (flags.on) s.on = flags.on.trim();
|
|
816
1486
|
if (flags.when) s.when = flags.when.trim();
|
|
817
|
-
|
|
1487
|
+
// A state in any case or spelling of its words (focusVisible,
|
|
1488
|
+
// focus_visible, 'focus visible') is the state, written as CSS writes it.
|
|
1489
|
+
if (flags.state)
|
|
1490
|
+
s.state = flags.state
|
|
1491
|
+
.trim()
|
|
1492
|
+
.replace(/^:+/, '')
|
|
1493
|
+
.replace(/([a-z0-9])([A-Z])/g, '$1-$2')
|
|
1494
|
+
.replace(/[\s_]+/g, '-')
|
|
1495
|
+
.toLowerCase();
|
|
818
1496
|
if (flags.only) s.only = true;
|
|
819
1497
|
if (flags.mode) {
|
|
820
1498
|
const mode = flags.mode.toLowerCase();
|
|
@@ -879,17 +1557,39 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
879
1557
|
if (s.on && !isRole && !FAMILIES[s.on]) {
|
|
880
1558
|
const t = TARGET.get(s.on);
|
|
881
1559
|
if (!t) {
|
|
882
|
-
// Another case of a part or group
|
|
883
|
-
|
|
884
|
-
|
|
1560
|
+
// Another case of a part or group, its class name copied from the
|
|
1561
|
+
// page (`.astryx-card`), or its component (`<Card>`, `Card`): that
|
|
1562
|
+
// part, as a working command with every flag kept.
|
|
1563
|
+
const lower = s.on
|
|
1564
|
+
.trim()
|
|
1565
|
+
.replace(/^<\/?\s*|\s*\/?>$/g, '')
|
|
1566
|
+
.replace(/^\./, '')
|
|
1567
|
+
.replace(/^astryx-/, '')
|
|
1568
|
+
.replace(/([a-z0-9])([A-Z])/g, '$1-$2')
|
|
1569
|
+
.toLowerCase();
|
|
1570
|
+
// A plain word how reads as a part or group (checkboxes: checks).
|
|
1571
|
+
const byWord = partForWord(lower);
|
|
1572
|
+
// A plain plural of a part (cards, dialogs, tabs) is that part.
|
|
1573
|
+
const singular = [
|
|
1574
|
+
lower.replace(/ies$/, 'y'),
|
|
1575
|
+
lower.replace(/(ch|sh|x|s)es$/, '$1'),
|
|
1576
|
+
lower.replace(/s$/, ''),
|
|
1577
|
+
].find(x => x !== lower && (TARGET.has(x) || FAMILIES[x]));
|
|
1578
|
+
const named =
|
|
1579
|
+
TARGET.has(lower) || FAMILIES[lower]
|
|
1580
|
+
? lower
|
|
1581
|
+
: singular
|
|
1582
|
+
? singular
|
|
1583
|
+
: byWord && (TARGET.has(byWord) || FAMILIES[byWord])
|
|
1584
|
+
? byWord
|
|
1585
|
+
: null;
|
|
1586
|
+
if (named)
|
|
885
1587
|
refuse(
|
|
886
1588
|
E.ERR_THEME_UNKNOWN_PART,
|
|
887
|
-
`"${s.on}" is not a part
|
|
1589
|
+
`"${s.on}" is not a part name; the part is ${named}.`,
|
|
888
1590
|
{
|
|
889
|
-
didYouMean: [
|
|
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
|
-
],
|
|
1591
|
+
didYouMean: [named],
|
|
1592
|
+
run: [setLine(slug, thing, v, {...s, on: named}, unset)],
|
|
893
1593
|
},
|
|
894
1594
|
);
|
|
895
1595
|
refuse(
|
|
@@ -902,7 +1602,7 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
902
1602
|
...Object.keys(FAMILIES),
|
|
903
1603
|
]),
|
|
904
1604
|
run: [
|
|
905
|
-
`${HOW} --list parts ${
|
|
1605
|
+
`${HOW} --list parts ${quoteCommandArgument(lower.replace(/s$/, '').split('-')[0] || 'button')}`,
|
|
906
1606
|
`${HOW} ${quoteCommandArgument(s.on)}`,
|
|
907
1607
|
],
|
|
908
1608
|
},
|
|
@@ -931,20 +1631,37 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
931
1631
|
);
|
|
932
1632
|
}
|
|
933
1633
|
const states = [...t.states, ...COMMON_STATES];
|
|
1634
|
+
// Other words for a state, mapped to the one the part has; with none
|
|
1635
|
+
// near, the list of its states (never a guess such as hover).
|
|
1636
|
+
const SYNONYMS = wordTable(
|
|
1637
|
+
/** @type {Record<string, string[]>} */ ({
|
|
1638
|
+
pressed: ['active'],
|
|
1639
|
+
press: ['active'],
|
|
1640
|
+
down: ['active'],
|
|
1641
|
+
clicked: ['active'],
|
|
1642
|
+
hovered: ['hover'],
|
|
1643
|
+
focused: ['focus-visible', 'focus-within', 'focus'],
|
|
1644
|
+
checked: ['checked', 'selected'],
|
|
1645
|
+
selected: ['selected', 'checked'],
|
|
1646
|
+
open: ['open', 'expanded'],
|
|
1647
|
+
expanded: ['expanded', 'open'],
|
|
1648
|
+
inactive: ['disabled'],
|
|
1649
|
+
}),
|
|
1650
|
+
);
|
|
1651
|
+
const meant =
|
|
1652
|
+
(SYNONYMS[String(s.state ?? '').toLowerCase()] ?? []).find(x =>
|
|
1653
|
+
states.includes(x),
|
|
1654
|
+
) ?? nearest(String(s.state ?? ''), states)[0];
|
|
934
1655
|
if (s.state && !states.includes(s.state))
|
|
935
1656
|
refuse(
|
|
936
1657
|
E.ERR_THEME_UNKNOWN_STATE,
|
|
937
1658
|
`"${s.state}" is not a state of ${s.on}. States: ${states.join(', ')}.`,
|
|
938
1659
|
{
|
|
939
|
-
didYouMean:
|
|
1660
|
+
...(meant ? {didYouMean: [meant]} : {}),
|
|
940
1661
|
run: [
|
|
941
|
-
|
|
942
|
-
slug,
|
|
943
|
-
|
|
944
|
-
v,
|
|
945
|
-
{...s, state: nearest(s.state, states)[0] ?? 'hover'},
|
|
946
|
-
unset,
|
|
947
|
-
),
|
|
1662
|
+
meant
|
|
1663
|
+
? setLine(slug, thing, v, {...s, state: meant}, unset)
|
|
1664
|
+
: `${HOW} ${quoteCommandArgument(s.on)}`,
|
|
948
1665
|
],
|
|
949
1666
|
},
|
|
950
1667
|
);
|
|
@@ -990,16 +1707,10 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
990
1707
|
// The part's component, or the one named like the part (tab is Tab,
|
|
991
1708
|
// under TabList), takes a disabled prop.
|
|
992
1709
|
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
1710
|
// Or its built module sets aria-disabled (a tab takes it through its
|
|
1000
1711
|
// other props): what Core renders, read from Core itself.
|
|
1001
|
-
const marks = (/** @type {string} */ n) => {
|
|
1002
|
-
const at =
|
|
1712
|
+
const marks = (/** @type {string} */ n, /** @type {any} */ doc) => {
|
|
1713
|
+
const at = doc?.importPath?.split('/').pop();
|
|
1003
1714
|
const file =
|
|
1004
1715
|
at && ctx.project.coreDir
|
|
1005
1716
|
? path.join(ctx.project.coreDir, 'dist', at, `${n}.js`)
|
|
@@ -1012,13 +1723,25 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
1012
1723
|
return false;
|
|
1013
1724
|
}
|
|
1014
1725
|
};
|
|
1015
|
-
return
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
(
|
|
1019
|
-
marks(n)),
|
|
1726
|
+
return partComponentDocs(ctx, t).some(
|
|
1727
|
+
({name, doc}) =>
|
|
1728
|
+
Object.keys(doc.props ?? {}).some(p => /disabled/i.test(p)) ||
|
|
1729
|
+
marks(name, doc),
|
|
1020
1730
|
);
|
|
1021
1731
|
};
|
|
1732
|
+
// A part holds content that can take focus, so focus-within applies
|
|
1733
|
+
// there: its component takes children or elements in a prop (a dialog,
|
|
1734
|
+
// a section, a chat composer's input).
|
|
1735
|
+
const holdsContent = (/** @type {string} */ t) =>
|
|
1736
|
+
partComponentDocs(ctx, t).some(({doc}) =>
|
|
1737
|
+
Object.entries(doc.props ?? {}).some(
|
|
1738
|
+
([k, v]) =>
|
|
1739
|
+
k === 'children' ||
|
|
1740
|
+
/\bReact(Node|Element)\b/.test(
|
|
1741
|
+
String(/** @type {any} */ (v)?.type ?? ''),
|
|
1742
|
+
),
|
|
1743
|
+
),
|
|
1744
|
+
);
|
|
1022
1745
|
// A part Core never styles in focus is not what takes focus (the
|
|
1023
1746
|
// focusable element is inside it, or beside it).
|
|
1024
1747
|
const focusable = (/** @type {string} */ t) =>
|
|
@@ -1026,7 +1749,8 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
1026
1749
|
const dead = parts.filter(
|
|
1027
1750
|
t =>
|
|
1028
1751
|
!states(t).includes(/** @type {string} */ (s.state)) &&
|
|
1029
|
-
(Object.keys(own(t)).length === 0
|
|
1752
|
+
((Object.keys(own(t)).length === 0 &&
|
|
1753
|
+
!(s.state === 'focus-within' && holdsContent(t))) ||
|
|
1030
1754
|
((s.state === 'focus' || s.state === 'focus-visible') &&
|
|
1031
1755
|
!focusable(t)) ||
|
|
1032
1756
|
(s.state === 'disabled' &&
|
|
@@ -1038,7 +1762,8 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
1038
1762
|
// focusable is inside it (a switch's input sits beside its track).
|
|
1039
1763
|
(s.state === 'focus-within' &&
|
|
1040
1764
|
!keys(t, 'focus-within') &&
|
|
1041
|
-
!focusable(t)
|
|
1765
|
+
!focusable(t) &&
|
|
1766
|
+
!holdsContent(t))),
|
|
1042
1767
|
);
|
|
1043
1768
|
if (parts.length && dead.length === parts.length) {
|
|
1044
1769
|
const bare = Object.keys(own(dead[0])).length === 0;
|
|
@@ -1069,6 +1794,42 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
1069
1794
|
);
|
|
1070
1795
|
}
|
|
1071
1796
|
}
|
|
1797
|
+
// Core expands a part's padding into its container tokens from a plain
|
|
1798
|
+
// padding only, so in a state that padding never reaches what sits edge
|
|
1799
|
+
// to edge inside it: refused, judged on the part named (a group member
|
|
1800
|
+
// spreads; when only another member is the reason, --only keeps it to
|
|
1801
|
+
// the part named).
|
|
1802
|
+
if (!unset && s.on && s.state && ctx.derived) {
|
|
1803
|
+
const prop =
|
|
1804
|
+
/^padding/.test(thing) || thing === 'spacing' ? 'padding' : null;
|
|
1805
|
+
const expands = (/** @type {string} */ t) =>
|
|
1806
|
+
(ctx.derived?.[t] ?? []).some(
|
|
1807
|
+
d => d.property === prop && d.expand === 'container',
|
|
1808
|
+
);
|
|
1809
|
+
const named = ctx.project.target.get(s.on) ? s.on : null;
|
|
1810
|
+
const hit = prop
|
|
1811
|
+
? named && expands(named)
|
|
1812
|
+
? named
|
|
1813
|
+
: partsOf(ctx, s).find(expands)
|
|
1814
|
+
: undefined;
|
|
1815
|
+
if (hit)
|
|
1816
|
+
refuse(
|
|
1817
|
+
E.ERR_THEME_NO_EFFECT,
|
|
1818
|
+
`Core sets ${hit}'s inner padding (what sits edge to edge inside it) from a plain padding setting only, so with --state ${s.state} it would stay behind.`,
|
|
1819
|
+
{
|
|
1820
|
+
// The value as set takes it: a bare number in px.
|
|
1821
|
+
run: (() => {
|
|
1822
|
+
const fixed =
|
|
1823
|
+
thing === 'spacing' ? v : (propertyProblem(thing, v)?.near ?? v);
|
|
1824
|
+
return [
|
|
1825
|
+
named && !expands(named) && !s.only
|
|
1826
|
+
? setLine(slug, thing, fixed, {...s, only: true})
|
|
1827
|
+
: setLine(slug, thing, fixed, {...s, state: undefined}),
|
|
1828
|
+
];
|
|
1829
|
+
})(),
|
|
1830
|
+
},
|
|
1831
|
+
);
|
|
1832
|
+
}
|
|
1072
1833
|
// On a group, a variant or state must belong to at least one member.
|
|
1073
1834
|
if (s.on && FAMILIES[s.on] && (s.when || s.state)) {
|
|
1074
1835
|
const members =
|
|
@@ -1100,6 +1861,23 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
1100
1861
|
{run: [`${HOW} ${s.on}`]},
|
|
1101
1862
|
);
|
|
1102
1863
|
}
|
|
1864
|
+
// A comparative is a step from the value now (never a rung picked by
|
|
1865
|
+
// spelling, which can go the other way).
|
|
1866
|
+
if (!unset && (thing === 'corners' || thing === 'spacing')) {
|
|
1867
|
+
const w = v.toLowerCase();
|
|
1868
|
+
const MORE =
|
|
1869
|
+
thing === 'corners'
|
|
1870
|
+
? /^(rounder|softer|bigger|larger|curvier|more rounded)$/
|
|
1871
|
+
: /^(roomier|looser|bigger|larger|wider|airier|more spacious)$/;
|
|
1872
|
+
const LESS =
|
|
1873
|
+
thing === 'corners'
|
|
1874
|
+
? /^(sharper|squarer|smaller|tighter|harder|less rounded)$/
|
|
1875
|
+
: /^(tighter|denser|smaller|narrower|more compact|closer)$/;
|
|
1876
|
+
if (MORE.test(w))
|
|
1877
|
+
return checkOne(ctx, slug, data, thing, 'more', flags, unset);
|
|
1878
|
+
if (LESS.test(w))
|
|
1879
|
+
return checkOne(ctx, slug, data, thing, 'less', flags, unset);
|
|
1880
|
+
}
|
|
1103
1881
|
const step = v === 'more' || v === 'less';
|
|
1104
1882
|
// more/less step a dial with a scale; on a dial of named looks, they name
|
|
1105
1883
|
// nothing, so the answer is what the dial takes, not one of its values.
|
|
@@ -1153,21 +1931,32 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
1153
1931
|
didYouMean: near,
|
|
1154
1932
|
run: near[0]
|
|
1155
1933
|
? [`${P} set ${slug} ${thing} ${near[0]}`]
|
|
1156
|
-
: // A
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1934
|
+
: // A type-scale ratio (1.25) is the nearest type preset.
|
|
1935
|
+
thing === 'type' && ratioPreset(lower)
|
|
1936
|
+
? [`${P} set ${slug} type ${ratioPreset(lower)}`]
|
|
1937
|
+
: // A corner word or a size with a unit is the corners dial:
|
|
1938
|
+
// on the buttons for `buttons`, for the whole theme
|
|
1939
|
+
// otherwise. A bare number is no size: the dial's own
|
|
1940
|
+
// words.
|
|
1941
|
+
CORNERS.some(([n]) => lower.replace(/s$/, '') === n) ||
|
|
1942
|
+
(/[a-z%]$/.test(lower) && lengthPx(lower) != null)
|
|
1943
|
+
? [
|
|
1944
|
+
setLine(
|
|
1945
|
+
slug,
|
|
1946
|
+
'corners',
|
|
1947
|
+
CORNERS.find(
|
|
1948
|
+
([n]) => lower.replace(/s$/, '') === n,
|
|
1949
|
+
)?.[0] ?? lower,
|
|
1950
|
+
thing === 'buttons' ? {on: 'button'} : {},
|
|
1951
|
+
),
|
|
1952
|
+
]
|
|
1953
|
+
: [
|
|
1954
|
+
...(/^[+-]?\d*\.?\d+$/.test(lower) ? ok : [])
|
|
1955
|
+
.filter(w => /^[a-z-]+$/.test(w))
|
|
1956
|
+
.slice(0, 4)
|
|
1957
|
+
.map(w => `${P} set ${slug} ${thing} ${w}`),
|
|
1958
|
+
`${HOW} ${thing}`,
|
|
1959
|
+
],
|
|
1171
1960
|
},
|
|
1172
1961
|
);
|
|
1173
1962
|
}
|
|
@@ -1179,9 +1968,24 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
1179
1968
|
E.ERR_THEME_BAD_VALUE,
|
|
1180
1969
|
'headings applies to every heading; drop --on. For one heading level use font-weight or letter-spacing --on heading --when level:<1-6>.',
|
|
1181
1970
|
{
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1971
|
+
// The dial without --on, then the asked weight or tracking on
|
|
1972
|
+
// one level; a word with no meaning here gets neither.
|
|
1973
|
+
run: (() => {
|
|
1974
|
+
const w = String(v ?? '')
|
|
1975
|
+
.trim()
|
|
1976
|
+
.toLowerCase();
|
|
1977
|
+
if (HEADING_WEIGHTS[w] !== undefined)
|
|
1978
|
+
return [
|
|
1979
|
+
`${P} set ${slug} headings ${w}`,
|
|
1980
|
+
`${P} set ${slug} font-weight ${HEADING_WEIGHTS[w]} --on heading --when level:1`,
|
|
1981
|
+
];
|
|
1982
|
+
if (HEADING_TRACKING[w] !== undefined)
|
|
1983
|
+
return [
|
|
1984
|
+
`${P} set ${slug} headings ${w}`,
|
|
1985
|
+
`${P} set ${slug} letter-spacing ${quoteCommandArgument(HEADING_TRACKING[w])} --on heading --when level:1`,
|
|
1986
|
+
];
|
|
1987
|
+
return [`${HOW} headings`];
|
|
1988
|
+
})(),
|
|
1185
1989
|
},
|
|
1186
1990
|
);
|
|
1187
1991
|
if (s.mode)
|
|
@@ -1209,28 +2013,36 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
1209
2013
|
}
|
|
1210
2014
|
if (HEADING_WEIGHTS[v] !== undefined) s.axis = 'weight';
|
|
1211
2015
|
else if (HEADING_TRACKING[v] !== undefined) s.axis = 'tracking';
|
|
1212
|
-
else
|
|
2016
|
+
else {
|
|
2017
|
+
// The word meant: in other letters (BOLD), or the rung nearest a
|
|
2018
|
+
// weight number (800 is heavy); never a rung the other way.
|
|
2019
|
+
const lower = v.trim().toLowerCase();
|
|
2020
|
+
const words = [
|
|
2021
|
+
...Object.keys(HEADING_WEIGHTS),
|
|
2022
|
+
...Object.keys(HEADING_TRACKING),
|
|
2023
|
+
];
|
|
2024
|
+
const weight = /^\d+(\.\d+)?$/.test(lower) ? Number(lower) : null;
|
|
2025
|
+
const meant =
|
|
2026
|
+
words.find(w => w === lower) ??
|
|
2027
|
+
(weight != null
|
|
2028
|
+
? Object.entries(HEADING_WEIGHTS).reduce((a, b) =>
|
|
2029
|
+
Math.abs(Number(b[1]) - weight) <
|
|
2030
|
+
Math.abs(Number(a[1]) - weight)
|
|
2031
|
+
? b
|
|
2032
|
+
: a,
|
|
2033
|
+
)[0]
|
|
2034
|
+
: nearest(lower, words)[0]);
|
|
1213
2035
|
refuse(
|
|
1214
2036
|
E.ERR_THEME_BAD_VALUE,
|
|
1215
|
-
`headings takes ${DIALS.headings.values}, not "${v}"
|
|
2037
|
+
`headings takes ${DIALS.headings.values}, not "${v}".${weight != null && meant ? ` ${meant} sets weight ${HEADING_WEIGHTS[meant]}.` : ''}`,
|
|
1216
2038
|
{
|
|
1217
|
-
didYouMean:
|
|
1218
|
-
|
|
1219
|
-
|
|
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
|
-
],
|
|
2039
|
+
didYouMean: meant ? [meant] : [],
|
|
2040
|
+
run: meant
|
|
2041
|
+
? [setLine(slug, 'headings', meant, s)]
|
|
2042
|
+
: [`${HOW} headings`],
|
|
1232
2043
|
},
|
|
1233
2044
|
);
|
|
2045
|
+
}
|
|
1234
2046
|
return s;
|
|
1235
2047
|
}
|
|
1236
2048
|
if (unset) return s;
|
|
@@ -1309,17 +2121,26 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
1309
2121
|
const edge = /** @type {[string, number]} */ (
|
|
1310
2122
|
v === 'more' ? L[L.length - 1] : L[0]
|
|
1311
2123
|
);
|
|
2124
|
+
// The example stays inside what the dial takes (text-size: 10 to
|
|
2125
|
+
// 32); at that end, the exact token takes the size instead.
|
|
2126
|
+
const [lo, hi] = thing === 'text-size' ? [10, 32] : [0, Infinity];
|
|
2127
|
+
const want = Math.round(px + (v === 'more' ? 2 : -2));
|
|
2128
|
+
const atEnd = v === 'more' ? px >= hi : px <= lo;
|
|
1312
2129
|
const example = String(cur).replace(
|
|
1313
2130
|
/\d*\.?\d+/,
|
|
1314
|
-
String(Math.max(
|
|
2131
|
+
String(Math.max(lo, Math.min(hi, want))),
|
|
1315
2132
|
);
|
|
1316
2133
|
refuse(
|
|
1317
2134
|
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
|
|
2135
|
+
`${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.${atEnd ? ` It is also the ${v === 'more' ? 'largest' : 'smallest'} size ${thing} takes (${lo} to ${hi}); the base font size token takes any size.` : ' Give an exact size.'}`,
|
|
1319
2136
|
{
|
|
1320
|
-
run:
|
|
1321
|
-
|
|
1322
|
-
|
|
2137
|
+
run: atEnd
|
|
2138
|
+
? [
|
|
2139
|
+
`${P} set ${slug} --font-size-base ${quoteCommandArgument(`${Math.max(1, want)}px`)}`,
|
|
2140
|
+
]
|
|
2141
|
+
: [
|
|
2142
|
+
`${P} set ${slug} ${thing} ${quoteCommandArgument(example)}${s.on ? ` --on ${s.on}` : ''}`,
|
|
2143
|
+
],
|
|
1323
2144
|
},
|
|
1324
2145
|
);
|
|
1325
2146
|
}
|
|
@@ -1469,10 +2290,15 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
1469
2290
|
} else {
|
|
1470
2291
|
// A rung in any case, a size in px written any way: the plain form.
|
|
1471
2292
|
const lower = v.toLowerCase();
|
|
1472
|
-
|
|
2293
|
+
// Any CSS number in px (2e1px, +4px), the shared length parse.
|
|
2294
|
+
const pxLen = /px$/.test(lower) ? lengthPx(lower) : null;
|
|
1473
2295
|
if (CORNERS.some(([n]) => n === lower)) s.value = lower;
|
|
1474
|
-
else if (
|
|
1475
|
-
|
|
2296
|
+
else if (pxLen != null && pxLen >= 0)
|
|
2297
|
+
s.value =
|
|
2298
|
+
pxLen >= 1000 ? 'pill' : `${Math.round(pxLen * 10000) / 10000}px`;
|
|
2299
|
+
// No rounding, said any way, is square.
|
|
2300
|
+
else if (/^(0|0%|none|sharp|zero|no|flat)$/.test(lower))
|
|
2301
|
+
s.value = 'square';
|
|
1476
2302
|
else {
|
|
1477
2303
|
// What it most likely means, as a value corners takes: a simple
|
|
1478
2304
|
// calc() of px is worked out.
|
|
@@ -1574,6 +2400,17 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
1574
2400
|
run: [setLine(slug, 'spacing', nearFactor, s)],
|
|
1575
2401
|
},
|
|
1576
2402
|
);
|
|
2403
|
+
else if (/^(0|none|zero|no|off)$/i.test(v))
|
|
2404
|
+
// Spacing scales the theme's space; it never goes to nothing. The
|
|
2405
|
+
// tightest rung is the nearest that works.
|
|
2406
|
+
refuse(
|
|
2407
|
+
E.ERR_THEME_BAD_VALUE,
|
|
2408
|
+
`spacing scales the theme's space and never removes it; the tightest it goes is ${SPACING[0][0]}. For no space on one part, set padding or gap 0 on it.`,
|
|
2409
|
+
{
|
|
2410
|
+
didYouMean: [SPACING[0][0]],
|
|
2411
|
+
run: [setLine(slug, 'spacing', SPACING[0][0], s)],
|
|
2412
|
+
},
|
|
2413
|
+
);
|
|
1577
2414
|
else if (!SPACING.some(([n]) => n === v))
|
|
1578
2415
|
refuse(
|
|
1579
2416
|
E.ERR_THEME_BAD_VALUE,
|
|
@@ -1601,10 +2438,34 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
1601
2438
|
refuse(
|
|
1602
2439
|
E.ERR_THEME_BAD_VALUE,
|
|
1603
2440
|
'text-size applies to the whole theme; for one part use font-size.',
|
|
1604
|
-
{
|
|
2441
|
+
{
|
|
2442
|
+
// The asked size on the part: a rung's px (large is 15px), a
|
|
2443
|
+
// number as px; a step (more, less) has no size to carry.
|
|
2444
|
+
run: (() => {
|
|
2445
|
+
const w = String(v ?? '')
|
|
2446
|
+
.trim()
|
|
2447
|
+
.toLowerCase();
|
|
2448
|
+
const rung = TEXT_SIZE.find(([n]) => n === w)?.[1];
|
|
2449
|
+
const px =
|
|
2450
|
+
rung ?? (/^\d+(\.\d+)?(px)?$/.test(w) ? parseFloat(w) : null);
|
|
2451
|
+
return px != null && px > 0
|
|
2452
|
+
? [setLine(slug, 'font-size', `${px}px`, s)]
|
|
2453
|
+
: [`${HOW} font-size`];
|
|
2454
|
+
})(),
|
|
2455
|
+
},
|
|
1605
2456
|
);
|
|
1606
2457
|
if (step) s.value = ladder(TEXT_SIZE, 'medium');
|
|
1607
2458
|
else if (
|
|
2459
|
+
/^\d+\.\d+$/.test(v.trim()) &&
|
|
2460
|
+
Number(v) >= 10 &&
|
|
2461
|
+
Number(v) <= 32 &&
|
|
2462
|
+
Math.round(Number(v)) !== Number(v)
|
|
2463
|
+
) {
|
|
2464
|
+
// Core builds the type scale in whole pixels: the size is saved as
|
|
2465
|
+
// the whole pixel it builds, and the result says so.
|
|
2466
|
+
s.value = String(Math.round(Number(v)));
|
|
2467
|
+
s.note = `text-size ${v.trim()} is saved as ${s.value}: the type scale is built in whole pixels`;
|
|
2468
|
+
} else if (
|
|
1608
2469
|
!TEXT_SIZE.some(([n]) => n === v) &&
|
|
1609
2470
|
!(/^\d+(\.\d+)?$/.test(v.trim()) && Number(v) >= 10 && Number(v) <= 32)
|
|
1610
2471
|
)
|
|
@@ -1624,7 +2485,19 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
1624
2485
|
didYouMean: [near],
|
|
1625
2486
|
run: [`${P} set ${slug} text-size ${near}`],
|
|
1626
2487
|
}
|
|
1627
|
-
: {
|
|
2488
|
+
: {
|
|
2489
|
+
run: [
|
|
2490
|
+
`${P} set ${slug} text-size ${
|
|
2491
|
+
// A size typed full-width or with a trailing dot
|
|
2492
|
+
// (18, 18.) is that size.
|
|
2493
|
+
/^\d+(\.\d+)?\.?$/.test(typedPlain(v)) &&
|
|
2494
|
+
Number(typedPlain(v).replace(/\.$/, '')) >= 10 &&
|
|
2495
|
+
Number(typedPlain(v).replace(/\.$/, '')) <= 32
|
|
2496
|
+
? String(Number(typedPlain(v).replace(/\.$/, '')))
|
|
2497
|
+
: (textSizePx(v) ?? 16)
|
|
2498
|
+
}`,
|
|
2499
|
+
],
|
|
2500
|
+
};
|
|
1628
2501
|
})(),
|
|
1629
2502
|
);
|
|
1630
2503
|
else if (!TEXT_SIZE.some(([n]) => n === v))
|
|
@@ -1639,7 +2512,7 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
1639
2512
|
// What the value most likely meant: without quotes, a trailing `;`
|
|
1640
2513
|
// or `!important`, a bare hex with its #, the opaque color, or the
|
|
1641
2514
|
// nearest color name.
|
|
1642
|
-
const cleaned = v
|
|
2515
|
+
const cleaned = typedPlain(v)
|
|
1643
2516
|
.replace(/^(["'])(.*)\1$/, '$2')
|
|
1644
2517
|
.replace(/\s*!important\s*$/i, '')
|
|
1645
2518
|
.replace(/;+\s*$/, '')
|
|
@@ -1697,23 +2570,34 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
1697
2570
|
},
|
|
1698
2571
|
);
|
|
1699
2572
|
s.value = String(next);
|
|
1700
|
-
}
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
2573
|
+
}
|
|
2574
|
+
const colors = data.settings.filter(
|
|
2575
|
+
x => x.source === 'dial' && PALETTE_DIALS.includes(x.thing),
|
|
2576
|
+
);
|
|
2577
|
+
// With no color to saturate, no vibrancy value is suggested.
|
|
2578
|
+
const canApply = colors.some(x => !isGraySeed(seedOf(x.value)));
|
|
2579
|
+
if (!step && canApply && (!/^\d{1,3}$/.test(v) || Number(v) > 100)) {
|
|
2580
|
+
// The value meant: a step in other letters (MORE), or the number
|
|
2581
|
+
// read as CSS reads it (70%, 7e1), kept in range.
|
|
2582
|
+
const word = v.trim().toLowerCase();
|
|
2583
|
+
const n = cssNumber(v);
|
|
2584
|
+
const near = ['more', 'less'].includes(word)
|
|
2585
|
+
? word
|
|
2586
|
+
: n && (n.unit === '' || n.unit === '%')
|
|
2587
|
+
? String(Math.max(0, Math.min(100, Math.round(n.value))))
|
|
2588
|
+
: null;
|
|
1706
2589
|
refuse(
|
|
1707
2590
|
E.ERR_THEME_BAD_VALUE,
|
|
1708
2591
|
`vibrancy takes a whole number from 0 (gray) to 100 (most vivid), or more or less, not "${v}".`,
|
|
1709
|
-
{
|
|
2592
|
+
{
|
|
2593
|
+
run: near
|
|
2594
|
+
? [`${P} set ${slug} vibrancy ${near}`]
|
|
2595
|
+
: [`${HOW} vibrancy`],
|
|
2596
|
+
},
|
|
1710
2597
|
);
|
|
1711
|
-
} else s.value = String(Number(v));
|
|
1712
|
-
const colors = data.settings.filter(
|
|
1713
|
-
x => x.source === 'dial' && PALETTE_DIALS.includes(x.thing),
|
|
1714
|
-
);
|
|
2598
|
+
} else if (!step && /^\d{1,3}$/.test(v)) s.value = String(Number(v));
|
|
1715
2599
|
// A gray has no color to saturate, so vibrancy changes nothing.
|
|
1716
|
-
if (!
|
|
2600
|
+
if (!canApply)
|
|
1717
2601
|
refuse(
|
|
1718
2602
|
E.ERR_THEME_NO_EFFECT,
|
|
1719
2603
|
colors.length
|
|
@@ -1741,7 +2625,7 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
1741
2625
|
const family = !parts && matchValue('font-family', v);
|
|
1742
2626
|
const example = `${P} set ${slug} font-family ${quoteCommandArgument(exampleOf('font', 'font-family'))} --on ${s.on}`;
|
|
1743
2627
|
const runs = parts
|
|
1744
|
-
? parts.system
|
|
2628
|
+
? parts.system || parts.repeat
|
|
1745
2629
|
? [example]
|
|
1746
2630
|
: Object.entries(parts).map(
|
|
1747
2631
|
([k, x]) =>
|
|
@@ -1754,9 +2638,55 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
1754
2638
|
: [example];
|
|
1755
2639
|
refuse(
|
|
1756
2640
|
E.ERR_THEME_BAD_VALUE,
|
|
1757
|
-
parts?.
|
|
1758
|
-
? `font --on takes body, heading, or code, and "${v}"
|
|
1759
|
-
:
|
|
2641
|
+
parts?.repeat
|
|
2642
|
+
? `font --on takes body, heading, or code, and "${v}" ${parts.part?.includes(',') ? `gives ${parts.repeat} more times than the parts that take it (${parts.part})` : `gives ${parts.part ?? 'one part of the font'} twice (${parts.repeat} is the second)`}, which no CSS font value does. For one part's font use font-family with a family, and set each other part of the font once.`
|
|
2643
|
+
: parts?.system
|
|
2644
|
+
? `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.`
|
|
2645
|
+
: `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' : ''}.`,
|
|
2646
|
+
{run: runs},
|
|
2647
|
+
);
|
|
2648
|
+
}
|
|
2649
|
+
// A size, a weight or a whole CSS font value is no family: the font
|
|
2650
|
+
// dial and the roles take the family alone.
|
|
2651
|
+
// A variable is answered below, as the token form.
|
|
2652
|
+
const fontParts =
|
|
2653
|
+
step || /\b(var|env)\(/i.test(v) ? null : fontShorthandParts(v);
|
|
2654
|
+
if (
|
|
2655
|
+
fontParts &&
|
|
2656
|
+
(fontParts.repeat ||
|
|
2657
|
+
fontParts.system ||
|
|
2658
|
+
Object.keys(fontParts).some(k => k !== 'font-family'))
|
|
2659
|
+
) {
|
|
2660
|
+
const fam = fontParts['font-family'];
|
|
2661
|
+
const on = s.on ? ` --on ${s.on}` : '';
|
|
2662
|
+
/** @type {string[]} */
|
|
2663
|
+
const runs = [
|
|
2664
|
+
`${P} set ${slug} font ${quoteCommandArgument(fam ?? 'inter')}${on}`,
|
|
2665
|
+
];
|
|
2666
|
+
if (fontParts['font-size'] && (!s.on || s.on === 'body'))
|
|
2667
|
+
runs.push(
|
|
2668
|
+
`${P} set ${slug} --font-size-base ${quoteCommandArgument(fontParts['font-size'])}`,
|
|
2669
|
+
);
|
|
2670
|
+
const w = fontParts['font-weight'];
|
|
2671
|
+
if (w && (!s.on || s.on === 'heading')) {
|
|
2672
|
+
const num =
|
|
2673
|
+
w === 'bold' ? 700 : w === 'normal' ? 400 : Number(w) || null;
|
|
2674
|
+
const rung = num
|
|
2675
|
+
? Object.entries(HEADING_WEIGHTS).reduce((a, b) =>
|
|
2676
|
+
Math.abs(Number(b[1]) - num) < Math.abs(Number(a[1]) - num)
|
|
2677
|
+
? b
|
|
2678
|
+
: a,
|
|
2679
|
+
)[0]
|
|
2680
|
+
: null;
|
|
2681
|
+
if (rung) runs.push(`${P} set ${slug} headings ${rung}`);
|
|
2682
|
+
}
|
|
2683
|
+
refuse(
|
|
2684
|
+
E.ERR_THEME_BAD_VALUE,
|
|
2685
|
+
`font${s.on ? ` --on ${s.on}` : ''} takes a family or a preset, and "${v}" ${fam ? 'is a whole CSS font value' : 'is no family'}: ${
|
|
2686
|
+
Object.keys(fontParts)
|
|
2687
|
+
.filter(k => !['font-family', 'repeat', 'system'].includes(k))
|
|
2688
|
+
.join(', ') || 'a keyword'
|
|
2689
|
+
} ${fam ? 'would be read as part of the family name' : 'would be read as a family name'}, and the text would fall back.`,
|
|
1760
2690
|
{run: runs},
|
|
1761
2691
|
);
|
|
1762
2692
|
}
|
|
@@ -1875,16 +2805,40 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
1875
2805
|
const meant = v
|
|
1876
2806
|
.toLowerCase()
|
|
1877
2807
|
.replace(/^base\s*[=:]\s*/, '')
|
|
1878
|
-
.trim()
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
2808
|
+
.trim()
|
|
2809
|
+
.replace(/^@astryxdesign\/theme-/, '')
|
|
2810
|
+
.replace(/^theme-/, '');
|
|
2811
|
+
// Only a base this project has installed is suggested; a theme
|
|
2812
|
+
// made here is never a base.
|
|
2813
|
+
const bases = [
|
|
2814
|
+
...LIKE.filter(b => baseInstalled(ctx.project, b)),
|
|
2815
|
+
'none',
|
|
2816
|
+
];
|
|
2817
|
+
// The base named in other letters is the one meant; a guess is
|
|
2818
|
+
// only among installed bases.
|
|
2819
|
+
const near =
|
|
2820
|
+
bases.includes(meant) || LIKE.includes(meant)
|
|
2821
|
+
? [meant]
|
|
2822
|
+
: nearest(meant, bases);
|
|
2823
|
+
// A built-in base named that is not installed: install it, then the
|
|
2824
|
+
// same set.
|
|
2825
|
+
const install =
|
|
2826
|
+
LIKE.includes(meant) && !baseInstalled(ctx.project, meant)
|
|
2827
|
+
? [installLine(ctx.project.cwd, [`@astryxdesign/theme-${meant}`])]
|
|
2828
|
+
: [];
|
|
2829
|
+
const madeHere = fs.existsSync(themeFiles(ctx.project.cwd, v).settings);
|
|
1882
2830
|
refuse(
|
|
1883
2831
|
E.ERR_THEME_BAD_VALUE,
|
|
1884
|
-
`base takes ${DIALS.base.values}, not "${v}"
|
|
2832
|
+
`base takes ${DIALS.base.values}, not "${v}".${madeHere ? ` ${v} is a theme made here, and a theme builds only on a built-in one.` : ''}`,
|
|
1885
2833
|
{
|
|
1886
2834
|
didYouMean: near,
|
|
1887
|
-
|
|
2835
|
+
// With nothing near, every base that works here, none first.
|
|
2836
|
+
run: near[0]
|
|
2837
|
+
? [...install, `${P} set ${slug} base ${near[0]}`]
|
|
2838
|
+
: [
|
|
2839
|
+
'none',
|
|
2840
|
+
...LIKE.filter(b => baseInstalled(ctx.project, b)),
|
|
2841
|
+
].map(b => `${P} set ${slug} base ${b}`),
|
|
1888
2842
|
},
|
|
1889
2843
|
);
|
|
1890
2844
|
}
|
|
@@ -1965,17 +2919,21 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
1965
2919
|
C.typeOf,
|
|
1966
2920
|
slug,
|
|
1967
2921
|
C.propsReading(thing),
|
|
2922
|
+
multipliedTokens(ctx.project).has(thing),
|
|
1968
2923
|
);
|
|
1969
|
-
checkCycle(thing, v, TOKENS, data);
|
|
2924
|
+
checkCycle(thing, v, TOKENS, data, ctx.project.cwd, s);
|
|
1970
2925
|
// With no part data, what reads the token is unknown: save, unchecked.
|
|
1971
2926
|
if (ctx.unchecked) return s;
|
|
1972
2927
|
const parts = partsOf(ctx, s);
|
|
1973
2928
|
if (parts.length) {
|
|
2929
|
+
// A part the base theme's own rule makes read the token reads it.
|
|
1974
2930
|
const results = parts.map(
|
|
1975
2931
|
t =>
|
|
1976
2932
|
/** @type {[string, import('./_compiler.mjs').CheckFailure | null]} */ ([
|
|
1977
2933
|
t,
|
|
1978
|
-
|
|
2934
|
+
baseComponentReads(ctx.project.cwd, data.like, t).has(thing)
|
|
2935
|
+
? null
|
|
2936
|
+
: C.checkTokenOn(slug, t, thing, v, P),
|
|
1979
2937
|
]),
|
|
1980
2938
|
);
|
|
1981
2939
|
const recorded = results.filter(([, r]) => !r?.soft);
|
|
@@ -2101,6 +3059,76 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
2101
3059
|
s.source = 'property';
|
|
2102
3060
|
s.thing = prop;
|
|
2103
3061
|
if (unset) return s;
|
|
3062
|
+
// A part whose visible box is drawn inside its themed wrapper: only
|
|
3063
|
+
// what reaches that box is taken.
|
|
3064
|
+
const wrapped = s.on ? WRAPPED_PARTS[s.on] : undefined;
|
|
3065
|
+
if (wrapped) {
|
|
3066
|
+
const surface =
|
|
3067
|
+
/^(background|border|box-shadow|outline)(-|$)/.test(prop) &&
|
|
3068
|
+
!/radius/.test(prop);
|
|
3069
|
+
const side = /^padding-/.test(prop);
|
|
3070
|
+
const density = prop === 'padding' && /^density:/.test(s.when ?? '');
|
|
3071
|
+
// Core reads the composer's padding inside calc() (the send button's
|
|
3072
|
+
// radius, the status row), as its own default var(--spacing-3) is:
|
|
3073
|
+
// one length works there, whether a length, a variable, or calc(),
|
|
3074
|
+
// min(), max() or clamp() giving one.
|
|
3075
|
+
if (prop === 'padding' && !density && !oneLength(v)) {
|
|
3076
|
+
const first = splitTop(v.trim(), ' ')[0] ?? '';
|
|
3077
|
+
const n = cssNumber(first);
|
|
3078
|
+
const fix = oneLength(first)
|
|
3079
|
+
? first
|
|
3080
|
+
: n && !n.unit
|
|
3081
|
+
? `${n.value}px`
|
|
3082
|
+
: '12px';
|
|
3083
|
+
refuse(
|
|
3084
|
+
E.ERR_THEME_BAD_VALUE,
|
|
3085
|
+
`${s.on} reads its padding inside calc() (the send button's corners, the status row), where only one length works: a length, a variable, or calc(), min(), max() or clamp() giving one; not "${v.trim()}".`,
|
|
3086
|
+
{
|
|
3087
|
+
run: [
|
|
3088
|
+
`${P} set ${slug} padding ${quoteCommandArgument(fix)} --on ${s.on}`,
|
|
3089
|
+
],
|
|
3090
|
+
},
|
|
3091
|
+
);
|
|
3092
|
+
}
|
|
3093
|
+
if (surface || side || density)
|
|
3094
|
+
refuse(
|
|
3095
|
+
E.ERR_THEME_BAD_VALUE,
|
|
3096
|
+
surface
|
|
3097
|
+
? `${s.on}'s theme class is on a transparent wrapper; Core draws ${wrapped.box} inside it, and that box has no class of its own, so ${prop} would paint the wrapper's square corners, not the box. Its colors come from the theme's popover tokens.`
|
|
3098
|
+
: side
|
|
3099
|
+
? `${s.on}'s theme class is on a transparent wrapper; ${wrapped.box} inside it reads one padding for every side, so a side padding would add a strip outside the box. Set padding (every side).`
|
|
3100
|
+
: `${s.on} sets its own padding on ${wrapped.box} for each density, which a theme padding for one density cannot reach. Set padding for every density.`,
|
|
3101
|
+
{
|
|
3102
|
+
run: surface
|
|
3103
|
+
? [
|
|
3104
|
+
`${P} set ${slug} --color-background-popover ${quoteCommandArgument('#ffffff')}`,
|
|
3105
|
+
`${HOW} ${s.on}`,
|
|
3106
|
+
]
|
|
3107
|
+
: [
|
|
3108
|
+
`${P} set ${slug} padding ${quoteCommandArgument(v)} --on ${s.on}`,
|
|
3109
|
+
],
|
|
3110
|
+
},
|
|
3111
|
+
);
|
|
3112
|
+
}
|
|
3113
|
+
// Core writes a container part's padding to variables of its own, where
|
|
3114
|
+
// a keyword that takes its value from elsewhere means no value at all.
|
|
3115
|
+
if (
|
|
3116
|
+
/^padding/.test(prop) &&
|
|
3117
|
+
/^(inherit|revert|revert-layer)$/i.test(v.trim()) &&
|
|
3118
|
+
(ctx.derived?.[/** @type {string} */ (s.on)] ?? []).some(
|
|
3119
|
+
d => d.property === 'padding' && d.expand,
|
|
3120
|
+
)
|
|
3121
|
+
)
|
|
3122
|
+
refuse(
|
|
3123
|
+
E.ERR_THEME_BAD_VALUE,
|
|
3124
|
+
`${s.on} writes ${prop} to variables of its own, where "${v.trim()}" has nothing to take its value from, so ${s.on} would fall back to its default padding. Give a length, or undo the padding to go back to the base theme's.`,
|
|
3125
|
+
{
|
|
3126
|
+
run: [
|
|
3127
|
+
`${P} set ${slug} ${prop} 0 --on ${s.on}`,
|
|
3128
|
+
`${P} undo ${slug} ${prop} --on ${s.on}`,
|
|
3129
|
+
],
|
|
3130
|
+
},
|
|
3131
|
+
);
|
|
2104
3132
|
// Text, headings and links take their color from the color prop.
|
|
2105
3133
|
const textParts = COLOR_PROP_PARTS;
|
|
2106
3134
|
if (
|
|
@@ -2109,16 +3137,22 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
2109
3137
|
) {
|
|
2110
3138
|
if (partsOf(ctx, s).every(t => textParts.includes(t))) {
|
|
2111
3139
|
const named = /^color:([\w-]+)$/.exec(s.when ?? '')?.[1];
|
|
3140
|
+
// The typed value goes into the token only when it is a plain color;
|
|
3141
|
+
// else the nearest color name, else an example.
|
|
3142
|
+
const color =
|
|
3143
|
+
v && isColorValue(v) && isFixedColor(v) && !/\bvar\(/i.test(v)
|
|
3144
|
+
? v
|
|
3145
|
+
: (nearestColorName(v) ?? '#1f2937');
|
|
2112
3146
|
refuse(
|
|
2113
3147
|
E.ERR_THEME_NO_EFFECT,
|
|
2114
3148
|
`${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
3149
|
{
|
|
2116
3150
|
run: [
|
|
2117
|
-
`${P} set ${slug} --color-text-${named ?? 'primary'} ${quoteCommandArgument(
|
|
3151
|
+
`${P} set ${slug} --color-text-${named ?? 'primary'} ${quoteCommandArgument(color)}${s.mode ? ` --mode ${s.mode}` : ''}`,
|
|
2118
3152
|
...(named
|
|
2119
3153
|
? []
|
|
2120
3154
|
: [
|
|
2121
|
-
`${P} set ${slug} --color-text-secondary ${quoteCommandArgument(
|
|
3155
|
+
`${P} set ${slug} --color-text-secondary ${quoteCommandArgument(color)}${s.mode ? ` --mode ${s.mode}` : ''}`,
|
|
2122
3156
|
]),
|
|
2123
3157
|
],
|
|
2124
3158
|
},
|
|
@@ -2131,7 +3165,13 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
2131
3165
|
// With a state, the other mode would take one variant's value for
|
|
2132
3166
|
// every variant, so any part whose variants read their own value needs
|
|
2133
3167
|
// the variant named.
|
|
2134
|
-
|
|
3168
|
+
// Per-variant colors only: a value that is not a color is refused for
|
|
3169
|
+
// --mode below, with the reason that holds.
|
|
3170
|
+
if (
|
|
3171
|
+
s.mode &&
|
|
3172
|
+
!s.when &&
|
|
3173
|
+
(COLOR_PROPS.test(prop) || (prop === 'background' && isColorValue(v)))
|
|
3174
|
+
) {
|
|
2135
3175
|
const g = C.groupOfProp(
|
|
2136
3176
|
prop === 'background' ? 'background-color' : prop,
|
|
2137
3177
|
);
|
|
@@ -2225,6 +3265,27 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
2225
3265
|
},
|
|
2226
3266
|
);
|
|
2227
3267
|
}
|
|
3268
|
+
// A var() inside a color (color-mix(in srgb, var(--x, 12px), red)) shows
|
|
3269
|
+
// its fallback when the variable is unset: that must be a color too,
|
|
3270
|
+
// except in a color's channels (rgb(var(--r, 0) 0 0)).
|
|
3271
|
+
if (COLOR_PROPS.test(prop) || (prop === 'background' && isColorValue(v)))
|
|
3272
|
+
for (const {fallback, within} of innerVarFallbacks(v)) {
|
|
3273
|
+
if (
|
|
3274
|
+
within.some(f =>
|
|
3275
|
+
/^(rgba?|hsla?|hwb|lab|lch|oklab|oklch|color)$/i.test(f),
|
|
3276
|
+
) ||
|
|
3277
|
+
/\bvar\(/i.test(fallback)
|
|
3278
|
+
)
|
|
3279
|
+
continue;
|
|
3280
|
+
if (fallback === '' || !isColorValue(fallback))
|
|
3281
|
+
refuse(
|
|
3282
|
+
E.ERR_THEME_BAD_VALUE,
|
|
3283
|
+
fallback === ''
|
|
3284
|
+
? `${prop} takes a color; the var() in "${v}" has an empty fallback, which leaves it with no color when the variable is unset.`
|
|
3285
|
+
: `${prop} takes a color; "${fallback}", a var() fallback in "${v}", is not one, so the ${prop} is lost when the variable is unset.`,
|
|
3286
|
+
{run: [setLine(slug, prop, exampleOf('color', prop), s)]},
|
|
3287
|
+
);
|
|
3288
|
+
}
|
|
2228
3289
|
// Every scope flag but --mode carries into the runs.
|
|
2229
3290
|
const whenFlag = `${s.when ? ` --when ${s.when}` : ''}${s.state ? ` --state ${s.state}` : ''}${s.only ? ' --only' : ''}`;
|
|
2230
3291
|
if (
|
|
@@ -2232,8 +3293,12 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
2232
3293
|
!COLOR_PROPS.test(prop) &&
|
|
2233
3294
|
!(prop === 'background' && isColorValue(v))
|
|
2234
3295
|
) {
|
|
2235
|
-
|
|
2236
|
-
|
|
3296
|
+
// A color mixed into the value (a border's) can go per mode on its
|
|
3297
|
+
// own; a value with none (a radius) is just set for both modes.
|
|
3298
|
+
const hasColor = /#[0-9a-f]{3,8}\b|rgba?\(|hsla?\(/i.test(v);
|
|
3299
|
+
const alt = !hasColor
|
|
3300
|
+
? null
|
|
3301
|
+
: prop === 'border' || prop.startsWith('border-')
|
|
2237
3302
|
? 'border-color'
|
|
2238
3303
|
: prop === 'background'
|
|
2239
3304
|
? 'background-color'
|
|
@@ -2435,3 +3500,53 @@ const dialWrites = token =>
|
|
|
2435
3500
|
|
|
2436
3501
|
/** The aspects `how` answers at the whole-theme level. */
|
|
2437
3502
|
export const ASPECTS = [...Object.keys(GROUPS), 'colors'];
|
|
3503
|
+
|
|
3504
|
+
/**
|
|
3505
|
+
* A setting's value as set reads it: one line, and tabs as spaces; in a font
|
|
3506
|
+
* value every run of spaces or tabs is one space, so `'Open Sans'` and
|
|
3507
|
+
* `'Open\tSans'` both name Open Sans.
|
|
3508
|
+
* @param {string} thing
|
|
3509
|
+
* @param {string} value
|
|
3510
|
+
*/
|
|
3511
|
+
export function normalValue(thing, value) {
|
|
3512
|
+
const one = value.replace(/\s*[\r\n]+\s*/g, ' ');
|
|
3513
|
+
return (
|
|
3514
|
+
thing === 'font' ? one.replace(/[ \t]+/g, ' ') : one.replace(/\t+/g, ' ')
|
|
3515
|
+
).trim();
|
|
3516
|
+
}
|
|
3517
|
+
|
|
3518
|
+
/**
|
|
3519
|
+
* The first var() in a value that names no design token and would read
|
|
3520
|
+
* nothing (no fallback), or one a letter or two off a token, else null.
|
|
3521
|
+
* Dials take their own words, so a dial's var() with no near token passes.
|
|
3522
|
+
* @param {string} v
|
|
3523
|
+
* @param {Record<string, unknown>} TOKENS
|
|
3524
|
+
* @param {string} thing
|
|
3525
|
+
* @returns {{message: string, near: string[], close: boolean} | null}
|
|
3526
|
+
*/
|
|
3527
|
+
export function unknownVarRef(v, TOKENS, thing) {
|
|
3528
|
+
for (const [, name, comma] of v.matchAll(/var\(\s*(--[a-z0-9-]+)\s*(,)?/gi)) {
|
|
3529
|
+
if (name in TOKENS || name.startsWith('--_')) continue;
|
|
3530
|
+
// A fallback always gives a value: never "reads nothing" (a likely
|
|
3531
|
+
// typo is noted when the setting is made).
|
|
3532
|
+
if (comma) continue;
|
|
3533
|
+
const near = nearest(name, Object.keys(TOKENS)).filter(
|
|
3534
|
+
n => levenshteinDistance(n, name) <= 2,
|
|
3535
|
+
);
|
|
3536
|
+
if (near.length)
|
|
3537
|
+
return {
|
|
3538
|
+
message: `${name} is not a design token, so var(${name}) would read nothing.`,
|
|
3539
|
+
near,
|
|
3540
|
+
close: true,
|
|
3541
|
+
};
|
|
3542
|
+
// Without a fallback, a variable no design token names reads nothing;
|
|
3543
|
+
// var(--x, <value>) falls back to the value.
|
|
3544
|
+
if (!comma && !DIALS[thing])
|
|
3545
|
+
return {
|
|
3546
|
+
message: `${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.`,
|
|
3547
|
+
near: nearest(name, Object.keys(TOKENS)).slice(0, 3),
|
|
3548
|
+
close: false,
|
|
3549
|
+
};
|
|
3550
|
+
}
|
|
3551
|
+
return null;
|
|
3552
|
+
}
|