@astryxdesign/cli 0.7.16 → 0.7.17-canary.g0135e03
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 +122 -1
- package/api/theme/build/build.mjs +412 -84
- 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 +23 -3
- package/api/theme/build/font-warning.mjs +54 -5
- package/api/theme/build/icon-imports.mjs +25 -2
- package/api/theme/theme.type.d.mts +10 -0
- package/api/theme/theme.type.mjs +7 -1
- package/api/theme-edit/_adapter.d.mts +103 -3
- package/api/theme-edit/_adapter.mjs +961 -82
- package/api/theme-edit/_catalog.mjs +19 -4
- package/api/theme-edit/_check.d.mts +63 -24
- package/api/theme-edit/_check.mjs +2467 -362
- package/api/theme-edit/_color.d.mts +10 -0
- package/api/theme-edit/_color.mjs +49 -1
- package/api/theme-edit/_compiler.mjs +89 -6
- package/api/theme-edit/_context.d.mts +3 -3
- package/api/theme-edit/_context.mjs +165 -54
- package/api/theme-edit/_css.d.mts +14 -0
- package/api/theme-edit/_css.mjs +46 -1
- package/api/theme-edit/_edit.d.mts +31 -4
- package/api/theme-edit/_edit.mjs +2433 -204
- package/api/theme-edit/_how-commands.d.mts +72 -1
- package/api/theme-edit/_how-commands.mjs +759 -9
- package/api/theme-edit/_how-question.d.mts +82 -5
- package/api/theme-edit/_how-question.mjs +6473 -553
- package/api/theme-edit/_how.d.mts +2 -1
- package/api/theme-edit/_how.mjs +237 -41
- 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 +292 -0
- package/api/theme-edit/_normal.mjs +1454 -0
- package/api/theme-edit/_palette.mjs +10 -4
- package/api/theme-edit/_part-words.d.mts +31 -0
- package/api/theme-edit/_part-words.mjs +126 -0
- package/api/theme-edit/_parts.d.mts +18 -1
- package/api/theme-edit/_parts.mjs +246 -23
- package/api/theme-edit/_preview-app.d.mts +7 -1
- package/api/theme-edit/_preview-app.mjs +776 -187
- package/api/theme-edit/_preview.d.mts +100 -14
- package/api/theme-edit/_preview.mjs +582 -139
- package/api/theme-edit/_project.d.mts +4 -0
- package/api/theme-edit/_project.mjs +3 -1
- package/api/theme-edit/_settings.d.mts +417 -42
- package/api/theme-edit/_settings.mjs +3262 -424
- package/api/theme-edit/_tables.d.mts +15 -0
- package/api/theme-edit/_tables.mjs +63 -1
- package/api/theme-edit/_vet.d.mts +20 -0
- package/api/theme-edit/_vet.mjs +47 -2
- 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 +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/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 +358 -63
- 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 +317 -47
- 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 +92 -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 +53 -1
- package/foundation/discovery/template-adapter.mjs +176 -12
- package/foundation/discovery/template-icons.mjs +2 -1
- package/foundation/discovery/theme-discovery.mjs +31 -4
- 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/exact-codec.d.mts +12 -2
- package/foundation/fs/exact-codec.mjs +23 -6
- package/foundation/fs/file-protection.mjs +4 -3
- package/foundation/fs/gather-cache.d.mts +62 -4
- package/foundation/fs/gather-cache.mjs +512 -91
- 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/fs/read-record.d.mts +9 -0
- package/foundation/fs/read-record.mjs +19 -11
- 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/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 +641 -96
- 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
|
@@ -12,10 +12,9 @@
|
|
|
12
12
|
import {AstryxError} from '../error.mjs';
|
|
13
13
|
import * as fs from 'node:fs';
|
|
14
14
|
import * as path from 'node:path';
|
|
15
|
-
import {partForWord} from './
|
|
15
|
+
import {partForWord} from './_part-words.mjs';
|
|
16
16
|
import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
|
|
17
17
|
import {baseInstalled, baseThemeFile, installLine} from './_project.mjs';
|
|
18
|
-
import {levenshteinDistance} from '../../foundation/text/levenshtein.mjs';
|
|
19
18
|
import {
|
|
20
19
|
withFallbacks,
|
|
21
20
|
MATH_FUNCTION,
|
|
@@ -32,9 +31,11 @@ import {
|
|
|
32
31
|
numbersIn,
|
|
33
32
|
propertyGrammar,
|
|
34
33
|
takesPercentage,
|
|
34
|
+
sameKindValues,
|
|
35
35
|
} from './_css.mjs';
|
|
36
36
|
import {calcVars, coreFallback, multipliedTokens} from './_parts.mjs';
|
|
37
37
|
import {
|
|
38
|
+
MODE_WORDS,
|
|
38
39
|
AUTO_SPREAD,
|
|
39
40
|
COLOR_PROP_PARTS,
|
|
40
41
|
COLOR_PROPS,
|
|
@@ -61,6 +62,8 @@ import {
|
|
|
61
62
|
wordTable,
|
|
62
63
|
WRAPPED_PARTS,
|
|
63
64
|
CARD_LIKE,
|
|
65
|
+
isSystemFamily,
|
|
66
|
+
fontStack,
|
|
64
67
|
} from './_tables.mjs';
|
|
65
68
|
import {
|
|
66
69
|
COLOR_NAMES,
|
|
@@ -85,27 +88,86 @@ import {
|
|
|
85
88
|
camel,
|
|
86
89
|
kebab,
|
|
87
90
|
nearest,
|
|
88
|
-
|
|
91
|
+
negates,
|
|
89
92
|
partsOf,
|
|
90
93
|
refuse,
|
|
91
94
|
lengthPx,
|
|
92
95
|
radiusAt,
|
|
93
96
|
radiusTokenOf,
|
|
97
|
+
cornerParts,
|
|
94
98
|
focusStateOf,
|
|
95
99
|
valueProblem,
|
|
96
100
|
partComponentDocs,
|
|
97
101
|
themeFiles,
|
|
98
102
|
ownSourceTokenValues,
|
|
99
103
|
baseTopTokens,
|
|
104
|
+
baseComponent,
|
|
100
105
|
baseComponentReads,
|
|
101
106
|
partRuleTokens,
|
|
102
107
|
cssFamily,
|
|
103
108
|
familySpaces,
|
|
109
|
+
baseTextPx,
|
|
110
|
+
fontsourcePackageOf,
|
|
111
|
+
dialWordOf,
|
|
112
|
+
paddedParts,
|
|
113
|
+
onBuiltIn,
|
|
104
114
|
} from './_settings.mjs';
|
|
115
|
+
import {isColorToken} from './_compiler.mjs';
|
|
116
|
+
import {
|
|
117
|
+
trimInsideQuotes,
|
|
118
|
+
colorPair,
|
|
119
|
+
otherSettingLabel,
|
|
120
|
+
familiesOf,
|
|
121
|
+
familyPieces,
|
|
122
|
+
normalValueText,
|
|
123
|
+
normalizeEntry,
|
|
124
|
+
withoutDebris,
|
|
125
|
+
typoOf,
|
|
126
|
+
typoNear,
|
|
127
|
+
modeWord,
|
|
128
|
+
documentTypoWords,
|
|
129
|
+
PROPERTY_WORDS,
|
|
130
|
+
WEIGHT_WORDS,
|
|
131
|
+
TAILWIND_RADIUS,
|
|
132
|
+
documentReadings,
|
|
133
|
+
documentNumericTable,
|
|
134
|
+
documentRange,
|
|
135
|
+
withoutCopyDebris,
|
|
136
|
+
commaNumbers,
|
|
137
|
+
weightSetting,
|
|
138
|
+
} from './_normal.mjs';
|
|
139
|
+
|
|
140
|
+
export {
|
|
141
|
+
familiesOf,
|
|
142
|
+
familyPieces,
|
|
143
|
+
normalValueText,
|
|
144
|
+
normalizeEntry,
|
|
145
|
+
withoutDebris,
|
|
146
|
+
};
|
|
105
147
|
import {quoteCommandArgument} from '../../foundation/env/package-manager.mjs';
|
|
106
148
|
|
|
107
149
|
export {lengthPx};
|
|
108
150
|
|
|
151
|
+
/**
|
|
152
|
+
* The radius the base theme's own rule gives a part, in px, or null when
|
|
153
|
+
* its rule gives none.
|
|
154
|
+
* @param {any} ctx
|
|
155
|
+
* @param {{light: Record<string, string>}} base
|
|
156
|
+
* @param {string} part
|
|
157
|
+
* @param {string | undefined} when
|
|
158
|
+
* @returns {number | null}
|
|
159
|
+
*/
|
|
160
|
+
function basePartRadiusPx(ctx, base, part, when) {
|
|
161
|
+
const own = ctx.base
|
|
162
|
+
? baseComponent(ctx.base, ctx, part, 'borderRadius', {when})
|
|
163
|
+
: null;
|
|
164
|
+
if (typeof own !== 'string') return null;
|
|
165
|
+
const tokenName = /var\(\s*(--radius-[\w-]+)/.exec(own)?.[1];
|
|
166
|
+
if (tokenName) return tokenPx(base, tokenName);
|
|
167
|
+
const px = lengthPx(own);
|
|
168
|
+
return px == null ? null : Math.min(px, 9999);
|
|
169
|
+
}
|
|
170
|
+
|
|
109
171
|
/**
|
|
110
172
|
* A token's value in px, following var() references through the tokens.
|
|
111
173
|
* @param {{light: Record<string, string>}} base
|
|
@@ -122,6 +184,13 @@ function tokenPx(base, token) {
|
|
|
122
184
|
return lengthPx(v);
|
|
123
185
|
}
|
|
124
186
|
|
|
187
|
+
// A type scale ratio is a number above 1, up to 2.
|
|
188
|
+
documentNumericTable(
|
|
189
|
+
['type'],
|
|
190
|
+
Object.entries(TYPE_STYLES).map(([name, style]) => [name, style.ratio]),
|
|
191
|
+
[1, 2],
|
|
192
|
+
);
|
|
193
|
+
|
|
125
194
|
/**
|
|
126
195
|
* The `type` preset nearest a scale ratio typed as a number (1.3 is
|
|
127
196
|
* editorial), or null for a number that is no ratio (16).
|
|
@@ -154,6 +223,108 @@ const cornerPxOf = v =>
|
|
|
154
223
|
|
|
155
224
|
const E = ERROR_CODES;
|
|
156
225
|
|
|
226
|
+
/**
|
|
227
|
+
* Why the math in a value's calc() cannot work, or null: each `+`/`-`
|
|
228
|
+
* needs two sides of one kind (a length with a length or a percentage, a
|
|
229
|
+
* number with a number), `*` needs a plain number on one side, `/` a plain
|
|
230
|
+
* number on the right. A var() counts as its fallback; one with none, or a
|
|
231
|
+
* nested min(), max() or clamp(), is not judged.
|
|
232
|
+
* @param {string} value
|
|
233
|
+
* @returns {string | null}
|
|
234
|
+
*/
|
|
235
|
+
export function calcUnitProblem(value) {
|
|
236
|
+
const text = String(value);
|
|
237
|
+
const re = /\bcalc\(/gi;
|
|
238
|
+
let m;
|
|
239
|
+
while ((m = re.exec(text))) {
|
|
240
|
+
const open = m.index + m[0].length - 1;
|
|
241
|
+
const close = matchingParen(text, open);
|
|
242
|
+
if (close < 0) return null;
|
|
243
|
+
let expr = text.slice(open + 1, close);
|
|
244
|
+
// Each var() is its fallback, innermost first.
|
|
245
|
+
for (let i = 0; i < 20 && /\bvar\(/i.test(expr); i += 1) {
|
|
246
|
+
const at = expr.search(/\bvar\((?:[^()]|\([^()]*\))*\)/i);
|
|
247
|
+
const v = /\bvar\(((?:[^()]|\([^()]*\))*)\)/i.exec(expr.slice(at));
|
|
248
|
+
if (at < 0 || !v) return null;
|
|
249
|
+
const comma = v[1].indexOf(',');
|
|
250
|
+
if (comma < 0) return null;
|
|
251
|
+
expr = `${expr.slice(0, at)}(${v[1].slice(comma + 1).trim()})${expr.slice(at + v[0].length)}`;
|
|
252
|
+
}
|
|
253
|
+
if (/[a-z-]+\(/i.test(expr.replace(/\bcalc\(/gi, '('))) continue;
|
|
254
|
+
const found = expr.match(/\d*\.?\d+(?:e[+-]?\d+)?[a-z%]*|[-+*/()]/gi);
|
|
255
|
+
if (!found) continue;
|
|
256
|
+
const tokens = found;
|
|
257
|
+
let pos = 0;
|
|
258
|
+
/** @returns {string | null} */
|
|
259
|
+
const kindOf = (/** @type {string} */ t) => {
|
|
260
|
+
const u = /[a-z%]*$/i.exec(t)?.[0].toLowerCase() ?? '';
|
|
261
|
+
if (!u) return 'number';
|
|
262
|
+
if (u === '%') return 'percent';
|
|
263
|
+
if (/^(m?s)$/.test(u)) return 'time';
|
|
264
|
+
if (/^(deg|rad|grad|turn)$/.test(u)) return 'angle';
|
|
265
|
+
return 'length';
|
|
266
|
+
};
|
|
267
|
+
/** @type {string | null} */
|
|
268
|
+
let why = null;
|
|
269
|
+
const fail = (/** @type {string} */ w) => {
|
|
270
|
+
why ??= w;
|
|
271
|
+
return 'number';
|
|
272
|
+
};
|
|
273
|
+
const join = (
|
|
274
|
+
/** @type {string} */ a,
|
|
275
|
+
/** @type {string} */ b,
|
|
276
|
+
/** @type {string} */ op,
|
|
277
|
+
) => {
|
|
278
|
+
if (op === '+' || op === '-') {
|
|
279
|
+
if (a === b) return a;
|
|
280
|
+
const lp = new Set([a, b]);
|
|
281
|
+
if (lp.has('length') && lp.has('percent') && lp.size === 2)
|
|
282
|
+
return 'length';
|
|
283
|
+
return fail(`${a} ${op} ${b} adds two kinds of value`);
|
|
284
|
+
}
|
|
285
|
+
if (op === '*') {
|
|
286
|
+
if (a === 'number') return b;
|
|
287
|
+
if (b === 'number') return a;
|
|
288
|
+
return fail(`${a} * ${b} multiplies two values with units`);
|
|
289
|
+
}
|
|
290
|
+
if (b === 'number') return a;
|
|
291
|
+
return fail(`${a} / ${b} divides by a value with a unit`);
|
|
292
|
+
};
|
|
293
|
+
/** @returns {string} */
|
|
294
|
+
const factor = () => {
|
|
295
|
+
const t = tokens[pos++];
|
|
296
|
+
if (t === '(') {
|
|
297
|
+
const k = sum();
|
|
298
|
+
pos++;
|
|
299
|
+
return k;
|
|
300
|
+
}
|
|
301
|
+
if (t === '-' || t === '+') return factor();
|
|
302
|
+
return t == null ? 'number' : (kindOf(t) ?? 'number');
|
|
303
|
+
};
|
|
304
|
+
/** @returns {string} */
|
|
305
|
+
const product = () => {
|
|
306
|
+
let k = factor();
|
|
307
|
+
while (tokens[pos] === '*' || tokens[pos] === '/') {
|
|
308
|
+
const op = tokens[pos++];
|
|
309
|
+
k = join(k, factor(), op);
|
|
310
|
+
}
|
|
311
|
+
return k;
|
|
312
|
+
};
|
|
313
|
+
/** @returns {string} */
|
|
314
|
+
function sum() {
|
|
315
|
+
let k = product();
|
|
316
|
+
while (tokens[pos] === '+' || tokens[pos] === '-') {
|
|
317
|
+
const op = tokens[pos++];
|
|
318
|
+
k = join(k, product(), op);
|
|
319
|
+
}
|
|
320
|
+
return k;
|
|
321
|
+
}
|
|
322
|
+
sum();
|
|
323
|
+
if (why) return why;
|
|
324
|
+
}
|
|
325
|
+
return null;
|
|
326
|
+
}
|
|
327
|
+
|
|
157
328
|
/**
|
|
158
329
|
* The fallbacks of the var() calls inside a value that is not one var()
|
|
159
330
|
* alone (`calc(var(--x, 4px) * 2)`), in order. A var() with an empty
|
|
@@ -227,6 +398,25 @@ function matchingParen(text, open) {
|
|
|
227
398
|
return -1;
|
|
228
399
|
}
|
|
229
400
|
|
|
401
|
+
/** A yes or no word, which `rounded` reads as round or square. */
|
|
402
|
+
const YES_NO = /^(true|yes|on|none|false|off|no)$/i;
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* A value as the corners dial reads it: a rung in any case, or a size with
|
|
406
|
+
* its unit (`10PX`, `1rem`) in px; null for anything else, a bare number
|
|
407
|
+
* included.
|
|
408
|
+
* @param {string} v
|
|
409
|
+
* @returns {string | null}
|
|
410
|
+
*/
|
|
411
|
+
function cornersRead(v) {
|
|
412
|
+
const lower = String(v).trim().toLowerCase();
|
|
413
|
+
if (CORNERS.some(([n]) => n === lower)) return lower;
|
|
414
|
+
if (/^(0|none|sharp|zero|flat)$/.test(lower)) return 'square';
|
|
415
|
+
if (/^[+-]?\d*\.?\d+$/.test(lower)) return null;
|
|
416
|
+
const px = lengthPx(lower);
|
|
417
|
+
return px != null && px >= 0 ? `${Math.round(px * 100) / 100}px` : null;
|
|
418
|
+
}
|
|
419
|
+
|
|
230
420
|
/**
|
|
231
421
|
* A text size written another way (20px, 2e1, +20, 1.25rem, 125%, `20 px`,
|
|
232
422
|
* `1,25rem`) as the body size in pixels text-size takes, kept to its 10 to
|
|
@@ -235,13 +425,55 @@ function matchingParen(text, open) {
|
|
|
235
425
|
* @returns {number | null}
|
|
236
426
|
*/
|
|
237
427
|
function textSizePx(v) {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
.replace(
|
|
428
|
+
// Paste debris around the size (quotes, `!important`, a trailing `;` or
|
|
429
|
+
// `,`) is not part of it.
|
|
430
|
+
const bare = withoutDebris(
|
|
431
|
+
String(v)
|
|
432
|
+
.replace(/^\s*(["'])(.*)\1\s*$/, '$2')
|
|
433
|
+
.replace(/\s*!\s*important\s*/i, '')
|
|
434
|
+
.replace(/[;,]+\s*$/, ''),
|
|
243
435
|
);
|
|
436
|
+
const plain = typedPlain(bare)
|
|
437
|
+
.replace(/(\d)\.(?=[a-z%]*$)/i, '$1')
|
|
438
|
+
// A unit split off by a space (`16 px`), and the spaces of a math
|
|
439
|
+
// function (`calc(1rem + 2px)`); two numbers stay two.
|
|
440
|
+
.replace(/(\d)\s+(?=[a-z%])/gi, '$1')
|
|
441
|
+
.replace(/\s*([*/+()-])\s*/g, '$1')
|
|
442
|
+
.replace(/^(\d+),(\d+)/, '$1.$2');
|
|
443
|
+
// A constant calc() of px and rem sizes (`calc(16px + 2px)`) is worked out.
|
|
444
|
+
const calc =
|
|
445
|
+
/^calc\((\d*\.?\d+)(px|rem|em)?([*/+-])(\d*\.?\d+)(px|rem|em)?\)$/i.exec(
|
|
446
|
+
plain,
|
|
447
|
+
);
|
|
448
|
+
if (calc) {
|
|
449
|
+
const px = (/** @type {string} */ n, /** @type {string | undefined} */ u) =>
|
|
450
|
+
Number(n) * (u && /r?em/i.test(u) ? 16 : 1);
|
|
451
|
+
const [a, b] = [px(calc[1], calc[2]), px(calc[4], calc[5])];
|
|
452
|
+
const op = calc[3];
|
|
453
|
+
// Sizes add and subtract; a size scales by a plain number.
|
|
454
|
+
const r =
|
|
455
|
+
op === '+' || op === '-'
|
|
456
|
+
? calc[2] && calc[5]
|
|
457
|
+
? op === '+'
|
|
458
|
+
? a + b
|
|
459
|
+
: a - b
|
|
460
|
+
: null
|
|
461
|
+
: op === '*'
|
|
462
|
+
? calc[2] && calc[5]
|
|
463
|
+
? null
|
|
464
|
+
: a * b
|
|
465
|
+
: calc[5]
|
|
466
|
+
? null
|
|
467
|
+
: a / b;
|
|
468
|
+
return r != null && Number.isFinite(r) && r >= 10 && r <= 32
|
|
469
|
+
? Math.round(r * 100) / 100
|
|
470
|
+
: null;
|
|
471
|
+
}
|
|
472
|
+
const m = /^\+?(\d*\.?\d+(?:e[+-]?\d+)?)(px|rem|em|pt|%)?$/i.exec(plain);
|
|
244
473
|
if (!m) return null;
|
|
474
|
+
// A bare number under 4 (1.5, 1.125) reads as rem as much as px: no
|
|
475
|
+
// size is guessed for it.
|
|
476
|
+
if (!m[2] && Number(m[1]) < 4) return null;
|
|
245
477
|
const unit = (m[2] ?? '').toLowerCase();
|
|
246
478
|
const n =
|
|
247
479
|
Number(m[1]) *
|
|
@@ -334,6 +566,8 @@ function valueMeant(type, value) {
|
|
|
334
566
|
.replace(/\s*!\s*important\s*$/i, '')
|
|
335
567
|
.replace(/;+\s*$/, '')
|
|
336
568
|
.trim();
|
|
569
|
+
// Copy debris around it (a trailing comma, a stray quote or bracket).
|
|
570
|
+
p = withoutDebris(p).trim();
|
|
337
571
|
const q = /^(["'])(.*)\1$/.exec(p);
|
|
338
572
|
if (q && type !== 'font') p = q[2].trim();
|
|
339
573
|
const out = [p];
|
|
@@ -344,13 +578,14 @@ function valueMeant(type, value) {
|
|
|
344
578
|
if (type === 'font' || type === 'font-family') {
|
|
345
579
|
// A comma left out between families (`"Open Sans" serif`), read with
|
|
346
580
|
// css-tree.
|
|
581
|
+
// The stack read as families (a trailing comma, a stack wrapped in one
|
|
582
|
+
// more pair of quotes), each quoted as CSS needs it.
|
|
583
|
+
const fams = familiesOf(p);
|
|
584
|
+
// A number or size is no family: never quoted into one (`"700"`).
|
|
585
|
+
if (fams?.length && !fams.some(f => NUMBERISH.test(f)))
|
|
586
|
+
out.push(fams.map(f => cssFamily(f, true)).join(', '));
|
|
347
587
|
const listed = familyListMeant(p);
|
|
348
|
-
if (listed) out.push(listed);
|
|
349
|
-
// Each family quoted as CSS needs it, only when no family holds a
|
|
350
|
-
// quote inside (the pieces are whole names).
|
|
351
|
-
const pieces = p.split(',').map(f => f.trim().replace(/^["']|["']$/g, ''));
|
|
352
|
-
if (!listed && pieces.every(f => !/["'\\]/.test(f)))
|
|
353
|
-
out.push(pieces.map(f => cssFamily(f, true)).join(', '));
|
|
588
|
+
if (listed && !fams?.length) out.push(listed);
|
|
354
589
|
}
|
|
355
590
|
return [...new Set(out)].filter(x => x && x !== value.trim());
|
|
356
591
|
}
|
|
@@ -391,8 +626,12 @@ function sizeMeant(v, ok) {
|
|
|
391
626
|
n,
|
|
392
627
|
n.replace(/(\d)\.(?=[a-z%]|$)/gi, '$1'),
|
|
393
628
|
t.replace(/(\d)\.(?=[a-z%]|$)/gi, '$1'),
|
|
394
|
-
|
|
395
|
-
|
|
629
|
+
// A unit split off by a space (`16 px`); two numbers (`12 16px`) are
|
|
630
|
+
// never joined into one.
|
|
631
|
+
t.replace(/(\d)\s+(?=[a-z%])/gi, '$1'),
|
|
632
|
+
t
|
|
633
|
+
.replace(/^([+-]?\d+),(\d+)/, '$1.$2')
|
|
634
|
+
.replace(/(\d)\s+(?=[a-z%])/gi, '$1'),
|
|
396
635
|
mathSpaced(t),
|
|
397
636
|
];
|
|
398
637
|
const m = /^([+-]?\d*\.?\d+)\s*([a-z%]+)$/i.exec(
|
|
@@ -430,7 +669,7 @@ function mathSpaced(v) {
|
|
|
430
669
|
function numberMeant(v, name, ok) {
|
|
431
670
|
const t = v.trim();
|
|
432
671
|
const plain = typedPlain(t).replace(/(\d)\.$/, '$1');
|
|
433
|
-
const comma = plain
|
|
672
|
+
const comma = commaNumbers(plain, weightSetting(name));
|
|
434
673
|
const tries = [
|
|
435
674
|
/^[\doO.]+$/.test(plain) && /\d/.test(plain)
|
|
436
675
|
? plain.replace(/[oO]/g, '0')
|
|
@@ -590,6 +829,22 @@ export function storedProblems(ctx, slug, data, skip = '') {
|
|
|
590
829
|
return scope(`${s.thing} applies to the whole theme, not to ${s.on}`);
|
|
591
830
|
if (s.mode && s.source === 'dial' && !PALETTE_DIALS.includes(s.thing))
|
|
592
831
|
return scope(`${s.thing} is the same in light and dark`);
|
|
832
|
+
// A light and a dark pair saved for one mode (a hand edit): set
|
|
833
|
+
// refuses that, so the loader does too; the repair is the half saved
|
|
834
|
+
// for that mode.
|
|
835
|
+
if (s.mode && /^\s*light-dark\(/i.test(String(s.value ?? ''))) {
|
|
836
|
+
const pair = colorPair(
|
|
837
|
+
String(s.value)
|
|
838
|
+
.trim()
|
|
839
|
+
.replace(/^light-dark\(\s*([\s\S]*)\)\s*$/i, 'light: $1')
|
|
840
|
+
.replace(/,\s*/, '; dark: '),
|
|
841
|
+
);
|
|
842
|
+
return {
|
|
843
|
+
setting: s,
|
|
844
|
+
why: `${s.thing} gives both modes with light-dark(), and is saved for ${s.mode} only`,
|
|
845
|
+
...(pair ? {fix: s.mode === 'dark' ? pair.dark : pair.light} : {}),
|
|
846
|
+
};
|
|
847
|
+
}
|
|
593
848
|
if (t && s.state && ![...t.states, ...COMMON_STATES].includes(s.state))
|
|
594
849
|
return scope(`"${s.state}" is not a state of ${s.on}`);
|
|
595
850
|
if (t && s.when) {
|
|
@@ -648,13 +903,45 @@ export function storedProblems(ctx, slug, data, skip = '') {
|
|
|
648
903
|
// it.
|
|
649
904
|
for (const s of data.settings) {
|
|
650
905
|
if (replaced(s) || typeof s.value !== 'string') continue;
|
|
651
|
-
|
|
652
|
-
|
|
906
|
+
// Read as typed input is (a font family's quotes trimmed too), so the
|
|
907
|
+
// line offered is the value set would save.
|
|
908
|
+
const clean = /font/i.test(s.thing)
|
|
909
|
+
? trimInsideQuotes(normalValueText(s.value))
|
|
910
|
+
: normalValueText(s.value);
|
|
911
|
+
if (clean !== s.value) {
|
|
912
|
+
// Name what is wrong: invisible spaces, or quotes around the value
|
|
913
|
+
// CSS does not read (a curly quote inside a quoted string is fine,
|
|
914
|
+
// and is left as it is).
|
|
915
|
+
const spaces =
|
|
916
|
+
clean.replace(/["']/g, '') !==
|
|
917
|
+
s.value.replace(
|
|
918
|
+
/[\u2018-\u201F\u00AB\u00BB\u2039\u203A\u300C-\u300F\uFF02\uFF07`"']/g,
|
|
919
|
+
'',
|
|
920
|
+
);
|
|
921
|
+
const quotes =
|
|
922
|
+
/[\u2018-\u201F\u00AB\u00BB\u2039\u203A\u300C-\u300F\uFF02\uFF07`]/.test(
|
|
923
|
+
s.value,
|
|
924
|
+
) &&
|
|
925
|
+
clean.replace(
|
|
926
|
+
/[\u00A0\u1680\u2000-\u200A\u202F\u205F\u3000\u200B-\u200D\u2060\uFEFF]/g,
|
|
927
|
+
'',
|
|
928
|
+
) !==
|
|
929
|
+
s.value.replace(
|
|
930
|
+
/[\u00A0\u1680\u2000-\u200A\u202F\u205F\u3000\u200B-\u200D\u2060\uFEFF]/g,
|
|
931
|
+
'',
|
|
932
|
+
);
|
|
933
|
+
const why = [
|
|
934
|
+
spaces &&
|
|
935
|
+
'a no-break, thin or zero-width space, which the browser does not read as a space',
|
|
936
|
+
quotes &&
|
|
937
|
+
'curly or other quotes around a value, where CSS reads only straight ones',
|
|
938
|
+
].filter(Boolean);
|
|
653
939
|
found.push({
|
|
654
940
|
setting: s,
|
|
655
|
-
why: `${s.thing} holds
|
|
941
|
+
why: `${s.thing} holds ${why.join(', and ') || 'characters the browser does not read as written'}`,
|
|
656
942
|
fix: clean,
|
|
657
943
|
});
|
|
944
|
+
}
|
|
658
945
|
}
|
|
659
946
|
for (const s of data.settings) {
|
|
660
947
|
if (s.source !== 'token' || s.thing === skipThing || !(s.thing in TOKENS))
|
|
@@ -700,6 +987,357 @@ export function storedProblems(ctx, slug, data, skip = '') {
|
|
|
700
987
|
return found;
|
|
701
988
|
}
|
|
702
989
|
|
|
990
|
+
/** The generic families a font list ends with. */
|
|
991
|
+
const GENERIC_FAMILIES = [
|
|
992
|
+
'serif',
|
|
993
|
+
'sans-serif',
|
|
994
|
+
'monospace',
|
|
995
|
+
'system-ui',
|
|
996
|
+
'cursive',
|
|
997
|
+
'fantasy',
|
|
998
|
+
'ui-serif',
|
|
999
|
+
'ui-sans-serif',
|
|
1000
|
+
'ui-monospace',
|
|
1001
|
+
'ui-rounded',
|
|
1002
|
+
];
|
|
1003
|
+
documentTypoWords(GENERIC_FAMILIES);
|
|
1004
|
+
documentTypoWords([...Object.keys(FONTS), ...Object.keys(OPEN_FONTS)]);
|
|
1005
|
+
|
|
1006
|
+
/** The theme-wide dial or token for a CSS property typed with no part. */
|
|
1007
|
+
const WHOLE_THEME_EQUIVALENT = /** @type {Record<string, string>} */ ({
|
|
1008
|
+
'border-radius': 'corners',
|
|
1009
|
+
'font-size': 'text-size',
|
|
1010
|
+
'font-family': 'font',
|
|
1011
|
+
color: '--color-text-primary',
|
|
1012
|
+
background: '--color-background-body',
|
|
1013
|
+
'background-color': '--color-background-body',
|
|
1014
|
+
});
|
|
1015
|
+
|
|
1016
|
+
/** A number or a size, which is never a font family. */
|
|
1017
|
+
const NUMBERISH = /^[+-]?(\d+\.?\d*|\.\d+)(px|rem|em|pt|%)?$/i;
|
|
1018
|
+
|
|
1019
|
+
/**
|
|
1020
|
+
* What is wrong with a typed family list, or null. Each family of the list
|
|
1021
|
+
* is read on its own, from its end:
|
|
1022
|
+
* - a size (`18px`, `Inter 16px`) is no family; a number is a weight only
|
|
1023
|
+
* as a whole hundred (100 to 1000), and any other bare number
|
|
1024
|
+
* (`Lato, 16`) is neither a weight nor a family;
|
|
1025
|
+
* - a weight (`600`, `ExtraBold`, `extra bold`, any form the weight table
|
|
1026
|
+
* reads) or a style (`Italic`, `Oblique`) after a family's name is that
|
|
1027
|
+
* family and the weight or style; a weight or style WORD is part of the
|
|
1028
|
+
* name unless the whole name is no family the editor knows and the name
|
|
1029
|
+
* without it is (knownFamily: `Arial Black` and `Segoe UI Semibold` are
|
|
1030
|
+
* families; `Inter ExtraBold` and `Inter Italic` are Inter and a word);
|
|
1031
|
+
* - a generic in quotes (`'sans-serif'`) is a family named so, and a
|
|
1032
|
+
* family the editor does not know that is a typo of a generic
|
|
1033
|
+
* (`sansserif`, `serf`, `system ui`) is that generic;
|
|
1034
|
+
* - with `presets` (the font dial), a lone family that is a typo of a
|
|
1035
|
+
* preset (`sytem`, `robto`) is that preset.
|
|
1036
|
+
* Only weight, style and size words (`16px bold`, `italic bold`) are a font
|
|
1037
|
+
* shorthand, read where the font dial reads one: null. `families` is the
|
|
1038
|
+
* list meant (empty when no family is left), `rung` the headings weight
|
|
1039
|
+
* nearest a weight given, `textSize` the text-size a size reads as, and
|
|
1040
|
+
* `style` a style given.
|
|
1041
|
+
* @param {string} value
|
|
1042
|
+
* @param {any} ctx
|
|
1043
|
+
* @param {boolean} [presets] whether a preset name is read (the font dial)
|
|
1044
|
+
* @returns {{why: string, families: string, rung: string | null, size: boolean, textSize: number | null, style: string | null} | null}
|
|
1045
|
+
*/
|
|
1046
|
+
function fontListProblem(value, ctx, presets = false) {
|
|
1047
|
+
// Copy debris (a trailing `;`, `!important`, a comment) is read away
|
|
1048
|
+
// first, as it is for any value.
|
|
1049
|
+
const pieces = familyPieces(withoutCopyDebris(pastedFont(value) ?? value));
|
|
1050
|
+
if (!pieces) return null;
|
|
1051
|
+
const weightOf = (/** @type {string} */ w) => {
|
|
1052
|
+
const k = w.toLowerCase().replace(/[\s_-]+/g, '');
|
|
1053
|
+
// A weight number is a whole hundred (Source Serif 4 is a family).
|
|
1054
|
+
return /^\d{3,4}$/.test(k) && Number(k) % 100 === 0 && Number(k) <= 1000
|
|
1055
|
+
? Number(k)
|
|
1056
|
+
: HEADING_WEIGHTS[k] !== undefined
|
|
1057
|
+
? Number(HEADING_WEIGHTS[k])
|
|
1058
|
+
: WEIGHT_WORDS[k] !== undefined
|
|
1059
|
+
? Number(WEIGHT_WORDS[k])
|
|
1060
|
+
: null;
|
|
1061
|
+
};
|
|
1062
|
+
const STYLE = /^(italic|oblique)$/i;
|
|
1063
|
+
const bare = (/** @type {string} */ w) =>
|
|
1064
|
+
w.toLowerCase().replace(/[\s_-]+/g, '');
|
|
1065
|
+
/** The generic a family the editor does not know is a typo of. */
|
|
1066
|
+
const genericOf = (/** @type {string} */ name) => {
|
|
1067
|
+
// Written with no dash or a space (sansserif, system ui): that generic.
|
|
1068
|
+
const exact = GENERIC_FAMILIES.find(g => bare(g) === bare(name));
|
|
1069
|
+
if (exact) return exact;
|
|
1070
|
+
const hits = GENERIC_FAMILIES.filter(g => typoNear(name.toLowerCase(), g));
|
|
1071
|
+
return hits.length === 1 ? hits[0] : null;
|
|
1072
|
+
};
|
|
1073
|
+
|
|
1074
|
+
/** @type {string[]} */
|
|
1075
|
+
const kept = [];
|
|
1076
|
+
/** @type {number | null} */
|
|
1077
|
+
let weight = null;
|
|
1078
|
+
let number = false;
|
|
1079
|
+
let size = false;
|
|
1080
|
+
/** @type {string | null} */
|
|
1081
|
+
let sizeTyped = null;
|
|
1082
|
+
/** @type {string | null} */
|
|
1083
|
+
let style = null;
|
|
1084
|
+
let quotedGeneric = false;
|
|
1085
|
+
let misspelled = false;
|
|
1086
|
+
for (const p of pieces) {
|
|
1087
|
+
const name = p.name.trim();
|
|
1088
|
+
if (!name) continue;
|
|
1089
|
+
if (p.quoted) {
|
|
1090
|
+
if (GENERIC_FAMILIES.includes(name.toLowerCase())) {
|
|
1091
|
+
quotedGeneric = true;
|
|
1092
|
+
kept.push(name.toLowerCase());
|
|
1093
|
+
} else kept.push(/[^a-z0-9-]/i.test(name) ? JSON.stringify(name) : name);
|
|
1094
|
+
continue;
|
|
1095
|
+
}
|
|
1096
|
+
// A number or size alone is read where the setting reads one (a
|
|
1097
|
+
// size for text-size, a weight for headings); in a list of several it
|
|
1098
|
+
// is a family that is not one.
|
|
1099
|
+
if (NUMBERISH.test(name)) {
|
|
1100
|
+
if (pieces.length < 2) return null;
|
|
1101
|
+
if (/[a-z%]$/i.test(name)) {
|
|
1102
|
+
size = true;
|
|
1103
|
+
sizeTyped ??= name;
|
|
1104
|
+
} else if (weightOf(name) != null) weight ??= weightOf(name);
|
|
1105
|
+
else number = true;
|
|
1106
|
+
continue;
|
|
1107
|
+
}
|
|
1108
|
+
// A preset named by its key on the font dial (dm-sans, mono) is that
|
|
1109
|
+
// preset.
|
|
1110
|
+
const PRESETS = [...Object.keys(FONTS), ...Object.keys(OPEN_FONTS)];
|
|
1111
|
+
if (presets && PRESETS.includes(name.toLowerCase())) {
|
|
1112
|
+
kept.push(name);
|
|
1113
|
+
continue;
|
|
1114
|
+
}
|
|
1115
|
+
// A family the editor knows is that family, whatever its last word
|
|
1116
|
+
// (Arial Black, Source Serif 4).
|
|
1117
|
+
if (knownFamily(ctx, name)) {
|
|
1118
|
+
kept.push(name);
|
|
1119
|
+
continue;
|
|
1120
|
+
}
|
|
1121
|
+
// Weight, style, size and number words after the name, read from the
|
|
1122
|
+
// end; a weight of two words (extra bold) first.
|
|
1123
|
+
const words = name.split(/\s+/);
|
|
1124
|
+
let end = words.length;
|
|
1125
|
+
/** @type {Array<{kind: string, text: string, value?: number}>} */
|
|
1126
|
+
const tail = [];
|
|
1127
|
+
while (end > 0) {
|
|
1128
|
+
// A known family before the words read so far keeps its own last
|
|
1129
|
+
// word (Arial Black 900 is Arial Black and 900).
|
|
1130
|
+
if (end < words.length && knownFamily(ctx, words.slice(0, end).join(' ')))
|
|
1131
|
+
break;
|
|
1132
|
+
const two =
|
|
1133
|
+
end >= 2 ? weightOf(words.slice(end - 2, end).join('')) : null;
|
|
1134
|
+
const w = words[end - 1];
|
|
1135
|
+
if (two != null && end >= 3) {
|
|
1136
|
+
tail.unshift({
|
|
1137
|
+
kind: 'weight',
|
|
1138
|
+
text: words.slice(end - 2, end).join(' '),
|
|
1139
|
+
value: two,
|
|
1140
|
+
});
|
|
1141
|
+
end -= 2;
|
|
1142
|
+
} else if (STYLE.test(w)) {
|
|
1143
|
+
tail.unshift({kind: 'style', text: w.toLowerCase()});
|
|
1144
|
+
end -= 1;
|
|
1145
|
+
} else if (weightOf(w) != null) {
|
|
1146
|
+
tail.unshift({
|
|
1147
|
+
kind: 'weight',
|
|
1148
|
+
text: w,
|
|
1149
|
+
value: /** @type {number} */ (weightOf(w)),
|
|
1150
|
+
});
|
|
1151
|
+
end -= 1;
|
|
1152
|
+
} else if (NUMBERISH.test(w) && /[a-z%]$/i.test(w)) {
|
|
1153
|
+
tail.unshift({kind: 'size', text: w});
|
|
1154
|
+
end -= 1;
|
|
1155
|
+
// A bare number that is no weight is part of the name (Source Sans
|
|
1156
|
+
// 3); only a separate list item is a number that is no family.
|
|
1157
|
+
} else break;
|
|
1158
|
+
}
|
|
1159
|
+
const base = words.slice(0, end).join(' ');
|
|
1160
|
+
// Only those words: a font shorthand, not a list.
|
|
1161
|
+
if (!base) return null;
|
|
1162
|
+
if (!tail.length) {
|
|
1163
|
+
// A family the editor does not know that is a typo of a generic, or
|
|
1164
|
+
// (on the font dial, alone) of a preset: that name.
|
|
1165
|
+
const generic = genericOf(name);
|
|
1166
|
+
const preset =
|
|
1167
|
+
presets && pieces.length === 1 && !generic
|
|
1168
|
+
? (() => {
|
|
1169
|
+
const hits = PRESETS.filter(k => typoNear(bare(name), bare(k)));
|
|
1170
|
+
return hits.length === 1 ? hits[0] : null;
|
|
1171
|
+
})()
|
|
1172
|
+
: null;
|
|
1173
|
+
if (generic || preset) {
|
|
1174
|
+
misspelled = true;
|
|
1175
|
+
kept.push(/** @type {string} */ (generic ?? preset));
|
|
1176
|
+
} else kept.push(name);
|
|
1177
|
+
continue;
|
|
1178
|
+
}
|
|
1179
|
+
// Words only (no number or size): part of the name unless the whole
|
|
1180
|
+
// name is unknown and the name without them is known.
|
|
1181
|
+
if (
|
|
1182
|
+
tail.every(
|
|
1183
|
+
t =>
|
|
1184
|
+
t.kind === 'style' || (t.kind === 'weight' && !/^\d+$/.test(t.text)),
|
|
1185
|
+
) &&
|
|
1186
|
+
!(!knownFamily(ctx, name) && knownFamily(ctx, base))
|
|
1187
|
+
) {
|
|
1188
|
+
kept.push(name);
|
|
1189
|
+
continue;
|
|
1190
|
+
}
|
|
1191
|
+
for (const t of tail) {
|
|
1192
|
+
if (t.kind === 'weight') weight ??= t.value ?? null;
|
|
1193
|
+
else if (t.kind === 'style') style ??= t.text;
|
|
1194
|
+
else if (t.kind === 'size') {
|
|
1195
|
+
size = true;
|
|
1196
|
+
sizeTyped ??= t.text;
|
|
1197
|
+
} else number = true;
|
|
1198
|
+
}
|
|
1199
|
+
kept.push(base);
|
|
1200
|
+
}
|
|
1201
|
+
if (
|
|
1202
|
+
weight == null &&
|
|
1203
|
+
!size &&
|
|
1204
|
+
!style &&
|
|
1205
|
+
!number &&
|
|
1206
|
+
!quotedGeneric &&
|
|
1207
|
+
!misspelled
|
|
1208
|
+
)
|
|
1209
|
+
return null;
|
|
1210
|
+
const rung =
|
|
1211
|
+
weight != null
|
|
1212
|
+
? Object.entries(HEADING_WEIGHTS).reduce((a, b) =>
|
|
1213
|
+
Math.abs(Number(b[1]) - weight) < Math.abs(Number(a[1]) - weight)
|
|
1214
|
+
? b
|
|
1215
|
+
: a,
|
|
1216
|
+
)[0]
|
|
1217
|
+
: null;
|
|
1218
|
+
return {
|
|
1219
|
+
why:
|
|
1220
|
+
weight != null
|
|
1221
|
+
? 'holds a weight where a family goes, so the browser reads it as a family named that and falls back'
|
|
1222
|
+
: size
|
|
1223
|
+
? 'holds a size where a family goes, so the browser reads it as a family named that and falls back'
|
|
1224
|
+
: style
|
|
1225
|
+
? 'holds a style where a family goes, so the browser reads it as a family named that and falls back'
|
|
1226
|
+
: number
|
|
1227
|
+
? 'holds a number where a family goes (a weight is a whole hundred, a size has a unit), so the browser reads it as a family named that and falls back'
|
|
1228
|
+
: quotedGeneric
|
|
1229
|
+
? 'quotes a generic family, which makes it a family named that, so there is no generic to fall back to'
|
|
1230
|
+
: 'misspells a generic family or font, so the browser reads it as a family named that and falls back',
|
|
1231
|
+
families: kept.join(', '),
|
|
1232
|
+
rung,
|
|
1233
|
+
size,
|
|
1234
|
+
textSize: sizeTyped ? textSizePx(sizeTyped) : null,
|
|
1235
|
+
style,
|
|
1236
|
+
};
|
|
1237
|
+
}
|
|
1238
|
+
|
|
1239
|
+
/**
|
|
1240
|
+
* A mode's label before a value, in any spelling: `dark mode:`, `darkmode:`,
|
|
1241
|
+
* `dark-mode:`, `mode dark:` (group 1 or 2 the mode, group 3 the value).
|
|
1242
|
+
*/
|
|
1243
|
+
const MODE_LABEL =
|
|
1244
|
+
/^\s*\{?\s*["']?(?:(light|dark)[\s_-]*mode|mode[\s_-]*(light|dark))["']?\s*[:=]\s*(.+?)\s*;?\s*\}?\s*$/i;
|
|
1245
|
+
|
|
1246
|
+
/**
|
|
1247
|
+
* The font list a value with a missing comma or a spaced generic means
|
|
1248
|
+
* (`Georgia serif` is `Georgia, serif`, `Inter, sans serif` is `Inter,
|
|
1249
|
+
* sans-serif`), with why; null when it has neither. A generic is read only
|
|
1250
|
+
* in lower case, so a family named `Source Serif` stays one name.
|
|
1251
|
+
* @param {string} value
|
|
1252
|
+
* @returns {{value: string, why: string} | null}
|
|
1253
|
+
*/
|
|
1254
|
+
export function fontListMeant(value) {
|
|
1255
|
+
const v = String(value).trim();
|
|
1256
|
+
// A whole list in one pair of quotes or brackets (`"Inter, serif"`,
|
|
1257
|
+
// `「Inter, serif」`): the quotes go around one family, so the list is
|
|
1258
|
+
// what is inside.
|
|
1259
|
+
const wrapped =
|
|
1260
|
+
/^(?:"([^"]*,[^"]*)"|'([^']*,[^']*)'|「([^」]*,[^」]*)」|『([^』]*,[^』]*)』|“([^”]*,[^”]*)”|‘([^’]*,[^’]*)’|«([^»]*,[^»]*)»)$/.exec(
|
|
1261
|
+
v,
|
|
1262
|
+
);
|
|
1263
|
+
if (wrapped) {
|
|
1264
|
+
const inside = wrapped.slice(1).find(x => x != null) ?? '';
|
|
1265
|
+
return {
|
|
1266
|
+
value: (fontListMeant(inside)?.value ?? inside).trim(),
|
|
1267
|
+
why: 'quotes go around one family name, not the whole list',
|
|
1268
|
+
};
|
|
1269
|
+
}
|
|
1270
|
+
if (/["']/.test(v)) return null;
|
|
1271
|
+
// Families split by `|`, `;` or ` / ` instead of commas.
|
|
1272
|
+
if (
|
|
1273
|
+
// (A pasted declaration, `font-family: Georgia, serif;`, is read
|
|
1274
|
+
// elsewhere: a colon or a trailing `;` is no separator.)
|
|
1275
|
+
!/:|\.(woff2?|ttf|otf)\b/i.test(v) &&
|
|
1276
|
+
/\S\s*(?:\||;|\s\/\s)\s*\S/.test(v)
|
|
1277
|
+
) {
|
|
1278
|
+
const list = v
|
|
1279
|
+
.split(/\s*(?:\||;|\s\/\s)\s*/)
|
|
1280
|
+
.map(x => x.trim())
|
|
1281
|
+
.filter(Boolean)
|
|
1282
|
+
.join(', ');
|
|
1283
|
+
if (list && list !== v)
|
|
1284
|
+
return {
|
|
1285
|
+
value: fontListMeant(list)?.value ?? list,
|
|
1286
|
+
why: 'families are separated by commas',
|
|
1287
|
+
};
|
|
1288
|
+
}
|
|
1289
|
+
if (/\bsans serif\b/.test(v) && !/\d/.test(v))
|
|
1290
|
+
return {
|
|
1291
|
+
value: v.replace(/\bsans serif\b/g, 'sans-serif'),
|
|
1292
|
+
why: 'the generic family is sans-serif, with a dash',
|
|
1293
|
+
};
|
|
1294
|
+
// A comma missing before the generic family of any family in the list
|
|
1295
|
+
// (`Inter, Georgia serif`), the names in any case (`georgia serif`).
|
|
1296
|
+
const SHORTHAND =
|
|
1297
|
+
/^(\d+(\.\d+)?(px|rem|em|pt|%)?|bold|bolder|lighter|normal|italic|oblique|small-caps)$/i;
|
|
1298
|
+
// A word of a family name: letters (a digit after the first word, as in
|
|
1299
|
+
// `Source Serif 4`), or a generic; never a shorthand's weight or size.
|
|
1300
|
+
const familyWord = (/** @type {string} */ w, /** @type {number} */ i) =>
|
|
1301
|
+
(/^[A-Za-z][A-Za-z0-9]*$/.test(w) && !SHORTHAND.test(w)) ||
|
|
1302
|
+
(i > 0 && /^\d+$/.test(w)) ||
|
|
1303
|
+
GENERIC_FAMILIES.includes(w);
|
|
1304
|
+
const pieces = v.split(/\s*,\s*/);
|
|
1305
|
+
let missing = false;
|
|
1306
|
+
const fixedPieces = pieces.map(piece => {
|
|
1307
|
+
const ws = piece.split(/\s+/);
|
|
1308
|
+
const end = ws[ws.length - 1];
|
|
1309
|
+
if (
|
|
1310
|
+
ws.length > 1 &&
|
|
1311
|
+
GENERIC_FAMILIES.includes(end) &&
|
|
1312
|
+
ws.slice(0, -1).every(familyWord)
|
|
1313
|
+
) {
|
|
1314
|
+
missing = true;
|
|
1315
|
+
return `${ws.slice(0, -1).join(' ')}, ${end}`;
|
|
1316
|
+
}
|
|
1317
|
+
return piece;
|
|
1318
|
+
});
|
|
1319
|
+
if (missing && pieces.length > 1)
|
|
1320
|
+
return {
|
|
1321
|
+
value: fixedPieces.join(', '),
|
|
1322
|
+
why: 'a comma goes before each generic family',
|
|
1323
|
+
};
|
|
1324
|
+
if (v.includes(',')) return null;
|
|
1325
|
+
const words = v.split(/\s+/);
|
|
1326
|
+
const last = words[words.length - 1];
|
|
1327
|
+
// Only family names before it (capitalized words), never a font
|
|
1328
|
+
// shorthand's weight, style or size.
|
|
1329
|
+
if (
|
|
1330
|
+
words.length > 1 &&
|
|
1331
|
+
GENERIC_FAMILIES.includes(last) &&
|
|
1332
|
+
words.slice(0, -1).every(familyWord)
|
|
1333
|
+
)
|
|
1334
|
+
return {
|
|
1335
|
+
value: `${words.slice(0, -1).join(' ')}, ${last}`,
|
|
1336
|
+
why: `a comma goes before the generic family ${last}`,
|
|
1337
|
+
};
|
|
1338
|
+
return null;
|
|
1339
|
+
}
|
|
1340
|
+
|
|
703
1341
|
/**
|
|
704
1342
|
* A value of a type to put in a suggestion, so a suggested command runs.
|
|
705
1343
|
* @param {string} type
|
|
@@ -739,6 +1377,8 @@ function groupOfPropType(prop) {
|
|
|
739
1377
|
* @param {string} slug
|
|
740
1378
|
* @param {string[]} [readers] the CSS properties that read the token
|
|
741
1379
|
* @param {boolean} [multiplied] whether Core multiplies the token by a size
|
|
1380
|
+
* @param {boolean} [isSet] whether the theme sets the token now (an undo
|
|
1381
|
+
* of it works)
|
|
742
1382
|
*/
|
|
743
1383
|
function checkTypedValue(
|
|
744
1384
|
type,
|
|
@@ -749,6 +1389,7 @@ function checkTypedValue(
|
|
|
749
1389
|
slug,
|
|
750
1390
|
readers = [],
|
|
751
1391
|
multiplied = false,
|
|
1392
|
+
isSet = true,
|
|
752
1393
|
) {
|
|
753
1394
|
// The value meant, when what is wrong is how it was typed (a trailing
|
|
754
1395
|
// `;`, a comment, quotes around it, full-width characters, a font name
|
|
@@ -772,17 +1413,37 @@ function checkTypedValue(
|
|
|
772
1413
|
}
|
|
773
1414
|
return null;
|
|
774
1415
|
};
|
|
775
|
-
/** @param {string} what @param {string} example */
|
|
1416
|
+
/** @param {string} what @param {string | null} example */
|
|
776
1417
|
const bad = (what, example) =>
|
|
777
1418
|
refuse(
|
|
778
1419
|
E.ERR_THEME_BAD_VALUE,
|
|
779
1420
|
`${name} is ${what}; "${value}" is not one.`,
|
|
780
1421
|
{
|
|
1422
|
+
// Nothing read from the value (no example given): how, never a
|
|
1423
|
+
// stock value.
|
|
781
1424
|
run: [
|
|
782
|
-
|
|
1425
|
+
(meant() ?? example) == null
|
|
1426
|
+
? `${HOW} ${name}`
|
|
1427
|
+
: `${P} set ${slug} ${name} ${quoteCommandArgument(String(meant() ?? example))}`,
|
|
783
1428
|
],
|
|
784
1429
|
},
|
|
785
1430
|
);
|
|
1431
|
+
// A font family list with a comma missing before a generic family
|
|
1432
|
+
// (`Georgia serif`), or a generic written with a space (`sans serif`): the
|
|
1433
|
+
// list meant.
|
|
1434
|
+
if (type === 'font') {
|
|
1435
|
+
const fixed = fontListMeant(value);
|
|
1436
|
+
if (fixed)
|
|
1437
|
+
refuse(
|
|
1438
|
+
E.ERR_THEME_BAD_VALUE,
|
|
1439
|
+
`"${value}" names a family that exists nowhere: ${fixed.why}.`,
|
|
1440
|
+
{
|
|
1441
|
+
run: [
|
|
1442
|
+
`${P} set ${slug} ${name} ${quoteCommandArgument(fixed.value)}`,
|
|
1443
|
+
],
|
|
1444
|
+
},
|
|
1445
|
+
);
|
|
1446
|
+
}
|
|
786
1447
|
// A font file or a link is no family name: never quoted into one.
|
|
787
1448
|
if (type === 'font') {
|
|
788
1449
|
const file = fontFileReason(pastedFont(value) || value);
|
|
@@ -792,6 +1453,18 @@ function checkTypedValue(
|
|
|
792
1453
|
`${P} set ${slug} ${name} ${quoteCommandArgument(exampleOf(type, name))}`,
|
|
793
1454
|
],
|
|
794
1455
|
});
|
|
1456
|
+
// An empty family (`""`, a trailing comma) or one quoted name holding
|
|
1457
|
+
// commas is a broken stack: the browser drops the fallback after it.
|
|
1458
|
+
const pieces = familyPieces(value);
|
|
1459
|
+
if (
|
|
1460
|
+
pieces &&
|
|
1461
|
+
(pieces.some(f => !f.name) ||
|
|
1462
|
+
pieces.some(f => f.quoted && f.name.includes(',')))
|
|
1463
|
+
)
|
|
1464
|
+
bad(
|
|
1465
|
+
'a font family list with a name for each family',
|
|
1466
|
+
exampleOf(type, name),
|
|
1467
|
+
);
|
|
795
1468
|
}
|
|
796
1469
|
if (!isSafeValue(value))
|
|
797
1470
|
refuse(
|
|
@@ -813,14 +1486,24 @@ function checkTypedValue(
|
|
|
813
1486
|
if (keyword)
|
|
814
1487
|
refuse(
|
|
815
1488
|
E.ERR_THEME_BAD_VALUE,
|
|
816
|
-
`"${keyword}" is a CSS keyword, not a value: on ${name} it leaves the token empty, so what reads it drops its style. Give a
|
|
1489
|
+
`"${keyword}" is a CSS keyword, not a value: on ${name} it leaves the token empty, so what reads it drops its style. Give a ${type} value${isSet ? `, or undo ${name} to go back to the base theme's` : ''}.`,
|
|
817
1490
|
{
|
|
1491
|
+
// How for the token; the undo only when the theme sets it.
|
|
818
1492
|
run: [
|
|
819
|
-
`${
|
|
820
|
-
`${P} undo ${slug} ${name}
|
|
1493
|
+
`${HOW} ${name}`,
|
|
1494
|
+
...(isSet ? [`${P} undo ${slug} ${name}`] : []),
|
|
821
1495
|
],
|
|
822
1496
|
},
|
|
823
1497
|
);
|
|
1498
|
+
// Math whose units cannot combine (`8 + 2px`, `0.5rem * 1px`, a var()
|
|
1499
|
+
// read as its fallback): the browser drops the whole value.
|
|
1500
|
+
const math = type === 'size' ? calcUnitProblem(value) : null;
|
|
1501
|
+
if (math)
|
|
1502
|
+
refuse(
|
|
1503
|
+
E.ERR_THEME_BAD_VALUE,
|
|
1504
|
+
`${name} is a ${type}; the calc() in "${value}" cannot be worked out: ${math} (with each var() at its fallback, as when the variable is unset), so the browser drops the value.`,
|
|
1505
|
+
{run: [`${HOW} ${name}`]},
|
|
1506
|
+
);
|
|
824
1507
|
// A var() inside a larger value (calc, max, color-mix) has a fallback of
|
|
825
1508
|
// the token's kind too, checked like a whole-value var().
|
|
826
1509
|
if (type !== 'other')
|
|
@@ -834,6 +1517,16 @@ function checkTypedValue(
|
|
|
834
1517
|
)
|
|
835
1518
|
)
|
|
836
1519
|
continue;
|
|
1520
|
+
// A factor in a size's math (`calc(0.75rem * var(--x, 1))`, as the
|
|
1521
|
+
// official themes write their type scale): a plain number there is
|
|
1522
|
+
// what multiplies the size.
|
|
1523
|
+
if (
|
|
1524
|
+
type === 'size' &&
|
|
1525
|
+
within.some(f => /^(calc|min|max|clamp)$/i.test(f)) &&
|
|
1526
|
+
/^[+-]?(\d+\.?\d*|\.\d+)$/.test(fallback.trim()) &&
|
|
1527
|
+
(/[*/]\s*var\(/i.test(value) || /var\([^()]*\)\s*[*/]/i.test(value))
|
|
1528
|
+
)
|
|
1529
|
+
continue;
|
|
837
1530
|
if (fallback === '')
|
|
838
1531
|
refuse(
|
|
839
1532
|
E.ERR_THEME_BAD_VALUE,
|
|
@@ -896,26 +1589,22 @@ function checkTypedValue(
|
|
|
896
1589
|
);
|
|
897
1590
|
return;
|
|
898
1591
|
}
|
|
899
|
-
if (type === 'color' && !isFixedColor(value)) bad('a color',
|
|
1592
|
+
if (type === 'color' && !isFixedColor(value)) bad('a color', null);
|
|
900
1593
|
if (type === 'size' && !isSize(value, name)) {
|
|
901
|
-
//
|
|
902
|
-
//
|
|
903
|
-
|
|
904
|
-
let own = String(TOKENS[name] ?? '').trim();
|
|
905
|
-
for (let hop = 0; hop < 4; hop += 1) {
|
|
906
|
-
const ref = /^var\(\s*(--[a-z0-9-]+)\s*\)$/i.exec(own)?.[1];
|
|
907
|
-
if (!ref) break;
|
|
908
|
-
own = String(TOKENS[ref] ?? '').trim();
|
|
909
|
-
}
|
|
910
|
-
const sizeExample =
|
|
911
|
-
own && isSize(own, name) && !/var\(/.test(own) ? own : '6px';
|
|
1594
|
+
// The token's own default is never offered as a repair: only a size
|
|
1595
|
+
// read from the value typed.
|
|
1596
|
+
const sizeExample = null;
|
|
912
1597
|
// The size meant, when one dot or sign is all that is wrong (1.px).
|
|
913
1598
|
const meant = value.trim().replace(/(\d)\.(?=[a-z%]|$)/gi, '$1');
|
|
914
|
-
// A bare number is the size in px
|
|
915
|
-
//
|
|
916
|
-
const plain = value.trim()
|
|
1599
|
+
// A bare number is the size in px; a minus sign is kept (a negative
|
|
1600
|
+
// size is refused, never offered as its positive).
|
|
1601
|
+
const plain = value.trim();
|
|
1602
|
+
// A bare number below one (a pasted `--radius: 0.5rem` that lost its
|
|
1603
|
+
// unit) has no unit to read it by: no size is guessed, as corners does.
|
|
917
1604
|
const px = /^[+]?\d*\.?\d+(e[+-]?\d+)?$/i.test(plain)
|
|
918
|
-
?
|
|
1605
|
+
? Number(plain) > 0 && Number(plain) < 1
|
|
1606
|
+
? null
|
|
1607
|
+
: `${Number(plain)}px`
|
|
919
1608
|
: /^\d*\.?\d+[a-z%]+$/i.test(plain) && plain !== value.trim()
|
|
920
1609
|
? plain
|
|
921
1610
|
: null;
|
|
@@ -1231,6 +1920,18 @@ function nearestColorName(v) {
|
|
|
1231
1920
|
return nearest(w, COLOR_NAMES)[0] ?? null;
|
|
1232
1921
|
}
|
|
1233
1922
|
|
|
1923
|
+
/**
|
|
1924
|
+
* Old keywords a property's grammar lists that no current browser applies,
|
|
1925
|
+
* each with the keyword that does what it meant.
|
|
1926
|
+
* @type {Record<string, Record<string, string>>}
|
|
1927
|
+
*/
|
|
1928
|
+
const OBSOLETE_KEYWORDS = {
|
|
1929
|
+
cursor: {hand: 'pointer'},
|
|
1930
|
+
};
|
|
1931
|
+
documentReadings(
|
|
1932
|
+
Object.values(OBSOLETE_KEYWORDS).flatMap(words => Object.entries(words)),
|
|
1933
|
+
);
|
|
1934
|
+
|
|
1234
1935
|
/**
|
|
1235
1936
|
* Why a value is not one the property takes, or null. Colors are checked
|
|
1236
1937
|
* by the editor's own color check; a property css-tree has no grammar for
|
|
@@ -1251,12 +1952,18 @@ function propertyProblem(prop, value) {
|
|
|
1251
1952
|
takes: `a value its CSS grammar takes in each var() fallback too (${grammarText(known)})`,
|
|
1252
1953
|
near: initialOf(prop),
|
|
1253
1954
|
};
|
|
1955
|
+
// An old keyword the grammar still lists but no current browser
|
|
1956
|
+
// applies (`cursor: hand`): the keyword that does what it meant.
|
|
1957
|
+
const obsolete = OBSOLETE_KEYWORDS[prop]?.[v.toLowerCase()];
|
|
1958
|
+
if (obsolete)
|
|
1959
|
+
return {
|
|
1960
|
+
takes: `a value current browsers apply ("${v}" is an old keyword none applies; ${obsolete} does what it meant)`,
|
|
1961
|
+
near: obsolete,
|
|
1962
|
+
};
|
|
1254
1963
|
if (matchValue(prop, v))
|
|
1255
1964
|
return belowRange(prop, v)
|
|
1256
|
-
?
|
|
1257
|
-
|
|
1258
|
-
near: v.replace(/(^|[\s(,/])-(?=\.?\d)/g, '$1'),
|
|
1259
|
-
}
|
|
1965
|
+
? // A negative value is no size of the other sign: no line mirrors it.
|
|
1966
|
+
{takes: 'a value of 0 or more', near: null}
|
|
1260
1967
|
: null;
|
|
1261
1968
|
// The same value as it was meant to be typed (a font name quoted, a
|
|
1262
1969
|
// trailing `;` gone), when the property takes that.
|
|
@@ -1281,9 +1988,7 @@ function propertyProblem(prop, value) {
|
|
|
1281
1988
|
null)
|
|
1282
1989
|
: null;
|
|
1283
1990
|
// A value that works, for the suggestion: a keyword near the one typed,
|
|
1284
|
-
// the
|
|
1285
|
-
const example = exampleOf(groupOfPropType(prop), prop);
|
|
1286
|
-
const initial = initialOf(prop);
|
|
1991
|
+
// or the value typed cleaned; each checked.
|
|
1287
1992
|
// A bare number on a length property means px (`padding 4` → `4px`, each
|
|
1288
1993
|
// number in a list too), when the property takes that.
|
|
1289
1994
|
// Each bare number token gets px (a mixed list `4 8px`, `8 / 4`, an
|
|
@@ -1296,31 +2001,82 @@ function propertyProblem(prop, value) {
|
|
|
1296
2001
|
Number(num) === 0 ? `${pre}${num}` : `${pre}${num}px`,
|
|
1297
2002
|
)
|
|
1298
2003
|
: null;
|
|
1299
|
-
// A suggestion is offered only when the property takes it, in range too
|
|
2004
|
+
// A suggestion is offered only when the property takes it, in range too,
|
|
2005
|
+
// and never a reset the input did not hold (0, none, 1, auto, normal):
|
|
2006
|
+
// following it would undo what was asked. A reset typed with a typo
|
|
2007
|
+
// (`nnone`, `normall`: a word within two edits of it) is that reset,
|
|
2008
|
+
// corrected.
|
|
2009
|
+
const RESETS =
|
|
2010
|
+
/^(0|0px|none|1|auto|normal|initial|unset|inherit|revert|transparent)$/i;
|
|
2011
|
+
const typedAs = (/** @type {string} */ x) => x === typed || typoOf(typed, x);
|
|
1300
2012
|
const takes = (/** @type {string | null} */ x) =>
|
|
1301
|
-
x != null &&
|
|
2013
|
+
x != null &&
|
|
2014
|
+
matchValue(prop, x) != null &&
|
|
2015
|
+
!belowRange(prop, x) &&
|
|
2016
|
+
!(RESETS.test(x.trim()) && !typedAs(x.trim().toLowerCase()));
|
|
2017
|
+
// A lone length on a shorthand where it is only a position (background,
|
|
2018
|
+
// mask) wipes the rest: no px is guessed there.
|
|
2019
|
+
const pxFits = !/^(background|mask)$/i.test(prop);
|
|
2020
|
+
// Words with a documented reading on a property (the allowlist a repair
|
|
2021
|
+
// may map through).
|
|
2022
|
+
const WORDS = PROPERTY_WORDS;
|
|
2023
|
+
// A weight word is its number (the same table the headings dial reads);
|
|
2024
|
+
// text in content is that text, quoted.
|
|
2025
|
+
const weightWord = typed.replace(/[\s-]+/g, '');
|
|
2026
|
+
const weight = HEADING_WEIGHTS[weightWord] ?? WEIGHT_WORDS[weightWord];
|
|
2027
|
+
const mapped =
|
|
2028
|
+
WORDS[prop]?.[typed.replace(/\s+/g, '-')] ??
|
|
2029
|
+
(prop === 'font-weight' && weight ? weight : null) ??
|
|
2030
|
+
(prop === 'content' && !/^["']|["']$/.test(v) ? JSON.stringify(v) : null) ??
|
|
2031
|
+
null;
|
|
1302
2032
|
return {
|
|
1303
2033
|
takes: `a value its CSS grammar takes (${grammarText(known)})`,
|
|
1304
2034
|
near:
|
|
1305
|
-
(
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
: null) ??
|
|
2035
|
+
(mapped && matchValue(prop, mapped) != null ? mapped : null) ??
|
|
2036
|
+
(pxFits && takes(withPx) ? withPx : null) ??
|
|
2037
|
+
// Below the property's range (a negative width) is no size of the
|
|
2038
|
+
// other sign: the mirrored value is never offered.
|
|
1310
2039
|
(takes(joined) && joined !== v ? joined : null) ??
|
|
1311
|
-
//
|
|
1312
|
-
//
|
|
2040
|
+
// A comma between digits is a decimal point (1,5rem is 1.5rem), never
|
|
2041
|
+
// a split into layers.
|
|
2042
|
+
(takes(commaNumbers(v, weightSetting(prop))) &&
|
|
2043
|
+
commaNumbers(v, weightSetting(prop)) !== v
|
|
2044
|
+
? commaNumbers(v, weightSetting(prop))
|
|
2045
|
+
: null) ??
|
|
2046
|
+
// Several values of one kind on a property that takes one
|
|
2047
|
+
// (padding-top with four lengths): the first as typed, with px only
|
|
2048
|
+
// when the property takes no bare number. Never one value of a
|
|
2049
|
+
// shorthand of several kinds (`all 200` for transition). A property
|
|
2050
|
+
// whose grammar pairs them with a slash (`aspect-ratio 16 9`,
|
|
2051
|
+
// `grid-row 2 4`) takes the pair, never its first half.
|
|
1313
2052
|
(() => {
|
|
1314
|
-
const
|
|
1315
|
-
|
|
2053
|
+
const all = splitTop(v.trim(), ' ');
|
|
2054
|
+
const slashed = all.join(' / ');
|
|
2055
|
+
if (all.length === 2 && takes(slashed)) return slashed;
|
|
2056
|
+
if (all.length > 1 && takes(all.slice(0, 2).join(' / '))) return null;
|
|
2057
|
+
const same = sameKindValues(v);
|
|
2058
|
+
if (!same) return null;
|
|
2059
|
+
const first = same.items[0];
|
|
2060
|
+
const px = same.kind === '' ? `${first}px` : null;
|
|
2061
|
+
return takes(first) ? first : pxFits && px && takes(px) ? px : null;
|
|
1316
2062
|
})() ??
|
|
1317
2063
|
(near && takes(near) ? near : null) ??
|
|
1318
|
-
//
|
|
1319
|
-
//
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
2064
|
+
// Layers typed with one too many or an empty one (`url(a.png), red,
|
|
2065
|
+
// blue`, `red,,blue`): the layers before the last, else one of them,
|
|
2066
|
+
// when the property takes it. Never the property's reset or a stock
|
|
2067
|
+
// example: a repair carries only what was typed.
|
|
2068
|
+
(() => {
|
|
2069
|
+
const layers = splitTop(v.trim(), ',')
|
|
2070
|
+
.map(x => x.trim())
|
|
2071
|
+
.filter(Boolean);
|
|
2072
|
+
if (layers.length < 2 && !/,\s*,/.test(v)) return null;
|
|
2073
|
+
const tries = [
|
|
2074
|
+
layers.join(', '),
|
|
2075
|
+
layers.slice(0, -1).join(', '),
|
|
2076
|
+
...layers,
|
|
2077
|
+
];
|
|
2078
|
+
return tries.find(x => x && x !== v && takes(x)) ?? null;
|
|
2079
|
+
})(),
|
|
1324
2080
|
};
|
|
1325
2081
|
}
|
|
1326
2082
|
|
|
@@ -1387,6 +2143,313 @@ function baseReads(ctx, like, token) {
|
|
|
1387
2143
|
}
|
|
1388
2144
|
}
|
|
1389
2145
|
|
|
2146
|
+
/**
|
|
2147
|
+
* The headings rung nearest a weight number (800 is heavy).
|
|
2148
|
+
* @param {number} weight
|
|
2149
|
+
*/
|
|
2150
|
+
const weightRung = weight =>
|
|
2151
|
+
Object.entries(HEADING_WEIGHTS).reduce((a, b) =>
|
|
2152
|
+
Math.abs(Number(b[1]) - weight) < Math.abs(Number(a[1]) - weight) ? b : a,
|
|
2153
|
+
)[0];
|
|
2154
|
+
documentNumericTable(
|
|
2155
|
+
['headings', 'font-weight'],
|
|
2156
|
+
Object.entries(HEADING_WEIGHTS).map(([w, n]) => [w, Number(n)]),
|
|
2157
|
+
[1, 1000],
|
|
2158
|
+
);
|
|
2159
|
+
// A font weight runs from 1 to 1000.
|
|
2160
|
+
documentRange(['font-weight', '--font-weight-*'], 1, 1000);
|
|
2161
|
+
documentNumericTable(
|
|
2162
|
+
['spacing'],
|
|
2163
|
+
SPACING.map(([name, factor]) => [name, factor]),
|
|
2164
|
+
);
|
|
2165
|
+
documentNumericTable(
|
|
2166
|
+
['text-size'],
|
|
2167
|
+
TEXT_SIZE.map(([name, px]) => [name, px]),
|
|
2168
|
+
);
|
|
2169
|
+
// The text size number is the body size in pixels, 10 to 32; vibrancy
|
|
2170
|
+
// runs from 0 to 100.
|
|
2171
|
+
documentRange(['text-size'], 10, 32);
|
|
2172
|
+
documentRange(['vibrancy'], 0, 100);
|
|
2173
|
+
documentReadings(TEXT_SIZE.map(([name, px]) => [name, `${px}px`]));
|
|
2174
|
+
documentReadings(Object.entries(HEADING_TRACKING));
|
|
2175
|
+
// `bold` given a no (false, off) is the normal weight.
|
|
2176
|
+
documentReadings(['false', 'off', 'no', 'none'].map(w => [w, 'normal']));
|
|
2177
|
+
/**
|
|
2178
|
+
* The CSS absolute-size keywords that are no text-size rung, as the px
|
|
2179
|
+
* CSS gives each at a 16px root.
|
|
2180
|
+
*/
|
|
2181
|
+
const CSS_SIZE_KEYWORDS = wordTable(
|
|
2182
|
+
/** @type {Record<string, number>} */ ({
|
|
2183
|
+
'xx-small': 9,
|
|
2184
|
+
'x-small': 10,
|
|
2185
|
+
'x-large': 24,
|
|
2186
|
+
'xx-large': 32,
|
|
2187
|
+
'xxx-large': 48,
|
|
2188
|
+
}),
|
|
2189
|
+
);
|
|
2190
|
+
documentReadings(
|
|
2191
|
+
Object.entries(CSS_SIZE_KEYWORDS)
|
|
2192
|
+
.filter(([, px]) => px >= 10 && px <= 32)
|
|
2193
|
+
.map(([w, px]) => [w, String(px)]),
|
|
2194
|
+
);
|
|
2195
|
+
// A weight word read as the headings rung its number is nearest.
|
|
2196
|
+
documentReadings(
|
|
2197
|
+
Object.entries(WEIGHT_WORDS).map(([w, n]) => [w, weightRung(Number(n))]),
|
|
2198
|
+
);
|
|
2199
|
+
/** Words for no rounding: corners square. */
|
|
2200
|
+
const NO_ROUNDING = ['0', '0%', 'none', 'sharp', 'zero', 'no', 'flat'];
|
|
2201
|
+
/** Words for no space: spacing's tightest rung. */
|
|
2202
|
+
const NO_SPACE = ['0', 'none', 'zero', 'no', 'off'];
|
|
2203
|
+
documentReadings(NO_ROUNDING.map(w => [w, 'square']));
|
|
2204
|
+
documentReadings(NO_SPACE.map(w => [w, SPACING[0][0]]));
|
|
2205
|
+
documentReadings(
|
|
2206
|
+
Object.values(DIAL_WORDS).flatMap(words => Object.entries(words)),
|
|
2207
|
+
);
|
|
2208
|
+
/** State words a value may be labeled with. */
|
|
2209
|
+
const STATE_WORDS = [
|
|
2210
|
+
'hover',
|
|
2211
|
+
'active',
|
|
2212
|
+
'focus',
|
|
2213
|
+
'focus-visible',
|
|
2214
|
+
'focus-within',
|
|
2215
|
+
'disabled',
|
|
2216
|
+
'pressed',
|
|
2217
|
+
'selected',
|
|
2218
|
+
'checked',
|
|
2219
|
+
'open',
|
|
2220
|
+
'expanded',
|
|
2221
|
+
'visited',
|
|
2222
|
+
];
|
|
2223
|
+
/** Words for a kind of screen a value may be labeled with. */
|
|
2224
|
+
const DEVICE_WORDS = [
|
|
2225
|
+
'phone',
|
|
2226
|
+
'phones',
|
|
2227
|
+
'mobile',
|
|
2228
|
+
'tablet',
|
|
2229
|
+
'tablets',
|
|
2230
|
+
'desktop',
|
|
2231
|
+
'laptop',
|
|
2232
|
+
'ipad',
|
|
2233
|
+
'iphone',
|
|
2234
|
+
'android',
|
|
2235
|
+
'ios',
|
|
2236
|
+
'touch',
|
|
2237
|
+
'small-screen',
|
|
2238
|
+
'small-screens',
|
|
2239
|
+
'large-screen',
|
|
2240
|
+
'large-screens',
|
|
2241
|
+
'print',
|
|
2242
|
+
];
|
|
2243
|
+
|
|
2244
|
+
/**
|
|
2245
|
+
* The word a value is labeled with and the value after it (`dark: #2563eb`,
|
|
2246
|
+
* `"corners": "pill"`, `{"dark": "#2563eb"}`, `dark=#2563eb`, `dark mode:
|
|
2247
|
+
* #2563eb`, `textSize: 18`), the word as a dashed name; null when the value
|
|
2248
|
+
* holds no label.
|
|
2249
|
+
* @param {string} value
|
|
2250
|
+
* @returns {{word: string, rest: string, when?: string} | null}
|
|
2251
|
+
*/
|
|
2252
|
+
function valueLabel(value) {
|
|
2253
|
+
// A mode label in any spelling (`dark mode: red`, `darkmode: red`,
|
|
2254
|
+
// `mode dark: red`) is that mode's label: one reading, read first so the
|
|
2255
|
+
// value is never taken for the label.
|
|
2256
|
+
const modeLabel = MODE_LABEL.exec(String(value));
|
|
2257
|
+
if (modeLabel)
|
|
2258
|
+
return {
|
|
2259
|
+
word: (modeLabel[1] ?? modeLabel[2]).toLowerCase(),
|
|
2260
|
+
rest: modeLabel[3].trim(),
|
|
2261
|
+
};
|
|
2262
|
+
// A flag's label after the value (`red mode: dark`, `red state: hover`,
|
|
2263
|
+
// `red part: card`) reads as the same label before it (`dark: red`); a
|
|
2264
|
+
// variant or size after it (`red variant: primary`) keeps its prop.
|
|
2265
|
+
const trail =
|
|
2266
|
+
/^\s*(.+?)\s+(mode|theme|state|part|on|variant|size|when)\s*[:=]\s*([a-z][a-z0-9:-]*)\s*;?\s*$/i.exec(
|
|
2267
|
+
String(value),
|
|
2268
|
+
);
|
|
2269
|
+
if (trail && !/[:=]/.test(trail[1])) {
|
|
2270
|
+
const flag = trail[2].toLowerCase();
|
|
2271
|
+
const word = trail[3].toLowerCase();
|
|
2272
|
+
if (/^(variant|size|when)$/.test(flag))
|
|
2273
|
+
return {
|
|
2274
|
+
word: 'when',
|
|
2275
|
+
rest: trail[1].trim(),
|
|
2276
|
+
when: flag === 'when' ? word : `${flag}:${word}`,
|
|
2277
|
+
};
|
|
2278
|
+
return {word, rest: trail[1].trim()};
|
|
2279
|
+
}
|
|
2280
|
+
const m =
|
|
2281
|
+
/^\s*\{?\s*["']?([a-zA-Z][a-zA-Z0-9 _-]*?|--[a-z0-9-]+)["']?\s*[:=]\s*(.+?)\s*;?\s*\}?\s*$/.exec(
|
|
2282
|
+
String(value),
|
|
2283
|
+
);
|
|
2284
|
+
if (!m || /^https?$/i.test(m[1])) return null;
|
|
2285
|
+
const word = m[1]
|
|
2286
|
+
.trim()
|
|
2287
|
+
.replace(/([a-z0-9])([A-Z])/g, '$1-$2')
|
|
2288
|
+
.replace(/[\s_]+/g, '-')
|
|
2289
|
+
.toLowerCase();
|
|
2290
|
+
const rest = m[2].trim().replace(/^"(.*)"\s*,?$/, '$1');
|
|
2291
|
+
return {word, rest};
|
|
2292
|
+
}
|
|
2293
|
+
|
|
2294
|
+
/**
|
|
2295
|
+
* Whether a label is the setting's own name (`accent: red` for accent,
|
|
2296
|
+
* `font-family: Inter` for font).
|
|
2297
|
+
* @param {string} thing @param {string} word
|
|
2298
|
+
*/
|
|
2299
|
+
const ownLabel = (thing, word) =>
|
|
2300
|
+
word === thing ||
|
|
2301
|
+
(thing === 'font' && word === 'font-family') ||
|
|
2302
|
+
(thing.startsWith('--font-family') &&
|
|
2303
|
+
(word === 'font-family' || word === 'font')) ||
|
|
2304
|
+
(thing === 'text-size' && word === 'font-size');
|
|
2305
|
+
|
|
2306
|
+
/**
|
|
2307
|
+
* Whether a family is one the editor knows: a system family on the theme
|
|
2308
|
+
* build's list, an open font in its table or a preset's family, or one
|
|
2309
|
+
* whose @fontsource package the project has installed.
|
|
2310
|
+
* @param {any} ctx
|
|
2311
|
+
* @param {string} family without quotes
|
|
2312
|
+
*/
|
|
2313
|
+
function knownFamily(ctx, family) {
|
|
2314
|
+
const name = family.trim().toLowerCase();
|
|
2315
|
+
if (!name) return false;
|
|
2316
|
+
if (isSystemFamily(family)) return true;
|
|
2317
|
+
if (
|
|
2318
|
+
[
|
|
2319
|
+
...Object.values(OPEN_FONTS).map(f => f.family),
|
|
2320
|
+
...Object.values(FONTS).map(f => f[0]),
|
|
2321
|
+
].some(f => f.toLowerCase() === name)
|
|
2322
|
+
)
|
|
2323
|
+
return true;
|
|
2324
|
+
try {
|
|
2325
|
+
ctx?.project?.req?.resolve(`${fontsourcePackageOf(family)}/package.json`);
|
|
2326
|
+
return Boolean(ctx?.project?.req);
|
|
2327
|
+
} catch {
|
|
2328
|
+
return false;
|
|
2329
|
+
}
|
|
2330
|
+
}
|
|
2331
|
+
|
|
2332
|
+
/**
|
|
2333
|
+
* The CSS properties a dial sets, whose pasted declaration is the dial's
|
|
2334
|
+
* own value (`border-radius: 8px` for corners, `color: #e11d48` for a
|
|
2335
|
+
* color dial). A dial with none takes no pasted property.
|
|
2336
|
+
* @type {Record<string, (word: string) => boolean>}
|
|
2337
|
+
*/
|
|
2338
|
+
const DIAL_PROPERTIES = {
|
|
2339
|
+
corners: w => /^border(-[a-z]+)*-radius$/.test(w),
|
|
2340
|
+
spacing: w => /^(padding|margin|gap|row-gap|column-gap)(-[a-z]+)*$/.test(w),
|
|
2341
|
+
'text-size': w => w === 'font-size',
|
|
2342
|
+
font: w => w === 'font' || w === 'font-family',
|
|
2343
|
+
headings: w => w === 'font-weight' || w === 'letter-spacing',
|
|
2344
|
+
...Object.fromEntries(
|
|
2345
|
+
PALETTE_DIALS.map(d => [
|
|
2346
|
+
d,
|
|
2347
|
+
(/** @type {string} */ w) => w === 'background' || COLOR_PROPS.test(w),
|
|
2348
|
+
]),
|
|
2349
|
+
),
|
|
2350
|
+
};
|
|
2351
|
+
|
|
2352
|
+
/**
|
|
2353
|
+
* Whether a CSS property pasted before a value (`margin: 8px`) is one the
|
|
2354
|
+
* setting sets: its own label, a property a dial sets, a property that
|
|
2355
|
+
* reads the token, or, for a color token, a color property.
|
|
2356
|
+
* @param {any} ctx
|
|
2357
|
+
* @param {string} thing
|
|
2358
|
+
* @param {string} word
|
|
2359
|
+
* @param {boolean} partProperty
|
|
2360
|
+
*/
|
|
2361
|
+
function labelOwned(ctx, thing, word, partProperty) {
|
|
2362
|
+
if (word === thing || ownLabel(thing, word)) return true;
|
|
2363
|
+
if (partProperty) return false;
|
|
2364
|
+
if (DIALS[thing]) return DIAL_PROPERTIES[thing]?.(word) ?? false;
|
|
2365
|
+
if (thing.startsWith('--')) {
|
|
2366
|
+
const kebab = (/** @type {string} */ p) =>
|
|
2367
|
+
p.replace(/[A-Z]/g, c => `-${c.toLowerCase()}`);
|
|
2368
|
+
return (
|
|
2369
|
+
(ctx?.C?.propsReading?.(thing) ?? []).some(
|
|
2370
|
+
(/** @type {string} */ p) => kebab(p) === word,
|
|
2371
|
+
) ||
|
|
2372
|
+
(isColorToken(thing) && (word === 'background' || COLOR_PROPS.test(word)))
|
|
2373
|
+
);
|
|
2374
|
+
}
|
|
2375
|
+
return false;
|
|
2376
|
+
}
|
|
2377
|
+
|
|
2378
|
+
/**
|
|
2379
|
+
* The one mode a light-only or dark-only theme shows, or null.
|
|
2380
|
+
* @param {{mode?: string} | null | undefined} data
|
|
2381
|
+
* @returns {'light' | 'dark' | null}
|
|
2382
|
+
*/
|
|
2383
|
+
function oneModeOfTheme(data) {
|
|
2384
|
+
return data?.mode === 'light-only'
|
|
2385
|
+
? 'light'
|
|
2386
|
+
: data?.mode === 'dark-only'
|
|
2387
|
+
? 'dark'
|
|
2388
|
+
: null;
|
|
2389
|
+
}
|
|
2390
|
+
|
|
2391
|
+
/**
|
|
2392
|
+
* What a text property CSS inherits, set on a part, also reaches: the parts
|
|
2393
|
+
* inside it that set no such property of their own, said in one line; null
|
|
2394
|
+
* for any other property or when none does.
|
|
2395
|
+
* @param {import('./_settings.mjs').Ctx} ctx
|
|
2396
|
+
* @param {{on?: string, only?: boolean, thing?: string}} s
|
|
2397
|
+
* @param {string} prop kebab-case
|
|
2398
|
+
* @returns {string | null}
|
|
2399
|
+
*/
|
|
2400
|
+
export function inheritedReach(ctx, s, prop) {
|
|
2401
|
+
if (
|
|
2402
|
+
!/^(font-(size|weight|style|family|variant)|text-(transform|align)|letter-spacing|line-height|white-space|word-spacing)$/.test(
|
|
2403
|
+
prop,
|
|
2404
|
+
)
|
|
2405
|
+
)
|
|
2406
|
+
return null;
|
|
2407
|
+
const reached = [
|
|
2408
|
+
...new Set(
|
|
2409
|
+
partsOf(ctx, /** @type {any} */ (s)).flatMap(t =>
|
|
2410
|
+
/** @type {string[]} */ (ctx.C.MAP[t]?.contains ?? []).filter(
|
|
2411
|
+
inner =>
|
|
2412
|
+
ctx.project.target.has(inner) && !ctx.C.MAP[inner]?.own?.[prop],
|
|
2413
|
+
),
|
|
2414
|
+
),
|
|
2415
|
+
),
|
|
2416
|
+
];
|
|
2417
|
+
return reached.length
|
|
2418
|
+
? `${prop} is inherited, so it also reaches ${reached.slice(0, 4).join(', ')}${reached.length > 4 ? ' and more' : ''} inside ${s.on}, which set no ${prop} of their own`
|
|
2419
|
+
: null;
|
|
2420
|
+
}
|
|
2421
|
+
|
|
2422
|
+
/**
|
|
2423
|
+
* The states `set` takes on a part: the ones its doc lists and the ones
|
|
2424
|
+
* every part takes, less any a change in it is refused for while the same
|
|
2425
|
+
* change without it passes (a state that never applies there). `how` lists
|
|
2426
|
+
* these, and a state that is not one names them.
|
|
2427
|
+
* @param {import('./_settings.mjs').Ctx} ctx
|
|
2428
|
+
* @param {string} slug
|
|
2429
|
+
* @param {any} data
|
|
2430
|
+
* @param {string} part
|
|
2431
|
+
* @returns {string[]}
|
|
2432
|
+
*/
|
|
2433
|
+
export function settableStates(ctx, slug, data, part) {
|
|
2434
|
+
const t = ctx.project.target.get(part);
|
|
2435
|
+
if (!t) return [];
|
|
2436
|
+
const takes = (/** @type {string | undefined} */ state) => {
|
|
2437
|
+
try {
|
|
2438
|
+
checkSetting(ctx, slug, data, 'opacity', '1', {
|
|
2439
|
+
on: part,
|
|
2440
|
+
...(state ? {state} : {}),
|
|
2441
|
+
});
|
|
2442
|
+
return true;
|
|
2443
|
+
} catch {
|
|
2444
|
+
return false;
|
|
2445
|
+
}
|
|
2446
|
+
};
|
|
2447
|
+
const plain = takes(undefined);
|
|
2448
|
+
return [...new Set([...t.states, ...COMMON_STATES])].filter(
|
|
2449
|
+
state => !plain || takes(state),
|
|
2450
|
+
);
|
|
2451
|
+
}
|
|
2452
|
+
|
|
1390
2453
|
/**
|
|
1391
2454
|
* Check one setting and give it back ready to store, or refuse. What it
|
|
1392
2455
|
* accepts, the settings loader takes too: the loader's own check runs last,
|
|
@@ -1398,6 +2461,9 @@ function baseReads(ctx, like, token) {
|
|
|
1398
2461
|
* @param {string | undefined} value
|
|
1399
2462
|
* @param {SetFlags} flags
|
|
1400
2463
|
* @param {boolean} [unset] an undo of one setting: only the identity of the setting is checked
|
|
2464
|
+
* @param {{reads?: ReadonlySet<string>}} [scope] `reads`: the custom
|
|
2465
|
+
* properties the theme itself sets where the value is read, which a var()
|
|
2466
|
+
* in it reads as it reads a design token
|
|
1401
2467
|
* @returns {import('./_settings.mjs').Setting}
|
|
1402
2468
|
*/
|
|
1403
2469
|
export function checkSetting(
|
|
@@ -1408,12 +2474,494 @@ export function checkSetting(
|
|
|
1408
2474
|
value,
|
|
1409
2475
|
flags,
|
|
1410
2476
|
unset = false,
|
|
2477
|
+
{reads} = {},
|
|
1411
2478
|
) {
|
|
1412
2479
|
// Any other dial's value pasted with its property name (`font-size:
|
|
1413
2480
|
// 18px;` for text-size, `color: #e11d48` for accent) is the value: one
|
|
1414
2481
|
// path for every dial (the font dial reads its own below).
|
|
1415
|
-
|
|
1416
|
-
|
|
2482
|
+
// A light and a dark color typed as one value: a token takes both as
|
|
2483
|
+
// light-dark() or one --mode at a time; a color dial takes one color and
|
|
2484
|
+
// makes both modes from it. Never one of them for both.
|
|
2485
|
+
// A light-dark() written with another separator (`light-dark(red /
|
|
2486
|
+
// blue)`, `light-dark(red; blue)`): the pair meant, with a comma.
|
|
2487
|
+
// A dial's own words in any case (ROOMY, MORE, Both, NONE): the word.
|
|
2488
|
+
if (!unset && typeof value === 'string')
|
|
2489
|
+
value = dialWordOf(thing, value) ?? value;
|
|
2490
|
+
if (!unset && typeof value === 'string') {
|
|
2491
|
+
const near =
|
|
2492
|
+
/^\s*light-dark\(\s*([^,;/()]+?)\s*(?:\s\/\s|\/|;)\s*([^,;/()]+?)\s*\)\s*$/i.exec(
|
|
2493
|
+
value,
|
|
2494
|
+
);
|
|
2495
|
+
if (near)
|
|
2496
|
+
refuse(
|
|
2497
|
+
E.ERR_THEME_BAD_VALUE,
|
|
2498
|
+
`"${value}" separates its two colors with something other than a comma; light-dark() takes "light-dark(light, dark)".`,
|
|
2499
|
+
{
|
|
2500
|
+
run: [
|
|
2501
|
+
setLine(
|
|
2502
|
+
slug,
|
|
2503
|
+
thing,
|
|
2504
|
+
`light-dark(${near[1]}, ${near[2]})`,
|
|
2505
|
+
{...flags, mode: undefined},
|
|
2506
|
+
false,
|
|
2507
|
+
),
|
|
2508
|
+
],
|
|
2509
|
+
},
|
|
2510
|
+
);
|
|
2511
|
+
}
|
|
2512
|
+
// One reader for a family list, on the font dial, a family token and a
|
|
2513
|
+
// part's font-family: a weight or a size in it, alone or after a
|
|
2514
|
+
// family, is no family, and a quoted generic is a family named that.
|
|
2515
|
+
const fontish =
|
|
2516
|
+
thing === 'font' ||
|
|
2517
|
+
thing === 'font-family' ||
|
|
2518
|
+
thing.startsWith('--font-family');
|
|
2519
|
+
const listProblem =
|
|
2520
|
+
!unset && typeof value === 'string' && fontish
|
|
2521
|
+
? fontListProblem(value, ctx, thing === 'font')
|
|
2522
|
+
: null;
|
|
2523
|
+
if (listProblem) {
|
|
2524
|
+
const on = flags.on ? ` --on ${flags.on}` : '';
|
|
2525
|
+
refuse(
|
|
2526
|
+
E.ERR_THEME_BAD_VALUE,
|
|
2527
|
+
`"${String(value).trim()}" ${listProblem.why}. ${thing} takes the families${listProblem.families ? ` (${listProblem.families})` : ''}${listProblem.size ? '; a size is set with text-size or a --font-size-* token' : listProblem.rung ? '; a weight is set with headings, font-weight or a --font-weight-* token' : listProblem.style ? '; a style is set with font-style on a part' : ''}.`,
|
|
2528
|
+
{
|
|
2529
|
+
run: [
|
|
2530
|
+
...(listProblem.families
|
|
2531
|
+
? [
|
|
2532
|
+
`${P} set ${slug} ${thing} ${quoteCommandArgument(listProblem.families)}${on}`,
|
|
2533
|
+
]
|
|
2534
|
+
: []),
|
|
2535
|
+
...(thing === 'font' && listProblem.rung
|
|
2536
|
+
? [`${P} set ${slug} headings ${listProblem.rung}`]
|
|
2537
|
+
: []),
|
|
2538
|
+
...(thing === 'font' && listProblem.textSize != null
|
|
2539
|
+
? [`${P} set ${slug} text-size ${listProblem.textSize}`]
|
|
2540
|
+
: []),
|
|
2541
|
+
...(thing === 'font-family' && flags.on && listProblem.style
|
|
2542
|
+
? [`${P} set ${slug} font-style ${listProblem.style}${on}`]
|
|
2543
|
+
: []),
|
|
2544
|
+
...(listProblem.families
|
|
2545
|
+
? []
|
|
2546
|
+
: [`${HOW} ${quoteCommandArgument(thing)}`]),
|
|
2547
|
+
],
|
|
2548
|
+
},
|
|
2549
|
+
);
|
|
2550
|
+
}
|
|
2551
|
+
// A font list with a comma missing before its generic family, or a
|
|
2552
|
+
// generic written with a space, on the font dial or a part's
|
|
2553
|
+
// font-family: the list meant (a family token reads it with its type).
|
|
2554
|
+
if (
|
|
2555
|
+
!unset &&
|
|
2556
|
+
typeof value === 'string' &&
|
|
2557
|
+
(thing === 'font' || thing === 'font-family')
|
|
2558
|
+
) {
|
|
2559
|
+
const fixed = fontListMeant(value);
|
|
2560
|
+
if (fixed)
|
|
2561
|
+
refuse(
|
|
2562
|
+
E.ERR_THEME_BAD_VALUE,
|
|
2563
|
+
`"${value}" names a family that exists nowhere: ${fixed.why}.`,
|
|
2564
|
+
{run: [setLine(slug, thing, fixed.value, flags, false)]},
|
|
2565
|
+
);
|
|
2566
|
+
// A font dial word that names no family (mono, system, rounded): a
|
|
2567
|
+
// part's font-family takes the stack it stands for, never the word.
|
|
2568
|
+
const word = value.trim().toLowerCase();
|
|
2569
|
+
const stack = thing === 'font-family' ? fontStack(word) : null;
|
|
2570
|
+
if (
|
|
2571
|
+
stack &&
|
|
2572
|
+
FONTS[word] &&
|
|
2573
|
+
FONTS[word][0].toLowerCase() !== word &&
|
|
2574
|
+
!isSystemFamily(word)
|
|
2575
|
+
)
|
|
2576
|
+
refuse(
|
|
2577
|
+
E.ERR_THEME_BAD_VALUE,
|
|
2578
|
+
`"${value.trim()}" is a font dial word, not a family: no font is named that. font-family takes the families it stands for (${stack}).`,
|
|
2579
|
+
{run: [setLine(slug, thing, stack, flags, false)]},
|
|
2580
|
+
);
|
|
2581
|
+
}
|
|
2582
|
+
// A light and a dark color on a part's color property (`background`,
|
|
2583
|
+
// `color`, `border-color` …) is that property's light-dark() pair.
|
|
2584
|
+
if (
|
|
2585
|
+
!unset &&
|
|
2586
|
+
typeof value === 'string' &&
|
|
2587
|
+
flags.on &&
|
|
2588
|
+
!flags.mode &&
|
|
2589
|
+
/^(color|background|(background|border|outline|text-decoration|caret|accent|fill|stroke)(-[a-z]+)?-color)$/.test(
|
|
2590
|
+
String(thing).trim().toLowerCase(),
|
|
2591
|
+
)
|
|
2592
|
+
) {
|
|
2593
|
+
const pair = colorPair(value);
|
|
2594
|
+
if (pair && !colorProblem(pair.light) && !colorProblem(pair.dark)) {
|
|
2595
|
+
// A theme with one mode shows one half: that half is the line, as
|
|
2596
|
+
// for a color token.
|
|
2597
|
+
const only = oneModeOfTheme(data);
|
|
2598
|
+
if (only)
|
|
2599
|
+
refuse(
|
|
2600
|
+
E.ERR_THEME_BAD_VALUE,
|
|
2601
|
+
`"${value}" is a light and a dark color; this theme is ${only} only, so it shows the ${only} one.`,
|
|
2602
|
+
{
|
|
2603
|
+
run: [
|
|
2604
|
+
setLine(slug, thing, pair[only], {...flags, mode: undefined}),
|
|
2605
|
+
],
|
|
2606
|
+
},
|
|
2607
|
+
);
|
|
2608
|
+
value = `light-dark(${pair.light}, ${pair.dark})`;
|
|
2609
|
+
}
|
|
2610
|
+
}
|
|
2611
|
+
if (
|
|
2612
|
+
!unset &&
|
|
2613
|
+
typeof value === 'string' &&
|
|
2614
|
+
(PALETTE_DIALS.includes(thing) || isColorToken(thing))
|
|
2615
|
+
) {
|
|
2616
|
+
const pair = colorPair(value);
|
|
2617
|
+
if (pair && !colorProblem(pair.light) && !colorProblem(pair.dark)) {
|
|
2618
|
+
const q = quoteCommandArgument;
|
|
2619
|
+
const on = flags.on ? ` --on ${flags.on}` : '';
|
|
2620
|
+
// A theme with one mode shows one half: that half is the line.
|
|
2621
|
+
const only = oneModeOfTheme(data);
|
|
2622
|
+
if (only)
|
|
2623
|
+
refuse(
|
|
2624
|
+
E.ERR_THEME_BAD_VALUE,
|
|
2625
|
+
`"${value}" is a light and a dark color; this theme is ${only} only, so it shows the ${only} one.`,
|
|
2626
|
+
{run: [`${P} set ${slug} ${thing} ${q(pair[only])}${on}`]},
|
|
2627
|
+
);
|
|
2628
|
+
refuse(
|
|
2629
|
+
E.ERR_THEME_BAD_VALUE,
|
|
2630
|
+
PALETTE_DIALS.includes(thing)
|
|
2631
|
+
? `"${value}" is a light and a dark color; ${thing} takes one color and makes both modes from it.`
|
|
2632
|
+
: `"${value}" is a light and a dark color; ${thing} takes them as light-dark(), or one --mode at a time.`,
|
|
2633
|
+
{
|
|
2634
|
+
run: PALETTE_DIALS.includes(thing)
|
|
2635
|
+
? [
|
|
2636
|
+
`${P} set ${slug} ${thing} ${q(pair.light)}${on}`,
|
|
2637
|
+
...(thing === 'accent'
|
|
2638
|
+
? [
|
|
2639
|
+
`${P} set ${slug} --color-accent ${q(`light-dark(${pair.light}, ${pair.dark})`)}${on}`,
|
|
2640
|
+
]
|
|
2641
|
+
: []),
|
|
2642
|
+
]
|
|
2643
|
+
: [
|
|
2644
|
+
`${P} set ${slug} ${thing} ${q(`light-dark(${pair.light}, ${pair.dark})`)}${on}`,
|
|
2645
|
+
`${P} set ${slug} ${thing} ${q(pair.light)}${on} --mode light`,
|
|
2646
|
+
`${P} set ${slug} ${thing} ${q(pair.dark)}${on} --mode dark`,
|
|
2647
|
+
],
|
|
2648
|
+
},
|
|
2649
|
+
);
|
|
2650
|
+
}
|
|
2651
|
+
}
|
|
2652
|
+
// A value labeled with a word that is not this setting's own name (a
|
|
2653
|
+
// mode, a state, a device, a part, or a word the editor does not read) is
|
|
2654
|
+
// refused with what that word means here, never set with the word dropped.
|
|
2655
|
+
// A property set on a part (`padding 'hover: 4px' --on button`) and the
|
|
2656
|
+
// type tokens (`--font-weight-bold 'dark: 700'`) are read the same way;
|
|
2657
|
+
// a content string is its own text.
|
|
2658
|
+
const partProperty =
|
|
2659
|
+
Boolean(flags.on) && !DIALS[thing] && !thing.startsWith('--');
|
|
2660
|
+
const familyToken = thing.startsWith('--font-family');
|
|
2661
|
+
if (
|
|
2662
|
+
!unset &&
|
|
2663
|
+
typeof value === 'string' &&
|
|
2664
|
+
!/content/.test(thing) &&
|
|
2665
|
+
(DIALS[thing] || partProperty || thing.startsWith('--'))
|
|
2666
|
+
) {
|
|
2667
|
+
const label = valueLabel(value);
|
|
2668
|
+
// Another CSS property's name before the value (`padding 'margin:
|
|
2669
|
+
// 8px'`, `corners 'margin: 24px'`, `--spacing-2 'border-radius: 8px'`)
|
|
2670
|
+
// is that property's value, never this setting's: for every setting, a
|
|
2671
|
+
// pasted property is read only when the setting is what it sets.
|
|
2672
|
+
if (
|
|
2673
|
+
label &&
|
|
2674
|
+
label.word !== thing &&
|
|
2675
|
+
!labelOwned(ctx, thing, label.word, Boolean(partProperty)) &&
|
|
2676
|
+
cssProperties().has(label.word) &&
|
|
2677
|
+
label.rest.trim()
|
|
2678
|
+
)
|
|
2679
|
+
refuse(
|
|
2680
|
+
E.ERR_THEME_BAD_VALUE,
|
|
2681
|
+
`"${value}" is labeled ${label.word}, another property than ${thing}; nothing is set from it.`,
|
|
2682
|
+
{
|
|
2683
|
+
didYouMean: [label.word],
|
|
2684
|
+
run: [setLine(slug, label.word, label.rest.trim(), flags, false)],
|
|
2685
|
+
},
|
|
2686
|
+
);
|
|
2687
|
+
// A CSS property's name before the value (`border-radius: pill`,
|
|
2688
|
+
// `color: #e11d48`, `font: bold 16px Inter`) is read by the paths
|
|
2689
|
+
// below, as a declaration pasted from a stylesheet.
|
|
2690
|
+
if (
|
|
2691
|
+
label &&
|
|
2692
|
+
!ownLabel(thing, label.word) &&
|
|
2693
|
+
!cssProperties().has(label.word)
|
|
2694
|
+
) {
|
|
2695
|
+
const q = quoteCommandArgument;
|
|
2696
|
+
const rest = label.rest;
|
|
2697
|
+
const scope = `${flags.on ? ` --on ${flags.on}` : ''}${flags.when ? ` --when ${flags.when}` : ''}`;
|
|
2698
|
+
// A variant named after the value: the value with --when.
|
|
2699
|
+
if ('when' in label && label.when)
|
|
2700
|
+
refuse(
|
|
2701
|
+
E.ERR_THEME_BAD_VALUE,
|
|
2702
|
+
`"${value}" names a variant after the value; a value for one variant is given with --on <part> --when ${label.when}.`,
|
|
2703
|
+
{
|
|
2704
|
+
didYouMean: ['--when'],
|
|
2705
|
+
run: [
|
|
2706
|
+
flags.on
|
|
2707
|
+
? `${P} set ${slug} ${thing} ${q(rest)} --on ${flags.on} --when ${label.when}`
|
|
2708
|
+
: `${HOW} ${q(`${label.when.split(':').pop()} ${thing}`)}`,
|
|
2709
|
+
],
|
|
2710
|
+
},
|
|
2711
|
+
);
|
|
2712
|
+
const mode = MODE_WORDS[label.word];
|
|
2713
|
+
const colorful =
|
|
2714
|
+
PALETTE_DIALS.includes(thing) ||
|
|
2715
|
+
(thing.startsWith('--') && isColorToken(thing)) ||
|
|
2716
|
+
(partProperty &&
|
|
2717
|
+
/color|^background$|^fill$|^stroke$|shadow/.test(thing));
|
|
2718
|
+
const parts = [...ctx.project.target.keys(), ...Object.keys(FAMILIES)];
|
|
2719
|
+
// A theme with one mode: its own mode's label is the value, as the
|
|
2720
|
+
// theme has no other; the other mode's label names a mode it lacks.
|
|
2721
|
+
const only = oneModeOfTheme(data);
|
|
2722
|
+
if (mode && only) {
|
|
2723
|
+
if (mode === only)
|
|
2724
|
+
return checkSetting(ctx, slug, data, thing, rest, flags, unset);
|
|
2725
|
+
refuse(
|
|
2726
|
+
E.ERR_THEME_BAD_VALUE,
|
|
2727
|
+
`"${label.word}" in "${value}" names the ${mode} mode, which this ${only}-only theme does not show.`,
|
|
2728
|
+
{
|
|
2729
|
+
run: [
|
|
2730
|
+
`${P} set ${slug} mode both`,
|
|
2731
|
+
`${P} set ${slug} ${thing} ${q(rest)}${scope}`,
|
|
2732
|
+
],
|
|
2733
|
+
},
|
|
2734
|
+
);
|
|
2735
|
+
}
|
|
2736
|
+
if (mode && DIALS[thing] && PALETTE_DIALS.includes(thing))
|
|
2737
|
+
refuse(
|
|
2738
|
+
E.ERR_THEME_BAD_VALUE,
|
|
2739
|
+
`"${label.word}" in "${value}" names the ${mode} mode; ${thing} makes both modes from one color.`,
|
|
2740
|
+
{
|
|
2741
|
+
run: [
|
|
2742
|
+
`${P} set ${slug} ${thing} ${q(rest)}${scope}`,
|
|
2743
|
+
...(thing === 'accent'
|
|
2744
|
+
? [
|
|
2745
|
+
`${P} set ${slug} --color-accent ${q(rest)}${scope} --mode ${mode}`,
|
|
2746
|
+
]
|
|
2747
|
+
: []),
|
|
2748
|
+
],
|
|
2749
|
+
},
|
|
2750
|
+
);
|
|
2751
|
+
const level = /^h([1-6])$/.exec(label.word)?.[1];
|
|
2752
|
+
if (level && thing === 'headings') {
|
|
2753
|
+
const w = rest.trim().toLowerCase();
|
|
2754
|
+
refuse(
|
|
2755
|
+
E.ERR_THEME_BAD_VALUE,
|
|
2756
|
+
`"${label.word}" in "${value}" is one heading level; headings sets every level, and one level is set with --on heading --when level:${level}.`,
|
|
2757
|
+
{
|
|
2758
|
+
run:
|
|
2759
|
+
HEADING_WEIGHTS[w] !== undefined
|
|
2760
|
+
? [
|
|
2761
|
+
`${P} set ${slug} font-weight ${HEADING_WEIGHTS[w]} --on heading --when level:${level}`,
|
|
2762
|
+
`${P} set ${slug} headings ${w}`,
|
|
2763
|
+
]
|
|
2764
|
+
: HEADING_TRACKING[w] !== undefined
|
|
2765
|
+
? [
|
|
2766
|
+
`${P} set ${slug} letter-spacing ${q(HEADING_TRACKING[w])} --on heading --when level:${level}`,
|
|
2767
|
+
`${P} set ${slug} headings ${w}`,
|
|
2768
|
+
]
|
|
2769
|
+
: [`${HOW} headings`],
|
|
2770
|
+
},
|
|
2771
|
+
);
|
|
2772
|
+
}
|
|
2773
|
+
if (mode)
|
|
2774
|
+
refuse(
|
|
2775
|
+
E.ERR_THEME_BAD_VALUE,
|
|
2776
|
+
colorful
|
|
2777
|
+
? `"${label.word}" in "${value}" names the ${mode} mode; a value for one mode is given with --mode ${mode}.`
|
|
2778
|
+
: `"${label.word}" in "${value}" names the ${mode} mode, and ${thing} is the same in light and dark.`,
|
|
2779
|
+
{
|
|
2780
|
+
run: [
|
|
2781
|
+
`${P} set ${slug} ${thing} ${q(rest)}${scope}${colorful ? ` --mode ${mode}` : ''}`,
|
|
2782
|
+
],
|
|
2783
|
+
},
|
|
2784
|
+
);
|
|
2785
|
+
if (STATE_WORDS.includes(label.word))
|
|
2786
|
+
refuse(
|
|
2787
|
+
E.ERR_THEME_BAD_VALUE,
|
|
2788
|
+
flags.on
|
|
2789
|
+
? `"${label.word}" in "${value}" is a state; a value for it is given with --state ${label.word}.`
|
|
2790
|
+
: `"${label.word}" in "${value}" is a state; a state is set on a part, with --on <part> --state ${label.word}.`,
|
|
2791
|
+
{
|
|
2792
|
+
run: [
|
|
2793
|
+
flags.on
|
|
2794
|
+
? `${P} set ${slug} ${thing} ${q(rest)}${scope} --state ${label.word}`
|
|
2795
|
+
: `${HOW} ${q(`${label.word} ${thing}`)}`,
|
|
2796
|
+
],
|
|
2797
|
+
},
|
|
2798
|
+
);
|
|
2799
|
+
if (DEVICE_WORDS.includes(label.word))
|
|
2800
|
+
refuse(
|
|
2801
|
+
E.ERR_THEME_BAD_VALUE,
|
|
2802
|
+
`"${label.word}" in "${value}" names a kind of screen; the editor sets ${thing} for every screen, not for one kind.`,
|
|
2803
|
+
{run: [`${P} set ${slug} ${thing} ${q(rest)}${scope}`]},
|
|
2804
|
+
);
|
|
2805
|
+
// `on button: pill`: the part named after `on`.
|
|
2806
|
+
const onPart = /^on-([a-z][a-z0-9-]*)$/.exec(label.word)?.[1];
|
|
2807
|
+
if (onPart && parts.includes(onPart))
|
|
2808
|
+
refuse(
|
|
2809
|
+
E.ERR_THEME_BAD_VALUE,
|
|
2810
|
+
`"${value}" names the part ${onPart}; a value for one part is given with --on ${onPart}.`,
|
|
2811
|
+
{run: [`${P} set ${slug} ${thing} ${q(rest)} --on ${onPart}`]},
|
|
2812
|
+
);
|
|
2813
|
+
if (parts.includes(label.word))
|
|
2814
|
+
refuse(
|
|
2815
|
+
E.ERR_THEME_BAD_VALUE,
|
|
2816
|
+
`"${label.word}" in "${value}" is a part; a value for one part is given with --on ${label.word}.`,
|
|
2817
|
+
{run: [`${P} set ${slug} ${thing} ${q(rest)} --on ${label.word}`]},
|
|
2818
|
+
);
|
|
2819
|
+
// A flag's own name as the label (`state: hover`, `part: card`,
|
|
2820
|
+
// `variant: primary`, `mode: dark`): what that flag does here.
|
|
2821
|
+
const flagWord = {
|
|
2822
|
+
state: 'state',
|
|
2823
|
+
states: 'state',
|
|
2824
|
+
part: 'on',
|
|
2825
|
+
on: 'on',
|
|
2826
|
+
component: 'on',
|
|
2827
|
+
variant: 'when',
|
|
2828
|
+
size: 'when',
|
|
2829
|
+
when: 'when',
|
|
2830
|
+
prop: 'when',
|
|
2831
|
+
mode: 'mode',
|
|
2832
|
+
theme: 'mode',
|
|
2833
|
+
}[label.word];
|
|
2834
|
+
if (
|
|
2835
|
+
flagWord &&
|
|
2836
|
+
(flagWord === 'mode'
|
|
2837
|
+
? Boolean(MODE_WORDS[rest.trim().toLowerCase()])
|
|
2838
|
+
: !otherSettingLabel(thing, value))
|
|
2839
|
+
) {
|
|
2840
|
+
const r = rest.trim().toLowerCase();
|
|
2841
|
+
// The flag's value and the setting's value in one (`state=hover
|
|
2842
|
+
// 4px`): the first word is the flag's, the rest the value.
|
|
2843
|
+
const [fv, ...more] = rest.trim().split(/\s+/);
|
|
2844
|
+
if (flagWord !== 'mode' && more.length > 0) {
|
|
2845
|
+
const flagged =
|
|
2846
|
+
flagWord === 'on'
|
|
2847
|
+
? ` --on ${fv}${flags.when ? ` --when ${flags.when}` : ''}`
|
|
2848
|
+
: flags.on
|
|
2849
|
+
? `${scope} --${flagWord} ${flagWord === 'when' && label.word !== 'when' && label.word !== 'prop' ? `${label.word}:${fv}` : fv}`
|
|
2850
|
+
: null;
|
|
2851
|
+
refuse(
|
|
2852
|
+
E.ERR_THEME_BAD_VALUE,
|
|
2853
|
+
`"${value}" holds the ${flagWord} ${fv} and the value ${more.join(' ')}; the ${flagWord} is given with --${flagWord}.`,
|
|
2854
|
+
{
|
|
2855
|
+
didYouMean: [`--${flagWord}`],
|
|
2856
|
+
run: [
|
|
2857
|
+
flagged
|
|
2858
|
+
? `${P} set ${slug} ${thing} ${q(more.join(' '))}${flagged}`
|
|
2859
|
+
: `${HOW} ${q(`${fv} ${thing}`)}`,
|
|
2860
|
+
],
|
|
2861
|
+
},
|
|
2862
|
+
);
|
|
2863
|
+
}
|
|
2864
|
+
const m = flagWord === 'mode' ? MODE_WORDS[r] : null;
|
|
2865
|
+
const when =
|
|
2866
|
+
flagWord === 'when'
|
|
2867
|
+
? label.word === 'when' || label.word === 'prop'
|
|
2868
|
+
? r
|
|
2869
|
+
: `${label.word}:${r}`
|
|
2870
|
+
: null;
|
|
2871
|
+
refuse(
|
|
2872
|
+
E.ERR_THEME_BAD_VALUE,
|
|
2873
|
+
flagWord === 'mode'
|
|
2874
|
+
? `"${value}" names ${m ? `the ${m} mode` : 'a mode'}, not a value for ${thing}: ${colorful ? `a value for one mode is given with --mode ${m ?? 'dark'}` : `a theme for one mode is set with \`set ${slug} mode ${m ?? 'dark'}-only\``}.`
|
|
2875
|
+
: flagWord === 'state'
|
|
2876
|
+
? `"${value}" names a state, not a value for ${thing}: a value for a state is given with --on <part> --state ${r}.`
|
|
2877
|
+
: flagWord === 'on'
|
|
2878
|
+
? `"${value}" names a part, not a value for ${thing}: a value for one part is given with --on ${r}.`
|
|
2879
|
+
: `"${value}" names a variant, not a value for ${thing}: a value for one variant is given with --on <part> --when ${when}.`,
|
|
2880
|
+
{
|
|
2881
|
+
didYouMean: [`--${flagWord}`],
|
|
2882
|
+
run: [
|
|
2883
|
+
flagWord === 'mode' && !colorful
|
|
2884
|
+
? `${P} set ${slug} mode ${m ?? 'dark'}-only`
|
|
2885
|
+
: `${HOW} ${q(`${r} ${thing}`)}`,
|
|
2886
|
+
],
|
|
2887
|
+
},
|
|
2888
|
+
);
|
|
2889
|
+
}
|
|
2890
|
+
// A Google Fonts family spec (`Inter:wght@400;600`): the family
|
|
2891
|
+
// before the colon.
|
|
2892
|
+
if (
|
|
2893
|
+
(thing === 'font' || familyToken || thing === 'font-family') &&
|
|
2894
|
+
/^(ital,)?wght@|^ital@/i.test(rest)
|
|
2895
|
+
) {
|
|
2896
|
+
const family = String(value).split(':')[0].replace(/\+/g, ' ').trim();
|
|
2897
|
+
refuse(
|
|
2898
|
+
E.ERR_THEME_BAD_VALUE,
|
|
2899
|
+
`"${value}" is a Google Fonts family spec; ${thing} takes the family (${family}). A weight is set with font-weight or a --font-weight-* token.`,
|
|
2900
|
+
{run: [`${P} set ${slug} ${thing} ${q(family)}${scope}`]},
|
|
2901
|
+
);
|
|
2902
|
+
}
|
|
2903
|
+
// A family's own words may hold a colon; only the words above are
|
|
2904
|
+
// read there.
|
|
2905
|
+
if (!familyToken && !otherSettingLabel(thing, value))
|
|
2906
|
+
refuse(
|
|
2907
|
+
E.ERR_THEME_BAD_VALUE,
|
|
2908
|
+
`"${label.word}" in "${value}" is not a name the editor reads for ${thing}; give the value alone.`,
|
|
2909
|
+
{
|
|
2910
|
+
// Only setting names: a part or a state is never a value.
|
|
2911
|
+
didYouMean: nearest(label.word, Object.keys(DIALS)),
|
|
2912
|
+
run: [`${P} set ${slug} ${thing} ${q(rest)}${scope}`],
|
|
2913
|
+
},
|
|
2914
|
+
);
|
|
2915
|
+
}
|
|
2916
|
+
// The setting's own name before its value (`font: Inter`, `Font:
|
|
2917
|
+
// Georgia`) is the value.
|
|
2918
|
+
// (A `font:` shorthand is read whole below, as its family.)
|
|
2919
|
+
if (
|
|
2920
|
+
label &&
|
|
2921
|
+
ownLabel(thing, label.word) &&
|
|
2922
|
+
// A `font:` with a size is the shorthand, read whole below; with
|
|
2923
|
+
// only families (`font: Inter, serif`) it is the label.
|
|
2924
|
+
(label.word !== 'font' || !/\d/.test(label.rest)) &&
|
|
2925
|
+
label.rest.replace(/;+\s*$/, '').trim()
|
|
2926
|
+
)
|
|
2927
|
+
value = label.rest;
|
|
2928
|
+
}
|
|
2929
|
+
if (
|
|
2930
|
+
!unset &&
|
|
2931
|
+
typeof value === 'string' &&
|
|
2932
|
+
(DIALS[thing] || partProperty || thing.startsWith('--')) &&
|
|
2933
|
+
!/content/.test(thing)
|
|
2934
|
+
) {
|
|
2935
|
+
// A value labeled with another setting's name is that setting's, never
|
|
2936
|
+
// this one's (`accent 'neutral: #64748b'`, `--radius-element 'accent:
|
|
2937
|
+
// red'`). The value goes to this setting again only for a dial that
|
|
2938
|
+
// checks it as its own (any word is a font family, so never the font).
|
|
2939
|
+
const other = otherSettingLabel(thing, value);
|
|
2940
|
+
if (other)
|
|
2941
|
+
refuse(
|
|
2942
|
+
E.ERR_THEME_BAD_VALUE,
|
|
2943
|
+
`"${value}" is labeled ${other.thing}, another setting than ${thing}; nothing is set from it.`,
|
|
2944
|
+
{
|
|
2945
|
+
didYouMean: [other.thing],
|
|
2946
|
+
run: [
|
|
2947
|
+
`${P} set ${slug} ${other.thing} ${quoteCommandArgument(other.value)}${flags.on ? ` --on ${flags.on}` : ''}`,
|
|
2948
|
+
// Another setting is not this part's property: the whole theme.
|
|
2949
|
+
...(flags.on && partProperty
|
|
2950
|
+
? [
|
|
2951
|
+
`${P} set ${slug} ${other.thing} ${quoteCommandArgument(other.value)}`,
|
|
2952
|
+
]
|
|
2953
|
+
: []),
|
|
2954
|
+
...(DIALS[thing] && thing !== 'font'
|
|
2955
|
+
? [
|
|
2956
|
+
`${P} set ${slug} ${thing} ${quoteCommandArgument(other.value)}${flags.on ? ` --on ${flags.on}` : ''}`,
|
|
2957
|
+
]
|
|
2958
|
+
: []),
|
|
2959
|
+
],
|
|
2960
|
+
},
|
|
2961
|
+
);
|
|
2962
|
+
}
|
|
2963
|
+
if (!unset && typeof value === 'string' && DIALS[thing]) {
|
|
2964
|
+
const d = thing === 'font' ? null : pastedDeclaration(value);
|
|
1417
2965
|
if (d?.value) value = d.value;
|
|
1418
2966
|
}
|
|
1419
2967
|
// The font dial's value as pasted from a stylesheet (`Georgia, serif;`,
|
|
@@ -1465,7 +3013,16 @@ export function checkSetting(
|
|
|
1465
3013
|
throw e;
|
|
1466
3014
|
}
|
|
1467
3015
|
}
|
|
1468
|
-
const s = checkSettingAsTyped(
|
|
3016
|
+
const s = checkSettingAsTyped(
|
|
3017
|
+
ctx,
|
|
3018
|
+
slug,
|
|
3019
|
+
data,
|
|
3020
|
+
thing,
|
|
3021
|
+
value,
|
|
3022
|
+
flags,
|
|
3023
|
+
unset,
|
|
3024
|
+
reads,
|
|
3025
|
+
);
|
|
1469
3026
|
// A var() with a fallback always gives a value; a name one slip from a
|
|
1470
3027
|
// design token is noted as a likely typo, and the setting stands.
|
|
1471
3028
|
if (!unset && typeof value === 'string' && !s.note) {
|
|
@@ -1485,8 +3042,8 @@ export function checkSetting(
|
|
|
1485
3042
|
function fallbackVarTypo(v, TOKENS) {
|
|
1486
3043
|
for (const [, name] of v.matchAll(/var\(\s*(--[a-z0-9-]+)\s*,/gi)) {
|
|
1487
3044
|
if (name in TOKENS || name.startsWith('--_')) continue;
|
|
1488
|
-
const near = nearest(name, Object.keys(TOKENS)).filter(
|
|
1489
|
-
|
|
3045
|
+
const near = nearest(name, Object.keys(TOKENS)).filter(n =>
|
|
3046
|
+
typoNear(name, n),
|
|
1490
3047
|
);
|
|
1491
3048
|
if (near.length)
|
|
1492
3049
|
return `${name} is not a design token, so its fallback always shows; did you mean ${near[0]}?`;
|
|
@@ -1503,6 +3060,7 @@ function fallbackVarTypo(v, TOKENS) {
|
|
|
1503
3060
|
* @param {string | undefined} value
|
|
1504
3061
|
* @param {SetFlags} flags
|
|
1505
3062
|
* @param {boolean} [unset]
|
|
3063
|
+
* @param {ReadonlySet<string>} [reads] custom properties the theme sets where the value is read
|
|
1506
3064
|
* @returns {import('./_settings.mjs').Setting}
|
|
1507
3065
|
*/
|
|
1508
3066
|
function checkSettingAsTyped(
|
|
@@ -1513,8 +3071,9 @@ function checkSettingAsTyped(
|
|
|
1513
3071
|
value,
|
|
1514
3072
|
flags,
|
|
1515
3073
|
unset = false,
|
|
3074
|
+
reads = undefined,
|
|
1516
3075
|
) {
|
|
1517
|
-
const s = checkOne(ctx, slug, data, thing, value, flags, unset);
|
|
3076
|
+
const s = checkOne(ctx, slug, data, thing, value, flags, unset, reads);
|
|
1518
3077
|
const why = unset ? null : valueProblem(s);
|
|
1519
3078
|
if (why)
|
|
1520
3079
|
refuse(
|
|
@@ -1542,9 +3101,10 @@ function checkSettingAsTyped(
|
|
|
1542
3101
|
* @param {string | undefined} value
|
|
1543
3102
|
* @param {SetFlags} flags
|
|
1544
3103
|
* @param {boolean} unset
|
|
3104
|
+
* @param {ReadonlySet<string>} [reads] custom properties the theme sets where the value is read
|
|
1545
3105
|
* @returns {import('./_settings.mjs').Setting}
|
|
1546
3106
|
*/
|
|
1547
|
-
function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
3107
|
+
function checkOne(ctx, slug, data, thing, value, flags, unset, reads) {
|
|
1548
3108
|
const {C} = ctx;
|
|
1549
3109
|
const TARGET = ctx.project.target;
|
|
1550
3110
|
const TOKENS = ctx.project.core.tokenDefaults;
|
|
@@ -1580,7 +3140,7 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
1580
3140
|
const v = normalValue(thing, value ?? '');
|
|
1581
3141
|
// A var() that misspells a design token would read nothing.
|
|
1582
3142
|
if (!unset) {
|
|
1583
|
-
const bad = unknownVarRef(v, TOKENS, thing);
|
|
3143
|
+
const bad = unknownVarRef(v, TOKENS, thing, reads);
|
|
1584
3144
|
if (bad)
|
|
1585
3145
|
refuse(E.ERR_THEME_UNKNOWN_TOKEN, bad.message, {
|
|
1586
3146
|
didYouMean: bad.near,
|
|
@@ -1628,23 +3188,89 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
1628
3188
|
.toLowerCase();
|
|
1629
3189
|
if (flags.only) s.only = true;
|
|
1630
3190
|
if (flags.mode) {
|
|
1631
|
-
|
|
1632
|
-
|
|
3191
|
+
// Read as any value is: invisible or no-break spaces, quotes around
|
|
3192
|
+
// it, a trailing colon (`'dark '`, `“dark”`, `dark:`).
|
|
3193
|
+
const mode = withoutDebris(normalValueText(String(flags.mode)))
|
|
3194
|
+
.trim()
|
|
3195
|
+
.replace(/^(["'])(.*)\1$/, '$2')
|
|
3196
|
+
.replace(/:+$/, '')
|
|
3197
|
+
.trim()
|
|
3198
|
+
.toLowerCase();
|
|
3199
|
+
if (mode !== 'light' && mode !== 'dark') {
|
|
3200
|
+
// A word that names one of the two (dark-only, darkmode, night) is
|
|
3201
|
+
// that one, by the one mode reader; never the nearest spelling, which
|
|
3202
|
+
// can be the other (night → light).
|
|
3203
|
+
const meant = modeWord(mode);
|
|
3204
|
+
const near = meant ? [meant] : nearest(mode, ['light', 'dark']);
|
|
3205
|
+
// The line for that one mode: for a dial, the one `--mode dark` itself
|
|
3206
|
+
// offers (the color token for that mode), never the both-modes dial.
|
|
3207
|
+
const modeLine = (/** @type {string} */ m) => {
|
|
3208
|
+
if (DIALS[thing] && !unset)
|
|
3209
|
+
try {
|
|
3210
|
+
checkSetting(ctx, slug, data, thing, v, {...flags, mode: m});
|
|
3211
|
+
} catch (e) {
|
|
3212
|
+
const first = /** @type {any} */ (e)?.suggestions?.find(
|
|
3213
|
+
(/** @type {any} */ x) => / --mode (light|dark)\b/.test(x.name),
|
|
3214
|
+
);
|
|
3215
|
+
if (first) return first.name;
|
|
3216
|
+
}
|
|
3217
|
+
return setLine(slug, thing, v, {...s, mode: m}, unset);
|
|
3218
|
+
};
|
|
1633
3219
|
refuse(
|
|
1634
3220
|
E.ERR_THEME_BAD_VALUE,
|
|
1635
3221
|
`--mode takes light or dark, not "${flags.mode}".`,
|
|
1636
3222
|
{
|
|
1637
|
-
didYouMean:
|
|
1638
|
-
// The
|
|
1639
|
-
//
|
|
1640
|
-
run: [
|
|
3223
|
+
didYouMean: near,
|
|
3224
|
+
// The mode it is nearest keeps --mode; only with none near is the
|
|
3225
|
+
// same setting for both modes offered.
|
|
3226
|
+
run: [
|
|
3227
|
+
...(near.length === 1 ? [modeLine(near[0])] : []),
|
|
3228
|
+
// A word that means one mode (night) keeps it: the both-modes
|
|
3229
|
+
// line only for a word read by spelling.
|
|
3230
|
+
...(meant
|
|
3231
|
+
? []
|
|
3232
|
+
: [setLine(slug, thing, v, {...s, mode: undefined}, unset)]),
|
|
3233
|
+
],
|
|
1641
3234
|
},
|
|
1642
3235
|
);
|
|
3236
|
+
}
|
|
1643
3237
|
s.mode = mode;
|
|
1644
3238
|
}
|
|
1645
3239
|
const onFlag = s.on ? ` --on ${s.on}` : '';
|
|
1646
|
-
// A
|
|
1647
|
-
|
|
3240
|
+
// A CSS-wide keyword is no color for one mode: a mode's half takes a
|
|
3241
|
+
// color, and the keyword applies to the whole declaration, in both modes.
|
|
3242
|
+
if (
|
|
3243
|
+
s.mode &&
|
|
3244
|
+
!unset &&
|
|
3245
|
+
CSS_WIDE.includes(
|
|
3246
|
+
String(v ?? '')
|
|
3247
|
+
.trim()
|
|
3248
|
+
.toLowerCase(),
|
|
3249
|
+
)
|
|
3250
|
+
)
|
|
3251
|
+
// A token takes no keyword in any mode (it would be left empty), so for
|
|
3252
|
+
// a token only the color is offered.
|
|
3253
|
+
refuse(
|
|
3254
|
+
E.ERR_THEME_NO_MODE,
|
|
3255
|
+
String(thing).startsWith('--')
|
|
3256
|
+
? `"${String(v).trim()}" is a CSS keyword, which applies in both modes, so it takes no --mode; and a token never takes one. Give the ${s.mode} color.`
|
|
3257
|
+
: `"${String(v).trim()}" is a CSS keyword, which applies in both modes, so it takes no --mode. Give the ${s.mode} color, or set ${thing} ${String(v).trim()} for both modes.`,
|
|
3258
|
+
{
|
|
3259
|
+
run: [
|
|
3260
|
+
String(thing).startsWith('--')
|
|
3261
|
+
? `${HOW} ${thing}`
|
|
3262
|
+
: `${P} set ${slug} ${thing} ${String(v).trim()}${onFlag}${s.when ? ` --when ${s.when}` : ''}${s.state ? ` --state ${s.state}` : ''}`,
|
|
3263
|
+
],
|
|
3264
|
+
},
|
|
3265
|
+
);
|
|
3266
|
+
// A value that already gives both modes takes no --mode (a gradient
|
|
3267
|
+
// holding a light-dark() stop included).
|
|
3268
|
+
if (
|
|
3269
|
+
s.mode &&
|
|
3270
|
+
!unset &&
|
|
3271
|
+
(/^\s*light-dark\(/i.test(v ?? '') ||
|
|
3272
|
+
(/gradient\(/i.test(v ?? '') && /light-dark\(/i.test(v ?? '')))
|
|
3273
|
+
)
|
|
1648
3274
|
refuse(
|
|
1649
3275
|
E.ERR_THEME_NO_MODE,
|
|
1650
3276
|
`"${v}" already gives both modes, so it takes no --mode; drop --mode, or give the ${s.mode} color alone.`,
|
|
@@ -1655,17 +3281,52 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
1655
3281
|
},
|
|
1656
3282
|
);
|
|
1657
3283
|
// A setting saved for a mode the theme no longer has can still be removed.
|
|
1658
|
-
|
|
3284
|
+
// An entry saved for the one mode the theme has ("[dark only]" in a
|
|
3285
|
+
// dark-only theme) can be set again with that --mode, so a doubled one
|
|
3286
|
+
// can be kept: that set replaces both.
|
|
3287
|
+
const sameModeEntry =
|
|
3288
|
+
s.mode &&
|
|
3289
|
+
data.mode === `${s.mode}-only` &&
|
|
3290
|
+
(Array.isArray(data.settings) ? data.settings : []).some(
|
|
3291
|
+
(/** @type {any} */ x) =>
|
|
3292
|
+
x &&
|
|
3293
|
+
x.thing === thing &&
|
|
3294
|
+
x.mode === s.mode &&
|
|
3295
|
+
(x.on ?? null) === (s.on ?? null) &&
|
|
3296
|
+
(x.when ?? null) === (s.when ?? null) &&
|
|
3297
|
+
(x.state ?? null) === (s.state ?? null),
|
|
3298
|
+
);
|
|
3299
|
+
if (s.mode && data.mode !== 'both' && !unset && !sameModeEntry) {
|
|
3300
|
+
// What takes no --mode in any theme (a size, a font, a keyword) is
|
|
3301
|
+
// refused for that, with the command that drops --mode: a theme with
|
|
3302
|
+
// both modes would refuse it too, so its mode is no way out.
|
|
3303
|
+
try {
|
|
3304
|
+
checkSetting(ctx, slug, {...data, mode: 'both'}, thing, v, flags);
|
|
3305
|
+
} catch (e) {
|
|
3306
|
+
if (/** @type {any} */ (e)?.code === E.ERR_THEME_NO_MODE) throw e;
|
|
3307
|
+
}
|
|
1659
3308
|
refuse(
|
|
1660
3309
|
E.ERR_THEME_NO_MODE,
|
|
1661
3310
|
`This theme is ${data.mode}; --mode is for themes with both modes.`,
|
|
1662
|
-
{
|
|
3311
|
+
{
|
|
3312
|
+
run: [
|
|
3313
|
+
// For the mode the theme does not show, both modes first; the
|
|
3314
|
+
// same setting for the theme's own mode keeps where it applies.
|
|
3315
|
+
...((data.mode === 'light-only' ? 'light' : 'dark') !== s.mode
|
|
3316
|
+
? [`${P} set ${slug} mode both`]
|
|
3317
|
+
: []),
|
|
3318
|
+
`${P} set ${slug} ${thing} ${quoteCommandArgument(v)}${onFlag}${s.when ? ` --when ${s.when}` : ''}${s.state ? ` --state ${s.state}` : ''}`,
|
|
3319
|
+
],
|
|
3320
|
+
},
|
|
1663
3321
|
);
|
|
3322
|
+
}
|
|
1664
3323
|
if ((s.when || s.state) && !s.on)
|
|
1665
3324
|
refuse(E.ERR_MISSING_ARGUMENT, '--when and --state need --on <part>.', {
|
|
1666
3325
|
run: [`${HOW} --list parts`],
|
|
1667
3326
|
});
|
|
1668
|
-
|
|
3327
|
+
// --only is checked on a part this Core has; a part in other letters or
|
|
3328
|
+
// misspelt gets the part's own refusal first, with --only kept.
|
|
3329
|
+
if (s.only && (!s.on || TARGET.has(s.on) || FAMILIES[s.on])) {
|
|
1669
3330
|
const fam = s.on ? familyOf(s.on) : null;
|
|
1670
3331
|
if (!fam || FAMILIES[/** @type {string} */ (s.on)])
|
|
1671
3332
|
refuse(
|
|
@@ -1693,29 +3354,99 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
1693
3354
|
// Another case of a part or group, its class name copied from the
|
|
1694
3355
|
// page (`.astryx-card`), or its component (`<Card>`, `Card`): that
|
|
1695
3356
|
// part, as a working command with every flag kept.
|
|
3357
|
+
// Stray punctuation from a copied list ("text-input,") and the dashes
|
|
3358
|
+
// autocorrect types ("text\u2013input") are not part of the name.
|
|
1696
3359
|
const lower = s.on
|
|
3360
|
+
.replace(/[\u2010-\u2015\u2212]/g, '-')
|
|
3361
|
+
.replace(/^[\s,;:.'"`]+|[\s,;:.'"`]+$/g, '')
|
|
1697
3362
|
.trim()
|
|
1698
3363
|
.replace(/^<\/?\s*|\s*\/?>$/g, '')
|
|
1699
3364
|
.replace(/^\./, '')
|
|
1700
3365
|
.replace(/^astryx-/, '')
|
|
1701
3366
|
.replace(/([a-z0-9])([A-Z])/g, '$1-$2')
|
|
1702
3367
|
.toLowerCase();
|
|
1703
|
-
// A
|
|
1704
|
-
|
|
3368
|
+
// A part named in words (dialog header, text inputs) is the dashed
|
|
3369
|
+
// part, read before any group a single word of it names.
|
|
3370
|
+
const dashed = lower.trim().replace(/[\s_]+/g, '-');
|
|
3371
|
+
// A plain word how reads as a part or group (checkboxes: checks):
|
|
3372
|
+
// only the whole value as one word, never one word inside a longer
|
|
3373
|
+
// name (nmber-input is no word for inputs).
|
|
3374
|
+
const byWord = /^[a-z]+$/.test(lower) ? partForWord(lower) : null;
|
|
3375
|
+
// A typo of one whole part or group name is that name.
|
|
3376
|
+
const typoParts = [...TARGET.keys(), ...Object.keys(FAMILIES)].filter(
|
|
3377
|
+
n => n !== lower && n !== dashed && typoNear(dashed, n),
|
|
3378
|
+
);
|
|
1705
3379
|
// A plain plural of a part (cards, dialogs, tabs) is that part.
|
|
1706
|
-
const singular = [
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
3380
|
+
const singular = [lower, dashed]
|
|
3381
|
+
.flatMap(w => [
|
|
3382
|
+
w.replace(/ies$/, 'y'),
|
|
3383
|
+
w.replace(/(ch|sh|x|s)es$/, '$1'),
|
|
3384
|
+
w.replace(/s$/, ''),
|
|
3385
|
+
])
|
|
3386
|
+
.find(x => x !== lower && (TARGET.has(x) || FAMILIES[x]));
|
|
3387
|
+
// Several parts named in one --on (`button, text-input`, `button/
|
|
3388
|
+
// text-input`, `button and text-input`, or spaces): one command per
|
|
3389
|
+
// part named, each checked, never a group that one word of the list
|
|
3390
|
+
// happens to name.
|
|
3391
|
+
const listed = /,|\/|&|\band\b/.test(lower);
|
|
3392
|
+
// (Words with only spaces that name one part, `text inputs`, are
|
|
3393
|
+
// that part.)
|
|
3394
|
+
if (!(TARGET.has(dashed) || FAMILIES[dashed]) && (listed || !singular)) {
|
|
3395
|
+
const pieces = lower
|
|
3396
|
+
.split(/\s*(?:,|\/|&|\band\b)\s*|\s+/)
|
|
3397
|
+
.map(x => x.trim())
|
|
3398
|
+
.filter(Boolean);
|
|
3399
|
+
const partOf = (/** @type {string} */ w) =>
|
|
3400
|
+
TARGET.has(w) || FAMILIES[w]
|
|
3401
|
+
? w
|
|
3402
|
+
: ([w.replace(/ies$/, 'y'), w.replace(/s$/, '')].find(
|
|
3403
|
+
x => x !== w && (TARGET.has(x) || FAMILIES[x]),
|
|
3404
|
+
) ?? null);
|
|
3405
|
+
const found = pieces.map(partOf);
|
|
3406
|
+
const parts = [...new Set(found.filter(x => x != null))];
|
|
3407
|
+
const missing = pieces.filter((_, i) => found[i] == null);
|
|
3408
|
+
if (
|
|
3409
|
+
pieces.length > 1 &&
|
|
3410
|
+
parts.length > 0 &&
|
|
3411
|
+
(missing.length === 0 || (listed && parts.length > 1))
|
|
3412
|
+
)
|
|
3413
|
+
refuse(
|
|
3414
|
+
E.ERR_THEME_UNKNOWN_PART,
|
|
3415
|
+
`"${s.on}" names ${pieces.length} parts; --on takes one part at a time${missing.length ? ` (${missing.map(x => `"${x}"`).join(', ')} is not a part you can style)` : ''}.`,
|
|
3416
|
+
{
|
|
3417
|
+
didYouMean: parts,
|
|
3418
|
+
run: parts
|
|
3419
|
+
.slice(0, 6)
|
|
3420
|
+
.map(on => setLine(slug, thing, v, {...s, on}, unset)),
|
|
3421
|
+
},
|
|
3422
|
+
);
|
|
3423
|
+
}
|
|
1711
3424
|
const named =
|
|
1712
3425
|
TARGET.has(lower) || FAMILIES[lower]
|
|
1713
3426
|
? lower
|
|
1714
|
-
:
|
|
1715
|
-
?
|
|
1716
|
-
:
|
|
1717
|
-
?
|
|
1718
|
-
:
|
|
3427
|
+
: TARGET.has(dashed) || FAMILIES[dashed]
|
|
3428
|
+
? dashed
|
|
3429
|
+
: singular
|
|
3430
|
+
? singular
|
|
3431
|
+
: typoParts.length === 1
|
|
3432
|
+
? typoParts[0]
|
|
3433
|
+
: byWord && (TARGET.has(byWord) || FAMILIES[byWord])
|
|
3434
|
+
? byWord
|
|
3435
|
+
: null;
|
|
3436
|
+
// The page (the body behind every part) is painted by the app shell.
|
|
3437
|
+
if (
|
|
3438
|
+
!named &&
|
|
3439
|
+
/^(page|body|app|background|page-background)$/i.test(s.on) &&
|
|
3440
|
+
TARGET.has('app-shell')
|
|
3441
|
+
)
|
|
3442
|
+
refuse(
|
|
3443
|
+
E.ERR_THEME_UNKNOWN_PART,
|
|
3444
|
+
`"${s.on}" is not a part name; the page behind your parts is app-shell (a background there shows in every AppShell variant).`,
|
|
3445
|
+
{
|
|
3446
|
+
didYouMean: ['app-shell'],
|
|
3447
|
+
run: [setLine(slug, thing, v, {...s, on: 'app-shell'}, unset)],
|
|
3448
|
+
},
|
|
3449
|
+
);
|
|
1719
3450
|
if (named)
|
|
1720
3451
|
refuse(
|
|
1721
3452
|
E.ERR_THEME_UNKNOWN_PART,
|
|
@@ -1725,16 +3456,22 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
1725
3456
|
run: [setLine(slug, thing, v, {...s, on: named}, unset)],
|
|
1726
3457
|
},
|
|
1727
3458
|
);
|
|
3459
|
+
// A plural or another case names the part it means; a typo of one
|
|
3460
|
+
// part leads with the same command on that part.
|
|
3461
|
+
const near = nearest(s.on.toLowerCase().replace(/s$/, ''), [
|
|
3462
|
+
...TARGET.keys(),
|
|
3463
|
+
...Object.keys(FAMILIES),
|
|
3464
|
+
]);
|
|
3465
|
+
const typo = near.filter(n => typoOf(lower, n));
|
|
1728
3466
|
refuse(
|
|
1729
3467
|
E.ERR_THEME_UNKNOWN_PART,
|
|
1730
3468
|
`"${s.on}" is not a part you can style.`,
|
|
1731
3469
|
{
|
|
1732
|
-
|
|
1733
|
-
didYouMean: nearest(s.on.toLowerCase().replace(/s$/, ''), [
|
|
1734
|
-
...TARGET.keys(),
|
|
1735
|
-
...Object.keys(FAMILIES),
|
|
1736
|
-
]),
|
|
3470
|
+
didYouMean: near,
|
|
1737
3471
|
run: [
|
|
3472
|
+
...(typo.length === 1
|
|
3473
|
+
? [setLine(slug, thing, v, {...s, on: typo[0]}, unset)]
|
|
3474
|
+
: []),
|
|
1738
3475
|
`${HOW} --list parts ${quoteCommandArgument(lower.replace(/s$/, '').split('-')[0] || 'button')}`,
|
|
1739
3476
|
`${HOW} ${quoteCommandArgument(s.on)}`,
|
|
1740
3477
|
],
|
|
@@ -1742,6 +3479,26 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
1742
3479
|
);
|
|
1743
3480
|
}
|
|
1744
3481
|
if (s.when) {
|
|
3482
|
+
// A prop and value in other letters, with spaces or `=` between
|
|
3483
|
+
// (`Variant: Primary`, `variant=primary`): the working command.
|
|
3484
|
+
const m = /^\s*([^:=\s]+)\s*[:=]\s*([^:=]+?)\s*$/.exec(s.when);
|
|
3485
|
+
if (m) {
|
|
3486
|
+
const prop = t.props.find(x => x.toLowerCase() === m[1].toLowerCase());
|
|
3487
|
+
const vals = prop ? (C.variantValues(s.on)[prop] ?? []) : [];
|
|
3488
|
+
const val = vals.length
|
|
3489
|
+
? vals.find(x => x.toLowerCase() === m[2].toLowerCase())
|
|
3490
|
+
: m[2];
|
|
3491
|
+
const when = prop && val ? `${prop}:${val}` : null;
|
|
3492
|
+
if (when && when !== s.when)
|
|
3493
|
+
refuse(
|
|
3494
|
+
E.ERR_THEME_UNKNOWN_VARIANT,
|
|
3495
|
+
`--when "${s.when}" is written ${when}.`,
|
|
3496
|
+
{
|
|
3497
|
+
didYouMean: [when],
|
|
3498
|
+
run: [setLine(slug, thing, v, {...s, when}, unset)],
|
|
3499
|
+
},
|
|
3500
|
+
);
|
|
3501
|
+
}
|
|
1745
3502
|
const [p, wv, ...more] = s.when.split(':');
|
|
1746
3503
|
if (!wv || more.length)
|
|
1747
3504
|
refuse(
|
|
@@ -1749,7 +3506,8 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
1749
3506
|
'--when takes <prop>:<value>, such as variant:primary.',
|
|
1750
3507
|
{run: [`${HOW} ${s.on}`]},
|
|
1751
3508
|
);
|
|
1752
|
-
|
|
3509
|
+
const conditions = Object.keys(C.variantValues(s.on));
|
|
3510
|
+
if (!t.props.includes(p) && !conditions.includes(p))
|
|
1753
3511
|
refuse(
|
|
1754
3512
|
E.ERR_THEME_UNKNOWN_VARIANT,
|
|
1755
3513
|
`${s.on} has no prop "${p}". It has: ${t.props.join(', ') || 'none'}.`,
|
|
@@ -1764,12 +3522,21 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
1764
3522
|
);
|
|
1765
3523
|
}
|
|
1766
3524
|
const states = [...t.states, ...COMMON_STATES];
|
|
3525
|
+
// A state the part lists in camelCase (toggle-button's isPressed) typed
|
|
3526
|
+
// in any case or with dashes is that state.
|
|
3527
|
+
const flat = (/** @type {string} */ x) =>
|
|
3528
|
+
x.replace(/[-_\s]/g, '').toLowerCase();
|
|
3529
|
+
if (s.state && !states.includes(s.state)) {
|
|
3530
|
+
const same = states.find(x => flat(x) === flat(String(s.state)));
|
|
3531
|
+
if (same) s.state = same;
|
|
3532
|
+
}
|
|
1767
3533
|
// Other words for a state, mapped to the one the part has; with none
|
|
1768
3534
|
// near, the list of its states (never a guess such as hover).
|
|
1769
3535
|
const SYNONYMS = wordTable(
|
|
1770
3536
|
/** @type {Record<string, string[]>} */ ({
|
|
1771
|
-
pressed: ['active'],
|
|
1772
|
-
press: ['active'],
|
|
3537
|
+
pressed: ['isPressed', 'active'],
|
|
3538
|
+
press: ['isPressed', 'active'],
|
|
3539
|
+
on: ['isPressed', 'checked', 'selected'],
|
|
1773
3540
|
down: ['active'],
|
|
1774
3541
|
clicked: ['active'],
|
|
1775
3542
|
hovered: ['hover'],
|
|
@@ -1781,6 +3548,27 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
1781
3548
|
inactive: ['disabled'],
|
|
1782
3549
|
}),
|
|
1783
3550
|
);
|
|
3551
|
+
// Several states in one --state (`hover,focus-visible`, `hover
|
|
3552
|
+
// focus-visible`): one line per state, the value quoted as typed.
|
|
3553
|
+
const typedStates = String(flags.state ?? '')
|
|
3554
|
+
.split(/\s*(?:,|\/|&|\band\b)\s*|\s+/)
|
|
3555
|
+
.map(x => x.trim().toLowerCase())
|
|
3556
|
+
.filter(Boolean);
|
|
3557
|
+
if (
|
|
3558
|
+
typedStates.length > 1 &&
|
|
3559
|
+
typedStates.every(x => states.includes(x)) &&
|
|
3560
|
+
!states.includes(String(s.state))
|
|
3561
|
+
)
|
|
3562
|
+
refuse(
|
|
3563
|
+
E.ERR_THEME_UNKNOWN_STATE,
|
|
3564
|
+
`"${flags.state}" names ${typedStates.length} states; --state takes one at a time.`,
|
|
3565
|
+
{
|
|
3566
|
+
didYouMean: typedStates,
|
|
3567
|
+
run: typedStates
|
|
3568
|
+
.slice(0, 6)
|
|
3569
|
+
.map(state => setLine(slug, thing, v, {...s, state}, unset)),
|
|
3570
|
+
},
|
|
3571
|
+
);
|
|
1784
3572
|
const meant =
|
|
1785
3573
|
(SYNONYMS[String(s.state ?? '').toLowerCase()] ?? []).find(x =>
|
|
1786
3574
|
states.includes(x),
|
|
@@ -1788,7 +3576,7 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
1788
3576
|
if (s.state && !states.includes(s.state))
|
|
1789
3577
|
refuse(
|
|
1790
3578
|
E.ERR_THEME_UNKNOWN_STATE,
|
|
1791
|
-
`"${s.state}" is not a state of ${s.on}. States: ${
|
|
3579
|
+
`"${s.state}" is not a state of ${s.on}. States: ${settableStates(ctx, slug, data, s.on).join(', ') || 'none'}.`,
|
|
1792
3580
|
{
|
|
1793
3581
|
...(meant ? {didYouMean: [meant]} : {}),
|
|
1794
3582
|
run: [
|
|
@@ -1901,6 +3689,13 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
1901
3689
|
if (parts.length && dead.length === parts.length) {
|
|
1902
3690
|
const bare = Object.keys(own(dead[0])).length === 0;
|
|
1903
3691
|
const within = keys(dead[0], 'focus-within');
|
|
3692
|
+
// A ring Core draws inline on the part at focus time (an indicator's)
|
|
3693
|
+
// is changed by its token, with no state.
|
|
3694
|
+
const inlineAlways = ctx.C.MAP[dead[0]]?.inline?.[''] ?? {};
|
|
3695
|
+
const ringToken = /^focus/.test(s.state)
|
|
3696
|
+
? (inlineAlways[kebab(thing)] ??
|
|
3697
|
+
(Object.values(inlineAlways).includes(thing) ? thing : null))
|
|
3698
|
+
: null;
|
|
1904
3699
|
refuse(
|
|
1905
3700
|
E.ERR_THEME_NO_EFFECT,
|
|
1906
3701
|
bare
|
|
@@ -1916,12 +3711,21 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
1916
3711
|
...(within && !bare && /^focus/.test(s.state)
|
|
1917
3712
|
? {didYouMean: ['focus-within']}
|
|
1918
3713
|
: {}),
|
|
3714
|
+
...(ringToken
|
|
3715
|
+
? {
|
|
3716
|
+
also: [
|
|
3717
|
+
`Core draws ${dead[0]}'s focus ring at focus time from ${ringToken}, set on the part with no state`,
|
|
3718
|
+
],
|
|
3719
|
+
}
|
|
3720
|
+
: {}),
|
|
1919
3721
|
run: [
|
|
1920
|
-
|
|
1921
|
-
?
|
|
1922
|
-
: bare
|
|
1923
|
-
?
|
|
1924
|
-
:
|
|
3722
|
+
ringToken
|
|
3723
|
+
? `${P} set ${slug} ${ringToken} ${quoteCommandArgument(v)} --on ${s.on}${s.mode ? ` --mode ${s.mode}` : ''}`
|
|
3724
|
+
: within && !bare && /^focus/.test(s.state)
|
|
3725
|
+
? setLine(slug, thing, v, {...s, state: 'focus-within'}, unset)
|
|
3726
|
+
: bare
|
|
3727
|
+
? `${HOW} --list parts ${s.on.split('-')[0]}`
|
|
3728
|
+
: `${HOW} ${quoteCommandArgument(s.on)}`,
|
|
1925
3729
|
],
|
|
1926
3730
|
},
|
|
1927
3731
|
);
|
|
@@ -1973,7 +3777,12 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
1973
3777
|
if (s.when) {
|
|
1974
3778
|
const [p, wv, ...more] = s.when.split(':');
|
|
1975
3779
|
const fits = members.some(([m, t]) => {
|
|
1976
|
-
if (
|
|
3780
|
+
if (
|
|
3781
|
+
!wv ||
|
|
3782
|
+
more.length ||
|
|
3783
|
+
!(t.props.includes(p) || p in C.variantValues(m))
|
|
3784
|
+
)
|
|
3785
|
+
return false;
|
|
1977
3786
|
const vals = C.variantValues(m)[p] ?? [];
|
|
1978
3787
|
return !vals.length || vals.includes(wv);
|
|
1979
3788
|
});
|
|
@@ -2131,6 +3940,38 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
2131
3940
|
})(),
|
|
2132
3941
|
},
|
|
2133
3942
|
);
|
|
3943
|
+
// A comparative weight word is the weight (lighter is light, never the
|
|
3944
|
+
// tracking tighter); two words (`bold tight`, `bold, tight`) are a
|
|
3945
|
+
// weight and a tracking, one line each.
|
|
3946
|
+
if (!unset) {
|
|
3947
|
+
const MORE = /** @type {Record<string, string>} */ ({
|
|
3948
|
+
lighter: 'light',
|
|
3949
|
+
thinner: 'light',
|
|
3950
|
+
bolder: 'bold',
|
|
3951
|
+
heavier: 'heavy',
|
|
3952
|
+
wider: 'wide',
|
|
3953
|
+
looser: 'wide',
|
|
3954
|
+
});
|
|
3955
|
+
const words = String(v ?? '')
|
|
3956
|
+
.trim()
|
|
3957
|
+
.toLowerCase()
|
|
3958
|
+
.split(/[\s,]+/)
|
|
3959
|
+
.filter(Boolean)
|
|
3960
|
+
.map(w => MORE[w] ?? w);
|
|
3961
|
+
const known = (/** @type {string} */ w) =>
|
|
3962
|
+
HEADING_WEIGHTS[w] !== undefined || HEADING_TRACKING[w] !== undefined;
|
|
3963
|
+
if (
|
|
3964
|
+
(words.length > 1 || MORE[String(v).trim().toLowerCase()]) &&
|
|
3965
|
+
words.every(known)
|
|
3966
|
+
)
|
|
3967
|
+
refuse(
|
|
3968
|
+
E.ERR_THEME_BAD_VALUE,
|
|
3969
|
+
words.length > 1
|
|
3970
|
+
? `"${v}" is ${words.length} headings values; headings takes one at a time (a weight and a tracking are two settings).`
|
|
3971
|
+
: `"${v}" is the weight ${words[0]}.`,
|
|
3972
|
+
{run: words.map(w => `${P} set ${slug} headings ${w}`)},
|
|
3973
|
+
);
|
|
3974
|
+
}
|
|
2134
3975
|
if (s.mode)
|
|
2135
3976
|
refuse(
|
|
2136
3977
|
E.ERR_THEME_NO_MODE,
|
|
@@ -2168,17 +4009,17 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
2168
4009
|
...Object.keys(HEADING_WEIGHTS),
|
|
2169
4010
|
...Object.keys(HEADING_TRACKING),
|
|
2170
4011
|
];
|
|
2171
|
-
|
|
4012
|
+
// A weight word (extra bold, ultra-bold) is its number, read as
|
|
4013
|
+
// the rung nearest it (800 is heavy).
|
|
4014
|
+
const weightWord = WEIGHT_WORDS[lower.replace(/[\s-]+/g, '')];
|
|
4015
|
+
const weight = /^\d+(\.\d+)?$/.test(lower)
|
|
4016
|
+
? Number(lower)
|
|
4017
|
+
: weightWord
|
|
4018
|
+
? Number(weightWord)
|
|
4019
|
+
: null;
|
|
2172
4020
|
const meant =
|
|
2173
4021
|
words.find(w => w === lower) ??
|
|
2174
|
-
(weight != null
|
|
2175
|
-
? Object.entries(HEADING_WEIGHTS).reduce((a, b) =>
|
|
2176
|
-
Math.abs(Number(b[1]) - weight) <
|
|
2177
|
-
Math.abs(Number(a[1]) - weight)
|
|
2178
|
-
? b
|
|
2179
|
-
: a,
|
|
2180
|
-
)[0]
|
|
2181
|
-
: nearest(lower, words)[0]);
|
|
4022
|
+
(weight != null ? weightRung(weight) : nearest(lower, words)[0]);
|
|
2182
4023
|
refuse(
|
|
2183
4024
|
E.ERR_THEME_BAD_VALUE,
|
|
2184
4025
|
`headings takes ${DIALS.headings.values}, not "${v}".${weight != null && meant ? ` ${meant} sets weight ${HEADING_WEIGHTS[meant]}.` : ''}`,
|
|
@@ -2248,10 +4089,16 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
2248
4089
|
(s.on && typeof def !== 'number' ? own('') : undefined) ??
|
|
2249
4090
|
def;
|
|
2250
4091
|
const at = L.findIndex(([n]) => n === cur);
|
|
4092
|
+
const stepped = at + (v === 'more' ? 1 : -1);
|
|
4093
|
+
if (at >= 0 && stepped >= 0 && stepped < L.length) return L[stepped][0];
|
|
4094
|
+
// At the last rung that way, a step goes nowhere: refused as every
|
|
4095
|
+
// dial refuses it at its end, with the other way.
|
|
2251
4096
|
if (at >= 0)
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
4097
|
+
refuse(
|
|
4098
|
+
E.ERR_THEME_NO_EFFECT,
|
|
4099
|
+
`${thing} is already at its ${v === 'more' ? 'largest' : 'smallest'} step, ${L[at][0]}${s.on ? ` on ${s.on}` : ''}, so "${v}" has nowhere to go.`,
|
|
4100
|
+
{run: [setLine(slug, thing, v === 'more' ? 'less' : 'more', s)]},
|
|
4101
|
+
);
|
|
2255
4102
|
// A size between rungs steps to the next rung that way, never past it.
|
|
2256
4103
|
const px =
|
|
2257
4104
|
typeof cur === 'number'
|
|
@@ -2279,7 +4126,7 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
2279
4126
|
);
|
|
2280
4127
|
refuse(
|
|
2281
4128
|
E.ERR_THEME_BAD_VALUE,
|
|
2282
|
-
`${thing} is ${typeof cur === 'number' ? `${cur}px` : cur}, already ${v === 'more' ? 'above' : 'below'} its ${v === 'more' ? 'largest' : 'smallest'} step (${edge[0]}, ${edge[1]}px), so "${v}" has nowhere to go.${atEnd ? ` It is also the ${v === 'more' ? 'largest' : 'smallest'} size ${thing} takes (${lo} to ${hi}); the base font size token takes any size.` : ' Give an exact size.'}`,
|
|
4129
|
+
`${thing} is ${typeof cur === 'number' ? `${cur}px` : cur}, already ${Math.abs(px - edge[1]) < 0.01 ? 'at' : v === 'more' ? 'above' : 'below'} its ${v === 'more' ? 'largest' : 'smallest'} step (${edge[0]}, ${edge[1]}px), so "${v}" has nowhere to go.${atEnd ? ` It is also the ${v === 'more' ? 'largest' : 'smallest'} size ${thing} takes (${lo} to ${hi}); the base font size token takes any size.` : ' Give an exact size.'}`,
|
|
2283
4130
|
{
|
|
2284
4131
|
run: atEnd
|
|
2285
4132
|
? [
|
|
@@ -2412,9 +4259,12 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
2412
4259
|
: cornerPxOf(onPart.value)
|
|
2413
4260
|
: whole
|
|
2414
4261
|
? radiusAt(base, whole.value, token)
|
|
2415
|
-
: // The base theme's radius
|
|
2416
|
-
//
|
|
2417
|
-
(
|
|
4262
|
+
: // The base theme's own radius on the part, when its rule
|
|
4263
|
+
// gives one; else the radius token's; one it does not give
|
|
4264
|
+
// in px (a var() chain) counts as medium's.
|
|
4265
|
+
(basePartRadiusPx(ctx, base, part, s.when) ??
|
|
4266
|
+
tokenPx(base, token) ??
|
|
4267
|
+
radiusAt(base, 'medium', token));
|
|
2418
4268
|
const rungs = CORNERS.map(
|
|
2419
4269
|
([n]) => /** @type {const} */ ([n, radiusAt(base, n, token)]),
|
|
2420
4270
|
);
|
|
@@ -2435,17 +4285,27 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
2435
4285
|
);
|
|
2436
4286
|
s.value = next ? next[0] : 'medium';
|
|
2437
4287
|
} else {
|
|
4288
|
+
// A value with copy debris (`8px;`): the value without it.
|
|
4289
|
+
if (withoutCopyDebris(v) !== v && withoutCopyDebris(v))
|
|
4290
|
+
refuse(
|
|
4291
|
+
E.ERR_THEME_BAD_VALUE,
|
|
4292
|
+
`"${v}" holds copy debris (a ;, a comment or !important); corners takes the value alone.`,
|
|
4293
|
+
{run: [setLine(slug, 'corners', withoutCopyDebris(v), s)]},
|
|
4294
|
+
);
|
|
2438
4295
|
// A rung in any case, a size in px written any way: the plain form.
|
|
2439
4296
|
const lower = v.toLowerCase();
|
|
2440
|
-
// Any CSS number in px (2e1px, +4px), the shared length parse
|
|
2441
|
-
|
|
4297
|
+
// Any CSS number in px (2e1px, +4px), the shared length parse; a
|
|
4298
|
+
// rem is that many 16px, saved in px.
|
|
4299
|
+
const pxLen = /\d(px|rem)$/.test(lower) ? lengthPx(lower) : null;
|
|
2442
4300
|
if (CORNERS.some(([n]) => n === lower)) s.value = lower;
|
|
2443
|
-
else if (pxLen != null && pxLen >= 0)
|
|
4301
|
+
else if (pxLen != null && pxLen >= 0) {
|
|
2444
4302
|
s.value =
|
|
2445
4303
|
pxLen >= 1000 ? 'pill' : `${Math.round(pxLen * 10000) / 10000}px`;
|
|
4304
|
+
if (/rem$/.test(lower))
|
|
4305
|
+
s.note = `corners ${v.trim()} is saved as ${s.value}`;
|
|
4306
|
+
}
|
|
2446
4307
|
// No rounding, said any way, is square.
|
|
2447
|
-
else if (
|
|
2448
|
-
s.value = 'square';
|
|
4308
|
+
else if (NO_ROUNDING.includes(lower)) s.value = 'square';
|
|
2449
4309
|
else {
|
|
2450
4310
|
// What it most likely means, as a value corners takes: a simple
|
|
2451
4311
|
// calc() of px is worked out.
|
|
@@ -2461,14 +4321,31 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
2461
4321
|
'-': Number(calc[1]) - Number(calc[3]),
|
|
2462
4322
|
}[/** @type {'*' | '/' | '+' | '-'} */ (calc[2])]
|
|
2463
4323
|
: null;
|
|
4324
|
+
// A bare number (0.5, as a pasted --radius: 0.5rem loses its
|
|
4325
|
+
// unit) has no unit to read it by: no size is guessed.
|
|
4326
|
+
const bareNumber = /^[+-]?\d*\.?\d+$/.test(lower);
|
|
2464
4327
|
const len =
|
|
2465
4328
|
calcPx != null && Number.isFinite(calcPx)
|
|
2466
4329
|
? calcPx
|
|
2467
|
-
:
|
|
4330
|
+
: bareNumber
|
|
4331
|
+
? null
|
|
4332
|
+
: lengthPx(lower);
|
|
2468
4333
|
const pct = /^(\d+(?:\.\d+)?)%$/.exec(lower);
|
|
4334
|
+
// Tailwind's names, and rounding said with a negation: what they
|
|
4335
|
+
// mean (rounded-none and not round are square, rounded-full is
|
|
4336
|
+
// pill, rounded-[12px] is 12px).
|
|
4337
|
+
const tw = /^rounded-\[(.+)\]$/.exec(lower)?.[1];
|
|
4338
|
+
const opposite =
|
|
4339
|
+
TAILWIND_RADIUS[lower] ??
|
|
4340
|
+
(tw && lengthPx(tw) != null
|
|
4341
|
+
? `${Math.round(Number(lengthPx(tw)) * 100) / 100}px`
|
|
4342
|
+
: negates(lower) && /round/.test(lower)
|
|
4343
|
+
? 'square'
|
|
4344
|
+
: null);
|
|
2469
4345
|
// A radius below zero means none: square.
|
|
2470
4346
|
const meant =
|
|
2471
|
-
|
|
4347
|
+
opposite ??
|
|
4348
|
+
(len != null
|
|
2472
4349
|
? len <= 0
|
|
2473
4350
|
? 'square'
|
|
2474
4351
|
: `${Math.round(len * 100) / 100}px`
|
|
@@ -2476,17 +4353,34 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
2476
4353
|
? Number(pct[1]) >= 50
|
|
2477
4354
|
? 'pill'
|
|
2478
4355
|
: null
|
|
2479
|
-
:
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
4356
|
+
: bareNumber
|
|
4357
|
+
? null
|
|
4358
|
+
: (nearest(
|
|
4359
|
+
lower,
|
|
4360
|
+
CORNERS.map(([n]) => n),
|
|
4361
|
+
)[0] ?? null));
|
|
2483
4362
|
refuse(
|
|
2484
4363
|
E.ERR_THEME_BAD_VALUE,
|
|
2485
|
-
`corners takes ${DIALS.corners.values}, not "${v}".`,
|
|
4364
|
+
`corners takes ${DIALS.corners.values}, not "${v}"${bareNumber ? ' (a number needs its unit: px or rem)' : ''}.`,
|
|
2486
4365
|
{
|
|
2487
4366
|
...(meant ? {didYouMean: [meant]} : {}),
|
|
2488
4367
|
// The same scope, flags included.
|
|
2489
|
-
|
|
4368
|
+
// Nothing near: how corners, never a stock rung.
|
|
4369
|
+
// A whole bare number gets the line with px, the unit it
|
|
4370
|
+
// most likely meant, and how corners; one below one (a
|
|
4371
|
+
// pasted 0.5rem that lost its unit) has no unit to read it
|
|
4372
|
+
// by: how corners only.
|
|
4373
|
+
run:
|
|
4374
|
+
bareNumber && Number(lower) >= 1
|
|
4375
|
+
? [
|
|
4376
|
+
setLine(slug, 'corners', `${Number(lower)}px`, s),
|
|
4377
|
+
`${HOW} corners`,
|
|
4378
|
+
]
|
|
4379
|
+
: [
|
|
4380
|
+
meant
|
|
4381
|
+
? setLine(slug, 'corners', meant, s)
|
|
4382
|
+
: `${HOW} corners`,
|
|
4383
|
+
],
|
|
2490
4384
|
},
|
|
2491
4385
|
);
|
|
2492
4386
|
}
|
|
@@ -2547,7 +4441,7 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
2547
4441
|
run: [setLine(slug, 'spacing', nearFactor, s)],
|
|
2548
4442
|
},
|
|
2549
4443
|
);
|
|
2550
|
-
else if (
|
|
4444
|
+
else if (NO_SPACE.includes(v.toLowerCase()))
|
|
2551
4445
|
// Spacing scales the theme's space; it never goes to nothing. The
|
|
2552
4446
|
// tightest rung is the nearest that works.
|
|
2553
4447
|
refuse(
|
|
@@ -2568,15 +4462,15 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
2568
4462
|
SPACING.map(([n]) => n),
|
|
2569
4463
|
),
|
|
2570
4464
|
run: [
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
'spacing',
|
|
2574
|
-
nearest(
|
|
4465
|
+
(() => {
|
|
4466
|
+
const near = nearest(
|
|
2575
4467
|
v,
|
|
2576
4468
|
SPACING.map(([n]) => n),
|
|
2577
|
-
)[0]
|
|
2578
|
-
|
|
2579
|
-
|
|
4469
|
+
)[0];
|
|
4470
|
+
return near
|
|
4471
|
+
? setLine(slug, 'spacing', near, s)
|
|
4472
|
+
: `${HOW} spacing`;
|
|
4473
|
+
})(),
|
|
2580
4474
|
],
|
|
2581
4475
|
},
|
|
2582
4476
|
);
|
|
@@ -2601,7 +4495,10 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
2601
4495
|
})(),
|
|
2602
4496
|
},
|
|
2603
4497
|
);
|
|
2604
|
-
|
|
4498
|
+
// With no text-size setting yet, a step starts from the size the base
|
|
4499
|
+
// theme's body text shows (past the last rung, it asks for a size).
|
|
4500
|
+
if (step)
|
|
4501
|
+
s.value = ladder(TEXT_SIZE, ctx.base ? baseTextPx(ctx.base) : 'medium');
|
|
2605
4502
|
else if (
|
|
2606
4503
|
/^\d+\.\d+$/.test(v.trim()) &&
|
|
2607
4504
|
Number(v) >= 10 &&
|
|
@@ -2620,7 +4517,11 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
2620
4517
|
E.ERR_THEME_BAD_VALUE,
|
|
2621
4518
|
`text-size takes ${DIALS['text-size'].values} (a number is the body size in pixels, 10 to 32), not "${v}".`,
|
|
2622
4519
|
(() => {
|
|
2623
|
-
// A rung in other letter case (Medium) or with px is that rung
|
|
4520
|
+
// A rung in other letter case (Medium) or with px is that rung;
|
|
4521
|
+
// a CSS size keyword (x-large) is the size CSS gives it.
|
|
4522
|
+
const keyword = CSS_SIZE_KEYWORDS[v.trim().toLowerCase()];
|
|
4523
|
+
if (keyword != null && keyword >= 10 && keyword <= 32)
|
|
4524
|
+
return {run: [`${P} set ${slug} text-size ${keyword}`]};
|
|
2624
4525
|
const near =
|
|
2625
4526
|
TEXT_SIZE.find(([n]) => n === v.trim().toLowerCase())?.[0] ??
|
|
2626
4527
|
nearest(
|
|
@@ -2632,19 +4533,26 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
2632
4533
|
didYouMean: [near],
|
|
2633
4534
|
run: [`${P} set ${slug} text-size ${near}`],
|
|
2634
4535
|
}
|
|
2635
|
-
: {
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
|
|
4536
|
+
: (() => {
|
|
4537
|
+
// A size typed full-width or with a trailing dot
|
|
4538
|
+
// (18, 18.) is that size; one read any other way (a
|
|
4539
|
+
// unit, a constant calc()) is that size. Nothing read:
|
|
4540
|
+
// how text-size, never a stock size.
|
|
4541
|
+
const t = typedPlain(v).replace(/\.$/, '');
|
|
4542
|
+
const size =
|
|
4543
|
+
/^\d+(\.\d+)?$/.test(t) &&
|
|
4544
|
+
Number(t) >= 10 &&
|
|
4545
|
+
Number(t) <= 32
|
|
4546
|
+
? String(Number(t))
|
|
4547
|
+
: textSizePx(v);
|
|
4548
|
+
return {
|
|
4549
|
+
run: [
|
|
4550
|
+
size != null
|
|
4551
|
+
? `${P} set ${slug} text-size ${size}`
|
|
4552
|
+
: `${HOW} text-size`,
|
|
4553
|
+
],
|
|
4554
|
+
};
|
|
4555
|
+
})();
|
|
2648
4556
|
})(),
|
|
2649
4557
|
);
|
|
2650
4558
|
else if (!TEXT_SIZE.some(([n]) => n === v))
|
|
@@ -2665,13 +4573,51 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
2665
4573
|
.replace(/\s*!important\s*$/i, '')
|
|
2666
4574
|
.replace(/;+\s*$/, '')
|
|
2667
4575
|
.trim()
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
.replace(
|
|
2671
|
-
|
|
4576
|
+
// A hex written 0x… (as in code) is that hex.
|
|
4577
|
+
.replace(/^0x([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i, '#$1')
|
|
4578
|
+
.replace(/^([0-9a-f]{3}|[0-9a-f]{6})$/i, '#$1');
|
|
4579
|
+
// A hex a digit short or over is refused as it is: the digit
|
|
4580
|
+
// missing could be anywhere, so none is made up.
|
|
4581
|
+
// A name of several words with a color among them (`navy blue`)
|
|
4582
|
+
// is that color.
|
|
4583
|
+
// Two names run together (`navyblue`) are the first, as the
|
|
4584
|
+
// spaced form is.
|
|
4585
|
+
const words = v
|
|
4586
|
+
.toLowerCase()
|
|
4587
|
+
.split(/[\s,-]+/)
|
|
4588
|
+
.filter(Boolean);
|
|
4589
|
+
// The words joined (dark red, light-blue, dark-slate-gray) are the
|
|
4590
|
+
// color they name. A word with a scale step (red-500, gray-900) is
|
|
4591
|
+
// no CSS color, and the bare word is another color: none is named.
|
|
4592
|
+
const joined = words.join('');
|
|
4593
|
+
const scaled = words.some(w => /\d/.test(w)) || /^[{]/.test(v.trim());
|
|
4594
|
+
const named =
|
|
4595
|
+
negates(v) || scaled
|
|
4596
|
+
? []
|
|
4597
|
+
: words.length > 1 && COLOR_NAMES.includes(joined)
|
|
4598
|
+
? [joined]
|
|
4599
|
+
: v
|
|
4600
|
+
.toLowerCase()
|
|
4601
|
+
.split(/[\s,-]+/)
|
|
4602
|
+
.flatMap(w =>
|
|
4603
|
+
COLOR_NAMES.includes(w)
|
|
4604
|
+
? [w]
|
|
4605
|
+
: COLOR_NAMES.filter(
|
|
4606
|
+
n =>
|
|
4607
|
+
n.length >= 3 &&
|
|
4608
|
+
w.startsWith(n) &&
|
|
4609
|
+
COLOR_NAMES.includes(w.slice(n.length)),
|
|
4610
|
+
).slice(0, 1),
|
|
4611
|
+
);
|
|
2672
4612
|
const near =
|
|
2673
4613
|
problem.kind === 'unknown'
|
|
2674
|
-
?
|
|
4614
|
+
? /^#?[0-9a-f]{4,8}$/i.test(v.trim())
|
|
4615
|
+
? []
|
|
4616
|
+
: named.length
|
|
4617
|
+
? named.slice(0, 1)
|
|
4618
|
+
: scaled
|
|
4619
|
+
? []
|
|
4620
|
+
: nearest(v.toLowerCase(), COLOR_NAMES)
|
|
2675
4621
|
: [];
|
|
2676
4622
|
// light-dark(a, b): the dial takes one color, from which it makes
|
|
2677
4623
|
// both modes; the light one is offered.
|
|
@@ -2735,12 +4681,23 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
2735
4681
|
if (!step && canApply && (!/^\d{1,3}$/.test(v) || Number(v) > 100)) {
|
|
2736
4682
|
// The value meant: a step in other letters (MORE), or the number
|
|
2737
4683
|
// read as CSS reads it (70%, 7e1), kept in range.
|
|
2738
|
-
|
|
2739
|
-
const
|
|
4684
|
+
// Quotes around it (`"50"`) are not part of it.
|
|
4685
|
+
const bare = v
|
|
4686
|
+
.trim()
|
|
4687
|
+
.replace(/^(["'])(.*)\1$/, '$2')
|
|
4688
|
+
.trim();
|
|
4689
|
+
const word = bare.toLowerCase();
|
|
4690
|
+
const n = cssNumber(bare);
|
|
4691
|
+
// A fraction of one (0.5) is that share of the scale (50), as a
|
|
4692
|
+
// number with no unit from 0 to 1 is read.
|
|
4693
|
+
const scaled =
|
|
4694
|
+
n && n.unit === '' && n.value > 0 && n.value < 1
|
|
4695
|
+
? n.value * 100
|
|
4696
|
+
: n?.value;
|
|
2740
4697
|
const near = ['more', 'less'].includes(word)
|
|
2741
4698
|
? word
|
|
2742
|
-
: n && (n.unit === '' || n.unit === '%')
|
|
2743
|
-
? String(Math.max(0, Math.min(100, Math.round(
|
|
4699
|
+
: n && (n.unit === '' || n.unit === '%') && scaled != null
|
|
4700
|
+
? String(Math.max(0, Math.min(100, Math.round(scaled))))
|
|
2744
4701
|
: null;
|
|
2745
4702
|
refuse(
|
|
2746
4703
|
E.ERR_THEME_BAD_VALUE,
|
|
@@ -2758,8 +4715,24 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
2758
4715
|
E.ERR_THEME_NO_EFFECT,
|
|
2759
4716
|
colors.length
|
|
2760
4717
|
? 'vibrancy sets how saturated the generated colors are, and every color this theme sets is a gray, so it would change nothing. Set a color first.'
|
|
2761
|
-
:
|
|
2762
|
-
|
|
4718
|
+
: (() => {
|
|
4719
|
+
// Colors set as tokens or on parts are values of their own:
|
|
4720
|
+
// vibrancy saturates only what the color dials make.
|
|
4721
|
+
const own = data.settings.find(
|
|
4722
|
+
(/** @type {any} */ x) =>
|
|
4723
|
+
x &&
|
|
4724
|
+
typeof x.value === 'string' &&
|
|
4725
|
+
(/^--color-/.test(String(x.thing)) ||
|
|
4726
|
+
/(^|-)colou?r$|^background(-color)?$|^fill$/.test(
|
|
4727
|
+
String(x.thing),
|
|
4728
|
+
)) &&
|
|
4729
|
+
parseColor(x.value) != null,
|
|
4730
|
+
);
|
|
4731
|
+
return own
|
|
4732
|
+
? `vibrancy sets how saturated the colors made from the color dials (accent, neutral, …) are; this theme's colors are values of their own (${own.thing} ${own.value}), which vibrancy does not change. Set a color dial such as accent first.`
|
|
4733
|
+
: 'vibrancy sets how saturated the generated colors are, and this theme sets no color yet. Set one first.';
|
|
4734
|
+
})(),
|
|
4735
|
+
{run: [`${HOW} accent`]},
|
|
2763
4736
|
);
|
|
2764
4737
|
} else if (thing === 'font') {
|
|
2765
4738
|
if (s.when || s.state)
|
|
@@ -2789,7 +4762,9 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
2789
4762
|
)
|
|
2790
4763
|
: family
|
|
2791
4764
|
? [
|
|
2792
|
-
|
|
4765
|
+
// A font dial word (mono, system, inter) names no family:
|
|
4766
|
+
// the part takes the stack it stands for.
|
|
4767
|
+
`${P} set ${slug} font-family ${quoteCommandArgument(fontStack(v) ?? v)} --on ${s.on}`,
|
|
2793
4768
|
]
|
|
2794
4769
|
: [example];
|
|
2795
4770
|
refuse(
|
|
@@ -2955,6 +4930,19 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
2955
4930
|
{run: [`${P} set ${slug} font inter`]},
|
|
2956
4931
|
);
|
|
2957
4932
|
} else if (thing === 'base') {
|
|
4933
|
+
// A built-in base this project has not installed: install it, then
|
|
4934
|
+
// the same set.
|
|
4935
|
+
if (LIKE.includes(v) && !unset && !baseInstalled(ctx.project, v))
|
|
4936
|
+
refuse(
|
|
4937
|
+
E.ERR_UNKNOWN_THEME,
|
|
4938
|
+
`The ${v} theme is not installed, so ${slug} cannot build on it. Install @astryxdesign/theme-${v}, then set the base again, or build on no theme.`,
|
|
4939
|
+
{
|
|
4940
|
+
run: [
|
|
4941
|
+
...onBuiltIn(ctx.project.cwd, v, `${P} set ${slug} base ${v}`),
|
|
4942
|
+
`${P} set ${slug} base none`,
|
|
4943
|
+
],
|
|
4944
|
+
},
|
|
4945
|
+
);
|
|
2958
4946
|
if (s.on)
|
|
2959
4947
|
refuse(
|
|
2960
4948
|
E.ERR_THEME_BAD_VALUE,
|
|
@@ -3053,16 +5041,46 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
3053
5041
|
],
|
|
3054
5042
|
},
|
|
3055
5043
|
);
|
|
5044
|
+
// A dial typed as a flag (--corners round): the dial is meant.
|
|
5045
|
+
const dial = thing.replace(/^-+/, '');
|
|
5046
|
+
if (
|
|
5047
|
+
!(thing in TOKENS) &&
|
|
5048
|
+
(dial in DIALS || dial === 'base' || dial === 'mode')
|
|
5049
|
+
)
|
|
5050
|
+
refuse(
|
|
5051
|
+
E.ERR_THEME_UNKNOWN_TOKEN,
|
|
5052
|
+
`"${thing}" is not a design token; ${dial} is a dial, typed without dashes.`,
|
|
5053
|
+
{
|
|
5054
|
+
run: [setLine(slug, dial, v, {...s, mode: undefined}, unset)],
|
|
5055
|
+
},
|
|
5056
|
+
);
|
|
3056
5057
|
if (!(thing in TOKENS)) {
|
|
3057
|
-
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
|
|
3061
|
-
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
|
|
5058
|
+
// The editor's own color words: danger is the error role, brand and
|
|
5059
|
+
// primary are the accent (as the danger and accent dials say).
|
|
5060
|
+
const role = thing
|
|
5061
|
+
.replace(/\bdanger\b/, 'error')
|
|
5062
|
+
.replace(/\b(brand|primary)\b/, 'accent');
|
|
5063
|
+
const aliased = role !== thing && role in TOKENS ? role : null;
|
|
5064
|
+
// The filtered list only when it lists something.
|
|
5065
|
+
const word = thing
|
|
5066
|
+
.replace(/^-+(color-)?/, '')
|
|
5067
|
+
.split('-')[0]
|
|
5068
|
+
.trim();
|
|
5069
|
+
const listed =
|
|
5070
|
+
word && Object.keys(TOKENS).some(k => k.includes(word))
|
|
5071
|
+
? `${HOW} --list tokens ${word}`
|
|
5072
|
+
: `${HOW} --list tokens`;
|
|
5073
|
+
refuse(
|
|
5074
|
+
E.ERR_THEME_UNKNOWN_TOKEN,
|
|
5075
|
+
`"${thing}" is not a design token.${aliased ? ` The token for that role is ${aliased}.` : ''}`,
|
|
5076
|
+
{
|
|
5077
|
+
didYouMean: aliased ? [aliased] : nearest(thing, Object.keys(TOKENS)),
|
|
5078
|
+
run: [
|
|
5079
|
+
...(aliased ? [setLine(slug, aliased, v, s, unset)] : []),
|
|
5080
|
+
listed,
|
|
5081
|
+
],
|
|
5082
|
+
},
|
|
5083
|
+
);
|
|
3066
5084
|
}
|
|
3067
5085
|
const type = C.typeOf(thing);
|
|
3068
5086
|
// Only colors differ by mode: a shadow list cannot sit inside
|
|
@@ -3097,6 +5115,7 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
3097
5115
|
slug,
|
|
3098
5116
|
C.propsReading(thing),
|
|
3099
5117
|
multipliedTokens(ctx.project).has(thing),
|
|
5118
|
+
data.settings.some(x => x.thing === thing),
|
|
3100
5119
|
);
|
|
3101
5120
|
checkCycle(thing, v, TOKENS, data, ctx.project.cwd, s);
|
|
3102
5121
|
// With no part data, what reads the token is unknown: save, unchecked.
|
|
@@ -3172,7 +5191,7 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
3172
5191
|
const instead = /reads: ([^.]+)\./.exec(
|
|
3173
5192
|
String(/** @type {any} */ (hard[0][1])?.message ?? ''),
|
|
3174
5193
|
)?.[1];
|
|
3175
|
-
s.note = `${readers.length ? `${readers.join(', ')} read ${thing} and take this change; ` : ''}the editor's render of ${hard.map(([t]) => t).join(', ')} did not read it${instead ? ` (${hard[0][0]} reads ${instead})` : ''}, so those stay as they were; each part is rendered
|
|
5194
|
+
s.note = `${readers.length ? `${readers.join(', ')} read ${thing} and take this change; ` : ''}the editor's render of ${hard.map(([t]) => t).join(', ')} did not read it${instead ? ` (${hard[0][0]} reads ${instead})` : ''}, so those stay as they were; each part is rendered with its default props, each variant value and each look flag, so a state or a combination that reads it may be missed`;
|
|
3176
5195
|
}
|
|
3177
5196
|
if (!s.note && recorded.length) {
|
|
3178
5197
|
const fed = C.feeds(recorded[0][0], thing);
|
|
@@ -3201,6 +5220,8 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
3201
5220
|
s.note = `no part reads ${thing} itself, but ${fed.slice(0, 4).join(', ')} ${fed.length > 1 ? 'are' : 'is'} built from it, so the change shows wherever ${fed.length > 1 ? 'those are' : 'that is'} used${fed.some(k => k.startsWith('--color-syntax-')) ? ' (such as diff rows in code blocks)' : ''}`;
|
|
3202
5221
|
else if (r && data.like && baseReads(ctx, data.like, thing))
|
|
3203
5222
|
s.note = `the ${data.like} theme's own part styles read ${thing}, so the change shows where they use it`;
|
|
5223
|
+
else if (r && coreStylesRead(ctx, thing))
|
|
5224
|
+
s.note = `Core's stylesheet reads ${thing} outside the parts the editor renders (such as the page behind them, the app shell), so the change shows where it is used`;
|
|
3204
5225
|
else if (r && dialWrites(thing))
|
|
3205
5226
|
s.note = `no part of this Core reads ${thing}, and no token it feeds is read, so it changes nothing you see now; it is set as asked because a dial writes it too`;
|
|
3206
5227
|
// The editor's record of what parts read comes from one render of
|
|
@@ -3208,11 +5229,17 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
3208
5229
|
// token is set as asked, and the result says nothing was seen
|
|
3209
5230
|
// reading it.
|
|
3210
5231
|
else if (r)
|
|
3211
|
-
s.note = `no part the editor rendered reads ${thing} (each part is rendered
|
|
5232
|
+
s.note = `no part the editor rendered reads ${thing} (each part is rendered with its default props, each variant value and each look flag, so a state or a combination that reads it may be missed); it is set as asked, and reaches any part that reads it`;
|
|
3212
5233
|
}
|
|
3213
5234
|
return s;
|
|
3214
5235
|
}
|
|
3215
|
-
|
|
5236
|
+
// A property in camel case, or with `_` or spaces for its dashes
|
|
5237
|
+
// (backgroundColor, font_size, "border radius"), is that property: one
|
|
5238
|
+
// reading, so each form gets the same answer.
|
|
5239
|
+
const spelled = kebab(thing.trim())
|
|
5240
|
+
.replace(/[_\s]+/g, '-')
|
|
5241
|
+
.replace(/-+/g, '-');
|
|
5242
|
+
const prop = cssProperties().has(spelled) ? spelled : kebab(thing);
|
|
3216
5243
|
// A token typed without its leading dashes (color-accent,
|
|
3217
5244
|
// text-body-size): the token, when no CSS property has that name.
|
|
3218
5245
|
if (
|
|
@@ -3252,9 +5279,15 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
3252
5279
|
E.ERR_MISSING_ARGUMENT,
|
|
3253
5280
|
`${prop} is a CSS property, so it needs --on <part|group>. For the whole theme use a dial or a token.`,
|
|
3254
5281
|
{
|
|
5282
|
+
// The theme-wide dial or token for it, when there is one; never
|
|
5283
|
+
// a part that was not named.
|
|
3255
5284
|
run: [
|
|
3256
|
-
|
|
3257
|
-
|
|
5285
|
+
...(v && WHOLE_THEME_EQUIVALENT[prop]
|
|
5286
|
+
? [
|
|
5287
|
+
`${P} set ${slug} ${WHOLE_THEME_EQUIVALENT[prop]} ${quoteCommandArgument(v)}`,
|
|
5288
|
+
]
|
|
5289
|
+
: []),
|
|
5290
|
+
`${HOW} ${quoteCommandArgument(prop)}`,
|
|
3258
5291
|
],
|
|
3259
5292
|
},
|
|
3260
5293
|
);
|
|
@@ -3374,9 +5407,141 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
3374
5407
|
},
|
|
3375
5408
|
);
|
|
3376
5409
|
}
|
|
5410
|
+
// A property Core paints with an inline style from a token outranks any
|
|
5411
|
+
// theme rule for it: the token the inline style reads is what changes it.
|
|
5412
|
+
// A paint Core always makes (an indicator's focus ring) is changed by the
|
|
5413
|
+
// token on the part with no state. A paint in a state (a selected table
|
|
5414
|
+
// row's wash) is changed by the token in that state; a component option
|
|
5415
|
+
// can turn that paint off (a table without its row highlight), and then
|
|
5416
|
+
// a rule in the state applies, so the refusal says both.
|
|
5417
|
+
if (!unset) {
|
|
5418
|
+
const family =
|
|
5419
|
+
prop === 'background' || prop === 'background-color'
|
|
5420
|
+
? 'background-color'
|
|
5421
|
+
: prop;
|
|
5422
|
+
const inline = partsOf(ctx, s)
|
|
5423
|
+
.map(t => {
|
|
5424
|
+
const at = ctx.C.MAP[t]?.inline ?? {};
|
|
5425
|
+
const tok =
|
|
5426
|
+
(s.state ? at[s.state]?.[family] : undefined) ?? at['']?.[family];
|
|
5427
|
+
return /** @type {const} */ ([t, tok]);
|
|
5428
|
+
})
|
|
5429
|
+
.find(([, tok]) => tok);
|
|
5430
|
+
if (inline) {
|
|
5431
|
+
const [part, token] = inline;
|
|
5432
|
+
const alwaysInline = Boolean(ctx.C.MAP[part]?.inline?.['']?.[family]);
|
|
5433
|
+
refuse(
|
|
5434
|
+
E.ERR_THEME_NO_EFFECT,
|
|
5435
|
+
alwaysInline
|
|
5436
|
+
? `Core paints ${part}'s ${family} as an inline style from ${token}, which no theme rule can replace; set ${token} on ${part} instead.`
|
|
5437
|
+
: `By default Core paints ${part}'s ${family} when ${s.state} as an inline style from ${token}, which no theme rule can replace, so set ${token} on ${part} when ${s.state} instead; only where the component is set not to paint it (such as a table with its row highlight off) does a ${s.state} ${family} apply, and there ${token} paints nothing.`,
|
|
5438
|
+
{
|
|
5439
|
+
run: [
|
|
5440
|
+
`${P} set ${slug} ${token} ${quoteCommandArgument(v)} --on ${part}${alwaysInline || !s.state ? '' : ` --state ${s.state}`}${s.mode ? ` --mode ${s.mode}` : ''}`,
|
|
5441
|
+
],
|
|
5442
|
+
},
|
|
5443
|
+
);
|
|
5444
|
+
}
|
|
5445
|
+
}
|
|
5446
|
+
// A border on a part that draws none itself, whose edges are drawn by
|
|
5447
|
+
// parts of its own inside it (a date-time input's date and time boxes):
|
|
5448
|
+
// those parts take it.
|
|
5449
|
+
if (
|
|
5450
|
+
!unset &&
|
|
5451
|
+
/^border(?!.*radius)(-|$)/.test(prop) &&
|
|
5452
|
+
partsOf(ctx, s).length === 1
|
|
5453
|
+
) {
|
|
5454
|
+
const part = partsOf(ctx, s)[0];
|
|
5455
|
+
const own = ctx.C.MAP[part]?.own ?? {};
|
|
5456
|
+
const inner = cornerParts(ctx, part).filter(t => t !== part);
|
|
5457
|
+
if (
|
|
5458
|
+
inner.length &&
|
|
5459
|
+
!Object.keys(own).some(k => /^border(?!.*radius)/.test(k))
|
|
5460
|
+
)
|
|
5461
|
+
refuse(
|
|
5462
|
+
E.ERR_THEME_NO_EFFECT,
|
|
5463
|
+
`${part} draws no border of its own; its edges are the borders of ${inner.join(' and ')}, so set ${prop} on ${inner.length > 1 ? 'those parts' : 'that part'}.`,
|
|
5464
|
+
{
|
|
5465
|
+
run: inner.map(t =>
|
|
5466
|
+
setLine(slug, prop, v, {...s, on: t, only: undefined}),
|
|
5467
|
+
),
|
|
5468
|
+
},
|
|
5469
|
+
);
|
|
5470
|
+
}
|
|
5471
|
+
// Padding on a part Core renders as a box CSS draws no padding on (a
|
|
5472
|
+
// table row): the parts inside it with padding of their own take it.
|
|
5473
|
+
if (
|
|
5474
|
+
!unset &&
|
|
5475
|
+
/^padding(-|$)/.test(prop) &&
|
|
5476
|
+
!s.state &&
|
|
5477
|
+
partsOf(ctx, s).length === 1
|
|
5478
|
+
) {
|
|
5479
|
+
const part = partsOf(ctx, s)[0];
|
|
5480
|
+
const inner = paddedParts(ctx, part).filter(t => t !== part);
|
|
5481
|
+
if (inner.length)
|
|
5482
|
+
refuse(
|
|
5483
|
+
E.ERR_THEME_NO_EFFECT,
|
|
5484
|
+
`${part} is drawn as a table row, row group or column, which CSS draws no padding on; its space is the padding of ${inner.join(' and ')}, so set ${prop} on ${inner.length > 1 ? 'those parts' : 'that part'}.`,
|
|
5485
|
+
{
|
|
5486
|
+
run: inner.map(t =>
|
|
5487
|
+
setLine(slug, prop, v, {...s, on: t, only: undefined}),
|
|
5488
|
+
),
|
|
5489
|
+
},
|
|
5490
|
+
);
|
|
5491
|
+
}
|
|
5492
|
+
// A text property on a part whose text is drawn by elements inside it
|
|
5493
|
+
// that set that property themselves from a token (a top nav heading's
|
|
5494
|
+
// title span) never reaches that text: the token, on the part, does.
|
|
5495
|
+
if (
|
|
5496
|
+
!unset &&
|
|
5497
|
+
!s.state &&
|
|
5498
|
+
['font-size', 'font-weight', 'line-height', 'letter-spacing'].includes(
|
|
5499
|
+
prop,
|
|
5500
|
+
)
|
|
5501
|
+
) {
|
|
5502
|
+
const inner = partsOf(ctx, s)
|
|
5503
|
+
.map(t => {
|
|
5504
|
+
const rec = ctx.C.MAP[t];
|
|
5505
|
+
const toks = Object.entries(rec?.inside ?? {})
|
|
5506
|
+
.filter(([, props]) => props.includes(prop))
|
|
5507
|
+
.map(([tok]) => tok);
|
|
5508
|
+
return /** @type {const} */ ([
|
|
5509
|
+
t,
|
|
5510
|
+
rec && !rec.own?.[prop] ? toks : [],
|
|
5511
|
+
]);
|
|
5512
|
+
})
|
|
5513
|
+
.filter(([, toks]) => toks.length);
|
|
5514
|
+
if (inner.length && inner.length === partsOf(ctx, s).length) {
|
|
5515
|
+
const [part, toks] = inner[0];
|
|
5516
|
+
refuse(
|
|
5517
|
+
E.ERR_THEME_NO_EFFECT,
|
|
5518
|
+
`${part}'s text is drawn by elements inside it that set their own ${prop} from ${toks.join(', ')}, so a ${prop} on ${part} never reaches it; set ${toks.length > 1 ? 'one of those tokens' : 'that token'} on ${part} instead.`,
|
|
5519
|
+
{
|
|
5520
|
+
run: toks.map(
|
|
5521
|
+
tok =>
|
|
5522
|
+
`${P} set ${slug} ${tok} ${quoteCommandArgument(v)} --on ${part}`,
|
|
5523
|
+
),
|
|
5524
|
+
},
|
|
5525
|
+
);
|
|
5526
|
+
}
|
|
5527
|
+
}
|
|
5528
|
+
// A text property CSS inherits reaches the parts inside the part that
|
|
5529
|
+
// do not set it themselves (a side nav section's items): the result
|
|
5530
|
+
// says which.
|
|
5531
|
+
if (!unset) {
|
|
5532
|
+
const reach = inheritedReach(ctx, s, prop);
|
|
5533
|
+
if (reach) s.note = reach;
|
|
5534
|
+
}
|
|
3377
5535
|
// Text, headings and links take their color from the color prop.
|
|
3378
5536
|
const textParts = COLOR_PROP_PARTS;
|
|
5537
|
+
// A heading's color is written as the text color tokens its color prop
|
|
5538
|
+
// reads, on the heading alone (compileTheme), so it shows.
|
|
5539
|
+
const headingColor =
|
|
5540
|
+
prop === 'color' &&
|
|
5541
|
+
partsOf(ctx, s).length > 0 &&
|
|
5542
|
+
partsOf(ctx, s).every(t => t === 'heading');
|
|
3379
5543
|
if (
|
|
5544
|
+
!headingColor &&
|
|
3380
5545
|
(prop === 'color' || prop === '-webkit-text-fill-color') &&
|
|
3381
5546
|
partsOf(ctx, s).some(t => textParts.includes(t))
|
|
3382
5547
|
) {
|
|
@@ -3405,67 +5570,21 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
3405
5570
|
}
|
|
3406
5571
|
s.note = `text, heading and link inside ${s.on} keep the color their color prop gives; set --color-text-primary for those`;
|
|
3407
5572
|
}
|
|
3408
|
-
// One mode on a part whose variants each read their own
|
|
3409
|
-
//
|
|
3410
|
-
//
|
|
3411
|
-
// every variant, so any part whose variants read their own value needs
|
|
3412
|
-
// the variant named.
|
|
3413
|
-
// Per-variant colors only: a value that is not a color is refused for
|
|
3414
|
-
// --mode below, with the reason that holds.
|
|
3415
|
-
if (
|
|
3416
|
-
s.mode &&
|
|
3417
|
-
!s.when &&
|
|
3418
|
-
(COLOR_PROPS.test(prop) || (prop === 'background' && isColorValue(v)))
|
|
3419
|
-
) {
|
|
3420
|
-
const g = C.groupOfProp(
|
|
3421
|
-
prop === 'background' ? 'background-color' : prop,
|
|
3422
|
-
);
|
|
3423
|
-
for (const t of partsOf(ctx, s)) {
|
|
3424
|
-
const reads = g
|
|
3425
|
-
? C.partReads(t, g).filter(r => r.props.includes(prop))
|
|
3426
|
-
: [];
|
|
3427
|
-
const variantsOf = (
|
|
3428
|
-
/** @type {(w: string) => string | undefined} */ pick,
|
|
3429
|
-
) => [
|
|
3430
|
-
...new Set(
|
|
3431
|
-
reads
|
|
3432
|
-
.flatMap(r => r.when)
|
|
3433
|
-
.map(pick)
|
|
3434
|
-
.filter(Boolean),
|
|
3435
|
-
),
|
|
3436
|
-
];
|
|
3437
|
-
// Resting reads keyed by the variant alone, and reads in the state.
|
|
3438
|
-
const rest = variantsOf(w => /^variant=([\w-]+)$/.exec(w)?.[1]);
|
|
3439
|
-
const inState = s.state
|
|
3440
|
-
? variantsOf(w =>
|
|
3441
|
-
w.includes(`:${s.state}`)
|
|
3442
|
-
? /(?:^|,)variant=([\w-]+)/.exec(w)?.[1]
|
|
3443
|
-
: undefined,
|
|
3444
|
-
)
|
|
3445
|
-
: [];
|
|
3446
|
-
// A state that does not change this property shows each variant's
|
|
3447
|
-
// resting value, so that is what the other mode must keep.
|
|
3448
|
-
const variants = inState.length ? inState : rest;
|
|
3449
|
-
const perVariant = inState.length
|
|
3450
|
-
? true
|
|
3451
|
-
: rest.length > 0 && !reads.some(r => r.when.includes(''));
|
|
3452
|
-
if (reads.length && variants.length && perVariant)
|
|
3453
|
-
refuse(
|
|
3454
|
-
E.ERR_THEME_NO_MODE,
|
|
3455
|
-
`Each variant of ${t} has its own ${prop}${s.state ? ` when ${s.state}` : ''}, so one mode cannot be set for all of them at once: the other mode would take one variant's color for every variant. Name the variant.`,
|
|
3456
|
-
{
|
|
3457
|
-
run: [
|
|
3458
|
-
`${P} set ${slug} ${prop} ${quoteCommandArgument(v)} --on ${s.on} --when variant:${variants[0]}${s.state ? ` --state ${s.state}` : ''} --mode ${s.mode}`,
|
|
3459
|
-
],
|
|
3460
|
-
},
|
|
3461
|
-
);
|
|
3462
|
-
}
|
|
3463
|
-
}
|
|
5573
|
+
// One mode on a part whose variants each read their own color is
|
|
5574
|
+
// written to each variant's rule with that variant's own other half
|
|
5575
|
+
// (compileTheme), so it needs no variant named.
|
|
3464
5576
|
if (!isSafeValue(v))
|
|
3465
5577
|
refuse(
|
|
3466
5578
|
E.ERR_THEME_BAD_VALUE,
|
|
3467
5579
|
`"${v}" cannot be a CSS value: it has a ; { } < > or a newline, a comment, !important, or an unclosed bracket or quote.`,
|
|
3468
|
-
{
|
|
5580
|
+
{
|
|
5581
|
+
// The value without its copy debris, when that is one.
|
|
5582
|
+
run: [
|
|
5583
|
+
withoutCopyDebris(v) !== v && isSafeValue(withoutCopyDebris(v))
|
|
5584
|
+
? setLine(slug, prop, withoutCopyDebris(v), s)
|
|
5585
|
+
: `${HOW} ${prop}`,
|
|
5586
|
+
],
|
|
5587
|
+
},
|
|
3469
5588
|
);
|
|
3470
5589
|
if (/radius$/.test(prop)) refuseInvisibleCorners(ctx, slug, s, data);
|
|
3471
5590
|
if (step)
|
|
@@ -3536,26 +5655,63 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
3536
5655
|
if (
|
|
3537
5656
|
s.mode &&
|
|
3538
5657
|
!COLOR_PROPS.test(prop) &&
|
|
3539
|
-
!(prop === 'background' && isColorValue(v))
|
|
5658
|
+
!(prop === 'background' && isColorValue(v)) &&
|
|
5659
|
+
// A gradient background (no image file) goes per mode: its colors
|
|
5660
|
+
// are each painted in that mode only (compileTheme).
|
|
5661
|
+
!(
|
|
5662
|
+
/^background(-image)?$/.test(prop) &&
|
|
5663
|
+
/gradient\(/i.test(v) &&
|
|
5664
|
+
!/url\(/i.test(v)
|
|
5665
|
+
)
|
|
3540
5666
|
) {
|
|
3541
5667
|
// A color mixed into the value (a border's) can go per mode on its
|
|
3542
5668
|
// own; a value with none (a radius) is just set for both modes.
|
|
3543
5669
|
const hasColor = /#[0-9a-f]{3,8}\b|rgba?\(|hsla?\(/i.test(v);
|
|
3544
|
-
|
|
3545
|
-
|
|
3546
|
-
|
|
3547
|
-
|
|
3548
|
-
|
|
3549
|
-
|
|
3550
|
-
|
|
5670
|
+
// A gradient's colors sit in its image, above any background-color:
|
|
5671
|
+
// no color step can make them differ per mode.
|
|
5672
|
+
const alt =
|
|
5673
|
+
!hasColor || /gradient\(/i.test(v)
|
|
5674
|
+
? null
|
|
5675
|
+
: prop === 'border' || prop.startsWith('border-')
|
|
5676
|
+
? 'border-color'
|
|
5677
|
+
: prop === 'background'
|
|
5678
|
+
? 'background-color'
|
|
5679
|
+
: null;
|
|
5680
|
+
// On a part whose variants each have their own color, the color per
|
|
5681
|
+
// mode is set for one variant at a time (as that refusal says): the
|
|
5682
|
+
// step names the default one, or the first.
|
|
5683
|
+
let altWhen = '';
|
|
5684
|
+
if (alt && !s.when) {
|
|
5685
|
+
const g = C.groupOfProp(alt);
|
|
5686
|
+
const variants = [
|
|
5687
|
+
...new Set(
|
|
5688
|
+
partsOf(ctx, s).flatMap(t =>
|
|
5689
|
+
(g ? C.partReads(t, g) : [])
|
|
5690
|
+
.filter(r => r.props.includes(alt))
|
|
5691
|
+
.flatMap(r => r.when)
|
|
5692
|
+
.map(w => /^variant=([\w-]+)$/.exec(w)?.[1])
|
|
5693
|
+
.filter(Boolean),
|
|
5694
|
+
),
|
|
5695
|
+
),
|
|
5696
|
+
];
|
|
5697
|
+
const plain = partsOf(ctx, s).some(t =>
|
|
5698
|
+
(g ? C.partReads(t, g) : []).some(
|
|
5699
|
+
r => r.props.includes(alt) && r.when.includes(''),
|
|
5700
|
+
),
|
|
5701
|
+
);
|
|
5702
|
+
if (variants.length && !plain)
|
|
5703
|
+
altWhen = ` --when variant:${variants.includes('default') ? 'default' : variants[0]}`;
|
|
5704
|
+
}
|
|
3551
5705
|
refuse(
|
|
3552
5706
|
E.ERR_THEME_NO_MODE,
|
|
3553
|
-
|
|
5707
|
+
prop === 'box-shadow' || prop === 'border'
|
|
5708
|
+
? `--mode takes a plain color; ${prop} mixes a color with sizes, so --mode cannot hold it. Its color can still differ between light and dark: write it in the value as light-dark(<light>, <dark>).`
|
|
5709
|
+
: `--mode works on plain colors; ${prop} is not a color, so it cannot differ between light and dark.`,
|
|
3554
5710
|
{
|
|
3555
5711
|
run: alt
|
|
3556
5712
|
? [
|
|
3557
5713
|
`${P} set ${slug} ${prop} ${quoteCommandArgument(v.replace(/#[0-9a-f]{3,8}|rgba?\([^)]*\)/i, 'currentcolor'))} --on ${s.on}${whenFlag} # the shape, both modes`,
|
|
3558
|
-
`${P} set ${slug} ${alt} ${quoteCommandArgument(/#[0-9a-f]{3,8}\b|rgba?\([^)]*\)|hsla?\([^)]*\)/i.exec(v)?.[0] ?? '#1f2937')} --on ${s.on}${whenFlag} --mode ${s.mode} # then the color per mode`,
|
|
5714
|
+
`${P} set ${slug} ${alt} ${quoteCommandArgument(/#[0-9a-f]{3,8}\b|rgba?\([^)]*\)|hsla?\([^)]*\)/i.exec(v)?.[0] ?? '#1f2937')} --on ${s.on}${altWhen}${whenFlag} --mode ${s.mode} # then the color per mode${altWhen ? ', for each variant' : ''}`,
|
|
3559
5715
|
]
|
|
3560
5716
|
: [
|
|
3561
5717
|
`${P} set ${slug} ${prop} ${quoteCommandArgument(v)} --on ${s.on}${whenFlag} # both modes`,
|
|
@@ -3563,34 +5719,6 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
3563
5719
|
},
|
|
3564
5720
|
);
|
|
3565
5721
|
}
|
|
3566
|
-
// In a state, the other mode keeps the state's own value there (or a
|
|
3567
|
-
// value set for both modes); with none to keep, the setting would
|
|
3568
|
-
// change that mode too. Without a state, the other mode keeps the
|
|
3569
|
-
// part's plain color.
|
|
3570
|
-
if (
|
|
3571
|
-
s.mode &&
|
|
3572
|
-
s.state &&
|
|
3573
|
-
!partsOf(ctx, s).every(t =>
|
|
3574
|
-
partDefault(ctx, t, camel(prop), s.when, s.state),
|
|
3575
|
-
) &&
|
|
3576
|
-
!data.settings.some(
|
|
3577
|
-
x =>
|
|
3578
|
-
x.thing === prop &&
|
|
3579
|
-
x.on === s.on &&
|
|
3580
|
-
x.when === s.when &&
|
|
3581
|
-
x.state === s.state &&
|
|
3582
|
-
x.mode !== s.mode,
|
|
3583
|
-
)
|
|
3584
|
-
)
|
|
3585
|
-
refuse(
|
|
3586
|
-
E.ERR_THEME_NO_MODE,
|
|
3587
|
-
`${s.on} has no ${prop}${s.state ? ` when ${s.state}` : ''}${s.when ? ` for ${s.when}` : ''} of its own for the ${s.mode === 'light' ? 'dark' : 'light'} mode to keep, so a ${s.mode}-only value would change it too. Set it for both modes.`,
|
|
3588
|
-
{
|
|
3589
|
-
run: [
|
|
3590
|
-
`${P} set ${slug} ${prop} ${quoteCommandArgument(v)} --on ${s.on}${s.when ? ` --when ${s.when}` : ''}${s.state ? ` --state ${s.state}` : ''}`,
|
|
3591
|
-
],
|
|
3592
|
-
},
|
|
3593
|
-
);
|
|
3594
5722
|
return s;
|
|
3595
5723
|
}
|
|
3596
5724
|
// A property written with _ or spaces, a trailing colon, or in camel
|
|
@@ -3607,7 +5735,10 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
3607
5735
|
run: [
|
|
3608
5736
|
unset
|
|
3609
5737
|
? `${P} undo ${slug} ${meant}${onFlag}`
|
|
3610
|
-
:
|
|
5738
|
+
: // The scope typed, never a part nobody named: with no --on,
|
|
5739
|
+
// set's own answer for the property (its whole-theme dial or
|
|
5740
|
+
// token) is folded in when the line is vetted.
|
|
5741
|
+
`${P} set ${slug} ${meant} ${quoteCommandArgument(v || exampleOf(groupOfPropType(meant), meant))}${onFlag}`,
|
|
3611
5742
|
],
|
|
3612
5743
|
},
|
|
3613
5744
|
);
|
|
@@ -3638,13 +5769,18 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
|
|
|
3638
5769
|
// A hint names this theme and the part (card when none is given),
|
|
3639
5770
|
// and a corners value corners takes.
|
|
3640
5771
|
run: hint
|
|
3641
|
-
? hint(
|
|
3642
|
-
|
|
3643
|
-
|
|
3644
|
-
|
|
3645
|
-
|
|
3646
|
-
|
|
3647
|
-
|
|
5772
|
+
? (/corners/.test(String(hint('', ''))) &&
|
|
5773
|
+
v.trim() &&
|
|
5774
|
+
!YES_NO.test(v.trim()) &&
|
|
5775
|
+
cornersRead(v) == null
|
|
5776
|
+
? // A value corners cannot read: how corners, never a stock rung.
|
|
5777
|
+
[`${HOW} corners`]
|
|
5778
|
+
: hint(
|
|
5779
|
+
/corners/.test(String(hint('', ''))) && !YES_NO.test(v.trim())
|
|
5780
|
+
? (cornersRead(v) ?? '')
|
|
5781
|
+
: v,
|
|
5782
|
+
s.on,
|
|
5783
|
+
)
|
|
3648
5784
|
).map(x =>
|
|
3649
5785
|
x
|
|
3650
5786
|
.replace(/<theme>/g, slug)
|
|
@@ -3672,6 +5808,13 @@ function refuseInvisibleCorners(ctx, slug, s, data) {
|
|
|
3672
5808
|
if (ctx.unchecked) return;
|
|
3673
5809
|
const parts = partsOf(ctx, s);
|
|
3674
5810
|
if (!parts.length || parts.some(t => ctx.C.showsCorners(t))) return;
|
|
5811
|
+
// The corners dial on a part whose corners are drawn by parts of its own
|
|
5812
|
+
// inside it (a date-time input's date and time boxes) rounds those.
|
|
5813
|
+
if (
|
|
5814
|
+
s.thing === 'corners' &&
|
|
5815
|
+
parts.some(t => cornerParts(ctx, t).some(x => x !== t))
|
|
5816
|
+
)
|
|
5817
|
+
return;
|
|
3675
5818
|
// An edge the theme gives the part itself shows its corners too.
|
|
3676
5819
|
const edged = data.settings.some(
|
|
3677
5820
|
x =>
|
|
@@ -3772,9 +5915,11 @@ export {familySpaces};
|
|
|
3772
5915
|
* @param {string} v
|
|
3773
5916
|
* @param {Record<string, unknown>} TOKENS
|
|
3774
5917
|
* @param {string} thing
|
|
5918
|
+
* @param {ReadonlySet<string>} [reads] custom properties the theme itself
|
|
5919
|
+
* sets where the value is read: a var() naming one reads it
|
|
3775
5920
|
* @returns {{message: string, near: string[], close: boolean, fixed?: string} | null}
|
|
3776
5921
|
*/
|
|
3777
|
-
export function unknownVarRef(v, TOKENS, thing) {
|
|
5922
|
+
export function unknownVarRef(v, TOKENS, thing, reads) {
|
|
3778
5923
|
// A var() whose name is not a custom property (`var(color-x)`, `var(-x)`,
|
|
3779
5924
|
// `var()`, `var(--)`) makes the whole value invalid: the browser drops
|
|
3780
5925
|
// it. Named with the repaired form when there is one.
|
|
@@ -3793,12 +5938,12 @@ export function unknownVarRef(v, TOKENS, thing) {
|
|
|
3793
5938
|
};
|
|
3794
5939
|
}
|
|
3795
5940
|
for (const [, name, comma] of v.matchAll(/var\(\s*(--[a-z0-9-]+)\s*(,)?/gi)) {
|
|
3796
|
-
if (name in TOKENS || name.startsWith('--_')) continue;
|
|
5941
|
+
if (name in TOKENS || name.startsWith('--_') || reads?.has(name)) continue;
|
|
3797
5942
|
// A fallback always gives a value: never "reads nothing" (a likely
|
|
3798
5943
|
// typo is noted when the setting is made).
|
|
3799
5944
|
if (comma) continue;
|
|
3800
|
-
const near = nearest(name, Object.keys(TOKENS)).filter(
|
|
3801
|
-
|
|
5945
|
+
const near = nearest(name, Object.keys(TOKENS)).filter(n =>
|
|
5946
|
+
typoNear(name, n),
|
|
3802
5947
|
);
|
|
3803
5948
|
if (near.length)
|
|
3804
5949
|
return {
|
|
@@ -3849,78 +5994,38 @@ export function fontFileReason(value) {
|
|
|
3849
5994
|
}
|
|
3850
5995
|
|
|
3851
5996
|
/**
|
|
3852
|
-
* A
|
|
3853
|
-
*
|
|
3854
|
-
* the browser reads only a plain space as one.
|
|
3855
|
-
* @param {string} v
|
|
5997
|
+
* A word as a suggested command quotes it, without the quotes.
|
|
5998
|
+
* @param {string} word
|
|
3856
5999
|
*/
|
|
3857
|
-
|
|
3858
|
-
|
|
3859
|
-
|
|
3860
|
-
const straight = v
|
|
3861
|
-
.replace(/[\u2018\u2019\u201A\u201B]/g, "'")
|
|
3862
|
-
.replace(/[\u201C\u201D\u201E\u201F]/g, '"');
|
|
3863
|
-
// A quoted CSS string (`content: "a\u00A0b"`) keeps what is inside it.
|
|
3864
|
-
return straight
|
|
3865
|
-
.split(/("(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*')/)
|
|
3866
|
-
.map((part, i) =>
|
|
3867
|
-
i % 2
|
|
3868
|
-
? part
|
|
3869
|
-
: part
|
|
3870
|
-
.replace(/[\u200B-\u200D\u2060\uFEFF]/g, '')
|
|
3871
|
-
.replace(/[\u00A0\u1680\u2000-\u200A\u202F\u205F\u3000]/g, ' '),
|
|
3872
|
-
)
|
|
3873
|
-
.join('');
|
|
6000
|
+
function unquoteArg(word) {
|
|
6001
|
+
const m = /^'(.*)'$/s.exec(word.trim());
|
|
6002
|
+
return m ? m[1].replace(/'\\''/g, "'") : word.trim();
|
|
3874
6003
|
}
|
|
3875
6004
|
|
|
6005
|
+
/** Core's stylesheet text, by project folder. @type {Map<string, string>} */
|
|
6006
|
+
const coreStyles = new Map();
|
|
6007
|
+
|
|
3876
6008
|
/**
|
|
3877
|
-
*
|
|
3878
|
-
*
|
|
3879
|
-
*
|
|
3880
|
-
*
|
|
3881
|
-
* Unicode spaces. A thing it cannot read is left as typed.
|
|
3882
|
-
* @param {string} thing
|
|
3883
|
-
* @param {string | undefined} value
|
|
3884
|
-
* @returns {{thing: string, value: string | undefined}}
|
|
6009
|
+
* Whether Core's own stylesheet reads a token anywhere (a part the editor
|
|
6010
|
+
* does not render, such as the app shell behind the page, included).
|
|
6011
|
+
* @param {any} ctx
|
|
6012
|
+
* @param {string} token
|
|
3885
6013
|
*/
|
|
3886
|
-
|
|
3887
|
-
|
|
3888
|
-
let
|
|
3889
|
-
|
|
3890
|
-
|
|
3891
|
-
|
|
3892
|
-
|
|
3893
|
-
|
|
3894
|
-
|
|
3895
|
-
|
|
3896
|
-
|
|
3897
|
-
pasted = true;
|
|
6014
|
+
function coreStylesRead(ctx, token) {
|
|
6015
|
+
const cwd = String(ctx?.project?.cwd ?? '');
|
|
6016
|
+
let css = coreStyles.get(cwd);
|
|
6017
|
+
if (css == null) {
|
|
6018
|
+
try {
|
|
6019
|
+
css = fs.readFileSync(
|
|
6020
|
+
ctx.project.req.resolve('@astryxdesign/core/astryx.css'),
|
|
6021
|
+
'utf8',
|
|
6022
|
+
);
|
|
6023
|
+
} catch {
|
|
6024
|
+
css = '';
|
|
3898
6025
|
}
|
|
6026
|
+
coreStyles.set(cwd, css);
|
|
3899
6027
|
}
|
|
3900
|
-
|
|
3901
|
-
|
|
3902
|
-
t = t.replace(/\s*[:=]+$/, '');
|
|
3903
|
-
pasted = true;
|
|
3904
|
-
}
|
|
3905
|
-
// Dash-like characters where a token's two dashes go (an em or en dash,
|
|
3906
|
-
// a non-breaking hyphen, a minus sign, a full-width hyphen, alone or
|
|
3907
|
-
// mixed with hyphens): `--`.
|
|
3908
|
-
t = t.replace(/^[-\u2010-\u2015\u2212\uFE58\uFE63\uFF0D]+/, run =>
|
|
3909
|
-
/[^-]/.test(run) ? '--' : run,
|
|
6028
|
+
return new RegExp(`var\\(\\s*${token.replace(/[-]/g, '\\-')}\\s*[,)]`).test(
|
|
6029
|
+
css,
|
|
3910
6030
|
);
|
|
3911
|
-
// A token typed as a var() reference.
|
|
3912
|
-
const ref = /^var\(\s*(--[a-z0-9-]+)\s*\)$/i.exec(t);
|
|
3913
|
-
if (ref) t = ref[1];
|
|
3914
|
-
if (pasted && typeof v === 'string')
|
|
3915
|
-
v = v.replace(/\s*!\s*important\s*;?\s*$/i, '').replace(/;+\s*$/, '');
|
|
3916
|
-
return {thing: t, value: v};
|
|
3917
|
-
}
|
|
3918
|
-
|
|
3919
|
-
/**
|
|
3920
|
-
* A word as a suggested command quotes it, without the quotes.
|
|
3921
|
-
* @param {string} word
|
|
3922
|
-
*/
|
|
3923
|
-
function unquoteArg(word) {
|
|
3924
|
-
const m = /^'(.*)'$/s.exec(word.trim());
|
|
3925
|
-
return m ? m[1].replace(/'\\''/g, "'") : word.trim();
|
|
3926
6031
|
}
|