soma-core 1.4.2 → 1.5.0
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/bin/component.cjs +240 -0
- package/bin/eject.cjs +174 -0
- package/bin/migrate.cjs +362 -0
- package/core/build/blocks/block-compile.ts +143 -17
- package/core/build/blocks/migrate-flat.ts +118 -25
- package/core/build/compiler/page-declaration-compiler.ts +149 -5
- package/core/build/compiler/route-builder.ts +0 -4
- package/core/build/compiler/soma-precompile.js +431 -26
- package/core/build/component/component-graph.ts +28 -105
- package/core/build/component/package-loader.ts +18 -4
- package/core/build/eject/component-eject.ts +8 -2
- package/core/build/layout/constraint-solver.ts +131 -16
- package/core/build/layout/css-emitter.ts +15 -9
- package/core/build/ooui/artifact/artifact.types.ts +275 -0
- package/core/build/ooui/artifact/emit-artifact.ts +269 -0
- package/core/build/ooui/artifact/emit-html.ts +204 -0
- package/core/build/ooui/artifact/index.ts +53 -0
- package/core/build/ooui/artifact/spatial-tree.ts +268 -0
- package/core/build/ooui/artifact/utility-class.ts +83 -0
- package/core/build/ooui/composition/candidate.types.ts +323 -0
- package/core/build/ooui/composition/control-model.ts +114 -0
- package/core/build/ooui/composition/registry.ts +520 -0
- package/core/build/ooui/composition/select.ts +232 -0
- package/core/build/ooui/diagnostics/codes.ts +230 -0
- package/core/build/ooui/diagnostics/error.ts +235 -0
- package/core/build/ooui/diagnostics/format.ts +106 -0
- package/core/build/ooui/diagnostics/index.ts +62 -0
- package/core/build/ooui/diagnostics/issue.types.ts +112 -0
- package/core/build/ooui/engine-slot.ts +184 -0
- package/core/build/ooui/index.ts +1427 -0
- package/core/build/ooui/intent/derive-intent.ts +450 -0
- package/core/build/ooui/intent/field-rules.ts +330 -0
- package/core/build/ooui/intent/intent.types.ts +476 -0
- package/core/build/ooui/intent/verb-events.ts +285 -0
- package/core/build/ooui/page/budget.ts +503 -0
- package/core/build/ooui/page/compose-page.ts +736 -0
- package/core/build/ooui/page/index.ts +66 -0
- package/core/build/ooui/page/page.types.ts +402 -0
- package/core/build/ooui/page/region-row.ts +241 -0
- package/core/build/ooui/semantic/expand-page-surface.ts +180 -0
- package/core/build/ooui/semantic/kernel.types.ts +187 -0
- package/core/build/ooui/semantic/normalize.ts +784 -0
- package/core/build/ooui/semantic/origin.types.ts +211 -0
- package/core/build/ooui/semantic/role-alias.ts +154 -0
- package/core/build/ooui/semantic/shorthand.ts +233 -0
- package/core/build/ooui/semantic/surface.types.ts +78 -0
- package/core/build/ooui/semantic/validate-request.ts +267 -0
- package/core/build/ooui/spatial/emit-utility.ts +480 -0
- package/core/build/ooui/spatial/ir.types.ts +443 -0
- package/core/build/ooui/spatial/registry.ts +565 -0
- package/core/build/ooui/spatial/solve.ts +769 -0
- package/core/build/ooui/spatial/utility.types.ts +242 -0
- package/core/build/ooui/trace/index.ts +40 -0
- package/core/build/ooui/trace/render.ts +190 -0
- package/core/build/ooui/trace/source.types.ts +69 -0
- package/core/build/ooui/trace/trace.types.ts +326 -0
- package/core/client/component/example-blocks.ts +1 -7
- package/core/client/component/theme-component-tokens.ts +12 -15
- package/core/client/data/data-object-resolver.ts +27 -8
- package/core/client/diagnostics/telemetry-context.ts +0 -4
- package/core/client/engine/asset-resolver.ts +0 -1
- package/core/client/engine/event-engine.ts +7 -3
- package/core/client/engine/soma-bootstrap.ts +292 -34
- package/core/client/engine/style-binder.ts +0 -1
- package/core/client/infra/http/IHttpClient.ts +0 -6
- package/core/client/infra/http/SomaHttpService.ts +4 -1
- package/core/client/infra/notify/DomNotifyService.ts +1 -1
- package/core/client/infra/router/router-path.ts +0 -6
- package/core/client/parser/annotation-extractor.ts +1 -1
- package/core/client/parser/blocks/namespace.ts +30 -5
- package/core/client/parser/blocks/page-parser.ts +44 -1
- package/core/client/parser/blocks/use-parser.ts +266 -46
- package/core/client/parser/data-config-parser.ts +71 -3
- package/core/client/parser/layout-parser.ts +4 -3
- package/core/client/parser/reaction-parser.ts +0 -1
- package/core/client/parser/ui-config-parser.ts +212 -74
- package/core/client/theme/scene-tokens.ts +9 -3
- package/core/client/theme/theme-axes.ts +74 -16
- package/core/client/theme/theme-engine.ts +280 -69
- package/core/client/theme/tone-solver.ts +9 -8
- package/core/index.ts +18 -4
- package/core/server/api/load-host-service.ts +8 -2
- package/core/server/declaration-safety.ts +11 -0
- package/core/server/host/page-response-request.ts +0 -2
- package/core/server/host/published-page-artifact-cache.ts +244 -0
- package/core/server/host/published-page-assets.ts +44 -5
- package/core/server/mock/node/cli.mjs +0 -1
- package/core/server/mock/node/schema-generator.mjs +0 -1
- package/core/server/ooui.ts +34 -0
- package/core/server/page-assets.ts +8 -0
- package/core/server/page-declaration.ts +18 -0
- package/core/server/registry/asset-store.ts +327 -0
- package/core/server/registry/declaration-precompiler.ts +49 -6
- package/core/server/registry/index.ts +47 -1
- package/core/server/registry/page-registry-repository.ts +6 -2
- package/core/server/registry/page-registry-store.ts +133 -19
- package/core/server/registry/publish-asset-pin.ts +557 -0
- package/core/server/registry/services/pages/List.ts +15 -3
- package/core/server/registry/validation/compile-gate.ts +180 -8
- package/core/server/registry/validation/declaration-safety-scan.ts +113 -23
- package/core/shared/component/derive-sample.ts +201 -16
- package/core/shared/component/field-lines.ts +98 -8
- package/core/shared/container-breakpoints.ts +46 -0
- package/core/shared/object-semantics.ts +240 -0
- package/core/shared/ooui-declaration.ts +235 -0
- package/core/shared/types/component-contract.types.ts +7 -6
- package/core/shared/types/data-config.types.ts +95 -0
- package/core/shared/types/domain.types.ts +0 -24
- package/core/shared/types/engine.types.ts +0 -5
- package/core/shared/types/layout-constraint.types.ts +16 -0
- package/core/shared/types/ui-config.types.ts +163 -13
- package/dist/cli/soma.js +24 -11
- package/dist/core/index.cjs +1563 -800
- package/dist/types/build/blocks/block-compile.d.ts +16 -1
- package/dist/types/build/blocks/migrate-flat.d.ts +17 -0
- package/dist/types/build/compiler/page-declaration-compiler.d.ts +46 -0
- package/dist/types/build/compiler/route-builder.d.ts +0 -1
- package/dist/types/build/component/component-graph.d.ts +17 -53
- package/dist/types/build/component/package-loader.d.ts +8 -1
- package/dist/types/build/layout/constraint-solver.d.ts +46 -4
- package/dist/types/build/ooui/artifact/artifact.types.d.ts +180 -0
- package/dist/types/build/ooui/artifact/emit-artifact.d.ts +58 -0
- package/dist/types/build/ooui/artifact/emit-html.d.ts +53 -0
- package/dist/types/build/ooui/artifact/index.d.ts +5 -0
- package/dist/types/build/ooui/artifact/spatial-tree.d.ts +48 -0
- package/dist/types/build/ooui/artifact/utility-class.d.ts +46 -0
- package/dist/types/build/ooui/composition/candidate.types.d.ts +206 -0
- package/dist/types/build/ooui/composition/control-model.d.ts +37 -0
- package/dist/types/build/ooui/composition/registry.d.ts +66 -0
- package/dist/types/build/ooui/composition/select.d.ts +63 -0
- package/dist/types/build/ooui/diagnostics/codes.d.ts +28 -0
- package/dist/types/build/ooui/diagnostics/error.d.ts +135 -0
- package/dist/types/build/ooui/diagnostics/format.d.ts +51 -0
- package/dist/types/build/ooui/diagnostics/index.d.ts +25 -0
- package/dist/types/build/ooui/diagnostics/issue.types.d.ts +56 -0
- package/dist/types/build/ooui/engine-slot.d.ts +41 -0
- package/dist/types/build/ooui/index.d.ts +286 -0
- package/dist/types/build/ooui/intent/derive-intent.d.ts +32 -0
- package/dist/types/build/ooui/intent/field-rules.d.ts +99 -0
- package/dist/types/build/ooui/intent/intent.types.d.ts +318 -0
- package/dist/types/build/ooui/intent/verb-events.d.ts +70 -0
- package/dist/types/build/ooui/page/budget.d.ts +28 -0
- package/dist/types/build/ooui/page/compose-page.d.ts +41 -0
- package/dist/types/build/ooui/page/index.d.ts +4 -0
- package/dist/types/build/ooui/page/page.types.d.ts +264 -0
- package/dist/types/build/ooui/page/region-row.d.ts +16 -0
- package/dist/types/build/ooui/semantic/expand-page-surface.d.ts +33 -0
- package/dist/types/build/ooui/semantic/kernel.types.d.ts +125 -0
- package/dist/types/build/ooui/semantic/normalize.d.ts +45 -0
- package/dist/types/build/ooui/semantic/origin.types.d.ts +95 -0
- package/dist/types/build/ooui/semantic/role-alias.d.ts +35 -0
- package/dist/types/build/ooui/semantic/shorthand.d.ts +60 -0
- package/dist/types/build/ooui/semantic/surface.types.d.ts +16 -0
- package/dist/types/build/ooui/semantic/validate-request.d.ts +19 -0
- package/dist/types/build/ooui/spatial/emit-utility.d.ts +43 -0
- package/dist/types/build/ooui/spatial/ir.types.d.ts +280 -0
- package/dist/types/build/ooui/spatial/registry.d.ts +110 -0
- package/dist/types/build/ooui/spatial/solve.d.ts +42 -0
- package/dist/types/build/ooui/spatial/utility.types.d.ts +191 -0
- package/dist/types/build/ooui/trace/index.d.ts +3 -0
- package/dist/types/build/ooui/trace/render.d.ts +42 -0
- package/dist/types/build/ooui/trace/source.types.d.ts +25 -0
- package/dist/types/build/ooui/trace/trace.types.d.ts +143 -0
- package/dist/types/client/component/example-blocks.d.ts +0 -2
- package/dist/types/client/component/theme-component-tokens.d.ts +8 -5
- package/dist/types/client/data/data-object-resolver.d.ts +10 -2
- package/dist/types/client/diagnostics/telemetry-context.d.ts +0 -1
- package/dist/types/client/engine/soma-bootstrap.d.ts +123 -10
- package/dist/types/client/infra/http/IHttpClient.d.ts +0 -5
- package/dist/types/client/infra/http/SomaHttpService.d.ts +1 -1
- package/dist/types/client/infra/router/router-path.d.ts +0 -2
- package/dist/types/client/parser/blocks/namespace.d.ts +20 -0
- package/dist/types/client/parser/blocks/page-parser.d.ts +9 -0
- package/dist/types/client/parser/blocks/use-parser.d.ts +38 -4
- package/dist/types/client/parser/data-config-parser.d.ts +13 -0
- package/dist/types/client/parser/ui-config-parser.d.ts +1 -11
- package/dist/types/client/theme/scene-tokens.d.ts +9 -3
- package/dist/types/client/theme/theme-axes.d.ts +64 -1
- package/dist/types/client/theme/theme-engine.d.ts +13 -8
- package/dist/types/client/theme/tone-solver.d.ts +9 -5
- package/dist/types/index.d.ts +4 -5
- package/dist/types/server/declaration-safety.d.ts +7 -0
- package/dist/types/server/host/page-response-request.d.ts +0 -1
- package/dist/types/server/host/published-page-artifact-cache.d.ts +64 -0
- package/dist/types/server/ooui.d.ts +18 -0
- package/dist/types/server/page-assets.d.ts +7 -0
- package/dist/types/server/page-declaration.d.ts +14 -0
- package/dist/types/server/registry/asset-store.d.ts +112 -0
- package/dist/types/server/registry/declaration-precompiler.d.ts +23 -3
- package/dist/types/server/registry/index.d.ts +3 -1
- package/dist/types/server/registry/page-registry-store.d.ts +57 -4
- package/dist/types/server/registry/publish-asset-pin.d.ts +166 -0
- package/dist/types/server/registry/services/pages/List.d.ts +9 -3
- package/dist/types/server/registry/validation/compile-gate.d.ts +63 -0
- package/dist/types/shared/component/derive-sample.d.ts +14 -0
- package/dist/types/shared/container-breakpoints.d.ts +42 -0
- package/dist/types/shared/object-semantics.d.ts +42 -0
- package/dist/types/shared/ooui-declaration.d.ts +135 -0
- package/dist/types/shared/types/component-contract.types.d.ts +7 -6
- package/dist/types/shared/types/data-config.types.d.ts +86 -0
- package/dist/types/shared/types/domain.types.d.ts +0 -21
- package/dist/types/shared/types/engine.types.d.ts +0 -4
- package/dist/types/shared/types/layout-constraint.types.d.ts +1 -0
- package/dist/types/shared/types/ui-config.types.d.ts +157 -12
- package/next.config.js +106 -13
- package/package.json +28 -2
- package/core/client/host-bridge/index.ts +0 -27
- package/core/client/parser/yaml-loader.ts +0 -36
- package/core/shared/manifest/manifest-contract.ts +0 -12
- package/dist/types/client/host-bridge/index.d.ts +0 -9
- package/dist/types/client/parser/yaml-loader.d.ts +0 -21
- package/dist/types/shared/manifest/manifest-contract.d.ts +0 -4
|
@@ -20,21 +20,21 @@
|
|
|
20
20
|
|
|
21
21
|
import {
|
|
22
22
|
resolveAxes,
|
|
23
|
+
type SomaContrastTargets,
|
|
23
24
|
type SomaPaletteAxes,
|
|
24
25
|
type SomaResolvedAxes,
|
|
25
26
|
type SomaSceneAxes,
|
|
26
27
|
} from './theme-axes';
|
|
27
28
|
import {
|
|
28
|
-
EXPRESSIVE_OFFSETS,
|
|
29
29
|
FUNCTIONAL_HUES,
|
|
30
30
|
applySeparationGuard,
|
|
31
31
|
resolveHueAnchors,
|
|
32
32
|
type SomaHueAnchors,
|
|
33
33
|
type SomaToneName,
|
|
34
34
|
} from './harmony';
|
|
35
|
-
import { ensureContrast } from './tone-solver';
|
|
35
|
+
import { ensureContrast, solveTone } from './tone-solver';
|
|
36
36
|
import { componentTokenVar } from '../../shared/types/component-contract.types';
|
|
37
|
-
import { sceneColorTokens, sceneStructureTokens } from './scene-tokens';
|
|
37
|
+
import { glassTokens, sceneColorTokens, sceneStructureTokens } from './scene-tokens';
|
|
38
38
|
|
|
39
39
|
export type { SomaPaletteAxes, SomaSceneAxes, SomaResolvedAxes } from './theme-axes';
|
|
40
40
|
export type { SomaToneName } from './harmony';
|
|
@@ -78,7 +78,7 @@ export interface SomaThemeInput {
|
|
|
78
78
|
* (页面永不可寻址组件内部,`scopeAnchors()` 的既定边界)。
|
|
79
79
|
*
|
|
80
80
|
* 引擎不认识组件,所以这里只做展平;「组件名 / 令牌名是否存在」由装配层的
|
|
81
|
-
* `validateThemeComponentTokens` 在 bootstrap
|
|
81
|
+
* `validateThemeComponentTokens` 在 bootstrap 期核对契约(对不上只告警,不阻断换装)。
|
|
82
82
|
*/
|
|
83
83
|
components?: Record<string, Record<string, string>>;
|
|
84
84
|
/** 组件令牌的暗色专属覆盖:与 `darkOverrides` 同一纪律,只并进 darkCssVars */
|
|
@@ -92,6 +92,18 @@ export interface SomaThemeMeta {
|
|
|
92
92
|
readonly separationApplied: boolean;
|
|
93
93
|
/** 被推开的语气 */
|
|
94
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[];
|
|
95
107
|
/** 本次写出的组件级令牌变量名(M-1)——快照与闸门的观测面 */
|
|
96
108
|
readonly componentTokens: readonly string[];
|
|
97
109
|
}
|
|
@@ -517,7 +529,7 @@ function chartSeries(
|
|
|
517
529
|
// 12~24px 的字阶)全部是 16 的整数分之一倍,换算**无一需要取整**,
|
|
518
530
|
// 因此 16px 根字号下输出值与迁移前逐令牌恒等,视觉基线零 diff。
|
|
519
531
|
const STATIC_TOKENS: Record<string, string> = {
|
|
520
|
-
// 字体排印:系统栈 + 八档字号 + AntD 标准行高 +
|
|
532
|
+
// 字体排印:系统栈 + 八档字号 + AntD 标准行高 + 四档字重
|
|
521
533
|
'--soma-font-family':
|
|
522
534
|
"-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif",
|
|
523
535
|
'--soma-font-size-xs': '0.75rem', // 12px
|
|
@@ -544,6 +556,13 @@ const STATIC_TOKENS: Record<string, string> = {
|
|
|
544
556
|
'--soma-font-weight-normal': '400',
|
|
545
557
|
'--soma-font-weight-medium': '500',
|
|
546
558
|
'--soma-font-weight-bold': '600',
|
|
559
|
+
// 展示档(2026-09-12 补):把字形当**图形**用的位置——头像/角标的首字母牌、
|
|
560
|
+
// 序号与勾选标记、KPI 大数字、倒计时格、hero 标题、金额主数字。
|
|
561
|
+
// 它不是文本层次的第四级(层次到 bold 就封顶,见排版册"层次三维"),
|
|
562
|
+
// 所以不参与"页题→脚注"六级;单列一档是因为这些位置此前各写各的裸值
|
|
563
|
+
// (650/700/750/800 混用,同一个 `__eyebrow` 在三个卡片工厂里是三个数),
|
|
564
|
+
// 没有令牌可引就只能硬编码,换肤对它们永远无效。
|
|
565
|
+
'--soma-font-weight-heavy': '800',
|
|
547
566
|
// 间距:4px 基准;0 贴合,9=48px,10=56px(文档 space.0~16,未一次铺满)
|
|
548
567
|
'--soma-space-0': '0rem',
|
|
549
568
|
'--soma-space-1': '0.25rem', // 4px
|
|
@@ -609,6 +628,30 @@ const CHROMA_CURVE = [0.14, 0.28, 0.48, 0.68, 0.85, 1.0, 1.0, 0.92, 0.8, 0.66, 0
|
|
|
609
628
|
*/
|
|
610
629
|
const SOLVER_DEPS = { oklchToHex, hexToOklch, contrastRatio, bestFg };
|
|
611
630
|
|
|
631
|
+
/**
|
|
632
|
+
* 求解方向:「远离页面底」。亮色恒 darken、暗色恒 lighten。
|
|
633
|
+
*
|
|
634
|
+
* 这不是启发,是把 toneOnPage 与 fgOnTone 从互相打架变成同向的那一步:
|
|
635
|
+
* 语气底对页面底的对比度在亮色下随明度**单调递减**、暗色下**单调递增**,
|
|
636
|
+
* 所以"远离页面底"这个方向上 toneOnPage 只会变好——`ensureContrast` 为了
|
|
637
|
+
* fgOnTone 多推的那几步顺带把 toneOnPage 推得更宽裕,而不是推回去。
|
|
638
|
+
*
|
|
639
|
+
* 反例正是 tone-solver 的 forceDirection 参数存在的理由(那里的注释讲的是
|
|
640
|
+
* 分离闸版本的同一类事故):缺省启发「l > 0.55 就提亮」会把一个刚解到
|
|
641
|
+
* l=0.56 的语气朝页面底推回去,toneOnPage 当场掉档。
|
|
642
|
+
*
|
|
643
|
+
* 取值与 solveTone 内部的方向判据同源(种子明度与页面明度谁大谁小):
|
|
644
|
+
* 全部语气种子的明度都落在 (darkBgPage.l, bgPage.l) 之间,方向因此与语气无关。
|
|
645
|
+
*
|
|
646
|
+
* **只在 toneOnPage 真的推动过该语气时才启用**(见 dirAfter):没推过就没有
|
|
647
|
+
* 要保护的约束,方向留给既有启发——缺省档因此与接线前逐字节一致。
|
|
648
|
+
*
|
|
649
|
+
* 只给亮色一个常量:暗色侧的三处 AA 循环用的启发是「l > 0.55 就提亮」,
|
|
650
|
+
* 而暗色语气的明度全部 > 0.55,它本来就等于"远离暗色页面底",两者不冲突,
|
|
651
|
+
* 不需要覆盖(⑤/⑤.1 那几段因此一行不动)。
|
|
652
|
+
*/
|
|
653
|
+
const AWAY_FROM_LIGHT_PAGE = 'darken' as const;
|
|
654
|
+
|
|
612
655
|
export function deriveTheme(input: SomaThemeInput): SomaDerivedTheme {
|
|
613
656
|
const brand = hexToOklch(input.brand);
|
|
614
657
|
// S0 轴解析:词元 → 数值参数。全部轴省略时 params 即现状行为
|
|
@@ -629,6 +672,13 @@ export function deriveTheme(input: SomaThemeInput): SomaDerivedTheme {
|
|
|
629
672
|
const grayChroma = input.mode === 'neutral' || !input.mode ? 0.008 : 0.014;
|
|
630
673
|
const gray = (l: number) => oklchToHex({ l, c: grayChroma, h: grayHue });
|
|
631
674
|
|
|
675
|
+
// ②.1 页面底先于语气求解算出来:S2 的 toneOnPage 解的是「语气实心底 vs 页面底」,
|
|
676
|
+
// 没有页面底就无从解起(REQ-007 架构设计 L1.5 手术表:S1/S2 插在 ② 之后)。
|
|
677
|
+
// 0.98 与纯白卡片的亮度差只有 2%,卡片浮不起来(2026-08-17 截图实测);
|
|
678
|
+
// 0.965 仍是"几乎白"的观感,但卡片边界一眼可辨。
|
|
679
|
+
const bgPage = gray(0.965);
|
|
680
|
+
const darkBgPage = gray(0.18);
|
|
681
|
+
|
|
632
682
|
// ③ 交互态:hover/active 依次压暗一档半亮度
|
|
633
683
|
const primaryIdx = Math.max(4, Math.min(7, brandSlot));
|
|
634
684
|
const primary = scale[STEPS[primaryIdx]];
|
|
@@ -648,17 +698,75 @@ export function deriveTheme(input: SomaThemeInput): SomaDerivedTheme {
|
|
|
648
698
|
|
|
649
699
|
const toneChroma = (mul: number): number => Math.max(brand.c, 0.12) * mul * params.chromaMul;
|
|
650
700
|
/**
|
|
651
|
-
* contrast 轴的明度带:把语气种子夹进粉彩带(soft
|
|
701
|
+
* contrast 轴的明度带:把语气种子夹进粉彩带(soft 档,亮色侧)。
|
|
652
702
|
*
|
|
653
|
-
* 缺省档 band 为 null
|
|
703
|
+
* 缺省档 band 为 null,种子原值穿过——缺省产出因此逐字节不变。
|
|
654
704
|
* 带只夹**种子**,后续 AA 保障仍可把它推出带外(对比度赢,
|
|
655
|
-
*
|
|
705
|
+
* 是《soma 设计令牌与主题》§10.3 原则 4 的承诺:AA 底线不随 contrast 档移动)。
|
|
706
|
+
*
|
|
707
|
+
* 带与同一档的 toneOnPage 目标是**同一条轴的两条腿**,取值必须相容:
|
|
708
|
+
* soft 的目标 1.2 取在带上界 L=0.86 处的最差实测值 1.271 之下,
|
|
709
|
+
* 所以带全区间达标、不会被目标顶穿(meta.bandBroken 因此应恒为空)。
|
|
656
710
|
*/
|
|
657
711
|
const banded = (l: number): number => {
|
|
658
712
|
const band = params.softLightnessBand;
|
|
659
713
|
return band ? Math.min(band[1], Math.max(band[0], l)) : l;
|
|
660
714
|
};
|
|
661
715
|
|
|
716
|
+
/** 带被 toneOnPage 目标顶穿的语气——收进 meta 供观测,不报错 */
|
|
717
|
+
const bandBroken = new Set<SomaToneName>();
|
|
718
|
+
interface SolvedSeed {
|
|
719
|
+
readonly tone: Oklch;
|
|
720
|
+
readonly hex: string;
|
|
721
|
+
/** toneOnPage 目标是否真的推动了这个种子 */
|
|
722
|
+
readonly pushed: boolean;
|
|
723
|
+
}
|
|
724
|
+
/**
|
|
725
|
+
* S2 toneOnPage 求解:把语气实心底推离页面底,直到命中档位目标。
|
|
726
|
+
*
|
|
727
|
+
* **位置即优先级**——排在 banded/separatedL 之后、④ 系 AA 求解之前。
|
|
728
|
+
* AA 底线(fgOnTone / textOnPage)与语义可分离是引擎的两条硬保障
|
|
729
|
+
* (《soma 设计令牌与主题》§10.3 原则 4「硬保障不是输入」),它们的三个夹子
|
|
730
|
+
* `ensureContrast` / `clampSeparated*` / `enforceContrastPairs` 全排在本步之后,
|
|
731
|
+
* 因此永远说了算;toneOnPage 是 contrast 档的气质目标,尽力而为、够不到不报错。
|
|
732
|
+
* 粉彩带最先让位:被顶穿时记进 meta.bandBroken,不抛错。
|
|
733
|
+
*
|
|
734
|
+
* **作用面 = banded() 的作用面**(secondary / accent / info / success / warning /
|
|
735
|
+
* danger,亮暗各一次共 12 处)。带与目标是同一个轴的两条腿,作用面必须一致。
|
|
736
|
+
* primary 不在其内——它恒随品牌(REQ-007 架构设计 §3 作用域表「primary | brand
|
|
737
|
+
* (永远)」),解它等于改宿主给的身份色;neutral 也不在——它的明度归 mode 管
|
|
738
|
+
* (近黑芯片 l=0.18 / 暗档 0.42),既不吃粉彩带也不吃语气彩度曲线。
|
|
739
|
+
*
|
|
740
|
+
* `record` 传 null = 不记 bandBroken:判撞用的首遍求解是一次性草稿,
|
|
741
|
+
* 它的带突破不该出现在观测面上(产出以第二遍为准)。
|
|
742
|
+
*/
|
|
743
|
+
const solveOnPage = (
|
|
744
|
+
record: SomaToneName | null,
|
|
745
|
+
seed: Oklch,
|
|
746
|
+
pageHex: string,
|
|
747
|
+
target: SomaContrastTargets,
|
|
748
|
+
band: readonly [number, number] | null,
|
|
749
|
+
): SolvedSeed => {
|
|
750
|
+
const solved = solveTone(seed, pageHex, target, band, SOLVER_DEPS);
|
|
751
|
+
if (record && solved.bandBroken) bandBroken.add(record);
|
|
752
|
+
return {
|
|
753
|
+
tone: solved.tone,
|
|
754
|
+
hex: oklchToHex(solved.tone),
|
|
755
|
+
pushed: Math.abs(solved.tone.l - seed.l) > 1e-9,
|
|
756
|
+
};
|
|
757
|
+
};
|
|
758
|
+
/**
|
|
759
|
+
* 方向权的闸:只有目标真的绑定过这个语气,下游 AA 求解的方向才交给
|
|
760
|
+
* 「远离页面底」那一侧——接管方向的理由是保护刚建立的约束不被缺省启发推翻,
|
|
761
|
+
* 没推过就没有要保护的东西。
|
|
762
|
+
*
|
|
763
|
+
* `banded()` 已在上游夹过带、分离在场时又不传带(见 bandFor),所以
|
|
764
|
+
* solveTone 内部的带夹恒是空操作,`pushed` 恰好等价于"目标绑定了",无假阳性。
|
|
765
|
+
*/
|
|
766
|
+
const dirAfter = (
|
|
767
|
+
solved: SolvedSeed, away: 'lighten' | 'darken',
|
|
768
|
+
): 'lighten' | 'darken' | undefined => (solved.pushed ? away : undefined);
|
|
769
|
+
|
|
662
770
|
/**
|
|
663
771
|
* S2 色调求解:由色相锚解出三个语义色的最终值。
|
|
664
772
|
*
|
|
@@ -669,11 +777,25 @@ export function deriveTheme(input: SomaThemeInput): SomaDerivedTheme {
|
|
|
669
777
|
* 回跑对未推动的语气零影响。
|
|
670
778
|
*/
|
|
671
779
|
const solveSemantics = (hues: { success: number; warning: number; danger: number }) => {
|
|
672
|
-
|
|
780
|
+
// 首遍必须与第二遍**同款流水线**(S2 求解 → AA),否则判撞拿到的又是
|
|
781
|
+
// "不是最终值"的明度——与下面 S3 那段讲的是同一条纪律的另一半
|
|
782
|
+
const band = params.softLightnessBand;
|
|
783
|
+
const seed = (l: number, mul: number, h: number): SolvedSeed => solveOnPage(
|
|
784
|
+
null, { l: banded(l), c: toneChroma(mul), h }, bgPage, params.targets, band,
|
|
785
|
+
);
|
|
786
|
+
const danger = seed(0.60, 0.95, hues.danger);
|
|
787
|
+
const success = seed(0.58, 0.85, hues.success);
|
|
788
|
+
const warning = seed(0.72, 0.9, hues.warning);
|
|
673
789
|
return {
|
|
674
|
-
danger: { bg:
|
|
675
|
-
success: ensureContrast(
|
|
676
|
-
|
|
790
|
+
danger: { bg: danger.hex, fg: '#ffffff', l: danger.tone.l },
|
|
791
|
+
success: ensureContrast(
|
|
792
|
+
success.hex, SOLVER_DEPS, params.targets.fgOnTone, undefined,
|
|
793
|
+
dirAfter(success, AWAY_FROM_LIGHT_PAGE),
|
|
794
|
+
),
|
|
795
|
+
warning: ensureContrast(
|
|
796
|
+
warning.hex, SOLVER_DEPS, params.targets.fgOnTone, undefined,
|
|
797
|
+
dirAfter(warning, AWAY_FROM_LIGHT_PAGE),
|
|
798
|
+
),
|
|
677
799
|
};
|
|
678
800
|
};
|
|
679
801
|
|
|
@@ -736,44 +858,124 @@ export function deriveTheme(input: SomaThemeInput): SomaDerivedTheme {
|
|
|
736
858
|
return Math.abs(clamped - current.l) < 1e-6 ? hex : oklchToHex({ ...current, l: clamped });
|
|
737
859
|
};
|
|
738
860
|
|
|
739
|
-
/**
|
|
740
|
-
|
|
861
|
+
/**
|
|
862
|
+
* 分离方向 → 求解方向:有分离意图时,求解器不许把它拉回品牌明度;
|
|
863
|
+
* 没有分离意图时,只有 toneOnPage 真推动过才钉"远离页面底"(见 dirAfter)。
|
|
864
|
+
*/
|
|
865
|
+
const solveDir = (
|
|
866
|
+
tone: 'success' | 'warning' | 'danger', solved: SolvedSeed,
|
|
867
|
+
): 'lighten' | 'darken' | undefined => {
|
|
741
868
|
const need = guard.lightnessSeparation[tone];
|
|
742
|
-
|
|
869
|
+
if (need) return need.direction > 0 ? 'lighten' : 'darken';
|
|
870
|
+
return dirAfter(solved, AWAY_FROM_LIGHT_PAGE);
|
|
743
871
|
};
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
872
|
+
/**
|
|
873
|
+
* 分离意图在场时粉彩带退场:带会把已经推离品牌明度的种子夹回来,
|
|
874
|
+
* 下游 clampSeparated 再把它推出去——一次无谓往返,还会在 meta 上留下
|
|
875
|
+
* 一条不是"目标对比度顶穿"的假 bandBroken。硬保障在场,气质让位。
|
|
876
|
+
*/
|
|
877
|
+
const bandFor = (
|
|
878
|
+
tone: 'success' | 'warning' | 'danger',
|
|
879
|
+
): readonly [number, number] | null => (
|
|
880
|
+
guard.lightnessSeparation[tone] ? null : params.softLightnessBand
|
|
881
|
+
);
|
|
882
|
+
|
|
883
|
+
const dangerSolved = solveOnPage(
|
|
884
|
+
'danger',
|
|
885
|
+
{ l: separatedL('danger', banded(0.60)), c: toneChroma(0.95), h: anchors.tones.danger },
|
|
886
|
+
bgPage, params.targets, bandFor('danger'),
|
|
887
|
+
);
|
|
888
|
+
const danger = clampSeparatedHex('danger', dangerSolved.hex);
|
|
889
|
+
const successSolved = solveOnPage(
|
|
890
|
+
'success',
|
|
891
|
+
{ l: separatedL('success', banded(0.58)), c: toneChroma(0.85), h: anchors.tones.success },
|
|
892
|
+
bgPage, params.targets, bandFor('success'),
|
|
893
|
+
);
|
|
894
|
+
const success = successSolved.hex;
|
|
895
|
+
const warningSolved = solveOnPage(
|
|
896
|
+
'warning',
|
|
897
|
+
{ l: separatedL('warning', banded(0.72)), c: toneChroma(0.9), h: anchors.tones.warning },
|
|
898
|
+
bgPage, params.targets, bandFor('warning'),
|
|
899
|
+
);
|
|
900
|
+
const warning = warningSolved.hex;
|
|
748
901
|
void firstPass; // 首遍求解只为判撞供明度,产出以第二遍为准
|
|
902
|
+
const infoOnPage = solveOnPage(
|
|
903
|
+
'info', { l: banded(0.60), c: toneChroma(0.9), h: anchors.tones.info },
|
|
904
|
+
bgPage, params.targets, params.softLightnessBand,
|
|
905
|
+
);
|
|
906
|
+
// minRatio 必须读 params.targets.fgOnTone:此前这里吃 ensureContrast 的缺省 4.5,
|
|
907
|
+
// 于是 contrast:'strong' 声明的 7.0 对 info 根本没生效(同一条轴"只生效一半"的第二处)
|
|
749
908
|
const infoSolved = ensureContrast(
|
|
750
|
-
|
|
909
|
+
infoOnPage.hex, SOLVER_DEPS, params.targets.fgOnTone, undefined,
|
|
910
|
+
dirAfter(infoOnPage, AWAY_FROM_LIGHT_PAGE),
|
|
751
911
|
);
|
|
752
912
|
const info = infoSolved.bg;
|
|
753
913
|
const infoFg = infoSolved.fg;
|
|
754
914
|
|
|
755
915
|
// ④.1b 第二/第三品牌色(对标 daisy secondary/accent):色相偏移 + 同主色 WCAG 循环。
|
|
756
916
|
// 组件可消费;daisy 预设可用 overrides 精调到源色板。
|
|
757
|
-
|
|
758
|
-
|
|
917
|
+
// minRatio 同样必须读 params.targets.fgOnTone:此前吃缺省 4.5,
|
|
918
|
+
// contrast:'strong' 的 7.0 对 secondary/accent/neutral 同样没生效
|
|
919
|
+
const ensureBrandTone = (
|
|
920
|
+
seedHex: string, forceDirection?: 'lighten' | 'darken',
|
|
921
|
+
): { bg: string; fg: string; soft: string } => {
|
|
922
|
+
const solved = ensureContrast(
|
|
923
|
+
seedHex, SOLVER_DEPS, params.targets.fgOnTone, undefined, forceDirection,
|
|
924
|
+
);
|
|
759
925
|
return { bg: solved.bg, fg: solved.fg, soft: hexWithAlpha(solved.bg, 0.12) };
|
|
760
926
|
};
|
|
761
|
-
|
|
762
|
-
|
|
927
|
+
/**
|
|
928
|
+
* 种子先提出来,因为它要被用**两次**:一次走亮色链路(粉彩带 → toneOnPage → AA),
|
|
929
|
+
* 一次作为暗色派生的基准(只走 AA)。
|
|
930
|
+
*
|
|
931
|
+
* 为什么暗色不能吃亮色那一份——contrast 轴的亮色侧加工(粉彩带把语气**抬亮**、
|
|
932
|
+
* toneOnPage 把语气**压暗**)在暗色底上作用方向全部反过来:`darkSecondary` 是
|
|
933
|
+
* "亮色成品 + 0.08",于是 strong 把亮色压暗 → 暗色种子跟着暗 → 在深底上反差
|
|
934
|
+
* **更低**(实测 #4f8cff:standard 8.76 → strong 5.56,档位越强反而越弱);
|
|
935
|
+
* soft 把亮色抬亮则反过来让暗色更强。两头都是把亮色的档位语义倒着装进暗色。
|
|
936
|
+
*
|
|
937
|
+
* 所以暗色从**未经 contrast 轴亮色侧加工的种子**重新出发,再按暗色目标独立求解
|
|
938
|
+
* (见 ⑤.1b)。缺省档下带为 null、toneOnPage 也不推动任何语气,两条路是同一次
|
|
939
|
+
* 求解的同一个结果——`darkSecondary/darkAccent` 因此逐字节不变。
|
|
940
|
+
*/
|
|
941
|
+
const secondarySeed: Oklch = {
|
|
942
|
+
l: Math.min(0.72, Math.max(0.45, brand.l + 0.04)),
|
|
763
943
|
c: Math.max(brand.c, 0.1) * 0.9 * params.chromaMul,
|
|
764
944
|
h: anchors.tones.secondary,
|
|
765
|
-
}
|
|
766
|
-
const
|
|
767
|
-
l:
|
|
945
|
+
};
|
|
946
|
+
const accentSeed: Oklch = {
|
|
947
|
+
l: Math.min(0.78, Math.max(0.48, brand.l + 0.08)),
|
|
768
948
|
c: Math.max(brand.c, 0.1) * 0.85 * params.chromaMul,
|
|
769
949
|
h: anchors.tones.accent,
|
|
770
|
-
}
|
|
771
|
-
|
|
772
|
-
|
|
950
|
+
};
|
|
951
|
+
const secondaryOnPage = solveOnPage(
|
|
952
|
+
'secondary', { ...secondarySeed, l: banded(secondarySeed.l) },
|
|
953
|
+
bgPage, params.targets, params.softLightnessBand,
|
|
954
|
+
);
|
|
955
|
+
const secondaryTone = ensureBrandTone(
|
|
956
|
+
secondaryOnPage.hex, dirAfter(secondaryOnPage, AWAY_FROM_LIGHT_PAGE),
|
|
957
|
+
);
|
|
958
|
+
const accentOnPage = solveOnPage(
|
|
959
|
+
'accent', { ...accentSeed, l: banded(accentSeed.l) },
|
|
960
|
+
bgPage, params.targets, params.softLightnessBand,
|
|
961
|
+
);
|
|
962
|
+
const accentTone = ensureBrandTone(
|
|
963
|
+
accentOnPage.hex, dirAfter(accentOnPage, AWAY_FROM_LIGHT_PAGE),
|
|
964
|
+
);
|
|
965
|
+
/** 暗色派生的基准:同一颗种子、同一套亮色 AA,但不吃粉彩带、也不吃 toneOnPage 的推动 */
|
|
966
|
+
const secondaryDarkBase = ensureContrast(
|
|
967
|
+
oklchToHex(secondarySeed), SOLVER_DEPS, params.targets.fgOnTone,
|
|
968
|
+
).bg;
|
|
969
|
+
const accentDarkBase = ensureContrast(
|
|
970
|
+
oklchToHex(accentSeed), SOLVER_DEPS, params.targets.fgOnTone,
|
|
971
|
+
).bg;
|
|
972
|
+
// 中性色(对标 daisy color-neutral):近黑按钮/标签底,色温跟随 grayHue。
|
|
973
|
+
// 不过 toneOnPage 求解:它的明度归 mode 管,不在 contrast 轴的作用面内
|
|
974
|
+
const neutralTone = ensureBrandTone(oklchToHex({
|
|
773
975
|
l: 0.18,
|
|
774
976
|
c: grayChroma * 1.4,
|
|
775
977
|
h: grayHue,
|
|
776
|
-
});
|
|
978
|
+
}));
|
|
777
979
|
/**
|
|
778
980
|
* 分离后的语气:AA 求解完还要**把明度夹回分离侧**。
|
|
779
981
|
*
|
|
@@ -801,16 +1003,16 @@ export function deriveTheme(input: SomaThemeInput): SomaDerivedTheme {
|
|
|
801
1003
|
};
|
|
802
1004
|
|
|
803
1005
|
const successFg = clampSeparated(
|
|
804
|
-
'success',
|
|
1006
|
+
'success',
|
|
1007
|
+
ensureContrast(success, SOLVER_DEPS, params.targets.fgOnTone, undefined, solveDir('success', successSolved)),
|
|
805
1008
|
);
|
|
806
1009
|
const warningFg = clampSeparated(
|
|
807
|
-
'warning',
|
|
1010
|
+
'warning',
|
|
1011
|
+
ensureContrast(warning, SOLVER_DEPS, params.targets.fgOnTone, undefined, solveDir('warning', warningSolved)),
|
|
808
1012
|
);
|
|
809
1013
|
|
|
810
1014
|
// ④.2 文字/背景层级(亮色):正文对页面底对比度硬保障 ≥ 4.5(不达标持续加深)
|
|
811
|
-
//
|
|
812
|
-
// 0.965 仍是"几乎白"的观感,但卡片边界一眼可辨
|
|
813
|
-
const bgPage = gray(0.965);
|
|
1015
|
+
// bgPage 在 ②.1 就已算出(S2 求解要用),这里只接着解正文色
|
|
814
1016
|
let textPrimary = gray(0.25);
|
|
815
1017
|
for (let i = 0; i < 16 && contrastRatio(bgPage, textPrimary) < params.targets.textOnPage; i++) {
|
|
816
1018
|
const cur = hexToOklch(textPrimary);
|
|
@@ -825,10 +1027,8 @@ export function deriveTheme(input: SomaThemeInput): SomaDerivedTheme {
|
|
|
825
1027
|
const glassShadowSoft = hexWithAlpha(scale['500'], 0.09);
|
|
826
1028
|
|
|
827
1029
|
const cssVars: Record<string, string> = {
|
|
828
|
-
//
|
|
829
|
-
|
|
830
|
-
'--soma-surface-glass-strong': 'rgba(255, 255, 255, 0.88)',
|
|
831
|
-
'--soma-surface-glass-weak': 'rgba(255, 255, 255, 0.52)',
|
|
1030
|
+
// 玻璃材质:面/强面/高光边/彩色投影。玻璃三档的值只住在 scene-tokens 的 glassTokens 一处
|
|
1031
|
+
...glassTokens(false),
|
|
832
1032
|
'--soma-edge-highlight': 'rgba(255, 255, 255, 0.72)',
|
|
833
1033
|
'--soma-shadow-tinted': `0 24px 70px ${glassShadow}`,
|
|
834
1034
|
'--soma-shadow-tinted-soft': `0 16px 36px ${glassShadowSoft}`,
|
|
@@ -922,15 +1122,18 @@ export function deriveTheme(input: SomaThemeInput): SomaDerivedTheme {
|
|
|
922
1122
|
&& axes.palette.accents.length === 0
|
|
923
1123
|
? FUNCTIONAL_HUES
|
|
924
1124
|
: anchors.tones;
|
|
925
|
-
|
|
1125
|
+
// 暗色侧的 S2:页面底换成 darkBgPage(0.18),目标换成 params.darkTargets,
|
|
1126
|
+
// 带恒传 null——粉彩带 [0.70, 0.86] 是按亮底校准的,落到暗色语气上会把它们
|
|
1127
|
+
// 推亮、反差反而更大,与 soft 这一档的语义相反(见 theme-axes 的带说明)
|
|
1128
|
+
const darkDanger = solveOnPage('danger', {
|
|
926
1129
|
l: 0.68, c: Math.max(brand.c, 0.12) * 0.9 * params.chromaMul, h: darkToneHues.danger,
|
|
927
|
-
});
|
|
928
|
-
const darkSuccess =
|
|
1130
|
+
}, darkBgPage, params.darkTargets, null).hex;
|
|
1131
|
+
const darkSuccess = solveOnPage('success', {
|
|
929
1132
|
l: 0.66, c: Math.max(brand.c, 0.12) * 0.8 * params.chromaMul, h: darkToneHues.success,
|
|
930
|
-
});
|
|
931
|
-
const darkWarning =
|
|
1133
|
+
}, darkBgPage, params.darkTargets, null).hex;
|
|
1134
|
+
const darkWarning = solveOnPage('warning', {
|
|
932
1135
|
l: 0.76, c: Math.max(brand.c, 0.12) * 0.85 * params.chromaMul, h: darkToneHues.warning,
|
|
933
|
-
});
|
|
1136
|
+
}, darkBgPage, params.darkTargets, null).hex;
|
|
934
1137
|
const darkSuccessEnsured = (() => {
|
|
935
1138
|
let bg = darkSuccess;
|
|
936
1139
|
let fg = bestFg(bg);
|
|
@@ -951,9 +1154,9 @@ export function deriveTheme(input: SomaThemeInput): SomaDerivedTheme {
|
|
|
951
1154
|
}
|
|
952
1155
|
return { bg, fg };
|
|
953
1156
|
})();
|
|
954
|
-
let darkInfo =
|
|
1157
|
+
let darkInfo = solveOnPage('info', {
|
|
955
1158
|
l: 0.68, c: Math.max(brand.c, 0.12) * 0.85 * params.chromaMul, h: darkToneHues.info,
|
|
956
|
-
});
|
|
1159
|
+
}, darkBgPage, params.darkTargets, null).hex;
|
|
957
1160
|
let darkInfoFg = bestFg(darkInfo);
|
|
958
1161
|
for (let i = 0; i < 16 && contrastRatio(darkInfo, darkInfoFg) < params.darkTargets.fgOnTone; i++) {
|
|
959
1162
|
const cur = hexToOklch(darkInfo);
|
|
@@ -961,8 +1164,27 @@ export function deriveTheme(input: SomaThemeInput): SomaDerivedTheme {
|
|
|
961
1164
|
darkInfoFg = bestFg(darkInfo);
|
|
962
1165
|
}
|
|
963
1166
|
|
|
1167
|
+
// ⑤.1b 暗色 secondary/accent:从 **DarkBase** 提亮一档,再按暗色目标独立求解。
|
|
1168
|
+
//
|
|
1169
|
+
// 基准是"未经 contrast 轴亮色侧加工的亮色 AA 结果",不是亮色成品——
|
|
1170
|
+
// 理由见 ④.1b 的种子注释:粉彩带与 toneOnPage 在深底上作用方向相反,
|
|
1171
|
+
// 继承亮色成品会让档位语义在暗色里倒过来(实测 strong 反而比 standard 弱)。
|
|
1172
|
+
// 缺省档下两者是同一次求解的同一个值,所以这一改动对缺省产出是恒等的。
|
|
1173
|
+
//
|
|
1174
|
+
// 再解一次 toneOnPage 是必须的:页面底换了(0.965 → 0.18),亮色那次求解的
|
|
1175
|
+
// 结论在这里不成立;而这两个语气没有 AA 循环(只由 ⑥ 的 enforceContrastPairs
|
|
1176
|
+
// 兜 4.5),暗档的 toneOnPage 目标正是绑住它们的那一条。
|
|
1177
|
+
const darkSecondary = solveOnPage('secondary', {
|
|
1178
|
+
...hexToOklch(secondaryDarkBase),
|
|
1179
|
+
l: Math.min(0.78, hexToOklch(secondaryDarkBase).l + 0.08),
|
|
1180
|
+
}, darkBgPage, params.darkTargets, null).hex;
|
|
1181
|
+
const darkAccent = solveOnPage('accent', {
|
|
1182
|
+
...hexToOklch(accentDarkBase),
|
|
1183
|
+
l: Math.min(0.82, hexToOklch(accentDarkBase).l + 0.08),
|
|
1184
|
+
}, darkBgPage, params.darkTargets, null).hex;
|
|
1185
|
+
|
|
964
1186
|
// ⑤.2 文字/背景层级(暗色):反转方向,正文对页面底不达标持续提亮
|
|
965
|
-
|
|
1187
|
+
// darkBgPage 同样在 ②.1 算出(暗色侧的 S2 求解要用)
|
|
966
1188
|
let darkTextPrimary = gray(0.92);
|
|
967
1189
|
for (let i = 0; i < 16 && contrastRatio(darkBgPage, darkTextPrimary) < params.darkTargets.textOnPage; i++) {
|
|
968
1190
|
const cur = hexToOklch(darkTextPrimary);
|
|
@@ -976,11 +1198,11 @@ export function deriveTheme(input: SomaThemeInput): SomaDerivedTheme {
|
|
|
976
1198
|
'--soma-c-primary-active': oklchToHex({ ...hexToOklch(darkPrimary), l: hexToOklch(darkPrimary).l + 0.1 }),
|
|
977
1199
|
'--soma-c-primary-fg': darkFg,
|
|
978
1200
|
'--soma-c-primary-soft': hexWithAlpha(scale['400'], 0.14),
|
|
979
|
-
'--soma-c-secondary':
|
|
980
|
-
'--soma-c-secondary-fg': bestFg(
|
|
1201
|
+
'--soma-c-secondary': darkSecondary,
|
|
1202
|
+
'--soma-c-secondary-fg': bestFg(darkSecondary),
|
|
981
1203
|
'--soma-c-secondary-soft': hexWithAlpha(secondaryTone.bg, 0.18),
|
|
982
|
-
'--soma-c-accent':
|
|
983
|
-
'--soma-c-accent-fg': bestFg(
|
|
1204
|
+
'--soma-c-accent': darkAccent,
|
|
1205
|
+
'--soma-c-accent-fg': bestFg(darkAccent),
|
|
984
1206
|
'--soma-c-accent-soft': hexWithAlpha(accentTone.bg, 0.18),
|
|
985
1207
|
'--soma-c-danger': darkDanger,
|
|
986
1208
|
'--soma-c-success': darkSuccessEnsured.bg,
|
|
@@ -1007,11 +1229,9 @@ export function deriveTheme(input: SomaThemeInput): SomaDerivedTheme {
|
|
|
1007
1229
|
'--soma-c-info-soft': hexWithAlpha(darkInfo, 0.16),
|
|
1008
1230
|
// 暗色下的阴影:亮色那套 rgba(0,0,0,.06~.16) 落在深底上等于不存在,
|
|
1009
1231
|
// 层级会整个塌掉。加深并加大扩散,让浮层仍然"浮"得起来
|
|
1010
|
-
//
|
|
1011
|
-
//
|
|
1012
|
-
|
|
1013
|
-
'--soma-surface-glass-strong': 'rgba(255, 255, 255, 0.1)',
|
|
1014
|
-
'--soma-surface-glass-weak': 'rgba(255, 255, 255, 0.04)',
|
|
1232
|
+
// 暗色玻璃:仍是白,但 alpha 只有 4%~10%(亮色是 52%~88%)——高 alpha 的白玻璃
|
|
1233
|
+
// 落在深底上会变成一块发光的板,层级反而糊掉。高光边同理减弱,只留一线。
|
|
1234
|
+
...glassTokens(true),
|
|
1015
1235
|
'--soma-edge-highlight': 'rgba(255, 255, 255, 0.12)',
|
|
1016
1236
|
'--soma-shadow-tinted': '0 24px 70px rgba(0, 0, 0, 0.55)',
|
|
1017
1237
|
'--soma-shadow-tinted-soft': '0 16px 36px rgba(0, 0, 0, 0.45)',
|
|
@@ -1110,6 +1330,8 @@ export function deriveTheme(input: SomaThemeInput): SomaDerivedTheme {
|
|
|
1110
1330
|
axes,
|
|
1111
1331
|
separationApplied: guard.applied,
|
|
1112
1332
|
pushed: guard.pushed,
|
|
1333
|
+
// 排序保证确定性:meta 也要满足"同输入必同输出"
|
|
1334
|
+
bandBroken: [...bandBroken].sort(),
|
|
1113
1335
|
componentTokens: Object.keys({ ...lightComponentTokens, ...darkComponentTokens }).sort(),
|
|
1114
1336
|
},
|
|
1115
1337
|
};
|
|
@@ -1166,17 +1388,6 @@ function assertComponentTokenValue(componentName: string, key: string, value: st
|
|
|
1166
1388
|
}
|
|
1167
1389
|
}
|
|
1168
1390
|
|
|
1169
|
-
/**
|
|
1170
|
-
* 引擎会写出的令牌名全集(静态令牌 + 派生令牌),不跑派生。
|
|
1171
|
-
*
|
|
1172
|
-
* 给 soma-ui 的 `token-existence-lint` 用:契约 `tokens.default` 引用的语义令牌
|
|
1173
|
-
* 必须真的存在,否则组件令牌指向一个空变量,回退值一路生效而没人发现。
|
|
1174
|
-
*/
|
|
1175
|
-
export function listThemeTokenNames(): readonly string[] {
|
|
1176
|
-
const probe = deriveTheme({ brand: '#2563eb' });
|
|
1177
|
-
return Object.keys({ ...probe.cssVars, ...probe.darkCssVars }).sort();
|
|
1178
|
-
}
|
|
1179
|
-
|
|
1180
1391
|
/**
|
|
1181
1392
|
* 派生结果 → 根元素属性。
|
|
1182
1393
|
*
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
//
|
|
12
12
|
// 纯函数模块:零全局、零缓存(memo 归编排者,沿用既有 onSoftMemo 的位置)。
|
|
13
13
|
|
|
14
|
-
import type {
|
|
14
|
+
import type { SomaContrastTargets } from './theme-axes';
|
|
15
15
|
|
|
16
16
|
export interface Oklch { l: number; c: number; h: number }
|
|
17
17
|
|
|
@@ -82,8 +82,14 @@ export function ensureContrast(
|
|
|
82
82
|
* 前景(-fg)仍由既有 ④ 系代码解——那部分是实测校准过的 AA 保障,不在此重复。
|
|
83
83
|
*
|
|
84
84
|
* **裁决**:粉彩带约束与对比度目标冲突时**对比度赢**(AA 底线不随 contrast 档
|
|
85
|
-
*
|
|
86
|
-
*
|
|
85
|
+
* 移动,是《soma 设计令牌与主题》§10.3 原则 4「硬保障不是输入」的承诺)。
|
|
86
|
+
* 带被突破时通过返回值旁路上报,由编排者收进 `meta.bandBroken`,供观测——
|
|
87
|
+
* 不报错,因为"带"是气质偏好不是硬约束。
|
|
88
|
+
*
|
|
89
|
+
* **编排者的责任**(theme-engine 的 `solveOnPage`):本函数排在 AA 求解与分离闸
|
|
90
|
+
* 夹子的**上游**,那两条是硬保障、永远说了算;本函数解出的 toneOnPage 是气质
|
|
91
|
+
* 目标,被它们顶掉不报错。调用点还要把下游 `ensureContrast` 的方向钉在
|
|
92
|
+
* 「远离页面底」一侧,否则缺省启发会把刚解好的语气朝页面底推回去。
|
|
87
93
|
*/
|
|
88
94
|
export function solveTone(
|
|
89
95
|
seed: Oklch,
|
|
@@ -111,8 +117,3 @@ export function solveTone(
|
|
|
111
117
|
}
|
|
112
118
|
return { tone: solved, bandBroken };
|
|
113
119
|
}
|
|
114
|
-
|
|
115
|
-
/** 彩度个性:把 chroma 轴的乘数应用到一个种子彩度上(下限护栏防止推成死灰) */
|
|
116
|
-
export function applyChroma(baseChroma: number, params: SomaAxisParams): number {
|
|
117
|
-
return Math.max(0.02, baseChroma * params.chromaMul);
|
|
118
|
-
}
|
package/core/index.ts
CHANGED
|
@@ -69,12 +69,20 @@ export type {
|
|
|
69
69
|
SomaDataWriteEndpoint,
|
|
70
70
|
SomaDataSubmitResult,
|
|
71
71
|
SomaDataPort,
|
|
72
|
+
// 对象级语义(REQ-014 期 2'.1):演绎链与业务方都要按结构消费它们,
|
|
73
|
+
// 不公开的话每个消费方只能本地重声明一份——那正是「同一个概念多份抄本」的起点
|
|
74
|
+
SomaDataObjectRoles,
|
|
75
|
+
SomaDataObjectRelation,
|
|
76
|
+
SomaDataRelationCardinality,
|
|
72
77
|
} from './shared/types/data-config.types';
|
|
73
78
|
// 字段类型的唯一真源(值导出):块解析器与 soma-ui 的双态映射表都消费它,
|
|
74
79
|
// 消费方不得再手抄一份清单——四份手写副本里漏改一份,就是「一处合法、一处静默按 text 渲染」。
|
|
75
80
|
export {
|
|
76
81
|
SOMA_DATA_FIELD_TYPES,
|
|
77
82
|
SOMA_DATA_FIELD_TYPE_ALIASES,
|
|
83
|
+
// 角色名与关系基数同样是封闭集,同样只准有一份(理由同上一段)
|
|
84
|
+
SOMA_DATA_OBJECT_ROLES,
|
|
85
|
+
SOMA_DATA_RELATION_CARDINALITIES,
|
|
78
86
|
} from './shared/types/data-config.types';
|
|
79
87
|
|
|
80
88
|
// 字段谓词图(REQ-010 S1b):三个消费者共用的封闭布尔代数——
|
|
@@ -311,10 +319,15 @@ export {
|
|
|
311
319
|
} from './shared/component/field-lines';
|
|
312
320
|
export {
|
|
313
321
|
deriveContractSample,
|
|
322
|
+
deriveContractPreviewSample,
|
|
314
323
|
deriveFieldSample,
|
|
315
324
|
hasRenderableSample,
|
|
316
325
|
} from './shared/component/derive-sample';
|
|
317
|
-
export type {
|
|
326
|
+
export type {
|
|
327
|
+
DerivePreviewSampleResult,
|
|
328
|
+
DeriveSampleResult,
|
|
329
|
+
SampleGap,
|
|
330
|
+
} from './shared/component/derive-sample';
|
|
318
331
|
// 组件级令牌(REQ-009 M-1)的命名规则。宿主与闸门都要按同一条规则拼名字——
|
|
319
332
|
// 各自拼一遍的话,主题的 `components` 段覆盖不上任何东西,而覆盖不上是静默的。
|
|
320
333
|
export {
|
|
@@ -478,9 +491,10 @@ export {
|
|
|
478
491
|
type HtmlAnchorIndex,
|
|
479
492
|
type HtmlAnchorInfo,
|
|
480
493
|
} from './build/blocks/html-index';
|
|
481
|
-
//
|
|
482
|
-
//
|
|
483
|
-
|
|
494
|
+
// `compilePageAssets` 是服务端/测试的构建期入口,不能从这个浏览器根 barrel
|
|
495
|
+
// 导出。它会装载声明编译器(含 Node 专用的 OOUI 内容指纹),而 Host bootstrap
|
|
496
|
+
// 从根包导入运行时 API;把它放在这里会让 Webpack 尝试解析 `node:crypto`。
|
|
497
|
+
// 服务端调用方请通过 `soma-core/server/page-assets` 延迟加载。
|
|
484
498
|
export {
|
|
485
499
|
compileSomaBlocks,
|
|
486
500
|
type CompiledSomaBlocks,
|
|
@@ -52,8 +52,14 @@ export function loadHostService(segments: string[]): IService | null {
|
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
try {
|
|
55
|
-
const
|
|
56
|
-
|
|
55
|
+
const loaded = getJiti(hostDir)(filePath) as unknown;
|
|
56
|
+
// Jiti with `interopDefault: true` returns a lone default export directly.
|
|
57
|
+
// A default class that extends another default-exported class can inherit a
|
|
58
|
+
// static `.default` from its base, so reading `loaded.default` first would
|
|
59
|
+
// instantiate the base service and silently drop the Host subclass setup.
|
|
60
|
+
const ServiceClass = typeof loaded === 'function'
|
|
61
|
+
? loaded as new () => IService
|
|
62
|
+
: (loaded as { default?: new () => IService } | null)?.default;
|
|
57
63
|
if (!ServiceClass || typeof ServiceClass !== 'function') {
|
|
58
64
|
console.warn(`[soma-core][接口] ${filePath} missing default export`);
|
|
59
65
|
return null;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server-only declaration injection scanner public entry.
|
|
3
|
+
*
|
|
4
|
+
* 刻意不 `import 'server-only'`:soma-ai 的声明校验器在经 jiti 加载的宿主服务里
|
|
5
|
+
* import 本入口,server-only 在纯 Node 语境下会抛错(理由同 `server/page-declaration.ts`)。
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export {
|
|
9
|
+
scanDeclarationSafety,
|
|
10
|
+
type ScannableDeclaration,
|
|
11
|
+
} from './registry/validation/declaration-safety-scan';
|