@astryxdesign/cli 0.7.15 → 0.7.16-canary.g9b5ad42
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 +5 -3
- package/api/doctor/_adapter.d.mts +17 -0
- package/api/doctor/_adapter.mjs +35 -0
- package/api/doctor/doctor.mjs +18 -4
- package/api/integration/validate-integration.mjs +1 -1
- package/api/theme/_adapter.d.mts +5 -2
- package/api/theme/_adapter.mjs +43 -12
- package/api/theme/build/build.d.mts +1 -21
- package/api/theme/build/build.mjs +149 -37
- package/api/theme/eject/eject.mjs +22 -1
- package/api/theme/template/template.d.mts +2 -0
- package/api/theme/template/template.mjs +41 -12
- package/api/theme/theme.type.d.mts +4 -0
- package/api/theme/theme.type.mjs +2 -1
- package/api/theme/themeBuild.doc.mjs +3 -3
- package/api/theme/themeEject.doc.mjs +1 -1
- package/api/theme/themeTemplate.doc.mjs +9 -3
- package/api/theme-edit/_adapter.d.mts +10 -0
- package/api/theme-edit/_adapter.mjs +76 -5
- package/api/theme-edit/_check.mjs +181 -50
- package/api/theme-edit/_color.d.mts +2 -8
- package/api/theme-edit/_color.mjs +126 -55
- package/api/theme-edit/_compiler.d.mts +1 -0
- package/api/theme-edit/_compiler.mjs +3 -0
- package/api/theme-edit/_context.d.mts +7 -0
- package/api/theme-edit/_context.mjs +34 -1
- package/api/theme-edit/_css.d.mts +21 -1
- package/api/theme-edit/_css.mjs +172 -13
- package/api/theme-edit/_edit.d.mts +9 -0
- package/api/theme-edit/_edit.mjs +377 -48
- package/api/theme-edit/_how-commands.d.mts +7 -26
- package/api/theme-edit/_how-commands.mjs +27 -1
- package/api/theme-edit/_how-question.mjs +330 -12
- package/api/theme-edit/_how.mjs +68 -26
- package/api/theme-edit/_palette.mjs +10 -0
- package/api/theme-edit/_parts.d.mts +16 -0
- package/api/theme-edit/_parts.mjs +49 -1
- package/api/theme-edit/_preview-app.mjs +176 -9
- package/api/theme-edit/_preview.mjs +7 -3
- package/api/theme-edit/_project.d.mts +11 -0
- package/api/theme-edit/_project.mjs +35 -9
- package/api/theme-edit/_settings.d.mts +46 -5
- package/api/theme-edit/_settings.mjs +217 -25
- package/api/theme-edit/theme-edit.type.d.mts +2 -1
- package/api/theme-edit/theme-edit.type.mjs +1 -1
- package/api/theme-edit/themeEditNew.doc.mjs +1 -1
- package/api/theme-edit/themeEditShow.doc.mjs +1 -1
- 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/self-audit.generated.json +1 -1
- 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/clients/cli/build-id.generated.json +1 -1
- package/clients/cli/commands/doctor.doc.mjs +2 -2
- package/clients/cli/commands/experimental/theme.mjs +113 -34
- package/clients/cli/commands/experimental-theme-compile.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +1 -1
- 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-template.doc.mjs +1 -1
- 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.mjs +85 -5
- package/clients/cli/manifest.generated.json +1 -1
- package/foundation/config/project.mjs +50 -14
- package/foundation/fs/gather-cache.d.mts +9 -2
- package/foundation/fs/gather-cache.mjs +36 -10
- package/foundation/fs/paths.d.mts +16 -0
- package/foundation/fs/paths.mjs +25 -0
- 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/response-types.doc.mjs +1 -1
- package/package.json +7 -6
|
@@ -1,32 +1,6 @@
|
|
|
1
1
|
// @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
|
|
2
2
|
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
* One change a command makes.
|
|
6
|
-
* @typedef {object} Step
|
|
7
|
-
* @property {'set' | 'undo'} verb
|
|
8
|
-
* @property {string} thing
|
|
9
|
-
* @property {string} [value]
|
|
10
|
-
* @property {string} [on]
|
|
11
|
-
* @property {string} [when]
|
|
12
|
-
* @property {string} [state]
|
|
13
|
-
* @property {string} [mode]
|
|
14
|
-
*/
|
|
15
|
-
/**
|
|
16
|
-
* The theme the commands of one answer are for, and the checks they pass.
|
|
17
|
-
* @typedef {object} HowTheme
|
|
18
|
-
* @property {string} slug
|
|
19
|
-
* @property {boolean} exists - false when the app has no theme: the commands name {@link EXAMPLE_THEME} and the answer starts with `new`.
|
|
20
|
-
* @property {string | null} previewDamage - why the in-app preview's record is damaged and how to fix it, or null.
|
|
21
|
-
* @property {string[]} themes - Every theme the editor made in the app.
|
|
22
|
-
* @property {string | null} note - Which theme the commands are for when the app has several, or that it has none.
|
|
23
|
-
* @property {'named' | 'only' | 'last-changed' | 'none'} chosenBy - How the theme was picked.
|
|
24
|
-
* @property {number} undoSteps - How many changes `undo` can step back.
|
|
25
|
-
* @property {boolean} bodyFontReachesHeadings - Whether `font X --on body` also changes the heading font in this release.
|
|
26
|
-
* @property {import('./_settings.mjs').ThemeData} data
|
|
27
|
-
* @property {{light: Record<string, string>, dark: Record<string, string>}} base
|
|
28
|
-
* @property {(steps: Step[]) => {ok: true} | {ok: false, why: string}} check
|
|
29
|
-
*/
|
|
30
4
|
/**
|
|
31
5
|
* The theme an answer's commands are for: the one named, the only one, or
|
|
32
6
|
* the one changed last; with none, a theme the answer first makes.
|
|
@@ -113,6 +87,13 @@ export type HowTheme = {
|
|
|
113
87
|
light: Record<string, string>;
|
|
114
88
|
dark: Record<string, string>;
|
|
115
89
|
};
|
|
90
|
+
/**
|
|
91
|
+
* - The theme's own values: the base's with its settings applied.
|
|
92
|
+
*/
|
|
93
|
+
own?: {
|
|
94
|
+
light: Record<string, string>;
|
|
95
|
+
dark: Record<string, string>;
|
|
96
|
+
} | undefined;
|
|
116
97
|
check: (steps: Step[]) => {
|
|
117
98
|
ok: true;
|
|
118
99
|
} | {
|
|
@@ -51,9 +51,32 @@ export const EXAMPLE_THEME = 'my-theme';
|
|
|
51
51
|
* @property {boolean} bodyFontReachesHeadings - Whether `font X --on body` also changes the heading font in this release.
|
|
52
52
|
* @property {import('./_settings.mjs').ThemeData} data
|
|
53
53
|
* @property {{light: Record<string, string>, dark: Record<string, string>}} base
|
|
54
|
+
* @property {{light: Record<string, string>, dark: Record<string, string>}} [own] - The theme's own values: the base's with its settings applied.
|
|
54
55
|
* @property {(steps: Step[]) => {ok: true} | {ok: false, why: string}} check
|
|
55
56
|
*/
|
|
56
57
|
|
|
58
|
+
/**
|
|
59
|
+
* The theme's own token values in each mode: the base theme's, with the
|
|
60
|
+
* theme's settings applied (a whole-theme corners setting, an exact
|
|
61
|
+
* token), as `compile` builds them.
|
|
62
|
+
* @param {any} compiled
|
|
63
|
+
* @param {{light: Record<string, string>, dark: Record<string, string>}} base
|
|
64
|
+
* @returns {{light: Record<string, string>, dark: Record<string, string>}}
|
|
65
|
+
*/
|
|
66
|
+
function ownTokens(compiled, base) {
|
|
67
|
+
const out = {light: {...base.light}, dark: {...base.dark}};
|
|
68
|
+
for (const [k, v] of Object.entries(compiled?.tokens ?? {})) {
|
|
69
|
+
const pair = Array.isArray(v)
|
|
70
|
+
? v
|
|
71
|
+
: v && typeof v === 'object'
|
|
72
|
+
? [/** @type {any} */ (v).light, /** @type {any} */ (v).dark]
|
|
73
|
+
: [v, v];
|
|
74
|
+
if (typeof pair[0] === 'string') out.light[k] = pair[0];
|
|
75
|
+
if (typeof pair[1] === 'string') out.dark[k] = pair[1];
|
|
76
|
+
}
|
|
77
|
+
return out;
|
|
78
|
+
}
|
|
79
|
+
|
|
57
80
|
/**
|
|
58
81
|
* The theme an answer's commands are for: the one named, the only one, or
|
|
59
82
|
* the one changed last; with none, a theme the answer first makes.
|
|
@@ -155,6 +178,7 @@ export async function howTheme(ctx, cwd, name) {
|
|
|
155
178
|
: 'last-changed',
|
|
156
179
|
data: theme,
|
|
157
180
|
base,
|
|
181
|
+
own: ownTokens(compileTheme(ctx, theme, base), base),
|
|
158
182
|
undoSteps: exists
|
|
159
183
|
? readHistory(themeFiles(cwd, slug).history).steps.length
|
|
160
184
|
: 0,
|
|
@@ -162,8 +186,10 @@ export async function howTheme(ctx, cwd, name) {
|
|
|
162
186
|
check(steps) {
|
|
163
187
|
/** @type {import('./_settings.mjs').ThemeData} */
|
|
164
188
|
const d = JSON.parse(JSON.stringify(theme));
|
|
189
|
+
// The checks set runs read the base theme's values (the corner rungs).
|
|
190
|
+
const checkCtx = /** @type {any} */ ({...ctx, base});
|
|
165
191
|
try {
|
|
166
|
-
for (const st of steps) apply(
|
|
192
|
+
for (const st of steps) apply(checkCtx, slug, d, st);
|
|
167
193
|
if (compiled(d) === before)
|
|
168
194
|
return {
|
|
169
195
|
ok: false,
|
|
@@ -59,6 +59,7 @@ const TRANSLATE = /** @type {Array<[RegExp, string]>} */ (
|
|
|
59
59
|
'圆|丸く|丸い|둥글게|둥근',
|
|
60
60
|
'rounded',
|
|
61
61
|
],
|
|
62
|
+
['cuadrad[oa]s|carrés|eckige', '四角|方形|네모', 'square'],
|
|
62
63
|
['esquinas?|coins|ecken|углы', '角', 'corners'],
|
|
63
64
|
[
|
|
64
65
|
'sombras?|ombres?|ombra|ombre|schatten|тен[ьи]|ظل',
|
|
@@ -155,6 +156,12 @@ const SHORT = /** @type {Record<string, string>} */ ({
|
|
|
155
156
|
|
|
156
157
|
/** Plain words that are never corrected, though one letter off a VOCAB word. */
|
|
157
158
|
const KEEP = new Set([
|
|
159
|
+
'selection',
|
|
160
|
+
'placeholder',
|
|
161
|
+
'cursor',
|
|
162
|
+
'tablets',
|
|
163
|
+
'mobile',
|
|
164
|
+
'printing',
|
|
158
165
|
'lines',
|
|
159
166
|
'block',
|
|
160
167
|
'blocks',
|
|
@@ -689,7 +696,18 @@ function partLexicon(ctx) {
|
|
|
689
696
|
.flatMap(key => [key, `${key}s`]),
|
|
690
697
|
]),
|
|
691
698
|
];
|
|
692
|
-
const lex = {
|
|
699
|
+
const lex = {
|
|
700
|
+
parts: [
|
|
701
|
+
...OVERRIDES,
|
|
702
|
+
...derived,
|
|
703
|
+
// "smaller labels on form fields": a field's label.
|
|
704
|
+
/** @type {[RegExp, PartRef]} */ ([
|
|
705
|
+
/(?<!\b(?:button|tab|badge|chip|nav|menu|link|checkbox|switch|radio)s? )\b(field |form |input )?labels?\b/,
|
|
706
|
+
{on: 'field-label'},
|
|
707
|
+
]),
|
|
708
|
+
],
|
|
709
|
+
vocab,
|
|
710
|
+
};
|
|
693
711
|
lexicons.set(project, lex);
|
|
694
712
|
return lex;
|
|
695
713
|
}
|
|
@@ -716,6 +734,7 @@ const STATE_WORDS = /** @type {Array<[RegExp, string]>} */ ([
|
|
|
716
734
|
[/\b(after i check|once checked|i check)\b/, 'checked'],
|
|
717
735
|
[/\b(picked|chosen|choose|pick)\b/, 'selected'],
|
|
718
736
|
[/\b(invalid|errors? state|has an error|with an error)\b/, 'invalid'],
|
|
737
|
+
[/\bvisited\b/, 'visited'],
|
|
719
738
|
// Words for states a part may not have: the answer says so.
|
|
720
739
|
[/\bread-?only\b/, 'readonly'],
|
|
721
740
|
[
|
|
@@ -796,6 +815,10 @@ function aspectsOf(text) {
|
|
|
796
815
|
if (/\bitalics?\b/.test(c)) add('italic');
|
|
797
816
|
if (
|
|
798
817
|
/\b(bold(er)?|unbold\w*|weight|heav(y|ier)|semibold)\b/.test(c) ||
|
|
818
|
+
// "body 16px regular": a weight word after a size.
|
|
819
|
+
/\b\d+(\.\d+)?(px|rem|em|pt) (regular|normal|medium)\b|\b(body|text|headings?) (regular|normal)$/.test(
|
|
820
|
+
c,
|
|
821
|
+
) ||
|
|
799
822
|
/\bthin(ner)? (body |button |heading |label )?(font|text|type|letters|headings?|labels?|copy)\b/.test(
|
|
800
823
|
c,
|
|
801
824
|
) ||
|
|
@@ -822,7 +845,7 @@ function aspectsOf(text) {
|
|
|
822
845
|
(/\b(bigger|larger|smaller)\b/.test(c) &&
|
|
823
846
|
/\b(text|font|headings?|titles?|h[1-6]|body)\b/.test(c)) ||
|
|
824
847
|
/\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(
|
|
848
|
+
/\b(text|font|body|headings?|titles?|labels?|h[1-6])\s+\d+(\.\d+)?(px|rem|em|pt)\b/.test(
|
|
826
849
|
c,
|
|
827
850
|
) ||
|
|
828
851
|
/\b(text|font|type)( is)? (way |far |much )?too (small|tiny|big|large)\b|\btoo (small|tiny) to read\b/.test(
|
|
@@ -985,7 +1008,7 @@ function clausesOf(q, partWords) {
|
|
|
985
1008
|
/\?/.test(text));
|
|
986
1009
|
const neg =
|
|
987
1010
|
!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(
|
|
1011
|
+
/\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
1012
|
negText
|
|
990
1013
|
.replace(/\bdisabled\b/g, ' ')
|
|
991
1014
|
// "not round enough" asks for more; "not so much" for less.
|
|
@@ -1403,10 +1426,37 @@ export function draftAnswer(ctx, env, question) {
|
|
|
1403
1426
|
const TARGET = ctx.project.target;
|
|
1404
1427
|
const TOKENS = ctx.project.core.tokenDefaults;
|
|
1405
1428
|
const lex = partLexicon(ctx);
|
|
1429
|
+
// "corners NaNpx": not a number; never a guess. After a CSS property the
|
|
1430
|
+
// property's own check says why.
|
|
1431
|
+
const notNumber = /\b(nan|-?infinity)(px|rem|em|%)?(?![a-z])/i.exec(question);
|
|
1432
|
+
const afterProperty = notNumber
|
|
1433
|
+
? cssProperties().has(
|
|
1434
|
+
(
|
|
1435
|
+
/([a-z-]+)\s*:?\s*$/i.exec(question.slice(0, notNumber.index))?.[1] ??
|
|
1436
|
+
''
|
|
1437
|
+
).toLowerCase(),
|
|
1438
|
+
)
|
|
1439
|
+
: false;
|
|
1440
|
+
if (notNumber && !afterProperty)
|
|
1441
|
+
return {
|
|
1442
|
+
parts: [],
|
|
1443
|
+
aspects: [],
|
|
1444
|
+
drafts: [
|
|
1445
|
+
{
|
|
1446
|
+
text: `${notNumber[0]} is not a number a theme can use; give a number, like 8px`,
|
|
1447
|
+
options: [],
|
|
1448
|
+
},
|
|
1449
|
+
],
|
|
1450
|
+
};
|
|
1406
1451
|
/** Family names written in quotes, kept as typed: qq<n>qq in the text. */
|
|
1407
1452
|
const quoted = /** @type {string[]} */ ([]);
|
|
1408
1453
|
let q = question
|
|
1409
1454
|
.normalize('NFKC')
|
|
1455
|
+
// ".btn-primary { … }": the primary button.
|
|
1456
|
+
.replace(
|
|
1457
|
+
/\.btn-(primary|secondary|ghost|destructive|danger)\b/g,
|
|
1458
|
+
(_, v) => `${v === 'danger' ? 'destructive' : v} button `,
|
|
1459
|
+
)
|
|
1410
1460
|
// Markup and comment text are not part of the ask.
|
|
1411
1461
|
.replace(/<(script|style)\b[^>]*>[\s\S]*?<\/\1\s*>/gi, ' ')
|
|
1412
1462
|
.replace(/<\/?[a-z][^>]*>/gi, ' ')
|
|
@@ -1471,6 +1521,15 @@ export function draftAnswer(ctx, env, question) {
|
|
|
1471
1521
|
.replace(/\b(?:no|not) more than\s+|\bat most\s+|\bmax(?:imum)? of\s+/g, '')
|
|
1472
1522
|
// Numbers written as words are numbers.
|
|
1473
1523
|
.replace(NUMBER_WORDS_RE, m => numberWord(m))
|
|
1524
|
+
// "less black", "not so white": a direction away from that color.
|
|
1525
|
+
.replace(
|
|
1526
|
+
/\b(?:slightly |a bit |a little )?(?:less|not so|not as) (black|dark)\b/g,
|
|
1527
|
+
'lighter',
|
|
1528
|
+
)
|
|
1529
|
+
.replace(
|
|
1530
|
+
/\b(?:slightly |a bit |a little )?(?:less|not so|not as) (white|bright)\b/g,
|
|
1531
|
+
'dimmer',
|
|
1532
|
+
)
|
|
1474
1533
|
// "8 or so px", "about 8 px": the number.
|
|
1475
1534
|
.replace(/\b(\d+(?:\.\d+)?)\s+or so\s+(?=px|rem|em|pixels?)/g, '$1 ')
|
|
1476
1535
|
// "0.5 rem", "14 px": a number and its unit are one length.
|
|
@@ -1591,6 +1650,22 @@ export function draftAnswer(ctx, env, question) {
|
|
|
1591
1650
|
/,?\s*\bbut not\s+(?=(bold|italic|uppercase|rounded|round|shadowed|underlined|bordered|faded|dark|light|bright|big|small|too \w+)\b)/g,
|
|
1592
1651
|
' not ',
|
|
1593
1652
|
)
|
|
1653
|
+
// Tailwind classes: "border-2" is 2px, "rounded-full" a pill.
|
|
1654
|
+
.replace(/\bborder-(\d)\b/g, 'border width $1px')
|
|
1655
|
+
.replace(/\brounded-full\b/g, 'pill corners')
|
|
1656
|
+
.replace(/\brounded-none\b/g, 'square corners')
|
|
1657
|
+
// "1e3px" is 1000px.
|
|
1658
|
+
.replace(
|
|
1659
|
+
/\b(\d+(?:\.\d+)?)e([+-]?\d+)(px|rem|em)\b/gi,
|
|
1660
|
+
(_, n, e, u) => `${Number(n) * 10 ** Number(e)}${u}`,
|
|
1661
|
+
)
|
|
1662
|
+
// "not so round", "not that dark": one step less, not the opposite.
|
|
1663
|
+
.replace(
|
|
1664
|
+
/\bnot (?:so|that|as|too) (round(?:ed)?|bold|dark|big|bright|spacious|thick)\b/g,
|
|
1665
|
+
'less $1',
|
|
1666
|
+
)
|
|
1667
|
+
// "flat cards, not flat buttons": the second part stays as it is.
|
|
1668
|
+
.replace(/^(.*\b(\w{3,})\b.*?),\s*(?:but )?not \2 [a-z ]+$/, '$1')
|
|
1594
1669
|
.replace(/\b(everything|everywhere|all) but\b/g, '$1 except')
|
|
1595
1670
|
.replace(
|
|
1596
1671
|
/\b(apart from|other than|excluding|but not (on|in|for)|but not)\b/g,
|
|
@@ -1598,7 +1673,64 @@ export function draftAnswer(ctx, env, question) {
|
|
|
1598
1673
|
)
|
|
1599
1674
|
.replace(/\s+/g, ' ')
|
|
1600
1675
|
.trim();
|
|
1676
|
+
// "cramped on mobile": the editor has no media conditions; the rest of
|
|
1677
|
+
// the ask is answered, with a note.
|
|
1678
|
+
const MEDIA_RE = new RegExp(
|
|
1679
|
+
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`,
|
|
1680
|
+
'g',
|
|
1681
|
+
);
|
|
1682
|
+
const media = MEDIA_RE.test(q);
|
|
1683
|
+
if (media) q = q.replace(MEDIA_RE, ' ').replace(/\s+/g, ' ').trim();
|
|
1601
1684
|
const clauses = clausesOf(q, lex.parts);
|
|
1685
|
+
// "labels on form fields": the label, not the field it sits on.
|
|
1686
|
+
for (const c of clauses)
|
|
1687
|
+
if (c.parts.some(p => p.on === 'field-label')) {
|
|
1688
|
+
// A checkbox's or switch's own label part, when Core has one.
|
|
1689
|
+
const own = c.parts
|
|
1690
|
+
.map(p => ({
|
|
1691
|
+
on:
|
|
1692
|
+
/** @type {Record<string, string>} */ ({
|
|
1693
|
+
checks: 'checkbox-label',
|
|
1694
|
+
checkbox: 'checkbox-label',
|
|
1695
|
+
switch: 'switch-label',
|
|
1696
|
+
})[p.on] ?? p.on,
|
|
1697
|
+
}))
|
|
1698
|
+
.filter(
|
|
1699
|
+
p =>
|
|
1700
|
+
/-label$/.test(p.on) && p.on !== 'field-label' && TARGET.has(p.on),
|
|
1701
|
+
);
|
|
1702
|
+
// "button labels": the label is the button's own text.
|
|
1703
|
+
const owner = c.parts.filter(
|
|
1704
|
+
p =>
|
|
1705
|
+
p.on !== 'field-label' &&
|
|
1706
|
+
![
|
|
1707
|
+
'inputs',
|
|
1708
|
+
'field',
|
|
1709
|
+
'checks',
|
|
1710
|
+
'checkbox',
|
|
1711
|
+
'switch',
|
|
1712
|
+
'text-input',
|
|
1713
|
+
].includes(p.on),
|
|
1714
|
+
);
|
|
1715
|
+
c.parts = own.length
|
|
1716
|
+
? own
|
|
1717
|
+
: owner.length
|
|
1718
|
+
? owner
|
|
1719
|
+
: c.parts.filter(p => p.on === 'field-label');
|
|
1720
|
+
}
|
|
1721
|
+
// "captions 12px": a clause led by a plural noun that names no part and
|
|
1722
|
+
// no change takes nothing from its neighbors.
|
|
1723
|
+
const unknownLead = (/** @type {Clause} */ c) => {
|
|
1724
|
+
const lead = /^(?:the |my |our |all )?([a-z]{4,}s)\b/.exec(c.text)?.[1];
|
|
1725
|
+
return Boolean(
|
|
1726
|
+
lead &&
|
|
1727
|
+
!c.parts.length &&
|
|
1728
|
+
!lex.vocab.includes(lead) &&
|
|
1729
|
+
!lex.vocab.includes(singular(lead)) &&
|
|
1730
|
+
!aspectsOf(lead).length &&
|
|
1731
|
+
!KEEP.has(lead),
|
|
1732
|
+
);
|
|
1733
|
+
};
|
|
1602
1734
|
for (const c of clauses) {
|
|
1603
1735
|
c.quoted = [...c.text.matchAll(/qq(\d+)qq/g)].map(
|
|
1604
1736
|
m => quoted[Number(m[1])],
|
|
@@ -1974,6 +2106,7 @@ export function draftAnswer(ctx, env, question) {
|
|
|
1974
2106
|
!(ROLE_WORDS.test(c.text) && !c.aspects.length) &&
|
|
1975
2107
|
// "Circular font" after "12px cards" is the theme's font.
|
|
1976
2108
|
!(c.aspects.length && c.aspects.every(a => a === 'family')) &&
|
|
2109
|
+
!unknownLead(c) &&
|
|
1977
2110
|
// "serif headings, no shadows": a type part does not take a shadow,
|
|
1978
2111
|
// corner or border ask.
|
|
1979
2112
|
!(
|
|
@@ -1991,6 +2124,7 @@ export function draftAnswer(ctx, env, question) {
|
|
|
1991
2124
|
if (
|
|
1992
2125
|
!c.aspects.length &&
|
|
1993
2126
|
!ROLE_WORDS.test(c.text) &&
|
|
2127
|
+
!unknownLead(c) &&
|
|
1994
2128
|
(c.lengths.length || /\b(stay|keep)\b/.test(c.text))
|
|
1995
2129
|
) {
|
|
1996
2130
|
const from = prev?.aspects.length
|
|
@@ -1998,7 +2132,12 @@ export function draftAnswer(ctx, env, question) {
|
|
|
1998
2132
|
: next?.aspects.length
|
|
1999
2133
|
? next
|
|
2000
2134
|
: null;
|
|
2001
|
-
|
|
2135
|
+
// Only the aspects a length can set: "headings 32px bold, captions
|
|
2136
|
+
// 12px" gives captions a size, not the headings' bold.
|
|
2137
|
+
if (from)
|
|
2138
|
+
c.aspects = from.aspects.filter(
|
|
2139
|
+
a => !['weight', 'italic', 'case', 'family'].includes(a),
|
|
2140
|
+
);
|
|
2002
2141
|
}
|
|
2003
2142
|
// "in dark mode, cards are #1c1c1e": a clause that only names the mode
|
|
2004
2143
|
// gives it to the clauses after it.
|
|
@@ -2034,12 +2173,28 @@ export function draftAnswer(ctx, env, question) {
|
|
|
2034
2173
|
c.parts = [];
|
|
2035
2174
|
c.text = '';
|
|
2036
2175
|
}
|
|
2176
|
+
// "the same accent in light and dark": every mode, so no mode.
|
|
2177
|
+
if (
|
|
2178
|
+
/\b(light and dark|dark and light|both modes|every mode|all modes|same in (both|light and dark))\b/.test(
|
|
2179
|
+
q,
|
|
2180
|
+
)
|
|
2181
|
+
)
|
|
2182
|
+
for (const c of clauses) c.mode = null;
|
|
2037
2183
|
// "only in dark mode, …": a clause that only names a mode scopes every
|
|
2038
2184
|
// clause after it.
|
|
2039
2185
|
for (let i = 0; i < clauses.length; i++) {
|
|
2040
2186
|
const c = clauses[i];
|
|
2041
|
-
if (c.mode && !c.parts.length && !c.aspects.length && !c.colors.length)
|
|
2042
|
-
|
|
2187
|
+
if (c.mode && !c.parts.length && !c.aspects.length && !c.colors.length) {
|
|
2188
|
+
// "don't touch dark mode, …": the other mode.
|
|
2189
|
+
const scope = c.neg ? (c.mode === 'dark' ? 'light' : 'dark') : c.mode;
|
|
2190
|
+
for (const o of c.neg ? clauses : clauses.slice(i + 1))
|
|
2191
|
+
if (o !== c) o.mode ??= scope;
|
|
2192
|
+
if (c.neg) {
|
|
2193
|
+
for (const o of clauses)
|
|
2194
|
+
if (o !== c && o.mode === c.mode) o.mode = scope;
|
|
2195
|
+
c.text = '';
|
|
2196
|
+
}
|
|
2197
|
+
}
|
|
2043
2198
|
}
|
|
2044
2199
|
// The tab's text is on the tab, not on its underline.
|
|
2045
2200
|
for (const c of clauses)
|
|
@@ -2067,8 +2222,11 @@ export function draftAnswer(ctx, env, question) {
|
|
|
2067
2222
|
if (!aspectsSeen.includes(a)) aspectsSeen.push(a);
|
|
2068
2223
|
};
|
|
2069
2224
|
/** @param {string} token @param {'light' | 'dark'} [mode] */
|
|
2225
|
+
// The theme's own value (its settings applied), else the base theme's.
|
|
2070
2226
|
const current = (token, mode = 'light') =>
|
|
2071
|
-
env.
|
|
2227
|
+
env.own?.[mode]?.[token] ??
|
|
2228
|
+
env.base[mode]?.[token] ??
|
|
2229
|
+
String(TOKENS[token] ?? '');
|
|
2072
2230
|
/** The member a group's checks read. @param {string} on */
|
|
2073
2231
|
const one = on => (FAMILIES[on] ? FAMILIES[on][0] : on);
|
|
2074
2232
|
/**
|
|
@@ -2399,6 +2557,146 @@ export function draftAnswer(ctx, env, question) {
|
|
|
2399
2557
|
continue;
|
|
2400
2558
|
}
|
|
2401
2559
|
}
|
|
2560
|
+
// "decrease the radius by 2px", "add 8px to the padding": a change from
|
|
2561
|
+
// the value now, never the new value itself.
|
|
2562
|
+
// "2px rounder", "8px larger", "4px wider": a change too.
|
|
2563
|
+
const COMPARATIVE =
|
|
2564
|
+
'more|less|bigger|smaller|rounder|sharper|squarer|larger|wider|narrower|taller|shorter|thicker|thinner|higher|lower';
|
|
2565
|
+
const delta = new RegExp(
|
|
2566
|
+
`\\b(?:by|add(?:ing)?|plus|minus|subtract(?:ing)?)\\s+(\\d*\\.?\\d+)px\\b|\\b(\\d*\\.?\\d+)px (?:${COMPARATIVE})\\b`,
|
|
2567
|
+
).exec(c.text);
|
|
2568
|
+
if (
|
|
2569
|
+
delta &&
|
|
2570
|
+
new RegExp(
|
|
2571
|
+
`\\b(by|add|adding|plus|minus|subtract|subtracting|increase|decrease|reduce|${COMPARATIVE})\\b`,
|
|
2572
|
+
).test(c.text)
|
|
2573
|
+
) {
|
|
2574
|
+
const n = Number(delta[1] ?? delta[2]);
|
|
2575
|
+
const down =
|
|
2576
|
+
/\b(decrease|reduce|less|smaller|minus|subtract|subtracting|lower|shrink|sharper|squarer|narrower|shorter|thinner)\b/.test(
|
|
2577
|
+
c.text,
|
|
2578
|
+
);
|
|
2579
|
+
const cornerAsk =
|
|
2580
|
+
c.aspects.includes('corners') ||
|
|
2581
|
+
/\b(rounder|sharper|squarer)\b/.test(c.text);
|
|
2582
|
+
// A part's corners: its radius token, moved by the amount.
|
|
2583
|
+
if (cornerAsk && c.parts.length) {
|
|
2584
|
+
const on = c.parts[0].on;
|
|
2585
|
+
const read = C.partReads(one(on), 'corners')[0];
|
|
2586
|
+
if (read) {
|
|
2587
|
+
const d = {
|
|
2588
|
+
text: `${on}'s corners ${down ? 'down' : 'up'} by ${n}px: ${read.token} ${down ? '-' : '+'} ${n}px`,
|
|
2589
|
+
options: [
|
|
2590
|
+
[
|
|
2591
|
+
set(
|
|
2592
|
+
'border-radius',
|
|
2593
|
+
`max(0px, calc(var(${read.token}) ${down ? '-' : '+'} ${n}px))`,
|
|
2594
|
+
{on},
|
|
2595
|
+
),
|
|
2596
|
+
],
|
|
2597
|
+
],
|
|
2598
|
+
};
|
|
2599
|
+
push(d);
|
|
2600
|
+
recordTop(c, d.options[0] ?? []);
|
|
2601
|
+
continue;
|
|
2602
|
+
}
|
|
2603
|
+
}
|
|
2604
|
+
if (cornerAsk && !c.parts.length) {
|
|
2605
|
+
const now = parseFloat(current('--radius-element'));
|
|
2606
|
+
const nowPx = /rem$/.test(current('--radius-element')) ? now * 16 : now;
|
|
2607
|
+
const next = Math.max(
|
|
2608
|
+
0,
|
|
2609
|
+
Math.round((nowPx + (down ? -n : n)) * 100) / 100,
|
|
2610
|
+
);
|
|
2611
|
+
const d = {
|
|
2612
|
+
text: `corners ${down ? 'down' : 'up'} by ${n}px: from ${Math.round(nowPx * 100) / 100}px to ${next}px`,
|
|
2613
|
+
options: [[set('corners', `${next}px`)]],
|
|
2614
|
+
};
|
|
2615
|
+
push(d);
|
|
2616
|
+
recordTop(c, d.options[0] ?? []);
|
|
2617
|
+
continue;
|
|
2618
|
+
}
|
|
2619
|
+
push({
|
|
2620
|
+
text: `set takes the new value, not a change by ${n}px; look up what it is now, then set the sum`,
|
|
2621
|
+
options: [],
|
|
2622
|
+
lookup: c.parts[0]
|
|
2623
|
+
? `${HOW} ${c.parts[0].on}`
|
|
2624
|
+
: `${P} show ${env.slug}`,
|
|
2625
|
+
});
|
|
2626
|
+
continue;
|
|
2627
|
+
}
|
|
2628
|
+
// "all corners like the buttons": every other radius token takes the
|
|
2629
|
+
// one the named part reads.
|
|
2630
|
+
if (
|
|
2631
|
+
c.parts.length === 1 &&
|
|
2632
|
+
c.aspects.includes('corners') &&
|
|
2633
|
+
/\b(all|every|other|everything|everywhere)\b/.test(c.text) &&
|
|
2634
|
+
/\b(like|match(es|ing)?|same as)\b/.test(c.text)
|
|
2635
|
+
) {
|
|
2636
|
+
const source = c.parts[0].on;
|
|
2637
|
+
const read = C.partReads(one(source), 'corners')[0];
|
|
2638
|
+
if (read) {
|
|
2639
|
+
const others = Object.keys(TOKENS).filter(
|
|
2640
|
+
t =>
|
|
2641
|
+
/^--radius-/.test(t) &&
|
|
2642
|
+
t !== read.token &&
|
|
2643
|
+
!/^--radius-(none|full)$/.test(t),
|
|
2644
|
+
);
|
|
2645
|
+
const d = {
|
|
2646
|
+
text: `every corner like ${source}'s: the other radius tokens take ${read.token}, which ${source} reads`,
|
|
2647
|
+
options: [others.map(t => set(t, `var(${read.token})`))],
|
|
2648
|
+
sequence: others.length > 1,
|
|
2649
|
+
};
|
|
2650
|
+
push(d);
|
|
2651
|
+
recordTop(c, d.options[0] ?? []);
|
|
2652
|
+
continue;
|
|
2653
|
+
}
|
|
2654
|
+
}
|
|
2655
|
+
// "outline offset 3px on focus": the focus ring's offset, not a border.
|
|
2656
|
+
if (
|
|
2657
|
+
!c.parts.length &&
|
|
2658
|
+
/\boutline[- ]offset\b/.test(c.text) &&
|
|
2659
|
+
c.lengths[0]
|
|
2660
|
+
) {
|
|
2661
|
+
const d = {
|
|
2662
|
+
text: "the focus ring's offset: --focus-outline-offset",
|
|
2663
|
+
options: [[set('--focus-outline-offset', c.lengths[0])]],
|
|
2664
|
+
};
|
|
2665
|
+
push(d);
|
|
2666
|
+
recordTop(c, d.options[0] ?? []);
|
|
2667
|
+
continue;
|
|
2668
|
+
}
|
|
2669
|
+
// Placeholder, caret and selection colors.
|
|
2670
|
+
if (
|
|
2671
|
+
/\b(placeholders?|caret|cursor colou?r|colou?r (of )?the cursor|selection|selected text highlight|text highlight)\b/.test(
|
|
2672
|
+
c.text,
|
|
2673
|
+
) &&
|
|
2674
|
+
!/\bloading placeholder/.test(c.text)
|
|
2675
|
+
) {
|
|
2676
|
+
const color = colorFor(c, 'fill');
|
|
2677
|
+
const caret =
|
|
2678
|
+
/\bcaret\b|\bcursor colou?r\b|\bcolou?r (of )?the cursor\b/.test(
|
|
2679
|
+
c.text,
|
|
2680
|
+
);
|
|
2681
|
+
if (caret && color) {
|
|
2682
|
+
const on = c.parts[0]?.on ?? 'inputs';
|
|
2683
|
+
const d = {
|
|
2684
|
+
text: `the text cursor color on ${on}: caret-color`,
|
|
2685
|
+
options: [[set('caret-color', color, {on})]],
|
|
2686
|
+
};
|
|
2687
|
+
push(d);
|
|
2688
|
+
recordTop(c, d.options[0] ?? []);
|
|
2689
|
+
continue;
|
|
2690
|
+
}
|
|
2691
|
+
push({
|
|
2692
|
+
text: caret
|
|
2693
|
+
? 'name the cursor color: caret-color takes a color'
|
|
2694
|
+
: `${/\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`,
|
|
2695
|
+
options: [],
|
|
2696
|
+
lookup: `${HOW} inputs`,
|
|
2697
|
+
});
|
|
2698
|
+
continue;
|
|
2699
|
+
}
|
|
2402
2700
|
// "… and set --border-width 2px": a real token typed in a clause.
|
|
2403
2701
|
// The value runs to the clause end ("--shadow-high 0 4px 12px black").
|
|
2404
2702
|
const tok = /(?:^|\s)(--[a-z][a-z0-9-]*)\s*:?\s+([^;]+?)\s*$/.exec(c.text);
|
|
@@ -2421,10 +2719,7 @@ export function draftAnswer(ctx, env, question) {
|
|
|
2421
2719
|
}
|
|
2422
2720
|
// "error text red", "labels smaller": text that belongs to parts how
|
|
2423
2721
|
// 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
|
-
) {
|
|
2722
|
+
if (!c.parts.length && /\berror (text|messages?)\b/.test(c.text)) {
|
|
2428
2723
|
const which = /\berror\b/.test(c.text) ? 'error text' : 'labels';
|
|
2429
2724
|
push({
|
|
2430
2725
|
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 +2840,7 @@ export function draftAnswer(ctx, env, question) {
|
|
|
2545
2840
|
function resetAnswer(c) {
|
|
2546
2841
|
// "go back to the neutral theme", "start over": every setting.
|
|
2547
2842
|
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(
|
|
2843
|
+
/\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
2844
|
c.text,
|
|
2550
2845
|
)
|
|
2551
2846
|
) {
|
|
@@ -2751,6 +3046,21 @@ export function draftAnswer(ctx, env, question) {
|
|
|
2751
3046
|
],
|
|
2752
3047
|
sequence: true,
|
|
2753
3048
|
};
|
|
3049
|
+
// "remove the focus outline": a ring keyboard users need; set it to
|
|
3050
|
+
// nothing only on the ask, and say what that costs.
|
|
3051
|
+
if (c.neg || /\b(remove|hide|get rid of)\b/.test(c.text))
|
|
3052
|
+
return {
|
|
3053
|
+
text: 'no focus ring: --focus-outline-width 0px. Keyboard users then cannot see where they are, so keep a visible focus style another way',
|
|
3054
|
+
options: [[set('--focus-outline-width', '0px')]],
|
|
3055
|
+
};
|
|
3056
|
+
// "focus ring offset 2px": the gap between the part and its ring.
|
|
3057
|
+
if (/\boffset\b/.test(c.text))
|
|
3058
|
+
return c.lengths[0]
|
|
3059
|
+
? {
|
|
3060
|
+
text: "the focus ring's offset: --focus-outline-offset",
|
|
3061
|
+
options: [[set('--focus-outline-offset', c.lengths[0])]],
|
|
3062
|
+
}
|
|
3063
|
+
: null;
|
|
2754
3064
|
if (
|
|
2755
3065
|
(a === 'border' && !ringColor) ||
|
|
2756
3066
|
a === 'size' ||
|
|
@@ -4178,6 +4488,9 @@ export function draftAnswer(ctx, env, question) {
|
|
|
4178
4488
|
// "dark only" with no "mode" word describes the theme's look.
|
|
4179
4489
|
(/\balways dark\b|\b(theme|app)\b/.test(t) ||
|
|
4180
4490
|
!/\bmode\b|\bin dark\b/.test(t) ||
|
|
4491
|
+
// "… accent and dark mode only": the last ask, scoping nothing.
|
|
4492
|
+
(clauses.indexOf(c) === clauses.length - 1 &&
|
|
4493
|
+
!/\b(in|for)\b/.test(c.text)) ||
|
|
4181
4494
|
!clauses.some(
|
|
4182
4495
|
o =>
|
|
4183
4496
|
o.text !== c.text &&
|
|
@@ -4606,6 +4919,11 @@ export function draftAnswer(ctx, env, question) {
|
|
|
4606
4919
|
});
|
|
4607
4920
|
}
|
|
4608
4921
|
result.push(...drafts.slice(0, clashes.length ? 0 : undefined));
|
|
4922
|
+
if (media)
|
|
4923
|
+
result.push({
|
|
4924
|
+
text: 'the theme editor has no screen-size, print or device conditions: this applies on every screen; a media query needs your own CSS',
|
|
4925
|
+
options: [],
|
|
4926
|
+
});
|
|
4609
4927
|
return {parts: partsSeen, aspects: aspectsSeen, drafts: result};
|
|
4610
4928
|
}
|
|
4611
4929
|
|