soma-core 1.3.2 → 1.3.4
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 +43 -0
- package/app/SomaPageClient.tsx +22 -68
- package/app/[...path]/page.tsx +7 -6
- package/app/api/[...path]/route.ts +3 -3
- package/app/api/soma-registry/[...path]/route.ts +67 -0
- package/app/components/SomaHostPage.tsx +3 -8
- package/app/components/SomaPageClientBoundary.tsx +13 -0
- package/app/layout.tsx +6 -1
- package/app/page.tsx +3 -3
- package/app/soma/manifest/route.ts +1 -0
- package/app/soma/page-object/route.ts +1 -1
- package/bin/soma-lsp.cjs +1 -4
- package/core/build/compiler/full-manifest-builder.ts +19 -23
- package/core/build/compiler/html-include-expander.ts +56 -0
- package/core/build/compiler/page-assets.ts +26 -0
- package/core/build/compiler/page-declaration-compiler.ts +85 -0
- package/core/build/compiler/rollup-plugin-soma.ts +4 -13
- package/core/build/compiler/route-builder.ts +0 -2
- package/core/build/compiler/rspack-plugin-soma.js +1 -10
- package/core/build/compiler/soma-manifest-webpack-plugin.js +54 -9
- package/core/build/compiler/soma-precompile.js +3581 -2387
- package/core/build/compiler/soma-precompile.ts +44 -2
- package/core/build/compiler/soma-rspack-yaml-loader.js +5 -8
- package/core/build/compiler/soma-webpack-loader.js +6 -15
- package/core/build/compiler/vite-plugin-soma.ts +9 -21
- package/core/build/component/pack-from-dir.ts +58 -0
- package/core/build/component/package-loader.ts +281 -0
- package/core/build/eject/apply-eject.ts +133 -0
- package/core/build/eject/plan-eject.ts +133 -0
- package/core/build/lsp/cross-file-diagnostics.cjs +82 -113
- package/core/build/lsp/extra-completion.cjs +14 -8
- package/core/build/lsp/lsp-navigation.cjs +50 -43
- package/core/build/lsp/soma-declaration.cjs +85 -0
- package/core/build/lsp/ui-yaml-completion.cjs +98 -104
- package/core/build/v2/block-compile.ts +200 -0
- package/core/build/v2/block-loader.ts +33 -0
- package/core/build/v2/html-index.ts +120 -0
- package/core/build/v2/migrate-v1.ts +370 -0
- package/core/build/v2/soma-file-loader.ts +216 -0
- package/core/client/adaptive/flush-scheduler.ts +96 -0
- package/core/client/adaptive/hysteresis.ts +56 -0
- package/core/client/adaptive/index.ts +23 -0
- package/core/client/adaptive/observer-pool.ts +90 -0
- package/core/client/base/SomaPageRootBase.ts +50 -0
- package/core/client/compiler/adaptive-compile.ts +136 -0
- package/core/client/compiler/manifest-compiler.ts +155 -27
- package/core/client/component/ai-catalog.ts +277 -0
- package/core/client/component/component-definition.types.ts +65 -0
- package/core/client/component/component-expander.ts +119 -0
- package/core/client/component/component-manager.ts +933 -0
- package/core/client/component/component-pack.ts +445 -0
- package/core/client/component/component-registry.ts +71 -0
- package/core/client/component/contract-compat.ts +132 -0
- package/core/client/component/example-v2.ts +132 -0
- package/core/client/component/pack-styles.ts +94 -0
- package/core/client/component/scoped-adapter.ts +85 -0
- package/core/client/component/verify-pack.ts +247 -0
- package/core/client/container/MiniProgramContainerAdapter.ts +15 -1
- package/core/client/container/ReactNativeContainerAdapter.ts +15 -1
- package/core/client/container/SomaContainerAdapter.ts +186 -180
- package/core/client/data/data-object-resolver.ts +417 -0
- package/core/client/diagnostics/SomaDiagnostics.ts +187 -186
- package/core/client/diagnostics/boot-timings.ts +152 -0
- package/core/client/engine/asset-resolver.ts +12 -2
- package/core/client/engine/dom-renderer.ts +249 -24
- package/core/client/engine/emit-event.ts +21 -0
- package/core/client/engine/event-engine.ts +34 -4
- package/core/client/engine/on-change-engine.ts +1 -1
- package/core/client/engine/property-watcher.ts +1 -1
- package/core/client/engine/reactive-proxy.ts +11 -10
- package/core/client/engine/render-engine.ts +39 -4
- package/core/client/engine/runtime-builder.ts +23 -0
- package/core/client/engine/soma-bootstrap.ts +380 -7
- package/core/client/engine/style-binder.ts +47 -1
- package/core/client/observability/error-reporter.ts +173 -0
- package/core/client/parser/adaptive-parser.ts +264 -0
- package/core/client/parser/data-config-parser.ts +396 -0
- package/core/client/parser/pipeline-parser.ts +15 -3
- package/core/client/parser/style-config-parser.ts +65 -2
- package/core/client/parser/ui-config-parser.ts +52 -3
- package/core/client/parser/v2/namespace.ts +182 -0
- package/core/client/parser/v2/page-parser.ts +359 -0
- package/core/client/parser/v2/use-parser.ts +412 -0
- package/core/client/parser/value-lang.ts +340 -0
- package/core/client/pipes/pipe-registry.ts +249 -0
- package/core/client/quality/SomaQualityRegistry.ts +3 -0
- package/core/client/registry/declaration-renderer.ts +161 -0
- package/core/client/registry/index.ts +28 -0
- package/core/client/registry/page-lifecycle.ts +171 -0
- package/core/client/registry/remote-page.ts +139 -0
- package/core/client/runtime/SomaRuntimeServices.ts +24 -0
- package/core/client/security/attribute-presence.ts +70 -0
- package/core/client/security/html-sanitizer.ts +113 -0
- package/core/client/security/url-guard.ts +0 -0
- package/core/client/theme/harmony.ts +307 -0
- package/core/client/theme/scene-tokens.ts +134 -0
- package/core/client/theme/theme-axes.ts +228 -0
- package/core/client/theme/theme-engine.ts +1196 -0
- package/core/client/theme/tone-solver.ts +118 -0
- package/core/client/typography/typography-base.ts +34 -0
- package/core/client/validation/contract-validator.ts +48 -5
- package/core/index.ts +262 -2
- package/core/server/api/IService.ts +18 -6
- package/core/server/api/load-host-service.ts +3 -3
- package/core/server/host/content-security-policy.ts +190 -0
- package/core/server/host/csp-nonce-metadata.ts +75 -0
- package/core/server/host/resolve-host-request-hook.ts +5 -0
- package/core/server/host/server-page-assets.ts +34 -7
- package/core/server/host/soma-page-compile.ts +33 -0
- package/core/server/index.ts +45 -1
- package/core/server/infra/cache/ServerFileCache.ts +1 -1
- package/core/server/mock/node/cli.mjs +2 -2
- package/core/server/registry/api-registry-store.ts +518 -0
- package/core/server/registry/conditional-object-store.ts +29 -0
- package/core/server/registry/declaration-precompiler.ts +99 -0
- package/core/server/registry/in-memory-conditional-object-store.ts +43 -0
- package/core/server/registry/index.ts +142 -0
- package/core/server/registry/page-registry-repository.ts +373 -0
- package/core/server/registry/page-registry-store.ts +932 -0
- package/core/server/registry/registry-error.ts +17 -0
- package/core/server/registry/registry-file-lock.ts +173 -0
- package/core/server/registry/registry-response.ts +71 -0
- package/core/server/registry/registry-subjects.ts +194 -0
- package/core/server/registry/registry-write-pipeline.ts +240 -0
- package/core/server/registry/request-body-limit.ts +99 -0
- package/core/server/registry/services/apis/Get.ts +25 -0
- package/core/server/registry/services/apis/List.ts +41 -0
- package/core/server/registry/services/apis/Register.ts +39 -0
- package/core/server/registry/services/apis/Unregister.ts +24 -0
- package/core/server/registry/services/index.ts +40 -0
- package/core/server/registry/services/pages/Get.ts +96 -0
- package/core/server/registry/services/pages/List.ts +53 -0
- package/core/server/registry/services/pages/Register.ts +49 -0
- package/core/server/registry/services/pages/Rollback.ts +36 -0
- package/core/server/registry/services/pages/Unregister.ts +23 -0
- package/core/server/registry/services/service-utils.ts +21 -0
- package/core/server/registry/validation/compile-gate.ts +54 -0
- package/core/server/registry/validation/component-existence.ts +55 -0
- package/core/server/registry/validation/credential-ban.ts +86 -0
- package/core/server/registry/validation/cross-check.ts +67 -0
- package/core/server/registry/validation/declaration-safety-scan.ts +102 -0
- package/core/shared/types/adaptive.types.ts +109 -0
- package/core/shared/types/component-contract.types.ts +120 -0
- package/core/shared/types/data-config.types.ts +105 -0
- package/core/shared/types/domain.types.ts +6 -0
- package/core/shared/types/engine.types.ts +41 -35
- package/core/shared/types/manifest.types.ts +55 -32
- package/core/shared/types/scope-manifest.types.ts +96 -0
- package/core/shared/types/style-config.types.ts +9 -0
- package/core/shared/types/ui-config.types.ts +118 -98
- package/dist/cli/soma.js +20 -5
- package/dist/core/index.cjs +7811 -1380
- package/dist/types/build/compiler/full-manifest-builder.d.ts +6 -2
- package/dist/types/build/compiler/html-include-expander.d.ts +19 -0
- package/dist/types/build/compiler/page-assets.d.ts +3 -0
- package/dist/types/build/compiler/page-declaration-compiler.d.ts +33 -0
- package/dist/types/build/compiler/rollup-plugin-soma.d.ts +0 -2
- package/dist/types/build/compiler/route-builder.d.ts +0 -1
- package/dist/types/build/compiler/soma-precompile.d.ts +17 -0
- package/dist/types/build/compiler/vite-plugin-soma.d.ts +2 -7
- package/dist/types/build/component/pack-from-dir.d.ts +17 -0
- package/dist/types/build/component/package-loader.d.ts +40 -0
- package/dist/types/build/eject/apply-eject.d.ts +22 -0
- package/dist/types/build/eject/plan-eject.d.ts +32 -0
- package/dist/types/build/v2/block-compile.d.ts +28 -0
- package/dist/types/build/v2/block-loader.d.ts +9 -0
- package/dist/types/build/v2/html-index.d.ts +37 -0
- package/dist/types/build/v2/migrate-v1.d.ts +32 -0
- package/dist/types/build/v2/soma-file-loader.d.ts +45 -0
- package/dist/types/client/adaptive/flush-scheduler.d.ts +13 -0
- package/dist/types/client/adaptive/hysteresis.d.ts +16 -0
- package/dist/types/client/adaptive/index.d.ts +5 -0
- package/dist/types/client/adaptive/observer-pool.d.ts +15 -0
- package/dist/types/client/base/SomaPageRootBase.d.ts +33 -0
- package/dist/types/client/compiler/adaptive-compile.d.ts +26 -0
- package/dist/types/client/compiler/manifest-compiler.d.ts +13 -2
- package/dist/types/client/component/ai-catalog.d.ts +73 -0
- package/dist/types/client/component/component-definition.types.d.ts +54 -0
- package/dist/types/client/component/component-expander.d.ts +25 -0
- package/dist/types/client/component/component-manager.d.ts +160 -0
- package/dist/types/client/component/component-pack.d.ts +110 -0
- package/dist/types/client/component/component-registry.d.ts +12 -0
- package/dist/types/client/component/contract-compat.d.ts +16 -0
- package/dist/types/client/component/example-v2.d.ts +9 -0
- package/dist/types/client/component/pack-styles.d.ts +22 -0
- package/dist/types/client/component/scoped-adapter.d.ts +18 -0
- package/dist/types/client/component/verify-pack.d.ts +14 -0
- package/dist/types/client/data/data-object-resolver.d.ts +71 -0
- package/dist/types/client/diagnostics/SomaDiagnostics.d.ts +2 -1
- package/dist/types/client/diagnostics/boot-timings.d.ts +30 -0
- package/dist/types/client/engine/asset-resolver.d.ts +7 -1
- package/dist/types/client/engine/dom-renderer.d.ts +51 -1
- package/dist/types/client/engine/emit-event.d.ts +6 -0
- package/dist/types/client/engine/event-engine.d.ts +6 -0
- package/dist/types/client/engine/render-engine.d.ts +25 -1
- package/dist/types/client/engine/runtime-builder.d.ts +7 -0
- package/dist/types/client/engine/soma-bootstrap.d.ts +118 -0
- package/dist/types/client/observability/error-reporter.d.ts +51 -0
- package/dist/types/client/parser/adaptive-parser.d.ts +28 -0
- package/dist/types/client/parser/data-config-parser.d.ts +34 -0
- package/dist/types/client/parser/pipeline-parser.d.ts +2 -0
- package/dist/types/client/parser/style-config-parser.d.ts +5 -3
- package/dist/types/client/parser/ui-config-parser.d.ts +22 -1
- package/dist/types/client/parser/v2/namespace.d.ts +52 -0
- package/dist/types/client/parser/v2/page-parser.d.ts +21 -0
- package/dist/types/client/parser/v2/use-parser.d.ts +72 -0
- package/dist/types/client/parser/value-lang.d.ts +63 -0
- package/dist/types/client/pipes/pipe-registry.d.ts +38 -0
- package/dist/types/client/registry/declaration-renderer.d.ts +50 -0
- package/dist/types/client/registry/index.d.ts +10 -0
- package/dist/types/client/registry/page-lifecycle.d.ts +61 -0
- package/dist/types/client/registry/remote-page.d.ts +52 -0
- package/dist/types/client/runtime/SomaRuntimeServices.d.ts +16 -0
- package/dist/types/client/security/attribute-presence.d.ts +7 -0
- package/dist/types/client/security/html-sanitizer.d.ts +37 -0
- package/dist/types/client/security/url-guard.d.ts +11 -0
- package/dist/types/client/theme/harmony.d.ts +77 -0
- package/dist/types/client/theme/scene-tokens.d.ts +25 -0
- package/dist/types/client/theme/theme-axes.d.ts +81 -0
- package/dist/types/client/theme/theme-engine.d.ts +77 -0
- package/dist/types/client/theme/tone-solver.d.ts +47 -0
- package/dist/types/client/typography/typography-base.d.ts +15 -0
- package/dist/types/client/validation/contract-validator.d.ts +2 -0
- package/dist/types/index.d.ts +47 -2
- package/dist/types/server/api/IService.d.ts +18 -6
- package/dist/types/server/host/content-security-policy.d.ts +53 -0
- package/dist/types/server/host/csp-nonce-metadata.d.ts +32 -0
- package/dist/types/server/host/resolve-host-request-hook.d.ts +5 -0
- package/dist/types/server/host/server-page-assets.d.ts +2 -0
- package/dist/types/server/host/soma-page-compile.d.ts +7 -0
- package/dist/types/server/index.d.ts +6 -1
- package/dist/types/server/registry/api-registry-store.d.ts +141 -0
- package/dist/types/server/registry/conditional-object-store.d.ts +27 -0
- package/dist/types/server/registry/declaration-precompiler.d.ts +30 -0
- package/dist/types/server/registry/in-memory-conditional-object-store.d.ts +8 -0
- package/dist/types/server/registry/index.d.ts +29 -0
- package/dist/types/server/registry/page-registry-repository.d.ts +58 -0
- package/dist/types/server/registry/page-registry-store.d.ts +259 -0
- package/dist/types/server/registry/registry-error.d.ts +12 -0
- package/dist/types/server/registry/registry-file-lock.d.ts +20 -0
- package/dist/types/server/registry/registry-response.d.ts +18 -0
- package/dist/types/server/registry/registry-subjects.d.ts +59 -0
- package/dist/types/server/registry/registry-write-pipeline.d.ts +48 -0
- package/dist/types/server/registry/request-body-limit.d.ts +31 -0
- package/dist/types/server/registry/services/apis/Get.d.ts +10 -0
- package/dist/types/server/registry/services/apis/List.d.ts +10 -0
- package/dist/types/server/registry/services/apis/Register.d.ts +13 -0
- package/dist/types/server/registry/services/apis/Unregister.d.ts +12 -0
- package/dist/types/server/registry/services/index.d.ts +3 -0
- package/dist/types/server/registry/services/pages/Get.d.ts +10 -0
- package/dist/types/server/registry/services/pages/List.d.ts +13 -0
- package/dist/types/server/registry/services/pages/Register.d.ts +11 -0
- package/dist/types/server/registry/services/pages/Rollback.d.ts +9 -0
- package/dist/types/server/registry/services/pages/Unregister.d.ts +9 -0
- package/dist/types/server/registry/services/service-utils.d.ts +10 -0
- package/dist/types/server/registry/validation/compile-gate.d.ts +12 -0
- package/dist/types/server/registry/validation/component-existence.d.ts +14 -0
- package/dist/types/server/registry/validation/credential-ban.d.ts +15 -0
- package/dist/types/server/registry/validation/cross-check.d.ts +16 -0
- package/dist/types/server/registry/validation/declaration-safety-scan.d.ts +15 -0
- package/dist/types/shared/types/adaptive.types.d.ts +88 -0
- package/dist/types/shared/types/component-contract.types.d.ts +78 -0
- package/dist/types/shared/types/data-config.types.d.ts +81 -0
- package/dist/types/shared/types/domain.types.d.ts +6 -0
- package/dist/types/shared/types/engine.types.d.ts +6 -0
- package/dist/types/shared/types/manifest.types.d.ts +23 -0
- package/dist/types/shared/types/scope-manifest.types.d.ts +82 -0
- package/dist/types/shared/types/style-config.types.d.ts +8 -0
- package/dist/types/shared/types/ui-config.types.d.ts +20 -0
- package/editor/vscode/package.json +1 -24
- package/global.d.ts +5 -11
- package/next.config.js +85 -28
- package/package.json +33 -11
- package/proxy.ts +62 -0
- package/tailwind.config.ts +0 -1
- package/core/build/lsp/event-yaml-completion.cjs +0 -106
- package/core/client/engine/theme-variables.ts +0 -37
- package/dist/tsconfig.types.tsbuildinfo +0 -1
- package/dist/types/client/engine/theme-variables.d.ts +0 -3
- package/editor/vscode/syntaxes/soma-event-yaml.tmLanguage.json +0 -30
- package/middleware.ts +0 -33
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
// 主题轴解析(REQ-007 S0):词元 → 数值参数。
|
|
2
|
+
//
|
|
3
|
+
// 这是全体系**唯一的调参处**。所有档位到数值的映射都是本文件顶部的 const 表,
|
|
4
|
+
// 下游阶段(harmony / tone-solver / scene-tokens)只认数值、不认词元——
|
|
5
|
+
// 因此"把 analogous 调得更紧一点"这类需求永远只改这里一张表,
|
|
6
|
+
// 不会散进派生链的十几个算式里。
|
|
7
|
+
//
|
|
8
|
+
// 缺省列即现状:全部轴省略时解析出的参数,必须让派生结果与 REQ-007 之前
|
|
9
|
+
// 字节级一致(theme-snapshot 闸门盯着这条)。其中 CONTRAST_TARGETS.standard
|
|
10
|
+
// 的数值是**逆算**出来的——把现状 l=0.60/0.58/0.72 三个字面常量的实测对比度
|
|
11
|
+
// 反填进表,这样"从目标对比度解出明度"与"直接写死明度"在缺省档殊途同归。
|
|
12
|
+
|
|
13
|
+
// ─── 轴词元(封闭集,与《主题属性设计》§4 逐字一致) ─────────────────
|
|
14
|
+
|
|
15
|
+
export type SomaHarmony = 'functional' | 'analogous' | 'monochrome' | 'complementary';
|
|
16
|
+
export type SomaSemantics = 'faithful' | 'tinted' | 'immersive';
|
|
17
|
+
export type SomaChroma = 'muted' | 'balanced' | 'vivid';
|
|
18
|
+
export type SomaContrast = 'soft' | 'standard' | 'strong';
|
|
19
|
+
export type SomaField = 'flat' | 'tinted' | 'aurora';
|
|
20
|
+
export type SomaIntensity = 'whisper' | 'soft' | 'bold';
|
|
21
|
+
export type SomaMaterial = 'solid' | 'glass';
|
|
22
|
+
|
|
23
|
+
export interface SomaPaletteAxes {
|
|
24
|
+
/** 色相编排:语义色与品牌的色相关系 */
|
|
25
|
+
harmony?: SomaHarmony;
|
|
26
|
+
/** 语义色忠实度:success/warning/danger 允许被 harmony 带走多远 */
|
|
27
|
+
semantics?: SomaSemantics;
|
|
28
|
+
/** 彩度个性:素净 ↔ 浓烈 */
|
|
29
|
+
chroma?: SomaChroma;
|
|
30
|
+
/** 明度反差:柔光粉彩 ↔ 高反差;AA 底线不随档移动 */
|
|
31
|
+
contrast?: SomaContrast;
|
|
32
|
+
/** 显式辅色(≤3):点名代替派生,依次锁 secondary/accent/info 的色相锚 */
|
|
33
|
+
accents?: string[];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface SomaSceneAxes {
|
|
37
|
+
/** 背景场:页面的"底"是平色、染色还是环境光场 */
|
|
38
|
+
field?: SomaField;
|
|
39
|
+
/** 场强三档(flat 下无义) */
|
|
40
|
+
intensity?: SomaIntensity;
|
|
41
|
+
/** 材质缺省档;组件级 surface prop 仍可逐个覆盖 */
|
|
42
|
+
material?: SomaMaterial;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** 缺省回落后的确定轴位——meta 观测面与全部下游阶段的输入 */
|
|
46
|
+
export interface SomaResolvedAxes {
|
|
47
|
+
readonly palette: {
|
|
48
|
+
readonly harmony: SomaHarmony;
|
|
49
|
+
readonly semantics: SomaSemantics;
|
|
50
|
+
readonly chroma: SomaChroma;
|
|
51
|
+
readonly contrast: SomaContrast;
|
|
52
|
+
readonly accents: readonly string[];
|
|
53
|
+
};
|
|
54
|
+
readonly scene: {
|
|
55
|
+
readonly field: SomaField;
|
|
56
|
+
readonly intensity: SomaIntensity;
|
|
57
|
+
readonly material: SomaMaterial;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** 三个目标对比度:语气底对页面底、前景对语气底、正文对页面底 */
|
|
62
|
+
export interface SomaContrastTargets {
|
|
63
|
+
readonly toneOnPage: number;
|
|
64
|
+
readonly fgOnTone: number;
|
|
65
|
+
readonly textOnPage: number;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** 档位解析出的数值参数 */
|
|
69
|
+
export interface SomaAxisParams {
|
|
70
|
+
/** 色相压缩系数:0 = 功能色相原值,1 = 完全归一到品牌色相 */
|
|
71
|
+
readonly harmonyK: number;
|
|
72
|
+
/** complementary 专用:accent 先跳到品牌对侧再压缩 */
|
|
73
|
+
readonly accentComplement: boolean;
|
|
74
|
+
/** 彩度乘数,乘在既有彩度算式上 */
|
|
75
|
+
readonly chromaMul: number;
|
|
76
|
+
readonly targets: SomaContrastTargets;
|
|
77
|
+
readonly darkTargets: SomaContrastTargets;
|
|
78
|
+
/** contrast:soft 的粉彩明度带;null = 不约束(现状) */
|
|
79
|
+
readonly softLightnessBand: readonly [number, number] | null;
|
|
80
|
+
/** 环境光三团的 alpha;null = flat(产 transparent) */
|
|
81
|
+
readonly fieldAlphas: readonly [number, number, number] | null;
|
|
82
|
+
readonly glassEnabled: boolean;
|
|
83
|
+
/** = semantics === 'immersive':信号通道令牌是否产出生效值 */
|
|
84
|
+
readonly signalEnabled: boolean;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export class SomaThemeAxisError extends Error {
|
|
88
|
+
constructor(message: string) {
|
|
89
|
+
super(`[soma-core][主题] ${message}`);
|
|
90
|
+
this.name = 'SomaThemeAxisError';
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// ─── 档位参数表(唯一调参处) ────────────────────────────────────────
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* 色相压缩系数。
|
|
98
|
+
*
|
|
99
|
+
* analogous 的 0.72 来自可行性演算:对 `#4f8cff` 产出 79° 色相带,
|
|
100
|
+
* 对标原型手写八色的 91°(《主题属性设计》§5)。
|
|
101
|
+
*/
|
|
102
|
+
const HARMONY_K: Record<SomaHarmony, number> = {
|
|
103
|
+
functional: 0,
|
|
104
|
+
analogous: 0.72,
|
|
105
|
+
monochrome: 1,
|
|
106
|
+
complementary: 0.72,
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
/** 彩度乘数。balanced = 1.0 是现状档,改它会动全部预设 */
|
|
110
|
+
const CHROMA_MUL: Record<SomaChroma, number> = {
|
|
111
|
+
muted: 0.6,
|
|
112
|
+
balanced: 1.0,
|
|
113
|
+
vivid: 1.35,
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* 目标对比度组(Leonardo 路线:明度是解出来的,不是写死的)。
|
|
118
|
+
*
|
|
119
|
+
* standard 一列**逆算自现状**:现状三个语义色常量 l=0.60/0.58/0.72 落在
|
|
120
|
+
* `--soma-bg-page`(亮档 0.965)上的实测对比度约 4.0;fgOnTone 4.5 是既有
|
|
121
|
+
* `enforceContrastPairs` 的硬保障值;textOnPage 4.5 是既有 ④.2 的保障值。
|
|
122
|
+
* 三个数都不是新定的口径,是把现状口径写成了参数。
|
|
123
|
+
*/
|
|
124
|
+
const CONTRAST_TARGETS: Record<SomaContrast, SomaContrastTargets> = {
|
|
125
|
+
soft: { toneOnPage: 3.2, fgOnTone: 4.5, textOnPage: 4.5 },
|
|
126
|
+
standard: { toneOnPage: 4.0, fgOnTone: 4.5, textOnPage: 4.5 },
|
|
127
|
+
strong: { toneOnPage: 5.5, fgOnTone: 7.0, textOnPage: 7.0 },
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
/** 暗色目标:底更深,语气底对底的对比要求相应放宽一档(与现状 ⑤ 的观感一致) */
|
|
131
|
+
const DARK_CONTRAST_TARGETS: Record<SomaContrast, SomaContrastTargets> = {
|
|
132
|
+
soft: { toneOnPage: 3.0, fgOnTone: 4.5, textOnPage: 4.5 },
|
|
133
|
+
standard: { toneOnPage: 3.6, fgOnTone: 4.5, textOnPage: 4.5 },
|
|
134
|
+
strong: { toneOnPage: 5.0, fgOnTone: 7.0, textOnPage: 7.0 },
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
/** contrast:soft 的粉彩明度带(对标原型八色的 L 0.66–0.88) */
|
|
138
|
+
const SOFT_LIGHTNESS_BAND: readonly [number, number] = [0.70, 0.86];
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* 环境光三团 alpha。
|
|
142
|
+
*
|
|
143
|
+
* soft 一档 = G1 现状值(`hexWithAlpha(scale300, .42)` 等),
|
|
144
|
+
* 因此 `field:'aurora', intensity:'soft'` 的产出与 G1 逐字节一致——
|
|
145
|
+
* aurora 预设参数化后观感不动,这是 T4 的零破坏锚点。
|
|
146
|
+
*/
|
|
147
|
+
const FIELD_ALPHAS: Record<Exclude<SomaField, 'flat'>, readonly [number, number, number]> = {
|
|
148
|
+
tinted: [0.18, 0.12, 0.10],
|
|
149
|
+
aurora: [0.42, 0.28, 0.26],
|
|
150
|
+
};
|
|
151
|
+
const INTENSITY_MUL: Record<SomaIntensity, number> = {
|
|
152
|
+
whisper: 0.45,
|
|
153
|
+
soft: 1.0,
|
|
154
|
+
bold: 1.35,
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
const HEX_SHAPE = /^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/;
|
|
158
|
+
const MAX_ACCENTS = 3;
|
|
159
|
+
|
|
160
|
+
// ─── 解析 ────────────────────────────────────────────────────────────
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* 轴解析:词元 → 确定轴位 + 数值参数。
|
|
164
|
+
*
|
|
165
|
+
* 纯函数,不读全局、不碰 DOM。全部轴省略时返回的参数即现状行为。
|
|
166
|
+
*/
|
|
167
|
+
export function resolveAxes(input: {
|
|
168
|
+
palette?: SomaPaletteAxes;
|
|
169
|
+
scene?: SomaSceneAxes;
|
|
170
|
+
}): { axes: SomaResolvedAxes; params: SomaAxisParams } {
|
|
171
|
+
const p = input.palette ?? {};
|
|
172
|
+
const s = input.scene ?? {};
|
|
173
|
+
|
|
174
|
+
const accents = p.accents ?? [];
|
|
175
|
+
if (accents.length > MAX_ACCENTS) {
|
|
176
|
+
throw new SomaThemeAxisError(
|
|
177
|
+
`accents 最多 ${MAX_ACCENTS} 个(依次锁 secondary/accent/info 的色相锚),收到 ${accents.length} 个。`
|
|
178
|
+
+ '要精调更多颜色请走 overrides 逐令牌通道。',
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
for (const hex of accents) {
|
|
182
|
+
if (!HEX_SHAPE.test(hex)) {
|
|
183
|
+
throw new SomaThemeAxisError(`accents 里的 "${hex}" 不是合法颜色(#rgb 或 #rrggbb)`);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const axes: SomaResolvedAxes = {
|
|
188
|
+
palette: {
|
|
189
|
+
harmony: p.harmony ?? 'functional',
|
|
190
|
+
semantics: p.semantics ?? 'faithful',
|
|
191
|
+
chroma: p.chroma ?? 'balanced',
|
|
192
|
+
contrast: p.contrast ?? 'standard',
|
|
193
|
+
accents,
|
|
194
|
+
},
|
|
195
|
+
scene: {
|
|
196
|
+
// 缺省是 aurora/soft 而不是 flat:**今天的引擎产出的就是这一档的值**
|
|
197
|
+
// (G1 的 `hexWithAlpha(scale300, .42)` 等三行),缺省若给 flat 就等于
|
|
198
|
+
// 把存量页面的 .soma-ambient 类清零——那是破坏,不是收编。
|
|
199
|
+
// flat 因此是一个**显式的退出档**:主题明说"这一页不要场"。
|
|
200
|
+
field: s.field ?? 'aurora',
|
|
201
|
+
intensity: s.intensity ?? 'soft',
|
|
202
|
+
material: s.material ?? 'solid',
|
|
203
|
+
},
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
const { harmony, chroma, contrast, field, intensity, semantics } = {
|
|
207
|
+
...axes.palette, ...axes.scene,
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
const alphas = field === 'flat'
|
|
211
|
+
? null
|
|
212
|
+
: (FIELD_ALPHAS[field].map((a) => a * INTENSITY_MUL[intensity]) as [number, number, number]);
|
|
213
|
+
|
|
214
|
+
return {
|
|
215
|
+
axes,
|
|
216
|
+
params: {
|
|
217
|
+
harmonyK: HARMONY_K[harmony],
|
|
218
|
+
accentComplement: harmony === 'complementary',
|
|
219
|
+
chromaMul: CHROMA_MUL[chroma],
|
|
220
|
+
targets: CONTRAST_TARGETS[contrast],
|
|
221
|
+
darkTargets: DARK_CONTRAST_TARGETS[contrast],
|
|
222
|
+
softLightnessBand: contrast === 'soft' ? SOFT_LIGHTNESS_BAND : null,
|
|
223
|
+
fieldAlphas: alphas,
|
|
224
|
+
glassEnabled: axes.scene.material === 'glass',
|
|
225
|
+
signalEnabled: semantics === 'immersive',
|
|
226
|
+
},
|
|
227
|
+
};
|
|
228
|
+
}
|