@astryxdesign/cli 0.7.16 → 0.7.17-canary.gb36275e
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 +13 -23
- package/api/build/_adapter.d.mts +5 -0
- package/api/build/_adapter.mjs +49 -34
- package/api/build/blocks/blocks.d.mts +7 -5
- package/api/build/blocks/blocks.mjs +113 -26
- package/api/build/build.doc.mjs +2 -1
- package/api/build/kit/rank.mjs +59 -12
- package/api/build/kit/weights.d.mts +16 -3
- package/api/build/kit/weights.json +1 -1
- package/api/build/kit/weights.mjs +238 -31
- package/api/build/kit/word-model.d.mts +23 -0
- package/api/build/kit/word-model.mjs +46 -0
- package/api/build/kit/words.d.mts +42 -0
- package/api/build/kit/words.mjs +82 -1
- package/api/component/__fixtures__/resolutions/modules.txt +4 -5
- package/api/component/list/list.d.mts +1 -1
- package/api/component/list/list.mjs +46 -5
- package/api/discover/_adapter.d.mts +1 -1
- package/api/docs/_adapter.d.mts +26 -2
- package/api/docs/_adapter.mjs +217 -5
- package/api/docs/docs.d.mts +3 -0
- package/api/docs/docs.doc.mjs +7 -1
- package/api/docs/docs.mjs +12 -0
- package/api/docs/docs.type.d.mts +5 -0
- package/api/docs/docs.type.mjs +2 -0
- package/api/docs/node/node.mjs +1 -1
- package/api/doctor/_adapter.d.mts +27 -5
- package/api/doctor/_adapter.mjs +77 -6
- package/api/doctor/built-checks.mjs +38 -13
- package/api/doctor/doctor.d.mts +4 -3
- package/api/doctor/doctor.mjs +14 -7
- package/api/doctor/theme-checks.mjs +121 -17
- package/api/render/_adapter.mjs +531 -192
- package/api/render/render.doc.mjs +11 -3
- package/api/render/render.type.d.mts +30 -0
- package/api/render/render.type.mjs +19 -0
- package/api/search/ORDERING.md +1 -1
- package/api/search/_candidate-score.mjs +51 -32
- package/api/search/_fit-order.mjs +3 -3
- package/api/search/_result.d.mts +5 -5
- package/api/search/_score.d.mts +6 -1
- package/api/search/_score.mjs +15 -3
- package/api/search/search.d.mts +1 -1
- package/api/theme/_adapter.mjs +10 -0
- package/api/theme/build/build.d.mts +47 -0
- package/api/theme/build/build.mjs +147 -25
- package/api/theme/theme.type.d.mts +10 -0
- package/api/theme/theme.type.mjs +7 -1
- package/api/theme-edit/_adapter.d.mts +48 -0
- package/api/theme-edit/_adapter.mjs +675 -42
- package/api/theme-edit/_check.d.mts +28 -22
- package/api/theme-edit/_check.mjs +1481 -252
- package/api/theme-edit/_color.d.mts +9 -0
- package/api/theme-edit/_color.mjs +41 -1
- package/api/theme-edit/_compiler.mjs +9 -0
- package/api/theme-edit/_context.mjs +60 -3
- package/api/theme-edit/_css.mjs +21 -1
- package/api/theme-edit/_edit.d.mts +22 -0
- package/api/theme-edit/_edit.mjs +1196 -88
- package/api/theme-edit/_how-commands.d.mts +57 -0
- package/api/theme-edit/_how-commands.mjs +536 -1
- package/api/theme-edit/_how-question.d.mts +65 -0
- package/api/theme-edit/_how-question.mjs +4401 -225
- package/api/theme-edit/_how.mjs +104 -4
- package/api/theme-edit/_marks.d.mts +31 -5
- package/api/theme-edit/_marks.mjs +57 -5
- package/api/theme-edit/_normal.d.mts +153 -0
- package/api/theme-edit/_normal.mjs +661 -0
- package/api/theme-edit/_palette.mjs +10 -4
- package/api/theme-edit/_parts.d.mts +8 -0
- package/api/theme-edit/_parts.mjs +103 -2
- package/api/theme-edit/_preview-app.d.mts +7 -1
- package/api/theme-edit/_preview-app.mjs +205 -17
- package/api/theme-edit/_preview.d.mts +64 -8
- package/api/theme-edit/_preview.mjs +447 -89
- package/api/theme-edit/_settings.d.mts +176 -5
- package/api/theme-edit/_settings.mjs +1936 -128
- package/api/theme-edit/_tables.d.mts +6 -0
- package/api/theme-edit/_tables.mjs +32 -1
- package/api/theme-edit/theme-edit.type.d.mts +10 -1
- package/api/theme-edit/theme-edit.type.mjs +4 -1
- package/api/theme-edit/themeEditPreviewApp.doc.mjs +3 -3
- package/assets/codemods/run-codemod.mjs +73 -6
- package/assets/codemods/transforms/next/index.mjs +11 -1
- package/assets/codemods/transforms/next/migrate-item-swipe-actions-to-swipe.mjs +394 -0
- package/assets/docs/author-a-theme.doc.mjs +1 -0
- package/assets/docs/theme.doc.dense.mjs +2 -2
- package/assets/docs/theme.doc.mjs +1 -1
- package/assets/docs/tree/check-your-docs.doc.mjs +1 -1
- package/assets/docs/tree/cli-command.doc.mjs +2 -3
- package/assets/docs/tree/render-pages.doc.mjs +43 -2
- package/assets/docs/tree/template-doc-overview.doc.mjs +1 -1
- package/assets/docs/tree/test-in-an-app.doc.mjs +1 -1
- package/assets/docs/use-a-theme.doc.mjs +1 -1
- package/assets/docs.generated.json +2 -2
- package/assets/self-audit.generated.json +1 -1
- package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.tsx +38 -0
- package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.tsx +36 -0
- package/assets/templates/components.generated.json +1 -1
- package/assets/templates/pages/ai-chat/template.doc.mjs +5 -4
- package/assets/templates/pages/ai-chat-landing/template.doc.mjs +2 -1
- package/assets/templates/pages/blank/template.doc.mjs +1 -1
- package/assets/templates/pages/canvas-editor/template.doc.mjs +4 -2
- package/assets/templates/pages/centered-hero/template.doc.mjs +9 -1
- package/assets/templates/pages/classic-gallery/template.doc.mjs +1 -1
- package/assets/templates/pages/contact-form/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard/template.doc.mjs +3 -2
- package/assets/templates/pages/dashboard-alert-rail/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard-cohort-funnel/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard-composition/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard-progress/template.doc.mjs +6 -3
- package/assets/templates/pages/detail-page/template.doc.mjs +10 -3
- package/assets/templates/pages/documentation/template.doc.mjs +4 -1
- package/assets/templates/pages/documentation-design/template.doc.mjs +7 -1
- package/assets/templates/pages/documentation-technical/template.doc.mjs +7 -1
- package/assets/templates/pages/editor/template.doc.mjs +2 -8
- package/assets/templates/pages/file-explorer/template.doc.mjs +1 -1
- package/assets/templates/pages/form-two-column/template.doc.mjs +4 -3
- package/assets/templates/pages/form-wizard/template.doc.mjs +5 -3
- package/assets/templates/pages/gallery-hero/template.doc.mjs +4 -2
- package/assets/templates/pages/ide/page.tsx +24 -2
- package/assets/templates/pages/kanban-board/template.doc.mjs +1 -9
- package/assets/templates/pages/library/template.doc.mjs +4 -1
- package/assets/templates/pages/login/template.doc.mjs +2 -1
- package/assets/templates/pages/login-card/template.doc.mjs +2 -1
- package/assets/templates/pages/login-split/template.doc.mjs +2 -1
- package/assets/templates/pages/login-sso/template.doc.mjs +4 -2
- package/assets/templates/pages/mixed-gallery/template.doc.mjs +2 -1
- package/assets/templates/pages/product-detail/template.doc.mjs +4 -2
- package/assets/templates/pages/product-gallery/template.doc.mjs +2 -1
- package/assets/templates/pages/settings-dialog/template.doc.mjs +2 -1
- package/assets/templates/pages/settings-sidebar/template.doc.mjs +2 -1
- package/assets/templates/pages/shell-nav/template.doc.mjs +4 -2
- package/assets/templates/pages/shell-side-nav/template.doc.mjs +5 -3
- package/assets/templates/pages/shell-top-nav/template.doc.mjs +2 -1
- package/assets/templates/pages/side-gallery/template.doc.mjs +9 -1
- package/assets/templates/pages/table-filter/template.doc.mjs +9 -8
- package/assets/templates/pages/table-grouped/template.doc.mjs +4 -2
- package/assets/templates/pages/table-page/template.doc.mjs +5 -4
- package/assets/templates/pages/table-tree/template.doc.mjs +6 -3
- package/assets/templates/pages/theme-showcase/template.doc.mjs +2 -9
- package/assets/templates/pages/work-item-detail/template.doc.mjs +1 -0
- package/authoring/debug/parse.d.mts +3 -3
- package/authoring/doctypes/_schema.d.mts +3 -3
- package/authoring/doctypes/command/command.doc.mjs +1 -1
- package/authoring/doctypes/template/template.doc.mjs +1 -1
- package/authoring/doctypes/template/type.ts +9 -0
- package/clients/cli/bin/astryx.mjs +6 -9
- package/clients/cli/build-id.generated.json +1 -1
- package/clients/cli/commands/component.doc.mjs +1 -1
- package/clients/cli/commands/component.mjs +20 -2
- package/clients/cli/commands/docs.doc.mjs +7 -1
- package/clients/cli/commands/docs.mjs +3 -1
- package/clients/cli/commands/doctor.mjs +22 -14
- package/clients/cli/commands/experimental/render.mjs +32 -1
- package/clients/cli/commands/experimental/theme.mjs +65 -14
- package/clients/cli/commands/experimental-render.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-compile.doc.mjs +3 -3
- package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
- package/clients/cli/commands/search.doc.mjs +2 -1
- package/clients/cli/commands/search.mjs +6 -1
- package/clients/cli/commands/template.mjs +4 -2
- package/clients/cli/commands/theme-build.doc.mjs +5 -1
- package/clients/cli/commands/theme.doc.mjs +1 -1
- package/clients/cli/commands/theme.mjs +153 -5
- package/clients/cli/commands/upgrade.mjs +42 -7
- package/clients/cli/index.mjs +1 -1
- package/clients/cli/lib/component-format.mjs +205 -98
- package/clients/cli/lib/hook-format.mjs +9 -19
- package/clients/cli/manifest.generated.json +1 -1
- package/foundation/agent-docs/agent-docs.mjs +1 -1
- package/foundation/config/theme-state.d.mts +13 -1
- package/foundation/config/theme-state.mjs +47 -7
- package/foundation/discovery/component-discovery.d.mts +11 -0
- package/foundation/discovery/component-discovery.mjs +27 -2
- package/foundation/discovery/component-replacement.mjs +130 -1
- package/foundation/discovery/entry-name-files.d.mts +43 -0
- package/foundation/discovery/entry-name-files.mjs +264 -0
- package/foundation/discovery/hook-discovery.d.mts +8 -2
- package/foundation/discovery/hook-discovery.mjs +20 -7
- package/foundation/discovery/package-exports.d.mts +10 -0
- package/foundation/discovery/package-exports.mjs +56 -3
- package/foundation/discovery/runner-allowlist.d.mts +1 -0
- package/foundation/discovery/runner-allowlist.mjs +2 -0
- package/foundation/discovery/template-adapter.d.mts +52 -0
- package/foundation/discovery/template-adapter.mjs +173 -10
- package/foundation/discovery/theme-imports.d.mts +14 -0
- package/foundation/discovery/theme-imports.mjs +43 -1
- package/foundation/doc-compiler/import.mjs +7 -1
- package/foundation/doc-compiler/parse-readable.mjs +4 -1
- package/foundation/doc-compiler/stored-docs.d.mts +22 -0
- package/foundation/doc-compiler/stored-docs.mjs +49 -0
- package/foundation/fs/cache-eviction.d.mts +21 -0
- package/foundation/fs/cache-eviction.mjs +73 -0
- package/foundation/fs/gather-cache.d.mts +25 -4
- package/foundation/fs/gather-cache.mjs +163 -53
- package/foundation/fs/jiti-cache.d.mts +19 -1
- package/foundation/fs/jiti-cache.mjs +130 -6
- package/foundation/fs/kept-tree.d.mts +60 -0
- package/foundation/fs/kept-tree.mjs +154 -0
- package/foundation/fs/module-loader.d.mts +18 -2
- package/foundation/fs/module-loader.mjs +92 -20
- package/foundation/identity/provider-identity.d.mts +6 -0
- package/foundation/identity/provider-identity.mjs +10 -1
- package/foundation/render/embedded-imports.d.mts +5 -4
- package/foundation/render/embedded-imports.mjs +7 -16
- package/foundation/render/file-header.d.mts +66 -0
- package/foundation/render/file-header.mjs +118 -0
- package/foundation/render/host-answer.d.mts +18 -0
- package/foundation/render/host-answer.mjs +46 -0
- package/foundation/render/host-exit.d.mts +1 -0
- package/foundation/render/host-exit.mjs +6 -1
- package/foundation/render/html-reader.d.mts +55 -2
- package/foundation/render/html-reader.mjs +145 -26
- package/foundation/render/markup-edits.d.mts +57 -0
- package/foundation/render/markup-edits.mjs +182 -0
- package/foundation/render/page-host.mjs +29 -12
- package/foundation/render/page-worker.mjs +83 -13
- package/foundation/render/render-page.d.mts +34 -2
- package/foundation/render/render-page.mjs +210 -29
- package/foundation/render/source-block.d.mts +73 -6
- package/foundation/render/source-block.mjs +170 -19
- package/foundation/render/ts-paths.d.mts +53 -6
- package/foundation/render/ts-paths.mjs +286 -41
- package/foundation/response/error-codes.d.mts +3 -1
- package/foundation/response/error-codes.d.ts +1 -0
- package/foundation/response/error-codes.doc.mjs +12 -1
- package/foundation/response/error-codes.mjs +10 -0
- package/foundation/text/string-utils.d.mts +3 -2
- package/foundation/text/string-utils.mjs +16 -3
- package/foundation/text/suggest-order.d.mts +9 -0
- package/foundation/text/suggest-order.mjs +13 -0
- package/host/index.mjs +8 -6
- package/package.json +6 -6
|
@@ -15,7 +15,6 @@ import * as path from 'node:path';
|
|
|
15
15
|
import {partForWord} from './_how-question.mjs';
|
|
16
16
|
import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
|
|
17
17
|
import {baseInstalled, baseThemeFile, installLine} from './_project.mjs';
|
|
18
|
-
import {levenshteinDistance} from '../../foundation/text/levenshtein.mjs';
|
|
19
18
|
import {
|
|
20
19
|
withFallbacks,
|
|
21
20
|
MATH_FUNCTION,
|
|
@@ -35,6 +34,7 @@ import {
|
|
|
35
34
|
} from './_css.mjs';
|
|
36
35
|
import {calcVars, coreFallback, multipliedTokens} from './_parts.mjs';
|
|
37
36
|
import {
|
|
37
|
+
MODE_WORDS,
|
|
38
38
|
AUTO_SPREAD,
|
|
39
39
|
COLOR_PROP_PARTS,
|
|
40
40
|
COLOR_PROPS,
|
|
@@ -85,6 +85,7 @@ import {
|
|
|
85
85
|
camel,
|
|
86
86
|
kebab,
|
|
87
87
|
nearest,
|
|
88
|
+
negates,
|
|
88
89
|
partDefault,
|
|
89
90
|
partsOf,
|
|
90
91
|
refuse,
|
|
@@ -98,10 +99,32 @@ import {
|
|
|
98
99
|
ownSourceTokenValues,
|
|
99
100
|
baseTopTokens,
|
|
100
101
|
baseComponentReads,
|
|
102
|
+
baseRuleHas,
|
|
101
103
|
partRuleTokens,
|
|
102
104
|
cssFamily,
|
|
103
105
|
familySpaces,
|
|
104
106
|
} from './_settings.mjs';
|
|
107
|
+
import {isColorToken} from './_compiler.mjs';
|
|
108
|
+
import {
|
|
109
|
+
trimInsideQuotes,
|
|
110
|
+
colorPair,
|
|
111
|
+
otherSettingLabel,
|
|
112
|
+
familiesOf,
|
|
113
|
+
familyPieces,
|
|
114
|
+
normalValueText,
|
|
115
|
+
normalizeEntry,
|
|
116
|
+
withoutDebris,
|
|
117
|
+
typoOf,
|
|
118
|
+
typoNear,
|
|
119
|
+
} from './_normal.mjs';
|
|
120
|
+
|
|
121
|
+
export {
|
|
122
|
+
familiesOf,
|
|
123
|
+
familyPieces,
|
|
124
|
+
normalValueText,
|
|
125
|
+
normalizeEntry,
|
|
126
|
+
withoutDebris,
|
|
127
|
+
};
|
|
105
128
|
import {quoteCommandArgument} from '../../foundation/env/package-manager.mjs';
|
|
106
129
|
|
|
107
130
|
export {lengthPx};
|
|
@@ -154,6 +177,108 @@ const cornerPxOf = v =>
|
|
|
154
177
|
|
|
155
178
|
const E = ERROR_CODES;
|
|
156
179
|
|
|
180
|
+
/**
|
|
181
|
+
* Why the math in a value's calc() cannot work, or null: each `+`/`-`
|
|
182
|
+
* needs two sides of one kind (a length with a length or a percentage, a
|
|
183
|
+
* number with a number), `*` needs a plain number on one side, `/` a plain
|
|
184
|
+
* number on the right. A var() counts as its fallback; one with none, or a
|
|
185
|
+
* nested min(), max() or clamp(), is not judged.
|
|
186
|
+
* @param {string} value
|
|
187
|
+
* @returns {string | null}
|
|
188
|
+
*/
|
|
189
|
+
export function calcUnitProblem(value) {
|
|
190
|
+
const text = String(value);
|
|
191
|
+
const re = /\bcalc\(/gi;
|
|
192
|
+
let m;
|
|
193
|
+
while ((m = re.exec(text))) {
|
|
194
|
+
const open = m.index + m[0].length - 1;
|
|
195
|
+
const close = matchingParen(text, open);
|
|
196
|
+
if (close < 0) return null;
|
|
197
|
+
let expr = text.slice(open + 1, close);
|
|
198
|
+
// Each var() is its fallback, innermost first.
|
|
199
|
+
for (let i = 0; i < 20 && /\bvar\(/i.test(expr); i += 1) {
|
|
200
|
+
const at = expr.search(/\bvar\((?:[^()]|\([^()]*\))*\)/i);
|
|
201
|
+
const v = /\bvar\(((?:[^()]|\([^()]*\))*)\)/i.exec(expr.slice(at));
|
|
202
|
+
if (at < 0 || !v) return null;
|
|
203
|
+
const comma = v[1].indexOf(',');
|
|
204
|
+
if (comma < 0) return null;
|
|
205
|
+
expr = `${expr.slice(0, at)}(${v[1].slice(comma + 1).trim()})${expr.slice(at + v[0].length)}`;
|
|
206
|
+
}
|
|
207
|
+
if (/[a-z-]+\(/i.test(expr.replace(/\bcalc\(/gi, '('))) continue;
|
|
208
|
+
const found = expr.match(/\d*\.?\d+(?:e[+-]?\d+)?[a-z%]*|[-+*/()]/gi);
|
|
209
|
+
if (!found) continue;
|
|
210
|
+
const tokens = found;
|
|
211
|
+
let pos = 0;
|
|
212
|
+
/** @returns {string | null} */
|
|
213
|
+
const kindOf = (/** @type {string} */ t) => {
|
|
214
|
+
const u = /[a-z%]*$/i.exec(t)?.[0].toLowerCase() ?? '';
|
|
215
|
+
if (!u) return 'number';
|
|
216
|
+
if (u === '%') return 'percent';
|
|
217
|
+
if (/^(m?s)$/.test(u)) return 'time';
|
|
218
|
+
if (/^(deg|rad|grad|turn)$/.test(u)) return 'angle';
|
|
219
|
+
return 'length';
|
|
220
|
+
};
|
|
221
|
+
/** @type {string | null} */
|
|
222
|
+
let why = null;
|
|
223
|
+
const fail = (/** @type {string} */ w) => {
|
|
224
|
+
why ??= w;
|
|
225
|
+
return 'number';
|
|
226
|
+
};
|
|
227
|
+
const join = (
|
|
228
|
+
/** @type {string} */ a,
|
|
229
|
+
/** @type {string} */ b,
|
|
230
|
+
/** @type {string} */ op,
|
|
231
|
+
) => {
|
|
232
|
+
if (op === '+' || op === '-') {
|
|
233
|
+
if (a === b) return a;
|
|
234
|
+
const lp = new Set([a, b]);
|
|
235
|
+
if (lp.has('length') && lp.has('percent') && lp.size === 2)
|
|
236
|
+
return 'length';
|
|
237
|
+
return fail(`${a} ${op} ${b} adds two kinds of value`);
|
|
238
|
+
}
|
|
239
|
+
if (op === '*') {
|
|
240
|
+
if (a === 'number') return b;
|
|
241
|
+
if (b === 'number') return a;
|
|
242
|
+
return fail(`${a} * ${b} multiplies two values with units`);
|
|
243
|
+
}
|
|
244
|
+
if (b === 'number') return a;
|
|
245
|
+
return fail(`${a} / ${b} divides by a value with a unit`);
|
|
246
|
+
};
|
|
247
|
+
/** @returns {string} */
|
|
248
|
+
const factor = () => {
|
|
249
|
+
const t = tokens[pos++];
|
|
250
|
+
if (t === '(') {
|
|
251
|
+
const k = sum();
|
|
252
|
+
pos++;
|
|
253
|
+
return k;
|
|
254
|
+
}
|
|
255
|
+
if (t === '-' || t === '+') return factor();
|
|
256
|
+
return t == null ? 'number' : (kindOf(t) ?? 'number');
|
|
257
|
+
};
|
|
258
|
+
/** @returns {string} */
|
|
259
|
+
const product = () => {
|
|
260
|
+
let k = factor();
|
|
261
|
+
while (tokens[pos] === '*' || tokens[pos] === '/') {
|
|
262
|
+
const op = tokens[pos++];
|
|
263
|
+
k = join(k, factor(), op);
|
|
264
|
+
}
|
|
265
|
+
return k;
|
|
266
|
+
};
|
|
267
|
+
/** @returns {string} */
|
|
268
|
+
function sum() {
|
|
269
|
+
let k = product();
|
|
270
|
+
while (tokens[pos] === '+' || tokens[pos] === '-') {
|
|
271
|
+
const op = tokens[pos++];
|
|
272
|
+
k = join(k, product(), op);
|
|
273
|
+
}
|
|
274
|
+
return k;
|
|
275
|
+
}
|
|
276
|
+
sum();
|
|
277
|
+
if (why) return why;
|
|
278
|
+
}
|
|
279
|
+
return null;
|
|
280
|
+
}
|
|
281
|
+
|
|
157
282
|
/**
|
|
158
283
|
* The fallbacks of the var() calls inside a value that is not one var()
|
|
159
284
|
* alone (`calc(var(--x, 4px) * 2)`), in order. A var() with an empty
|
|
@@ -227,6 +352,25 @@ function matchingParen(text, open) {
|
|
|
227
352
|
return -1;
|
|
228
353
|
}
|
|
229
354
|
|
|
355
|
+
/** A yes or no word, which `rounded` reads as round or square. */
|
|
356
|
+
const YES_NO = /^(true|yes|on|none|false|off|no)$/i;
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* A value as the corners dial reads it: a rung in any case, or a size with
|
|
360
|
+
* its unit (`10PX`, `1rem`) in px; null for anything else, a bare number
|
|
361
|
+
* included.
|
|
362
|
+
* @param {string} v
|
|
363
|
+
* @returns {string | null}
|
|
364
|
+
*/
|
|
365
|
+
function cornersRead(v) {
|
|
366
|
+
const lower = String(v).trim().toLowerCase();
|
|
367
|
+
if (CORNERS.some(([n]) => n === lower)) return lower;
|
|
368
|
+
if (/^(0|none|sharp|zero|flat)$/.test(lower)) return 'square';
|
|
369
|
+
if (/^[+-]?\d*\.?\d+$/.test(lower)) return null;
|
|
370
|
+
const px = lengthPx(lower);
|
|
371
|
+
return px != null && px >= 0 ? `${Math.round(px * 100) / 100}px` : null;
|
|
372
|
+
}
|
|
373
|
+
|
|
230
374
|
/**
|
|
231
375
|
* A text size written another way (20px, 2e1, +20, 1.25rem, 125%, `20 px`,
|
|
232
376
|
* `1,25rem`) as the body size in pixels text-size takes, kept to its 10 to
|
|
@@ -235,13 +379,52 @@ function matchingParen(text, open) {
|
|
|
235
379
|
* @returns {number | null}
|
|
236
380
|
*/
|
|
237
381
|
function textSizePx(v) {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
.replace(
|
|
382
|
+
// Paste debris around the size (quotes, `!important`, a trailing `;` or
|
|
383
|
+
// `,`) is not part of it.
|
|
384
|
+
const bare = withoutDebris(
|
|
385
|
+
String(v)
|
|
386
|
+
.replace(/^\s*(["'])(.*)\1\s*$/, '$2')
|
|
387
|
+
.replace(/\s*!\s*important\s*/i, '')
|
|
388
|
+
.replace(/[;,]+\s*$/, ''),
|
|
243
389
|
);
|
|
390
|
+
const plain = typedPlain(bare)
|
|
391
|
+
.replace(/(\d)\.(?=[a-z%]*$)/i, '$1')
|
|
392
|
+
.replace(/\s+/g, '')
|
|
393
|
+
.replace(/^(\d+),(\d+)/, '$1.$2');
|
|
394
|
+
// A constant calc() of px and rem sizes (`calc(16px + 2px)`) is worked out.
|
|
395
|
+
const calc =
|
|
396
|
+
/^calc\((\d*\.?\d+)(px|rem|em)?([*/+-])(\d*\.?\d+)(px|rem|em)?\)$/i.exec(
|
|
397
|
+
plain,
|
|
398
|
+
);
|
|
399
|
+
if (calc) {
|
|
400
|
+
const px = (/** @type {string} */ n, /** @type {string | undefined} */ u) =>
|
|
401
|
+
Number(n) * (u && /r?em/i.test(u) ? 16 : 1);
|
|
402
|
+
const [a, b] = [px(calc[1], calc[2]), px(calc[4], calc[5])];
|
|
403
|
+
const op = calc[3];
|
|
404
|
+
// Sizes add and subtract; a size scales by a plain number.
|
|
405
|
+
const r =
|
|
406
|
+
op === '+' || op === '-'
|
|
407
|
+
? calc[2] && calc[5]
|
|
408
|
+
? op === '+'
|
|
409
|
+
? a + b
|
|
410
|
+
: a - b
|
|
411
|
+
: null
|
|
412
|
+
: op === '*'
|
|
413
|
+
? calc[2] && calc[5]
|
|
414
|
+
? null
|
|
415
|
+
: a * b
|
|
416
|
+
: calc[5]
|
|
417
|
+
? null
|
|
418
|
+
: a / b;
|
|
419
|
+
return r != null && Number.isFinite(r) && r >= 10 && r <= 32
|
|
420
|
+
? Math.round(r * 100) / 100
|
|
421
|
+
: null;
|
|
422
|
+
}
|
|
423
|
+
const m = /^\+?(\d*\.?\d+(?:e[+-]?\d+)?)(px|rem|em|pt|%)?$/i.exec(plain);
|
|
244
424
|
if (!m) return null;
|
|
425
|
+
// A bare number under 4 (1.5, 1.125) reads as rem as much as px: no
|
|
426
|
+
// size is guessed for it.
|
|
427
|
+
if (!m[2] && Number(m[1]) < 4) return null;
|
|
245
428
|
const unit = (m[2] ?? '').toLowerCase();
|
|
246
429
|
const n =
|
|
247
430
|
Number(m[1]) *
|
|
@@ -334,6 +517,8 @@ function valueMeant(type, value) {
|
|
|
334
517
|
.replace(/\s*!\s*important\s*$/i, '')
|
|
335
518
|
.replace(/;+\s*$/, '')
|
|
336
519
|
.trim();
|
|
520
|
+
// Copy debris around it (a trailing comma, a stray quote or bracket).
|
|
521
|
+
p = withoutDebris(p).trim();
|
|
337
522
|
const q = /^(["'])(.*)\1$/.exec(p);
|
|
338
523
|
if (q && type !== 'font') p = q[2].trim();
|
|
339
524
|
const out = [p];
|
|
@@ -344,13 +529,14 @@ function valueMeant(type, value) {
|
|
|
344
529
|
if (type === 'font' || type === 'font-family') {
|
|
345
530
|
// A comma left out between families (`"Open Sans" serif`), read with
|
|
346
531
|
// css-tree.
|
|
532
|
+
// The stack read as families (a trailing comma, a stack wrapped in one
|
|
533
|
+
// more pair of quotes), each quoted as CSS needs it.
|
|
534
|
+
const fams = familiesOf(p);
|
|
535
|
+
// A number or size is no family: never quoted into one (`"700"`).
|
|
536
|
+
if (fams?.length && !fams.some(f => NUMBERISH.test(f)))
|
|
537
|
+
out.push(fams.map(f => cssFamily(f, true)).join(', '));
|
|
347
538
|
const listed = familyListMeant(p);
|
|
348
|
-
if (listed) out.push(listed);
|
|
349
|
-
// Each family quoted as CSS needs it, only when no family holds a
|
|
350
|
-
// quote inside (the pieces are whole names).
|
|
351
|
-
const pieces = p.split(',').map(f => f.trim().replace(/^["']|["']$/g, ''));
|
|
352
|
-
if (!listed && pieces.every(f => !/["'\\]/.test(f)))
|
|
353
|
-
out.push(pieces.map(f => cssFamily(f, true)).join(', '));
|
|
539
|
+
if (listed && !fams?.length) out.push(listed);
|
|
354
540
|
}
|
|
355
541
|
return [...new Set(out)].filter(x => x && x !== value.trim());
|
|
356
542
|
}
|
|
@@ -648,13 +834,45 @@ export function storedProblems(ctx, slug, data, skip = '') {
|
|
|
648
834
|
// it.
|
|
649
835
|
for (const s of data.settings) {
|
|
650
836
|
if (replaced(s) || typeof s.value !== 'string') continue;
|
|
651
|
-
|
|
652
|
-
|
|
837
|
+
// Read as typed input is (a font family's quotes trimmed too), so the
|
|
838
|
+
// line offered is the value set would save.
|
|
839
|
+
const clean = /font/i.test(s.thing)
|
|
840
|
+
? trimInsideQuotes(normalValueText(s.value))
|
|
841
|
+
: normalValueText(s.value);
|
|
842
|
+
if (clean !== s.value) {
|
|
843
|
+
// Name what is wrong: invisible spaces, or quotes around the value
|
|
844
|
+
// CSS does not read (a curly quote inside a quoted string is fine,
|
|
845
|
+
// and is left as it is).
|
|
846
|
+
const spaces =
|
|
847
|
+
clean.replace(/["']/g, '') !==
|
|
848
|
+
s.value.replace(
|
|
849
|
+
/[\u2018-\u201F\u00AB\u00BB\u2039\u203A\u300C-\u300F\uFF02\uFF07`"']/g,
|
|
850
|
+
'',
|
|
851
|
+
);
|
|
852
|
+
const quotes =
|
|
853
|
+
/[\u2018-\u201F\u00AB\u00BB\u2039\u203A\u300C-\u300F\uFF02\uFF07`]/.test(
|
|
854
|
+
s.value,
|
|
855
|
+
) &&
|
|
856
|
+
clean.replace(
|
|
857
|
+
/[\u00A0\u1680\u2000-\u200A\u202F\u205F\u3000\u200B-\u200D\u2060\uFEFF]/g,
|
|
858
|
+
'',
|
|
859
|
+
) !==
|
|
860
|
+
s.value.replace(
|
|
861
|
+
/[\u00A0\u1680\u2000-\u200A\u202F\u205F\u3000\u200B-\u200D\u2060\uFEFF]/g,
|
|
862
|
+
'',
|
|
863
|
+
);
|
|
864
|
+
const why = [
|
|
865
|
+
spaces &&
|
|
866
|
+
'a no-break, thin or zero-width space, which the browser does not read as a space',
|
|
867
|
+
quotes &&
|
|
868
|
+
'curly or other quotes around a value, where CSS reads only straight ones',
|
|
869
|
+
].filter(Boolean);
|
|
653
870
|
found.push({
|
|
654
871
|
setting: s,
|
|
655
|
-
why: `${s.thing} holds
|
|
872
|
+
why: `${s.thing} holds ${why.join(', and ') || 'characters the browser does not read as written'}`,
|
|
656
873
|
fix: clean,
|
|
657
874
|
});
|
|
875
|
+
}
|
|
658
876
|
}
|
|
659
877
|
for (const s of data.settings) {
|
|
660
878
|
if (s.source !== 'token' || s.thing === skipThing || !(s.thing in TOKENS))
|
|
@@ -700,6 +918,118 @@ export function storedProblems(ctx, slug, data, skip = '') {
|
|
|
700
918
|
return found;
|
|
701
919
|
}
|
|
702
920
|
|
|
921
|
+
/** The generic families a font list ends with. */
|
|
922
|
+
const GENERIC_FAMILIES = [
|
|
923
|
+
'serif',
|
|
924
|
+
'sans-serif',
|
|
925
|
+
'monospace',
|
|
926
|
+
'system-ui',
|
|
927
|
+
'cursive',
|
|
928
|
+
'fantasy',
|
|
929
|
+
'ui-serif',
|
|
930
|
+
'ui-sans-serif',
|
|
931
|
+
'ui-monospace',
|
|
932
|
+
'ui-rounded',
|
|
933
|
+
];
|
|
934
|
+
|
|
935
|
+
/** A number or a size, which is never a font family. */
|
|
936
|
+
const NUMBERISH = /^[+-]?(\d+\.?\d*|\.\d+)(px|rem|em|pt|%)?$/i;
|
|
937
|
+
|
|
938
|
+
/**
|
|
939
|
+
* The font list a value with a missing comma or a spaced generic means
|
|
940
|
+
* (`Georgia serif` is `Georgia, serif`, `Inter, sans serif` is `Inter,
|
|
941
|
+
* sans-serif`), with why; null when it has neither. A generic is read only
|
|
942
|
+
* in lower case, so a family named `Source Serif` stays one name.
|
|
943
|
+
* @param {string} value
|
|
944
|
+
* @returns {{value: string, why: string} | null}
|
|
945
|
+
*/
|
|
946
|
+
export function fontListMeant(value) {
|
|
947
|
+
const v = String(value).trim();
|
|
948
|
+
// A whole list in one pair of quotes or brackets (`"Inter, serif"`,
|
|
949
|
+
// `「Inter, serif」`): the quotes go around one family, so the list is
|
|
950
|
+
// what is inside.
|
|
951
|
+
const wrapped =
|
|
952
|
+
/^(?:"([^"]*,[^"]*)"|'([^']*,[^']*)'|「([^」]*,[^」]*)」|『([^』]*,[^』]*)』|“([^”]*,[^”]*)”|‘([^’]*,[^’]*)’|«([^»]*,[^»]*)»)$/.exec(
|
|
953
|
+
v,
|
|
954
|
+
);
|
|
955
|
+
if (wrapped) {
|
|
956
|
+
const inside = wrapped.slice(1).find(x => x != null) ?? '';
|
|
957
|
+
return {
|
|
958
|
+
value: (fontListMeant(inside)?.value ?? inside).trim(),
|
|
959
|
+
why: 'quotes go around one family name, not the whole list',
|
|
960
|
+
};
|
|
961
|
+
}
|
|
962
|
+
if (/["']/.test(v)) return null;
|
|
963
|
+
// Families split by `|`, `;` or ` / ` instead of commas.
|
|
964
|
+
if (
|
|
965
|
+
// (A pasted declaration, `font-family: Georgia, serif;`, is read
|
|
966
|
+
// elsewhere: a colon or a trailing `;` is no separator.)
|
|
967
|
+
!/:|\.(woff2?|ttf|otf)\b/i.test(v) &&
|
|
968
|
+
/\S\s*(?:\||;|\s\/\s)\s*\S/.test(v)
|
|
969
|
+
) {
|
|
970
|
+
const list = v
|
|
971
|
+
.split(/\s*(?:\||;|\s\/\s)\s*/)
|
|
972
|
+
.map(x => x.trim())
|
|
973
|
+
.filter(Boolean)
|
|
974
|
+
.join(', ');
|
|
975
|
+
if (list && list !== v)
|
|
976
|
+
return {
|
|
977
|
+
value: fontListMeant(list)?.value ?? list,
|
|
978
|
+
why: 'families are separated by commas',
|
|
979
|
+
};
|
|
980
|
+
}
|
|
981
|
+
if (/\bsans serif\b/.test(v) && !/\d/.test(v))
|
|
982
|
+
return {
|
|
983
|
+
value: v.replace(/\bsans serif\b/g, 'sans-serif'),
|
|
984
|
+
why: 'the generic family is sans-serif, with a dash',
|
|
985
|
+
};
|
|
986
|
+
// A comma missing before the generic family of any family in the list
|
|
987
|
+
// (`Inter, Georgia serif`), the names in any case (`georgia serif`).
|
|
988
|
+
const SHORTHAND =
|
|
989
|
+
/^(\d+(\.\d+)?(px|rem|em|pt|%)?|bold|bolder|lighter|normal|italic|oblique|small-caps)$/i;
|
|
990
|
+
// A word of a family name: letters (a digit after the first word, as in
|
|
991
|
+
// `Source Serif 4`), or a generic; never a shorthand's weight or size.
|
|
992
|
+
const familyWord = (/** @type {string} */ w, /** @type {number} */ i) =>
|
|
993
|
+
(/^[A-Za-z][A-Za-z0-9]*$/.test(w) && !SHORTHAND.test(w)) ||
|
|
994
|
+
(i > 0 && /^\d+$/.test(w)) ||
|
|
995
|
+
GENERIC_FAMILIES.includes(w);
|
|
996
|
+
const pieces = v.split(/\s*,\s*/);
|
|
997
|
+
let missing = false;
|
|
998
|
+
const fixedPieces = pieces.map(piece => {
|
|
999
|
+
const ws = piece.split(/\s+/);
|
|
1000
|
+
const end = ws[ws.length - 1];
|
|
1001
|
+
if (
|
|
1002
|
+
ws.length > 1 &&
|
|
1003
|
+
GENERIC_FAMILIES.includes(end) &&
|
|
1004
|
+
ws.slice(0, -1).every(familyWord)
|
|
1005
|
+
) {
|
|
1006
|
+
missing = true;
|
|
1007
|
+
return `${ws.slice(0, -1).join(' ')}, ${end}`;
|
|
1008
|
+
}
|
|
1009
|
+
return piece;
|
|
1010
|
+
});
|
|
1011
|
+
if (missing && pieces.length > 1)
|
|
1012
|
+
return {
|
|
1013
|
+
value: fixedPieces.join(', '),
|
|
1014
|
+
why: 'a comma goes before each generic family',
|
|
1015
|
+
};
|
|
1016
|
+
if (v.includes(',')) return null;
|
|
1017
|
+
const words = v.split(/\s+/);
|
|
1018
|
+
const last = words[words.length - 1];
|
|
1019
|
+
// Only family names before it (capitalized words), never a font
|
|
1020
|
+
// shorthand's weight, style or size.
|
|
1021
|
+
if (
|
|
1022
|
+
words.length > 1 &&
|
|
1023
|
+
GENERIC_FAMILIES.includes(last) &&
|
|
1024
|
+
words.slice(0, -1).every(familyWord)
|
|
1025
|
+
)
|
|
1026
|
+
return {
|
|
1027
|
+
value: `${words.slice(0, -1).join(' ')}, ${last}`,
|
|
1028
|
+
why: `a comma goes before the generic family ${last}`,
|
|
1029
|
+
};
|
|
1030
|
+
return null;
|
|
1031
|
+
}
|
|
1032
|
+
|
|
703
1033
|
/**
|
|
704
1034
|
* A value of a type to put in a suggestion, so a suggested command runs.
|
|
705
1035
|
* @param {string} type
|
|
@@ -772,17 +1102,37 @@ function checkTypedValue(
|
|
|
772
1102
|
}
|
|
773
1103
|
return null;
|
|
774
1104
|
};
|
|
775
|
-
/** @param {string} what @param {string} example */
|
|
1105
|
+
/** @param {string} what @param {string | null} example */
|
|
776
1106
|
const bad = (what, example) =>
|
|
777
1107
|
refuse(
|
|
778
1108
|
E.ERR_THEME_BAD_VALUE,
|
|
779
1109
|
`${name} is ${what}; "${value}" is not one.`,
|
|
780
1110
|
{
|
|
1111
|
+
// Nothing read from the value (no example given): how, never a
|
|
1112
|
+
// stock value.
|
|
781
1113
|
run: [
|
|
782
|
-
|
|
1114
|
+
(meant() ?? example) == null
|
|
1115
|
+
? `${HOW} ${name}`
|
|
1116
|
+
: `${P} set ${slug} ${name} ${quoteCommandArgument(String(meant() ?? example))}`,
|
|
783
1117
|
],
|
|
784
1118
|
},
|
|
785
1119
|
);
|
|
1120
|
+
// A font family list with a comma missing before a generic family
|
|
1121
|
+
// (`Georgia serif`), or a generic written with a space (`sans serif`): the
|
|
1122
|
+
// list meant.
|
|
1123
|
+
if (type === 'font') {
|
|
1124
|
+
const fixed = fontListMeant(value);
|
|
1125
|
+
if (fixed)
|
|
1126
|
+
refuse(
|
|
1127
|
+
E.ERR_THEME_BAD_VALUE,
|
|
1128
|
+
`"${value}" names a family that exists nowhere: ${fixed.why}.`,
|
|
1129
|
+
{
|
|
1130
|
+
run: [
|
|
1131
|
+
`${P} set ${slug} ${name} ${quoteCommandArgument(fixed.value)}`,
|
|
1132
|
+
],
|
|
1133
|
+
},
|
|
1134
|
+
);
|
|
1135
|
+
}
|
|
786
1136
|
// A font file or a link is no family name: never quoted into one.
|
|
787
1137
|
if (type === 'font') {
|
|
788
1138
|
const file = fontFileReason(pastedFont(value) || value);
|
|
@@ -792,6 +1142,18 @@ function checkTypedValue(
|
|
|
792
1142
|
`${P} set ${slug} ${name} ${quoteCommandArgument(exampleOf(type, name))}`,
|
|
793
1143
|
],
|
|
794
1144
|
});
|
|
1145
|
+
// An empty family (`""`, a trailing comma) or one quoted name holding
|
|
1146
|
+
// commas is a broken stack: the browser drops the fallback after it.
|
|
1147
|
+
const pieces = familyPieces(value);
|
|
1148
|
+
if (
|
|
1149
|
+
pieces &&
|
|
1150
|
+
(pieces.some(f => !f.name) ||
|
|
1151
|
+
pieces.some(f => f.quoted && f.name.includes(',')))
|
|
1152
|
+
)
|
|
1153
|
+
bad(
|
|
1154
|
+
'a font family list with a name for each family',
|
|
1155
|
+
exampleOf(type, name),
|
|
1156
|
+
);
|
|
795
1157
|
}
|
|
796
1158
|
if (!isSafeValue(value))
|
|
797
1159
|
refuse(
|
|
@@ -821,6 +1183,15 @@ function checkTypedValue(
|
|
|
821
1183
|
],
|
|
822
1184
|
},
|
|
823
1185
|
);
|
|
1186
|
+
// Math whose units cannot combine (`8 + 2px`, `0.5rem * 1px`, a var()
|
|
1187
|
+
// read as its fallback): the browser drops the whole value.
|
|
1188
|
+
const math = type === 'size' ? calcUnitProblem(value) : null;
|
|
1189
|
+
if (math)
|
|
1190
|
+
refuse(
|
|
1191
|
+
E.ERR_THEME_BAD_VALUE,
|
|
1192
|
+
`${name} is a ${type}; the calc() in "${value}" cannot be worked out: ${math} (with each var() at its fallback, as when the variable is unset), so the browser drops the value.`,
|
|
1193
|
+
{run: [`${HOW} ${name}`]},
|
|
1194
|
+
);
|
|
824
1195
|
// A var() inside a larger value (calc, max, color-mix) has a fallback of
|
|
825
1196
|
// the token's kind too, checked like a whole-value var().
|
|
826
1197
|
if (type !== 'other')
|
|
@@ -834,6 +1205,16 @@ function checkTypedValue(
|
|
|
834
1205
|
)
|
|
835
1206
|
)
|
|
836
1207
|
continue;
|
|
1208
|
+
// A factor in a size's math (`calc(0.75rem * var(--x, 1))`, as the
|
|
1209
|
+
// official themes write their type scale): a plain number there is
|
|
1210
|
+
// what multiplies the size.
|
|
1211
|
+
if (
|
|
1212
|
+
type === 'size' &&
|
|
1213
|
+
within.some(f => /^(calc|min|max|clamp)$/i.test(f)) &&
|
|
1214
|
+
/^[+-]?(\d+\.?\d*|\.\d+)$/.test(fallback.trim()) &&
|
|
1215
|
+
(/[*/]\s*var\(/i.test(value) || /var\([^()]*\)\s*[*/]/i.test(value))
|
|
1216
|
+
)
|
|
1217
|
+
continue;
|
|
837
1218
|
if (fallback === '')
|
|
838
1219
|
refuse(
|
|
839
1220
|
E.ERR_THEME_BAD_VALUE,
|
|
@@ -896,19 +1277,11 @@ function checkTypedValue(
|
|
|
896
1277
|
);
|
|
897
1278
|
return;
|
|
898
1279
|
}
|
|
899
|
-
if (type === 'color' && !isFixedColor(value)) bad('a color',
|
|
1280
|
+
if (type === 'color' && !isFixedColor(value)) bad('a color', null);
|
|
900
1281
|
if (type === 'size' && !isSize(value, name)) {
|
|
901
|
-
//
|
|
902
|
-
//
|
|
903
|
-
|
|
904
|
-
let own = String(TOKENS[name] ?? '').trim();
|
|
905
|
-
for (let hop = 0; hop < 4; hop += 1) {
|
|
906
|
-
const ref = /^var\(\s*(--[a-z0-9-]+)\s*\)$/i.exec(own)?.[1];
|
|
907
|
-
if (!ref) break;
|
|
908
|
-
own = String(TOKENS[ref] ?? '').trim();
|
|
909
|
-
}
|
|
910
|
-
const sizeExample =
|
|
911
|
-
own && isSize(own, name) && !/var\(/.test(own) ? own : '6px';
|
|
1282
|
+
// The token's own default is never offered as a repair: only a size
|
|
1283
|
+
// read from the value typed.
|
|
1284
|
+
const sizeExample = null;
|
|
912
1285
|
// The size meant, when one dot or sign is all that is wrong (1.px).
|
|
913
1286
|
const meant = value.trim().replace(/(\d)\.(?=[a-z%]|$)/gi, '$1');
|
|
914
1287
|
// A bare number is the size in px.
|
|
@@ -1231,6 +1604,15 @@ function nearestColorName(v) {
|
|
|
1231
1604
|
return nearest(w, COLOR_NAMES)[0] ?? null;
|
|
1232
1605
|
}
|
|
1233
1606
|
|
|
1607
|
+
/**
|
|
1608
|
+
* Old keywords a property's grammar lists that no current browser applies,
|
|
1609
|
+
* each with the keyword that does what it meant.
|
|
1610
|
+
* @type {Record<string, Record<string, string>>}
|
|
1611
|
+
*/
|
|
1612
|
+
const OBSOLETE_KEYWORDS = {
|
|
1613
|
+
cursor: {hand: 'pointer'},
|
|
1614
|
+
};
|
|
1615
|
+
|
|
1234
1616
|
/**
|
|
1235
1617
|
* Why a value is not one the property takes, or null. Colors are checked
|
|
1236
1618
|
* by the editor's own color check; a property css-tree has no grammar for
|
|
@@ -1251,6 +1633,14 @@ function propertyProblem(prop, value) {
|
|
|
1251
1633
|
takes: `a value its CSS grammar takes in each var() fallback too (${grammarText(known)})`,
|
|
1252
1634
|
near: initialOf(prop),
|
|
1253
1635
|
};
|
|
1636
|
+
// An old keyword the grammar still lists but no current browser
|
|
1637
|
+
// applies (`cursor: hand`): the keyword that does what it meant.
|
|
1638
|
+
const obsolete = OBSOLETE_KEYWORDS[prop]?.[v.toLowerCase()];
|
|
1639
|
+
if (obsolete)
|
|
1640
|
+
return {
|
|
1641
|
+
takes: `a value current browsers apply ("${v}" is an old keyword none applies; ${obsolete} does what it meant)`,
|
|
1642
|
+
near: obsolete,
|
|
1643
|
+
};
|
|
1254
1644
|
if (matchValue(prop, v))
|
|
1255
1645
|
return belowRange(prop, v)
|
|
1256
1646
|
? {
|
|
@@ -1281,9 +1671,7 @@ function propertyProblem(prop, value) {
|
|
|
1281
1671
|
null)
|
|
1282
1672
|
: null;
|
|
1283
1673
|
// A value that works, for the suggestion: a keyword near the one typed,
|
|
1284
|
-
// the
|
|
1285
|
-
const example = exampleOf(groupOfPropType(prop), prop);
|
|
1286
|
-
const initial = initialOf(prop);
|
|
1674
|
+
// or the value typed cleaned; each checked.
|
|
1287
1675
|
// A bare number on a length property means px (`padding 4` → `4px`, each
|
|
1288
1676
|
// number in a list too), when the property takes that.
|
|
1289
1677
|
// Each bare number token gets px (a mixed list `4 8px`, `8 / 4`, an
|
|
@@ -1296,31 +1684,99 @@ function propertyProblem(prop, value) {
|
|
|
1296
1684
|
Number(num) === 0 ? `${pre}${num}` : `${pre}${num}px`,
|
|
1297
1685
|
)
|
|
1298
1686
|
: null;
|
|
1299
|
-
// A suggestion is offered only when the property takes it, in range too
|
|
1687
|
+
// A suggestion is offered only when the property takes it, in range too,
|
|
1688
|
+
// and never a reset the input did not hold (0, none, 1, auto, normal):
|
|
1689
|
+
// following it would undo what was asked. A reset typed with a typo
|
|
1690
|
+
// (`nnone`, `normall`: a word within two edits of it) is that reset,
|
|
1691
|
+
// corrected.
|
|
1692
|
+
const RESETS =
|
|
1693
|
+
/^(0|0px|none|1|auto|normal|initial|unset|inherit|revert|transparent)$/i;
|
|
1694
|
+
const typedAs = (/** @type {string} */ x) => x === typed || typoOf(typed, x);
|
|
1300
1695
|
const takes = (/** @type {string | null} */ x) =>
|
|
1301
|
-
x != null &&
|
|
1696
|
+
x != null &&
|
|
1697
|
+
matchValue(prop, x) != null &&
|
|
1698
|
+
!belowRange(prop, x) &&
|
|
1699
|
+
!(RESETS.test(x.trim()) && !typedAs(x.trim().toLowerCase()));
|
|
1700
|
+
// A lone length on a shorthand where it is only a position (background,
|
|
1701
|
+
// mask) wipes the rest: no px is guessed there.
|
|
1702
|
+
const pxFits = !/^(background|mask)$/i.test(prop);
|
|
1703
|
+
// Words with a documented reading on a property.
|
|
1704
|
+
const WORDS = /** @type {Record<string, Record<string, string>>} */ ({
|
|
1705
|
+
opacity: {
|
|
1706
|
+
half: '0.5',
|
|
1707
|
+
'half-transparent': '0.5',
|
|
1708
|
+
opaque: '1',
|
|
1709
|
+
solid: '1',
|
|
1710
|
+
},
|
|
1711
|
+
'text-transform': {
|
|
1712
|
+
caps: 'uppercase',
|
|
1713
|
+
'all-caps': 'uppercase',
|
|
1714
|
+
upper: 'uppercase',
|
|
1715
|
+
lower: 'lowercase',
|
|
1716
|
+
title: 'capitalize',
|
|
1717
|
+
'no-caps': 'none',
|
|
1718
|
+
},
|
|
1719
|
+
'border-radius': {
|
|
1720
|
+
round: '9999px',
|
|
1721
|
+
rounded: '9999px',
|
|
1722
|
+
pill: '9999px',
|
|
1723
|
+
circle: '50%',
|
|
1724
|
+
square: '0',
|
|
1725
|
+
},
|
|
1726
|
+
});
|
|
1727
|
+
// A weight word is its number (the same table the headings dial reads);
|
|
1728
|
+
// text in content is that text, quoted.
|
|
1729
|
+
const weightWord = typed.replace(/[\s-]+/g, '');
|
|
1730
|
+
const weight =
|
|
1731
|
+
HEADING_WEIGHTS[weightWord] ??
|
|
1732
|
+
/** @type {Record<string, string>} */ ({
|
|
1733
|
+
thin: '100',
|
|
1734
|
+
extralight: '200',
|
|
1735
|
+
extrabold: '800',
|
|
1736
|
+
ultrabold: '800',
|
|
1737
|
+
black: '900',
|
|
1738
|
+
})[weightWord];
|
|
1739
|
+
const mapped =
|
|
1740
|
+
WORDS[prop]?.[typed.replace(/\s+/g, '-')] ??
|
|
1741
|
+
(prop === 'font-weight' && weight ? weight : null) ??
|
|
1742
|
+
(prop === 'content' && !/^["']|["']$/.test(v) ? JSON.stringify(v) : null) ??
|
|
1743
|
+
null;
|
|
1302
1744
|
return {
|
|
1303
1745
|
takes: `a value its CSS grammar takes (${grammarText(known)})`,
|
|
1304
1746
|
near:
|
|
1305
|
-
(
|
|
1747
|
+
(mapped && matchValue(prop, mapped) != null ? mapped : null) ??
|
|
1748
|
+
(pxFits && takes(withPx) ? withPx : null) ??
|
|
1306
1749
|
// Below the property's range (a negative width): the same, 0 or more.
|
|
1307
|
-
(withPx && takes(withPx.replace(/(^|[\s/(,])-(?=\.?\d)/g, '$1'))
|
|
1750
|
+
(pxFits && withPx && takes(withPx.replace(/(^|[\s/(,])-(?=\.?\d)/g, '$1'))
|
|
1308
1751
|
? withPx.replace(/(^|[\s/(,])-(?=\.?\d)/g, '$1')
|
|
1309
1752
|
: null) ??
|
|
1310
1753
|
(takes(joined) && joined !== v ? joined : null) ??
|
|
1311
1754
|
// Several values on a property that takes one (padding-top with four):
|
|
1312
|
-
// the first of them, when it is one the property takes.
|
|
1755
|
+
// the first of them, when it is one the property takes. Not when the
|
|
1756
|
+
// rest are words (`2 spacing units` is no 2px).
|
|
1313
1757
|
(() => {
|
|
1314
|
-
const
|
|
1315
|
-
|
|
1758
|
+
const all = splitTop((withPx ?? joined).trim(), ' ');
|
|
1759
|
+
if (all.slice(1).some(x => /^[a-z]/i.test(x))) return null;
|
|
1760
|
+
const first = all[0];
|
|
1761
|
+
return pxFits && first && first !== v && takes(first) ? first : null;
|
|
1316
1762
|
})() ??
|
|
1317
1763
|
(near && takes(near) ? near : null) ??
|
|
1318
|
-
//
|
|
1319
|
-
//
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1764
|
+
// Layers typed with one too many or an empty one (`url(a.png), red,
|
|
1765
|
+
// blue`, `red,,blue`): the layers before the last, else one of them,
|
|
1766
|
+
// when the property takes it. Never the property's reset or a stock
|
|
1767
|
+
// example: a repair carries only what was typed.
|
|
1768
|
+
(() => {
|
|
1769
|
+
const layers = splitTop(v.trim(), ',')
|
|
1770
|
+
.map(x => x.trim())
|
|
1771
|
+
.filter(Boolean);
|
|
1772
|
+
if (layers.length < 2 && !/,\s*,/.test(v)) return null;
|
|
1773
|
+
const tries = [
|
|
1774
|
+
layers.join(', '),
|
|
1775
|
+
layers.slice(0, -1).join(', '),
|
|
1776
|
+
...layers,
|
|
1777
|
+
];
|
|
1778
|
+
return tries.find(x => x && x !== v && takes(x)) ?? null;
|
|
1779
|
+
})(),
|
|
1324
1780
|
};
|
|
1325
1781
|
}
|
|
1326
1782
|
|
|
@@ -1387,6 +1843,108 @@ function baseReads(ctx, like, token) {
|
|
|
1387
1843
|
}
|
|
1388
1844
|
}
|
|
1389
1845
|
|
|
1846
|
+
/** State words a value may be labeled with. */
|
|
1847
|
+
const STATE_WORDS = [
|
|
1848
|
+
'hover',
|
|
1849
|
+
'active',
|
|
1850
|
+
'focus',
|
|
1851
|
+
'focus-visible',
|
|
1852
|
+
'focus-within',
|
|
1853
|
+
'disabled',
|
|
1854
|
+
'pressed',
|
|
1855
|
+
'selected',
|
|
1856
|
+
'checked',
|
|
1857
|
+
'open',
|
|
1858
|
+
'expanded',
|
|
1859
|
+
'visited',
|
|
1860
|
+
];
|
|
1861
|
+
/** Words for a kind of screen a value may be labeled with. */
|
|
1862
|
+
const DEVICE_WORDS = [
|
|
1863
|
+
'phone',
|
|
1864
|
+
'phones',
|
|
1865
|
+
'mobile',
|
|
1866
|
+
'tablet',
|
|
1867
|
+
'tablets',
|
|
1868
|
+
'desktop',
|
|
1869
|
+
'laptop',
|
|
1870
|
+
'ipad',
|
|
1871
|
+
'iphone',
|
|
1872
|
+
'android',
|
|
1873
|
+
'ios',
|
|
1874
|
+
'touch',
|
|
1875
|
+
'small-screen',
|
|
1876
|
+
'small-screens',
|
|
1877
|
+
'large-screen',
|
|
1878
|
+
'large-screens',
|
|
1879
|
+
'print',
|
|
1880
|
+
];
|
|
1881
|
+
|
|
1882
|
+
/**
|
|
1883
|
+
* The word a value is labeled with and the value after it (`dark: #2563eb`,
|
|
1884
|
+
* `"corners": "pill"`, `{"dark": "#2563eb"}`, `dark=#2563eb`, `dark mode:
|
|
1885
|
+
* #2563eb`, `textSize: 18`), the word as a dashed name; null when the value
|
|
1886
|
+
* holds no label.
|
|
1887
|
+
* @param {string} value
|
|
1888
|
+
* @returns {{word: string, rest: string, when?: string} | null}
|
|
1889
|
+
*/
|
|
1890
|
+
function valueLabel(value) {
|
|
1891
|
+
// A flag's label after the value (`red mode: dark`, `red state: hover`,
|
|
1892
|
+
// `red part: card`) reads as the same label before it (`dark: red`); a
|
|
1893
|
+
// variant or size after it (`red variant: primary`) keeps its prop.
|
|
1894
|
+
const trail =
|
|
1895
|
+
/^\s*(.+?)\s+(mode|theme|state|part|on|variant|size|when)\s*[:=]\s*([a-z][a-z0-9:-]*)\s*;?\s*$/i.exec(
|
|
1896
|
+
String(value),
|
|
1897
|
+
);
|
|
1898
|
+
if (trail && !/[:=]/.test(trail[1])) {
|
|
1899
|
+
const flag = trail[2].toLowerCase();
|
|
1900
|
+
const word = trail[3].toLowerCase();
|
|
1901
|
+
if (/^(variant|size|when)$/.test(flag))
|
|
1902
|
+
return {
|
|
1903
|
+
word: 'when',
|
|
1904
|
+
rest: trail[1].trim(),
|
|
1905
|
+
when: flag === 'when' ? word : `${flag}:${word}`,
|
|
1906
|
+
};
|
|
1907
|
+
return {word, rest: trail[1].trim()};
|
|
1908
|
+
}
|
|
1909
|
+
const m =
|
|
1910
|
+
/^\s*\{?\s*["']?([a-zA-Z][a-zA-Z0-9 _-]*?|--[a-z0-9-]+)["']?\s*[:=]\s*(.+?)\s*;?\s*\}?\s*$/.exec(
|
|
1911
|
+
String(value),
|
|
1912
|
+
);
|
|
1913
|
+
if (!m || /^https?$/i.test(m[1])) return null;
|
|
1914
|
+
const word = m[1]
|
|
1915
|
+
.trim()
|
|
1916
|
+
.replace(/([a-z0-9])([A-Z])/g, '$1-$2')
|
|
1917
|
+
.replace(/[\s_]+/g, '-')
|
|
1918
|
+
.toLowerCase();
|
|
1919
|
+
const rest = m[2].trim().replace(/^"(.*)"\s*,?$/, '$1');
|
|
1920
|
+
return {word, rest};
|
|
1921
|
+
}
|
|
1922
|
+
|
|
1923
|
+
/**
|
|
1924
|
+
* Whether a label is the setting's own name (`accent: red` for accent,
|
|
1925
|
+
* `font-family: Inter` for font).
|
|
1926
|
+
* @param {string} thing @param {string} word
|
|
1927
|
+
*/
|
|
1928
|
+
const ownLabel = (thing, word) =>
|
|
1929
|
+
word === thing ||
|
|
1930
|
+
(thing === 'font' && word === 'font-family') ||
|
|
1931
|
+
(thing.startsWith('--font-family') &&
|
|
1932
|
+
(word === 'font-family' || word === 'font')) ||
|
|
1933
|
+
(thing === 'text-size' && word === 'font-size');
|
|
1934
|
+
|
|
1935
|
+
/**
|
|
1936
|
+
* The one mode a light-only or dark-only theme shows, or null.
|
|
1937
|
+
* @param {{mode?: string} | null | undefined} data
|
|
1938
|
+
* @returns {'light' | 'dark' | null}
|
|
1939
|
+
*/
|
|
1940
|
+
function oneModeOfTheme(data) {
|
|
1941
|
+
return data?.mode === 'light-only'
|
|
1942
|
+
? 'light'
|
|
1943
|
+
: data?.mode === 'dark-only'
|
|
1944
|
+
? 'dark'
|
|
1945
|
+
: null;
|
|
1946
|
+
}
|
|
1947
|
+
|
|
1390
1948
|
/**
|
|
1391
1949
|
* Check one setting and give it back ready to store, or refuse. What it
|
|
1392
1950
|
* accepts, the settings loader takes too: the loader's own check runs last,
|
|
@@ -1412,8 +1970,397 @@ export function checkSetting(
|
|
|
1412
1970
|
// Any other dial's value pasted with its property name (`font-size:
|
|
1413
1971
|
// 18px;` for text-size, `color: #e11d48` for accent) is the value: one
|
|
1414
1972
|
// path for every dial (the font dial reads its own below).
|
|
1415
|
-
|
|
1416
|
-
|
|
1973
|
+
// A light and a dark color typed as one value: a token takes both as
|
|
1974
|
+
// light-dark() or one --mode at a time; a color dial takes one color and
|
|
1975
|
+
// makes both modes from it. Never one of them for both.
|
|
1976
|
+
// A light-dark() written with another separator (`light-dark(red /
|
|
1977
|
+
// blue)`, `light-dark(red; blue)`): the pair meant, with a comma.
|
|
1978
|
+
if (!unset && typeof value === 'string') {
|
|
1979
|
+
const near =
|
|
1980
|
+
/^\s*light-dark\(\s*([^,;/()]+?)\s*(?:\s\/\s|\/|;)\s*([^,;/()]+?)\s*\)\s*$/i.exec(
|
|
1981
|
+
value,
|
|
1982
|
+
);
|
|
1983
|
+
if (near)
|
|
1984
|
+
refuse(
|
|
1985
|
+
E.ERR_THEME_BAD_VALUE,
|
|
1986
|
+
`"${value}" separates its two colors with something other than a comma; light-dark() takes "light-dark(light, dark)".`,
|
|
1987
|
+
{
|
|
1988
|
+
run: [
|
|
1989
|
+
setLine(
|
|
1990
|
+
slug,
|
|
1991
|
+
thing,
|
|
1992
|
+
`light-dark(${near[1]}, ${near[2]})`,
|
|
1993
|
+
{...flags, mode: undefined},
|
|
1994
|
+
false,
|
|
1995
|
+
),
|
|
1996
|
+
],
|
|
1997
|
+
},
|
|
1998
|
+
);
|
|
1999
|
+
}
|
|
2000
|
+
// A number or size given as a font family (`--font-family-body 700`,
|
|
2001
|
+
// `font-family 16px --on card`) is a weight or a size, never a family.
|
|
2002
|
+
if (
|
|
2003
|
+
!unset &&
|
|
2004
|
+
typeof value === 'string' &&
|
|
2005
|
+
(thing === 'font-family' || thing.startsWith('--font-family')) &&
|
|
2006
|
+
NUMBERISH.test(value.trim())
|
|
2007
|
+
)
|
|
2008
|
+
refuse(
|
|
2009
|
+
E.ERR_THEME_BAD_VALUE,
|
|
2010
|
+
`"${value.trim()}" is a ${/[a-z%]$/i.test(value.trim()) ? 'size' : 'weight'}, not a font family: ${thing} names families (such as Inter, serif). ${/[a-z%]$/i.test(value.trim()) ? 'A text size is set with text-size or a --font-size-* token.' : 'A weight is set with font-weight or a --font-weight-* token.'}`,
|
|
2011
|
+
{run: [`${HOW} ${quoteCommandArgument(thing)}`]},
|
|
2012
|
+
);
|
|
2013
|
+
// A font list with a comma missing before its generic family, or a
|
|
2014
|
+
// generic written with a space, on the font dial: the list meant.
|
|
2015
|
+
if (!unset && typeof value === 'string' && thing === 'font') {
|
|
2016
|
+
const fixed = fontListMeant(value);
|
|
2017
|
+
if (fixed)
|
|
2018
|
+
refuse(
|
|
2019
|
+
E.ERR_THEME_BAD_VALUE,
|
|
2020
|
+
`"${value}" names a family that exists nowhere: ${fixed.why}.`,
|
|
2021
|
+
{run: [setLine(slug, 'font', fixed.value, flags, false)]},
|
|
2022
|
+
);
|
|
2023
|
+
}
|
|
2024
|
+
// A light and a dark color on a part's color property (`background`,
|
|
2025
|
+
// `color`, `border-color` …) is that property's light-dark() pair.
|
|
2026
|
+
if (
|
|
2027
|
+
!unset &&
|
|
2028
|
+
typeof value === 'string' &&
|
|
2029
|
+
flags.on &&
|
|
2030
|
+
!flags.mode &&
|
|
2031
|
+
/^(color|background|(background|border|outline|text-decoration|caret|accent|fill|stroke)(-[a-z]+)?-color)$/.test(
|
|
2032
|
+
String(thing).trim().toLowerCase(),
|
|
2033
|
+
)
|
|
2034
|
+
) {
|
|
2035
|
+
const pair = colorPair(value);
|
|
2036
|
+
if (pair && !colorProblem(pair.light) && !colorProblem(pair.dark))
|
|
2037
|
+
value = `light-dark(${pair.light}, ${pair.dark})`;
|
|
2038
|
+
}
|
|
2039
|
+
if (
|
|
2040
|
+
!unset &&
|
|
2041
|
+
typeof value === 'string' &&
|
|
2042
|
+
(PALETTE_DIALS.includes(thing) || isColorToken(thing))
|
|
2043
|
+
) {
|
|
2044
|
+
const pair = colorPair(value);
|
|
2045
|
+
if (pair && !colorProblem(pair.light) && !colorProblem(pair.dark)) {
|
|
2046
|
+
const q = quoteCommandArgument;
|
|
2047
|
+
const on = flags.on ? ` --on ${flags.on}` : '';
|
|
2048
|
+
// A theme with one mode shows one half: that half is the line.
|
|
2049
|
+
const only = oneModeOfTheme(data);
|
|
2050
|
+
if (only)
|
|
2051
|
+
refuse(
|
|
2052
|
+
E.ERR_THEME_BAD_VALUE,
|
|
2053
|
+
`"${value}" is a light and a dark color; this theme is ${only} only, so it shows the ${only} one.`,
|
|
2054
|
+
{run: [`${P} set ${slug} ${thing} ${q(pair[only])}${on}`]},
|
|
2055
|
+
);
|
|
2056
|
+
refuse(
|
|
2057
|
+
E.ERR_THEME_BAD_VALUE,
|
|
2058
|
+
PALETTE_DIALS.includes(thing)
|
|
2059
|
+
? `"${value}" is a light and a dark color; ${thing} takes one color and makes both modes from it.`
|
|
2060
|
+
: `"${value}" is a light and a dark color; ${thing} takes them as light-dark(), or one --mode at a time.`,
|
|
2061
|
+
{
|
|
2062
|
+
run: PALETTE_DIALS.includes(thing)
|
|
2063
|
+
? [
|
|
2064
|
+
`${P} set ${slug} ${thing} ${q(pair.light)}${on}`,
|
|
2065
|
+
...(thing === 'accent'
|
|
2066
|
+
? [
|
|
2067
|
+
`${P} set ${slug} --color-accent ${q(`light-dark(${pair.light}, ${pair.dark})`)}${on}`,
|
|
2068
|
+
]
|
|
2069
|
+
: []),
|
|
2070
|
+
]
|
|
2071
|
+
: [
|
|
2072
|
+
`${P} set ${slug} ${thing} ${q(`light-dark(${pair.light}, ${pair.dark})`)}${on}`,
|
|
2073
|
+
`${P} set ${slug} ${thing} ${q(pair.light)}${on} --mode light`,
|
|
2074
|
+
`${P} set ${slug} ${thing} ${q(pair.dark)}${on} --mode dark`,
|
|
2075
|
+
],
|
|
2076
|
+
},
|
|
2077
|
+
);
|
|
2078
|
+
}
|
|
2079
|
+
}
|
|
2080
|
+
// A value labeled with a word that is not this setting's own name (a
|
|
2081
|
+
// mode, a state, a device, a part, or a word the editor does not read) is
|
|
2082
|
+
// refused with what that word means here, never set with the word dropped.
|
|
2083
|
+
// A property set on a part (`padding 'hover: 4px' --on button`) and the
|
|
2084
|
+
// type tokens (`--font-weight-bold 'dark: 700'`) are read the same way;
|
|
2085
|
+
// a content string is its own text.
|
|
2086
|
+
const partProperty =
|
|
2087
|
+
Boolean(flags.on) && !DIALS[thing] && !thing.startsWith('--');
|
|
2088
|
+
const familyToken = thing.startsWith('--font-family');
|
|
2089
|
+
if (
|
|
2090
|
+
!unset &&
|
|
2091
|
+
typeof value === 'string' &&
|
|
2092
|
+
!/content/.test(thing) &&
|
|
2093
|
+
(DIALS[thing] || partProperty || thing.startsWith('--'))
|
|
2094
|
+
) {
|
|
2095
|
+
const label = valueLabel(value);
|
|
2096
|
+
// A CSS property's name before the value (`border-radius: pill`,
|
|
2097
|
+
// `color: #e11d48`, `font: bold 16px Inter`) is read by the paths
|
|
2098
|
+
// below, as a declaration pasted from a stylesheet.
|
|
2099
|
+
if (
|
|
2100
|
+
label &&
|
|
2101
|
+
!ownLabel(thing, label.word) &&
|
|
2102
|
+
!cssProperties().has(label.word)
|
|
2103
|
+
) {
|
|
2104
|
+
const q = quoteCommandArgument;
|
|
2105
|
+
const rest = label.rest;
|
|
2106
|
+
const scope = `${flags.on ? ` --on ${flags.on}` : ''}${flags.when ? ` --when ${flags.when}` : ''}`;
|
|
2107
|
+
// A variant named after the value: the value with --when.
|
|
2108
|
+
if ('when' in label && label.when)
|
|
2109
|
+
refuse(
|
|
2110
|
+
E.ERR_THEME_BAD_VALUE,
|
|
2111
|
+
`"${value}" names a variant after the value; a value for one variant is given with --on <part> --when ${label.when}.`,
|
|
2112
|
+
{
|
|
2113
|
+
didYouMean: ['--when'],
|
|
2114
|
+
run: [
|
|
2115
|
+
flags.on
|
|
2116
|
+
? `${P} set ${slug} ${thing} ${q(rest)} --on ${flags.on} --when ${label.when}`
|
|
2117
|
+
: `${HOW} ${q(`${label.when.split(':').pop()} ${thing}`)}`,
|
|
2118
|
+
],
|
|
2119
|
+
},
|
|
2120
|
+
);
|
|
2121
|
+
const mode = MODE_WORDS[label.word];
|
|
2122
|
+
const colorful =
|
|
2123
|
+
PALETTE_DIALS.includes(thing) ||
|
|
2124
|
+
(thing.startsWith('--') && isColorToken(thing)) ||
|
|
2125
|
+
(partProperty &&
|
|
2126
|
+
/color|^background$|^fill$|^stroke$|shadow/.test(thing));
|
|
2127
|
+
const parts = [...ctx.project.target.keys(), ...Object.keys(FAMILIES)];
|
|
2128
|
+
// A theme with one mode: its own mode's label is the value, as the
|
|
2129
|
+
// theme has no other; the other mode's label names a mode it lacks.
|
|
2130
|
+
const only = oneModeOfTheme(data);
|
|
2131
|
+
if (mode && only) {
|
|
2132
|
+
if (mode === only)
|
|
2133
|
+
return checkSetting(ctx, slug, data, thing, rest, flags, unset);
|
|
2134
|
+
refuse(
|
|
2135
|
+
E.ERR_THEME_BAD_VALUE,
|
|
2136
|
+
`"${label.word}" in "${value}" names the ${mode} mode, which this ${only}-only theme does not show.`,
|
|
2137
|
+
{
|
|
2138
|
+
run: [
|
|
2139
|
+
`${P} set ${slug} mode both`,
|
|
2140
|
+
`${P} set ${slug} ${thing} ${q(rest)}${scope}`,
|
|
2141
|
+
],
|
|
2142
|
+
},
|
|
2143
|
+
);
|
|
2144
|
+
}
|
|
2145
|
+
if (mode && DIALS[thing] && PALETTE_DIALS.includes(thing))
|
|
2146
|
+
refuse(
|
|
2147
|
+
E.ERR_THEME_BAD_VALUE,
|
|
2148
|
+
`"${label.word}" in "${value}" names the ${mode} mode; ${thing} makes both modes from one color.`,
|
|
2149
|
+
{
|
|
2150
|
+
run: [
|
|
2151
|
+
`${P} set ${slug} ${thing} ${q(rest)}${scope}`,
|
|
2152
|
+
...(thing === 'accent'
|
|
2153
|
+
? [
|
|
2154
|
+
`${P} set ${slug} --color-accent ${q(rest)}${scope} --mode ${mode}`,
|
|
2155
|
+
]
|
|
2156
|
+
: []),
|
|
2157
|
+
],
|
|
2158
|
+
},
|
|
2159
|
+
);
|
|
2160
|
+
const level = /^h([1-6])$/.exec(label.word)?.[1];
|
|
2161
|
+
if (level && thing === 'headings') {
|
|
2162
|
+
const w = rest.trim().toLowerCase();
|
|
2163
|
+
refuse(
|
|
2164
|
+
E.ERR_THEME_BAD_VALUE,
|
|
2165
|
+
`"${label.word}" in "${value}" is one heading level; headings sets every level, and one level is set with --on heading --when level:${level}.`,
|
|
2166
|
+
{
|
|
2167
|
+
run:
|
|
2168
|
+
HEADING_WEIGHTS[w] !== undefined
|
|
2169
|
+
? [
|
|
2170
|
+
`${P} set ${slug} font-weight ${HEADING_WEIGHTS[w]} --on heading --when level:${level}`,
|
|
2171
|
+
`${P} set ${slug} headings ${w}`,
|
|
2172
|
+
]
|
|
2173
|
+
: HEADING_TRACKING[w] !== undefined
|
|
2174
|
+
? [
|
|
2175
|
+
`${P} set ${slug} letter-spacing ${q(HEADING_TRACKING[w])} --on heading --when level:${level}`,
|
|
2176
|
+
`${P} set ${slug} headings ${w}`,
|
|
2177
|
+
]
|
|
2178
|
+
: [`${HOW} headings`],
|
|
2179
|
+
},
|
|
2180
|
+
);
|
|
2181
|
+
}
|
|
2182
|
+
if (mode)
|
|
2183
|
+
refuse(
|
|
2184
|
+
E.ERR_THEME_BAD_VALUE,
|
|
2185
|
+
colorful
|
|
2186
|
+
? `"${label.word}" in "${value}" names the ${mode} mode; a value for one mode is given with --mode ${mode}.`
|
|
2187
|
+
: `"${label.word}" in "${value}" names the ${mode} mode, and ${thing} is the same in light and dark.`,
|
|
2188
|
+
{
|
|
2189
|
+
run: [
|
|
2190
|
+
`${P} set ${slug} ${thing} ${q(rest)}${scope}${colorful ? ` --mode ${mode}` : ''}`,
|
|
2191
|
+
],
|
|
2192
|
+
},
|
|
2193
|
+
);
|
|
2194
|
+
if (STATE_WORDS.includes(label.word))
|
|
2195
|
+
refuse(
|
|
2196
|
+
E.ERR_THEME_BAD_VALUE,
|
|
2197
|
+
flags.on
|
|
2198
|
+
? `"${label.word}" in "${value}" is a state; a value for it is given with --state ${label.word}.`
|
|
2199
|
+
: `"${label.word}" in "${value}" is a state; a state is set on a part, with --on <part> --state ${label.word}.`,
|
|
2200
|
+
{
|
|
2201
|
+
run: [
|
|
2202
|
+
flags.on
|
|
2203
|
+
? `${P} set ${slug} ${thing} ${q(rest)}${scope} --state ${label.word}`
|
|
2204
|
+
: `${HOW} ${q(`${label.word} ${thing}`)}`,
|
|
2205
|
+
],
|
|
2206
|
+
},
|
|
2207
|
+
);
|
|
2208
|
+
if (DEVICE_WORDS.includes(label.word))
|
|
2209
|
+
refuse(
|
|
2210
|
+
E.ERR_THEME_BAD_VALUE,
|
|
2211
|
+
`"${label.word}" in "${value}" names a kind of screen; the editor sets ${thing} for every screen, not for one kind.`,
|
|
2212
|
+
{run: [`${P} set ${slug} ${thing} ${q(rest)}${scope}`]},
|
|
2213
|
+
);
|
|
2214
|
+
// `on button: pill`: the part named after `on`.
|
|
2215
|
+
const onPart = /^on-([a-z][a-z0-9-]*)$/.exec(label.word)?.[1];
|
|
2216
|
+
if (onPart && parts.includes(onPart))
|
|
2217
|
+
refuse(
|
|
2218
|
+
E.ERR_THEME_BAD_VALUE,
|
|
2219
|
+
`"${value}" names the part ${onPart}; a value for one part is given with --on ${onPart}.`,
|
|
2220
|
+
{run: [`${P} set ${slug} ${thing} ${q(rest)} --on ${onPart}`]},
|
|
2221
|
+
);
|
|
2222
|
+
if (parts.includes(label.word))
|
|
2223
|
+
refuse(
|
|
2224
|
+
E.ERR_THEME_BAD_VALUE,
|
|
2225
|
+
`"${label.word}" in "${value}" is a part; a value for one part is given with --on ${label.word}.`,
|
|
2226
|
+
{run: [`${P} set ${slug} ${thing} ${q(rest)} --on ${label.word}`]},
|
|
2227
|
+
);
|
|
2228
|
+
// A flag's own name as the label (`state: hover`, `part: card`,
|
|
2229
|
+
// `variant: primary`, `mode: dark`): what that flag does here.
|
|
2230
|
+
const flagWord = {
|
|
2231
|
+
state: 'state',
|
|
2232
|
+
states: 'state',
|
|
2233
|
+
part: 'on',
|
|
2234
|
+
on: 'on',
|
|
2235
|
+
component: 'on',
|
|
2236
|
+
variant: 'when',
|
|
2237
|
+
size: 'when',
|
|
2238
|
+
when: 'when',
|
|
2239
|
+
prop: 'when',
|
|
2240
|
+
mode: 'mode',
|
|
2241
|
+
theme: 'mode',
|
|
2242
|
+
}[label.word];
|
|
2243
|
+
if (
|
|
2244
|
+
flagWord &&
|
|
2245
|
+
(flagWord === 'mode'
|
|
2246
|
+
? Boolean(MODE_WORDS[rest.trim().toLowerCase()])
|
|
2247
|
+
: !otherSettingLabel(thing, value))
|
|
2248
|
+
) {
|
|
2249
|
+
const r = rest.trim().toLowerCase();
|
|
2250
|
+
// The flag's value and the setting's value in one (`state=hover
|
|
2251
|
+
// 4px`): the first word is the flag's, the rest the value.
|
|
2252
|
+
const [fv, ...more] = rest.trim().split(/\s+/);
|
|
2253
|
+
if (flagWord !== 'mode' && more.length > 0) {
|
|
2254
|
+
const flagged =
|
|
2255
|
+
flagWord === 'on'
|
|
2256
|
+
? ` --on ${fv}${flags.when ? ` --when ${flags.when}` : ''}`
|
|
2257
|
+
: flags.on
|
|
2258
|
+
? `${scope} --${flagWord} ${flagWord === 'when' && label.word !== 'when' && label.word !== 'prop' ? `${label.word}:${fv}` : fv}`
|
|
2259
|
+
: null;
|
|
2260
|
+
refuse(
|
|
2261
|
+
E.ERR_THEME_BAD_VALUE,
|
|
2262
|
+
`"${value}" holds the ${flagWord} ${fv} and the value ${more.join(' ')}; the ${flagWord} is given with --${flagWord}.`,
|
|
2263
|
+
{
|
|
2264
|
+
didYouMean: [`--${flagWord}`],
|
|
2265
|
+
run: [
|
|
2266
|
+
flagged
|
|
2267
|
+
? `${P} set ${slug} ${thing} ${q(more.join(' '))}${flagged}`
|
|
2268
|
+
: `${HOW} ${q(`${fv} ${thing}`)}`,
|
|
2269
|
+
],
|
|
2270
|
+
},
|
|
2271
|
+
);
|
|
2272
|
+
}
|
|
2273
|
+
const m = flagWord === 'mode' ? MODE_WORDS[r] : null;
|
|
2274
|
+
const when =
|
|
2275
|
+
flagWord === 'when'
|
|
2276
|
+
? label.word === 'when' || label.word === 'prop'
|
|
2277
|
+
? r
|
|
2278
|
+
: `${label.word}:${r}`
|
|
2279
|
+
: null;
|
|
2280
|
+
refuse(
|
|
2281
|
+
E.ERR_THEME_BAD_VALUE,
|
|
2282
|
+
flagWord === 'mode'
|
|
2283
|
+
? `"${value}" names ${m ? `the ${m} mode` : 'a mode'}, not a value for ${thing}: ${colorful ? `a value for one mode is given with --mode ${m ?? 'dark'}` : `a theme for one mode is set with \`set ${slug} mode ${m ?? 'dark'}-only\``}.`
|
|
2284
|
+
: flagWord === 'state'
|
|
2285
|
+
? `"${value}" names a state, not a value for ${thing}: a value for a state is given with --on <part> --state ${r}.`
|
|
2286
|
+
: flagWord === 'on'
|
|
2287
|
+
? `"${value}" names a part, not a value for ${thing}: a value for one part is given with --on ${r}.`
|
|
2288
|
+
: `"${value}" names a variant, not a value for ${thing}: a value for one variant is given with --on <part> --when ${when}.`,
|
|
2289
|
+
{
|
|
2290
|
+
didYouMean: [`--${flagWord}`],
|
|
2291
|
+
run: [
|
|
2292
|
+
flagWord === 'mode' && !colorful
|
|
2293
|
+
? `${P} set ${slug} mode ${m ?? 'dark'}-only`
|
|
2294
|
+
: `${HOW} ${q(`${r} ${thing}`)}`,
|
|
2295
|
+
],
|
|
2296
|
+
},
|
|
2297
|
+
);
|
|
2298
|
+
}
|
|
2299
|
+
// A family's own words may hold a colon; only the words above are
|
|
2300
|
+
// read there.
|
|
2301
|
+
if (!familyToken && !otherSettingLabel(thing, value))
|
|
2302
|
+
refuse(
|
|
2303
|
+
E.ERR_THEME_BAD_VALUE,
|
|
2304
|
+
`"${label.word}" in "${value}" is not a name the editor reads for ${thing}; give the value alone.`,
|
|
2305
|
+
{
|
|
2306
|
+
didYouMean: nearest(label.word, [
|
|
2307
|
+
...Object.keys(DIALS),
|
|
2308
|
+
...parts,
|
|
2309
|
+
...STATE_WORDS,
|
|
2310
|
+
]),
|
|
2311
|
+
run: [`${P} set ${slug} ${thing} ${q(rest)}${scope}`],
|
|
2312
|
+
},
|
|
2313
|
+
);
|
|
2314
|
+
}
|
|
2315
|
+
// The setting's own name before its value (`font: Inter`, `Font:
|
|
2316
|
+
// Georgia`) is the value.
|
|
2317
|
+
// (A `font:` shorthand is read whole below, as its family.)
|
|
2318
|
+
if (
|
|
2319
|
+
label &&
|
|
2320
|
+
ownLabel(thing, label.word) &&
|
|
2321
|
+
// A `font:` with a size is the shorthand, read whole below; with
|
|
2322
|
+
// only families (`font: Inter, serif`) it is the label.
|
|
2323
|
+
(label.word !== 'font' || !/\d/.test(label.rest)) &&
|
|
2324
|
+
label.rest.replace(/;+\s*$/, '').trim()
|
|
2325
|
+
)
|
|
2326
|
+
value = label.rest;
|
|
2327
|
+
}
|
|
2328
|
+
if (
|
|
2329
|
+
!unset &&
|
|
2330
|
+
typeof value === 'string' &&
|
|
2331
|
+
(DIALS[thing] || partProperty || thing.startsWith('--')) &&
|
|
2332
|
+
!/content/.test(thing)
|
|
2333
|
+
) {
|
|
2334
|
+
// A value labeled with another setting's name is that setting's, never
|
|
2335
|
+
// this one's (`accent 'neutral: #64748b'`, `--radius-element 'accent:
|
|
2336
|
+
// red'`). The value goes to this setting again only for a dial that
|
|
2337
|
+
// checks it as its own (any word is a font family, so never the font).
|
|
2338
|
+
const other = otherSettingLabel(thing, value);
|
|
2339
|
+
if (other)
|
|
2340
|
+
refuse(
|
|
2341
|
+
E.ERR_THEME_BAD_VALUE,
|
|
2342
|
+
`"${value}" is labeled ${other.thing}, another setting than ${thing}; nothing is set from it.`,
|
|
2343
|
+
{
|
|
2344
|
+
didYouMean: [other.thing],
|
|
2345
|
+
run: [
|
|
2346
|
+
`${P} set ${slug} ${other.thing} ${quoteCommandArgument(other.value)}${flags.on ? ` --on ${flags.on}` : ''}`,
|
|
2347
|
+
// Another setting is not this part's property: the whole theme.
|
|
2348
|
+
...(flags.on && partProperty
|
|
2349
|
+
? [
|
|
2350
|
+
`${P} set ${slug} ${other.thing} ${quoteCommandArgument(other.value)}`,
|
|
2351
|
+
]
|
|
2352
|
+
: []),
|
|
2353
|
+
...(DIALS[thing] && thing !== 'font'
|
|
2354
|
+
? [
|
|
2355
|
+
`${P} set ${slug} ${thing} ${quoteCommandArgument(other.value)}${flags.on ? ` --on ${flags.on}` : ''}`,
|
|
2356
|
+
]
|
|
2357
|
+
: []),
|
|
2358
|
+
],
|
|
2359
|
+
},
|
|
2360
|
+
);
|
|
2361
|
+
}
|
|
2362
|
+
if (!unset && typeof value === 'string' && DIALS[thing]) {
|
|
2363
|
+
const d = thing === 'font' ? null : pastedDeclaration(value);
|
|
1417
2364
|
if (d?.value) value = d.value;
|
|
1418
2365
|
}
|
|
1419
2366
|
// The font dial's value as pasted from a stylesheet (`Georgia, serif;`,
|
|
@@ -1485,8 +2432,8 @@ export function checkSetting(
|
|
|
1485
2432
|
function fallbackVarTypo(v, TOKENS) {
|
|
1486
2433
|
for (const [, name] of v.matchAll(/var\(\s*(--[a-z0-9-]+)\s*,/gi)) {
|
|
1487
2434
|
if (name in TOKENS || name.startsWith('--_')) continue;
|
|
1488
|
-
const near = nearest(name, Object.keys(TOKENS)).filter(
|
|
1489
|
-
|
|
2435
|
+
const near = nearest(name, Object.keys(TOKENS)).filter(n =>
|
|
2436
|
+
typoNear(name, n),
|
|
1490
2437
|
);
|
|
1491
2438
|
if (near.length)
|
|
1492
2439
|
return `${name} is not a design token, so its fallback always shows; did you mean ${near[0]}?`;
|
|
@@ -1628,23 +2575,71 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
1628
2575
|
.toLowerCase();
|
|
1629
2576
|
if (flags.only) s.only = true;
|
|
1630
2577
|
if (flags.mode) {
|
|
1631
|
-
|
|
1632
|
-
|
|
2578
|
+
// Read as any value is: invisible or no-break spaces, quotes around
|
|
2579
|
+
// it, a trailing colon (`'dark '`, `“dark”`, `dark:`).
|
|
2580
|
+
const mode = withoutDebris(normalValueText(String(flags.mode)))
|
|
2581
|
+
.trim()
|
|
2582
|
+
.replace(/^(["'])(.*)\1$/, '$2')
|
|
2583
|
+
.replace(/:+$/, '')
|
|
2584
|
+
.trim()
|
|
2585
|
+
.toLowerCase();
|
|
2586
|
+
if (mode !== 'light' && mode !== 'dark') {
|
|
2587
|
+
// A word for one of the two (night, day) is that one; never the
|
|
2588
|
+
// nearest spelling, which can be the other (night → light).
|
|
2589
|
+
const meant = {
|
|
2590
|
+
night: 'dark',
|
|
2591
|
+
nighttime: 'dark',
|
|
2592
|
+
dim: 'dark',
|
|
2593
|
+
black: 'dark',
|
|
2594
|
+
day: 'light',
|
|
2595
|
+
daytime: 'light',
|
|
2596
|
+
bright: 'light',
|
|
2597
|
+
white: 'light',
|
|
2598
|
+
}[mode];
|
|
2599
|
+
const near = meant ? [meant] : nearest(mode, ['light', 'dark']);
|
|
2600
|
+
// The line for that one mode: for a dial, the one `--mode dark` itself
|
|
2601
|
+
// offers (the color token for that mode), never the both-modes dial.
|
|
2602
|
+
const modeLine = (/** @type {string} */ m) => {
|
|
2603
|
+
if (DIALS[thing] && !unset)
|
|
2604
|
+
try {
|
|
2605
|
+
checkSetting(ctx, slug, data, thing, v, {...flags, mode: m});
|
|
2606
|
+
} catch (e) {
|
|
2607
|
+
const first = /** @type {any} */ (e)?.suggestions?.find(
|
|
2608
|
+
(/** @type {any} */ x) => / --mode (light|dark)\b/.test(x.name),
|
|
2609
|
+
);
|
|
2610
|
+
if (first) return first.name;
|
|
2611
|
+
}
|
|
2612
|
+
return setLine(slug, thing, v, {...s, mode: m}, unset);
|
|
2613
|
+
};
|
|
1633
2614
|
refuse(
|
|
1634
2615
|
E.ERR_THEME_BAD_VALUE,
|
|
1635
2616
|
`--mode takes light or dark, not "${flags.mode}".`,
|
|
1636
2617
|
{
|
|
1637
|
-
didYouMean:
|
|
1638
|
-
// The
|
|
1639
|
-
//
|
|
1640
|
-
run: [
|
|
2618
|
+
didYouMean: near,
|
|
2619
|
+
// The mode it is nearest keeps --mode; only with none near is the
|
|
2620
|
+
// same setting for both modes offered.
|
|
2621
|
+
run: [
|
|
2622
|
+
...(near.length === 1 ? [modeLine(near[0])] : []),
|
|
2623
|
+
// A word that means one mode (night) keeps it: the both-modes
|
|
2624
|
+
// line only for a word read by spelling.
|
|
2625
|
+
...(meant
|
|
2626
|
+
? []
|
|
2627
|
+
: [setLine(slug, thing, v, {...s, mode: undefined}, unset)]),
|
|
2628
|
+
],
|
|
1641
2629
|
},
|
|
1642
2630
|
);
|
|
2631
|
+
}
|
|
1643
2632
|
s.mode = mode;
|
|
1644
2633
|
}
|
|
1645
2634
|
const onFlag = s.on ? ` --on ${s.on}` : '';
|
|
1646
|
-
// A value that already gives both modes takes no --mode
|
|
1647
|
-
|
|
2635
|
+
// A value that already gives both modes takes no --mode (a gradient
|
|
2636
|
+
// holding a light-dark() stop included).
|
|
2637
|
+
if (
|
|
2638
|
+
s.mode &&
|
|
2639
|
+
!unset &&
|
|
2640
|
+
(/^\s*light-dark\(/i.test(v ?? '') ||
|
|
2641
|
+
(/gradient\(/i.test(v ?? '') && /light-dark\(/i.test(v ?? '')))
|
|
2642
|
+
)
|
|
1648
2643
|
refuse(
|
|
1649
2644
|
E.ERR_THEME_NO_MODE,
|
|
1650
2645
|
`"${v}" already gives both modes, so it takes no --mode; drop --mode, or give the ${s.mode} color alone.`,
|
|
@@ -1655,11 +2650,35 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
1655
2650
|
},
|
|
1656
2651
|
);
|
|
1657
2652
|
// A setting saved for a mode the theme no longer has can still be removed.
|
|
1658
|
-
|
|
2653
|
+
// An entry saved for the one mode the theme has ("[dark only]" in a
|
|
2654
|
+
// dark-only theme) can be set again with that --mode, so a doubled one
|
|
2655
|
+
// can be kept: that set replaces both.
|
|
2656
|
+
const sameModeEntry =
|
|
2657
|
+
s.mode &&
|
|
2658
|
+
data.mode === `${s.mode}-only` &&
|
|
2659
|
+
(Array.isArray(data.settings) ? data.settings : []).some(
|
|
2660
|
+
(/** @type {any} */ x) =>
|
|
2661
|
+
x &&
|
|
2662
|
+
x.thing === thing &&
|
|
2663
|
+
x.mode === s.mode &&
|
|
2664
|
+
(x.on ?? null) === (s.on ?? null) &&
|
|
2665
|
+
(x.when ?? null) === (s.when ?? null) &&
|
|
2666
|
+
(x.state ?? null) === (s.state ?? null),
|
|
2667
|
+
);
|
|
2668
|
+
if (s.mode && data.mode !== 'both' && !unset && !sameModeEntry)
|
|
1659
2669
|
refuse(
|
|
1660
2670
|
E.ERR_THEME_NO_MODE,
|
|
1661
2671
|
`This theme is ${data.mode}; --mode is for themes with both modes.`,
|
|
1662
|
-
{
|
|
2672
|
+
{
|
|
2673
|
+
run: [
|
|
2674
|
+
// For the mode the theme does not show, both modes first; the
|
|
2675
|
+
// same setting for the theme's own mode keeps where it applies.
|
|
2676
|
+
...((data.mode === 'light-only' ? 'light' : 'dark') !== s.mode
|
|
2677
|
+
? [`${P} set ${slug} mode both`]
|
|
2678
|
+
: []),
|
|
2679
|
+
`${P} set ${slug} ${thing} ${quoteCommandArgument(v)}${onFlag}${s.when ? ` --when ${s.when}` : ''}${s.state ? ` --state ${s.state}` : ''}`,
|
|
2680
|
+
],
|
|
2681
|
+
},
|
|
1663
2682
|
);
|
|
1664
2683
|
if ((s.when || s.state) && !s.on)
|
|
1665
2684
|
refuse(E.ERR_MISSING_ARGUMENT, '--when and --state need --on <part>.', {
|
|
@@ -1693,29 +2712,91 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
1693
2712
|
// Another case of a part or group, its class name copied from the
|
|
1694
2713
|
// page (`.astryx-card`), or its component (`<Card>`, `Card`): that
|
|
1695
2714
|
// part, as a working command with every flag kept.
|
|
2715
|
+
// Stray punctuation from a copied list ("text-input,") and the dashes
|
|
2716
|
+
// autocorrect types ("text\u2013input") are not part of the name.
|
|
1696
2717
|
const lower = s.on
|
|
2718
|
+
.replace(/[\u2010-\u2015\u2212]/g, '-')
|
|
2719
|
+
.replace(/^[\s,;:.'"`]+|[\s,;:.'"`]+$/g, '')
|
|
1697
2720
|
.trim()
|
|
1698
2721
|
.replace(/^<\/?\s*|\s*\/?>$/g, '')
|
|
1699
2722
|
.replace(/^\./, '')
|
|
1700
2723
|
.replace(/^astryx-/, '')
|
|
1701
2724
|
.replace(/([a-z0-9])([A-Z])/g, '$1-$2')
|
|
1702
2725
|
.toLowerCase();
|
|
2726
|
+
// A part named in words (dialog header, text inputs) is the dashed
|
|
2727
|
+
// part, read before any group a single word of it names.
|
|
2728
|
+
const dashed = lower.trim().replace(/[\s_]+/g, '-');
|
|
1703
2729
|
// A plain word how reads as a part or group (checkboxes: checks).
|
|
1704
2730
|
const byWord = partForWord(lower);
|
|
1705
2731
|
// A plain plural of a part (cards, dialogs, tabs) is that part.
|
|
1706
|
-
const singular = [
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
2732
|
+
const singular = [lower, dashed]
|
|
2733
|
+
.flatMap(w => [
|
|
2734
|
+
w.replace(/ies$/, 'y'),
|
|
2735
|
+
w.replace(/(ch|sh|x|s)es$/, '$1'),
|
|
2736
|
+
w.replace(/s$/, ''),
|
|
2737
|
+
])
|
|
2738
|
+
.find(x => x !== lower && (TARGET.has(x) || FAMILIES[x]));
|
|
2739
|
+
// Several parts named in one --on (`button, text-input`, `button/
|
|
2740
|
+
// text-input`, `button and text-input`, or spaces): one command per
|
|
2741
|
+
// part named, each checked, never a group that one word of the list
|
|
2742
|
+
// happens to name.
|
|
2743
|
+
const listed = /,|\/|&|\band\b/.test(lower);
|
|
2744
|
+
// (Words with only spaces that name one part, `text inputs`, are
|
|
2745
|
+
// that part.)
|
|
2746
|
+
if (!(TARGET.has(dashed) || FAMILIES[dashed]) && (listed || !singular)) {
|
|
2747
|
+
const pieces = lower
|
|
2748
|
+
.split(/\s*(?:,|\/|&|\band\b)\s*|\s+/)
|
|
2749
|
+
.map(x => x.trim())
|
|
2750
|
+
.filter(Boolean);
|
|
2751
|
+
const partOf = (/** @type {string} */ w) =>
|
|
2752
|
+
TARGET.has(w) || FAMILIES[w]
|
|
2753
|
+
? w
|
|
2754
|
+
: ([w.replace(/ies$/, 'y'), w.replace(/s$/, '')].find(
|
|
2755
|
+
x => x !== w && (TARGET.has(x) || FAMILIES[x]),
|
|
2756
|
+
) ?? null);
|
|
2757
|
+
const found = pieces.map(partOf);
|
|
2758
|
+
const parts = [...new Set(found.filter(x => x != null))];
|
|
2759
|
+
const missing = pieces.filter((_, i) => found[i] == null);
|
|
2760
|
+
if (
|
|
2761
|
+
pieces.length > 1 &&
|
|
2762
|
+
parts.length > 0 &&
|
|
2763
|
+
(missing.length === 0 || (listed && parts.length > 1))
|
|
2764
|
+
)
|
|
2765
|
+
refuse(
|
|
2766
|
+
E.ERR_THEME_UNKNOWN_PART,
|
|
2767
|
+
`"${s.on}" names ${pieces.length} parts; --on takes one part at a time${missing.length ? ` (${missing.map(x => `"${x}"`).join(', ')} is not a part you can style)` : ''}.`,
|
|
2768
|
+
{
|
|
2769
|
+
didYouMean: parts,
|
|
2770
|
+
run: parts
|
|
2771
|
+
.slice(0, 6)
|
|
2772
|
+
.map(on => setLine(slug, thing, v, {...s, on}, unset)),
|
|
2773
|
+
},
|
|
2774
|
+
);
|
|
2775
|
+
}
|
|
1711
2776
|
const named =
|
|
1712
2777
|
TARGET.has(lower) || FAMILIES[lower]
|
|
1713
2778
|
? lower
|
|
1714
|
-
:
|
|
1715
|
-
?
|
|
1716
|
-
:
|
|
1717
|
-
?
|
|
1718
|
-
:
|
|
2779
|
+
: TARGET.has(dashed) || FAMILIES[dashed]
|
|
2780
|
+
? dashed
|
|
2781
|
+
: singular
|
|
2782
|
+
? singular
|
|
2783
|
+
: byWord && (TARGET.has(byWord) || FAMILIES[byWord])
|
|
2784
|
+
? byWord
|
|
2785
|
+
: null;
|
|
2786
|
+
// The page (the body behind every part) is painted by the app shell.
|
|
2787
|
+
if (
|
|
2788
|
+
!named &&
|
|
2789
|
+
/^(page|body|app|background|page-background)$/i.test(s.on) &&
|
|
2790
|
+
TARGET.has('app-shell')
|
|
2791
|
+
)
|
|
2792
|
+
refuse(
|
|
2793
|
+
E.ERR_THEME_UNKNOWN_PART,
|
|
2794
|
+
`"${s.on}" is not a part name; the page behind your parts is app-shell (a background there shows in every AppShell variant).`,
|
|
2795
|
+
{
|
|
2796
|
+
didYouMean: ['app-shell'],
|
|
2797
|
+
run: [setLine(slug, thing, v, {...s, on: 'app-shell'}, unset)],
|
|
2798
|
+
},
|
|
2799
|
+
);
|
|
1719
2800
|
if (named)
|
|
1720
2801
|
refuse(
|
|
1721
2802
|
E.ERR_THEME_UNKNOWN_PART,
|
|
@@ -1742,6 +2823,26 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
1742
2823
|
);
|
|
1743
2824
|
}
|
|
1744
2825
|
if (s.when) {
|
|
2826
|
+
// A prop and value in other letters, with spaces or `=` between
|
|
2827
|
+
// (`Variant: Primary`, `variant=primary`): the working command.
|
|
2828
|
+
const m = /^\s*([^:=\s]+)\s*[:=]\s*([^:=]+?)\s*$/.exec(s.when);
|
|
2829
|
+
if (m) {
|
|
2830
|
+
const prop = t.props.find(x => x.toLowerCase() === m[1].toLowerCase());
|
|
2831
|
+
const vals = prop ? (C.variantValues(s.on)[prop] ?? []) : [];
|
|
2832
|
+
const val = vals.length
|
|
2833
|
+
? vals.find(x => x.toLowerCase() === m[2].toLowerCase())
|
|
2834
|
+
: m[2];
|
|
2835
|
+
const when = prop && val ? `${prop}:${val}` : null;
|
|
2836
|
+
if (when && when !== s.when)
|
|
2837
|
+
refuse(
|
|
2838
|
+
E.ERR_THEME_UNKNOWN_VARIANT,
|
|
2839
|
+
`--when "${s.when}" is written ${when}.`,
|
|
2840
|
+
{
|
|
2841
|
+
didYouMean: [when],
|
|
2842
|
+
run: [setLine(slug, thing, v, {...s, when}, unset)],
|
|
2843
|
+
},
|
|
2844
|
+
);
|
|
2845
|
+
}
|
|
1745
2846
|
const [p, wv, ...more] = s.when.split(':');
|
|
1746
2847
|
if (!wv || more.length)
|
|
1747
2848
|
refuse(
|
|
@@ -1764,12 +2865,21 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
1764
2865
|
);
|
|
1765
2866
|
}
|
|
1766
2867
|
const states = [...t.states, ...COMMON_STATES];
|
|
2868
|
+
// A state the part lists in camelCase (toggle-button's isPressed) typed
|
|
2869
|
+
// in any case or with dashes is that state.
|
|
2870
|
+
const flat = (/** @type {string} */ x) =>
|
|
2871
|
+
x.replace(/[-_\s]/g, '').toLowerCase();
|
|
2872
|
+
if (s.state && !states.includes(s.state)) {
|
|
2873
|
+
const same = states.find(x => flat(x) === flat(String(s.state)));
|
|
2874
|
+
if (same) s.state = same;
|
|
2875
|
+
}
|
|
1767
2876
|
// Other words for a state, mapped to the one the part has; with none
|
|
1768
2877
|
// near, the list of its states (never a guess such as hover).
|
|
1769
2878
|
const SYNONYMS = wordTable(
|
|
1770
2879
|
/** @type {Record<string, string[]>} */ ({
|
|
1771
|
-
pressed: ['active'],
|
|
1772
|
-
press: ['active'],
|
|
2880
|
+
pressed: ['isPressed', 'active'],
|
|
2881
|
+
press: ['isPressed', 'active'],
|
|
2882
|
+
on: ['isPressed', 'checked', 'selected'],
|
|
1773
2883
|
down: ['active'],
|
|
1774
2884
|
clicked: ['active'],
|
|
1775
2885
|
hovered: ['hover'],
|
|
@@ -2131,6 +3241,38 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
2131
3241
|
})(),
|
|
2132
3242
|
},
|
|
2133
3243
|
);
|
|
3244
|
+
// A comparative weight word is the weight (lighter is light, never the
|
|
3245
|
+
// tracking tighter); two words (`bold tight`, `bold, tight`) are a
|
|
3246
|
+
// weight and a tracking, one line each.
|
|
3247
|
+
if (!unset) {
|
|
3248
|
+
const MORE = /** @type {Record<string, string>} */ ({
|
|
3249
|
+
lighter: 'light',
|
|
3250
|
+
thinner: 'light',
|
|
3251
|
+
bolder: 'bold',
|
|
3252
|
+
heavier: 'heavy',
|
|
3253
|
+
wider: 'wide',
|
|
3254
|
+
looser: 'wide',
|
|
3255
|
+
});
|
|
3256
|
+
const words = String(v ?? '')
|
|
3257
|
+
.trim()
|
|
3258
|
+
.toLowerCase()
|
|
3259
|
+
.split(/[\s,]+/)
|
|
3260
|
+
.filter(Boolean)
|
|
3261
|
+
.map(w => MORE[w] ?? w);
|
|
3262
|
+
const known = (/** @type {string} */ w) =>
|
|
3263
|
+
HEADING_WEIGHTS[w] !== undefined || HEADING_TRACKING[w] !== undefined;
|
|
3264
|
+
if (
|
|
3265
|
+
(words.length > 1 || MORE[String(v).trim().toLowerCase()]) &&
|
|
3266
|
+
words.every(known)
|
|
3267
|
+
)
|
|
3268
|
+
refuse(
|
|
3269
|
+
E.ERR_THEME_BAD_VALUE,
|
|
3270
|
+
words.length > 1
|
|
3271
|
+
? `"${v}" is ${words.length} headings values; headings takes one at a time (a weight and a tracking are two settings).`
|
|
3272
|
+
: `"${v}" is the weight ${words[0]}.`,
|
|
3273
|
+
{run: words.map(w => `${P} set ${slug} headings ${w}`)},
|
|
3274
|
+
);
|
|
3275
|
+
}
|
|
2134
3276
|
if (s.mode)
|
|
2135
3277
|
refuse(
|
|
2136
3278
|
E.ERR_THEME_NO_MODE,
|
|
@@ -2461,14 +3603,32 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
2461
3603
|
'-': Number(calc[1]) - Number(calc[3]),
|
|
2462
3604
|
}[/** @type {'*' | '/' | '+' | '-'} */ (calc[2])]
|
|
2463
3605
|
: null;
|
|
3606
|
+
// A bare number (0.5, as a pasted --radius: 0.5rem loses its
|
|
3607
|
+
// unit) has no unit to read it by: no size is guessed.
|
|
3608
|
+
const bareNumber = /^[+-]?\d*\.?\d+$/.test(lower);
|
|
2464
3609
|
const len =
|
|
2465
3610
|
calcPx != null && Number.isFinite(calcPx)
|
|
2466
3611
|
? calcPx
|
|
2467
|
-
:
|
|
3612
|
+
: bareNumber
|
|
3613
|
+
? null
|
|
3614
|
+
: lengthPx(lower);
|
|
2468
3615
|
const pct = /^(\d+(?:\.\d+)?)%$/.exec(lower);
|
|
3616
|
+
// Tailwind's names, and rounding said with a negation: what they
|
|
3617
|
+
// mean (rounded-none and not round are square, rounded-full is
|
|
3618
|
+
// pill, rounded-[12px] is 12px).
|
|
3619
|
+
const tw = /^rounded-\[(.+)\]$/.exec(lower)?.[1];
|
|
3620
|
+
const opposite =
|
|
3621
|
+
lower === 'rounded-full'
|
|
3622
|
+
? 'pill'
|
|
3623
|
+
: tw && lengthPx(tw) != null
|
|
3624
|
+
? `${Math.round(Number(lengthPx(tw)) * 100) / 100}px`
|
|
3625
|
+
: negates(lower) && /round/.test(lower)
|
|
3626
|
+
? 'square'
|
|
3627
|
+
: null;
|
|
2469
3628
|
// A radius below zero means none: square.
|
|
2470
3629
|
const meant =
|
|
2471
|
-
|
|
3630
|
+
opposite ??
|
|
3631
|
+
(len != null
|
|
2472
3632
|
? len <= 0
|
|
2473
3633
|
? 'square'
|
|
2474
3634
|
: `${Math.round(len * 100) / 100}px`
|
|
@@ -2476,17 +3636,22 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
2476
3636
|
? Number(pct[1]) >= 50
|
|
2477
3637
|
? 'pill'
|
|
2478
3638
|
: null
|
|
2479
|
-
:
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
3639
|
+
: bareNumber
|
|
3640
|
+
? null
|
|
3641
|
+
: (nearest(
|
|
3642
|
+
lower,
|
|
3643
|
+
CORNERS.map(([n]) => n),
|
|
3644
|
+
)[0] ?? null));
|
|
2483
3645
|
refuse(
|
|
2484
3646
|
E.ERR_THEME_BAD_VALUE,
|
|
2485
|
-
`corners takes ${DIALS.corners.values}, not "${v}".`,
|
|
3647
|
+
`corners takes ${DIALS.corners.values}, not "${v}"${bareNumber ? ' (a number needs its unit: px or rem)' : ''}.`,
|
|
2486
3648
|
{
|
|
2487
3649
|
...(meant ? {didYouMean: [meant]} : {}),
|
|
2488
3650
|
// The same scope, flags included.
|
|
2489
|
-
|
|
3651
|
+
// Nothing near: how corners, never a stock rung.
|
|
3652
|
+
run: [
|
|
3653
|
+
meant ? setLine(slug, 'corners', meant, s) : `${HOW} corners`,
|
|
3654
|
+
],
|
|
2490
3655
|
},
|
|
2491
3656
|
);
|
|
2492
3657
|
}
|
|
@@ -2568,15 +3733,15 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
2568
3733
|
SPACING.map(([n]) => n),
|
|
2569
3734
|
),
|
|
2570
3735
|
run: [
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
'spacing',
|
|
2574
|
-
nearest(
|
|
3736
|
+
(() => {
|
|
3737
|
+
const near = nearest(
|
|
2575
3738
|
v,
|
|
2576
3739
|
SPACING.map(([n]) => n),
|
|
2577
|
-
)[0]
|
|
2578
|
-
|
|
2579
|
-
|
|
3740
|
+
)[0];
|
|
3741
|
+
return near
|
|
3742
|
+
? setLine(slug, 'spacing', near, s)
|
|
3743
|
+
: `${HOW} spacing`;
|
|
3744
|
+
})(),
|
|
2580
3745
|
],
|
|
2581
3746
|
},
|
|
2582
3747
|
);
|
|
@@ -2632,19 +3797,26 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
2632
3797
|
didYouMean: [near],
|
|
2633
3798
|
run: [`${P} set ${slug} text-size ${near}`],
|
|
2634
3799
|
}
|
|
2635
|
-
: {
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
|
|
3800
|
+
: (() => {
|
|
3801
|
+
// A size typed full-width or with a trailing dot
|
|
3802
|
+
// (18, 18.) is that size; one read any other way (a
|
|
3803
|
+
// unit, a constant calc()) is that size. Nothing read:
|
|
3804
|
+
// how text-size, never a stock size.
|
|
3805
|
+
const t = typedPlain(v).replace(/\.$/, '');
|
|
3806
|
+
const size =
|
|
3807
|
+
/^\d+(\.\d+)?$/.test(t) &&
|
|
3808
|
+
Number(t) >= 10 &&
|
|
3809
|
+
Number(t) <= 32
|
|
3810
|
+
? String(Number(t))
|
|
3811
|
+
: textSizePx(v);
|
|
3812
|
+
return {
|
|
3813
|
+
run: [
|
|
3814
|
+
size != null
|
|
3815
|
+
? `${P} set ${slug} text-size ${size}`
|
|
3816
|
+
: `${HOW} text-size`,
|
|
3817
|
+
],
|
|
3818
|
+
};
|
|
3819
|
+
})();
|
|
2648
3820
|
})(),
|
|
2649
3821
|
);
|
|
2650
3822
|
else if (!TEXT_SIZE.some(([n]) => n === v))
|
|
@@ -2665,13 +3837,37 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
2665
3837
|
.replace(/\s*!important\s*$/i, '')
|
|
2666
3838
|
.replace(/;+\s*$/, '')
|
|
2667
3839
|
.trim()
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
.replace(
|
|
2671
|
-
|
|
3840
|
+
// A hex written 0x… (as in code) is that hex.
|
|
3841
|
+
.replace(/^0x([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i, '#$1')
|
|
3842
|
+
.replace(/^([0-9a-f]{3}|[0-9a-f]{6})$/i, '#$1');
|
|
3843
|
+
// A hex a digit short or over is refused as it is: the digit
|
|
3844
|
+
// missing could be anywhere, so none is made up.
|
|
3845
|
+
// A name of several words with a color among them (`navy blue`)
|
|
3846
|
+
// is that color.
|
|
3847
|
+
// Two names run together (`navyblue`) are the first, as the
|
|
3848
|
+
// spaced form is.
|
|
3849
|
+
const named = negates(v)
|
|
3850
|
+
? []
|
|
3851
|
+
: v
|
|
3852
|
+
.toLowerCase()
|
|
3853
|
+
.split(/[\s,-]+/)
|
|
3854
|
+
.flatMap(w =>
|
|
3855
|
+
COLOR_NAMES.includes(w)
|
|
3856
|
+
? [w]
|
|
3857
|
+
: COLOR_NAMES.filter(
|
|
3858
|
+
n =>
|
|
3859
|
+
n.length >= 3 &&
|
|
3860
|
+
w.startsWith(n) &&
|
|
3861
|
+
COLOR_NAMES.includes(w.slice(n.length)),
|
|
3862
|
+
).slice(0, 1),
|
|
3863
|
+
);
|
|
2672
3864
|
const near =
|
|
2673
3865
|
problem.kind === 'unknown'
|
|
2674
|
-
?
|
|
3866
|
+
? /^#?[0-9a-f]{4,8}$/i.test(v.trim())
|
|
3867
|
+
? []
|
|
3868
|
+
: named.length
|
|
3869
|
+
? named.slice(0, 1)
|
|
3870
|
+
: nearest(v.toLowerCase(), COLOR_NAMES)
|
|
2675
3871
|
: [];
|
|
2676
3872
|
// light-dark(a, b): the dial takes one color, from which it makes
|
|
2677
3873
|
// both modes; the light one is offered.
|
|
@@ -2735,12 +3931,23 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
2735
3931
|
if (!step && canApply && (!/^\d{1,3}$/.test(v) || Number(v) > 100)) {
|
|
2736
3932
|
// The value meant: a step in other letters (MORE), or the number
|
|
2737
3933
|
// read as CSS reads it (70%, 7e1), kept in range.
|
|
2738
|
-
|
|
2739
|
-
const
|
|
3934
|
+
// Quotes around it (`"50"`) are not part of it.
|
|
3935
|
+
const bare = v
|
|
3936
|
+
.trim()
|
|
3937
|
+
.replace(/^(["'])(.*)\1$/, '$2')
|
|
3938
|
+
.trim();
|
|
3939
|
+
const word = bare.toLowerCase();
|
|
3940
|
+
const n = cssNumber(bare);
|
|
3941
|
+
// A fraction of one (0.5) is that share of the scale (50), as a
|
|
3942
|
+
// number with no unit from 0 to 1 is read.
|
|
3943
|
+
const scaled =
|
|
3944
|
+
n && n.unit === '' && n.value > 0 && n.value < 1
|
|
3945
|
+
? n.value * 100
|
|
3946
|
+
: n?.value;
|
|
2740
3947
|
const near = ['more', 'less'].includes(word)
|
|
2741
3948
|
? word
|
|
2742
|
-
: n && (n.unit === '' || n.unit === '%')
|
|
2743
|
-
? String(Math.max(0, Math.min(100, Math.round(
|
|
3949
|
+
: n && (n.unit === '' || n.unit === '%') && scaled != null
|
|
3950
|
+
? String(Math.max(0, Math.min(100, Math.round(scaled))))
|
|
2744
3951
|
: null;
|
|
2745
3952
|
refuse(
|
|
2746
3953
|
E.ERR_THEME_BAD_VALUE,
|
|
@@ -2758,8 +3965,24 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
2758
3965
|
E.ERR_THEME_NO_EFFECT,
|
|
2759
3966
|
colors.length
|
|
2760
3967
|
? 'vibrancy sets how saturated the generated colors are, and every color this theme sets is a gray, so it would change nothing. Set a color first.'
|
|
2761
|
-
:
|
|
2762
|
-
|
|
3968
|
+
: (() => {
|
|
3969
|
+
// Colors set as tokens or on parts are values of their own:
|
|
3970
|
+
// vibrancy saturates only what the color dials make.
|
|
3971
|
+
const own = data.settings.find(
|
|
3972
|
+
(/** @type {any} */ x) =>
|
|
3973
|
+
x &&
|
|
3974
|
+
typeof x.value === 'string' &&
|
|
3975
|
+
(/^--color-/.test(String(x.thing)) ||
|
|
3976
|
+
/(^|-)colou?r$|^background(-color)?$|^fill$/.test(
|
|
3977
|
+
String(x.thing),
|
|
3978
|
+
)) &&
|
|
3979
|
+
parseColor(x.value) != null,
|
|
3980
|
+
);
|
|
3981
|
+
return own
|
|
3982
|
+
? `vibrancy sets how saturated the colors made from the color dials (accent, neutral, …) are; this theme's colors are values of their own (${own.thing} ${own.value}), which vibrancy does not change. Set a color dial such as accent first.`
|
|
3983
|
+
: 'vibrancy sets how saturated the generated colors are, and this theme sets no color yet. Set one first.';
|
|
3984
|
+
})(),
|
|
3985
|
+
{run: [`${HOW} accent`]},
|
|
2763
3986
|
);
|
|
2764
3987
|
} else if (thing === 'font') {
|
|
2765
3988
|
if (s.when || s.state)
|
|
@@ -3053,6 +4276,19 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
3053
4276
|
],
|
|
3054
4277
|
},
|
|
3055
4278
|
);
|
|
4279
|
+
// A dial typed as a flag (--corners round): the dial is meant.
|
|
4280
|
+
const dial = thing.replace(/^-+/, '');
|
|
4281
|
+
if (
|
|
4282
|
+
!(thing in TOKENS) &&
|
|
4283
|
+
(dial in DIALS || dial === 'base' || dial === 'mode')
|
|
4284
|
+
)
|
|
4285
|
+
refuse(
|
|
4286
|
+
E.ERR_THEME_UNKNOWN_TOKEN,
|
|
4287
|
+
`"${thing}" is not a design token; ${dial} is a dial, typed without dashes.`,
|
|
4288
|
+
{
|
|
4289
|
+
run: [setLine(slug, dial, v, {...s, mode: undefined}, unset)],
|
|
4290
|
+
},
|
|
4291
|
+
);
|
|
3056
4292
|
if (!(thing in TOKENS)) {
|
|
3057
4293
|
refuse(E.ERR_THEME_UNKNOWN_TOKEN, `"${thing}" is not a design token.`, {
|
|
3058
4294
|
didYouMean: nearest(thing, Object.keys(TOKENS)),
|
|
@@ -3201,6 +4437,8 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
3201
4437
|
s.note = `no part reads ${thing} itself, but ${fed.slice(0, 4).join(', ')} ${fed.length > 1 ? 'are' : 'is'} built from it, so the change shows wherever ${fed.length > 1 ? 'those are' : 'that is'} used${fed.some(k => k.startsWith('--color-syntax-')) ? ' (such as diff rows in code blocks)' : ''}`;
|
|
3202
4438
|
else if (r && data.like && baseReads(ctx, data.like, thing))
|
|
3203
4439
|
s.note = `the ${data.like} theme's own part styles read ${thing}, so the change shows where they use it`;
|
|
4440
|
+
else if (r && coreStylesRead(ctx, thing))
|
|
4441
|
+
s.note = `Core's stylesheet reads ${thing} outside the parts the editor renders (such as the page behind them, the app shell), so the change shows where it is used`;
|
|
3204
4442
|
else if (r && dialWrites(thing))
|
|
3205
4443
|
s.note = `no part of this Core reads ${thing}, and no token it feeds is read, so it changes nothing you see now; it is set as asked because a dial writes it too`;
|
|
3206
4444
|
// The editor's record of what parts read comes from one render of
|
|
@@ -3374,9 +4612,40 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
3374
4612
|
},
|
|
3375
4613
|
);
|
|
3376
4614
|
}
|
|
4615
|
+
// A state Core paints at run time with an inline style (a selected table
|
|
4616
|
+
// row's wash) outranks any theme rule for that property while Core paints
|
|
4617
|
+
// it: the token the inline style reads is what changes it. A component
|
|
4618
|
+
// option can turn that paint off (a table without its row highlight), and
|
|
4619
|
+
// then a rule in the state applies; the refusal says both.
|
|
4620
|
+
if (s.state && !unset) {
|
|
4621
|
+
const family =
|
|
4622
|
+
prop === 'background' || prop === 'background-color'
|
|
4623
|
+
? 'background-color'
|
|
4624
|
+
: prop;
|
|
4625
|
+
const inline = partsOf(ctx, s)
|
|
4626
|
+
.map(t => [t, ctx.C.MAP[t]?.inline?.[s.state ?? '']?.[family]])
|
|
4627
|
+
.find(([, tok]) => tok);
|
|
4628
|
+
if (inline)
|
|
4629
|
+
refuse(
|
|
4630
|
+
E.ERR_THEME_NO_EFFECT,
|
|
4631
|
+
`By default Core paints ${inline[0]}'s ${family} when ${s.state} as an inline style from ${inline[1]}, which no theme rule can replace, so set ${inline[1]} on ${inline[0]} when ${s.state} instead; only where the component is set not to paint it (such as a table with its row highlight off) does a ${s.state} ${family} apply, and there ${inline[1]} paints nothing.`,
|
|
4632
|
+
{
|
|
4633
|
+
run: [
|
|
4634
|
+
`${P} set ${slug} ${inline[1]} ${quoteCommandArgument(v)} --on ${inline[0]} --state ${s.state}${s.mode ? ` --mode ${s.mode}` : ''}`,
|
|
4635
|
+
],
|
|
4636
|
+
},
|
|
4637
|
+
);
|
|
4638
|
+
}
|
|
3377
4639
|
// Text, headings and links take their color from the color prop.
|
|
3378
4640
|
const textParts = COLOR_PROP_PARTS;
|
|
4641
|
+
// A heading's color is written as the text color tokens its color prop
|
|
4642
|
+
// reads, on the heading alone (compileTheme), so it shows.
|
|
4643
|
+
const headingColor =
|
|
4644
|
+
prop === 'color' &&
|
|
4645
|
+
partsOf(ctx, s).length > 0 &&
|
|
4646
|
+
partsOf(ctx, s).every(t => t === 'heading');
|
|
3379
4647
|
if (
|
|
4648
|
+
!headingColor &&
|
|
3380
4649
|
(prop === 'color' || prop === '-webkit-text-fill-color') &&
|
|
3381
4650
|
partsOf(ctx, s).some(t => textParts.includes(t))
|
|
3382
4651
|
) {
|
|
@@ -3405,62 +4674,9 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
3405
4674
|
}
|
|
3406
4675
|
s.note = `text, heading and link inside ${s.on} keep the color their color prop gives; set --color-text-primary for those`;
|
|
3407
4676
|
}
|
|
3408
|
-
// One mode on a part whose variants each read their own
|
|
3409
|
-
//
|
|
3410
|
-
//
|
|
3411
|
-
// every variant, so any part whose variants read their own value needs
|
|
3412
|
-
// the variant named.
|
|
3413
|
-
// Per-variant colors only: a value that is not a color is refused for
|
|
3414
|
-
// --mode below, with the reason that holds.
|
|
3415
|
-
if (
|
|
3416
|
-
s.mode &&
|
|
3417
|
-
!s.when &&
|
|
3418
|
-
(COLOR_PROPS.test(prop) || (prop === 'background' && isColorValue(v)))
|
|
3419
|
-
) {
|
|
3420
|
-
const g = C.groupOfProp(
|
|
3421
|
-
prop === 'background' ? 'background-color' : prop,
|
|
3422
|
-
);
|
|
3423
|
-
for (const t of partsOf(ctx, s)) {
|
|
3424
|
-
const reads = g
|
|
3425
|
-
? C.partReads(t, g).filter(r => r.props.includes(prop))
|
|
3426
|
-
: [];
|
|
3427
|
-
const variantsOf = (
|
|
3428
|
-
/** @type {(w: string) => string | undefined} */ pick,
|
|
3429
|
-
) => [
|
|
3430
|
-
...new Set(
|
|
3431
|
-
reads
|
|
3432
|
-
.flatMap(r => r.when)
|
|
3433
|
-
.map(pick)
|
|
3434
|
-
.filter(Boolean),
|
|
3435
|
-
),
|
|
3436
|
-
];
|
|
3437
|
-
// Resting reads keyed by the variant alone, and reads in the state.
|
|
3438
|
-
const rest = variantsOf(w => /^variant=([\w-]+)$/.exec(w)?.[1]);
|
|
3439
|
-
const inState = s.state
|
|
3440
|
-
? variantsOf(w =>
|
|
3441
|
-
w.includes(`:${s.state}`)
|
|
3442
|
-
? /(?:^|,)variant=([\w-]+)/.exec(w)?.[1]
|
|
3443
|
-
: undefined,
|
|
3444
|
-
)
|
|
3445
|
-
: [];
|
|
3446
|
-
// A state that does not change this property shows each variant's
|
|
3447
|
-
// resting value, so that is what the other mode must keep.
|
|
3448
|
-
const variants = inState.length ? inState : rest;
|
|
3449
|
-
const perVariant = inState.length
|
|
3450
|
-
? true
|
|
3451
|
-
: rest.length > 0 && !reads.some(r => r.when.includes(''));
|
|
3452
|
-
if (reads.length && variants.length && perVariant)
|
|
3453
|
-
refuse(
|
|
3454
|
-
E.ERR_THEME_NO_MODE,
|
|
3455
|
-
`Each variant of ${t} has its own ${prop}${s.state ? ` when ${s.state}` : ''}, so one mode cannot be set for all of them at once: the other mode would take one variant's color for every variant. Name the variant.`,
|
|
3456
|
-
{
|
|
3457
|
-
run: [
|
|
3458
|
-
`${P} set ${slug} ${prop} ${quoteCommandArgument(v)} --on ${s.on} --when variant:${variants[0]}${s.state ? ` --state ${s.state}` : ''} --mode ${s.mode}`,
|
|
3459
|
-
],
|
|
3460
|
-
},
|
|
3461
|
-
);
|
|
3462
|
-
}
|
|
3463
|
-
}
|
|
4677
|
+
// One mode on a part whose variants each read their own color is
|
|
4678
|
+
// written to each variant's rule with that variant's own other half
|
|
4679
|
+
// (compileTheme), so it needs no variant named.
|
|
3464
4680
|
if (!isSafeValue(v))
|
|
3465
4681
|
refuse(
|
|
3466
4682
|
E.ERR_THEME_BAD_VALUE,
|
|
@@ -3536,18 +4752,53 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
3536
4752
|
if (
|
|
3537
4753
|
s.mode &&
|
|
3538
4754
|
!COLOR_PROPS.test(prop) &&
|
|
3539
|
-
!(prop === 'background' && isColorValue(v))
|
|
4755
|
+
!(prop === 'background' && isColorValue(v)) &&
|
|
4756
|
+
// A gradient background (no image file) goes per mode: its colors
|
|
4757
|
+
// are each painted in that mode only (compileTheme).
|
|
4758
|
+
!(
|
|
4759
|
+
/^background(-image)?$/.test(prop) &&
|
|
4760
|
+
/gradient\(/i.test(v) &&
|
|
4761
|
+
!/url\(/i.test(v)
|
|
4762
|
+
)
|
|
3540
4763
|
) {
|
|
3541
4764
|
// A color mixed into the value (a border's) can go per mode on its
|
|
3542
4765
|
// own; a value with none (a radius) is just set for both modes.
|
|
3543
4766
|
const hasColor = /#[0-9a-f]{3,8}\b|rgba?\(|hsla?\(/i.test(v);
|
|
3544
|
-
|
|
3545
|
-
|
|
3546
|
-
|
|
3547
|
-
|
|
3548
|
-
|
|
3549
|
-
|
|
3550
|
-
|
|
4767
|
+
// A gradient's colors sit in its image, above any background-color:
|
|
4768
|
+
// no color step can make them differ per mode.
|
|
4769
|
+
const alt =
|
|
4770
|
+
!hasColor || /gradient\(/i.test(v)
|
|
4771
|
+
? null
|
|
4772
|
+
: prop === 'border' || prop.startsWith('border-')
|
|
4773
|
+
? 'border-color'
|
|
4774
|
+
: prop === 'background'
|
|
4775
|
+
? 'background-color'
|
|
4776
|
+
: null;
|
|
4777
|
+
// On a part whose variants each have their own color, the color per
|
|
4778
|
+
// mode is set for one variant at a time (as that refusal says): the
|
|
4779
|
+
// step names the default one, or the first.
|
|
4780
|
+
let altWhen = '';
|
|
4781
|
+
if (alt && !s.when) {
|
|
4782
|
+
const g = C.groupOfProp(alt);
|
|
4783
|
+
const variants = [
|
|
4784
|
+
...new Set(
|
|
4785
|
+
partsOf(ctx, s).flatMap(t =>
|
|
4786
|
+
(g ? C.partReads(t, g) : [])
|
|
4787
|
+
.filter(r => r.props.includes(alt))
|
|
4788
|
+
.flatMap(r => r.when)
|
|
4789
|
+
.map(w => /^variant=([\w-]+)$/.exec(w)?.[1])
|
|
4790
|
+
.filter(Boolean),
|
|
4791
|
+
),
|
|
4792
|
+
),
|
|
4793
|
+
];
|
|
4794
|
+
const plain = partsOf(ctx, s).some(t =>
|
|
4795
|
+
(g ? C.partReads(t, g) : []).some(
|
|
4796
|
+
r => r.props.includes(alt) && r.when.includes(''),
|
|
4797
|
+
),
|
|
4798
|
+
);
|
|
4799
|
+
if (variants.length && !plain)
|
|
4800
|
+
altWhen = ` --when variant:${variants.includes('default') ? 'default' : variants[0]}`;
|
|
4801
|
+
}
|
|
3551
4802
|
refuse(
|
|
3552
4803
|
E.ERR_THEME_NO_MODE,
|
|
3553
4804
|
`--mode works on plain colors; ${prop} ${prop === 'box-shadow' || prop === 'border' ? 'mixes a color with sizes' : 'is not a color'}, so it cannot differ between light and dark.`,
|
|
@@ -3555,7 +4806,7 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
3555
4806
|
run: alt
|
|
3556
4807
|
? [
|
|
3557
4808
|
`${P} set ${slug} ${prop} ${quoteCommandArgument(v.replace(/#[0-9a-f]{3,8}|rgba?\([^)]*\)/i, 'currentcolor'))} --on ${s.on}${whenFlag} # the shape, both modes`,
|
|
3558
|
-
`${P} set ${slug} ${alt} ${quoteCommandArgument(/#[0-9a-f]{3,8}\b|rgba?\([^)]*\)|hsla?\([^)]*\)/i.exec(v)?.[0] ?? '#1f2937')} --on ${s.on}${whenFlag} --mode ${s.mode} # then the color per mode`,
|
|
4809
|
+
`${P} set ${slug} ${alt} ${quoteCommandArgument(/#[0-9a-f]{3,8}\b|rgba?\([^)]*\)|hsla?\([^)]*\)/i.exec(v)?.[0] ?? '#1f2937')} --on ${s.on}${altWhen}${whenFlag} --mode ${s.mode} # then the color per mode${altWhen ? ', for each variant' : ''}`,
|
|
3559
4810
|
]
|
|
3560
4811
|
: [
|
|
3561
4812
|
`${P} set ${slug} ${prop} ${quoteCommandArgument(v)} --on ${s.on}${whenFlag} # both modes`,
|
|
@@ -3570,8 +4821,21 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
3570
4821
|
if (
|
|
3571
4822
|
s.mode &&
|
|
3572
4823
|
s.state &&
|
|
3573
|
-
!partsOf(ctx, s).every(
|
|
3574
|
-
|
|
4824
|
+
!partsOf(ctx, s).every(
|
|
4825
|
+
t =>
|
|
4826
|
+
partDefault(ctx, t, camel(prop), s.when, s.state) ||
|
|
4827
|
+
// The base theme's own value there (in the state, else at rest)
|
|
4828
|
+
// is what the other mode keeps.
|
|
4829
|
+
[`:${s.state}`, null].some(st =>
|
|
4830
|
+
baseRuleHas(
|
|
4831
|
+
ctx.project.cwd,
|
|
4832
|
+
data.like,
|
|
4833
|
+
t,
|
|
4834
|
+
s.when ?? 'base',
|
|
4835
|
+
st,
|
|
4836
|
+
camel(prop),
|
|
4837
|
+
),
|
|
4838
|
+
),
|
|
3575
4839
|
) &&
|
|
3576
4840
|
!data.settings.some(
|
|
3577
4841
|
x =>
|
|
@@ -3638,13 +4902,18 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
3638
4902
|
// A hint names this theme and the part (card when none is given),
|
|
3639
4903
|
// and a corners value corners takes.
|
|
3640
4904
|
run: hint
|
|
3641
|
-
? hint(
|
|
3642
|
-
|
|
3643
|
-
|
|
3644
|
-
|
|
3645
|
-
|
|
3646
|
-
|
|
3647
|
-
|
|
4905
|
+
? (/corners/.test(String(hint('', ''))) &&
|
|
4906
|
+
v.trim() &&
|
|
4907
|
+
!YES_NO.test(v.trim()) &&
|
|
4908
|
+
cornersRead(v) == null
|
|
4909
|
+
? // A value corners cannot read: how corners, never a stock rung.
|
|
4910
|
+
[`${HOW} corners`]
|
|
4911
|
+
: hint(
|
|
4912
|
+
/corners/.test(String(hint('', ''))) && !YES_NO.test(v.trim())
|
|
4913
|
+
? (cornersRead(v) ?? '')
|
|
4914
|
+
: v,
|
|
4915
|
+
s.on,
|
|
4916
|
+
)
|
|
3648
4917
|
).map(x =>
|
|
3649
4918
|
x
|
|
3650
4919
|
.replace(/<theme>/g, slug)
|
|
@@ -3797,8 +5066,8 @@ export function unknownVarRef(v, TOKENS, thing) {
|
|
|
3797
5066
|
// A fallback always gives a value: never "reads nothing" (a likely
|
|
3798
5067
|
// typo is noted when the setting is made).
|
|
3799
5068
|
if (comma) continue;
|
|
3800
|
-
const near = nearest(name, Object.keys(TOKENS)).filter(
|
|
3801
|
-
|
|
5069
|
+
const near = nearest(name, Object.keys(TOKENS)).filter(n =>
|
|
5070
|
+
typoNear(name, n),
|
|
3802
5071
|
);
|
|
3803
5072
|
if (near.length)
|
|
3804
5073
|
return {
|
|
@@ -3849,78 +5118,38 @@ export function fontFileReason(value) {
|
|
|
3849
5118
|
}
|
|
3850
5119
|
|
|
3851
5120
|
/**
|
|
3852
|
-
* A
|
|
3853
|
-
*
|
|
3854
|
-
* the browser reads only a plain space as one.
|
|
3855
|
-
* @param {string} v
|
|
5121
|
+
* A word as a suggested command quotes it, without the quotes.
|
|
5122
|
+
* @param {string} word
|
|
3856
5123
|
*/
|
|
3857
|
-
|
|
3858
|
-
|
|
3859
|
-
|
|
3860
|
-
const straight = v
|
|
3861
|
-
.replace(/[\u2018\u2019\u201A\u201B]/g, "'")
|
|
3862
|
-
.replace(/[\u201C\u201D\u201E\u201F]/g, '"');
|
|
3863
|
-
// A quoted CSS string (`content: "a\u00A0b"`) keeps what is inside it.
|
|
3864
|
-
return straight
|
|
3865
|
-
.split(/("(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*')/)
|
|
3866
|
-
.map((part, i) =>
|
|
3867
|
-
i % 2
|
|
3868
|
-
? part
|
|
3869
|
-
: part
|
|
3870
|
-
.replace(/[\u200B-\u200D\u2060\uFEFF]/g, '')
|
|
3871
|
-
.replace(/[\u00A0\u1680\u2000-\u200A\u202F\u205F\u3000]/g, ' '),
|
|
3872
|
-
)
|
|
3873
|
-
.join('');
|
|
5124
|
+
function unquoteArg(word) {
|
|
5125
|
+
const m = /^'(.*)'$/s.exec(word.trim());
|
|
5126
|
+
return m ? m[1].replace(/'\\''/g, "'") : word.trim();
|
|
3874
5127
|
}
|
|
3875
5128
|
|
|
5129
|
+
/** Core's stylesheet text, by project folder. @type {Map<string, string>} */
|
|
5130
|
+
const coreStyles = new Map();
|
|
5131
|
+
|
|
3876
5132
|
/**
|
|
3877
|
-
*
|
|
3878
|
-
*
|
|
3879
|
-
*
|
|
3880
|
-
*
|
|
3881
|
-
* Unicode spaces. A thing it cannot read is left as typed.
|
|
3882
|
-
* @param {string} thing
|
|
3883
|
-
* @param {string | undefined} value
|
|
3884
|
-
* @returns {{thing: string, value: string | undefined}}
|
|
5133
|
+
* Whether Core's own stylesheet reads a token anywhere (a part the editor
|
|
5134
|
+
* does not render, such as the app shell behind the page, included).
|
|
5135
|
+
* @param {any} ctx
|
|
5136
|
+
* @param {string} token
|
|
3885
5137
|
*/
|
|
3886
|
-
|
|
3887
|
-
|
|
3888
|
-
let
|
|
3889
|
-
|
|
3890
|
-
|
|
3891
|
-
|
|
3892
|
-
|
|
3893
|
-
|
|
3894
|
-
|
|
3895
|
-
|
|
3896
|
-
|
|
3897
|
-
pasted = true;
|
|
5138
|
+
function coreStylesRead(ctx, token) {
|
|
5139
|
+
const cwd = String(ctx?.project?.cwd ?? '');
|
|
5140
|
+
let css = coreStyles.get(cwd);
|
|
5141
|
+
if (css == null) {
|
|
5142
|
+
try {
|
|
5143
|
+
css = fs.readFileSync(
|
|
5144
|
+
ctx.project.req.resolve('@astryxdesign/core/astryx.css'),
|
|
5145
|
+
'utf8',
|
|
5146
|
+
);
|
|
5147
|
+
} catch {
|
|
5148
|
+
css = '';
|
|
3898
5149
|
}
|
|
5150
|
+
coreStyles.set(cwd, css);
|
|
3899
5151
|
}
|
|
3900
|
-
|
|
3901
|
-
|
|
3902
|
-
t = t.replace(/\s*[:=]+$/, '');
|
|
3903
|
-
pasted = true;
|
|
3904
|
-
}
|
|
3905
|
-
// Dash-like characters where a token's two dashes go (an em or en dash,
|
|
3906
|
-
// a non-breaking hyphen, a minus sign, a full-width hyphen, alone or
|
|
3907
|
-
// mixed with hyphens): `--`.
|
|
3908
|
-
t = t.replace(/^[-\u2010-\u2015\u2212\uFE58\uFE63\uFF0D]+/, run =>
|
|
3909
|
-
/[^-]/.test(run) ? '--' : run,
|
|
5152
|
+
return new RegExp(`var\\(\\s*${token.replace(/[-]/g, '\\-')}\\s*[,)]`).test(
|
|
5153
|
+
css,
|
|
3910
5154
|
);
|
|
3911
|
-
// A token typed as a var() reference.
|
|
3912
|
-
const ref = /^var\(\s*(--[a-z0-9-]+)\s*\)$/i.exec(t);
|
|
3913
|
-
if (ref) t = ref[1];
|
|
3914
|
-
if (pasted && typeof v === 'string')
|
|
3915
|
-
v = v.replace(/\s*!\s*important\s*;?\s*$/i, '').replace(/;+\s*$/, '');
|
|
3916
|
-
return {thing: t, value: v};
|
|
3917
|
-
}
|
|
3918
|
-
|
|
3919
|
-
/**
|
|
3920
|
-
* A word as a suggested command quotes it, without the quotes.
|
|
3921
|
-
* @param {string} word
|
|
3922
|
-
*/
|
|
3923
|
-
function unquoteArg(word) {
|
|
3924
|
-
const m = /^'(.*)'$/s.exec(word.trim());
|
|
3925
|
-
return m ? m[1].replace(/'\\''/g, "'") : word.trim();
|
|
3926
5155
|
}
|