@mindexec/cli 0.2.478 → 0.2.480

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 (146) hide show
  1. package/README.md +323 -323
  2. package/codex-model-catalog.js +202 -202
  3. package/codex-runtime.js +1608 -1608
  4. package/desktop-workspace-state.cjs +120 -120
  5. package/electron/main.cjs +517 -517
  6. package/electron/preload.cjs +17 -17
  7. package/electron/recurring-update-owner-smoke.mjs +55 -55
  8. package/electron/recurring-update-owner.cjs +97 -97
  9. package/electron/source-smoke.mjs +108 -108
  10. package/electron/update-feed-resolver.cjs +79 -79
  11. package/electron/update-feed.json +10 -10
  12. package/electron/update-manager-smoke.mjs +146 -146
  13. package/electron/update-manager.cjs +297 -297
  14. package/electron/windows-package-smoke.mjs +156 -156
  15. package/launch-bridge.cjs +236 -236
  16. package/lzo1x.js +110 -110
  17. package/mode4-atlas-worker.js +440 -440
  18. package/mode4-atlas.js +130 -130
  19. package/package.json +1 -1
  20. package/port-guard.cjs +285 -285
  21. package/remote-fast/osx-arm64/MacScreenCaptureKitH264.swift +339 -339
  22. package/remote-fast/osx-arm64/MacSystemAudioCapture.swift +214 -214
  23. package/remote-fast/osx-arm64/UnixRawCaptureHelper.mjs +80 -80
  24. package/remote-fast/osx-arm64/livedesk-raw-capture-resampler.mjs +73 -73
  25. package/remote-fast/osx-arm64/mindexec-remote-fast.dll +0 -0
  26. package/remote-fast/osx-x64/MacScreenCaptureKitH264.swift +339 -339
  27. package/remote-fast/osx-x64/MacSystemAudioCapture.swift +214 -214
  28. package/remote-fast/osx-x64/UnixRawCaptureHelper.mjs +80 -80
  29. package/remote-fast/osx-x64/livedesk-raw-capture-resampler.mjs +73 -73
  30. package/remote-fast/osx-x64/mindexec-remote-fast.dll +0 -0
  31. package/remote-fast/win-x64/mindexec-remote-fast.dll +0 -0
  32. package/remote-hub.js +3698 -3698
  33. package/scripts/auth-session-smoke.mjs +262 -262
  34. package/scripts/board-render-ownership-smoke.mjs +85 -85
  35. package/scripts/codex-model-catalog-smoke.mjs +150 -150
  36. package/scripts/codex-runtime-home-smoke.mjs +58 -58
  37. package/scripts/codex-sdk-image-live-smoke.mjs +43 -43
  38. package/scripts/codex-sdk-image-runtime-smoke.mjs +122 -122
  39. package/scripts/codex-sdk-runtime-smoke.mjs +89 -89
  40. package/scripts/desktop-update-publisher-smoke.mjs +89 -89
  41. package/scripts/desktop-update-worker-smoke.mjs +72 -72
  42. package/scripts/desktop-workspace-state-smoke.mjs +81 -81
  43. package/scripts/drive-installed-update-smoke.mjs +67 -67
  44. package/scripts/npm-fresh-install-smoke.mjs +216 -216
  45. package/scripts/publish-mindexec-desktop-updates.mjs +224 -224
  46. package/scripts/remote-agent-managed-smoke.mjs +318 -318
  47. package/scripts/remote-agent-package-smoke.mjs +64 -64
  48. package/scripts/remote-agent-ws-smoke.mjs +269 -269
  49. package/scripts/remote-fast-live-rate-smoke.mjs +343 -343
  50. package/scripts/remote-fast-mdm-browser-smoke.mjs +453 -453
  51. package/scripts/remote-fleet-render-smoke.mjs +1350 -1350
  52. package/scripts/remote-frame-ws-smoke.mjs +234 -234
  53. package/scripts/remote-http-smoke.mjs +592 -592
  54. package/scripts/remote-hub-identity-smoke.mjs +146 -146
  55. package/scripts/remote-hub-scale-smoke.mjs +124 -124
  56. package/scripts/remote-hub-smoke.mjs +699 -699
  57. package/scripts/remote-input-ws-smoke.mjs +263 -263
  58. package/scripts/remote-registry-follower-smoke.mjs +815 -815
  59. package/scripts/setup-tree-sitter-grammars.mjs +59 -59
  60. package/server.js +7510 -7510
  61. package/start-bridge.bat +32 -32
  62. package/start-bridge.sh +81 -81
  63. package/tree-sitter-grammars/README.md +18 -0
  64. package/tree-sitter-grammars/tree-sitter-c_sharp.wasm +0 -0
  65. package/tree-sitter-grammars/tree-sitter-go.wasm +0 -0
  66. package/tree-sitter-grammars/tree-sitter-java.wasm +0 -0
  67. package/tree-sitter-grammars/tree-sitter-javascript.wasm +0 -0
  68. package/tree-sitter-grammars/tree-sitter-python.wasm +0 -0
  69. package/tree-sitter-grammars/tree-sitter-rust.wasm +0 -0
  70. package/tree-sitter-grammars/tree-sitter-tsx.wasm +0 -0
  71. package/tree-sitter-grammars/tree-sitter-typescript.wasm +0 -0
  72. package/wwwroot/_content/MindExecution.Plugins.Admin/css/admin-dashboard.css +546 -546
  73. package/wwwroot/_content/MindExecution.Plugins.Directory/background.png +0 -0
  74. package/wwwroot/_content/MindExecution.Plugins.YouTube/css/youtube-search.css +251 -251
  75. package/wwwroot/_content/MindExecution.Shared/css/mind-map-overrides.css +3789 -3789
  76. package/wwwroot/_content/MindExecution.Shared/fonts/NotoSansKR-Bold.ttf +0 -0
  77. package/wwwroot/_content/MindExecution.Shared/fonts/NotoSansKR-Regular.ttf +0 -0
  78. package/wwwroot/_content/MindExecution.Shared/js/agent-visualization.js +27 -27
  79. package/wwwroot/_content/MindExecution.Shared/js/background-themes.js +1449 -1449
  80. package/wwwroot/_content/MindExecution.Shared/js/code-master.js +8316 -8316
  81. package/wwwroot/_content/MindExecution.Shared/js/file-system-helper.js +338 -338
  82. package/wwwroot/_content/MindExecution.Shared/js/marked.min.js +69 -69
  83. package/wwwroot/_content/MindExecution.Shared/js/mind-map-animated-image-preview.js +270 -270
  84. package/wwwroot/_content/MindExecution.Shared/js/mind-map-automation-edge-motion.js +170 -170
  85. package/wwwroot/_content/MindExecution.Shared/js/mind-map-board-render-ownership.js +81 -81
  86. package/wwwroot/_content/MindExecution.Shared/js/mind-map-core.js +10528 -10506
  87. package/wwwroot/_content/MindExecution.Shared/js/mind-map-core.js.backup +1059 -0
  88. package/wwwroot/_content/MindExecution.Shared/js/mind-map-css3d-hotpath.js +902 -902
  89. package/wwwroot/_content/MindExecution.Shared/js/mind-map-css3d-manager.js +24637 -24637
  90. package/wwwroot/_content/MindExecution.Shared/js/mind-map-dev-guards.js +325 -325
  91. package/wwwroot/_content/MindExecution.Shared/js/mind-map-dnd.js +1491 -1491
  92. package/wwwroot/_content/MindExecution.Shared/js/mind-map-dnd.js.bak +434 -0
  93. package/wwwroot/_content/MindExecution.Shared/js/mind-map-glow-shader.js +70 -70
  94. package/wwwroot/_content/MindExecution.Shared/js/mind-map-image-policy.js +218 -218
  95. package/wwwroot/_content/MindExecution.Shared/js/mind-map-interactions.js +7081 -7087
  96. package/wwwroot/_content/MindExecution.Shared/js/mind-map-lod-plan-worker.js +160 -160
  97. package/wwwroot/_content/MindExecution.Shared/js/mind-map-lod-renderer.js +9960 -9958
  98. package/wwwroot/_content/MindExecution.Shared/js/mind-map-lod-video-placeholder.js +107 -107
  99. package/wwwroot/_content/MindExecution.Shared/js/mind-map-logic-workers.js +1004 -1004
  100. package/wwwroot/_content/MindExecution.Shared/js/mind-map-menu-manager.js +1351 -1351
  101. package/wwwroot/_content/MindExecution.Shared/js/mind-map-multi-select.js +865 -865
  102. package/wwwroot/_content/MindExecution.Shared/js/mind-map-node-search-worker.js +554 -554
  103. package/wwwroot/_content/MindExecution.Shared/js/mind-map-nodes.js +4771 -4744
  104. package/wwwroot/_content/MindExecution.Shared/js/mind-map-normal-boundary-optimizer.js +624 -624
  105. package/wwwroot/_content/MindExecution.Shared/js/mind-map-object-manager.js +241 -241
  106. package/wwwroot/_content/MindExecution.Shared/js/mind-map-object-manager.js.backup +372 -0
  107. package/wwwroot/_content/MindExecution.Shared/js/mind-map-pipeline.js +2290 -2290
  108. package/wwwroot/_content/MindExecution.Shared/js/mind-map-remote-codecs.js +202 -202
  109. package/wwwroot/_content/MindExecution.Shared/js/mind-map-render-plan.js +1971 -1971
  110. package/wwwroot/_content/MindExecution.Shared/js/mind-map-text-lod-system.js +93 -93
  111. package/wwwroot/_content/MindExecution.Shared/js/mind-map-texture-factory.js +2391 -2391
  112. package/wwwroot/_content/MindExecution.Shared/js/mind-map-texture-factory.js.backup +1258 -0
  113. package/wwwroot/_content/MindExecution.Shared/js/mind-map-video-playback-controls.js +95 -95
  114. package/wwwroot/_content/MindExecution.Shared/js/mind-map-visibility-worker.js +895 -895
  115. package/wwwroot/_content/MindExecution.Shared/js/mindmap-toolbar.js +636 -636
  116. package/wwwroot/_content/MindExecution.Shared/js/native-drop-handler.js +45 -45
  117. package/wwwroot/_content/MindExecution.Shared/js/plan-master.js +117 -117
  118. package/wwwroot/_content/MindExecution.Shared/js/renderers/CSS3DRenderer.js +114 -114
  119. package/wwwroot/_content/MindExecution.Shared/js/texture-worker-manager.js +10 -10
  120. package/wwwroot/_content/MindExecution.Shared/js/three.min.js +6 -6
  121. package/wwwroot/_content/MindExecution.Shared/js/token-manager.js +7 -7
  122. package/wwwroot/_content/MindExecution.Shared/js/troika-bundle.js +6 -6
  123. package/wwwroot/_content/MindExecution.Shared/js/troika-bundle.js.map +2 -2
  124. package/wwwroot/_content/MindExecution.Shared/lib/font-awesome/css/all.min.css +8 -8
  125. package/wwwroot/_content/MindExecution.Shared/models/vocab.txt +30522 -30522
  126. package/wwwroot/_framework/{Google.Protobuf.33g2gb5is0.dll → Google.Protobuf.9h59ukbel7.dll} +0 -0
  127. package/wwwroot/_framework/{MindExecution.Core.z100xo4mg0.dll → MindExecution.Core.gnj3fo0pr7.dll} +0 -0
  128. package/wwwroot/_framework/{MindExecution.Kernel.i9cldrx8yc.dll → MindExecution.Kernel.1qygzf8o02.dll} +0 -0
  129. package/wwwroot/_framework/{MindExecution.Plugins.Admin.48lzqddb0a.dll → MindExecution.Plugins.Admin.n3uxh144wo.dll} +0 -0
  130. package/wwwroot/_framework/{MindExecution.Plugins.Business.7m8u1q142p.dll → MindExecution.Plugins.Business.vl5dximn25.dll} +0 -0
  131. package/wwwroot/_framework/{MindExecution.Plugins.Concept.cl5wmr53od.dll → MindExecution.Plugins.Concept.rutru9qeoi.dll} +0 -0
  132. package/wwwroot/_framework/{MindExecution.Plugins.Directory.slipi39041.dll → MindExecution.Plugins.Directory.fqbmq85het.dll} +0 -0
  133. package/wwwroot/_framework/{MindExecution.Plugins.PlanMaster.qfge05l671.dll → MindExecution.Plugins.PlanMaster.ko11cc9pll.dll} +0 -0
  134. package/wwwroot/_framework/{MindExecution.Plugins.YouTube.tn7v29ut77.dll → MindExecution.Plugins.YouTube.mt39q0to2j.dll} +0 -0
  135. package/wwwroot/_framework/MindExecution.Shared.umgls362or.dll +0 -0
  136. package/wwwroot/_framework/{MindExecution.Web.rwawrxxk38.dll → MindExecution.Web.1dwoarj2hg.dll} +0 -0
  137. package/wwwroot/_framework/{System.Collections.23yxgetbju.dll → System.Collections.zyvbaq6mpd.dll} +0 -0
  138. package/wwwroot/_framework/blazor.boot.json +25 -25
  139. package/wwwroot/_headers +40 -40
  140. package/wwwroot/_redirects +1 -1
  141. package/wwwroot/index.html +772 -772
  142. package/wwwroot/js/marketing-tool.js +180 -180
  143. package/wwwroot/manifest.webmanifest +23 -23
  144. package/wwwroot/service-worker-assets.js +109 -81
  145. package/wwwroot/service-worker.js +33 -33
  146. package/wwwroot/_framework/MindExecution.Shared.rjqlf0umjn.dll +0 -0
