soma-core 1.5.0 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/app/SomaPageClient.tsx +28 -9
- package/app/soma/manifest/route.ts +3 -0
- package/bin/migrate.cjs +71 -1
- package/bin/soma-lsp.cjs +8 -1
- package/core/build/blocks/block-compile.ts +23 -5
- package/core/build/compiler/full-manifest-builder.ts +15 -0
- package/core/build/compiler/page-assets.ts +17 -1
- package/core/build/compiler/page-declaration-compiler.ts +67 -11
- package/core/build/compiler/precompiled-manifest-loader.ts +7 -0
- package/core/build/compiler/soma-manifest-webpack-plugin.js +7 -0
- package/core/build/compiler/soma-precompile.js +30 -6
- package/core/build/component/package-loader.ts +35 -4
- package/core/build/component-tree/artifact-codec.ts +192 -0
- package/core/build/component-tree/binding-bridge.ts +272 -0
- package/core/build/component-tree/collection-binding-lowerer.ts +65 -0
- package/core/build/component-tree/definition-preparation.ts +320 -0
- package/core/build/component-tree/migration-files.ts +214 -0
- package/core/build/component-tree/migration.ts +170 -0
- package/core/build/component-tree/parser.ts +362 -0
- package/core/build/component-tree/registry-snapshot.ts +317 -0
- package/core/build/component-tree/source-preflight.ts +132 -0
- package/core/build/component-tree/structure-topology.ts +63 -0
- package/core/build/component-tree/validator.ts +318 -0
- package/core/build/layout/css-emitter.ts +14 -1
- package/core/build/lsp/component-tree-service.ts +79 -0
- package/core/build/lsp/component-tree.cjs +42 -0
- package/core/build/lsp/cross-file-diagnostics.cjs +15 -3
- package/core/build/lsp/extra-completion.cjs +7 -0
- package/core/client/compiler/manifest-compiler.ts +2 -0
- package/core/client/component/ai-catalog.ts +41 -3
- package/core/client/component/catalog-examples.ts +60 -0
- package/core/client/component/component-definition.types.ts +9 -0
- package/core/client/component/component-expander.ts +39 -8
- package/core/client/component/component-manager.ts +107 -16
- package/core/client/component/component-registry.ts +10 -1
- package/core/client/component/scoped-adapter.ts +29 -2
- package/core/client/component/structure-adapter.ts +207 -0
- package/core/client/component/verify-pack.ts +64 -1
- package/core/client/engine/asset-resolver.ts +1 -1
- package/core/client/engine/dom-renderer.ts +283 -0
- package/core/client/engine/event-engine.ts +28 -9
- package/core/client/engine/render-engine.ts +2 -0
- package/core/client/engine/row-range.ts +62 -0
- package/core/client/engine/row-scope.ts +77 -0
- package/core/client/engine/runtime-builder.ts +2 -0
- package/core/client/engine/soma-bootstrap.ts +146 -1
- package/core/client/parser/blocks/page-parser.ts +9 -2
- package/core/client/parser/ui-config-parser.ts +38 -6
- package/core/client/registry/declaration-renderer.ts +32 -24
- package/core/client/registry/remote-page.ts +1 -1
- package/core/client/theme/theme-engine.ts +61 -1
- package/core/client/validation/contract-validator.ts +1 -1
- package/core/index.ts +9 -1
- package/core/server/host/page-markup-config.ts +42 -0
- package/core/server/host/published-page-artifact-cache.ts +36 -4
- package/core/server/host/published-page-assets.ts +13 -7
- package/core/server/host/resolve-host-tree-context.ts +43 -0
- package/core/server/host/server-page-assets.ts +23 -4
- package/core/server/host/soma-page-compile.ts +10 -0
- package/core/server/page-declaration.ts +7 -0
- package/core/server/registry/declaration-precompiler.ts +35 -3
- package/core/server/registry/page-registry-repository.ts +31 -3
- package/core/server/registry/page-registry-store.ts +64 -7
- package/core/server/registry/publish-asset-pin.ts +6 -1
- package/core/server/registry/services/pages/Get.ts +11 -6
- package/core/server/registry/validation/compile-gate.ts +10 -1
- package/core/shared/component-tree-artifact.ts +237 -0
- package/core/shared/component-tree-errors.ts +52 -0
- package/core/shared/types/component-contract.types.ts +51 -0
- package/core/shared/types/component-tree-artifact.types.ts +121 -0
- package/core/shared/types/component-tree.types.ts +170 -0
- package/core/shared/types/engine.types.ts +5 -0
- package/core/shared/types/manifest.types.ts +4 -0
- package/core/shared/types/ui-config.types.ts +8 -0
- package/dist/cli/soma.js +1 -1
- package/dist/core/index.cjs +1976 -692
- package/dist/lsp/component-tree.cjs +20807 -0
- package/dist/types/build/blocks/block-compile.d.ts +10 -1
- package/dist/types/build/compiler/full-manifest-builder.d.ts +9 -0
- package/dist/types/build/compiler/page-assets.d.ts +6 -1
- package/dist/types/build/compiler/page-declaration-compiler.d.ts +11 -1
- package/dist/types/build/component/package-loader.d.ts +4 -1
- package/dist/types/build/component-tree/artifact-codec.d.ts +50 -0
- package/dist/types/build/component-tree/binding-bridge.d.ts +19 -0
- package/dist/types/build/component-tree/collection-binding-lowerer.d.ts +18 -0
- package/dist/types/build/component-tree/definition-preparation.d.ts +11 -0
- package/dist/types/build/component-tree/migration-files.d.ts +35 -0
- package/dist/types/build/component-tree/migration.d.ts +28 -0
- package/dist/types/build/component-tree/parser.d.ts +13 -0
- package/dist/types/build/component-tree/registry-snapshot.d.ts +15 -0
- package/dist/types/build/component-tree/source-preflight.d.ts +22 -0
- package/dist/types/build/component-tree/structure-topology.d.ts +7 -0
- package/dist/types/build/component-tree/validator.d.ts +9 -0
- package/dist/types/build/lsp/component-tree-service.d.ts +34 -0
- package/dist/types/client/component/ai-catalog.d.ts +18 -1
- package/dist/types/client/component/catalog-examples.d.ts +18 -0
- package/dist/types/client/component/component-definition.types.d.ts +9 -0
- package/dist/types/client/component/component-expander.d.ts +3 -1
- package/dist/types/client/component/component-manager.d.ts +11 -0
- package/dist/types/client/component/scoped-adapter.d.ts +1 -0
- package/dist/types/client/component/structure-adapter.d.ts +17 -0
- package/dist/types/client/engine/dom-renderer.d.ts +15 -0
- package/dist/types/client/engine/event-engine.d.ts +1 -0
- package/dist/types/client/engine/render-engine.d.ts +1 -0
- package/dist/types/client/engine/row-range.d.ts +13 -0
- package/dist/types/client/engine/row-scope.d.ts +20 -0
- package/dist/types/client/engine/runtime-builder.d.ts +1 -0
- package/dist/types/client/engine/soma-bootstrap.d.ts +4 -1
- package/dist/types/client/parser/ui-config-parser.d.ts +2 -0
- package/dist/types/client/registry/declaration-renderer.d.ts +5 -1
- package/dist/types/client/registry/remote-page.d.ts +1 -1
- package/dist/types/index.d.ts +3 -2
- package/dist/types/server/host/page-markup-config.d.ts +6 -0
- package/dist/types/server/host/published-page-artifact-cache.d.ts +9 -1
- package/dist/types/server/host/published-page-assets.d.ts +5 -3
- package/dist/types/server/host/resolve-host-tree-context.d.ts +8 -0
- package/dist/types/server/host/server-page-assets.d.ts +6 -0
- package/dist/types/server/host/soma-page-compile.d.ts +10 -1
- package/dist/types/server/page-declaration.d.ts +6 -0
- package/dist/types/server/registry/declaration-precompiler.d.ts +8 -3
- package/dist/types/server/registry/page-registry-repository.d.ts +5 -0
- package/dist/types/server/registry/page-registry-store.d.ts +11 -1
- package/dist/types/server/registry/publish-asset-pin.d.ts +4 -0
- package/dist/types/server/registry/validation/compile-gate.d.ts +4 -1
- package/dist/types/shared/component-tree-artifact.d.ts +5 -0
- package/dist/types/shared/component-tree-errors.d.ts +22 -0
- package/dist/types/shared/types/component-contract.types.d.ts +42 -0
- package/dist/types/shared/types/component-tree-artifact.types.d.ts +104 -0
- package/dist/types/shared/types/component-tree.types.d.ts +149 -0
- package/dist/types/shared/types/engine.types.d.ts +5 -0
- package/dist/types/shared/types/manifest.types.d.ts +4 -0
- package/dist/types/shared/types/ui-config.types.d.ts +8 -0
- package/package.json +3 -1
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import type { StructurePlan, RepeatPlan } from '../../shared/types/component-tree-artifact.types';
|
|
2
|
+
import type { SomaStructureSemanticToken } from '../../shared/types/component-contract.types';
|
|
3
|
+
import { SomaComponentTreeError } from '../../shared/component-tree-errors';
|
|
4
|
+
import type { SomaComponentDefinition } from './component-definition.types';
|
|
5
|
+
import { SomaScopedContainerAdapter } from './scoped-adapter';
|
|
6
|
+
|
|
7
|
+
const preparedHosts = new WeakMap<HTMLElement, { definition: SomaComponentDefinition; scopeId: string; staticProps: Record<string, unknown> }>();
|
|
8
|
+
const semanticTags: Record<SomaStructureSemanticToken, string> = {
|
|
9
|
+
root: 'div', div: 'div', flow: 'div', none: 'div', main: 'main', section: 'section',
|
|
10
|
+
article: 'article', aside: 'aside', header: 'header', footer: 'footer', nav: 'nav',
|
|
11
|
+
navigation: 'nav', complementary: 'aside', contentinfo: 'footer', region: 'section',
|
|
12
|
+
unordered: 'ul', ordered: 'ol',
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export interface PreparedStructureTemplate {
|
|
16
|
+
fragment: DocumentFragment;
|
|
17
|
+
root?: HTMLElement;
|
|
18
|
+
rootAlias?: string;
|
|
19
|
+
merge: boolean;
|
|
20
|
+
staticProps: Record<string, unknown>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Validate off-DOM, before replacing the old host or activating any controller. */
|
|
24
|
+
export function prepareStructureTemplate(
|
|
25
|
+
host: HTMLElement, definition: SomaComponentDefinition, plan?: StructurePlan,
|
|
26
|
+
suppliedProps: Record<string, unknown> = {},
|
|
27
|
+
): PreparedStructureTemplate {
|
|
28
|
+
const structure = definition.contract.structure;
|
|
29
|
+
if (structure?.kind === 'fragment-macro') fail('Fragment 宏不可在运行时挂载');
|
|
30
|
+
if (!plan && (host.hasAttribute('data-soma-tree-mount') || host.hasAttribute('data-soma-tree-as'))) {
|
|
31
|
+
fail('结构标记没有已验证的实例计划');
|
|
32
|
+
}
|
|
33
|
+
if (plan && (plan.componentName !== definition.contract.name
|
|
34
|
+
|| plan.mountMode !== (structure?.tree_mount ?? 'legacy-host')
|
|
35
|
+
|| plan.hostTag.toLowerCase() !== host.tagName.toLowerCase())) fail('结构计划与实际组件或宿主不一致');
|
|
36
|
+
const template = host.ownerDocument.createElement('template');
|
|
37
|
+
template.innerHTML = definition.templateHtml;
|
|
38
|
+
const result: PreparedStructureTemplate = { fragment: template.content, merge: plan?.mountMode === 'single-host', staticProps: {} };
|
|
39
|
+
if (!structure) return result;
|
|
40
|
+
const rootId = definition.structureAdapter?.rootAnchor;
|
|
41
|
+
let root: HTMLElement | undefined;
|
|
42
|
+
if (rootId) {
|
|
43
|
+
const matches = [...template.content.querySelectorAll<HTMLElement>('[data-soma-id]')].filter(el => el.getAttribute('data-soma-id') === rootId);
|
|
44
|
+
if (matches.length !== 1) fail('结构定义的内部根必须恰好匹配一次');
|
|
45
|
+
root = matches[0];
|
|
46
|
+
}
|
|
47
|
+
const semantics = structure.semantics;
|
|
48
|
+
if (semantics) {
|
|
49
|
+
let token = plan?.semanticToken;
|
|
50
|
+
const prop = semantics.staticProp;
|
|
51
|
+
if (prop) {
|
|
52
|
+
const raw = suppliedProps[prop] ?? plan?.staticProps?.[prop] ?? definition.contract.props?.[prop]?.default;
|
|
53
|
+
const derived = prop === 'ordered' ? typeof raw === 'boolean' ? raw ? 'ordered' : 'unordered' : undefined : raw;
|
|
54
|
+
if (derived !== undefined && (typeof derived !== 'string' || !semantics.allowed.includes(derived as SomaStructureSemanticToken))) {
|
|
55
|
+
fail('结构语义属性必须是受控静态字面量');
|
|
56
|
+
}
|
|
57
|
+
if (token && derived !== undefined && token !== derived) fail('结构计划与静态语义属性冲突');
|
|
58
|
+
token ??= derived as SomaStructureSemanticToken | undefined;
|
|
59
|
+
result.staticProps[prop] = prop === 'ordered' ? (token ?? semantics.default) === 'ordered' : token ?? semantics.default;
|
|
60
|
+
}
|
|
61
|
+
token ??= semantics.default;
|
|
62
|
+
if (!semantics.allowed.includes(token)) fail('结构语义不在组件允许词汇中');
|
|
63
|
+
const tag = semanticTags[token];
|
|
64
|
+
if (plan && plan.mountMode !== 'legacy-host' && plan.hostTag !== tag) fail('结构计划宿主标签不符合受控语义');
|
|
65
|
+
if (root && root.tagName.toLowerCase() !== tag) {
|
|
66
|
+
const replacement = host.ownerDocument.createElement(tag);
|
|
67
|
+
for (const attr of [...root.attributes]) replacement.setAttribute(attr.name, attr.value);
|
|
68
|
+
replacement.append(...Array.from(root.childNodes));
|
|
69
|
+
root.replaceWith(replacement);
|
|
70
|
+
root = replacement;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (rootId && hasRootVisibility(definition.uiConfig?.show, rootId)) fail('结构原语内部不得接管共享宿主显隐');
|
|
74
|
+
if (root?.hasAttribute('hidden') || root?.hasAttribute('style')) fail('结构根不得写入 hidden/style 显隐后门');
|
|
75
|
+
assertStructureLabel(definition, { label: definition.contract.props?.label?.default, ...suppliedProps, ...result.staticProps });
|
|
76
|
+
if (result.merge) {
|
|
77
|
+
if (!root || root.parentNode !== template.content || template.content.children.length !== 1
|
|
78
|
+
|| [...template.content.childNodes].some(node => node.nodeType === 3 && !!node.textContent?.trim())) {
|
|
79
|
+
fail('single-host 定义必须恰好有一个元素根');
|
|
80
|
+
}
|
|
81
|
+
if (plan?.internalRootId && plan.internalRootId !== rootId) fail('内部根别名与计划不符');
|
|
82
|
+
for (const attr of [...root.attributes]) {
|
|
83
|
+
if (attr.name === 'data-soma-id' || attr.name === 'class') continue;
|
|
84
|
+
if (attr.name === 'id' || attr.name.startsWith('data-soma-') || attr.name.startsWith('on')) fail('模板根不能覆盖外部身份属性');
|
|
85
|
+
if (host.hasAttribute(attr.name) && host.getAttribute(attr.name) !== attr.value) fail('模板根与外部宿主属性冲突');
|
|
86
|
+
}
|
|
87
|
+
result.rootAlias = rootId;
|
|
88
|
+
}
|
|
89
|
+
result.root = root;
|
|
90
|
+
return result;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function commitStructureTemplate(host: HTMLElement, prepared: PreparedStructureTemplate): void {
|
|
94
|
+
if (!prepared.merge) {
|
|
95
|
+
host.replaceChildren(prepared.fragment);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
const root = prepared.root!;
|
|
99
|
+
for (const attr of [...root.attributes]) {
|
|
100
|
+
if (attr.name === 'data-soma-id') continue;
|
|
101
|
+
if (attr.name === 'class') {
|
|
102
|
+
for (const name of [...root.classList]) host.classList.add(name);
|
|
103
|
+
} else host.setAttribute(attr.name, attr.value);
|
|
104
|
+
}
|
|
105
|
+
host.replaceChildren(...Array.from(root.childNodes));
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export function registerPreparedStructure(host: HTMLElement, definition: SomaComponentDefinition, scopeId: string, staticProps: Record<string, unknown>): void {
|
|
109
|
+
preparedHosts.set(host, { definition, scopeId, staticProps });
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function assertPreparedStructureProps(host: HTMLElement, props: Record<string, unknown>): void {
|
|
113
|
+
const prepared = preparedHosts.get(host);
|
|
114
|
+
const staticProps = prepared?.staticProps;
|
|
115
|
+
for (const [name, value] of Object.entries(staticProps ?? {})) {
|
|
116
|
+
if (props[name] !== value) fail('组件更新不能改变已冻结的结构语义属性');
|
|
117
|
+
}
|
|
118
|
+
if (prepared) {
|
|
119
|
+
assertStructureLabel(prepared.definition, props);
|
|
120
|
+
assertResolvedPrimitiveProps(prepared.definition, props);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** The new closed primitive protocol only; legacy component validation is unchanged. */
|
|
125
|
+
function assertResolvedPrimitiveProps(definition: SomaComponentDefinition, props: Record<string, unknown>): void {
|
|
126
|
+
const contract = definition.contract;
|
|
127
|
+
if (contract.structure?.tree_mount !== 'single-host'
|
|
128
|
+
|| !['Box', 'Region', 'Heading', 'Text', 'List'].includes(contract.name)) return;
|
|
129
|
+
const fields = contract.props ?? {};
|
|
130
|
+
for (const [name, value] of Object.entries(props)) {
|
|
131
|
+
const field = fields[name];
|
|
132
|
+
if (!field || (field.type === 'enum' ? !field.values?.some(option => option === value)
|
|
133
|
+
: field.type === 'array' ? !Array.isArray(value)
|
|
134
|
+
: field.type === 'object' ? value === null || typeof value !== 'object' || Array.isArray(value)
|
|
135
|
+
: typeof value !== field.type || (typeof value === 'number' && !Number.isFinite(value)))) {
|
|
136
|
+
fail('结构原语属性不符合契约类型或值域;拒绝本次挂载或属性更新');
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
for (const [name, field] of Object.entries(fields)) {
|
|
140
|
+
if (field.required && !Object.hasOwn(props, name)) fail('结构原语缺少必填属性');
|
|
141
|
+
}
|
|
142
|
+
if (contract.name === 'Box' && props.display === 'block' && props.gap !== 'none') {
|
|
143
|
+
fail('Box block 布局只允许 gap=none;拒绝本次挂载或属性更新');
|
|
144
|
+
}
|
|
145
|
+
if (contract.name === 'Text' && ((props.truncate === true && (props.wrap !== 'none' || props.line_clamp !== 0))
|
|
146
|
+
|| (props.line_clamp !== 0 && (props.truncate === true || props.wrap === 'none')))) {
|
|
147
|
+
fail('Text truncate/wrap/line_clamp 组合互斥;拒绝本次挂载或属性更新');
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function assertStructureLabel(definition: SomaComponentDefinition, props: Record<string, unknown>): void {
|
|
152
|
+
const semantics = definition.contract.structure?.semantics;
|
|
153
|
+
const token = semantics?.staticProp ? props[semantics.staticProp] : semantics?.default;
|
|
154
|
+
if (['nav', 'navigation', 'region'].includes(String(token))
|
|
155
|
+
&& (typeof props.label !== 'string' || !props.label.trim())) fail('命名导航或区域必须保持非空 label;拒绝本次挂载或属性更新');
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export function withPreparedStructureProps(host: HTMLElement, props: Record<string, unknown>, declared: Record<string, unknown>): Record<string, unknown> {
|
|
159
|
+
const result = { ...props };
|
|
160
|
+
for (const [name, value] of Object.entries(preparedHosts.get(host)?.staticProps ?? {})) {
|
|
161
|
+
if (!Object.prototype.hasOwnProperty.call(declared, name)) result[name] = value;
|
|
162
|
+
}
|
|
163
|
+
return result;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export function resolveCollectionOutlet(host: HTMLElement, plan: RepeatPlan): HTMLElement {
|
|
167
|
+
const prepared = preparedHosts.get(host);
|
|
168
|
+
if (!prepared || prepared.definition.contract.name !== plan.consumerOwner.componentName) fail('集合缺少已准备的消费组件');
|
|
169
|
+
const slot = prepared.definition.contract.structure?.slots?.[plan.consumerOwner.slotName];
|
|
170
|
+
if (slot?.kind !== 'collection' || slot.layoutRoot !== plan.consumerOwner.layoutRootKey
|
|
171
|
+
|| slot.rowContainer !== plan.consumerOwner.rowContainer) fail('集合计划与消费组件出口契约不符');
|
|
172
|
+
const anchor = prepared.definition.structureAdapter?.layoutRoots[plan.consumerOwner.layoutRootKey];
|
|
173
|
+
if (!anchor) fail('集合出口缺少受信内部根映射');
|
|
174
|
+
const adapter = new SomaScopedContainerAdapter(prepared.scopeId);
|
|
175
|
+
const root = adapter.findAnchor(host, anchor);
|
|
176
|
+
if (!root) fail('集合出口内部根不存在');
|
|
177
|
+
return root;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export function publishCollectionState(host: HTMLElement, root: HTMLElement, phase: 'pending' | 'ready' | 'error', count: number, generation: number): void {
|
|
181
|
+
const prepared = preparedHosts.get(host);
|
|
182
|
+
if (!prepared) return;
|
|
183
|
+
root.setAttribute('aria-busy', String(phase === 'pending'));
|
|
184
|
+
root.setAttribute('data-soma-collection-phase', phase);
|
|
185
|
+
root.setAttribute('data-soma-collection-generation', String(generation));
|
|
186
|
+
const emptyAnchor = prepared.definition.structureAdapter?.layoutRoots.empty;
|
|
187
|
+
if (emptyAnchor) {
|
|
188
|
+
const empty = new SomaScopedContainerAdapter(prepared.scopeId).findAnchor(host, emptyAnchor);
|
|
189
|
+
if (empty) empty.hidden = phase !== 'ready' || count !== 0;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function hasRootVisibility(show: unknown, rootId: string): boolean {
|
|
194
|
+
if (!show || typeof show !== 'object') return false;
|
|
195
|
+
for (const [key, value] of Object.entries(show)) {
|
|
196
|
+
if (key === `${rootId}@hidden` || key === `${rootId}@style`) return true;
|
|
197
|
+
if (!value || typeof value !== 'object') continue;
|
|
198
|
+
const config = value as Record<string, unknown>;
|
|
199
|
+
if (key === rootId && config.when !== undefined) return true;
|
|
200
|
+
if (config.show && hasRootVisibility(config.show, rootId)) return true;
|
|
201
|
+
}
|
|
202
|
+
return false;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function fail(fixHint: string): never {
|
|
206
|
+
throw new SomaComponentTreeError({ code: 'CT-STRUCTURE-MOUNT', phase: 'runtime', sourceId: 'runtime', nodePath: 'component', fixHint });
|
|
207
|
+
}
|
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
type SomaContractField,
|
|
20
20
|
} from '../../shared/types/component-contract.types';
|
|
21
21
|
import { deriveContractSample, hasRenderableSample } from '../../shared/component/derive-sample';
|
|
22
|
+
import { copyCatalogExamples } from './catalog-examples';
|
|
22
23
|
|
|
23
24
|
const LAYERS = new Set(['atom', 'composite', 'solution', 'template', 'page', 'token']);
|
|
24
25
|
|
|
@@ -154,10 +155,26 @@ function verifyDefinition(key: string, definition: SomaComponentDefinition): str
|
|
|
154
155
|
if (ai.example === undefined || (typeof ai.example === 'string' && !ai.example.trim())) {
|
|
155
156
|
issues.push(`[目录] ${label} 的 ai.example 为空——给一段能直接用的四件套片段`);
|
|
156
157
|
}
|
|
158
|
+
if (ai.examples !== undefined) {
|
|
159
|
+
try { copyCatalogExamples(ai.examples as Parameters<typeof copyCatalogExamples>[0]); }
|
|
160
|
+
catch { issues.push(`[目录] ${label} 的 ai.examples 格式/语法版本/统一声明非法`); }
|
|
161
|
+
}
|
|
157
162
|
}
|
|
158
163
|
|
|
159
164
|
const template = definition.templateHtml;
|
|
160
|
-
|
|
165
|
+
const macro = definition.contract.structure?.kind === 'fragment-macro';
|
|
166
|
+
if (macro) {
|
|
167
|
+
const structure = definition.contract.structure!;
|
|
168
|
+
const slots = definition.contract.slots;
|
|
169
|
+
const executableFields = ['controllerFactory', 'uiConfig', 'eventConfig', 'services', 'styleFeatures'] as const;
|
|
170
|
+
const runtimeContractFields = ['props', 'emits', 'tokens', 'keyboard', 'overlay'] as const;
|
|
171
|
+
if (template !== '' || !structure.rootless || structure.tree_mount !== 'erase'
|
|
172
|
+
|| structure.semantics !== undefined || slots?.content?.required !== true || Object.keys(slots ?? {}).length !== 1
|
|
173
|
+
|| executableFields.some((field) => definition[field] !== undefined)
|
|
174
|
+
|| runtimeContractFields.some((field) => definition.contract[field] !== undefined)) {
|
|
175
|
+
issues.push(`[结构] ${label} 的 fragment-macro 必须是空模板、必填content与纯编译元数据,不得带运行时能力`);
|
|
176
|
+
}
|
|
177
|
+
} else if (typeof template !== 'string' || !template.trim()) {
|
|
161
178
|
issues.push(`[模板] ${label} 的 templateHtml 为空`);
|
|
162
179
|
} else {
|
|
163
180
|
if (/data-soma-scoped-id=/.test(template)) {
|
|
@@ -291,6 +308,9 @@ function verifyStyleRegistration(pack: SomaComponentPack): string[] {
|
|
|
291
308
|
const sharedNames = new Set(Object.keys(styles.shared ?? {}));
|
|
292
309
|
|
|
293
310
|
for (const name of Object.keys(styles.components ?? {})) {
|
|
311
|
+
if (pack.components[name]?.contract.structure?.kind === 'fragment-macro') {
|
|
312
|
+
issues.push(`[结构] 编译宏 ${name} 不得登记运行时 CSS`);
|
|
313
|
+
}
|
|
294
314
|
if (!componentNames.has(name)) {
|
|
295
315
|
issues.push(
|
|
296
316
|
`[样式] 为 "${name}" 登记了组件样式,但包里没有这个组件——`
|
|
@@ -331,6 +351,9 @@ function verifyStyleDiscipline(pack: SomaComponentPack): string[] {
|
|
|
331
351
|
+ '裸色值会让换肤对这个组件失效,而且不报错',
|
|
332
352
|
);
|
|
333
353
|
}
|
|
354
|
+
for (const problem of colorRolePairing(css)) {
|
|
355
|
+
issues.push(`[配色] ${label} ${problem}`);
|
|
356
|
+
}
|
|
334
357
|
for (const property of physicalDirections(css)) {
|
|
335
358
|
issues.push(
|
|
336
359
|
`[RTL] ${label} 使用物理方向属性 ${property}——请改用逻辑属性`
|
|
@@ -342,6 +365,46 @@ function verifyStyleDiscipline(pack: SomaComponentPack): string[] {
|
|
|
342
365
|
return issues;
|
|
343
366
|
}
|
|
344
367
|
|
|
368
|
+
const TONE = '(primary|secondary|accent|neutral|info|success|warning|danger)';
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* 颜色角色配对:令牌化了仍可能不可读——配对错了同样"不报错但坏掉"。
|
|
372
|
+
*
|
|
373
|
+
* 与 soma-ui 自身的配色闸门同一套判据(《soma 视觉与空间规范》§11):
|
|
374
|
+
* ① `--soma-c-X` 是填充色,不能当文字色(46 套出厂预设下当字最差 1.01:1),彩色文字用 `-on-soft`;
|
|
375
|
+
* ② 实心底 `--soma-c-X` 上写了字色,就必须是同语气 `-fg`;
|
|
376
|
+
* ③ 淡底 `--soma-c-X-soft` 上写了字色,不能是 `--soma-c-X` 或 `-fg`(引擎只对 `-on-soft` 承诺 AA);
|
|
377
|
+
* ④ 渐变不跨语气(primary→accent 在功能配色下是蓝→橙,读起来像两种状态)。
|
|
378
|
+
* 只看同一条规则内的配对;字色压在祖先的底上这类跨规则关系静态看不到,不在准入线内。
|
|
379
|
+
*/
|
|
380
|
+
function colorRolePairing(css: string): string[] {
|
|
381
|
+
const found = new Set<string>();
|
|
382
|
+
const flat = css.replace(/\/\*[\s\S]*?\*\//g, '');
|
|
383
|
+
for (const match of flat.matchAll(/([^{}@]+)\{([^{}]*)\}/g)) {
|
|
384
|
+
const selector = match[1].trim().slice(0, 60);
|
|
385
|
+
const body = match[2];
|
|
386
|
+
const color = /(?:^|;)\s*color\s*:\s*([^;]+)/.exec(body)?.[1]?.trim() ?? '';
|
|
387
|
+
const fillAsText = new RegExp(`^var\\(--soma-c-${TONE}\\s*[,)]`).exec(color);
|
|
388
|
+
if (fillAsText) {
|
|
389
|
+
found.add(`${selector} 把填充色 --soma-c-${fillAsText[1]} 当文字色——彩色文字用 var(--soma-c-${fillAsText[1]}-on-soft, 回退)`);
|
|
390
|
+
}
|
|
391
|
+
const solid = new RegExp(`background(?:-color)?\\s*:\\s*var\\(--soma-c-${TONE}\\s*[,)]`).exec(body);
|
|
392
|
+
if (solid && color && !/^(inherit|currentColor|transparent)$/.test(color)
|
|
393
|
+
&& !new RegExp(`^var\\(--soma-(c-${solid[1]}-fg|ui-tone-fg)\\b`).test(color)) {
|
|
394
|
+
found.add(`${selector} 实心底 --soma-c-${solid[1]} 上的字色必须是 var(--soma-c-${solid[1]}-fg, 回退)`);
|
|
395
|
+
}
|
|
396
|
+
const soft = new RegExp(`background(?:-color)?\\s*:\\s*var\\(--soma-c-${TONE}-soft\\s*[,)]`).exec(body);
|
|
397
|
+
if (soft && new RegExp(`^var\\(--soma-c-${soft[1]}(-fg)?\\s*[,)]`).test(color)) {
|
|
398
|
+
found.add(`${selector} 淡底 --soma-c-${soft[1]}-soft 上的字色必须是 var(--soma-c-${soft[1]}-on-soft, 回退)`);
|
|
399
|
+
}
|
|
400
|
+
for (const gradient of body.matchAll(/gradient\(([^;]+)/g)) {
|
|
401
|
+
const tones = new Set([...gradient[1].matchAll(new RegExp(`--soma-c-${TONE}\\b`, 'g'))].map((item) => item[1]));
|
|
402
|
+
if (tones.size > 1) found.add(`${selector} 渐变混用了 ${[...tones].join(' / ')} 两种语气——同色相用 color-mix 调明度`);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
return [...found];
|
|
406
|
+
}
|
|
407
|
+
|
|
345
408
|
/** 收集裸色值:var(--x, #fff) 的回退位不算 */
|
|
346
409
|
function nakedColors(css: string): string[] {
|
|
347
410
|
const found = new Set<string>();
|
|
@@ -67,7 +67,7 @@ export class SomaAssetResolver {
|
|
|
67
67
|
};
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
const cacheKey = `${uiYaml}\0${eventYaml}\0${localeYaml}\0${assets.appConfigYaml ?? ''}\0${assets.styleYaml ?? ''}`;
|
|
70
|
+
const cacheKey = `${uiYaml}\0${eventYaml}\0${localeYaml}\0${assets.appConfigYaml ?? ''}\0${assets.styleYaml ?? ''}\0${assets.dataYaml ?? ''}\0${assets.sourceMarkup ?? 'legacy-html'}\0${assets.artifact?.artifactDigest ?? ''}`;
|
|
71
71
|
const cached = this.cache.get(cacheKey);
|
|
72
72
|
if (cached) {
|
|
73
73
|
return cached;
|