@astryxdesign/cli 0.7.14 → 0.7.15-canary.g061b2fa
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 +63 -63
- package/api/build/_adapter.d.mts +4 -0
- package/api/build/_adapter.mjs +28 -2
- package/api/build/blocks/blocks.d.mts +10 -1
- package/api/build/blocks/blocks.mjs +84 -7
- package/api/build/build.mjs +6 -1
- package/api/build/tree.d.mts +4 -0
- package/api/build/tree.mjs +9 -2
- package/api/doctor/_adapter.d.mts +3 -1
- package/api/doctor/_adapter.mjs +14 -1
- package/api/doctor/_authoring-audit.d.mts +42 -0
- package/api/doctor/_authoring-audit.mjs +106 -0
- package/api/doctor/doctor.d.mts +7 -0
- package/api/doctor/doctor.mjs +24 -39
- package/api/doctor/theme-checks.mjs +56 -21
- package/api/integration/validate-integration.mjs +17 -3
- package/api/integration/validateIntegration.doc.mjs +1 -1
- package/api/search/_adapter.mjs +124 -3
- package/api/search/_candidate-score.mjs +63 -9
- package/api/search/_entries.d.mts +10 -0
- package/api/search/_entries.mjs +68 -1
- package/api/search/_gather-templates.d.mts +11 -0
- package/api/search/_gather-templates.mjs +22 -2
- package/api/search/_words.mjs +26 -6
- package/api/swizzle/copy/copy.mjs +1 -1
- package/api/theme/_adapter.d.mts +17 -1
- package/api/theme/_adapter.mjs +185 -40
- package/api/theme/build/build.d.mts +29 -1
- package/api/theme/build/build.mjs +426 -65
- package/api/theme/eject/eject.mjs +10 -6
- package/api/theme/targets/targets.d.mts +8 -0
- package/api/theme/targets/targets.mjs +24 -4
- package/api/theme/template/template.mjs +48 -2
- package/api/theme/theme.type.d.mts +8 -0
- package/api/theme/theme.type.mjs +5 -1
- package/api/theme/themeBuild.doc.mjs +7 -4
- package/api/theme/themeEject.doc.mjs +3 -3
- package/api/theme/themeRemove.doc.mjs +5 -2
- package/api/theme/themeTargets.doc.mjs +1 -1
- package/api/theme/themeTemplate.doc.mjs +2 -2
- package/api/theme/themeUse.doc.mjs +8 -2
- package/api/theme-edit/_adapter.d.mts +46 -3
- package/api/theme-edit/_adapter.mjs +372 -109
- package/api/theme-edit/_check.d.mts +6 -3
- package/api/theme-edit/_check.mjs +665 -87
- package/api/theme-edit/_color.mjs +4 -2
- package/api/theme-edit/_compiler.d.mts +2 -1
- package/api/theme-edit/_compiler.mjs +27 -13
- package/api/theme-edit/_context.d.mts +2 -1
- package/api/theme-edit/_context.mjs +47 -8
- package/api/theme-edit/_edit.d.mts +9 -3
- package/api/theme-edit/_edit.mjs +484 -66
- package/api/theme-edit/_how-commands.d.mts +33 -7
- package/api/theme-edit/_how-commands.mjs +57 -45
- package/api/theme-edit/_how-question.d.mts +4 -0
- package/api/theme-edit/_how-question.mjs +1004 -223
- package/api/theme-edit/_how.mjs +96 -9
- package/api/theme-edit/_palette.d.mts +38 -13
- package/api/theme-edit/_palette.mjs +620 -223
- package/api/theme-edit/_parts.mjs +63 -7
- package/api/theme-edit/_png.d.mts +4 -4
- package/api/theme-edit/_png.mjs +4 -2
- package/api/theme-edit/_preview-app.d.mts +6 -0
- package/api/theme-edit/_preview-app.mjs +1194 -207
- package/api/theme-edit/_preview.mjs +2 -2
- package/api/theme-edit/_project.d.mts +12 -1
- package/api/theme-edit/_project.mjs +37 -6
- package/api/theme-edit/_settings.d.mts +104 -33
- package/api/theme-edit/_settings.mjs +818 -118
- package/api/theme-edit/_tables.d.mts +7 -0
- package/api/theme-edit/_tables.mjs +61 -0
- package/api/theme-edit/theme-edit.type.d.mts +11 -1
- package/api/theme-edit/theme-edit.type.mjs +4 -3
- package/api/theme-edit/themeEditHow.doc.mjs +6 -0
- package/api/theme-edit/themeEditPreviewAdd.doc.mjs +1 -1
- package/api/theme-edit/themeEditPreviewApp.doc.mjs +1 -1
- package/api/theme-edit/themeEditPreviewList.doc.mjs +1 -1
- package/api/theme-edit/themeEditPreviewRemove.doc.mjs +5 -1
- package/api/theme-edit/themeEditUndo.doc.mjs +1 -1
- package/api/upgrade/_adapter.d.mts +1 -0
- package/assets/codemods/run-codemod.mjs +61 -0
- package/assets/codemods/runner.mjs +5 -4
- package/assets/codemods/transforms/v0.0.14/rename-status-variants.mjs +3 -0
- package/assets/codemods/transforms/v0.1.8/rename-avatar-size-scale.mjs +5 -1
- package/assets/codemods/transforms/v0.6.4/migrate-native-picker-to-presentation.mjs +3 -0
- package/assets/codemods/transforms/v0.7.0/migrate-deprecated-theme-surface.mjs +4 -0
- package/assets/codemods/transforms/v0.7.0/rename-empty-search-results-text.mjs +17 -12
- package/assets/codemods/transforms/v0.7.2/migrate-list-edge-compensation-to-edge.mjs +3 -0
- package/assets/codemods/transforms/v0.7.5/migrate-codeblock-tokenizer-to-language.mjs +3 -0
- package/assets/codemods/transforms/v0.7.8/promote-tokenizer-presentation.mjs +3 -0
- package/assets/docs/tree/calendars.doc.mjs +1 -3
- package/assets/docs/tree/checks.doc.mjs +22 -1
- package/assets/docs.generated.json +2 -1
- package/assets/self-audit.generated.json +1 -0
- package/assets/templates/blocks/components/Theme/useThemeNameHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Theme/useThemeNameHookUsage.tsx +31 -0
- package/assets/templates/components.generated.json +1 -1
- package/authoring/integration/integration.doc.mjs +8 -0
- package/authoring/integration/schema.d.mts +8 -0
- package/authoring/integration/schema.mjs +1 -0
- package/authoring/integration/type.ts +9 -0
- package/clients/cli/bin/astryx.mjs +19 -15
- package/clients/cli/build-id.generated.json +1 -0
- package/clients/cli/commands/ensure-core-built.mjs +12 -5
- package/clients/cli/commands/experimental/theme.mjs +178 -78
- package/clients/cli/commands/experimental-theme-compile.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +1 -2
- package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-eject.doc.mjs +3 -3
- package/clients/cli/commands/experimental-theme-preview-add.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-preview-list.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-preview-remove.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-remove.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-template.doc.mjs +4 -3
- package/clients/cli/commands/manifest.mjs +5 -2
- package/clients/cli/commands/theme-build.doc.mjs +1 -1
- package/clients/cli/commands/theme-list.doc.mjs +1 -1
- package/clients/cli/commands/theme-template.doc.mjs +1 -1
- package/clients/cli/commands/theme.mjs +374 -42
- package/clients/cli/index.mjs +9 -3
- package/clients/cli/lib/manifest.mjs +37 -0
- package/clients/cli/lib/resolve-theme.mjs +2 -1
- package/clients/cli/manifest.generated.json +1 -0
- package/foundation/config/theme-state.d.mts +16 -0
- package/foundation/config/theme-state.mjs +84 -13
- package/foundation/discovery/module-exports.mjs +16 -2
- package/foundation/discovery/stored-self-audit.d.mts +31 -0
- package/foundation/discovery/stored-self-audit.mjs +119 -0
- package/foundation/discovery/template-adapter.d.mts +48 -2
- package/foundation/discovery/template-adapter.mjs +51 -19
- package/foundation/discovery/template-needs.d.mts +19 -0
- package/foundation/discovery/template-needs.mjs +50 -16
- package/foundation/discovery/template-source-tree.d.mts +7 -0
- package/foundation/discovery/template-source-tree.mjs +15 -0
- package/foundation/discovery/theme-discovery.d.mts +2 -1
- package/foundation/discovery/theme-discovery.mjs +2 -8
- package/foundation/discovery/theme-module-extensions.d.mts +18 -0
- package/foundation/discovery/theme-module-extensions.mjs +30 -0
- package/foundation/doc-compiler/import.mjs +22 -15
- package/foundation/doc-compiler/stored-docs.d.mts +18 -12
- package/foundation/doc-compiler/stored-docs.mjs +52 -19
- package/foundation/env/private-dir.d.mts +17 -0
- package/foundation/env/private-dir.mjs +42 -0
- package/foundation/fs/gather-cache.d.mts +108 -0
- package/foundation/fs/gather-cache.mjs +741 -0
- package/foundation/fs/jiti-cache.d.mts +21 -0
- package/foundation/fs/jiti-cache.mjs +66 -0
- package/foundation/fs/module-loader.mjs +14 -3
- package/foundation/fs/read-record.d.mts +31 -1
- package/foundation/fs/read-record.mjs +100 -7
- package/foundation/integrations/integrations.d.mts +8 -0
- package/foundation/integrations/integrations.mjs +4 -0
- package/foundation/integrations/validate-contributions.d.mts +62 -1
- package/foundation/integrations/validate-contributions.mjs +476 -40
- package/foundation/release/cache.d.mts +11 -2
- package/foundation/release/cache.mjs +59 -10
- package/foundation/release/folder-lock.d.mts +21 -0
- package/foundation/release/folder-lock.mjs +171 -0
- package/foundation/response/response-types.doc.mjs +1 -1
- package/package.json +8 -6
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* @position api/theme-edit — imported only by _how.mjs
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
import {hex, parseColor} from './_color.mjs';
|
|
12
|
+
import {hex, parseColor, ratio} from './_color.mjs';
|
|
13
13
|
import {
|
|
14
14
|
DESIGN,
|
|
15
15
|
DIALS,
|
|
@@ -40,19 +40,33 @@ import {COLOR_PROPS} from './_tables.mjs';
|
|
|
40
40
|
const TRANSLATE = /** @type {Array<[RegExp, string]>} */ (
|
|
41
41
|
[
|
|
42
42
|
[
|
|
43
|
-
'botones?|boutons?|knöpfe|knopf|кнопк[аиу]|botões|botão|botao|pulsanti|bottoni',
|
|
43
|
+
'botones?|boutons?|knöpfe|knopf|кнопк[аиу]|botões|botão|botao|pulsanti|bottoni|الأزرار|أزرار|زر|बटन',
|
|
44
44
|
'按钮|ボタン|버튼',
|
|
45
45
|
'buttons',
|
|
46
46
|
],
|
|
47
|
-
['tarjetas?|cartes|karten?|карточк[аи]', '卡片|カード', 'cards'],
|
|
48
47
|
[
|
|
49
|
-
'
|
|
48
|
+
'tarjetas?|cartes|karten?|карточк[аи]|schede|carte',
|
|
49
|
+
'卡片|カード|카드',
|
|
50
|
+
'cards',
|
|
51
|
+
],
|
|
52
|
+
[
|
|
53
|
+
'redondead[oa]s?|redond[oa]s|arrondi[es]*|abgerundet\\p{L}*|скругл\\p{L}*|arredondad\\p{L}*|arrotondat\\p{L}*|مستدير\\p{L}*|गोल',
|
|
50
54
|
'圆|丸く|丸い|둥글게|둥근',
|
|
51
55
|
'rounded',
|
|
52
56
|
],
|
|
53
57
|
['esquinas?|coins|ecken|углы', '角', 'corners'],
|
|
54
|
-
[
|
|
55
|
-
|
|
58
|
+
[
|
|
59
|
+
'sombras?|ombres?|ombra|ombre|schatten|тен[ьи]|ظل',
|
|
60
|
+
'阴影|影|그림자',
|
|
61
|
+
'shadow',
|
|
62
|
+
],
|
|
63
|
+
[
|
|
64
|
+
'entfernen|quitar|enlever|supprimer|убрать|togliere|rimuovere|remover|हटाओ',
|
|
65
|
+
'去掉|删除|消して|없애',
|
|
66
|
+
'remove',
|
|
67
|
+
],
|
|
68
|
+
['цвет\\p{L}*|colore|farbe', '颜色|色', 'color'],
|
|
69
|
+
['акцент\\p{L}*', '强调', 'accent'],
|
|
56
70
|
['más|mais|mehr|più|более', '更', 'more'],
|
|
57
71
|
// "sans" is a typeface word before serif or font.
|
|
58
72
|
[
|
|
@@ -427,7 +441,11 @@ const boxIn = c =>
|
|
|
427
441
|
function shadowIn(c) {
|
|
428
442
|
const one =
|
|
429
443
|
'(?:inset\\s+)?-?\\d*\\.?\\d+(?:px)?\\s+-?\\d*\\.?\\d+(?:px)?(?:\\s+-?\\d*\\.?\\d+(?:px)?){0,2}\\s+(?:#[0-9a-f]{3,8}|(?:rgba?|hsla?|oklch)\\([^)]*\\)|[a-z]+)';
|
|
430
|
-
return
|
|
444
|
+
return (
|
|
445
|
+
new RegExp(`${one}(?:\\s*[,\u2e34]\\s*${one})*`)
|
|
446
|
+
.exec(c)?.[0]
|
|
447
|
+
.replace(/\u2e34/g, ',') ?? null
|
|
448
|
+
);
|
|
431
449
|
}
|
|
432
450
|
|
|
433
451
|
/** A length tied to a height word ("40px tall", "height 40px"). @param {string} c */
|
|
@@ -439,7 +457,7 @@ const tallIn = c =>
|
|
|
439
457
|
|
|
440
458
|
/** A length tied to a radius word ("8px radius", "radius: 8px"). @param {string} c */
|
|
441
459
|
const radiusIn = c =>
|
|
442
|
-
/(-?\d*\.?\d+(?:px|rem|em)?)\s*(?:radius|corners?)\b|\b(?:radius|corners?|rounded)\s*:?\s*(?:to\s+)?(-?\d*\.?\d+(?:px|rem|em)?)
|
|
460
|
+
/(-?\d*\.?\d+(?:px|rem|em|%)?)\s*(?:border[\s-]+)?(?:radius|corners?)\b|\b(?:radius|corners?|rounded)\s*(?:values?\s+)?(?:are|is|of|at)?\s*:?\s*(?:to\s+)?(?:about\s+|around\s+)?(-?\d*\.?\d+(?:px|rem|em|%)?)(?:\b|(?<=%))/
|
|
443
461
|
.exec(c)
|
|
444
462
|
?.slice(1)
|
|
445
463
|
.find(Boolean) ?? null;
|
|
@@ -523,7 +541,11 @@ const PARTS = [
|
|
|
523
541
|
/\b((side ?nav|sidebar)( nav(igation)?)? (links?|items?))\b/,
|
|
524
542
|
{on: 'side-nav-item'},
|
|
525
543
|
],
|
|
526
|
-
[
|
|
544
|
+
[
|
|
545
|
+
/\b((dropdown |context )?menu (items?|options?|entries)|dropdown items?)\b/,
|
|
546
|
+
{on: 'dropdown-menu-item'},
|
|
547
|
+
],
|
|
548
|
+
[/\b(nav(igation)? (links?|items?))\b/, {on: 'top-nav-item'}],
|
|
527
549
|
[/\b(side ?nav|sidebar|side ?panel)\b/, {on: 'side-nav'}],
|
|
528
550
|
[
|
|
529
551
|
/\b(app (name|title)|logo|site title|product name)\b/,
|
|
@@ -534,6 +556,7 @@ const PARTS = [
|
|
|
534
556
|
{on: 'app-shell-header'},
|
|
535
557
|
],
|
|
536
558
|
[/\b(page|app background|whole background|body background)\b/, {on: 'page'}],
|
|
559
|
+
[/\b(radio( buttons?)?|radios)\b/, {on: 'radio-indicator'}],
|
|
537
560
|
[/\b(primary|main) buttons?\b/, {on: 'button', when: 'variant:primary'}],
|
|
538
561
|
[/\bsecondary buttons?\b/, {on: 'button', when: 'variant:secondary'}],
|
|
539
562
|
[/\bghost buttons?\b/, {on: 'button', when: 'variant:ghost'}],
|
|
@@ -545,12 +568,23 @@ const PARTS = [
|
|
|
545
568
|
[/\bcards?\b/, {on: 'card'}],
|
|
546
569
|
[/\b(panels?|windows?|boxes|tiles?|containers?)\b/, {on: 'containers'}],
|
|
547
570
|
[/\b(banners?|alerts?|notices?|announcements?)\b/, {on: 'banner'}],
|
|
571
|
+
[/\b(text ?areas?|multi-?line (inputs?|fields?))\b/, {on: 'text-area'}],
|
|
572
|
+
[
|
|
573
|
+
/\b(select (dropdowns?|menus?|box(es)?|inputs?)|selects|dropdowns?|pickers?)\b/,
|
|
574
|
+
{on: 'selector'},
|
|
575
|
+
],
|
|
576
|
+
[/\b(skeletons?( loaders?)?|loading placeholders?)\b/, {on: 'skeleton'}],
|
|
548
577
|
[
|
|
549
578
|
/\b(inputs?|text ?box(es)?|text ?fields?|form fields?|fields?)\b/,
|
|
550
579
|
{on: 'inputs'},
|
|
551
580
|
],
|
|
552
581
|
[/\b(checkbox(es)?|check ?marks?)\b/, {on: 'checks'}],
|
|
553
|
-
|
|
582
|
+
// "switch off", "switch the buttons to" are the verb, not the part.
|
|
583
|
+
[
|
|
584
|
+
/\b(toggles?|switch(es)?(?! (off|on|to|the|out|it|them|over|back|from)\b))\b/,
|
|
585
|
+
{on: 'switch'},
|
|
586
|
+
],
|
|
587
|
+
[/\b((table )?cells?)\b/, {on: 'table-cell'}],
|
|
554
588
|
[/\b(table rows?|rows?|tables?)\b/, {on: 'table-row'}],
|
|
555
589
|
[/\btabs?\b/, {on: 'tab'}],
|
|
556
590
|
[/\b(badges?|chips?|tags?)\b/, {on: 'badge'}],
|
|
@@ -558,6 +592,7 @@ const PARTS = [
|
|
|
558
592
|
[/\b(headings?|titles?)\b/, {on: 'heading'}],
|
|
559
593
|
[/\b(dialogs?|modals?|popups?)\b/, {on: 'dialog'}],
|
|
560
594
|
[/\btooltips?\b/, {on: 'tooltip'}],
|
|
595
|
+
[/\bpopovers?\b/, {on: 'popover'}],
|
|
561
596
|
[/\btoasts?\b/, {on: 'toast'}],
|
|
562
597
|
[/\bavatars?\b/, {on: 'avatar'}],
|
|
563
598
|
[/\blinks?\b/, {on: 'link'}],
|
|
@@ -598,6 +633,7 @@ const STATE_WORDS = /** @type {Array<[RegExp, string]>} */ ([
|
|
|
598
633
|
* @property {'light' | 'dark' | null} mode
|
|
599
634
|
* @property {boolean} except - "but not on X": X keeps what the clause before does
|
|
600
635
|
* @property {Record<string, string>} decl - CSS written as `prop: value`
|
|
636
|
+
* @property {string[]} [quoted] - family names the clause writes in quotes
|
|
601
637
|
*/
|
|
602
638
|
|
|
603
639
|
/**
|
|
@@ -617,8 +653,9 @@ function aspectsOf(text) {
|
|
|
617
653
|
};
|
|
618
654
|
if (/\b(letter ?spacing|tracking|kerning)\b/.test(c)) add('tracking');
|
|
619
655
|
if (
|
|
620
|
-
/\b(round(ed|er|ness|ing)?|unround\w*|corners?|radius|radii|curv\w*|circular|circles?|pill( shaped)?|sharp(er)?|square(d|r)?)\b/.test(
|
|
621
|
-
|
|
656
|
+
/\b(round(ed|er|ness|ing)?|unround\w*|corners?|radius|radii|curv\w*|circular(?! (font|typeface))|circles?|pill( shaped)?|sharp(er)?|square(d|r)?)\b/.test(
|
|
657
|
+
// "Feedback round 2" is not a corner.
|
|
658
|
+
c.replace(/\bround \d+\b/g, ' '),
|
|
622
659
|
)
|
|
623
660
|
)
|
|
624
661
|
add('corners');
|
|
@@ -629,7 +666,9 @@ function aspectsOf(text) {
|
|
|
629
666
|
)
|
|
630
667
|
add('shadow');
|
|
631
668
|
if (
|
|
632
|
-
/\b(borders?(
|
|
669
|
+
/\b(borders?(?![\s-]*radius)|outlines?|strokes?|edges?|frames?|rings?)\b/.test(
|
|
670
|
+
c,
|
|
671
|
+
)
|
|
633
672
|
)
|
|
634
673
|
add('border');
|
|
635
674
|
if (/\bunderlined?\b|\bunderlines\b/.test(c) && !/\btabs?\b/.test(c))
|
|
@@ -656,7 +695,9 @@ function aspectsOf(text) {
|
|
|
656
695
|
)
|
|
657
696
|
add('weight');
|
|
658
697
|
if (
|
|
659
|
-
/\b(fonts?|typefaces?|serif|sans(-serif)?|mono(space|spaced)?)\b/.test(
|
|
698
|
+
/\b(fonts?|typefaces?|serif|sans(-serif)?|sanz|mono(space|spaced)?)\b/.test(
|
|
699
|
+
c,
|
|
700
|
+
) &&
|
|
660
701
|
!/\bfont ?size\b/.test(c) &&
|
|
661
702
|
!/\bfont ?weight\b|\b(bold|heav|light(er)?|thin)\w* fonts?\b|\bfonts? weight/.test(
|
|
662
703
|
c,
|
|
@@ -670,11 +711,15 @@ function aspectsOf(text) {
|
|
|
670
711
|
) ||
|
|
671
712
|
(/\b(bigger|larger|smaller)\b/.test(c) &&
|
|
672
713
|
/\b(text|font|headings?|titles?|h[1-6]|body)\b/.test(c)) ||
|
|
673
|
-
/\b\d+(px|rem) (text|font|labels?|type)\b/.test(c)
|
|
714
|
+
/\b\d+(px|rem) (text|font|labels?|type)\b/.test(c) ||
|
|
715
|
+
/\b(text|font|type)( is)? (way |far |much )?too (small|tiny|big|large)\b|\btoo (small|tiny) to read\b/.test(
|
|
716
|
+
c,
|
|
717
|
+
) ||
|
|
718
|
+
/\bbody (text|copy|font)\s+\d+(\.\d+)?(px|rem)\b/.test(c)
|
|
674
719
|
)
|
|
675
720
|
add('fontsize');
|
|
676
721
|
if (
|
|
677
|
-
(/\b(taller|shorter|wider|narrower|width|height|bigger|larger|smaller|tall)\b/.test(
|
|
722
|
+
(/\b(taller|shorter|wider|narrower|width|(?<!line )height|bigger|larger|smaller|tall|too (small|tiny|big|large))\b/.test(
|
|
678
723
|
c,
|
|
679
724
|
) ||
|
|
680
725
|
(/\b(thick(er)?|thin(ner)?)\b/.test(c) &&
|
|
@@ -683,19 +728,26 @@ function aspectsOf(text) {
|
|
|
683
728
|
!a.includes('tracking')
|
|
684
729
|
)
|
|
685
730
|
add('size');
|
|
686
|
-
if (
|
|
731
|
+
if (
|
|
732
|
+
!a.includes('family') &&
|
|
733
|
+
new RegExp(`\\b(${FONT_NAMES})\\b`).test(c.replace(/\bsanz\b/g, 'sans'))
|
|
734
|
+
)
|
|
687
735
|
add('family');
|
|
688
736
|
if (!a.length && /\b(thick(er)?|thin(ner)?)\b/.test(c)) add('border');
|
|
689
737
|
if (
|
|
690
738
|
/\b(faded|fade|opacity|see-through|washed out)\b/.test(c) ||
|
|
691
|
-
/\d+%/.test(
|
|
739
|
+
(/\d+%/.test(
|
|
692
740
|
c.replace(/\b(?:rgba?|hsla?|hwb|lab|lch|oklab|oklch)\([^)]*\)/g, ''),
|
|
693
|
-
)
|
|
741
|
+
) &&
|
|
742
|
+
!a.includes('corners'))
|
|
694
743
|
)
|
|
695
744
|
add('opacity');
|
|
696
745
|
if (/\b(scales? (down|up)|shrinks?|grows?)\b/.test(c)) add('scale');
|
|
697
746
|
if (
|
|
698
|
-
/\b(text|writing|words|labels?|font colou?r|readable|links
|
|
747
|
+
(/\b(text|writing|words|labels?|font colou?r|readable|links?|body copy)\b/.test(
|
|
748
|
+
c,
|
|
749
|
+
) ||
|
|
750
|
+
/\b(buttons?|links?) colou?r\b/.test(c)) &&
|
|
699
751
|
!a.some(x =>
|
|
700
752
|
['case', 'italic', 'weight', 'family', 'fontsize', 'tracking'].includes(
|
|
701
753
|
x,
|
|
@@ -727,7 +779,7 @@ function clausesOf(q) {
|
|
|
727
779
|
// "swap X and Y" is one ask.
|
|
728
780
|
const pieces = (/\bswap\b/.test(q) ? q.replace(/\band\b/g, '&') : q)
|
|
729
781
|
.split(
|
|
730
|
-
/;|\.(?=\s|$)|,(?![^(]*\))|\b(?:and|with|but|then|plus|also)\b|\bwhile\b|(?=\bexcept\b)/,
|
|
782
|
+
/;|\.(?=\s|$)|,(?![^(]*\))|\b(?:and|with|but|then|plus|also|y|et|und|и)\b|\bwhile\b|(?=\bexcept\b)/,
|
|
731
783
|
)
|
|
732
784
|
.map(s => s.trim())
|
|
733
785
|
.filter(Boolean);
|
|
@@ -741,6 +793,13 @@ function clausesOf(q) {
|
|
|
741
793
|
if (!m) continue;
|
|
742
794
|
const p = {...part};
|
|
743
795
|
if (p.on === 'heading' && /^h[1-4]$/.test(m[0])) p.level = m[1];
|
|
796
|
+
// "the error banner": one status of the banner.
|
|
797
|
+
const status =
|
|
798
|
+
/\b(error|danger|warning|success|info)\s+(banners?|alerts?|notices?)\b/.exec(
|
|
799
|
+
rest,
|
|
800
|
+
)?.[1];
|
|
801
|
+
if (p.on === 'banner' && status)
|
|
802
|
+
p.when = `status:${status === 'danger' ? 'error' : status}`;
|
|
744
803
|
parts.push(p);
|
|
745
804
|
rest = rest.replace(re, ' ');
|
|
746
805
|
}
|
|
@@ -753,31 +812,40 @@ function clausesOf(q) {
|
|
|
753
812
|
// "orange not red" negates a color, not the change.
|
|
754
813
|
const hue = Object.keys(HUES).join('|');
|
|
755
814
|
const negText = text.replace(
|
|
756
|
-
new RegExp(
|
|
815
|
+
new RegExp(
|
|
816
|
+
`\\b(not|no)\\s+((pure|plain|light|dark|pale|off)[\\s-]+)?(${hue})\\b`,
|
|
817
|
+
'g',
|
|
818
|
+
),
|
|
757
819
|
' ',
|
|
758
820
|
);
|
|
759
821
|
const neg =
|
|
760
|
-
/\b(no|not|don'?t|do not|never|without|remove|removing|get rid of|lose|drop|kill|none|shouldn'?t|should not|mustn'?t|turn off|turn (the|it|them) off|switch off|stop|unbold\w*|unround\w*|disable)\b/.test(
|
|
761
|
-
negText
|
|
822
|
+
/\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(
|
|
823
|
+
negText
|
|
824
|
+
.replace(/\bdisabled\b/g, ' ')
|
|
825
|
+
// "not round enough" asks for more; "not so much" for less.
|
|
826
|
+
.replace(/\bnot (\w+ ){0,2}enough\b/g, ' ')
|
|
827
|
+
.replace(/\bnot (so|as|that|too) (much|many)\b/g, ' '),
|
|
762
828
|
) && !/\bno (wait|longer)\b/.test(negText);
|
|
763
829
|
// "too X" asks for less X: too sharp is rounder, too heavy is lighter.
|
|
764
830
|
const tooLess =
|
|
765
831
|
/\btoo (big|large|round|rounded|bold|heavy|thick|dark|spacious|airy|bright|loud|strong|harsh|much|wide|tall)\b/;
|
|
766
832
|
const tooMore =
|
|
767
833
|
/\btoo (small|cramped|tight|crowded|faded|light|thin|sharp|square|boxy|pointy|subtle|weak|narrow|dim|low|short)\b/;
|
|
768
|
-
const dir =
|
|
769
|
-
? '
|
|
770
|
-
:
|
|
771
|
-
? '
|
|
772
|
-
:
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
? 'less'
|
|
776
|
-
: /\b(more|bigger|larger|higher|increase|stronger|thicker|wider|taller|rounder|roomier|airy|spacious|bolder|heavier|darker|a bit|a little|slightly|much)\b/.test(
|
|
834
|
+
const dir = /\bnot (\w+ ){0,2}enough\b/.test(text)
|
|
835
|
+
? 'more'
|
|
836
|
+
: /\bnot (so|as|that|too) (much|many)\b/.test(text) || tooLess.test(text)
|
|
837
|
+
? 'less'
|
|
838
|
+
: tooMore.test(text)
|
|
839
|
+
? 'more'
|
|
840
|
+
: /\b(less|fewer|smaller|lower|reduce|softer|lighter|thinner|narrower|shorter|tight(er)?|dense(r)?|denser|compact|sharper|squarer|subtler|tone down|dimmer)\b/.test(
|
|
777
841
|
text,
|
|
778
842
|
)
|
|
779
|
-
? '
|
|
780
|
-
:
|
|
843
|
+
? 'less'
|
|
844
|
+
: /\b(more|bigger|larger|higher|increase|stronger|thicker|wider|taller|rounder|roomier|airy|spacious|bolder|heavier|darker|a bit|a little|slightly|much)\b/.test(
|
|
845
|
+
text,
|
|
846
|
+
)
|
|
847
|
+
? 'more'
|
|
848
|
+
: null;
|
|
781
849
|
/** @type {Record<string, string>} */
|
|
782
850
|
const decl = {};
|
|
783
851
|
for (const m of text.matchAll(
|
|
@@ -825,6 +893,25 @@ function clausesOf(q) {
|
|
|
825
893
|
});
|
|
826
894
|
}
|
|
827
895
|
|
|
896
|
+
/**
|
|
897
|
+
* Whether a few words name a color or a font, for "swap A for B".
|
|
898
|
+
* @param {string} words lower-case
|
|
899
|
+
* @returns {'color' | 'font' | undefined}
|
|
900
|
+
*/
|
|
901
|
+
function valueKind(words) {
|
|
902
|
+
const w = words.trim();
|
|
903
|
+
if (parseColor(w) || Object.hasOwn(HUES, w)) return 'color';
|
|
904
|
+
const slug = w.replace(/\s+/g, '-');
|
|
905
|
+
if (
|
|
906
|
+
Object.hasOwn(OPEN_FONTS, slug) ||
|
|
907
|
+
Object.hasOwn(FONTS, slug) ||
|
|
908
|
+
Object.values(OPEN_FONTS).some(f => f.family.toLowerCase() === w) ||
|
|
909
|
+
Object.values(FONTS).some(f => String(f[0]).toLowerCase() === w)
|
|
910
|
+
)
|
|
911
|
+
return 'font';
|
|
912
|
+
return undefined;
|
|
913
|
+
}
|
|
914
|
+
|
|
828
915
|
/**
|
|
829
916
|
* Answer a plain-words question with drafts of commands.
|
|
830
917
|
* @param {import('./_settings.mjs').Ctx} ctx
|
|
@@ -836,20 +923,127 @@ export function draftAnswer(ctx, env, question) {
|
|
|
836
923
|
const {C} = ctx;
|
|
837
924
|
const TARGET = ctx.project.target;
|
|
838
925
|
const TOKENS = ctx.project.core.tokenDefaults;
|
|
926
|
+
/** Family names written in quotes, kept as typed: qq<n>qq in the text. */
|
|
927
|
+
const quoted = /** @type {string[]} */ ([]);
|
|
839
928
|
let q = question
|
|
840
929
|
.normalize('NFKC')
|
|
930
|
+
// Markup and comment text are not part of the ask.
|
|
931
|
+
.replace(/<(script|style)\b[^>]*>[\s\S]*?<\/\1\s*>/gi, ' ')
|
|
932
|
+
.replace(/<\/?[a-z][^>]*>/gi, ' ')
|
|
933
|
+
.replace(/\*\/[\s\S]*?\/\*/g, ' ')
|
|
934
|
+
.replace(/\/\*[\s\S]*?\*\//g, ' ')
|
|
935
|
+
.replace(
|
|
936
|
+
/(?<=\bfont(?:[ -]family)?\s*:?\s*)'((?:[^'\\]|\\.){2,40})'|["\u201c]([^"\u201d\n]{2,40})["\u201d]/gi,
|
|
937
|
+
(m, a, b, off, all) => {
|
|
938
|
+
const name = String(a ?? b)
|
|
939
|
+
.replace(/\\(.)/g, '$1')
|
|
940
|
+
.trim();
|
|
941
|
+
// Only a font name after a font word ("font 'O\'Reilly Sans'",
|
|
942
|
+
// headings use "Playfair Display") is kept as typed; other quoted
|
|
943
|
+
// text is read as words.
|
|
944
|
+
const fontWord =
|
|
945
|
+
a != null ||
|
|
946
|
+
/\b(font(?:[ -]family)?|typeface|family|uses?)\s*:?\s*$/i.test(
|
|
947
|
+
String(all).slice(Math.max(0, off - 30), off),
|
|
948
|
+
) ||
|
|
949
|
+
/^\s*(font|typeface)\b/i.test(String(all).slice(off + m.length));
|
|
950
|
+
if (!fontWord || !/^[A-Za-z][A-Za-z0-9 '.-]{1,38}$/.test(name))
|
|
951
|
+
return m;
|
|
952
|
+
quoted.push(name);
|
|
953
|
+
return ` qq${quoted.length - 1}qq `;
|
|
954
|
+
},
|
|
955
|
+
)
|
|
956
|
+
// Each line of a list is its own ask: a "no" on one line never reaches
|
|
957
|
+
// the next.
|
|
958
|
+
.replace(/^[ \t]*(?:[-*\u2022\u25e6]|\d+[.)])[ \t]+/gm, '')
|
|
959
|
+
.replace(/\s*[\r\n]+\s*/g, ' ; ')
|
|
960
|
+
// "1) square corners 2) no shadows": a marker is a break, never a
|
|
961
|
+
// value. "N)" is a marker anywhere; "N." only at the start or after a
|
|
962
|
+
// break, so "radius 8. Shadows off." keeps its 8.
|
|
963
|
+
.replace(/(^|\s)\d{1,2}\)(?=\s)/g, ' ; ')
|
|
964
|
+
.replace(/(^|;)\s*\d{1,2}\.(?=\s)/g, ' ; ')
|
|
965
|
+
// "primary=#7c3aed radius=10": each key=value pair is its own ask.
|
|
966
|
+
.replace(/\s+(?=[a-z][\w-]*\s*=\s*\S)/gi, ' ; ')
|
|
841
967
|
.replace(/\p{Cc}/gu, ' ')
|
|
842
968
|
// Code-shaped asks: camelCase keys, JSON and CSS punctuation, dotted
|
|
843
969
|
// paths ("primaryColor=#3b82f6", {"accent": ...}, theme.colors.primary).
|
|
970
|
+
// Font names keep their words: "JetBrains" is one word, and the "Sans"
|
|
971
|
+
// of "IBM Plex Sans" is not the French "without".
|
|
972
|
+
.replace(/\bJetBrains\b/g, 'Jetbrains')
|
|
973
|
+
.replace(/(?<=\b[A-Z][\w-]*\s)Sans\b/g, 'Sanz')
|
|
844
974
|
.replace(/([a-z])([A-Z])/g, '$1 $2')
|
|
845
975
|
.replace(/[{}"`]/g, ' ')
|
|
846
976
|
.replace(/(?<=[a-z])\.(?=[a-z])/gi, ' ')
|
|
847
977
|
.replace(/(?<![\w-])\.(?=[a-z])/gi, ' ')
|
|
848
978
|
.replace(/\s*=\s*/g, ' ')
|
|
979
|
+
// Near-white and near-black are their own colors.
|
|
980
|
+
.replace(/\boff[- ]?white\b/gi, '#fafafa')
|
|
981
|
+
.replace(/\boff[- ]?black\b/gi, '#111111')
|
|
982
|
+
// "match the header color to the sidebar": the first part is the one to
|
|
983
|
+
// change.
|
|
984
|
+
.replace(
|
|
985
|
+
/\bmatch\s+(?:the\s+)?(.+?)\s+to\s+(?:the\s+)?[a-z][a-z -]*?(?=\s*[(,;.]|\s*$)/gi,
|
|
986
|
+
'$1',
|
|
987
|
+
)
|
|
988
|
+
// "button padding 8", "radius 10": a bare number there is pixels.
|
|
989
|
+
.replace(
|
|
990
|
+
/\b(padding|radius|corners|gap|margin)(\s*:?\s*)(\d+(?:\.\d+)?)(?![\d.%\w])/gi,
|
|
991
|
+
'$1$2$3px',
|
|
992
|
+
)
|
|
849
993
|
.toLowerCase()
|
|
850
|
-
.replace(/[\u2018\u2019]/g, "'")
|
|
994
|
+
.replace(/[\u2018\u2019]/g, "'")
|
|
995
|
+
// CSS property names read as their words.
|
|
996
|
+
.replace(
|
|
997
|
+
/\b(letter|line|font)-(spacing|height|size|weight|family)\b/g,
|
|
998
|
+
'$1 $2',
|
|
999
|
+
)
|
|
1000
|
+
// "12 pixels", "8 px" are lengths.
|
|
1001
|
+
.replace(/\b(\d+(?:\.\d+)?)\s*(?:pixels?|px)\b/g, '$1px')
|
|
1002
|
+
// A drop shadow is a shadow, not a "drop".
|
|
1003
|
+
.replace(/\bdrop[- ]shadows?\b/g, 'shadow')
|
|
1004
|
+
// "x 0, y 4, blur 6, spread -1, rgba(...)": one shadow value.
|
|
1005
|
+
.replace(
|
|
1006
|
+
/\bx\s*:?\s*(-?\d+)(?:px)?\s*,?\s*y\s*:?\s*(-?\d+)(?:px)?(?:\s*,?\s*blur\s*:?\s*(-?\d+)(?:px)?)?(?:\s*,?\s*spread\s*:?\s*(-?\d+)(?:px)?)?\s*,?\s*(#[0-9a-f]{3,8}|(?:rgba?|hsla?)\([^)]*\))/g,
|
|
1007
|
+
(_, x, y, b, sp, col) =>
|
|
1008
|
+
[x, y, b, sp]
|
|
1009
|
+
.filter(v => v != null)
|
|
1010
|
+
.map(v => (v === '0' ? '0' : `${v}px`))
|
|
1011
|
+
.join(' ') + ` ${col}`,
|
|
1012
|
+
)
|
|
1013
|
+
// A shadow's layers stay one value: the comma between them is not a
|
|
1014
|
+
// clause break.
|
|
1015
|
+
.replace(/\)\s*,\s*(?=(?:inset\s+)?-?\d)/g, ')\u2e34 ')
|
|
1016
|
+
// "replace the shadow on cards with a border": no shadow, and a border.
|
|
1017
|
+
.replace(
|
|
1018
|
+
/\b(?:replace|swap)\s+(?:out\s+)?(?:the\s+)?((?:shadows?|borders?|gradients?|underlines?|outlines?)\b[^,;]*?)\s+(?:with|for)\s+/g,
|
|
1019
|
+
'no $1 ; ',
|
|
1020
|
+
)
|
|
1021
|
+
// "swap Inter for Manrope", "replace red with #e11d48": B is the ask,
|
|
1022
|
+
// but only when A and B are the same kind of value. "Replace the shadow
|
|
1023
|
+
// with a border" keeps both words.
|
|
1024
|
+
.replace(
|
|
1025
|
+
/\b(?:swap|replace|switch)\s+(?:out\s+)?(?:the\s+)?([^,;]+?)\s+(?:for|with)\s+(?=(#[0-9a-f]{3,8}\b|[a-z][\w-]*(?:\s+[a-z][\w-]*)?))/g,
|
|
1026
|
+
(m, a, b) => {
|
|
1027
|
+
const kind = valueKind(a) ?? null;
|
|
1028
|
+
const bKind = valueKind(b) ?? valueKind(b.split(/\s+/)[0]);
|
|
1029
|
+
return kind && kind === bKind ? 'use ' : m;
|
|
1030
|
+
},
|
|
1031
|
+
)
|
|
1032
|
+
// "bg #fff text #000": a new color after a color starts a new ask.
|
|
1033
|
+
.replace(
|
|
1034
|
+
/(#[0-9a-f]{3,8}|\))\s+(?!(?:to|into|and|or|vs|than|then)\b)(?=[a-z][\w-]*\s*:?\s*(?:#[0-9a-f]{3,8}\b|(?:rgba?|hsla?|oklch)\())/g,
|
|
1035
|
+
'$1 ; ',
|
|
1036
|
+
)
|
|
1037
|
+
// "#0d6efd primary": the color belongs to the word after it, when that
|
|
1038
|
+
// word has no color of its own.
|
|
1039
|
+
.replace(
|
|
1040
|
+
/(#[0-9a-f]{3,8}|(?:rgba?|hsla?|oklch)\([^)]*\))\s+(primary|secondary|accent|brand|danger|error|success|warning|info|neutral|bg|background|text|border|links?)\b(?!\s*:?\s*(?:#|rgba?\(|hsla?\(|oklch\())/g,
|
|
1041
|
+
'$2 $1',
|
|
1042
|
+
);
|
|
851
1043
|
for (const [re, w] of TRANSLATE) q = q.replace(re, w);
|
|
852
1044
|
q = q
|
|
1045
|
+
// "bordes redondeados": rounded edges are corners.
|
|
1046
|
+
.replace(/\bborders?\s+rounded\b/g, 'rounded corners')
|
|
853
1047
|
.replace(/\bbutton-s\b/g, 'buttons')
|
|
854
1048
|
.replace(/[a-z]+/g, w => corrected(w))
|
|
855
1049
|
.replace(/\b(everything|everywhere|all) but\b/g, '$1 except')
|
|
@@ -860,6 +1054,129 @@ export function draftAnswer(ctx, env, question) {
|
|
|
860
1054
|
.replace(/\s+/g, ' ')
|
|
861
1055
|
.trim();
|
|
862
1056
|
const clauses = clausesOf(q);
|
|
1057
|
+
for (const c of clauses) {
|
|
1058
|
+
c.quoted = [...c.text.matchAll(/qq(\d+)qq/g)].map(
|
|
1059
|
+
m => quoted[Number(m[1])],
|
|
1060
|
+
);
|
|
1061
|
+
c.text = c.text
|
|
1062
|
+
.replace(/\s*qq\d+qq\s*/g, ' font ')
|
|
1063
|
+
.replace(/\s+/g, ' ')
|
|
1064
|
+
.trim();
|
|
1065
|
+
if (c.quoted.length && !c.aspects.includes('family'))
|
|
1066
|
+
c.aspects.push('family');
|
|
1067
|
+
}
|
|
1068
|
+
// The generic family after a quoted one is its fallback, not a second ask.
|
|
1069
|
+
for (let i = 1; i < clauses.length; i++)
|
|
1070
|
+
if (
|
|
1071
|
+
clauses[i - 1].quoted?.length &&
|
|
1072
|
+
/^(monospace|mono|sans ?-?serif|serif|system-ui|cursive)$/.test(
|
|
1073
|
+
clauses[i].text,
|
|
1074
|
+
)
|
|
1075
|
+
) {
|
|
1076
|
+
clauses[i].text = '';
|
|
1077
|
+
clauses[i].aspects = [];
|
|
1078
|
+
}
|
|
1079
|
+
for (const c of clauses)
|
|
1080
|
+
if (!c.aspects.includes('shadow') && shadowIn(c.text))
|
|
1081
|
+
c.aspects.push('shadow');
|
|
1082
|
+
// "color #000" after a clause about borders is the border's color.
|
|
1083
|
+
for (let i = 1; i < clauses.length; i++) {
|
|
1084
|
+
const c = clauses[i];
|
|
1085
|
+
const word = c.text
|
|
1086
|
+
.replace(/#[0-9a-f]+|\b(?:rgba?|hsla?|oklch)\([^)]*\)/g, '')
|
|
1087
|
+
.trim();
|
|
1088
|
+
if (
|
|
1089
|
+
c.colors.length &&
|
|
1090
|
+
/^colou?rs?:?$/.test(word) &&
|
|
1091
|
+
clauses[i - 1].aspects.length
|
|
1092
|
+
) {
|
|
1093
|
+
c.aspects = [...clauses[i - 1].aspects.filter(a => a !== 'size')];
|
|
1094
|
+
c.parts = clauses[i - 1].parts.map(p => ({...p}));
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
// "success badge": a variant word right before the part.
|
|
1098
|
+
for (const c of clauses)
|
|
1099
|
+
for (const p of c.parts) {
|
|
1100
|
+
if (p.when || !C.MAP[p.on]) continue;
|
|
1101
|
+
const own = JSON.stringify(C.MAP[p.on].own ?? {});
|
|
1102
|
+
const noun = PARTS.find(([, x]) => x.on === p.on && !x.when)?.[0];
|
|
1103
|
+
for (const m of c.text.matchAll(/\b([a-z]+)\s+([a-z]+)\b/g))
|
|
1104
|
+
if (own.includes(`variant=${m[1]}"`) && noun?.test(m[2])) {
|
|
1105
|
+
p.when = `variant:${m[1]}`;
|
|
1106
|
+
break;
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
// "no shadows on cards and dialogs": a clause that only names a part
|
|
1110
|
+
// takes the ask of the clause before it.
|
|
1111
|
+
for (let i = 1; i < clauses.length; i++) {
|
|
1112
|
+
const c = clauses[i];
|
|
1113
|
+
const prev = clauses[i - 1];
|
|
1114
|
+
if (
|
|
1115
|
+
c.parts.length &&
|
|
1116
|
+
!c.aspects.length &&
|
|
1117
|
+
!c.colors.length &&
|
|
1118
|
+
!c.lengths.length &&
|
|
1119
|
+
!c.except &&
|
|
1120
|
+
prev.aspects.length &&
|
|
1121
|
+
prev.parts.length &&
|
|
1122
|
+
!PARTS.reduce((t, [re]) => t.replace(re, ' '), ` ${c.text} `)
|
|
1123
|
+
.replace(/\b(the|a|an|all|every|on|for|too|both)\b/g, ' ')
|
|
1124
|
+
.trim()
|
|
1125
|
+
) {
|
|
1126
|
+
c.aspects = [...prev.aspects];
|
|
1127
|
+
c.neg = prev.neg;
|
|
1128
|
+
c.dir ??= prev.dir;
|
|
1129
|
+
c.text = `${prev.text.replace(/\bon\b.*$/, '')} ${c.text}`;
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
// "the table ... a header" is the table's header row.
|
|
1133
|
+
if (/\b(tables?|rows?|zebra)\b/.test(q))
|
|
1134
|
+
for (const c of clauses)
|
|
1135
|
+
for (const p of c.parts)
|
|
1136
|
+
if (p.on === 'app-shell-header') p.on = 'table-header-cell';
|
|
1137
|
+
// A clause that is only a color ("brand blue, #0057ff") belongs to the
|
|
1138
|
+
// clause before it; a clause with any other word ("accent #fff") does not.
|
|
1139
|
+
for (let i = 1; i < clauses.length; i++) {
|
|
1140
|
+
const c = clauses[i];
|
|
1141
|
+
const rest = c.text
|
|
1142
|
+
.replace(/#[0-9a-f]+|\b(?:rgba?|hsla?|oklch)\([^)]*\)/g, '')
|
|
1143
|
+
.replace(/\b(the|a|an|it|its|is|like|please|pls|thanks|ok)\b/g, '')
|
|
1144
|
+
.trim();
|
|
1145
|
+
if (c.colors.length && !rest && !c.parts.length && !c.aspects.length) {
|
|
1146
|
+
clauses[i - 1].colors = [...c.colors, ...clauses[i - 1].colors];
|
|
1147
|
+
c.colors = [];
|
|
1148
|
+
c.text = '';
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
// A clause that names a color the theme generates with no color ("LGTM
|
|
1152
|
+
// except the accent") gives that role to the next clause with only a
|
|
1153
|
+
// color ("make it #6d28d9"); so does "the purple" for the brand color.
|
|
1154
|
+
for (let i = 1; i < clauses.length; i++) {
|
|
1155
|
+
const c = clauses[i];
|
|
1156
|
+
const prev = clauses[i - 1];
|
|
1157
|
+
if (
|
|
1158
|
+
c.colors.length &&
|
|
1159
|
+
!c.parts.length &&
|
|
1160
|
+
!c.aspects.length &&
|
|
1161
|
+
!ROLE_WORDS.test(c.text) &&
|
|
1162
|
+
// The color before is one the question moves away from ("I hate the
|
|
1163
|
+
// purple"), or one for the other mode ("in light mode … in dark mode").
|
|
1164
|
+
(!prev.colors.length ||
|
|
1165
|
+
prev.neg ||
|
|
1166
|
+
/\b(hate|dislike|not a fan|tired of|sick of)\b/.test(prev.text) ||
|
|
1167
|
+
Boolean(c.mode && prev.mode && c.mode !== prev.mode)) &&
|
|
1168
|
+
!prev.parts.length
|
|
1169
|
+
) {
|
|
1170
|
+
const role =
|
|
1171
|
+
ROLE_WORDS.exec(prev.text)?.[0] ??
|
|
1172
|
+
(new RegExp(`\\bthe (${Object.keys(HUES).join('|')})\\b`).test(
|
|
1173
|
+
prev.text,
|
|
1174
|
+
)
|
|
1175
|
+
? 'accent'
|
|
1176
|
+
: null);
|
|
1177
|
+
if (role) c.text = `${role} ${c.text}`;
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
863
1180
|
// "nav items" in a question about the sidebar are the side nav's; an
|
|
864
1181
|
// underline on tabs is the tab indicator.
|
|
865
1182
|
const side = /\b(side ?nav|sidebar|side ?panel)\b/.test(q);
|
|
@@ -899,6 +1216,17 @@ export function draftAnswer(ctx, env, question) {
|
|
|
899
1216
|
!c.except &&
|
|
900
1217
|
// "per the brand guide" names no part; "accent text" does.
|
|
901
1218
|
!(ROLE_WORDS.test(c.text) && !c.aspects.length) &&
|
|
1219
|
+
// "Circular font" after "12px cards" is the theme's font.
|
|
1220
|
+
!(c.aspects.length && c.aspects.every(a => a === 'family')) &&
|
|
1221
|
+
// "serif headings, no shadows": a type part does not take a shadow,
|
|
1222
|
+
// corner or border ask.
|
|
1223
|
+
!(
|
|
1224
|
+
before.parts.every(p => ['heading', 'body', 'code'].includes(p.on)) &&
|
|
1225
|
+
c.aspects.length &&
|
|
1226
|
+
c.aspects.every(a =>
|
|
1227
|
+
['shadow', 'corners', 'border', 'spacing'].includes(a),
|
|
1228
|
+
)
|
|
1229
|
+
) &&
|
|
902
1230
|
(c.aspects.length || c.colors.length || c.lengths.length)
|
|
903
1231
|
) {
|
|
904
1232
|
c.parts = before.parts.map(p => ({...p}));
|
|
@@ -924,24 +1252,16 @@ export function draftAnswer(ctx, env, question) {
|
|
|
924
1252
|
(!c.parts.length || (!prev.parts.length && !prev.aspects.length))
|
|
925
1253
|
)
|
|
926
1254
|
c.mode = prev.mode;
|
|
927
|
-
// "brand blue, #0057ff": a clause that is only a color belongs to the
|
|
928
|
-
// clause before it.
|
|
929
|
-
if (
|
|
930
|
-
prev &&
|
|
931
|
-
!c.parts.length &&
|
|
932
|
-
!c.aspects.length &&
|
|
933
|
-
c.colors.length &&
|
|
934
|
-
c.text
|
|
935
|
-
.replace(/#[0-9a-f]+|\b(?:rgba?|hsla?|oklch)\([^)]*\)/g, '')
|
|
936
|
-
.trim()
|
|
937
|
-
.split(/\s+/)
|
|
938
|
-
.filter(Boolean).length <= 1
|
|
939
|
-
) {
|
|
940
|
-
prev.colors = [...c.colors, ...prev.colors];
|
|
941
|
-
c.colors = [];
|
|
942
|
-
c.text = '';
|
|
943
|
-
}
|
|
944
1255
|
}
|
|
1256
|
+
// The tab's text is on the tab, not on its underline.
|
|
1257
|
+
for (const c of clauses)
|
|
1258
|
+
for (const p of c.parts)
|
|
1259
|
+
if (
|
|
1260
|
+
p.on === 'tab-indicator' &&
|
|
1261
|
+
c.aspects.includes('text') &&
|
|
1262
|
+
!/\bunderline|indicator\b/.test(c.text)
|
|
1263
|
+
)
|
|
1264
|
+
p.on = 'tab';
|
|
945
1265
|
fillAspect();
|
|
946
1266
|
const modal = env.data.mode === 'both';
|
|
947
1267
|
const modeOf = (/** @type {Clause} */ c) =>
|
|
@@ -963,6 +1283,44 @@ export function draftAnswer(ctx, env, question) {
|
|
|
963
1283
|
env.base[mode]?.[token] ?? String(TOKENS[token] ?? '');
|
|
964
1284
|
/** The member a group's checks read. @param {string} on */
|
|
965
1285
|
const one = on => (FAMILIES[on] ? FAMILIES[on][0] : on);
|
|
1286
|
+
/**
|
|
1287
|
+
* Steps for a color how works out from the one a token has now. On a
|
|
1288
|
+
* theme with both modes there is one step per mode, each from that mode's
|
|
1289
|
+
* own value, so a change made for light never lands on dark; with the
|
|
1290
|
+
* clause's mode, only that one. A mode whose value would not change gets
|
|
1291
|
+
* no step.
|
|
1292
|
+
* @param {string} token the token whose value the new color starts from
|
|
1293
|
+
* @param {string} thing what the step sets (the token, or a property)
|
|
1294
|
+
* @param {Record<string, string | undefined>} flags
|
|
1295
|
+
* @param {(now: string, mode: 'light' | 'dark') => string | null} fn
|
|
1296
|
+
* @param {Clause} c
|
|
1297
|
+
* @returns {Step[]}
|
|
1298
|
+
*/
|
|
1299
|
+
const perMode = (token, thing, flags, fn, c) => {
|
|
1300
|
+
const modes = /** @type {Array<'light' | 'dark'>} */ (
|
|
1301
|
+
c.mode && modal
|
|
1302
|
+
? [c.mode]
|
|
1303
|
+
: modal
|
|
1304
|
+
? ['light', 'dark']
|
|
1305
|
+
: [env.data.mode === 'dark-only' ? 'dark' : 'light']
|
|
1306
|
+
);
|
|
1307
|
+
/** @type {Step[]} */
|
|
1308
|
+
const out = [];
|
|
1309
|
+
for (const m of modes) {
|
|
1310
|
+
const now = current(token, m);
|
|
1311
|
+
const v = fn(now, m);
|
|
1312
|
+
if (v && v.toLowerCase() !== now.toLowerCase())
|
|
1313
|
+
out.push(set(thing, v, {...flags, ...(modal ? {mode: m} : {})}));
|
|
1314
|
+
}
|
|
1315
|
+
return out;
|
|
1316
|
+
};
|
|
1317
|
+
/** How the mode of a set of per-mode steps reads in a sentence. @param {Step[]} steps */
|
|
1318
|
+
const modesSaid = steps =>
|
|
1319
|
+
modal && steps.length
|
|
1320
|
+
? steps.length > 1
|
|
1321
|
+
? ', each mode from its own value'
|
|
1322
|
+
: ` in ${steps[0].mode} mode only (the other mode keeps its value)`
|
|
1323
|
+
: '';
|
|
966
1324
|
/**
|
|
967
1325
|
* The state a part takes for a state word, as `set` names it.
|
|
968
1326
|
* @param {string} on @param {string} word
|
|
@@ -1058,7 +1416,15 @@ export function draftAnswer(ctx, env, question) {
|
|
|
1058
1416
|
/** @param {Draft} input */
|
|
1059
1417
|
const push = input => {
|
|
1060
1418
|
const d = withMode(input, clauseNow);
|
|
1061
|
-
|
|
1419
|
+
// A step given twice in one option runs once.
|
|
1420
|
+
const options = d.options
|
|
1421
|
+
.map(o =>
|
|
1422
|
+
o.filter(
|
|
1423
|
+
(st, i) =>
|
|
1424
|
+
o.findIndex(x => JSON.stringify(x) === JSON.stringify(st)) === i,
|
|
1425
|
+
),
|
|
1426
|
+
)
|
|
1427
|
+
.filter(o => o.length);
|
|
1062
1428
|
// The caller reads what was kept.
|
|
1063
1429
|
input.text = d.text;
|
|
1064
1430
|
input.options = options;
|
|
@@ -1084,6 +1450,18 @@ export function draftAnswer(ctx, env, question) {
|
|
|
1084
1450
|
const colorFor = (c, kind) => {
|
|
1085
1451
|
for (const [re, fill, text] of THEME_COLOR_WORDS)
|
|
1086
1452
|
if (re.test(c.text)) return kind === 'fill' ? fill : text;
|
|
1453
|
+
// "fails contrast on white": the color after "on" is what the text sits
|
|
1454
|
+
// on, never the text's own color.
|
|
1455
|
+
if (kind === 'text') {
|
|
1456
|
+
const own = colorsIn(
|
|
1457
|
+
c.text.replace(
|
|
1458
|
+
/\b(on|against|over)\s+(a\s+|the\s+)?((light|dark|pale)\s+)?(#[0-9a-f]+|[a-z]+)(\s+(background|bg|page|surface|cards?))?/g,
|
|
1459
|
+
' ',
|
|
1460
|
+
),
|
|
1461
|
+
);
|
|
1462
|
+
if (c.colors.length && !own.length) return null;
|
|
1463
|
+
if (own.length) return own[0];
|
|
1464
|
+
}
|
|
1087
1465
|
if (kind === 'text' && !c.colors.length) {
|
|
1088
1466
|
if (/\bdark (text|labels?|writing|words)\b/.test(c.text))
|
|
1089
1467
|
return '#111827';
|
|
@@ -1356,8 +1734,10 @@ export function draftAnswer(ctx, env, question) {
|
|
|
1356
1734
|
: null;
|
|
1357
1735
|
}
|
|
1358
1736
|
if (on === 'page') {
|
|
1359
|
-
const color = colorFor(c, 'fill')
|
|
1360
|
-
|
|
1737
|
+
const color = colorFor(c, 'fill');
|
|
1738
|
+
// "the page background lighter": the whole-theme answer, per mode.
|
|
1739
|
+
if (!color)
|
|
1740
|
+
return a === 'background' && c.dir ? answerFor(c, null, a) : null;
|
|
1361
1741
|
return {
|
|
1362
1742
|
text: `the page background: --color-background-body${c.mode && modal ? ` in ${c.mode} mode` : ''}`,
|
|
1363
1743
|
options: [
|
|
@@ -1378,16 +1758,23 @@ export function draftAnswer(ctx, env, question) {
|
|
|
1378
1758
|
};
|
|
1379
1759
|
}
|
|
1380
1760
|
if (on === 'overlay') {
|
|
1381
|
-
const
|
|
1382
|
-
const
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
?
|
|
1386
|
-
|
|
1387
|
-
|
|
1761
|
+
const typed = colorFor(c, 'fill');
|
|
1762
|
+
const steps = typed
|
|
1763
|
+
? [set('--color-overlay', typed, modeOf(c))]
|
|
1764
|
+
: c.dir || c.neg
|
|
1765
|
+
? perMode(
|
|
1766
|
+
'--color-overlay',
|
|
1767
|
+
'--color-overlay',
|
|
1768
|
+
{},
|
|
1769
|
+
(now, m) => stronger(now, c.dir === 'more' ? 1.5 : 0.6, m),
|
|
1770
|
+
c,
|
|
1771
|
+
)
|
|
1772
|
+
: [];
|
|
1773
|
+
if (!steps.length) return null;
|
|
1388
1774
|
return {
|
|
1389
|
-
text: `the dimmed layer behind dialogs and drawers: --color-overlay (
|
|
1390
|
-
options: [
|
|
1775
|
+
text: `the dimmed layer behind dialogs and drawers: --color-overlay${typed ? '' : modesSaid(steps)}`,
|
|
1776
|
+
options: [steps],
|
|
1777
|
+
sequence: steps.length > 1,
|
|
1391
1778
|
};
|
|
1392
1779
|
}
|
|
1393
1780
|
if (p?.role === 'body' && a === 'weight') {
|
|
@@ -1407,13 +1794,27 @@ export function draftAnswer(ctx, env, question) {
|
|
|
1407
1794
|
}
|
|
1408
1795
|
if (p?.role && (a === 'family' || a === 'fontsize')) {
|
|
1409
1796
|
if (a === 'family') {
|
|
1410
|
-
const font = fontIn(c
|
|
1411
|
-
return
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1797
|
+
const font = fontIn(c, question);
|
|
1798
|
+
if (!font) return null;
|
|
1799
|
+
// set font --on body moves the heading font too in this release, so
|
|
1800
|
+
// the body alone takes its token.
|
|
1801
|
+
if (p.role === 'body' && env.bodyFontReachesHeadings) {
|
|
1802
|
+
const stack = FONTS[font]
|
|
1803
|
+
? `${FONTS[font][0].includes(' ') ? `"${FONTS[font][0]}"` : FONTS[font][0]}, ${FONTS[font][1]}`
|
|
1804
|
+
: OPEN_FONTS[font]
|
|
1805
|
+
? `"${OPEN_FONTS[font].family}", ${OPEN_FONTS[font].fallbacks}`
|
|
1806
|
+
: /[\s,]/.test(font) && !font.includes(',')
|
|
1807
|
+
? `"${font}"`
|
|
1808
|
+
: font;
|
|
1809
|
+
return {
|
|
1810
|
+
text: 'the body font alone: --font-family-body (font --on body also changes the headings in this release)',
|
|
1811
|
+
options: [[set('--font-family-body', stack)]],
|
|
1812
|
+
};
|
|
1813
|
+
}
|
|
1814
|
+
return {
|
|
1815
|
+
text: `the ${p.role} font: font --on ${p.role}`,
|
|
1816
|
+
options: [[set('font', font, {on: p.role})]],
|
|
1817
|
+
};
|
|
1417
1818
|
}
|
|
1418
1819
|
if (p.role === 'body') {
|
|
1419
1820
|
const px = /\b(\d+)px\b/.exec(c.text)?.[1];
|
|
@@ -1467,10 +1868,30 @@ export function draftAnswer(ctx, env, question) {
|
|
|
1467
1868
|
case 'corners': {
|
|
1468
1869
|
const tall = tallIn(c.text);
|
|
1469
1870
|
const tied = radiusIn(c.text);
|
|
1470
|
-
const
|
|
1871
|
+
const typedPx =
|
|
1471
1872
|
(tied && /^-?\d*\.?\d+$/.test(tied) ? `${tied}px` : tied) ??
|
|
1472
1873
|
c.lengths.find(l => l !== tall) ??
|
|
1473
1874
|
null;
|
|
1875
|
+
// A radius of 0 is square.
|
|
1876
|
+
const px = typedPx && parseFloat(typedPx) === 0 ? null : typedPx;
|
|
1877
|
+
const zero = Boolean(typedPx) && !px;
|
|
1878
|
+
// "revert the rounded corners": take back what the theme sets.
|
|
1879
|
+
if (/\b(revert|undo|take back)\b/.test(c.text)) {
|
|
1880
|
+
const back = existing(['corners', 'border-radius'], on);
|
|
1881
|
+
if (back.length)
|
|
1882
|
+
return {
|
|
1883
|
+
text: `take back the corners this theme sets${where}`,
|
|
1884
|
+
options: back.map(x => [
|
|
1885
|
+
/** @type {Step} */ ({
|
|
1886
|
+
verb: 'undo',
|
|
1887
|
+
thing: x.thing,
|
|
1888
|
+
...(on ? {on} : {}),
|
|
1889
|
+
...(x.when ? {when: x.when} : {}),
|
|
1890
|
+
...(x.state ? {state: x.state} : {}),
|
|
1891
|
+
}),
|
|
1892
|
+
]),
|
|
1893
|
+
};
|
|
1894
|
+
}
|
|
1474
1895
|
if (px?.startsWith('-'))
|
|
1475
1896
|
return {
|
|
1476
1897
|
text: `a radius cannot be negative ("${px}"); give a size of 0 or more`,
|
|
@@ -1479,9 +1900,11 @@ export function draftAnswer(ctx, env, question) {
|
|
|
1479
1900
|
// "too sharp" asks for rounder, not square.
|
|
1480
1901
|
const shapeText = c.text.replace(/\btoo \w+/g, ' ');
|
|
1481
1902
|
const shape =
|
|
1482
|
-
c.neg || /\b(square(d)?|sharp)\b/.test(shapeText)
|
|
1903
|
+
zero || c.neg || /\b(square(d)?|sharp)\b/.test(shapeText)
|
|
1483
1904
|
? 'square'
|
|
1484
|
-
: /\b(pill|circular|circles?|fully round)\b/.test(
|
|
1905
|
+
: /\b(pill|circular(?! (font|typeface))|circles?|fully round)\b/.test(
|
|
1906
|
+
shapeText,
|
|
1907
|
+
)
|
|
1485
1908
|
? 'pill'
|
|
1486
1909
|
: null;
|
|
1487
1910
|
const value =
|
|
@@ -1495,11 +1918,17 @@ export function draftAnswer(ctx, env, question) {
|
|
|
1495
1918
|
? 'more'
|
|
1496
1919
|
: 'round');
|
|
1497
1920
|
if (!value) return null;
|
|
1498
|
-
if (!on)
|
|
1921
|
+
if (!on) {
|
|
1922
|
+
// The corners dial takes pixels: a rem or em size is converted at
|
|
1923
|
+
// 16px to the rem.
|
|
1924
|
+
const dial = /^\d*\.?\d+r?em$/.test(value)
|
|
1925
|
+
? `${Math.round(parseFloat(value) * 16 * 100) / 100}px`
|
|
1926
|
+
: value;
|
|
1499
1927
|
return {
|
|
1500
|
-
text: `corners${where}: the corners dial (sets the corner tokens together)`,
|
|
1501
|
-
options: [[set('corners',
|
|
1928
|
+
text: `corners${where}: the corners dial (sets the corner tokens together)${dial !== value ? `, ${value} as ${dial}` : ''}`,
|
|
1929
|
+
options: [[set('corners', dial)]],
|
|
1502
1930
|
};
|
|
1931
|
+
}
|
|
1503
1932
|
if (px)
|
|
1504
1933
|
return {
|
|
1505
1934
|
text: `corners${where}: border-radius ${px}`,
|
|
@@ -1522,11 +1951,19 @@ export function draftAnswer(ctx, env, question) {
|
|
|
1522
1951
|
text: 'the shadow you wrote, as the shared medium shadow most panels use: --shadow-med',
|
|
1523
1952
|
options: [[set('--shadow-med', typedShadow, modeOf(c))]],
|
|
1524
1953
|
};
|
|
1954
|
+
// Another clause writes the shadow out: that one answers.
|
|
1955
|
+
if (!typedShadow && !on && !c.neg && shadowIn(q)) return null;
|
|
1956
|
+
// "too strong" asks for softer: the word after "too" is what to
|
|
1957
|
+
// move away from.
|
|
1958
|
+
const shadowText = c.text.replace(/\btoo \w+/g, ' ');
|
|
1959
|
+
const soft =
|
|
1960
|
+
c.dir === 'less' ||
|
|
1961
|
+
/\b(soft(er)?|subtle(r)?|light(er)?|gentle|less)\b/.test(shadowText);
|
|
1525
1962
|
const strong =
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1963
|
+
!soft &&
|
|
1964
|
+
/\b(strong(er)?|deep(er)?|heav(y|ier)|bigger|more)\b/.test(
|
|
1965
|
+
shadowText,
|
|
1966
|
+
);
|
|
1530
1967
|
if (!on) {
|
|
1531
1968
|
if (c.neg || /\bflat\b/.test(c.text))
|
|
1532
1969
|
return {
|
|
@@ -1568,7 +2005,8 @@ export function draftAnswer(ctx, env, question) {
|
|
|
1568
2005
|
sequence: true,
|
|
1569
2006
|
};
|
|
1570
2007
|
}
|
|
1571
|
-
|
|
2008
|
+
// "flat cards": no shadow on them ("too flat" asks for one).
|
|
2009
|
+
if (c.neg || (/\bflat\b/.test(c.text) && !/\btoo flat\b/.test(c.text)))
|
|
1572
2010
|
return {
|
|
1573
2011
|
text: `no shadow${where}`,
|
|
1574
2012
|
options: [...undo(['box-shadow']), [set('box-shadow', 'none', f)]],
|
|
@@ -1608,19 +2046,29 @@ export function draftAnswer(ctx, env, question) {
|
|
|
1608
2046
|
};
|
|
1609
2047
|
// Darker, lighter, subtler or more contrast asks for the color.
|
|
1610
2048
|
if (
|
|
1611
|
-
/\b(darker|lighter|subtle\w*|contrast|stronger|fainter|softer|visible|invisible)\b/.test(
|
|
2049
|
+
/\b(darker|lighter|subtle\w*|contrast|stronger|fainter|softer|visible|invisible|too (dark|light|faint|strong|harsh|heavy))\b/.test(
|
|
1612
2050
|
c.text,
|
|
1613
2051
|
)
|
|
1614
2052
|
) {
|
|
1615
|
-
|
|
2053
|
+
// "too light" asks for stronger borders, "too dark" for fainter.
|
|
1616
2054
|
const more =
|
|
1617
|
-
/\b(darker|stronger|more contrast|visible)\b/.test(
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
2055
|
+
(/\b(darker|stronger|more contrast|visible|too (light|faint|subtle))\b/.test(
|
|
2056
|
+
c.text,
|
|
2057
|
+
) &&
|
|
2058
|
+
!/\binvisible\b/.test(c.text)) ||
|
|
2059
|
+
false;
|
|
2060
|
+
const steps = perMode(
|
|
2061
|
+
'--color-border',
|
|
2062
|
+
'--color-border',
|
|
2063
|
+
{},
|
|
2064
|
+
(now, m) => stronger(now, more ? 2 : 0.5, m),
|
|
2065
|
+
c,
|
|
2066
|
+
);
|
|
2067
|
+
return steps.length
|
|
1621
2068
|
? {
|
|
1622
|
-
text: `the border color of the whole theme: --color-border
|
|
1623
|
-
options: [
|
|
2069
|
+
text: `the border color of the whole theme: --color-border, ${more ? 'stronger' : 'fainter'}${modesSaid(steps)}`,
|
|
2070
|
+
options: [steps],
|
|
2071
|
+
sequence: steps.length > 1,
|
|
1624
2072
|
}
|
|
1625
2073
|
: null;
|
|
1626
2074
|
}
|
|
@@ -1813,7 +2261,7 @@ export function draftAnswer(ctx, env, question) {
|
|
|
1813
2261
|
};
|
|
1814
2262
|
}
|
|
1815
2263
|
case 'family': {
|
|
1816
|
-
const font = fontIn(c
|
|
2264
|
+
const font = fontIn(c, question);
|
|
1817
2265
|
if (!font) return null;
|
|
1818
2266
|
if (!on)
|
|
1819
2267
|
return {
|
|
@@ -1872,10 +2320,16 @@ export function draftAnswer(ctx, env, question) {
|
|
|
1872
2320
|
const sizeTok =
|
|
1873
2321
|
on === 'heading' && p?.level
|
|
1874
2322
|
? `--text-heading-${p.level}-size`
|
|
1875
|
-
: C.partReads(one(on), 'font').find(r =>
|
|
2323
|
+
: (C.partReads(one(on), 'font').find(r =>
|
|
1876
2324
|
r.props.includes('font-size'),
|
|
1877
|
-
)?.token
|
|
1878
|
-
|
|
2325
|
+
)?.token ??
|
|
2326
|
+
Object.keys(C.MAP[one(on)]?.own?.['font-size']?.tokens ?? {})[0]);
|
|
2327
|
+
// A part with no size token of its own starts from the body size.
|
|
2328
|
+
const now = sizeTok
|
|
2329
|
+
? current(sizeTok)
|
|
2330
|
+
: on !== 'heading' && '--text-body-size' in TOKENS
|
|
2331
|
+
? current('--text-body-size')
|
|
2332
|
+
: null;
|
|
1879
2333
|
const value = px ?? (now ? scaled(now, factor) : null);
|
|
1880
2334
|
if (!value) return null;
|
|
1881
2335
|
return {
|
|
@@ -1959,7 +2413,12 @@ export function draftAnswer(ctx, env, question) {
|
|
|
1959
2413
|
: null;
|
|
1960
2414
|
case 'size': {
|
|
1961
2415
|
if (!on) return null;
|
|
1962
|
-
|
|
2416
|
+
// A heading's size is its type size.
|
|
2417
|
+
if (on === 'heading' && !c.lengths.length)
|
|
2418
|
+
return answerFor(c, p, 'fontsize');
|
|
2419
|
+
const tall =
|
|
2420
|
+
tallIn(c.text) ??
|
|
2421
|
+
(/\b(taller|shorter|height)\b/.test(c.text) ? c.lengths[0] : null);
|
|
1963
2422
|
if (tall)
|
|
1964
2423
|
return {
|
|
1965
2424
|
text: `the height${where}: min-height ${tall}`,
|
|
@@ -2020,30 +2479,115 @@ export function draftAnswer(ctx, env, question) {
|
|
|
2020
2479
|
? '--color-text-secondary'
|
|
2021
2480
|
: '--color-text-primary';
|
|
2022
2481
|
if (!on) {
|
|
2023
|
-
const
|
|
2024
|
-
|
|
2025
|
-
|
|
2482
|
+
const label = `${tok === '--color-text-secondary' ? 'secondary' : 'main'} text color: ${tok}`;
|
|
2483
|
+
// "never use pure black": where the token is that color, a near
|
|
2484
|
+
// color that is not it; a mode where it is not keeps its value.
|
|
2485
|
+
if (c.neg && color) {
|
|
2486
|
+
const avoid = parseColor(color);
|
|
2487
|
+
const steps = perMode(
|
|
2488
|
+
tok,
|
|
2489
|
+
tok,
|
|
2490
|
+
{},
|
|
2491
|
+
now => {
|
|
2492
|
+
const n = parseColor(now);
|
|
2493
|
+
if (
|
|
2494
|
+
!avoid ||
|
|
2495
|
+
!n ||
|
|
2496
|
+
n.some((x, i) => Math.abs(x - avoid[i]) > 2)
|
|
2497
|
+
)
|
|
2498
|
+
return null;
|
|
2499
|
+
return avoid.reduce((x, y) => x + y, 0) < 384
|
|
2500
|
+
? '#1f2937'
|
|
2501
|
+
: '#f9fafb';
|
|
2502
|
+
},
|
|
2503
|
+
c,
|
|
2504
|
+
);
|
|
2505
|
+
return steps.length
|
|
2506
|
+
? {
|
|
2507
|
+
text: `${label}, off ${color}${modesSaid(steps)}`,
|
|
2508
|
+
options: [steps],
|
|
2509
|
+
sequence: steps.length > 1,
|
|
2510
|
+
}
|
|
2511
|
+
: {
|
|
2512
|
+
text: `${label} is not ${color} in any mode, so nothing changes`,
|
|
2513
|
+
options: [],
|
|
2514
|
+
};
|
|
2515
|
+
}
|
|
2516
|
+
if (color) {
|
|
2517
|
+
// A text color for both modes that one mode's page would make
|
|
2518
|
+
// unreadable is set for the other mode only.
|
|
2519
|
+
const rgb = parseColor(color);
|
|
2520
|
+
const readable = /** @type {Array<'light' | 'dark'>} */ ([
|
|
2521
|
+
'light',
|
|
2522
|
+
'dark',
|
|
2523
|
+
]).filter(m => {
|
|
2524
|
+
const page = parseColor(current('--color-background-body', m));
|
|
2525
|
+
return !rgb || !page || ratio(rgb, page) >= 3;
|
|
2526
|
+
});
|
|
2527
|
+
if (
|
|
2528
|
+
!c.mode &&
|
|
2529
|
+
modal &&
|
|
2530
|
+
readable.length === 1 &&
|
|
2531
|
+
// Asked for every mode, or with its own page color: as asked.
|
|
2532
|
+
!/\b(everywhere|both modes|all modes|always|in every mode)\b/.test(
|
|
2533
|
+
q,
|
|
2534
|
+
) &&
|
|
2535
|
+
!/\b(bg|background|page)\b/.test(q)
|
|
2536
|
+
)
|
|
2537
|
+
return {
|
|
2538
|
+
text: `${label} in ${readable[0]} mode only: on the ${readable[0] === 'light' ? 'dark' : 'light'} page ${color} would not be readable`,
|
|
2539
|
+
options: [[set(tok, color, {mode: readable[0]})]],
|
|
2540
|
+
};
|
|
2541
|
+
return {
|
|
2542
|
+
text: `${label}${c.mode && modal ? ` in ${c.mode} mode` : ''}`,
|
|
2543
|
+
options: [[set(tok, color, modeOf(c))]],
|
|
2544
|
+
};
|
|
2545
|
+
}
|
|
2546
|
+
// More contrast moves text away from its page: darker on light,
|
|
2547
|
+
// lighter on dark. Less contrast moves it toward the page.
|
|
2548
|
+
const more =
|
|
2549
|
+
/\b(darker|too light|can'?t read|hard to read|unreadable|(more|better|higher|low|fails?|failing|enough) contrast|contrast)\b/.test(
|
|
2550
|
+
c.text,
|
|
2551
|
+
) && !/\bless contrast\b/.test(c.text);
|
|
2552
|
+
const less =
|
|
2553
|
+
/\b(less bright|dimmer|softer|lighter|less contrast|too dark)\b/.test(
|
|
2026
2554
|
c.text,
|
|
2027
2555
|
);
|
|
2028
|
-
|
|
2029
|
-
const
|
|
2030
|
-
const
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2556
|
+
if (!more && !less) return null;
|
|
2557
|
+
const literal = /\b(darker|lighter)\b/.test(c.text) && c.mode;
|
|
2558
|
+
const steps = perMode(
|
|
2559
|
+
tok,
|
|
2560
|
+
tok,
|
|
2561
|
+
{},
|
|
2562
|
+
(now, m) => {
|
|
2563
|
+
const toward = literal
|
|
2564
|
+
? /\bdarker\b/.test(c.text)
|
|
2565
|
+
? -1
|
|
2566
|
+
: 1
|
|
2567
|
+
: (m === 'dark' ? 1 : -1) * (more ? 1 : -1);
|
|
2568
|
+
return shift(now, toward * (more ? 0.3 : 0.2));
|
|
2569
|
+
},
|
|
2570
|
+
c,
|
|
2571
|
+
);
|
|
2572
|
+
return steps.length
|
|
2573
|
+
? {
|
|
2574
|
+
text: `${label}, ${more ? 'more' : 'less'} contrast with the page${modesSaid(steps)}`,
|
|
2575
|
+
options: [steps],
|
|
2576
|
+
sequence: steps.length > 1,
|
|
2577
|
+
}
|
|
2578
|
+
: {
|
|
2579
|
+
text: `${label} is already ${more ? 'as far from the page as it goes' : 'as close to the page as it should go'} (${current(tok, 'light')} in light${modal ? `, ${current(tok, 'dark')} in dark` : ''}), so nothing changes`,
|
|
2580
|
+
options: [],
|
|
2581
|
+
};
|
|
2582
|
+
}
|
|
2583
|
+
// A link's color comes from its color prop, so no part style
|
|
2584
|
+
// reaches it: the accent text token is what a link reads, in every
|
|
2585
|
+
// state.
|
|
2586
|
+
if (on === 'link' && color)
|
|
2042
2587
|
return {
|
|
2043
|
-
text:
|
|
2044
|
-
options: [[set(
|
|
2588
|
+
text: `the link color: --color-text-accent, the token a link reads (it also colors other accent text)${f.state ? `; a link has no color of its own for ${f.state}, so this changes it in every state` : ''}`,
|
|
2589
|
+
options: [[set('--color-text-accent', color, modeOf(c))]],
|
|
2045
2590
|
};
|
|
2046
|
-
}
|
|
2047
2591
|
if (!color) return null;
|
|
2048
2592
|
return {
|
|
2049
2593
|
text: `text color${where}: color`,
|
|
@@ -2106,17 +2650,49 @@ export function draftAnswer(ctx, env, question) {
|
|
|
2106
2650
|
};
|
|
2107
2651
|
}
|
|
2108
2652
|
if (!on) {
|
|
2109
|
-
const
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
if (!
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2653
|
+
const color = colorFor(c, 'fill');
|
|
2654
|
+
if (color)
|
|
2655
|
+
return {
|
|
2656
|
+
text: `the page background: --color-background-body${c.mode && modal ? ` in ${c.mode} mode` : ''}`,
|
|
2657
|
+
options: [[set('--color-background-body', color, modeOf(c))]],
|
|
2658
|
+
};
|
|
2659
|
+
if (!c.dir) return null;
|
|
2660
|
+
const lighter = /\blight(er)?|brighter\b/.test(c.text);
|
|
2661
|
+
const steps = perMode(
|
|
2662
|
+
'--color-background-body',
|
|
2663
|
+
'--color-background-body',
|
|
2664
|
+
{},
|
|
2665
|
+
(now, m) => {
|
|
2666
|
+
const v = shift(
|
|
2667
|
+
now,
|
|
2668
|
+
lighter
|
|
2669
|
+
? m === 'dark'
|
|
2670
|
+
? 0.06
|
|
2671
|
+
: 0.5
|
|
2672
|
+
: m === 'dark'
|
|
2673
|
+
? -0.3
|
|
2674
|
+
: -0.06,
|
|
2675
|
+
);
|
|
2676
|
+
// White cannot get lighter, nor black darker.
|
|
2677
|
+
const sum = (/** @type {string | null} */ x) =>
|
|
2678
|
+
(x &&
|
|
2679
|
+
parseColor(x)
|
|
2680
|
+
?.slice(0, 3)
|
|
2681
|
+
.reduce((p, q) => p + q, 0)) ??
|
|
2682
|
+
0;
|
|
2683
|
+
return v && (lighter ? sum(v) > sum(now) : sum(v) < sum(now))
|
|
2684
|
+
? v
|
|
2685
|
+
: null;
|
|
2686
|
+
},
|
|
2687
|
+
c,
|
|
2688
|
+
);
|
|
2689
|
+
return steps.length
|
|
2690
|
+
? {
|
|
2691
|
+
text: `a ${lighter ? 'lighter' : 'darker'} page background: --color-background-body${modesSaid(steps)}`,
|
|
2692
|
+
options: [steps],
|
|
2693
|
+
sequence: steps.length > 1,
|
|
2694
|
+
}
|
|
2695
|
+
: null;
|
|
2120
2696
|
}
|
|
2121
2697
|
if (c.decl.background || c.decl['background-color'])
|
|
2122
2698
|
return {
|
|
@@ -2131,6 +2707,15 @@ export function draftAnswer(ctx, env, question) {
|
|
|
2131
2707
|
],
|
|
2132
2708
|
],
|
|
2133
2709
|
};
|
|
2710
|
+
// "from #f58529 to #dd2a7b": the gradient written in the question.
|
|
2711
|
+
const ends = /\bfrom\s+(\S+)\s+(?:to|into)\s+(\S+)/.exec(c.text);
|
|
2712
|
+
if (design && ends && parseColor(ends[1]) && parseColor(ends[2]))
|
|
2713
|
+
return {
|
|
2714
|
+
text: `a gradient from ${ends[1]} to ${ends[2]}${where}`,
|
|
2715
|
+
options: [
|
|
2716
|
+
[set('background', `linear-gradient(${ends[1]}, ${ends[2]})`, f)],
|
|
2717
|
+
],
|
|
2718
|
+
};
|
|
2134
2719
|
if (design)
|
|
2135
2720
|
return {
|
|
2136
2721
|
text: `a ${design} fill${where}`,
|
|
@@ -2152,23 +2737,36 @@ export function draftAnswer(ctx, env, question) {
|
|
|
2152
2737
|
sequence: true,
|
|
2153
2738
|
};
|
|
2154
2739
|
if (!color && c.dir) {
|
|
2155
|
-
const tok =
|
|
2156
|
-
C.partReads(one(on), 'background').find(r => r.when.includes(''))
|
|
2157
|
-
?.token ??
|
|
2158
|
-
(FAMILIES.containers.includes(one(on))
|
|
2159
|
-
? '--color-background-card'
|
|
2160
|
-
: '--color-background-surface');
|
|
2161
|
-
const now = tok ? current(tok, c.mode ?? 'light') : null;
|
|
2162
2740
|
const lighter = /\blight(er)?\b/.test(c.text);
|
|
2163
|
-
|
|
2164
|
-
|
|
2741
|
+
const reads = C.partReads(one(on), 'background');
|
|
2742
|
+
const read = C.MAP[one(on)]
|
|
2743
|
+
? (reads.find(r => r.when.includes(''))?.token ??
|
|
2744
|
+
(FAMILIES.containers.includes(one(on))
|
|
2745
|
+
? '--color-background-card'
|
|
2746
|
+
: reads[0]?.token))
|
|
2747
|
+
: null;
|
|
2748
|
+
// A part with no recorded fill: what its color is now is unknown,
|
|
2749
|
+
// so a brightness filter makes it darker or lighter from there.
|
|
2750
|
+
if (!read || f.state)
|
|
2165
2751
|
return {
|
|
2166
|
-
text: `${lighter ? 'a lighter' : 'a darker'}
|
|
2752
|
+
text: `${lighter ? 'a lighter' : 'a darker'} ${on}${where}: a brightness filter, from whatever color it has now`,
|
|
2167
2753
|
options: [
|
|
2168
|
-
[set('filter', `brightness(${lighter ? 1.
|
|
2169
|
-
[set('background-color', color, f)],
|
|
2754
|
+
[set('filter', `brightness(${lighter ? 1.15 : 0.85})`, f)],
|
|
2170
2755
|
],
|
|
2171
2756
|
};
|
|
2757
|
+
const steps = perMode(
|
|
2758
|
+
read,
|
|
2759
|
+
'background',
|
|
2760
|
+
f,
|
|
2761
|
+
now => shift(now, lighter ? 0.12 : -0.12),
|
|
2762
|
+
c,
|
|
2763
|
+
);
|
|
2764
|
+
if (steps.length)
|
|
2765
|
+
return {
|
|
2766
|
+
text: `${lighter ? 'a lighter' : 'a darker'} background${where}, from ${read}${modesSaid(steps)}`,
|
|
2767
|
+
options: [steps],
|
|
2768
|
+
sequence: steps.length > 1,
|
|
2769
|
+
};
|
|
2172
2770
|
}
|
|
2173
2771
|
if (!color && f.state === 'hover')
|
|
2174
2772
|
return {
|
|
@@ -2235,16 +2833,25 @@ export function draftAnswer(ctx, env, question) {
|
|
|
2235
2833
|
}
|
|
2236
2834
|
}
|
|
2237
2835
|
if (/\b(more|higher|high|better) contrast\b|\bcontrast mode\b/.test(t)) {
|
|
2238
|
-
|
|
2239
|
-
const
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2836
|
+
// Away from the page in each mode: darker on light, lighter on dark.
|
|
2837
|
+
const steps = [
|
|
2838
|
+
...perMode(
|
|
2839
|
+
'--color-text-secondary',
|
|
2840
|
+
'--color-text-secondary',
|
|
2841
|
+
{},
|
|
2842
|
+
(now, m) => shift(now, m === 'dark' ? 0.35 : -0.35),
|
|
2843
|
+
c,
|
|
2844
|
+
),
|
|
2845
|
+
...perMode(
|
|
2846
|
+
'--color-border',
|
|
2847
|
+
'--color-border',
|
|
2848
|
+
{},
|
|
2849
|
+
(now, m) => stronger(now, 2.5, m),
|
|
2850
|
+
c,
|
|
2851
|
+
),
|
|
2852
|
+
];
|
|
2246
2853
|
return {
|
|
2247
|
-
text: `more contrast:
|
|
2854
|
+
text: `more contrast: secondary text further from the page and stronger borders${modal && !c.mode ? ', in light and in dark mode, each from its own value' : c.mode ? ` in ${c.mode} mode` : ''}`,
|
|
2248
2855
|
options: [steps],
|
|
2249
2856
|
sequence: steps.length > 1,
|
|
2250
2857
|
};
|
|
@@ -2257,12 +2864,18 @@ export function draftAnswer(ctx, env, question) {
|
|
|
2257
2864
|
: 'a theme that is always dark: mode dark-only',
|
|
2258
2865
|
options: [[set('mode', 'dark-only')]],
|
|
2259
2866
|
};
|
|
2260
|
-
if (/\b(undo|revert|go back|take back)\b/.test(t))
|
|
2261
|
-
return
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2867
|
+
if (/\b(undo|revert|go back|take back)\b/.test(t) && !c.colors.length)
|
|
2868
|
+
return env.undoSteps
|
|
2869
|
+
? {
|
|
2870
|
+
text: `undo ${env.slug} steps back one change (${env.undoSteps} can be undone); undo ${env.slug} <thing> removes one setting`,
|
|
2871
|
+
options: [],
|
|
2872
|
+
lookup: `${P} undo ${env.slug}`,
|
|
2873
|
+
}
|
|
2874
|
+
: {
|
|
2875
|
+
text: `${env.slug} has no change to undo yet; show ${env.slug} lists its settings`,
|
|
2876
|
+
options: [],
|
|
2877
|
+
...(env.exists ? {lookup: `${P} show ${env.slug}`} : {}),
|
|
2878
|
+
};
|
|
2266
2879
|
if (/\breset\b|\bstart over\b|\bback to (the )?defaults?\b/.test(t))
|
|
2267
2880
|
return {
|
|
2268
2881
|
text: `each undo ${env.slug} steps back one change; show ${env.slug} lists every setting, and undo ${env.slug} <thing> removes one`,
|
|
@@ -2302,6 +2915,10 @@ export function draftAnswer(ctx, env, question) {
|
|
|
2302
2915
|
/\b(colou?rful|saturat\w*|desaturat\w*|vivid|vibran\w*|muted|dull|washed|pastel|intense|pop|punch\w*|gr[ae]yer)\b/.test(
|
|
2303
2916
|
t,
|
|
2304
2917
|
);
|
|
2918
|
+
if (vib && c.colors.length && ROLE_WORDS.test(t)) {
|
|
2919
|
+
const named = roleAnswer(c);
|
|
2920
|
+
if (named) return named;
|
|
2921
|
+
}
|
|
2305
2922
|
if (vib) {
|
|
2306
2923
|
seenAspect('colors');
|
|
2307
2924
|
const less =
|
|
@@ -2393,78 +3010,178 @@ export function draftAnswer(ctx, env, question) {
|
|
|
2393
3010
|
lookup: `${HOW} colors`,
|
|
2394
3011
|
};
|
|
2395
3012
|
}
|
|
2396
|
-
|
|
2397
|
-
|
|
3013
|
+
const named = roleAnswer(c);
|
|
3014
|
+
if (named) return named;
|
|
3015
|
+
// A color with nothing else named, in a question about a look ("Duolingo
|
|
3016
|
+
// vibes: green #58cc02"), is the brand color.
|
|
3017
|
+
if (
|
|
3018
|
+
/#[0-9a-f]{3,8}\b|\b(?:rgba?|hsla?|oklch)\(/.test(c.text) &&
|
|
3019
|
+
!c.parts.length &&
|
|
3020
|
+
!c.aspects.length &&
|
|
3021
|
+
!c.lengths.length &&
|
|
3022
|
+
c.text
|
|
3023
|
+
.replace(/#[0-9a-f]+|\b(?:rgba?|hsla?|oklch)\([^)]*\)/g, '')
|
|
3024
|
+
.replace(new RegExp(`\\b(${Object.keys(HUES).join('|')})\\b`, 'g'), '')
|
|
3025
|
+
.trim()
|
|
3026
|
+
.split(/\s+/)
|
|
3027
|
+
.filter(Boolean).length <= 2 &&
|
|
3028
|
+
/\b(look|vibes?|style|like|feel|brand|theme)\b/.test(
|
|
3029
|
+
question.toLowerCase(),
|
|
3030
|
+
)
|
|
3031
|
+
)
|
|
3032
|
+
return roleAnswer({...c, text: `accent ${c.text}`});
|
|
3033
|
+
return null;
|
|
3034
|
+
}
|
|
3035
|
+
|
|
3036
|
+
/**
|
|
3037
|
+
* The colors the theme generates that a clause names, each with its own
|
|
3038
|
+
* color: the color right after the word, or right before it when nothing
|
|
3039
|
+
* follows ("#0d6efd primary"). A color is used once.
|
|
3040
|
+
* @param {Clause} c
|
|
3041
|
+
* @returns {Draft | null}
|
|
3042
|
+
*/
|
|
3043
|
+
function roleAnswer(c) {
|
|
3044
|
+
const t = c.text;
|
|
3045
|
+
const ROLES = /** @type {Array<[RegExp, string, string]>} */ ([
|
|
2398
3046
|
[
|
|
2399
|
-
/\b(accent|brand|primary
|
|
3047
|
+
/\b(accent|brand|primary|main colou?r|key colou?r)\b/g,
|
|
2400
3048
|
'accent',
|
|
2401
3049
|
'--color-accent',
|
|
2402
3050
|
],
|
|
2403
|
-
[/\b(errors?|danger|destructive)\b
|
|
2404
|
-
[/\b(success|positive)\b
|
|
2405
|
-
[/\b(warnings?|caution)\b
|
|
2406
|
-
[/\b(info|notices?)\b
|
|
3051
|
+
[/\b(errors?|danger|destructive)\b/g, 'danger', '--color-error'],
|
|
3052
|
+
[/\b(success|positive)\b/g, 'success', '--color-success'],
|
|
3053
|
+
[/\b(warnings?|caution)\b/g, 'warning', '--color-warning'],
|
|
3054
|
+
[/\b(info|notices?)\b/g, 'info', '--color-info'],
|
|
2407
3055
|
[
|
|
2408
|
-
/\b(neutrals?|gr[ae]ys?|warm(er)?|cool(er)?)\b
|
|
3056
|
+
/\b(neutrals?|gr[ae]ys?|warm(er)?|cool(er)?)\b/g,
|
|
2409
3057
|
'neutral',
|
|
2410
3058
|
'--color-neutral',
|
|
2411
3059
|
],
|
|
3060
|
+
[/\bsecondary\b(?! (text|buttons?))/g, 'secondary', ''],
|
|
2412
3061
|
]);
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
const
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
3062
|
+
/** @type {Array<{at: number, dial: string, token: string}>} */
|
|
3063
|
+
const found = [];
|
|
3064
|
+
for (const [re, dial, token] of ROLES)
|
|
3065
|
+
for (const m of t.matchAll(re))
|
|
3066
|
+
if (!found.some(x => x.dial === dial))
|
|
3067
|
+
found.push({at: m.index ?? 0, dial, token});
|
|
3068
|
+
if (!found.length) return null;
|
|
3069
|
+
found.sort((x, y) => x.at - y.at);
|
|
3070
|
+
seenAspect('colors');
|
|
3071
|
+
// Each color written in the clause, where it is.
|
|
3072
|
+
const placed = [
|
|
3073
|
+
...t.matchAll(
|
|
3074
|
+
/#[0-9a-f]{3,8}\b|\b(?:rgba?|hsla?|hwb|lab|lch|oklab|oklch)\([^)]*\)/g,
|
|
3075
|
+
),
|
|
3076
|
+
]
|
|
3077
|
+
.filter(m => parseColor(m[0]))
|
|
3078
|
+
.map(m => ({at: m.index ?? 0, color: m[0], used: false}));
|
|
3079
|
+
const hues = c.colors.filter(x => !placed.some(p => p.color === x));
|
|
3080
|
+
/** @type {Draft[]} */
|
|
3081
|
+
const answers = [];
|
|
3082
|
+
for (let i = 0; i < found.length; i++) {
|
|
3083
|
+
const {at, dial, token} = found[i];
|
|
3084
|
+
const end = found[i + 1]?.at ?? Infinity;
|
|
3085
|
+
const after = placed.find(p => !p.used && p.at > at && p.at < end);
|
|
3086
|
+
const before = [...placed].reverse().find(p => !p.used && p.at < at);
|
|
3087
|
+
const pick = after ?? (found.length === 1 || !after ? before : undefined);
|
|
3088
|
+
if (pick) pick.used = true;
|
|
3089
|
+
answers.push(
|
|
3090
|
+
one1(
|
|
3091
|
+
dial,
|
|
3092
|
+
token,
|
|
3093
|
+
pick?.color ?? (found.length === 1 ? hues[0] : undefined) ?? null,
|
|
3094
|
+
c,
|
|
3095
|
+
),
|
|
3096
|
+
);
|
|
3097
|
+
}
|
|
3098
|
+
const doing = answers.filter(x => x.options.length);
|
|
3099
|
+
if (doing.length > 1)
|
|
3100
|
+
return {
|
|
3101
|
+
text: doing.map(x => x.text).join('; '),
|
|
3102
|
+
options: [doing.map(x => x.options[0][0])],
|
|
3103
|
+
sequence: true,
|
|
3104
|
+
};
|
|
3105
|
+
return doing[0] ?? answers[0];
|
|
3106
|
+
}
|
|
3107
|
+
|
|
3108
|
+
/**
|
|
3109
|
+
* One color the theme generates, set from a clause.
|
|
3110
|
+
* @param {string} dial @param {string} token @param {string | null} given @param {Clause} c
|
|
3111
|
+
* @returns {Draft}
|
|
3112
|
+
*/
|
|
3113
|
+
function one1(dial, token, given, c) {
|
|
3114
|
+
const t = c.text;
|
|
3115
|
+
if (dial === 'secondary')
|
|
3116
|
+
return given
|
|
3117
|
+
? {
|
|
3118
|
+
text: `no setting is a second brand color; for secondary buttons, their fill: background ${given} --on button --when variant:secondary`,
|
|
3119
|
+
options: [
|
|
3120
|
+
[
|
|
3121
|
+
set('background', given, {
|
|
3122
|
+
on: 'button',
|
|
3123
|
+
when: 'variant:secondary',
|
|
3124
|
+
}),
|
|
3125
|
+
],
|
|
3126
|
+
],
|
|
3127
|
+
}
|
|
3128
|
+
: {text: 'no setting is a second brand color', options: []};
|
|
3129
|
+
let color =
|
|
3130
|
+
given &&
|
|
3131
|
+
!(
|
|
3132
|
+
dial === 'neutral' &&
|
|
3133
|
+
['#9ca3af', '#e5e7eb', '#374151', '#f3f4f6'].includes(given)
|
|
3134
|
+
)
|
|
3135
|
+
? given
|
|
3136
|
+
: null;
|
|
3137
|
+
if (dial === 'neutral' && !color)
|
|
3138
|
+
// "too warm" asks for cooler, "too cool" for warmer.
|
|
3139
|
+
color = /\btoo warm\b|\bcool(er)?\b/.test(t)
|
|
3140
|
+
? '#64748b'
|
|
3141
|
+
: /\btoo cool\b|\bwarm(er)?\b/.test(t)
|
|
2427
3142
|
? '#78716c'
|
|
2428
|
-
:
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
if (
|
|
2441
|
-
const
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
};
|
|
2449
|
-
}
|
|
2450
|
-
// No color given: say how, and never pick one.
|
|
2451
|
-
if (!color)
|
|
2452
|
-
return {
|
|
2453
|
-
text: `${DIALS[dial].help} Give the color: set ${env.slug} ${dial} <color>.`,
|
|
2454
|
-
options: [],
|
|
2455
|
-
lookup: `${HOW} ${dial}`,
|
|
2456
|
-
};
|
|
2457
|
-
if (c.mode && modal)
|
|
3143
|
+
: null;
|
|
3144
|
+
// "make the error red darker": the hue names the color; the change is darker.
|
|
3145
|
+
const NATURAL = /** @type {Record<string, string>} */ ({
|
|
3146
|
+
danger: HUES.red,
|
|
3147
|
+
success: HUES.green,
|
|
3148
|
+
warning: HUES.yellow,
|
|
3149
|
+
info: HUES.blue,
|
|
3150
|
+
});
|
|
3151
|
+
if (c.dir && color && (color === NATURAL[dial] || color === HUES.amber))
|
|
3152
|
+
color = null;
|
|
3153
|
+
if (!color && c.dir && !/\btoo (warm|cool)\b/.test(t)) {
|
|
3154
|
+
const lighter = /\b(light(er)?|brighter|paler)\b/.test(t);
|
|
3155
|
+
if (c.mode && modal) {
|
|
3156
|
+
const steps = perMode(
|
|
3157
|
+
token,
|
|
3158
|
+
token,
|
|
3159
|
+
{},
|
|
3160
|
+
now => shift(now, lighter ? 0.2 : -0.2),
|
|
3161
|
+
c,
|
|
3162
|
+
);
|
|
2458
3163
|
return {
|
|
2459
3164
|
text: `${dial} in ${c.mode} mode only: the exact token ${token}`,
|
|
2460
|
-
options: [
|
|
3165
|
+
options: steps.length ? [steps] : [],
|
|
2461
3166
|
};
|
|
3167
|
+
}
|
|
3168
|
+
color = shift(current(token, 'light'), lighter ? 0.2 : -0.2);
|
|
3169
|
+
}
|
|
3170
|
+
if (!color)
|
|
2462
3171
|
return {
|
|
2463
|
-
text: `${dial}
|
|
2464
|
-
options: [
|
|
3172
|
+
text: `${DIALS[dial].help} Give the color: set ${env.slug} ${dial} <color>.`,
|
|
3173
|
+
options: [],
|
|
3174
|
+
lookup: `${HOW} ${dial}`,
|
|
2465
3175
|
};
|
|
2466
|
-
|
|
2467
|
-
|
|
3176
|
+
if (c.mode && modal)
|
|
3177
|
+
return {
|
|
3178
|
+
text: `${dial} in ${c.mode} mode only: the exact token ${token}`,
|
|
3179
|
+
options: [[set(token, color, modeOf(c))]],
|
|
3180
|
+
};
|
|
3181
|
+
return {
|
|
3182
|
+
text: `${dial}: the editor makes its light and dark shades from ${color}`,
|
|
3183
|
+
options: [[set(dial, color)], [set(token, color)]],
|
|
3184
|
+
};
|
|
2468
3185
|
}
|
|
2469
3186
|
|
|
2470
3187
|
/**
|
|
@@ -2538,7 +3255,22 @@ export function draftAnswer(ctx, env, question) {
|
|
|
2538
3255
|
options: [[a], [b]],
|
|
2539
3256
|
});
|
|
2540
3257
|
} else if (last.size > 1 && clauses.length > 1) {
|
|
2541
|
-
|
|
3258
|
+
// The page never takes the color the text takes in the same mode.
|
|
3259
|
+
const all = [...last.values()]
|
|
3260
|
+
.map(x => x.step)
|
|
3261
|
+
.filter(
|
|
3262
|
+
(st, i, list) =>
|
|
3263
|
+
!(
|
|
3264
|
+
st.thing === '--color-background-body' &&
|
|
3265
|
+
list.some(
|
|
3266
|
+
t =>
|
|
3267
|
+
t.thing === '--color-text-primary' &&
|
|
3268
|
+
String(t.value).toLowerCase() ===
|
|
3269
|
+
String(st.value).toLowerCase() &&
|
|
3270
|
+
(!t.mode || !st.mode || t.mode === st.mode),
|
|
3271
|
+
)
|
|
3272
|
+
),
|
|
3273
|
+
);
|
|
2542
3274
|
result.push({
|
|
2543
3275
|
text:
|
|
2544
3276
|
all.length > MAX_STEPS
|
|
@@ -2555,20 +3287,69 @@ export function draftAnswer(ctx, env, question) {
|
|
|
2555
3287
|
/**
|
|
2556
3288
|
* A font a clause names: a preset, an open font, or a family written with
|
|
2557
3289
|
* capitals in the question.
|
|
2558
|
-
* @param {string}
|
|
3290
|
+
* @param {{text: string, quoted?: string[]}} cl the clause, lower-case
|
|
2559
3291
|
* @param {string} question the question as typed
|
|
2560
3292
|
*/
|
|
2561
|
-
function fontIn(
|
|
3293
|
+
function fontIn(cl, question) {
|
|
3294
|
+
const c = cl.text.replace(/\bsanz\b/g, 'sans');
|
|
3295
|
+
// A family written in quotes, as typed: a shipped font when it names one.
|
|
3296
|
+
for (const name of cl.quoted ?? []) {
|
|
3297
|
+
const low = name.toLowerCase();
|
|
3298
|
+
const slug =
|
|
3299
|
+
Object.keys(OPEN_FONTS).find(
|
|
3300
|
+
k =>
|
|
3301
|
+
OPEN_FONTS[k].family.toLowerCase() === low ||
|
|
3302
|
+
k === low.replace(/\s+/g, '-'),
|
|
3303
|
+
) ??
|
|
3304
|
+
Object.keys(FONTS).find(
|
|
3305
|
+
k => k === low || FONTS[k][0].toLowerCase() === low,
|
|
3306
|
+
);
|
|
3307
|
+
return slug ?? name;
|
|
3308
|
+
}
|
|
3309
|
+
// A shipped font named in the clause, the longest name first, so "Geist
|
|
3310
|
+
// Mono" is not Geist and "DM Sans" is not the generic sans.
|
|
3311
|
+
const shipped = [...Object.keys(OPEN_FONTS), ...Object.keys(FONTS)].sort(
|
|
3312
|
+
(x, y) => y.length - x.length,
|
|
3313
|
+
);
|
|
3314
|
+
// The generic stacks are read last, so "sans-serif" is not "serif".
|
|
3315
|
+
const known = shipped.find(
|
|
3316
|
+
k =>
|
|
3317
|
+
!['system', 'serif', 'mono'].includes(k) &&
|
|
3318
|
+
new RegExp(`\\b${k.replace(/-/g, '[\\s-]')}\\b`).test(c),
|
|
3319
|
+
);
|
|
3320
|
+
// A name as typed, up to four words ("Source Sans 3", "Roboto Slab"):
|
|
3321
|
+
// after "use" or "font", or before "font"; one this clause names.
|
|
3322
|
+
const GENERIC =
|
|
3323
|
+
/^(a|an|the|my|our|this|that|any|some|same|another|different|new|nice|modern|bold|light|thin|heavy|big|small|serif|sans|sans-serif|mono|monospace|system|default|body|heading|headings|code|for|on|in)$/i;
|
|
3324
|
+
const NAME =
|
|
3325
|
+
"([A-Z][\\w-]*(?:'[\\w-]+)*(?: (?:[A-Z][\\w-]*(?:'[\\w-]+)*|\\d+)){0,3})";
|
|
3326
|
+
/** @type {string | undefined} */
|
|
3327
|
+
let typed;
|
|
3328
|
+
for (const re of [
|
|
3329
|
+
new RegExp(`\\b(?:[Uu]se|[Ff]ont|[Tt]ypeface)s?:?\\s+["']?${NAME}`, 'g'),
|
|
3330
|
+
new RegExp(`\\b${NAME}\\s+(?:font|typeface)\\b`, 'g'),
|
|
3331
|
+
]) {
|
|
3332
|
+
for (const m of question.matchAll(re)) {
|
|
3333
|
+
const name = m[1].replace(/ (Font|Typeface)$/, '');
|
|
3334
|
+
if (GENERIC.test(name.split(' ')[0])) continue;
|
|
3335
|
+
if (c.includes(name.toLowerCase())) {
|
|
3336
|
+
typed = name;
|
|
3337
|
+
break;
|
|
3338
|
+
}
|
|
3339
|
+
}
|
|
3340
|
+
if (typed) break;
|
|
3341
|
+
}
|
|
3342
|
+
// "Roboto Mono" is not Roboto: a longer typed name wins over a shipped
|
|
3343
|
+
// one inside it.
|
|
3344
|
+
if (
|
|
3345
|
+
typed &&
|
|
3346
|
+
(!known || typed.replace(/\s+/g, '-').toLowerCase().length > known.length)
|
|
3347
|
+
)
|
|
3348
|
+
return typed;
|
|
3349
|
+
if (known) return known;
|
|
2562
3350
|
if (/\bmono(space|spaced)?\b/.test(c)) return 'mono';
|
|
2563
3351
|
if (/\bsans(-serif)?\b/.test(c)) return 'system';
|
|
2564
3352
|
if (/\bserif\b/.test(c)) return 'serif';
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
if (new RegExp(`\\b${words}\\b`).test(c)) return k;
|
|
2568
|
-
}
|
|
2569
|
-
const typed =
|
|
2570
|
-
/\b(?:use|font|typeface)\s+["']?([A-Z][\w-]*(?: [A-Z][\w-]*)?)["']?/.exec(
|
|
2571
|
-
question,
|
|
2572
|
-
)?.[1];
|
|
2573
|
-
return typed ?? null;
|
|
3353
|
+
if (/\bsystem(-ui)?\b/.test(c)) return 'system';
|
|
3354
|
+
return null;
|
|
2574
3355
|
}
|