soma-core 2.2.9 → 2.2.11

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.
Files changed (51) hide show
  1. package/README.md +8 -19
  2. package/bin/service-codegen.cjs +2 -3
  3. package/bin/soma.cjs +2 -2
  4. package/core/build/compiler/soma-precompile.js +19 -6
  5. package/core/client/data/region-scope-port.ts +8 -3
  6. package/core/client/engine/event-engine.ts +1 -1
  7. package/core/client/engine/soma-bootstrap.ts +9 -0
  8. package/core/client/engines/diff/code.ts +205 -0
  9. package/core/client/engines/diff/index.ts +27 -1
  10. package/core/client/engines/diff/port.ts +75 -0
  11. package/core/client/parser/confirm-spec.ts +10 -4
  12. package/core/client/parser/ui-config-parser.ts +14 -2
  13. package/core/index.ts +1 -1
  14. package/core/server/api/load-host-service.ts +0 -1
  15. package/core/server/host/source-packages.cjs +3 -0
  16. package/core/shared/registry-generated/diagnostic-registry-index.ts +16 -0
  17. package/core/shared/registry-generated/diagnostic-registry.ts +130 -0
  18. package/core/shared/registry-generated/limits.ts +6 -2
  19. package/core/shared/registry-generated/std-grammar-views.ts +1 -1
  20. package/core/shared/registry-generated/std-grammar.ts +1 -1
  21. package/core/shared/types/region-scope.types.ts +6 -0
  22. package/dist/browser/runtime-bundle.manifest.json +12 -12
  23. package/dist/browser/soma-runtime.js +752 -489
  24. package/dist/core/index.cjs +752 -489
  25. package/dist/host-native/aot-builder.cjs +366 -226
  26. package/dist/host-native/native-server.cjs +131 -56
  27. package/dist/lsp/component-tree.cjs +23 -10
  28. package/dist/types/client/data/region-scope-port.d.ts +1 -1
  29. package/dist/types/client/engine/soma-bootstrap.d.ts +5 -0
  30. package/dist/types/client/engines/diff/code.d.ts +27 -0
  31. package/dist/types/client/engines/diff/index.d.ts +2 -1
  32. package/dist/types/client/engines/diff/port.d.ts +77 -0
  33. package/dist/types/client/parser/confirm-spec.d.ts +1 -1
  34. package/dist/types/server/host/source-packages.d.cts +5 -0
  35. package/dist/types/shared/registry-generated/diagnostic-registry.d.ts +113 -1
  36. package/dist/types/shared/registry-generated/limits.d.ts +4 -0
  37. package/dist/types/shared/registry-generated/std-grammar-views.d.ts +1 -1
  38. package/dist/types/shared/registry-generated/std-grammar.d.ts +1 -1
  39. package/dist/types/shared/types/region-scope.types.d.ts +6 -0
  40. package/host-native/bin/host-native.cjs +1 -1
  41. package/host-native/client/browser-entry.ts +12 -1
  42. package/host-native/client/first-frame.ts +8 -0
  43. package/host-native/client/router-bridge.ts +8 -2
  44. package/host-native/src/aot-builder.ts +173 -93
  45. package/host-native/src/native-server.ts +131 -25
  46. package/host-native/src/public-packages.cjs +156 -50
  47. package/host-native/styles/globals.css +28 -2
  48. package/package.json +2 -2
  49. package/dist/core/adaptive-pure.cjs +0 -41
  50. package/dist/core/theme-pure.cjs +0 -38
  51. package/dist/preview-export.cjs +0 -3401
@@ -2,6 +2,11 @@
2
2
 
3
3
  const fs = require('node:fs');
4
4
  const path = require('node:path');
5
+ const {
6
+ isSomaSourcePackage,
7
+ readExplicitSourcePackages,
8
+ resolvePackageRoot,
9
+ } = require('../../core/server/host/source-packages.cjs');
5
10
 