@@ -1,1004 +1,1004 @@
1
- (function () {
2
- 'use strict';
3
-
4
- const LOGIC_WORKER_BRIDGE_BUILD_ID = '20260728-cached-viewport-v008';
5
- const VISIBILITY_WORKER_URL = `_content/MindExecution.Shared/js/mind-map-visibility-worker.js?v=${LOGIC_WORKER_BRIDGE_BUILD_ID}`;
6
- const LOD_PLAN_WORKER_URL = `_content/MindExecution.Shared/js/mind-map-lod-plan-worker.js?v=${LOGIC_WORKER_BRIDGE_BUILD_ID}`;
7
- const NODE_SEARCH_WORKER_URL = `_content/MindExecution.Shared/js/mind-map-node-search-worker.js?v=${LOGIC_WORKER_BRIDGE_BUILD_ID}`;
8
- const CTRL_WHEEL_SCROLL_ACTIVE_WINDOW_MS = 140;
9
- const SEARCH_METADATA_TEXT_LIMIT = 8192;
10
-
11
- function getNodeContentType(model) {
12
- return String(model?.contentType ?? model?.ContentType ?? '').trim().toLowerCase();
13
- }
14
-
15
- function isTextLikeContentType(contentType) {
16
- return contentType === 'text' ||
17
- contentType === 'note' ||
18
- contentType === 'memo' ||
19
- contentType === 'markdown' ||
20
- contentType === 'code';
21
- }
22
-
23
- function getNodeSpatialGridKeys(entry) {
24
- if (entry?._spatialGridKeys instanceof Set) {
25
- return entry._spatialGridKeys;
26
- }
27
- if (entry?.glObject?.userData?.spatialGridKeys instanceof Set) {
28
- return entry.glObject.userData.spatialGridKeys;
29
- }
30
- if (entry?.cssObject?.userData?.spatialGridKeys instanceof Set) {
31
- return entry.cssObject.userData.spatialGridKeys;
32
- }
33
-
34
- return new Set();
35
- }
36
-
37
- function normalizeBoardId(boardId) {
38
- return String(boardId ?? '').trim();
39
- }
40
-
41
- function cloneCellKeys(cellKeys) {
42
- if (Array.isArray(cellKeys)) {
43
- return cellKeys
44
- .map((key) => String(key || '').trim())
45
- .filter(Boolean);
46
- }
47
- if (cellKeys instanceof Set) {
48
- return Array.from(cellKeys)
49
- .map((key) => String(key || '').trim())
50
- .filter(Boolean);
51
- }
52
-
53
- return [];
54
- }
55
-
56
- function limitSearchText(value, maxLength) {
57
- const text = String(value ?? '');
58
- if (!text) {
59
- return '';
60
- }
61
-
62
- return text.length <= maxLength
63
- ? text
64
- : text.slice(0, maxLength);
65
- }
66
-
67
- function buildSearchMetadataText(metadata) {
68
- if (!metadata) {
69
- return '';
70
- }
71
-
72
- if (typeof metadata === 'string') {
73
- return limitSearchText(metadata, SEARCH_METADATA_TEXT_LIMIT);
74
- }
75
-
76
- const values = [];
77
- const entries = Array.isArray(metadata)
78
- ? metadata
79
- : Object.entries(metadata);
80
- for (let i = 0; i < entries.length; i++) {
81
- const entry = entries[i];
82
- if (Array.isArray(entry)) {
83
- const key = limitSearchText(entry[0], 128).trim();
84
- const value = limitSearchText(entry[1], 1024).trim();
85
- if (key) values.push(key);
86
- if (value) values.push(value);
87
- } else if (entry) {
88
- const value = limitSearchText(entry, 1024).trim();
89
- if (value) values.push(value);
90
- }
91
-
92
- if (values.join(' ').length >= SEARCH_METADATA_TEXT_LIMIT) {
93
- break;
94
- }
95
- }
96
-
97
- return limitSearchText(values.join(' '), SEARCH_METADATA_TEXT_LIMIT);
98
- }
99
-
100
- function buildWorkerNodeSnapshot(entry, fallbackNodeId = null, boundsOverride = null, cellKeysOverride = null) {
101
- const model = entry?.model || null;
102
- const nodeId = String(
103
- model?.id ??
104
- entry?.glObject?.userData?.nodeId ??
105
- entry?.cssObject?.userData?.nodeId ??
106
- fallbackNodeId ??
107
- ''
108
- ).trim();
109
- if (!nodeId) {
110
- return null;
111
- }
112
-
113
- const bounds = boundsOverride || window.MindMapNodeBounds?.getNodeWorldBounds?.(entry);
114
- if (!bounds) {
115
- return null;
116
- }
117
-
118
- const contentType = getNodeContentType(model);
119
- const cellKeys = cloneCellKeys(cellKeysOverride || getNodeSpatialGridKeys(entry));
120
-
121
- return {
122
- id: nodeId,
123
- contentType,
124
- textLike: isTextLikeContentType(contentType),
125
- x: Number(bounds.x || 0),
126
- y: Number(bounds.y || 0),
127
- z: Number(bounds.z || 0),
128
- width: Math.max(1, Number(bounds.width || 1)),
129
- height: Math.max(1, Number(bounds.height || 1)),
130
- minX: Number(bounds.minX || 0),
131
- maxX: Number(bounds.maxX || 0),
132
- minY: Number(bounds.minY || 0),
133
- maxY: Number(bounds.maxY || 0),
134
- cellKeys
135
- };
136
- }
137
-
138
- function buildWorkerSearchSnapshot(source, fallbackNodeId = null, boundsOverride = null) {
139
- const model = source?.model || source || null;
140
- const nodeId = String(
141
- model?.id ??
142
- model?.Id ??
143
- source?.glObject?.userData?.nodeId ??
144
- source?.cssObject?.userData?.nodeId ??
145
- fallbackNodeId ??
146
- ''
147
- ).trim();
148
- if (!nodeId) {
149
- return null;
150
- }
151
-
152
- const bounds = boundsOverride || window.MindMapNodeBounds?.getNodeWorldBounds?.(source) || null;
153
- const contentType = String(model?.contentType ?? model?.ContentType ?? source?.contentType ?? source?.ContentType ?? '').trim().toLowerCase();
154
-
155
- return {
156
- id: nodeId,
157
- contentType,
158
- prompt: limitSearchText(model?.prompt ?? model?.Prompt ?? source?.prompt ?? source?.Prompt, 2048),
159
- response: limitSearchText(model?.response ?? model?.Response ?? source?.response ?? source?.Response, 16000),
160
- metadataText: buildSearchMetadataText(model?.metadata ?? model?.Metadata ?? source?.metadataText ?? source?.MetadataText ?? source?.metadata ?? source?.Metadata),
161
- sourcePath: limitSearchText(model?.sourceFilePath ?? model?.SourceFilePath ?? source?.sourcePath ?? source?.SourcePath, 2048),
162
- positionX: Number(model?.positionX ?? model?.PositionX ?? model?.x ?? bounds?.x ?? source?.positionX ?? source?.PositionX ?? 0),
163
- positionY: Number(model?.positionY ?? model?.PositionY ?? model?.y ?? bounds?.y ?? source?.positionY ?? source?.PositionY ?? 0),
164
- width: Math.max(1, Number(model?.width ?? model?.Width ?? bounds?.width ?? source?.width ?? source?.Width ?? 1)),
165
- height: Math.max(1, Number(model?.height ?? model?.Height ?? bounds?.height ?? source?.height ?? source?.Height ?? 1))
166
- };
167
- }
168
-
169
- class MindMapLogicWorkerBridge {
170
- constructor(module) {
171
- this.module = module || null;
172
- this.boardId = normalizeBoardId(module?.activeBoardId || window.mindMap?.activeBoardId || '');
173
-
174
- this._visibilityWorker = null;
175
- this._lodPlanWorker = null;
176
- this._searchWorker = null;
177
- this._visibilityReady = false;
178
- this._lodPlanReady = false;
179
- this._searchReady = false;
180
- this._visibilityDisabled = false;
181
- this._lodPlanDisabled = false;
182
- this._searchDisabled = false;
183
- this._latestVisibilityRequestSeq = 0;
184
- this._latestHitTestRequestSeq = 0;
185
- this._latestSelectionRequestSeq = 0;
186
- this._latestLodPlanRequestSeq = 0;
187
- this._latestSearchRequestSeq = 0;
188
- this._pendingLodPlanKey = '';
189
- this._visibilityQueryPending = false;
190
- this._inFlightVisibilityRequestSeq = 0;
191
- this._deferredVisibilityPayload = null;
192
- this._hitTestQueryPending = false;
193
- this._deferredHitTestPayload = null;
194
- this._pendingSelectionResolvers = new Map();
195
- this._pendingSearchResolvers = new Map();
196
-
197
- this._createWorkers();
198
- }
199
-
200
- _createWorkers() {
201
- this._visibilityWorker = this._createWorker(
202
- 'visibility',
203
- VISIBILITY_WORKER_URL,
204
- (data) => this._handleVisibilityMessage(data)
205
- );
206
- this._lodPlanWorker = this._createWorker(
207
- 'lod-plan',
208
- LOD_PLAN_WORKER_URL,
209
- (data) => this._handleLodPlanMessage(data)
210
- );
211
- this._searchWorker = this._createWorker(
212
- 'node-search',
213
- NODE_SEARCH_WORKER_URL,
214
- (data) => this._handleSearchMessage(data)
215
- );
216
- }
217
-
218
- _createWorker(kind, url, onMessage) {
219
- try {
220
- const worker = new Worker(url);
221
- worker.onmessage = (event) => {
222
- const data = event?.data || null;
223
- if (!data || typeof data !== 'object') {
224
- return;
225
- }
226
-
227
- if (data.type === 'READY') {
228
- if (kind === 'visibility') {
229
- this._visibilityReady = true;
230
- } else if (kind === 'lod-plan') {
231
- this._lodPlanReady = true;
232
- } else if (kind === 'node-search') {
233
- this._searchReady = true;
234
- }
235
- return;
236
- }
237
-
238
- onMessage(data);
239
- };
240
- worker.onerror = (error) => {
241
- console.warn(`[MindMapLogicWorkerBridge] ${kind} worker disabled after error.`, error);
242
- if (kind === 'visibility') {
243
- this._visibilityDisabled = true;
244
- this._visibilityReady = false;
245
- this._visibilityQueryPending = false;
246
- this._inFlightVisibilityRequestSeq = 0;
247
- this._deferredVisibilityPayload = null;
248
- this._clearHitTestCache(this.module);
249
- this._hitTestQueryPending = false;
250
- this._deferredHitTestPayload = null;
251
- this._resolvePendingSelectionQueries(null);
252
- } else if (kind === 'lod-plan') {
253
- this._lodPlanDisabled = true;
254
- this._lodPlanReady = false;
255
- } else {
256
- this._searchDisabled = true;
257
- this._searchReady = false;
258
- this._resolvePendingSearches(null);
259
- }
260
- try {
261
- worker.terminate();
262
- } catch { }
263
- };
264
- return worker;
265
- } catch (error) {
266
- console.warn(`[MindMapLogicWorkerBridge] Failed to create ${kind} worker.`, error);
267
- if (kind === 'visibility') {
268
- this._visibilityDisabled = true;
269
- } else if (kind === 'lod-plan') {
270
- this._lodPlanDisabled = true;
271
- } else {
272
- this._searchDisabled = true;
273
- }
274
- return null;
275
- }
276
- }
277
-
278
- _post(worker, payload) {
279
- if (!worker || !payload) {
280
- return false;
281
- }
282
-
283
- try {
284
- worker.postMessage(payload);
285
- return true;
286
- } catch (error) {
287
- console.warn('[MindMapLogicWorkerBridge] Failed to post worker message.', payload?.type, error);
288
- return false;
289
- }
290
- }
291
-
292
- _stampVisibilityPayloadForPost(payload) {
293
- if (!payload || String(payload.type || '') !== 'VISIBILITY_QUERY') {
294
- return payload;
295
- }
296
-
297
- payload.mainLastAppliedSeq = Math.max(
298
- 0,
299
- Math.floor(Number(this.module?._workerVisibilitySeq || 0))
300
- );
301
- return payload;
302
- }
303
-
304
- _resolveBoardId(module = this.module, fallbackBoardId = null) {
305
- const candidate = normalizeBoardId(
306
- fallbackBoardId ??
307
- module?.activeBoardId ??
308
- window.mindMap?.activeBoardId ??
309
- this.boardId
310
- );
311
- if (candidate) {
312
- this.boardId = candidate;
313
- }
314
- return candidate;
315
- }
316
-
317
- _clearHitTestCache(module = this.module) {
318
- if (!module) {
319
- return;
320
- }
321
-
322
- module._workerHitTestRangeKey = '';
323
- module._workerHitTestBoardId = '';
324
- module._workerHitTestCandidateIds = [];
325
- module._workerHitTestSeq = 0;
326
- module._workerHitTestCellX = 0;
327
- module._workerHitTestCellY = 0;
328
- module._workerHitTestCellRadius = 0;
329
- module._workerHitTestUpdatedAt = 0;
330
- module._workerHitTestProfile = null;
331
- }
332
-
333
- _handleVisibilityMessage(data) {
334
- if (String(data?.type || '') === 'HIT_TEST_RESULT') {
335
- this._handleHitTestMessage(data);
336
- return;
337
- }
338
- if (String(data?.type || '') === 'SELECTION_QUERY_RESULT') {
339
- this._handleSelectionQueryMessage(data);
340
- return;
341
- }
342
-
343
- const module = this.module;
344
- const boardId = this._resolveBoardId(module);
345
- if (!module || !boardId) {
346
- return;
347
- }
348
-
349
- if (normalizeBoardId(data.boardId) !== boardId) {
350
- return;
351
- }
352
-
353
- const resultSeq = Math.max(0, Math.floor(Number(data.seq || 0)));
354
- const inFlightSeq = Math.max(0, Math.floor(Number(this._inFlightVisibilityRequestSeq || 0)));
355
- if (resultSeq <= 0 || resultSeq !== inFlightSeq) {
356
- return;
357
- }
358
-
359
- module._applyWorkerVisibilityResult?.(data);
360
- this._visibilityQueryPending = false;
361
- this._inFlightVisibilityRequestSeq = 0;
362
- this._flushDeferredVisibilityRequest();
363
- }
364
-
365
- _handleHitTestMessage(data) {
366
- const module = this.module;
367
- const boardId = this._resolveBoardId(module);
368
- this._hitTestQueryPending = false;
369
-
370
- if (!module || !boardId) {
371
- this._flushDeferredHitTestRequest();
372
- return;
373
- }
374
-
375
- if (normalizeBoardId(data.boardId) !== boardId) {
376
- this._flushDeferredHitTestRequest();
377
- return;
378
- }
379
-
380
- if (Number(data.seq || 0) < Number(this._latestHitTestRequestSeq || 0)) {
381
- this._flushDeferredHitTestRequest();
382
- return;
383
- }
384
-
385
- module._workerHitTestRangeKey = String(data.rangeKey || '').trim();
386
- module._workerHitTestBoardId = boardId;
387
- module._workerHitTestCandidateIds = Array.isArray(data.candidateIds)
388
- ? data.candidateIds.map((nodeId) => String(nodeId || '').trim()).filter(Boolean)
389
- : [];
390
- module._workerHitTestSeq = Number(data.seq || 0);
391
- module._workerHitTestCellX = Number(data.cellX || 0);
392
- module._workerHitTestCellY = Number(data.cellY || 0);
393
- module._workerHitTestCellRadius = Number(data.cellRadius || 0);
394
- module._workerHitTestUpdatedAt = (typeof performance !== 'undefined' && typeof performance.now === 'function')
395
- ? performance.now()
396
- : Date.now();
397
- module._workerHitTestProfile = data.profile || null;
398
-
399
- this._flushDeferredHitTestRequest();
400
- }
401
-
402
- _handleSelectionQueryMessage(data) {
403
- const boardId = this._resolveBoardId(this.module);
404
- const seq = Number(data.seq || 0);
405
- const resolver = this._pendingSelectionResolvers.get(seq) || null;
406
- if (resolver) {
407
- this._pendingSelectionResolvers.delete(seq);
408
- }
409
-
410
- if (!resolver) {
411
- return;
412
- }
413
-
414
- if (seq < Number(this._latestSelectionRequestSeq || 0)) {
415
- resolver(null);
416
- return;
417
- }
418
-
419
- if (!boardId || normalizeBoardId(data.boardId) !== boardId) {
420
- resolver(null);
421
- return;
422
- }
423
-
424
- const selectedIds = Array.isArray(data.selectedIds)
425
- ? data.selectedIds.map((nodeId) => String(nodeId || '').trim()).filter(Boolean)
426
- : [];
427
- resolver(selectedIds);
428
- }
429
-
430
- _handleLodPlanMessage(data) {
431
- const module = this.module;
432
- const boardId = this._resolveBoardId(module);
433
- if (!module || !module.lodRenderer || !boardId) {
434
- return;
435
- }
436
-
437
- if (normalizeBoardId(data.boardId) !== boardId) {
438
- return;
439
- }
440
-
441
- if (Number(data.seq || 0) < Number(this._latestLodPlanRequestSeq || 0)) {
442
- return;
443
- }
444
-
445
- if (String(data.key || '') === this._pendingLodPlanKey) {
446
- this._pendingLodPlanKey = '';
447
- }
448
-
449
- module.lodRenderer._applyWorkerLodPlanResult?.(data);
450
- }
451
-
452
- _handleSearchMessage(data) {
453
- const boardId = this._resolveBoardId(this.module);
454
- const normalizedBoardId = normalizeBoardId(data.boardId);
455
- const seq = Number(data.seq || 0);
456
- const resolver = this._pendingSearchResolvers.get(seq) || null;
457
- if (resolver) {
458
- this._pendingSearchResolvers.delete(seq);
459
- }
460
-
461
- if (!resolver) {
462
- return;
463
- }
464
-
465
- if (!boardId || normalizedBoardId !== boardId) {
466
- resolver([]);
467
- return;
468
- }
469
-
470
- const hits = Array.isArray(data.hits)
471
- ? data.hits.map((hit) => ({
472
- nodeId: String(hit?.nodeId ?? hit?.id ?? '').trim(),
473
- score: Number(hit?.score || 0)
474
- })).filter((hit) => hit.nodeId)
475
- : [];
476
- resolver(hits);
477
- }
478
-
479
- _resolvePendingSearches(hits) {
480
- const resolvers = Array.from(this._pendingSearchResolvers.values());
481
- this._pendingSearchResolvers.clear();
482
- for (let i = 0; i < resolvers.length; i++) {
483
- try {
484
- resolvers[i](hits);
485
- } catch {
486
- }
487
- }
488
- }
489
-
490
- _resolvePendingSelectionQueries(nodeIds) {
491
- const resolvers = Array.from(this._pendingSelectionResolvers.values());
492
- this._pendingSelectionResolvers.clear();
493
- for (let i = 0; i < resolvers.length; i++) {
494
- try {
495
- resolvers[i](nodeIds);
496
- } catch {
497
- }
498
- }
499
- }
500
-
501
- dispose() {
502
- try {
503
- this._visibilityWorker?.terminate?.();
504
- } catch { }
505
- try {
506
- this._lodPlanWorker?.terminate?.();
507
- } catch { }
508
- try {
509
- this._searchWorker?.terminate?.();
510
- } catch { }
511
-
512
- this._visibilityWorker = null;
513
- this._lodPlanWorker = null;
514
- this._searchWorker = null;
515
- this._visibilityReady = false;
516
- this._lodPlanReady = false;
517
- this._searchReady = false;
518
- this._visibilityQueryPending = false;
519
- this._inFlightVisibilityRequestSeq = 0;
520
- this._deferredVisibilityPayload = null;
521
- this._hitTestQueryPending = false;
522
- this._deferredHitTestPayload = null;
523
- this._resolvePendingSelectionQueries(null);
524
- this._clearHitTestCache(this.module);
525
- this._resolvePendingSearches(null);
526
- }
527
-
528
- resetBoard(boardId, reason = 'reset-board') {
529
- const normalizedBoardId = this._resolveBoardId(this.module, boardId);
530
- this._latestVisibilityRequestSeq = 0;
531
- this._latestHitTestRequestSeq = 0;
532
- this._latestSelectionRequestSeq = 0;
533
- this._latestLodPlanRequestSeq = 0;
534
- this._latestSearchRequestSeq = 0;
535
- this._pendingLodPlanKey = '';
536
- this._visibilityQueryPending = false;
537
- this._inFlightVisibilityRequestSeq = 0;
538
- this._deferredVisibilityPayload = null;
539
- this._hitTestQueryPending = false;
540
- this._deferredHitTestPayload = null;
541
- this._resolvePendingSelectionQueries(null);
542
- this._resolvePendingSearches(null);
543
- this._clearHitTestCache(this.module);
544
-
545
- if (this.module) {
546
- this.module._visibilityWorkerPrimed = false;
547
- }
548
-
549
- const payload = {
550
- type: 'RESET_BOARD',
551
- boardId: normalizedBoardId,
552
- reason,
553
- cellSize: Math.max(1, Number(this.module?.GRID_CELL_SIZE || 500))
554
- };
555
- this._post(this._visibilityWorker, payload);
556
- this._post(this._lodPlanWorker, payload);
557
- this._post(this._searchWorker, payload);
558
- }
559
-
560
- rebuildNodeTables(module = this.module, options = {}) {
561
- const activeModule = module || this.module;
562
- const boardId = this._resolveBoardId(activeModule, options.boardId);
563
- if (!activeModule || !boardId) {
564
- return false;
565
- }
566
-
567
- const nodes = [];
568
- const searchNodes = [];
569
- activeModule.nodeObjectsById?.forEach?.((entry, nodeId) => {
570
- const snapshot = buildWorkerNodeSnapshot(entry, nodeId);
571
- if (snapshot) {
572
- nodes.push(snapshot);
573
- }
574
-
575
- const searchSnapshot = buildWorkerSearchSnapshot(entry, nodeId);
576
- if (searchSnapshot) {
577
- searchNodes.push(searchSnapshot);
578
- }
579
- });
580
-
581
- const payload = {
582
- type: 'REBUILD_BOARD',
583
- boardId,
584
- reason: String(options.reason || 'rebuild-node-tables'),
585
- cellSize: Math.max(1, Number(activeModule.GRID_CELL_SIZE || 500)),
586
- nodes
587
- };
588
-
589
- const postedVisibility = this._post(this._visibilityWorker, payload);
590
- const postedLodPlan = this._post(this._lodPlanWorker, payload);
591
- const postedSearch = this._post(this._searchWorker, {
592
- type: 'REBUILD_BOARD',
593
- boardId,
594
- reason: String(options.reason || 'rebuild-search-index'),
595
- nodes: searchNodes
596
- });
597
- if (postedVisibility || postedLodPlan || postedSearch) {
598
- activeModule._visibilityWorkerPrimed = false;
599
- this._clearHitTestCache(activeModule);
600
- }
601
- return postedVisibility || postedLodPlan || postedSearch;
602
- }
603
-
604
- upsertNodeEntry(entry, module = this.module, options = {}) {
605
- const activeModule = module || this.module;
606
- const boardId = this._resolveBoardId(activeModule, options.boardId);
607
- if (!activeModule || !boardId) {
608
- return false;
609
- }
610
-
611
- const snapshot = buildWorkerNodeSnapshot(
612
- entry,
613
- options.nodeId,
614
- options.bounds || null,
615
- options.cellKeys || null
616
- );
617
- const searchSnapshot = buildWorkerSearchSnapshot(
618
- entry,
619
- options.nodeId,
620
- options.bounds || null
621
- );
622
- if (!snapshot && !searchSnapshot) {
623
- return false;
624
- }
625
-
626
- let postedVisibility = false;
627
- let postedLodPlan = false;
628
- let postedSearch = false;
629
- if (snapshot) {
630
- const payload = {
631
- type: 'UPSERT_NODE',
632
- boardId,
633
- node: snapshot
634
- };
635
- postedVisibility = this._post(this._visibilityWorker, payload);
636
- postedLodPlan = this._post(this._lodPlanWorker, payload);
637
- }
638
- if (searchSnapshot) {
639
- postedSearch = this._post(this._searchWorker, {
640
- type: 'UPSERT_NODE',
641
- boardId,
642
- node: searchSnapshot
643
- });
644
- }
645
- if (postedVisibility || postedLodPlan) {
646
- this._clearHitTestCache(activeModule);
647
- }
648
- return postedVisibility || postedLodPlan || postedSearch;
649
- }
650
-
651
- removeNode(nodeId, module = this.module, options = {}) {
652
- const boardId = this._resolveBoardId(module, options.boardId);
653
- const normalizedNodeId = String(nodeId || '').trim();
654
- if (!boardId || !normalizedNodeId) {
655
- return false;
656
- }
657
-
658
- const payload = {
659
- type: 'REMOVE_NODE',
660
- boardId,
661
- nodeId: normalizedNodeId
662
- };
663
-
664
- const postedVisibility = this._post(this._visibilityWorker, payload);
665
- const postedLodPlan = this._post(this._lodPlanWorker, payload);
666
- const postedSearch = this._post(this._searchWorker, payload);
667
- if (postedVisibility || postedLodPlan) {
668
- this._clearHitTestCache(module || this.module);
669
- }
670
- return postedVisibility || postedLodPlan || postedSearch;
671
- }
672
-
673
- batchSyncSearchNodes(boardId, nodes = null, removedIds = null) {
674
- if (this._searchDisabled || !this._searchWorker) {
675
- return false;
676
- }
677
-
678
- const normalizedBoardId = this._resolveBoardId(this.module, boardId);
679
- if (!normalizedBoardId) {
680
- return false;
681
- }
682
-
683
- const normalizedNodes = Array.isArray(nodes)
684
- ? nodes.map((node) => buildWorkerSearchSnapshot(node)).filter(Boolean)
685
- : [];
686
- const normalizedRemovedIds = Array.isArray(removedIds)
687
- ? removedIds.map((nodeId) => String(nodeId || '').trim()).filter(Boolean)
688
- : [];
689
- if (normalizedNodes.length === 0 && normalizedRemovedIds.length === 0) {
690
- return false;
691
- }
692
-
693
- return this._post(this._searchWorker, {
694
- type: 'BATCH_SYNC',
695
- boardId: normalizedBoardId,
696
- nodes: normalizedNodes,
697
- removedIds: normalizedRemovedIds
698
- });
699
- }
700
-
701
- requestVisibility(module = this.module, camera) {
702
- if (this._visibilityDisabled || !this._visibilityReady) {
703
- return false;
704
- }
705
-
706
- const activeModule = module || this.module;
707
- const boardId = this._resolveBoardId(activeModule);
708
- if (!activeModule || !camera || !boardId) {
709
- return false;
710
- }
711
-
712
- const cachedViewportWidth = Number(activeModule._lastViewportWidth || 0);
713
- const cachedViewportHeight = Number(activeModule._lastViewportHeight || 0);
714
- const viewportWidth = cachedViewportWidth > 0
715
- ? cachedViewportWidth
716
- : Math.max(1, Number(activeModule.container?.clientWidth || 1));
717
- const viewportHeight = cachedViewportHeight > 0
718
- ? cachedViewportHeight
719
- : Math.max(1, Number(activeModule.container?.clientHeight || 1));
720
- const now = (typeof performance !== 'undefined' && typeof performance.now === 'function')
721
- ? performance.now()
722
- : Date.now();
723
- const isCtrlWheelVerticalScrolling =
724
- (now - Number(activeModule._ctrlWheelScrollInputTime || 0)) <= CTRL_WHEEL_SCROLL_ACTIVE_WINDOW_MS;
725
- let seq = 0;
726
- if (this._visibilityQueryPending === true) {
727
- seq = Math.max(0, Math.floor(Number(this._deferredVisibilityPayload?.seq || 0)));
728
- if (seq <= 0) {
729
- seq = ++this._latestVisibilityRequestSeq;
730
- }
731
- } else {
732
- seq = ++this._latestVisibilityRequestSeq;
733
- }
734
-
735
- const payload = {
736
- type: 'VISIBILITY_QUERY',
737
- boardId,
738
- seq,
739
- cellSize: Math.max(1, Number(activeModule.GRID_CELL_SIZE || 500)),
740
- camera: {
741
- x: Number(camera.position?.x || 0),
742
- y: Number(camera.position?.y || 0),
743
- z: Number(camera.position?.z || 0),
744
- near: Number(camera.near || 0),
745
- far: Number(camera.far || Number.MAX_SAFE_INTEGER),
746
- fov: Number(camera.fov || 45),
747
- aspect: Math.max(0.1, Number(camera.aspect || 1)),
748
- viewportW: viewportWidth,
749
- viewportH: viewportHeight
750
- },
751
- state: {
752
- isPanning: activeModule.isPanning === true || activeModule._panSmoothingActive === true,
753
- isZooming: activeModule.isZooming === true,
754
- isWindowResizing: activeModule.isWindowResizing === true,
755
- isResizing: activeModule.isResizing === true,
756
- isFullResMode: activeModule.lodRenderer?.isInLODMode !== true,
757
- isCtrlWheelVerticalScrolling,
758
- lastCtrlWheelDeltaY: Number(activeModule._ctrlWheelScrollLastDeltaY || 0),
759
- lastPanWorldDeltaX: Number(activeModule._lastPanWorldDeltaX || 0),
760
- lastPanWorldDeltaY: Number(activeModule._lastPanWorldDeltaY || 0)
761
- }
762
- };
763
-
764
- if (this._visibilityQueryPending === true) {
765
- this._deferredVisibilityPayload = payload;
766
- return true;
767
- }
768
-
769
- const posted = this._post(this._visibilityWorker, this._stampVisibilityPayloadForPost(payload));
770
- this._visibilityQueryPending = posted;
771
- this._inFlightVisibilityRequestSeq = posted ? seq : 0;
772
- return posted;
773
- }
774
-
775
- _flushDeferredVisibilityRequest() {
776
- if (!this._deferredVisibilityPayload || !this._visibilityWorker || this._visibilityDisabled || !this._visibilityReady) {
777
- return;
778
- }
779
-
780
- const payload = this._deferredVisibilityPayload;
781
- this._deferredVisibilityPayload = null;
782
- const posted = this._post(this._visibilityWorker, this._stampVisibilityPayloadForPost(payload));
783
- this._visibilityQueryPending = posted;
784
- this._inFlightVisibilityRequestSeq = posted
785
- ? Math.max(0, Math.floor(Number(payload.seq || 0)))
786
- : 0;
787
- }
788
-
789
- _describeHitTestQuery(module = this.module, options = {}) {
790
- const activeModule = module || this.module;
791
- const boardId = this._resolveBoardId(activeModule);
792
- const point = options.point || null;
793
- const pointX = Number(point?.x);
794
- const pointY = Number(point?.y);
795
- if (!activeModule || !boardId || !Number.isFinite(pointX) || !Number.isFinite(pointY)) {
796
- return null;
797
- }
798
-
799
- const cellSize = Math.max(1, Number(activeModule.GRID_CELL_SIZE || 500));
800
- const cellRadius = Math.max(0, Math.min(3, Math.round(Number(options.cellRadius || 1))));
801
- const cellX = Math.floor(pointX / cellSize);
802
- const cellY = Math.floor(pointY / cellSize);
803
-
804
- return {
805
- boardId,
806
- cellRadius,
807
- cellSize,
808
- cellX,
809
- cellY,
810
- rangeKey: `${cellX}:${cellY}:${cellRadius}`
811
- };
812
- }
813
-
814
- primeHitTestCandidates(module = this.module, options = {}) {
815
- if (this._visibilityDisabled || !this._visibilityReady) {
816
- return false;
817
- }
818
-
819
- const activeModule = module || this.module;
820
- const query = this._describeHitTestQuery(activeModule, options);
821
- if (!activeModule || !query) {
822
- return false;
823
- }
824
-
825
- if (String(activeModule._workerHitTestBoardId || '') === query.boardId &&
826
- String(activeModule._workerHitTestRangeKey || '') === query.rangeKey) {
827
- return true;
828
- }
829
-
830
- const payload = {
831
- type: 'HIT_TEST_QUERY',
832
- boardId: query.boardId,
833
- seq: ++this._latestHitTestRequestSeq,
834
- cellX: query.cellX,
835
- cellY: query.cellY,
836
- cellRadius: query.cellRadius
837
- };
838
-
839
- if (this._hitTestQueryPending === true) {
840
- this._deferredHitTestPayload = payload;
841
- return true;
842
- }
843
-
844
- const posted = this._post(this._visibilityWorker, payload);
845
- this._hitTestQueryPending = posted;
846
- return posted;
847
- }
848
-
849
- _flushDeferredHitTestRequest() {
850
- if (!this._deferredHitTestPayload || !this._visibilityWorker || this._visibilityDisabled || !this._visibilityReady) {
851
- return;
852
- }
853
-
854
- const payload = this._deferredHitTestPayload;
855
- this._deferredHitTestPayload = null;
856
- const posted = this._post(this._visibilityWorker, payload);
857
- this._hitTestQueryPending = posted;
858
- }
859
-
860
- getCachedHitTestCandidateIds(module = this.module, options = {}) {
861
- const activeModule = module || this.module;
862
- const query = this._describeHitTestQuery(activeModule, options);
863
- if (!activeModule || !query) {
864
- return null;
865
- }
866
-
867
- if (String(activeModule._workerHitTestBoardId || '') !== query.boardId) {
868
- return null;
869
- }
870
-
871
- if (String(activeModule._workerHitTestRangeKey || '') !== query.rangeKey) {
872
- return null;
873
- }
874
-
875
- return Array.isArray(activeModule._workerHitTestCandidateIds)
876
- ? activeModule._workerHitTestCandidateIds.slice()
877
- : [];
878
- }
879
-
880
- requestSelectionQuery(module = this.module, options = {}) {
881
- if (this._visibilityDisabled || !this._visibilityReady) {
882
- return Promise.resolve(null);
883
- }
884
-
885
- const activeModule = module || this.module;
886
- const boardId = this._resolveBoardId(activeModule);
887
- const selectionRect = options.selectionRect || null;
888
- if (!activeModule || !boardId || !selectionRect) {
889
- return Promise.resolve(null);
890
- }
891
-
892
- const payload = {
893
- type: 'SELECTION_QUERY',
894
- boardId,
895
- seq: ++this._latestSelectionRequestSeq,
896
- cellSize: Math.max(1, Number(activeModule.GRID_CELL_SIZE || 500)),
897
- selectionRect: {
898
- left: Number(selectionRect.left || 0),
899
- right: Number(selectionRect.right || 0),
900
- bottom: Number(selectionRect.bottom || 0),
901
- top: Number(selectionRect.top || 0)
902
- }
903
- };
904
-
905
- return new Promise((resolve) => {
906
- this._pendingSelectionResolvers.set(payload.seq, resolve);
907
- const posted = this._post(this._visibilityWorker, payload);
908
- if (!posted) {
909
- this._pendingSelectionResolvers.delete(payload.seq);
910
- resolve(null);
911
- }
912
- });
913
- }
914
-
915
- requestLodPlan(module = this.module, options = {}) {
916
- if (this._lodPlanDisabled || !this._lodPlanReady) {
917
- return false;
918
- }
919
-
920
- const activeModule = module || this.module;
921
- const boardId = this._resolveBoardId(activeModule);
922
- const visibleIds = options.visibleIds instanceof Set
923
- ? Array.from(options.visibleIds)
924
- : Array.isArray(options.visibleIds)
925
- ? options.visibleIds
926
- : [];
927
- const key = String(options.key || '').trim();
928
-
929
- if (!activeModule || !boardId || !key || visibleIds.length === 0 && Number(options.totalNodeCount || 0) === 0) {
930
- return false;
931
- }
932
-
933
- if (this._pendingLodPlanKey === key) {
934
- return true;
935
- }
936
-
937
- this._pendingLodPlanKey = key;
938
- const seq = ++this._latestLodPlanRequestSeq;
939
- return this._post(this._lodPlanWorker, {
940
- type: 'LOD_PLAN_QUERY',
941
- boardId,
942
- seq,
943
- key,
944
- visibilityVersion: Number(options.visibilityVersion || 0),
945
- lodBand: String(options.lodBand || '').trim(),
946
- selectionKey: String(options.selectionKey || '').trim(),
947
- totalNodeCount: Number(options.totalNodeCount || 0),
948
- visibleIds: visibleIds.map((id) => String(id || '').trim()).filter(Boolean)
949
- });
950
- }
951
-
952
- requestNodeSearch(module = this.module, options = {}) {
953
- if (this._searchDisabled || !this._searchReady) {
954
- return Promise.resolve(null);
955
- }
956
-
957
- const activeModule = module || this.module;
958
- const boardId = this._resolveBoardId(activeModule);
959
- const query = String(options.query || '').trim();
960
- if (!activeModule || !boardId || !query) {
961
- return Promise.resolve(null);
962
- }
963
-
964
- const seq = ++this._latestSearchRequestSeq;
965
- const limit = Math.max(1, Number(options.limit || 12));
966
- const contentTypes = Array.isArray(options.contentTypes)
967
- ? options.contentTypes.map((value) => String(value || '').trim().toLowerCase()).filter(Boolean)
968
- : [];
969
- const payload = {
970
- type: 'SEARCH_QUERY',
971
- boardId,
972
- seq,
973
- query,
974
- limit,
975
- contentTypes,
976
- camera: {
977
- x: Number(activeModule.camera?.position?.x || 0),
978
- y: Number(activeModule.camera?.position?.y || 0),
979
- z: Number(activeModule.camera?.position?.z || 0),
980
- aspect: Math.max(0.1, Number(activeModule.camera?.aspect || 1))
981
- }
982
- };
983
-
984
- return new Promise((resolve) => {
985
- this._pendingSearchResolvers.set(seq, resolve);
986
- const posted = this._post(this._searchWorker, payload);
987
- if (!posted) {
988
- this._pendingSearchResolvers.delete(seq);
989
- resolve(null);
990
- }
991
- });
992
- }
993
- }
994
-
995
- window.MindMapLogicWorkers = Object.assign(window.MindMapLogicWorkers || {}, {
996
- BUILD_ID: LOGIC_WORKER_BRIDGE_BUILD_ID,
997
- createBridge(module) {
998
- return new MindMapLogicWorkerBridge(module);
999
- },
1000
- buildWorkerNodeSnapshot,
1001
- buildWorkerSearchSnapshot,
1002
- isTextLikeContentType
1003
- });
1004
- })();
1
+ (function () {
2
+ 'use strict';
3
+
4
+ const LOGIC_WORKER_BRIDGE_BUILD_ID = '20260728-cached-viewport-v008';
5
+ const VISIBILITY_WORKER_URL = `_content/MindExecution.Shared/js/mind-map-visibility-worker.js?v=${LOGIC_WORKER_BRIDGE_BUILD_ID}`;
6
+ const LOD_PLAN_WORKER_URL = `_content/MindExecution.Shared/js/mind-map-lod-plan-worker.js?v=${LOGIC_WORKER_BRIDGE_BUILD_ID}`;
7
+ const NODE_SEARCH_WORKER_URL = `_content/MindExecution.Shared/js/mind-map-node-search-worker.js?v=${LOGIC_WORKER_BRIDGE_BUILD_ID}`;
8
+ const CTRL_WHEEL_SCROLL_ACTIVE_WINDOW_MS = 140;
9
+ const SEARCH_METADATA_TEXT_LIMIT = 8192;
10
+
11
+ function getNodeContentType(model) {
12
+ return String(model?.contentType ?? model?.ContentType ?? '').trim().toLowerCase();
13
+ }
14
+
15
+ function isTextLikeContentType(contentType) {
16
+ return contentType === 'text' ||
17
+ contentType === 'note' ||
18
+ contentType === 'memo' ||
19
+ contentType === 'markdown' ||
20
+ contentType === 'code';
21
+ }
22
+
23
+ function getNodeSpatialGridKeys(entry) {
24
+ if (entry?._spatialGridKeys instanceof Set) {
25
+ return entry._spatialGridKeys;
26
+ }
27
+ if (entry?.glObject?.userData?.spatialGridKeys instanceof Set) {
28
+ return entry.glObject.userData.spatialGridKeys;
29
+ }
30
+ if (entry?.cssObject?.userData?.spatialGridKeys instanceof Set) {
31
+ return entry.cssObject.userData.spatialGridKeys;
32
+ }
33
+
34
+ return new Set();
35
+ }
36
+
37
+ function normalizeBoardId(boardId) {
38
+ return String(boardId ?? '').trim();
39
+ }
40
+
41
+ function cloneCellKeys(cellKeys) {
42
+ if (Array.isArray(cellKeys)) {
43
+ return cellKeys
44
+ .map((key) => String(key || '').trim())
45
+ .filter(Boolean);
46
+ }
47
+ if (cellKeys instanceof Set) {
48
+ return Array.from(cellKeys)
49
+ .map((key) => String(key || '').trim())
50
+ .filter(Boolean);
51
+ }
52
+
53
+ return [];
54
+ }
55
+
56
+ function limitSearchText(value, maxLength) {
57
+ const text = String(value ?? '');
58
+ if (!text) {
59
+ return '';
60
+ }
61
+
62
+ return text.length <= maxLength
63
+ ? text
64
+ : text.slice(0, maxLength);
65
+ }
66
+
67
+ function buildSearchMetadataText(metadata) {
68
+ if (!metadata) {
69
+ return '';
70
+ }
71
+
72
+ if (typeof metadata === 'string') {
73
+ return limitSearchText(metadata, SEARCH_METADATA_TEXT_LIMIT);
74
+ }
75
+
76
+ const values = [];
77
+ const entries = Array.isArray(metadata)
78
+ ? metadata
79
+ : Object.entries(metadata);
80
+ for (let i = 0; i < entries.length; i++) {
81
+ const entry = entries[i];
82
+ if (Array.isArray(entry)) {
83
+ const key = limitSearchText(entry[0], 128).trim();
84
+ const value = limitSearchText(entry[1], 1024).trim();
85
+ if (key) values.push(key);
86
+ if (value) values.push(value);
87
+ } else if (entry) {
88
+ const value = limitSearchText(entry, 1024).trim();
89
+ if (value) values.push(value);
90
+ }
91
+
92
+ if (values.join(' ').length >= SEARCH_METADATA_TEXT_LIMIT) {
93
+ break;
94
+ }
95
+ }
96
+
97
+ return limitSearchText(values.join(' '), SEARCH_METADATA_TEXT_LIMIT);
98
+ }
99
+
100
+ function buildWorkerNodeSnapshot(entry, fallbackNodeId = null, boundsOverride = null, cellKeysOverride = null) {
101
+ const model = entry?.model || null;
102
+ const nodeId = String(
103
+ model?.id ??
104
+ entry?.glObject?.userData?.nodeId ??
105
+ entry?.cssObject?.userData?.nodeId ??
106
+ fallbackNodeId ??
107
+ ''
108
+ ).trim();
109
+ if (!nodeId) {
110
+ return null;
111
+ }
112
+
113
+ const bounds = boundsOverride || window.MindMapNodeBounds?.getNodeWorldBounds?.(entry);
114
+ if (!bounds) {
115
+ return null;
116
+ }
117
+
118
+ const contentType = getNodeContentType(model);
119
+ const cellKeys = cloneCellKeys(cellKeysOverride || getNodeSpatialGridKeys(entry));
120
+
121
+ return {
122
+ id: nodeId,
123
+ contentType,
124
+ textLike: isTextLikeContentType(contentType),
125
+ x: Number(bounds.x || 0),
126
+ y: Number(bounds.y || 0),
127
+ z: Number(bounds.z || 0),
128
+ width: Math.max(1, Number(bounds.width || 1)),
129
+ height: Math.max(1, Number(bounds.height || 1)),
130
+ minX: Number(bounds.minX || 0),
131
+ maxX: Number(bounds.maxX || 0),
132
+ minY: Number(bounds.minY || 0),
133
+ maxY: Number(bounds.maxY || 0),
134
+ cellKeys
135
+ };
136
+ }
137
+
138
+ function buildWorkerSearchSnapshot(source, fallbackNodeId = null, boundsOverride = null) {
139
+ const model = source?.model || source || null;
140
+ const nodeId = String(
141
+ model?.id ??
142
+ model?.Id ??
143
+ source?.glObject?.userData?.nodeId ??
144
+ source?.cssObject?.userData?.nodeId ??
145
+ fallbackNodeId ??
146
+ ''
147
+ ).trim();
148
+ if (!nodeId) {
149
+ return null;
150
+ }
151
+
152
+ const bounds = boundsOverride || window.MindMapNodeBounds?.getNodeWorldBounds?.(source) || null;
153
+ const contentType = String(model?.contentType ?? model?.ContentType ?? source?.contentType ?? source?.ContentType ?? '').trim().toLowerCase();
154
+
155
+ return {
156
+ id: nodeId,
157
+ contentType,
158
+ prompt: limitSearchText(model?.prompt ?? model?.Prompt ?? source?.prompt ?? source?.Prompt, 2048),
159
+ response: limitSearchText(model?.response ?? model?.Response ?? source?.response ?? source?.Response, 16000),
160
+ metadataText: buildSearchMetadataText(model?.metadata ?? model?.Metadata ?? source?.metadataText ?? source?.MetadataText ?? source?.metadata ?? source?.Metadata),
161
+ sourcePath: limitSearchText(model?.sourceFilePath ?? model?.SourceFilePath ?? source?.sourcePath ?? source?.SourcePath, 2048),
162
+ positionX: Number(model?.positionX ?? model?.PositionX ?? model?.x ?? bounds?.x ?? source?.positionX ?? source?.PositionX ?? 0),
163
+ positionY: Number(model?.positionY ?? model?.PositionY ?? model?.y ?? bounds?.y ?? source?.positionY ?? source?.PositionY ?? 0),
164
+ width: Math.max(1, Number(model?.width ?? model?.Width ?? bounds?.width ?? source?.width ?? source?.Width ?? 1)),
165
+ height: Math.max(1, Number(model?.height ?? model?.Height ?? bounds?.height ?? source?.height ?? source?.Height ?? 1))
166
+ };
167
+ }
168
+
169
+ class MindMapLogicWorkerBridge {
170
+ constructor(module) {
171
+ this.module = module || null;
172
+ this.boardId = normalizeBoardId(module?.activeBoardId || window.mindMap?.activeBoardId || '');
173
+
174
+ this._visibilityWorker = null;
175
+ this._lodPlanWorker = null;
176
+ this._searchWorker = null;
177
+ this._visibilityReady = false;
178
+ this._lodPlanReady = false;
179
+ this._searchReady = false;
180
+ this._visibilityDisabled = false;
181
+ this._lodPlanDisabled = false;
182
+ this._searchDisabled = false;
183
+ this._latestVisibilityRequestSeq = 0;
184
+ this._latestHitTestRequestSeq = 0;
185
+ this._latestSelectionRequestSeq = 0;
186
+ this._latestLodPlanRequestSeq = 0;
187
+ this._latestSearchRequestSeq = 0;
188
+ this._pendingLodPlanKey = '';
189
+ this._visibilityQueryPending = false;
190
+ this._inFlightVisibilityRequestSeq = 0;
191
+ this._deferredVisibilityPayload = null;
192
+ this._hitTestQueryPending = false;
193
+ this._deferredHitTestPayload = null;
194
+ this._pendingSelectionResolvers = new Map();
195
+ this._pendingSearchResolvers = new Map();
196
+
197
+ this._createWorkers();
198
+ }
199
+
200
+ _createWorkers() {
201
+ this._visibilityWorker = this._createWorker(
202
+ 'visibility',
203
+ VISIBILITY_WORKER_URL,
204
+ (data) => this._handleVisibilityMessage(data)
205
+ );
206
+ this._lodPlanWorker = this._createWorker(
207
+ 'lod-plan',
208
+ LOD_PLAN_WORKER_URL,
209
+ (data) => this._handleLodPlanMessage(data)
210
+ );
211
+ this._searchWorker = this._createWorker(
212
+ 'node-search',
213
+ NODE_SEARCH_WORKER_URL,
214
+ (data) => this._handleSearchMessage(data)
215
+ );
216
+ }
217
+
218
+ _createWorker(kind, url, onMessage) {
219
+ try {
220
+ const worker = new Worker(url);
221
+ worker.onmessage = (event) => {
222
+ const data = event?.data || null;
223
+ if (!data || typeof data !== 'object') {
224
+ return;
225
+ }
226
+
227
+ if (data.type === 'READY') {
228
+ if (kind === 'visibility') {
229
+ this._visibilityReady = true;
230
+ } else if (kind === 'lod-plan') {
231
+ this._lodPlanReady = true;
232
+ } else if (kind === 'node-search') {
233
+ this._searchReady = true;
234
+ }
235
+ return;
236
+ }
237
+
238
+ onMessage(data);
239
+ };
240
+ worker.onerror = (error) => {
241
+ console.warn(`[MindMapLogicWorkerBridge] ${kind} worker disabled after error.`, error);
242
+ if (kind === 'visibility') {
243
+ this._visibilityDisabled = true;
244
+ this._visibilityReady = false;
245
+ this._visibilityQueryPending = false;
246
+ this._inFlightVisibilityRequestSeq = 0;
247
+ this._deferredVisibilityPayload = null;
248
+ this._clearHitTestCache(this.module);
249
+ this._hitTestQueryPending = false;
250
+ this._deferredHitTestPayload = null;
251
+ this._resolvePendingSelectionQueries(null);
252
+ } else if (kind === 'lod-plan') {
253
+ this._lodPlanDisabled = true;
254
+ this._lodPlanReady = false;
255
+ } else {
256
+ this._searchDisabled = true;
257
+ this._searchReady = false;
258
+ this._resolvePendingSearches(null);
259
+ }
260
+ try {
261
+ worker.terminate();
262
+ } catch { }
263
+ };
264
+ return worker;
265
+ } catch (error) {
266
+ console.warn(`[MindMapLogicWorkerBridge] Failed to create ${kind} worker.`, error);
267
+ if (kind === 'visibility') {
268
+ this._visibilityDisabled = true;
269
+ } else if (kind === 'lod-plan') {
270
+ this._lodPlanDisabled = true;
271
+ } else {
272
+ this._searchDisabled = true;
273
+ }
274
+ return null;
275
+ }
276
+ }
277
+
278
+ _post(worker, payload) {
279
+ if (!worker || !payload) {
280
+ return false;
281
+ }
282
+
283
+ try {
284
+ worker.postMessage(payload);
285
+ return true;
286
+ } catch (error) {
287
+ console.warn('[MindMapLogicWorkerBridge] Failed to post worker message.', payload?.type, error);
288
+ return false;
289
+ }
290
+ }
291
+
292
+ _stampVisibilityPayloadForPost(payload) {
293
+ if (!payload || String(payload.type || '') !== 'VISIBILITY_QUERY') {
294
+ return payload;
295
+ }
296
+
297
+ payload.mainLastAppliedSeq = Math.max(
298
+ 0,
299
+ Math.floor(Number(this.module?._workerVisibilitySeq || 0))
300
+ );
301
+ return payload;
302
+ }
303
+
304
+ _resolveBoardId(module = this.module, fallbackBoardId = null) {
305
+ const candidate = normalizeBoardId(
306
+ fallbackBoardId ??
307
+ module?.activeBoardId ??
308
+ window.mindMap?.activeBoardId ??
309
+ this.boardId
310
+ );
311
+ if (candidate) {
312
+ this.boardId = candidate;
313
+ }
314
+ return candidate;
315
+ }
316
+
317
+ _clearHitTestCache(module = this.module) {
318
+ if (!module) {
319
+ return;
320
+ }
321
+
322
+ module._workerHitTestRangeKey = '';
323
+ module._workerHitTestBoardId = '';
324
+ module._workerHitTestCandidateIds = [];
325
+ module._workerHitTestSeq = 0;
326
+ module._workerHitTestCellX = 0;
327
+ module._workerHitTestCellY = 0;
328
+ module._workerHitTestCellRadius = 0;
329
+ module._workerHitTestUpdatedAt = 0;
330
+ module._workerHitTestProfile = null;
331
+ }
332
+
333
+ _handleVisibilityMessage(data) {
334
+ if (String(data?.type || '') === 'HIT_TEST_RESULT') {
335
+ this._handleHitTestMessage(data);
336
+ return;
337
+ }
338
+ if (String(data?.type || '') === 'SELECTION_QUERY_RESULT') {
339
+ this._handleSelectionQueryMessage(data);
340
+ return;
341
+ }
342
+
343
+ const module = this.module;
344
+ const boardId = this._resolveBoardId(module);
345
+ if (!module || !boardId) {
346
+ return;
347
+ }
348
+
349
+ if (normalizeBoardId(data.boardId) !== boardId) {
350
+ return;
351
+ }
352
+
353
+ const resultSeq = Math.max(0, Math.floor(Number(data.seq || 0)));
354
+ const inFlightSeq = Math.max(0, Math.floor(Number(this._inFlightVisibilityRequestSeq || 0)));
355
+ if (resultSeq <= 0 || resultSeq !== inFlightSeq) {
356
+ return;
357
+ }
358
+
359
+ module._applyWorkerVisibilityResult?.(data);
360
+ this._visibilityQueryPending = false;
361
+ this._inFlightVisibilityRequestSeq = 0;
362
+ this._flushDeferredVisibilityRequest();
363
+ }
364
+
365
+ _handleHitTestMessage(data) {
366
+ const module = this.module;
367
+ const boardId = this._resolveBoardId(module);
368
+ this._hitTestQueryPending = false;
369
+
370
+ if (!module || !boardId) {
371
+ this._flushDeferredHitTestRequest();
372
+ return;
373
+ }
374
+
375
+ if (normalizeBoardId(data.boardId) !== boardId) {
376
+ this._flushDeferredHitTestRequest();
377
+ return;
378
+ }
379
+
380
+ if (Number(data.seq || 0) < Number(this._latestHitTestRequestSeq || 0)) {
381
+ this._flushDeferredHitTestRequest();
382
+ return;
383
+ }
384
+
385
+ module._workerHitTestRangeKey = String(data.rangeKey || '').trim();
386
+ module._workerHitTestBoardId = boardId;
387
+ module._workerHitTestCandidateIds = Array.isArray(data.candidateIds)
388
+ ? data.candidateIds.map((nodeId) => String(nodeId || '').trim()).filter(Boolean)
389
+ : [];
390
+ module._workerHitTestSeq = Number(data.seq || 0);
391
+ module._workerHitTestCellX = Number(data.cellX || 0);
392
+ module._workerHitTestCellY = Number(data.cellY || 0);
393
+ module._workerHitTestCellRadius = Number(data.cellRadius || 0);
394
+ module._workerHitTestUpdatedAt = (typeof performance !== 'undefined' && typeof performance.now === 'function')
395
+ ? performance.now()
396
+ : Date.now();
397
+ module._workerHitTestProfile = data.profile || null;
398
+
399
+ this._flushDeferredHitTestRequest();
400
+ }
401
+
402
+ _handleSelectionQueryMessage(data) {
403
+ const boardId = this._resolveBoardId(this.module);
404
+ const seq = Number(data.seq || 0);
405
+ const resolver = this._pendingSelectionResolvers.get(seq) || null;
406
+ if (resolver) {
407
+ this._pendingSelectionResolvers.delete(seq);
408
+ }
409
+
410
+ if (!resolver) {
411
+ return;
412
+ }
413
+
414
+ if (seq < Number(this._latestSelectionRequestSeq || 0)) {
415
+ resolver(null);
416
+ return;
417
+ }
418
+
419
+ if (!boardId || normalizeBoardId(data.boardId) !== boardId) {
420
+ resolver(null);
421
+ return;
422
+ }
423
+
424
+ const selectedIds = Array.isArray(data.selectedIds)
425
+ ? data.selectedIds.map((nodeId) => String(nodeId || '').trim()).filter(Boolean)
426
+ : [];
427
+ resolver(selectedIds);
428
+ }
429
+
430
+ _handleLodPlanMessage(data) {
431
+ const module = this.module;
432
+ const boardId = this._resolveBoardId(module);
433
+ if (!module || !module.lodRenderer || !boardId) {
434
+ return;
435
+ }
436
+
437
+ if (normalizeBoardId(data.boardId) !== boardId) {
438
+ return;
439
+ }
440
+
441
+ if (Number(data.seq || 0) < Number(this._latestLodPlanRequestSeq || 0)) {
442
+ return;
443
+ }
444
+
445
+ if (String(data.key || '') === this._pendingLodPlanKey) {
446
+ this._pendingLodPlanKey = '';
447
+ }
448
+
449
+ module.lodRenderer._applyWorkerLodPlanResult?.(data);
450
+ }
451
+
452
+ _handleSearchMessage(data) {
453
+ const boardId = this._resolveBoardId(this.module);
454
+ const normalizedBoardId = normalizeBoardId(data.boardId);
455
+ const seq = Number(data.seq || 0);
456
+ const resolver = this._pendingSearchResolvers.get(seq) || null;
457
+ if (resolver) {
458
+ this._pendingSearchResolvers.delete(seq);
459
+ }
460
+
461
+ if (!resolver) {
462
+ return;
463
+ }
464
+
465
+ if (!boardId || normalizedBoardId !== boardId) {
466
+ resolver([]);
467
+ return;
468
+ }
469
+
470
+ const hits = Array.isArray(data.hits)
471
+ ? data.hits.map((hit) => ({
472
+ nodeId: String(hit?.nodeId ?? hit?.id ?? '').trim(),
473
+ score: Number(hit?.score || 0)
474
+ })).filter((hit) => hit.nodeId)
475
+ : [];
476
+ resolver(hits);
477
+ }
478
+
479
+ _resolvePendingSearches(hits) {
480
+ const resolvers = Array.from(this._pendingSearchResolvers.values());
481
+ this._pendingSearchResolvers.clear();
482
+ for (let i = 0; i < resolvers.length; i++) {
483
+ try {
484
+ resolvers[i](hits);
485
+ } catch {
486
+ }
487
+ }
488
+ }
489
+
490
+ _resolvePendingSelectionQueries(nodeIds) {
491
+ const resolvers = Array.from(this._pendingSelectionResolvers.values());
492
+ this._pendingSelectionResolvers.clear();
493
+ for (let i = 0; i < resolvers.length; i++) {
494
+ try {
495
+ resolvers[i](nodeIds);
496
+ } catch {
497
+ }
498
+ }
499
+ }
500
+
501
+ dispose() {
502
+ try {
503
+ this._visibilityWorker?.terminate?.();
504
+ } catch { }
505
+ try {
506
+ this._lodPlanWorker?.terminate?.();
507
+ } catch { }
508
+ try {
509
+ this._searchWorker?.terminate?.();
510
+ } catch { }
511
+
512
+ this._visibilityWorker = null;
513
+ this._lodPlanWorker = null;
514
+ this._searchWorker = null;
515
+ this._visibilityReady = false;
516
+ this._lodPlanReady = false;
517
+ this._searchReady = false;
518
+ this._visibilityQueryPending = false;
519
+ this._inFlightVisibilityRequestSeq = 0;
520
+ this._deferredVisibilityPayload = null;
521
+ this._hitTestQueryPending = false;
522
+ this._deferredHitTestPayload = null;
523
+ this._resolvePendingSelectionQueries(null);
524
+ this._clearHitTestCache(this.module);
525
+ this._resolvePendingSearches(null);
526
+ }
527
+
528
+ resetBoard(boardId, reason = 'reset-board') {
529
+ const normalizedBoardId = this._resolveBoardId(this.module, boardId);
530
+ this._latestVisibilityRequestSeq = 0;
531
+ this._latestHitTestRequestSeq = 0;
532
+ this._latestSelectionRequestSeq = 0;
533
+ this._latestLodPlanRequestSeq = 0;
534
+ this._latestSearchRequestSeq = 0;
535
+ this._pendingLodPlanKey = '';
536
+ this._visibilityQueryPending = false;
537
+ this._inFlightVisibilityRequestSeq = 0;
538
+ this._deferredVisibilityPayload = null;
539
+ this._hitTestQueryPending = false;
540
+ this._deferredHitTestPayload = null;
541
+ this._resolvePendingSelectionQueries(null);
542
+ this._resolvePendingSearches(null);
543
+ this._clearHitTestCache(this.module);
544
+
545
+ if (this.module) {
546
+ this.module._visibilityWorkerPrimed = false;
547
+ }
548
+
549
+ const payload = {
550
+ type: 'RESET_BOARD',
551
+ boardId: normalizedBoardId,
552
+ reason,
553
+ cellSize: Math.max(1, Number(this.module?.GRID_CELL_SIZE || 500))
554
+ };
555
+ this._post(this._visibilityWorker, payload);
556
+ this._post(this._lodPlanWorker, payload);
557
+ this._post(this._searchWorker, payload);
558
+ }
559
+
560
+ rebuildNodeTables(module = this.module, options = {}) {
561
+ const activeModule = module || this.module;
562
+ const boardId = this._resolveBoardId(activeModule, options.boardId);
563
+ if (!activeModule || !boardId) {
564
+ return false;
565
+ }
566
+
567
+ const nodes = [];
568
+ const searchNodes = [];
569
+ activeModule.nodeObjectsById?.forEach?.((entry, nodeId) => {
570
+ const snapshot = buildWorkerNodeSnapshot(entry, nodeId);
571
+ if (snapshot) {
572
+ nodes.push(snapshot);
573
+ }
574
+
575
+ const searchSnapshot = buildWorkerSearchSnapshot(entry, nodeId);
576
+ if (searchSnapshot) {
577
+ searchNodes.push(searchSnapshot);
578
+ }
579
+ });
580
+
581
+ const payload = {
582
+ type: 'REBUILD_BOARD',
583
+ boardId,
584
+ reason: String(options.reason || 'rebuild-node-tables'),
585
+ cellSize: Math.max(1, Number(activeModule.GRID_CELL_SIZE || 500)),
586
+ nodes
587
+ };
588
+
589
+ const postedVisibility = this._post(this._visibilityWorker, payload);
590
+ const postedLodPlan = this._post(this._lodPlanWorker, payload);
591
+ const postedSearch = this._post(this._searchWorker, {
592
+ type: 'REBUILD_BOARD',
593
+ boardId,
594
+ reason: String(options.reason || 'rebuild-search-index'),
595
+ nodes: searchNodes
596
+ });
597
+ if (postedVisibility || postedLodPlan || postedSearch) {
598
+ activeModule._visibilityWorkerPrimed = false;
599
+ this._clearHitTestCache(activeModule);
600
+ }
601
+ return postedVisibility || postedLodPlan || postedSearch;
602
+ }
603
+
604
+ upsertNodeEntry(entry, module = this.module, options = {}) {
605
+ const activeModule = module || this.module;
606
+ const boardId = this._resolveBoardId(activeModule, options.boardId);
607
+ if (!activeModule || !boardId) {
608
+ return false;
609
+ }
610
+
611
+ const snapshot = buildWorkerNodeSnapshot(
612
+ entry,
613
+ options.nodeId,
614
+ options.bounds || null,
615
+ options.cellKeys || null
616
+ );
617
+ const searchSnapshot = buildWorkerSearchSnapshot(
618
+ entry,
619
+ options.nodeId,
620
+ options.bounds || null
621
+ );
622
+ if (!snapshot && !searchSnapshot) {
623
+ return false;
624
+ }
625
+
626
+ let postedVisibility = false;
627
+ let postedLodPlan = false;
628
+ let postedSearch = false;
629
+ if (snapshot) {
630
+ const payload = {
631
+ type: 'UPSERT_NODE',
632
+ boardId,
633
+ node: snapshot
634
+ };
635
+ postedVisibility = this._post(this._visibilityWorker, payload);
636
+ postedLodPlan = this._post(this._lodPlanWorker, payload);
637
+ }
638
+ if (searchSnapshot) {
639
+ postedSearch = this._post(this._searchWorker, {
640
+ type: 'UPSERT_NODE',
641
+ boardId,
642
+ node: searchSnapshot
643
+ });
644
+ }
645
+ if (postedVisibility || postedLodPlan) {
646
+ this._clearHitTestCache(activeModule);
647
+ }
648
+ return postedVisibility || postedLodPlan || postedSearch;
649
+ }
650
+
651
+ removeNode(nodeId, module = this.module, options = {}) {
652
+ const boardId = this._resolveBoardId(module, options.boardId);
653
+ const normalizedNodeId = String(nodeId || '').trim();
654
+ if (!boardId || !normalizedNodeId) {
655
+ return false;
656
+ }
657
+
658
+ const payload = {
659
+ type: 'REMOVE_NODE',
660
+ boardId,
661
+ nodeId: normalizedNodeId
662
+ };
663
+
664
+ const postedVisibility = this._post(this._visibilityWorker, payload);
665
+ const postedLodPlan = this._post(this._lodPlanWorker, payload);
666
+ const postedSearch = this._post(this._searchWorker, payload);
667
+ if (postedVisibility || postedLodPlan) {
668
+ this._clearHitTestCache(module || this.module);
669
+ }
670
+ return postedVisibility || postedLodPlan || postedSearch;
671
+ }
672
+
673
+ batchSyncSearchNodes(boardId, nodes = null, removedIds = null) {
674
+ if (this._searchDisabled || !this._searchWorker) {
675
+ return false;
676
+ }
677
+
678
+ const normalizedBoardId = this._resolveBoardId(this.module, boardId);
679
+ if (!normalizedBoardId) {
680
+ return false;
681
+ }
682
+
683
+ const normalizedNodes = Array.isArray(nodes)
684
+ ? nodes.map((node) => buildWorkerSearchSnapshot(node)).filter(Boolean)
685
+ : [];
686
+ const normalizedRemovedIds = Array.isArray(removedIds)
687
+ ? removedIds.map((nodeId) => String(nodeId || '').trim()).filter(Boolean)
688
+ : [];
689
+ if (normalizedNodes.length === 0 && normalizedRemovedIds.length === 0) {
690
+ return false;
691
+ }
692
+
693
+ return this._post(this._searchWorker, {
694
+ type: 'BATCH_SYNC',
695
+ boardId: normalizedBoardId,
696
+ nodes: normalizedNodes,
697
+ removedIds: normalizedRemovedIds
698
+ });
699
+ }
700
+
701
+ requestVisibility(module = this.module, camera) {
702
+ if (this._visibilityDisabled || !this._visibilityReady) {
703
+ return false;
704
+ }
705
+
706
+ const activeModule = module || this.module;
707
+ const boardId = this._resolveBoardId(activeModule);
708
+ if (!activeModule || !camera || !boardId) {
709
+ return false;
710
+ }
711
+
712
+ const cachedViewportWidth = Number(activeModule._lastViewportWidth || 0);
713
+ const cachedViewportHeight = Number(activeModule._lastViewportHeight || 0);
714
+ const viewportWidth = cachedViewportWidth > 0
715
+ ? cachedViewportWidth
716
+ : Math.max(1, Number(activeModule.container?.clientWidth || 1));
717
+ const viewportHeight = cachedViewportHeight > 0
718
+ ? cachedViewportHeight
719
+ : Math.max(1, Number(activeModule.container?.clientHeight || 1));
720
+ const now = (typeof performance !== 'undefined' && typeof performance.now === 'function')
721
+ ? performance.now()
722
+ : Date.now();
723
+ const isCtrlWheelVerticalScrolling =
724
+ (now - Number(activeModule._ctrlWheelScrollInputTime || 0)) <= CTRL_WHEEL_SCROLL_ACTIVE_WINDOW_MS;
725
+ let seq = 0;
726
+ if (this._visibilityQueryPending === true) {
727
+ seq = Math.max(0, Math.floor(Number(this._deferredVisibilityPayload?.seq || 0)));
728
+ if (seq <= 0) {
729
+ seq = ++this._latestVisibilityRequestSeq;
730
+ }
731
+ } else {
732
+ seq = ++this._latestVisibilityRequestSeq;
733
+ }
734
+
735
+ const payload = {
736
+ type: 'VISIBILITY_QUERY',
737
+ boardId,
738
+ seq,
739
+ cellSize: Math.max(1, Number(activeModule.GRID_CELL_SIZE || 500)),
740
+ camera: {
741
+ x: Number(camera.position?.x || 0),
742
+ y: Number(camera.position?.y || 0),
743
+ z: Number(camera.position?.z || 0),
744
+ near: Number(camera.near || 0),
745
+ far: Number(camera.far || Number.MAX_SAFE_INTEGER),
746
+ fov: Number(camera.fov || 45),
747
+ aspect: Math.max(0.1, Number(camera.aspect || 1)),
748
+ viewportW: viewportWidth,
749
+ viewportH: viewportHeight
750
+ },
751
+ state: {
752
+ isPanning: activeModule.isPanning === true || activeModule._panSmoothingActive === true,
753
+ isZooming: activeModule.isZooming === true,
754
+ isWindowResizing: activeModule.isWindowResizing === true,
755
+ isResizing: activeModule.isResizing === true,
756
+ isFullResMode: activeModule.lodRenderer?.isInLODMode !== true,
757
+ isCtrlWheelVerticalScrolling,
758
+ lastCtrlWheelDeltaY: Number(activeModule._ctrlWheelScrollLastDeltaY || 0),
759
+ lastPanWorldDeltaX: Number(activeModule._lastPanWorldDeltaX || 0),
760
+ lastPanWorldDeltaY: Number(activeModule._lastPanWorldDeltaY || 0)
761
+ }
762
+ };
763
+
764
+ if (this._visibilityQueryPending === true) {
765
+ this._deferredVisibilityPayload = payload;
766
+ return true;
767
+ }
768
+
769
+ const posted = this._post(this._visibilityWorker, this._stampVisibilityPayloadForPost(payload));
770
+ this._visibilityQueryPending = posted;
771
+ this._inFlightVisibilityRequestSeq = posted ? seq : 0;
772
+ return posted;
773
+ }
774
+
775
+ _flushDeferredVisibilityRequest() {
776
+ if (!this._deferredVisibilityPayload || !this._visibilityWorker || this._visibilityDisabled || !this._visibilityReady) {
777
+ return;
778
+ }
779
+
780
+ const payload = this._deferredVisibilityPayload;
781
+ this._deferredVisibilityPayload = null;
782
+ const posted = this._post(this._visibilityWorker, this._stampVisibilityPayloadForPost(payload));
783
+ this._visibilityQueryPending = posted;
784
+ this._inFlightVisibilityRequestSeq = posted
785
+ ? Math.max(0, Math.floor(Number(payload.seq || 0)))
786
+ : 0;
787
+ }
788
+
789
+ _describeHitTestQuery(module = this.module, options = {}) {
790
+ const activeModule = module || this.module;
791
+ const boardId = this._resolveBoardId(activeModule);
792
+ const point = options.point || null;
793
+ const pointX = Number(point?.x);
794
+ const pointY = Number(point?.y);
795
+ if (!activeModule || !boardId || !Number.isFinite(pointX) || !Number.isFinite(pointY)) {
796
+ return null;
797
+ }
798
+
799
+ const cellSize = Math.max(1, Number(activeModule.GRID_CELL_SIZE || 500));
800
+ const cellRadius = Math.max(0, Math.min(3, Math.round(Number(options.cellRadius || 1))));
801
+ const cellX = Math.floor(pointX / cellSize);
802
+ const cellY = Math.floor(pointY / cellSize);
803
+
804
+ return {
805
+ boardId,
806
+ cellRadius,
807
+ cellSize,
808
+ cellX,
809
+ cellY,
810
+ rangeKey: `${cellX}:${cellY}:${cellRadius}`
811
+ };
812
+ }
813
+
814
+ primeHitTestCandidates(module = this.module, options = {}) {
815
+ if (this._visibilityDisabled || !this._visibilityReady) {
816
+ return false;
817
+ }
818
+
819
+ const activeModule = module || this.module;
820
+ const query = this._describeHitTestQuery(activeModule, options);
821
+ if (!activeModule || !query) {
822
+ return false;
823
+ }
824
+
825
+ if (String(activeModule._workerHitTestBoardId || '') === query.boardId &&
826
+ String(activeModule._workerHitTestRangeKey || '') === query.rangeKey) {
827
+ return true;
828
+ }
829
+
830
+ const payload = {
831
+ type: 'HIT_TEST_QUERY',
832
+ boardId: query.boardId,
833
+ seq: ++this._latestHitTestRequestSeq,
834
+ cellX: query.cellX,
835
+ cellY: query.cellY,
836
+ cellRadius: query.cellRadius
837
+ };
838
+
839
+ if (this._hitTestQueryPending === true) {
840
+ this._deferredHitTestPayload = payload;
841
+ return true;
842
+ }
843
+
844
+ const posted = this._post(this._visibilityWorker, payload);
845
+ this._hitTestQueryPending = posted;
846
+ return posted;
847
+ }
848
+
849
+ _flushDeferredHitTestRequest() {
850
+ if (!this._deferredHitTestPayload || !this._visibilityWorker || this._visibilityDisabled || !this._visibilityReady) {
851
+ return;
852
+ }
853
+
854
+ const payload = this._deferredHitTestPayload;
855
+ this._deferredHitTestPayload = null;
856
+ const posted = this._post(this._visibilityWorker, payload);
857
+ this._hitTestQueryPending = posted;
858
+ }
859
+
860
+ getCachedHitTestCandidateIds(module = this.module, options = {}) {
861
+ const activeModule = module || this.module;
862
+ const query = this._describeHitTestQuery(activeModule, options);
863
+ if (!activeModule || !query) {
864
+ return null;
865
+ }
866
+
867
+ if (String(activeModule._workerHitTestBoardId || '') !== query.boardId) {
868
+ return null;
869
+ }
870
+
871
+ if (String(activeModule._workerHitTestRangeKey || '') !== query.rangeKey) {
872
+ return null;
873
+ }
874
+
875
+ return Array.isArray(activeModule._workerHitTestCandidateIds)
876
+ ? activeModule._workerHitTestCandidateIds.slice()
877
+ : [];
878
+ }
879
+
880
+ requestSelectionQuery(module = this.module, options = {}) {
881
+ if (this._visibilityDisabled || !this._visibilityReady) {
882
+ return Promise.resolve(null);
883
+ }
884
+
885
+ const activeModule = module || this.module;
886
+ const boardId = this._resolveBoardId(activeModule);
887
+ const selectionRect = options.selectionRect || null;
888
+ if (!activeModule || !boardId || !selectionRect) {
889
+ return Promise.resolve(null);
890
+ }
891
+
892
+ const payload = {
893
+ type: 'SELECTION_QUERY',
894
+ boardId,
895
+ seq: ++this._latestSelectionRequestSeq,
896
+ cellSize: Math.max(1, Number(activeModule.GRID_CELL_SIZE || 500)),
897
+ selectionRect: {
898
+ left: Number(selectionRect.left || 0),
899
+ right: Number(selectionRect.right || 0),
900
+ bottom: Number(selectionRect.bottom || 0),
901
+ top: Number(selectionRect.top || 0)
902
+ }
903
+ };
904
+
905
+ return new Promise((resolve) => {
906
+ this._pendingSelectionResolvers.set(payload.seq, resolve);
907
+ const posted = this._post(this._visibilityWorker, payload);
908
+ if (!posted) {
909
+ this._pendingSelectionResolvers.delete(payload.seq);
910
+ resolve(null);
911
+ }
912
+ });
913
+ }
914
+
915
+ requestLodPlan(module = this.module, options = {}) {
916
+ if (this._lodPlanDisabled || !this._lodPlanReady) {
917
+ return false;
918
+ }
919
+
920
+ const activeModule = module || this.module;
921
+ const boardId = this._resolveBoardId(activeModule);
922
+ const visibleIds = options.visibleIds instanceof Set
923
+ ? Array.from(options.visibleIds)
924
+ : Array.isArray(options.visibleIds)
925
+ ? options.visibleIds
926
+ : [];
927
+ const key = String(options.key || '').trim();
928
+
929
+ if (!activeModule || !boardId || !key || visibleIds.length === 0 && Number(options.totalNodeCount || 0) === 0) {
930
+ return false;
931
+ }
932
+
933
+ if (this._pendingLodPlanKey === key) {
934
+ return true;
935
+ }
936
+
937
+ this._pendingLodPlanKey = key;
938
+ const seq = ++this._latestLodPlanRequestSeq;
939
+ return this._post(this._lodPlanWorker, {
940
+ type: 'LOD_PLAN_QUERY',
941
+ boardId,
942
+ seq,
943
+ key,
944
+ visibilityVersion: Number(options.visibilityVersion || 0),
945
+ lodBand: String(options.lodBand || '').trim(),
946
+ selectionKey: String(options.selectionKey || '').trim(),
947
+ totalNodeCount: Number(options.totalNodeCount || 0),
948
+ visibleIds: visibleIds.map((id) => String(id || '').trim()).filter(Boolean)
949
+ });
950
+ }
951
+
952
+ requestNodeSearch(module = this.module, options = {}) {
953
+ if (this._searchDisabled || !this._searchReady) {
954
+ return Promise.resolve(null);
955
+ }
956
+
957
+ const activeModule = module || this.module;
958
+ const boardId = this._resolveBoardId(activeModule);
959
+ const query = String(options.query || '').trim();
960
+ if (!activeModule || !boardId || !query) {
961
+ return Promise.resolve(null);
962
+ }
963
+
964
+ const seq = ++this._latestSearchRequestSeq;
965
+ const limit = Math.max(1, Number(options.limit || 12));
966
+ const contentTypes = Array.isArray(options.contentTypes)
967
+ ? options.contentTypes.map((value) => String(value || '').trim().toLowerCase()).filter(Boolean)
968
+ : [];
969
+ const payload = {
970
+ type: 'SEARCH_QUERY',
971
+ boardId,
972
+ seq,
973
+ query,
974
+ limit,
975
+ contentTypes,
976
+ camera: {
977
+ x: Number(activeModule.camera?.position?.x || 0),
978
+ y: Number(activeModule.camera?.position?.y || 0),
979
+ z: Number(activeModule.camera?.position?.z || 0),
980
+ aspect: Math.max(0.1, Number(activeModule.camera?.aspect || 1))
981
+ }
982
+ };
983
+
984
+ return new Promise((resolve) => {
985
+ this._pendingSearchResolvers.set(seq, resolve);
986
+ const posted = this._post(this._searchWorker, payload);
987
+ if (!posted) {
988
+ this._pendingSearchResolvers.delete(seq);
989
+ resolve(null);
990
+ }
991
+ });
992
+ }
993
+ }
994
+
995
+ window.MindMapLogicWorkers = Object.assign(window.MindMapLogicWorkers || {}, {
996
+ BUILD_ID: LOGIC_WORKER_BRIDGE_BUILD_ID,
997
+ createBridge(module) {
998
+ return new MindMapLogicWorkerBridge(module);
999
+ },
1000
+ buildWorkerNodeSnapshot,
1001
+ buildWorkerSearchSnapshot,
1002
+ isTextLikeContentType
1003
+ });
1004
+ })();