@dimina-kit/devtools 0.3.2-dev.20260525152421 → 0.3.2-dev.20260610082053

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 (295) hide show
  1. package/README.md +43 -40
  2. package/dist/main/api.d.ts +0 -1
  3. package/dist/main/api.js +5 -1
  4. package/dist/main/app/app.d.ts +15 -5
  5. package/dist/main/app/app.js +247 -110
  6. package/dist/main/app/bootstrap.d.ts +16 -0
  7. package/dist/main/app/bootstrap.js +20 -0
  8. package/dist/main/app/launch.d.ts +8 -4
  9. package/dist/main/app/launch.js +9 -4
  10. package/dist/main/index.bundle.js +6607 -2102
  11. package/dist/main/index.js +9 -1
  12. package/dist/main/ipc/app.d.ts +1 -1
  13. package/dist/main/ipc/bridge-router.d.ts +61 -0
  14. package/dist/main/ipc/bridge-router.js +1300 -0
  15. package/dist/main/ipc/panels.d.ts +1 -1
  16. package/dist/main/ipc/panels.js +6 -2
  17. package/dist/main/ipc/popover.d.ts +1 -1
  18. package/dist/main/ipc/project-fs.d.ts +57 -0
  19. package/dist/main/ipc/project-fs.js +448 -0
  20. package/dist/main/ipc/projects.d.ts +1 -1
  21. package/dist/main/ipc/session.d.ts +1 -1
  22. package/dist/main/ipc/settings.d.ts +1 -1
  23. package/dist/main/ipc/simulator-module.d.ts +6 -0
  24. package/dist/main/ipc/simulator-module.js +11 -1
  25. package/dist/main/ipc/simulator.d.ts +2 -2
  26. package/dist/main/ipc/simulator.js +49 -5
  27. package/dist/main/ipc/toolbar.d.ts +1 -1
  28. package/dist/main/ipc/views.d.ts +19 -0
  29. package/dist/main/ipc/views.js +65 -0
  30. package/dist/main/runtime/devtools-backend.d.ts +17 -0
  31. package/dist/main/runtime/devtools-backend.js +49 -0
  32. package/dist/main/runtime/miniapp-runtime.d.ts +39 -0
  33. package/dist/main/runtime/miniapp-runtime.js +17 -0
  34. package/dist/main/services/automation/exec.d.ts +27 -2
  35. package/dist/main/services/automation/exec.js +37 -3
  36. package/dist/main/services/automation/handlers/app.js +127 -11
  37. package/dist/main/services/automation/handlers/page.js +36 -19
  38. package/dist/main/services/automation/index.js +40 -13
  39. package/dist/main/services/automation/wait-active-page.d.ts +56 -0
  40. package/dist/main/services/automation/wait-active-page.js +71 -0
  41. package/dist/main/services/console-forward/index.d.ts +36 -0
  42. package/dist/main/services/console-forward/index.js +81 -0
  43. package/dist/main/services/dimina-resource-server.d.ts +7 -0
  44. package/dist/main/services/dimina-resource-server.js +99 -0
  45. package/dist/main/services/elements-forward/index.d.ts +66 -0
  46. package/dist/main/services/elements-forward/index.js +583 -0
  47. package/dist/main/services/layout/index.d.ts +23 -1
  48. package/dist/main/services/layout/index.js +28 -3
  49. package/dist/main/services/mcp/index.d.ts +1 -0
  50. package/dist/main/services/mcp/index.js +3 -0
  51. package/dist/main/services/mcp/server.d.ts +1 -1
  52. package/dist/main/services/mcp/server.js +1 -1
  53. package/dist/main/services/mcp/target-manager.d.ts +35 -0
  54. package/dist/main/services/mcp/target-manager.js +63 -1
  55. package/dist/main/services/mcp/tools/context-tools.js +15 -1
  56. package/dist/main/services/module.d.ts +1 -1
  57. package/dist/main/services/network-forward/index.d.ts +190 -0
  58. package/dist/main/services/network-forward/index.js +765 -0
  59. package/dist/main/services/notifications/renderer-notifier.d.ts +11 -0
  60. package/dist/main/services/notifications/renderer-notifier.js +7 -1
  61. package/dist/main/services/render-inspect/index.d.ts +41 -0
  62. package/dist/main/services/render-inspect/index.js +88 -0
  63. package/dist/main/services/safe-area/index.d.ts +17 -0
  64. package/dist/main/services/safe-area/index.js +59 -0
  65. package/dist/main/services/service-host-pool/pool.d.ts +197 -0
  66. package/dist/main/services/service-host-pool/pool.js +364 -0
  67. package/dist/main/services/simulator/custom-apis.d.ts +34 -0
  68. package/dist/main/services/simulator/custom-apis.js +22 -0
  69. package/dist/main/services/simulator-appdata/index.d.ts +35 -0
  70. package/dist/main/services/simulator-appdata/index.js +71 -0
  71. package/dist/main/services/simulator-current-page/index.d.ts +24 -0
  72. package/dist/main/services/simulator-current-page/index.js +19 -0
  73. package/dist/main/services/simulator-storage/index.d.ts +37 -2
  74. package/dist/main/services/simulator-storage/index.js +209 -32
  75. package/dist/main/services/simulator-storage/service-storage-ops.d.ts +40 -0
  76. package/dist/main/services/simulator-storage/service-storage-ops.js +67 -0
  77. package/dist/main/services/simulator-temp-files/fs-channels.js +1 -1
  78. package/dist/main/services/simulator-temp-files/index.d.ts +1 -1
  79. package/dist/main/services/simulator-temp-files/index.js +1 -1
  80. package/dist/main/services/simulator-temp-files/request-handler.js +1 -1
  81. package/dist/main/services/simulator-wxml/index.d.ts +29 -0
  82. package/dist/main/services/simulator-wxml/index.js +28 -0
  83. package/dist/main/services/update/update-manager.d.ts +10 -0
  84. package/dist/main/services/update/update-manager.js +16 -3
  85. package/dist/main/services/views/devtools-tabs.d.ts +47 -0
  86. package/dist/main/services/views/devtools-tabs.js +95 -0
  87. package/dist/main/services/views/view-manager.d.ts +142 -4
  88. package/dist/main/services/views/view-manager.js +909 -17
  89. package/dist/main/services/workbench-context.d.ts +66 -1
  90. package/dist/main/services/workbench-context.js +6 -1
  91. package/dist/main/services/workspace/workspace-service.d.ts +8 -0
  92. package/dist/main/services/workspace/workspace-service.js +12 -0
  93. package/dist/main/utils/ipc-registry.d.ts +11 -2
  94. package/dist/main/utils/ipc-registry.js +63 -3
  95. package/dist/main/utils/paths.d.ts +15 -0
  96. package/dist/main/utils/paths.js +19 -0
  97. package/dist/main/utils/sender-policy.d.ts +9 -3
  98. package/dist/main/utils/sender-policy.js +18 -4
  99. package/dist/main/utils/theme.d.ts +1 -1
  100. package/dist/main/utils/theme.js +1 -1
  101. package/dist/main/windows/main-window/create.d.ts +0 -6
  102. package/dist/main/windows/main-window/create.js +11 -59
  103. package/dist/main/windows/main-window/events.d.ts +1 -1
  104. package/dist/main/windows/main-window/events.js +1 -1
  105. package/dist/main/windows/service-host-window/create.d.ts +52 -0
  106. package/dist/main/windows/service-host-window/create.js +112 -0
  107. package/dist/native-host/common/common.js +368 -0
  108. package/dist/native-host/container/pageFrame.css +1 -0
  109. package/dist/native-host/render/render.js +9334 -0
  110. package/dist/native-host/service/service.js +6 -0
  111. package/dist/preload/index.d.ts +2 -0
  112. package/dist/preload/index.js +6 -0
  113. package/dist/preload/instrumentation/app-data.d.ts +18 -20
  114. package/dist/preload/instrumentation/app-data.js +23 -160
  115. package/dist/preload/instrumentation/wxml-extract.d.ts +1 -1
  116. package/dist/preload/instrumentation/wxml-extract.js +1 -1
  117. package/dist/preload/runtime/bridge.d.ts +3 -8
  118. package/dist/preload/runtime/bridge.js +2 -32
  119. package/dist/preload/runtime/custom-apis.js +20 -17
  120. package/dist/preload/runtime/host-toolbar-advertiser.d.ts +27 -0
  121. package/dist/preload/runtime/host-toolbar-advertiser.js +55 -0
  122. package/dist/preload/runtime/main-api-runner.d.ts +9 -0
  123. package/dist/preload/runtime/main-api-runner.js +85 -0
  124. package/dist/preload/runtime/native-host.d.ts +43 -0
  125. package/dist/preload/runtime/native-host.js +83 -0
  126. package/dist/preload/shared/expose.d.ts +10 -5
  127. package/dist/preload/shared/expose.js +29 -11
  128. package/dist/preload/shared/sid-registry.d.ts +11 -0
  129. package/dist/preload/shared/sid-registry.js +38 -0
  130. package/dist/preload/windows/host-toolbar.cjs +161 -0
  131. package/dist/preload/windows/host-toolbar.cjs.map +7 -0
  132. package/dist/preload/windows/host-toolbar.d.ts +2 -0
  133. package/dist/preload/windows/host-toolbar.js +12 -0
  134. package/dist/preload/windows/main.cjs +1939 -0
  135. package/dist/preload/windows/main.cjs.map +4 -4
  136. package/dist/preload/windows/simulator.cjs +925 -0
  137. package/dist/preload/windows/simulator.cjs.map +7 -0
  138. package/dist/preload/windows/simulator.js +243 -573
  139. package/dist/render-host/pageFrame.html +29 -0
  140. package/dist/render-host/preload.cjs +154 -0
  141. package/dist/render-host/render-inspect.js +295 -0
  142. package/dist/renderer/assets/abap-DiwvWnMr.js +2 -0
  143. package/dist/renderer/assets/apex-CmtZjKlf.js +2 -0
  144. package/dist/renderer/assets/azcli-DL2My_i-.js +2 -0
  145. package/dist/renderer/assets/bat-B-nC98wG.js +2 -0
  146. package/dist/renderer/assets/bicep-Ju5MwOgh.js +3 -0
  147. package/dist/renderer/assets/cameligo-8Eu1TyBr.js +2 -0
  148. package/dist/renderer/assets/chunk-DPI0Y_ll.js +1 -0
  149. package/dist/renderer/assets/clojure-u-RpMkH3.js +2 -0
  150. package/dist/renderer/assets/codicon-ngg6Pgfi.ttf +0 -0
  151. package/dist/renderer/assets/coffee-CdA7bbTe.js +2 -0
  152. package/dist/renderer/assets/constants-CLAQX6VZ.js +2 -0
  153. package/dist/renderer/assets/cpp-CzNFP8ks.js +2 -0
  154. package/dist/renderer/assets/csharp-j1LThmcE.js +2 -0
  155. package/dist/renderer/assets/csp-CLRC61y6.js +2 -0
  156. package/dist/renderer/assets/css-r6rC_7P2.js +4 -0
  157. package/dist/renderer/assets/css.worker-DyDu5ynT.js +90 -0
  158. package/dist/renderer/assets/cssMode-BCBgxrnA.js +2 -0
  159. package/dist/renderer/assets/cypher-CW08XVUh.js +2 -0
  160. package/dist/renderer/assets/dart-Cs9aL5T_.js +2 -0
  161. package/dist/renderer/assets/dockerfile-BWM0M184.js +2 -0
  162. package/dist/renderer/assets/ecl-MJJuer5P.js +2 -0
  163. package/dist/renderer/assets/editor-CWI9TnMM.css +1 -0
  164. package/dist/renderer/assets/editor.api2-BTaYmRq7.js +873 -0
  165. package/dist/renderer/assets/editor.worker-Dpt_xPrs.js +27 -0
  166. package/dist/renderer/assets/elixir-D2AIuXqn.js +2 -0
  167. package/dist/renderer/assets/flow9-B2H24giC.js +2 -0
  168. package/dist/renderer/assets/freemarker2-DGDGzimW.js +4 -0
  169. package/dist/renderer/assets/fsharp-CMk2OIJN.js +2 -0
  170. package/dist/renderer/assets/go-BrMkuJg0.js +2 -0
  171. package/dist/renderer/assets/graphql-PSR1UKGv.js +2 -0
  172. package/dist/renderer/assets/handlebars-bOHhw3EG.js +2 -0
  173. package/dist/renderer/assets/hcl-DAQrbDOW.js +2 -0
  174. package/dist/renderer/assets/html-BMyuX0_c.js +2 -0
  175. package/dist/renderer/assets/html.worker-IWNXhnIC.js +503 -0
  176. package/dist/renderer/assets/htmlMode-DR4kXJ7l.js +2 -0
  177. package/dist/renderer/assets/index-CcJKzatF.js +50 -0
  178. package/dist/renderer/assets/ini-0TG5BxW0.js +2 -0
  179. package/dist/renderer/assets/input-QGx6FFX1.js +2 -0
  180. package/dist/renderer/assets/ipc-transport-BT4QYQqu.css +1 -0
  181. package/dist/renderer/assets/{ipc-transport-BzPzxPwf.js → ipc-transport-DvZvwK-Z.js} +5 -5
  182. package/dist/renderer/assets/java-rgorz17v.js +2 -0
  183. package/dist/renderer/assets/javascript-Bu-tl1P7.js +2 -0
  184. package/dist/renderer/assets/json.worker-c4h5s80L.js +59 -0
  185. package/dist/renderer/assets/jsonMode-MQV_ffLR.js +8 -0
  186. package/dist/renderer/assets/julia-C8VMdHm8.js +2 -0
  187. package/dist/renderer/assets/kotlin-AhhC4Qhm.js +2 -0
  188. package/dist/renderer/assets/less-Cgca25AP.js +3 -0
  189. package/dist/renderer/assets/lexon-D0GHdBaw.js +2 -0
  190. package/dist/renderer/assets/liquid-ClkfOvhB.js +2 -0
  191. package/dist/renderer/assets/lspLanguageFeatures-Bke_4Ie9.js +5 -0
  192. package/dist/renderer/assets/lua-DmRsNG-P.js +2 -0
  193. package/dist/renderer/assets/m3-BgL5dNKT.js +2 -0
  194. package/dist/renderer/assets/markdown-BuJfycGS.js +2 -0
  195. package/dist/renderer/assets/mdx-RZdUskPu.js +2 -0
  196. package/dist/renderer/assets/mips-C9m_93PR.js +2 -0
  197. package/dist/renderer/assets/monaco.contribution-B7rUMaEv.js +3 -0
  198. package/dist/renderer/assets/msdax-CpFHC9OI.js +2 -0
  199. package/dist/renderer/assets/mysql-qFvltsqN.js +2 -0
  200. package/dist/renderer/assets/objective-c-Bnmr858J.js +2 -0
  201. package/dist/renderer/assets/pascal-WP0_D5AO.js +2 -0
  202. package/dist/renderer/assets/pascaligo-Blom4Rij.js +2 -0
  203. package/dist/renderer/assets/perl-B-vk8g64.js +2 -0
  204. package/dist/renderer/assets/pgsql-Cgvz6v67.js +2 -0
  205. package/dist/renderer/assets/php-8a3Lrw9m.js +2 -0
  206. package/dist/renderer/assets/pla-DuFqEZ8V.js +2 -0
  207. package/dist/renderer/assets/popover-BOH1If1J.js +2 -0
  208. package/dist/renderer/assets/postiats-DkLtSgkp.js +2 -0
  209. package/dist/renderer/assets/powerquery-BJ1aNepW.js +2 -0
  210. package/dist/renderer/assets/powershell-rE98k687.js +2 -0
  211. package/dist/renderer/assets/protobuf-CUheFacr.js +3 -0
  212. package/dist/renderer/assets/pug-LDcAMD8w.js +2 -0
  213. package/dist/renderer/assets/python-Cobrm_-8.js +2 -0
  214. package/dist/renderer/assets/qsharp-DUKSQoR1.js +2 -0
  215. package/dist/renderer/assets/r-D-QApv87.js +2 -0
  216. package/dist/renderer/assets/razor-BEUIQFNJ.js +2 -0
  217. package/dist/renderer/assets/redis-SXdDyWR9.js +2 -0
  218. package/dist/renderer/assets/redshift-Y6lsCryn.js +2 -0
  219. package/dist/renderer/assets/restructuredtext-edObr9a8.js +2 -0
  220. package/dist/renderer/assets/ruby-CNnUfF-8.js +2 -0
  221. package/dist/renderer/assets/rust-IHUZWzBr.js +2 -0
  222. package/dist/renderer/assets/sb-DrUvY44N.js +2 -0
  223. package/dist/renderer/assets/scala-B4hbXGLM.js +2 -0
  224. package/dist/renderer/assets/scheme-BGrd12j3.js +2 -0
  225. package/dist/renderer/assets/scss-x5G1ES4U.js +4 -0
  226. package/dist/renderer/assets/select-C7JQ8G5N.js +2 -0
  227. package/dist/renderer/assets/settings-DpAbTJyF.js +2 -0
  228. package/dist/renderer/assets/{settings-api-BXCw9vOZ.js → settings-api-RD2IZF53.js} +2 -2
  229. package/dist/renderer/assets/shell-DOehe2Y8.js +2 -0
  230. package/dist/renderer/assets/solidity-BeRvcwWV.js +2 -0
  231. package/dist/renderer/assets/sophia-DZbkUNjy.js +2 -0
  232. package/dist/renderer/assets/sparql-B7_oi5-h.js +2 -0
  233. package/dist/renderer/assets/sql-CTlsFWVE.js +2 -0
  234. package/dist/renderer/assets/st-DJVEJdPE.js +2 -0
  235. package/dist/renderer/assets/swift-CwhT3fYa.js +2 -0
  236. package/dist/renderer/assets/systemverilog-BQN63pkN.js +2 -0
  237. package/dist/renderer/assets/tcl-DqwfpskA.js +2 -0
  238. package/dist/renderer/assets/ts.worker-BwM5Ha3L.js +67720 -0
  239. package/dist/renderer/assets/tsMode-BHa7dl9v.js +12 -0
  240. package/dist/renderer/assets/twig-BiyenUgc.js +2 -0
  241. package/dist/renderer/assets/typescript-15aT0Yj8.js +2 -0
  242. package/dist/renderer/assets/typespec-CWOJribt.js +2 -0
  243. package/dist/renderer/assets/vb-Cq5F87m3.js +2 -0
  244. package/dist/renderer/assets/wgsl-BAvW2lVr.js +299 -0
  245. package/dist/renderer/assets/workbenchSettings-CNJX4Qna.js +8 -0
  246. package/dist/renderer/assets/workers-CRBS0W-v.js +2 -0
  247. package/dist/renderer/assets/xml-bR2Zh-HV.js +2 -0
  248. package/dist/renderer/assets/yaml-Bdk54Qrb.js +2 -0
  249. package/dist/renderer/entries/main/index.html +29 -6
  250. package/dist/renderer/entries/popover/index.html +7 -6
  251. package/dist/renderer/entries/settings/index.html +6 -5
  252. package/dist/renderer/entries/workbench-settings/index.html +6 -5
  253. package/dist/service-host/preload.cjs +254 -0
  254. package/dist/service-host/service.html +10 -0
  255. package/dist/service-host/sourcemap-rewrite.cjs +58 -0
  256. package/dist/service-host/sync-api-patch.js +20 -0
  257. package/dist/service-host/sync-impls/menu-button.js +16 -0
  258. package/dist/service-host/sync-impls/storage.js +50 -0
  259. package/dist/service-host/sync-impls/system-info.js +54 -0
  260. package/dist/shared/appdata-accumulator.d.ts +95 -0
  261. package/dist/shared/appdata-accumulator.js +213 -0
  262. package/dist/shared/bridge-channels.d.ts +364 -0
  263. package/dist/shared/bridge-channels.js +54 -0
  264. package/dist/shared/constants.d.ts +0 -4
  265. package/dist/shared/constants.js +0 -4
  266. package/dist/shared/ipc-channels.d.ts +108 -1
  267. package/dist/shared/ipc-channels.js +127 -10
  268. package/dist/shared/ipc-schemas.d.ts +65 -2
  269. package/dist/shared/ipc-schemas.js +79 -3
  270. package/dist/shared/open-in-editor.d.ts +71 -0
  271. package/dist/shared/open-in-editor.js +138 -0
  272. package/dist/shared/simulator-api-metadata.d.ts +21 -0
  273. package/dist/shared/simulator-api-metadata.js +23 -0
  274. package/dist/shared/types.d.ts +2 -2
  275. package/dist/shared/vpath.d.ts +42 -0
  276. package/dist/shared/vpath.js +105 -0
  277. package/dist/simulator/assets/device-shell-DsdcNEkt.css +1 -0
  278. package/dist/simulator/assets/device-shell-vwYSOVrh.js +2 -0
  279. package/dist/simulator/assets/jsx-runtime-P6ZegaOf.js +2 -0
  280. package/dist/simulator/assets/simulator-DddliUL5.js +10 -0
  281. package/dist/simulator/assets/simulator-mini-app-BDNu5n26.js +2 -0
  282. package/dist/simulator/device-shell/menu-button-geometry.js +8 -0
  283. package/dist/simulator/simulator.html +2 -112
  284. package/package.json +9 -9
  285. package/dist/main/utils/disposable.d.ts +0 -18
  286. package/dist/main/utils/disposable.js +0 -67
  287. package/dist/renderer/assets/constants-DI382mTP.js +0 -2
  288. package/dist/renderer/assets/index-4lkyF644.js +0 -46
  289. package/dist/renderer/assets/input-D4byFOLS.js +0 -2
  290. package/dist/renderer/assets/ipc-transport-DqbRdZNO.css +0 -1
  291. package/dist/renderer/assets/popover-cxKrg_os.js +0 -2
  292. package/dist/renderer/assets/select-BgSkkdHW.js +0 -2
  293. package/dist/renderer/assets/settings-oD2K1jdT.js +0 -2
  294. package/dist/renderer/assets/workbenchSettings-CTNBpTft.js +0 -8
  295. package/dist/simulator/assets/simulator-CVOFTpSj.js +0 -9
