@astryxdesign/cli 0.7.14 → 0.7.15-canary.g06b7e61
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/CHANGELOG.md +3 -3
- package/README.md +63 -63
- package/api/build/_adapter.d.mts +4 -0
- package/api/build/_adapter.mjs +28 -2
- package/api/build/blocks/blocks.d.mts +10 -1
- package/api/build/blocks/blocks.mjs +84 -7
- package/api/build/build.mjs +6 -1
- package/api/build/tree.d.mts +4 -0
- package/api/build/tree.mjs +9 -2
- package/api/doctor/_adapter.d.mts +3 -1
- package/api/doctor/_adapter.mjs +14 -1
- package/api/doctor/_authoring-audit.d.mts +42 -0
- package/api/doctor/_authoring-audit.mjs +106 -0
- package/api/doctor/doctor.d.mts +7 -0
- package/api/doctor/doctor.mjs +24 -39
- package/api/doctor/theme-checks.mjs +56 -21
- package/api/integration/add-helpers.mjs +5 -0
- package/api/integration/add-theme.mjs +15 -110
- package/api/integration/validate-integration.mjs +17 -3
- package/api/integration/validateIntegration.doc.mjs +1 -1
- package/api/search/_adapter.mjs +124 -3
- package/api/search/_candidate-score.mjs +63 -9
- package/api/search/_entries.d.mts +10 -0
- package/api/search/_entries.mjs +68 -1
- package/api/search/_gather-templates.d.mts +11 -0
- package/api/search/_gather-templates.mjs +22 -2
- package/api/search/_words.mjs +26 -6
- package/api/swizzle/copy/copy.mjs +1 -1
- package/api/theme/_adapter.d.mts +37 -5
- package/api/theme/_adapter.mjs +381 -57
- package/api/theme/_fork.d.mts +90 -0
- package/api/theme/_fork.mjs +246 -0
- package/api/theme/build/build.d.mts +40 -2
- package/api/theme/build/build.mjs +477 -66
- package/api/theme/eject/eject.mjs +36 -15
- package/api/theme/list/list.mjs +3 -6
- package/api/theme/palette/generate/generator.d.mts +13 -0
- package/api/theme/palette/generate/generator.mjs +32 -2
- package/api/theme/targets/targets.d.mts +8 -0
- package/api/theme/targets/targets.mjs +24 -4
- package/api/theme/template/template.mjs +48 -2
- package/api/theme/theme.type.d.mts +8 -0
- package/api/theme/theme.type.mjs +5 -1
- package/api/theme/themeBuild.doc.mjs +7 -4
- package/api/theme/themeEject.doc.mjs +3 -3
- package/api/theme/themeRemove.doc.mjs +5 -2
- package/api/theme/themeTargets.doc.mjs +1 -1
- package/api/theme/themeTemplate.doc.mjs +2 -2
- package/api/theme/themeUse.doc.mjs +8 -2
- package/api/theme-edit/_adapter.d.mts +46 -3
- package/api/theme-edit/_adapter.mjs +496 -112
- package/api/theme-edit/_catalog.d.mts +1 -6
- package/api/theme-edit/_catalog.mjs +5 -268
- package/api/theme-edit/_check.d.mts +9 -4
- package/api/theme-edit/_check.mjs +1232 -229
- package/api/theme-edit/_color.d.mts +19 -0
- package/api/theme-edit/_color.mjs +280 -34
- package/api/theme-edit/_compiler.d.mts +3 -1
- package/api/theme-edit/_compiler.mjs +52 -13
- package/api/theme-edit/_context.d.mts +4 -1
- package/api/theme-edit/_context.mjs +126 -13
- package/api/theme-edit/_css.d.mts +84 -0
- package/api/theme-edit/_css.mjs +700 -0
- package/api/theme-edit/_edit.d.mts +9 -3
- package/api/theme-edit/_edit.mjs +806 -103
- package/api/theme-edit/_how-commands.d.mts +38 -7
- package/api/theme-edit/_how-commands.mjs +64 -45
- package/api/theme-edit/_how-question.d.mts +33 -0
- package/api/theme-edit/_how-question.mjs +2553 -381
- package/api/theme-edit/_how.mjs +402 -31
- package/api/theme-edit/_overview.mjs +2 -7
- package/api/theme-edit/_palette.d.mts +60 -13
- package/api/theme-edit/_palette.mjs +826 -295
- package/api/theme-edit/_parts.d.mts +42 -10
- package/api/theme-edit/_parts.mjs +280 -69
- package/api/theme-edit/_png.d.mts +4 -4
- package/api/theme-edit/_png.mjs +4 -2
- package/api/theme-edit/_preview-app.d.mts +14 -0
- package/api/theme-edit/_preview-app.mjs +1675 -235
- package/api/theme-edit/_preview.d.mts +7 -16
- package/api/theme-edit/_preview.mjs +79 -86
- package/api/theme-edit/_project.d.mts +32 -2
- package/api/theme-edit/_project.mjs +80 -19
- package/api/theme-edit/_settings.d.mts +199 -52
- package/api/theme-edit/_settings.mjs +1422 -217
- package/api/theme-edit/_tables.d.mts +19 -6
- package/api/theme-edit/_tables.mjs +150 -92
- package/api/theme-edit/theme-edit.type.d.mts +20 -1
- package/api/theme-edit/theme-edit.type.mjs +6 -3
- package/api/theme-edit/themeEditHow.doc.mjs +6 -0
- package/api/theme-edit/themeEditNew.doc.mjs +1 -1
- package/api/theme-edit/themeEditPreviewAdd.doc.mjs +1 -1
- package/api/theme-edit/themeEditPreviewApp.doc.mjs +1 -1
- package/api/theme-edit/themeEditPreviewList.doc.mjs +2 -2
- package/api/theme-edit/themeEditPreviewRemove.doc.mjs +5 -1
- package/api/theme-edit/themeEditSet.doc.mjs +1 -1
- package/api/theme-edit/themeEditUndo.doc.mjs +1 -1
- package/api/upgrade/_adapter.d.mts +1 -0
- package/assets/codemods/run-codemod.mjs +61 -0
- package/assets/codemods/runner.mjs +5 -4
- package/assets/codemods/transforms/v0.0.14/rename-status-variants.mjs +3 -0
- package/assets/codemods/transforms/v0.1.8/rename-avatar-size-scale.mjs +5 -1
- package/assets/codemods/transforms/v0.6.4/migrate-native-picker-to-presentation.mjs +3 -0
- package/assets/codemods/transforms/v0.7.0/migrate-deprecated-theme-surface.mjs +4 -0
- package/assets/codemods/transforms/v0.7.0/rename-empty-search-results-text.mjs +17 -12
- package/assets/codemods/transforms/v0.7.2/migrate-list-edge-compensation-to-edge.mjs +3 -0
- package/assets/codemods/transforms/v0.7.5/migrate-codeblock-tokenizer-to-language.mjs +3 -0
- package/assets/codemods/transforms/v0.7.8/promote-tokenizer-presentation.mjs +3 -0
- package/assets/docs/tree/calendars.doc.mjs +1 -3
- package/assets/docs/tree/checks.doc.mjs +22 -1
- package/assets/docs/tree/publishing.doc.mjs +1 -0
- package/assets/docs/tree/tokens-and-setup.doc.mjs +39 -3
- package/assets/docs.generated.json +2 -1
- package/assets/preview-app/next.config.mjs +7 -1
- package/assets/self-audit.generated.json +1 -0
- package/assets/templates/blocks/components/Theme/useThemeNameHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Theme/useThemeNameHookUsage.tsx +31 -0
- package/assets/templates/components.generated.json +1 -1
- package/authoring/integration/integration.doc.mjs +8 -0
- package/authoring/integration/schema.d.mts +8 -0
- package/authoring/integration/schema.mjs +1 -0
- package/authoring/integration/type.ts +9 -0
- package/clients/cli/bin/astryx.mjs +19 -15
- package/clients/cli/build-id.generated.json +1 -0
- package/clients/cli/commands/ensure-core-built.mjs +12 -5
- package/clients/cli/commands/experimental/index.mjs +10 -10
- package/clients/cli/commands/experimental/theme.mjs +200 -81
- package/clients/cli/commands/experimental-theme-compile.doc.mjs +3 -3
- package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +3 -3
- package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +1 -2
- package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-eject.doc.mjs +3 -3
- package/clients/cli/commands/experimental-theme-preview-add.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-preview-list.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-preview-remove.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-remove.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-template.doc.mjs +4 -3
- package/clients/cli/commands/integration.mjs +8 -0
- package/clients/cli/commands/manifest.mjs +5 -2
- package/clients/cli/commands/theme-build.doc.mjs +2 -2
- package/clients/cli/commands/theme-list.doc.mjs +1 -1
- package/clients/cli/commands/theme-template.doc.mjs +1 -1
- package/clients/cli/commands/theme.mjs +439 -66
- package/clients/cli/index.mjs +27 -6
- package/clients/cli/lib/cli-error.mjs +118 -3
- package/clients/cli/lib/manifest.mjs +37 -0
- package/clients/cli/lib/resolve-theme.mjs +2 -1
- package/clients/cli/manifest.generated.json +1 -0
- package/foundation/config/project.mjs +34 -8
- package/foundation/config/theme-state.d.mts +16 -0
- package/foundation/config/theme-state.mjs +84 -13
- package/foundation/discovery/module-exports.mjs +16 -2
- package/foundation/discovery/stored-self-audit.d.mts +31 -0
- package/foundation/discovery/stored-self-audit.mjs +119 -0
- package/foundation/discovery/template-adapter.d.mts +48 -2
- package/foundation/discovery/template-adapter.mjs +51 -19
- package/foundation/discovery/template-needs.d.mts +19 -0
- package/foundation/discovery/template-needs.mjs +50 -16
- package/foundation/discovery/template-source-tree.d.mts +7 -0
- package/foundation/discovery/template-source-tree.mjs +15 -0
- package/foundation/discovery/theme-discovery.d.mts +2 -1
- package/foundation/discovery/theme-discovery.mjs +16 -10
- package/foundation/discovery/theme-imports.d.mts +16 -0
- package/foundation/discovery/theme-imports.mjs +30 -2
- package/foundation/discovery/theme-module-extensions.d.mts +18 -0
- package/foundation/discovery/theme-module-extensions.mjs +30 -0
- package/foundation/doc-compiler/import.mjs +22 -15
- package/foundation/doc-compiler/stored-docs.d.mts +18 -12
- package/foundation/doc-compiler/stored-docs.mjs +52 -19
- package/foundation/env/private-dir.d.mts +17 -0
- package/foundation/env/private-dir.mjs +42 -0
- package/foundation/fs/gather-cache.d.mts +108 -0
- package/foundation/fs/gather-cache.mjs +783 -0
- package/foundation/fs/jiti-cache.d.mts +21 -0
- package/foundation/fs/jiti-cache.mjs +66 -0
- package/foundation/fs/module-loader.mjs +14 -3
- package/foundation/fs/read-record.d.mts +31 -1
- package/foundation/fs/read-record.mjs +100 -7
- package/foundation/integrations/autolink.d.mts +1 -24
- package/foundation/integrations/autolink.mjs +7 -60
- package/foundation/integrations/declared-dependencies.d.mts +27 -0
- package/foundation/integrations/declared-dependencies.mjs +73 -0
- package/foundation/integrations/integrations.d.mts +8 -0
- package/foundation/integrations/integrations.mjs +4 -0
- package/foundation/integrations/may-have-integrations.d.mts +8 -0
- package/foundation/integrations/may-have-integrations.mjs +47 -0
- package/foundation/integrations/validate-contributions.d.mts +62 -1
- package/foundation/integrations/validate-contributions.mjs +476 -40
- package/foundation/release/cache.d.mts +32 -4
- package/foundation/release/cache.mjs +105 -16
- package/foundation/release/folder-lock.d.mts +28 -0
- package/foundation/release/folder-lock.mjs +205 -0
- package/foundation/release/lock-lease.d.mts +2 -1
- package/foundation/release/lock-lease.mjs +7 -2
- package/foundation/response/error-codes.doc.mjs +1 -1
- package/foundation/response/response-types.doc.mjs +5 -5
- package/package.json +8 -6
- package/api/theme-edit/_css-properties.d.mts +0 -10
- package/api/theme-edit/_css-properties.mjs +0 -556
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* @position api/theme-edit — imported only by _how.mjs
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
import {hex, parseColor} from './_color.mjs';
|
|
12
|
+
import {hex, parseColor, ratio} from './_color.mjs';
|
|
13
13
|
import {
|
|
14
14
|
DESIGN,
|
|
15
15
|
DIALS,
|
|
@@ -20,9 +20,14 @@ import {
|
|
|
20
20
|
HOW,
|
|
21
21
|
OPEN_FONTS,
|
|
22
22
|
COMMON_STATES,
|
|
23
|
+
COLOR_PROPS,
|
|
24
|
+
GROUPS,
|
|
25
|
+
isSystemFamily,
|
|
23
26
|
} from './_tables.mjs';
|
|
24
27
|
import {PALETTE_DIALS, isGraySeed, seedOf} from './_palette.mjs';
|
|
25
|
-
import {
|
|
28
|
+
import {focusStateOf} from './_settings.mjs';
|
|
29
|
+
import {levenshteinDistance} from '../../foundation/text/levenshtein.mjs';
|
|
30
|
+
import {cssProperties, keywordsOf, matchValue} from './_css.mjs';
|
|
26
31
|
|
|
27
32
|
/** @typedef {import('./_how-commands.mjs').Step} Step */
|
|
28
33
|
|
|
@@ -40,19 +45,33 @@ import {COLOR_PROPS} from './_tables.mjs';
|
|
|
40
45
|
const TRANSLATE = /** @type {Array<[RegExp, string]>} */ (
|
|
41
46
|
[
|
|
42
47
|
[
|
|
43
|
-
'botones?|boutons?|knöpfe|knopf|кнопк[аиу]|botões|botão|botao|pulsanti|bottoni',
|
|
48
|
+
'botones?|boutons?|knöpfe|knopf|кнопк[аиу]|botões|botão|botao|pulsanti|bottoni|الأزرار|أزرار|زر|बटन',
|
|
44
49
|
'按钮|ボタン|버튼',
|
|
45
50
|
'buttons',
|
|
46
51
|
],
|
|
47
|
-
['tarjetas?|cartes|karten?|карточк[аи]', '卡片|カード', 'cards'],
|
|
48
52
|
[
|
|
49
|
-
'
|
|
53
|
+
'tarjetas?|cartes|karten?|карточк[аи]|schede|carte',
|
|
54
|
+
'卡片|カード|카드',
|
|
55
|
+
'cards',
|
|
56
|
+
],
|
|
57
|
+
[
|
|
58
|
+
'redondead[oa]s?|redond[oa]s|arrondi[es]*|abgerundet\\p{L}*|скругл\\p{L}*|arredondad\\p{L}*|arrotondat\\p{L}*|مستدير\\p{L}*|गोल',
|
|
50
59
|
'圆|丸く|丸い|둥글게|둥근',
|
|
51
60
|
'rounded',
|
|
52
61
|
],
|
|
53
62
|
['esquinas?|coins|ecken|углы', '角', 'corners'],
|
|
54
|
-
[
|
|
55
|
-
|
|
63
|
+
[
|
|
64
|
+
'sombras?|ombres?|ombra|ombre|schatten|тен[ьи]|ظل',
|
|
65
|
+
'阴影|影|그림자',
|
|
66
|
+
'shadow',
|
|
67
|
+
],
|
|
68
|
+
[
|
|
69
|
+
'entfernen|quitar|enlever|supprimer|убрать|togliere|rimuovere|remover|हटाओ',
|
|
70
|
+
'去掉|删除|消して|없애',
|
|
71
|
+
'remove',
|
|
72
|
+
],
|
|
73
|
+
['цвет\\p{L}*|colore|farbe', '颜色|色', 'color'],
|
|
74
|
+
['акцент\\p{L}*', '强调', 'accent'],
|
|
56
75
|
['más|mais|mehr|più|более', '更', 'more'],
|
|
57
76
|
// "sans" is a typeface word before serif or font.
|
|
58
77
|
[
|
|
@@ -74,12 +93,21 @@ const TRANSLATE = /** @type {Array<[RegExp, string]>} */ (
|
|
|
74
93
|
])
|
|
75
94
|
);
|
|
76
95
|
|
|
77
|
-
/**
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
96
|
+
/**
|
|
97
|
+
* Words a near miss is corrected to (one or two letters off), besides the
|
|
98
|
+
* one-word target names Core's catalog gives (partLexicon): design words,
|
|
99
|
+
* and the words the part overrides read.
|
|
100
|
+
*/
|
|
101
|
+
const DESIGN_WORDS = [
|
|
102
|
+
'leading',
|
|
103
|
+
'header',
|
|
104
|
+
'headers',
|
|
105
|
+
'input',
|
|
106
|
+
'inputs',
|
|
107
|
+
'checkbox',
|
|
108
|
+
'toggle',
|
|
109
|
+
'sidebar',
|
|
110
|
+
'progress',
|
|
83
111
|
'shadow',
|
|
84
112
|
'shadows',
|
|
85
113
|
'border',
|
|
@@ -91,24 +119,6 @@ const VOCAB = [
|
|
|
91
119
|
'radius',
|
|
92
120
|
'padding',
|
|
93
121
|
'spacing',
|
|
94
|
-
'header',
|
|
95
|
-
'banner',
|
|
96
|
-
'input',
|
|
97
|
-
'inputs',
|
|
98
|
-
'dialog',
|
|
99
|
-
'dialogs',
|
|
100
|
-
'tooltip',
|
|
101
|
-
'heading',
|
|
102
|
-
'headings',
|
|
103
|
-
'checkbox',
|
|
104
|
-
'switch',
|
|
105
|
-
'toggle',
|
|
106
|
-
'table',
|
|
107
|
-
'badge',
|
|
108
|
-
'badges',
|
|
109
|
-
'avatar',
|
|
110
|
-
'avatars',
|
|
111
|
-
'sidebar',
|
|
112
122
|
'gradient',
|
|
113
123
|
'color',
|
|
114
124
|
'colour',
|
|
@@ -122,11 +132,6 @@ const VOCAB = [
|
|
|
122
132
|
'compact',
|
|
123
133
|
'accent',
|
|
124
134
|
'remove',
|
|
125
|
-
'shadows',
|
|
126
|
-
'rounded',
|
|
127
|
-
'headers',
|
|
128
|
-
'tables',
|
|
129
|
-
'progress',
|
|
130
135
|
'outline',
|
|
131
136
|
];
|
|
132
137
|
|
|
@@ -144,10 +149,19 @@ const SHORT = /** @type {Record<string, string>} */ ({
|
|
|
144
149
|
txt: 'text',
|
|
145
150
|
clr: 'color',
|
|
146
151
|
shdw: 'shadow',
|
|
152
|
+
fnot: 'font',
|
|
153
|
+
fnt: 'font',
|
|
147
154
|
});
|
|
148
155
|
|
|
149
156
|
/** Plain words that are never corrected, though one letter off a VOCAB word. */
|
|
150
157
|
const KEEP = new Set([
|
|
158
|
+
'lines',
|
|
159
|
+
'block',
|
|
160
|
+
'blocks',
|
|
161
|
+
'blank',
|
|
162
|
+
'blur',
|
|
163
|
+
'shadowy',
|
|
164
|
+
'times',
|
|
151
165
|
'remote',
|
|
152
166
|
'reverse',
|
|
153
167
|
'access',
|
|
@@ -159,23 +173,17 @@ const KEEP = new Set([
|
|
|
159
173
|
'agent',
|
|
160
174
|
'tighter',
|
|
161
175
|
'tight',
|
|
162
|
-
'lighter',
|
|
163
176
|
'brighter',
|
|
164
177
|
'wider',
|
|
165
178
|
'danger',
|
|
166
179
|
'orange',
|
|
167
180
|
'ranger',
|
|
168
181
|
'rows',
|
|
169
|
-
'darker',
|
|
170
182
|
'thinner',
|
|
171
183
|
'rounds',
|
|
172
184
|
'should',
|
|
173
|
-
'button',
|
|
174
|
-
'buttons',
|
|
175
|
-
'color',
|
|
176
185
|
'colors',
|
|
177
186
|
'italics',
|
|
178
|
-
'border',
|
|
179
187
|
'fonts',
|
|
180
188
|
'title',
|
|
181
189
|
'titles',
|
|
@@ -185,7 +193,6 @@ const KEEP = new Set([
|
|
|
185
193
|
'muted',
|
|
186
194
|
'filled',
|
|
187
195
|
'spaced',
|
|
188
|
-
'wider',
|
|
189
196
|
'bolder',
|
|
190
197
|
'cord',
|
|
191
198
|
'board',
|
|
@@ -196,9 +203,7 @@ const KEEP = new Set([
|
|
|
196
203
|
'later',
|
|
197
204
|
'darken',
|
|
198
205
|
'ladder',
|
|
199
|
-
'header',
|
|
200
206
|
'leader',
|
|
201
|
-
'bigger',
|
|
202
207
|
'cars',
|
|
203
208
|
'care',
|
|
204
209
|
'hard',
|
|
@@ -206,58 +211,80 @@ const KEEP = new Set([
|
|
|
206
211
|
'bottom',
|
|
207
212
|
'botton',
|
|
208
213
|
'inside',
|
|
209
|
-
'tables',
|
|
210
|
-
'colors',
|
|
211
214
|
'colours',
|
|
212
215
|
'sitch',
|
|
213
216
|
'witch',
|
|
214
|
-
'border',
|
|
215
217
|
'sharper',
|
|
216
|
-
'shadows',
|
|
217
|
-
'smaller',
|
|
218
218
|
'taller',
|
|
219
219
|
]);
|
|
220
220
|
|
|
221
221
|
/**
|
|
222
|
-
*
|
|
223
|
-
* @param {string}
|
|
222
|
+
* A word with a near miss corrected: two swapped letters count as one edit.
|
|
223
|
+
* @param {string} w
|
|
224
|
+
* @param {string[]} vocab
|
|
224
225
|
*/
|
|
225
|
-
function
|
|
226
|
-
if (Math.abs(a.length - b.length) > 2) return 3;
|
|
227
|
-
/** @type {number[][]} */
|
|
228
|
-
const d = Array.from({length: a.length + 1}, (_, i) =>
|
|
229
|
-
Array.from({length: b.length + 1}, (_, j) =>
|
|
230
|
-
i === 0 ? j : j === 0 ? i : 0,
|
|
231
|
-
),
|
|
232
|
-
);
|
|
233
|
-
for (let i = 1; i <= a.length; i++)
|
|
234
|
-
for (let j = 1; j <= b.length; j++) {
|
|
235
|
-
d[i][j] = Math.min(
|
|
236
|
-
d[i - 1][j] + 1,
|
|
237
|
-
d[i][j - 1] + 1,
|
|
238
|
-
d[i - 1][j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1),
|
|
239
|
-
);
|
|
240
|
-
if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1])
|
|
241
|
-
d[i][j] = Math.min(d[i][j], d[i - 2][j - 2] + 1);
|
|
242
|
-
}
|
|
243
|
-
return Math.min(3, d[a.length][b.length]);
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
/** @param {string} w */
|
|
247
|
-
function corrected(w) {
|
|
226
|
+
function corrected(w, vocab) {
|
|
248
227
|
if (SHORT[w]) return SHORT[w];
|
|
249
|
-
|
|
228
|
+
// A state word ("selected") is read as a state, never corrected.
|
|
229
|
+
if (
|
|
230
|
+
w.length < 5 ||
|
|
231
|
+
KEEP.has(w) ||
|
|
232
|
+
vocab.includes(w) ||
|
|
233
|
+
!/^[a-z]+$/.test(w) ||
|
|
234
|
+
STATE_WORDS.some(([re]) => re.test(w))
|
|
235
|
+
)
|
|
250
236
|
return w;
|
|
251
237
|
const limit = w.length >= 8 ? 2 : 1;
|
|
252
238
|
let best = w;
|
|
253
239
|
let bestD = limit + 1;
|
|
254
|
-
for (const v of
|
|
255
|
-
const d =
|
|
240
|
+
for (const v of vocab) {
|
|
241
|
+
const d = levenshteinDistance(w, v, 2, {swaps: true});
|
|
256
242
|
if (d < bestD) [best, bestD] = [v, d];
|
|
257
243
|
}
|
|
258
244
|
return bestD <= limit ? best : w;
|
|
259
245
|
}
|
|
260
246
|
|
|
247
|
+
/** A stop on a gray family: "gray-50", "slate 100", "zinc-900". */
|
|
248
|
+
const GRAY_STOP =
|
|
249
|
+
/\b(gr[ae]y|slate|zinc|neutral|stone)[\s-]?(50|[1-9]00|950)\b/g;
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* The color at a stop of a gray family, in OKLCH: the lightness the common
|
|
253
|
+
* 50-950 gray scales give each stop, with the family's slight hue.
|
|
254
|
+
* @param {string} family @param {number} stop
|
|
255
|
+
*/
|
|
256
|
+
function grayStop(family, stop) {
|
|
257
|
+
const L = /** @type {Record<number, number>} */ ({
|
|
258
|
+
50: 0.985,
|
|
259
|
+
100: 0.967,
|
|
260
|
+
200: 0.928,
|
|
261
|
+
300: 0.872,
|
|
262
|
+
400: 0.707,
|
|
263
|
+
500: 0.551,
|
|
264
|
+
600: 0.446,
|
|
265
|
+
700: 0.373,
|
|
266
|
+
800: 0.278,
|
|
267
|
+
900: 0.21,
|
|
268
|
+
950: 0.13,
|
|
269
|
+
})[stop];
|
|
270
|
+
// Grays are near neutral at the light and dark ends, tinted most in
|
|
271
|
+
// the middle.
|
|
272
|
+
const [base, hue] = /** @type {Record<string, [number, number]>} */ ({
|
|
273
|
+
gray: [0.03, 264],
|
|
274
|
+
grey: [0.03, 264],
|
|
275
|
+
slate: [0.05, 257],
|
|
276
|
+
zinc: [0.015, 286],
|
|
277
|
+
neutral: [0, 0],
|
|
278
|
+
stone: [0.012, 56],
|
|
279
|
+
})[family];
|
|
280
|
+
const chroma = Number(
|
|
281
|
+
(base * Math.min(1, 2 * Math.min(L, 1 - L))).toFixed(4),
|
|
282
|
+
);
|
|
283
|
+
return hex(
|
|
284
|
+
/** @type {number[]} */ (parseColor(`oklch(${L} ${chroma} ${hue})`)),
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
|
|
261
288
|
/** Hues people name, as fills a part can take. */
|
|
262
289
|
const HUES = /** @type {Record<string, string>} */ ({
|
|
263
290
|
red: '#dc2626',
|
|
@@ -274,6 +301,7 @@ const HUES = /** @type {Record<string, string>} */ ({
|
|
|
274
301
|
navy: '#1e3a8a',
|
|
275
302
|
indigo: '#4f46e5',
|
|
276
303
|
purple: '#7c3aed',
|
|
304
|
+
charcoal: '#333333',
|
|
277
305
|
violet: '#7c3aed',
|
|
278
306
|
pink: '#db2777',
|
|
279
307
|
magenta: '#c026d3',
|
|
@@ -327,18 +355,29 @@ const THEME_COLOR_WORDS = /** @type {Array<[RegExp, string, string]>} */ ([
|
|
|
327
355
|
function colorsIn(c) {
|
|
328
356
|
/** @type {Array<[number, string, boolean?]>} */
|
|
329
357
|
const found = [];
|
|
358
|
+
// "gray-50", "zinc 900": a stop on a gray family, by its lightness.
|
|
359
|
+
for (const m of c.matchAll(GRAY_STOP))
|
|
360
|
+
found.push([m.index ?? 0, grayStop(m[1], Number(m[2])), true]);
|
|
330
361
|
const re =
|
|
331
|
-
/#[0-9a-f]{3,8}\b|\b(?:rgba?|hsla?|hwb|lab|lch|oklab|oklch)\([^)]*\)|\b(?:(light|pale|dark)\s+)?([a-z]+)\b/g;
|
|
332
|
-
for (const m of c
|
|
333
|
-
|
|
334
|
-
|
|
362
|
+
/#[0-9a-f]{3,8}\b|\b(?:rgba?|hsla?|hwb|lab|lch|oklab|oklch|color-mix)\([^)]*\)|\b(?:(light|pale|dark|subtle|soft)\s+)?([a-z]+)\b/g;
|
|
363
|
+
for (const m of c
|
|
364
|
+
.replace(GRAY_STOP, s => ' '.repeat(s.length))
|
|
365
|
+
.matchAll(re)) {
|
|
366
|
+
const before = c.slice(Math.max(0, (m.index ?? 0) - 12), m.index);
|
|
367
|
+
// "charcoal text instead of black": the color after "instead of" is
|
|
368
|
+
// the one to move away from.
|
|
369
|
+
if (/\bnot\s*$|\bno\s*$|\binstead of\s*$|\brather than\s*$/.test(before))
|
|
370
|
+
continue;
|
|
335
371
|
const whole = m[0];
|
|
336
372
|
if (whole.startsWith('#') || whole.includes('(')) {
|
|
337
373
|
// A typed hex color keeps the case it is written in, as set stores it.
|
|
338
|
-
|
|
374
|
+
// A color-mix() is kept as typed; set checks it.
|
|
375
|
+
if (parseColor(whole) || /^color-mix\(/.test(whole))
|
|
376
|
+
found.push([m.index ?? 0, whole, true]);
|
|
339
377
|
continue;
|
|
340
378
|
}
|
|
341
|
-
const
|
|
379
|
+
const shade = m[1] === 'subtle' || m[1] === 'soft' ? 'pale' : m[1];
|
|
380
|
+
const word = m[2];
|
|
342
381
|
if (shade && SHADED[shade]?.[word]) {
|
|
343
382
|
found.push([m.index ?? 0, SHADED[shade][word]]);
|
|
344
383
|
continue;
|
|
@@ -397,7 +436,6 @@ const NOT_COLORS = new Set([
|
|
|
397
436
|
'gold',
|
|
398
437
|
'silver',
|
|
399
438
|
'salmon',
|
|
400
|
-
'tomato',
|
|
401
439
|
'thistle',
|
|
402
440
|
'orchid',
|
|
403
441
|
'wheat',
|
|
@@ -427,7 +465,11 @@ const boxIn = c =>
|
|
|
427
465
|
function shadowIn(c) {
|
|
428
466
|
const one =
|
|
429
467
|
'(?:inset\\s+)?-?\\d*\\.?\\d+(?:px)?\\s+-?\\d*\\.?\\d+(?:px)?(?:\\s+-?\\d*\\.?\\d+(?:px)?){0,2}\\s+(?:#[0-9a-f]{3,8}|(?:rgba?|hsla?|oklch)\\([^)]*\\)|[a-z]+)';
|
|
430
|
-
return
|
|
468
|
+
return (
|
|
469
|
+
new RegExp(`${one}(?:\\s*[,\u2e34]\\s*${one})*`)
|
|
470
|
+
.exec(c)?.[0]
|
|
471
|
+
.replace(/\u2e34/g, ',') ?? null
|
|
472
|
+
);
|
|
431
473
|
}
|
|
432
474
|
|
|
433
475
|
/** A length tied to a height word ("40px tall", "height 40px"). @param {string} c */
|
|
@@ -439,7 +481,7 @@ const tallIn = c =>
|
|
|
439
481
|
|
|
440
482
|
/** A length tied to a radius word ("8px radius", "radius: 8px"). @param {string} c */
|
|
441
483
|
const radiusIn = c =>
|
|
442
|
-
/(-?\d*\.?\d+(?:px|rem|em)?)\s*(?:radius|corners?)\b|\b(?:radius|corners?|rounded)\s*:?\s*(?:to\s+)?(-?\d*\.?\d+(?:px|rem|em)?)
|
|
484
|
+
/(-?\d*\.?\d+(?:px|rem|em|%)?)\s*(?:border[\s-]+)?(?:radius|corners?)\b|\b(?:radius|corners?|rounded)\s*(?:values?\s+)?(?:are|is|of|at)?\s*:?\s*(?:to\s+)?(?:about\s+|around\s+)?(-?\d*\.?\d+(?:px|rem|em|%)?)(?:\b|(?<=%))/
|
|
443
485
|
.exec(c)
|
|
444
486
|
?.slice(1)
|
|
445
487
|
.find(Boolean) ?? null;
|
|
@@ -480,15 +522,9 @@ function stronger(color, f, mode) {
|
|
|
480
522
|
function weightIn(c) {
|
|
481
523
|
const n = /\b([1-9]00)\b(?!\s*(px|ms|%))/.exec(c.text)?.[1];
|
|
482
524
|
if (n) return n;
|
|
483
|
-
const w = /\b(
|
|
525
|
+
const w = /\b(semi-?bold|medium|regular|normal)\b/.exec(c.text)?.[1];
|
|
484
526
|
return w
|
|
485
|
-
?
|
|
486
|
-
semibold: '600',
|
|
487
|
-
'semi-bold': '600',
|
|
488
|
-
medium: '500',
|
|
489
|
-
regular: '400',
|
|
490
|
-
normal: '400',
|
|
491
|
-
})[w]
|
|
527
|
+
? HEADING_WEIGHTS[w === 'normal' ? 'regular' : w.replace('-', '')]
|
|
492
528
|
: null;
|
|
493
529
|
}
|
|
494
530
|
|
|
@@ -501,11 +537,25 @@ function scaled(v, f) {
|
|
|
501
537
|
}
|
|
502
538
|
|
|
503
539
|
/**
|
|
504
|
-
*
|
|
505
|
-
* and maybe a `--when` condition, a heading level or a font role.
|
|
506
|
-
* @type {Array<[RegExp, {on: string, when?: string, role?: string, level?: string}]>}
|
|
540
|
+
* @typedef {{on: string, when?: string, role?: string, level?: string}} PartRef
|
|
507
541
|
*/
|
|
508
|
-
|
|
542
|
+
|
|
543
|
+
/**
|
|
544
|
+
* Phrases for parts that Core's catalog cannot give: groups, variants,
|
|
545
|
+
* font roles, phrases of several words, and words two components share.
|
|
546
|
+
* They are read before the catalog's names and doc keywords
|
|
547
|
+
* (partLexicon), longest phrase first.
|
|
548
|
+
* @type {Array<[RegExp, PartRef]>}
|
|
549
|
+
*/
|
|
550
|
+
const OVERRIDES = [
|
|
551
|
+
[/\bdividers?\b/, {on: 'divider'}],
|
|
552
|
+
[
|
|
553
|
+
/\baccordions? (headers?|triggers?|titles?|headings?)\b/,
|
|
554
|
+
{on: 'collapsible-trigger'},
|
|
555
|
+
],
|
|
556
|
+
[/\baccordions?\b/, {on: 'collapsible'}],
|
|
557
|
+
[/\bcombo ?box(es)?\b/, {on: 'complex-selector'}],
|
|
558
|
+
[/\bnotifications?\b/, {on: 'toast'}],
|
|
509
559
|
[/\b(focus (ring|outline)s?)\b/, {on: 'focus-ring'}],
|
|
510
560
|
[/\b((modal |dialog )?(overlay|scrim|backdrop))\b/, {on: 'overlay'}],
|
|
511
561
|
[/\bicons?\b/, {on: 'icons'}],
|
|
@@ -523,7 +573,13 @@ const PARTS = [
|
|
|
523
573
|
/\b((side ?nav|sidebar)( nav(igation)?)? (links?|items?))\b/,
|
|
524
574
|
{on: 'side-nav-item'},
|
|
525
575
|
],
|
|
526
|
-
[
|
|
576
|
+
[
|
|
577
|
+
/\b((dropdown |context )?menu (items?|options?|entries)|dropdown items?)\b/,
|
|
578
|
+
{on: 'dropdown-menu-item'},
|
|
579
|
+
],
|
|
580
|
+
[/\b(nav(igation)? (links?|items?))\b/, {on: 'top-nav-item'}],
|
|
581
|
+
[/\b((dropdown |context )?menus?)\b/, {on: 'dropdown-menu'}],
|
|
582
|
+
[/\bfooters?\b/, {on: 'layout-footer'}],
|
|
527
583
|
[/\b(side ?nav|sidebar|side ?panel)\b/, {on: 'side-nav'}],
|
|
528
584
|
[
|
|
529
585
|
/\b(app (name|title)|logo|site title|product name)\b/,
|
|
@@ -534,6 +590,7 @@ const PARTS = [
|
|
|
534
590
|
{on: 'app-shell-header'},
|
|
535
591
|
],
|
|
536
592
|
[/\b(page|app background|whole background|body background)\b/, {on: 'page'}],
|
|
593
|
+
[/\b(radio( buttons?)?|radios)\b/, {on: 'radio-indicator'}],
|
|
537
594
|
[/\b(primary|main) buttons?\b/, {on: 'button', when: 'variant:primary'}],
|
|
538
595
|
[/\bsecondary buttons?\b/, {on: 'button', when: 'variant:secondary'}],
|
|
539
596
|
[/\bghost buttons?\b/, {on: 'button', when: 'variant:ghost'}],
|
|
@@ -541,30 +598,102 @@ const PARTS = [
|
|
|
541
598
|
/\b(danger|destructive|delete) (buttons?|ones?|variant)\b/,
|
|
542
599
|
{on: 'button', when: 'variant:destructive'},
|
|
543
600
|
],
|
|
544
|
-
[/\bbuttons?\b/, {on: 'button'}],
|
|
545
|
-
[/\bcards?\b/, {on: 'card'}],
|
|
546
601
|
[/\b(panels?|windows?|boxes|tiles?|containers?)\b/, {on: 'containers'}],
|
|
547
602
|
[/\b(banners?|alerts?|notices?|announcements?)\b/, {on: 'banner'}],
|
|
603
|
+
[/\b(text ?areas?|multi-?line (inputs?|fields?))\b/, {on: 'text-area'}],
|
|
604
|
+
[
|
|
605
|
+
/\b(select (dropdowns?|menus?|box(es)?|inputs?)|selects|dropdowns?|pickers?|select(?! (the|a|an|all|any|one|which|what|it|them)\b))\b/,
|
|
606
|
+
{on: 'selector'},
|
|
607
|
+
],
|
|
608
|
+
[/\b(skeletons?( loaders?)?|loading placeholders?)\b/, {on: 'skeleton'}],
|
|
548
609
|
[
|
|
549
610
|
/\b(inputs?|text ?box(es)?|text ?fields?|form fields?|fields?)\b/,
|
|
550
611
|
{on: 'inputs'},
|
|
551
612
|
],
|
|
552
613
|
[/\b(checkbox(es)?|check ?marks?)\b/, {on: 'checks'}],
|
|
553
|
-
|
|
614
|
+
// "switch off", "switch the buttons to" are the verb, not the part.
|
|
615
|
+
[
|
|
616
|
+
/\b(toggles?|switch(es)?(?! (off|on|to|the|out|it|them|over|back|from)\b))\b/,
|
|
617
|
+
{on: 'switch'},
|
|
618
|
+
],
|
|
619
|
+
[/\b((table )?cells?)\b/, {on: 'table-cell'}],
|
|
554
620
|
[/\b(table rows?|rows?|tables?)\b/, {on: 'table-row'}],
|
|
555
|
-
[/\btabs?\b/, {on: 'tab'}],
|
|
556
621
|
[/\b(badges?|chips?|tags?)\b/, {on: 'badge'}],
|
|
557
622
|
[/\bh([1-4])\b/, {on: 'heading'}],
|
|
558
623
|
[/\b(headings?|titles?)\b/, {on: 'heading'}],
|
|
559
|
-
[/\b(
|
|
560
|
-
[/\btooltips?\b/, {on: 'tooltip'}],
|
|
561
|
-
[/\btoasts?\b/, {on: 'toast'}],
|
|
562
|
-
[/\bavatars?\b/, {on: 'avatar'}],
|
|
563
|
-
[/\blinks?\b/, {on: 'link'}],
|
|
624
|
+
[/\b(modals?|popups?)\b/, {on: 'dialog'}],
|
|
564
625
|
[/\bcode\b/, {on: 'code', role: 'code'}],
|
|
565
626
|
[/\bbody( text)?\b/, {on: 'body', role: 'body'}],
|
|
566
627
|
];
|
|
567
628
|
|
|
629
|
+
/**
|
|
630
|
+
* Target names in Core's catalog that are plain words a question uses for
|
|
631
|
+
* something else ("more padding", "align the text").
|
|
632
|
+
*/
|
|
633
|
+
const NOT_PART_WORDS = new Set([
|
|
634
|
+
'center',
|
|
635
|
+
'grid',
|
|
636
|
+
'item',
|
|
637
|
+
'layout',
|
|
638
|
+
'list',
|
|
639
|
+
'outline',
|
|
640
|
+
'section',
|
|
641
|
+
'stack',
|
|
642
|
+
'step',
|
|
643
|
+
'token',
|
|
644
|
+
]);
|
|
645
|
+
|
|
646
|
+
/** A word without its plural ending. @param {string} w */
|
|
647
|
+
const singular = w =>
|
|
648
|
+
/(x|ch|sh|ss)es$/.test(w)
|
|
649
|
+
? w.slice(0, -2)
|
|
650
|
+
: /[^s]s$/.test(w)
|
|
651
|
+
? w.slice(0, -1)
|
|
652
|
+
: w;
|
|
653
|
+
|
|
654
|
+
/** @type {WeakMap<object, {parts: Array<[RegExp, PartRef]>, vocab: string[]}>} */
|
|
655
|
+
const lexicons = new WeakMap();
|
|
656
|
+
|
|
657
|
+
/**
|
|
658
|
+
* The words for parts: the overrides, then every theming target's name read
|
|
659
|
+
* from Core's catalog, longest first; and the words a near miss is
|
|
660
|
+
* corrected to.
|
|
661
|
+
* @param {import('./_settings.mjs').Ctx} ctx
|
|
662
|
+
*/
|
|
663
|
+
function partLexicon(ctx) {
|
|
664
|
+
const {project} = ctx;
|
|
665
|
+
const known = lexicons.get(project);
|
|
666
|
+
if (known) return known;
|
|
667
|
+
// A one-word name how reads as something else is never a part's name:
|
|
668
|
+
// "text" is an aspect, "overlay" and "code" have overrides.
|
|
669
|
+
const other = (/** @type {string} */ w) =>
|
|
670
|
+
NOT_PART_WORDS.has(w) ||
|
|
671
|
+
aspectsOf(w).includes(w) ||
|
|
672
|
+
Object.hasOwn(DIALS, w) ||
|
|
673
|
+
OVERRIDES.some(([re]) => re.test(` ${w} `) || re.test(` ${w}s `));
|
|
674
|
+
/** @type {Array<[RegExp, PartRef]>} */
|
|
675
|
+
const derived = [...project.target.keys()]
|
|
676
|
+
.filter(key => key.includes('-') || !other(key))
|
|
677
|
+
.sort((x, y) => y.length - x.length)
|
|
678
|
+
.map(key => [
|
|
679
|
+
new RegExp(`\\b${key.replace(/-/g, '[\\s-]?')}s?\\b`),
|
|
680
|
+
{on: key},
|
|
681
|
+
]);
|
|
682
|
+
// Near misses are corrected to one-word part names and design words.
|
|
683
|
+
const vocab = [
|
|
684
|
+
...new Set([
|
|
685
|
+
...DESIGN_WORDS,
|
|
686
|
+
...Object.keys(HUES).filter(w => w.length >= 5),
|
|
687
|
+
...[...project.target.keys()]
|
|
688
|
+
.filter(key => !key.includes('-'))
|
|
689
|
+
.flatMap(key => [key, `${key}s`]),
|
|
690
|
+
]),
|
|
691
|
+
];
|
|
692
|
+
const lex = {parts: [...OVERRIDES, ...derived], vocab};
|
|
693
|
+
lexicons.set(project, lex);
|
|
694
|
+
return lex;
|
|
695
|
+
}
|
|
696
|
+
|
|
568
697
|
/** Words for a color the theme generates. */
|
|
569
698
|
const ROLE_WORDS =
|
|
570
699
|
/\b(accent|brand|primary colou?r|main colou?r|key colou?r|errors?|danger|destructive|success|positive|warnings?|caution|info|notices?|neutrals?)\b|\bprimary\s*:?\s*(?=#|rgb|hsl|oklch)/;
|
|
@@ -579,8 +708,21 @@ const STATE_WORDS = /** @type {Array<[RegExp, string]>} */ ([
|
|
|
579
708
|
/\b(selected|active (tab|nav|item|link|page))\b|\bactive\b(?=.*\b(nav|tab|item)\b)/,
|
|
580
709
|
'selected',
|
|
581
710
|
],
|
|
582
|
-
[
|
|
711
|
+
[
|
|
712
|
+
/\b(press(ed|es)?|click(ed|s)?|tap(ped|s)?(?! targets?)|on press|on click|when i click)\b/,
|
|
713
|
+
'active',
|
|
714
|
+
],
|
|
715
|
+
[/\b(typing|type in|tab to|tabbing|keyboard focus)\b/, 'focus'],
|
|
716
|
+
[/\b(after i check|once checked|i check)\b/, 'checked'],
|
|
717
|
+
[/\b(picked|chosen|choose|pick)\b/, 'selected'],
|
|
583
718
|
[/\b(invalid|errors? state|has an error|with an error)\b/, 'invalid'],
|
|
719
|
+
// Words for states a part may not have: the answer says so.
|
|
720
|
+
[/\bread-?only\b/, 'readonly'],
|
|
721
|
+
[
|
|
722
|
+
/\bloading\b(?! (bars?|placeholders?|skeletons?|spinners?|states?|indicators?))/,
|
|
723
|
+
'loading',
|
|
724
|
+
],
|
|
725
|
+
[/\b(unchecked|not checked|unticked)\b/, 'unchecked'],
|
|
584
726
|
]);
|
|
585
727
|
|
|
586
728
|
/**
|
|
@@ -598,6 +740,8 @@ const STATE_WORDS = /** @type {Array<[RegExp, string]>} */ ([
|
|
|
598
740
|
* @property {'light' | 'dark' | null} mode
|
|
599
741
|
* @property {boolean} except - "but not on X": X keeps what the clause before does
|
|
600
742
|
* @property {Record<string, string>} decl - CSS written as `prop: value`
|
|
743
|
+
* @property {string[]} [quoted] - family names the clause writes in quotes
|
|
744
|
+
* @property {{prop: string, value: string, bad?: string} | null} named - a CSS property the clause names, with its value as typed
|
|
601
745
|
*/
|
|
602
746
|
|
|
603
747
|
/**
|
|
@@ -617,19 +761,22 @@ function aspectsOf(text) {
|
|
|
617
761
|
};
|
|
618
762
|
if (/\b(letter ?spacing|tracking|kerning)\b/.test(c)) add('tracking');
|
|
619
763
|
if (
|
|
620
|
-
/\b(round(ed|er|ness|ing)?|unround\w*|corners?|radius|radii|curv\w*|circular|circles?|pill( shaped)?|sharp(er)?|square(d|r)?)\b/.test(
|
|
621
|
-
|
|
764
|
+
/\b(round(ed|er|ness|ing)?|unround\w*|corners?|radius|radii|curv\w*|circular(?! (font|typeface))|circles?|pill( shaped)?|sharp(er)?|square(d|r)?)\b/.test(
|
|
765
|
+
// "Feedback round 2" is not a corner.
|
|
766
|
+
c.replace(/\bround \d+\b/g, ' '),
|
|
622
767
|
)
|
|
623
768
|
)
|
|
624
769
|
add('corners');
|
|
625
770
|
if (
|
|
626
|
-
/\b(shadows?|elevat\w*|depth|raised|lifts?|lifted|lifting|glow\w*|bevel\w*|sunken|inset|flat)\b/.test(
|
|
771
|
+
/\b(shadows?|shadowy|elevat\w*|depth|raised|lifts?|lifted|lifting|glow\w*|bevel\w*|sunken|inset|flat)\b/.test(
|
|
627
772
|
c,
|
|
628
773
|
)
|
|
629
774
|
)
|
|
630
775
|
add('shadow');
|
|
631
776
|
if (
|
|
632
|
-
/\b(borders?(
|
|
777
|
+
/\b(borders?(?![\s-]*radius)|outlines?|strokes?|edges?|frames?|rings?)\b/.test(
|
|
778
|
+
c,
|
|
779
|
+
)
|
|
633
780
|
)
|
|
634
781
|
add('border');
|
|
635
782
|
if (/\bunderlined?\b|\bunderlines\b/.test(c) && !/\btabs?\b/.test(c))
|
|
@@ -649,14 +796,18 @@ function aspectsOf(text) {
|
|
|
649
796
|
if (/\bitalics?\b/.test(c)) add('italic');
|
|
650
797
|
if (
|
|
651
798
|
/\b(bold(er)?|unbold\w*|weight|heav(y|ier)|semibold)\b/.test(c) ||
|
|
652
|
-
/\bthin(ner)? (font|text|type|letters|headings?|labels
|
|
799
|
+
/\bthin(ner)? (body |button |heading |label )?(font|text|type|letters|headings?|labels?|copy)\b/.test(
|
|
800
|
+
c,
|
|
801
|
+
) ||
|
|
653
802
|
(/\blight(er)?\b/.test(c) &&
|
|
654
803
|
/\b(headings?|titles?|font|weight)\b/.test(c) &&
|
|
655
804
|
!/\b(text|colou?r|mode|background|bg)\b/.test(c))
|
|
656
805
|
)
|
|
657
806
|
add('weight');
|
|
658
807
|
if (
|
|
659
|
-
/\b(fonts?|typefaces?|serif|sans(-serif)?|mono(space|spaced)?)\b/.test(
|
|
808
|
+
/\b(fonts?|typefaces?|serif|sans(-serif)?|sanz|mono(space|spaced)?)\b/.test(
|
|
809
|
+
c,
|
|
810
|
+
) &&
|
|
660
811
|
!/\bfont ?size\b/.test(c) &&
|
|
661
812
|
!/\bfont ?weight\b|\b(bold|heav|light(er)?|thin)\w* fonts?\b|\bfonts? weight/.test(
|
|
662
813
|
c,
|
|
@@ -670,32 +821,68 @@ function aspectsOf(text) {
|
|
|
670
821
|
) ||
|
|
671
822
|
(/\b(bigger|larger|smaller)\b/.test(c) &&
|
|
672
823
|
/\b(text|font|headings?|titles?|h[1-6]|body)\b/.test(c)) ||
|
|
673
|
-
/\b\d+(px|rem) (text|font|labels?|type)\b/.test(c)
|
|
824
|
+
/\b\d+(px|rem) (text|font|labels?|type)\b/.test(c) ||
|
|
825
|
+
/\b(text|font|headings?|titles?|labels?|h[1-6])\s+\d+(\.\d+)?(px|rem|em|pt)\b/.test(
|
|
826
|
+
c,
|
|
827
|
+
) ||
|
|
828
|
+
/\b(text|font|type)( is)? (way |far |much )?too (small|tiny|big|large)\b|\btoo (small|tiny) to read\b/.test(
|
|
829
|
+
c,
|
|
830
|
+
) ||
|
|
831
|
+
/\bbody (text|copy|font)\s+\d+(\.\d+)?(px|rem)\b/.test(c)
|
|
674
832
|
)
|
|
675
833
|
add('fontsize');
|
|
676
834
|
if (
|
|
677
|
-
(/\b(taller|shorter|wider|narrower|width|height|bigger|larger|smaller|tall)\b/.test(
|
|
835
|
+
(/\b(taller|shorter|wider|narrower|width|(?<!line )height|bigger|larger|smaller|tall|too (small|tiny|big|large))\b/.test(
|
|
678
836
|
c,
|
|
679
837
|
) ||
|
|
680
838
|
(/\b(thick(er)?|thin(ner)?)\b/.test(c) &&
|
|
681
839
|
/\b(progress|underline|indicator)/.test(c))) &&
|
|
682
840
|
!a.includes('fontsize') &&
|
|
683
|
-
!a.includes('tracking')
|
|
841
|
+
!a.includes('tracking') &&
|
|
842
|
+
// "a bigger shadow" is a stronger shadow, not a bigger part.
|
|
843
|
+
!(
|
|
844
|
+
a.includes('shadow') &&
|
|
845
|
+
!/\b(taller|shorter|wider|narrower|width|height|tall)\b/.test(c)
|
|
846
|
+
)
|
|
684
847
|
)
|
|
685
848
|
add('size');
|
|
686
|
-
if (
|
|
849
|
+
if (
|
|
850
|
+
!a.includes('family') &&
|
|
851
|
+
new RegExp(`\\b(${FONT_NAMES})\\b`).test(c.replace(/\bsanz\b/g, 'sans'))
|
|
852
|
+
)
|
|
687
853
|
add('family');
|
|
688
854
|
if (!a.length && /\b(thick(er)?|thin(ner)?)\b/.test(c)) add('border');
|
|
855
|
+
// "faster hover transitions", "fade in slower": motion, not opacity.
|
|
689
856
|
if (
|
|
690
|
-
/\b(
|
|
691
|
-
|
|
692
|
-
|
|
857
|
+
/\b(transitions?|animations?|animate[sd]?|fade[sd]? (in|out)|motion)\b/.test(
|
|
858
|
+
c,
|
|
859
|
+
) &&
|
|
860
|
+
/\b(fast(er)?|slow(er)?|quick(er)?|snappier|speed|duration|\d+m?s|off|no|none|disable|stop|remove)\b/.test(
|
|
861
|
+
c,
|
|
693
862
|
)
|
|
863
|
+
) {
|
|
864
|
+
a.splice(0, a.length);
|
|
865
|
+
add('motion');
|
|
866
|
+
return a;
|
|
867
|
+
}
|
|
868
|
+
if (
|
|
869
|
+
/\b(faded|fade|opacity|see-through|washed out)\b/.test(c) ||
|
|
870
|
+
// A percent is an opacity only beside an opacity word, never inside a
|
|
871
|
+
// function or after a color ("#2563eb 0%" is a gradient stop).
|
|
872
|
+
(/\d+%/.test(withoutFunctions(c)) &&
|
|
873
|
+
/\b(transparent|translucent|opaque|alpha|visible)\b/.test(c) &&
|
|
874
|
+
!a.includes('corners'))
|
|
694
875
|
)
|
|
695
876
|
add('opacity');
|
|
696
|
-
if (/\b(scales? (down|up)|shrinks?|grows
|
|
877
|
+
if (/\b(scales? (down|up)|shrinks?|grows?|scale\s*:?\s*0?\.\d+)\b/.test(c))
|
|
878
|
+
add('scale');
|
|
697
879
|
if (
|
|
698
|
-
/\b(text|writing|words|labels?|font colou?r|readable|links
|
|
880
|
+
(/\b(text|writing|words|labels?|font colou?r|readable|links?|body copy)\b/.test(
|
|
881
|
+
c,
|
|
882
|
+
) ||
|
|
883
|
+
// "heading color red": a part that is only text has a text color.
|
|
884
|
+
/\b(headings?|titles?|h[1-6]) colou?rs?\b/.test(c) ||
|
|
885
|
+
/\b(buttons?|links?) colou?r\b/.test(c)) &&
|
|
699
886
|
!a.some(x =>
|
|
700
887
|
['case', 'italic', 'weight', 'family', 'fontsize', 'tracking'].includes(
|
|
701
888
|
x,
|
|
@@ -721,63 +908,111 @@ const FONT_NAMES = [...Object.keys(OPEN_FONTS), ...Object.keys(FONTS)]
|
|
|
721
908
|
/**
|
|
722
909
|
* Read a question into clauses.
|
|
723
910
|
* @param {string} q lower-case, translated, corrected
|
|
911
|
+
* @param {Array<[RegExp, PartRef]>} partWords
|
|
724
912
|
* @returns {Clause[]}
|
|
725
913
|
*/
|
|
726
|
-
function clausesOf(q) {
|
|
914
|
+
function clausesOf(q, partWords) {
|
|
727
915
|
// "swap X and Y" is one ask.
|
|
728
916
|
const pieces = (/\bswap\b/.test(q) ? q.replace(/\band\b/g, '&') : q)
|
|
729
917
|
.split(
|
|
730
|
-
/;|\.(?=\s|$)|,(?![^(]*\))|\b(?:and|with|but|then|plus|also)\b|\bwhile\b|(?=\bexcept\b)/,
|
|
918
|
+
/;|\.(?=\s|$)|,(?![^(]*\))|\b(?:and|with|but|then|plus|also|y|et|und|и)\b|\bwhile\b|(?=\bexcept\b)/,
|
|
731
919
|
)
|
|
732
920
|
.map(s => s.trim())
|
|
733
921
|
.filter(Boolean);
|
|
734
922
|
return pieces.map(text => {
|
|
735
923
|
/** @type {Clause['parts']} */
|
|
736
924
|
const parts = [];
|
|
737
|
-
|
|
925
|
+
// A property name is not a part: "backdrop-filter" names no backdrop.
|
|
926
|
+
let rest = ` ${text} `
|
|
927
|
+
// "when I tab to a link": the key, not the tab part.
|
|
928
|
+
.replace(/\b(i |we |you )?tab(bing)? (to|through|into)\b/g, ' ')
|
|
929
|
+
.replace(/\bvar\([^)]*\)|--[a-z][\w-]*/g, ' ')
|
|
930
|
+
.replace(/\b[a-z]+(?:-[a-z]+)+\b/g, m =>
|
|
931
|
+
cssProperties().has(m) ? ' ' : m,
|
|
932
|
+
);
|
|
738
933
|
const cornerWords = /\b(round|corner|radius|shape|circular)/.test(text);
|
|
739
|
-
for (const [re, part] of
|
|
934
|
+
for (const [re, part] of partWords) {
|
|
740
935
|
const m = re.exec(rest);
|
|
741
936
|
if (!m) continue;
|
|
742
937
|
const p = {...part};
|
|
743
938
|
if (p.on === 'heading' && /^h[1-4]$/.test(m[0])) p.level = m[1];
|
|
939
|
+
// "the error banner": one status of the banner.
|
|
940
|
+
const status =
|
|
941
|
+
/\b(error|danger|warning|success|info)\s+(banners?|alerts?|notices?)\b/.exec(
|
|
942
|
+
rest,
|
|
943
|
+
)?.[1];
|
|
944
|
+
if (p.on === 'banner' && status)
|
|
945
|
+
p.when = `status:${status === 'danger' ? 'error' : status}`;
|
|
744
946
|
parts.push(p);
|
|
745
947
|
rest = rest.replace(re, ' ');
|
|
746
948
|
}
|
|
949
|
+
// "list rounder": a catalog name that is also a plain word is the part
|
|
950
|
+
// when the clause names no other part and asks for a shape change.
|
|
951
|
+
const shapeAsk =
|
|
952
|
+
/\b(round\w*|corners?|radius|shadows?|borders?|padding|bold\w*|bigger|smaller|taller|wider)\b/;
|
|
953
|
+
if (!parts.length && shapeAsk.test(text))
|
|
954
|
+
for (const w of NOT_PART_WORDS)
|
|
955
|
+
if (new RegExp(`\\b${w}s?\\b`).test(text)) {
|
|
956
|
+
parts.push({on: w});
|
|
957
|
+
break;
|
|
958
|
+
}
|
|
747
959
|
// "pill" names a corner shape, not a badge, when the clause is about shape.
|
|
748
960
|
if (cornerWords || /\bpill( shaped)?\b/.test(text))
|
|
749
961
|
for (let i = parts.length - 1; i >= 0; i--)
|
|
750
962
|
if (parts[i].on === 'badge' && !/\b(badges?|chips?|tags?)\b/.test(text))
|
|
751
963
|
parts.splice(i, 1);
|
|
752
|
-
|
|
964
|
+
// "Space Grotesk headings": a font's name is a font, never its words.
|
|
965
|
+
const aspects = aspectsOf(
|
|
966
|
+
text
|
|
967
|
+
.replace(new RegExp(`\\b(${FONT_NAMES})\\b`, 'g'), ' font ')
|
|
968
|
+
.replace(/\bspace (mono|grotesk|grotesque)\b/g, ' font '),
|
|
969
|
+
);
|
|
753
970
|
// "orange not red" negates a color, not the change.
|
|
754
971
|
const hue = Object.keys(HUES).join('|');
|
|
755
972
|
const negText = text.replace(
|
|
756
|
-
new RegExp(
|
|
973
|
+
new RegExp(
|
|
974
|
+
`\\b(not|no)\\s+((pure|plain|light|dark|pale|off)[\\s-]+)?(${hue})\\b`,
|
|
975
|
+
'g',
|
|
976
|
+
),
|
|
757
977
|
' ',
|
|
758
978
|
);
|
|
979
|
+
// "shouldn't links be underlined?": a question that asks for it.
|
|
980
|
+
const askedFor =
|
|
981
|
+
/^(shouldn'?t|wouldn'?t|isn'?t|aren'?t|can'?t|couldn'?t) .*\?$/.test(
|
|
982
|
+
text.trim(),
|
|
983
|
+
) ||
|
|
984
|
+
(/^(shouldn'?t|wouldn'?t|isn'?t|aren'?t)\b/.test(text.trim()) &&
|
|
985
|
+
/\?/.test(text));
|
|
759
986
|
const neg =
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
987
|
+
!askedFor &&
|
|
988
|
+
/\b(no|not|nothing|none of|don'?t|do not|never|without|remove|removing|get rid of|lose|drop|ditch|nix|scrap|kill|none|shouldn'?t|should not|mustn'?t|turn off|turn (the|it|them) off|switch off|stop|unbold\w*|unround\w*|disable|(?:revert|undo|take back) (?:the|those|that|these|my|our|all)|(?:shadows?|borders?|underlines?|outlines?|gradients?|uppercase|caps) (?:off|out|gone))\b/.test(
|
|
989
|
+
negText
|
|
990
|
+
.replace(/\bdisabled\b/g, ' ')
|
|
991
|
+
// "not round enough" asks for more; "not so much" for less.
|
|
992
|
+
.replace(/\bnot (\w+ ){0,2}enough\b/g, ' ')
|
|
993
|
+
.replace(/\bnot (so|as|that|too) (much|many)\b/g, ' '),
|
|
994
|
+
) &&
|
|
995
|
+
!/\bno (wait|longer)\b/.test(negText);
|
|
763
996
|
// "too X" asks for less X: too sharp is rounder, too heavy is lighter.
|
|
764
997
|
const tooLess =
|
|
765
|
-
/\btoo (big|large|round|rounded|bold|heavy|thick|dark|spacious|airy|bright|loud|strong|harsh|much|wide|tall)\b/;
|
|
998
|
+
/\btoo (big|large|round|rounded|roundy|bubbly|shadowy|bold|heavy|thick|dark|spacious|airy|bright|loud|strong|harsh|aggressive|intense|garish|saturated|much|wide|tall)\b/;
|
|
766
999
|
const tooMore =
|
|
767
1000
|
/\btoo (small|cramped|tight|crowded|faded|light|thin|sharp|square|boxy|pointy|subtle|weak|narrow|dim|low|short)\b/;
|
|
768
|
-
const dir =
|
|
769
|
-
? '
|
|
770
|
-
:
|
|
771
|
-
? '
|
|
772
|
-
:
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
? 'less'
|
|
776
|
-
: /\b(more|bigger|larger|higher|increase|stronger|thicker|wider|taller|rounder|roomier|airy|spacious|bolder|heavier|darker|a bit|a little|slightly|much)\b/.test(
|
|
1001
|
+
const dir = /\bnot (\w+ ){0,2}enough\b/.test(text)
|
|
1002
|
+
? 'more'
|
|
1003
|
+
: /\bnot (so|as|that|too) (much|many)\b/.test(text) || tooLess.test(text)
|
|
1004
|
+
? 'less'
|
|
1005
|
+
: tooMore.test(text)
|
|
1006
|
+
? 'more'
|
|
1007
|
+
: /\b(less|fewer|smaller|lower|reduce|softer|lighter|lighten|thinner|narrower|shorter|tight(en|er)?|dense(r)?|denser|compact|sharper|squarer|subtler|tone down|dimmer|halve|half|halved|least|minimum|min|minimal|barely|as little)\b|\bcut\b.*\bin half\b|\bx ?0?\.\d+\b|\b(knock|turn|dial|bring|tone)\b.*\bdown\b/.test(
|
|
777
1008
|
text,
|
|
778
1009
|
)
|
|
779
|
-
? '
|
|
780
|
-
:
|
|
1010
|
+
? 'less'
|
|
1011
|
+
: /\b(more|bigger|larger|higher|increase|stronger|thicker|wider|taller|rounder|roomier|airy|spacious|bolder|heavier|darker|darken|loosen|open up|twice|double|a bit|a little|slightly|much)\b/.test(
|
|
1012
|
+
text,
|
|
1013
|
+
)
|
|
1014
|
+
? 'more'
|
|
1015
|
+
: null;
|
|
781
1016
|
/** @type {Record<string, string>} */
|
|
782
1017
|
const decl = {};
|
|
783
1018
|
for (const m of text.matchAll(
|
|
@@ -796,10 +1031,14 @@ function clausesOf(q) {
|
|
|
796
1031
|
break;
|
|
797
1032
|
}
|
|
798
1033
|
const mode =
|
|
799
|
-
/\bdark( mode| theme)?\b/.test(text) &&
|
|
800
|
-
|
|
1034
|
+
(/\bdark( mode| theme)?\b/.test(text) &&
|
|
1035
|
+
/\b(mode|theme|in dark)\b/.test(text)) ||
|
|
1036
|
+
// Only mode phrases: "all day" or "the selected day" is no mode.
|
|
1037
|
+
/\bnight (mode|theme)\b|\bat night\b|\boled\b|^dark\s*:/.test(text)
|
|
801
1038
|
? 'dark'
|
|
802
|
-
: /\blight (mode|theme)\b
|
|
1039
|
+
: /\blight (mode|theme)\b|\bday ?time\b|\bday (mode|theme)\b|\bin the day\b|^light\s*:/.test(
|
|
1040
|
+
text,
|
|
1041
|
+
)
|
|
803
1042
|
? 'light'
|
|
804
1043
|
: null;
|
|
805
1044
|
const except =
|
|
@@ -812,11 +1051,16 @@ function clausesOf(q) {
|
|
|
812
1051
|
text,
|
|
813
1052
|
parts,
|
|
814
1053
|
aspects,
|
|
1054
|
+
named: namedProperty(text),
|
|
815
1055
|
neg,
|
|
816
1056
|
dir,
|
|
817
1057
|
colors: colorsIn(text),
|
|
818
1058
|
bad: badHex(text),
|
|
819
|
-
|
|
1059
|
+
// A typed clamp() or calc() is a length, kept whole.
|
|
1060
|
+
lengths: [
|
|
1061
|
+
...(text.match(/\b(?:clamp|calc|min|max)\([^)]*\)/g) ?? []),
|
|
1062
|
+
...lengthsIn(text),
|
|
1063
|
+
],
|
|
820
1064
|
state,
|
|
821
1065
|
mode,
|
|
822
1066
|
except,
|
|
@@ -825,6 +1069,328 @@ function clausesOf(q) {
|
|
|
825
1069
|
});
|
|
826
1070
|
}
|
|
827
1071
|
|
|
1072
|
+
/**
|
|
1073
|
+
* A CSS property the clause names, with its value kept whole ("caret-color
|
|
1074
|
+
* #2563eb", "transition: background-color 150ms ease", "border-radius 12px
|
|
1075
|
+
* 12px 0 0"). The value runs to the end of the clause or the part it is
|
|
1076
|
+
* for, and is the longest start of it the property's grammar accepts.
|
|
1077
|
+
* Plain words that are also properties ("color", "padding") count only
|
|
1078
|
+
* with a colon; the aspect words read those.
|
|
1079
|
+
* @param {string} text
|
|
1080
|
+
* @returns {{prop: string, value: string, bad?: string} | null}
|
|
1081
|
+
*/
|
|
1082
|
+
export function namedProperty(text) {
|
|
1083
|
+
const props = cssProperties();
|
|
1084
|
+
const flat = text.replace(/\u2e34/g, ',');
|
|
1085
|
+
for (const m of flat.matchAll(
|
|
1086
|
+
/\b((?:border|outline)(?: (?:top|right|bottom|left))? (?:colou?r|width|style)|(?:min|max) (?:height|width)|line height|letter spacing|font (?:size|weight)|radius|[a-z]+(?:-[a-z]+)+|[a-z]+)(\s*:)?\s*/g,
|
|
1087
|
+
)) {
|
|
1088
|
+
const prop =
|
|
1089
|
+
PROPERTY_WORDS[m[1]] ??
|
|
1090
|
+
(/^(border|outline)( (top|right|bottom|left))? (colou?r|width|style)$/.test(
|
|
1091
|
+
m[1],
|
|
1092
|
+
)
|
|
1093
|
+
? m[1].replace(/colour/, 'color').replace(/ /g, '-')
|
|
1094
|
+
: m[1]);
|
|
1095
|
+
// A property word right after another one ("border width") is part of
|
|
1096
|
+
// it, never a property of its own.
|
|
1097
|
+
if (
|
|
1098
|
+
/\b(border|outline)\s*$/.test(flat.slice(0, m.index ?? 0)) &&
|
|
1099
|
+
!m[1].startsWith('border') &&
|
|
1100
|
+
m[1] !== 'radius'
|
|
1101
|
+
)
|
|
1102
|
+
continue;
|
|
1103
|
+
if (!props.has(prop)) continue;
|
|
1104
|
+
// A plain word ("background", "padding") without a colon is a property
|
|
1105
|
+
// only before a value that is typed, not described.
|
|
1106
|
+
const plain = !m[2] && !/[- ]/.test(m[1]);
|
|
1107
|
+
// Without a colon, only these plain words name a property; others
|
|
1108
|
+
// ("inset", "fill") are design words.
|
|
1109
|
+
if (plain && !PLAIN_PROPERTIES.has(prop)) continue;
|
|
1110
|
+
// "shadow opacity", "border opacity": a layer's alpha, not the part's.
|
|
1111
|
+
if (
|
|
1112
|
+
prop === 'opacity' &&
|
|
1113
|
+
/\b(shadows?|backgrounds?|bg|borders?|outlines?)\s*$/.test(
|
|
1114
|
+
flat.slice(0, m.index ?? 0),
|
|
1115
|
+
)
|
|
1116
|
+
)
|
|
1117
|
+
continue;
|
|
1118
|
+
const rest = flat
|
|
1119
|
+
.slice((m.index ?? 0) + m[0].length)
|
|
1120
|
+
.replace(/^(?:to|of|is|=)\s+/, '')
|
|
1121
|
+
.replace(
|
|
1122
|
+
/\s+(?:on|for|in|when|while|if)\s+(?:the\s+|all\s+|every\s+)?[a-z][\w-]*.*$/,
|
|
1123
|
+
'',
|
|
1124
|
+
)
|
|
1125
|
+
.trim();
|
|
1126
|
+
const tokens = valueWords(rest);
|
|
1127
|
+
// "padding NaNpx": a length the property cannot take.
|
|
1128
|
+
if (
|
|
1129
|
+
tokens[0] &&
|
|
1130
|
+
/^(?:nan|[\d.]+[a-z]*)(px|rem|em)$/.test(tokens[0]) &&
|
|
1131
|
+
!matchValue(prop, tokens[0])
|
|
1132
|
+
)
|
|
1133
|
+
return {prop, value: '', bad: tokens[0]};
|
|
1134
|
+
if (
|
|
1135
|
+
plain &&
|
|
1136
|
+
(!/^(?:[-.\d#]|[a-z-]+\(|transparent\b|none\b|normal\b|currentcolor\b)/.test(
|
|
1137
|
+
rest,
|
|
1138
|
+
) ||
|
|
1139
|
+
// "a #e5e7eb border" has no width: the border answer gives one.
|
|
1140
|
+
(prop === 'border' && /^#/.test(rest)))
|
|
1141
|
+
)
|
|
1142
|
+
continue;
|
|
1143
|
+
// "border 0 0 2px": lengths alone on a border are its widths, all kept.
|
|
1144
|
+
const lengths = tokens.filter(t => /^(0|\d*\.?\d+(px|rem|em))$/.test(t));
|
|
1145
|
+
if (
|
|
1146
|
+
/^(border|outline)$/.test(prop) &&
|
|
1147
|
+
lengths.length > 1 &&
|
|
1148
|
+
lengths.length === tokens.length &&
|
|
1149
|
+
matchValue(`${prop}-width`, tokens.join(' '))
|
|
1150
|
+
)
|
|
1151
|
+
return {prop: `${prop}-width`, value: tokens.join(' ')};
|
|
1152
|
+
for (let n = tokens.length; n > 0; n--) {
|
|
1153
|
+
const value = tokens
|
|
1154
|
+
.slice(0, n)
|
|
1155
|
+
.join(' ')
|
|
1156
|
+
.replace(/[.;,]+$/, '');
|
|
1157
|
+
// A font size of 0 hides the text.
|
|
1158
|
+
if (prop === 'font-size' && /^0(px|rem|em)?$/.test(value))
|
|
1159
|
+
return {prop, value: '', bad: value};
|
|
1160
|
+
if (!value || !matchValue(prop, value)) continue;
|
|
1161
|
+
// A value that drops typed words is not the one asked for: "border
|
|
1162
|
+
// 0 0 2px" is not "border 0".
|
|
1163
|
+
if (n < tokens.length && /^[-.\d#]/.test(tokens[n] ?? '')) break;
|
|
1164
|
+
return completeShorthand(prop, value);
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
return null;
|
|
1168
|
+
}
|
|
1169
|
+
|
|
1170
|
+
/**
|
|
1171
|
+
* A shorthand value made complete, so it does what was asked: a border or
|
|
1172
|
+
* outline with no line style draws nothing, and a text-decoration with
|
|
1173
|
+
* only a color takes the underline away. Lengths alone are the width, a
|
|
1174
|
+
* color alone is the color, and a width with a color gets a solid line.
|
|
1175
|
+
* @param {string} prop
|
|
1176
|
+
* @param {string} value
|
|
1177
|
+
* @returns {{prop: string, value: string}}
|
|
1178
|
+
*/
|
|
1179
|
+
function completeShorthand(prop, value) {
|
|
1180
|
+
const words = valueWords(value);
|
|
1181
|
+
const isLength = (/** @type {string} */ w) =>
|
|
1182
|
+
/^(0|-?\d*\.?\d+(px|rem|em|pt)|thin|medium|thick)$/.test(w) ||
|
|
1183
|
+
/^(calc|var)\(/.test(w);
|
|
1184
|
+
const isColor = (/** @type {string} */ w) =>
|
|
1185
|
+
Boolean(parseColor(w)) ||
|
|
1186
|
+
/^(var|color-mix|light-dark)\(/.test(w) ||
|
|
1187
|
+
w === 'transparent' ||
|
|
1188
|
+
w === 'currentcolor';
|
|
1189
|
+
const styled = words.some(w =>
|
|
1190
|
+
/^(none|hidden|solid|dashed|dotted|double|groove|ridge|inset|outset|auto)$/.test(
|
|
1191
|
+
w,
|
|
1192
|
+
),
|
|
1193
|
+
);
|
|
1194
|
+
// "border 0" takes the border away, as typed.
|
|
1195
|
+
if (/^(border|outline)$/.test(prop) && value === '0') return {prop, value};
|
|
1196
|
+
if (/^(border|outline)(-(top|right|bottom|left))?$/.test(prop) && !styled) {
|
|
1197
|
+
if (words.every(isLength))
|
|
1198
|
+
return {
|
|
1199
|
+
prop:
|
|
1200
|
+
prop === 'outline'
|
|
1201
|
+
? 'outline-width'
|
|
1202
|
+
: `${prop.replace(/-(top|right|bottom|left)$/, '')}${/-(top|right|bottom|left)$/.test(prop) ? prop.slice(prop.lastIndexOf('-')) : ''}-width`,
|
|
1203
|
+
value,
|
|
1204
|
+
};
|
|
1205
|
+
if (words.every(isColor)) return {prop: `${prop}-color`, value};
|
|
1206
|
+
if (words.length === 2 && words.some(isLength) && words.some(isColor)) {
|
|
1207
|
+
const len = /** @type {string} */ (words.find(isLength));
|
|
1208
|
+
const col = /** @type {string} */ (words.find(isColor));
|
|
1209
|
+
return {prop, value: `${len} solid ${col}`};
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
if (prop === 'text-decoration' && words.every(isColor))
|
|
1213
|
+
return {prop: 'text-decoration-color', value};
|
|
1214
|
+
return {prop, value};
|
|
1215
|
+
}
|
|
1216
|
+
|
|
1217
|
+
/** Plain words that name a property without a colon, before a typed value. */
|
|
1218
|
+
const PLAIN_PROPERTIES = new Set([
|
|
1219
|
+
'background',
|
|
1220
|
+
'opacity',
|
|
1221
|
+
'border',
|
|
1222
|
+
'border-radius',
|
|
1223
|
+
'border-color',
|
|
1224
|
+
'padding',
|
|
1225
|
+
'margin',
|
|
1226
|
+
'gap',
|
|
1227
|
+
'filter',
|
|
1228
|
+
'width',
|
|
1229
|
+
'height',
|
|
1230
|
+
'min-height',
|
|
1231
|
+
'max-height',
|
|
1232
|
+
'min-width',
|
|
1233
|
+
'max-width',
|
|
1234
|
+
'line-height',
|
|
1235
|
+
'letter-spacing',
|
|
1236
|
+
'font-size',
|
|
1237
|
+
'font-weight',
|
|
1238
|
+
'outline',
|
|
1239
|
+
'transition',
|
|
1240
|
+
'transform',
|
|
1241
|
+
]);
|
|
1242
|
+
|
|
1243
|
+
/** Words people write for a CSS property. */
|
|
1244
|
+
const PROPERTY_WORDS = /** @type {Record<string, string>} */ ({
|
|
1245
|
+
radius: 'border-radius',
|
|
1246
|
+
'min height': 'min-height',
|
|
1247
|
+
'max height': 'max-height',
|
|
1248
|
+
'min width': 'min-width',
|
|
1249
|
+
'max width': 'max-width',
|
|
1250
|
+
'line height': 'line-height',
|
|
1251
|
+
'letter spacing': 'letter-spacing',
|
|
1252
|
+
'font size': 'font-size',
|
|
1253
|
+
'font weight': 'font-weight',
|
|
1254
|
+
'border color': 'border-color',
|
|
1255
|
+
'border colour': 'border-color',
|
|
1256
|
+
});
|
|
1257
|
+
|
|
1258
|
+
/**
|
|
1259
|
+
* The words of a value, with each function call kept whole, nested calls
|
|
1260
|
+
* included ("linear-gradient(135deg, rgba(0,0,0,.1) 0%, #fff 100%)").
|
|
1261
|
+
* @param {string} rest
|
|
1262
|
+
* @returns {string[]}
|
|
1263
|
+
*/
|
|
1264
|
+
function valueWords(rest) {
|
|
1265
|
+
/** @type {string[]} */
|
|
1266
|
+
const out = [];
|
|
1267
|
+
let word = '';
|
|
1268
|
+
let depth = 0;
|
|
1269
|
+
for (const ch of rest) {
|
|
1270
|
+
if (ch === '(') depth++;
|
|
1271
|
+
if (ch === ')') depth = Math.max(0, depth - 1);
|
|
1272
|
+
if (/\s/.test(ch) && !depth) {
|
|
1273
|
+
if (word) out.push(word);
|
|
1274
|
+
word = '';
|
|
1275
|
+
} else word += ch;
|
|
1276
|
+
}
|
|
1277
|
+
if (word) out.push(word);
|
|
1278
|
+
return out;
|
|
1279
|
+
}
|
|
1280
|
+
|
|
1281
|
+
/**
|
|
1282
|
+
* Text with every CSS function call taken out, nested calls included.
|
|
1283
|
+
* @param {string} text
|
|
1284
|
+
*/
|
|
1285
|
+
function withoutFunctions(text) {
|
|
1286
|
+
let out = '';
|
|
1287
|
+
let depth = 0;
|
|
1288
|
+
for (let i = 0; i < text.length; i++) {
|
|
1289
|
+
const ch = text[i];
|
|
1290
|
+
if (ch === '(' && (depth || /[\w-]$/.test(out))) {
|
|
1291
|
+
if (!depth) out = out.replace(/[\w-]+$/, '');
|
|
1292
|
+
depth++;
|
|
1293
|
+
} else if (ch === ')' && depth) depth--;
|
|
1294
|
+
else if (!depth) out += ch;
|
|
1295
|
+
}
|
|
1296
|
+
return out;
|
|
1297
|
+
}
|
|
1298
|
+
|
|
1299
|
+
/** The settings each aspect names, for a reset; `*` matches a prefix. */
|
|
1300
|
+
const RESET_THINGS = /** @type {Record<string, string[]>} */ ({
|
|
1301
|
+
corners: ['corners', 'border-radius', '--radius-*'],
|
|
1302
|
+
spacing: ['spacing', 'padding', 'gap', 'margin', '--spacing-*'],
|
|
1303
|
+
family: ['font', 'font-family', '--font-family-*'],
|
|
1304
|
+
background: ['background', 'background-color'],
|
|
1305
|
+
text: ['color', '--color-text-*'],
|
|
1306
|
+
shadow: ['box-shadow', 'surfaces', '--shadow-*'],
|
|
1307
|
+
border: [
|
|
1308
|
+
'border',
|
|
1309
|
+
'border-width',
|
|
1310
|
+
'border-color',
|
|
1311
|
+
'--border-width',
|
|
1312
|
+
'--color-border',
|
|
1313
|
+
],
|
|
1314
|
+
weight: ['headings', 'font-weight', '--text-body-weight'],
|
|
1315
|
+
fontsize: ['text-size', 'type', 'font-size'],
|
|
1316
|
+
leading: ['line-height', '--text-body-leading'],
|
|
1317
|
+
tracking: ['letter-spacing'],
|
|
1318
|
+
});
|
|
1319
|
+
|
|
1320
|
+
/** Words for a color the theme generates: the word, its dial, its token. */
|
|
1321
|
+
const ROLE_DIALS = /** @type {Array<[RegExp, string, string]>} */ ([
|
|
1322
|
+
[/\b(accent|brand|primary colou?r)\b/, 'accent', '--color-accent'],
|
|
1323
|
+
[/\b(danger|errors?)\b/, 'danger', '--color-error'],
|
|
1324
|
+
[/\bsuccess\b/, 'success', '--color-success'],
|
|
1325
|
+
[/\bwarnings?\b/, 'warning', '--color-warning'],
|
|
1326
|
+
[/\binfo\b/, 'info', '--color-info'],
|
|
1327
|
+
[/\b(neutrals?|grays?|greys?)\b/, 'neutral', '--color-neutral'],
|
|
1328
|
+
]);
|
|
1329
|
+
|
|
1330
|
+
/** Number words, longest phrase first. */
|
|
1331
|
+
const NUMBER_WORDS = /** @type {Record<string, number>} */ ({
|
|
1332
|
+
zero: 0,
|
|
1333
|
+
one: 1,
|
|
1334
|
+
two: 2,
|
|
1335
|
+
three: 3,
|
|
1336
|
+
four: 4,
|
|
1337
|
+
five: 5,
|
|
1338
|
+
six: 6,
|
|
1339
|
+
seven: 7,
|
|
1340
|
+
eight: 8,
|
|
1341
|
+
nine: 9,
|
|
1342
|
+
ten: 10,
|
|
1343
|
+
eleven: 11,
|
|
1344
|
+
twelve: 12,
|
|
1345
|
+
thirteen: 13,
|
|
1346
|
+
fourteen: 14,
|
|
1347
|
+
fifteen: 15,
|
|
1348
|
+
sixteen: 16,
|
|
1349
|
+
seventeen: 17,
|
|
1350
|
+
eighteen: 18,
|
|
1351
|
+
nineteen: 19,
|
|
1352
|
+
twenty: 20,
|
|
1353
|
+
thirty: 30,
|
|
1354
|
+
forty: 40,
|
|
1355
|
+
fifty: 50,
|
|
1356
|
+
sixty: 60,
|
|
1357
|
+
seventy: 70,
|
|
1358
|
+
eighty: 80,
|
|
1359
|
+
ninety: 90,
|
|
1360
|
+
hundred: 100,
|
|
1361
|
+
});
|
|
1362
|
+
const NUMBER_WORDS_RE = new RegExp(
|
|
1363
|
+
`\\b(?:(?:one|a) and a half|half an?|an? quarter(?: of an?)?|an? half|(?:twenty|thirty|forty|fifty|sixty|seventy|eighty|ninety)[- ](?:one|two|three|four|five|six|seven|eight|nine)|${Object.keys(NUMBER_WORDS).join('|')})\\b(?=\\s*(?:-|\\s)?\\s*(?:px|pixels?|rem|em|pt|percent|%|radius|corners?|line height|times|x\\b|\\w+ (?:tall|wide|thick)|tall|wide|thick))`,
|
|
1364
|
+
'gi',
|
|
1365
|
+
);
|
|
1366
|
+
/** A number phrase as digits. @param {string} m */
|
|
1367
|
+
function numberWord(m) {
|
|
1368
|
+
const w = m.toLowerCase().replace(/-/g, ' ');
|
|
1369
|
+
if (/and a half/.test(w)) return '1.5';
|
|
1370
|
+
if (/^(half|a half|an half)/.test(w)) return '0.5';
|
|
1371
|
+
if (/quarter/.test(w)) return '0.25';
|
|
1372
|
+
return String(w.split(' ').reduce((n, x) => n + (NUMBER_WORDS[x] ?? 0), 0));
|
|
1373
|
+
}
|
|
1374
|
+
|
|
1375
|
+
/**
|
|
1376
|
+
* Whether a few words name a color or a font, for "swap A for B".
|
|
1377
|
+
* @param {string} words lower-case
|
|
1378
|
+
* @returns {'color' | 'font' | undefined}
|
|
1379
|
+
*/
|
|
1380
|
+
function valueKind(words) {
|
|
1381
|
+
const w = words.trim();
|
|
1382
|
+
if (parseColor(w) || Object.hasOwn(HUES, w)) return 'color';
|
|
1383
|
+
const slug = w.replace(/\s+/g, '-');
|
|
1384
|
+
if (
|
|
1385
|
+
Object.hasOwn(OPEN_FONTS, slug) ||
|
|
1386
|
+
Object.hasOwn(FONTS, slug) ||
|
|
1387
|
+
Object.values(OPEN_FONTS).some(f => f.family.toLowerCase() === w) ||
|
|
1388
|
+
Object.values(FONTS).some(f => String(f[0]).toLowerCase() === w)
|
|
1389
|
+
)
|
|
1390
|
+
return 'font';
|
|
1391
|
+
return undefined;
|
|
1392
|
+
}
|
|
1393
|
+
|
|
828
1394
|
/**
|
|
829
1395
|
* Answer a plain-words question with drafts of commands.
|
|
830
1396
|
* @param {import('./_settings.mjs').Ctx} ctx
|
|
@@ -836,22 +1402,195 @@ export function draftAnswer(ctx, env, question) {
|
|
|
836
1402
|
const {C} = ctx;
|
|
837
1403
|
const TARGET = ctx.project.target;
|
|
838
1404
|
const TOKENS = ctx.project.core.tokenDefaults;
|
|
1405
|
+
const lex = partLexicon(ctx);
|
|
1406
|
+
/** Family names written in quotes, kept as typed: qq<n>qq in the text. */
|
|
1407
|
+
const quoted = /** @type {string[]} */ ([]);
|
|
839
1408
|
let q = question
|
|
840
1409
|
.normalize('NFKC')
|
|
1410
|
+
// Markup and comment text are not part of the ask.
|
|
1411
|
+
.replace(/<(script|style)\b[^>]*>[\s\S]*?<\/\1\s*>/gi, ' ')
|
|
1412
|
+
.replace(/<\/?[a-z][^>]*>/gi, ' ')
|
|
1413
|
+
.replace(/\*\/[\s\S]*?\/\*/g, ' ')
|
|
1414
|
+
.replace(/\/\*[\s\S]*?\*\//g, ' ')
|
|
1415
|
+
.replace(
|
|
1416
|
+
/(?<=\bfont(?:[ -]family)?\s*:?\s*)'((?:[^'\\]|\\.){2,40})'|["\u201c]([^"\u201d\n]{2,40})["\u201d]/gi,
|
|
1417
|
+
(m, a, b, off, all) => {
|
|
1418
|
+
const name = String(a ?? b)
|
|
1419
|
+
.replace(/\\(.)/g, '$1')
|
|
1420
|
+
.trim();
|
|
1421
|
+
// Only a font name after a font word ("font 'O\'Reilly Sans'",
|
|
1422
|
+
// headings use "Playfair Display") is kept as typed; other quoted
|
|
1423
|
+
// text is read as words.
|
|
1424
|
+
const fontWord =
|
|
1425
|
+
a != null ||
|
|
1426
|
+
/\b(font(?:[ -]family)?|typeface|family|uses?)\s*:?\s*$/i.test(
|
|
1427
|
+
String(all).slice(Math.max(0, off - 30), off),
|
|
1428
|
+
) ||
|
|
1429
|
+
/^\s*(font|typeface)\b/i.test(String(all).slice(off + m.length));
|
|
1430
|
+
if (!fontWord || !/^[A-Za-z][A-Za-z0-9 '.-]{1,38}$/.test(name))
|
|
1431
|
+
return m;
|
|
1432
|
+
quoted.push(name);
|
|
1433
|
+
return ` qq${quoted.length - 1}qq `;
|
|
1434
|
+
},
|
|
1435
|
+
)
|
|
1436
|
+
// Each line of a list is its own ask: a "no" on one line never reaches
|
|
1437
|
+
// the next.
|
|
1438
|
+
.replace(/^[ \t]*(?:[-*\u2022\u25e6]|\d+[.)])[ \t]+/gm, '')
|
|
1439
|
+
.replace(/\s*[\r\n]+\s*/g, ' ; ')
|
|
1440
|
+
// "1) square corners 2) no shadows": a marker is a break, never a
|
|
1441
|
+
// value. "N)" is a marker anywhere; "N." only at the start or after a
|
|
1442
|
+
// break, so "radius 8. Shadows off." keeps its 8.
|
|
1443
|
+
.replace(/(^|\s)\d{1,2}\)(?=\s)/g, ' ; ')
|
|
1444
|
+
.replace(/(^|;)\s*\d{1,2}\.(?=\s)/g, ' ; ')
|
|
1445
|
+
// "primary=#7c3aed radius=10": each key=value pair is its own ask.
|
|
1446
|
+
.replace(/\s+(?=[a-z][\w-]*\s*=\s*\S)/gi, ' ; ')
|
|
841
1447
|
.replace(/\p{Cc}/gu, ' ')
|
|
842
1448
|
// Code-shaped asks: camelCase keys, JSON and CSS punctuation, dotted
|
|
843
1449
|
// paths ("primaryColor=#3b82f6", {"accent": ...}, theme.colors.primary).
|
|
1450
|
+
// Font names keep their words: "JetBrains" is one word, and the "Sans"
|
|
1451
|
+
// of "IBM Plex Sans" is not the French "without".
|
|
1452
|
+
.replace(/\bJetBrains\b/g, 'Jetbrains')
|
|
1453
|
+
.replace(/(?<=\b[A-Z][\w-]*\s)Sans\b/g, 'Sanz')
|
|
1454
|
+
.replace(/\bNaN/g, 'nan')
|
|
844
1455
|
.replace(/([a-z])([A-Z])/g, '$1 $2')
|
|
845
1456
|
.replace(/[{}"`]/g, ' ')
|
|
846
1457
|
.replace(/(?<=[a-z])\.(?=[a-z])/gi, ' ')
|
|
847
1458
|
.replace(/(?<![\w-])\.(?=[a-z])/gi, ' ')
|
|
848
1459
|
.replace(/\s*=\s*/g, ' ')
|
|
1460
|
+
.replace(/\bon\s*:\s*/g, 'on ')
|
|
1461
|
+
// Near-white and near-black are their own colors.
|
|
1462
|
+
.replace(/\boff[- ]?white\b/gi, '#fafafa')
|
|
1463
|
+
.replace(/\boff[- ]?black\b/gi, '#111111')
|
|
1464
|
+
// "match the header color to the sidebar": the first part is the one to
|
|
1465
|
+
// change.
|
|
1466
|
+
.replace(
|
|
1467
|
+
/\bmatch\s+(?:the\s+)?(.+?)\s+to\s+(?:the\s+)?[a-z][a-z -]*?(?=\s*[(,;.]|\s*$)/gi,
|
|
1468
|
+
'$1',
|
|
1469
|
+
)
|
|
1470
|
+
// "no more than 2px": a limit, the number itself.
|
|
1471
|
+
.replace(/\b(?:no|not) more than\s+|\bat most\s+|\bmax(?:imum)? of\s+/g, '')
|
|
1472
|
+
// Numbers written as words are numbers.
|
|
1473
|
+
.replace(NUMBER_WORDS_RE, m => numberWord(m))
|
|
1474
|
+
// "8 or so px", "about 8 px": the number.
|
|
1475
|
+
.replace(/\b(\d+(?:\.\d+)?)\s+or so\s+(?=px|rem|em|pixels?)/g, '$1 ')
|
|
1476
|
+
// "0.5 rem", "14 px": a number and its unit are one length.
|
|
1477
|
+
.replace(/\b(\d+(?:\.\d+)?)\s+(px|rem|em|pt|vh|vw|ch)\b/gi, '$1$2')
|
|
1478
|
+
// Typography words for the properties they name.
|
|
1479
|
+
.replace(
|
|
1480
|
+
/\btabular (numbers|numerals|figures|nums)\b/g,
|
|
1481
|
+
'font-variant-numeric: tabular-nums',
|
|
1482
|
+
)
|
|
1483
|
+
.replace(
|
|
1484
|
+
/\bbalance (?:the )?(?:(\w+) )?(?:line breaks|lines|wrapping)\b/g,
|
|
1485
|
+
'$1 text-wrap: balance',
|
|
1486
|
+
)
|
|
1487
|
+
// "hover does nothing visible": the effect is too subtle.
|
|
1488
|
+
.replace(
|
|
1489
|
+
/\b(?:does|do) nothing(?: visible)?\b|\bnothing happens\b/g,
|
|
1490
|
+
'is too subtle',
|
|
1491
|
+
)
|
|
1492
|
+
// "I can barely see the borders": too faint.
|
|
1493
|
+
.replace(
|
|
1494
|
+
/\b(?:i )?(?:can )?(?:barely|hardly) see (?:the )?(\w+)/g,
|
|
1495
|
+
'$1 too faint',
|
|
1496
|
+
)
|
|
1497
|
+
// "11pt": points as pixels (a point is 4/3 of a pixel).
|
|
1498
|
+
.replace(
|
|
1499
|
+
/\b(\d+(?:\.\d+)?)pt\b/gi,
|
|
1500
|
+
(_, n) => `${Math.round((Number(n) * 4) / 3)}px`,
|
|
1501
|
+
)
|
|
1502
|
+
// "a 1px border instead of a shadow": no shadow, and the border.
|
|
1503
|
+
.replace(
|
|
1504
|
+
/^(.*?)\binstead of (?:a |an |the )?([a-z]+(?: [a-z]+)?)\b/gim,
|
|
1505
|
+
(m, a, b) => (a.trim() ? `no ${b} ; ${a}` : m),
|
|
1506
|
+
)
|
|
1507
|
+
// "why are my headings not bold": the complaint asks for bold.
|
|
1508
|
+
.replace(/\bwhy (?:is|are|isn'?t|aren'?t)\b(.*?)\bnot\s+/gi, 'make$1 ')
|
|
1509
|
+
// "button padding 8", "radius 10": a bare number there is pixels.
|
|
1510
|
+
.replace(
|
|
1511
|
+
/\b(padding|radius|corners|gap|margin)(\s*:?\s*)(\d+(?:\.\d+)?)(?![\d.%\w])/gi,
|
|
1512
|
+
'$1$2$3px',
|
|
1513
|
+
)
|
|
849
1514
|
.toLowerCase()
|
|
850
|
-
.replace(/[\u2018\u2019]/g, "'")
|
|
1515
|
+
.replace(/[\u2018\u2019]/g, "'")
|
|
1516
|
+
// CSS property names read as their words.
|
|
1517
|
+
.replace(
|
|
1518
|
+
/\b(letter|line|font)-(spacing|height|size|weight|family)\b/g,
|
|
1519
|
+
'$1 $2',
|
|
1520
|
+
)
|
|
1521
|
+
// "12 pixels", "8 px" are lengths.
|
|
1522
|
+
.replace(/\b(\d+(?:\.\d+)?)\s*(?:pixels?|px)\b/g, '$1px')
|
|
1523
|
+
// A drop shadow is a shadow, not a "drop".
|
|
1524
|
+
.replace(/\bdrop[- ]shadows?\b(?!\s*\()/g, 'shadow')
|
|
1525
|
+
// "x 0, y 4, blur 6, spread -1, rgba(...)": one shadow value.
|
|
1526
|
+
.replace(
|
|
1527
|
+
/\bx\s*:?\s*(-?\d+)(?:px)?\s*,?\s*y\s*:?\s*(-?\d+)(?:px)?(?:\s*,?\s*blur\s*:?\s*(-?\d+)(?:px)?)?(?:\s*,?\s*spread\s*:?\s*(-?\d+)(?:px)?)?\s*,?\s*(#[0-9a-f]{3,8}|(?:rgba?|hsla?)\([^)]*\))/g,
|
|
1528
|
+
(_, x, y, b, sp, col) =>
|
|
1529
|
+
[x, y, b, sp]
|
|
1530
|
+
.filter(v => v != null)
|
|
1531
|
+
.map(v => (v === '0' ? '0' : `${v}px`))
|
|
1532
|
+
.join(' ') + ` ${col}`,
|
|
1533
|
+
)
|
|
1534
|
+
// A shadow's layers stay one value: the comma between them is not a
|
|
1535
|
+
// clause break.
|
|
1536
|
+
.replace(
|
|
1537
|
+
/(\)|#[0-9a-f]{3,8}\b)\s*,\s*(?=(?:inset\s+)?-?\d+(?:px)?\s+-?\d)/g,
|
|
1538
|
+
'$1\u2e34 ',
|
|
1539
|
+
)
|
|
1540
|
+
// "font-family: Georgia, serif": the font list is one value.
|
|
1541
|
+
.replace(
|
|
1542
|
+
/(\bfont[- ]family\s*:?\s*[^,;]+?)\s*,\s*(?=(?:serif|sans-serif|monospace|system-ui|cursive|ui-monospace|ui-sans-serif|ui-serif)\b)/g,
|
|
1543
|
+
'$1\u2e34 ',
|
|
1544
|
+
)
|
|
1545
|
+
// "rounder? or maybe not. actually yes": the ask stands.
|
|
1546
|
+
.replace(
|
|
1547
|
+
/[?.!]?\s*\b(?:or )?maybe not\b[.?!,]*\s*(?:actually|ok(?:ay)?|no wait)?,?\s*(?:yes|do it)\b[.!]*/g,
|
|
1548
|
+
'. ',
|
|
1549
|
+
)
|
|
1550
|
+
// "the gray text fails contrast": gray text is the secondary text,
|
|
1551
|
+
// when no color is typed for it.
|
|
1552
|
+
.replace(
|
|
1553
|
+
/\b(gr[ae]y|muted) text\b(?![^;,]*(#[0-9a-f]{3}|\brgb|\bhsl))/g,
|
|
1554
|
+
'secondary text',
|
|
1555
|
+
)
|
|
1556
|
+
// "replace the shadow on cards with a border": no shadow, and a border.
|
|
1557
|
+
.replace(
|
|
1558
|
+
/\b(?:replace|swap)\s+(?:out\s+)?(?:the\s+)?((?:shadows?|borders?|gradients?|underlines?|outlines?)\b[^,;]*?)\s+(?:with|for)\s+/g,
|
|
1559
|
+
'no $1 ; ',
|
|
1560
|
+
)
|
|
1561
|
+
// "swap Inter for Manrope", "replace red with #e11d48": B is the ask,
|
|
1562
|
+
// but only when A and B are the same kind of value. "Replace the shadow
|
|
1563
|
+
// with a border" keeps both words.
|
|
1564
|
+
.replace(
|
|
1565
|
+
/\b(?:swap|replace|switch)\s+(?:out\s+)?(?:the\s+)?([^,;]+?)\s+(?:for|with)\s+(?=(#[0-9a-f]{3,8}\b|[a-z][\w-]*(?:\s+[a-z][\w-]*)?))/g,
|
|
1566
|
+
(m, a, b) => {
|
|
1567
|
+
const kind = valueKind(a) ?? null;
|
|
1568
|
+
const bKind = valueKind(b) ?? valueKind(b.split(/\s+/)[0]);
|
|
1569
|
+
return kind && kind === bKind ? 'use ' : m;
|
|
1570
|
+
},
|
|
1571
|
+
)
|
|
1572
|
+
// "bg #fff text #000": a new color after a color starts a new ask.
|
|
1573
|
+
.replace(
|
|
1574
|
+
/(#[0-9a-f]{3,8}|\))\s+(?!(?:to|into|and|or|vs|than|then)\b)(?=[a-z][\w-]*\s*:?\s*(?:#[0-9a-f]{3,8}\b|(?:rgba?|hsla?|oklch)\())/g,
|
|
1575
|
+
'$1 ; ',
|
|
1576
|
+
)
|
|
1577
|
+
// "#0d6efd primary": the color belongs to the word after it, when that
|
|
1578
|
+
// word has no color of its own.
|
|
1579
|
+
.replace(
|
|
1580
|
+
/(#[0-9a-f]{3,8}|(?:rgba?|hsla?|oklch)\([^)]*\))\s+(primary|secondary|accent|brand|danger|error|success|warning|info|neutral|bg|background|text|border|links?)\b(?!\s*:?\s*(?:#|rgba?\(|hsla?\(|oklch\())/g,
|
|
1581
|
+
'$2 $1',
|
|
1582
|
+
);
|
|
851
1583
|
for (const [re, w] of TRANSLATE) q = q.replace(re, w);
|
|
852
1584
|
q = q
|
|
1585
|
+
// "bordes redondeados": rounded edges are corners.
|
|
1586
|
+
.replace(/\bborders?\s+rounded\b/g, 'rounded corners')
|
|
853
1587
|
.replace(/\bbutton-s\b/g, 'buttons')
|
|
854
|
-
.replace(/[a-z]+/g, w => corrected(w))
|
|
1588
|
+
.replace(/[a-z]+/g, w => corrected(w, lex.vocab))
|
|
1589
|
+
// "buttons, but not bold": the "not" is about the buttons.
|
|
1590
|
+
.replace(
|
|
1591
|
+
/,?\s*\bbut not\s+(?=(bold|italic|uppercase|rounded|round|shadowed|underlined|bordered|faded|dark|light|bright|big|small|too \w+)\b)/g,
|
|
1592
|
+
' not ',
|
|
1593
|
+
)
|
|
855
1594
|
.replace(/\b(everything|everywhere|all) but\b/g, '$1 except')
|
|
856
1595
|
.replace(
|
|
857
1596
|
/\b(apart from|other than|excluding|but not (on|in|for)|but not)\b/g,
|
|
@@ -859,7 +1598,336 @@ export function draftAnswer(ctx, env, question) {
|
|
|
859
1598
|
)
|
|
860
1599
|
.replace(/\s+/g, ' ')
|
|
861
1600
|
.trim();
|
|
862
|
-
const clauses = clausesOf(q);
|
|
1601
|
+
const clauses = clausesOf(q, lex.parts);
|
|
1602
|
+
for (const c of clauses) {
|
|
1603
|
+
c.quoted = [...c.text.matchAll(/qq(\d+)qq/g)].map(
|
|
1604
|
+
m => quoted[Number(m[1])],
|
|
1605
|
+
);
|
|
1606
|
+
c.text = c.text
|
|
1607
|
+
.replace(/\s*qq\d+qq\s*/g, ' font ')
|
|
1608
|
+
.replace(/\s+/g, ' ')
|
|
1609
|
+
.trim();
|
|
1610
|
+
if (c.quoted.length && !c.aspects.includes('family'))
|
|
1611
|
+
c.aspects.push('family');
|
|
1612
|
+
}
|
|
1613
|
+
// The generic family after a quoted one is its fallback, not a second ask.
|
|
1614
|
+
for (let i = 1; i < clauses.length; i++)
|
|
1615
|
+
if (
|
|
1616
|
+
clauses[i - 1].quoted?.length &&
|
|
1617
|
+
/^(monospace|mono|sans ?-?serif|serif|system-ui|cursive)$/.test(
|
|
1618
|
+
clauses[i].text,
|
|
1619
|
+
)
|
|
1620
|
+
) {
|
|
1621
|
+
clauses[i].text = '';
|
|
1622
|
+
clauses[i].aspects = [];
|
|
1623
|
+
}
|
|
1624
|
+
for (const c of clauses)
|
|
1625
|
+
if (!c.aspects.includes('shadow') && shadowIn(c.text))
|
|
1626
|
+
c.aspects.push('shadow');
|
|
1627
|
+
// "color #000" after a clause about borders is the border's color.
|
|
1628
|
+
for (let i = 1; i < clauses.length; i++) {
|
|
1629
|
+
const c = clauses[i];
|
|
1630
|
+
const word = c.text
|
|
1631
|
+
.replace(/#[0-9a-f]+|\b(?:rgba?|hsla?|oklch)\([^)]*\)/g, '')
|
|
1632
|
+
.trim();
|
|
1633
|
+
if (
|
|
1634
|
+
c.colors.length &&
|
|
1635
|
+
/^colou?rs?:?$/.test(word) &&
|
|
1636
|
+
clauses[i - 1].aspects.length
|
|
1637
|
+
) {
|
|
1638
|
+
c.aspects = [...clauses[i - 1].aspects.filter(a => a !== 'size')];
|
|
1639
|
+
c.parts = clauses[i - 1].parts.map(p => ({...p}));
|
|
1640
|
+
}
|
|
1641
|
+
}
|
|
1642
|
+
// "success badge", "error toasts": a value of the part's variant, type
|
|
1643
|
+
// or status right before the part.
|
|
1644
|
+
for (const c of clauses)
|
|
1645
|
+
for (const p of c.parts) {
|
|
1646
|
+
const member = FAMILIES[p.on] ? FAMILIES[p.on][0] : p.on;
|
|
1647
|
+
if (p.when || !C.MAP[member]) continue;
|
|
1648
|
+
const vals = C.variantValues(member);
|
|
1649
|
+
const nouns = lex.parts.filter(([, x]) => x.on === p.on && !x.when);
|
|
1650
|
+
for (const m of c.text.matchAll(/\b([a-z]+)\s+([a-z]+)\b/g)) {
|
|
1651
|
+
const key = ['variant', 'type', 'status', 'tone', 'color'].find(k =>
|
|
1652
|
+
(vals[k] ?? []).includes(m[1]),
|
|
1653
|
+
);
|
|
1654
|
+
if (key && nouns.some(([re]) => re.test(` ${m[2]} `))) {
|
|
1655
|
+
p.when = `${key}:${m[1]}`;
|
|
1656
|
+
break;
|
|
1657
|
+
}
|
|
1658
|
+
}
|
|
1659
|
+
}
|
|
1660
|
+
// "cards and dialogs with no shadow", "tooltips and toasts black": parts
|
|
1661
|
+
// listed before the ask all take it.
|
|
1662
|
+
for (let i = 0; i < clauses.length - 1; i++) {
|
|
1663
|
+
const c = clauses[i];
|
|
1664
|
+
const onlyParts = (/** @type {Clause} */ x) =>
|
|
1665
|
+
x.parts.length &&
|
|
1666
|
+
!x.aspects.length &&
|
|
1667
|
+
!x.colors.length &&
|
|
1668
|
+
!x.lengths.length &&
|
|
1669
|
+
!x.except &&
|
|
1670
|
+
!x.dir &&
|
|
1671
|
+
!lex.parts
|
|
1672
|
+
.reduce((t, [re]) => t.replace(re, ' '), ` ${x.text} `)
|
|
1673
|
+
.replace(/\b(the|a|an|all|every|both|my|our)\b/g, ' ')
|
|
1674
|
+
.trim();
|
|
1675
|
+
if (!onlyParts(c)) continue;
|
|
1676
|
+
let j = i + 1;
|
|
1677
|
+
while (j < clauses.length && onlyParts(clauses[j])) j++;
|
|
1678
|
+
const ask = clauses[j];
|
|
1679
|
+
if (
|
|
1680
|
+
!ask ||
|
|
1681
|
+
ask.except ||
|
|
1682
|
+
!(
|
|
1683
|
+
ask.aspects.length ||
|
|
1684
|
+
ask.colors.length ||
|
|
1685
|
+
ask.lengths.length ||
|
|
1686
|
+
ask.dir
|
|
1687
|
+
)
|
|
1688
|
+
)
|
|
1689
|
+
continue;
|
|
1690
|
+
const listed = clauses.slice(i, j).flatMap(x => x.parts);
|
|
1691
|
+
ask.parts = [...listed.map(p => ({...p})), ...ask.parts];
|
|
1692
|
+
for (const x of clauses.slice(i, j)) {
|
|
1693
|
+
x.parts = [];
|
|
1694
|
+
x.text = '';
|
|
1695
|
+
}
|
|
1696
|
+
i = j;
|
|
1697
|
+
}
|
|
1698
|
+
// "less padding on cards but more on buttons": a part with only a
|
|
1699
|
+
// direction takes the aspect of the clause before it.
|
|
1700
|
+
for (let i = 1; i < clauses.length; i++) {
|
|
1701
|
+
const c = clauses[i];
|
|
1702
|
+
const prev = clauses[i - 1];
|
|
1703
|
+
if (
|
|
1704
|
+
c.parts.length &&
|
|
1705
|
+
c.dir &&
|
|
1706
|
+
!c.aspects.length &&
|
|
1707
|
+
!c.colors.length &&
|
|
1708
|
+
prev.aspects.length
|
|
1709
|
+
)
|
|
1710
|
+
c.aspects = [...prev.aspects];
|
|
1711
|
+
}
|
|
1712
|
+
// "thicker focus outline, 4px": a clause that is only a length is the
|
|
1713
|
+
// value of the clause before it, and the typed value wins over the
|
|
1714
|
+
// direction word.
|
|
1715
|
+
for (let i = 1; i < clauses.length; i++) {
|
|
1716
|
+
const c = clauses[i];
|
|
1717
|
+
const prev = clauses[i - 1];
|
|
1718
|
+
if (
|
|
1719
|
+
c.lengths.length &&
|
|
1720
|
+
!c.parts.length &&
|
|
1721
|
+
!c.aspects.length &&
|
|
1722
|
+
!c.colors.length &&
|
|
1723
|
+
prev.aspects.length &&
|
|
1724
|
+
c.text
|
|
1725
|
+
.replace(
|
|
1726
|
+
/\b(at least|at most|about|around|roughly|or so|min(imum)?|max(imum)?)\b/g,
|
|
1727
|
+
'',
|
|
1728
|
+
)
|
|
1729
|
+
.replace(/-?\d*\.?\d+(px|rem|em)/g, '')
|
|
1730
|
+
.trim() === ''
|
|
1731
|
+
) {
|
|
1732
|
+
prev.lengths = [...c.lengths, ...prev.lengths];
|
|
1733
|
+
prev.dir = null;
|
|
1734
|
+
prev.text = `${prev.text} ${c.lengths.join(' ')}`;
|
|
1735
|
+
c.lengths = [];
|
|
1736
|
+
c.text = '';
|
|
1737
|
+
}
|
|
1738
|
+
}
|
|
1739
|
+
// "every part bold except body text": the body is left as it is, so the
|
|
1740
|
+
// bold goes to the headings, not the body's weight.
|
|
1741
|
+
for (let i = 0; i < clauses.length - 1; i++) {
|
|
1742
|
+
const c = clauses[i];
|
|
1743
|
+
const next = clauses[i + 1];
|
|
1744
|
+
if (
|
|
1745
|
+
!c.parts.length &&
|
|
1746
|
+
c.aspects.includes('weight') &&
|
|
1747
|
+
next.except &&
|
|
1748
|
+
next.parts.some(p => p.on === 'body')
|
|
1749
|
+
) {
|
|
1750
|
+
c.parts = [{on: 'heading'}];
|
|
1751
|
+
next.parts = [];
|
|
1752
|
+
next.text = '';
|
|
1753
|
+
}
|
|
1754
|
+
}
|
|
1755
|
+
// "no shadows on cards and dialogs": a clause that only names a part
|
|
1756
|
+
// takes the ask of the clause before it.
|
|
1757
|
+
for (let i = 1; i < clauses.length; i++) {
|
|
1758
|
+
const c = clauses[i];
|
|
1759
|
+
const prev = clauses[i - 1];
|
|
1760
|
+
if (
|
|
1761
|
+
c.parts.length &&
|
|
1762
|
+
!c.aspects.length &&
|
|
1763
|
+
!c.colors.length &&
|
|
1764
|
+
!c.lengths.length &&
|
|
1765
|
+
!c.except &&
|
|
1766
|
+
prev.aspects.length &&
|
|
1767
|
+
prev.parts.length &&
|
|
1768
|
+
!lex.parts
|
|
1769
|
+
.reduce((t, [re]) => t.replace(re, ' '), ` ${c.text} `)
|
|
1770
|
+
.replace(/\b(the|a|an|all|every|on|for|too|both)\b/g, ' ')
|
|
1771
|
+
.trim()
|
|
1772
|
+
) {
|
|
1773
|
+
c.aspects = [...prev.aspects];
|
|
1774
|
+
c.neg = prev.neg;
|
|
1775
|
+
c.dir ??= prev.dir;
|
|
1776
|
+
c.text = `${prev.text.replace(/\bon\b.*$/, '')} ${c.text}`;
|
|
1777
|
+
}
|
|
1778
|
+
}
|
|
1779
|
+
// "the cards and the dialogs both need 16px radius": a clause that only
|
|
1780
|
+
// names a part, before one that says what to change, takes that ask
|
|
1781
|
+
// ("h1, h2, h3 { … }": read from the last, so each takes it in turn).
|
|
1782
|
+
for (let i = clauses.length - 2; i >= 0; i--) {
|
|
1783
|
+
const c = clauses[i];
|
|
1784
|
+
const next = clauses[i + 1];
|
|
1785
|
+
if (
|
|
1786
|
+
c.parts.length &&
|
|
1787
|
+
!c.aspects.length &&
|
|
1788
|
+
!c.colors.length &&
|
|
1789
|
+
!c.lengths.length &&
|
|
1790
|
+
!c.except &&
|
|
1791
|
+
next.aspects.length &&
|
|
1792
|
+
next.parts.length &&
|
|
1793
|
+
!lex.parts
|
|
1794
|
+
.reduce((t, [re]) => t.replace(re, ' '), ` ${c.text} `)
|
|
1795
|
+
.replace(/\b(the|a|an|all|every|on|for|both)\b/g, ' ')
|
|
1796
|
+
.trim()
|
|
1797
|
+
) {
|
|
1798
|
+
const parts = c.parts;
|
|
1799
|
+
Object.assign(c, {...next, parts, text: next.text});
|
|
1800
|
+
}
|
|
1801
|
+
}
|
|
1802
|
+
// "BORDER-RADIUS: 8PX; ON: CARD": a clause that is only "on <part>" names
|
|
1803
|
+
// the part of the clause before it.
|
|
1804
|
+
for (let i = 1; i < clauses.length; i++) {
|
|
1805
|
+
const c = clauses[i];
|
|
1806
|
+
if (
|
|
1807
|
+
c.parts.length &&
|
|
1808
|
+
!c.aspects.length &&
|
|
1809
|
+
/^on\b/.test(c.text) &&
|
|
1810
|
+
!clauses[i - 1].parts.length
|
|
1811
|
+
) {
|
|
1812
|
+
clauses[i - 1].parts = c.parts;
|
|
1813
|
+
c.parts = [];
|
|
1814
|
+
c.text = '';
|
|
1815
|
+
}
|
|
1816
|
+
}
|
|
1817
|
+
// "buttons feel heavy, lighten them up", "the hierarchy is flat, headings
|
|
1818
|
+
// need more weight": a clause that only describes the problem, before
|
|
1819
|
+
// one that says what to do, asks for nothing itself; the fix takes its
|
|
1820
|
+
// part and aspect when it names none.
|
|
1821
|
+
for (let i = 0; i < clauses.length - 1; i++) {
|
|
1822
|
+
const c = clauses[i];
|
|
1823
|
+
const next = clauses[i + 1];
|
|
1824
|
+
const describes =
|
|
1825
|
+
/\b(is|are|feels?|looks|seems?|fails?)\b/.test(c.text) &&
|
|
1826
|
+
/\b(too|so|very|really|kind of|feels?|seems?|fails?|cramped|flat|heavy|crowded|cluttered|busy|boring|bland|dull|harsh|loud|weak|hard|ugly|off)\b/.test(
|
|
1827
|
+
c.text,
|
|
1828
|
+
) &&
|
|
1829
|
+
!/\d/.test(c.text) &&
|
|
1830
|
+
!/^(make|set|use|give|add|remove|change|put)\b/.test(c.text) &&
|
|
1831
|
+
!/#[0-9a-f]{3,8}\b|\(/.test(c.text) &&
|
|
1832
|
+
!c.lengths.length;
|
|
1833
|
+
if (!describes || !(next.aspects.length || next.dir) || next.colors.length)
|
|
1834
|
+
continue;
|
|
1835
|
+
if (!next.aspects.length)
|
|
1836
|
+
next.aspects = c.aspects.filter(
|
|
1837
|
+
a => a !== 'shadow' || !/\bflat\b/.test(c.text),
|
|
1838
|
+
);
|
|
1839
|
+
if (!next.parts.length) next.parts = c.parts.map(p => ({...p}));
|
|
1840
|
+
next.text =
|
|
1841
|
+
`${next.text} ${c.text.replace(/\b(is|are|feels?|looks?|seems?)\b.*$/, '')}`.trim();
|
|
1842
|
+
if (/\bcontrast\b/.test(c.text)) next.text += ' contrast';
|
|
1843
|
+
c.text = '';
|
|
1844
|
+
c.parts = [];
|
|
1845
|
+
c.aspects = [];
|
|
1846
|
+
c.colors = [];
|
|
1847
|
+
}
|
|
1848
|
+
// "Arial everywhere", "code blocks should use Menlo": a family named with
|
|
1849
|
+
// its capitals is a font ask; so is the system font by name.
|
|
1850
|
+
for (const c of clauses)
|
|
1851
|
+
if (
|
|
1852
|
+
!c.aspects.includes('family') &&
|
|
1853
|
+
(systemFamilyIn(c.text, question) || OS_FONT.test(c.text))
|
|
1854
|
+
)
|
|
1855
|
+
c.aspects.push('family');
|
|
1856
|
+
// "make the divider 2px": a divider's length is its thickness.
|
|
1857
|
+
for (const c of clauses)
|
|
1858
|
+
if (
|
|
1859
|
+
c.parts.some(p => p.on === 'divider') &&
|
|
1860
|
+
!c.aspects.length &&
|
|
1861
|
+
c.lengths.length
|
|
1862
|
+
)
|
|
1863
|
+
c.aspects = ['size'];
|
|
1864
|
+
// "shadow opacity 0.2": the layer's alpha is the ask, not the layer.
|
|
1865
|
+
for (const c of clauses)
|
|
1866
|
+
if (
|
|
1867
|
+
/\b(shadows?|backgrounds?|bg|borders?|outlines?)\s+opacity\b/.test(c.text)
|
|
1868
|
+
)
|
|
1869
|
+
c.aspects = ['opacity'];
|
|
1870
|
+
// "the table ... a header" is the table's header row.
|
|
1871
|
+
if (/\b(tables?|rows?|zebra)\b/.test(q))
|
|
1872
|
+
for (const c of clauses)
|
|
1873
|
+
for (const p of c.parts)
|
|
1874
|
+
if (p.on === 'app-shell-header') p.on = 'table-header-cell';
|
|
1875
|
+
// A clause that is only a color ("brand blue, #0057ff") belongs to the
|
|
1876
|
+
// clause before it; a clause with any other word ("accent #fff") does not.
|
|
1877
|
+
for (let i = 1; i < clauses.length; i++) {
|
|
1878
|
+
const c = clauses[i];
|
|
1879
|
+
const rest = c.text
|
|
1880
|
+
.replace(/#[0-9a-f]+|\b(?:rgba?|hsla?|oklch)\([^)]*\)/g, '')
|
|
1881
|
+
.replace(/\b(the|a|an|it|its|is|like|please|pls|thanks|ok)\b/g, '')
|
|
1882
|
+
.trim();
|
|
1883
|
+
if (c.colors.length && !rest && !c.parts.length && !c.aspects.length) {
|
|
1884
|
+
clauses[i - 1].colors = [...c.colors, ...clauses[i - 1].colors];
|
|
1885
|
+
c.colors = [];
|
|
1886
|
+
c.text = '';
|
|
1887
|
+
}
|
|
1888
|
+
}
|
|
1889
|
+
// A clause that names a color the theme generates with no color ("LGTM
|
|
1890
|
+
// except the accent") gives that role to the next clause with only a
|
|
1891
|
+
// color ("make it #6d28d9"); so does "the purple" for the brand color.
|
|
1892
|
+
for (let i = 1; i < clauses.length; i++) {
|
|
1893
|
+
const c = clauses[i];
|
|
1894
|
+
const prev = clauses[i - 1];
|
|
1895
|
+
if (
|
|
1896
|
+
c.colors.length &&
|
|
1897
|
+
!c.parts.length &&
|
|
1898
|
+
!c.aspects.length &&
|
|
1899
|
+
!ROLE_WORDS.test(c.text) &&
|
|
1900
|
+
// The color before is one the question moves away from ("I hate the
|
|
1901
|
+
// purple"), or one for the other mode ("in light mode … in dark mode").
|
|
1902
|
+
(!prev.colors.length ||
|
|
1903
|
+
prev.neg ||
|
|
1904
|
+
/\b(hate|dislike|not a fan|tired of|sick of|too)\b/.test(prev.text) ||
|
|
1905
|
+
Boolean(c.mode && prev.mode && c.mode !== prev.mode)) &&
|
|
1906
|
+
!prev.parts.length
|
|
1907
|
+
) {
|
|
1908
|
+
const role =
|
|
1909
|
+
ROLE_WORDS.exec(prev.text)?.[0] ??
|
|
1910
|
+
(new RegExp(`\\bthe (${Object.keys(HUES).join('|')})\\b`).test(
|
|
1911
|
+
prev.text,
|
|
1912
|
+
)
|
|
1913
|
+
? 'accent'
|
|
1914
|
+
: null);
|
|
1915
|
+
if (role) {
|
|
1916
|
+
c.text = `${role} ${c.text}`;
|
|
1917
|
+
// "the danger red is too bright, use #b91c1c": the typed color is
|
|
1918
|
+
// the target, so the clause before it asks for nothing of its own.
|
|
1919
|
+
if (
|
|
1920
|
+
!/#[0-9a-f]{3,8}\b/.test(prev.text) &&
|
|
1921
|
+
prev.dir &&
|
|
1922
|
+
!prev.parts.length
|
|
1923
|
+
) {
|
|
1924
|
+
prev.text = '';
|
|
1925
|
+
prev.colors = [];
|
|
1926
|
+
prev.aspects = [];
|
|
1927
|
+
}
|
|
1928
|
+
}
|
|
1929
|
+
}
|
|
1930
|
+
}
|
|
863
1931
|
// "nav items" in a question about the sidebar are the side nav's; an
|
|
864
1932
|
// underline on tabs is the tab indicator.
|
|
865
1933
|
const side = /\b(side ?nav|sidebar|side ?panel)\b/.test(q);
|
|
@@ -882,7 +1950,12 @@ export function draftAnswer(ctx, env, question) {
|
|
|
882
1950
|
/\b(darker|lighter|brighter|colou?r(ed)?)\b/.test(c.text) ||
|
|
883
1951
|
(!c.neg && toneIn(c.text)))
|
|
884
1952
|
)
|
|
885
|
-
c.aspects.push(
|
|
1953
|
+
c.aspects.push(
|
|
1954
|
+
// "headings red": a part that is only text has a text color.
|
|
1955
|
+
c.parts.every(p => ['heading', 'link'].includes(p.on))
|
|
1956
|
+
? 'text'
|
|
1957
|
+
: 'background',
|
|
1958
|
+
);
|
|
886
1959
|
};
|
|
887
1960
|
fillAspect();
|
|
888
1961
|
for (let i = 0; i < clauses.length; i++) {
|
|
@@ -899,6 +1972,17 @@ export function draftAnswer(ctx, env, question) {
|
|
|
899
1972
|
!c.except &&
|
|
900
1973
|
// "per the brand guide" names no part; "accent text" does.
|
|
901
1974
|
!(ROLE_WORDS.test(c.text) && !c.aspects.length) &&
|
|
1975
|
+
// "Circular font" after "12px cards" is the theme's font.
|
|
1976
|
+
!(c.aspects.length && c.aspects.every(a => a === 'family')) &&
|
|
1977
|
+
// "serif headings, no shadows": a type part does not take a shadow,
|
|
1978
|
+
// corner or border ask.
|
|
1979
|
+
!(
|
|
1980
|
+
before.parts.every(p => ['heading', 'body', 'code'].includes(p.on)) &&
|
|
1981
|
+
c.aspects.length &&
|
|
1982
|
+
c.aspects.every(a =>
|
|
1983
|
+
['shadow', 'corners', 'border', 'spacing'].includes(a),
|
|
1984
|
+
)
|
|
1985
|
+
) &&
|
|
902
1986
|
(c.aspects.length || c.colors.length || c.lengths.length)
|
|
903
1987
|
) {
|
|
904
1988
|
c.parts = before.parts.map(p => ({...p}));
|
|
@@ -924,24 +2008,48 @@ export function draftAnswer(ctx, env, question) {
|
|
|
924
2008
|
(!c.parts.length || (!prev.parts.length && !prev.aspects.length))
|
|
925
2009
|
)
|
|
926
2010
|
c.mode = prev.mode;
|
|
927
|
-
// "
|
|
928
|
-
// clause
|
|
2011
|
+
// "on focus, inputs get a 2px outline": a clause that only names a state
|
|
2012
|
+
// gives it to the clause after it.
|
|
929
2013
|
if (
|
|
930
|
-
|
|
931
|
-
|
|
2014
|
+
!c.state &&
|
|
2015
|
+
prev?.state &&
|
|
2016
|
+
!prev.parts.length &&
|
|
2017
|
+
!prev.aspects.length &&
|
|
2018
|
+
c.parts.length
|
|
2019
|
+
)
|
|
2020
|
+
c.state = prev.state;
|
|
2021
|
+
}
|
|
2022
|
+
// "when hovering a card, lift it with a bigger shadow": a clause that only
|
|
2023
|
+
// names a part and a state, beside clauses that say what to change, asks
|
|
2024
|
+
// for nothing of its own.
|
|
2025
|
+
for (const c of clauses)
|
|
2026
|
+
if (
|
|
2027
|
+
c.parts.length &&
|
|
2028
|
+
c.state &&
|
|
932
2029
|
!c.aspects.length &&
|
|
933
|
-
c.colors.length &&
|
|
934
|
-
c.
|
|
935
|
-
|
|
936
|
-
.trim()
|
|
937
|
-
.split(/\s+/)
|
|
938
|
-
.filter(Boolean).length <= 1
|
|
2030
|
+
!c.colors.length &&
|
|
2031
|
+
!c.lengths.length &&
|
|
2032
|
+
clauses.some(o => o !== c && o.aspects.length)
|
|
939
2033
|
) {
|
|
940
|
-
|
|
941
|
-
c.colors = [];
|
|
2034
|
+
c.parts = [];
|
|
942
2035
|
c.text = '';
|
|
943
2036
|
}
|
|
2037
|
+
// "only in dark mode, …": a clause that only names a mode scopes every
|
|
2038
|
+
// clause after it.
|
|
2039
|
+
for (let i = 0; i < clauses.length; i++) {
|
|
2040
|
+
const c = clauses[i];
|
|
2041
|
+
if (c.mode && !c.parts.length && !c.aspects.length && !c.colors.length)
|
|
2042
|
+
for (const o of clauses.slice(i + 1)) o.mode ??= c.mode;
|
|
944
2043
|
}
|
|
2044
|
+
// The tab's text is on the tab, not on its underline.
|
|
2045
|
+
for (const c of clauses)
|
|
2046
|
+
for (const p of c.parts)
|
|
2047
|
+
if (
|
|
2048
|
+
p.on === 'tab-indicator' &&
|
|
2049
|
+
c.aspects.includes('text') &&
|
|
2050
|
+
!/\bunderline|indicator\b/.test(c.text)
|
|
2051
|
+
)
|
|
2052
|
+
p.on = 'tab';
|
|
945
2053
|
fillAspect();
|
|
946
2054
|
const modal = env.data.mode === 'both';
|
|
947
2055
|
const modeOf = (/** @type {Clause} */ c) =>
|
|
@@ -963,6 +2071,44 @@ export function draftAnswer(ctx, env, question) {
|
|
|
963
2071
|
env.base[mode]?.[token] ?? String(TOKENS[token] ?? '');
|
|
964
2072
|
/** The member a group's checks read. @param {string} on */
|
|
965
2073
|
const one = on => (FAMILIES[on] ? FAMILIES[on][0] : on);
|
|
2074
|
+
/**
|
|
2075
|
+
* Steps for a color how works out from the one a token has now. On a
|
|
2076
|
+
* theme with both modes there is one step per mode, each from that mode's
|
|
2077
|
+
* own value, so a change made for light never lands on dark; with the
|
|
2078
|
+
* clause's mode, only that one. A mode whose value would not change gets
|
|
2079
|
+
* no step.
|
|
2080
|
+
* @param {string} token the token whose value the new color starts from
|
|
2081
|
+
* @param {string} thing what the step sets (the token, or a property)
|
|
2082
|
+
* @param {Record<string, string | undefined>} flags
|
|
2083
|
+
* @param {(now: string, mode: 'light' | 'dark') => string | null} fn
|
|
2084
|
+
* @param {Clause} c
|
|
2085
|
+
* @returns {Step[]}
|
|
2086
|
+
*/
|
|
2087
|
+
const perMode = (token, thing, flags, fn, c) => {
|
|
2088
|
+
const modes = /** @type {Array<'light' | 'dark'>} */ (
|
|
2089
|
+
c.mode && modal
|
|
2090
|
+
? [c.mode]
|
|
2091
|
+
: modal
|
|
2092
|
+
? ['light', 'dark']
|
|
2093
|
+
: [env.data.mode === 'dark-only' ? 'dark' : 'light']
|
|
2094
|
+
);
|
|
2095
|
+
/** @type {Step[]} */
|
|
2096
|
+
const out = [];
|
|
2097
|
+
for (const m of modes) {
|
|
2098
|
+
const now = current(token, m);
|
|
2099
|
+
const v = fn(now, m);
|
|
2100
|
+
if (v && v.toLowerCase() !== now.toLowerCase())
|
|
2101
|
+
out.push(set(thing, v, {...flags, ...(modal ? {mode: m} : {})}));
|
|
2102
|
+
}
|
|
2103
|
+
return out;
|
|
2104
|
+
};
|
|
2105
|
+
/** How the mode of a set of per-mode steps reads in a sentence. @param {Step[]} steps */
|
|
2106
|
+
const modesSaid = steps =>
|
|
2107
|
+
modal && steps.length
|
|
2108
|
+
? steps.length > 1
|
|
2109
|
+
? ', each mode from its own value'
|
|
2110
|
+
: ` in ${steps[0].mode} mode only (the other mode keeps its value)`
|
|
2111
|
+
: '';
|
|
966
2112
|
/**
|
|
967
2113
|
* The state a part takes for a state word, as `set` names it.
|
|
968
2114
|
* @param {string} on @param {string} word
|
|
@@ -970,12 +2116,8 @@ export function draftAnswer(ctx, env, question) {
|
|
|
970
2116
|
const stateFor = (on, word) => {
|
|
971
2117
|
const t = TARGET.get(one(on));
|
|
972
2118
|
const states = [...(t?.states ?? []), ...COMMON_STATES];
|
|
973
|
-
if (word === 'focus')
|
|
974
|
-
|
|
975
|
-
for (const s of ['focus-within', 'focus-visible', 'focus'])
|
|
976
|
-
if (conds.includes(`:${s}`)) return s;
|
|
977
|
-
return 'focus-visible';
|
|
978
|
-
}
|
|
2119
|
+
if (word === 'focus')
|
|
2120
|
+
return focusStateOf(/** @type {any} */ ({C}), one(on)) ?? 'focus-visible';
|
|
979
2121
|
if (word === 'invalid') return null;
|
|
980
2122
|
return states.includes(word) ? word : null;
|
|
981
2123
|
};
|
|
@@ -1058,7 +2200,15 @@ export function draftAnswer(ctx, env, question) {
|
|
|
1058
2200
|
/** @param {Draft} input */
|
|
1059
2201
|
const push = input => {
|
|
1060
2202
|
const d = withMode(input, clauseNow);
|
|
1061
|
-
|
|
2203
|
+
// A step given twice in one option runs once.
|
|
2204
|
+
const options = d.options
|
|
2205
|
+
.map(o =>
|
|
2206
|
+
o.filter(
|
|
2207
|
+
(st, i) =>
|
|
2208
|
+
o.findIndex(x => JSON.stringify(x) === JSON.stringify(st)) === i,
|
|
2209
|
+
),
|
|
2210
|
+
)
|
|
2211
|
+
.filter(o => o.length);
|
|
1062
2212
|
// The caller reads what was kept.
|
|
1063
2213
|
input.text = d.text;
|
|
1064
2214
|
input.options = options;
|
|
@@ -1084,6 +2234,18 @@ export function draftAnswer(ctx, env, question) {
|
|
|
1084
2234
|
const colorFor = (c, kind) => {
|
|
1085
2235
|
for (const [re, fill, text] of THEME_COLOR_WORDS)
|
|
1086
2236
|
if (re.test(c.text)) return kind === 'fill' ? fill : text;
|
|
2237
|
+
// "fails contrast on white": the color after "on" is what the text sits
|
|
2238
|
+
// on, never the text's own color.
|
|
2239
|
+
if (kind === 'text') {
|
|
2240
|
+
const own = colorsIn(
|
|
2241
|
+
c.text.replace(
|
|
2242
|
+
/\b(on|against|over)\s+(a\s+|the\s+)?((light|dark|pale)\s+)?(#[0-9a-f]+|[a-z]+)(\s+(background|bg|page|surface|cards?))?/g,
|
|
2243
|
+
' ',
|
|
2244
|
+
),
|
|
2245
|
+
);
|
|
2246
|
+
if (c.colors.length && !own.length) return null;
|
|
2247
|
+
if (own.length) return own[0];
|
|
2248
|
+
}
|
|
1087
2249
|
if (kind === 'text' && !c.colors.length) {
|
|
1088
2250
|
if (/\bdark (text|labels?|writing|words)\b/.test(c.text))
|
|
1089
2251
|
return '#111827';
|
|
@@ -1100,6 +2262,14 @@ export function draftAnswer(ctx, env, question) {
|
|
|
1100
2262
|
|
|
1101
2263
|
for (const c of clauses) {
|
|
1102
2264
|
clauseNow = c;
|
|
2265
|
+
// "reset the corners to default", "revert the font": take back what the
|
|
2266
|
+
// theme sets for it, as undo does.
|
|
2267
|
+
const back = resetAnswer(c);
|
|
2268
|
+
if (back) {
|
|
2269
|
+
push(back);
|
|
2270
|
+
recordTop(c, back.options[0] ?? []);
|
|
2271
|
+
continue;
|
|
2272
|
+
}
|
|
1103
2273
|
if (c.except) {
|
|
1104
2274
|
const prior = tops[tops.length - 1];
|
|
1105
2275
|
if (!prior) continue;
|
|
@@ -1145,6 +2315,158 @@ export function draftAnswer(ctx, env, question) {
|
|
|
1145
2315
|
}
|
|
1146
2316
|
for (const a of c.aspects) seenAspect(a);
|
|
1147
2317
|
for (const p of c.parts) seenPart(p.on);
|
|
2318
|
+
if (c.named?.bad) {
|
|
2319
|
+
push({
|
|
2320
|
+
text:
|
|
2321
|
+
c.named.prop === 'font-size'
|
|
2322
|
+
? 'a font size of 0 hides the text; give a size above 0'
|
|
2323
|
+
: `"${c.named.bad}" is not a value ${c.named.prop} takes; give a length such as 16px`,
|
|
2324
|
+
options: [],
|
|
2325
|
+
});
|
|
2326
|
+
continue;
|
|
2327
|
+
}
|
|
2328
|
+
// "cards the same radius as buttons": the first part takes the second
|
|
2329
|
+
// part's value, read from the token the second part reads.
|
|
2330
|
+
const same = /\b(?:the )?same (\w+(?: \w+)?) as (?:the )?([a-z-]+)\b/.exec(
|
|
2331
|
+
c.text,
|
|
2332
|
+
);
|
|
2333
|
+
// "buttons twice as round as inputs": the part after "as" is only the
|
|
2334
|
+
// measure; the first part is the one that changes.
|
|
2335
|
+
const asAs = /\bas \w+ as (?:the )?([a-z-]+)/.exec(c.text);
|
|
2336
|
+
if (asAs && c.parts.length >= 2) {
|
|
2337
|
+
const after = (/** @type {{on: string}} */ p) =>
|
|
2338
|
+
lex.parts.some(
|
|
2339
|
+
([re, x]) =>
|
|
2340
|
+
x.on === p.on && (re.exec(c.text)?.index ?? -1) > (asAs.index ?? 0),
|
|
2341
|
+
);
|
|
2342
|
+
c.parts = c.parts.filter(p => !after(p));
|
|
2343
|
+
}
|
|
2344
|
+
// "focus ring the same color as the danger color": a role's token.
|
|
2345
|
+
const role = same ? ROLE_DIALS.find(([re]) => re.test(same[0])) : null;
|
|
2346
|
+
if (same && role && c.parts.length === 1) {
|
|
2347
|
+
const target = c.parts[0];
|
|
2348
|
+
const d =
|
|
2349
|
+
target.on === 'focus-ring'
|
|
2350
|
+
? {
|
|
2351
|
+
text: `the focus ring takes the ${role[1]} color: --focus-outline-color reads ${role[2]}`,
|
|
2352
|
+
options: [[set('--focus-outline-color', `var(${role[2]})`)]],
|
|
2353
|
+
}
|
|
2354
|
+
: {
|
|
2355
|
+
text: `${target.on} takes the ${role[1]} color`,
|
|
2356
|
+
options: [
|
|
2357
|
+
[set('background', `var(${role[2]})`, {on: target.on})],
|
|
2358
|
+
],
|
|
2359
|
+
};
|
|
2360
|
+
seenPart(target.on);
|
|
2361
|
+
push(d);
|
|
2362
|
+
recordTop(c, d.options[0] ?? []);
|
|
2363
|
+
continue;
|
|
2364
|
+
}
|
|
2365
|
+
if (same && c.parts.length >= 2) {
|
|
2366
|
+
// The part named first takes the value; the order is the question's.
|
|
2367
|
+
const at = (/** @type {{on: string}} */ p) =>
|
|
2368
|
+
Math.min(
|
|
2369
|
+
...lex.parts
|
|
2370
|
+
.filter(([, x]) => x.on === p.on)
|
|
2371
|
+
.map(([re]) => re.exec(c.text)?.index ?? Infinity),
|
|
2372
|
+
);
|
|
2373
|
+
const [target, source] = [...c.parts].sort((x, y) => at(x) - at(y));
|
|
2374
|
+
const group =
|
|
2375
|
+
/** @type {Record<string, string>} */ ({
|
|
2376
|
+
corners: 'corners',
|
|
2377
|
+
radius: 'corners',
|
|
2378
|
+
color: 'background',
|
|
2379
|
+
background: 'background',
|
|
2380
|
+
border: 'border',
|
|
2381
|
+
shadow: 'shadow',
|
|
2382
|
+
padding: 'spacing',
|
|
2383
|
+
spacing: 'spacing',
|
|
2384
|
+
font: 'font',
|
|
2385
|
+
})[same[1].split(' ').pop() ?? ''] ??
|
|
2386
|
+
c.aspects.map(a => (a === 'family' ? 'font' : a)).find(a => GROUPS[a]);
|
|
2387
|
+
const reads = group ? C.partReads(one(source.on), group) : [];
|
|
2388
|
+
const read = reads.find(r => r.when.includes('')) ?? reads[0];
|
|
2389
|
+
const prop = read?.props[0];
|
|
2390
|
+
if (read && prop) {
|
|
2391
|
+
seenPart(target.on);
|
|
2392
|
+
seenPart(source.on);
|
|
2393
|
+
const d = {
|
|
2394
|
+
text: `${target.on} takes ${source.on}'s ${prop}: ${source.on} reads ${read.token} for it`,
|
|
2395
|
+
options: [[set(prop, `var(${read.token})`, {on: target.on})]],
|
|
2396
|
+
};
|
|
2397
|
+
push(d);
|
|
2398
|
+
recordTop(c, d.options[0] ?? []);
|
|
2399
|
+
continue;
|
|
2400
|
+
}
|
|
2401
|
+
}
|
|
2402
|
+
// "… and set --border-width 2px": a real token typed in a clause.
|
|
2403
|
+
// The value runs to the clause end ("--shadow-high 0 4px 12px black").
|
|
2404
|
+
const tok = /(?:^|\s)(--[a-z][a-z0-9-]*)\s*:?\s+([^;]+?)\s*$/.exec(c.text);
|
|
2405
|
+
if (tok && Object.hasOwn(TOKENS, tok[1])) {
|
|
2406
|
+
const d = {
|
|
2407
|
+
text: `the token ${tok[1]}, as you wrote it`,
|
|
2408
|
+
options: [
|
|
2409
|
+
[
|
|
2410
|
+
set(
|
|
2411
|
+
tok[1],
|
|
2412
|
+
tok[2].replace(/\s+(on|for|in|everywhere)\b.*$/, ''),
|
|
2413
|
+
modeOf(c),
|
|
2414
|
+
),
|
|
2415
|
+
],
|
|
2416
|
+
],
|
|
2417
|
+
};
|
|
2418
|
+
push(d);
|
|
2419
|
+
recordTop(c, d.options[0] ?? []);
|
|
2420
|
+
continue;
|
|
2421
|
+
}
|
|
2422
|
+
// "error text red", "labels smaller": text that belongs to parts how
|
|
2423
|
+
// cannot pick alone is a lookup, never the whole theme's text.
|
|
2424
|
+
if (
|
|
2425
|
+
!c.parts.length &&
|
|
2426
|
+
/\b(error (text|messages?)|(field |form |input )?labels?)\b/.test(c.text)
|
|
2427
|
+
) {
|
|
2428
|
+
const which = /\berror\b/.test(c.text) ? 'error text' : 'labels';
|
|
2429
|
+
push({
|
|
2430
|
+
text: `${which} belong to the parts that show them (an input's error message, a field's label); name the part, or look it up`,
|
|
2431
|
+
options: [],
|
|
2432
|
+
lookup: `${HOW} --list parts ${which === 'labels' ? 'label' : 'error'}`,
|
|
2433
|
+
});
|
|
2434
|
+
continue;
|
|
2435
|
+
}
|
|
2436
|
+
// A CSS property named with its value is set as named, on each part.
|
|
2437
|
+
const named = c.named;
|
|
2438
|
+
if (
|
|
2439
|
+
named &&
|
|
2440
|
+
!named.bad &&
|
|
2441
|
+
// A divider's thickness and color are its border tokens.
|
|
2442
|
+
!c.parts.some(p => p.on === 'divider') &&
|
|
2443
|
+
c.parts.length &&
|
|
2444
|
+
c.parts.every(p => TARGET.has(one(p.on)) || FAMILIES[p.on])
|
|
2445
|
+
) {
|
|
2446
|
+
const steps = c.parts.slice(0, 3).map(p => {
|
|
2447
|
+
const {noState: _n, ...f} = flagsFor(c, p);
|
|
2448
|
+
return {p, f, st: set(named.prop, named.value, {...f, ...modeOf(c)})};
|
|
2449
|
+
});
|
|
2450
|
+
// A property set cannot use on a part (a heading's color comes from
|
|
2451
|
+
// its prop) is answered the usual way, which says why.
|
|
2452
|
+
if (steps.every(({st}) => env.check([st]).ok)) {
|
|
2453
|
+
for (const {p, f, st} of steps) {
|
|
2454
|
+
seenPart(p.on);
|
|
2455
|
+
const d = {
|
|
2456
|
+
text: `${named.prop} on ${p.on}${f.state ? ` when ${f.state}` : ''}, as you wrote it`,
|
|
2457
|
+
options: [[st]],
|
|
2458
|
+
};
|
|
2459
|
+
push(d);
|
|
2460
|
+
recordTop(c, d.options[0] ?? []);
|
|
2461
|
+
}
|
|
2462
|
+
continue;
|
|
2463
|
+
}
|
|
2464
|
+
if (named.prop === 'color')
|
|
2465
|
+
c.aspects = [
|
|
2466
|
+
'text',
|
|
2467
|
+
...c.aspects.filter(x => x !== 'background' && x !== 'text'),
|
|
2468
|
+
];
|
|
2469
|
+
}
|
|
1148
2470
|
// A hover effect with nothing more said: a slightly darker part.
|
|
1149
2471
|
if (c.parts.length && !c.aspects.length && c.state === 'hover' && !c.neg)
|
|
1150
2472
|
c.aspects.push('background');
|
|
@@ -1159,6 +2481,20 @@ export function draftAnswer(ctx, env, question) {
|
|
|
1159
2481
|
});
|
|
1160
2482
|
continue;
|
|
1161
2483
|
}
|
|
2484
|
+
// "combobox rounder": a word a component's doc lists, as the subject of
|
|
2485
|
+
// a shape change with no part named, is a part how cannot name; it is
|
|
2486
|
+
// never a whole-theme change.
|
|
2487
|
+
const unknown = !c.parts.length && unknownPart(c.text);
|
|
2488
|
+
if (unknown) {
|
|
2489
|
+
push({
|
|
2490
|
+
text: `no part is called "${unknown.word}"${unknown.parts.length ? `; the closest parts: ${unknown.parts.join(', ')}` : ''}. Name one of them, or list the parts`,
|
|
2491
|
+
options: [],
|
|
2492
|
+
lookup: unknown.parts.length
|
|
2493
|
+
? `${HOW} ${unknown.parts[0]}`
|
|
2494
|
+
: `${HOW} --list parts`,
|
|
2495
|
+
});
|
|
2496
|
+
continue;
|
|
2497
|
+
}
|
|
1162
2498
|
const targets = c.parts.length ? c.parts : [null];
|
|
1163
2499
|
for (const p of targets.slice(0, 3)) {
|
|
1164
2500
|
for (const a of c.aspects.slice(0, 3)) {
|
|
@@ -1198,6 +2534,97 @@ export function draftAnswer(ctx, env, question) {
|
|
|
1198
2534
|
}
|
|
1199
2535
|
}
|
|
1200
2536
|
|
|
2537
|
+
/**
|
|
2538
|
+
* The undo steps for a clause that asks to go back to the base value of a
|
|
2539
|
+
* setting the theme has ("reset the corners", "the accent back to what it
|
|
2540
|
+
* was", "clear the card background override"), or null when it does not
|
|
2541
|
+
* ask that.
|
|
2542
|
+
* @param {Clause} c
|
|
2543
|
+
* @returns {Draft | null}
|
|
2544
|
+
*/
|
|
2545
|
+
function resetAnswer(c) {
|
|
2546
|
+
// "go back to the neutral theme", "start over": every setting.
|
|
2547
|
+
if (
|
|
2548
|
+
/\b(back to|reset to|revert to|restore) (the )?(neutral|base|original|default|plain) theme\b|\bstart over\b|\breset (the )?(whole )?theme\b/.test(
|
|
2549
|
+
c.text,
|
|
2550
|
+
)
|
|
2551
|
+
) {
|
|
2552
|
+
const all = env.data.settings;
|
|
2553
|
+
return all.length
|
|
2554
|
+
? {
|
|
2555
|
+
text: `take back every setting ${env.slug} has, one undo each, to its base theme (${env.data.like ?? 'none'})`,
|
|
2556
|
+
options: [
|
|
2557
|
+
all.map(
|
|
2558
|
+
st =>
|
|
2559
|
+
/** @type {Step} */ ({
|
|
2560
|
+
verb: 'undo',
|
|
2561
|
+
thing: st.thing,
|
|
2562
|
+
...(st.on ? {on: st.on} : {}),
|
|
2563
|
+
...(st.when ? {when: st.when} : {}),
|
|
2564
|
+
...(st.state ? {state: st.state} : {}),
|
|
2565
|
+
...(st.mode ? {mode: st.mode} : {}),
|
|
2566
|
+
}),
|
|
2567
|
+
),
|
|
2568
|
+
],
|
|
2569
|
+
sequence: all.length > 1,
|
|
2570
|
+
}
|
|
2571
|
+
: {
|
|
2572
|
+
text: `${env.slug} sets nothing, so it is its base theme as it is`,
|
|
2573
|
+
options: [],
|
|
2574
|
+
};
|
|
2575
|
+
}
|
|
2576
|
+
if (
|
|
2577
|
+
!/\b(reset|revert|restore|back to|default|original|what it was|standard|clear|no custom|remove the override|(remove|clear|drop|delete) (my |the )?(\w+ )?overrides?|by mistake|by accident|accidentally|put .* back|.* back to normal)\b/.test(
|
|
2578
|
+
c.text,
|
|
2579
|
+
) ||
|
|
2580
|
+
/\bby default\b|\bthe last change\b|\beverything\b/.test(c.text) ||
|
|
2581
|
+
(c.colors.length > 0 &&
|
|
2582
|
+
!/\b(by mistake|by accident|accidentally)\b/.test(c.text)) ||
|
|
2583
|
+
OS_FONT.test(c.text)
|
|
2584
|
+
)
|
|
2585
|
+
return null;
|
|
2586
|
+
const role = ROLE_DIALS.find(([re]) => re.test(c.text));
|
|
2587
|
+
const things = [
|
|
2588
|
+
...c.aspects.flatMap(a => RESET_THINGS[a] ?? []),
|
|
2589
|
+
...(role ? [role[1], role[2]] : []),
|
|
2590
|
+
];
|
|
2591
|
+
const on = c.parts[0]?.on;
|
|
2592
|
+
// "revert the cards to default": every setting on that part.
|
|
2593
|
+
if (!things.length && !on) return null;
|
|
2594
|
+
const matches = env.data.settings.filter(
|
|
2595
|
+
st =>
|
|
2596
|
+
(!things.length ||
|
|
2597
|
+
things.includes(st.thing) ||
|
|
2598
|
+
things.some(
|
|
2599
|
+
t => t.endsWith('*') && st.thing.startsWith(t.slice(0, -1)),
|
|
2600
|
+
)) &&
|
|
2601
|
+
(st.on ?? '') === (on ?? ''),
|
|
2602
|
+
);
|
|
2603
|
+
const what = role ? role[1] : (c.aspects[0] ?? 'everything');
|
|
2604
|
+
if (!matches.length)
|
|
2605
|
+
return {
|
|
2606
|
+
text: `${env.slug} sets nothing for ${what}${on ? ` on ${on}` : ''}, so it already uses the base value`,
|
|
2607
|
+
options: [],
|
|
2608
|
+
};
|
|
2609
|
+
return {
|
|
2610
|
+
text: `take back what ${env.slug} sets for ${what}${on ? ` on ${on}` : ''}: undo restores the base value`,
|
|
2611
|
+
options: [
|
|
2612
|
+
matches.map(
|
|
2613
|
+
st =>
|
|
2614
|
+
/** @type {Step} */ ({
|
|
2615
|
+
verb: 'undo',
|
|
2616
|
+
thing: st.thing,
|
|
2617
|
+
...(st.on ? {on: st.on} : {}),
|
|
2618
|
+
...(st.when ? {when: st.when} : {}),
|
|
2619
|
+
...(st.state ? {state: st.state} : {}),
|
|
2620
|
+
...(st.mode ? {mode: st.mode} : {}),
|
|
2621
|
+
}),
|
|
2622
|
+
),
|
|
2623
|
+
],
|
|
2624
|
+
sequence: matches.length > 1,
|
|
2625
|
+
};
|
|
2626
|
+
}
|
|
2627
|
+
|
|
1201
2628
|
/**
|
|
1202
2629
|
* The step that keeps one part as it is now when a step changes the whole
|
|
1203
2630
|
* theme (or a group the part is in), or null when none can.
|
|
@@ -1356,40 +2783,159 @@ export function draftAnswer(ctx, env, question) {
|
|
|
1356
2783
|
: null;
|
|
1357
2784
|
}
|
|
1358
2785
|
if (on === 'page') {
|
|
1359
|
-
const color = colorFor(c, 'fill')
|
|
2786
|
+
const color = colorFor(c, 'fill');
|
|
2787
|
+
// "the page background lighter": the whole-theme answer, per mode.
|
|
2788
|
+
if (!color)
|
|
2789
|
+
return a === 'background' && c.dir ? answerFor(c, null, a) : null;
|
|
2790
|
+
return {
|
|
2791
|
+
text: `the page background: --color-background-body${c.mode && modal ? ` in ${c.mode} mode` : ''}`,
|
|
2792
|
+
options: [
|
|
2793
|
+
[set('--color-background-body', color, modeOf(c))],
|
|
2794
|
+
[set('background', color, {on: 'app-shell'})],
|
|
2795
|
+
],
|
|
2796
|
+
};
|
|
2797
|
+
}
|
|
2798
|
+
if (on === 'icons') {
|
|
2799
|
+
const color = colorFor(c, 'fill');
|
|
1360
2800
|
if (!color) return null;
|
|
1361
2801
|
return {
|
|
1362
|
-
text:
|
|
2802
|
+
text: 'icon colors: --color-icon-primary for most icons, --color-icon-secondary for quieter ones',
|
|
2803
|
+
options: [
|
|
2804
|
+
[set('--color-icon-primary', color, modeOf(c))],
|
|
2805
|
+
[set('--color-icon-secondary', color, modeOf(c))],
|
|
2806
|
+
],
|
|
2807
|
+
};
|
|
2808
|
+
}
|
|
2809
|
+
if (a === 'motion') {
|
|
2810
|
+
// "turn off all animations", "no transition on links".
|
|
2811
|
+
if (c.neg || /\b(off|none)\b/.test(c.text)) {
|
|
2812
|
+
if (on)
|
|
2813
|
+
return {
|
|
2814
|
+
text: `no transition${where}`,
|
|
2815
|
+
options: [[set('transition', 'none', f)]],
|
|
2816
|
+
};
|
|
2817
|
+
return {
|
|
2818
|
+
text: 'no motion: every shared duration token at 0ms',
|
|
2819
|
+
options: [
|
|
2820
|
+
Object.keys(TOKENS)
|
|
2821
|
+
.filter(t => /^--duration-/.test(t))
|
|
2822
|
+
.map(t => set(t, '0ms')),
|
|
2823
|
+
],
|
|
2824
|
+
sequence: true,
|
|
2825
|
+
};
|
|
2826
|
+
}
|
|
2827
|
+
const typedMs = /\b(\d+)ms\b/.exec(c.text)?.[1];
|
|
2828
|
+
if (typedMs && !on)
|
|
2829
|
+
return {
|
|
2830
|
+
text: `every motion at ${typedMs}ms: the shared duration tokens`,
|
|
2831
|
+
options: [
|
|
2832
|
+
['--duration-fast', '--duration-medium', '--duration-slow']
|
|
2833
|
+
.filter(t => t in TOKENS)
|
|
2834
|
+
.map(t => set(t, `${typedMs}ms`)),
|
|
2835
|
+
],
|
|
2836
|
+
sequence: true,
|
|
2837
|
+
};
|
|
2838
|
+
const slower = /\b(slow(er)?|longer)\b/.test(c.text);
|
|
2839
|
+
const ms =
|
|
2840
|
+
/\b(\d+)ms\b/.exec(c.text)?.[1] ??
|
|
2841
|
+
(/\b(\d*\.?\d+)s\b/.exec(c.text)?.[1] &&
|
|
2842
|
+
String(Number(/\b(\d*\.?\d+)s\b/.exec(c.text)?.[1]) * 1000));
|
|
2843
|
+
const own = on ? (C.MAP[one(on)]?.own ?? {}) : {};
|
|
2844
|
+
const moves = Object.keys(own).some(k =>
|
|
2845
|
+
/^(transition|animation)-duration$/.test(k),
|
|
2846
|
+
);
|
|
2847
|
+
if (on && !moves)
|
|
2848
|
+
return {
|
|
2849
|
+
text: `${on} has no motion of its own that set can change; the theme's motion speeds are the --duration-* tokens, which every part shares`,
|
|
2850
|
+
options: [],
|
|
2851
|
+
lookup: `${HOW} --duration-medium`,
|
|
2852
|
+
};
|
|
2853
|
+
if (!on) {
|
|
2854
|
+
const scale = slower ? 1.5 : 0.6;
|
|
2855
|
+
return {
|
|
2856
|
+
text: `${slower ? 'slower' : 'faster'} motion everywhere: the shared duration tokens`,
|
|
2857
|
+
options: [
|
|
2858
|
+
['--duration-fast', '--duration-medium', '--duration-slow']
|
|
2859
|
+
.filter(t => t in TOKENS)
|
|
2860
|
+
.map(t =>
|
|
2861
|
+
set(t, `${Math.round(parseFloat(current(t)) * scale)}ms`),
|
|
2862
|
+
),
|
|
2863
|
+
],
|
|
2864
|
+
sequence: true,
|
|
2865
|
+
};
|
|
2866
|
+
}
|
|
2867
|
+
return {
|
|
2868
|
+
text: `${slower ? 'slower' : 'faster'} transitions${where}: transition-duration`,
|
|
1363
2869
|
options: [
|
|
1364
|
-
[set('
|
|
1365
|
-
[set('background', color, {on: 'app-shell'})],
|
|
2870
|
+
[set('transition-duration', `${ms ?? (slower ? 300 : 100)}ms`, f)],
|
|
1366
2871
|
],
|
|
1367
2872
|
};
|
|
1368
2873
|
}
|
|
1369
|
-
|
|
2874
|
+
// A divider draws with the border tokens: its thickness and color.
|
|
2875
|
+
if (
|
|
2876
|
+
on === 'divider' &&
|
|
2877
|
+
['border', 'size', 'background', 'text'].includes(a)
|
|
2878
|
+
) {
|
|
1370
2879
|
const color = colorFor(c, 'fill');
|
|
1371
|
-
if (
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
]
|
|
1378
|
-
|
|
2880
|
+
if (color && (a === 'background' || a === 'text' || a === 'border'))
|
|
2881
|
+
return {
|
|
2882
|
+
text: 'the divider color: --color-border, on the divider only',
|
|
2883
|
+
options: [[set('--color-border', color, {on, ...modeOf(c)})]],
|
|
2884
|
+
};
|
|
2885
|
+
const len =
|
|
2886
|
+
c.lengths[0] ??
|
|
2887
|
+
(c.dir === 'less'
|
|
2888
|
+
? '1px'
|
|
2889
|
+
: c.dir || /\bthick/.test(c.text)
|
|
2890
|
+
? '2px'
|
|
2891
|
+
: null);
|
|
2892
|
+
return len
|
|
2893
|
+
? {
|
|
2894
|
+
text: 'the divider thickness: --border-width, on the divider only',
|
|
2895
|
+
options: [[set('--border-width', len, {on})]],
|
|
2896
|
+
}
|
|
2897
|
+
: null;
|
|
1379
2898
|
}
|
|
1380
2899
|
if (on === 'overlay') {
|
|
1381
|
-
const
|
|
1382
|
-
const
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
?
|
|
1386
|
-
|
|
1387
|
-
|
|
2900
|
+
const typed = colorFor(c, 'fill');
|
|
2901
|
+
const steps = typed
|
|
2902
|
+
? [set('--color-overlay', typed, modeOf(c))]
|
|
2903
|
+
: c.dir || c.neg
|
|
2904
|
+
? perMode(
|
|
2905
|
+
'--color-overlay',
|
|
2906
|
+
'--color-overlay',
|
|
2907
|
+
{},
|
|
2908
|
+
(now, m) => stronger(now, c.dir === 'more' ? 1.5 : 0.6, m),
|
|
2909
|
+
c,
|
|
2910
|
+
)
|
|
2911
|
+
: [];
|
|
2912
|
+
if (!steps.length) return null;
|
|
1388
2913
|
return {
|
|
1389
|
-
text: `the dimmed layer behind dialogs and drawers: --color-overlay (
|
|
1390
|
-
options: [
|
|
2914
|
+
text: `the dimmed layer behind dialogs and drawers: --color-overlay${typed ? '' : modesSaid(steps)}`,
|
|
2915
|
+
options: [steps],
|
|
2916
|
+
sequence: steps.length > 1,
|
|
1391
2917
|
};
|
|
1392
2918
|
}
|
|
2919
|
+
// A part that reads no fill or text color token ("spinner in the accent
|
|
2920
|
+
// color") gets no fill it never had.
|
|
2921
|
+
if (
|
|
2922
|
+
a === 'background' &&
|
|
2923
|
+
on &&
|
|
2924
|
+
!f.state &&
|
|
2925
|
+
!/\b(stripe[sd]?|striped|zebra)\b/.test(c.text) &&
|
|
2926
|
+
C.MAP[one(on)] &&
|
|
2927
|
+
!Object.keys(C.MAP[one(on)].own ?? {}).some(k =>
|
|
2928
|
+
/^(background|background-color|background-image|color|fill|stroke|border-color|border|outline-color)$/.test(
|
|
2929
|
+
k,
|
|
2930
|
+
),
|
|
2931
|
+
) &&
|
|
2932
|
+
!/\b(background|bg|fill(ed)?|gradient)\b/.test(c.text)
|
|
2933
|
+
)
|
|
2934
|
+
return {
|
|
2935
|
+
text: `${on} reads no fill or text color token that set can change; its color comes from its own props`,
|
|
2936
|
+
options: [],
|
|
2937
|
+
lookup: `${HOW} ${on}`,
|
|
2938
|
+
};
|
|
1393
2939
|
if (p?.role === 'body' && a === 'weight') {
|
|
1394
2940
|
const v =
|
|
1395
2941
|
weightIn(c) ??
|
|
@@ -1407,13 +2953,27 @@ export function draftAnswer(ctx, env, question) {
|
|
|
1407
2953
|
}
|
|
1408
2954
|
if (p?.role && (a === 'family' || a === 'fontsize')) {
|
|
1409
2955
|
if (a === 'family') {
|
|
1410
|
-
const font = fontIn(c
|
|
1411
|
-
return
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
2956
|
+
const font = fontIn(c, question);
|
|
2957
|
+
if (!font) return null;
|
|
2958
|
+
// set font --on body moves the heading font too in this release, so
|
|
2959
|
+
// the body alone takes its token.
|
|
2960
|
+
if (p.role === 'body' && env.bodyFontReachesHeadings) {
|
|
2961
|
+
const stack = FONTS[font]
|
|
2962
|
+
? `${FONTS[font][0].includes(' ') ? `"${FONTS[font][0]}"` : FONTS[font][0]}, ${FONTS[font][1]}`
|
|
2963
|
+
: OPEN_FONTS[font]
|
|
2964
|
+
? `"${OPEN_FONTS[font].family}", ${OPEN_FONTS[font].fallbacks}`
|
|
2965
|
+
: /[\s,]/.test(font) && !font.includes(',')
|
|
2966
|
+
? `"${font}"`
|
|
2967
|
+
: font;
|
|
2968
|
+
return {
|
|
2969
|
+
text: 'the body font alone: --font-family-body (font --on body also changes the headings in this release)',
|
|
2970
|
+
options: [[set('--font-family-body', stack)]],
|
|
2971
|
+
};
|
|
2972
|
+
}
|
|
2973
|
+
return {
|
|
2974
|
+
text: `the ${p.role} font: font --on ${p.role}`,
|
|
2975
|
+
options: [[set('font', font, {on: p.role})]],
|
|
2976
|
+
};
|
|
1417
2977
|
}
|
|
1418
2978
|
if (p.role === 'body') {
|
|
1419
2979
|
const px = /\b(\d+)px\b/.exec(c.text)?.[1];
|
|
@@ -1437,7 +2997,9 @@ export function draftAnswer(ctx, env, question) {
|
|
|
1437
2997
|
};
|
|
1438
2998
|
}
|
|
1439
2999
|
case 'leading': {
|
|
1440
|
-
const n =
|
|
3000
|
+
const n =
|
|
3001
|
+
/\b(normal)\b/.exec(c.text)?.[1] ??
|
|
3002
|
+
/\b(\d(?:\.\d+)?)\b(?!\s*(px|rem|em|%))/.exec(c.text)?.[1];
|
|
1441
3003
|
const tok =
|
|
1442
3004
|
!on || on === 'body' || p?.role === 'body'
|
|
1443
3005
|
? '--text-body-leading'
|
|
@@ -1467,10 +3029,30 @@ export function draftAnswer(ctx, env, question) {
|
|
|
1467
3029
|
case 'corners': {
|
|
1468
3030
|
const tall = tallIn(c.text);
|
|
1469
3031
|
const tied = radiusIn(c.text);
|
|
1470
|
-
const
|
|
3032
|
+
const typedPx =
|
|
1471
3033
|
(tied && /^-?\d*\.?\d+$/.test(tied) ? `${tied}px` : tied) ??
|
|
1472
3034
|
c.lengths.find(l => l !== tall) ??
|
|
1473
3035
|
null;
|
|
3036
|
+
// A radius of 0 is square.
|
|
3037
|
+
const px = typedPx && parseFloat(typedPx) === 0 ? null : typedPx;
|
|
3038
|
+
const zero = Boolean(typedPx) && !px;
|
|
3039
|
+
// "revert the rounded corners": take back what the theme sets.
|
|
3040
|
+
if (/\b(revert|undo|take back)\b/.test(c.text)) {
|
|
3041
|
+
const back = existing(['corners', 'border-radius'], on);
|
|
3042
|
+
if (back.length)
|
|
3043
|
+
return {
|
|
3044
|
+
text: `take back the corners this theme sets${where}`,
|
|
3045
|
+
options: back.map(x => [
|
|
3046
|
+
/** @type {Step} */ ({
|
|
3047
|
+
verb: 'undo',
|
|
3048
|
+
thing: x.thing,
|
|
3049
|
+
...(on ? {on} : {}),
|
|
3050
|
+
...(x.when ? {when: x.when} : {}),
|
|
3051
|
+
...(x.state ? {state: x.state} : {}),
|
|
3052
|
+
}),
|
|
3053
|
+
]),
|
|
3054
|
+
};
|
|
3055
|
+
}
|
|
1474
3056
|
if (px?.startsWith('-'))
|
|
1475
3057
|
return {
|
|
1476
3058
|
text: `a radius cannot be negative ("${px}"); give a size of 0 or more`,
|
|
@@ -1479,9 +3061,11 @@ export function draftAnswer(ctx, env, question) {
|
|
|
1479
3061
|
// "too sharp" asks for rounder, not square.
|
|
1480
3062
|
const shapeText = c.text.replace(/\btoo \w+/g, ' ');
|
|
1481
3063
|
const shape =
|
|
1482
|
-
c.neg || /\b(square(d)?|sharp)\b/.test(shapeText)
|
|
3064
|
+
zero || c.neg || /\b(square(d)?|sharp)\b/.test(shapeText)
|
|
1483
3065
|
? 'square'
|
|
1484
|
-
: /\b(pill|circular|circles?|fully round)\b/.test(
|
|
3066
|
+
: /\b(pill|circular(?! (font|typeface))|circles?|fully round|max(imum)? round\w*|most round\w*|as round as possible)\b/.test(
|
|
3067
|
+
shapeText,
|
|
3068
|
+
)
|
|
1485
3069
|
? 'pill'
|
|
1486
3070
|
: null;
|
|
1487
3071
|
const value =
|
|
@@ -1495,11 +3079,17 @@ export function draftAnswer(ctx, env, question) {
|
|
|
1495
3079
|
? 'more'
|
|
1496
3080
|
: 'round');
|
|
1497
3081
|
if (!value) return null;
|
|
1498
|
-
if (!on)
|
|
3082
|
+
if (!on) {
|
|
3083
|
+
// The corners dial takes pixels: a rem or em size is converted at
|
|
3084
|
+
// 16px to the rem.
|
|
3085
|
+
const dial = /^\d*\.?\d+r?em$/.test(value)
|
|
3086
|
+
? `${Math.round(parseFloat(value) * 16 * 100) / 100}px`
|
|
3087
|
+
: value;
|
|
1499
3088
|
return {
|
|
1500
|
-
text: `corners${where}: the corners dial (sets the corner tokens together)`,
|
|
1501
|
-
options: [[set('corners',
|
|
3089
|
+
text: `corners${where}: the corners dial (sets the corner tokens together)${dial !== value ? `, ${value} as ${dial}` : ''}`,
|
|
3090
|
+
options: [[set('corners', dial)]],
|
|
1502
3091
|
};
|
|
3092
|
+
}
|
|
1503
3093
|
if (px)
|
|
1504
3094
|
return {
|
|
1505
3095
|
text: `corners${where}: border-radius ${px}`,
|
|
@@ -1522,11 +3112,19 @@ export function draftAnswer(ctx, env, question) {
|
|
|
1522
3112
|
text: 'the shadow you wrote, as the shared medium shadow most panels use: --shadow-med',
|
|
1523
3113
|
options: [[set('--shadow-med', typedShadow, modeOf(c))]],
|
|
1524
3114
|
};
|
|
3115
|
+
// Another clause writes the shadow out: that one answers.
|
|
3116
|
+
if (!typedShadow && !on && !c.neg && shadowIn(q)) return null;
|
|
3117
|
+
// "too strong" asks for softer: the word after "too" is what to
|
|
3118
|
+
// move away from.
|
|
3119
|
+
const shadowText = c.text.replace(/\btoo \w+/g, ' ');
|
|
3120
|
+
const soft =
|
|
3121
|
+
c.dir === 'less' ||
|
|
3122
|
+
/\b(soft(er)?|subtle(r)?|light(er)?|gentle|less)\b/.test(shadowText);
|
|
1525
3123
|
const strong =
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
3124
|
+
!soft &&
|
|
3125
|
+
/\b(strong(er)?|deep(er)?|heav(y|ier)|bigger|more)\b/.test(
|
|
3126
|
+
shadowText,
|
|
3127
|
+
);
|
|
1530
3128
|
if (!on) {
|
|
1531
3129
|
if (c.neg || /\bflat\b/.test(c.text))
|
|
1532
3130
|
return {
|
|
@@ -1568,7 +3166,8 @@ export function draftAnswer(ctx, env, question) {
|
|
|
1568
3166
|
sequence: true,
|
|
1569
3167
|
};
|
|
1570
3168
|
}
|
|
1571
|
-
|
|
3169
|
+
// "flat cards": no shadow on them ("too flat" asks for one).
|
|
3170
|
+
if (c.neg || (/\bflat\b/.test(c.text) && !/\btoo flat\b/.test(c.text)))
|
|
1572
3171
|
return {
|
|
1573
3172
|
text: `no shadow${where}`,
|
|
1574
3173
|
options: [...undo(['box-shadow']), [set('box-shadow', 'none', f)]],
|
|
@@ -1608,19 +3207,29 @@ export function draftAnswer(ctx, env, question) {
|
|
|
1608
3207
|
};
|
|
1609
3208
|
// Darker, lighter, subtler or more contrast asks for the color.
|
|
1610
3209
|
if (
|
|
1611
|
-
/\b(darker|lighter|subtle\w*|contrast|stronger|fainter|softer|visible|invisible)\b/.test(
|
|
3210
|
+
/\b(darker|lighter|subtle\w*|contrast|stronger|fainter|softer|visible|invisible|too (dark|light|faint|strong|harsh|heavy))\b/.test(
|
|
1612
3211
|
c.text,
|
|
1613
3212
|
)
|
|
1614
3213
|
) {
|
|
1615
|
-
|
|
3214
|
+
// "too light" asks for stronger borders, "too dark" for fainter.
|
|
1616
3215
|
const more =
|
|
1617
|
-
/\b(darker|stronger|more contrast|visible)\b/.test(
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
3216
|
+
(/\b(darker|stronger|more contrast|visible|too (light|faint|subtle))\b/.test(
|
|
3217
|
+
c.text,
|
|
3218
|
+
) &&
|
|
3219
|
+
!/\binvisible\b/.test(c.text)) ||
|
|
3220
|
+
false;
|
|
3221
|
+
const steps = perMode(
|
|
3222
|
+
'--color-border',
|
|
3223
|
+
'--color-border',
|
|
3224
|
+
{},
|
|
3225
|
+
(now, m) => stronger(now, more ? 2 : 0.5, m),
|
|
3226
|
+
c,
|
|
3227
|
+
);
|
|
3228
|
+
return steps.length
|
|
1621
3229
|
? {
|
|
1622
|
-
text: `the border color of the whole theme: --color-border
|
|
1623
|
-
options: [
|
|
3230
|
+
text: `the border color of the whole theme: --color-border, ${more ? 'stronger' : 'fainter'}${modesSaid(steps)}`,
|
|
3231
|
+
options: [steps],
|
|
3232
|
+
sequence: steps.length > 1,
|
|
1624
3233
|
}
|
|
1625
3234
|
: null;
|
|
1626
3235
|
}
|
|
@@ -1754,9 +3363,9 @@ export function draftAnswer(ctx, env, question) {
|
|
|
1754
3363
|
};
|
|
1755
3364
|
}
|
|
1756
3365
|
case 'tracking': {
|
|
1757
|
-
const tight =
|
|
1758
|
-
c.
|
|
1759
|
-
|
|
3366
|
+
const tight =
|
|
3367
|
+
c.dir === 'less' ||
|
|
3368
|
+
/\b(tight(en|er)?|narrow(er)?|less|condensed)\b/.test(c.text);
|
|
1760
3369
|
const typedTrack = c.lengths.find(l => /em$/.test(l)) ?? c.lengths[0];
|
|
1761
3370
|
const value = typedTrack ?? (tight ? '-0.02em' : '0.04em');
|
|
1762
3371
|
if (!on || on === 'heading')
|
|
@@ -1813,7 +3422,7 @@ export function draftAnswer(ctx, env, question) {
|
|
|
1813
3422
|
};
|
|
1814
3423
|
}
|
|
1815
3424
|
case 'family': {
|
|
1816
|
-
const font = fontIn(c
|
|
3425
|
+
const font = fontIn(c, question);
|
|
1817
3426
|
if (!font) return null;
|
|
1818
3427
|
if (!on)
|
|
1819
3428
|
return {
|
|
@@ -1832,6 +3441,12 @@ export function draftAnswer(ctx, env, question) {
|
|
|
1832
3441
|
};
|
|
1833
3442
|
}
|
|
1834
3443
|
case 'fontsize': {
|
|
3444
|
+
// A size of 0 hides the text: refused by name, never made bigger.
|
|
3445
|
+
if (/\b(font|text) size\s*:?\s*0(px|rem|em)?\b(?!\.)/.test(c.text))
|
|
3446
|
+
return {
|
|
3447
|
+
text: 'a font size of 0 hides the text; give a size above 0',
|
|
3448
|
+
options: [],
|
|
3449
|
+
};
|
|
1835
3450
|
const px = c.lengths[0];
|
|
1836
3451
|
const f2 = /\bmuch\b/.test(c.text) ? 1.5 : 1.25;
|
|
1837
3452
|
const factor = c.dir === 'less' ? 1 / f2 : f2;
|
|
@@ -1843,7 +3458,11 @@ export function draftAnswer(ctx, env, question) {
|
|
|
1843
3458
|
set(
|
|
1844
3459
|
'text-size',
|
|
1845
3460
|
px
|
|
1846
|
-
? String(
|
|
3461
|
+
? String(
|
|
3462
|
+
/r?em$/.test(px)
|
|
3463
|
+
? Math.round(parseFloat(px) * 16 * 100) / 100
|
|
3464
|
+
: parseFloat(px),
|
|
3465
|
+
)
|
|
1847
3466
|
: c.dir === 'less'
|
|
1848
3467
|
? 'less'
|
|
1849
3468
|
: 'more',
|
|
@@ -1872,10 +3491,16 @@ export function draftAnswer(ctx, env, question) {
|
|
|
1872
3491
|
const sizeTok =
|
|
1873
3492
|
on === 'heading' && p?.level
|
|
1874
3493
|
? `--text-heading-${p.level}-size`
|
|
1875
|
-
: C.partReads(one(on), 'font').find(r =>
|
|
3494
|
+
: (C.partReads(one(on), 'font').find(r =>
|
|
1876
3495
|
r.props.includes('font-size'),
|
|
1877
|
-
)?.token
|
|
1878
|
-
|
|
3496
|
+
)?.token ??
|
|
3497
|
+
Object.keys(C.MAP[one(on)]?.own?.['font-size']?.tokens ?? {})[0]);
|
|
3498
|
+
// A part with no size token of its own starts from the body size.
|
|
3499
|
+
const now = sizeTok
|
|
3500
|
+
? current(sizeTok)
|
|
3501
|
+
: on !== 'heading' && '--text-body-size' in TOKENS
|
|
3502
|
+
? current('--text-body-size')
|
|
3503
|
+
: null;
|
|
1879
3504
|
const value = px ?? (now ? scaled(now, factor) : null);
|
|
1880
3505
|
if (!value) return null;
|
|
1881
3506
|
return {
|
|
@@ -1887,6 +3512,13 @@ export function draftAnswer(ctx, env, question) {
|
|
|
1887
3512
|
};
|
|
1888
3513
|
}
|
|
1889
3514
|
case 'case': {
|
|
3515
|
+
if (/\bsmall caps\b/.test(c.text) && on)
|
|
3516
|
+
return {
|
|
3517
|
+
text: `small caps${where}: font-variant-caps`,
|
|
3518
|
+
options: [
|
|
3519
|
+
[set('font-variant-caps', c.neg ? 'normal' : 'small-caps', f)],
|
|
3520
|
+
],
|
|
3521
|
+
};
|
|
1890
3522
|
const value = c.neg
|
|
1891
3523
|
? 'none'
|
|
1892
3524
|
: /\blower/.test(c.text)
|
|
@@ -1913,7 +3545,71 @@ export function draftAnswer(ctx, env, question) {
|
|
|
1913
3545
|
}
|
|
1914
3546
|
: null;
|
|
1915
3547
|
case 'opacity': {
|
|
1916
|
-
const
|
|
3548
|
+
const layer =
|
|
3549
|
+
/\b(shadows?|backgrounds?|bg|borders?|outlines?)\s+opacity\b/.exec(
|
|
3550
|
+
c.text,
|
|
3551
|
+
)?.[1];
|
|
3552
|
+
const alpha =
|
|
3553
|
+
/\bopacity\s*:?\s*(0?\.\d+|0|1)\b(?!%)/.exec(c.text)?.[1] ??
|
|
3554
|
+
(Number(/\b(\d{1,3})%/.exec(withoutFunctions(c.text))?.[1] ?? NaN) /
|
|
3555
|
+
100 ||
|
|
3556
|
+
null);
|
|
3557
|
+
// "shadow opacity 0.2": the layer's own alpha, never the part's.
|
|
3558
|
+
if (layer && on) {
|
|
3559
|
+
const a =
|
|
3560
|
+
alpha == null ? (c.dir === 'less' ? 0.08 : 0.2) : Number(alpha);
|
|
3561
|
+
if (/^shadow/.test(layer))
|
|
3562
|
+
return {
|
|
3563
|
+
text: `a shadow at ${a} alpha${where}`,
|
|
3564
|
+
options: [[set('box-shadow', `0 1px 3px rgb(0 0 0 / ${a})`, f)]],
|
|
3565
|
+
};
|
|
3566
|
+
if (/^(background|bg)/.test(layer)) {
|
|
3567
|
+
const tok =
|
|
3568
|
+
C.partReads(one(on), 'background').find(r => r.when.includes(''))
|
|
3569
|
+
?.token ??
|
|
3570
|
+
(FAMILIES.containers.includes(one(on))
|
|
3571
|
+
? '--color-background-card'
|
|
3572
|
+
: null);
|
|
3573
|
+
return tok
|
|
3574
|
+
? {
|
|
3575
|
+
text: `the background at ${Math.round(a * 100)}%${where}, see-through to what is behind it`,
|
|
3576
|
+
options: [
|
|
3577
|
+
[
|
|
3578
|
+
set(
|
|
3579
|
+
'background-color',
|
|
3580
|
+
`color-mix(in srgb, var(${tok}) ${Math.round(a * 100)}%, transparent)`,
|
|
3581
|
+
f,
|
|
3582
|
+
),
|
|
3583
|
+
],
|
|
3584
|
+
],
|
|
3585
|
+
}
|
|
3586
|
+
: {
|
|
3587
|
+
text: `${on} has no background color of its own to make see-through`,
|
|
3588
|
+
options: [],
|
|
3589
|
+
};
|
|
3590
|
+
}
|
|
3591
|
+
return {
|
|
3592
|
+
text: `the border at ${Math.round(a * 100)}%${where}`,
|
|
3593
|
+
options: [
|
|
3594
|
+
[
|
|
3595
|
+
set(
|
|
3596
|
+
'border-color',
|
|
3597
|
+
`color-mix(in srgb, var(--color-border) ${Math.round(a * 100)}%, transparent)`,
|
|
3598
|
+
f,
|
|
3599
|
+
),
|
|
3600
|
+
],
|
|
3601
|
+
],
|
|
3602
|
+
};
|
|
3603
|
+
}
|
|
3604
|
+
const typedOpacity = /\bopacity\s*:?\s*(0?\.\d+|0|1)\b(?!%)/.exec(
|
|
3605
|
+
c.text,
|
|
3606
|
+
)?.[1];
|
|
3607
|
+
if (typedOpacity && on)
|
|
3608
|
+
return {
|
|
3609
|
+
text: `opacity${where}: ${typedOpacity}`,
|
|
3610
|
+
options: [[set('opacity', typedOpacity, f)]],
|
|
3611
|
+
};
|
|
3612
|
+
const pct = /\b(\d{1,3})%/.exec(withoutFunctions(c.text))?.[1];
|
|
1917
3613
|
if (pct && on)
|
|
1918
3614
|
return Number(pct) > 100
|
|
1919
3615
|
? {text: `opacity runs from 0% to 100%, not ${pct}%`, options: []}
|
|
@@ -1941,6 +3637,12 @@ export function draftAnswer(ctx, env, question) {
|
|
|
1941
3637
|
: null;
|
|
1942
3638
|
}
|
|
1943
3639
|
case 'scale':
|
|
3640
|
+
// "should not shrink when pressed": no scale.
|
|
3641
|
+
if (on && c.neg)
|
|
3642
|
+
return {
|
|
3643
|
+
text: `${on} keeps its size${where}: transform none`,
|
|
3644
|
+
options: [[set('transform', 'none', f)]],
|
|
3645
|
+
};
|
|
1944
3646
|
return on
|
|
1945
3647
|
? {
|
|
1946
3648
|
text: `${on} scales${where}: transform`,
|
|
@@ -1948,9 +3650,11 @@ export function draftAnswer(ctx, env, question) {
|
|
|
1948
3650
|
[
|
|
1949
3651
|
set(
|
|
1950
3652
|
'transform',
|
|
1951
|
-
/\
|
|
1952
|
-
?
|
|
1953
|
-
:
|
|
3653
|
+
/\bscale\s*:?\s*(0?\.\d+|1(\.\d+)?)\b/.test(c.text)
|
|
3654
|
+
? `scale(${/\bscale\s*:?\s*(0?\.\d+|1(?:\.\d+)?)\b/.exec(c.text)?.[1]})`
|
|
3655
|
+
: /\b(up|grows?)\b/.test(c.text)
|
|
3656
|
+
? 'scale(1.03)'
|
|
3657
|
+
: 'scale(0.97)',
|
|
1954
3658
|
f,
|
|
1955
3659
|
),
|
|
1956
3660
|
],
|
|
@@ -1959,7 +3663,16 @@ export function draftAnswer(ctx, env, question) {
|
|
|
1959
3663
|
: null;
|
|
1960
3664
|
case 'size': {
|
|
1961
3665
|
if (!on) return null;
|
|
1962
|
-
|
|
3666
|
+
// A heading's size is its type size.
|
|
3667
|
+
if (on === 'heading' && !c.lengths.length)
|
|
3668
|
+
return answerFor(c, p, 'fontsize');
|
|
3669
|
+
const tall =
|
|
3670
|
+
tallIn(c.text) ??
|
|
3671
|
+
(/\b(taller|shorter|height|bigger|larger|tap targets?|touch targets?)\b/.test(
|
|
3672
|
+
c.text,
|
|
3673
|
+
) && !/\b(wider|narrower|width)\b/.test(c.text)
|
|
3674
|
+
? c.lengths[0]
|
|
3675
|
+
: null);
|
|
1963
3676
|
if (tall)
|
|
1964
3677
|
return {
|
|
1965
3678
|
text: `the height${where}: min-height ${tall}`,
|
|
@@ -2015,36 +3728,147 @@ export function draftAnswer(ctx, env, question) {
|
|
|
2015
3728
|
};
|
|
2016
3729
|
}
|
|
2017
3730
|
case 'text': {
|
|
2018
|
-
|
|
3731
|
+
// "dim the white text": the color word names the text to change,
|
|
3732
|
+
// not the color to give it.
|
|
3733
|
+
const recolor =
|
|
3734
|
+
/\b(dim|dimmer|soften|darken|lighten|brighten|tone down)\b/.test(
|
|
3735
|
+
c.text,
|
|
3736
|
+
) && !/#[0-9a-f]{3,8}\b|\(/.test(c.text);
|
|
3737
|
+
const color = recolor ? null : colorFor(c, 'text');
|
|
2019
3738
|
const tok = /\bsecondary\b/.test(c.text)
|
|
2020
3739
|
? '--color-text-secondary'
|
|
2021
3740
|
: '--color-text-primary';
|
|
2022
3741
|
if (!on) {
|
|
2023
|
-
const
|
|
2024
|
-
|
|
2025
|
-
|
|
3742
|
+
const label = `${tok === '--color-text-secondary' ? 'secondary' : 'main'} text color: ${tok}`;
|
|
3743
|
+
// "never use pure black": where the token is that color, a near
|
|
3744
|
+
// color that is not it; a mode where it is not keeps its value.
|
|
3745
|
+
if (c.neg && color) {
|
|
3746
|
+
const avoid = parseColor(color);
|
|
3747
|
+
const steps = perMode(
|
|
3748
|
+
tok,
|
|
3749
|
+
tok,
|
|
3750
|
+
{},
|
|
3751
|
+
now => {
|
|
3752
|
+
const n = parseColor(now);
|
|
3753
|
+
if (
|
|
3754
|
+
!avoid ||
|
|
3755
|
+
!n ||
|
|
3756
|
+
n.some((x, i) => Math.abs(x - avoid[i]) > 2)
|
|
3757
|
+
)
|
|
3758
|
+
return null;
|
|
3759
|
+
return avoid.reduce((x, y) => x + y, 0) < 384
|
|
3760
|
+
? '#1f2937'
|
|
3761
|
+
: '#f9fafb';
|
|
3762
|
+
},
|
|
3763
|
+
c,
|
|
3764
|
+
);
|
|
3765
|
+
return steps.length
|
|
3766
|
+
? {
|
|
3767
|
+
text: `${label}, off ${color}${modesSaid(steps)}`,
|
|
3768
|
+
options: [steps],
|
|
3769
|
+
sequence: steps.length > 1,
|
|
3770
|
+
}
|
|
3771
|
+
: {
|
|
3772
|
+
text: `${label} is not ${color} in any mode, so nothing changes`,
|
|
3773
|
+
options: [],
|
|
3774
|
+
};
|
|
3775
|
+
}
|
|
3776
|
+
if (color) {
|
|
3777
|
+
// A text color for both modes that one mode's page would make
|
|
3778
|
+
// unreadable is set for the other mode only.
|
|
3779
|
+
const rgb = parseColor(color);
|
|
3780
|
+
const readable = /** @type {Array<'light' | 'dark'>} */ ([
|
|
3781
|
+
'light',
|
|
3782
|
+
'dark',
|
|
3783
|
+
]).filter(m => {
|
|
3784
|
+
const page = parseColor(current('--color-background-body', m));
|
|
3785
|
+
return !rgb || !page || ratio(rgb, page) >= 3;
|
|
3786
|
+
});
|
|
3787
|
+
if (
|
|
3788
|
+
!c.mode &&
|
|
3789
|
+
modal &&
|
|
3790
|
+
readable.length === 1 &&
|
|
3791
|
+
// Asked for every mode, or with its own page color: as asked.
|
|
3792
|
+
!/\b(everywhere|both modes|all modes|always|in every mode)\b/.test(
|
|
3793
|
+
q,
|
|
3794
|
+
) &&
|
|
3795
|
+
!/\b(bg|background|page)\b/.test(q)
|
|
3796
|
+
)
|
|
3797
|
+
return {
|
|
3798
|
+
text: `${label} in ${readable[0]} mode only: on the ${readable[0] === 'light' ? 'dark' : 'light'} page ${color} would not be readable`,
|
|
3799
|
+
options: [[set(tok, color, {mode: readable[0]})]],
|
|
3800
|
+
};
|
|
3801
|
+
return {
|
|
3802
|
+
text: `${label}${c.mode && modal ? ` in ${c.mode} mode` : ''}`,
|
|
3803
|
+
options: [[set(tok, color, modeOf(c))]],
|
|
3804
|
+
};
|
|
3805
|
+
}
|
|
3806
|
+
// More contrast moves text away from its page: darker on light,
|
|
3807
|
+
// lighter on dark. Less contrast moves it toward the page.
|
|
3808
|
+
// "knock the contrast down" asks for less contrast.
|
|
3809
|
+
const down = c.dir === 'less' && /\bcontrast\b/.test(c.text);
|
|
3810
|
+
const more =
|
|
3811
|
+
!down &&
|
|
3812
|
+
/\b(darker|darken|too light|can'?t read|hard to read|unreadable|(more|better|higher|low|fails?|failing|enough) contrast|contrast)\b/.test(
|
|
3813
|
+
c.text,
|
|
3814
|
+
) &&
|
|
3815
|
+
!/\bless contrast\b/.test(c.text);
|
|
3816
|
+
const less =
|
|
3817
|
+
down ||
|
|
3818
|
+
/\b(less bright|dim|dimmer|soften|softer|lighter|less contrast|too dark)\b/.test(
|
|
2026
3819
|
c.text,
|
|
2027
3820
|
);
|
|
2028
|
-
|
|
2029
|
-
const
|
|
2030
|
-
const
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
3821
|
+
if (!more && !less) return null;
|
|
3822
|
+
const literal = /\b(darker|lighter)\b/.test(c.text) && c.mode;
|
|
3823
|
+
const steps = perMode(
|
|
3824
|
+
tok,
|
|
3825
|
+
tok,
|
|
3826
|
+
{},
|
|
3827
|
+
(now, m) => {
|
|
3828
|
+
const toward = literal
|
|
3829
|
+
? /\bdarker\b/.test(c.text)
|
|
3830
|
+
? -1
|
|
3831
|
+
: 1
|
|
3832
|
+
: (m === 'dark' ? 1 : -1) * (more ? 1 : -1);
|
|
3833
|
+
return shift(now, toward * (more ? 0.3 : 0.2));
|
|
3834
|
+
},
|
|
3835
|
+
c,
|
|
3836
|
+
);
|
|
3837
|
+
return steps.length
|
|
3838
|
+
? {
|
|
3839
|
+
text: `${label}, ${more ? 'more' : 'less'} contrast with the page${modesSaid(steps)}`,
|
|
3840
|
+
options: [steps],
|
|
3841
|
+
sequence: steps.length > 1,
|
|
3842
|
+
}
|
|
3843
|
+
: {
|
|
3844
|
+
text: `${label} is already ${more ? 'as far from the page as it goes' : 'as close to the page as it should go'} (${current(tok, 'light')} in light${modal ? `, ${current(tok, 'dark')} in dark` : ''}), so nothing changes`,
|
|
3845
|
+
options: [],
|
|
3846
|
+
};
|
|
3847
|
+
}
|
|
3848
|
+
// A link's color comes from its color prop, so no part style
|
|
3849
|
+
// reaches it: the accent text token is what a link reads, in every
|
|
3850
|
+
// state.
|
|
3851
|
+
// A link's color in one state: the token, scoped to that state.
|
|
3852
|
+
if (on === 'link' && color && f.state)
|
|
3853
|
+
return {
|
|
3854
|
+
text: `the link color${where}: --color-text-accent on links in that state`,
|
|
3855
|
+
options: [
|
|
3856
|
+
[set('--color-text-accent', color, {...f, ...modeOf(c)})],
|
|
3857
|
+
],
|
|
3858
|
+
};
|
|
3859
|
+
if (on === 'link' && color)
|
|
2042
3860
|
return {
|
|
2043
|
-
text:
|
|
2044
|
-
options: [[set(
|
|
3861
|
+
text: `the link color: --color-text-accent, the token a link reads (it also colors other accent text)${f.state ? `; a link has no color of its own for ${f.state}, so this changes it in every state` : ''}`,
|
|
3862
|
+
options: [[set('--color-text-accent', color, modeOf(c))]],
|
|
2045
3863
|
};
|
|
2046
|
-
}
|
|
2047
3864
|
if (!color) return null;
|
|
3865
|
+
// A part that takes its color from a prop (a heading): the text
|
|
3866
|
+
// token, on that part only.
|
|
3867
|
+
if (!env.check([set('color', color, f)]).ok)
|
|
3868
|
+
return {
|
|
3869
|
+
text: `the text color${where}: --color-text-primary on ${on} only (${on} takes its color from a prop, so a color property never shows)`,
|
|
3870
|
+
options: [[set('--color-text-primary', color, {on, ...modeOf(c)})]],
|
|
3871
|
+
};
|
|
2048
3872
|
return {
|
|
2049
3873
|
text: `text color${where}: color`,
|
|
2050
3874
|
options: [[set('color', color, {...f, ...modeOf(c)})]],
|
|
@@ -2106,17 +3930,49 @@ export function draftAnswer(ctx, env, question) {
|
|
|
2106
3930
|
};
|
|
2107
3931
|
}
|
|
2108
3932
|
if (!on) {
|
|
2109
|
-
const
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
if (!
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
3933
|
+
const color = colorFor(c, 'fill');
|
|
3934
|
+
if (color)
|
|
3935
|
+
return {
|
|
3936
|
+
text: `the page background: --color-background-body${c.mode && modal ? ` in ${c.mode} mode` : ''}`,
|
|
3937
|
+
options: [[set('--color-background-body', color, modeOf(c))]],
|
|
3938
|
+
};
|
|
3939
|
+
if (!c.dir) return null;
|
|
3940
|
+
const lighter = /\blight(er)?|brighter\b/.test(c.text);
|
|
3941
|
+
const steps = perMode(
|
|
3942
|
+
'--color-background-body',
|
|
3943
|
+
'--color-background-body',
|
|
3944
|
+
{},
|
|
3945
|
+
(now, m) => {
|
|
3946
|
+
const v = shift(
|
|
3947
|
+
now,
|
|
3948
|
+
lighter
|
|
3949
|
+
? m === 'dark'
|
|
3950
|
+
? 0.06
|
|
3951
|
+
: 0.5
|
|
3952
|
+
: m === 'dark'
|
|
3953
|
+
? -0.3
|
|
3954
|
+
: -0.06,
|
|
3955
|
+
);
|
|
3956
|
+
// White cannot get lighter, nor black darker.
|
|
3957
|
+
const sum = (/** @type {string | null} */ x) =>
|
|
3958
|
+
(x &&
|
|
3959
|
+
parseColor(x)
|
|
3960
|
+
?.slice(0, 3)
|
|
3961
|
+
.reduce((p, q) => p + q, 0)) ??
|
|
3962
|
+
0;
|
|
3963
|
+
return v && (lighter ? sum(v) > sum(now) : sum(v) < sum(now))
|
|
3964
|
+
? v
|
|
3965
|
+
: null;
|
|
3966
|
+
},
|
|
3967
|
+
c,
|
|
3968
|
+
);
|
|
3969
|
+
return steps.length
|
|
3970
|
+
? {
|
|
3971
|
+
text: `a ${lighter ? 'lighter' : 'darker'} page background: --color-background-body${modesSaid(steps)}`,
|
|
3972
|
+
options: [steps],
|
|
3973
|
+
sequence: steps.length > 1,
|
|
3974
|
+
}
|
|
3975
|
+
: null;
|
|
2120
3976
|
}
|
|
2121
3977
|
if (c.decl.background || c.decl['background-color'])
|
|
2122
3978
|
return {
|
|
@@ -2131,6 +3987,21 @@ export function draftAnswer(ctx, env, question) {
|
|
|
2131
3987
|
],
|
|
2132
3988
|
],
|
|
2133
3989
|
};
|
|
3990
|
+
// "from #f58529 to #dd2a7b": the gradient written in the question.
|
|
3991
|
+
// "from #a to #b", "#a 0% to #b 100%": the stops as typed.
|
|
3992
|
+
const ends =
|
|
3993
|
+
/\bfrom\s+(\S+)\s+(?:to|into)\s+(\S+)/.exec(c.text) ??
|
|
3994
|
+
/(#[0-9a-f]{3,8}(?:\s+\d+%)?)\s+(?:to|into)\s+(#[0-9a-f]{3,8}(?:\s+\d+%)?)/.exec(
|
|
3995
|
+
c.text,
|
|
3996
|
+
);
|
|
3997
|
+
const stop = (/** @type {string} */ x) => parseColor(x.split(/\s+/)[0]);
|
|
3998
|
+
if (design && ends && stop(ends[1]) && stop(ends[2]))
|
|
3999
|
+
return {
|
|
4000
|
+
text: `a gradient from ${ends[1]} to ${ends[2]}${where}`,
|
|
4001
|
+
options: [
|
|
4002
|
+
[set('background', `linear-gradient(${ends[1]}, ${ends[2]})`, f)],
|
|
4003
|
+
],
|
|
4004
|
+
};
|
|
2134
4005
|
if (design)
|
|
2135
4006
|
return {
|
|
2136
4007
|
text: `a ${design} fill${where}`,
|
|
@@ -2152,23 +4023,36 @@ export function draftAnswer(ctx, env, question) {
|
|
|
2152
4023
|
sequence: true,
|
|
2153
4024
|
};
|
|
2154
4025
|
if (!color && c.dir) {
|
|
2155
|
-
const tok =
|
|
2156
|
-
C.partReads(one(on), 'background').find(r => r.when.includes(''))
|
|
2157
|
-
?.token ??
|
|
2158
|
-
(FAMILIES.containers.includes(one(on))
|
|
2159
|
-
? '--color-background-card'
|
|
2160
|
-
: '--color-background-surface');
|
|
2161
|
-
const now = tok ? current(tok, c.mode ?? 'light') : null;
|
|
2162
4026
|
const lighter = /\blight(er)?\b/.test(c.text);
|
|
2163
|
-
|
|
2164
|
-
|
|
4027
|
+
const reads = C.partReads(one(on), 'background');
|
|
4028
|
+
const read = C.MAP[one(on)]
|
|
4029
|
+
? (reads.find(r => r.when.includes(''))?.token ??
|
|
4030
|
+
(FAMILIES.containers.includes(one(on))
|
|
4031
|
+
? '--color-background-card'
|
|
4032
|
+
: reads[0]?.token))
|
|
4033
|
+
: null;
|
|
4034
|
+
// A part with no recorded fill: what its color is now is unknown,
|
|
4035
|
+
// so a brightness filter makes it darker or lighter from there.
|
|
4036
|
+
if (!read || f.state)
|
|
2165
4037
|
return {
|
|
2166
|
-
text: `${lighter ? 'a lighter' : 'a darker'}
|
|
4038
|
+
text: `${lighter ? 'a lighter' : 'a darker'} ${on}${where}: a brightness filter, from whatever color it has now`,
|
|
2167
4039
|
options: [
|
|
2168
|
-
[set('filter', `brightness(${lighter ? 1.
|
|
2169
|
-
[set('background-color', color, f)],
|
|
4040
|
+
[set('filter', `brightness(${lighter ? 1.15 : 0.85})`, f)],
|
|
2170
4041
|
],
|
|
2171
4042
|
};
|
|
4043
|
+
const steps = perMode(
|
|
4044
|
+
read,
|
|
4045
|
+
'background',
|
|
4046
|
+
f,
|
|
4047
|
+
now => shift(now, lighter ? 0.12 : -0.12),
|
|
4048
|
+
c,
|
|
4049
|
+
);
|
|
4050
|
+
if (steps.length)
|
|
4051
|
+
return {
|
|
4052
|
+
text: `${lighter ? 'a lighter' : 'a darker'} background${where}, from ${read}${modesSaid(steps)}`,
|
|
4053
|
+
options: [steps],
|
|
4054
|
+
sequence: steps.length > 1,
|
|
4055
|
+
};
|
|
2172
4056
|
}
|
|
2173
4057
|
if (!color && f.state === 'hover')
|
|
2174
4058
|
return {
|
|
@@ -2235,16 +4119,25 @@ export function draftAnswer(ctx, env, question) {
|
|
|
2235
4119
|
}
|
|
2236
4120
|
}
|
|
2237
4121
|
if (/\b(more|higher|high|better) contrast\b|\bcontrast mode\b/.test(t)) {
|
|
2238
|
-
|
|
2239
|
-
const
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
4122
|
+
// Away from the page in each mode: darker on light, lighter on dark.
|
|
4123
|
+
const steps = [
|
|
4124
|
+
...perMode(
|
|
4125
|
+
'--color-text-secondary',
|
|
4126
|
+
'--color-text-secondary',
|
|
4127
|
+
{},
|
|
4128
|
+
(now, m) => shift(now, m === 'dark' ? 0.35 : -0.35),
|
|
4129
|
+
c,
|
|
4130
|
+
),
|
|
4131
|
+
...perMode(
|
|
4132
|
+
'--color-border',
|
|
4133
|
+
'--color-border',
|
|
4134
|
+
{},
|
|
4135
|
+
(now, m) => stronger(now, 2.5, m),
|
|
4136
|
+
c,
|
|
4137
|
+
),
|
|
4138
|
+
];
|
|
2246
4139
|
return {
|
|
2247
|
-
text: `more contrast:
|
|
4140
|
+
text: `more contrast: secondary text further from the page and stronger borders${modal && !c.mode ? ', in light and in dark mode, each from its own value' : c.mode ? ` in ${c.mode} mode` : ''}`,
|
|
2248
4141
|
options: [steps],
|
|
2249
4142
|
sequence: steps.length > 1,
|
|
2250
4143
|
};
|
|
@@ -2257,12 +4150,18 @@ export function draftAnswer(ctx, env, question) {
|
|
|
2257
4150
|
: 'a theme that is always dark: mode dark-only',
|
|
2258
4151
|
options: [[set('mode', 'dark-only')]],
|
|
2259
4152
|
};
|
|
2260
|
-
if (/\b(undo|revert|go back|take back)\b/.test(t))
|
|
2261
|
-
return
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
4153
|
+
if (/\b(undo|revert|go back|take back)\b/.test(t) && !c.colors.length)
|
|
4154
|
+
return env.undoSteps
|
|
4155
|
+
? {
|
|
4156
|
+
text: `undo ${env.slug} steps back one change (${env.undoSteps} can be undone); undo ${env.slug} <thing> removes one setting`,
|
|
4157
|
+
options: [],
|
|
4158
|
+
lookup: `${P} undo ${env.slug}`,
|
|
4159
|
+
}
|
|
4160
|
+
: {
|
|
4161
|
+
text: `${env.slug} has no change to undo yet; show ${env.slug} lists its settings`,
|
|
4162
|
+
options: [],
|
|
4163
|
+
...(env.exists ? {lookup: `${P} show ${env.slug}`} : {}),
|
|
4164
|
+
};
|
|
2266
4165
|
if (/\breset\b|\bstart over\b|\bback to (the )?defaults?\b/.test(t))
|
|
2267
4166
|
return {
|
|
2268
4167
|
text: `each undo ${env.slug} steps back one change; show ${env.slug} lists every setting, and undo ${env.slug} <thing> removes one`,
|
|
@@ -2271,7 +4170,20 @@ export function draftAnswer(ctx, env, question) {
|
|
|
2271
4170
|
};
|
|
2272
4171
|
if (/\b(dark|light)\b/.test(t) && /\b(mode|theme|only)\b/.test(t))
|
|
2273
4172
|
seenAspect('mode');
|
|
2274
|
-
if (
|
|
4173
|
+
if (
|
|
4174
|
+
/\bdark[- ]?(mode|theme)? only\b|\bonly dark\b|\bdark-only\b|\bdark by default\b|\bdefault(s)? to dark\b|\balways dark\b/.test(
|
|
4175
|
+
t,
|
|
4176
|
+
) &&
|
|
4177
|
+
// "in dark mode only, cards #111111": the mode scopes the other ask.
|
|
4178
|
+
// "dark only" with no "mode" word describes the theme's look.
|
|
4179
|
+
(/\balways dark\b|\b(theme|app)\b/.test(t) ||
|
|
4180
|
+
!/\bmode\b|\bin dark\b/.test(t) ||
|
|
4181
|
+
!clauses.some(
|
|
4182
|
+
o =>
|
|
4183
|
+
o.text !== c.text &&
|
|
4184
|
+
(o.parts.length || o.colors.length || o.aspects.length),
|
|
4185
|
+
))
|
|
4186
|
+
)
|
|
2275
4187
|
return {
|
|
2276
4188
|
text: 'a theme with only a dark mode: mode dark-only',
|
|
2277
4189
|
options: [[set('mode', 'dark-only')]],
|
|
@@ -2302,6 +4214,10 @@ export function draftAnswer(ctx, env, question) {
|
|
|
2302
4214
|
/\b(colou?rful|saturat\w*|desaturat\w*|vivid|vibran\w*|muted|dull|washed|pastel|intense|pop|punch\w*|gr[ae]yer)\b/.test(
|
|
2303
4215
|
t,
|
|
2304
4216
|
);
|
|
4217
|
+
if (vib && c.colors.length && ROLE_WORDS.test(t)) {
|
|
4218
|
+
const named = roleAnswer(c);
|
|
4219
|
+
if (named) return named;
|
|
4220
|
+
}
|
|
2305
4221
|
if (vib) {
|
|
2306
4222
|
seenAspect('colors');
|
|
2307
4223
|
const less =
|
|
@@ -2347,9 +4263,9 @@ export function draftAnswer(ctx, env, question) {
|
|
|
2347
4263
|
) {
|
|
2348
4264
|
seenAspect('colors');
|
|
2349
4265
|
return {
|
|
2350
|
-
text:
|
|
4266
|
+
text: `Every shade of every color, light and dark, with the tokens that use each, is on the Colors page of the in-app preview. It changes with every set.${env.previewDamage ? ` The preview cannot be changed now: ${env.previewDamage}` : ''}`,
|
|
2351
4267
|
options: [],
|
|
2352
|
-
...(env.exists
|
|
4268
|
+
...(env.exists && !env.previewDamage
|
|
2353
4269
|
? {
|
|
2354
4270
|
lookup: `astryx experimental theme preview add --theme ${env.slug}`,
|
|
2355
4271
|
}
|
|
@@ -2393,78 +4309,212 @@ export function draftAnswer(ctx, env, question) {
|
|
|
2393
4309
|
lookup: `${HOW} colors`,
|
|
2394
4310
|
};
|
|
2395
4311
|
}
|
|
2396
|
-
|
|
2397
|
-
|
|
4312
|
+
const named = roleAnswer(c);
|
|
4313
|
+
if (named) return named;
|
|
4314
|
+
// A color with nothing else named, in a question about a look ("Duolingo
|
|
4315
|
+
// vibes: green #58cc02"), is the brand color.
|
|
4316
|
+
if (
|
|
4317
|
+
/#[0-9a-f]{3,8}\b|\b(?:rgba?|hsla?|oklch)\(/.test(c.text) &&
|
|
4318
|
+
!c.parts.length &&
|
|
4319
|
+
!c.aspects.length &&
|
|
4320
|
+
!c.lengths.length &&
|
|
4321
|
+
c.text
|
|
4322
|
+
.replace(/#[0-9a-f]+|\b(?:rgba?|hsla?|oklch)\([^)]*\)/g, '')
|
|
4323
|
+
.replace(new RegExp(`\\b(${Object.keys(HUES).join('|')})\\b`, 'g'), '')
|
|
4324
|
+
.trim()
|
|
4325
|
+
.split(/\s+/)
|
|
4326
|
+
.filter(Boolean).length <= 2 &&
|
|
4327
|
+
/\b(look|vibes?|style|like|feel|brand|theme)\b/.test(
|
|
4328
|
+
question.toLowerCase(),
|
|
4329
|
+
)
|
|
4330
|
+
)
|
|
4331
|
+
return roleAnswer({...c, text: `accent ${c.text}`});
|
|
4332
|
+
return null;
|
|
4333
|
+
}
|
|
4334
|
+
|
|
4335
|
+
/**
|
|
4336
|
+
* The colors the theme generates that a clause names, each with its own
|
|
4337
|
+
* color: the color right after the word, or right before it when nothing
|
|
4338
|
+
* follows ("#0d6efd primary"). A color is used once.
|
|
4339
|
+
* @param {Clause} c
|
|
4340
|
+
* @returns {Draft | null}
|
|
4341
|
+
*/
|
|
4342
|
+
function roleAnswer(c) {
|
|
4343
|
+
const t = c.text;
|
|
4344
|
+
const ROLES = /** @type {Array<[RegExp, string, string]>} */ ([
|
|
2398
4345
|
[
|
|
2399
|
-
/\b(accent|brand|primary
|
|
4346
|
+
/\b(accent|brand|primary|main colou?r|key colou?r)\b/g,
|
|
2400
4347
|
'accent',
|
|
2401
4348
|
'--color-accent',
|
|
2402
4349
|
],
|
|
2403
|
-
[/\b(errors?|danger|destructive)\b
|
|
2404
|
-
[/\b(success|positive)\b
|
|
2405
|
-
[/\b(warnings?|caution)\b
|
|
2406
|
-
[/\b(info|notices?)\b
|
|
4350
|
+
[/\b(errors?|danger|destructive)\b/g, 'danger', '--color-error'],
|
|
4351
|
+
[/\b(success|positive)\b/g, 'success', '--color-success'],
|
|
4352
|
+
[/\b(warnings?|caution)\b/g, 'warning', '--color-warning'],
|
|
4353
|
+
[/\b(info|notices?)\b/g, 'info', '--color-info'],
|
|
2407
4354
|
[
|
|
2408
|
-
/\b(neutrals?|gr[ae]ys?|warm(er)?|cool(er)?)\b
|
|
4355
|
+
/\b(neutrals?|gr[ae]ys?|warm(er)?|cool(er)?)\b/g,
|
|
2409
4356
|
'neutral',
|
|
2410
4357
|
'--color-neutral',
|
|
2411
4358
|
],
|
|
4359
|
+
[/\bsecondary\b(?! (text|buttons?))/g, 'secondary', ''],
|
|
2412
4360
|
]);
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
const
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
4361
|
+
/** @type {Array<{at: number, dial: string, token: string}>} */
|
|
4362
|
+
const found = [];
|
|
4363
|
+
for (const [re, dial, token] of ROLES)
|
|
4364
|
+
for (const m of t.matchAll(re))
|
|
4365
|
+
if (!found.some(x => x.dial === dial))
|
|
4366
|
+
found.push({at: m.index ?? 0, dial, token});
|
|
4367
|
+
if (!found.length) return null;
|
|
4368
|
+
found.sort((x, y) => x.at - y.at);
|
|
4369
|
+
seenAspect('colors');
|
|
4370
|
+
// Each color written in the clause, where it is.
|
|
4371
|
+
const placed = [
|
|
4372
|
+
...t.matchAll(
|
|
4373
|
+
/#[0-9a-f]{3,8}\b|\b(?:rgba?|hsla?|hwb|lab|lch|oklab|oklch)\([^)]*\)/g,
|
|
4374
|
+
),
|
|
4375
|
+
]
|
|
4376
|
+
.filter(m => parseColor(m[0]))
|
|
4377
|
+
.map(m => ({at: m.index ?? 0, color: m[0], used: false}));
|
|
4378
|
+
const hues = c.colors.filter(x => !placed.some(p => p.color === x));
|
|
4379
|
+
/** @type {Draft[]} */
|
|
4380
|
+
const answers = [];
|
|
4381
|
+
for (let i = 0; i < found.length; i++) {
|
|
4382
|
+
const {at, dial, token} = found[i];
|
|
4383
|
+
const end = found[i + 1]?.at ?? Infinity;
|
|
4384
|
+
const after = placed.find(p => !p.used && p.at > at && p.at < end);
|
|
4385
|
+
const before = [...placed].reverse().find(p => !p.used && p.at < at);
|
|
4386
|
+
const pick = after ?? (found.length === 1 || !after ? before : undefined);
|
|
4387
|
+
if (pick) pick.used = true;
|
|
4388
|
+
answers.push(
|
|
4389
|
+
one1(
|
|
4390
|
+
dial,
|
|
4391
|
+
token,
|
|
4392
|
+
pick?.color ?? (found.length === 1 ? hues[0] : undefined) ?? null,
|
|
4393
|
+
c,
|
|
4394
|
+
),
|
|
4395
|
+
);
|
|
4396
|
+
}
|
|
4397
|
+
const doing = answers.filter(x => x.options.length);
|
|
4398
|
+
if (doing.length > 1)
|
|
4399
|
+
return {
|
|
4400
|
+
text: doing.map(x => x.text).join('; '),
|
|
4401
|
+
options: [doing.map(x => x.options[0][0])],
|
|
4402
|
+
sequence: true,
|
|
4403
|
+
};
|
|
4404
|
+
return doing[0] ?? answers[0];
|
|
4405
|
+
}
|
|
4406
|
+
|
|
4407
|
+
/**
|
|
4408
|
+
* One color the theme generates, set from a clause.
|
|
4409
|
+
* @param {string} dial @param {string} token @param {string | null} given @param {Clause} c
|
|
4410
|
+
* @returns {Draft}
|
|
4411
|
+
*/
|
|
4412
|
+
function one1(dial, token, given, c) {
|
|
4413
|
+
const t = c.text;
|
|
4414
|
+
if (dial === 'secondary')
|
|
4415
|
+
return given
|
|
4416
|
+
? {
|
|
4417
|
+
text: `no setting is a second brand color; for secondary buttons, their fill: background ${given} --on button --when variant:secondary`,
|
|
4418
|
+
options: [
|
|
4419
|
+
[
|
|
4420
|
+
set('background', given, {
|
|
4421
|
+
on: 'button',
|
|
4422
|
+
when: 'variant:secondary',
|
|
4423
|
+
}),
|
|
4424
|
+
],
|
|
4425
|
+
],
|
|
4426
|
+
}
|
|
4427
|
+
: {text: 'no setting is a second brand color', options: []};
|
|
4428
|
+
let color =
|
|
4429
|
+
given &&
|
|
4430
|
+
!(
|
|
4431
|
+
dial === 'neutral' &&
|
|
4432
|
+
['#9ca3af', '#e5e7eb', '#374151', '#f3f4f6'].includes(given)
|
|
4433
|
+
)
|
|
4434
|
+
? given
|
|
4435
|
+
: null;
|
|
4436
|
+
if (dial === 'neutral' && !color)
|
|
4437
|
+
// "too warm" asks for cooler, "too cool" for warmer.
|
|
4438
|
+
color = /\btoo warm\b|\bcool(er)?\b/.test(t)
|
|
4439
|
+
? '#64748b'
|
|
4440
|
+
: /\btoo cool\b|\bwarm(er)?\b/.test(t)
|
|
2427
4441
|
? '#78716c'
|
|
2428
|
-
:
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
text: `${DIALS[dial].help} Give the color: set ${env.slug} ${dial} <color>.`,
|
|
2454
|
-
options: [],
|
|
2455
|
-
lookup: `${HOW} ${dial}`,
|
|
2456
|
-
};
|
|
2457
|
-
if (c.mode && modal)
|
|
4442
|
+
: null;
|
|
4443
|
+
// "make the error red darker": the hue names the color; the change is darker.
|
|
4444
|
+
const NATURAL = /** @type {Record<string, string>} */ ({
|
|
4445
|
+
danger: HUES.red,
|
|
4446
|
+
success: HUES.green,
|
|
4447
|
+
warning: HUES.yellow,
|
|
4448
|
+
info: HUES.blue,
|
|
4449
|
+
});
|
|
4450
|
+
if (c.dir && color && (color === NATURAL[dial] || color === HUES.amber))
|
|
4451
|
+
color = null;
|
|
4452
|
+
if (!color && c.dir && !/\btoo (warm|cool)\b/.test(t)) {
|
|
4453
|
+
// "too dark" asks for lighter, "too bright" for darker.
|
|
4454
|
+
const lighter =
|
|
4455
|
+
/\btoo dark\b/.test(t) ||
|
|
4456
|
+
/\b(light(er)?|brighter|paler)\b/.test(
|
|
4457
|
+
t.replace(/\btoo (light|bright|pale)\b/g, ' '),
|
|
4458
|
+
);
|
|
4459
|
+
if (c.mode && modal) {
|
|
4460
|
+
const steps = perMode(
|
|
4461
|
+
token,
|
|
4462
|
+
token,
|
|
4463
|
+
{},
|
|
4464
|
+
now => shift(now, lighter ? 0.2 : -0.2),
|
|
4465
|
+
c,
|
|
4466
|
+
);
|
|
2458
4467
|
return {
|
|
2459
4468
|
text: `${dial} in ${c.mode} mode only: the exact token ${token}`,
|
|
2460
|
-
options: [
|
|
4469
|
+
options: steps.length ? [steps] : [],
|
|
2461
4470
|
};
|
|
4471
|
+
}
|
|
4472
|
+
color = shift(current(token, 'light'), lighter ? 0.2 : -0.2);
|
|
4473
|
+
}
|
|
4474
|
+
if (!color)
|
|
2462
4475
|
return {
|
|
2463
|
-
text: `${dial}
|
|
2464
|
-
options: [
|
|
4476
|
+
text: `${DIALS[dial].help} Give the color: set ${env.slug} ${dial} <color>.`,
|
|
4477
|
+
options: [],
|
|
4478
|
+
lookup: `${HOW} ${dial}`,
|
|
2465
4479
|
};
|
|
2466
|
-
|
|
2467
|
-
|
|
4480
|
+
if (c.mode && modal)
|
|
4481
|
+
return {
|
|
4482
|
+
text: `${dial} in ${c.mode} mode only: the exact token ${token}`,
|
|
4483
|
+
options: [[set(token, color, modeOf(c))]],
|
|
4484
|
+
};
|
|
4485
|
+
return {
|
|
4486
|
+
text: `${dial}: the editor makes its light and dark shades from ${color}`,
|
|
4487
|
+
options: [[set(dial, color)], [set(token, color)]],
|
|
4488
|
+
};
|
|
4489
|
+
}
|
|
4490
|
+
|
|
4491
|
+
/**
|
|
4492
|
+
* A part word how cannot name: the clause starts with a word a component
|
|
4493
|
+
* doc lists as a keyword, or a near catalog name, and asks for a shape
|
|
4494
|
+
* change. Gives the word and the parts of the components that list it.
|
|
4495
|
+
* @param {string} text
|
|
4496
|
+
* @returns {{word: string, parts: string[]} | null}
|
|
4497
|
+
*/
|
|
4498
|
+
function unknownPart(text) {
|
|
4499
|
+
const m =
|
|
4500
|
+
/^(?:the |a |an |my |our |all |every )?([a-z]+)\b(?: [a-z]+)? (?:rounder|rounded|bolder|bold|bigger|smaller|taller|wider|darker|lighter|padding|shadow|border|corners?|radius)\b/.exec(
|
|
4501
|
+
text,
|
|
4502
|
+
);
|
|
4503
|
+
if (!m) return null;
|
|
4504
|
+
const word = singular(m[1]);
|
|
4505
|
+
// A word how reads as a change ("border radius") is not a part.
|
|
4506
|
+
if (aspectsOf(word).length || aspectsOf(m[1]).length) return null;
|
|
4507
|
+
const owners = Object.values(ctx.project.components)
|
|
4508
|
+
.filter(info =>
|
|
4509
|
+
(info.keywords ?? []).some(
|
|
4510
|
+
k => singular(String(k).toLowerCase()) === word,
|
|
4511
|
+
),
|
|
4512
|
+
)
|
|
4513
|
+
.map(info => info.targets[0]?.className.replace(/^astryx-/, ''))
|
|
4514
|
+
.filter(t => t && TARGET.has(t));
|
|
4515
|
+
return owners.length
|
|
4516
|
+
? {word, parts: [...new Set(owners)].slice(0, 4)}
|
|
4517
|
+
: null;
|
|
2468
4518
|
}
|
|
2469
4519
|
|
|
2470
4520
|
/**
|
|
@@ -2481,20 +4531,7 @@ export function draftAnswer(ctx, env, question) {
|
|
|
2481
4531
|
case: 'font',
|
|
2482
4532
|
italic: 'font',
|
|
2483
4533
|
})[a] ?? a;
|
|
2484
|
-
if (
|
|
2485
|
-
!C.MAP[one(on)] ||
|
|
2486
|
-
![
|
|
2487
|
-
'text',
|
|
2488
|
-
'background',
|
|
2489
|
-
'border',
|
|
2490
|
-
'corners',
|
|
2491
|
-
'shadow',
|
|
2492
|
-
'spacing',
|
|
2493
|
-
'font',
|
|
2494
|
-
'size',
|
|
2495
|
-
].includes(group)
|
|
2496
|
-
)
|
|
2497
|
-
return '';
|
|
4534
|
+
if (!C.MAP[one(on)] || !Object.hasOwn(GROUPS, group)) return '';
|
|
2498
4535
|
// Reads that always apply first; partReads sorts them so.
|
|
2499
4536
|
const toks = C.partReads(one(on), group)
|
|
2500
4537
|
.map(r => r.token)
|
|
@@ -2525,7 +4562,12 @@ export function draftAnswer(ctx, env, question) {
|
|
|
2525
4562
|
for (const {clause, steps} of tops)
|
|
2526
4563
|
for (const st of steps) {
|
|
2527
4564
|
const prior = last.get(idOf(st));
|
|
2528
|
-
if (
|
|
4565
|
+
if (
|
|
4566
|
+
prior &&
|
|
4567
|
+
prior.clause !== clause &&
|
|
4568
|
+
prior.step.value !== st.value &&
|
|
4569
|
+
(prior.clause.mode ?? '') === (clause.mode ?? '')
|
|
4570
|
+
)
|
|
2529
4571
|
clashes.push([prior.step, st]);
|
|
2530
4572
|
last.delete(idOf(st));
|
|
2531
4573
|
last.set(idOf(st), {step: st, clause});
|
|
@@ -2538,7 +4580,22 @@ export function draftAnswer(ctx, env, question) {
|
|
|
2538
4580
|
options: [[a], [b]],
|
|
2539
4581
|
});
|
|
2540
4582
|
} else if (last.size > 1 && clauses.length > 1) {
|
|
2541
|
-
|
|
4583
|
+
// The page never takes the color the text takes in the same mode.
|
|
4584
|
+
const all = [...last.values()]
|
|
4585
|
+
.map(x => x.step)
|
|
4586
|
+
.filter(
|
|
4587
|
+
(st, i, list) =>
|
|
4588
|
+
!(
|
|
4589
|
+
st.thing === '--color-background-body' &&
|
|
4590
|
+
list.some(
|
|
4591
|
+
t =>
|
|
4592
|
+
t.thing === '--color-text-primary' &&
|
|
4593
|
+
String(t.value).toLowerCase() ===
|
|
4594
|
+
String(st.value).toLowerCase() &&
|
|
4595
|
+
(!t.mode || !st.mode || t.mode === st.mode),
|
|
4596
|
+
)
|
|
4597
|
+
),
|
|
4598
|
+
);
|
|
2542
4599
|
result.push({
|
|
2543
4600
|
text:
|
|
2544
4601
|
all.length > MAX_STEPS
|
|
@@ -2552,23 +4609,138 @@ export function draftAnswer(ctx, env, question) {
|
|
|
2552
4609
|
return {parts: partsSeen, aspects: aspectsSeen, drafts: result};
|
|
2553
4610
|
}
|
|
2554
4611
|
|
|
4612
|
+
/** Words for the operating system's own font. */
|
|
4613
|
+
const OS_FONT =
|
|
4614
|
+
/^(mac|macos|apple|windows|ios|android|os)$|\b(mac|macos|apple|windows|ios|android|os|system)('s)?( default| own| native)?( ui)? (font|typeface)\b|\bdefault (mac|apple|windows|system|os) (font|typeface)\b/i;
|
|
4615
|
+
|
|
4616
|
+
/**
|
|
4617
|
+
* A family a clean machine already has (the editor's font check reads the
|
|
4618
|
+
* same list), named in the clause and written with its capitals in the
|
|
4619
|
+
* question, as typed there.
|
|
4620
|
+
* @param {string} c the clause, lower-case
|
|
4621
|
+
* @param {string} question
|
|
4622
|
+
*/
|
|
4623
|
+
function systemFamilyIn(c, question) {
|
|
4624
|
+
const generic = new Set(keywordsOf('font-family'));
|
|
4625
|
+
const words = [...question.matchAll(/[A-Za-z][\w-]*/g)];
|
|
4626
|
+
/** @type {string | null} */
|
|
4627
|
+
let best = null;
|
|
4628
|
+
// The longest run of words, starting with a capital, that names one.
|
|
4629
|
+
for (let i = 0; i < words.length; i++) {
|
|
4630
|
+
if (!/^[A-Z]/.test(words[i][0])) continue;
|
|
4631
|
+
for (let n = Math.min(4, words.length - i); n >= 1; n--) {
|
|
4632
|
+
const run = words.slice(i, i + n);
|
|
4633
|
+
const gap = run.every(
|
|
4634
|
+
(w, k) =>
|
|
4635
|
+
k === 0 ||
|
|
4636
|
+
/^\s+$/.test(
|
|
4637
|
+
question.slice(
|
|
4638
|
+
/** @type {number} */ (run[k - 1].index) + run[k - 1][0].length,
|
|
4639
|
+
w.index,
|
|
4640
|
+
),
|
|
4641
|
+
),
|
|
4642
|
+
);
|
|
4643
|
+
if (!gap) continue;
|
|
4644
|
+
const name = run.map(w => w[0]).join(' ');
|
|
4645
|
+
const low = name.toLowerCase();
|
|
4646
|
+
if (
|
|
4647
|
+
generic.has(low) ||
|
|
4648
|
+
!new RegExp(`\\b${low}\\b`).test(c) ||
|
|
4649
|
+
!isSystemFamily(name)
|
|
4650
|
+
)
|
|
4651
|
+
continue;
|
|
4652
|
+
if (!best || name.length > best.length) best = name;
|
|
4653
|
+
break;
|
|
4654
|
+
}
|
|
4655
|
+
}
|
|
4656
|
+
return best;
|
|
4657
|
+
}
|
|
4658
|
+
|
|
2555
4659
|
/**
|
|
2556
4660
|
* A font a clause names: a preset, an open font, or a family written with
|
|
2557
4661
|
* capitals in the question.
|
|
2558
|
-
* @param {string}
|
|
4662
|
+
* @param {{text: string, quoted?: string[]}} cl the clause, lower-case
|
|
2559
4663
|
* @param {string} question the question as typed
|
|
2560
4664
|
*/
|
|
2561
|
-
function fontIn(
|
|
4665
|
+
function fontIn(cl, question) {
|
|
4666
|
+
const c = cl.text.replace(/\bsanz\b/g, 'sans');
|
|
4667
|
+
// A family written in quotes, as typed: a shipped font when it names one.
|
|
4668
|
+
for (const name of cl.quoted ?? []) {
|
|
4669
|
+
const low = name.toLowerCase();
|
|
4670
|
+
const slug =
|
|
4671
|
+
Object.keys(OPEN_FONTS).find(
|
|
4672
|
+
k =>
|
|
4673
|
+
OPEN_FONTS[k].family.toLowerCase() === low ||
|
|
4674
|
+
k === low.replace(/\s+/g, '-'),
|
|
4675
|
+
) ??
|
|
4676
|
+
Object.keys(FONTS).find(
|
|
4677
|
+
k => k === low || FONTS[k][0].toLowerCase() === low,
|
|
4678
|
+
);
|
|
4679
|
+
return slug ?? name;
|
|
4680
|
+
}
|
|
4681
|
+
// A shipped font named in the clause, the longest name first, so "Geist
|
|
4682
|
+
// Mono" is not Geist and "DM Sans" is not the generic sans.
|
|
4683
|
+
const shipped = [...Object.keys(OPEN_FONTS), ...Object.keys(FONTS)].sort(
|
|
4684
|
+
(x, y) => y.length - x.length,
|
|
4685
|
+
);
|
|
4686
|
+
// The generic stacks are read last, so "sans-serif" is not "serif".
|
|
4687
|
+
const known = shipped.find(
|
|
4688
|
+
k =>
|
|
4689
|
+
!['system', 'serif', 'mono'].includes(k) &&
|
|
4690
|
+
new RegExp(`\\b${k.replace(/-/g, '[\\s-]')}\\b`).test(c),
|
|
4691
|
+
);
|
|
4692
|
+
// A name as typed, up to four words ("Source Sans 3", "Roboto Slab"):
|
|
4693
|
+
// after "use" or "font", or before "font"; one this clause names.
|
|
4694
|
+
const GENERIC =
|
|
4695
|
+
/^(a|an|the|my|our|this|that|any|some|same|another|different|new|nice|modern|bold|light|thin|heavy|big|small|serif|sans|sans-serif|mono|monospace|system|default|body|heading|headings|code|for|on|in|dark|light|night)$/i;
|
|
4696
|
+
const NAME =
|
|
4697
|
+
"([A-Z][\\w-]*(?:'[\\w-]+)*(?: (?:[A-Z][\\w-]*(?:'[\\w-]+)*|\\d+)){0,3})";
|
|
4698
|
+
/** @type {string | undefined} */
|
|
4699
|
+
let typed;
|
|
4700
|
+
for (const re of [
|
|
4701
|
+
new RegExp(
|
|
4702
|
+
`\\b(?:[Uu]se|[Ff]ont|[Tt]ypeface|[Tt]o|in)s?:?\\s+["']?${NAME}`,
|
|
4703
|
+
'g',
|
|
4704
|
+
),
|
|
4705
|
+
new RegExp(`\\b${NAME}\\s+(?:font|typeface)\\b`, 'g'),
|
|
4706
|
+
// "Plus Jakarta Sans as the main font", "Arial everywhere", "Fira
|
|
4707
|
+
// Code for monospace".
|
|
4708
|
+
new RegExp(
|
|
4709
|
+
`(?:^|[\\s,;:])${NAME}\\s+(?:as|for|everywhere|throughout|across)\\b`,
|
|
4710
|
+
'g',
|
|
4711
|
+
),
|
|
4712
|
+
]) {
|
|
4713
|
+
for (const m of question.matchAll(re)) {
|
|
4714
|
+
const name = m[1].replace(/ (Font|Typeface)$/, '');
|
|
4715
|
+
if (GENERIC.test(name.split(' ')[0]) || OS_FONT.test(name)) continue;
|
|
4716
|
+
// "Plus Jakarta Sans": a clause break word may start the name.
|
|
4717
|
+
const low = name.toLowerCase();
|
|
4718
|
+
if (
|
|
4719
|
+
c.includes(low) ||
|
|
4720
|
+
(low.split(' ').length > 2 && c.includes(low.replace(/^\S+ /, '')))
|
|
4721
|
+
) {
|
|
4722
|
+
typed = name;
|
|
4723
|
+
break;
|
|
4724
|
+
}
|
|
4725
|
+
}
|
|
4726
|
+
if (typed) break;
|
|
4727
|
+
}
|
|
4728
|
+
// "Roboto Mono" is not Roboto: a longer typed name wins over a shipped
|
|
4729
|
+
// one inside it.
|
|
4730
|
+
if (
|
|
4731
|
+
typed &&
|
|
4732
|
+
(!known || typed.replace(/\s+/g, '-').toLowerCase().length > known.length)
|
|
4733
|
+
)
|
|
4734
|
+
return typed;
|
|
4735
|
+
if (known) return known;
|
|
4736
|
+
// "the default Mac font": the system font.
|
|
4737
|
+
if (OS_FONT.test(c)) return 'system';
|
|
4738
|
+
// A family every machine has, named with its capitals ("use Menlo").
|
|
4739
|
+
const local = systemFamilyIn(c, question);
|
|
4740
|
+
if (local) return local;
|
|
2562
4741
|
if (/\bmono(space|spaced)?\b/.test(c)) return 'mono';
|
|
2563
4742
|
if (/\bsans(-serif)?\b/.test(c)) return 'system';
|
|
2564
4743
|
if (/\bserif\b/.test(c)) return 'serif';
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
if (new RegExp(`\\b${words}\\b`).test(c)) return k;
|
|
2568
|
-
}
|
|
2569
|
-
const typed =
|
|
2570
|
-
/\b(?:use|font|typeface)\s+["']?([A-Z][\w-]*(?: [A-Z][\w-]*)?)["']?/.exec(
|
|
2571
|
-
question,
|
|
2572
|
-
)?.[1];
|
|
2573
|
-
return typed ?? null;
|
|
4744
|
+
if (/\bsystem(-ui)?\b/.test(c)) return 'system';
|
|
4745
|
+
return null;
|
|
2574
4746
|
}
|