@astryxdesign/cli 0.7.15 → 0.7.16-canary.g07c77c0
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/build/_adapter.d.mts +1 -0
- package/api/build/blocks/blocks.d.mts +1 -0
- package/api/build/blocks/blocks.mjs +18 -1
- 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 +43 -0
- package/api/doctor/built-checks.mjs +1 -1
- package/api/doctor/doctor.mjs +18 -4
- package/api/doctor/theme-checks.mjs +1 -1
- package/api/integration/add-contribution.mjs +3 -3
- package/api/integration/pack-check.mjs +14 -8
- package/api/integration/validate-integration.mjs +1 -1
- package/api/search/_adapter.mjs +15 -16
- package/api/search/_entries.d.mts +2 -1
- package/api/search/_entries.mjs +28 -1
- package/api/swizzle/_moduleGraph.mjs +1 -1
- package/api/theme/_adapter.d.mts +5 -2
- package/api/theme/_adapter.mjs +43 -12
- package/api/theme/_fork.mjs +1 -1
- package/api/theme/build/build.d.mts +116 -32
- package/api/theme/build/build.mjs +449 -102
- 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 +32 -2
- package/api/theme-edit/_adapter.mjs +213 -36
- package/api/theme-edit/_check.d.mts +69 -3
- package/api/theme-edit/_check.mjs +1517 -218
- 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 +426 -40
- 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 +1300 -135
- 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 +33 -0
- package/api/theme-edit/_parts.mjs +138 -9
- package/api/theme-edit/_png.d.mts +18 -0
- package/api/theme-edit/_png.mjs +95 -14
- package/api/theme-edit/_preview-app.d.mts +9 -0
- package/api/theme-edit/_preview-app.mjs +1191 -71
- package/api/theme-edit/_preview.d.mts +16 -3
- package/api/theme-edit/_preview.mjs +335 -30
- package/api/theme-edit/_project.d.mts +11 -0
- package/api/theme-edit/_project.mjs +46 -12
- package/api/theme-edit/_settings.d.mts +240 -5
- package/api/theme-edit/_settings.mjs +2561 -115
- 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/codemods/parse.mjs +2 -2
- 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/authoring/shadcn/source-variants.d.mts +1 -1
- package/authoring/shadcn/source-variants.mjs +32 -10
- 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 +237 -45
- package/clients/cli/commands/experimental-theme-compile.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +3 -3
- package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-eject.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-preview-add.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 +190 -46
- 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 +72 -2
- package/clients/cli/manifest.generated.json +1 -1
- package/clients/cli/run.mjs +49 -0
- package/foundation/agent-docs/agent-docs-target.d.mts +2 -6
- package/foundation/agent-docs/agent-docs-target.mjs +9 -17
- package/foundation/agent-docs/agent-docs.mjs +3 -2
- package/foundation/config/config-writer.mjs +2 -2
- package/foundation/config/project.mjs +60 -14
- package/foundation/discovery/component-discovery.mjs +5 -17
- package/foundation/discovery/icon-set-writer.mjs +1 -1
- package/foundation/discovery/module-exports.mjs +1 -15
- package/foundation/discovery/template-adapter.mjs +44 -19
- package/foundation/discovery/template-source-tree.mjs +3 -16
- package/foundation/discovery/theme-discovery.d.mts +5 -1
- package/foundation/discovery/theme-discovery.mjs +30 -35
- package/foundation/fs/exact-codec.d.mts +35 -0
- package/foundation/fs/exact-codec.mjs +148 -0
- package/foundation/fs/gather-cache.d.mts +15 -5
- package/foundation/fs/gather-cache.mjs +123 -30
- package/foundation/fs/paths.d.mts +39 -0
- package/foundation/fs/paths.mjs +44 -11
- package/foundation/fs/read-record.mjs +11 -1
- package/foundation/integrations/contribution-fixes.mjs +1 -16
- package/foundation/integrations/may-have-integrations.mjs +3 -2
- package/foundation/integrations/public-imports.mjs +1 -1
- package/foundation/render/embedded-imports.mjs +1 -1
- 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/foundation/runtime/lazy-dependencies.d.mts +14 -0
- package/foundation/runtime/lazy-dependencies.mjs +82 -0
- package/foundation/xle/browser.d.mts +2 -2
- 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 {calcVars, coreFallback, multipliedTokens} from './_parts.mjs';
|
|
31
37
|
import {
|
|
32
38
|
AUTO_SPREAD,
|
|
33
39
|
COLOR_PROP_PARTS,
|
|
@@ -50,7 +56,11 @@ import {
|
|
|
50
56
|
SPACING,
|
|
51
57
|
TEXT_SIZE,
|
|
52
58
|
THING_HINTS,
|
|
59
|
+
TYPE_STYLES,
|
|
53
60
|
familyOf,
|
|
61
|
+
wordTable,
|
|
62
|
+
WRAPPED_PARTS,
|
|
63
|
+
CARD_LIKE,
|
|
54
64
|
} from './_tables.mjs';
|
|
55
65
|
import {
|
|
56
66
|
COLOR_NAMES,
|
|
@@ -83,6 +93,14 @@ import {
|
|
|
83
93
|
radiusTokenOf,
|
|
84
94
|
focusStateOf,
|
|
85
95
|
valueProblem,
|
|
96
|
+
partComponentDocs,
|
|
97
|
+
themeFiles,
|
|
98
|
+
ownSourceTokenValues,
|
|
99
|
+
baseTopTokens,
|
|
100
|
+
baseComponentReads,
|
|
101
|
+
partRuleTokens,
|
|
102
|
+
cssFamily,
|
|
103
|
+
familySpaces,
|
|
86
104
|
} from './_settings.mjs';
|
|
87
105
|
import {quoteCommandArgument} from '../../foundation/env/package-manager.mjs';
|
|
88
106
|
|
|
@@ -104,6 +122,21 @@ function tokenPx(base, token) {
|
|
|
104
122
|
return lengthPx(v);
|
|
105
123
|
}
|
|
106
124
|
|
|
125
|
+
/**
|
|
126
|
+
* The `type` preset nearest a scale ratio typed as a number (1.3 is
|
|
127
|
+
* editorial), or null for a number that is no ratio (16).
|
|
128
|
+
* @param {string} v
|
|
129
|
+
* @returns {string | null}
|
|
130
|
+
*/
|
|
131
|
+
function ratioPreset(v) {
|
|
132
|
+
if (!/^\d+(\.\d+)?$/.test(v)) return null;
|
|
133
|
+
const r = Number(v);
|
|
134
|
+
if (!(r > 1 && r <= 2)) return null;
|
|
135
|
+
return Object.entries(TYPE_STYLES).reduce((a, b) =>
|
|
136
|
+
Math.abs(b[1].ratio - r) < Math.abs(a[1].ratio - r) ? b : a,
|
|
137
|
+
)[0];
|
|
138
|
+
}
|
|
139
|
+
|
|
107
140
|
/**
|
|
108
141
|
* A `set` (or `undo`) command for a setting, with its scope, to suggest.
|
|
109
142
|
* @param {string} slug
|
|
@@ -112,7 +145,7 @@ function tokenPx(base, token) {
|
|
|
112
145
|
* @param {{on?: string, when?: string, state?: string, mode?: string, only?: boolean}} s
|
|
113
146
|
* @param {boolean} [unset]
|
|
114
147
|
*/
|
|
115
|
-
const setLine = (slug, thing, value, s, unset = false) =>
|
|
148
|
+
export const setLine = (slug, thing, value, s, unset = false) =>
|
|
116
149
|
`${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
150
|
|
|
118
151
|
/** @param {string} v */
|
|
@@ -121,6 +154,291 @@ const cornerPxOf = v =>
|
|
|
121
154
|
|
|
122
155
|
const E = ERROR_CODES;
|
|
123
156
|
|
|
157
|
+
/**
|
|
158
|
+
* The fallbacks of the var() calls inside a value that is not one var()
|
|
159
|
+
* alone (`calc(var(--x, 4px) * 2)`), in order. A var() with an empty
|
|
160
|
+
* fallback (`var(--x,)`) gives ''.
|
|
161
|
+
* @param {string} value
|
|
162
|
+
* @returns {Array<{fallback: string, within: string[]}>} each fallback, with
|
|
163
|
+
* the names of the functions around its var(), innermost first
|
|
164
|
+
*/
|
|
165
|
+
function innerVarFallbacks(value) {
|
|
166
|
+
const text = value.trim();
|
|
167
|
+
if (/^var\(/i.test(text) && matchingParen(text, 3) === text.length - 1)
|
|
168
|
+
return [];
|
|
169
|
+
/** @type {Array<{fallback: string, within: string[]}>} */
|
|
170
|
+
const out = [];
|
|
171
|
+
const re = /\bvar\(/gi;
|
|
172
|
+
let m;
|
|
173
|
+
while ((m = re.exec(text))) {
|
|
174
|
+
const open = m.index + m[0].length - 1;
|
|
175
|
+
const close = matchingParen(text, open);
|
|
176
|
+
if (close < 0) break;
|
|
177
|
+
const inner = text.slice(open + 1, close);
|
|
178
|
+
let depth = 0;
|
|
179
|
+
for (let i = 0; i < inner.length; i += 1) {
|
|
180
|
+
const c = inner[i];
|
|
181
|
+
if (c === '(') depth += 1;
|
|
182
|
+
else if (c === ')') depth -= 1;
|
|
183
|
+
else if (c === ',' && depth === 0) {
|
|
184
|
+
out.push({
|
|
185
|
+
fallback: inner.slice(i + 1).trim(),
|
|
186
|
+
within: enclosingFunctions(text, m.index),
|
|
187
|
+
});
|
|
188
|
+
break;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return out;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* The names of the functions whose parentheses are open at `at`, innermost
|
|
197
|
+
* first.
|
|
198
|
+
* @param {string} text
|
|
199
|
+
* @param {number} at
|
|
200
|
+
* @returns {string[]}
|
|
201
|
+
*/
|
|
202
|
+
function enclosingFunctions(text, at) {
|
|
203
|
+
/** @type {string[]} */
|
|
204
|
+
const open = [];
|
|
205
|
+
for (let i = 0; i < at; i += 1) {
|
|
206
|
+
if (text[i] === '(')
|
|
207
|
+
open.push(/([a-z-]*)$/i.exec(text.slice(0, i))?.[1] ?? '');
|
|
208
|
+
else if (text[i] === ')') open.pop();
|
|
209
|
+
}
|
|
210
|
+
return open.reverse();
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* The index of the parenthesis that closes the one at `open`, or -1.
|
|
215
|
+
* @param {string} text
|
|
216
|
+
* @param {number} open
|
|
217
|
+
*/
|
|
218
|
+
function matchingParen(text, open) {
|
|
219
|
+
let depth = 0;
|
|
220
|
+
for (let i = open; i < text.length; i += 1) {
|
|
221
|
+
if (text[i] === '(') depth += 1;
|
|
222
|
+
else if (text[i] === ')') {
|
|
223
|
+
depth -= 1;
|
|
224
|
+
if (depth === 0) return i;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return -1;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* A text size written another way (20px, 2e1, +20, 1.25rem, 125%, `20 px`,
|
|
232
|
+
* `1,25rem`) as the body size in pixels text-size takes, kept to its 10 to
|
|
233
|
+
* 32 (a size past an end is that end); null when it reads as no size.
|
|
234
|
+
* @param {string} v
|
|
235
|
+
* @returns {number | null}
|
|
236
|
+
*/
|
|
237
|
+
function textSizePx(v) {
|
|
238
|
+
const m = /^\+?(\d*\.?\d+(?:e[+-]?\d+)?)(px|rem|em|%)?$/i.exec(
|
|
239
|
+
typedPlain(v)
|
|
240
|
+
.replace(/(\d)\.(?=[a-z%]*$)/i, '$1')
|
|
241
|
+
.replace(/\s+/g, '')
|
|
242
|
+
.replace(/^(\d+),(\d+)/, '$1.$2'),
|
|
243
|
+
);
|
|
244
|
+
if (!m) return null;
|
|
245
|
+
const unit = (m[2] ?? '').toLowerCase();
|
|
246
|
+
const n =
|
|
247
|
+
Number(m[1]) * (/r?em/.test(unit) ? 16 : unit === '%' ? 16 / 100 : 1);
|
|
248
|
+
const px = Math.round(n * 100) / 100;
|
|
249
|
+
return Math.max(10, Math.min(32, px));
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* A value as it reads once what an input method or a stylesheet adds is
|
|
254
|
+
* taken off: full-width digits, letters and signs (`18`, `#`) as their
|
|
255
|
+
* plain forms, and CSS comments.
|
|
256
|
+
* @param {string} v
|
|
257
|
+
*/
|
|
258
|
+
function typedPlain(v) {
|
|
259
|
+
return v
|
|
260
|
+
.normalize('NFKC')
|
|
261
|
+
.replace(/\/\*[\s\S]*?\*\//g, ' ')
|
|
262
|
+
.replace(/\s+/g, ' ')
|
|
263
|
+
.trim();
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* A value pasted as a CSS declaration (`color: #e11d48;`, `font-weight: 700
|
|
268
|
+
* !important`), from devtools or a stylesheet: its property and value, with
|
|
269
|
+
* the `;` and `!important` gone. Null when the value is not a declaration (a
|
|
270
|
+
* URL's `https:` is not a property).
|
|
271
|
+
* @param {string} v
|
|
272
|
+
* @returns {{property: string, value: string} | null}
|
|
273
|
+
*/
|
|
274
|
+
export function pastedDeclaration(v) {
|
|
275
|
+
const plain = typedPlain(v);
|
|
276
|
+
const m = /^(--[a-z0-9-]+|[a-z][a-z-]*)\s*:\s*(?!\/\/)(.*)$/i.exec(plain);
|
|
277
|
+
if (!m || /^(https?|data|file|blob)$/i.test(m[1])) return null;
|
|
278
|
+
const value = m[2]
|
|
279
|
+
.replace(/;+\s*$/, '')
|
|
280
|
+
.replace(/\s*!\s*important\s*$/i, '')
|
|
281
|
+
.replace(/;+\s*$/, '')
|
|
282
|
+
.trim();
|
|
283
|
+
// `font-family: ;` names a property and no value: value is ''.
|
|
284
|
+
return {property: m[1].toLowerCase(), value};
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* A font pasted as a declaration (`font-family: Georgia, serif;`, from
|
|
289
|
+
* devtools or a stylesheet), as the family list it names; a `font:`
|
|
290
|
+
* shorthand gives its family; '' when it names the property and no value.
|
|
291
|
+
* Null when the value is not a pasted declaration.
|
|
292
|
+
* @param {string} v
|
|
293
|
+
* @returns {string | null}
|
|
294
|
+
*/
|
|
295
|
+
export function pastedFont(v) {
|
|
296
|
+
const d = pastedDeclaration(v);
|
|
297
|
+
if (!d || !/^font(-family)?$/.test(d.property)) return null;
|
|
298
|
+
const rest = d.value;
|
|
299
|
+
// `font-family: ;` gives no font: '' (the caller refuses it).
|
|
300
|
+
if (!rest) return '';
|
|
301
|
+
if (d.property === 'font-family') return rest;
|
|
302
|
+
const parts = fontShorthandParts(rest);
|
|
303
|
+
return parts && typeof parts['font-family'] === 'string'
|
|
304
|
+
? parts['font-family']
|
|
305
|
+
: null;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* The values a value may have meant, when what is wrong is how it was
|
|
310
|
+
* typed: plain (full-width characters, comments and a trailing `;` gone,
|
|
311
|
+
* quotes around a whole non-font value dropped), and for a font list each
|
|
312
|
+
* family quoted as CSS needs it (`Font Awesome 6 Free`). Only values that
|
|
313
|
+
* differ from the one typed.
|
|
314
|
+
* @param {string} type
|
|
315
|
+
* @param {string} value
|
|
316
|
+
*/
|
|
317
|
+
function valueMeant(type, value) {
|
|
318
|
+
// `!important` is not part of a token's value (the theme places its
|
|
319
|
+
// rules itself): the value without it.
|
|
320
|
+
/** @type {string} */
|
|
321
|
+
let p = (
|
|
322
|
+
type === 'font' || type === 'font-family'
|
|
323
|
+
? pastedFont(value) || value
|
|
324
|
+
: pastedDeclaration(value)?.value || typedPlain(value)
|
|
325
|
+
)
|
|
326
|
+
.replace(/;+\s*$/, '')
|
|
327
|
+
.replace(/\s*!\s*important\s*$/i, '')
|
|
328
|
+
.replace(/;+\s*$/, '')
|
|
329
|
+
.trim();
|
|
330
|
+
const q = /^(["'])(.*)\1$/.exec(p);
|
|
331
|
+
if (q && type !== 'font') p = q[2].trim();
|
|
332
|
+
const out = [p];
|
|
333
|
+
// A var() of the app's own variable with a fallback: the fallback is the
|
|
334
|
+
// value meant (`var(--brand, #e11d48)` → #e11d48).
|
|
335
|
+
const fb = /^var\(\s*--[a-z0-9-]+\s*,\s*(.+)\)$/i.exec(p);
|
|
336
|
+
if (fb) out.push(fb[1].trim());
|
|
337
|
+
if (type === 'font' || type === 'font-family') {
|
|
338
|
+
// A comma left out between families (`"Open Sans" serif`), read with
|
|
339
|
+
// css-tree.
|
|
340
|
+
const listed = familyListMeant(p);
|
|
341
|
+
if (listed) out.push(listed);
|
|
342
|
+
// Each family quoted as CSS needs it, only when no family holds a
|
|
343
|
+
// quote inside (the pieces are whole names).
|
|
344
|
+
const pieces = p.split(',').map(f => f.trim().replace(/^["']|["']$/g, ''));
|
|
345
|
+
if (!listed && pieces.every(f => !/["'\\]/.test(f)))
|
|
346
|
+
out.push(pieces.map(f => cssFamily(f, true)).join(', '));
|
|
347
|
+
}
|
|
348
|
+
return [...new Set(out)].filter(x => x && x !== value.trim());
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* Whether a value is one length that works inside calc(): a length with a
|
|
353
|
+
* unit, a variable (with a fallback that is one too), or calc(), min(),
|
|
354
|
+
* max() or clamp() giving a length; never several values, a bare number
|
|
355
|
+
* (calc() cannot add one to a length, 0 included), a percentage or a
|
|
356
|
+
* keyword.
|
|
357
|
+
* @param {string} v
|
|
358
|
+
* @returns {boolean}
|
|
359
|
+
*/
|
|
360
|
+
function oneLength(v) {
|
|
361
|
+
const t = v.trim();
|
|
362
|
+
if (splitTop(t, ' ').length !== 1) return false;
|
|
363
|
+
const ref = /^var\(\s*--[a-z0-9-]+\s*(?:,(.*))?\)$/i.exec(t);
|
|
364
|
+
if (ref) return ref[1] == null || oneLength(ref[1]);
|
|
365
|
+
if (MATH_FUNCTION.test(t)) return matchType('length', t) != null;
|
|
366
|
+
const n = cssNumber(t);
|
|
367
|
+
return !!n && !!n.unit && n.unit !== '%';
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/** The size units a typo is read against. */
|
|
371
|
+
const SIZE_UNITS = ['px', 'rem', 'em', '%', 'vh', 'vw', 'ch'];
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* The size meant by a value one slip away from one: a space inside
|
|
375
|
+
* (`16 px`), a decimal comma (`1,5rem`), a doubled or mistyped unit
|
|
376
|
+
* (`16pxx`), a dot with no digit after it (`1.px`); null when none reads.
|
|
377
|
+
* @param {string} v
|
|
378
|
+
* @param {(x: string) => boolean} ok
|
|
379
|
+
*/
|
|
380
|
+
function sizeMeant(v, ok) {
|
|
381
|
+
const t = v.trim();
|
|
382
|
+
const n = typedPlain(t);
|
|
383
|
+
const tries = [
|
|
384
|
+
n,
|
|
385
|
+
n.replace(/(\d)\.(?=[a-z%]|$)/gi, '$1'),
|
|
386
|
+
t.replace(/(\d)\.(?=[a-z%]|$)/gi, '$1'),
|
|
387
|
+
t.replace(/\s+/g, ''),
|
|
388
|
+
t.replace(/^([+-]?\d+),(\d+)/, '$1.$2').replace(/\s+/g, ''),
|
|
389
|
+
mathSpaced(t),
|
|
390
|
+
];
|
|
391
|
+
const m = /^([+-]?\d*\.?\d+)\s*([a-z%]+)$/i.exec(
|
|
392
|
+
t.replace(/^([+-]?\d+),(\d+)/, '$1.$2'),
|
|
393
|
+
);
|
|
394
|
+
if (m) {
|
|
395
|
+
// A unit typed with a letter too many (pxx, remm, pxs).
|
|
396
|
+
const unit = [...SIZE_UNITS]
|
|
397
|
+
.sort((a, b) => b.length - a.length)
|
|
398
|
+
.find(u => m[2].toLowerCase().startsWith(u));
|
|
399
|
+
if (unit) tries.push(`${m[1]}${unit}`);
|
|
400
|
+
}
|
|
401
|
+
return tries.find(x => x !== t && ok(x)) ?? null;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* A math function with the spaces CSS needs around `+` and `-` put back
|
|
406
|
+
* (`calc(1rem+2px)` is `calc(1rem + 2px)`); the value as it is otherwise.
|
|
407
|
+
* @param {string} v
|
|
408
|
+
*/
|
|
409
|
+
function mathSpaced(v) {
|
|
410
|
+
if (!/^(calc|min|max|clamp)\(/i.test(v) || /\bvar\(/i.test(v)) return v;
|
|
411
|
+
return v.replace(/(\d(?<![\d.]e)|[%a-z)])([+-])(?=[\d.(])/gi, '$1 $2 ');
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
/**
|
|
415
|
+
* The number meant by a value one slip away from one: a unit on a number
|
|
416
|
+
* (`700px`), a decimal comma (`1,5`), letter O for zero (`7OO`), a weight
|
|
417
|
+
* past the range (`1001` is 1000), a math function with no spaces around
|
|
418
|
+
* `+` or `-`; null when none reads.
|
|
419
|
+
* @param {string} v
|
|
420
|
+
* @param {string} name the token
|
|
421
|
+
* @param {(x: string) => boolean} ok
|
|
422
|
+
*/
|
|
423
|
+
function numberMeant(v, name, ok) {
|
|
424
|
+
const t = v.trim();
|
|
425
|
+
const plain = typedPlain(t).replace(/(\d)\.$/, '$1');
|
|
426
|
+
const comma = plain.replace(/^([+-]?\d+),(\d+)/, '$1.$2');
|
|
427
|
+
const tries = [
|
|
428
|
+
/^[\doO.]+$/.test(plain) && /\d/.test(plain)
|
|
429
|
+
? plain.replace(/[oO]/g, '0')
|
|
430
|
+
: plain,
|
|
431
|
+
comma.replace(/^([+-]?\d*\.?\d+)\s*[a-z]+$/i, '$1'),
|
|
432
|
+
comma,
|
|
433
|
+
mathSpaced(t),
|
|
434
|
+
];
|
|
435
|
+
if (/weight/.test(name)) {
|
|
436
|
+
const n = Number(tries[1]);
|
|
437
|
+
if (Number.isFinite(n)) tries.push(String(Math.min(1000, Math.max(1, n))));
|
|
438
|
+
}
|
|
439
|
+
return tries.find(x => x !== t && ok(x)) ?? null;
|
|
440
|
+
}
|
|
441
|
+
|
|
124
442
|
/**
|
|
125
443
|
* The value to carry into a suggestion for another dial: the one given when
|
|
126
444
|
* that dial takes it, else the dial's example.
|
|
@@ -190,10 +508,22 @@ const COLOR_DIAL_WORDS = (() => {
|
|
|
190
508
|
* @param {import('./_settings.mjs').Ctx} ctx
|
|
191
509
|
* @param {string} slug
|
|
192
510
|
* @param {import('./_settings.mjs').ThemeData} data
|
|
193
|
-
* @param {string} [skip]
|
|
511
|
+
* @param {string | {thing: string, on?: string, when?: string, state?: string, mode?: string}} [skip]
|
|
194
512
|
* @returns {Array<{setting: import('./_settings.mjs').Setting, why: string, scope?: boolean}>} every saved setting the editor no longer accepts
|
|
195
513
|
*/
|
|
196
514
|
export function storedProblems(ctx, slug, data, skip = '') {
|
|
515
|
+
// The setting the command replaces (its thing in the same scope); a
|
|
516
|
+
// setting of the same thing elsewhere is still checked.
|
|
517
|
+
const skipThing = typeof skip === 'string' ? skip : skip.thing;
|
|
518
|
+
/** @param {import('./_settings.mjs').Setting} s */
|
|
519
|
+
const replaced = s =>
|
|
520
|
+
typeof skip === 'string'
|
|
521
|
+
? s.thing === skip
|
|
522
|
+
: s.thing === skip.thing &&
|
|
523
|
+
(s.on ?? '') === (skip.on ?? '') &&
|
|
524
|
+
(s.when ?? '') === (skip.when ?? '') &&
|
|
525
|
+
(s.state ?? '') === (skip.state ?? '') &&
|
|
526
|
+
(s.mode ?? '') === (skip.mode ?? '');
|
|
197
527
|
/** @type {Array<{setting: import('./_settings.mjs').Setting, why: string, scope?: boolean}>} */
|
|
198
528
|
const found = [];
|
|
199
529
|
const TOKENS = ctx.project.core.tokenDefaults;
|
|
@@ -211,7 +541,7 @@ export function storedProblems(ctx, slug, data, skip = '') {
|
|
|
211
541
|
...PALETTE_DIALS,
|
|
212
542
|
];
|
|
213
543
|
for (const s of data.settings) {
|
|
214
|
-
if (s.thing ===
|
|
544
|
+
if (s.thing === skipThing) continue;
|
|
215
545
|
/** @param {string} why */
|
|
216
546
|
const scope = why => ({setting: s, why, scope: true});
|
|
217
547
|
const problem = (() => {
|
|
@@ -223,6 +553,32 @@ export function storedProblems(ctx, slug, data, skip = '') {
|
|
|
223
553
|
!(s.thing === 'font' && FONT_ROLES.includes(s.on))
|
|
224
554
|
)
|
|
225
555
|
return scope(`there is no part or group "${s.on}"`);
|
|
556
|
+
// A token that is no design token, or a part property that is no
|
|
557
|
+
// CSS property or names no part, styles nothing: reported, never
|
|
558
|
+
// built.
|
|
559
|
+
if (s.source === 'token' && !(s.thing in TOKENS))
|
|
560
|
+
return {setting: s, why: `${s.thing} is not a design token`};
|
|
561
|
+
if (s.source === 'property' && !s.on)
|
|
562
|
+
return {
|
|
563
|
+
setting: s,
|
|
564
|
+
why: `${s.thing} is a CSS property, so it needs a part (--on)`,
|
|
565
|
+
};
|
|
566
|
+
if (
|
|
567
|
+
s.source === 'property' &&
|
|
568
|
+
!s.thing.startsWith('--') &&
|
|
569
|
+
!cssProperties().has(s.thing)
|
|
570
|
+
)
|
|
571
|
+
return {setting: s, why: `${s.thing} is not a CSS property`};
|
|
572
|
+
// A value its CSS grammar does not take (a hand edit: padding
|
|
573
|
+
// banana) is dropped by the browser: reported by name, never built.
|
|
574
|
+
if (s.source === 'property' && !s.thing.startsWith('--')) {
|
|
575
|
+
const bad = propertyProblem(s.thing, String(s.value ?? ''));
|
|
576
|
+
if (bad)
|
|
577
|
+
return {
|
|
578
|
+
setting: s,
|
|
579
|
+
why: `${s.thing} takes ${bad.takes}, not "${String(s.value ?? '').slice(0, 60)}"`,
|
|
580
|
+
};
|
|
581
|
+
}
|
|
226
582
|
if (s.source === 'dial' && s.on && WHOLE_ONLY.includes(s.thing))
|
|
227
583
|
return scope(`${s.thing} applies to the whole theme, not to ${s.on}`);
|
|
228
584
|
if (s.mode && s.source === 'dial' && !PALETTE_DIALS.includes(s.thing))
|
|
@@ -240,9 +596,48 @@ export function storedProblems(ctx, slug, data, skip = '') {
|
|
|
240
596
|
})();
|
|
241
597
|
if (problem) found.push(problem);
|
|
242
598
|
}
|
|
599
|
+
// Every part setting and the font dial are checked as set checks a value
|
|
600
|
+
// typed in (a CSS keyword where no family is, one length where Core reads
|
|
601
|
+
// a padding inside calc(), a value the property's grammar refuses …), so
|
|
602
|
+
// a hand edit set would refuse is reported, never built, as compile does.
|
|
603
|
+
const scoped = new Set(found.map(f => f.setting));
|
|
243
604
|
for (const s of data.settings) {
|
|
244
|
-
if (s
|
|
605
|
+
if (replaced(s) || scoped.has(s)) continue;
|
|
606
|
+
if (!(
|
|
607
|
+
s.source === 'property' ||
|
|
608
|
+
(s.source === 'dial' && s.thing === 'font')
|
|
609
|
+
))
|
|
245
610
|
continue;
|
|
611
|
+
try {
|
|
612
|
+
checkSetting(
|
|
613
|
+
ctx,
|
|
614
|
+
slug,
|
|
615
|
+
{...data, settings: data.settings.filter(x => x !== s)},
|
|
616
|
+
s.thing,
|
|
617
|
+
s.value,
|
|
618
|
+
{on: s.on, when: s.when, state: s.state, mode: s.mode, only: s.only},
|
|
619
|
+
);
|
|
620
|
+
} catch (e) {
|
|
621
|
+
if (!(e instanceof AstryxError)) throw e;
|
|
622
|
+
found.push({
|
|
623
|
+
setting: s,
|
|
624
|
+
why:
|
|
625
|
+
e instanceof Error
|
|
626
|
+
? e.message.replace(/ Nothing was changed\.$/, '')
|
|
627
|
+
: String(e),
|
|
628
|
+
});
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
for (const s of data.settings) {
|
|
632
|
+
if (s.source !== 'token' || s.thing === skipThing || !(s.thing in TOKENS))
|
|
633
|
+
continue;
|
|
634
|
+
// A var() a hand edit put in that names no design token reads nothing,
|
|
635
|
+
// as set refuses it.
|
|
636
|
+
const bad = unknownVarRef(String(s.value ?? ''), TOKENS, s.thing);
|
|
637
|
+
if (bad) {
|
|
638
|
+
found.push({setting: s, why: bad.message});
|
|
639
|
+
continue;
|
|
640
|
+
}
|
|
246
641
|
try {
|
|
247
642
|
checkTypedValue(
|
|
248
643
|
ctx.C.typeOf(s.thing),
|
|
@@ -252,8 +647,9 @@ export function storedProblems(ctx, slug, data, skip = '') {
|
|
|
252
647
|
ctx.C.typeOf,
|
|
253
648
|
slug,
|
|
254
649
|
ctx.C.propsReading(s.thing),
|
|
650
|
+
multipliedTokens(ctx.project).has(s.thing),
|
|
255
651
|
);
|
|
256
|
-
checkCycle(s.thing, s.value, TOKENS, data);
|
|
652
|
+
checkCycle(s.thing, s.value, TOKENS, data, ctx.project.cwd, s);
|
|
257
653
|
} catch (e) {
|
|
258
654
|
found.push({
|
|
259
655
|
setting: s,
|
|
@@ -305,6 +701,7 @@ function groupOfPropType(prop) {
|
|
|
305
701
|
* @param {(token: string) => string} typeOf
|
|
306
702
|
* @param {string} slug
|
|
307
703
|
* @param {string[]} [readers] the CSS properties that read the token
|
|
704
|
+
* @param {boolean} [multiplied] whether Core multiplies the token by a size
|
|
308
705
|
*/
|
|
309
706
|
function checkTypedValue(
|
|
310
707
|
type,
|
|
@@ -314,21 +711,58 @@ function checkTypedValue(
|
|
|
314
711
|
typeOf,
|
|
315
712
|
slug,
|
|
316
713
|
readers = [],
|
|
714
|
+
multiplied = false,
|
|
317
715
|
) {
|
|
716
|
+
// The value meant, when what is wrong is how it was typed (a trailing
|
|
717
|
+
// `;`, a comment, quotes around it, full-width characters, a font name
|
|
718
|
+
// that needs quotes): the same value, if the token takes it.
|
|
719
|
+
const meant = () => {
|
|
720
|
+
for (const c of valueMeant(type, value))
|
|
721
|
+
try {
|
|
722
|
+
checkTypedValue(
|
|
723
|
+
type,
|
|
724
|
+
c,
|
|
725
|
+
name,
|
|
726
|
+
TOKENS,
|
|
727
|
+
typeOf,
|
|
728
|
+
slug,
|
|
729
|
+
readers,
|
|
730
|
+
multiplied,
|
|
731
|
+
);
|
|
732
|
+
return c;
|
|
733
|
+
} catch {
|
|
734
|
+
// Not this one.
|
|
735
|
+
}
|
|
736
|
+
return null;
|
|
737
|
+
};
|
|
318
738
|
/** @param {string} what @param {string} example */
|
|
319
739
|
const bad = (what, example) =>
|
|
320
740
|
refuse(
|
|
321
741
|
E.ERR_THEME_BAD_VALUE,
|
|
322
742
|
`${name} is ${what}; "${value}" is not one.`,
|
|
323
|
-
{
|
|
743
|
+
{
|
|
744
|
+
run: [
|
|
745
|
+
`${P} set ${slug} ${name} ${quoteCommandArgument(meant() ?? example)}`,
|
|
746
|
+
],
|
|
747
|
+
},
|
|
324
748
|
);
|
|
749
|
+
// A font file or a link is no family name: never quoted into one.
|
|
750
|
+
if (type === 'font') {
|
|
751
|
+
const file = fontFileReason(pastedFont(value) || value);
|
|
752
|
+
if (file)
|
|
753
|
+
refuse(E.ERR_THEME_BAD_VALUE, file, {
|
|
754
|
+
run: [
|
|
755
|
+
`${P} set ${slug} ${name} ${quoteCommandArgument(exampleOf(type, name))}`,
|
|
756
|
+
],
|
|
757
|
+
});
|
|
758
|
+
}
|
|
325
759
|
if (!isSafeValue(value))
|
|
326
760
|
refuse(
|
|
327
761
|
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
|
|
762
|
+
`"${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
763
|
{
|
|
330
764
|
run: [
|
|
331
|
-
`${P} set ${slug} ${name} ${quoteCommandArgument(exampleOf(type, name))}`,
|
|
765
|
+
`${P} set ${slug} ${name} ${quoteCommandArgument(meant() ?? exampleOf(type, name))}`,
|
|
332
766
|
],
|
|
333
767
|
},
|
|
334
768
|
);
|
|
@@ -350,6 +784,41 @@ function checkTypedValue(
|
|
|
350
784
|
],
|
|
351
785
|
},
|
|
352
786
|
);
|
|
787
|
+
// A var() inside a larger value (calc, max, color-mix) has a fallback of
|
|
788
|
+
// the token's kind too, checked like a whole-value var().
|
|
789
|
+
if (type !== 'other')
|
|
790
|
+
for (const {fallback, within} of innerVarFallbacks(value)) {
|
|
791
|
+
// Inside a color's channels (rgb(var(--r, 0) 0 0)) a fallback is a
|
|
792
|
+
// channel, not a color.
|
|
793
|
+
if (
|
|
794
|
+
type === 'color' &&
|
|
795
|
+
within.some(f =>
|
|
796
|
+
/^(rgba?|hsla?|hwb|lab|lch|oklab|oklch|color)$/i.test(f),
|
|
797
|
+
)
|
|
798
|
+
)
|
|
799
|
+
continue;
|
|
800
|
+
if (fallback === '')
|
|
801
|
+
refuse(
|
|
802
|
+
E.ERR_THEME_BAD_VALUE,
|
|
803
|
+
`${name} is a ${type}; the var() in "${value}" has an empty fallback, which leaves it with no value when the variable is unset.`,
|
|
804
|
+
{
|
|
805
|
+
run: [
|
|
806
|
+
`${P} set ${slug} ${name} ${quoteCommandArgument(exampleOf(type, name))}`,
|
|
807
|
+
],
|
|
808
|
+
},
|
|
809
|
+
);
|
|
810
|
+
if (!/\bvar\(/i.test(fallback) && !/^[a-z-]+\(/i.test(fallback))
|
|
811
|
+
checkTypedValue(
|
|
812
|
+
type,
|
|
813
|
+
fallback,
|
|
814
|
+
name,
|
|
815
|
+
TOKENS,
|
|
816
|
+
typeOf,
|
|
817
|
+
slug,
|
|
818
|
+
readers,
|
|
819
|
+
multiplied,
|
|
820
|
+
);
|
|
821
|
+
}
|
|
353
822
|
// A var() naming a design token must name one of the same kind; the
|
|
354
823
|
// app's own variables are its business.
|
|
355
824
|
const ref = /^var\(\s*(--[a-z0-9-]+)\s*(,.*)?\)$/i.exec(value.trim());
|
|
@@ -364,10 +833,65 @@ function checkTypedValue(
|
|
|
364
833
|
],
|
|
365
834
|
},
|
|
366
835
|
);
|
|
836
|
+
// The fallback is what shows when the variable is unset: it must be a
|
|
837
|
+
// value of the token's kind too.
|
|
838
|
+
const fallback = ref[2]?.slice(1).trim();
|
|
839
|
+
if (fallback === '' && type !== 'other')
|
|
840
|
+
refuse(
|
|
841
|
+
E.ERR_THEME_BAD_VALUE,
|
|
842
|
+
`${name} is a ${type}; "${value}" has an empty fallback, which leaves it with no value when the variable is unset.`,
|
|
843
|
+
{
|
|
844
|
+
run: [
|
|
845
|
+
`${P} set ${slug} ${name} ${quoteCommandArgument(exampleOf(type, name))}`,
|
|
846
|
+
],
|
|
847
|
+
},
|
|
848
|
+
);
|
|
849
|
+
if (fallback)
|
|
850
|
+
checkTypedValue(
|
|
851
|
+
type,
|
|
852
|
+
fallback,
|
|
853
|
+
name,
|
|
854
|
+
TOKENS,
|
|
855
|
+
typeOf,
|
|
856
|
+
slug,
|
|
857
|
+
readers,
|
|
858
|
+
multiplied,
|
|
859
|
+
);
|
|
367
860
|
return;
|
|
368
861
|
}
|
|
369
862
|
if (type === 'color' && !isFixedColor(value)) bad('a color', '#1f2937');
|
|
370
|
-
if (type === 'size' && !isSize(value, name))
|
|
863
|
+
if (type === 'size' && !isSize(value, name)) {
|
|
864
|
+
// With nothing to read from the value, the token's own default (a text
|
|
865
|
+
// size stays readable), never one size for every token.
|
|
866
|
+
// Followed through the tokens it reads (var(--font-size-base)).
|
|
867
|
+
let own = String(TOKENS[name] ?? '').trim();
|
|
868
|
+
for (let hop = 0; hop < 4; hop += 1) {
|
|
869
|
+
const ref = /^var\(\s*(--[a-z0-9-]+)\s*\)$/i.exec(own)?.[1];
|
|
870
|
+
if (!ref) break;
|
|
871
|
+
own = String(TOKENS[ref] ?? '').trim();
|
|
872
|
+
}
|
|
873
|
+
const sizeExample =
|
|
874
|
+
own && isSize(own, name) && !/var\(/.test(own) ? own : '6px';
|
|
875
|
+
// The size meant, when one dot or sign is all that is wrong (1.px).
|
|
876
|
+
const meant = value.trim().replace(/(\d)\.(?=[a-z%]|$)/gi, '$1');
|
|
877
|
+
// A bare number is the size in px.
|
|
878
|
+
// A bare number is the size in px; a minus sign is dropped.
|
|
879
|
+
const plain = value.trim().replace(/^-(?=\d|\.\d)/, '');
|
|
880
|
+
const px = /^[+]?\d*\.?\d+(e[+-]?\d+)?$/i.test(plain)
|
|
881
|
+
? `${Number(plain)}px`
|
|
882
|
+
: /^\d*\.?\d+[a-z%]+$/i.test(plain) && plain !== value.trim()
|
|
883
|
+
? plain
|
|
884
|
+
: null;
|
|
885
|
+
const slip = sizeMeant(value, x => isSize(x, name));
|
|
886
|
+
bad(
|
|
887
|
+
'a size',
|
|
888
|
+
meant !== value.trim() && isSize(meant, name)
|
|
889
|
+
? meant
|
|
890
|
+
: px && isSize(px, name)
|
|
891
|
+
? px
|
|
892
|
+
: (slip ?? sizeExample),
|
|
893
|
+
);
|
|
894
|
+
}
|
|
371
895
|
// A percentage reaches every property that reads the token; one that
|
|
372
896
|
// takes none (a border or outline width, an outline offset) drops it.
|
|
373
897
|
if (type === 'size' && /%/.test(value.replace(/var\([^)]*\)/g, ''))) {
|
|
@@ -379,7 +903,38 @@ function checkTypedValue(
|
|
|
379
903
|
);
|
|
380
904
|
}
|
|
381
905
|
if (type === 'number' && !isNumber(value, name))
|
|
382
|
-
bad(
|
|
906
|
+
bad(
|
|
907
|
+
'a number',
|
|
908
|
+
numberMeant(value, name, x => isNumber(x, name)) ??
|
|
909
|
+
(/weight/.test(name) ? '600' : '1.4'),
|
|
910
|
+
);
|
|
911
|
+
// A token Core's stylesheet multiplies by a size inside calc() (the line
|
|
912
|
+
// heights) takes a number with no unit: there a length, a percentage or
|
|
913
|
+
// normal is invalid.
|
|
914
|
+
const coreDefault = String(TOKENS[name] ?? '').trim();
|
|
915
|
+
const v0 = value.trim();
|
|
916
|
+
const read = cssNumber(v0);
|
|
917
|
+
if (
|
|
918
|
+
type === 'number' &&
|
|
919
|
+
multiplied &&
|
|
920
|
+
!/^var\(--[a-z0-9-]+\)$/i.test(v0) &&
|
|
921
|
+
read?.unit !== '' &&
|
|
922
|
+
!(MATH_FUNCTION.test(v0) && matchType('number', v0) != null)
|
|
923
|
+
) {
|
|
924
|
+
const unitless =
|
|
925
|
+
read?.unit === 'em'
|
|
926
|
+
? String(read.value)
|
|
927
|
+
: read?.unit === '%'
|
|
928
|
+
? String(read.value / 100)
|
|
929
|
+
: coreDefault;
|
|
930
|
+
refuse(
|
|
931
|
+
E.ERR_THEME_BAD_VALUE,
|
|
932
|
+
`${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.`}`,
|
|
933
|
+
{
|
|
934
|
+
run: [`${P} set ${slug} ${name} ${quoteCommandArgument(unitless)}`],
|
|
935
|
+
},
|
|
936
|
+
);
|
|
937
|
+
}
|
|
383
938
|
if (type === 'time' && !isTime(value)) bad('a time up to 60s', '150ms');
|
|
384
939
|
if (type === 'easing' && !isEasing(value))
|
|
385
940
|
bad('an easing', 'cubic-bezier(0.2, 0, 0, 1)');
|
|
@@ -408,9 +963,13 @@ function isFixedColor(value) {
|
|
|
408
963
|
if (/^var\(/.test(v)) return true;
|
|
409
964
|
if (SYSTEM_COLORS.includes(v)) return true;
|
|
410
965
|
// Percentages that add up to 0 leave color-mix() no color.
|
|
966
|
+
// A share is 0% to 100%.
|
|
411
967
|
const zeroMix = (/** @type {string[]} */ colors) => {
|
|
412
968
|
const pcts = colors.map(c => mixSide(c).pct);
|
|
413
|
-
return
|
|
969
|
+
return (
|
|
970
|
+
pcts.some(p => p != null && (p < 0 || p > 100)) ||
|
|
971
|
+
(pcts.every(p => p != null) && pcts.every(p => p === 0))
|
|
972
|
+
);
|
|
414
973
|
};
|
|
415
974
|
const inner = (/** @type {string} */ fn) =>
|
|
416
975
|
splitTop(v.slice(fn.length + 1, -1), ',').map(x => x.trim());
|
|
@@ -517,18 +1076,66 @@ function isShadow(value) {
|
|
|
517
1076
|
|
|
518
1077
|
/**
|
|
519
1078
|
* Refuse a value that would read the token itself, through other tokens.
|
|
1079
|
+
* A token set on a part (`--on`) overrides only inside that part: there
|
|
1080
|
+
* it reads the part's own settings first and the whole theme's after, and
|
|
1081
|
+
* a whole-theme value never reads a part's. So a loop counts only when it
|
|
1082
|
+
* closes within one scope: a part token that reads a whole-theme token
|
|
1083
|
+
* reads the inherited value, which is already resolved.
|
|
520
1084
|
* @param {string} thing
|
|
521
1085
|
* @param {string} value
|
|
522
1086
|
* @param {Record<string, unknown>} TOKENS
|
|
523
1087
|
* @param {import('./_settings.mjs').ThemeData} data
|
|
1088
|
+
* @param {string} [cwd] the project, whose `<slug>.theme.ts` tokens win
|
|
1089
|
+
* over the settings and are read too
|
|
1090
|
+
* @param {{on?: string, state?: string, when?: string}} [scope] where
|
|
1091
|
+
* the token is set; none for the whole theme
|
|
524
1092
|
*/
|
|
525
|
-
function checkCycle(thing, value, TOKENS, data) {
|
|
1093
|
+
function checkCycle(thing, value, TOKENS, data, cwd, scope = {}) {
|
|
1094
|
+
const own = cwd ? ownSourceTokenValues(cwd, data.name) : {};
|
|
1095
|
+
// The base theme's own values come under the settings: a base that maps
|
|
1096
|
+
// one token to another closes a loop too.
|
|
1097
|
+
const baseTokens = cwd ? baseTopTokens(cwd, data.like) : new Map();
|
|
1098
|
+
const on = scope.on ?? null;
|
|
1099
|
+
const settings = [...data.settings].reverse();
|
|
1100
|
+
/**
|
|
1101
|
+
* The token's value set on the part, or undefined: a setting with the
|
|
1102
|
+
* same state and variant wins over the part's plain one.
|
|
1103
|
+
* @param {string} t
|
|
1104
|
+
*/
|
|
1105
|
+
const partValue = t => {
|
|
1106
|
+
if (on == null) return undefined;
|
|
1107
|
+
const onPart = settings.filter(
|
|
1108
|
+
s => s.source === 'token' && s.thing === t && s.on === on,
|
|
1109
|
+
);
|
|
1110
|
+
const same = onPart.find(
|
|
1111
|
+
s =>
|
|
1112
|
+
(s.state ?? null) === (scope.state ?? null) &&
|
|
1113
|
+
(s.when ?? null) === (scope.when ?? null),
|
|
1114
|
+
);
|
|
1115
|
+
const set = (same ?? onPart.find(s => s.state == null && s.when == null))
|
|
1116
|
+
?.value;
|
|
1117
|
+
if (set !== undefined) return set;
|
|
1118
|
+
// Else what the part's plain rule holds as built: the own source's and
|
|
1119
|
+
// the base theme's part rules (neutral's progress-bar reads
|
|
1120
|
+
// --color-border-emphasized).
|
|
1121
|
+
// A state or variant rule of the part inherits its plain rule.
|
|
1122
|
+
if (!cwd) return undefined;
|
|
1123
|
+
const rule = partRule().get(t);
|
|
1124
|
+
return rule ?? undefined;
|
|
1125
|
+
};
|
|
1126
|
+
/** @type {Map<string, string | null> | null} */
|
|
1127
|
+
let rule = null;
|
|
1128
|
+
const partRule = () =>
|
|
1129
|
+
(rule ??= on
|
|
1130
|
+
? partRuleTokens(/** @type {string} */ (cwd), data.name, data.like, on)
|
|
1131
|
+
: new Map());
|
|
526
1132
|
/** @param {string} t */
|
|
527
|
-
const
|
|
1133
|
+
const globalValue = t =>
|
|
528
1134
|
String(
|
|
529
|
-
[
|
|
530
|
-
.
|
|
531
|
-
|
|
1135
|
+
(Object.hasOwn(own, t) ? own[t] : null) ??
|
|
1136
|
+
settings.find(s => s.source === 'token' && s.thing === t && !s.on)
|
|
1137
|
+
?.value ??
|
|
1138
|
+
baseTokens.get(t) ??
|
|
532
1139
|
TOKENS[t] ??
|
|
533
1140
|
'',
|
|
534
1141
|
);
|
|
@@ -537,23 +1144,40 @@ function checkCycle(thing, value, TOKENS, data) {
|
|
|
537
1144
|
/** @type {string[]} */
|
|
538
1145
|
const path = [];
|
|
539
1146
|
const seen = new Set();
|
|
540
|
-
/**
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
1147
|
+
/**
|
|
1148
|
+
* Whether `t`, read in the part (`inPart`) or the whole theme, reaches
|
|
1149
|
+
* the token being set in its own scope.
|
|
1150
|
+
* @param {string} t @param {boolean} inPart @returns {boolean}
|
|
1151
|
+
*/
|
|
1152
|
+
const reaches = (t, inPart) => {
|
|
1153
|
+
// The token being set is reached only in the scope it is set in.
|
|
1154
|
+
if (t === thing && inPart === (on != null)) return true;
|
|
1155
|
+
const part = inPart ? partValue(t) : undefined;
|
|
1156
|
+
const local = part !== undefined;
|
|
1157
|
+
const key = `${local ? 'part' : 'theme'}:${t}`;
|
|
1158
|
+
if (seen.has(key)) return false;
|
|
1159
|
+
seen.add(key);
|
|
1160
|
+
path.push(
|
|
1161
|
+
local
|
|
1162
|
+
? `${t} (on ${on})`
|
|
1163
|
+
: Object.hasOwn(own, t)
|
|
1164
|
+
? `${t} (set in ${data.name}.theme.ts)`
|
|
1165
|
+
: t,
|
|
1166
|
+
);
|
|
1167
|
+
if (
|
|
1168
|
+
refs(local ? String(part) : globalValue(t)).some(r => reaches(r, local))
|
|
1169
|
+
)
|
|
1170
|
+
return true;
|
|
547
1171
|
path.pop();
|
|
548
1172
|
return false;
|
|
549
1173
|
};
|
|
550
|
-
if (refs(value).some(reaches))
|
|
1174
|
+
if (refs(value).some(r => reaches(r, on != null)))
|
|
551
1175
|
refuse(
|
|
552
1176
|
E.ERR_THEME_BAD_VALUE,
|
|
553
1177
|
`${thing} would read itself${path.length ? ` through ${path.join(', ')}` : ''}, so it would have no value at all.`,
|
|
554
1178
|
{
|
|
555
1179
|
run: [
|
|
556
|
-
`${P} set ${data.name} ${thing} <a value that does not read ${thing}
|
|
1180
|
+
`${P} set ${data.name} ${thing} <a value that does not read ${thing}>${on != null ? ` --on ${on}` : ''}`,
|
|
557
1181
|
],
|
|
558
1182
|
},
|
|
559
1183
|
);
|
|
@@ -582,10 +1206,31 @@ function propertyProblem(prop, value) {
|
|
|
582
1206
|
const v = value.trim();
|
|
583
1207
|
const known = propertyGrammar(prop);
|
|
584
1208
|
if (!known || COLOR_PROPS.test(prop)) return null;
|
|
1209
|
+
// Each var() fallback is what shows when its variable is unset: the
|
|
1210
|
+
// value with the fallbacks in place must be one the property takes too.
|
|
1211
|
+
const unset = withFallbacks(v);
|
|
1212
|
+
if (unset != null && matchValue(prop, v) && !matchValue(prop, unset))
|
|
1213
|
+
return {
|
|
1214
|
+
takes: `a value its CSS grammar takes in each var() fallback too (${grammarText(known)})`,
|
|
1215
|
+
near: initialOf(prop),
|
|
1216
|
+
};
|
|
585
1217
|
if (matchValue(prop, v))
|
|
586
1218
|
return belowRange(prop, v)
|
|
587
|
-
? {
|
|
1219
|
+
? {
|
|
1220
|
+
takes: 'a value of 0 or more',
|
|
1221
|
+
near: v.replace(/(^|[\s(,/])-(?=\.?\d)/g, '$1'),
|
|
1222
|
+
}
|
|
588
1223
|
: null;
|
|
1224
|
+
// The same value as it was meant to be typed (a font name quoted, a
|
|
1225
|
+
// trailing `;` gone), when the property takes that.
|
|
1226
|
+
const fixed = valueMeant(prop === 'font-family' ? 'font' : 'other', v).find(
|
|
1227
|
+
c => matchValue(prop, c),
|
|
1228
|
+
);
|
|
1229
|
+
if (fixed)
|
|
1230
|
+
return {
|
|
1231
|
+
takes: `a value its CSS grammar takes (${grammarText(known)})`,
|
|
1232
|
+
near: fixed,
|
|
1233
|
+
};
|
|
589
1234
|
// Only keywords the property takes on their own are offered; the same
|
|
590
1235
|
// word without its dashes or a trailing -ed/-s comes first (no-wrap is
|
|
591
1236
|
// nowrap, underlined is underline), then the nearest in spelling.
|
|
@@ -602,57 +1247,90 @@ function propertyProblem(prop, value) {
|
|
|
602
1247
|
// the property's initial value, or an example of its kind; each checked.
|
|
603
1248
|
const example = exampleOf(groupOfPropType(prop), prop);
|
|
604
1249
|
const initial = initialOf(prop);
|
|
1250
|
+
// A bare number on a length property means px (`padding 4` → `4px`, each
|
|
1251
|
+
// number in a list too), when the property takes that.
|
|
1252
|
+
// Each bare number token gets px (a mixed list `4 8px`, `8 / 4`, an
|
|
1253
|
+
// exponent `1e1`), a unit split off by a space (`4 px`) joins its number.
|
|
1254
|
+
const joined = v.replace(/(\d)\s+(px|rem|em|%)\b/gi, '$1$2');
|
|
1255
|
+
const withPx = /\d/.test(joined)
|
|
1256
|
+
? joined.replace(
|
|
1257
|
+
/(^|[\s/(,])([+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?)(?=$|[\s/),])/gi,
|
|
1258
|
+
(_, pre, num) =>
|
|
1259
|
+
Number(num) === 0 ? `${pre}${num}` : `${pre}${num}px`,
|
|
1260
|
+
)
|
|
1261
|
+
: null;
|
|
1262
|
+
// A suggestion is offered only when the property takes it, in range too.
|
|
1263
|
+
const takes = (/** @type {string | null} */ x) =>
|
|
1264
|
+
x != null && matchValue(prop, x) != null && !belowRange(prop, x);
|
|
605
1265
|
return {
|
|
606
1266
|
takes: `a value its CSS grammar takes (${grammarText(known)})`,
|
|
607
1267
|
near:
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
(
|
|
1268
|
+
(takes(withPx) ? withPx : null) ??
|
|
1269
|
+
// Below the property's range (a negative width): the same, 0 or more.
|
|
1270
|
+
(withPx && takes(withPx.replace(/(^|[\s/(,])-(?=\.?\d)/g, '$1'))
|
|
1271
|
+
? withPx.replace(/(^|[\s/(,])-(?=\.?\d)/g, '$1')
|
|
1272
|
+
: null) ??
|
|
1273
|
+
(takes(joined) && joined !== v ? joined : null) ??
|
|
1274
|
+
// Several values on a property that takes one (padding-top with four):
|
|
1275
|
+
// the first of them, when it is one the property takes.
|
|
1276
|
+
(() => {
|
|
1277
|
+
const first = splitTop((withPx ?? joined).trim(), ' ')[0];
|
|
1278
|
+
return first && first !== v && takes(first) ? first : null;
|
|
1279
|
+
})() ??
|
|
1280
|
+
(near && takes(near) ? near : null) ??
|
|
1281
|
+
// A value with numbers never falls back to the property's reset
|
|
1282
|
+
// (padding 0 would remove what was asked for).
|
|
1283
|
+
(/\d/.test(v)
|
|
1284
|
+
? null
|
|
1285
|
+
: ((takes(initial) ? initial : null) ??
|
|
1286
|
+
(takes(example) ? example : null))),
|
|
611
1287
|
};
|
|
612
1288
|
}
|
|
613
1289
|
|
|
614
1290
|
/** 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
|
-
}
|
|
1291
|
+
const DIAL_WORDS = wordTable(
|
|
1292
|
+
/** @type {Record<string, Record<string, string>>} */ ({
|
|
1293
|
+
surfaces: {
|
|
1294
|
+
elevated: 'raised',
|
|
1295
|
+
elevation: 'raised',
|
|
1296
|
+
shadow: 'raised',
|
|
1297
|
+
shadows: 'raised',
|
|
1298
|
+
lifted: 'raised',
|
|
1299
|
+
frosted: 'glass',
|
|
1300
|
+
blur: 'glass',
|
|
1301
|
+
blurred: 'glass',
|
|
1302
|
+
translucent: 'glass',
|
|
1303
|
+
bordered: 'outlined',
|
|
1304
|
+
border: 'outlined',
|
|
1305
|
+
borders: 'outlined',
|
|
1306
|
+
lined: 'outlined',
|
|
1307
|
+
outline: 'outlined',
|
|
1308
|
+
plain: 'flat',
|
|
1309
|
+
minimal: 'flat',
|
|
1310
|
+
},
|
|
1311
|
+
buttons: {
|
|
1312
|
+
uppercase: 'caps',
|
|
1313
|
+
upper: 'caps',
|
|
1314
|
+
allcaps: 'caps',
|
|
1315
|
+
capitals: 'caps',
|
|
1316
|
+
tint: 'soft',
|
|
1317
|
+
tinted: 'soft',
|
|
1318
|
+
subtle: 'soft',
|
|
1319
|
+
outlined: 'outline',
|
|
1320
|
+
bordered: 'outline',
|
|
1321
|
+
ghost: 'outline',
|
|
1322
|
+
filled: 'solid',
|
|
1323
|
+
fill: 'solid',
|
|
1324
|
+
},
|
|
1325
|
+
mode: {
|
|
1326
|
+
auto: 'both',
|
|
1327
|
+
system: 'both',
|
|
1328
|
+
default: 'both',
|
|
1329
|
+
light: 'light-only',
|
|
1330
|
+
dark: 'dark-only',
|
|
1331
|
+
},
|
|
1332
|
+
}),
|
|
1333
|
+
);
|
|
656
1334
|
|
|
657
1335
|
/**
|
|
658
1336
|
/**
|
|
@@ -693,6 +1371,111 @@ export function checkSetting(
|
|
|
693
1371
|
value,
|
|
694
1372
|
flags,
|
|
695
1373
|
unset = false,
|
|
1374
|
+
) {
|
|
1375
|
+
// Any other dial's value pasted with its property name (`font-size:
|
|
1376
|
+
// 18px;` for text-size, `color: #e11d48` for accent) is the value: one
|
|
1377
|
+
// path for every dial (the font dial reads its own below).
|
|
1378
|
+
if (!unset && typeof value === 'string' && DIALS[thing] && thing !== 'font') {
|
|
1379
|
+
const d = pastedDeclaration(value);
|
|
1380
|
+
if (d?.value) value = d.value;
|
|
1381
|
+
}
|
|
1382
|
+
// The font dial's value as pasted from a stylesheet (`Georgia, serif;`,
|
|
1383
|
+
// a comment, `!important`): a refusal suggests the font it names, when
|
|
1384
|
+
// set takes that.
|
|
1385
|
+
// A font pasted with its property name is the family list it names.
|
|
1386
|
+
if (
|
|
1387
|
+
!unset &&
|
|
1388
|
+
typeof value === 'string' &&
|
|
1389
|
+
(thing === 'font' ||
|
|
1390
|
+
(thing.startsWith('--') && ctx.C.typeOf(thing) === 'font'))
|
|
1391
|
+
) {
|
|
1392
|
+
const pasted = pastedFont(value);
|
|
1393
|
+
if (pasted === '')
|
|
1394
|
+
refuse(
|
|
1395
|
+
E.ERR_MISSING_ARGUMENT,
|
|
1396
|
+
`"${value.trim()}" names a font property but gives no font. Give the family after the colon, or alone.`,
|
|
1397
|
+
{
|
|
1398
|
+
run: [
|
|
1399
|
+
`${P} set ${slug} ${thing} ${quoteCommandArgument(thing === 'font' ? 'inter' : 'Inter, sans-serif')}${flags.on ? ` --on ${quoteCommandArgument(flags.on)}` : ''}`,
|
|
1400
|
+
],
|
|
1401
|
+
},
|
|
1402
|
+
);
|
|
1403
|
+
if (pasted) value = pasted;
|
|
1404
|
+
}
|
|
1405
|
+
if (thing === 'font' && !unset && typeof value === 'string') {
|
|
1406
|
+
const meant = typedPlain(value)
|
|
1407
|
+
.replace(/;+\s*$/, '')
|
|
1408
|
+
.replace(/\s*!\s*important\s*$/i, '')
|
|
1409
|
+
.replace(/;+\s*$/, '')
|
|
1410
|
+
.replace(/\s+/g, ' ')
|
|
1411
|
+
.trim();
|
|
1412
|
+
if (meant && meant !== value.trim())
|
|
1413
|
+
try {
|
|
1414
|
+
return checkSettingAsTyped(ctx, slug, data, thing, value, flags);
|
|
1415
|
+
} catch (e) {
|
|
1416
|
+
try {
|
|
1417
|
+
checkSettingAsTyped(ctx, slug, data, thing, meant, flags);
|
|
1418
|
+
} catch {
|
|
1419
|
+
throw e;
|
|
1420
|
+
}
|
|
1421
|
+
if (e instanceof AstryxError)
|
|
1422
|
+
e.suggestions = [
|
|
1423
|
+
{
|
|
1424
|
+
name: `${P} set ${slug} font ${quoteCommandArgument(meant)}${flags.on ? ` --on ${quoteCommandArgument(flags.on)}` : ''}`,
|
|
1425
|
+
reason: 'do this instead',
|
|
1426
|
+
},
|
|
1427
|
+
];
|
|
1428
|
+
throw e;
|
|
1429
|
+
}
|
|
1430
|
+
}
|
|
1431
|
+
const s = checkSettingAsTyped(ctx, slug, data, thing, value, flags, unset);
|
|
1432
|
+
// A var() with a fallback always gives a value; a name one slip from a
|
|
1433
|
+
// design token is noted as a likely typo, and the setting stands.
|
|
1434
|
+
if (!unset && typeof value === 'string' && !s.note) {
|
|
1435
|
+
const typo = fallbackVarTypo(value, ctx.project.core.tokenDefaults ?? {});
|
|
1436
|
+
if (typo) s.note = typo;
|
|
1437
|
+
}
|
|
1438
|
+
return s;
|
|
1439
|
+
}
|
|
1440
|
+
|
|
1441
|
+
/**
|
|
1442
|
+
* A note for a var() with a fallback whose name is a letter or two off a
|
|
1443
|
+
* design token (`var(--spacing-xl, 2rem)` when the token is `--spacing-x1`):
|
|
1444
|
+
* the fallback shows until it is fixed. Null when there is none.
|
|
1445
|
+
* @param {string} v
|
|
1446
|
+
* @param {Record<string, unknown>} TOKENS
|
|
1447
|
+
*/
|
|
1448
|
+
function fallbackVarTypo(v, TOKENS) {
|
|
1449
|
+
for (const [, name] of v.matchAll(/var\(\s*(--[a-z0-9-]+)\s*,/gi)) {
|
|
1450
|
+
if (name in TOKENS || name.startsWith('--_')) continue;
|
|
1451
|
+
const near = nearest(name, Object.keys(TOKENS)).filter(
|
|
1452
|
+
n => levenshteinDistance(n, name) <= 2,
|
|
1453
|
+
);
|
|
1454
|
+
if (near.length)
|
|
1455
|
+
return `${name} is not a design token, so its fallback always shows; did you mean ${near[0]}?`;
|
|
1456
|
+
}
|
|
1457
|
+
return null;
|
|
1458
|
+
}
|
|
1459
|
+
|
|
1460
|
+
/**
|
|
1461
|
+
* checkSetting for the value as typed.
|
|
1462
|
+
* @param {import('./_settings.mjs').Ctx} ctx
|
|
1463
|
+
* @param {string} slug
|
|
1464
|
+
* @param {import('./_settings.mjs').ThemeData} data
|
|
1465
|
+
* @param {string} thing
|
|
1466
|
+
* @param {string | undefined} value
|
|
1467
|
+
* @param {SetFlags} flags
|
|
1468
|
+
* @param {boolean} [unset]
|
|
1469
|
+
* @returns {import('./_settings.mjs').Setting}
|
|
1470
|
+
*/
|
|
1471
|
+
function checkSettingAsTyped(
|
|
1472
|
+
ctx,
|
|
1473
|
+
slug,
|
|
1474
|
+
data,
|
|
1475
|
+
thing,
|
|
1476
|
+
value,
|
|
1477
|
+
flags,
|
|
1478
|
+
unset = false,
|
|
696
1479
|
) {
|
|
697
1480
|
const s = checkOne(ctx, slug, data, thing, value, flags, unset);
|
|
698
1481
|
const why = unset ? null : valueProblem(s);
|
|
@@ -757,42 +1540,20 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
757
1540
|
run: [`${P} ${unset ? 'undo' : 'set'} --help`],
|
|
758
1541
|
});
|
|
759
1542
|
// 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();
|
|
1543
|
+
const v = normalValue(thing, value ?? '');
|
|
764
1544
|
// 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
|
-
}
|
|
1545
|
+
if (!unset) {
|
|
1546
|
+
const bad = unknownVarRef(v, TOKENS, thing);
|
|
1547
|
+
if (bad)
|
|
1548
|
+
refuse(E.ERR_THEME_UNKNOWN_TOKEN, bad.message, {
|
|
1549
|
+
didYouMean: bad.near,
|
|
1550
|
+
run: [
|
|
1551
|
+
bad.close
|
|
1552
|
+
? `${HOW} --list tokens ${bad.near[0].replace(/^--/, '').split('-')[0]}`
|
|
1553
|
+
: `${HOW} --list tokens`,
|
|
1554
|
+
],
|
|
1555
|
+
});
|
|
1556
|
+
}
|
|
796
1557
|
// A placeholder copied from a suggestion is not a value.
|
|
797
1558
|
if (!unset && /<[a-z][\w -]*>/i.test(v))
|
|
798
1559
|
refuse(
|
|
@@ -814,7 +1575,15 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
814
1575
|
});
|
|
815
1576
|
if (flags.on) s.on = flags.on.trim();
|
|
816
1577
|
if (flags.when) s.when = flags.when.trim();
|
|
817
|
-
|
|
1578
|
+
// A state in any case or spelling of its words (focusVisible,
|
|
1579
|
+
// focus_visible, 'focus visible') is the state, written as CSS writes it.
|
|
1580
|
+
if (flags.state)
|
|
1581
|
+
s.state = flags.state
|
|
1582
|
+
.trim()
|
|
1583
|
+
.replace(/^:+/, '')
|
|
1584
|
+
.replace(/([a-z0-9])([A-Z])/g, '$1-$2')
|
|
1585
|
+
.replace(/[\s_]+/g, '-')
|
|
1586
|
+
.toLowerCase();
|
|
818
1587
|
if (flags.only) s.only = true;
|
|
819
1588
|
if (flags.mode) {
|
|
820
1589
|
const mode = flags.mode.toLowerCase();
|
|
@@ -879,17 +1648,39 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
879
1648
|
if (s.on && !isRole && !FAMILIES[s.on]) {
|
|
880
1649
|
const t = TARGET.get(s.on);
|
|
881
1650
|
if (!t) {
|
|
882
|
-
// Another case of a part or group
|
|
883
|
-
|
|
884
|
-
|
|
1651
|
+
// Another case of a part or group, its class name copied from the
|
|
1652
|
+
// page (`.astryx-card`), or its component (`<Card>`, `Card`): that
|
|
1653
|
+
// part, as a working command with every flag kept.
|
|
1654
|
+
const lower = s.on
|
|
1655
|
+
.trim()
|
|
1656
|
+
.replace(/^<\/?\s*|\s*\/?>$/g, '')
|
|
1657
|
+
.replace(/^\./, '')
|
|
1658
|
+
.replace(/^astryx-/, '')
|
|
1659
|
+
.replace(/([a-z0-9])([A-Z])/g, '$1-$2')
|
|
1660
|
+
.toLowerCase();
|
|
1661
|
+
// A plain word how reads as a part or group (checkboxes: checks).
|
|
1662
|
+
const byWord = partForWord(lower);
|
|
1663
|
+
// A plain plural of a part (cards, dialogs, tabs) is that part.
|
|
1664
|
+
const singular = [
|
|
1665
|
+
lower.replace(/ies$/, 'y'),
|
|
1666
|
+
lower.replace(/(ch|sh|x|s)es$/, '$1'),
|
|
1667
|
+
lower.replace(/s$/, ''),
|
|
1668
|
+
].find(x => x !== lower && (TARGET.has(x) || FAMILIES[x]));
|
|
1669
|
+
const named =
|
|
1670
|
+
TARGET.has(lower) || FAMILIES[lower]
|
|
1671
|
+
? lower
|
|
1672
|
+
: singular
|
|
1673
|
+
? singular
|
|
1674
|
+
: byWord && (TARGET.has(byWord) || FAMILIES[byWord])
|
|
1675
|
+
? byWord
|
|
1676
|
+
: null;
|
|
1677
|
+
if (named)
|
|
885
1678
|
refuse(
|
|
886
1679
|
E.ERR_THEME_UNKNOWN_PART,
|
|
887
|
-
`"${s.on}" is not a part
|
|
1680
|
+
`"${s.on}" is not a part name; the part is ${named}.`,
|
|
888
1681
|
{
|
|
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
|
-
],
|
|
1682
|
+
didYouMean: [named],
|
|
1683
|
+
run: [setLine(slug, thing, v, {...s, on: named}, unset)],
|
|
893
1684
|
},
|
|
894
1685
|
);
|
|
895
1686
|
refuse(
|
|
@@ -902,7 +1693,7 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
902
1693
|
...Object.keys(FAMILIES),
|
|
903
1694
|
]),
|
|
904
1695
|
run: [
|
|
905
|
-
`${HOW} --list parts ${
|
|
1696
|
+
`${HOW} --list parts ${quoteCommandArgument(lower.replace(/s$/, '').split('-')[0] || 'button')}`,
|
|
906
1697
|
`${HOW} ${quoteCommandArgument(s.on)}`,
|
|
907
1698
|
],
|
|
908
1699
|
},
|
|
@@ -931,20 +1722,37 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
931
1722
|
);
|
|
932
1723
|
}
|
|
933
1724
|
const states = [...t.states, ...COMMON_STATES];
|
|
1725
|
+
// Other words for a state, mapped to the one the part has; with none
|
|
1726
|
+
// near, the list of its states (never a guess such as hover).
|
|
1727
|
+
const SYNONYMS = wordTable(
|
|
1728
|
+
/** @type {Record<string, string[]>} */ ({
|
|
1729
|
+
pressed: ['active'],
|
|
1730
|
+
press: ['active'],
|
|
1731
|
+
down: ['active'],
|
|
1732
|
+
clicked: ['active'],
|
|
1733
|
+
hovered: ['hover'],
|
|
1734
|
+
focused: ['focus-visible', 'focus-within', 'focus'],
|
|
1735
|
+
checked: ['checked', 'selected'],
|
|
1736
|
+
selected: ['selected', 'checked'],
|
|
1737
|
+
open: ['open', 'expanded'],
|
|
1738
|
+
expanded: ['expanded', 'open'],
|
|
1739
|
+
inactive: ['disabled'],
|
|
1740
|
+
}),
|
|
1741
|
+
);
|
|
1742
|
+
const meant =
|
|
1743
|
+
(SYNONYMS[String(s.state ?? '').toLowerCase()] ?? []).find(x =>
|
|
1744
|
+
states.includes(x),
|
|
1745
|
+
) ?? nearest(String(s.state ?? ''), states)[0];
|
|
934
1746
|
if (s.state && !states.includes(s.state))
|
|
935
1747
|
refuse(
|
|
936
1748
|
E.ERR_THEME_UNKNOWN_STATE,
|
|
937
1749
|
`"${s.state}" is not a state of ${s.on}. States: ${states.join(', ')}.`,
|
|
938
1750
|
{
|
|
939
|
-
didYouMean:
|
|
1751
|
+
...(meant ? {didYouMean: [meant]} : {}),
|
|
940
1752
|
run: [
|
|
941
|
-
|
|
942
|
-
slug,
|
|
943
|
-
|
|
944
|
-
v,
|
|
945
|
-
{...s, state: nearest(s.state, states)[0] ?? 'hover'},
|
|
946
|
-
unset,
|
|
947
|
-
),
|
|
1753
|
+
meant
|
|
1754
|
+
? setLine(slug, thing, v, {...s, state: meant}, unset)
|
|
1755
|
+
: `${HOW} ${quoteCommandArgument(s.on)}`,
|
|
948
1756
|
],
|
|
949
1757
|
},
|
|
950
1758
|
);
|
|
@@ -990,16 +1798,10 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
990
1798
|
// The part's component, or the one named like the part (tab is Tab,
|
|
991
1799
|
// under TabList), takes a disabled prop.
|
|
992
1800
|
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
1801
|
// Or its built module sets aria-disabled (a tab takes it through its
|
|
1000
1802
|
// other props): what Core renders, read from Core itself.
|
|
1001
|
-
const marks = (/** @type {string} */ n) => {
|
|
1002
|
-
const at =
|
|
1803
|
+
const marks = (/** @type {string} */ n, /** @type {any} */ doc) => {
|
|
1804
|
+
const at = doc?.importPath?.split('/').pop();
|
|
1003
1805
|
const file =
|
|
1004
1806
|
at && ctx.project.coreDir
|
|
1005
1807
|
? path.join(ctx.project.coreDir, 'dist', at, `${n}.js`)
|
|
@@ -1012,13 +1814,25 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
1012
1814
|
return false;
|
|
1013
1815
|
}
|
|
1014
1816
|
};
|
|
1015
|
-
return
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
(
|
|
1019
|
-
marks(n)),
|
|
1817
|
+
return partComponentDocs(ctx, t).some(
|
|
1818
|
+
({name, doc}) =>
|
|
1819
|
+
Object.keys(doc.props ?? {}).some(p => /disabled/i.test(p)) ||
|
|
1820
|
+
marks(name, doc),
|
|
1020
1821
|
);
|
|
1021
1822
|
};
|
|
1823
|
+
// A part holds content that can take focus, so focus-within applies
|
|
1824
|
+
// there: its component takes children or elements in a prop (a dialog,
|
|
1825
|
+
// a section, a chat composer's input).
|
|
1826
|
+
const holdsContent = (/** @type {string} */ t) =>
|
|
1827
|
+
partComponentDocs(ctx, t).some(({doc}) =>
|
|
1828
|
+
Object.entries(doc.props ?? {}).some(
|
|
1829
|
+
([k, v]) =>
|
|
1830
|
+
k === 'children' ||
|
|
1831
|
+
/\bReact(Node|Element)\b/.test(
|
|
1832
|
+
String(/** @type {any} */ (v)?.type ?? ''),
|
|
1833
|
+
),
|
|
1834
|
+
),
|
|
1835
|
+
);
|
|
1022
1836
|
// A part Core never styles in focus is not what takes focus (the
|
|
1023
1837
|
// focusable element is inside it, or beside it).
|
|
1024
1838
|
const focusable = (/** @type {string} */ t) =>
|
|
@@ -1026,7 +1840,8 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
1026
1840
|
const dead = parts.filter(
|
|
1027
1841
|
t =>
|
|
1028
1842
|
!states(t).includes(/** @type {string} */ (s.state)) &&
|
|
1029
|
-
(Object.keys(own(t)).length === 0
|
|
1843
|
+
((Object.keys(own(t)).length === 0 &&
|
|
1844
|
+
!(s.state === 'focus-within' && holdsContent(t))) ||
|
|
1030
1845
|
((s.state === 'focus' || s.state === 'focus-visible') &&
|
|
1031
1846
|
!focusable(t)) ||
|
|
1032
1847
|
(s.state === 'disabled' &&
|
|
@@ -1038,7 +1853,8 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
1038
1853
|
// focusable is inside it (a switch's input sits beside its track).
|
|
1039
1854
|
(s.state === 'focus-within' &&
|
|
1040
1855
|
!keys(t, 'focus-within') &&
|
|
1041
|
-
!focusable(t)
|
|
1856
|
+
!focusable(t) &&
|
|
1857
|
+
!holdsContent(t))),
|
|
1042
1858
|
);
|
|
1043
1859
|
if (parts.length && dead.length === parts.length) {
|
|
1044
1860
|
const bare = Object.keys(own(dead[0])).length === 0;
|
|
@@ -1069,6 +1885,43 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
1069
1885
|
);
|
|
1070
1886
|
}
|
|
1071
1887
|
}
|
|
1888
|
+
// Core expands a part's padding into its container tokens from a plain
|
|
1889
|
+
// padding only, so in a state that padding never reaches what sits edge
|
|
1890
|
+
// to edge inside it: refused, judged on the part named (a group member
|
|
1891
|
+
// spreads; when only another member is the reason, --only keeps it to
|
|
1892
|
+
// the part named).
|
|
1893
|
+
if (!unset && s.on && s.state && ctx.derived) {
|
|
1894
|
+
// A padding property goes through the padding model, which writes a
|
|
1895
|
+
// state's own side variables; the spacing dial does not.
|
|
1896
|
+
const prop = thing === 'spacing' ? 'padding' : null;
|
|
1897
|
+
const expands = (/** @type {string} */ t) =>
|
|
1898
|
+
(ctx.derived?.[t] ?? []).some(
|
|
1899
|
+
d => d.property === prop && d.expand === 'container',
|
|
1900
|
+
);
|
|
1901
|
+
const named = ctx.project.target.get(s.on) ? s.on : null;
|
|
1902
|
+
const hit = prop
|
|
1903
|
+
? named && expands(named)
|
|
1904
|
+
? named
|
|
1905
|
+
: partsOf(ctx, s).find(expands)
|
|
1906
|
+
: undefined;
|
|
1907
|
+
if (hit)
|
|
1908
|
+
refuse(
|
|
1909
|
+
E.ERR_THEME_NO_EFFECT,
|
|
1910
|
+
`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.`,
|
|
1911
|
+
{
|
|
1912
|
+
// The value as set takes it: a bare number in px.
|
|
1913
|
+
run: (() => {
|
|
1914
|
+
const fixed =
|
|
1915
|
+
thing === 'spacing' ? v : (propertyProblem(thing, v)?.near ?? v);
|
|
1916
|
+
return [
|
|
1917
|
+
named && !expands(named) && !s.only
|
|
1918
|
+
? setLine(slug, thing, fixed, {...s, only: true})
|
|
1919
|
+
: setLine(slug, thing, fixed, {...s, state: undefined}),
|
|
1920
|
+
];
|
|
1921
|
+
})(),
|
|
1922
|
+
},
|
|
1923
|
+
);
|
|
1924
|
+
}
|
|
1072
1925
|
// On a group, a variant or state must belong to at least one member.
|
|
1073
1926
|
if (s.on && FAMILIES[s.on] && (s.when || s.state)) {
|
|
1074
1927
|
const members =
|
|
@@ -1100,6 +1953,23 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
1100
1953
|
{run: [`${HOW} ${s.on}`]},
|
|
1101
1954
|
);
|
|
1102
1955
|
}
|
|
1956
|
+
// A comparative is a step from the value now (never a rung picked by
|
|
1957
|
+
// spelling, which can go the other way).
|
|
1958
|
+
if (!unset && (thing === 'corners' || thing === 'spacing')) {
|
|
1959
|
+
const w = v.toLowerCase();
|
|
1960
|
+
const MORE =
|
|
1961
|
+
thing === 'corners'
|
|
1962
|
+
? /^(rounder|softer|bigger|larger|curvier|more rounded)$/
|
|
1963
|
+
: /^(roomier|looser|bigger|larger|wider|airier|more spacious)$/;
|
|
1964
|
+
const LESS =
|
|
1965
|
+
thing === 'corners'
|
|
1966
|
+
? /^(sharper|squarer|smaller|tighter|harder|less rounded)$/
|
|
1967
|
+
: /^(tighter|denser|smaller|narrower|more compact|closer)$/;
|
|
1968
|
+
if (MORE.test(w))
|
|
1969
|
+
return checkOne(ctx, slug, data, thing, 'more', flags, unset);
|
|
1970
|
+
if (LESS.test(w))
|
|
1971
|
+
return checkOne(ctx, slug, data, thing, 'less', flags, unset);
|
|
1972
|
+
}
|
|
1103
1973
|
const step = v === 'more' || v === 'less';
|
|
1104
1974
|
// more/less step a dial with a scale; on a dial of named looks, they name
|
|
1105
1975
|
// nothing, so the answer is what the dial takes, not one of its values.
|
|
@@ -1153,21 +2023,32 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
1153
2023
|
didYouMean: near,
|
|
1154
2024
|
run: near[0]
|
|
1155
2025
|
? [`${P} set ${slug} ${thing} ${near[0]}`]
|
|
1156
|
-
: // A
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
2026
|
+
: // A type-scale ratio (1.25) is the nearest type preset.
|
|
2027
|
+
thing === 'type' && ratioPreset(lower)
|
|
2028
|
+
? [`${P} set ${slug} type ${ratioPreset(lower)}`]
|
|
2029
|
+
: // A corner word or a size with a unit is the corners dial:
|
|
2030
|
+
// on the buttons for `buttons`, for the whole theme
|
|
2031
|
+
// otherwise. A bare number is no size: the dial's own
|
|
2032
|
+
// words.
|
|
2033
|
+
CORNERS.some(([n]) => lower.replace(/s$/, '') === n) ||
|
|
2034
|
+
(/[a-z%]$/.test(lower) && lengthPx(lower) != null)
|
|
2035
|
+
? [
|
|
2036
|
+
setLine(
|
|
2037
|
+
slug,
|
|
2038
|
+
'corners',
|
|
2039
|
+
CORNERS.find(
|
|
2040
|
+
([n]) => lower.replace(/s$/, '') === n,
|
|
2041
|
+
)?.[0] ?? lower,
|
|
2042
|
+
thing === 'buttons' ? {on: 'button'} : {},
|
|
2043
|
+
),
|
|
2044
|
+
]
|
|
2045
|
+
: [
|
|
2046
|
+
...(/^[+-]?\d*\.?\d+$/.test(lower) ? ok : [])
|
|
2047
|
+
.filter(w => /^[a-z-]+$/.test(w))
|
|
2048
|
+
.slice(0, 4)
|
|
2049
|
+
.map(w => `${P} set ${slug} ${thing} ${w}`),
|
|
2050
|
+
`${HOW} ${thing}`,
|
|
2051
|
+
],
|
|
1171
2052
|
},
|
|
1172
2053
|
);
|
|
1173
2054
|
}
|
|
@@ -1179,9 +2060,24 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
1179
2060
|
E.ERR_THEME_BAD_VALUE,
|
|
1180
2061
|
'headings applies to every heading; drop --on. For one heading level use font-weight or letter-spacing --on heading --when level:<1-6>.',
|
|
1181
2062
|
{
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
2063
|
+
// The dial without --on, then the asked weight or tracking on
|
|
2064
|
+
// one level; a word with no meaning here gets neither.
|
|
2065
|
+
run: (() => {
|
|
2066
|
+
const w = String(v ?? '')
|
|
2067
|
+
.trim()
|
|
2068
|
+
.toLowerCase();
|
|
2069
|
+
if (HEADING_WEIGHTS[w] !== undefined)
|
|
2070
|
+
return [
|
|
2071
|
+
`${P} set ${slug} headings ${w}`,
|
|
2072
|
+
`${P} set ${slug} font-weight ${HEADING_WEIGHTS[w]} --on heading --when level:1`,
|
|
2073
|
+
];
|
|
2074
|
+
if (HEADING_TRACKING[w] !== undefined)
|
|
2075
|
+
return [
|
|
2076
|
+
`${P} set ${slug} headings ${w}`,
|
|
2077
|
+
`${P} set ${slug} letter-spacing ${quoteCommandArgument(HEADING_TRACKING[w])} --on heading --when level:1`,
|
|
2078
|
+
];
|
|
2079
|
+
return [`${HOW} headings`];
|
|
2080
|
+
})(),
|
|
1185
2081
|
},
|
|
1186
2082
|
);
|
|
1187
2083
|
if (s.mode)
|
|
@@ -1197,10 +2093,14 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
1197
2093
|
if (unset) {
|
|
1198
2094
|
// With no word, the one headings setting the theme has.
|
|
1199
2095
|
const held = data.settings.filter(x => x.thing === 'headings');
|
|
2096
|
+
// The half word in any letters: `Tracking`, `TIGHT`.
|
|
2097
|
+
const w = String(v ?? '')
|
|
2098
|
+
.trim()
|
|
2099
|
+
.toLowerCase();
|
|
1200
2100
|
s.axis =
|
|
1201
|
-
HEADING_TRACKING[
|
|
2101
|
+
HEADING_TRACKING[w] !== undefined || w === 'tracking'
|
|
1202
2102
|
? 'tracking'
|
|
1203
|
-
: HEADING_WEIGHTS[
|
|
2103
|
+
: HEADING_WEIGHTS[w] !== undefined || w === 'weight'
|
|
1204
2104
|
? 'weight'
|
|
1205
2105
|
: held.length === 1
|
|
1206
2106
|
? (held[0].axis ?? 'weight')
|
|
@@ -1209,28 +2109,36 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
1209
2109
|
}
|
|
1210
2110
|
if (HEADING_WEIGHTS[v] !== undefined) s.axis = 'weight';
|
|
1211
2111
|
else if (HEADING_TRACKING[v] !== undefined) s.axis = 'tracking';
|
|
1212
|
-
else
|
|
2112
|
+
else {
|
|
2113
|
+
// The word meant: in other letters (BOLD), or the rung nearest a
|
|
2114
|
+
// weight number (800 is heavy); never a rung the other way.
|
|
2115
|
+
const lower = v.trim().toLowerCase();
|
|
2116
|
+
const words = [
|
|
2117
|
+
...Object.keys(HEADING_WEIGHTS),
|
|
2118
|
+
...Object.keys(HEADING_TRACKING),
|
|
2119
|
+
];
|
|
2120
|
+
const weight = /^\d+(\.\d+)?$/.test(lower) ? Number(lower) : null;
|
|
2121
|
+
const meant =
|
|
2122
|
+
words.find(w => w === lower) ??
|
|
2123
|
+
(weight != null
|
|
2124
|
+
? Object.entries(HEADING_WEIGHTS).reduce((a, b) =>
|
|
2125
|
+
Math.abs(Number(b[1]) - weight) <
|
|
2126
|
+
Math.abs(Number(a[1]) - weight)
|
|
2127
|
+
? b
|
|
2128
|
+
: a,
|
|
2129
|
+
)[0]
|
|
2130
|
+
: nearest(lower, words)[0]);
|
|
1213
2131
|
refuse(
|
|
1214
2132
|
E.ERR_THEME_BAD_VALUE,
|
|
1215
|
-
`headings takes ${DIALS.headings.values}, not "${v}"
|
|
2133
|
+
`headings takes ${DIALS.headings.values}, not "${v}".${weight != null && meant ? ` ${meant} sets weight ${HEADING_WEIGHTS[meant]}.` : ''}`,
|
|
1216
2134
|
{
|
|
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
|
-
],
|
|
2135
|
+
didYouMean: meant ? [meant] : [],
|
|
2136
|
+
run: meant
|
|
2137
|
+
? [setLine(slug, 'headings', meant, s)]
|
|
2138
|
+
: [`${HOW} headings`],
|
|
1232
2139
|
},
|
|
1233
2140
|
);
|
|
2141
|
+
}
|
|
1234
2142
|
return s;
|
|
1235
2143
|
}
|
|
1236
2144
|
if (unset) return s;
|
|
@@ -1309,17 +2217,26 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
1309
2217
|
const edge = /** @type {[string, number]} */ (
|
|
1310
2218
|
v === 'more' ? L[L.length - 1] : L[0]
|
|
1311
2219
|
);
|
|
2220
|
+
// The example stays inside what the dial takes (text-size: 10 to
|
|
2221
|
+
// 32); at that end, the exact token takes the size instead.
|
|
2222
|
+
const [lo, hi] = thing === 'text-size' ? [10, 32] : [0, Infinity];
|
|
2223
|
+
const want = Math.round(px + (v === 'more' ? 2 : -2));
|
|
2224
|
+
const atEnd = v === 'more' ? px >= hi : px <= lo;
|
|
1312
2225
|
const example = String(cur).replace(
|
|
1313
2226
|
/\d*\.?\d+/,
|
|
1314
|
-
String(Math.max(
|
|
2227
|
+
String(Math.max(lo, Math.min(hi, want))),
|
|
1315
2228
|
);
|
|
1316
2229
|
refuse(
|
|
1317
2230
|
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
|
|
2231
|
+
`${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
2232
|
{
|
|
1320
|
-
run:
|
|
1321
|
-
|
|
1322
|
-
|
|
2233
|
+
run: atEnd
|
|
2234
|
+
? [
|
|
2235
|
+
`${P} set ${slug} --font-size-base ${quoteCommandArgument(`${Math.max(1, want)}px`)}`,
|
|
2236
|
+
]
|
|
2237
|
+
: [
|
|
2238
|
+
`${P} set ${slug} ${thing} ${quoteCommandArgument(example)}${s.on ? ` --on ${s.on}` : ''}`,
|
|
2239
|
+
],
|
|
1323
2240
|
},
|
|
1324
2241
|
);
|
|
1325
2242
|
}
|
|
@@ -1469,10 +2386,15 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
1469
2386
|
} else {
|
|
1470
2387
|
// A rung in any case, a size in px written any way: the plain form.
|
|
1471
2388
|
const lower = v.toLowerCase();
|
|
1472
|
-
|
|
2389
|
+
// Any CSS number in px (2e1px, +4px), the shared length parse.
|
|
2390
|
+
const pxLen = /px$/.test(lower) ? lengthPx(lower) : null;
|
|
1473
2391
|
if (CORNERS.some(([n]) => n === lower)) s.value = lower;
|
|
1474
|
-
else if (
|
|
1475
|
-
|
|
2392
|
+
else if (pxLen != null && pxLen >= 0)
|
|
2393
|
+
s.value =
|
|
2394
|
+
pxLen >= 1000 ? 'pill' : `${Math.round(pxLen * 10000) / 10000}px`;
|
|
2395
|
+
// No rounding, said any way, is square.
|
|
2396
|
+
else if (/^(0|0%|none|sharp|zero|no|flat)$/.test(lower))
|
|
2397
|
+
s.value = 'square';
|
|
1476
2398
|
else {
|
|
1477
2399
|
// What it most likely means, as a value corners takes: a simple
|
|
1478
2400
|
// calc() of px is worked out.
|
|
@@ -1574,6 +2496,17 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
1574
2496
|
run: [setLine(slug, 'spacing', nearFactor, s)],
|
|
1575
2497
|
},
|
|
1576
2498
|
);
|
|
2499
|
+
else if (/^(0|none|zero|no|off)$/i.test(v))
|
|
2500
|
+
// Spacing scales the theme's space; it never goes to nothing. The
|
|
2501
|
+
// tightest rung is the nearest that works.
|
|
2502
|
+
refuse(
|
|
2503
|
+
E.ERR_THEME_BAD_VALUE,
|
|
2504
|
+
`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.`,
|
|
2505
|
+
{
|
|
2506
|
+
didYouMean: [SPACING[0][0]],
|
|
2507
|
+
run: [setLine(slug, 'spacing', SPACING[0][0], s)],
|
|
2508
|
+
},
|
|
2509
|
+
);
|
|
1577
2510
|
else if (!SPACING.some(([n]) => n === v))
|
|
1578
2511
|
refuse(
|
|
1579
2512
|
E.ERR_THEME_BAD_VALUE,
|
|
@@ -1601,10 +2534,34 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
1601
2534
|
refuse(
|
|
1602
2535
|
E.ERR_THEME_BAD_VALUE,
|
|
1603
2536
|
'text-size applies to the whole theme; for one part use font-size.',
|
|
1604
|
-
{
|
|
2537
|
+
{
|
|
2538
|
+
// The asked size on the part: a rung's px (large is 15px), a
|
|
2539
|
+
// number as px; a step (more, less) has no size to carry.
|
|
2540
|
+
run: (() => {
|
|
2541
|
+
const w = String(v ?? '')
|
|
2542
|
+
.trim()
|
|
2543
|
+
.toLowerCase();
|
|
2544
|
+
const rung = TEXT_SIZE.find(([n]) => n === w)?.[1];
|
|
2545
|
+
const px =
|
|
2546
|
+
rung ?? (/^\d+(\.\d+)?(px)?$/.test(w) ? parseFloat(w) : null);
|
|
2547
|
+
return px != null && px > 0
|
|
2548
|
+
? [setLine(slug, 'font-size', `${px}px`, s)]
|
|
2549
|
+
: [`${HOW} font-size`];
|
|
2550
|
+
})(),
|
|
2551
|
+
},
|
|
1605
2552
|
);
|
|
1606
2553
|
if (step) s.value = ladder(TEXT_SIZE, 'medium');
|
|
1607
2554
|
else if (
|
|
2555
|
+
/^\d+\.\d+$/.test(v.trim()) &&
|
|
2556
|
+
Number(v) >= 10 &&
|
|
2557
|
+
Number(v) <= 32 &&
|
|
2558
|
+
Math.round(Number(v)) !== Number(v)
|
|
2559
|
+
) {
|
|
2560
|
+
// Core builds the type scale in whole pixels: the size is saved as
|
|
2561
|
+
// the whole pixel it builds, and the result says so.
|
|
2562
|
+
s.value = String(Math.round(Number(v)));
|
|
2563
|
+
s.note = `text-size ${v.trim()} is saved as ${s.value}: the type scale is built in whole pixels`;
|
|
2564
|
+
} else if (
|
|
1608
2565
|
!TEXT_SIZE.some(([n]) => n === v) &&
|
|
1609
2566
|
!(/^\d+(\.\d+)?$/.test(v.trim()) && Number(v) >= 10 && Number(v) <= 32)
|
|
1610
2567
|
)
|
|
@@ -1624,7 +2581,19 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
1624
2581
|
didYouMean: [near],
|
|
1625
2582
|
run: [`${P} set ${slug} text-size ${near}`],
|
|
1626
2583
|
}
|
|
1627
|
-
: {
|
|
2584
|
+
: {
|
|
2585
|
+
run: [
|
|
2586
|
+
`${P} set ${slug} text-size ${
|
|
2587
|
+
// A size typed full-width or with a trailing dot
|
|
2588
|
+
// (18, 18.) is that size.
|
|
2589
|
+
/^\d+(\.\d+)?\.?$/.test(typedPlain(v)) &&
|
|
2590
|
+
Number(typedPlain(v).replace(/\.$/, '')) >= 10 &&
|
|
2591
|
+
Number(typedPlain(v).replace(/\.$/, '')) <= 32
|
|
2592
|
+
? String(Number(typedPlain(v).replace(/\.$/, '')))
|
|
2593
|
+
: (textSizePx(v) ?? 16)
|
|
2594
|
+
}`,
|
|
2595
|
+
],
|
|
2596
|
+
};
|
|
1628
2597
|
})(),
|
|
1629
2598
|
);
|
|
1630
2599
|
else if (!TEXT_SIZE.some(([n]) => n === v))
|
|
@@ -1639,7 +2608,8 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
1639
2608
|
// What the value most likely meant: without quotes, a trailing `;`
|
|
1640
2609
|
// or `!important`, a bare hex with its #, the opaque color, or the
|
|
1641
2610
|
// nearest color name.
|
|
1642
|
-
const cleaned = v
|
|
2611
|
+
const cleaned = (pastedDeclaration(v)?.value || typedPlain(v))
|
|
2612
|
+
.replace(/^var\(\s*--[a-z0-9-]+\s*,\s*(.+)\)$/i, '$1')
|
|
1643
2613
|
.replace(/^(["'])(.*)\1$/, '$2')
|
|
1644
2614
|
.replace(/\s*!important\s*$/i, '')
|
|
1645
2615
|
.replace(/;+\s*$/, '')
|
|
@@ -1652,12 +2622,20 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
1652
2622
|
problem.kind === 'unknown'
|
|
1653
2623
|
? nearest(v.toLowerCase(), COLOR_NAMES)
|
|
1654
2624
|
: [];
|
|
2625
|
+
// light-dark(a, b): the dial takes one color, from which it makes
|
|
2626
|
+
// both modes; the light one is offered.
|
|
2627
|
+
const lightHalf =
|
|
2628
|
+
/^light-dark\(\s*([^,]+?)\s*,/i.exec(cleaned)?.[1] ?? null;
|
|
1655
2629
|
const better =
|
|
1656
2630
|
problem.opaque ??
|
|
1657
|
-
(cleaned !== v && !colorProblem(cleaned)
|
|
2631
|
+
(cleaned !== v && !colorProblem(cleaned)
|
|
2632
|
+
? cleaned
|
|
2633
|
+
: lightHalf && !colorProblem(lightHalf)
|
|
2634
|
+
? lightHalf
|
|
2635
|
+
: near[0]);
|
|
1658
2636
|
refuse(
|
|
1659
2637
|
E.ERR_THEME_BAD_VALUE,
|
|
1660
|
-
`"${v}" ${problem.message}.${problem.kind === 'unknown' || problem.kind === 'malformed' ? ' Give a hex, a color name, or an rgb(), hsl(), hwb(), lab(), lch(), oklab(), oklch() or color() color.' : ''}`,
|
|
2638
|
+
`"${v}" ${problem.message}.${problem.kind === 'unknown' || problem.kind === 'malformed' ? ' Give a hex, a color name, or an rgb(), hsl(), hwb(), lab(), lch(), oklab(), oklch() or color() color.' : ''}${better && better === lightHalf ? ` ${thing} takes one color and makes both modes from it; the light one (${better}) is offered. For a dark value of your own, set --color-accent --mode dark after.` : ''}`,
|
|
1661
2639
|
{
|
|
1662
2640
|
didYouMean: better ? [better] : near,
|
|
1663
2641
|
run: [
|
|
@@ -1697,23 +2675,34 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
1697
2675
|
},
|
|
1698
2676
|
);
|
|
1699
2677
|
s.value = String(next);
|
|
1700
|
-
}
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
2678
|
+
}
|
|
2679
|
+
const colors = data.settings.filter(
|
|
2680
|
+
x => x.source === 'dial' && PALETTE_DIALS.includes(x.thing),
|
|
2681
|
+
);
|
|
2682
|
+
// With no color to saturate, no vibrancy value is suggested.
|
|
2683
|
+
const canApply = colors.some(x => !isGraySeed(seedOf(x.value)));
|
|
2684
|
+
if (!step && canApply && (!/^\d{1,3}$/.test(v) || Number(v) > 100)) {
|
|
2685
|
+
// The value meant: a step in other letters (MORE), or the number
|
|
2686
|
+
// read as CSS reads it (70%, 7e1), kept in range.
|
|
2687
|
+
const word = v.trim().toLowerCase();
|
|
2688
|
+
const n = cssNumber(v);
|
|
2689
|
+
const near = ['more', 'less'].includes(word)
|
|
2690
|
+
? word
|
|
2691
|
+
: n && (n.unit === '' || n.unit === '%')
|
|
2692
|
+
? String(Math.max(0, Math.min(100, Math.round(n.value))))
|
|
2693
|
+
: null;
|
|
1706
2694
|
refuse(
|
|
1707
2695
|
E.ERR_THEME_BAD_VALUE,
|
|
1708
2696
|
`vibrancy takes a whole number from 0 (gray) to 100 (most vivid), or more or less, not "${v}".`,
|
|
1709
|
-
{
|
|
2697
|
+
{
|
|
2698
|
+
run: near
|
|
2699
|
+
? [`${P} set ${slug} vibrancy ${near}`]
|
|
2700
|
+
: [`${HOW} vibrancy`],
|
|
2701
|
+
},
|
|
1710
2702
|
);
|
|
1711
|
-
} else s.value = String(Number(v));
|
|
1712
|
-
const colors = data.settings.filter(
|
|
1713
|
-
x => x.source === 'dial' && PALETTE_DIALS.includes(x.thing),
|
|
1714
|
-
);
|
|
2703
|
+
} else if (!step && /^\d{1,3}$/.test(v)) s.value = String(Number(v));
|
|
1715
2704
|
// A gray has no color to saturate, so vibrancy changes nothing.
|
|
1716
|
-
if (!
|
|
2705
|
+
if (!canApply)
|
|
1717
2706
|
refuse(
|
|
1718
2707
|
E.ERR_THEME_NO_EFFECT,
|
|
1719
2708
|
colors.length
|
|
@@ -1741,7 +2730,7 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
1741
2730
|
const family = !parts && matchValue('font-family', v);
|
|
1742
2731
|
const example = `${P} set ${slug} font-family ${quoteCommandArgument(exampleOf('font', 'font-family'))} --on ${s.on}`;
|
|
1743
2732
|
const runs = parts
|
|
1744
|
-
? parts.system
|
|
2733
|
+
? parts.system || parts.repeat
|
|
1745
2734
|
? [example]
|
|
1746
2735
|
: Object.entries(parts).map(
|
|
1747
2736
|
([k, x]) =>
|
|
@@ -1754,9 +2743,55 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
1754
2743
|
: [example];
|
|
1755
2744
|
refuse(
|
|
1756
2745
|
E.ERR_THEME_BAD_VALUE,
|
|
1757
|
-
parts?.
|
|
1758
|
-
? `font --on takes body, heading, or code, and "${v}"
|
|
1759
|
-
:
|
|
2746
|
+
parts?.repeat
|
|
2747
|
+
? `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.`
|
|
2748
|
+
: parts?.system
|
|
2749
|
+
? `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.`
|
|
2750
|
+
: `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' : ''}.`,
|
|
2751
|
+
{run: runs},
|
|
2752
|
+
);
|
|
2753
|
+
}
|
|
2754
|
+
// A size, a weight or a whole CSS font value is no family: the font
|
|
2755
|
+
// dial and the roles take the family alone.
|
|
2756
|
+
// A variable is answered below, as the token form.
|
|
2757
|
+
const fontParts =
|
|
2758
|
+
step || /\b(var|env)\(/i.test(v) ? null : fontShorthandParts(v);
|
|
2759
|
+
if (
|
|
2760
|
+
fontParts &&
|
|
2761
|
+
(fontParts.repeat ||
|
|
2762
|
+
fontParts.system ||
|
|
2763
|
+
Object.keys(fontParts).some(k => k !== 'font-family'))
|
|
2764
|
+
) {
|
|
2765
|
+
const fam = fontParts['font-family'];
|
|
2766
|
+
const on = s.on ? ` --on ${s.on}` : '';
|
|
2767
|
+
/** @type {string[]} */
|
|
2768
|
+
const runs = [
|
|
2769
|
+
`${P} set ${slug} font ${quoteCommandArgument(fam ?? 'inter')}${on}`,
|
|
2770
|
+
];
|
|
2771
|
+
if (fontParts['font-size'] && (!s.on || s.on === 'body'))
|
|
2772
|
+
runs.push(
|
|
2773
|
+
`${P} set ${slug} --font-size-base ${quoteCommandArgument(fontParts['font-size'])}`,
|
|
2774
|
+
);
|
|
2775
|
+
const w = fontParts['font-weight'];
|
|
2776
|
+
if (w && (!s.on || s.on === 'heading')) {
|
|
2777
|
+
const num =
|
|
2778
|
+
w === 'bold' ? 700 : w === 'normal' ? 400 : Number(w) || null;
|
|
2779
|
+
const rung = num
|
|
2780
|
+
? Object.entries(HEADING_WEIGHTS).reduce((a, b) =>
|
|
2781
|
+
Math.abs(Number(b[1]) - num) < Math.abs(Number(a[1]) - num)
|
|
2782
|
+
? b
|
|
2783
|
+
: a,
|
|
2784
|
+
)[0]
|
|
2785
|
+
: null;
|
|
2786
|
+
if (rung) runs.push(`${P} set ${slug} headings ${rung}`);
|
|
2787
|
+
}
|
|
2788
|
+
refuse(
|
|
2789
|
+
E.ERR_THEME_BAD_VALUE,
|
|
2790
|
+
`font${s.on ? ` --on ${s.on}` : ''} takes a family or a preset, and "${v}" ${fam ? 'is a whole CSS font value' : 'is no family'}: ${
|
|
2791
|
+
Object.keys(fontParts)
|
|
2792
|
+
.filter(k => !['font-family', 'repeat', 'system'].includes(k))
|
|
2793
|
+
.join(', ') || 'a keyword'
|
|
2794
|
+
} ${fam ? 'would be read as part of the family name' : 'would be read as a family name'}, and the text would fall back.`,
|
|
1760
2795
|
{run: runs},
|
|
1761
2796
|
);
|
|
1762
2797
|
}
|
|
@@ -1847,6 +2882,11 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
1847
2882
|
],
|
|
1848
2883
|
},
|
|
1849
2884
|
);
|
|
2885
|
+
const file = fontFileReason(s.value);
|
|
2886
|
+
if (file)
|
|
2887
|
+
refuse(E.ERR_THEME_BAD_VALUE, file, {
|
|
2888
|
+
run: [`${P} set ${slug} font inter${s.on ? ` --on ${s.on}` : ''}`],
|
|
2889
|
+
});
|
|
1850
2890
|
if (s.value.split(',').some(f => f.trim().length > 100))
|
|
1851
2891
|
refuse(
|
|
1852
2892
|
E.ERR_THEME_BAD_VALUE,
|
|
@@ -1875,16 +2915,40 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
1875
2915
|
const meant = v
|
|
1876
2916
|
.toLowerCase()
|
|
1877
2917
|
.replace(/^base\s*[=:]\s*/, '')
|
|
1878
|
-
.trim()
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
2918
|
+
.trim()
|
|
2919
|
+
.replace(/^@astryxdesign\/theme-/, '')
|
|
2920
|
+
.replace(/^theme-/, '');
|
|
2921
|
+
// Only a base this project has installed is suggested; a theme
|
|
2922
|
+
// made here is never a base.
|
|
2923
|
+
const bases = [
|
|
2924
|
+
...LIKE.filter(b => baseInstalled(ctx.project, b)),
|
|
2925
|
+
'none',
|
|
2926
|
+
];
|
|
2927
|
+
// The base named in other letters is the one meant; a guess is
|
|
2928
|
+
// only among installed bases.
|
|
2929
|
+
const near =
|
|
2930
|
+
bases.includes(meant) || LIKE.includes(meant)
|
|
2931
|
+
? [meant]
|
|
2932
|
+
: nearest(meant, bases);
|
|
2933
|
+
// A built-in base named that is not installed: install it, then the
|
|
2934
|
+
// same set.
|
|
2935
|
+
const install =
|
|
2936
|
+
LIKE.includes(meant) && !baseInstalled(ctx.project, meant)
|
|
2937
|
+
? [installLine(ctx.project.cwd, [`@astryxdesign/theme-${meant}`])]
|
|
2938
|
+
: [];
|
|
2939
|
+
const madeHere = fs.existsSync(themeFiles(ctx.project.cwd, v).settings);
|
|
1882
2940
|
refuse(
|
|
1883
2941
|
E.ERR_THEME_BAD_VALUE,
|
|
1884
|
-
`base takes ${DIALS.base.values}, not "${v}"
|
|
2942
|
+
`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
2943
|
{
|
|
1886
2944
|
didYouMean: near,
|
|
1887
|
-
|
|
2945
|
+
// With nothing near, every base that works here, none first.
|
|
2946
|
+
run: near[0]
|
|
2947
|
+
? [...install, `${P} set ${slug} base ${near[0]}`]
|
|
2948
|
+
: [
|
|
2949
|
+
'none',
|
|
2950
|
+
...LIKE.filter(b => baseInstalled(ctx.project, b)),
|
|
2951
|
+
].map(b => `${P} set ${slug} base ${b}`),
|
|
1888
2952
|
},
|
|
1889
2953
|
);
|
|
1890
2954
|
}
|
|
@@ -1922,6 +2986,18 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
1922
2986
|
`"${thing}" is private to a component; themes cannot set it.`,
|
|
1923
2987
|
{run: [`${HOW} ${quoteCommandArgument(thing)}`]},
|
|
1924
2988
|
);
|
|
2989
|
+
// A token typed with its declaration's colon (`--color-accent:`).
|
|
2990
|
+
const colonless = thing.replace(/\s*:+\s*$/, '');
|
|
2991
|
+
if (!(thing in TOKENS) && colonless !== thing && colonless in TOKENS)
|
|
2992
|
+
refuse(
|
|
2993
|
+
E.ERR_THEME_UNKNOWN_TOKEN,
|
|
2994
|
+
`"${thing}" ends with a colon; the token is ${colonless}.`,
|
|
2995
|
+
{
|
|
2996
|
+
run: [
|
|
2997
|
+
`${P} set ${slug} ${colonless}${v ? ` ${quoteCommandArgument(v.replace(/;+\s*$/, ''))}` : ''}`,
|
|
2998
|
+
],
|
|
2999
|
+
},
|
|
3000
|
+
);
|
|
1925
3001
|
if (!(thing in TOKENS)) {
|
|
1926
3002
|
refuse(E.ERR_THEME_UNKNOWN_TOKEN, `"${thing}" is not a design token.`, {
|
|
1927
3003
|
didYouMean: nearest(thing, Object.keys(TOKENS)),
|
|
@@ -1965,17 +3041,21 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
1965
3041
|
C.typeOf,
|
|
1966
3042
|
slug,
|
|
1967
3043
|
C.propsReading(thing),
|
|
3044
|
+
multipliedTokens(ctx.project).has(thing),
|
|
1968
3045
|
);
|
|
1969
|
-
checkCycle(thing, v, TOKENS, data);
|
|
3046
|
+
checkCycle(thing, v, TOKENS, data, ctx.project.cwd, s);
|
|
1970
3047
|
// With no part data, what reads the token is unknown: save, unchecked.
|
|
1971
3048
|
if (ctx.unchecked) return s;
|
|
1972
3049
|
const parts = partsOf(ctx, s);
|
|
1973
3050
|
if (parts.length) {
|
|
3051
|
+
// A part the base theme's own rule makes read the token reads it.
|
|
1974
3052
|
const results = parts.map(
|
|
1975
3053
|
t =>
|
|
1976
3054
|
/** @type {[string, import('./_compiler.mjs').CheckFailure | null]} */ ([
|
|
1977
3055
|
t,
|
|
1978
|
-
|
|
3056
|
+
baseComponentReads(ctx.project.cwd, data.like, t).has(thing)
|
|
3057
|
+
? null
|
|
3058
|
+
: C.checkTokenOn(slug, t, thing, v, P),
|
|
1979
3059
|
]),
|
|
1980
3060
|
);
|
|
1981
3061
|
const recorded = results.filter(([, r]) => !r?.soft);
|
|
@@ -2101,6 +3181,103 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
2101
3181
|
s.source = 'property';
|
|
2102
3182
|
s.thing = prop;
|
|
2103
3183
|
if (unset) return s;
|
|
3184
|
+
// initial and unset leave a part's padding variables without a value:
|
|
3185
|
+
// the part takes Core's own default, which the result names.
|
|
3186
|
+
if (/^padding/.test(prop) && /^(initial|unset)$/i.test(v.trim()) && s.on) {
|
|
3187
|
+
const owner = (ctx.derived?.[s.on] ?? []).some(
|
|
3188
|
+
d => d.property === 'padding' && d.expand,
|
|
3189
|
+
)
|
|
3190
|
+
? s.on
|
|
3191
|
+
: CARD_LIKE.includes(s.on)
|
|
3192
|
+
? 'card'
|
|
3193
|
+
: null;
|
|
3194
|
+
const fallback = owner
|
|
3195
|
+
? coreFallback(ctx.project, `--astryx-${owner}-padding`)
|
|
3196
|
+
: null;
|
|
3197
|
+
if (fallback) {
|
|
3198
|
+
const token = /^var\((--[a-z0-9-]+)\)$/i.exec(fallback)?.[1];
|
|
3199
|
+
const px = token
|
|
3200
|
+
? lengthPx(String(ctx.project.core.tokenDefaults?.[token] ?? ''))
|
|
3201
|
+
: lengthPx(fallback);
|
|
3202
|
+
s.note = `${v.trim()} means ${s.on}'s own default padding from Core: ${fallback}${px != null ? ` (${px}px)` : ''}`;
|
|
3203
|
+
}
|
|
3204
|
+
}
|
|
3205
|
+
// A part whose Core box reads this property's variable inside calc()
|
|
3206
|
+
// (a composer's or a menu's padding in its corners): one length is all
|
|
3207
|
+
// that works there, whether a length, a variable, or calc(), min(),
|
|
3208
|
+
// max() or clamp() giving one.
|
|
3209
|
+
if (s.on && ctx.derived) {
|
|
3210
|
+
const inCalc = calcVars(ctx.project);
|
|
3211
|
+
const hit = partsOf(ctx, s).find(t =>
|
|
3212
|
+
(ctx.derived?.[t] ?? []).some(
|
|
3213
|
+
d =>
|
|
3214
|
+
d.property === camel(prop) &&
|
|
3215
|
+
(d.vars ?? []).some(x => inCalc.has(x.toLowerCase())),
|
|
3216
|
+
),
|
|
3217
|
+
);
|
|
3218
|
+
if (hit && !oneLength(v)) {
|
|
3219
|
+
const first = splitTop(v.trim(), ' ')[0] ?? '';
|
|
3220
|
+
const n = cssNumber(first);
|
|
3221
|
+
const fix = oneLength(first)
|
|
3222
|
+
? first
|
|
3223
|
+
: n && !n.unit
|
|
3224
|
+
? `${n.value}px`
|
|
3225
|
+
: '12px';
|
|
3226
|
+
refuse(
|
|
3227
|
+
E.ERR_THEME_BAD_VALUE,
|
|
3228
|
+
`${hit} reads ${prop} inside calc() (its corners and inner rows follow it), where only one length works: a length, a variable, or calc(), min(), max() or clamp() giving one; not "${v.trim()}".`,
|
|
3229
|
+
{run: [setLine(slug, prop, fix, s)]},
|
|
3230
|
+
);
|
|
3231
|
+
}
|
|
3232
|
+
}
|
|
3233
|
+
// A part whose visible box is drawn inside its themed wrapper: only
|
|
3234
|
+
// what reaches that box is taken.
|
|
3235
|
+
const wrapped = s.on ? WRAPPED_PARTS[s.on] : undefined;
|
|
3236
|
+
if (wrapped) {
|
|
3237
|
+
const surface =
|
|
3238
|
+
/^(background|border|box-shadow|outline)(-|$)/.test(prop) &&
|
|
3239
|
+
!/radius/.test(prop);
|
|
3240
|
+
const side = /^padding-/.test(prop);
|
|
3241
|
+
const density = prop === 'padding' && /^density:/.test(s.when ?? '');
|
|
3242
|
+
if (surface || side || density)
|
|
3243
|
+
refuse(
|
|
3244
|
+
E.ERR_THEME_BAD_VALUE,
|
|
3245
|
+
surface
|
|
3246
|
+
? `${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.`
|
|
3247
|
+
: side
|
|
3248
|
+
? `${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).`
|
|
3249
|
+
: `${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.`,
|
|
3250
|
+
{
|
|
3251
|
+
run: surface
|
|
3252
|
+
? [
|
|
3253
|
+
`${P} set ${slug} --color-background-popover ${quoteCommandArgument('#ffffff')}`,
|
|
3254
|
+
`${HOW} ${s.on}`,
|
|
3255
|
+
]
|
|
3256
|
+
: [
|
|
3257
|
+
`${P} set ${slug} padding ${quoteCommandArgument(v)} --on ${s.on}`,
|
|
3258
|
+
],
|
|
3259
|
+
},
|
|
3260
|
+
);
|
|
3261
|
+
}
|
|
3262
|
+
// Core writes a container part's padding to variables of its own, where
|
|
3263
|
+
// a keyword that takes its value from elsewhere means no value at all.
|
|
3264
|
+
if (
|
|
3265
|
+
/^padding/.test(prop) &&
|
|
3266
|
+
/^(inherit|revert|revert-layer)$/i.test(v.trim()) &&
|
|
3267
|
+
(ctx.derived?.[/** @type {string} */ (s.on)] ?? []).some(
|
|
3268
|
+
d => d.property === 'padding' && d.expand,
|
|
3269
|
+
)
|
|
3270
|
+
)
|
|
3271
|
+
refuse(
|
|
3272
|
+
E.ERR_THEME_BAD_VALUE,
|
|
3273
|
+
`${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.`,
|
|
3274
|
+
{
|
|
3275
|
+
run: [
|
|
3276
|
+
`${P} set ${slug} ${prop} 0 --on ${s.on}`,
|
|
3277
|
+
`${P} undo ${slug} ${prop} --on ${s.on}`,
|
|
3278
|
+
],
|
|
3279
|
+
},
|
|
3280
|
+
);
|
|
2104
3281
|
// Text, headings and links take their color from the color prop.
|
|
2105
3282
|
const textParts = COLOR_PROP_PARTS;
|
|
2106
3283
|
if (
|
|
@@ -2109,16 +3286,22 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
2109
3286
|
) {
|
|
2110
3287
|
if (partsOf(ctx, s).every(t => textParts.includes(t))) {
|
|
2111
3288
|
const named = /^color:([\w-]+)$/.exec(s.when ?? '')?.[1];
|
|
3289
|
+
// The typed value goes into the token only when it is a plain color;
|
|
3290
|
+
// else the nearest color name, else an example.
|
|
3291
|
+
const color =
|
|
3292
|
+
v && isColorValue(v) && isFixedColor(v) && !/\bvar\(/i.test(v)
|
|
3293
|
+
? v
|
|
3294
|
+
: (nearestColorName(v) ?? '#1f2937');
|
|
2112
3295
|
refuse(
|
|
2113
3296
|
E.ERR_THEME_NO_EFFECT,
|
|
2114
3297
|
`${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
3298
|
{
|
|
2116
3299
|
run: [
|
|
2117
|
-
`${P} set ${slug} --color-text-${named ?? 'primary'} ${quoteCommandArgument(
|
|
3300
|
+
`${P} set ${slug} --color-text-${named ?? 'primary'} ${quoteCommandArgument(color)}${s.mode ? ` --mode ${s.mode}` : ''}`,
|
|
2118
3301
|
...(named
|
|
2119
3302
|
? []
|
|
2120
3303
|
: [
|
|
2121
|
-
`${P} set ${slug} --color-text-secondary ${quoteCommandArgument(
|
|
3304
|
+
`${P} set ${slug} --color-text-secondary ${quoteCommandArgument(color)}${s.mode ? ` --mode ${s.mode}` : ''}`,
|
|
2122
3305
|
]),
|
|
2123
3306
|
],
|
|
2124
3307
|
},
|
|
@@ -2131,7 +3314,13 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
2131
3314
|
// With a state, the other mode would take one variant's value for
|
|
2132
3315
|
// every variant, so any part whose variants read their own value needs
|
|
2133
3316
|
// the variant named.
|
|
2134
|
-
|
|
3317
|
+
// Per-variant colors only: a value that is not a color is refused for
|
|
3318
|
+
// --mode below, with the reason that holds.
|
|
3319
|
+
if (
|
|
3320
|
+
s.mode &&
|
|
3321
|
+
!s.when &&
|
|
3322
|
+
(COLOR_PROPS.test(prop) || (prop === 'background' && isColorValue(v)))
|
|
3323
|
+
) {
|
|
2135
3324
|
const g = C.groupOfProp(
|
|
2136
3325
|
prop === 'background' ? 'background-color' : prop,
|
|
2137
3326
|
);
|
|
@@ -2225,6 +3414,27 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
2225
3414
|
},
|
|
2226
3415
|
);
|
|
2227
3416
|
}
|
|
3417
|
+
// A var() inside a color (color-mix(in srgb, var(--x, 12px), red)) shows
|
|
3418
|
+
// its fallback when the variable is unset: that must be a color too,
|
|
3419
|
+
// except in a color's channels (rgb(var(--r, 0) 0 0)).
|
|
3420
|
+
if (COLOR_PROPS.test(prop) || (prop === 'background' && isColorValue(v)))
|
|
3421
|
+
for (const {fallback, within} of innerVarFallbacks(v)) {
|
|
3422
|
+
if (
|
|
3423
|
+
within.some(f =>
|
|
3424
|
+
/^(rgba?|hsla?|hwb|lab|lch|oklab|oklch|color)$/i.test(f),
|
|
3425
|
+
) ||
|
|
3426
|
+
/\bvar\(/i.test(fallback)
|
|
3427
|
+
)
|
|
3428
|
+
continue;
|
|
3429
|
+
if (fallback === '' || !isColorValue(fallback))
|
|
3430
|
+
refuse(
|
|
3431
|
+
E.ERR_THEME_BAD_VALUE,
|
|
3432
|
+
fallback === ''
|
|
3433
|
+
? `${prop} takes a color; the var() in "${v}" has an empty fallback, which leaves it with no color when the variable is unset.`
|
|
3434
|
+
: `${prop} takes a color; "${fallback}", a var() fallback in "${v}", is not one, so the ${prop} is lost when the variable is unset.`,
|
|
3435
|
+
{run: [setLine(slug, prop, exampleOf('color', prop), s)]},
|
|
3436
|
+
);
|
|
3437
|
+
}
|
|
2228
3438
|
// Every scope flag but --mode carries into the runs.
|
|
2229
3439
|
const whenFlag = `${s.when ? ` --when ${s.when}` : ''}${s.state ? ` --state ${s.state}` : ''}${s.only ? ' --only' : ''}`;
|
|
2230
3440
|
if (
|
|
@@ -2232,8 +3442,12 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
2232
3442
|
!COLOR_PROPS.test(prop) &&
|
|
2233
3443
|
!(prop === 'background' && isColorValue(v))
|
|
2234
3444
|
) {
|
|
2235
|
-
|
|
2236
|
-
|
|
3445
|
+
// A color mixed into the value (a border's) can go per mode on its
|
|
3446
|
+
// own; a value with none (a radius) is just set for both modes.
|
|
3447
|
+
const hasColor = /#[0-9a-f]{3,8}\b|rgba?\(|hsla?\(/i.test(v);
|
|
3448
|
+
const alt = !hasColor
|
|
3449
|
+
? null
|
|
3450
|
+
: prop === 'border' || prop.startsWith('border-')
|
|
2237
3451
|
? 'border-color'
|
|
2238
3452
|
: prop === 'background'
|
|
2239
3453
|
? 'background-color'
|
|
@@ -2435,3 +3649,88 @@ const dialWrites = token =>
|
|
|
2435
3649
|
|
|
2436
3650
|
/** The aspects `how` answers at the whole-theme level. */
|
|
2437
3651
|
export const ASPECTS = [...Object.keys(GROUPS), 'colors'];
|
|
3652
|
+
|
|
3653
|
+
/**
|
|
3654
|
+
* A setting's value as set reads it: one line, and tabs as spaces; in a font
|
|
3655
|
+
* value every run of spaces or tabs is one space, so `'Open Sans'` and
|
|
3656
|
+
* `'Open\tSans'` both name Open Sans.
|
|
3657
|
+
* @param {string} thing
|
|
3658
|
+
* @param {string} value
|
|
3659
|
+
*/
|
|
3660
|
+
export function normalValue(thing, value) {
|
|
3661
|
+
const one = value.replace(/\s*[\r\n]+\s*/g, ' ');
|
|
3662
|
+
return (
|
|
3663
|
+
thing === 'font' || thing.startsWith('--font-family')
|
|
3664
|
+
? familySpaces(one)
|
|
3665
|
+
: one.replace(/\t+/g, ' ')
|
|
3666
|
+
).trim();
|
|
3667
|
+
}
|
|
3668
|
+
|
|
3669
|
+
/** @see familySpaces in _settings.mjs, re-exported for the checks. */
|
|
3670
|
+
export {familySpaces};
|
|
3671
|
+
|
|
3672
|
+
/**
|
|
3673
|
+
* The first var() in a value that names no design token and would read
|
|
3674
|
+
* nothing (no fallback), or one a letter or two off a token, else null.
|
|
3675
|
+
* Dials take their own words, so a dial's var() with no near token passes.
|
|
3676
|
+
* @param {string} v
|
|
3677
|
+
* @param {Record<string, unknown>} TOKENS
|
|
3678
|
+
* @param {string} thing
|
|
3679
|
+
* @returns {{message: string, near: string[], close: boolean} | null}
|
|
3680
|
+
*/
|
|
3681
|
+
export function unknownVarRef(v, TOKENS, thing) {
|
|
3682
|
+
for (const [, name, comma] of v.matchAll(/var\(\s*(--[a-z0-9-]+)\s*(,)?/gi)) {
|
|
3683
|
+
if (name in TOKENS || name.startsWith('--_')) continue;
|
|
3684
|
+
// A fallback always gives a value: never "reads nothing" (a likely
|
|
3685
|
+
// typo is noted when the setting is made).
|
|
3686
|
+
if (comma) continue;
|
|
3687
|
+
const near = nearest(name, Object.keys(TOKENS)).filter(
|
|
3688
|
+
n => levenshteinDistance(n, name) <= 2,
|
|
3689
|
+
);
|
|
3690
|
+
if (near.length)
|
|
3691
|
+
return {
|
|
3692
|
+
message: `${name} is not a design token, so var(${name}) would read nothing.`,
|
|
3693
|
+
near,
|
|
3694
|
+
close: true,
|
|
3695
|
+
};
|
|
3696
|
+
// Without a fallback, a variable no design token names reads nothing;
|
|
3697
|
+
// var(--x, <value>) falls back to the value.
|
|
3698
|
+
if (!comma && !DIALS[thing])
|
|
3699
|
+
return {
|
|
3700
|
+
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.`,
|
|
3701
|
+
near: nearest(name, Object.keys(TOKENS)).slice(0, 3),
|
|
3702
|
+
close: false,
|
|
3703
|
+
};
|
|
3704
|
+
}
|
|
3705
|
+
return null;
|
|
3706
|
+
}
|
|
3707
|
+
|
|
3708
|
+
/**
|
|
3709
|
+
* Why a font value names a font file or a link rather than a family
|
|
3710
|
+
* (`./fonts/My.woff2`, `Inter.ttf`, `https://fonts.googleapis.com/…`,
|
|
3711
|
+
* `url(…)`), or null. A theme names families; a file is loaded with
|
|
3712
|
+
* @font-face or a font package.
|
|
3713
|
+
* @param {string} value
|
|
3714
|
+
* @returns {string | null}
|
|
3715
|
+
*/
|
|
3716
|
+
export function fontFileReason(value) {
|
|
3717
|
+
const hit = String(value)
|
|
3718
|
+
.split(',')
|
|
3719
|
+
.map(f => f.trim().replace(/^["']|["']$/g, ''))
|
|
3720
|
+
.find(
|
|
3721
|
+
f =>
|
|
3722
|
+
/^url\(/i.test(f) ||
|
|
3723
|
+
/:\/\//.test(f) ||
|
|
3724
|
+
/[\\/]/.test(f) ||
|
|
3725
|
+
/\.(woff2?|ttf|otf|eot)$/i.test(f),
|
|
3726
|
+
);
|
|
3727
|
+
const colon = String(value)
|
|
3728
|
+
.split(',')
|
|
3729
|
+
.map(f => f.trim().replace(/^["']|["']$/g, ''))
|
|
3730
|
+
.find(f => f.includes(':'));
|
|
3731
|
+
if (!hit && colon)
|
|
3732
|
+
return `"${colon}" holds a colon, so it is a pasted declaration or a link, not a font family name. Give the family alone, such as Inter, sans-serif.`;
|
|
3733
|
+
return hit
|
|
3734
|
+
? `"${hit}" is a font file or a link, not a font family name. A theme names a family (such as Inter); load the file with @font-face in your app's CSS, or install a font package, then set the family it defines.`
|
|
3735
|
+
: null;
|
|
3736
|
+
}
|