@astryxdesign/cli 0.7.18-canary.gfca8508 → 0.7.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +185 -19
- package/README.md +19 -19
- package/api/component/_adapter.d.mts +2 -1
- package/api/component/_adapter.mjs +2 -1
- package/api/docs/_adapter.d.mts +6 -5
- package/api/docs/_adapter.mjs +36 -5
- package/api/doctor/_adapter.d.mts +6 -3
- package/api/doctor/_adapter.mjs +13 -5
- package/api/doctor/doctor.mjs +2 -2
- package/api/doctor/font-packages.d.mts +36 -0
- package/api/doctor/font-packages.mjs +124 -0
- package/api/doctor/theme-checks.mjs +110 -49
- package/api/experimental.d.mts +0 -2
- package/api/experimental.mjs +0 -12
- package/api/icon/_adapter.d.mts +1 -1
- package/api/icon/_adapter.mjs +1 -0
- package/api/icon/_authoring.mjs +17 -8
- package/api/icon/_default-look.mjs +15 -15
- package/api/icon/add/add.mjs +9 -4
- package/api/icon/exportIconIndex.doc.mjs +1 -1
- package/api/icon/icon.doc.mjs +1 -1
- package/api/icon/icon.type.d.mts +33 -33
- package/api/icon/icon.type.mjs +45 -45
- package/api/icon/iconAdd.doc.mjs +1 -1
- package/api/icon/iconNewSet.doc.mjs +3 -3
- package/api/icon/iconUse.doc.mjs +5 -5
- package/api/icon/rankIconIndex.doc.mjs +1 -1
- package/api/icon/use/use.mjs +4 -4
- package/api/init/run/run.mjs +0 -1
- package/api/integration/add-helpers.mjs +1 -1
- package/api/render/_adapter.mjs +7 -1
- package/api/search/ORDERING.md +1 -1
- package/api/search/_candidate-score.mjs +20 -0
- package/api/search/_words.d.mts +8 -0
- package/api/search/_words.mjs +15 -0
- package/api/template/template.type.d.mts +2 -2
- package/api/template/template.type.mjs +2 -2
- package/api/theme/_adapter.mjs +19 -11
- package/api/theme/build/build.d.mts +19 -51
- package/api/theme/build/build.mjs +195 -189
- package/api/theme/build/font-warning.d.mts +19 -2
- package/api/theme/build/font-warning.mjs +46 -5
- package/api/theme/generateTonalPalette.doc.mjs +1 -1
- package/api/theme/palette/generate/derive-look.mjs +108 -37
- package/api/theme/palette/generate/mapping.mjs +2 -0
- package/api/theme/template/template.d.mts +0 -17
- package/api/theme/template/template.mjs +1 -42
- package/api/theme/theme.type.d.mts +5 -4
- package/api/theme/theme.type.mjs +5 -4
- package/api/theme/themePaletteGenerate.doc.mjs +1 -1
- package/api/theme/themeRemove.doc.mjs +1 -1
- package/assets/codemods/transforms/v0.7.0/preserve-bottom-sheet-content-padding.mjs +3 -1
- package/assets/component-list.generated.json +1 -1
- package/assets/discover/official-packages.json +26 -2
- package/assets/docs/author-a-theme.doc.mjs +6 -5
- package/assets/docs/browser-support.doc.mjs +1 -0
- package/assets/docs/icons.doc.mjs +8 -7
- package/assets/docs/motion.doc.mjs +46 -0
- package/assets/docs/theme.doc.dense.mjs +6 -17
- package/assets/docs/theme.doc.mjs +6 -16
- package/assets/docs/theme.doc.zh.mjs +6 -16
- package/assets/docs/tree/ci-and-containers.doc.mjs +1 -1
- package/assets/docs/tree/font-setup.doc.mjs +30 -0
- package/assets/docs/tree/icon-sets.doc.mjs +1 -1
- package/assets/docs/tree/template-icons.doc.mjs +3 -3
- package/assets/docs/tree/tokens-color.doc.mjs +5 -0
- package/assets/docs/tree/tokens.doc.mjs +4 -3
- package/assets/docs/tree/updates.doc.mjs +1 -1
- package/assets/docs-routes.generated.json +1 -1
- package/assets/docs.generated.json +2 -2
- package/assets/icons/definitions/drag.doc.mjs +1 -0
- package/assets/search-catalog.generated.json +2 -2
- package/assets/self-audit.generated.json +1 -1
- package/assets/templates/blocks/components/Card/SelectableCardElevated.doc.mjs +1 -1
- package/assets/templates/blocks/components/Card/SelectableCardElevated.tsx +20 -10
- package/assets/templates/blocks/components/Card/SelectableCardShowcase.doc.mjs +1 -1
- package/assets/templates/blocks/components/Card/SelectableCardShowcase.tsx +36 -16
- package/assets/templates/blocks/components/ChatComposerInput/ChatComposerInputMentionTrigger.tsx +6 -0
- package/assets/templates/blocks/components/ChatComposerInput/ChatComposerInputMultipleTriggers.tsx +6 -0
- package/assets/templates/blocks/components/Hooks/useIndicatorFocusRingHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Hooks/useIndicatorFocusRingHookUsage.tsx +63 -0
- package/assets/templates/blocks/components/Hooks/useLongPressHookUsage.doc.mjs +29 -0
- package/assets/templates/blocks/components/Hooks/useLongPressHookUsage.tsx +237 -0
- package/assets/templates/blocks/components/SideNav/SideNavShowcase.tsx +10 -72
- package/assets/templates/blocks/components/SideNav/SideNavWithHeaderMenu.doc.mjs +1 -1
- package/assets/templates/blocks/components/SideNav/SideNavWithHeaderMenu.tsx +7 -7
- package/assets/templates/blocks/components/Table/TableCustomRowTable.doc.mjs +14 -0
- package/assets/templates/blocks/components/Table/TableCustomRowTable.tsx +96 -0
- package/assets/templates/components.generated.json +1 -1
- package/assets/templates/pages/ai-chat-landing/page.tsx +4 -0
- package/assets/templates/pages/dashboard-scorecard/page.tsx +26 -7
- package/assets/templates/pages/editor/page.tsx +13 -3
- package/assets/templates/themes/butter/butterPaletteRefs.generated.ts +2 -2
- package/assets/templates/themes/butter/butterTheme.ts +12 -10
- package/assets/templates/themes/butter/icons.tsx +2 -0
- package/assets/templates/themes/chocolate/chocolateTheme.ts +1 -0
- package/assets/templates/themes/chocolate/icons.tsx +2 -0
- package/assets/templates/themes/gothic/gothicPaletteRefs.generated.ts +1 -1
- package/assets/templates/themes/gothic/gothicTheme.ts +1 -0
- package/assets/templates/themes/gothic/icons.tsx +2 -0
- package/assets/templates/themes/matcha/icons.tsx +2 -0
- package/assets/templates/themes/matcha/matchaPaletteRefs.generated.ts +2 -2
- package/assets/templates/themes/matcha/matchaTheme.ts +1 -0
- package/assets/templates/themes/neutral/icons.tsx +2 -0
- package/assets/templates/themes/neutral/neutralPaletteRefs.generated.ts +2 -2
- package/assets/templates/themes/neutral/neutralTheme.ts +1 -0
- package/assets/templates/themes/stone/icons.tsx +2 -0
- package/assets/templates/themes/stone/stonePaletteRefs.generated.ts +1 -1
- package/assets/templates/themes/stone/stoneTheme.ts +1 -0
- package/assets/templates/themes/y2k/icons.tsx +2 -0
- package/assets/templates/themes/y2k/y2kTheme.ts +1 -0
- package/assets/theme.template.ts +9 -5
- package/authoring/config/parse.mjs +1 -1
- package/authoring/doctypes/base/type.ts +2 -3
- package/authoring/doctypes/component/component.doc.mjs +1 -1
- package/authoring/doctypes/icon-set/icon-names.mjs +1 -0
- package/authoring/integration/integration.doc.mjs +1 -1
- package/authoring/integration/type.ts +1 -1
- package/clients/cli/build-id.generated.json +1 -1
- package/clients/cli/commands/experimental/icon.mjs +7 -7
- package/clients/cli/commands/experimental/index.mjs +0 -5
- package/clients/cli/commands/experimental-icon-new-set.doc.mjs +2 -2
- package/clients/cli/commands/experimental-icon-use.doc.mjs +4 -4
- package/clients/cli/commands/experimental-icon.doc.mjs +1 -1
- package/clients/cli/commands/experimental.doc.mjs +2 -6
- package/clients/cli/commands/template.mjs +1 -1
- package/clients/cli/commands/theme-build.doc.mjs +8 -1
- package/clients/cli/commands/theme-palette-generate.doc.mjs +1 -1
- package/clients/cli/commands/theme-remove.doc.mjs +1 -1
- package/clients/cli/commands/theme.doc.mjs +1 -11
- package/clients/cli/commands/theme.mjs +110 -475
- package/clients/cli/commands.generated.json +1 -1
- package/clients/cli/index.mjs +4 -34
- package/clients/cli/lib/base-gate.mjs +2 -3
- package/clients/cli/lib/cli-error.mjs +8 -72
- package/clients/cli/lib/define-command.mjs +0 -19
- package/clients/cli/lib/json-shim.mjs +11 -633
- package/clients/cli/lib/manifest.mjs +0 -4
- package/clients/cli/lib/stray-option.mjs +1 -2
- package/clients/cli/manifest.generated.json +1 -1
- package/foundation/agent-docs/agent-docs.mjs +1 -1
- package/foundation/color/css-color.mjs +2 -3
- package/foundation/discovery/app-layout.d.mts +13 -0
- package/foundation/discovery/app-layout.mjs +35 -0
- package/foundation/discovery/fixture-refs.d.mts +51 -0
- package/foundation/discovery/fixture-refs.mjs +351 -0
- package/foundation/discovery/icon-definition-discovery.mjs +1 -1
- package/foundation/discovery/icon-ranking.mjs +2 -2
- package/foundation/discovery/icon-set-checks.mjs +1 -1
- package/foundation/discovery/icon-set-discovery.mjs +1 -1
- package/foundation/discovery/icon-set-writer.d.mts +24 -7
- package/foundation/discovery/icon-set-writer.mjs +66 -22
- package/foundation/discovery/static-descriptor.d.mts +49 -0
- package/foundation/discovery/static-descriptor.mjs +548 -0
- package/foundation/discovery/template-adapter.d.mts +0 -47
- package/foundation/discovery/template-adapter.mjs +1 -333
- package/foundation/discovery/theme-discovery.d.mts +6 -47
- package/foundation/discovery/theme-discovery.mjs +15 -537
- package/foundation/doc-compiler/import.mjs +1 -1
- package/foundation/env/user-dirs.d.mts +5 -2
- package/foundation/env/user-dirs.mjs +12 -5
- package/foundation/fonts/next-font.d.mts +26 -0
- package/foundation/fonts/next-font.mjs +149 -0
- package/foundation/fs/empty-folder.mjs +2 -2
- package/foundation/fs/read-record.mjs +11 -4
- package/foundation/pictures/pictures.d.mts +1 -45
- package/foundation/pictures/pictures.mjs +8 -8
- package/foundation/release/folder-lock.mjs +3 -2
- package/foundation/render/cut-short.d.mts +2 -2
- package/foundation/render/cut-short.mjs +2 -2
- package/foundation/render/drawn-contrast.d.mts +2 -2
- package/foundation/render/drawn-contrast.mjs +2 -2
- package/foundation/render/font-probe.d.mts +2 -2
- package/foundation/render/font-probe.mjs +2 -2
- package/foundation/render/layers.mjs +1 -2
- package/foundation/render/package-resolve-hooks.d.mts +25 -5
- package/foundation/render/package-resolve-hooks.mjs +77 -14
- package/foundation/render/page-worker.mjs +24 -12
- package/foundation/render/part-boxes.d.mts +2 -3
- package/foundation/render/part-boxes.mjs +2 -3
- package/foundation/render/picture-chrome.mjs +5 -0
- package/foundation/render/render-page.d.mts +1 -1
- package/foundation/render/render-page.mjs +4 -5
- package/foundation/render/single-copy-hooks.d.mts +2 -0
- package/foundation/render/single-copy-hooks.mjs +2 -0
- package/foundation/response/error-codes.doc.mjs +14 -14
- package/foundation/response/error-codes.mjs +13 -13
- package/foundation/response/response-types.doc.mjs +7 -68
- package/foundation/runtime/css-tree.mjs +2 -2
- package/foundation/runtime/word-table.d.mts +1 -1
- package/foundation/runtime/word-table.mjs +1 -1
- package/foundation/suggest/other-command.d.mts +52 -15
- package/foundation/suggest/other-command.mjs +168 -45
- package/foundation/text/suggest-order.d.mts +7 -0
- package/foundation/text/suggest-order.mjs +1 -1
- package/package.json +7 -8
- package/api/theme-edit/_adapter.d.mts +0 -228
- package/api/theme-edit/_adapter.mjs +0 -2025
- package/api/theme-edit/_catalog.d.mts +0 -172
- package/api/theme-edit/_catalog.mjs +0 -806
- package/api/theme-edit/_check.d.mts +0 -391
- package/api/theme-edit/_check.mjs +0 -9370
- package/api/theme-edit/_color.d.mts +0 -135
- package/api/theme-edit/_color.mjs +0 -480
- package/api/theme-edit/_compiler.d.mts +0 -77
- package/api/theme-edit/_compiler.mjs +0 -1053
- package/api/theme-edit/_context.d.mts +0 -399
- package/api/theme-edit/_context.mjs +0 -1778
- package/api/theme-edit/_css.d.mts +0 -169
- package/api/theme-edit/_css.mjs +0 -1167
- package/api/theme-edit/_edit.d.mts +0 -167
- package/api/theme-edit/_edit.mjs +0 -11220
- package/api/theme-edit/_how-commands.d.mts +0 -315
- package/api/theme-edit/_how-commands.mjs +0 -1664
- package/api/theme-edit/_how-question.d.mts +0 -341
- package/api/theme-edit/_how-question.mjs +0 -33339
- package/api/theme-edit/_how-sides.d.mts +0 -22
- package/api/theme-edit/_how-sides.mjs +0 -173
- package/api/theme-edit/_how-steps.d.mts +0 -42
- package/api/theme-edit/_how-steps.mjs +0 -208
- package/api/theme-edit/_how-values.d.mts +0 -29
- package/api/theme-edit/_how-values.mjs +0 -111
- package/api/theme-edit/_how-words.d.mts +0 -15
- package/api/theme-edit/_how-words.mjs +0 -239
- package/api/theme-edit/_how.d.mts +0 -55
- package/api/theme-edit/_how.mjs +0 -2388
- package/api/theme-edit/_importers.d.mts +0 -38
- package/api/theme-edit/_importers.mjs +0 -188
- package/api/theme-edit/_marks.d.mts +0 -39
- package/api/theme-edit/_marks.mjs +0 -67
- package/api/theme-edit/_missed.d.mts +0 -56
- package/api/theme-edit/_missed.mjs +0 -1128
- package/api/theme-edit/_name-rule.d.mts +0 -11
- package/api/theme-edit/_name-rule.mjs +0 -12
- package/api/theme-edit/_normal.d.mts +0 -365
- package/api/theme-edit/_normal.mjs +0 -1978
- package/api/theme-edit/_overview.d.mts +0 -9
- package/api/theme-edit/_overview.mjs +0 -293
- package/api/theme-edit/_palette.d.mts +0 -616
- package/api/theme-edit/_palette.mjs +0 -2776
- package/api/theme-edit/_part-pieces.d.mts +0 -54
- package/api/theme-edit/_part-pieces.mjs +0 -179
- package/api/theme-edit/_part-words.d.mts +0 -39
- package/api/theme-edit/_part-words.mjs +0 -242
- package/api/theme-edit/_parts.d.mts +0 -402
- package/api/theme-edit/_parts.mjs +0 -2322
- package/api/theme-edit/_picture-traits.d.mts +0 -259
- package/api/theme-edit/_picture-traits.mjs +0 -1030
- package/api/theme-edit/_png.d.mts +0 -94
- package/api/theme-edit/_png.mjs +0 -479
- package/api/theme-edit/_preview-app.d.mts +0 -172
- package/api/theme-edit/_preview-app.mjs +0 -6430
- package/api/theme-edit/_preview.d.mts +0 -484
- package/api/theme-edit/_preview.mjs +0 -2775
- package/api/theme-edit/_project.d.mts +0 -207
- package/api/theme-edit/_project.mjs +0 -643
- package/api/theme-edit/_resolved.d.mts +0 -46
- package/api/theme-edit/_resolved.mjs +0 -800
- package/api/theme-edit/_set-line.d.mts +0 -29
- package/api/theme-edit/_set-line.mjs +0 -100
- package/api/theme-edit/_settings.d.mts +0 -2426
- package/api/theme-edit/_settings.mjs +0 -18449
- package/api/theme-edit/_tables.d.mts +0 -227
- package/api/theme-edit/_tables.mjs +0 -1128
- package/api/theme-edit/_text-looks.d.mts +0 -78
- package/api/theme-edit/_text-looks.mjs +0 -376
- package/api/theme-edit/_vet.d.mts +0 -50
- package/api/theme-edit/_vet.mjs +0 -166
- package/api/theme-edit/how/how.d.mts +0 -17
- package/api/theme-edit/how/how.mjs +0 -28
- package/api/theme-edit/new/new.d.mts +0 -11
- package/api/theme-edit/new/new.mjs +0 -22
- package/api/theme-edit/preview-add/preview-add.d.mts +0 -14
- package/api/theme-edit/preview-add/preview-add.mjs +0 -25
- package/api/theme-edit/preview-app/preview-app.d.mts +0 -13
- package/api/theme-edit/preview-app/preview-app.mjs +0 -24
- package/api/theme-edit/preview-list/preview-list.d.mts +0 -10
- package/api/theme-edit/preview-list/preview-list.mjs +0 -21
- package/api/theme-edit/preview-remove/preview-remove.d.mts +0 -12
- package/api/theme-edit/preview-remove/preview-remove.mjs +0 -23
- package/api/theme-edit/set/set.d.mts +0 -13
- package/api/theme-edit/set/set.mjs +0 -24
- package/api/theme-edit/show/show.d.mts +0 -13
- package/api/theme-edit/show/show.mjs +0 -24
- package/api/theme-edit/theme-edit.d.mts +0 -12
- package/api/theme-edit/theme-edit.mjs +0 -36
- package/api/theme-edit/theme-edit.type.d.mts +0 -730
- package/api/theme-edit/theme-edit.type.mjs +0 -342
- package/api/theme-edit/themeEditHow.doc.d.mts +0 -6
- package/api/theme-edit/themeEditHow.doc.mjs +0 -105
- package/api/theme-edit/themeEditNew.doc.d.mts +0 -5
- package/api/theme-edit/themeEditNew.doc.mjs +0 -112
- package/api/theme-edit/themeEditPreviewAdd.doc.d.mts +0 -6
- package/api/theme-edit/themeEditPreviewAdd.doc.mjs +0 -121
- package/api/theme-edit/themeEditPreviewApp.doc.d.mts +0 -6
- package/api/theme-edit/themeEditPreviewApp.doc.mjs +0 -87
- package/api/theme-edit/themeEditPreviewList.doc.d.mts +0 -6
- package/api/theme-edit/themeEditPreviewList.doc.mjs +0 -62
- package/api/theme-edit/themeEditPreviewRemove.doc.d.mts +0 -6
- package/api/theme-edit/themeEditPreviewRemove.doc.mjs +0 -96
- package/api/theme-edit/themeEditSet.doc.d.mts +0 -6
- package/api/theme-edit/themeEditSet.doc.mjs +0 -175
- package/api/theme-edit/themeEditShow.doc.d.mts +0 -6
- package/api/theme-edit/themeEditShow.doc.mjs +0 -118
- package/api/theme-edit/themeEditUndo.doc.d.mts +0 -6
- package/api/theme-edit/themeEditUndo.doc.mjs +0 -133
- package/api/theme-edit/undo/undo.d.mts +0 -13
- package/api/theme-edit/undo/undo.mjs +0 -24
- package/assets/preview-app/README.md +0 -6
- package/assets/preview-app/css.d.ts +0 -5
- package/assets/preview-app/gitignore +0 -4
- package/assets/preview-app/next.config.mjs +0 -12
- package/assets/preview-app/package.json +0 -24
- package/assets/preview-app/src/app/globals.css +0 -6
- package/assets/preview-app/src/app/layout.tsx +0 -21
- package/assets/preview-app/src/app/page.tsx +0 -94
- package/assets/preview-app/src/app/providers.tsx +0 -16
- package/assets/preview-app/tsconfig.json +0 -27
- package/clients/cli/commands/experimental/theme.mjs +0 -2990
- package/clients/cli/commands/experimental-theme-add.doc.mjs +0 -80
- package/clients/cli/commands/experimental-theme-compile.doc.mjs +0 -98
- package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +0 -196
- package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +0 -174
- package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +0 -139
- package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +0 -77
- package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +0 -105
- package/clients/cli/commands/experimental-theme-editor.doc.mjs +0 -49
- package/clients/cli/commands/experimental-theme-eject.doc.mjs +0 -72
- package/clients/cli/commands/experimental-theme-list.doc.mjs +0 -49
- package/clients/cli/commands/experimental-theme-preview-add.doc.mjs +0 -88
- package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +0 -61
- package/clients/cli/commands/experimental-theme-preview-list.doc.mjs +0 -48
- package/clients/cli/commands/experimental-theme-preview-remove.doc.mjs +0 -59
- package/clients/cli/commands/experimental-theme-preview.doc.mjs +0 -41
- package/clients/cli/commands/experimental-theme-remove.doc.mjs +0 -57
- package/clients/cli/commands/experimental-theme-targets.doc.mjs +0 -62
- package/clients/cli/commands/experimental-theme-template.doc.mjs +0 -63
- package/clients/cli/commands/experimental-theme-use.doc.mjs +0 -57
- package/clients/cli/commands/experimental-theme.doc.mjs +0 -60
- package/foundation/fonts/fontsource-families.generated.d.mts +0 -5
- package/foundation/fonts/fontsource-families.generated.mjs +0 -2110
package/api/theme-edit/_how.mjs
DELETED
|
@@ -1,2388 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @file The lookup behind `astryx experimental theme editor how`: a part, a
|
|
5
|
-
* group, a setting, an aspect, a plain-words question, a PNG picture's
|
|
6
|
-
* colors, or a list of what a change can name. Every command it suggests is
|
|
7
|
-
* written for the user's theme, safe to paste into a shell, and checked as
|
|
8
|
-
* `set` checks it, so it is accepted and changes the theme.
|
|
9
|
-
*
|
|
10
|
-
* @position api/theme-edit — imported only by _adapter.mjs
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import * as fs from 'node:fs';
|
|
14
|
-
import * as path from 'node:path';
|
|
15
|
-
import {AstryxError} from '../error.mjs';
|
|
16
|
-
import {cssProperties} from './_css.mjs';
|
|
17
|
-
import {
|
|
18
|
-
AUTO_SPREAD,
|
|
19
|
-
COLOR_PROPS,
|
|
20
|
-
COMMON_PROPERTIES,
|
|
21
|
-
DIALS,
|
|
22
|
-
FAMILIES,
|
|
23
|
-
GROUPS,
|
|
24
|
-
HOW,
|
|
25
|
-
LIKE,
|
|
26
|
-
P,
|
|
27
|
-
familyOf,
|
|
28
|
-
pageColorNote,
|
|
29
|
-
} from './_tables.mjs';
|
|
30
|
-
import {colorsAt, decodePng, mainColors} from './_png.mjs';
|
|
31
|
-
import {pixelScale, readTraits} from './_picture-traits.mjs';
|
|
32
|
-
import {baseInstalled, installLine} from './_project.mjs';
|
|
33
|
-
import {
|
|
34
|
-
editedThemes,
|
|
35
|
-
loadTheme,
|
|
36
|
-
nearest,
|
|
37
|
-
partComponentDocs,
|
|
38
|
-
partStates,
|
|
39
|
-
ARIA_STATES,
|
|
40
|
-
refuse,
|
|
41
|
-
resolvedTokens,
|
|
42
|
-
themeSourceParseError,
|
|
43
|
-
themeSourceProblem,
|
|
44
|
-
baseRedraws,
|
|
45
|
-
groupsOf,
|
|
46
|
-
selfSizedBox,
|
|
47
|
-
selfSizedBoxLines,
|
|
48
|
-
selfSizedWhy,
|
|
49
|
-
sizesItsOwnBox,
|
|
50
|
-
} from './_settings.mjs';
|
|
51
|
-
import {missedSteps} from './_missed.mjs';
|
|
52
|
-
import {ASPECTS, settableStates} from './_check.mjs';
|
|
53
|
-
import {MODAL} from './_compiler.mjs';
|
|
54
|
-
import {PALETTE_DIALS, mappingRows, paletteFiles} from './_palette.mjs';
|
|
55
|
-
import {requireProject, context} from './_context.mjs';
|
|
56
|
-
import {checked, exampleStep, howTheme, render} from './_how-commands.mjs';
|
|
57
|
-
import {draftAnswer, partLexicon} from './_how-question.mjs';
|
|
58
|
-
import {valueAsked} from './_how-values.mjs';
|
|
59
|
-
import {
|
|
60
|
-
getCliInvocation,
|
|
61
|
-
quoteCommandArgument,
|
|
62
|
-
} from '../../foundation/env/package-manager.mjs';
|
|
63
|
-
import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
|
|
64
|
-
|
|
65
|
-
const E = ERROR_CODES;
|
|
66
|
-
|
|
67
|
-
/** What `how --list` takes. */
|
|
68
|
-
const HOW_LISTS = ['dials', 'tokens', 'parts', 'groups', 'properties'];
|
|
69
|
-
|
|
70
|
-
/** The most points one `--at` reads. */
|
|
71
|
-
const MAX_POINTS = 1000;
|
|
72
|
-
|
|
73
|
-
/** The in-app preview, whose Colors page shows every shade. */
|
|
74
|
-
const PREVIEW = 'astryx experimental theme preview';
|
|
75
|
-
|
|
76
|
-
/** Picture formats people try that are not PNG, by their first bytes. */
|
|
77
|
-
const OTHER_FORMATS = /** @type {Array<[string, number[]]>} */ ([
|
|
78
|
-
['JPEG', [0xff, 0xd8, 0xff]],
|
|
79
|
-
['GIF', [0x47, 0x49, 0x46, 0x38]],
|
|
80
|
-
['WebP', [0x52, 0x49, 0x46, 0x46]],
|
|
81
|
-
['BMP', [0x42, 0x4d]],
|
|
82
|
-
]);
|
|
83
|
-
|
|
84
|
-
/** File names that are pictures, whatever their format. */
|
|
85
|
-
const PICTURE_NAME = /\.(png|jpe?g|gif|webp|bmp|avif|heic|tiff?|svg)$/i;
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Whether a subject names a picture: a picture file name, or a file that
|
|
89
|
-
* exists.
|
|
90
|
-
* @param {string} subject
|
|
91
|
-
* @param {string} cwd
|
|
92
|
-
*/
|
|
93
|
-
export function isPicture(subject, cwd) {
|
|
94
|
-
if (!subject) return false;
|
|
95
|
-
// A file that exists is a picture whatever its name: macOS names every
|
|
96
|
-
// screenshot "Screenshot … at 1.23.45 PM.png".
|
|
97
|
-
try {
|
|
98
|
-
if (fs.statSync(path.resolve(cwd, subject.trim())).isFile()) return true;
|
|
99
|
-
} catch {
|
|
100
|
-
// Not a file here.
|
|
101
|
-
}
|
|
102
|
-
return !/\s/.test(subject.trim()) && PICTURE_NAME.test(subject);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* A dial's help, with what `set` does now where that differs from it: Core
|
|
107
|
-
* gives headings the body family when the theme names no heading family,
|
|
108
|
-
* so `font --on body` moves headings too.
|
|
109
|
-
* @param {string} key
|
|
110
|
-
* @param {{bodyFontReachesHeadings: boolean}} env
|
|
111
|
-
*/
|
|
112
|
-
function dialHelp(key, env) {
|
|
113
|
-
return key === 'font' && env.bodyFontReachesHeadings
|
|
114
|
-
? `${DIALS.font.help} Note: font --on body also sets the heading font while the theme sets no heading font; for body text alone, set --font-family-body.`
|
|
115
|
-
: DIALS[key].help;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Explain anything a theme change can name, or answer a question about one:
|
|
120
|
-
* a part (what it reads for each aspect, under which `--when` or `--state`,
|
|
121
|
-
* its variants, states and the parts inside it), a group (its members), a
|
|
122
|
-
* setting (a dial's rungs, a token's type and readers, a CSS property), an
|
|
123
|
-
* aspect (text, corners...: the whole-theme tokens and dial), `colors` (how
|
|
124
|
-
* the theme's colors are made), a plain-words question (exact commands), a
|
|
125
|
-
* PNG picture (its main colors and the look's traits measured from it, or the color at points), or with `list` a
|
|
126
|
-
* list of dials, tokens, parts, groups or CSS properties.
|
|
127
|
-
* @experimental
|
|
128
|
-
* @param {string} subject a part, group, setting, aspect, question, or PNG file; with `list`, a filter
|
|
129
|
-
* @param {import('./theme-edit.type.mjs').ThemeEditHowOptions} [options]
|
|
130
|
-
* @returns {Promise<import('./theme-edit.type.mjs').ThemeEditHowResponse>}
|
|
131
|
-
*/
|
|
132
|
-
export async function themeEditHow(subject, options = {}) {
|
|
133
|
-
const {cwd = process.cwd()} = options;
|
|
134
|
-
requireProject(cwd);
|
|
135
|
-
try {
|
|
136
|
-
if (options.words) {
|
|
137
|
-
// The words as typed: a picture first takes only a count after it;
|
|
138
|
-
// anything else is one subject.
|
|
139
|
-
const words = options.words;
|
|
140
|
-
const picture = isPicture(words[0] ?? '', cwd);
|
|
141
|
-
const again = `${HOW} ${quoteCommandArgument(words[0] ?? '')} 5`;
|
|
142
|
-
if (picture && words.length > 2)
|
|
143
|
-
throw new AstryxError(
|
|
144
|
-
`After a picture, give only how many colors to list, not "${words.slice(1).join(' ')}".`,
|
|
145
|
-
[{name: again, reason: 'do this instead'}],
|
|
146
|
-
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
147
|
-
);
|
|
148
|
-
// A missing picture is the first thing to say, before a bad count.
|
|
149
|
-
if (
|
|
150
|
-
picture &&
|
|
151
|
-
words.length === 2 &&
|
|
152
|
-
!/^[1-9]\d*$/.test(words[1]) &&
|
|
153
|
-
fs.existsSync(path.resolve(cwd, words[0]))
|
|
154
|
-
)
|
|
155
|
-
throw new AstryxError(
|
|
156
|
-
`The count after a picture must be a positive whole number, not "${words[1]}".`,
|
|
157
|
-
[{name: again, reason: 'do this instead'}],
|
|
158
|
-
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
159
|
-
);
|
|
160
|
-
subject = picture ? words[0] : words.join(' ');
|
|
161
|
-
if (picture && words.length === 2)
|
|
162
|
-
options = {...options, count: Number(words[1])};
|
|
163
|
-
}
|
|
164
|
-
const data = await answer(subject, options, cwd);
|
|
165
|
-
return {type: 'themeEdit.how', data: withPrefix(data, cwd)};
|
|
166
|
-
} catch (e) {
|
|
167
|
-
// A refusal's commands start the same way as an answer's.
|
|
168
|
-
if (e instanceof AstryxError && e.suggestions)
|
|
169
|
-
e.suggestions = withPrefix(e.suggestions, cwd);
|
|
170
|
-
throw e;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* Every command in the answer starts the way this project runs the CLI,
|
|
176
|
-
* the same in JSON as in text.
|
|
177
|
-
* @template T
|
|
178
|
-
* @param {T} value
|
|
179
|
-
* @param {string} cwd
|
|
180
|
-
* @returns {T}
|
|
181
|
-
*/
|
|
182
|
-
function withPrefix(value, cwd) {
|
|
183
|
-
const cli = getCliInvocation(cwd);
|
|
184
|
-
if (cli === 'astryx') return value;
|
|
185
|
-
// (A line may name the stable theme commands too, "astryx theme add
|
|
186
|
-
// neutral"; each runs as the app runs the CLI.)
|
|
187
|
-
/** @param {any} v @returns {any} */
|
|
188
|
-
const walk = v =>
|
|
189
|
-
typeof v === 'string'
|
|
190
|
-
? v.replace(/\bastryx (experimental theme|theme)\b/g, `${cli} $1`)
|
|
191
|
-
: Array.isArray(v)
|
|
192
|
-
? v.map(walk)
|
|
193
|
-
: v && typeof v === 'object'
|
|
194
|
-
? Object.fromEntries(Object.entries(v).map(([k, x]) => [k, walk(x)]))
|
|
195
|
-
: v;
|
|
196
|
-
return walk(value);
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* @param {string} subject
|
|
201
|
-
* @param {import('./theme-edit.type.mjs').ThemeEditHowOptions} options
|
|
202
|
-
* @param {string} cwd
|
|
203
|
-
* @param {boolean} [blindSaid] the color-blind pieces were answered
|
|
204
|
-
* already: the rest is asked as said, never split for them again
|
|
205
|
-
* @returns {Promise<import('./theme-edit.type.mjs').ThemeEditHowResponse['data']>}
|
|
206
|
-
*/
|
|
207
|
-
async function answer(subject, options, cwd, blindSaid = false) {
|
|
208
|
-
const {list, at = [], count} = options;
|
|
209
|
-
// "½rem": a fraction is a number before anything reads the question.
|
|
210
|
-
const t = (subject ?? '')
|
|
211
|
-
.trim()
|
|
212
|
-
// "corners:", "var(--radius-element)": a setting pasted as written is
|
|
213
|
-
// a lookup of it.
|
|
214
|
-
.replace(/^([a-z][a-z -]*):\s*$/i, '$1')
|
|
215
|
-
.replace(/^var\(\s*(--[a-z0-9-]+)\s*\)$/i, '$1')
|
|
216
|
-
// A lone "½" with no unit after it is a share of now ("card padding
|
|
217
|
-
// ½"), never 0.5px.
|
|
218
|
-
.replace(
|
|
219
|
-
/(\d*)(?:½|1\u20442)(?!\s*(?:rem|px|em|%|x\b|×|times\b))/g,
|
|
220
|
-
(_, n) => (n ? `${n}½` : ' half '),
|
|
221
|
-
)
|
|
222
|
-
.replace(/(\d*)(?:½|1\u20442)/g, (_, n) => `${n ? Number(n) + 0.5 : '0.5'}`)
|
|
223
|
-
.replace(
|
|
224
|
-
/(\d*)(?:¼|1\u20444)/g,
|
|
225
|
-
(_, n) => `${n ? Number(n) + 0.25 : '0.25'}`,
|
|
226
|
-
)
|
|
227
|
-
.replace(
|
|
228
|
-
/(\d*)(?:¾|3\u20444)/g,
|
|
229
|
-
(_, n) => `${n ? Number(n) + 0.75 : '0.75'}`,
|
|
230
|
-
);
|
|
231
|
-
// "paddingLeft", "borderRadius": a property as JavaScript spells it is
|
|
232
|
-
// that CSS property, as set takes it.
|
|
233
|
-
if (/^[a-z]+(?:[A-Z][a-z]+)+$/.test(t)) {
|
|
234
|
-
const kebab = t.replace(/[A-Z]/g, ch => `-${ch.toLowerCase()}`);
|
|
235
|
-
if (cssProperties().has(kebab)) return answer(kebab, options, cwd);
|
|
236
|
-
}
|
|
237
|
-
// "explain spacing", "tell me about the accent": the lookup of what is
|
|
238
|
-
// named, never a change.
|
|
239
|
-
const explain =
|
|
240
|
-
/^(?:explain|describe|tell me about)\s+(?:the |my )?([a-z][a-z -]*?)\s*$/i.exec(
|
|
241
|
-
t,
|
|
242
|
-
);
|
|
243
|
-
if (explain && explain[1] !== t) return answer(explain[1], options, cwd);
|
|
244
|
-
// --theme names a theme whatever the subject, so a bad one is refused
|
|
245
|
-
// for a picture and a list too.
|
|
246
|
-
if (options.theme === '')
|
|
247
|
-
refuse(E.ERR_INVALID_ARGUMENT, '--theme was given no name.', {
|
|
248
|
-
run: [`${HOW} ${t ? JSON.stringify(t) : 'card'}`],
|
|
249
|
-
});
|
|
250
|
-
if (options.theme != null) {
|
|
251
|
-
try {
|
|
252
|
-
loadTheme(cwd, options.theme);
|
|
253
|
-
} catch (e) {
|
|
254
|
-
// A theme name near the one typed: the same question for it, never
|
|
255
|
-
// only `show` (the question is kept).
|
|
256
|
-
const err = /** @type {any} */ (e);
|
|
257
|
-
// (A name typed in another case or as a path too.)
|
|
258
|
-
if (err?.suggestions)
|
|
259
|
-
for (const s of err.suggestions) {
|
|
260
|
-
const near = / show ([a-z][a-z0-9-]*)$/.exec(
|
|
261
|
-
String(s.name ?? ''),
|
|
262
|
-
)?.[1];
|
|
263
|
-
if (near)
|
|
264
|
-
s.name = `${HOW} ${quoteCommandArgument(t || 'card')} --theme ${near}`;
|
|
265
|
-
}
|
|
266
|
-
throw e;
|
|
267
|
-
}
|
|
268
|
-
// A theme whose source no longer extends its settings takes no setting:
|
|
269
|
-
// an answer would suggest commands that cannot run.
|
|
270
|
-
const parseError = themeSourceParseError(cwd, options.theme);
|
|
271
|
-
const broken = parseError
|
|
272
|
-
? {
|
|
273
|
-
problem: parseError,
|
|
274
|
-
fix: `Fix themes/${options.theme}/${options.theme}.theme.ts.`,
|
|
275
|
-
}
|
|
276
|
-
: await themeSourceProblem(cwd, options.theme);
|
|
277
|
-
if (broken)
|
|
278
|
-
refuse(
|
|
279
|
-
E.ERR_THEME_INVALID,
|
|
280
|
-
`${broken.problem}, so settings cannot take effect and no command here would change the theme. ${broken.fix} Then ask again.`,
|
|
281
|
-
{run: [`${P} show ${options.theme}`]},
|
|
282
|
-
);
|
|
283
|
-
}
|
|
284
|
-
if (list != null) {
|
|
285
|
-
if (at.length)
|
|
286
|
-
refuse(
|
|
287
|
-
E.ERR_INVALID_ARGUMENT,
|
|
288
|
-
'--at reads a picture; --list lists names, so drop one of them.',
|
|
289
|
-
{run: [`${HOW} --list ${quoteCommandArgument(String(list))}`]},
|
|
290
|
-
);
|
|
291
|
-
const kind = listKind(list);
|
|
292
|
-
if (kind === 'kinds')
|
|
293
|
-
return {
|
|
294
|
-
kind: 'list',
|
|
295
|
-
subject: t,
|
|
296
|
-
list: 'kinds',
|
|
297
|
-
items: HOW_LISTS.map(name => ({
|
|
298
|
-
name,
|
|
299
|
-
example: `${HOW} --list ${name}`,
|
|
300
|
-
})),
|
|
301
|
-
};
|
|
302
|
-
return {kind: 'list', subject: t, ...(await listItems(kind, t, cwd))};
|
|
303
|
-
}
|
|
304
|
-
if (isPicture(t, cwd)) {
|
|
305
|
-
const {traits, ...read} = pictureColors(t, cwd, at, count);
|
|
306
|
-
if (!traits) return {kind: 'picture', subject: t, ...read};
|
|
307
|
-
return {
|
|
308
|
-
kind: 'picture',
|
|
309
|
-
subject: t,
|
|
310
|
-
...read,
|
|
311
|
-
...(await pictureLook(cwd, options.theme, traits)),
|
|
312
|
-
};
|
|
313
|
-
}
|
|
314
|
-
// What runs instead: the same subject without the picture option (a
|
|
315
|
-
// real command), never a made-up file name.
|
|
316
|
-
const without = t ? `${HOW} ${quoteCommandArgument(t)}` : `${HOW} --help`;
|
|
317
|
-
if (at.length)
|
|
318
|
-
refuse(
|
|
319
|
-
E.ERR_INVALID_ARGUMENT,
|
|
320
|
-
`--at reads the color at points of a PNG picture; name your picture first (${HOW} <your .png file> --at x,y).`,
|
|
321
|
-
{run: [without]},
|
|
322
|
-
);
|
|
323
|
-
if (count != null)
|
|
324
|
-
refuse(
|
|
325
|
-
E.ERR_INVALID_ARGUMENT,
|
|
326
|
-
`A count applies only to a picture (${HOW} <your .png file> 5).`,
|
|
327
|
-
{run: [without]},
|
|
328
|
-
);
|
|
329
|
-
if (!t) {
|
|
330
|
-
refuse(
|
|
331
|
-
E.ERR_MISSING_ARGUMENT,
|
|
332
|
-
'Name a part, a group, a setting, an aspect, a question in quotes, or a PNG picture.',
|
|
333
|
-
{
|
|
334
|
-
run: [
|
|
335
|
-
`${HOW} card`,
|
|
336
|
-
`${HOW} "white text in the banner"`,
|
|
337
|
-
`${HOW} --list dials`,
|
|
338
|
-
],
|
|
339
|
-
},
|
|
340
|
-
);
|
|
341
|
-
}
|
|
342
|
-
// "how b make buttons pill": a first word typed as its own argument that
|
|
343
|
-
// names an existing theme, with more words after it, is the theme, as for
|
|
344
|
-
// set, show and undo. A quoted question ("how 'accent red'") is one
|
|
345
|
-
// argument: its first word is never a theme.
|
|
346
|
-
const argv = /** @type {string[] | undefined} */ (options.words);
|
|
347
|
-
if (
|
|
348
|
-
!options.theme &&
|
|
349
|
-
argv &&
|
|
350
|
-
argv.length >= 2 &&
|
|
351
|
-
editedThemes(cwd).includes(argv[0])
|
|
352
|
-
)
|
|
353
|
-
return answer(
|
|
354
|
-
argv.slice(1).join(' '),
|
|
355
|
-
{...options, words: undefined, theme: argv[0]},
|
|
356
|
-
cwd,
|
|
357
|
-
);
|
|
358
|
-
const ctx = await context(cwd);
|
|
359
|
-
const {C} = ctx;
|
|
360
|
-
const env = await howTheme(ctx, cwd, options.theme);
|
|
361
|
-
// Without part data, what each part reads is unknown: answers that need
|
|
362
|
-
// it say so instead of reporting nothing read.
|
|
363
|
-
const unknown = ctx.unchecked
|
|
364
|
-
? {notChecked: {code: E.ERR_THEME_NOT_CHECKED, cause: ctx.unchecked}}
|
|
365
|
-
: {};
|
|
366
|
-
const themeFields = {
|
|
367
|
-
theme: env.slug,
|
|
368
|
-
themeChosenBy: env.chosenBy,
|
|
369
|
-
...(env.note ? {themeNote: env.note} : {}),
|
|
370
|
-
};
|
|
371
|
-
/**
|
|
372
|
-
* Dial examples as commands for the theme, each checked.
|
|
373
|
-
* @param {string} dial
|
|
374
|
-
*/
|
|
375
|
-
const dialCommands = dial =>
|
|
376
|
-
checked(
|
|
377
|
-
env,
|
|
378
|
-
DIALS[dial].examples
|
|
379
|
-
.map(exampleStep)
|
|
380
|
-
.filter(st => st != null)
|
|
381
|
-
.map(st => [/** @type {import('./_how-commands.mjs').Step} */ (st)]),
|
|
382
|
-
).commands;
|
|
383
|
-
const key = lookupKey(t, ctx);
|
|
384
|
-
// A list's name alone ("dials", "tokens") is that list.
|
|
385
|
-
if (/^(dials?|tokens?|parts?|groups?|propert(y|ies))$/.test(key)) {
|
|
386
|
-
const kind = listKind(key);
|
|
387
|
-
return {kind: 'list', subject: '', ...(await listItems(kind, '', cwd))};
|
|
388
|
-
}
|
|
389
|
-
if (Object.hasOwn(groupsOf(ctx), key)) {
|
|
390
|
-
return {
|
|
391
|
-
kind: 'group',
|
|
392
|
-
subject: t,
|
|
393
|
-
group: key,
|
|
394
|
-
members: groupsOf(ctx)[key],
|
|
395
|
-
spreads: AUTO_SPREAD.includes(key),
|
|
396
|
-
};
|
|
397
|
-
}
|
|
398
|
-
if (ctx.project.target.has(key))
|
|
399
|
-
return partAnswer(ctx, env, t, key, unknown, themeFields);
|
|
400
|
-
if (key === 'colors' || key === 'palette')
|
|
401
|
-
return {
|
|
402
|
-
kind: 'aspect',
|
|
403
|
-
subject: t,
|
|
404
|
-
...themeFields,
|
|
405
|
-
results: [
|
|
406
|
-
...colorsAnswer(env, dialCommands),
|
|
407
|
-
...['text', 'background', 'border'].flatMap(a =>
|
|
408
|
-
wholeThemeTokens(ctx, env, a),
|
|
409
|
-
),
|
|
410
|
-
],
|
|
411
|
-
};
|
|
412
|
-
if (ASPECTS.includes(key)) {
|
|
413
|
-
const results = wholeThemeTokens(ctx, env, key);
|
|
414
|
-
const dial = /** @type {Record<string, string>} */ ({
|
|
415
|
-
corners: 'corners',
|
|
416
|
-
spacing: 'spacing',
|
|
417
|
-
font: 'font',
|
|
418
|
-
size: 'text-size',
|
|
419
|
-
shadow: 'surfaces',
|
|
420
|
-
border: 'surfaces',
|
|
421
|
-
})[key];
|
|
422
|
-
if (key === 'text' || key === 'background')
|
|
423
|
-
results.unshift(
|
|
424
|
-
...['accent', 'neutral'].map(d => ({
|
|
425
|
-
text: dialHelp(d, env),
|
|
426
|
-
commands: dialCommands(d),
|
|
427
|
-
})),
|
|
428
|
-
);
|
|
429
|
-
if (dial)
|
|
430
|
-
results.unshift({
|
|
431
|
-
text: dialHelp(dial, env),
|
|
432
|
-
commands: dialCommands(dial),
|
|
433
|
-
});
|
|
434
|
-
results.push({
|
|
435
|
-
text: `for one part: ${HOW} <part> lists what it reads for ${key}`,
|
|
436
|
-
commands: [`${HOW} button`],
|
|
437
|
-
});
|
|
438
|
-
return {kind: 'aspect', subject: t, ...themeFields, results};
|
|
439
|
-
}
|
|
440
|
-
if (Object.hasOwn(DIALS, key)) {
|
|
441
|
-
const d = DIALS[key];
|
|
442
|
-
// A base is named only when it is installed here; the others are
|
|
443
|
-
// listed with the line that installs them.
|
|
444
|
-
const installed = (/** @type {string} */ b) =>
|
|
445
|
-
baseInstalled(ctx.project, b);
|
|
446
|
-
const missing = key === 'base' ? LIKE.filter(b => !installed(b)) : [];
|
|
447
|
-
return {
|
|
448
|
-
kind: 'setting',
|
|
449
|
-
subject: t,
|
|
450
|
-
source: 'dial',
|
|
451
|
-
values:
|
|
452
|
-
key === 'base'
|
|
453
|
-
? [...LIKE.filter(installed), 'none'].join('|')
|
|
454
|
-
: d.values,
|
|
455
|
-
help:
|
|
456
|
-
dialHelp(key, env) +
|
|
457
|
-
(missing.length
|
|
458
|
-
? ` Not installed here: ${missing.join(', ')} (${installLine(
|
|
459
|
-
ctx.project.cwd,
|
|
460
|
-
missing.map(b => `@astryxdesign/theme-${b}`),
|
|
461
|
-
)}).`
|
|
462
|
-
: ''),
|
|
463
|
-
...(PALETTE_DIALS.includes(key) ? {shades: mappingRows(key)} : {}),
|
|
464
|
-
...themeFields,
|
|
465
|
-
examples: dialCommands(key),
|
|
466
|
-
};
|
|
467
|
-
}
|
|
468
|
-
if (
|
|
469
|
-
key.startsWith('--') &&
|
|
470
|
-
Object.hasOwn(ctx.project.core.tokenDefaults, key)
|
|
471
|
-
)
|
|
472
|
-
return tokenAnswer(ctx, env, t, key, unknown, themeFields);
|
|
473
|
-
if (cssProperties().has(key)) {
|
|
474
|
-
const setters = Object.keys(C.MAP).filter(p => key in C.MAP[p].own);
|
|
475
|
-
const value = exampleForProperty(key);
|
|
476
|
-
const {commands, refused} = value
|
|
477
|
-
? checked(
|
|
478
|
-
env,
|
|
479
|
-
setters
|
|
480
|
-
.slice(0, 3)
|
|
481
|
-
.map(on => [
|
|
482
|
-
{verb: /** @type {'set'} */ ('set'), thing: key, value, on},
|
|
483
|
-
]),
|
|
484
|
-
)
|
|
485
|
-
: {commands: [], refused: []};
|
|
486
|
-
return {
|
|
487
|
-
kind: 'setting',
|
|
488
|
-
subject: t,
|
|
489
|
-
source: 'property',
|
|
490
|
-
setBy: setters,
|
|
491
|
-
...unknown,
|
|
492
|
-
...themeFields,
|
|
493
|
-
examples: commands.slice(0, 1),
|
|
494
|
-
...(refused.length && !commands.length
|
|
495
|
-
? {refused: refused.slice(0, 2)}
|
|
496
|
-
: {}),
|
|
497
|
-
};
|
|
498
|
-
}
|
|
499
|
-
// "What does --color-accent do", "what's the variable for card padding":
|
|
500
|
-
// "--focus-outline-width: 3px": a token typed with a value is set exactly,
|
|
501
|
-
// or refused with the nearest names; never another token.
|
|
502
|
-
// "cards: --color-border red", "--color-border red on inputs": the token
|
|
503
|
-
// on that part.
|
|
504
|
-
const scopeLead = /^\s*([a-z][a-z -]*?)\s*:\s*(?=--)/i.exec(t)?.[1];
|
|
505
|
-
const scopeTail =
|
|
506
|
-
/\s+(?:on|for)\s+(?:the |my |all )?([a-z][a-z -]*?)\s*$/i.exec(t)?.[1];
|
|
507
|
-
const scopeWord = scopeLead ?? scopeTail;
|
|
508
|
-
const scopeOn = scopeWord
|
|
509
|
-
? (() => {
|
|
510
|
-
const w = ` ${scopeWord.trim().toLowerCase()} `;
|
|
511
|
-
return (
|
|
512
|
-
partLexicon(ctx).parts.find(([re]) => re.test(w))?.[1].on ?? null
|
|
513
|
-
);
|
|
514
|
-
})()
|
|
515
|
-
: null;
|
|
516
|
-
const typedToken =
|
|
517
|
-
/^\s*(--[a-z][a-z0-9-]*)\s*(?::|\s+to\s+|\s+)\s*([^;]+?)\s*;?\s*(?:\bin (light|dark) mode\b.*)?$/i.exec(
|
|
518
|
-
t
|
|
519
|
-
.replace(/^\s*(?:change|set|make|token)\s+/i, ' ')
|
|
520
|
-
.replace(/^\s*[a-z][a-z -]*?\s*:\s*(?=--)/i, ' ')
|
|
521
|
-
.replace(
|
|
522
|
-
scopeOn && scopeTail
|
|
523
|
-
? /\s+(?:on|for)\s+(?:the |my |all )?[a-z][a-z -]*?\s*$/i
|
|
524
|
-
: /$^/,
|
|
525
|
-
'',
|
|
526
|
-
),
|
|
527
|
-
);
|
|
528
|
-
if (
|
|
529
|
-
typedToken &&
|
|
530
|
-
(Object.hasOwn(
|
|
531
|
-
ctx.project.core.tokenDefaults,
|
|
532
|
-
typedToken[1].toLowerCase(),
|
|
533
|
-
) ||
|
|
534
|
-
nearest(
|
|
535
|
-
typedToken[1].toLowerCase(),
|
|
536
|
-
Object.keys(ctx.project.core.tokenDefaults),
|
|
537
|
-
).length > 0) &&
|
|
538
|
-
!/^--(on|when|state|mode|theme|list|at)$/.test(typedToken[1]) &&
|
|
539
|
-
// "what does --color-accent do" is a lookup.
|
|
540
|
-
!/^\s*(what|which|where|how|is|are|does|do|explain|why)\b/i.test(t) &&
|
|
541
|
-
!/^(do|does|mean|means|for|control|controls)\b/i.test(
|
|
542
|
-
typedToken[2].trim(),
|
|
543
|
-
) &&
|
|
544
|
-
// "--color-accent darker", "--a and --b bigger": a way to move it (or
|
|
545
|
-
// more tokens), never a value: the question reader answers it.
|
|
546
|
-
!/^(?:and\s+--|(?:a bit |slightly )?(?:darker|lighter|bigger|larger|smaller|thicker|thinner|wider|narrower)(?:$|\s+(?:and|,)))/i.test(
|
|
547
|
-
typedToken[2].trim(),
|
|
548
|
-
)
|
|
549
|
-
) {
|
|
550
|
-
const token = typedToken[1].toLowerCase();
|
|
551
|
-
const mode = /\bin (light|dark) mode\b/i.exec(t)?.[1]?.toLowerCase();
|
|
552
|
-
const defaults = ctx.project.core.tokenDefaults;
|
|
553
|
-
const near = nearest(token, Object.keys(defaults));
|
|
554
|
-
// A token that does not exist is refused with the nearest real names;
|
|
555
|
-
// a flag-like word with none near is read as words.
|
|
556
|
-
if (!Object.hasOwn(defaults, token) && near.length)
|
|
557
|
-
return refuse(E.ERR_INVALID_ARGUMENT, `There is no token ${token}.`, {
|
|
558
|
-
run: near.map(k => `${HOW} ${k}`),
|
|
559
|
-
});
|
|
560
|
-
// Quotes come off only when the whole value is one quoted string: a
|
|
561
|
-
// font stack keeps its quoted family.
|
|
562
|
-
const typedValue = typedToken[2].trim();
|
|
563
|
-
const value = /^(["'])([^"']*)\1$/.test(typedValue)
|
|
564
|
-
? typedValue.slice(1, -1)
|
|
565
|
-
: typedValue;
|
|
566
|
-
const {commands, refused} = checked(env, [
|
|
567
|
-
[
|
|
568
|
-
{
|
|
569
|
-
verb: 'set',
|
|
570
|
-
thing: token,
|
|
571
|
-
value,
|
|
572
|
-
...(scopeOn ? {on: scopeOn} : {}),
|
|
573
|
-
...(mode && env.data.mode === 'both' ? {mode} : {}),
|
|
574
|
-
},
|
|
575
|
-
],
|
|
576
|
-
]);
|
|
577
|
-
return {
|
|
578
|
-
kind: 'question',
|
|
579
|
-
subject: t,
|
|
580
|
-
understood: {parts: [], aspects: []},
|
|
581
|
-
...themeFields,
|
|
582
|
-
results: [
|
|
583
|
-
{
|
|
584
|
-
text: commands.length
|
|
585
|
-
? `the token ${token}, as you wrote it`
|
|
586
|
-
: `${token} ${value}: ${refused[0]?.why ?? 'no command does it'}`,
|
|
587
|
-
commands,
|
|
588
|
-
...(refused.length ? {refused} : {}),
|
|
589
|
-
},
|
|
590
|
-
],
|
|
591
|
-
...unknown,
|
|
592
|
-
};
|
|
593
|
-
}
|
|
594
|
-
// A question about the tool itself gets the command that answers it.
|
|
595
|
-
const tool = toolAnswer(t, env, ctx.project.target);
|
|
596
|
-
if (tool === 'list') {
|
|
597
|
-
const kind =
|
|
598
|
-
/\b(dials?|tokens?|parts?|groups?|properties|property)\b/i
|
|
599
|
-
.exec(t)?.[1]
|
|
600
|
-
?.toLowerCase() ?? 'kinds';
|
|
601
|
-
return answer('', {...options, list: kind}, cwd);
|
|
602
|
-
}
|
|
603
|
-
// (Color-blind readers asked about in a list of asks: the other pieces
|
|
604
|
-
// are answered as typed, in their case and order, and the color-blind
|
|
605
|
-
// answer follows them, before the first offer, as every answer does.)
|
|
606
|
-
const blind = blindSaid
|
|
607
|
-
? {blind: false, rest: ''}
|
|
608
|
-
: colorBlindPieces(t.trim().replace(/[?.!]+$/, ''));
|
|
609
|
-
if (!tool && blind.blind && blind.rest) {
|
|
610
|
-
const rest = await answer(blind.rest, options, cwd, true);
|
|
611
|
-
const results = rest.results ?? [];
|
|
612
|
-
const firstOffer = results.findIndex(r => r.offer);
|
|
613
|
-
const at = firstOffer < 0 ? results.length : firstOffer;
|
|
614
|
-
return {
|
|
615
|
-
...rest,
|
|
616
|
-
subject: t,
|
|
617
|
-
results: [
|
|
618
|
-
...results.slice(0, at),
|
|
619
|
-
...colorBlindAnswer(env),
|
|
620
|
-
...results.slice(at),
|
|
621
|
-
],
|
|
622
|
-
};
|
|
623
|
-
}
|
|
624
|
-
if (tool)
|
|
625
|
-
return {
|
|
626
|
-
kind: 'question',
|
|
627
|
-
subject: t,
|
|
628
|
-
understood: {parts: [], aspects: []},
|
|
629
|
-
...themeFields,
|
|
630
|
-
results: tool,
|
|
631
|
-
...unknown,
|
|
632
|
-
};
|
|
633
|
-
// a question about what something is gets the lookup, not a change; a
|
|
634
|
-
// question about a part's value now gets the value (draftAnswer).
|
|
635
|
-
if (
|
|
636
|
-
!valueAsked(t) &&
|
|
637
|
-
(/^\s*(what|which|where)\b.*\b(variables?|tokens?|do|does|means?|controls?|for)\b|^\s*what('s| is) the (css )?(variable|token|property)/i.test(
|
|
638
|
-
t,
|
|
639
|
-
) ||
|
|
640
|
-
/^\s*(is there|are there|explain|what is|what's|what are)\b/i.test(t)) &&
|
|
641
|
-
!/\b(command|make|makes|set|change)\b/i.test(t)
|
|
642
|
-
) {
|
|
643
|
-
const tok = /--[a-z0-9-]+/i.exec(t)?.[0]?.toLowerCase();
|
|
644
|
-
if (tok && Object.hasOwn(ctx.project.core.tokenDefaults, tok))
|
|
645
|
-
return tokenAnswer(ctx, env, t, tok, unknown, themeFields);
|
|
646
|
-
// "what does spacing more do": the dial's own lookup, its values and
|
|
647
|
-
// what each does.
|
|
648
|
-
// ("in dark mode" names a mode to read, never the mode dial; a dial
|
|
649
|
-
// word that names a part's thing, "the focus ring of buttons", is the
|
|
650
|
-
// part's.)
|
|
651
|
-
const dial = Object.keys(DIALS).find(d =>
|
|
652
|
-
new RegExp(`\\b${d}\\b`, 'i').test(
|
|
653
|
-
t
|
|
654
|
-
.replace(/--[a-z0-9-]+/gi, ' ')
|
|
655
|
-
.replace(/\b(?:in|for)\s+(?:the\s+)?(?:dark|light)\s+mode\b/gi, ' '),
|
|
656
|
-
),
|
|
657
|
-
);
|
|
658
|
-
// (Asked as a question, its example lines are said, never offered to
|
|
659
|
-
// run: "what does spacing less do" asks what a change would do.)
|
|
660
|
-
if (dial && !/\b(on|for|of)\s+(the\s+)?[a-z]+s?\b/i.test(t)) {
|
|
661
|
-
const looked = await answer(dial, options, cwd);
|
|
662
|
-
const results = /** @type {any} */ (looked).results;
|
|
663
|
-
if (Array.isArray(results))
|
|
664
|
-
for (const r of results) {
|
|
665
|
-
const runs = r.commands.filter((/** @type {string} */ c) =>
|
|
666
|
-
/ editor (?:set|undo) /.test(c),
|
|
667
|
-
);
|
|
668
|
-
if (!runs.length) continue;
|
|
669
|
-
r.text += ` (for example: ${runs.map((/** @type {string} */ c) => c.replace(/^.* editor (?:set|undo) \S+ /, '')).join('; ')})`;
|
|
670
|
-
r.commands = r.commands.filter(
|
|
671
|
-
(/** @type {string} */ c) => !runs.includes(c),
|
|
672
|
-
);
|
|
673
|
-
}
|
|
674
|
-
return {...looked, subject: t};
|
|
675
|
-
}
|
|
676
|
-
const q = draftAnswer(ctx, env, t);
|
|
677
|
-
const groups = q.aspects.filter(a => Object.hasOwn(GROUPS, a));
|
|
678
|
-
const results = q.parts
|
|
679
|
-
.map(p => (groupsOf(ctx)[p] ? groupsOf(ctx)[p][0] : p))
|
|
680
|
-
.filter(p => ctx.project.target.has(p))
|
|
681
|
-
.map(p => {
|
|
682
|
-
const toks = (groups.length ? groups : [null]).flatMap(g =>
|
|
683
|
-
C.partReads(p, g).map(r => r.token),
|
|
684
|
-
);
|
|
685
|
-
return {
|
|
686
|
-
text: toks.length
|
|
687
|
-
? `${p} reads ${[...new Set(toks)].slice(0, 6).join(', ')}${groups.length ? ` for ${groups.join(' and ')}` : ''}`
|
|
688
|
-
: `what ${p} reads`,
|
|
689
|
-
commands: [`${HOW} ${p}`],
|
|
690
|
-
};
|
|
691
|
-
});
|
|
692
|
-
if (results.length)
|
|
693
|
-
return {
|
|
694
|
-
kind: 'question',
|
|
695
|
-
subject: t,
|
|
696
|
-
understood: {parts: q.parts, aspects: q.aspects},
|
|
697
|
-
...themeFields,
|
|
698
|
-
results,
|
|
699
|
-
...unknown,
|
|
700
|
-
};
|
|
701
|
-
// "which token sets the page background?": the token the answer would
|
|
702
|
-
// set, looked up.
|
|
703
|
-
const token = q.parts.includes('page')
|
|
704
|
-
? '--color-background-body'
|
|
705
|
-
: q.drafts
|
|
706
|
-
.flatMap(d => d.options.flat())
|
|
707
|
-
.find(st => st.thing.startsWith('--'))?.thing;
|
|
708
|
-
if (token && Object.hasOwn(ctx.project.core.tokenDefaults, token))
|
|
709
|
-
return {
|
|
710
|
-
...tokenAnswer(ctx, env, token, token, unknown, themeFields),
|
|
711
|
-
subject: t,
|
|
712
|
-
};
|
|
713
|
-
}
|
|
714
|
-
// "<part> match the theme": the steps show's missed list has for that
|
|
715
|
-
// part (what the theme's own changes should have reached on it), checked
|
|
716
|
-
// as every answer is; a part they reached already is said so.
|
|
717
|
-
const matchAsk =
|
|
718
|
-
/\b(?:match(?:es|ing)?|fits?|follows?)\s+(?:the|my|this)\s+(?:theme|look)\b/i.exec(
|
|
719
|
-
t,
|
|
720
|
-
);
|
|
721
|
-
if (matchAsk && env.exists) {
|
|
722
|
-
const q = draftAnswer(ctx, env, t.replace(matchAsk[0], ' '));
|
|
723
|
-
const parts = q.parts.flatMap(p =>
|
|
724
|
-
groupsOf(ctx)[p]
|
|
725
|
-
? groupsOf(ctx)[p]
|
|
726
|
-
: ctx.project.target.has(p)
|
|
727
|
-
? [p]
|
|
728
|
-
: [],
|
|
729
|
-
);
|
|
730
|
-
if (parts.length) {
|
|
731
|
-
const res = await resolvedTokens(ctx, env.slug).catch(() => null);
|
|
732
|
-
const missed = res ? missedSteps(ctx, env.data, res, env.base) : [];
|
|
733
|
-
const mine = missed.filter(x => parts.includes(x.part));
|
|
734
|
-
const drafts = mine.length
|
|
735
|
-
? mine.map(x => ({
|
|
736
|
-
text: `${x.part}${x.state ? ` (${x.state})` : ''}: ${x.why}`,
|
|
737
|
-
options: [x.steps.map(st => ({verb: 'set', ...st}))],
|
|
738
|
-
...(x.steps.length > 1 ? {sequence: true} : {}),
|
|
739
|
-
}))
|
|
740
|
-
: [
|
|
741
|
-
{
|
|
742
|
-
text: `${[...new Set(parts)].join(', ')} ${parts.length > 1 ? 'follow' : 'follows'} ${env.slug}'s changes already: show's missed list has nothing for ${parts.length > 1 ? 'them' : 'it'}; to change ${parts.length > 1 ? 'them' : 'it'} anyway, ask for the change ("${parts[0]} background #f0f0f0")`,
|
|
743
|
-
options: [],
|
|
744
|
-
lookup: `${P} show ${env.slug}`,
|
|
745
|
-
},
|
|
746
|
-
];
|
|
747
|
-
return {
|
|
748
|
-
kind: 'question',
|
|
749
|
-
subject: t,
|
|
750
|
-
understood: {parts: q.parts, aspects: q.aspects},
|
|
751
|
-
...themeFields,
|
|
752
|
-
results: finish(env, /** @type {any} */ (drafts)),
|
|
753
|
-
...unknown,
|
|
754
|
-
};
|
|
755
|
-
}
|
|
756
|
-
}
|
|
757
|
-
const h = draftAnswer(ctx, env, t);
|
|
758
|
-
// The question guard: a question with no clause that asks for a change
|
|
759
|
-
// never writes. Decided once, for the whole question.
|
|
760
|
-
if (questionOnly(t))
|
|
761
|
-
for (const d of h.drafts)
|
|
762
|
-
if (d.options.some(o => o.length)) {
|
|
763
|
-
d.options = [];
|
|
764
|
-
d.text = `${d.text} (a question: nothing is changed; ask for the change to get its command)`;
|
|
765
|
-
}
|
|
766
|
-
// A part show's missed list has (a tooltip still on the base's dark
|
|
767
|
-
// surface), asked about for its look (its fill or text, or nothing more
|
|
768
|
-
// said: "tooltips grey like the rest"): the missed steps lead.
|
|
769
|
-
if (
|
|
770
|
-
env.exists &&
|
|
771
|
-
!questionOnly(t) &&
|
|
772
|
-
h.parts.length &&
|
|
773
|
-
(!h.aspects.length ||
|
|
774
|
-
h.aspects.some(a => a === 'background' || a === 'text'))
|
|
775
|
-
) {
|
|
776
|
-
const parts = h.parts.flatMap(p =>
|
|
777
|
-
groupsOf(ctx)[p]
|
|
778
|
-
? groupsOf(ctx)[p]
|
|
779
|
-
: ctx.project.target.has(p)
|
|
780
|
-
? [p]
|
|
781
|
-
: [],
|
|
782
|
-
);
|
|
783
|
-
const res = await resolvedTokens(ctx, env.slug).catch(() => null);
|
|
784
|
-
// (A missed entry never says otherwise than the question: where the
|
|
785
|
-
// question gives the part a fill or a text color, the missed list's
|
|
786
|
-
// fill or text for it is not offered, "tooltips #1f2328 with white
|
|
787
|
-
// text"; and where the question writes the part at all, its own
|
|
788
|
-
// answer leads and the missed list follows, "secondary buttons white
|
|
789
|
-
// …" before a disabled-primary entry.)
|
|
790
|
-
const asked = h.drafts.flatMap(d => d.options.flat());
|
|
791
|
-
/** @param {any} st */
|
|
792
|
-
const family = st =>
|
|
793
|
-
/^background(?:-color)?$|^--color-background-|^--color-[a-z]+-muted$/.test(
|
|
794
|
-
String(st.thing),
|
|
795
|
-
)
|
|
796
|
-
? 'fill'
|
|
797
|
-
: st.thing === 'color' || /^--color-(?:text|on)-/.test(String(st.thing))
|
|
798
|
-
? 'text'
|
|
799
|
-
: null;
|
|
800
|
-
// (An ask to match the rest, "tooltips grey like the rest", is the
|
|
801
|
-
// missed list's own ask: it leads.)
|
|
802
|
-
const matching =
|
|
803
|
-
/\b(?:like the rest|like everything else|match(?:es|ing)? the (?:theme|rest)|same as the rest)\b/i.test(
|
|
804
|
-
t,
|
|
805
|
-
);
|
|
806
|
-
const mine = (res ? missedSteps(ctx, env.data, res, env.base) : []).filter(
|
|
807
|
-
x =>
|
|
808
|
-
parts.includes(x.part) &&
|
|
809
|
-
x.steps.length &&
|
|
810
|
-
(matching ||
|
|
811
|
-
!x.steps.some(st => {
|
|
812
|
-
const f = family(st);
|
|
813
|
-
return (
|
|
814
|
-
f != null && asked.some(a => a.on === x.part && family(a) === f)
|
|
815
|
-
);
|
|
816
|
-
})),
|
|
817
|
-
);
|
|
818
|
-
const entries = /** @type {any[]} */ (
|
|
819
|
-
mine.map(x => ({
|
|
820
|
-
text: `${x.part}${x.state ? ` (${x.state})` : ''}: ${x.why} (show's missed list)`,
|
|
821
|
-
options: [x.steps.map(st => ({verb: 'set', ...st}))],
|
|
822
|
-
...(x.steps.length > 1 ? {sequence: true} : {}),
|
|
823
|
-
}))
|
|
824
|
-
);
|
|
825
|
-
const written = new Set(
|
|
826
|
-
matching ? [] : asked.map(a => a.on).filter(Boolean),
|
|
827
|
-
);
|
|
828
|
-
h.drafts.unshift(...entries.filter((_, k) => !written.has(mine[k].part)));
|
|
829
|
-
h.drafts.push(...entries.filter((_, k) => written.has(mine[k].part)));
|
|
830
|
-
}
|
|
831
|
-
const results = finish(env, h.drafts);
|
|
832
|
-
const empty = !results.some(r => r.commands.length);
|
|
833
|
-
const already = results.length > 0 && results.every(r => ALREADY.has(r));
|
|
834
|
-
return {
|
|
835
|
-
kind: 'question',
|
|
836
|
-
subject: t,
|
|
837
|
-
understood: {parts: h.parts, aspects: h.aspects},
|
|
838
|
-
...themeFields,
|
|
839
|
-
results,
|
|
840
|
-
...unknown,
|
|
841
|
-
...(empty && already
|
|
842
|
-
? {
|
|
843
|
-
hint: `"${t}" is already so in ${env.slug}: nothing to change. Each result says what it found.`,
|
|
844
|
-
}
|
|
845
|
-
: empty
|
|
846
|
-
? {
|
|
847
|
-
hint: `${
|
|
848
|
-
results.length
|
|
849
|
-
? `No command does all of "${t}" on ${env.slug}; each result says why.`
|
|
850
|
-
: `No match for "${t}". Name the part (header, nav links, card, button, banner, input...) and what to change (text color, background, gradient, corners, border, shadow, spacing, bold), in English.`
|
|
851
|
-
} See ${HOW} --help for the asks it understands.`,
|
|
852
|
-
run: [
|
|
853
|
-
`${HOW} --help`,
|
|
854
|
-
`${HOW} --list parts`,
|
|
855
|
-
`${HOW} "rounder buttons"`,
|
|
856
|
-
`${HOW} colors`,
|
|
857
|
-
],
|
|
858
|
-
}
|
|
859
|
-
: {}),
|
|
860
|
-
};
|
|
861
|
-
}
|
|
862
|
-
|
|
863
|
-
/**
|
|
864
|
-
* The commands a refusal names to run instead that answer the draft: the
|
|
865
|
-
* same thing set, accepted by set's check, and (for a draft that carries
|
|
866
|
-
* what its clause asks) measured to do it.
|
|
867
|
-
* @param {import('./_how-commands.mjs').HowTheme} env
|
|
868
|
-
* @param {import('./_how-question.mjs').Draft} d
|
|
869
|
-
* @param {Array<{command: string, why: string, run?: string[]}>} refused
|
|
870
|
-
* @returns {string[]}
|
|
871
|
-
*/
|
|
872
|
-
function insteadOf(env, d, refused) {
|
|
873
|
-
// (The same thing on the same part: another part is another ask.)
|
|
874
|
-
const things = new Set(
|
|
875
|
-
d.options.flat().map(st => `${st.thing}|${st.on ?? ''}`),
|
|
876
|
-
);
|
|
877
|
-
/** @type {string[]} */
|
|
878
|
-
const out = [];
|
|
879
|
-
for (const line of refused.flatMap(r => r.run ?? [])) {
|
|
880
|
-
const words = [
|
|
881
|
-
...line
|
|
882
|
-
.replace(/^.*? editor /, '')
|
|
883
|
-
.matchAll(/'((?:[^'\\]|\\.)*)'|"((?:[^"\\]|\\.)*)"|(\S+)/g),
|
|
884
|
-
].map(m => m[1] ?? m[2] ?? m[3]);
|
|
885
|
-
const st = exampleStep(
|
|
886
|
-
words.map(w => (/\s/.test(w) ? `"${w}"` : w)).join(' '),
|
|
887
|
-
);
|
|
888
|
-
if (
|
|
889
|
-
!st ||
|
|
890
|
-
!things.has(`${st.thing}|${st.on ?? ''}`) ||
|
|
891
|
-
/[<>]/.test(String(st.value ?? ''))
|
|
892
|
-
)
|
|
893
|
-
continue;
|
|
894
|
-
if (!env.check([st]).ok) continue;
|
|
895
|
-
// Held to what the draft asks, else to the way its own dial step went
|
|
896
|
-
// ("more"): never offered unmeasured.
|
|
897
|
-
const way = d.options
|
|
898
|
-
.flat()
|
|
899
|
-
.map(x => x.value)
|
|
900
|
-
.find(v => v === 'more' || v === 'less');
|
|
901
|
-
const intent =
|
|
902
|
-
d.intent ??
|
|
903
|
-
(way
|
|
904
|
-
? /** @type {import('./_how-commands.mjs').MeasureIntent} */ ({
|
|
905
|
-
families: [],
|
|
906
|
-
typed: [],
|
|
907
|
-
opacityDir: null,
|
|
908
|
-
dir: way,
|
|
909
|
-
zero: false,
|
|
910
|
-
lighter: null,
|
|
911
|
-
subjects: [],
|
|
912
|
-
keep: [],
|
|
913
|
-
mode: null,
|
|
914
|
-
})
|
|
915
|
-
: null);
|
|
916
|
-
if (!intent || typeof env.measure !== 'function') continue;
|
|
917
|
-
// A dial word the other way round from the one asked never answers it.
|
|
918
|
-
if (way && (st.value === 'more' || st.value === 'less') && st.value !== way)
|
|
919
|
-
continue;
|
|
920
|
-
if (env.measure([st], intent)) continue;
|
|
921
|
-
out.push(render(st, env.slug));
|
|
922
|
-
}
|
|
923
|
-
return out;
|
|
924
|
-
}
|
|
925
|
-
|
|
926
|
-
/**
|
|
927
|
-
* Whether a question only asks (how, what, which, is, does …) and has no
|
|
928
|
-
* clause that asks for a change: "how heavy is the text" asks; "how heavy
|
|
929
|
-
* are headings - set them bold", "what color is the page? make it white"
|
|
930
|
-
* and "can you make cards rounder?" ask for a change.
|
|
931
|
-
* @param {string} q
|
|
932
|
-
*/
|
|
933
|
-
export function questionOnly(q) {
|
|
934
|
-
const t = String(q).toLowerCase().trim();
|
|
935
|
-
// ("why not square buttons", "what about no borders": a suggestion is
|
|
936
|
-
// an ask.)
|
|
937
|
-
if (
|
|
938
|
-
!/^(?:how|what|what's|whats|which|is|are|does|do|did|why|where)\b/.test(
|
|
939
|
-
t,
|
|
940
|
-
) ||
|
|
941
|
-
/^(?:why not|what about|how about|what if)\b/.test(t) ||
|
|
942
|
-
// ("why are my headings not bold", "why is everything so round": a
|
|
943
|
-
// complaint is an ask.)
|
|
944
|
-
/^why\b.*\b(?:not|n'?t)\b/.test(t) ||
|
|
945
|
-
/^why (?:is|are)\b.*\bso [a-z]+\b/.test(t)
|
|
946
|
-
)
|
|
947
|
-
return false;
|
|
948
|
-
// A verb that asks for a change anywhere after the question's first
|
|
949
|
-
// word ("whats the padding on cards make it 12").
|
|
950
|
-
if (
|
|
951
|
-
/\s(?:make|set|turn|give|change|add|remove|put|round|darken|lighten|increase|decrease|bump|apply)\s+(?:it|them|this|that|the|all|every|my|our|\w+s)\b/.test(
|
|
952
|
-
t,
|
|
953
|
-
)
|
|
954
|
-
)
|
|
955
|
-
return false;
|
|
956
|
-
if (/\b(?:can|could|would|will) (?:you|we|i)\b/.test(t)) return false;
|
|
957
|
-
// A clause after the question that does not ask again ("… underline
|
|
958
|
-
// them", "… - set them bold") is the change it asks for.
|
|
959
|
-
const QUESTION_LEAD =
|
|
960
|
-
/^(?:how|what|what's|whats|which|is|are|does|do|did|why|where|who|it|its|it's|they|the|a|an|my|our|or|and|i|im|i'm|that|this)\b/;
|
|
961
|
-
return !t
|
|
962
|
-
.split(/[?;!.]+|\s[-–—]+\s|,\s*/)
|
|
963
|
-
.slice(1)
|
|
964
|
-
.some(seg => seg.trim() && !QUESTION_LEAD.test(seg.trim()));
|
|
965
|
-
}
|
|
966
|
-
|
|
967
|
-
/**
|
|
968
|
-
* The results that say the theme already does what was asked: when every
|
|
969
|
-
* result is one, the answer leads with that, never with a failure.
|
|
970
|
-
* @type {WeakSet<object>}
|
|
971
|
-
*/
|
|
972
|
-
const ALREADY = new WeakSet();
|
|
973
|
-
|
|
974
|
-
/**
|
|
975
|
-
* Check each draft's commands and keep what passes; a draft whose commands
|
|
976
|
-
* are all refused says why, and points to the lookup that helps.
|
|
977
|
-
* @param {import('./_how-commands.mjs').HowTheme} env
|
|
978
|
-
* @param {import('./_how-question.mjs').Draft[]} drafts
|
|
979
|
-
*/
|
|
980
|
-
function finish(env, drafts) {
|
|
981
|
-
/** @type {Array<{text: string, commands: string[], sequence?: boolean, refused?: Array<{command: string, why: string, run?: string[]}>, offer?: boolean}>} */
|
|
982
|
-
const out = [];
|
|
983
|
-
// The measured check runs first on the drafts that carry what their
|
|
984
|
-
// clause asks; a draft that joins them ("all of it, in order") then keeps
|
|
985
|
-
// only the steps some kept option still has, so it never brings back a
|
|
986
|
-
// step the check left out.
|
|
987
|
-
const key = (/** @type {import('./_how-commands.mjs').Step} */ st) =>
|
|
988
|
-
JSON.stringify([
|
|
989
|
-
st.verb,
|
|
990
|
-
st.thing,
|
|
991
|
-
st.value,
|
|
992
|
-
st.on,
|
|
993
|
-
st.when,
|
|
994
|
-
st.state,
|
|
995
|
-
st.mode,
|
|
996
|
-
]);
|
|
997
|
-
/** @type {Set<string>} */
|
|
998
|
-
const dropped = new Set();
|
|
999
|
-
/** @type {Set<string>} */
|
|
1000
|
-
const kept = new Set();
|
|
1001
|
-
/** @type {Map<object, string[]>} */
|
|
1002
|
-
const unmetOf = new Map();
|
|
1003
|
-
// ("…, and make headings bigger": where an answer's first line fails the
|
|
1004
|
-
// check and a later line of it passes, a joined answer takes that line
|
|
1005
|
-
// in its place, never drops the ask unsaid.)
|
|
1006
|
-
/** @type {Map<string, import('./_how-commands.mjs').Step[]>} */
|
|
1007
|
-
const joinsInstead = new Map();
|
|
1008
|
-
if (typeof env.measure === 'function')
|
|
1009
|
-
for (const d of drafts) {
|
|
1010
|
-
if (!d.intent) continue;
|
|
1011
|
-
const intent = d.intent;
|
|
1012
|
-
/** @type {string[]} */
|
|
1013
|
-
const unmet = [];
|
|
1014
|
-
const first = d.options[0];
|
|
1015
|
-
d.options = d.options.flatMap(o => {
|
|
1016
|
-
const why = env.measure(o, intent);
|
|
1017
|
-
if (why) {
|
|
1018
|
-
// A change written per mode that goes the wrong way in one mode
|
|
1019
|
-
// only ("warning text darker": the dark half lighter is what
|
|
1020
|
-
// darker means against a dark page): the other mode's half is
|
|
1021
|
-
// kept, and the dropped half is named.
|
|
1022
|
-
const modes = new Set(o.map(st => st.mode).filter(Boolean));
|
|
1023
|
-
if (modes.size === 2 && o.every(st => st.mode))
|
|
1024
|
-
for (const m of /** @type {const} */ (['light', 'dark'])) {
|
|
1025
|
-
const half = o.filter(st => st.mode !== m);
|
|
1026
|
-
if (env.measure(half, intent)) continue;
|
|
1027
|
-
for (const st of o) (st.mode === m ? dropped : kept).add(key(st));
|
|
1028
|
-
unmet.push(`${why}, so only the other mode is changed`);
|
|
1029
|
-
return [half];
|
|
1030
|
-
}
|
|
1031
|
-
}
|
|
1032
|
-
for (const st of o) (why ? dropped : kept).add(key(st));
|
|
1033
|
-
if (why) unmet.push(why);
|
|
1034
|
-
return why ? [] : [o];
|
|
1035
|
-
});
|
|
1036
|
-
if (first?.length === 1 && d.options.length && d.options[0] !== first)
|
|
1037
|
-
joinsInstead.set(key(first[0]), d.options[0]);
|
|
1038
|
-
// One change in growing amounts: the first kept is the answer, and
|
|
1039
|
-
// the smaller amounts that fell short are no reason to tell.
|
|
1040
|
-
if (d.smallest && d.options.length) {
|
|
1041
|
-
d.options = d.options.slice(0, 1);
|
|
1042
|
-
unmet.length = 0;
|
|
1043
|
-
}
|
|
1044
|
-
unmetOf.set(d, unmet);
|
|
1045
|
-
}
|
|
1046
|
-
for (const d of drafts) {
|
|
1047
|
-
if (!d.intent && dropped.size) {
|
|
1048
|
-
d.options = d.options
|
|
1049
|
-
.map(o =>
|
|
1050
|
-
o.flatMap(st =>
|
|
1051
|
-
!dropped.has(key(st)) || kept.has(key(st))
|
|
1052
|
-
? [st]
|
|
1053
|
-
: (joinsInstead.get(key(st)) ?? []),
|
|
1054
|
-
),
|
|
1055
|
-
)
|
|
1056
|
-
.filter(o => o.length);
|
|
1057
|
-
// A joined answer left holding what another answer already says is
|
|
1058
|
-
// that answer: it is not given twice (and never as "all of it").
|
|
1059
|
-
const same = (/** @type {import('./_how-commands.mjs').Step[]} */ o) =>
|
|
1060
|
-
drafts.some(
|
|
1061
|
-
x =>
|
|
1062
|
-
x !== d &&
|
|
1063
|
-
x.options.some(
|
|
1064
|
-
y =>
|
|
1065
|
-
y.length === o.length &&
|
|
1066
|
-
y.every((st, i) => key(st) === key(o[i])),
|
|
1067
|
-
),
|
|
1068
|
-
);
|
|
1069
|
-
if (d.options.length && d.options.every(same)) continue;
|
|
1070
|
-
}
|
|
1071
|
-
// The measured check: an option whose built result does not do what
|
|
1072
|
-
// the question asks is left out, with a plain line saying why.
|
|
1073
|
-
const unmet = unmetOf.get(d) ?? [];
|
|
1074
|
-
if (unmet.length) {
|
|
1075
|
-
if (unmet.length && !d.options.length)
|
|
1076
|
-
d.text = `couldn't work out a command that does "${d.text}" as asked: ${[...new Set(unmet)].join('; ')}`;
|
|
1077
|
-
else if (unmet.length)
|
|
1078
|
-
d.text = `${d.text} (left out: ${[...new Set(unmet)].join('; ')})`;
|
|
1079
|
-
}
|
|
1080
|
-
// A joined answer ("all of it, in order") drops each step that alone
|
|
1081
|
-
// changes nothing, as its own line says; written, it would pin that
|
|
1082
|
-
// setting, so a later dial would not reach it.
|
|
1083
|
-
if (d.sequence && d.options.some(o => o.length > 1)) {
|
|
1084
|
-
/** @param {import('./_how-commands.mjs').Step} st */
|
|
1085
|
-
const noOp = st => {
|
|
1086
|
-
const r = env.check([st]);
|
|
1087
|
-
return !r.ok && /^it changes nothing/.test(r.why);
|
|
1088
|
-
};
|
|
1089
|
-
const before = d.options.map(o => o.length);
|
|
1090
|
-
d.options = d.options
|
|
1091
|
-
.map(o => (o.length > 1 ? o.filter(st => !noOp(st)) : o))
|
|
1092
|
-
.filter(o => o.length);
|
|
1093
|
-
// (Left holding what another answer already says: not given twice.)
|
|
1094
|
-
const narrowed = d.options.some((o, i) => o.length < (before[i] ?? 0));
|
|
1095
|
-
if (
|
|
1096
|
-
narrowed &&
|
|
1097
|
-
d.options.every(o =>
|
|
1098
|
-
drafts.some(
|
|
1099
|
-
x =>
|
|
1100
|
-
x !== d &&
|
|
1101
|
-
x.options.some(
|
|
1102
|
-
y =>
|
|
1103
|
-
y.length === o.length &&
|
|
1104
|
-
y.every((st, k) => key(st) === key(o[k])),
|
|
1105
|
-
),
|
|
1106
|
-
),
|
|
1107
|
-
)
|
|
1108
|
-
)
|
|
1109
|
-
continue;
|
|
1110
|
-
}
|
|
1111
|
-
const {commands, refused} = checked(env, d.options);
|
|
1112
|
-
// (A choice whose options hold more than one step, a fill with the text
|
|
1113
|
-
// that reads on it: each option is one line, so a line is one whole
|
|
1114
|
-
// choice.)
|
|
1115
|
-
if (d.joined) {
|
|
1116
|
-
const whole = d.options
|
|
1117
|
-
.map(o => checked(env, [o]))
|
|
1118
|
-
.filter(r => r.commands.length && !r.refused.length)
|
|
1119
|
-
.map(r => r.commands.join(' && '));
|
|
1120
|
-
commands.splice(0, commands.length, ...whole);
|
|
1121
|
-
}
|
|
1122
|
-
const lookups = d.lookup ? [d.lookup] : [];
|
|
1123
|
-
// (The draft found it in place already: said, with no command.)
|
|
1124
|
-
if (d.already) {
|
|
1125
|
-
const r = {text: d.text, commands: lookups};
|
|
1126
|
-
ALREADY.add(r);
|
|
1127
|
-
out.push(r);
|
|
1128
|
-
continue;
|
|
1129
|
-
}
|
|
1130
|
-
if (!commands.length && !d.options.length && unmet.length) {
|
|
1131
|
-
out.push({text: d.text, commands: lookups});
|
|
1132
|
-
continue;
|
|
1133
|
-
}
|
|
1134
|
-
// (What the ask writes is in place already: said so, first, with no
|
|
1135
|
-
// command, so an offer beside it is never taken for the answer.)
|
|
1136
|
-
if (
|
|
1137
|
-
!commands.length &&
|
|
1138
|
-
d.options.length &&
|
|
1139
|
-
!d.offer &&
|
|
1140
|
-
refused.length &&
|
|
1141
|
-
refused.every(r => /^it changes nothing/.test(r.why))
|
|
1142
|
-
) {
|
|
1143
|
-
const steps = d.options[0];
|
|
1144
|
-
const values = [...new Set(steps.map(st => String(st.value)))];
|
|
1145
|
-
const parts = [...new Set(steps.map(st => st.on).filter(Boolean))];
|
|
1146
|
-
const r = {
|
|
1147
|
-
text: `already ${values.join(', ')}${parts.length ? ` on the ${parts.join(', ')}` : ''} in ${env.slug}, nothing to change (${d.text})`,
|
|
1148
|
-
commands: lookups,
|
|
1149
|
-
};
|
|
1150
|
-
ALREADY.add(r);
|
|
1151
|
-
out.push(r);
|
|
1152
|
-
continue;
|
|
1153
|
-
}
|
|
1154
|
-
if (!commands.length && d.options.length && !lookups.length) {
|
|
1155
|
-
out.push({
|
|
1156
|
-
text: `${d.text}: no command does it on ${env.slug}${refused[0] ? `: ${refused[0].why}` : ''}`,
|
|
1157
|
-
// The command the refusal itself names to run instead, when it
|
|
1158
|
-
// sets the same thing, passes set's check and does what the
|
|
1159
|
-
// question asks.
|
|
1160
|
-
commands: insteadOf(env, d, refused),
|
|
1161
|
-
refused,
|
|
1162
|
-
});
|
|
1163
|
-
continue;
|
|
1164
|
-
}
|
|
1165
|
-
out.push({
|
|
1166
|
-
text: d.text,
|
|
1167
|
-
commands: [...commands, ...lookups],
|
|
1168
|
-
...(d.sequence && commands.length ? {sequence: true} : {}),
|
|
1169
|
-
...(refused.length ? {refused} : {}),
|
|
1170
|
-
...(d.offer ? {offer: true} : {}),
|
|
1171
|
-
});
|
|
1172
|
-
}
|
|
1173
|
-
if (!env.exists && out.some(r => r.commands.some(c => / set /.test(c))))
|
|
1174
|
-
out.unshift({
|
|
1175
|
-
text: `the app has no theme yet: make ${env.slug} first`,
|
|
1176
|
-
commands: [`${P} new ${env.slug} --like ${env.data.like ?? 'neutral'}`],
|
|
1177
|
-
});
|
|
1178
|
-
const seen = new Set();
|
|
1179
|
-
// Changes first; a lookup ("how card") after the commands that change.
|
|
1180
|
-
const changes = (/** @type {{commands: string[]}} */ r) =>
|
|
1181
|
-
r.commands.some(c => / editor (set|undo|new) /.test(c)) ? 0 : 1;
|
|
1182
|
-
// An offer, more than the ask, is never first or the answer: it follows
|
|
1183
|
-
// every other result; left alone, a first line says the ask itself
|
|
1184
|
-
// writes nothing here.
|
|
1185
|
-
const offered = (/** @type {{offer?: boolean}} */ r) => (r.offer ? 1 : 0);
|
|
1186
|
-
// (Its words first, with no command: "the mode the app shows first is
|
|
1187
|
-
// set where it renders the theme"; the line it offers follows.)
|
|
1188
|
-
if (out.length && out.every(r => r.offer))
|
|
1189
|
-
out.unshift({text: out[0].text, commands: []});
|
|
1190
|
-
return out
|
|
1191
|
-
.sort((a, b) => offered(a) - offered(b) || changes(a) - changes(b))
|
|
1192
|
-
.filter(r => {
|
|
1193
|
-
const k = `${r.text}\n${r.commands.join('\n')}`;
|
|
1194
|
-
if (seen.has(k)) return false;
|
|
1195
|
-
seen.add(k);
|
|
1196
|
-
return true;
|
|
1197
|
-
})
|
|
1198
|
-
.slice(0, 10);
|
|
1199
|
-
}
|
|
1200
|
-
|
|
1201
|
-
/**
|
|
1202
|
-
* The key a lookup matches: lower case, without closing punctuation, a
|
|
1203
|
-
* plural part or aspect made singular, and a token name given its dashes.
|
|
1204
|
-
* @param {string} t
|
|
1205
|
-
* @param {import('./_settings.mjs').Ctx} ctx
|
|
1206
|
-
*/
|
|
1207
|
-
function lookupKey(t, ctx) {
|
|
1208
|
-
const k = t
|
|
1209
|
-
.toLowerCase()
|
|
1210
|
-
.replace(/[?.!]+$/, '')
|
|
1211
|
-
.trim();
|
|
1212
|
-
if (/\s/.test(k)) return t;
|
|
1213
|
-
const known = (/** @type {string} */ x) =>
|
|
1214
|
-
Object.hasOwn(groupsOf(ctx), x) ||
|
|
1215
|
-
ctx.project.target.has(x) ||
|
|
1216
|
-
ASPECTS.includes(x) ||
|
|
1217
|
-
Object.hasOwn(DIALS, x) ||
|
|
1218
|
-
cssProperties().has(x) ||
|
|
1219
|
-
x === 'colors' ||
|
|
1220
|
-
x === 'palette';
|
|
1221
|
-
if (known(k)) return k;
|
|
1222
|
-
const token = `--${k.replace(/^-+/, '')}`;
|
|
1223
|
-
if (Object.hasOwn(ctx.project.core.tokenDefaults, token)) return token;
|
|
1224
|
-
for (const x of [k.replace(/s$/, ''), k.replace(/es$/, ''), `${k}s`])
|
|
1225
|
-
if (x !== k && known(x)) return x;
|
|
1226
|
-
return t;
|
|
1227
|
-
}
|
|
1228
|
-
|
|
1229
|
-
/**
|
|
1230
|
-
* The answer for one part.
|
|
1231
|
-
* @param {import('./_settings.mjs').Ctx} ctx
|
|
1232
|
-
* @param {import('./_how-commands.mjs').HowTheme} env
|
|
1233
|
-
* @param {string} subject
|
|
1234
|
-
* @param {string} key
|
|
1235
|
-
* @param {object} unknown
|
|
1236
|
-
* @param {object} themeFields
|
|
1237
|
-
* @returns {import('./theme-edit.type.mjs').ThemeEditHowResponse['data']}
|
|
1238
|
-
*/
|
|
1239
|
-
function partAnswer(ctx, env, subject, key, unknown, themeFields) {
|
|
1240
|
-
const {C} = ctx;
|
|
1241
|
-
const target = /** @type {{component?: string, states: string[]}} */ (
|
|
1242
|
-
ctx.project.target.get(key)
|
|
1243
|
-
);
|
|
1244
|
-
const group = familyOf(key);
|
|
1245
|
-
const states = settableStates(ctx, env.slug, env.data, key);
|
|
1246
|
-
// A token the base theme points at another one on the part or a part
|
|
1247
|
-
// around it (neutral's progress track reads the muted fill, which it
|
|
1248
|
-
// points at the emphasized border there): that token is what it shows.
|
|
1249
|
-
const blocks =
|
|
1250
|
-
/** @type {{components?: Record<string, Record<string, Record<string, unknown>>>}} */ (
|
|
1251
|
-
env.base
|
|
1252
|
-
).components ?? {};
|
|
1253
|
-
const around = [
|
|
1254
|
-
key,
|
|
1255
|
-
...Object.keys(C.MAP).filter(t => C.MAP[t]?.contains?.includes(key)),
|
|
1256
|
-
];
|
|
1257
|
-
/** @param {string} token */
|
|
1258
|
-
const pointedAt = token => {
|
|
1259
|
-
for (const t of around) {
|
|
1260
|
-
const v = blocks[t]?.base?.[token];
|
|
1261
|
-
const to =
|
|
1262
|
-
typeof v === 'string'
|
|
1263
|
-
? /^var\(\s*(--[\w-]+)\s*\)$/.exec(v.trim())?.[1]
|
|
1264
|
-
: null;
|
|
1265
|
-
if (to) return {token: to, on: t};
|
|
1266
|
-
}
|
|
1267
|
-
return null;
|
|
1268
|
-
};
|
|
1269
|
-
const reads = Object.fromEntries(
|
|
1270
|
-
Object.keys(GROUPS).map(g => [
|
|
1271
|
-
g,
|
|
1272
|
-
C.partReads(key, g).map(r => {
|
|
1273
|
-
const to = r.token ? pointedAt(r.token) : null;
|
|
1274
|
-
return {
|
|
1275
|
-
token: r.token,
|
|
1276
|
-
...(to
|
|
1277
|
-
? {
|
|
1278
|
-
shows: `${to.token} (the ${env.data.like ?? 'base'} theme points ${r.token} at it on ${to.on})`,
|
|
1279
|
-
}
|
|
1280
|
-
: {}),
|
|
1281
|
-
props: r.props,
|
|
1282
|
-
when: [...new Set(r.when.map(w => condition(ctx, key, w, states)))],
|
|
1283
|
-
};
|
|
1284
|
-
}),
|
|
1285
|
-
]),
|
|
1286
|
-
);
|
|
1287
|
-
const components = [
|
|
1288
|
-
...new Set(
|
|
1289
|
-
ctx.project.targets.filter(x => x.key === key).map(x => x.component),
|
|
1290
|
-
),
|
|
1291
|
-
];
|
|
1292
|
-
const recorded = Boolean(C.MAP[key]);
|
|
1293
|
-
/** @type {Record<string, unknown>} */
|
|
1294
|
-
const extra = {};
|
|
1295
|
-
if (!recorded && !ctx.unchecked) {
|
|
1296
|
-
const {commands} = checked(env, [
|
|
1297
|
-
// (A fill of one color is the background color: the shorthand would
|
|
1298
|
-
// clear the image Core draws its hover tint with.)
|
|
1299
|
-
[{verb: 'set', thing: 'background-color', value: '#f3f4f6', on: key}],
|
|
1300
|
-
[{verb: 'set', thing: 'color', value: '#111827', on: key}],
|
|
1301
|
-
[{verb: 'set', thing: 'border-radius', value: '8px', on: key}],
|
|
1302
|
-
]);
|
|
1303
|
-
extra.unrecorded = {
|
|
1304
|
-
reason: `the part data comes from one render of every component, and it has no ${key}, so what ${key} reads is unknown; a CSS property set --on ${key} still applies`,
|
|
1305
|
-
examples: commands,
|
|
1306
|
-
};
|
|
1307
|
-
}
|
|
1308
|
-
return {
|
|
1309
|
-
kind: 'part',
|
|
1310
|
-
subject,
|
|
1311
|
-
component: target.component ?? null,
|
|
1312
|
-
// What the part is, from its component's doc (a side nav heading is the
|
|
1313
|
-
// product or account heading at the top, not a section title).
|
|
1314
|
-
is: partComponentDocs(ctx, key).at(-1)?.doc.description || null,
|
|
1315
|
-
components,
|
|
1316
|
-
recorded,
|
|
1317
|
-
group,
|
|
1318
|
-
groupMembers: group ? groupsOf(ctx)[group] : [],
|
|
1319
|
-
spreads: group ? AUTO_SPREAD.includes(group) : false,
|
|
1320
|
-
variants: C.variantValues(key),
|
|
1321
|
-
states,
|
|
1322
|
-
reads,
|
|
1323
|
-
contains: C.MAP[key]?.contains ?? [],
|
|
1324
|
-
...extra,
|
|
1325
|
-
...unknown,
|
|
1326
|
-
...themeFields,
|
|
1327
|
-
};
|
|
1328
|
-
}
|
|
1329
|
-
|
|
1330
|
-
/**
|
|
1331
|
-
* One condition a part reads a token under, written as the flags `set`
|
|
1332
|
-
* takes (`always` for none), or the condition and why no flag reaches it.
|
|
1333
|
-
* @param {import('./_settings.mjs').Ctx} ctx
|
|
1334
|
-
* @param {string} target
|
|
1335
|
-
* @param {string} cond
|
|
1336
|
-
* @param {string[]} [settable] the states set takes on the part (the one
|
|
1337
|
-
* list its refusals and how name too), when known
|
|
1338
|
-
* @returns {string}
|
|
1339
|
-
*/
|
|
1340
|
-
export function condition(ctx, target, cond, settable) {
|
|
1341
|
-
if (!cond.trim()) return 'always';
|
|
1342
|
-
const t = ctx.project.target.get(target);
|
|
1343
|
-
const props = t?.props ?? [];
|
|
1344
|
-
const states = settable ?? partStates(ctx, target);
|
|
1345
|
-
const values = ctx.C.variantValues(target);
|
|
1346
|
-
// An attribute the part has no prop for and is drawn with the same value
|
|
1347
|
-
// in every render (a toggle button is always a ghost button): the part
|
|
1348
|
-
// itself, not a condition.
|
|
1349
|
-
/** @type {Map<string, Set<string>>} */
|
|
1350
|
-
const seen = new Map();
|
|
1351
|
-
for (const byCond of Object.values(ctx.C.MAP[target]?.at ?? {}))
|
|
1352
|
-
for (const c of Object.keys(/** @type {object} */ (byCond)))
|
|
1353
|
-
for (const m of c.matchAll(/(?:^|[\s,])([a-z][\w-]*)=([^\s,]*)/gi))
|
|
1354
|
-
(seen.get(m[1]) ?? seen.set(m[1], new Set()).get(m[1]))?.add(m[2]);
|
|
1355
|
-
/** @type {Record<string, string>} */
|
|
1356
|
-
const ariaOf = Object.fromEntries(
|
|
1357
|
-
Object.entries(ARIA_STATES).map(([name, {attr}]) => [attr, name]),
|
|
1358
|
-
);
|
|
1359
|
-
const words = cond.trim().split(/\s+/);
|
|
1360
|
-
const isAttr = (/** @type {string} */ w) => /^[a-z][\w-]*=[^\s]*$/i.test(w);
|
|
1361
|
-
const attrs = words.filter(isAttr).flatMap(w => w.split(','));
|
|
1362
|
-
const css = words.filter(w => !isAttr(w)).join(' ');
|
|
1363
|
-
/** @type {string[]} */
|
|
1364
|
-
const flags = [];
|
|
1365
|
-
/** @type {string | null} */
|
|
1366
|
-
let why = null;
|
|
1367
|
-
for (const kv of attrs) {
|
|
1368
|
-
const [k, v] = kv.split('=');
|
|
1369
|
-
// A state Core paints from an ARIA attribute: --state by its name.
|
|
1370
|
-
if (ariaOf[k] && states.includes(ariaOf[k]) && v !== 'false')
|
|
1371
|
-
flags.push(`--state ${ariaOf[k]}`);
|
|
1372
|
-
else if (
|
|
1373
|
-
!props.includes(k) &&
|
|
1374
|
-
!states.includes(k) &&
|
|
1375
|
-
!ariaOf[k] &&
|
|
1376
|
-
seen.get(k)?.size === 1 &&
|
|
1377
|
-
Object.values(ctx.C.MAP[target]?.at ?? {}).every(byCond =>
|
|
1378
|
-
Object.keys(/** @type {object} */ (byCond)).every(
|
|
1379
|
-
c => !c.trim() || new RegExp(`(^|[\\s,])${k}=`).test(c),
|
|
1380
|
-
),
|
|
1381
|
-
)
|
|
1382
|
-
)
|
|
1383
|
-
continue;
|
|
1384
|
-
// A state written as its own name (`checked=checked`) set takes as
|
|
1385
|
-
// --state.
|
|
1386
|
-
else if ((v === k || v === 'true') && states.includes(k))
|
|
1387
|
-
flags.push(`--state ${k}`);
|
|
1388
|
-
else if (props.includes(k) && (!values[k]?.length || values[k].includes(v)))
|
|
1389
|
-
flags.push(`--when ${k}:${v}`);
|
|
1390
|
-
// Another value of a state (a checkbox's `checked="indeterminate"`):
|
|
1391
|
-
// set names it with --when.
|
|
1392
|
-
else if (states.includes(k)) flags.push(`--when ${k}:${v}`);
|
|
1393
|
-
else why ??= `${target} has no ${k} prop or state that set can name`;
|
|
1394
|
-
}
|
|
1395
|
-
if (css) {
|
|
1396
|
-
const m = /^:([a-z-]+)$/.exec(css);
|
|
1397
|
-
// An ARIA state Core writes as a selector of its own (an open menu
|
|
1398
|
-
// button's `:is([aria-expanded="true"][aria-haspopup]…)`).
|
|
1399
|
-
const aria = /^(?::is\()?\[(aria-[a-z]+)="?([\w-]+)"?\]/.exec(css);
|
|
1400
|
-
if (m && states.includes(m[1])) flags.push(`--state ${m[1]}`);
|
|
1401
|
-
else if (
|
|
1402
|
-
aria &&
|
|
1403
|
-
ariaOf[aria[1]] &&
|
|
1404
|
-
states.includes(ariaOf[aria[1]]) &&
|
|
1405
|
-
aria[2] !== 'false' &&
|
|
1406
|
-
!/::|:(?!is\(|not\()/.test(css.replace(/^:is\(|\)$/g, ''))
|
|
1407
|
-
)
|
|
1408
|
-
flags.push(`--state ${ariaOf[aria[1]]}`);
|
|
1409
|
-
else why ??= `${css} is a CSS selector that set cannot name`;
|
|
1410
|
-
}
|
|
1411
|
-
if (flags.filter(f => f.startsWith('--when')).length > 1)
|
|
1412
|
-
why ??= 'set names one --when at a time';
|
|
1413
|
-
// Several states at once (a checked and disabled box): one --state with
|
|
1414
|
-
// each, joined by +.
|
|
1415
|
-
const stateFlags = flags.filter(f => f.startsWith('--state'));
|
|
1416
|
-
if (stateFlags.length > 1) {
|
|
1417
|
-
const joined = `--state ${stateFlags.map(f => f.slice(8)).join('+')}`;
|
|
1418
|
-
flags.splice(
|
|
1419
|
-
0,
|
|
1420
|
-
flags.length,
|
|
1421
|
-
...flags.filter(f => !f.startsWith('--state')),
|
|
1422
|
-
joined,
|
|
1423
|
-
);
|
|
1424
|
-
}
|
|
1425
|
-
return why ? `${cond.trim()} (not settable: ${why})` : flags.join(' ');
|
|
1426
|
-
}
|
|
1427
|
-
|
|
1428
|
-
/** Whether Core's stylesheet reads a token. @type {Map<string, string>} */
|
|
1429
|
-
const sheets = new Map();
|
|
1430
|
-
/**
|
|
1431
|
-
* @param {import('./_settings.mjs').Ctx} ctx
|
|
1432
|
-
* @param {string} token
|
|
1433
|
-
*/
|
|
1434
|
-
function stylesheetReads(ctx, token) {
|
|
1435
|
-
const file = ctx.project.req.resolve('@astryxdesign/core/astryx.css');
|
|
1436
|
-
let css = sheets.get(file);
|
|
1437
|
-
if (css == null) {
|
|
1438
|
-
try {
|
|
1439
|
-
css = fs.readFileSync(file, 'utf8');
|
|
1440
|
-
} catch {
|
|
1441
|
-
css = '';
|
|
1442
|
-
}
|
|
1443
|
-
sheets.set(file, css);
|
|
1444
|
-
}
|
|
1445
|
-
return new RegExp(`var\\(${token}[,)]`).test(css);
|
|
1446
|
-
}
|
|
1447
|
-
|
|
1448
|
-
/**
|
|
1449
|
-
* A value of a token's own type that differs from the one it has now.
|
|
1450
|
-
* @param {string} type
|
|
1451
|
-
* @param {string} token
|
|
1452
|
-
* @param {string} now
|
|
1453
|
-
*/
|
|
1454
|
-
function exampleForToken(type, token, now) {
|
|
1455
|
-
const pick = (/** @type {string[]} */ xs) =>
|
|
1456
|
-
xs.find(x => x.toLowerCase() !== now.toLowerCase()) ?? xs[0];
|
|
1457
|
-
if (type === 'color') return pick(['#7c3aed', '#2563eb']);
|
|
1458
|
-
if (type === 'shadow') return '0 2px 8px rgb(0 0 0 / 0.15)';
|
|
1459
|
-
if (type === 'size') {
|
|
1460
|
-
const m = /^(\d*\.?\d+)(px|rem|em)$/.exec(now.trim());
|
|
1461
|
-
if (m) return `${Number((Number(m[1]) * 1.25).toFixed(3))}${m[2]}`;
|
|
1462
|
-
return pick(['8px', '10px']);
|
|
1463
|
-
}
|
|
1464
|
-
if (type === 'number')
|
|
1465
|
-
return /leading|line-height/.test(token)
|
|
1466
|
-
? pick(['1.6', '1.4'])
|
|
1467
|
-
: pick(['600', '700']);
|
|
1468
|
-
if (type === 'font') return 'Georgia, serif';
|
|
1469
|
-
if (type === 'time') return pick(['200ms', '300ms']);
|
|
1470
|
-
if (type === 'easing') return 'ease-out';
|
|
1471
|
-
return null;
|
|
1472
|
-
}
|
|
1473
|
-
|
|
1474
|
-
/** An example value for a CSS property. @param {string} prop */
|
|
1475
|
-
function exampleForProperty(prop) {
|
|
1476
|
-
if (COLOR_PROPS.test(prop)) return '#7c3aed';
|
|
1477
|
-
/** @type {Record<string, string>} */
|
|
1478
|
-
const known = {
|
|
1479
|
-
background: '#f3f4f6',
|
|
1480
|
-
'background-image': 'linear-gradient(#ffffff, #e5e7eb)',
|
|
1481
|
-
border: '1px solid var(--color-border)',
|
|
1482
|
-
'border-width': '2px',
|
|
1483
|
-
'border-style': 'dashed',
|
|
1484
|
-
'box-shadow': 'var(--shadow-med)',
|
|
1485
|
-
'font-weight': '600',
|
|
1486
|
-
'font-family': 'Georgia, serif',
|
|
1487
|
-
'letter-spacing': '0.02em',
|
|
1488
|
-
'text-transform': 'uppercase',
|
|
1489
|
-
'font-style': 'italic',
|
|
1490
|
-
opacity: '0.8',
|
|
1491
|
-
transform: 'scale(0.97)',
|
|
1492
|
-
outline: 'none',
|
|
1493
|
-
};
|
|
1494
|
-
if (known[prop]) return known[prop];
|
|
1495
|
-
if (/radius$/.test(prop)) return '8px';
|
|
1496
|
-
if (/^(padding|margin|gap|row-gap|column-gap)/.test(prop)) return '12px';
|
|
1497
|
-
if (/^(font-size)$/.test(prop)) return '16px';
|
|
1498
|
-
if (/(height|width|block-size|inline-size)$/.test(prop)) return '40px';
|
|
1499
|
-
return null;
|
|
1500
|
-
}
|
|
1501
|
-
|
|
1502
|
-
/**
|
|
1503
|
-
* The answer for one design token: its type, default, the parts that read
|
|
1504
|
-
* it, and commands that set it, each checked.
|
|
1505
|
-
* @param {import('./_settings.mjs').Ctx} ctx
|
|
1506
|
-
* @param {import('./_how-commands.mjs').HowTheme} env
|
|
1507
|
-
* @param {string} subject
|
|
1508
|
-
* @param {string} key
|
|
1509
|
-
* @param {object} unknown
|
|
1510
|
-
* @param {object} themeFields
|
|
1511
|
-
* @returns {import('./theme-edit.type.mjs').ThemeEditHowResponse['data']}
|
|
1512
|
-
*/
|
|
1513
|
-
function tokenAnswer(ctx, env, subject, key, unknown, themeFields) {
|
|
1514
|
-
const {C} = ctx;
|
|
1515
|
-
const readers = C.anyReader(key);
|
|
1516
|
-
const type = C.typeOf(key);
|
|
1517
|
-
// The theme's own value (its settings applied), else the base theme's.
|
|
1518
|
-
const now =
|
|
1519
|
-
env.own?.light[key] ??
|
|
1520
|
-
env.base.light[key] ??
|
|
1521
|
-
String(ctx.project.core.tokenDefaults[key]);
|
|
1522
|
-
const value = exampleForToken(type, key, now);
|
|
1523
|
-
const {commands, refused} = value
|
|
1524
|
-
? checked(env, [
|
|
1525
|
-
[{verb: 'set', thing: key, value}],
|
|
1526
|
-
...(readers[0]
|
|
1527
|
-
? [
|
|
1528
|
-
[
|
|
1529
|
-
{
|
|
1530
|
-
verb: /** @type {'set'} */ ('set'),
|
|
1531
|
-
thing: key,
|
|
1532
|
-
value,
|
|
1533
|
-
on: readers[0],
|
|
1534
|
-
},
|
|
1535
|
-
],
|
|
1536
|
-
]
|
|
1537
|
-
: []),
|
|
1538
|
-
])
|
|
1539
|
-
: {commands: [], refused: []};
|
|
1540
|
-
// The part data comes from one render of each component, so a token only
|
|
1541
|
-
// a variant it does not render reads (heading level 5, an error toast)
|
|
1542
|
-
// shows no reader there; Core's stylesheet still names it.
|
|
1543
|
-
const inSheet = !readers.length && stylesheetReads(ctx, key);
|
|
1544
|
-
// Where the theme's base draws past it: a part and condition whose own
|
|
1545
|
-
// base rule sets the property this token feeds in Core.
|
|
1546
|
-
const redrawn = ctx.unchecked ? [] : baseRedraws(C, env.base, key);
|
|
1547
|
-
return {
|
|
1548
|
-
kind: 'setting',
|
|
1549
|
-
subject,
|
|
1550
|
-
// (The page color shows inside AppShell only: said first.)
|
|
1551
|
-
...(key === '--color-background-body'
|
|
1552
|
-
? {note: pageColorNote(env.data?.mode)}
|
|
1553
|
-
: {}),
|
|
1554
|
-
source: 'token',
|
|
1555
|
-
tokenType: type,
|
|
1556
|
-
default: String(ctx.project.core.tokenDefaults[key]),
|
|
1557
|
-
perMode: MODAL.has(type),
|
|
1558
|
-
readBy: readers,
|
|
1559
|
-
...(readers.length || ctx.unchecked
|
|
1560
|
-
? {}
|
|
1561
|
-
: {
|
|
1562
|
-
readByNote: inSheet
|
|
1563
|
-
? `no part in the part data reads ${key}, but Core's stylesheet does, in a variant or state the part data does not render; so readBy is incomplete`
|
|
1564
|
-
: `no part reads ${key}, and Core's stylesheet does not use it`,
|
|
1565
|
-
}),
|
|
1566
|
-
...(redrawn.length
|
|
1567
|
-
? {
|
|
1568
|
-
notIn: redrawn.map(
|
|
1569
|
-
r =>
|
|
1570
|
-
`${r.part}${r.when ? ` (${r.when.replace(':', ' ')})` : ''}: the ${env.data.like ?? 'base'} theme draws its ${r.prop} from ${r.value}, so ${key} does not reach it; set ${r.prop} --on ${r.part}${r.when ? ` --when ${r.when}` : ''} there`,
|
|
1571
|
-
),
|
|
1572
|
-
}
|
|
1573
|
-
: {}),
|
|
1574
|
-
...unknown,
|
|
1575
|
-
...themeFields,
|
|
1576
|
-
examples: commands,
|
|
1577
|
-
...(refused.length ? {refused} : {}),
|
|
1578
|
-
};
|
|
1579
|
-
}
|
|
1580
|
-
|
|
1581
|
-
/**
|
|
1582
|
-
* How the theme's colors are made, for `how colors`: one line on the
|
|
1583
|
-
* generator, one per color with the shade each token starts from, then
|
|
1584
|
-
* vibrancy, every shade, and the exact-token escape hatch.
|
|
1585
|
-
* @param {import('./_how-commands.mjs').HowTheme} env
|
|
1586
|
-
* @param {(dial: string) => string[]} dialCommands
|
|
1587
|
-
* @returns {Array<{text: string, commands: string[]}>}
|
|
1588
|
-
*/
|
|
1589
|
-
function colorsAnswer(env, dialCommands) {
|
|
1590
|
-
const f = paletteFiles(env.slug);
|
|
1591
|
-
const one = (/** @type {import('./_how-commands.mjs').Step[]} */ steps) =>
|
|
1592
|
-
checked(env, [steps]).commands;
|
|
1593
|
-
return [
|
|
1594
|
-
{
|
|
1595
|
-
text: `Each color you set (${PALETTE_DIALS.join(', ')}) is one seed: the editor generates its shades from it, light and dark, with the same generator as \`theme palette generate\`, and points the color tokens at those shades. The exact color you gave sits at its own shade, in dark too when it reads there. A token moves to a nearby shade when it must read: text at 4.5:1, the focus ring and secondary icons at 3:1. A fill never moves: the text on it changes instead. It never mixes a new color. The generated files are ${f.palette}, made from ${f.config}; the theme imports only the shades it uses, from ${f.refs}, so every change moves the theme with it. Hand edits to ${f.config} that no color setting owns are kept; a hand edit to ${f.palette} is never overwritten.`,
|
|
1596
|
-
commands: [
|
|
1597
|
-
...one([{verb: 'set', thing: 'accent', value: '#7c3aed'}]),
|
|
1598
|
-
...one([{verb: 'set', thing: 'neutral', value: '#64748b'}]),
|
|
1599
|
-
...(env.exists ? [`${P} show ${env.slug}`] : []),
|
|
1600
|
-
],
|
|
1601
|
-
},
|
|
1602
|
-
...PALETTE_DIALS.map(d => ({
|
|
1603
|
-
text: `${d}: ${mappingRows(d).join('; ')}`,
|
|
1604
|
-
commands: dialCommands(d),
|
|
1605
|
-
})),
|
|
1606
|
-
{
|
|
1607
|
-
text: DIALS.vibrancy.help,
|
|
1608
|
-
commands: dialCommands('vibrancy'),
|
|
1609
|
-
},
|
|
1610
|
-
{
|
|
1611
|
-
text: 'Every shade, light and dark, with the tokens that use each: the Colors page of the in-app preview. It changes with every set.',
|
|
1612
|
-
commands: env.exists ? [`${PREVIEW} add --theme ${env.slug}`] : [],
|
|
1613
|
-
},
|
|
1614
|
-
{
|
|
1615
|
-
text: 'An exact color for one token: set the token itself. It always wins over the generated colors, whatever order you set them in.',
|
|
1616
|
-
commands: one([{verb: 'set', thing: '--color-accent', value: '#7c3aed'}]),
|
|
1617
|
-
},
|
|
1618
|
-
];
|
|
1619
|
-
}
|
|
1620
|
-
|
|
1621
|
-
/** A word for color-vision deficiency, as a pattern's source. */
|
|
1622
|
-
const COLOR_BLIND_WORD = String.raw`(?:colou?r[- ]?blind\w*|colou?r[- ]vision|cvd|deuteran\w*|protan\w*|tritan\w*)`;
|
|
1623
|
-
const COLOR_BLIND = new RegExp(String.raw`\b${COLOR_BLIND_WORD}\b`, 'i');
|
|
1624
|
-
|
|
1625
|
-
/**
|
|
1626
|
-
* An ask's pieces, split at commas and at an "and" that joins two asks
|
|
1627
|
-
* ("color-blind friendly statuses and a blue accent"; "red and green for
|
|
1628
|
-
* color-blind people" is one ask): whether a piece asks about color-blind
|
|
1629
|
-
* readers, and the pieces that do not.
|
|
1630
|
-
* @param {string} q
|
|
1631
|
-
*/
|
|
1632
|
-
function colorBlindPieces(q) {
|
|
1633
|
-
const pieces = q
|
|
1634
|
-
.split(
|
|
1635
|
-
new RegExp(
|
|
1636
|
-
String.raw`[,;:]|\s(?:and|plus|&)\s(?!(?:[\w-]+\s+){0,3}${COLOR_BLIND_WORD})`,
|
|
1637
|
-
'i',
|
|
1638
|
-
),
|
|
1639
|
-
)
|
|
1640
|
-
.map(x => x.trim())
|
|
1641
|
-
.filter(Boolean);
|
|
1642
|
-
const blind = pieces.filter(x => COLOR_BLIND.test(x));
|
|
1643
|
-
if (!blind.length) return {blind: false, rest: ''};
|
|
1644
|
-
// (A color-blind piece that says a change, "warnings darker for
|
|
1645
|
-
// color-blind users", is asked as said; a piece that is only about
|
|
1646
|
-
// color-blind readers is read as the status colors it is about, so the
|
|
1647
|
-
// list keeps its shape.)
|
|
1648
|
-
const own = (/** @type {string} */ x) => {
|
|
1649
|
-
const left = x
|
|
1650
|
-
.replace(
|
|
1651
|
-
new RegExp(
|
|
1652
|
-
String.raw`\s*\b(?:that|which|so(?:\s+that)?|for|to)\s+(?:[\w-]+\s+){0,3}?${COLOR_BLIND_WORD}(?:\s+[\w-]+){0,5}\s*$`,
|
|
1653
|
-
'i',
|
|
1654
|
-
),
|
|
1655
|
-
'',
|
|
1656
|
-
)
|
|
1657
|
-
.replace(
|
|
1658
|
-
new RegExp(
|
|
1659
|
-
String.raw`\b${COLOR_BLIND_WORD}(?:[- ](?:friendly|safe|proof|readers?|users?|people))?`,
|
|
1660
|
-
'gi',
|
|
1661
|
-
),
|
|
1662
|
-
'',
|
|
1663
|
-
)
|
|
1664
|
-
.replace(/\s+/g, ' ')
|
|
1665
|
-
.trim();
|
|
1666
|
-
// (What is left is a change unless it is only words about the ask
|
|
1667
|
-
// itself: "color-blind friendly statuses", "a color-blind safe
|
|
1668
|
-
// palette".)
|
|
1669
|
-
const said = left
|
|
1670
|
-
.replace(
|
|
1671
|
-
/\b(?:make|makes|making|it|its|this|that|the|a|an|be|is|are|please|our|my|your|theme|app|site|ui|friendly|safe|proof|accessible|people|users?|readers?|staff|folks|viewers?|visitors?|for|with|to|so|also|and|status(?:es)?|colou?rs?|palette|statuses|can|tell|apart|them)\b/gi,
|
|
1672
|
-
'',
|
|
1673
|
-
)
|
|
1674
|
-
.replace(/[^\w#]+/g, '');
|
|
1675
|
-
return said ? x : 'status colors';
|
|
1676
|
-
};
|
|
1677
|
-
const kept = blind.map(own);
|
|
1678
|
-
if (blind.length === pieces.length && kept.every(x => x === 'status colors'))
|
|
1679
|
-
return {blind: true, rest: ''};
|
|
1680
|
-
const rest = blind
|
|
1681
|
-
.reduce((t, x, k) => t.replace(x, ` ${kept[k]} `), q)
|
|
1682
|
-
.replace(/\s+/g, ' ')
|
|
1683
|
-
.trim();
|
|
1684
|
-
return {blind: true, rest};
|
|
1685
|
-
}
|
|
1686
|
-
|
|
1687
|
-
/**
|
|
1688
|
-
* The answer about color-blind readers.
|
|
1689
|
-
* @param {import('./_how-commands.mjs').HowTheme} env
|
|
1690
|
-
*/
|
|
1691
|
-
function colorBlindAnswer(env) {
|
|
1692
|
-
return [
|
|
1693
|
-
{
|
|
1694
|
-
text: `color-blind readers: the editor checks that the status fills (info, success, warning, danger) stay apart for someone red-weak or green-weak, and show and set note a pair that may look alike, with a line that moves one of them lighter or darker. A status shown with its words or an icon does not rest on color alone; a status dot does, so its colors need lightness apart too. To choose the colors yourself, set each status color; keep warning light and danger dark so lightness, not only hue, tells them apart.`,
|
|
1695
|
-
commands: [
|
|
1696
|
-
...(env.exists ? [`${P} show ${env.slug}`] : []),
|
|
1697
|
-
`${HOW} "status colors"`,
|
|
1698
|
-
],
|
|
1699
|
-
},
|
|
1700
|
-
];
|
|
1701
|
-
}
|
|
1702
|
-
|
|
1703
|
-
/**
|
|
1704
|
-
* The answer to a question about the tool itself: help, a list, how to see
|
|
1705
|
-
* a change, or the difference between two things it names. 'list' means
|
|
1706
|
-
* the caller lists the kind the question names.
|
|
1707
|
-
* @param {string} t
|
|
1708
|
-
* @param {import('./_how-commands.mjs').HowTheme} env
|
|
1709
|
-
* @param {Map<string, unknown>} targets the parts Core styles
|
|
1710
|
-
* @returns {Array<{text: string, commands: string[]}> | 'list' | null}
|
|
1711
|
-
*/
|
|
1712
|
-
function toolAnswer(t, env, targets) {
|
|
1713
|
-
const q = t
|
|
1714
|
-
.trim()
|
|
1715
|
-
.toLowerCase()
|
|
1716
|
-
.replace(/[?.!]+$/, '');
|
|
1717
|
-
if (
|
|
1718
|
-
/^(help|usage|\?|how does (this|it) work|what can (i|you) (ask|do))$/.test(
|
|
1719
|
-
q,
|
|
1720
|
-
)
|
|
1721
|
-
)
|
|
1722
|
-
return [
|
|
1723
|
-
{
|
|
1724
|
-
text: 'how answers a part, a setting, a plain-words question or a PNG picture with the commands that make the change; set makes it, show lists what a theme sets',
|
|
1725
|
-
commands: [`${HOW} --help`, `${HOW} --list kinds`],
|
|
1726
|
-
},
|
|
1727
|
-
];
|
|
1728
|
-
if (
|
|
1729
|
-
/^(list|show)( me)? (all|every|the)? ?(the )?(dials?|tokens?|parts?|groups?|properties)\b/.test(
|
|
1730
|
-
q,
|
|
1731
|
-
)
|
|
1732
|
-
)
|
|
1733
|
-
return 'list';
|
|
1734
|
-
// (Only an ask about color-blind readers alone; in a list of asks the
|
|
1735
|
-
// other pieces are answered too (answer).)
|
|
1736
|
-
if (colorBlindPieces(q).blind && !colorBlindPieces(q).rest)
|
|
1737
|
-
return colorBlindAnswer(env);
|
|
1738
|
-
if (/\b(see|view|preview|check) (my |the )?(changes?|theme|edits?)\b/.test(q))
|
|
1739
|
-
return [
|
|
1740
|
-
{
|
|
1741
|
-
text: `show lists what ${env.slug} sets; a preview page shows the theme in the app`,
|
|
1742
|
-
commands: [
|
|
1743
|
-
`${P} show ${env.slug}`,
|
|
1744
|
-
`${PREVIEW} add --theme ${env.slug}`,
|
|
1745
|
-
],
|
|
1746
|
-
},
|
|
1747
|
-
];
|
|
1748
|
-
// Questions about the theme's files and life.
|
|
1749
|
-
if (
|
|
1750
|
-
/\b(use|import|apply|add|load) (this|the|my) theme (in|to|into) (my|the) app\b/.test(
|
|
1751
|
-
q,
|
|
1752
|
-
)
|
|
1753
|
-
)
|
|
1754
|
-
return [
|
|
1755
|
-
{
|
|
1756
|
-
text: `the theme is a module in themes/${env.slug}/; show names it and its files, and the theme docs say how an app loads a theme`,
|
|
1757
|
-
commands: [`${P} show ${env.slug}`, 'astryx docs theme'],
|
|
1758
|
-
},
|
|
1759
|
-
];
|
|
1760
|
-
if (/\brename\b/.test(q))
|
|
1761
|
-
return [
|
|
1762
|
-
{
|
|
1763
|
-
text: 'no command renames a theme: make a new one, set what you need on it, and remove the old folder',
|
|
1764
|
-
commands: [
|
|
1765
|
-
`${P} new ${env.slug}-2 --like ${env.data.like ?? 'none'}`,
|
|
1766
|
-
`${P} show ${env.slug}`,
|
|
1767
|
-
],
|
|
1768
|
-
},
|
|
1769
|
-
];
|
|
1770
|
-
if (
|
|
1771
|
-
/\b(what|which) (changed|did i change|have i changed)\b|\bwhat (is|does) (my|this|the) theme set\b/.test(
|
|
1772
|
-
q,
|
|
1773
|
-
)
|
|
1774
|
-
)
|
|
1775
|
-
return [
|
|
1776
|
-
{
|
|
1777
|
-
text: `show lists every setting ${env.slug} has, in the order they were made`,
|
|
1778
|
-
commands: [`${P} show ${env.slug}`],
|
|
1779
|
-
},
|
|
1780
|
-
];
|
|
1781
|
-
if (/\b(second|another|new|other) theme\b/.test(q))
|
|
1782
|
-
return [
|
|
1783
|
-
{
|
|
1784
|
-
text: 'new makes a theme beside the ones you have; how and set take --theme to pick one',
|
|
1785
|
-
commands: [`${P} new ${env.slug}-2 --like ${env.data.like ?? 'none'}`],
|
|
1786
|
-
},
|
|
1787
|
-
];
|
|
1788
|
-
// Screen-size, print and device conditions: the editor has none.
|
|
1789
|
-
if (
|
|
1790
|
-
/\bmedia quer|^(on|for) (mobile|phones?|tablets?|desktops?|print)$|^(print|printing|print styles?)$/.test(
|
|
1791
|
-
q,
|
|
1792
|
-
)
|
|
1793
|
-
)
|
|
1794
|
-
return [
|
|
1795
|
-
{
|
|
1796
|
-
text: 'the theme editor has no screen-size, print or device conditions: every setting applies on every screen; a media query needs your own CSS',
|
|
1797
|
-
commands: [`${HOW} --help`],
|
|
1798
|
-
},
|
|
1799
|
-
];
|
|
1800
|
-
// Questions about what is set now, or the choices: a lookup, never a
|
|
1801
|
-
// write.
|
|
1802
|
-
const asks =
|
|
1803
|
-
/^(how (round|big|small|large|thick|dark|light|bold|wide|tall) (is|are)|what (is|are) the (current|available)|which \w+ (does|do|is|are)|what (font|color|colour|radius|accent) (does|do|is|are)|what (values|options|choices))\b|\b(right now|currently|at the moment)\??$|\bnow\?$/.exec(
|
|
1804
|
-
q,
|
|
1805
|
-
);
|
|
1806
|
-
// "is my theme valid", "how many dials", "list every change".
|
|
1807
|
-
if (
|
|
1808
|
-
/^(is|are) (my|the|this) theme (valid|ok|okay|broken|working)\b|^(check|validate) (my|the) theme\b/.test(
|
|
1809
|
-
q,
|
|
1810
|
-
)
|
|
1811
|
-
)
|
|
1812
|
-
return [
|
|
1813
|
-
{
|
|
1814
|
-
text: `show builds ${env.slug} and says what is wrong with it, if anything`,
|
|
1815
|
-
commands: [`${P} show ${env.slug}`],
|
|
1816
|
-
},
|
|
1817
|
-
];
|
|
1818
|
-
if (
|
|
1819
|
-
/^how many (dials|settings|tokens|parts)\b|^(list|show) (every|all|each) (dial|setting|token|part)s?\b/.test(
|
|
1820
|
-
q,
|
|
1821
|
-
)
|
|
1822
|
-
)
|
|
1823
|
-
return 'list';
|
|
1824
|
-
if (/^(list|show) (every|all|my) (changes?|edits?|settings)\b/.test(q))
|
|
1825
|
-
return [
|
|
1826
|
-
{
|
|
1827
|
-
text: `show lists every setting ${env.slug} has`,
|
|
1828
|
-
commands: [`${P} show ${env.slug}`],
|
|
1829
|
-
},
|
|
1830
|
-
];
|
|
1831
|
-
if (
|
|
1832
|
-
// A question about a part's value now is answered with that value.
|
|
1833
|
-
(asks && !valueAsked(q)) ||
|
|
1834
|
-
/^which parts (are|does|do)\b/.test(q) ||
|
|
1835
|
-
(/^why (is|are|does|do)\b/.test(q) &&
|
|
1836
|
-
!/\bnot\b|n'?t\b/.test(q) &&
|
|
1837
|
-
// ("why is everything so round": a complaint, an ask.)
|
|
1838
|
-
!/^why (?:is|are)\b.*\bso [a-z]+\b/.test(q))
|
|
1839
|
-
) {
|
|
1840
|
-
// The part or setting the question names gets its own lookup.
|
|
1841
|
-
const named = q
|
|
1842
|
-
.split(/[^a-z-]+/)
|
|
1843
|
-
.find(
|
|
1844
|
-
w =>
|
|
1845
|
-
w.length > 2 &&
|
|
1846
|
-
(targets.has(w) ||
|
|
1847
|
-
targets.has(w.replace(/s$/, '')) ||
|
|
1848
|
-
['inputs', 'checks'].includes(w)),
|
|
1849
|
-
);
|
|
1850
|
-
const key =
|
|
1851
|
-
named && !targets.has(named) && !['inputs', 'checks'].includes(named)
|
|
1852
|
-
? named.replace(/s$/, '')
|
|
1853
|
-
: named;
|
|
1854
|
-
return [
|
|
1855
|
-
{
|
|
1856
|
-
text: key
|
|
1857
|
-
? `how ${key} says what ${key} reads and what sets it; show lists what ${env.slug} sets now`
|
|
1858
|
-
: `show lists what ${env.slug} sets now; how <part> or how <setting> says what a part reads and the values a setting takes`,
|
|
1859
|
-
commands: [...(key ? [`${HOW} ${key}`] : []), `${P} show ${env.slug}`],
|
|
1860
|
-
},
|
|
1861
|
-
];
|
|
1862
|
-
}
|
|
1863
|
-
if (
|
|
1864
|
-
/\b((astryx|cli) version|version of (the )?(cli|astryx)|which cli|what cli)\b/.test(
|
|
1865
|
-
q,
|
|
1866
|
-
)
|
|
1867
|
-
)
|
|
1868
|
-
return [{text: 'the CLI says its version', commands: ['astryx --version']}];
|
|
1869
|
-
if (/\bwhere (are|is|do) .*\b(stored|saved|kept|live|files?)\b/.test(q))
|
|
1870
|
-
return [
|
|
1871
|
-
{
|
|
1872
|
-
text: `everything is in themes/${env.slug}/: the settings file is the source, and the CSS and module are built from it`,
|
|
1873
|
-
commands: [`${P} show ${env.slug}`],
|
|
1874
|
-
},
|
|
1875
|
-
];
|
|
1876
|
-
if (
|
|
1877
|
-
/\b(edit|change) (the )?(css|module|theme)?( files?)? by hand\b|\bhand[- ]edit/.test(
|
|
1878
|
-
q,
|
|
1879
|
-
)
|
|
1880
|
-
)
|
|
1881
|
-
return [
|
|
1882
|
-
{
|
|
1883
|
-
text: `the CSS and module in themes/${env.slug}/ are built from the settings file, so a hand edit is lost at the next set; make the change with set`,
|
|
1884
|
-
commands: [`${HOW} --help`],
|
|
1885
|
-
},
|
|
1886
|
-
];
|
|
1887
|
-
const diff = /\bdifference between (.+?) and (.+)$/.exec(q);
|
|
1888
|
-
if (diff) {
|
|
1889
|
-
const props = cssProperties();
|
|
1890
|
-
return [diff[1], diff[2]].map(x => {
|
|
1891
|
-
const w = x.trim().replace(/^(the|a) /, '');
|
|
1892
|
-
return {
|
|
1893
|
-
text: Object.hasOwn(DIALS, w)
|
|
1894
|
-
? `${w} is a dial: ${DIALS[w].help}`
|
|
1895
|
-
: props.has(w)
|
|
1896
|
-
? `${w} is a CSS property: set it on one part with --on`
|
|
1897
|
-
: w.startsWith('--')
|
|
1898
|
-
? `${w} is a token: one value the whole theme reads`
|
|
1899
|
-
: `what ${w} is`,
|
|
1900
|
-
commands: [`${HOW} ${w}`],
|
|
1901
|
-
};
|
|
1902
|
-
});
|
|
1903
|
-
}
|
|
1904
|
-
return null;
|
|
1905
|
-
}
|
|
1906
|
-
|
|
1907
|
-
/**
|
|
1908
|
-
* The tokens most parts read for one aspect, for a whole-theme change.
|
|
1909
|
-
* @param {import('./_settings.mjs').Ctx} ctx
|
|
1910
|
-
* @param {import('./_how-commands.mjs').HowTheme} env
|
|
1911
|
-
* @param {string} aspect
|
|
1912
|
-
* @returns {Array<{text: string, commands: string[]}>}
|
|
1913
|
-
*/
|
|
1914
|
-
function wholeThemeTokens(ctx, env, aspect) {
|
|
1915
|
-
const {C} = ctx;
|
|
1916
|
-
const toks = Object.keys(ctx.project.core.tokenDefaults)
|
|
1917
|
-
.filter(k => C.groupOfToken(k) === aspect && C.anyReader(k).length)
|
|
1918
|
-
.sort((a, b) => C.anyReader(b).length - C.anyReader(a).length)
|
|
1919
|
-
.slice(0, 6);
|
|
1920
|
-
if (!toks.length) return [];
|
|
1921
|
-
// The example uses the most read token whose example changes what shows:
|
|
1922
|
-
// a fully round corner (9999px) scaled up stays fully round.
|
|
1923
|
-
/** @type {string[]} */
|
|
1924
|
-
let commands = [];
|
|
1925
|
-
for (const tok of toks) {
|
|
1926
|
-
const now = env.own?.light[tok] ?? env.base.light[tok] ?? '';
|
|
1927
|
-
if (parseFloat(now) >= 999) continue;
|
|
1928
|
-
const value = exampleForToken(C.typeOf(tok), tok, now);
|
|
1929
|
-
if (!value) continue;
|
|
1930
|
-
commands = checked(env, [[{verb: 'set', thing: tok, value}]]).commands;
|
|
1931
|
-
if (commands.length) break;
|
|
1932
|
-
}
|
|
1933
|
-
return [
|
|
1934
|
-
{
|
|
1935
|
-
text: `whole-theme tokens for ${aspect}, most used first: ${toks.map(k => `${k} (${C.anyReader(k).length} parts)`).join(', ')}`,
|
|
1936
|
-
commands: commands.length ? commands : [`${HOW} ${toks[0]}`],
|
|
1937
|
-
},
|
|
1938
|
-
];
|
|
1939
|
-
}
|
|
1940
|
-
|
|
1941
|
-
/**
|
|
1942
|
-
* What `--list` lists: a kind in any case, singular or plural.
|
|
1943
|
-
* @param {string} list
|
|
1944
|
-
*/
|
|
1945
|
-
function listKind(list) {
|
|
1946
|
-
const k = list.trim().toLowerCase();
|
|
1947
|
-
if (k === '' || k === 'kinds' || k === 'kind') return 'kinds';
|
|
1948
|
-
const plural =
|
|
1949
|
-
k.endsWith('ies') || k.endsWith('s') ? k : k.replace(/y$/, 'ie') + 's';
|
|
1950
|
-
if (HOW_LISTS.includes(plural)) return plural;
|
|
1951
|
-
const near = nearest(k, [...HOW_LISTS, 'kinds']);
|
|
1952
|
-
return refuse(
|
|
1953
|
-
E.ERR_INVALID_ARGUMENT,
|
|
1954
|
-
`--list takes ${HOW_LISTS.join(', ')} or kinds, not "${list}".`,
|
|
1955
|
-
{
|
|
1956
|
-
didYouMean: near,
|
|
1957
|
-
run: [...near.map(n => `${HOW} --list ${n}`), `${HOW} --list kinds`],
|
|
1958
|
-
},
|
|
1959
|
-
);
|
|
1960
|
-
}
|
|
1961
|
-
|
|
1962
|
-
/**
|
|
1963
|
-
* The items of `how --list`.
|
|
1964
|
-
* @param {string} kind
|
|
1965
|
-
* @param {string} filter
|
|
1966
|
-
* @param {string} cwd
|
|
1967
|
-
* @returns {Promise<{list: string, items: Array<Record<string, unknown>>, common?: boolean}>}
|
|
1968
|
-
*/
|
|
1969
|
-
async function listItems(kind, filter, cwd) {
|
|
1970
|
-
const f = (/** @type {string} */ x) =>
|
|
1971
|
-
x.toLowerCase().includes(filter.toLowerCase());
|
|
1972
|
-
if (kind === 'dials') {
|
|
1973
|
-
const ctx = await context(cwd);
|
|
1974
|
-
const env = await howTheme(ctx, cwd, undefined);
|
|
1975
|
-
return {
|
|
1976
|
-
list: kind,
|
|
1977
|
-
items: Object.entries(DIALS)
|
|
1978
|
-
.filter(([k]) => f(k))
|
|
1979
|
-
.map(([name, d]) => ({
|
|
1980
|
-
name,
|
|
1981
|
-
values: d.values,
|
|
1982
|
-
help: dialHelp(name, env),
|
|
1983
|
-
examples: d.examples
|
|
1984
|
-
.map(exampleStep)
|
|
1985
|
-
.filter(st => st != null)
|
|
1986
|
-
.map(st =>
|
|
1987
|
-
render(
|
|
1988
|
-
/** @type {import('./_how-commands.mjs').Step} */ (st),
|
|
1989
|
-
env.slug,
|
|
1990
|
-
),
|
|
1991
|
-
),
|
|
1992
|
-
})),
|
|
1993
|
-
};
|
|
1994
|
-
}
|
|
1995
|
-
if (kind === 'groups')
|
|
1996
|
-
return {
|
|
1997
|
-
list: kind,
|
|
1998
|
-
items: Object.entries(groupsOf(await context(cwd)))
|
|
1999
|
-
.filter(([k, v]) => f(k) || v.some(f))
|
|
2000
|
-
.map(([name, members]) => ({
|
|
2001
|
-
name,
|
|
2002
|
-
members,
|
|
2003
|
-
spreads: AUTO_SPREAD.includes(name),
|
|
2004
|
-
})),
|
|
2005
|
-
};
|
|
2006
|
-
if (kind === 'properties') {
|
|
2007
|
-
const props = filter
|
|
2008
|
-
? [...cssProperties()].filter(x => f(x)).slice(0, 60)
|
|
2009
|
-
: COMMON_PROPERTIES;
|
|
2010
|
-
return {list: kind, items: props.map(name => ({name})), common: !filter};
|
|
2011
|
-
}
|
|
2012
|
-
const ctx = await context(cwd);
|
|
2013
|
-
const {C} = ctx;
|
|
2014
|
-
if (kind === 'tokens') {
|
|
2015
|
-
const toks = Object.keys(ctx.project.core.tokenDefaults).filter(k => f(k));
|
|
2016
|
-
return {
|
|
2017
|
-
list: kind,
|
|
2018
|
-
items: toks.map(k => ({
|
|
2019
|
-
name: k,
|
|
2020
|
-
type: C.typeOf(k),
|
|
2021
|
-
default: String(ctx.project.core.tokenDefaults[k]),
|
|
2022
|
-
readBy: ctx.unchecked ? null : C.anyReader(k).length,
|
|
2023
|
-
})),
|
|
2024
|
-
};
|
|
2025
|
-
}
|
|
2026
|
-
// One item per part name: a name two components share lists both.
|
|
2027
|
-
/** @type {Map<string, {key: string, components: string[], states: string[]}>} */
|
|
2028
|
-
const byKey = new Map();
|
|
2029
|
-
for (const x of ctx.project.targets) {
|
|
2030
|
-
if (!f(x.key) && !f(x.component)) continue;
|
|
2031
|
-
const e = byKey.get(x.key) ?? {key: x.key, components: [], states: []};
|
|
2032
|
-
if (!e.components.includes(x.component)) e.components.push(x.component);
|
|
2033
|
-
for (const s of x.states) if (!e.states.includes(s)) e.states.push(s);
|
|
2034
|
-
byKey.set(x.key, e);
|
|
2035
|
-
}
|
|
2036
|
-
// A filter no part name holds lists the closest names, never nothing.
|
|
2037
|
-
if (!byKey.size && filter) {
|
|
2038
|
-
const word = filter.toLowerCase().replace(/s$/, '');
|
|
2039
|
-
// The parts of components whose doc lists the word, else the names
|
|
2040
|
-
// nearest it.
|
|
2041
|
-
const owners = Object.entries(ctx.project.components)
|
|
2042
|
-
.filter(([, info]) =>
|
|
2043
|
-
(info.keywords ?? []).some(
|
|
2044
|
-
k => k.toLowerCase().replace(/s$/, '') === word,
|
|
2045
|
-
),
|
|
2046
|
-
)
|
|
2047
|
-
.map(([name]) => name);
|
|
2048
|
-
const close = new Set(
|
|
2049
|
-
owners.length
|
|
2050
|
-
? ctx.project.targets
|
|
2051
|
-
.filter(x => owners.includes(x.component))
|
|
2052
|
-
.map(x => x.key)
|
|
2053
|
-
: nearest(
|
|
2054
|
-
word,
|
|
2055
|
-
ctx.project.targets.map(x => x.key),
|
|
2056
|
-
5,
|
|
2057
|
-
),
|
|
2058
|
-
);
|
|
2059
|
-
for (const x of ctx.project.targets) {
|
|
2060
|
-
if (!close.has(x.key)) continue;
|
|
2061
|
-
const e = byKey.get(x.key) ?? {key: x.key, components: [], states: []};
|
|
2062
|
-
if (!e.components.includes(x.component)) e.components.push(x.component);
|
|
2063
|
-
for (const st of x.states) if (!e.states.includes(st)) e.states.push(st);
|
|
2064
|
-
byKey.set(x.key, e);
|
|
2065
|
-
}
|
|
2066
|
-
}
|
|
2067
|
-
return {
|
|
2068
|
-
list: kind,
|
|
2069
|
-
items: [...byKey.values()].map(x => ({
|
|
2070
|
-
name: x.key,
|
|
2071
|
-
component: x.components.join(', '),
|
|
2072
|
-
group: familyOf(x.key),
|
|
2073
|
-
variants: C.variantValues(x.key),
|
|
2074
|
-
states: x.states,
|
|
2075
|
-
recorded: Boolean(C.MAP[x.key]),
|
|
2076
|
-
})),
|
|
2077
|
-
};
|
|
2078
|
-
}
|
|
2079
|
-
|
|
2080
|
-
/**
|
|
2081
|
-
* Read `--at` points: "x,y;x,y", "x,y x,y", repeated, or a flat "a,b,c,d".
|
|
2082
|
-
* Each number is a whole pixel; anything else is refused by name.
|
|
2083
|
-
* @param {string[]} at
|
|
2084
|
-
* @param {string | null} [file] the picture the points are on
|
|
2085
|
-
* @returns {Array<{x: number, y: number}>}
|
|
2086
|
-
*/
|
|
2087
|
-
export function parsePoints(at, file = null) {
|
|
2088
|
-
const words = at
|
|
2089
|
-
.join(' ')
|
|
2090
|
-
.split(/[;\s]+/)
|
|
2091
|
-
.filter(Boolean);
|
|
2092
|
-
// The picture named, never a made-up file.
|
|
2093
|
-
const example = file
|
|
2094
|
-
? `${HOW} ${quoteCommandArgument(file)} --at "40,20;300,180"`
|
|
2095
|
-
: `${HOW} --help`;
|
|
2096
|
-
if (!words.length)
|
|
2097
|
-
refuse(E.ERR_INVALID_ARGUMENT, '--at names no point; give x,y pairs.', {
|
|
2098
|
-
run: [example],
|
|
2099
|
-
});
|
|
2100
|
-
/** @type {Array<{x: number, y: number}>} */
|
|
2101
|
-
const points = [];
|
|
2102
|
-
for (const w of words) {
|
|
2103
|
-
const nums = w.split(',');
|
|
2104
|
-
if (!nums.every(n => /^-?\d+$/.test(n)))
|
|
2105
|
-
refuse(
|
|
2106
|
-
E.ERR_INVALID_ARGUMENT,
|
|
2107
|
-
`--at takes whole pixel numbers as x,y; "${w}" is not that.`,
|
|
2108
|
-
{run: [example]},
|
|
2109
|
-
);
|
|
2110
|
-
if (nums.length % 2)
|
|
2111
|
-
refuse(
|
|
2112
|
-
E.ERR_INVALID_ARGUMENT,
|
|
2113
|
-
`--at takes x,y pairs; "${w}" has an odd count of numbers.`,
|
|
2114
|
-
{run: [example]},
|
|
2115
|
-
);
|
|
2116
|
-
for (let i = 0; i < nums.length; i += 2)
|
|
2117
|
-
points.push({x: Number(nums[i]), y: Number(nums[i + 1])});
|
|
2118
|
-
}
|
|
2119
|
-
if (points.length > MAX_POINTS)
|
|
2120
|
-
refuse(
|
|
2121
|
-
E.ERR_INVALID_ARGUMENT,
|
|
2122
|
-
`--at reads at most ${MAX_POINTS} points; it got ${points.length}.`,
|
|
2123
|
-
{run: [example]},
|
|
2124
|
-
);
|
|
2125
|
-
return points;
|
|
2126
|
-
}
|
|
2127
|
-
|
|
2128
|
-
/**
|
|
2129
|
-
* The main colors of a PNG picture, or the exact color at points.
|
|
2130
|
-
* @param {string} file
|
|
2131
|
-
* @param {string} cwd
|
|
2132
|
-
* @param {string[]} at
|
|
2133
|
-
* @param {number | undefined} count
|
|
2134
|
-
*/
|
|
2135
|
-
function pictureColors(file, cwd, at, count) {
|
|
2136
|
-
const abs = path.resolve(cwd, file);
|
|
2137
|
-
if (!fs.existsSync(abs) || !fs.statSync(abs).isFile())
|
|
2138
|
-
throw new AstryxError(
|
|
2139
|
-
`${file} does not exist.`,
|
|
2140
|
-
[{name: `${HOW} --list parts`, reason: 'or ask in plain words'}],
|
|
2141
|
-
E.ERR_FILE_NOT_FOUND,
|
|
2142
|
-
);
|
|
2143
|
-
if (count != null && at.length)
|
|
2144
|
-
refuse(
|
|
2145
|
-
E.ERR_INVALID_ARGUMENT,
|
|
2146
|
-
'A count lists main colors; --at reads points. Give one of them.',
|
|
2147
|
-
{run: [`${HOW} ${quoteCommandArgument(file)} ${count}`]},
|
|
2148
|
-
);
|
|
2149
|
-
if (count != null && (!Number.isInteger(count) || count <= 0))
|
|
2150
|
-
refuse(
|
|
2151
|
-
E.ERR_INVALID_ARGUMENT,
|
|
2152
|
-
`The count must be a positive whole number, not "${count}".`,
|
|
2153
|
-
{run: [`${HOW} ${file} 5`]},
|
|
2154
|
-
);
|
|
2155
|
-
const points = at.length ? parsePoints(at, file) : null;
|
|
2156
|
-
// The header holds the size, so a huge picture is refused unread.
|
|
2157
|
-
const fd = fs.openSync(abs, 'r');
|
|
2158
|
-
const head = Buffer.alloc(8);
|
|
2159
|
-
fs.readSync(fd, head, 0, 8, 0);
|
|
2160
|
-
fs.closeSync(fd);
|
|
2161
|
-
const other = OTHER_FORMATS.find(([, sig]) =>
|
|
2162
|
-
sig.every((b, i) => head[i] === b),
|
|
2163
|
-
);
|
|
2164
|
-
if (other)
|
|
2165
|
-
refuse(
|
|
2166
|
-
E.ERR_INVALID_ARGUMENT,
|
|
2167
|
-
`${file} is a ${other[0]} picture; how reads PNG only. Save or convert it as PNG.`,
|
|
2168
|
-
{run: [`${HOW} --list`]},
|
|
2169
|
-
);
|
|
2170
|
-
/** @type {import('./_png.mjs').Picture} */
|
|
2171
|
-
let pic;
|
|
2172
|
-
/** @type {Buffer} */
|
|
2173
|
-
let bytes;
|
|
2174
|
-
try {
|
|
2175
|
-
pic = decodePng((bytes = fs.readFileSync(abs)));
|
|
2176
|
-
} catch (e) {
|
|
2177
|
-
throw new AstryxError(
|
|
2178
|
-
`Could not read ${file} as a PNG picture: ${e instanceof Error ? e.message : String(e)}.`,
|
|
2179
|
-
[{name: `${HOW} --list`, reason: 'what how reads'}],
|
|
2180
|
-
E.ERR_INVALID_ARGUMENT,
|
|
2181
|
-
);
|
|
2182
|
-
}
|
|
2183
|
-
if (points) {
|
|
2184
|
-
const outside = points.filter(
|
|
2185
|
-
p => p.x < 0 || p.y < 0 || p.x >= pic.width || p.y >= pic.height,
|
|
2186
|
-
);
|
|
2187
|
-
if (outside.length)
|
|
2188
|
-
refuse(
|
|
2189
|
-
E.ERR_INVALID_ARGUMENT,
|
|
2190
|
-
`${outside
|
|
2191
|
-
.slice(0, 3)
|
|
2192
|
-
.map(p => `${p.x},${p.y}`)
|
|
2193
|
-
.join(
|
|
2194
|
-
'; ',
|
|
2195
|
-
)} ${outside.length > 1 ? 'are' : 'is'} outside the picture, which is ${pic.width}x${pic.height} (x from 0 to ${pic.width - 1}, y from 0 to ${pic.height - 1}).`,
|
|
2196
|
-
{run: [`${HOW} ${quoteCommandArgument(file)} --at 0,0`]},
|
|
2197
|
-
);
|
|
2198
|
-
return {
|
|
2199
|
-
file,
|
|
2200
|
-
width: pic.width,
|
|
2201
|
-
height: pic.height,
|
|
2202
|
-
colors: null,
|
|
2203
|
-
points: colorsAt(pic, points),
|
|
2204
|
-
};
|
|
2205
|
-
}
|
|
2206
|
-
const colors = mainColors(pic, count ?? 14);
|
|
2207
|
-
// The look's traits, measured from the same pixels.
|
|
2208
|
-
const traits = colors.length ? readTraits(pic, pixelScale(bytes)) : null;
|
|
2209
|
-
// Every pixel see-through: no color shows, as with a 0-pixel picture.
|
|
2210
|
-
if (!colors.length)
|
|
2211
|
-
throw new AstryxError(
|
|
2212
|
-
`Could not read ${file} as a PNG picture: every pixel is fully see-through, so it has no visible colors.`,
|
|
2213
|
-
[{name: `${HOW} --list`, reason: 'what how reads'}],
|
|
2214
|
-
E.ERR_INVALID_ARGUMENT,
|
|
2215
|
-
);
|
|
2216
|
-
return {
|
|
2217
|
-
file,
|
|
2218
|
-
width: pic.width,
|
|
2219
|
-
height: pic.height,
|
|
2220
|
-
colors,
|
|
2221
|
-
points: null,
|
|
2222
|
-
traits,
|
|
2223
|
-
};
|
|
2224
|
-
}
|
|
2225
|
-
|
|
2226
|
-
/**
|
|
2227
|
-
* The aspects a setting changes, so a dial and the tokens it writes count as
|
|
2228
|
-
* one: corners (the corners dial and every radius token), the control size
|
|
2229
|
-
* (its size tokens, and the spacing dial, which scales control heights), the
|
|
2230
|
-
* spacing tokens (and the spacing dial), the line height (the leading
|
|
2231
|
-
* tokens), the text size (the text-size dial and the text
|
|
2232
|
-
* size tokens), and the heading weight (the headings dial, and the type
|
|
2233
|
-
* dial, which sets it). A checks size is its box: its width and its height.
|
|
2234
|
-
* Anything else is its own aspect.
|
|
2235
|
-
* @param {string} thing
|
|
2236
|
-
* @returns {string[]}
|
|
2237
|
-
*/
|
|
2238
|
-
function aspectsOf(thing) {
|
|
2239
|
-
if (thing === 'corners' || /^--radius-/.test(thing)) return ['corners'];
|
|
2240
|
-
if (/^--size-element-/.test(thing)) return ['control-size'];
|
|
2241
|
-
if (thing === 'spacing') return ['control-size', 'spacing'];
|
|
2242
|
-
if (/^--spacing-/.test(thing)) return ['spacing'];
|
|
2243
|
-
if (/^--text-[\w-]*leading$|^--line-height/.test(thing)) return ['leading'];
|
|
2244
|
-
if (thing === 'text-size' || /^--text-[\w-]*-size$/.test(thing))
|
|
2245
|
-
return ['text-size'];
|
|
2246
|
-
if (thing === 'headings' || thing === 'type') return ['heading-weight'];
|
|
2247
|
-
if (thing === 'width' || thing === 'height') return ['box-size'];
|
|
2248
|
-
return [thing];
|
|
2249
|
-
}
|
|
2250
|
-
|
|
2251
|
-
/**
|
|
2252
|
-
* The lines that give the checks a measured box: width and height at the
|
|
2253
|
-
* same px on each member that sizes its own box (sizesItsOwnBox), so a box
|
|
2254
|
-
* stays square and a radio stays round. The measured box is the size drawn;
|
|
2255
|
-
* each size moves by the same step from its own box (selfSizedBox), with a
|
|
2256
|
-
* `--when size:` line per size when the member has more than one, one
|
|
2257
|
-
* `--on checks` line where every member has the same box, else a line per
|
|
2258
|
-
* member. A size whose box the editor does not know keeps its own, named in
|
|
2259
|
-
* `kept`. No steps, with why, when no size can be read.
|
|
2260
|
-
* @param {import('./_settings.mjs').Ctx} ctx
|
|
2261
|
-
* @param {import('./_settings.mjs').Setting[]} settings
|
|
2262
|
-
* @param {number} px the measured box
|
|
2263
|
-
* @returns {{steps: import('./_how-commands.mjs').Step[], kept: string[], why?: undefined} | {steps?: undefined, kept?: undefined, why: string}}
|
|
2264
|
-
*/
|
|
2265
|
-
function checksBoxSteps(ctx, settings, px) {
|
|
2266
|
-
const C = /** @type {any} */ (ctx).C;
|
|
2267
|
-
const members = (FAMILIES.checks ?? []).filter(m => sizesItsOwnBox(C, m));
|
|
2268
|
-
if (!members.length) return {why: 'no member of checks sets its own box'};
|
|
2269
|
-
const drawn = selfSizedBox(ctx, settings, members[0]);
|
|
2270
|
-
if (!drawn)
|
|
2271
|
-
return {
|
|
2272
|
-
why:
|
|
2273
|
-
selfSizedWhy(ctx, settings, members[0]) ?? 'no size the editor knows',
|
|
2274
|
-
};
|
|
2275
|
-
const step = px - drawn.h;
|
|
2276
|
-
const sizes = /** @type {string[]} */ (
|
|
2277
|
-
C.variantValues(members[0])?.size ?? []
|
|
2278
|
-
);
|
|
2279
|
-
const {lines, unknown} = selfSizedBoxLines(
|
|
2280
|
-
ctx,
|
|
2281
|
-
settings,
|
|
2282
|
-
'checks',
|
|
2283
|
-
sizes.length > 1 ? sizes : [undefined],
|
|
2284
|
-
box => {
|
|
2285
|
-
const side = Math.max(1, Math.round(Math.max(box.w, box.h) + step));
|
|
2286
|
-
return {w: side, h: side};
|
|
2287
|
-
},
|
|
2288
|
-
sizes.length > 1,
|
|
2289
|
-
);
|
|
2290
|
-
const kept = unknown.map(u => `${u.sz ? `size ${u.sz}: ` : ''}${u.why}`);
|
|
2291
|
-
/** @type {import('./_how-commands.mjs').Step[]} */
|
|
2292
|
-
const steps = lines.flatMap(l => [
|
|
2293
|
-
{verb: 'set', thing: 'width', value: `${l.next.w}px`, ...l.flags},
|
|
2294
|
-
{verb: 'set', thing: 'height', value: `${l.next.h}px`, ...l.flags},
|
|
2295
|
-
]);
|
|
2296
|
-
if (!steps.length) return {why: kept.join('; ')};
|
|
2297
|
-
return {steps, kept};
|
|
2298
|
-
}
|
|
2299
|
-
|
|
2300
|
-
/**
|
|
2301
|
-
* The commands that make a picture's measured look, each checked as `set`
|
|
2302
|
-
* checks it: one result per trait, saying where it was read and how sure.
|
|
2303
|
-
* A trait the theme already sets keeps the theme's own value (what was typed
|
|
2304
|
-
* wins) and is named with the picture's reading instead.
|
|
2305
|
-
* @param {string} cwd
|
|
2306
|
-
* @param {string | undefined} name the theme asked for
|
|
2307
|
-
* @param {ReturnType<typeof readTraits>} read
|
|
2308
|
-
*/
|
|
2309
|
-
async function pictureLook(cwd, name, read) {
|
|
2310
|
-
const ctx = await context(cwd);
|
|
2311
|
-
const groups = groupsOf(ctx);
|
|
2312
|
-
/** @param {string} family @param {string} on */
|
|
2313
|
-
const familyHolds = (family, on) => {
|
|
2314
|
-
const families =
|
|
2315
|
-
family === 'controls' ? ['button-like', 'inputs'] : [family];
|
|
2316
|
-
// (The family itself holds what is set on it: a height set on a
|
|
2317
|
-
// control is saved on the controls.)
|
|
2318
|
-
return (
|
|
2319
|
-
on === family ||
|
|
2320
|
-
families.some(f => on === f || (groups[f] ?? []).includes(on))
|
|
2321
|
-
);
|
|
2322
|
-
};
|
|
2323
|
-
const env = await howTheme(ctx, cwd, name);
|
|
2324
|
-
const own = env.data.settings;
|
|
2325
|
-
/** @type {Array<{text: string, commands: string[], refused?: Array<{command: string, why: string, run?: string[]}>}>} */
|
|
2326
|
-
const results = [];
|
|
2327
|
-
const unsure = read.unsure.map(u => ({
|
|
2328
|
-
text: `${u.trait} on ${u.on}: ${u.why}`,
|
|
2329
|
-
...(u.options ? {options: u.options.map(st => render(st, env.slug))} : {}),
|
|
2330
|
-
}));
|
|
2331
|
-
for (const tr of read.traits) {
|
|
2332
|
-
const step = tr.step;
|
|
2333
|
-
// What the theme sets itself wins over a reading of the same aspect
|
|
2334
|
-
// (the corners dial and the radius tokens are one aspect, as are the
|
|
2335
|
-
// control size tokens), unless the two are on different parts.
|
|
2336
|
-
// A checks size is its box: width and height at the same px, per size.
|
|
2337
|
-
const checksSize = step.on === 'checks' && step.thing === 'height';
|
|
2338
|
-
// (A box the theme sizes, on the checks or on any one of them with
|
|
2339
|
-
// --only, its width or its height, is the theme's own.)
|
|
2340
|
-
const kept = own.find(s =>
|
|
2341
|
-
checksSize
|
|
2342
|
-
? /^(?:width|height)$/.test(s.thing) &&
|
|
2343
|
-
(s.on === 'checks' ||
|
|
2344
|
-
(FAMILIES.checks ?? []).includes(String(s.on ?? '')))
|
|
2345
|
-
: aspectsOf(s.thing).some(a => aspectsOf(step.thing).includes(a)) &&
|
|
2346
|
-
// (A part's own setting keeps a reading only for the family the
|
|
2347
|
-
// reading is of, or a member of it: `corners --on button` keeps a
|
|
2348
|
-
// button-like reading, never a theme-wide radius the card sets
|
|
2349
|
-
// apart from.)
|
|
2350
|
-
(!s.on || familyHolds(step.on ?? tr.on, String(s.on))),
|
|
2351
|
-
);
|
|
2352
|
-
const box = checksSize
|
|
2353
|
-
? checksBoxSteps(ctx, own, Number.parseFloat(String(step.value)))
|
|
2354
|
-
: null;
|
|
2355
|
-
if (kept) {
|
|
2356
|
-
unsure.push({
|
|
2357
|
-
text: `${tr.trait} on ${tr.on}: the picture reads ${tr.value} (${tr.read}); ${env.slug} sets ${kept.thing}${kept.on ? ` on ${kept.on}` : ''} ${kept.value} already, which stays`,
|
|
2358
|
-
options: (box?.steps ?? [step]).map(st => render(st, env.slug)),
|
|
2359
|
-
});
|
|
2360
|
-
continue;
|
|
2361
|
-
}
|
|
2362
|
-
if (box?.why) {
|
|
2363
|
-
unsure.push({
|
|
2364
|
-
text: `${tr.trait} on ${tr.on}: the picture reads ${tr.value} (${tr.read}); ${box.why}, so the box is not written`,
|
|
2365
|
-
});
|
|
2366
|
-
continue;
|
|
2367
|
-
}
|
|
2368
|
-
const {commands, refused} = checked(env, [box?.steps ?? [step]]);
|
|
2369
|
-
results.push({
|
|
2370
|
-
text: `${tr.trait} on ${tr.on}: ${tr.value}, read from ${tr.read}${tr.sure === 'about' ? ' (about: few boxes)' : ''}${box?.kept?.length ? `; width and height at each size, by the same step; kept: ${box.kept.join('; ')}` : box?.steps ? '; width and height at each size, by the same step' : ''}`,
|
|
2371
|
-
commands,
|
|
2372
|
-
...(refused.length ? {refused} : {}),
|
|
2373
|
-
});
|
|
2374
|
-
}
|
|
2375
|
-
return {
|
|
2376
|
-
theme: env.slug,
|
|
2377
|
-
themeChosenBy: env.chosenBy,
|
|
2378
|
-
...(env.note ? {themeNote: env.note} : {}),
|
|
2379
|
-
look: {
|
|
2380
|
-
source: 'picture',
|
|
2381
|
-
scale: read.scale,
|
|
2382
|
-
traits: read.traits.map(({step: _step, ...tr}) => tr),
|
|
2383
|
-
slots: read.slots,
|
|
2384
|
-
},
|
|
2385
|
-
results,
|
|
2386
|
-
unsure,
|
|
2387
|
-
};
|
|
2388
|
-
}
|