@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
|
@@ -20,7 +20,14 @@ import {
|
|
|
20
20
|
readHistory,
|
|
21
21
|
themeFiles,
|
|
22
22
|
} from './_settings.mjs';
|
|
23
|
-
import {LIKE, P} from './_tables.mjs';
|
|
23
|
+
import {FAMILIES, GROUPS, LIKE, P} from './_tables.mjs';
|
|
24
|
+
import {
|
|
25
|
+
COLOR_IN_VALUE,
|
|
26
|
+
alphaOf,
|
|
27
|
+
colorsIn,
|
|
28
|
+
parseColor,
|
|
29
|
+
splitTop,
|
|
30
|
+
} from './_color.mjs';
|
|
24
31
|
import {quoteCommandArgument} from '../../foundation/env/package-manager.mjs';
|
|
25
32
|
|
|
26
33
|
/** The theme name commands use when the app has no theme yet. */
|
|
@@ -54,6 +61,7 @@ export const EXAMPLE_THEME = 'my-theme';
|
|
|
54
61
|
* @property {{light: Record<string, string>, dark: Record<string, string>}} base
|
|
55
62
|
* @property {{light: Record<string, string>, dark: Record<string, string>}} [own] - The theme's own values: the base's with its settings applied.
|
|
56
63
|
* @property {(steps: Step[]) => {ok: true} | {ok: false, why: string}} check
|
|
64
|
+
* @property {(steps: Step[], intent: MeasureIntent) => string | null} measure the measured check: why the built result does not do what the question asks, or null
|
|
57
65
|
*/
|
|
58
66
|
|
|
59
67
|
/**
|
|
@@ -120,6 +128,9 @@ export async function howTheme(ctx, cwd, name) {
|
|
|
120
128
|
const compiled = (/** @type {import('./_settings.mjs').ThemeData} */ d) =>
|
|
121
129
|
JSON.stringify([d.mode, compileTheme(ctx, d, base)]);
|
|
122
130
|
const before = compiled(theme);
|
|
131
|
+
/** @type {any} */
|
|
132
|
+
let beforeCache = null;
|
|
133
|
+
const beforeCompiled = () => (beforeCache ??= compileTheme(ctx, theme, base));
|
|
123
134
|
// Whether a body font setting also moves the heading font: Core gives
|
|
124
135
|
// headings the body family when a theme names no heading family, so it is
|
|
125
136
|
// read from Core, and stays right when that changes.
|
|
@@ -184,6 +195,35 @@ export async function howTheme(ctx, cwd, name) {
|
|
|
184
195
|
? readHistory(themeFiles(cwd, slug).history).steps.length
|
|
185
196
|
: 0,
|
|
186
197
|
bodyFontReachesHeadings,
|
|
198
|
+
/**
|
|
199
|
+
* The measured check: build the theme with the steps in memory (the
|
|
200
|
+
* same compile `set` builds from; nothing is written), resolve every
|
|
201
|
+
* value the touched parts show at rest and in the named state or
|
|
202
|
+
* variant, in light and dark, before and after, and hold them to what
|
|
203
|
+
* the question asks. Returns why it does not fit, or null.
|
|
204
|
+
* @param {Step[]} steps
|
|
205
|
+
* @param {MeasureIntent} intent
|
|
206
|
+
* @returns {string | null}
|
|
207
|
+
*/
|
|
208
|
+
measure(steps, intent) {
|
|
209
|
+
const d = JSON.parse(JSON.stringify(theme));
|
|
210
|
+
const checkCtx = /** @type {any} */ ({...ctx, base});
|
|
211
|
+
try {
|
|
212
|
+
for (const st of steps) apply(checkCtx, slug, d, st);
|
|
213
|
+
} catch {
|
|
214
|
+
return null; // check() says why
|
|
215
|
+
}
|
|
216
|
+
const was = beforeCompiled();
|
|
217
|
+
const now = compileTheme(ctx, d, base);
|
|
218
|
+
// A one-mode theme shows only that mode: only it is measured.
|
|
219
|
+
const visible =
|
|
220
|
+
d.mode === 'light-only'
|
|
221
|
+
? 'light'
|
|
222
|
+
: d.mode === 'dark-only'
|
|
223
|
+
? 'dark'
|
|
224
|
+
: null;
|
|
225
|
+
return measureFit(ctx, base, was, now, intent, steps, visible);
|
|
226
|
+
},
|
|
187
227
|
check(steps) {
|
|
188
228
|
/** @type {import('./_settings.mjs').ThemeData} */
|
|
189
229
|
const d = JSON.parse(JSON.stringify(theme));
|
|
@@ -209,6 +249,598 @@ export async function howTheme(ctx, cwd, name) {
|
|
|
209
249
|
};
|
|
210
250
|
}
|
|
211
251
|
|
|
252
|
+
/**
|
|
253
|
+
* What the measured check holds a command to.
|
|
254
|
+
* @typedef {object} MeasureIntent
|
|
255
|
+
* @property {string[]} families the kinds of change asked for (color, radius, space, border, weight, opacity, shadow, fontsize); empty: any
|
|
256
|
+
* @property {'more' | 'less' | null} dir the way a size moves
|
|
257
|
+
* @property {boolean | null} lighter the way a color moves
|
|
258
|
+
* @property {'more' | 'less' | null} opacityDir the way an opacity moves
|
|
259
|
+
* @property {boolean} zero a removal: the changed values reach none or 0
|
|
260
|
+
* @property {string[]} subjects the parts the question changes
|
|
261
|
+
* @property {string[]} keep the parts it excepts, compares against or forbids changing
|
|
262
|
+
* @property {string[]} typed values the question gives (taken as given)
|
|
263
|
+
* @property {'light' | 'dark' | null} [mode] the mode the question names
|
|
264
|
+
* @property {boolean} [bound] the question gives a bound ("smaller than 24px"): a space is checked against it too
|
|
265
|
+
* @property {boolean} [contrast] the words ask about contrast ("too light to read"): text in dark mode moves the other way
|
|
266
|
+
* @property {string[]} [than] parts the question compares against ("darker than the page"): a color moves past theirs
|
|
267
|
+
* @property {boolean} [literal] a mode is named with lighter or darker: borders and the shared text color move as written
|
|
268
|
+
* @property {'more' | 'less' | null} [shadowDir] the way a shadow's strength moves ("darker shadows": more)
|
|
269
|
+
*/
|
|
270
|
+
|
|
271
|
+
/** A camelCase property as CSS writes it. @param {string} k */
|
|
272
|
+
const kebab = k => k.replace(/[A-Z]/g, m => `-${m.toLowerCase()}`);
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Every value of a compiled part, by `when|state|prop`.
|
|
276
|
+
* @param {any} comp the part's compiled styles
|
|
277
|
+
* @returns {Map<string, string>}
|
|
278
|
+
*/
|
|
279
|
+
function partValues(comp) {
|
|
280
|
+
/** @type {Map<string, string>} */
|
|
281
|
+
const out = new Map();
|
|
282
|
+
for (const [when, rules] of Object.entries(comp ?? {}))
|
|
283
|
+
for (const [k, v] of Object.entries(/** @type {any} */ (rules) ?? {}))
|
|
284
|
+
if (v && typeof v === 'object')
|
|
285
|
+
for (const [k2, v2] of Object.entries(v))
|
|
286
|
+
out.set(`${when}|${k}|${kebab(k2)}`, String(v2));
|
|
287
|
+
else out.set(`${when}||${kebab(k)}`, String(v));
|
|
288
|
+
// A plain color written as `background` paints the background color.
|
|
289
|
+
for (const [k, v] of [...out])
|
|
290
|
+
if (/\|background$/.test(k) && !/gradient|url\(/.test(v)) {
|
|
291
|
+
const bc = k.replace(/background$/, 'background-color');
|
|
292
|
+
if (!out.has(bc)) out.set(bc, v);
|
|
293
|
+
}
|
|
294
|
+
return out;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* A value with every var() written out from a mode's tokens, and
|
|
299
|
+
* light-dark() taken for that mode.
|
|
300
|
+
* @param {string} v
|
|
301
|
+
* @param {Record<string, string>} map
|
|
302
|
+
* @param {'light' | 'dark'} mode
|
|
303
|
+
*/
|
|
304
|
+
function resolveIn(v, map, mode) {
|
|
305
|
+
let out = String(v ?? '');
|
|
306
|
+
for (let i = 0; i < 8; i++) {
|
|
307
|
+
const next = out
|
|
308
|
+
.replace(/var\(\s*(--[a-z0-9-]+)\s*(?:,\s*([^()]*))?\)/gi, (_, t, fb) =>
|
|
309
|
+
String(map[t] ?? fb ?? ''),
|
|
310
|
+
)
|
|
311
|
+
.replace(
|
|
312
|
+
/light-dark\(\s*([^,()]+(?:\([^()]*\))?)\s*,\s*([^()]+(?:\([^()]*\))?)\s*\)/gi,
|
|
313
|
+
(_, a, b) => (mode === 'light' ? a : b),
|
|
314
|
+
);
|
|
315
|
+
if (next === out) break;
|
|
316
|
+
out = next;
|
|
317
|
+
}
|
|
318
|
+
return out.trim().toLowerCase();
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/** The family of a CSS property or token, as the step check names them. @param {string} prop */
|
|
322
|
+
function familyOf(prop) {
|
|
323
|
+
if (/radius/.test(prop)) return 'radius';
|
|
324
|
+
if (/^--shadow-|^box-shadow$/.test(prop)) return 'shadow';
|
|
325
|
+
if (/^opacity$/.test(prop)) return 'opacity';
|
|
326
|
+
if (/weight/.test(prop)) return 'weight';
|
|
327
|
+
if (/^(font-size|--font-size-[a-z0-9]+|--text-[a-z0-9-]+-size)$/.test(prop))
|
|
328
|
+
return 'fontsize';
|
|
329
|
+
if (
|
|
330
|
+
/^(border(-[a-z]+)?-width|border(-(top|bottom|left|right|block|inline))?$|--border-width|--focus-outline-width|outline-width)$/.test(
|
|
331
|
+
prop,
|
|
332
|
+
)
|
|
333
|
+
)
|
|
334
|
+
return 'border';
|
|
335
|
+
if (/colou?r|^background(-image)?$|^fill$|^stroke$|^filter$/.test(prop))
|
|
336
|
+
return 'color';
|
|
337
|
+
if (
|
|
338
|
+
/^(padding|gap|margin|min-height|height|width|max-width|min-width|--spacing-|--size-)/.test(
|
|
339
|
+
prop,
|
|
340
|
+
)
|
|
341
|
+
)
|
|
342
|
+
return 'space';
|
|
343
|
+
return null;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/** A length as px (rem/em at 16), or a plain number, or null. @param {string} v */
|
|
347
|
+
function measureNumber(v) {
|
|
348
|
+
const m = /^(-?\d*\.?\d+)(px|rem|em)?$/.exec(
|
|
349
|
+
String(v).trim().split(/\s+/)[0],
|
|
350
|
+
);
|
|
351
|
+
return m ? Number(m[1]) * (m[2] === 'rem' || m[2] === 'em' ? 16 : 1) : null;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Whether a color steps for contrast in dark mode (a border; text when the
|
|
356
|
+
* words ask about contrast): there "darker" asks for more contrast, so it
|
|
357
|
+
* moves lighter, and "lighter" darker; a fill moves the same way in both
|
|
358
|
+
* modes.
|
|
359
|
+
* @param {string} name a token or a property
|
|
360
|
+
* @param {boolean} [contrast] the words ask about contrast
|
|
361
|
+
* @param {boolean} [literal] a mode is named with lighter or darker
|
|
362
|
+
*/
|
|
363
|
+
const isForeground = (name, contrast = false, literal = false) =>
|
|
364
|
+
!/background|surface|fill|accent|overlay/.test(name) &&
|
|
365
|
+
// Borders and the shared text tokens step by contrast with the page (how
|
|
366
|
+
// answers "lighter text" and "darker borders" that way), unless a mode is
|
|
367
|
+
// named; a part's own color steps as written.
|
|
368
|
+
((!literal && /border|outline/.test(name)) ||
|
|
369
|
+
(!literal && /^--color-text-/.test(name)) ||
|
|
370
|
+
(contrast && /text|^color$|on-/.test(name)));
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* How strong a shadow reads: the sum of its colors' alphas; 0 for none.
|
|
374
|
+
* @param {string} v
|
|
375
|
+
*/
|
|
376
|
+
function shadowStrength(v) {
|
|
377
|
+
if (!v || /^none$/.test(v.trim())) return 0;
|
|
378
|
+
// Each layer's color, read by the one color reader (hex with alpha,
|
|
379
|
+
// rgba(), hsla(), `/ alpha`). A layer has lengths: a bare color is no
|
|
380
|
+
// shadow.
|
|
381
|
+
return splitTop(v, ',')
|
|
382
|
+
.filter(layer => /(?:^|\s)-?\d*\.?\d+(?:px|rem|em)?(?=\s|$)/.test(layer))
|
|
383
|
+
.reduce(
|
|
384
|
+
(sum, layer) => sum + colorsIn(layer).reduce((n, c) => n + alphaOf(c), 0),
|
|
385
|
+
0,
|
|
386
|
+
);
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* A shadow as it renders: each color written in one form (hex with its
|
|
391
|
+
* alpha), so two spellings of the same shadow compare equal.
|
|
392
|
+
* @param {string} v
|
|
393
|
+
*/
|
|
394
|
+
function shadowLook(v) {
|
|
395
|
+
return String(v)
|
|
396
|
+
.replace(COLOR_IN_VALUE, c => {
|
|
397
|
+
const rgb = parseColor(c);
|
|
398
|
+
if (!rgb) return c;
|
|
399
|
+
const a = Math.round(alphaOf(c) * 255);
|
|
400
|
+
return `rgb(${rgb.slice(0, 3).join(' ')} / ${a})`;
|
|
401
|
+
})
|
|
402
|
+
.replace(/\s+/g, ' ')
|
|
403
|
+
.trim();
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* A color as it paints over the page in a mode: its alpha blended with the
|
|
408
|
+
* page color, so a see-through fill compares by what shows.
|
|
409
|
+
* @param {string} v
|
|
410
|
+
* @param {Record<string, string>} toks the mode's tokens
|
|
411
|
+
* @param {'light' | 'dark'} mode
|
|
412
|
+
* @returns {number[] | null}
|
|
413
|
+
*/
|
|
414
|
+
function painted(v, toks, mode) {
|
|
415
|
+
const rgb = parseColor(v);
|
|
416
|
+
if (!rgb) return null;
|
|
417
|
+
const a = alphaOf(v);
|
|
418
|
+
const page =
|
|
419
|
+
parseColor(resolveIn('var(--color-background-body)', toks, mode)) ??
|
|
420
|
+
(mode === 'dark' ? [0, 0, 0] : [255, 255, 255]);
|
|
421
|
+
return rgb.slice(0, 3).map((x, i) => x * a + page[i] * (1 - a));
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
/** @param {number[]} c */
|
|
425
|
+
const luminance = c => c[0] * 0.299 + c[1] * 0.587 + c[2] * 0.114;
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* Hold the after build to the intent; why it does not fit, or null.
|
|
429
|
+
* @param {any} ctx
|
|
430
|
+
* @param {any} base
|
|
431
|
+
* @param {any} was
|
|
432
|
+
* @param {any} now
|
|
433
|
+
* @param {MeasureIntent} intent
|
|
434
|
+
* @param {Step[]} steps
|
|
435
|
+
* @param {'light' | 'dark' | null} [visible] the one mode a one-mode theme shows
|
|
436
|
+
*/
|
|
437
|
+
function measureFit(ctx, base, was, now, intent, steps, visible = null) {
|
|
438
|
+
const tw = ownTokens(was, base);
|
|
439
|
+
const tn = ownTokens(now, base);
|
|
440
|
+
const C = ctx.C;
|
|
441
|
+
/** @param {string} part */
|
|
442
|
+
const members = part => FAMILIES[part] ?? [part];
|
|
443
|
+
// A kept part, or one state or variant of it (`part@when|state|`).
|
|
444
|
+
/** @type {Array<{part: string, prefix: string}>} */
|
|
445
|
+
const keeps = intent.keep.flatMap(k => {
|
|
446
|
+
const [part, prefix = ''] = k.split('@');
|
|
447
|
+
return members(part).map(m => ({part: m, prefix}));
|
|
448
|
+
});
|
|
449
|
+
const subjects = new Set(intent.subjects.flatMap(members));
|
|
450
|
+
/**
|
|
451
|
+
* The values a part shows, by `when|state|prop` and mode: its own
|
|
452
|
+
* compiled rules, then each token it reads for a property.
|
|
453
|
+
* @param {any} compiled
|
|
454
|
+
* @param {{light: Record<string, string>, dark: Record<string, string>}} toks
|
|
455
|
+
* @param {string} part
|
|
456
|
+
*/
|
|
457
|
+
const shown = (compiled, toks, part) => {
|
|
458
|
+
// Each rule of the part: the base theme's own declarations with the
|
|
459
|
+
// theme's on top, condition by condition (a theme rule that sets one
|
|
460
|
+
// property keeps the base rule's others).
|
|
461
|
+
/** @type {Record<string, Record<string, any>>} */
|
|
462
|
+
const rules = {};
|
|
463
|
+
for (const src of [
|
|
464
|
+
base.components?.[part] ?? {},
|
|
465
|
+
compiled.components?.[part] ?? {},
|
|
466
|
+
])
|
|
467
|
+
for (const [when, rule] of Object.entries(src))
|
|
468
|
+
rules[when] =
|
|
469
|
+
rule && typeof rule === 'object' && !Array.isArray(rule)
|
|
470
|
+
? {...(rules[when] ?? {}), ...rule}
|
|
471
|
+
: rule;
|
|
472
|
+
const own = partValues(rules);
|
|
473
|
+
// A token the part's own rule sets (a part-scoped dial's --spacing-4)
|
|
474
|
+
// is the value inside the part.
|
|
475
|
+
// A token a variant's rule sets holds in that variant, over the part's.
|
|
476
|
+
const scoped = (
|
|
477
|
+
/** @type {'light' | 'dark'} */ m,
|
|
478
|
+
/** @type {string} */ when,
|
|
479
|
+
) => {
|
|
480
|
+
/** @type {Record<string, string>} */
|
|
481
|
+
const t = {...toks[m]};
|
|
482
|
+
for (const w of when === 'base' ? ['base'] : ['base', when])
|
|
483
|
+
for (const [k, v] of Object.entries(rules[w] ?? {}))
|
|
484
|
+
if (k.startsWith('--') && typeof v === 'string') t[k] = v;
|
|
485
|
+
return t;
|
|
486
|
+
};
|
|
487
|
+
/** @type {Map<string, string>} */
|
|
488
|
+
const raw = new Map(own);
|
|
489
|
+
// The part at rest in its main variant is its `base` too (a set with no
|
|
490
|
+
// --when writes base).
|
|
491
|
+
const mainWhen = (/** @type {string[]} */ ws) =>
|
|
492
|
+
ws.some(
|
|
493
|
+
w =>
|
|
494
|
+
w === '' ||
|
|
495
|
+
/^variant=(default|primary|accent|neutral)$|^size=md$/.test(w),
|
|
496
|
+
);
|
|
497
|
+
for (const g of Object.keys(GROUPS))
|
|
498
|
+
for (const r of C.partReads(part, g) ?? [])
|
|
499
|
+
if (mainWhen(r.when?.length ? r.when : ['']))
|
|
500
|
+
for (const prop of r.props ?? []) {
|
|
501
|
+
const key = `base||${prop}`;
|
|
502
|
+
if (!raw.has(key)) raw.set(key, `var(${r.token})`);
|
|
503
|
+
}
|
|
504
|
+
for (const g of Object.keys(GROUPS))
|
|
505
|
+
for (const r of C.partReads(part, g) ?? [])
|
|
506
|
+
for (const prop of r.props ?? [])
|
|
507
|
+
for (const w of r.when?.length ? r.when : [''])
|
|
508
|
+
if (!/::|:active|:hover|:focus|:checked|:disabled/.test(w)) {
|
|
509
|
+
const key = `${w ? w.replace('=', ':') : 'base'}||${prop}`;
|
|
510
|
+
// A variant with no rule of its own takes the part's own base
|
|
511
|
+
// rule over the token it reads.
|
|
512
|
+
if (!raw.has(key))
|
|
513
|
+
raw.set(key, own.get(`base||${prop}`) ?? `var(${r.token})`);
|
|
514
|
+
}
|
|
515
|
+
/** @type {Map<string, {light: string, dark: string, raw: string}>} */
|
|
516
|
+
const out = new Map();
|
|
517
|
+
for (const [k, v] of raw)
|
|
518
|
+
out.set(k, {
|
|
519
|
+
light: resolveIn(v, scoped('light', k.split('|')[0]), 'light'),
|
|
520
|
+
dark: resolveIn(v, scoped('dark', k.split('|')[0]), 'dark'),
|
|
521
|
+
raw: v,
|
|
522
|
+
});
|
|
523
|
+
return out;
|
|
524
|
+
};
|
|
525
|
+
// Parts the question keeps: every value they show is the same after.
|
|
526
|
+
for (const {part, prefix} of keeps) {
|
|
527
|
+
const a = shown(was, tw, part);
|
|
528
|
+
const b = shown(now, tn, part);
|
|
529
|
+
for (const [k, v] of b) {
|
|
530
|
+
// A whole kept part: its plain look (base); a state or variant: that.
|
|
531
|
+
// A whole kept part: every rule it shows at rest (its plain rule and
|
|
532
|
+
// each variant's); a state or variant: that.
|
|
533
|
+
// (At rest: the plain rule, or one variant's alone; a variant in a
|
|
534
|
+
// selected or checked state is a state of it.)
|
|
535
|
+
if (
|
|
536
|
+
prefix
|
|
537
|
+
? !k.startsWith(prefix)
|
|
538
|
+
: k.split('|')[1] || !/^(base|[a-z]+:[\w-]+)$/.test(k.split('|')[0])
|
|
539
|
+
)
|
|
540
|
+
continue;
|
|
541
|
+
// A plain color written as `background` is the background color the
|
|
542
|
+
// part painted before.
|
|
543
|
+
const prop0 = k.split('|')[2] ?? '';
|
|
544
|
+
const o =
|
|
545
|
+
a.get(k) ??
|
|
546
|
+
(/\|background$/.test(k) ? a.get(`${k}-color`) : undefined) ??
|
|
547
|
+
// A custom property set on the part: what that token was before.
|
|
548
|
+
(/^--/.test(prop0)
|
|
549
|
+
? {
|
|
550
|
+
light: resolveIn(`var(${prop0})`, tw.light, 'light'),
|
|
551
|
+
dark: resolveIn(`var(${prop0})`, tw.dark, 'dark'),
|
|
552
|
+
raw: `var(${prop0})`,
|
|
553
|
+
}
|
|
554
|
+
: undefined);
|
|
555
|
+
// (A state rule the part did not list before is not measured: what
|
|
556
|
+
// it showed in that state is not known here.)
|
|
557
|
+
if (!o && k.split('|')[1]) continue;
|
|
558
|
+
// A value the part did not show before (a keep rule on a member that
|
|
559
|
+
// reads none of it) is not a change it shows; a kept variant is held
|
|
560
|
+
// exactly: a rule it did not have, other than none, is a change,
|
|
561
|
+
// unless it is what the part showed at rest; a corner longhand under
|
|
562
|
+
// a kept shorthand follows the shorthand.
|
|
563
|
+
if (!o && (!prefix || /^(none|transparent|initial|unset)$/.test(v.raw)))
|
|
564
|
+
continue;
|
|
565
|
+
const inherited = a.get(`base||${k.split('|')[2]}`);
|
|
566
|
+
if (
|
|
567
|
+
!o &&
|
|
568
|
+
inherited &&
|
|
569
|
+
inherited.light === v.light &&
|
|
570
|
+
inherited.dark === v.dark
|
|
571
|
+
)
|
|
572
|
+
continue;
|
|
573
|
+
if (!o)
|
|
574
|
+
return `it would change ${part} (${k.split('|').filter(Boolean).join(' ')}), which the question keeps as it is`;
|
|
575
|
+
if (
|
|
576
|
+
/radius$/.test(k) &&
|
|
577
|
+
/-(start|end)-(start|end)-radius$/.test(k) &&
|
|
578
|
+
b.has('base||border-radius')
|
|
579
|
+
)
|
|
580
|
+
continue;
|
|
581
|
+
// A padding side under a kept padding shorthand follows the shorthand
|
|
582
|
+
// (the part's own padding covers every side).
|
|
583
|
+
if (/\|padding-/.test(k)) {
|
|
584
|
+
const sh = b.get('base||padding');
|
|
585
|
+
const was = a.get('base||padding');
|
|
586
|
+
if (sh && was && sh.light === was.light && sh.dark === was.dark)
|
|
587
|
+
continue;
|
|
588
|
+
}
|
|
589
|
+
if (o.light !== v.light || o.dark !== v.dark)
|
|
590
|
+
return `it would change ${part} (${k.split('|').filter(Boolean).join(' ')}), which the question keeps as it is`;
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
const typed = new Set(intent.typed.map(x => x.toLowerCase()));
|
|
594
|
+
// A shadow ask is answered only by a shadow that looks different: an
|
|
595
|
+
// opaque color written with alpha ff, or clamped there, is no change.
|
|
596
|
+
let shadowMoved = !intent.shadowDir;
|
|
597
|
+
// A value the question types is the target: the way of what it writes
|
|
598
|
+
// is as written, but the kind of change and a removal are still held,
|
|
599
|
+
// and every other value is measured the way asked (a dial step beside a
|
|
600
|
+
// typed value included: "smaller, 16px" never gives spacing more). A dial
|
|
601
|
+
// is judged by what it does, never by its own word: "vibrancy less" is
|
|
602
|
+
// the way "more washed out" asks.
|
|
603
|
+
const typedFamilies = new Set(
|
|
604
|
+
steps
|
|
605
|
+
.filter(st => typed.has(String(st.value ?? '').toLowerCase()))
|
|
606
|
+
.map(st => familyOf(st.thing)),
|
|
607
|
+
);
|
|
608
|
+
// The subject's changed values: family, direction, removal.
|
|
609
|
+
const touched = new Set([
|
|
610
|
+
...subjects,
|
|
611
|
+
...steps
|
|
612
|
+
.map(st => st.on)
|
|
613
|
+
.filter(Boolean)
|
|
614
|
+
.flatMap(x => members(String(x))),
|
|
615
|
+
]);
|
|
616
|
+
for (const part of touched) {
|
|
617
|
+
// A whole kept part is checked above, not as a subject.
|
|
618
|
+
if (keeps.some(k => k.part === part && !k.prefix)) continue;
|
|
619
|
+
const a = shown(was, tw, part);
|
|
620
|
+
const b = shown(now, tn, part);
|
|
621
|
+
for (const [k, v] of b) {
|
|
622
|
+
// A kept state or variant of the part is checked above.
|
|
623
|
+
if (
|
|
624
|
+
keeps.some(x => x.part === part && x.prefix && k.startsWith(x.prefix))
|
|
625
|
+
)
|
|
626
|
+
continue;
|
|
627
|
+
const prop = k.split('|')[2];
|
|
628
|
+
// A shorthand written where the part read longhands: its first side.
|
|
629
|
+
// (Whether the value before is the same rule's, not a stand-in.)
|
|
630
|
+
const exact = a.has(k);
|
|
631
|
+
const o =
|
|
632
|
+
a.get(k) ??
|
|
633
|
+
(prop === 'padding'
|
|
634
|
+
? (a.get(`${k.split('|')[0]}||padding-top`) ??
|
|
635
|
+
a.get('base||padding-top'))
|
|
636
|
+
: prop === 'border'
|
|
637
|
+
? a.get('base||border-width')
|
|
638
|
+
: a.get(`base||${prop}`));
|
|
639
|
+
if (o && o.light === v.light && o.dark === v.dark) continue;
|
|
640
|
+
const fam = familyOf(prop);
|
|
641
|
+
if (!fam) continue;
|
|
642
|
+
// A property a typed value writes is asked: the question wrote it.
|
|
643
|
+
const typedHere = steps.some(
|
|
644
|
+
st =>
|
|
645
|
+
typed.has(String(st.value ?? '').toLowerCase()) &&
|
|
646
|
+
familyOf(st.thing) === fam,
|
|
647
|
+
);
|
|
648
|
+
if (
|
|
649
|
+
intent.families.length &&
|
|
650
|
+
!intent.families.includes(fam) &&
|
|
651
|
+
!typedHere
|
|
652
|
+
)
|
|
653
|
+
return `it would also change ${part}'s ${prop}, which is not what the question asks to change`;
|
|
654
|
+
for (const mode of /** @type {const} */ (['light', 'dark'])) {
|
|
655
|
+
if (visible && mode !== visible) continue;
|
|
656
|
+
const after = v[mode];
|
|
657
|
+
const before = o?.[mode] ?? null;
|
|
658
|
+
if (
|
|
659
|
+
intent.zero &&
|
|
660
|
+
['radius', 'space', 'border', 'shadow'].includes(fam)
|
|
661
|
+
) {
|
|
662
|
+
const n = measureNumber(after);
|
|
663
|
+
if (!/^(none|transparent|0)$/.test(after) && n !== 0)
|
|
664
|
+
return `${part}'s ${prop} would be ${after} in ${mode} mode, not none`;
|
|
665
|
+
continue;
|
|
666
|
+
}
|
|
667
|
+
// A shadow written where the part showed none it can read is a
|
|
668
|
+
// change.
|
|
669
|
+
if (fam === 'shadow' && before == null && !/^none$/i.test(after))
|
|
670
|
+
shadowMoved = true;
|
|
671
|
+
if (before == null || typedFamilies.has(fam)) continue;
|
|
672
|
+
// A shadow's strength moves the way asked, in each mode.
|
|
673
|
+
if (fam === 'shadow' && intent.shadowDir) {
|
|
674
|
+
const x = shadowStrength(after);
|
|
675
|
+
const y = shadowStrength(before);
|
|
676
|
+
if (Math.abs(x - y) > 1e-6 && (intent.shadowDir === 'more') !== x > y)
|
|
677
|
+
return `${part}'s ${prop} would get ${intent.shadowDir === 'more' ? 'weaker' : 'stronger'} in ${mode} mode`;
|
|
678
|
+
if (shadowLook(after) !== shadowLook(before)) shadowMoved = true;
|
|
679
|
+
continue;
|
|
680
|
+
}
|
|
681
|
+
// "more transparent": the color's alpha goes down, "more opaque" up.
|
|
682
|
+
if (fam === 'color' && intent.opacityDir) {
|
|
683
|
+
const x = parseColor(after) ? alphaOf(after) : null;
|
|
684
|
+
const y = parseColor(before) ? alphaOf(before) : null;
|
|
685
|
+
if (
|
|
686
|
+
x != null &&
|
|
687
|
+
y != null &&
|
|
688
|
+
Math.abs(x - y) > 1e-3 &&
|
|
689
|
+
(intent.opacityDir === 'more') !== x > y
|
|
690
|
+
)
|
|
691
|
+
return `${part}'s ${prop} would get ${intent.opacityDir === 'more' ? 'more' : 'less'} see-through in ${mode} mode`;
|
|
692
|
+
}
|
|
693
|
+
if (fam === 'color' && intent.lighter != null) {
|
|
694
|
+
// A part's color, in every variant and state it shows (a step on
|
|
695
|
+
// the plain rule reaches the variants that take it), in each mode
|
|
696
|
+
// (or the one the question names), never an overlay layer over
|
|
697
|
+
// the fill; only the kind of color the steps write (a new fill
|
|
698
|
+
// may bring a text color that reads on it).
|
|
699
|
+
if (intent.mode && mode !== intent.mode) continue;
|
|
700
|
+
const [when] = k.split('|');
|
|
701
|
+
if (!exact) continue;
|
|
702
|
+
const kindOf = (/** @type {string} */ x) =>
|
|
703
|
+
/^background/.test(x)
|
|
704
|
+
? 'fill'
|
|
705
|
+
: /border|outline/.test(x)
|
|
706
|
+
? 'line'
|
|
707
|
+
: 'ink';
|
|
708
|
+
if (
|
|
709
|
+
!steps.some(
|
|
710
|
+
st => kindOf(st.thing.replace(/^--color-/, '')) === kindOf(prop),
|
|
711
|
+
)
|
|
712
|
+
)
|
|
713
|
+
continue;
|
|
714
|
+
if (
|
|
715
|
+
/overlay|tint/.test(String(o?.raw ?? '')) ||
|
|
716
|
+
/overlay|tint/.test(v.raw)
|
|
717
|
+
)
|
|
718
|
+
continue;
|
|
719
|
+
const x = painted(after, tn[mode], mode);
|
|
720
|
+
const y = painted(before, tw[mode], mode);
|
|
721
|
+
const want =
|
|
722
|
+
mode === 'dark' &&
|
|
723
|
+
isForeground(prop, intent.contrast, intent.literal)
|
|
724
|
+
? !intent.lighter
|
|
725
|
+
: intent.lighter;
|
|
726
|
+
if (x && y && Math.abs(luminance(x) - luminance(y)) >= 0.5)
|
|
727
|
+
if (want !== luminance(x) > luminance(y))
|
|
728
|
+
return `${part}'s ${prop}${when !== 'base' ? ` (${when})` : ''} would get ${want ? 'darker' : 'lighter'} in ${mode} mode (${before} to ${after})`;
|
|
729
|
+
// "darker than the page": past the part compared against, in
|
|
730
|
+
// each mode it shows.
|
|
731
|
+
if (x && /^background/.test(prop))
|
|
732
|
+
for (const ref of intent.than ?? []) {
|
|
733
|
+
const refValue =
|
|
734
|
+
ref === 'page'
|
|
735
|
+
? resolveIn('var(--color-background-body)', tn[mode], mode)
|
|
736
|
+
: shown(now, tn, ref).get('base||background-color')?.[mode];
|
|
737
|
+
const r = refValue ? painted(refValue, tn[mode], mode) : null;
|
|
738
|
+
if (r && want !== luminance(x) > luminance(r))
|
|
739
|
+
return `${part}'s ${prop}${when !== 'base' ? ` (${when})` : ''} would still be ${want ? 'darker' : 'lighter'} than the ${ref} in ${mode} mode (${after} on ${refValue})`;
|
|
740
|
+
}
|
|
741
|
+
continue;
|
|
742
|
+
}
|
|
743
|
+
const dir = fam === 'opacity' ? intent.opacityDir : intent.dir;
|
|
744
|
+
if (
|
|
745
|
+
!dir ||
|
|
746
|
+
!(
|
|
747
|
+
['radius', 'border', 'weight', 'opacity', 'fontsize'].includes(
|
|
748
|
+
fam,
|
|
749
|
+
) ||
|
|
750
|
+
// A space: one length written over one read (never a shorthand).
|
|
751
|
+
(fam === 'space' &&
|
|
752
|
+
(intent.bound ||
|
|
753
|
+
(exact &&
|
|
754
|
+
steps.some(st => st.thing === prop) &&
|
|
755
|
+
!/\s/.test(after) &&
|
|
756
|
+
!/\s/.test(String(before)))))
|
|
757
|
+
)
|
|
758
|
+
)
|
|
759
|
+
continue;
|
|
760
|
+
const x = measureNumber(after);
|
|
761
|
+
const y = measureNumber(before);
|
|
762
|
+
if (x != null && y != null && x !== y && (dir === 'more') !== x > y)
|
|
763
|
+
return `${part}'s ${prop} would move the other way in ${mode} mode (${before} to ${after})`;
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
// Tokens the steps name (a dial: its main token): the same checks.
|
|
768
|
+
const DIAL_TOKEN = /** @type {Record<string, string>} */ ({
|
|
769
|
+
accent: '--color-accent',
|
|
770
|
+
danger: '--color-error',
|
|
771
|
+
success: '--color-success',
|
|
772
|
+
warning: '--color-warning',
|
|
773
|
+
info: '--color-info',
|
|
774
|
+
neutral: '--color-neutral',
|
|
775
|
+
});
|
|
776
|
+
for (const st of steps) {
|
|
777
|
+
const tok = /^--/.test(st.thing) ? st.thing : DIAL_TOKEN[st.thing];
|
|
778
|
+
if (!tok || st.on) continue;
|
|
779
|
+
const fam = familyOf(tok);
|
|
780
|
+
if (!fam) continue;
|
|
781
|
+
if (intent.families.length && !intent.families.includes(fam))
|
|
782
|
+
return `${tok} is not what the question asks to change`;
|
|
783
|
+
for (const mode of /** @type {const} */ (['light', 'dark'])) {
|
|
784
|
+
if (visible && mode !== visible) continue;
|
|
785
|
+
const after = resolveIn(`var(${tok})`, tn[mode], mode);
|
|
786
|
+
const before = resolveIn(`var(${tok})`, tw[mode], mode);
|
|
787
|
+
if (after === before) continue;
|
|
788
|
+
if (
|
|
789
|
+
intent.zero &&
|
|
790
|
+
['radius', 'space', 'border', 'shadow'].includes(fam)
|
|
791
|
+
) {
|
|
792
|
+
const n = measureNumber(after);
|
|
793
|
+
if (!/^(none|transparent|0)$/.test(after) && n !== 0)
|
|
794
|
+
return `${tok} would be ${after} in ${mode} mode, not none`;
|
|
795
|
+
continue;
|
|
796
|
+
}
|
|
797
|
+
if (typedFamilies.has(fam)) continue;
|
|
798
|
+
if (fam === 'shadow' && intent.shadowDir) {
|
|
799
|
+
const x = shadowStrength(after);
|
|
800
|
+
const y = shadowStrength(before);
|
|
801
|
+
if (Math.abs(x - y) > 1e-6 && (intent.shadowDir === 'more') !== x > y)
|
|
802
|
+
return `${tok} would get ${intent.shadowDir === 'more' ? 'weaker' : 'stronger'} in ${mode} mode`;
|
|
803
|
+
if (shadowLook(after) !== shadowLook(before)) shadowMoved = true;
|
|
804
|
+
continue;
|
|
805
|
+
}
|
|
806
|
+
if (fam === 'color' && intent.opacityDir) {
|
|
807
|
+
const x = parseColor(after) ? alphaOf(after) : null;
|
|
808
|
+
const y = parseColor(before) ? alphaOf(before) : null;
|
|
809
|
+
if (
|
|
810
|
+
x != null &&
|
|
811
|
+
y != null &&
|
|
812
|
+
Math.abs(x - y) > 1e-3 &&
|
|
813
|
+
(intent.opacityDir === 'more') !== x > y
|
|
814
|
+
)
|
|
815
|
+
return `${tok} would get ${intent.opacityDir === 'more' ? 'more' : 'less'} see-through in ${mode} mode`;
|
|
816
|
+
continue;
|
|
817
|
+
}
|
|
818
|
+
if (fam === 'color' && intent.lighter != null) {
|
|
819
|
+
if (intent.mode && mode !== intent.mode) continue;
|
|
820
|
+
const x = painted(after, tn[mode], mode);
|
|
821
|
+
const y = painted(before, tw[mode], mode);
|
|
822
|
+
const want =
|
|
823
|
+
mode === 'dark' && isForeground(tok, intent.contrast, intent.literal)
|
|
824
|
+
? !intent.lighter
|
|
825
|
+
: intent.lighter;
|
|
826
|
+
if (x && y && Math.abs(luminance(x) - luminance(y)) >= 0.5)
|
|
827
|
+
if (want !== luminance(x) > luminance(y))
|
|
828
|
+
return `${tok} would get ${want ? 'darker' : 'lighter'} in ${mode} mode (${before} to ${after})`;
|
|
829
|
+
continue;
|
|
830
|
+
}
|
|
831
|
+
const dir = fam === 'opacity' ? intent.opacityDir : intent.dir;
|
|
832
|
+
if (!dir) continue;
|
|
833
|
+
const x = measureNumber(after);
|
|
834
|
+
const y = measureNumber(before);
|
|
835
|
+
if (x != null && y != null && x !== y && (dir === 'more') !== x > y)
|
|
836
|
+
return `${tok} would move the other way in ${mode} mode (${before} to ${after})`;
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
if (!shadowMoved && steps.some(st => familyOf(st.thing) === 'shadow'))
|
|
840
|
+
return 'the shadows would look the same as they do now (a shadow color at full strength gets no stronger; a bigger or blurrier shadow can)';
|
|
841
|
+
return null;
|
|
842
|
+
}
|
|
843
|
+
|
|
212
844
|
/**
|
|
213
845
|
* Apply one step to theme data in memory, as `set` and `undo` do.
|
|
214
846
|
* @param {import('./_settings.mjs').Ctx} ctx
|