soma-kit 0.1.10 → 0.1.12
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 +103 -110
- package/bin/soma-kit.mjs +1 -1
- package/bin/soma.mjs +22 -0
- package/package.json +13 -7
- package/packs/finance/reconcile-board.ts +5 -2
- package/packs/finance/reconcile-desk/compile.ts +3 -2
- package/spec/generated/kit-app.schema.json +776 -38
- package/spec/generated/kit-page.schema.json +1613 -224
- package/spec/kit-grammar.json +770 -529
- package/spec/kit-grammar.schema.json +1962 -392
- package/src/app/app-config.ts +371 -347
- package/src/app/component-gate.ts +12 -15
- package/src/app/compose-apps.ts +79 -8
- package/src/app/define-kit-actions.ts +245 -41
- package/src/app/define-kit-app.ts +174 -31
- package/src/app/define-kit-view.ts +100 -0
- package/src/app/envelope.ts +1 -161
- package/src/app/index.ts +13 -2
- package/src/app/kit-view-context.ts +290 -0
- package/src/app/notify-renderer.ts +1 -115
- package/src/app/paged-list-adapter.ts +1 -240
- package/src/app/server-pages.ts +8 -2
- package/src/app/server.ts +491 -101
- package/src/app/submit.types.ts +1 -1
- package/src/app/theme-endpoint.ts +63 -0
- package/src/app/theme-runtime-shared.ts +1 -0
- package/src/app/theme-runtime.ts +663 -0
- package/src/base/action-busy.ts +2 -2
- package/src/base/action-gate.ts +4 -255
- package/src/base/action-slots.ts +47 -0
- package/src/base/alert.ts +5 -3
- package/src/base/avatar.ts +2 -2
- package/src/base/button.ts +46 -29
- package/src/base/cascader.ts +11 -12
- package/src/base/check-core.ts +1 -1
- package/src/base/choice.ts +28 -26
- package/src/base/class-candidates.ts +17 -0
- package/src/base/color-picker.ts +6 -6
- package/src/base/combobox.ts +5 -3
- package/src/base/command-palette.ts +9 -5
- package/src/base/countdown.ts +1 -1
- package/src/base/date-range.ts +25 -11
- package/src/base/date.ts +85 -17
- package/src/base/divider.ts +2 -2
- package/src/base/fab.ts +11 -4
- package/src/base/image.ts +1 -1
- package/src/base/index.ts +9 -3
- package/src/base/input.ts +42 -13
- package/src/base/kbd.ts +3 -1
- package/src/base/link.ts +4 -4
- package/src/base/listbox-core.ts +50 -30
- package/src/base/loading-gate.ts +133 -0
- package/src/base/mentions.ts +5 -5
- package/src/base/menu-button.ts +6 -1
- package/src/base/menu-core.ts +4 -0
- package/src/base/motion/aura.ts +2 -2
- package/src/base/motion/hover-3d.ts +2 -2
- package/src/base/motion/hover-gallery.ts +2 -2
- package/src/base/motion/marquee.ts +2 -2
- package/src/base/motion/text-rotate.ts +2 -2
- package/src/base/number.ts +93 -80
- package/src/base/otp.ts +4 -1
- package/src/base/permission-gate.ts +6 -0
- package/src/base/popover.ts +40 -8
- package/src/base/popup.ts +79 -14
- package/src/base/price-text.ts +2 -2
- package/src/base/progress.ts +2 -2
- package/src/base/qr-code.ts +4 -4
- package/src/base/qty-stepper.ts +9 -3
- package/src/base/range.ts +2 -2
- package/src/base/rating.ts +1 -1
- package/src/base/segmented.ts +4 -0
- package/src/base/select.ts +4 -3
- package/src/base/shared.ts +221 -29
- package/src/base/swap.ts +4 -1
- package/src/base/switch.ts +1 -1
- package/src/base/tag-input.ts +14 -10
- package/src/base/tag.ts +5 -1
- package/src/base/text.ts +39 -6
- package/src/base/textarea.ts +37 -11
- package/src/base/time-picker.ts +12 -9
- package/src/base/tree-select.ts +15 -8
- package/src/base/upload.ts +34 -5
- package/src/base/virtual-list.ts +107 -1
- package/src/biz/approval-desk/compile.ts +23 -41
- package/src/biz/auth-panel/compile.ts +37 -52
- package/src/biz/auth-panel/index.ts +1 -1
- package/src/biz/category-crud/compile.ts +22 -36
- package/src/biz/checkout-page/compile.ts +21 -5
- package/src/biz/compose.ts +13 -27
- package/src/biz/define.ts +5 -4
- package/src/biz/import-wizard/compile.ts +22 -26
- package/src/biz/import-wizard/hub.ts +126 -61
- package/src/biz/import-wizard/shell.ts +3 -3
- package/src/biz/index.ts +3 -3
- package/src/biz/landing-page/compile.ts +19 -3
- package/src/biz/link/hub.ts +49 -20
- package/src/biz/link/shared.ts +115 -118
- package/src/biz/master-sub/compile.ts +31 -44
- package/src/biz/multi-board/compile.ts +34 -49
- package/src/biz/multi-board/index.ts +18 -1
- package/src/biz/multi-board/shell.ts +24 -15
- package/src/biz/notification-center/compile.ts +21 -33
- package/src/biz/page-templates/domain-templates.ts +80 -13
- package/src/biz/page-templates/result-page/compile.ts +11 -2
- package/src/biz/page-templates/shared.ts +34 -36
- package/src/biz/record-detail/compile.ts +47 -42
- package/src/biz/record-detail/index.ts +11 -1
- package/src/biz/settings-center/compile.ts +6 -5
- package/src/biz/shared/action-host.ts +91 -211
- package/src/biz/shared/compile-helpers.ts +80 -0
- package/src/biz/shared/coordinator.ts +486 -83
- package/src/biz/shared/index.ts +8 -2
- package/src/biz/shared/overlay-shell.ts +80 -0
- package/src/biz/shared/pipes.ts +43 -30
- package/src/biz/shared/remove-key.ts +6 -0
- package/src/biz/shared/remove-wire.ts +29 -0
- package/src/biz/shared/runtime-hub.ts +216 -24
- package/src/biz/single-form/compile.ts +15 -37
- package/src/biz/standard-crud/compile.ts +62 -107
- package/src/biz/standard-crud/shell.ts +16 -66
- package/src/biz/step-form/compile.ts +26 -97
- package/src/biz/step-form/hub.ts +34 -41
- package/src/biz/types.ts +4 -3
- package/src/cli/core-imports.ts +54 -0
- package/src/cli/kit-cli.ts +130 -26
- package/src/cli/kit-init.ts +222 -0
- package/src/cli/service-endpoint-check.ts +425 -0
- package/src/cli/source-path-check.d.mts +17 -0
- package/src/cli/source-path-check.mjs +334 -0
- package/src/cli/view-writes.ts +752 -0
- package/src/compile/action-host-attach.ts +21 -29
- package/src/compile/closed-set.ts +509 -0
- package/src/compile/compile-page.ts +219 -72
- package/src/compile/component-candidates.ts +1 -1
- package/src/compile/hints.ts +30 -1
- package/src/compile/index.ts +1 -0
- package/src/compile/kit-error.ts +1 -0
- package/src/compile/locate.ts +21 -1
- package/src/compile/parse.ts +370 -41
- package/src/compile/redirect.ts +6 -2
- package/src/compile/styles.ts +35 -2
- package/src/compile/types.ts +18 -2
- package/src/compile/view-check.ts +151 -0
- package/src/data/amount-breakdown.ts +2 -2
- package/src/data/anchor-nav.ts +2 -2
- package/src/data/approval-flow.ts +2 -2
- package/src/data/assignment-picker.ts +40 -29
- package/src/data/async-result-panel.ts +62 -6
- package/src/data/breadcrumbs.ts +2 -2
- package/src/data/calendar.ts +22 -25
- package/src/data/carousel.ts +5 -2
- package/src/data/chart.ts +42 -34
- package/src/data/checklist.ts +2 -2
- package/src/data/code-view.ts +4 -2
- package/src/data/comment-thread.ts +5 -2
- package/src/data/confirm-dialog.ts +10 -0
- package/src/data/context-menu.ts +29 -37
- package/src/data/d9-util.ts +2 -18
- package/src/data/diff.ts +4 -2
- package/src/data/dock.ts +2 -2
- package/src/data/embed.ts +2 -1
- package/src/data/field-mapper.ts +31 -26
- package/src/data/flow-editor-contract.ts +1 -1
- package/src/data/flow-editor.ts +89 -100
- package/src/data/flow-node-options.ts +90 -0
- package/src/data/flow-remote-options.ts +0 -103
- package/src/data/footer.ts +2 -2
- package/src/data/form-draft-registry.ts +2 -4
- package/src/data/gantt.ts +14 -17
- package/src/data/hero.ts +2 -2
- package/src/data/image-viewer.ts +20 -26
- package/src/data/index.ts +0 -2
- package/src/data/item-list.ts +31 -22
- package/src/data/kanban.ts +43 -42
- package/src/data/media-grid.ts +14 -19
- package/src/data/menu.ts +2 -2
- package/src/data/mockup.ts +2 -2
- package/src/data/modal-dialog.ts +22 -18
- package/src/data/navbar.ts +7 -2
- package/src/data/notify-renderer.ts +235 -0
- package/src/data/object-form.ts +1036 -648
- package/src/data/pager.ts +65 -29
- package/src/data/permission-matrix.ts +20 -21
- package/src/data/permission-tree.ts +28 -26
- package/src/data/pricing-table.ts +9 -3
- package/src/data/reaction-bar.ts +77 -88
- package/src/data/read-rollback.ts +73 -0
- package/src/data/record-card.ts +3 -3
- package/src/data/record-picker.ts +93 -50
- package/src/data/redirect.ts +32 -32
- package/src/data/remote-options.ts +13 -6
- package/src/data/request-console.ts +5 -3
- package/src/data/resident.ts +2 -1
- package/src/data/result-panel.ts +4 -2
- package/src/data/rich-text.ts +45 -55
- package/src/data/row-editor.ts +285 -52
- package/src/data/rule-builder.ts +18 -12
- package/src/data/shape-util.ts +4 -0
- package/src/data/stat-group.ts +243 -101
- package/src/data/static-registry.ts +22 -11
- package/src/data/steps.ts +2 -2
- package/src/data/survey.ts +24 -29
- package/src/data/system-switcher.ts +2 -2
- package/src/data/timeline.ts +2 -2
- package/src/data/tour-guide.ts +22 -29
- package/src/data/transfer.ts +27 -23
- package/src/data/tree-table.ts +96 -48
- package/src/data/tree.ts +27 -34
- package/src/data/trend-line.ts +6 -24
- package/src/data/virtual-rows.ts +118 -76
- package/src/data/watermark.ts +2 -2
- package/src/data/wrap.ts +63 -38
- package/src/frames/blank-frame.ts +1 -0
- package/src/frames/index.ts +2 -2
- package/src/frames/page-bar.ts +12 -11
- package/src/frames/page-header.ts +14 -5
- package/src/frames/page-status.ts +2 -2
- package/src/frames/shared.ts +23 -17
- package/src/frames/single-frame.ts +1 -0
- package/src/frames/split-frame/shell.ts +5 -5
- package/src/frames/split-frame/wiring.ts +2 -2
- package/src/frames/tabs-frame/shell.ts +2 -13
- package/src/frames/tabs-frame/wiring.ts +4 -8
- package/src/frames/top-main-frame.ts +1 -0
- package/src/frames/types.ts +13 -2
- package/src/frames/workspace-frame/extras.ts +20 -4
- package/src/frames/workspace-frame/index.ts +1 -1
- package/src/frames/workspace-frame/shell.ts +1 -0
- package/src/frames/workspace-frame/state.ts +13 -6
- package/src/frames/workspace-frame/view.ts +119 -25
- package/src/generated/kit-grammar-runtime.ts +430 -366
- package/src/generated/page-origin.ts +0 -11
- package/src/i18n/kit-text.ts +23 -27
- package/src/index.ts +2 -1
- package/src/object-renderer/action-gate.ts +11 -147
- package/src/object-renderer/arrange.ts +71 -77
- package/src/object-renderer/collapse-wiring.ts +2 -2
- package/src/object-renderer/collection-expand.ts +2 -2
- package/src/object-renderer/collection-parts.ts +216 -100
- package/src/object-renderer/collection-table.ts +180 -42
- package/src/object-renderer/collection.ts +95 -79
- package/src/object-renderer/compile-data.ts +85 -100
- package/src/object-renderer/crud-bridge.ts +32 -0
- package/src/object-renderer/defaults.ts +8 -14
- package/src/object-renderer/display-checks.ts +3 -24
- package/src/object-renderer/emit-events.ts +186 -172
- package/src/object-renderer/emit-object.ts +15 -2
- package/src/object-renderer/emit-static.ts +174 -132
- package/src/object-renderer/field-value.ts +593 -396
- package/src/object-renderer/filter-reload.ts +70 -0
- package/src/object-renderer/form-detail.ts +112 -2
- package/src/object-renderer/index.ts +26 -0
- package/src/object-renderer/key-field.ts +12 -0
- package/src/object-renderer/linkage.ts +7 -270
- package/src/object-renderer/merge-class.ts +18 -1
- package/src/object-renderer/path-pick.ts +27 -0
- package/src/object-renderer/render-object.ts +405 -86
- package/src/object-renderer/request-actions.ts +230 -249
- package/src/object-renderer/table-actions.ts +195 -95
- package/src/object-renderer/table-summary.ts +2 -2
- package/src/object-renderer/table-tools.ts +418 -84
- package/src/object-renderer/types.ts +128 -122
- package/src/object-renderer/view-binding.ts +196 -0
- package/src/page-target/ai-surface.ts +37 -0
- package/src/page-target/compile.ts +48 -8
- package/src/page-target/index.ts +8 -1
- package/src/page-target/intent-schema.ts +154 -28
- package/src/page-target/target.ts +257 -50
- package/src/page-target/writer-policy.ts +14 -3
- package/src/recipes/container.ts +165 -0
- package/src/recipes/control.ts +219 -0
- package/src/recipes/index.ts +263 -0
- package/src/recipes/overlay.ts +182 -0
- package/src/recipes/state.ts +70 -0
- package/src/recipes/table-row.ts +51 -0
- package/src/recipes/typography.ts +87 -0
- package/src/shared/action-field-guard.ts +41 -0
- package/src/shared/envelope.ts +207 -0
- package/src/shared/escape.ts +57 -0
- package/src/shared/kit-error.ts +21 -0
- package/src/shared/paged-list-adapter.ts +240 -0
- package/src/shared/path-guard.ts +127 -0
- package/src/shared/theme-runtime-shared.ts +175 -0
- package/src/shared/view-info.ts +10 -0
- package/src/theme/index.ts +12 -0
- package/src/theme/kit-theme-text.ts +1 -1
- package/src/theme/kit-theme.css +38 -1
- package/src/theme/kit-theme.tpl +38 -1
- package/src/theme/nine-dim-structure.ts +77 -0
- package/src/theme/surface-layers.ts +97 -0
- package/src/theme/theme-tokens.ts +85 -79
- package/src/theme/theme-types.ts +71 -0
- package/src/theme/typography.ts +17 -17
- package/src/biz/shared/step-values.ts +0 -25
- package/src/biz/step-form/steps-ref.ts +0 -112
- package/src/data/options-bus.ts +0 -24
- package/src/data/prompt-dialog.ts +0 -235
- package/src/object-renderer/adopt-gate.ts +0 -333
- package/src/object-renderer/field-policy.ts +0 -89
- package/src/object-renderer/outcome-draft.ts +0 -61
- package/src/theme/nine-dim-palettes.ts +0 -1278
package/src/theme/kit-theme.css
CHANGED
|
@@ -10,6 +10,8 @@
|
|
|
10
10
|
--color-surface: var(--soma-surface-base);
|
|
11
11
|
--color-surface-sunken: var(--soma-surface-sunken);
|
|
12
12
|
--color-surface-raised: var(--soma-surface-raised);
|
|
13
|
+
/* 遮罩幕:亮暗各一档的深色 + 内含透明度(design surface#/scrim),类名 bg-scrim 不再叠 /N 透明度 */
|
|
14
|
+
--color-scrim: var(--soma-overlay-bg);
|
|
13
15
|
|
|
14
16
|
--color-fg: var(--soma-text-primary);
|
|
15
17
|
--color-fg-muted: var(--soma-text-secondary);
|
|
@@ -53,15 +55,23 @@
|
|
|
53
55
|
--color-info-soft: var(--soma-c-info-soft);
|
|
54
56
|
--color-info-on-soft: var(--soma-c-info-on-soft);
|
|
55
57
|
|
|
56
|
-
--color-ring: var(--soma-focus
|
|
58
|
+
--color-ring: var(--soma-border-focus);
|
|
57
59
|
|
|
58
60
|
--spacing: var(--soma-space-1);
|
|
61
|
+
--spacing-card: var(--soma-card-padding);
|
|
62
|
+
--spacing-section: var(--soma-section-gap);
|
|
63
|
+
--spacing-table-row: var(--soma-table-row-height);
|
|
59
64
|
|
|
60
65
|
--radius-sm: var(--soma-radius-sm);
|
|
61
66
|
--radius-md: var(--soma-radius-md);
|
|
62
67
|
--radius-lg: var(--soma-radius-lg);
|
|
63
68
|
--radius-xl: var(--soma-radius-xl);
|
|
64
69
|
--radius-full: var(--soma-radius-full);
|
|
70
|
+
--radius-card: var(--soma-radius-card);
|
|
71
|
+
--radius-control: var(--soma-radius-control);
|
|
72
|
+
--radius-button: var(--soma-radius-button);
|
|
73
|
+
--radius-badge: var(--soma-radius-badge);
|
|
74
|
+
--radius-inner: var(--soma-radius-inner);
|
|
65
75
|
|
|
66
76
|
--text-xs: var(--soma-font-size-xs);
|
|
67
77
|
--text-xs--line-height: var(--soma-line-height-xs);
|
|
@@ -75,11 +85,21 @@
|
|
|
75
85
|
--text-xl--line-height: var(--soma-line-height-xl);
|
|
76
86
|
--text-2xl: var(--soma-font-size-xxl);
|
|
77
87
|
--text-2xl--line-height: var(--soma-line-height-xxl);
|
|
88
|
+
--text-title-page: var(--soma-title-page-size);
|
|
89
|
+
--text-title-dialog: var(--soma-title-dialog-size);
|
|
90
|
+
--text-title-section: var(--soma-title-section-size);
|
|
91
|
+
--text-stat-value: var(--soma-stat-value-size);
|
|
78
92
|
|
|
79
93
|
--font-weight-normal: var(--soma-font-weight-normal);
|
|
80
94
|
--font-weight-medium: var(--soma-font-weight-medium);
|
|
81
95
|
--font-weight-semibold: var(--soma-font-weight-bold);
|
|
82
96
|
--font-weight-bold: var(--soma-font-weight-heavy);
|
|
97
|
+
--font-weight-title: var(--soma-title-weight);
|
|
98
|
+
|
|
99
|
+
--tracking-tight: var(--soma-tracking-tight);
|
|
100
|
+
--tracking-heading: var(--soma-tracking-heading);
|
|
101
|
+
--tracking-normal: var(--soma-tracking-normal);
|
|
102
|
+
--tracking-wide: var(--soma-tracking-wide);
|
|
83
103
|
|
|
84
104
|
--font-sans: var(--soma-font-family);
|
|
85
105
|
--font-mono: var(--soma-font-family-mono);
|
|
@@ -265,6 +285,13 @@
|
|
|
265
285
|
/* 骨架屏(KitCollectionState 的 loading: skeleton):呼吸占位;使用处一律 motion-safe: 前缀,减少动效下静止 */
|
|
266
286
|
@theme inline {
|
|
267
287
|
--animate-kit-pulse: kit-pulse 2s ease-in-out infinite;
|
|
288
|
+
--animate-spin: kit-spin 1s linear infinite;
|
|
289
|
+
|
|
290
|
+
@keyframes kit-spin {
|
|
291
|
+
to {
|
|
292
|
+
transform: rotate(360deg);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
268
295
|
|
|
269
296
|
@keyframes kit-pulse {
|
|
270
297
|
0%,
|
|
@@ -276,3 +303,13 @@
|
|
|
276
303
|
}
|
|
277
304
|
}
|
|
278
305
|
}
|
|
306
|
+
|
|
307
|
+
/* 高对比度模式(forced-colors: active):浏览器强制关闭 box-shadow 焦点环,统一保底使用系统 CanvasText 实线轮廓 */
|
|
308
|
+
@media (forced-colors: active) {
|
|
309
|
+
*:focus-visible,
|
|
310
|
+
[data-soma-component]:focus-within {
|
|
311
|
+
outline: 2px solid CanvasText !important;
|
|
312
|
+
outline-offset: 2px !important;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
package/src/theme/kit-theme.tpl
CHANGED
|
@@ -10,6 +10,8 @@
|
|
|
10
10
|
--color-surface: var(--soma-surface-base);
|
|
11
11
|
--color-surface-sunken: var(--soma-surface-sunken);
|
|
12
12
|
--color-surface-raised: var(--soma-surface-raised);
|
|
13
|
+
/* 遮罩幕:亮暗各一档的深色 + 内含透明度(design surface#/scrim),类名 bg-scrim 不再叠 /N 透明度 */
|
|
14
|
+
--color-scrim: var(--soma-overlay-bg);
|
|
13
15
|
|
|
14
16
|
--color-fg: var(--soma-text-primary);
|
|
15
17
|
--color-fg-muted: var(--soma-text-secondary);
|
|
@@ -53,15 +55,23 @@
|
|
|
53
55
|
--color-info-soft: var(--soma-c-info-soft);
|
|
54
56
|
--color-info-on-soft: var(--soma-c-info-on-soft);
|
|
55
57
|
|
|
56
|
-
--color-ring: var(--soma-focus
|
|
58
|
+
--color-ring: var(--soma-border-focus);
|
|
57
59
|
|
|
58
60
|
--spacing: var(--soma-space-1);
|
|
61
|
+
--spacing-card: var(--soma-card-padding);
|
|
62
|
+
--spacing-section: var(--soma-section-gap);
|
|
63
|
+
--spacing-table-row: var(--soma-table-row-height);
|
|
59
64
|
|
|
60
65
|
--radius-sm: var(--soma-radius-sm);
|
|
61
66
|
--radius-md: var(--soma-radius-md);
|
|
62
67
|
--radius-lg: var(--soma-radius-lg);
|
|
63
68
|
--radius-xl: var(--soma-radius-xl);
|
|
64
69
|
--radius-full: var(--soma-radius-full);
|
|
70
|
+
--radius-card: var(--soma-radius-card);
|
|
71
|
+
--radius-control: var(--soma-radius-control);
|
|
72
|
+
--radius-button: var(--soma-radius-button);
|
|
73
|
+
--radius-badge: var(--soma-radius-badge);
|
|
74
|
+
--radius-inner: var(--soma-radius-inner);
|
|
65
75
|
|
|
66
76
|
--text-xs: var(--soma-font-size-xs);
|
|
67
77
|
--text-xs--line-height: var(--soma-line-height-xs);
|
|
@@ -75,11 +85,21 @@
|
|
|
75
85
|
--text-xl--line-height: var(--soma-line-height-xl);
|
|
76
86
|
--text-2xl: var(--soma-font-size-xxl);
|
|
77
87
|
--text-2xl--line-height: var(--soma-line-height-xxl);
|
|
88
|
+
--text-title-page: var(--soma-title-page-size);
|
|
89
|
+
--text-title-dialog: var(--soma-title-dialog-size);
|
|
90
|
+
--text-title-section: var(--soma-title-section-size);
|
|
91
|
+
--text-stat-value: var(--soma-stat-value-size);
|
|
78
92
|
|
|
79
93
|
--font-weight-normal: var(--soma-font-weight-normal);
|
|
80
94
|
--font-weight-medium: var(--soma-font-weight-medium);
|
|
81
95
|
--font-weight-semibold: var(--soma-font-weight-bold);
|
|
82
96
|
--font-weight-bold: var(--soma-font-weight-heavy);
|
|
97
|
+
--font-weight-title: var(--soma-title-weight);
|
|
98
|
+
|
|
99
|
+
--tracking-tight: var(--soma-tracking-tight);
|
|
100
|
+
--tracking-heading: var(--soma-tracking-heading);
|
|
101
|
+
--tracking-normal: var(--soma-tracking-normal);
|
|
102
|
+
--tracking-wide: var(--soma-tracking-wide);
|
|
83
103
|
|
|
84
104
|
--font-sans: var(--soma-font-family);
|
|
85
105
|
--font-mono: var(--soma-font-family-mono);
|
|
@@ -265,6 +285,13 @@
|
|
|
265
285
|
/* 骨架屏(KitCollectionState 的 loading: skeleton):呼吸占位;使用处一律 motion-safe: 前缀,减少动效下静止 */
|
|
266
286
|
@theme inline {
|
|
267
287
|
--animate-kit-pulse: kit-pulse {{themeScales.pulse.durationS}}s ease-in-out infinite;
|
|
288
|
+
--animate-spin: kit-spin 1s linear infinite;
|
|
289
|
+
|
|
290
|
+
@keyframes kit-spin {
|
|
291
|
+
to {
|
|
292
|
+
transform: rotate(360deg);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
268
295
|
|
|
269
296
|
@keyframes kit-pulse {
|
|
270
297
|
0%,
|
|
@@ -276,3 +303,13 @@
|
|
|
276
303
|
}
|
|
277
304
|
}
|
|
278
305
|
}
|
|
306
|
+
|
|
307
|
+
/* 高对比度模式(forced-colors: active):浏览器强制关闭 box-shadow 焦点环,统一保底使用系统 CanvasText 实线轮廓 */
|
|
308
|
+
@media (forced-colors: active) {
|
|
309
|
+
*:focus-visible,
|
|
310
|
+
[data-soma-component]:focus-within {
|
|
311
|
+
outline: 2px solid CanvasText !important;
|
|
312
|
+
outline-offset: 2px !important;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// 九维主题的结构 CSS:只引令牌(--soma-container-* / --soma-texture-* / --soma-surface-layer-* 等,值由 soma-foundation/kit-nine-dim 求出),
|
|
2
|
+
// 不含色值与维度数字;结构数字(页头 z-index、模糊半径、CRUD 条内边距等)读 design 真源 kit-nine-dim.json 的 structure 节。
|
|
3
|
+
// 层级由编译期标注的 `data-kit-layer` 属性决定(surface-layers.ts 写入),这里不再按标签名 / 类名猜层级。
|
|
4
|
+
// 没有按维度取值写分支的选择器:边界、质感、圆角、密度都已经折进令牌,所以这里没有 `[data-kit-boundary=…]` 之类的规则。
|
|
5
|
+
|
|
6
|
+
import { KIT_NINE_DIM } from 'soma-foundation/kit-nine-dim';
|
|
7
|
+
|
|
8
|
+
const S = KIT_NINE_DIM.structure;
|
|
9
|
+
const L = KIT_NINE_DIM.surfaceLayers;
|
|
10
|
+
const ATTR = L.layerAttribute;
|
|
11
|
+
const LAST = L.maxDistinctDepth - 1;
|
|
12
|
+
|
|
13
|
+
const CONTAINERS = 'section, aside, article, [role="region"], [data-kit-part="card"], [data-kit-vscroll], [data-soma-component="KitTreeTable"], [data-soma-component="TreeTable"]';
|
|
14
|
+
|
|
15
|
+
/** 做毛玻璃 / 浮起阴影的最外层容器(比 CONTAINERS 少 role=region / vscroll / 树表,原因见下方规则注释) */
|
|
16
|
+
const BLUR_CONTAINERS = 'section, aside, article, [data-kit-part="card"]';
|
|
17
|
+
|
|
18
|
+
/** 层级规则:第 k 层容器的 base = 层 k,sunken = 层 k + 1(顶格夹住);浮层单独一档。 */
|
|
19
|
+
function layerRules(): string[] {
|
|
20
|
+
// 选择器带宿主前缀(特异度高于单类工具类),层级底色不被 bg-surface-sunken 之类的工具类顺序压掉
|
|
21
|
+
const rules: string[] = [];
|
|
22
|
+
for (let k = 0; k <= LAST; k++) {
|
|
23
|
+
const below = Math.min(k + 1, LAST);
|
|
24
|
+
rules.push(`[data-soma-host] [${ATTR}="${k}"] { --soma-surface-base: var(--soma-surface-layer-${k}); --soma-surface-sunken: var(--soma-surface-layer-${below}); background-color: var(--soma-surface-layer-${k}); }`);
|
|
25
|
+
}
|
|
26
|
+
rules.push(`[data-soma-host] [${ATTR}="float"] { --soma-surface-base: var(--soma-surface-float); --soma-surface-raised: var(--soma-surface-float); --soma-surface-sunken: var(--soma-surface-layer-2); background-color: var(--soma-surface-float); box-shadow: var(--soma-shadow-popover); backdrop-filter: var(--soma-texture-backdrop); -webkit-backdrop-filter: var(--soma-texture-backdrop); }`);
|
|
27
|
+
rules.push(`[data-soma-host] [${ATTR}="float"]:is([role="dialog"], [role="alertdialog"], [data-kit-part="dialog"], [data-kit-part="drawer"]) { box-shadow: var(--soma-shadow-dialog); }`);
|
|
28
|
+
return rules;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const NINE_DIM_STRUCTURE_CSS: string = [
|
|
32
|
+
...layerRules(),
|
|
33
|
+
`[data-soma-host] :is(${CONTAINERS}) { border-radius: var(--soma-radius-card); border-width: var(--soma-container-border-width); border-color: var(--soma-container-border-color); }`,
|
|
34
|
+
`[data-soma-host] :is(${CONTAINERS}):not(:focus-visible) { box-shadow: var(--soma-container-shadow); }`,
|
|
35
|
+
`[data-soma-host] [${ATTR}="2"], [data-soma-host] [${ATTR}="3"] { border-radius: var(--soma-radius-inner); }`,
|
|
36
|
+
// 质感·容器:只给「最外层」容器(section / aside / article / card)加毛玻璃与浮起阴影。
|
|
37
|
+
// 不含 [role="region"] / [data-kit-vscroll] / 树表:它们总是嵌在已经模糊的容器里,嵌套 backdrop-filter 只多一份合成开销,
|
|
38
|
+
// 还会为内部 sticky / fixed 后代新建包含块(containing block);令牌为 none 时本规则无副作用。
|
|
39
|
+
// 守卫:backdrop-filter 会让容器成为 position: fixed 后代的包含块——容器里若有 kit 在流内渲染的 fixed 元素(抽屉 / 弹层壳 / 浮动钮,
|
|
40
|
+
// 组件统一打 data-kit-fixed 标记),fixed 就会被困在容器里、不再相对视口定位。所以「内含 data-kit-fixed 的容器」不做毛玻璃(只是不模糊,
|
|
41
|
+
// 浮起阴影不受影响);经 mountKitOverlay 搬到浮层端口的元素不在容器里,不需要标记。
|
|
42
|
+
`[data-soma-host] :is(${BLUR_CONTAINERS}):not(:has([data-kit-fixed])) { backdrop-filter: var(--soma-texture-backdrop, none); -webkit-backdrop-filter: var(--soma-texture-backdrop, none); }`,
|
|
43
|
+
`[data-soma-host] :is(${BLUR_CONTAINERS}):not(:focus-visible) { box-shadow: var(--soma-container-shadow-raised); }`,
|
|
44
|
+
// 质感·画布:第 0 层就是页面框的画布元素(surface-layers 把顶层 bg-surface-sunken 的 main / div 标成 0 层),光晕画在它自己身上;
|
|
45
|
+
// background-color 仍由 layerRules 写,这里只叠 background-image,令牌为 none(实底 / 浮雕档)时无效果。
|
|
46
|
+
`[data-soma-host] [${ATTR}="0"] { background-image: var(--soma-texture-canvas-image, none); background-attachment: fixed; background-repeat: no-repeat; }`,
|
|
47
|
+
// 质感·可浮起控件 / 凹陷输入框:零特异度(整条 :where 包住),任何 Tailwind 工具类(focus-visible:ring-* / focus-within:ring-* / shadow-*)
|
|
48
|
+
// 写的 box-shadow 都比它高,焦点环永远不会被压掉(样式引擎不带 preflight、工具类不进 @layer,同为无层样式,比特异度即可)。
|
|
49
|
+
// 只认编译期 / 组件写下的 data-kit-face 标记:无底无边的幽灵钮、仅描边标签、嵌在外壳里的无边内层 input 都不带标记,不会被画出浮雕线。
|
|
50
|
+
':where([data-soma-theme-root], [data-soma-host], main) :where([data-kit-face="raised"], [data-soma-badge]) { box-shadow: var(--soma-texture-control-shadow, none); --tw-inset-shadow: var(--soma-texture-control-inset, 0 0 #0000); }',
|
|
51
|
+
':where([data-soma-theme-root], [data-soma-host], main) :where([data-kit-face="field"]) { box-shadow: var(--soma-texture-field-shadow, none); --tw-inset-shadow: var(--soma-texture-field-inset, 0 0 #0000); }',
|
|
52
|
+
// 质感·合成槽:Tailwind v4 的 shadow-* / ring-* 工具类写 box-shadow: var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow),
|
|
53
|
+
// 首项 --tw-inset-shadow(@property 声明 inherits: false、初值 0 0 #0000)正好是空槽——上面两条把质感内描线写进该槽,带常驻阴影 / 焦点环工具类的控件
|
|
54
|
+
// 就把质感线合成进自己的 box-shadow(不被工具类整条替换,也不会与上面的普通 box-shadow 双画:工具类特异度更高,只有一条生效)。
|
|
55
|
+
// 显式 inset-shadow-* 工具类也写这个变量,特异度高于本规则(零特异度),仍以工具类为准。-inset 令牌恒存在、中性值 0 0 #0000,可安全放进逗号列表。
|
|
56
|
+
// 质感·页签:页签没有稳定的「面」——静态标 data-kit-face="tab",只有选中态(aria-selected="true")才画浮雕线,无需任何 JS 切换;
|
|
57
|
+
// 仅下划线式页签(选中态无底无边)不标,不会被画出浮雕。
|
|
58
|
+
':where([data-soma-theme-root], [data-soma-host], main) :where([data-kit-face="tab"][aria-selected="true"]) { box-shadow: var(--soma-texture-control-shadow, none); --tw-inset-shadow: var(--soma-texture-control-inset, 0 0 #0000); }',
|
|
59
|
+
':where([data-soma-theme-root], [data-soma-host], main) :where([data-kit-part="control"], [data-kit-part="button"], button, [role="button"], [role="tab"], [role="combobox"], input:not([type="checkbox"]):not([type="radio"]), select):not(textarea):not([data-kit-part="textarea"]):not([role="listbox"]):not([role="menu"]):not([role="dialog"]):not([role="alertdialog"]):not([data-kit-part="dialog"]):not([data-kit-part="drawer"]):not([data-kit-part="popover"]):not([data-kit-popover]):where(.rounded, .rounded-sm, .rounded-md, [data-kit-part="control"], [data-kit-part="button"]) { border-radius: var(--soma-radius-button, var(--soma-radius-control)); }',
|
|
60
|
+
':where([data-soma-theme-root], [data-soma-host], main) :where(textarea, [data-kit-part="textarea"], [data-soma-component="Textarea"] textarea, [data-soma-component="Mentions"] textarea, [role="listbox"], [role="menu"], [role="dialog"], [role="alertdialog"], [data-kit-part="dialog"], [data-kit-part="drawer"], [data-kit-part="popover"], [data-kit-popover]) { border-radius: var(--soma-radius-card, var(--soma-radius-md)); }',
|
|
61
|
+
':where([data-soma-theme-root], [data-soma-host], main) :where(span.inline-flex.items-center, [data-soma-badge], [data-kit-part="badge"]):where(.rounded, .rounded-sm, .rounded-md, [data-kit-part="badge"]):not(.rounded-full) { border-radius: var(--soma-radius-badge, var(--soma-radius-control)); }',
|
|
62
|
+
`[data-soma-host] [id$="__crud_root"] > section:first-child { padding: ${S.crudBarPadding}; margin-bottom: ${S.crudBarMarginBottom}; background-color: var(--soma-surface-base); border-radius: var(--soma-radius-card); }`,
|
|
63
|
+
`[data-soma-host] [id$="__crud_root"] > section:first-child form { display: flex; flex-wrap: wrap; align-items: center; gap: ${S.crudBarGap}; }`,
|
|
64
|
+
'[data-soma-host] [id$="__crud_root"] section :is([role="region"], [data-kit-vscroll], [data-soma-component="KitTreeTable"], [data-soma-component="TreeTable"]) { border: none; box-shadow: none; }',
|
|
65
|
+
`[data-soma-host] table th { background-color: var(--soma-surface-sunken); color: var(--soma-text-secondary); font-weight: var(--soma-font-weight-medium); border-bottom: ${S.dividerWidth} solid var(--soma-border-divider); }`,
|
|
66
|
+
// 虚拟滚动行(滚动外壳 [data-kit-vscroll] 内)不吃这三条最小行高:它们的行高只由固定档位类(h-8 / h-10 / h-12)决定,
|
|
67
|
+
// 窗口估算与实测都以该类为准;主题最小行高若叠上去会让实际高度高于档位类、与窗口数学错位。
|
|
68
|
+
`[data-soma-host] :is(table tbody tr, [data-kit-part="table-row"]):not([data-kit-vscroll] *) { min-height: var(--soma-table-row-height); }`,
|
|
69
|
+
// 表格工具栏的逐表行高(KitTableTools.applyDensity 在 group/tbl 外壳上标 data-kit-dense / data-kit-roomy):
|
|
70
|
+
// 最小行高随外壳标记换成紧凑 / 宽松档令牌(缺令牌回落主题行高);特异度(0,3,0)高于上面的基础规则,且写在其后
|
|
71
|
+
`[data-soma-host] [data-kit-dense] :is(table tbody tr, [data-kit-part="table-row"]):not([data-kit-vscroll] *) { min-height: var(--soma-table-row-height-dense, var(--soma-table-row-height)); }`,
|
|
72
|
+
`[data-soma-host] [data-kit-roomy] :is(table tbody tr, [data-kit-part="table-row"]):not([data-kit-vscroll] *) { min-height: var(--soma-table-row-height-roomy, var(--soma-table-row-height)); }`,
|
|
73
|
+
`[data-soma-host] :is(table tbody tr, [data-kit-part="table-row"]):not(:last-child) { border-bottom: ${S.dividerWidth} solid var(--soma-border-divider); }`,
|
|
74
|
+
`[data-soma-host] [data-kit-layout-header="true"] { position: sticky; top: 0; z-index: ${S.headerStickyZ}; backdrop-filter: blur(${S.headerBlurPx}px); -webkit-backdrop-filter: blur(${S.headerBlurPx}px); border-bottom: ${S.dividerWidth} solid var(--soma-border-hairline); background-color: color-mix(in srgb, var(--soma-surface-base) ${S.headerBgPercent}%, transparent); }`,
|
|
75
|
+
'[data-soma-host] [data-kit-layout-header="true"] a:not([class*="font-semibold"]):hover { background-color: var(--soma-surface-sunken); border-radius: var(--soma-radius-control); }',
|
|
76
|
+
`[data-soma-host] [data-kit-layout-footer="true"] { border-top: ${S.dividerWidth} solid var(--soma-border-hairline); background-color: var(--soma-surface-sunken); }`,
|
|
77
|
+
].join('\n') + '\n';
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// 四层表面的编译期标注:在页面 HTML 上给「表面容器」写 `data-kit-layer`,层级由元素嵌套深度算出,不靠运行期 CSS 按标签名 / 类名猜。
|
|
2
|
+
//
|
|
3
|
+
// 规则(所有名单读 design 真源 kit-nine-dim.json#surfaceLayers,本文件只写遍历结构):
|
|
4
|
+
// · 表面容器 = 标签在 annotatableTags、类串含 bg-surface / bg-surface-sunken / bg-surface-raised 之一的元素;
|
|
5
|
+
// 输入、按钮、表格单元等叶子标签不在名单,不标注(它们的底色随最近容器的令牌走)。
|
|
6
|
+
// · 画布(层 0)= 不在任何容器内、标签在 canvasTags 且带 bg-surface-sunken 的最外层元素。
|
|
7
|
+
// · 浮层("float")= 带 bg-surface-raised 且(带 floatingClasses 里的类,或 role 在 floatingRoles,或带 floatingAttribute)的元素;
|
|
8
|
+
// 浮层内部重新计层,浮层本身按层 1 计。
|
|
9
|
+
// · 其余容器:层 = 最近的已标注祖先的层 + 1,封顶 maxDistinctDepth - 1。
|
|
10
|
+
// 标注只在编译期做一次;运行期由组件新建的 DOM(弹层、对话框)不在其中,沿用令牌表的 base / sunken / raised 三名。
|
|
11
|
+
|
|
12
|
+
import { KIT_NINE_DIM } from 'soma-foundation/kit-nine-dim';
|
|
13
|
+
|
|
14
|
+
const SL = KIT_NINE_DIM.surfaceLayers;
|
|
15
|
+
const TAGS = new Set<string>(SL.annotatableTags);
|
|
16
|
+
const CANVAS_TAGS = new Set<string>(SL.canvasTags);
|
|
17
|
+
const FLOAT_CLASSES = new Set<string>(SL.floatingClasses);
|
|
18
|
+
const FLOAT_ROLES = new Set<string>(SL.floatingRoles);
|
|
19
|
+
const VOID = new Set(['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'source', 'track', 'wbr']);
|
|
20
|
+
const RAW_TEXT = new Set(['script', 'style', 'textarea', 'title']);
|
|
21
|
+
const MAX_LAYER = SL.maxDistinctDepth - 1;
|
|
22
|
+
|
|
23
|
+
const TAG_RE = /<!--[\s\S]*?-->|<\/([A-Za-z][\w:-]*)\s*>|<([A-Za-z][\w:-]*)((?:"[^"]*"|'[^']*'|[^'">])*)>/g;
|
|
24
|
+
|
|
25
|
+
function attrOf(attrs: string, name: string): string | undefined {
|
|
26
|
+
const m = new RegExp(`(?:^|\\s)${name}\\s*=\\s*(?:"([^"]*)"|'([^']*)')`).exec(attrs);
|
|
27
|
+
if (m === null) return undefined;
|
|
28
|
+
return m[1] ?? m[2];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export type SurfaceLayer = number | 'float';
|
|
32
|
+
|
|
33
|
+
/** 一个元素该标注成什么层(纯函数,便于单测):不是表面容器返回 undefined。parentLayer = 最近已标注祖先的层数值(无祖先 = -1)。 */
|
|
34
|
+
function layerOfElement(tag: string, attrs: string, parentLayer: number): SurfaceLayer | undefined {
|
|
35
|
+
const name = tag.toLowerCase();
|
|
36
|
+
if (!TAGS.has(name)) return undefined;
|
|
37
|
+
const classes = (attrOf(attrs, 'class') ?? '').split(/\s+/).filter((c) => c !== '');
|
|
38
|
+
const isBase = classes.includes(SL.surfaceClasses.base);
|
|
39
|
+
const isSunken = classes.includes(SL.surfaceClasses.sunken);
|
|
40
|
+
const isRaised = classes.includes(SL.surfaceClasses.raised);
|
|
41
|
+
const floating = classes.some((c) => FLOAT_CLASSES.has(c)) || FLOAT_ROLES.has(attrOf(attrs, 'role') ?? '') || attrOf(attrs, SL.floatingAttribute) !== undefined;
|
|
42
|
+
if ((isRaised || attrOf(attrs, SL.floatingAttribute) !== undefined) && floating) return 'float';
|
|
43
|
+
if (!isBase && !isSunken && !isRaised) return undefined;
|
|
44
|
+
if (parentLayer < 0 && isSunken && CANVAS_TAGS.has(name)) return 0;
|
|
45
|
+
return Math.min(parentLayer + 1 < 1 ? 1 : parentLayer + 1, MAX_LAYER);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function parseExistingLayer(attr: string | undefined): number | undefined {
|
|
49
|
+
if (attr === undefined) return undefined;
|
|
50
|
+
if (attr === 'float') return 1;
|
|
51
|
+
const n = Number(attr);
|
|
52
|
+
return Number.isFinite(n) ? n : undefined;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** 给 HTML 里的表面容器写 `data-kit-layer`;已带该属性的元素不改。不改 HTML 的其余部分。 */
|
|
56
|
+
export function annotateSurfaceLayers(html: string): string {
|
|
57
|
+
const stack: { tag: string; layer: number }[] = [];
|
|
58
|
+
const parentOf = (): number => (stack.length === 0 ? -1 : stack[stack.length - 1]!.layer);
|
|
59
|
+
let out = '';
|
|
60
|
+
let last = 0;
|
|
61
|
+
let rawUntil: string | undefined;
|
|
62
|
+
TAG_RE.lastIndex = 0;
|
|
63
|
+
for (let m = TAG_RE.exec(html); m !== null; m = TAG_RE.exec(html)) {
|
|
64
|
+
const [whole, closeTag, openTag, attrs = ''] = m;
|
|
65
|
+
if (rawUntil !== undefined) {
|
|
66
|
+
if (closeTag !== undefined && closeTag.toLowerCase() === rawUntil) {
|
|
67
|
+
rawUntil = undefined;
|
|
68
|
+
} else {
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (closeTag !== undefined) {
|
|
73
|
+
const name = closeTag.toLowerCase();
|
|
74
|
+
for (let i = stack.length - 1; i >= 0; i--) {
|
|
75
|
+
if (stack[i]!.tag === name) { stack.length = i; break; }
|
|
76
|
+
}
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
if (openTag === undefined) continue; // 注释
|
|
80
|
+
const name = openTag.toLowerCase();
|
|
81
|
+
if (RAW_TEXT.has(name)) rawUntil = name;
|
|
82
|
+
const selfClosed = VOID.has(name) || attrs.trimEnd().endsWith('/');
|
|
83
|
+
const parent = parentOf();
|
|
84
|
+
const existingAttr = attrOf(attrs, SL.layerAttribute);
|
|
85
|
+
const layer = existingAttr === undefined ? layerOfElement(name, attrs, parent) : undefined;
|
|
86
|
+
if (layer !== undefined) {
|
|
87
|
+
const at = m.index + 1 + openTag.length;
|
|
88
|
+
out += html.slice(last, at) + ` ${SL.layerAttribute}="${layer}"`;
|
|
89
|
+
last = at;
|
|
90
|
+
}
|
|
91
|
+
const stackLayer = layer !== undefined
|
|
92
|
+
? (layer === 'float' ? 1 : layer)
|
|
93
|
+
: (parseExistingLayer(existingAttr) ?? parent);
|
|
94
|
+
if (!selfClosed) stack.push({ tag: name, layer: stackLayer });
|
|
95
|
+
}
|
|
96
|
+
return out + html.slice(last);
|
|
97
|
+
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// 令牌 CSS:kit.app.yaml 的 `theme` 声明 -> soma-foundation 主题流水线(意图折叠 -> 令牌求解)-> `:root` 亮色块 + 暗色块。
|
|
2
2
|
// 本文件只做序列化与取值域校验:所有令牌值由 foundation 求出,kit 不手写任何色值、字号、间距。
|
|
3
|
+
// 单一链路:只支持九维(palette 等 9 键 + mode),旧库方案链(库配色方案 / 库字体方案 / 品牌色号)已删除、不留兼容;
|
|
4
|
+
// 九维的维度折叠、覆盖步、四层表面、对比度收口在 soma-foundation/kit-nine-dim(solveNineDimTables),本文件只调它。
|
|
3
5
|
// 只在服务端 / 构建面使用(server.ts 调用);不进浏览器包。
|
|
4
6
|
//
|
|
5
7
|
// 产物(顺序固定,同输入同输出):
|
|
@@ -8,40 +10,45 @@
|
|
|
8
10
|
// light / soft 极性:只有 :root(锁亮);dark 极性::root 取暗表全量(锁暗)
|
|
9
11
|
// 暗色切换:mode 缺省 system,跟随设备偏好,也可在根元素上加类 `soma-scheme-dark` / `soma-scheme-light` 显式切换(不重编译)。
|
|
10
12
|
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
themeDeclarationOfString,
|
|
17
|
-
} from 'soma-foundation/compile';
|
|
18
|
-
import type { ScopeDeclaration, SchemeChoices, ThemeDeclaration, ThemeDiagnostic, TokenTables } from 'soma-foundation/compile';
|
|
19
|
-
import { SOMA_DESIGN_FONT_SCHEMES } from 'soma-foundation/design-data';
|
|
20
|
-
import { paletteById, selectFontScheme } from 'soma-foundation/theme';
|
|
13
|
+
import { darkSchemeRules, explicitLightSchemeRules } from 'soma-foundation/compile';
|
|
14
|
+
import type { ScopeDeclaration, ThemeDiagnostic, TokenTables } from 'soma-foundation/compile';
|
|
15
|
+
import { solveNineDimTables } from 'soma-foundation/kit-nine-dim';
|
|
16
|
+
import type { NineDimDegradation, NineDimTheme } from 'soma-foundation/kit-nine-dim';
|
|
17
|
+
export type { NineDimDegradation, NineDimTheme };
|
|
21
18
|
import type { KitDiagnostic } from '../object-renderer/types';
|
|
19
|
+
import type { KitAppTheme, KitThemeBoundary, KitThemeColorDepth, KitThemeColorSaturation, KitThemeDensity, KitThemeFontFamily, KitThemeFontScale, KitThemePalette, KitThemeShape, KitThemeSurfaceTexture } from './theme-types';
|
|
20
|
+
export * from './theme-types';
|
|
21
|
+
import { toKitRuntimeTheme } from '../shared/theme-runtime-shared';
|
|
22
|
+
import { NINE_DIM_STRUCTURE_CSS } from './nine-dim-structure';
|
|
22
23
|
|
|
23
|
-
/** kit.app.yaml 的 theme
|
|
24
|
+
/** kit.app.yaml 的 theme 段(已规整;只有九维 + mode,取值域在 solveKitTheme 里按 foundation / design 真源校验) */
|
|
24
25
|
export interface KitThemeConfig {
|
|
25
|
-
/**
|
|
26
|
-
paletteScheme?: string;
|
|
27
|
-
/** 字体方案 id 或 'auto' */
|
|
28
|
-
fontScheme?: string;
|
|
29
|
-
/** 品牌色 #rgb / #rrggbb */
|
|
30
|
-
color?: string;
|
|
31
|
-
/** 极性:light / dark / system / soft;缺省 system */
|
|
26
|
+
/** 极性:light / dark / system / soft;未显式指定时一律默认 system(跟随系统偏好) */
|
|
32
27
|
mode?: 'light' | 'dark' | 'system' | 'soft';
|
|
33
|
-
/**
|
|
34
|
-
|
|
28
|
+
/** 九维 01..09(取值域读 design 真源 kit-nine-dim.json;未写的维度取真源默认档) */
|
|
29
|
+
palette?: KitThemePalette;
|
|
30
|
+
colorDepth?: KitThemeColorDepth;
|
|
31
|
+
colorSaturation?: KitThemeColorSaturation;
|
|
32
|
+
fontFamily?: KitThemeFontFamily;
|
|
33
|
+
fontScale?: KitThemeFontScale;
|
|
34
|
+
boundary?: KitThemeBoundary;
|
|
35
|
+
shape?: KitThemeShape;
|
|
36
|
+
surfaceTexture?: KitThemeSurfaceTexture;
|
|
37
|
+
density?: KitThemeDensity;
|
|
35
38
|
}
|
|
36
39
|
|
|
37
40
|
export const KIT_THEME_MODES: readonly string[] = ['light', 'dark', 'system', 'soft'];
|
|
38
|
-
|
|
39
|
-
|
|
41
|
+
|
|
42
|
+
/** kit.app.yaml 解析后的 theme(蛇形 / 驼峰两写法并存)-> 求解入参:只带九维键与 mode */
|
|
43
|
+
export function kitThemeConfigOf(theme: KitAppTheme | KitThemeConfig): KitThemeConfig {
|
|
44
|
+
return toKitRuntimeTheme(theme) as KitThemeConfig;
|
|
45
|
+
}
|
|
40
46
|
|
|
41
47
|
export interface KitThemeTokensResult {
|
|
42
48
|
/** 令牌 CSS(失败时为空串) */
|
|
43
49
|
css: string;
|
|
44
50
|
diagnostics: KitDiagnostic[];
|
|
51
|
+
degradations?: readonly NineDimDegradation[];
|
|
45
52
|
}
|
|
46
53
|
|
|
47
54
|
function tokenBlock(selector: string, vars: Readonly<Record<string, string>>, extra: readonly string[] = []): string {
|
|
@@ -55,22 +62,10 @@ function tableDiff(base: Readonly<Record<string, string>>, next: Readonly<Record
|
|
|
55
62
|
return out;
|
|
56
63
|
}
|
|
57
64
|
|
|
58
|
-
/** 令牌表 -> CSS 文本(极性决定发哪几块,格式与 soma-
|
|
65
|
+
/** 令牌表 -> CSS 文本(极性决定发哪几块,格式与 soma-ui 同一份 foundation 规则;边框四档由 foundation 按对比目标求解,kit 不覆盖) */
|
|
59
66
|
export function serializeTokenTables(tables: TokenTables): string {
|
|
60
|
-
const light: Record<string, string> = {
|
|
61
|
-
|
|
62
|
-
'--soma-border-hairline': 'rgba(15, 23, 42, 0.08)',
|
|
63
|
-
'--soma-border-strong': 'rgba(15, 23, 42, 0.14)',
|
|
64
|
-
'--soma-border-control': 'rgba(15, 23, 42, 0.14)',
|
|
65
|
-
'--soma-border-divider': 'rgba(15, 23, 42, 0.06)',
|
|
66
|
-
};
|
|
67
|
-
const dark: Record<string, string> = {
|
|
68
|
-
...tables.dark,
|
|
69
|
-
'--soma-border-hairline': 'rgba(255, 255, 255, 0.10)',
|
|
70
|
-
'--soma-border-strong': 'rgba(255, 255, 255, 0.16)',
|
|
71
|
-
'--soma-border-control': 'rgba(255, 255, 255, 0.14)',
|
|
72
|
-
'--soma-border-divider': 'rgba(255, 255, 255, 0.07)',
|
|
73
|
-
};
|
|
67
|
+
const light: Record<string, string> = { ...tables.light };
|
|
68
|
+
const dark: Record<string, string> = { ...tables.dark };
|
|
74
69
|
if (tables.polarity === 'dark') return tokenBlock(':root', dark, ['color-scheme: dark;']);
|
|
75
70
|
const parts = [tokenBlock(':root', light, ['color-scheme: light;'])];
|
|
76
71
|
const darkOnly = tableDiff(light, dark);
|
|
@@ -92,64 +87,75 @@ function fromThemeDiagnostics(list: readonly ThemeDiagnostic[]): KitDiagnostic[]
|
|
|
92
87
|
.map((d) => themeDiag('KIT-APP-003', 'kit.app.yaml.theme', `${d.code}:${d.message}${d.fix !== undefined && d.fix.length > 0 ? `;修法:${d.fix.join(';')}` : ''}`));
|
|
93
88
|
}
|
|
94
89
|
|
|
95
|
-
/** 求解令牌表(不序列化;测试与 explain
|
|
90
|
+
/** 求解令牌表(不序列化;测试与 explain 可单独用)。只走九维:空配置或只写 mode 时其余维度取 design 真源默认档 */
|
|
96
91
|
export function solveKitTheme(
|
|
97
92
|
theme: KitThemeConfig | undefined,
|
|
98
93
|
locale?: string,
|
|
99
94
|
/** 页面 / 产品块级主题的作用域声明(block-theme.ts 读出);求解结果在 `tables.scopes` */
|
|
100
95
|
blockScopes: readonly ScopeDeclaration[] = [],
|
|
101
|
-
): { tables?: TokenTables; diagnostics: KitDiagnostic[] } {
|
|
96
|
+
): { tables?: TokenTables; diagnostics: KitDiagnostic[]; degradations?: readonly NineDimDegradation[] } {
|
|
102
97
|
const cfg = theme ?? {};
|
|
103
|
-
const diagnostics: KitDiagnostic[] = [];
|
|
104
|
-
if (cfg.paletteScheme !== undefined && paletteById(cfg.paletteScheme) === undefined) {
|
|
105
|
-
diagnostics.push(themeDiag('KIT-APP-002', 'kit.app.yaml.theme.palette_scheme', `palette_scheme「${cfg.paletteScheme}」不是配色方案库里的方案 id`));
|
|
106
|
-
}
|
|
107
|
-
if (cfg.fontScheme !== undefined && cfg.fontScheme !== 'auto' && !Object.prototype.hasOwnProperty.call(SOMA_DESIGN_FONT_SCHEMES, cfg.fontScheme)) {
|
|
108
|
-
diagnostics.push(themeDiag('KIT-APP-002', 'kit.app.yaml.theme.font_scheme', `font_scheme「${cfg.fontScheme}」既不是 auto 也不是字体方案库里的方案 id`));
|
|
109
|
-
}
|
|
110
|
-
if (cfg.color !== undefined && !HEX.test(cfg.color)) {
|
|
111
|
-
diagnostics.push(themeDiag('KIT-APP-002', 'kit.app.yaml.theme.color', `color「${cfg.color}」必须是 #rgb / #rrggbb 品牌色号`));
|
|
112
|
-
}
|
|
113
98
|
if (cfg.mode !== undefined && !KIT_THEME_MODES.includes(cfg.mode)) {
|
|
114
|
-
diagnostics
|
|
99
|
+
return { diagnostics: [themeDiag('KIT-APP-002', 'kit.app.yaml.theme.mode', `mode「${String(cfg.mode)}」只能是 ${KIT_THEME_MODES.join(' / ')}`)] };
|
|
115
100
|
}
|
|
116
|
-
|
|
117
|
-
|
|
101
|
+
// 当 mode 未显式指定时,一律默认 mode: 'system'(跟随系统偏好)
|
|
102
|
+
const nineDimInput: NineDimTheme = cfg.mode === undefined
|
|
103
|
+
? { ...(cfg as NineDimTheme), mode: 'system' }
|
|
104
|
+
: (cfg as NineDimTheme);
|
|
105
|
+
const solved = solveNineDimTables(nineDimInput, { ...(locale === undefined ? {} : { locale }), blockScopes });
|
|
106
|
+
if (!solved.ok) {
|
|
107
|
+
const detail = fromThemeDiagnostics(solved.diagnostics);
|
|
108
|
+
const problems = detail.length > 0 ? detail : solved.problems.map((p) => themeDiag('KIT-APP-002', 'kit.app.yaml.theme', p));
|
|
109
|
+
return { diagnostics: problems };
|
|
118
110
|
}
|
|
119
|
-
|
|
111
|
+
const degradations: NineDimDegradation[] = solved.degradations.map((d) =>
|
|
112
|
+
d.rule === 'borderless-needs-layer-separation' && !d.detail.includes('BORDERLESS_SHADOW')
|
|
113
|
+
? { ...d, detail: `无边框档(BORDERLESS_SHADOW)${d.detail}` }
|
|
114
|
+
: d,
|
|
115
|
+
);
|
|
116
|
+
return { tables: solved.tables, diagnostics: [], degradations };
|
|
117
|
+
}
|
|
120
118
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
: selectFontScheme({ ...(cfg.fontScheme === 'auto' ? {} : { explicit: cfg.fontScheme }), ...(locale === undefined ? {} : { locale }) }).id;
|
|
125
|
-
const schemes: SchemeChoices | undefined = palette === undefined && fontSchemeId === undefined
|
|
126
|
-
? undefined
|
|
127
|
-
: {
|
|
128
|
-
...(palette === undefined ? {} : { palette }),
|
|
129
|
-
...(palette !== undefined && cfg.color !== undefined ? { brandHex: cfg.color } : {}),
|
|
130
|
-
...(fontSchemeId === undefined ? {} : { fontSchemeId }),
|
|
131
|
-
};
|
|
119
|
+
function formatOneDegradation(d: NineDimDegradation): string {
|
|
120
|
+
return `[KIT-THEME-004] (${d.rule}/${d.scheme}) ${d.detail}`;
|
|
121
|
+
}
|
|
132
122
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
123
|
+
function isDegradationItem(x: unknown): x is NineDimDegradation {
|
|
124
|
+
return (
|
|
125
|
+
x !== null &&
|
|
126
|
+
typeof x === 'object' &&
|
|
127
|
+
typeof (x as NineDimDegradation).rule === 'string' &&
|
|
128
|
+
typeof (x as NineDimDegradation).detail === 'string'
|
|
129
|
+
);
|
|
130
|
+
}
|
|
138
131
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
132
|
+
/**
|
|
133
|
+
* 格式化九维主题降级提示:
|
|
134
|
+
* - 传入单条 NineDimDegradation 或 NineDimDegradation[] 时,将其格式化为中文诊断行数组;
|
|
135
|
+
* - 传入 theme 配置对象(支持 snake_case 与 camelCase)时,求解其九维降级项并返回中文诊断行数组。
|
|
136
|
+
*/
|
|
137
|
+
export function formatKitThemeDegradation(themeOrDegradation: unknown): string[] {
|
|
138
|
+
if (themeOrDegradation === null || themeOrDegradation === undefined || typeof themeOrDegradation !== 'object') {
|
|
139
|
+
return [];
|
|
146
140
|
}
|
|
147
|
-
|
|
141
|
+
if (Array.isArray(themeOrDegradation)) {
|
|
142
|
+
return themeOrDegradation.flatMap((item) => formatKitThemeDegradation(item));
|
|
143
|
+
}
|
|
144
|
+
if (isDegradationItem(themeOrDegradation)) {
|
|
145
|
+
return [formatOneDegradation(themeOrDegradation)];
|
|
146
|
+
}
|
|
147
|
+
const cfg = kitThemeConfigOf(themeOrDegradation as KitAppTheme | KitThemeConfig);
|
|
148
|
+
const solved = solveKitTheme(cfg);
|
|
149
|
+
return (solved.degradations ?? []).map(formatOneDegradation);
|
|
148
150
|
}
|
|
149
151
|
|
|
150
|
-
/** 一站式:theme 声明 -> 令牌 CSS(拼在 kit
|
|
152
|
+
/** 一站式:theme 声明 -> 令牌 CSS(拼在 kit 主题头前面交样式引擎);九维主题另附结构 CSS(只引令牌,不含数字) */
|
|
151
153
|
export function resolveKitThemeTokens(theme: KitThemeConfig | undefined, locale?: string): KitThemeTokensResult {
|
|
152
154
|
const solved = solveKitTheme(theme, locale);
|
|
153
155
|
if (solved.tables === undefined) return { css: '', diagnostics: solved.diagnostics };
|
|
154
|
-
return {
|
|
156
|
+
return {
|
|
157
|
+
css: `${serializeTokenTables(solved.tables)}\n${NINE_DIM_STRUCTURE_CSS}`,
|
|
158
|
+
diagnostics: [],
|
|
159
|
+
...(solved.degradations !== undefined && solved.degradations.length > 0 ? { degradations: solved.degradations } : {}),
|
|
160
|
+
};
|
|
155
161
|
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// 九维取值域只在 soma-design/spec/pipeline/kit-nine-dim.json 声明一处(经 soma-foundation/kit-limits 的 KIT_NINE_DIM_DOMAINS 投影),
|
|
2
|
+
// 类型与运行期数组都从它派生,这里不再手抄枚举。
|
|
3
|
+
|
|
4
|
+
import { KIT_NINE_DIM_DOMAINS } from 'soma-foundation/kit-limits';
|
|
5
|
+
|
|
6
|
+
type Domains = typeof KIT_NINE_DIM_DOMAINS;
|
|
7
|
+
|
|
8
|
+
/** 01 · 主题配色枚举(24 套全行业手调配色) */
|
|
9
|
+
export type KitThemePalette = Domains['palette'][number];
|
|
10
|
+
export const KIT_THEME_PALETTES: readonly KitThemePalette[] = KIT_NINE_DIM_DOMAINS.palette;
|
|
11
|
+
|
|
12
|
+
/** 02 · 颜色深浅枚举(5 档:很淡 / 略淡 / 标准 / 略深 / 很深) */
|
|
13
|
+
export type KitThemeColorDepth = Domains['colorDepth'][number];
|
|
14
|
+
export const KIT_THEME_COLOR_DEPTHS: readonly KitThemeColorDepth[] = KIT_NINE_DIM_DOMAINS.colorDepth;
|
|
15
|
+
|
|
16
|
+
/** 03 · 颜色鲜艳度枚举(4 档,品牌色彩度倍率) */
|
|
17
|
+
export type KitThemeColorSaturation = Domains['colorSaturation'][number];
|
|
18
|
+
export const KIT_THEME_COLOR_SATURATIONS: readonly KitThemeColorSaturation[] = KIT_NINE_DIM_DOMAINS.colorSaturation;
|
|
19
|
+
|
|
20
|
+
/** 04 · 字体类型枚举(6 种) */
|
|
21
|
+
export type KitThemeFontFamily = Domains['fontFamily'][number];
|
|
22
|
+
export const KIT_THEME_FONT_FAMILIES: readonly KitThemeFontFamily[] = KIT_NINE_DIM_DOMAINS.fontFamily;
|
|
23
|
+
|
|
24
|
+
/** 05 · 字体大小与行距枚举(4 档,最小字号不低于 12px 底线) */
|
|
25
|
+
export type KitThemeFontScale = Domains['fontScale'][number];
|
|
26
|
+
export const KIT_THEME_FONT_SCALES: readonly KitThemeFontScale[] = KIT_NINE_DIM_DOMAINS.fontScale;
|
|
27
|
+
|
|
28
|
+
/** 06 · 组件边界方案枚举(严格二选一) */
|
|
29
|
+
export type KitThemeBoundary = Domains['boundary'][number];
|
|
30
|
+
export const KIT_THEME_BOUNDARIES: readonly KitThemeBoundary[] = KIT_NINE_DIM_DOMAINS.boundary;
|
|
31
|
+
|
|
32
|
+
/** 07 · 组件圆角与形状枚举(4 档;语义圆形部件不随它变) */
|
|
33
|
+
export type KitThemeShape = Domains['shape'][number];
|
|
34
|
+
export const KIT_THEME_SHAPES: readonly KitThemeShape[] = KIT_NINE_DIM_DOMAINS.shape;
|
|
35
|
+
|
|
36
|
+
/** 08 · 组件表面质感枚举(3 档) */
|
|
37
|
+
export type KitThemeSurfaceTexture = Domains['surfaceTexture'][number];
|
|
38
|
+
export const KIT_THEME_SURFACE_TEXTURES: readonly KitThemeSurfaceTexture[] = KIT_NINE_DIM_DOMAINS.surfaceTexture;
|
|
39
|
+
|
|
40
|
+
/** 09 · 空间松紧度枚举(3 档,驱动控件高度与间距单位) */
|
|
41
|
+
export type KitThemeDensity = Domains['density'][number];
|
|
42
|
+
export const KIT_THEME_DENSITIES: readonly KitThemeDensity[] = KIT_NINE_DIM_DOMAINS.density;
|
|
43
|
+
|
|
44
|
+
/** kit.app.yaml 的 theme 段(9 维正交页面主题 DSL 规格 + 基础编译可选兼容字段) */
|
|
45
|
+
export interface KitAppTheme {
|
|
46
|
+
/** 01 · 主题配色枚举(24 套全行业主题配色) */
|
|
47
|
+
palette?: KitThemePalette;
|
|
48
|
+
/** 02 · 颜色深浅枚举(5 档) */
|
|
49
|
+
color_depth?: KitThemeColorDepth;
|
|
50
|
+
colorDepth?: KitThemeColorDepth;
|
|
51
|
+
/** 03 · 颜色鲜艳度枚举(4 档) */
|
|
52
|
+
color_saturation?: KitThemeColorSaturation;
|
|
53
|
+
colorSaturation?: KitThemeColorSaturation;
|
|
54
|
+
/** 04 · 字体类型枚举(6 种) */
|
|
55
|
+
font_family?: KitThemeFontFamily;
|
|
56
|
+
fontFamily?: KitThemeFontFamily;
|
|
57
|
+
/** 05 · 字体大小与行距枚举(4 档) */
|
|
58
|
+
font_scale?: KitThemeFontScale;
|
|
59
|
+
fontScale?: KitThemeFontScale;
|
|
60
|
+
/** 06 · 组件边界方案枚举(严格二选一) */
|
|
61
|
+
boundary?: KitThemeBoundary;
|
|
62
|
+
/** 07 · 组件圆角与形状枚举(4 档) */
|
|
63
|
+
shape?: KitThemeShape;
|
|
64
|
+
/** 08 · 组件表面质感枚举(3 档) */
|
|
65
|
+
surface_texture?: KitThemeSurfaceTexture;
|
|
66
|
+
surfaceTexture?: KitThemeSurfaceTexture;
|
|
67
|
+
/** 09 · 空间松紧度枚举(3 档) */
|
|
68
|
+
density?: KitThemeDensity;
|
|
69
|
+
/** 极性:light / dark / system / soft */
|
|
70
|
+
mode?: string;
|
|
71
|
+
}
|