@astryxdesign/cli 0.7.17 → 0.7.18-canary.g6dfc0b6
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 +1 -1
- package/api/discover/_adapter.d.mts +7 -5
- package/api/discover/_adapter.mjs +12 -11
- package/api/doctor/_adapter.d.mts +11 -62
- package/api/doctor/_adapter.mjs +242 -472
- package/api/doctor/doctor.d.mts +1 -1
- package/api/doctor/doctor.mjs +1 -1
- package/api/doctor/theme-checks.mjs +37 -45
- package/api/error.d.mts +21 -0
- package/api/error.mjs +89 -0
- package/api/hook/list/list.d.mts +1 -1
- package/api/icon/icon.doc.mjs +1 -1
- package/api/icon/icon.type.mjs +1 -1
- package/api/icon/search/search.d.mts +4 -1
- package/api/icon/search/search.mjs +41 -4
- package/api/render/_adapter.mjs +233 -40
- package/api/render/render.type.d.mts +1 -1
- package/api/render/render.type.mjs +1 -1
- package/api/search/ORDERING.md +2 -2
- package/api/search/_candidate-score.mjs +32 -8
- package/api/search/_cards.json +1 -1
- package/api/search/_compound.d.mts +0 -1
- package/api/search/_compound.mjs +93 -2
- package/api/search/_lexical.mjs +177 -17
- package/api/search/_order.d.mts +3 -1
- package/api/search/_order.mjs +16 -5
- package/api/search/_result.d.mts +9 -0
- package/api/search/_result.mjs +10 -0
- package/api/search/_score.mjs +21 -3
- package/api/swizzle/_moduleGraph.d.mts +8 -0
- package/api/swizzle/_moduleGraph.mjs +61 -3
- package/api/template/copy/copy.mjs +5 -3
- package/api/theme/_adapter.mjs +48 -12
- package/api/theme/build/build.d.mts +4 -0
- package/api/theme/build/build.mjs +69 -18
- package/api/theme/build/style-keys.mjs +4 -5
- package/api/theme/build/theme-object.mjs +5 -0
- package/api/theme/palette/generate/color.d.mts +47 -0
- package/api/theme/palette/generate/color.mjs +58 -1
- package/api/theme/palette/generate/derive-look.d.mts +293 -0
- package/api/theme/palette/generate/derive-look.mjs +1362 -0
- package/api/theme/palette/generate/editor-look.d.mts +62 -0
- package/api/theme/palette/generate/editor-look.mjs +550 -0
- package/api/theme/palette/generate/mapping.d.mts +94 -9
- package/api/theme/palette/generate/mapping.mjs +94 -22
- package/api/theme-edit/_adapter.mjs +10 -1
- package/api/theme-edit/_catalog.d.mts +13 -13
- package/api/theme-edit/_catalog.mjs +38 -16
- package/api/theme-edit/_check.d.mts +82 -6
- package/api/theme-edit/_check.mjs +1230 -223
- package/api/theme-edit/_color.d.mts +74 -0
- package/api/theme-edit/_color.mjs +168 -3
- package/api/theme-edit/_compiler.d.mts +3 -5
- package/api/theme-edit/_compiler.mjs +122 -23
- package/api/theme-edit/_context.d.mts +46 -5
- package/api/theme-edit/_context.mjs +97 -49
- package/api/theme-edit/_css.d.mts +11 -0
- package/api/theme-edit/_css.mjs +40 -0
- package/api/theme-edit/_edit.d.mts +13 -0
- package/api/theme-edit/_edit.mjs +1450 -128
- package/api/theme-edit/_how-commands.d.mts +12 -0
- package/api/theme-edit/_how-commands.mjs +96 -14
- package/api/theme-edit/_how-question.d.mts +73 -29
- package/api/theme-edit/_how-question.mjs +8131 -1209
- package/api/theme-edit/_how-sides.d.mts +22 -0
- package/api/theme-edit/_how-sides.mjs +173 -0
- package/api/theme-edit/_how-steps.d.mts +42 -0
- package/api/theme-edit/_how-steps.mjs +208 -0
- package/api/theme-edit/_how-values.d.mts +29 -0
- package/api/theme-edit/_how-values.mjs +111 -0
- package/api/theme-edit/_how-words.d.mts +15 -0
- package/api/theme-edit/_how-words.mjs +239 -0
- package/api/theme-edit/_how.d.mts +1 -1
- package/api/theme-edit/_how.mjs +412 -37
- package/api/theme-edit/_missed.d.mts +2 -1
- package/api/theme-edit/_missed.mjs +125 -13
- package/api/theme-edit/_normal.d.mts +5 -3
- package/api/theme-edit/_normal.mjs +54 -14
- package/api/theme-edit/_palette.d.mts +204 -4
- package/api/theme-edit/_palette.mjs +901 -25
- package/api/theme-edit/_part-pieces.d.mts +54 -0
- package/api/theme-edit/_part-pieces.mjs +179 -0
- package/api/theme-edit/_part-words.mjs +33 -5
- package/api/theme-edit/_parts.d.mts +133 -0
- package/api/theme-edit/_parts.mjs +599 -10
- package/api/theme-edit/_picture-traits.d.mts +259 -0
- package/api/theme-edit/_picture-traits.mjs +1030 -0
- package/api/theme-edit/_preview.d.mts +84 -4
- package/api/theme-edit/_preview.mjs +260 -24
- package/api/theme-edit/_project.d.mts +14 -4
- package/api/theme-edit/_project.mjs +95 -26
- package/api/theme-edit/_set-line.d.mts +29 -0
- package/api/theme-edit/_set-line.mjs +100 -0
- package/api/theme-edit/_settings.d.mts +625 -28
- package/api/theme-edit/_settings.mjs +4587 -880
- package/api/theme-edit/_tables.d.mts +25 -1
- package/api/theme-edit/_tables.mjs +115 -11
- package/api/theme-edit/_text-looks.d.mts +78 -0
- package/api/theme-edit/_text-looks.mjs +376 -0
- package/api/theme-edit/_vet.d.mts +3 -26
- package/api/theme-edit/_vet.mjs +5 -89
- package/api/theme-edit/how/how.d.mts +1 -1
- package/api/theme-edit/how/how.mjs +1 -1
- package/api/theme-edit/theme-edit.type.d.mts +54 -1
- package/api/theme-edit/theme-edit.type.mjs +17 -2
- package/api/theme-edit/themeEditHow.doc.mjs +3 -3
- package/api/theme-edit/themeEditNew.doc.mjs +4 -0
- package/api/theme-edit/themeEditSet.doc.mjs +6 -2
- package/api/theme-edit/themeEditShow.doc.mjs +4 -0
- package/api/theme-edit/themeEditUndo.doc.mjs +4 -0
- package/assets/component-list.generated.json +1 -1
- package/assets/docs/author-a-theme.doc.mjs +7 -4
- package/assets/docs/tree/export-pages.doc.mjs +1 -1
- package/assets/docs/tree/icon-sets.doc.mjs +1 -1
- package/assets/docs/use-a-theme.doc.mjs +89 -17
- package/assets/docs-routes.generated.json +1 -1
- package/assets/docs.generated.json +2 -2
- package/assets/icons/definitions/article.doc.mjs +9 -0
- package/assets/icons/template-icons.json +5 -0
- package/assets/search-catalog.generated.json +2 -2
- package/assets/self-audit.generated.json +1 -1
- package/assets/templates/blocks/components/Citation/CitationInlineText.doc.mjs +1 -1
- package/assets/templates/blocks/components/Citation/CitationInlineText.tsx +3 -1
- package/assets/templates/blocks/components/Citation/CitationShowcase.doc.mjs +1 -1
- package/assets/templates/blocks/components/Citation/CitationShowcase.tsx +3 -1
- package/assets/templates/blocks/components/Citation/CitationSourceList.doc.mjs +1 -1
- package/assets/templates/blocks/components/Citation/CitationSourceList.tsx +7 -3
- package/assets/templates/blocks/components/Markdown/MarkdownCitedContent.doc.mjs +1 -1
- package/assets/templates/blocks/components/Markdown/MarkdownCitedContent.tsx +5 -2
- package/assets/templates/components.generated.json +1 -1
- package/assets/templates/pages/ide/page.tsx +5 -10
- package/assets/templates/pages/payment-form/page.tsx +16 -60
- package/assets/templates/themes/neutral/neutralTheme.ts +4 -3
- package/authoring/debug/parse.d.mts +1 -1
- package/authoring/doctypes/_schema.d.mts +13 -13
- package/authoring/gap-report/parse.d.mts +1 -1
- package/clients/cli/build-id.generated.json +1 -1
- package/clients/cli/commands/ensure-core-built.mjs +17 -10
- package/clients/cli/commands/experimental/theme.mjs +46 -6
- package/clients/cli/commands/experimental-icon.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-compile.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +11 -3
- package/clients/cli/commands/experimental-theme-editor-set.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/hook.mjs +7 -0
- package/clients/cli/commands/theme-build.doc.mjs +1 -1
- package/clients/cli/index.mjs +6 -2
- package/clients/cli/lib/hook-format.mjs +41 -1
- package/clients/cli/lib/json-shim.mjs +34 -14
- package/clients/cli/lib/other-cli-words.mjs +7 -0
- package/clients/cli/lib/unknown-command.mjs +345 -46
- package/clients/cli/manifest.generated.json +1 -1
- package/foundation/agent-docs/agent-docs.d.mts +11 -2
- package/foundation/agent-docs/agent-docs.mjs +51 -8
- package/foundation/config/project.d.mts +11 -1
- package/foundation/config/project.mjs +11 -2
- package/foundation/discovery/component-replacement.d.mts +5 -8
- package/foundation/discovery/component-replacement.mjs +12 -14
- package/foundation/discovery/core-augmentation-points.d.mts +35 -0
- package/foundation/discovery/core-augmentation-points.mjs +410 -9
- package/foundation/discovery/core-elements.d.mts +6 -0
- package/foundation/discovery/core-elements.mjs +10 -2
- package/foundation/discovery/core-prop-types.d.mts +5 -0
- package/foundation/discovery/core-prop-types.mjs +10 -3
- package/foundation/discovery/core-props.d.mts +8 -0
- package/foundation/discovery/core-props.mjs +29 -13
- package/foundation/discovery/official-list.d.mts +17 -0
- package/foundation/discovery/official-list.mjs +77 -0
- package/foundation/discovery/unknown-core-props.d.mts +130 -0
- package/foundation/discovery/unknown-core-props.mjs +601 -0
- package/foundation/discovery/written-prop-values.d.mts +35 -0
- package/foundation/discovery/written-prop-values.mjs +258 -0
- package/foundation/fonts/fontsource-families.generated.d.mts +5 -0
- package/foundation/fonts/fontsource-families.generated.mjs +2110 -0
- package/foundation/fs/package-name.d.mts +10 -0
- package/foundation/fs/package-name.mjs +37 -0
- package/foundation/fs/project-source-files.d.mts +27 -0
- package/foundation/fs/project-source-files.mjs +115 -0
- package/foundation/fs/project-sources.d.mts +25 -0
- package/foundation/fs/project-sources.mjs +83 -0
- package/foundation/fs/read-record.d.mts +18 -0
- package/foundation/fs/read-record.mjs +36 -2
- package/foundation/integrations/integration-warnings.d.mts +39 -7
- package/foundation/integrations/integration-warnings.mjs +141 -19
- package/foundation/integrations/missing-dependency.d.mts +11 -0
- package/foundation/integrations/missing-dependency.mjs +20 -5
- package/foundation/release/folder-lock.d.mts +5 -2
- package/foundation/release/folder-lock.mjs +9 -3
- package/foundation/release/notices.mjs +2 -8
- package/foundation/render/cut-short.d.mts +8 -2
- package/foundation/render/cut-short.mjs +50 -5
- package/foundation/render/drawn-contrast.d.mts +38 -0
- package/foundation/render/drawn-contrast.mjs +237 -0
- package/foundation/render/file-header.mjs +4 -0
- package/foundation/render/layers.d.mts +2 -1
- package/foundation/render/layers.mjs +22 -1
- package/foundation/render/page-worker.mjs +83 -18
- package/foundation/render/part-boxes.d.mts +27 -0
- package/foundation/render/part-boxes.mjs +45 -0
- package/foundation/render/picture-chrome.mjs +36 -4
- package/foundation/render/picture-playwright.mjs +26 -2
- package/foundation/render/picture-window.d.mts +29 -2
- package/foundation/render/picture-window.mjs +99 -1
- package/foundation/render/render-page.d.mts +39 -6
- package/foundation/render/render-page.mjs +26 -10
- package/foundation/render/ts-paths.mjs +2 -1
- package/foundation/response/error-codes.doc.mjs +1 -1
- package/foundation/response/error-codes.mjs +1 -1
- package/foundation/response/response-types.doc.mjs +1 -1
- package/foundation/text/written-string.d.mts +4 -1
- package/foundation/text/written-string.mjs +4 -1
- package/package.json +8 -7
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import {CUSTOM_PROPERTY} from '../theme/build/written-values.mjs';
|
|
13
|
+
import {readSetLine} from './_set-line.mjs';
|
|
13
14
|
import {AstryxError} from '../error.mjs';
|
|
14
15
|
import * as fs from 'node:fs';
|
|
15
16
|
import * as path from 'node:path';
|
|
@@ -37,8 +38,15 @@ import {
|
|
|
37
38
|
takesPercentage,
|
|
38
39
|
sameKindValues,
|
|
39
40
|
unitsJoined,
|
|
41
|
+
sidesOf,
|
|
42
|
+
BOX_SIDES,
|
|
40
43
|
} from './_css.mjs';
|
|
41
|
-
import {
|
|
44
|
+
import {
|
|
45
|
+
calcVars,
|
|
46
|
+
coreFallback,
|
|
47
|
+
multipliedTokens,
|
|
48
|
+
INHERITED_TEXT,
|
|
49
|
+
} from './_parts.mjs';
|
|
42
50
|
import {
|
|
43
51
|
AUTO_SPREAD,
|
|
44
52
|
COMMON_STATES,
|
|
@@ -64,13 +72,14 @@ import {
|
|
|
64
72
|
THING_HINTS,
|
|
65
73
|
TYPE_STYLES,
|
|
66
74
|
familyOf,
|
|
75
|
+
onlyMeans,
|
|
67
76
|
wordTable,
|
|
68
77
|
WRAPPED_PARTS,
|
|
69
78
|
CARD_LIKE,
|
|
70
79
|
systemFontFamilies,
|
|
71
80
|
isSystemFamily,
|
|
72
81
|
fontStack,
|
|
73
|
-
|
|
82
|
+
STATE_SYNONYMS,
|
|
74
83
|
} from './_tables.mjs';
|
|
75
84
|
import {
|
|
76
85
|
COLOR_NAMES,
|
|
@@ -87,12 +96,15 @@ import {
|
|
|
87
96
|
ratio,
|
|
88
97
|
mixSide,
|
|
89
98
|
splitTop,
|
|
99
|
+
colorSides,
|
|
100
|
+
colorOpacitiesAsCss,
|
|
90
101
|
} from './_color.mjs';
|
|
91
102
|
import {
|
|
92
103
|
PALETTE_DIALS,
|
|
93
104
|
PALETTE_TOKENS,
|
|
105
|
+
isLookToken,
|
|
94
106
|
VIBRANCY_DEFAULT,
|
|
95
|
-
|
|
107
|
+
vibrancyMovesAny,
|
|
96
108
|
paletteToken,
|
|
97
109
|
seedsInEffect,
|
|
98
110
|
} from './_palette.mjs';
|
|
@@ -116,6 +128,12 @@ import {
|
|
|
116
128
|
focusStateOf,
|
|
117
129
|
valueProblem,
|
|
118
130
|
partComponentDocs,
|
|
131
|
+
colorPropTokens,
|
|
132
|
+
innerPropTokens,
|
|
133
|
+
columnLineTokens,
|
|
134
|
+
mainTextSizeToken,
|
|
135
|
+
namesToken,
|
|
136
|
+
heldSizeTokenFor,
|
|
119
137
|
themeFiles,
|
|
120
138
|
ownSourceTokenValues,
|
|
121
139
|
baseTopTokens,
|
|
@@ -137,6 +155,13 @@ import {
|
|
|
137
155
|
propertySpelling,
|
|
138
156
|
modesOf,
|
|
139
157
|
dialNumber,
|
|
158
|
+
dialValueFits,
|
|
159
|
+
groupsOf,
|
|
160
|
+
onlyFits,
|
|
161
|
+
growsWithContent,
|
|
162
|
+
notGrowingWhens,
|
|
163
|
+
sharedControlHeight,
|
|
164
|
+
controlHeightValue,
|
|
140
165
|
} from './_settings.mjs';
|
|
141
166
|
import {isColorToken} from './_compiler.mjs';
|
|
142
167
|
import {
|
|
@@ -267,43 +292,43 @@ export const setLine = (slug, thing, value, s, unset = false) =>
|
|
|
267
292
|
`${P} ${unset ? 'undo' : 'set'} ${slug} ${quoteCommandArgument(thing)}${value ? ` ${quoteCommandArgument(value)}` : ''}${s.on ? ` --on ${s.on}` : ''}${s.when ? ` --when ${s.when}` : ''}${s.state ? ` --state ${s.state}` : ''}${s.mode ? ` --mode ${s.mode}` : ''}${s.only ? ' --only' : ''}`;
|
|
268
293
|
|
|
269
294
|
/**
|
|
270
|
-
* The
|
|
271
|
-
*
|
|
272
|
-
*
|
|
273
|
-
* other property or value.
|
|
274
|
-
* @param {string} slug
|
|
295
|
+
* The sides a box shorthand of two to four values gives out, as CSS does
|
|
296
|
+
* (`5px 0`: block 5px, inline 0), each with the value typed for it, which
|
|
297
|
+
* that side's own check reads; one working length said for every side is
|
|
298
|
+
* that length alone (side ''); null for any other property or value.
|
|
275
299
|
* @param {string} prop
|
|
276
300
|
* @param {string} v
|
|
277
|
-
* @
|
|
278
|
-
* @returns {string[] | null}
|
|
301
|
+
* @returns {Array<[string, string]> | null}
|
|
279
302
|
*/
|
|
280
|
-
function
|
|
303
|
+
function boxSides(prop, v) {
|
|
281
304
|
if (prop !== 'padding' && prop !== 'margin') return null;
|
|
282
|
-
const
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
if (
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
305
|
+
const n = splitTop(v.trim(), ' ').filter(Boolean).length;
|
|
306
|
+
// (The shorthand rules split the value, as every other reader of a box
|
|
307
|
+
// shorthand's sides does.)
|
|
308
|
+
const sides = n >= 2 ? sidesOf(prop, v) : null;
|
|
309
|
+
if (!sides) return null;
|
|
310
|
+
const [top, right, bottom, left] = ['top', 'right', 'bottom', 'left'].map(
|
|
311
|
+
side => sides[`${prop}-${side}`],
|
|
312
|
+
);
|
|
313
|
+
if (top === right && right === bottom && bottom === left && oneLength(top))
|
|
314
|
+
return [['', top]];
|
|
315
|
+
return n === 2
|
|
316
|
+
? [
|
|
317
|
+
['block', top],
|
|
318
|
+
['inline', right],
|
|
319
|
+
]
|
|
320
|
+
: n === 3
|
|
290
321
|
? [
|
|
291
|
-
['
|
|
292
|
-
['inline',
|
|
322
|
+
['top', top],
|
|
323
|
+
['inline', right],
|
|
324
|
+
['bottom', bottom],
|
|
293
325
|
]
|
|
294
|
-
:
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
: [
|
|
301
|
-
['top', w[0]],
|
|
302
|
-
['right', w[1]],
|
|
303
|
-
['bottom', w[2]],
|
|
304
|
-
['left', w[3]],
|
|
305
|
-
];
|
|
306
|
-
return sides.map(([side, x]) => setLine(slug, `${prop}-${side}`, x, s));
|
|
326
|
+
: [
|
|
327
|
+
['top', top],
|
|
328
|
+
['right', right],
|
|
329
|
+
['bottom', bottom],
|
|
330
|
+
['left', left],
|
|
331
|
+
];
|
|
307
332
|
}
|
|
308
333
|
|
|
309
334
|
/** @param {string} v */
|
|
@@ -836,6 +861,7 @@ const COLOR_DIAL_WORDS = (() => {
|
|
|
836
861
|
* @property {string} [state]
|
|
837
862
|
* @property {string} [mode]
|
|
838
863
|
* @property {boolean} [only]
|
|
864
|
+
* @property {boolean} [sides] - set's own value: a box shorthand where one length works is written as its sides (never a saved entry, which is checked as written)
|
|
839
865
|
*/
|
|
840
866
|
|
|
841
867
|
/**
|
|
@@ -846,7 +872,7 @@ const COLOR_DIAL_WORDS = (() => {
|
|
|
846
872
|
* @param {string} slug
|
|
847
873
|
* @param {import('./_settings.mjs').ThemeData} data
|
|
848
874
|
* @param {string | {thing: string, on?: string, when?: string, state?: string, mode?: string}} [skip]
|
|
849
|
-
* @returns {Array<{setting: import('./_settings.mjs').Setting, why: string, scope?: boolean, fix?: string}>} every saved setting the editor no longer accepts (`fix`: the clean value to set, when one reads)
|
|
875
|
+
* @returns {Array<{setting: import('./_settings.mjs').Setting, why: string, scope?: boolean, fix?: string, noEffect?: boolean}>} every saved setting the editor no longer accepts (`fix`: the clean value to set, when one reads; `noEffect`: refused as it never shows where it is saved)
|
|
850
876
|
*/
|
|
851
877
|
export function storedProblems(ctx, slug, data, skip = '') {
|
|
852
878
|
// The setting the command replaces (its thing in the same scope); a
|
|
@@ -861,7 +887,7 @@ export function storedProblems(ctx, slug, data, skip = '') {
|
|
|
861
887
|
(s.when ?? '') === (skip.when ?? '') &&
|
|
862
888
|
(s.state ?? '') === (skip.state ?? '') &&
|
|
863
889
|
(s.mode ?? '') === (skip.mode ?? '');
|
|
864
|
-
/** @type {Array<{setting: import('./_settings.mjs').Setting, why: string, scope?: boolean, fix?: string}>} */
|
|
890
|
+
/** @type {Array<{setting: import('./_settings.mjs').Setting, why: string, scope?: boolean, fix?: string, noEffect?: boolean}>} */
|
|
865
891
|
const found = [];
|
|
866
892
|
const TOKENS = ctx.project.core.tokenDefaults;
|
|
867
893
|
// Where each saved setting applies names a real part, group, state and
|
|
@@ -869,6 +895,7 @@ export function storedProblems(ctx, slug, data, skip = '') {
|
|
|
869
895
|
const WHOLE_ONLY = [
|
|
870
896
|
'surfaces',
|
|
871
897
|
'buttons',
|
|
898
|
+
'badges',
|
|
872
899
|
'base',
|
|
873
900
|
'mode',
|
|
874
901
|
'vibrancy',
|
|
@@ -886,7 +913,7 @@ export function storedProblems(ctx, slug, data, skip = '') {
|
|
|
886
913
|
if (
|
|
887
914
|
s.on &&
|
|
888
915
|
!t &&
|
|
889
|
-
!
|
|
916
|
+
!groupsOf(ctx)[s.on] &&
|
|
890
917
|
!(s.thing === 'font' && FONT_ROLES.includes(s.on))
|
|
891
918
|
)
|
|
892
919
|
return scope(`there is no part or group "${s.on}"`);
|
|
@@ -984,7 +1011,15 @@ export function storedProblems(ctx, slug, data, skip = '') {
|
|
|
984
1011
|
},
|
|
985
1012
|
s.thing,
|
|
986
1013
|
s.value,
|
|
987
|
-
{
|
|
1014
|
+
{
|
|
1015
|
+
on: s.on,
|
|
1016
|
+
when: s.when,
|
|
1017
|
+
state: s.state,
|
|
1018
|
+
mode: s.mode,
|
|
1019
|
+
only: s.only,
|
|
1020
|
+
},
|
|
1021
|
+
false,
|
|
1022
|
+
{saved: true},
|
|
988
1023
|
);
|
|
989
1024
|
} catch (e) {
|
|
990
1025
|
if (!(e instanceof AstryxError)) throw e;
|
|
@@ -994,6 +1029,8 @@ export function storedProblems(ctx, slug, data, skip = '') {
|
|
|
994
1029
|
e instanceof Error
|
|
995
1030
|
? e.message.replace(/ Nothing was changed\.$/, '')
|
|
996
1031
|
: String(e),
|
|
1032
|
+
// Refused for having no effect where it is saved: it never shows.
|
|
1033
|
+
...(e.code === E.ERR_THEME_NO_EFFECT ? {noEffect: true} : {}),
|
|
997
1034
|
});
|
|
998
1035
|
}
|
|
999
1036
|
}
|
|
@@ -2366,6 +2403,53 @@ function isShadow(value) {
|
|
|
2366
2403
|
});
|
|
2367
2404
|
}
|
|
2368
2405
|
|
|
2406
|
+
/**
|
|
2407
|
+
* The tokens a control height written as a size token reads on its way
|
|
2408
|
+
* back to that token, ending with it; null when it never reads it. A
|
|
2409
|
+
* custom property's var() resolves on the element that sets it, so only
|
|
2410
|
+
* the tokens set where this one is written are followed: on the controls
|
|
2411
|
+
* group, and on the one control for its own height (where its own tokens
|
|
2412
|
+
* win).
|
|
2413
|
+
* @param {import('./_settings.mjs').ThemeData} data
|
|
2414
|
+
* @param {{token: string, own: boolean, setting: import('./_settings.mjs').Setting}} asToken
|
|
2415
|
+
* @param {string} value
|
|
2416
|
+
* @returns {string[] | null}
|
|
2417
|
+
*/
|
|
2418
|
+
function heightTokenLoop(data, asToken, value) {
|
|
2419
|
+
const scopes = asToken.own ? ['controls', asToken.setting.on] : ['controls'];
|
|
2420
|
+
/** @type {Map<string, string>} */
|
|
2421
|
+
const held = new Map();
|
|
2422
|
+
for (const on of scopes)
|
|
2423
|
+
for (const x of data.settings)
|
|
2424
|
+
if (
|
|
2425
|
+
x.source === 'token' &&
|
|
2426
|
+
x.on === on &&
|
|
2427
|
+
!x.when &&
|
|
2428
|
+
!x.state &&
|
|
2429
|
+
(x.mode ?? null) === (asToken.setting.mode ?? null)
|
|
2430
|
+
)
|
|
2431
|
+
held.set(x.thing, String(x.value));
|
|
2432
|
+
held.set(asToken.token, value);
|
|
2433
|
+
/** @param {string} v */
|
|
2434
|
+
const refs = v =>
|
|
2435
|
+
[
|
|
2436
|
+
...v.matchAll(new RegExp(String.raw`var\(\s*(${CUSTOM_PROPERTY})`, 'gi')),
|
|
2437
|
+
].map(m => m[1]);
|
|
2438
|
+
const seen = new Set();
|
|
2439
|
+
/** @param {string} v @param {string[]} path @returns {string[] | null} */
|
|
2440
|
+
const walk = (v, path) => {
|
|
2441
|
+
for (const t of refs(v)) {
|
|
2442
|
+
if (t === asToken.token) return [...path, t];
|
|
2443
|
+
if (seen.has(t) || !held.has(t)) continue;
|
|
2444
|
+
seen.add(t);
|
|
2445
|
+
const found = walk(/** @type {string} */ (held.get(t)), [...path, t]);
|
|
2446
|
+
if (found) return found;
|
|
2447
|
+
}
|
|
2448
|
+
return null;
|
|
2449
|
+
};
|
|
2450
|
+
return walk(value, []);
|
|
2451
|
+
}
|
|
2452
|
+
|
|
2369
2453
|
/**
|
|
2370
2454
|
* Refuse a value that would read the token itself, through other tokens.
|
|
2371
2455
|
* A token set on a part (`--on`) overrides only inside that part: there
|
|
@@ -2707,6 +2791,15 @@ const DIAL_WORDS = wordTable(
|
|
|
2707
2791
|
plain: 'flat',
|
|
2708
2792
|
minimal: 'flat',
|
|
2709
2793
|
},
|
|
2794
|
+
badges: {
|
|
2795
|
+
tint: 'soft',
|
|
2796
|
+
tinted: 'soft',
|
|
2797
|
+
subtle: 'soft',
|
|
2798
|
+
outlined: 'outline',
|
|
2799
|
+
bordered: 'outline',
|
|
2800
|
+
filled: 'solid',
|
|
2801
|
+
fill: 'solid',
|
|
2802
|
+
},
|
|
2710
2803
|
buttons: {
|
|
2711
2804
|
uppercase: 'caps',
|
|
2712
2805
|
upper: 'caps',
|
|
@@ -3030,14 +3123,19 @@ function oneModeOfTheme(data) {
|
|
|
3030
3123
|
/**
|
|
3031
3124
|
* Whether any of the parts draws a line of that kind (a border, one side's
|
|
3032
3125
|
* border, an outline) with a width, at rest or in the state named: then its
|
|
3033
|
-
* color alone can differ by mode.
|
|
3126
|
+
* color alone can differ by mode. A width drawn with a style of none or
|
|
3127
|
+
* hidden in the same rule is no line. A side cleared only on the first or
|
|
3128
|
+
* last child (a list row's divider, a grouped button's join) is still
|
|
3129
|
+
* drawn on the others, so it counts. With a variant (`variant:primary`), a rule for another value of that
|
|
3130
|
+
* prop does not count.
|
|
3034
3131
|
* @param {any} C the part census
|
|
3035
3132
|
* @param {string[]} parts
|
|
3036
3133
|
* @param {string} prop border, border-<side> or outline
|
|
3037
3134
|
* @param {string | undefined | null} [state]
|
|
3135
|
+
* @param {string | undefined | null} [when] a variant, `prop:value`
|
|
3038
3136
|
* @returns {boolean}
|
|
3039
3137
|
*/
|
|
3040
|
-
export function drawsLine(C, parts, prop, state) {
|
|
3138
|
+
export function drawsLine(C, parts, prop, state, when) {
|
|
3041
3139
|
// (A side's line is drawn by the side's own width or the shared one.)
|
|
3042
3140
|
const keys =
|
|
3043
3141
|
prop === 'border'
|
|
@@ -3048,15 +3146,29 @@ export function drawsLine(C, parts, prop, state) {
|
|
|
3048
3146
|
: prop.startsWith('border-')
|
|
3049
3147
|
? [`${prop}-width`, 'border-width']
|
|
3050
3148
|
: [`${prop}-width`];
|
|
3149
|
+
const [wp, wv] = String(when ?? '').split(':');
|
|
3150
|
+
const zero = (/** @type {unknown} */ v) =>
|
|
3151
|
+
/^\s*0(?:px|rem|em)?\s*$/.test(String(v));
|
|
3152
|
+
const none = (/** @type {unknown} */ v) =>
|
|
3153
|
+
/^\s*(?:none|hidden)\b/i.test(String(v));
|
|
3051
3154
|
return parts.some(t => {
|
|
3052
3155
|
const at = C.MAP[t]?.at ?? {};
|
|
3053
|
-
return keys.some(k =>
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
|
|
3057
|
-
|
|
3058
|
-
),
|
|
3059
|
-
|
|
3156
|
+
return keys.some(k => {
|
|
3157
|
+
const rules = /** @type {Record<string, string>} */ (at[k] ?? {});
|
|
3158
|
+
const styles = /** @type {Record<string, string>} */ (
|
|
3159
|
+
at[k.replace(/-width$/, '-style')] ?? {}
|
|
3160
|
+
);
|
|
3161
|
+
return Object.entries(rules).some(([sel, w]) => {
|
|
3162
|
+
if (zero(w) || none(styles[sel] ?? '')) return false;
|
|
3163
|
+
if (state ? !sel.includes(state) : /:/.test(sel)) return false;
|
|
3164
|
+
const pairs = sel.split(' ')[0].split(',');
|
|
3165
|
+
return !(
|
|
3166
|
+
wp &&
|
|
3167
|
+
pairs.some(pr => pr.startsWith(`${wp}=`)) &&
|
|
3168
|
+
!pairs.includes(`${wp}=${wv}`)
|
|
3169
|
+
);
|
|
3170
|
+
});
|
|
3171
|
+
});
|
|
3060
3172
|
});
|
|
3061
3173
|
}
|
|
3062
3174
|
|
|
@@ -3407,6 +3519,417 @@ function lineRefusal(ctx, slug, s, prop, v) {
|
|
|
3407
3519
|
);
|
|
3408
3520
|
}
|
|
3409
3521
|
|
|
3522
|
+
/**
|
|
3523
|
+
* The elements a browser draws a border on by itself (a native button's,
|
|
3524
|
+
* a text field's): a part rendered as one of these with no border rule of
|
|
3525
|
+
* its own is not known to draw none.
|
|
3526
|
+
*/
|
|
3527
|
+
const NATIVE_BORDER_TAGS = new Set([
|
|
3528
|
+
'button',
|
|
3529
|
+
'input',
|
|
3530
|
+
'textarea',
|
|
3531
|
+
'select',
|
|
3532
|
+
'fieldset',
|
|
3533
|
+
'hr',
|
|
3534
|
+
'iframe',
|
|
3535
|
+
]);
|
|
3536
|
+
|
|
3537
|
+
/**
|
|
3538
|
+
* Whether a part draws a border in the variant and state a setting names
|
|
3539
|
+
* from outside Core's own rules (drawsLine reads those): the base theme's
|
|
3540
|
+
* rules for it, or the theme's own settings for it; or a part Core sets no
|
|
3541
|
+
* border on whose element the browser draws one (a native button), or a
|
|
3542
|
+
* part the part data does not know.
|
|
3543
|
+
* @param {import('./_settings.mjs').Ctx} ctx
|
|
3544
|
+
* @param {any} data
|
|
3545
|
+
* @param {import('./_settings.mjs').Setting} s
|
|
3546
|
+
* @param {string} part
|
|
3547
|
+
*/
|
|
3548
|
+
function bordersBeyondCore(ctx, data, s, part) {
|
|
3549
|
+
const rec = ctx.C.MAP[part];
|
|
3550
|
+
if (!rec) return true;
|
|
3551
|
+
const wp = String(s.when ?? '').split(':')[0];
|
|
3552
|
+
const edgeProp =
|
|
3553
|
+
/^border(?:-(?:top|right|bottom|left|block|inline)(?:-(?:start|end))?)?(?:-(?:width|style))?$/;
|
|
3554
|
+
const blank = (/** @type {unknown} */ v) =>
|
|
3555
|
+
/^\s*(?:none|hidden|0(?:px|rem|em)?)\s*$/i.test(String(v)) ||
|
|
3556
|
+
/^\s*(?:none|hidden)\b/i.test(String(v));
|
|
3557
|
+
// A part Core sets no border on draws none, unless the browser draws one
|
|
3558
|
+
// on its element (a native button).
|
|
3559
|
+
const recorded = Object.keys(rec.at ?? {}).some(p => edgeProp.test(p));
|
|
3560
|
+
if (!recorded && (rec.tags ?? []).some(t => NATIVE_BORDER_TAGS.has(t)))
|
|
3561
|
+
return true;
|
|
3562
|
+
// The base theme's rules for the part (its own block and the variant's).
|
|
3563
|
+
const blocks = ctx.base?.components?.[part] ?? {};
|
|
3564
|
+
/** @param {unknown} b @returns {boolean} */
|
|
3565
|
+
const drawsIn = b =>
|
|
3566
|
+
!!b &&
|
|
3567
|
+
typeof b === 'object' &&
|
|
3568
|
+
Object.entries(b).some(([k, v]) =>
|
|
3569
|
+
v && typeof v === 'object'
|
|
3570
|
+
? drawsIn(v)
|
|
3571
|
+
: /^border(?:Top|Right|Bottom|Left|Block|Inline)?(?:Start|End)?(?:Width|Style)?$/.test(
|
|
3572
|
+
k,
|
|
3573
|
+
) && !blank(v),
|
|
3574
|
+
);
|
|
3575
|
+
for (const [k, b] of Object.entries(blocks))
|
|
3576
|
+
if (k === 'base' || !wp || k === s.when) if (drawsIn(b)) return true;
|
|
3577
|
+
// The theme's own settings for it. (A width alone draws no line: Core's
|
|
3578
|
+
// style stays none; a style draws, and a shorthand only with a style word
|
|
3579
|
+
// in it, as borderSidesOff reads it: `border-top 1px` draws nothing.)
|
|
3580
|
+
const STYLE_WORD =
|
|
3581
|
+
/(?:^|\s)(?:solid|dashed|dotted|double|groove|ridge|inset|outset)(?:\s|$)/i;
|
|
3582
|
+
return (data?.settings ?? []).some(
|
|
3583
|
+
(/** @type {any} */ x) =>
|
|
3584
|
+
x.source === 'property' &&
|
|
3585
|
+
edgeProp.test(String(x.thing)) &&
|
|
3586
|
+
!/-width$/.test(String(x.thing)) &&
|
|
3587
|
+
(/-style$/.test(String(x.thing)) || STYLE_WORD.test(String(x.value))) &&
|
|
3588
|
+
!blank(x.value) &&
|
|
3589
|
+
(!x.when || !s.when || x.when === s.when) &&
|
|
3590
|
+
(!x.state || x.state === s.state) &&
|
|
3591
|
+
// (A border written for one mode draws only in that mode.)
|
|
3592
|
+
(!x.mode || x.mode === /** @type {any} */ (s).mode) &&
|
|
3593
|
+
partsOf(ctx, x).includes(part),
|
|
3594
|
+
);
|
|
3595
|
+
}
|
|
3596
|
+
|
|
3597
|
+
/**
|
|
3598
|
+
* The look a part has by default: its documented default variant, as
|
|
3599
|
+
* `variant:<value>`, when the part records that variant.
|
|
3600
|
+
* @param {import('./_settings.mjs').Ctx} ctx
|
|
3601
|
+
* @param {string} part
|
|
3602
|
+
* @returns {string | undefined}
|
|
3603
|
+
*/
|
|
3604
|
+
function defaultLook(ctx, part) {
|
|
3605
|
+
const values = ctx.C.variantValues(part)?.variant ?? [];
|
|
3606
|
+
if (!values.length) return undefined;
|
|
3607
|
+
for (const info of Object.values(ctx.project?.components ?? {})) {
|
|
3608
|
+
if (!info?.targets?.some(t => t.className === `astryx-${part}`)) continue;
|
|
3609
|
+
const v = String(info.props?.variant?.default ?? '').replace(/['"]/g, '');
|
|
3610
|
+
if (values.includes(v)) return `variant:${v}`;
|
|
3611
|
+
}
|
|
3612
|
+
return undefined;
|
|
3613
|
+
}
|
|
3614
|
+
|
|
3615
|
+
/**
|
|
3616
|
+
* Whether every border side a part draws at rest in a look is cleared on
|
|
3617
|
+
* its first child: a seam with the sibling before it (a button group's
|
|
3618
|
+
* join), never a line around the part.
|
|
3619
|
+
* @param {any} C
|
|
3620
|
+
* @param {string} part
|
|
3621
|
+
* @param {string | undefined} when
|
|
3622
|
+
*/
|
|
3623
|
+
function seamOnly(C, part, when) {
|
|
3624
|
+
const v = String(when ?? '').replace(/^variant:/, '');
|
|
3625
|
+
const blank = (/** @type {unknown} */ x) =>
|
|
3626
|
+
/^\s*(?:0(?:px)?|none)\s*$/.test(String(x));
|
|
3627
|
+
const drawn = Object.entries(C.MAP[part]?.at ?? {})
|
|
3628
|
+
.filter(([prop]) => /^border(?:-[a-z-]+)?-width$/.test(prop))
|
|
3629
|
+
.flatMap(([, rules]) =>
|
|
3630
|
+
Object.entries(/** @type {Record<string, unknown>} */ (rules))
|
|
3631
|
+
.filter(
|
|
3632
|
+
([sel, val]) =>
|
|
3633
|
+
!/[\s:]/.test(sel) &&
|
|
3634
|
+
!blank(val) &&
|
|
3635
|
+
(!v ||
|
|
3636
|
+
!/(?:^|,)variant=/.test(sel) ||
|
|
3637
|
+
sel.split(',').includes(`variant=${v}`)),
|
|
3638
|
+
)
|
|
3639
|
+
.map(([sel]) => [rules, sel]),
|
|
3640
|
+
);
|
|
3641
|
+
return (
|
|
3642
|
+
drawn.length > 0 &&
|
|
3643
|
+
drawn.every(([rules, sel]) =>
|
|
3644
|
+
blank(/** @type {any} */ (rules)[`${sel} :first-child`]),
|
|
3645
|
+
)
|
|
3646
|
+
);
|
|
3647
|
+
}
|
|
3648
|
+
|
|
3649
|
+
/**
|
|
3650
|
+
* Whether Core draws a line around a part where it is asked: in the look
|
|
3651
|
+
* said, else the part's default look, at rest or in the state said. A side
|
|
3652
|
+
* cleared on the first child, a seam with the sibling before it, is never a
|
|
3653
|
+
* line around the part: a secondary button standing alone draws none.
|
|
3654
|
+
* @param {import('./_settings.mjs').Ctx} ctx
|
|
3655
|
+
* @param {string} part
|
|
3656
|
+
* @param {string | null | undefined} state
|
|
3657
|
+
* @param {string | undefined} when
|
|
3658
|
+
*/
|
|
3659
|
+
export function drawsLineAround(ctx, part, state, when) {
|
|
3660
|
+
const look = when ?? defaultLook(ctx, part);
|
|
3661
|
+
const line =
|
|
3662
|
+
drawsLine(ctx.C, [part], 'border', null, look) ||
|
|
3663
|
+
(!!state && drawsLine(ctx.C, [part], 'border', state, look));
|
|
3664
|
+
return line && !seamOnly(ctx.C, part, look);
|
|
3665
|
+
}
|
|
3666
|
+
|
|
3667
|
+
/** A border color: one color, one per side, or one side's. */
|
|
3668
|
+
export const BORDER_COLOR_PROP =
|
|
3669
|
+
/^border(?:-(?:top|right|bottom|left|block|inline)(?:-(?:start|end))?)?-color$/;
|
|
3670
|
+
|
|
3671
|
+
/** The border a border color brings to a part that draws none. */
|
|
3672
|
+
export const BORDER_TO_COLOR = 'var(--border-width) solid transparent';
|
|
3673
|
+
|
|
3674
|
+
/**
|
|
3675
|
+
* The theme's own setting that turns off every side a border color is on
|
|
3676
|
+
* (`border none`, `border-width 0`, `border-bottom none` for a bottom
|
|
3677
|
+
* color), read in order, or undefined.
|
|
3678
|
+
* @param {import('./_settings.mjs').Ctx} ctx
|
|
3679
|
+
* @param {any} data
|
|
3680
|
+
* @param {{on?: string, when?: string, state?: string}} s
|
|
3681
|
+
* @param {string} part
|
|
3682
|
+
*/
|
|
3683
|
+
function borderSetToNone(ctx, data, s, part) {
|
|
3684
|
+
const hidden = borderSidesOff(ctx, data, s, part);
|
|
3685
|
+
const asked = borderSides(String(/** @type {any} */ (s).thing ?? ''));
|
|
3686
|
+
return asked.every(side => hidden.has(side))
|
|
3687
|
+
? hidden.get(asked[0])
|
|
3688
|
+
: undefined;
|
|
3689
|
+
}
|
|
3690
|
+
|
|
3691
|
+
/**
|
|
3692
|
+
* The sides a border property names: one side, a logical pair, or all four.
|
|
3693
|
+
* @param {string} thing
|
|
3694
|
+
* @returns {string[]}
|
|
3695
|
+
*/
|
|
3696
|
+
function borderSides(thing) {
|
|
3697
|
+
const m =
|
|
3698
|
+
/^border-(top|right|bottom|left|block|inline)(?:-(start|end))?/.exec(thing);
|
|
3699
|
+
if (!m) return [...BOX_SIDES];
|
|
3700
|
+
if (m[1] === 'block')
|
|
3701
|
+
return m[2] ? [m[2] === 'start' ? 'top' : 'bottom'] : ['top', 'bottom'];
|
|
3702
|
+
if (m[1] === 'inline')
|
|
3703
|
+
return m[2] ? [m[2] === 'start' ? 'left' : 'right'] : ['left', 'right'];
|
|
3704
|
+
return [m[1]];
|
|
3705
|
+
}
|
|
3706
|
+
|
|
3707
|
+
/**
|
|
3708
|
+
* The sides of a part's border the theme turns off where a color is asked,
|
|
3709
|
+
* each with the setting that does it, read in the order the settings are
|
|
3710
|
+
* written: a none or zero hides a side, and a later width, style or
|
|
3711
|
+
* shorthand on it draws it again (`border none` then `border-top 1px
|
|
3712
|
+
* solid` leaves the top). A width or style of several values names each
|
|
3713
|
+
* side as CSS reads it, a logical pair (`border-block-width '0 1px'`) its
|
|
3714
|
+
* start and end.
|
|
3715
|
+
* @param {import('./_settings.mjs').Ctx} ctx
|
|
3716
|
+
* @param {any} data
|
|
3717
|
+
* @param {{on?: string, when?: string, state?: string}} s
|
|
3718
|
+
* @param {string} part
|
|
3719
|
+
* @returns {Map<string, any>}
|
|
3720
|
+
*/
|
|
3721
|
+
function borderSidesOff(ctx, data, s, part) {
|
|
3722
|
+
const edge =
|
|
3723
|
+
/^border(?:-(?:top|right|bottom|left|block|inline)(?:-(?:start|end))?)?(?:-(width|style))?$/;
|
|
3724
|
+
const blank = (/** @type {string | undefined} */ t) =>
|
|
3725
|
+
/^(?:none|hidden|0(?:px|rem|em)?)$/i.test(t ?? '');
|
|
3726
|
+
/** @type {Map<string, any>} */
|
|
3727
|
+
const widthOff = new Map();
|
|
3728
|
+
/** @type {Map<string, any>} */
|
|
3729
|
+
const styleOff = new Map();
|
|
3730
|
+
for (const x of /** @type {any[]} */ (data?.settings ?? [])) {
|
|
3731
|
+
const m = edge.exec(String(x.thing));
|
|
3732
|
+
if (
|
|
3733
|
+
!m ||
|
|
3734
|
+
x.source !== 'property' ||
|
|
3735
|
+
// (A none set for one look hides only that look.)
|
|
3736
|
+
(x.when && x.when !== s.when) ||
|
|
3737
|
+
(x.state && x.state !== s.state) ||
|
|
3738
|
+
!partsOf(ctx, x).includes(part)
|
|
3739
|
+
)
|
|
3740
|
+
continue;
|
|
3741
|
+
const sides = borderSides(String(x.thing));
|
|
3742
|
+
const tokens = String(x.value).trim().split(/\s+/).filter(Boolean);
|
|
3743
|
+
// (A width or style names each side's value as CSS reads the list,
|
|
3744
|
+
// `calc()` kept whole; a logical pair is its start and its end.)
|
|
3745
|
+
const perSide = m[1] ? sidesOf(String(x.thing), String(x.value)) : null;
|
|
3746
|
+
/** @param {string} side @returns {string | undefined} */
|
|
3747
|
+
const tokenAt = side => {
|
|
3748
|
+
if (!perSide) return tokens[0];
|
|
3749
|
+
const prop = Object.keys(perSide).find(p => borderSides(p)[0] === side);
|
|
3750
|
+
return prop ? perSide[prop] : undefined;
|
|
3751
|
+
};
|
|
3752
|
+
sides.forEach(side => {
|
|
3753
|
+
if (m[1]) {
|
|
3754
|
+
const off = m[1] === 'width' ? widthOff : styleOff;
|
|
3755
|
+
if (blank(tokenAt(side))) off.set(side, x);
|
|
3756
|
+
else off.delete(side);
|
|
3757
|
+
} else {
|
|
3758
|
+
// (A shorthand writes the side's width and style together; with no
|
|
3759
|
+
// style in it, the style is none: `border-top 1px` draws no line.)
|
|
3760
|
+
const none =
|
|
3761
|
+
tokens.some(t => /^(?:none|hidden)$/i.test(t)) ||
|
|
3762
|
+
!tokens.some(t =>
|
|
3763
|
+
/^(?:solid|dashed|dotted|double|groove|ridge|inset|outset)$/i.test(
|
|
3764
|
+
t,
|
|
3765
|
+
),
|
|
3766
|
+
);
|
|
3767
|
+
const zero = tokens.some(t => /^0(?:px|rem|em)?$/i.test(t));
|
|
3768
|
+
if (none || zero) {
|
|
3769
|
+
if (none) styleOff.set(side, x);
|
|
3770
|
+
else styleOff.delete(side);
|
|
3771
|
+
if (zero) widthOff.set(side, x);
|
|
3772
|
+
else widthOff.delete(side);
|
|
3773
|
+
} else {
|
|
3774
|
+
widthOff.delete(side);
|
|
3775
|
+
styleOff.delete(side);
|
|
3776
|
+
}
|
|
3777
|
+
}
|
|
3778
|
+
});
|
|
3779
|
+
}
|
|
3780
|
+
/** @type {Map<string, any>} */
|
|
3781
|
+
const off = new Map();
|
|
3782
|
+
for (const side of BOX_SIDES) {
|
|
3783
|
+
const by = styleOff.get(side) ?? widthOff.get(side);
|
|
3784
|
+
if (by) off.set(side, by);
|
|
3785
|
+
}
|
|
3786
|
+
return off;
|
|
3787
|
+
}
|
|
3788
|
+
|
|
3789
|
+
/**
|
|
3790
|
+
* The border a border color (one color, a color per side, or one side's)
|
|
3791
|
+
* brings to the part it is set on, when the part draws no border in the
|
|
3792
|
+
* variant and state asked (Core sets a tab's, a primary button's and a
|
|
3793
|
+
* banner's to none): a transparent one at rest, as wide as the theme's
|
|
3794
|
+
* border width, so the part keeps one size in every state and the color
|
|
3795
|
+
* has a line to show on. Null when the setting is no border color, its
|
|
3796
|
+
* parts draw a border there, or the theme itself sets their border to none
|
|
3797
|
+
* (set refuses that conflict, naming the none). Set and how both write it
|
|
3798
|
+
* before the color.
|
|
3799
|
+
* @param {import('./_settings.mjs').Ctx} ctx
|
|
3800
|
+
* @param {string} slug
|
|
3801
|
+
* @param {any} data
|
|
3802
|
+
* @param {import('./_settings.mjs').Setting} s the checked border color
|
|
3803
|
+
* @returns {import('./_settings.mjs').Setting | null}
|
|
3804
|
+
*/
|
|
3805
|
+
export function borderFor(ctx, slug, data, s) {
|
|
3806
|
+
if (ctx.unchecked || !s.on || s.source !== 'property') return null;
|
|
3807
|
+
if (!BORDER_COLOR_PROP.test(s.thing)) return null;
|
|
3808
|
+
if (
|
|
3809
|
+
CSS_WIDE.includes(
|
|
3810
|
+
String(s.value ?? '')
|
|
3811
|
+
.trim()
|
|
3812
|
+
.toLowerCase(),
|
|
3813
|
+
)
|
|
3814
|
+
)
|
|
3815
|
+
return null;
|
|
3816
|
+
const parts = partsOf(ctx, s);
|
|
3817
|
+
/**
|
|
3818
|
+
* Whether the part draws a border where the color is asked. With no
|
|
3819
|
+
* --when, that is the look the part has by default, its documented
|
|
3820
|
+
* default variant (a card's default draws one; a button's secondary draws
|
|
3821
|
+
* only the seam with the button before it in a group, cleared on the
|
|
3822
|
+
* first child, which is no line around it).
|
|
3823
|
+
* @param {string} t
|
|
3824
|
+
*/
|
|
3825
|
+
const draws = t =>
|
|
3826
|
+
drawsLineAround(ctx, t, s.state, s.when) ||
|
|
3827
|
+
bordersBeyondCore(
|
|
3828
|
+
ctx,
|
|
3829
|
+
data,
|
|
3830
|
+
{...s, when: s.when ?? defaultLook(ctx, t)},
|
|
3831
|
+
t,
|
|
3832
|
+
);
|
|
3833
|
+
if (
|
|
3834
|
+
!parts.length ||
|
|
3835
|
+
parts.some(
|
|
3836
|
+
t =>
|
|
3837
|
+
draws(t) ||
|
|
3838
|
+
// (Every side the color is on turned off: set refuses it.)
|
|
3839
|
+
borderSetToNone(ctx, data, s, t) != null,
|
|
3840
|
+
)
|
|
3841
|
+
)
|
|
3842
|
+
return null;
|
|
3843
|
+
const edge = checkSetting(
|
|
3844
|
+
ctx,
|
|
3845
|
+
slug,
|
|
3846
|
+
structuredClone(data),
|
|
3847
|
+
'border',
|
|
3848
|
+
BORDER_TO_COLOR,
|
|
3849
|
+
{on: s.on, when: s.when, only: s.only},
|
|
3850
|
+
false,
|
|
3851
|
+
);
|
|
3852
|
+
// (In the color's own mode only where the look draws a line in the other
|
|
3853
|
+
// mode, a button group's seam, which a border for every mode would hide;
|
|
3854
|
+
// elsewhere for every mode, so the part keeps one size when the mode
|
|
3855
|
+
// changes.)
|
|
3856
|
+
const seam = parts.some(t =>
|
|
3857
|
+
drawsLine(ctx.C, [t], 'border', null, s.when ?? defaultLook(ctx, t)),
|
|
3858
|
+
);
|
|
3859
|
+
return s.mode && seam ? {...edge, mode: s.mode} : edge;
|
|
3860
|
+
}
|
|
3861
|
+
|
|
3862
|
+
/**
|
|
3863
|
+
* Whether a setting turns a border side off: a border width, style or side
|
|
3864
|
+
* shorthand (never a radius, spacing or image) whose value holds a none,
|
|
3865
|
+
* hidden or zero.
|
|
3866
|
+
* @param {{thing?: unknown, value?: unknown}} x
|
|
3867
|
+
*/
|
|
3868
|
+
export function turnsBorderOff(x) {
|
|
3869
|
+
return (
|
|
3870
|
+
/^border(?:-(?:top|right|bottom|left|block|inline)(?:-(?:start|end))?)?(?:-(?:width|style))?$/.test(
|
|
3871
|
+
String(x.thing),
|
|
3872
|
+
) &&
|
|
3873
|
+
String(x.value ?? '')
|
|
3874
|
+
.trim()
|
|
3875
|
+
.split(/\s+/)
|
|
3876
|
+
.some(t => /^(?:none|hidden|0(?:px|rem|em)?)$/i.test(t))
|
|
3877
|
+
);
|
|
3878
|
+
}
|
|
3879
|
+
|
|
3880
|
+
/**
|
|
3881
|
+
* Where a border a color brings goes in the theme's settings: before the
|
|
3882
|
+
* part's own border widths, styles, shorthands and colors, so a side the
|
|
3883
|
+
* theme turns off or sizes itself keeps its own value and a color saved
|
|
3884
|
+
* earlier still draws.
|
|
3885
|
+
* @param {import('./_settings.mjs').Ctx} ctx
|
|
3886
|
+
* @param {any[]} settings
|
|
3887
|
+
* @param {import('./_settings.mjs').Setting} edge
|
|
3888
|
+
* @returns {number}
|
|
3889
|
+
*/
|
|
3890
|
+
export function broughtBorderAt(ctx, settings, edge) {
|
|
3891
|
+
const parts = partsOf(ctx, edge);
|
|
3892
|
+
const i = settings.findIndex(
|
|
3893
|
+
x =>
|
|
3894
|
+
x.source === 'property' &&
|
|
3895
|
+
// (A saved border color too: written before the brought border, the
|
|
3896
|
+
// border's shorthand would reset it to see-through.)
|
|
3897
|
+
(/^border(?:-(?:top|right|bottom|left|block|inline)(?:-(?:start|end))?)?(?:-(?:width|style))?$/.test(
|
|
3898
|
+
String(x.thing),
|
|
3899
|
+
) ||
|
|
3900
|
+
BORDER_COLOR_PROP.test(String(x.thing))) &&
|
|
3901
|
+
(!x.when || !edge.when || x.when === edge.when) &&
|
|
3902
|
+
partsOf(ctx, x).some(t => parts.includes(t)),
|
|
3903
|
+
);
|
|
3904
|
+
return i < 0 ? settings.length : i;
|
|
3905
|
+
}
|
|
3906
|
+
|
|
3907
|
+
/**
|
|
3908
|
+
* Refuses a border color on a part where the theme itself turns off every
|
|
3909
|
+
* side the color is on (`border none --on tab`): the two say opposite
|
|
3910
|
+
* things, so neither is changed for the other. The refusal names the none
|
|
3911
|
+
* and offers its undo.
|
|
3912
|
+
* @param {import('./_settings.mjs').Ctx} ctx
|
|
3913
|
+
* @param {string} slug
|
|
3914
|
+
* @param {any} data
|
|
3915
|
+
* @param {import('./_settings.mjs').Setting} s
|
|
3916
|
+
* @param {string} prop
|
|
3917
|
+
*/
|
|
3918
|
+
function borderNoneRefusal(ctx, slug, data, s, prop) {
|
|
3919
|
+
if (ctx.unchecked || !s.on || !BORDER_COLOR_PROP.test(prop)) return;
|
|
3920
|
+
const parts = partsOf(ctx, s);
|
|
3921
|
+
// (Whether Core draws the border or not: the theme's own none hides it
|
|
3922
|
+
// either way, an input's included.)
|
|
3923
|
+
if (!parts.length) return;
|
|
3924
|
+
const none = parts.map(t => borderSetToNone(ctx, data, s, t)).find(Boolean);
|
|
3925
|
+
if (!none) return;
|
|
3926
|
+
refuse(
|
|
3927
|
+
E.ERR_THEME_NO_EFFECT,
|
|
3928
|
+
`${slug} sets ${none.thing} ${none.value} on ${none.on}${none.when ? ` when ${none.when}` : ''}${none.state ? ` :${none.state}` : ''}, so ${prop} on ${s.on} has no line to color. Undo that first, then set the color: it brings the border it needs.`,
|
|
3929
|
+
{run: [setLine(slug, none.thing, '', none, true)]},
|
|
3930
|
+
);
|
|
3931
|
+
}
|
|
3932
|
+
|
|
3410
3933
|
/**
|
|
3411
3934
|
* Refuses an outline's color, width or offset on a part whose outline Core
|
|
3412
3935
|
* draws as none in every rule (an input, which shows focus with a ring in
|
|
@@ -3516,12 +4039,7 @@ function mediaTextRefusal(ctx, slug, s, v) {
|
|
|
3516
4039
|
* @returns {string | null}
|
|
3517
4040
|
*/
|
|
3518
4041
|
export function inheritedReach(ctx, s, prop) {
|
|
3519
|
-
if (
|
|
3520
|
-
!/^(font-(size|weight|style|family|variant)|text-(transform|align)|letter-spacing|line-height|white-space|word-spacing)$/.test(
|
|
3521
|
-
prop,
|
|
3522
|
-
)
|
|
3523
|
-
)
|
|
3524
|
-
return null;
|
|
4042
|
+
if (!INHERITED_TEXT.test(prop)) return null;
|
|
3525
4043
|
const reached = [
|
|
3526
4044
|
...new Set(
|
|
3527
4045
|
partsOf(ctx, /** @type {any} */ (s)).flatMap(t =>
|
|
@@ -3659,24 +4177,6 @@ function sameState(state, states) {
|
|
|
3659
4177
|
return states.find(x => flat(x) === flat(state)) ?? null;
|
|
3660
4178
|
}
|
|
3661
4179
|
|
|
3662
|
-
/** Other words for a state, each read as the first of these there is. */
|
|
3663
|
-
const STATE_SYNONYMS = wordTable(
|
|
3664
|
-
/** @type {Record<string, string[]>} */ ({
|
|
3665
|
-
pressed: ['isPressed', 'active'],
|
|
3666
|
-
press: ['isPressed', 'active'],
|
|
3667
|
-
on: ['isPressed', 'checked', 'selected'],
|
|
3668
|
-
down: ['active'],
|
|
3669
|
-
clicked: ['active'],
|
|
3670
|
-
hovered: ['hover'],
|
|
3671
|
-
focused: ['focus-visible', 'focus-within', 'focus'],
|
|
3672
|
-
checked: ['checked', 'selected'],
|
|
3673
|
-
selected: ['selected', 'checked'],
|
|
3674
|
-
open: ['open', 'expanded'],
|
|
3675
|
-
expanded: ['expanded', 'open'],
|
|
3676
|
-
inactive: ['disabled'],
|
|
3677
|
-
}),
|
|
3678
|
-
);
|
|
3679
|
-
|
|
3680
4180
|
/**
|
|
3681
4181
|
* The state a word for one names among those a part has, by the one table
|
|
3682
4182
|
* of other words for states (expanded: open; pressed: a toggle's isPressed,
|
|
@@ -3802,7 +4302,10 @@ export function coveredPaints(ctx, part, prop) {
|
|
|
3802
4302
|
? null
|
|
3803
4303
|
: t?.states.includes(k) && (v === k || v === 'true')
|
|
3804
4304
|
? `--state ${k}`
|
|
3805
|
-
:
|
|
4305
|
+
: // (A prop the part's doc lists, or one the census saw it drawn
|
|
4306
|
+
// with, a toast's `type`.)
|
|
4307
|
+
t?.props.includes(k) ||
|
|
4308
|
+
/** @type {any} */ (C.MAP[part])?.attrs?.[k]?.includes(v)
|
|
3806
4309
|
? `--when ${k}:${v}`
|
|
3807
4310
|
: null;
|
|
3808
4311
|
covered.push({token: r.token, flags, cond: cond.replace(':', '=')});
|
|
@@ -3810,24 +4313,6 @@ export function coveredPaints(ctx, part, prop) {
|
|
|
3810
4313
|
return {rest, covered};
|
|
3811
4314
|
}
|
|
3812
4315
|
|
|
3813
|
-
/**
|
|
3814
|
-
* The colors a part's color prop may show when none is given: its default
|
|
3815
|
-
* as its doc gives it; with none (Text's depends on its type), each value
|
|
3816
|
-
* of the prop whose text token the part's own color reads, in the order
|
|
3817
|
-
* the prop lists them. Empty with no color prop.
|
|
3818
|
-
* @param {{type?: string, default?: string | null} | undefined} prop
|
|
3819
|
-
* @param {Record<string, unknown> | undefined} reads the tokens the part's color reads (its part data)
|
|
3820
|
-
* @returns {string[]}
|
|
3821
|
-
*/
|
|
3822
|
-
function colorPropDefaults(prop, reads) {
|
|
3823
|
-
if (!prop) return [];
|
|
3824
|
-
const own = /^'([\w-]+)'$/.exec(String(prop.default ?? '').trim())?.[1];
|
|
3825
|
-
if (own) return [own];
|
|
3826
|
-
return [...String(prop.type ?? '').matchAll(/'([\w-]+)'/g)]
|
|
3827
|
-
.map(m => m[1])
|
|
3828
|
-
.filter(v => Object.hasOwn(reads ?? {}, `--color-text-${v}`));
|
|
3829
|
-
}
|
|
3830
|
-
|
|
3831
4316
|
/**
|
|
3832
4317
|
* Check one setting and give it back ready to store, or refuse. What it
|
|
3833
4318
|
* accepts, the settings loader takes too: the loader's own check runs last,
|
|
@@ -3839,11 +4324,13 @@ function colorPropDefaults(prop, reads) {
|
|
|
3839
4324
|
* @param {string | undefined} value
|
|
3840
4325
|
* @param {SetFlags} flags
|
|
3841
4326
|
* @param {boolean} [unset] an undo of one setting: only the identity of the setting is checked
|
|
3842
|
-
* @param {{reads?: ReadonlySet<string>, element?: Record<string, unknown
|
|
4327
|
+
* @param {{reads?: ReadonlySet<string>, element?: Record<string, unknown>, saved?: boolean}} [scope] `reads`: the custom
|
|
3843
4328
|
* properties the theme itself sets where the value is read, which a var()
|
|
3844
4329
|
* in it reads as it reads a design token; `element`: the custom properties
|
|
3845
4330
|
* set on the element the value is set on, when that is not the theme's
|
|
3846
|
-
* root (a surface's own tokens), the only ones that can loop back to it
|
|
4331
|
+
* root (a surface's own tokens), the only ones that can loop back to it;
|
|
4332
|
+
* `saved`: the setting is read from the settings file, not typed in, so a
|
|
4333
|
+
* rule about what a new `set` writes does not refuse it
|
|
3847
4334
|
* @returns {import('./_settings.mjs').Setting}
|
|
3848
4335
|
*/
|
|
3849
4336
|
export function checkSetting(
|
|
@@ -3854,7 +4341,124 @@ export function checkSetting(
|
|
|
3854
4341
|
value,
|
|
3855
4342
|
flags,
|
|
3856
4343
|
unset = false,
|
|
3857
|
-
|
|
4344
|
+
scope = {},
|
|
4345
|
+
) {
|
|
4346
|
+
try {
|
|
4347
|
+
return checkTyped(ctx, slug, data, thing, value, flags, unset, scope);
|
|
4348
|
+
} catch (e) {
|
|
4349
|
+
throw keepTypedScope(e, ctx, slug, data, flags);
|
|
4350
|
+
}
|
|
4351
|
+
}
|
|
4352
|
+
|
|
4353
|
+
/** The scope flags a refusal's line keeps from the line typed. */
|
|
4354
|
+
const SCOPE_FLAGS = /** @type {const} */ (['state', 'when', 'mode']);
|
|
4355
|
+
|
|
4356
|
+
/**
|
|
4357
|
+
* Every line a refusal offers for the theme keeps the scope typed: a
|
|
4358
|
+
* `--state` or `--when` on the same part, and a `--mode`, that the line
|
|
4359
|
+
* leaves out and does not give another value for go back into it whenever
|
|
4360
|
+
* the command takes the line with them, so following the line never writes
|
|
4361
|
+
* wider than what was asked (a hovered link's color offered for every
|
|
4362
|
+
* link). A line the command refuses with that flag (a `--mode` on what is
|
|
4363
|
+
* not a color) is the one that works, and is kept as it is.
|
|
4364
|
+
* @param {unknown} e
|
|
4365
|
+
* @param {import('./_settings.mjs').Ctx} ctx
|
|
4366
|
+
* @param {string} slug
|
|
4367
|
+
* @param {import('./_settings.mjs').ThemeData} data
|
|
4368
|
+
* @param {SetFlags} flags
|
|
4369
|
+
*/
|
|
4370
|
+
function keepTypedScope(e, ctx, slug, data, flags) {
|
|
4371
|
+
if (!(e instanceof AstryxError) || !e.suggestions?.length || !data) return e;
|
|
4372
|
+
const typed = SCOPE_FLAGS.filter(k => flags?.[k]);
|
|
4373
|
+
if (!typed.length) return e;
|
|
4374
|
+
/** The line as the command reads it, set or undo. @param {string} name */
|
|
4375
|
+
const read = name => {
|
|
4376
|
+
const sub = name.startsWith(`${P} undo ${slug} `)
|
|
4377
|
+
? 'undo'
|
|
4378
|
+
: name.startsWith(`${P} set ${slug} `)
|
|
4379
|
+
? 'set'
|
|
4380
|
+
: null;
|
|
4381
|
+
if (!sub) return null;
|
|
4382
|
+
const line = readSetLine(
|
|
4383
|
+
sub === 'undo' ? name.replace(`${P} undo `, `${P} set `) : name,
|
|
4384
|
+
slug,
|
|
4385
|
+
);
|
|
4386
|
+
return line ? {sub, ...line} : null;
|
|
4387
|
+
};
|
|
4388
|
+
/**
|
|
4389
|
+
* Whether the command takes the line with these flags.
|
|
4390
|
+
* @param {NonNullable<ReturnType<typeof read>>} line
|
|
4391
|
+
* @param {SetFlags} withFlags
|
|
4392
|
+
*/
|
|
4393
|
+
const takes = (line, withFlags) => {
|
|
4394
|
+
try {
|
|
4395
|
+
checkTyped(
|
|
4396
|
+
ctx,
|
|
4397
|
+
slug,
|
|
4398
|
+
structuredClone(data),
|
|
4399
|
+
line.thing,
|
|
4400
|
+
line.value,
|
|
4401
|
+
withFlags,
|
|
4402
|
+
line.sub === 'undo',
|
|
4403
|
+
);
|
|
4404
|
+
return true;
|
|
4405
|
+
} catch (err) {
|
|
4406
|
+
if (err instanceof AstryxError) return false;
|
|
4407
|
+
throw err;
|
|
4408
|
+
}
|
|
4409
|
+
};
|
|
4410
|
+
e.suggestions = e.suggestions.map(x => {
|
|
4411
|
+
const line = read(x.name);
|
|
4412
|
+
if (!line) return x;
|
|
4413
|
+
const missing = typed.filter(
|
|
4414
|
+
k =>
|
|
4415
|
+
line.flags[k] == null &&
|
|
4416
|
+
(k === 'mode' || (line.flags.on ?? null) === (flags.on ?? null)),
|
|
4417
|
+
);
|
|
4418
|
+
if (!missing.length) return x;
|
|
4419
|
+
/** @type {SetFlags} */
|
|
4420
|
+
const withFlags = {...line.flags};
|
|
4421
|
+
for (const k of missing) /** @type {any} */ (withFlags)[k] = flags[k];
|
|
4422
|
+
// Each flag on its own when the line does not take them together.
|
|
4423
|
+
const kept = takes(line, withFlags)
|
|
4424
|
+
? withFlags
|
|
4425
|
+
: missing
|
|
4426
|
+
.map(k => ({...line.flags, [k]: flags[k]}))
|
|
4427
|
+
.find(f => takes(line, f));
|
|
4428
|
+
if (!kept) return x;
|
|
4429
|
+
const name = setLine(
|
|
4430
|
+
slug,
|
|
4431
|
+
line.thing,
|
|
4432
|
+
line.value,
|
|
4433
|
+
kept,
|
|
4434
|
+
line.sub === 'undo',
|
|
4435
|
+
);
|
|
4436
|
+
return {...x, name};
|
|
4437
|
+
});
|
|
4438
|
+
return e;
|
|
4439
|
+
}
|
|
4440
|
+
|
|
4441
|
+
/**
|
|
4442
|
+
* {@link checkSetting} without the scope pass on its refusals.
|
|
4443
|
+
* @param {import('./_settings.mjs').Ctx} ctx
|
|
4444
|
+
* @param {string} slug
|
|
4445
|
+
* @param {import('./_settings.mjs').ThemeData} data
|
|
4446
|
+
* @param {string} thing
|
|
4447
|
+
* @param {string | undefined} value
|
|
4448
|
+
* @param {SetFlags} flags
|
|
4449
|
+
* @param {boolean} [unset]
|
|
4450
|
+
* @param {{reads?: ReadonlySet<string>, element?: Record<string, unknown>, saved?: boolean}} [scope]
|
|
4451
|
+
* @returns {import('./_settings.mjs').Setting}
|
|
4452
|
+
*/
|
|
4453
|
+
function checkTyped(
|
|
4454
|
+
ctx,
|
|
4455
|
+
slug,
|
|
4456
|
+
data,
|
|
4457
|
+
thing,
|
|
4458
|
+
value,
|
|
4459
|
+
flags,
|
|
4460
|
+
unset = false,
|
|
4461
|
+
{reads, element, saved = false} = {},
|
|
3858
4462
|
) {
|
|
3859
4463
|
// Any other dial's value pasted with its property name (`font-size:
|
|
3860
4464
|
// 18px;` for text-size, `color: #e11d48` for accent) is the value: one
|
|
@@ -3889,6 +4493,27 @@ export function checkSetting(
|
|
|
3889
4493
|
},
|
|
3890
4494
|
);
|
|
3891
4495
|
}
|
|
4496
|
+
// Tailwind's color/opacity shorthand (`black/5`, `#000/10`) is no CSS
|
|
4497
|
+
// color: the same color at that opacity is, and is the line offered; a
|
|
4498
|
+
// Tailwind stop (`blue-500/20`) is named, since its color is not read
|
|
4499
|
+
// here. The opacity is never dropped.
|
|
4500
|
+
if (!unset && typeof value === 'string') {
|
|
4501
|
+
const read = colorOpacitiesAsCss(value);
|
|
4502
|
+
if (read) {
|
|
4503
|
+
const {css: asCss, found: clear, unread} = read;
|
|
4504
|
+
refuse(
|
|
4505
|
+
E.ERR_THEME_BAD_VALUE,
|
|
4506
|
+
unread.length
|
|
4507
|
+
? `${unread.map(x => `"${x.typed}"`).join(', ')} ${unread.length > 1 ? 'are colors' : 'is a color'} with an opacity after the slash, as Tailwind writes it; CSS writes a color at an opacity as rgb(r g b / alpha), such as rgb(59 130 246 / 0.2). Give the color written out at that opacity.`
|
|
4508
|
+
: `${clear.map(x => `"${x.typed}"`).join(', ')} ${clear.length > 1 ? 'are colors' : 'is a color'} with an opacity after the slash, as Tailwind writes it; CSS writes ${clear.length > 1 ? 'them' : 'it'} as ${clear.map(x => x.color).join(', ')}.`,
|
|
4509
|
+
{
|
|
4510
|
+
run: unread.length
|
|
4511
|
+
? [`${HOW} ${thing}`]
|
|
4512
|
+
: [setLine(slug, thing, asCss, flags)],
|
|
4513
|
+
},
|
|
4514
|
+
);
|
|
4515
|
+
}
|
|
4516
|
+
}
|
|
3892
4517
|
// A value that holds NaN or undefined (a script's empty value pasted)
|
|
3893
4518
|
// is no CSS value, and Core refuses a theme that resolves to one.
|
|
3894
4519
|
if (
|
|
@@ -4047,6 +4672,61 @@ export function checkSetting(
|
|
|
4047
4672
|
);
|
|
4048
4673
|
}
|
|
4049
4674
|
}
|
|
4675
|
+
// A part typed in the setting's place, the setting and its value after it
|
|
4676
|
+
// (`set t button background-color '#2563eb'`, `card padding 20px`,
|
|
4677
|
+
// `card 'padding: 20px'`, `buttons background-color red`): the setting
|
|
4678
|
+
// on that part, as --on reads it. (A dial of the same name, `buttons`,
|
|
4679
|
+
// only when what follows is no value of it.)
|
|
4680
|
+
if (!unset && typeof value === 'string' && !flags.on) {
|
|
4681
|
+
const on = partNamed(ctx, thing);
|
|
4682
|
+
const m =
|
|
4683
|
+
/^\s*([a-z-]+|--[a-z0-9-]+)\s*(?::\s*|\s+)(\S[\s\S]*?)\s*;?\s*$/i.exec(
|
|
4684
|
+
value,
|
|
4685
|
+
);
|
|
4686
|
+
const next = m ? m[1].toLowerCase() : '';
|
|
4687
|
+
if (
|
|
4688
|
+
on &&
|
|
4689
|
+
m &&
|
|
4690
|
+
(!DIALS[thing] || !dialValueFits(thing, value)) &&
|
|
4691
|
+
(DIALS[next] || cssProperties().has(next) || next.startsWith('--'))
|
|
4692
|
+
)
|
|
4693
|
+
refuse(
|
|
4694
|
+
E.ERR_THEME_BAD_VALUE,
|
|
4695
|
+
`"${thing}" is a part, typed in the setting's place; the setting is ${next}, and a value for one part is given with --on ${on}.`,
|
|
4696
|
+
{
|
|
4697
|
+
run: [
|
|
4698
|
+
`${P} set ${slug} ${next} ${quoteCommandArgument(m[2])} --on ${on}${flags.when ? ` --when ${flags.when}` : ''}${flags.state ? ` --state ${flags.state}` : ''}${flags.mode ? ` --mode ${flags.mode}` : ''}`,
|
|
4699
|
+
],
|
|
4700
|
+
},
|
|
4701
|
+
);
|
|
4702
|
+
}
|
|
4703
|
+
// A dial's value that names a part or group, plural included, as a label
|
|
4704
|
+
// (`spacing 'buttons: roomy'`, `corners 'cards: pill'`), after `on`
|
|
4705
|
+
// (`'pill on card'`) or as its first or last word (`'card pill'`): the
|
|
4706
|
+
// part is read first, by the one part-in-value reader the properties
|
|
4707
|
+
// use, so the line keeps the change on that part, never the whole theme
|
|
4708
|
+
// (and never a dial the label also spells, when the rest is this dial's
|
|
4709
|
+
// value). The font takes any words, so its value is never split.
|
|
4710
|
+
if (
|
|
4711
|
+
!unset &&
|
|
4712
|
+
typeof value === 'string' &&
|
|
4713
|
+
DIALS[thing] &&
|
|
4714
|
+
thing !== 'font' &&
|
|
4715
|
+
!flags.on &&
|
|
4716
|
+
!dialValueFits(thing, value)
|
|
4717
|
+
) {
|
|
4718
|
+
const named = partInValue(ctx, value);
|
|
4719
|
+
if (named && dialValueFits(thing, named.value))
|
|
4720
|
+
refuse(
|
|
4721
|
+
E.ERR_THEME_BAD_VALUE,
|
|
4722
|
+
`${named.on} in "${value}" is a part; a value for one part is given with --on ${named.on}.`,
|
|
4723
|
+
{
|
|
4724
|
+
run: [
|
|
4725
|
+
`${P} set ${slug} ${thing} ${quoteCommandArgument(named.value)} --on ${named.on}${named.state ? ` --state ${named.state}` : ''}${flags.when ? ` --when ${flags.when}` : ''}${flags.mode ? ` --mode ${flags.mode}` : ''}`,
|
|
4726
|
+
],
|
|
4727
|
+
},
|
|
4728
|
+
);
|
|
4729
|
+
}
|
|
4050
4730
|
// A value labeled with a word that is not this setting's own name (a
|
|
4051
4731
|
// mode, a state, a device, a part, or a word the editor does not read) is
|
|
4052
4732
|
// refused with what that word means here, never set with the word dropped.
|
|
@@ -4113,7 +4793,10 @@ export function checkSetting(
|
|
|
4113
4793
|
(thing.startsWith('--') && isColorToken(thing)) ||
|
|
4114
4794
|
(partProperty &&
|
|
4115
4795
|
/color|^background$|^fill$|^stroke$|shadow/.test(thing));
|
|
4116
|
-
const parts = [
|
|
4796
|
+
const parts = [
|
|
4797
|
+
...ctx.project.target.keys(),
|
|
4798
|
+
...Object.keys(groupsOf(ctx)),
|
|
4799
|
+
];
|
|
4117
4800
|
// A theme with one mode: its own mode's label is the value, as the
|
|
4118
4801
|
// theme has no other; the other mode's label names a mode it lacks.
|
|
4119
4802
|
const only = oneModeOfTheme(data);
|
|
@@ -4424,6 +5107,7 @@ export function checkSetting(
|
|
|
4424
5107
|
unset,
|
|
4425
5108
|
reads,
|
|
4426
5109
|
element,
|
|
5110
|
+
saved,
|
|
4427
5111
|
);
|
|
4428
5112
|
// A var() with a fallback always gives a value; a name one slip from a
|
|
4429
5113
|
// design token is noted as a likely typo, and the setting stands.
|
|
@@ -4467,15 +5151,7 @@ export function checkSetting(
|
|
|
4467
5151
|
* @returns {{on: string, value: string, state?: string} | null}
|
|
4468
5152
|
*/
|
|
4469
5153
|
function partInValue(ctx, text) {
|
|
4470
|
-
|
|
4471
|
-
const partOf = w => {
|
|
4472
|
-
const word = w.trim().toLowerCase().replace(/\s+/g, '-');
|
|
4473
|
-
return (
|
|
4474
|
-
[word, word.replace(/e?s$/, ''), word.replace(/s$/, '')].find(
|
|
4475
|
-
x => x && (ctx.project.target.has(x) || FAMILIES[x]),
|
|
4476
|
-
) ?? null
|
|
4477
|
-
);
|
|
4478
|
-
};
|
|
5154
|
+
const partOf = (/** @type {string} */ w) => partNamed(ctx, w);
|
|
4479
5155
|
const t = text.trim();
|
|
4480
5156
|
/** @type {Array<[string, string, string?]>} part words, value, state */
|
|
4481
5157
|
const readings = [];
|
|
@@ -4499,6 +5175,23 @@ function partInValue(ctx, text) {
|
|
|
4499
5175
|
return null;
|
|
4500
5176
|
}
|
|
4501
5177
|
|
|
5178
|
+
/**
|
|
5179
|
+
* The part or group a word names as --on reads it (a plural is its part:
|
|
5180
|
+
* `cards`, `buttons`), or null. The one reader for a part named inside a
|
|
5181
|
+
* value and a part typed in the setting's place.
|
|
5182
|
+
* @param {any} ctx
|
|
5183
|
+
* @param {string} w
|
|
5184
|
+
* @returns {string | null}
|
|
5185
|
+
*/
|
|
5186
|
+
export function partNamed(ctx, w) {
|
|
5187
|
+
const word = String(w).trim().toLowerCase().replace(/\s+/g, '-');
|
|
5188
|
+
return (
|
|
5189
|
+
[word, word.replace(/e?s$/, ''), word.replace(/s$/, '')].find(
|
|
5190
|
+
x => x && (ctx.project.target.has(x) || groupsOf(ctx)[x]),
|
|
5191
|
+
) ?? null
|
|
5192
|
+
);
|
|
5193
|
+
}
|
|
5194
|
+
|
|
4502
5195
|
/**
|
|
4503
5196
|
* A note for a var() with a fallback whose name is a letter or two off a
|
|
4504
5197
|
* design token (`var(--spacing-xl, 2rem)` when the token is `--spacing-x1`):
|
|
@@ -4533,6 +5226,7 @@ function fallbackVarTypo(v, TOKENS) {
|
|
|
4533
5226
|
* @param {Record<string, unknown>} [element] the custom properties set on
|
|
4534
5227
|
* the element the value is set on, when that is not the theme's root (a
|
|
4535
5228
|
* surface's own tokens): only these can loop back to it
|
|
5229
|
+
* @param {boolean} [saved] read from the settings file, not typed in
|
|
4536
5230
|
* @returns {import('./_settings.mjs').Setting}
|
|
4537
5231
|
*/
|
|
4538
5232
|
function checkSettingAsTyped(
|
|
@@ -4545,6 +5239,7 @@ function checkSettingAsTyped(
|
|
|
4545
5239
|
unset = false,
|
|
4546
5240
|
reads = undefined,
|
|
4547
5241
|
element = undefined,
|
|
5242
|
+
saved = false,
|
|
4548
5243
|
) {
|
|
4549
5244
|
const s = checkOne(
|
|
4550
5245
|
ctx,
|
|
@@ -4556,6 +5251,7 @@ function checkSettingAsTyped(
|
|
|
4556
5251
|
unset,
|
|
4557
5252
|
reads,
|
|
4558
5253
|
element,
|
|
5254
|
+
saved,
|
|
4559
5255
|
);
|
|
4560
5256
|
const why = unset ? null : valueProblem(s);
|
|
4561
5257
|
if (why)
|
|
@@ -4586,6 +5282,7 @@ function checkSettingAsTyped(
|
|
|
4586
5282
|
* @param {boolean} unset
|
|
4587
5283
|
* @param {ReadonlySet<string>} [reads] custom properties the theme sets where the value is read
|
|
4588
5284
|
* @param {Record<string, unknown>} [element] the custom properties set on the element the value is set on, when that is not the theme's root
|
|
5285
|
+
* @param {boolean} [saved] read from the settings file, not typed in
|
|
4589
5286
|
* @returns {import('./_settings.mjs').Setting}
|
|
4590
5287
|
*/
|
|
4591
5288
|
function checkOne(
|
|
@@ -4598,6 +5295,7 @@ function checkOne(
|
|
|
4598
5295
|
unset,
|
|
4599
5296
|
reads,
|
|
4600
5297
|
element = undefined,
|
|
5298
|
+
saved = false,
|
|
4601
5299
|
) {
|
|
4602
5300
|
const {C} = ctx;
|
|
4603
5301
|
const TARGET = ctx.project.target;
|
|
@@ -4822,25 +5520,75 @@ function checkOne(
|
|
|
4822
5520
|
});
|
|
4823
5521
|
// --only is checked on a part this Core has; a part in other letters or
|
|
4824
5522
|
// misspelt gets the part's own refusal first, with --only kept.
|
|
4825
|
-
//
|
|
4826
|
-
//
|
|
4827
|
-
|
|
4828
|
-
|
|
4829
|
-
|
|
5523
|
+
// --only keeps a change to the part named. On a group itself, or with no
|
|
5524
|
+
// part, it names nothing to keep to, and is refused. On a part that is
|
|
5525
|
+
// styled on its own already (a part in no group that spreads, such as a
|
|
5526
|
+
// sub-part or a member of a group that spreads only when named), it asks
|
|
5527
|
+
// for what the change does anyway: the change is made, without it, and
|
|
5528
|
+
// said, so the escape always works.
|
|
5529
|
+
if (s.only && (!s.on || TARGET.has(s.on) || groupsOf(ctx)[s.on])) {
|
|
5530
|
+
// (One predicate with the settings reader: onlyMeans.)
|
|
5531
|
+
if (onlyMeans(s.on) === 'group')
|
|
4830
5532
|
refuse(
|
|
4831
5533
|
E.ERR_INVALID_ARGUMENT,
|
|
4832
5534
|
'--only is for one member of a group, such as text-input (how --list groups).',
|
|
4833
5535
|
{run: [`${HOW} --list groups`]},
|
|
4834
5536
|
);
|
|
4835
|
-
|
|
5537
|
+
// (One predicate with the settings reader: a member of a group that
|
|
5538
|
+
// spreads.)
|
|
5539
|
+
if (!onlyFits(s, ctx)) {
|
|
5540
|
+
s.only = undefined;
|
|
5541
|
+
if (!unset)
|
|
5542
|
+
s.note = `${s.on} is styled on its own already (only the ${AUTO_SPREAD.join(' and ')} groups spread), so --only changes nothing: it is saved without it`;
|
|
5543
|
+
}
|
|
5544
|
+
}
|
|
5545
|
+
// A control that grows with its content takes its top and bottom padding
|
|
5546
|
+
// from its size's height, so controls keep one height at each size: a
|
|
5547
|
+
// padding of those sides alone changes nothing on it.
|
|
5548
|
+
if (
|
|
5549
|
+
s.on &&
|
|
5550
|
+
/^padding-(top|bottom|block(-start|-end)?)$/.test(kebab(String(thing)))
|
|
5551
|
+
) {
|
|
5552
|
+
const reached = partsOf(ctx, /** @type {any} */ (s));
|
|
5553
|
+
if (
|
|
5554
|
+
reached.length &&
|
|
5555
|
+
reached.every(
|
|
5556
|
+
t =>
|
|
5557
|
+
growsWithContent(ctx, t, s.when) &&
|
|
5558
|
+
!notGrowingWhens(ctx, t, s.when).length,
|
|
5559
|
+
)
|
|
5560
|
+
)
|
|
4836
5561
|
refuse(
|
|
4837
|
-
E.
|
|
4838
|
-
`${s.on}
|
|
4839
|
-
|
|
4840
|
-
// (a variant, a state, a mode) kept, never a wider write.
|
|
4841
|
-
{run: [setLine(slug, thing, v, {...s, only: undefined}, unset)]},
|
|
5562
|
+
E.ERR_THEME_NO_EFFECT,
|
|
5563
|
+
`${s.on} keeps Core's top and bottom padding, so a theme's padding never makes it taller than the other controls at its size; ${thing} changes nothing on it. Set its height instead: ${P} set ${slug} height <length> --on ${s.on} (every control's height at that size; add --only for ${s.on} alone).`,
|
|
5564
|
+
{run: [`${HOW} height`]},
|
|
4842
5565
|
);
|
|
4843
5566
|
}
|
|
5567
|
+
// A control's height is a size every control shares, which Core reads
|
|
5568
|
+
// inside its own sums: a word (auto) cannot be one. Only a height set
|
|
5569
|
+
// writes as a size token is refused (one predicate with set): a variant
|
|
5570
|
+
// that is not a size keeps a plain height. (A saved word height was built
|
|
5571
|
+
// as a plain height, and still is.)
|
|
5572
|
+
const asToken =
|
|
5573
|
+
!unset && !saved
|
|
5574
|
+
? sharedControlHeight(ctx, {...s, source: 'property'})
|
|
5575
|
+
: null;
|
|
5576
|
+
if (asToken && !controlHeightValue(String(value)))
|
|
5577
|
+
refuse(
|
|
5578
|
+
E.ERR_THEME_BAD_VALUE,
|
|
5579
|
+
`${value} is not a size, and a height on ${s.on} ${asToken.own ? `is written as its own size token (${asToken.token})` : 'is the size every control takes (buttons, inputs, selectors, input groups)'}: give a length, as in ${P} set ${slug} height <length> --on ${s.on}${asToken.own ? ' --only' : ''}.`,
|
|
5580
|
+
{run: [`${HOW} height`]},
|
|
5581
|
+
);
|
|
5582
|
+
// (The height is written as that size's token: a value that reads the
|
|
5583
|
+
// token, itself or through the tokens set on the controls, would read
|
|
5584
|
+
// itself.)
|
|
5585
|
+
const loop = asToken ? heightTokenLoop(data, asToken, String(value)) : null;
|
|
5586
|
+
if (asToken && loop)
|
|
5587
|
+
refuse(
|
|
5588
|
+
E.ERR_THEME_BAD_VALUE,
|
|
5589
|
+
`${value} reads ${loop.length > 1 ? `${loop.slice(0, -1).join(', which reads ')}, which reads ` : ''}${asToken.token}, which is the token this height is written as, so it would read itself: give a length, as in ${P} set ${slug} height <length> --on ${s.on}${s.when ? ` --when ${s.when}` : ''}${asToken.own ? ' --only' : ''}.`,
|
|
5590
|
+
{run: [`${HOW} height`]},
|
|
5591
|
+
);
|
|
4844
5592
|
// A font role in other letters (Body, CODE) is that role.
|
|
4845
5593
|
if (
|
|
4846
5594
|
thing === 'font' &&
|
|
@@ -4857,7 +5605,7 @@ function checkOne(
|
|
|
4857
5605
|
},
|
|
4858
5606
|
);
|
|
4859
5607
|
const isRole = thing === 'font' && FONT_ROLES.includes(s.on ?? '');
|
|
4860
|
-
if (s.on && !isRole && !
|
|
5608
|
+
if (s.on && !isRole && !groupsOf(ctx)[s.on]) {
|
|
4861
5609
|
const t = TARGET.get(s.on);
|
|
4862
5610
|
if (!t) {
|
|
4863
5611
|
// Another case of a part or group, its class name copied from the
|
|
@@ -4888,16 +5636,16 @@ function checkOne(
|
|
|
4888
5636
|
const words = partWords();
|
|
4889
5637
|
const candidates = [
|
|
4890
5638
|
...TARGET.keys(),
|
|
4891
|
-
...Object.keys(
|
|
5639
|
+
...Object.keys(groupsOf(ctx)),
|
|
4892
5640
|
...[...words]
|
|
4893
|
-
.filter(([, on]) => TARGET.has(on) ||
|
|
5641
|
+
.filter(([, on]) => TARGET.has(on) || groupsOf(ctx)[on])
|
|
4894
5642
|
.map(([w]) => w),
|
|
4895
5643
|
].filter(n => n !== lower && n !== dashed);
|
|
4896
5644
|
// The one typo ranker (closestOf). A hit that is a part or group
|
|
4897
5645
|
// name is that name (`tabel` is table); a word that is no name is
|
|
4898
5646
|
// read as its part (`sidebr` is side-nav).
|
|
4899
5647
|
const isName = (/** @type {string} */ n) =>
|
|
4900
|
-
TARGET.has(n) || Boolean(
|
|
5648
|
+
TARGET.has(n) || Boolean(groupsOf(ctx)[n]);
|
|
4901
5649
|
return [
|
|
4902
5650
|
...new Set(
|
|
4903
5651
|
closestOf(dashed, candidates).map(n =>
|
|
@@ -4913,7 +5661,7 @@ function checkOne(
|
|
|
4913
5661
|
w.replace(/(ch|sh|x|s)es$/, '$1'),
|
|
4914
5662
|
w.replace(/s$/, ''),
|
|
4915
5663
|
])
|
|
4916
|
-
.find(x => x !== lower && (TARGET.has(x) ||
|
|
5664
|
+
.find(x => x !== lower && (TARGET.has(x) || groupsOf(ctx)[x]));
|
|
4917
5665
|
// Several parts named in one --on (`button, text-input`, `button/
|
|
4918
5666
|
// text-input`, `button and text-input`, or spaces): one command per
|
|
4919
5667
|
// part named, each checked, never a group that one word of the list
|
|
@@ -4921,16 +5669,19 @@ function checkOne(
|
|
|
4921
5669
|
const listed = /,|\/|&|\band\b/.test(lower);
|
|
4922
5670
|
// (Words with only spaces that name one part, `text inputs`, are
|
|
4923
5671
|
// that part.)
|
|
4924
|
-
if (
|
|
5672
|
+
if (
|
|
5673
|
+
!(TARGET.has(dashed) || groupsOf(ctx)[dashed]) &&
|
|
5674
|
+
(listed || !singular)
|
|
5675
|
+
) {
|
|
4925
5676
|
const pieces = lower
|
|
4926
5677
|
.split(/\s*(?:,|\/|&|\band\b)\s*|\s+/)
|
|
4927
5678
|
.map(x => x.trim())
|
|
4928
5679
|
.filter(Boolean);
|
|
4929
5680
|
const partOf = (/** @type {string} */ w) =>
|
|
4930
|
-
TARGET.has(w) ||
|
|
5681
|
+
TARGET.has(w) || groupsOf(ctx)[w]
|
|
4931
5682
|
? w
|
|
4932
5683
|
: ([w.replace(/ies$/, 'y'), w.replace(/s$/, '')].find(
|
|
4933
|
-
x => x !== w && (TARGET.has(x) ||
|
|
5684
|
+
x => x !== w && (TARGET.has(x) || groupsOf(ctx)[x]),
|
|
4934
5685
|
) ?? null);
|
|
4935
5686
|
const found = pieces.map(partOf);
|
|
4936
5687
|
const parts = [...new Set(found.filter(x => x != null))];
|
|
@@ -4952,15 +5703,15 @@ function checkOne(
|
|
|
4952
5703
|
);
|
|
4953
5704
|
}
|
|
4954
5705
|
const named =
|
|
4955
|
-
TARGET.has(lower) ||
|
|
5706
|
+
TARGET.has(lower) || groupsOf(ctx)[lower]
|
|
4956
5707
|
? lower
|
|
4957
|
-
: TARGET.has(dashed) ||
|
|
5708
|
+
: TARGET.has(dashed) || groupsOf(ctx)[dashed]
|
|
4958
5709
|
? dashed
|
|
4959
5710
|
: singular
|
|
4960
5711
|
? singular
|
|
4961
5712
|
: typoParts.length === 1
|
|
4962
5713
|
? typoParts[0]
|
|
4963
|
-
: byWord && (TARGET.has(byWord) ||
|
|
5714
|
+
: byWord && (TARGET.has(byWord) || groupsOf(ctx)[byWord])
|
|
4964
5715
|
? byWord
|
|
4965
5716
|
: null;
|
|
4966
5717
|
// The page (the body behind every part) is painted by the app shell.
|
|
@@ -4986,11 +5737,80 @@ function checkOne(
|
|
|
4986
5737
|
run: [setLine(slug, thing, v, {...s, on: named}, unset)],
|
|
4987
5738
|
},
|
|
4988
5739
|
);
|
|
5740
|
+
// A name that is a part's name with more after it: the longest part
|
|
5741
|
+
// name it starts with. The rest is a state of that part (`link-hover`,
|
|
5742
|
+
// `tab-selected`), a variant of it (`button-primary`), or a piece it
|
|
5743
|
+
// draws (a top nav heading's title, `top-nav-heading-title`): the
|
|
5744
|
+
// piece's own name among the parts it holds, or, holding none, an
|
|
5745
|
+
// inner element the census saw. A text property those inner elements
|
|
5746
|
+
// read from tokens is offered as those tokens there. Any other rest
|
|
5747
|
+
// (`tab-panel`) is no piece of it.
|
|
5748
|
+
const holder = [...TARGET.keys()]
|
|
5749
|
+
.filter(n => dashed.startsWith(`${n}-`))
|
|
5750
|
+
.sort((a, b) => b.length - a.length)[0];
|
|
5751
|
+
const rest = holder ? dashed.slice(holder.length + 1) : '';
|
|
5752
|
+
const record = holder ? ctx.C.MAP[holder] : null;
|
|
5753
|
+
const variant = Object.entries(record?.attrs ?? {}).find(
|
|
5754
|
+
([, vals]) => Array.isArray(vals) && vals.includes(rest),
|
|
5755
|
+
)?.[0];
|
|
5756
|
+
if (
|
|
5757
|
+
holder &&
|
|
5758
|
+
(STATE_WORDS.includes(rest) ||
|
|
5759
|
+
TARGET.get(holder)?.states?.includes(rest))
|
|
5760
|
+
)
|
|
5761
|
+
refuse(
|
|
5762
|
+
E.ERR_THEME_UNKNOWN_PART,
|
|
5763
|
+
`"${s.on}" is not a part name; it is ${holder} when ${rest}, set on ${holder} --state ${rest}.`,
|
|
5764
|
+
{
|
|
5765
|
+
didYouMean: [holder],
|
|
5766
|
+
run: [
|
|
5767
|
+
setLine(slug, thing, v, {...s, on: holder, state: rest}, unset),
|
|
5768
|
+
],
|
|
5769
|
+
},
|
|
5770
|
+
);
|
|
5771
|
+
if (holder && variant)
|
|
5772
|
+
refuse(
|
|
5773
|
+
E.ERR_THEME_UNKNOWN_PART,
|
|
5774
|
+
`"${s.on}" is not a part name; it is ${holder} with ${variant} ${rest}, set on ${holder} --when ${variant}:${rest}.`,
|
|
5775
|
+
{
|
|
5776
|
+
didYouMean: [holder],
|
|
5777
|
+
run: [
|
|
5778
|
+
setLine(
|
|
5779
|
+
slug,
|
|
5780
|
+
thing,
|
|
5781
|
+
v,
|
|
5782
|
+
{...s, on: holder, when: `${variant}:${rest}`},
|
|
5783
|
+
unset,
|
|
5784
|
+
),
|
|
5785
|
+
],
|
|
5786
|
+
},
|
|
5787
|
+
);
|
|
5788
|
+
const held = record?.contains ?? [];
|
|
5789
|
+
if (
|
|
5790
|
+
holder &&
|
|
5791
|
+
(held.length
|
|
5792
|
+
? held.some(k => k.split('-').at(-1) === rest.split('-').at(-1))
|
|
5793
|
+
: Object.keys(record?.innerSets ?? {}).length > 0)
|
|
5794
|
+
) {
|
|
5795
|
+
const toks = innerPropTokens(ctx.C, holder, kebab(thing));
|
|
5796
|
+
refuse(
|
|
5797
|
+
E.ERR_THEME_UNKNOWN_PART,
|
|
5798
|
+
`"${s.on}" is not a part name; what it names is drawn inside ${holder}, the part to set it on${toks.length ? `, where its ${kebab(thing)} comes from ${toks.join(', ')}` : ''}.`,
|
|
5799
|
+
{
|
|
5800
|
+
didYouMean: [holder],
|
|
5801
|
+
run: toks.length
|
|
5802
|
+
? toks.map(tok =>
|
|
5803
|
+
setLine(slug, tok, v, {...s, on: holder}, unset),
|
|
5804
|
+
)
|
|
5805
|
+
: [setLine(slug, thing, v, {...s, on: holder}, unset)],
|
|
5806
|
+
},
|
|
5807
|
+
);
|
|
5808
|
+
}
|
|
4989
5809
|
// A plural or another case names the part it means; a typo of one
|
|
4990
5810
|
// part leads with the same command on that part.
|
|
4991
5811
|
const near = nearest(s.on.toLowerCase().replace(/s$/, ''), [
|
|
4992
5812
|
...TARGET.keys(),
|
|
4993
|
-
...Object.keys(
|
|
5813
|
+
...Object.keys(groupsOf(ctx)),
|
|
4994
5814
|
]);
|
|
4995
5815
|
const typo = near.filter(n => typoOf(lower, n));
|
|
4996
5816
|
refuse(
|
|
@@ -5091,6 +5911,19 @@ function checkOne(
|
|
|
5091
5911
|
// name or its ARIA attribute (`isPressed`, `aria-pressed` on a button,
|
|
5092
5912
|
// `isSelected` on a tab) is the state of that name.
|
|
5093
5913
|
if (s.state) s.state = partState(ctx, s.on, s.state);
|
|
5914
|
+
// Another word for one state the part has (pressed on a part whose
|
|
5915
|
+
// press is active): written as that state, and said. A word for more
|
|
5916
|
+
// than one of its states is not written: the refusal below offers one.
|
|
5917
|
+
if (s.state && !s.state.includes('+') && !statesHold(states, s.state)) {
|
|
5918
|
+
const same = (STATE_SYNONYMS[s.state.toLowerCase()] ?? []).filter(x =>
|
|
5919
|
+
states.includes(x),
|
|
5920
|
+
);
|
|
5921
|
+
if (same.length === 1) {
|
|
5922
|
+
// (Its own note, beside any other the setting carries.)
|
|
5923
|
+
s.stateNote = `read as --state ${same[0]}: ${s.on} marks the ${s.state} moment as ${same[0]}`;
|
|
5924
|
+
s.state = same[0];
|
|
5925
|
+
}
|
|
5926
|
+
}
|
|
5094
5927
|
// Several states in one --state (`hover,focus-visible`, `hover
|
|
5095
5928
|
// focus-visible`): one line per state, the value quoted as typed.
|
|
5096
5929
|
const typedStates = String(flags.state ?? '')
|
|
@@ -5145,16 +5978,23 @@ function checkOne(
|
|
|
5145
5978
|
);
|
|
5146
5979
|
if (s.state && !statesHold(states, s.state)) {
|
|
5147
5980
|
// A part drawn inside this one that has the state (a calendar's day
|
|
5148
|
-
// is today; the calendar is not
|
|
5981
|
+
// is today; the calendar is not; a pagination's page button is the
|
|
5982
|
+
// current one): that part's line, with the state. Its own pieces
|
|
5983
|
+
// first, then the parts the census finds drawn inside it.
|
|
5149
5984
|
const state = String(s.state);
|
|
5985
|
+
const holds = (/** @type {string} */ k) =>
|
|
5986
|
+
statesHold(partStates(ctx, k), state);
|
|
5150
5987
|
const inner = meant
|
|
5151
5988
|
? []
|
|
5152
|
-
: [
|
|
5153
|
-
|
|
5154
|
-
k =>
|
|
5155
|
-
k.startsWith(`${s.on}-`)
|
|
5156
|
-
|
|
5157
|
-
|
|
5989
|
+
: [
|
|
5990
|
+
...new Set([
|
|
5991
|
+
...[...ctx.project.target.keys()].filter(k =>
|
|
5992
|
+
k.startsWith(`${s.on}-`),
|
|
5993
|
+
),
|
|
5994
|
+
...(ctx.C.MAP[String(s.on)]?.contains ?? []),
|
|
5995
|
+
]),
|
|
5996
|
+
]
|
|
5997
|
+
.filter(k => ctx.project.target.has(k) && holds(k))
|
|
5158
5998
|
.slice(0, 3);
|
|
5159
5999
|
refuse(
|
|
5160
6000
|
E.ERR_THEME_UNKNOWN_STATE,
|
|
@@ -5181,7 +6021,7 @@ function checkOne(
|
|
|
5181
6021
|
!unset &&
|
|
5182
6022
|
s.on &&
|
|
5183
6023
|
!String(s.thing).startsWith('--') &&
|
|
5184
|
-
!
|
|
6024
|
+
!groupsOf(ctx)[s.on] &&
|
|
5185
6025
|
/^(background(-color)?|color)$/.test(prop)
|
|
5186
6026
|
) {
|
|
5187
6027
|
const rec = ctx.C.MAP[s.on];
|
|
@@ -5429,10 +6269,12 @@ function checkOne(
|
|
|
5429
6269
|
);
|
|
5430
6270
|
}
|
|
5431
6271
|
// On a group, a variant or state must belong to at least one member.
|
|
5432
|
-
if (s.on &&
|
|
6272
|
+
if (s.on && groupsOf(ctx)[s.on] && (s.when || s.state)) {
|
|
5433
6273
|
const members =
|
|
5434
6274
|
/** @type {Array<[string, import('../../foundation/discovery/theming-targets.mjs').ThemingTarget]>} */ (
|
|
5435
|
-
|
|
6275
|
+
(groupsOf(ctx)[s.on] ?? [])
|
|
6276
|
+
.map(m => [m, TARGET.get(m)])
|
|
6277
|
+
.filter(([, t]) => t)
|
|
5436
6278
|
);
|
|
5437
6279
|
// What the members have between them: their props, each prop's values,
|
|
5438
6280
|
// their states. A typo or another case on the group is read as on one
|
|
@@ -5540,7 +6382,7 @@ function checkOne(
|
|
|
5540
6382
|
);
|
|
5541
6383
|
if (DIALS[thing]) {
|
|
5542
6384
|
s.source = 'dial';
|
|
5543
|
-
if (['surfaces', 'buttons', 'type'].includes(thing)) {
|
|
6385
|
+
if (['surfaces', 'buttons', 'badges', 'type'].includes(thing)) {
|
|
5544
6386
|
if (s.on)
|
|
5545
6387
|
refuse(
|
|
5546
6388
|
E.ERR_THEME_BAD_VALUE,
|
|
@@ -5603,7 +6445,11 @@ function checkOne(
|
|
|
5603
6445
|
CORNERS.find(
|
|
5604
6446
|
([n]) => lower.replace(/s$/, '') === n,
|
|
5605
6447
|
)?.[0] ?? lower,
|
|
5606
|
-
thing === 'buttons'
|
|
6448
|
+
thing === 'buttons'
|
|
6449
|
+
? {on: 'button'}
|
|
6450
|
+
: thing === 'badges'
|
|
6451
|
+
? {on: 'badge'}
|
|
6452
|
+
: {},
|
|
5607
6453
|
),
|
|
5608
6454
|
]
|
|
5609
6455
|
: [
|
|
@@ -5944,7 +6790,7 @@ function checkOne(
|
|
|
5944
6790
|
if (thing === 'corners') {
|
|
5945
6791
|
if (s.on) {
|
|
5946
6792
|
refuseInvisibleCorners(ctx, slug, s, data);
|
|
5947
|
-
refuseRadioCorners(ctx, slug, s);
|
|
6793
|
+
refuseRadioCorners(ctx, slug, s, data);
|
|
5948
6794
|
}
|
|
5949
6795
|
// With no corners setting yet, a step starts from the base theme's
|
|
5950
6796
|
// own radius.
|
|
@@ -6237,7 +7083,7 @@ function checkOne(
|
|
|
6237
7083
|
const pastSpacing = (/** @type {[string, number]} */ [, k]) => {
|
|
6238
7084
|
if (!s.on) return null;
|
|
6239
7085
|
// (A group: its first member that reads a control height.)
|
|
6240
|
-
const parts =
|
|
7086
|
+
const parts = groupsOf(ctx)[s.on] ?? [s.on];
|
|
6241
7087
|
const token = parts
|
|
6242
7088
|
.flatMap(p => C.partReads(p, 'size') ?? [])
|
|
6243
7089
|
.map((/** @type {{token: string}} */ r) => r.token)
|
|
@@ -6519,9 +7365,7 @@ function checkOne(
|
|
|
6519
7365
|
// counts when vibrancy changes the shades made from it at all (a warm
|
|
6520
7366
|
// gray has a little hue to take out or add; a pure gray has none).
|
|
6521
7367
|
const inEffect = seedsInEffect(ctx.project.cwd, slug, data);
|
|
6522
|
-
const canApply = inEffect
|
|
6523
|
-
vibrancyMoves(f.dial, f.seed, 0, 100),
|
|
6524
|
-
);
|
|
7368
|
+
const canApply = vibrancyMovesAny(inEffect);
|
|
6525
7369
|
// The fills the theme's own source sets win over their settings.
|
|
6526
7370
|
const fromSource = inEffect.filter(f => f.source);
|
|
6527
7371
|
if (!step && canApply && (!/^\d{1,3}$/.test(v) || Number(v) > 100)) {
|
|
@@ -6948,7 +7792,7 @@ function checkOne(
|
|
|
6948
7792
|
// or group, `link`) is no typo of another token's word (`pink`): the
|
|
6949
7793
|
// name near by spelling is then no reading of it.
|
|
6950
7794
|
const knownWord = (/** @type {string} */ w) =>
|
|
6951
|
-
TARGET.has(w) || Boolean(
|
|
7795
|
+
TARGET.has(w) || Boolean(groupsOf(ctx)[w]) || partWords().has(w);
|
|
6952
7796
|
const typedWords = thing.toLowerCase().replace(/^-+/, '').split('-');
|
|
6953
7797
|
const near = nearest(thing, Object.keys(TOKENS)).filter(n => {
|
|
6954
7798
|
const nearWords = n.replace(/^-+/, '').split('-');
|
|
@@ -7074,6 +7918,15 @@ function checkOne(
|
|
|
7074
7918
|
multipliedTokens(ctx.project).has(thing),
|
|
7075
7919
|
data.settings.some(x => x.thing === thing),
|
|
7076
7920
|
);
|
|
7921
|
+
// A control's size token takes what a control's height takes (one
|
|
7922
|
+
// predicate with `set height --on <control>`): no percentage. Only a
|
|
7923
|
+
// typed value is refused; a saved one still opens.
|
|
7924
|
+
if (!saved && /^--size-element-/.test(thing) && !controlHeightValue(v))
|
|
7925
|
+
refuse(
|
|
7926
|
+
E.ERR_THEME_BAD_VALUE,
|
|
7927
|
+
`${v} is not a size a control can take: ${thing} is a control's height, which Core reads inside its own sums, so it takes a length and no percentage, as in ${setLine(slug, thing, '40px', s)}.`,
|
|
7928
|
+
{run: [`${HOW} ${thing}`]},
|
|
7929
|
+
);
|
|
7077
7930
|
checkCycle(thing, v, TOKENS, data, ctx.project.cwd, s, element);
|
|
7078
7931
|
// With no part data, what reads the token is unknown: save, unchecked.
|
|
7079
7932
|
if (ctx.unchecked) return s;
|
|
@@ -7098,16 +7951,34 @@ function checkOne(
|
|
|
7098
7951
|
),
|
|
7099
7952
|
]),
|
|
7100
7953
|
);
|
|
7954
|
+
// (A text size token said for one part that reads no size token,
|
|
7955
|
+
// whose held parts read one, a tab list's tabs: the value goes into
|
|
7956
|
+
// that token on the part; the build reads it the same way.)
|
|
7957
|
+
if (results.length === 1 && results[0][1] && !results[0][1].soft) {
|
|
7958
|
+
const held = heldSizeTokenFor(
|
|
7959
|
+
C,
|
|
7960
|
+
s,
|
|
7961
|
+
results[0][0],
|
|
7962
|
+
thing,
|
|
7963
|
+
v,
|
|
7964
|
+
results[0][1],
|
|
7965
|
+
);
|
|
7966
|
+
if (held) {
|
|
7967
|
+
results[0][1] = null;
|
|
7968
|
+
const said = `${results[0][0]} never reads ${thing}: its text reads ${held}, so the value goes into ${held} on ${results[0][0]}`;
|
|
7969
|
+
s.note = s.note ? `${s.note}; ${said}` : said;
|
|
7970
|
+
}
|
|
7971
|
+
}
|
|
7101
7972
|
const recorded = results.filter(([, r]) => !r?.soft);
|
|
7102
7973
|
const hard = recorded.filter(([, r]) => r);
|
|
7103
7974
|
const spread = Boolean(
|
|
7104
|
-
|
|
7975
|
+
groupsOf(ctx)[s.on ?? ''] || (familyOf(s.on ?? '') && parts.length > 1),
|
|
7105
7976
|
);
|
|
7106
7977
|
// A part with no record is judged by its group: refused when no
|
|
7107
7978
|
// member that has a record reads the token, as the group form is.
|
|
7108
7979
|
const fam = s.on ? familyOf(s.on) : null;
|
|
7109
7980
|
if (!recorded.length && fam && !spread) {
|
|
7110
|
-
const siblings =
|
|
7981
|
+
const siblings = groupsOf(ctx)[fam].filter(t => C.MAP[t]);
|
|
7111
7982
|
const famResults = siblings.map(
|
|
7112
7983
|
t =>
|
|
7113
7984
|
/** @type {[string, import('./_compiler.mjs').CheckFailure | null]} */ ([
|
|
@@ -7343,7 +8214,54 @@ function checkOne(
|
|
|
7343
8214
|
(d.vars ?? []).some(x => inCalc.has(x.toLowerCase())),
|
|
7344
8215
|
),
|
|
7345
8216
|
);
|
|
7346
|
-
|
|
8217
|
+
// (A radius of two to four corners, each one length, is written as
|
|
8218
|
+
// each corner on the box, and its first corner as the one length the
|
|
8219
|
+
// variable takes: the build's corner radii, so it is taken.)
|
|
8220
|
+
const corners =
|
|
8221
|
+
prop === 'border-radius' &&
|
|
8222
|
+
splitTop(v.trim(), '/').every(half => {
|
|
8223
|
+
const w = splitTop(half.trim(), ' ').filter(Boolean);
|
|
8224
|
+
return (
|
|
8225
|
+
w.length >= 1 &&
|
|
8226
|
+
w.length <= 4 &&
|
|
8227
|
+
w.every(x => oneLength(x) || /^0+(?:\.0+)?$/.test(x))
|
|
8228
|
+
);
|
|
8229
|
+
}) &&
|
|
8230
|
+
(splitTop(v.trim(), ' ').filter(Boolean).length > 1 || v.includes('/'));
|
|
8231
|
+
// A padding of two to four lengths there is its sides, each with the
|
|
8232
|
+
// length typed for it: set writes them in this one change (a side
|
|
8233
|
+
// the part cannot take refuses as that side).
|
|
8234
|
+
const sides = !unset && hit && flags?.sides ? boxSides(prop, v) : null;
|
|
8235
|
+
if (sides?.length === 1) {
|
|
8236
|
+
s.value = sides[0][1];
|
|
8237
|
+
const said = `"${v.trim()}" is ${s.value} on every side, the one length ${hit} takes there`;
|
|
8238
|
+
// The value's own typo note, which the check below gives only to a
|
|
8239
|
+
// setting with no note yet, is kept beside it.
|
|
8240
|
+
const typo = fallbackVarTypo(
|
|
8241
|
+
String(s.value),
|
|
8242
|
+
ctx.project.core.tokenDefaults ?? {},
|
|
8243
|
+
);
|
|
8244
|
+
s.note = [s.note, said, typo].filter(Boolean).join('; ');
|
|
8245
|
+
} else if (sides)
|
|
8246
|
+
return {
|
|
8247
|
+
...s,
|
|
8248
|
+
sides: sides.map(([side, x]) =>
|
|
8249
|
+
checkSetting(ctx, slug, data, `${prop}-${side}`, x, {
|
|
8250
|
+
on: s.on,
|
|
8251
|
+
when: s.when,
|
|
8252
|
+
state: s.state,
|
|
8253
|
+
mode: s.mode,
|
|
8254
|
+
only: s.only,
|
|
8255
|
+
}),
|
|
8256
|
+
),
|
|
8257
|
+
};
|
|
8258
|
+
// A bare 0 is a length everywhere in CSS but inside calc(), where it
|
|
8259
|
+
// is a number: it is saved as 0px, the length it means.
|
|
8260
|
+
if (hit && /^[+-]?0*\.?0+$/.test(v.trim())) {
|
|
8261
|
+
s.value = '0px';
|
|
8262
|
+
const said = `${v.trim()} is saved as 0px: ${hit} reads ${prop} inside calc(), where a bare 0 is not a length`;
|
|
8263
|
+
s.note = s.note ? `${s.note}; ${said}` : said;
|
|
8264
|
+
} else if (hit && !oneLength(String(s.value)) && !corners) {
|
|
7347
8265
|
const first = splitTop(v.trim(), ' ')[0] ?? '';
|
|
7348
8266
|
const n = cssNumber(first);
|
|
7349
8267
|
const fix = oneLength(first)
|
|
@@ -7354,11 +8272,7 @@ function checkOne(
|
|
|
7354
8272
|
refuse(
|
|
7355
8273
|
E.ERR_THEME_BAD_VALUE,
|
|
7356
8274
|
`${hit} reads ${prop} inside calc() (its corners and inner rows follow it), where only one length works: a length, a variable, or calc(), min(), max() or clamp() giving one; not "${v.trim()}".`,
|
|
7357
|
-
{
|
|
7358
|
-
run: boxSideLines(slug, prop, v, s) ?? [
|
|
7359
|
-
setLine(slug, prop, fix, s),
|
|
7360
|
-
],
|
|
7361
|
-
},
|
|
8275
|
+
{run: [setLine(slug, prop, fix, s)]},
|
|
7362
8276
|
);
|
|
7363
8277
|
}
|
|
7364
8278
|
}
|
|
@@ -7490,6 +8404,9 @@ function checkOne(
|
|
|
7490
8404
|
// style is set for it.
|
|
7491
8405
|
if (!unset && /^outline-(color|width|offset)$/.test(prop))
|
|
7492
8406
|
noOutlineRefusal(ctx, slug, data, s, prop, v);
|
|
8407
|
+
// A border color where the theme itself sets the part's border to none
|
|
8408
|
+
// has no line to color (elsewhere set brings the border it needs).
|
|
8409
|
+
if (!unset) borderNoneRefusal(ctx, slug, data, s, prop);
|
|
7493
8410
|
// A text property on a part whose text is drawn by elements inside it
|
|
7494
8411
|
// that set that property themselves from a token (a top nav heading's
|
|
7495
8412
|
// title span) never reaches that text: the token, on the part, does.
|
|
@@ -7508,38 +8425,42 @@ function checkOne(
|
|
|
7508
8425
|
].includes(prop)
|
|
7509
8426
|
) {
|
|
7510
8427
|
const inner = partsOf(ctx, s)
|
|
7511
|
-
.map(t => {
|
|
7512
|
-
const rec = ctx.C.MAP[t];
|
|
7513
|
-
// (A color only through the parts inside it: elements inside a
|
|
7514
|
-
// part that read a color token are answered with the tokens on
|
|
7515
|
-
// the part by how.)
|
|
7516
|
-
let toks =
|
|
7517
|
-
prop === 'color'
|
|
7518
|
-
? []
|
|
7519
|
-
: Object.entries(rec?.inside ?? {})
|
|
7520
|
-
.filter(([, props]) => props.includes(prop))
|
|
7521
|
-
.map(([tok]) => tok);
|
|
7522
|
-
const held = (rec?.contains ?? []).map(x => ctx.C.MAP[x]);
|
|
7523
|
-
if (
|
|
7524
|
-
!toks.length &&
|
|
7525
|
-
!Object.keys(rec?.inside ?? {}).length &&
|
|
7526
|
-
held.length &&
|
|
7527
|
-
held.every(x => x?.own?.[prop])
|
|
7528
|
-
)
|
|
7529
|
-
toks = [
|
|
7530
|
-
...new Set(
|
|
7531
|
-
held.flatMap(x => Object.keys(x.own[prop].tokens ?? {})),
|
|
7532
|
-
),
|
|
7533
|
-
]
|
|
7534
|
-
.filter(tok => !/disabled|placeholder|accent/.test(tok))
|
|
7535
|
-
.slice(0, 4);
|
|
7536
|
-
return /** @type {const} */ ([
|
|
7537
|
-
t,
|
|
7538
|
-
rec && !rec.own?.[prop] ? toks : [],
|
|
7539
|
-
]);
|
|
7540
|
-
})
|
|
8428
|
+
.map(t => /** @type {const} */ ([t, innerPropTokens(ctx.C, t, prop)]))
|
|
7541
8429
|
.filter(([, toks]) => toks.length);
|
|
7542
|
-
|
|
8430
|
+
// One token for each part (a banner's text size, --text-label-size):
|
|
8431
|
+
// the value goes into it on the part (compileTheme), and the result
|
|
8432
|
+
// says so. With several (a top nav heading's title and subtitle
|
|
8433
|
+
// sizes), which one is meant is not known: the refusal names each.
|
|
8434
|
+
// A text column's lines (a banner's title and description) each take
|
|
8435
|
+
// it, since it means all of the part's text.
|
|
8436
|
+
const column = (/** @type {string} */ t, /** @type {string[]} */ toks) =>
|
|
8437
|
+
toks.length > 1 &&
|
|
8438
|
+
columnLineTokens(ctx.C, t, prop).join() === toks.join();
|
|
8439
|
+
// (A text size whose pieces each read a text size token, said of one
|
|
8440
|
+
// part, a top nav heading's title and supporting line: the main
|
|
8441
|
+
// text's, the largest.)
|
|
8442
|
+
const main = (/** @type {string} */ t) => {
|
|
8443
|
+
if (prop !== 'font-size' || partsOf(ctx, s).length !== 1) return null;
|
|
8444
|
+
const m = mainTextSizeToken(ctx.C, t, TOKENS);
|
|
8445
|
+
return m && !namesToken(v, m) ? m : null;
|
|
8446
|
+
};
|
|
8447
|
+
const oneEach =
|
|
8448
|
+
prop !== 'color' &&
|
|
8449
|
+
inner.every(
|
|
8450
|
+
([t, toks]) => toks.length === 1 || column(t, toks) || main(t),
|
|
8451
|
+
);
|
|
8452
|
+
if (inner.length && inner.length === partsOf(ctx, s).length && oneEach) {
|
|
8453
|
+
const said = inner
|
|
8454
|
+
.map(([part, toks]) =>
|
|
8455
|
+
toks.length === 1
|
|
8456
|
+
? `${part}'s text is drawn by elements inside it that set their own ${prop} from ${toks[0]}, so the value goes into ${toks[0]} on ${part}`
|
|
8457
|
+
: column(part, toks)
|
|
8458
|
+
? `${part}'s text is in parts inside it that set their own ${prop} from ${toks.join(' and ')}, so the value goes into each: ${toks.map(tok => `${tok} on ${part}`).join(', ')}`
|
|
8459
|
+
: `${part}'s text is drawn by elements inside it that set their own ${prop} from ${toks.join(' and ')}, so the value goes into ${main(part)} on ${part}, the size of its main text`,
|
|
8460
|
+
)
|
|
8461
|
+
.join('; ');
|
|
8462
|
+
s.note = s.note ? `${s.note}; ${said}` : said;
|
|
8463
|
+
} else if (inner.length && inner.length === partsOf(ctx, s).length) {
|
|
7543
8464
|
const [part, toks] = inner[0];
|
|
7544
8465
|
refuse(
|
|
7545
8466
|
E.ERR_THEME_NO_EFFECT,
|
|
@@ -7553,23 +8474,59 @@ function checkOne(
|
|
|
7553
8474
|
);
|
|
7554
8475
|
}
|
|
7555
8476
|
}
|
|
8477
|
+
// A text property CSS inherits that an element inside the part sets
|
|
8478
|
+
// itself, to a value the component's props choose (a code block's lines:
|
|
8479
|
+
// white-space pre, or pre-wrap when wrapped), never reaches the text
|
|
8480
|
+
// that element holds: the prop decides it, never the theme. Refused,
|
|
8481
|
+
// naming the values there.
|
|
8482
|
+
if (!unset && INHERITED_TEXT.test(prop)) {
|
|
8483
|
+
const held = partsOf(ctx, s)
|
|
8484
|
+
.map(t => /** @type {const} */ ([t, ctx.C.MAP[t]?.innerSets?.[prop]]))
|
|
8485
|
+
.filter(
|
|
8486
|
+
([t, vals]) =>
|
|
8487
|
+
Array.isArray(vals) &&
|
|
8488
|
+
vals.length > 1 &&
|
|
8489
|
+
!ctx.C.MAP[t]?.own?.[prop] &&
|
|
8490
|
+
innerPropTokens(ctx.C, t, prop).length === 0,
|
|
8491
|
+
);
|
|
8492
|
+
if (held.length && held.length === partsOf(ctx, s).length) {
|
|
8493
|
+
const [part, vals] = held[0];
|
|
8494
|
+
refuse(
|
|
8495
|
+
E.ERR_THEME_NO_EFFECT,
|
|
8496
|
+
`${part}'s text is laid out by an element inside it that sets its own ${prop} (${/** @type {string[]} */ (vals).join(' or ')}, as the component's props choose), so ${prop} on ${part} never shows; the app chooses it with that prop, never the theme.`,
|
|
8497
|
+
{run: [`${HOW} ${part}`]},
|
|
8498
|
+
);
|
|
8499
|
+
}
|
|
8500
|
+
}
|
|
7556
8501
|
// A text property CSS inherits reaches the parts inside the part that
|
|
7557
8502
|
// do not set it themselves (a side nav section's items): the result
|
|
7558
8503
|
// says which.
|
|
7559
8504
|
if (!unset) {
|
|
7560
8505
|
const reach = inheritedReach(ctx, s, prop);
|
|
7561
|
-
if (reach) s.note = reach;
|
|
8506
|
+
if (reach) s.note = s.note ? `${s.note}; ${reach}` : reach;
|
|
7562
8507
|
}
|
|
7563
8508
|
// Text, headings and links take their color from the color prop.
|
|
7564
8509
|
const textParts = COLOR_PROP_PARTS;
|
|
7565
|
-
// A heading
|
|
7566
|
-
// reads, on
|
|
7567
|
-
const
|
|
8510
|
+
// A text, heading or link color is written as the text color tokens
|
|
8511
|
+
// its color prop reads, on that part alone (compileTheme), so it shows.
|
|
8512
|
+
const propTokens = partsOf(ctx, s).map(t =>
|
|
8513
|
+
colorPropTokens(ctx, t, s.when),
|
|
8514
|
+
);
|
|
8515
|
+
// (A value that is no color is refused below, with the nearest color.)
|
|
8516
|
+
const propColor =
|
|
7568
8517
|
prop === 'color' &&
|
|
7569
|
-
|
|
7570
|
-
|
|
8518
|
+
isColorValue(v) &&
|
|
8519
|
+
propTokens.length > 0 &&
|
|
8520
|
+
propTokens.every(k => k.length);
|
|
8521
|
+
if (propColor && partsOf(ctx, s).some(t => t !== 'heading')) {
|
|
8522
|
+
const toks = [...new Set(propTokens.flat())];
|
|
8523
|
+
const said = `the color goes into ${toks.join(' and ')} on ${s.on}, the ${toks.length > 1 ? 'tokens' : 'token'} its color prop reads (Core sets that prop after part styles)`;
|
|
8524
|
+
s.note = s.note ? `${s.note}; ${said}` : said;
|
|
8525
|
+
}
|
|
7571
8526
|
if (
|
|
7572
|
-
!
|
|
8527
|
+
!propColor &&
|
|
8528
|
+
// (A value that is no color, "12px", is refused below as no color.)
|
|
8529
|
+
(unset || !v || isColorValue(v)) &&
|
|
7573
8530
|
(prop === 'color' || prop === '-webkit-text-fill-color') &&
|
|
7574
8531
|
partsOf(ctx, s).some(t => textParts.includes(t))
|
|
7575
8532
|
) {
|
|
@@ -7581,26 +8538,24 @@ function checkOne(
|
|
|
7581
8538
|
v && isColorValue(v) && isFixedColor(v) && !/\bvar\(/i.test(v)
|
|
7582
8539
|
? v
|
|
7583
8540
|
: (nearestColorName(v) ?? '#1f2937');
|
|
7584
|
-
// The tokens the part's color prop reads
|
|
7585
|
-
//
|
|
7586
|
-
|
|
7587
|
-
|
|
7588
|
-
|
|
7589
|
-
|
|
7590
|
-
|
|
7591
|
-
partComponentDocs(ctx, /** @type {string} */ (s.on))
|
|
7592
|
-
.map(d => d.doc.props?.color)
|
|
7593
|
-
.find(Boolean),
|
|
7594
|
-
ctx.C.MAP[/** @type {string} */ (s.on)]?.own?.color?.tokens,
|
|
7595
|
-
);
|
|
7596
|
-
const tail = `${s.on ? ` --on ${s.on}` : ''}${s.mode ? ` --mode ${s.mode}` : ''}`;
|
|
8541
|
+
// The tokens the part's color prop reads (colorPropTokens), set on
|
|
8542
|
+
// the part alone.
|
|
8543
|
+
const colors = colorPropTokens(
|
|
8544
|
+
ctx,
|
|
8545
|
+
/** @type {string} */ (s.on),
|
|
8546
|
+
s.when,
|
|
8547
|
+
).map(t => t.replace(/^--color-text-/, ''));
|
|
7597
8548
|
refuse(
|
|
7598
8549
|
E.ERR_THEME_NO_EFFECT,
|
|
7599
8550
|
`${s.on} takes its color from the color prop, which Core sets after part styles, so a color set on ${s.on} never shows. Set the token its color prop reads (${colors.map(c => `${c}: --color-text-${c}`).join('; ')}) on ${s.on} instead.`,
|
|
7600
8551
|
{
|
|
7601
|
-
|
|
7602
|
-
|
|
7603
|
-
|
|
8552
|
+
// The token on the part, in the scope typed: a hovered link's
|
|
8553
|
+
// color is the hovered link's token, never every link's.
|
|
8554
|
+
run: colors.map(c =>
|
|
8555
|
+
setLine(slug, `--color-text-${c}`, color, {
|
|
8556
|
+
...s,
|
|
8557
|
+
when: named ? undefined : s.when,
|
|
8558
|
+
}),
|
|
7604
8559
|
),
|
|
7605
8560
|
},
|
|
7606
8561
|
);
|
|
@@ -7647,7 +8602,26 @@ function checkOne(
|
|
|
7647
8602
|
: [`${HOW} ${prop}`],
|
|
7648
8603
|
},
|
|
7649
8604
|
);
|
|
8605
|
+
// A box color shorthand takes a color per side (`#ddd #ddd
|
|
8606
|
+
// transparent`), each one read as a color.
|
|
8607
|
+
const sides = colorSides(prop, v);
|
|
8608
|
+
if (sides?.tooMany)
|
|
8609
|
+
refuse(
|
|
8610
|
+
E.ERR_THEME_BAD_VALUE,
|
|
8611
|
+
`${prop} takes 1 to ${sides.max} colors, one per side; "${v}" has ${sides.colors.length}.`,
|
|
8612
|
+
{run: [`${HOW} ${prop}`]},
|
|
8613
|
+
);
|
|
8614
|
+
const notColor = sides?.colors.find(
|
|
8615
|
+
x => !isColorValue(x.color) || !isFixedColor(x.color),
|
|
8616
|
+
);
|
|
8617
|
+
if (sides && notColor)
|
|
8618
|
+
refuse(
|
|
8619
|
+
E.ERR_THEME_BAD_VALUE,
|
|
8620
|
+
`${prop} takes a color for each side; "${notColor.color}" in "${v}" is not one.`,
|
|
8621
|
+
{run: [`${HOW} ${prop}`]},
|
|
8622
|
+
);
|
|
7650
8623
|
if (
|
|
8624
|
+
!sides &&
|
|
7651
8625
|
COLOR_PROPS.test(prop) &&
|
|
7652
8626
|
!CSS_WIDE.includes(v.trim().toLowerCase()) &&
|
|
7653
8627
|
(!isColorValue(v) || !isFixedColor(v))
|
|
@@ -7693,6 +8667,9 @@ function checkOne(
|
|
|
7693
8667
|
s.mode &&
|
|
7694
8668
|
!COLOR_PROPS.test(prop) &&
|
|
7695
8669
|
!(prop === 'background' && isColorValue(v)) &&
|
|
8670
|
+
// (The see-through border a border color brings, in that color's
|
|
8671
|
+
// mode: it shows nothing, and the other mode keeps its own line.)
|
|
8672
|
+
!(prop === 'border' && v.trim() === BORDER_TO_COLOR) &&
|
|
7696
8673
|
// A gradient background (no image file) goes per mode: its colors
|
|
7697
8674
|
// are each painted in that mode only (compileTheme).
|
|
7698
8675
|
!(
|
|
@@ -7995,21 +8972,39 @@ function checkOne(
|
|
|
7995
8972
|
* @param {import('./_settings.mjs').Ctx} ctx
|
|
7996
8973
|
* @param {string} slug
|
|
7997
8974
|
* @param {import('./_settings.mjs').Setting} s
|
|
8975
|
+
* @param {import('./_settings.mjs').ThemeData} data
|
|
7998
8976
|
*/
|
|
7999
|
-
function refuseRadioCorners(ctx, slug, s) {
|
|
8977
|
+
function refuseRadioCorners(ctx, slug, s, data) {
|
|
8000
8978
|
if (ctx.unchecked) return;
|
|
8001
8979
|
const parts = partsOf(ctx, s);
|
|
8002
8980
|
if (!parts.length || !parts.every(t => radioCircle(ctx.C, t))) return;
|
|
8003
8981
|
// A radius set on the part itself overrides the circle: a square radio
|
|
8004
|
-
// is asked of this component, by name.
|
|
8982
|
+
// is asked of this component, by name. A fully round ask (pill, round)
|
|
8983
|
+
// is the circle it has: with a radius the theme set on it, the undo of
|
|
8984
|
+
// that radius gives the circle back.
|
|
8005
8985
|
const px = cornerPxOf(String(s.value));
|
|
8006
|
-
const
|
|
8007
|
-
|
|
8008
|
-
|
|
8009
|
-
|
|
8986
|
+
const saved = (data?.settings ?? []).find(
|
|
8987
|
+
(/** @type {any} */ x) =>
|
|
8988
|
+
x.thing === 'border-radius' &&
|
|
8989
|
+
x.on === s.on &&
|
|
8990
|
+
!x.when &&
|
|
8991
|
+
!x.state &&
|
|
8992
|
+
!x.mode,
|
|
8993
|
+
);
|
|
8994
|
+
// (A step, "rounder" or "sharper", is no length: only "more" is round,
|
|
8995
|
+
// and "less" gets no line, since a circle has no corner to sharpen.)
|
|
8996
|
+
const step = Number.isFinite(px) ? null : String(s.value);
|
|
8997
|
+
const round = step ? step === 'more' : px >= 9999;
|
|
8998
|
+
const own = round
|
|
8999
|
+
? saved
|
|
9000
|
+
? `${P} undo ${slug} border-radius --on ${s.on}`
|
|
9001
|
+
: null
|
|
9002
|
+
: step
|
|
9003
|
+
? null
|
|
9004
|
+
: setLine(slug, 'border-radius', px === 0 ? '0' : `${px}px`, s);
|
|
8010
9005
|
refuse(
|
|
8011
9006
|
E.ERR_THEME_NO_EFFECT,
|
|
8012
|
-
`${s.on} is a radio's circle (border-radius 50%), not a corner, so the corners dial leaves it and changes nothing you see.${own ? ` A border-radius on it sets its shape: ${own.replace(`${P} `, '')}.` : ''}`,
|
|
9007
|
+
`${s.on} is a radio's circle (border-radius 50%), not a corner, so the corners dial leaves it and changes nothing you see.${round ? (saved ? ` ${slug} sets border-radius ${saved.value} on it; undoing that gives the circle back: ${String(own).replace(`${P} `, '')}.` : ` It is fully round already.`) : own ? ` A border-radius on it sets its shape: ${own.replace(`${P} `, '')}.` : ''}`,
|
|
8013
9008
|
{run: own ? [own] : [`${HOW} ${s.on}`]},
|
|
8014
9009
|
);
|
|
8015
9010
|
}
|
|
@@ -8046,13 +9041,16 @@ function refuseInvisibleCorners(ctx, slug, s, data) {
|
|
|
8046
9041
|
.slice(0, 3);
|
|
8047
9042
|
refuse(
|
|
8048
9043
|
E.ERR_THEME_NO_EFFECT,
|
|
8049
|
-
`${s.on} has no background, border or shadow of its own, so rounding its corners changes nothing you see.${kids.length ? ` Parts inside it that do show an edge: ${kids.join(', ')}.` : ''}`,
|
|
9044
|
+
`${s.on} has no background, border or shadow of its own, so rounding its corners changes nothing you see. To round ${s.on} itself, give it a background or a border first, then set its corners.${kids.length ? ` Parts inside it that do show an edge: ${kids.join(', ')}.` : ''}`,
|
|
8050
9045
|
{
|
|
8051
|
-
|
|
8052
|
-
|
|
8053
|
-
|
|
8054
|
-
|
|
8055
|
-
|
|
9046
|
+
// (How names the fill and border the part takes; the editor offers
|
|
9047
|
+
// no value the person did not type.)
|
|
9048
|
+
run: [
|
|
9049
|
+
`${HOW} ${s.on}`,
|
|
9050
|
+
...kids.map(k =>
|
|
9051
|
+
setLine(slug, 'corners', s.value || 'round', {...s, on: k}),
|
|
9052
|
+
),
|
|
9053
|
+
],
|
|
8056
9054
|
},
|
|
8057
9055
|
);
|
|
8058
9056
|
}
|
|
@@ -8100,6 +9098,7 @@ function statusTwin(C, recorded, thing, when) {
|
|
|
8100
9098
|
*/
|
|
8101
9099
|
const dialWrites = token =>
|
|
8102
9100
|
PALETTE_TOKENS.has(token) ||
|
|
9101
|
+
isLookToken(token) ||
|
|
8103
9102
|
/^--(text-(heading|display)-\d-weight|radius-|spacing-|size-element-|font-size-)/.test(
|
|
8104
9103
|
token,
|
|
8105
9104
|
);
|
|
@@ -8188,10 +9187,18 @@ export function propertyValueProblem(ctx, prop, value, TOKENS, reads) {
|
|
|
8188
9187
|
const mismatch = tokenKindMismatch(ctx, prop, v);
|
|
8189
9188
|
if (mismatch) return mismatch.message;
|
|
8190
9189
|
if (CSS_WIDE.includes(v.toLowerCase())) return null;
|
|
8191
|
-
if (COLOR_PROPS.test(prop))
|
|
8192
|
-
|
|
8193
|
-
|
|
8194
|
-
|
|
9190
|
+
if (COLOR_PROPS.test(prop)) {
|
|
9191
|
+
const sides = colorSides(prop, v);
|
|
9192
|
+
const one = (/** @type {string} */ x) =>
|
|
9193
|
+
/\bvar\(/i.test(x) || isColorValue(x);
|
|
9194
|
+
if (sides)
|
|
9195
|
+
return sides.tooMany
|
|
9196
|
+
? `${prop} takes 1 to ${sides.max} colors, one per side; "${v}" has ${sides.colors.length}.`
|
|
9197
|
+
: sides.colors.every(x => one(x.color))
|
|
9198
|
+
? null
|
|
9199
|
+
: `${prop} takes a color for each side; "${v}" is not that.`;
|
|
9200
|
+
return one(v) ? null : `${prop} takes a color; "${v}" is not one.`;
|
|
9201
|
+
}
|
|
8195
9202
|
const grammar = propertyProblem(prop, v);
|
|
8196
9203
|
return grammar ? `${prop} takes ${grammar.takes}; "${v}" is not one.` : null;
|
|
8197
9204
|
}
|