soma-kit 0.1.11 → 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 -1473
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
// 服务端分页适配(P1,服务端薄壳用,纯函数、无 node 依赖):kit 列表的页码协议 <-> 旧后台的分页与信封。
|
|
2
|
+
//
|
|
3
|
+
// kit 列表对象以 `GET ?pageNo=&pageSize=&<筛选字段>=…` 读数据(参数名可由 behavior.list 的 pageParam / sizeParam 改;
|
|
4
|
+
// 筛选字段名就是 schema 字段名,空值不带),期望响应 `{ rows, total }`(缺省 listShape)。旧后台常见三种不一样:
|
|
5
|
+
// 1 后端页码键叫 page / pageNum,页长叫 size / limit,筛选参数名与字段名不同 -> createPagedListAdapter 的 upstream* 与 filterMap;
|
|
6
|
+
// 2 响应是业务信封(失败判定 / 数据位置由 kit.app.yaml 的 envelope 声明),列表键与总数键不统一 -> unwrapBizEnvelope + 适配器的 rowsPath / totalPaths;
|
|
7
|
+
// 3 游标分页(cursor / limit / nextCursor),没有页码 -> cursorPageWindow(沿游标走到第 N 页)。
|
|
8
|
+
// 这里只做形状翻译,不碰业务、不发请求(请求由调用方的 load 函数发)。数字(缺省页长 / 页长上限 / 信封嵌套层数)读 design 的 kit-limits。
|
|
9
|
+
|
|
10
|
+
import { KIT_DATA_LIMITS } from 'soma-foundation/kit-limits';
|
|
11
|
+
import { isEnvelopeFailure, unwrapEnvelope, type KitEnvelope, type UnwrappedEnvelope } from './envelope';
|
|
12
|
+
|
|
13
|
+
type Rec = Record<string, unknown>;
|
|
14
|
+
const LIMITS = (KIT_DATA_LIMITS as unknown as { pagedList: { pageSizeDefault: number; pageSizeMax: number; unwrapDepth: number } }).pagedList;
|
|
15
|
+
|
|
16
|
+
const isRec = (v: unknown): v is Rec => typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
17
|
+
|
|
18
|
+
/** kit 列表请求里唯一的页码键与页长键;其余键都当筛选(外部后端的参数名由 upstreamPage / upstreamSize 显式配置) */
|
|
19
|
+
const KIT_PAGE_KEY = 'pageNo';
|
|
20
|
+
const KIT_SIZE_KEY = 'pageSize';
|
|
21
|
+
const RESERVED: ReadonlySet<string> = new Set([KIT_PAGE_KEY, KIT_SIZE_KEY, 'window', 'sort', 'order']);
|
|
22
|
+
const DEFAULT_ROW_KEYS: readonly string[] = ['list', 'records', 'rows', 'items', 'data'];
|
|
23
|
+
const DEFAULT_TOTAL_PATHS: readonly string[] = ['totalCount', 'total', 'count'];
|
|
24
|
+
|
|
25
|
+
function positiveInt(raw: unknown): number | null {
|
|
26
|
+
const n = typeof raw === 'number' ? raw : typeof raw === 'string' && raw.trim() !== '' ? Number(raw) : Number.NaN;
|
|
27
|
+
return Number.isInteger(n) && n > 0 ? n : null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function pathGet(root: unknown, path: string): unknown {
|
|
31
|
+
let cur = root;
|
|
32
|
+
for (const key of path.split('.')) {
|
|
33
|
+
if (!isRec(cur)) return undefined;
|
|
34
|
+
cur = cur[key];
|
|
35
|
+
}
|
|
36
|
+
return cur;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// ---------------------------------------------------------------- 业务信封
|
|
40
|
+
|
|
41
|
+
export type { UnwrappedEnvelope };
|
|
42
|
+
|
|
43
|
+
/** 响应是业务错误信封:命中应用声明的 failWhen(kit.app.yaml 的 envelope;由调用方显式传入,没传按无信封判定,不读任何全局) */
|
|
44
|
+
export function isBizFailure(raw: unknown, env?: KitEnvelope): raw is Rec {
|
|
45
|
+
return isEnvelopeFailure(raw, env);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* 拆业务信封:失败信封原样放进 `error`(调用方应把它直接回给浏览器,不要再包成成功的列表);
|
|
50
|
+
* 成功则按 envelope.dataPath 取数据(没声明不拆)。写死的 success / ret / data 约定已删,全部来自声明。
|
|
51
|
+
*/
|
|
52
|
+
export function unwrapBizEnvelope(raw: unknown, env?: KitEnvelope): UnwrappedEnvelope {
|
|
53
|
+
return unwrapEnvelope(raw, env);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// ---------------------------------------------------------------- 页码协议适配器
|
|
57
|
+
|
|
58
|
+
export interface PagedListAdapterOptions {
|
|
59
|
+
/** 上游页码参数名(缺省 page) */
|
|
60
|
+
upstreamPage?: string;
|
|
61
|
+
/** 上游页长参数名(缺省 pageSize) */
|
|
62
|
+
upstreamSize?: string;
|
|
63
|
+
/** 响应里行数组的位置:点路径(相对拆信封后的 data),或候选键列表(取第一个数组);缺省 list / records / rows / items / data */
|
|
64
|
+
rowsPath?: string | readonly string[];
|
|
65
|
+
/** 总数的候选位置(相对拆信封后的 data);缺省 totalCount / total / count */
|
|
66
|
+
totalPaths?: readonly string[];
|
|
67
|
+
/** 筛选参数:kit 字段名 -> 上游参数名;数组 = 同名透传的白名单;缺省收全部非保留参数同名透传 */
|
|
68
|
+
filterMap?: Readonly<Record<string, string>> | readonly string[];
|
|
69
|
+
/** 给行补主键 id:依次取这些键里第一个非空值(已有非空 id 不动) */
|
|
70
|
+
rowId?: string | readonly string[];
|
|
71
|
+
/** 缺省页长 / 页长上限(缺省读 kit-limits) */
|
|
72
|
+
defaultPageSize?: number;
|
|
73
|
+
maxPageSize?: number;
|
|
74
|
+
/** 业务信封约定(服务端薄壳从装配对象 appContext.envelope 取来显式传入;缺省按无信封处理,不读任何全局) */
|
|
75
|
+
envelope?: KitEnvelope;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface PagedQuery {
|
|
79
|
+
/** 从 1 起 */
|
|
80
|
+
page: number;
|
|
81
|
+
pageSize: number;
|
|
82
|
+
/** kit 字段名 -> 值(已去空白,空值不进) */
|
|
83
|
+
filters: Record<string, string>;
|
|
84
|
+
/** 可直接拼到上游请求的参数:页码、页长、已改名的筛选 */
|
|
85
|
+
upstream: Record<string, string | number>;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface PagedList {
|
|
89
|
+
rows: Rec[];
|
|
90
|
+
total: number;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export interface PagedListAdapter {
|
|
94
|
+
/** 请求里没有页码键 = 旧调用方(调用方可据此原样转交旧服务) */
|
|
95
|
+
hasPage(input: unknown): boolean;
|
|
96
|
+
readQuery(input: unknown): PagedQuery;
|
|
97
|
+
/** 上游响应 -> kit 列表;失败信封返回 { error } */
|
|
98
|
+
toList(raw: unknown, mapRow?: (row: Rec, index: number) => Rec): PagedList | { error: Rec };
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function entriesOf(input: unknown): Array<[string, unknown]> {
|
|
102
|
+
if (input instanceof URLSearchParams) return [...input.entries()];
|
|
103
|
+
if (typeof input === 'string') return [...new URLSearchParams(input.includes('?') ? input.slice(input.indexOf('?') + 1) : input).entries()];
|
|
104
|
+
if (isRec(input)) return Object.entries(input);
|
|
105
|
+
return [];
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function rowsOf(data: unknown, rowsPath: string | readonly string[] | undefined): Rec[] {
|
|
109
|
+
let list: unknown;
|
|
110
|
+
if (Array.isArray(data)) list = data;
|
|
111
|
+
else if (typeof rowsPath === 'string') list = pathGet(data, rowsPath);
|
|
112
|
+
else list = (rowsPath ?? DEFAULT_ROW_KEYS).map((key) => (isRec(data) ? data[key] : undefined)).find(Array.isArray);
|
|
113
|
+
return Array.isArray(list) ? list.filter(isRec) : [];
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function totalOf(data: unknown, paths: readonly string[], fallback: number): number {
|
|
117
|
+
for (const path of paths) {
|
|
118
|
+
const v = pathGet(data, path);
|
|
119
|
+
if (typeof v === 'number' && Number.isFinite(v)) return v;
|
|
120
|
+
if (typeof v === 'string' && v.trim() !== '' && Number.isFinite(Number(v))) return Number(v);
|
|
121
|
+
}
|
|
122
|
+
return fallback;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** 给行补主键:id 缺省时依次取 keys 里第一个非空值(字符串化),已有非空 id 不动 */
|
|
126
|
+
export function withRowId(row: Rec, keys: string | readonly string[]): Rec {
|
|
127
|
+
if (typeof row.id === 'string' && row.id !== '') return row;
|
|
128
|
+
if (typeof row.id === 'number') return { ...row, id: String(row.id) };
|
|
129
|
+
for (const key of typeof keys === 'string' ? [keys] : keys) {
|
|
130
|
+
const v = row[key];
|
|
131
|
+
if (typeof v === 'string' && v.trim() !== '') return { ...row, id: v.trim() };
|
|
132
|
+
if (typeof v === 'number') return { ...row, id: String(v) };
|
|
133
|
+
}
|
|
134
|
+
return { ...row, id: '' };
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export function createPagedListAdapter(options: PagedListAdapterOptions = {}): PagedListAdapter {
|
|
138
|
+
const upstreamPage = options.upstreamPage ?? 'page';
|
|
139
|
+
const upstreamSize = options.upstreamSize ?? 'pageSize';
|
|
140
|
+
const totalPaths = options.totalPaths ?? DEFAULT_TOTAL_PATHS;
|
|
141
|
+
const defaultSize = options.defaultPageSize ?? LIMITS.pageSizeDefault;
|
|
142
|
+
const maxSize = options.maxPageSize ?? LIMITS.pageSizeMax;
|
|
143
|
+
const filterMap = options.filterMap;
|
|
144
|
+
const filterName = (key: string): string | null => {
|
|
145
|
+
if (filterMap === undefined) return key;
|
|
146
|
+
if (Array.isArray(filterMap)) return filterMap.includes(key) ? key : null;
|
|
147
|
+
const mapped = (filterMap as Readonly<Record<string, string>>)[key];
|
|
148
|
+
return mapped === undefined ? null : mapped;
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
return {
|
|
152
|
+
hasPage(input) {
|
|
153
|
+
return entriesOf(input).some(([k, v]) => k === KIT_PAGE_KEY && positiveInt(v) !== null);
|
|
154
|
+
},
|
|
155
|
+
readQuery(input) {
|
|
156
|
+
const entries = entriesOf(input);
|
|
157
|
+
const pick = (key: string): number | null => {
|
|
158
|
+
const hit = entries.find(([k]) => k === key);
|
|
159
|
+
return hit === undefined ? null : positiveInt(hit[1]);
|
|
160
|
+
};
|
|
161
|
+
const page = pick(KIT_PAGE_KEY) ?? 1;
|
|
162
|
+
const pageSize = Math.min(pick(KIT_SIZE_KEY) ?? defaultSize, maxSize);
|
|
163
|
+
const filters: Record<string, string> = {};
|
|
164
|
+
const upstream: Record<string, string | number> = { [upstreamPage]: page, [upstreamSize]: pageSize };
|
|
165
|
+
for (const [key, value] of entries) {
|
|
166
|
+
if (RESERVED.has(key) || value === undefined || value === null) continue;
|
|
167
|
+
const text = String(value).trim();
|
|
168
|
+
const target = filterName(key);
|
|
169
|
+
if (text === '' || target === null) continue;
|
|
170
|
+
filters[key] = text;
|
|
171
|
+
upstream[target] = text;
|
|
172
|
+
}
|
|
173
|
+
return { page, pageSize, filters, upstream };
|
|
174
|
+
},
|
|
175
|
+
toList(raw, mapRow) {
|
|
176
|
+
const unwrapped = unwrapBizEnvelope(raw, options.envelope);
|
|
177
|
+
if (!unwrapped.ok) return { error: unwrapped.error };
|
|
178
|
+
let rows = rowsOf(unwrapped.data, options.rowsPath);
|
|
179
|
+
if (options.rowId !== undefined) rows = rows.map((r) => withRowId(r, options.rowId!));
|
|
180
|
+
if (mapRow !== undefined) rows = rows.map(mapRow);
|
|
181
|
+
return { rows, total: totalOf(unwrapped.data, totalPaths, rows.length) };
|
|
182
|
+
},
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// ---------------------------------------------------------------- 游标分页
|
|
187
|
+
|
|
188
|
+
export type CursorLoader = (query: { cursor?: string; limit: number }) => Promise<unknown>;
|
|
189
|
+
|
|
190
|
+
export interface CursorPageOptions<T> {
|
|
191
|
+
load: CursorLoader;
|
|
192
|
+
/** 响应里行数组的键(缺省 rows) */
|
|
193
|
+
rowsKey?: string;
|
|
194
|
+
/** 响应里总数的键(缺省 total) */
|
|
195
|
+
totalKey?: string;
|
|
196
|
+
/** 响应里下一页游标的键(缺省 nextCursor) */
|
|
197
|
+
nextKey?: string;
|
|
198
|
+
parse?: (raw: unknown) => T;
|
|
199
|
+
/** 目标页(从 1 起)与页长 */
|
|
200
|
+
page: number;
|
|
201
|
+
pageSize: number;
|
|
202
|
+
/** 出错信息前缀(如「接口目录」) */
|
|
203
|
+
label: string;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export interface CursorPageResult<T> {
|
|
207
|
+
rows: T[];
|
|
208
|
+
total: number;
|
|
209
|
+
/** 最后一次取到的原始响应(调用方要读其它字段,如 snapshotVersion);页号超过末页时是末页那次的响应 */
|
|
210
|
+
raw: Rec | null;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* 沿游标走到第 page 页,返回该页行与总数;页号超过末页返回空行(total 仍真实)。
|
|
215
|
+
* 响应结构非法(行不是数组、总数不是非负整数、行数超过页长)抛错,不静默截断;游标重复也抛错(防死循环)。
|
|
216
|
+
*/
|
|
217
|
+
export async function cursorPageWindow<T = unknown>(options: CursorPageOptions<T>): Promise<CursorPageResult<T>> {
|
|
218
|
+
const { load, page, pageSize, label } = options;
|
|
219
|
+
const rowsKey = options.rowsKey ?? 'rows';
|
|
220
|
+
const totalKey = options.totalKey ?? 'total';
|
|
221
|
+
const nextKey = options.nextKey ?? 'nextCursor';
|
|
222
|
+
const parse = options.parse ?? ((raw: unknown) => raw as T);
|
|
223
|
+
let cursor: string | undefined;
|
|
224
|
+
const seen = new Set<string>();
|
|
225
|
+
let total = 0;
|
|
226
|
+
for (let current = 1; current <= page; current += 1) {
|
|
227
|
+
const response = await load({ ...(cursor !== undefined ? { cursor } : {}), limit: pageSize });
|
|
228
|
+
if (!isRec(response)) throw new Error(`${label}分页响应结构非法`);
|
|
229
|
+
const result: Rec = response;
|
|
230
|
+
const raw = result[rowsKey];
|
|
231
|
+
total = Number(result[totalKey]);
|
|
232
|
+
if (!Array.isArray(raw) || !Number.isSafeInteger(total) || total < 0 || raw.length > pageSize) throw new Error(`${label}分页响应结构非法`);
|
|
233
|
+
if (current === page) return { rows: raw.map(parse), total, raw: result };
|
|
234
|
+
const next = typeof result[nextKey] === 'string' ? (result[nextKey] as string).trim() : '';
|
|
235
|
+
if (next === '' || next === cursor || seen.has(next)) return { rows: [], total, raw: result };
|
|
236
|
+
seen.add(next);
|
|
237
|
+
cursor = next;
|
|
238
|
+
}
|
|
239
|
+
return { rows: [], total, raw: null };
|
|
240
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import type { KitDiagnostic } from '../object-renderer/types';
|
|
2
|
+
|
|
3
|
+
/** 纯路径校验:浏览器入口仅依赖该小模块,不导入 Node、扫描器或语法真源。 */
|
|
4
|
+
const CONTROL_CHAR_PATTERN = /[\u0000-\u001f\u007f-\u009f]/;
|
|
5
|
+
const EXTERNAL_HREF_PATTERN = /^(?:https?:\/\/|mailto:|tel:|#)/i;
|
|
6
|
+
const WINDOWS_DRIVE_PATTERN = /^[A-Za-z]:[\\/]/;
|
|
7
|
+
const FILE_SCHEME_PATTERN = /^file:/i;
|
|
8
|
+
const UNC_PATTERN = /^(?:\\\\|\/\/)/;
|
|
9
|
+
const PROTOCOL_RELATIVE_PATTERN = /^[/\\][\s\u0000-\u001f\u007f]*[/\\]/;
|
|
10
|
+
|
|
11
|
+
export interface PathCheckOptions {
|
|
12
|
+
/** 是否允许纯 query 传参形式(如 ?id=1) */
|
|
13
|
+
allowQueryOnly?: boolean;
|
|
14
|
+
/** 是否允许相对应用根的无前缀配置子路径(如 style: 'theme/custom.css') */
|
|
15
|
+
allowConfigSubpath?: boolean;
|
|
16
|
+
/** 是否允许外部超链接(如 https://, mailto:, tel:, #) */
|
|
17
|
+
allowExternalHref?: boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** 兼容旧 helper:只识别 URL 语境下无歧义的非站内形态;单斜杠路由必须由语境校验。 */
|
|
21
|
+
export function isSystemAbsolutePath(val: string): boolean {
|
|
22
|
+
const trimmed = val.trim();
|
|
23
|
+
return /^[A-Za-z]:[\\/]/.test(trimmed) || /^\\\\|^\/\/|^file:/i.test(trimmed);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function pathnameOf(value: string): string {
|
|
27
|
+
const query = value.indexOf('?');
|
|
28
|
+
const hash = value.indexOf('#');
|
|
29
|
+
const end = query < 0 ? hash : hash < 0 ? query : Math.min(query, hash);
|
|
30
|
+
return end < 0 ? value : value.slice(0, end);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** 编码约束只应用于 pathname/config path,不应用于 query 或 hash 的值。 */
|
|
34
|
+
function hasSafeEncodedSegments(pathname: string, allowEncodedSeparator = false): boolean {
|
|
35
|
+
const badEscape = allowEncodedSeparator ? /%(?:0[0-9a-f]|1[0-9a-f]|7f)/i : /%(?:2f|5c|0[0-9a-f]|1[0-9a-f]|7f)/i;
|
|
36
|
+
if (/%(?![0-9a-f]{2})/i.test(pathname) || badEscape.test(pathname)) return false;
|
|
37
|
+
for (const segment of pathname.split('/')) {
|
|
38
|
+
let decoded: string;
|
|
39
|
+
try {
|
|
40
|
+
decoded = decodeURIComponent(segment);
|
|
41
|
+
} catch {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
if (decoded === '.' || decoded === '..' || CONTROL_CHAR_PATTERN.test(decoded) || (!allowEncodedSeparator && (decoded.includes('/') || decoded.includes('\\')))) return false;
|
|
45
|
+
}
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function isSafeInternalPath(value: string): boolean {
|
|
50
|
+
const pathname = pathnameOf(value);
|
|
51
|
+
if (!value.startsWith('/') || value.startsWith('//') || pathname.includes('\\') || PROTOCOL_RELATIVE_PATTERN.test(pathname)) return false;
|
|
52
|
+
if (!pathname.startsWith('/') || pathname.startsWith('//') || /(?:^|\/)\.{1,2}(?:\/|$)/.test(pathname)) return false;
|
|
53
|
+
return hasSafeEncodedSegments(pathname);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function isSafeConfigSubpath(value: string): boolean {
|
|
57
|
+
if (value === '' || value.startsWith('/') || value.includes('\\') || WINDOWS_DRIVE_PATTERN.test(value) || UNC_PATTERN.test(value) || FILE_SCHEME_PATTERN.test(value)) return false;
|
|
58
|
+
if (value.includes('?') || value.includes('#') || /(?:^|\/)\.{1,2}(?:\/|$)/.test(value)) return false;
|
|
59
|
+
return hasSafeEncodedSegments(value);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function isSafeExternalHref(value: string): boolean {
|
|
63
|
+
if (!EXTERNAL_HREF_PATTERN.test(value) || FILE_SCHEME_PATTERN.test(value) || WINDOWS_DRIVE_PATTERN.test(value) || UNC_PATTERN.test(value) || pathnameOf(value).includes('\\')) return false;
|
|
64
|
+
if (!/^https?:\/\//i.test(value)) return true;
|
|
65
|
+
const match = /^https?:\/\/[^/?#]+(\/[^?#]*)?(?:[?#]|$)/i.exec(value);
|
|
66
|
+
// 外部 http(s) 链接的路径段允许编码的 / \(如 SSO 回跳地址 https%3A%2F%2F…);点段与控制符仍拦
|
|
67
|
+
return match !== null && hasSafeEncodedSegments(match[1] ?? '', true);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** 兼容原有公开 helper;true 表示值不符合当前 URL/config 路径语境。 */
|
|
71
|
+
export function isRelativePathValue(val: string, options?: PathCheckOptions): boolean {
|
|
72
|
+
if (CONTROL_CHAR_PATTERN.test(val)) return true;
|
|
73
|
+
const trimmed = val.trim();
|
|
74
|
+
if (trimmed === '') return false;
|
|
75
|
+
if (options?.allowQueryOnly === true && trimmed.startsWith('?')) return false;
|
|
76
|
+
if (options?.allowConfigSubpath === true) return !isSafeConfigSubpath(trimmed);
|
|
77
|
+
if (options?.allowExternalHref === true && EXTERNAL_HREF_PATTERN.test(trimmed)) return !isSafeExternalHref(trimmed);
|
|
78
|
+
return !isSafeInternalPath(trimmed);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function pushDiagOnce(out: KitDiagnostic[], diag: KitDiagnostic): void {
|
|
82
|
+
if (!out.some((d) => d.code === diag.code && d.path === diag.path)) out.push(diag);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** 按 URL/config 语境校验;单个 / 开头的任意业务段都是合法站内路由。 */
|
|
86
|
+
export function checkNoRelativeOrSystemPath(
|
|
87
|
+
val: unknown,
|
|
88
|
+
fieldPath: string,
|
|
89
|
+
diagnostics: KitDiagnostic[],
|
|
90
|
+
code = 'KIT-PAGE-004',
|
|
91
|
+
options?: PathCheckOptions,
|
|
92
|
+
): boolean {
|
|
93
|
+
if (typeof val !== 'string') return true;
|
|
94
|
+
if (CONTROL_CHAR_PATTERN.test(val)) {
|
|
95
|
+
pushDiagOnce(diagnostics, { code, path: fieldPath, message: `${fieldPath} 含非法控制字符(收到 ${JSON.stringify(val)})` });
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const trimmed = val.trim();
|
|
100
|
+
if (trimmed === '') return true;
|
|
101
|
+
if (options?.allowQueryOnly === true && trimmed.startsWith('?')) return true;
|
|
102
|
+
|
|
103
|
+
if (options?.allowConfigSubpath === true) {
|
|
104
|
+
if (isSafeConfigSubpath(trimmed)) return true;
|
|
105
|
+
pushDiagOnce(diagnostics, {
|
|
106
|
+
code,
|
|
107
|
+
path: fieldPath,
|
|
108
|
+
message: `${fieldPath} 必须是位于应用根内的配置子路径(收到 ${JSON.stringify(val)});不允许绝对路径、点段、编码分隔符或 query/hash`,
|
|
109
|
+
});
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (options?.allowExternalHref === true && EXTERNAL_HREF_PATTERN.test(trimmed) && isSafeExternalHref(trimmed)) return true;
|
|
114
|
+
if (!isSafeInternalPath(trimmed)) {
|
|
115
|
+
const nonSite = FILE_SCHEME_PATTERN.test(trimmed) || WINDOWS_DRIVE_PATTERN.test(trimmed) || UNC_PATTERN.test(trimmed) || trimmed.startsWith('//') || pathnameOf(trimmed).includes('\\');
|
|
116
|
+
const message = PROTOCOL_RELATIVE_PATTERN.test(trimmed)
|
|
117
|
+
? `${fieldPath} 严禁使用协议相对或混淆地址(收到 ${JSON.stringify(val)});站内地址必须以单个 / 开头`
|
|
118
|
+
: nonSite
|
|
119
|
+
? `${fieldPath} 严禁使用 file:、盘符、UNC、协议相对或反斜杠路径(收到 ${JSON.stringify(val)});站内地址必须以单个 / 开头`
|
|
120
|
+
: !trimmed.startsWith('/')
|
|
121
|
+
? `${fieldPath} 严禁使用裸相对路径(收到 ${JSON.stringify(val)});必须是以 / 开头的站内路径`
|
|
122
|
+
: `${fieldPath} 的路径部分含非法点段、百分号编码、分隔符或控制符(收到 ${JSON.stringify(val)})`;
|
|
123
|
+
pushDiagOnce(diagnostics, { code, path: fieldPath, message });
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
// 运行期主题的两端共享常量(浏览器面 theme-runtime.ts、编译期首屏恢复脚本与服务端端点 theme-endpoint.ts);不含任何取值域与数字,取值域读 design 真源。
|
|
2
|
+
|
|
3
|
+
/** 主题端点路径(走 Host 的 requestHook,不占用户的 api/service 目录) */
|
|
4
|
+
export const KIT_THEME_ENDPOINT = '/api/soma-kit/theme';
|
|
5
|
+
|
|
6
|
+
/** 令牌样式元素上的标记属性 */
|
|
7
|
+
export const KIT_THEME_STYLE_ATTR = 'data-soma-kit-theme';
|
|
8
|
+
|
|
9
|
+
/** 页面内惰性引导数据元素 id(携带应用标识与主题存储键,供首屏同步恢复) */
|
|
10
|
+
export const KIT_THEME_BOOT_ID = 'soma-kit-theme-boot';
|
|
11
|
+
|
|
12
|
+
/** 主题状态与缓存 CSS 的 localStorage 键前缀与默认应用标识 */
|
|
13
|
+
export const KIT_THEME_STORAGE_PREFIX = 'soma-kit-theme-state';
|
|
14
|
+
export const KIT_THEME_CSS_STORAGE_PREFIX = 'soma-kit-theme-css';
|
|
15
|
+
export const KIT_THEME_DEFAULT_APP_ID = 'default';
|
|
16
|
+
|
|
17
|
+
const ASCII_APP_ID = /^[A-Za-z0-9_-]+$/;
|
|
18
|
+
|
|
19
|
+
/** FNV-1a 32 位哈希 -> 8 位小写十六进制(按 UTF-16 码元逐个折叠;纯函数,同输入同输出,两端共用) */
|
|
20
|
+
function fnv1a32Hex(text: string): string {
|
|
21
|
+
let hash = 0x811c9dc5;
|
|
22
|
+
for (let i = 0; i < text.length; i++) {
|
|
23
|
+
hash ^= text.charCodeAt(i);
|
|
24
|
+
hash = Math.imul(hash, 0x01000193) >>> 0;
|
|
25
|
+
}
|
|
26
|
+
return hash.toString(16).padStart(8, '0');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* 规整应用标识:
|
|
31
|
+
* - 去首尾空白后仅含 [A-Za-z0-9_-] 的非空值原样使用;
|
|
32
|
+
* - 含其它字符(如中文名)时用 FNV-1a 32 位哈希生成稳定 ASCII 标识 `app-xxxxxxxx`(不同名字得不同标识,不再剥成 default);
|
|
33
|
+
* - 空值或非字符串才退回 default。
|
|
34
|
+
*/
|
|
35
|
+
export function normalizeKitThemeAppId(appId?: string): string {
|
|
36
|
+
if (typeof appId !== 'string') return KIT_THEME_DEFAULT_APP_ID;
|
|
37
|
+
const trimmed = appId.trim();
|
|
38
|
+
if (trimmed === '') return KIT_THEME_DEFAULT_APP_ID;
|
|
39
|
+
if (ASCII_APP_ID.test(trimmed)) return trimmed;
|
|
40
|
+
return `app-${fnv1a32Hex(trimmed)}`;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** 按应用标识生成主题状态 localStorage 键:soma-kit-theme-state:<appId> */
|
|
44
|
+
export function kitThemeStorageKey(appId?: string): string {
|
|
45
|
+
return `${KIT_THEME_STORAGE_PREFIX}:${normalizeKitThemeAppId(appId)}`;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** 按应用标识生成主题 CSS 缓存 localStorage 键:soma-kit-theme-css:<appId> */
|
|
49
|
+
export function kitThemeCssStorageKey(appId?: string): string {
|
|
50
|
+
return `${KIT_THEME_CSS_STORAGE_PREFIX}:${normalizeKitThemeAppId(appId)}`;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* 生成首屏同步恢复主题的内联脚本(供服务端 HTML 壳 <head> 在首屏绘制前同步恢复缓存主题 CSS)。
|
|
55
|
+
* 存储结构与 theme-runtime.ts 一致:状态键只存用户覆盖层 { overrides };覆盖层非空才使用缓存 CSS,
|
|
56
|
+
* 旧格式(整套九维平铺)或损坏内容视为无效,连同缓存 CSS 一并丢弃。
|
|
57
|
+
* 零外部依赖;若传入 nonce 或页面含 style[nonce] / meta[name="csp-nonce"],自动为注入的 <style> 附加 nonce,兼容严格 CSP。
|
|
58
|
+
*/
|
|
59
|
+
export function buildKitThemeFirstPaintScript(appId?: string, nonce?: string): string {
|
|
60
|
+
const cssKey = JSON.stringify(kitThemeCssStorageKey(appId));
|
|
61
|
+
const stateKey = JSON.stringify(kitThemeStorageKey(appId));
|
|
62
|
+
const styleAttr = JSON.stringify(KIT_THEME_STYLE_ATTR);
|
|
63
|
+
const nonceAttr = typeof nonce === 'string' && nonce !== '' ? ` nonce="${nonce.replace(/"/g, '"')}"` : '';
|
|
64
|
+
const body = [
|
|
65
|
+
'(function(){try{',
|
|
66
|
+
'if(typeof localStorage==="undefined"||typeof document==="undefined")return;',
|
|
67
|
+
`var raw=localStorage.getItem(${stateKey}),o=null;`,
|
|
68
|
+
'if(raw){try{var p=JSON.parse(raw),ks=p&&typeof p==="object"?Object.keys(p):[];',
|
|
69
|
+
'if(ks.length===1&&ks[0]==="overrides"&&p.overrides&&typeof p.overrides==="object"&&!Array.isArray(p.overrides)&&Object.keys(p.overrides).length>0)o=p.overrides;}catch(_){}}',
|
|
70
|
+
`if(!o){localStorage.removeItem(${stateKey});localStorage.removeItem(${cssKey});return;}`,
|
|
71
|
+
`var css=localStorage.getItem(${cssKey});`,
|
|
72
|
+
`if(css){var h=document.head||document.documentElement;var s=h.querySelector("style["+${styleAttr}+"]");`,
|
|
73
|
+
`if(!s){s=document.createElement("style");s.setAttribute(${styleAttr},"");`,
|
|
74
|
+
'var m=h.querySelector(\'meta[name="csp-nonce"]\'),n=m&&m.getAttribute("content")||(h.querySelector("style[nonce]")&&h.querySelector("style[nonce]").nonce);',
|
|
75
|
+
'if(n)s.setAttribute("nonce",n);h.appendChild(s);}s.textContent=css;}',
|
|
76
|
+
'var cl=document.documentElement&&document.documentElement.classList;',
|
|
77
|
+
'if(cl&&typeof o.mode==="string"){if(o.mode==="dark"){cl.add("soma-scheme-dark");cl.remove("soma-scheme-light");}else if(o.mode==="light"||o.mode==="soft"){cl.add("soma-scheme-light");cl.remove("soma-scheme-dark");}else if(o.mode==="system"){cl.remove("soma-scheme-dark");cl.remove("soma-scheme-light");}}',
|
|
78
|
+
'}catch(_){}})();',
|
|
79
|
+
].join('');
|
|
80
|
+
return `<script${nonceAttr}>${body}</script>`;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** 端点收的键:九维键(驼峰)+ 极性 mode */
|
|
84
|
+
export const KIT_RUNTIME_THEME_KEYS = ['palette', 'colorDepth', 'colorSaturation', 'fontFamily', 'fontScale', 'boundary', 'shape', 'surfaceTexture', 'density', 'mode'] as const;
|
|
85
|
+
export type KitRuntimeThemeKey = (typeof KIT_RUNTIME_THEME_KEYS)[number];
|
|
86
|
+
|
|
87
|
+
/** 运行期主题声明:九维键(驼峰)+ 极性;取值域由服务端求解时校验 */
|
|
88
|
+
export type KitRuntimeTheme = { readonly [K in KitRuntimeThemeKey]?: string };
|
|
89
|
+
|
|
90
|
+
/** 只保留已知键且取值是非空字符串的项(取值域由服务端按真源校验,这里不重复持有) */
|
|
91
|
+
export function normalizeKitRuntimeTheme(raw: unknown): KitRuntimeTheme {
|
|
92
|
+
const out: Record<string, string> = {};
|
|
93
|
+
if (raw === null || typeof raw !== 'object') return out;
|
|
94
|
+
for (const key of KIT_RUNTIME_THEME_KEYS) {
|
|
95
|
+
const value = (raw as Record<string, unknown>)[key];
|
|
96
|
+
if (typeof value === 'string' && value !== '') out[key] = value;
|
|
97
|
+
}
|
|
98
|
+
return out;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* 将任意对象格式的主题(蛇形 / 驼峰 / 混合写法)规整为标准 KitRuntimeTheme 纯对象。
|
|
103
|
+
* 只保留已知九维键(驼峰)与 mode 且取值为非空字符串的项(自动 trim),未传或非法格式返回 {}。
|
|
104
|
+
*/
|
|
105
|
+
export function toKitRuntimeTheme(raw: unknown): KitRuntimeTheme {
|
|
106
|
+
if (raw === null || typeof raw !== 'object' || Array.isArray(raw)) return {};
|
|
107
|
+
const r = raw as Record<string, unknown>;
|
|
108
|
+
const out: Record<string, string> = {};
|
|
109
|
+
|
|
110
|
+
const pick = (key: KitRuntimeThemeKey, val: unknown): void => {
|
|
111
|
+
if (typeof val === 'string') {
|
|
112
|
+
const trimmed = val.trim();
|
|
113
|
+
if (trimmed !== '') out[key] = trimmed;
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
pick('palette', r.palette);
|
|
118
|
+
pick('colorDepth', r.colorDepth ?? r.color_depth);
|
|
119
|
+
pick('colorSaturation', r.colorSaturation ?? r.color_saturation);
|
|
120
|
+
pick('fontFamily', r.fontFamily ?? r.font_family);
|
|
121
|
+
pick('fontScale', r.fontScale ?? r.font_scale);
|
|
122
|
+
pick('boundary', r.boundary ?? r.componentBoundary ?? r.component_boundary);
|
|
123
|
+
pick('shape', r.shape);
|
|
124
|
+
pick('surfaceTexture', r.surfaceTexture ?? r.surface_texture);
|
|
125
|
+
pick('density', r.density);
|
|
126
|
+
pick('mode', r.mode);
|
|
127
|
+
|
|
128
|
+
return out;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* 转义内嵌在 <script> 标签内的 JSON 字符串,防止 </script> 截断逃逸与 XSS。
|
|
133
|
+
* 转义 <、>、& 以及 ECMAScript 行分隔符 U+2028、段落分隔符 U+2029。
|
|
134
|
+
* 转义后仍符合标准 JSON 语法,JSON.parse 可 100% 无损还原。
|
|
135
|
+
*/
|
|
136
|
+
export function escapeJsonForScript(json: string): string {
|
|
137
|
+
return json
|
|
138
|
+
.replace(/</g, '\\u003c')
|
|
139
|
+
.replace(/>/g, '\\u003e')
|
|
140
|
+
.replace(/&/g, '\\u0026')
|
|
141
|
+
.replace(new RegExp('\\u2028', 'g'), '\\u2028')
|
|
142
|
+
.replace(new RegExp('\\u2029', 'g'), '\\u2029');
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* 生成编译期写入页面根容器的惰性主题引导数据元素(<script type="application/json" id="soma-kit-theme-boot">)。
|
|
147
|
+
* 符合 soma-core 惰性数据元素安全规范(零脚本执行、通过 declaration-safety-scan),携带本页所属应用标识与缓存键,
|
|
148
|
+
* 以及服务端编译期直接下发的应用纯净基底主题(不可变、不受首屏缓存样式污染)。
|
|
149
|
+
*/
|
|
150
|
+
export function buildKitThemeBootDataElement(
|
|
151
|
+
appId?: string,
|
|
152
|
+
baseTheme?: KitRuntimeTheme | Record<string, unknown>,
|
|
153
|
+
nonce?: string,
|
|
154
|
+
): string {
|
|
155
|
+
const resolvedAppId = normalizeKitThemeAppId(appId);
|
|
156
|
+
const normalizedBaseTheme = toKitRuntimeTheme(baseTheme);
|
|
157
|
+
const nonceAttr = typeof nonce === 'string' && nonce !== '' ? ` nonce="${nonce.replace(/"/g, '"')}"` : '';
|
|
158
|
+
const rawPayload = JSON.stringify({
|
|
159
|
+
appId: resolvedAppId,
|
|
160
|
+
storageKey: kitThemeStorageKey(resolvedAppId),
|
|
161
|
+
cssStorageKey: kitThemeCssStorageKey(resolvedAppId),
|
|
162
|
+
baseTheme: normalizedBaseTheme,
|
|
163
|
+
});
|
|
164
|
+
const payload = escapeJsonForScript(rawPayload);
|
|
165
|
+
return `<script type="application/json" id="${KIT_THEME_BOOT_ID}"${nonceAttr}>${payload}</script>`;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** 请求地址(绝对或相对)是否指向主题端点;只看路径 */
|
|
169
|
+
export function isKitThemePath(url: string): boolean {
|
|
170
|
+
try {
|
|
171
|
+
return new URL(url, 'http://soma.local').pathname === KIT_THEME_ENDPOINT;
|
|
172
|
+
} catch {
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// 展示对象元信息读取(纯函数,只读 soma-core 元信息,供编译期与检查器使用)
|
|
2
|
+
|
|
3
|
+
import { readSomaViewMeta } from 'soma-core/base';
|
|
4
|
+
import type { ViewStateShape } from 'soma-foundation/view-state';
|
|
5
|
+
|
|
6
|
+
/** 读展示对象类的成员与方法清单(编译期核对用);不是 defineKitView 的返回值返回 undefined */
|
|
7
|
+
export function readKitViewInfo(cls: unknown): { name: string; stateKeys: ReadonlySet<string>; methodNames: ReadonlySet<string>; shape: ViewStateShape } | undefined {
|
|
8
|
+
const meta = readSomaViewMeta(cls);
|
|
9
|
+
return meta === undefined ? undefined : { name: meta.name, stateKeys: new Set(meta.stateKeys), shape: meta.shape, methodNames: new Set(meta.methodNames) };
|
|
10
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export {
|
|
2
|
+
KIT_THEME_MODES,
|
|
3
|
+
formatKitThemeDegradation,
|
|
4
|
+
kitThemeConfigOf,
|
|
5
|
+
resolveKitThemeTokens,
|
|
6
|
+
serializeTokenTables,
|
|
7
|
+
solveKitTheme,
|
|
8
|
+
type KitThemeConfig,
|
|
9
|
+
type KitThemeTokensResult,
|
|
10
|
+
type NineDimDegradation,
|
|
11
|
+
type NineDimTheme,
|
|
12
|
+
} from './theme-tokens';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// 默认主题头文本(与 ./kit-theme.css 同源,均由 scripts/build-kit-theme.mjs 从 kit-theme.tpl + kit-limits 生成,勿手改;tests/app/server.test.ts 字节对账;避免打包器改写 import.meta.url 导致 fileURLToPath 报错)
|
|
2
|
-
export const KIT_DEFAULT_THEME_CSS: string = "/*\n * 用 @theme inline:值引用 var(--soma-*),inline 让工具类直接展开成 var(--soma-*),\n * 运行时换主题、切密度时跟着变,不被 @theme 提前固化到 :root 的 --color-* 副本上。\n * core 样式引擎禁止 @import / @plugin / @config,Tailwind 默认色板与尺度全为空,\n * 所以这里必须自带用到的全部尺度;没声明的键不会生成工具类。\n * 尺度允许的键见 spec/kit-grammar.json 的 utilityScales;尺度里的数字(容器档、命中区、透视、模糊、动画时长等)\n * 由 scripts/build-kit-theme.mjs 从 soma-design/spec/pipeline/kit-limits.json 写入,本文件由 src/theme/kit-theme.tpl 生成,勿手改。\n */\n@theme inline {\n --color-surface: var(--soma-surface-base);\n --color-surface-sunken: var(--soma-surface-sunken);\n --color-surface-raised: var(--soma-surface-raised);\n\n --color-fg: var(--soma-text-primary);\n --color-fg-muted: var(--soma-text-secondary);\n --color-fg-subtle: var(--soma-text-muted);\n\n --color-border: var(--soma-border-control);\n --color-border-strong: var(--soma-border-strong);\n --color-border-subtle: var(--soma-border-hairline);\n --color-border-divider: var(--soma-border-divider);\n --color-subtle: var(--soma-border-hairline);\n --color-divider: var(--soma-border-divider);\n --color-input: color-mix(in oklab, var(--soma-border-control) 60%, var(--soma-surface-base));\n --color-input-hover: var(--soma-border-control);\n\n --color-primary: var(--soma-c-primary);\n --color-primary-fg: var(--soma-c-primary-fg);\n --color-primary-soft: var(--soma-c-primary-soft);\n --color-primary-on-soft: var(--soma-c-primary-on-soft);\n --color-primary-hover: var(--soma-c-primary-hover);\n --color-primary-active: var(--soma-c-primary-active);\n\n --color-success: var(--soma-c-success);\n --color-success-fg: var(--soma-c-success-fg);\n --color-success-soft: var(--soma-c-success-soft);\n --color-success-on-soft: var(--soma-c-success-on-soft);\n\n --color-warning: var(--soma-c-warning);\n --color-warning-fg: var(--soma-c-warning-fg);\n --color-warning-soft: var(--soma-c-warning-soft);\n --color-warning-on-soft: var(--soma-c-warning-on-soft);\n\n --color-danger: var(--soma-c-danger);\n --color-danger-fg: var(--soma-c-danger-fg);\n --color-danger-soft: var(--soma-c-danger-soft);\n --color-danger-on-soft: var(--soma-c-danger-on-soft);\n --color-danger-hover: var(--soma-c-danger-hover);\n --color-danger-active: var(--soma-c-danger-active);\n\n --color-info: var(--soma-c-info);\n --color-info-fg: var(--soma-c-info-fg);\n --color-info-soft: var(--soma-c-info-soft);\n --color-info-on-soft: var(--soma-c-info-on-soft);\n\n --color-ring: var(--soma-focus-ring);\n\n --spacing: var(--soma-space-1);\n\n --radius-sm: var(--soma-radius-sm);\n --radius-md: var(--soma-radius-md);\n --radius-lg: var(--soma-radius-lg);\n --radius-xl: var(--soma-radius-xl);\n --radius-full: var(--soma-radius-full);\n\n --text-xs: var(--soma-font-size-xs);\n --text-xs--line-height: var(--soma-line-height-xs);\n --text-sm: var(--soma-font-size-sm);\n --text-sm--line-height: var(--soma-line-height-sm);\n --text-base: var(--soma-font-size-md);\n --text-base--line-height: var(--soma-line-height-md);\n --text-lg: var(--soma-font-size-lg);\n --text-lg--line-height: var(--soma-line-height-lg);\n --text-xl: var(--soma-font-size-xl);\n --text-xl--line-height: var(--soma-line-height-xl);\n --text-2xl: var(--soma-font-size-xxl);\n --text-2xl--line-height: var(--soma-line-height-xxl);\n\n --font-weight-normal: var(--soma-font-weight-normal);\n --font-weight-medium: var(--soma-font-weight-medium);\n --font-weight-semibold: var(--soma-font-weight-bold);\n --font-weight-bold: var(--soma-font-weight-heavy);\n\n --font-sans: var(--soma-font-family);\n --font-mono: var(--soma-font-family-mono);\n\n --shadow-xs: var(--soma-shadow-step-0);\n --shadow-sm: var(--soma-shadow-step-1);\n --shadow-md: var(--soma-shadow-step-2);\n --shadow-lg: var(--soma-shadow-popover);\n --shadow-xl: var(--soma-shadow-dialog);\n\n --ease-standard: var(--soma-motion-easing-standard);\n --ease-enter: var(--soma-motion-easing-enter);\n --ease-exit: var(--soma-motion-easing-exit);\n --ease-emphasized: var(--soma-motion-spring-emphasized-easing);\n\n --default-transition-duration: var(--soma-motion-duration-base);\n --default-transition-timing-function: var(--soma-motion-easing-standard);\n\n --container-xs: 20rem;\n --container-sm: 24rem;\n --container-md: 28rem;\n --container-lg: 36rem;\n --container-xl: 40rem;\n --container-2xl: 48rem;\n --container-3xl: 56rem;\n --container-4xl: 64rem;\n\n --aspect-video: 16 / 9;\n}\n\n/*\n * 进退动效组:时长与缓动成对取自 design 动效真源(进入 200ms、退出 150ms,退出短于进入;减少动效档令牌自动归 100ms / linear)。\n * motion-enter 用于出现,motion-exit 用于消失,motion-emphasized 用于强调进入(弹簧曲线);使用处一律 motion-safe: 前缀。\n * 命中区 hit-area:小控件的不可见扩展点击区(伪元素铺满),最小边长取 design adaptive#/…/hitTarget(精细指针 24px、粗指针 44px,生成时换算成 rem);\n * 宿主元素自带 relative 定位,宿主本身要有 overflow 可见。\n * 文本框去自动填充底色 autofill-clear:文本类输入(input / textarea)与 appearance-none 同用,:-webkit-autofill 的黄 / 蓝底改回令牌色(surface-base / text-primary);\n * 数字框不再用原生 type=number(改 type=text + role=spinbutton,步进自绘),所以没有隐藏原生微调钮的类。\n */\n@utility motion-enter {\n transition-duration: var(--soma-motion-duration-enter);\n transition-timing-function: var(--soma-motion-easing-enter);\n}\n\n@utility motion-exit {\n transition-duration: var(--soma-motion-duration-exit);\n transition-timing-function: var(--soma-motion-easing-exit);\n}\n\n@utility motion-emphasized {\n transition-duration: var(--soma-motion-spring-emphasized-duration);\n transition-timing-function: var(--soma-motion-spring-emphasized-easing);\n}\n\n@utility autofill-clear {\n &:-webkit-autofill,\n &:-webkit-autofill:hover,\n &:-webkit-autofill:focus {\n -webkit-text-fill-color: var(--soma-text-primary);\n caret-color: var(--soma-text-primary);\n box-shadow: 0 0 0 100vmax var(--soma-surface-base) inset;\n transition: background-color 9999s ease-out 0s;\n }\n}\n\n@utility hit-area {\n position: relative;\n\n &::after {\n content: '';\n position: absolute;\n top: 50%;\n left: 50%;\n width: max(100%, 1.5rem);\n height: max(100%, 1.5rem);\n transform: translate(-50%, -50%);\n }\n\n @media (pointer: coarse) {\n &::after {\n width: max(100%, 2.75rem);\n height: max(100%, 2.75rem);\n }\n }\n}\n\n/* 导航件(Menu / Navbar / MegaMenu / workspace-frame)的弹层入场;使用处一律 motion-safe: 前缀 */\n@theme inline {\n --animate-kit-menu-in: kit-menu-in var(--soma-motion-duration-base) var(--soma-motion-easing-standard);\n\n @keyframes kit-menu-in {\n from {\n opacity: 0;\n transform: translateY(-0.25rem);\n }\n to {\n opacity: 1;\n transform: translateY(0);\n }\n }\n}\n\n/* 状态件(StatusDot 脉冲、ProgressBar 不确定态):使用处一律 motion-safe: 前缀,motion-reduce 下静止 */\n@theme inline {\n --animate-kit-ping: kit-ping 1.5s cubic-bezier(0, 0, 0.2, 1) infinite;\n --animate-kit-indeterminate: kit-indeterminate 1.4s ease-in-out infinite;\n\n @keyframes kit-ping {\n 75%,\n 100% {\n opacity: 0;\n transform: scale(2.2);\n }\n }\n\n @keyframes kit-indeterminate {\n from {\n transform: translateX(-100%);\n }\n to {\n transform: translateX(250%);\n }\n }\n}\n\n/* 动效展示件(TextRotate / Hover3d / HoverGallery / Aura / Marquee):关键帧与透视、模糊刻度;使用处一律 motion-safe: 前缀,motion-reduce 下静止 */\n@theme inline {\n --perspective-normal: 1000px;\n --blur-sm: 4px;\n --blur-md: 12px;\n\n --animate-kit-rise: kit-rise var(--soma-motion-duration-base) var(--soma-motion-easing-standard);\n --animate-kit-fade: kit-fade var(--soma-motion-duration-base) var(--soma-motion-easing-standard);\n --animate-kit-aura: kit-aura 3s ease-in-out infinite;\n --animate-kit-marquee-slow: kit-marquee 40s linear infinite;\n --animate-kit-marquee-slow-paused: kit-marquee 40s linear infinite paused;\n --animate-kit-marquee-normal: kit-marquee 25s linear infinite;\n --animate-kit-marquee-normal-paused: kit-marquee 25s linear infinite paused;\n --animate-kit-marquee-fast: kit-marquee 12s linear infinite;\n --animate-kit-marquee-fast-paused: kit-marquee 12s linear infinite paused;\n\n @keyframes kit-rise {\n from {\n opacity: 0;\n transform: translateY(0.5rem);\n }\n to {\n opacity: 1;\n transform: translateY(0);\n }\n }\n\n @keyframes kit-fade {\n from {\n opacity: 0;\n }\n to {\n opacity: 1;\n }\n }\n\n @keyframes kit-aura {\n 0%,\n 100% {\n opacity: 0.5;\n transform: scale(1);\n }\n 50% {\n opacity: 1;\n transform: scale(1.03);\n }\n }\n\n @keyframes kit-marquee {\n from {\n transform: translateX(0);\n }\n to {\n transform: translateX(-50%);\n }\n }\n}\n\n/* 骨架屏(KitCollectionState 的 loading: skeleton):呼吸占位;使用处一律 motion-safe: 前缀,减少动效下静止 */\n@theme inline {\n --animate-kit-pulse: kit-pulse 2s ease-in-out infinite;\n\n @keyframes kit-pulse {\n 0%,\n 100% {\n opacity: 1;\n }\n 50% {\n opacity: 0.5;\n }\n }\n}\n";
|
|
2
|
+
export const KIT_DEFAULT_THEME_CSS: string = "/*\n * 用 @theme inline:值引用 var(--soma-*),inline 让工具类直接展开成 var(--soma-*),\n * 运行时换主题、切密度时跟着变,不被 @theme 提前固化到 :root 的 --color-* 副本上。\n * core 样式引擎禁止 @import / @plugin / @config,Tailwind 默认色板与尺度全为空,\n * 所以这里必须自带用到的全部尺度;没声明的键不会生成工具类。\n * 尺度允许的键见 spec/kit-grammar.json 的 utilityScales;尺度里的数字(容器档、命中区、透视、模糊、动画时长等)\n * 由 scripts/build-kit-theme.mjs 从 soma-design/spec/pipeline/kit-limits.json 写入,本文件由 src/theme/kit-theme.tpl 生成,勿手改。\n */\n@theme inline {\n --color-surface: var(--soma-surface-base);\n --color-surface-sunken: var(--soma-surface-sunken);\n --color-surface-raised: var(--soma-surface-raised);\n /* 遮罩幕:亮暗各一档的深色 + 内含透明度(design surface#/scrim),类名 bg-scrim 不再叠 /N 透明度 */\n --color-scrim: var(--soma-overlay-bg);\n\n --color-fg: var(--soma-text-primary);\n --color-fg-muted: var(--soma-text-secondary);\n --color-fg-subtle: var(--soma-text-muted);\n\n --color-border: var(--soma-border-control);\n --color-border-strong: var(--soma-border-strong);\n --color-border-subtle: var(--soma-border-hairline);\n --color-border-divider: var(--soma-border-divider);\n --color-subtle: var(--soma-border-hairline);\n --color-divider: var(--soma-border-divider);\n --color-input: color-mix(in oklab, var(--soma-border-control) 60%, var(--soma-surface-base));\n --color-input-hover: var(--soma-border-control);\n\n --color-primary: var(--soma-c-primary);\n --color-primary-fg: var(--soma-c-primary-fg);\n --color-primary-soft: var(--soma-c-primary-soft);\n --color-primary-on-soft: var(--soma-c-primary-on-soft);\n --color-primary-hover: var(--soma-c-primary-hover);\n --color-primary-active: var(--soma-c-primary-active);\n\n --color-success: var(--soma-c-success);\n --color-success-fg: var(--soma-c-success-fg);\n --color-success-soft: var(--soma-c-success-soft);\n --color-success-on-soft: var(--soma-c-success-on-soft);\n\n --color-warning: var(--soma-c-warning);\n --color-warning-fg: var(--soma-c-warning-fg);\n --color-warning-soft: var(--soma-c-warning-soft);\n --color-warning-on-soft: var(--soma-c-warning-on-soft);\n\n --color-danger: var(--soma-c-danger);\n --color-danger-fg: var(--soma-c-danger-fg);\n --color-danger-soft: var(--soma-c-danger-soft);\n --color-danger-on-soft: var(--soma-c-danger-on-soft);\n --color-danger-hover: var(--soma-c-danger-hover);\n --color-danger-active: var(--soma-c-danger-active);\n\n --color-info: var(--soma-c-info);\n --color-info-fg: var(--soma-c-info-fg);\n --color-info-soft: var(--soma-c-info-soft);\n --color-info-on-soft: var(--soma-c-info-on-soft);\n\n --color-ring: var(--soma-border-focus);\n\n --spacing: var(--soma-space-1);\n --spacing-card: var(--soma-card-padding);\n --spacing-section: var(--soma-section-gap);\n --spacing-table-row: var(--soma-table-row-height);\n\n --radius-sm: var(--soma-radius-sm);\n --radius-md: var(--soma-radius-md);\n --radius-lg: var(--soma-radius-lg);\n --radius-xl: var(--soma-radius-xl);\n --radius-full: var(--soma-radius-full);\n --radius-card: var(--soma-radius-card);\n --radius-control: var(--soma-radius-control);\n --radius-button: var(--soma-radius-button);\n --radius-badge: var(--soma-radius-badge);\n --radius-inner: var(--soma-radius-inner);\n\n --text-xs: var(--soma-font-size-xs);\n --text-xs--line-height: var(--soma-line-height-xs);\n --text-sm: var(--soma-font-size-sm);\n --text-sm--line-height: var(--soma-line-height-sm);\n --text-base: var(--soma-font-size-md);\n --text-base--line-height: var(--soma-line-height-md);\n --text-lg: var(--soma-font-size-lg);\n --text-lg--line-height: var(--soma-line-height-lg);\n --text-xl: var(--soma-font-size-xl);\n --text-xl--line-height: var(--soma-line-height-xl);\n --text-2xl: var(--soma-font-size-xxl);\n --text-2xl--line-height: var(--soma-line-height-xxl);\n --text-title-page: var(--soma-title-page-size);\n --text-title-dialog: var(--soma-title-dialog-size);\n --text-title-section: var(--soma-title-section-size);\n --text-stat-value: var(--soma-stat-value-size);\n\n --font-weight-normal: var(--soma-font-weight-normal);\n --font-weight-medium: var(--soma-font-weight-medium);\n --font-weight-semibold: var(--soma-font-weight-bold);\n --font-weight-bold: var(--soma-font-weight-heavy);\n --font-weight-title: var(--soma-title-weight);\n\n --tracking-tight: var(--soma-tracking-tight);\n --tracking-heading: var(--soma-tracking-heading);\n --tracking-normal: var(--soma-tracking-normal);\n --tracking-wide: var(--soma-tracking-wide);\n\n --font-sans: var(--soma-font-family);\n --font-mono: var(--soma-font-family-mono);\n\n --shadow-xs: var(--soma-shadow-step-0);\n --shadow-sm: var(--soma-shadow-step-1);\n --shadow-md: var(--soma-shadow-step-2);\n --shadow-lg: var(--soma-shadow-popover);\n --shadow-xl: var(--soma-shadow-dialog);\n\n --ease-standard: var(--soma-motion-easing-standard);\n --ease-enter: var(--soma-motion-easing-enter);\n --ease-exit: var(--soma-motion-easing-exit);\n --ease-emphasized: var(--soma-motion-spring-emphasized-easing);\n\n --default-transition-duration: var(--soma-motion-duration-base);\n --default-transition-timing-function: var(--soma-motion-easing-standard);\n\n --container-xs: 20rem;\n --container-sm: 24rem;\n --container-md: 28rem;\n --container-lg: 36rem;\n --container-xl: 40rem;\n --container-2xl: 48rem;\n --container-3xl: 56rem;\n --container-4xl: 64rem;\n\n --aspect-video: 16 / 9;\n}\n\n/*\n * 进退动效组:时长与缓动成对取自 design 动效真源(进入 200ms、退出 150ms,退出短于进入;减少动效档令牌自动归 100ms / linear)。\n * motion-enter 用于出现,motion-exit 用于消失,motion-emphasized 用于强调进入(弹簧曲线);使用处一律 motion-safe: 前缀。\n * 命中区 hit-area:小控件的不可见扩展点击区(伪元素铺满),最小边长取 design adaptive#/…/hitTarget(精细指针 24px、粗指针 44px,生成时换算成 rem);\n * 宿主元素自带 relative 定位,宿主本身要有 overflow 可见。\n * 文本框去自动填充底色 autofill-clear:文本类输入(input / textarea)与 appearance-none 同用,:-webkit-autofill 的黄 / 蓝底改回令牌色(surface-base / text-primary);\n * 数字框不再用原生 type=number(改 type=text + role=spinbutton,步进自绘),所以没有隐藏原生微调钮的类。\n */\n@utility motion-enter {\n transition-duration: var(--soma-motion-duration-enter);\n transition-timing-function: var(--soma-motion-easing-enter);\n}\n\n@utility motion-exit {\n transition-duration: var(--soma-motion-duration-exit);\n transition-timing-function: var(--soma-motion-easing-exit);\n}\n\n@utility motion-emphasized {\n transition-duration: var(--soma-motion-spring-emphasized-duration);\n transition-timing-function: var(--soma-motion-spring-emphasized-easing);\n}\n\n@utility autofill-clear {\n &:-webkit-autofill,\n &:-webkit-autofill:hover,\n &:-webkit-autofill:focus {\n -webkit-text-fill-color: var(--soma-text-primary);\n caret-color: var(--soma-text-primary);\n box-shadow: 0 0 0 100vmax var(--soma-surface-base) inset;\n transition: background-color 9999s ease-out 0s;\n }\n}\n\n@utility hit-area {\n position: relative;\n\n &::after {\n content: '';\n position: absolute;\n top: 50%;\n left: 50%;\n width: max(100%, 1.5rem);\n height: max(100%, 1.5rem);\n transform: translate(-50%, -50%);\n }\n\n @media (pointer: coarse) {\n &::after {\n width: max(100%, 2.75rem);\n height: max(100%, 2.75rem);\n }\n }\n}\n\n/* 导航件(Menu / Navbar / MegaMenu / workspace-frame)的弹层入场;使用处一律 motion-safe: 前缀 */\n@theme inline {\n --animate-kit-menu-in: kit-menu-in var(--soma-motion-duration-base) var(--soma-motion-easing-standard);\n\n @keyframes kit-menu-in {\n from {\n opacity: 0;\n transform: translateY(-0.25rem);\n }\n to {\n opacity: 1;\n transform: translateY(0);\n }\n }\n}\n\n/* 状态件(StatusDot 脉冲、ProgressBar 不确定态):使用处一律 motion-safe: 前缀,motion-reduce 下静止 */\n@theme inline {\n --animate-kit-ping: kit-ping 1.5s cubic-bezier(0, 0, 0.2, 1) infinite;\n --animate-kit-indeterminate: kit-indeterminate 1.4s ease-in-out infinite;\n\n @keyframes kit-ping {\n 75%,\n 100% {\n opacity: 0;\n transform: scale(2.2);\n }\n }\n\n @keyframes kit-indeterminate {\n from {\n transform: translateX(-100%);\n }\n to {\n transform: translateX(250%);\n }\n }\n}\n\n/* 动效展示件(TextRotate / Hover3d / HoverGallery / Aura / Marquee):关键帧与透视、模糊刻度;使用处一律 motion-safe: 前缀,motion-reduce 下静止 */\n@theme inline {\n --perspective-normal: 1000px;\n --blur-sm: 4px;\n --blur-md: 12px;\n\n --animate-kit-rise: kit-rise var(--soma-motion-duration-base) var(--soma-motion-easing-standard);\n --animate-kit-fade: kit-fade var(--soma-motion-duration-base) var(--soma-motion-easing-standard);\n --animate-kit-aura: kit-aura 3s ease-in-out infinite;\n --animate-kit-marquee-slow: kit-marquee 40s linear infinite;\n --animate-kit-marquee-slow-paused: kit-marquee 40s linear infinite paused;\n --animate-kit-marquee-normal: kit-marquee 25s linear infinite;\n --animate-kit-marquee-normal-paused: kit-marquee 25s linear infinite paused;\n --animate-kit-marquee-fast: kit-marquee 12s linear infinite;\n --animate-kit-marquee-fast-paused: kit-marquee 12s linear infinite paused;\n\n @keyframes kit-rise {\n from {\n opacity: 0;\n transform: translateY(0.5rem);\n }\n to {\n opacity: 1;\n transform: translateY(0);\n }\n }\n\n @keyframes kit-fade {\n from {\n opacity: 0;\n }\n to {\n opacity: 1;\n }\n }\n\n @keyframes kit-aura {\n 0%,\n 100% {\n opacity: 0.5;\n transform: scale(1);\n }\n 50% {\n opacity: 1;\n transform: scale(1.03);\n }\n }\n\n @keyframes kit-marquee {\n from {\n transform: translateX(0);\n }\n to {\n transform: translateX(-50%);\n }\n }\n}\n\n/* 骨架屏(KitCollectionState 的 loading: skeleton):呼吸占位;使用处一律 motion-safe: 前缀,减少动效下静止 */\n@theme inline {\n --animate-kit-pulse: kit-pulse 2s ease-in-out infinite;\n --animate-spin: kit-spin 1s linear infinite;\n\n @keyframes kit-spin {\n to {\n transform: rotate(360deg);\n }\n }\n\n @keyframes kit-pulse {\n 0%,\n 100% {\n opacity: 1;\n }\n 50% {\n opacity: 0.5;\n }\n }\n}\n\n/* 高对比度模式(forced-colors: active):浏览器强制关闭 box-shadow 焦点环,统一保底使用系统 CanvasText 实线轮廓 */\n@media (forced-colors: active) {\n *:focus-visible,\n [data-soma-component]:focus-within {\n outline: 2px solid CanvasText !important;\n outline-offset: 2px !important;\n }\n}\n\n";
|