soma-core 1.6.0 → 2.0.1
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 +28 -19
- package/bin/codegen.cjs +191 -0
- package/bin/eject.cjs +25 -12
- package/bin/service-codegen.cjs +98 -0
- package/bin/soma-lsp.cjs +140 -23
- package/bin/soma-runtime.cjs +193 -0
- package/bin/soma-sync-runtime.cjs +130 -0
- package/bin/soma.cjs +200 -13
- package/bin/soma.ts +182 -0
- package/core/build/compiler/flat-page.ts +305 -0
- package/core/build/compiler/full-manifest-builder.ts +68 -27
- package/core/build/{blocks → compiler}/html-index.ts +64 -15
- package/core/build/compiler/page-assets.ts +30 -7
- package/core/build/compiler/page-base-resolver.ts +11 -0
- package/core/build/compiler/page-declaration-compiler.ts +265 -226
- package/core/build/compiler/rollup-plugin-soma.ts +7 -2
- package/core/build/compiler/soma-manifest-webpack-plugin.js +114 -229
- package/core/build/compiler/soma-precompile.js +3737 -1729
- package/core/build/compiler/soma-precompile.ts +15 -20
- package/core/build/compiler/soma-rspack-yaml-loader.js +4 -3
- package/core/build/compiler/soma-webpack-loader.js +8 -4
- package/core/build/compiler/vite-plugin-soma.ts +8 -8
- package/core/build/component/component-graph.ts +1 -1
- package/core/build/component-tree/artifact-codec.ts +9 -42
- package/core/build/component-tree/collection-binding-lowerer.ts +1 -1
- package/core/build/component-tree/definition-preparation.ts +4 -5
- package/core/build/component-tree/parser.ts +1 -1
- package/core/build/component-tree/registry-snapshot.ts +45 -10
- package/core/build/component-tree/source-preflight.ts +2 -90
- package/core/build/component-tree/structure-topology.ts +1 -1
- package/core/build/eject/plan-eject.ts +9 -11
- package/core/build/lsp/component-tree-service.ts +4 -1
- package/core/build/lsp/component-tree.cjs +1 -1
- package/core/build/lsp/cross-file-diagnostics.cjs +5 -21
- package/core/build/lsp/soma-declaration.cjs +50 -46
- package/core/build/lsp/std-completion.generated.json +26 -0
- package/core/build/lsp/ui-yaml-completion.cjs +25 -37
- package/core/client/a11y/a11y-config.ts +50 -0
- package/core/client/a11y/announcer.ts +140 -0
- package/core/client/a11y/dom-id.ts +31 -0
- package/core/client/a11y/index.ts +40 -0
- package/core/client/a11y/motion-hook.ts +48 -0
- package/core/client/a11y/motion.ts +95 -0
- package/core/client/base/SomaPageRootBase.ts +44 -2
- package/core/client/base/index.ts +10 -8
- package/core/client/behavior/adapter-collection.ts +65 -0
- package/core/client/behavior/adapter-popper.ts +60 -0
- package/core/client/behavior/aria-hide-outside.ts +144 -0
- package/core/client/behavior/css-escape.ts +51 -0
- package/core/client/behavior/focus-scope.ts +433 -0
- package/core/client/behavior/focus-traversal.ts +68 -0
- package/core/client/behavior/index.ts +109 -0
- package/core/client/behavior/layer-stack.ts +234 -0
- package/core/client/behavior/overlay-host/index.ts +192 -0
- package/core/client/behavior/overlay-host/port.ts +76 -0
- package/core/client/behavior/overlay-wiring.ts +186 -0
- package/core/client/behavior/port.ts +85 -0
- package/core/client/behavior/positioner.ts +32 -0
- package/core/client/behavior/presence.ts +197 -0
- package/core/client/behavior/zag/adapter-vanilla.ts +96 -0
- package/core/client/behavior/zag/layer-bridge.ts +51 -0
- package/core/client/behavior/zag/machine-host.ts +69 -0
- package/core/client/behavior/zag/machines.ts +52 -0
- package/core/client/compiler/manifest-compiler.ts +28 -24
- package/core/client/component/adapter/adapt.ts +79 -0
- package/core/client/component/adapter/index.ts +3 -0
- package/core/client/component/adapter/types.ts +37 -0
- package/core/client/component/adapter/web-component.ts +130 -0
- package/core/client/component/component-definition.types.ts +27 -5
- package/core/client/component/component-expander.ts +23 -15
- package/core/client/component/component-manager.ts +215 -35
- package/core/client/component/component-pack.ts +57 -215
- package/core/client/component/component-registry.ts +52 -28
- package/core/client/component/projection-admission.ts +63 -0
- package/core/client/component/projection-registry.ts +653 -0
- package/core/client/component/projection.types.ts +48 -0
- package/core/client/component/region-unavailable.ts +37 -0
- package/core/client/component/scoped-adapter.ts +3 -3
- package/core/client/component/structure-adapter.ts +93 -8
- package/core/client/container/IContainerAdapter.ts +4 -3
- package/core/client/container/SomaContainerAdapter.ts +20 -20
- package/core/client/data/collection-payload.ts +2 -0
- package/core/client/data/data-object-resolver.ts +827 -286
- package/core/client/data/data-polling.ts +110 -0
- package/core/client/data/data-subscriptions.ts +98 -0
- package/core/client/data/data-write-actions.ts +118 -0
- package/core/client/data/envelope-failure.ts +48 -0
- package/core/client/data/format-config.ts +62 -0
- package/core/client/data/region-scope-port.ts +265 -0
- package/core/client/data/region-scope-views.ts +96 -0
- package/core/client/data/role-gate.ts +44 -0
- package/core/client/data/write-outcome-store.ts +101 -0
- package/core/client/data/write-outcome.ts +175 -0
- package/core/client/engine/asset-resolver.ts +12 -21
- package/core/client/engine/dom-renderer.ts +57 -29
- package/core/client/engine/event-engine.ts +335 -16
- package/core/client/engine/locale-text-binder.ts +168 -0
- package/core/client/engine/render-engine.ts +6 -1
- package/core/client/engine/row-range.ts +11 -0
- package/core/client/engine/runtime-builder.ts +10 -13
- package/core/client/engine/soma-bootstrap.ts +1229 -292
- package/core/client/engine/step-runner.ts +90 -12
- package/core/client/engine/style-binder.ts +2 -162
- package/core/client/engine/timer-engine.ts +2 -1
- package/core/client/engines/chart/adapter-echarts.ts +144 -0
- package/core/client/engines/chart/echarts-subpaths.d.ts +3 -0
- package/core/client/engines/chart/index.ts +90 -0
- package/core/client/engines/chart/kind-modules.ts +74 -0
- package/core/client/engines/chart/port.ts +44 -0
- package/core/client/engines/diff/adapter-jsdiff.ts +35 -0
- package/core/client/engines/diff/index.ts +33 -0
- package/core/client/engines/diff/port.ts +26 -0
- package/core/client/engines/dnd/adapter-pragmatic.ts +159 -0
- package/core/client/engines/dnd/index.ts +67 -0
- package/core/client/engines/dnd/port.ts +45 -0
- package/core/client/engines/engine-adapters.ts +29 -0
- package/core/client/engines/load.ts +44 -0
- package/core/client/engines/qrcode/adapter-qrcode-generator.ts +52 -0
- package/core/client/engines/qrcode/index.ts +30 -0
- package/core/client/engines/qrcode/port.ts +27 -0
- package/core/client/engines/table/adapter-tanstack.ts +132 -0
- package/core/client/engines/table/index.ts +80 -0
- package/core/client/engines/table/port.ts +55 -0
- package/core/client/engines/temporal/adapter-polyfill.ts +158 -0
- package/core/client/engines/temporal/index.ts +84 -0
- package/core/client/engines/temporal/port.ts +53 -0
- package/core/client/engines/virtual/adapter-tanstack.ts +133 -0
- package/core/client/engines/virtual/index.ts +43 -0
- package/core/client/engines/virtual/port.ts +43 -0
- package/core/client/format/formatter.ts +32 -0
- package/core/client/format/index.ts +26 -0
- package/core/client/format/zoned.ts +10 -0
- package/core/client/host-bridge/index.ts +17 -0
- package/core/client/host-bridge/load-host-domain-class.ts +15 -4
- package/core/client/host-bridge/resolve-host-bootstrap.ts +63 -11
- package/core/client/host-bridge/soma-app-host.stub.ts +3 -0
- package/core/client/host-bridge/soma-bootstrap-from-app.ts +25 -0
- package/core/client/infra/auth/IAuthService.ts +18 -13
- package/core/client/infra/auth/TokenAuthService.ts +126 -112
- package/core/client/infra/config/SomaConfig.ts +16 -0
- package/core/client/infra/config/feature-flags.ts +28 -0
- package/core/client/infra/http/IHttpClient.ts +2 -0
- package/core/client/infra/http/SomaHttpService.ts +1 -0
- package/core/client/infra/i18n/II18n.ts +24 -6
- package/core/client/infra/i18n/builtin-locale.ts +31 -0
- package/core/client/infra/i18n/index.ts +4 -0
- package/core/client/infra/i18n/interpolate.ts +28 -0
- package/core/client/infra/i18n/locale-catalog.ts +230 -0
- package/core/client/infra/i18n/pack-locales.ts +117 -0
- package/core/client/infra/identity/identity-port.ts +178 -0
- package/core/client/infra/notify/DefaultNotifyService.ts +86 -31
- package/core/client/infra/notify/INotifyService.ts +2 -14
- package/core/client/infra/notify/notify-declaration.ts +37 -0
- package/core/client/infra/permission/SomaPermission.ts +58 -48
- package/core/client/infra/router/IRouter.ts +24 -19
- package/core/client/infra/router/SomaRouter.ts +78 -66
- package/core/client/keyboard/collection.ts +197 -0
- package/core/client/keyboard/compose-keys.ts +68 -0
- package/core/client/keyboard/cursor.ts +117 -0
- package/core/client/keyboard/delegate.ts +195 -0
- package/core/client/keyboard/ime.ts +8 -0
- package/core/client/keyboard/index.ts +74 -0
- package/core/client/keyboard/intents.ts +60 -0
- package/core/client/keyboard/matrix.ts +269 -0
- package/core/client/keyboard/submit.ts +30 -0
- package/core/client/keyboard/typeahead.ts +203 -0
- package/core/client/keyboard/wiring.ts +327 -0
- package/core/client/middleware/createPermissionMiddleware.ts +20 -11
- package/core/client/mount/domain-rule.ts +43 -0
- package/core/client/mount/index.ts +3 -0
- package/core/client/mount/mount-page.ts +163 -0
- package/core/client/mount/types.ts +93 -0
- package/core/client/observability/runtime-observer.ts +136 -0
- package/core/client/parser/confirm-spec.ts +139 -0
- package/core/client/parser/data-config-parser.ts +415 -216
- package/core/client/parser/duration.ts +2 -16
- package/core/client/parser/page-state-parser.ts +59 -64
- package/core/client/parser/pipeline-parser.ts +183 -4
- package/core/client/parser/style-config-parser.ts +14 -80
- package/core/client/parser/subscribe-parser.ts +83 -0
- package/core/client/parser/ui-config-parser.ts +246 -242
- package/core/client/pipes/pipe-registry.ts +301 -32
- package/core/client/registry/declaration-renderer.ts +20 -8
- package/core/client/registry/page-lifecycle.ts +4 -4
- package/core/client/registry/remote-page.ts +4 -4
- package/core/client/render-ports/index.ts +18 -0
- package/core/client/render-ports/notify-renderer.ts +45 -0
- package/core/client/render-ports/region-fallback.ts +8 -0
- package/core/client/render-ports/scheduling/prompt-queue.ts +102 -0
- package/core/client/render-ports/scheduling/toast-scheduler.ts +253 -0
- package/core/client/runtime/SomaRuntimeServices.ts +180 -16
- package/core/client/runtime/SomaSnapshotStore.ts +100 -100
- package/core/client/runtime/nav-history.ts +147 -0
- package/core/client/runtime/nav-port.ts +68 -0
- package/core/client/runtime/shortcuts.ts +360 -0
- package/core/client/runtime/write-feedback.ts +71 -0
- package/core/client/runtime-entry.ts +29 -0
- package/core/client/scheduler/SomaScheduler.ts +13 -3
- package/core/client/{adaptive → scheduling}/flush-scheduler.ts +16 -12
- package/core/client/scheduling/index.ts +22 -0
- package/core/client/scheduling/observer-pool.ts +109 -0
- package/core/client/security/attribute-presence.ts +1 -0
- package/core/client/security/html-sanitizer.ts +23 -1
- package/core/client/security/url-guard.ts +0 -0
- package/core/client/styles/compiled-styles.ts +47 -0
- package/core/client/styles/index.ts +10 -0
- package/core/client/styles/pack-styles.ts +169 -0
- package/core/client/styles/sheet-mount.ts +48 -0
- package/core/client/{component → styles}/style-features.ts +3 -3
- package/core/client/time/clock.ts +36 -0
- package/core/client/time/instant.ts +2 -0
- package/core/client/url-state/index.ts +15 -0
- package/core/client/url-state/page-tabs-controller.ts +47 -0
- package/core/client/url-state/state-query-binding.ts +114 -0
- package/core/client/url-state/url-state.ts +149 -0
- package/core/client/validation/async-check-registry.ts +129 -0
- package/core/client/validation/async-rules.ts +259 -0
- package/core/client/validation/contract-validator.ts +43 -4
- package/core/client/validation/field-rules.ts +49 -0
- package/core/client/validation/index.ts +53 -0
- package/core/client/validation/object-rules.ts +72 -0
- package/core/index.ts +290 -264
- package/core/inspect/check-product.ts +542 -0
- package/core/inspect/check-runtime.ts +866 -0
- package/core/inspect/runtime.ts +98 -0
- package/core/page-target/index.ts +9 -0
- package/core/page-target/provenance.ts +119 -0
- package/core/page-target/slug.ts +7 -0
- package/core/page-target/testing/index.ts +329 -0
- package/core/page-target/types.ts +279 -0
- package/core/predicates-entry.ts +43 -0
- package/core/server/api/load-host-service.ts +3 -0
- package/core/server/compile-port.ts +18 -0
- package/core/server/diagnostic-gate-entry.ts +14 -0
- package/core/server/engines/style/candidate-guard.ts +59 -0
- package/core/server/engines/style/index.ts +57 -0
- package/core/server/engines/style/port.ts +34 -0
- package/core/server/engines/style/tailwind-adapter.ts +68 -0
- package/core/server/host/content-security-policy.ts +12 -5
- package/core/server/host/host-assembly-entry.ts +16 -0
- package/core/server/host/host-assembly.ts +249 -0
- package/core/server/host/invoke-host-request-hook.ts +5 -0
- package/core/server/host/locale-yaml.ts +51 -0
- package/core/server/host/page-markup-config.ts +13 -0
- package/core/server/host/published-page-artifact-cache.ts +355 -124
- package/core/server/host/published-page-assets.ts +90 -45
- package/core/server/host/resolve-host-request-hook.ts +8 -0
- package/core/server/host/resolve-host-tree-context.ts +15 -1
- package/core/server/host/server-page-assets.ts +178 -38
- package/core/server/host/soma-page-compile.ts +57 -16
- package/core/server/host/source-packages.cjs +185 -0
- package/core/server/host/source-packages.ts +18 -126
- package/core/server/host/virtual-pages.ts +255 -0
- package/core/server/index.ts +13 -42
- package/core/server/node.ts +53 -0
- package/core/server/page-assets.ts +91 -0
- package/core/server/page-declaration.ts +83 -7
- package/core/server/registry/api-registry-store.ts +38 -29
- package/core/server/registry/asset-store.ts +35 -19
- package/core/server/registry/batch-publish.ts +38 -0
- package/core/server/registry/batch-stage.ts +130 -0
- package/core/server/registry/component-supply.ts +31 -0
- package/core/server/registry/declaration-precompiler.ts +48 -34
- package/core/server/registry/index.ts +78 -1
- package/core/server/registry/page-registry-repository.ts +479 -60
- package/core/server/registry/page-registry-store.ts +627 -80
- package/core/server/registry/publish-asset-pin.ts +19 -16
- package/core/server/registry/registry-file-lock.ts +16 -3
- package/core/server/registry/registry-write-pipeline.ts +65 -1
- package/core/server/registry/request-body-limit.ts +3 -1
- package/core/server/registry/rollback-plan.ts +184 -0
- package/core/server/registry/services/index.ts +14 -1
- package/core/server/registry/services/pages/Get.ts +26 -4
- package/core/server/registry/services/pages/Register.ts +29 -7
- package/core/server/registry/services/pages/RegisterBatch.ts +68 -0
- package/core/server/registry/services/pages/Rollback.ts +14 -4
- package/core/server/registry/services/pages/Unregister.ts +2 -1
- package/core/server/registry/source/canonical.ts +57 -0
- package/core/server/registry/source/errors.ts +81 -0
- package/core/server/registry/source/index.ts +49 -0
- package/core/server/registry/source/ledger.ts +306 -0
- package/core/server/registry/source/snapshot.ts +29 -0
- package/core/server/registry/source/source-name.ts +48 -0
- package/core/server/registry/source/types.ts +106 -0
- package/core/server/registry/source/version-store.ts +371 -0
- package/core/server/registry/standard-product.ts +185 -0
- package/core/server/registry/validation/compile-gate.ts +39 -50
- package/core/server/registry/validation/cross-check.ts +18 -5
- package/core/server/registry/validation/declaration-safety-scan.ts +12 -10
- package/core/server/registry/validation/region-scopes.ts +50 -0
- package/core/server/runtime-space/access-gate.ts +206 -0
- package/core/server/runtime-space/advice-log.ts +67 -0
- package/core/server/runtime-space/artifact-evict.ts +15 -0
- package/core/server/runtime-space/bindings.ts +481 -0
- package/core/server/runtime-space/digest.ts +62 -0
- package/core/server/runtime-space/dynamic-pages.ts +379 -0
- package/core/server/runtime-space/errors.ts +96 -0
- package/core/server/runtime-space/gc.ts +117 -0
- package/core/server/runtime-space/index.ts +106 -0
- package/core/server/runtime-space/inject.ts +498 -0
- package/core/server/runtime-space/migrate-sources.ts +124 -0
- package/core/server/runtime-space/nav-catalog.ts +140 -0
- package/core/server/runtime-space/page-grants.ts +436 -0
- package/core/server/runtime-space/prewarm.ts +234 -0
- package/core/server/runtime-space/registry-cold-start.ts +69 -0
- package/core/server/runtime-space/resolve.ts +552 -0
- package/core/server/runtime-space/root.cjs +251 -0
- package/core/server/runtime-space/root.ts +46 -0
- package/core/server/runtime-space/static-source.ts +85 -0
- package/core/server/runtime-space/store.ts +253 -0
- package/core/server/runtime-space/submit-steps.ts +412 -0
- package/core/server/runtime-space/types.ts +325 -0
- package/core/shared/anchor-space.ts +48 -0
- package/core/shared/artifact-compatibility.ts +166 -0
- package/core/shared/behavior-machine-names.ts +8 -0
- package/core/shared/calc/coerce.ts +2 -29
- package/core/shared/calc/errors.ts +4 -7
- package/core/shared/calc/evaluator.ts +23 -11
- package/core/shared/calc/index.ts +3 -4
- package/core/shared/calc/lexer.ts +7 -12
- package/core/shared/calc/parser.ts +8 -19
- package/core/shared/calc/typer.ts +10 -23
- package/core/shared/component-tree-artifact.ts +85 -7
- package/core/shared/contract-a11y.ts +335 -0
- package/core/shared/contract-sections.ts +344 -0
- package/core/shared/core-diagnostic-codes.ts +210 -0
- package/core/shared/data-declaration-checks.ts +211 -0
- package/core/shared/date-parts.ts +2 -0
- package/core/shared/declaration-errors.ts +14 -0
- package/core/shared/declaration-keys.ts +36 -0
- package/core/shared/diagnostic-code-index-entry.ts +14 -0
- package/core/shared/diagnostic-gate.ts +139 -0
- package/core/shared/engines/engine-error.ts +33 -0
- package/core/shared/engines/style/style-engine.types.ts +28 -0
- package/core/shared/envelope-text-width.generated.d.mts +19 -0
- package/core/shared/envelope-text-width.generated.mjs +413 -0
- package/core/shared/fragments-section.ts +10 -0
- package/core/shared/generation-diagnostics.ts +58 -0
- package/core/shared/generation-error.ts +73 -0
- package/core/shared/hook-attributes.ts +159 -0
- package/core/shared/inert-data-element.ts +50 -0
- package/core/shared/nav-back.ts +120 -0
- package/core/shared/page-access-text.ts +7 -0
- package/core/shared/page-envelope-runtime.ts +88 -0
- package/core/shared/page-envelope.ts +618 -0
- package/core/shared/page-scopes.ts +83 -0
- package/core/shared/pipeline-error-codes-view.ts +31 -0
- package/core/shared/pipeline-limits-view.ts +27 -0
- package/core/shared/predicates/index.ts +85 -497
- package/core/shared/predicates/relative-window.ts +19 -0
- package/core/shared/published-page-route.ts +4 -8
- package/core/shared/region-scope-decl.ts +488 -0
- package/core/shared/registry-generated/compile-purposes.ts +53 -0
- package/core/shared/registry-generated/diagnostic-registry-index.ts +798 -0
- package/core/shared/registry-generated/diagnostic-registry.ts +5886 -0
- package/core/shared/registry-generated/error-codes.ts +137 -0
- package/core/shared/registry-generated/index.ts +13 -0
- package/core/shared/registry-generated/limits.ts +552 -0
- package/core/shared/registry-generated/platform-keys.ts +56 -0
- package/core/shared/registry-generated/region-scope.ts +823 -0
- package/core/shared/registry-generated/std-grammar-completion.ts +216 -0
- package/core/shared/registry-generated/std-grammar-views.ts +139 -0
- package/core/shared/registry-generated/std-grammar.ts +161 -0
- package/core/shared/rule-step.ts +2 -0
- package/core/shared/runtime-address.ts +244 -0
- package/core/shared/scope-decl.ts +77 -0
- package/core/shared/sha256.ts +108 -0
- package/core/shared/show-when.ts +77 -0
- package/core/shared/source-compat.ts +9 -0
- package/core/shared/std-auth-scan.ts +158 -0
- package/core/shared/types/choice-confirm.types.ts +2 -0
- package/core/shared/types/compile-diagnostic.types.ts +42 -0
- package/core/shared/types/compile-port.types.ts +41 -0
- package/core/shared/types/component-contract.types.ts +145 -156
- package/core/shared/types/component-tree-artifact.types.ts +31 -2
- package/core/shared/types/component-tree.types.ts +17 -6
- package/core/shared/types/data-config.types.ts +182 -222
- package/core/shared/types/domain.types.ts +20 -5
- package/core/shared/types/engine.types.ts +2 -0
- package/core/shared/types/event.types.ts +74 -0
- package/core/shared/types/generation-error.types.ts +83 -0
- package/core/shared/types/host-assembly.types.ts +97 -0
- package/core/shared/types/locale.types.ts +46 -0
- package/core/shared/types/manifest.types.ts +2 -7
- package/core/shared/types/nav-context.types.ts +46 -0
- package/core/shared/types/nav.types.ts +57 -0
- package/core/shared/types/notify.types.ts +45 -0
- package/core/shared/types/observation.types.ts +76 -0
- package/core/shared/types/page-envelope.types.ts +125 -0
- package/core/shared/types/page-state.types.ts +21 -42
- package/core/shared/types/region-scope.types.ts +177 -0
- package/core/shared/types/registry-batch.types.ts +45 -0
- package/core/shared/types/shortcuts.types.ts +61 -0
- package/core/shared/types/source.types.ts +10 -0
- package/core/shared/types/style-config.types.ts +61 -82
- package/core/shared/types/temporal.types.ts +3 -0
- package/core/shared/types/ui-config.types.ts +85 -152
- package/core/shared/types/write-outcome-view.types.ts +24 -0
- package/core/shared/types/write-runtime.types.ts +10 -0
- package/core/shared/types/write.types.ts +86 -0
- package/dist/browser/runtime-bundle.manifest.json +938 -0
- package/dist/browser/soma-runtime.js +120276 -0
- package/dist/cli/soma.js +131 -454
- package/dist/core/adaptive-pure.cjs +41 -0
- package/dist/core/index.cjs +116366 -17233
- package/dist/core/theme-pure.cjs +38 -0
- package/dist/diagnostics/telemetry.cjs +2 -1
- package/dist/lsp/component-tree.cjs +7079 -8738
- package/dist/types/build/compiler/flat-page.d.ts +52 -0
- package/dist/types/build/compiler/full-manifest-builder.d.ts +26 -1
- package/dist/types/build/{blocks → compiler}/html-index.d.ts +19 -8
- package/dist/types/build/compiler/page-assets.d.ts +11 -3
- package/dist/types/build/compiler/page-base-resolver.d.ts +5 -0
- package/dist/types/build/compiler/page-declaration-compiler.d.ts +97 -56
- package/dist/types/build/compiler/soma-precompile.d.ts +3 -3
- package/dist/types/build/compiler/vite-plugin-soma.d.ts +2 -2
- package/dist/types/build/component/component-graph.d.ts +1 -1
- package/dist/types/build/component-tree/artifact-codec.d.ts +5 -8
- package/dist/types/build/component-tree/registry-snapshot.d.ts +18 -0
- package/dist/types/build/component-tree/source-preflight.d.ts +4 -14
- package/dist/types/build/component-tree/structure-topology.d.ts +1 -1
- package/dist/types/build/eject/plan-eject.d.ts +0 -1
- package/dist/types/build/lsp/component-tree-service.d.ts +2 -0
- package/dist/types/client/a11y/a11y-config.d.ts +15 -0
- package/dist/types/client/a11y/announcer.d.ts +45 -0
- package/dist/types/client/a11y/dom-id.d.ts +4 -0
- package/dist/types/client/a11y/index.d.ts +5 -0
- package/dist/types/client/a11y/motion-hook.d.ts +13 -0
- package/dist/types/client/a11y/motion.d.ts +24 -0
- package/dist/types/client/base/SomaPageRootBase.d.ts +17 -2
- package/dist/types/client/base/index.d.ts +8 -8
- package/dist/types/client/behavior/adapter-collection.d.ts +39 -0
- package/dist/types/client/behavior/adapter-popper.d.ts +2 -0
- package/dist/types/client/behavior/aria-hide-outside.d.ts +13 -0
- package/dist/types/client/behavior/css-escape.d.ts +11 -0
- package/dist/types/client/behavior/focus-scope.d.ts +69 -0
- package/dist/types/client/behavior/focus-traversal.d.ts +3 -0
- package/dist/types/client/behavior/index.d.ts +17 -0
- package/dist/types/client/behavior/layer-stack.d.ts +39 -0
- package/dist/types/client/behavior/overlay-host/index.d.ts +5 -0
- package/dist/types/client/behavior/overlay-host/port.d.ts +55 -0
- package/dist/types/client/behavior/overlay-wiring.d.ts +59 -0
- package/dist/types/client/behavior/port.d.ts +79 -0
- package/dist/types/client/behavior/positioner.d.ts +2 -0
- package/dist/types/client/behavior/presence.d.ts +27 -0
- package/dist/types/client/behavior/zag/adapter-vanilla.d.ts +2 -0
- package/dist/types/client/behavior/zag/layer-bridge.d.ts +15 -0
- package/dist/types/client/behavior/zag/machine-host.d.ts +22 -0
- package/dist/types/client/behavior/zag/machines.d.ts +23 -0
- package/dist/types/client/compiler/manifest-compiler.d.ts +2 -3
- package/dist/types/client/component/adapter/adapt.d.ts +9 -0
- package/dist/types/client/component/adapter/index.d.ts +3 -0
- package/dist/types/client/component/adapter/types.d.ts +33 -0
- package/dist/types/client/component/adapter/web-component.d.ts +9 -0
- package/dist/types/client/component/component-definition.types.d.ts +23 -5
- package/dist/types/client/component/component-expander.d.ts +1 -12
- package/dist/types/client/component/component-manager.d.ts +39 -3
- package/dist/types/client/component/component-pack.d.ts +21 -54
- package/dist/types/client/component/component-registry.d.ts +5 -0
- package/dist/types/client/component/projection-admission.d.ts +5 -0
- package/dist/types/client/component/projection-registry.d.ts +6 -0
- package/dist/types/client/component/projection.types.d.ts +44 -0
- package/dist/types/client/component/region-unavailable.d.ts +10 -0
- package/dist/types/client/component/scoped-adapter.d.ts +2 -3
- package/dist/types/client/container/IContainerAdapter.d.ts +8 -3
- package/dist/types/client/container/SomaContainerAdapter.d.ts +7 -2
- package/dist/types/client/data/collection-payload.d.ts +1 -0
- package/dist/types/client/data/data-object-resolver.d.ts +231 -91
- package/dist/types/client/data/data-polling.d.ts +28 -0
- package/dist/types/client/data/data-subscriptions.d.ts +20 -0
- package/dist/types/client/data/data-write-actions.d.ts +9 -0
- package/dist/types/client/data/envelope-failure.d.ts +17 -0
- package/dist/types/client/data/format-config.d.ts +13 -0
- package/dist/types/client/data/region-scope-port.d.ts +34 -0
- package/dist/types/client/data/region-scope-views.d.ts +15 -0
- package/dist/types/client/data/role-gate.d.ts +10 -0
- package/dist/types/client/data/write-outcome-store.d.ts +23 -0
- package/dist/types/client/data/write-outcome.d.ts +48 -0
- package/dist/types/client/engine/asset-resolver.d.ts +2 -7
- package/dist/types/client/engine/dom-renderer.d.ts +3 -1
- package/dist/types/client/engine/event-engine.d.ts +49 -0
- package/dist/types/client/engine/locale-text-binder.d.ts +28 -0
- package/dist/types/client/engine/row-range.d.ts +1 -0
- package/dist/types/client/engine/runtime-builder.d.ts +7 -3
- package/dist/types/client/engine/soma-bootstrap.d.ts +315 -91
- package/dist/types/client/engine/step-runner.d.ts +20 -2
- package/dist/types/client/engine/style-binder.d.ts +2 -16
- package/dist/types/client/engines/chart/adapter-echarts.d.ts +6 -0
- package/dist/types/client/engines/chart/index.d.ts +8 -0
- package/dist/types/client/engines/chart/kind-modules.d.ts +8 -0
- package/dist/types/client/engines/chart/port.d.ts +46 -0
- package/dist/types/client/engines/diff/adapter-jsdiff.d.ts +6 -0
- package/dist/types/client/engines/diff/index.d.ts +8 -0
- package/dist/types/client/engines/diff/port.d.ts +16 -0
- package/dist/types/client/engines/dnd/adapter-pragmatic.d.ts +9 -0
- package/dist/types/client/engines/dnd/index.d.ts +6 -0
- package/dist/types/client/engines/dnd/port.d.ts +33 -0
- package/dist/types/client/engines/engine-adapters.d.ts +23 -0
- package/dist/types/client/engines/load.d.ts +11 -0
- package/dist/types/client/engines/qrcode/adapter-qrcode-generator.d.ts +6 -0
- package/dist/types/client/engines/qrcode/index.d.ts +8 -0
- package/dist/types/client/engines/qrcode/port.d.ts +16 -0
- package/dist/types/client/engines/table/adapter-tanstack.d.ts +6 -0
- package/dist/types/client/engines/table/index.d.ts +8 -0
- package/dist/types/client/engines/table/port.d.ts +51 -0
- package/dist/types/client/engines/temporal/adapter-polyfill.d.ts +6 -0
- package/dist/types/client/engines/temporal/index.d.ts +8 -0
- package/dist/types/client/engines/temporal/port.d.ts +41 -0
- package/dist/types/client/engines/virtual/adapter-tanstack.d.ts +9 -0
- package/dist/types/client/engines/virtual/index.d.ts +8 -0
- package/dist/types/client/engines/virtual/port.d.ts +33 -0
- package/dist/types/client/format/formatter.d.ts +3 -0
- package/dist/types/client/format/index.d.ts +2 -0
- package/dist/types/client/format/zoned.d.ts +1 -0
- package/dist/types/client/host-bridge/index.d.ts +3 -0
- package/dist/types/client/host-bridge/resolve-host-bootstrap.d.ts +7 -1
- package/dist/types/client/host-bridge/soma-app-host.stub.d.ts +3 -0
- package/dist/types/client/host-bridge/soma-bootstrap-from-app.d.ts +9 -0
- package/dist/types/client/infra/auth/IAuthService.d.ts +5 -0
- package/dist/types/client/infra/auth/TokenAuthService.d.ts +1 -0
- package/dist/types/client/infra/config/SomaConfig.d.ts +4 -0
- package/dist/types/client/infra/config/feature-flags.d.ts +10 -0
- package/dist/types/client/infra/http/IHttpClient.d.ts +4 -0
- package/dist/types/client/infra/i18n/II18n.d.ts +18 -1
- package/dist/types/client/infra/i18n/builtin-locale.d.ts +11 -0
- package/dist/types/client/infra/i18n/index.d.ts +1 -0
- package/dist/types/client/infra/i18n/interpolate.d.ts +12 -0
- package/dist/types/client/infra/i18n/locale-catalog.d.ts +71 -0
- package/dist/types/client/infra/i18n/pack-locales.d.ts +29 -0
- package/dist/types/client/infra/identity/identity-port.d.ts +54 -0
- package/dist/types/client/infra/notify/DefaultNotifyService.d.ts +29 -7
- package/dist/types/client/infra/notify/INotifyService.d.ts +1 -12
- package/dist/types/client/infra/notify/notify-declaration.d.ts +10 -0
- package/dist/types/client/infra/permission/SomaPermission.d.ts +7 -0
- package/dist/types/client/infra/router/IRouter.d.ts +5 -1
- package/dist/types/client/infra/router/SomaRouter.d.ts +6 -2
- package/dist/types/client/keyboard/collection.d.ts +58 -0
- package/dist/types/client/keyboard/compose-keys.d.ts +24 -0
- package/dist/types/client/keyboard/cursor.d.ts +48 -0
- package/dist/types/client/keyboard/delegate.d.ts +48 -0
- package/dist/types/client/keyboard/ime.d.ts +2 -0
- package/dist/types/client/keyboard/index.d.ts +10 -0
- package/dist/types/client/keyboard/intents.d.ts +35 -0
- package/dist/types/client/keyboard/matrix.d.ts +29 -0
- package/dist/types/client/keyboard/submit.d.ts +7 -0
- package/dist/types/client/keyboard/typeahead.d.ts +28 -0
- package/dist/types/client/keyboard/wiring.d.ts +87 -0
- package/dist/types/client/middleware/createPermissionMiddleware.d.ts +5 -0
- package/dist/types/client/mount/domain-rule.d.ts +17 -0
- package/dist/types/client/mount/index.d.ts +3 -0
- package/dist/types/client/mount/mount-page.d.ts +11 -0
- package/dist/types/client/mount/types.d.ts +100 -0
- package/dist/types/client/observability/runtime-observer.d.ts +24 -0
- package/dist/types/client/parser/confirm-spec.d.ts +37 -0
- package/dist/types/client/parser/data-config-parser.d.ts +23 -17
- package/dist/types/client/parser/duration.d.ts +1 -1
- package/dist/types/client/parser/page-state-parser.d.ts +1 -6
- package/dist/types/client/parser/pipeline-parser.d.ts +3 -0
- package/dist/types/client/parser/style-config-parser.d.ts +2 -1
- package/dist/types/client/parser/subscribe-parser.d.ts +5 -0
- package/dist/types/client/parser/ui-config-parser.d.ts +26 -25
- package/dist/types/client/pipes/pipe-registry.d.ts +30 -2
- package/dist/types/client/registry/declaration-renderer.d.ts +11 -3
- package/dist/types/client/registry/page-lifecycle.d.ts +3 -3
- package/dist/types/client/registry/remote-page.d.ts +3 -3
- package/dist/types/client/render-ports/index.d.ts +15 -0
- package/dist/types/client/render-ports/notify-renderer.d.ts +55 -0
- package/dist/types/client/render-ports/region-fallback.d.ts +10 -0
- package/dist/types/client/render-ports/scheduling/prompt-queue.d.ts +19 -0
- package/dist/types/client/render-ports/scheduling/toast-scheduler.d.ts +60 -0
- package/dist/types/client/runtime/SomaRuntimeServices.d.ts +102 -5
- package/dist/types/client/runtime/nav-history.d.ts +31 -0
- package/dist/types/client/runtime/nav-port.d.ts +12 -0
- package/dist/types/client/runtime/shortcuts.d.ts +41 -0
- package/dist/types/client/runtime/write-feedback.d.ts +22 -0
- package/dist/types/client/runtime-entry.d.ts +13 -0
- package/dist/types/client/scheduler/SomaScheduler.d.ts +5 -0
- package/dist/types/client/{adaptive → scheduling}/flush-scheduler.d.ts +2 -2
- package/dist/types/client/scheduling/index.d.ts +4 -0
- package/dist/types/client/{adaptive → scheduling}/observer-pool.d.ts +5 -5
- package/dist/types/client/security/url-guard.d.ts +18 -0
- package/dist/types/client/styles/compiled-styles.d.ts +10 -0
- package/dist/types/client/styles/index.d.ts +3 -0
- package/dist/types/client/styles/pack-styles.d.ts +51 -0
- package/dist/types/client/styles/sheet-mount.d.ts +7 -0
- package/dist/types/client/{component → styles}/style-features.d.ts +1 -1
- package/dist/types/client/time/clock.d.ts +10 -0
- package/dist/types/client/time/instant.d.ts +1 -0
- package/dist/types/client/url-state/index.d.ts +6 -0
- package/dist/types/client/url-state/page-tabs-controller.d.ts +22 -0
- package/dist/types/client/url-state/state-query-binding.d.ts +22 -0
- package/dist/types/client/url-state/url-state.d.ts +47 -0
- package/dist/types/client/validation/async-check-registry.d.ts +41 -0
- package/dist/types/client/validation/async-rules.d.ts +81 -0
- package/dist/types/client/validation/contract-validator.d.ts +10 -0
- package/dist/types/client/validation/field-rules.d.ts +6 -0
- package/dist/types/client/validation/index.d.ts +5 -0
- package/dist/types/client/validation/object-rules.d.ts +22 -0
- package/dist/types/index.d.ts +97 -61
- package/dist/types/inspect/check-product.d.ts +123 -0
- package/dist/types/inspect/check-runtime.d.ts +19 -0
- package/dist/types/inspect/runtime.d.ts +39 -0
- package/dist/types/page-target/index.d.ts +3 -0
- package/dist/types/page-target/provenance.d.ts +20 -0
- package/dist/types/page-target/slug.d.ts +7 -0
- package/dist/types/page-target/testing/index.d.ts +55 -0
- package/dist/types/page-target/types.d.ts +260 -0
- package/dist/types/predicates-entry.d.ts +3 -0
- package/dist/types/server/compile-port.d.ts +13 -0
- package/dist/types/server/diagnostic-gate-entry.d.ts +3 -0
- package/dist/types/server/engines/style/candidate-guard.d.ts +14 -0
- package/dist/types/server/engines/style/index.d.ts +10 -0
- package/dist/types/server/engines/style/port.d.ts +8 -0
- package/dist/types/server/engines/style/tailwind-adapter.d.ts +6 -0
- package/dist/types/server/host/content-security-policy.d.ts +5 -0
- package/dist/types/server/host/host-assembly-entry.d.ts +2 -0
- package/dist/types/server/host/host-assembly.d.ts +56 -0
- package/dist/types/server/host/host-config-paths.d.cts +7 -0
- package/dist/types/server/host/locale-yaml.d.ts +3 -0
- package/dist/types/server/host/page-markup-config.d.ts +6 -0
- package/dist/types/server/host/published-page-artifact-cache.d.ts +99 -22
- package/dist/types/server/host/published-page-assets.d.ts +74 -4
- package/dist/types/server/host/server-page-assets.d.ts +29 -1
- package/dist/types/server/host/soma-page-compile.d.ts +26 -4
- package/dist/types/server/host/source-packages.d.cts +23 -0
- package/dist/types/server/host/source-packages.d.ts +15 -2
- package/dist/types/server/host/virtual-pages.d.ts +43 -0
- package/dist/types/server/index.d.ts +8 -12
- package/dist/types/server/node.d.ts +16 -0
- package/dist/types/server/page-assets.d.ts +10 -0
- package/dist/types/server/page-declaration.d.ts +21 -6
- package/dist/types/server/registry/api-registry-store.d.ts +9 -7
- package/dist/types/server/registry/asset-store.d.ts +13 -7
- package/dist/types/server/registry/batch-publish.d.ts +12 -0
- package/dist/types/server/registry/batch-stage.d.ts +24 -0
- package/dist/types/server/registry/component-supply.d.ts +6 -0
- package/dist/types/server/registry/declaration-precompiler.d.ts +22 -8
- package/dist/types/server/registry/index.d.ts +12 -3
- package/dist/types/server/registry/page-registry-repository.d.ts +46 -0
- package/dist/types/server/registry/page-registry-store.d.ts +225 -23
- package/dist/types/server/registry/publish-asset-pin.d.ts +5 -4
- package/dist/types/server/registry/registry-file-lock.d.ts +5 -0
- package/dist/types/server/registry/registry-write-pipeline.d.ts +22 -0
- package/dist/types/server/registry/request-body-limit.d.ts +1 -1
- package/dist/types/server/registry/rollback-plan.d.ts +61 -0
- package/dist/types/server/registry/services/index.d.ts +5 -0
- package/dist/types/server/registry/services/pages/Register.d.ts +1 -1
- package/dist/types/server/registry/services/pages/RegisterBatch.d.ts +12 -0
- package/dist/types/server/registry/services/pages/Rollback.d.ts +4 -1
- package/dist/types/server/registry/source/canonical.d.ts +2 -0
- package/dist/types/server/registry/source/errors.d.ts +44 -0
- package/dist/types/server/registry/source/index.d.ts +7 -0
- package/dist/types/server/registry/source/ledger.d.ts +99 -0
- package/dist/types/server/registry/source/snapshot.d.ts +6 -0
- package/dist/types/server/registry/source/source-name.d.ts +20 -0
- package/dist/types/server/registry/source/types.d.ts +89 -0
- package/dist/types/server/registry/source/version-store.d.ts +66 -0
- package/dist/types/server/registry/standard-product.d.ts +78 -0
- package/dist/types/server/registry/validation/compile-gate.d.ts +12 -45
- package/dist/types/server/registry/validation/cross-check.d.ts +7 -0
- package/dist/types/server/registry/validation/declaration-safety-scan.d.ts +0 -1
- package/dist/types/server/registry/validation/region-scopes.d.ts +10 -0
- package/dist/types/server/runtime-space/access-gate.d.ts +41 -0
- package/dist/types/server/runtime-space/advice-log.d.ts +18 -0
- package/dist/types/server/runtime-space/artifact-evict.d.ts +4 -0
- package/dist/types/server/runtime-space/bindings.d.ts +115 -0
- package/dist/types/server/runtime-space/digest.d.ts +19 -0
- package/dist/types/server/runtime-space/dynamic-pages.d.ts +120 -0
- package/dist/types/server/runtime-space/errors.d.ts +37 -0
- package/dist/types/server/runtime-space/gc.d.ts +6 -0
- package/dist/types/server/runtime-space/index.d.ts +19 -0
- package/dist/types/server/runtime-space/inject.d.ts +55 -0
- package/dist/types/server/runtime-space/migrate-sources.d.ts +19 -0
- package/dist/types/server/runtime-space/nav-catalog.d.ts +33 -0
- package/dist/types/server/runtime-space/page-grants.d.ts +90 -0
- package/dist/types/server/runtime-space/prewarm.d.ts +60 -0
- package/dist/types/server/runtime-space/registry-cold-start.d.ts +4 -0
- package/dist/types/server/runtime-space/resolve.d.ts +38 -0
- package/dist/types/server/runtime-space/root.d.cts +88 -0
- package/dist/types/server/runtime-space/root.d.ts +21 -0
- package/dist/types/server/runtime-space/static-source.d.ts +8 -0
- package/dist/types/server/runtime-space/store.d.ts +63 -0
- package/dist/types/server/runtime-space/submit-steps.d.ts +116 -0
- package/dist/types/server/runtime-space/types.d.ts +264 -0
- package/dist/types/shared/anchor-space.d.ts +17 -0
- package/dist/types/shared/artifact-compatibility.d.ts +77 -0
- package/dist/types/shared/behavior-machine-names.d.ts +2 -0
- package/dist/types/shared/calc/coerce.d.ts +1 -4
- package/dist/types/shared/calc/lexer.d.ts +1 -2
- package/dist/types/shared/calc/parser.d.ts +1 -7
- package/dist/types/shared/calc/typer.d.ts +1 -6
- package/dist/types/shared/component-tree-artifact.d.ts +16 -2
- package/dist/types/shared/contract-a11y.d.ts +33 -0
- package/dist/types/shared/contract-sections.d.ts +50 -0
- package/dist/types/shared/core-diagnostic-codes.d.ts +28 -0
- package/dist/types/shared/data-declaration-checks.d.ts +71 -0
- package/dist/types/shared/date-parts.d.ts +1 -0
- package/dist/types/shared/declaration-errors.d.ts +12 -0
- package/dist/types/shared/declaration-keys.d.ts +9 -0
- package/dist/types/shared/diagnostic-code-index-entry.d.ts +5 -0
- package/dist/types/shared/diagnostic-gate.d.ts +60 -0
- package/dist/types/shared/engines/engine-error.d.ts +14 -0
- package/dist/types/shared/engines/style/style-engine.types.d.ts +22 -0
- package/dist/types/shared/fragments-section.d.ts +2 -0
- package/dist/types/shared/generation-diagnostics.d.ts +7 -0
- package/dist/types/shared/generation-error.d.ts +20 -0
- package/dist/types/shared/hook-attributes.d.ts +220 -0
- package/dist/types/shared/inert-data-element.d.ts +14 -0
- package/dist/types/shared/nav-back.d.ts +22 -0
- package/dist/types/shared/page-access-text.d.ts +4 -0
- package/dist/types/shared/page-envelope-runtime.d.ts +32 -0
- package/dist/types/shared/page-envelope.d.ts +61 -0
- package/dist/types/shared/page-scopes.d.ts +35 -0
- package/dist/types/shared/pipeline-error-codes-view.d.ts +11 -0
- package/dist/types/shared/pipeline-limits-view.d.ts +8 -0
- package/dist/types/shared/predicates/index.d.ts +24 -67
- package/dist/types/shared/predicates/relative-window.d.ts +1 -0
- package/dist/types/shared/published-page-route.d.ts +2 -2
- package/dist/types/shared/region-scope-decl.d.ts +121 -0
- package/dist/types/shared/registry-generated/compile-purposes.d.ts +37 -0
- package/dist/types/shared/registry-generated/diagnostic-registry-index.d.ts +2 -0
- package/dist/types/shared/registry-generated/diagnostic-registry.d.ts +5023 -0
- package/dist/types/shared/registry-generated/error-codes.d.ts +115 -0
- package/dist/types/shared/registry-generated/index.d.ts +10 -0
- package/dist/types/shared/registry-generated/limits.d.ts +461 -0
- package/dist/types/shared/registry-generated/platform-keys.d.ts +42 -0
- package/dist/types/shared/registry-generated/region-scope.d.ts +511 -0
- package/dist/types/shared/registry-generated/std-grammar-completion.d.ts +773 -0
- package/dist/types/shared/registry-generated/std-grammar-views.d.ts +203 -0
- package/dist/types/shared/registry-generated/std-grammar.d.ts +3515 -0
- package/dist/types/shared/rule-step.d.ts +1 -0
- package/dist/types/shared/runtime-address.d.ts +70 -0
- package/dist/types/shared/scope-decl.d.ts +15 -0
- package/dist/types/shared/sha256.d.ts +4 -0
- package/dist/types/shared/show-when.d.ts +21 -0
- package/dist/types/shared/source-compat.d.ts +2 -0
- package/dist/types/shared/std-auth-scan.d.ts +45 -0
- package/dist/types/shared/types/choice-confirm.types.d.ts +1 -0
- package/dist/types/shared/types/compile-diagnostic.types.d.ts +34 -0
- package/dist/types/shared/types/compile-port.types.d.ts +30 -0
- package/dist/types/shared/types/component-contract.types.d.ts +134 -129
- package/dist/types/shared/types/component-tree-artifact.types.d.ts +29 -2
- package/dist/types/shared/types/component-tree.types.d.ts +15 -6
- package/dist/types/shared/types/data-config.types.d.ts +175 -191
- package/dist/types/shared/types/domain.types.d.ts +20 -5
- package/dist/types/shared/types/engine.types.d.ts +2 -0
- package/dist/types/shared/types/event.types.d.ts +55 -1
- package/dist/types/shared/types/generation-error.types.d.ts +28 -0
- package/dist/types/shared/types/host-assembly.types.d.ts +95 -0
- package/dist/types/shared/types/locale.types.d.ts +17 -0
- package/dist/types/shared/types/manifest.types.d.ts +2 -7
- package/dist/types/shared/types/nav-context.types.d.ts +41 -0
- package/dist/types/shared/types/nav.types.d.ts +53 -0
- package/dist/types/shared/types/notify.types.d.ts +37 -0
- package/dist/types/shared/types/observation.types.d.ts +72 -0
- package/dist/types/shared/types/page-envelope.types.d.ts +98 -0
- package/dist/types/shared/types/page-state.types.d.ts +17 -33
- package/dist/types/shared/types/region-scope.types.d.ts +150 -0
- package/dist/types/shared/types/registry-batch.types.d.ts +48 -0
- package/dist/types/shared/types/shortcuts.types.d.ts +67 -0
- package/dist/types/shared/types/source.types.d.ts +10 -0
- package/dist/types/shared/types/style-config.types.d.ts +0 -19
- package/dist/types/shared/types/temporal.types.d.ts +1 -0
- package/dist/types/shared/types/ui-config.types.d.ts +82 -148
- package/dist/types/shared/types/write-outcome-view.types.d.ts +19 -0
- package/dist/types/shared/types/write-runtime.types.d.ts +1 -0
- package/dist/types/shared/types/write.types.d.ts +70 -0
- package/global.d.ts +2 -1
- package/package.json +215 -61
- package/tsconfig.json +2 -10
- package/app/SomaPageClient.tsx +0 -313
- package/app/[...path]/page.tsx +0 -22
- package/app/api/[...path]/route.ts +0 -86
- package/app/api/soma-registry/[...path]/route.ts +0 -67
- package/app/components/SomaHostPage.tsx +0 -128
- package/app/components/SomaHydrationShell.tsx +0 -20
- package/app/components/SomaPageClientBoundary.tsx +0 -13
- package/app/favicon.ico/route.ts +0 -13
- package/app/globals.css +0 -126
- package/app/layout.tsx +0 -27
- package/app/page.tsx +0 -9
- package/app/soma/[...path]/route.ts +0 -9
- package/app/soma/manifest/route.ts +0 -43
- package/app/soma/page/route.ts +0 -44
- package/app/soma/page-object/route.ts +0 -159
- package/app/soma/route.ts +0 -9
- package/bin/component.cjs +0 -240
- package/bin/migrate.cjs +0 -432
- package/bin/soma-db.cjs +0 -13
- package/bin/soma-mock.mjs +0 -38
- package/bin/soma-sync.cjs +0 -3
- package/core/build/blocks/block-compile.ts +0 -373
- package/core/build/blocks/block-container.ts +0 -207
- package/core/build/blocks/block-loader.ts +0 -33
- package/core/build/blocks/migrate-flat.ts +0 -463
- package/core/build/compiler/precompiled-manifest-loader.ts +0 -41
- package/core/build/component/pack-from-dir.ts +0 -58
- package/core/build/component/package-loader.ts +0 -358
- package/core/build/component-tree/binding-bridge.ts +0 -272
- package/core/build/component-tree/migration-files.ts +0 -214
- package/core/build/component-tree/migration.ts +0 -170
- package/core/build/component-tree/validator.ts +0 -318
- package/core/build/db/cli.ts +0 -10
- package/core/build/db/emit-entities.ts +0 -45
- package/core/build/db/emit-mappers.ts +0 -175
- package/core/build/db/emit-prisma-schema.ts +0 -92
- package/core/build/db/generate.ts +0 -166
- package/core/build/db/ir.ts +0 -75
- package/core/build/db/load-db-yaml.ts +0 -241
- package/core/build/eject/component-eject.ts +0 -479
- package/core/build/eject/component-upgrade.ts +0 -359
- package/core/build/layout/constraint-solver.ts +0 -350
- package/core/build/layout/css-emitter.ts +0 -135
- package/core/build/layout/page-layout.ts +0 -85
- package/core/build/ooui/artifact/artifact.types.ts +0 -275
- package/core/build/ooui/artifact/emit-artifact.ts +0 -269
- package/core/build/ooui/artifact/emit-html.ts +0 -204
- package/core/build/ooui/artifact/index.ts +0 -53
- package/core/build/ooui/artifact/spatial-tree.ts +0 -268
- package/core/build/ooui/artifact/utility-class.ts +0 -83
- package/core/build/ooui/composition/candidate.types.ts +0 -323
- package/core/build/ooui/composition/control-model.ts +0 -114
- package/core/build/ooui/composition/registry.ts +0 -520
- package/core/build/ooui/composition/select.ts +0 -232
- package/core/build/ooui/diagnostics/codes.ts +0 -230
- package/core/build/ooui/diagnostics/error.ts +0 -235
- package/core/build/ooui/diagnostics/format.ts +0 -106
- package/core/build/ooui/diagnostics/index.ts +0 -62
- package/core/build/ooui/diagnostics/issue.types.ts +0 -112
- package/core/build/ooui/engine-slot.ts +0 -184
- package/core/build/ooui/index.ts +0 -1427
- package/core/build/ooui/intent/derive-intent.ts +0 -450
- package/core/build/ooui/intent/field-rules.ts +0 -330
- package/core/build/ooui/intent/intent.types.ts +0 -476
- package/core/build/ooui/intent/verb-events.ts +0 -285
- package/core/build/ooui/page/budget.ts +0 -503
- package/core/build/ooui/page/compose-page.ts +0 -736
- package/core/build/ooui/page/index.ts +0 -66
- package/core/build/ooui/page/page.types.ts +0 -402
- package/core/build/ooui/page/region-row.ts +0 -241
- package/core/build/ooui/semantic/expand-page-surface.ts +0 -180
- package/core/build/ooui/semantic/kernel.types.ts +0 -187
- package/core/build/ooui/semantic/normalize.ts +0 -784
- package/core/build/ooui/semantic/origin.types.ts +0 -211
- package/core/build/ooui/semantic/role-alias.ts +0 -154
- package/core/build/ooui/semantic/shorthand.ts +0 -233
- package/core/build/ooui/semantic/surface.types.ts +0 -78
- package/core/build/ooui/semantic/validate-request.ts +0 -267
- package/core/build/ooui/spatial/emit-utility.ts +0 -480
- package/core/build/ooui/spatial/ir.types.ts +0 -443
- package/core/build/ooui/spatial/registry.ts +0 -565
- package/core/build/ooui/spatial/solve.ts +0 -769
- package/core/build/ooui/spatial/utility.types.ts +0 -242
- package/core/build/ooui/trace/index.ts +0 -40
- package/core/build/ooui/trace/render.ts +0 -190
- package/core/build/ooui/trace/source.types.ts +0 -69
- package/core/build/ooui/trace/trace.types.ts +0 -326
- package/core/build/pack/pack-init.ts +0 -270
- package/core/client/adaptive/hysteresis.ts +0 -56
- package/core/client/adaptive/index.ts +0 -23
- package/core/client/adaptive/observer-pool.ts +0 -90
- package/core/client/compiler/adaptive-compile.ts +0 -136
- package/core/client/component/ai-catalog.ts +0 -432
- package/core/client/component/catalog-examples.ts +0 -60
- package/core/client/component/contract-compat.ts +0 -161
- package/core/client/component/example-blocks.ts +0 -126
- package/core/client/component/keyboard-matrix.ts +0 -144
- package/core/client/component/pack-styles.ts +0 -152
- package/core/client/component/theme-component-tokens.ts +0 -80
- package/core/client/component/verify-pack.ts +0 -429
- package/core/client/container/MiniProgramContainerAdapter.ts +0 -204
- package/core/client/container/ReactNativeContainerAdapter.ts +0 -203
- package/core/client/data/reaction-engine.ts +0 -176
- package/core/client/data/window-engine.ts +0 -477
- package/core/client/infra/i18n/DefaultI18n.ts +0 -29
- package/core/client/infra/notify/DomNotifyService.ts +0 -99
- package/core/client/infra/notify/INotifyTheme.ts +0 -22
- package/core/client/parser/adaptive-parser.ts +0 -264
- package/core/client/parser/blocks/namespace.ts +0 -207
- package/core/client/parser/blocks/page-parser.ts +0 -423
- package/core/client/parser/blocks/use-parser.ts +0 -631
- package/core/client/parser/layout-parser.ts +0 -158
- package/core/client/parser/reaction-parser.ts +0 -458
- package/core/client/parser/reaction-sugar.ts +0 -47
- package/core/client/parser/window-parser.ts +0 -294
- package/core/client/quality/SomaQualityRegistry.ts +0 -71
- package/core/client/runtime/serialize-page-state.ts +0 -152
- package/core/client/theme/harmony.ts +0 -307
- package/core/client/theme/scene-tokens.ts +0 -140
- package/core/client/theme/theme-axes.ts +0 -286
- package/core/client/theme/theme-engine.ts +0 -1595
- package/core/client/theme/tone-solver.ts +0 -119
- package/core/client/typography/typography-base.ts +0 -34
- package/core/server/headless/soma-headless-page.ts +0 -103
- package/core/server/infra/db/errors.ts +0 -11
- package/core/server/infra/db/mapper/PrismaSomaMapper.ts +0 -313
- package/core/server/infra/db/mapper/SomaBaseMapper.ts +0 -23
- package/core/server/infra/db/mapper/SomaMapperHooks.ts +0 -13
- package/core/server/infra/db/query/SomaQuery.ts +0 -149
- package/core/server/infra/db/service/SomaDbService.ts +0 -64
- package/core/server/infra/db/soma-db.ts +0 -120
- package/core/server/infra/db/types.ts +0 -21
- package/core/server/mock/node/catch-all.mjs +0 -35
- package/core/server/mock/node/cli.d.mts +0 -58
- package/core/server/mock/node/cli.mjs +0 -244
- package/core/server/mock/node/context.mjs +0 -167
- package/core/server/mock/node/environment-policy.mjs +0 -52
- package/core/server/mock/node/plugin-loader.mjs +0 -212
- package/core/server/mock/node/preload.mjs +0 -91
- package/core/server/mock/node/process-lifecycle.mjs +0 -236
- package/core/server/mock/node/public.d.mts +0 -110
- package/core/server/mock/node/public.mjs +0 -4
- package/core/server/mock/node/registry.mjs +0 -336
- package/core/server/mock/node/schema-generator.mjs +0 -1309
- package/core/server/mock/testing/host-harness.d.mts +0 -66
- package/core/server/mock/testing/host-harness.mjs +0 -276
- package/core/server/mock/testing/host-runtime.mjs +0 -48
- package/core/server/ooui.ts +0 -34
- package/core/shared/block-errors.ts +0 -11
- package/core/shared/component/derive-sample.ts +0 -290
- package/core/shared/component/field-lines.ts +0 -563
- package/core/shared/container-breakpoints.ts +0 -46
- package/core/shared/object-semantics.ts +0 -240
- package/core/shared/ooui-declaration.ts +0 -235
- package/core/shared/path-algebra.ts +0 -169
- package/core/shared/types/adaptive.types.ts +0 -109
- package/core/shared/types/layout-constraint.types.ts +0 -89
- package/core/shared/types/reaction.types.ts +0 -144
- package/core/shared/types/window.types.ts +0 -177
- package/dist/types/build/blocks/block-compile.d.ts +0 -52
- package/dist/types/build/blocks/block-container.d.ts +0 -40
- package/dist/types/build/blocks/block-loader.d.ts +0 -9
- package/dist/types/build/blocks/migrate-flat.d.ts +0 -49
- package/dist/types/build/compiler/precompiled-manifest-loader.d.ts +0 -5
- package/dist/types/build/component/pack-from-dir.d.ts +0 -17
- package/dist/types/build/component/package-loader.d.ts +0 -50
- package/dist/types/build/component-tree/binding-bridge.d.ts +0 -19
- package/dist/types/build/component-tree/migration-files.d.ts +0 -35
- package/dist/types/build/component-tree/migration.d.ts +0 -28
- package/dist/types/build/component-tree/validator.d.ts +0 -9
- package/dist/types/build/db/cli.d.ts +0 -2
- package/dist/types/build/db/emit-entities.d.ts +0 -5
- package/dist/types/build/db/emit-mappers.d.ts +0 -15
- package/dist/types/build/db/emit-prisma-schema.d.ts +0 -2
- package/dist/types/build/db/generate.d.ts +0 -7
- package/dist/types/build/db/ir.d.ts +0 -58
- package/dist/types/build/db/load-db-yaml.d.ts +0 -14
- package/dist/types/build/eject/component-eject.d.ts +0 -121
- package/dist/types/build/eject/component-upgrade.d.ts +0 -43
- package/dist/types/build/layout/constraint-solver.d.ts +0 -78
- package/dist/types/build/layout/css-emitter.d.ts +0 -18
- package/dist/types/build/layout/page-layout.d.ts +0 -24
- package/dist/types/build/ooui/artifact/artifact.types.d.ts +0 -180
- package/dist/types/build/ooui/artifact/emit-artifact.d.ts +0 -58
- package/dist/types/build/ooui/artifact/emit-html.d.ts +0 -53
- package/dist/types/build/ooui/artifact/index.d.ts +0 -5
- package/dist/types/build/ooui/artifact/spatial-tree.d.ts +0 -48
- package/dist/types/build/ooui/artifact/utility-class.d.ts +0 -46
- package/dist/types/build/ooui/composition/candidate.types.d.ts +0 -206
- package/dist/types/build/ooui/composition/control-model.d.ts +0 -37
- package/dist/types/build/ooui/composition/registry.d.ts +0 -66
- package/dist/types/build/ooui/composition/select.d.ts +0 -63
- package/dist/types/build/ooui/diagnostics/codes.d.ts +0 -28
- package/dist/types/build/ooui/diagnostics/error.d.ts +0 -135
- package/dist/types/build/ooui/diagnostics/format.d.ts +0 -51
- package/dist/types/build/ooui/diagnostics/index.d.ts +0 -25
- package/dist/types/build/ooui/diagnostics/issue.types.d.ts +0 -56
- package/dist/types/build/ooui/engine-slot.d.ts +0 -41
- package/dist/types/build/ooui/index.d.ts +0 -286
- package/dist/types/build/ooui/intent/derive-intent.d.ts +0 -32
- package/dist/types/build/ooui/intent/field-rules.d.ts +0 -99
- package/dist/types/build/ooui/intent/intent.types.d.ts +0 -318
- package/dist/types/build/ooui/intent/verb-events.d.ts +0 -70
- package/dist/types/build/ooui/page/budget.d.ts +0 -28
- package/dist/types/build/ooui/page/compose-page.d.ts +0 -41
- package/dist/types/build/ooui/page/index.d.ts +0 -4
- package/dist/types/build/ooui/page/page.types.d.ts +0 -264
- package/dist/types/build/ooui/page/region-row.d.ts +0 -16
- package/dist/types/build/ooui/semantic/expand-page-surface.d.ts +0 -33
- package/dist/types/build/ooui/semantic/kernel.types.d.ts +0 -125
- package/dist/types/build/ooui/semantic/normalize.d.ts +0 -45
- package/dist/types/build/ooui/semantic/origin.types.d.ts +0 -95
- package/dist/types/build/ooui/semantic/role-alias.d.ts +0 -35
- package/dist/types/build/ooui/semantic/shorthand.d.ts +0 -60
- package/dist/types/build/ooui/semantic/surface.types.d.ts +0 -16
- package/dist/types/build/ooui/semantic/validate-request.d.ts +0 -19
- package/dist/types/build/ooui/spatial/emit-utility.d.ts +0 -43
- package/dist/types/build/ooui/spatial/ir.types.d.ts +0 -280
- package/dist/types/build/ooui/spatial/registry.d.ts +0 -110
- package/dist/types/build/ooui/spatial/solve.d.ts +0 -42
- package/dist/types/build/ooui/spatial/utility.types.d.ts +0 -191
- package/dist/types/build/ooui/trace/index.d.ts +0 -3
- package/dist/types/build/ooui/trace/render.d.ts +0 -42
- package/dist/types/build/ooui/trace/source.types.d.ts +0 -25
- package/dist/types/build/ooui/trace/trace.types.d.ts +0 -143
- package/dist/types/build/pack/pack-init.d.ts +0 -8
- package/dist/types/client/adaptive/hysteresis.d.ts +0 -16
- package/dist/types/client/adaptive/index.d.ts +0 -5
- package/dist/types/client/compiler/adaptive-compile.d.ts +0 -26
- package/dist/types/client/component/ai-catalog.d.ts +0 -122
- package/dist/types/client/component/catalog-examples.d.ts +0 -18
- package/dist/types/client/component/contract-compat.d.ts +0 -16
- package/dist/types/client/component/example-blocks.d.ts +0 -7
- package/dist/types/client/component/keyboard-matrix.d.ts +0 -24
- package/dist/types/client/component/pack-styles.d.ts +0 -43
- package/dist/types/client/component/theme-component-tokens.d.ts +0 -17
- package/dist/types/client/component/verify-pack.d.ts +0 -24
- package/dist/types/client/container/MiniProgramContainerAdapter.d.ts +0 -52
- package/dist/types/client/container/ReactNativeContainerAdapter.d.ts +0 -47
- package/dist/types/client/data/reaction-engine.d.ts +0 -21
- package/dist/types/client/data/window-engine.d.ts +0 -27
- package/dist/types/client/infra/i18n/DefaultI18n.d.ts +0 -7
- package/dist/types/client/infra/notify/DomNotifyService.d.ts +0 -17
- package/dist/types/client/infra/notify/INotifyTheme.d.ts +0 -12
- package/dist/types/client/parser/adaptive-parser.d.ts +0 -28
- package/dist/types/client/parser/blocks/namespace.d.ts +0 -72
- package/dist/types/client/parser/blocks/page-parser.d.ts +0 -30
- package/dist/types/client/parser/blocks/use-parser.d.ts +0 -106
- package/dist/types/client/parser/layout-parser.d.ts +0 -9
- package/dist/types/client/parser/reaction-parser.d.ts +0 -16
- package/dist/types/client/parser/reaction-sugar.d.ts +0 -13
- package/dist/types/client/parser/window-parser.d.ts +0 -25
- package/dist/types/client/quality/SomaQualityRegistry.d.ts +0 -31
- package/dist/types/client/runtime/serialize-page-state.d.ts +0 -10
- package/dist/types/client/theme/harmony.d.ts +0 -77
- package/dist/types/client/theme/scene-tokens.d.ts +0 -31
- package/dist/types/client/theme/theme-axes.d.ts +0 -144
- package/dist/types/client/theme/theme-engine.d.ts +0 -119
- package/dist/types/client/theme/tone-solver.d.ts +0 -51
- package/dist/types/client/typography/typography-base.d.ts +0 -15
- package/dist/types/server/headless/soma-headless-page.d.ts +0 -12
- package/dist/types/server/infra/db/errors.d.ts +0 -5
- package/dist/types/server/infra/db/mapper/PrismaSomaMapper.d.ts +0 -77
- package/dist/types/server/infra/db/mapper/SomaBaseMapper.d.ts +0 -20
- package/dist/types/server/infra/db/mapper/SomaMapperHooks.d.ts +0 -12
- package/dist/types/server/infra/db/query/SomaQuery.d.ts +0 -42
- package/dist/types/server/infra/db/service/SomaDbService.d.ts +0 -24
- package/dist/types/server/infra/db/soma-db.d.ts +0 -45
- package/dist/types/server/infra/db/types.d.ts +0 -18
- package/dist/types/server/ooui.d.ts +0 -18
- package/dist/types/shared/block-errors.d.ts +0 -5
- package/dist/types/shared/component/derive-sample.d.ts +0 -37
- package/dist/types/shared/component/field-lines.d.ts +0 -19
- package/dist/types/shared/container-breakpoints.d.ts +0 -42
- package/dist/types/shared/object-semantics.d.ts +0 -42
- package/dist/types/shared/ooui-declaration.d.ts +0 -135
- package/dist/types/shared/path-algebra.d.ts +0 -56
- package/dist/types/shared/types/adaptive.types.d.ts +0 -88
- package/dist/types/shared/types/layout-constraint.types.d.ts +0 -53
- package/dist/types/shared/types/reaction.types.d.ts +0 -115
- package/dist/types/shared/types/window.types.d.ts +0 -171
- package/next.config.js +0 -387
- package/proxy.ts +0 -62
|
@@ -1,1595 +0,0 @@
|
|
|
1
|
-
// 主题派生引擎(P2,soma-core/doc/soma 设计令牌与主题.md)。
|
|
2
|
-
//
|
|
3
|
-
// 使用面承诺:theme: { brand: "#f97316" } 一行,全组件库换装。
|
|
4
|
-
// 实现四层:OKLCH 色阶派生 → 功能语义令牌 → WCAG 对比度硬保障 → CSS 变量注入。
|
|
5
|
-
// 全部确定性纯函数:同输入必同输出(可快照测试、可构建期物化)。
|
|
6
|
-
//
|
|
7
|
-
// 引擎边界(硬):本模块是通用引擎内建能力,不是 SPI。
|
|
8
|
-
// 无 registerTheme / setThemeEngine;Host 只传 SomaThemeInput 或调 deriveTheme/applyTheme。
|
|
9
|
-
// 新增静态令牌改下方 STATIC_TOKENS;components/pipes/middleware 等可注册面禁止承接主题。
|
|
10
|
-
//
|
|
11
|
-
// **WCAG AA 承诺的确切边界**(2026-08-27 逐配对实测后写明;不要笼统说"整套达 AA"):
|
|
12
|
-
// 成立 · 实心底 `--soma-c-X` + `--soma-c-X-fg`(八语气 × 亮暗 × 任意品牌色,
|
|
13
|
-
// `enforceContrastPairs` 硬保障 ≥ 4.5),以及 `--soma-bg-page` + `--soma-text-primary`;
|
|
14
|
-
// 成立 · 淡底 `--soma-c-X-soft` + `--soma-c-X-on-soft`(对本引擎产出的五张不透明表面,
|
|
15
|
-
// 含两层同语气淡底叠加,硬保障 ≥ 4.5);
|
|
16
|
-
// 不成立 · 淡底 + `--soma-c-X`("自己的淡色垫自己",亮档实测 1.75~3.78);
|
|
17
|
-
// 不成立 · 淡底 + `--soma-c-X-fg`(`-fg` 是配实心底的黑或白,暗档实测 1.37~1.60,
|
|
18
|
-
// 亮档 neutral 1.29——文字基本消失);
|
|
19
|
-
// 不承诺 · 把 `-soft` 放到宿主自造的底上:`-soft` 半透明,屏幕上的颜色由祖先决定。
|
|
20
|
-
|
|
21
|
-
import {
|
|
22
|
-
resolveAxes,
|
|
23
|
-
type SomaContrastTargets,
|
|
24
|
-
type SomaPaletteAxes,
|
|
25
|
-
type SomaResolvedAxes,
|
|
26
|
-
type SomaSceneAxes,
|
|
27
|
-
} from './theme-axes';
|
|
28
|
-
import {
|
|
29
|
-
FUNCTIONAL_HUES,
|
|
30
|
-
applySeparationGuard,
|
|
31
|
-
resolveHueAnchors,
|
|
32
|
-
type SomaHueAnchors,
|
|
33
|
-
type SomaToneName,
|
|
34
|
-
} from './harmony';
|
|
35
|
-
import { ensureContrast, solveTone } from './tone-solver';
|
|
36
|
-
import { componentTokenVar } from '../../shared/types/component-contract.types';
|
|
37
|
-
import { glassTokens, sceneColorTokens, sceneStructureTokens } from './scene-tokens';
|
|
38
|
-
|
|
39
|
-
export type { SomaPaletteAxes, SomaSceneAxes, SomaResolvedAxes } from './theme-axes';
|
|
40
|
-
export type { SomaToneName } from './harmony';
|
|
41
|
-
|
|
42
|
-
export interface SomaThemeInput {
|
|
43
|
-
/** 品牌主色(#rgb / #rrggbb) */
|
|
44
|
-
brand: string;
|
|
45
|
-
/**
|
|
46
|
-
* 色彩轴(REQ-007):色相编排 / 语义忠实度 / 彩度 / 反差 / 显式辅色。
|
|
47
|
-
* 整组可省——省略时派生结果与 REQ-007 之前字节级一致。
|
|
48
|
-
*/
|
|
49
|
-
palette?: SomaPaletteAxes;
|
|
50
|
-
/** 场景轴(REQ-007):背景场 / 场强 / 材质缺省档。整组可省 */
|
|
51
|
-
scene?: SomaSceneAxes;
|
|
52
|
-
/** 中性灰气质:warm 暖灰 / cool 冷灰 / neutral 跟随品牌色相(默认) */
|
|
53
|
-
mode?: 'warm' | 'cool' | 'neutral';
|
|
54
|
-
/** 应用暗色令牌(applyTheme 时生效;deriveTheme 恒产出亮暗两套) */
|
|
55
|
-
dark?: boolean;
|
|
56
|
-
/** 逐令牌精调通道:最后合并进 cssVars 与 darkCssVars,优先级最高(亮暗同时生效) */
|
|
57
|
-
overrides?: Record<string, string>;
|
|
58
|
-
/**
|
|
59
|
-
* 暗色专属精调:只并进 darkCssVars,在 `overrides` **之后**合并(同键胜出)。
|
|
60
|
-
*
|
|
61
|
-
* 为什么需要它:`overrides` 一份表同时盖亮暗两套,等于「一个令牌只能有一个值」。
|
|
62
|
-
* 后果不是理论问题——`soma-ui/src/daisy-presets.ts` 里 daisyLight / daisyDark 因此
|
|
63
|
-
* 被迫拆成两套完整独立预设,而 `ThemeScope` 的 `mode: 'system'` 只认一个预设名,
|
|
64
|
-
* 于是 35 套 daisy 主题的跟随系统亮暗**全部失效**。
|
|
65
|
-
*
|
|
66
|
-
* 缺省不给 = 行为与之前字节级一致(不影响任何既有预设)。
|
|
67
|
-
*/
|
|
68
|
-
darkOverrides?: Record<string, string>;
|
|
69
|
-
/**
|
|
70
|
-
* 组件级令牌覆盖(REQ-009 M-1):组件名 → { 令牌名: 值 }。
|
|
71
|
-
*
|
|
72
|
-
* 这是三级令牌的第三级在主题输入侧的入口。它存在的理由:今天想只改 Button 的圆角,
|
|
73
|
-
* 只能改全局 `--soma-radius-control`,于是**所有 control 族**跟着变。
|
|
74
|
-
*
|
|
75
|
-
* 与 MUI 的 `theme.components.MuiX.styleOverrides.<slot>` 的关键差别:
|
|
76
|
-
* 这里能改的只有**组件自己在契约 `tokens` 段声明过的旋钮**,
|
|
77
|
-
* 而不是任意内部元素的任意 CSS 声明。组件内部结构仍然封闭
|
|
78
|
-
* (页面永不可寻址组件内部,`scopeAnchors()` 的既定边界)。
|
|
79
|
-
*
|
|
80
|
-
* 引擎不认识组件,所以这里只做展平;「组件名 / 令牌名是否存在」由装配层的
|
|
81
|
-
* `validateThemeComponentTokens` 在 bootstrap 期核对契约(对不上只告警,不阻断换装)。
|
|
82
|
-
*/
|
|
83
|
-
components?: Record<string, Record<string, string>>;
|
|
84
|
-
/** 组件令牌的暗色专属覆盖:与 `darkOverrides` 同一纪律,只并进 darkCssVars */
|
|
85
|
-
darkComponents?: Record<string, Record<string, string>>;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export interface SomaThemeMeta {
|
|
89
|
-
/** 本次派生实际生效的轴位(含缺省回落)——诊断与测试的观测面 */
|
|
90
|
-
readonly axes: SomaResolvedAxes;
|
|
91
|
-
/** 语义分离闸是否触发(品牌撞进语义色地盘时为 true) */
|
|
92
|
-
readonly separationApplied: boolean;
|
|
93
|
-
/** 被推开的语气 */
|
|
94
|
-
readonly pushed: readonly SomaToneName[];
|
|
95
|
-
/**
|
|
96
|
-
* `contrast:soft` 的粉彩明度带被 toneOnPage 目标顶穿的语气(按名排序)。
|
|
97
|
-
*
|
|
98
|
-
* 不报错只上报:带是气质偏好,目标对比度是无障碍口径,冲突时对比度赢
|
|
99
|
-
* (《soma 设计令牌与主题》§10.3 原则 4「硬保障不是输入」)。留这条旁路是为了
|
|
100
|
-
* 让"带没生效"可观测——否则调参的人只看到颜色不对、不知道是谁让的位。
|
|
101
|
-
*
|
|
102
|
-
* 当前参数下它应当恒为空:soft 的 toneOnPage 1.2 取在带上界 L=0.86 处的
|
|
103
|
-
* 最差实测值 1.271 之下,带全区间达标。它变成非空 = 有人动了带或目标而没对齐。
|
|
104
|
-
* 暗色侧不参与(带只作用于亮色,暗色求解恒传 null)。
|
|
105
|
-
*/
|
|
106
|
-
readonly bandBroken: readonly SomaToneName[];
|
|
107
|
-
/** 本次写出的组件级令牌变量名(M-1)——快照与闸门的观测面 */
|
|
108
|
-
readonly componentTokens: readonly string[];
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
export interface SomaDerivedTheme {
|
|
112
|
-
/** 品牌色阶 50~950(11 档 hex) */
|
|
113
|
-
scale: Record<string, string>;
|
|
114
|
-
/** 语义令牌 → CSS 变量表(--soma-*),soma-ui 全组件消费面(亮色) */
|
|
115
|
-
cssVars: Record<string, string>;
|
|
116
|
-
/** 暗色令牌(同名变量的暗色重映射:主色提亮、深色基底、文字反转) */
|
|
117
|
-
darkCssVars: Record<string, string>;
|
|
118
|
-
/** 对比度报告:主色上文字的 WCAG 对比度(亮/暗均保障 ≥ 4.5) */
|
|
119
|
-
contrast: { primaryFg: number; darkPrimaryFg: number };
|
|
120
|
-
/** 轴位与闸门观测面(REQ-007 新增;既有消费方零感知) */
|
|
121
|
-
meta: SomaThemeMeta;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// ─── 色彩数学:sRGB ↔ OKLCH(Björn Ottosson OKLab) ─────────
|
|
125
|
-
|
|
126
|
-
interface Oklch { l: number; c: number; h: number }
|
|
127
|
-
|
|
128
|
-
function srgbToLinear(c: number): number {
|
|
129
|
-
return c <= 0.04045 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
function linearToSrgb(c: number): number {
|
|
133
|
-
return c <= 0.0031308 ? c * 12.92 : 1.055 * Math.pow(c, 1 / 2.4) - 0.055;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
export function hexToOklch(hex: string): Oklch {
|
|
137
|
-
const parsed = parseHex(hex);
|
|
138
|
-
const [r, g, b] = parsed.map(srgbToLinear);
|
|
139
|
-
const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b);
|
|
140
|
-
const m = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b);
|
|
141
|
-
const s = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b);
|
|
142
|
-
const L = 0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s;
|
|
143
|
-
const a = 1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s;
|
|
144
|
-
const bb = 0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s;
|
|
145
|
-
const c = Math.sqrt(a * a + bb * bb);
|
|
146
|
-
let h = (Math.atan2(bb, a) * 180) / Math.PI;
|
|
147
|
-
if (h < 0) h += 360;
|
|
148
|
-
return { l: L, c, h };
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
function oklchToRgb({ l: L, c, h }: Oklch): [number, number, number] {
|
|
152
|
-
const rad = (h * Math.PI) / 180;
|
|
153
|
-
const a = c * Math.cos(rad);
|
|
154
|
-
const bb = c * Math.sin(rad);
|
|
155
|
-
const l = Math.pow(L + 0.3963377774 * a + 0.2158037573 * bb, 3);
|
|
156
|
-
const m = Math.pow(L - 0.1055613458 * a - 0.0638541728 * bb, 3);
|
|
157
|
-
const s = Math.pow(L - 0.0894841775 * a - 1.291485548 * bb, 3);
|
|
158
|
-
return [
|
|
159
|
-
linearToSrgb(4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s),
|
|
160
|
-
linearToSrgb(-1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s),
|
|
161
|
-
linearToSrgb(-0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s),
|
|
162
|
-
];
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
function inGamut(rgb: [number, number, number]): boolean {
|
|
166
|
-
return rgb.every((v) => v >= -0.0001 && v <= 1.0001);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/** OKLCH → hex;超 sRGB 色域时压缩 chroma 直到入域(保色相/亮度) */
|
|
170
|
-
export function oklchToHex(color: Oklch): string {
|
|
171
|
-
let { c } = color;
|
|
172
|
-
let rgb = oklchToRgb({ ...color, c });
|
|
173
|
-
for (let i = 0; i < 24 && !inGamut(rgb); i++) {
|
|
174
|
-
c *= 0.9;
|
|
175
|
-
rgb = oklchToRgb({ ...color, c });
|
|
176
|
-
}
|
|
177
|
-
const to255 = (v: number) => Math.max(0, Math.min(255, Math.round(v * 255)));
|
|
178
|
-
return `#${rgb.map((v) => to255(v).toString(16).padStart(2, '0')).join('')}`;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
function parseHex(hex: string): [number, number, number] {
|
|
182
|
-
const raw = hex.trim().replace(/^#/, '');
|
|
183
|
-
const full = raw.length === 3 ? raw.split('').map((ch) => ch + ch).join('') : raw;
|
|
184
|
-
if (!/^[0-9a-fA-F]{6}$/.test(full)) {
|
|
185
|
-
throw new Error(`[SomaTheme] 非法颜色值: "${hex}"(需 #rgb 或 #rrggbb)`);
|
|
186
|
-
}
|
|
187
|
-
return [0, 2, 4].map((i) => parseInt(full.slice(i, i + 2), 16) / 255) as [number, number, number];
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
// ─── WCAG 对比度 ─────────────────────────────────────────────
|
|
191
|
-
|
|
192
|
-
export function contrastRatio(hexA: string, hexB: string): number {
|
|
193
|
-
const lum = (hex: string) => {
|
|
194
|
-
const [r, g, b] = parseHex(hex).map(srgbToLinear);
|
|
195
|
-
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
|
196
|
-
};
|
|
197
|
-
const [hi, lo] = [lum(hexA), lum(hexB)].sort((a, b) => b - a);
|
|
198
|
-
return (hi + 0.05) / (lo + 0.05);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
const CONTRAST_TOKEN_PAIRS = [
|
|
202
|
-
['--soma-c-primary', '--soma-c-primary-fg'],
|
|
203
|
-
['--soma-c-secondary', '--soma-c-secondary-fg'],
|
|
204
|
-
['--soma-c-accent', '--soma-c-accent-fg'],
|
|
205
|
-
['--soma-c-neutral', '--soma-c-neutral-fg'],
|
|
206
|
-
['--soma-c-info', '--soma-c-info-fg'],
|
|
207
|
-
['--soma-c-success', '--soma-c-success-fg'],
|
|
208
|
-
['--soma-c-warning', '--soma-c-warning-fg'],
|
|
209
|
-
['--soma-c-danger', '--soma-c-danger-fg'],
|
|
210
|
-
['--soma-bg-page', '--soma-text-primary'],
|
|
211
|
-
] as const;
|
|
212
|
-
|
|
213
|
-
// ─── 半透明色的真合成(-soft 家族的对比度只能这样算) ─────────
|
|
214
|
-
|
|
215
|
-
interface Rgba { r: number; g: number; b: number; a: number }
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* 解析带透明度的 CSS 颜色。`contrastColorToHex` 刻意拒收透明色(它守的是"实心底不许被
|
|
219
|
-
* 透明值绕过 AA"),但 `-soft` 令牌**本身就是** `rgba(…, .1)`——要算它上面的文字对比度,
|
|
220
|
-
* 必须先把 alpha 解出来、再压到真实祖先底上。两个函数职责不同,不能互相顶替。
|
|
221
|
-
*/
|
|
222
|
-
function parseRgba(value: string): Rgba | null {
|
|
223
|
-
const trimmed = value.trim();
|
|
224
|
-
const rgbaMatch = /^rgba?\(\s*([\d.]+)\s*[, ]+\s*([\d.]+)\s*[, ]+\s*([\d.]+)\s*(?:[,/]\s*([\d.]+)(%)?\s*)?\)$/i.exec(trimmed);
|
|
225
|
-
if (rgbaMatch) {
|
|
226
|
-
const alpha = rgbaMatch[4] === undefined
|
|
227
|
-
? 1
|
|
228
|
-
: Number(rgbaMatch[4]) / (rgbaMatch[5] ? 100 : 1);
|
|
229
|
-
const channels = rgbaMatch.slice(1, 4).map((channel) => Math.max(0, Math.min(255, Number(channel))));
|
|
230
|
-
if (![...channels, alpha].every(Number.isFinite)) return null;
|
|
231
|
-
return { r: channels[0], g: channels[1], b: channels[2], a: Math.max(0, Math.min(1, alpha)) };
|
|
232
|
-
}
|
|
233
|
-
const hex = contrastColorToHex(trimmed);
|
|
234
|
-
if (!hex) return null;
|
|
235
|
-
const [r, g, b] = parseHex(hex).map((channel) => channel * 255);
|
|
236
|
-
return { r, g, b, a: 1 };
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
/** 源色按 alpha 压到底色上(Porter-Duff over),结果恒为不透明 */
|
|
240
|
-
function compositeOver(top: Rgba, bottom: Rgba): Rgba {
|
|
241
|
-
return {
|
|
242
|
-
r: top.r * top.a + bottom.r * (1 - top.a),
|
|
243
|
-
g: top.g * top.a + bottom.g * (1 - top.a),
|
|
244
|
-
b: top.b * top.a + bottom.b * (1 - top.a),
|
|
245
|
-
a: 1,
|
|
246
|
-
};
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
* 合成底的对比度用浮点算,不走 hex 中转。
|
|
251
|
-
* `contrastRatio` 只吃 hex,把合成结果先四舍五入到 8bit 再量,误差落在小数点后两位——
|
|
252
|
-
* 恰好够让一个按 4.5 收敛的搜索产出 4.493 这种"看着达标、量出来不达标"的边界值。
|
|
253
|
-
*/
|
|
254
|
-
function luminanceRgba({ r, g, b }: Rgba): number {
|
|
255
|
-
return 0.2126 * srgbToLinear(r / 255)
|
|
256
|
-
+ 0.7152 * srgbToLinear(g / 255)
|
|
257
|
-
+ 0.0722 * srgbToLinear(b / 255);
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
/** `#rrggbb` 直取亮度:明度搜索每一步都要算一次,不值得为它走一遍正则 + 通用解析 */
|
|
261
|
-
function luminanceHex(hex: string): number {
|
|
262
|
-
return 0.2126 * srgbToLinear(parseInt(hex.slice(1, 3), 16) / 255)
|
|
263
|
-
+ 0.7152 * srgbToLinear(parseInt(hex.slice(3, 5), 16) / 255)
|
|
264
|
-
+ 0.0722 * srgbToLinear(parseInt(hex.slice(5, 7), 16) / 255);
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
function contrastColorToHex(value: string): string | null {
|
|
268
|
-
const trimmed = value.trim();
|
|
269
|
-
if (/^#[0-9a-f]{3}(?:[0-9a-f]{3})?$/i.test(trimmed)) {
|
|
270
|
-
const rgb = parseHex(trimmed).map((channel) => Math.round(channel * 255));
|
|
271
|
-
return `#${rgb.map((channel) => channel.toString(16).padStart(2, '0')).join('')}`;
|
|
272
|
-
}
|
|
273
|
-
const rgbMatch = /^rgb\(\s*([\d.]+)\s*[, ]+\s*([\d.]+)\s*[, ]+\s*([\d.]+)\s*\)$/i.exec(trimmed);
|
|
274
|
-
if (rgbMatch) {
|
|
275
|
-
const rgb = rgbMatch.slice(1).map((channel) => Math.max(0, Math.min(255, Math.round(Number(channel)))));
|
|
276
|
-
return `#${rgb.map((channel) => channel.toString(16).padStart(2, '0')).join('')}`;
|
|
277
|
-
}
|
|
278
|
-
const oklchMatch = /^oklch\(\s*([\d.]+)(%)?\s+([\d.]+)\s+([\d.]+)(?:deg)?\s*\)$/i.exec(trimmed);
|
|
279
|
-
if (oklchMatch) {
|
|
280
|
-
const lightness = Number(oklchMatch[1]) / (oklchMatch[2] ? 100 : 1);
|
|
281
|
-
const chroma = Number(oklchMatch[3]);
|
|
282
|
-
const hue = Number(oklchMatch[4]);
|
|
283
|
-
if ([lightness, chroma, hue].every(Number.isFinite) && lightness >= 0 && lightness <= 1 && chroma >= 0) {
|
|
284
|
-
return oklchToHex({ l: lightness, c: chroma, h: hue });
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
return null;
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
/**
|
|
291
|
-
* 逐令牌 overrides 仍可精确保留背景/品牌色,但不能关闭组件文字的 WCAG AA 底线。
|
|
292
|
-
* 语义配对接受 #rgb/#rrggbb、rgb() 与无透明度 oklch();无法验证的值 fail fast,
|
|
293
|
-
* 避免 `var()` 或透明色在未知底色上制造“看似自定义、实际绕过”漏洞。
|
|
294
|
-
*/
|
|
295
|
-
function enforceContrastPairs(vars: Record<string, string>): void {
|
|
296
|
-
for (const [backgroundKey, foregroundKey] of CONTRAST_TOKEN_PAIRS) {
|
|
297
|
-
const background = vars[backgroundKey];
|
|
298
|
-
const foreground = vars[foregroundKey];
|
|
299
|
-
const backgroundHex = contrastColorToHex(background);
|
|
300
|
-
const foregroundHex = contrastColorToHex(foreground);
|
|
301
|
-
if (!backgroundHex || !foregroundHex) {
|
|
302
|
-
throw new Error(`[SomaTheme] 无法验证语义对比度: ${backgroundKey}="${background}" / ${foregroundKey}="${foreground}";请使用不含透明度的 #rgb、#rrggbb、rgb() 或 oklch()`);
|
|
303
|
-
}
|
|
304
|
-
if (contrastRatio(backgroundHex, foregroundHex) >= 4.5) continue;
|
|
305
|
-
vars[foregroundKey] = ['#000000', '#ffffff', '#111827']
|
|
306
|
-
.sort((left, right) => contrastRatio(backgroundHex, right) - contrastRatio(backgroundHex, left))[0];
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
// ─── 可读文字 × 中性表面:配色规格的令牌层保障 ─────────
|
|
311
|
-
|
|
312
|
-
/**
|
|
313
|
-
* 页面上**读得到的字**用的五枚文字令牌。弱化(muted)与次级(secondary)同样是要读的字——
|
|
314
|
-
* 卡片副标题、指标标签、定义列表 dt 全靠它们——AA 底线不因"弱化"降级。
|
|
315
|
-
* 禁用文字(text-disabled / control-fg-disabled)按 WCAG 1.4.3 豁免,不在此列。
|
|
316
|
-
*/
|
|
317
|
-
const READABLE_TEXT_KEYS = [
|
|
318
|
-
'--soma-text-strong',
|
|
319
|
-
'--soma-text-primary',
|
|
320
|
-
'--soma-text-secondary',
|
|
321
|
-
'--soma-text-muted',
|
|
322
|
-
'--soma-text-link',
|
|
323
|
-
] as const;
|
|
324
|
-
|
|
325
|
-
/** 文字令牌可能直接落上的五张中性表面;取最坏的那张求解(组件不必关心自己在哪张底上)。 */
|
|
326
|
-
const NEUTRAL_SURFACE_KEYS = [
|
|
327
|
-
'--soma-bg-page',
|
|
328
|
-
'--soma-bg-container',
|
|
329
|
-
'--soma-surface-card',
|
|
330
|
-
'--soma-bg-elevated',
|
|
331
|
-
'--soma-bg-hover',
|
|
332
|
-
] as const;
|
|
333
|
-
|
|
334
|
-
const READABLE_TEXT_TARGET = 4.52;
|
|
335
|
-
|
|
336
|
-
/**
|
|
337
|
-
* 在**最终生效**的变量表上(overrides 合并之后)逐枚校正文字令牌:
|
|
338
|
-
* 对五张中性表面取最坏对比度,不达标就沿"远离表面"的方向按 0.02 明度步进,
|
|
339
|
-
* 停在刚好可读的最浅处——层级(strong > primary > secondary > muted)因此保留。
|
|
340
|
-
* 与 enforceContrastPairs 的区别:那边是实心语气底配黑白字,二选一即可;
|
|
341
|
-
* 这里是灰阶层级,直接换成黑/白会把四档墨色压成一档。
|
|
342
|
-
*/
|
|
343
|
-
function enforceReadableText(vars: Record<string, string>): void {
|
|
344
|
-
const surfaces = NEUTRAL_SURFACE_KEYS
|
|
345
|
-
.map((key) => contrastColorToHex(vars[key] ?? ''))
|
|
346
|
-
.filter((hex): hex is string => hex !== null);
|
|
347
|
-
if (surfaces.length === 0) return;
|
|
348
|
-
const surfaceLum = Math.min(...surfaces.map((hex) => hexToOklch(hex).l));
|
|
349
|
-
for (const key of READABLE_TEXT_KEYS) {
|
|
350
|
-
let tone = contrastColorToHex(vars[key] ?? '');
|
|
351
|
-
if (!tone) continue;
|
|
352
|
-
const worst = (hex: string) => Math.min(...surfaces.map((surface) => contrastRatio(surface, hex)));
|
|
353
|
-
if (worst(tone) >= READABLE_TEXT_TARGET) continue;
|
|
354
|
-
const direction = hexToOklch(tone).l < surfaceLum ? -1 : 1;
|
|
355
|
-
for (let i = 0; i < 40 && worst(tone) < READABLE_TEXT_TARGET; i++) {
|
|
356
|
-
const cur = hexToOklch(tone);
|
|
357
|
-
const next = Math.max(0, Math.min(1, cur.l + direction * 0.02));
|
|
358
|
-
if (next === cur.l) break;
|
|
359
|
-
tone = oklchToHex({ ...cur, l: next });
|
|
360
|
-
}
|
|
361
|
-
vars[key] = tone;
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
// ─── 淡底前景(-on-soft):AA 承诺覆盖到"淡底徽标"这一类配对 ─────────
|
|
366
|
-
|
|
367
|
-
/** 有 `-soft` 淡底的八个语气;每个都配一枚 `-on-soft` 前景 */
|
|
368
|
-
const SOFT_TONES = ['primary', 'secondary', 'accent', 'neutral', 'info', 'success', 'warning', 'danger'] as const;
|
|
369
|
-
|
|
370
|
-
/**
|
|
371
|
-
* 收敛目标留 0.02 余量而不是卡在 4.5:屏幕上的合成结果最终会量化到 8bit,
|
|
372
|
-
* 卡线收敛出来的 4.500 落到真实像素上可能变成 4.49x。余量比"刚好达标"便宜得多。
|
|
373
|
-
*/
|
|
374
|
-
const SOFT_AA_TARGET = 4.52;
|
|
375
|
-
|
|
376
|
-
/**
|
|
377
|
-
* 淡底可能落在哪些不透明表面上。`-soft` 是半透明的,它**没有自己的颜色**——
|
|
378
|
-
* 屏幕上那个颜色由祖先决定。所以 AA 只能对"引擎自己产出的这几张底"承诺,
|
|
379
|
-
* 逐张算、取最坏。宿主把徽标放进自造的深色盒子里,那是宿主的合成,引擎管不到。
|
|
380
|
-
*/
|
|
381
|
-
const SOFT_SURFACE_KEYS = [
|
|
382
|
-
'--soma-bg-container',
|
|
383
|
-
'--soma-surface-card',
|
|
384
|
-
'--soma-bg-elevated',
|
|
385
|
-
'--soma-bg-page',
|
|
386
|
-
'--soma-bg-hover',
|
|
387
|
-
] as const;
|
|
388
|
-
|
|
389
|
-
/**
|
|
390
|
-
* overrides 改了 `--soma-c-X`,`-soft` 必须跟着换色相。
|
|
391
|
-
*
|
|
392
|
-
* 为什么要补这一刀:`-soft` 在派生阶段就按引擎自算的语气色烘焙好了,而 overrides 在最后合并。
|
|
393
|
-
* daisy 那 35 套预设正是只覆盖实心语气色——于是 `--soma-c-warning` 是 daisy 的柠檬黄、
|
|
394
|
-
* `--soma-c-warning-soft` 还是品牌派生出来的土褐,同一枚徽标的底和字来自两个色系。
|
|
395
|
-
* 实测 daisyAcid 亮档 warning 配对对比度 1.04:不是"低对比度",是**底和字撞成了同一个颜色**。
|
|
396
|
-
* 跟随规则:只在"实心色被覆盖、soft 没被覆盖"时重算,且沿用原 soft 的 alpha——
|
|
397
|
-
* 淡底的浓度是设计口径(亮 10% / 暗 16%),换色相不该顺带改浓度。
|
|
398
|
-
*/
|
|
399
|
-
function syncSoftWithOverrides(vars: Record<string, string>, overrides: Record<string, string> | undefined): void {
|
|
400
|
-
if (!overrides) return;
|
|
401
|
-
for (const tone of SOFT_TONES) {
|
|
402
|
-
const solidKey = `--soma-c-${tone}`;
|
|
403
|
-
const softKey = `${solidKey}-soft`;
|
|
404
|
-
if (!(solidKey in overrides) || softKey in overrides) continue;
|
|
405
|
-
const solidHex = contrastColorToHex(vars[solidKey] ?? '');
|
|
406
|
-
const currentSoft = parseRgba(vars[softKey] ?? '');
|
|
407
|
-
if (!solidHex || !currentSoft) continue;
|
|
408
|
-
vars[softKey] = hexWithAlpha(solidHex, currentSoft.a);
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
/**
|
|
413
|
-
* 派生 `--soma-c-X-on-soft`:**淡底上的**同语气前景,硬保障 AA 4.5。
|
|
414
|
-
*
|
|
415
|
-
* 为什么必须新开一枚令牌,而不是调 soft 的明度或复用既有令牌:
|
|
416
|
-
* · `-fg`(白/近黑)是配**实心底**的——把它放到淡底上,亮档是黑字压浅底(还行),
|
|
417
|
-
* 暗档就是近黑字压深底,实测 1.37~1.60,等于文字消失;
|
|
418
|
-
* · 直接用 `--soma-c-X` 当字色(全库徽标的既有写法)是"自己的淡色垫自己":
|
|
419
|
-
* warning 实心色明度 0.72,压在自己 10% 的淡底上最高只有 2.3,
|
|
420
|
-
* **无论怎么调 soft 的明度都够不到 4.5**——淡底越浅差距越小,越深就不叫淡底了。
|
|
421
|
-
* 能动的只有前景,所以答案是"给淡底单独派生一个足够深(亮档)/足够亮(暗档)的前景"。
|
|
422
|
-
*
|
|
423
|
-
* 算法:锁死语气的色相与彩度(换肤后仍是同一个语气色),只沿明度走,
|
|
424
|
-
* 直到对**所有候选淡底**都 ≥ 4.5。候选底含一层与两层 `-soft` 叠加——
|
|
425
|
-
* 库里 `.__row--trouble`(整行淡底)套 `.__status--warning`(徽标淡底)就是两层,
|
|
426
|
-
* 只按一层算会在这类嵌套上差半档。
|
|
427
|
-
*/
|
|
428
|
-
/**
|
|
429
|
-
* 淡底前景的记忆表。
|
|
430
|
-
*
|
|
431
|
-
* 为什么这里可以缓存、而本仓另外两次缓存实弹要小心:**缓存的是八个字符串,不是对象**。
|
|
432
|
-
* 命中时把同样的字面量写进一份全新的 vars,调用方拿到的仍是自己的表,
|
|
433
|
-
* 不存在"两处共享同一个可变对象"的经典事故面。派生本身是纯函数,同键必同值。
|
|
434
|
-
*
|
|
435
|
-
* 为什么值得缓存:`-on-soft` 是这套派生里唯一带搜索的一步(沿明度找首个达标点,
|
|
436
|
-
* 每步都要 oklchToHex + 一圈色域压缩)。实测它给 deriveTheme 加了约 0.7ms/次;
|
|
437
|
-
* 而真实调用形态几乎全是重复键——同一个 brand 在亮暗之间来回切、
|
|
438
|
-
* 同一套预设被反复 apply。键含全部输入(亮暗 + 八个淡底 + 八个语气色 + 五张表面),
|
|
439
|
-
* 任何一个变了就是新键,不会串味。
|
|
440
|
-
*/
|
|
441
|
-
const onSoftMemo = new Map<string, string[]>();
|
|
442
|
-
const ON_SOFT_MEMO_LIMIT = 32;
|
|
443
|
-
|
|
444
|
-
function deriveOnSoftTokens(vars: Record<string, string>, dark: boolean): void {
|
|
445
|
-
const surfaceValues = SOFT_SURFACE_KEYS.map((key) => vars[key] ?? '');
|
|
446
|
-
const memoKey = `${dark ? 'd' : 'l'}|${surfaceValues.join('|')}|`
|
|
447
|
-
+ SOFT_TONES.map((tone) => `${vars[`--soma-c-${tone}`] ?? ''}~${vars[`--soma-c-${tone}-soft`] ?? ''}`).join('|');
|
|
448
|
-
const memoized = onSoftMemo.get(memoKey);
|
|
449
|
-
if (memoized) {
|
|
450
|
-
SOFT_TONES.forEach((tone, index) => { vars[`--soma-c-${tone}-on-soft`] = memoized[index]; });
|
|
451
|
-
return;
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
const surfaces: Rgba[] = [];
|
|
455
|
-
for (const value of surfaceValues) {
|
|
456
|
-
const surface = parseRgba(value);
|
|
457
|
-
if (surface && surface.a >= 0.999) surfaces.push(surface);
|
|
458
|
-
}
|
|
459
|
-
if (surfaces.length === 0) surfaces.push(dark ? { r: 24, g: 24, b: 24, a: 1 } : { r: 255, g: 255, b: 255, a: 1 });
|
|
460
|
-
|
|
461
|
-
for (const tone of SOFT_TONES) {
|
|
462
|
-
const soft = parseRgba(vars[`--soma-c-${tone}-soft`] ?? '');
|
|
463
|
-
const solidHex = contrastColorToHex(vars[`--soma-c-${tone}`] ?? '');
|
|
464
|
-
const onSoftKey = `--soma-c-${tone}-on-soft`;
|
|
465
|
-
if (!soft || !solidHex) {
|
|
466
|
-
// 语气色被宿主覆盖成引擎无法验证的值(var()/渐变…)时不硬编一个颜色上去,
|
|
467
|
-
// 退回实心色,行为与改动前一致——不制造"看似达标"的假象。
|
|
468
|
-
vars[onSoftKey] = vars[`--soma-c-${tone}`] ?? (dark ? '#ffffff' : '#000000');
|
|
469
|
-
continue;
|
|
470
|
-
}
|
|
471
|
-
// 候选底的亮度只算一次:明度搜索每步都要跟全部候选底比一遍,
|
|
472
|
-
// 在循环里反复求同一组底的亮度会把这次派生的成本放大一个数量级
|
|
473
|
-
// (换肤路径上有一条"批写不慢于逐个 setProperty"的性能闸门在看着)。
|
|
474
|
-
const backdropLuminance: number[] = [];
|
|
475
|
-
for (const surface of surfaces) {
|
|
476
|
-
const once = compositeOver(soft, surface);
|
|
477
|
-
// 素面本身也算一张底:`-on-soft` 是全库唯一的「彩色文字」令牌(配色规格 §11.2),
|
|
478
|
-
// 状态文案、选中项文字这类不带淡底的彩色字同样用它,AA 必须对素面同时成立
|
|
479
|
-
backdropLuminance.push(luminanceRgba(surface), luminanceRgba(once), luminanceRgba(compositeOver(soft, once)));
|
|
480
|
-
}
|
|
481
|
-
const worst = (hex: string) => {
|
|
482
|
-
const fgLuminance = luminanceHex(hex);
|
|
483
|
-
let lowest = Infinity;
|
|
484
|
-
for (const backdrop of backdropLuminance) {
|
|
485
|
-
const ratio = fgLuminance >= backdrop
|
|
486
|
-
? (fgLuminance + 0.05) / (backdrop + 0.05)
|
|
487
|
-
: (backdrop + 0.05) / (fgLuminance + 0.05);
|
|
488
|
-
if (ratio < lowest) lowest = ratio;
|
|
489
|
-
}
|
|
490
|
-
return lowest;
|
|
491
|
-
};
|
|
492
|
-
// 明度搜索:先按 0.06 粗扫找到跨过阈值的那一段,再在段内按 0.02 精扫。
|
|
493
|
-
// 结果与"整段 0.02 逐格扫"一致(同一格网、同一个"首个达标点"),
|
|
494
|
-
// 但 oklchToHex 的调用次数降到约三分之一——它内部还带一圈色域压缩循环,是这里最贵的一步。
|
|
495
|
-
const step = dark ? 0.02 : -0.02;
|
|
496
|
-
const seed = hexToOklch(solidHex);
|
|
497
|
-
const at = (index: number) => oklchToHex({
|
|
498
|
-
l: Math.max(0.02, Math.min(0.99, seed.l + step * index)),
|
|
499
|
-
c: seed.c,
|
|
500
|
-
h: seed.h,
|
|
501
|
-
});
|
|
502
|
-
let picked: string | null = null;
|
|
503
|
-
let coarse = 0;
|
|
504
|
-
for (; coarse <= 48; coarse += 3) {
|
|
505
|
-
if (worst(at(coarse)) >= SOFT_AA_TARGET) break;
|
|
506
|
-
}
|
|
507
|
-
if (coarse <= 48) {
|
|
508
|
-
for (let fine = Math.max(0, coarse - 2); fine <= coarse; fine += 1) {
|
|
509
|
-
const candidate = at(fine);
|
|
510
|
-
if (worst(candidate) >= SOFT_AA_TARGET) { picked = candidate; break; }
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
|
-
// 明度走到头仍不达标(极端窄色域)时退到黑/白——保 AA 优先于保色相
|
|
514
|
-
vars[onSoftKey] = picked ?? (worst('#ffffff') >= worst('#000000') ? '#ffffff' : '#000000');
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
// 键无上限地长(宿主可以逐令牌 override 出无穷多套),所以给记忆表封顶。
|
|
518
|
-
// 满了直接清空而不是做 LRU:这张表的价值全在"同一套主题被反复派生",
|
|
519
|
-
// 一次清空最多让下一次重算一遍,不值得为它维护一套淘汰簿记。
|
|
520
|
-
if (onSoftMemo.size >= ON_SOFT_MEMO_LIMIT) onSoftMemo.clear();
|
|
521
|
-
onSoftMemo.set(memoKey, SOFT_TONES.map((tone) => vars[`--soma-c-${tone}-on-soft`]));
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
// ─── 派生 ───────────────────────────────────────────────────
|
|
525
|
-
|
|
526
|
-
// 静态令牌(不随品牌色/亮暗变化;刻度对标 AntD Design Token 与 Material 3)
|
|
527
|
-
/**
|
|
528
|
-
* 图表序列色板(8 色)。
|
|
529
|
-
*
|
|
530
|
-
* 为什么由主题引擎产出而不是让组件库自己定:颜色是 soma-core 的独占职责
|
|
531
|
-
* (《组件体系》B6「主题责任边界」)。图表如果各自硬编码一套配色,
|
|
532
|
-
* 「改一行 brand 换整站皮」的承诺就在数据看板上当场破功——而看板恰恰是最显眼的地方。
|
|
533
|
-
*
|
|
534
|
-
* 取色办法:以品牌色的色相为起点,在 OKLCH 上按固定步长转色相、锁定明度与彩度。
|
|
535
|
-
* 锁 L/C 的意义是**让每条序列的视觉分量相等**——同一张图里如果一条比一条浅,
|
|
536
|
-
* 读者会误以为浅的那条"次要"。步长不取等分(360/8=45)而是打散排列,
|
|
537
|
-
* 让相邻序列的色相差尽量大:折线图上相邻的两条线最容易被看混。
|
|
538
|
-
*/
|
|
539
|
-
function chartSeries(
|
|
540
|
-
hue: number,
|
|
541
|
-
chroma: number,
|
|
542
|
-
lightness: number,
|
|
543
|
-
/** harmony 压缩后的色相锚;不传则走既有的全轮打散(functional 缺省档) */
|
|
544
|
-
anchors?: SomaHueAnchors,
|
|
545
|
-
): Record<string, string> {
|
|
546
|
-
const vars: Record<string, string> = {};
|
|
547
|
-
|
|
548
|
-
// 窄带编排(analogous / monochrome)下色相已经没有区分力——
|
|
549
|
-
// 8 条曲线挤在 80° 里靠色相根本分不开,这是感知事实不是风格选择。
|
|
550
|
-
// 此时改用**明度阶梯**做主区分,色相退为次级。
|
|
551
|
-
// 不这么做的话,单色系页面上的图表会是一张外来物:要么整张糊成一片,
|
|
552
|
-
// 要么为了分开而把色相摊回全轮,与页面其余部分割裂。
|
|
553
|
-
if (anchors?.chartLightnessLadder) {
|
|
554
|
-
const span = 0.34; // 阶梯总跨度:够分辨又不至于让末档发灰
|
|
555
|
-
const start = lightness - span / 2;
|
|
556
|
-
anchors.chart.forEach((h, index) => {
|
|
557
|
-
vars[`--soma-chart-${index + 1}`] = oklchToHex({
|
|
558
|
-
l: Math.max(0.28, Math.min(0.88, start + (span * index) / 7)),
|
|
559
|
-
c: chroma,
|
|
560
|
-
h,
|
|
561
|
-
});
|
|
562
|
-
});
|
|
563
|
-
return vars;
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
// 宽带(含 functional 缺省档):锁 L/C,靠色相分。
|
|
567
|
-
// 步长不取等分(360/8=45)而是打散排列,让相邻序列的色相差尽量大:
|
|
568
|
-
// 折线图上相邻的两条线最容易被看混。
|
|
569
|
-
const offsets = [0, 200, 130, 45, 275, 95, 320, 165];
|
|
570
|
-
const hues = anchors && anchors.chart.length === 8
|
|
571
|
-
? anchors.chart
|
|
572
|
-
: offsets.map((offset) => (hue + offset) % 360);
|
|
573
|
-
hues.forEach((h, index) => {
|
|
574
|
-
vars[`--soma-chart-${index + 1}`] = oklchToHex({ l: lightness, c: chroma, h });
|
|
575
|
-
});
|
|
576
|
-
return vars;
|
|
577
|
-
}
|
|
578
|
-
|
|
579
|
-
// 空间量(间距 / 字号)以 rem 落盘,描边级光学量(圆角 / 阴影 / 描边)保持 px。
|
|
580
|
-
//
|
|
581
|
-
// 为什么分两类而不是"全部改 rem":rem 化的目的是**保形缩放**——用户把浏览器字号
|
|
582
|
-
// 调大时整套版式等比放大,WCAG 1.4.4 才从"能不能读"变成恒等式。而圆角、阴影偏移、
|
|
583
|
-
// 1px 描边是光学属性,跟着字号放大只会失真;`9999px` 胶囊这类语义值更不宜缩放。
|
|
584
|
-
//
|
|
585
|
-
// 换算规则:`rem = px / 16`,精度 1/16(0.0625rem)。现有刻度(4px 基准的间距、
|
|
586
|
-
// 12~24px 的字阶)全部是 16 的整数分之一倍,换算**无一需要取整**,
|
|
587
|
-
// 因此 16px 根字号下输出值与迁移前逐令牌恒等,视觉基线零 diff。
|
|
588
|
-
const STATIC_TOKENS: Record<string, string> = {
|
|
589
|
-
// 字体排印:系统栈 + 八档字号 + AntD 标准行高 + 四档字重
|
|
590
|
-
'--soma-font-family':
|
|
591
|
-
"-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif",
|
|
592
|
-
'--soma-font-size-xs': '0.75rem', // 12px
|
|
593
|
-
'--soma-font-size-sm': '0.875rem', // 14px
|
|
594
|
-
'--soma-font-size-md': '1rem', // 16px
|
|
595
|
-
'--soma-font-size-lg': '1.125rem', // 18px
|
|
596
|
-
'--soma-font-size-xl': '1.25rem', // 20px
|
|
597
|
-
'--soma-font-size-xxl': '1.5rem', // 24px
|
|
598
|
-
// 页头/落地页标题用的两级。加在这里而不是让组件写死回退值:
|
|
599
|
-
// 写死的话换肤对标题字号无效,而"无效"看不出来——回退值本身就是个合理的数。
|
|
600
|
-
'--soma-font-size-3xl': '1.875rem', // 30px
|
|
601
|
-
'--soma-font-size-4xl': '2.25rem', // 36px
|
|
602
|
-
// 行高三档齐(tight 给标题 / KPI 大数字 / 控件单行文本,base 给正文与一切默认,
|
|
603
|
-
// loose 给成段长文阅读区)。行高由本层**独占**:soma-ui 不得再置
|
|
604
|
-
// `--soma-ui-line-height-*` 同义副本——排版阶梯换一套组件库也不该丢,
|
|
605
|
-
// 两处并存即 G6 分叉。出现第四个行高值就是违规。
|
|
606
|
-
'--soma-line-height-tight': '1.25',
|
|
607
|
-
'--soma-line-height': '1.5715',
|
|
608
|
-
'--soma-line-height-loose': '1.75',
|
|
609
|
-
// 等宽栈:代码块、日志、单号与需要对齐的数字(2026-08-17 soma-ui B13 补:
|
|
610
|
-
// 此前 RichTextEditor 引用了这个名字,但引擎从不产出它——换肤对代码块永远没作用)
|
|
611
|
-
'--soma-font-mono':
|
|
612
|
-
"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, 'Liberation Mono', 'Courier New', monospace",
|
|
613
|
-
'--soma-font-weight-normal': '400',
|
|
614
|
-
'--soma-font-weight-medium': '500',
|
|
615
|
-
'--soma-font-weight-bold': '600',
|
|
616
|
-
// 展示档(2026-09-12 补):把字形当**图形**用的位置——头像/角标的首字母牌、
|
|
617
|
-
// 序号与勾选标记、KPI 大数字、倒计时格、hero 标题、金额主数字。
|
|
618
|
-
// 它不是文本层次的第四级(层次到 bold 就封顶,见排版册"层次三维"),
|
|
619
|
-
// 所以不参与"页题→脚注"六级;单列一档是因为这些位置此前各写各的裸值
|
|
620
|
-
// (650/700/750/800 混用,同一个 `__eyebrow` 在三个卡片工厂里是三个数),
|
|
621
|
-
// 没有令牌可引就只能硬编码,换肤对它们永远无效。
|
|
622
|
-
'--soma-font-weight-heavy': '800',
|
|
623
|
-
// 间距:4px 基准;0 贴合,9=48px,10=56px(文档 space.0~16,未一次铺满)
|
|
624
|
-
'--soma-space-0': '0rem',
|
|
625
|
-
'--soma-space-1': '0.25rem', // 4px
|
|
626
|
-
'--soma-space-2': '0.5rem', // 8px
|
|
627
|
-
'--soma-space-3': '0.75rem', // 12px
|
|
628
|
-
'--soma-space-4': '1rem', // 16px
|
|
629
|
-
'--soma-space-5': '1.25rem', // 20px
|
|
630
|
-
'--soma-space-6': '1.5rem', // 24px
|
|
631
|
-
'--soma-space-7': '2rem', // 32px
|
|
632
|
-
'--soma-space-8': '2.5rem', // 40px
|
|
633
|
-
'--soma-space-9': '3rem', // 48px
|
|
634
|
-
'--soma-space-10': '3.5rem', // 56px
|
|
635
|
-
// 圆角:记名**不 rem 化**。圆角是描边级光学属性,跟着字号缩放会失真;
|
|
636
|
-
// `9999px` 是"胶囊"的语义值,缩放它没有意义。阴影偏移与 1px 描边同理。
|
|
637
|
-
// (radius-control/overlay 仍单列在语义组)
|
|
638
|
-
// 材质档(REQ-006 G1):玻璃拟态需要的几何与模糊量。
|
|
639
|
-
// 与既有 radius 同理不 rem 化——它们是描边级光学属性。
|
|
640
|
-
'--soma-radius-plush': '22px', // 玻璃面的"厚实"圆角(参照实测 22~26px)
|
|
641
|
-
'--soma-surface-blur': '18px', // backdrop-filter 模糊半径
|
|
642
|
-
'--soma-surface-saturate': '140%', // 模糊同时提饱和,避免背景透上来发灰
|
|
643
|
-
'--soma-lift-hover': 'translateY(-2px)', // 悬停位移量(reduced-motion 下由组件退化)
|
|
644
|
-
'--soma-radius-none': '0px',
|
|
645
|
-
'--soma-radius-sm': '4px',
|
|
646
|
-
'--soma-radius-md': '8px',
|
|
647
|
-
'--soma-radius-lg': '12px',
|
|
648
|
-
'--soma-radius-xl': '16px',
|
|
649
|
-
'--soma-radius-full': '9999px',
|
|
650
|
-
// 阴影三档(参考 AntD boxShadow 三级层次;shadow-overlay 仍单列)
|
|
651
|
-
'--soma-shadow-sm': '0 1px 2px rgba(0, 0, 0, 0.06), 0 1px 3px rgba(0, 0, 0, 0.1)',
|
|
652
|
-
'--soma-shadow-md': '0 4px 12px rgba(0, 0, 0, 0.12)',
|
|
653
|
-
'--soma-shadow-lg': '0 12px 32px rgba(0, 0, 0, 0.16)',
|
|
654
|
-
// 动效:三档时长 + 入场/离场/悬停时长(motion.enter/exit/hover)+ 标准缓动 + 入场 ease-out / 离场 ease-in
|
|
655
|
-
'--soma-duration-fast': '0.1s',
|
|
656
|
-
'--soma-duration-base': '0.2s',
|
|
657
|
-
'--soma-duration-slow': '0.3s',
|
|
658
|
-
'--soma-duration-enter': '0.2s',
|
|
659
|
-
'--soma-duration-exit': '0.3s',
|
|
660
|
-
'--soma-duration-hover': '0.1s',
|
|
661
|
-
'--soma-ease': 'cubic-bezier(0.645, 0.045, 0.355, 1)',
|
|
662
|
-
'--soma-ease-enter': 'cubic-bezier(0.215, 0.61, 0.355, 1)',
|
|
663
|
-
'--soma-ease-exit': 'cubic-bezier(0.55, 0.055, 0.675, 0.19)',
|
|
664
|
-
// 控件高度步进:daisy --size-field / --size-selector(几何原语,非颜色)
|
|
665
|
-
'--soma-size-field': '0.25rem',
|
|
666
|
-
'--soma-size-selector': '0.25rem',
|
|
667
|
-
// 层级:下拉 < 吸顶 < 遮罩 < 轻提示
|
|
668
|
-
// 禁用态统一不透明度:各组件此前各写各的(0.5/0.55/0.6),换肤与密度配方都管不到
|
|
669
|
-
'--soma-opacity-disabled': '0.55',
|
|
670
|
-
'--soma-z-dropdown': '50',
|
|
671
|
-
'--soma-z-sticky': '80',
|
|
672
|
-
'--soma-z-overlay': '100',
|
|
673
|
-
'--soma-z-toast': '200',
|
|
674
|
-
};
|
|
675
|
-
|
|
676
|
-
const STEPS = ['50', '100', '200', '300', '400', '500', '600', '700', '800', '900', '950'];
|
|
677
|
-
const LIGHTNESS = [0.985, 0.955, 0.91, 0.85, 0.78, 0.70, 0.62, 0.54, 0.46, 0.38, 0.30];
|
|
678
|
-
const CHROMA_CURVE = [0.14, 0.28, 0.48, 0.68, 0.85, 1.0, 1.0, 0.92, 0.8, 0.66, 0.52];
|
|
679
|
-
|
|
680
|
-
/**
|
|
681
|
-
* 求解器的色彩原语注入点。
|
|
682
|
-
*
|
|
683
|
-
* tone-solver 不 import 本文件——否则两个模块互相引用,
|
|
684
|
-
* 预编译与 tree-shaking 都会变得难以推理。原语由这里传进去。
|
|
685
|
-
*/
|
|
686
|
-
const SOLVER_DEPS = { oklchToHex, hexToOklch, contrastRatio, bestFg };
|
|
687
|
-
|
|
688
|
-
/**
|
|
689
|
-
* 求解方向:「远离页面底」。亮色恒 darken、暗色恒 lighten。
|
|
690
|
-
*
|
|
691
|
-
* 这不是启发,是把 toneOnPage 与 fgOnTone 从互相打架变成同向的那一步:
|
|
692
|
-
* 语气底对页面底的对比度在亮色下随明度**单调递减**、暗色下**单调递增**,
|
|
693
|
-
* 所以"远离页面底"这个方向上 toneOnPage 只会变好——`ensureContrast` 为了
|
|
694
|
-
* fgOnTone 多推的那几步顺带把 toneOnPage 推得更宽裕,而不是推回去。
|
|
695
|
-
*
|
|
696
|
-
* 反例正是 tone-solver 的 forceDirection 参数存在的理由(那里的注释讲的是
|
|
697
|
-
* 分离闸版本的同一类事故):缺省启发「l > 0.55 就提亮」会把一个刚解到
|
|
698
|
-
* l=0.56 的语气朝页面底推回去,toneOnPage 当场掉档。
|
|
699
|
-
*
|
|
700
|
-
* 取值与 solveTone 内部的方向判据同源(种子明度与页面明度谁大谁小):
|
|
701
|
-
* 全部语气种子的明度都落在 (darkBgPage.l, bgPage.l) 之间,方向因此与语气无关。
|
|
702
|
-
*
|
|
703
|
-
* **只在 toneOnPage 真的推动过该语气时才启用**(见 dirAfter):没推过就没有
|
|
704
|
-
* 要保护的约束,方向留给既有启发——缺省档因此与接线前逐字节一致。
|
|
705
|
-
*
|
|
706
|
-
* 只给亮色一个常量:暗色侧的三处 AA 循环用的启发是「l > 0.55 就提亮」,
|
|
707
|
-
* 而暗色语气的明度全部 > 0.55,它本来就等于"远离暗色页面底",两者不冲突,
|
|
708
|
-
* 不需要覆盖(⑤/⑤.1 那几段因此一行不动)。
|
|
709
|
-
*/
|
|
710
|
-
const AWAY_FROM_LIGHT_PAGE = 'darken' as const;
|
|
711
|
-
|
|
712
|
-
export function deriveTheme(input: SomaThemeInput): SomaDerivedTheme {
|
|
713
|
-
const brand = hexToOklch(input.brand);
|
|
714
|
-
// S0 轴解析:词元 → 数值参数。全部轴省略时 params 即现状行为
|
|
715
|
-
const { axes, params } = resolveAxes(input);
|
|
716
|
-
const accentHues = axes.palette.accents.map((hex) => hexToOklch(hex).h);
|
|
717
|
-
|
|
718
|
-
// ① 品牌色阶:锁色相,chroma 曲线随亮度变化;品牌原值落位最近档
|
|
719
|
-
const brandSlot = nearestIndex(LIGHTNESS, brand.l);
|
|
720
|
-
const scale: Record<string, string> = {};
|
|
721
|
-
STEPS.forEach((step, i) => {
|
|
722
|
-
scale[step] = i === brandSlot
|
|
723
|
-
? oklchToHex(brand)
|
|
724
|
-
: oklchToHex({ l: LIGHTNESS[i], c: Math.max(brand.c, 0.02) * CHROMA_CURVE[i], h: brand.h });
|
|
725
|
-
});
|
|
726
|
-
|
|
727
|
-
// ② 中性灰:低彩度,气质由 mode 决定色温
|
|
728
|
-
const grayHue = input.mode === 'warm' ? 60 : input.mode === 'cool' ? 250 : brand.h;
|
|
729
|
-
const grayChroma = input.mode === 'neutral' || !input.mode ? 0.008 : 0.014;
|
|
730
|
-
const gray = (l: number) => oklchToHex({ l, c: grayChroma, h: grayHue });
|
|
731
|
-
|
|
732
|
-
// ②.1 页面底先于语气求解算出来:S2 的 toneOnPage 解的是「语气实心底 vs 页面底」,
|
|
733
|
-
// 没有页面底就无从解起(REQ-007 架构设计 L1.5 手术表:S1/S2 插在 ② 之后)。
|
|
734
|
-
// 0.98 与纯白卡片的亮度差只有 2%,卡片浮不起来(2026-08-17 截图实测);
|
|
735
|
-
// 0.965 仍是"几乎白"的观感,但卡片边界一眼可辨。
|
|
736
|
-
const bgPage = gray(0.965);
|
|
737
|
-
const darkBgPage = gray(0.18);
|
|
738
|
-
|
|
739
|
-
// ③ 交互态:hover/active 依次压暗一档半亮度
|
|
740
|
-
const primaryIdx = Math.max(4, Math.min(7, brandSlot));
|
|
741
|
-
const primary = scale[STEPS[primaryIdx]];
|
|
742
|
-
const hover = oklchToHex({ ...hexToOklch(primary), l: hexToOklch(primary).l - 0.06 });
|
|
743
|
-
const active = oklchToHex({ ...hexToOklch(primary), l: hexToOklch(primary).l - 0.11 });
|
|
744
|
-
|
|
745
|
-
// ④ 对比度硬保障:主色上文字取黑/白较优者;不达 AA 则压暗主色直到达标
|
|
746
|
-
const primarySolved = ensureContrast(primary, SOLVER_DEPS, params.targets.fgOnTone);
|
|
747
|
-
const ensuredPrimary = primarySolved.bg;
|
|
748
|
-
const fg = primarySolved.fg;
|
|
749
|
-
|
|
750
|
-
// ④.1 语义功能色:色相由 S1/S3 决定(REQ-007),明度彩度沿用既有校准值。
|
|
751
|
-
// functional 档(缺省)下 anchors 即 FUNCTIONAL_HUES 原值,产出与重构前一致。
|
|
752
|
-
//
|
|
753
|
-
// S1 色相编排 —— 八语气的色相锚集中一处决定,不再散在字面常量里
|
|
754
|
-
const anchors0 = resolveHueAnchors(brand.h, axes, params, accentHues);
|
|
755
|
-
|
|
756
|
-
const toneChroma = (mul: number): number => Math.max(brand.c, 0.12) * mul * params.chromaMul;
|
|
757
|
-
/**
|
|
758
|
-
* contrast 轴的明度带:把语气种子夹进粉彩带(soft 档,亮色侧)。
|
|
759
|
-
*
|
|
760
|
-
* 缺省档 band 为 null,种子原值穿过——缺省产出因此逐字节不变。
|
|
761
|
-
* 带只夹**种子**,后续 AA 保障仍可把它推出带外(对比度赢,
|
|
762
|
-
* 是《soma 设计令牌与主题》§10.3 原则 4 的承诺:AA 底线不随 contrast 档移动)。
|
|
763
|
-
*
|
|
764
|
-
* 带与同一档的 toneOnPage 目标是**同一条轴的两条腿**,取值必须相容:
|
|
765
|
-
* soft 的目标 1.2 取在带上界 L=0.86 处的最差实测值 1.271 之下,
|
|
766
|
-
* 所以带全区间达标、不会被目标顶穿(meta.bandBroken 因此应恒为空)。
|
|
767
|
-
*/
|
|
768
|
-
const banded = (l: number): number => {
|
|
769
|
-
const band = params.softLightnessBand;
|
|
770
|
-
return band ? Math.min(band[1], Math.max(band[0], l)) : l;
|
|
771
|
-
};
|
|
772
|
-
|
|
773
|
-
/** 带被 toneOnPage 目标顶穿的语气——收进 meta 供观测,不报错 */
|
|
774
|
-
const bandBroken = new Set<SomaToneName>();
|
|
775
|
-
interface SolvedSeed {
|
|
776
|
-
readonly tone: Oklch;
|
|
777
|
-
readonly hex: string;
|
|
778
|
-
/** toneOnPage 目标是否真的推动了这个种子 */
|
|
779
|
-
readonly pushed: boolean;
|
|
780
|
-
}
|
|
781
|
-
/**
|
|
782
|
-
* S2 toneOnPage 求解:把语气实心底推离页面底,直到命中档位目标。
|
|
783
|
-
*
|
|
784
|
-
* **位置即优先级**——排在 banded/separatedL 之后、④ 系 AA 求解之前。
|
|
785
|
-
* AA 底线(fgOnTone / textOnPage)与语义可分离是引擎的两条硬保障
|
|
786
|
-
* (《soma 设计令牌与主题》§10.3 原则 4「硬保障不是输入」),它们的三个夹子
|
|
787
|
-
* `ensureContrast` / `clampSeparated*` / `enforceContrastPairs` 全排在本步之后,
|
|
788
|
-
* 因此永远说了算;toneOnPage 是 contrast 档的气质目标,尽力而为、够不到不报错。
|
|
789
|
-
* 粉彩带最先让位:被顶穿时记进 meta.bandBroken,不抛错。
|
|
790
|
-
*
|
|
791
|
-
* **作用面 = banded() 的作用面**(secondary / accent / info / success / warning /
|
|
792
|
-
* danger,亮暗各一次共 12 处)。带与目标是同一个轴的两条腿,作用面必须一致。
|
|
793
|
-
* primary 不在其内——它恒随品牌(REQ-007 架构设计 §3 作用域表「primary | brand
|
|
794
|
-
* (永远)」),解它等于改宿主给的身份色;neutral 也不在——它的明度归 mode 管
|
|
795
|
-
* (近黑芯片 l=0.18 / 暗档 0.42),既不吃粉彩带也不吃语气彩度曲线。
|
|
796
|
-
*
|
|
797
|
-
* `record` 传 null = 不记 bandBroken:判撞用的首遍求解是一次性草稿,
|
|
798
|
-
* 它的带突破不该出现在观测面上(产出以第二遍为准)。
|
|
799
|
-
*/
|
|
800
|
-
const solveOnPage = (
|
|
801
|
-
record: SomaToneName | null,
|
|
802
|
-
seed: Oklch,
|
|
803
|
-
pageHex: string,
|
|
804
|
-
target: SomaContrastTargets,
|
|
805
|
-
band: readonly [number, number] | null,
|
|
806
|
-
): SolvedSeed => {
|
|
807
|
-
const solved = solveTone(seed, pageHex, target, band, SOLVER_DEPS);
|
|
808
|
-
if (record && solved.bandBroken) bandBroken.add(record);
|
|
809
|
-
return {
|
|
810
|
-
tone: solved.tone,
|
|
811
|
-
hex: oklchToHex(solved.tone),
|
|
812
|
-
pushed: Math.abs(solved.tone.l - seed.l) > 1e-9,
|
|
813
|
-
};
|
|
814
|
-
};
|
|
815
|
-
/**
|
|
816
|
-
* 方向权的闸:只有目标真的绑定过这个语气,下游 AA 求解的方向才交给
|
|
817
|
-
* 「远离页面底」那一侧——接管方向的理由是保护刚建立的约束不被缺省启发推翻,
|
|
818
|
-
* 没推过就没有要保护的东西。
|
|
819
|
-
*
|
|
820
|
-
* `banded()` 已在上游夹过带、分离在场时又不传带(见 bandFor),所以
|
|
821
|
-
* solveTone 内部的带夹恒是空操作,`pushed` 恰好等价于"目标绑定了",无假阳性。
|
|
822
|
-
*/
|
|
823
|
-
const dirAfter = (
|
|
824
|
-
solved: SolvedSeed, away: 'lighten' | 'darken',
|
|
825
|
-
): 'lighten' | 'darken' | undefined => (solved.pushed ? away : undefined);
|
|
826
|
-
|
|
827
|
-
/**
|
|
828
|
-
* S2 色调求解:由色相锚解出三个语义色的最终值。
|
|
829
|
-
*
|
|
830
|
-
* 提成函数是因为 **S3 之后要回跑一次**:分离闸移动色相,而
|
|
831
|
-
* `ensureContrast` 会把明度推到达标位——色相变了,明度落点也会变。
|
|
832
|
-
* 拿求解前的明度估值去判撞,就会漏掉那些"seed 看着够远、解完贴到一起"的病例
|
|
833
|
-
* (terminalHacker 的绿品牌撞 success 实测就差在这 0.01)。求解器是幂等的,
|
|
834
|
-
* 回跑对未推动的语气零影响。
|
|
835
|
-
*/
|
|
836
|
-
const solveSemantics = (hues: { success: number; warning: number; danger: number }) => {
|
|
837
|
-
// 首遍必须与第二遍**同款流水线**(S2 求解 → AA),否则判撞拿到的又是
|
|
838
|
-
// "不是最终值"的明度——与下面 S3 那段讲的是同一条纪律的另一半
|
|
839
|
-
const band = params.softLightnessBand;
|
|
840
|
-
const seed = (l: number, mul: number, h: number): SolvedSeed => solveOnPage(
|
|
841
|
-
null, { l: banded(l), c: toneChroma(mul), h }, bgPage, params.targets, band,
|
|
842
|
-
);
|
|
843
|
-
const danger = seed(0.60, 0.95, hues.danger);
|
|
844
|
-
const success = seed(0.58, 0.85, hues.success);
|
|
845
|
-
const warning = seed(0.72, 0.9, hues.warning);
|
|
846
|
-
return {
|
|
847
|
-
danger: { bg: danger.hex, fg: '#ffffff', l: danger.tone.l },
|
|
848
|
-
success: ensureContrast(
|
|
849
|
-
success.hex, SOLVER_DEPS, params.targets.fgOnTone, undefined,
|
|
850
|
-
dirAfter(success, AWAY_FROM_LIGHT_PAGE),
|
|
851
|
-
),
|
|
852
|
-
warning: ensureContrast(
|
|
853
|
-
warning.hex, SOLVER_DEPS, params.targets.fgOnTone, undefined,
|
|
854
|
-
dirAfter(warning, AWAY_FROM_LIGHT_PAGE),
|
|
855
|
-
),
|
|
856
|
-
};
|
|
857
|
-
};
|
|
858
|
-
|
|
859
|
-
const firstPass = solveSemantics(anchors0.tones);
|
|
860
|
-
|
|
861
|
-
// S3 语义分离闸 —— 品牌撞进语义色地盘时推开语义色(immersive 档退场)。
|
|
862
|
-
// 明度用**求解后的实际值**,不是 seed
|
|
863
|
-
// 判定必须对着**最终生效**的主色,不是品牌种子色。
|
|
864
|
-
//
|
|
865
|
-
// 全色轮扫描(648 个配对)实测:用 brand.l 判定时 36 个配对漏判——
|
|
866
|
-
// 深红品牌(如 #951d52,种子 l≈0.42)经 ④ 的 AA 循环推到 l≈0.54 之后,
|
|
867
|
-
// 才真正贴上 danger 的明度,而闸在推之前就已经放行了。
|
|
868
|
-
// 这与"判撞要用求解后的语义色明度"是同一条纪律的另一半:
|
|
869
|
-
// **两边都得是最终值**,只对一边求解等于没求解。
|
|
870
|
-
const primaryFinal = hexToOklch(ensuredPrimary);
|
|
871
|
-
const guard = applySeparationGuard(
|
|
872
|
-
anchors0,
|
|
873
|
-
primaryFinal.h,
|
|
874
|
-
primaryFinal.l,
|
|
875
|
-
{
|
|
876
|
-
primary: primaryFinal.l, secondary: primaryFinal.l, accent: primaryFinal.l, info: 0.60,
|
|
877
|
-
success: hexToOklch(firstPass.success.bg).l,
|
|
878
|
-
warning: hexToOklch(firstPass.warning.bg).l,
|
|
879
|
-
danger: firstPass.danger.l,
|
|
880
|
-
},
|
|
881
|
-
axes.palette.semantics,
|
|
882
|
-
);
|
|
883
|
-
const anchors = guard.anchors;
|
|
884
|
-
/**
|
|
885
|
-
* 图表锚只在**压缩档**下传给序列色生成器。
|
|
886
|
-
*
|
|
887
|
-
* functional(缺省)下 anchors.chart 是"带内均布",与既有的 offsets 打散
|
|
888
|
-
* 不是同一组数——传进去会改变 46 套预设的图表色。缺省档必须走原路。
|
|
889
|
-
*/
|
|
890
|
-
const chartAnchorsOrNull = axes.palette.harmony === 'functional' ? undefined : anchors;
|
|
891
|
-
/**
|
|
892
|
-
* 明度分离:色相区内推不出安全距离时(红色品牌 × danger 是典型),
|
|
893
|
-
* 闸把分离责任交给明度——把该语气推离品牌明度至少一个判撞阈值。
|
|
894
|
-
* 危险色因此仍然是红的("危险必须看起来危险"),靠深浅与主色拉开。
|
|
895
|
-
*/
|
|
896
|
-
const separatedL = (tone: 'success' | 'warning' | 'danger', base: number): number => {
|
|
897
|
-
const need = guard.lightnessSeparation[tone];
|
|
898
|
-
if (!need) return base;
|
|
899
|
-
// 推到**阈值 + 余量**,不是刚好等于阈值。
|
|
900
|
-
//
|
|
901
|
-
// 全色轮扫描(216 个品牌)实测:推到刚好等于时,橙色品牌 #e29f2e 的
|
|
902
|
-
// warning 最终差 0.001 达不到——明度推完还要过一轮 AA 求解与 hex 量化,
|
|
903
|
-
// 两处各吃掉一点,卡在边界上就会掉回来。余量取阈值的 15%:
|
|
904
|
-
// 足够吸收量化误差,又不会把语气推到离它自己的语义太远。
|
|
905
|
-
const target = brand.l + need.direction * need.minGap * 1.15;
|
|
906
|
-
return need.direction > 0 ? Math.max(base, target) : Math.min(base, target);
|
|
907
|
-
};
|
|
908
|
-
/** danger 的前景恒为白、不过 AA 循环,所以单独夹一次分离下界 */
|
|
909
|
-
const clampSeparatedHex = (tone: 'success' | 'warning' | 'danger', hex: string): string => {
|
|
910
|
-
const need = guard.lightnessSeparation[tone];
|
|
911
|
-
if (!need) return hex;
|
|
912
|
-
const current = hexToOklch(hex);
|
|
913
|
-
const floor = primaryFinal.l + need.direction * need.minGap * 1.15;
|
|
914
|
-
const clamped = need.direction > 0 ? Math.max(current.l, floor) : Math.min(current.l, floor);
|
|
915
|
-
return Math.abs(clamped - current.l) < 1e-6 ? hex : oklchToHex({ ...current, l: clamped });
|
|
916
|
-
};
|
|
917
|
-
|
|
918
|
-
/**
|
|
919
|
-
* 分离方向 → 求解方向:有分离意图时,求解器不许把它拉回品牌明度;
|
|
920
|
-
* 没有分离意图时,只有 toneOnPage 真推动过才钉"远离页面底"(见 dirAfter)。
|
|
921
|
-
*/
|
|
922
|
-
const solveDir = (
|
|
923
|
-
tone: 'success' | 'warning' | 'danger', solved: SolvedSeed,
|
|
924
|
-
): 'lighten' | 'darken' | undefined => {
|
|
925
|
-
const need = guard.lightnessSeparation[tone];
|
|
926
|
-
if (need) return need.direction > 0 ? 'lighten' : 'darken';
|
|
927
|
-
return dirAfter(solved, AWAY_FROM_LIGHT_PAGE);
|
|
928
|
-
};
|
|
929
|
-
/**
|
|
930
|
-
* 分离意图在场时粉彩带退场:带会把已经推离品牌明度的种子夹回来,
|
|
931
|
-
* 下游 clampSeparated 再把它推出去——一次无谓往返,还会在 meta 上留下
|
|
932
|
-
* 一条不是"目标对比度顶穿"的假 bandBroken。硬保障在场,气质让位。
|
|
933
|
-
*/
|
|
934
|
-
const bandFor = (
|
|
935
|
-
tone: 'success' | 'warning' | 'danger',
|
|
936
|
-
): readonly [number, number] | null => (
|
|
937
|
-
guard.lightnessSeparation[tone] ? null : params.softLightnessBand
|
|
938
|
-
);
|
|
939
|
-
|
|
940
|
-
const dangerSolved = solveOnPage(
|
|
941
|
-
'danger',
|
|
942
|
-
{ l: separatedL('danger', banded(0.60)), c: toneChroma(0.95), h: anchors.tones.danger },
|
|
943
|
-
bgPage, params.targets, bandFor('danger'),
|
|
944
|
-
);
|
|
945
|
-
const danger = clampSeparatedHex('danger', dangerSolved.hex);
|
|
946
|
-
const successSolved = solveOnPage(
|
|
947
|
-
'success',
|
|
948
|
-
{ l: separatedL('success', banded(0.58)), c: toneChroma(0.85), h: anchors.tones.success },
|
|
949
|
-
bgPage, params.targets, bandFor('success'),
|
|
950
|
-
);
|
|
951
|
-
const success = successSolved.hex;
|
|
952
|
-
const warningSolved = solveOnPage(
|
|
953
|
-
'warning',
|
|
954
|
-
{ l: separatedL('warning', banded(0.72)), c: toneChroma(0.9), h: anchors.tones.warning },
|
|
955
|
-
bgPage, params.targets, bandFor('warning'),
|
|
956
|
-
);
|
|
957
|
-
const warning = warningSolved.hex;
|
|
958
|
-
void firstPass; // 首遍求解只为判撞供明度,产出以第二遍为准
|
|
959
|
-
const infoOnPage = solveOnPage(
|
|
960
|
-
'info', { l: banded(0.60), c: toneChroma(0.9), h: anchors.tones.info },
|
|
961
|
-
bgPage, params.targets, params.softLightnessBand,
|
|
962
|
-
);
|
|
963
|
-
// minRatio 必须读 params.targets.fgOnTone:此前这里吃 ensureContrast 的缺省 4.5,
|
|
964
|
-
// 于是 contrast:'strong' 声明的 7.0 对 info 根本没生效(同一条轴"只生效一半"的第二处)
|
|
965
|
-
const infoSolved = ensureContrast(
|
|
966
|
-
infoOnPage.hex, SOLVER_DEPS, params.targets.fgOnTone, undefined,
|
|
967
|
-
dirAfter(infoOnPage, AWAY_FROM_LIGHT_PAGE),
|
|
968
|
-
);
|
|
969
|
-
const info = infoSolved.bg;
|
|
970
|
-
const infoFg = infoSolved.fg;
|
|
971
|
-
|
|
972
|
-
// ④.1b 第二/第三品牌色(对标 daisy secondary/accent):色相偏移 + 同主色 WCAG 循环。
|
|
973
|
-
// 组件可消费;daisy 预设可用 overrides 精调到源色板。
|
|
974
|
-
// minRatio 同样必须读 params.targets.fgOnTone:此前吃缺省 4.5,
|
|
975
|
-
// contrast:'strong' 的 7.0 对 secondary/accent/neutral 同样没生效
|
|
976
|
-
const ensureBrandTone = (
|
|
977
|
-
seedHex: string, forceDirection?: 'lighten' | 'darken',
|
|
978
|
-
): { bg: string; fg: string; soft: string } => {
|
|
979
|
-
const solved = ensureContrast(
|
|
980
|
-
seedHex, SOLVER_DEPS, params.targets.fgOnTone, undefined, forceDirection,
|
|
981
|
-
);
|
|
982
|
-
return { bg: solved.bg, fg: solved.fg, soft: hexWithAlpha(solved.bg, 0.12) };
|
|
983
|
-
};
|
|
984
|
-
/**
|
|
985
|
-
* 种子先提出来,因为它要被用**两次**:一次走亮色链路(粉彩带 → toneOnPage → AA),
|
|
986
|
-
* 一次作为暗色派生的基准(只走 AA)。
|
|
987
|
-
*
|
|
988
|
-
* 为什么暗色不能吃亮色那一份——contrast 轴的亮色侧加工(粉彩带把语气**抬亮**、
|
|
989
|
-
* toneOnPage 把语气**压暗**)在暗色底上作用方向全部反过来:`darkSecondary` 是
|
|
990
|
-
* "亮色成品 + 0.08",于是 strong 把亮色压暗 → 暗色种子跟着暗 → 在深底上反差
|
|
991
|
-
* **更低**(实测 #4f8cff:standard 8.76 → strong 5.56,档位越强反而越弱);
|
|
992
|
-
* soft 把亮色抬亮则反过来让暗色更强。两头都是把亮色的档位语义倒着装进暗色。
|
|
993
|
-
*
|
|
994
|
-
* 所以暗色从**未经 contrast 轴亮色侧加工的种子**重新出发,再按暗色目标独立求解
|
|
995
|
-
* (见 ⑤.1b)。缺省档下带为 null、toneOnPage 也不推动任何语气,两条路是同一次
|
|
996
|
-
* 求解的同一个结果——`darkSecondary/darkAccent` 因此逐字节不变。
|
|
997
|
-
*/
|
|
998
|
-
const secondarySeed: Oklch = {
|
|
999
|
-
l: Math.min(0.72, Math.max(0.45, brand.l + 0.04)),
|
|
1000
|
-
c: Math.max(brand.c, 0.1) * 0.9 * params.chromaMul,
|
|
1001
|
-
h: anchors.tones.secondary,
|
|
1002
|
-
};
|
|
1003
|
-
const accentSeed: Oklch = {
|
|
1004
|
-
l: Math.min(0.78, Math.max(0.48, brand.l + 0.08)),
|
|
1005
|
-
c: Math.max(brand.c, 0.1) * 0.85 * params.chromaMul,
|
|
1006
|
-
h: anchors.tones.accent,
|
|
1007
|
-
};
|
|
1008
|
-
const secondaryOnPage = solveOnPage(
|
|
1009
|
-
'secondary', { ...secondarySeed, l: banded(secondarySeed.l) },
|
|
1010
|
-
bgPage, params.targets, params.softLightnessBand,
|
|
1011
|
-
);
|
|
1012
|
-
const secondaryTone = ensureBrandTone(
|
|
1013
|
-
secondaryOnPage.hex, dirAfter(secondaryOnPage, AWAY_FROM_LIGHT_PAGE),
|
|
1014
|
-
);
|
|
1015
|
-
const accentOnPage = solveOnPage(
|
|
1016
|
-
'accent', { ...accentSeed, l: banded(accentSeed.l) },
|
|
1017
|
-
bgPage, params.targets, params.softLightnessBand,
|
|
1018
|
-
);
|
|
1019
|
-
const accentTone = ensureBrandTone(
|
|
1020
|
-
accentOnPage.hex, dirAfter(accentOnPage, AWAY_FROM_LIGHT_PAGE),
|
|
1021
|
-
);
|
|
1022
|
-
/** 暗色派生的基准:同一颗种子、同一套亮色 AA,但不吃粉彩带、也不吃 toneOnPage 的推动 */
|
|
1023
|
-
const secondaryDarkBase = ensureContrast(
|
|
1024
|
-
oklchToHex(secondarySeed), SOLVER_DEPS, params.targets.fgOnTone,
|
|
1025
|
-
).bg;
|
|
1026
|
-
const accentDarkBase = ensureContrast(
|
|
1027
|
-
oklchToHex(accentSeed), SOLVER_DEPS, params.targets.fgOnTone,
|
|
1028
|
-
).bg;
|
|
1029
|
-
// 中性色(对标 daisy color-neutral):近黑按钮/标签底,色温跟随 grayHue。
|
|
1030
|
-
// 不过 toneOnPage 求解:它的明度归 mode 管,不在 contrast 轴的作用面内
|
|
1031
|
-
const neutralTone = ensureBrandTone(oklchToHex({
|
|
1032
|
-
l: 0.18,
|
|
1033
|
-
c: grayChroma * 1.4,
|
|
1034
|
-
h: grayHue,
|
|
1035
|
-
}));
|
|
1036
|
-
/**
|
|
1037
|
-
* 分离后的语气:AA 求解完还要**把明度夹回分离侧**。
|
|
1038
|
-
*
|
|
1039
|
-
* 全色轮扫描实测:只把分离目标当种子是不够的——`ensureContrast` 为了达 AA
|
|
1040
|
-
* 会把明度往回推,16 个配对因此"推了但没推够"(深红品牌的 danger 卡在
|
|
1041
|
-
* ΔL≈0.06,阈值 0.12)。分离是**硬保障**,它必须是求解的下界而不是起点:
|
|
1042
|
-
* 求解完再夹一次,谁也拉不回来。
|
|
1043
|
-
*
|
|
1044
|
-
* 夹之后 AA 会不会掉?不会——夹的方向恒是"远离主色明度",
|
|
1045
|
-
* 而主色与页面底的对比本就达标,往远处走只会让语气底与文字的对比更宽裕。
|
|
1046
|
-
*/
|
|
1047
|
-
const clampSeparated = (
|
|
1048
|
-
tone: 'success' | 'warning' | 'danger', solved: { bg: string; fg: string },
|
|
1049
|
-
): { bg: string; fg: string } => {
|
|
1050
|
-
const need = guard.lightnessSeparation[tone];
|
|
1051
|
-
if (!need) return solved;
|
|
1052
|
-
const current = hexToOklch(solved.bg);
|
|
1053
|
-
const floor = primaryFinal.l + need.direction * need.minGap * 1.15;
|
|
1054
|
-
const clamped = need.direction > 0
|
|
1055
|
-
? Math.max(current.l, floor)
|
|
1056
|
-
: Math.min(current.l, floor);
|
|
1057
|
-
if (Math.abs(clamped - current.l) < 1e-6) return solved;
|
|
1058
|
-
const bg = oklchToHex({ ...current, l: clamped });
|
|
1059
|
-
return { bg, fg: bestFg(bg) };
|
|
1060
|
-
};
|
|
1061
|
-
|
|
1062
|
-
const successFg = clampSeparated(
|
|
1063
|
-
'success',
|
|
1064
|
-
ensureContrast(success, SOLVER_DEPS, params.targets.fgOnTone, undefined, solveDir('success', successSolved)),
|
|
1065
|
-
);
|
|
1066
|
-
const warningFg = clampSeparated(
|
|
1067
|
-
'warning',
|
|
1068
|
-
ensureContrast(warning, SOLVER_DEPS, params.targets.fgOnTone, undefined, solveDir('warning', warningSolved)),
|
|
1069
|
-
);
|
|
1070
|
-
|
|
1071
|
-
// ④.2 文字/背景层级(亮色):正文对页面底对比度硬保障 ≥ 4.5(不达标持续加深)
|
|
1072
|
-
// bgPage 在 ②.1 就已算出(S2 求解要用),这里只接着解正文色
|
|
1073
|
-
let textPrimary = gray(0.25);
|
|
1074
|
-
for (let i = 0; i < 16 && contrastRatio(bgPage, textPrimary) < params.targets.textOnPage; i++) {
|
|
1075
|
-
const cur = hexToOklch(textPrimary);
|
|
1076
|
-
textPrimary = oklchToHex({ ...cur, l: cur.l - 0.04 });
|
|
1077
|
-
}
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
// ── 材质令牌(REQ-006 G1)──────────────────────────────────────────────
|
|
1081
|
-
// 玻璃面是**半透明白 + 背后模糊**;高光边是它立体感的来源(少了边就成了糊面)。
|
|
1082
|
-
// 彩色投影取品牌色相:参照实现里投影是 rgba(37,99,235,.14) 而不是灰——
|
|
1083
|
-
// 这一条是"高级感"里最容易被忽略、却最起作用的一笔。
|
|
1084
|
-
const glassShadow = hexWithAlpha(scale['500'], 0.14);
|
|
1085
|
-
const glassShadowSoft = hexWithAlpha(scale['500'], 0.09);
|
|
1086
|
-
|
|
1087
|
-
const cssVars: Record<string, string> = {
|
|
1088
|
-
// 玻璃材质:面/强面/高光边/彩色投影。玻璃三档的值只住在 scene-tokens 的 glassTokens 一处
|
|
1089
|
-
...glassTokens(false),
|
|
1090
|
-
'--soma-edge-highlight': 'rgba(255, 255, 255, 0.72)',
|
|
1091
|
-
'--soma-shadow-tinted': `0 24px 70px ${glassShadow}`,
|
|
1092
|
-
'--soma-shadow-tinted-soft': `0 16px 36px ${glassShadowSoft}`,
|
|
1093
|
-
// 环境光(--soma-ambient-1/2/3)不在这里产:它取自**最终生效**的色板,
|
|
1094
|
-
// 必须排在 ⑥ 的 overrides 之后(S7′),否则 daisy × aurora 会出现
|
|
1095
|
-
// "表面一个色系、光球另一个色系"——与 ⑥.1 修过的是同一类病
|
|
1096
|
-
...sceneStructureTokens(axes),
|
|
1097
|
-
'--soma-c-primary': ensuredPrimary,
|
|
1098
|
-
'--soma-c-primary-hover': hover,
|
|
1099
|
-
'--soma-c-primary-active': active,
|
|
1100
|
-
'--soma-c-primary-fg': fg,
|
|
1101
|
-
'--soma-c-primary-soft': hexWithAlpha(scale['500'], 0.08),
|
|
1102
|
-
'--soma-c-secondary': secondaryTone.bg,
|
|
1103
|
-
'--soma-c-secondary-fg': secondaryTone.fg,
|
|
1104
|
-
'--soma-c-secondary-soft': secondaryTone.soft,
|
|
1105
|
-
'--soma-c-accent': accentTone.bg,
|
|
1106
|
-
'--soma-c-accent-fg': accentTone.fg,
|
|
1107
|
-
'--soma-c-accent-soft': accentTone.soft,
|
|
1108
|
-
'--soma-c-danger': danger,
|
|
1109
|
-
'--soma-c-danger-fg': '#ffffff',
|
|
1110
|
-
'--soma-c-success': successFg.bg,
|
|
1111
|
-
'--soma-c-success-fg': successFg.fg,
|
|
1112
|
-
'--soma-c-warning': warningFg.bg,
|
|
1113
|
-
'--soma-c-warning-fg': warningFg.fg,
|
|
1114
|
-
'--soma-c-neutral': neutralTone.bg,
|
|
1115
|
-
'--soma-c-neutral-fg': neutralTone.fg,
|
|
1116
|
-
'--soma-c-neutral-soft': neutralTone.soft,
|
|
1117
|
-
// ── 语义色补全:info + 四语义色 soft 底(对标 AntD colorInfo / colorErrorBg 族)──
|
|
1118
|
-
'--soma-c-info': info,
|
|
1119
|
-
'--soma-c-info-fg': infoFg,
|
|
1120
|
-
'--soma-c-danger-soft': hexWithAlpha(danger, 0.1),
|
|
1121
|
-
'--soma-c-success-soft': hexWithAlpha(successFg.bg, 0.1),
|
|
1122
|
-
'--soma-c-warning-soft': hexWithAlpha(warningFg.bg, 0.1),
|
|
1123
|
-
'--soma-c-info-soft': hexWithAlpha(info, 0.1),
|
|
1124
|
-
// ── 文字层级:正文/次级/禁用/反色/链接 ──
|
|
1125
|
-
'--soma-text-primary': textPrimary,
|
|
1126
|
-
// 标题/强调文字:比正文再深一档(对标 AntD colorTextHeading)。
|
|
1127
|
-
// 没有这一档时,标题只能靠字重与正文拉开差距,信息层级在暗色下尤其糊
|
|
1128
|
-
'--soma-text-strong': gray(0.14),
|
|
1129
|
-
'--soma-text-secondary': gray(0.45),
|
|
1130
|
-
'--soma-text-disabled': gray(0.72),
|
|
1131
|
-
'--soma-text-inverse': '#ffffff',
|
|
1132
|
-
'--soma-text-link': ensuredPrimary,
|
|
1133
|
-
'--soma-text-link-hover': hover,
|
|
1134
|
-
// ── 背景层级:页面底 < 容器 < 浮层;行悬停单列 ──
|
|
1135
|
-
'--soma-bg-page': bgPage,
|
|
1136
|
-
'--soma-bg-container': '#ffffff',
|
|
1137
|
-
'--soma-bg-elevated': '#ffffff',
|
|
1138
|
-
'--soma-bg-hover': gray(0.96),
|
|
1139
|
-
// ── 边框与分割:常规 < 强调;分割线最浅 ──
|
|
1140
|
-
'--soma-border': gray(0.9),
|
|
1141
|
-
'--soma-border-strong': gray(0.82),
|
|
1142
|
-
'--soma-divider': gray(0.93),
|
|
1143
|
-
// ── 焦点环:主色低透明外扩 3px ──
|
|
1144
|
-
'--soma-focus-ring': `0 0 0 3px ${hexWithAlpha(ensuredPrimary, 0.2)}`,
|
|
1145
|
-
...STATIC_TOKENS,
|
|
1146
|
-
'--soma-control-border': gray(0.87),
|
|
1147
|
-
'--soma-control-bg': 'transparent',
|
|
1148
|
-
'--soma-control-bg-hover': gray(0.955),
|
|
1149
|
-
'--soma-control-bg-disabled': gray(0.96),
|
|
1150
|
-
'--soma-control-fg': gray(0.46),
|
|
1151
|
-
'--soma-control-fg-disabled': gray(0.85),
|
|
1152
|
-
'--soma-text-muted': gray(0.62),
|
|
1153
|
-
'--soma-surface-card': '#ffffff',
|
|
1154
|
-
'--soma-overlay-bg': hexWithAlpha(gray(0.2), 0.5),
|
|
1155
|
-
'--soma-radius-control': '8px',
|
|
1156
|
-
'--soma-radius-overlay': '12px',
|
|
1157
|
-
'--soma-shadow-overlay': '0 20px 40px rgba(0, 0, 0, 0.2)',
|
|
1158
|
-
'--soma-marquee-duration': '18s',
|
|
1159
|
-
// 图表序列色板:亮色下压暗一档,保证在白底上足够沉稳
|
|
1160
|
-
...chartSeries(brand.h, Math.max(brand.c, 0.12), 0.62, chartAnchorsOrNull),
|
|
1161
|
-
};
|
|
1162
|
-
STEPS.forEach((step) => {
|
|
1163
|
-
cssVars[`--soma-brand-${step}`] = scale[step];
|
|
1164
|
-
});
|
|
1165
|
-
|
|
1166
|
-
// ⑤ 暗色重映射:主色提亮一档(深底上降刺眼度)、深色基底、文字反转,同样硬保障对比度
|
|
1167
|
-
const darkPrimaryIdx = Math.max(3, primaryIdx - 1);
|
|
1168
|
-
let darkPrimary = scale[STEPS[darkPrimaryIdx]];
|
|
1169
|
-
let darkFg = bestFg(darkPrimary);
|
|
1170
|
-
for (let i = 0; i < 16 && contrastRatio(darkPrimary, darkFg) < params.darkTargets.fgOnTone; i++) {
|
|
1171
|
-
const cur = hexToOklch(darkPrimary);
|
|
1172
|
-
darkPrimary = oklchToHex({ ...cur, l: cur.l > 0.55 ? cur.l + 0.04 : cur.l - 0.04 });
|
|
1173
|
-
darkFg = bestFg(darkPrimary);
|
|
1174
|
-
}
|
|
1175
|
-
// ⑤.1 暗色语义功能色具名化:缺省轴保持既有固定色相;显式换轴后继承轴锚。
|
|
1176
|
-
const darkHover = oklchToHex({ ...hexToOklch(darkPrimary), l: hexToOklch(darkPrimary).l + 0.05 });
|
|
1177
|
-
const darkToneHues = axes.palette.harmony === 'functional'
|
|
1178
|
-
&& axes.palette.semantics === 'faithful'
|
|
1179
|
-
&& axes.palette.chroma === 'balanced'
|
|
1180
|
-
&& axes.palette.accents.length === 0
|
|
1181
|
-
? FUNCTIONAL_HUES
|
|
1182
|
-
: anchors.tones;
|
|
1183
|
-
// 暗色侧的 S2:页面底换成 darkBgPage(0.18),目标换成 params.darkTargets,
|
|
1184
|
-
// 带恒传 null——粉彩带 [0.70, 0.86] 是按亮底校准的,落到暗色语气上会把它们
|
|
1185
|
-
// 推亮、反差反而更大,与 soft 这一档的语义相反(见 theme-axes 的带说明)
|
|
1186
|
-
const darkDanger = solveOnPage('danger', {
|
|
1187
|
-
l: 0.68, c: Math.max(brand.c, 0.12) * 0.9 * params.chromaMul, h: darkToneHues.danger,
|
|
1188
|
-
}, darkBgPage, params.darkTargets, null).hex;
|
|
1189
|
-
const darkSuccess = solveOnPage('success', {
|
|
1190
|
-
l: 0.66, c: Math.max(brand.c, 0.12) * 0.8 * params.chromaMul, h: darkToneHues.success,
|
|
1191
|
-
}, darkBgPage, params.darkTargets, null).hex;
|
|
1192
|
-
const darkWarning = solveOnPage('warning', {
|
|
1193
|
-
l: 0.76, c: Math.max(brand.c, 0.12) * 0.85 * params.chromaMul, h: darkToneHues.warning,
|
|
1194
|
-
}, darkBgPage, params.darkTargets, null).hex;
|
|
1195
|
-
const darkSuccessEnsured = (() => {
|
|
1196
|
-
let bg = darkSuccess;
|
|
1197
|
-
let fg = bestFg(bg);
|
|
1198
|
-
for (let i = 0; i < 16 && contrastRatio(bg, fg) < params.darkTargets.fgOnTone; i++) {
|
|
1199
|
-
const cur = hexToOklch(bg);
|
|
1200
|
-
bg = oklchToHex({ ...cur, l: cur.l > 0.55 ? cur.l + 0.04 : cur.l - 0.04 });
|
|
1201
|
-
fg = bestFg(bg);
|
|
1202
|
-
}
|
|
1203
|
-
return { bg, fg };
|
|
1204
|
-
})();
|
|
1205
|
-
const darkWarningEnsured = (() => {
|
|
1206
|
-
let bg = darkWarning;
|
|
1207
|
-
let fg = bestFg(bg);
|
|
1208
|
-
for (let i = 0; i < 16 && contrastRatio(bg, fg) < params.darkTargets.fgOnTone; i++) {
|
|
1209
|
-
const cur = hexToOklch(bg);
|
|
1210
|
-
bg = oklchToHex({ ...cur, l: cur.l > 0.55 ? cur.l + 0.04 : cur.l - 0.04 });
|
|
1211
|
-
fg = bestFg(bg);
|
|
1212
|
-
}
|
|
1213
|
-
return { bg, fg };
|
|
1214
|
-
})();
|
|
1215
|
-
let darkInfo = solveOnPage('info', {
|
|
1216
|
-
l: 0.68, c: Math.max(brand.c, 0.12) * 0.85 * params.chromaMul, h: darkToneHues.info,
|
|
1217
|
-
}, darkBgPage, params.darkTargets, null).hex;
|
|
1218
|
-
let darkInfoFg = bestFg(darkInfo);
|
|
1219
|
-
for (let i = 0; i < 16 && contrastRatio(darkInfo, darkInfoFg) < params.darkTargets.fgOnTone; i++) {
|
|
1220
|
-
const cur = hexToOklch(darkInfo);
|
|
1221
|
-
darkInfo = oklchToHex({ ...cur, l: cur.l > 0.55 ? cur.l + 0.04 : cur.l - 0.04 });
|
|
1222
|
-
darkInfoFg = bestFg(darkInfo);
|
|
1223
|
-
}
|
|
1224
|
-
|
|
1225
|
-
// ⑤.1b 暗色 secondary/accent:从 **DarkBase** 提亮一档,再按暗色目标独立求解。
|
|
1226
|
-
//
|
|
1227
|
-
// 基准是"未经 contrast 轴亮色侧加工的亮色 AA 结果",不是亮色成品——
|
|
1228
|
-
// 理由见 ④.1b 的种子注释:粉彩带与 toneOnPage 在深底上作用方向相反,
|
|
1229
|
-
// 继承亮色成品会让档位语义在暗色里倒过来(实测 strong 反而比 standard 弱)。
|
|
1230
|
-
// 缺省档下两者是同一次求解的同一个值,所以这一改动对缺省产出是恒等的。
|
|
1231
|
-
//
|
|
1232
|
-
// 再解一次 toneOnPage 是必须的:页面底换了(0.965 → 0.18),亮色那次求解的
|
|
1233
|
-
// 结论在这里不成立;而这两个语气没有 AA 循环(只由 ⑥ 的 enforceContrastPairs
|
|
1234
|
-
// 兜 4.5),暗档的 toneOnPage 目标正是绑住它们的那一条。
|
|
1235
|
-
const darkSecondary = solveOnPage('secondary', {
|
|
1236
|
-
...hexToOklch(secondaryDarkBase),
|
|
1237
|
-
l: Math.min(0.78, hexToOklch(secondaryDarkBase).l + 0.08),
|
|
1238
|
-
}, darkBgPage, params.darkTargets, null).hex;
|
|
1239
|
-
const darkAccent = solveOnPage('accent', {
|
|
1240
|
-
...hexToOklch(accentDarkBase),
|
|
1241
|
-
l: Math.min(0.82, hexToOklch(accentDarkBase).l + 0.08),
|
|
1242
|
-
}, darkBgPage, params.darkTargets, null).hex;
|
|
1243
|
-
|
|
1244
|
-
// ⑤.2 文字/背景层级(暗色):反转方向,正文对页面底不达标持续提亮
|
|
1245
|
-
// darkBgPage 同样在 ②.1 算出(暗色侧的 S2 求解要用)
|
|
1246
|
-
let darkTextPrimary = gray(0.92);
|
|
1247
|
-
for (let i = 0; i < 16 && contrastRatio(darkBgPage, darkTextPrimary) < params.darkTargets.textOnPage; i++) {
|
|
1248
|
-
const cur = hexToOklch(darkTextPrimary);
|
|
1249
|
-
darkTextPrimary = oklchToHex({ ...cur, l: cur.l + 0.04 });
|
|
1250
|
-
}
|
|
1251
|
-
|
|
1252
|
-
const darkCssVars: Record<string, string> = {
|
|
1253
|
-
...cssVars,
|
|
1254
|
-
'--soma-c-primary': darkPrimary,
|
|
1255
|
-
'--soma-c-primary-hover': darkHover,
|
|
1256
|
-
'--soma-c-primary-active': oklchToHex({ ...hexToOklch(darkPrimary), l: hexToOklch(darkPrimary).l + 0.1 }),
|
|
1257
|
-
'--soma-c-primary-fg': darkFg,
|
|
1258
|
-
'--soma-c-primary-soft': hexWithAlpha(scale['400'], 0.14),
|
|
1259
|
-
'--soma-c-secondary': darkSecondary,
|
|
1260
|
-
'--soma-c-secondary-fg': bestFg(darkSecondary),
|
|
1261
|
-
'--soma-c-secondary-soft': hexWithAlpha(secondaryTone.bg, 0.18),
|
|
1262
|
-
'--soma-c-accent': darkAccent,
|
|
1263
|
-
'--soma-c-accent-fg': bestFg(darkAccent),
|
|
1264
|
-
'--soma-c-accent-soft': hexWithAlpha(accentTone.bg, 0.18),
|
|
1265
|
-
'--soma-c-danger': darkDanger,
|
|
1266
|
-
'--soma-c-success': darkSuccessEnsured.bg,
|
|
1267
|
-
'--soma-c-success-fg': darkSuccessEnsured.fg,
|
|
1268
|
-
'--soma-c-warning': darkWarningEnsured.bg,
|
|
1269
|
-
'--soma-c-warning-fg': darkWarningEnsured.fg,
|
|
1270
|
-
'--soma-c-neutral': oklchToHex({ l: 0.42, c: grayChroma * 1.4, h: grayHue }),
|
|
1271
|
-
'--soma-c-neutral-fg': bestFg(oklchToHex({ l: 0.42, c: grayChroma * 1.4, h: grayHue })),
|
|
1272
|
-
'--soma-c-neutral-soft': hexWithAlpha(neutralTone.bg, 0.18),
|
|
1273
|
-
'--soma-control-border': gray(0.34),
|
|
1274
|
-
'--soma-control-bg-hover': gray(0.28),
|
|
1275
|
-
'--soma-control-bg-disabled': gray(0.26),
|
|
1276
|
-
'--soma-control-fg': gray(0.78),
|
|
1277
|
-
'--soma-control-fg-disabled': gray(0.38),
|
|
1278
|
-
'--soma-text-muted': gray(0.62),
|
|
1279
|
-
'--soma-surface-card': gray(0.24),
|
|
1280
|
-
'--soma-overlay-bg': hexWithAlpha(gray(0.12), 0.65),
|
|
1281
|
-
// ── 语义色补全(暗色):soft 底透明度略高(深底上需更实的衬底)──
|
|
1282
|
-
'--soma-c-info': darkInfo,
|
|
1283
|
-
'--soma-c-info-fg': darkInfoFg,
|
|
1284
|
-
'--soma-c-danger-soft': hexWithAlpha(darkDanger, 0.16),
|
|
1285
|
-
'--soma-c-success-soft': hexWithAlpha(darkSuccessEnsured.bg, 0.16),
|
|
1286
|
-
'--soma-c-warning-soft': hexWithAlpha(darkWarningEnsured.bg, 0.16),
|
|
1287
|
-
'--soma-c-info-soft': hexWithAlpha(darkInfo, 0.16),
|
|
1288
|
-
// 暗色下的阴影:亮色那套 rgba(0,0,0,.06~.16) 落在深底上等于不存在,
|
|
1289
|
-
// 层级会整个塌掉。加深并加大扩散,让浮层仍然"浮"得起来
|
|
1290
|
-
// 暗色玻璃:仍是白,但 alpha 只有 4%~10%(亮色是 52%~88%)——高 alpha 的白玻璃
|
|
1291
|
-
// 落在深底上会变成一块发光的板,层级反而糊掉。高光边同理减弱,只留一线。
|
|
1292
|
-
...glassTokens(true),
|
|
1293
|
-
'--soma-edge-highlight': 'rgba(255, 255, 255, 0.12)',
|
|
1294
|
-
'--soma-shadow-tinted': '0 24px 70px rgba(0, 0, 0, 0.55)',
|
|
1295
|
-
'--soma-shadow-tinted-soft': '0 16px 36px rgba(0, 0, 0, 0.45)',
|
|
1296
|
-
'--soma-shadow-sm': '0 1px 2px rgba(0, 0, 0, 0.5)',
|
|
1297
|
-
'--soma-shadow-md': '0 6px 16px rgba(0, 0, 0, 0.55)',
|
|
1298
|
-
'--soma-shadow-lg': '0 16px 40px rgba(0, 0, 0, 0.6)',
|
|
1299
|
-
// ── 文字层级(暗色反转)──
|
|
1300
|
-
'--soma-text-primary': darkTextPrimary,
|
|
1301
|
-
'--soma-text-strong': gray(0.98),
|
|
1302
|
-
'--soma-text-secondary': gray(0.72),
|
|
1303
|
-
'--soma-text-disabled': gray(0.45),
|
|
1304
|
-
// 图表序列色板(暗色):提亮一档,深底上才看得清;色相与亮色一一对应,换模式不会"换了一张图"
|
|
1305
|
-
...chartSeries(brand.h, Math.max(brand.c, 0.12), 0.72, chartAnchorsOrNull),
|
|
1306
|
-
'--soma-text-inverse': gray(0.2),
|
|
1307
|
-
'--soma-text-link': darkPrimary,
|
|
1308
|
-
'--soma-text-link-hover': darkHover,
|
|
1309
|
-
// ── 背景层级(深色基底,与 --soma-surface-card 同族渐进)──
|
|
1310
|
-
'--soma-bg-page': darkBgPage,
|
|
1311
|
-
'--soma-bg-container': gray(0.24),
|
|
1312
|
-
'--soma-bg-elevated': gray(0.28),
|
|
1313
|
-
'--soma-bg-hover': gray(0.3),
|
|
1314
|
-
// ── 边框与分割(暗色)──
|
|
1315
|
-
'--soma-border': gray(0.32),
|
|
1316
|
-
'--soma-border-strong': gray(0.4),
|
|
1317
|
-
'--soma-divider': gray(0.28),
|
|
1318
|
-
// ── 焦点环(暗色主色,透明度略高以在深底可见)──
|
|
1319
|
-
'--soma-focus-ring': `0 0 0 3px ${hexWithAlpha(darkPrimary, 0.35)}`,
|
|
1320
|
-
};
|
|
1321
|
-
|
|
1322
|
-
// ⑥ 用户逐令牌精调通道:最后合并;语义色背景保留,低于 AA 的配对前景随后自动校正
|
|
1323
|
-
//
|
|
1324
|
-
// 亮暗分列:`overrides` 是两套共用的基线,`darkOverrides` 只盖暗色且排在它之后。
|
|
1325
|
-
// 不给 darkOverrides 时 darkMerged === input.overrides,行为与分列之前完全一致。
|
|
1326
|
-
const darkMerged = input.darkOverrides
|
|
1327
|
-
? { ...input.overrides, ...input.darkOverrides }
|
|
1328
|
-
: input.overrides;
|
|
1329
|
-
if (input.overrides) {
|
|
1330
|
-
Object.assign(cssVars, input.overrides);
|
|
1331
|
-
}
|
|
1332
|
-
if (darkMerged) {
|
|
1333
|
-
Object.assign(darkCssVars, darkMerged);
|
|
1334
|
-
}
|
|
1335
|
-
// ⑥.1 淡底跟随实心色的覆盖(否则 daisy 那 35 套预设的徽标底与字来自两个色系)
|
|
1336
|
-
// 暗色侧要吃合并后的表,否则 darkOverrides 换掉的实心色配不上淡底
|
|
1337
|
-
syncSoftWithOverrides(cssVars, input.overrides);
|
|
1338
|
-
syncSoftWithOverrides(darkCssVars, darkMerged);
|
|
1339
|
-
enforceContrastPairs(cssVars);
|
|
1340
|
-
enforceContrastPairs(darkCssVars);
|
|
1341
|
-
enforceReadableText(cssVars);
|
|
1342
|
-
enforceReadableText(darkCssVars);
|
|
1343
|
-
// ⑥.2 淡底前景:必须在 overrides 之后算,AA 保障的是**最终生效**的那套底与那套色
|
|
1344
|
-
deriveOnSoftTokens(cssVars, false);
|
|
1345
|
-
deriveOnSoftTokens(darkCssVars, true);
|
|
1346
|
-
|
|
1347
|
-
// S7′ 场景颜色:与 ⑥.1/⑥.2 同一条纪律——吃最终变量表,不吃派生中途的值
|
|
1348
|
-
/** 主色被 overrides 换过时按新主色重建色阶——光球才不会与表面分属两个色系 */
|
|
1349
|
-
const makeRescale = (
|
|
1350
|
-
tokens: Record<string, string> | undefined,
|
|
1351
|
-
): ((primaryHex: string) => Record<string, string>) | null => (
|
|
1352
|
-
tokens?.['--soma-c-primary']
|
|
1353
|
-
? (primaryHex: string): Record<string, string> => {
|
|
1354
|
-
const p = hexToOklch(primaryHex);
|
|
1355
|
-
const rebuilt: Record<string, string> = {};
|
|
1356
|
-
STEPS.forEach((step, i) => {
|
|
1357
|
-
rebuilt[step] = oklchToHex({
|
|
1358
|
-
l: LIGHTNESS[i], c: Math.max(p.c, 0.02) * CHROMA_CURVE[i], h: p.h,
|
|
1359
|
-
});
|
|
1360
|
-
});
|
|
1361
|
-
return rebuilt;
|
|
1362
|
-
}
|
|
1363
|
-
: null
|
|
1364
|
-
);
|
|
1365
|
-
// 亮暗各按自己那套最终 overrides 判定要不要重建色阶:
|
|
1366
|
-
// 只在 darkOverrides 里换主色时,亮色侧不该跟着重建。
|
|
1367
|
-
const rescale = makeRescale(input.overrides);
|
|
1368
|
-
const darkRescale = makeRescale(darkMerged);
|
|
1369
|
-
Object.assign(cssVars, sceneColorTokens(cssVars, axes, params.fieldAlphas, hexWithAlpha, scale, rescale));
|
|
1370
|
-
Object.assign(darkCssVars, sceneColorTokens(darkCssVars, axes, params.fieldAlphas, hexWithAlpha, scale, darkRescale));
|
|
1371
|
-
|
|
1372
|
-
// ⑦ 组件级令牌(M-1):排在最后——它是「在最终语义令牌之上再收窄一档」,
|
|
1373
|
-
// 所以必须看得见 overrides 与场景色的最终结果。亮暗分列与 ⑥ 同纪律。
|
|
1374
|
-
const lightComponentTokens = flattenComponentTokens(input.components);
|
|
1375
|
-
const darkComponentTokens = flattenComponentTokens(
|
|
1376
|
-
input.darkComponents ? mergeComponentTokens(input.components, input.darkComponents) : input.components,
|
|
1377
|
-
);
|
|
1378
|
-
Object.assign(cssVars, lightComponentTokens);
|
|
1379
|
-
Object.assign(darkCssVars, darkComponentTokens);
|
|
1380
|
-
|
|
1381
|
-
return {
|
|
1382
|
-
scale,
|
|
1383
|
-
cssVars,
|
|
1384
|
-
darkCssVars,
|
|
1385
|
-
contrast: {
|
|
1386
|
-
primaryFg: contrastRatio(cssVars['--soma-c-primary'], cssVars['--soma-c-primary-fg']),
|
|
1387
|
-
darkPrimaryFg: contrastRatio(darkCssVars['--soma-c-primary'], darkCssVars['--soma-c-primary-fg']),
|
|
1388
|
-
},
|
|
1389
|
-
meta: {
|
|
1390
|
-
axes,
|
|
1391
|
-
separationApplied: guard.applied,
|
|
1392
|
-
pushed: guard.pushed,
|
|
1393
|
-
// 排序保证确定性:meta 也要满足"同输入必同输出"
|
|
1394
|
-
bandBroken: [...bandBroken].sort(),
|
|
1395
|
-
componentTokens: Object.keys({ ...lightComponentTokens, ...darkComponentTokens }).sort(),
|
|
1396
|
-
},
|
|
1397
|
-
};
|
|
1398
|
-
}
|
|
1399
|
-
|
|
1400
|
-
/**
|
|
1401
|
-
* 组件令牌表 → CSS 变量表:{ Button: { radius: 'var(--soma-radius-pill)' } }
|
|
1402
|
-
* → { '--soma-button-radius': 'var(--soma-radius-pill)' }
|
|
1403
|
-
*
|
|
1404
|
-
* 值必须是令牌引用或几何字面量。裸色值在这里就拦下——它是零裸色值禁令的延伸:
|
|
1405
|
-
* 组件令牌若能写死颜色,换肤就在这一层破了口子,而且破得很隐蔽(只有那一个组件不跟随)。
|
|
1406
|
-
*/
|
|
1407
|
-
function flattenComponentTokens(
|
|
1408
|
-
input: Record<string, Record<string, string>> | undefined,
|
|
1409
|
-
): Record<string, string> {
|
|
1410
|
-
if (!input) return {};
|
|
1411
|
-
const result: Record<string, string> = {};
|
|
1412
|
-
for (const [componentName, tokens] of Object.entries(input)) {
|
|
1413
|
-
for (const [key, value] of Object.entries(tokens ?? {})) {
|
|
1414
|
-
assertComponentTokenValue(componentName, key, value);
|
|
1415
|
-
result[componentTokenVar(componentName, key)] = value;
|
|
1416
|
-
}
|
|
1417
|
-
}
|
|
1418
|
-
return result;
|
|
1419
|
-
}
|
|
1420
|
-
|
|
1421
|
-
function mergeComponentTokens(
|
|
1422
|
-
base: Record<string, Record<string, string>> | undefined,
|
|
1423
|
-
patch: Record<string, Record<string, string>>,
|
|
1424
|
-
): Record<string, Record<string, string>> {
|
|
1425
|
-
const result: Record<string, Record<string, string>> = {};
|
|
1426
|
-
for (const [name, tokens] of Object.entries(base ?? {})) result[name] = { ...tokens };
|
|
1427
|
-
for (const [name, tokens] of Object.entries(patch)) {
|
|
1428
|
-
result[name] = { ...(result[name] ?? {}), ...tokens };
|
|
1429
|
-
}
|
|
1430
|
-
return result;
|
|
1431
|
-
}
|
|
1432
|
-
|
|
1433
|
-
/** 裸色值检测:#hex / rgb() / hsl() / oklch() / 具名色都不许直接写进组件令牌 */
|
|
1434
|
-
const NAKED_COLOR_PATTERN = /(^|[\s(,])(#[0-9a-fA-F]{3,8}\b|(rgba?|hsla?|oklch|oklab|lab|lch|color-mix)\s*\()/;
|
|
1435
|
-
|
|
1436
|
-
function assertComponentTokenValue(componentName: string, key: string, value: string): void {
|
|
1437
|
-
if (typeof value !== 'string' || !value.trim()) {
|
|
1438
|
-
throw new Error(
|
|
1439
|
-
`[soma-core][主题] 组件令牌 ${componentName}.${key} 的值必须是非空字符串`,
|
|
1440
|
-
);
|
|
1441
|
-
}
|
|
1442
|
-
if (NAKED_COLOR_PATTERN.test(value)) {
|
|
1443
|
-
throw new Error(
|
|
1444
|
-
`[soma-core][主题] 组件令牌 ${componentName}.${key} 写了裸色值 "${value}"。`
|
|
1445
|
-
+ '\n 组件令牌是语义令牌的收窄,不是新的颜色真源——'
|
|
1446
|
-
+ '写死颜色会让这一个组件不跟随换肤,而且很难发现。请改写 var(--soma-…)。',
|
|
1447
|
-
);
|
|
1448
|
-
}
|
|
1449
|
-
}
|
|
1450
|
-
|
|
1451
|
-
/**
|
|
1452
|
-
* 派生结果 → 根元素属性。
|
|
1453
|
-
*
|
|
1454
|
-
* 纯函数而不是写在 applyTheme 里:服务端渲染路径要用同一份逻辑预先戳属性,
|
|
1455
|
-
* 否则 immersive 主题的页面会在补水前用色相编码、补水后切成信号编码,
|
|
1456
|
-
* 闪一下。属性是编码通道的开关,必须和首屏 HTML 一起到达。
|
|
1457
|
-
*/
|
|
1458
|
-
export function themeRootAttributes(theme: SomaDerivedTheme): Record<string, string> {
|
|
1459
|
-
return {
|
|
1460
|
-
'data-soma-semantics': theme.meta.axes.palette.semantics,
|
|
1461
|
-
'data-soma-field': theme.meta.axes.scene.field,
|
|
1462
|
-
};
|
|
1463
|
-
}
|
|
1464
|
-
|
|
1465
|
-
function nearestIndex(ladder: number[], value: number): number {
|
|
1466
|
-
let best = 0;
|
|
1467
|
-
ladder.forEach((l, i) => {
|
|
1468
|
-
if (Math.abs(l - value) < Math.abs(ladder[best] - value)) best = i;
|
|
1469
|
-
});
|
|
1470
|
-
return best;
|
|
1471
|
-
}
|
|
1472
|
-
|
|
1473
|
-
function bestFg(bg: string): string {
|
|
1474
|
-
return contrastRatio(bg, '#ffffff') >= contrastRatio(bg, '#111827') ? '#ffffff' : '#111827';
|
|
1475
|
-
}
|
|
1476
|
-
|
|
1477
|
-
function hexWithAlpha(hex: string, alpha: number): string {
|
|
1478
|
-
const [r, g, b] = parseHex(hex).map((v) => Math.round(v * 255));
|
|
1479
|
-
return `rgba(${r}, ${g}, ${b}, ${alpha})`;
|
|
1480
|
-
}
|
|
1481
|
-
|
|
1482
|
-
// ─── 注入 ───────────────────────────────────────────────────
|
|
1483
|
-
|
|
1484
|
-
/** 令牌前缀:批写时据此区分「本引擎写的」与「宿主自己写的」内联声明 */
|
|
1485
|
-
const TOKEN_PREFIX = '--soma-';
|
|
1486
|
-
|
|
1487
|
-
/**
|
|
1488
|
-
* 换肤期间挂在根节点上的过渡抑制类名(生产化强化 §6,作业单 P-4)。
|
|
1489
|
-
*
|
|
1490
|
-
* 为什么需要:一次换肤要改 86 个 CSS 变量,而组件库里大量元素带 `transition`
|
|
1491
|
-
* (按钮/输入框的 background、border、color 都在过渡列表里)。变量一改,
|
|
1492
|
-
* 这些元素会同时进入过渡——视觉上是"整页缓慢褪色",且几百个元素并发过渡实打实吃 CPU。
|
|
1493
|
-
* 换肤是一次状态切换,不是一次交互反馈,它本来就不该有动画。
|
|
1494
|
-
*
|
|
1495
|
-
* 配套 CSS 规则由 soma-ui 的聚合样式表提供(`THEME_SWITCHING_CSS`):
|
|
1496
|
-
* 类名是两包之间的契约,改名要两边一起改。未接入 soma-ui 的 Host 只是拿不到抑制效果,
|
|
1497
|
-
* 不会因此出错——挂一个没有规则匹配的类不产生任何副作用。
|
|
1498
|
-
*/
|
|
1499
|
-
export const THEME_SWITCHING_CLASS = 'soma-theme-switching';
|
|
1500
|
-
|
|
1501
|
-
/**
|
|
1502
|
-
* 抑制类的待摘除凭据:值是本次换肤的序号。
|
|
1503
|
-
* 连点换肤(亮 → 暗 → 亮)时,前一次调度的摘除会落在后一次写入之后,
|
|
1504
|
-
* 那一摘就会让后一次换肤的过渡漏出来。所以只有"最后一次调度"有资格摘。
|
|
1505
|
-
*/
|
|
1506
|
-
const pendingThemeRelease = new WeakMap<HTMLElement, number>();
|
|
1507
|
-
|
|
1508
|
-
/** 把派生令牌注入 :root(运行时换肤/切暗色:重复调用即时生效) */
|
|
1509
|
-
export function applyTheme(input: SomaThemeInput, root?: HTMLElement): SomaDerivedTheme {
|
|
1510
|
-
const theme = deriveTheme(input);
|
|
1511
|
-
const el = root ?? (typeof document !== 'undefined' ? document.documentElement : null);
|
|
1512
|
-
if (el) {
|
|
1513
|
-
// 先挂抑制类再写变量:两者在同一个任务里完成,浏览器只做一次样式重算,
|
|
1514
|
-
// 重算时 transition 已被 none 覆盖,新旧值直接跳变,不会生成任何过渡。
|
|
1515
|
-
el.classList.add(THEME_SWITCHING_CLASS);
|
|
1516
|
-
try {
|
|
1517
|
-
writeTokensBatch(el, input.dark ? theme.darkCssVars : theme.cssVars);
|
|
1518
|
-
// 编码通道开关与令牌同批写:属性决定 immersive 的信号规则命不命中,
|
|
1519
|
-
// 分两次写会让页面在两帧之间处于"色相已换、信号未开"的空档
|
|
1520
|
-
for (const [name, value] of Object.entries(themeRootAttributes(theme))) {
|
|
1521
|
-
el.setAttribute(name, value);
|
|
1522
|
-
}
|
|
1523
|
-
} finally {
|
|
1524
|
-
// finally 而不是写在 try 之后:批写抛错(宿主给了个 style 只读的元素之类)
|
|
1525
|
-
// 也必须把抑制类摘掉,否则整页的 transition 会被永久禁掉——
|
|
1526
|
-
// 那是比换肤闪一下严重得多的后果。
|
|
1527
|
-
scheduleThemeTransitionRelease(el);
|
|
1528
|
-
}
|
|
1529
|
-
}
|
|
1530
|
-
return theme;
|
|
1531
|
-
}
|
|
1532
|
-
|
|
1533
|
-
/**
|
|
1534
|
-
* 下一帧(准确说是"下下帧")摘除抑制类。
|
|
1535
|
-
*
|
|
1536
|
-
* 为什么是双 rAF:rAF 回调跑在本帧的样式重算与绘制**之前**。若只等一帧就摘,
|
|
1537
|
-
* 摘除与新令牌值会落进同一次样式重算,浏览器看到的是"transition 有效 + 值变了",
|
|
1538
|
-
* 过渡照样会起——等于没抑制。多等一帧,保证新值已经至少绘制过一次,
|
|
1539
|
-
* 此时再恢复 transition 就没有可过渡的差值了。
|
|
1540
|
-
*
|
|
1541
|
-
* 没有 rAF 的环境(SSR 后的补水前、部分测试环境)退回 setTimeout:
|
|
1542
|
-
* 抑制类必须摘掉这件事不能依赖 rAF 是否存在。
|
|
1543
|
-
*/
|
|
1544
|
-
function scheduleThemeTransitionRelease(el: HTMLElement): void {
|
|
1545
|
-
const seq = (pendingThemeRelease.get(el) ?? 0) + 1;
|
|
1546
|
-
pendingThemeRelease.set(el, seq);
|
|
1547
|
-
nextFrame(() =>
|
|
1548
|
-
nextFrame(() => {
|
|
1549
|
-
if (pendingThemeRelease.get(el) !== seq) return;
|
|
1550
|
-
pendingThemeRelease.delete(el);
|
|
1551
|
-
el.classList.remove(THEME_SWITCHING_CLASS);
|
|
1552
|
-
}),
|
|
1553
|
-
);
|
|
1554
|
-
}
|
|
1555
|
-
|
|
1556
|
-
function nextFrame(run: () => void): void {
|
|
1557
|
-
if (typeof requestAnimationFrame === 'function') {
|
|
1558
|
-
requestAnimationFrame(() => run());
|
|
1559
|
-
return;
|
|
1560
|
-
}
|
|
1561
|
-
setTimeout(run, 0);
|
|
1562
|
-
}
|
|
1563
|
-
|
|
1564
|
-
/**
|
|
1565
|
-
* 一次性 cssText 批写,而不是逐个 setProperty。
|
|
1566
|
-
*
|
|
1567
|
-
* 为什么改:一次换肤要写 86 个变量(deriveTheme 的实测产出数),逐个 setProperty 就是
|
|
1568
|
-
* 86 次 CSSOM 变更调用,批写只有 1 次字符串解析 + 1 次变更。实测(jsdom,200 次取中均值)
|
|
1569
|
-
* 86 个令牌:逐个 2.09ms → 批写 1.40ms,省约 1/3。
|
|
1570
|
-
*
|
|
1571
|
-
* 为什么收益只在 CPU 不在重排:两种写法都是在同一个任务里改同一个节点(:root)的内联样式,
|
|
1572
|
-
* 浏览器把样式失效合并成一次样式重算 + 一次重排,重排次数完全相同;
|
|
1573
|
-
* 省下的是 86 次 CSSOM 调用本身的开销,所以这是纯 CPU 收益,不要宣称成"少了重排"。
|
|
1574
|
-
*
|
|
1575
|
-
* 为什么要保留既有声明:宿主可能在同一个元素上写过自己的内联样式(如 color-scheme),
|
|
1576
|
-
* 整段覆盖会把它们连坐删掉。这里按声明名逐条筛,只重写 --soma-* 前缀的部分;
|
|
1577
|
-
* 不走 cssText 字符串切分,是因为值里可能藏着 `url(data:image/svg+xml;base64,...)` 这类
|
|
1578
|
-
* 带分号的内容,按 `;` 切会把它劈坏。
|
|
1579
|
-
*/
|
|
1580
|
-
function writeTokensBatch(el: HTMLElement, vars: Record<string, string>): void {
|
|
1581
|
-
const style = el.style;
|
|
1582
|
-
const preserved: string[] = [];
|
|
1583
|
-
for (let i = 0; i < style.length; i++) {
|
|
1584
|
-
const name = style.item(i);
|
|
1585
|
-
if (name.startsWith(TOKEN_PREFIX)) continue;
|
|
1586
|
-
const priority = style.getPropertyPriority(name);
|
|
1587
|
-
preserved.push(`${name}: ${style.getPropertyValue(name)}${priority ? ` !${priority}` : ''}`);
|
|
1588
|
-
}
|
|
1589
|
-
|
|
1590
|
-
const parts = preserved;
|
|
1591
|
-
for (const key in vars) {
|
|
1592
|
-
parts.push(`${key}: ${vars[key]}`);
|
|
1593
|
-
}
|
|
1594
|
-
style.cssText = `${parts.join('; ')};`;
|
|
1595
|
-
}
|