@astryxdesign/cli 0.7.13 → 0.7.14-canary.108f354
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 +18 -18
- package/api/component/__fixtures__/resolutions/modules.txt +1 -1
- package/api/doctor/doctor.mjs +3 -7
- package/api/experimental.d.mts +2 -0
- package/api/experimental.mjs +12 -0
- package/api/icon/_adapter.d.mts +10 -0
- package/api/icon/_adapter.mjs +31 -2
- package/api/icon/_authoring.d.mts +2 -1
- package/api/icon/_authoring.mjs +91 -6
- package/api/icon/_options.mjs +1 -0
- package/api/icon/_records.d.mts +18 -0
- package/api/icon/_records.mjs +26 -0
- package/api/icon/add/add.mjs +7 -1
- package/api/icon/definitions/definitions.d.mts +12 -0
- package/api/icon/definitions/definitions.mjs +83 -0
- package/api/icon/icon.doc.mjs +5 -4
- package/api/icon/icon.mjs +5 -16
- package/api/icon/icon.type.d.mts +29 -2
- package/api/icon/icon.type.mjs +17 -3
- package/api/icon/iconAdd.doc.mjs +1 -1
- package/api/icon/iconMap.doc.mjs +2 -2
- package/api/icon/iconNewSet.doc.mjs +8 -2
- package/api/icon/map/map.mjs +21 -2
- package/api/icon/new-set/new-set.mjs +14 -2
- package/api/icon/search/search.mjs +2 -15
- package/api/icon/use/use.mjs +4 -3
- package/api/integration/validate-integration.mjs +6 -1
- package/api/integration/validate-integration.type.d.mts +12 -0
- package/api/integration/validate-integration.type.mjs +5 -0
- package/api/theme-edit/_adapter.d.mts +116 -0
- package/api/theme-edit/_adapter.mjs +1683 -0
- package/api/theme-edit/_catalog.d.mts +59 -0
- package/api/theme-edit/_catalog.mjs +564 -0
- package/api/theme-edit/_check.d.mts +49 -0
- package/api/theme-edit/_check.mjs +845 -0
- package/api/theme-edit/_color.d.mts +29 -0
- package/api/theme-edit/_color.mjs +300 -0
- package/api/theme-edit/_compiler.d.mts +61 -0
- package/api/theme-edit/_compiler.mjs +522 -0
- package/api/theme-edit/_css-properties.d.mts +10 -0
- package/api/theme-edit/_css-properties.mjs +556 -0
- package/api/theme-edit/_parts.d.mts +111 -0
- package/api/theme-edit/_parts.mjs +409 -0
- package/api/theme-edit/_png.d.mts +40 -0
- package/api/theme-edit/_png.mjs +187 -0
- package/api/theme-edit/_preview.d.mts +121 -0
- package/api/theme-edit/_preview.mjs +720 -0
- package/api/theme-edit/_project.d.mts +83 -0
- package/api/theme-edit/_project.mjs +289 -0
- package/api/theme-edit/_settings.d.mts +222 -0
- package/api/theme-edit/_settings.mjs +861 -0
- package/api/theme-edit/_tables.d.mts +132 -0
- package/api/theme-edit/_tables.mjs +700 -0
- package/api/theme-edit/theme-edit.d.mts +93 -0
- package/api/theme-edit/theme-edit.mjs +145 -0
- package/api/theme-edit/theme-edit.type.d.mts +413 -0
- package/api/theme-edit/theme-edit.type.mjs +233 -0
- package/api/theme-edit/themeEditHow.doc.d.mts +6 -0
- package/api/theme-edit/themeEditHow.doc.mjs +88 -0
- package/api/theme-edit/themeEditNew.doc.d.mts +6 -0
- package/api/theme-edit/themeEditNew.doc.mjs +89 -0
- package/api/theme-edit/themeEditPreviewAdd.doc.d.mts +6 -0
- package/api/theme-edit/themeEditPreviewAdd.doc.mjs +100 -0
- package/api/theme-edit/themeEditPreviewApp.doc.d.mts +6 -0
- package/api/theme-edit/themeEditPreviewApp.doc.mjs +84 -0
- package/api/theme-edit/themeEditPreviewList.doc.d.mts +6 -0
- package/api/theme-edit/themeEditPreviewList.doc.mjs +53 -0
- package/api/theme-edit/themeEditPreviewRemove.doc.d.mts +6 -0
- package/api/theme-edit/themeEditPreviewRemove.doc.mjs +66 -0
- package/api/theme-edit/themeEditSet.doc.d.mts +6 -0
- package/api/theme-edit/themeEditSet.doc.mjs +165 -0
- package/api/theme-edit/themeEditShow.doc.d.mts +6 -0
- package/api/theme-edit/themeEditShow.doc.mjs +86 -0
- package/api/theme-edit/themeEditUndo.doc.d.mts +6 -0
- package/api/theme-edit/themeEditUndo.doc.mjs +124 -0
- package/assets/docs/color.doc.mjs +5 -5
- package/assets/docs/tree/icon-sets.doc.mjs +6 -2
- package/assets/docs/tree/tokens-border.doc.mjs +1 -1
- package/assets/docs/tree/tokens-color.doc.mjs +2 -2
- package/assets/docs/tree/tokens-data.doc.mjs +2 -2
- package/assets/docs/tree/tokens-duration.doc.mjs +1 -1
- package/assets/docs/tree/tokens-ease.doc.mjs +1 -1
- package/assets/docs/tree/tokens-focus.doc.mjs +1 -1
- package/assets/docs/tree/tokens-font-weight.doc.mjs +1 -1
- package/assets/docs/tree/tokens-radius.doc.mjs +1 -1
- package/assets/docs/tree/tokens-shadow.doc.mjs +1 -1
- package/assets/docs/tree/tokens-size.doc.mjs +1 -1
- package/assets/docs/tree/tokens-spacing.doc.mjs +1 -1
- package/assets/docs/tree/tokens-syntax.doc.mjs +1 -1
- package/assets/docs/tree/tokens-text-size.doc.mjs +1 -1
- package/assets/docs/tree/tokens-type-scale.doc.mjs +1 -1
- package/assets/docs/tree/tokens-typography.doc.mjs +1 -1
- package/assets/icons/definitions/bank.doc.mjs +1 -1
- package/assets/icons/definitions/save.doc.mjs +1 -1
- package/assets/preview-app/README.md +6 -0
- package/assets/preview-app/css.d.ts +5 -0
- package/assets/preview-app/gitignore +1 -0
- package/assets/preview-app/next.config.mjs +6 -0
- package/assets/preview-app/package.json +23 -0
- package/assets/preview-app/src/app/globals.css +5 -0
- package/assets/preview-app/src/app/layout.tsx +21 -0
- package/assets/preview-app/src/app/page.tsx +94 -0
- package/assets/preview-app/src/app/providers.tsx +16 -0
- package/assets/preview-app/tsconfig.json +27 -0
- package/assets/templates/blocks/components/InternationalizationProvider/InternationalizationProvider01ShippedLocale.doc.mjs +2 -1
- package/assets/templates/blocks/components/InternationalizationProvider/InternationalizationProvider02Overrides.doc.mjs +2 -1
- package/assets/templates/blocks/components/InternationalizationProvider/InternationalizationProvider03RtlDirection.doc.mjs +2 -1
- package/assets/templates/blocks/components/InternationalizationProvider/InternationalizationProvider04Calendar.doc.mjs +2 -1
- package/assets/templates/blocks/components/Text/useTruncationHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Text/useTruncationHookUsage.tsx +112 -0
- package/authoring/doctypes/_schema.d.mts +1 -0
- package/authoring/doctypes/_schema.mjs +1 -0
- package/authoring/doctypes/command/command.doc.mjs +7 -0
- package/authoring/doctypes/command/type.ts +3 -0
- package/authoring/doctypes/icon-set/parse.d.mts +7 -0
- package/authoring/doctypes/icon-set/parse.mjs +18 -8
- package/clients/cli/commands/doctor.mjs +33 -3
- package/clients/cli/commands/experimental/icon.mjs +67 -14
- package/clients/cli/commands/experimental/index.mjs +2 -0
- package/clients/cli/commands/experimental/theme.mjs +684 -0
- package/clients/cli/commands/experimental-icon-new-set.doc.mjs +7 -1
- package/clients/cli/commands/experimental-icon.doc.mjs +3 -2
- package/clients/cli/commands/experimental-theme-add.doc.mjs +78 -0
- package/clients/cli/commands/experimental-theme-compile.doc.mjs +97 -0
- package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +84 -0
- package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +66 -0
- package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +121 -0
- package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +66 -0
- package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +104 -0
- package/clients/cli/commands/experimental-theme-editor.doc.mjs +49 -0
- package/clients/cli/commands/experimental-theme-eject.doc.mjs +71 -0
- package/clients/cli/commands/experimental-theme-list.doc.mjs +49 -0
- package/clients/cli/commands/experimental-theme-palette-generate.doc.mjs +73 -0
- package/clients/cli/commands/experimental-theme-palette.doc.mjs +37 -0
- package/clients/cli/commands/experimental-theme-preview-add.doc.mjs +86 -0
- package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +66 -0
- package/clients/cli/commands/experimental-theme-preview-list.doc.mjs +48 -0
- package/clients/cli/commands/experimental-theme-preview-remove.doc.mjs +59 -0
- package/clients/cli/commands/experimental-theme-preview.doc.mjs +40 -0
- package/clients/cli/commands/experimental-theme-remove.doc.mjs +55 -0
- package/clients/cli/commands/experimental-theme-targets.doc.mjs +61 -0
- package/clients/cli/commands/experimental-theme-template.doc.mjs +61 -0
- package/clients/cli/commands/experimental-theme-use.doc.mjs +55 -0
- package/clients/cli/commands/experimental-theme.doc.mjs +57 -0
- package/clients/cli/commands/experimental.doc.mjs +10 -3
- package/clients/cli/commands/theme.mjs +101 -34
- package/clients/cli/index.mjs +18 -0
- package/clients/cli/lib/define-command.mjs +3 -0
- package/foundation/discovery/icon-set-checks.d.mts +16 -1
- package/foundation/discovery/icon-set-checks.mjs +68 -7
- package/foundation/discovery/icon-set-discovery.d.mts +21 -6
- package/foundation/discovery/icon-set-discovery.mjs +17 -8
- package/foundation/discovery/template-icon-meanings.d.mts +39 -0
- package/foundation/discovery/template-icon-meanings.mjs +95 -0
- package/foundation/discovery/theming-targets.d.mts +6 -0
- package/foundation/discovery/theming-targets.mjs +33 -0
- package/foundation/response/error-codes.d.mts +12 -1
- package/foundation/response/error-codes.doc.mjs +66 -0
- package/foundation/response/error-codes.mjs +55 -0
- package/foundation/response/response-types.doc.mjs +55 -0
- package/foundation/text/template-meanings-line.d.mts +16 -0
- package/foundation/text/template-meanings-line.mjs +37 -0
- package/foundation/xle/browser.d.mts +2 -2
- package/package.json +6 -6
|
@@ -0,0 +1,845 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file The type check of one `set` or `undo <theme> <thing>`: the part, the variant, the
|
|
5
|
+
* state, the mode, the token's type, and whether the part (or anything in
|
|
6
|
+
* it) reads the token. A change that cannot take effect is refused, and the
|
|
7
|
+
* refusal leads with the command that works. Also `how`, which answers a
|
|
8
|
+
* plain-words question with exact commands from the same part data.
|
|
9
|
+
*
|
|
10
|
+
* @position api/theme-edit — checks and questions over the part data
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
|
|
14
|
+
import {CSS_PROPERTIES} from './_css-properties.mjs';
|
|
15
|
+
import {
|
|
16
|
+
AUTO_SPREAD,
|
|
17
|
+
COLOR_PROPS,
|
|
18
|
+
COMMON_STATES,
|
|
19
|
+
CORNERS,
|
|
20
|
+
DESIGN,
|
|
21
|
+
DIALS,
|
|
22
|
+
DIRECT,
|
|
23
|
+
FAMILIES,
|
|
24
|
+
GROUPS,
|
|
25
|
+
HEADING_TRACKING,
|
|
26
|
+
HEADING_WEIGHTS,
|
|
27
|
+
INTENTS,
|
|
28
|
+
LIKE,
|
|
29
|
+
HOW,
|
|
30
|
+
P,
|
|
31
|
+
PART_WORDS,
|
|
32
|
+
SPACING,
|
|
33
|
+
TEXT_SIZE,
|
|
34
|
+
THING_HINTS,
|
|
35
|
+
familyOf,
|
|
36
|
+
} from './_tables.mjs';
|
|
37
|
+
import {isColorValue, isNumber, isSize} from './_color.mjs';
|
|
38
|
+
import {MODAL} from './_compiler.mjs';
|
|
39
|
+
import {
|
|
40
|
+
camel,
|
|
41
|
+
kebab,
|
|
42
|
+
nearest,
|
|
43
|
+
partDefault,
|
|
44
|
+
partsOf,
|
|
45
|
+
q,
|
|
46
|
+
refuse,
|
|
47
|
+
} from './_settings.mjs';
|
|
48
|
+
|
|
49
|
+
const E = ERROR_CODES;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @typedef {object} SetFlags
|
|
53
|
+
* @property {string} [on]
|
|
54
|
+
* @property {string} [when]
|
|
55
|
+
* @property {string} [state]
|
|
56
|
+
* @property {string} [mode]
|
|
57
|
+
* @property {boolean} [only]
|
|
58
|
+
*/
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Refuse a value that does not parse as the token's type.
|
|
62
|
+
* @param {string} type @param {string} value @param {string} name
|
|
63
|
+
*/
|
|
64
|
+
function checkTypedValue(type, value, name) {
|
|
65
|
+
if (type === 'color' && !isColorValue(value))
|
|
66
|
+
refuse(
|
|
67
|
+
E.ERR_THEME_BAD_VALUE,
|
|
68
|
+
`${name} is a color; "${value}" is not a CSS color.`,
|
|
69
|
+
{fix: 'give one like "#1f2937", "rgb(31 41 55)" or "oklch(0.5 0.1 250)"'},
|
|
70
|
+
);
|
|
71
|
+
if (type === 'size' && !isSize(value))
|
|
72
|
+
refuse(
|
|
73
|
+
E.ERR_THEME_BAD_VALUE,
|
|
74
|
+
`${name} is a size; "${value}" is not a CSS size.`,
|
|
75
|
+
{fix: 'give one like 6px, 0.75rem or 0'},
|
|
76
|
+
);
|
|
77
|
+
if (type === 'number' && !isNumber(value))
|
|
78
|
+
refuse(
|
|
79
|
+
E.ERR_THEME_BAD_VALUE,
|
|
80
|
+
`${name} is a number; "${value}" is not one.`,
|
|
81
|
+
{fix: 'give one like 600 or 1.4'},
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Check one setting and give it back ready to store, or refuse.
|
|
87
|
+
* @param {import('./_settings.mjs').Ctx} ctx
|
|
88
|
+
* @param {string} slug
|
|
89
|
+
* @param {import('./_settings.mjs').ThemeData} data
|
|
90
|
+
* @param {string} thing
|
|
91
|
+
* @param {string | undefined} value
|
|
92
|
+
* @param {SetFlags} flags
|
|
93
|
+
* @param {boolean} [unset] an undo of one setting: only the identity of the setting is checked
|
|
94
|
+
* @returns {import('./_settings.mjs').Setting}
|
|
95
|
+
*/
|
|
96
|
+
export function checkSetting(
|
|
97
|
+
ctx,
|
|
98
|
+
slug,
|
|
99
|
+
data,
|
|
100
|
+
thing,
|
|
101
|
+
value,
|
|
102
|
+
flags,
|
|
103
|
+
unset = false,
|
|
104
|
+
) {
|
|
105
|
+
const {C} = ctx;
|
|
106
|
+
const TARGET = ctx.project.target;
|
|
107
|
+
const TOKENS = ctx.project.core.tokenDefaults;
|
|
108
|
+
if (!thing)
|
|
109
|
+
refuse(E.ERR_MISSING_ARGUMENT, 'Name the thing to change.', {
|
|
110
|
+
run: [`${P} ${unset ? 'undo' : 'set'} --help`],
|
|
111
|
+
});
|
|
112
|
+
if (!unset && (value === undefined || value === ''))
|
|
113
|
+
refuse(E.ERR_MISSING_ARGUMENT, `Give a value for ${thing}.`, {
|
|
114
|
+
run: [`${P} set --help`],
|
|
115
|
+
});
|
|
116
|
+
const v = value ?? '';
|
|
117
|
+
/** @type {import('./_settings.mjs').Setting} */
|
|
118
|
+
const s = {thing, value: v, source: 'dial'};
|
|
119
|
+
if (flags.on) s.on = flags.on;
|
|
120
|
+
if (flags.when) s.when = flags.when;
|
|
121
|
+
if (flags.state) s.state = flags.state;
|
|
122
|
+
if (flags.only) s.only = true;
|
|
123
|
+
if (flags.mode) {
|
|
124
|
+
if (flags.mode !== 'light' && flags.mode !== 'dark')
|
|
125
|
+
refuse(
|
|
126
|
+
E.ERR_THEME_BAD_VALUE,
|
|
127
|
+
`--mode takes light or dark, not "${flags.mode}".`,
|
|
128
|
+
);
|
|
129
|
+
s.mode = flags.mode;
|
|
130
|
+
}
|
|
131
|
+
const onFlag = s.on ? ` --on ${s.on}` : '';
|
|
132
|
+
if (s.mode && data.mode !== 'both')
|
|
133
|
+
refuse(
|
|
134
|
+
E.ERR_THEME_NO_MODE,
|
|
135
|
+
`This theme is ${data.mode}; --mode is for themes with both modes.`,
|
|
136
|
+
{run: [`${P} set ${slug} ${thing} ${q(v)}${onFlag}`]},
|
|
137
|
+
);
|
|
138
|
+
if ((s.when || s.state) && !s.on)
|
|
139
|
+
refuse(E.ERR_MISSING_ARGUMENT, '--when and --state need --on <part>.', {
|
|
140
|
+
run: [`${HOW} <part>`],
|
|
141
|
+
});
|
|
142
|
+
if (s.only) {
|
|
143
|
+
const fam = s.on ? familyOf(s.on) : null;
|
|
144
|
+
if (!fam || FAMILIES[/** @type {string} */ (s.on)])
|
|
145
|
+
refuse(
|
|
146
|
+
E.ERR_INVALID_ARGUMENT,
|
|
147
|
+
'--only is for one member of a family, such as text-input (how --list families).',
|
|
148
|
+
{run: [`${HOW} --list families`]},
|
|
149
|
+
);
|
|
150
|
+
if (!AUTO_SPREAD.includes(/** @type {string} */ (fam)))
|
|
151
|
+
refuse(
|
|
152
|
+
E.ERR_INVALID_ARGUMENT,
|
|
153
|
+
`${s.on} is styled on its own already: only ${AUTO_SPREAD.join(' and ')} spread to their family, so drop --only.`,
|
|
154
|
+
{
|
|
155
|
+
run: [
|
|
156
|
+
unset
|
|
157
|
+
? `${P} undo ${slug} ${thing}${v ? ` ${q(v)}` : ''} --on ${s.on}`
|
|
158
|
+
: `${P} set ${slug} ${thing} ${q(v)} --on ${s.on}`,
|
|
159
|
+
],
|
|
160
|
+
},
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
const isRole =
|
|
164
|
+
thing === 'font' && ['body', 'heading', 'code'].includes(s.on ?? '');
|
|
165
|
+
if (s.on && !isRole && !FAMILIES[s.on]) {
|
|
166
|
+
const t = TARGET.get(s.on);
|
|
167
|
+
if (!t) {
|
|
168
|
+
refuse(
|
|
169
|
+
E.ERR_THEME_UNKNOWN_PART,
|
|
170
|
+
`"${s.on}" is not a part you can style.`,
|
|
171
|
+
{
|
|
172
|
+
didYouMean: nearest(s.on, [
|
|
173
|
+
...TARGET.keys(),
|
|
174
|
+
...Object.keys(FAMILIES),
|
|
175
|
+
]),
|
|
176
|
+
run: [
|
|
177
|
+
`${HOW} ${s.on.split('-')[0]} --list parts`,
|
|
178
|
+
`${HOW} "${s.on}"`,
|
|
179
|
+
],
|
|
180
|
+
},
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
if (s.when) {
|
|
184
|
+
const [p, wv] = s.when.split(':');
|
|
185
|
+
if (!wv)
|
|
186
|
+
refuse(
|
|
187
|
+
E.ERR_THEME_BAD_VALUE,
|
|
188
|
+
'--when takes <prop>:<value>, such as variant:primary.',
|
|
189
|
+
{run: [`${HOW} ${s.on}`]},
|
|
190
|
+
);
|
|
191
|
+
if (!t.props.includes(p))
|
|
192
|
+
refuse(
|
|
193
|
+
E.ERR_THEME_UNKNOWN_VARIANT,
|
|
194
|
+
`${s.on} has no prop "${p}". It has: ${t.props.join(', ') || 'none'}.`,
|
|
195
|
+
{didYouMean: nearest(p, t.props), run: [`${HOW} ${s.on}`]},
|
|
196
|
+
);
|
|
197
|
+
const vals = C.variantValues(s.on)[p] ?? [];
|
|
198
|
+
if (vals.length && !vals.includes(wv))
|
|
199
|
+
refuse(
|
|
200
|
+
E.ERR_THEME_UNKNOWN_VARIANT,
|
|
201
|
+
`${s.on} has no ${p} "${wv}". ${p} is one of: ${vals.join(', ')}.`,
|
|
202
|
+
{didYouMean: nearest(wv, vals), run: [`${HOW} ${s.on}`]},
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
const states = [...t.states, ...COMMON_STATES];
|
|
206
|
+
if (s.state && !states.includes(s.state))
|
|
207
|
+
refuse(
|
|
208
|
+
E.ERR_THEME_UNKNOWN_STATE,
|
|
209
|
+
`"${s.state}" is not a state of ${s.on}. States: ${states.join(', ')}.`,
|
|
210
|
+
{didYouMean: nearest(s.state, states)},
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
const step = v === 'more' || v === 'less';
|
|
214
|
+
if (DIALS[thing]) {
|
|
215
|
+
s.source = 'dial';
|
|
216
|
+
if (['surfaces', 'buttons', 'type'].includes(thing)) {
|
|
217
|
+
if (s.on)
|
|
218
|
+
refuse(
|
|
219
|
+
E.ERR_THEME_BAD_VALUE,
|
|
220
|
+
`${thing} moves every part it covers; drop --on. For one part, set CSS properties --on <part>.`,
|
|
221
|
+
{
|
|
222
|
+
run: [
|
|
223
|
+
`${P} set ${slug} ${thing} ${q(v || DIALS[thing].values.split('|')[0])}`,
|
|
224
|
+
],
|
|
225
|
+
},
|
|
226
|
+
);
|
|
227
|
+
if (s.mode)
|
|
228
|
+
refuse(
|
|
229
|
+
E.ERR_THEME_NO_MODE,
|
|
230
|
+
`${thing} is the same in light and dark; drop --mode.`,
|
|
231
|
+
{run: [`${P} set ${slug} ${thing} ${q(v)}`]},
|
|
232
|
+
);
|
|
233
|
+
if (unset) return s;
|
|
234
|
+
const ok = DIALS[thing].values.split('|');
|
|
235
|
+
if (!ok.includes(v))
|
|
236
|
+
refuse(
|
|
237
|
+
E.ERR_THEME_BAD_VALUE,
|
|
238
|
+
`${thing} takes ${DIALS[thing].values}, not "${v}".`,
|
|
239
|
+
{didYouMean: nearest(v, ok)},
|
|
240
|
+
);
|
|
241
|
+
return s;
|
|
242
|
+
}
|
|
243
|
+
if (thing === 'headings') {
|
|
244
|
+
if (s.on)
|
|
245
|
+
refuse(
|
|
246
|
+
E.ERR_THEME_BAD_VALUE,
|
|
247
|
+
'headings applies to every heading; drop --on. For one heading level use font-weight or letter-spacing --on heading --when level:<1-6>.',
|
|
248
|
+
{
|
|
249
|
+
run: [
|
|
250
|
+
`${P} set ${slug} font-weight 700 --on heading --when level:1`,
|
|
251
|
+
],
|
|
252
|
+
},
|
|
253
|
+
);
|
|
254
|
+
if (unset) {
|
|
255
|
+
s.axis =
|
|
256
|
+
HEADING_TRACKING[v] !== undefined || v === 'tracking'
|
|
257
|
+
? 'tracking'
|
|
258
|
+
: 'weight';
|
|
259
|
+
return s;
|
|
260
|
+
}
|
|
261
|
+
if (HEADING_WEIGHTS[v] !== undefined) s.axis = 'weight';
|
|
262
|
+
else if (HEADING_TRACKING[v] !== undefined) s.axis = 'tracking';
|
|
263
|
+
else
|
|
264
|
+
refuse(
|
|
265
|
+
E.ERR_THEME_BAD_VALUE,
|
|
266
|
+
`headings takes ${DIALS.headings.values}, not "${v}".`,
|
|
267
|
+
{
|
|
268
|
+
didYouMean: nearest(v, [
|
|
269
|
+
...Object.keys(HEADING_WEIGHTS),
|
|
270
|
+
...Object.keys(HEADING_TRACKING),
|
|
271
|
+
]),
|
|
272
|
+
},
|
|
273
|
+
);
|
|
274
|
+
return s;
|
|
275
|
+
}
|
|
276
|
+
if (unset) return s;
|
|
277
|
+
/** @param {Array<[string, number]>} L @param {string} def */
|
|
278
|
+
const ladder = (L, def) => {
|
|
279
|
+
const cur =
|
|
280
|
+
[...data.settings]
|
|
281
|
+
.reverse()
|
|
282
|
+
.find(x => x.thing === thing && (x.on ?? '') === (s.on ?? ''))
|
|
283
|
+
?.value ?? def;
|
|
284
|
+
let i = L.findIndex(([n]) => n === cur);
|
|
285
|
+
if (i < 0) {
|
|
286
|
+
const px = parseFloat(cur);
|
|
287
|
+
i = L.findIndex(([, n]) => n >= px);
|
|
288
|
+
if (i < 0) i = L.length - 1;
|
|
289
|
+
}
|
|
290
|
+
return L[
|
|
291
|
+
Math.max(0, Math.min(L.length - 1, i + (v === 'more' ? 1 : -1)))
|
|
292
|
+
][0];
|
|
293
|
+
};
|
|
294
|
+
if (s.mode && thing !== 'accent')
|
|
295
|
+
refuse(
|
|
296
|
+
E.ERR_THEME_NO_MODE,
|
|
297
|
+
`${thing} is not a color, so it is the same in light and dark; drop --mode.`,
|
|
298
|
+
{run: [`${P} set ${slug} ${thing} ${q(v)}${onFlag}`]},
|
|
299
|
+
);
|
|
300
|
+
if (thing === 'corners') {
|
|
301
|
+
if (s.on) refuseInvisibleCorners(ctx, slug, s);
|
|
302
|
+
if (step) s.value = ladder(CORNERS, 'medium');
|
|
303
|
+
else if (!CORNERS.some(([n]) => n === v) && !/^\d+(\.\d+)?px$/.test(v))
|
|
304
|
+
refuse(
|
|
305
|
+
E.ERR_THEME_BAD_VALUE,
|
|
306
|
+
`corners takes ${DIALS.corners.values}, not "${v}".`,
|
|
307
|
+
{
|
|
308
|
+
didYouMean: nearest(
|
|
309
|
+
v,
|
|
310
|
+
CORNERS.map(([n]) => n),
|
|
311
|
+
),
|
|
312
|
+
},
|
|
313
|
+
);
|
|
314
|
+
} else if (thing === 'spacing') {
|
|
315
|
+
if (step) s.value = ladder(SPACING, 'medium');
|
|
316
|
+
else if (!SPACING.some(([n]) => n === v))
|
|
317
|
+
refuse(
|
|
318
|
+
E.ERR_THEME_BAD_VALUE,
|
|
319
|
+
`spacing takes ${DIALS.spacing.values}, not "${v}".`,
|
|
320
|
+
{
|
|
321
|
+
didYouMean: nearest(
|
|
322
|
+
v,
|
|
323
|
+
SPACING.map(([n]) => n),
|
|
324
|
+
),
|
|
325
|
+
},
|
|
326
|
+
);
|
|
327
|
+
} else if (thing === 'text-size') {
|
|
328
|
+
if (s.on)
|
|
329
|
+
refuse(
|
|
330
|
+
E.ERR_THEME_BAD_VALUE,
|
|
331
|
+
'text-size applies to the whole theme; for one part use font-size.',
|
|
332
|
+
{run: [`${P} set ${slug} font-size 13px --on ${s.on}`]},
|
|
333
|
+
);
|
|
334
|
+
if (step) s.value = ladder(TEXT_SIZE, 'medium');
|
|
335
|
+
else if (!TEXT_SIZE.some(([n]) => n === v) && !Number.isFinite(Number(v)))
|
|
336
|
+
refuse(
|
|
337
|
+
E.ERR_THEME_BAD_VALUE,
|
|
338
|
+
`text-size takes ${DIALS['text-size'].values}, not "${v}".`,
|
|
339
|
+
);
|
|
340
|
+
} else if (thing === 'accent') {
|
|
341
|
+
if (step)
|
|
342
|
+
refuse(E.ERR_THEME_BAD_VALUE, 'accent takes a color, not a step.', {
|
|
343
|
+
run: [`${P} set ${slug} accent "#7c3aed"`],
|
|
344
|
+
});
|
|
345
|
+
if (!isColorValue(v))
|
|
346
|
+
refuse(E.ERR_THEME_BAD_VALUE, `"${v}" is not a CSS color.`, {
|
|
347
|
+
fix: 'give one like "#7c3aed"',
|
|
348
|
+
});
|
|
349
|
+
} else if (thing === 'font') {
|
|
350
|
+
if (s.on && !isRole)
|
|
351
|
+
refuse(
|
|
352
|
+
E.ERR_THEME_BAD_VALUE,
|
|
353
|
+
"font --on takes body, heading, or code. For one part's font use font-family.",
|
|
354
|
+
{run: [`${P} set ${slug} font-family ${q(v)} --on ${s.on}`]},
|
|
355
|
+
);
|
|
356
|
+
if (step)
|
|
357
|
+
refuse(
|
|
358
|
+
E.ERR_THEME_BAD_VALUE,
|
|
359
|
+
'font takes a preset or a family name, not a step.',
|
|
360
|
+
{fix: `the values are ${DIALS.font.values}`},
|
|
361
|
+
);
|
|
362
|
+
} else if (thing === 'base') {
|
|
363
|
+
if (s.on)
|
|
364
|
+
refuse(
|
|
365
|
+
E.ERR_THEME_BAD_VALUE,
|
|
366
|
+
'base applies to the whole theme; drop --on.',
|
|
367
|
+
{run: [`${P} set ${slug} base ${q(v)}`]},
|
|
368
|
+
);
|
|
369
|
+
if (![...LIKE, 'none'].includes(v))
|
|
370
|
+
refuse(
|
|
371
|
+
E.ERR_THEME_BAD_VALUE,
|
|
372
|
+
`base takes ${DIALS.base.values}, not "${v}".`,
|
|
373
|
+
{didYouMean: nearest(v, LIKE)},
|
|
374
|
+
);
|
|
375
|
+
} else if (thing === 'mode') {
|
|
376
|
+
if (s.on)
|
|
377
|
+
refuse(
|
|
378
|
+
E.ERR_THEME_BAD_VALUE,
|
|
379
|
+
'mode applies to the whole theme; drop --on.',
|
|
380
|
+
{run: [`${P} set ${slug} mode ${q(v)}`]},
|
|
381
|
+
);
|
|
382
|
+
if (!['both', 'light-only', 'dark-only'].includes(v))
|
|
383
|
+
refuse(
|
|
384
|
+
E.ERR_THEME_BAD_VALUE,
|
|
385
|
+
`mode takes both, light-only, or dark-only, not "${v}".`,
|
|
386
|
+
{didYouMean: nearest(v, ['both', 'light-only', 'dark-only'])},
|
|
387
|
+
);
|
|
388
|
+
}
|
|
389
|
+
return s;
|
|
390
|
+
}
|
|
391
|
+
if (thing.startsWith('--')) {
|
|
392
|
+
if (thing.startsWith('--_'))
|
|
393
|
+
refuse(
|
|
394
|
+
E.ERR_THEME_PRIVATE_TOKEN,
|
|
395
|
+
`"${thing}" is private to a component; themes cannot set it.`,
|
|
396
|
+
{run: [`${HOW} "<what you want>"`]},
|
|
397
|
+
);
|
|
398
|
+
if (!(thing in TOKENS)) {
|
|
399
|
+
refuse(E.ERR_THEME_UNKNOWN_TOKEN, `"${thing}" is not a design token.`, {
|
|
400
|
+
didYouMean: nearest(thing, Object.keys(TOKENS)),
|
|
401
|
+
run: [
|
|
402
|
+
`${HOW} ${thing.replace(/^--(color-)?/, '').split('-')[0]} --list tokens`,
|
|
403
|
+
],
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
const type = C.typeOf(thing);
|
|
407
|
+
if (s.mode && !MODAL.has(type))
|
|
408
|
+
refuse(
|
|
409
|
+
E.ERR_THEME_NO_MODE,
|
|
410
|
+
`${thing} is a ${type}, so it is the same in light and dark; drop --mode. Only colors and shadows differ by mode.`,
|
|
411
|
+
{run: [`${P} set ${slug} ${thing} ${q(v)}${onFlag}`]},
|
|
412
|
+
);
|
|
413
|
+
s.source = 'token';
|
|
414
|
+
if (unset) return s;
|
|
415
|
+
if (step)
|
|
416
|
+
refuse(
|
|
417
|
+
E.ERR_THEME_BAD_VALUE,
|
|
418
|
+
`"more"/"less" work only on dials (${Object.keys(DIALS).join(', ')}). Give ${thing} a ${type} value.`,
|
|
419
|
+
);
|
|
420
|
+
checkTypedValue(type, v, thing);
|
|
421
|
+
const parts = partsOf(ctx, s);
|
|
422
|
+
if (parts.length) {
|
|
423
|
+
const results = parts.map(
|
|
424
|
+
t =>
|
|
425
|
+
/** @type {[string, import('./_compiler.mjs').CheckFailure | null]} */ ([
|
|
426
|
+
t,
|
|
427
|
+
C.checkTokenOn(slug, t, thing, v, P),
|
|
428
|
+
]),
|
|
429
|
+
);
|
|
430
|
+
const recorded = results.filter(([, r]) => !r?.soft);
|
|
431
|
+
const hard = recorded.filter(([, r]) => r);
|
|
432
|
+
const spread = Boolean(
|
|
433
|
+
FAMILIES[s.on ?? ''] || (familyOf(s.on ?? '') && parts.length > 1),
|
|
434
|
+
);
|
|
435
|
+
// A part with no record is judged by its family: refused when no
|
|
436
|
+
// member that has a record reads the token, as the family form is.
|
|
437
|
+
const fam = s.on ? familyOf(s.on) : null;
|
|
438
|
+
if (!recorded.length && fam && !spread) {
|
|
439
|
+
const siblings = FAMILIES[fam].filter(t => C.MAP[t]);
|
|
440
|
+
const famResults = siblings.map(
|
|
441
|
+
t =>
|
|
442
|
+
/** @type {[string, import('./_compiler.mjs').CheckFailure | null]} */ ([
|
|
443
|
+
t,
|
|
444
|
+
C.checkTokenOn(slug, t, thing, v, P),
|
|
445
|
+
]),
|
|
446
|
+
);
|
|
447
|
+
if (famResults.length && famResults.every(([, r]) => r)) {
|
|
448
|
+
const r = /** @type {import('./_compiler.mjs').CheckFailure} */ (
|
|
449
|
+
famResults[0][1]
|
|
450
|
+
);
|
|
451
|
+
refuse(
|
|
452
|
+
E.ERR_THEME_NO_EFFECT,
|
|
453
|
+
`No part of the ${fam} family reads ${thing}, so ${s.on} cannot either. ${r.message}`,
|
|
454
|
+
{
|
|
455
|
+
run: r.run.map(x =>
|
|
456
|
+
x.replace(`--on ${famResults[0][0]}`, `--on ${s.on}`),
|
|
457
|
+
),
|
|
458
|
+
also: r.also,
|
|
459
|
+
},
|
|
460
|
+
);
|
|
461
|
+
}
|
|
462
|
+
if (famResults.length)
|
|
463
|
+
s.note = `${s.on} has no compiled record; checked against the ${fam} family, where ${famResults
|
|
464
|
+
.filter(([, r]) => !r)
|
|
465
|
+
.map(([t]) => t)
|
|
466
|
+
.join(', ')} read ${thing}`;
|
|
467
|
+
} else if (recorded.length && hard.length === recorded.length) {
|
|
468
|
+
const [t0, r0] =
|
|
469
|
+
/** @type {[string, import('./_compiler.mjs').CheckFailure]} */ (
|
|
470
|
+
hard[0]
|
|
471
|
+
);
|
|
472
|
+
refuse(E.ERR_THEME_NO_EFFECT, r0.message, {
|
|
473
|
+
run: r0.run.map(x =>
|
|
474
|
+
spread ? x.replace(`--on ${t0}`, `--on ${s.on}`) : x,
|
|
475
|
+
),
|
|
476
|
+
also: r0.also,
|
|
477
|
+
});
|
|
478
|
+
} else if (hard.length)
|
|
479
|
+
s.note = `no effect on ${hard.map(([t]) => t).join(', ')} (they never read ${thing})`;
|
|
480
|
+
if (!s.note && recorded.length) {
|
|
481
|
+
const fed = C.feeds(recorded[0][0], thing);
|
|
482
|
+
if (fed.length) s.note = `feeds ${C.fmtFeeds(fed)}`;
|
|
483
|
+
}
|
|
484
|
+
const soft = results.filter(([, r]) => r?.soft);
|
|
485
|
+
if (!s.note && soft.length && soft.length === results.length)
|
|
486
|
+
s.note = /** @type {import('./_compiler.mjs').CheckFailure} */ (
|
|
487
|
+
soft[0][1]
|
|
488
|
+
).message;
|
|
489
|
+
} else {
|
|
490
|
+
const r = C.checkTokenGlobal(thing, P);
|
|
491
|
+
if (r)
|
|
492
|
+
refuse(E.ERR_THEME_NO_EFFECT, r.message, {run: r.run, also: r.also});
|
|
493
|
+
}
|
|
494
|
+
return s;
|
|
495
|
+
}
|
|
496
|
+
const prop = kebab(thing);
|
|
497
|
+
if (CSS_PROPERTIES.has(prop)) {
|
|
498
|
+
if (!s.on)
|
|
499
|
+
refuse(
|
|
500
|
+
E.ERR_MISSING_ARGUMENT,
|
|
501
|
+
`${prop} is a CSS property, so it needs --on <part|family>. For the whole theme use a dial or a token.`,
|
|
502
|
+
{
|
|
503
|
+
run: [
|
|
504
|
+
`${P} set ${slug} ${prop} ${q(v || '<value>')} --on <part>`,
|
|
505
|
+
`${HOW} "${prop}"`,
|
|
506
|
+
],
|
|
507
|
+
},
|
|
508
|
+
);
|
|
509
|
+
s.source = 'property';
|
|
510
|
+
s.thing = prop;
|
|
511
|
+
if (unset) return s;
|
|
512
|
+
if (/radius$/.test(prop)) refuseInvisibleCorners(ctx, slug, s);
|
|
513
|
+
if (step)
|
|
514
|
+
refuse(
|
|
515
|
+
E.ERR_THEME_BAD_VALUE,
|
|
516
|
+
`"more"/"less" work only on dials. Give ${prop} an exact CSS value.`,
|
|
517
|
+
);
|
|
518
|
+
if (COLOR_PROPS.test(prop) && !isColorValue(v)) {
|
|
519
|
+
refuse(
|
|
520
|
+
E.ERR_THEME_BAD_VALUE,
|
|
521
|
+
`${prop} takes a color; "${v}" is not one.${/gradient/.test(v) ? ' Gradients go in background.' : ''}`,
|
|
522
|
+
{
|
|
523
|
+
run: /gradient/.test(v)
|
|
524
|
+
? [`${P} set ${slug} background ${q(v)} --on ${s.on}`]
|
|
525
|
+
: [],
|
|
526
|
+
},
|
|
527
|
+
);
|
|
528
|
+
}
|
|
529
|
+
const whenFlag = s.when ? ` --when ${s.when}` : '';
|
|
530
|
+
if (
|
|
531
|
+
s.mode &&
|
|
532
|
+
!COLOR_PROPS.test(prop) &&
|
|
533
|
+
!(prop === 'background' && isColorValue(v))
|
|
534
|
+
) {
|
|
535
|
+
const alt =
|
|
536
|
+
prop === 'border' || prop.startsWith('border-')
|
|
537
|
+
? 'border-color'
|
|
538
|
+
: prop === 'background'
|
|
539
|
+
? 'background-color'
|
|
540
|
+
: null;
|
|
541
|
+
refuse(
|
|
542
|
+
E.ERR_THEME_NO_MODE,
|
|
543
|
+
`--mode works on plain colors; ${prop} ${prop === 'box-shadow' || prop === 'border' ? 'mixes a color with sizes' : 'is not a color'}, so it cannot differ between light and dark.`,
|
|
544
|
+
{
|
|
545
|
+
run: alt
|
|
546
|
+
? [
|
|
547
|
+
`${P} set ${slug} ${prop} ${q(v.replace(/#[0-9a-f]{3,8}|rgba?\([^)]*\)/i, 'currentcolor'))} --on ${s.on}${whenFlag} # the shape, both modes`,
|
|
548
|
+
`${P} set ${slug} ${alt} "<color>" --on ${s.on}${whenFlag} --mode ${s.mode} # then the color per mode`,
|
|
549
|
+
]
|
|
550
|
+
: [
|
|
551
|
+
`${P} set ${slug} ${prop} ${q(v)} --on ${s.on}${whenFlag} # both modes`,
|
|
552
|
+
],
|
|
553
|
+
},
|
|
554
|
+
);
|
|
555
|
+
}
|
|
556
|
+
if (
|
|
557
|
+
s.mode &&
|
|
558
|
+
!partsOf(ctx, s).some(t => partDefault(ctx, t, camel(prop), s.when))
|
|
559
|
+
)
|
|
560
|
+
s.note = `the ${s.mode === 'light' ? 'dark' : 'light'} side keeps the part's current ${prop}`;
|
|
561
|
+
return s;
|
|
562
|
+
}
|
|
563
|
+
const hint =
|
|
564
|
+
/** @type {((v: string, on: string | undefined) => string[]) | undefined} */ (
|
|
565
|
+
THING_HINTS[thing.toLowerCase()]
|
|
566
|
+
);
|
|
567
|
+
return refuse(
|
|
568
|
+
E.ERR_THEME_UNKNOWN_THING,
|
|
569
|
+
`"${thing}" is not a dial, a token, or a CSS property.`,
|
|
570
|
+
{
|
|
571
|
+
run: hint
|
|
572
|
+
? hint(v, s.on)
|
|
573
|
+
: [`${HOW} "${thing}${s.on ? ` on ${s.on}` : ''}"`],
|
|
574
|
+
didYouMean: hint
|
|
575
|
+
? []
|
|
576
|
+
: nearest(prop, [...Object.keys(DIALS), ...CSS_PROPERTIES]),
|
|
577
|
+
},
|
|
578
|
+
);
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
/**
|
|
582
|
+
* Refuse rounding a part that shows no edge: no background, border, shadow
|
|
583
|
+
* or radius of its own, so a radius on it changes nothing you see.
|
|
584
|
+
* @param {import('./_settings.mjs').Ctx} ctx
|
|
585
|
+
* @param {string} slug
|
|
586
|
+
* @param {import('./_settings.mjs').Setting} s
|
|
587
|
+
*/
|
|
588
|
+
function refuseInvisibleCorners(ctx, slug, s) {
|
|
589
|
+
const parts = partsOf(ctx, s);
|
|
590
|
+
if (!parts.length || parts.some(t => ctx.C.showsCorners(t))) return;
|
|
591
|
+
const kids = (ctx.C.MAP[parts[0]]?.contains ?? [])
|
|
592
|
+
.filter(k => ctx.C.showsCorners(k) && ctx.C.MAP[k])
|
|
593
|
+
.slice(0, 3);
|
|
594
|
+
refuse(
|
|
595
|
+
E.ERR_THEME_NO_EFFECT,
|
|
596
|
+
`${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(', ')}.` : ''}`,
|
|
597
|
+
{
|
|
598
|
+
run: kids.length
|
|
599
|
+
? kids.map(
|
|
600
|
+
k => `${P} set ${slug} corners ${q(s.value || 'round')} --on ${k}`,
|
|
601
|
+
)
|
|
602
|
+
: [`${HOW} ${s.on}`],
|
|
603
|
+
},
|
|
604
|
+
);
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
/**
|
|
608
|
+
* Answer a plain-words question with exact commands: the parts it names,
|
|
609
|
+
* the aspects it asks about, and what each part really reads for them.
|
|
610
|
+
* @param {import('./_settings.mjs').Ctx} ctx
|
|
611
|
+
* @param {string} question
|
|
612
|
+
* @returns {{parts: string[], aspects: string[], results: Array<{text: string, commands: string[]}>}}
|
|
613
|
+
*/
|
|
614
|
+
export function answerHow(ctx, question) {
|
|
615
|
+
const {C} = ctx;
|
|
616
|
+
const TARGET = ctx.project.target;
|
|
617
|
+
const TOKENS = ctx.project.core.tokenDefaults;
|
|
618
|
+
const text = question.toLowerCase();
|
|
619
|
+
/** @type {string[]} */
|
|
620
|
+
const parts = [];
|
|
621
|
+
for (const [re, ts] of PART_WORDS)
|
|
622
|
+
if (re.test(text))
|
|
623
|
+
for (const t of ts) if (!parts.includes(t)) parts.push(t);
|
|
624
|
+
/** @type {Array<string | null>} */
|
|
625
|
+
let intents = INTENTS.filter(([, re]) => re.test(text)).map(([g]) => g);
|
|
626
|
+
if (
|
|
627
|
+
intents.includes('text') &&
|
|
628
|
+
intents.includes('background') &&
|
|
629
|
+
!/background|fill|gradient|glossy/.test(text)
|
|
630
|
+
)
|
|
631
|
+
intents = intents.filter(g => g !== 'background');
|
|
632
|
+
if (!intents.length && parts.length) intents = [null];
|
|
633
|
+
const design = Object.keys(DESIGN).filter(w => text.includes(w));
|
|
634
|
+
const tracking = /letter ?spacing|tracking|kerning/.test(text);
|
|
635
|
+
/** @type {Array<{text: string, commands: string[]}>} */
|
|
636
|
+
const results = [];
|
|
637
|
+
/** @param {string | null} g */
|
|
638
|
+
const V = g => {
|
|
639
|
+
const bg = design.find(d => ['gradient', 'glossy'].includes(d));
|
|
640
|
+
const sh = design.find(d =>
|
|
641
|
+
['bevel', 'raised', 'flat', 'sunken'].includes(d),
|
|
642
|
+
);
|
|
643
|
+
if (g === 'background' && bg) return DESIGN[bg];
|
|
644
|
+
if (g === 'shadow' && sh) return DESIGN[sh];
|
|
645
|
+
if (g === 'font' && tracking)
|
|
646
|
+
return /tight/.test(text) ? '-0.02em' : '0.04em';
|
|
647
|
+
if (g === 'font' && /bold|heav/.test(text)) return '700';
|
|
648
|
+
if (g === 'text' && /white/.test(text)) return '"#ffffff"';
|
|
649
|
+
return '<value>';
|
|
650
|
+
};
|
|
651
|
+
for (const raw of parts.slice(0, 3)) {
|
|
652
|
+
const [part, wp, wv] = raw.split(':');
|
|
653
|
+
const when = wp ? ` --when ${wp}:${wv}` : '';
|
|
654
|
+
const one = FAMILIES[part] ? FAMILIES[part][0] : part;
|
|
655
|
+
if (!TARGET.has(one)) continue;
|
|
656
|
+
// A part with variants: a change without --when reaches every variant.
|
|
657
|
+
const variants = Object.entries(C.variantValues(one)).filter(
|
|
658
|
+
([p, vals]) =>
|
|
659
|
+
['status', 'variant', 'tone', 'color'].includes(p) && vals.length > 1,
|
|
660
|
+
);
|
|
661
|
+
for (const g of intents.slice(0, 3)) {
|
|
662
|
+
if (g === null) {
|
|
663
|
+
results.push({
|
|
664
|
+
text: `what ${one} reads:`,
|
|
665
|
+
commands: C.explain(one, P).slice(1),
|
|
666
|
+
});
|
|
667
|
+
continue;
|
|
668
|
+
}
|
|
669
|
+
if (g === 'corners') {
|
|
670
|
+
results.push({
|
|
671
|
+
text: `corners on ${part}${when ? ` (${wp} ${wv})` : ''}`,
|
|
672
|
+
commands: [
|
|
673
|
+
`${P} set <theme> corners ${/pill|circ/.test(text) ? 'pill' : /sharp|square/.test(text) ? 'square' : 'round'} --on ${part}${when}`,
|
|
674
|
+
`${P} set <theme> border-radius 6px --on ${part}${when}`,
|
|
675
|
+
],
|
|
676
|
+
});
|
|
677
|
+
continue;
|
|
678
|
+
}
|
|
679
|
+
if (g === 'shadow') {
|
|
680
|
+
const shadows = Object.keys(ctx.project.core.tokenDefaults).filter(k =>
|
|
681
|
+
/^--shadow-(low|med|high)$/.test(k),
|
|
682
|
+
);
|
|
683
|
+
const value =
|
|
684
|
+
V('shadow') !== '<value>'
|
|
685
|
+
? V('shadow')
|
|
686
|
+
: shadows.length
|
|
687
|
+
? `"var(${/soft|subtle|light/.test(text) ? shadows[0] : /strong|deep|heavy/.test(text) ? shadows[shadows.length - 1] : shadows[Math.min(1, shadows.length - 1)]})"`
|
|
688
|
+
: '"0 2px 6px rgb(0 0 0 / 0.2)"';
|
|
689
|
+
results.push({
|
|
690
|
+
text: `shadow on ${part}${when ? ` (${wp} ${wv})` : ''}: box-shadow${shadows.length ? `; the theme's shadow tokens are ${shadows.join(', ')}` : ''}`,
|
|
691
|
+
commands: [
|
|
692
|
+
`${P} set <theme> box-shadow ${value} --on ${part}${when}`,
|
|
693
|
+
...(shadows.length
|
|
694
|
+
? [
|
|
695
|
+
`${P} set <theme> ${shadows[0]} "0 1px 3px rgb(0 0 0 / 0.12)" # change the shared shadow everywhere`,
|
|
696
|
+
]
|
|
697
|
+
: []),
|
|
698
|
+
],
|
|
699
|
+
});
|
|
700
|
+
continue;
|
|
701
|
+
}
|
|
702
|
+
if (g === 'spacing' && !tracking) {
|
|
703
|
+
results.push({
|
|
704
|
+
text: `room inside ${part}`,
|
|
705
|
+
commands: [
|
|
706
|
+
`${P} set <theme> spacing ${/dense|compact|tight|cramped/.test(text) ? 'compact' : 'roomy'} --on ${part}`,
|
|
707
|
+
`${P} set <theme> padding 12px --on ${part}${when}`,
|
|
708
|
+
],
|
|
709
|
+
});
|
|
710
|
+
continue;
|
|
711
|
+
}
|
|
712
|
+
const group = g === 'spacing' ? 'font' : g;
|
|
713
|
+
const reads = C.partReads(one, group);
|
|
714
|
+
const filtered = wv
|
|
715
|
+
? reads.filter(
|
|
716
|
+
r =>
|
|
717
|
+
r.when.some(w => w.includes(`${wp}=${wv}`)) ||
|
|
718
|
+
r.when.includes(''),
|
|
719
|
+
)
|
|
720
|
+
: reads;
|
|
721
|
+
const list = (filtered.length ? filtered : reads).slice(0, 4);
|
|
722
|
+
const direct =
|
|
723
|
+
group === 'font' && tracking
|
|
724
|
+
? 'letter-spacing'
|
|
725
|
+
: group === 'font' && /bold|weight|heav/.test(text)
|
|
726
|
+
? 'font-weight'
|
|
727
|
+
: group === 'font'
|
|
728
|
+
? 'font-family'
|
|
729
|
+
: DIRECT[group];
|
|
730
|
+
const tokenRoute =
|
|
731
|
+
(group === 'text' || group === 'background' || group === 'border') &&
|
|
732
|
+
!/gradient|inset/.test(V(group));
|
|
733
|
+
results.push({
|
|
734
|
+
text: `${part} ${group}${when ? ` (${wp} ${wv})` : ''}: ${list.length ? `comes from ${list.map(r => r.token + C.fmtWhen(r.when) + C.statusNote(one, r.token)).join(', ')}` : 'no token; set the property directly'}`,
|
|
735
|
+
commands: [
|
|
736
|
+
`${P} set <theme> ${direct} ${V(group)} --on ${part}${when} # direct: always works`,
|
|
737
|
+
...(tokenRoute
|
|
738
|
+
? list
|
|
739
|
+
.slice(0, 2)
|
|
740
|
+
.map(
|
|
741
|
+
r =>
|
|
742
|
+
`${P} set <theme> ${r.token} ${V(group)} --on ${part} # via the token${C.fmtWhen(r.when)}`,
|
|
743
|
+
)
|
|
744
|
+
: []),
|
|
745
|
+
],
|
|
746
|
+
});
|
|
747
|
+
if (
|
|
748
|
+
!when &&
|
|
749
|
+
variants.length &&
|
|
750
|
+
['text', 'background', 'border'].includes(group)
|
|
751
|
+
) {
|
|
752
|
+
const [vp, vals] = variants[0];
|
|
753
|
+
results.push({
|
|
754
|
+
text: `${part} has ${vp} ${vals.join('|')}: without --when the change reaches every ${vp}. To change one, add --when ${vp}:<value>.`,
|
|
755
|
+
commands: [
|
|
756
|
+
`${P} set <theme> ${direct} ${V(group)} --on ${part} --when ${vp}:${vals[0]}`,
|
|
757
|
+
],
|
|
758
|
+
});
|
|
759
|
+
}
|
|
760
|
+
const kids = (C.MAP[one]?.contains ?? [])
|
|
761
|
+
.filter(
|
|
762
|
+
k =>
|
|
763
|
+
C.partReads(k, group).length && !(FAMILIES[part] ?? []).includes(k),
|
|
764
|
+
)
|
|
765
|
+
.slice(0, 3);
|
|
766
|
+
if (kids.length && group === 'text') {
|
|
767
|
+
results.push({
|
|
768
|
+
text: `parts inside ${part} with their own text color: ${kids.join(', ')}. A text token set --on ${part} reaches them; a color property does not.`,
|
|
769
|
+
commands: kids.slice(0, 1).map(k => `${HOW} ${k}`),
|
|
770
|
+
});
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
if (!parts.length) {
|
|
775
|
+
if (tracking)
|
|
776
|
+
results.push({
|
|
777
|
+
text: 'letter spacing is a CSS property on a part; for headings there is a dial',
|
|
778
|
+
commands: [
|
|
779
|
+
`${P} set <theme> letter-spacing 0.02em --on <part>`,
|
|
780
|
+
`${P} set <theme> headings tight`,
|
|
781
|
+
],
|
|
782
|
+
});
|
|
783
|
+
for (const g of /** @type {string[]} */ (intents.filter(Boolean)).slice(
|
|
784
|
+
0,
|
|
785
|
+
2,
|
|
786
|
+
)) {
|
|
787
|
+
const dial = /** @type {Record<string, string>} */ ({
|
|
788
|
+
corners: 'corners',
|
|
789
|
+
spacing: 'spacing',
|
|
790
|
+
font: 'font',
|
|
791
|
+
size: 'text-size',
|
|
792
|
+
})[g];
|
|
793
|
+
if (dial && !(tracking && (g === 'spacing' || g === 'font')))
|
|
794
|
+
results.push({
|
|
795
|
+
text: DIALS[dial].help,
|
|
796
|
+
commands: DIALS[dial].examples.map(e => `${P} ${e}`),
|
|
797
|
+
});
|
|
798
|
+
if (g === 'background' || g === 'text')
|
|
799
|
+
results.push({
|
|
800
|
+
text: DIALS.accent.help,
|
|
801
|
+
commands: DIALS.accent.examples.map(e => `${P} ${e}`),
|
|
802
|
+
});
|
|
803
|
+
results.push(...wholeThemeTokens(ctx, g));
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
if (!results.length) {
|
|
807
|
+
for (const d of Object.values(DIALS)) {
|
|
808
|
+
if (d.words.split(' ').some(w => w.length > 3 && text.includes(w)))
|
|
809
|
+
results.push({
|
|
810
|
+
text: d.help,
|
|
811
|
+
commands: d.examples.map(e => `${P} ${e}`),
|
|
812
|
+
});
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
void TOKENS;
|
|
816
|
+
return {
|
|
817
|
+
parts,
|
|
818
|
+
aspects: /** @type {string[]} */ (intents.filter(Boolean)),
|
|
819
|
+
results: results.slice(0, 10),
|
|
820
|
+
};
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
/**
|
|
824
|
+
* The tokens most parts read for one aspect, for a whole-theme change.
|
|
825
|
+
* @param {import('./_settings.mjs').Ctx} ctx
|
|
826
|
+
* @param {string} aspect
|
|
827
|
+
* @returns {Array<{text: string, commands: string[]}>}
|
|
828
|
+
*/
|
|
829
|
+
export function wholeThemeTokens(ctx, aspect) {
|
|
830
|
+
const {C} = ctx;
|
|
831
|
+
const toks = Object.keys(ctx.project.core.tokenDefaults)
|
|
832
|
+
.filter(k => C.groupOfToken(k) === aspect && C.anyReader(k).length)
|
|
833
|
+
.sort((a, b) => C.anyReader(b).length - C.anyReader(a).length)
|
|
834
|
+
.slice(0, 6);
|
|
835
|
+
if (!toks.length) return [];
|
|
836
|
+
return [
|
|
837
|
+
{
|
|
838
|
+
text: `whole-theme tokens for ${aspect}, most used first: ${toks.map(k => `${k} (${C.anyReader(k).length} parts)`).join(', ')}`,
|
|
839
|
+
commands: [`${P} set <theme> ${toks[0]} <value>`],
|
|
840
|
+
},
|
|
841
|
+
];
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
/** The aspects `how` answers at the whole-theme level. */
|
|
845
|
+
export const ASPECTS = [...Object.keys(GROUPS), 'colors'];
|