@dimina-kit/devtools 0.1.0-dev.20260422094158

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 (301) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +562 -0
  3. package/dist/main/api.d.ts +21 -0
  4. package/dist/main/api.d.ts.map +1 -0
  5. package/dist/main/api.js +22 -0
  6. package/dist/main/api.js.map +1 -0
  7. package/dist/main/app/app.d.ts +15 -0
  8. package/dist/main/app/app.d.ts.map +1 -0
  9. package/dist/main/app/app.js +192 -0
  10. package/dist/main/app/app.js.map +1 -0
  11. package/dist/main/app/bootstrap.d.ts +14 -0
  12. package/dist/main/app/bootstrap.d.ts.map +1 -0
  13. package/dist/main/app/bootstrap.js +41 -0
  14. package/dist/main/app/bootstrap.js.map +1 -0
  15. package/dist/main/app/launch.d.ts +10 -0
  16. package/dist/main/app/launch.d.ts.map +1 -0
  17. package/dist/main/app/launch.js +28 -0
  18. package/dist/main/app/launch.js.map +1 -0
  19. package/dist/main/app/lifecycle.d.ts +2 -0
  20. package/dist/main/app/lifecycle.d.ts.map +1 -0
  21. package/dist/main/app/lifecycle.js +11 -0
  22. package/dist/main/app/lifecycle.js.map +1 -0
  23. package/dist/main/index.d.ts +2 -0
  24. package/dist/main/index.d.ts.map +1 -0
  25. package/dist/main/index.js +3 -0
  26. package/dist/main/index.js.map +1 -0
  27. package/dist/main/ipc/app.d.ts +3 -0
  28. package/dist/main/ipc/app.d.ts.map +1 -0
  29. package/dist/main/ipc/app.js +14 -0
  30. package/dist/main/ipc/app.js.map +1 -0
  31. package/dist/main/ipc/index.d.ts +9 -0
  32. package/dist/main/ipc/index.d.ts.map +1 -0
  33. package/dist/main/ipc/index.js +9 -0
  34. package/dist/main/ipc/index.js.map +1 -0
  35. package/dist/main/ipc/panels.d.ts +3 -0
  36. package/dist/main/ipc/panels.d.ts.map +1 -0
  37. package/dist/main/ipc/panels.js +39 -0
  38. package/dist/main/ipc/panels.js.map +1 -0
  39. package/dist/main/ipc/popover.d.ts +3 -0
  40. package/dist/main/ipc/popover.d.ts.map +1 -0
  41. package/dist/main/ipc/popover.js +13 -0
  42. package/dist/main/ipc/popover.js.map +1 -0
  43. package/dist/main/ipc/projects.d.ts +3 -0
  44. package/dist/main/ipc/projects.d.ts.map +1 -0
  45. package/dist/main/ipc/projects.js +15 -0
  46. package/dist/main/ipc/projects.js.map +1 -0
  47. package/dist/main/ipc/session.d.ts +3 -0
  48. package/dist/main/ipc/session.d.ts.map +1 -0
  49. package/dist/main/ipc/session.js +10 -0
  50. package/dist/main/ipc/session.js.map +1 -0
  51. package/dist/main/ipc/settings.d.ts +3 -0
  52. package/dist/main/ipc/settings.d.ts.map +1 -0
  53. package/dist/main/ipc/settings.js +61 -0
  54. package/dist/main/ipc/settings.js.map +1 -0
  55. package/dist/main/ipc/simulator.d.ts +3 -0
  56. package/dist/main/ipc/simulator.d.ts.map +1 -0
  57. package/dist/main/ipc/simulator.js +26 -0
  58. package/dist/main/ipc/simulator.js.map +1 -0
  59. package/dist/main/ipc/toolbar.d.ts +3 -0
  60. package/dist/main/ipc/toolbar.d.ts.map +1 -0
  61. package/dist/main/ipc/toolbar.js +10 -0
  62. package/dist/main/ipc/toolbar.js.map +1 -0
  63. package/dist/main/menu/index.d.ts +3 -0
  64. package/dist/main/menu/index.d.ts.map +1 -0
  65. package/dist/main/menu/index.js +65 -0
  66. package/dist/main/menu/index.js.map +1 -0
  67. package/dist/main/services/automation/exec.d.ts +9 -0
  68. package/dist/main/services/automation/exec.d.ts.map +1 -0
  69. package/dist/main/services/automation/exec.js +33 -0
  70. package/dist/main/services/automation/exec.js.map +1 -0
  71. package/dist/main/services/automation/handlers/app.d.ts +3 -0
  72. package/dist/main/services/automation/handlers/app.d.ts.map +1 -0
  73. package/dist/main/services/automation/handlers/app.js +132 -0
  74. package/dist/main/services/automation/handlers/app.js.map +1 -0
  75. package/dist/main/services/automation/handlers/element.d.ts +3 -0
  76. package/dist/main/services/automation/handlers/element.d.ts.map +1 -0
  77. package/dist/main/services/automation/handlers/element.js +151 -0
  78. package/dist/main/services/automation/handlers/element.js.map +1 -0
  79. package/dist/main/services/automation/handlers/page.d.ts +3 -0
  80. package/dist/main/services/automation/handlers/page.d.ts.map +1 -0
  81. package/dist/main/services/automation/handlers/page.js +66 -0
  82. package/dist/main/services/automation/handlers/page.js.map +1 -0
  83. package/dist/main/services/automation/handlers/tool.d.ts +3 -0
  84. package/dist/main/services/automation/handlers/tool.d.ts.map +1 -0
  85. package/dist/main/services/automation/handlers/tool.js +8 -0
  86. package/dist/main/services/automation/handlers/tool.js.map +1 -0
  87. package/dist/main/services/automation/index.d.ts +18 -0
  88. package/dist/main/services/automation/index.d.ts.map +1 -0
  89. package/dist/main/services/automation/index.js +95 -0
  90. package/dist/main/services/automation/index.js.map +1 -0
  91. package/dist/main/services/automation/registry.d.ts +6 -0
  92. package/dist/main/services/automation/registry.d.ts.map +1 -0
  93. package/dist/main/services/automation/registry.js +20 -0
  94. package/dist/main/services/automation/registry.js.map +1 -0
  95. package/dist/main/services/automation/shared.d.ts +24 -0
  96. package/dist/main/services/automation/shared.d.ts.map +1 -0
  97. package/dist/main/services/automation/shared.js +2 -0
  98. package/dist/main/services/automation/shared.js.map +1 -0
  99. package/dist/main/services/default-adapter.d.ts +3 -0
  100. package/dist/main/services/default-adapter.d.ts.map +1 -0
  101. package/dist/main/services/default-adapter.js +17 -0
  102. package/dist/main/services/default-adapter.js.map +1 -0
  103. package/dist/main/services/layout/index.d.ts +27 -0
  104. package/dist/main/services/layout/index.d.ts.map +1 -0
  105. package/dist/main/services/layout/index.js +49 -0
  106. package/dist/main/services/layout/index.js.map +1 -0
  107. package/dist/main/services/mcp/index.d.ts +15 -0
  108. package/dist/main/services/mcp/index.d.ts.map +1 -0
  109. package/dist/main/services/mcp/index.js +15 -0
  110. package/dist/main/services/mcp/index.js.map +1 -0
  111. package/dist/main/services/mcp/server.d.ts +10 -0
  112. package/dist/main/services/mcp/server.d.ts.map +1 -0
  113. package/dist/main/services/mcp/server.js +76 -0
  114. package/dist/main/services/mcp/server.js.map +1 -0
  115. package/dist/main/services/mcp/target-manager.d.ts +43 -0
  116. package/dist/main/services/mcp/target-manager.d.ts.map +1 -0
  117. package/dist/main/services/mcp/target-manager.js +165 -0
  118. package/dist/main/services/mcp/target-manager.js.map +1 -0
  119. package/dist/main/services/mcp/tool-registry.d.ts +14 -0
  120. package/dist/main/services/mcp/tool-registry.d.ts.map +1 -0
  121. package/dist/main/services/mcp/tool-registry.js +84 -0
  122. package/dist/main/services/mcp/tool-registry.js.map +1 -0
  123. package/dist/main/services/mcp/tools/context-tools.d.ts +15 -0
  124. package/dist/main/services/mcp/tools/context-tools.d.ts.map +1 -0
  125. package/dist/main/services/mcp/tools/context-tools.js +244 -0
  126. package/dist/main/services/mcp/tools/context-tools.js.map +1 -0
  127. package/dist/main/services/mcp/tools/simulator-tools.d.ts +14 -0
  128. package/dist/main/services/mcp/tools/simulator-tools.d.ts.map +1 -0
  129. package/dist/main/services/mcp/tools/simulator-tools.js +143 -0
  130. package/dist/main/services/mcp/tools/simulator-tools.js.map +1 -0
  131. package/dist/main/services/mcp/tools/workbench-tools.d.ts +7 -0
  132. package/dist/main/services/mcp/tools/workbench-tools.d.ts.map +1 -0
  133. package/dist/main/services/mcp/tools/workbench-tools.js +13 -0
  134. package/dist/main/services/mcp/tools/workbench-tools.js.map +1 -0
  135. package/dist/main/services/notifications/renderer-notifier.d.ts +80 -0
  136. package/dist/main/services/notifications/renderer-notifier.d.ts.map +1 -0
  137. package/dist/main/services/notifications/renderer-notifier.js +70 -0
  138. package/dist/main/services/notifications/renderer-notifier.js.map +1 -0
  139. package/dist/main/services/projects/index.d.ts +2 -0
  140. package/dist/main/services/projects/index.d.ts.map +1 -0
  141. package/dist/main/services/projects/index.js +6 -0
  142. package/dist/main/services/projects/index.js.map +1 -0
  143. package/dist/main/services/projects/project-repository.d.ts +28 -0
  144. package/dist/main/services/projects/project-repository.d.ts.map +1 -0
  145. package/dist/main/services/projects/project-repository.js +145 -0
  146. package/dist/main/services/projects/project-repository.js.map +1 -0
  147. package/dist/main/services/settings/index.d.ts +16 -0
  148. package/dist/main/services/settings/index.d.ts.map +1 -0
  149. package/dist/main/services/settings/index.js +46 -0
  150. package/dist/main/services/settings/index.js.map +1 -0
  151. package/dist/main/services/simulator/dir.d.ts +2 -0
  152. package/dist/main/services/simulator/dir.d.ts.map +1 -0
  153. package/dist/main/services/simulator/dir.js +5 -0
  154. package/dist/main/services/simulator/dir.js.map +1 -0
  155. package/dist/main/services/simulator/referer.d.ts +10 -0
  156. package/dist/main/services/simulator/referer.d.ts.map +1 -0
  157. package/dist/main/services/simulator/referer.js +20 -0
  158. package/dist/main/services/simulator/referer.js.map +1 -0
  159. package/dist/main/services/views/view-manager.d.ts +84 -0
  160. package/dist/main/services/views/view-manager.d.ts.map +1 -0
  161. package/dist/main/services/views/view-manager.js +254 -0
  162. package/dist/main/services/views/view-manager.js.map +1 -0
  163. package/dist/main/services/workbench-context.d.ts +59 -0
  164. package/dist/main/services/workbench-context.d.ts.map +1 -0
  165. package/dist/main/services/workbench-context.js +33 -0
  166. package/dist/main/services/workbench-context.js.map +1 -0
  167. package/dist/main/services/workspace/index.d.ts +2 -0
  168. package/dist/main/services/workspace/index.d.ts.map +1 -0
  169. package/dist/main/services/workspace/index.js +2 -0
  170. package/dist/main/services/workspace/index.js.map +1 -0
  171. package/dist/main/services/workspace/workspace-service.d.ts +49 -0
  172. package/dist/main/services/workspace/workspace-service.d.ts.map +1 -0
  173. package/dist/main/services/workspace/workspace-service.js +90 -0
  174. package/dist/main/services/workspace/workspace-service.js.map +1 -0
  175. package/dist/main/utils/logger.d.ts +15 -0
  176. package/dist/main/utils/logger.d.ts.map +1 -0
  177. package/dist/main/utils/logger.js +48 -0
  178. package/dist/main/utils/logger.js.map +1 -0
  179. package/dist/main/utils/paths.d.ts +6 -0
  180. package/dist/main/utils/paths.d.ts.map +1 -0
  181. package/dist/main/utils/paths.js +15 -0
  182. package/dist/main/utils/paths.js.map +1 -0
  183. package/dist/main/utils/theme.d.ts +10 -0
  184. package/dist/main/utils/theme.d.ts.map +1 -0
  185. package/dist/main/utils/theme.js +13 -0
  186. package/dist/main/utils/theme.js.map +1 -0
  187. package/dist/main/windows/main-window/create.d.ts +11 -0
  188. package/dist/main/windows/main-window/create.d.ts.map +1 -0
  189. package/dist/main/windows/main-window/create.js +67 -0
  190. package/dist/main/windows/main-window/create.js.map +1 -0
  191. package/dist/main/windows/main-window/events.d.ts +9 -0
  192. package/dist/main/windows/main-window/events.d.ts.map +1 -0
  193. package/dist/main/windows/main-window/events.js +18 -0
  194. package/dist/main/windows/main-window/events.js.map +1 -0
  195. package/dist/main/windows/main-window/index.d.ts +5 -0
  196. package/dist/main/windows/main-window/index.d.ts.map +1 -0
  197. package/dist/main/windows/main-window/index.js +3 -0
  198. package/dist/main/windows/main-window/index.js.map +1 -0
  199. package/dist/main/windows/settings-window/create.d.ts +3 -0
  200. package/dist/main/windows/settings-window/create.d.ts.map +1 -0
  201. package/dist/main/windows/settings-window/create.js +18 -0
  202. package/dist/main/windows/settings-window/create.js.map +1 -0
  203. package/dist/main/windows/settings-window/events.d.ts +3 -0
  204. package/dist/main/windows/settings-window/events.d.ts.map +1 -0
  205. package/dist/main/windows/settings-window/events.js +6 -0
  206. package/dist/main/windows/settings-window/events.js.map +1 -0
  207. package/dist/main/windows/settings-window/index.d.ts +3 -0
  208. package/dist/main/windows/settings-window/index.d.ts.map +1 -0
  209. package/dist/main/windows/settings-window/index.js +3 -0
  210. package/dist/main/windows/settings-window/index.js.map +1 -0
  211. package/dist/preload/instrumentation/app-data.d.ts +3 -0
  212. package/dist/preload/instrumentation/app-data.d.ts.map +1 -0
  213. package/dist/preload/instrumentation/app-data.js +103 -0
  214. package/dist/preload/instrumentation/app-data.js.map +1 -0
  215. package/dist/preload/instrumentation/console.d.ts +2 -0
  216. package/dist/preload/instrumentation/console.d.ts.map +1 -0
  217. package/dist/preload/instrumentation/console.js +54 -0
  218. package/dist/preload/instrumentation/console.js.map +1 -0
  219. package/dist/preload/instrumentation/disposable.d.ts +11 -0
  220. package/dist/preload/instrumentation/disposable.d.ts.map +1 -0
  221. package/dist/preload/instrumentation/disposable.js +15 -0
  222. package/dist/preload/instrumentation/disposable.js.map +1 -0
  223. package/dist/preload/instrumentation/index.d.ts +5 -0
  224. package/dist/preload/instrumentation/index.d.ts.map +1 -0
  225. package/dist/preload/instrumentation/index.js +5 -0
  226. package/dist/preload/instrumentation/index.js.map +1 -0
  227. package/dist/preload/instrumentation/storage.d.ts +2 -0
  228. package/dist/preload/instrumentation/storage.d.ts.map +1 -0
  229. package/dist/preload/instrumentation/storage.js +106 -0
  230. package/dist/preload/instrumentation/storage.js.map +1 -0
  231. package/dist/preload/instrumentation/wxml-extract.d.ts +11 -0
  232. package/dist/preload/instrumentation/wxml-extract.d.ts.map +1 -0
  233. package/dist/preload/instrumentation/wxml-extract.js +173 -0
  234. package/dist/preload/instrumentation/wxml-extract.js.map +1 -0
  235. package/dist/preload/instrumentation/wxml.d.ts +5 -0
  236. package/dist/preload/instrumentation/wxml.d.ts.map +1 -0
  237. package/dist/preload/instrumentation/wxml.js +223 -0
  238. package/dist/preload/instrumentation/wxml.js.map +1 -0
  239. package/dist/preload/runtime/bridge.d.ts +36 -0
  240. package/dist/preload/runtime/bridge.d.ts.map +1 -0
  241. package/dist/preload/runtime/bridge.js +151 -0
  242. package/dist/preload/runtime/bridge.js.map +1 -0
  243. package/dist/preload/runtime/host.d.ts +3 -0
  244. package/dist/preload/runtime/host.d.ts.map +1 -0
  245. package/dist/preload/runtime/host.js +28 -0
  246. package/dist/preload/runtime/host.js.map +1 -0
  247. package/dist/preload/shared/api-compat.d.ts +2 -0
  248. package/dist/preload/shared/api-compat.d.ts.map +1 -0
  249. package/dist/preload/shared/api-compat.js +196 -0
  250. package/dist/preload/shared/api-compat.js.map +1 -0
  251. package/dist/preload/shared/constants.d.ts +16 -0
  252. package/dist/preload/shared/constants.d.ts.map +1 -0
  253. package/dist/preload/shared/constants.js +16 -0
  254. package/dist/preload/shared/constants.js.map +1 -0
  255. package/dist/preload/shared/types.d.ts +34 -0
  256. package/dist/preload/shared/types.d.ts.map +1 -0
  257. package/dist/preload/shared/types.js +8 -0
  258. package/dist/preload/shared/types.js.map +1 -0
  259. package/dist/preload/windows/main.d.ts +7 -0
  260. package/dist/preload/windows/main.d.ts.map +1 -0
  261. package/dist/preload/windows/main.js +7 -0
  262. package/dist/preload/windows/main.js.map +1 -0
  263. package/dist/preload/windows/simulator.js +969 -0
  264. package/dist/preload/windows/simulator.js.map +7 -0
  265. package/dist/renderer/assets/index-kcmIQPCg.js +2 -0
  266. package/dist/renderer/assets/index-kcmIQPCg.js.map +1 -0
  267. package/dist/renderer/assets/input-B7sz4y1r.js +2 -0
  268. package/dist/renderer/assets/input-B7sz4y1r.js.map +1 -0
  269. package/dist/renderer/assets/ipc-transport-C9-PPTGn.css +1 -0
  270. package/dist/renderer/assets/ipc-transport-L_WD9x12.js +9 -0
  271. package/dist/renderer/assets/ipc-transport-L_WD9x12.js.map +1 -0
  272. package/dist/renderer/assets/popover-CzMIs2j4.js +2 -0
  273. package/dist/renderer/assets/popover-CzMIs2j4.js.map +1 -0
  274. package/dist/renderer/assets/select-BBXJVe8R.js +2 -0
  275. package/dist/renderer/assets/select-BBXJVe8R.js.map +1 -0
  276. package/dist/renderer/assets/settings-Db1pvrBJ.js +2 -0
  277. package/dist/renderer/assets/settings-Db1pvrBJ.js.map +1 -0
  278. package/dist/renderer/assets/settings-api-DJ1M-CNt.js +2 -0
  279. package/dist/renderer/assets/settings-api-DJ1M-CNt.js.map +1 -0
  280. package/dist/renderer/assets/workbenchSettings-BnQsvWkQ.js +8 -0
  281. package/dist/renderer/assets/workbenchSettings-BnQsvWkQ.js.map +1 -0
  282. package/dist/renderer/entries/main/index.html +15 -0
  283. package/dist/renderer/entries/popover/index.html +18 -0
  284. package/dist/renderer/entries/settings/index.html +15 -0
  285. package/dist/renderer/entries/workbench-settings/index.html +15 -0
  286. package/dist/shared/constants.d.ts +10 -0
  287. package/dist/shared/constants.d.ts.map +1 -0
  288. package/dist/shared/constants.js +10 -0
  289. package/dist/shared/constants.js.map +1 -0
  290. package/dist/shared/ipc-channels.d.ts +89 -0
  291. package/dist/shared/ipc-channels.d.ts.map +1 -0
  292. package/dist/shared/ipc-channels.js +102 -0
  293. package/dist/shared/ipc-channels.js.map +1 -0
  294. package/dist/shared/types.d.ts +89 -0
  295. package/dist/shared/types.d.ts.map +1 -0
  296. package/dist/shared/types.js +2 -0
  297. package/dist/shared/types.js.map +1 -0
  298. package/dist/simulator/assets/simulator-C1eHXnuq.js +9 -0
  299. package/dist/simulator/assets/simulator-C1eHXnuq.js.map +1 -0
  300. package/dist/simulator/simulator.html +164 -0
  301. package/package.json +204 -0
