@astryxdesign/cli 0.7.16 → 0.7.17-canary.g9a957aa
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 +12 -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 +47 -9
- 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 +32 -0
- package/api/build/kit/words.mjs +49 -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 +48 -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 +491 -186
- package/api/render/render.doc.mjs +10 -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 +38 -0
- package/api/theme/build/build.mjs +144 -24
- package/api/theme/theme.type.d.mts +10 -0
- package/api/theme/theme.type.mjs +7 -1
- package/api/theme-edit/_adapter.d.mts +35 -0
- package/api/theme-edit/_adapter.mjs +477 -41
- package/api/theme-edit/_check.d.mts +28 -22
- package/api/theme-edit/_check.mjs +1077 -200
- 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 +932 -82
- package/api/theme-edit/_how-commands.d.mts +49 -0
- package/api/theme-edit/_how-commands.mjs +386 -1
- package/api/theme-edit/_how-question.d.mts +56 -0
- package/api/theme-edit/_how-question.mjs +3509 -168
- 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 +137 -0
- package/api/theme-edit/_normal.mjs +612 -0
- package/api/theme-edit/_palette.mjs +10 -4
- package/api/theme-edit/_parts.d.mts +4 -0
- package/api/theme-edit/_parts.mjs +28 -2
- package/api/theme-edit/_preview-app.d.mts +7 -1
- package/api/theme-edit/_preview-app.mjs +191 -15
- package/api/theme-edit/_preview.d.mts +64 -8
- package/api/theme-edit/_preview.mjs +401 -83
- package/api/theme-edit/_settings.d.mts +139 -5
- package/api/theme-edit/_settings.mjs +1659 -112
- package/api/theme-edit/_tables.mjs +17 -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 +2 -2
- 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 +8 -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 +1 -7
- 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/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 -1
- 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 +27 -2
- 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 +138 -3
- 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/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 +169 -0
- 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 +138 -52
- 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/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 +79 -10
- 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 +4 -1
- package/foundation/render/ts-paths.mjs +7 -3
- package/foundation/response/error-codes.d.mts +2 -1
- package/foundation/response/error-codes.doc.mjs +7 -1
- package/foundation/response/error-codes.mjs +7 -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/package.json +6 -6
|
@@ -98,10 +98,30 @@ import {
|
|
|
98
98
|
ownSourceTokenValues,
|
|
99
99
|
baseTopTokens,
|
|
100
100
|
baseComponentReads,
|
|
101
|
+
baseRuleHas,
|
|
101
102
|
partRuleTokens,
|
|
102
103
|
cssFamily,
|
|
103
104
|
familySpaces,
|
|
104
105
|
} from './_settings.mjs';
|
|
106
|
+
import {isColorToken} from './_compiler.mjs';
|
|
107
|
+
import {
|
|
108
|
+
trimInsideQuotes,
|
|
109
|
+
colorPair,
|
|
110
|
+
otherSettingLabel,
|
|
111
|
+
familiesOf,
|
|
112
|
+
familyPieces,
|
|
113
|
+
normalValueText,
|
|
114
|
+
normalizeEntry,
|
|
115
|
+
withoutDebris,
|
|
116
|
+
} from './_normal.mjs';
|
|
117
|
+
|
|
118
|
+
export {
|
|
119
|
+
familiesOf,
|
|
120
|
+
familyPieces,
|
|
121
|
+
normalValueText,
|
|
122
|
+
normalizeEntry,
|
|
123
|
+
withoutDebris,
|
|
124
|
+
};
|
|
105
125
|
import {quoteCommandArgument} from '../../foundation/env/package-manager.mjs';
|
|
106
126
|
|
|
107
127
|
export {lengthPx};
|
|
@@ -154,6 +174,108 @@ const cornerPxOf = v =>
|
|
|
154
174
|
|
|
155
175
|
const E = ERROR_CODES;
|
|
156
176
|
|
|
177
|
+
/**
|
|
178
|
+
* Why the math in a value's calc() cannot work, or null: each `+`/`-`
|
|
179
|
+
* needs two sides of one kind (a length with a length or a percentage, a
|
|
180
|
+
* number with a number), `*` needs a plain number on one side, `/` a plain
|
|
181
|
+
* number on the right. A var() counts as its fallback; one with none, or a
|
|
182
|
+
* nested min(), max() or clamp(), is not judged.
|
|
183
|
+
* @param {string} value
|
|
184
|
+
* @returns {string | null}
|
|
185
|
+
*/
|
|
186
|
+
export function calcUnitProblem(value) {
|
|
187
|
+
const text = String(value);
|
|
188
|
+
const re = /\bcalc\(/gi;
|
|
189
|
+
let m;
|
|
190
|
+
while ((m = re.exec(text))) {
|
|
191
|
+
const open = m.index + m[0].length - 1;
|
|
192
|
+
const close = matchingParen(text, open);
|
|
193
|
+
if (close < 0) return null;
|
|
194
|
+
let expr = text.slice(open + 1, close);
|
|
195
|
+
// Each var() is its fallback, innermost first.
|
|
196
|
+
for (let i = 0; i < 20 && /\bvar\(/i.test(expr); i += 1) {
|
|
197
|
+
const at = expr.search(/\bvar\((?:[^()]|\([^()]*\))*\)/i);
|
|
198
|
+
const v = /\bvar\(((?:[^()]|\([^()]*\))*)\)/i.exec(expr.slice(at));
|
|
199
|
+
if (at < 0 || !v) return null;
|
|
200
|
+
const comma = v[1].indexOf(',');
|
|
201
|
+
if (comma < 0) return null;
|
|
202
|
+
expr = `${expr.slice(0, at)}(${v[1].slice(comma + 1).trim()})${expr.slice(at + v[0].length)}`;
|
|
203
|
+
}
|
|
204
|
+
if (/[a-z-]+\(/i.test(expr.replace(/\bcalc\(/gi, '('))) continue;
|
|
205
|
+
const found = expr.match(/\d*\.?\d+(?:e[+-]?\d+)?[a-z%]*|[-+*/()]/gi);
|
|
206
|
+
if (!found) continue;
|
|
207
|
+
const tokens = found;
|
|
208
|
+
let pos = 0;
|
|
209
|
+
/** @returns {string | null} */
|
|
210
|
+
const kindOf = (/** @type {string} */ t) => {
|
|
211
|
+
const u = /[a-z%]*$/i.exec(t)?.[0].toLowerCase() ?? '';
|
|
212
|
+
if (!u) return 'number';
|
|
213
|
+
if (u === '%') return 'percent';
|
|
214
|
+
if (/^(m?s)$/.test(u)) return 'time';
|
|
215
|
+
if (/^(deg|rad|grad|turn)$/.test(u)) return 'angle';
|
|
216
|
+
return 'length';
|
|
217
|
+
};
|
|
218
|
+
/** @type {string | null} */
|
|
219
|
+
let why = null;
|
|
220
|
+
const fail = (/** @type {string} */ w) => {
|
|
221
|
+
why ??= w;
|
|
222
|
+
return 'number';
|
|
223
|
+
};
|
|
224
|
+
const join = (
|
|
225
|
+
/** @type {string} */ a,
|
|
226
|
+
/** @type {string} */ b,
|
|
227
|
+
/** @type {string} */ op,
|
|
228
|
+
) => {
|
|
229
|
+
if (op === '+' || op === '-') {
|
|
230
|
+
if (a === b) return a;
|
|
231
|
+
const lp = new Set([a, b]);
|
|
232
|
+
if (lp.has('length') && lp.has('percent') && lp.size === 2)
|
|
233
|
+
return 'length';
|
|
234
|
+
return fail(`${a} ${op} ${b} adds two kinds of value`);
|
|
235
|
+
}
|
|
236
|
+
if (op === '*') {
|
|
237
|
+
if (a === 'number') return b;
|
|
238
|
+
if (b === 'number') return a;
|
|
239
|
+
return fail(`${a} * ${b} multiplies two values with units`);
|
|
240
|
+
}
|
|
241
|
+
if (b === 'number') return a;
|
|
242
|
+
return fail(`${a} / ${b} divides by a value with a unit`);
|
|
243
|
+
};
|
|
244
|
+
/** @returns {string} */
|
|
245
|
+
const factor = () => {
|
|
246
|
+
const t = tokens[pos++];
|
|
247
|
+
if (t === '(') {
|
|
248
|
+
const k = sum();
|
|
249
|
+
pos++;
|
|
250
|
+
return k;
|
|
251
|
+
}
|
|
252
|
+
if (t === '-' || t === '+') return factor();
|
|
253
|
+
return t == null ? 'number' : (kindOf(t) ?? 'number');
|
|
254
|
+
};
|
|
255
|
+
/** @returns {string} */
|
|
256
|
+
const product = () => {
|
|
257
|
+
let k = factor();
|
|
258
|
+
while (tokens[pos] === '*' || tokens[pos] === '/') {
|
|
259
|
+
const op = tokens[pos++];
|
|
260
|
+
k = join(k, factor(), op);
|
|
261
|
+
}
|
|
262
|
+
return k;
|
|
263
|
+
};
|
|
264
|
+
/** @returns {string} */
|
|
265
|
+
function sum() {
|
|
266
|
+
let k = product();
|
|
267
|
+
while (tokens[pos] === '+' || tokens[pos] === '-') {
|
|
268
|
+
const op = tokens[pos++];
|
|
269
|
+
k = join(k, product(), op);
|
|
270
|
+
}
|
|
271
|
+
return k;
|
|
272
|
+
}
|
|
273
|
+
sum();
|
|
274
|
+
if (why) return why;
|
|
275
|
+
}
|
|
276
|
+
return null;
|
|
277
|
+
}
|
|
278
|
+
|
|
157
279
|
/**
|
|
158
280
|
* The fallbacks of the var() calls inside a value that is not one var()
|
|
159
281
|
* alone (`calc(var(--x, 4px) * 2)`), in order. A var() with an empty
|
|
@@ -235,8 +357,16 @@ function matchingParen(text, open) {
|
|
|
235
357
|
* @returns {number | null}
|
|
236
358
|
*/
|
|
237
359
|
function textSizePx(v) {
|
|
360
|
+
// Paste debris around the size (quotes, `!important`, a trailing `;` or
|
|
361
|
+
// `,`) is not part of it.
|
|
362
|
+
const bare = withoutDebris(
|
|
363
|
+
String(v)
|
|
364
|
+
.replace(/^\s*(["'])(.*)\1\s*$/, '$2')
|
|
365
|
+
.replace(/\s*!\s*important\s*/i, '')
|
|
366
|
+
.replace(/[;,]+\s*$/, ''),
|
|
367
|
+
);
|
|
238
368
|
const m = /^\+?(\d*\.?\d+(?:e[+-]?\d+)?)(px|rem|em|pt|%)?$/i.exec(
|
|
239
|
-
typedPlain(
|
|
369
|
+
typedPlain(bare)
|
|
240
370
|
.replace(/(\d)\.(?=[a-z%]*$)/i, '$1')
|
|
241
371
|
.replace(/\s+/g, '')
|
|
242
372
|
.replace(/^(\d+),(\d+)/, '$1.$2'),
|
|
@@ -334,6 +464,8 @@ function valueMeant(type, value) {
|
|
|
334
464
|
.replace(/\s*!\s*important\s*$/i, '')
|
|
335
465
|
.replace(/;+\s*$/, '')
|
|
336
466
|
.trim();
|
|
467
|
+
// Copy debris around it (a trailing comma, a stray quote or bracket).
|
|
468
|
+
p = withoutDebris(p).trim();
|
|
337
469
|
const q = /^(["'])(.*)\1$/.exec(p);
|
|
338
470
|
if (q && type !== 'font') p = q[2].trim();
|
|
339
471
|
const out = [p];
|
|
@@ -344,13 +476,12 @@ function valueMeant(type, value) {
|
|
|
344
476
|
if (type === 'font' || type === 'font-family') {
|
|
345
477
|
// A comma left out between families (`"Open Sans" serif`), read with
|
|
346
478
|
// css-tree.
|
|
479
|
+
// The stack read as families (a trailing comma, a stack wrapped in one
|
|
480
|
+
// more pair of quotes), each quoted as CSS needs it.
|
|
481
|
+
const fams = familiesOf(p);
|
|
482
|
+
if (fams?.length) out.push(fams.map(f => cssFamily(f, true)).join(', '));
|
|
347
483
|
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(', '));
|
|
484
|
+
if (listed && !fams?.length) out.push(listed);
|
|
354
485
|
}
|
|
355
486
|
return [...new Set(out)].filter(x => x && x !== value.trim());
|
|
356
487
|
}
|
|
@@ -648,13 +779,45 @@ export function storedProblems(ctx, slug, data, skip = '') {
|
|
|
648
779
|
// it.
|
|
649
780
|
for (const s of data.settings) {
|
|
650
781
|
if (replaced(s) || typeof s.value !== 'string') continue;
|
|
651
|
-
|
|
652
|
-
|
|
782
|
+
// Read as typed input is (a font family's quotes trimmed too), so the
|
|
783
|
+
// line offered is the value set would save.
|
|
784
|
+
const clean = /font/i.test(s.thing)
|
|
785
|
+
? trimInsideQuotes(normalValueText(s.value))
|
|
786
|
+
: normalValueText(s.value);
|
|
787
|
+
if (clean !== s.value) {
|
|
788
|
+
// Name what is wrong: invisible spaces, or quotes around the value
|
|
789
|
+
// CSS does not read (a curly quote inside a quoted string is fine,
|
|
790
|
+
// and is left as it is).
|
|
791
|
+
const spaces =
|
|
792
|
+
clean.replace(/["']/g, '') !==
|
|
793
|
+
s.value.replace(
|
|
794
|
+
/[\u2018-\u201F\u00AB\u00BB\u2039\u203A\u300C-\u300F\uFF02\uFF07`"']/g,
|
|
795
|
+
'',
|
|
796
|
+
);
|
|
797
|
+
const quotes =
|
|
798
|
+
/[\u2018-\u201F\u00AB\u00BB\u2039\u203A\u300C-\u300F\uFF02\uFF07`]/.test(
|
|
799
|
+
s.value,
|
|
800
|
+
) &&
|
|
801
|
+
clean.replace(
|
|
802
|
+
/[\u00A0\u1680\u2000-\u200A\u202F\u205F\u3000\u200B-\u200D\u2060\uFEFF]/g,
|
|
803
|
+
'',
|
|
804
|
+
) !==
|
|
805
|
+
s.value.replace(
|
|
806
|
+
/[\u00A0\u1680\u2000-\u200A\u202F\u205F\u3000\u200B-\u200D\u2060\uFEFF]/g,
|
|
807
|
+
'',
|
|
808
|
+
);
|
|
809
|
+
const why = [
|
|
810
|
+
spaces &&
|
|
811
|
+
'a no-break, thin or zero-width space, which the browser does not read as a space',
|
|
812
|
+
quotes &&
|
|
813
|
+
'curly or other quotes around a value, where CSS reads only straight ones',
|
|
814
|
+
].filter(Boolean);
|
|
653
815
|
found.push({
|
|
654
816
|
setting: s,
|
|
655
|
-
why: `${s.thing} holds
|
|
817
|
+
why: `${s.thing} holds ${why.join(', and ') || 'characters the browser does not read as written'}`,
|
|
656
818
|
fix: clean,
|
|
657
819
|
});
|
|
820
|
+
}
|
|
658
821
|
}
|
|
659
822
|
for (const s of data.settings) {
|
|
660
823
|
if (s.source !== 'token' || s.thing === skipThing || !(s.thing in TOKENS))
|
|
@@ -700,6 +863,115 @@ export function storedProblems(ctx, slug, data, skip = '') {
|
|
|
700
863
|
return found;
|
|
701
864
|
}
|
|
702
865
|
|
|
866
|
+
/** The generic families a font list ends with. */
|
|
867
|
+
const GENERIC_FAMILIES = [
|
|
868
|
+
'serif',
|
|
869
|
+
'sans-serif',
|
|
870
|
+
'monospace',
|
|
871
|
+
'system-ui',
|
|
872
|
+
'cursive',
|
|
873
|
+
'fantasy',
|
|
874
|
+
'ui-serif',
|
|
875
|
+
'ui-sans-serif',
|
|
876
|
+
'ui-monospace',
|
|
877
|
+
'ui-rounded',
|
|
878
|
+
];
|
|
879
|
+
|
|
880
|
+
/**
|
|
881
|
+
* The font list a value with a missing comma or a spaced generic means
|
|
882
|
+
* (`Georgia serif` is `Georgia, serif`, `Inter, sans serif` is `Inter,
|
|
883
|
+
* sans-serif`), with why; null when it has neither. A generic is read only
|
|
884
|
+
* in lower case, so a family named `Source Serif` stays one name.
|
|
885
|
+
* @param {string} value
|
|
886
|
+
* @returns {{value: string, why: string} | null}
|
|
887
|
+
*/
|
|
888
|
+
export function fontListMeant(value) {
|
|
889
|
+
const v = String(value).trim();
|
|
890
|
+
// A whole list in one pair of quotes or brackets (`"Inter, serif"`,
|
|
891
|
+
// `「Inter, serif」`): the quotes go around one family, so the list is
|
|
892
|
+
// what is inside.
|
|
893
|
+
const wrapped =
|
|
894
|
+
/^(?:"([^"]*,[^"]*)"|'([^']*,[^']*)'|「([^」]*,[^」]*)」|『([^』]*,[^』]*)』|“([^”]*,[^”]*)”|‘([^’]*,[^’]*)’|«([^»]*,[^»]*)»)$/.exec(
|
|
895
|
+
v,
|
|
896
|
+
);
|
|
897
|
+
if (wrapped) {
|
|
898
|
+
const inside = wrapped.slice(1).find(x => x != null) ?? '';
|
|
899
|
+
return {
|
|
900
|
+
value: (fontListMeant(inside)?.value ?? inside).trim(),
|
|
901
|
+
why: 'quotes go around one family name, not the whole list',
|
|
902
|
+
};
|
|
903
|
+
}
|
|
904
|
+
if (/["']/.test(v)) return null;
|
|
905
|
+
// Families split by `|`, `;` or ` / ` instead of commas.
|
|
906
|
+
if (
|
|
907
|
+
// (A pasted declaration, `font-family: Georgia, serif;`, is read
|
|
908
|
+
// elsewhere: a colon or a trailing `;` is no separator.)
|
|
909
|
+
!/:|\.(woff2?|ttf|otf)\b/i.test(v) &&
|
|
910
|
+
/\S\s*(?:\||;|\s\/\s)\s*\S/.test(v)
|
|
911
|
+
) {
|
|
912
|
+
const list = v
|
|
913
|
+
.split(/\s*(?:\||;|\s\/\s)\s*/)
|
|
914
|
+
.map(x => x.trim())
|
|
915
|
+
.filter(Boolean)
|
|
916
|
+
.join(', ');
|
|
917
|
+
if (list && list !== v)
|
|
918
|
+
return {
|
|
919
|
+
value: fontListMeant(list)?.value ?? list,
|
|
920
|
+
why: 'families are separated by commas',
|
|
921
|
+
};
|
|
922
|
+
}
|
|
923
|
+
if (/\bsans serif\b/.test(v) && !/\d/.test(v))
|
|
924
|
+
return {
|
|
925
|
+
value: v.replace(/\bsans serif\b/g, 'sans-serif'),
|
|
926
|
+
why: 'the generic family is sans-serif, with a dash',
|
|
927
|
+
};
|
|
928
|
+
// A comma missing before the generic family of any family in the list
|
|
929
|
+
// (`Inter, Georgia serif`), the names in any case (`georgia serif`).
|
|
930
|
+
const SHORTHAND =
|
|
931
|
+
/^(\d+(\.\d+)?(px|rem|em|pt|%)?|bold|bolder|lighter|normal|italic|oblique|small-caps)$/i;
|
|
932
|
+
// A word of a family name: letters (a digit after the first word, as in
|
|
933
|
+
// `Source Serif 4`), or a generic; never a shorthand's weight or size.
|
|
934
|
+
const familyWord = (/** @type {string} */ w, /** @type {number} */ i) =>
|
|
935
|
+
(/^[A-Za-z][A-Za-z0-9]*$/.test(w) && !SHORTHAND.test(w)) ||
|
|
936
|
+
(i > 0 && /^\d+$/.test(w)) ||
|
|
937
|
+
GENERIC_FAMILIES.includes(w);
|
|
938
|
+
const pieces = v.split(/\s*,\s*/);
|
|
939
|
+
let missing = false;
|
|
940
|
+
const fixedPieces = pieces.map(piece => {
|
|
941
|
+
const ws = piece.split(/\s+/);
|
|
942
|
+
const end = ws[ws.length - 1];
|
|
943
|
+
if (
|
|
944
|
+
ws.length > 1 &&
|
|
945
|
+
GENERIC_FAMILIES.includes(end) &&
|
|
946
|
+
ws.slice(0, -1).every(familyWord)
|
|
947
|
+
) {
|
|
948
|
+
missing = true;
|
|
949
|
+
return `${ws.slice(0, -1).join(' ')}, ${end}`;
|
|
950
|
+
}
|
|
951
|
+
return piece;
|
|
952
|
+
});
|
|
953
|
+
if (missing && pieces.length > 1)
|
|
954
|
+
return {
|
|
955
|
+
value: fixedPieces.join(', '),
|
|
956
|
+
why: 'a comma goes before each generic family',
|
|
957
|
+
};
|
|
958
|
+
if (v.includes(',')) return null;
|
|
959
|
+
const words = v.split(/\s+/);
|
|
960
|
+
const last = words[words.length - 1];
|
|
961
|
+
// Only family names before it (capitalized words), never a font
|
|
962
|
+
// shorthand's weight, style or size.
|
|
963
|
+
if (
|
|
964
|
+
words.length > 1 &&
|
|
965
|
+
GENERIC_FAMILIES.includes(last) &&
|
|
966
|
+
words.slice(0, -1).every(familyWord)
|
|
967
|
+
)
|
|
968
|
+
return {
|
|
969
|
+
value: `${words.slice(0, -1).join(' ')}, ${last}`,
|
|
970
|
+
why: `a comma goes before the generic family ${last}`,
|
|
971
|
+
};
|
|
972
|
+
return null;
|
|
973
|
+
}
|
|
974
|
+
|
|
703
975
|
/**
|
|
704
976
|
* A value of a type to put in a suggestion, so a suggested command runs.
|
|
705
977
|
* @param {string} type
|
|
@@ -772,17 +1044,37 @@ function checkTypedValue(
|
|
|
772
1044
|
}
|
|
773
1045
|
return null;
|
|
774
1046
|
};
|
|
775
|
-
/** @param {string} what @param {string} example */
|
|
1047
|
+
/** @param {string} what @param {string | null} example */
|
|
776
1048
|
const bad = (what, example) =>
|
|
777
1049
|
refuse(
|
|
778
1050
|
E.ERR_THEME_BAD_VALUE,
|
|
779
1051
|
`${name} is ${what}; "${value}" is not one.`,
|
|
780
1052
|
{
|
|
1053
|
+
// Nothing read from the value (no example given): how, never a
|
|
1054
|
+
// stock value.
|
|
781
1055
|
run: [
|
|
782
|
-
|
|
1056
|
+
(meant() ?? example) == null
|
|
1057
|
+
? `${HOW} ${name}`
|
|
1058
|
+
: `${P} set ${slug} ${name} ${quoteCommandArgument(String(meant() ?? example))}`,
|
|
783
1059
|
],
|
|
784
1060
|
},
|
|
785
1061
|
);
|
|
1062
|
+
// A font family list with a comma missing before a generic family
|
|
1063
|
+
// (`Georgia serif`), or a generic written with a space (`sans serif`): the
|
|
1064
|
+
// list meant.
|
|
1065
|
+
if (type === 'font') {
|
|
1066
|
+
const fixed = fontListMeant(value);
|
|
1067
|
+
if (fixed)
|
|
1068
|
+
refuse(
|
|
1069
|
+
E.ERR_THEME_BAD_VALUE,
|
|
1070
|
+
`"${value}" names a family that exists nowhere: ${fixed.why}.`,
|
|
1071
|
+
{
|
|
1072
|
+
run: [
|
|
1073
|
+
`${P} set ${slug} ${name} ${quoteCommandArgument(fixed.value)}`,
|
|
1074
|
+
],
|
|
1075
|
+
},
|
|
1076
|
+
);
|
|
1077
|
+
}
|
|
786
1078
|
// A font file or a link is no family name: never quoted into one.
|
|
787
1079
|
if (type === 'font') {
|
|
788
1080
|
const file = fontFileReason(pastedFont(value) || value);
|
|
@@ -792,6 +1084,18 @@ function checkTypedValue(
|
|
|
792
1084
|
`${P} set ${slug} ${name} ${quoteCommandArgument(exampleOf(type, name))}`,
|
|
793
1085
|
],
|
|
794
1086
|
});
|
|
1087
|
+
// An empty family (`""`, a trailing comma) or one quoted name holding
|
|
1088
|
+
// commas is a broken stack: the browser drops the fallback after it.
|
|
1089
|
+
const pieces = familyPieces(value);
|
|
1090
|
+
if (
|
|
1091
|
+
pieces &&
|
|
1092
|
+
(pieces.some(f => !f.name) ||
|
|
1093
|
+
pieces.some(f => f.quoted && f.name.includes(',')))
|
|
1094
|
+
)
|
|
1095
|
+
bad(
|
|
1096
|
+
'a font family list with a name for each family',
|
|
1097
|
+
exampleOf(type, name),
|
|
1098
|
+
);
|
|
795
1099
|
}
|
|
796
1100
|
if (!isSafeValue(value))
|
|
797
1101
|
refuse(
|
|
@@ -821,6 +1125,15 @@ function checkTypedValue(
|
|
|
821
1125
|
],
|
|
822
1126
|
},
|
|
823
1127
|
);
|
|
1128
|
+
// Math whose units cannot combine (`8 + 2px`, `0.5rem * 1px`, a var()
|
|
1129
|
+
// read as its fallback): the browser drops the whole value.
|
|
1130
|
+
const math = type === 'size' ? calcUnitProblem(value) : null;
|
|
1131
|
+
if (math)
|
|
1132
|
+
refuse(
|
|
1133
|
+
E.ERR_THEME_BAD_VALUE,
|
|
1134
|
+
`${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.`,
|
|
1135
|
+
{run: [`${HOW} ${name}`]},
|
|
1136
|
+
);
|
|
824
1137
|
// A var() inside a larger value (calc, max, color-mix) has a fallback of
|
|
825
1138
|
// the token's kind too, checked like a whole-value var().
|
|
826
1139
|
if (type !== 'other')
|
|
@@ -834,6 +1147,16 @@ function checkTypedValue(
|
|
|
834
1147
|
)
|
|
835
1148
|
)
|
|
836
1149
|
continue;
|
|
1150
|
+
// A factor in a size's math (`calc(0.75rem * var(--x, 1))`, as the
|
|
1151
|
+
// official themes write their type scale): a plain number there is
|
|
1152
|
+
// what multiplies the size.
|
|
1153
|
+
if (
|
|
1154
|
+
type === 'size' &&
|
|
1155
|
+
within.some(f => /^(calc|min|max|clamp)$/i.test(f)) &&
|
|
1156
|
+
/^[+-]?(\d+\.?\d*|\.\d+)$/.test(fallback.trim()) &&
|
|
1157
|
+
(/[*/]\s*var\(/i.test(value) || /var\([^()]*\)\s*[*/]/i.test(value))
|
|
1158
|
+
)
|
|
1159
|
+
continue;
|
|
837
1160
|
if (fallback === '')
|
|
838
1161
|
refuse(
|
|
839
1162
|
E.ERR_THEME_BAD_VALUE,
|
|
@@ -896,19 +1219,11 @@ function checkTypedValue(
|
|
|
896
1219
|
);
|
|
897
1220
|
return;
|
|
898
1221
|
}
|
|
899
|
-
if (type === 'color' && !isFixedColor(value)) bad('a color',
|
|
1222
|
+
if (type === 'color' && !isFixedColor(value)) bad('a color', null);
|
|
900
1223
|
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';
|
|
1224
|
+
// The token's own default is never offered as a repair: only a size
|
|
1225
|
+
// read from the value typed.
|
|
1226
|
+
const sizeExample = null;
|
|
912
1227
|
// The size meant, when one dot or sign is all that is wrong (1.px).
|
|
913
1228
|
const meant = value.trim().replace(/(\d)\.(?=[a-z%]|$)/gi, '$1');
|
|
914
1229
|
// A bare number is the size in px.
|
|
@@ -1387,6 +1702,86 @@ function baseReads(ctx, like, token) {
|
|
|
1387
1702
|
}
|
|
1388
1703
|
}
|
|
1389
1704
|
|
|
1705
|
+
/** Mode words a value may be labeled with, and the mode each means. */
|
|
1706
|
+
const MODE_WORDS = /** @type {Record<string, 'light' | 'dark'>} */ ({
|
|
1707
|
+
light: 'light',
|
|
1708
|
+
'light-mode': 'light',
|
|
1709
|
+
day: 'light',
|
|
1710
|
+
dark: 'dark',
|
|
1711
|
+
'dark-mode': 'dark',
|
|
1712
|
+
night: 'dark',
|
|
1713
|
+
});
|
|
1714
|
+
/** State words a value may be labeled with. */
|
|
1715
|
+
const STATE_WORDS = [
|
|
1716
|
+
'hover',
|
|
1717
|
+
'active',
|
|
1718
|
+
'focus',
|
|
1719
|
+
'focus-visible',
|
|
1720
|
+
'focus-within',
|
|
1721
|
+
'disabled',
|
|
1722
|
+
'pressed',
|
|
1723
|
+
'selected',
|
|
1724
|
+
'checked',
|
|
1725
|
+
'open',
|
|
1726
|
+
'expanded',
|
|
1727
|
+
'visited',
|
|
1728
|
+
];
|
|
1729
|
+
/** Words for a kind of screen a value may be labeled with. */
|
|
1730
|
+
const DEVICE_WORDS = [
|
|
1731
|
+
'phone',
|
|
1732
|
+
'phones',
|
|
1733
|
+
'mobile',
|
|
1734
|
+
'tablet',
|
|
1735
|
+
'tablets',
|
|
1736
|
+
'desktop',
|
|
1737
|
+
'laptop',
|
|
1738
|
+
'ipad',
|
|
1739
|
+
'iphone',
|
|
1740
|
+
'android',
|
|
1741
|
+
'ios',
|
|
1742
|
+
'touch',
|
|
1743
|
+
'small-screen',
|
|
1744
|
+
'small-screens',
|
|
1745
|
+
'large-screen',
|
|
1746
|
+
'large-screens',
|
|
1747
|
+
'print',
|
|
1748
|
+
];
|
|
1749
|
+
|
|
1750
|
+
/**
|
|
1751
|
+
* The word a value is labeled with and the value after it (`dark: #2563eb`,
|
|
1752
|
+
* `"corners": "pill"`, `{"dark": "#2563eb"}`, `dark=#2563eb`, `dark mode:
|
|
1753
|
+
* #2563eb`, `textSize: 18`), the word as a dashed name; null when the value
|
|
1754
|
+
* holds no label.
|
|
1755
|
+
* @param {string} value
|
|
1756
|
+
* @returns {{word: string, rest: string} | null}
|
|
1757
|
+
*/
|
|
1758
|
+
function valueLabel(value) {
|
|
1759
|
+
const m =
|
|
1760
|
+
/^\s*\{?\s*["']?([a-zA-Z][a-zA-Z0-9 _-]*?|--[a-z0-9-]+)["']?\s*[:=]\s*(.+?)\s*;?\s*\}?\s*$/.exec(
|
|
1761
|
+
String(value),
|
|
1762
|
+
);
|
|
1763
|
+
if (!m || /^https?$/i.test(m[1])) return null;
|
|
1764
|
+
const word = m[1]
|
|
1765
|
+
.trim()
|
|
1766
|
+
.replace(/([a-z0-9])([A-Z])/g, '$1-$2')
|
|
1767
|
+
.replace(/[\s_]+/g, '-')
|
|
1768
|
+
.toLowerCase();
|
|
1769
|
+
const rest = m[2].trim().replace(/^"(.*)"\s*,?$/, '$1');
|
|
1770
|
+
return {word, rest};
|
|
1771
|
+
}
|
|
1772
|
+
|
|
1773
|
+
/**
|
|
1774
|
+
* Whether a label is the setting's own name (`accent: red` for accent,
|
|
1775
|
+
* `font-family: Inter` for font).
|
|
1776
|
+
* @param {string} thing @param {string} word
|
|
1777
|
+
*/
|
|
1778
|
+
const ownLabel = (thing, word) =>
|
|
1779
|
+
word === thing ||
|
|
1780
|
+
(thing === 'font' && word === 'font-family') ||
|
|
1781
|
+
(thing.startsWith('--font-family') &&
|
|
1782
|
+
(word === 'font-family' || word === 'font')) ||
|
|
1783
|
+
(thing === 'text-size' && word === 'font-size');
|
|
1784
|
+
|
|
1390
1785
|
/**
|
|
1391
1786
|
* Check one setting and give it back ready to store, or refuse. What it
|
|
1392
1787
|
* accepts, the settings loader takes too: the loader's own check runs last,
|
|
@@ -1412,8 +1807,314 @@ export function checkSetting(
|
|
|
1412
1807
|
// Any other dial's value pasted with its property name (`font-size:
|
|
1413
1808
|
// 18px;` for text-size, `color: #e11d48` for accent) is the value: one
|
|
1414
1809
|
// path for every dial (the font dial reads its own below).
|
|
1415
|
-
|
|
1416
|
-
|
|
1810
|
+
// A light and a dark color typed as one value: a token takes both as
|
|
1811
|
+
// light-dark() or one --mode at a time; a color dial takes one color and
|
|
1812
|
+
// makes both modes from it. Never one of them for both.
|
|
1813
|
+
// A light-dark() written with another separator (`light-dark(red /
|
|
1814
|
+
// blue)`, `light-dark(red; blue)`): the pair meant, with a comma.
|
|
1815
|
+
if (!unset && typeof value === 'string') {
|
|
1816
|
+
const near =
|
|
1817
|
+
/^\s*light-dark\(\s*([^,;/()]+?)\s*(?:\s\/\s|\/|;)\s*([^,;/()]+?)\s*\)\s*$/i.exec(
|
|
1818
|
+
value,
|
|
1819
|
+
);
|
|
1820
|
+
if (near)
|
|
1821
|
+
refuse(
|
|
1822
|
+
E.ERR_THEME_BAD_VALUE,
|
|
1823
|
+
`"${value}" separates its two colors with something other than a comma; light-dark() takes "light-dark(light, dark)".`,
|
|
1824
|
+
{
|
|
1825
|
+
run: [
|
|
1826
|
+
setLine(
|
|
1827
|
+
slug,
|
|
1828
|
+
thing,
|
|
1829
|
+
`light-dark(${near[1]}, ${near[2]})`,
|
|
1830
|
+
{...flags, mode: undefined},
|
|
1831
|
+
false,
|
|
1832
|
+
),
|
|
1833
|
+
],
|
|
1834
|
+
},
|
|
1835
|
+
);
|
|
1836
|
+
}
|
|
1837
|
+
// A font list with a comma missing before its generic family, or a
|
|
1838
|
+
// generic written with a space, on the font dial: the list meant.
|
|
1839
|
+
if (!unset && typeof value === 'string' && thing === 'font') {
|
|
1840
|
+
const fixed = fontListMeant(value);
|
|
1841
|
+
if (fixed)
|
|
1842
|
+
refuse(
|
|
1843
|
+
E.ERR_THEME_BAD_VALUE,
|
|
1844
|
+
`"${value}" names a family that exists nowhere: ${fixed.why}.`,
|
|
1845
|
+
{run: [setLine(slug, 'font', fixed.value, flags, false)]},
|
|
1846
|
+
);
|
|
1847
|
+
}
|
|
1848
|
+
// A light and a dark color on a part's color property (`background`,
|
|
1849
|
+
// `color`, `border-color` …) is that property's light-dark() pair.
|
|
1850
|
+
if (
|
|
1851
|
+
!unset &&
|
|
1852
|
+
typeof value === 'string' &&
|
|
1853
|
+
flags.on &&
|
|
1854
|
+
!flags.mode &&
|
|
1855
|
+
/^(color|background|(background|border|outline|text-decoration|caret|accent|fill|stroke)(-[a-z]+)?-color)$/.test(
|
|
1856
|
+
String(thing).trim().toLowerCase(),
|
|
1857
|
+
)
|
|
1858
|
+
) {
|
|
1859
|
+
const pair = colorPair(value);
|
|
1860
|
+
if (pair && !colorProblem(pair.light) && !colorProblem(pair.dark))
|
|
1861
|
+
value = `light-dark(${pair.light}, ${pair.dark})`;
|
|
1862
|
+
}
|
|
1863
|
+
if (
|
|
1864
|
+
!unset &&
|
|
1865
|
+
typeof value === 'string' &&
|
|
1866
|
+
(PALETTE_DIALS.includes(thing) || isColorToken(thing))
|
|
1867
|
+
) {
|
|
1868
|
+
const pair = colorPair(value);
|
|
1869
|
+
if (pair && !colorProblem(pair.light) && !colorProblem(pair.dark)) {
|
|
1870
|
+
const q = quoteCommandArgument;
|
|
1871
|
+
const on = flags.on ? ` --on ${flags.on}` : '';
|
|
1872
|
+
refuse(
|
|
1873
|
+
E.ERR_THEME_BAD_VALUE,
|
|
1874
|
+
PALETTE_DIALS.includes(thing)
|
|
1875
|
+
? `"${value}" is a light and a dark color; ${thing} takes one color and makes both modes from it.`
|
|
1876
|
+
: `"${value}" is a light and a dark color; ${thing} takes them as light-dark(), or one --mode at a time.`,
|
|
1877
|
+
{
|
|
1878
|
+
run: PALETTE_DIALS.includes(thing)
|
|
1879
|
+
? [
|
|
1880
|
+
`${P} set ${slug} ${thing} ${q(pair.light)}${on}`,
|
|
1881
|
+
...(thing === 'accent'
|
|
1882
|
+
? [
|
|
1883
|
+
`${P} set ${slug} --color-accent ${q(`light-dark(${pair.light}, ${pair.dark})`)}${on}`,
|
|
1884
|
+
]
|
|
1885
|
+
: []),
|
|
1886
|
+
]
|
|
1887
|
+
: [
|
|
1888
|
+
`${P} set ${slug} ${thing} ${q(`light-dark(${pair.light}, ${pair.dark})`)}${on}`,
|
|
1889
|
+
`${P} set ${slug} ${thing} ${q(pair.light)}${on} --mode light`,
|
|
1890
|
+
`${P} set ${slug} ${thing} ${q(pair.dark)}${on} --mode dark`,
|
|
1891
|
+
],
|
|
1892
|
+
},
|
|
1893
|
+
);
|
|
1894
|
+
}
|
|
1895
|
+
}
|
|
1896
|
+
// A value labeled with a word that is not this setting's own name (a
|
|
1897
|
+
// mode, a state, a device, a part, or a word the editor does not read) is
|
|
1898
|
+
// refused with what that word means here, never set with the word dropped.
|
|
1899
|
+
// A property set on a part (`padding 'hover: 4px' --on button`) and the
|
|
1900
|
+
// type tokens (`--font-weight-bold 'dark: 700'`) are read the same way;
|
|
1901
|
+
// a content string is its own text.
|
|
1902
|
+
const partProperty =
|
|
1903
|
+
Boolean(flags.on) && !DIALS[thing] && !thing.startsWith('--');
|
|
1904
|
+
const familyToken = thing.startsWith('--font-family');
|
|
1905
|
+
if (
|
|
1906
|
+
!unset &&
|
|
1907
|
+
typeof value === 'string' &&
|
|
1908
|
+
!/content/.test(thing) &&
|
|
1909
|
+
(DIALS[thing] || partProperty || thing.startsWith('--'))
|
|
1910
|
+
) {
|
|
1911
|
+
const label = valueLabel(value);
|
|
1912
|
+
// A CSS property's name before the value (`border-radius: pill`,
|
|
1913
|
+
// `color: #e11d48`, `font: bold 16px Inter`) is read by the paths
|
|
1914
|
+
// below, as a declaration pasted from a stylesheet.
|
|
1915
|
+
if (
|
|
1916
|
+
label &&
|
|
1917
|
+
!ownLabel(thing, label.word) &&
|
|
1918
|
+
!cssProperties().has(label.word)
|
|
1919
|
+
) {
|
|
1920
|
+
const q = quoteCommandArgument;
|
|
1921
|
+
const rest = label.rest;
|
|
1922
|
+
const scope = `${flags.on ? ` --on ${flags.on}` : ''}${flags.when ? ` --when ${flags.when}` : ''}`;
|
|
1923
|
+
const mode = MODE_WORDS[label.word];
|
|
1924
|
+
const colorful =
|
|
1925
|
+
PALETTE_DIALS.includes(thing) ||
|
|
1926
|
+
(thing.startsWith('--') && isColorToken(thing)) ||
|
|
1927
|
+
(partProperty &&
|
|
1928
|
+
/color|^background$|^fill$|^stroke$|shadow/.test(thing));
|
|
1929
|
+
const parts = [...ctx.project.target.keys(), ...Object.keys(FAMILIES)];
|
|
1930
|
+
if (mode && DIALS[thing] && PALETTE_DIALS.includes(thing))
|
|
1931
|
+
refuse(
|
|
1932
|
+
E.ERR_THEME_BAD_VALUE,
|
|
1933
|
+
`"${label.word}" in "${value}" names the ${mode} mode; ${thing} makes both modes from one color.`,
|
|
1934
|
+
{
|
|
1935
|
+
run: [
|
|
1936
|
+
`${P} set ${slug} ${thing} ${q(rest)}${scope}`,
|
|
1937
|
+
...(thing === 'accent'
|
|
1938
|
+
? [
|
|
1939
|
+
`${P} set ${slug} --color-accent ${q(rest)}${scope} --mode ${mode}`,
|
|
1940
|
+
]
|
|
1941
|
+
: []),
|
|
1942
|
+
],
|
|
1943
|
+
},
|
|
1944
|
+
);
|
|
1945
|
+
const level = /^h([1-6])$/.exec(label.word)?.[1];
|
|
1946
|
+
if (level && thing === 'headings') {
|
|
1947
|
+
const w = rest.trim().toLowerCase();
|
|
1948
|
+
refuse(
|
|
1949
|
+
E.ERR_THEME_BAD_VALUE,
|
|
1950
|
+
`"${label.word}" in "${value}" is one heading level; headings sets every level, and one level is set with --on heading --when level:${level}.`,
|
|
1951
|
+
{
|
|
1952
|
+
run:
|
|
1953
|
+
HEADING_WEIGHTS[w] !== undefined
|
|
1954
|
+
? [
|
|
1955
|
+
`${P} set ${slug} font-weight ${HEADING_WEIGHTS[w]} --on heading --when level:${level}`,
|
|
1956
|
+
`${P} set ${slug} headings ${w}`,
|
|
1957
|
+
]
|
|
1958
|
+
: HEADING_TRACKING[w] !== undefined
|
|
1959
|
+
? [
|
|
1960
|
+
`${P} set ${slug} letter-spacing ${q(HEADING_TRACKING[w])} --on heading --when level:${level}`,
|
|
1961
|
+
`${P} set ${slug} headings ${w}`,
|
|
1962
|
+
]
|
|
1963
|
+
: [`${HOW} headings`],
|
|
1964
|
+
},
|
|
1965
|
+
);
|
|
1966
|
+
}
|
|
1967
|
+
if (mode)
|
|
1968
|
+
refuse(
|
|
1969
|
+
E.ERR_THEME_BAD_VALUE,
|
|
1970
|
+
colorful
|
|
1971
|
+
? `"${label.word}" in "${value}" names the ${mode} mode; a value for one mode is given with --mode ${mode}.`
|
|
1972
|
+
: `"${label.word}" in "${value}" names the ${mode} mode, and ${thing} is the same in light and dark.`,
|
|
1973
|
+
{
|
|
1974
|
+
run: [
|
|
1975
|
+
`${P} set ${slug} ${thing} ${q(rest)}${scope}${colorful ? ` --mode ${mode}` : ''}`,
|
|
1976
|
+
],
|
|
1977
|
+
},
|
|
1978
|
+
);
|
|
1979
|
+
if (STATE_WORDS.includes(label.word))
|
|
1980
|
+
refuse(
|
|
1981
|
+
E.ERR_THEME_BAD_VALUE,
|
|
1982
|
+
flags.on
|
|
1983
|
+
? `"${label.word}" in "${value}" is a state; a value for it is given with --state ${label.word}.`
|
|
1984
|
+
: `"${label.word}" in "${value}" is a state; a state is set on a part, with --on <part> --state ${label.word}.`,
|
|
1985
|
+
{
|
|
1986
|
+
run: [
|
|
1987
|
+
flags.on
|
|
1988
|
+
? `${P} set ${slug} ${thing} ${q(rest)}${scope} --state ${label.word}`
|
|
1989
|
+
: `${HOW} ${q(`${label.word} ${thing}`)}`,
|
|
1990
|
+
],
|
|
1991
|
+
},
|
|
1992
|
+
);
|
|
1993
|
+
if (DEVICE_WORDS.includes(label.word))
|
|
1994
|
+
refuse(
|
|
1995
|
+
E.ERR_THEME_BAD_VALUE,
|
|
1996
|
+
`"${label.word}" in "${value}" names a kind of screen; the editor sets ${thing} for every screen, not for one kind.`,
|
|
1997
|
+
{run: [`${P} set ${slug} ${thing} ${q(rest)}${scope}`]},
|
|
1998
|
+
);
|
|
1999
|
+
if (parts.includes(label.word))
|
|
2000
|
+
refuse(
|
|
2001
|
+
E.ERR_THEME_BAD_VALUE,
|
|
2002
|
+
`"${label.word}" in "${value}" is a part; a value for one part is given with --on ${label.word}.`,
|
|
2003
|
+
{run: [`${P} set ${slug} ${thing} ${q(rest)} --on ${label.word}`]},
|
|
2004
|
+
);
|
|
2005
|
+
// A flag's own name as the label (`state: hover`, `part: card`,
|
|
2006
|
+
// `variant: primary`, `mode: dark`): what that flag does here.
|
|
2007
|
+
const flagWord = {
|
|
2008
|
+
state: 'state',
|
|
2009
|
+
states: 'state',
|
|
2010
|
+
part: 'on',
|
|
2011
|
+
on: 'on',
|
|
2012
|
+
component: 'on',
|
|
2013
|
+
variant: 'when',
|
|
2014
|
+
size: 'when',
|
|
2015
|
+
when: 'when',
|
|
2016
|
+
prop: 'when',
|
|
2017
|
+
mode: 'mode',
|
|
2018
|
+
theme: 'mode',
|
|
2019
|
+
}[label.word];
|
|
2020
|
+
if (
|
|
2021
|
+
flagWord &&
|
|
2022
|
+
(flagWord === 'mode'
|
|
2023
|
+
? Boolean(MODE_WORDS[rest.trim().toLowerCase()])
|
|
2024
|
+
: !otherSettingLabel(thing, value))
|
|
2025
|
+
) {
|
|
2026
|
+
const r = rest.trim().toLowerCase();
|
|
2027
|
+
const m = flagWord === 'mode' ? MODE_WORDS[r] : null;
|
|
2028
|
+
const when =
|
|
2029
|
+
flagWord === 'when'
|
|
2030
|
+
? label.word === 'when' || label.word === 'prop'
|
|
2031
|
+
? r
|
|
2032
|
+
: `${label.word}:${r}`
|
|
2033
|
+
: null;
|
|
2034
|
+
refuse(
|
|
2035
|
+
E.ERR_THEME_BAD_VALUE,
|
|
2036
|
+
flagWord === 'mode'
|
|
2037
|
+
? `"${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\``}.`
|
|
2038
|
+
: flagWord === 'state'
|
|
2039
|
+
? `"${value}" names a state, not a value for ${thing}: a value for a state is given with --on <part> --state ${r}.`
|
|
2040
|
+
: flagWord === 'on'
|
|
2041
|
+
? `"${value}" names a part, not a value for ${thing}: a value for one part is given with --on ${r}.`
|
|
2042
|
+
: `"${value}" names a variant, not a value for ${thing}: a value for one variant is given with --on <part> --when ${when}.`,
|
|
2043
|
+
{
|
|
2044
|
+
didYouMean: [`--${flagWord}`],
|
|
2045
|
+
run: [
|
|
2046
|
+
flagWord === 'mode' && !colorful
|
|
2047
|
+
? `${P} set ${slug} mode ${m ?? 'dark'}-only`
|
|
2048
|
+
: `${HOW} ${q(`${r} ${thing}`)}`,
|
|
2049
|
+
],
|
|
2050
|
+
},
|
|
2051
|
+
);
|
|
2052
|
+
}
|
|
2053
|
+
// A family's own words may hold a colon; only the words above are
|
|
2054
|
+
// read there.
|
|
2055
|
+
if (!familyToken && !otherSettingLabel(thing, value))
|
|
2056
|
+
refuse(
|
|
2057
|
+
E.ERR_THEME_BAD_VALUE,
|
|
2058
|
+
`"${label.word}" in "${value}" is not a name the editor reads for ${thing}; give the value alone.`,
|
|
2059
|
+
{
|
|
2060
|
+
didYouMean: nearest(label.word, [
|
|
2061
|
+
...Object.keys(DIALS),
|
|
2062
|
+
...parts,
|
|
2063
|
+
...STATE_WORDS,
|
|
2064
|
+
]),
|
|
2065
|
+
run: [`${P} set ${slug} ${thing} ${q(rest)}${scope}`],
|
|
2066
|
+
},
|
|
2067
|
+
);
|
|
2068
|
+
}
|
|
2069
|
+
// The setting's own name before its value (`font: Inter`, `Font:
|
|
2070
|
+
// Georgia`) is the value.
|
|
2071
|
+
// (A `font:` shorthand is read whole below, as its family.)
|
|
2072
|
+
if (
|
|
2073
|
+
label &&
|
|
2074
|
+
ownLabel(thing, label.word) &&
|
|
2075
|
+
// A `font:` with a size is the shorthand, read whole below; with
|
|
2076
|
+
// only families (`font: Inter, serif`) it is the label.
|
|
2077
|
+
(label.word !== 'font' || !/\d/.test(label.rest)) &&
|
|
2078
|
+
label.rest.replace(/;+\s*$/, '').trim()
|
|
2079
|
+
)
|
|
2080
|
+
value = label.rest;
|
|
2081
|
+
}
|
|
2082
|
+
if (
|
|
2083
|
+
!unset &&
|
|
2084
|
+
typeof value === 'string' &&
|
|
2085
|
+
(DIALS[thing] || partProperty || thing.startsWith('--')) &&
|
|
2086
|
+
!/content/.test(thing)
|
|
2087
|
+
) {
|
|
2088
|
+
// A value labeled with another setting's name is that setting's, never
|
|
2089
|
+
// this one's (`accent 'neutral: #64748b'`, `--radius-element 'accent:
|
|
2090
|
+
// red'`). The value goes to this setting again only for a dial that
|
|
2091
|
+
// checks it as its own (any word is a font family, so never the font).
|
|
2092
|
+
const other = otherSettingLabel(thing, value);
|
|
2093
|
+
if (other)
|
|
2094
|
+
refuse(
|
|
2095
|
+
E.ERR_THEME_BAD_VALUE,
|
|
2096
|
+
`"${value}" is labeled ${other.thing}, another setting than ${thing}; nothing is set from it.`,
|
|
2097
|
+
{
|
|
2098
|
+
didYouMean: [other.thing],
|
|
2099
|
+
run: [
|
|
2100
|
+
`${P} set ${slug} ${other.thing} ${quoteCommandArgument(other.value)}${flags.on ? ` --on ${flags.on}` : ''}`,
|
|
2101
|
+
// Another setting is not this part's property: the whole theme.
|
|
2102
|
+
...(flags.on && partProperty
|
|
2103
|
+
? [
|
|
2104
|
+
`${P} set ${slug} ${other.thing} ${quoteCommandArgument(other.value)}`,
|
|
2105
|
+
]
|
|
2106
|
+
: []),
|
|
2107
|
+
...(DIALS[thing] && thing !== 'font'
|
|
2108
|
+
? [
|
|
2109
|
+
`${P} set ${slug} ${thing} ${quoteCommandArgument(other.value)}${flags.on ? ` --on ${flags.on}` : ''}`,
|
|
2110
|
+
]
|
|
2111
|
+
: []),
|
|
2112
|
+
],
|
|
2113
|
+
},
|
|
2114
|
+
);
|
|
2115
|
+
}
|
|
2116
|
+
if (!unset && typeof value === 'string' && DIALS[thing]) {
|
|
2117
|
+
const d = thing === 'font' ? null : pastedDeclaration(value);
|
|
1417
2118
|
if (d?.value) value = d.value;
|
|
1418
2119
|
}
|
|
1419
2120
|
// The font dial's value as pasted from a stylesheet (`Georgia, serif;`,
|
|
@@ -1628,23 +2329,71 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
1628
2329
|
.toLowerCase();
|
|
1629
2330
|
if (flags.only) s.only = true;
|
|
1630
2331
|
if (flags.mode) {
|
|
1631
|
-
|
|
1632
|
-
|
|
2332
|
+
// Read as any value is: invisible or no-break spaces, quotes around
|
|
2333
|
+
// it, a trailing colon (`'dark '`, `“dark”`, `dark:`).
|
|
2334
|
+
const mode = withoutDebris(normalValueText(String(flags.mode)))
|
|
2335
|
+
.trim()
|
|
2336
|
+
.replace(/^(["'])(.*)\1$/, '$2')
|
|
2337
|
+
.replace(/:+$/, '')
|
|
2338
|
+
.trim()
|
|
2339
|
+
.toLowerCase();
|
|
2340
|
+
if (mode !== 'light' && mode !== 'dark') {
|
|
2341
|
+
// A word for one of the two (night, day) is that one; never the
|
|
2342
|
+
// nearest spelling, which can be the other (night → light).
|
|
2343
|
+
const meant = {
|
|
2344
|
+
night: 'dark',
|
|
2345
|
+
nighttime: 'dark',
|
|
2346
|
+
dim: 'dark',
|
|
2347
|
+
black: 'dark',
|
|
2348
|
+
day: 'light',
|
|
2349
|
+
daytime: 'light',
|
|
2350
|
+
bright: 'light',
|
|
2351
|
+
white: 'light',
|
|
2352
|
+
}[mode];
|
|
2353
|
+
const near = meant ? [meant] : nearest(mode, ['light', 'dark']);
|
|
2354
|
+
// The line for that one mode: for a dial, the one `--mode dark` itself
|
|
2355
|
+
// offers (the color token for that mode), never the both-modes dial.
|
|
2356
|
+
const modeLine = (/** @type {string} */ m) => {
|
|
2357
|
+
if (DIALS[thing] && !unset)
|
|
2358
|
+
try {
|
|
2359
|
+
checkSetting(ctx, slug, data, thing, v, {...flags, mode: m});
|
|
2360
|
+
} catch (e) {
|
|
2361
|
+
const first = /** @type {any} */ (e)?.suggestions?.find(
|
|
2362
|
+
(/** @type {any} */ x) => / --mode (light|dark)\b/.test(x.name),
|
|
2363
|
+
);
|
|
2364
|
+
if (first) return first.name;
|
|
2365
|
+
}
|
|
2366
|
+
return setLine(slug, thing, v, {...s, mode: m}, unset);
|
|
2367
|
+
};
|
|
1633
2368
|
refuse(
|
|
1634
2369
|
E.ERR_THEME_BAD_VALUE,
|
|
1635
2370
|
`--mode takes light or dark, not "${flags.mode}".`,
|
|
1636
2371
|
{
|
|
1637
|
-
didYouMean:
|
|
1638
|
-
// The
|
|
1639
|
-
//
|
|
1640
|
-
run: [
|
|
2372
|
+
didYouMean: near,
|
|
2373
|
+
// The mode it is nearest keeps --mode; only with none near is the
|
|
2374
|
+
// same setting for both modes offered.
|
|
2375
|
+
run: [
|
|
2376
|
+
...(near.length === 1 ? [modeLine(near[0])] : []),
|
|
2377
|
+
// A word that means one mode (night) keeps it: the both-modes
|
|
2378
|
+
// line only for a word read by spelling.
|
|
2379
|
+
...(meant
|
|
2380
|
+
? []
|
|
2381
|
+
: [setLine(slug, thing, v, {...s, mode: undefined}, unset)]),
|
|
2382
|
+
],
|
|
1641
2383
|
},
|
|
1642
2384
|
);
|
|
2385
|
+
}
|
|
1643
2386
|
s.mode = mode;
|
|
1644
2387
|
}
|
|
1645
2388
|
const onFlag = s.on ? ` --on ${s.on}` : '';
|
|
1646
|
-
// A value that already gives both modes takes no --mode
|
|
1647
|
-
|
|
2389
|
+
// A value that already gives both modes takes no --mode (a gradient
|
|
2390
|
+
// holding a light-dark() stop included).
|
|
2391
|
+
if (
|
|
2392
|
+
s.mode &&
|
|
2393
|
+
!unset &&
|
|
2394
|
+
(/^\s*light-dark\(/i.test(v ?? '') ||
|
|
2395
|
+
(/gradient\(/i.test(v ?? '') && /light-dark\(/i.test(v ?? '')))
|
|
2396
|
+
)
|
|
1648
2397
|
refuse(
|
|
1649
2398
|
E.ERR_THEME_NO_MODE,
|
|
1650
2399
|
`"${v}" already gives both modes, so it takes no --mode; drop --mode, or give the ${s.mode} color alone.`,
|
|
@@ -1655,11 +2404,35 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
1655
2404
|
},
|
|
1656
2405
|
);
|
|
1657
2406
|
// A setting saved for a mode the theme no longer has can still be removed.
|
|
1658
|
-
|
|
2407
|
+
// An entry saved for the one mode the theme has ("[dark only]" in a
|
|
2408
|
+
// dark-only theme) can be set again with that --mode, so a doubled one
|
|
2409
|
+
// can be kept: that set replaces both.
|
|
2410
|
+
const sameModeEntry =
|
|
2411
|
+
s.mode &&
|
|
2412
|
+
data.mode === `${s.mode}-only` &&
|
|
2413
|
+
(Array.isArray(data.settings) ? data.settings : []).some(
|
|
2414
|
+
(/** @type {any} */ x) =>
|
|
2415
|
+
x &&
|
|
2416
|
+
x.thing === thing &&
|
|
2417
|
+
x.mode === s.mode &&
|
|
2418
|
+
(x.on ?? null) === (s.on ?? null) &&
|
|
2419
|
+
(x.when ?? null) === (s.when ?? null) &&
|
|
2420
|
+
(x.state ?? null) === (s.state ?? null),
|
|
2421
|
+
);
|
|
2422
|
+
if (s.mode && data.mode !== 'both' && !unset && !sameModeEntry)
|
|
1659
2423
|
refuse(
|
|
1660
2424
|
E.ERR_THEME_NO_MODE,
|
|
1661
2425
|
`This theme is ${data.mode}; --mode is for themes with both modes.`,
|
|
1662
|
-
{
|
|
2426
|
+
{
|
|
2427
|
+
run: [
|
|
2428
|
+
// For the mode the theme does not show, both modes first; the
|
|
2429
|
+
// same setting for the theme's own mode keeps where it applies.
|
|
2430
|
+
...((data.mode === 'light-only' ? 'light' : 'dark') !== s.mode
|
|
2431
|
+
? [`${P} set ${slug} mode both`]
|
|
2432
|
+
: []),
|
|
2433
|
+
`${P} set ${slug} ${thing} ${quoteCommandArgument(v)}${onFlag}${s.when ? ` --when ${s.when}` : ''}${s.state ? ` --state ${s.state}` : ''}`,
|
|
2434
|
+
],
|
|
2435
|
+
},
|
|
1663
2436
|
);
|
|
1664
2437
|
if ((s.when || s.state) && !s.on)
|
|
1665
2438
|
refuse(E.ERR_MISSING_ARGUMENT, '--when and --state need --on <part>.', {
|
|
@@ -1693,29 +2466,54 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
1693
2466
|
// Another case of a part or group, its class name copied from the
|
|
1694
2467
|
// page (`.astryx-card`), or its component (`<Card>`, `Card`): that
|
|
1695
2468
|
// part, as a working command with every flag kept.
|
|
2469
|
+
// Stray punctuation from a copied list ("text-input,") and the dashes
|
|
2470
|
+
// autocorrect types ("text\u2013input") are not part of the name.
|
|
1696
2471
|
const lower = s.on
|
|
2472
|
+
.replace(/[\u2010-\u2015\u2212]/g, '-')
|
|
2473
|
+
.replace(/^[\s,;:.'"`]+|[\s,;:.'"`]+$/g, '')
|
|
1697
2474
|
.trim()
|
|
1698
2475
|
.replace(/^<\/?\s*|\s*\/?>$/g, '')
|
|
1699
2476
|
.replace(/^\./, '')
|
|
1700
2477
|
.replace(/^astryx-/, '')
|
|
1701
2478
|
.replace(/([a-z0-9])([A-Z])/g, '$1-$2')
|
|
1702
2479
|
.toLowerCase();
|
|
2480
|
+
// A part named in words (dialog header, text inputs) is the dashed
|
|
2481
|
+
// part, read before any group a single word of it names.
|
|
2482
|
+
const dashed = lower.trim().replace(/[\s_]+/g, '-');
|
|
1703
2483
|
// A plain word how reads as a part or group (checkboxes: checks).
|
|
1704
2484
|
const byWord = partForWord(lower);
|
|
1705
2485
|
// A plain plural of a part (cards, dialogs, tabs) is that part.
|
|
1706
|
-
const singular = [
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
2486
|
+
const singular = [lower, dashed]
|
|
2487
|
+
.flatMap(w => [
|
|
2488
|
+
w.replace(/ies$/, 'y'),
|
|
2489
|
+
w.replace(/(ch|sh|x|s)es$/, '$1'),
|
|
2490
|
+
w.replace(/s$/, ''),
|
|
2491
|
+
])
|
|
2492
|
+
.find(x => x !== lower && (TARGET.has(x) || FAMILIES[x]));
|
|
1711
2493
|
const named =
|
|
1712
2494
|
TARGET.has(lower) || FAMILIES[lower]
|
|
1713
2495
|
? lower
|
|
1714
|
-
:
|
|
1715
|
-
?
|
|
1716
|
-
:
|
|
1717
|
-
?
|
|
1718
|
-
:
|
|
2496
|
+
: TARGET.has(dashed) || FAMILIES[dashed]
|
|
2497
|
+
? dashed
|
|
2498
|
+
: singular
|
|
2499
|
+
? singular
|
|
2500
|
+
: byWord && (TARGET.has(byWord) || FAMILIES[byWord])
|
|
2501
|
+
? byWord
|
|
2502
|
+
: null;
|
|
2503
|
+
// The page (the body behind every part) is painted by the app shell.
|
|
2504
|
+
if (
|
|
2505
|
+
!named &&
|
|
2506
|
+
/^(page|body|app|background|page-background)$/i.test(s.on) &&
|
|
2507
|
+
TARGET.has('app-shell')
|
|
2508
|
+
)
|
|
2509
|
+
refuse(
|
|
2510
|
+
E.ERR_THEME_UNKNOWN_PART,
|
|
2511
|
+
`"${s.on}" is not a part name; the page behind your parts is app-shell (a background there shows in every AppShell variant).`,
|
|
2512
|
+
{
|
|
2513
|
+
didYouMean: ['app-shell'],
|
|
2514
|
+
run: [setLine(slug, thing, v, {...s, on: 'app-shell'}, unset)],
|
|
2515
|
+
},
|
|
2516
|
+
);
|
|
1719
2517
|
if (named)
|
|
1720
2518
|
refuse(
|
|
1721
2519
|
E.ERR_THEME_UNKNOWN_PART,
|
|
@@ -1742,6 +2540,26 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
1742
2540
|
);
|
|
1743
2541
|
}
|
|
1744
2542
|
if (s.when) {
|
|
2543
|
+
// A prop and value in other letters, with spaces or `=` between
|
|
2544
|
+
// (`Variant: Primary`, `variant=primary`): the working command.
|
|
2545
|
+
const m = /^\s*([^:=\s]+)\s*[:=]\s*([^:=]+?)\s*$/.exec(s.when);
|
|
2546
|
+
if (m) {
|
|
2547
|
+
const prop = t.props.find(x => x.toLowerCase() === m[1].toLowerCase());
|
|
2548
|
+
const vals = prop ? (C.variantValues(s.on)[prop] ?? []) : [];
|
|
2549
|
+
const val = vals.length
|
|
2550
|
+
? vals.find(x => x.toLowerCase() === m[2].toLowerCase())
|
|
2551
|
+
: m[2];
|
|
2552
|
+
const when = prop && val ? `${prop}:${val}` : null;
|
|
2553
|
+
if (when && when !== s.when)
|
|
2554
|
+
refuse(
|
|
2555
|
+
E.ERR_THEME_UNKNOWN_VARIANT,
|
|
2556
|
+
`--when "${s.when}" is written ${when}.`,
|
|
2557
|
+
{
|
|
2558
|
+
didYouMean: [when],
|
|
2559
|
+
run: [setLine(slug, thing, v, {...s, when}, unset)],
|
|
2560
|
+
},
|
|
2561
|
+
);
|
|
2562
|
+
}
|
|
1745
2563
|
const [p, wv, ...more] = s.when.split(':');
|
|
1746
2564
|
if (!wv || more.length)
|
|
1747
2565
|
refuse(
|
|
@@ -1764,12 +2582,21 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
1764
2582
|
);
|
|
1765
2583
|
}
|
|
1766
2584
|
const states = [...t.states, ...COMMON_STATES];
|
|
2585
|
+
// A state the part lists in camelCase (toggle-button's isPressed) typed
|
|
2586
|
+
// in any case or with dashes is that state.
|
|
2587
|
+
const flat = (/** @type {string} */ x) =>
|
|
2588
|
+
x.replace(/[-_\s]/g, '').toLowerCase();
|
|
2589
|
+
if (s.state && !states.includes(s.state)) {
|
|
2590
|
+
const same = states.find(x => flat(x) === flat(String(s.state)));
|
|
2591
|
+
if (same) s.state = same;
|
|
2592
|
+
}
|
|
1767
2593
|
// Other words for a state, mapped to the one the part has; with none
|
|
1768
2594
|
// near, the list of its states (never a guess such as hover).
|
|
1769
2595
|
const SYNONYMS = wordTable(
|
|
1770
2596
|
/** @type {Record<string, string[]>} */ ({
|
|
1771
|
-
pressed: ['active'],
|
|
1772
|
-
press: ['active'],
|
|
2597
|
+
pressed: ['isPressed', 'active'],
|
|
2598
|
+
press: ['isPressed', 'active'],
|
|
2599
|
+
on: ['isPressed', 'checked', 'selected'],
|
|
1773
2600
|
down: ['active'],
|
|
1774
2601
|
clicked: ['active'],
|
|
1775
2602
|
hovered: ['hover'],
|
|
@@ -2131,6 +2958,38 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
2131
2958
|
})(),
|
|
2132
2959
|
},
|
|
2133
2960
|
);
|
|
2961
|
+
// A comparative weight word is the weight (lighter is light, never the
|
|
2962
|
+
// tracking tighter); two words (`bold tight`, `bold, tight`) are a
|
|
2963
|
+
// weight and a tracking, one line each.
|
|
2964
|
+
if (!unset) {
|
|
2965
|
+
const MORE = /** @type {Record<string, string>} */ ({
|
|
2966
|
+
lighter: 'light',
|
|
2967
|
+
thinner: 'light',
|
|
2968
|
+
bolder: 'bold',
|
|
2969
|
+
heavier: 'heavy',
|
|
2970
|
+
wider: 'wide',
|
|
2971
|
+
looser: 'wide',
|
|
2972
|
+
});
|
|
2973
|
+
const words = String(v ?? '')
|
|
2974
|
+
.trim()
|
|
2975
|
+
.toLowerCase()
|
|
2976
|
+
.split(/[\s,]+/)
|
|
2977
|
+
.filter(Boolean)
|
|
2978
|
+
.map(w => MORE[w] ?? w);
|
|
2979
|
+
const known = (/** @type {string} */ w) =>
|
|
2980
|
+
HEADING_WEIGHTS[w] !== undefined || HEADING_TRACKING[w] !== undefined;
|
|
2981
|
+
if (
|
|
2982
|
+
(words.length > 1 || MORE[String(v).trim().toLowerCase()]) &&
|
|
2983
|
+
words.every(known)
|
|
2984
|
+
)
|
|
2985
|
+
refuse(
|
|
2986
|
+
E.ERR_THEME_BAD_VALUE,
|
|
2987
|
+
words.length > 1
|
|
2988
|
+
? `"${v}" is ${words.length} headings values; headings takes one at a time (a weight and a tracking are two settings).`
|
|
2989
|
+
: `"${v}" is the weight ${words[0]}.`,
|
|
2990
|
+
{run: words.map(w => `${P} set ${slug} headings ${w}`)},
|
|
2991
|
+
);
|
|
2992
|
+
}
|
|
2134
2993
|
if (s.mode)
|
|
2135
2994
|
refuse(
|
|
2136
2995
|
E.ERR_THEME_NO_MODE,
|
|
@@ -2486,7 +3345,10 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
2486
3345
|
{
|
|
2487
3346
|
...(meant ? {didYouMean: [meant]} : {}),
|
|
2488
3347
|
// The same scope, flags included.
|
|
2489
|
-
|
|
3348
|
+
// Nothing near: how corners, never a stock rung.
|
|
3349
|
+
run: [
|
|
3350
|
+
meant ? setLine(slug, 'corners', meant, s) : `${HOW} corners`,
|
|
3351
|
+
],
|
|
2490
3352
|
},
|
|
2491
3353
|
);
|
|
2492
3354
|
}
|
|
@@ -2568,15 +3430,15 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
2568
3430
|
SPACING.map(([n]) => n),
|
|
2569
3431
|
),
|
|
2570
3432
|
run: [
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
'spacing',
|
|
2574
|
-
nearest(
|
|
3433
|
+
(() => {
|
|
3434
|
+
const near = nearest(
|
|
2575
3435
|
v,
|
|
2576
3436
|
SPACING.map(([n]) => n),
|
|
2577
|
-
)[0]
|
|
2578
|
-
|
|
2579
|
-
|
|
3437
|
+
)[0];
|
|
3438
|
+
return near
|
|
3439
|
+
? setLine(slug, 'spacing', near, s)
|
|
3440
|
+
: `${HOW} spacing`;
|
|
3441
|
+
})(),
|
|
2580
3442
|
],
|
|
2581
3443
|
},
|
|
2582
3444
|
);
|
|
@@ -2665,13 +3527,24 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
2665
3527
|
.replace(/\s*!important\s*$/i, '')
|
|
2666
3528
|
.replace(/;+\s*$/, '')
|
|
2667
3529
|
.trim()
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
.replace(
|
|
2671
|
-
|
|
3530
|
+
// A hex written 0x… (as in code) is that hex.
|
|
3531
|
+
.replace(/^0x([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i, '#$1')
|
|
3532
|
+
.replace(/^([0-9a-f]{3}|[0-9a-f]{6})$/i, '#$1');
|
|
3533
|
+
// A hex a digit short or over is refused as it is: the digit
|
|
3534
|
+
// missing could be anywhere, so none is made up.
|
|
3535
|
+
// A name of several words with a color among them (`navy blue`)
|
|
3536
|
+
// is that color.
|
|
3537
|
+
const named = v
|
|
3538
|
+
.toLowerCase()
|
|
3539
|
+
.split(/[\s,-]+/)
|
|
3540
|
+
.filter(w => COLOR_NAMES.includes(w));
|
|
2672
3541
|
const near =
|
|
2673
3542
|
problem.kind === 'unknown'
|
|
2674
|
-
?
|
|
3543
|
+
? /^#?[0-9a-f]{4,8}$/i.test(v.trim())
|
|
3544
|
+
? []
|
|
3545
|
+
: named.length
|
|
3546
|
+
? named.slice(0, 1)
|
|
3547
|
+
: nearest(v.toLowerCase(), COLOR_NAMES)
|
|
2675
3548
|
: [];
|
|
2676
3549
|
// light-dark(a, b): the dial takes one color, from which it makes
|
|
2677
3550
|
// both modes; the light one is offered.
|
|
@@ -2735,12 +3608,23 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
2735
3608
|
if (!step && canApply && (!/^\d{1,3}$/.test(v) || Number(v) > 100)) {
|
|
2736
3609
|
// The value meant: a step in other letters (MORE), or the number
|
|
2737
3610
|
// read as CSS reads it (70%, 7e1), kept in range.
|
|
2738
|
-
|
|
2739
|
-
const
|
|
3611
|
+
// Quotes around it (`"50"`) are not part of it.
|
|
3612
|
+
const bare = v
|
|
3613
|
+
.trim()
|
|
3614
|
+
.replace(/^(["'])(.*)\1$/, '$2')
|
|
3615
|
+
.trim();
|
|
3616
|
+
const word = bare.toLowerCase();
|
|
3617
|
+
const n = cssNumber(bare);
|
|
3618
|
+
// A fraction of one (0.5) is that share of the scale (50), as a
|
|
3619
|
+
// number with no unit from 0 to 1 is read.
|
|
3620
|
+
const scaled =
|
|
3621
|
+
n && n.unit === '' && n.value > 0 && n.value < 1
|
|
3622
|
+
? n.value * 100
|
|
3623
|
+
: n?.value;
|
|
2740
3624
|
const near = ['more', 'less'].includes(word)
|
|
2741
3625
|
? word
|
|
2742
|
-
: n && (n.unit === '' || n.unit === '%')
|
|
2743
|
-
? String(Math.max(0, Math.min(100, Math.round(
|
|
3626
|
+
: n && (n.unit === '' || n.unit === '%') && scaled != null
|
|
3627
|
+
? String(Math.max(0, Math.min(100, Math.round(scaled))))
|
|
2744
3628
|
: null;
|
|
2745
3629
|
refuse(
|
|
2746
3630
|
E.ERR_THEME_BAD_VALUE,
|
|
@@ -2758,8 +3642,24 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
2758
3642
|
E.ERR_THEME_NO_EFFECT,
|
|
2759
3643
|
colors.length
|
|
2760
3644
|
? '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
|
-
|
|
3645
|
+
: (() => {
|
|
3646
|
+
// Colors set as tokens or on parts are values of their own:
|
|
3647
|
+
// vibrancy saturates only what the color dials make.
|
|
3648
|
+
const own = data.settings.find(
|
|
3649
|
+
(/** @type {any} */ x) =>
|
|
3650
|
+
x &&
|
|
3651
|
+
typeof x.value === 'string' &&
|
|
3652
|
+
(/^--color-/.test(String(x.thing)) ||
|
|
3653
|
+
/(^|-)colou?r$|^background(-color)?$|^fill$/.test(
|
|
3654
|
+
String(x.thing),
|
|
3655
|
+
)) &&
|
|
3656
|
+
parseColor(x.value) != null,
|
|
3657
|
+
);
|
|
3658
|
+
return own
|
|
3659
|
+
? `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.`
|
|
3660
|
+
: 'vibrancy sets how saturated the generated colors are, and this theme sets no color yet. Set one first.';
|
|
3661
|
+
})(),
|
|
3662
|
+
{run: [`${HOW} accent`]},
|
|
2763
3663
|
);
|
|
2764
3664
|
} else if (thing === 'font') {
|
|
2765
3665
|
if (s.when || s.state)
|
|
@@ -3053,6 +3953,19 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
3053
3953
|
],
|
|
3054
3954
|
},
|
|
3055
3955
|
);
|
|
3956
|
+
// A dial typed as a flag (--corners round): the dial is meant.
|
|
3957
|
+
const dial = thing.replace(/^-+/, '');
|
|
3958
|
+
if (
|
|
3959
|
+
!(thing in TOKENS) &&
|
|
3960
|
+
(dial in DIALS || dial === 'base' || dial === 'mode')
|
|
3961
|
+
)
|
|
3962
|
+
refuse(
|
|
3963
|
+
E.ERR_THEME_UNKNOWN_TOKEN,
|
|
3964
|
+
`"${thing}" is not a design token; ${dial} is a dial, typed without dashes.`,
|
|
3965
|
+
{
|
|
3966
|
+
run: [setLine(slug, dial, v, {...s, mode: undefined}, unset)],
|
|
3967
|
+
},
|
|
3968
|
+
);
|
|
3056
3969
|
if (!(thing in TOKENS)) {
|
|
3057
3970
|
refuse(E.ERR_THEME_UNKNOWN_TOKEN, `"${thing}" is not a design token.`, {
|
|
3058
3971
|
didYouMean: nearest(thing, Object.keys(TOKENS)),
|
|
@@ -3201,6 +4114,8 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
3201
4114
|
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
4115
|
else if (r && data.like && baseReads(ctx, data.like, thing))
|
|
3203
4116
|
s.note = `the ${data.like} theme's own part styles read ${thing}, so the change shows where they use it`;
|
|
4117
|
+
else if (r && coreStylesRead(ctx, thing))
|
|
4118
|
+
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
4119
|
else if (r && dialWrites(thing))
|
|
3205
4120
|
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
4121
|
// The editor's record of what parts read comes from one render of
|
|
@@ -3376,7 +4291,14 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
3376
4291
|
}
|
|
3377
4292
|
// Text, headings and links take their color from the color prop.
|
|
3378
4293
|
const textParts = COLOR_PROP_PARTS;
|
|
4294
|
+
// A heading's color is written as the text color tokens its color prop
|
|
4295
|
+
// reads, on the heading alone (compileTheme), so it shows.
|
|
4296
|
+
const headingColor =
|
|
4297
|
+
prop === 'color' &&
|
|
4298
|
+
partsOf(ctx, s).length > 0 &&
|
|
4299
|
+
partsOf(ctx, s).every(t => t === 'heading');
|
|
3379
4300
|
if (
|
|
4301
|
+
!headingColor &&
|
|
3380
4302
|
(prop === 'color' || prop === '-webkit-text-fill-color') &&
|
|
3381
4303
|
partsOf(ctx, s).some(t => textParts.includes(t))
|
|
3382
4304
|
) {
|
|
@@ -3405,62 +4327,9 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
3405
4327
|
}
|
|
3406
4328
|
s.note = `text, heading and link inside ${s.on} keep the color their color prop gives; set --color-text-primary for those`;
|
|
3407
4329
|
}
|
|
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
|
-
}
|
|
4330
|
+
// One mode on a part whose variants each read their own color is
|
|
4331
|
+
// written to each variant's rule with that variant's own other half
|
|
4332
|
+
// (compileTheme), so it needs no variant named.
|
|
3464
4333
|
if (!isSafeValue(v))
|
|
3465
4334
|
refuse(
|
|
3466
4335
|
E.ERR_THEME_BAD_VALUE,
|
|
@@ -3536,18 +4405,53 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
3536
4405
|
if (
|
|
3537
4406
|
s.mode &&
|
|
3538
4407
|
!COLOR_PROPS.test(prop) &&
|
|
3539
|
-
!(prop === 'background' && isColorValue(v))
|
|
4408
|
+
!(prop === 'background' && isColorValue(v)) &&
|
|
4409
|
+
// A gradient background (no image file) goes per mode: its colors
|
|
4410
|
+
// are each painted in that mode only (compileTheme).
|
|
4411
|
+
!(
|
|
4412
|
+
/^background(-image)?$/.test(prop) &&
|
|
4413
|
+
/gradient\(/i.test(v) &&
|
|
4414
|
+
!/url\(/i.test(v)
|
|
4415
|
+
)
|
|
3540
4416
|
) {
|
|
3541
4417
|
// A color mixed into the value (a border's) can go per mode on its
|
|
3542
4418
|
// own; a value with none (a radius) is just set for both modes.
|
|
3543
4419
|
const hasColor = /#[0-9a-f]{3,8}\b|rgba?\(|hsla?\(/i.test(v);
|
|
3544
|
-
|
|
3545
|
-
|
|
3546
|
-
|
|
3547
|
-
|
|
3548
|
-
|
|
3549
|
-
|
|
3550
|
-
|
|
4420
|
+
// A gradient's colors sit in its image, above any background-color:
|
|
4421
|
+
// no color step can make them differ per mode.
|
|
4422
|
+
const alt =
|
|
4423
|
+
!hasColor || /gradient\(/i.test(v)
|
|
4424
|
+
? null
|
|
4425
|
+
: prop === 'border' || prop.startsWith('border-')
|
|
4426
|
+
? 'border-color'
|
|
4427
|
+
: prop === 'background'
|
|
4428
|
+
? 'background-color'
|
|
4429
|
+
: null;
|
|
4430
|
+
// On a part whose variants each have their own color, the color per
|
|
4431
|
+
// mode is set for one variant at a time (as that refusal says): the
|
|
4432
|
+
// step names the default one, or the first.
|
|
4433
|
+
let altWhen = '';
|
|
4434
|
+
if (alt && !s.when) {
|
|
4435
|
+
const g = C.groupOfProp(alt);
|
|
4436
|
+
const variants = [
|
|
4437
|
+
...new Set(
|
|
4438
|
+
partsOf(ctx, s).flatMap(t =>
|
|
4439
|
+
(g ? C.partReads(t, g) : [])
|
|
4440
|
+
.filter(r => r.props.includes(alt))
|
|
4441
|
+
.flatMap(r => r.when)
|
|
4442
|
+
.map(w => /^variant=([\w-]+)$/.exec(w)?.[1])
|
|
4443
|
+
.filter(Boolean),
|
|
4444
|
+
),
|
|
4445
|
+
),
|
|
4446
|
+
];
|
|
4447
|
+
const plain = partsOf(ctx, s).some(t =>
|
|
4448
|
+
(g ? C.partReads(t, g) : []).some(
|
|
4449
|
+
r => r.props.includes(alt) && r.when.includes(''),
|
|
4450
|
+
),
|
|
4451
|
+
);
|
|
4452
|
+
if (variants.length && !plain)
|
|
4453
|
+
altWhen = ` --when variant:${variants.includes('default') ? 'default' : variants[0]}`;
|
|
4454
|
+
}
|
|
3551
4455
|
refuse(
|
|
3552
4456
|
E.ERR_THEME_NO_MODE,
|
|
3553
4457
|
`--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 +4459,7 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
3555
4459
|
run: alt
|
|
3556
4460
|
? [
|
|
3557
4461
|
`${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`,
|
|
4462
|
+
`${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
4463
|
]
|
|
3560
4464
|
: [
|
|
3561
4465
|
`${P} set ${slug} ${prop} ${quoteCommandArgument(v)} --on ${s.on}${whenFlag} # both modes`,
|
|
@@ -3570,8 +4474,21 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
3570
4474
|
if (
|
|
3571
4475
|
s.mode &&
|
|
3572
4476
|
s.state &&
|
|
3573
|
-
!partsOf(ctx, s).every(
|
|
3574
|
-
|
|
4477
|
+
!partsOf(ctx, s).every(
|
|
4478
|
+
t =>
|
|
4479
|
+
partDefault(ctx, t, camel(prop), s.when, s.state) ||
|
|
4480
|
+
// The base theme's own value there (in the state, else at rest)
|
|
4481
|
+
// is what the other mode keeps.
|
|
4482
|
+
[`:${s.state}`, null].some(st =>
|
|
4483
|
+
baseRuleHas(
|
|
4484
|
+
ctx.project.cwd,
|
|
4485
|
+
data.like,
|
|
4486
|
+
t,
|
|
4487
|
+
s.when ?? 'base',
|
|
4488
|
+
st,
|
|
4489
|
+
camel(prop),
|
|
4490
|
+
),
|
|
4491
|
+
),
|
|
3575
4492
|
) &&
|
|
3576
4493
|
!data.settings.some(
|
|
3577
4494
|
x =>
|
|
@@ -3849,78 +4766,38 @@ export function fontFileReason(value) {
|
|
|
3849
4766
|
}
|
|
3850
4767
|
|
|
3851
4768
|
/**
|
|
3852
|
-
* A
|
|
3853
|
-
*
|
|
3854
|
-
* the browser reads only a plain space as one.
|
|
3855
|
-
* @param {string} v
|
|
4769
|
+
* A word as a suggested command quotes it, without the quotes.
|
|
4770
|
+
* @param {string} word
|
|
3856
4771
|
*/
|
|
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('');
|
|
4772
|
+
function unquoteArg(word) {
|
|
4773
|
+
const m = /^'(.*)'$/s.exec(word.trim());
|
|
4774
|
+
return m ? m[1].replace(/'\\''/g, "'") : word.trim();
|
|
3874
4775
|
}
|
|
3875
4776
|
|
|
4777
|
+
/** Core's stylesheet text, by project folder. @type {Map<string, string>} */
|
|
4778
|
+
const coreStyles = new Map();
|
|
4779
|
+
|
|
3876
4780
|
/**
|
|
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}}
|
|
4781
|
+
* Whether Core's own stylesheet reads a token anywhere (a part the editor
|
|
4782
|
+
* does not render, such as the app shell behind the page, included).
|
|
4783
|
+
* @param {any} ctx
|
|
4784
|
+
* @param {string} token
|
|
3885
4785
|
*/
|
|
3886
|
-
|
|
3887
|
-
|
|
3888
|
-
let
|
|
3889
|
-
|
|
3890
|
-
|
|
3891
|
-
|
|
3892
|
-
|
|
3893
|
-
|
|
3894
|
-
|
|
3895
|
-
|
|
3896
|
-
|
|
3897
|
-
pasted = true;
|
|
4786
|
+
function coreStylesRead(ctx, token) {
|
|
4787
|
+
const cwd = String(ctx?.project?.cwd ?? '');
|
|
4788
|
+
let css = coreStyles.get(cwd);
|
|
4789
|
+
if (css == null) {
|
|
4790
|
+
try {
|
|
4791
|
+
css = fs.readFileSync(
|
|
4792
|
+
ctx.project.req.resolve('@astryxdesign/core/astryx.css'),
|
|
4793
|
+
'utf8',
|
|
4794
|
+
);
|
|
4795
|
+
} catch {
|
|
4796
|
+
css = '';
|
|
3898
4797
|
}
|
|
4798
|
+
coreStyles.set(cwd, css);
|
|
3899
4799
|
}
|
|
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,
|
|
4800
|
+
return new RegExp(`var\\(\\s*${token.replace(/[-]/g, '\\-')}\\s*[,)]`).test(
|
|
4801
|
+
css,
|
|
3910
4802
|
);
|
|
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
4803
|
}
|