@@ -3,16 +3,22 @@
3
3
  // src/preload/shared/expose.ts
4
4
  var import_electron = require("electron");
5
5
  function exposeOnMainWorld(key, value) {
6
- let fellBack = false;
7
- try {
8
- import_electron.contextBridge.exposeInMainWorld(key, value);
9
- } catch {
6
+ let assignedToWindow = false;
7
+ if (process.contextIsolated) {
8
+ try {
9
+ import_electron.contextBridge.exposeInMainWorld(key, value);
10
+ } catch (err) {
11
+ console.warn("[devtools/expose] contextBridge.exposeInMainWorld failed, falling back to direct window assignment:", err);
12
+ window[key] = value;
13
+ assignedToWindow = true;
14
+ }
15
+ } else {
10
16
  ;
11
17
  window[key] = value;
12
- fellBack = true;
18
+ assignedToWindow = true;
13
19
  }
14
20
  return () => {
15
- if (!fellBack) return;
21
+ if (!assignedToWindow) return;
16
22
  const w = window;
17
23
  if (w[key] === value) delete w[key];
18
24
  };
@@ -24,27 +30,9 @@ function getActivePageIframe() {
24
30
  return iframes.length > 0 ? iframes[iframes.length - 1] : null;
25
31
  }
26
32
 
27
- // src/preload/runtime/bridge.ts
28
- var state = {
29
- appdata: { gen: 0, ready: true, data: {} },
30
- storage: { gen: 0, ready: false, namespace: null, data: {} },
31
- wxml: { gen: 0, ready: false, data: null },
32
- refreshHandler: null
33
- };
34
- var highlightOverlay = null;
35
- var exposedApi = null;
33
+ // src/preload/shared/sid-registry.ts
36
34
  var SYNTHETIC_SID_PREFIX = "devtools-";
37
- var syntheticSidByEl = /* @__PURE__ */ new WeakMap();
38
35
  var elBySyntheticSid = /* @__PURE__ */ new Map();
39
- var nextSyntheticSid = 1;
40
- function registerSyntheticSid(el) {
41
- const existing = syntheticSidByEl.get(el);
42
- if (existing) return existing;
43
- const synthetic = `${SYNTHETIC_SID_PREFIX}${nextSyntheticSid++}`;
44
- syntheticSidByEl.set(el, synthetic);
45
- elBySyntheticSid.set(synthetic, new WeakRef(el));
46
- return synthetic;
47
- }
48
36
  function findElementBySid(doc, sid) {
49
37
  if (sid.startsWith(SYNTHETIC_SID_PREFIX)) {
50
38
  const ref = elBySyntheticSid.get(sid);
@@ -59,6 +47,16 @@ function findElementBySid(doc, sid) {
59
47
  }
60
48
  return doc.querySelector(`[data-sid="${CSS.escape(sid)}"]`);
61
49
  }
50
+
51
+ // src/preload/runtime/bridge.ts
52
+ var state = {
53
+ appdata: { gen: 0, ready: true, data: {} },
54
+ storage: { gen: 0, ready: false, namespace: null, data: {} },
55
+ wxml: { gen: 0, ready: false, data: null },
56
+ refreshHandler: null
57
+ };
58
+ var highlightOverlay = null;
59
+ var exposedApi = null;
62
60
  function clone(value) {
63
61
  try {
64
62
  return JSON.parse(JSON.stringify(value));
@@ -145,13 +143,6 @@ function clearStorageSnapshot() {
145
143
  data: {}
146
144
  };
147
145
  }
148
- function setWxmlSnapshot(data, ready = true) {
149
- state.wxml = {
150
- gen: state.wxml.gen + 1,
151
- ready,
152
- data: clone(data)
153
- };
154
- }
155
146
  function clearWxmlSnapshot() {
156
147
  state.wxml = {
157
148
  gen: state.wxml.gen + 1,
@@ -182,20 +173,31 @@ var import_electron2 = require("electron");
182
173
 
183
174
  // src/shared/ipc-channels.ts
184
175
  var SimulatorChannel = {
185
- Attach: "simulator:attach",
176
+ // Ask main to create the simulator as a top-level WebContentsView (so nested
177
+ // render-host <webview>s can attach). Native-host is the sole runtime.
178
+ AttachNative: "simulator:attach-native",
179
+ // Renderer reports the device-bezel inner-screen rect (CSS px from content
180
+ // top-left) + zoom so main can overlay the simulator WCV on it.
181
+ SetNativeBounds: "simulator:set-native-bounds",
182
+ // Renderer pushes the selected device's LOGICAL metrics (screen size,
183
+ // pixelRatio, statusBarHeight, …) when the device dropdown changes. Main
184
+ // maps it to a HostEnvSnapshot and live-updates the running service-host
185
+ // window — the authoritative `wx.getSystemInfoSync()` source — so the
186
+ // mini-app sees the selected device without a relaunch.
187
+ SetDeviceInfo: "simulator:set-device-info",
186
188
  Detach: "simulator:detach",
187
189
  Resize: "simulator:resize",
188
190
  SetVisible: "simulator:setVisible",
189
- Console: "simulator:console"
191
+ Console: "simulator:console",
192
+ // Main → renderer push of the visible top-of-stack page route whenever the
193
+ // mini-app navigates (navigateTo / switchTab / back). Payload: the page path
194
+ // string (same bare format as `getCurrentPagePath`), or '' when unknown.
195
+ CurrentPage: "simulator:current-page"
190
196
  };
191
197
  var SimulatorCustomApiBridgeChannel = {
192
198
  Request: "simulator:custom-apis:bridge-request",
193
199
  Response: "simulator:custom-apis:bridge-response"
194
200
  };
195
- var MiniappSnapshotChannel = {
196
- Push: "miniapp-snapshot:push",
197
- Pull: "miniapp-snapshot:pull"
198
- };
199
201
 
200
202
  // src/preload/runtime/custom-apis.ts
201
203
  var LIST_RETRY_INTERVAL_MS = 150;
@@ -203,6 +205,9 @@ var LIST_RETRY_CEILING_MS = 2500;
203
205
  function buildBridge() {
204
206
  let nextId = 1;
205
207
  const pending = /* @__PURE__ */ new Map();
208
+ const sendRequest = (req) => {
209
+ import_electron2.ipcRenderer.send(SimulatorCustomApiBridgeChannel.Request, req);
210
+ };
206
211
  import_electron2.ipcRenderer.on(SimulatorCustomApiBridgeChannel.Response, (_event, payload) => {
207
212
  const entry = pending.get(payload.id);
208
213
  if (!entry) return;
@@ -219,7 +224,7 @@ function buildBridge() {
219
224
  resolve: (value) => resolve(value),
220
225
  reject
221
226
  });
222
- import_electron2.ipcRenderer.sendToHost(SimulatorCustomApiBridgeChannel.Request, req);
227
+ sendRequest(req);
223
228
  });
224
229
  };
225
230
  const listWithRetry = () => {
@@ -249,7 +254,7 @@ function buildBridge() {
249
254
  reject(reason);
250
255
  }
251
256
  });
252
- import_electron2.ipcRenderer.sendToHost(SimulatorCustomApiBridgeChannel.Request, { id, op: "list" });
257
+ sendRequest({ id, op: "list" });
253
258
  };
254
259
  state2.retryTimer = setInterval(attempt, LIST_RETRY_INTERVAL_MS);
255
260
  state2.ceilingTimer = setTimeout(() => {
@@ -306,18 +311,6 @@ var import_electron4 = require("electron");
306
311
  function sendToHost(channel, data) {
307
312
  import_electron4.ipcRenderer.sendToHost(channel, data);
308
313
  }
309
- function onHostMessage(channel, handler) {
310
- let active = true;
311
- const wrapped = (_event, ...args) => {
312
- if (!active) return;
313
- handler(...args);
314
- };
315
- import_electron4.ipcRenderer.on(channel, wrapped);
316
- return () => {
317
- active = false;
318
- import_electron4.ipcRenderer.removeListener(channel, wrapped);
319
- };
320
- }
321
314
  function safeSerialize(val) {
322
315
  if (val === null || val === void 0) return val;
323
316
  if (typeof val === "function") return `[Function: ${val.name || "anonymous"}]`;
@@ -386,7 +379,7 @@ function installConsoleInstrumentation() {
386
379
  };
387
380
  }
388
381
 
389
- // src/preload/instrumentation/app-data.ts
382
+ // src/shared/appdata-accumulator.ts
390
383
  function decodeWorkerMessage(message) {
391
384
  let payload = message;
392
385
  if (typeof payload === "string") {
@@ -442,25 +435,53 @@ function decodeOutgoingMessage(message) {
442
435
  bridgeId: typeof r.body?.bridgeId === "string" ? r.body.bridgeId : void 0
443
436
  };
444
437
  }
445
- function createAppDataSource() {
446
- const appDataCache = /* @__PURE__ */ new Map();
447
- const bridgeOrder = [];
448
- const bridgePagePath = /* @__PURE__ */ new Map();
449
- let emit = null;
450
- let installed = false;
451
- let originalHook;
452
- let originalDescriptor;
453
- let OriginalWorker;
454
- function recordBridge(bridgeId) {
455
- if (!bridgeOrder.includes(bridgeId)) bridgeOrder.push(bridgeId);
438
+ var AppDataAccumulator = class {
439
+ cache = /* @__PURE__ */ new Map();
440
+ // Bridges in insertion order — drives the `bridges` array (stable tab order).
441
+ bridgeOrder = [];
442
+ // Page path per bridge: set from `page_*` init's body.path (the page route).
443
+ bridgePagePath = /* @__PURE__ */ new Map();
444
+ recordBridge(bridgeId) {
445
+ if (!this.bridgeOrder.includes(bridgeId)) this.bridgeOrder.push(bridgeId);
446
+ }
447
+ /**
448
+ * Apply one entry. Returns true if it was accepted (a mutation worth
449
+ * republishing), false if dropped (missing ids, or the R6 gate).
450
+ */
451
+ apply(input) {
452
+ if (!input.bridgeId || !input.moduleId) return false;
453
+ if (input.mode !== "init" && !this.bridgePagePath.has(input.bridgeId)) return false;
454
+ const key = `${input.bridgeId}/${input.moduleId}`;
455
+ const prev = this.cache.get(key);
456
+ const incoming = input.data && typeof input.data === "object" ? input.data : {};
457
+ const merged = input.mode === "init" ? { ...incoming } : { ...prev?.data ?? {}, ...incoming };
458
+ const componentPath = input.componentPath ?? prev?.componentPath;
459
+ const next = componentPath !== void 0 ? { componentPath, data: merged } : { data: merged };
460
+ this.cache.set(key, next);
461
+ this.recordBridge(input.bridgeId);
462
+ if (input.mode === "init" && input.moduleId.startsWith("page_") && input.componentPath) {
463
+ this.bridgePagePath.set(input.bridgeId, input.componentPath);
464
+ }
465
+ return true;
456
466
  }
457
- function buildSnapshot() {
467
+ /** Evict every entry for a bridge (page teardown). */
468
+ clearBridge(bridgeId) {
469
+ const prefix = `${bridgeId}/`;
470
+ for (const key of [...this.cache.keys()]) {
471
+ if (key.startsWith(prefix)) this.cache.delete(key);
472
+ }
473
+ const idx = this.bridgeOrder.indexOf(bridgeId);
474
+ if (idx >= 0) this.bridgeOrder.splice(idx, 1);
475
+ this.bridgePagePath.delete(bridgeId);
476
+ }
477
+ /** The full cumulative snapshot for the panel. */
478
+ snapshot() {
458
479
  const bridges = [];
459
- for (const id of bridgeOrder) {
460
- bridges.push({ id, pagePath: bridgePagePath.get(id) ?? null });
480
+ for (const id of this.bridgeOrder) {
481
+ bridges.push({ id, pagePath: this.bridgePagePath.get(id) ?? null });
461
482
  }
462
483
  const entries = {};
463
- for (const [key, entry] of appDataCache) {
484
+ for (const [key, entry] of this.cache) {
464
485
  const slash = key.indexOf("/");
465
486
  if (slash < 0) continue;
466
487
  const bridgeId = key.slice(0, slash);
@@ -471,39 +492,53 @@ function createAppDataSource() {
471
492
  }
472
493
  return { bridges, entries };
473
494
  }
474
- function publishSnapshot() {
475
- const data = {};
476
- for (const [key, entry] of appDataCache) {
477
- data[key] = entry.data;
495
+ /**
496
+ * The current reactive page state for a bridge: shallow-merge of `entry.data`
497
+ * across every cache entry whose key starts with `${bridgeId}/`, in insertion
498
+ * order (later entries win on key conflicts). `{}` when no entries match
499
+ * (unknown bridge / after clearBridge). Pure, no side effects.
500
+ */
501
+ pageData(bridgeId) {
502
+ const merged = {};
503
+ for (const [key, entry] of this.cache) {
504
+ const slash = key.indexOf("/");
505
+ if (slash < 0) continue;
506
+ if (key.slice(0, slash) !== bridgeId) continue;
507
+ Object.assign(merged, entry.data);
478
508
  }
479
- setAppDataSnapshot(data);
509
+ return merged;
510
+ }
511
+ /** Flat `key → data` map for the `__simulatorData.getAppdata()` mirror. */
512
+ flat() {
513
+ const data = {};
514
+ for (const [key, entry] of this.cache) data[key] = entry.data;
515
+ return data;
516
+ }
517
+ clear() {
518
+ this.cache.clear();
519
+ this.bridgeOrder.length = 0;
520
+ this.bridgePagePath.clear();
521
+ }
522
+ };
523
+
524
+ // src/preload/instrumentation/app-data.ts
525
+ function createAppDataSource() {
526
+ const accumulator = new AppDataAccumulator();
527
+ let emit = null;
528
+ let installed = false;
529
+ let originalHook;
530
+ let originalDescriptor;
531
+ let OriginalWorker;
532
+ function publishSnapshot() {
533
+ setAppDataSnapshot(accumulator.flat());
480
534
  }
481
535
  function clearBridge(bridgeId) {
482
- const prefix = `${bridgeId}/`;
483
- for (const key of [...appDataCache.keys()]) {
484
- if (key.startsWith(prefix)) appDataCache.delete(key);
485
- }
486
- const idx = bridgeOrder.indexOf(bridgeId);
487
- if (idx >= 0) bridgeOrder.splice(idx, 1);
488
- bridgePagePath.delete(bridgeId);
536
+ accumulator.clearBridge(bridgeId);
489
537
  publishSnapshot();
490
538
  emit?.();
491
539
  }
492
540
  function applyAppData(body) {
493
- const record = body;
494
- if (!record?.bridgeId || !record?.moduleId) return;
495
- if (record.mode !== "init" && !bridgePagePath.has(record.bridgeId)) return;
496
- const key = `${record.bridgeId}/${record.moduleId}`;
497
- const prev = appDataCache.get(key);
498
- const incoming = record.data && typeof record.data === "object" ? record.data : {};
499
- const merged = record.mode === "init" ? { ...incoming } : { ...prev?.data ?? {}, ...incoming };
500
- const componentPath = record.componentPath ?? prev?.componentPath;
501
- const next = componentPath !== void 0 ? { componentPath, data: merged } : { data: merged };
502
- appDataCache.set(key, next);
503
- recordBridge(record.bridgeId);
504
- if (record.mode === "init" && record.moduleId.startsWith("page_") && record.componentPath) {
505
- bridgePagePath.set(record.bridgeId, record.componentPath);
506
- }
541
+ if (!accumulator.apply(body)) return;
507
542
  publishSnapshot();
508
543
  emit?.();
509
544
  }
@@ -550,7 +585,7 @@ function createAppDataSource() {
550
585
  }
551
586
  return {
552
587
  id: "appdata",
553
- snapshot: () => buildSnapshot(),
588
+ snapshot: () => accumulator.snapshot(),
554
589
  start(onChange) {
555
590
  if (installed) return;
556
591
  installed = true;
@@ -583,486 +618,13 @@ function createAppDataSource() {
583
618
  originalDescriptor = void 0;
584
619
  OriginalWorker = void 0;
585
620
  originalHook = void 0;
586
- appDataCache.clear();
587
- bridgeOrder.length = 0;
588
- bridgePagePath.clear();
621
+ accumulator.clear();
589
622
  clearAppDataSnapshot();
590
623
  emit = null;
591
624
  }
592
625
  };
593
626
  }
594
627
 
595
- // src/preload/shared/constants.ts
596
- var WXML_DEBOUNCE_MS = 300;
597
- var WXML_RETRY_INTERVAL_MS = 500;
598
- var WXML_RETRY_TIMEOUT_MS = 1e4;
599
- var NAVIGATION_POLL_INTERVAL_MS = 200;
600
- var NAVIGATION_TIMEOUT_MS = 1e4;
601
-
602
- // src/preload/instrumentation/wxml-extract.ts
603
- var INTERNAL_CLASSES = /* @__PURE__ */ new Set([
604
- "dd-swiper-wrapper",
605
- "dd-swiper-slides",
606
- "dd-swiper-slide-frame",
607
- "dd-swiper-dots",
608
- "dd-picker-overlay",
609
- "dd-picker-container",
610
- "dd-picker-header",
611
- "dd-picker-body"
612
- ]);
613
- var FRAMEWORK_TEMPLATE_RE = /^(taro_tmpl|tmpl_\d+)/;
614
- function resolveTemplateNameFromParent(instance) {
615
- const parent = instance.parent;
616
- if (!parent) return null;
617
- const parentType = parent.type;
618
- const components = parentType?.components;
619
- if (components) {
620
- for (const [regName, comp] of Object.entries(components)) {
621
- if (comp === instance.type) return regName.startsWith("dd-") ? regName.slice(3) : regName;
622
- }
623
- }
624
- const appComponents = instance.appContext?.components;
625
- if (!appComponents) return null;
626
- for (const [regName, comp] of Object.entries(appComponents)) {
627
- if (comp === instance.type) return regName.startsWith("dd-") ? regName.slice(3) : regName;
628
- }
629
- return null;
630
- }
631
- function pascalToKebab(name) {
632
- return name.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
633
- }
634
- function resolvePagePath(instance) {
635
- const proxy = instance.proxy;
636
- if (proxy?.__page__ !== true) return null;
637
- const provides = instance.provides;
638
- const path = provides?.path;
639
- if (typeof path !== "string" || !path) return null;
640
- return path.startsWith("/") ? path.slice(1) : path;
641
- }
642
- function resolveTagName(instance) {
643
- const type = instance.type;
644
- if (!type) return "unknown";
645
- const pagePath = resolvePagePath(instance);
646
- if (pagePath) return pagePath;
647
- if (typeof type.__tagName === "string") return type.__tagName;
648
- const name = type.__name || type.name;
649
- if (!name) {
650
- if (type.__scopeId && type.components) return "page";
651
- if (type.__scopeId) return resolveTemplateNameFromParent(instance) || "template";
652
- return "unknown";
653
- }
654
- if (name === "dd-page") return "page";
655
- if (name.startsWith("dd-")) return name.slice(3);
656
- if (name.startsWith("Dd") && name.length > 2) return pascalToKebab(name.slice(2));
657
- if (/^[A-Z]/.test(name)) return pascalToKebab(name);
658
- return name;
659
- }
660
- function extractProps(instance) {
661
- const out = {};
662
- for (const raw of [instance.props, instance.attrs]) {
663
- if (!raw) continue;
664
- for (const [k, v] of Object.entries(raw)) {
665
- if (typeof v === "function" || v === void 0) continue;
666
- if (k === "data" || k.startsWith("__")) continue;
667
- if (typeof v === "boolean" && !v) continue;
668
- if (k === "class" && typeof v === "string") {
669
- const cleaned = v.split(/\s+/).filter((c) => !c.startsWith("dd-")).join(" ");
670
- if (cleaned) out[k] = cleaned;
671
- continue;
672
- }
673
- out[k] = typeof v === "object" ? JSON.stringify(v) : String(v);
674
- }
675
- }
676
- return out;
677
- }
678
- function isInternalElement(vnode) {
679
- const props = vnode.props;
680
- if (!props) return false;
681
- const cls = String(props.class || "");
682
- return cls.split(/\s+/).some((c) => INTERNAL_CLASSES.has(c));
683
- }
684
- function getElementSid(instance) {
685
- const subTree = instance.subTree;
686
- const el = subTree?.el;
687
- if (!el?.getAttribute) return void 0;
688
- const sid = el.getAttribute("data-sid");
689
- if (sid) return sid;
690
- return registerSyntheticSid(el);
691
- }
692
- function isTransparentComponent(instance, tagName) {
693
- if (tagName === "unknown") return true;
694
- if (tagName === "template") {
695
- const props = instance.props;
696
- const is = props?.is;
697
- if (is && FRAMEWORK_TEMPLATE_RE.test(is)) return true;
698
- if (!is) {
699
- const type = instance.type;
700
- if (type?.__scopeId && !type.components) return true;
701
- }
702
- }
703
- return false;
704
- }
705
- function isCommentVNode(vnode) {
706
- const type = vnode.type;
707
- if (typeof type !== "symbol") return false;
708
- const desc = type.description;
709
- if (desc === "Comment" || desc === "v-cmt") return true;
710
- const children = typeof vnode.children === "string" ? vnode.children : "";
711
- return /^v-(if|else|else-if|for)$/.test(children);
712
- }
713
- function extractChildrenFromVNode(vnode, depth) {
714
- if (!vnode || depth > 50) return [];
715
- if (isCommentVNode(vnode)) return [];
716
- if (vnode.component) {
717
- const result2 = walkInstance(vnode.component, depth + 1);
718
- return result2 ? Array.isArray(result2) ? result2 : [result2] : [];
719
- }
720
- if (vnode.suspense) {
721
- const suspense = vnode.suspense;
722
- const activeBranch = suspense.activeBranch;
723
- return activeBranch ? extractChildrenFromVNode(activeBranch, depth + 1) : [];
724
- }
725
- if (typeof vnode.children === "string" && vnode.children.trim()) {
726
- const vnodeType = vnode.type;
727
- if (typeof vnodeType === "symbol" || typeof vnodeType === "string") {
728
- return [{ tagName: "#text", attrs: {}, children: [], text: vnode.children.trim() }];
729
- }
730
- }
731
- const kids = vnode.children;
732
- if (!Array.isArray(kids)) return [];
733
- const result = [];
734
- for (const child of kids) {
735
- if (!child) continue;
736
- if (typeof child === "string") {
737
- const trimmed = child.trim();
738
- if (trimmed) result.push({ tagName: "#text", attrs: {}, children: [], text: trimmed });
739
- continue;
740
- }
741
- if (typeof child !== "object") continue;
742
- const c = child;
743
- if (c.component) {
744
- const walked = walkInstance(c.component, depth + 1);
745
- if (walked) result.push(...Array.isArray(walked) ? walked : [walked]);
746
- continue;
747
- }
748
- if (typeof c.type === "symbol") {
749
- result.push(...extractChildrenFromVNode(c, depth + 1));
750
- continue;
751
- }
752
- if (typeof c.type === "string") {
753
- if (isInternalElement(c)) {
754
- result.push(...extractChildrenFromVNode(c, depth + 1));
755
- } else if (typeof c.children === "string" && c.children.trim()) {
756
- result.push({ tagName: "#text", attrs: {}, children: [], text: c.children.trim() });
757
- } else {
758
- result.push(...extractChildrenFromVNode(c, depth + 1));
759
- }
760
- continue;
761
- }
762
- result.push(...extractChildrenFromVNode(c, depth + 1));
763
- }
764
- return result;
765
- }
766
- function unwrapCustomComponent(node) {
767
- if (node.tagName !== "wrapper") return node;
768
- const path = node.attrs?.name;
769
- if (typeof path !== "string" || !path.startsWith("/")) return node;
770
- const stripped = path.replace(/^\//, "");
771
- const withoutIndex = stripped.endsWith("/index") ? stripped.slice(0, -"/index".length) : stripped;
772
- const recovered = withoutIndex || stripped;
773
- if (!recovered || recovered === "index") return node;
774
- const nextAttrs = {};
775
- for (const [k, v] of Object.entries(node.attrs)) {
776
- if (k === "name") continue;
777
- nextAttrs[k] = v;
778
- }
779
- return { ...node, tagName: recovered, attrs: nextAttrs };
780
- }
781
- function wrapInShadowRoot(node) {
782
- if (!node.tagName.includes("/")) return node;
783
- if (node.children.length === 0) return node;
784
- if (node.children[0]?.tagName === "#shadow-root") return node;
785
- return {
786
- ...node,
787
- children: [{ tagName: "#shadow-root", attrs: {}, children: node.children }]
788
- };
789
- }
790
- function walkInstance(instance, depth) {
791
- if (depth > 50) return null;
792
- const tagName = resolveTagName(instance);
793
- const children = extractChildrenFromVNode(instance.subTree, depth);
794
- if (isTransparentComponent(instance, tagName)) return children.length > 0 ? children : null;
795
- const node = { tagName, attrs: extractProps(instance), children };
796
- const sid = getElementSid(instance);
797
- if (sid) node.sid = sid;
798
- return wrapInShadowRoot(unwrapCustomComponent(node));
799
- }
800
-
801
- // src/preload/instrumentation/wxml.ts
802
- function getVueAppFromIframe(iframe) {
803
- try {
804
- const doc = iframe.contentDocument;
805
- if (!doc?.body) return null;
806
- const body = doc.body;
807
- const app = body.__vue_app__;
808
- if (!app) return null;
809
- if (app._instance) return app._instance;
810
- const container = app._container;
811
- const vnode = container?._vnode;
812
- return vnode?.component ?? null;
813
- } catch {
814
- return null;
815
- }
816
- }
817
- function computeWxmlTree() {
818
- const iframe = getActivePageIframe();
819
- if (!iframe) return null;
820
- const instance = getVueAppFromIframe(iframe);
821
- if (!instance) return null;
822
- const tree = walkInstance(instance, 0);
823
- if (!tree) return null;
824
- return Array.isArray(tree) ? { tagName: "#fragment", attrs: {}, children: tree } : tree;
825
- }
826
- function createWxmlSource() {
827
- let tree = null;
828
- let emit = null;
829
- let wxmlTimer;
830
- let currentObserver = null;
831
- let currentIframe = null;
832
- let topObserver = null;
833
- let retryTimer;
834
- let retryTimeout;
835
- let navigationWaitTimer;
836
- let navigationWaitTimeout;
837
- function clearTimers() {
838
- if (wxmlTimer) clearTimeout(wxmlTimer);
839
- if (retryTimer) clearInterval(retryTimer);
840
- if (retryTimeout) clearTimeout(retryTimeout);
841
- if (navigationWaitTimer) clearInterval(navigationWaitTimer);
842
- if (navigationWaitTimeout) clearTimeout(navigationWaitTimeout);
843
- wxmlTimer = void 0;
844
- retryTimer = void 0;
845
- retryTimeout = void 0;
846
- navigationWaitTimer = void 0;
847
- navigationWaitTimeout = void 0;
848
- }
849
- function refresh() {
850
- tree = computeWxmlTree();
851
- if (tree) {
852
- setWxmlSnapshot(tree, true);
853
- } else {
854
- clearWxmlSnapshot();
855
- unhighlightElement();
856
- }
857
- emit?.();
858
- }
859
- function observeIframe(iframe) {
860
- if (iframe === currentIframe) return;
861
- if (currentObserver) {
862
- currentObserver.disconnect();
863
- currentObserver = null;
864
- }
865
- if (navigationWaitTimer) {
866
- clearInterval(navigationWaitTimer);
867
- navigationWaitTimer = void 0;
868
- }
869
- if (navigationWaitTimeout) {
870
- clearTimeout(navigationWaitTimeout);
871
- navigationWaitTimeout = void 0;
872
- }
873
- currentIframe = iframe;
874
- const doc = iframe.contentDocument;
875
- if (!doc?.body) {
876
- refresh();
877
- return;
878
- }
879
- refresh();
880
- currentObserver = new MutationObserver(() => {
881
- clearTimeout(wxmlTimer);
882
- wxmlTimer = setTimeout(refresh, WXML_DEBOUNCE_MS);
883
- });
884
- currentObserver.observe(doc.body, { childList: true, subtree: true });
885
- }
886
- function tryAttach() {
887
- const iframe = getActivePageIframe();
888
- if (!iframe) return false;
889
- const instance = getVueAppFromIframe(iframe);
890
- if (!instance) return false;
891
- observeIframe(iframe);
892
- return true;
893
- }
894
- function scheduleAttach() {
895
- if (retryTimer) clearInterval(retryTimer);
896
- if (retryTimeout) clearTimeout(retryTimeout);
897
- retryTimer = setInterval(() => {
898
- if (tryAttach() && retryTimer) {
899
- clearInterval(retryTimer);
900
- retryTimer = void 0;
901
- }
902
- }, WXML_RETRY_INTERVAL_MS);
903
- retryTimeout = setTimeout(() => {
904
- if (retryTimer) clearInterval(retryTimer);
905
- retryTimer = void 0;
906
- }, WXML_RETRY_TIMEOUT_MS);
907
- }
908
- function observeTopLevel() {
909
- if (topObserver) return;
910
- topObserver = new MutationObserver(() => {
911
- const iframe = getActivePageIframe();
912
- if (!iframe) {
913
- refresh();
914
- return;
915
- }
916
- if (iframe !== currentIframe) {
917
- if (navigationWaitTimer) {
918
- clearInterval(navigationWaitTimer);
919
- navigationWaitTimer = void 0;
920
- }
921
- if (navigationWaitTimeout) {
922
- clearTimeout(navigationWaitTimeout);
923
- navigationWaitTimeout = void 0;
924
- }
925
- navigationWaitTimer = setInterval(() => {
926
- if (getVueAppFromIframe(iframe)) {
927
- if (navigationWaitTimer) {
928
- clearInterval(navigationWaitTimer);
929
- navigationWaitTimer = void 0;
930
- }
931
- if (navigationWaitTimeout) {
932
- clearTimeout(navigationWaitTimeout);
933
- navigationWaitTimeout = void 0;
934
- }
935
- observeIframe(iframe);
936
- }
937
- }, NAVIGATION_POLL_INTERVAL_MS);
938
- navigationWaitTimeout = setTimeout(() => {
939
- if (navigationWaitTimer) {
940
- clearInterval(navigationWaitTimer);
941
- navigationWaitTimer = void 0;
942
- }
943
- navigationWaitTimeout = void 0;
944
- }, NAVIGATION_TIMEOUT_MS);
945
- }
946
- });
947
- if (document.body) {
948
- topObserver.observe(document.body, { childList: true, subtree: true });
949
- } else {
950
- document.addEventListener("DOMContentLoaded", () => {
951
- if (document.body && topObserver) {
952
- topObserver.observe(document.body, { childList: true, subtree: true });
953
- }
954
- }, { once: true });
955
- }
956
- }
957
- return {
958
- id: "wxml",
959
- snapshot: () => tree,
960
- start(onChange) {
961
- emit = onChange;
962
- if (!tryAttach()) {
963
- scheduleAttach();
964
- }
965
- observeTopLevel();
966
- },
967
- dispose() {
968
- if (currentObserver) {
969
- currentObserver.disconnect();
970
- currentObserver = null;
971
- }
972
- if (topObserver) {
973
- topObserver.disconnect();
974
- topObserver = null;
975
- }
976
- currentIframe = null;
977
- clearTimers();
978
- clearWxmlSnapshot();
979
- unhighlightElement();
980
- tree = null;
981
- emit = null;
982
- }
983
- };
984
- }
985
-
986
- // src/preload/miniapp-snapshot/host.ts
987
- var import_electron5 = require("electron");
988
- var ACCESSOR_KEY = "__miniappSnapshot";
989
- function exposeApi(api) {
990
- try {
991
- import_electron5.contextBridge.exposeInMainWorld(ACCESSOR_KEY, api);
992
- } catch {
993
- ;
994
- window.__miniappSnapshot = api;
995
- }
996
- return () => {
997
- const windowRef = window;
998
- if (windowRef[ACCESSOR_KEY] === api) {
999
- delete windowRef[ACCESSOR_KEY];
1000
- }
1001
- };
1002
- }
1003
- function createMiniappSnapshotHost() {
1004
- const sources = [];
1005
- const byId = /* @__PURE__ */ new Map();
1006
- let installed = false;
1007
- let disposed = false;
1008
- let seq = 0;
1009
- function publish(source) {
1010
- if (disposed) return;
1011
- seq += 1;
1012
- const envelope = {
1013
- id: source.id,
1014
- seq,
1015
- ts: Date.now(),
1016
- data: source.snapshot()
1017
- };
1018
- sendToHost(MiniappSnapshotChannel.Push, envelope);
1019
- }
1020
- function register(source) {
1021
- if (installed) {
1022
- throw new Error("MiniappSnapshotHost: register() called after install()");
1023
- }
1024
- if (byId.has(source.id)) {
1025
- throw new Error(`MiniappSnapshotHost: duplicate source id "${source.id}"`);
1026
- }
1027
- const erased = source;
1028
- byId.set(source.id, erased);
1029
- sources.push(erased);
1030
- }
1031
- function install() {
1032
- if (installed) {
1033
- throw new Error("MiniappSnapshotHost: install() called twice");
1034
- }
1035
- installed = true;
1036
- for (const source of sources) {
1037
- source.start(() => publish(source));
1038
- publish(source);
1039
- }
1040
- const disposePull = onHostMessage(MiniappSnapshotChannel.Pull, (...args) => {
1041
- const payload = args[0];
1042
- const id = payload?.id;
1043
- if (typeof id !== "string") return;
1044
- const source = byId.get(id);
1045
- if (!source) return;
1046
- publish(source);
1047
- });
1048
- const api = {
1049
- get: (id) => byId.get(id)?.snapshot(),
1050
- ids: () => sources.map((source) => source.id)
1051
- };
1052
- const disposeApi = exposeApi(api);
1053
- return () => {
1054
- if (disposed) return;
1055
- disposed = true;
1056
- disposePull();
1057
- disposeApi();
1058
- for (const source of sources) {
1059
- source.dispose();
1060
- }
1061
- };
1062
- }
1063
- return { register, install };
1064
- }
1065
-
1066
628
  // src/preload/shared/api-compat.ts
1067
629
  function call(fn, payload) {
1068
630
  try {
@@ -1242,14 +804,122 @@ function setupApiCompatHook() {
1242
804
  }, 200);
1243
805
  }
1244
806
 
807
+ // src/preload/runtime/native-host.ts
808
+ var import_electron5 = require("electron");
809
+
810
+ // src/shared/bridge-channels.ts
811
+ var BRIDGE_CHANNELS = {
812
+ SPAWN: "dmb:spawn",
813
+ DISPOSE: "dmb:dispose",
814
+ PAGE_OPEN: "dmb:page:open",
815
+ PAGE_CLOSE: "dmb:page:close",
816
+ PAGE_LIFECYCLE: "dmb:page:lifecycle",
817
+ NAV_CALLBACK: "dmb:nav:callback",
818
+ SERVICE_INVOKE: "dmb:service:invoke",
819
+ SERVICE_PUBLISH: "dmb:service:publish",
820
+ RENDER_INVOKE: "dmb:render:invoke",
821
+ RENDER_PUBLISH: "dmb:render:publish",
822
+ TO_SERVICE: "dmb:to-service",
823
+ TO_RENDER: "dmb:to-render",
824
+ SIMULATOR_API: "dmb:simulator-api",
825
+ /** simulator → main: ack of an API_CALL request (carries success/fail args). */
826
+ API_RESPONSE: "dmb:api:response",
827
+ /**
828
+ * simulator webview preload → main (sendSync): "is native-host mode on?".
829
+ * The guest preload can't read the launch `process.env`, so it asks main
830
+ * (which can) at install time. Reply is `e.returnValue = boolean`.
831
+ */
832
+ NATIVE_HOST_ENABLED: "dmb:native-host-enabled",
833
+ /**
834
+ * simulator (DeviceShell) → main: the visible top-of-stack page bridgeId.
835
+ * Main has no z-order concept — the active page lives only in DeviceShell's
836
+ * ShellState — so devtools panels / automation that must target "the current
837
+ * page's render webContents" resolve it through this signal. Fire-and-forget.
838
+ */
839
+ ACTIVE_PAGE: "dmb:active-page",
840
+ /**
841
+ * simulator (DeviceShell) → main: the FULL ordered page stack (bottom→top)
842
+ * whenever it changes. Main has no stack of its own (it only learns the
843
+ * active bridgeId via ACTIVE_PAGE), so automation's `App.getPageStack` needs
844
+ * this to report multi-page stacks. Fire-and-forget.
845
+ */
846
+ PAGE_STACK: "dmb:page-stack"
847
+ };
848
+
849
+ // src/preload/runtime/native-host.ts
850
+ function queryNativeHostConfig() {
851
+ try {
852
+ const res = import_electron5.ipcRenderer.sendSync(BRIDGE_CHANNELS.NATIVE_HOST_ENABLED);
853
+ return res && res.enabled ? res : null;
854
+ } catch {
855
+ return null;
856
+ }
857
+ }
858
+ function buildBridge2(cfg) {
859
+ return {
860
+ enabled: true,
861
+ spawn(opts) {
862
+ return import_electron5.ipcRenderer.invoke(BRIDGE_CHANNELS.SPAWN, opts);
863
+ },
864
+ dispose(bridgeId) {
865
+ const payload = { bridgeId };
866
+ import_electron5.ipcRenderer.send(BRIDGE_CHANNELS.DISPOSE, payload);
867
+ },
868
+ openPage(opts) {
869
+ return import_electron5.ipcRenderer.invoke(BRIDGE_CHANNELS.PAGE_OPEN, opts);
870
+ },
871
+ closePage(bridgeId) {
872
+ const payload = { bridgeId };
873
+ import_electron5.ipcRenderer.send(BRIDGE_CHANNELS.PAGE_CLOSE, payload);
874
+ },
875
+ notifyLifecycle(payload) {
876
+ import_electron5.ipcRenderer.send(BRIDGE_CHANNELS.PAGE_LIFECYCLE, payload);
877
+ },
878
+ notifyNavCallback(payload) {
879
+ import_electron5.ipcRenderer.send(BRIDGE_CHANNELS.NAV_CALLBACK, payload);
880
+ },
881
+ notifyApiResponse(payload) {
882
+ import_electron5.ipcRenderer.send(BRIDGE_CHANNELS.API_RESPONSE, payload);
883
+ },
884
+ notifyActivePage(payload) {
885
+ import_electron5.ipcRenderer.send(BRIDGE_CHANNELS.ACTIVE_PAGE, payload);
886
+ },
887
+ notifyPageStack(payload) {
888
+ import_electron5.ipcRenderer.send(BRIDGE_CHANNELS.PAGE_STACK, payload);
889
+ },
890
+ createRenderHostUrl(opts) {
891
+ const url = new URL(cfg.renderHostHtmlUrl);
892
+ url.searchParams.set("bridgeId", opts.bridgeId);
893
+ url.searchParams.set("appId", opts.appId);
894
+ url.searchParams.set("pagePath", opts.pagePath);
895
+ return url.toString();
896
+ },
897
+ renderPreloadUrl: cfg.renderPreloadUrl,
898
+ device: cfg.device,
899
+ onSimulatorEvent(channel, listener) {
900
+ const wrapped = (_event, payload) => {
901
+ ;
902
+ listener(payload);
903
+ };
904
+ import_electron5.ipcRenderer.on(channel, wrapped);
905
+ return () => import_electron5.ipcRenderer.removeListener(channel, wrapped);
906
+ }
907
+ };
908
+ }
909
+ function installNativeHostBridge() {
910
+ const cfg = queryNativeHostConfig();
911
+ if (!cfg) return () => {
912
+ };
913
+ return exposeOnMainWorld("__diminaNativeHost", buildBridge2(cfg));
914
+ }
915
+
1245
916
  // src/preload/windows/simulator.ts
1246
917
  setupApiCompatHook();
1247
918
  installSimulatorBridge();
1248
919
  installCustomApisBridge();
1249
920
  installTempFileBridge();
1250
921
  installConsoleInstrumentation();
1251
- var snapshotHost = createMiniappSnapshotHost();
1252
- snapshotHost.register(createAppDataSource());
1253
- snapshotHost.register(createWxmlSource());
1254
- snapshotHost.install();
922
+ installNativeHostBridge();
923
+ createAppDataSource().start(() => {
924
+ });
1255
925
  //# sourceMappingURL=simulator.js.map