@astryxdesign/cli 0.7.15 → 0.7.16-canary.g22213fd
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -4
- package/api/build/_adapter.d.mts +10 -0
- package/api/build/_adapter.mjs +24 -0
- package/api/build/blocks/blocks.d.mts +1 -0
- package/api/build/blocks/blocks.mjs +18 -1
- package/api/build/kit/shell.weights.json +1 -0
- package/api/build/kit/shellcall.d.mts +26 -0
- package/api/build/kit/shellcall.mjs +87 -0
- package/api/build/kit/start.mjs +67 -4
- package/api/build/kit/weights.d.mts +15 -0
- package/api/build/kit/weights.mjs +27 -0
- package/api/component/__fixtures__/resolutions/modules.txt +1 -1
- package/api/component/_adapter.d.mts +1 -1
- package/api/component/_adapter.mjs +28 -1
- package/api/doctor/_adapter.d.mts +38 -2
- package/api/doctor/_adapter.mjs +76 -1
- package/api/doctor/built-checks.mjs +1 -1
- package/api/doctor/doctor.d.mts +26 -0
- package/api/doctor/doctor.doc.mjs +1 -1
- package/api/doctor/doctor.mjs +156 -11
- package/api/doctor/theme-checks.mjs +163 -18
- package/api/icon/_adapter.d.mts +7 -3
- package/api/icon/_adapter.mjs +12 -3
- package/api/icon/icon.type.d.mts +15 -0
- package/api/icon/icon.type.mjs +10 -3
- package/api/icon/iconUse.doc.mjs +19 -5
- package/api/icon/list/list.mjs +7 -1
- package/api/icon/use/use.d.mts +8 -5
- package/api/icon/use/use.mjs +95 -13
- package/api/init/run/run.mjs +1 -0
- package/api/integration/add-contribution.mjs +3 -3
- package/api/integration/pack-check.mjs +14 -8
- package/api/integration/validate-integration.mjs +1 -1
- package/api/search/_adapter.mjs +15 -16
- package/api/search/_entries.d.mts +2 -1
- package/api/search/_entries.mjs +28 -1
- package/api/swizzle/_moduleGraph.mjs +1 -1
- package/api/template/template.type.d.mts +6 -2
- package/api/template/template.type.mjs +2 -1
- package/api/theme/_adapter.d.mts +5 -2
- package/api/theme/_adapter.mjs +59 -14
- package/api/theme/_fork.mjs +1 -1
- package/api/theme/build/build.d.mts +120 -32
- package/api/theme/build/build.mjs +471 -111
- package/api/theme/eject/eject.mjs +22 -1
- package/api/theme/generateTonalPalette.doc.mjs +2 -2
- package/api/theme/palette/generate/generator.mjs +141 -2
- package/api/theme/template/template.d.mts +19 -0
- package/api/theme/template/template.mjs +102 -25
- package/api/theme/theme.type.d.mts +44 -1
- package/api/theme/theme.type.mjs +23 -1
- package/api/theme/themeBuild.doc.mjs +4 -4
- package/api/theme/themeEject.doc.mjs +1 -1
- package/api/theme/themePaletteGenerate.doc.mjs +1 -1
- package/api/theme/themeTemplate.doc.mjs +9 -3
- package/api/theme-edit/_adapter.d.mts +33 -2
- package/api/theme-edit/_adapter.mjs +276 -41
- package/api/theme-edit/_check.d.mts +93 -4
- package/api/theme-edit/_check.mjs +1712 -223
- package/api/theme-edit/_color.d.mts +2 -8
- package/api/theme-edit/_color.mjs +292 -219
- package/api/theme-edit/_compiler.d.mts +1 -0
- package/api/theme-edit/_compiler.mjs +20 -1
- package/api/theme-edit/_context.d.mts +31 -1
- package/api/theme-edit/_context.mjs +445 -41
- package/api/theme-edit/_css.d.mts +60 -1
- package/api/theme-edit/_css.mjs +404 -28
- package/api/theme-edit/_edit.d.mts +25 -0
- package/api/theme-edit/_edit.mjs +1620 -154
- package/api/theme-edit/_how-commands.d.mts +11 -26
- package/api/theme-edit/_how-commands.mjs +30 -2
- package/api/theme-edit/_how-question.d.mts +15 -0
- package/api/theme-edit/_how-question.mjs +1469 -194
- package/api/theme-edit/_how.mjs +144 -30
- package/api/theme-edit/_marks.d.mts +13 -0
- package/api/theme-edit/_marks.mjs +15 -0
- package/api/theme-edit/_overview.mjs +2 -0
- package/api/theme-edit/_palette.d.mts +38 -0
- package/api/theme-edit/_palette.mjs +306 -73
- package/api/theme-edit/_parts.d.mts +33 -0
- package/api/theme-edit/_parts.mjs +138 -9
- package/api/theme-edit/_png.d.mts +18 -0
- package/api/theme-edit/_png.mjs +95 -14
- package/api/theme-edit/_preview-app.d.mts +55 -1
- package/api/theme-edit/_preview-app.mjs +1552 -101
- package/api/theme-edit/_preview.d.mts +71 -3
- package/api/theme-edit/_preview.mjs +565 -35
- package/api/theme-edit/_project.d.mts +15 -0
- package/api/theme-edit/_project.mjs +68 -13
- package/api/theme-edit/_settings.d.mts +299 -5
- package/api/theme-edit/_settings.mjs +2806 -158
- package/api/theme-edit/_tables.d.mts +24 -0
- package/api/theme-edit/_tables.mjs +212 -150
- package/api/theme-edit/_vet.d.mts +42 -0
- package/api/theme-edit/_vet.mjs +144 -0
- package/api/theme-edit/theme-edit.type.d.mts +31 -2
- package/api/theme-edit/theme-edit.type.mjs +10 -2
- package/api/theme-edit/themeEditNew.doc.mjs +1 -1
- package/api/theme-edit/themeEditPreviewApp.doc.mjs +1 -1
- package/api/theme-edit/themeEditShow.doc.mjs +11 -3
- package/api/upgrade/registry/registry.mjs +6 -1
- package/assets/codemods/parse.mjs +2 -2
- package/assets/docs/author-a-theme.doc.mjs +1 -1
- package/assets/docs/theme.doc.dense.mjs +1 -1
- package/assets/docs/theme.doc.mjs +1 -1
- package/assets/docs/theme.doc.zh.mjs +4 -3
- package/assets/docs/tree/define-the-theme.doc.mjs +1 -1
- package/assets/docs/tree/icon-sets.doc.mjs +63 -8
- package/assets/docs/tree/single-component.doc.mjs +11 -2
- package/assets/docs/tree/tokens-and-setup.doc.mjs +39 -3
- package/assets/docs.generated.json +2 -2
- package/assets/preview-app/next.config.mjs +7 -1
- package/assets/preview-app/package.json +1 -0
- package/assets/preview-app/src/app/globals.css +1 -0
- package/assets/self-audit.generated.json +1 -1
- package/assets/templates/blocks/components/Outline/useOutlineFromDOMHookUsage.doc.mjs +21 -0
- package/assets/templates/blocks/components/Outline/useOutlineFromDOMHookUsage.tsx +62 -0
- package/assets/templates/blocks/components/Table/ColumnsVirtualizationHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Table/ColumnsVirtualizationHookUsage.tsx +53 -0
- package/assets/templates/blocks/components/Table/InfiniteScrollHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Table/InfiniteScrollHookUsage.tsx +33 -0
- package/assets/templates/components.generated.json +1 -1
- package/assets/templates/pages/ai-chat/page.tsx +20 -2
- package/assets/templates/pages/dashboard/page.tsx +1 -1
- package/assets/templates/themes/neutral/neutralPalettes.generated.receipt.json +2 -0
- package/authoring/config/config.doc.mjs +8 -0
- package/authoring/config/parse.d.mts +1 -0
- package/authoring/config/parse.mjs +12 -0
- package/authoring/config/type.ts +8 -0
- package/authoring/doctypes/_schema.d.mts +52 -5
- package/authoring/doctypes/_schema.mjs +62 -7
- package/authoring/doctypes/base/type.ts +10 -0
- package/authoring/doctypes/component/component.doc.mjs +1 -1
- package/authoring/doctypes/function/function.doc.mjs +6 -0
- package/authoring/doctypes/function/type.ts +3 -0
- package/authoring/doctypes/icon-set/icon-set-data.doc.mjs +3 -3
- package/authoring/doctypes/legacy.mjs +5 -1
- package/authoring/index.d.ts +1 -0
- package/authoring/shadcn/source-variants.d.mts +1 -1
- package/authoring/shadcn/source-variants.mjs +32 -10
- package/clients/cli/build-id.generated.json +1 -1
- package/clients/cli/commands/doctor.doc.mjs +2 -2
- package/clients/cli/commands/experimental/icon.mjs +61 -6
- package/clients/cli/commands/experimental/theme.mjs +244 -45
- package/clients/cli/commands/experimental-icon-use.doc.mjs +12 -5
- package/clients/cli/commands/experimental-theme-compile.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +3 -3
- 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 +1 -1
- 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-template.doc.mjs +2 -2
- package/clients/cli/commands/theme-build.doc.mjs +2 -2
- package/clients/cli/commands/theme-eject.doc.mjs +1 -1
- package/clients/cli/commands/theme-template.doc.mjs +3 -1
- package/clients/cli/commands/theme.doc.mjs +7 -2
- package/clients/cli/commands/theme.mjs +222 -55
- package/clients/cli/commands.generated.json +1 -1
- package/clients/cli/formatters/index.mjs +7 -4
- package/clients/cli/index.mjs +25 -5
- package/clients/cli/lib/cli-error.mjs +9 -3
- package/clients/cli/lib/component-format.mjs +27 -9
- package/clients/cli/lib/json-shim.mjs +72 -2
- package/clients/cli/manifest.generated.json +1 -1
- package/clients/cli/run.mjs +49 -0
- package/foundation/agent-docs/agent-docs-target.d.mts +2 -6
- package/foundation/agent-docs/agent-docs-target.mjs +9 -17
- package/foundation/agent-docs/agent-docs.mjs +4 -3
- package/foundation/config/config-writer.d.mts +23 -0
- package/foundation/config/config-writer.mjs +152 -58
- package/foundation/config/project.mjs +103 -16
- package/foundation/discovery/component-discovery.mjs +11 -22
- package/foundation/discovery/icon-set-checks.mjs +164 -48
- package/foundation/discovery/icon-set-discovery.d.mts +38 -5
- package/foundation/discovery/icon-set-discovery.mjs +50 -6
- package/foundation/discovery/icon-set-theme-maps.d.mts +59 -0
- package/foundation/discovery/icon-set-theme-maps.mjs +95 -0
- package/foundation/discovery/icon-set-writer.d.mts +2 -3
- package/foundation/discovery/icon-set-writer.mjs +58 -17
- package/foundation/discovery/module-exports.mjs +1 -15
- package/foundation/discovery/template-adapter.mjs +44 -19
- package/foundation/discovery/template-icons.d.mts +27 -10
- package/foundation/discovery/template-icons.mjs +142 -26
- package/foundation/discovery/template-source-tree.mjs +3 -16
- package/foundation/discovery/theme-discovery.d.mts +30 -1
- package/foundation/discovery/theme-discovery.mjs +109 -50
- package/foundation/fs/exact-codec.d.mts +35 -0
- package/foundation/fs/exact-codec.mjs +148 -0
- package/foundation/fs/gather-cache.d.mts +15 -5
- package/foundation/fs/gather-cache.mjs +129 -31
- package/foundation/fs/paths.d.mts +39 -0
- package/foundation/fs/paths.mjs +44 -11
- package/foundation/fs/read-record.mjs +11 -1
- package/foundation/integrations/autolink.d.mts +4 -2
- package/foundation/integrations/autolink.mjs +4 -2
- package/foundation/integrations/cli-requirement.d.mts +16 -5
- package/foundation/integrations/cli-requirement.mjs +27 -6
- package/foundation/integrations/contribution-fixes.mjs +1 -16
- package/foundation/integrations/may-have-integrations.mjs +7 -3
- package/foundation/integrations/missing-dependency.d.mts +9 -0
- package/foundation/integrations/missing-dependency.mjs +100 -0
- package/foundation/integrations/public-imports.mjs +1 -1
- package/foundation/render/embedded-imports.mjs +1 -1
- package/foundation/render/host-exit.d.mts +8 -0
- package/foundation/render/host-exit.mjs +11 -0
- package/foundation/render/page-host.mjs +56 -10
- package/foundation/render/page-worker.mjs +14 -0
- package/foundation/render/render-page.mjs +37 -2
- package/foundation/response/error-codes.d.mts +2 -1
- package/foundation/response/error-codes.d.ts +1 -0
- package/foundation/response/error-codes.doc.mjs +5 -0
- package/foundation/response/error-codes.mjs +3 -0
- package/foundation/response/json.d.mts +15 -0
- package/foundation/response/json.mjs +52 -1
- package/foundation/response/response-types.doc.mjs +1 -1
- package/foundation/runtime/lazy-dependencies.d.mts +14 -0
- package/foundation/runtime/lazy-dependencies.mjs +82 -0
- package/foundation/xle/browser.d.mts +2 -2
- package/package.json +7 -6
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* @position api/theme-edit — imported only by _how.mjs
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
import {hex, parseColor, ratio} from './_color.mjs';
|
|
12
|
+
import {COLOR_NAMES, hex, parseColor, ratio} from './_color.mjs';
|
|
13
13
|
import {
|
|
14
14
|
DESIGN,
|
|
15
15
|
DIALS,
|
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
COLOR_PROPS,
|
|
24
24
|
GROUPS,
|
|
25
25
|
isSystemFamily,
|
|
26
|
+
wordTable,
|
|
26
27
|
} from './_tables.mjs';
|
|
27
28
|
import {PALETTE_DIALS, isGraySeed, seedOf} from './_palette.mjs';
|
|
28
29
|
import {focusStateOf} from './_settings.mjs';
|
|
@@ -59,6 +60,7 @@ const TRANSLATE = /** @type {Array<[RegExp, string]>} */ (
|
|
|
59
60
|
'圆|丸く|丸い|둥글게|둥근',
|
|
60
61
|
'rounded',
|
|
61
62
|
],
|
|
63
|
+
['cuadrad[oa]s|carrés|eckige\\p{L}*', '四角|方形|네모', 'square'],
|
|
62
64
|
['esquinas?|coins|ecken|углы', '角', 'corners'],
|
|
63
65
|
[
|
|
64
66
|
'sombras?|ombres?|ombra|ombre|schatten|тен[ьи]|ظل',
|
|
@@ -136,25 +138,36 @@ const DESIGN_WORDS = [
|
|
|
136
138
|
];
|
|
137
139
|
|
|
138
140
|
/** Short forms people type, and the word each means. */
|
|
139
|
-
const SHORT =
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
141
|
+
const SHORT = wordTable(
|
|
142
|
+
/** @type {Record<string, string>} */ ({
|
|
143
|
+
btn: 'button',
|
|
144
|
+
btns: 'buttons',
|
|
145
|
+
bttn: 'button',
|
|
146
|
+
bttns: 'buttons',
|
|
147
|
+
brdr: 'border',
|
|
148
|
+
bdr: 'border',
|
|
149
|
+
hdr: 'header',
|
|
150
|
+
rad: 'radius',
|
|
151
|
+
dlg: 'dialog',
|
|
152
|
+
txt: 'text',
|
|
153
|
+
clr: 'color',
|
|
154
|
+
shdw: 'shadow',
|
|
155
|
+
squre: 'square',
|
|
156
|
+
sqaure: 'square',
|
|
157
|
+
suqare: 'square',
|
|
158
|
+
fnot: 'font',
|
|
159
|
+
fnt: 'font',
|
|
160
|
+
}),
|
|
161
|
+
);
|
|
155
162
|
|
|
156
163
|
/** Plain words that are never corrected, though one letter off a VOCAB word. */
|
|
157
164
|
const KEEP = new Set([
|
|
165
|
+
'selection',
|
|
166
|
+
'placeholder',
|
|
167
|
+
'cursor',
|
|
168
|
+
'tablets',
|
|
169
|
+
'mobile',
|
|
170
|
+
'printing',
|
|
158
171
|
'lines',
|
|
159
172
|
'block',
|
|
160
173
|
'blocks',
|
|
@@ -286,56 +299,60 @@ function grayStop(family, stop) {
|
|
|
286
299
|
}
|
|
287
300
|
|
|
288
301
|
/** Hues people name, as fills a part can take. */
|
|
289
|
-
const HUES =
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
302
|
+
const HUES = wordTable(
|
|
303
|
+
/** @type {Record<string, string>} */ ({
|
|
304
|
+
red: '#dc2626',
|
|
305
|
+
orange: '#f97316',
|
|
306
|
+
amber: '#f59e0b',
|
|
307
|
+
yellow: '#eab308',
|
|
308
|
+
lime: '#65a30d',
|
|
309
|
+
green: '#16a34a',
|
|
310
|
+
mint: '#34d399',
|
|
311
|
+
minty: '#34d399',
|
|
312
|
+
teal: '#0d9488',
|
|
313
|
+
cyan: '#0891b2',
|
|
314
|
+
blue: '#2563eb',
|
|
315
|
+
navy: '#1e3a8a',
|
|
316
|
+
indigo: '#4f46e5',
|
|
317
|
+
purple: '#7c3aed',
|
|
318
|
+
charcoal: '#333333',
|
|
319
|
+
violet: '#7c3aed',
|
|
320
|
+
pink: '#db2777',
|
|
321
|
+
magenta: '#c026d3',
|
|
322
|
+
brown: '#92400e',
|
|
323
|
+
gray: '#9ca3af',
|
|
324
|
+
grey: '#9ca3af',
|
|
325
|
+
black: '#000000',
|
|
326
|
+
white: '#ffffff',
|
|
327
|
+
cream: '#fef3c7',
|
|
328
|
+
beige: '#f5f5dc',
|
|
329
|
+
}),
|
|
330
|
+
);
|
|
316
331
|
/** A hue with light, pale or dark before it. */
|
|
317
|
-
const SHADED =
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
}
|
|
332
|
+
const SHADED = wordTable(
|
|
333
|
+
/** @type {Record<string, Record<string, string>>} */ ({
|
|
334
|
+
light: {
|
|
335
|
+
gray: '#e5e7eb',
|
|
336
|
+
grey: '#e5e7eb',
|
|
337
|
+
blue: '#dbeafe',
|
|
338
|
+
green: '#dcfce7',
|
|
339
|
+
red: '#fee2e2',
|
|
340
|
+
yellow: '#fef9c3',
|
|
341
|
+
purple: '#ede9fe',
|
|
342
|
+
pink: '#fce7f3',
|
|
343
|
+
orange: '#ffedd5',
|
|
344
|
+
},
|
|
345
|
+
pale: {gray: '#f3f4f6', grey: '#f3f4f6', blue: '#eff6ff', green: '#f0fdf4'},
|
|
346
|
+
dark: {
|
|
347
|
+
gray: '#374151',
|
|
348
|
+
grey: '#374151',
|
|
349
|
+
blue: '#1e40af',
|
|
350
|
+
green: '#166534',
|
|
351
|
+
red: '#991b1b',
|
|
352
|
+
purple: '#5b21b6',
|
|
353
|
+
},
|
|
354
|
+
}),
|
|
355
|
+
);
|
|
339
356
|
|
|
340
357
|
/** The color tokens a word for a color the theme uses names. */
|
|
341
358
|
const THEME_COLOR_WORDS = /** @type {Array<[RegExp, string, string]>} */ ([
|
|
@@ -536,6 +553,35 @@ function scaled(v, f) {
|
|
|
536
553
|
return `${m[2] === 'px' ? Math.round(n) : Number(n.toFixed(3))}${m[2]}`;
|
|
537
554
|
}
|
|
538
555
|
|
|
556
|
+
/**
|
|
557
|
+
* The part a clause measures against ("cards twice the padding of
|
|
558
|
+
* buttons": buttons), by clause.
|
|
559
|
+
* @type {WeakMap<object, string>}
|
|
560
|
+
*/
|
|
561
|
+
const compared = new WeakMap();
|
|
562
|
+
|
|
563
|
+
/**
|
|
564
|
+
* An exact relative amount the words give ("half", "double", "twice",
|
|
565
|
+
* "triple", "a third", "a quarter", "50%", "x0.8"), as a factor of the
|
|
566
|
+
* theme's current value; null when the words give only a direction.
|
|
567
|
+
* @param {string} text
|
|
568
|
+
* @returns {number | null}
|
|
569
|
+
*/
|
|
570
|
+
export function exactFactor(text) {
|
|
571
|
+
const t = text.toLowerCase();
|
|
572
|
+
if (/\b(half|halve|halved)\b/.test(t)) return 0.5;
|
|
573
|
+
if (/\b(double|doubled|twice)\b/.test(t)) return 2;
|
|
574
|
+
if (/\b(triple|tripled|three times)\b/.test(t)) return 3;
|
|
575
|
+
if (/\ba third\b/.test(t)) return 1 / 3;
|
|
576
|
+
if (/\ba quarter\b/.test(t)) return 0.25;
|
|
577
|
+
const pct = /\b(\d{1,3})\s?%\s*(?:strength|of|as)\b/.exec(t);
|
|
578
|
+
if (pct && Number(pct[1]) > 0) return Number(pct[1]) / 100;
|
|
579
|
+
const times = /\bx\s?(\d*\.?\d+)\b/.exec(t);
|
|
580
|
+
if (times && Number(times[1]) > 0 && Number(times[1]) <= 4)
|
|
581
|
+
return Number(times[1]);
|
|
582
|
+
return null;
|
|
583
|
+
}
|
|
584
|
+
|
|
539
585
|
/**
|
|
540
586
|
* @typedef {{on: string, when?: string, role?: string, level?: string}} PartRef
|
|
541
587
|
*/
|
|
@@ -626,6 +672,23 @@ const OVERRIDES = [
|
|
|
626
672
|
[/\bbody( text)?\b/, {on: 'body', role: 'body'}],
|
|
627
673
|
];
|
|
628
674
|
|
|
675
|
+
/**
|
|
676
|
+
* The part or group a plain word names, as how reads it (`checkboxes` is
|
|
677
|
+
* the checks group, `panels` the containers), or null.
|
|
678
|
+
* @param {string} word
|
|
679
|
+
* @returns {string | null}
|
|
680
|
+
*/
|
|
681
|
+
export function partForWord(word) {
|
|
682
|
+
const w = String(word ?? '')
|
|
683
|
+
.trim()
|
|
684
|
+
.toLowerCase();
|
|
685
|
+
if (!w) return null;
|
|
686
|
+
for (const [re, hit] of OVERRIDES)
|
|
687
|
+
if (/** @type {RegExp} */ (re).test(w))
|
|
688
|
+
return /** @type {{on: string}} */ (hit).on;
|
|
689
|
+
return null;
|
|
690
|
+
}
|
|
691
|
+
|
|
629
692
|
/**
|
|
630
693
|
* Target names in Core's catalog that are plain words a question uses for
|
|
631
694
|
* something else ("more padding", "align the text").
|
|
@@ -689,7 +752,18 @@ function partLexicon(ctx) {
|
|
|
689
752
|
.flatMap(key => [key, `${key}s`]),
|
|
690
753
|
]),
|
|
691
754
|
];
|
|
692
|
-
const lex = {
|
|
755
|
+
const lex = {
|
|
756
|
+
parts: [
|
|
757
|
+
...OVERRIDES,
|
|
758
|
+
...derived,
|
|
759
|
+
// "smaller labels on form fields": a field's label.
|
|
760
|
+
/** @type {[RegExp, PartRef]} */ ([
|
|
761
|
+
/(?<!\b(?:button|tab|badge|chip|nav|menu|link|checkbox|switch|radio)s? )\b(field |form |input )?labels?\b/,
|
|
762
|
+
{on: 'field-label'},
|
|
763
|
+
]),
|
|
764
|
+
],
|
|
765
|
+
vocab,
|
|
766
|
+
};
|
|
693
767
|
lexicons.set(project, lex);
|
|
694
768
|
return lex;
|
|
695
769
|
}
|
|
@@ -716,6 +790,8 @@ const STATE_WORDS = /** @type {Array<[RegExp, string]>} */ ([
|
|
|
716
790
|
[/\b(after i check|once checked|i check)\b/, 'checked'],
|
|
717
791
|
[/\b(picked|chosen|choose|pick)\b/, 'selected'],
|
|
718
792
|
[/\b(invalid|errors? state|has an error|with an error)\b/, 'invalid'],
|
|
793
|
+
[/\bvisited\b/, 'visited'],
|
|
794
|
+
[/\b(opened|expanded)\b/, 'open'],
|
|
719
795
|
// Words for states a part may not have: the answer says so.
|
|
720
796
|
[/\bread-?only\b/, 'readonly'],
|
|
721
797
|
[
|
|
@@ -796,6 +872,10 @@ function aspectsOf(text) {
|
|
|
796
872
|
if (/\bitalics?\b/.test(c)) add('italic');
|
|
797
873
|
if (
|
|
798
874
|
/\b(bold(er)?|unbold\w*|weight|heav(y|ier)|semibold)\b/.test(c) ||
|
|
875
|
+
// "body 16px regular": a weight word after a size.
|
|
876
|
+
/\b\d+(\.\d+)?(px|rem|em|pt) (regular|normal|medium)\b|\b(body|text|headings?) (regular|normal)$/.test(
|
|
877
|
+
c,
|
|
878
|
+
) ||
|
|
799
879
|
/\bthin(ner)? (body |button |heading |label )?(font|text|type|letters|headings?|labels?|copy)\b/.test(
|
|
800
880
|
c,
|
|
801
881
|
) ||
|
|
@@ -822,7 +902,7 @@ function aspectsOf(text) {
|
|
|
822
902
|
(/\b(bigger|larger|smaller)\b/.test(c) &&
|
|
823
903
|
/\b(text|font|headings?|titles?|h[1-6]|body)\b/.test(c)) ||
|
|
824
904
|
/\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(
|
|
905
|
+
/\b(text|font|body|headings?|titles?|labels?|h[1-6])\s+\d+(\.\d+)?(px|rem|em|pt)\b/.test(
|
|
826
906
|
c,
|
|
827
907
|
) ||
|
|
828
908
|
/\b(text|font|type)( is)? (way |far |much )?too (small|tiny|big|large)\b|\btoo (small|tiny) to read\b/.test(
|
|
@@ -857,16 +937,18 @@ function aspectsOf(text) {
|
|
|
857
937
|
/\b(transitions?|animations?|animate[sd]?|fade[sd]? (in|out)|motion)\b/.test(
|
|
858
938
|
c,
|
|
859
939
|
) &&
|
|
860
|
-
/\b(fast(er)?|slow(er)?|quick(er)?|snappier|speed|duration|\d+m?s|off|no|none|disable|stop|remove)\b/.test(
|
|
940
|
+
(/\b(fast(er)?|slow(er)?|quick(er)?|snappier|speed|duration|\d+(\.\d+)?m?s|off|no|none|disable|stop|remove)\b/.test(
|
|
861
941
|
c,
|
|
862
|
-
)
|
|
942
|
+
) ||
|
|
943
|
+
/\bfade[sd]?[- ](in|out)\b/.test(c))
|
|
863
944
|
) {
|
|
864
945
|
a.splice(0, a.length);
|
|
865
946
|
add('motion');
|
|
866
947
|
return a;
|
|
867
948
|
}
|
|
868
949
|
if (
|
|
869
|
-
|
|
950
|
+
// Washed-out colors are a vibrancy ask, not an opacity one.
|
|
951
|
+
/\b(faded|fade|opacity|see-through|washed out(?! colou?rs?\b))\b/.test(c) ||
|
|
870
952
|
// A percent is an opacity only beside an opacity word, never inside a
|
|
871
953
|
// function or after a color ("#2563eb 0%" is a gradient stop).
|
|
872
954
|
(/\d+%/.test(withoutFunctions(c)) &&
|
|
@@ -985,7 +1067,7 @@ function clausesOf(q, partWords) {
|
|
|
985
1067
|
/\?/.test(text));
|
|
986
1068
|
const neg =
|
|
987
1069
|
!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(
|
|
1070
|
+
/\b(no|not|nothing|none of|don'?t|do not|never|avoid|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
1071
|
negText
|
|
990
1072
|
.replace(/\bdisabled\b/g, ' ')
|
|
991
1073
|
// "not round enough" asks for more; "not so much" for less.
|
|
@@ -1004,7 +1086,7 @@ function clausesOf(q, partWords) {
|
|
|
1004
1086
|
? 'less'
|
|
1005
1087
|
: tooMore.test(text)
|
|
1006
1088
|
? '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(
|
|
1089
|
+
: /\b(less|fewer|smaller|lower|reduce|decrease|shrink|minimi[sz]e|scale down|trim|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(
|
|
1008
1090
|
text,
|
|
1009
1091
|
)
|
|
1010
1092
|
? 'less'
|
|
@@ -1241,19 +1323,21 @@ const PLAIN_PROPERTIES = new Set([
|
|
|
1241
1323
|
]);
|
|
1242
1324
|
|
|
1243
1325
|
/** Words people write for a CSS property. */
|
|
1244
|
-
const PROPERTY_WORDS =
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1326
|
+
const PROPERTY_WORDS = wordTable(
|
|
1327
|
+
/** @type {Record<string, string>} */ ({
|
|
1328
|
+
radius: 'border-radius',
|
|
1329
|
+
'min height': 'min-height',
|
|
1330
|
+
'max height': 'max-height',
|
|
1331
|
+
'min width': 'min-width',
|
|
1332
|
+
'max width': 'max-width',
|
|
1333
|
+
'line height': 'line-height',
|
|
1334
|
+
'letter spacing': 'letter-spacing',
|
|
1335
|
+
'font size': 'font-size',
|
|
1336
|
+
'font weight': 'font-weight',
|
|
1337
|
+
'border color': 'border-color',
|
|
1338
|
+
'border colour': 'border-color',
|
|
1339
|
+
}),
|
|
1340
|
+
);
|
|
1257
1341
|
|
|
1258
1342
|
/**
|
|
1259
1343
|
* The words of a value, with each function call kept whole, nested calls
|
|
@@ -1297,25 +1381,27 @@ function withoutFunctions(text) {
|
|
|
1297
1381
|
}
|
|
1298
1382
|
|
|
1299
1383
|
/** The settings each aspect names, for a reset; `*` matches a prefix. */
|
|
1300
|
-
const RESET_THINGS =
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1384
|
+
const RESET_THINGS = wordTable(
|
|
1385
|
+
/** @type {Record<string, string[]>} */ ({
|
|
1386
|
+
corners: ['corners', 'border-radius', '--radius-*'],
|
|
1387
|
+
spacing: ['spacing', 'padding', 'gap', 'margin', '--spacing-*'],
|
|
1388
|
+
family: ['font', 'font-family', '--font-family-*'],
|
|
1389
|
+
background: ['background', 'background-color'],
|
|
1390
|
+
text: ['color', '--color-text-*'],
|
|
1391
|
+
shadow: ['box-shadow', 'surfaces', '--shadow-*'],
|
|
1392
|
+
border: [
|
|
1393
|
+
'border',
|
|
1394
|
+
'border-width',
|
|
1395
|
+
'border-color',
|
|
1396
|
+
'--border-width',
|
|
1397
|
+
'--color-border',
|
|
1398
|
+
],
|
|
1399
|
+
weight: ['headings', 'font-weight', '--text-body-weight'],
|
|
1400
|
+
fontsize: ['text-size', 'type', 'font-size'],
|
|
1401
|
+
leading: ['line-height', '--text-body-leading'],
|
|
1402
|
+
tracking: ['letter-spacing'],
|
|
1403
|
+
}),
|
|
1404
|
+
);
|
|
1319
1405
|
|
|
1320
1406
|
/** Words for a color the theme generates: the word, its dial, its token. */
|
|
1321
1407
|
const ROLE_DIALS = /** @type {Array<[RegExp, string, string]>} */ ([
|
|
@@ -1328,37 +1414,39 @@ const ROLE_DIALS = /** @type {Array<[RegExp, string, string]>} */ ([
|
|
|
1328
1414
|
]);
|
|
1329
1415
|
|
|
1330
1416
|
/** Number words, longest phrase first. */
|
|
1331
|
-
const NUMBER_WORDS =
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1417
|
+
const NUMBER_WORDS = wordTable(
|
|
1418
|
+
/** @type {Record<string, number>} */ ({
|
|
1419
|
+
zero: 0,
|
|
1420
|
+
one: 1,
|
|
1421
|
+
two: 2,
|
|
1422
|
+
three: 3,
|
|
1423
|
+
four: 4,
|
|
1424
|
+
five: 5,
|
|
1425
|
+
six: 6,
|
|
1426
|
+
seven: 7,
|
|
1427
|
+
eight: 8,
|
|
1428
|
+
nine: 9,
|
|
1429
|
+
ten: 10,
|
|
1430
|
+
eleven: 11,
|
|
1431
|
+
twelve: 12,
|
|
1432
|
+
thirteen: 13,
|
|
1433
|
+
fourteen: 14,
|
|
1434
|
+
fifteen: 15,
|
|
1435
|
+
sixteen: 16,
|
|
1436
|
+
seventeen: 17,
|
|
1437
|
+
eighteen: 18,
|
|
1438
|
+
nineteen: 19,
|
|
1439
|
+
twenty: 20,
|
|
1440
|
+
thirty: 30,
|
|
1441
|
+
forty: 40,
|
|
1442
|
+
fifty: 50,
|
|
1443
|
+
sixty: 60,
|
|
1444
|
+
seventy: 70,
|
|
1445
|
+
eighty: 80,
|
|
1446
|
+
ninety: 90,
|
|
1447
|
+
hundred: 100,
|
|
1448
|
+
}),
|
|
1449
|
+
);
|
|
1362
1450
|
const NUMBER_WORDS_RE = new RegExp(
|
|
1363
1451
|
`\\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
1452
|
'gi',
|
|
@@ -1403,10 +1491,579 @@ export function draftAnswer(ctx, env, question) {
|
|
|
1403
1491
|
const TARGET = ctx.project.target;
|
|
1404
1492
|
const TOKENS = ctx.project.core.tokenDefaults;
|
|
1405
1493
|
const lex = partLexicon(ctx);
|
|
1494
|
+
// "corners NaNpx": not a number; never a guess. After a CSS property the
|
|
1495
|
+
// property's own check says why.
|
|
1496
|
+
const notNumber = /\b(nan|-?infinity)(px|rem|em|%)?(?![a-z])/i.exec(question);
|
|
1497
|
+
const afterProperty = notNumber
|
|
1498
|
+
? cssProperties().has(
|
|
1499
|
+
(
|
|
1500
|
+
/([a-z-]+)\s*:?\s*$/i.exec(question.slice(0, notNumber.index))?.[1] ??
|
|
1501
|
+
''
|
|
1502
|
+
).toLowerCase(),
|
|
1503
|
+
)
|
|
1504
|
+
: false;
|
|
1505
|
+
if (notNumber && !afterProperty)
|
|
1506
|
+
return {
|
|
1507
|
+
parts: [],
|
|
1508
|
+
aspects: [],
|
|
1509
|
+
drafts: [
|
|
1510
|
+
{
|
|
1511
|
+
text: `${notNumber[0]} is not a number a theme can use; give a number, like 8px`,
|
|
1512
|
+
options: [],
|
|
1513
|
+
},
|
|
1514
|
+
],
|
|
1515
|
+
};
|
|
1516
|
+
// Sarcasm and dislike name the thing to drop: "enough with the shadows",
|
|
1517
|
+
// "nobody asked for borders", "who needs X", "shadows 👎".
|
|
1518
|
+
question = question
|
|
1519
|
+
.replace(/\b([a-z]+) (?:👎|❌)/gi, 'no $1')
|
|
1520
|
+
.replace(/(?:👎|❌)\s*([a-z]+)/gi, 'no $1')
|
|
1521
|
+
.replace(
|
|
1522
|
+
/\b(?:enough with|quit with|nobody asked for|no one asked for|who needs|get rid of all|(?:i )?loathe) (?:the |all the |these |those )?/gi,
|
|
1523
|
+
'no ',
|
|
1524
|
+
)
|
|
1525
|
+
.replace(/^\s*([a-z][a-z -]*?)\s*(?:👎|:-?\(|:thumbsdown:)\s*$/i, 'no $1')
|
|
1526
|
+
// "too dark, I hate it": the description is the ask.
|
|
1527
|
+
.replace(
|
|
1528
|
+
/[,.;!]?\s*(?:i )?(?:hate|dislike|can'?t stand) (?:it|this|that)\b[.!]*/gi,
|
|
1529
|
+
'',
|
|
1530
|
+
);
|
|
1531
|
+
// The gate works per clause: a clause that is a question, a "tell me",
|
|
1532
|
+
// a "stop …" or a "don't touch …" blocks only itself; the other clauses
|
|
1533
|
+
// are read, with the parts the blocked clause names.
|
|
1534
|
+
const GATE =
|
|
1535
|
+
/\b(tell me|explain|what does|how does|but not too|stop (making|turning|being|using)|don'?t (touch|change)(?! (the )?(dark|light) mode)|leave (?!(?:the )?(?:dark|light) mode)[a-z ]+ alone|who made|just what i wanted|eyes hurt|is a great)\b|^\s*(yeah|oh sure|sure|great|wow)\b|,\s*nice[.!]*\s*$/i;
|
|
1536
|
+
const QUESTION_CLAUSE =
|
|
1537
|
+
/^\s*(?!(?:can|could|would|will) you\b|why (?:are|is|aren'?t|isn'?t)\b[^?]*\bnot\b|why not\b|why don'?t (?:we|you)\b|what about\b|what if\b|how about\b|is it possible\b|is there a way\b|can we\b|could we\b)(what|whats|what's|which|why|where|who|when|is|are|does|do|did|can|could|should|will)\b[^?]*\?+!*\s*$|^\s*(?!why not\b|why don'?t (?:we|you)\b|what about\b|what if\b|why (?:are|is|aren'?t|isn'?t)\b[^?]*\bnot\b)(what|whats|what's|which|why|where)\b|^\s*(?!is it possible\b|is there a way\b)(are|is|does|did|would|should) (my|the|it|this|these|those|our|there|a|an|square|round|rounder|bigger|smaller|darker|lighter)\b/i;
|
|
1538
|
+
// "if you can", "if possible": politeness, not a condition. "no fewer
|
|
1539
|
+
// than 2px": a limit, the number.
|
|
1540
|
+
question = question
|
|
1541
|
+
.replace(
|
|
1542
|
+
/\b(?:if (?:you can|possible|you could|you don'?t mind|it'?s not too much trouble|it is not too much trouble)|when you get a chance)\b[,]?\s*/gi,
|
|
1543
|
+
'',
|
|
1544
|
+
)
|
|
1545
|
+
.replace(/\bno (?:less|fewer) than\s+(?=\d)/gi, '');
|
|
1546
|
+
// "dark page #0b0b0f", "dark.page=#…", "dark page: #…": the mode word
|
|
1547
|
+
// scopes the color. "dark mode only: accent #…" is that mode, not a
|
|
1548
|
+
// dark-only theme. Vocabulary that names a direction: nuke/kill/zap =
|
|
1549
|
+
// remove, sharpen = sharper, zero out = 0, flatten = flat, X++ / X-- =
|
|
1550
|
+
// more / less X, "X: off|none" = no X.
|
|
1551
|
+
question = question
|
|
1552
|
+
.replace(
|
|
1553
|
+
/\b(dark|light)[. ](page|background|body)( colou?r)?\s*[:=]?\s*(#[0-9a-f]{3,8})\b/gi,
|
|
1554
|
+
'$2 $4 in $1 mode',
|
|
1555
|
+
)
|
|
1556
|
+
.replace(/^\s*(dark|light) mode only\s*:\s*/i, 'in $1 mode: ')
|
|
1557
|
+
// "cards with twice the padding of buttons": one comparison, not two
|
|
1558
|
+
// asks.
|
|
1559
|
+
.replace(
|
|
1560
|
+
/\bwith\s+(?=(?:twice|double|half|triple|three times)\s+(?:the\s+)?\w+\s+(?:of|than|as)\b)/gi,
|
|
1561
|
+
'',
|
|
1562
|
+
)
|
|
1563
|
+
// "just the headers bolder", "only the titles bigger": a scope, not a
|
|
1564
|
+
// break between asks.
|
|
1565
|
+
.replace(/(?<![-\w])(?:just|only)\s+(?=(?:the|my)\s+\w+\s+\w)/gi, '')
|
|
1566
|
+
// "headers bolder", "titles bigger": with a text word and no surface
|
|
1567
|
+
// word, the headings' type; with a surface word ("header background"),
|
|
1568
|
+
// the app header part.
|
|
1569
|
+
.replace(/\b(headers?|titles?)\b/gi, (m, _w, at, all) => {
|
|
1570
|
+
// The clause the word is in: from the last break before it (a comma,
|
|
1571
|
+
// semicolon, full stop or new line) to the next one after it.
|
|
1572
|
+
const head = String(all).slice(0, at);
|
|
1573
|
+
const from =
|
|
1574
|
+
Math.max(...[',', ';', '.', '\n'].map(b => head.lastIndexOf(b))) + 1;
|
|
1575
|
+
const clause = String(all)
|
|
1576
|
+
.slice(from)
|
|
1577
|
+
.split(/[,;.\n]/)[0];
|
|
1578
|
+
const text =
|
|
1579
|
+
/\b(bold(er)?|bigger|smaller|larger|font|weight|size|serif|sans|italic|heavier|lighter|thinner|uppercase|letter[- ]?spacing|tracking|line[- ]?height)\b/i.test(
|
|
1580
|
+
clause,
|
|
1581
|
+
);
|
|
1582
|
+
const surface =
|
|
1583
|
+
/\b(background|bg|bar|border|sticky|height|shadow|color of the bar|padding|fixed)\b/i.test(
|
|
1584
|
+
clause,
|
|
1585
|
+
);
|
|
1586
|
+
// "table header", "accordion header", "card title": that part's own.
|
|
1587
|
+
// A place ("not in the header") is the header part too.
|
|
1588
|
+
const before = String(all).slice(Math.max(0, at - 16), at);
|
|
1589
|
+
const owned =
|
|
1590
|
+
/\b(table|column|accordion|card|dialog|modal|page|section|app|site|product|top ?nav)\s+$/i.test(
|
|
1591
|
+
before,
|
|
1592
|
+
) || /\b(in|on|inside|into|across|of)\s+(the\s+|my\s+)?$/i.test(before);
|
|
1593
|
+
return text && !surface && !owned
|
|
1594
|
+
? /s$/i.test(m)
|
|
1595
|
+
? 'headings'
|
|
1596
|
+
: 'heading'
|
|
1597
|
+
: m;
|
|
1598
|
+
})
|
|
1599
|
+
// "focus ring on inputs only, at half strength": an amount alone after a
|
|
1600
|
+
// comma belongs to the ask before it.
|
|
1601
|
+
.replace(
|
|
1602
|
+
/,\s*(?=(?:at|with|by|to)?\s*(?:about\s+)?(?:half|double|twice|triple|a third|a quarter|\d{1,3}\s?%)(?:\s+(?:the\s+)?(?:strength|width|size|thickness|weight|intensity|as (?:much|strong|thick|wide)))?\s*(?:[;.\n]|$))/gi,
|
|
1603
|
+
' ',
|
|
1604
|
+
)
|
|
1605
|
+
// "I need: 1. accent red 2. pill badges": inline list numbers are breaks,
|
|
1606
|
+
// not values.
|
|
1607
|
+
.replace(/(?:^|\s)\d{1,2}[.)]\s+(?=[a-z#])/gi, m =>
|
|
1608
|
+
(question.match(/(?:^|\s)\d{1,2}[.)]\s+[a-z#]/gi) ?? []).length >= 2
|
|
1609
|
+
? '; '
|
|
1610
|
+
: m,
|
|
1611
|
+
)
|
|
1612
|
+
// "only when dark mode is on", "except in dark mode": the mode itself.
|
|
1613
|
+
.replace(
|
|
1614
|
+
/\b(?:only )?(?:when|while|whenever) (?:the )?(dark|light) mode is (?:on|active|enabled|used)\b/gi,
|
|
1615
|
+
'in $1 mode',
|
|
1616
|
+
)
|
|
1617
|
+
.replace(
|
|
1618
|
+
/\b(?:except|but not|not) (?:in |for |on )?dark(?: mode| theme)?\b(?! enough\b)|\b(?:don'?t|do not) (?:touch|change) (?:the )?dark mode\b|\b(?:leave|keep) (?:the )?dark mode (?:alone|as it is|as is|untouched)\b/gi,
|
|
1619
|
+
'in light mode',
|
|
1620
|
+
)
|
|
1621
|
+
.replace(
|
|
1622
|
+
/\b(?:except|but not|not) (?:in |for |on )?light(?: mode| theme)?\b(?! enough\b)|\b(?:don'?t|do not) (?:touch|change) (?:the )?light mode\b|\b(?:leave|keep) (?:the )?light mode (?:alone|as it is|as is|untouched)\b/gi,
|
|
1623
|
+
'in dark mode',
|
|
1624
|
+
)
|
|
1625
|
+
// Removal words in other languages and 🚫: none of it.
|
|
1626
|
+
.replace(/(?:🚫|⛔)\s*/gu, 'no ')
|
|
1627
|
+
.replace(
|
|
1628
|
+
/\b(?:rimuovi|togli|elimina|entferne|quita|retire)\b\s*(?:l'|la |le |il |lo |el |los |las |o |a |os |as |die |der |das |den )?/gi,
|
|
1629
|
+
'no ',
|
|
1630
|
+
)
|
|
1631
|
+
.replace(
|
|
1632
|
+
/\b(?:sans|sin|sem|ohne)\s+(?=(?:l'|la |le |el |o |a |den )?(?:ombres?|bordures?|sombras?|bordes?|bordas?|schatten|rand)\b)/gi,
|
|
1633
|
+
'no ',
|
|
1634
|
+
)
|
|
1635
|
+
// "those dialog shadows are heavy": too heavy, so lighter.
|
|
1636
|
+
.replace(
|
|
1637
|
+
/\b(?:are|is|look|looks|seem|seems) (?:so |very |way |kinda |pretty |quite )?(heavy|strong|harsh|loud|thick|dark|bright)\b/gi,
|
|
1638
|
+
'too $1',
|
|
1639
|
+
)
|
|
1640
|
+
.replace(/\b(dark|light)mode\b/gi, '$1 mode')
|
|
1641
|
+
.replace(/\b(?:nuke|kill|zap|axe)\b/gi, 'remove')
|
|
1642
|
+
.replace(
|
|
1643
|
+
/\bsharpen (?:the |all the |every |all )?([a-z]+)/gi,
|
|
1644
|
+
'make the $1 sharper',
|
|
1645
|
+
)
|
|
1646
|
+
.replace(/\bzero out (?:the )?([a-z ]+?)(?=$|[,;.])/gi, '$1 0')
|
|
1647
|
+
.replace(/\bflatten (?:the )?([a-z]+)/gi, 'make the $1 flat')
|
|
1648
|
+
.replace(/\b([a-z][a-z -]*?)\s*\+\+/gi, 'more $1')
|
|
1649
|
+
.replace(/\b([a-z][a-z -]*?)\s*--(?![a-z])/gi, 'less $1')
|
|
1650
|
+
.replace(/\b([a-z][a-z -]*?)\s*[:=]\s*(?:off|none|no)\b/gi, 'no $1');
|
|
1651
|
+
const segments = question
|
|
1652
|
+
.split(
|
|
1653
|
+
/\s*(?:,(?![^(]*\))|[;\n|]|\s[/+]\s(?![^(]*\))|\.{2,}|[.?!](?=\s)|\bjust\b|\bthen\b|\s[-\u2013\u2014]\s|\bstep \d+\b|\bbut\b(?= (?:make|set|change|use|give|turn|remove|add)\b)|(?<=\S)(?<!\b(?:don'?t|never|do not|not|to|please|and|you|we|i|let'?s|can|could|would|will))\s+(?=(?:make|set|change|give|turn) (?:it|them|the|my|this|that|those|these)\b)|(?<=\S)\s+(?=(?:do|does|will) \w+ (?:follow|match)\b))\s*/i,
|
|
1654
|
+
)
|
|
1655
|
+
.map(x => x.replace(/^\s*(?:[-*•]|\d+[.)])\s*/, ''))
|
|
1656
|
+
.filter(x => x.trim());
|
|
1657
|
+
// "drop shadow: x 0, y 4, …", "card shadow: 0 1px …, 0 2px …": a label
|
|
1658
|
+
// with its value is one clause, commas and all.
|
|
1659
|
+
if (
|
|
1660
|
+
/^\s*[a-z][\w -]{0,30}:\s*[^?]*$/i.test(question) &&
|
|
1661
|
+
!/\n/.test(question) &&
|
|
1662
|
+
!/;/.test(question)
|
|
1663
|
+
)
|
|
1664
|
+
segments.splice(0, segments.length, question);
|
|
1665
|
+
// A clause writes only when it reads as a direct ask: an imperative, a
|
|
1666
|
+
// request, or a thing with a value or a direction; a condition, an
|
|
1667
|
+
// indirect question, a double negative or a statement of fact gets the
|
|
1668
|
+
// lookup instead. A wrong write is worse than no command.
|
|
1669
|
+
const CONDITION =
|
|
1670
|
+
/^\s*(?:if|unless|in case|provided|providing|only if|assuming|suppose|supposing|as long as|whenever|as soon as|once|given|in the event|should (?:the|it|they)|were (?:the|it|they)|otherwise|on condition)\b|\b(?:except if|on condition that|in the event)\b/i;
|
|
1671
|
+
const NOT_ASK =
|
|
1672
|
+
/\b(i wonder|wondering|curious|would like to know|let me see|help me understand|any idea|just checking|just asking|check if|check whether|can you check|look at|double check|idk|quick q|do you think)\b|\b(don'?t not|not without|not un-?(?:bold|round|rounded|flat|square|styled)\w*|never no|no lighter|no darker|not at all|isn'?t it time|weren'?t)\b|^\s*(?!(?:can|could|would|will) (?:you|i|we)\b|can (?:the|my|our|all) [\w -]+ be\b|is it possible\b|is there a way\b)(?:do|does|did|will|would|can(?!'t|not)|could|should|is|are)\b(?!n'?t)|^\s*checking\b|\bno less (?!than)|^\s*(would|could|should|does|do|is|are|will)\b[^.]*\b(work|look|be (?:a )?(?:good|better|too much|ok|okay)|good|better|accessible|clash|too much)\b[^.]*\??$|\bor\b[^.]*\?\s*$|^\s*how (?:would|round|big|dark|light|thick)\b|\b(right now|rn)\b(?!.*\b(make|set|change)\b)/i;
|
|
1673
|
+
const ASK_START =
|
|
1674
|
+
/^\s*(?:please |pls |ok,? |okay,? |also |and |now |so |anyway,? )*(?:make|set|change|use|give|turn|add|remove|increase|decrease|lighten|darken|round|square|put|switch|swap|replace|drop|ditch|kill|hide|bump|reduce|raise|lower|tighten|loosen|shrink|grow|enlarge|boost|soften|sharpen|undo|revert|reset|restore|bring|go|keep|let'?s|try|apply|get rid|take|knock|cut|paint|colou?r|fill|flatten|thicken|widen|narrow|underline|bold|unbold|uppercase|lowercase|no|without|stop|don'?t|never|avoid|less|more|bigger|smaller|rounder|sharper|darker|lighter|softer|bolder|thinner|thicker|wider|tighter|looser)\b|^\s*(?:can|could|would|will) (?:you|i|we)\b|^\s*can (?:the|my|our|all) [\w -]+ be\b|^\s*(?:i|we) (?:want|need|'d like|would like)\b|^\s*(?:i'd|id) like\b|^\s*please\b/i;
|
|
1675
|
+
// Strict: a clause writes only when it positively reads as an ask:
|
|
1676
|
+
// (a) an imperative from a closed verb list, after an optional politeness
|
|
1677
|
+
// prefix; (b) an assignment of a known thing ("<thing> <value>",
|
|
1678
|
+
// "<thing>: <value>"); (c) a bare comparative or style word with a part
|
|
1679
|
+
// ("rounder buttons", "serif headings"). Anything else is held back.
|
|
1680
|
+
const VETO =
|
|
1681
|
+
/^(?:don'?t|doesn'?t|isn'?t|aren'?t|won'?t|wouldn'?t|can'?t|shouldn'?t)\s+(?:the |my |our )?[a-z]+\s+(?:get|have|use|look|be|need|seem)\b|\b(no idea|who knows|not sure|no reason not|can'?t not|isn'?t wrong|not unlike|not never|wouldn'?t say no|can'?t say|it'?s not that|nobody said|hardly|imagine|picture|pretend|hypothetically|in theory|one day|might|toying|consider|someday|maybe|perhaps)\b|\b(?:don'?t|never|no)\b[^,;.]*\bnot\b|\bnever without\b/i;
|
|
1682
|
+
const POLITE =
|
|
1683
|
+
/^\s*(?:(?:please|pls|kindly|ok(?:ay)?|also|and|now|so|anyway|alright|hey|hi|then)[,\s]+|(?:can|could|would|will) (?:you|we|i) (?:please )?|i'?d like (?:you )?to |i'?d like |i (?:want|need|prefer) (?:you )?(?:to )?|we'?d (?:like|prefer) |we (?:want|need|prefer) |hoping for |my request is |let'?s (?:go with )?|lets (?:go with )?|how (?:about|'bout) |what about |why not |why don'?t we (?:go with )?|go ahead and |mind making |you'?d better |you can |you forgot to |only |just |everything |lol |umm+ |ugh,? |quick one:? |(?:way|much|much much|slightly|a bit|a little|a smidge|just slightly|even|super|really|very) |when (?:hovering|hovered|pressed|clicked|focused|i hover|i click|i tab to)(?: (?:on|over|a|an|the) [a-z]+)? |(?:the |our |my )?(?:designer|pm|client|boss|users?|marketing|legal|design spec|style guide|mockup|brand) (?:wants?|needs?|requires?|prefers?|asked for|said:?|says:?) |please and thank you:? |thank you:? |thanks:? |in (?:dark|light) mode[:,]?\s*|(?:dark|light) mode[:,]\s*)+/i;
|
|
1684
|
+
const VERB =
|
|
1685
|
+
/^(?:crank up|fix|make|set|change|use|turn|add|remove|drop|kill|increase|decrease|raise|lower|lighten|darken|round|sharpen|square|flatten|soften|tighten|loosen|beef up|bump|boost|tone down|thicken|thin|bold|unbold|underline|hide|put|switch|swap|replace|ditch|reduce|shrink|trim|minimi[sz]e|scale down|grow|enlarge|widen|narrow|paint|colou?r|fill|undo|revert|reset|restore|bring|go back|keep|apply|try|get rid|take|knock|cut|stop|don'?t|do not|never|avoid|no|without|scale|move|space|pad|center|align|uppercase|lowercase|italicize|enable|disable|switch)\b/i;
|
|
1686
|
+
const THING =
|
|
1687
|
+
/^(?:the |my |our |all |every |all the )?(?:--[a-z][\w-]*|accent|brand|primary|secondary|danger|success|warning|info|corners?|radius|border-radius|spacing|padding|gap|margin|density|headings?|titles?|text(?:-size)?|font(?:s|-size|-family|-weight)?|body|page|background|bg|vibrancy|shadows?|borders?|outlines?|underlines?|links?|mode|leading|line[- ]height|letter[- ]spacing|tracking|weight|focus(?: ring| outline)?|colou?rs?)\b/i;
|
|
1688
|
+
const STYLE =
|
|
1689
|
+
/^(?:muted|pastel|subdued|duller|vivid|saturated|desaturated|vibrant|\d+(?:\.\d+)?(?:px|rem|em|%)?|underlined?|more|less|extra|rounder|sharper|squarer|square|round(?:ed)?|pill|flat|serif|sans(?:-serif)?|mono(?:space)?|bold(?:er)?|italic|uppercase|lowercase|compact|roomy|dense|airy|tight(?:er)?|loose(?:r)?|wide(?:r)?|thin(?:ner)?|thick(?:er)?|big(?:ger)?|small(?:er)?|large(?:r)?|tiny|huge|dark(?:er)?|light(?:er)?|bright(?:er)?|soft(?:er)?|heav(?:y|ier)|no|without|#[0-9a-f]{3,8}|red|orange|yellow|green|teal|cyan|blue|indigo|purple|violet|pink|rose|gray|grey|black|white|navy|crimson|maroon)\b/i;
|
|
1690
|
+
const COPULA =
|
|
1691
|
+
/\b(is|are|was|were|has|have|had|isn'?t|aren'?t|doesn'?t|did|does|truly)\b|\?/i;
|
|
1692
|
+
// Clauses that only scope or give a value ("in dark mode", "on hover",
|
|
1693
|
+
// "4px", "at least 44px") join the ask next to them.
|
|
1694
|
+
const NEUTRAL =
|
|
1695
|
+
/^\s*(?:below|above|under|over)\s+\d+(?:px|em|rem)\s*$|^\s*(?:on|for) (?:mobile|phones?|tablets?|desktops?|print)\s*$|^\s*when printing\s*$|^\s*(?:(?:in|on) (?:the )?(?:dark|light) mode )?#[0-9a-f]{3,8}(?: in (?:dark|light)(?: mode)?)?\s*$|^\s*(?:leave|keep) (?:the )?(?:dark|light) mode (?:alone|as is|as it is|untouched)\s*$|^\s*(?:only |just )?(?:(?:in|on|for|when|while) )?(?:(?:the )?(?:dark|light) mode|hover(?:ed|ing)?|focus(?:ed)?|press(?:ed)?|click(?:ed)?|selected|checked|disabled)(?: only)?\s*$|^\s*(?:at (?:least|most) |about |around |roughly |maybe )?(?:-?\d*\.?\d+(?:px|rem|em|%|ms|s)?|#[0-9a-f]{3,8})\s*$/i;
|
|
1696
|
+
const isAsk = (/** @type {string} */ x) => {
|
|
1697
|
+
if (NEUTRAL.test(x)) return true;
|
|
1698
|
+
// A bare CSS value ("0 8px 10px -6px rgb(0 0 0 / 0.1)") continues the
|
|
1699
|
+
// clause before it.
|
|
1700
|
+
const bare = x.replace(
|
|
1701
|
+
/^\s*(?:like|e\.?g\.?|say|maybe|about|around|roughly)\s+/i,
|
|
1702
|
+
'',
|
|
1703
|
+
);
|
|
1704
|
+
if (
|
|
1705
|
+
/\d/.test(bare) &&
|
|
1706
|
+
!/[a-z]{3,}/i.test(
|
|
1707
|
+
bare.replace(
|
|
1708
|
+
/\b(?:px|rem|em|rgba?|hsla?|oklch|oklab|var|calc|inset)\b|\([^)]*\)/gi,
|
|
1709
|
+
'',
|
|
1710
|
+
),
|
|
1711
|
+
)
|
|
1712
|
+
)
|
|
1713
|
+
return true;
|
|
1714
|
+
const low = x.toLowerCase().trim();
|
|
1715
|
+
// "card shadow: 0 1px 3px …", "Airbnb: accent #ff385c": a label and its
|
|
1716
|
+
// value; "setRadius(4)"; "shouldn't links be underlined?"; a question in
|
|
1717
|
+
// another language the editor translates.
|
|
1718
|
+
if (
|
|
1719
|
+
/^([a-z][\w -]{0,30}):\s*\S/.test(low) &&
|
|
1720
|
+
!/^(?:just )?(?:checking|question|quick q|q|fyi|todo|note|changes)\s*:|:\s*(?:are|is|do|does|what|which|how|why)\b/.test(
|
|
1721
|
+
low,
|
|
1722
|
+
) &&
|
|
1723
|
+
!NOT_ASK.test(low) &&
|
|
1724
|
+
!CONDITION.test(low) &&
|
|
1725
|
+
!VETO.test(low) &&
|
|
1726
|
+
!/\?\s*$/.test(low)
|
|
1727
|
+
)
|
|
1728
|
+
return true;
|
|
1729
|
+
if (/^set[a-z]*\(|^shouldn'?t\b[^?]*\?\s*$/.test(low)) return true;
|
|
1730
|
+
// "I set the accent to red by mistake", "does nothing visible".
|
|
1731
|
+
if (
|
|
1732
|
+
/\b(by mistake|by accident|accidentally|does nothing|do nothing)\b/.test(
|
|
1733
|
+
low,
|
|
1734
|
+
)
|
|
1735
|
+
)
|
|
1736
|
+
return true;
|
|
1737
|
+
if (
|
|
1738
|
+
/\b(schatten|karten|ecken|knöpfe|entfernen|pulsanti|arrotondat\w*|ombra|ombre|bordure|cartes|esquinas|redond\w*|botones|boutons|arrondi\w*|rouges?|bleus?|verts?|sombra|couleur|tarjetas|espacio|angoli|cantos|botões)\b/.test(
|
|
1739
|
+
low,
|
|
1740
|
+
)
|
|
1741
|
+
)
|
|
1742
|
+
return true;
|
|
1743
|
+
// "I hate the shadows", "I can barely see the borders", "the client
|
|
1744
|
+
// wants …": a wish or a complaint about a named thing.
|
|
1745
|
+
if (
|
|
1746
|
+
/^(?:i|we|they|the client|the designer|stakeholders?|users?|the night shift)\b[^?]*\b(hate|want|wants|need|needs|like|prefer|barely see|can'?t see|think|wish)\b(?! to know)/.test(
|
|
1747
|
+
low,
|
|
1748
|
+
) &&
|
|
1749
|
+
!VETO.test(low) &&
|
|
1750
|
+
!CONDITION.test(low) &&
|
|
1751
|
+
(aspectsOf(low).length > 0 ||
|
|
1752
|
+
lex.parts.some(([re]) => re.test(low)) ||
|
|
1753
|
+
/#[0-9a-f]{3,8}|\b(accent|colou?r|brand|grays?|font|purple|blue|red|green|orange|teal|pink|navy|black|white|yellow|violet)\b/.test(
|
|
1754
|
+
low,
|
|
1755
|
+
))
|
|
1756
|
+
)
|
|
1757
|
+
return true;
|
|
1758
|
+
// Typos are read as the words they are near ("accnet" is accent).
|
|
1759
|
+
const t0 = x
|
|
1760
|
+
.toLowerCase()
|
|
1761
|
+
.trim()
|
|
1762
|
+
.replace(/[a-z]+/g, w => corrected(w, lex.vocab));
|
|
1763
|
+
// "our brand color is #0055ff": a value given for the brand; pasted CSS
|
|
1764
|
+
// ("html.dark .card { … }"); "X should be/look Y".
|
|
1765
|
+
if (
|
|
1766
|
+
/^(?:our|my|the) brand colou?r is #[0-9a-f]{3,8}\b|\{[^}]*:|\bshould (?:be|look|have|get|use|match|feel)\b(?![^?]*\?)/.test(
|
|
1767
|
+
t0,
|
|
1768
|
+
) &&
|
|
1769
|
+
!CONDITION.test(t0) &&
|
|
1770
|
+
!VETO.test(t0)
|
|
1771
|
+
)
|
|
1772
|
+
return true;
|
|
1773
|
+
const raw = x.toLowerCase();
|
|
1774
|
+
if (
|
|
1775
|
+
[t0, raw].some(v => CONDITION.test(v) || NOT_ASK.test(v) || VETO.test(v))
|
|
1776
|
+
)
|
|
1777
|
+
return false;
|
|
1778
|
+
// Questions in a script how cannot read word by word keep their ask.
|
|
1779
|
+
if (/[^ -~]/.test(t0.replace(/[\u{1F000}-\u{1FFFF}\u2000-\u2BFF]/gu, '')))
|
|
1780
|
+
return true;
|
|
1781
|
+
if (
|
|
1782
|
+
VERB.test(
|
|
1783
|
+
raw
|
|
1784
|
+
.replace(POLITE, '')
|
|
1785
|
+
.replace(/^(?:the|my|our|all|every|a|an)\s+/, '')
|
|
1786
|
+
.trim(),
|
|
1787
|
+
)
|
|
1788
|
+
)
|
|
1789
|
+
return true;
|
|
1790
|
+
const t = t0
|
|
1791
|
+
.replace(POLITE, '')
|
|
1792
|
+
.replace(
|
|
1793
|
+
/^(?:the|my|our|all|every|all the|a|an|those|these|this|that)\s+/,
|
|
1794
|
+
'',
|
|
1795
|
+
)
|
|
1796
|
+
.trim();
|
|
1797
|
+
// "could the buttons be rounder", "can I get a serif font".
|
|
1798
|
+
if (
|
|
1799
|
+
/^(?:can|could) (?:the|my|our|all) [\w -]+ be\b|^(?:can|could) i (?:get|have)\b/.test(
|
|
1800
|
+
t0,
|
|
1801
|
+
)
|
|
1802
|
+
)
|
|
1803
|
+
return true;
|
|
1804
|
+
if (VERB.test(t)) return true;
|
|
1805
|
+
// "give buttons 8px corners": give a thing a value; "give me …" asks.
|
|
1806
|
+
if (/^give (?!me\b|us\b)/.test(t)) return true;
|
|
1807
|
+
const short = t.split(/\s+/).length <= 7;
|
|
1808
|
+
const part = lex.parts.some(([re]) => re.exec(t)?.index === 0);
|
|
1809
|
+
if ((THING.test(t) || part) && short && !COPULA.test(t)) return true;
|
|
1810
|
+
if (
|
|
1811
|
+
STYLE.test(t) &&
|
|
1812
|
+
short &&
|
|
1813
|
+
!COPULA.test(t) &&
|
|
1814
|
+
(THING.test(t.replace(STYLE, '').trim()) ||
|
|
1815
|
+
lex.parts.some(([re]) => re.test(t)) ||
|
|
1816
|
+
/\b(corners?|spacing|padding|shadows?|borders?|accent|headings?|text|font|page|background|colou?rs?|colou?rful|pastel|muted|subdued|vivid|saturated|washed out)\b/.test(
|
|
1817
|
+
t,
|
|
1818
|
+
))
|
|
1819
|
+
)
|
|
1820
|
+
return true;
|
|
1821
|
+
// "why are my headings not bold", "I hate the purple": asks.
|
|
1822
|
+
if (/^why (?:are|is|aren'?t|isn'?t)\b.*\bnot\b/.test(t)) return true;
|
|
1823
|
+
if (/^(?:i )?(?:hate|dislike|(?:am )?not a fan of|don'?t like)\b/.test(t))
|
|
1824
|
+
return true;
|
|
1825
|
+
// A description of the look wanted ("stronger shadow on dialogs",
|
|
1826
|
+
// "headings are 600 weight", "the page is white") names a thing and asks
|
|
1827
|
+
// nothing back: an ask. An info request ("show me …") is a lookup.
|
|
1828
|
+
if (
|
|
1829
|
+
!/\?|\b(isn'?t|aren'?t|doesn'?t|don'?t|won'?t|wouldn'?t|did|does|was|were|could|might|should)\b/.test(
|
|
1830
|
+
t,
|
|
1831
|
+
) &&
|
|
1832
|
+
!/^(?:i|we|you|it|this|that|there|they|(?:show|give|tell|remind|walk) (?:me|us))\b/.test(
|
|
1833
|
+
t,
|
|
1834
|
+
) &&
|
|
1835
|
+
(aspectsOf(t).length > 0 ||
|
|
1836
|
+
lex.parts.some(([re]) => re.test(t)) ||
|
|
1837
|
+
/\b(accent|contrast|neutrals?|grays?|greys?|colou?rs?|font|fonts|everywhere|error|danger|success|warning|info|purple|blue|red|green|orange|teal|pink|navy|black|white|yellow|violet)\b/.test(
|
|
1838
|
+
t,
|
|
1839
|
+
))
|
|
1840
|
+
)
|
|
1841
|
+
return true;
|
|
1842
|
+
return false;
|
|
1843
|
+
};
|
|
1844
|
+
// "don't touch the buttons", "leave the corners": an exclusion. It writes
|
|
1845
|
+
// nothing, and it gives nothing to the clause after it.
|
|
1846
|
+
const EXCLUDE =
|
|
1847
|
+
/^\s*(?:don'?t (?:touch|change)|do not (?:touch|change)|leave(?! (?:the )?(?:dark|light) mode\b)|keep (?:the )?[\w -]+ (?:alone|as is|as it is|unchanged|untouched|the same))\b/i;
|
|
1848
|
+
const blocked = (/** @type {string} */ x) =>
|
|
1849
|
+
EXCLUDE.test(x) ||
|
|
1850
|
+
(!/^\s*(?:please )?(?:can|could) (?:the|my|our|all) [\w -]+ be\b|^\s*(?:can|could) i (?:get|have)\b/i.test(
|
|
1851
|
+
x,
|
|
1852
|
+
) &&
|
|
1853
|
+
(GATE.test(x) ||
|
|
1854
|
+
(QUESTION_CLAUSE.test(x) && !ASK_START.test(x.toLowerCase())) ||
|
|
1855
|
+
!isAsk(x)));
|
|
1856
|
+
const gated = segments.filter(blocked);
|
|
1857
|
+
// A condition holds back the whole question: the ask depends on it.
|
|
1858
|
+
// Sarcasm makes every clause unsure, not only the one with the marker.
|
|
1859
|
+
const SARCASM =
|
|
1860
|
+
/^\s*(yeah|oh sure|sure|great|wow|oh great|brilliant|perfect|cool cool|amazing|thrilled|nothing says)\b|\bjust what i wanted\b|,\s*nice[.!]*\s*$|\bis a great\b|\bsaid no one\b|\btruly\b|🙃/iu;
|
|
1861
|
+
// A hypothetical anywhere makes every clause one.
|
|
1862
|
+
const HYPOTHETICAL =
|
|
1863
|
+
/\b(imagine|picture|pretend|hypothetically|in theory|toying with)\b/i;
|
|
1864
|
+
// A tag question ("corners are 10px, eh", "cards have a shadow, right?")
|
|
1865
|
+
// asks back about the whole line.
|
|
1866
|
+
const TAG =
|
|
1867
|
+
/^(?:eh|right|correct|yeah|huh|no|isn'?t it|aren'?t they|are they|is it|are we|do they|does it|ok|okay)\s*[?!.]*$/i;
|
|
1868
|
+
const gateAll =
|
|
1869
|
+
segments.some(x => TAG.test(x.trim())) ||
|
|
1870
|
+
SARCASM.test(question) ||
|
|
1871
|
+
HYPOTHETICAL.test(question) ||
|
|
1872
|
+
(gated.length > 0 && gated.length === segments.length) ||
|
|
1873
|
+
segments.some(x => CONDITION.test(x.replace(/^[^:]*:\s*/, '')));
|
|
1874
|
+
if (gated.length && !gateAll) {
|
|
1875
|
+
// A held-back clause gives the next clause what it names: its part, and
|
|
1876
|
+
// the thing a "them" or "it" there stands for.
|
|
1877
|
+
/** @type {string[]} */
|
|
1878
|
+
const kept = [];
|
|
1879
|
+
let carry = '';
|
|
1880
|
+
let carryPart = '';
|
|
1881
|
+
for (const x of segments) {
|
|
1882
|
+
if (gated.includes(x) && EXCLUDE.test(x)) {
|
|
1883
|
+
carry = '';
|
|
1884
|
+
carryPart = '';
|
|
1885
|
+
continue;
|
|
1886
|
+
}
|
|
1887
|
+
if (gated.includes(x)) {
|
|
1888
|
+
const part = [
|
|
1889
|
+
...lex.parts.map(([re]) => re.exec(x.toLowerCase())?.[0]),
|
|
1890
|
+
/\b(accent|brand|primary|secondary|danger|success|warning|info)\b/i.exec(
|
|
1891
|
+
x,
|
|
1892
|
+
)?.[0],
|
|
1893
|
+
].find(Boolean);
|
|
1894
|
+
const thing =
|
|
1895
|
+
/\b(borders?|shadows?|radius|corners|padding|spacing|gap|font|underlines?|background)\b/i.exec(
|
|
1896
|
+
x,
|
|
1897
|
+
)?.[0];
|
|
1898
|
+
carry = [part, thing].filter(Boolean).join(' ');
|
|
1899
|
+
carryPart = part ?? '';
|
|
1900
|
+
continue;
|
|
1901
|
+
}
|
|
1902
|
+
if (carry && /\b(them|it)\b/i.test(x))
|
|
1903
|
+
kept.push(x.replace(/\b(them|it)\b/i, carry));
|
|
1904
|
+
else if (carryPart) kept.push(carryPart, x);
|
|
1905
|
+
else kept.push(x);
|
|
1906
|
+
carry = '';
|
|
1907
|
+
carryPart = '';
|
|
1908
|
+
}
|
|
1909
|
+
if (carryPart) kept.push(carryPart);
|
|
1910
|
+
question = kept.filter(Boolean).join(', ');
|
|
1911
|
+
}
|
|
1406
1912
|
/** Family names written in quotes, kept as typed: qq<n>qq in the text. */
|
|
1407
1913
|
const quoted = /** @type {string[]} */ ([]);
|
|
1408
1914
|
let q = question
|
|
1409
1915
|
.normalize('NFKC')
|
|
1916
|
+
// "more muted", "pastel", "duller", "subdued": less vivid colors (free
|
|
1917
|
+
// words only: never inside a token name like --color-background-muted).
|
|
1918
|
+
.replace(
|
|
1919
|
+
/(?<![-\w])less (?:muted|pastel|dull|subdued)(?![-\w])/gi,
|
|
1920
|
+
'more saturated',
|
|
1921
|
+
)
|
|
1922
|
+
.replace(
|
|
1923
|
+
/(?<![-\w])(?:more )?(?:muted|pastel|duller|subdued|desaturated)(?![-\w])/gi,
|
|
1924
|
+
'less saturated',
|
|
1925
|
+
)
|
|
1926
|
+
// "less light", "less heavy", "less tight", "less thin": one step back on
|
|
1927
|
+
// the same aspect.
|
|
1928
|
+
.replace(
|
|
1929
|
+
/\bless (?:light|thin|skinny)\b(?= (?:headings?|titles?|text|fonts?|weight)|\s*$)/gi,
|
|
1930
|
+
'bolder',
|
|
1931
|
+
)
|
|
1932
|
+
.replace(
|
|
1933
|
+
/\b(headings?|titles?|text|fonts?) (?:a bit |slightly )?less (?:light|thin)\b/gi,
|
|
1934
|
+
'$1 bolder',
|
|
1935
|
+
)
|
|
1936
|
+
.replace(/\bless heavy\b/gi, 'less bold')
|
|
1937
|
+
.replace(/\bless tight\b/gi, 'wider letter spacing')
|
|
1938
|
+
// "too dark" asks for lighter, "too light" for darker.
|
|
1939
|
+
.replace(/\btoo dark\b(?! mode)/gi, 'lighter')
|
|
1940
|
+
.replace(/\btoo light(?: gray| grey)?\b(?! mode)/gi, 'darker')
|
|
1941
|
+
// "no big gaps": less room.
|
|
1942
|
+
.replace(
|
|
1943
|
+
/\bno (?:big|large|huge) (?:gaps|spaces|spacing)\b/gi,
|
|
1944
|
+
'less spacing',
|
|
1945
|
+
)
|
|
1946
|
+
// "too airy", "headings too thin", "not bright enough": the other way.
|
|
1947
|
+
.replace(
|
|
1948
|
+
/\btoo (airy|spacious|roomy|loose|spread out)\b/gi,
|
|
1949
|
+
'tighter spacing',
|
|
1950
|
+
)
|
|
1951
|
+
.replace(
|
|
1952
|
+
/\b(headings?|titles?|fonts?) (?:are |is |look |looks )?too (thin|light|weak)\b|\b(text|labels?) (?:are |is |looks? )?too (thin)\b/gi,
|
|
1953
|
+
(_, a, _b, t) => `${a ?? t} bolder`,
|
|
1954
|
+
)
|
|
1955
|
+
.replace(
|
|
1956
|
+
/\bnot (bright|dark|bold|round|big|light|soft|warm|cool) enough\b/gi,
|
|
1957
|
+
(_, w) =>
|
|
1958
|
+
`${{bright: 'brighter', dark: 'darker', bold: 'bolder', round: 'rounder', big: 'bigger', light: 'lighter', soft: 'softer', warm: 'warmer', cool: 'cooler'}[/** @type {'bright'} */ (w.toLowerCase())]}`,
|
|
1959
|
+
)
|
|
1960
|
+
// "change only light to violet": light mode, not a light-only theme.
|
|
1961
|
+
.replace(
|
|
1962
|
+
/\b(?:change |set |make )?only (light|dark)(?: mode)? (?=to\b)/gi,
|
|
1963
|
+
'in $1 mode change ',
|
|
1964
|
+
)
|
|
1965
|
+
// "links not underlined until hover": none, then underlined on hover.
|
|
1966
|
+
.replace(
|
|
1967
|
+
/\b([a-z]+) (?:are |is )?not underlined until (?:you )?hover\w*/gi,
|
|
1968
|
+
'$1 no underline; $1 underlined on hover',
|
|
1969
|
+
)
|
|
1970
|
+
// "3 pixels sharper": pixels are px.
|
|
1971
|
+
.replace(/(\d+(?:\.\d+)?)\s*pixels?\b/gi, '$1px')
|
|
1972
|
+
// "take 2px off", "remove 4px from": an amount down.
|
|
1973
|
+
.replace(
|
|
1974
|
+
/\b(?:take|knock|shave|cut)\s+(\d+(?:\.\d+)?(?:px|rem|em))\s+off\b/gi,
|
|
1975
|
+
'minus $1 off',
|
|
1976
|
+
)
|
|
1977
|
+
.replace(
|
|
1978
|
+
/\bremove\s+(\d+(?:\.\d+)?(?:px|rem|em))\s+(?=from\b)/gi,
|
|
1979
|
+
'minus $1 ',
|
|
1980
|
+
)
|
|
1981
|
+
// "darkmode", "html.dark .card", "@media (prefers-color-scheme: dark)".
|
|
1982
|
+
.replace(/\b(dark|light)mode\b/gi, '$1 mode')
|
|
1983
|
+
.replace(
|
|
1984
|
+
/@media\s*\(\s*prefers-color-scheme\s*:\s*(dark|light)\s*\)\s*\{/gi,
|
|
1985
|
+
'in $1 mode {',
|
|
1986
|
+
)
|
|
1987
|
+
.replace(
|
|
1988
|
+
/(?:\bhtml)?\.(dark|light)\s+(?=\.)|\[data-(?:theme|mode)=["']?(dark|light)["']?\]\s*/gi,
|
|
1989
|
+
(_, a, b) => `in ${a ?? b} mode `,
|
|
1990
|
+
)
|
|
1991
|
+
// "I hate the shadows", "skip the shadows", "not a fan of": none of it.
|
|
1992
|
+
// "I hate the shadows", "not a fan of the rounded buttons": none of it,
|
|
1993
|
+
// when that is the whole ask.
|
|
1994
|
+
.replace(
|
|
1995
|
+
/^\s*(?:i )?(?:hate|dislike|can'?t stand|don'?t like|am not a fan of|not a fan of|skip|ditch)(?: the)? ([^,.;?!]+?)[.!]?\s*$/i,
|
|
1996
|
+
'no $1',
|
|
1997
|
+
)
|
|
1998
|
+
// "pointer cursor on hover": the cursor, no state needed.
|
|
1999
|
+
.replace(
|
|
2000
|
+
/\bpointer cursor(?: on hover)?\b|\bcursor:?\s+pointer(?: on hover)?\b/gi,
|
|
2001
|
+
'cursor: pointer',
|
|
2002
|
+
)
|
|
2003
|
+
// "cards look flat": a complaint that asks for depth.
|
|
2004
|
+
.replace(
|
|
2005
|
+
/\b(look|looks|feel|feels|seem|seems) (?:too |so |very )?flat\b(?!.*\bshadow)/gi,
|
|
2006
|
+
'need more shadow',
|
|
2007
|
+
)
|
|
2008
|
+
// "darker while being clicked": the pressed state.
|
|
2009
|
+
.replace(
|
|
2010
|
+
/\b(darker|lighter) while being (clicked|pressed|tapped)\b/gi,
|
|
2011
|
+
'get $1 when clicked',
|
|
2012
|
+
)
|
|
2013
|
+
// "except in dark mode", "but not in dark mode", "leave dark mode alone":
|
|
2014
|
+
// the other mode.
|
|
2015
|
+
.replace(
|
|
2016
|
+
/\b(?:except|but not|not) (?:in |for |on )?dark(?: mode| theme)?\b(?! enough\b)|\b(?:leave|keep) dark mode (?:alone|as it is|as is|untouched)\b|\bdon'?t (?:touch|change) dark mode\b/gi,
|
|
2017
|
+
'in light mode',
|
|
2018
|
+
)
|
|
2019
|
+
.replace(
|
|
2020
|
+
/\b(?:except|but not|not) (?:in |for |on )?light(?: mode| theme)?\b(?! enough\b)|\b(?:leave|keep) light mode (?:alone|as it is|as is|untouched)\b|\bdon'?t (?:touch|change) light mode\b/gi,
|
|
2021
|
+
'in dark mode',
|
|
2022
|
+
)
|
|
2023
|
+
// "not pure black": a near-black; "not pure white": a near-white.
|
|
2024
|
+
.replace(/\bnot (?:pure |true |full )?black\b/gi, '#111111')
|
|
2025
|
+
.replace(/\bnot (?:pure |true |full )?white\b/gi, '#fafafa')
|
|
2026
|
+
// "dropdown shadow": the dropdown's menu, the part that floats.
|
|
2027
|
+
.replace(/\bdropdowns? (?=shadows?|elevation)/gi, 'dropdown-menu ')
|
|
2028
|
+
// "½rem": a fraction is a number.
|
|
2029
|
+
.replace(/(\d*)(?:½|1\u20442)/g, (_, n) => `${n ? Number(n) + 0.5 : '0.5'}`)
|
|
2030
|
+
.replace(
|
|
2031
|
+
/(\d*)(?:¼|1\u20444)/g,
|
|
2032
|
+
(_, n) => `${n ? Number(n) + 0.25 : '0.25'}`,
|
|
2033
|
+
)
|
|
2034
|
+
.replace(
|
|
2035
|
+
/(\d*)(?:¾|3\u20444)/g,
|
|
2036
|
+
(_, n) => `${n ? Number(n) + 0.75 : '0.75'}`,
|
|
2037
|
+
)
|
|
2038
|
+
// "radius sm", "setRadius(4)": the corner rungs and a number.
|
|
2039
|
+
.replace(/\bset-?radius\s*\(\s*(\d+(?:\.\d+)?)\s*\)/gi, 'corners $1px')
|
|
2040
|
+
.replace(
|
|
2041
|
+
/\b(?:radius|corners|rounded)[- ](xs|sm|md|lg|xl)\b/gi,
|
|
2042
|
+
(_, /** @type {string} */ r) =>
|
|
2043
|
+
`corners ${/** @type {Record<string, string>} */ ({xs: '4px', sm: '8px', md: '10px', lg: '12px', xl: '16px'})[r.toLowerCase()]}`,
|
|
2044
|
+
)
|
|
2045
|
+
// "midnight blue": the CSS named color.
|
|
2046
|
+
.replace(/\b([a-z]+) ([a-z]+)\b/gi, (m, a, b) =>
|
|
2047
|
+
COLOR_NAMES.includes(`${a}${b}`.toLowerCase()) &&
|
|
2048
|
+
!/^(dark|light)$/i.test(a)
|
|
2049
|
+
? `${a}${b}`.toLowerCase()
|
|
2050
|
+
: m,
|
|
2051
|
+
)
|
|
2052
|
+
// "translateY(-2px) on hover": a transform.
|
|
2053
|
+
.replace(
|
|
2054
|
+
/(?<!transform\s*:?\s*)\b((?:translate[xyz]?|scale[xy]?|rotate)\([^)]*\))/gi,
|
|
2055
|
+
(_, fn) => `transform: ${fn.toLowerCase()}`,
|
|
2056
|
+
)
|
|
2057
|
+
// "#22c55e in light, #4ade80 in dark": the accent, per mode.
|
|
2058
|
+
.replace(
|
|
2059
|
+
/^\s*(#[0-9a-f]{3,8}) in (light|dark)(?: mode)?\s*(,|and|;)\s*(#[0-9a-f]{3,8}) in (light|dark)(?: mode)?\s*$/i,
|
|
2060
|
+
'accent $1 in $2 mode$3 accent $4 in $5 mode',
|
|
2061
|
+
)
|
|
2062
|
+
// ".btn-primary { … }": the primary button.
|
|
2063
|
+
.replace(
|
|
2064
|
+
/\.btn-(primary|secondary|ghost|destructive|danger)\b/g,
|
|
2065
|
+
(_, v) => `${v === 'danger' ? 'destructive' : v} button `,
|
|
2066
|
+
)
|
|
1410
2067
|
// Markup and comment text are not part of the ask.
|
|
1411
2068
|
.replace(/<(script|style)\b[^>]*>[\s\S]*?<\/\1\s*>/gi, ' ')
|
|
1412
2069
|
.replace(/<\/?[a-z][^>]*>/gi, ' ')
|
|
@@ -1471,6 +2128,15 @@ export function draftAnswer(ctx, env, question) {
|
|
|
1471
2128
|
.replace(/\b(?:no|not) more than\s+|\bat most\s+|\bmax(?:imum)? of\s+/g, '')
|
|
1472
2129
|
// Numbers written as words are numbers.
|
|
1473
2130
|
.replace(NUMBER_WORDS_RE, m => numberWord(m))
|
|
2131
|
+
// "less black", "not so white": a direction away from that color.
|
|
2132
|
+
.replace(
|
|
2133
|
+
/\b(?:slightly |a bit |a little )?(?:less|not so|not as) (black|dark)\b/g,
|
|
2134
|
+
'lighter',
|
|
2135
|
+
)
|
|
2136
|
+
.replace(
|
|
2137
|
+
/\b(?:slightly |a bit |a little )?(?:less|not so|not as) (white|bright)\b/g,
|
|
2138
|
+
'dimmer',
|
|
2139
|
+
)
|
|
1474
2140
|
// "8 or so px", "about 8 px": the number.
|
|
1475
2141
|
.replace(/\b(\d+(?:\.\d+)?)\s+or so\s+(?=px|rem|em|pixels?)/g, '$1 ')
|
|
1476
2142
|
// "0.5 rem", "14 px": a number and its unit are one length.
|
|
@@ -1585,12 +2251,31 @@ export function draftAnswer(ctx, env, question) {
|
|
|
1585
2251
|
// "bordes redondeados": rounded edges are corners.
|
|
1586
2252
|
.replace(/\bborders?\s+rounded\b/g, 'rounded corners')
|
|
1587
2253
|
.replace(/\bbutton-s\b/g, 'buttons')
|
|
1588
|
-
.replace(/[a-z]+/g, w =>
|
|
2254
|
+
.replace(/[a-z]+/g, w => {
|
|
2255
|
+
const fixed = corrected(w, lex.vocab);
|
|
2256
|
+
return fixed;
|
|
2257
|
+
})
|
|
1589
2258
|
// "buttons, but not bold": the "not" is about the buttons.
|
|
1590
2259
|
.replace(
|
|
1591
2260
|
/,?\s*\bbut not\s+(?=(bold|italic|uppercase|rounded|round|shadowed|underlined|bordered|faded|dark|light|bright|big|small|too \w+)\b)/g,
|
|
1592
2261
|
' not ',
|
|
1593
2262
|
)
|
|
2263
|
+
// Tailwind classes: "border-2" is 2px, "rounded-full" a pill.
|
|
2264
|
+
.replace(/\bborder-(\d)\b/g, 'border width $1px')
|
|
2265
|
+
.replace(/\brounded-full\b/g, 'pill corners')
|
|
2266
|
+
.replace(/\brounded-none\b/g, 'square corners')
|
|
2267
|
+
// "1e3px" is 1000px.
|
|
2268
|
+
.replace(
|
|
2269
|
+
/\b(\d+(?:\.\d+)?)e([+-]?\d+)(px|rem|em)\b/gi,
|
|
2270
|
+
(_, n, e, u) => `${Number(n) * 10 ** Number(e)}${u}`,
|
|
2271
|
+
)
|
|
2272
|
+
// "not so round", "not that dark": one step less, not the opposite.
|
|
2273
|
+
.replace(
|
|
2274
|
+
/\bnot (?:so|that|as|too) (round(?:ed)?|bold|dark|big|bright|spacious|thick)\b/g,
|
|
2275
|
+
'less $1',
|
|
2276
|
+
)
|
|
2277
|
+
// "flat cards, not flat buttons": the second part stays as it is.
|
|
2278
|
+
.replace(/^(.*\b(\w{3,})\b.*?),\s*(?:but )?not \2 [a-z ]+$/, '$1')
|
|
1594
2279
|
.replace(/\b(everything|everywhere|all) but\b/g, '$1 except')
|
|
1595
2280
|
.replace(
|
|
1596
2281
|
/\b(apart from|other than|excluding|but not (on|in|for)|but not)\b/g,
|
|
@@ -1598,7 +2283,75 @@ export function draftAnswer(ctx, env, question) {
|
|
|
1598
2283
|
)
|
|
1599
2284
|
.replace(/\s+/g, ' ')
|
|
1600
2285
|
.trim();
|
|
2286
|
+
// "cramped on mobile": the editor has no media conditions; the rest of
|
|
2287
|
+
// the ask is answered, with a note.
|
|
2288
|
+
const MEDIA_RE = new RegExp(
|
|
2289
|
+
String.raw`(?<!\bno |\bnot )\b(?:below|above|under|over|wider than|narrower than)\s+(?:\d{3,}px|\d+em)\b|\b(?:screens?|viewports?|windows?) (?:below|above|under|over|less than|more than|wider than|narrower than)\s+\d+(?:px|em|rem)\b|\b(?:on|for) (?:mobile|phones?|tablets?|desktops?|touch(?: screens?)?|small screens?|large screens?|wide screens?|landscape|portrait)\b|\b(?:when )?print(?:ing)?\b|\b(?:the )?print version\b`,
|
|
2290
|
+
'g',
|
|
2291
|
+
);
|
|
2292
|
+
const media = MEDIA_RE.test(q);
|
|
2293
|
+
if (media) q = q.replace(MEDIA_RE, ' ').replace(/\s+/g, ' ').trim();
|
|
1601
2294
|
const clauses = clausesOf(q, lex.parts);
|
|
2295
|
+
// "checkboxes green": the color a checked box fills with.
|
|
2296
|
+
for (const c of clauses)
|
|
2297
|
+
if (
|
|
2298
|
+
c.parts.length === 1 &&
|
|
2299
|
+
c.parts[0].on === 'checks' &&
|
|
2300
|
+
c.colors.length &&
|
|
2301
|
+
!c.state &&
|
|
2302
|
+
!c.named &&
|
|
2303
|
+
!/\b(border|outline|background|unchecked)\b/.test(c.text)
|
|
2304
|
+
)
|
|
2305
|
+
c.state = 'checked';
|
|
2306
|
+
// "labels on form fields": the label, not the field it sits on.
|
|
2307
|
+
for (const c of clauses)
|
|
2308
|
+
if (c.parts.some(p => p.on === 'field-label')) {
|
|
2309
|
+
// A checkbox's or switch's own label part, when Core has one.
|
|
2310
|
+
const own = c.parts
|
|
2311
|
+
.map(p => ({
|
|
2312
|
+
on:
|
|
2313
|
+
/** @type {Record<string, string>} */ ({
|
|
2314
|
+
checks: 'checkbox-label',
|
|
2315
|
+
checkbox: 'checkbox-label',
|
|
2316
|
+
switch: 'switch-label',
|
|
2317
|
+
})[p.on] ?? p.on,
|
|
2318
|
+
}))
|
|
2319
|
+
.filter(
|
|
2320
|
+
p =>
|
|
2321
|
+
/-label$/.test(p.on) && p.on !== 'field-label' && TARGET.has(p.on),
|
|
2322
|
+
);
|
|
2323
|
+
// "button labels": the label is the button's own text.
|
|
2324
|
+
const owner = c.parts.filter(
|
|
2325
|
+
p =>
|
|
2326
|
+
p.on !== 'field-label' &&
|
|
2327
|
+
![
|
|
2328
|
+
'inputs',
|
|
2329
|
+
'field',
|
|
2330
|
+
'checks',
|
|
2331
|
+
'checkbox',
|
|
2332
|
+
'switch',
|
|
2333
|
+
'text-input',
|
|
2334
|
+
].includes(p.on),
|
|
2335
|
+
);
|
|
2336
|
+
c.parts = own.length
|
|
2337
|
+
? own
|
|
2338
|
+
: owner.length
|
|
2339
|
+
? owner
|
|
2340
|
+
: c.parts.filter(p => p.on === 'field-label');
|
|
2341
|
+
}
|
|
2342
|
+
// "captions 12px": a clause led by a plural noun that names no part and
|
|
2343
|
+
// no change takes nothing from its neighbors.
|
|
2344
|
+
const unknownLead = (/** @type {Clause} */ c) => {
|
|
2345
|
+
const lead = /^(?:the |my |our |all )?([a-z]{4,}s)\b/.exec(c.text)?.[1];
|
|
2346
|
+
return Boolean(
|
|
2347
|
+
lead &&
|
|
2348
|
+
!c.parts.length &&
|
|
2349
|
+
!lex.vocab.includes(lead) &&
|
|
2350
|
+
!lex.vocab.includes(singular(lead)) &&
|
|
2351
|
+
!aspectsOf(lead).length &&
|
|
2352
|
+
!KEEP.has(lead),
|
|
2353
|
+
);
|
|
2354
|
+
};
|
|
1602
2355
|
for (const c of clauses) {
|
|
1603
2356
|
c.quoted = [...c.text.matchAll(/qq(\d+)qq/g)].map(
|
|
1604
2357
|
m => quoted[Number(m[1])],
|
|
@@ -1705,6 +2458,8 @@ export function draftAnswer(ctx, env, question) {
|
|
|
1705
2458
|
c.dir &&
|
|
1706
2459
|
!c.aspects.length &&
|
|
1707
2460
|
!c.colors.length &&
|
|
2461
|
+
// "tooltips darker" is a color, never the border of the clause before.
|
|
2462
|
+
!/\b(dark|light|bright|dim)(er)?\b/.test(c.text) &&
|
|
1708
2463
|
prev.aspects.length
|
|
1709
2464
|
)
|
|
1710
2465
|
c.aspects = [...prev.aspects];
|
|
@@ -1974,6 +2729,7 @@ export function draftAnswer(ctx, env, question) {
|
|
|
1974
2729
|
!(ROLE_WORDS.test(c.text) && !c.aspects.length) &&
|
|
1975
2730
|
// "Circular font" after "12px cards" is the theme's font.
|
|
1976
2731
|
!(c.aspects.length && c.aspects.every(a => a === 'family')) &&
|
|
2732
|
+
!unknownLead(c) &&
|
|
1977
2733
|
// "serif headings, no shadows": a type part does not take a shadow,
|
|
1978
2734
|
// corner or border ask.
|
|
1979
2735
|
!(
|
|
@@ -1991,6 +2747,7 @@ export function draftAnswer(ctx, env, question) {
|
|
|
1991
2747
|
if (
|
|
1992
2748
|
!c.aspects.length &&
|
|
1993
2749
|
!ROLE_WORDS.test(c.text) &&
|
|
2750
|
+
!unknownLead(c) &&
|
|
1994
2751
|
(c.lengths.length || /\b(stay|keep)\b/.test(c.text))
|
|
1995
2752
|
) {
|
|
1996
2753
|
const from = prev?.aspects.length
|
|
@@ -1998,7 +2755,12 @@ export function draftAnswer(ctx, env, question) {
|
|
|
1998
2755
|
: next?.aspects.length
|
|
1999
2756
|
? next
|
|
2000
2757
|
: null;
|
|
2001
|
-
|
|
2758
|
+
// Only the aspects a length can set: "headings 32px bold, captions
|
|
2759
|
+
// 12px" gives captions a size, not the headings' bold.
|
|
2760
|
+
if (from)
|
|
2761
|
+
c.aspects = from.aspects.filter(
|
|
2762
|
+
a => !['weight', 'italic', 'case', 'family'].includes(a),
|
|
2763
|
+
);
|
|
2002
2764
|
}
|
|
2003
2765
|
// "in dark mode, cards are #1c1c1e": a clause that only names the mode
|
|
2004
2766
|
// gives it to the clauses after it.
|
|
@@ -2034,12 +2796,28 @@ export function draftAnswer(ctx, env, question) {
|
|
|
2034
2796
|
c.parts = [];
|
|
2035
2797
|
c.text = '';
|
|
2036
2798
|
}
|
|
2799
|
+
// "the same accent in light and dark": every mode, so no mode.
|
|
2800
|
+
if (
|
|
2801
|
+
/\b(light and dark|dark and light|both modes|every mode|all modes|same in (both|light and dark))\b/.test(
|
|
2802
|
+
q,
|
|
2803
|
+
)
|
|
2804
|
+
)
|
|
2805
|
+
for (const c of clauses) c.mode = null;
|
|
2037
2806
|
// "only in dark mode, …": a clause that only names a mode scopes every
|
|
2038
2807
|
// clause after it.
|
|
2039
2808
|
for (let i = 0; i < clauses.length; i++) {
|
|
2040
2809
|
const c = clauses[i];
|
|
2041
|
-
if (c.mode && !c.parts.length && !c.aspects.length && !c.colors.length)
|
|
2042
|
-
|
|
2810
|
+
if (c.mode && !c.parts.length && !c.aspects.length && !c.colors.length) {
|
|
2811
|
+
// "don't touch dark mode, …": the other mode.
|
|
2812
|
+
const scope = c.neg ? (c.mode === 'dark' ? 'light' : 'dark') : c.mode;
|
|
2813
|
+
for (const o of c.neg ? clauses : clauses.slice(i + 1))
|
|
2814
|
+
if (o !== c) o.mode ??= scope;
|
|
2815
|
+
if (c.neg) {
|
|
2816
|
+
for (const o of clauses)
|
|
2817
|
+
if (o !== c && o.mode === c.mode) o.mode = scope;
|
|
2818
|
+
c.text = '';
|
|
2819
|
+
}
|
|
2820
|
+
}
|
|
2043
2821
|
}
|
|
2044
2822
|
// The tab's text is on the tab, not on its underline.
|
|
2045
2823
|
for (const c of clauses)
|
|
@@ -2067,8 +2845,49 @@ export function draftAnswer(ctx, env, question) {
|
|
|
2067
2845
|
if (!aspectsSeen.includes(a)) aspectsSeen.push(a);
|
|
2068
2846
|
};
|
|
2069
2847
|
/** @param {string} token @param {'light' | 'dark'} [mode] */
|
|
2848
|
+
// The theme's own value (its settings applied), else the base theme's.
|
|
2070
2849
|
const current = (token, mode = 'light') =>
|
|
2071
|
-
env.
|
|
2850
|
+
env.own?.[mode]?.[token] ??
|
|
2851
|
+
env.base[mode]?.[token] ??
|
|
2852
|
+
String(TOKENS[token] ?? '');
|
|
2853
|
+
/**
|
|
2854
|
+
* What the theme itself sets for a CSS property on a part (its plain
|
|
2855
|
+
* setting: no variant, state or mode), so a change by an amount starts
|
|
2856
|
+
* from the theme, not from Core.
|
|
2857
|
+
* @param {string} on @param {string} prop
|
|
2858
|
+
*/
|
|
2859
|
+
const partValue = (on, prop) =>
|
|
2860
|
+
[...env.data.settings]
|
|
2861
|
+
.reverse()
|
|
2862
|
+
.find(
|
|
2863
|
+
st =>
|
|
2864
|
+
st.thing === prop &&
|
|
2865
|
+
st.on === on &&
|
|
2866
|
+
!st.when &&
|
|
2867
|
+
!st.state &&
|
|
2868
|
+
!st.mode,
|
|
2869
|
+
)?.value ?? null;
|
|
2870
|
+
/**
|
|
2871
|
+
* The theme's own whole-theme value for a dial (its last plain setting).
|
|
2872
|
+
* @param {string} thing
|
|
2873
|
+
*/
|
|
2874
|
+
const ownDial = thing =>
|
|
2875
|
+
[...env.data.settings]
|
|
2876
|
+
.reverse()
|
|
2877
|
+
.find(
|
|
2878
|
+
st => st.thing === thing && !st.on && !st.when && !st.state && !st.mode,
|
|
2879
|
+
)?.value ?? null;
|
|
2880
|
+
/**
|
|
2881
|
+
* The text-size a step takes from the theme's own size: a number moves by
|
|
2882
|
+
* the dial's step of 2px; a named size steps with more/less.
|
|
2883
|
+
* @param {'more' | 'less'} dir
|
|
2884
|
+
*/
|
|
2885
|
+
const textSizeStep = dir => {
|
|
2886
|
+
const own = ownDial('text-size');
|
|
2887
|
+
return own && /^\d+(\.\d+)?$/.test(own)
|
|
2888
|
+
? String(Number(own) + (dir === 'less' ? -2 : 2))
|
|
2889
|
+
: dir;
|
|
2890
|
+
};
|
|
2072
2891
|
/** The member a group's checks read. @param {string} on */
|
|
2073
2892
|
const one = on => (FAMILIES[on] ? FAMILIES[on][0] : on);
|
|
2074
2893
|
/**
|
|
@@ -2229,6 +3048,15 @@ export function draftAnswer(ctx, env, question) {
|
|
|
2229
3048
|
thing,
|
|
2230
3049
|
value,
|
|
2231
3050
|
...Object.fromEntries(Object.entries(flags).filter(([, v]) => v)),
|
|
3051
|
+
// One member of a group ("the text area") is that member only; set
|
|
3052
|
+
// otherwise reaches the whole group.
|
|
3053
|
+
// (set spreads only the inputs and checks groups).
|
|
3054
|
+
...(flags.on &&
|
|
3055
|
+
['inputs', 'checks'].some(g =>
|
|
3056
|
+
(FAMILIES[g] ?? []).includes(/** @type {string} */ (flags.on)),
|
|
3057
|
+
)
|
|
3058
|
+
? {only: true}
|
|
3059
|
+
: {}),
|
|
2232
3060
|
});
|
|
2233
3061
|
/** A color for the clause, for a fill or a text color. @param {Clause} c @param {'fill' | 'text'} kind */
|
|
2234
3062
|
const colorFor = (c, kind) => {
|
|
@@ -2332,13 +3160,20 @@ export function draftAnswer(ctx, env, question) {
|
|
|
2332
3160
|
);
|
|
2333
3161
|
// "buttons twice as round as inputs": the part after "as" is only the
|
|
2334
3162
|
// measure; the first part is the one that changes.
|
|
2335
|
-
const asAs =
|
|
3163
|
+
const asAs =
|
|
3164
|
+
/\bas \w+ as (?:the )?([a-z-]+)/.exec(c.text) ??
|
|
3165
|
+
// "cards twice the padding of buttons": the same, by the measure.
|
|
3166
|
+
/\b(?:twice|double|half|triple|three times)\s+(?:the\s+)?\w+\s+(?:of|than|as)\s+(?:the\s+)?([a-z-]+)/.exec(
|
|
3167
|
+
c.text,
|
|
3168
|
+
);
|
|
2336
3169
|
if (asAs && c.parts.length >= 2) {
|
|
2337
3170
|
const after = (/** @type {{on: string}} */ p) =>
|
|
2338
3171
|
lex.parts.some(
|
|
2339
3172
|
([re, x]) =>
|
|
2340
3173
|
x.on === p.on && (re.exec(c.text)?.index ?? -1) > (asAs.index ?? 0),
|
|
2341
3174
|
);
|
|
3175
|
+
const other = c.parts.find(p => after(p));
|
|
3176
|
+
if (other) compared.set(c, other.on);
|
|
2342
3177
|
c.parts = c.parts.filter(p => !after(p));
|
|
2343
3178
|
}
|
|
2344
3179
|
// "focus ring the same color as the danger color": a role's token.
|
|
@@ -2399,6 +3234,234 @@ export function draftAnswer(ctx, env, question) {
|
|
|
2399
3234
|
continue;
|
|
2400
3235
|
}
|
|
2401
3236
|
}
|
|
3237
|
+
// "decrease the radius by 2px", "add 8px to the padding": a change from
|
|
3238
|
+
// the value now, never the new value itself.
|
|
3239
|
+
// "shrink headings by 20%": a change by a share, from the value now.
|
|
3240
|
+
const share = /\bby (\d+(?:\.\d+)?)%/.exec(c.text);
|
|
3241
|
+
if (
|
|
3242
|
+
share &&
|
|
3243
|
+
/\b(shrink|grow|increase|decrease|reduce|raise|lower|bigger|smaller|more|less)\b/.test(
|
|
3244
|
+
c.text,
|
|
3245
|
+
)
|
|
3246
|
+
) {
|
|
3247
|
+
push({
|
|
3248
|
+
text: `set takes the new value, not a change by ${share[1]}%; look up what it is now, then set that value ${/\b(shrink|decrease|reduce|lower|smaller|less)\b/.test(c.text) ? 'minus' : 'plus'} ${share[1]}%`,
|
|
3249
|
+
options: [],
|
|
3250
|
+
lookup: c.parts[0]
|
|
3251
|
+
? `${HOW} ${c.parts[0].on}`
|
|
3252
|
+
: `${P} show ${env.slug}`,
|
|
3253
|
+
});
|
|
3254
|
+
continue;
|
|
3255
|
+
}
|
|
3256
|
+
// "2px rounder", "8px larger", "4px wider": a change too.
|
|
3257
|
+
const COMPARATIVE =
|
|
3258
|
+
'more|less|bigger|smaller|rounder|sharper|squarer|larger|wider|narrower|taller|shorter|thicker|thinner|higher|lower|tighter|looser|roomier|airier|denser|bolder|heavier|lighter';
|
|
3259
|
+
// A weight moved by a number ("100 bolder"): set takes the new weight.
|
|
3260
|
+
const weightDelta = /\b(\d{2,3}) (bolder|heavier|lighter|thinner)\b/.exec(
|
|
3261
|
+
c.text,
|
|
3262
|
+
);
|
|
3263
|
+
if (weightDelta) {
|
|
3264
|
+
push({
|
|
3265
|
+
text: `set takes the new weight, not a change by ${weightDelta[1]}; look up the weight now, then set it ${/lighter|thinner/.test(weightDelta[2]) ? 'minus' : 'plus'} ${weightDelta[1]}`,
|
|
3266
|
+
options: [],
|
|
3267
|
+
lookup: c.parts[0]
|
|
3268
|
+
? `${HOW} ${c.parts[0].on}`
|
|
3269
|
+
: `${P} show ${env.slug}`,
|
|
3270
|
+
});
|
|
3271
|
+
continue;
|
|
3272
|
+
}
|
|
3273
|
+
// Amounts in rem or em count at a 16px root.
|
|
3274
|
+
const delta = new RegExp(
|
|
3275
|
+
`\\b(?:by|add(?:ing)?|plus|minus|subtract(?:ing)?)\\s+(\\d*\\.?\\d+)(px|rem|em)\\b|\\b(\\d*\\.?\\d+)(px|rem|em) (?:${COMPARATIVE})\\b`,
|
|
3276
|
+
).exec(c.text);
|
|
3277
|
+
if (
|
|
3278
|
+
delta &&
|
|
3279
|
+
new RegExp(
|
|
3280
|
+
`\\b(by|add|adding|plus|minus|subtract|subtracting|increase|decrease|reduce|${COMPARATIVE})\\b`,
|
|
3281
|
+
).test(c.text)
|
|
3282
|
+
) {
|
|
3283
|
+
const unit = delta[2] ?? delta[4];
|
|
3284
|
+
const n =
|
|
3285
|
+
Math.round(
|
|
3286
|
+
Number(delta[1] ?? delta[3]) * (unit === 'px' ? 1 : 16) * 100,
|
|
3287
|
+
) / 100;
|
|
3288
|
+
const down =
|
|
3289
|
+
/\b(decrease|reduce|less|smaller|minus|subtract|subtracting|lower|shrink|sharper|squarer|narrower|shorter|thinner|tighter|denser|lighter)\b/.test(
|
|
3290
|
+
c.text,
|
|
3291
|
+
);
|
|
3292
|
+
const cornerAsk =
|
|
3293
|
+
c.aspects.includes('corners') ||
|
|
3294
|
+
/\b(rounder|sharper|squarer)\b/.test(c.text);
|
|
3295
|
+
// A part's corners: its radius token, moved by the amount.
|
|
3296
|
+
if (cornerAsk && c.parts.length) {
|
|
3297
|
+
const on = c.parts[0].on;
|
|
3298
|
+
const read = C.partReads(one(on), 'corners')[0];
|
|
3299
|
+
// A radius the theme set on the part in px moves from that value.
|
|
3300
|
+
const ownRadius = partValue(on, 'border-radius');
|
|
3301
|
+
if (ownRadius && /^\d*\.?\d+px$/.test(ownRadius)) {
|
|
3302
|
+
const next = Math.max(0, parseFloat(ownRadius) + (down ? -n : n));
|
|
3303
|
+
const d = {
|
|
3304
|
+
text: `${on}'s corners ${down ? 'down' : 'up'} by ${n}px: from ${ownRadius} to ${next}px`,
|
|
3305
|
+
options: [[set('border-radius', `${next}px`, {on})]],
|
|
3306
|
+
};
|
|
3307
|
+
push(d);
|
|
3308
|
+
recordTop(c, d.options[0] ?? []);
|
|
3309
|
+
continue;
|
|
3310
|
+
}
|
|
3311
|
+
if (read) {
|
|
3312
|
+
const d = {
|
|
3313
|
+
text: `${on}'s corners ${down ? 'down' : 'up'} by ${n}px: ${read.token} ${down ? '-' : '+'} ${n}px`,
|
|
3314
|
+
options: [
|
|
3315
|
+
[
|
|
3316
|
+
set(
|
|
3317
|
+
'border-radius',
|
|
3318
|
+
`max(0px, calc(var(${read.token}) ${down ? '-' : '+'} ${n}px))`,
|
|
3319
|
+
{on},
|
|
3320
|
+
),
|
|
3321
|
+
],
|
|
3322
|
+
],
|
|
3323
|
+
};
|
|
3324
|
+
push(d);
|
|
3325
|
+
recordTop(c, d.options[0] ?? []);
|
|
3326
|
+
continue;
|
|
3327
|
+
}
|
|
3328
|
+
}
|
|
3329
|
+
if (cornerAsk && !c.parts.length) {
|
|
3330
|
+
const now = parseFloat(current('--radius-element'));
|
|
3331
|
+
const nowPx = /rem$/.test(current('--radius-element')) ? now * 16 : now;
|
|
3332
|
+
const next = Math.max(
|
|
3333
|
+
0,
|
|
3334
|
+
Math.round((nowPx + (down ? -n : n)) * 100) / 100,
|
|
3335
|
+
);
|
|
3336
|
+
const d = {
|
|
3337
|
+
text: `corners ${down ? 'down' : 'up'} by ${n}px: from ${Math.round(nowPx * 100) / 100}px to ${next}px`,
|
|
3338
|
+
options: [[set('corners', `${next}px`)]],
|
|
3339
|
+
};
|
|
3340
|
+
push(d);
|
|
3341
|
+
recordTop(c, d.options[0] ?? []);
|
|
3342
|
+
continue;
|
|
3343
|
+
}
|
|
3344
|
+
push({
|
|
3345
|
+
text: `set takes the new value, not a change by ${n}px; look up what it is now, then set it ${down ? 'minus' : 'plus'} ${n}px`,
|
|
3346
|
+
options: [],
|
|
3347
|
+
lookup: c.parts[0]
|
|
3348
|
+
? `${HOW} ${c.parts[0].on}`
|
|
3349
|
+
: `${P} show ${env.slug}`,
|
|
3350
|
+
});
|
|
3351
|
+
continue;
|
|
3352
|
+
}
|
|
3353
|
+
// "all corners like the buttons": every other radius token takes the
|
|
3354
|
+
// one the named part reads.
|
|
3355
|
+
if (
|
|
3356
|
+
c.parts.length === 1 &&
|
|
3357
|
+
c.aspects.includes('corners') &&
|
|
3358
|
+
/\b(all|every|other|everything|everywhere)\b/.test(c.text) &&
|
|
3359
|
+
/\b(like|match(es|ing)?|same as)\b/.test(c.text)
|
|
3360
|
+
) {
|
|
3361
|
+
const source = c.parts[0].on;
|
|
3362
|
+
const read = C.partReads(one(source), 'corners')[0];
|
|
3363
|
+
if (read) {
|
|
3364
|
+
const others = Object.keys(TOKENS).filter(
|
|
3365
|
+
t =>
|
|
3366
|
+
/^--radius-/.test(t) &&
|
|
3367
|
+
t !== read.token &&
|
|
3368
|
+
!/^--radius-(none|full)$/.test(t),
|
|
3369
|
+
);
|
|
3370
|
+
const d = {
|
|
3371
|
+
text: `every corner like ${source}'s: the other radius tokens take ${read.token}, which ${source} reads`,
|
|
3372
|
+
options: [others.map(t => set(t, `var(${read.token})`))],
|
|
3373
|
+
sequence: others.length > 1,
|
|
3374
|
+
};
|
|
3375
|
+
push(d);
|
|
3376
|
+
recordTop(c, d.options[0] ?? []);
|
|
3377
|
+
continue;
|
|
3378
|
+
}
|
|
3379
|
+
}
|
|
3380
|
+
// "text on the accent color is hard to read": the on-accent text color,
|
|
3381
|
+
// the one of black or white that reads on the accent in each mode.
|
|
3382
|
+
if (
|
|
3383
|
+
/\btext on (?:the )?accent\b/.test(c.text) &&
|
|
3384
|
+
TOKENS['--color-on-accent'] !== undefined
|
|
3385
|
+
) {
|
|
3386
|
+
const steps = /** @type {Array<'light' | 'dark'>} */ (['light', 'dark'])
|
|
3387
|
+
.filter(m => env.data.mode === 'both' || m === 'light')
|
|
3388
|
+
.map(m => {
|
|
3389
|
+
const acc = parseColor(current('--color-accent', m));
|
|
3390
|
+
const pick =
|
|
3391
|
+
acc && ratio(acc, [255, 255, 255]) >= ratio(acc, [0, 0, 0])
|
|
3392
|
+
? '#ffffff'
|
|
3393
|
+
: '#000000';
|
|
3394
|
+
return set(
|
|
3395
|
+
'--color-on-accent',
|
|
3396
|
+
pick,
|
|
3397
|
+
env.data.mode === 'both' ? {mode: m} : {},
|
|
3398
|
+
);
|
|
3399
|
+
});
|
|
3400
|
+
const d = {
|
|
3401
|
+
text: 'the text on the accent: --color-on-accent, black or white, whichever reads better on the accent',
|
|
3402
|
+
options: [steps],
|
|
3403
|
+
sequence: steps.length > 1,
|
|
3404
|
+
};
|
|
3405
|
+
push(d);
|
|
3406
|
+
recordTop(c, d.options[0] ?? []);
|
|
3407
|
+
continue;
|
|
3408
|
+
}
|
|
3409
|
+
// "5 lines tall text box": a text area's height in lines.
|
|
3410
|
+
const lines = /\b(\d+) (?:lines?|rows?) (?:tall|high)\b/.exec(c.text);
|
|
3411
|
+
if (lines && TARGET.has('text-area')) {
|
|
3412
|
+
const d = {
|
|
3413
|
+
text: `a text area ${lines[1]} lines tall: min-height ${lines[1]}lh`,
|
|
3414
|
+
options: [[set('min-height', `${lines[1]}lh`, {on: 'text-area'})]],
|
|
3415
|
+
};
|
|
3416
|
+
push(d);
|
|
3417
|
+
recordTop(c, d.options[0] ?? []);
|
|
3418
|
+
continue;
|
|
3419
|
+
}
|
|
3420
|
+
// "outline offset 3px on focus": the focus ring's offset, not a border.
|
|
3421
|
+
if (
|
|
3422
|
+
!c.parts.length &&
|
|
3423
|
+
/\boutline[- ]offset\b/.test(c.text) &&
|
|
3424
|
+
c.lengths[0]
|
|
3425
|
+
) {
|
|
3426
|
+
const d = {
|
|
3427
|
+
text: "the focus ring's offset: --focus-outline-offset",
|
|
3428
|
+
options: [[set('--focus-outline-offset', c.lengths[0])]],
|
|
3429
|
+
};
|
|
3430
|
+
push(d);
|
|
3431
|
+
recordTop(c, d.options[0] ?? []);
|
|
3432
|
+
continue;
|
|
3433
|
+
}
|
|
3434
|
+
// Placeholder, caret and selection colors.
|
|
3435
|
+
if (
|
|
3436
|
+
/\b(placeholders?|caret|cursor colou?r|colou?r (of )?the cursor|selection|selected text highlight|text highlight)\b/.test(
|
|
3437
|
+
c.text,
|
|
3438
|
+
) &&
|
|
3439
|
+
!/\bloading placeholder/.test(c.text)
|
|
3440
|
+
) {
|
|
3441
|
+
const color = colorFor(c, 'fill');
|
|
3442
|
+
const caret =
|
|
3443
|
+
/\bcaret\b|\bcursor colou?r\b|\bcolou?r (of )?the cursor\b/.test(
|
|
3444
|
+
c.text,
|
|
3445
|
+
);
|
|
3446
|
+
if (caret && color) {
|
|
3447
|
+
const on = c.parts[0]?.on ?? 'inputs';
|
|
3448
|
+
const d = {
|
|
3449
|
+
text: `the text cursor color on ${on}: caret-color`,
|
|
3450
|
+
options: [[set('caret-color', color, {on})]],
|
|
3451
|
+
};
|
|
3452
|
+
push(d);
|
|
3453
|
+
recordTop(c, d.options[0] ?? []);
|
|
3454
|
+
continue;
|
|
3455
|
+
}
|
|
3456
|
+
push({
|
|
3457
|
+
text: caret
|
|
3458
|
+
? 'name the cursor color: caret-color takes a color'
|
|
3459
|
+
: `${/\bplaceholder/.test(c.text) ? 'placeholder text' : 'the text selection highlight'} has no setting: the editor themes parts, not ${/\bplaceholder/.test(c.text) ? '::placeholder' : '::selection'}; it takes your own CSS`,
|
|
3460
|
+
options: [],
|
|
3461
|
+
lookup: `${HOW} inputs`,
|
|
3462
|
+
});
|
|
3463
|
+
continue;
|
|
3464
|
+
}
|
|
2402
3465
|
// "… and set --border-width 2px": a real token typed in a clause.
|
|
2403
3466
|
// The value runs to the clause end ("--shadow-high 0 4px 12px black").
|
|
2404
3467
|
const tok = /(?:^|\s)(--[a-z][a-z0-9-]*)\s*:?\s+([^;]+?)\s*$/.exec(c.text);
|
|
@@ -2421,10 +3484,7 @@ export function draftAnswer(ctx, env, question) {
|
|
|
2421
3484
|
}
|
|
2422
3485
|
// "error text red", "labels smaller": text that belongs to parts how
|
|
2423
3486
|
// 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
|
-
) {
|
|
3487
|
+
if (!c.parts.length && /\berror (text|messages?)\b/.test(c.text)) {
|
|
2428
3488
|
const which = /\berror\b/.test(c.text) ? 'error text' : 'labels';
|
|
2429
3489
|
push({
|
|
2430
3490
|
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`,
|
|
@@ -2545,7 +3605,7 @@ export function draftAnswer(ctx, env, question) {
|
|
|
2545
3605
|
function resetAnswer(c) {
|
|
2546
3606
|
// "go back to the neutral theme", "start over": every setting.
|
|
2547
3607
|
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(
|
|
3608
|
+
/\b(back to|reset to|revert to|restore) (the )?(neutral|base|original|default|plain) theme\b|\bstart over\b|\breset (the )?(whole )?theme\b|\b(remove|undo|clear|drop|revert) (all|every one of|each of) (my |the )?(changes|settings|edits|overrides)\b|\bundo everything\b/.test(
|
|
2549
3609
|
c.text,
|
|
2550
3610
|
)
|
|
2551
3611
|
) {
|
|
@@ -2574,7 +3634,7 @@ export function draftAnswer(ctx, env, question) {
|
|
|
2574
3634
|
};
|
|
2575
3635
|
}
|
|
2576
3636
|
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(
|
|
3637
|
+
!/\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|^undo|take back|like before|as before|the way (it|they) (was|were)|by accident|accidentally|put .* back|.* back to normal)\b/.test(
|
|
2578
3638
|
c.text,
|
|
2579
3639
|
) ||
|
|
2580
3640
|
/\bby default\b|\bthe last change\b|\beverything\b/.test(c.text) ||
|
|
@@ -2740,45 +3800,70 @@ export function draftAnswer(ctx, env, question) {
|
|
|
2740
3800
|
]);
|
|
2741
3801
|
if (on === 'focus-ring') {
|
|
2742
3802
|
const ringColor = colorFor(c, 'fill');
|
|
3803
|
+
// "focus ring on inputs only": the ring's tokens set on that part or
|
|
3804
|
+
// group, so the other parts keep theirs.
|
|
3805
|
+
const scope =
|
|
3806
|
+
c.parts.map(x => x.on).find(x => x && x !== 'focus-ring') ?? null;
|
|
3807
|
+
const sc = scope ? {on: scope} : {};
|
|
3808
|
+
const scoped = scope ? ` on ${scope} only` : '';
|
|
2743
3809
|
if (ringColor && c.lengths[0] && !c.neg)
|
|
2744
3810
|
return {
|
|
2745
|
-
text:
|
|
3811
|
+
text: `the focus ring's width and color${scoped}: --focus-outline-width and --focus-outline-color`,
|
|
2746
3812
|
options: [
|
|
2747
3813
|
[
|
|
2748
|
-
set('--focus-outline-width', c.lengths[0]),
|
|
2749
|
-
set('--focus-outline-color', ringColor, modeOf(c)),
|
|
3814
|
+
set('--focus-outline-width', c.lengths[0], sc),
|
|
3815
|
+
set('--focus-outline-color', ringColor, {...modeOf(c), ...sc}),
|
|
2750
3816
|
],
|
|
2751
3817
|
],
|
|
2752
3818
|
sequence: true,
|
|
2753
3819
|
};
|
|
3820
|
+
// "remove the focus outline": a ring keyboard users need; set it to
|
|
3821
|
+
// nothing only on the ask, and say what that costs.
|
|
3822
|
+
if (c.neg || /\b(remove|hide|get rid of)\b/.test(c.text))
|
|
3823
|
+
return {
|
|
3824
|
+
text: `no focus ring${scoped}: --focus-outline-width 0px. Keyboard users then cannot see where they are, so keep a visible focus style another way`,
|
|
3825
|
+
options: [[set('--focus-outline-width', '0px', sc)]],
|
|
3826
|
+
};
|
|
3827
|
+
// "focus ring offset 2px": the gap between the part and its ring.
|
|
3828
|
+
if (/\boffset\b/.test(c.text))
|
|
3829
|
+
return c.lengths[0]
|
|
3830
|
+
? {
|
|
3831
|
+
text: `the focus ring's offset${scoped}: --focus-outline-offset`,
|
|
3832
|
+
options: [[set('--focus-outline-offset', c.lengths[0], sc)]],
|
|
3833
|
+
}
|
|
3834
|
+
: null;
|
|
2754
3835
|
if (
|
|
2755
3836
|
(a === 'border' && !ringColor) ||
|
|
2756
3837
|
a === 'size' ||
|
|
2757
3838
|
a === 'spacing' ||
|
|
2758
|
-
/\b(thick|thin|width)/.test(
|
|
3839
|
+
/\b(thick|thin|width|strength|stronger|weaker|bolder|subtler)/.test(
|
|
3840
|
+
c.text,
|
|
3841
|
+
)
|
|
2759
3842
|
) {
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
3843
|
+
// From the theme's own width there (on the part when it sets one).
|
|
3844
|
+
const own = scope ? partValue(scope, '--focus-outline-width') : null;
|
|
3845
|
+
const now = own ?? current('--focus-outline-width');
|
|
3846
|
+
const exact = exactFactor(c.text);
|
|
3847
|
+
const factor = exact ?? (c.dir === 'less' ? 0.5 : 1.5);
|
|
3848
|
+
const w = c.lengths[0] ?? scaled(now, factor);
|
|
3849
|
+
const strength = /\bstrength\b/.test(c.text) && !c.lengths[0];
|
|
2767
3850
|
return {
|
|
2768
|
-
text: `the focus ring's width${where}: --focus-outline-width`,
|
|
2769
|
-
options: [[set('--focus-outline-width', w)]],
|
|
3851
|
+
text: `the focus ring's width${scoped || where}: --focus-outline-width ${w ?? ''}${!c.lengths[0] && now ? ` (now ${now})` : ''}${strength ? '; "strength" read as the width of the ring' : ''}${!c.lengths[0] && !exact && !c.dir ? '; no amount was given, so this is a guess: give a width (2px)' : ''}`,
|
|
3852
|
+
options: w ? [[set('--focus-outline-width', w, sc)]] : [],
|
|
2770
3853
|
};
|
|
2771
3854
|
}
|
|
2772
3855
|
const color = colorFor(c, 'fill');
|
|
2773
3856
|
if (c.neg)
|
|
2774
3857
|
return {
|
|
2775
|
-
text:
|
|
2776
|
-
options: [[set('--focus-outline-width', '1px')]],
|
|
3858
|
+
text: `the focus ring shows keyboard users where they are; it can be made subtle but not removed${scoped}`,
|
|
3859
|
+
options: [[set('--focus-outline-width', '1px', sc)]],
|
|
2777
3860
|
};
|
|
2778
3861
|
return color
|
|
2779
3862
|
? {
|
|
2780
|
-
text: `the focus ring's color: --focus-outline-color`,
|
|
2781
|
-
options: [
|
|
3863
|
+
text: `the focus ring's color${scoped}: --focus-outline-color`,
|
|
3864
|
+
options: [
|
|
3865
|
+
[set('--focus-outline-color', color, {...modeOf(c), ...sc})],
|
|
3866
|
+
],
|
|
2782
3867
|
}
|
|
2783
3868
|
: null;
|
|
2784
3869
|
}
|
|
@@ -2824,7 +3909,14 @@ export function draftAnswer(ctx, env, question) {
|
|
|
2824
3909
|
sequence: true,
|
|
2825
3910
|
};
|
|
2826
3911
|
}
|
|
2827
|
-
const
|
|
3912
|
+
const typedTime = /\b(\d+(?:\.\d+)?)(ms|s)\b/.exec(c.text);
|
|
3913
|
+
const typedMs = typedTime
|
|
3914
|
+
? String(
|
|
3915
|
+
Math.round(
|
|
3916
|
+
Number(typedTime[1]) * (typedTime[2] === 's' ? 1000 : 1),
|
|
3917
|
+
),
|
|
3918
|
+
)
|
|
3919
|
+
: undefined;
|
|
2828
3920
|
if (typedMs && !on)
|
|
2829
3921
|
return {
|
|
2830
3922
|
text: `every motion at ${typedMs}ms: the shared duration tokens`,
|
|
@@ -2980,7 +4072,12 @@ export function draftAnswer(ctx, env, question) {
|
|
|
2980
4072
|
return {
|
|
2981
4073
|
text: 'the body text size: text-size (every heading scales from it)',
|
|
2982
4074
|
options: [
|
|
2983
|
-
[
|
|
4075
|
+
[
|
|
4076
|
+
set(
|
|
4077
|
+
'text-size',
|
|
4078
|
+
px ?? textSizeStep(c.dir === 'less' ? 'less' : 'more'),
|
|
4079
|
+
),
|
|
4080
|
+
],
|
|
2984
4081
|
],
|
|
2985
4082
|
};
|
|
2986
4083
|
}
|
|
@@ -3036,6 +4133,29 @@ export function draftAnswer(ctx, env, question) {
|
|
|
3036
4133
|
// A radius of 0 is square.
|
|
3037
4134
|
const px = typedPx && parseFloat(typedPx) === 0 ? null : typedPx;
|
|
3038
4135
|
const zero = Boolean(typedPx) && !px;
|
|
4136
|
+
// "half the corner radius on buttons": an exact amount of the
|
|
4137
|
+
// radius the part has now (its own setting, else the token it reads).
|
|
4138
|
+
// Not a comparison with another part ("twice as round as inputs"):
|
|
4139
|
+
// that amount is of the other part's radius.
|
|
4140
|
+
const cornerFactor =
|
|
4141
|
+
!typedPx &&
|
|
4142
|
+
on &&
|
|
4143
|
+
!/\b(as|than)\s+(the\s+)?\w+\s*$|\bas \w+ as\b/.test(c.text)
|
|
4144
|
+
? exactFactor(c.text)
|
|
4145
|
+
: null;
|
|
4146
|
+
if (cornerFactor) {
|
|
4147
|
+
const part = /** @type {string} */ (on);
|
|
4148
|
+
const read = C.partReads(one(part), 'corners')[0];
|
|
4149
|
+
const now =
|
|
4150
|
+
partValue(part, 'border-radius') ??
|
|
4151
|
+
(read?.token ? current(read.token) : null);
|
|
4152
|
+
const value = now ? scaled(now, cornerFactor) : null;
|
|
4153
|
+
if (value)
|
|
4154
|
+
return {
|
|
4155
|
+
text: `corners${where}: border-radius ${value} (now ${now})`,
|
|
4156
|
+
options: [[set('border-radius', value, f)]],
|
|
4157
|
+
};
|
|
4158
|
+
}
|
|
3039
4159
|
// "revert the rounded corners": take back what the theme sets.
|
|
3040
4160
|
if (/\b(revert|undo|take back)\b/.test(c.text)) {
|
|
3041
4161
|
const back = existing(['corners', 'border-radius'], on);
|
|
@@ -3352,6 +4472,36 @@ export function draftAnswer(ctx, env, question) {
|
|
|
3352
4472
|
options: [[set(gap ? 'gap' : 'padding', box, f)]],
|
|
3353
4473
|
};
|
|
3354
4474
|
}
|
|
4475
|
+
// "double the padding on cards": an exact amount of the padding the
|
|
4476
|
+
// part has now, when the theme sets one; else the dial's step, and
|
|
4477
|
+
// the answer says the amount is a step.
|
|
4478
|
+
const padFactor = exactFactor(c.text);
|
|
4479
|
+
// A comparison ("twice the padding of buttons"): the amount is of
|
|
4480
|
+
// the other part's padding, when the theme sets one; else a step,
|
|
4481
|
+
// and the answer says so.
|
|
4482
|
+
const versus = compared.get(c) ?? null;
|
|
4483
|
+
if (padFactor && versus) {
|
|
4484
|
+
const now = partValue(versus, gap ? 'gap' : 'padding');
|
|
4485
|
+
const exact = now ? scaled(now, padFactor) : null;
|
|
4486
|
+
return exact
|
|
4487
|
+
? {
|
|
4488
|
+
text: `${gap ? 'the gap' : 'padding'}${where}: ${exact} (${versus} has ${now})`,
|
|
4489
|
+
options: [[set(gap ? 'gap' : 'padding', exact, f)]],
|
|
4490
|
+
}
|
|
4491
|
+
: {
|
|
4492
|
+
text: `room inside ${on}: spacing ${value ?? 'more'}; this theme sets no ${gap ? 'gap' : 'padding'} of its own on ${versus}, so this is a step, not an exact amount of ${versus}'s: give a value (24px) for one`,
|
|
4493
|
+
options: [[set('spacing', value ?? 'more', f)]],
|
|
4494
|
+
};
|
|
4495
|
+
}
|
|
4496
|
+
if (padFactor) {
|
|
4497
|
+
const now = partValue(on, gap ? 'gap' : 'padding');
|
|
4498
|
+
const value = now ? scaled(now, padFactor) : null;
|
|
4499
|
+
if (value)
|
|
4500
|
+
return {
|
|
4501
|
+
text: `${gap ? 'the gap' : 'padding'}${where}: ${value} (now ${now})`,
|
|
4502
|
+
options: [[set(gap ? 'gap' : 'padding', value, f)]],
|
|
4503
|
+
};
|
|
4504
|
+
}
|
|
3355
4505
|
if (!value)
|
|
3356
4506
|
return {
|
|
3357
4507
|
text: `no padding${where}`,
|
|
@@ -3400,6 +4550,33 @@ export function draftAnswer(ctx, env, question) {
|
|
|
3400
4550
|
const rung = Object.entries(HEADING_WEIGHTS).find(
|
|
3401
4551
|
([, v]) => v === value,
|
|
3402
4552
|
)?.[0];
|
|
4553
|
+
// A step ("bolder", "a bit lighter") moves one rung from the
|
|
4554
|
+
// headings rung the theme sets, never back to a fixed one.
|
|
4555
|
+
const ownRung = ownDial('headings');
|
|
4556
|
+
const rungs = Object.keys(HEADING_WEIGHTS);
|
|
4557
|
+
const stepAsk =
|
|
4558
|
+
!typedW &&
|
|
4559
|
+
!c.neg &&
|
|
4560
|
+
!/\btoo /.test(c.text) &&
|
|
4561
|
+
/\b(bolder|heavier|lighter|thinner|less bold)\b/.test(c.text);
|
|
4562
|
+
if (
|
|
4563
|
+
stepAsk &&
|
|
4564
|
+
ownRung &&
|
|
4565
|
+
rungs.includes(ownRung) &&
|
|
4566
|
+
((!on && /\b(headings?|titles?)\b/.test(c.text)) ||
|
|
4567
|
+
(on === 'heading' && !f.when))
|
|
4568
|
+
) {
|
|
4569
|
+
const next = rungs[rungs.indexOf(ownRung) + (light ? -1 : 1)];
|
|
4570
|
+
if (!next)
|
|
4571
|
+
return {
|
|
4572
|
+
text: `the headings are already ${light ? 'the lightest' : 'the boldest'} rung (${ownRung}), so nothing changes`,
|
|
4573
|
+
options: [],
|
|
4574
|
+
};
|
|
4575
|
+
return {
|
|
4576
|
+
text: `${next} headings: one rung ${light ? 'lighter' : 'bolder'} than ${ownRung}`,
|
|
4577
|
+
options: [[set('headings', next)]],
|
|
4578
|
+
};
|
|
4579
|
+
}
|
|
3403
4580
|
if (
|
|
3404
4581
|
(!on && /\b(headings?|titles?)\b/.test(c.text)) ||
|
|
3405
4582
|
(on === 'heading' && !f.when)
|
|
@@ -3450,6 +4627,49 @@ export function draftAnswer(ctx, env, question) {
|
|
|
3450
4627
|
const px = c.lengths[0];
|
|
3451
4628
|
const f2 = /\bmuch\b/.test(c.text) ? 1.5 : 1.25;
|
|
3452
4629
|
const factor = c.dir === 'less' ? 1 / f2 : f2;
|
|
4630
|
+
// An exact --font-size-base wins over the text-size dial, so the
|
|
4631
|
+
// dial would change nothing there: step that token instead.
|
|
4632
|
+
const pinned = on
|
|
4633
|
+
? null
|
|
4634
|
+
: ([...env.data.settings]
|
|
4635
|
+
.reverse()
|
|
4636
|
+
.find(
|
|
4637
|
+
st =>
|
|
4638
|
+
st.source === 'token' &&
|
|
4639
|
+
st.thing === '--font-size-base' &&
|
|
4640
|
+
!st.on &&
|
|
4641
|
+
!st.when &&
|
|
4642
|
+
!st.state &&
|
|
4643
|
+
!st.mode,
|
|
4644
|
+
)?.value ?? null);
|
|
4645
|
+
if (pinned != null) {
|
|
4646
|
+
const m = /^(\d*\.?\d+)(px|rem|em)$/i.exec(pinned.trim());
|
|
4647
|
+
const next = px
|
|
4648
|
+
? px
|
|
4649
|
+
: m
|
|
4650
|
+
? `${Math.round(parseFloat(m[1]) * factor * 100) / 100}${m[2].toLowerCase()}`
|
|
4651
|
+
: null;
|
|
4652
|
+
return next
|
|
4653
|
+
? {
|
|
4654
|
+
text: `the base text size: --font-size-base, set exactly to ${pinned} (it wins over the text-size dial)`,
|
|
4655
|
+
options: [[set('--font-size-base', next)]],
|
|
4656
|
+
}
|
|
4657
|
+
: {
|
|
4658
|
+
text: `the base text size: --font-size-base is set exactly to ${pinned}, which wins over the text-size dial; remove it, then text-size changes the size`,
|
|
4659
|
+
options: [
|
|
4660
|
+
[
|
|
4661
|
+
/** @type {Step} */ ({
|
|
4662
|
+
verb: 'undo',
|
|
4663
|
+
thing: '--font-size-base',
|
|
4664
|
+
}),
|
|
4665
|
+
set(
|
|
4666
|
+
'text-size',
|
|
4667
|
+
textSizeStep(c.dir === 'less' ? 'less' : 'more'),
|
|
4668
|
+
),
|
|
4669
|
+
],
|
|
4670
|
+
],
|
|
4671
|
+
};
|
|
4672
|
+
}
|
|
3453
4673
|
if (!on)
|
|
3454
4674
|
return {
|
|
3455
4675
|
text: 'the base text size: text-size (every heading scales from it)',
|
|
@@ -3463,9 +4683,7 @@ export function draftAnswer(ctx, env, question) {
|
|
|
3463
4683
|
? Math.round(parseFloat(px) * 16 * 100) / 100
|
|
3464
4684
|
: parseFloat(px),
|
|
3465
4685
|
)
|
|
3466
|
-
: c.dir === 'less'
|
|
3467
|
-
? 'less'
|
|
3468
|
-
: 'more',
|
|
4686
|
+
: textSizeStep(c.dir === 'less' ? 'less' : 'more'),
|
|
3469
4687
|
),
|
|
3470
4688
|
],
|
|
3471
4689
|
],
|
|
@@ -3495,12 +4713,16 @@ export function draftAnswer(ctx, env, question) {
|
|
|
3495
4713
|
r.props.includes('font-size'),
|
|
3496
4714
|
)?.token ??
|
|
3497
4715
|
Object.keys(C.MAP[one(on)]?.own?.['font-size']?.tokens ?? {})[0]);
|
|
3498
|
-
//
|
|
3499
|
-
|
|
3500
|
-
|
|
3501
|
-
|
|
3502
|
-
|
|
3503
|
-
|
|
4716
|
+
// The theme's own size on the part first; a part with no size token
|
|
4717
|
+
// of its own starts from the body size.
|
|
4718
|
+
const own = on ? partValue(on, 'font-size') : null;
|
|
4719
|
+
const now = own
|
|
4720
|
+
? own
|
|
4721
|
+
: sizeTok
|
|
4722
|
+
? current(sizeTok)
|
|
4723
|
+
: on !== 'heading' && '--text-body-size' in TOKENS
|
|
4724
|
+
? current('--text-body-size')
|
|
4725
|
+
: null;
|
|
3504
4726
|
const value = px ?? (now ? scaled(now, factor) : null);
|
|
3505
4727
|
if (!value) return null;
|
|
3506
4728
|
return {
|
|
@@ -3972,7 +5194,11 @@ export function draftAnswer(ctx, env, question) {
|
|
|
3972
5194
|
options: [steps],
|
|
3973
5195
|
sequence: steps.length > 1,
|
|
3974
5196
|
}
|
|
3975
|
-
:
|
|
5197
|
+
: {
|
|
5198
|
+
// The theme's own page is already at the end of the range.
|
|
5199
|
+
text: `the page background of ${env.slug} is already ${lighter ? 'as light' : 'as dark'} as it goes (${current('--color-background-body')}), so nothing changes`,
|
|
5200
|
+
options: [],
|
|
5201
|
+
};
|
|
3976
5202
|
}
|
|
3977
5203
|
if (c.decl.background || c.decl['background-color'])
|
|
3978
5204
|
return {
|
|
@@ -4094,13 +5320,15 @@ export function draftAnswer(ctx, env, question) {
|
|
|
4094
5320
|
options: [],
|
|
4095
5321
|
};
|
|
4096
5322
|
if (/\bswap\b/.test(t)) {
|
|
4097
|
-
const ROLE_TOKEN =
|
|
4098
|
-
|
|
4099
|
-
|
|
4100
|
-
|
|
4101
|
-
|
|
4102
|
-
|
|
4103
|
-
|
|
5323
|
+
const ROLE_TOKEN = wordTable(
|
|
5324
|
+
/** @type {Record<string, string>} */ ({
|
|
5325
|
+
accent: '--color-accent',
|
|
5326
|
+
danger: '--color-error',
|
|
5327
|
+
success: '--color-success',
|
|
5328
|
+
warning: '--color-warning',
|
|
5329
|
+
info: '--color-info',
|
|
5330
|
+
}),
|
|
5331
|
+
);
|
|
4104
5332
|
const named = Object.keys(ROLE_TOKEN).filter(r =>
|
|
4105
5333
|
new RegExp(`\\b${r === 'danger' ? '(danger|error)' : r}\\b`).test(t),
|
|
4106
5334
|
);
|
|
@@ -4178,6 +5406,9 @@ export function draftAnswer(ctx, env, question) {
|
|
|
4178
5406
|
// "dark only" with no "mode" word describes the theme's look.
|
|
4179
5407
|
(/\balways dark\b|\b(theme|app)\b/.test(t) ||
|
|
4180
5408
|
!/\bmode\b|\bin dark\b/.test(t) ||
|
|
5409
|
+
// "… accent and dark mode only": the last ask, scoping nothing.
|
|
5410
|
+
(clauses.indexOf(c) === clauses.length - 1 &&
|
|
5411
|
+
!/\b(in|for)\b/.test(c.text)) ||
|
|
4181
5412
|
!clauses.some(
|
|
4182
5413
|
o =>
|
|
4183
5414
|
o.text !== c.text &&
|
|
@@ -4189,7 +5420,17 @@ export function draftAnswer(ctx, env, question) {
|
|
|
4189
5420
|
options: [[set('mode', 'dark-only')]],
|
|
4190
5421
|
};
|
|
4191
5422
|
if (
|
|
4192
|
-
/\blight[- ]?(mode|theme)? only\b|\bonly light\b|\blight-only\b/.test(
|
|
5423
|
+
/\blight[- ]?(mode|theme)? only\b|\bonly light\b|\blight-only\b/.test(
|
|
5424
|
+
t,
|
|
5425
|
+
) &&
|
|
5426
|
+
// "light only" removes dark mode only when the ask is about the
|
|
5427
|
+
// theme's modes, never beside another change.
|
|
5428
|
+
(/\b(theme|app)\b/.test(t) ||
|
|
5429
|
+
!clauses.some(
|
|
5430
|
+
o =>
|
|
5431
|
+
o.text !== c.text &&
|
|
5432
|
+
(o.parts.length || o.colors.length || o.aspects.length),
|
|
5433
|
+
))
|
|
4193
5434
|
)
|
|
4194
5435
|
return {
|
|
4195
5436
|
text: 'a theme with only a light mode: mode light-only',
|
|
@@ -4220,10 +5461,14 @@ export function draftAnswer(ctx, env, question) {
|
|
|
4220
5461
|
}
|
|
4221
5462
|
if (vib) {
|
|
4222
5463
|
seenAspect('colors');
|
|
5464
|
+
// "More" goes with the word after it: more washed out, more muted
|
|
5465
|
+
// and more pastel are less vibrant; less muted is more.
|
|
5466
|
+
const dim =
|
|
5467
|
+
/\b(desaturat\w*|muted|dull|washed|pastel|gr[ae]yer|calm\w*|softer)\b/;
|
|
4223
5468
|
const less =
|
|
4224
|
-
/\
|
|
4225
|
-
|
|
4226
|
-
|
|
5469
|
+
/\bless (desaturat\w*|muted|dull|washed|pastel|gr[ae]y\w*)\b/.test(t)
|
|
5470
|
+
? false
|
|
5471
|
+
: dim.test(t) || (/\bless\b/.test(t) && !/\bmore\b/.test(t));
|
|
4227
5472
|
const step = set('vibrancy', less ? 'less' : 'more');
|
|
4228
5473
|
const colored = (/** @type {string} */ v) => !isGraySeed(seedOf(v));
|
|
4229
5474
|
const hasColor = env.data.settings.some(
|
|
@@ -4441,12 +5686,14 @@ export function draftAnswer(ctx, env, question) {
|
|
|
4441
5686
|
? '#78716c'
|
|
4442
5687
|
: null;
|
|
4443
5688
|
// "make the error red darker": the hue names the color; the change is darker.
|
|
4444
|
-
const NATURAL =
|
|
4445
|
-
|
|
4446
|
-
|
|
4447
|
-
|
|
4448
|
-
|
|
4449
|
-
|
|
5689
|
+
const NATURAL = wordTable(
|
|
5690
|
+
/** @type {Record<string, string>} */ ({
|
|
5691
|
+
danger: HUES.red,
|
|
5692
|
+
success: HUES.green,
|
|
5693
|
+
warning: HUES.yellow,
|
|
5694
|
+
info: HUES.blue,
|
|
5695
|
+
}),
|
|
5696
|
+
);
|
|
4450
5697
|
if (c.dir && color && (color === NATURAL[dial] || color === HUES.amber))
|
|
4451
5698
|
color = null;
|
|
4452
5699
|
if (!color && c.dir && !/\btoo (warm|cool)\b/.test(t)) {
|
|
@@ -4533,7 +5780,18 @@ export function draftAnswer(ctx, env, question) {
|
|
|
4533
5780
|
})[a] ?? a;
|
|
4534
5781
|
if (!C.MAP[one(on)] || !Object.hasOwn(GROUPS, group)) return '';
|
|
4535
5782
|
// Reads that always apply first; partReads sorts them so.
|
|
5783
|
+
// Only the reads of the property the aspect is about (a weight question
|
|
5784
|
+
// never lists the size tokens).
|
|
5785
|
+
const prop = /** @type {Record<string, RegExp>} */ ({
|
|
5786
|
+
weight: /^font-weight$/,
|
|
5787
|
+
family: /^font-family$/,
|
|
5788
|
+
fontsize: /^font-size$/,
|
|
5789
|
+
tracking: /^letter-spacing$/,
|
|
5790
|
+
case: /^text-transform$/,
|
|
5791
|
+
italic: /^font-style$/,
|
|
5792
|
+
})[a];
|
|
4536
5793
|
const toks = C.partReads(one(on), group)
|
|
5794
|
+
.filter(r => !prop || r.props.some(x => prop.test(x)))
|
|
4537
5795
|
.map(r => r.token)
|
|
4538
5796
|
.slice(0, 4);
|
|
4539
5797
|
return toks.length ? `; ${one(on)} reads ${toks.join(', ')} for it` : '';
|
|
@@ -4606,6 +5864,23 @@ export function draftAnswer(ctx, env, question) {
|
|
|
4606
5864
|
});
|
|
4607
5865
|
}
|
|
4608
5866
|
result.push(...drafts.slice(0, clashes.length ? 0 : undefined));
|
|
5867
|
+
// A confidence gate: a question, a "tell me", a "but not too" or a typo
|
|
5868
|
+
// read as a direction leaves how unsure which way to go; a wrong write is
|
|
5869
|
+
// worse than none, so it gives the lookup and asks for the ask.
|
|
5870
|
+
const unsure = gateAll;
|
|
5871
|
+
if (unsure && result.some(d => d.options.some(o => o.length))) {
|
|
5872
|
+
const part = partsSeen[0];
|
|
5873
|
+
result.splice(0, result.length, {
|
|
5874
|
+
text: `how is not sure which change you want; say it as an ask instead (for example "rounder cards" or "no shadows on buttons")`,
|
|
5875
|
+
options: [],
|
|
5876
|
+
lookup: part ? `${HOW} ${part}` : `${P} show ${env.slug}`,
|
|
5877
|
+
});
|
|
5878
|
+
}
|
|
5879
|
+
if (media)
|
|
5880
|
+
result.push({
|
|
5881
|
+
text: 'the theme editor has no screen-size, print or device conditions: this applies on every screen; a media query needs your own CSS',
|
|
5882
|
+
options: [],
|
|
5883
|
+
});
|
|
4609
5884
|
return {parts: partsSeen, aspects: aspectsSeen, drafts: result};
|
|
4610
5885
|
}
|
|
4611
5886
|
|