soma-core 2.2.7 → 2.2.9

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 (109) hide show
  1. package/core/build/compiler/full-manifest-builder.ts +1 -1
  2. package/core/build/compiler/host-config-sync.cjs +1 -1
  3. package/core/build/compiler/soma-manifest-webpack-plugin.js +2 -6
  4. package/core/build/compiler/soma-precompile.js +80 -4
  5. package/core/client/a11y/announcer.ts +2 -16
  6. package/core/client/base/SomaPageRootBase.ts +2 -2
  7. package/core/client/base/defineSomaView.ts +11 -2
  8. package/core/client/base/runtime-services.types.ts +57 -0
  9. package/core/client/data/data-object-resolver.ts +36 -5
  10. package/core/client/data/role-gate.ts +2 -8
  11. package/core/client/engine/event-engine.ts +1 -0
  12. package/core/client/engines/chart/adapter-echarts.ts +75 -2
  13. package/core/client/engines/chart/index.ts +18 -0
  14. package/core/client/engines/chart/port.ts +13 -0
  15. package/core/client/engines/diff/adapter-jsdiff.ts +27 -8
  16. package/core/client/engines/diff/index.ts +81 -6
  17. package/core/client/engines/diff/items.ts +212 -0
  18. package/core/client/engines/diff/port.ts +140 -3
  19. package/core/client/engines/diff/prose.ts +443 -0
  20. package/core/client/engines/engine-adapters.ts +6 -0
  21. package/core/client/engines/highlight/adapter-lezer.ts +109 -0
  22. package/core/client/engines/highlight/index.ts +135 -0
  23. package/core/client/engines/highlight/port.ts +92 -0
  24. package/core/client/engines/markdown/adapter-markdown-it.ts +65 -0
  25. package/core/client/engines/markdown/blocks.ts +335 -0
  26. package/core/client/engines/markdown/index.ts +51 -0
  27. package/core/client/engines/markdown/port.ts +94 -0
  28. package/core/client/engines/markdown/vendor-modules.d.ts +6 -0
  29. package/core/client/engines/structured/adapter-js-yaml.ts +33 -0
  30. package/core/client/engines/structured/index.ts +139 -0
  31. package/core/client/engines/structured/port.ts +59 -0
  32. package/core/client/infra/http/SomaHttpService.ts +2 -4
  33. package/core/client/infra/notify/DefaultNotifyService.ts +2 -3
  34. package/core/client/infra/permission/SomaPermission.ts +1 -1
  35. package/core/client/render-ports/notify-renderer.ts +2 -46
  36. package/core/client/runtime/SomaRuntimeServices.ts +16 -45
  37. package/core/server/host/app-config-composer.ts +6 -52
  38. package/core/server/host/host-config-paths.cjs +2 -100
  39. package/core/server/host/precompiled-manifest.ts +69 -0
  40. package/core/server/infra/host-config-paths.cjs +100 -0
  41. package/core/server/page-assets.ts +2 -70
  42. package/core/server/runtime-space/bindings.ts +76 -1
  43. package/core/server/runtime-space/digest.ts +6 -0
  44. package/core/server/runtime-space/index.ts +1 -1
  45. package/core/server/runtime-space/prewarm.ts +8 -8
  46. package/core/server/runtime-space/store.ts +23 -7
  47. package/core/server/runtime-space/types.ts +3 -2
  48. package/core/shared/app-config-merge.ts +59 -0
  49. package/core/shared/registry-generated/limits.ts +80 -4
  50. package/core/shared/types/announcer.types.ts +18 -0
  51. package/core/shared/types/notify.types.ts +26 -0
  52. package/core/shared/types/role-gate.types.ts +11 -0
  53. package/dist/browser/runtime-bundle.manifest.json +50 -7
  54. package/dist/browser/soma-runtime.js +120022 -103991
  55. package/dist/core/index.cjs +113888 -97846
  56. package/dist/host-native/aot-builder.cjs +277 -189
  57. package/dist/host-native/native-server.cjs +245 -84
  58. package/dist/lsp/component-tree.cjs +80 -4
  59. package/dist/types/build/compiler/full-manifest-builder.d.ts +1 -1
  60. package/dist/types/client/a11y/announcer.d.ts +2 -14
  61. package/dist/types/client/base/SomaPageRootBase.d.ts +2 -2
  62. package/dist/types/client/base/runtime-services.types.d.ts +50 -0
  63. package/dist/types/client/data/role-gate.d.ts +2 -8
  64. package/dist/types/client/engines/chart/index.d.ts +1 -1
  65. package/dist/types/client/engines/chart/port.d.ts +15 -0
  66. package/dist/types/client/engines/diff/index.d.ts +1 -1
  67. package/dist/types/client/engines/diff/items.d.ts +24 -0
  68. package/dist/types/client/engines/diff/port.d.ts +124 -2
  69. package/dist/types/client/engines/diff/prose.d.ts +80 -0
  70. package/dist/types/client/engines/engine-adapters.d.ts +6 -0
  71. package/dist/types/client/engines/highlight/adapter-lezer.d.ts +6 -0
  72. package/dist/types/client/engines/highlight/index.d.ts +15 -0
  73. package/dist/types/client/engines/highlight/port.d.ts +64 -0
  74. package/dist/types/client/engines/markdown/adapter-markdown-it.d.ts +6 -0
  75. package/dist/types/client/engines/markdown/blocks.d.ts +29 -0
  76. package/dist/types/client/engines/markdown/index.d.ts +9 -0
  77. package/dist/types/client/engines/markdown/port.d.ts +166 -0
  78. package/dist/types/client/engines/structured/adapter-js-yaml.d.ts +6 -0
  79. package/dist/types/client/engines/structured/index.d.ts +29 -0
  80. package/dist/types/client/engines/structured/port.d.ts +45 -0
  81. package/dist/types/client/infra/http/SomaHttpService.d.ts +1 -1
  82. package/dist/types/client/infra/notify/DefaultNotifyService.d.ts +2 -3
  83. package/dist/types/client/infra/permission/SomaPermission.d.ts +1 -1
  84. package/dist/types/client/render-ports/notify-renderer.d.ts +1 -56
  85. package/dist/types/client/runtime/SomaRuntimeServices.d.ts +9 -44
  86. package/dist/types/server/host/app-config-composer.d.ts +2 -3
  87. package/dist/types/server/host/host-config-paths.d.cts +2 -7
  88. package/dist/types/server/host/precompiled-manifest.d.ts +5 -0
  89. package/dist/types/server/infra/host-config-paths.d.cts +7 -0
  90. package/dist/types/server/page-assets.d.ts +2 -5
  91. package/dist/types/server/runtime-space/bindings.d.ts +9 -0
  92. package/dist/types/server/runtime-space/digest.d.ts +5 -0
  93. package/dist/types/server/runtime-space/index.d.ts +1 -1
  94. package/dist/types/server/runtime-space/prewarm.d.ts +2 -2
  95. package/dist/types/server/runtime-space/store.d.ts +4 -0
  96. package/dist/types/server/runtime-space/types.d.ts +3 -2
  97. package/dist/types/shared/app-config-merge.d.ts +3 -0
  98. package/dist/types/shared/registry-generated/limits.d.ts +78 -4
  99. package/dist/types/shared/types/announcer.types.d.ts +14 -0
  100. package/dist/types/shared/types/notify.types.d.ts +36 -0
  101. package/dist/types/shared/types/role-gate.types.d.ts +8 -0
  102. package/host-native/src/aot-builder.ts +12 -5
  103. package/host-native/src/dev-chunk-gc.ts +104 -0
  104. package/host-native/src/host-prepare.ts +19 -2
  105. package/host-native/src/manifest-http.ts +1 -1
  106. package/host-native/src/native-server.ts +16 -0
  107. package/host-native/src/page-http.ts +2 -67
  108. package/host-native/src/page-payload-cache.ts +68 -0
  109. package/package.json +16 -2
