@astryxdesign/cli 0.7.16 → 0.7.17-canary.g0404a74
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 +17 -0
- package/api/build/_adapter.mjs +53 -34
- package/api/build/blocks/blocks.d.mts +7 -5
- package/api/build/blocks/blocks.mjs +113 -26
- package/api/build/blocks/blocks.weights.json +1 -1
- 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 +6 -4
- package/api/build/kit/rank.mjs +132 -28
- package/api/build/kit/signals.d.mts +7 -1
- package/api/build/kit/signals.mjs +21 -10
- package/api/build/kit/start.d.mts +5 -4
- package/api/build/kit/start.mjs +14 -9
- package/api/build/kit/weights.d.mts +39 -3
- package/api/build/kit/weights.json +1 -1
- package/api/build/kit/weights.mjs +351 -46
- 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 +86 -0
- package/api/build/kit/words.mjs +241 -1
- package/api/build/tree.mjs +1 -1
- package/api/component/__fixtures__/resolutions/modules.txt +5 -6
- package/api/component/_adapter.d.mts +26 -2
- package/api/component/_adapter.mjs +135 -8
- package/api/component/component.mjs +14 -1
- package/api/component/list/list.d.mts +1 -1
- package/api/component/list/list.mjs +48 -6
- package/api/discover/_adapter.d.mts +11 -1
- package/api/discover/_adapter.mjs +95 -1
- package/api/discover/detail/item/item.mjs +5 -0
- package/api/discover/discover.mjs +12 -3
- package/api/discover/discover.type.d.mts +16 -3
- package/api/discover/discover.type.mjs +13 -3
- package/api/discover/search/search.mjs +3 -2
- package/api/docs/_adapter.d.mts +57 -2
- package/api/docs/_adapter.mjs +266 -33
- package/api/docs/_entry-names-lazily.d.mts +22 -0
- package/api/docs/_entry-names-lazily.mjs +25 -0
- package/api/docs/_entry-names.d.mts +23 -0
- package/api/docs/_entry-names.mjs +105 -0
- 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 +54 -5
- package/api/doctor/_adapter.mjs +162 -11
- package/api/doctor/built-checks.mjs +40 -14
- package/api/doctor/doctor.d.mts +15 -3
- package/api/doctor/doctor.doc.mjs +1 -1
- package/api/doctor/doctor.mjs +31 -7
- package/api/doctor/theme-checks.d.mts +35 -3
- package/api/doctor/theme-checks.mjs +377 -29
- package/api/hook/_adapter.d.mts +10 -4
- package/api/hook/_adapter.mjs +41 -5
- package/api/hook/detail/detail.mjs +5 -2
- package/api/hook/detail/params/params.mjs +10 -3
- 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/add-helpers.mjs +10 -0
- package/api/integration/authoring-checks.mjs +11 -8
- 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/pack-check.mjs +16 -1
- package/api/integration/validate-integration.d.mts +18 -6
- package/api/integration/validate-integration.mjs +129 -15
- package/api/integration/validate-integration.type.d.mts +22 -0
- package/api/integration/validate-integration.type.mjs +2 -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 +53 -1
- package/api/render/render.type.mjs +32 -2
- package/api/search/ORDERING.md +2 -2
- package/api/search/_adapter.d.mts +9 -0
- package/api/search/_adapter.mjs +85 -0
- package/api/search/_candidate-score.d.mts +9 -4
- package/api/search/_candidate-score.mjs +133 -46
- 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 +14 -0
- package/api/search/_lexical.mjs +93 -11
- 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/template/_adapter.d.mts +16 -0
- package/api/template/_adapter.mjs +39 -2
- package/api/template/cdn/cdn.mjs +37 -8
- package/api/template/copy/copy.d.mts +6 -3
- package/api/template/copy/copy.mjs +40 -8
- package/api/template/template.doc.mjs +3 -3
- package/api/template/template.mjs +63 -11
- package/api/template/template.type.d.mts +1 -0
- package/api/template/template.type.mjs +1 -0
- package/api/theme/_adapter.d.mts +12 -1
- package/api/theme/_adapter.mjs +132 -13
- package/api/theme/_app-provider.d.mts +31 -0
- package/api/theme/_app-provider.mjs +135 -0
- package/api/theme/add/add.mjs +3 -1
- package/api/theme/build/build.d.mts +142 -1
- package/api/theme/build/build.mjs +692 -284
- package/api/theme/build/core-interception.d.mts +10 -0
- package/api/theme/build/core-interception.mjs +10 -0
- package/api/theme/build/font-warning.d.mts +80 -5
- package/api/theme/build/font-warning.mjs +323 -55
- package/api/theme/build/icon-imports.mjs +51 -9
- package/api/theme/build/null-values.d.mts +28 -0
- package/api/theme/build/null-values.mjs +191 -0
- package/api/theme/list/list.mjs +17 -1
- package/api/theme/remove/remove.d.mts +2 -1
- package/api/theme/remove/remove.mjs +7 -3
- package/api/theme/theme.type.d.mts +78 -1
- package/api/theme/theme.type.mjs +38 -2
- package/api/theme/themeAdd.doc.mjs +1 -1
- package/api/theme/themeListAvailable.doc.mjs +1 -1
- package/api/theme/themeRemove.doc.mjs +8 -5
- package/api/theme-edit/_adapter.d.mts +116 -4
- package/api/theme-edit/_adapter.mjs +1058 -93
- package/api/theme-edit/_catalog.d.mts +46 -2
- package/api/theme-edit/_catalog.mjs +115 -14
- package/api/theme-edit/_check.d.mts +133 -24
- package/api/theme-edit/_check.mjs +3392 -531
- package/api/theme-edit/_color.d.mts +26 -0
- package/api/theme-edit/_color.mjs +92 -2
- package/api/theme-edit/_compiler.d.mts +5 -1
- package/api/theme-edit/_compiler.mjs +141 -17
- package/api/theme-edit/_context.d.mts +74 -6
- package/api/theme-edit/_context.mjs +468 -76
- package/api/theme-edit/_css.d.mts +21 -0
- package/api/theme-edit/_css.mjs +87 -14
- package/api/theme-edit/_edit.d.mts +74 -7
- package/api/theme-edit/_edit.mjs +4426 -319
- package/api/theme-edit/_how-commands.d.mts +76 -1
- package/api/theme-edit/_how-commands.mjs +793 -9
- package/api/theme-edit/_how-question.d.mts +97 -6
- package/api/theme-edit/_how-question.mjs +9184 -747
- package/api/theme-edit/_how.d.mts +5 -2
- package/api/theme-edit/_how.mjs +255 -46
- package/api/theme-edit/_importers.d.mts +38 -0
- package/api/theme-edit/_importers.mjs +188 -0
- 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 +322 -0
- package/api/theme-edit/_normal.mjs +1630 -0
- package/api/theme-edit/_palette.d.mts +49 -0
- package/api/theme-edit/_palette.mjs +180 -38
- package/api/theme-edit/_part-words.d.mts +39 -0
- package/api/theme-edit/_part-words.mjs +152 -0
- package/api/theme-edit/_parts.d.mts +55 -3
- package/api/theme-edit/_parts.mjs +421 -36
- package/api/theme-edit/_preview-app.d.mts +7 -13
- package/api/theme-edit/_preview-app.mjs +1108 -599
- package/api/theme-edit/_preview.d.mts +156 -19
- package/api/theme-edit/_preview.mjs +809 -180
- package/api/theme-edit/_project.d.mts +61 -1
- package/api/theme-edit/_project.mjs +177 -6
- package/api/theme-edit/_settings.d.mts +619 -48
- package/api/theme-edit/_settings.mjs +4910 -617
- package/api/theme-edit/_tables.d.mts +41 -0
- package/api/theme-edit/_tables.mjs +261 -41
- package/api/theme-edit/_vet.d.mts +31 -0
- package/api/theme-edit/_vet.mjs +114 -8
- package/api/theme-edit/theme-edit.type.d.mts +34 -2
- package/api/theme-edit/theme-edit.type.mjs +18 -3
- 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/api/upgrade/upgrade.mjs +16 -1
- package/assets/codemods/integration-discovery.mjs +2 -1
- package/assets/codemods/integration-runner.mjs +1 -1
- package/assets/codemods/jscodeshift.d.ts +1 -1
- package/assets/codemods/run-codemod.mjs +151 -18
- package/assets/codemods/runner.mjs +1 -4
- 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 +2 -0
- package/assets/docs/theme.doc.dense.mjs +76 -7
- package/assets/docs/theme.doc.mjs +66 -2
- package/assets/docs/theme.doc.zh.mjs +51 -1
- package/assets/docs/tree/check-your-docs.doc.mjs +1 -1
- package/assets/docs/tree/checks.doc.mjs +2 -2
- package/assets/docs/tree/cli-command.doc.mjs +2 -3
- package/assets/docs/tree/document-the-theme.doc.mjs +1 -1
- package/assets/docs/tree/font-setup.doc.mjs +1 -1
- package/assets/docs/tree/fonts-and-assets.doc.mjs +1 -1
- package/assets/docs/tree/render-pages.doc.mjs +46 -5
- package/assets/docs/tree/share-a-page.doc.mjs +157 -0
- 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/tree/write-good-templates.doc.mjs +1 -1
- package/assets/docs/use-a-theme.doc.mjs +2 -2
- package/assets/docs-routes.generated.json +1 -0
- 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/ChatComposerInput/useSpeechRecognitionHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/ChatComposerInput/useSpeechRecognitionHookUsage.tsx +43 -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/page.tsx +31 -4
- package/assets/templates/pages/ai-chat-landing/template.doc.mjs +5 -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/page.tsx +1 -1
- package/assets/templates/pages/dashboard-alert-rail/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard-cohort-funnel/page.tsx +1 -1
- package/assets/templates/pages/dashboard-cohort-funnel/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard-comparison/page.tsx +2 -2
- package/assets/templates/pages/dashboard-composition/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard-progress/page.tsx +1 -1
- package/assets/templates/pages/dashboard-progress/template.doc.mjs +6 -3
- package/assets/templates/pages/detail-page/page.tsx +60 -7
- 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/page.tsx +13 -13
- package/assets/templates/pages/documentation-technical/template.doc.mjs +7 -1
- package/assets/templates/pages/editor/page.tsx +14 -2
- package/assets/templates/pages/editor/template.doc.mjs +2 -8
- package/assets/templates/pages/file-explorer/page.tsx +9 -0
- 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/form-wizard-vertical/page.tsx +23 -3
- package/assets/templates/pages/gallery-hero/template.doc.mjs +4 -2
- package/assets/templates/pages/ide/page.tsx +33 -2
- package/assets/templates/pages/kanban-board/page.tsx +12 -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/page.tsx +16 -0
- package/assets/templates/pages/login-card/template.doc.mjs +2 -1
- package/assets/templates/pages/login-split/page.tsx +19 -6
- 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/messaging-shell/template.doc.mjs +6 -0
- package/assets/templates/pages/mixed-gallery/template.doc.mjs +2 -1
- package/assets/templates/pages/payment-form/page.tsx +30 -4
- package/assets/templates/pages/product-detail/page.tsx +26 -2
- 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/page.tsx +162 -12
- 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/page.tsx +11 -3
- 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/page.tsx +9 -0
- package/assets/templates/pages/table-filter/template.doc.mjs +9 -8
- package/assets/templates/pages/table-grouped/page.tsx +161 -133
- package/assets/templates/pages/table-grouped/template.doc.mjs +4 -2
- package/assets/templates/pages/table-page/page.tsx +14 -1
- 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/page.tsx +47 -7
- package/assets/templates/pages/work-item-detail/template.doc.mjs +1 -0
- package/assets/theme.template.ts +9 -2
- package/authoring/debug/parse.d.mts +3 -3
- package/authoring/doctypes/_schema.d.mts +9 -9
- 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/authoring/integration/integration.doc.mjs +8 -0
- package/authoring/integration/schema.d.mts +24 -1
- package/authoring/integration/schema.mjs +126 -4
- package/authoring/integration/type.ts +14 -0
- 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/discover.mjs +70 -3
- package/clients/cli/commands/docs.doc.mjs +7 -1
- package/clients/cli/commands/docs.mjs +44 -6
- package/clients/cli/commands/doctor.mjs +84 -16
- package/clients/cli/commands/experimental/render.mjs +42 -1
- package/clients/cli/commands/experimental/theme.mjs +1032 -134
- 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 +2 -2
- package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +2 -2
- 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 +2 -2
- 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-remove.doc.mjs +4 -4
- 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.doc.mjs +1 -1
- package/clients/cli/commands/template.mjs +15 -2
- package/clients/cli/commands/theme-add.doc.mjs +1 -1
- package/clients/cli/commands/theme-build.doc.mjs +5 -1
- package/clients/cli/commands/theme-list.doc.mjs +1 -1
- package/clients/cli/commands/theme-remove.doc.mjs +13 -5
- package/clients/cli/commands/theme.doc.mjs +1 -1
- package/clients/cli/commands/theme.mjs +849 -441
- package/clients/cli/commands/upgrade.mjs +46 -8
- package/clients/cli/index.mjs +9 -19
- 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 +265 -29
- package/clients/cli/lib/manifest.mjs +3 -2
- package/clients/cli/lib/stray-option.mjs +478 -0
- package/clients/cli/lib/unknown-command.mjs +353 -0
- package/clients/cli/manifest.generated.json +1 -1
- package/foundation/agent-docs/agent-docs.mjs +1 -1
- package/foundation/config/project.d.mts +8 -0
- package/foundation/config/project.mjs +26 -29
- package/foundation/config/theme-state.d.mts +31 -2
- package/foundation/config/theme-state.mjs +140 -8
- package/foundation/discovery/authoring-self-docs.mjs +1 -0
- package/foundation/discovery/cli-self-doc-names.d.mts +13 -0
- package/foundation/discovery/cli-self-doc-names.mjs +51 -0
- package/foundation/discovery/cli-self-docs.d.mts +0 -2
- package/foundation/discovery/cli-self-docs.mjs +2 -15
- package/foundation/discovery/component-discovery.d.mts +11 -0
- package/foundation/discovery/component-discovery.mjs +59 -10
- package/foundation/discovery/component-replacement.mjs +130 -1
- package/foundation/discovery/copied-passages.mjs +2 -1
- package/foundation/discovery/core-component-docs.d.mts +29 -0
- package/foundation/discovery/core-component-docs.mjs +83 -0
- package/foundation/discovery/core-theme-facts.d.mts +70 -0
- package/foundation/discovery/core-theme-facts.mjs +384 -0
- package/foundation/discovery/doc-types.mjs +4 -3
- package/foundation/discovery/docs-discovery.d.mts +66 -9
- package/foundation/discovery/docs-discovery.mjs +126 -60
- package/foundation/discovery/entry-name-files.d.mts +106 -0
- package/foundation/discovery/entry-name-files.mjs +354 -0
- package/foundation/discovery/hook-discovery.d.mts +18 -2
- package/foundation/discovery/hook-discovery.mjs +93 -42
- 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-component-views.d.mts +15 -0
- package/foundation/discovery/integration-component-views.mjs +91 -0
- package/foundation/discovery/integration-doc-files.mjs +2 -1
- package/foundation/discovery/module-exports.d.mts +26 -1
- package/foundation/discovery/module-exports.mjs +114 -40
- package/foundation/discovery/name-roots.d.mts +38 -0
- package/foundation/discovery/name-roots.mjs +108 -0
- package/foundation/discovery/next-routes.d.mts +48 -0
- package/foundation/discovery/next-routes.mjs +181 -0
- 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 +40 -18
- package/foundation/discovery/template-adapter.d.mts +49 -29
- package/foundation/discovery/template-adapter.mjs +89 -99
- package/foundation/discovery/template-destination.d.mts +28 -0
- package/foundation/discovery/template-destination.mjs +104 -0
- package/foundation/discovery/template-icons.mjs +2 -1
- package/foundation/discovery/template-ids.d.mts +69 -0
- package/foundation/discovery/template-ids.mjs +199 -0
- package/foundation/discovery/theme-discovery.d.mts +12 -0
- package/foundation/discovery/theme-discovery.mjs +34 -4
- package/foundation/discovery/theme-imports.d.mts +24 -0
- package/foundation/discovery/theme-imports.mjs +61 -4
- package/foundation/discovery/theming-targets.d.mts +13 -5
- package/foundation/discovery/theming-targets.mjs +41 -47
- package/foundation/doc-compiler/generated-levels.d.mts +43 -0
- package/foundation/doc-compiler/generated-levels.mjs +72 -0
- package/foundation/doc-compiler/import.mjs +7 -1
- package/foundation/doc-compiler/inputs.mjs +3 -2
- package/foundation/doc-compiler/literal-doc.d.mts +12 -0
- package/foundation/doc-compiler/literal-doc.mjs +322 -0
- package/foundation/doc-compiler/parse-readable.mjs +4 -1
- package/foundation/doc-compiler/stored-docs.d.mts +29 -0
- package/foundation/doc-compiler/stored-docs.mjs +63 -1
- package/foundation/doc-compiler/tree.d.mts +4 -84
- package/foundation/doc-compiler/tree.mjs +4 -62
- package/foundation/env/semver.mjs +3 -1
- package/foundation/fonts/font-stylesheet.d.mts +46 -0
- package/foundation/fonts/font-stylesheet.mjs +173 -0
- package/foundation/fs/cache-eviction.d.mts +21 -0
- package/foundation/fs/cache-eviction.mjs +73 -0
- package/foundation/fs/exact-codec.d.mts +12 -2
- package/foundation/fs/exact-codec.mjs +23 -6
- package/foundation/fs/file-protection.mjs +16 -5
- package/foundation/fs/gather-cache.d.mts +94 -4
- package/foundation/fs/gather-cache.mjs +671 -106
- package/foundation/fs/glob.d.mts +16 -0
- package/foundation/fs/glob.mjs +105 -0
- package/foundation/fs/jiti-cache.d.mts +19 -1
- package/foundation/fs/jiti-cache.mjs +130 -6
- package/foundation/fs/kept-tree.d.mts +80 -0
- package/foundation/fs/kept-tree.mjs +240 -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/path-safety.d.mts +11 -2
- package/foundation/fs/path-safety.mjs +108 -18
- package/foundation/fs/paths.d.mts +18 -0
- package/foundation/fs/paths.mjs +15 -2
- package/foundation/fs/read-record.d.mts +56 -7
- package/foundation/fs/read-record.mjs +280 -56
- package/foundation/fs/regular-file.d.mts +29 -0
- package/foundation/fs/regular-file.mjs +77 -0
- package/foundation/fs/stop-cleanup.d.mts +12 -0
- package/foundation/fs/stop-cleanup.mjs +66 -0
- 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/integrations.d.mts +23 -1
- package/foundation/integrations/integrations.mjs +18 -1
- package/foundation/integrations/pack-state.d.mts +75 -0
- package/foundation/integrations/pack-state.mjs +314 -0
- package/foundation/integrations/public-imports.d.mts +9 -0
- package/foundation/integrations/public-imports.mjs +3 -2
- package/foundation/integrations/shipped-imports.d.mts +122 -0
- package/foundation/integrations/shipped-imports.mjs +497 -0
- package/foundation/integrations/validate-contributions.d.mts +0 -17
- package/foundation/integrations/validate-contributions.mjs +59 -333
- package/foundation/render/assets.mjs +52 -7
- package/foundation/render/charts.d.mts +78 -27
- package/foundation/render/charts.mjs +266 -90
- package/foundation/render/embedded-files.d.mts +6 -0
- package/foundation/render/embedded-files.mjs +25 -5
- package/foundation/render/embedded-imports.d.mts +70 -7
- package/foundation/render/embedded-imports.mjs +132 -41
- 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/layers.d.mts +30 -0
- package/foundation/render/layers.mjs +158 -0
- package/foundation/render/markup-edits.d.mts +57 -0
- package/foundation/render/markup-edits.mjs +182 -0
- package/foundation/render/offline.d.mts +32 -0
- package/foundation/render/offline.mjs +56 -0
- package/foundation/render/page-host.mjs +29 -12
- package/foundation/render/page-worker.mjs +354 -21
- package/foundation/render/picture-chrome.d.mts +4 -0
- package/foundation/render/picture-chrome.mjs +192 -0
- package/foundation/render/picture-playwright.d.mts +4 -0
- package/foundation/render/picture-playwright.mjs +46 -0
- package/foundation/render/rebuild.mjs +2 -1
- package/foundation/render/render-page.d.mts +79 -5
- package/foundation/render/render-page.mjs +735 -109
- 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 +6 -6
- package/foundation/suggest/name-index.d.mts +148 -0
- package/foundation/suggest/name-index.mjs +317 -0
- package/foundation/suggest/other-command.d.mts +140 -0
- package/foundation/suggest/other-command.mjs +756 -0
- package/foundation/text/compare-text.d.mts +14 -0
- package/foundation/text/compare-text.mjs +68 -0
- package/foundation/text/css-escape.d.mts +18 -0
- package/foundation/text/css-escape.mjs +35 -0
- package/foundation/text/entry-names.d.mts +14 -0
- package/foundation/text/entry-names.mjs +14 -0
- package/foundation/text/string-utils.d.mts +46 -6
- package/foundation/text/string-utils.mjs +118 -20
- package/foundation/text/suggest-order.d.mts +47 -4
- package/foundation/text/suggest-order.mjs +174 -5
- package/foundation/xle/browser.d.mts +2 -2
- package/foundation/xle/expand.mjs +2 -1
- package/host/index.mjs +8 -6
- package/package.json +7 -6
|
@@ -12,6 +12,7 @@ import {AstryxError} from '../error.mjs';
|
|
|
12
12
|
import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
|
|
13
13
|
import {checkSetting} from './_check.mjs';
|
|
14
14
|
import {baseResolved} from './_project.mjs';
|
|
15
|
+
import {readThemeListState} from '../theme/_adapter.mjs';
|
|
15
16
|
import {
|
|
16
17
|
compileTheme,
|
|
17
18
|
editedThemes,
|
|
@@ -20,7 +21,14 @@ import {
|
|
|
20
21
|
readHistory,
|
|
21
22
|
themeFiles,
|
|
22
23
|
} from './_settings.mjs';
|
|
23
|
-
import {LIKE, P} from './_tables.mjs';
|
|
24
|
+
import {FAMILIES, GROUPS, LIKE, P} from './_tables.mjs';
|
|
25
|
+
import {
|
|
26
|
+
COLOR_IN_VALUE,
|
|
27
|
+
alphaOf,
|
|
28
|
+
colorsIn,
|
|
29
|
+
parseColor,
|
|
30
|
+
splitTop,
|
|
31
|
+
} from './_color.mjs';
|
|
24
32
|
import {quoteCommandArgument} from '../../foundation/env/package-manager.mjs';
|
|
25
33
|
|
|
26
34
|
/** The theme name commands use when the app has no theme yet. */
|
|
@@ -53,7 +61,8 @@ export const EXAMPLE_THEME = 'my-theme';
|
|
|
53
61
|
* @property {import('./_settings.mjs').ThemeData} data
|
|
54
62
|
* @property {{light: Record<string, string>, dark: Record<string, string>}} base
|
|
55
63
|
* @property {{light: Record<string, string>, dark: Record<string, string>}} [own] - The theme's own values: the base's with its settings applied.
|
|
56
|
-
* @property {(steps: Step[]) => {ok: true} | {ok: false, why: string}} check
|
|
64
|
+
* @property {(steps: Step[]) => {ok: true} | {ok: false, why: string, run?: string[]}} check
|
|
65
|
+
* @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
66
|
*/
|
|
58
67
|
|
|
59
68
|
/**
|
|
@@ -108,18 +117,34 @@ export async function howTheme(ctx, cwd, name) {
|
|
|
108
117
|
}
|
|
109
118
|
if (themes.length > 1 && !note)
|
|
110
119
|
note = `the commands are for ${slug}, the theme changed last; --theme picks another of: ${themes.join(', ')}`;
|
|
111
|
-
}
|
|
112
|
-
|
|
120
|
+
}
|
|
121
|
+
// With no editor theme, the theme the app shows now (its default, read
|
|
122
|
+
// as `theme add` and doctor read it) is what the answer starts from and
|
|
123
|
+
// measures against, when it is a base the editor can start from.
|
|
124
|
+
const appDefault = (() => {
|
|
125
|
+
try {
|
|
126
|
+
const d = readThemeListState(cwd).defaultSlug;
|
|
127
|
+
return d && LIKE.includes(d) ? d : null;
|
|
128
|
+
} catch {
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
})();
|
|
132
|
+
const startLike = appDefault ?? LIKE[0];
|
|
133
|
+
if (!name && !themes.length)
|
|
134
|
+
note = `the app has no theme yet; the commands are for a theme named ${EXAMPLE_THEME}, made first with: ${P} new ${EXAMPLE_THEME} --like ${startLike}${appDefault ? ` (${appDefault} is the theme the app shows now)` : ''}`;
|
|
113
135
|
const exists = Boolean(data);
|
|
114
136
|
if (!data) {
|
|
115
137
|
if (!themes.length) slug = EXAMPLE_THEME;
|
|
116
|
-
data = {name: slug, like:
|
|
138
|
+
data = {name: slug, like: startLike, mode: 'both', settings: []};
|
|
117
139
|
}
|
|
118
140
|
const theme = /** @type {import('./_settings.mjs').ThemeData} */ (data);
|
|
119
141
|
const base = await baseResolved(ctx.project, theme.like);
|
|
120
142
|
const compiled = (/** @type {import('./_settings.mjs').ThemeData} */ d) =>
|
|
121
143
|
JSON.stringify([d.mode, compileTheme(ctx, d, base)]);
|
|
122
144
|
const before = compiled(theme);
|
|
145
|
+
/** @type {any} */
|
|
146
|
+
let beforeCache = null;
|
|
147
|
+
const beforeCompiled = () => (beforeCache ??= compileTheme(ctx, theme, base));
|
|
123
148
|
// Whether a body font setting also moves the heading font: Core gives
|
|
124
149
|
// headings the body family when a theme names no heading family, so it is
|
|
125
150
|
// read from Core, and stays right when that changes.
|
|
@@ -184,6 +209,35 @@ export async function howTheme(ctx, cwd, name) {
|
|
|
184
209
|
? readHistory(themeFiles(cwd, slug).history).steps.length
|
|
185
210
|
: 0,
|
|
186
211
|
bodyFontReachesHeadings,
|
|
212
|
+
/**
|
|
213
|
+
* The measured check: build the theme with the steps in memory (the
|
|
214
|
+
* same compile `set` builds from; nothing is written), resolve every
|
|
215
|
+
* value the touched parts show at rest and in the named state or
|
|
216
|
+
* variant, in light and dark, before and after, and hold them to what
|
|
217
|
+
* the question asks. Returns why it does not fit, or null.
|
|
218
|
+
* @param {Step[]} steps
|
|
219
|
+
* @param {MeasureIntent} intent
|
|
220
|
+
* @returns {string | null}
|
|
221
|
+
*/
|
|
222
|
+
measure(steps, intent) {
|
|
223
|
+
const d = JSON.parse(JSON.stringify(theme));
|
|
224
|
+
const checkCtx = /** @type {any} */ ({...ctx, base});
|
|
225
|
+
try {
|
|
226
|
+
for (const st of steps) apply(checkCtx, slug, d, st);
|
|
227
|
+
} catch {
|
|
228
|
+
return null; // check() says why
|
|
229
|
+
}
|
|
230
|
+
const was = beforeCompiled();
|
|
231
|
+
const now = compileTheme(ctx, d, base);
|
|
232
|
+
// A one-mode theme shows only that mode: only it is measured.
|
|
233
|
+
const visible =
|
|
234
|
+
d.mode === 'light-only'
|
|
235
|
+
? 'light'
|
|
236
|
+
: d.mode === 'dark-only'
|
|
237
|
+
? 'dark'
|
|
238
|
+
: null;
|
|
239
|
+
return measureFit(ctx, base, was, now, intent, steps, visible);
|
|
240
|
+
},
|
|
187
241
|
check(steps) {
|
|
188
242
|
/** @type {import('./_settings.mjs').ThemeData} */
|
|
189
243
|
const d = JSON.parse(JSON.stringify(theme));
|
|
@@ -198,17 +252,742 @@ export async function howTheme(ctx, cwd, name) {
|
|
|
198
252
|
};
|
|
199
253
|
return {ok: true};
|
|
200
254
|
} catch (e) {
|
|
201
|
-
if (e instanceof AstryxError)
|
|
255
|
+
if (e instanceof AstryxError) {
|
|
256
|
+
// The command the refusal names to run instead, when it names
|
|
257
|
+
// one ("set t text-size 18").
|
|
258
|
+
const run = (e.suggestions ?? [])
|
|
259
|
+
.filter(x => /^do this instead/.test(String(x.reason ?? '')))
|
|
260
|
+
.map(x => String(x.name));
|
|
202
261
|
return {
|
|
203
262
|
ok: false,
|
|
204
263
|
why: e.message.replace(/ Nothing was changed\.$/, ''),
|
|
264
|
+
...(run.length ? {run} : {}),
|
|
205
265
|
};
|
|
266
|
+
}
|
|
206
267
|
throw e;
|
|
207
268
|
}
|
|
208
269
|
},
|
|
209
270
|
};
|
|
210
271
|
}
|
|
211
272
|
|
|
273
|
+
/**
|
|
274
|
+
* What the measured check holds a command to.
|
|
275
|
+
* @typedef {object} MeasureIntent
|
|
276
|
+
* @property {string[]} families the kinds of change asked for (color, radius, space, border, weight, opacity, shadow, fontsize); empty: any
|
|
277
|
+
* @property {'more' | 'less' | null} dir the way a size moves
|
|
278
|
+
* @property {boolean | null} lighter the way a color moves
|
|
279
|
+
* @property {'more' | 'less' | null} opacityDir the way an opacity moves
|
|
280
|
+
* @property {boolean} zero a removal: the changed values reach none or 0
|
|
281
|
+
* @property {string[]} subjects the parts the question changes
|
|
282
|
+
* @property {string[]} keep the parts it excepts, compares against or forbids changing
|
|
283
|
+
* @property {string[]} typed values the question gives (taken as given)
|
|
284
|
+
* @property {'light' | 'dark' | null} [mode] the mode the question names
|
|
285
|
+
* @property {boolean} [bound] the question gives a bound ("smaller than 24px"): a space is checked against it too
|
|
286
|
+
* @property {boolean} [contrast] the words ask about contrast ("too light to read"): text in dark mode moves the other way
|
|
287
|
+
* @property {string[]} [than] parts the question compares against ("darker than the page"): a color moves past theirs
|
|
288
|
+
* @property {string} [from] a theme color the way is taken from ("the accent color but lighter"): a color moves that way from it, not from the part's own
|
|
289
|
+
* @property {'more' | 'less'} [saturation] the colors asked more or less saturated ("more colorful", "more muted")
|
|
290
|
+
* @property {boolean} [literal] a mode is named with lighter or darker: borders and the shared text color move as written
|
|
291
|
+
* @property {'more' | 'less' | null} [shadowDir] the way a shadow's strength moves ("darker shadows": more)
|
|
292
|
+
*/
|
|
293
|
+
|
|
294
|
+
/** A camelCase property as CSS writes it. @param {string} k */
|
|
295
|
+
const kebab = k => k.replace(/[A-Z]/g, m => `-${m.toLowerCase()}`);
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Every value of a compiled part, by `when|state|prop`.
|
|
299
|
+
* @param {any} comp the part's compiled styles
|
|
300
|
+
* @returns {Map<string, string>}
|
|
301
|
+
*/
|
|
302
|
+
function partValues(comp) {
|
|
303
|
+
/** @type {Map<string, string>} */
|
|
304
|
+
const out = new Map();
|
|
305
|
+
for (const [when, rules] of Object.entries(comp ?? {}))
|
|
306
|
+
for (const [k, v] of Object.entries(/** @type {any} */ (rules) ?? {}))
|
|
307
|
+
if (v && typeof v === 'object')
|
|
308
|
+
for (const [k2, v2] of Object.entries(v))
|
|
309
|
+
out.set(`${when}|${k}|${kebab(k2)}`, String(v2));
|
|
310
|
+
else out.set(`${when}||${kebab(k)}`, String(v));
|
|
311
|
+
// A plain color written as `background` paints the background color.
|
|
312
|
+
for (const [k, v] of [...out])
|
|
313
|
+
if (/\|background$/.test(k) && !/gradient|url\(/.test(v)) {
|
|
314
|
+
const bc = k.replace(/background$/, 'background-color');
|
|
315
|
+
if (!out.has(bc)) out.set(bc, v);
|
|
316
|
+
}
|
|
317
|
+
return out;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* A value with every var() written out from a mode's tokens, and
|
|
322
|
+
* light-dark() taken for that mode.
|
|
323
|
+
* @param {string} v
|
|
324
|
+
* @param {Record<string, string>} map
|
|
325
|
+
* @param {'light' | 'dark'} mode
|
|
326
|
+
*/
|
|
327
|
+
function resolveIn(v, map, mode) {
|
|
328
|
+
let out = String(v ?? '');
|
|
329
|
+
for (let i = 0; i < 8; i++) {
|
|
330
|
+
const next = out
|
|
331
|
+
// (A variable with no value here and no fallback stays as written:
|
|
332
|
+
// a value read in part is no value, never the rest of it.)
|
|
333
|
+
.replace(/var\(\s*(--[a-z0-9-]+)\s*(?:,\s*([^()]*))?\)/gi, (m, t, fb) =>
|
|
334
|
+
String(map[t] ?? fb ?? m),
|
|
335
|
+
)
|
|
336
|
+
.replace(
|
|
337
|
+
/light-dark\(\s*([^,()]+(?:\([^()]*\))?)\s*,\s*([^()]+(?:\([^()]*\))?)\s*\)/gi,
|
|
338
|
+
(_, a, b) => (mode === 'light' ? a : b),
|
|
339
|
+
);
|
|
340
|
+
if (next === out) break;
|
|
341
|
+
out = next;
|
|
342
|
+
}
|
|
343
|
+
return out.trim().toLowerCase();
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/** The family of a CSS property or token, as the step check names them. @param {string} prop */
|
|
347
|
+
function familyOf(prop) {
|
|
348
|
+
if (/radius/.test(prop)) return 'radius';
|
|
349
|
+
if (/^--shadow-|^box-shadow$/.test(prop)) return 'shadow';
|
|
350
|
+
if (/^opacity$/.test(prop)) return 'opacity';
|
|
351
|
+
if (/weight/.test(prop)) return 'weight';
|
|
352
|
+
if (/^(font-size|--font-size-[a-z0-9]+|--text-[a-z0-9-]+-size)$/.test(prop))
|
|
353
|
+
return 'fontsize';
|
|
354
|
+
if (
|
|
355
|
+
/^(border(-[a-z]+)?-width|border(-(top|bottom|left|right|block|inline))?$|--border-width|--focus-outline-width|outline-width)$/.test(
|
|
356
|
+
prop,
|
|
357
|
+
)
|
|
358
|
+
)
|
|
359
|
+
return 'border';
|
|
360
|
+
if (/colou?r|^background(-image)?$|^fill$|^stroke$|^filter$/.test(prop))
|
|
361
|
+
return 'color';
|
|
362
|
+
if (
|
|
363
|
+
/^(padding|gap|margin|min-height|height|width|max-width|min-width|--spacing-|--size-)/.test(
|
|
364
|
+
prop,
|
|
365
|
+
)
|
|
366
|
+
)
|
|
367
|
+
return 'space';
|
|
368
|
+
return null;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/** A length as px (rem/em at 16), or a plain number, or null. @param {string} v */
|
|
372
|
+
function measureNumber(v) {
|
|
373
|
+
const m = /^(-?\d*\.?\d+)(px|rem|em)?$/.exec(
|
|
374
|
+
String(v).trim().split(/\s+/)[0],
|
|
375
|
+
);
|
|
376
|
+
return m ? Number(m[1]) * (m[2] === 'rem' || m[2] === 'em' ? 16 : 1) : null;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* Whether a color steps for contrast in dark mode (a border; text when the
|
|
381
|
+
* words ask about contrast): there "darker" asks for more contrast, so it
|
|
382
|
+
* moves lighter, and "lighter" darker; a fill moves the same way in both
|
|
383
|
+
* modes.
|
|
384
|
+
* @param {string} name a token or a property
|
|
385
|
+
* @param {boolean} [contrast] the words ask about contrast
|
|
386
|
+
* @param {boolean} [literal] a mode is named with lighter or darker
|
|
387
|
+
*/
|
|
388
|
+
const isForeground = (name, contrast = false, literal = false) =>
|
|
389
|
+
!/background|surface|fill|accent|overlay/.test(name) &&
|
|
390
|
+
// Borders and the shared text tokens step by contrast with the page (how
|
|
391
|
+
// answers "lighter text" and "darker borders" that way), unless a mode is
|
|
392
|
+
// named; a part's own color steps as written.
|
|
393
|
+
((!literal && /border|outline/.test(name)) ||
|
|
394
|
+
(!literal && /^--color-text-/.test(name)) ||
|
|
395
|
+
(contrast && /text|^color$|on-/.test(name)));
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* How strong a shadow reads: the sum of its colors' alphas; 0 for none.
|
|
399
|
+
* @param {string} v
|
|
400
|
+
*/
|
|
401
|
+
function shadowStrength(v) {
|
|
402
|
+
if (!v || /^none$/.test(v.trim())) return 0;
|
|
403
|
+
// Each layer's color, read by the one color reader (hex with alpha,
|
|
404
|
+
// rgba(), hsla(), `/ alpha`). A layer has lengths: a bare color is no
|
|
405
|
+
// shadow.
|
|
406
|
+
return splitTop(v, ',')
|
|
407
|
+
.filter(layer => /(?:^|\s)-?\d*\.?\d+(?:px|rem|em)?(?=\s|$)/.test(layer))
|
|
408
|
+
.reduce(
|
|
409
|
+
(sum, layer) => sum + colorsIn(layer).reduce((n, c) => n + alphaOf(c), 0),
|
|
410
|
+
0,
|
|
411
|
+
);
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
/**
|
|
415
|
+
* A shadow as it renders: each color written in one form (hex with its
|
|
416
|
+
* alpha), so two spellings of the same shadow compare equal.
|
|
417
|
+
* @param {string} v
|
|
418
|
+
*/
|
|
419
|
+
function shadowLook(v) {
|
|
420
|
+
return String(v)
|
|
421
|
+
.replace(COLOR_IN_VALUE, c => {
|
|
422
|
+
const rgb = parseColor(c);
|
|
423
|
+
if (!rgb) return c;
|
|
424
|
+
const a = Math.round(alphaOf(c) * 255);
|
|
425
|
+
return `rgb(${rgb.slice(0, 3).join(' ')} / ${a})`;
|
|
426
|
+
})
|
|
427
|
+
.replace(/\s+/g, ' ')
|
|
428
|
+
.trim();
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* A color as it paints over the page in a mode: its alpha blended with the
|
|
433
|
+
* page color, so a see-through fill compares by what shows.
|
|
434
|
+
* @param {string} v
|
|
435
|
+
* @param {Record<string, string>} toks the mode's tokens
|
|
436
|
+
* @param {'light' | 'dark'} mode
|
|
437
|
+
* @returns {number[] | null}
|
|
438
|
+
*/
|
|
439
|
+
function painted(v, toks, mode) {
|
|
440
|
+
const rgb = parseColor(v);
|
|
441
|
+
if (!rgb) return null;
|
|
442
|
+
const a = alphaOf(v);
|
|
443
|
+
const page =
|
|
444
|
+
parseColor(resolveIn('var(--color-background-body)', toks, mode)) ??
|
|
445
|
+
(mode === 'dark' ? [0, 0, 0] : [255, 255, 255]);
|
|
446
|
+
return rgb.slice(0, 3).map((x, i) => x * a + page[i] * (1 - a));
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
/**
|
|
450
|
+
* A color's HSL saturation, 0 to 1, or null when it does not read.
|
|
451
|
+
* @param {string | number[] | null} v a color, or its RGB
|
|
452
|
+
*/
|
|
453
|
+
function saturationOf(v) {
|
|
454
|
+
const rgb = Array.isArray(v) ? v : v == null ? null : parseColor(v);
|
|
455
|
+
if (!rgb) return null;
|
|
456
|
+
const [r, g, b] = rgb.map(x => x / 255);
|
|
457
|
+
const max = Math.max(r, g, b);
|
|
458
|
+
const min = Math.min(r, g, b);
|
|
459
|
+
const l = (max + min) / 2;
|
|
460
|
+
const d = max - min;
|
|
461
|
+
return d === 0 ? 0 : d / (1 - Math.abs(2 * l - 1));
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
/** @param {number[]} c */
|
|
465
|
+
const luminance = c => c[0] * 0.299 + c[1] * 0.587 + c[2] * 0.114;
|
|
466
|
+
|
|
467
|
+
/**
|
|
468
|
+
* Hold the after build to the intent; why it does not fit, or null.
|
|
469
|
+
* @param {any} ctx
|
|
470
|
+
* @param {any} base
|
|
471
|
+
* @param {any} was
|
|
472
|
+
* @param {any} now
|
|
473
|
+
* @param {MeasureIntent} intent
|
|
474
|
+
* @param {Step[]} steps
|
|
475
|
+
* @param {'light' | 'dark' | null} [visible] the one mode a one-mode theme shows
|
|
476
|
+
*/
|
|
477
|
+
function measureFit(ctx, base, was, now, intent, steps, visible = null) {
|
|
478
|
+
const tw = ownTokens(was, base);
|
|
479
|
+
const tn = ownTokens(now, base);
|
|
480
|
+
const C = ctx.C;
|
|
481
|
+
/** @param {string} part */
|
|
482
|
+
const members = part => FAMILIES[part] ?? [part];
|
|
483
|
+
// A kept part, or one state or variant of it (`part@when|state|`).
|
|
484
|
+
/** @type {Array<{part: string, prefix: string}>} */
|
|
485
|
+
const keeps = intent.keep.flatMap(k => {
|
|
486
|
+
const [part, prefix = ''] = k.split('@');
|
|
487
|
+
return members(part).map(m => ({part: m, prefix}));
|
|
488
|
+
});
|
|
489
|
+
const subjects = new Set(intent.subjects.flatMap(members));
|
|
490
|
+
/**
|
|
491
|
+
* The values a part shows, by `when|state|prop` and mode: its own
|
|
492
|
+
* compiled rules, then each token it reads for a property.
|
|
493
|
+
* @param {any} compiled
|
|
494
|
+
* @param {{light: Record<string, string>, dark: Record<string, string>}} toks
|
|
495
|
+
* @param {string} part
|
|
496
|
+
*/
|
|
497
|
+
const shown = (compiled, toks, part) => {
|
|
498
|
+
// Each rule of the part: the base theme's own declarations with the
|
|
499
|
+
// theme's on top, condition by condition (a theme rule that sets one
|
|
500
|
+
// property keeps the base rule's others).
|
|
501
|
+
/** @type {Record<string, Record<string, any>>} */
|
|
502
|
+
const rules = {};
|
|
503
|
+
for (const src of [
|
|
504
|
+
base.components?.[part] ?? {},
|
|
505
|
+
compiled.components?.[part] ?? {},
|
|
506
|
+
])
|
|
507
|
+
for (const [when, rule] of Object.entries(src))
|
|
508
|
+
rules[when] =
|
|
509
|
+
rule && typeof rule === 'object' && !Array.isArray(rule)
|
|
510
|
+
? {...(rules[when] ?? {}), ...rule}
|
|
511
|
+
: rule;
|
|
512
|
+
const own = partValues(rules);
|
|
513
|
+
// A token the part's own rule sets (a part-scoped dial's --spacing-4)
|
|
514
|
+
// is the value inside the part.
|
|
515
|
+
// A token a variant's rule sets holds in that variant, over the part's.
|
|
516
|
+
const scoped = (
|
|
517
|
+
/** @type {'light' | 'dark'} */ m,
|
|
518
|
+
/** @type {string} */ when,
|
|
519
|
+
) => {
|
|
520
|
+
/** @type {Record<string, string>} */
|
|
521
|
+
const t = {...toks[m]};
|
|
522
|
+
for (const w of when === 'base' ? ['base'] : ['base', when])
|
|
523
|
+
for (const [k, v] of Object.entries(rules[w] ?? {}))
|
|
524
|
+
if (k.startsWith('--') && typeof v === 'string') t[k] = v;
|
|
525
|
+
return t;
|
|
526
|
+
};
|
|
527
|
+
/** @type {Map<string, string>} */
|
|
528
|
+
const raw = new Map(own);
|
|
529
|
+
// The part at rest in its main variant is its `base` too (a set with no
|
|
530
|
+
// --when writes base).
|
|
531
|
+
const mainWhen = (/** @type {string[]} */ ws) =>
|
|
532
|
+
ws.some(
|
|
533
|
+
w =>
|
|
534
|
+
w === '' ||
|
|
535
|
+
/^variant=(default|primary|accent|neutral)$|^size=md$/.test(w),
|
|
536
|
+
);
|
|
537
|
+
// What Core writes for a property in a rule (a card's padding is its
|
|
538
|
+
// container padding less the border width): the whole declaration, so
|
|
539
|
+
// a value is never read from one token of several.
|
|
540
|
+
const declOf = (
|
|
541
|
+
/** @type {string} */ prop,
|
|
542
|
+
/** @type {string} */ w,
|
|
543
|
+
/** @type {string} */ token,
|
|
544
|
+
) => {
|
|
545
|
+
const at = C.MAP[part]?.at?.[prop] ?? {};
|
|
546
|
+
const attrs = w ? w.split(' ') : [];
|
|
547
|
+
const key = Object.keys(at).find(k =>
|
|
548
|
+
attrs.every(x => k.split(',').includes(x)),
|
|
549
|
+
);
|
|
550
|
+
// (Only a declaration of several theme tokens: one token alone is
|
|
551
|
+
// read as that token.)
|
|
552
|
+
const decl = key ? String(at[key]) : '';
|
|
553
|
+
const tokens = new Set(
|
|
554
|
+
[...decl.matchAll(/var\(\s*(--[a-z][a-z0-9-]*)/g)]
|
|
555
|
+
.map(m => m[1])
|
|
556
|
+
.filter(t => !/^--(_|astryx-)/.test(t)),
|
|
557
|
+
);
|
|
558
|
+
return decl.includes(token) && tokens.size > 1 ? decl : `var(${token})`;
|
|
559
|
+
};
|
|
560
|
+
for (const g of Object.keys(GROUPS))
|
|
561
|
+
for (const r of C.partReads(part, g) ?? [])
|
|
562
|
+
if (mainWhen(r.when?.length ? r.when : ['']))
|
|
563
|
+
for (const prop of r.props ?? []) {
|
|
564
|
+
const key = `base||${prop}`;
|
|
565
|
+
const w = (r.when?.length ? r.when : ['']).find(
|
|
566
|
+
(/** @type {string} */ x) => mainWhen([x]),
|
|
567
|
+
);
|
|
568
|
+
if (!raw.has(key)) raw.set(key, declOf(prop, w ?? '', r.token));
|
|
569
|
+
}
|
|
570
|
+
for (const g of Object.keys(GROUPS))
|
|
571
|
+
for (const r of C.partReads(part, g) ?? [])
|
|
572
|
+
for (const prop of r.props ?? [])
|
|
573
|
+
for (const w of r.when?.length ? r.when : [''])
|
|
574
|
+
if (!/::|:active|:hover|:focus|:checked|:disabled/.test(w)) {
|
|
575
|
+
const key = `${w ? w.replace('=', ':') : 'base'}||${prop}`;
|
|
576
|
+
// A variant with no rule of its own takes the part's own base
|
|
577
|
+
// rule over the token it reads.
|
|
578
|
+
if (!raw.has(key))
|
|
579
|
+
raw.set(
|
|
580
|
+
key,
|
|
581
|
+
own.get(`base||${prop}`) ?? declOf(prop, w, r.token),
|
|
582
|
+
);
|
|
583
|
+
}
|
|
584
|
+
/** @type {Map<string, {light: string, dark: string, raw: string}>} */
|
|
585
|
+
const out = new Map();
|
|
586
|
+
for (const [k, v] of raw)
|
|
587
|
+
out.set(k, {
|
|
588
|
+
light: resolveIn(v, scoped('light', k.split('|')[0]), 'light'),
|
|
589
|
+
dark: resolveIn(v, scoped('dark', k.split('|')[0]), 'dark'),
|
|
590
|
+
raw: v,
|
|
591
|
+
});
|
|
592
|
+
return out;
|
|
593
|
+
};
|
|
594
|
+
// Parts the question keeps: every value they show is the same after.
|
|
595
|
+
for (const {part, prefix} of keeps) {
|
|
596
|
+
const a = shown(was, tw, part);
|
|
597
|
+
const b = shown(now, tn, part);
|
|
598
|
+
for (const [k, v] of b) {
|
|
599
|
+
// A whole kept part: its plain look (base); a state or variant: that.
|
|
600
|
+
// A whole kept part: every rule it shows at rest (its plain rule and
|
|
601
|
+
// each variant's); a state or variant: that.
|
|
602
|
+
// (At rest: the plain rule, or one variant's alone; a variant in a
|
|
603
|
+
// selected or checked state is a state of it.)
|
|
604
|
+
if (
|
|
605
|
+
prefix
|
|
606
|
+
? !k.startsWith(prefix)
|
|
607
|
+
: k.split('|')[1] || !/^(base|[a-z]+:[\w-]+)$/.test(k.split('|')[0])
|
|
608
|
+
)
|
|
609
|
+
continue;
|
|
610
|
+
// A plain color written as `background` is the background color the
|
|
611
|
+
// part painted before.
|
|
612
|
+
const prop0 = k.split('|')[2] ?? '';
|
|
613
|
+
const o =
|
|
614
|
+
a.get(k) ??
|
|
615
|
+
(/\|background$/.test(k) ? a.get(`${k}-color`) : undefined) ??
|
|
616
|
+
// A custom property set on the part: what that token was before.
|
|
617
|
+
(/^--/.test(prop0)
|
|
618
|
+
? {
|
|
619
|
+
light: resolveIn(`var(${prop0})`, tw.light, 'light'),
|
|
620
|
+
dark: resolveIn(`var(${prop0})`, tw.dark, 'dark'),
|
|
621
|
+
raw: `var(${prop0})`,
|
|
622
|
+
}
|
|
623
|
+
: undefined);
|
|
624
|
+
// (A state rule the part did not list before is not measured: what
|
|
625
|
+
// it showed in that state is not known here.)
|
|
626
|
+
if (!o && k.split('|')[1]) continue;
|
|
627
|
+
// A value the part did not show before (a keep rule on a member that
|
|
628
|
+
// reads none of it) is not a change it shows; a kept variant is held
|
|
629
|
+
// exactly: a rule it did not have, other than none, is a change,
|
|
630
|
+
// unless it is what the part showed at rest; a corner longhand under
|
|
631
|
+
// a kept shorthand follows the shorthand.
|
|
632
|
+
if (!o && (!prefix || /^(none|transparent|initial|unset)$/.test(v.raw)))
|
|
633
|
+
continue;
|
|
634
|
+
const inherited = a.get(`base||${k.split('|')[2]}`);
|
|
635
|
+
if (
|
|
636
|
+
!o &&
|
|
637
|
+
inherited &&
|
|
638
|
+
inherited.light === v.light &&
|
|
639
|
+
inherited.dark === v.dark
|
|
640
|
+
)
|
|
641
|
+
continue;
|
|
642
|
+
if (!o)
|
|
643
|
+
return `it would change ${part} (${k.split('|').filter(Boolean).join(' ')}), which the question keeps as it is`;
|
|
644
|
+
if (
|
|
645
|
+
/radius$/.test(k) &&
|
|
646
|
+
/-(start|end)-(start|end)-radius$/.test(k) &&
|
|
647
|
+
b.has('base||border-radius')
|
|
648
|
+
)
|
|
649
|
+
continue;
|
|
650
|
+
// A padding side under a kept padding shorthand follows the shorthand
|
|
651
|
+
// (the part's own padding covers every side).
|
|
652
|
+
if (/\|padding-/.test(k)) {
|
|
653
|
+
const sh = b.get('base||padding');
|
|
654
|
+
const was = a.get('base||padding');
|
|
655
|
+
if (sh && was && sh.light === was.light && sh.dark === was.dark)
|
|
656
|
+
continue;
|
|
657
|
+
}
|
|
658
|
+
if (o.light !== v.light || o.dark !== v.dark)
|
|
659
|
+
return `it would change ${part} (${k.split('|').filter(Boolean).join(' ')}), which the question keeps as it is`;
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
const typed = new Set(intent.typed.map(x => x.toLowerCase()));
|
|
663
|
+
// A shadow ask is answered only by a shadow that looks different: an
|
|
664
|
+
// opaque color written with alpha ff, or clamped there, is no change.
|
|
665
|
+
let shadowMoved = !intent.shadowDir;
|
|
666
|
+
// A value the question types is the target: the way of what it writes
|
|
667
|
+
// is as written, but the kind of change and a removal are still held,
|
|
668
|
+
// and every other value is measured the way asked (a dial step beside a
|
|
669
|
+
// typed value included: "smaller, 16px" never gives spacing more). A dial
|
|
670
|
+
// is judged by what it does, never by its own word: "vibrancy less" is
|
|
671
|
+
// the way "more washed out" asks.
|
|
672
|
+
const typedFamilies = new Set(
|
|
673
|
+
steps
|
|
674
|
+
.filter(st => typed.has(String(st.value ?? '').toLowerCase()))
|
|
675
|
+
.map(st => familyOf(st.thing)),
|
|
676
|
+
);
|
|
677
|
+
// The subject's changed values: family, direction, removal.
|
|
678
|
+
const touched = new Set([
|
|
679
|
+
...subjects,
|
|
680
|
+
...steps
|
|
681
|
+
.map(st => st.on)
|
|
682
|
+
.filter(Boolean)
|
|
683
|
+
.flatMap(x => members(String(x))),
|
|
684
|
+
]);
|
|
685
|
+
for (const part of touched) {
|
|
686
|
+
// A whole kept part is checked above, not as a subject.
|
|
687
|
+
if (keeps.some(k => k.part === part && !k.prefix)) continue;
|
|
688
|
+
const a = shown(was, tw, part);
|
|
689
|
+
const b = shown(now, tn, part);
|
|
690
|
+
for (const [k, v] of b) {
|
|
691
|
+
// A kept state or variant of the part is checked above.
|
|
692
|
+
if (
|
|
693
|
+
keeps.some(x => x.part === part && x.prefix && k.startsWith(x.prefix))
|
|
694
|
+
)
|
|
695
|
+
continue;
|
|
696
|
+
const prop = k.split('|')[2];
|
|
697
|
+
// A shorthand written where the part read longhands: its first side.
|
|
698
|
+
// (Whether the value before is the same rule's, not a stand-in.)
|
|
699
|
+
const exact = a.has(k);
|
|
700
|
+
const o =
|
|
701
|
+
a.get(k) ??
|
|
702
|
+
(prop === 'padding'
|
|
703
|
+
? (a.get(`${k.split('|')[0]}||padding-top`) ??
|
|
704
|
+
a.get('base||padding-top'))
|
|
705
|
+
: prop === 'border'
|
|
706
|
+
? a.get('base||border-width')
|
|
707
|
+
: a.get(`base||${prop}`));
|
|
708
|
+
if (o && o.light === v.light && o.dark === v.dark) continue;
|
|
709
|
+
const fam = familyOf(prop);
|
|
710
|
+
if (!fam) continue;
|
|
711
|
+
// A property a typed value writes is asked: the question wrote it.
|
|
712
|
+
const typedHere = steps.some(
|
|
713
|
+
st =>
|
|
714
|
+
typed.has(String(st.value ?? '').toLowerCase()) &&
|
|
715
|
+
familyOf(st.thing) === fam,
|
|
716
|
+
);
|
|
717
|
+
// A property Core draws from the very token a step writes (a title's
|
|
718
|
+
// margin from its heading size) moves with it: that token is asked.
|
|
719
|
+
const sameToken = steps.some(
|
|
720
|
+
st =>
|
|
721
|
+
/^--/.test(String(st.thing)) &&
|
|
722
|
+
Object.keys(GROUPS).some(g =>
|
|
723
|
+
(C.partReads(part, g) ?? []).some(
|
|
724
|
+
(/** @type {{token: string, props: string[]}} */ r) =>
|
|
725
|
+
r.token === st.thing && r.props.includes(prop),
|
|
726
|
+
),
|
|
727
|
+
) &&
|
|
728
|
+
steps.some(x => x.thing === st.thing && familyOf(x.thing) !== fam),
|
|
729
|
+
);
|
|
730
|
+
if (
|
|
731
|
+
intent.families.length &&
|
|
732
|
+
!intent.families.includes(fam) &&
|
|
733
|
+
!typedHere &&
|
|
734
|
+
!sameToken
|
|
735
|
+
)
|
|
736
|
+
return `it would also change ${part}'s ${prop}, which is not what the question asks to change`;
|
|
737
|
+
for (const mode of /** @type {const} */ (['light', 'dark'])) {
|
|
738
|
+
if (visible && mode !== visible) continue;
|
|
739
|
+
const after = v[mode];
|
|
740
|
+
const before = o?.[mode] ?? null;
|
|
741
|
+
if (
|
|
742
|
+
intent.zero &&
|
|
743
|
+
['radius', 'space', 'border', 'shadow'].includes(fam)
|
|
744
|
+
) {
|
|
745
|
+
// (Core's own composed layers, a card's ring, are no shadow of
|
|
746
|
+
// the theme's: a shadow of only those is none at rest.)
|
|
747
|
+
const own = splitTop(after, ',')
|
|
748
|
+
.map(x => x.trim())
|
|
749
|
+
.filter(
|
|
750
|
+
x =>
|
|
751
|
+
x &&
|
|
752
|
+
!/^var\(\s*--_/.test(x) &&
|
|
753
|
+
!/^(?:0(?:px)?\s+)+transparent$/i.test(x),
|
|
754
|
+
)
|
|
755
|
+
.join(', ');
|
|
756
|
+
const n = measureNumber(own);
|
|
757
|
+
if (own && !/^(none|transparent|0)$/.test(own) && n !== 0)
|
|
758
|
+
return `${part}'s ${prop} would be ${after} in ${mode} mode, not none`;
|
|
759
|
+
continue;
|
|
760
|
+
}
|
|
761
|
+
// A shadow written where the part showed none it can read is a
|
|
762
|
+
// change.
|
|
763
|
+
if (fam === 'shadow' && before == null && !/^none$/i.test(after))
|
|
764
|
+
shadowMoved = true;
|
|
765
|
+
if (before == null || typedFamilies.has(fam)) continue;
|
|
766
|
+
// A shadow's strength moves the way asked, in each mode.
|
|
767
|
+
if (fam === 'shadow' && intent.shadowDir) {
|
|
768
|
+
const x = shadowStrength(after);
|
|
769
|
+
const y = shadowStrength(before);
|
|
770
|
+
if (Math.abs(x - y) > 1e-6 && (intent.shadowDir === 'more') !== x > y)
|
|
771
|
+
return `${part}'s ${prop} would get ${intent.shadowDir === 'more' ? 'weaker' : 'stronger'} in ${mode} mode`;
|
|
772
|
+
if (shadowLook(after) !== shadowLook(before)) shadowMoved = true;
|
|
773
|
+
continue;
|
|
774
|
+
}
|
|
775
|
+
// "more transparent": the color's alpha goes down, "more opaque" up.
|
|
776
|
+
if (fam === 'color' && intent.opacityDir) {
|
|
777
|
+
const x = parseColor(after) ? alphaOf(after) : null;
|
|
778
|
+
const y = parseColor(before) ? alphaOf(before) : null;
|
|
779
|
+
if (
|
|
780
|
+
x != null &&
|
|
781
|
+
y != null &&
|
|
782
|
+
Math.abs(x - y) > 1e-3 &&
|
|
783
|
+
(intent.opacityDir === 'more') !== x > y
|
|
784
|
+
)
|
|
785
|
+
return `${part}'s ${prop} would get ${intent.opacityDir === 'more' ? 'more' : 'less'} see-through in ${mode} mode`;
|
|
786
|
+
}
|
|
787
|
+
if (fam === 'color' && intent.lighter != null) {
|
|
788
|
+
// A part's color, in every variant and state it shows (a step on
|
|
789
|
+
// the plain rule reaches the variants that take it), in each mode
|
|
790
|
+
// (or the one the question names), never an overlay layer over
|
|
791
|
+
// the fill; only the kind of color the steps write (a new fill
|
|
792
|
+
// may bring a text color that reads on it).
|
|
793
|
+
if (intent.mode && mode !== intent.mode) continue;
|
|
794
|
+
const [when] = k.split('|');
|
|
795
|
+
if (!exact) continue;
|
|
796
|
+
const kindOf = (/** @type {string} */ x) =>
|
|
797
|
+
/^background/.test(x)
|
|
798
|
+
? 'fill'
|
|
799
|
+
: /border|outline/.test(x)
|
|
800
|
+
? 'line'
|
|
801
|
+
: 'ink';
|
|
802
|
+
if (
|
|
803
|
+
!steps.some(
|
|
804
|
+
st => kindOf(st.thing.replace(/^--color-/, '')) === kindOf(prop),
|
|
805
|
+
)
|
|
806
|
+
)
|
|
807
|
+
continue;
|
|
808
|
+
if (
|
|
809
|
+
/overlay|tint/.test(String(o?.raw ?? '')) ||
|
|
810
|
+
/overlay|tint/.test(v.raw)
|
|
811
|
+
)
|
|
812
|
+
continue;
|
|
813
|
+
const x = painted(after, tn[mode], mode);
|
|
814
|
+
const y = intent.from
|
|
815
|
+
? painted(
|
|
816
|
+
resolveIn(`var(${intent.from})`, tw[mode], mode),
|
|
817
|
+
tw[mode],
|
|
818
|
+
mode,
|
|
819
|
+
)
|
|
820
|
+
: painted(before, tw[mode], mode);
|
|
821
|
+
// (A way from a theme color is that color's way, in every mode.)
|
|
822
|
+
const want =
|
|
823
|
+
mode === 'dark' &&
|
|
824
|
+
!intent.from &&
|
|
825
|
+
isForeground(prop, intent.contrast, intent.literal)
|
|
826
|
+
? !intent.lighter
|
|
827
|
+
: intent.lighter;
|
|
828
|
+
if (x && y && Math.abs(luminance(x) - luminance(y)) >= 0.5)
|
|
829
|
+
if (want !== luminance(x) > luminance(y))
|
|
830
|
+
return `${part}'s ${prop}${when !== 'base' ? ` (${when})` : ''} would get ${want ? 'darker' : 'lighter'} in ${mode} mode (${before} to ${after})`;
|
|
831
|
+
// "darker than the page": past the part compared against, in
|
|
832
|
+
// each mode it shows.
|
|
833
|
+
if (x && /^background/.test(prop))
|
|
834
|
+
for (const ref of intent.than ?? []) {
|
|
835
|
+
const refValue =
|
|
836
|
+
ref === 'page'
|
|
837
|
+
? resolveIn('var(--color-background-body)', tn[mode], mode)
|
|
838
|
+
: shown(now, tn, ref).get('base||background-color')?.[mode];
|
|
839
|
+
const r = refValue ? painted(refValue, tn[mode], mode) : null;
|
|
840
|
+
if (r && want !== luminance(x) > luminance(r))
|
|
841
|
+
return `${part}'s ${prop}${when !== 'base' ? ` (${when})` : ''} would still be ${want ? 'darker' : 'lighter'} than the ${ref} in ${mode} mode (${after} on ${refValue})`;
|
|
842
|
+
}
|
|
843
|
+
continue;
|
|
844
|
+
}
|
|
845
|
+
const dir = fam === 'opacity' ? intent.opacityDir : intent.dir;
|
|
846
|
+
if (
|
|
847
|
+
!dir ||
|
|
848
|
+
!(
|
|
849
|
+
['radius', 'border', 'weight', 'opacity', 'fontsize'].includes(
|
|
850
|
+
fam,
|
|
851
|
+
) ||
|
|
852
|
+
// A space: one length written over one read (never a shorthand).
|
|
853
|
+
(fam === 'space' &&
|
|
854
|
+
(intent.bound ||
|
|
855
|
+
(exact &&
|
|
856
|
+
steps.some(st => st.thing === prop) &&
|
|
857
|
+
!/\s/.test(after) &&
|
|
858
|
+
!/\s/.test(String(before)))))
|
|
859
|
+
)
|
|
860
|
+
)
|
|
861
|
+
continue;
|
|
862
|
+
const x = measureNumber(after);
|
|
863
|
+
const y = measureNumber(before);
|
|
864
|
+
if (x != null && y != null && x !== y && (dir === 'more') !== x > y)
|
|
865
|
+
return `${part}'s ${prop} would move the other way in ${mode} mode (${before} to ${after})`;
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
// Tokens the steps name (a dial: its main token): the same checks.
|
|
870
|
+
const DIAL_TOKEN = /** @type {Record<string, string>} */ ({
|
|
871
|
+
accent: '--color-accent',
|
|
872
|
+
danger: '--color-error',
|
|
873
|
+
success: '--color-success',
|
|
874
|
+
warning: '--color-warning',
|
|
875
|
+
info: '--color-info',
|
|
876
|
+
neutral: '--color-neutral',
|
|
877
|
+
});
|
|
878
|
+
for (const st of steps) {
|
|
879
|
+
const tok = /^--/.test(st.thing) ? st.thing : DIAL_TOKEN[st.thing];
|
|
880
|
+
if (!tok || st.on) continue;
|
|
881
|
+
const fam = familyOf(tok);
|
|
882
|
+
if (!fam) continue;
|
|
883
|
+
if (intent.families.length && !intent.families.includes(fam))
|
|
884
|
+
return `${tok} is not what the question asks to change`;
|
|
885
|
+
for (const mode of /** @type {const} */ (['light', 'dark'])) {
|
|
886
|
+
if (visible && mode !== visible) continue;
|
|
887
|
+
const after = resolveIn(`var(${tok})`, tn[mode], mode);
|
|
888
|
+
const before = resolveIn(`var(${tok})`, tw[mode], mode);
|
|
889
|
+
if (after === before) continue;
|
|
890
|
+
if (
|
|
891
|
+
intent.zero &&
|
|
892
|
+
['radius', 'space', 'border', 'shadow'].includes(fam)
|
|
893
|
+
) {
|
|
894
|
+
const n = measureNumber(after);
|
|
895
|
+
if (!/^(none|transparent|0)$/.test(after) && n !== 0)
|
|
896
|
+
return `${tok} would be ${after} in ${mode} mode, not none`;
|
|
897
|
+
continue;
|
|
898
|
+
}
|
|
899
|
+
if (typedFamilies.has(fam)) continue;
|
|
900
|
+
if (fam === 'shadow' && intent.shadowDir) {
|
|
901
|
+
const x = shadowStrength(after);
|
|
902
|
+
const y = shadowStrength(before);
|
|
903
|
+
if (Math.abs(x - y) > 1e-6 && (intent.shadowDir === 'more') !== x > y)
|
|
904
|
+
return `${tok} would get ${intent.shadowDir === 'more' ? 'weaker' : 'stronger'} in ${mode} mode`;
|
|
905
|
+
if (shadowLook(after) !== shadowLook(before)) shadowMoved = true;
|
|
906
|
+
continue;
|
|
907
|
+
}
|
|
908
|
+
if (fam === 'color' && intent.opacityDir) {
|
|
909
|
+
const x = parseColor(after) ? alphaOf(after) : null;
|
|
910
|
+
const y = parseColor(before) ? alphaOf(before) : null;
|
|
911
|
+
if (
|
|
912
|
+
x != null &&
|
|
913
|
+
y != null &&
|
|
914
|
+
Math.abs(x - y) > 1e-3 &&
|
|
915
|
+
(intent.opacityDir === 'more') !== x > y
|
|
916
|
+
)
|
|
917
|
+
return `${tok} would get ${intent.opacityDir === 'more' ? 'more' : 'less'} see-through in ${mode} mode`;
|
|
918
|
+
continue;
|
|
919
|
+
}
|
|
920
|
+
if (fam === 'color' && intent.lighter != null) {
|
|
921
|
+
if (intent.mode && mode !== intent.mode) continue;
|
|
922
|
+
const x = painted(after, tn[mode], mode);
|
|
923
|
+
const y = painted(before, tw[mode], mode);
|
|
924
|
+
const want =
|
|
925
|
+
mode === 'dark' && isForeground(tok, intent.contrast, intent.literal)
|
|
926
|
+
? !intent.lighter
|
|
927
|
+
: intent.lighter;
|
|
928
|
+
if (x && y && Math.abs(luminance(x) - luminance(y)) >= 0.5)
|
|
929
|
+
if (want !== luminance(x) > luminance(y))
|
|
930
|
+
return `${tok} would get ${want ? 'darker' : 'lighter'} in ${mode} mode (${before} to ${after})`;
|
|
931
|
+
continue;
|
|
932
|
+
}
|
|
933
|
+
const dir = fam === 'opacity' ? intent.opacityDir : intent.dir;
|
|
934
|
+
if (!dir) continue;
|
|
935
|
+
const x = measureNumber(after);
|
|
936
|
+
const y = measureNumber(before);
|
|
937
|
+
if (x != null && y != null && x !== y && (dir === 'more') !== x > y)
|
|
938
|
+
return `${tok} would move the other way in ${mode} mode (${before} to ${after})`;
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
// "more colorful", "more muted": the accent colors the theme shows (the
|
|
942
|
+
// accent and the text and icons drawn in it) move that way in saturation
|
|
943
|
+
// together, in each mode shown (a step that dulls them is not more
|
|
944
|
+
// colorful), and the accent wash, as it paints over the page, never moves
|
|
945
|
+
// the other way (a faint wash made a solid fill is not less colorful).
|
|
946
|
+
if (intent.saturation)
|
|
947
|
+
for (const mode of /** @type {Array<'light' | 'dark'>} */ (
|
|
948
|
+
visible ? [visible] : ['light', 'dark']
|
|
949
|
+
)) {
|
|
950
|
+
let x = 0;
|
|
951
|
+
let y = 0;
|
|
952
|
+
let n = 0;
|
|
953
|
+
for (const tok of Object.keys(tw[mode])) {
|
|
954
|
+
if (!/^--color-(?:text-|icon-)?accent$/.test(tok)) continue;
|
|
955
|
+
// (As it paints over the page.)
|
|
956
|
+
const a = saturationOf(
|
|
957
|
+
painted(resolveIn(`var(${tok})`, tn[mode], mode), tn[mode], mode),
|
|
958
|
+
);
|
|
959
|
+
const b = saturationOf(
|
|
960
|
+
painted(resolveIn(`var(${tok})`, tw[mode], mode), tw[mode], mode),
|
|
961
|
+
);
|
|
962
|
+
if (a == null || b == null) continue;
|
|
963
|
+
x += a;
|
|
964
|
+
y += b;
|
|
965
|
+
n++;
|
|
966
|
+
}
|
|
967
|
+
if (
|
|
968
|
+
n &&
|
|
969
|
+
(intent.saturation === 'more' ? x < y - 0.02 * n : x > y + 0.02 * n)
|
|
970
|
+
)
|
|
971
|
+
return `the accent colors would get ${intent.saturation === 'more' ? 'duller' : 'more saturated'} in ${mode} mode`;
|
|
972
|
+
const wash = (/** @type {Record<string, string>} */ t) =>
|
|
973
|
+
t['--color-accent-muted'] == null
|
|
974
|
+
? null
|
|
975
|
+
: saturationOf(
|
|
976
|
+
painted(resolveIn('var(--color-accent-muted)', t, mode), t, mode),
|
|
977
|
+
);
|
|
978
|
+
const [wa, wb] = [wash(tn[mode]), wash(tw[mode])];
|
|
979
|
+
if (
|
|
980
|
+
wa != null &&
|
|
981
|
+
wb != null &&
|
|
982
|
+
(intent.saturation === 'more' ? wa < wb - 0.02 : wa > wb + 0.02)
|
|
983
|
+
)
|
|
984
|
+
return `the accent wash (--color-accent-muted) would get ${intent.saturation === 'more' ? 'duller' : 'more saturated'} in ${mode} mode, as it paints over the page`;
|
|
985
|
+
}
|
|
986
|
+
if (!shadowMoved && steps.some(st => familyOf(st.thing) === 'shadow'))
|
|
987
|
+
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)';
|
|
988
|
+
return null;
|
|
989
|
+
}
|
|
990
|
+
|
|
212
991
|
/**
|
|
213
992
|
* Apply one step to theme data in memory, as `set` and `undo` do.
|
|
214
993
|
* @param {import('./_settings.mjs').Ctx} ctx
|
|
@@ -299,18 +1078,23 @@ export function exampleStep(example) {
|
|
|
299
1078
|
* Keep the alternatives that pass, and render them for the theme.
|
|
300
1079
|
* @param {HowTheme} env
|
|
301
1080
|
* @param {Step[][]} options each a list of steps run in order
|
|
302
|
-
* @returns {{commands: string[], refused: Array<{command: string, why: string}>}}
|
|
1081
|
+
* @returns {{commands: string[], refused: Array<{command: string, why: string, run?: string[]}>}}
|
|
303
1082
|
*/
|
|
304
1083
|
export function checked(env, options) {
|
|
305
1084
|
/** @type {string[]} */
|
|
306
1085
|
const commands = [];
|
|
307
|
-
/** @type {Array<{command: string, why: string}>} */
|
|
1086
|
+
/** @type {Array<{command: string, why: string, run?: string[]}>} */
|
|
308
1087
|
const refused = [];
|
|
309
1088
|
for (const steps of options) {
|
|
310
1089
|
const text = steps.map(st => render(st, env.slug));
|
|
311
1090
|
const r = env.check(steps);
|
|
312
1091
|
if (r.ok) commands.push(...text.filter(c => !commands.includes(c)));
|
|
313
|
-
else
|
|
1092
|
+
else
|
|
1093
|
+
refused.push({
|
|
1094
|
+
command: text.join(' && '),
|
|
1095
|
+
why: r.why,
|
|
1096
|
+
...(r.run ? {run: r.run} : {}),
|
|
1097
|
+
});
|
|
314
1098
|
}
|
|
315
1099
|
return {commands, refused};
|
|
316
1100
|
}
|