@joekytc/dsh-swarm 0.1.2 → 0.2.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.
Files changed (567) hide show
  1. package/README.md +3 -3
  2. package/README.zh-CN.md +3 -3
  3. package/client/BoardCard.tsx +24 -2
  4. package/client/ConfigSection.tsx +71 -0
  5. package/client/ConfigSelect.tsx +69 -0
  6. package/client/KanbanBoard.tsx +3 -0
  7. package/client/KanbanTab.tsx +4 -3
  8. package/client/TaskDrawer.tsx +2 -26
  9. package/client/WorkflowRail.tsx +3 -1
  10. package/client/config-store.ts +51 -0
  11. package/client/config.css +110 -0
  12. package/client/index.ts +39 -4
  13. package/client/kanban.css +19 -2
  14. package/client/session-bridge.ts +39 -0
  15. package/client/timeline-model.ts +10 -1
  16. package/client/workflow-model.ts +3 -1
  17. package/lib/client.js +358 -53
  18. package/lib/config.d.ts +8 -1
  19. package/lib/config.js +6 -1
  20. package/lib/dispatcher/agent-runner.d.ts +28 -6
  21. package/lib/dispatcher/agent-runner.js +175 -62
  22. package/lib/dispatcher/chain-auditor.js +4 -1
  23. package/lib/dispatcher/dispatcher.d.ts +62 -3
  24. package/lib/dispatcher/dispatcher.js +243 -20
  25. package/lib/dispatcher/session-events.d.ts +11 -15
  26. package/lib/dispatcher/session-events.js +17 -5
  27. package/lib/dispatcher/v-orchestrator.d.ts +42 -9
  28. package/lib/dispatcher/v-orchestrator.js +236 -28
  29. package/lib/domain/config-override.d.ts +38 -0
  30. package/lib/domain/config-override.js +101 -0
  31. package/lib/domain/delivery-contract.d.ts +3 -2
  32. package/lib/domain/delivery-contract.js +28 -16
  33. package/lib/domain/gate-policy.d.ts +26 -0
  34. package/lib/domain/gate-policy.js +44 -0
  35. package/lib/domain/kanban-service.d.ts +16 -3
  36. package/lib/domain/kanban-service.js +41 -6
  37. package/lib/domain/permissions.js +1 -1
  38. package/lib/domain/planning-checklist.d.ts +5 -0
  39. package/lib/domain/planning-checklist.js +80 -6
  40. package/lib/domain/projection.js +2 -1
  41. package/lib/domain/review-evidence.js +1 -1
  42. package/lib/domain/state-machine.js +2 -1
  43. package/lib/domain/types.d.ts +2 -2
  44. package/lib/index.js +19 -21
  45. package/lib/roles/clean-fs-tools.d.ts +22 -0
  46. package/lib/roles/clean-fs-tools.js +118 -0
  47. package/lib/roles/skill-installer.d.ts +6 -0
  48. package/lib/roles/skill-installer.js +32 -0
  49. package/lib/roles/toolsets.d.ts +13 -1
  50. package/lib/roles/toolsets.js +163 -31
  51. package/lib/roles/wiki-worker.d.ts +1 -0
  52. package/lib/roles/wiki-worker.js +10 -2
  53. package/lib/routes/kanban-http.d.ts +5 -2
  54. package/lib/routes/kanban-http.js +36 -3
  55. package/lib/routes/planning-driver.d.ts +3 -1
  56. package/lib/routes/planning-driver.js +10 -6
  57. package/lib/routes/prefix-router.d.ts +16 -0
  58. package/lib/routes/prefix-router.js +37 -2
  59. package/lib/services/config-provider.d.ts +42 -0
  60. package/lib/services/config-provider.js +94 -0
  61. package/lib/services/gate-runner.d.ts +24 -0
  62. package/lib/services/gate-runner.js +87 -0
  63. package/lib/services/kanban-provider.d.ts +5 -1
  64. package/lib/services/kanban-provider.js +40 -2
  65. package/lib/services/llm-catalog.d.ts +35 -0
  66. package/lib/services/llm-catalog.js +19 -0
  67. package/lib/tools/kanban-tools.js +1 -0
  68. package/lib/tools/main-session-tools.d.ts +17 -2
  69. package/lib/tools/main-session-tools.js +88 -21
  70. package/lib/tools/planning-tools.d.ts +4 -0
  71. package/lib/tools/planning-tools.js +39 -12
  72. package/lib/tools/prefetch-tools.js +1 -0
  73. package/lib/tools/spec-card-tools.js +1 -0
  74. package/lib/tools/wiki-tools.js +5 -4
  75. package/lib/wiki/kb-linkage.d.ts +9 -2
  76. package/lib/wiki/kb-linkage.js +3 -3
  77. package/lib/wiki/local-kb-client.d.ts +14 -0
  78. package/lib/wiki/local-kb-client.js +101 -0
  79. package/lib/wiki/local-kb.d.ts +6 -0
  80. package/lib/wiki/local-kb.js +25 -0
  81. package/lib/wiki/memory-recall.d.ts +14 -6
  82. package/lib/wiki/memory-recall.js +17 -13
  83. package/lib/wiki/page-path.d.ts +9 -3
  84. package/lib/wiki/page-path.js +29 -11
  85. package/lib/wiki/wiki-vault-client.d.ts +3 -3
  86. package/lib/wiki/wiki-vault-client.js +6 -6
  87. package/package.json +16 -11
  88. package/personas/kanban-d/preset.yml +1 -1
  89. package/personas/kanban-dt/agent.cordis.yml +2 -2
  90. package/personas/kanban-dt/preset.yml +1 -1
  91. package/personas/kanban-p/agent.cordis.yml +16 -0
  92. package/personas/kanban-p/preset.yml +1 -1
  93. package/personas/kanban-pt/agent.cordis.yml +38 -8
  94. package/personas/kanban-pt/preset.yml +1 -1
  95. package/personas/kanban-w/agent.cordis.yml +35 -16
  96. package/personas/kanban-w/preset.yml +1 -1
  97. package/personas/persona-dt.md +1 -1
  98. package/personas/persona-p.md +4 -1
  99. package/personas/persona-pt.md +13 -6
  100. package/personas/persona-w.md +11 -9
  101. package/skills/grill-me/SKILL.md +71 -0
  102. package/skills/llm-wiki-skill/.mise.toml +2 -0
  103. package/skills/llm-wiki-skill/.nvmrc +1 -0
  104. package/skills/llm-wiki-skill/AGENTS.md +173 -0
  105. package/skills/llm-wiki-skill/CHANGELOG.md +548 -0
  106. package/skills/llm-wiki-skill/CLAUDE.md +152 -0
  107. package/skills/llm-wiki-skill/HERMES.md +44 -0
  108. package/skills/llm-wiki-skill/README.en.md +261 -0
  109. package/skills/llm-wiki-skill/README.md +291 -0
  110. package/skills/llm-wiki-skill/SKILL.md +1133 -0
  111. package/skills/llm-wiki-skill/assets/graph-demo.gif +0 -0
  112. package/skills/llm-wiki-skill/assets/graph-preview.png +0 -0
  113. package/skills/llm-wiki-skill/deps/LICENSE-d3.txt +13 -0
  114. package/skills/llm-wiki-skill/deps/LICENSE-marked.txt +44 -0
  115. package/skills/llm-wiki-skill/deps/LICENSE-purify.txt +568 -0
  116. package/skills/llm-wiki-skill/deps/LICENSE-roughjs.txt +21 -0
  117. package/skills/llm-wiki-skill/deps/baoyu-url-to-markdown/SKILL.md +261 -0
  118. package/skills/llm-wiki-skill/deps/baoyu-url-to-markdown/references/config/first-time-setup.md +106 -0
  119. package/skills/llm-wiki-skill/deps/baoyu-url-to-markdown/scripts/cdp.ts +179 -0
  120. package/skills/llm-wiki-skill/deps/baoyu-url-to-markdown/scripts/constants.ts +13 -0
  121. package/skills/llm-wiki-skill/deps/baoyu-url-to-markdown/scripts/defuddle-converter.ts +58 -0
  122. package/skills/llm-wiki-skill/deps/baoyu-url-to-markdown/scripts/html-to-markdown.ts +135 -0
  123. package/skills/llm-wiki-skill/deps/baoyu-url-to-markdown/scripts/legacy-converter.ts +629 -0
  124. package/skills/llm-wiki-skill/deps/baoyu-url-to-markdown/scripts/main.ts +314 -0
  125. package/skills/llm-wiki-skill/deps/baoyu-url-to-markdown/scripts/markdown-conversion-shared.ts +305 -0
  126. package/skills/llm-wiki-skill/deps/baoyu-url-to-markdown/scripts/media-localizer.ts +317 -0
  127. package/skills/llm-wiki-skill/deps/baoyu-url-to-markdown/scripts/package.json +14 -0
  128. package/skills/llm-wiki-skill/deps/baoyu-url-to-markdown/scripts/paths.ts +29 -0
  129. package/skills/llm-wiki-skill/deps/baoyu-url-to-markdown/scripts/vendor/baoyu-chrome-cdp/package.json +9 -0
  130. package/skills/llm-wiki-skill/deps/baoyu-url-to-markdown/scripts/vendor/baoyu-chrome-cdp/src/index.test.ts +307 -0
  131. package/skills/llm-wiki-skill/deps/baoyu-url-to-markdown/scripts/vendor/baoyu-chrome-cdp/src/index.ts +523 -0
  132. package/skills/llm-wiki-skill/deps/d3.min.js +2 -0
  133. package/skills/llm-wiki-skill/deps/marked.min.js +6 -0
  134. package/skills/llm-wiki-skill/deps/purify.min.js +3 -0
  135. package/skills/llm-wiki-skill/deps/rough.min.js +7 -0
  136. package/skills/llm-wiki-skill/deps/youtube-transcript/SKILL.md +47 -0
  137. package/skills/llm-wiki-skill/deps/youtube-transcript/scripts/get_transcript.py +72 -0
  138. package/skills/llm-wiki-skill/designs/graph-edge-legibility/graph-edge-treatments.html +480 -0
  139. package/skills/llm-wiki-skill/docs/design/oriental-atlas/DESIGN.md +183 -0
  140. package/skills/llm-wiki-skill/docs/design/oriental-atlas/README.md +10 -0
  141. package/skills/llm-wiki-skill/docs/design/oriental-atlas/design-brief.md +170 -0
  142. package/skills/llm-wiki-skill/docs/design/oriental-atlas/oriental-editorial-atlas.html +1908 -0
  143. package/skills/llm-wiki-skill/docs/design/oriental-atlas/reviews/result-review.md +68 -0
  144. package/skills/llm-wiki-skill/docs/graph/2026-06-16-interaction-risk-audit.md +88 -0
  145. package/skills/llm-wiki-skill/docs/graph/2026-06-16-interaction-test-coverage-map.md +212 -0
  146. package/skills/llm-wiki-skill/docs/graph/performance/2026-06-18-phase-0-2-baseline.md +86 -0
  147. package/skills/llm-wiki-skill/docs/graph/performance/2026-06-18-phase-1-3-dom-svg-large-baseline.md +85 -0
  148. package/skills/llm-wiki-skill/docs/graph/performance/2026-06-18-phase-1-4-disposable-validation-gate.md +97 -0
  149. package/skills/llm-wiki-skill/docs/graph/performance/2026-06-18-phase-2-4-global-renderer-trial-matrix.md +168 -0
  150. package/skills/llm-wiki-skill/docs/graph/performance/2026-06-19-phase-6-1-sigma-graphology-trial.md +71 -0
  151. package/skills/llm-wiki-skill/docs/graph/performance/2026-06-19-phase-6-2-vis-network-trial.md +78 -0
  152. package/skills/llm-wiki-skill/docs/graph/performance/2026-06-19-phase-6-3-aggregation-fallback-trial.md +72 -0
  153. package/skills/llm-wiki-skill/docs/graph/performance/2026-06-19-phase-6-4-global-renderer-route-decision.md +94 -0
  154. package/skills/llm-wiki-skill/docs/graph/performance/2026-06-19-sigma-global-production-integration-result.md +102 -0
  155. package/skills/llm-wiki-skill/docs/graph/performance/artifacts/2026-06-18-phase-0-2/stage-4.5-offline-dense-wheel.json +9 -0
  156. package/skills/llm-wiki-skill/docs/graph/performance/artifacts/2026-06-18-phase-0-2/stage-4.5-offline-dense-wheel.png +0 -0
  157. package/skills/llm-wiki-skill/docs/graph/performance/artifacts/2026-06-18-phase-0-2/stage-4.5-offline-navigation.png +0 -0
  158. package/skills/llm-wiki-skill/docs/spark/2026-06-15-omp-tool-status-events-design.md +174 -0
  159. package/skills/llm-wiki-skill/docs/spark/2026-06-16-graph-interaction-geometry-design.md +832 -0
  160. package/skills/llm-wiki-skill/docs/spark/2026-06-16-graph-six-layer-architecture-design.md +577 -0
  161. package/skills/llm-wiki-skill/docs/spark/2026-06-17-static-renderer-coordination-split-design.md +172 -0
  162. package/skills/llm-wiki-skill/docs/spark/2026-06-18-large-graph-global-community-design.md +909 -0
  163. package/skills/llm-wiki-skill/docs/spark/2026-06-19-sigma-global-graph-renderer-design.md +360 -0
  164. package/skills/llm-wiki-skill/docs/spark/2026-06-20-paper-ui-port-design.md +162 -0
  165. package/skills/llm-wiki-skill/docs/spark/2026-06-20-paper-ui-v2-shell-alignment-design.md +384 -0
  166. package/skills/llm-wiki-skill/docs/spark/2026-06-21-graph-experience-completion-design.md +534 -0
  167. package/skills/llm-wiki-skill/docs/spark/2026-06-22-chat-auto-scroll-design.md +185 -0
  168. package/skills/llm-wiki-skill/docs/spark/2026-06-22-graph-community-node-visual-design.md +266 -0
  169. package/skills/llm-wiki-skill/docs/spark/2026-06-25-sigma-overlay-refactor-perf-design.md +170 -0
  170. package/skills/llm-wiki-skill/docs/spark/2026-06-26-global-sigma-community-spotlight-design.md +393 -0
  171. package/skills/llm-wiki-skill/docs/spark/mockups/2026-06-18-large-graph-global-community-flow.html +746 -0
  172. package/skills/llm-wiki-skill/install.ps1 +87 -0
  173. package/skills/llm-wiki-skill/install.sh +722 -0
  174. package/skills/llm-wiki-skill/package-lock.json +11171 -0
  175. package/skills/llm-wiki-skill/package.json +24 -0
  176. package/skills/llm-wiki-skill/packages/graph-engine/package.json +37 -0
  177. package/skills/llm-wiki-skill/packages/graph-engine/src/anim/.gitkeep +1 -0
  178. package/skills/llm-wiki-skill/packages/graph-engine/src/anim/index.ts +179 -0
  179. package/skills/llm-wiki-skill/packages/graph-engine/src/architecture.ts +79 -0
  180. package/skills/llm-wiki-skill/packages/graph-engine/src/diff.ts +121 -0
  181. package/skills/llm-wiki-skill/packages/graph-engine/src/facade.ts +1406 -0
  182. package/skills/llm-wiki-skill/packages/graph-engine/src/graph-node.ts +37 -0
  183. package/skills/llm-wiki-skill/packages/graph-engine/src/index.ts +25 -0
  184. package/skills/llm-wiki-skill/packages/graph-engine/src/layout/edge-geometry.ts +17 -0
  185. package/skills/llm-wiki-skill/packages/graph-engine/src/layout/index.ts +16 -0
  186. package/skills/llm-wiki-skill/packages/graph-engine/src/layout/spatial-index.ts +509 -0
  187. package/skills/llm-wiki-skill/packages/graph-engine/src/model/atlas.ts +18 -0
  188. package/skills/llm-wiki-skill/packages/graph-engine/src/model/index.ts +10 -0
  189. package/skills/llm-wiki-skill/packages/graph-engine/src/model/labels.ts +11 -0
  190. package/skills/llm-wiki-skill/packages/graph-engine/src/model/layout.ts +81 -0
  191. package/skills/llm-wiki-skill/packages/graph-engine/src/model/learning.ts +8 -0
  192. package/skills/llm-wiki-skill/packages/graph-engine/src/model/legacy-helpers.ts +1379 -0
  193. package/skills/llm-wiki-skill/packages/graph-engine/src/model/queue.ts +7 -0
  194. package/skills/llm-wiki-skill/packages/graph-engine/src/model/storage.ts +4 -0
  195. package/skills/llm-wiki-skill/packages/graph-engine/src/model/visibility.ts +9 -0
  196. package/skills/llm-wiki-skill/packages/graph-engine/src/render/.gitkeep +1 -0
  197. package/skills/llm-wiki-skill/packages/graph-engine/src/render/adapter.ts +443 -0
  198. package/skills/llm-wiki-skill/packages/graph-engine/src/render/aggregation-containers.ts +64 -0
  199. package/skills/llm-wiki-skill/packages/graph-engine/src/render/community-cloud-geometry.ts +178 -0
  200. package/skills/llm-wiki-skill/packages/graph-engine/src/render/community-wash.ts +238 -0
  201. package/skills/llm-wiki-skill/packages/graph-engine/src/render/community-washes.ts +19 -0
  202. package/skills/llm-wiki-skill/packages/graph-engine/src/render/compat-contract.ts +14 -0
  203. package/skills/llm-wiki-skill/packages/graph-engine/src/render/controller.ts +705 -0
  204. package/skills/llm-wiki-skill/packages/graph-engine/src/render/controls.ts +288 -0
  205. package/skills/llm-wiki-skill/packages/graph-engine/src/render/dom-svg-renderer.ts +180 -0
  206. package/skills/llm-wiki-skill/packages/graph-engine/src/render/edges.ts +51 -0
  207. package/skills/llm-wiki-skill/packages/graph-engine/src/render/geometry.ts +380 -0
  208. package/skills/llm-wiki-skill/packages/graph-engine/src/render/gestures.ts +673 -0
  209. package/skills/llm-wiki-skill/packages/graph-engine/src/render/graph-renderer-root.ts +387 -0
  210. package/skills/llm-wiki-skill/packages/graph-engine/src/render/hit-testing.ts +56 -0
  211. package/skills/llm-wiki-skill/packages/graph-engine/src/render/host-dom.ts +14 -0
  212. package/skills/llm-wiki-skill/packages/graph-engine/src/render/hover-card.ts +37 -0
  213. package/skills/llm-wiki-skill/packages/graph-engine/src/render/index.ts +213 -0
  214. package/skills/llm-wiki-skill/packages/graph-engine/src/render/keyboard.ts +48 -0
  215. package/skills/llm-wiki-skill/packages/graph-engine/src/render/legend.ts +25 -0
  216. package/skills/llm-wiki-skill/packages/graph-engine/src/render/minimap.ts +45 -0
  217. package/skills/llm-wiki-skill/packages/graph-engine/src/render/model.ts +1339 -0
  218. package/skills/llm-wiki-skill/packages/graph-engine/src/render/node-drag-lifecycle.ts +94 -0
  219. package/skills/llm-wiki-skill/packages/graph-engine/src/render/nodes.ts +103 -0
  220. package/skills/llm-wiki-skill/packages/graph-engine/src/render/offline-reader.ts +209 -0
  221. package/skills/llm-wiki-skill/packages/graph-engine/src/render/overlays-presenter.ts +192 -0
  222. package/skills/llm-wiki-skill/packages/graph-engine/src/render/overlays.ts +73 -0
  223. package/skills/llm-wiki-skill/packages/graph-engine/src/render/pin-position.ts +51 -0
  224. package/skills/llm-wiki-skill/packages/graph-engine/src/render/preview.ts +65 -0
  225. package/skills/llm-wiki-skill/packages/graph-engine/src/render/relation-focus.ts +91 -0
  226. package/skills/llm-wiki-skill/packages/graph-engine/src/render/render-context.ts +85 -0
  227. package/skills/llm-wiki-skill/packages/graph-engine/src/render/render-pipeline.ts +871 -0
  228. package/skills/llm-wiki-skill/packages/graph-engine/src/render/render-styles.ts +1405 -0
  229. package/skills/llm-wiki-skill/packages/graph-engine/src/render/renderer-surface.ts +75 -0
  230. package/skills/llm-wiki-skill/packages/graph-engine/src/render/search.ts +57 -0
  231. package/skills/llm-wiki-skill/packages/graph-engine/src/render/sigma-coordinates.ts +44 -0
  232. package/skills/llm-wiki-skill/packages/graph-engine/src/render/sigma-global-drag.ts +246 -0
  233. package/skills/llm-wiki-skill/packages/graph-engine/src/render/sigma-global-renderer.ts +1425 -0
  234. package/skills/llm-wiki-skill/packages/graph-engine/src/render/sigma-overlay-svg.ts +121 -0
  235. package/skills/llm-wiki-skill/packages/graph-engine/src/render/simulation-bridge.ts +59 -0
  236. package/skills/llm-wiki-skill/packages/graph-engine/src/render/state.ts +262 -0
  237. package/skills/llm-wiki-skill/packages/graph-engine/src/render/toolbar.ts +40 -0
  238. package/skills/llm-wiki-skill/packages/graph-engine/src/render/viewport.ts +336 -0
  239. package/skills/llm-wiki-skill/packages/graph-engine/src/select/.gitkeep +1 -0
  240. package/skills/llm-wiki-skill/packages/graph-engine/src/select/index.ts +189 -0
  241. package/skills/llm-wiki-skill/packages/graph-engine/src/sim/index.ts +372 -0
  242. package/skills/llm-wiki-skill/packages/graph-engine/src/sim/pins.ts +84 -0
  243. package/skills/llm-wiki-skill/packages/graph-engine/src/summary/index.ts +447 -0
  244. package/skills/llm-wiki-skill/packages/graph-engine/src/themes/.gitkeep +1 -0
  245. package/skills/llm-wiki-skill/packages/graph-engine/src/themes/index.ts +8 -0
  246. package/skills/llm-wiki-skill/packages/graph-engine/src/themes/tokens.ts +117 -0
  247. package/skills/llm-wiki-skill/packages/graph-engine/src/types/d3-quadtree.d.ts +22 -0
  248. package/skills/llm-wiki-skill/packages/graph-engine/src/types.ts +531 -0
  249. package/skills/llm-wiki-skill/packages/graph-engine/test/aggregation-fallback-trial-adapter.test.ts +115 -0
  250. package/skills/llm-wiki-skill/packages/graph-engine/test/aggregation-fallback-trial-adapter.ts +222 -0
  251. package/skills/llm-wiki-skill/packages/graph-engine/test/anim.test.ts +121 -0
  252. package/skills/llm-wiki-skill/packages/graph-engine/test/architecture.test.ts +63 -0
  253. package/skills/llm-wiki-skill/packages/graph-engine/test/community-cloud-geometry.test.ts +86 -0
  254. package/skills/llm-wiki-skill/packages/graph-engine/test/community-wash.test.ts +97 -0
  255. package/skills/llm-wiki-skill/packages/graph-engine/test/diff.test.ts +133 -0
  256. package/skills/llm-wiki-skill/packages/graph-engine/test/facade.test.ts +1369 -0
  257. package/skills/llm-wiki-skill/packages/graph-engine/test/geometry.test.ts +147 -0
  258. package/skills/llm-wiki-skill/packages/graph-engine/test/gestures.test.ts +768 -0
  259. package/skills/llm-wiki-skill/packages/graph-engine/test/graph-layout.test.ts +110 -0
  260. package/skills/llm-wiki-skill/packages/graph-engine/test/helpers.test.ts +287 -0
  261. package/skills/llm-wiki-skill/packages/graph-engine/test/interaction-contract.test.ts +106 -0
  262. package/skills/llm-wiki-skill/packages/graph-engine/test/keyboard.test.ts +59 -0
  263. package/skills/llm-wiki-skill/packages/graph-engine/test/large-fixtures.test.ts +47 -0
  264. package/skills/llm-wiki-skill/packages/graph-engine/test/large-graph-fixtures.ts +420 -0
  265. package/skills/llm-wiki-skill/packages/graph-engine/test/learning.test.ts +259 -0
  266. package/skills/llm-wiki-skill/packages/graph-engine/test/node-drag-lifecycle.test.ts +166 -0
  267. package/skills/llm-wiki-skill/packages/graph-engine/test/overlays.test.ts +115 -0
  268. package/skills/llm-wiki-skill/packages/graph-engine/test/preview.test.ts +56 -0
  269. package/skills/llm-wiki-skill/packages/graph-engine/test/queue.test.ts +114 -0
  270. package/skills/llm-wiki-skill/packages/graph-engine/test/relation-focus.test.ts +115 -0
  271. package/skills/llm-wiki-skill/packages/graph-engine/test/render-model.test.ts +1030 -0
  272. package/skills/llm-wiki-skill/packages/graph-engine/test/renderer-adapter-contract.test.ts +271 -0
  273. package/skills/llm-wiki-skill/packages/graph-engine/test/renderer-boundary.test.ts +618 -0
  274. package/skills/llm-wiki-skill/packages/graph-engine/test/renderer-lifecycle.test.ts +1711 -0
  275. package/skills/llm-wiki-skill/packages/graph-engine/test/route-continuity.test.ts +284 -0
  276. package/skills/llm-wiki-skill/packages/graph-engine/test/runtime-state.test.ts +281 -0
  277. package/skills/llm-wiki-skill/packages/graph-engine/test/search-and-legend.test.ts +124 -0
  278. package/skills/llm-wiki-skill/packages/graph-engine/test/select.test.ts +168 -0
  279. package/skills/llm-wiki-skill/packages/graph-engine/test/sigma-coordinates.test.ts +50 -0
  280. package/skills/llm-wiki-skill/packages/graph-engine/test/sigma-global-renderer.test.ts +2210 -0
  281. package/skills/llm-wiki-skill/packages/graph-engine/test/sigma-trial-adapter.test.ts +82 -0
  282. package/skills/llm-wiki-skill/packages/graph-engine/test/sigma-trial-adapter.ts +271 -0
  283. package/skills/llm-wiki-skill/packages/graph-engine/test/sim.test.ts +207 -0
  284. package/skills/llm-wiki-skill/packages/graph-engine/test/simulation-bridge.test.ts +96 -0
  285. package/skills/llm-wiki-skill/packages/graph-engine/test/spatial-index.test.ts +222 -0
  286. package/skills/llm-wiki-skill/packages/graph-engine/test/state.test.ts +189 -0
  287. package/skills/llm-wiki-skill/packages/graph-engine/test/summary-contract.test.ts +422 -0
  288. package/skills/llm-wiki-skill/packages/graph-engine/test/themes.test.ts +62 -0
  289. package/skills/llm-wiki-skill/packages/graph-engine/test/toolbar.test.ts +64 -0
  290. package/skills/llm-wiki-skill/packages/graph-engine/test/viewport.test.ts +213 -0
  291. package/skills/llm-wiki-skill/packages/graph-engine/test/vis-network-trial-adapter.test.ts +82 -0
  292. package/skills/llm-wiki-skill/packages/graph-engine/test/vis-network-trial-adapter.ts +186 -0
  293. package/skills/llm-wiki-skill/packages/graph-engine/tsconfig.json +17 -0
  294. package/skills/llm-wiki-skill/packages/graph-engine/vite.config.ts +15 -0
  295. package/skills/llm-wiki-skill/platforms/claude/CLAUDE.md +37 -0
  296. package/skills/llm-wiki-skill/platforms/claude/companions/llm-wiki-upgrade/SKILL.md +95 -0
  297. package/skills/llm-wiki-skill/platforms/codex/AGENTS.md +23 -0
  298. package/skills/llm-wiki-skill/platforms/hermes/README.md +31 -0
  299. package/skills/llm-wiki-skill/platforms/openclaw/README.md +31 -0
  300. package/skills/llm-wiki-skill/scripts/adapter-state.sh +424 -0
  301. package/skills/llm-wiki-skill/scripts/build-graph-data.sh +395 -0
  302. package/skills/llm-wiki-skill/scripts/build-graph-html.sh +459 -0
  303. package/skills/llm-wiki-skill/scripts/cache.sh +352 -0
  304. package/skills/llm-wiki-skill/scripts/create-source-page.sh +100 -0
  305. package/skills/llm-wiki-skill/scripts/delete-helper.sh +68 -0
  306. package/skills/llm-wiki-skill/scripts/graph-analysis.js +732 -0
  307. package/skills/llm-wiki-skill/scripts/hook-session-start.sh +46 -0
  308. package/skills/llm-wiki-skill/scripts/init-wiki.sh +95 -0
  309. package/skills/llm-wiki-skill/scripts/lib/source-signal-eligibility.js +158 -0
  310. package/skills/llm-wiki-skill/scripts/lint-fix.sh +114 -0
  311. package/skills/llm-wiki-skill/scripts/lint-runner.sh +217 -0
  312. package/skills/llm-wiki-skill/scripts/runtime-context.sh +77 -0
  313. package/skills/llm-wiki-skill/scripts/shared-config.sh +83 -0
  314. package/skills/llm-wiki-skill/scripts/source-record-contract.tsv +10 -0
  315. package/skills/llm-wiki-skill/scripts/source-registry.sh +349 -0
  316. package/skills/llm-wiki-skill/scripts/source-registry.tsv +10 -0
  317. package/skills/llm-wiki-skill/scripts/source-signal-coverage.js +83 -0
  318. package/skills/llm-wiki-skill/scripts/validate-step1.sh +144 -0
  319. package/skills/llm-wiki-skill/scripts/wiki-compat.sh +267 -0
  320. package/skills/llm-wiki-skill/setup.sh +8 -0
  321. package/skills/llm-wiki-skill/templates/entity-template.md +30 -0
  322. package/skills/llm-wiki-skill/templates/graph-styles/wash/footer.html +27 -0
  323. package/skills/llm-wiki-skill/templates/graph-styles/wash/graph-wash-helpers.js +1326 -0
  324. package/skills/llm-wiki-skill/templates/graph-styles/wash/graph-wash.js +1009 -0
  325. package/skills/llm-wiki-skill/templates/graph-styles/wash/header.html +2002 -0
  326. package/skills/llm-wiki-skill/templates/index-en-template.md +51 -0
  327. package/skills/llm-wiki-skill/templates/index-template.md +51 -0
  328. package/skills/llm-wiki-skill/templates/log-en-template.md +11 -0
  329. package/skills/llm-wiki-skill/templates/log-template.md +11 -0
  330. package/skills/llm-wiki-skill/templates/overview-en-template.md +41 -0
  331. package/skills/llm-wiki-skill/templates/overview-template.md +41 -0
  332. package/skills/llm-wiki-skill/templates/purpose-en-template.md +16 -0
  333. package/skills/llm-wiki-skill/templates/purpose-template.md +16 -0
  334. package/skills/llm-wiki-skill/templates/query-template.md +19 -0
  335. package/skills/llm-wiki-skill/templates/schema-template.md +185 -0
  336. package/skills/llm-wiki-skill/templates/source-template.md +51 -0
  337. package/skills/llm-wiki-skill/templates/synthesis-template.md +25 -0
  338. package/skills/llm-wiki-skill/templates/topic-template.md +35 -0
  339. package/skills/llm-wiki-skill/tests/adapter-state.sh +338 -0
  340. package/skills/llm-wiki-skill/tests/browser/graph-aggregation-fallback-trial.ts +737 -0
  341. package/skills/llm-wiki-skill/tests/browser/graph-community-node-map.mjs +255 -0
  342. package/skills/llm-wiki-skill/tests/browser/graph-community-wash-interactions.mjs +170 -0
  343. package/skills/llm-wiki-skill/tests/browser/graph-default-behavior.mjs +630 -0
  344. package/skills/llm-wiki-skill/tests/browser/graph-density-preview.mjs +53 -0
  345. package/skills/llm-wiki-skill/tests/browser/graph-html-insights.mjs +41 -0
  346. package/skills/llm-wiki-skill/tests/browser/graph-large-performance.ts +689 -0
  347. package/skills/llm-wiki-skill/tests/browser/graph-node-slim.mjs +75 -0
  348. package/skills/llm-wiki-skill/tests/browser/graph-offline-phase-6.mjs +660 -0
  349. package/skills/llm-wiki-skill/tests/browser/graph-renderer-trial-shared.ts +291 -0
  350. package/skills/llm-wiki-skill/tests/browser/graph-sigma-global-production.ts +1437 -0
  351. package/skills/llm-wiki-skill/tests/browser/graph-sigma-graphology-trial.ts +949 -0
  352. package/skills/llm-wiki-skill/tests/browser/graph-stage-4-5.mjs +815 -0
  353. package/skills/llm-wiki-skill/tests/browser/graph-vis-network-trial.ts +762 -0
  354. package/skills/llm-wiki-skill/tests/browser/graph-workbench-interactions.mjs +730 -0
  355. package/skills/llm-wiki-skill/tests/browser/validate-graph-trial-result.mjs +149 -0
  356. package/skills/llm-wiki-skill/tests/expected/graph-data-empty.json +60 -0
  357. package/skills/llm-wiki-skill/tests/expected/graph-data-sample.json +396 -0
  358. package/skills/llm-wiki-skill/tests/expected/graph-interactive-basic.html +1736 -0
  359. package/skills/llm-wiki-skill/tests/expected/lint-output.txt +44 -0
  360. package/skills/llm-wiki-skill/tests/fixtures/coverage-sample-wiki/index.md +1 -0
  361. package/skills/llm-wiki-skill/tests/fixtures/coverage-sample-wiki/wiki/entities/Alpha.md +10 -0
  362. package/skills/llm-wiki-skill/tests/fixtures/coverage-sample-wiki/wiki/entities/Beta.md +7 -0
  363. package/skills/llm-wiki-skill/tests/fixtures/coverage-sample-wiki/wiki/entities/Delta.md +8 -0
  364. package/skills/llm-wiki-skill/tests/fixtures/coverage-sample-wiki/wiki/entities/Gamma.md +8 -0
  365. package/skills/llm-wiki-skill/tests/fixtures/coverage-sample-wiki/wiki/queries/20260422-abc.md +10 -0
  366. package/skills/llm-wiki-skill/tests/fixtures/coverage-sample-wiki/wiki/synthesis/Crystal.md +8 -0
  367. package/skills/llm-wiki-skill/tests/fixtures/coverage-sample-wiki/wiki/topics/Overview.md +9 -0
  368. package/skills/llm-wiki-skill/tests/fixtures/graph-data-empty-wiki/wiki/entities/.gitkeep +0 -0
  369. package/skills/llm-wiki-skill/tests/fixtures/graph-data-sample-wiki/purpose.md +3 -0
  370. package/skills/llm-wiki-skill/tests/fixtures/graph-data-sample-wiki/wiki/entities/Attention.md +7 -0
  371. package/skills/llm-wiki-skill/tests/fixtures/graph-data-sample-wiki/wiki/entities/Decoder.md +7 -0
  372. package/skills/llm-wiki-skill/tests/fixtures/graph-data-sample-wiki/wiki/entities/Encoder.md +7 -0
  373. package/skills/llm-wiki-skill/tests/fixtures/graph-data-sample-wiki/wiki/entities/GPT.md +7 -0
  374. package/skills/llm-wiki-skill/tests/fixtures/graph-data-sample-wiki/wiki/entities/Transformer.md +13 -0
  375. package/skills/llm-wiki-skill/tests/fixtures/graph-data-sample-wiki/wiki/sources/paper.md +9 -0
  376. package/skills/llm-wiki-skill/tests/fixtures/graph-data-sample-wiki/wiki/topics/arch.md +12 -0
  377. package/skills/llm-wiki-skill/tests/fixtures/graph-data-sample-wiki/wiki/topics/finetune.md +9 -0
  378. package/skills/llm-wiki-skill/tests/fixtures/graph-interactive-basic/wiki/graph-data.json +40 -0
  379. package/skills/llm-wiki-skill/tests/fixtures/graph-interactive-dense/wiki/graph-data.json +3965 -0
  380. package/skills/llm-wiki-skill/tests/fixtures/graph-interactive-multicomm/wiki/graph-data.json +212 -0
  381. package/skills/llm-wiki-skill/tests/fixtures/lint-sample-wiki/index.md +14 -0
  382. package/skills/llm-wiki-skill/tests/fixtures/lint-sample-wiki/wiki/entities/C++.md +6 -0
  383. package/skills/llm-wiki-skill/tests/fixtures/lint-sample-wiki/wiki/entities/Lonely.md +4 -0
  384. package/skills/llm-wiki-skill/tests/fixtures/lint-sample-wiki/wiki/entities/Other.md +8 -0
  385. package/skills/llm-wiki-skill/tests/fixtures/lint-sample-wiki/wiki/entities/Real.md +7 -0
  386. package/skills/llm-wiki-skill/tests/fixtures/lint-sample-wiki/wiki/sources/2026-01-01-test-source.md +15 -0
  387. package/skills/llm-wiki-skill/tests/fixtures/lint-sample-wiki/wiki/sources/2026-02-01-inline-img.md +12 -0
  388. package/skills/llm-wiki-skill/tests/fixtures/lint-sample-wiki/wiki/topics/AIbasic.md +3 -0
  389. package/skills/llm-wiki-skill/tests/graph-aggregation-fallback-trial.regression-1.sh +46 -0
  390. package/skills/llm-wiki-skill/tests/graph-analysis-helper.regression-1.sh +237 -0
  391. package/skills/llm-wiki-skill/tests/graph-browser-large-performance.regression-1.sh +39 -0
  392. package/skills/llm-wiki-skill/tests/graph-browser-stage-4-5.regression-1.sh +163 -0
  393. package/skills/llm-wiki-skill/tests/graph-build-failures.regression-1.sh +91 -0
  394. package/skills/llm-wiki-skill/tests/graph-community-node-map.regression-1.sh +107 -0
  395. package/skills/llm-wiki-skill/tests/graph-community-wash-interactions.regression-1.sh +35 -0
  396. package/skills/llm-wiki-skill/tests/graph-data-confidence-merge.regression-1.sh +309 -0
  397. package/skills/llm-wiki-skill/tests/graph-data-source-paths.regression-1.sh +49 -0
  398. package/skills/llm-wiki-skill/tests/graph-default-behavior.regression-1.sh +35 -0
  399. package/skills/llm-wiki-skill/tests/graph-html-a11y.regression-1.sh +50 -0
  400. package/skills/llm-wiki-skill/tests/graph-html-brand-link.regression-1.sh +47 -0
  401. package/skills/llm-wiki-skill/tests/graph-html-density.regression-1.sh +228 -0
  402. package/skills/llm-wiki-skill/tests/graph-html-drawer-neighbors.regression-1.sh +47 -0
  403. package/skills/llm-wiki-skill/tests/graph-html-insights.regression-1.sh +80 -0
  404. package/skills/llm-wiki-skill/tests/graph-html-long-label.regression-1.sh +92 -0
  405. package/skills/llm-wiki-skill/tests/graph-html-minimap.regression-1.sh +51 -0
  406. package/skills/llm-wiki-skill/tests/graph-html-mobile.regression-1.sh +48 -0
  407. package/skills/llm-wiki-skill/tests/graph-html-oriental-atlas-contract.regression-1.sh +94 -0
  408. package/skills/llm-wiki-skill/tests/graph-html-oriental-design-contract.regression-1.sh +82 -0
  409. package/skills/llm-wiki-skill/tests/graph-html-search.regression-1.sh +52 -0
  410. package/skills/llm-wiki-skill/tests/graph-html-styles.regression-1.sh +66 -0
  411. package/skills/llm-wiki-skill/tests/graph-html-toolbar.regression-1.sh +62 -0
  412. package/skills/llm-wiki-skill/tests/graph-offline-phase-6.regression-1.sh +51 -0
  413. package/skills/llm-wiki-skill/tests/graph-sigma-global-production.regression-1.sh +64 -0
  414. package/skills/llm-wiki-skill/tests/graph-sigma-graphology-trial.regression-1.sh +46 -0
  415. package/skills/llm-wiki-skill/tests/graph-vis-network-trial.regression-1.sh +46 -0
  416. package/skills/llm-wiki-skill/tests/graph-workbench-interactions.regression-1.sh +151 -0
  417. package/skills/llm-wiki-skill/tests/js/graph-wash-bootstrap.test.js +110 -0
  418. package/skills/llm-wiki-skill/tests/js/graph-wash-helpers.test.js +296 -0
  419. package/skills/llm-wiki-skill/tests/js/graph-wash-learning.test.js +260 -0
  420. package/skills/llm-wiki-skill/tests/js/graph-wash-queue.test.js +115 -0
  421. package/skills/llm-wiki-skill/tests/js/graph-wash-runtime-state.test.js +282 -0
  422. package/skills/llm-wiki-skill/tests/js/source-signal-coverage.test.js +48 -0
  423. package/skills/llm-wiki-skill/tests/js/source-signal-eligibility.test.js +202 -0
  424. package/skills/llm-wiki-skill/tests/lib/graph-html-engine-helpers.sh +110 -0
  425. package/skills/llm-wiki-skill/tests/lint-output.regression-1.sh +32 -0
  426. package/skills/llm-wiki-skill/tests/regression.sh +1754 -0
  427. package/skills/llm-wiki-skill/workbench/AGENTS.md +110 -0
  428. package/skills/llm-wiki-skill/workbench/CLAUDE.md +55 -0
  429. package/skills/llm-wiki-skill/workbench/LICENSE +21 -0
  430. package/skills/llm-wiki-skill/workbench/PRODUCT.md +1353 -0
  431. package/skills/llm-wiki-skill/workbench/README.md +30 -0
  432. package/skills/llm-wiki-skill/workbench/docs/current-kb-retrieval-design.md +587 -0
  433. package/skills/llm-wiki-skill/workbench/docs/graph-evolution-1-design.md +210 -0
  434. package/skills/llm-wiki-skill/workbench/docs/stage-2-design.md +1139 -0
  435. package/skills/llm-wiki-skill/workbench/docs/stage-3-design.md +1269 -0
  436. package/skills/llm-wiki-skill/workbench/docs/stage-3.5-design.md +1164 -0
  437. package/skills/llm-wiki-skill/workbench/docs/stage-4-design.md +504 -0
  438. package/skills/llm-wiki-skill/workbench/docs/stage-4.5-design.md +195 -0
  439. package/skills/llm-wiki-skill/workbench/docs/superpowers/specs/2026-05-28-resizable-preview-layout-design.md +165 -0
  440. package/skills/llm-wiki-skill/workbench/docs/superpowers/specs/2026-05-28-settings-panel-scroll-fix.md +50 -0
  441. package/skills/llm-wiki-skill/workbench/server/package.json +31 -0
  442. package/skills/llm-wiki-skill/workbench/server/src/agent.ts +457 -0
  443. package/skills/llm-wiki-skill/workbench/server/src/artifacts.ts +248 -0
  444. package/skills/llm-wiki-skill/workbench/server/src/auth.ts +164 -0
  445. package/skills/llm-wiki-skill/workbench/server/src/config.ts +130 -0
  446. package/skills/llm-wiki-skill/workbench/server/src/conversations.test.ts +159 -0
  447. package/skills/llm-wiki-skill/workbench/server/src/conversations.ts +270 -0
  448. package/skills/llm-wiki-skill/workbench/server/src/digest/batch.ts +189 -0
  449. package/skills/llm-wiki-skill/workbench/server/src/digest/concurrency.test.ts +36 -0
  450. package/skills/llm-wiki-skill/workbench/server/src/digest/concurrency.ts +31 -0
  451. package/skills/llm-wiki-skill/workbench/server/src/digest/subagent.ts +91 -0
  452. package/skills/llm-wiki-skill/workbench/server/src/extensions/artifacts.ts +81 -0
  453. package/skills/llm-wiki-skill/workbench/server/src/extensions/knowledge-base.ts +263 -0
  454. package/skills/llm-wiki-skill/workbench/server/src/extensions/new-wiki.ts +42 -0
  455. package/skills/llm-wiki-skill/workbench/server/src/extensions/synthesis.ts +172 -0
  456. package/skills/llm-wiki-skill/workbench/server/src/graph-watcher.test.ts +196 -0
  457. package/skills/llm-wiki-skill/workbench/server/src/graph.test.ts +113 -0
  458. package/skills/llm-wiki-skill/workbench/server/src/graph.ts +351 -0
  459. package/skills/llm-wiki-skill/workbench/server/src/index.ts +1148 -0
  460. package/skills/llm-wiki-skill/workbench/server/src/knowledge-bases.test.ts +30 -0
  461. package/skills/llm-wiki-skill/workbench/server/src/knowledge-bases.ts +321 -0
  462. package/skills/llm-wiki-skill/workbench/server/src/pages.test.ts +41 -0
  463. package/skills/llm-wiki-skill/workbench/server/src/pages.ts +160 -0
  464. package/skills/llm-wiki-skill/workbench/server/src/retrieval.test.ts +151 -0
  465. package/skills/llm-wiki-skill/workbench/server/src/retrieval.ts +427 -0
  466. package/skills/llm-wiki-skill/workbench/server/src/tool-status-events.test.ts +363 -0
  467. package/skills/llm-wiki-skill/workbench/server/src/tool-status-events.ts +616 -0
  468. package/skills/llm-wiki-skill/workbench/server/src/wiki-init.test.ts +19 -0
  469. package/skills/llm-wiki-skill/workbench/server/src/wiki-init.ts +188 -0
  470. package/skills/llm-wiki-skill/workbench/server/tsconfig.json +10 -0
  471. package/skills/llm-wiki-skill/workbench/tsconfig.json +20 -0
  472. package/skills/llm-wiki-skill/workbench/web/README.md +73 -0
  473. package/skills/llm-wiki-skill/workbench/web/components.json +21 -0
  474. package/skills/llm-wiki-skill/workbench/web/eslint.config.js +22 -0
  475. package/skills/llm-wiki-skill/workbench/web/index.html +16 -0
  476. package/skills/llm-wiki-skill/workbench/web/package.json +54 -0
  477. package/skills/llm-wiki-skill/workbench/web/src/App.tsx +1195 -0
  478. package/skills/llm-wiki-skill/workbench/web/src/components/AddExternalDialog.tsx +375 -0
  479. package/skills/llm-wiki-skill/workbench/web/src/components/AppearancePanel.tsx +158 -0
  480. package/skills/llm-wiki-skill/workbench/web/src/components/ArtifactView.tsx +15 -0
  481. package/skills/llm-wiki-skill/workbench/web/src/components/BatchDigestPanel.tsx +117 -0
  482. package/skills/llm-wiki-skill/workbench/web/src/components/ChatPanel.tsx +890 -0
  483. package/skills/llm-wiki-skill/workbench/web/src/components/CommandMenu.tsx +75 -0
  484. package/skills/llm-wiki-skill/workbench/web/src/components/ExportButtons.tsx +58 -0
  485. package/skills/llm-wiki-skill/workbench/web/src/components/GraphPanel.tsx +800 -0
  486. package/skills/llm-wiki-skill/workbench/web/src/components/GraphReader.tsx +52 -0
  487. package/skills/llm-wiki-skill/workbench/web/src/components/GraphSelection.tsx +100 -0
  488. package/skills/llm-wiki-skill/workbench/web/src/components/GraphSummaryDrawer.tsx +269 -0
  489. package/skills/llm-wiki-skill/workbench/web/src/components/MainViewTabs.tsx +69 -0
  490. package/skills/llm-wiki-skill/workbench/web/src/components/MarkdownView.tsx +106 -0
  491. package/skills/llm-wiki-skill/workbench/web/src/components/NewWikiDialog.tsx +103 -0
  492. package/skills/llm-wiki-skill/workbench/web/src/components/RefMenu.tsx +44 -0
  493. package/skills/llm-wiki-skill/workbench/web/src/components/RightDrawer.tsx +298 -0
  494. package/skills/llm-wiki-skill/workbench/web/src/components/SearchPanel.tsx +165 -0
  495. package/skills/llm-wiki-skill/workbench/web/src/components/SettingsPanel.tsx +320 -0
  496. package/skills/llm-wiki-skill/workbench/web/src/components/Sidebar.tsx +354 -0
  497. package/skills/llm-wiki-skill/workbench/web/src/components/ToolHistorySummary.tsx +111 -0
  498. package/skills/llm-wiki-skill/workbench/web/src/components/ToolStatusRunway.tsx +70 -0
  499. package/skills/llm-wiki-skill/workbench/web/src/components/TopBar.tsx +348 -0
  500. package/skills/llm-wiki-skill/workbench/web/src/components/renderers/DownloadOnlyRenderer.tsx +88 -0
  501. package/skills/llm-wiki-skill/workbench/web/src/components/renderers/HtmlRenderer.tsx +92 -0
  502. package/skills/llm-wiki-skill/workbench/web/src/components/ui/button.tsx +52 -0
  503. package/skills/llm-wiki-skill/workbench/web/src/components/ui/command.tsx +50 -0
  504. package/skills/llm-wiki-skill/workbench/web/src/components/ui/dialog.tsx +156 -0
  505. package/skills/llm-wiki-skill/workbench/web/src/components/ui/input.tsx +21 -0
  506. package/skills/llm-wiki-skill/workbench/web/src/components/ui/tooltip.tsx +57 -0
  507. package/skills/llm-wiki-skill/workbench/web/src/index.css +4204 -0
  508. package/skills/llm-wiki-skill/workbench/web/src/lib/api.ts +648 -0
  509. package/skills/llm-wiki-skill/workbench/web/src/lib/appearance.ts +114 -0
  510. package/skills/llm-wiki-skill/workbench/web/src/lib/drawer-layout.ts +41 -0
  511. package/skills/llm-wiki-skill/workbench/web/src/lib/drawer-state.ts +168 -0
  512. package/skills/llm-wiki-skill/workbench/web/src/lib/graph-reader.ts +25 -0
  513. package/skills/llm-wiki-skill/workbench/web/src/lib/graph-selection-drawer.ts +35 -0
  514. package/skills/llm-wiki-skill/workbench/web/src/lib/graph-selection.ts +96 -0
  515. package/skills/llm-wiki-skill/workbench/web/src/lib/graph-summary-actions.ts +184 -0
  516. package/skills/llm-wiki-skill/workbench/web/src/lib/legacy-tool-status.ts +113 -0
  517. package/skills/llm-wiki-skill/workbench/web/src/lib/model-roles.ts +20 -0
  518. package/skills/llm-wiki-skill/workbench/web/src/lib/search-filter.ts +104 -0
  519. package/skills/llm-wiki-skill/workbench/web/src/lib/sse.ts +72 -0
  520. package/skills/llm-wiki-skill/workbench/web/src/lib/tool-status-format.ts +170 -0
  521. package/skills/llm-wiki-skill/workbench/web/src/lib/tool-status-model.ts +392 -0
  522. package/skills/llm-wiki-skill/workbench/web/src/lib/utils.ts +10 -0
  523. package/skills/llm-wiki-skill/workbench/web/src/lib/view-status.ts +16 -0
  524. package/skills/llm-wiki-skill/workbench/web/src/lib/wiki-links.ts +32 -0
  525. package/skills/llm-wiki-skill/workbench/web/src/main.tsx +10 -0
  526. package/skills/llm-wiki-skill/workbench/web/test/api.test.ts +61 -0
  527. package/skills/llm-wiki-skill/workbench/web/test/app-shell-drawer-layout.test.tsx +48 -0
  528. package/skills/llm-wiki-skill/workbench/web/test/appearance-panel.test.tsx +121 -0
  529. package/skills/llm-wiki-skill/workbench/web/test/appearance.test.ts +262 -0
  530. package/skills/llm-wiki-skill/workbench/web/test/chat-host-source.test.tsx +22 -0
  531. package/skills/llm-wiki-skill/workbench/web/test/chat-panel-auto-scroll.test.tsx +311 -0
  532. package/skills/llm-wiki-skill/workbench/web/test/chat-panel-bubbles.test.tsx +48 -0
  533. package/skills/llm-wiki-skill/workbench/web/test/chat-panel-composer.test.tsx +86 -0
  534. package/skills/llm-wiki-skill/workbench/web/test/chat-panel-tool-status.test.tsx +26 -0
  535. package/skills/llm-wiki-skill/workbench/web/test/export-batch-paper.test.tsx +101 -0
  536. package/skills/llm-wiki-skill/workbench/web/test/graph-drawer-state.test.ts +257 -0
  537. package/skills/llm-wiki-skill/workbench/web/test/graph-panel-paper.test.tsx +200 -0
  538. package/skills/llm-wiki-skill/workbench/web/test/graph-reader-request.test.ts +32 -0
  539. package/skills/llm-wiki-skill/workbench/web/test/graph-reader.test.ts +62 -0
  540. package/skills/llm-wiki-skill/workbench/web/test/graph-selection-drawer.test.ts +56 -0
  541. package/skills/llm-wiki-skill/workbench/web/test/graph-selection.test.ts +83 -0
  542. package/skills/llm-wiki-skill/workbench/web/test/graph-summary-actions.test.ts +188 -0
  543. package/skills/llm-wiki-skill/workbench/web/test/main-view-tabs.test.tsx +34 -0
  544. package/skills/llm-wiki-skill/workbench/web/test/markdown-view.test.tsx +34 -0
  545. package/skills/llm-wiki-skill/workbench/web/test/popup-menus.test.tsx +85 -0
  546. package/skills/llm-wiki-skill/workbench/web/test/render.test.tsx +30 -0
  547. package/skills/llm-wiki-skill/workbench/web/test/render.tsx +38 -0
  548. package/skills/llm-wiki-skill/workbench/web/test/right-drawer-graph-summary.test.tsx +287 -0
  549. package/skills/llm-wiki-skill/workbench/web/test/right-drawer-interactions.test.tsx +182 -0
  550. package/skills/llm-wiki-skill/workbench/web/test/search-filter.test.ts +65 -0
  551. package/skills/llm-wiki-skill/workbench/web/test/search-panel.test.tsx +155 -0
  552. package/skills/llm-wiki-skill/workbench/web/test/setup-dom.ts +66 -0
  553. package/skills/llm-wiki-skill/workbench/web/test/sidebar-v2-source.test.ts +17 -0
  554. package/skills/llm-wiki-skill/workbench/web/test/sidebar.test.tsx +110 -0
  555. package/skills/llm-wiki-skill/workbench/web/test/tool-history-summary.test.tsx +150 -0
  556. package/skills/llm-wiki-skill/workbench/web/test/tool-status-format.test.ts +107 -0
  557. package/skills/llm-wiki-skill/workbench/web/test/tool-status-model.test.ts +324 -0
  558. package/skills/llm-wiki-skill/workbench/web/test/tool-status-runway.test.ts +159 -0
  559. package/skills/llm-wiki-skill/workbench/web/test/topbar.test.tsx +248 -0
  560. package/skills/llm-wiki-skill/workbench/web/test/visual/paper-ui.ts +898 -0
  561. package/skills/llm-wiki-skill/workbench/web/test/wiki-links.test.ts +23 -0
  562. package/skills/llm-wiki-skill/workbench/web/test-results/paper-ui/actual/.gitkeep +1 -0
  563. package/skills/llm-wiki-skill/workbench/web/test-results/paper-ui/baseline/.gitkeep +1 -0
  564. package/skills/llm-wiki-skill/workbench/web/tsconfig.app.json +30 -0
  565. package/skills/llm-wiki-skill/workbench/web/tsconfig.json +7 -0
  566. package/skills/llm-wiki-skill/workbench/web/tsconfig.node.json +24 -0
  567. package/skills/llm-wiki-skill/workbench/web/vite.config.ts +28 -0
