@astryxdesign/cli 0.7.16 → 0.7.17-canary.g49a475f
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +76 -86
- package/api/build/_adapter.d.mts +12 -0
- package/api/build/_adapter.mjs +51 -34
- package/api/build/blocks/blocks.d.mts +7 -5
- package/api/build/blocks/blocks.mjs +113 -26
- package/api/build/build.doc.mjs +4 -3
- package/api/build/build.type.d.mts +2 -2
- package/api/build/build.type.mjs +3 -3
- package/api/build/kit/kind.d.mts +2 -1
- package/api/build/kit/kind.mjs +199 -10
- package/api/build/kit/kit.mjs +6 -4
- package/api/build/kit/rank.d.mts +4 -2
- package/api/build/kit/rank.mjs +125 -24
- package/api/build/kit/start.d.mts +5 -4
- package/api/build/kit/start.mjs +12 -8
- package/api/build/kit/weights.d.mts +39 -3
- package/api/build/kit/weights.json +1 -1
- package/api/build/kit/weights.mjs +340 -43
- package/api/build/kit/word-model.d.mts +23 -0
- package/api/build/kit/word-model.mjs +46 -0
- package/api/build/kit/words.d.mts +48 -0
- package/api/build/kit/words.mjs +90 -1
- package/api/component/__fixtures__/resolutions/modules.txt +4 -5
- package/api/component/list/list.d.mts +1 -1
- package/api/component/list/list.mjs +48 -6
- package/api/discover/_adapter.d.mts +1 -1
- package/api/discover/search/search.mjs +3 -2
- package/api/docs/_adapter.d.mts +26 -2
- package/api/docs/_adapter.mjs +219 -6
- package/api/docs/docs.d.mts +3 -0
- package/api/docs/docs.doc.mjs +7 -1
- package/api/docs/docs.mjs +12 -0
- package/api/docs/docs.type.d.mts +5 -0
- package/api/docs/docs.type.mjs +2 -0
- package/api/docs/node/node.mjs +1 -1
- package/api/doctor/_adapter.d.mts +27 -5
- package/api/doctor/_adapter.mjs +83 -10
- package/api/doctor/built-checks.mjs +40 -14
- package/api/doctor/doctor.d.mts +4 -3
- package/api/doctor/doctor.mjs +14 -7
- package/api/doctor/theme-checks.mjs +121 -17
- package/api/icon/_records.mjs +2 -1
- package/api/index.d.mts +2 -0
- package/api/index.mjs +2 -0
- package/api/integration/_adapter.d.mts +44 -0
- package/api/integration/_adapter.mjs +77 -1
- package/api/integration/authoring-checks.mjs +6 -6
- package/api/integration/example-scope.d.mts +14 -0
- package/api/integration/example-scope.mjs +44 -0
- package/api/integration/example-scope.type.d.mts +29 -0
- package/api/integration/example-scope.type.mjs +25 -0
- package/api/integration/integrationExampleScope.doc.d.mts +11 -0
- package/api/integration/integrationExampleScope.doc.mjs +59 -0
- package/api/integration/validate-integration.mjs +19 -1
- package/api/integration/validate-integration.type.d.mts +9 -0
- package/api/integration/validate-integration.type.mjs +1 -1
- package/api/integration/validateIntegration.doc.mjs +1 -1
- package/api/render/_adapter.mjs +591 -195
- package/api/render/render.doc.mjs +11 -3
- package/api/render/render.type.d.mts +52 -0
- package/api/render/render.type.mjs +31 -1
- package/api/search/ORDERING.md +1 -1
- package/api/search/_adapter.d.mts +9 -0
- package/api/search/_adapter.mjs +85 -0
- package/api/search/_candidate-score.mjs +51 -32
- package/api/search/_fit-order.mjs +3 -3
- package/api/search/_gather-components.d.mts +3 -2
- package/api/search/_gather-components.mjs +12 -3
- package/api/search/_lexical.d.mts +5 -0
- package/api/search/_lexical.mjs +8 -2
- package/api/search/_result.d.mts +11 -9
- package/api/search/_result.mjs +4 -4
- package/api/search/_score.d.mts +6 -1
- package/api/search/_score.mjs +15 -3
- package/api/search/search-index.mjs +7 -1
- package/api/search/search.d.mts +1 -1
- package/api/theme/_adapter.mjs +12 -1
- package/api/theme/build/build.d.mts +75 -0
- package/api/theme/build/build.mjs +243 -58
- package/api/theme/build/font-warning.d.mts +7 -0
- package/api/theme/build/font-warning.mjs +17 -0
- package/api/theme/theme.type.d.mts +10 -0
- package/api/theme/theme.type.mjs +7 -1
- package/api/theme-edit/_adapter.d.mts +63 -2
- package/api/theme-edit/_adapter.mjs +771 -57
- package/api/theme-edit/_check.d.mts +40 -22
- package/api/theme-edit/_check.mjs +2029 -336
- package/api/theme-edit/_color.d.mts +10 -0
- package/api/theme-edit/_color.mjs +49 -1
- package/api/theme-edit/_compiler.mjs +9 -0
- package/api/theme-edit/_context.d.mts +3 -3
- package/api/theme-edit/_context.mjs +111 -48
- package/api/theme-edit/_css.d.mts +14 -0
- package/api/theme-edit/_css.mjs +46 -1
- package/api/theme-edit/_edit.d.mts +18 -4
- package/api/theme-edit/_edit.mjs +1685 -155
- package/api/theme-edit/_how-commands.d.mts +65 -0
- package/api/theme-edit/_how-commands.mjs +633 -1
- package/api/theme-edit/_how-question.d.mts +84 -0
- package/api/theme-edit/_how-question.mjs +5124 -281
- package/api/theme-edit/_how.mjs +140 -29
- package/api/theme-edit/_marks.d.mts +31 -5
- package/api/theme-edit/_marks.mjs +57 -5
- package/api/theme-edit/_name-rule.d.mts +11 -0
- package/api/theme-edit/_name-rule.mjs +12 -0
- package/api/theme-edit/_normal.d.mts +257 -0
- package/api/theme-edit/_normal.mjs +1252 -0
- package/api/theme-edit/_palette.mjs +10 -4
- package/api/theme-edit/_parts.d.mts +10 -1
- package/api/theme-edit/_parts.mjs +179 -3
- package/api/theme-edit/_preview-app.d.mts +7 -1
- package/api/theme-edit/_preview-app.mjs +515 -148
- package/api/theme-edit/_preview.d.mts +100 -14
- package/api/theme-edit/_preview.mjs +549 -137
- package/api/theme-edit/_settings.d.mts +347 -30
- package/api/theme-edit/_settings.mjs +2971 -327
- package/api/theme-edit/_tables.d.mts +6 -0
- package/api/theme-edit/_tables.mjs +44 -1
- package/api/theme-edit/_vet.d.mts +18 -0
- package/api/theme-edit/_vet.mjs +32 -0
- package/api/theme-edit/theme-edit.type.d.mts +10 -1
- package/api/theme-edit/theme-edit.type.mjs +4 -1
- package/api/theme-edit/themeEditHow.doc.mjs +1 -1
- package/api/theme-edit/themeEditNew.doc.d.mts +0 -1
- package/api/theme-edit/themeEditNew.doc.mjs +7 -4
- package/api/theme-edit/themeEditPreviewApp.doc.mjs +3 -3
- package/api/theme-edit/themeEditPreviewRemove.doc.mjs +2 -2
- package/api/upgrade/run/run.mjs +4 -3
- package/assets/codemods/integration-discovery.mjs +2 -1
- package/assets/codemods/run-codemod.mjs +87 -7
- package/assets/codemods/transforms/next/index.mjs +11 -1
- package/assets/codemods/transforms/next/migrate-item-swipe-actions-to-swipe.mjs +394 -0
- package/assets/component-list.generated.json +1 -0
- package/assets/docs/author-a-theme.doc.mjs +1 -0
- package/assets/docs/theme.doc.dense.mjs +2 -2
- package/assets/docs/theme.doc.mjs +1 -1
- package/assets/docs/tree/check-your-docs.doc.mjs +1 -1
- package/assets/docs/tree/checks.doc.mjs +1 -1
- package/assets/docs/tree/cli-command.doc.mjs +2 -3
- package/assets/docs/tree/render-pages.doc.mjs +44 -3
- package/assets/docs/tree/single-component.doc.mjs +4 -0
- package/assets/docs/tree/template-doc-overview.doc.mjs +1 -1
- package/assets/docs/tree/test-in-an-app.doc.mjs +1 -1
- package/assets/docs/use-a-theme.doc.mjs +1 -1
- package/assets/docs.generated.json +2 -2
- package/assets/search-catalog.generated.json +2 -0
- package/assets/self-audit.generated.json +1 -1
- package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.tsx +38 -0
- package/assets/templates/blocks/components/Hooks/useContainerRevealHookUsage.tsx +2 -2
- package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.tsx +36 -0
- package/assets/templates/components.generated.json +1 -1
- package/assets/templates/pages/ai-chat/template.doc.mjs +5 -4
- package/assets/templates/pages/ai-chat-landing/template.doc.mjs +2 -1
- package/assets/templates/pages/blank/template.doc.mjs +1 -1
- package/assets/templates/pages/canvas-editor/template.doc.mjs +4 -2
- package/assets/templates/pages/centered-hero/template.doc.mjs +9 -1
- package/assets/templates/pages/classic-gallery/template.doc.mjs +1 -1
- package/assets/templates/pages/contact-form/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard/template.doc.mjs +3 -2
- package/assets/templates/pages/dashboard-alert-rail/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard-cohort-funnel/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard-composition/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard-progress/template.doc.mjs +6 -3
- package/assets/templates/pages/detail-page/template.doc.mjs +10 -3
- package/assets/templates/pages/documentation/template.doc.mjs +4 -1
- package/assets/templates/pages/documentation-design/template.doc.mjs +7 -1
- package/assets/templates/pages/documentation-technical/template.doc.mjs +7 -1
- package/assets/templates/pages/editor/template.doc.mjs +2 -8
- package/assets/templates/pages/file-explorer/template.doc.mjs +1 -1
- package/assets/templates/pages/form-two-column/template.doc.mjs +4 -3
- package/assets/templates/pages/form-wizard/template.doc.mjs +5 -3
- package/assets/templates/pages/gallery-hero/template.doc.mjs +4 -2
- package/assets/templates/pages/ide/page.tsx +24 -2
- package/assets/templates/pages/kanban-board/template.doc.mjs +1 -9
- package/assets/templates/pages/library/template.doc.mjs +4 -1
- package/assets/templates/pages/login/template.doc.mjs +2 -1
- package/assets/templates/pages/login-card/template.doc.mjs +2 -1
- package/assets/templates/pages/login-split/template.doc.mjs +2 -1
- package/assets/templates/pages/login-sso/template.doc.mjs +4 -2
- package/assets/templates/pages/mixed-gallery/template.doc.mjs +2 -1
- package/assets/templates/pages/product-detail/template.doc.mjs +4 -2
- package/assets/templates/pages/product-gallery/template.doc.mjs +2 -1
- package/assets/templates/pages/settings-dialog/template.doc.mjs +2 -1
- package/assets/templates/pages/settings-sidebar/template.doc.mjs +2 -1
- package/assets/templates/pages/shell-nav/template.doc.mjs +4 -2
- package/assets/templates/pages/shell-side-nav/template.doc.mjs +5 -3
- package/assets/templates/pages/shell-top-nav/template.doc.mjs +2 -1
- package/assets/templates/pages/side-gallery/template.doc.mjs +9 -1
- package/assets/templates/pages/table-filter/template.doc.mjs +9 -8
- package/assets/templates/pages/table-grouped/template.doc.mjs +4 -2
- package/assets/templates/pages/table-page/template.doc.mjs +5 -4
- package/assets/templates/pages/table-tree/template.doc.mjs +6 -3
- package/assets/templates/pages/theme-showcase/template.doc.mjs +2 -9
- package/assets/templates/pages/work-item-detail/template.doc.mjs +1 -0
- package/assets/theme.template.ts +6 -0
- package/authoring/debug/parse.d.mts +3 -3
- package/authoring/doctypes/_schema.d.mts +3 -3
- package/authoring/doctypes/command/command.doc.mjs +1 -1
- package/authoring/doctypes/component/categories.d.mts +37 -0
- package/authoring/doctypes/component/categories.mjs +54 -0
- package/authoring/doctypes/template/template.doc.mjs +1 -1
- package/authoring/doctypes/template/type.ts +9 -0
- package/authoring/example/example.doc.d.mts +12 -0
- package/authoring/example/example.doc.mjs +69 -0
- package/authoring/example/preview.d.mts +92 -0
- package/authoring/example/preview.mjs +994 -0
- package/authoring/example/type.ts +102 -0
- package/authoring/index.d.mts +1 -0
- package/authoring/index.d.ts +12 -0
- package/authoring/index.mjs +3 -1
- package/clients/cli/bin/astryx.mjs +6 -9
- package/clients/cli/build-id.generated.json +1 -1
- package/clients/cli/commands/component.doc.mjs +1 -1
- package/clients/cli/commands/component.mjs +22 -3
- package/clients/cli/commands/docs.doc.mjs +7 -1
- package/clients/cli/commands/docs.mjs +3 -1
- package/clients/cli/commands/doctor.mjs +32 -14
- package/clients/cli/commands/experimental/render.mjs +42 -1
- package/clients/cli/commands/experimental/theme.mjs +163 -28
- package/clients/cli/commands/experimental-render.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-compile.doc.mjs +3 -3
- package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +87 -1
- package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +10 -3
- package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-preview-remove.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-preview.doc.mjs +2 -1
- package/clients/cli/commands/experimental-theme.doc.mjs +5 -1
- package/clients/cli/commands/search.doc.mjs +2 -1
- package/clients/cli/commands/search.mjs +6 -1
- package/clients/cli/commands/template.mjs +4 -2
- package/clients/cli/commands/theme-build.doc.mjs +5 -1
- package/clients/cli/commands/theme.doc.mjs +1 -1
- package/clients/cli/commands/theme.mjs +209 -8
- package/clients/cli/commands/upgrade.mjs +42 -7
- package/clients/cli/index.mjs +1 -1
- package/clients/cli/lib/cli-error.mjs +2 -1
- package/clients/cli/lib/component-format.mjs +205 -98
- package/clients/cli/lib/hook-format.mjs +9 -19
- package/clients/cli/lib/json-shim.mjs +77 -21
- package/clients/cli/lib/manifest.mjs +3 -2
- package/clients/cli/manifest.generated.json +1 -1
- package/foundation/agent-docs/agent-docs.mjs +1 -1
- package/foundation/config/theme-state.d.mts +13 -1
- package/foundation/config/theme-state.mjs +47 -7
- package/foundation/discovery/authoring-self-docs.mjs +1 -0
- package/foundation/discovery/component-discovery.d.mts +11 -0
- package/foundation/discovery/component-discovery.mjs +56 -8
- package/foundation/discovery/component-replacement.mjs +130 -1
- package/foundation/discovery/copied-passages.mjs +2 -1
- package/foundation/discovery/doc-types.mjs +4 -3
- package/foundation/discovery/entry-name-files.d.mts +43 -0
- package/foundation/discovery/entry-name-files.mjs +264 -0
- package/foundation/discovery/hook-discovery.d.mts +8 -2
- package/foundation/discovery/hook-discovery.mjs +22 -8
- package/foundation/discovery/icon-definition-discovery.mjs +2 -1
- package/foundation/discovery/icon-set-checks.mjs +2 -1
- package/foundation/discovery/icon-set-discovery.mjs +2 -1
- package/foundation/discovery/integration-doc-files.mjs +2 -1
- package/foundation/discovery/package-exports.d.mts +10 -0
- package/foundation/discovery/package-exports.mjs +56 -3
- package/foundation/discovery/prop-drift.mjs +9 -9
- package/foundation/discovery/runner-allowlist.d.mts +1 -0
- package/foundation/discovery/runner-allowlist.mjs +2 -0
- package/foundation/discovery/stored-component-list.d.mts +43 -0
- package/foundation/discovery/stored-component-list.mjs +90 -0
- package/foundation/discovery/stored-search-catalog.d.mts +115 -0
- package/foundation/discovery/stored-search-catalog.mjs +297 -0
- package/foundation/discovery/stored-self-audit.d.mts +26 -10
- package/foundation/discovery/stored-self-audit.mjs +38 -18
- package/foundation/discovery/template-adapter.d.mts +52 -0
- package/foundation/discovery/template-adapter.mjs +176 -12
- package/foundation/discovery/template-icons.mjs +2 -1
- package/foundation/discovery/theme-discovery.mjs +3 -2
- package/foundation/discovery/theme-imports.d.mts +14 -0
- package/foundation/discovery/theme-imports.mjs +43 -1
- package/foundation/discovery/theming-targets.mjs +3 -2
- package/foundation/doc-compiler/import.mjs +7 -1
- package/foundation/doc-compiler/inputs.mjs +3 -2
- package/foundation/doc-compiler/parse-readable.mjs +4 -1
- package/foundation/doc-compiler/stored-docs.d.mts +22 -0
- package/foundation/doc-compiler/stored-docs.mjs +49 -0
- package/foundation/env/semver.mjs +3 -1
- package/foundation/fonts/font-stylesheet.d.mts +31 -0
- package/foundation/fonts/font-stylesheet.mjs +115 -0
- package/foundation/fs/cache-eviction.d.mts +21 -0
- package/foundation/fs/cache-eviction.mjs +73 -0
- package/foundation/fs/file-protection.mjs +4 -3
- package/foundation/fs/gather-cache.d.mts +25 -4
- package/foundation/fs/gather-cache.mjs +164 -55
- package/foundation/fs/jiti-cache.d.mts +19 -1
- package/foundation/fs/jiti-cache.mjs +130 -6
- package/foundation/fs/kept-tree.d.mts +60 -0
- package/foundation/fs/kept-tree.mjs +154 -0
- package/foundation/fs/listing-cache.d.mts +7 -0
- package/foundation/fs/listing-cache.mjs +10 -0
- package/foundation/fs/module-loader.d.mts +24 -2
- package/foundation/fs/module-loader.mjs +94 -21
- package/foundation/fs/paths.d.mts +18 -0
- package/foundation/fs/paths.mjs +15 -2
- package/foundation/identity/provider-identity.d.mts +6 -0
- package/foundation/identity/provider-identity.mjs +10 -1
- package/foundation/integrations/contribution-inventory.mjs +4 -3
- package/foundation/integrations/example-code.d.mts +63 -0
- package/foundation/integrations/example-code.mjs +416 -0
- package/foundation/integrations/public-imports.d.mts +9 -0
- package/foundation/integrations/public-imports.mjs +3 -2
- package/foundation/integrations/validate-contributions.mjs +17 -45
- package/foundation/render/embedded-files.d.mts +6 -0
- package/foundation/render/embedded-files.mjs +25 -5
- package/foundation/render/embedded-imports.d.mts +39 -7
- package/foundation/render/embedded-imports.mjs +66 -27
- package/foundation/render/file-header.d.mts +66 -0
- package/foundation/render/file-header.mjs +118 -0
- package/foundation/render/host-answer.d.mts +18 -0
- package/foundation/render/host-answer.mjs +46 -0
- package/foundation/render/host-exit.d.mts +1 -0
- package/foundation/render/host-exit.mjs +6 -1
- package/foundation/render/html-reader.d.mts +55 -2
- package/foundation/render/html-reader.mjs +145 -26
- package/foundation/render/markup-edits.d.mts +57 -0
- package/foundation/render/markup-edits.mjs +182 -0
- package/foundation/render/page-host.mjs +29 -12
- package/foundation/render/page-worker.mjs +121 -13
- package/foundation/render/picture-chrome.d.mts +4 -0
- package/foundation/render/picture-chrome.mjs +185 -0
- package/foundation/render/picture-playwright.d.mts +4 -0
- package/foundation/render/picture-playwright.mjs +34 -0
- package/foundation/render/rebuild.mjs +2 -1
- package/foundation/render/render-page.d.mts +35 -3
- package/foundation/render/render-page.mjs +316 -42
- package/foundation/render/source-block.d.mts +85 -6
- package/foundation/render/source-block.mjs +211 -20
- package/foundation/render/ts-paths.d.mts +69 -6
- package/foundation/render/ts-paths.mjs +326 -40
- package/foundation/response/error-codes.d.mts +3 -1
- package/foundation/response/error-codes.d.ts +1 -0
- package/foundation/response/error-codes.doc.mjs +12 -1
- package/foundation/response/error-codes.mjs +11 -1
- package/foundation/response/response-types.doc.mjs +2 -2
- package/foundation/text/compare-text.d.mts +14 -0
- package/foundation/text/compare-text.mjs +68 -0
- package/foundation/text/string-utils.d.mts +3 -2
- package/foundation/text/string-utils.mjs +18 -4
- package/foundation/text/suggest-order.d.mts +9 -0
- package/foundation/text/suggest-order.mjs +15 -1
- package/foundation/xle/expand.mjs +2 -1
- package/host/index.mjs +8 -6
- package/package.json +7 -6
package/api/theme-edit/_edit.mjs
CHANGED
|
@@ -9,11 +9,24 @@
|
|
|
9
9
|
* @position api/theme-edit — imported only by _adapter.mjs
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
+
import {THEME_SLUG_RE} from '../../foundation/discovery/theme-discovery.mjs';
|
|
12
13
|
import * as fs from 'node:fs';
|
|
13
14
|
import {coversProperty} from './_css.mjs';
|
|
14
15
|
import * as path from 'node:path';
|
|
15
16
|
import {AstryxError} from '../error.mjs';
|
|
16
|
-
import {
|
|
17
|
+
import {
|
|
18
|
+
followLine,
|
|
19
|
+
readSetLine,
|
|
20
|
+
splitCommand,
|
|
21
|
+
vetSuggestions,
|
|
22
|
+
} from './_vet.mjs';
|
|
23
|
+
import {
|
|
24
|
+
allowedLine,
|
|
25
|
+
colorPair,
|
|
26
|
+
coversTyped,
|
|
27
|
+
readsTyped,
|
|
28
|
+
withoutCopyDebris,
|
|
29
|
+
} from './_normal.mjs';
|
|
17
30
|
import {
|
|
18
31
|
AUTO_SPREAD,
|
|
19
32
|
CORNERS,
|
|
@@ -38,6 +51,8 @@ import {
|
|
|
38
51
|
radiusTokenOf,
|
|
39
52
|
contrastProblems,
|
|
40
53
|
describe,
|
|
54
|
+
entryDamage,
|
|
55
|
+
entryNotes,
|
|
41
56
|
keyOf,
|
|
42
57
|
loadTheme,
|
|
43
58
|
maskedSettings,
|
|
@@ -66,33 +81,39 @@ import {
|
|
|
66
81
|
NEW_MARKER,
|
|
67
82
|
clearNewMarker,
|
|
68
83
|
refuseThemeSource,
|
|
69
|
-
|
|
84
|
+
settingsEntriesOk,
|
|
85
|
+
entriesReadable,
|
|
86
|
+
readAsMeant,
|
|
87
|
+
onBuiltIn,
|
|
88
|
+
readFields,
|
|
89
|
+
settingsJson,
|
|
70
90
|
slugFor,
|
|
91
|
+
typedThemeName,
|
|
92
|
+
themeNameReadings,
|
|
71
93
|
themeSource,
|
|
72
94
|
themeSourceProblem,
|
|
73
95
|
refuseThemeParse,
|
|
74
96
|
ownSourceTokens,
|
|
75
97
|
ownSourceTokenValues,
|
|
98
|
+
ownTokenEntries,
|
|
99
|
+
evaluatedTheme,
|
|
100
|
+
nonTextMessage,
|
|
76
101
|
ownPartTokens,
|
|
77
102
|
PHONE_TYPE,
|
|
78
103
|
refreshSourceStamp,
|
|
79
104
|
sourceChangedReason,
|
|
80
|
-
|
|
81
|
-
ownPairMessage,
|
|
105
|
+
setOwnTokenCheck,
|
|
82
106
|
freeThemeName,
|
|
83
107
|
refuseLinks,
|
|
84
108
|
usableNewName,
|
|
85
109
|
FOLDER_JUNK,
|
|
110
|
+
folderIsEmpty,
|
|
86
111
|
dialValueFits,
|
|
87
112
|
holdAfterBuild,
|
|
88
113
|
} from './_settings.mjs';
|
|
89
|
-
import {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
normalizeEntry,
|
|
93
|
-
storedProblems,
|
|
94
|
-
} from './_check.mjs';
|
|
95
|
-
import {MODAL} from './_compiler.mjs';
|
|
114
|
+
import {checkSetting, normalizeEntry, storedProblems} from './_check.mjs';
|
|
115
|
+
import {MODAL, isColorToken} from './_compiler.mjs';
|
|
116
|
+
import {colorProblem} from './_color.mjs';
|
|
96
117
|
import {
|
|
97
118
|
PALETTE_DIALS,
|
|
98
119
|
VIBRANCY_DEFAULT,
|
|
@@ -105,15 +126,21 @@ import {
|
|
|
105
126
|
writeWhole,
|
|
106
127
|
isGraySeed,
|
|
107
128
|
seedOf,
|
|
129
|
+
isEditorTemp,
|
|
108
130
|
} from './_palette.mjs';
|
|
109
131
|
import {
|
|
110
132
|
renderPreview,
|
|
111
133
|
renderSheet,
|
|
112
134
|
previewIsCurrent,
|
|
113
135
|
takeFirstAppCopy,
|
|
136
|
+
appCopyBehind,
|
|
137
|
+
appCopyStale,
|
|
138
|
+
copyFontsCss,
|
|
114
139
|
writeAppCopy,
|
|
115
140
|
} from './_preview.mjs';
|
|
116
141
|
import {appWiring, refreshPreviewRoute, seeLine} from './_preview-app.mjs';
|
|
142
|
+
/** The preview command, as a person runs it. */
|
|
143
|
+
const PREVIEW_CMD = `${P.replace(/ editor$/, '')} preview`;
|
|
117
144
|
import {baseInstalled, baseResolved, installLine} from './_project.mjs';
|
|
118
145
|
import {reactMissing} from './_parts.mjs';
|
|
119
146
|
import {
|
|
@@ -129,6 +156,7 @@ import {
|
|
|
129
156
|
} from './_context.mjs';
|
|
130
157
|
import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
|
|
131
158
|
import {
|
|
159
|
+
formatCliCommand,
|
|
132
160
|
getCliInvocation,
|
|
133
161
|
quoteCommandArgument,
|
|
134
162
|
} from '../../foundation/env/package-manager.mjs';
|
|
@@ -171,12 +199,11 @@ function editorLeftovers(dir, slug, damaged = false) {
|
|
|
171
199
|
const named = (/** @type {string} */ n) =>
|
|
172
200
|
n === NEW_MARKER ||
|
|
173
201
|
EDITOR_SUFFIXES.some(x => n === `${slug}.${x}`) ||
|
|
174
|
-
/^(preview(-
|
|
202
|
+
/^(preview(-dark)?\.(html|png)|sheet(-[a-z-]+)?\.(html|png)|palette\.config\.json)$/.test(
|
|
175
203
|
n,
|
|
176
204
|
) ||
|
|
177
|
-
// The editor's temp names
|
|
178
|
-
|
|
179
|
-
/^\..+\.(astryx-\d+-[a-z0-9]+\.tmp|tmp-[\w-]+)$/.test(n);
|
|
205
|
+
// The editor's temp names (writes, builds, pictures).
|
|
206
|
+
isEditorTemp(n);
|
|
180
207
|
for (const e of fs.readdirSync(dir, {withFileTypes: true})) {
|
|
181
208
|
const p = path.join(dir, e.name);
|
|
182
209
|
if (FOLDER_JUNK.has(e.name)) continue;
|
|
@@ -209,9 +236,9 @@ function editorLeftovers(dir, slug, damaged = false) {
|
|
|
209
236
|
/** Whether a settings file parses, in the shape the editor reads. @param {string} file */
|
|
210
237
|
function readableJson(file) {
|
|
211
238
|
try {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
);
|
|
239
|
+
// An entry with no thing or no source is damage too: `new` keeps the
|
|
240
|
+
// file aside, as the refusal for it says.
|
|
241
|
+
return settingsEntriesOk(settingsJson(fs.readFileSync(file, 'utf8')));
|
|
215
242
|
} catch {
|
|
216
243
|
return false;
|
|
217
244
|
}
|
|
@@ -345,21 +372,50 @@ export async function themeEditNew(name, options = {}) {
|
|
|
345
372
|
/** @type {string} */ newName,
|
|
346
373
|
/** @type {string | null | undefined} */ likeValue = likeFixed,
|
|
347
374
|
) => `${P} new ${newName}${newFlags(likeValue, fitSettings, png)}`;
|
|
375
|
+
// The same new as lines that run here: a built-in base the project has
|
|
376
|
+
// not installed is installed first.
|
|
377
|
+
const againLines = (
|
|
378
|
+
/** @type {string} */ newName,
|
|
379
|
+
/** @type {string | null | undefined} */ likeValue = likeFixed,
|
|
380
|
+
) =>
|
|
381
|
+
likeValue && LIKE.includes(likeValue)
|
|
382
|
+
? onBuiltIn(cwd, likeValue, again(newName, likeValue))
|
|
383
|
+
: [again(newName, likeValue)];
|
|
348
384
|
if (!slugOk(name)) {
|
|
349
|
-
|
|
350
|
-
//
|
|
351
|
-
|
|
352
|
-
|
|
385
|
+
// A path typed for the name (themes/brand, ./t, t/) names the theme the
|
|
386
|
+
// path ends in.
|
|
387
|
+
// A file name, the app copy's export (tTheme), camelCase or spaces
|
|
388
|
+
// (BrandDark, "Brand Dark") name the theme they read as: when it is
|
|
389
|
+
// here already, that is said, never a numbered second copy offered.
|
|
390
|
+
const typed = String(name ?? '');
|
|
391
|
+
const path_ = /[\\/]/.test(typed);
|
|
392
|
+
const readings = themeNameReadings(typed);
|
|
393
|
+
const present = readings.find(n =>
|
|
394
|
+
fs.existsSync(themeFiles(cwd, n).settings),
|
|
395
|
+
);
|
|
396
|
+
const fixed =
|
|
397
|
+
present ?? readings[0] ?? slugFor(path_ ? typedThemeName(typed) : typed);
|
|
398
|
+
const exists = Boolean(present);
|
|
353
399
|
refuse(
|
|
354
400
|
E.ERR_INVALID_ARGUMENT,
|
|
355
401
|
`"${String(name ?? '').slice(0, 80)}" is not a theme name (${NAME_RULE})${exists ? `; ${fixed} is a theme here already` : ''}.${dropped}`,
|
|
356
402
|
{
|
|
357
403
|
run: exists
|
|
358
404
|
? [`${P} show ${fixed}`]
|
|
359
|
-
:
|
|
405
|
+
: againLines(usableNewName(cwd, fixed)),
|
|
360
406
|
},
|
|
361
407
|
);
|
|
362
408
|
}
|
|
409
|
+
// A name the theme commands' own discovery skips ("a--b", "b-") would
|
|
410
|
+
// make an app copy no `theme add`, `theme list` or doctor takes.
|
|
411
|
+
if (!THEME_SLUG_RE.test(name)) {
|
|
412
|
+
const cleaned = name.replace(/-{2,}/g, '-').replace(/-+$/, '');
|
|
413
|
+
refuse(
|
|
414
|
+
E.ERR_INVALID_ARGUMENT,
|
|
415
|
+
`"${name}" is not a theme name the theme commands take: a dash only between letters or digits (no two in a row, none at the end), so its app copy in src/themes/ would be skipped by theme add, theme list and doctor.${dropped}`,
|
|
416
|
+
{run: againLines(usableNewName(cwd, cleaned))},
|
|
417
|
+
);
|
|
418
|
+
}
|
|
363
419
|
// A built-in theme's name would collide with the theme of that name the
|
|
364
420
|
// app may also use.
|
|
365
421
|
if (LIKE.includes(name))
|
|
@@ -367,16 +423,19 @@ export async function themeEditNew(name, options = {}) {
|
|
|
367
423
|
E.ERR_FILE_EXISTS,
|
|
368
424
|
`${name} is a built-in theme; an editor theme needs a name of its own. To start from ${name}, build on it.${dropped}`,
|
|
369
425
|
{
|
|
370
|
-
run:
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
426
|
+
run: (() => {
|
|
427
|
+
const mine = fs.existsSync(themeFiles(cwd, `my-${name}`).dir)
|
|
428
|
+
? freeThemeName(cwd, `my-${name}`)
|
|
429
|
+
: `my-${name}`;
|
|
430
|
+
// Built on the theme named (installed first when it is not),
|
|
431
|
+
// unless another base (or none) was given; or on no base.
|
|
432
|
+
return likeFixed !== undefined
|
|
433
|
+
? againLines(mine, likeFixed)
|
|
434
|
+
: [
|
|
435
|
+
...againLines(mine, name),
|
|
436
|
+
...(baseInstalled(cwd, name) ? [] : [again(mine, null)]),
|
|
437
|
+
];
|
|
438
|
+
})(),
|
|
380
439
|
},
|
|
381
440
|
);
|
|
382
441
|
const f = themeFiles(cwd, name);
|
|
@@ -400,7 +459,7 @@ export async function themeEditNew(name, options = {}) {
|
|
|
400
459
|
refuse(
|
|
401
460
|
E.ERR_FILE_EXISTS,
|
|
402
461
|
`themes/${name} is ${dirSt.isSymbolicLink() ? 'a link' : 'a file'}, so a theme is not made there.${dropped}`,
|
|
403
|
-
{run:
|
|
462
|
+
{run: againLines(freeThemeName(cwd, name))},
|
|
404
463
|
);
|
|
405
464
|
// Settings that are not valid JSON are kept aside, and the theme is
|
|
406
465
|
// made again beside them.
|
|
@@ -408,12 +467,15 @@ export async function themeEditNew(name, options = {}) {
|
|
|
408
467
|
if (fs.existsSync(f.settings) && !damaged)
|
|
409
468
|
refuse(E.ERR_FILE_EXISTS, `Theme "${name}" already exists.${dropped}`, {
|
|
410
469
|
// What the command asked for, on the theme that exists or as a new one.
|
|
470
|
+
// A base's install line, when one is needed, is given once.
|
|
411
471
|
run: [
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
472
|
+
...new Set([
|
|
473
|
+
`${P} show ${name}`,
|
|
474
|
+
...(likeFixed && LIKE.includes(likeFixed)
|
|
475
|
+
? onBuiltIn(cwd, likeFixed, `${P} set ${name} base ${likeFixed}`)
|
|
476
|
+
: []),
|
|
477
|
+
...againLines(freeThemeName(cwd, name)),
|
|
478
|
+
]),
|
|
417
479
|
],
|
|
418
480
|
});
|
|
419
481
|
// A `new` stopped part way (killed, out of memory) leaves its own marker
|
|
@@ -426,12 +488,13 @@ export async function themeEditNew(name, options = {}) {
|
|
|
426
488
|
const holdsOther =
|
|
427
489
|
fs.existsSync(f.dir) &&
|
|
428
490
|
!left &&
|
|
429
|
-
|
|
491
|
+
// Empty folders (an empty tokens/) hold nothing of anyone's.
|
|
492
|
+
!folderIsEmpty(f.dir);
|
|
430
493
|
if (holdsOther)
|
|
431
494
|
refuse(
|
|
432
495
|
E.ERR_FILE_EXISTS,
|
|
433
496
|
`themes/${name}/ already holds files this command did not make; choose another name.${dropped}`,
|
|
434
|
-
{run:
|
|
497
|
+
{run: againLines(freeThemeName(cwd, name))},
|
|
435
498
|
);
|
|
436
499
|
if (like != null && !LIKE.includes(like))
|
|
437
500
|
refuse(
|
|
@@ -469,9 +532,21 @@ export async function themeEditNew(name, options = {}) {
|
|
|
469
532
|
// Every check comes before the first change to the folder: the settings,
|
|
470
533
|
// and a source of the user's own kept from before (it must still extend
|
|
471
534
|
// the settings, or the build fails after the folder was cleared).
|
|
535
|
+
try {
|
|
536
|
+
applyNewSettings(
|
|
537
|
+
ctx,
|
|
538
|
+
name,
|
|
539
|
+
structuredClone(data),
|
|
540
|
+
settings,
|
|
541
|
+
png,
|
|
542
|
+
likeFixed ?? undefined,
|
|
543
|
+
);
|
|
544
|
+
} catch (e) {
|
|
545
|
+
throw await followNewLine(e, ctx, name, data);
|
|
546
|
+
}
|
|
472
547
|
applyNewSettings(ctx, name, data, settings, png, likeFixed ?? undefined);
|
|
473
548
|
if (left?.keep.some(p => path.basename(p) === `${name}.theme.ts`))
|
|
474
|
-
refuseThemeSource(cwd, name);
|
|
549
|
+
await refuseThemeSource(cwd, name);
|
|
475
550
|
/** @type {string[]} */
|
|
476
551
|
const keptNotes = [];
|
|
477
552
|
/** @type {string[]} */
|
|
@@ -576,7 +651,7 @@ export async function themeEditNew(name, options = {}) {
|
|
|
576
651
|
}
|
|
577
652
|
refuseIfLockLost();
|
|
578
653
|
fs.rmSync(marker, {force: true});
|
|
579
|
-
const p = await previewAndRoute(ctx, name, data, png);
|
|
654
|
+
const p = await previewAndRoute(ctx, name, data, png, 'overview', 'new');
|
|
580
655
|
/** @type {string[]} */
|
|
581
656
|
const notes = [
|
|
582
657
|
...keptNotes,
|
|
@@ -610,6 +685,77 @@ export async function themeEditNew(name, options = {}) {
|
|
|
610
685
|
};
|
|
611
686
|
}
|
|
612
687
|
|
|
688
|
+
/**
|
|
689
|
+
* A refused `new` whose suggestions include another `new` of the theme:
|
|
690
|
+
* that line is checked as `new` checks its dial flags (in memory, nothing
|
|
691
|
+
* written), and each repair a refusal of it offers is folded in, so the one
|
|
692
|
+
* line fixes or drops every bad flag. It comes first.
|
|
693
|
+
* @param {unknown} e
|
|
694
|
+
* @param {import('./_settings.mjs').Ctx} ctx
|
|
695
|
+
* @param {string} slug
|
|
696
|
+
* @param {import('./_settings.mjs').ThemeData} data the theme before any dial
|
|
697
|
+
* @returns {Promise<unknown>}
|
|
698
|
+
*/
|
|
699
|
+
async function followNewLine(e, ctx, slug, data) {
|
|
700
|
+
if (!(e instanceof AstryxError)) return e;
|
|
701
|
+
const prefix = `${P} new ${slug}`;
|
|
702
|
+
const isNew = (/** @type {string} */ n) =>
|
|
703
|
+
n === prefix || n.startsWith(`${prefix} `);
|
|
704
|
+
const first = (e.suggestions ?? []).find(x => isNew(x.name));
|
|
705
|
+
if (!first) return e;
|
|
706
|
+
const followed = await followLine(
|
|
707
|
+
first.name,
|
|
708
|
+
line => {
|
|
709
|
+
const args = splitCommand(line.slice(prefix.length));
|
|
710
|
+
if (!args) return null;
|
|
711
|
+
/** @type {Record<string, string | string[]>} */
|
|
712
|
+
const settings = {};
|
|
713
|
+
/** @type {string | undefined} */
|
|
714
|
+
let like;
|
|
715
|
+
let png = false;
|
|
716
|
+
for (let j = 0; j < args.length; j += 1) {
|
|
717
|
+
const m = /^--([a-z-]+)$/.exec(args[j]);
|
|
718
|
+
if (m?.[1] === 'png') png = true;
|
|
719
|
+
else if (m && args[j + 1] != null) {
|
|
720
|
+
const v = args[(j += 1)];
|
|
721
|
+
if (m[1] === 'like') like = v;
|
|
722
|
+
else {
|
|
723
|
+
const had = settings[m[1]];
|
|
724
|
+
settings[m[1]] = had == null ? v : [...[had].flat(), v];
|
|
725
|
+
}
|
|
726
|
+
} else return null;
|
|
727
|
+
}
|
|
728
|
+
try {
|
|
729
|
+
applyNewSettings(
|
|
730
|
+
ctx,
|
|
731
|
+
slug,
|
|
732
|
+
structuredClone(data),
|
|
733
|
+
settings,
|
|
734
|
+
png,
|
|
735
|
+
like ?? data.like,
|
|
736
|
+
);
|
|
737
|
+
return null;
|
|
738
|
+
} catch (again) {
|
|
739
|
+
if (again instanceof AstryxError) return again;
|
|
740
|
+
throw again;
|
|
741
|
+
}
|
|
742
|
+
},
|
|
743
|
+
isNew,
|
|
744
|
+
);
|
|
745
|
+
if (followed.line === first.name) return e;
|
|
746
|
+
e.suggestions = [
|
|
747
|
+
{
|
|
748
|
+
...first,
|
|
749
|
+
name: followed.line,
|
|
750
|
+
reason: `do this instead: every flag fixed${followed.why ? `, but this still needs a fix: ${followed.why}` : ''}`,
|
|
751
|
+
},
|
|
752
|
+
...(e.suggestions ?? []).filter(
|
|
753
|
+
x => x !== first && x.name !== followed.line,
|
|
754
|
+
),
|
|
755
|
+
];
|
|
756
|
+
return e;
|
|
757
|
+
}
|
|
758
|
+
|
|
613
759
|
/**
|
|
614
760
|
* The dial settings of `new`, checked one at a time in dial order (mode
|
|
615
761
|
* first; a color before vibrancy, which needs one) into `data`.
|
|
@@ -655,15 +801,34 @@ function applyNewSettings(
|
|
|
655
801
|
/** @type {import('./_settings.mjs').Setting} */
|
|
656
802
|
let s;
|
|
657
803
|
try {
|
|
658
|
-
|
|
804
|
+
// The same input cleanup set gives a typed value (quotes of any
|
|
805
|
+
// kind around a font, invisible spaces, a pasted `name: value`).
|
|
806
|
+
const typed = normalizeEntry(thing, String(value)).value;
|
|
807
|
+
s = checkSetting(
|
|
808
|
+
ctx,
|
|
809
|
+
slug,
|
|
810
|
+
data,
|
|
811
|
+
thing,
|
|
812
|
+
typed ?? String(value),
|
|
813
|
+
{},
|
|
814
|
+
false,
|
|
815
|
+
);
|
|
659
816
|
} catch (e) {
|
|
660
|
-
throw
|
|
661
|
-
|
|
817
|
+
throw newColorPair(
|
|
818
|
+
asNewRefusal(
|
|
819
|
+
vetSuggestions(e, ctx, slug, data),
|
|
820
|
+
slug,
|
|
821
|
+
settings,
|
|
822
|
+
likeFlag,
|
|
823
|
+
png,
|
|
824
|
+
{thing, index},
|
|
825
|
+
),
|
|
662
826
|
slug,
|
|
663
827
|
settings,
|
|
664
828
|
likeFlag,
|
|
665
829
|
png,
|
|
666
|
-
|
|
830
|
+
thing,
|
|
831
|
+
String(value),
|
|
667
832
|
);
|
|
668
833
|
}
|
|
669
834
|
if (thing === 'mode')
|
|
@@ -771,6 +936,81 @@ function asNewRefusal(e, slug, settings, like, png = false, at = null) {
|
|
|
771
936
|
return e;
|
|
772
937
|
}
|
|
773
938
|
|
|
939
|
+
/**
|
|
940
|
+
* A color dial on `new` given a light and a dark color ("light #111111 dark
|
|
941
|
+
* #eeeeee"): the refusal offers the user's own colors, per mode, as set
|
|
942
|
+
* does, never a stock color they did not type.
|
|
943
|
+
* @param {unknown} e
|
|
944
|
+
* @param {string} slug
|
|
945
|
+
* @param {Record<string, any>} settings
|
|
946
|
+
* @param {string | undefined} like
|
|
947
|
+
* @param {boolean} png
|
|
948
|
+
* @param {string} thing
|
|
949
|
+
* @param {string} typed
|
|
950
|
+
*/
|
|
951
|
+
function newColorPair(e, slug, settings, like, png, thing, typed) {
|
|
952
|
+
if (!(e instanceof AstryxError) || !PALETTE_DIALS.includes(thing)) return e;
|
|
953
|
+
const typedLower = typed.toLowerCase();
|
|
954
|
+
// A color in a line the user did not type (a stock example) goes.
|
|
955
|
+
e.suggestions = (e.suggestions ?? []).filter(x => {
|
|
956
|
+
if (!x.name.startsWith(`${P} new `)) return true;
|
|
957
|
+
const m = new RegExp(`--${thing} '?(#[0-9a-f]{3,8})'?`, 'i').exec(x.name);
|
|
958
|
+
return !m || typedLower.includes(m[1].toLowerCase());
|
|
959
|
+
});
|
|
960
|
+
// With every color line gone, the same new without that color, every
|
|
961
|
+
// other option kept.
|
|
962
|
+
if (!e.suggestions.some(x => x.name.startsWith(`${P} new `)))
|
|
963
|
+
e.suggestions.push({
|
|
964
|
+
name: `${P} new ${slug}${newFlags(like, {...settings, [thing]: undefined}, png)}`,
|
|
965
|
+
reason: `without --${thing} ${quoteCommandArgument(typed)}`,
|
|
966
|
+
});
|
|
967
|
+
/** @type {Record<string, string>} */
|
|
968
|
+
const pair = {};
|
|
969
|
+
for (const m of typed.matchAll(
|
|
970
|
+
/\b(light|dark)\b\s*(?:mode\s*)?[:=]?\s*(#[0-9a-f]{3,8}\b|[a-z]+\([^)]*\)|[a-z]+)/gi,
|
|
971
|
+
))
|
|
972
|
+
pair[m[1].toLowerCase()] = m[2];
|
|
973
|
+
if (!pair.light && !pair.dark) return e;
|
|
974
|
+
const mode = String(
|
|
975
|
+
Array.isArray(settings.mode) ? settings.mode[0] : (settings.mode ?? 'both'),
|
|
976
|
+
);
|
|
977
|
+
/** @type {Array<{name: string, reason: string}>} */
|
|
978
|
+
const lines = [];
|
|
979
|
+
/** @param {string} color @param {string} reason @param {Record<string, any>} [extra] */
|
|
980
|
+
const line = (color, reason, extra = {}) =>
|
|
981
|
+
lines.push({
|
|
982
|
+
name: `${P} new ${slug}${newFlags(like, {...settings, ...extra, [thing]: color}, png)}`,
|
|
983
|
+
reason,
|
|
984
|
+
});
|
|
985
|
+
if (mode === 'dark-only' && pair.dark)
|
|
986
|
+
line(pair.dark, 'do this instead: the dark color you gave');
|
|
987
|
+
else if (mode === 'light-only' && pair.light)
|
|
988
|
+
line(pair.light, 'do this instead: the light color you gave');
|
|
989
|
+
else if (mode === 'both') {
|
|
990
|
+
if (pair.light)
|
|
991
|
+
line(
|
|
992
|
+
pair.light,
|
|
993
|
+
`the light color you gave; then set ${slug} --color-${thing} ${pair.dark ?? '…'} --mode dark for the dark one`,
|
|
994
|
+
);
|
|
995
|
+
if (pair.dark)
|
|
996
|
+
line(pair.dark, 'or a dark-only theme with the dark color you gave', {
|
|
997
|
+
mode: 'dark-only',
|
|
998
|
+
});
|
|
999
|
+
}
|
|
1000
|
+
// No color for the mode the theme has: how the dial works, and the
|
|
1001
|
+
// same new without it, never a color made up.
|
|
1002
|
+
if (!lines.length)
|
|
1003
|
+
lines.push({
|
|
1004
|
+
name: `${P} how ${thing}`,
|
|
1005
|
+
reason: `no ${mode === 'light-only' ? 'light' : 'dark'} color was given for this ${mode} theme`,
|
|
1006
|
+
});
|
|
1007
|
+
e.suggestions = [
|
|
1008
|
+
...lines,
|
|
1009
|
+
...(e.suggestions ?? []).filter(x => !lines.some(l => l.name === x.name)),
|
|
1010
|
+
];
|
|
1011
|
+
return e;
|
|
1012
|
+
}
|
|
1013
|
+
|
|
774
1014
|
/**
|
|
775
1015
|
* Headings values with every later value for an axis already given left
|
|
776
1016
|
* out (the first weight and the first tracking stay); a word of neither
|
|
@@ -822,6 +1062,32 @@ function changeFocus(s) {
|
|
|
822
1062
|
return 'overview';
|
|
823
1063
|
}
|
|
824
1064
|
|
|
1065
|
+
/**
|
|
1066
|
+
* A signal handler for the checks and pictures after a change is saved: it
|
|
1067
|
+
* says what is saved (in the words of the command that ran) and how to run
|
|
1068
|
+
* what did not, with the project's own CLI invocation, then lets the
|
|
1069
|
+
* signal end the process (the render's own handler re-raises it; with none,
|
|
1070
|
+
* this one does).
|
|
1071
|
+
* @param {string} slug
|
|
1072
|
+
* @param {'set' | 'undo' | 'new'} [kind] the command that saved
|
|
1073
|
+
* @param {string} [cwd] the project, for the CLI invocation
|
|
1074
|
+
* @returns {(sig: NodeJS.Signals) => void}
|
|
1075
|
+
*/
|
|
1076
|
+
export function stoppedAfterSave(slug, kind = 'set', cwd = process.cwd()) {
|
|
1077
|
+
const done =
|
|
1078
|
+
kind === 'undo'
|
|
1079
|
+
? `the undo is done: ${slug} is saved and built as it was before that change`
|
|
1080
|
+
: kind === 'new'
|
|
1081
|
+
? `${slug} is made and built`
|
|
1082
|
+
: `the change to ${slug} is saved and built (and its undo step kept)`;
|
|
1083
|
+
return sig => {
|
|
1084
|
+
process.stderr.write(
|
|
1085
|
+
`Stopped: ${done}; its checks and pictures did not run. ${formatCliCommand(`${P} show ${slug}`, cwd)} runs them.\n`,
|
|
1086
|
+
);
|
|
1087
|
+
if (process.listenerCount(sig) === 0) process.kill(process.pid, sig);
|
|
1088
|
+
};
|
|
1089
|
+
}
|
|
1090
|
+
|
|
825
1091
|
/**
|
|
826
1092
|
* The preview after a change, with the in-app preview route kept in step:
|
|
827
1093
|
* its imports follow the theme, such as the stylesheet of a font package
|
|
@@ -832,13 +1098,34 @@ function changeFocus(s) {
|
|
|
832
1098
|
* @param {boolean} png
|
|
833
1099
|
* @param {'colors' | 'components' | 'overview'} [focus] the preview page
|
|
834
1100
|
* most about the change: Colors for a color, Components for a part
|
|
1101
|
+
* @param {'set' | 'undo' | 'new'} [kind] the command that saved
|
|
835
1102
|
*/
|
|
836
|
-
async function previewAndRoute(
|
|
837
|
-
|
|
1103
|
+
async function previewAndRoute(
|
|
1104
|
+
ctx,
|
|
1105
|
+
slug,
|
|
1106
|
+
data,
|
|
1107
|
+
png,
|
|
1108
|
+
focus = 'overview',
|
|
1109
|
+
kind = /** @type {'set' | 'undo' | 'new'} */ ('set'),
|
|
1110
|
+
) {
|
|
1111
|
+
// Stopped (Ctrl-C) while the checks and pictures run: the change is saved
|
|
1112
|
+
// and built already, which one line says before the process ends.
|
|
1113
|
+
const stopped = stoppedAfterSave(slug, kind, ctx.project.cwd);
|
|
1114
|
+
process.once('SIGINT', stopped);
|
|
1115
|
+
process.once('SIGTERM', stopped);
|
|
1116
|
+
/** @type {Awaited<ReturnType<typeof previewAfter>>} */
|
|
1117
|
+
let p;
|
|
1118
|
+
try {
|
|
1119
|
+
p = await previewAfter(ctx, slug, data, png);
|
|
1120
|
+
} finally {
|
|
1121
|
+
process.removeListener('SIGINT', stopped);
|
|
1122
|
+
process.removeListener('SIGTERM', stopped);
|
|
1123
|
+
}
|
|
838
1124
|
const wrote = takeFirstAppCopy(ctx.project.cwd, slug);
|
|
1125
|
+
const previewStale = await keepPreviewRoute(ctx, slug);
|
|
839
1126
|
return {
|
|
840
1127
|
...p,
|
|
841
|
-
previewStale
|
|
1128
|
+
previewStale,
|
|
842
1129
|
// How to see the change: the page about it, at its own URL.
|
|
843
1130
|
// A page not written this time (preview null) still shows the theme
|
|
844
1131
|
// as it was; checks that failed with the page written do not.
|
|
@@ -852,9 +1139,18 @@ async function previewAndRoute(ctx, slug, data, png, focus = 'overview') {
|
|
|
852
1139
|
cause: 'no preview was rendered',
|
|
853
1140
|
})
|
|
854
1141
|
: null,
|
|
1142
|
+
{
|
|
1143
|
+
// Only a run that took no picture failed: a note on pictures that
|
|
1144
|
+
// were taken (why an earlier browser did not) is not a failure.
|
|
1145
|
+
pictureProblem:
|
|
1146
|
+
png && !(p.pictures ?? []).length ? p.pictureProblem : null,
|
|
1147
|
+
stale: previewStale,
|
|
1148
|
+
},
|
|
855
1149
|
),
|
|
856
1150
|
// The first time the theme's app copy is written, its files are named.
|
|
857
1151
|
...(wrote ? {appCopy: {wrote}} : {}),
|
|
1152
|
+
// A copy a file of yours kept from being written: said, never a quiet ok.
|
|
1153
|
+
...appCopyStale(ctx.project.cwd, slug),
|
|
858
1154
|
};
|
|
859
1155
|
}
|
|
860
1156
|
|
|
@@ -870,12 +1166,48 @@ async function previewAndRoute(ctx, slug, data, png, focus = 'overview') {
|
|
|
870
1166
|
async function keepPreviewRoute(ctx, slug) {
|
|
871
1167
|
try {
|
|
872
1168
|
return (await refreshPreviewRoute(ctx.project.cwd, slug)).stale;
|
|
873
|
-
} catch {
|
|
874
|
-
// A
|
|
1169
|
+
} catch (e) {
|
|
1170
|
+
// A route that could not be written (its permissions, a folder in its
|
|
1171
|
+
// place) does not follow this change: said, never a quiet ok. A
|
|
1172
|
+
// damaged preview record is named by the preview commands themselves.
|
|
1173
|
+
const code = /** @type {any} */ (e)?.code;
|
|
1174
|
+
if (code && /^E[A-Z]+$/.test(code)) {
|
|
1175
|
+
const where = /** @type {any} */ (e)?.path;
|
|
1176
|
+
return [
|
|
1177
|
+
`${where ? path.relative(ctx.project.cwd, where) : 'the in-app preview route'} could not be written (${code}), so the in-app preview does not follow this change; fix its permissions, then ${PREVIEW_CMD} add writes it again`,
|
|
1178
|
+
];
|
|
1179
|
+
}
|
|
875
1180
|
return [];
|
|
876
1181
|
}
|
|
877
1182
|
}
|
|
878
1183
|
|
|
1184
|
+
/**
|
|
1185
|
+
* What a change of mode asks of the app's wiring: a one-mode theme is
|
|
1186
|
+
* given its mode by the app's <Theme>, and one back to both modes no longer.
|
|
1187
|
+
* @param {string} slug
|
|
1188
|
+
* @param {string | undefined} before
|
|
1189
|
+
* @param {string | undefined} after
|
|
1190
|
+
* @returns {string[]}
|
|
1191
|
+
*/
|
|
1192
|
+
function modeWiringNotes(slug, before, after) {
|
|
1193
|
+
const one = (/** @type {string | undefined} */ m) =>
|
|
1194
|
+
m === 'light-only' ? 'light' : m === 'dark-only' ? 'dark' : null;
|
|
1195
|
+
const [was, now] = [one(before), one(after)];
|
|
1196
|
+
if (was === now) return [];
|
|
1197
|
+
return [
|
|
1198
|
+
...(was
|
|
1199
|
+
? [
|
|
1200
|
+
`if the app's <Theme> was given mode="${was}" for ${slug}, take it out${now ? ` (or make it mode="${now}")` : ''}: with it the app stays ${was}, whatever the system asks for`,
|
|
1201
|
+
]
|
|
1202
|
+
: []),
|
|
1203
|
+
...(now && !was
|
|
1204
|
+
? [
|
|
1205
|
+
`the app shows ${slug} in ${now} mode when its <Theme> is given mode="${now}" (<Theme theme={…} mode="${now}">), as the preview does; the theme keeps both halves of its colors, so a toast or a lightbox Core draws in the other mode stays readable`,
|
|
1206
|
+
]
|
|
1207
|
+
: []),
|
|
1208
|
+
];
|
|
1209
|
+
}
|
|
1210
|
+
|
|
879
1211
|
/**
|
|
880
1212
|
* Change one thing in a theme: checked, built, previewed.
|
|
881
1213
|
* @experimental
|
|
@@ -886,7 +1218,61 @@ async function keepPreviewRoute(ctx, slug) {
|
|
|
886
1218
|
* @returns {Promise<import('./theme-edit.type.mjs').ThemeEditChangeResponse>}
|
|
887
1219
|
*/
|
|
888
1220
|
export async function themeEditSet(theme, thing, value, options = {}) {
|
|
889
|
-
|
|
1221
|
+
try {
|
|
1222
|
+
return await change('set', theme, thing, value, options);
|
|
1223
|
+
} catch (e) {
|
|
1224
|
+
throw await swappedOrder(e, 'set', [theme, thing, value], options);
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
|
|
1228
|
+
/**
|
|
1229
|
+
* A refused theme name when the theme was typed after the setting (`set
|
|
1230
|
+
* --color-accent '#123457' t`): the same command with the theme first,
|
|
1231
|
+
* checked by that command, comes first, and no `new` of the setting's name
|
|
1232
|
+
* is offered.
|
|
1233
|
+
* @param {unknown} e
|
|
1234
|
+
* @param {'set' | 'undo'} sub
|
|
1235
|
+
* @param {Array<string | undefined>} words the positionals as typed
|
|
1236
|
+
* @param {{cwd?: string, on?: string, when?: string, state?: string, mode?: string, only?: boolean}} options
|
|
1237
|
+
* @returns {Promise<unknown>}
|
|
1238
|
+
*/
|
|
1239
|
+
async function swappedOrder(e, sub, words, options) {
|
|
1240
|
+
if (
|
|
1241
|
+
!(e instanceof AstryxError) ||
|
|
1242
|
+
(e.code !== E.ERR_INVALID_ARGUMENT && e.code !== E.ERR_UNKNOWN_THEME)
|
|
1243
|
+
)
|
|
1244
|
+
return e;
|
|
1245
|
+
const cwd = options.cwd ?? process.cwd();
|
|
1246
|
+
const [first, ...rest] = words.map(w => (w == null ? '' : String(w)));
|
|
1247
|
+
if (slugOk(first) && fs.existsSync(themeFiles(cwd, first).settings)) return e;
|
|
1248
|
+
const at = rest.findIndex(
|
|
1249
|
+
w => slugOk(w) && fs.existsSync(themeFiles(cwd, w).settings),
|
|
1250
|
+
);
|
|
1251
|
+
if (at < 0) return e;
|
|
1252
|
+
const theme = rest[at];
|
|
1253
|
+
const moved = [first, ...rest.filter((_, i) => i !== at)].filter(
|
|
1254
|
+
w => w !== '',
|
|
1255
|
+
);
|
|
1256
|
+
const flags = [
|
|
1257
|
+
...(options.on ? ['--on', options.on] : []),
|
|
1258
|
+
...(options.when ? ['--when', options.when] : []),
|
|
1259
|
+
...(options.state ? ['--state', options.state] : []),
|
|
1260
|
+
...(options.mode ? ['--mode', options.mode] : []),
|
|
1261
|
+
];
|
|
1262
|
+
const line = `${P} ${sub} ${theme} ${[...moved, ...flags]
|
|
1263
|
+
.map(w => quoteCommandArgument(w))
|
|
1264
|
+
.join(' ')}${options.only ? ' --only' : ''}`;
|
|
1265
|
+
const followed = await followChangeLine(sub, theme, line, cwd);
|
|
1266
|
+
e.suggestions = [
|
|
1267
|
+
{
|
|
1268
|
+
name: followed.line,
|
|
1269
|
+
reason: `do this instead: ${theme} is the theme, so it comes first${followed.why ? `, but this still needs a fix: ${followed.why}` : ''}`,
|
|
1270
|
+
},
|
|
1271
|
+
...(e.suggestions ?? []).filter(
|
|
1272
|
+
x => x.name !== followed.line && !x.name.startsWith(`${P} new `),
|
|
1273
|
+
),
|
|
1274
|
+
];
|
|
1275
|
+
return e;
|
|
890
1276
|
}
|
|
891
1277
|
|
|
892
1278
|
/**
|
|
@@ -900,9 +1286,47 @@ export async function themeEditSet(theme, thing, value, options = {}) {
|
|
|
900
1286
|
function refuseStoredTokens(ctx, slug, data, skip) {
|
|
901
1287
|
const bad = storedProblems(ctx, slug, data, skip);
|
|
902
1288
|
if (!bad.length) return;
|
|
1289
|
+
// A repair offers only the value it holds, cleaned: never a stock value
|
|
1290
|
+
// the saved setting did not hold.
|
|
1291
|
+
for (const b of bad) {
|
|
1292
|
+
if (
|
|
1293
|
+
b.fix &&
|
|
1294
|
+
!allowedLine({
|
|
1295
|
+
offered: String(b.fix),
|
|
1296
|
+
typed: String(b.setting.value),
|
|
1297
|
+
thing: b.setting.thing,
|
|
1298
|
+
mode: b.setting.mode ?? '',
|
|
1299
|
+
})
|
|
1300
|
+
)
|
|
1301
|
+
delete b.fix;
|
|
1302
|
+
// A light and a dark color saved as one (`red / blue`) is that pair.
|
|
1303
|
+
const pair =
|
|
1304
|
+
!b.fix && isColorToken(b.setting.thing)
|
|
1305
|
+
? colorPair(String(b.setting.value))
|
|
1306
|
+
: null;
|
|
1307
|
+
if (pair && !colorProblem(pair.light) && !colorProblem(pair.dark))
|
|
1308
|
+
b.fix = `light-dark(${pair.light}, ${pair.dark})`;
|
|
1309
|
+
}
|
|
903
1310
|
const found = bad.length === 1 ? bad[0] : null;
|
|
904
1311
|
// A clean value is offered only when set takes it, so the line works.
|
|
905
1312
|
const takes = (/** @type {typeof found} */ b) => {
|
|
1313
|
+
if (!b?.fix) return true;
|
|
1314
|
+
// A value whose only fault was curly quotes around it: without them,
|
|
1315
|
+
// when set takes that (`“#e11d48”` is #e11d48).
|
|
1316
|
+
const bare = /^(["'])(.*)\1$/.exec(b.fix)?.[2];
|
|
1317
|
+
if (
|
|
1318
|
+
bare &&
|
|
1319
|
+
b.setting.source === 'token' &&
|
|
1320
|
+
!/font|content/.test(b.setting.thing)
|
|
1321
|
+
) {
|
|
1322
|
+
const was = b.fix;
|
|
1323
|
+
b.fix = bare;
|
|
1324
|
+
if (takesOne(b)) return true;
|
|
1325
|
+
b.fix = was;
|
|
1326
|
+
}
|
|
1327
|
+
return takesOne(b);
|
|
1328
|
+
};
|
|
1329
|
+
const takesOne = (/** @type {typeof found} */ b) => {
|
|
906
1330
|
if (!b?.fix) return true;
|
|
907
1331
|
try {
|
|
908
1332
|
checkSetting(
|
|
@@ -941,13 +1365,14 @@ function refuseStoredTokens(ctx, slug, data, skip) {
|
|
|
941
1365
|
// A value to set only for a token whose stored value has the wrong
|
|
942
1366
|
// type; any other thing `set` would refuse, or read as a dial.
|
|
943
1367
|
...(one &&
|
|
1368
|
+
one.fix &&
|
|
944
1369
|
!one.scope &&
|
|
945
1370
|
one.setting.source === 'token' &&
|
|
946
1371
|
ctx.C.isToken(one.setting.thing)
|
|
947
1372
|
? [
|
|
948
1373
|
// The value the check suggests for this value, else a stock
|
|
949
1374
|
// one of the token's type.
|
|
950
|
-
`${P} set ${slug} ${one.setting.thing} ${quoteCommandArgument(one.fix
|
|
1375
|
+
`${P} set ${slug} ${one.setting.thing} ${quoteCommandArgument(String(one.fix))}${one.setting.mode ? ` --mode ${one.setting.mode}` : ''}`,
|
|
951
1376
|
]
|
|
952
1377
|
: one && one.fix && one.setting.source === 'dial'
|
|
953
1378
|
? [
|
|
@@ -978,28 +1403,357 @@ export async function editorStoredRefusal(root, slug) {
|
|
|
978
1403
|
}
|
|
979
1404
|
|
|
980
1405
|
/**
|
|
981
|
-
*
|
|
982
|
-
*
|
|
983
|
-
*
|
|
1406
|
+
* The token values the theme's own source gives that `set` refuses (a
|
|
1407
|
+
* radius of `banana`, a color of `12px`), each with why and the line of
|
|
1408
|
+
* the file that sets it; checked with the very rules `set` uses.
|
|
1409
|
+
* @param {import('./_settings.mjs').Ctx} ctx
|
|
984
1410
|
* @param {string} slug
|
|
985
|
-
* @
|
|
1411
|
+
* @param {import('./_settings.mjs').ThemeData} data
|
|
1412
|
+
* @returns {Promise<Array<{token: string, value: string, why: string, line: number | null, file?: string | null}>>}
|
|
986
1413
|
*/
|
|
987
|
-
|
|
988
|
-
const
|
|
989
|
-
|
|
990
|
-
|
|
1414
|
+
async function ownTokenProblems(ctx, slug, data) {
|
|
1415
|
+
const {cwd} = ctx.project;
|
|
1416
|
+
/** @type {Array<{token: string, value: string, why: string, line: number | null, file?: string | null}>} */
|
|
1417
|
+
const out = [];
|
|
1418
|
+
const known = ctx.project.core.tokenDefaults;
|
|
1419
|
+
/** @param {string} token @param {string} value @returns {string | null} */
|
|
1420
|
+
const refused = (token, value) => {
|
|
1421
|
+
try {
|
|
1422
|
+
checkSetting(ctx, slug, {...data, settings: []}, token, value, {});
|
|
1423
|
+
return null;
|
|
1424
|
+
} catch (e) {
|
|
1425
|
+
if (!(e instanceof AstryxError)) throw e;
|
|
1426
|
+
return e.message.replace(/ Nothing was changed\.$/, '');
|
|
1427
|
+
}
|
|
1428
|
+
};
|
|
1429
|
+
/** The file an entry is in, as the project names it; null for the theme file. @param {{file?: string}} e */
|
|
1430
|
+
const fileOf = e => (e.file ? path.relative(cwd, e.file) : null);
|
|
1431
|
+
/** @param {{line: number | null, file?: string}} e */
|
|
1432
|
+
const atOf = e => ({line: e.line, file: fileOf(e)});
|
|
1433
|
+
// Every value is judged as a build made now writes it (an import, an
|
|
1434
|
+
// expression, a spread or a computed key is its evaluated value). The
|
|
1435
|
+
// source is read to name the file and line that hold each value, and for
|
|
1436
|
+
// what a build erases or refuses outright: a `tokens` key given twice
|
|
1437
|
+
// (JavaScript keeps the last), a [light, dark] pair with other than two
|
|
1438
|
+
// values (the build drops the rest), a private variable (the build
|
|
1439
|
+
// refuses it), and a key that is no token name.
|
|
1440
|
+
const entries = ownTokenEntries(cwd, slug).filter(e => !e.overridden);
|
|
1441
|
+
const tokensLine = entries.find(e => e.kind === 'unresolved')?.line ?? null;
|
|
1442
|
+
/** Where the build's value for a token comes from. @param {string} token */
|
|
1443
|
+
const whereOf = token => {
|
|
1444
|
+
const e = entries.find(x => x.token === token);
|
|
1445
|
+
return e ? atOf(e) : {line: tokensLine, file: null};
|
|
1446
|
+
};
|
|
1447
|
+
for (const e of entries) {
|
|
1448
|
+
if (e.kind === 'duplicate')
|
|
1449
|
+
out.push({
|
|
1450
|
+
token: 'tokens',
|
|
1451
|
+
value: '',
|
|
1452
|
+
why: `defineTheme is given tokens twice (lines ${(e.lines ?? []).join(' and ')}); the build keeps only the last, so the first does nothing: merge them into one`,
|
|
1453
|
+
...atOf(e),
|
|
1454
|
+
});
|
|
1455
|
+
else if (e.notToken) {
|
|
1456
|
+
const key = e.key.replace(/^(["'`])(.*)\1$/, '$2');
|
|
1457
|
+
out.push({
|
|
1458
|
+
token: key,
|
|
1459
|
+
value: '',
|
|
1460
|
+
why: `${key} is no token: a token name starts with -- (such as --color-accent), and the build writes any other key as a CSS declaration on the theme's root, which styles every element; for one part, set it as a property on that part (\`${P} set ${slug} ${key} <value> --on <part>\`)`,
|
|
1461
|
+
...atOf(e),
|
|
1462
|
+
});
|
|
1463
|
+
} else if (e.token?.startsWith('--_'))
|
|
1464
|
+
out.push({
|
|
1465
|
+
token: e.token,
|
|
1466
|
+
value: '',
|
|
1467
|
+
why: `${e.token} is a private variable (--_*), which Core sets itself, so the build refuses a theme that sets one: remove it`,
|
|
1468
|
+
...atOf(e),
|
|
1469
|
+
});
|
|
1470
|
+
else if (
|
|
1471
|
+
e.kind === 'pair' &&
|
|
1472
|
+
e.token &&
|
|
1473
|
+
e.token in known &&
|
|
1474
|
+
(e.halves ?? []).length !== 2
|
|
1475
|
+
) {
|
|
1476
|
+
const halves = e.halves ?? [];
|
|
1477
|
+
out.push({
|
|
1478
|
+
token: e.token,
|
|
1479
|
+
value: `[${halves.map(h => (h === undefined ? '…' : JSON.stringify(h))).join(', ')}]`,
|
|
1480
|
+
why: `a [light, dark] pair holds exactly two values in quotes, and this holds ${halves.length}; the build would write ${halves.length < 2 ? 'light-dark() with an undefined half' : 'the first two and drop the rest'}`,
|
|
1481
|
+
...atOf(e),
|
|
1482
|
+
});
|
|
1483
|
+
}
|
|
1484
|
+
}
|
|
1485
|
+
// A private variable stops the build itself: nothing more to judge.
|
|
1486
|
+
if (out.some(b => b.token.startsWith('--_'))) return out;
|
|
1487
|
+
const built = await evaluatedTheme(ctx, slug, data.like ?? null);
|
|
1488
|
+
if (!built) return out;
|
|
1489
|
+
const named = new Set(out.map(b => b.token));
|
|
1490
|
+
// Typography: each token the build writes from it is judged like any
|
|
1491
|
+
// other, and named by the typography field that gives it.
|
|
1492
|
+
const typo = entries.filter(e => e.kind === 'typography');
|
|
1493
|
+
/** @param {string} role */
|
|
1494
|
+
const roleEntry = role =>
|
|
1495
|
+
typo.find(e => e.key.startsWith(`${role}.`)) ??
|
|
1496
|
+
(role === 'heading'
|
|
1497
|
+
? typo.find(e => e.key.startsWith('body.'))
|
|
1498
|
+
: undefined);
|
|
1499
|
+
/**
|
|
1500
|
+
* The typography field that gives a token the build writes, or null when
|
|
1501
|
+
* the token is no typography token or the source sets no typography.
|
|
1502
|
+
* @param {string} token
|
|
1503
|
+
*/
|
|
1504
|
+
const typographyOf = token => {
|
|
1505
|
+
if (!typo.length) return null;
|
|
1506
|
+
const family = /^--font-family-([a-z]+)$/.exec(token)?.[1];
|
|
1507
|
+
if (family) return roleEntry(family) ?? null;
|
|
1508
|
+
if (!/^--(font-size|text|heading)-/.test(token)) return null;
|
|
1509
|
+
if (/-weight$/.test(token))
|
|
1510
|
+
return (
|
|
1511
|
+
roleEntry(
|
|
1512
|
+
/heading/.test(token)
|
|
1513
|
+
? 'heading'
|
|
1514
|
+
: /code/.test(token)
|
|
1515
|
+
? 'code'
|
|
1516
|
+
: 'body',
|
|
1517
|
+
) ??
|
|
1518
|
+
typo.find(e => /weight/.test(e.key)) ??
|
|
1519
|
+
typo[0]
|
|
1520
|
+
);
|
|
1521
|
+
return typo.find(e => e.key.startsWith('scale.')) ?? typo[0];
|
|
1522
|
+
};
|
|
1523
|
+
// The fields the typography is given, as the build was given them
|
|
1524
|
+
// (evaluated): what Core reads them as, with the working form.
|
|
1525
|
+
/** @type {Set<any>} */
|
|
1526
|
+
const flagged = new Set();
|
|
1527
|
+
for (const e of typo) {
|
|
1528
|
+
const value = e.key
|
|
1529
|
+
.split('.')
|
|
1530
|
+
.reduce(
|
|
1531
|
+
(/** @type {any} */ o, /** @type {string} */ k) => o?.[k],
|
|
1532
|
+
built.typography,
|
|
1533
|
+
);
|
|
1534
|
+
const why = typographyProblem(e.key, value);
|
|
1535
|
+
if (why) {
|
|
1536
|
+
flagged.add(e);
|
|
1537
|
+
out.push({
|
|
1538
|
+
token: `typography.${e.key}`,
|
|
1539
|
+
value: value == null ? '' : String(value),
|
|
1540
|
+
why,
|
|
1541
|
+
...atOf(e),
|
|
1542
|
+
});
|
|
1543
|
+
}
|
|
1544
|
+
}
|
|
1545
|
+
const scale = built.typography?.scale;
|
|
1546
|
+
const scaleEntry = typo.find(e => e.key.startsWith('scale.'));
|
|
1547
|
+
if (
|
|
1548
|
+
scaleEntry &&
|
|
1549
|
+
scale &&
|
|
1550
|
+
scale.base === undefined &&
|
|
1551
|
+
!flagged.has(scaleEntry)
|
|
1552
|
+
) {
|
|
1553
|
+
flagged.add(scaleEntry);
|
|
1554
|
+
out.push({
|
|
1555
|
+
token: 'typography.scale',
|
|
1556
|
+
value: '',
|
|
1557
|
+
why: 'the type scale is given no base, and Core reads the sizes from the base and the ratio together: add the body size in pixels, such as scale: {base: 16, ratio: …}',
|
|
1558
|
+
...atOf(scaleEntry),
|
|
1559
|
+
});
|
|
1560
|
+
}
|
|
1561
|
+
for (const [token, value] of built.tops) {
|
|
1562
|
+
if (!(token in known) || named.has(token)) continue;
|
|
1563
|
+
const shape = built.shapes.get(token) ?? {kind: 'other'};
|
|
1564
|
+
if (
|
|
1565
|
+
value == null &&
|
|
1566
|
+
shape.kind !== 'number' &&
|
|
1567
|
+
shape.kind !== 'object' &&
|
|
1568
|
+
shape.kind !== 'pair'
|
|
1569
|
+
)
|
|
1570
|
+
continue;
|
|
1571
|
+
const owner = typographyOf(token);
|
|
1572
|
+
const own = built.own.has(token);
|
|
1573
|
+
if (!own && !owner) continue;
|
|
1574
|
+
// A typography token the build leaves as the base theme writes it is
|
|
1575
|
+
// the base theme's.
|
|
1576
|
+
if (owner && !own && built.base.get(token) === value) continue;
|
|
1577
|
+
// One problem per typography field: the first token it builds wrong.
|
|
1578
|
+
if (owner && flagged.has(owner)) continue;
|
|
1579
|
+
const at = owner ? atOf(owner) : whereOf(token);
|
|
1580
|
+
const label = owner ? `typography.${owner.key} (builds ${token})` : token;
|
|
1581
|
+
// A number, an object or a pair that is not two texts is no text.
|
|
1582
|
+
if (
|
|
1583
|
+
shape.kind === 'number' ||
|
|
1584
|
+
shape.kind === 'object' ||
|
|
1585
|
+
(shape.kind === 'pair' &&
|
|
1586
|
+
!(shape.halves ?? []).every(h => typeof h === 'string'))
|
|
1587
|
+
) {
|
|
1588
|
+
out.push({
|
|
1589
|
+
token: label,
|
|
1590
|
+
value: '',
|
|
1591
|
+
why: nonTextMessage(
|
|
1592
|
+
ctx,
|
|
1593
|
+
slug,
|
|
1594
|
+
shape.kind === 'object'
|
|
1595
|
+
? [token, shape.value, 'object']
|
|
1596
|
+
: [token, shape.kind === 'pair' ? shape.halves : shape.value],
|
|
1597
|
+
),
|
|
1598
|
+
...at,
|
|
1599
|
+
});
|
|
1600
|
+
if (owner) flagged.add(owner);
|
|
1601
|
+
continue;
|
|
1602
|
+
}
|
|
1603
|
+
if (value == null) continue;
|
|
1604
|
+
// Only a color differs by mode: a pair on any other token builds a
|
|
1605
|
+
// light-dark() no browser reads there. A size whose halves are bare
|
|
1606
|
+
// numbers is named with the unit it needs too.
|
|
1607
|
+
if (/^light-dark\(/i.test(value) && !isColorToken(token)) {
|
|
1608
|
+
const halves = value
|
|
1609
|
+
.replace(/^light-dark\(\s*|\s*\)$/gi, '')
|
|
1610
|
+
.split(/\s*,\s*/);
|
|
1611
|
+
const unitless =
|
|
1612
|
+
ctx.C.typeOf(token) === 'size' &&
|
|
1613
|
+
halves.every(h => /^\d*\.?\d+$/.test(h));
|
|
1614
|
+
out.push({
|
|
1615
|
+
token: label,
|
|
1616
|
+
value,
|
|
1617
|
+
why: unitless
|
|
1618
|
+
? nonTextMessage(ctx, slug, [token, halves.map(Number), 'unit'])
|
|
1619
|
+
: `${at.file ?? `${slug}.theme.ts`} gives ${token} a [light, dark] pair, but only colors differ by mode: the build would write light-dark(), which browsers take only for colors; give it one value`,
|
|
1620
|
+
...at,
|
|
1621
|
+
});
|
|
1622
|
+
if (owner) flagged.add(owner);
|
|
1623
|
+
continue;
|
|
1624
|
+
}
|
|
1625
|
+
const why = refused(token, value);
|
|
1626
|
+
if (why) {
|
|
1627
|
+
out.push({token: label, value, why, ...at});
|
|
1628
|
+
if (owner) flagged.add(owner);
|
|
1629
|
+
}
|
|
1630
|
+
}
|
|
1631
|
+
return out;
|
|
1632
|
+
}
|
|
1633
|
+
|
|
1634
|
+
/**
|
|
1635
|
+
* What is wrong with one typography field of a theme's own source, or
|
|
1636
|
+
* null: a family is one family name without quotes (Core quotes it whole)
|
|
1637
|
+
* and with nothing CSS would read as the end of the value; the scale's
|
|
1638
|
+
* ratio is above 1 and at most 4, its base a positive number of pixels.
|
|
1639
|
+
* @param {string} key the dotted field (`body.family`, `scale.ratio`)
|
|
1640
|
+
* @param {unknown} value
|
|
1641
|
+
* @returns {string | null}
|
|
1642
|
+
*/
|
|
1643
|
+
function typographyProblem(key, value) {
|
|
1644
|
+
const field = key.split('.').pop();
|
|
1645
|
+
if (field === 'family') {
|
|
1646
|
+
if (typeof value !== 'string')
|
|
1647
|
+
return 'a typography family is a family name in quotes, such as "Inter"';
|
|
1648
|
+
const v = value.trim();
|
|
1649
|
+
if (/[;{}<>]/.test(v))
|
|
1650
|
+
return `"${v}" holds a ; { } < or >, so the CSS writer drops the whole declaration; give the family name alone, such as "Inter"`;
|
|
1651
|
+
const quoted = /^(["'])(.*)\1$/.exec(v);
|
|
1652
|
+
if (quoted)
|
|
1653
|
+
return `the family is written in quotes, and Core adds its own, so it builds ${JSON.stringify(`"${v}"`)}, a name no font has; write it without them: family: '${quoted[2]}'`;
|
|
1654
|
+
// Core quotes a family with a space whole, so a list here is one
|
|
1655
|
+
// family by that whole name, which exists nowhere.
|
|
1656
|
+
if (v.includes(','))
|
|
1657
|
+
return `a typography family is one family name, which Core quotes whole ("${v}" is one family that exists nowhere); give the first as family and the rest as fallbacks, such as family: '${v
|
|
1658
|
+
.split(',')[0]
|
|
1659
|
+
.trim()
|
|
1660
|
+
.replace(
|
|
1661
|
+
/^["']|["']$/g,
|
|
1662
|
+
'',
|
|
1663
|
+
)}', fallbacks: '${v.split(',').slice(1).join(',').trim()}'`;
|
|
1664
|
+
if (!v || /^[-+]?\d/.test(v) || /^(inherit|initial|unset|revert)$/i.test(v))
|
|
1665
|
+
return `"${v}" is no font family name; give one such as "Inter"`;
|
|
1666
|
+
return null;
|
|
1667
|
+
}
|
|
1668
|
+
if (field === 'ratio') {
|
|
1669
|
+
const n = Number(value);
|
|
1670
|
+
if (!Number.isFinite(n) || n <= 1 || n > 4)
|
|
1671
|
+
return `the type scale's ratio is how much each size grows over the last, a number above 1 and at most 4 (such as 1.2); ${JSON.stringify(value)} makes ${n <= 0 ? 'sizes that are not numbers' : n <= 1 ? 'every size the same or smaller' : 'sizes no page can use'}`;
|
|
1672
|
+
return null;
|
|
1673
|
+
}
|
|
1674
|
+
if (field === 'base') {
|
|
1675
|
+
const n = Number(value);
|
|
1676
|
+
if (!Number.isFinite(n) || n <= 0) {
|
|
1677
|
+
// A size with a unit builds NaNrem: the number of pixels it means.
|
|
1678
|
+
const m = /^\s*([0-9.]+)\s*(px|rem|em)\s*$/i.exec(String(value));
|
|
1679
|
+
const px = m ? Number(m[1]) * (/^r?em$/i.test(m[2]) ? 16 : 1) : null;
|
|
1680
|
+
return `the type scale's base is the body size, a positive number of pixels${px ? `, so ${JSON.stringify(value)} is base: ${px}` : ' (such as 16)'}; ${JSON.stringify(value)} builds sizes no page can use${m ? ' (NaNrem)' : ''}`;
|
|
1681
|
+
}
|
|
1682
|
+
return null;
|
|
1683
|
+
}
|
|
1684
|
+
return null;
|
|
1685
|
+
}
|
|
1686
|
+
|
|
1687
|
+
/**
|
|
1688
|
+
* Refuse a theme whose own source gives a token a value `set` refuses: the
|
|
1689
|
+
* build would write it as it is (a browser drops it), so it is named, with
|
|
1690
|
+
* the line of the file, before anything is written.
|
|
1691
|
+
* @param {import('./_settings.mjs').Ctx} ctx
|
|
1692
|
+
* @param {string} slug
|
|
1693
|
+
* @param {import('./_settings.mjs').ThemeData} data
|
|
1694
|
+
*/
|
|
1695
|
+
async function refuseOwnTokenValues(ctx, slug, data) {
|
|
1696
|
+
const err = await ownTokenRefusal(ctx, slug, data);
|
|
1697
|
+
if (err) throw err;
|
|
1698
|
+
}
|
|
1699
|
+
setOwnTokenCheck(refuseOwnTokenValues);
|
|
1700
|
+
|
|
1701
|
+
/**
|
|
1702
|
+
* The refusal for own-source token values `set` refuses, or null.
|
|
1703
|
+
* @param {import('./_settings.mjs').Ctx} ctx
|
|
1704
|
+
* @param {string} slug
|
|
1705
|
+
* @param {import('./_settings.mjs').ThemeData} data
|
|
1706
|
+
* @returns {Promise<AstryxError | null>}
|
|
1707
|
+
*/
|
|
1708
|
+
async function ownTokenRefusal(ctx, slug, data) {
|
|
1709
|
+
const bad = await ownTokenProblems(ctx, slug, data);
|
|
1710
|
+
if (!bad.length) return null;
|
|
1711
|
+
const own = `themes/${slug}/${slug}.theme.ts`;
|
|
1712
|
+
const file = bad[0].file ?? own;
|
|
991
1713
|
return new AstryxError(
|
|
992
|
-
|
|
1714
|
+
`${own} gives ${bad.length === 1 ? 'a token a value' : `${bad.length} tokens values`} the editor refuses, which the build would write as it is: ${bad
|
|
1715
|
+
.slice(0, 3)
|
|
1716
|
+
.map(
|
|
1717
|
+
b =>
|
|
1718
|
+
`${b.token}${b.value ? `: "${b.value}"` : ''}${b.file ? ` (in ${b.file}${b.line ? `, line ${b.line}` : ''})` : b.line ? ` (line ${b.line})` : ''}: ${b.why.replace(/\.+$/, '')}`,
|
|
1719
|
+
)
|
|
1720
|
+
.join(
|
|
1721
|
+
'; ',
|
|
1722
|
+
)}${bad.length > 3 ? `; and ${bad.length - 3} more` : ''}. Change it in ${file}. Nothing was changed.`,
|
|
993
1723
|
[
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
1724
|
+
bad[0].line
|
|
1725
|
+
? {
|
|
1726
|
+
name: `sed -n ${bad[0].line}p ${quoteCommandArgument(file)}`,
|
|
1727
|
+
reason: 'see the line that sets it',
|
|
1728
|
+
}
|
|
1729
|
+
: {
|
|
1730
|
+
name: `grep -n -- ${quoteCommandArgument(bad[0].token)} ${quoteCommandArgument(file)}`,
|
|
1731
|
+
reason: 'see the line',
|
|
1732
|
+
},
|
|
998
1733
|
],
|
|
999
1734
|
ERROR_CODES.ERR_THEME_INVALID,
|
|
1000
1735
|
);
|
|
1001
1736
|
}
|
|
1002
1737
|
|
|
1738
|
+
/**
|
|
1739
|
+
* The refusal `compile` gives an editor theme whose own source gives a
|
|
1740
|
+
* token a value `set` refuses, or null.
|
|
1741
|
+
* @param {string} root
|
|
1742
|
+
* @param {string} slug
|
|
1743
|
+
* @returns {Promise<AstryxError | null>}
|
|
1744
|
+
*/
|
|
1745
|
+
export async function editorOwnTokenRefusal(root, slug) {
|
|
1746
|
+
const ctx = await context(root);
|
|
1747
|
+
/** @type {import('./_settings.mjs').ThemeData} */
|
|
1748
|
+
let data;
|
|
1749
|
+
try {
|
|
1750
|
+
data = loadTheme(root, slug);
|
|
1751
|
+
} catch {
|
|
1752
|
+
return null;
|
|
1753
|
+
}
|
|
1754
|
+
return ownTokenRefusal(ctx, slug, data);
|
|
1755
|
+
}
|
|
1756
|
+
|
|
1003
1757
|
/**
|
|
1004
1758
|
* A note for type scale steps that land outside 9 to 200 pixels.
|
|
1005
1759
|
* @param {Record<string, string>} res resolved light tokens
|
|
@@ -1021,6 +1775,223 @@ function extremeSteps(res) {
|
|
|
1021
1775
|
: [];
|
|
1022
1776
|
}
|
|
1023
1777
|
|
|
1778
|
+
export {carriesTyped, offersTyped} from './_normal.mjs';
|
|
1779
|
+
|
|
1780
|
+
/**
|
|
1781
|
+
* An object of settings written as JSON, with single quotes, or as its
|
|
1782
|
+
* entries with no braces (`"accent": "#e11d48", "corners": "pill"`).
|
|
1783
|
+
* Throws when it is none of these.
|
|
1784
|
+
* @param {string} text
|
|
1785
|
+
* @returns {any}
|
|
1786
|
+
*/
|
|
1787
|
+
function looseObject(text) {
|
|
1788
|
+
const t = text.trim();
|
|
1789
|
+
const braced = t.startsWith('{') ? t : `{${t}}`;
|
|
1790
|
+
try {
|
|
1791
|
+
return JSON.parse(braced);
|
|
1792
|
+
} catch {
|
|
1793
|
+
return JSON.parse(
|
|
1794
|
+
braced.replace(/'((?:[^'\\]|\\.)*)'/g, (_, x) =>
|
|
1795
|
+
JSON.stringify(x.replace(/\\'/g, "'")),
|
|
1796
|
+
),
|
|
1797
|
+
);
|
|
1798
|
+
}
|
|
1799
|
+
}
|
|
1800
|
+
|
|
1801
|
+
/**
|
|
1802
|
+
* A refusal with each line that sets the typed setting again kept only
|
|
1803
|
+
* when it carries the value typed; with none left, `how` for the setting.
|
|
1804
|
+
* Another setting's line, an undo or a look stays.
|
|
1805
|
+
* @param {any} e
|
|
1806
|
+
* @param {'set' | 'undo'} sub
|
|
1807
|
+
* @param {string} slug
|
|
1808
|
+
* @param {string} thing
|
|
1809
|
+
* @param {unknown} typed
|
|
1810
|
+
* @param {import('./_settings.mjs').ThemeData} [data] the theme, whose saved
|
|
1811
|
+
* values a keep line may carry
|
|
1812
|
+
*/
|
|
1813
|
+
function carryTyped(e, sub, slug, thing, typed, data) {
|
|
1814
|
+
if (
|
|
1815
|
+
sub !== 'set' ||
|
|
1816
|
+
!(e instanceof AstryxError) ||
|
|
1817
|
+
typeof typed !== 'string' ||
|
|
1818
|
+
!e.suggestions?.length
|
|
1819
|
+
)
|
|
1820
|
+
return e;
|
|
1821
|
+
const head = new RegExp(
|
|
1822
|
+
`^.* set \\S+ (?:'([^']+)'|(\\S+)) (?:'((?:[^']|'\\\\'')*)'|(\\S+))`,
|
|
1823
|
+
);
|
|
1824
|
+
// Every set line, of this setting or another (a dial's other name, a
|
|
1825
|
+
// label, a theme-wide equivalent), offers a value only through the gate's
|
|
1826
|
+
// declared sources (readsTyped): never a stock, reset or nearest value.
|
|
1827
|
+
// A line that carries only part of the value is offered only when the
|
|
1828
|
+
// refusal's lines together carry all of it (a family and its weight).
|
|
1829
|
+
// With no value typed, the thing held it (`accent: red`).
|
|
1830
|
+
const typedText = typed.trim() ? typed : String(thing);
|
|
1831
|
+
/** @type {Map<string, string[]>} */
|
|
1832
|
+
const saved = new Map();
|
|
1833
|
+
for (const x of data?.settings ?? [])
|
|
1834
|
+
saved.set(x.thing, [...(saved.get(x.thing) ?? []), String(x.value ?? '')]);
|
|
1835
|
+
if (data?.like) saved.set('base', [data.like]);
|
|
1836
|
+
if (data?.mode) saved.set('mode', [data.mode]);
|
|
1837
|
+
const reads = e.suggestions.map(x => {
|
|
1838
|
+
const m = head.exec(x.name);
|
|
1839
|
+
if (!m) return /** @type {true | number[] | false} */ (true);
|
|
1840
|
+
return readsTyped({
|
|
1841
|
+
offered: m[3] ?? m[4],
|
|
1842
|
+
typed: typedText,
|
|
1843
|
+
thing: (m[1] ?? m[2]).replace(/^'(.*)'$/, '$1'),
|
|
1844
|
+
typedThing: String(thing),
|
|
1845
|
+
saved,
|
|
1846
|
+
mode: / --mode (light|dark)\b/.exec(x.name)?.[1] ?? '',
|
|
1847
|
+
});
|
|
1848
|
+
});
|
|
1849
|
+
const covered = coversTyped(reads, typedText);
|
|
1850
|
+
/** @type {Set<string>} */
|
|
1851
|
+
const dropped = new Set();
|
|
1852
|
+
const lines = e.suggestions.filter((x, i) => {
|
|
1853
|
+
if (reads[i] === true || (Array.isArray(reads[i]) && covered)) return true;
|
|
1854
|
+
const m = head.exec(x.name);
|
|
1855
|
+
if (m) dropped.add(String(m[3] ?? m[4]).toLowerCase());
|
|
1856
|
+
return false;
|
|
1857
|
+
});
|
|
1858
|
+
// A value named as a did-you-mean goes with its line.
|
|
1859
|
+
const kept = lines.filter(
|
|
1860
|
+
x => !(x.reason === 'did you mean' && dropped.has(x.name.toLowerCase())),
|
|
1861
|
+
);
|
|
1862
|
+
// A refusal always names a command that works: with no set, undo, new or
|
|
1863
|
+
// how line left, how for the setting.
|
|
1864
|
+
const runnable = kept.some(
|
|
1865
|
+
x => x.reason !== 'did you mean' && !/ --help$/.test(x.name),
|
|
1866
|
+
);
|
|
1867
|
+
if (kept.length === e.suggestions.length && runnable) return e;
|
|
1868
|
+
e.suggestions = runnable
|
|
1869
|
+
? kept
|
|
1870
|
+
: [
|
|
1871
|
+
...kept.filter(x => !/ --help$/.test(x.name)),
|
|
1872
|
+
{
|
|
1873
|
+
name: `${P} how ${quoteCommandArgument(String(thing))}`,
|
|
1874
|
+
reason: 'what it takes',
|
|
1875
|
+
},
|
|
1876
|
+
];
|
|
1877
|
+
return e;
|
|
1878
|
+
}
|
|
1879
|
+
|
|
1880
|
+
/**
|
|
1881
|
+
* A theme's settings file as written, for the values a keep line may carry
|
|
1882
|
+
* when the theme does not load (a damaged entry); null when it cannot be
|
|
1883
|
+
* read.
|
|
1884
|
+
* @param {string} cwd
|
|
1885
|
+
* @param {string} slug
|
|
1886
|
+
* @returns {import('./_settings.mjs').ThemeData | undefined}
|
|
1887
|
+
*/
|
|
1888
|
+
function savedAsWritten(cwd, slug) {
|
|
1889
|
+
try {
|
|
1890
|
+
const data = settingsJson(
|
|
1891
|
+
fs.readFileSync(themeFiles(cwd, slug).settings, 'utf8'),
|
|
1892
|
+
);
|
|
1893
|
+
return entriesReadable(data) ? data : undefined;
|
|
1894
|
+
} catch {
|
|
1895
|
+
return undefined;
|
|
1896
|
+
}
|
|
1897
|
+
}
|
|
1898
|
+
|
|
1899
|
+
/**
|
|
1900
|
+
* The lines of a repair that work: each run through set's own check (in
|
|
1901
|
+
* memory) and offered only when set takes it as offered and its value
|
|
1902
|
+
* passes the allowlist of exact readings of what was typed. With none
|
|
1903
|
+
* left, how for the thing.
|
|
1904
|
+
* @param {'set' | 'undo'} sub
|
|
1905
|
+
* @param {string} slug
|
|
1906
|
+
* @param {Array<string | [string, string]>} lines each line, or each line
|
|
1907
|
+
* with the typed text it carries (an entry of a pasted object)
|
|
1908
|
+
* @param {string} cwd
|
|
1909
|
+
* @param {string} typed
|
|
1910
|
+
* @param {string} thing
|
|
1911
|
+
* @returns {Promise<string[]>}
|
|
1912
|
+
*/
|
|
1913
|
+
async function workingLines(sub, slug, lines, cwd, typed, thing) {
|
|
1914
|
+
/** @type {string[]} */
|
|
1915
|
+
const out = [];
|
|
1916
|
+
for (const item of lines) {
|
|
1917
|
+
const [line, own] = Array.isArray(item) ? item : [item, typed];
|
|
1918
|
+
// The line as set takes it (a repair set offers for it folded in).
|
|
1919
|
+
const followed = await followChangeLine(sub, slug, line, cwd);
|
|
1920
|
+
if (followed.why) continue;
|
|
1921
|
+
const read = readSetLine(followed.line, slug);
|
|
1922
|
+
if (
|
|
1923
|
+
sub === 'set' &&
|
|
1924
|
+
read &&
|
|
1925
|
+
!allowedLine({
|
|
1926
|
+
offered: read.value,
|
|
1927
|
+
typed: own,
|
|
1928
|
+
thing: read.thing,
|
|
1929
|
+
mode: String(read.flags?.mode ?? ''),
|
|
1930
|
+
})
|
|
1931
|
+
)
|
|
1932
|
+
continue;
|
|
1933
|
+
out.push(followed.line);
|
|
1934
|
+
}
|
|
1935
|
+
return out.length ? out : [`${P} how ${quoteCommandArgument(thing)}`];
|
|
1936
|
+
}
|
|
1937
|
+
|
|
1938
|
+
/**
|
|
1939
|
+
* A `set` or `undo` line for the theme a path or other letters named, run
|
|
1940
|
+
* through that command's own check (in memory, nothing written). Each
|
|
1941
|
+
* repair a refusal of it offers is folded into the one line, so the line
|
|
1942
|
+
* runs as offered; `why` names what is still refused when no repair is
|
|
1943
|
+
* offered.
|
|
1944
|
+
* @param {'set' | 'undo'} sub
|
|
1945
|
+
* @param {string} slug
|
|
1946
|
+
* @param {string} line
|
|
1947
|
+
* @param {string} cwd
|
|
1948
|
+
* @returns {Promise<{line: string, why: string | null}>}
|
|
1949
|
+
*/
|
|
1950
|
+
async function followChangeLine(sub, slug, line, cwd) {
|
|
1951
|
+
/** @type {import('./_settings.mjs').ThemeData} */
|
|
1952
|
+
let data;
|
|
1953
|
+
/** @type {import('./_settings.mjs').Ctx} */
|
|
1954
|
+
let ctx;
|
|
1955
|
+
try {
|
|
1956
|
+
data = loadTheme(cwd, slug);
|
|
1957
|
+
ctx = /** @type {import('./_settings.mjs').Ctx} */ (await context(cwd));
|
|
1958
|
+
ctx.base = await baseResolved(ctx.project, data.like);
|
|
1959
|
+
} catch {
|
|
1960
|
+
return {line, why: null};
|
|
1961
|
+
}
|
|
1962
|
+
const prefix = `${P} ${sub} ${slug} `;
|
|
1963
|
+
return followLine(
|
|
1964
|
+
line,
|
|
1965
|
+
now => {
|
|
1966
|
+
const read = readSetLine(
|
|
1967
|
+
sub === 'undo' ? now.replace(`${P} undo `, `${P} set `) : now,
|
|
1968
|
+
slug,
|
|
1969
|
+
);
|
|
1970
|
+
if (!read) return null;
|
|
1971
|
+
try {
|
|
1972
|
+
const s = checkSetting(
|
|
1973
|
+
ctx,
|
|
1974
|
+
slug,
|
|
1975
|
+
structuredClone(data),
|
|
1976
|
+
read.thing,
|
|
1977
|
+
read.value,
|
|
1978
|
+
read.flags,
|
|
1979
|
+
sub === 'undo',
|
|
1980
|
+
);
|
|
1981
|
+
return sub === 'undo' && !data.settings.some(x => keyOf(x) === keyOf(s))
|
|
1982
|
+
? new AstryxError(
|
|
1983
|
+
`${slug} does not set ${describe({...s, value: '?'}).replace(' = ?', '')}`,
|
|
1984
|
+
)
|
|
1985
|
+
: null;
|
|
1986
|
+
} catch (e) {
|
|
1987
|
+
if (e instanceof AstryxError) return e;
|
|
1988
|
+
throw e;
|
|
1989
|
+
}
|
|
1990
|
+
},
|
|
1991
|
+
name => name.startsWith(prefix),
|
|
1992
|
+
);
|
|
1993
|
+
}
|
|
1994
|
+
|
|
1024
1995
|
/**
|
|
1025
1996
|
* @param {'set' | 'undo'} sub
|
|
1026
1997
|
* @param {string} slug
|
|
@@ -1033,21 +2004,192 @@ async function change(sub, slug, thing, value, options) {
|
|
|
1033
2004
|
// As typed: an undo of a saved entry written in a form the cleanup below
|
|
1034
2005
|
// repairs (`Corners`, `var(--radius-page)`) removes that exact entry.
|
|
1035
2006
|
const typedThing = thing;
|
|
2007
|
+
const typedValue = value;
|
|
2008
|
+
// An object of several settings pasted as one (JSON, single quotes, or
|
|
2009
|
+
// its entries with no braces, split at the first colon on the way): one
|
|
2010
|
+
// set line each.
|
|
2011
|
+
const objectText =
|
|
2012
|
+
typeof thing !== 'string'
|
|
2013
|
+
? null
|
|
2014
|
+
: value == null || value === ''
|
|
2015
|
+
? /^\s*\{[\s\S]*\}\s*$/.test(thing)
|
|
2016
|
+
? thing
|
|
2017
|
+
: null
|
|
2018
|
+
: /^\s*\{?\s*["']/.test(thing) && /["']\s*:/.test(String(value))
|
|
2019
|
+
? `${thing}:${value}`
|
|
2020
|
+
: null;
|
|
2021
|
+
if (objectText != null) {
|
|
2022
|
+
/** @type {any} */
|
|
2023
|
+
let obj = null;
|
|
2024
|
+
try {
|
|
2025
|
+
obj = looseObject(objectText);
|
|
2026
|
+
} catch {
|
|
2027
|
+
// Not an object: read as typed.
|
|
2028
|
+
}
|
|
2029
|
+
if (obj && typeof obj === 'object' && Object.keys(obj).length > 1)
|
|
2030
|
+
refuse(
|
|
2031
|
+
E.ERR_INVALID_ARGUMENT,
|
|
2032
|
+
`This holds ${Object.keys(obj).length} settings; ${sub} changes one at a time.`,
|
|
2033
|
+
{
|
|
2034
|
+
// Each entry as its own line, a nested value (`{"$value": …}`, a
|
|
2035
|
+
// light and dark pair) written back as typed; each line checked,
|
|
2036
|
+
// and one set refuses is left out.
|
|
2037
|
+
run: await workingLines(
|
|
2038
|
+
sub,
|
|
2039
|
+
slug,
|
|
2040
|
+
Object.entries(obj)
|
|
2041
|
+
.slice(0, 6)
|
|
2042
|
+
.map(([k, x]) => {
|
|
2043
|
+
const entry =
|
|
2044
|
+
x != null && typeof x === 'object'
|
|
2045
|
+
? JSON.stringify(x)
|
|
2046
|
+
: String(x);
|
|
2047
|
+
const read = String(normalizeEntry(k, entry).value ?? '');
|
|
2048
|
+
// Each line with the entry it carries, as typed.
|
|
2049
|
+
return /** @type {[string, string]} */ ([
|
|
2050
|
+
`${P} ${sub} ${slug} ${quoteCommandArgument(k)}${sub === 'set' ? ` ${quoteCommandArgument(read)}` : ''}`,
|
|
2051
|
+
read,
|
|
2052
|
+
]);
|
|
2053
|
+
}),
|
|
2054
|
+
options.cwd ?? process.cwd(),
|
|
2055
|
+
objectText,
|
|
2056
|
+
'settings',
|
|
2057
|
+
),
|
|
2058
|
+
},
|
|
2059
|
+
);
|
|
2060
|
+
}
|
|
2061
|
+
// A flag typed inside the value (`'red --mode dark'`, `'4px --state
|
|
2062
|
+
// hover'`, `'pill --on button'`): the same command with the flag lifted
|
|
2063
|
+
// out, never the value alone, which would change another scope.
|
|
2064
|
+
if (typeof value === 'string' && /\s--(mode|state|on|when)\b/.test(value)) {
|
|
2065
|
+
/** @type {Record<string, string>} */
|
|
2066
|
+
const lifted = {};
|
|
2067
|
+
// The rest is cleaned as any value is (a trailing `;`, `!important`,
|
|
2068
|
+
// a comment).
|
|
2069
|
+
const bare = withoutCopyDebris(
|
|
2070
|
+
value.replace(
|
|
2071
|
+
/\s+--(mode|state|on|when)(?:\s*=\s*|\s+)("[^"]*"|'[^']*'|\S+)/g,
|
|
2072
|
+
(_, f, x) => {
|
|
2073
|
+
lifted[f] = x.replace(/^(["'])(.*)\1$/, '$2');
|
|
2074
|
+
return '';
|
|
2075
|
+
},
|
|
2076
|
+
),
|
|
2077
|
+
);
|
|
2078
|
+
if (bare && Object.keys(lifted).length) {
|
|
2079
|
+
const opts = /** @type {Record<string, unknown>} */ ({
|
|
2080
|
+
...options,
|
|
2081
|
+
...lifted,
|
|
2082
|
+
});
|
|
2083
|
+
const flagText = ['on', 'when', 'state', 'mode']
|
|
2084
|
+
.filter(f => opts[f])
|
|
2085
|
+
.map(f => ` --${f} ${quoteCommandArgument(String(opts[f]))}`)
|
|
2086
|
+
.join('');
|
|
2087
|
+
refuse(
|
|
2088
|
+
E.ERR_INVALID_ARGUMENT,
|
|
2089
|
+
`"${value}" holds ${Object.keys(lifted)
|
|
2090
|
+
.map(f => `--${f}`)
|
|
2091
|
+
.join(' and ')} inside the value; a flag goes outside the quotes.`,
|
|
2092
|
+
{
|
|
2093
|
+
// The line is checked as set checks it; one set refuses is left
|
|
2094
|
+
// out, and how is named instead.
|
|
2095
|
+
run: await workingLines(
|
|
2096
|
+
sub,
|
|
2097
|
+
slug,
|
|
2098
|
+
[
|
|
2099
|
+
`${P} ${sub} ${slug} ${quoteCommandArgument(String(thing))}${sub === 'set' ? ` ${quoteCommandArgument(bare)}` : ''}${flagText}${options.only ? ' --only' : ''}`,
|
|
2100
|
+
],
|
|
2101
|
+
options.cwd ?? process.cwd(),
|
|
2102
|
+
value,
|
|
2103
|
+
String(thing),
|
|
2104
|
+
),
|
|
2105
|
+
},
|
|
2106
|
+
);
|
|
2107
|
+
}
|
|
2108
|
+
}
|
|
1036
2109
|
// How it was typed, put right before anything reads it (a pasted
|
|
1037
2110
|
// declaration, a dash, a var(), invisible spaces).
|
|
2111
|
+
/** @type {string | undefined} */
|
|
2112
|
+
let dropped;
|
|
1038
2113
|
if (typeof thing === 'string') {
|
|
1039
2114
|
const entry = normalizeEntry(thing, value);
|
|
1040
2115
|
thing = entry.thing;
|
|
1041
2116
|
value = entry.value;
|
|
2117
|
+
dropped = entry.dropped;
|
|
1042
2118
|
}
|
|
1043
2119
|
/** @type {{ctx?: import('./_settings.mjs').Ctx, data?: import('./_settings.mjs').ThemeData}} */
|
|
1044
2120
|
const seen = {};
|
|
1045
2121
|
try {
|
|
1046
|
-
|
|
2122
|
+
const r = await changeOnce(
|
|
2123
|
+
sub,
|
|
2124
|
+
slug,
|
|
2125
|
+
thing,
|
|
2126
|
+
value,
|
|
2127
|
+
options,
|
|
2128
|
+
seen,
|
|
2129
|
+
typedThing,
|
|
2130
|
+
);
|
|
2131
|
+
// A second declaration pasted after the first is not set: said, with
|
|
2132
|
+
// its own set line.
|
|
2133
|
+
if (dropped && sub === 'set') {
|
|
2134
|
+
const m = /^([^:]+):\s*(.*?);?\s*$/.exec(dropped);
|
|
2135
|
+
const flags = [
|
|
2136
|
+
...(options.on ? [`--on ${options.on}`] : []),
|
|
2137
|
+
...(options.when ? [`--when ${options.when}`] : []),
|
|
2138
|
+
...(options.state ? [`--state ${options.state}`] : []),
|
|
2139
|
+
].join(' ');
|
|
2140
|
+
// Its line goes through the one gate as a repair does: checked as set
|
|
2141
|
+
// checks it (a repair set offers for it folded in) and carrying what
|
|
2142
|
+
// was pasted; else no line is named.
|
|
2143
|
+
const [line] = m
|
|
2144
|
+
? await workingLines(
|
|
2145
|
+
'set',
|
|
2146
|
+
slug,
|
|
2147
|
+
[
|
|
2148
|
+
`${P} set ${slug} ${quoteCommandArgument(m[1].trim())} ${quoteCommandArgument(m[2].trim())}${flags ? ` ${flags}` : ''}`,
|
|
2149
|
+
],
|
|
2150
|
+
options.cwd ?? process.cwd(),
|
|
2151
|
+
m[2].trim(),
|
|
2152
|
+
m[1].trim(),
|
|
2153
|
+
)
|
|
2154
|
+
: [];
|
|
2155
|
+
/** @type {any} */ (r.data).notes = [
|
|
2156
|
+
...(r.data.notes ?? []),
|
|
2157
|
+
`the pasted text also held "${dropped}", which this did not set${line && / set /.test(line) ? `: ${line} sets it` : ''}`,
|
|
2158
|
+
];
|
|
2159
|
+
}
|
|
2160
|
+
// A mode or base entry in the settings list does nothing: said after
|
|
2161
|
+
// every change, with the undo that removes it.
|
|
2162
|
+
if (seen.ctx && r.data.theme) {
|
|
2163
|
+
/** @type {import('./_settings.mjs').ThemeData | null} */
|
|
2164
|
+
let now = null;
|
|
2165
|
+
try {
|
|
2166
|
+
now = loadTheme(seen.ctx.project.cwd, r.data.theme);
|
|
2167
|
+
} catch {
|
|
2168
|
+
now = null;
|
|
2169
|
+
}
|
|
2170
|
+
const left = now ? misplacedNotes(r.data.theme, now) : [];
|
|
2171
|
+
if (left.length)
|
|
2172
|
+
/** @type {any} */ (r.data).notes = [...left, ...(r.data.notes ?? [])];
|
|
2173
|
+
}
|
|
2174
|
+
return r;
|
|
1047
2175
|
} catch (e) {
|
|
1048
|
-
// A theme name one letter off an existing theme
|
|
1049
|
-
//
|
|
1050
|
-
|
|
2176
|
+
// A theme name one letter off an existing theme, or typed in other
|
|
2177
|
+
// letters or as a path (T, ./t, themes/t): the same command with that
|
|
2178
|
+
// name comes first, never a bare look at the theme that drops the change.
|
|
2179
|
+
const named =
|
|
2180
|
+
e instanceof AstryxError &&
|
|
2181
|
+
(e.code === E.ERR_UNKNOWN_THEME ||
|
|
2182
|
+
(e.code === E.ERR_INVALID_ARGUMENT &&
|
|
2183
|
+
(e.suggestions ?? []).some(
|
|
2184
|
+
x =>
|
|
2185
|
+
x.reason === 'did you mean' &&
|
|
2186
|
+
slugOk(x.name) &&
|
|
2187
|
+
x.name !== slug &&
|
|
2188
|
+
fs.existsSync(
|
|
2189
|
+
themeFiles(options.cwd ?? process.cwd(), x.name).settings,
|
|
2190
|
+
),
|
|
2191
|
+
)));
|
|
2192
|
+
if (named) {
|
|
1051
2193
|
const near = (e.suggestions ?? []).find(x => x.reason === 'did you mean');
|
|
1052
2194
|
if (near && slugOk(near.name)) {
|
|
1053
2195
|
const flags = [
|
|
@@ -1062,18 +2204,38 @@ async function change(sub, slug, thing, value, options) {
|
|
|
1062
2204
|
.map(w =>
|
|
1063
2205
|
String(w).startsWith('--') ? w : quoteCommandArgument(String(w)),
|
|
1064
2206
|
);
|
|
2207
|
+
const followed = await followChangeLine(
|
|
2208
|
+
sub,
|
|
2209
|
+
near.name,
|
|
2210
|
+
`${P} ${sub} ${near.name}${words.length ? ` ${words.join(' ')}` : ''}`,
|
|
2211
|
+
options.cwd ?? process.cwd(),
|
|
2212
|
+
);
|
|
1065
2213
|
e.suggestions = [
|
|
1066
2214
|
{
|
|
1067
|
-
name:
|
|
1068
|
-
reason: `do this instead: ${near.name} is a theme here`,
|
|
2215
|
+
name: followed.line,
|
|
2216
|
+
reason: `do this instead: ${near.name} is a theme here${followed.why ? `, but this still needs a fix: ${followed.why}` : ''}`,
|
|
1069
2217
|
},
|
|
1070
|
-
...(e.suggestions ?? []).filter(
|
|
2218
|
+
...(e.suggestions ?? []).filter(
|
|
2219
|
+
x => x !== near && x.name !== `${P} show ${near.name}`,
|
|
2220
|
+
),
|
|
1071
2221
|
];
|
|
1072
2222
|
}
|
|
1073
2223
|
throw e;
|
|
1074
2224
|
}
|
|
1075
|
-
// Every `set` the refusal suggests is checked as `set` checks it
|
|
1076
|
-
|
|
2225
|
+
// Every `set` the refusal suggests is checked as `set` checks it, and
|
|
2226
|
+
// carries the value typed (cleaned), never a stock value.
|
|
2227
|
+
throw misplacedFirst(
|
|
2228
|
+
carryTyped(
|
|
2229
|
+
vetSuggestions(e, seen.ctx, slug, seen.data),
|
|
2230
|
+
sub,
|
|
2231
|
+
slug,
|
|
2232
|
+
typedThing,
|
|
2233
|
+
typedValue,
|
|
2234
|
+
seen.data ?? savedAsWritten(options.cwd ?? process.cwd(), slug),
|
|
2235
|
+
),
|
|
2236
|
+
seen.data?.name ?? slug,
|
|
2237
|
+
seen.data,
|
|
2238
|
+
);
|
|
1077
2239
|
}
|
|
1078
2240
|
}
|
|
1079
2241
|
|
|
@@ -1107,29 +2269,26 @@ async function changeOnce(
|
|
|
1107
2269
|
when: options.when,
|
|
1108
2270
|
state: options.state,
|
|
1109
2271
|
mode: options.mode,
|
|
2272
|
+
// An undo removes the entry it names even when that entry's mode or
|
|
2273
|
+
// source means nothing.
|
|
2274
|
+
...(sub === 'undo' ? {removing: true} : {}),
|
|
1110
2275
|
});
|
|
1111
2276
|
const data = loadTheme(cwd, slug, target);
|
|
1112
2277
|
/** @type {string[]} */
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
}
|
|
1124
|
-
if (thing !== 'base' && data.like != null && !LIKE.includes(data.like)) {
|
|
1125
|
-
delete data.like;
|
|
1126
|
-
fieldNotes.push('base was not a built-in theme, so it is none again');
|
|
1127
|
-
}
|
|
1128
|
-
}
|
|
2278
|
+
// A damaged mode or base the command does not set itself is read as
|
|
2279
|
+
// meant, or goes back to its default, so the theme loads again.
|
|
2280
|
+
const fieldNotes = [
|
|
2281
|
+
...entryNotes(data),
|
|
2282
|
+
...readFields(
|
|
2283
|
+
data,
|
|
2284
|
+
cwd,
|
|
2285
|
+
thing === 'mode' || thing === 'base' ? thing : undefined,
|
|
2286
|
+
),
|
|
2287
|
+
];
|
|
1129
2288
|
const ctx = await context(cwd);
|
|
1130
2289
|
// An undo of one setting only removes it, so it never waits on the
|
|
1131
2290
|
// others being fixed.
|
|
1132
|
-
if (sub !== 'undo')
|
|
2291
|
+
if (sub !== 'undo') {
|
|
1133
2292
|
refuseStoredTokens(ctx, slug, data, {
|
|
1134
2293
|
thing,
|
|
1135
2294
|
on: options.on,
|
|
@@ -1137,6 +2296,7 @@ async function changeOnce(
|
|
|
1137
2296
|
state: options.state,
|
|
1138
2297
|
mode: options.mode,
|
|
1139
2298
|
});
|
|
2299
|
+
}
|
|
1140
2300
|
const flags = {
|
|
1141
2301
|
on: options.on,
|
|
1142
2302
|
when: options.when,
|
|
@@ -1175,8 +2335,25 @@ async function changeOnce(
|
|
|
1175
2335
|
Boolean(x.only) === Boolean(flags.only),
|
|
1176
2336
|
)
|
|
1177
2337
|
: -1;
|
|
1178
|
-
|
|
1179
|
-
|
|
2338
|
+
// An entry of this name whose mode or source means nothing is the one an
|
|
2339
|
+
// undo removes: only that entry, never a valid one beside it.
|
|
2340
|
+
const damagedIdx =
|
|
2341
|
+
sub === 'undo'
|
|
2342
|
+
? data.settings.findIndex(
|
|
2343
|
+
x =>
|
|
2344
|
+
(x.thing === typedThing || x.thing === thing) &&
|
|
2345
|
+
(x.on ?? null) === (flags.on ?? null) &&
|
|
2346
|
+
(x.when ?? null) === (flags.when ?? null) &&
|
|
2347
|
+
(x.state ?? null) === (flags.state ?? null) &&
|
|
2348
|
+
(entryDamage(x) === 'only' ||
|
|
2349
|
+
Boolean(x.only) === Boolean(flags.only)) &&
|
|
2350
|
+
(entryDamage(x) === 'source' || entryDamage(x) === 'only'
|
|
2351
|
+
? (x.mode ?? null) === (flags.mode ?? null)
|
|
2352
|
+
: entryDamage(x) === 'mode' && !flags.mode),
|
|
2353
|
+
)
|
|
2354
|
+
: -1;
|
|
2355
|
+
let rawIdx = damagedIdx;
|
|
2356
|
+
if (exactIdx >= 0 && rawIdx < 0) {
|
|
1180
2357
|
// Only an entry the editor would not save as written: one it refuses,
|
|
1181
2358
|
// or reads as another name, part or state.
|
|
1182
2359
|
const entry = data.settings[exactIdx];
|
|
@@ -1341,7 +2518,28 @@ async function changeOnce(
|
|
|
1341
2518
|
);
|
|
1342
2519
|
}
|
|
1343
2520
|
const compiledBefore = compileTheme(ctx, data, base);
|
|
2521
|
+
// The build notes the theme had before this change: only new ones are
|
|
2522
|
+
// this change's to report.
|
|
2523
|
+
const notesBefore = new Set(buildNotes(ctx));
|
|
1344
2524
|
if (sub === 'set' && (s.thing === 'base' || s.thing === 'mode')) {
|
|
2525
|
+
// A built-in base this project has not installed: install it, then the
|
|
2526
|
+
// same set, whichever letters it was typed in.
|
|
2527
|
+
if (
|
|
2528
|
+
s.thing === 'base' &&
|
|
2529
|
+
s.value !== 'none' &&
|
|
2530
|
+
!baseInstalled(cwd, s.value)
|
|
2531
|
+
)
|
|
2532
|
+
refuse(
|
|
2533
|
+
E.ERR_UNKNOWN_THEME,
|
|
2534
|
+
`The ${s.value} theme is not installed, so ${slug} cannot build on it. Install @astryxdesign/theme-${s.value}, then set the base again, or build on no theme.`,
|
|
2535
|
+
{
|
|
2536
|
+
run: [
|
|
2537
|
+
installLine(cwd, [`@astryxdesign/theme-${s.value}`]),
|
|
2538
|
+
`${P} set ${slug} base ${s.value}`,
|
|
2539
|
+
`${P} set ${slug} base none`,
|
|
2540
|
+
],
|
|
2541
|
+
},
|
|
2542
|
+
);
|
|
1345
2543
|
const before = s.thing === 'base' ? (data.like ?? 'none') : data.mode;
|
|
1346
2544
|
if (s.thing === 'base') {
|
|
1347
2545
|
if (s.value === 'none') delete data.like;
|
|
@@ -1349,7 +2547,7 @@ async function changeOnce(
|
|
|
1349
2547
|
} else
|
|
1350
2548
|
data.mode = /** @type {'both' | 'light-only' | 'dark-only'} */ (s.value);
|
|
1351
2549
|
const r = await commitTheme(ctx, slug, data, {history: true});
|
|
1352
|
-
const p = await previewAndRoute(ctx, slug, data, png);
|
|
2550
|
+
const p = await previewAndRoute(ctx, slug, data, png, 'overview', sub);
|
|
1353
2551
|
const after = await baseResolved(ctx.project, data.like).catch(() => base);
|
|
1354
2552
|
return {
|
|
1355
2553
|
type: 'themeEdit.set',
|
|
@@ -1377,6 +2575,15 @@ async function changeOnce(
|
|
|
1377
2575
|
]
|
|
1378
2576
|
: []),
|
|
1379
2577
|
...otherModeNotes(data),
|
|
2578
|
+
// Back to both modes: a mode the app's <Theme> was given for the
|
|
2579
|
+
// one-mode theme pins it still.
|
|
2580
|
+
...(s.thing === 'mode' &&
|
|
2581
|
+
data.mode === 'both' &&
|
|
2582
|
+
(before === 'light-only' || before === 'dark-only')
|
|
2583
|
+
? [
|
|
2584
|
+
`if the app's <Theme> was given mode="${before === 'light-only' ? 'light' : 'dark'}" for ${slug}, take it out: with it the app stays ${before === 'light-only' ? 'light' : 'dark'}, whatever the system asks for`,
|
|
2585
|
+
]
|
|
2586
|
+
: []),
|
|
1380
2587
|
// Core has no mode inside a theme: the app's <Theme> is given it.
|
|
1381
2588
|
...(s.thing === 'mode' &&
|
|
1382
2589
|
(data.mode === 'light-only' || data.mode === 'dark-only')
|
|
@@ -1411,13 +2618,51 @@ async function changeOnce(
|
|
|
1411
2618
|
}
|
|
1412
2619
|
const k = keyOf(s);
|
|
1413
2620
|
const prevIdx =
|
|
1414
|
-
rawIdx >= 0
|
|
2621
|
+
rawIdx >= 0
|
|
2622
|
+
? rawIdx
|
|
2623
|
+
: // A setting listed twice by hand: the last entry is the one the
|
|
2624
|
+
// build reads, so it is the one this command changes.
|
|
2625
|
+
data.settings.map(x => keyOf(x)).lastIndexOf(k);
|
|
1415
2626
|
/** @type {string | null} */
|
|
1416
2627
|
let vibrancyGone = null;
|
|
1417
2628
|
const prev = prevIdx >= 0 ? data.settings[prevIdx] : null;
|
|
1418
2629
|
if (sub === 'undo') {
|
|
1419
2630
|
if (!prev) {
|
|
1420
|
-
|
|
2631
|
+
// A padding set in the other form (a side for the shorthand, or the
|
|
2632
|
+
// shorthand for a side) on the same part is a near one too.
|
|
2633
|
+
const PAD = /^padding(?:-(?:inline|block|top|right|bottom|left))?$/;
|
|
2634
|
+
const nearOnes = data.settings.filter(
|
|
2635
|
+
x =>
|
|
2636
|
+
x.thing === s.thing ||
|
|
2637
|
+
(PAD.test(s.thing) &&
|
|
2638
|
+
PAD.test(x.thing) &&
|
|
2639
|
+
(x.on ?? null) === (s.on ?? null)),
|
|
2640
|
+
);
|
|
2641
|
+
const near = nearOnes.map(describe);
|
|
2642
|
+
// A token the theme's own source sets: that file is where it is
|
|
2643
|
+
// changed, never the settings.
|
|
2644
|
+
const ownEntry =
|
|
2645
|
+
s.thing.startsWith('--') && !s.on && !s.when && !s.state
|
|
2646
|
+
? ownTokenEntries(cwd, slug).find(
|
|
2647
|
+
x => x.token === s.thing && !x.overridden,
|
|
2648
|
+
)
|
|
2649
|
+
: undefined;
|
|
2650
|
+
if (ownEntry) {
|
|
2651
|
+
const file = ownEntry.file
|
|
2652
|
+
? path.relative(cwd, ownEntry.file)
|
|
2653
|
+
: `themes/${slug}/${slug}.theme.ts`;
|
|
2654
|
+
refuse(
|
|
2655
|
+
E.ERR_THEME_NOT_SET,
|
|
2656
|
+
`The settings do not set ${s.thing}: ${file} sets it itself${ownEntry.line ? ` (line ${ownEntry.line})` : ''}, so undo has nothing to remove; change or remove it in ${file}.`,
|
|
2657
|
+
{
|
|
2658
|
+
run: [
|
|
2659
|
+
ownEntry.line
|
|
2660
|
+
? `sed -n ${ownEntry.line}p ${quoteCommandArgument(file)}`
|
|
2661
|
+
: `grep -n -- ${quoteCommandArgument(s.thing)} ${quoteCommandArgument(file)}`,
|
|
2662
|
+
],
|
|
2663
|
+
},
|
|
2664
|
+
);
|
|
2665
|
+
}
|
|
1421
2666
|
// headings has two halves: name the one that is set.
|
|
1422
2667
|
const otherHalf =
|
|
1423
2668
|
s.thing === 'headings'
|
|
@@ -1430,11 +2675,12 @@ async function changeOnce(
|
|
|
1430
2675
|
: `The theme does not set ${describe({...s, value: '?'}).replace(' = ?', '')}.`,
|
|
1431
2676
|
{
|
|
1432
2677
|
also: near.length
|
|
1433
|
-
? [
|
|
2678
|
+
? [
|
|
2679
|
+
`settings for ${s.thing}: ${near.join('; ')}${nearOnes.some(x => x.thing === 'padding' && s.thing !== 'padding') ? ' (undoing padding removes all four sides)' : ''}`,
|
|
2680
|
+
]
|
|
1434
2681
|
: [],
|
|
1435
2682
|
run: [
|
|
1436
|
-
...
|
|
1437
|
-
.filter(x => x.thing === s.thing)
|
|
2683
|
+
...nearOnes
|
|
1438
2684
|
.slice(0, 3)
|
|
1439
2685
|
.map(x => `${P} undo ${slug} ${undoArgs(x)}`),
|
|
1440
2686
|
`${P} show ${slug}`,
|
|
@@ -1480,9 +2726,13 @@ async function changeOnce(
|
|
|
1480
2726
|
if (prev) data.settings.splice(prevIdx, 1);
|
|
1481
2727
|
data.settings.push(s);
|
|
1482
2728
|
}
|
|
1483
|
-
// A setting listed twice by hand keeps only the entry this command left
|
|
2729
|
+
// A setting listed twice by hand keeps only the entry this command left;
|
|
2730
|
+
// every other entry it replaces is named in the notes.
|
|
2731
|
+
/** @type {import('./_settings.mjs').Setting[]} */
|
|
2732
|
+
let alsoReplaced = [];
|
|
1484
2733
|
if (sub === 'set') {
|
|
1485
2734
|
const last = data.settings.map(x => keyOf(x)).lastIndexOf(k);
|
|
2735
|
+
alsoReplaced = data.settings.filter((x, i) => keyOf(x) === k && i !== last);
|
|
1486
2736
|
data.settings = data.settings.filter(
|
|
1487
2737
|
(x, i) => keyOf(x) !== k || i === last,
|
|
1488
2738
|
);
|
|
@@ -1493,7 +2743,21 @@ async function changeOnce(
|
|
|
1493
2743
|
const covered =
|
|
1494
2744
|
sub === 'set' && !s.mode && s.source !== 'dial'
|
|
1495
2745
|
? data.settings.filter(
|
|
1496
|
-
x =>
|
|
2746
|
+
x =>
|
|
2747
|
+
x !== s &&
|
|
2748
|
+
x.mode &&
|
|
2749
|
+
(keyOf({...x, mode: undefined}) === k ||
|
|
2750
|
+
// The background shorthand and its color are one property
|
|
2751
|
+
// here: a one-mode one is replaced by either for both modes.
|
|
2752
|
+
(s.source === 'property' &&
|
|
2753
|
+
x.source === 'property' &&
|
|
2754
|
+
x.on === s.on &&
|
|
2755
|
+
x.when === s.when &&
|
|
2756
|
+
x.state === s.state &&
|
|
2757
|
+
[x.thing, s.thing].every(t =>
|
|
2758
|
+
/^background(-color)?$/.test(kebab(t)),
|
|
2759
|
+
) &&
|
|
2760
|
+
!/gradient\(|url\(/i.test(String(s.value)))),
|
|
1497
2761
|
)
|
|
1498
2762
|
: [];
|
|
1499
2763
|
data.settings = data.settings.filter(x => !covered.includes(x));
|
|
@@ -1513,6 +2777,9 @@ async function changeOnce(
|
|
|
1513
2777
|
))) &&
|
|
1514
2778
|
x.when === s.when &&
|
|
1515
2779
|
x.state === s.state &&
|
|
2780
|
+
// A shorthand for one mode replaces longhands of that mode or of
|
|
2781
|
+
// both, never the other mode's.
|
|
2782
|
+
(!s.mode || !x.mode || x.mode === s.mode) &&
|
|
1516
2783
|
// A longhand the shorthand really sets (MDN's data), never a
|
|
1517
2784
|
// property that only shares its name (overflow-wrap).
|
|
1518
2785
|
(coversProperty(s.thing, x.thing) ||
|
|
@@ -1537,6 +2804,12 @@ async function changeOnce(
|
|
|
1537
2804
|
: [];
|
|
1538
2805
|
const r = await commitTheme(ctx, slug, data, {history: true});
|
|
1539
2806
|
const compiledAfter = compileTheme(ctx, data, base);
|
|
2807
|
+
// What the spacing dial said of the sizes it could not keep apart.
|
|
2808
|
+
// What the build said of settings it could not write as they are.
|
|
2809
|
+
const compileNotes = buildNotes(ctx).filter(n => !notesBefore.has(n));
|
|
2810
|
+
const sizeNotes =
|
|
2811
|
+
/** @type {{sizeNotes?: string[]}} */ (/** @type {unknown} */ (ctx))
|
|
2812
|
+
.sizeNotes ?? [];
|
|
1540
2813
|
const styled = styledChanges(compiledBefore, compiledAfter, base);
|
|
1541
2814
|
const parts = partsOf(ctx, s);
|
|
1542
2815
|
// Exact whole-theme tokens that win over what this dial writes: the dial
|
|
@@ -1562,6 +2835,29 @@ async function changeOnce(
|
|
|
1562
2835
|
!x.when &&
|
|
1563
2836
|
x.thing === `--font-family-${s.on}`,
|
|
1564
2837
|
);
|
|
2838
|
+
// A whole-theme spacing dial keeps a part's own exact control size too,
|
|
2839
|
+
// on that part.
|
|
2840
|
+
if (sub === 'set' && s.source === 'dial' && s.thing === 'spacing' && !s.on)
|
|
2841
|
+
exactWins.push(
|
|
2842
|
+
...data.settings.filter(
|
|
2843
|
+
x =>
|
|
2844
|
+
x.source === 'token' &&
|
|
2845
|
+
!!x.on &&
|
|
2846
|
+
!x.state &&
|
|
2847
|
+
/^--size-element-/.test(x.thing),
|
|
2848
|
+
),
|
|
2849
|
+
);
|
|
2850
|
+
// A spacing dial on a part keeps the exact spacing and sizes there too:
|
|
2851
|
+
// the whole theme's, and the part's own.
|
|
2852
|
+
if (sub === 'set' && s.source === 'dial' && s.thing === 'spacing' && s.on)
|
|
2853
|
+
exactWins = data.settings.filter(
|
|
2854
|
+
x =>
|
|
2855
|
+
x.source === 'token' &&
|
|
2856
|
+
!x.when &&
|
|
2857
|
+
!x.state &&
|
|
2858
|
+
/^--(size-element|spacing)-/.test(x.thing) &&
|
|
2859
|
+
(!x.on || x.on === s.on),
|
|
2860
|
+
);
|
|
1565
2861
|
// The theme's own source wins over an exact setting, as the exact
|
|
1566
2862
|
// setting does over a dial: an exact token the file also sets is named
|
|
1567
2863
|
// as the file's below, never as the one that shows after an undo.
|
|
@@ -1762,6 +3058,12 @@ async function changeOnce(
|
|
|
1762
3058
|
: null;
|
|
1763
3059
|
/** @type {string[]} */
|
|
1764
3060
|
const notes = [
|
|
3061
|
+
...fieldNotes,
|
|
3062
|
+
...(alsoReplaced.length && prev
|
|
3063
|
+
? [
|
|
3064
|
+
`${describe({...prev, value: '?'}).replace(' = ?', '')} was listed ${alsoReplaced.length === 1 ? 'twice' : `${alsoReplaced.length + 1} times`} (${[...alsoReplaced, prev].map(x => x.value).join(', ')}); each is replaced`,
|
|
3065
|
+
]
|
|
3066
|
+
: []),
|
|
1765
3067
|
...(covered.length ? [`replaces ${covered.map(describe).join(', ')}`] : []),
|
|
1766
3068
|
...(ownPartHits.length
|
|
1767
3069
|
? [
|
|
@@ -1773,7 +3075,7 @@ async function changeOnce(
|
|
|
1773
3075
|
)
|
|
1774
3076
|
.join(
|
|
1775
3077
|
', ',
|
|
1776
|
-
)}${ownPartHits.length > 3 ? ` and ${ownPartHits.length - 3} more` : ''}, and your own source wins over the settings, so this does not show there; change it in ${slug}.theme.ts${ownHitDirect ? `, or take this back with \`${P} undo ${slug} ${undoArgs(s)}\`` : ''}`,
|
|
3078
|
+
)}${ownPartHits.length > 3 ? ` and ${ownPartHits.length - 3} more` : ''}, and your own source wins over the settings, so this does not show ${/^padding(-|$)/.test(s.thing) && ownPartHits.every(h => /^padding-/.test(h.prop)) ? 'on the sides that sets; its other sides take this setting' : 'there'}; change it in ${slug}.theme.ts${ownHitDirect ? `, or take this back with \`${P} undo ${slug} ${undoArgs(s)}\`` : ''}`,
|
|
1777
3079
|
]
|
|
1778
3080
|
: []),
|
|
1779
3081
|
...(ownOverToken
|
|
@@ -1786,6 +3088,8 @@ async function changeOnce(
|
|
|
1786
3088
|
`keeps your exact ${exactWins.map(describe).join(', ')}: an exact setting wins over a dial, so ${exactWins.length > 1 ? 'those do' : 'that does'} not change; this shows after \`${P} undo ${slug} ${exactWins.map(x => undoArgs(x)).join(`\` and \`${P} undo ${slug} `)}\``,
|
|
1787
3089
|
]
|
|
1788
3090
|
: []),
|
|
3091
|
+
...(sub === 'set' && s.thing === 'spacing' ? sizeNotes : []),
|
|
3092
|
+
...(sub === 'set' ? compileNotes : []),
|
|
1789
3093
|
...(covers.length
|
|
1790
3094
|
? [
|
|
1791
3095
|
`comes after ${covers.map(describe).join(', ')}, so ${covers.length > 1 ? 'those parts show' : `${covers[0].on} shows`} this value now; set ${covers.length > 1 ? 'one' : 'it'} again to make it win`,
|
|
@@ -1831,9 +3135,18 @@ async function changeOnce(
|
|
|
1831
3135
|
// An exact property on the same part wins over a dial there.
|
|
1832
3136
|
...(exactOver
|
|
1833
3137
|
? [
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
3138
|
+
// The own source holding only some sides or corners there leaves
|
|
3139
|
+
// the dial the others once the exact property is undone.
|
|
3140
|
+
ownPartHits.length &&
|
|
3141
|
+
ownPartHits.every(h =>
|
|
3142
|
+
/(Top|Bottom|Left|Right|Start|End|Block|Inline)/.test(
|
|
3143
|
+
camel(String(h.prop)),
|
|
3144
|
+
),
|
|
3145
|
+
)
|
|
3146
|
+
? `${describe(exactOver)} is an exact property and wins over ${s.thing} there, so this shows only after \`${P} undo ${slug} ${undoArgs(exactOver)}\`, and then not on the ${[...new Set(ownPartHits.map(h => kebab(String(h.prop))))].join(', ')} ${slug}.theme.ts sets itself`
|
|
3147
|
+
: ownPartHits.length
|
|
3148
|
+
? `${describe(exactOver)} is an exact property and wins over ${s.thing} there too; undoing it does not make ${s.thing} show on ${[...new Set(ownPartHits.map(h => h.target))].join(', ')}, where ${slug}.theme.ts wins`
|
|
3149
|
+
: `${describe(exactOver)} is an exact property and wins over ${s.thing} there, so this shows only after \`${P} undo ${slug} ${undoArgs(exactOver)}\``,
|
|
1837
3150
|
]
|
|
1838
3151
|
: []),
|
|
1839
3152
|
// A whole-theme font under fonts set for each role shows only where no
|
|
@@ -1900,6 +3213,21 @@ async function changeOnce(
|
|
|
1900
3213
|
: null
|
|
1901
3214
|
: null;
|
|
1902
3215
|
if (s.note) notes.push(s.note);
|
|
3216
|
+
// A group kept alike (inputs share one height) loses that when one member
|
|
3217
|
+
// changes its height alone.
|
|
3218
|
+
const family = s.on && s.only ? familyOf(s.on) : null;
|
|
3219
|
+
if (
|
|
3220
|
+
family &&
|
|
3221
|
+
AUTO_SPREAD.includes(family) &&
|
|
3222
|
+
(s.thing === 'spacing' ||
|
|
3223
|
+
/^--size-element-/.test(s.thing) ||
|
|
3224
|
+
/^(min-|max-)?(height|block-size)$|^padding(-block(-start|-end)?|-top|-bottom)?$/.test(
|
|
3225
|
+
s.thing,
|
|
3226
|
+
))
|
|
3227
|
+
)
|
|
3228
|
+
notes.push(
|
|
3229
|
+
`${s.on} alone now differs in height from the rest of ${family}, which are kept alike; --on ${family} changes them together`,
|
|
3230
|
+
);
|
|
1903
3231
|
// A token the theme's own source sets itself wins over what this dial
|
|
1904
3232
|
// writes, as an exact setting does.
|
|
1905
3233
|
const ownWins = ownSourceTokens(cwd, slug).filter(
|
|
@@ -2018,6 +3346,12 @@ async function changeOnce(
|
|
|
2018
3346
|
// once preview.html was rendered from the theme as it is now (a retry
|
|
2019
3347
|
// after a render that failed renders it).
|
|
2020
3348
|
const f0 = themeFiles(cwd, slug);
|
|
3349
|
+
// A change that changed nothing still writes back an app copy file that
|
|
3350
|
+
// is gone or not the current build.
|
|
3351
|
+
// Its font stylesheet follows the fonts the theme loads now (a font
|
|
3352
|
+
// package installed or removed since).
|
|
3353
|
+
if (r.unchanged && appCopyBehind(cwd, slug, copyFontsCss(ctx, slug, data)))
|
|
3354
|
+
writeAppCopy(ctx, slug, data);
|
|
2021
3355
|
const p =
|
|
2022
3356
|
r.unchanged &&
|
|
2023
3357
|
!png &&
|
|
@@ -2030,8 +3364,10 @@ async function changeOnce(
|
|
|
2030
3364
|
notChecked: null,
|
|
2031
3365
|
previewStale: [],
|
|
2032
3366
|
see: seeLine(cwd, slug, changeFocus(s)),
|
|
3367
|
+
// A copy something keeps behind is said here too.
|
|
3368
|
+
...appCopyStale(cwd, slug),
|
|
2033
3369
|
}
|
|
2034
|
-
: await previewAndRoute(ctx, slug, data, png, changeFocus(s));
|
|
3370
|
+
: await previewAndRoute(ctx, slug, data, png, changeFocus(s), sub);
|
|
2035
3371
|
return {
|
|
2036
3372
|
type: sub === 'set' ? 'themeEdit.set' : 'themeEdit.undo',
|
|
2037
3373
|
data: {
|
|
@@ -2105,6 +3441,50 @@ function unsetColorNotes(data, base, slug) {
|
|
|
2105
3441
|
];
|
|
2106
3442
|
}
|
|
2107
3443
|
|
|
3444
|
+
/**
|
|
3445
|
+
* Whether a settings entry is a mode or base a hand edit put in the list:
|
|
3446
|
+
* it does nothing there (the theme's mode and base are its own fields).
|
|
3447
|
+
* @param {{thing: string}} s
|
|
3448
|
+
*/
|
|
3449
|
+
const misplaced = s => s.thing === 'mode' || s.thing === 'base';
|
|
3450
|
+
|
|
3451
|
+
/**
|
|
3452
|
+
* The note for each misplaced entry: listed here only, never as a
|
|
3453
|
+
* setting, with the undo that removes it first.
|
|
3454
|
+
* @param {string} slug
|
|
3455
|
+
* @param {import('./_settings.mjs').ThemeData} data
|
|
3456
|
+
* @returns {string[]}
|
|
3457
|
+
*/
|
|
3458
|
+
function misplacedNotes(slug, data) {
|
|
3459
|
+
return data.settings
|
|
3460
|
+
.filter(misplaced)
|
|
3461
|
+
.map(
|
|
3462
|
+
x =>
|
|
3463
|
+
`misplaced: the settings list holds ${x.thing} = ${x.value}, which does nothing there (the theme's ${x.thing} is ${x.thing === 'mode' ? data.mode : (data.like ?? 'none')}); \`${P} undo ${slug} ${x.thing}\` removes it, and \`${P} set ${slug} ${x.thing} <value>\` sets the theme's ${x.thing}`,
|
|
3464
|
+
);
|
|
3465
|
+
}
|
|
3466
|
+
|
|
3467
|
+
/**
|
|
3468
|
+
* A refusal for a theme with misplaced entries, its suggestions led by the
|
|
3469
|
+
* undo that removes each.
|
|
3470
|
+
* @param {unknown} e
|
|
3471
|
+
* @param {string} slug
|
|
3472
|
+
* @param {import('./_settings.mjs').ThemeData | undefined} data
|
|
3473
|
+
*/
|
|
3474
|
+
function misplacedFirst(e, slug, data) {
|
|
3475
|
+
if (!(e instanceof AstryxError) || !data) return e;
|
|
3476
|
+
const undos = data.settings.filter(misplaced).map(x => ({
|
|
3477
|
+
name: `${P} undo ${slug} ${x.thing}`,
|
|
3478
|
+
reason: `removes the ${x.thing} entry that does nothing in the settings list`,
|
|
3479
|
+
}));
|
|
3480
|
+
if (!undos.length) return e;
|
|
3481
|
+
e.suggestions = [
|
|
3482
|
+
...undos,
|
|
3483
|
+
...(e.suggestions ?? []).filter(x => !undos.some(u => u.name === x.name)),
|
|
3484
|
+
];
|
|
3485
|
+
return e;
|
|
3486
|
+
}
|
|
3487
|
+
|
|
2108
3488
|
/**
|
|
2109
3489
|
* Every setting of a theme, key resolved values, problems it caused, the
|
|
2110
3490
|
* sample page and the theme-building page with every component.
|
|
@@ -2126,6 +3506,7 @@ export async function themeEditShow(theme, options = {}) {
|
|
|
2126
3506
|
// build a later refusal puts back.
|
|
2127
3507
|
holdAfterBuild(ctx);
|
|
2128
3508
|
refuseStoredTokens(ctx, theme, data);
|
|
3509
|
+
await refuseOwnTokenValues(ctx, theme, data);
|
|
2129
3510
|
// Without React, show still lists the settings and builds the theme, as
|
|
2130
3511
|
// set does; only the pages, pictures and the checks that render are
|
|
2131
3512
|
// skipped, and the result says how to fix it.
|
|
@@ -2157,7 +3538,7 @@ export async function themeEditShow(theme, options = {}) {
|
|
|
2157
3538
|
// An own source that does not parse is refused before anything is
|
|
2158
3539
|
// built, written or removed (the build would fail part way).
|
|
2159
3540
|
if (!readOnly) refuseThemeParse(cwd, theme);
|
|
2160
|
-
const brokenSource = themeSourceProblem(cwd, theme);
|
|
3541
|
+
const brokenSource = await themeSourceProblem(cwd, theme);
|
|
2161
3542
|
// Every output, as `compile --check` reads them: one missing or edited by
|
|
2162
3543
|
// hand is built again too.
|
|
2163
3544
|
let stale = staleBuild(cwd, theme, data);
|
|
@@ -2287,6 +3668,16 @@ export async function themeEditShow(theme, options = {}) {
|
|
|
2287
3668
|
if (!(e instanceof Error)) throw e;
|
|
2288
3669
|
if (e instanceof AstryxError && e.code !== E.ERR_RENDER_FAILED) throw e;
|
|
2289
3670
|
putBack(kept, tokensDir);
|
|
3671
|
+
// A folder it cannot write is no render failure: the folder is named.
|
|
3672
|
+
const code = /** @type {any} */ (e).code;
|
|
3673
|
+
if (['EACCES', 'EPERM', 'EROFS'].includes(code)) {
|
|
3674
|
+
const where = /** @type {any} */ (e).path;
|
|
3675
|
+
return refuse(
|
|
3676
|
+
E.ERR_WRITE_FAILED,
|
|
3677
|
+
`${theme} cannot be shown: ${where ? `${shown(cwd, path.dirname(where))}/` : 'its theme folder'} cannot be written (${code}). Fix its permissions, then run the command again. Nothing was written.`,
|
|
3678
|
+
{run: [`${P} show ${theme}`]},
|
|
3679
|
+
);
|
|
3680
|
+
}
|
|
2290
3681
|
return refuse(
|
|
2291
3682
|
E.ERR_RENDER_FAILED,
|
|
2292
3683
|
`${theme} cannot be shown: ${renderCause(ctx.project, e.message)} ${[...kept.values()].some(Boolean) ? 'The build this show made again was put back as it was. ' : ''}Nothing was written.`,
|
|
@@ -2328,7 +3719,15 @@ export async function themeEditShow(theme, options = {}) {
|
|
|
2328
3719
|
],
|
|
2329
3720
|
modes,
|
|
2330
3721
|
)
|
|
2331
|
-
:
|
|
3722
|
+
: // Pictures asked for but not taken: said, never a quiet none.
|
|
3723
|
+
{
|
|
3724
|
+
files: [],
|
|
3725
|
+
problem: png
|
|
3726
|
+
? readOnly
|
|
3727
|
+
? 'no picture was taken: show ran read-only (the project or its install cannot be written, so it could not hold the theme lock), and the pages the pictures are taken of were not made; run show --png where the project can be written'
|
|
3728
|
+
: 'no picture was taken: React is not installed here, so the pages the pictures are taken of could not be made; install react and react-dom, then run show --png again'
|
|
3729
|
+
: null,
|
|
3730
|
+
};
|
|
2332
3731
|
// The app copy follows the build there now, also when the build was
|
|
2333
3732
|
// current and only the copy is missing (a theme made before it existed).
|
|
2334
3733
|
if (!readOnly)
|
|
@@ -2347,29 +3746,32 @@ export async function themeEditShow(theme, options = {}) {
|
|
|
2347
3746
|
const looksBase = await baseResolved(ctx.project, data.like).catch(
|
|
2348
3747
|
() => null,
|
|
2349
3748
|
);
|
|
2350
|
-
return data.settings
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
x
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
3749
|
+
return data.settings
|
|
3750
|
+
.filter(s => !misplaced(s))
|
|
3751
|
+
.map(s => {
|
|
3752
|
+
let masked = maskedSettings(data, ctx).get(s);
|
|
3753
|
+
// A look dial (buttons, surfaces) under an exact property on a
|
|
3754
|
+
// part it writes: named, as corners under border-radius is.
|
|
3755
|
+
if (!masked && looksBase && s.source === 'dial' && !s.on) {
|
|
3756
|
+
const writes = dialWrites(ctx, data, s, looksBase);
|
|
3757
|
+
const exact = writes.size
|
|
3758
|
+
? data.settings.find(
|
|
3759
|
+
x =>
|
|
3760
|
+
x.source === 'property' &&
|
|
3761
|
+
x.on &&
|
|
3762
|
+
!x.when &&
|
|
3763
|
+
!x.state &&
|
|
3764
|
+
partsOf(ctx, x).some(t => writes.has(`${t}\0${x.thing}`)),
|
|
3765
|
+
)
|
|
3766
|
+
: undefined;
|
|
3767
|
+
if (exact)
|
|
3768
|
+
masked = `${describe(exact)} is an exact property and wins over ${s.thing} on ${exact.on}`;
|
|
3769
|
+
}
|
|
3770
|
+
return {...s, parts: partsOf(ctx, s), ...(masked ? {masked} : {})};
|
|
3771
|
+
});
|
|
2371
3772
|
})(),
|
|
2372
3773
|
notes: [
|
|
3774
|
+
...misplacedNotes(theme, data),
|
|
2373
3775
|
...(noReact
|
|
2374
3776
|
? [
|
|
2375
3777
|
`react and react-dom cannot be found from this app, so the pages and pictures were not made again and the checks that render components were skipped; install them (${installLine(cwd, ['react', 'react-dom'])}), then run show again`,
|
|
@@ -2443,6 +3845,7 @@ export async function themeEditShow(theme, options = {}) {
|
|
|
2443
3845
|
const wrote = takeFirstAppCopy(cwd, theme);
|
|
2444
3846
|
return wrote ? {appCopy: {wrote}} : {};
|
|
2445
3847
|
})(),
|
|
3848
|
+
...appCopyStale(cwd, theme),
|
|
2446
3849
|
colorFiles: pal ? colorFiles(theme) : null,
|
|
2447
3850
|
},
|
|
2448
3851
|
};
|
|
@@ -2492,6 +3895,10 @@ function dialWrites(ctx, data, dial, base) {
|
|
|
2492
3895
|
* @returns {string}
|
|
2493
3896
|
*/
|
|
2494
3897
|
function nowApplies(ctx, data, removed, base) {
|
|
3898
|
+
// Vibrancy has no base theme value: the colors are made again at the
|
|
3899
|
+
// default.
|
|
3900
|
+
if (removed.source === 'dial' && removed.thing === 'vibrancy')
|
|
3901
|
+
return `the default vibrancy, ${VIBRANCY_DEFAULT}`;
|
|
2495
3902
|
// A token the theme's own source sets shows its value, whatever else
|
|
2496
3903
|
// the settings give it.
|
|
2497
3904
|
if (removed.source === 'token' && !removed.on && !removed.when) {
|
|
@@ -2726,8 +4133,28 @@ function ownPhoneNotes(cwd, slug, data) {
|
|
|
2726
4133
|
.filter(x => x.source === 'token' && !x.on && !x.when && !x.state)
|
|
2727
4134
|
.map(x => x.thing),
|
|
2728
4135
|
);
|
|
4136
|
+
// A family or size the theme's typography sets is kept on phones (the
|
|
4137
|
+
// base theme's rule for those screens keeps the theme's typography); only
|
|
4138
|
+
// one the tokens map sets is lost there.
|
|
4139
|
+
const entries = ownTokenEntries(cwd, slug);
|
|
4140
|
+
const roles = new Set(
|
|
4141
|
+
entries.filter(e => e.kind === 'typography').map(e => e.key.split('.')[0]),
|
|
4142
|
+
);
|
|
4143
|
+
const inMap = new Set(
|
|
4144
|
+
entries.filter(e => e.token && !e.overridden).map(e => e.token),
|
|
4145
|
+
);
|
|
4146
|
+
/** @param {string} k */
|
|
4147
|
+
const fromTypography = k => {
|
|
4148
|
+
const role = /^--font-family-([a-z]+)$/.exec(k)?.[1];
|
|
4149
|
+
if (role)
|
|
4150
|
+
return roles.has(role) || (role === 'heading' && roles.has('body'));
|
|
4151
|
+
return roles.has('scale') && !/^--font-family-/.test(k);
|
|
4152
|
+
};
|
|
2729
4153
|
const lost = ownSourceTokens(cwd, slug).filter(
|
|
2730
|
-
k =>
|
|
4154
|
+
k =>
|
|
4155
|
+
PHONE_TYPE.test(k) &&
|
|
4156
|
+
!exact.has(k) &&
|
|
4157
|
+
(!fromTypography(k) || inMap.has(k)),
|
|
2731
4158
|
);
|
|
2732
4159
|
if (!lost.length) return [];
|
|
2733
4160
|
const families = lost.filter(k => /^--font-family-/.test(k));
|
|
@@ -3038,10 +4465,99 @@ function colorFiles(slug) {
|
|
|
3038
4465
|
* @returns {Promise<import('./theme-edit.type.mjs').ThemeEditUndoResponse | import('./theme-edit.type.mjs').ThemeEditChangeResponse>}
|
|
3039
4466
|
*/
|
|
3040
4467
|
export async function themeEditUndo(theme, options = {}) {
|
|
4468
|
+
try {
|
|
4469
|
+
return await undoTheme(theme, options).catch(async e => {
|
|
4470
|
+
throw await swappedOrder(
|
|
4471
|
+
e,
|
|
4472
|
+
'undo',
|
|
4473
|
+
[theme, options.thing, options.value],
|
|
4474
|
+
options,
|
|
4475
|
+
);
|
|
4476
|
+
});
|
|
4477
|
+
} catch (e) {
|
|
4478
|
+
// A theme name typed in another form (tTheme, T, brand_dark, themes/t):
|
|
4479
|
+
// the same undo with the theme's name comes first, never a look at the
|
|
4480
|
+
// theme that drops the undo.
|
|
4481
|
+
if (
|
|
4482
|
+
e instanceof AstryxError &&
|
|
4483
|
+
(e.code === E.ERR_INVALID_ARGUMENT || e.code === E.ERR_UNKNOWN_THEME)
|
|
4484
|
+
) {
|
|
4485
|
+
const cwd = options.cwd ?? process.cwd();
|
|
4486
|
+
const showOf = (/** @type {{name: string}} */ x) => {
|
|
4487
|
+
const rest = x.name.startsWith(`${P} show `)
|
|
4488
|
+
? x.name.slice(`${P} show `.length)
|
|
4489
|
+
: null;
|
|
4490
|
+
return rest && !/\s/.test(rest) ? rest : null;
|
|
4491
|
+
};
|
|
4492
|
+
// A list of themes (t,u) stays a look at each: one theme at a time.
|
|
4493
|
+
const shows = (e.suggestions ?? []).filter(x => showOf(x) != null);
|
|
4494
|
+
const near = (shows.length === 1 ? shows : []).find(x => {
|
|
4495
|
+
const n = showOf(x);
|
|
4496
|
+
return (
|
|
4497
|
+
n != null &&
|
|
4498
|
+
n !== theme &&
|
|
4499
|
+
slugOk(n) &&
|
|
4500
|
+
fs.existsSync(themeFiles(cwd, n).settings)
|
|
4501
|
+
);
|
|
4502
|
+
});
|
|
4503
|
+
const name = near ? showOf(near) : null;
|
|
4504
|
+
if (near && name) {
|
|
4505
|
+
const words = [
|
|
4506
|
+
...(options.thing ? [options.thing] : []),
|
|
4507
|
+
...(options.value ? [options.value] : []),
|
|
4508
|
+
...(options.on ? ['--on', options.on] : []),
|
|
4509
|
+
...(options.when ? ['--when', options.when] : []),
|
|
4510
|
+
...(options.state ? ['--state', options.state] : []),
|
|
4511
|
+
...(options.mode ? ['--mode', options.mode] : []),
|
|
4512
|
+
].map(w =>
|
|
4513
|
+
String(w).startsWith('--') ? w : quoteCommandArgument(String(w)),
|
|
4514
|
+
);
|
|
4515
|
+
const followed = await followChangeLine(
|
|
4516
|
+
'undo',
|
|
4517
|
+
name,
|
|
4518
|
+
`${P} undo ${name}${words.length ? ` ${words.join(' ')}` : ''}`,
|
|
4519
|
+
cwd,
|
|
4520
|
+
);
|
|
4521
|
+
e.suggestions = [
|
|
4522
|
+
{
|
|
4523
|
+
name: followed.line,
|
|
4524
|
+
reason: `do this instead: ${name} is a theme here${followed.why ? `, but this still needs a fix: ${followed.why}` : ''}`,
|
|
4525
|
+
},
|
|
4526
|
+
...(e.suggestions ?? []).filter(x => x !== near),
|
|
4527
|
+
];
|
|
4528
|
+
}
|
|
4529
|
+
}
|
|
4530
|
+
throw e;
|
|
4531
|
+
}
|
|
4532
|
+
}
|
|
4533
|
+
|
|
4534
|
+
/**
|
|
4535
|
+
* {@link themeEditUndo}'s work.
|
|
4536
|
+
* @param {string} theme
|
|
4537
|
+
* @param {import('./theme-edit.type.mjs').ThemeEditUndoOptions} options
|
|
4538
|
+
* @returns {Promise<import('./theme-edit.type.mjs').ThemeEditUndoResponse | import('./theme-edit.type.mjs').ThemeEditChangeResponse>}
|
|
4539
|
+
*/
|
|
4540
|
+
async function undoTheme(theme, options) {
|
|
3041
4541
|
const {cwd = process.cwd(), png = false, thing} = options;
|
|
3042
4542
|
// base and mode are not settings in the list: undoing one goes back to
|
|
3043
4543
|
// what the theme was made with (the oldest step the history keeps).
|
|
3044
|
-
|
|
4544
|
+
// A `base` or `mode` entry a hand edit put in the settings list is a
|
|
4545
|
+
// setting like any other there: undo removes it.
|
|
4546
|
+
const listed =
|
|
4547
|
+
(thing === 'base' || thing === 'mode') &&
|
|
4548
|
+
slugOk(theme) &&
|
|
4549
|
+
(() => {
|
|
4550
|
+
try {
|
|
4551
|
+
return JSON.parse(
|
|
4552
|
+
fs
|
|
4553
|
+
.readFileSync(themeFiles(cwd, theme).settings, 'utf8')
|
|
4554
|
+
.replace(/^\uFEFF/, ''),
|
|
4555
|
+
).settings.some((/** @type {any} */ x) => x?.thing === thing);
|
|
4556
|
+
} catch {
|
|
4557
|
+
return false;
|
|
4558
|
+
}
|
|
4559
|
+
})();
|
|
4560
|
+
if ((thing === 'base' || thing === 'mode') && !listed) {
|
|
3045
4561
|
requireProject(cwd);
|
|
3046
4562
|
const now = loadTheme(cwd, theme, thing);
|
|
3047
4563
|
const historyFile = themeFiles(cwd, theme).history;
|
|
@@ -3128,10 +4644,18 @@ export async function themeEditUndo(theme, options = {}) {
|
|
|
3128
4644
|
// A link in the theme is refused as set refuses it, never read as an
|
|
3129
4645
|
// empty history.
|
|
3130
4646
|
if (slugOk(theme)) refuseLinks(cwd, theme);
|
|
4647
|
+
/** The command that works when the settings cannot be read. @type {string[] | null} */
|
|
4648
|
+
let repair = null;
|
|
3131
4649
|
try {
|
|
3132
4650
|
current = loadTheme(cwd, theme);
|
|
3133
4651
|
} catch (e) {
|
|
3134
4652
|
if (!(e instanceof AstryxError && e.code === E.ERR_THEME_INVALID)) throw e;
|
|
4653
|
+
// What the refusal itself names (make the theme again, keeping the
|
|
4654
|
+
// damaged file), never `show`, which fails the same way.
|
|
4655
|
+
repair = (e.suggestions ?? [])
|
|
4656
|
+
.map(x => x.name)
|
|
4657
|
+
.filter(n => !/ show /.test(` ${n} `) && !/ undo /.test(` ${n} `));
|
|
4658
|
+
if (!repair.length) repair = [`${P} new ${theme}`];
|
|
3135
4659
|
}
|
|
3136
4660
|
const f = themeFiles(cwd, theme);
|
|
3137
4661
|
const {steps: history, dropped} = readHistory(f.history);
|
|
@@ -3141,35 +4665,26 @@ export async function themeEditUndo(theme, options = {}) {
|
|
|
3141
4665
|
`${theme}.history.json is damaged, so there is no step to go back to.`,
|
|
3142
4666
|
{
|
|
3143
4667
|
fix: `move ${shown(cwd, f.history)} out of the theme folder (it is kept as it is): the next change starts a new history, and your settings stay as they are`,
|
|
3144
|
-
run: [`${P} show ${theme}`],
|
|
4668
|
+
run: repair ?? [`${P} show ${theme}`],
|
|
3145
4669
|
},
|
|
3146
4670
|
);
|
|
3147
4671
|
if (!history.length)
|
|
3148
4672
|
refuse(
|
|
3149
4673
|
E.ERR_THEME_NOTHING_TO_UNDO,
|
|
3150
|
-
`Nothing to undo: ${theme} has no earlier change.`,
|
|
3151
|
-
{run: [`${P} show ${theme}`]},
|
|
4674
|
+
`Nothing to undo: ${theme} has no earlier change${repair ? `, and ${theme}.settings.json cannot be read` : ''}.`,
|
|
4675
|
+
{run: repair ?? [`${P} show ${theme}`]},
|
|
3152
4676
|
);
|
|
3153
4677
|
// A top step equal to the settings now (left by an undo stopped between
|
|
3154
4678
|
// its two writes) changes nothing: skip it.
|
|
3155
4679
|
const nowText = fs.readFileSync(f.settings, 'utf8');
|
|
3156
4680
|
const same = (/** @type {string} */ a, /** @type {string} */ b) => {
|
|
3157
|
-
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
JSON.stringify({
|
|
3165
|
-
...JSON.parse(b.replace(/^\uFEFF/, '')),
|
|
3166
|
-
lifted: 0,
|
|
3167
|
-
built: 0,
|
|
3168
|
-
})
|
|
3169
|
-
);
|
|
3170
|
-
} catch {
|
|
3171
|
-
return false;
|
|
3172
|
-
}
|
|
4681
|
+
const [x, y] = [settingsJson(a), settingsJson(b)];
|
|
4682
|
+
return (
|
|
4683
|
+
x !== undefined &&
|
|
4684
|
+
y !== undefined &&
|
|
4685
|
+
JSON.stringify({...x, lifted: 0, built: 0}) ===
|
|
4686
|
+
JSON.stringify({...y, lifted: 0, built: 0})
|
|
4687
|
+
);
|
|
3173
4688
|
};
|
|
3174
4689
|
while (history.length && same(history[history.length - 1], nowText))
|
|
3175
4690
|
history.pop();
|
|
@@ -3182,8 +4697,10 @@ export async function themeEditUndo(theme, options = {}) {
|
|
|
3182
4697
|
const ctx = await context(cwd);
|
|
3183
4698
|
const prevText = /** @type {string} */ (history.pop());
|
|
3184
4699
|
let prev = /** @type {import('./_settings.mjs').ThemeData} */ (
|
|
3185
|
-
|
|
4700
|
+
settingsJson(prevText)
|
|
3186
4701
|
);
|
|
4702
|
+
// A step is read as a change reads the settings file.
|
|
4703
|
+
readAsMeant(prev, cwd);
|
|
3187
4704
|
// A step always restores into this theme, whatever name it holds.
|
|
3188
4705
|
prev.name = theme;
|
|
3189
4706
|
// What the step's build showed is restored with it, not saved as a
|
|
@@ -3278,8 +4795,10 @@ export async function themeEditUndo(theme, options = {}) {
|
|
|
3278
4795
|
undone.push(
|
|
3279
4796
|
`base ${current.like ?? 'none'} is back to ${prev.like ?? 'none'}`,
|
|
3280
4797
|
);
|
|
3281
|
-
if (current && current.mode !== prev.mode)
|
|
4798
|
+
if (current && current.mode !== prev.mode) {
|
|
3282
4799
|
undone.push(`mode ${current.mode} is back to ${prev.mode}`);
|
|
4800
|
+
undone.push(...modeWiringNotes(theme, current.mode, prev.mode));
|
|
4801
|
+
}
|
|
3283
4802
|
// The page most about what the step reverted: Colors for a color,
|
|
3284
4803
|
// Components for a part setting, else Overview.
|
|
3285
4804
|
const touched = [
|
|
@@ -3291,7 +4810,7 @@ export async function themeEditUndo(theme, options = {}) {
|
|
|
3291
4810
|
: touched.includes('components')
|
|
3292
4811
|
? 'components'
|
|
3293
4812
|
: 'overview';
|
|
3294
|
-
const p = await previewAndRoute(ctx, theme, prev, png, focus);
|
|
4813
|
+
const p = await previewAndRoute(ctx, theme, prev, png, focus, 'undo');
|
|
3295
4814
|
return {
|
|
3296
4815
|
type: 'themeEdit.undo',
|
|
3297
4816
|
data: {
|
|
@@ -3320,3 +4839,14 @@ export async function editorStale(cwd, slug) {
|
|
|
3320
4839
|
const data = loadTheme(cwd, slug);
|
|
3321
4840
|
return staleBuild(cwd, slug, data) || null;
|
|
3322
4841
|
}
|
|
4842
|
+
|
|
4843
|
+
/**
|
|
4844
|
+
* The notes the last build of the theme left (settings it could not write
|
|
4845
|
+
* as they are).
|
|
4846
|
+
* @param {unknown} ctx
|
|
4847
|
+
* @returns {string[]}
|
|
4848
|
+
*/
|
|
4849
|
+
function buildNotes(ctx) {
|
|
4850
|
+
const notes = /** @type {{compileNotes?: unknown}} */ (ctx)?.compileNotes;
|
|
4851
|
+
return Array.isArray(notes) ? notes.map(String) : [];
|
|
4852
|
+
}
|