@@ -0,0 +1,969 @@
1
+ "use strict";
2
+
3
+ // src/preload/runtime/bridge.ts
4
+ var import_electron = require("electron");
5
+ var state = {
6
+ appdata: { gen: 0, ready: true, data: {} },
7
+ storage: { gen: 0, ready: false, namespace: null, data: {} },
8
+ wxml: { gen: 0, ready: false, data: null },
9
+ refreshHandler: null
10
+ };
11
+ var highlightOverlay = null;
12
+ var exposedApi = null;
13
+ function clone(value) {
14
+ try {
15
+ return JSON.parse(JSON.stringify(value));
16
+ } catch {
17
+ return value;
18
+ }
19
+ }
20
+ function getPageIframe() {
21
+ const iframes = document.querySelectorAll(".dimina-native-webview__window");
22
+ return iframes.length > 0 ? iframes[iframes.length - 1] : null;
23
+ }
24
+ function ensureOverlay(doc) {
25
+ if (highlightOverlay && highlightOverlay.ownerDocument === doc) return highlightOverlay;
26
+ highlightOverlay = doc.createElement("div");
27
+ highlightOverlay.id = "__simulator-highlight";
28
+ highlightOverlay.style.cssText = "position:fixed;pointer-events:none;z-index:999999;border:2px solid #1a73e8;background:rgba(26,115,232,0.12);transition:all 0.1s ease;display:none;border-radius:2px;";
29
+ doc.body.appendChild(highlightOverlay);
30
+ return highlightOverlay;
31
+ }
32
+ function highlightElement(sid) {
33
+ const iframe = getPageIframe();
34
+ if (!iframe?.contentDocument) return;
35
+ const doc = iframe.contentDocument;
36
+ const el = doc.querySelector(`[data-sid="${sid}"]`);
37
+ if (!el) return;
38
+ const rect = el.getBoundingClientRect();
39
+ const overlay = ensureOverlay(doc);
40
+ overlay.style.left = `${rect.left}px`;
41
+ overlay.style.top = `${rect.top}px`;
42
+ overlay.style.width = `${rect.width}px`;
43
+ overlay.style.height = `${rect.height}px`;
44
+ overlay.style.display = "block";
45
+ }
46
+ function unhighlightElement() {
47
+ if (highlightOverlay) highlightOverlay.style.display = "none";
48
+ }
49
+ function buildApi() {
50
+ return {
51
+ getAppdata: () => clone(state.appdata.data),
52
+ getAppdataSnapshot: () => clone(state.appdata),
53
+ getAppdataGen: () => state.appdata.gen,
54
+ getStorageSnapshot: () => clone(state.storage),
55
+ getStorageGen: () => state.storage.gen,
56
+ getWxml: () => clone(state.wxml.data),
57
+ getWxmlSnapshot: () => clone(state.wxml),
58
+ getWxmlGen: () => state.wxml.gen,
59
+ refresh: (type) => state.refreshHandler?.(type),
60
+ highlightElement,
61
+ unhighlightElement
62
+ };
63
+ }
64
+ function setAppDataSnapshot(data) {
65
+ state.appdata = {
66
+ gen: state.appdata.gen + 1,
67
+ ready: true,
68
+ data: clone(data)
69
+ };
70
+ }
71
+ function clearAppDataSnapshot() {
72
+ state.appdata = {
73
+ gen: state.appdata.gen + 1,
74
+ ready: true,
75
+ data: {}
76
+ };
77
+ }
78
+ function setStorageSnapshot(namespace, data) {
79
+ state.storage = {
80
+ gen: state.storage.gen + 1,
81
+ ready: namespace !== null,
82
+ namespace,
83
+ data: clone(data)
84
+ };
85
+ }
86
+ function clearStorageSnapshot() {
87
+ state.storage = {
88
+ gen: state.storage.gen + 1,
89
+ ready: false,
90
+ namespace: null,
91
+ data: {}
92
+ };
93
+ }
94
+ function setWxmlSnapshot(data, ready = true) {
95
+ state.wxml = {
96
+ gen: state.wxml.gen + 1,
97
+ ready,
98
+ data: clone(data)
99
+ };
100
+ }
101
+ function clearWxmlSnapshot() {
102
+ state.wxml = {
103
+ gen: state.wxml.gen + 1,
104
+ ready: false,
105
+ data: null
106
+ };
107
+ }
108
+ function resetBridgeState() {
109
+ clearAppDataSnapshot();
110
+ clearStorageSnapshot();
111
+ clearWxmlSnapshot();
112
+ unhighlightElement();
113
+ state.refreshHandler = null;
114
+ }
115
+ function installSimulatorBridge() {
116
+ if (!exposedApi) {
117
+ exposedApi = buildApi();
118
+ }
119
+ try {
120
+ import_electron.contextBridge.exposeInMainWorld("__simulatorData", {
121
+ ...exposedApi,
122
+ getAppdata: () => clone(state.appdata.data),
123
+ getAppdataSnapshot: () => clone(state.appdata),
124
+ getStorageSnapshot: () => clone(state.storage),
125
+ getWxml: () => clone(state.wxml.data),
126
+ getWxmlSnapshot: () => clone(state.wxml)
127
+ });
128
+ } catch {
129
+ ;
130
+ window.__simulatorData = exposedApi;
131
+ }
132
+ return () => {
133
+ resetBridgeState();
134
+ const windowRef = window;
135
+ if (windowRef.__simulatorData === exposedApi) {
136
+ delete windowRef.__simulatorData;
137
+ }
138
+ };
139
+ }
140
+
141
+ // src/shared/ipc-channels.ts
142
+ var SimulatorChannel = {
143
+ Attach: "simulator:attach",
144
+ Detach: "simulator:detach",
145
+ Resize: "simulator:resize",
146
+ SetVisible: "simulator:setVisible",
147
+ Console: "simulator:console",
148
+ Wxml: "simulator:wxml",
149
+ AppData: "simulator:appdata",
150
+ AppDataAll: "simulator:appdata-all",
151
+ Storage: "simulator:storage",
152
+ StorageAll: "simulator:storage-all"
153
+ };
154
+
155
+ // src/preload/runtime/host.ts
156
+ var import_electron2 = require("electron");
157
+ function sendToHost(channel, data) {
158
+ import_electron2.ipcRenderer.sendToHost(channel, data);
159
+ }
160
+ function safeSerialize(val) {
161
+ if (val === null || val === void 0) return val;
162
+ if (typeof val === "function") return `[Function: ${val.name || "anonymous"}]`;
163
+ if (typeof val !== "object") return val;
164
+ if (val instanceof Error) return { __isError: true, message: val.message, stack: val.stack };
165
+ try {
166
+ return structuredClone(val);
167
+ } catch {
168
+ }
169
+ try {
170
+ return JSON.parse(JSON.stringify(val));
171
+ } catch {
172
+ }
173
+ return String(val);
174
+ }
175
+
176
+ // src/preload/instrumentation/console.ts
177
+ function installConsoleInstrumentation() {
178
+ const consoleRef = console;
179
+ const originals = /* @__PURE__ */ new Map();
180
+ const levels = ["log", "warn", "error", "info", "debug"];
181
+ for (const level of levels) {
182
+ const original = consoleRef[level]?.bind(console);
183
+ if (!original) continue;
184
+ originals.set(level, original);
185
+ consoleRef[level] = (...args) => {
186
+ original(...args);
187
+ sendToHost(SimulatorChannel.Console, {
188
+ source: "container",
189
+ level,
190
+ args: args.map(safeSerialize),
191
+ ts: Date.now()
192
+ });
193
+ };
194
+ }
195
+ const handleError = (event) => {
196
+ sendToHost(SimulatorChannel.Console, {
197
+ source: "container",
198
+ level: "error",
199
+ args: [{
200
+ message: event.message,
201
+ source: event.filename,
202
+ lineno: event.lineno,
203
+ colno: event.colno,
204
+ stack: event.error?.stack
205
+ }],
206
+ ts: Date.now()
207
+ });
208
+ };
209
+ const handleRejection = (event) => {
210
+ sendToHost(SimulatorChannel.Console, {
211
+ source: "container",
212
+ level: "error",
213
+ args: [{ message: "Unhandled Promise Rejection", reason: String(event.reason) }],
214
+ ts: Date.now()
215
+ });
216
+ };
217
+ window.addEventListener("error", handleError);
218
+ window.addEventListener("unhandledrejection", handleRejection);
219
+ return () => {
220
+ for (const [level, original] of originals) {
221
+ consoleRef[level] = original;
222
+ }
223
+ window.removeEventListener("error", handleError);
224
+ window.removeEventListener("unhandledrejection", handleRejection);
225
+ };
226
+ }
227
+
228
+ // src/preload/instrumentation/disposable.ts
229
+ function createDisposableSet() {
230
+ const disposables2 = [];
231
+ return {
232
+ add: (fn) => disposables2.push(fn),
233
+ disposeAll: () => {
234
+ disposables2.forEach((fn) => fn());
235
+ disposables2.length = 0;
236
+ }
237
+ };
238
+ }
239
+
240
+ // src/preload/instrumentation/storage.ts
241
+ var STORAGE_PREFIX = /^#\/?/;
242
+ function getStorageNamespace() {
243
+ const hash = window.location.hash || "";
244
+ const normalized = hash.replace(STORAGE_PREFIX, "");
245
+ const candidate = normalized.split(/[|/?&]/, 1)[0]?.trim();
246
+ return candidate ? candidate : null;
247
+ }
248
+ function normalizeStorageKey(rawKey, namespace) {
249
+ const prefix = `${namespace}_`;
250
+ if (!rawKey.startsWith(prefix)) return null;
251
+ return rawKey.slice(prefix.length);
252
+ }
253
+ function readSnapshot(namespace) {
254
+ if (!namespace) return {};
255
+ const items = {};
256
+ for (let i = 0; i < localStorage.length; i++) {
257
+ const key = localStorage.key(i);
258
+ if (!key) continue;
259
+ const normalized = normalizeStorageKey(key, namespace);
260
+ if (normalized === null) continue;
261
+ items[normalized] = localStorage.getItem(key) ?? "";
262
+ }
263
+ return items;
264
+ }
265
+ function syncSnapshot(namespace) {
266
+ if (!namespace) {
267
+ clearStorageSnapshot();
268
+ return;
269
+ }
270
+ setStorageSnapshot(namespace, readSnapshot(namespace));
271
+ }
272
+ function installStorageInstrumentation() {
273
+ const originalSetItem = localStorage.setItem.bind(localStorage);
274
+ const originalRemoveItem = localStorage.removeItem.bind(localStorage);
275
+ const namespaceRef = { value: getStorageNamespace() };
276
+ const handleNamespaceChange = () => {
277
+ namespaceRef.value = getStorageNamespace();
278
+ syncSnapshot(namespaceRef.value);
279
+ };
280
+ const handleSetItem = (key, value) => {
281
+ const namespace = namespaceRef.value;
282
+ originalSetItem(key, value);
283
+ if (namespace) {
284
+ const normalized = normalizeStorageKey(key, namespace);
285
+ if (normalized !== null) {
286
+ const snapshot = readSnapshot(namespace);
287
+ setStorageSnapshot(namespace, snapshot);
288
+ sendToHost(SimulatorChannel.Storage, {
289
+ namespace,
290
+ action: "set",
291
+ key: normalized,
292
+ rawKey: key,
293
+ value,
294
+ ts: Date.now()
295
+ });
296
+ }
297
+ }
298
+ };
299
+ const handleRemoveItem = (key) => {
300
+ const namespace = namespaceRef.value;
301
+ originalRemoveItem(key);
302
+ if (namespace) {
303
+ const normalized = normalizeStorageKey(key, namespace);
304
+ if (normalized !== null) {
305
+ const snapshot = readSnapshot(namespace);
306
+ setStorageSnapshot(namespace, snapshot);
307
+ sendToHost(SimulatorChannel.Storage, {
308
+ namespace,
309
+ action: "remove",
310
+ key: normalized,
311
+ rawKey: key,
312
+ ts: Date.now()
313
+ });
314
+ }
315
+ }
316
+ };
317
+ const disposables2 = createDisposableSet();
318
+ localStorage.setItem = handleSetItem;
319
+ localStorage.removeItem = handleRemoveItem;
320
+ window.addEventListener("hashchange", handleNamespaceChange);
321
+ syncSnapshot(namespaceRef.value);
322
+ disposables2.add(() => {
323
+ localStorage.setItem = originalSetItem;
324
+ localStorage.removeItem = originalRemoveItem;
325
+ });
326
+ disposables2.add(() => {
327
+ window.removeEventListener("hashchange", handleNamespaceChange);
328
+ });
329
+ disposables2.add(() => {
330
+ clearStorageSnapshot();
331
+ });
332
+ return () => {
333
+ disposables2.disposeAll();
334
+ };
335
+ }
336
+
337
+ // src/preload/instrumentation/app-data.ts
338
+ var appDataCache = /* @__PURE__ */ new Map();
339
+ function publishSnapshot() {
340
+ const data = {};
341
+ for (const [key, value] of appDataCache) {
342
+ data[key] = value;
343
+ }
344
+ setAppDataSnapshot(data);
345
+ }
346
+ function decodeWorkerMessage(message) {
347
+ let payload = message;
348
+ if (typeof payload === "string") {
349
+ try {
350
+ payload = JSON.parse(payload);
351
+ } catch {
352
+ return null;
353
+ }
354
+ }
355
+ const record = payload;
356
+ if (record?.type !== "u" || !record.body) return null;
357
+ return record.body;
358
+ }
359
+ function createInstrumentedWorker(OriginalWorker) {
360
+ function InstrumentedWorker(scriptURL, options) {
361
+ const resolvedScriptURL = scriptURL instanceof URL ? scriptURL : new URL(scriptURL, window.location.href);
362
+ const worker = Reflect.construct(
363
+ OriginalWorker,
364
+ [resolvedScriptURL, options],
365
+ new.target ?? InstrumentedWorker
366
+ );
367
+ worker.addEventListener("message", (event) => {
368
+ const body = decodeWorkerMessage(event.data);
369
+ if (!body) return;
370
+ window.__simulatorHook?.appData({
371
+ bridgeId: body.bridgeId,
372
+ moduleId: body.moduleId,
373
+ data: body.data
374
+ });
375
+ });
376
+ return worker;
377
+ }
378
+ Object.setPrototypeOf(InstrumentedWorker, OriginalWorker);
379
+ Object.defineProperty(InstrumentedWorker, "prototype", {
380
+ value: OriginalWorker.prototype
381
+ });
382
+ return InstrumentedWorker;
383
+ }
384
+ function installAppDataInstrumentation() {
385
+ const disposables2 = createDisposableSet();
386
+ const originalHook = window.__simulatorHook;
387
+ const originalDescriptor = Object.getOwnPropertyDescriptor(window, "Worker");
388
+ const OriginalWorker = window.Worker;
389
+ window.__simulatorHook = {
390
+ appData: (body) => {
391
+ const record = body;
392
+ if (record?.bridgeId && record?.moduleId) {
393
+ const key = `${record.bridgeId}/${record.moduleId}`;
394
+ appDataCache.set(key, record.data);
395
+ publishSnapshot();
396
+ }
397
+ sendToHost(SimulatorChannel.AppData, body);
398
+ }
399
+ };
400
+ Object.defineProperty(window, "Worker", {
401
+ configurable: true,
402
+ writable: true,
403
+ value: createInstrumentedWorker(OriginalWorker)
404
+ });
405
+ publishSnapshot();
406
+ disposables2.add(() => {
407
+ if (originalDescriptor) {
408
+ Object.defineProperty(window, "Worker", originalDescriptor);
409
+ } else {
410
+ window.Worker = OriginalWorker;
411
+ }
412
+ });
413
+ disposables2.add(() => {
414
+ if (originalHook) {
415
+ window.__simulatorHook = originalHook;
416
+ } else {
417
+ delete window.__simulatorHook;
418
+ }
419
+ });
420
+ disposables2.add(() => {
421
+ appDataCache.clear();
422
+ clearAppDataSnapshot();
423
+ publishSnapshot();
424
+ });
425
+ return () => {
426
+ disposables2.disposeAll();
427
+ };
428
+ }
429
+
430
+ // src/preload/shared/constants.ts
431
+ var WXML_DEBOUNCE_MS = 300;
432
+ var WXML_RETRY_INTERVAL_MS = 500;
433
+ var WXML_RETRY_TIMEOUT_MS = 1e4;
434
+ var NAVIGATION_POLL_INTERVAL_MS = 200;
435
+ var NAVIGATION_TIMEOUT_MS = 1e4;
436
+
437
+ // src/preload/instrumentation/wxml-extract.ts
438
+ var INTERNAL_CLASSES = /* @__PURE__ */ new Set([
439
+ "dd-swiper-wrapper",
440
+ "dd-swiper-slides",
441
+ "dd-swiper-slide-frame",
442
+ "dd-swiper-dots",
443
+ "dd-picker-overlay",
444
+ "dd-picker-container",
445
+ "dd-picker-header",
446
+ "dd-picker-body"
447
+ ]);
448
+ var FRAMEWORK_TEMPLATE_RE = /^(taro_tmpl|tmpl_\d+)/;
449
+ function resolveTemplateNameFromParent(instance) {
450
+ const parent = instance.parent;
451
+ if (!parent) return null;
452
+ const parentType = parent.type;
453
+ const components = parentType?.components;
454
+ if (components) {
455
+ for (const [regName, comp] of Object.entries(components)) {
456
+ if (comp === instance.type) return regName.startsWith("dd-") ? regName.slice(3) : regName;
457
+ }
458
+ }
459
+ const appComponents = instance.appContext?.components;
460
+ if (!appComponents) return null;
461
+ for (const [regName, comp] of Object.entries(appComponents)) {
462
+ if (comp === instance.type) return regName.startsWith("dd-") ? regName.slice(3) : regName;
463
+ }
464
+ return null;
465
+ }
466
+ function resolveTagName(instance) {
467
+ const type = instance.type;
468
+ if (!type) return "unknown";
469
+ if (typeof type.__tagName === "string") return type.__tagName;
470
+ const name = type.__name || type.name;
471
+ if (!name) {
472
+ if (type.__scopeId && type.components) return "page";
473
+ if (type.__scopeId) return resolveTemplateNameFromParent(instance) || "template";
474
+ return "unknown";
475
+ }
476
+ if (name === "dd-page") return "page";
477
+ if (name.startsWith("dd-")) return name.slice(3);
478
+ if (name.startsWith("Dd") && name.length > 2) return name.slice(2).toLowerCase();
479
+ return name;
480
+ }
481
+ function extractProps(instance) {
482
+ const out = {};
483
+ for (const raw of [instance.props, instance.attrs]) {
484
+ if (!raw) continue;
485
+ for (const [k, v] of Object.entries(raw)) {
486
+ if (typeof v === "function" || v === void 0) continue;
487
+ if (k === "data" || k.startsWith("__")) continue;
488
+ if (typeof v === "boolean" && !v) continue;
489
+ if (k === "class" && typeof v === "string") {
490
+ const cleaned = v.split(/\s+/).filter((c) => !c.startsWith("dd-")).join(" ");
491
+ if (cleaned) out[k] = cleaned;
492
+ continue;
493
+ }
494
+ out[k] = typeof v === "object" ? JSON.stringify(v) : String(v);
495
+ }
496
+ }
497
+ return out;
498
+ }
499
+ function isInternalElement(vnode) {
500
+ const props = vnode.props;
501
+ if (!props) return false;
502
+ const cls = String(props.class || "");
503
+ return cls.split(/\s+/).some((c) => INTERNAL_CLASSES.has(c));
504
+ }
505
+ function getElementSid(instance) {
506
+ const subTree = instance.subTree;
507
+ const el = subTree?.el;
508
+ return el?.getAttribute ? el.getAttribute("data-sid") ?? void 0 : void 0;
509
+ }
510
+ function isTransparentComponent(instance, tagName) {
511
+ if (tagName === "unknown") return true;
512
+ if (tagName === "template") {
513
+ const props = instance.props;
514
+ const is = props?.is;
515
+ if (is && FRAMEWORK_TEMPLATE_RE.test(is)) return true;
516
+ if (!is) {
517
+ const type = instance.type;
518
+ if (type?.__scopeId && !type.components) return true;
519
+ }
520
+ }
521
+ return false;
522
+ }
523
+ function extractChildrenFromVNode(vnode, depth) {
524
+ if (!vnode || depth > 50) return [];
525
+ if (vnode.component) {
526
+ const result2 = walkInstance(vnode.component, depth + 1);
527
+ return result2 ? Array.isArray(result2) ? result2 : [result2] : [];
528
+ }
529
+ if (vnode.suspense) {
530
+ const suspense = vnode.suspense;
531
+ const activeBranch = suspense.activeBranch;
532
+ return activeBranch ? extractChildrenFromVNode(activeBranch, depth + 1) : [];
533
+ }
534
+ if (typeof vnode.children === "string" && vnode.children.trim()) {
535
+ const vnodeType = vnode.type;
536
+ if (typeof vnodeType === "symbol" || typeof vnodeType === "string") {
537
+ return [{ tagName: "#text", attrs: {}, children: [], text: vnode.children.trim() }];
538
+ }
539
+ }
540
+ const kids = vnode.children;
541
+ if (!Array.isArray(kids)) return [];
542
+ const result = [];
543
+ for (const child of kids) {
544
+ if (!child) continue;
545
+ if (typeof child === "string") {
546
+ const trimmed = child.trim();
547
+ if (trimmed) result.push({ tagName: "#text", attrs: {}, children: [], text: trimmed });
548
+ continue;
549
+ }
550
+ if (typeof child !== "object") continue;
551
+ const c = child;
552
+ if (c.component) {
553
+ const walked = walkInstance(c.component, depth + 1);
554
+ if (walked) result.push(...Array.isArray(walked) ? walked : [walked]);
555
+ continue;
556
+ }
557
+ if (typeof c.type === "symbol") {
558
+ result.push(...extractChildrenFromVNode(c, depth + 1));
559
+ continue;
560
+ }
561
+ if (typeof c.type === "string") {
562
+ if (isInternalElement(c)) {
563
+ result.push(...extractChildrenFromVNode(c, depth + 1));
564
+ } else if (typeof c.children === "string" && c.children.trim()) {
565
+ result.push({ tagName: "#text", attrs: {}, children: [], text: c.children.trim() });
566
+ } else {
567
+ result.push(...extractChildrenFromVNode(c, depth + 1));
568
+ }
569
+ continue;
570
+ }
571
+ result.push(...extractChildrenFromVNode(c, depth + 1));
572
+ }
573
+ return result;
574
+ }
575
+ function walkInstance(instance, depth) {
576
+ if (depth > 50) return null;
577
+ const tagName = resolveTagName(instance);
578
+ const children = extractChildrenFromVNode(instance.subTree, depth);
579
+ if (isTransparentComponent(instance, tagName)) return children.length > 0 ? children : null;
580
+ const node = { tagName, attrs: extractProps(instance), children };
581
+ const sid = getElementSid(instance);
582
+ if (sid) node.sid = sid;
583
+ return node;
584
+ }
585
+
586
+ // src/preload/instrumentation/wxml.ts
587
+ function findActivePageIframe() {
588
+ const iframes = document.querySelectorAll(".dimina-native-webview__window");
589
+ return iframes.length > 0 ? iframes[iframes.length - 1] : null;
590
+ }
591
+ function getVueAppFromIframe(iframe) {
592
+ try {
593
+ const doc = iframe.contentDocument;
594
+ if (!doc?.body) return null;
595
+ const body = doc.body;
596
+ const app = body.__vue_app__;
597
+ if (!app) return null;
598
+ if (app._instance) return app._instance;
599
+ const container = app._container;
600
+ const vnode = container?._vnode;
601
+ return vnode?.component ?? null;
602
+ } catch {
603
+ return null;
604
+ }
605
+ }
606
+ var wxmlTimer;
607
+ var currentObserver = null;
608
+ var currentIframe = null;
609
+ var topObserver = null;
610
+ var retryTimer;
611
+ var retryTimeout;
612
+ var navigationWaitTimer;
613
+ var navigationWaitTimeout;
614
+ var disposables = createDisposableSet();
615
+ function clearTimers() {
616
+ if (wxmlTimer) clearTimeout(wxmlTimer);
617
+ if (retryTimer) clearInterval(retryTimer);
618
+ if (retryTimeout) clearTimeout(retryTimeout);
619
+ if (navigationWaitTimer) clearInterval(navigationWaitTimer);
620
+ if (navigationWaitTimeout) clearTimeout(navigationWaitTimeout);
621
+ wxmlTimer = void 0;
622
+ retryTimer = void 0;
623
+ retryTimeout = void 0;
624
+ navigationWaitTimer = void 0;
625
+ navigationWaitTimeout = void 0;
626
+ }
627
+ function publishTree(tree) {
628
+ if (tree) {
629
+ const normalized = Array.isArray(tree) ? { tagName: "#fragment", attrs: {}, children: tree } : tree;
630
+ setWxmlSnapshot(normalized, true);
631
+ sendToHost(SimulatorChannel.Wxml, normalized);
632
+ return;
633
+ }
634
+ clearWxmlSnapshot();
635
+ unhighlightElement();
636
+ }
637
+ function sendWxmlTree() {
638
+ const iframe = findActivePageIframe();
639
+ if (!iframe) {
640
+ publishTree(null);
641
+ return;
642
+ }
643
+ const instance = getVueAppFromIframe(iframe);
644
+ if (!instance) {
645
+ publishTree(null);
646
+ return;
647
+ }
648
+ const tree = walkInstance(instance, 0);
649
+ if (!tree) {
650
+ publishTree(null);
651
+ return;
652
+ }
653
+ publishTree(tree);
654
+ }
655
+ function observeIframe(iframe) {
656
+ if (iframe === currentIframe) return;
657
+ if (currentObserver) {
658
+ currentObserver.disconnect();
659
+ currentObserver = null;
660
+ }
661
+ if (navigationWaitTimer) {
662
+ clearInterval(navigationWaitTimer);
663
+ navigationWaitTimer = void 0;
664
+ }
665
+ if (navigationWaitTimeout) {
666
+ clearTimeout(navigationWaitTimeout);
667
+ navigationWaitTimeout = void 0;
668
+ }
669
+ currentIframe = iframe;
670
+ const doc = iframe.contentDocument;
671
+ if (!doc?.body) {
672
+ publishTree(null);
673
+ return;
674
+ }
675
+ sendWxmlTree();
676
+ currentObserver = new MutationObserver(() => {
677
+ clearTimeout(wxmlTimer);
678
+ wxmlTimer = setTimeout(sendWxmlTree, WXML_DEBOUNCE_MS);
679
+ });
680
+ currentObserver.observe(doc.body, { childList: true, subtree: true });
681
+ }
682
+ function tryAttach() {
683
+ const iframe = findActivePageIframe();
684
+ if (!iframe) return false;
685
+ const instance = getVueAppFromIframe(iframe);
686
+ if (!instance) return false;
687
+ observeIframe(iframe);
688
+ return true;
689
+ }
690
+ function scheduleAttach() {
691
+ if (retryTimer) clearInterval(retryTimer);
692
+ if (retryTimeout) clearTimeout(retryTimeout);
693
+ retryTimer = setInterval(() => {
694
+ if (tryAttach() && retryTimer) {
695
+ clearInterval(retryTimer);
696
+ retryTimer = void 0;
697
+ }
698
+ }, WXML_RETRY_INTERVAL_MS);
699
+ retryTimeout = setTimeout(() => {
700
+ if (retryTimer) clearInterval(retryTimer);
701
+ retryTimer = void 0;
702
+ }, WXML_RETRY_TIMEOUT_MS);
703
+ }
704
+ function observeTopLevel() {
705
+ if (topObserver) return;
706
+ topObserver = new MutationObserver(() => {
707
+ const iframe = findActivePageIframe();
708
+ if (!iframe) {
709
+ publishTree(null);
710
+ return;
711
+ }
712
+ if (iframe !== currentIframe) {
713
+ if (navigationWaitTimer) {
714
+ clearInterval(navigationWaitTimer);
715
+ navigationWaitTimer = void 0;
716
+ }
717
+ if (navigationWaitTimeout) {
718
+ clearTimeout(navigationWaitTimeout);
719
+ navigationWaitTimeout = void 0;
720
+ }
721
+ navigationWaitTimer = setInterval(() => {
722
+ if (getVueAppFromIframe(iframe)) {
723
+ if (navigationWaitTimer) {
724
+ clearInterval(navigationWaitTimer);
725
+ navigationWaitTimer = void 0;
726
+ }
727
+ if (navigationWaitTimeout) {
728
+ clearTimeout(navigationWaitTimeout);
729
+ navigationWaitTimeout = void 0;
730
+ }
731
+ observeIframe(iframe);
732
+ }
733
+ }, NAVIGATION_POLL_INTERVAL_MS);
734
+ navigationWaitTimeout = setTimeout(() => {
735
+ if (navigationWaitTimer) {
736
+ clearInterval(navigationWaitTimer);
737
+ navigationWaitTimer = void 0;
738
+ }
739
+ navigationWaitTimeout = void 0;
740
+ }, NAVIGATION_TIMEOUT_MS);
741
+ }
742
+ });
743
+ if (document.body) {
744
+ topObserver.observe(document.body, { childList: true, subtree: true });
745
+ } else {
746
+ document.addEventListener("DOMContentLoaded", () => {
747
+ if (document.body && topObserver) {
748
+ topObserver.observe(document.body, { childList: true, subtree: true });
749
+ }
750
+ }, { once: true });
751
+ }
752
+ }
753
+ function installWxmlInstrumentation() {
754
+ if (!tryAttach()) {
755
+ scheduleAttach();
756
+ }
757
+ observeTopLevel();
758
+ disposables.add(() => {
759
+ if (currentObserver) {
760
+ currentObserver.disconnect();
761
+ currentObserver = null;
762
+ }
763
+ });
764
+ disposables.add(() => {
765
+ if (topObserver) {
766
+ topObserver.disconnect();
767
+ topObserver = null;
768
+ }
769
+ });
770
+ disposables.add(() => {
771
+ currentIframe = null;
772
+ clearTimers();
773
+ });
774
+ disposables.add(() => {
775
+ clearWxmlSnapshot();
776
+ unhighlightElement();
777
+ });
778
+ return () => {
779
+ disposables.disposeAll();
780
+ };
781
+ }
782
+
783
+ // src/preload/shared/api-compat.ts
784
+ function call(fn, payload) {
785
+ try {
786
+ fn?.(payload);
787
+ } catch {
788
+ }
789
+ }
790
+ function buildWindowInfo() {
791
+ const width = window.innerWidth || document.documentElement.clientWidth || 375;
792
+ const height = window.innerHeight || document.documentElement.clientHeight || 812;
793
+ const pixelRatio = window.devicePixelRatio || 2;
794
+ const statusBarHeight = 0;
795
+ return {
796
+ pixelRatio,
797
+ screenWidth: width,
798
+ screenHeight: height,
799
+ windowWidth: width,
800
+ windowHeight: height,
801
+ statusBarHeight,
802
+ safeArea: {
803
+ width,
804
+ height,
805
+ top: statusBarHeight,
806
+ bottom: height,
807
+ left: 0,
808
+ right: width
809
+ }
810
+ };
811
+ }
812
+ function makeStorageKey(key) {
813
+ return `dimina:${key}`;
814
+ }
815
+ function ensureWxApi(wx) {
816
+ if (typeof wx.canIUse !== "function") {
817
+ wx.canIUse = (_schema) => true;
818
+ }
819
+ if (typeof wx.getWindowInfo !== "function") {
820
+ wx.getWindowInfo = (opts = {}) => {
821
+ const info = buildWindowInfo();
822
+ call(opts.success, info);
823
+ call(opts.complete, void 0);
824
+ return info;
825
+ };
826
+ }
827
+ if (typeof wx.getSystemSetting !== "function") {
828
+ wx.getSystemSetting = (opts = {}) => {
829
+ const info = {
830
+ bluetoothEnabled: false,
831
+ locationEnabled: true,
832
+ wifiEnabled: true,
833
+ deviceOrientation: "portrait"
834
+ };
835
+ call(opts.success, info);
836
+ call(opts.complete, void 0);
837
+ return info;
838
+ };
839
+ }
840
+ if (typeof wx.getSystemInfoSync !== "function") {
841
+ wx.getSystemInfoSync = () => ({
842
+ brand: "simulator",
843
+ model: "web",
844
+ platform: "simulator",
845
+ system: "web",
846
+ language: "zh_CN",
847
+ SDKVersion: "3.0.0",
848
+ ...buildWindowInfo()
849
+ });
850
+ }
851
+ if (typeof wx.setStorageSync !== "function") {
852
+ wx.setStorageSync = (key, data) => {
853
+ const value = typeof data === "string" ? data : JSON.stringify(data);
854
+ localStorage.setItem(makeStorageKey(String(key)), value);
855
+ };
856
+ }
857
+ if (typeof wx.getStorageSync !== "function") {
858
+ wx.getStorageSync = (key) => {
859
+ const raw = localStorage.getItem(makeStorageKey(String(key)));
860
+ if (raw == null) return "";
861
+ try {
862
+ return JSON.parse(raw);
863
+ } catch {
864
+ return raw;
865
+ }
866
+ };
867
+ }
868
+ if (typeof wx.removeStorageSync !== "function") {
869
+ wx.removeStorageSync = (key) => {
870
+ localStorage.removeItem(makeStorageKey(String(key)));
871
+ };
872
+ }
873
+ if (typeof wx.clearStorageSync !== "function") {
874
+ wx.clearStorageSync = () => {
875
+ const prefix = "dimina:";
876
+ const keys = [];
877
+ for (let i = 0; i < localStorage.length; i++) {
878
+ const key = localStorage.key(i);
879
+ if (key?.startsWith(prefix)) keys.push(key);
880
+ }
881
+ keys.forEach((key) => localStorage.removeItem(key));
882
+ };
883
+ }
884
+ if (typeof wx.getStorageInfoSync !== "function") {
885
+ wx.getStorageInfoSync = () => {
886
+ const prefix = "dimina:";
887
+ const keys = [];
888
+ let currentSize = 0;
889
+ for (let i = 0; i < localStorage.length; i++) {
890
+ const fullKey = localStorage.key(i);
891
+ if (!fullKey?.startsWith(prefix)) continue;
892
+ keys.push(fullKey.slice(prefix.length));
893
+ currentSize += (localStorage.getItem(fullKey) || "").length * 2;
894
+ }
895
+ return { keys, currentSize, limitSize: 10 * 1024 * 1024 };
896
+ };
897
+ }
898
+ if (typeof wx.request !== "function") {
899
+ wx.request = (opts) => {
900
+ const controller = new AbortController();
901
+ const method = (opts.method || "GET").toUpperCase();
902
+ let requestUrl = opts.url;
903
+ const init = {
904
+ method,
905
+ headers: { "Content-Type": "application/json", ...opts.header || {} },
906
+ signal: controller.signal
907
+ };
908
+ if (method === "GET" && opts.data && typeof opts.data === "object") {
909
+ const url = new URL(requestUrl, window.location.href);
910
+ Object.entries(opts.data).forEach(([key, value]) => {
911
+ url.searchParams.append(key, String(value));
912
+ });
913
+ requestUrl = url.toString();
914
+ } else if (opts.data != null) {
915
+ init.body = typeof opts.data === "string" ? opts.data : JSON.stringify(opts.data);
916
+ }
917
+ const timeoutId = Number(opts.timeout) > 0 ? window.setTimeout(() => controller.abort(), Number(opts.timeout)) : null;
918
+ fetch(requestUrl, init).then(async (response) => {
919
+ const headers = Object.fromEntries(response.headers.entries());
920
+ let data;
921
+ if (opts.dataType === "arraybuffer") data = await response.arrayBuffer();
922
+ else {
923
+ const text = await response.text();
924
+ if (opts.dataType === "text") data = text;
925
+ else {
926
+ try {
927
+ data = JSON.parse(text);
928
+ } catch {
929
+ data = text;
930
+ }
931
+ }
932
+ }
933
+ call(opts.success, { data, statusCode: response.status, header: headers, errMsg: "request:ok" });
934
+ }).catch((error) => {
935
+ call(opts.fail, { errMsg: `request:fail ${error instanceof Error ? error.message : String(error)}` });
936
+ }).finally(() => {
937
+ if (timeoutId != null) window.clearTimeout(timeoutId);
938
+ call(opts.complete, void 0);
939
+ });
940
+ return {
941
+ abort: () => controller.abort()
942
+ };
943
+ };
944
+ }
945
+ }
946
+ function setupApiCompatHook() {
947
+ const apply = () => {
948
+ const target = window;
949
+ if (!target.wx || typeof target.wx !== "object") {
950
+ target.wx = {};
951
+ }
952
+ const wx = target.wx;
953
+ ensureWxApi(wx);
954
+ return true;
955
+ };
956
+ if (apply()) return;
957
+ const timer = window.setInterval(() => {
958
+ if (apply()) window.clearInterval(timer);
959
+ }, 200);
960
+ }
961
+
962
+ // src/preload/windows/simulator.ts
963
+ setupApiCompatHook();
964
+ installSimulatorBridge();
965
+ installConsoleInstrumentation();
966
+ installStorageInstrumentation();
967
+ installAppDataInstrumentation();
968
+ installWxmlInstrumentation();
969
+ //# sourceMappingURL=simulator.js.map