@@ -0,0 +1,1425 @@
1
+ import type { GraphEdgeStyleOptions, PinMap, PinPosition, ThemeId } from "../types";
2
+ import { createGraphSpatialIndex, type GraphSpatialIndex, type GraphSpatialIndexInput } from "../layout";
3
+ import { getThemeTokens } from "../themes";
4
+ import type {
5
+ GraphRendererAdapterAggregation,
6
+ GraphRendererAdapterCommunity,
7
+ GraphRendererAdapterData,
8
+ GraphRendererAdapterEdge,
9
+ GraphRendererAdapterNode
10
+ } from "./adapter";
11
+ import {
12
+ bindSigmaGlobalOverlayMouseDrag,
13
+ bindSigmaGlobalOverlayPointerDrag,
14
+ createSigmaGlobalNodeDragSession,
15
+ gestureTargetFromSigmaRenderedObject,
16
+ moveSigmaGlobalNodeDragSession,
17
+ sigmaAdapterDataWithNodePoint,
18
+ sigmaCommunityLabels,
19
+ type SigmaGlobalRenderedObject,
20
+ type SigmaGlobalNodeDragSession
21
+ } from "./sigma-global-drag";
22
+ import { screenPointToWorldPoint, type GraphScreenPoint } from "./geometry";
23
+ import { graphSpatialHitToGestureTarget, type GraphGestureTarget } from "./gestures";
24
+ import { edgeRelationClass } from "./model";
25
+ import { DEFAULT_RENDERER_VIEWPORT, type RendererViewport, type RendererViewportSize } from "./viewport";
26
+ import { overlayPointerScreenPoint, sigmaScreenPointToWorldPoint, sigmaWorldPointToScreenPoint } from "./sigma-coordinates";
27
+ import {
28
+ sigmaCommunityCloud,
29
+ sigmaCommunityCloudBasisById,
30
+ sigmaCommunityCloudBasisByIdWithNodePoint,
31
+ sigmaCommunityCloudBasisByIdWithReuse,
32
+ sigmaProjectedCloudHullPoints,
33
+ type SigmaCommunityCloud
34
+ } from "./community-cloud-geometry";
35
+ import {
36
+ applyOverlayBox,
37
+ applySigmaCloudColor,
38
+ applySigmaCloudGeometry,
39
+ createSigmaCloudSvg,
40
+ createSigmaOverlayRoot,
41
+ nextSigmaCloudFilterSequence,
42
+ sigmaOverlayButton,
43
+ sigmaOverlayPassiveElement,
44
+ sigmaSharedCloudFilterDef,
45
+ type SigmaCloudKind
46
+ } from "./sigma-overlay-svg";
47
+
48
+ export const SIGMA_GLOBAL_RENDERER_ID = "sigma-global" as const;
49
+
50
+ export const SIGMA_GLOBAL_RENDERER_ROUTE_MANAGER_OWNER = "facade" as const;
51
+
52
+ const SIGMA_GLOBAL_COMMUNITY_LABEL_LIMIT = 8;
53
+ const SIGMA_GLOBAL_NODE_HIT_TARGET_LIMIT = 160;
54
+
55
+ export const SIGMA_GLOBAL_RENDERER_BUNDLE_BOUNDARY = {
56
+ sigma: "runtime-loaded-by-sigma-global-renderer",
57
+ graphology: "runtime-loaded-by-sigma-global-renderer",
58
+ workbench: "loads through the graph-engine ESM Sigma runtime boundary when global route manager selects Sigma",
59
+ offlineHtml: "loads through the graph-engine IIFE Sigma runtime boundary when offline global route manager selects Sigma"
60
+ } as const;
61
+
62
+ export interface SigmaGlobalRendererRuntimeBoundary {
63
+ Sigma: typeof import("sigma").default;
64
+ GraphologyGraph: typeof import("graphology").default;
65
+ }
66
+
67
+ export type SigmaGlobalGraphologyGraph = InstanceType<SigmaGlobalRendererRuntimeBoundary["GraphologyGraph"]>;
68
+
69
+ export interface SigmaGlobalCameraState {
70
+ x: number;
71
+ y: number;
72
+ angle: number;
73
+ ratio: number;
74
+ }
75
+
76
+ export interface SigmaGlobalCameraLike {
77
+ getState?: () => SigmaGlobalCameraState;
78
+ setState?: (state: Partial<SigmaGlobalCameraState>) => unknown;
79
+ isAnimated?: () => boolean;
80
+ animate?: (
81
+ state: Partial<SigmaGlobalCameraState>,
82
+ options?: { duration?: number; easing?: string }
83
+ ) => unknown;
84
+ }
85
+
86
+ export interface SigmaGlobalSigmaLike {
87
+ getCamera?: () => SigmaGlobalCameraLike;
88
+ getGraph?: () => unknown;
89
+ setGraph?: (graph: SigmaGlobalGraphologyGraph) => unknown;
90
+ getSetting?: (key: string) => unknown;
91
+ setSetting?: (key: string, value: unknown) => unknown;
92
+ viewportToGraph?: (point: GraphScreenPoint) => { x: number; y: number };
93
+ viewportToFramedGraph?: (point: GraphScreenPoint) => { x: number; y: number };
94
+ graphToViewport?: (point: { x: number; y: number }) => GraphScreenPoint;
95
+ refresh?: () => unknown;
96
+ on?: (event: string, listener: (payload?: unknown) => void) => unknown;
97
+ off?: (event: string, listener: (payload?: unknown) => void) => unknown;
98
+ kill?: () => unknown;
99
+ }
100
+
101
+ export interface SigmaGlobalGraphologyRuntime {
102
+ GraphologyGraph: SigmaGlobalRendererRuntimeBoundary["GraphologyGraph"];
103
+ }
104
+
105
+ export interface SigmaGlobalRendererRuntime extends SigmaGlobalGraphologyRuntime {
106
+ Sigma: new (graph: SigmaGlobalGraphologyGraph, container: HTMLElement, settings?: Record<string, unknown>) => SigmaGlobalSigmaLike;
107
+ }
108
+
109
+ export interface SigmaGlobalGraphologyNodeAttributes {
110
+ x: number;
111
+ y: number;
112
+ label: string;
113
+ size: number;
114
+ color: string;
115
+ type: string;
116
+ graphNodeType: string;
117
+ communityId: string | null;
118
+ sourcePath: string;
119
+ selected: boolean;
120
+ searchHit: boolean;
121
+ pinned: boolean;
122
+ communityDimmed: boolean;
123
+ communitySpotlightVisible: boolean;
124
+ aggregationIds: string[];
125
+ labelVisible: boolean;
126
+ displayMode: string;
127
+ visualRole: string;
128
+ priority: number;
129
+ drawerTarget: GraphRendererAdapterNode["drawerTarget"];
130
+ }
131
+
132
+ export interface SigmaGlobalGraphologyEdgeAttributes {
133
+ size: number;
134
+ color: string;
135
+ relationType: string | null;
136
+ confidence: string | null;
137
+ weight: number;
138
+ sourceCommunityId: string | null;
139
+ targetCommunityId: string | null;
140
+ }
141
+
142
+ export interface SigmaGlobalGraphologyCommunityAttributes {
143
+ id: string;
144
+ label: string;
145
+ color: string;
146
+ nodeIds: string[];
147
+ nodeCount: number;
148
+ selected: boolean;
149
+ searchResultIds: string[];
150
+ pinnedNodeIds: string[];
151
+ aggregationIds: string[];
152
+ drawerTarget: GraphRendererAdapterCommunity["drawerTarget"];
153
+ commands: GraphRendererAdapterCommunity["commands"];
154
+ }
155
+
156
+ export interface SigmaGlobalGraphologyAggregationAttributes {
157
+ id: string;
158
+ label: string;
159
+ communityId: string | null;
160
+ nodeIds: string[];
161
+ selectedNodeIds: string[];
162
+ searchResultIds: string[];
163
+ pinnedNodeIds: string[];
164
+ totalCount: number;
165
+ selected: boolean;
166
+ color: string;
167
+ point: { x: number; y: number } | null;
168
+ radius: number | null;
169
+ drawerTarget: GraphRendererAdapterAggregation["drawerTarget"];
170
+ commands: GraphRendererAdapterAggregation["commands"];
171
+ }
172
+
173
+ export interface SigmaGlobalHitInput {
174
+ nodeId?: string | null;
175
+ screenPoint?: GraphScreenPoint | null;
176
+ renderedObject?: SigmaGlobalRenderedObject | null;
177
+ }
178
+
179
+ interface SigmaGlobalPointerEventPayload {
180
+ node?: unknown;
181
+ event?: { x?: unknown; y?: unknown; preventSigmaDefault?: () => void };
182
+ x?: unknown;
183
+ y?: unknown;
184
+ preventSigmaDefault?: () => void;
185
+ }
186
+
187
+ export interface SigmaGlobalHitProjectorInput {
188
+ adapterData: GraphRendererAdapterData;
189
+ viewport: RendererViewport;
190
+ viewportSize: RendererViewportSize;
191
+ screenPointToWorldPoint?: (point: GraphScreenPoint) => { x: number; y: number };
192
+ }
193
+
194
+ export interface SigmaGlobalHitProjector {
195
+ targetFromSigmaHit(input: SigmaGlobalHitInput): GraphGestureTarget;
196
+ index(): GraphSpatialIndex;
197
+ }
198
+
199
+ export interface SigmaGlobalRendererCreateOptions {
200
+ container: HTMLElement;
201
+ adapterData: GraphRendererAdapterData;
202
+ theme: ThemeId;
203
+ edgeStyle?: GraphEdgeStyleOptions;
204
+ onHitTarget?: (target: GraphGestureTarget) => void;
205
+ onPinsChanged?: (pins: PinMap) => void;
206
+ onDragActiveChange?: (dragging: boolean) => void;
207
+ onFatalError?: (error: unknown) => void;
208
+ pins?: PinMap;
209
+ runtime?: SigmaGlobalRendererRuntime;
210
+ viewport?: RendererViewport;
211
+ viewportSize?: RendererViewportSize;
212
+ }
213
+
214
+ export interface SigmaGlobalRendererUpdateOptions {
215
+ adapterData: GraphRendererAdapterData;
216
+ theme?: ThemeId;
217
+ edgeStyle?: GraphEdgeStyleOptions;
218
+ pins?: PinMap;
219
+ }
220
+
221
+ export interface SigmaGlobalRenderer {
222
+ readonly id: typeof SIGMA_GLOBAL_RENDERER_ID;
223
+ readonly root: HTMLElement;
224
+ readonly overlayRoot: HTMLElement;
225
+ readonly graph: SigmaGlobalGraphologyGraph;
226
+ readonly updateStrategy: "rebuild-graph-preserve-camera";
227
+ readonly lastHitTarget: GraphGestureTarget | null;
228
+ isDragging(): boolean;
229
+ resetView(): void;
230
+ update(options: SigmaGlobalRendererUpdateOptions): void;
231
+ destroy(): void;
232
+ }
233
+
234
+ export interface SigmaGlobalEdgeStyle {
235
+ color: string;
236
+ size: number;
237
+ }
238
+
239
+ export async function sigmaGlobalRendererRuntimeBoundary(): Promise<SigmaGlobalRendererRuntimeBoundary> {
240
+ const [{ default: Sigma }, { default: GraphologyGraph }] = await Promise.all([
241
+ import("sigma"),
242
+ import("graphology")
243
+ ]);
244
+
245
+ return {
246
+ Sigma,
247
+ GraphologyGraph
248
+ };
249
+ }
250
+
251
+ export function buildSigmaGlobalGraphologyGraph(
252
+ adapterData: GraphRendererAdapterData,
253
+ runtime: SigmaGlobalGraphologyRuntime,
254
+ theme: ThemeId = "shan-shui",
255
+ edgeStyle?: GraphEdgeStyleOptions
256
+ ): SigmaGlobalGraphologyGraph {
257
+ const graph = new runtime.GraphologyGraph({ multi: true, type: "mixed" });
258
+ const communityColorById = new Map(adapterData.renderable.communities.map((community) => [community.id, community.color]));
259
+ const aggregationRenderById = new Map(adapterData.renderable.aggregationContainers.map((aggregation) => [aggregation.id, aggregation]));
260
+ const selectedCommunityIds = sigmaSelectedCommunityIds(adapterData);
261
+ const spotlightCommunityIds = sigmaSpotlightCommunityIds(adapterData);
262
+
263
+ for (const node of adapterData.nodes) {
264
+ graph.addNode(node.id, sigmaGlobalNodeAttributes(node, communityColorById, spotlightCommunityIds));
265
+ }
266
+
267
+ for (const edge of adapterData.edges) {
268
+ graph.addEdgeWithKey(edge.id, edge.sourceNodeId, edge.targetNodeId, sigmaGlobalEdgeAttributes(edge, theme, edgeStyle, selectedCommunityIds));
269
+ }
270
+
271
+ graph.setAttribute("counts", adapterData.counts);
272
+ graph.setAttribute("selection", adapterData.selection);
273
+ graph.setAttribute(
274
+ "communities",
275
+ adapterData.communities.map((community) => sigmaGlobalCommunityAttributes(community, communityColorById))
276
+ );
277
+ graph.setAttribute(
278
+ "aggregations",
279
+ adapterData.aggregations.map((aggregation) => sigmaGlobalAggregationAttributes(aggregation, aggregationRenderById))
280
+ );
281
+
282
+ return graph;
283
+ }
284
+
285
+ export function createSigmaGlobalHitProjector(input: SigmaGlobalHitProjectorInput): SigmaGlobalHitProjector {
286
+ const knownNodeIds = new Set(input.adapterData.nodes.map((node) => node.id));
287
+ const spatialIndex = createGraphSpatialIndex(spatialInputFromAdapterData(input.adapterData));
288
+
289
+ return {
290
+ targetFromSigmaHit(hit) {
291
+ if (hit.nodeId && knownNodeIds.has(hit.nodeId)) {
292
+ return { kind: "node", id: hit.nodeId };
293
+ }
294
+
295
+ const renderedObjectTarget = hit.renderedObject ? gestureTargetFromSigmaRenderedObject(hit.renderedObject, input.adapterData) : null;
296
+ if (renderedObjectTarget) return renderedObjectTarget;
297
+
298
+ if (hit.screenPoint) {
299
+ const worldPoint = input.screenPointToWorldPoint
300
+ ? input.screenPointToWorldPoint(hit.screenPoint)
301
+ : screenPointToWorldPoint(
302
+ hit.screenPoint,
303
+ input.viewport,
304
+ input.viewportSize,
305
+ input.adapterData.renderable.worldBounds
306
+ );
307
+ return graphSpatialHitToGestureTarget(spatialIndex.hitTest(worldPoint));
308
+ }
309
+
310
+ return { kind: "graph-blank" };
311
+ },
312
+ index() {
313
+ return spatialIndex;
314
+ }
315
+ };
316
+ }
317
+
318
+ export function createSigmaGlobalRenderer(options: SigmaGlobalRendererCreateOptions): SigmaGlobalRenderer {
319
+ if (!options.container) {
320
+ throw new Error("createSigmaGlobalRenderer requires a container element");
321
+ }
322
+ if (!options.runtime) {
323
+ throw new Error("createSigmaGlobalRenderer requires a loaded Sigma runtime boundary");
324
+ }
325
+
326
+ const runtime = options.runtime;
327
+ let destroyed = false;
328
+ let currentTheme = options.theme;
329
+ let currentEdgeStyle = options.edgeStyle;
330
+ let adapterData = options.adapterData;
331
+ let graph = buildSigmaGlobalGraphologyGraph(adapterData, runtime, currentTheme, currentEdgeStyle);
332
+ const sigmaRoot = createSigmaRoot(options.container, currentTheme);
333
+ const overlayRoot = createSigmaOverlayRoot(sigmaRoot);
334
+ // 云团模糊滤镜内容与帧无关,挂到独立的 filterHost 只建一次,renderSigmaOverlays
335
+ // 每帧 replaceChildren(overlayRoot) 不会动到它。随 sigmaRoot.remove() 一并回收。
336
+ const cloudFilterId = `sigma-community-cloud-blur-${nextSigmaCloudFilterSequence()}`;
337
+ const filterHost = sigmaRoot.ownerDocument.createElement("div");
338
+ filterHost.setAttribute("aria-hidden", "true");
339
+ filterHost.style.position = "absolute";
340
+ filterHost.style.inset = "0";
341
+ filterHost.style.pointerEvents = "none";
342
+ filterHost.append(sigmaSharedCloudFilterDef(sigmaRoot.ownerDocument, cloudFilterId));
343
+ sigmaRoot.append(filterHost);
344
+ let cloudBasisByCommunityId = sigmaCommunityCloudBasisById(adapterData);
345
+ let projector = createSigmaGlobalHitProjector({
346
+ adapterData,
347
+ viewport: options.viewport ?? DEFAULT_RENDERER_VIEWPORT,
348
+ viewportSize: options.viewportSize ?? { width: 1, height: 1 },
349
+ screenPointToWorldPoint: (point) => sigmaScreenPointToWorldPoint(sigma, point, options)
350
+ });
351
+ let sigma: SigmaGlobalSigmaLike;
352
+ let generation = 0;
353
+ let lastHitTarget: GraphGestureTarget | null = null;
354
+ let activeNodeDrag: SigmaGlobalNodeDragSession | null = null;
355
+ let currentPins: PinMap = { ...(options.pins ?? {}) };
356
+ let cameraSpotlightCommunityId: string | null = sigmaSpotlightCommunityId(adapterData);
357
+ let suppressNextNodeClickId: string | null = null;
358
+ let overlayPointerDragCleanup: (() => void) | null = null;
359
+ let eventBindings: Array<{ event: string; listener: (payload?: unknown) => void }> = [];
360
+ let resizeObserver: ResizeObserver | null = null;
361
+ let resizeAnimationFrame: number | null = null;
362
+ let lastObservedRootSize: RendererViewportSize | null = null;
363
+ // 覆盖层元素按 id 复用:rebuild 维护这三张表(增删元素、绑监听一次),
364
+ // reposition 只读它们更新位置,相机移动时不重建 DOM。
365
+ const overlayRegionEntries = new Map<string, { element: HTMLElement; shape: SVGElement; kind: SigmaCloudKind }>();
366
+ const overlayNodeEntries = new Map<string, HTMLButtonElement>();
367
+ const overlayLabelEntries = new Map<string, HTMLElement>();
368
+
369
+ try {
370
+ sigma = new runtime.Sigma(graph, sigmaRoot, sigmaSettingsForTheme(currentTheme));
371
+ bindSigmaEvents();
372
+ bindSigmaResizeObserver();
373
+ rebuildSigmaOverlays();
374
+ } catch (error) {
375
+ options.onFatalError?.(error);
376
+ sigmaRoot.remove();
377
+ throw error;
378
+ }
379
+
380
+ const renderer: SigmaGlobalRenderer = {
381
+ id: SIGMA_GLOBAL_RENDERER_ID,
382
+ root: sigmaRoot,
383
+ overlayRoot,
384
+ get graph() {
385
+ return graph;
386
+ },
387
+ updateStrategy: "rebuild-graph-preserve-camera",
388
+ get lastHitTarget() {
389
+ return lastHitTarget;
390
+ },
391
+ isDragging() {
392
+ return Boolean(activeNodeDrag);
393
+ },
394
+ resetView() {
395
+ assertActive();
396
+ cameraSpotlightCommunityId = null;
397
+ sigma.getCamera?.().setState?.(sigmaGlobalCameraState(sigma, adapterData));
398
+ },
399
+ update(updateOptions) {
400
+ assertActive();
401
+ const cameraState = readCameraState(sigma);
402
+ const previousCameraSpotlightCommunityId = cameraSpotlightCommunityId;
403
+ cancelNodeDrag();
404
+ generation += 1;
405
+ const finalizeUpdate = (): void => {
406
+ try {
407
+ restoreCameraState(sigma, cameraState);
408
+ sigma.refresh?.();
409
+ rebuildSigmaOverlays();
410
+ cameraSpotlightCommunityId = maybeAnimateSigmaCommunitySpotlightCamera(
411
+ sigma,
412
+ sigmaRoot,
413
+ adapterData,
414
+ previousCameraSpotlightCommunityId
415
+ );
416
+ } catch (error) {
417
+ options.onFatalError?.(error);
418
+ }
419
+ };
420
+ const nextAdapterData = updateOptions.adapterData;
421
+ const nextTheme = updateOptions.theme ?? currentTheme;
422
+ const nextEdgeStyle = updateOptions.edgeStyle ?? currentEdgeStyle;
423
+ const nextPins = { ...(updateOptions.pins ?? currentPins) };
424
+ if (canPatchSigmaGlobalGraphAttributes(adapterData, nextAdapterData, currentTheme, nextTheme)) {
425
+ adapterData = nextAdapterData;
426
+ currentEdgeStyle = nextEdgeStyle;
427
+ currentPins = nextPins;
428
+ cloudBasisByCommunityId = sigmaCommunityCloudBasisByIdWithReuse(cloudBasisByCommunityId, adapterData);
429
+ patchSigmaGlobalGraphAttributes(graph, adapterData, currentTheme, currentEdgeStyle);
430
+ projector = createSigmaGlobalHitProjector({
431
+ adapterData,
432
+ viewport: options.viewport ?? DEFAULT_RENDERER_VIEWPORT,
433
+ viewportSize: options.viewportSize ?? { width: 1, height: 1 },
434
+ screenPointToWorldPoint: (point) => sigmaScreenPointToWorldPoint(sigma, point, options)
435
+ });
436
+ finalizeUpdate();
437
+ return;
438
+ }
439
+ adapterData = updateOptions.adapterData;
440
+ cloudBasisByCommunityId = sigmaCommunityCloudBasisByIdWithReuse(cloudBasisByCommunityId, adapterData);
441
+ currentTheme = updateOptions.theme ?? currentTheme;
442
+ currentEdgeStyle = updateOptions.edgeStyle ?? currentEdgeStyle;
443
+ currentPins = { ...(updateOptions.pins ?? currentPins) };
444
+ graph = buildSigmaGlobalGraphologyGraph(adapterData, runtime, currentTheme, currentEdgeStyle);
445
+ projector = createSigmaGlobalHitProjector({
446
+ adapterData,
447
+ viewport: options.viewport ?? DEFAULT_RENDERER_VIEWPORT,
448
+ viewportSize: options.viewportSize ?? { width: 1, height: 1 },
449
+ screenPointToWorldPoint: (point) => sigmaScreenPointToWorldPoint(sigma, point, options)
450
+ });
451
+ try {
452
+ sigma.setGraph?.(graph);
453
+ if (updateOptions.theme) {
454
+ sigmaRoot.dataset.theme = currentTheme;
455
+ sigma.setSetting?.("labelColor", sigmaLabelColor(currentTheme));
456
+ }
457
+ finalizeUpdate();
458
+ } catch (error) {
459
+ options.onFatalError?.(error);
460
+ }
461
+ },
462
+ destroy() {
463
+ if (destroyed) return;
464
+ cancelNodeDrag();
465
+ destroyed = true;
466
+ generation += 1;
467
+ unbindSigmaEvents();
468
+ cancelScheduledResizeRefresh();
469
+ resizeObserver?.disconnect();
470
+ resizeObserver = null;
471
+ try {
472
+ sigma.kill?.();
473
+ } catch (error) {
474
+ options.onFatalError?.(error);
475
+ }
476
+ sigmaRoot.remove();
477
+ overlayRegionEntries.clear();
478
+ overlayNodeEntries.clear();
479
+ overlayLabelEntries.clear();
480
+ }
481
+ };
482
+
483
+ return renderer;
484
+
485
+ function bindSigmaEvents(): void {
486
+ const nodeClick = (payload?: unknown): void => {
487
+ const nodeId = sigmaNodeIdFromPayload(payload);
488
+ if (consumeSuppressedNodeClick(nodeId)) return;
489
+ handleSigmaHit({ nodeId });
490
+ };
491
+ const stageClick = (payload?: unknown): void => handleSigmaHit({ screenPoint: sigmaScreenPointFromPayload(payload) });
492
+ const cameraUpdated = (): void => repositionSigmaOverlays();
493
+ const nodeDown = (payload?: unknown): void => beginNodeDrag(sigmaNodeIdFromPayload(payload), sigmaScreenPointFromPayload(payload), payload);
494
+ const nodeMove = (payload?: unknown): void => moveNodeDrag(sigmaScreenPointFromPayload(payload), payload);
495
+ const nodeUp = (payload?: unknown): void => commitNodeDrag(sigmaScreenPointFromPayload(payload), payload);
496
+ eventBindings = [
497
+ { event: "clickNode", listener: nodeClick },
498
+ { event: "clickStage", listener: stageClick },
499
+ { event: "downNode", listener: nodeDown },
500
+ { event: "moveBody", listener: nodeMove },
501
+ { event: "upNode", listener: nodeUp },
502
+ { event: "upStage", listener: nodeUp },
503
+ { event: "cameraUpdated", listener: cameraUpdated },
504
+ { event: "afterRender", listener: cameraUpdated }
505
+ ];
506
+ for (const binding of eventBindings) {
507
+ sigma.on?.(binding.event, binding.listener);
508
+ }
509
+ }
510
+
511
+ function unbindSigmaEvents(): void {
512
+ for (const binding of eventBindings) {
513
+ sigma.off?.(binding.event, binding.listener);
514
+ }
515
+ eventBindings = [];
516
+ }
517
+
518
+ function bindSigmaResizeObserver(): void {
519
+ const view = sigmaRoot.ownerDocument.defaultView;
520
+ const ViewResizeObserver = view?.ResizeObserver;
521
+ if (!ViewResizeObserver) return;
522
+ lastObservedRootSize = readObservedRootSize();
523
+ resizeObserver = new ViewResizeObserver((entries) => {
524
+ if (destroyed) return;
525
+ const nextSize = readResizeEntrySize(entries) ?? readObservedRootSize();
526
+ if (nextSize && lastObservedRootSize && sameRendererViewportSize(nextSize, lastObservedRootSize)) return;
527
+ if (nextSize) lastObservedRootSize = nextSize;
528
+ scheduleResizeRefresh();
529
+ });
530
+ resizeObserver.observe(sigmaRoot);
531
+ }
532
+
533
+ function scheduleResizeRefresh(): void {
534
+ if (resizeAnimationFrame !== null) return;
535
+ const view = sigmaRoot.ownerDocument.defaultView;
536
+ const run = () => {
537
+ resizeAnimationFrame = null;
538
+ try {
539
+ if (destroyed) return;
540
+ sigma.refresh?.();
541
+ repositionSigmaOverlays();
542
+ } catch (error) {
543
+ options.onFatalError?.(error);
544
+ }
545
+ };
546
+ if (view?.requestAnimationFrame) {
547
+ resizeAnimationFrame = view.requestAnimationFrame(run);
548
+ return;
549
+ }
550
+ run();
551
+ }
552
+
553
+ function cancelScheduledResizeRefresh(): void {
554
+ if (resizeAnimationFrame === null) return;
555
+ sigmaRoot.ownerDocument.defaultView?.cancelAnimationFrame?.(resizeAnimationFrame);
556
+ resizeAnimationFrame = null;
557
+ }
558
+
559
+ function readResizeEntrySize(entries: ResizeObserverEntry[]): RendererViewportSize | null {
560
+ const entry = entries.find((item) => item.target === sigmaRoot) ?? entries[0];
561
+ if (!entry?.contentRect) return null;
562
+ const width = finiteNumber(entry.contentRect.width, 0);
563
+ const height = finiteNumber(entry.contentRect.height, 0);
564
+ if (width <= 0 || height <= 0) return null;
565
+ return { width, height };
566
+ }
567
+
568
+ function readObservedRootSize(): RendererViewportSize | null {
569
+ const rect = typeof sigmaRoot.getBoundingClientRect === "function" ? sigmaRoot.getBoundingClientRect() : null;
570
+ const width = finiteNumber(rect?.width, 0);
571
+ const height = finiteNumber(rect?.height, 0);
572
+ if (width <= 0 || height <= 0) return null;
573
+ return { width, height };
574
+ }
575
+
576
+ function handleSigmaHit(input: SigmaGlobalHitInput): void {
577
+ if (destroyed) return;
578
+ const eventGeneration = generation;
579
+ const target = projector.targetFromSigmaHit(input);
580
+ if (destroyed || eventGeneration !== generation) return;
581
+ lastHitTarget = target;
582
+ options.onHitTarget?.(target);
583
+ }
584
+
585
+ function beginNodeDrag(nodeId: string | null, screenPoint: GraphScreenPoint | null, payload?: unknown): void {
586
+ if (destroyed || !nodeId || !screenPoint || !graph.hasNode(nodeId)) return;
587
+ preventSigmaDefault(payload);
588
+ cancelNodeDrag();
589
+ const startPoint = sigmaNodeWorldPoint(nodeId);
590
+ const pointerWorldPoint = sigmaScreenPointToWorldPoint(sigma, screenPoint, options);
591
+ activeNodeDrag = createSigmaGlobalNodeDragSession({
592
+ nodeId,
593
+ pinKey: sigmaPinKeyForNode(nodeId),
594
+ startPoint,
595
+ pointerStart: screenPoint,
596
+ pointerWorldPoint,
597
+ initiallyPinned: Boolean(graph.getNodeAttribute(nodeId, "pinned")),
598
+ initialPinPosition: sigmaPinPositionForNode(nodeId),
599
+ previousCameraPanning: sigma.getSetting?.("enableCameraPanning")
600
+ });
601
+ sigma.setSetting?.("enableCameraPanning", false);
602
+ sigmaRoot.dataset.draggingNodeId = nodeId;
603
+ options.onDragActiveChange?.(true);
604
+ }
605
+
606
+ function moveNodeDrag(screenPoint: GraphScreenPoint | null, payload?: unknown): void {
607
+ const drag = activeNodeDrag;
608
+ if (!drag || destroyed || !screenPoint) return;
609
+ preventSigmaDefault(payload);
610
+ const pointerWorldPoint = sigmaScreenPointToWorldPoint(sigma, screenPoint, options);
611
+ moveSigmaGlobalNodeDragSession(drag, screenPoint, pointerWorldPoint);
612
+ if (drag.moved) {
613
+ applyNodeDragPoint(drag.nodeId, drag.currentPoint, drag.initiallyPinned, drag.initialPinPosition);
614
+ }
615
+ }
616
+
617
+ function commitNodeDrag(screenPoint: GraphScreenPoint | null, payload?: unknown): void {
618
+ const drag = activeNodeDrag;
619
+ if (!drag || destroyed) return;
620
+ preventSigmaDefault(payload);
621
+ if (screenPoint) moveNodeDrag(screenPoint, payload);
622
+ clearOverlayPointerDragListeners();
623
+ restoreNodeDragCamera(drag);
624
+ activeNodeDrag = null;
625
+ delete sigmaRoot.dataset.draggingNodeId;
626
+ options.onDragActiveChange?.(false);
627
+ if (!drag.moved) {
628
+ return;
629
+ }
630
+ suppressNextNodeClickId = drag.nodeId;
631
+ const finalPin: PinPosition = {
632
+ x: drag.currentPoint.x,
633
+ y: drag.currentPoint.y,
634
+ coordinateSpace: "world"
635
+ };
636
+ currentPins = {
637
+ ...currentPins,
638
+ [drag.pinKey]: finalPin
639
+ };
640
+ applyNodeDragPoint(drag.nodeId, drag.currentPoint, true, finalPin);
641
+ options.onPinsChanged?.(currentPins);
642
+ }
643
+
644
+ function cancelNodeDrag(): void {
645
+ const drag = activeNodeDrag;
646
+ if (!drag) return;
647
+ clearOverlayPointerDragListeners();
648
+ restoreNodeDragCamera(drag);
649
+ activeNodeDrag = null;
650
+ delete sigmaRoot.dataset.draggingNodeId;
651
+ applyNodeDragPoint(drag.nodeId, drag.startPoint, Boolean(currentPins[drag.pinKey]), currentPins[drag.pinKey] ?? null);
652
+ options.onDragActiveChange?.(false);
653
+ }
654
+
655
+ function restoreNodeDragCamera(drag: SigmaGlobalNodeDragSession): void {
656
+ const nextValue = typeof drag.previousCameraPanning === "boolean" ? drag.previousCameraPanning : true;
657
+ sigma.setSetting?.("enableCameraPanning", nextValue);
658
+ }
659
+
660
+ function applyNodeDragPoint(nodeId: string, point: { x: number; y: number }, pinned: boolean, pinPosition: PinPosition | null = null): void {
661
+ const dragging = Boolean(activeNodeDrag);
662
+ if (!graph.hasNode(nodeId)) return;
663
+ graph.mergeNodeAttributes(nodeId, {
664
+ x: finiteNumber(point.x, 0),
665
+ y: finiteNumber(point.y, 0),
666
+ pinned
667
+ });
668
+ adapterData = sigmaAdapterDataWithNodePoint(adapterData, nodeId, point, pinned, pinPosition);
669
+ sigma.refresh?.();
670
+ if (!dragging) {
671
+ cloudBasisByCommunityId = sigmaCommunityCloudBasisByIdWithNodePoint(cloudBasisByCommunityId, adapterData, nodeId);
672
+ // 拖拽提交/取消是终态数据变化(pin 状态、永久坐标),走 rebuild 刷新 dataset 等属性;
673
+ // 拖拽过程中的每帧位置更新由 afterRender → reposition 负责。
674
+ rebuildSigmaOverlays();
675
+ }
676
+ }
677
+
678
+ function sigmaNodeWorldPoint(nodeId: string): { x: number; y: number } {
679
+ return {
680
+ x: finiteNumber(graph.getNodeAttribute(nodeId, "x"), 0),
681
+ y: finiteNumber(graph.getNodeAttribute(nodeId, "y"), 0)
682
+ };
683
+ }
684
+
685
+ function sigmaPinKeyForNode(nodeId: string): string {
686
+ const sourcePath = graph.getNodeAttribute(nodeId, "sourcePath");
687
+ return typeof sourcePath === "string" && sourcePath ? sourcePath : nodeId;
688
+ }
689
+
690
+ function sigmaPinPositionForNode(nodeId: string): PinPosition | null {
691
+ const pinKey = sigmaPinKeyForNode(nodeId);
692
+ return currentPins[pinKey] ?? null;
693
+ }
694
+
695
+ function consumeSuppressedNodeClick(nodeId: string | null): boolean {
696
+ if (!nodeId || suppressNextNodeClickId !== nodeId) return false;
697
+ suppressNextNodeClickId = null;
698
+ return true;
699
+ }
700
+
701
+ // 结构更新:仅在数据/选中变化时调用。按 id 复用元素、绑监听一次、写数据态属性,
702
+ // 最后调用 reposition 完成定位(定位逻辑只存在于 reposition,避免两条路径分叉)。
703
+ function rebuildSigmaOverlays(): void {
704
+ if (destroyed) return;
705
+ const ordered: HTMLElement[] = [];
706
+ const selectedCommunityIds = sigmaSelectedCommunityIds(adapterData);
707
+ const spotlightCommunityIds = sigmaSpotlightCommunityIds(adapterData);
708
+
709
+ const nextRegionIds = new Set<string>();
710
+ for (const community of adapterData.renderable.communities) {
711
+ if (!community.wash) continue;
712
+ nextRegionIds.add(community.id);
713
+ const cloud = sigmaCommunityCloudFor(community.id, community.wash);
714
+ const kind: SigmaCloudKind = cloud.localPoints ? "polygon" : "ellipse";
715
+ let entry = overlayRegionEntries.get(community.id);
716
+ if (!entry || entry.kind !== kind) {
717
+ const element = sigmaOverlayPassiveElement(overlayRoot.ownerDocument, "community-region", community.id);
718
+ element.className = "sigma-global-community-region";
719
+ element.dataset.communityId = community.id;
720
+ element.style.overflow = "visible";
721
+ const handle = createSigmaCloudSvg(overlayRoot.ownerDocument, cloud, cloudFilterId, () => {
722
+ handleSigmaHit({ renderedObject: { kind: "community-wash", id: community.id } });
723
+ });
724
+ element.append(handle.svg);
725
+ entry = { element, shape: handle.shape, kind: handle.kind };
726
+ overlayRegionEntries.set(community.id, entry);
727
+ }
728
+ const selected = selectedCommunityIds.has(community.id);
729
+ const dim = selectedCommunityIds.size > 0 && !selected;
730
+ entry.element.dataset.selected = selected ? "true" : "false";
731
+ applySigmaCloudColor(entry.shape, community.color, dim);
732
+ ordered.push(entry.element);
733
+ }
734
+ pruneOverlayEntries(overlayRegionEntries, nextRegionIds);
735
+
736
+ const nextNodeIds = new Set<string>();
737
+ for (const node of sigmaOverlayNodes(adapterData)) {
738
+ nextNodeIds.add(node.id);
739
+ let element = overlayNodeEntries.get(node.id);
740
+ if (!element) {
741
+ element = createSigmaNodeHitTarget(node.id, node.label || node.id);
742
+ overlayNodeEntries.set(node.id, element);
743
+ }
744
+ element.setAttribute("aria-label", node.label || node.id);
745
+ element.dataset.nodeId = node.id;
746
+ element.dataset.searchHit = node.searchHit ? "true" : "false";
747
+ element.dataset.selected = node.selected ? "true" : "false";
748
+ element.dataset.pinned = node.pinHint.pinned ? "true" : "false";
749
+ element.dataset.communityDimmed = sigmaGlobalNodeSpotlightState(node, spotlightCommunityIds).dimmed ? "true" : "false";
750
+ ordered.push(element);
751
+ }
752
+ pruneOverlayEntries(overlayNodeEntries, nextNodeIds);
753
+
754
+ const nextLabelIds = new Set<string>();
755
+ for (const community of sigmaCommunityLabels(adapterData, SIGMA_GLOBAL_COMMUNITY_LABEL_LIMIT)) {
756
+ if (!community.wash) continue;
757
+ nextLabelIds.add(community.id);
758
+ let element = overlayLabelEntries.get(community.id);
759
+ if (!element) {
760
+ element = sigmaOverlayPassiveElement(overlayRoot.ownerDocument, "community-label", community.id);
761
+ element.className = "sigma-global-community-label";
762
+ element.dataset.communityId = community.id;
763
+ overlayLabelEntries.set(community.id, element);
764
+ }
765
+ const labelSelected = selectedCommunityIds.has(community.id);
766
+ element.dataset.selected = labelSelected ? "true" : "false";
767
+ element.dataset.dim = selectedCommunityIds.size > 0 && !labelSelected ? "true" : "false";
768
+ element.textContent = community.label || community.id;
769
+ ordered.push(element);
770
+ }
771
+ pruneOverlayEntries(overlayLabelEntries, nextLabelIds);
772
+
773
+ overlayRoot.replaceChildren(...ordered);
774
+ repositionSigmaOverlays();
775
+ }
776
+
777
+ // 位置更新:相机/缩放/拖拽每帧调用。只读已存在元素更新位置与云层几何,
778
+ // 不创建元素、不重绑监听、不调用 replaceChildren;缺失的 id 安全跳过。
779
+ function repositionSigmaOverlays(): void {
780
+ if (destroyed) return;
781
+ for (const community of adapterData.renderable.communities) {
782
+ if (!community.wash) continue;
783
+ const entry = overlayRegionEntries.get(community.id);
784
+ if (!entry) continue;
785
+ const cloud = sigmaCommunityCloudFor(community.id, community.wash);
786
+ applyOverlayBox(entry.element, cloud.box);
787
+ applySigmaCloudGeometry(entry.shape, entry.kind, cloud);
788
+ }
789
+ for (const node of sigmaOverlayNodes(adapterData)) {
790
+ const element = overlayNodeEntries.get(node.id);
791
+ if (!element) continue;
792
+ const size = Math.max(16, sigmaGlobalNodeSize(node) * 3);
793
+ const center = sigmaWorldPointToScreenPoint(sigma, node.point, options);
794
+ applyOverlayBox(element, {
795
+ left: center.x - size / 2,
796
+ top: center.y - size / 2,
797
+ width: size,
798
+ height: size
799
+ });
800
+ }
801
+ for (const community of sigmaCommunityLabels(adapterData, SIGMA_GLOBAL_COMMUNITY_LABEL_LIMIT)) {
802
+ if (!community.wash) continue;
803
+ const element = overlayLabelEntries.get(community.id);
804
+ if (!element) continue;
805
+ const center = sigmaWorldPointToScreenPoint(sigma, {
806
+ x: community.wash.cx,
807
+ y: community.wash.cy - community.wash.ry * 0.16
808
+ }, options);
809
+ applyOverlayBox(element, {
810
+ left: center.x,
811
+ top: center.y,
812
+ width: 160,
813
+ height: 22
814
+ });
815
+ }
816
+ }
817
+
818
+ function sigmaCommunityCloudFor(communityId: string, wash: { cx: number; cy: number; rx: number; ry: number }): SigmaCommunityCloud {
819
+ const fallbackBox = overlayBoxFromWorldEllipse(wash.cx, wash.cy, wash.rx, wash.ry);
820
+ return sigmaCommunityCloud(
821
+ sigmaProjectedCloudHullPoints(cloudBasisByCommunityId.get(communityId), sigma, options),
822
+ fallbackBox
823
+ );
824
+ }
825
+
826
+ function createSigmaNodeHitTarget(nodeId: string, label: string): HTMLButtonElement {
827
+ const element = sigmaOverlayButton(overlayRoot.ownerDocument, "node", nodeId, label);
828
+ element.className = "sigma-global-node-hit-target";
829
+ element.addEventListener("click", (event) => {
830
+ event.stopPropagation();
831
+ if (consumeSuppressedNodeClick(nodeId)) return;
832
+ handleSigmaHit({ renderedObject: { kind: "node", id: nodeId } });
833
+ });
834
+ element.addEventListener("pointerdown", (event) => {
835
+ if (event.button !== 0) return;
836
+ event.preventDefault();
837
+ event.stopPropagation();
838
+ beginNodeDrag(nodeId, overlayPointerScreenPoint(event, sigmaRoot), event);
839
+ if (activeNodeDrag?.nodeId === nodeId) {
840
+ bindOverlayPointerDragListeners(element.ownerDocument, element, nodeId, event.pointerId);
841
+ }
842
+ });
843
+ element.addEventListener("mousedown", (event) => {
844
+ if (event.button !== 0) return;
845
+ if (element.ownerDocument.defaultView?.PointerEvent) return;
846
+ event.preventDefault();
847
+ event.stopPropagation();
848
+ if (activeNodeDrag?.nodeId !== nodeId) {
849
+ beginNodeDrag(nodeId, overlayPointerScreenPoint(event, sigmaRoot), event);
850
+ }
851
+ if (activeNodeDrag?.nodeId === nodeId) {
852
+ bindOverlayMouseDragListeners(element.ownerDocument, nodeId);
853
+ }
854
+ });
855
+ element.addEventListener("dragstart", (event) => {
856
+ event.preventDefault();
857
+ });
858
+ return element;
859
+ }
860
+
861
+ function pruneOverlayEntries(entries: Map<string, unknown>, keep: Set<string>): void {
862
+ for (const id of [...entries.keys()]) {
863
+ if (!keep.has(id)) entries.delete(id);
864
+ }
865
+ }
866
+
867
+ function overlayBoxFromWorldEllipse(x: number, y: number, rx: number, ry: number): { left: number; top: number; width: number; height: number } {
868
+ const topLeft = sigmaWorldPointToScreenPoint(sigma, { x: x - rx, y: y - ry }, options);
869
+ const bottomRight = sigmaWorldPointToScreenPoint(sigma, { x: x + rx, y: y + ry }, options);
870
+ const left = Math.min(topLeft.x, bottomRight.x);
871
+ const top = Math.min(topLeft.y, bottomRight.y);
872
+ return {
873
+ left,
874
+ top,
875
+ width: Math.max(8, Math.abs(bottomRight.x - topLeft.x)),
876
+ height: Math.max(8, Math.abs(bottomRight.y - topLeft.y))
877
+ };
878
+ }
879
+
880
+ function bindOverlayPointerDragListeners(ownerDocument: Document, element: HTMLElement, nodeId: string, pointerId: number): void {
881
+ clearOverlayPointerDragListeners();
882
+ const cleanup = bindSigmaGlobalOverlayPointerDrag({
883
+ ownerDocument,
884
+ element,
885
+ nodeId,
886
+ pointerId,
887
+ isActive: isActiveOverlayDrag,
888
+ screenPointFromEvent: (event) => overlayPointerScreenPoint(event, sigmaRoot),
889
+ onMove: moveNodeDrag,
890
+ onEnd: commitNodeDrag,
891
+ onCancel: cancelNodeDrag
892
+ });
893
+ overlayPointerDragCleanup = () => {
894
+ cleanup();
895
+ overlayPointerDragCleanup = null;
896
+ };
897
+ }
898
+
899
+ function bindOverlayMouseDragListeners(ownerDocument: Document, nodeId: string): void {
900
+ clearOverlayPointerDragListeners();
901
+ const cleanup = bindSigmaGlobalOverlayMouseDrag({
902
+ ownerDocument,
903
+ nodeId,
904
+ isActive: isActiveOverlayDrag,
905
+ screenPointFromEvent: (event) => overlayPointerScreenPoint(event, sigmaRoot),
906
+ onMove: moveNodeDrag,
907
+ onEnd: commitNodeDrag
908
+ });
909
+ overlayPointerDragCleanup = () => {
910
+ cleanup();
911
+ overlayPointerDragCleanup = null;
912
+ };
913
+ }
914
+
915
+ function isActiveOverlayDrag(nodeId: string): boolean {
916
+ return activeNodeDrag?.nodeId === nodeId;
917
+ }
918
+
919
+ function clearOverlayPointerDragListeners(): void {
920
+ overlayPointerDragCleanup?.();
921
+ }
922
+
923
+ function assertActive(): void {
924
+ if (destroyed) {
925
+ throw new Error("Sigma global renderer has been destroyed");
926
+ }
927
+ }
928
+
929
+ }
930
+
931
+ function createSigmaRoot(container: HTMLElement, theme: ThemeId): HTMLElement {
932
+ const root = container.ownerDocument.createElement("div");
933
+ root.className = "sigma-global-renderer";
934
+ root.dataset.renderer = SIGMA_GLOBAL_RENDERER_ID;
935
+ root.dataset.theme = theme;
936
+ root.tabIndex = 0;
937
+ container.append(root);
938
+ return root;
939
+ }
940
+
941
+ function sigmaSettingsForTheme(theme: ThemeId): Record<string, unknown> {
942
+ return {
943
+ renderEdgeLabels: false,
944
+ allowInvalidContainer: false,
945
+ labelColor: sigmaLabelColor(theme)
946
+ };
947
+ }
948
+
949
+ function sigmaLabelColor(theme: ThemeId): { color: string } {
950
+ return { color: theme === "mo-ye" ? "#f8fafc" : "#6b6256" };
951
+ }
952
+
953
+ function readCameraState(sigma: SigmaGlobalSigmaLike): SigmaGlobalCameraState | null {
954
+ const state = sigma.getCamera?.().getState?.();
955
+ if (!state) return null;
956
+ return {
957
+ x: finiteNumber(state.x, 0),
958
+ y: finiteNumber(state.y, 0),
959
+ angle: finiteNumber(state.angle, 0),
960
+ ratio: finiteNumber(state.ratio, 1)
961
+ };
962
+ }
963
+
964
+ function restoreCameraState(sigma: SigmaGlobalSigmaLike, state: SigmaGlobalCameraState | null): void {
965
+ if (!state) return;
966
+ sigma.getCamera?.().setState?.(state);
967
+ }
968
+
969
+ function maybeAnimateSigmaCommunitySpotlightCamera(
970
+ sigma: SigmaGlobalSigmaLike,
971
+ root: HTMLElement,
972
+ adapterData: GraphRendererAdapterData,
973
+ previousCommunityId: string | null
974
+ ): string | null {
975
+ const communityId = sigmaSpotlightCommunityId(adapterData);
976
+ if (!communityId) return null;
977
+ if (communityId === previousCommunityId) return communityId;
978
+ const target = sigmaCommunitySpotlightCameraState(sigma, adapterData, communityId);
979
+ if (!target) return communityId;
980
+ moveSigmaCamera(sigma, target, prefersReducedMotion(root.ownerDocument.defaultView));
981
+ return communityId;
982
+ }
983
+
984
+ function moveSigmaCamera(
985
+ sigma: SigmaGlobalSigmaLike,
986
+ target: Partial<SigmaGlobalCameraState>,
987
+ reducedMotion: boolean
988
+ ): void {
989
+ const camera = sigma.getCamera?.();
990
+ if (!camera) return;
991
+ if (reducedMotion || !camera.animate) {
992
+ camera.setState?.(target);
993
+ return;
994
+ }
995
+ void camera.animate(target, { duration: 380, easing: "quadraticInOut" });
996
+ }
997
+
998
+ function sigmaCommunitySpotlightCameraState(
999
+ sigma: SigmaGlobalSigmaLike,
1000
+ adapterData: GraphRendererAdapterData,
1001
+ communityId: string
1002
+ ): Partial<SigmaGlobalCameraState> | null {
1003
+ const current = readCameraState(sigma) ?? { x: 0, y: 0, angle: 0, ratio: 1 };
1004
+ const center = sigmaCommunitySpotlightCenter(adapterData, communityId);
1005
+ if (!center) return null;
1006
+ const bounds = adapterData.renderable.worldBounds;
1007
+ const worldWidth = Math.max(0, finiteNumber(bounds.maxX, center.x) - finiteNumber(bounds.minX, center.x));
1008
+ const drawerOffset = worldWidth * 0.08;
1009
+ const graphTargetPoint = { x: center.x + drawerOffset, y: center.y };
1010
+ const targetPoint = sigmaGraphPointToCameraPoint(sigma, graphTargetPoint);
1011
+ const targetX = roundNumber(targetPoint.x, 3);
1012
+ const targetY = roundNumber(targetPoint.y, 3);
1013
+ const settledThreshold = sigmaCameraDistanceForGraphDistance(sigma, graphTargetPoint, Math.max(worldWidth * 0.015, 4));
1014
+ const positionSettled = Math.abs(current.x - targetX) <= settledThreshold
1015
+ && Math.abs(current.y - targetY) <= settledThreshold;
1016
+ const target = {
1017
+ x: targetX,
1018
+ y: targetY,
1019
+ angle: current.angle,
1020
+ ratio: positionSettled || current.ratio <= 0.9
1021
+ ? current.ratio
1022
+ : roundNumber(clamp(current.ratio * 0.92, 0.72, current.ratio), 3)
1023
+ };
1024
+ const settled = positionSettled
1025
+ && Math.abs(current.ratio - target.ratio) <= 0.025;
1026
+ return settled ? null : target;
1027
+ }
1028
+
1029
+ function sigmaGlobalCameraState(
1030
+ sigma: SigmaGlobalSigmaLike,
1031
+ adapterData: GraphRendererAdapterData
1032
+ ): Partial<SigmaGlobalCameraState> {
1033
+ const bounds = adapterData.renderable.worldBounds;
1034
+ const center = sigmaGraphPointToCameraPoint(sigma, {
1035
+ x: (finiteNumber(bounds.minX, 0) + finiteNumber(bounds.maxX, 0)) / 2,
1036
+ y: (finiteNumber(bounds.minY, 0) + finiteNumber(bounds.maxY, 0)) / 2
1037
+ });
1038
+ return {
1039
+ x: roundNumber(center.x, 3),
1040
+ y: roundNumber(center.y, 3),
1041
+ angle: 0,
1042
+ ratio: 1
1043
+ };
1044
+ }
1045
+
1046
+ function sigmaGraphPointToCameraPoint(
1047
+ sigma: SigmaGlobalSigmaLike,
1048
+ point: { x: number; y: number }
1049
+ ): { x: number; y: number } {
1050
+ const viewportPoint = sigma.graphToViewport?.(point);
1051
+ const cameraPoint = viewportPoint ? sigma.viewportToFramedGraph?.(viewportPoint) : null;
1052
+ if (cameraPoint && Number.isFinite(cameraPoint.x) && Number.isFinite(cameraPoint.y)) {
1053
+ return cameraPoint;
1054
+ }
1055
+ return point;
1056
+ }
1057
+
1058
+ function sigmaCameraDistanceForGraphDistance(
1059
+ sigma: SigmaGlobalSigmaLike,
1060
+ point: { x: number; y: number },
1061
+ graphDistance: number
1062
+ ): number {
1063
+ if (graphDistance <= 0) return 0;
1064
+ const base = sigmaGraphPointToCameraPoint(sigma, point);
1065
+ const shifted = sigmaGraphPointToCameraPoint(sigma, { x: point.x + graphDistance, y: point.y });
1066
+ const distance = Math.abs(shifted.x - base.x);
1067
+ return Number.isFinite(distance) && distance > 0 ? distance : graphDistance;
1068
+ }
1069
+
1070
+ function sigmaCommunitySpotlightCenter(
1071
+ adapterData: GraphRendererAdapterData,
1072
+ communityId: string
1073
+ ): { x: number; y: number } | null {
1074
+ const renderableCommunity = adapterData.renderable.communities.find((community) => community.id === communityId);
1075
+ if (renderableCommunity?.wash) {
1076
+ return {
1077
+ x: finiteNumber(renderableCommunity.wash.cx, 0),
1078
+ y: finiteNumber(renderableCommunity.wash.cy, 0)
1079
+ };
1080
+ }
1081
+ const nodes = adapterData.nodes.filter((node) => node.communityId === communityId);
1082
+ if (nodes.length === 0) return null;
1083
+ const sum = nodes.reduce((acc, node) => ({
1084
+ x: acc.x + finiteNumber(node.point.x, 0),
1085
+ y: acc.y + finiteNumber(node.point.y, 0)
1086
+ }), { x: 0, y: 0 });
1087
+ return { x: sum.x / nodes.length, y: sum.y / nodes.length };
1088
+ }
1089
+
1090
+ function prefersReducedMotion(view: Window | null | undefined): boolean {
1091
+ return Boolean(view?.matchMedia?.("(prefers-reduced-motion: reduce)").matches);
1092
+ }
1093
+
1094
+ function canPatchSigmaGlobalGraphAttributes(
1095
+ current: GraphRendererAdapterData,
1096
+ next: GraphRendererAdapterData,
1097
+ currentTheme: ThemeId,
1098
+ nextTheme: ThemeId
1099
+ ): boolean {
1100
+ if (currentTheme !== nextTheme) return false;
1101
+ if (current.nodes.length !== next.nodes.length || current.edges.length !== next.edges.length) return false;
1102
+ return current.nodes.every((node, index) => node.id === next.nodes[index]?.id)
1103
+ && current.edges.every((edge, index) => {
1104
+ const nextEdge = next.edges[index];
1105
+ return Boolean(nextEdge)
1106
+ && edge.id === nextEdge.id
1107
+ && edge.sourceNodeId === nextEdge.sourceNodeId
1108
+ && edge.targetNodeId === nextEdge.targetNodeId;
1109
+ });
1110
+ }
1111
+
1112
+ function patchSigmaGlobalGraphAttributes(
1113
+ graph: SigmaGlobalGraphologyGraph,
1114
+ adapterData: GraphRendererAdapterData,
1115
+ theme: ThemeId,
1116
+ edgeStyle?: GraphEdgeStyleOptions
1117
+ ): void {
1118
+ const communityColorById = new Map(adapterData.renderable.communities.map((community) => [community.id, community.color]));
1119
+ const aggregationRenderById = new Map(adapterData.renderable.aggregationContainers.map((aggregation) => [aggregation.id, aggregation]));
1120
+ const selectedCommunityIds = sigmaSelectedCommunityIds(adapterData);
1121
+ const spotlightCommunityIds = sigmaSpotlightCommunityIds(adapterData);
1122
+
1123
+ for (const node of adapterData.nodes) {
1124
+ if (!graph.hasNode(node.id)) continue;
1125
+ graph.mergeNodeAttributes(node.id, sigmaGlobalNodeAttributes(node, communityColorById, spotlightCommunityIds));
1126
+ }
1127
+ for (const edge of adapterData.edges) {
1128
+ graph.mergeEdgeAttributes(edge.id, sigmaGlobalEdgeAttributes(edge, theme, edgeStyle, selectedCommunityIds));
1129
+ }
1130
+ graph.setAttribute("counts", adapterData.counts);
1131
+ graph.setAttribute("selection", adapterData.selection);
1132
+ graph.setAttribute(
1133
+ "communities",
1134
+ adapterData.communities.map((community) => sigmaGlobalCommunityAttributes(community, communityColorById))
1135
+ );
1136
+ graph.setAttribute(
1137
+ "aggregations",
1138
+ adapterData.aggregations.map((aggregation) => sigmaGlobalAggregationAttributes(aggregation, aggregationRenderById))
1139
+ );
1140
+ }
1141
+
1142
+ function sigmaNodeIdFromPayload(payload: unknown): string | null {
1143
+ const candidate = payload as { node?: unknown } | null;
1144
+ return typeof candidate?.node === "string" ? candidate.node : null;
1145
+ }
1146
+
1147
+ function sigmaScreenPointFromPayload(payload: unknown): GraphScreenPoint | null {
1148
+ const candidate = payload as { event?: { x?: unknown; y?: unknown }; x?: unknown; y?: unknown } | null;
1149
+ const x = candidate?.event?.x ?? candidate?.x;
1150
+ const y = candidate?.event?.y ?? candidate?.y;
1151
+ return typeof x === "number" && typeof y === "number" ? { x, y } : null;
1152
+ }
1153
+
1154
+ function preventSigmaDefault(payload: unknown): void {
1155
+ const eventPayload = payload as SigmaGlobalPointerEventPayload | null;
1156
+ eventPayload?.preventSigmaDefault?.();
1157
+ eventPayload?.event?.preventSigmaDefault?.();
1158
+ if (payload instanceof Event) payload.preventDefault();
1159
+ }
1160
+
1161
+ function spatialInputFromAdapterData(adapterData: GraphRendererAdapterData): GraphSpatialIndexInput {
1162
+ const renderableEdgeById = new Map(adapterData.renderable.edges.map((edge) => [edge.id, edge]));
1163
+ return {
1164
+ nodes: adapterData.nodes.map((node) => ({
1165
+ id: node.id,
1166
+ label: node.label,
1167
+ type: node.type,
1168
+ point: node.point,
1169
+ displayMode: node.render.displayMode,
1170
+ visualRole: node.render.visualRole
1171
+ })),
1172
+ edges: adapterData.edges.map((edge) => ({
1173
+ id: edge.id,
1174
+ source: edge.sourceNodeId,
1175
+ target: edge.targetNodeId,
1176
+ curveOffset: renderableEdgeById.get(edge.id)?.curveOffset ?? 0
1177
+ })),
1178
+ communities: adapterData.renderable.communities.map((community) => ({
1179
+ id: community.id,
1180
+ wash: community.wash
1181
+ })),
1182
+ aggregationContainers: adapterData.renderable.aggregationContainers.map((aggregation) => ({
1183
+ id: aggregation.id,
1184
+ communityId: aggregation.communityId,
1185
+ point: aggregation.point,
1186
+ radius: aggregation.radius
1187
+ }))
1188
+ };
1189
+ }
1190
+
1191
+ function sigmaGlobalNodeAttributes(
1192
+ node: GraphRendererAdapterNode,
1193
+ communityColorById: Map<string, string>,
1194
+ selectedCommunityIds: ReadonlySet<string> = new Set()
1195
+ ): SigmaGlobalGraphologyNodeAttributes {
1196
+ const spotlight = sigmaGlobalNodeSpotlightState(node, selectedCommunityIds);
1197
+ const baseSize = sigmaGlobalNodeSize(node);
1198
+ const baseColor = sigmaGlobalNodeColor(node, communityColorById);
1199
+ return {
1200
+ x: finiteNumber(node.point.x, 0),
1201
+ y: finiteNumber(node.point.y, 0),
1202
+ label: node.render.labelVisible ? node.label : "",
1203
+ size: spotlight.dimmed ? roundNumber(baseSize * 0.72, 2) : baseSize,
1204
+ color: spotlight.dimmed ? rgbaColor(baseColor, 0.2) : baseColor,
1205
+ type: "circle",
1206
+ graphNodeType: node.type,
1207
+ communityId: node.communityId,
1208
+ sourcePath: node.sourcePath,
1209
+ selected: node.selected,
1210
+ searchHit: node.searchHit,
1211
+ pinned: node.pinHint.pinned,
1212
+ communityDimmed: spotlight.dimmed,
1213
+ communitySpotlightVisible: spotlight.forceVisible,
1214
+ aggregationIds: [...node.aggregationIds],
1215
+ labelVisible: node.render.labelVisible,
1216
+ displayMode: node.render.displayMode,
1217
+ visualRole: node.render.visualRole,
1218
+ priority: finiteNumber(node.render.priority, 0),
1219
+ drawerTarget: node.drawerTarget
1220
+ };
1221
+ }
1222
+
1223
+ function sigmaSelectedCommunityIds(adapterData: GraphRendererAdapterData): Set<string> {
1224
+ return new Set(adapterData.communities.filter((community) => community.selected).map((community) => community.id));
1225
+ }
1226
+
1227
+ function sigmaSpotlightCommunityIds(adapterData: GraphRendererAdapterData): Set<string> {
1228
+ const communityId = sigmaSpotlightCommunityId(adapterData);
1229
+ return communityId ? new Set([communityId]) : new Set();
1230
+ }
1231
+
1232
+ function sigmaSpotlightCommunityId(adapterData: GraphRendererAdapterData): string | null {
1233
+ return adapterData.selection.input?.kind === "community" ? adapterData.selection.input.id : null;
1234
+ }
1235
+
1236
+ function sigmaGlobalNodeSpotlightState(
1237
+ node: GraphRendererAdapterNode,
1238
+ selectedCommunityIds: ReadonlySet<string>
1239
+ ): { dimmed: boolean; forceVisible: boolean } {
1240
+ const forceVisible = node.selected || node.searchHit || node.pinHint.pinned;
1241
+ const inSelectedCommunity = Boolean(node.communityId && selectedCommunityIds.has(node.communityId));
1242
+ return {
1243
+ forceVisible,
1244
+ dimmed: selectedCommunityIds.size > 0 && !inSelectedCommunity && !forceVisible
1245
+ };
1246
+ }
1247
+
1248
+ function sigmaGlobalEdgeAttributes(
1249
+ edge: GraphRendererAdapterEdge,
1250
+ theme: ThemeId = "shan-shui",
1251
+ style?: GraphEdgeStyleOptions,
1252
+ selectedCommunityIds: ReadonlySet<string> = new Set()
1253
+ ): SigmaGlobalGraphologyEdgeAttributes {
1254
+ const edgeStyle = sigmaGlobalEdgeStyle(edge, theme, style, selectedCommunityIds);
1255
+ return {
1256
+ size: edgeStyle.size,
1257
+ color: edgeStyle.color,
1258
+ relationType: edge.relationType == null ? null : String(edge.relationType),
1259
+ confidence: edge.confidence == null ? null : String(edge.confidence),
1260
+ weight: finiteNumber(edge.weight, 0),
1261
+ sourceCommunityId: edge.sourceCommunityId,
1262
+ targetCommunityId: edge.targetCommunityId
1263
+ };
1264
+ }
1265
+
1266
+ export function sigmaGlobalEdgeStyle(
1267
+ edge: GraphRendererAdapterEdge,
1268
+ theme: ThemeId = "shan-shui",
1269
+ style?: GraphEdgeStyleOptions,
1270
+ selectedCommunityIds: ReadonlySet<string> = new Set()
1271
+ ): SigmaGlobalEdgeStyle {
1272
+ const relationClass = edgeRelationClass(edge.relationType);
1273
+ const semantic = relationClass === "relation-contrast" || relationClass === "relation-conflict";
1274
+ const bridge = Boolean(edge.sourceCommunityId && edge.targetCommunityId && edge.sourceCommunityId !== edge.targetCommunityId);
1275
+ const weight = clamp(finiteNumber(edge.weight, 0), 0, 1);
1276
+ let alpha = semantic ? (bridge ? 0.58 : 0.5) + weight * 0.08 : (bridge ? 0.34 : 0.1) + weight * (bridge ? 0.08 : 0.06);
1277
+ let size = semantic ? (bridge ? 1.65 : 1.25) + weight * 0.6 : (bridge ? 1.1 : 0.72) + weight * (bridge ? 0.85 : 0.55);
1278
+
1279
+ if (style?.semanticEmphasis) {
1280
+ if (semantic) {
1281
+ alpha = alpha * 1.16 + 0.04;
1282
+ size += 0.45;
1283
+ } else {
1284
+ alpha *= 0.6;
1285
+ size *= 0.75;
1286
+ }
1287
+ }
1288
+
1289
+ if (style?.focusHighlight && selectedCommunityIds.size > 0) {
1290
+ const touchesSelectedCommunity =
1291
+ Boolean(edge.sourceCommunityId && selectedCommunityIds.has(edge.sourceCommunityId))
1292
+ || Boolean(edge.targetCommunityId && selectedCommunityIds.has(edge.targetCommunityId));
1293
+ if (touchesSelectedCommunity) {
1294
+ alpha = alpha * 1.12 + 0.02;
1295
+ size += semantic ? 0.2 : 0.12;
1296
+ } else {
1297
+ alpha *= 0.05;
1298
+ size *= 0.55;
1299
+ }
1300
+ }
1301
+
1302
+ alpha = roundNumber(clamp(alpha, 0.05, 0.7), 3);
1303
+ size = roundNumber(clamp(size, 0.6, 4), 2);
1304
+
1305
+ return {
1306
+ color: rgbaColor(sigmaGlobalEdgeRelationColor(relationClass, theme), alpha),
1307
+ size
1308
+ };
1309
+ }
1310
+
1311
+ function sigmaGlobalEdgeRelationColor(relationClass: string, theme: ThemeId): string {
1312
+ const vars = getThemeTokens(theme).vars;
1313
+ if (relationClass === "relation-contrast") return vars["--amber"] ?? (theme === "mo-ye" ? "#e0b35e" : "#b7791f");
1314
+ if (relationClass === "relation-conflict") return theme === "mo-ye" ? "#f472b6" : "#d94693";
1315
+ if (theme === "mo-ye") return vars["--line"] ?? "#8e8778";
1316
+ return vars["--night"] ?? "#315f72";
1317
+ }
1318
+
1319
+ function rgbaColor(hexColor: string, alpha: number): string {
1320
+ const hex = hexColor.trim().replace(/^#/, "");
1321
+ const normalized = hex.length === 3
1322
+ ? hex.split("").map((part) => `${part}${part}`).join("")
1323
+ : hex;
1324
+ const red = Number.parseInt(normalized.slice(0, 2), 16);
1325
+ const green = Number.parseInt(normalized.slice(2, 4), 16);
1326
+ const blue = Number.parseInt(normalized.slice(4, 6), 16);
1327
+ if (![red, green, blue].every(Number.isFinite)) return `rgba(49, 95, 114, ${alpha})`;
1328
+ return `rgba(${red}, ${green}, ${blue}, ${alpha})`;
1329
+ }
1330
+
1331
+ function sigmaGlobalCommunityAttributes(
1332
+ community: GraphRendererAdapterCommunity,
1333
+ communityColorById: Map<string, string>
1334
+ ): SigmaGlobalGraphologyCommunityAttributes {
1335
+ return {
1336
+ id: community.id,
1337
+ label: community.label,
1338
+ color: communityColorById.get(community.id) ?? "#64748b",
1339
+ nodeIds: [...community.nodeIds],
1340
+ nodeCount: community.nodeCount,
1341
+ selected: community.selected,
1342
+ searchResultIds: [...community.searchResultIds],
1343
+ pinnedNodeIds: community.pinHints.map((hint) => hint.nodeId),
1344
+ aggregationIds: [...community.aggregationIds],
1345
+ drawerTarget: community.drawerTarget,
1346
+ commands: community.commands
1347
+ };
1348
+ }
1349
+
1350
+ function sigmaGlobalAggregationAttributes(
1351
+ aggregation: GraphRendererAdapterAggregation,
1352
+ aggregationRenderById: Map<string, GraphRendererAdapterData["renderable"]["aggregationContainers"][number]>
1353
+ ): SigmaGlobalGraphologyAggregationAttributes {
1354
+ const render = aggregationRenderById.get(aggregation.id);
1355
+ return {
1356
+ id: aggregation.id,
1357
+ label: aggregation.label,
1358
+ communityId: aggregation.communityId,
1359
+ nodeIds: [...aggregation.nodeIds],
1360
+ selectedNodeIds: [...aggregation.selectedNodeIds],
1361
+ searchResultIds: [...aggregation.searchResultIds],
1362
+ pinnedNodeIds: [...aggregation.pinnedNodeIds],
1363
+ totalCount: aggregation.totalCount,
1364
+ selected: aggregation.selected,
1365
+ color: render?.color ?? "#64748b",
1366
+ point: render ? { ...render.point } : null,
1367
+ radius: render ? finiteNumber(render.radius, 0) : null,
1368
+ drawerTarget: aggregation.drawerTarget,
1369
+ commands: aggregation.commands
1370
+ };
1371
+ }
1372
+
1373
+ function sigmaGlobalNodeSize(node: GraphRendererAdapterNode): number {
1374
+ if (node.pinHint.pinned || node.selected) return 10;
1375
+ if (node.searchHit) return 9;
1376
+ if (node.render.displayMode === "card") return 8;
1377
+ if (node.render.displayMode === "compact-card") return 7;
1378
+ if (node.render.displayMode === "overview") return 6;
1379
+ return 5;
1380
+ }
1381
+
1382
+ function sigmaOverlayNodes(adapterData: GraphRendererAdapterData): GraphRendererAdapterNode[] {
1383
+ const nodes = adapterData.nodes;
1384
+ const seen = new Set<string>();
1385
+ const output: GraphRendererAdapterNode[] = [];
1386
+ const append = (candidates: GraphRendererAdapterNode[], limit: number) => {
1387
+ let count = 0;
1388
+ for (const node of candidates) {
1389
+ if (output.length >= SIGMA_GLOBAL_NODE_HIT_TARGET_LIMIT || count >= limit || seen.has(node.id)) continue;
1390
+ seen.add(node.id);
1391
+ output.push(node);
1392
+ count += 1;
1393
+ }
1394
+ };
1395
+ if (adapterData.selection.input?.kind !== "community") {
1396
+ append(nodes.filter((node) => node.selected), Number.POSITIVE_INFINITY);
1397
+ }
1398
+ append(nodes.filter((node) => node.searchHit), 80);
1399
+ append(nodes.filter((node) => node.pinHint.pinned), 80);
1400
+ return output;
1401
+ }
1402
+
1403
+ function sigmaGlobalNodeColor(node: GraphRendererAdapterNode, communityColorById: Map<string, string>): string {
1404
+ if (node.selected) return "#ef4444";
1405
+ if (node.searchHit) return "#f59e0b";
1406
+ if (node.pinHint.pinned) return "#0ea5e9";
1407
+ return node.communityId ? communityColorById.get(node.communityId) ?? "#64748b" : "#64748b";
1408
+ }
1409
+
1410
+ function finiteNumber(value: unknown, fallback: number): number {
1411
+ return typeof value === "number" && Number.isFinite(value) ? value : fallback;
1412
+ }
1413
+
1414
+ function sameRendererViewportSize(left: RendererViewportSize, right: RendererViewportSize): boolean {
1415
+ return Math.abs(left.width - right.width) < 1 && Math.abs(left.height - right.height) < 1;
1416
+ }
1417
+
1418
+ function clamp(value: number, min: number, max: number): number {
1419
+ return Math.min(max, Math.max(min, value));
1420
+ }
1421
+
1422
+ function roundNumber(value: number, digits: number): number {
1423
+ const factor = 10 ** digits;
1424
+ return Math.round(value * factor) / factor;
1425
+ }