@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
|
@@ -1,800 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @file What one part of a theme shows: each CSS property the part reads,
|
|
5
|
-
* at rest and in each variant, with its final value in each mode, the
|
|
6
|
-
* declaration that gives it, the tokens it reads, and who decides it (Core,
|
|
7
|
-
* the theme it extends, or the theme's own file). The theme is any theme
|
|
8
|
-
* the project builds: an editor theme, a local theme or an installed theme
|
|
9
|
-
* package. It is loaded the way `theme build` loads it, and its tokens are
|
|
10
|
-
* resolved by Core. Nothing is written.
|
|
11
|
-
*
|
|
12
|
-
* @input the project folder, a theme name, a part name
|
|
13
|
-
* @output `themePartValues`: the `themeEdit.showPart` answer
|
|
14
|
-
* @position api/theme-edit — `show <theme> --on <part>` (_edit.mjs)
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
import * as path from 'node:path';
|
|
18
|
-
import {AstryxError} from '../error.mjs';
|
|
19
|
-
import {
|
|
20
|
-
coversProperty,
|
|
21
|
-
longhandsOf,
|
|
22
|
-
} from '../../foundation/runtime/css-tree.mjs';
|
|
23
|
-
import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
|
|
24
|
-
import {context} from './_context.mjs';
|
|
25
|
-
import {baseResolved} from './_project.mjs';
|
|
26
|
-
import {
|
|
27
|
-
compileTheme,
|
|
28
|
-
controlOf,
|
|
29
|
-
editedThemes,
|
|
30
|
-
loadTheme,
|
|
31
|
-
stateSlot,
|
|
32
|
-
} from './_settings.mjs';
|
|
33
|
-
import {censusStatesOf} from './_parts.mjs';
|
|
34
|
-
import {
|
|
35
|
-
mergeRules,
|
|
36
|
-
ownTokens,
|
|
37
|
-
partShows,
|
|
38
|
-
partValues,
|
|
39
|
-
resolveIn,
|
|
40
|
-
scopedTokens,
|
|
41
|
-
} from './_how-commands.mjs';
|
|
42
|
-
import {FAMILIES, P} from './_tables.mjs';
|
|
43
|
-
import {condition} from './_how.mjs';
|
|
44
|
-
|
|
45
|
-
/** @typedef {{light: Record<string, string>, dark: Record<string, string>}} ModeTokens */
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* A theme as the answer reads it: its tokens and part styles, and those of
|
|
49
|
-
* the theme it extends (Core's defaults when it extends none).
|
|
50
|
-
* @typedef {object} LoadedTheme
|
|
51
|
-
* @property {'editor' | 'local' | 'package' | 'bundled'} kind
|
|
52
|
-
* @property {ModeTokens} tokens
|
|
53
|
-
* @property {Record<string, any>} components
|
|
54
|
-
* @property {ModeTokens} parentTokens
|
|
55
|
-
* @property {Record<string, any>} parentComponents
|
|
56
|
-
* @property {ModeTokens} coreTokens - Core's own defaults
|
|
57
|
-
* @property {(property: string, part: string, when: string, state: string) => {when: string | null, state: string | null, exact: boolean} | null} [settingAt] - The property setting that wrote the theme's rule on the part under a rule key (`when|state` as the build writes them), as `set` took it.
|
|
58
|
-
*/
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* A logical property as the physical one it sets in a left-to-right,
|
|
62
|
-
* top-to-bottom page (`padding-inline-start` is `padding-left`): the two
|
|
63
|
-
* cascade as one property.
|
|
64
|
-
* @param {string} prop
|
|
65
|
-
*/
|
|
66
|
-
const physical = prop =>
|
|
67
|
-
prop
|
|
68
|
-
.replace(/-inline-start(?=$|-)/, '-left')
|
|
69
|
-
.replace(/-inline-end(?=$|-)/, '-right')
|
|
70
|
-
.replace(/-block-start(?=$|-)/, '-top')
|
|
71
|
-
.replace(/-block-end(?=$|-)/, '-bottom')
|
|
72
|
-
.replace(/^border-start-start-radius$/, 'border-top-left-radius')
|
|
73
|
-
.replace(/^border-start-end-radius$/, 'border-top-right-radius')
|
|
74
|
-
.replace(/^border-end-start-radius$/, 'border-bottom-left-radius')
|
|
75
|
-
.replace(/^border-end-end-radius$/, 'border-bottom-right-radius')
|
|
76
|
-
.replace(/^inset-inline-start$/, 'left')
|
|
77
|
-
.replace(/^inset-inline-end$/, 'right')
|
|
78
|
-
.replace(/^inset-block-start$/, 'top')
|
|
79
|
-
.replace(/^inset-block-end$/, 'bottom');
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Whether a rule that sets `a` also sets what `b` shows: `b` is `a`, a
|
|
83
|
-
* longhand of it, or a logical name of one of those.
|
|
84
|
-
* @param {string} a
|
|
85
|
-
* @param {string} b
|
|
86
|
-
*/
|
|
87
|
-
const sets = (a, b) =>
|
|
88
|
-
a === b ||
|
|
89
|
-
physical(a) === physical(b) ||
|
|
90
|
-
coversProperty(a, b) ||
|
|
91
|
-
coversProperty(physical(a), physical(b));
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* A part's rules with each rule's `@light` and `@dark` blocks taken out,
|
|
95
|
-
* and what those blocks set: a value for one mode of a property under the
|
|
96
|
-
* rule's key, not a condition of its own.
|
|
97
|
-
* @param {Record<string, any> | undefined} comp
|
|
98
|
-
*/
|
|
99
|
-
function foldModes(comp) {
|
|
100
|
-
/** @type {Record<string, any>} */
|
|
101
|
-
const rules = {};
|
|
102
|
-
/** @type {{when: string, state: string, property: string, mode: 'light' | 'dark', value: string}[]} */
|
|
103
|
-
const modeSets = [];
|
|
104
|
-
for (const [when, rule] of Object.entries(comp ?? {})) {
|
|
105
|
-
if (!rule || typeof rule !== 'object') {
|
|
106
|
-
rules[when] = rule;
|
|
107
|
-
continue;
|
|
108
|
-
}
|
|
109
|
-
/** @type {Record<string, any>} */
|
|
110
|
-
const kept = {};
|
|
111
|
-
for (const [k, v] of Object.entries(rule)) {
|
|
112
|
-
if (k !== '@light' && k !== '@dark') {
|
|
113
|
-
kept[k] = v;
|
|
114
|
-
continue;
|
|
115
|
-
}
|
|
116
|
-
const mode = k === '@light' ? 'light' : 'dark';
|
|
117
|
-
for (const [k2, v2] of Object.entries(v ?? {}))
|
|
118
|
-
if (v2 && typeof v2 === 'object')
|
|
119
|
-
for (const [k3, v3] of Object.entries(v2))
|
|
120
|
-
modeSets.push({
|
|
121
|
-
when,
|
|
122
|
-
state: k2,
|
|
123
|
-
property: kebab(k3),
|
|
124
|
-
mode,
|
|
125
|
-
value: String(v3),
|
|
126
|
-
});
|
|
127
|
-
else
|
|
128
|
-
modeSets.push({
|
|
129
|
-
when,
|
|
130
|
-
state: '',
|
|
131
|
-
property: kebab(k2),
|
|
132
|
-
mode,
|
|
133
|
-
value: String(v2),
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
rules[when] = kept;
|
|
137
|
-
}
|
|
138
|
-
return {rules, modeSets};
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* Whether two rule keys name one condition: a theme's own rule writes a
|
|
143
|
-
* variant `variant:ghost`, Core writes `variant=ghost`, in any word order.
|
|
144
|
-
* @param {string} a
|
|
145
|
-
* @param {string} b
|
|
146
|
-
*/
|
|
147
|
-
const sameWhen = (a, b) => {
|
|
148
|
-
/** @param {string} w */
|
|
149
|
-
const words = w =>
|
|
150
|
-
w
|
|
151
|
-
.split(/[\s+]/)
|
|
152
|
-
.filter(Boolean)
|
|
153
|
-
.map(x => (/^[a-z][\w-]*:[^\s:]+$/i.test(x) ? x.replace(':', '=') : x))
|
|
154
|
-
.sort()
|
|
155
|
-
.join(' ');
|
|
156
|
-
return words(a) === words(b);
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
/** @param {string} k */
|
|
160
|
-
const kebab = k =>
|
|
161
|
-
k.startsWith('--') ? k : k.replace(/[A-Z]/g, c => `-${c.toLowerCase()}`);
|
|
162
|
-
|
|
163
|
-
/** A token Core keeps to itself (`--_x`, `--astryx-x`). @param {string} t */
|
|
164
|
-
const isPrivate = t => /^--(?:_|astryx-)/.test(t);
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* The public tokens a declaration reads, in order, once each.
|
|
168
|
-
* @param {string} value
|
|
169
|
-
*/
|
|
170
|
-
function tokensIn(value) {
|
|
171
|
-
return [
|
|
172
|
-
...new Set(
|
|
173
|
-
[...String(value).matchAll(/var\(\s*(--[a-z0-9-]+)/gi)].map(m => m[1]),
|
|
174
|
-
),
|
|
175
|
-
].filter(t => !isPrivate(t));
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* The tokens a declaration reads in one mode, following each token's own
|
|
180
|
-
* value to the tokens it reads in turn.
|
|
181
|
-
* @param {string} value
|
|
182
|
-
* @param {Record<string, string>} map
|
|
183
|
-
*/
|
|
184
|
-
function tokenChain(value, map) {
|
|
185
|
-
/** @type {string[]} */
|
|
186
|
-
const out = [];
|
|
187
|
-
/** @param {string} v @param {number} depth */
|
|
188
|
-
const walk = (v, depth) => {
|
|
189
|
-
for (const t of tokensIn(v)) {
|
|
190
|
-
if (out.includes(t)) continue;
|
|
191
|
-
out.push(t);
|
|
192
|
-
if (depth < 8 && map[t] != null) walk(map[t], depth + 1);
|
|
193
|
-
}
|
|
194
|
-
};
|
|
195
|
-
walk(value, 0);
|
|
196
|
-
return out;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* Load a theme by name: an editor theme first (it is the one `show` names
|
|
201
|
-
* without more), else a theme the project lists (local, package or
|
|
202
|
-
* bundled), loaded as `theme build` loads it.
|
|
203
|
-
* @param {any} ctx the editor context
|
|
204
|
-
* @param {string} cwd
|
|
205
|
-
* @param {string} name
|
|
206
|
-
* @returns {Promise<LoadedTheme>}
|
|
207
|
-
*/
|
|
208
|
-
async function loadNamedTheme(ctx, cwd, name) {
|
|
209
|
-
const {core} = ctx.project;
|
|
210
|
-
const coreDefaults = await baseResolved(ctx.project, undefined);
|
|
211
|
-
if (editedThemes(cwd).includes(name)) {
|
|
212
|
-
const data = loadTheme(cwd, name);
|
|
213
|
-
const base = await baseResolved(ctx.project, data.like);
|
|
214
|
-
const compiled = compileTheme(ctx, data, base);
|
|
215
|
-
/** @param {import('./_settings.mjs').ThemeData['settings'][number]} st @param {string} part */
|
|
216
|
-
const reaches = (st, part) =>
|
|
217
|
-
st.on == null
|
|
218
|
-
? false
|
|
219
|
-
: st.on === part || (FAMILIES[st.on] ?? []).includes(part);
|
|
220
|
-
// A rule the theme writes on a part comes from a property setting on
|
|
221
|
-
// it, matched by the rule key the build writes for that setting (its
|
|
222
|
-
// `--when` and `--state` placed the way the build places them).
|
|
223
|
-
/** @type {NonNullable<LoadedTheme['settingAt']>} */
|
|
224
|
-
const settingAt = (property, part, when, state) => {
|
|
225
|
-
const t = ctx.project.target.get(part);
|
|
226
|
-
const mine = data.settings.filter(
|
|
227
|
-
s =>
|
|
228
|
-
reaches(s, part) &&
|
|
229
|
-
s.source === 'property' &&
|
|
230
|
-
sets(String(s.thing), property),
|
|
231
|
-
);
|
|
232
|
-
/** @param {any} s */
|
|
233
|
-
const slotOf = s =>
|
|
234
|
-
stateSlot(
|
|
235
|
-
t?.states ?? [],
|
|
236
|
-
s.state,
|
|
237
|
-
s.when,
|
|
238
|
-
controlOf(ctx, part),
|
|
239
|
-
t?.stateValues,
|
|
240
|
-
censusStatesOf(ctx.project, part),
|
|
241
|
-
);
|
|
242
|
-
const exact = mine.find(s => {
|
|
243
|
-
const slot = slotOf(s);
|
|
244
|
-
return slot.key === when && (slot.pseudo ?? '') === state;
|
|
245
|
-
});
|
|
246
|
-
if (exact)
|
|
247
|
-
return {
|
|
248
|
-
when: exact.when ?? null,
|
|
249
|
-
state: exact.state ?? null,
|
|
250
|
-
exact: true,
|
|
251
|
-
};
|
|
252
|
-
// (A setting with no --when that the build copies into each variant
|
|
253
|
-
// rule the part draws, as a card's fill: the part's, under the
|
|
254
|
-
// variant's own condition.)
|
|
255
|
-
const copied = mine.find(s => {
|
|
256
|
-
const slot = slotOf(s);
|
|
257
|
-
return (
|
|
258
|
-
s.when == null &&
|
|
259
|
-
when !== 'base' &&
|
|
260
|
-
slot.key === 'base' &&
|
|
261
|
-
(slot.pseudo ?? '') === state
|
|
262
|
-
);
|
|
263
|
-
});
|
|
264
|
-
return copied
|
|
265
|
-
? {when: null, state: copied.state ?? null, exact: false}
|
|
266
|
-
: null;
|
|
267
|
-
};
|
|
268
|
-
// (What the theme's settings make. What a person adds by hand below
|
|
269
|
-
// the settings in its theme file is not read here.)
|
|
270
|
-
const tokens = ownTokens(compiled, base, core);
|
|
271
|
-
const components = mergeComponents(
|
|
272
|
-
base.components,
|
|
273
|
-
compiled.components ?? {},
|
|
274
|
-
);
|
|
275
|
-
return {
|
|
276
|
-
kind: 'editor',
|
|
277
|
-
tokens,
|
|
278
|
-
components,
|
|
279
|
-
parentTokens: {light: base.light, dark: base.dark},
|
|
280
|
-
parentComponents: base.components ?? {},
|
|
281
|
-
coreTokens: {light: coreDefaults.light, dark: coreDefaults.dark},
|
|
282
|
-
settingAt,
|
|
283
|
-
};
|
|
284
|
-
}
|
|
285
|
-
const found = await findProjectTheme(cwd, name);
|
|
286
|
-
if (!found)
|
|
287
|
-
throw new AstryxError(
|
|
288
|
-
`No theme named "${name}" in this project: an editor theme, a local theme or an installed theme package.`,
|
|
289
|
-
[
|
|
290
|
-
{name: 'astryx theme list', reason: 'the themes this project has'},
|
|
291
|
-
{name: `${P} new ${name} --like neutral`, reason: 'or start one'},
|
|
292
|
-
],
|
|
293
|
-
ERROR_CODES.ERR_UNKNOWN_THEME,
|
|
294
|
-
);
|
|
295
|
-
const {loadThemeInput} = await import('../theme/build/build.mjs');
|
|
296
|
-
const file = path.resolve(found.sourceDir, found.entry);
|
|
297
|
-
const loaded = await loadThemeInput(file, {cwd, name: found.slug});
|
|
298
|
-
if (!loaded?.theme)
|
|
299
|
-
throw new AstryxError(
|
|
300
|
-
`The ${found.slug} theme does not load${loaded?.error ? `: ${loaded.error.message}` : ''}.`,
|
|
301
|
-
[
|
|
302
|
-
{
|
|
303
|
-
name: `astryx theme build ${path.relative(cwd, file) || file} --check`,
|
|
304
|
-
reason: 'see why',
|
|
305
|
-
},
|
|
306
|
-
],
|
|
307
|
-
ERROR_CODES.ERR_THEME_INVALID,
|
|
308
|
-
);
|
|
309
|
-
const theme = loaded.theme;
|
|
310
|
-
// The theme it extends, made again from its input as Core made it; Core's
|
|
311
|
-
// defaults when it extends none.
|
|
312
|
-
const parentInput = loaded.chain[0];
|
|
313
|
-
const parent = parentInput ? core.defineTheme(parentInput) : null;
|
|
314
|
-
return {
|
|
315
|
-
kind: found.source,
|
|
316
|
-
tokens: {
|
|
317
|
-
light: core.resolveThemeTokens(theme, {mode: 'light'}),
|
|
318
|
-
dark: core.resolveThemeTokens(theme, {mode: 'dark'}),
|
|
319
|
-
},
|
|
320
|
-
components: theme.components ?? {},
|
|
321
|
-
parentTokens: parent
|
|
322
|
-
? {
|
|
323
|
-
light: core.resolveThemeTokens(parent, {mode: 'light'}),
|
|
324
|
-
dark: core.resolveThemeTokens(parent, {mode: 'dark'}),
|
|
325
|
-
}
|
|
326
|
-
: {light: coreDefaults.light, dark: coreDefaults.dark},
|
|
327
|
-
parentComponents: parent?.components ?? {},
|
|
328
|
-
coreTokens: {light: coreDefaults.light, dark: coreDefaults.dark},
|
|
329
|
-
};
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
/**
|
|
333
|
-
* Part styles with another theme's on top, rule by rule (a rule that sets
|
|
334
|
-
* one property keeps the others).
|
|
335
|
-
* @param {Record<string, any>} under
|
|
336
|
-
* @param {Record<string, any>} over
|
|
337
|
-
*/
|
|
338
|
-
function mergeComponents(under, over) {
|
|
339
|
-
/** @type {Record<string, any>} */
|
|
340
|
-
const out = {};
|
|
341
|
-
for (const part of new Set([
|
|
342
|
-
...Object.keys(under ?? {}),
|
|
343
|
-
...Object.keys(over ?? {}),
|
|
344
|
-
]))
|
|
345
|
-
out[part] = mergeRules(under?.[part] ?? {}, over?.[part] ?? {});
|
|
346
|
-
return out;
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
/**
|
|
350
|
-
* One property of the part, as the answer gives it.
|
|
351
|
-
* @typedef {import('./theme-edit.type.mjs').ThemeEditPartValue} PartValue
|
|
352
|
-
*/
|
|
353
|
-
|
|
354
|
-
/**
|
|
355
|
-
* What one part of a theme shows.
|
|
356
|
-
* @param {string} cwd
|
|
357
|
-
* @param {string} name the theme
|
|
358
|
-
* @param {string} part
|
|
359
|
-
* @returns {Promise<import('./theme-edit.type.mjs').ThemeEditShowPartResponse>}
|
|
360
|
-
*/
|
|
361
|
-
export async function themePartValues(cwd, name, part) {
|
|
362
|
-
const ctx = await context(cwd);
|
|
363
|
-
const key = String(part).trim().toLowerCase();
|
|
364
|
-
if (Object.hasOwn(FAMILIES, key) && !ctx.project.target.has(key))
|
|
365
|
-
throw new AstryxError(
|
|
366
|
-
`${key} is a group; --on takes one part of it: ${FAMILIES[key].join(', ')}.`,
|
|
367
|
-
FAMILIES[key].slice(0, 3).map((/** @type {string} */ m) => ({
|
|
368
|
-
name: `${P} show ${name} --on ${m}`,
|
|
369
|
-
reason: 'one part',
|
|
370
|
-
})),
|
|
371
|
-
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
372
|
-
);
|
|
373
|
-
if (!ctx.project.target.has(key))
|
|
374
|
-
throw new AstryxError(
|
|
375
|
-
`No part named "${part}". --on takes a part, as \`${P} how --list parts\` lists them.`,
|
|
376
|
-
[{name: `${P} how --list parts`, reason: 'every part'}],
|
|
377
|
-
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
378
|
-
);
|
|
379
|
-
if (ctx.unchecked)
|
|
380
|
-
throw new AstryxError(
|
|
381
|
-
`What ${key} reads cannot be worked out here: ${ctx.unchecked}`,
|
|
382
|
-
[{name: 'astryx doctor', reason: 'see why'}],
|
|
383
|
-
ERROR_CODES.ERR_RENDER_FAILED,
|
|
384
|
-
);
|
|
385
|
-
const theme = await loadNamedTheme(ctx, cwd, name);
|
|
386
|
-
// A rule's `@light` or `@dark` block is a value for one mode, read into
|
|
387
|
-
// that mode's value below, not a condition.
|
|
388
|
-
const folded = foldModes(theme.components?.[key]);
|
|
389
|
-
const parentFolded = foldModes(theme.parentComponents?.[key]);
|
|
390
|
-
const shows = partShows(
|
|
391
|
-
ctx.C,
|
|
392
|
-
{},
|
|
393
|
-
{components: {...theme.components, [key]: folded.rules}},
|
|
394
|
-
theme.tokens,
|
|
395
|
-
key,
|
|
396
|
-
);
|
|
397
|
-
const own = partValues(folded.rules);
|
|
398
|
-
const inherited = partValues(parentFolded.rules);
|
|
399
|
-
const themeRules = mergeRules(folded.rules);
|
|
400
|
-
const parentRules = mergeRules(parentFolded.rules);
|
|
401
|
-
/**
|
|
402
|
-
* The tokens inside the part under a condition, in each mode: the
|
|
403
|
-
* theme's, the theme it extends, and Core's, each with what that theme's
|
|
404
|
-
* own rule on the part sets.
|
|
405
|
-
* @param {string} when
|
|
406
|
-
*/
|
|
407
|
-
const inside = when => {
|
|
408
|
-
/**
|
|
409
|
-
* A mode's tokens with what the rules' `@light` or `@dark` blocks set
|
|
410
|
-
* for that mode on the part, at rest and under this condition.
|
|
411
|
-
* @param {Record<string, string>} map
|
|
412
|
-
* @param {typeof folded.modeSets} sets
|
|
413
|
-
* @param {'light' | 'dark'} mode
|
|
414
|
-
*/
|
|
415
|
-
const withBlocks = (map, sets, mode) => {
|
|
416
|
-
const out = {...map};
|
|
417
|
-
for (const w of ['base', when])
|
|
418
|
-
for (const m of sets)
|
|
419
|
-
if (
|
|
420
|
-
m.mode === mode &&
|
|
421
|
-
!m.state &&
|
|
422
|
-
m.property.startsWith('--') &&
|
|
423
|
-
sameWhen(m.when, w)
|
|
424
|
-
)
|
|
425
|
-
out[m.property] = m.value;
|
|
426
|
-
return out;
|
|
427
|
-
};
|
|
428
|
-
const tl = scopedTokens(themeRules, theme.tokens.light, when);
|
|
429
|
-
const td = scopedTokens(themeRules, theme.tokens.dark, when);
|
|
430
|
-
const pl = scopedTokens(parentRules, theme.parentTokens.light, when);
|
|
431
|
-
const pd = scopedTokens(parentRules, theme.parentTokens.dark, when);
|
|
432
|
-
return {
|
|
433
|
-
theme: {
|
|
434
|
-
light: withBlocks(tl, folded.modeSets, 'light'),
|
|
435
|
-
dark: withBlocks(td, folded.modeSets, 'dark'),
|
|
436
|
-
},
|
|
437
|
-
parent: {
|
|
438
|
-
light: withBlocks(pl, parentFolded.modeSets, 'light'),
|
|
439
|
-
dark: withBlocks(pd, parentFolded.modeSets, 'dark'),
|
|
440
|
-
},
|
|
441
|
-
};
|
|
442
|
-
};
|
|
443
|
-
/**
|
|
444
|
-
* Whether a mode block is the theme's own: not taken unchanged from the
|
|
445
|
-
* theme it extends.
|
|
446
|
-
* @param {(typeof folded.modeSets)[number]} m
|
|
447
|
-
*/
|
|
448
|
-
const ownBlock = m =>
|
|
449
|
-
!parentFolded.modeSets.some(
|
|
450
|
-
p =>
|
|
451
|
-
p.mode === m.mode &&
|
|
452
|
-
p.property === m.property &&
|
|
453
|
-
p.state === m.state &&
|
|
454
|
-
p.value === m.value &&
|
|
455
|
-
sameWhen(p.when, m.when),
|
|
456
|
-
);
|
|
457
|
-
/**
|
|
458
|
-
* The tokens the theme's own mode blocks set inside the part under a
|
|
459
|
-
* condition: the ones a value there reads in that mode (a block at rest,
|
|
460
|
-
* or under the same condition, with no state).
|
|
461
|
-
* @param {string} when
|
|
462
|
-
* @param {boolean} [any] the theme's and the base's blocks alike
|
|
463
|
-
*/
|
|
464
|
-
const blockTokensAt = (when, any = false) =>
|
|
465
|
-
new Set(
|
|
466
|
-
folded.modeSets
|
|
467
|
-
.filter(
|
|
468
|
-
m =>
|
|
469
|
-
m.property.startsWith('--') &&
|
|
470
|
-
!m.state &&
|
|
471
|
-
['base', when].some(w => sameWhen(m.when, w)) &&
|
|
472
|
-
(any || ownBlock(m)),
|
|
473
|
-
)
|
|
474
|
-
.map(m => m.property),
|
|
475
|
-
);
|
|
476
|
-
/** @type {PartValue[]} */
|
|
477
|
-
const values = [];
|
|
478
|
-
/** @type {WeakMap<PartValue, {when: string, state: string, own: boolean}>} */
|
|
479
|
-
const rawKey = new WeakMap();
|
|
480
|
-
// The theme layer comes after Core's styles: a property a rule on the
|
|
481
|
-
// part sets, in the same variant or at rest, is what shows for every
|
|
482
|
-
// property it sets, whatever Core writes.
|
|
483
|
-
const ruleProps = [...own.keys()].map(k => k.split('|'));
|
|
484
|
-
/** @param {string} when @param {string} property */
|
|
485
|
-
const ruledOver = (when, property) =>
|
|
486
|
-
ruleProps.some(
|
|
487
|
-
([w, st, p]) =>
|
|
488
|
-
!st &&
|
|
489
|
-
(w === when || w === 'base') &&
|
|
490
|
-
p !== property &&
|
|
491
|
-
sets(p, property),
|
|
492
|
-
);
|
|
493
|
-
// A shorthand in a rule whose every longhand a later declaration of the
|
|
494
|
-
// same rule sets shows none of its own value.
|
|
495
|
-
const order = [...own.keys()];
|
|
496
|
-
/** @param {string} k */
|
|
497
|
-
const overwritten = k => {
|
|
498
|
-
const [when, state, property] = k.split('|');
|
|
499
|
-
const parts = [...longhandsOf(property)].map(physical);
|
|
500
|
-
if (!parts.length) return false;
|
|
501
|
-
const later = order
|
|
502
|
-
.slice(order.indexOf(k) + 1)
|
|
503
|
-
.map(x => x.split('|'))
|
|
504
|
-
.filter(([w, st]) => w === when && st === state)
|
|
505
|
-
.map(([, , p]) => physical(p));
|
|
506
|
-
return parts.every(p => later.some(l => l === p || longhandsOf(l).has(p)));
|
|
507
|
-
};
|
|
508
|
-
const t = ctx.project.target.get(key);
|
|
509
|
-
/**
|
|
510
|
-
* A rule key's condition as the flags `set` takes, the way `how` gives
|
|
511
|
-
* it: a theme rule a property setting wrote takes that setting's own
|
|
512
|
-
* --when and --state; any other key is read the way Core reads a style
|
|
513
|
-
* key (`variant:ghost+selected`, `variant=ghost`) and given to the same
|
|
514
|
-
* converter `how <part>` uses. A condition no flag reaches keeps Core's
|
|
515
|
-
* words and says why.
|
|
516
|
-
* @param {string} when @param {string} state
|
|
517
|
-
* @param {string | null} ruleProperty the property of the theme's own
|
|
518
|
-
* rule, or null for one of Core's
|
|
519
|
-
* @returns {{when: string | null, state: string | null, notSettable?: string}}
|
|
520
|
-
*/
|
|
521
|
-
const condOf = (when, state, ruleProperty) => {
|
|
522
|
-
const wrote =
|
|
523
|
-
ruleProperty != null && theme.settingAt
|
|
524
|
-
? theme.settingAt(ruleProperty, key, when, state)
|
|
525
|
-
: null;
|
|
526
|
-
if (wrote?.exact) return {when: wrote.when, state: wrote.state};
|
|
527
|
-
const words = [
|
|
528
|
-
...(when === 'base' ? [] : when.split(/\+|\s+/)),
|
|
529
|
-
...(state ? [state] : []),
|
|
530
|
-
]
|
|
531
|
-
.filter(Boolean)
|
|
532
|
-
.map(w =>
|
|
533
|
-
/^[a-z][\w-]*:[^\s:]+$/i.test(w)
|
|
534
|
-
? w.replace(':', '=')
|
|
535
|
-
: /^[a-z][\w-]*$/i.test(w) && (t?.states ?? []).includes(w)
|
|
536
|
-
? `${w}=${t?.stateValues?.[w] ?? w}`
|
|
537
|
-
: w,
|
|
538
|
-
);
|
|
539
|
-
const coreCond = words.join(' ');
|
|
540
|
-
const flags = condition(ctx, key, coreCond);
|
|
541
|
-
const unsettable = /\(not settable: (.*)\)$/.exec(flags);
|
|
542
|
-
if (unsettable)
|
|
543
|
-
return {
|
|
544
|
-
// (Core's attribute words in one order, so one condition is one row.)
|
|
545
|
-
when: [
|
|
546
|
-
...words.filter(w => /^[a-z][\w-]*=/i.test(w)).sort(),
|
|
547
|
-
...words.filter(w => !/^[a-z][\w-]*=/i.test(w)),
|
|
548
|
-
].join(' '),
|
|
549
|
-
state: null,
|
|
550
|
-
notSettable: unsettable[1],
|
|
551
|
-
};
|
|
552
|
-
return {
|
|
553
|
-
when: /--when (\S+)/.exec(flags)?.[1] ?? null,
|
|
554
|
-
state: /--state (\S+)/.exec(flags)?.[1] ?? null,
|
|
555
|
-
};
|
|
556
|
-
};
|
|
557
|
-
for (const [k, v] of shows) {
|
|
558
|
-
const [when, state, property] = k.split('|');
|
|
559
|
-
if (!own.has(k) && ruledOver(when, property)) continue;
|
|
560
|
-
if (own.has(k) && overwritten(k)) continue;
|
|
561
|
-
const ruleKey = own.has(k) ? k : `base||${property}`;
|
|
562
|
-
const at = inside(when);
|
|
563
|
-
const light = tokenChain(v.raw, at.theme.light);
|
|
564
|
-
const dark = tokenChain(v.raw, at.theme.dark);
|
|
565
|
-
/** @param {ModeTokens} a @param {ModeTokens} b */
|
|
566
|
-
const changed = (a, b) => [
|
|
567
|
-
...light.filter(t => a.light[t] !== b.light[t]),
|
|
568
|
-
...dark.filter(t => a.dark[t] !== b.dark[t]),
|
|
569
|
-
];
|
|
570
|
-
const mine = changed(at.theme, at.parent);
|
|
571
|
-
/** @type {PartValue['source']} */
|
|
572
|
-
let source = 'core';
|
|
573
|
-
if (own.has(ruleKey) && own.get(ruleKey) === v.raw) {
|
|
574
|
-
// A rule on the part: the theme's own, or the one it extends with
|
|
575
|
-
// the tokens it reads changed inside the part.
|
|
576
|
-
const inheritedRule = inherited.get(ruleKey) === v.raw;
|
|
577
|
-
if (!inheritedRule) source = 'theme';
|
|
578
|
-
else source = mine.length ? 'theme' : 'base';
|
|
579
|
-
} else if (mine.length) {
|
|
580
|
-
source = 'theme';
|
|
581
|
-
} else if (changed(at.parent, theme.coreTokens).length) {
|
|
582
|
-
source = 'base';
|
|
583
|
-
}
|
|
584
|
-
// A value that reads a token a mode block sets on the part is the
|
|
585
|
-
// theme's, through that token.
|
|
586
|
-
const blockTokens = blockTokensAt(when);
|
|
587
|
-
if ([...light, ...dark].some(t => blockTokens.has(t))) source = 'theme';
|
|
588
|
-
const cond = condOf(when, state, own.has(k) ? property : null);
|
|
589
|
-
const row = {
|
|
590
|
-
property,
|
|
591
|
-
...cond,
|
|
592
|
-
value: pairOf(
|
|
593
|
-
.../** @type {[string, string]} */ (
|
|
594
|
-
[...light, ...dark].some(t => blockTokensAt(when, true).has(t))
|
|
595
|
-
? [
|
|
596
|
-
resolveIn(v.raw, at.theme.light, 'light'),
|
|
597
|
-
resolveIn(v.raw, at.theme.dark, 'dark'),
|
|
598
|
-
]
|
|
599
|
-
: [v.light, v.dark]
|
|
600
|
-
),
|
|
601
|
-
),
|
|
602
|
-
expression: v.raw,
|
|
603
|
-
tokens: light.join(' ') === dark.join(' ') ? light : {light, dark},
|
|
604
|
-
source,
|
|
605
|
-
};
|
|
606
|
-
values.push(row);
|
|
607
|
-
rawKey.set(row, {when, state, own: own.has(k)});
|
|
608
|
-
}
|
|
609
|
-
// What a rule's `@light` or `@dark` block sets: that mode's value of the
|
|
610
|
-
// property under the rule's condition, with that mode's declaration and
|
|
611
|
-
// tokens; a block with no row of its own (a state Core's map leaves out,
|
|
612
|
-
// a property the part reads nowhere else) is a row of its own.
|
|
613
|
-
for (const m of folded.modeSets) {
|
|
614
|
-
const other = m.mode === 'light' ? 'dark' : 'light';
|
|
615
|
-
const at = inside(m.when);
|
|
616
|
-
const shown = orNull(resolveIn(m.value, at.theme[m.mode], m.mode));
|
|
617
|
-
const chain = tokenChain(m.value, at.theme[m.mode]);
|
|
618
|
-
/** @param {any} x @param {'light' | 'dark'} mode */
|
|
619
|
-
const half = (x, mode) =>
|
|
620
|
-
x && typeof x === 'object' && !Array.isArray(x) ? x[mode] : x;
|
|
621
|
-
/** @param {any} a @param {any} b */
|
|
622
|
-
const pair = (a, b) =>
|
|
623
|
-
JSON.stringify(a) === JSON.stringify(b)
|
|
624
|
-
? a
|
|
625
|
-
: // (A mode with nothing under it is left out: not shown yet.)
|
|
626
|
-
Object.fromEntries(
|
|
627
|
-
/** @type {[string, any][]} */ (
|
|
628
|
-
m.mode === 'light'
|
|
629
|
-
? [
|
|
630
|
-
['light', a],
|
|
631
|
-
['dark', b],
|
|
632
|
-
]
|
|
633
|
-
: [
|
|
634
|
-
['light', b],
|
|
635
|
-
['dark', a],
|
|
636
|
-
]
|
|
637
|
-
).filter(([, x]) => x !== undefined),
|
|
638
|
-
);
|
|
639
|
-
let alone = false;
|
|
640
|
-
let target = values.find(v => {
|
|
641
|
-
const r = rawKey.get(v);
|
|
642
|
-
return (
|
|
643
|
-
v.property === m.property &&
|
|
644
|
-
r != null &&
|
|
645
|
-
sameWhen(r.when, m.when) &&
|
|
646
|
-
r.state === m.state
|
|
647
|
-
);
|
|
648
|
-
});
|
|
649
|
-
if (!target) {
|
|
650
|
-
// The other mode shows what the same condition shows without the
|
|
651
|
-
// block: its own row, else the same variant at rest (Core's state
|
|
652
|
-
// conditions are not rows of their own), else the part at rest.
|
|
653
|
-
const cond = condOf(m.when, m.state, m.property);
|
|
654
|
-
const base =
|
|
655
|
-
values.find(
|
|
656
|
-
v =>
|
|
657
|
-
v.property === m.property &&
|
|
658
|
-
v.when === cond.when &&
|
|
659
|
-
v.state === cond.state,
|
|
660
|
-
) ??
|
|
661
|
-
(cond.when != null
|
|
662
|
-
? values.find(
|
|
663
|
-
v =>
|
|
664
|
-
v.property === m.property &&
|
|
665
|
-
v.when === cond.when &&
|
|
666
|
-
v.state == null,
|
|
667
|
-
)
|
|
668
|
-
: undefined) ??
|
|
669
|
-
values.find(
|
|
670
|
-
v => v.property === m.property && v.when == null && v.state == null,
|
|
671
|
-
);
|
|
672
|
-
alone = !base;
|
|
673
|
-
target = {
|
|
674
|
-
property: m.property,
|
|
675
|
-
...cond,
|
|
676
|
-
value: base ? half(base.value, other) : null,
|
|
677
|
-
expression: base ? half(base.expression, other) : '',
|
|
678
|
-
tokens: base ? half(base.tokens, other) : [],
|
|
679
|
-
source: 'theme',
|
|
680
|
-
};
|
|
681
|
-
// (Filled in for this mode below, as for a row the block joins.)
|
|
682
|
-
target.value = pair(null, target.value);
|
|
683
|
-
target.expression = pair('', target.expression);
|
|
684
|
-
target.tokens = pair([], target.tokens);
|
|
685
|
-
values.push(target);
|
|
686
|
-
rawKey.set(target, {when: m.when, state: m.state, own: true});
|
|
687
|
-
}
|
|
688
|
-
target.value = pair(shown, half(target.value, other));
|
|
689
|
-
target.expression = pair(m.value, half(target.expression, other));
|
|
690
|
-
target.tokens = pair(chain, half(target.tokens, other));
|
|
691
|
-
// (A row of its own with nothing else under its condition: the other
|
|
692
|
-
// mode is not shown yet, so it is left out, not given as no value.)
|
|
693
|
-
if (alone) {
|
|
694
|
-
target.value = /** @type {any} */ ({[m.mode]: shown});
|
|
695
|
-
target.expression = /** @type {any} */ ({[m.mode]: m.value});
|
|
696
|
-
target.tokens = /** @type {any} */ ({[m.mode]: chain});
|
|
697
|
-
}
|
|
698
|
-
// (A block the theme takes as it is from the theme it extends is the
|
|
699
|
-
// base's.)
|
|
700
|
-
const inherited = !ownBlock(m);
|
|
701
|
-
target.source = inherited ? 'base' : 'theme';
|
|
702
|
-
}
|
|
703
|
-
// At rest first, then each variant, in the order the part reads them.
|
|
704
|
-
values.sort((a, b) => Number(a.when != null) - Number(b.when != null));
|
|
705
|
-
// A longhand Core writes beside its own shorthand, with the same value,
|
|
706
|
-
// says nothing more (a button's four corner radii beside its radius).
|
|
707
|
-
// One condition Core writes in two word orders reads as one row.
|
|
708
|
-
const seenRows = new Set();
|
|
709
|
-
// A condition a theme rule sets shows the rule's value, not Core's too.
|
|
710
|
-
const ruled = new Set(
|
|
711
|
-
values
|
|
712
|
-
.filter(v => rawKey.get(v)?.own)
|
|
713
|
-
.map(v => JSON.stringify([v.property, v.when, v.state])),
|
|
714
|
-
);
|
|
715
|
-
const unique = values.filter(v => {
|
|
716
|
-
if (
|
|
717
|
-
!rawKey.get(v)?.own &&
|
|
718
|
-
ruled.has(JSON.stringify([v.property, v.when, v.state]))
|
|
719
|
-
)
|
|
720
|
-
return false;
|
|
721
|
-
const id = JSON.stringify([
|
|
722
|
-
v.property,
|
|
723
|
-
v.when,
|
|
724
|
-
v.state,
|
|
725
|
-
v.value,
|
|
726
|
-
v.expression,
|
|
727
|
-
]);
|
|
728
|
-
if (seenRows.has(id)) return false;
|
|
729
|
-
seenRows.add(id);
|
|
730
|
-
return true;
|
|
731
|
-
});
|
|
732
|
-
const said = unique.filter(
|
|
733
|
-
v =>
|
|
734
|
-
!unique.some(
|
|
735
|
-
o =>
|
|
736
|
-
o !== v &&
|
|
737
|
-
o.when === v.when &&
|
|
738
|
-
o.state === v.state &&
|
|
739
|
-
o.property !== v.property &&
|
|
740
|
-
sets(o.property, v.property) &&
|
|
741
|
-
!sets(v.property, o.property) &&
|
|
742
|
-
JSON.stringify(o.value) === JSON.stringify(v.value) &&
|
|
743
|
-
o.expression === v.expression,
|
|
744
|
-
),
|
|
745
|
-
);
|
|
746
|
-
return {
|
|
747
|
-
type: 'themeEdit.showPart',
|
|
748
|
-
data: {theme: name, kind: theme.kind, part: key, values: said},
|
|
749
|
-
};
|
|
750
|
-
}
|
|
751
|
-
|
|
752
|
-
/**
|
|
753
|
-
* A value in each mode, one value when the modes agree; a value with a
|
|
754
|
-
* var() still in it is no value.
|
|
755
|
-
* @param {string} light
|
|
756
|
-
* @param {string} dark
|
|
757
|
-
*/
|
|
758
|
-
const pairOf = (light, dark) =>
|
|
759
|
-
light === dark ? orNull(light) : {light: orNull(light), dark: orNull(dark)};
|
|
760
|
-
|
|
761
|
-
/**
|
|
762
|
-
* A value with a var() still in it is no value: null.
|
|
763
|
-
* @param {string} v
|
|
764
|
-
*/
|
|
765
|
-
const orNull = v => (/var\(/.test(v) ? null : v);
|
|
766
|
-
|
|
767
|
-
/**
|
|
768
|
-
* A theme the project lists, by slug. A slug two packages provide is the
|
|
769
|
-
* one the app records under that slug; with none recorded, it is refused,
|
|
770
|
-
* naming the packages: `show` selects no package.
|
|
771
|
-
* @param {string} cwd
|
|
772
|
-
* @param {string} name
|
|
773
|
-
*/
|
|
774
|
-
async function findProjectTheme(cwd, name) {
|
|
775
|
-
const {findTheme, readThemeListState} = await import('../theme/_adapter.mjs');
|
|
776
|
-
try {
|
|
777
|
-
return await findTheme(name, {cwd, includeLocal: true});
|
|
778
|
-
} catch (e) {
|
|
779
|
-
const err = /** @type {any} */ (e);
|
|
780
|
-
if (err?.code !== ERROR_CODES.ERR_AMBIGUOUS_THEME) throw e;
|
|
781
|
-
const recorded = (() => {
|
|
782
|
-
try {
|
|
783
|
-
return readThemeListState(cwd).themes[name] ?? null;
|
|
784
|
-
} catch {
|
|
785
|
-
return null;
|
|
786
|
-
}
|
|
787
|
-
})();
|
|
788
|
-
if (recorded)
|
|
789
|
-
return findTheme(name, {cwd, includeLocal: true, package: recorded});
|
|
790
|
-
// Each package's `theme add`, which takes --package; once the app
|
|
791
|
-
// records one, show reads that one.
|
|
792
|
-
throw new AstryxError(
|
|
793
|
-
`Theme "${name}" is provided by more than one package, and the app records none of them, so show cannot tell which one to read. Add the one you use to the app; show then reads it.`,
|
|
794
|
-
err.suggestions ?? [
|
|
795
|
-
{name: 'astryx theme list', reason: 'the packages that provide it'},
|
|
796
|
-
],
|
|
797
|
-
ERROR_CODES.ERR_AMBIGUOUS_THEME,
|
|
798
|
-
);
|
|
799
|
-
}
|
|
800
|
-
}
|