6
11
  function readJson(filePath) {
7
12
  try {
@@ -16,6 +21,16 @@ function isSafePackageChild(packageRoot, candidate) {
16
21
  return candidate === packageRoot || candidate.startsWith(`${packageRoot}${path.sep}`);
17
22
  }
18
23
 
24
+ function isDirectoryOrSymlinkToDir(baseDir, entry) {
25
+ if (entry.isDirectory()) return true;
26
+ if (!entry.isSymbolicLink()) return false;
27
+ try {
28
+ return fs.statSync(path.join(baseDir, entry.name)).isDirectory();
29
+ } catch {
30
+ return false;
31
+ }
32
+ }
33
+
19
34
  function collectFiles(root) {
20
35
  if (!fs.existsSync(root) || !fs.statSync(root).isDirectory()) return [];
21
36
  const files = [];
@@ -60,59 +75,68 @@ function expandWildcardExportAliases(packageName, packageRoot, entry, target) {
60
75
  }
61
76
 
62
77
  /**
63
- * 枚举单个包 package.json 中的公开 exports 映射表。
78
+ * 枚举单个包 package.json 中的公开 exports 映射表(缺省 exports 时回退 main)。
64
79
  * 返回 map: specifier -> resolvedFilePath
65
80
  */
66
81
  function readPublicPackageAliases(packageName, packageRoot) {
67
- const exportsMap = readJson(path.join(packageRoot, 'package.json'))?.exports;
68
- if (!exportsMap || typeof exportsMap !== 'object') return {};
82
+ const pkgJson = readJson(path.join(packageRoot, 'package.json'));
83
+ const exportsMap = pkgJson?.exports;
69
84
 
70
85
  const exactAliases = {};
71
86
  const wildcardAliases = {};
72
87
 
73
- for (const [entry, descriptor] of Object.entries(exportsMap)) {
74
- if (entry !== '.' && !entry.startsWith('./')) continue;
75
- let target = null;
76
- if (typeof descriptor === 'string') {
77
- target = descriptor;
78
- } else if (descriptor && typeof descriptor === 'object') {
79
- target =
80
- descriptor.import?.default ??
81
- descriptor.import ??
82
- descriptor.default ??
83
- descriptor.require?.default ??
84
- descriptor.require;
85
- if (typeof target === 'object' && target !== null) {
86
- target = target.default;
88
+ if (exportsMap && typeof exportsMap === 'object') {
89
+ for (const [entry, descriptor] of Object.entries(exportsMap)) {
90
+ if (entry !== '.' && !entry.startsWith('./')) continue;
91
+ let target = null;
92
+ if (typeof descriptor === 'string') {
93
+ target = descriptor;
94
+ } else if (descriptor && typeof descriptor === 'object') {
95
+ target =
96
+ descriptor.import?.default ??
97
+ descriptor.import ??
98
+ descriptor.default ??
99
+ descriptor.require?.default ??
100
+ descriptor.require;
101
+ if (typeof target === 'object' && target !== null) {
102
+ target = target.default;
103
+ }
104
+ }
105
+ if (typeof target !== 'string' || !target.startsWith('./')) continue;
106
+
107
+ const isWildcard = entry.includes('*') || target.includes('*');
108
+ if (entry.includes('*') !== target.includes('*')) continue;
109
+ if (isWildcard) {
110
+ Object.assign(
111
+ wildcardAliases,
112
+ expandWildcardExportAliases(packageName, packageRoot, entry, target),
113
+ );
114
+ continue;
87
115
  }
116
+
117
+ const resolved = path.resolve(packageRoot, target);
118
+ if (!isSafePackageChild(packageRoot, resolved) || !fs.existsSync(resolved)) continue;
119
+ const publicPath = entry === '.' ? '' : entry.slice(2);
120
+ const specifier = publicPath ? `${packageName}/${publicPath}` : packageName;
121
+ exactAliases[specifier] = resolved;
88
122
  }
89
- if (typeof target !== 'string' || !target.startsWith('./')) continue;
90
-
91
- const isWildcard = entry.includes('*') || target.includes('*');
92
- if (entry.includes('*') !== target.includes('*')) continue;
93
- if (isWildcard) {
94
- Object.assign(
95
- wildcardAliases,
96
- expandWildcardExportAliases(packageName, packageRoot, entry, target),
97
- );
98
- continue;
123
+ } else if (typeof pkgJson?.main === 'string' && pkgJson.main.trim()) {
124
+ const resolved = path.resolve(packageRoot, pkgJson.main.trim());
125
+ if (isSafePackageChild(packageRoot, resolved) && fs.existsSync(resolved) && fs.statSync(resolved).isFile()) {
126
+ exactAliases[packageName] = resolved;
99
127
  }
100
-
101
- const resolved = path.resolve(packageRoot, target);
102
- if (!isSafePackageChild(packageRoot, resolved) || !fs.existsSync(resolved)) continue;
103
- const publicPath = entry === '.' ? '' : entry.slice(2);
104
- const specifier = publicPath ? `${packageName}/${publicPath}` : packageName;
105
- exactAliases[specifier] = resolved;
106
128
  }
107
129
 
108
130
  return { ...wildcardAliases, ...exactAliases };
109
131
  }
110
132
 
111
133
  /**
112
- * 扫描仓库/依赖中的全部 soma-* 包并生成完整的别名表
134
+ * 扫描仓库/依赖中的全部 soma-* 包及声明了 soma.source(或 SOMA_SOURCE_PACKAGES)的源包,
135
+ * 生成完整的公开入口别名表。源包判定唯一复用 core/server/host/source-packages.cjs(S1-d)。
113
136
  */
114
- function readAllSomaPublicAliases(hostDir, repoRoot, extraRoots = []) {
137
+ function readAllSomaPublicAliases(hostDir, repoRoot, extraRoots = [], env = process.env) {
115
138
  const aliases = {};
139
+ const explicitPackages = new Set(readExplicitSourcePackages(env));
116
140
  const searchRoots = [
117
141
  repoRoot,
118
142
  path.join(repoRoot, 'soma-core'),
@@ -130,37 +154,119 @@ function readAllSomaPublicAliases(hostDir, repoRoot, extraRoots = []) {
130
154
  }
131
155
 
132
156
  const seenPackages = new Set();
157
+ const seenNodeModules = new Set();
158
+
159
+ const shouldIncludePackage = (pkgName, pkgRoot) =>
160
+ Boolean(pkgName) && (pkgName.startsWith('soma-') || isSomaSourcePackage(pkgRoot, explicitPackages.has(pkgName)));
161
+
162
+ const registerPackage = (pkgName, linkedRoot) => {
163
+ if (!pkgName || seenPackages.has(pkgName) || !fs.existsSync(linkedRoot)) return;
164
+ // 别名一律落到包的真实路径:esbuild 对插件返回的路径不再做 realpath,若保留软链路径(如宿主
165
+ // node_modules/soma-ai -> ../../soma/soma-ai),包内的三方依赖(如 soma-ai 的 `ai`)会从宿主的
166
+ // node_modules 起找而解析失败,同一个包也会经不同软链路径各装一份(单例分裂)。
167
+ let pkgRoot = linkedRoot;
168
+ try {
169
+ pkgRoot = fs.realpathSync(linkedRoot);
170
+ } catch {
171
+ /* keep linked path */
172
+ }
173
+ if (!shouldIncludePackage(pkgName, pkgRoot)) return;
174
+ seenPackages.add(pkgName);
175
+ Object.assign(aliases, readPublicPackageAliases(pkgName, pkgRoot));
176
+ // 递归检查源包自带的嵌套 node_modules(防止传递源包未被提升到宿主根时漏扫)
177
+ const nestedNm = path.join(pkgRoot, 'node_modules');
178
+ if (fs.existsSync(nestedNm)) scanNodeModules(nestedNm);
179
+ };
180
+
181
+ const scanNodeModules = (nmDir) => {
182
+ let realNm = path.resolve(nmDir);
183
+ try {
184
+ realNm = fs.realpathSync(nmDir);
185
+ } catch {
186
+ /* keep resolved */
187
+ }
188
+ if (seenNodeModules.has(realNm)) return;
189
+ seenNodeModules.add(realNm);
190
+
191
+ let entries = [];
192
+ try {
193
+ entries = fs.readdirSync(nmDir, { withFileTypes: true });
194
+ } catch {
195
+ return;
196
+ }
197
+ for (const entry of entries) {
198
+ if (entry.name.startsWith('.')) continue;
199
+ if (!isDirectoryOrSymlinkToDir(nmDir, entry)) continue;
200
+ const entryPath = path.join(nmDir, entry.name);
201
+ if (entry.name.startsWith('@')) {
202
+ let scopedEntries = [];
203
+ try {
204
+ scopedEntries = fs.readdirSync(entryPath, { withFileTypes: true });
205
+ } catch {
206
+ scopedEntries = [];
207
+ }
208
+ for (const scoped of scopedEntries) {
209
+ if (scoped.name.startsWith('.')) continue;
210
+ if (!isDirectoryOrSymlinkToDir(entryPath, scoped)) continue;
211
+ registerPackage(`${entry.name}/${scoped.name}`, path.join(entryPath, scoped.name));
212
+ }
213
+ } else {
214
+ registerPackage(entry.name, entryPath);
215
+ }
216
+ }
217
+ };
133
218
 
134
219
  for (const searchRoot of searchRoots) {
135
- if (!fs.existsSync(searchRoot)) continue;
220
+ if (!searchRoot || !fs.existsSync(searchRoot)) continue;
136
221
  const pkgJsonPath = path.join(searchRoot, 'package.json');
137
222
  const pkgJson = readJson(pkgJsonPath);
138
- if (pkgJson?.name && pkgJson.name.startsWith('soma-') && !seenPackages.has(pkgJson.name)) {
139
- seenPackages.add(pkgJson.name);
140
- Object.assign(aliases, readPublicPackageAliases(pkgJson.name, searchRoot));
223
+ if (pkgJson?.name) {
224
+ registerPackage(pkgJson.name, searchRoot);
225
+ }
226
+
227
+ // 检查声明在 dependencies / devDependencies(含 file: 依赖)及 SOMA_SOURCE_PACKAGES 里的源包
228
+ const deps = {
229
+ ...(pkgJson?.dependencies ?? {}),
230
+ ...(pkgJson?.devDependencies ?? {}),
231
+ };
232
+ const depNames = new Set([...Object.keys(deps), ...explicitPackages]);
233
+ for (const depName of depNames) {
234
+ if (seenPackages.has(depName)) continue;
235
+ const depRoot = resolvePackageRoot(searchRoot, depName, deps[depName]);
236
+ if (depRoot) registerPackage(depName, depRoot);
141
237
  }
142
238
 
143
- // 检查子目录或 node_modules
239
+ // 扫描 node_modules(含实包、软链与 @scope/*)
144
240
  const nm = path.join(searchRoot, 'node_modules');
145
241
  if (fs.existsSync(nm)) {
146
- try {
147
- for (const entry of fs.readdirSync(nm, { withFileTypes: true })) {
148
- if (!entry.isDirectory()) continue;
149
- if (entry.name.startsWith('soma-') && !seenPackages.has(entry.name)) {
150
- const pkgPath = path.join(nm, entry.name);
151
- seenPackages.add(entry.name);
152
- Object.assign(aliases, readPublicPackageAliases(entry.name, pkgPath));
153
- }
154
- }
155
- } catch {}
242
+ scanNodeModules(nm);
156
243
  }
157
244
  }
158
245
 
159
246
  return aliases;
160
247
  }
161
248
 
249
+ /**
250
+ * 根据别名表构造 esbuild `onResolve` 过滤正则(精确覆盖全部公开包根,含 `@scope/pkg`);空表返回 null。
251
+ */
252
+ function createPublicAliasesFilter(aliases) {
253
+ const roots = new Set();
254
+ for (const spec of Object.keys(aliases || {})) {
255
+ const root = spec.startsWith('@')
256
+ ? spec.split('/').slice(0, 2).join('/')
257
+ : spec.split('/')[0];
258
+ if (root) roots.add(root);
259
+ }
260
+ if (roots.size === 0) return null;
261
+ const escaped = [...roots]
262
+ .sort()
263
+ .map((name) => name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'));
264
+ return new RegExp(`^(?:${escaped.join('|')})(?:/.*)?$`);
265
+ }
266
+
162
267
  module.exports = {
163
268
  readJson,
164
269
  readPublicPackageAliases,
165
270
  readAllSomaPublicAliases,
271
+ createPublicAliasesFilter,
166
272
  };
@@ -21,8 +21,9 @@ body {
21
21
  margin: 0;
22
22
  }
23
23
 
24
+ /* 主题 CSS 进文档前(水合期)的回落值取画布系统色 Canvas(随 color-scheme),与主题画布同色,挂载前后底色不跳变 */
24
25
  body {
25
- background: var(--soma-surface-base, #f8fafc);
26
+ background: var(--soma-surface-base, Canvas);
26
27
  color: var(--soma-text-primary, #1f2937);
27
28
  font-family: var(--soma-font-family, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif);
28
29
  }
@@ -69,6 +70,31 @@ select {
69
70
  color: inherit;
70
71
  text-decoration: inherit;
71
72
  }
73
+
74
+ /*
75
+ * 浮层根(data-soma-overlay-root,挂在 body 下、不在组件宿主里)补齐与组件宿主相同的归零范围:标题 / 段落、列表、表格、链接。
76
+ * 只在文档根带 data-soma-overlay-reset 时生效(宿主选择加入;soma-kit 在主题流水线新模式启动时写上),
77
+ * 没有这个标记的页面(含 soma-kit 旧版)浮层外观不变。表单控件的归零上面一条已覆盖浮层根,不受此标记限定。
78
+ */
79
+ :where([data-soma-overlay-reset] [data-soma-overlay-root]) :where(h1, h2, h3, h4, h5, h6, p, blockquote, figure, dl, dd) {
80
+ margin: 0;
81
+ }
82
+
83
+ :where([data-soma-overlay-reset] [data-soma-overlay-root]) :where(ol, ul, menu) {
84
+ list-style: none;
85
+ margin: 0;
86
+ padding: 0;
87
+ }
88
+
89
+ :where([data-soma-overlay-reset] [data-soma-overlay-root]) table {
90
+ border-collapse: collapse;
91
+ text-indent: 0;
92
+ }
93
+
94
+ :where([data-soma-overlay-reset] [data-soma-overlay-root]) a {
95
+ color: inherit;
96
+ text-decoration: inherit;
97
+ }
72
98
  }
73
99
 
74
100
  .soma-hidden {
@@ -84,7 +110,7 @@ select {
84
110
  display: grid;
85
111
  min-block-size: 100dvh;
86
112
  place-items: center;
87
- background: var(--soma-surface-base, #f8fafc);
113
+ background: var(--soma-surface-base, Canvas);
88
114
  color: var(--soma-text-primary, #374151);
89
115
  }
90
116
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "soma-core",
3
- "version": "2.2.9",
3
+ "version": "2.2.11",
4
4
  "description": "SOMA — Semantic Oriented Modular Architecture. A declarative frontend framework runtime with no UI framework dependency; native host shell ships in host-native/.",
5
5
  "keywords": [
6
6
  "soma",
@@ -346,7 +346,7 @@
346
346
  "parse5": "7.3.0",
347
347
  "qrcode-generator": "2.0.4",
348
348
  "server-only": "0.0.1",
349
- "soma-foundation": "^0.1.6",
349
+ "soma-foundation": "^0.1.7",
350
350
  "temporal-polyfill": "0.3.2"
351
351
  },
352
352
  "peerDependencies": {
@@ -1,41 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // core/shared/adaptive-pure.ts
21
- var adaptive_pure_exports = {};
22
- __export(adaptive_pure_exports, {
23
- SOMA_ADAPTIVE_MAX_LADDER: () => import_adaptive2.SOMA_ADAPTIVE_MAX_LADDER,
24
- SOMA_ADAPTIVE_PROFILES: () => import_adaptive2.SOMA_ADAPTIVE_PROFILES,
25
- SOMA_DEFAULT_HYSTERESIS: () => import_adaptive.SOMA_DEFAULT_HYSTERESIS,
26
- resolveTierWithHysteresis: () => import_adaptive.resolveTierWithHysteresis
27
- });
28
- module.exports = __toCommonJS(adaptive_pure_exports);
29
-
30
- // core/client/adaptive/hysteresis.ts
31
- var import_adaptive = require("soma-foundation/adaptive");
32
-
33
- // core/shared/types/adaptive.types.ts
34
- var import_adaptive2 = require("soma-foundation/adaptive");
35
- // Annotate the CommonJS export names for ESM import in node:
36
- 0 && (module.exports = {
37
- SOMA_ADAPTIVE_MAX_LADDER,
38
- SOMA_ADAPTIVE_PROFILES,
39
- SOMA_DEFAULT_HYSTERESIS,
40
- resolveTierWithHysteresis
41
- });
@@ -1,38 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // core/client/theme/theme-derivation.ts
21
- var theme_derivation_exports = {};
22
- __export(theme_derivation_exports, {
23
- contrastRatio: () => import_theme_derivation.contrastRatio,
24
- deriveTheme: () => import_theme_derivation.deriveTheme,
25
- hexToOklch: () => import_theme_derivation.hexToOklch,
26
- oklchToHex: () => import_theme_derivation.oklchToHex,
27
- themeRootAttributes: () => import_theme_derivation.themeRootAttributes
28
- });
29
- module.exports = __toCommonJS(theme_derivation_exports);
30
- var import_theme_derivation = require("soma-foundation/theme/theme-derivation");
31
- // Annotate the CommonJS export names for ESM import in node:
32
- 0 && (module.exports = {
33
- contrastRatio,
34
- deriveTheme,
35
- hexToOklch,
36
- oklchToHex,
37
- themeRootAttributes
38
- });