@@ -17,7 +17,7 @@ import type { TreeArtifact } from '../../shared/types/component-tree-artifact.ty
17
17
  import {
18
18
  mergeSourcePackageAppConfig,
19
19
  parseAppConfigYaml,
20
- } from '../../server/host/app-config-composer';
20
+ } from '../../shared/app-config-merge';
21
21
 
22
22
  export interface SomaPrecompiledPage {
23
23
  path: string;
@@ -1,7 +1,7 @@
1
1
  /** HOST 配置同步 — 供 bin/soma-sync.cjs 使用 */
2
2
  const fs = require('node:fs');
3
3
  const path = require('node:path');
4
- const { resolveHostConfigRoot } = require('../../server/host/host-config-paths.cjs');
4
+ const { resolveHostConfigRoot } = require('../../server/infra/host-config-paths.cjs');
5
5
 
6
6
  const SYNC_FILES = [
7
7
  'locale.yaml',
@@ -12,12 +12,7 @@ const createJiti = require('jiti');
12
12
  const {
13
13
  resolveAppConfigPath,
14
14
  resolveHostAppConfigPath,
15
- } = require('../../server/host/host-config-paths.cjs');
16
- const {
17
- getSomaAssetSources,
18
- collectPageEntries,
19
- collectIncludes,
20
- } = require('../../server/host/source-packages.cjs');
15
+ } = require('../../server/infra/host-config-paths.cjs');
21
16
 
22
17
  function readFileOrEmpty(filePath) {
23
18
  return fs.existsSync(filePath) ? fs.readFileSync(filePath, 'utf8') : '';
@@ -81,6 +76,7 @@ class SomaManifestWebpackPlugin {
81
76
  const { loadPageMarkupConfig } = this.jiti('../../server/host/page-markup-config.ts');
82
77
  const { resolveHostTreeCompileContext } = this.jiti('../../server/host/resolve-host-tree-context.ts');
83
78
  const { runPrewarm, computePrewarmInputsDigest } = this.jiti('../../server/runtime-space/prewarm.ts');
79
+ const { getSomaAssetSources, collectPageEntries, collectIncludes } = this.jiti('../../server/host/source-packages.cjs');
84
80
 
85
81
  const sources = getSomaAssetSources(hostDir);
86
82
  const pageEntries = collectPageEntries(sources);
@@ -6218,6 +6218,16 @@ var SOMA_PIPELINE_LIMITS = {
6218
6218
  "file": "core/server/registry/api-registry-store.ts",
6219
6219
  "symbol": "SOMA_PIPELINE_LIMITS"
6220
6220
  },
6221
+ {
6222
+ "module": "soma-core",
6223
+ "file": "core/client/engines/diff/index.ts",
6224
+ "symbol": "SOMA_PIPELINE_LIMITS"
6225
+ },
6226
+ {
6227
+ "module": "soma-core",
6228
+ "file": "core/client/engines/highlight/index.ts",
6229
+ "symbol": "SOMA_PIPELINE_LIMITS"
6230
+ },
6221
6231
  {
6222
6232
  "module": "soma-core",
6223
6233
  "file": "core/server/registry/page-registry-store.ts",
@@ -6520,17 +6530,17 @@ var SOMA_PIPELINE_LIMITS = {
6520
6530
  },
6521
6531
  {
6522
6532
  "module": "soma-ai",
6523
- "file": "src/api/common/RateLimitBackend.ts",
6533
+ "file": "src/server/common/RateLimitBackend.ts",
6524
6534
  "symbol": "SOMA_PIPELINE_LIMITS_AI"
6525
6535
  },
6526
6536
  {
6527
6537
  "module": "soma-ai",
6528
- "file": "src/api/common/RequestBodyLimit.ts",
6538
+ "file": "src/server/common/RequestBodyLimit.ts",
6529
6539
  "symbol": "SOMA_PIPELINE_LIMITS_AI"
6530
6540
  },
6531
6541
  {
6532
6542
  "module": "soma-ai",
6533
- "file": "src/api/service/ai-assistant/Chat.ts",
6543
+ "file": "src/server/services/ai-assistant/Chat.ts",
6534
6544
  "symbol": "SOMA_PIPELINE_LIMITS_AI"
6535
6545
  },
6536
6546
  {
@@ -6545,7 +6555,7 @@ var SOMA_PIPELINE_LIMITS = {
6545
6555
  },
6546
6556
  {
6547
6557
  "module": "soma-ai",
6548
- "file": "src/api/common/TrustedRequestContext.ts",
6558
+ "file": "src/domain/ai-shared/TrustedRequestContext.ts",
6549
6559
  "symbol": "SOMA_PIPELINE_LIMITS_AI_RUNTIME"
6550
6560
  },
6551
6561
  {
@@ -6718,6 +6728,72 @@ var SOMA_PIPELINE_LIMITS = {
6718
6728
  "tokensBytes": 40960,
6719
6729
  "componentBytesPerPage": 163840,
6720
6730
  "overrideBlockBytes": 8192
6731
+ },
6732
+ "contentEngines": {
6733
+ "diff": {
6734
+ "basis": {
6735
+ "maxChars": "\u5355\u4E2A\u5DEE\u5F02\u8BA1\u7B97\u4E24\u4FA7\u5408\u8BA1\u5B57\u6570\u4E0A\u9650\uFF1B\u8D85\u9650\u4E0D\u8BA1\u7B97\u3001\u6574\u6BB5\u66FF\u6362\uFF08\u53C2\u8003\u6587\u672C\u5DEE\u5F02\u7EC4\u4EF6\u7B14\u8BB0 C.5\u300C\u5355\u4E2A\u5DEE\u5F02\u7EC4\u4EF6\u603B\u91CF 200 000 \u5B57\u300D\uFF0C\u5B9E\u6D4B 4\uFF1A\u4E07\u5B57\u7EA7\u9010\u5B57\u6BD4\u8F83\u9700\u8D85\u65F6\u4E0E\u9000\u5316\uFF09",
6736
+ "maxCharsPerCompare": "\u5355\u6B21\u8BCD\u7EA7\u6BD4\u8F83\uFF08\u4E00\u5BF9\u53E5\u5B50 / \u4E00\u6B21 diff \u8C03\u7528\uFF09\u4E24\u4FA7\u5408\u8BA1\u5B57\u6570\u4E0A\u9650\uFF08\u7B14\u8BB0 C.2 BaseOpts maxChars 20 000\uFF09",
6737
+ "timeoutMs": "\u4E00\u6B21 diffProse / diffItems \u7684\u603B\u65F6\u9650\uFF08\u6BEB\u79D2\uFF09\uFF0C\u540C VisualEditor timeout 1000\uFF08\u7B14\u8BB0 C.2\uFF09",
6738
+ "maxItems": "\u6761\u76EE\u5217\u8868\u5355\u4FA7\u6761\u76EE\u6570\u4E0A\u9650\uFF1B\u8D85\u9650\u4E0D\u9010\u6761\u6BD4\u8F83\uFF08\u7B14\u8BB0 C.5\u300C\u6761\u76EE 2 000 \u4E2A\u300D\uFF09",
6739
+ "moveDetectMaxChanged": "\u53D8\u5316\u6761\u76EE\uFF08\u589E + \u5220\uFF09\u8D85\u8FC7\u6B64\u6570\u4E0D\u505A\u79FB\u52A8\u68C0\u6D4B\uFF08\u7B14\u8BB0 C.2\uFF0Cwikidiff2 \u589E\u5220\u5408\u8BA1 > 100 \u4E0D\u68C0\u6D4B\u7684\u653E\u5BBD\u7248\uFF0C\u7ECF\u9A8C\u503C\uFF09",
6740
+ "pairAt": "\u53E5 / \u6BB5\u914D\u5BF9\u9608\u503C\uFF1A\u5B57\u7B26\u591A\u91CD\u96C6 Dice \u2265 \u6B64\u503C\u89C6\u4E3A\u6539\u5199\uFF08VisualEditor diffThreshold 0.5\uFF1B\u5B9E\u6D4B 3 \u7684\u6539\u5199\u53E5\u4E3A 0.84\u20130.89\uFF09",
6741
+ "rewriteBelow": "\u6574\u4F53\u76F8\u4F3C\u5EA6\u4F4E\u4E8E\u6B64\u503C\u6574\u6BB5\u66FF\u6362\uFF08\u7B49\u6548 VE keep < 0.5 \xD7 diff\uFF1B\u5B9E\u6D4B 2 \u7684 C3 \u6574\u53E5\u91CD\u5199\u7EA6 0.16\uFF09",
6742
+ "absorbOrphan": "\u5B64\u5B57\u5438\u6536\uFF1A\u5939\u5728\u4E24\u5904\u6539\u52A8\u95F4\u3001\u957F\u5EA6 \u2264 \u6B64\u503C\uFF08\u5B57\uFF09\u7684\u975E\u6807\u70B9\u76F8\u540C\u7247\u6BB5\u5E76\u5165\u6539\u52A8\uFF08\u5B9E\u6D4B 2 \u7684 C5\u300C\u671F\u300D\uFF09",
6743
+ "absorbOrphanMax": "\u8C03\u7528\u65B9\u53EF\u8C03\u7684\u5B64\u5B57\u5438\u6536\u4E0A\u9650\uFF08\u5B57\uFF09\uFF0C\u9632\u6B62\u628A\u6574\u53E5\u5438\u6210\u6539\u52A8",
6744
+ "titleAt": "\u65E0 key \u6761\u76EE\u6309\u6807\u9898\u914D\u5BF9\u7684\u76F8\u4F3C\u5EA6\u9608\u503C\uFF08\u7B14\u8BB0 C.2 ItemOpts.match.titleAt 0.6\uFF09",
6745
+ "bodyAt": "\u65E0 key \u6761\u76EE\u6309\u6B63\u6587\u914D\u5BF9\u7684\u76F8\u4F3C\u5EA6\u9608\u503C\uFF08\u7B14\u8BB0 C.2 ItemOpts.match.bodyAt 0.5\uFF09",
6746
+ "maxAlignTokens": "\u5E8F\u5217\u5BF9\u9F50\u7684\u4E0D\u540C\u952E\u6570\u4E0A\u9650\uFF08\u6BCF\u4E2A\u952E\u6620\u5C04\u4E3A\u4E00\u4E2A BMP \u79C1\u7528\u533A\u5B57\u7B26\uFF0CU+E000\u2013U+F8FF \u5171 6400 \u4E2A\uFF09",
6747
+ "maxPairMatrix": "\u4E00\u6BB5\u5220\u589E\u533A\u95F4\u5185\u53E5 / \u6BB5\u914D\u5BF9\u7684\u5019\u9009\u77E9\u9635\u4E0A\u9650\uFF08\u5220\u6570 \xD7 \u589E\u6570\uFF09\uFF0C\u8D85\u51FA\u4E0D\u914D\u5BF9\u3001\u6309\u5220 + \u589E\u5448\u73B0\uFF1B\u7ECF\u9A8C\u503C\uFF0C\u8BC1\u636E\u5F31",
6748
+ "maxPairCandidates": "\u65E0 key \u6761\u76EE\u6309\u76F8\u4F3C\u5EA6\u914D\u5BF9\u7684\u5019\u9009\u77E9\u9635\u4E0A\u9650\uFF08\u5269\u4F59\u65E7\u6761\u76EE \xD7 \u5269\u4F59\u65B0\u6761\u76EE\uFF09\uFF1B\u7ECF\u9A8C\u503C\uFF0C\u8BC1\u636E\u5F31"
6749
+ },
6750
+ "maxChars": 2e5,
6751
+ "maxCharsPerCompare": 2e4,
6752
+ "timeoutMs": 1e3,
6753
+ "maxItems": 2e3,
6754
+ "moveDetectMaxChanged": 500,
6755
+ "pairAt": 0.5,
6756
+ "rewriteBelow": 0.4,
6757
+ "absorbOrphan": 1,
6758
+ "absorbOrphanMax": 4,
6759
+ "titleAt": 0.6,
6760
+ "bodyAt": 0.5,
6761
+ "maxAlignTokens": 6400,
6762
+ "maxPairMatrix": 2500,
6763
+ "maxPairCandidates": 25e4
6764
+ },
6765
+ "highlight": {
6766
+ "basis": {
6767
+ "maxLines": "\u9AD8\u4EAE\u7684\u6700\u591A\u884C\u6570\uFF1B\u8D85\u51FA\u90E8\u5206\u6309\u7EAF\u6587\u672C\uFF08\u53C2\u8003\u6587\u672C\u5DEE\u5F02\u7EC4\u4EF6\u7B14\u8BB0 C.2 \u7AEF\u53E3 2 maxLines 5 000\uFF09",
6768
+ "maxLineLength": "\u5355\u884C\u8D85\u8FC7\u6B64\u5B57\u7B26\u6570\u6574\u884C\u6309\u7EAF\u6587\u672C\uFF08\u7B14\u8BB0 C.2 maxLineLength 2 000\uFF0C\u538B\u7F29\u540E\u7684\u5355\u884C JS / JSON \u5E38\u89C1\uFF09",
6769
+ "timeoutMs": "\u4E00\u6B21\u89E3\u6790\u7684\u65F6\u9650\uFF08\u6BEB\u79D2\uFF09\uFF1BLezer \u6309 advance() \u5206\u6B65\u89E3\u6790\uFF0C\u8D85\u65F6\u6574\u6BB5\u6309\u7EAF\u6587\u672C\uFF08\u7ECF\u9A8C\u503C\uFF0C\u4E0E\u5DEE\u5F02\u7AEF\u53E3\u540C\u53D6 1 000\uFF09",
6770
+ "maxChars": "\u6574\u6BB5\u8D85\u8FC7\u6B64\u5B57\u7B26\u6570\u4E0D\u89E3\u6790\u3001\u6309\u7EAF\u6587\u672C\uFF08\u7ECF\u9A8C\u503C\uFF0C\u8BC1\u636E\u5F31\uFF1A\u7EA6 1 MB \u6587\u672C\uFF09",
6771
+ "jsonSniffMaxChars": "\u8BED\u8A00\u63A8\u65AD\u300C\u6574\u4F53\u80FD JSON.parse\u300D\u53EA\u5BF9\u4E0D\u8D85\u8FC7\u6B64\u5B57\u7B26\u6570\u7684\u6837\u672C\u505A\uFF08\u907F\u514D\u5BF9\u5927\u6587\u672C\u53CD\u590D\u89E3\u6790\uFF1B\u7ECF\u9A8C\u503C\uFF09"
6772
+ },
6773
+ "maxLines": 5e3,
6774
+ "maxLineLength": 2e3,
6775
+ "timeoutMs": 1e3,
6776
+ "maxChars": 1e6,
6777
+ "jsonSniffMaxChars": 2e5
6778
+ },
6779
+ "structured": {
6780
+ "basis": {
6781
+ "maxChars": "JSON / YAML \u539F\u6587\u8D85\u8FC7\u6B64\u5B57\u7B26\u6570\u4E0D\u89E3\u6790\u3001\u6309\u539F\u6587\u663E\u793A\uFF08\u4E0E\u4EE3\u7801\u9AD8\u4EAE\u7AEF\u53E3 maxChars \u540C\u53D6\u7EA6 1 MB\uFF1B\u7ECF\u9A8C\u503C\uFF0C\u8BC1\u636E\u5F31\uFF09",
6782
+ "maxNodes": "\u89E3\u6790\u540E\u503C\u7684\u8282\u70B9\u603B\u6570\u4E0A\u9650\uFF08\u5BF9\u8C61 / \u6570\u7EC4 / \u53F6\u5B50\u5404\u8BA1 1\uFF09\uFF1BYAML \u522B\u540D\u5C55\u5F00\u8D85\u9650\u5373\u6309 too-many-nodes \u964D\u7EA7\uFF0C\u9632\u300C\u5341\u4EBF\u7B11\u58F0\u300D\u5F0F\u522B\u540D\u70B8\u5F39\uFF08\u7ECF\u9A8C\u503C\uFF1A20 \u4E07\u8282\u70B9\u7EA6\u4E3A 1 MB \u7D27\u51D1 JSON \u7684\u91CF\u7EA7\uFF09"
6783
+ },
6784
+ "maxChars": 1e6,
6785
+ "maxNodes": 2e5
6786
+ },
6787
+ "markdown": {
6788
+ "basis": {
6789
+ "maxChars": "Markdown \u539F\u6587\u8D85\u8FC7\u6B64\u5B57\u7B26\u6570\u4E0D\u89E3\u6790\u3001\u6309\u7EAF\u6587\u672C\u663E\u793A\uFF08\u53C2\u8003\u6587\u672C\u5DEE\u5F02\u7EC4\u4EF6\u7B14\u8BB0 C.2 \u7AEF\u53E3 1 limits.maxChars 200 000\uFF09",
6790
+ "maxBlocks": "\u5757\u6570\u4E0A\u9650\uFF0C\u8D85\u51FA\u622A\u65AD\u5E76\u6807 truncated\uFF08\u7B14\u8BB0 C.2 maxBlocks 5 000\uFF09",
6791
+ "summaryChars": "meta.summary \u53D6\u53BB\u6807\u8BB0\u5168\u6587\u7684\u524D N \u5B57\uFF08\u7B14\u8BB0 C.2\u300C\u524D 80 \u5B57\u300D\uFF09"
6792
+ },
6793
+ "maxChars": 2e5,
6794
+ "maxBlocks": 5e3,
6795
+ "summaryChars": 80
6796
+ }
6721
6797
  }
6722
6798
  };
6723
6799
 
@@ -11,8 +11,9 @@
11
11
  // core 只用 CSSOM `style.setProperty` 写,不持有任何几何值;缺省则不写样式,由 UI 体系按 `data-soma-announcer-host` 选择器隐藏。
12
12
  // 去重 / 节流:design 真源没有规则,不做。
13
13
  import { SOMA_PLATFORM_KEYS_CORE } from '../../shared/registry-generated/platform-keys';
14
+ import type { AnnounceOptions, AnnouncePoliteness, Announcer } from '../../shared/types/announcer.types';
14
15
 
15
- export type AnnouncePoliteness = 'polite' | 'assertive';
16
+ export type { AnnounceOptions, AnnouncePoliteness, Announcer };
16
17
 
17
18
  /** politeness 闭集;宿主也按这个顺序创建 */
18
19
  export const ANNOUNCE_POLITENESS: readonly AnnouncePoliteness[] = ['polite', 'assertive'];
@@ -41,21 +42,6 @@ export interface AnnouncerOptions {
41
42
  readonly clock?: AnnouncerClock;
42
43
  }
43
44
 
44
- export interface AnnounceOptions {
45
- readonly politeness?: AnnouncePoliteness;
46
- }
47
-
48
- export interface Announcer {
49
- /** 追加一条播报;空消息忽略;politeness 缺省 polite,未知值抛 TypeError */
50
- announce(message: string, options?: AnnounceOptions): void;
51
- /** 两个常驻宿主 */
52
- hosts(): Readonly<Record<AnnouncePoliteness, HTMLElement>>;
53
- /** 立即移除全部待清理节点 */
54
- clear(): void;
55
- /** 清空、取消计时并移除宿主;之后 announce 忽略 */
56
- dispose(): void;
57
- }
58
-
59
45
  /**
60
46
  * 读 design `announcer.clearAfterMs`;真源(生成物)目前没有 `announcer` 族,缺该键时为 undefined。
61
47
  * 按未知形状守卫读取,不再强转成生成物类型里并不存在的字段。
@@ -3,7 +3,7 @@
3
3
 
4
4
  import type { SomaPageRoot, SomaAppConfig } from '../../shared/types/domain.types';
5
5
  import type { SomaPageState, SomaPageStateConfig } from '../../shared/types/page-state.types';
6
- import type { SomaRuntimeServices } from '../runtime/SomaRuntimeServices';
6
+ import type { SomaRuntimeServicesShape } from './runtime-services.types';
7
7
  import type { SomaPageNav } from '../../shared/types/nav.types';
8
8
  import { readQueryParam } from '../infra/router/router-path';
9
9
  import { runAsync as runAsyncUtil } from './runAsync';
@@ -39,7 +39,7 @@ export abstract class SomaPageRootBase implements SomaPageRoot {
39
39
  _config: SomaAppConfig = {} as SomaAppConfig;
40
40
 
41
41
  /** 由引擎注入的运行时基础设施(router / http / notify 等) */
42
- _services?: SomaRuntimeServices;
42
+ _services?: SomaRuntimeServicesShape;
43
43
 
44
44
  /**
45
45
  * 导航目录的只读视图(E4 / R-15):`services.nav.entries()` 与 `activeOf()` 的当前快照,外壳(顶栏、框架菜单)绑定
@@ -84,6 +84,11 @@ function reservedMemberNames(): ReadonlySet<string> {
84
84
  return names;
85
85
  }
86
86
 
87
+ /** 判断对象是否持有页面根的 _viewContext 钩子(避免把行作用域数据误认成页面根) */
88
+ function isViewRoot(value: unknown): value is { _viewContext(): SomaViewContextHandle } {
89
+ return value !== null && typeof value === 'object' && typeof (value as { _viewContext?: unknown })._viewContext === 'function';
90
+ }
91
+
87
92
  /** 取页面根(原始实例或响应式代理)上的 ctx */
88
93
  function ctxOf(view: unknown): SomaViewContext {
89
94
  return (view as { _viewContext(): SomaViewContextHandle })._viewContext().ctx;
@@ -163,9 +168,13 @@ export function defineSomaView<
163
168
  Object.defineProperty(cls, 'name', { value: name });
164
169
  for (const key of methodNames) {
165
170
  const fn = methods[key]!;
166
- // core 的 `UI_REFRESH | page.方法` 以 (当前页面根, 载荷) 调用;this 与第一实参都是响应式页面根
171
+ // core 的 `UI_REFRESH | page.方法` 或 `ACTION | 方法` 绑定页面根为 this;
172
+ // 行作用域内事件引擎第一实参会传入行数据而非页面根,优先取带 _viewContext 的 this(退回第一实参以兼容显式 unbound 调用)
167
173
  Object.defineProperty(cls.prototype, key, {
168
- value: function (this: unknown, view: unknown, payload: unknown): unknown { const v = view ?? this; return fn(v, payload, ctxOf(v)); },
174
+ value: function (this: unknown, view: unknown, payload: unknown): unknown {
175
+ const v = isViewRoot(this) ? this : (isViewRoot(view) ? view : (view ?? this));
176
+ return fn(v, payload, ctxOf(v));
177
+ },
169
178
  writable: true,
170
179
  configurable: true,
171
180
  enumerable: false,
@@ -0,0 +1,57 @@
1
+ // 运行时基础设施服务表形状类型(CORE-L01:放在 client/base 基础支撑层,供同层 SomaPageRootBase 引用,
2
+ // 既不反向依赖 client/runtime/SomaRuntimeServices.ts,也不违反 KI-8 对 core/shared 的隔离规则;
3
+ // 完整服务表在 client/runtime/SomaRuntimeServices.ts 继承并补齐领域引擎端口与返回栈类型)。
4
+
5
+ import type { TokenAuthService } from '../infra/auth/TokenAuthService';
6
+ import type { MemoryCache } from '../infra/cache/MemoryCache';
7
+ import type { SomaConfig } from '../infra/config/SomaConfig';
8
+ import type { SomaAppConfigPort } from '../infra/config/feature-flags';
9
+ import type { SomaEventBus } from '../infra/event-bus/SomaEventBus';
10
+ import type { SomaHttpService } from '../infra/http/SomaHttpService';
11
+ import type { SomaLocaleCatalog } from '../infra/i18n/locale-catalog';
12
+ import type { SomaIdentityPort } from '../infra/identity/identity-port';
13
+ import type { ConsoleLogger } from '../infra/logger/ConsoleLogger';
14
+ import type { DefaultNotifyService } from '../infra/notify/DefaultNotifyService';
15
+ import type { SomaPermission } from '../infra/permission/SomaPermission';
16
+ import type { IRealtimeService } from '../infra/realtime/IRealtimeService';
17
+ import type { SomaRouter } from '../infra/router/SomaRouter';
18
+ import type { IStorageService } from '../infra/storage/IStorageService';
19
+ import type { SomaTimer } from '../infra/timer/SomaTimer';
20
+ import type { SomaObservationChannel } from '../observability/runtime-observer';
21
+ import type { SomaRuntimeServicesBase } from '../../shared/types/domain.types';
22
+ import type { SomaNavPort } from '../../shared/types/nav.types';
23
+ import type { SomaShortcutRegistry } from '../../shared/types/write-runtime.types';
24
+
25
+ /** 界面中途提交服务(见 SomaRuntimeServices.ui) */
26
+ export interface SomaUiService {
27
+ publish(): Promise<void>;
28
+ }
29
+
30
+ /**
31
+ * 运行时基础设施形状契约(`SomaPageRootBase._services` 与 `SomaRuntimeServices` 共用)。
32
+ * `engines` 与 `navHistory` 为领域层具体类型,在此以泛型槽位留口,避免基础层反向依赖领域层。
33
+ */
34
+ export interface SomaRuntimeServicesShape<TEngines = unknown, TNavHistory = unknown>
35
+ extends SomaRuntimeServicesBase {
36
+ router: SomaRouter;
37
+ notify: DefaultNotifyService;
38
+ logger: ConsoleLogger;
39
+ http: SomaHttpService;
40
+ storage: IStorageService;
41
+ timer: SomaTimer;
42
+ eventBus: SomaEventBus;
43
+ cache: MemoryCache<unknown>;
44
+ config: SomaConfig;
45
+ auth: TokenAuthService;
46
+ permission: SomaPermission;
47
+ i18n: SomaLocaleCatalog;
48
+ realtime: IRealtimeService;
49
+ ui: SomaUiService;
50
+ observation: SomaObservationChannel;
51
+ readonly engines: TEngines;
52
+ nav?: SomaNavPort;
53
+ readonly identity: SomaIdentityPort;
54
+ readonly navHistory?: TNavHistory;
55
+ readonly appConfig?: SomaAppConfigPort;
56
+ readonly shortcuts?: SomaShortcutRegistry;
57
+ }
@@ -150,6 +150,28 @@ function isPlainObject(value: unknown): value is Record<string, unknown> {
150
150
  return typeof value === 'object' && value !== null && !Array.isArray(value);
151
151
  }
152
152
 
153
+ /**
154
+ * 提交体里的布尔显式化:字典里 `type: bool` 的字段,新建时缺席或为空(undefined / null / 空串)→ false;
155
+ * 已给出的布尔(true / false)原样保留。没有要改的返回原对象(同一引用)。
156
+ */
157
+ function explicitBooleans(
158
+ fields: Readonly<Record<string, { readonly type?: string }>>,
159
+ model: Readonly<Record<string, unknown>>,
160
+ create: boolean,
161
+ ): Record<string, unknown> {
162
+ let next: Record<string, unknown> | null = null;
163
+ for (const [key, field] of Object.entries(fields)) {
164
+ if (field?.type !== 'bool') continue;
165
+ const present = Object.hasOwn(model, key);
166
+ const value = model[key];
167
+ const blank = value === undefined || value === null || value === '';
168
+ if (present ? !blank : !create) continue;
169
+ next ??= { ...model };
170
+ next[key] = false;
171
+ }
172
+ return next ?? (model as Record<string, unknown>);
173
+ }
174
+
153
175
  /** 按点分路径段读取(任一环节为空即返回 undefined) */
154
176
  function readPath(root: unknown, segments: string[]): unknown {
155
177
  let current: unknown = root;
@@ -675,8 +697,14 @@ export class SomaDataObjectResolver {
675
697
  options: SomaSubmitOptions = {},
676
698
  ): Promise<SomaDataSubmitResult> {
677
699
  const intent = options.intent ?? 'explicit';
678
- const result = await this.submitRaw(name, model, mode, options.identityField, options.signal);
679
- const write = this.config.objects[name]?.write;
700
+ const declared = this.config.objects[name];
701
+ const write = declared?.write;
702
+ // 布尔字段无论真假都显式提交:新建时缺席 / 空的布尔补 false,取消勾选的 false 与勾选的 true 原样上行;
703
+ // 发出去的就是显式化后的这份,不靠后端回落默认值。更新缺席 = 不改,不补
704
+ const sent = write !== undefined && declared?.fields !== undefined && isPlainObject(model)
705
+ ? explicitBooleans(declared.fields, model, (mode ?? this.inferWriteMode(name, write)) === 'create')
706
+ : model;
707
+ const result = await this.submitRaw(name, sent, mode, options.identityField, options.signal);
680
708
  if (!write) return result;
681
709
  if (result.ok) return decorateSuccess(result, write, intent);
682
710
  return decorateFailure(result, intent, { sentToken: readConcurrencyToken(model, write) });
@@ -872,11 +900,14 @@ export class SomaDataObjectResolver {
872
900
  */
873
901
  mapSubmitError(error: unknown, write: SomaDataWriteConfig): Extract<SomaDataSubmitResult, { ok: false }> {
874
902
  const payload = extractErrorPayload(error);
875
- const message = payload.message
903
+ const raw = payload.message
876
904
  ?? (error instanceof Error ? error.message : '提交失败');
877
905
  // 状态码(版本冲突 409 / 412 等):异常或响应上的 status,或 SomaHttpService 写进消息的 `HTTP 409: …`。
878
- // 只补 status,不改写文案——存量调用方按原文案显示。
879
- const status = commandStatusOf(error) ?? splitHttpMessage(message)?.status;
906
+ // 面向使用者的文案只留后端给的可读原因:`HTTP 409:` 前缀剥掉,状态码走结果的 `status` 字段(开发态诊断读它,界面不显示);
907
+ // 前缀后面没有原因时退到通用说法,不把状态码当文案
908
+ const http = splitHttpMessage(raw);
909
+ const message = http === null ? raw : (http.text !== '' ? http.text : '提交失败');
910
+ const status = commandStatusOf(error) ?? http?.status;
880
911
  // 版本冲突带上服务端当前令牌与当前记录(取得不到就不带,调用方退回重读)
881
912
  const conflict = status === 409 || status === 412 ? readConflictState(error, write) : {};
882
913
  const withStatus = status === undefined ? { ...conflict } : { status, ...conflict };
@@ -9,15 +9,9 @@
9
9
  // - 角色值只在函数内比较,不写入 DOM、诊断、观测或控制台;
10
10
  // - 请求不附带任何 core 生成的身份字段(这里不碰 http)。
11
11
 
12
- /** Host 提供的角色集来源(`SomaBootstrapOptions.auth`) */
13
- export interface SomaAuthOption {
14
- getRoles(): readonly string[];
15
- }
12
+ import type { SomaAuthOption, SomaRoleGate } from '../../shared/types/role-gate.types';
16
13
 
17
- export interface SomaRoleGate {
18
- /** 当前角色集与 `required` 有交集才为真 */
19
- hasAnyRole(required: readonly string[]): boolean;
20
- }
14
+ export type { SomaAuthOption, SomaRoleGate };
21
15
 
22
16
  function readRoles(auth: SomaAuthOption | undefined): ReadonlySet<string> {
23
17
  if (auth === undefined || typeof auth.getRoles !== 'function') return new Set();
@@ -388,6 +388,7 @@ export class SomaEventEngine<TContext extends Record<string, unknown> = Record<s
388
388
  runtime.status = 'error';
389
389
  runtime.message = error instanceof Error ? error.message : String(error);
390
390
  result = false;
391
+ console.error(`[soma-core][引擎] ${config.somaId}.${config.domEvent} (${config.funcPath}) 执行失败:${runtime.message}`);
391
392
  } finally {
392
393
  if (rowContext instanceof SomaRowScope) this.pendingRows.delete(element);
393
394
  else this.pendingSet.delete(config.somaId);
@@ -5,7 +5,7 @@
5
5
  import { SomaEngineError } from '../../../shared/engines/engine-error';
6
6
  import { loadEngineModule, type EngineLoadTelemetry } from '../load';
7
7
  import { COMPONENT_LOADERS, SERIES_IMPLIED_COMPONENTS, SERIES_LOADERS } from './kind-modules';
8
- import type { ChartInit, ChartInstance, ChartPointer, SomaChartAdapter } from './port';
8
+ import type { ChartColumn, ChartInit, ChartInstance, ChartPointer, SomaChartAdapter } from './port';
9
9
 
10
10
  interface Rect { x: number; y: number; width: number; height: number; clone(): Rect; applyTransform(m: ArrayLike<number> | null): void }
11
11
  interface GraphicEl { getBoundingRect(): Rect; getComputedTransform(): ArrayLike<number> | null }
@@ -18,7 +18,17 @@ interface EChartsInstance {
18
18
  resize(opts?: { width: number; height: number }): void;
19
19
  dispose(): void;
20
20
  /** 公开于实例但文档称内部:用来取数据项的图元(假设项,见 §12) */
21
- getModel(): { getSeriesByIndex(i: number): { getData(): { getItemGraphicEl(i: number): GraphicEl | undefined } } | undefined };
21
+ getModel(): {
22
+ getSeriesByIndex(i: number): { getData(): { getItemGraphicEl(i: number): GraphicEl | undefined } } | undefined;
23
+ getComponent(type: string, index: number): unknown;
24
+ };
25
+ getZr(): {
26
+ on(event: string, handler: (e: { offsetX?: number; offsetY?: number }) => void): void;
27
+ off(event: string, handler: (e: { offsetX?: number; offsetY?: number }) => void): void;
28
+ };
29
+ containPixel(finder: Record<string, number>, value: number[]): boolean;
30
+ convertFromPixel(finder: Record<string, number>, value: number[]): number | number[];
31
+ convertToPixel(finder: Record<string, number>, value: number): number | number[];
22
32
  }
23
33
  interface EChartsCore {
24
34
  init(host: HTMLElement, theme: unknown, opts: Record<string, unknown>): EChartsInstance;
@@ -132,6 +142,69 @@ export function createEChartsAdapter(adapterOptions: EChartsAdapterOptions = {})
132
142
  chart.off('mouseout', onOut);
133
143
  };
134
144
  },
145
+ onColumn(handler): () => void {
146
+ // 按坐标轴换算所在列:第一个类目轴(优先 x 轴,其次 y 轴),不依赖系列图元,null 列与列间空白也命中
147
+ const zr = chart.getZr();
148
+ const axisOf = (): { dim: 'x' | 'y'; count: number } | null => {
149
+ const model = chart.getModel();
150
+ for (const dim of ['x', 'y'] as const) {
151
+ const axis = model.getComponent(`${dim}Axis`, 0) as { get(k: string): unknown; getCategories?(): unknown[] } | undefined;
152
+ if (axis !== undefined && axis.get('type') === 'category') {
153
+ // 类目来自系列数据时选项的 xAxis.data 为空(getCategories 只读选项里写的),实际类目在轴刻度的 ordinalMeta 里:优先读它
154
+ const scale = (axis as { axis?: { scale?: { getOrdinalMeta?(): { categories?: unknown[] } | undefined } } }).axis?.scale;
155
+ const metaCats = scale?.getOrdinalMeta?.()?.categories;
156
+ const cats = metaCats !== undefined && metaCats.length > 0 ? metaCats : (axis.getCategories?.() ?? []);
157
+ return { dim, count: cats.length };
158
+ }
159
+ }
160
+ return null;
161
+ };
162
+ const columnAt = (x: number, y: number): ChartColumn | null => {
163
+ const axis = axisOf();
164
+ if (axis === null || axis.count === 0) return null;
165
+ if (!chart.containPixel({ gridIndex: 0 }, [x, y])) return null;
166
+ // 像素 → 数据:二维像素 [x, y] 必须配坐标系 finder(gridIndex)取回 [x 值, y 值];
167
+ // 配单轴 finder(xAxisIndex)时引擎期望的是标量像素,传数组得不到数值(实测列命中恒为 null、读数不随悬停变)
168
+ const raw = chart.convertFromPixel({ gridIndex: 0 }, [x, y]);
169
+ const v = Array.isArray(raw) ? raw[axis.dim === 'x' ? 0 : 1] : raw;
170
+ if (typeof v !== 'number' || !Number.isFinite(v)) return null;
171
+ const dataIndex = Math.min(axis.count - 1, Math.max(0, Math.round(v)));
172
+ return columnAnchor(dataIndex, axis.dim);
173
+ };
174
+ const columnAnchor = (dataIndex: number, dim: 'x' | 'y'): ChartColumn | null => {
175
+ const finder: Record<string, number> = dim === 'x' ? { xAxisIndex: 0 } : { yAxisIndex: 0 };
176
+ const px = chart.convertToPixel(finder, dataIndex);
177
+ const grid = chart.getModel().getComponent('grid', 0) as { coordinateSystem?: { getRect(): Rect } } | undefined;
178
+ const rect = grid?.coordinateSystem?.getRect();
179
+ const along = typeof px === 'number' ? px : Array.isArray(px) ? px[0] : NaN;
180
+ if (!Number.isFinite(along)) return null;
181
+ // 绘图区矩形取不到(引擎内部模型形状随版本变)时锚点的另一轴退到 0:列号才是命中的事实,锚点只用于对齐浮层
182
+ const anchor = dim === 'x' ? { x: along, y: rect?.y ?? 0 } : { x: rect?.x ?? 0, y: along };
183
+ return { dataIndex, anchor };
184
+ };
185
+ const read = (e: { offsetX?: number; offsetY?: number }): ChartColumn | null =>
186
+ typeof e.offsetX === 'number' && typeof e.offsetY === 'number' ? columnAt(e.offsetX, e.offsetY) : null;
187
+ const onMove = (e: { offsetX?: number; offsetY?: number }): void => {
188
+ const c = read(e);
189
+ handler(c === null ? 'leave' : 'hover', c);
190
+ };
191
+ const onClick = (e: { offsetX?: number; offsetY?: number }): void => {
192
+ const c = read(e);
193
+ if (c !== null) handler('click', c);
194
+ };
195
+ const onOut = (): void => handler('leave', null);
196
+ zr.on('mousemove', onMove);
197
+ zr.on('click', onClick);
198
+ zr.on('globalout', onOut);
199
+ let active = true;
200
+ return () => {
201
+ if (!active) return;
202
+ active = false;
203
+ zr.off('mousemove', onMove);
204
+ zr.off('click', onClick);
205
+ zr.off('globalout', onOut);
206
+ };
207
+ },
135
208
  resize(): void {
136
209
  chart.resize(size === undefined ? undefined : { width: size.width, height: size.height });
137
210
  },
@@ -1,6 +1,7 @@
1
1
  // exports `./chart`:图表引擎端口。`createChartPort(adapter?)`:缺省 ECharts 6 适配器(SVG 渲染器,动态加载)。
2
2
  // 入参校验(主题、option、销毁后调用)在 createChartPort 里做,换适配器也一样受约束。
3
3
  export type {
4
+ ChartColumn,
4
5
  ChartInit,
5
6
  ChartInstance,
6
7
  ChartPointer,
@@ -61,6 +62,23 @@ function guard(inner: ChartInstance): ChartInstance {
61
62
  unsubs.add(wrapped);
62
63
  return wrapped;
63
64
  },
65
+ ...(inner.onColumn === undefined
66
+ ? {}
67
+ : {
68
+ onColumn(handler: Parameters<NonNullable<ChartInstance['onColumn']>>[0]) {
69
+ live();
70
+ const off = inner.onColumn!(handler);
71
+ let done = false;
72
+ const wrapped = (): void => {
73
+ if (done) return;
74
+ done = true;
75
+ unsubs.delete(wrapped);
76
+ off();
77
+ };
78
+ unsubs.add(wrapped);
79
+ return wrapped;
80
+ },
81
+ }),
64
82
  resize(): void { live(); inner.resize(); },
65
83
  dispose(): void {
66
84
  if (disposed) return;
@@ -22,7 +22,20 @@ export interface ChartPointer {
22
22
  readonly anchor: { readonly x: number; readonly y: number };
23
23
  }
24
24
 
25
+ /** 指针 / 键盘所在的类目轴列;空值列、列间空白也能命中(与系列是否有图元无关) */
26
+ export interface ChartColumn {
27
+ /** 第一个类目轴上的列序号(与系列 data 下标一致) */
28
+ readonly dataIndex: number;
29
+ /** 该列在容器内的锚点像素(列中心、绘图区顶部) */
30
+ readonly anchor: { readonly x: number; readonly y: number };
31
+ }
32
+
25
33
  export interface ChartInstance {
34
+ /**
35
+ * 指针在绘图区内移动 / 点击 / 离开时按坐标轴换算所在列;落在绘图区外按 leave 处理;无类目轴的图(饼、仪表等)不触发。
36
+ * 可选:旧适配器缺该方法时调用方回落到 `onPointer`(只有带图元的列可交互)。
37
+ */
38
+ onColumn?(handler: (kind: 'hover' | 'click' | 'leave', col: ChartColumn | null) => void): () => void;
26
39
  setOption(option: Readonly<Record<string, unknown>>, mode?: 'merge' | 'replace'): void;
27
40
  /** 键盘漫游驱动 */
28
41
  highlight(p: { seriesIndex: number; dataIndex: number } | null): void;
@@ -1,14 +1,28 @@
1
1
  // jsdiff 缺省适配器(core 引擎端口设计 §7.2):全仓唯一 import `diff` 的文件,只用动态 import()。
2
2
  // 输出纯数据片段;不拼标记 HTML。
3
+ // `words-zh`:`diffWords` + `intlSegmenter`(jsdiff ≥ 8.0.4 才可靠,仓库固定 8.0.4);运行时没有 `Intl.Segmenter` 时退回 `diffChars`。
4
+ // `timeout`:交给 jsdiff,超时库返回 undefined → 本适配器返回 null(端口据此退化)。
3
5
 
4
6
  import { loadEngineModule, type EngineLoadTelemetry } from '../load';
5
7
  import type { DiffMode, DiffOptions, DiffPart, SomaDiffAdapter } from './port';
6
8
 
7
9
  interface JsdiffChange { readonly value: string; readonly added?: boolean; readonly removed?: boolean }
10
+ interface JsdiffBaseOptions { timeout?: number }
8
11
  interface JsdiffModule {
9
- diffChars(a: string, b: string): JsdiffChange[];
10
- diffWords(a: string, b: string): JsdiffChange[];
11
- diffLines(a: string, b: string, options?: { ignoreWhitespace?: boolean }): JsdiffChange[];
12
+ diffChars(a: string, b: string, options?: JsdiffBaseOptions): JsdiffChange[] | undefined;
13
+ diffWords(a: string, b: string, options?: JsdiffBaseOptions & { intlSegmenter?: unknown }): JsdiffChange[] | undefined;
14
+ diffLines(a: string, b: string, options?: JsdiffBaseOptions & { ignoreWhitespace?: boolean }): JsdiffChange[] | undefined;
15
+ }
16
+
17
+ interface SegmenterCtor { new (locale: string, options: { granularity: 'word' }): unknown }
18
+
19
+ /** 运行时的 `Intl.Segmenter`(没有则 null);词粒度分词器只建一次 */
20
+ let wordSegmenter: unknown;
21
+ function zhWordSegmenter(): unknown {
22
+ if (wordSegmenter !== undefined) return wordSegmenter;
23
+ const ctor = (Intl as unknown as { Segmenter?: SegmenterCtor }).Segmenter;
24
+ wordSegmenter = typeof ctor === 'function' ? new ctor('zh', { granularity: 'word' }) : null;
25
+ return wordSegmenter;
12
26
  }
13
27
 
14
28
  export interface JsdiffAdapterOptions { readonly telemetry?: EngineLoadTelemetry }
@@ -18,12 +32,17 @@ export function createJsdiffAdapter(adapterOptions: JsdiffAdapterOptions = {}):
18
32
  loadEngineModule<JsdiffModule>('diff', () => import('diff') as unknown as Promise<JsdiffModule>, { telemetry: adapterOptions.telemetry });
19
33
 
20
34
  return {
21
- async diff(a: string, b: string, mode: DiffMode, options?: DiffOptions): Promise<readonly DiffPart[]> {
35
+ async diff(a: string, b: string, mode: DiffMode, options?: DiffOptions): Promise<readonly DiffPart[] | null> {
22
36
  const lib = await load();
23
- const changes =
24
- mode === 'chars' ? lib.diffChars(a, b)
25
- : mode === 'words' ? lib.diffWords(a, b)
26
- : lib.diffLines(a, b, options?.ignoreWhitespace === true ? { ignoreWhitespace: true } : undefined);
37
+ const base: JsdiffBaseOptions = options?.timeoutMs !== undefined ? { timeout: options.timeoutMs } : {};
38
+ let changes: JsdiffChange[] | undefined;
39
+ if (mode === 'chars') changes = lib.diffChars(a, b, base);
40
+ else if (mode === 'words') changes = lib.diffWords(a, b, base);
41
+ else if (mode === 'words-zh') {
42
+ const seg = zhWordSegmenter();
43
+ changes = seg === null ? lib.diffChars(a, b, base) : lib.diffWords(a, b, { ...base, intlSegmenter: seg });
44
+ } else changes = lib.diffLines(a, b, options?.ignoreWhitespace === true ? { ...base, ignoreWhitespace: true } : base);
45
+ if (changes === undefined) return null;
27
46
  const parts: DiffPart[] = [];
28
47
  for (const change of changes) {
29
48
  if (change.value === '') continue;