@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.
- package/README.md +43 -40
- package/dist/main/api.d.ts +0 -1
- package/dist/main/api.js +5 -1
- package/dist/main/app/app.d.ts +15 -5
- package/dist/main/app/app.js +247 -110
- package/dist/main/app/bootstrap.d.ts +16 -0
- package/dist/main/app/bootstrap.js +20 -0
- package/dist/main/app/launch.d.ts +8 -4
- package/dist/main/app/launch.js +9 -4
- package/dist/main/index.bundle.js +6607 -2102
- package/dist/main/index.js +9 -1
- package/dist/main/ipc/app.d.ts +1 -1
- package/dist/main/ipc/bridge-router.d.ts +61 -0
- package/dist/main/ipc/bridge-router.js +1300 -0
- package/dist/main/ipc/panels.d.ts +1 -1
- package/dist/main/ipc/panels.js +6 -2
- package/dist/main/ipc/popover.d.ts +1 -1
- package/dist/main/ipc/project-fs.d.ts +57 -0
- package/dist/main/ipc/project-fs.js +448 -0
- package/dist/main/ipc/projects.d.ts +1 -1
- package/dist/main/ipc/session.d.ts +1 -1
- package/dist/main/ipc/settings.d.ts +1 -1
- package/dist/main/ipc/simulator-module.d.ts +6 -0
- package/dist/main/ipc/simulator-module.js +11 -1
- package/dist/main/ipc/simulator.d.ts +2 -2
- package/dist/main/ipc/simulator.js +49 -5
- package/dist/main/ipc/toolbar.d.ts +1 -1
- package/dist/main/ipc/views.d.ts +19 -0
- package/dist/main/ipc/views.js +65 -0
- package/dist/main/runtime/devtools-backend.d.ts +17 -0
- package/dist/main/runtime/devtools-backend.js +49 -0
- package/dist/main/runtime/miniapp-runtime.d.ts +39 -0
- package/dist/main/runtime/miniapp-runtime.js +17 -0
- package/dist/main/services/automation/exec.d.ts +27 -2
- package/dist/main/services/automation/exec.js +37 -3
- package/dist/main/services/automation/handlers/app.js +127 -11
- package/dist/main/services/automation/handlers/page.js +36 -19
- package/dist/main/services/automation/index.js +40 -13
- package/dist/main/services/automation/wait-active-page.d.ts +56 -0
- package/dist/main/services/automation/wait-active-page.js +71 -0
- package/dist/main/services/console-forward/index.d.ts +36 -0
- package/dist/main/services/console-forward/index.js +81 -0
- package/dist/main/services/dimina-resource-server.d.ts +7 -0
- package/dist/main/services/dimina-resource-server.js +99 -0
- package/dist/main/services/elements-forward/index.d.ts +66 -0
- package/dist/main/services/elements-forward/index.js +583 -0
- package/dist/main/services/layout/index.d.ts +23 -1
- package/dist/main/services/layout/index.js +28 -3
- package/dist/main/services/mcp/index.d.ts +1 -0
- package/dist/main/services/mcp/index.js +3 -0
- package/dist/main/services/mcp/server.d.ts +1 -1
- package/dist/main/services/mcp/server.js +1 -1
- package/dist/main/services/mcp/target-manager.d.ts +35 -0
- package/dist/main/services/mcp/target-manager.js +63 -1
- package/dist/main/services/mcp/tools/context-tools.js +15 -1
- package/dist/main/services/module.d.ts +1 -1
- package/dist/main/services/network-forward/index.d.ts +190 -0
- package/dist/main/services/network-forward/index.js +765 -0
- package/dist/main/services/notifications/renderer-notifier.d.ts +11 -0
- package/dist/main/services/notifications/renderer-notifier.js +7 -1
- package/dist/main/services/render-inspect/index.d.ts +41 -0
- package/dist/main/services/render-inspect/index.js +88 -0
- package/dist/main/services/safe-area/index.d.ts +17 -0
- package/dist/main/services/safe-area/index.js +59 -0
- package/dist/main/services/service-host-pool/pool.d.ts +197 -0
- package/dist/main/services/service-host-pool/pool.js +364 -0
- package/dist/main/services/simulator/custom-apis.d.ts +34 -0
- package/dist/main/services/simulator/custom-apis.js +22 -0
- package/dist/main/services/simulator-appdata/index.d.ts +35 -0
- package/dist/main/services/simulator-appdata/index.js +71 -0
- package/dist/main/services/simulator-current-page/index.d.ts +24 -0
- package/dist/main/services/simulator-current-page/index.js +19 -0
- package/dist/main/services/simulator-storage/index.d.ts +37 -2
- package/dist/main/services/simulator-storage/index.js +209 -32
- package/dist/main/services/simulator-storage/service-storage-ops.d.ts +40 -0
- package/dist/main/services/simulator-storage/service-storage-ops.js +67 -0
- package/dist/main/services/simulator-temp-files/fs-channels.js +1 -1
- package/dist/main/services/simulator-temp-files/index.d.ts +1 -1
- package/dist/main/services/simulator-temp-files/index.js +1 -1
- package/dist/main/services/simulator-temp-files/request-handler.js +1 -1
- package/dist/main/services/simulator-wxml/index.d.ts +29 -0
- package/dist/main/services/simulator-wxml/index.js +28 -0
- package/dist/main/services/update/update-manager.d.ts +10 -0
- package/dist/main/services/update/update-manager.js +16 -3
- package/dist/main/services/views/devtools-tabs.d.ts +47 -0
- package/dist/main/services/views/devtools-tabs.js +95 -0
- package/dist/main/services/views/view-manager.d.ts +142 -4
- package/dist/main/services/views/view-manager.js +909 -17
- package/dist/main/services/workbench-context.d.ts +66 -1
- package/dist/main/services/workbench-context.js +6 -1
- package/dist/main/services/workspace/workspace-service.d.ts +8 -0
- package/dist/main/services/workspace/workspace-service.js +12 -0
- package/dist/main/utils/ipc-registry.d.ts +11 -2
- package/dist/main/utils/ipc-registry.js +63 -3
- package/dist/main/utils/paths.d.ts +15 -0
- package/dist/main/utils/paths.js +19 -0
- package/dist/main/utils/sender-policy.d.ts +9 -3
- package/dist/main/utils/sender-policy.js +18 -4
- package/dist/main/utils/theme.d.ts +1 -1
- package/dist/main/utils/theme.js +1 -1
- package/dist/main/windows/main-window/create.d.ts +0 -6
- package/dist/main/windows/main-window/create.js +11 -59
- package/dist/main/windows/main-window/events.d.ts +1 -1
- package/dist/main/windows/main-window/events.js +1 -1
- package/dist/main/windows/service-host-window/create.d.ts +52 -0
- package/dist/main/windows/service-host-window/create.js +112 -0
- package/dist/native-host/common/common.js +368 -0
- package/dist/native-host/container/pageFrame.css +1 -0
- package/dist/native-host/render/render.js +9334 -0
- package/dist/native-host/service/service.js +6 -0
- package/dist/preload/index.d.ts +2 -0
- package/dist/preload/index.js +6 -0
- package/dist/preload/instrumentation/app-data.d.ts +18 -20
- package/dist/preload/instrumentation/app-data.js +23 -160
- package/dist/preload/instrumentation/wxml-extract.d.ts +1 -1
- package/dist/preload/instrumentation/wxml-extract.js +1 -1
- package/dist/preload/runtime/bridge.d.ts +3 -8
- package/dist/preload/runtime/bridge.js +2 -32
- package/dist/preload/runtime/custom-apis.js +20 -17
- package/dist/preload/runtime/host-toolbar-advertiser.d.ts +27 -0
- package/dist/preload/runtime/host-toolbar-advertiser.js +55 -0
- package/dist/preload/runtime/main-api-runner.d.ts +9 -0
- package/dist/preload/runtime/main-api-runner.js +85 -0
- package/dist/preload/runtime/native-host.d.ts +43 -0
- package/dist/preload/runtime/native-host.js +83 -0
- package/dist/preload/shared/expose.d.ts +10 -5
- package/dist/preload/shared/expose.js +29 -11
- package/dist/preload/shared/sid-registry.d.ts +11 -0
- package/dist/preload/shared/sid-registry.js +38 -0
- package/dist/preload/windows/host-toolbar.cjs +161 -0
- package/dist/preload/windows/host-toolbar.cjs.map +7 -0
- package/dist/preload/windows/host-toolbar.d.ts +2 -0
- package/dist/preload/windows/host-toolbar.js +12 -0
- package/dist/preload/windows/main.cjs +1939 -0
- package/dist/preload/windows/main.cjs.map +4 -4
- package/dist/preload/windows/simulator.cjs +925 -0
- package/dist/preload/windows/simulator.cjs.map +7 -0
- package/dist/preload/windows/simulator.js +243 -573
- package/dist/render-host/pageFrame.html +29 -0
- package/dist/render-host/preload.cjs +154 -0
- package/dist/render-host/render-inspect.js +295 -0
- package/dist/renderer/assets/abap-DiwvWnMr.js +2 -0
- package/dist/renderer/assets/apex-CmtZjKlf.js +2 -0
- package/dist/renderer/assets/azcli-DL2My_i-.js +2 -0
- package/dist/renderer/assets/bat-B-nC98wG.js +2 -0
- package/dist/renderer/assets/bicep-Ju5MwOgh.js +3 -0
- package/dist/renderer/assets/cameligo-8Eu1TyBr.js +2 -0
- package/dist/renderer/assets/chunk-DPI0Y_ll.js +1 -0
- package/dist/renderer/assets/clojure-u-RpMkH3.js +2 -0
- package/dist/renderer/assets/codicon-ngg6Pgfi.ttf +0 -0
- package/dist/renderer/assets/coffee-CdA7bbTe.js +2 -0
- package/dist/renderer/assets/constants-CLAQX6VZ.js +2 -0
- package/dist/renderer/assets/cpp-CzNFP8ks.js +2 -0
- package/dist/renderer/assets/csharp-j1LThmcE.js +2 -0
- package/dist/renderer/assets/csp-CLRC61y6.js +2 -0
- package/dist/renderer/assets/css-r6rC_7P2.js +4 -0
- package/dist/renderer/assets/css.worker-DyDu5ynT.js +90 -0
- package/dist/renderer/assets/cssMode-BCBgxrnA.js +2 -0
- package/dist/renderer/assets/cypher-CW08XVUh.js +2 -0
- package/dist/renderer/assets/dart-Cs9aL5T_.js +2 -0
- package/dist/renderer/assets/dockerfile-BWM0M184.js +2 -0
- package/dist/renderer/assets/ecl-MJJuer5P.js +2 -0
- package/dist/renderer/assets/editor-CWI9TnMM.css +1 -0
- package/dist/renderer/assets/editor.api2-BTaYmRq7.js +873 -0
- package/dist/renderer/assets/editor.worker-Dpt_xPrs.js +27 -0
- package/dist/renderer/assets/elixir-D2AIuXqn.js +2 -0
- package/dist/renderer/assets/flow9-B2H24giC.js +2 -0
- package/dist/renderer/assets/freemarker2-DGDGzimW.js +4 -0
- package/dist/renderer/assets/fsharp-CMk2OIJN.js +2 -0
- package/dist/renderer/assets/go-BrMkuJg0.js +2 -0
- package/dist/renderer/assets/graphql-PSR1UKGv.js +2 -0
- package/dist/renderer/assets/handlebars-bOHhw3EG.js +2 -0
- package/dist/renderer/assets/hcl-DAQrbDOW.js +2 -0
- package/dist/renderer/assets/html-BMyuX0_c.js +2 -0
- package/dist/renderer/assets/html.worker-IWNXhnIC.js +503 -0
- package/dist/renderer/assets/htmlMode-DR4kXJ7l.js +2 -0
- package/dist/renderer/assets/index-CcJKzatF.js +50 -0
- package/dist/renderer/assets/ini-0TG5BxW0.js +2 -0
- package/dist/renderer/assets/input-QGx6FFX1.js +2 -0
- package/dist/renderer/assets/ipc-transport-BT4QYQqu.css +1 -0
- package/dist/renderer/assets/{ipc-transport-BzPzxPwf.js → ipc-transport-DvZvwK-Z.js} +5 -5
- package/dist/renderer/assets/java-rgorz17v.js +2 -0
- package/dist/renderer/assets/javascript-Bu-tl1P7.js +2 -0
- package/dist/renderer/assets/json.worker-c4h5s80L.js +59 -0
- package/dist/renderer/assets/jsonMode-MQV_ffLR.js +8 -0
- package/dist/renderer/assets/julia-C8VMdHm8.js +2 -0
- package/dist/renderer/assets/kotlin-AhhC4Qhm.js +2 -0
- package/dist/renderer/assets/less-Cgca25AP.js +3 -0
- package/dist/renderer/assets/lexon-D0GHdBaw.js +2 -0
- package/dist/renderer/assets/liquid-ClkfOvhB.js +2 -0
- package/dist/renderer/assets/lspLanguageFeatures-Bke_4Ie9.js +5 -0
- package/dist/renderer/assets/lua-DmRsNG-P.js +2 -0
- package/dist/renderer/assets/m3-BgL5dNKT.js +2 -0
- package/dist/renderer/assets/markdown-BuJfycGS.js +2 -0
- package/dist/renderer/assets/mdx-RZdUskPu.js +2 -0
- package/dist/renderer/assets/mips-C9m_93PR.js +2 -0
- package/dist/renderer/assets/monaco.contribution-B7rUMaEv.js +3 -0
- package/dist/renderer/assets/msdax-CpFHC9OI.js +2 -0
- package/dist/renderer/assets/mysql-qFvltsqN.js +2 -0
- package/dist/renderer/assets/objective-c-Bnmr858J.js +2 -0
- package/dist/renderer/assets/pascal-WP0_D5AO.js +2 -0
- package/dist/renderer/assets/pascaligo-Blom4Rij.js +2 -0
- package/dist/renderer/assets/perl-B-vk8g64.js +2 -0
- package/dist/renderer/assets/pgsql-Cgvz6v67.js +2 -0
- package/dist/renderer/assets/php-8a3Lrw9m.js +2 -0
- package/dist/renderer/assets/pla-DuFqEZ8V.js +2 -0
- package/dist/renderer/assets/popover-BOH1If1J.js +2 -0
- package/dist/renderer/assets/postiats-DkLtSgkp.js +2 -0
- package/dist/renderer/assets/powerquery-BJ1aNepW.js +2 -0
- package/dist/renderer/assets/powershell-rE98k687.js +2 -0
- package/dist/renderer/assets/protobuf-CUheFacr.js +3 -0
- package/dist/renderer/assets/pug-LDcAMD8w.js +2 -0
- package/dist/renderer/assets/python-Cobrm_-8.js +2 -0
- package/dist/renderer/assets/qsharp-DUKSQoR1.js +2 -0
- package/dist/renderer/assets/r-D-QApv87.js +2 -0
- package/dist/renderer/assets/razor-BEUIQFNJ.js +2 -0
- package/dist/renderer/assets/redis-SXdDyWR9.js +2 -0
- package/dist/renderer/assets/redshift-Y6lsCryn.js +2 -0
- package/dist/renderer/assets/restructuredtext-edObr9a8.js +2 -0
- package/dist/renderer/assets/ruby-CNnUfF-8.js +2 -0
- package/dist/renderer/assets/rust-IHUZWzBr.js +2 -0
- package/dist/renderer/assets/sb-DrUvY44N.js +2 -0
- package/dist/renderer/assets/scala-B4hbXGLM.js +2 -0
- package/dist/renderer/assets/scheme-BGrd12j3.js +2 -0
- package/dist/renderer/assets/scss-x5G1ES4U.js +4 -0
- package/dist/renderer/assets/select-C7JQ8G5N.js +2 -0
- package/dist/renderer/assets/settings-DpAbTJyF.js +2 -0
- package/dist/renderer/assets/{settings-api-BXCw9vOZ.js → settings-api-RD2IZF53.js} +2 -2
- package/dist/renderer/assets/shell-DOehe2Y8.js +2 -0
- package/dist/renderer/assets/solidity-BeRvcwWV.js +2 -0
- package/dist/renderer/assets/sophia-DZbkUNjy.js +2 -0
- package/dist/renderer/assets/sparql-B7_oi5-h.js +2 -0
- package/dist/renderer/assets/sql-CTlsFWVE.js +2 -0
- package/dist/renderer/assets/st-DJVEJdPE.js +2 -0
- package/dist/renderer/assets/swift-CwhT3fYa.js +2 -0
- package/dist/renderer/assets/systemverilog-BQN63pkN.js +2 -0
- package/dist/renderer/assets/tcl-DqwfpskA.js +2 -0
- package/dist/renderer/assets/ts.worker-BwM5Ha3L.js +67720 -0
- package/dist/renderer/assets/tsMode-BHa7dl9v.js +12 -0
- package/dist/renderer/assets/twig-BiyenUgc.js +2 -0
- package/dist/renderer/assets/typescript-15aT0Yj8.js +2 -0
- package/dist/renderer/assets/typespec-CWOJribt.js +2 -0
- package/dist/renderer/assets/vb-Cq5F87m3.js +2 -0
- package/dist/renderer/assets/wgsl-BAvW2lVr.js +299 -0
- package/dist/renderer/assets/workbenchSettings-CNJX4Qna.js +8 -0
- package/dist/renderer/assets/workers-CRBS0W-v.js +2 -0
- package/dist/renderer/assets/xml-bR2Zh-HV.js +2 -0
- package/dist/renderer/assets/yaml-Bdk54Qrb.js +2 -0
- package/dist/renderer/entries/main/index.html +29 -6
- package/dist/renderer/entries/popover/index.html +7 -6
- package/dist/renderer/entries/settings/index.html +6 -5
- package/dist/renderer/entries/workbench-settings/index.html +6 -5
- package/dist/service-host/preload.cjs +254 -0
- package/dist/service-host/service.html +10 -0
- package/dist/service-host/sourcemap-rewrite.cjs +58 -0
- package/dist/service-host/sync-api-patch.js +20 -0
- package/dist/service-host/sync-impls/menu-button.js +16 -0
- package/dist/service-host/sync-impls/storage.js +50 -0
- package/dist/service-host/sync-impls/system-info.js +54 -0
- package/dist/shared/appdata-accumulator.d.ts +95 -0
- package/dist/shared/appdata-accumulator.js +213 -0
- package/dist/shared/bridge-channels.d.ts +364 -0
- package/dist/shared/bridge-channels.js +54 -0
- package/dist/shared/constants.d.ts +0 -4
- package/dist/shared/constants.js +0 -4
- package/dist/shared/ipc-channels.d.ts +108 -1
- package/dist/shared/ipc-channels.js +127 -10
- package/dist/shared/ipc-schemas.d.ts +65 -2
- package/dist/shared/ipc-schemas.js +79 -3
- package/dist/shared/open-in-editor.d.ts +71 -0
- package/dist/shared/open-in-editor.js +138 -0
- package/dist/shared/simulator-api-metadata.d.ts +21 -0
- package/dist/shared/simulator-api-metadata.js +23 -0
- package/dist/shared/types.d.ts +2 -2
- package/dist/shared/vpath.d.ts +42 -0
- package/dist/shared/vpath.js +105 -0
- package/dist/simulator/assets/device-shell-DsdcNEkt.css +1 -0
- package/dist/simulator/assets/device-shell-vwYSOVrh.js +2 -0
- package/dist/simulator/assets/jsx-runtime-P6ZegaOf.js +2 -0
- package/dist/simulator/assets/simulator-DddliUL5.js +10 -0
- package/dist/simulator/assets/simulator-mini-app-BDNu5n26.js +2 -0
- package/dist/simulator/device-shell/menu-button-geometry.js +8 -0
- package/dist/simulator/simulator.html +2 -112
- package/package.json +9 -9
- package/dist/main/utils/disposable.d.ts +0 -18
- package/dist/main/utils/disposable.js +0 -67
- package/dist/renderer/assets/constants-DI382mTP.js +0 -2
- package/dist/renderer/assets/index-4lkyF644.js +0 -46
- package/dist/renderer/assets/input-D4byFOLS.js +0 -2
- package/dist/renderer/assets/ipc-transport-DqbRdZNO.css +0 -1
- package/dist/renderer/assets/popover-cxKrg_os.js +0 -2
- package/dist/renderer/assets/select-BgSkkdHW.js +0 -2
- package/dist/renderer/assets/settings-oD2K1jdT.js +0 -2
- package/dist/renderer/assets/workbenchSettings-CTNBpTft.js +0 -8
- package/dist/simulator/assets/simulator-CVOFTpSj.js +0 -9
|
@@ -0,0 +1,925 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// src/preload/shared/expose.ts
|
|
4
|
+
var import_electron = require("electron");
|
|
5
|
+
function exposeOnMainWorld(key, value) {
|
|
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 {
|
|
16
|
+
;
|
|
17
|
+
window[key] = value;
|
|
18
|
+
assignedToWindow = true;
|
|
19
|
+
}
|
|
20
|
+
return () => {
|
|
21
|
+
if (!assignedToWindow) return;
|
|
22
|
+
const w = window;
|
|
23
|
+
if (w[key] === value) delete w[key];
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// src/preload/shared/page-iframe.ts
|
|
28
|
+
function getActivePageIframe() {
|
|
29
|
+
const iframes = document.querySelectorAll(".dimina-native-webview__window");
|
|
30
|
+
return iframes.length > 0 ? iframes[iframes.length - 1] : null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// src/preload/shared/sid-registry.ts
|
|
34
|
+
var SYNTHETIC_SID_PREFIX = "devtools-";
|
|
35
|
+
var elBySyntheticSid = /* @__PURE__ */ new Map();
|
|
36
|
+
function findElementBySid(doc, sid) {
|
|
37
|
+
if (sid.startsWith(SYNTHETIC_SID_PREFIX)) {
|
|
38
|
+
const ref = elBySyntheticSid.get(sid);
|
|
39
|
+
if (!ref) return null;
|
|
40
|
+
const el = ref.deref();
|
|
41
|
+
if (!el || !el.isConnected) {
|
|
42
|
+
elBySyntheticSid.delete(sid);
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
if (el.ownerDocument !== doc) return null;
|
|
46
|
+
return el;
|
|
47
|
+
}
|
|
48
|
+
return doc.querySelector(`[data-sid="${CSS.escape(sid)}"]`);
|
|
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;
|
|
60
|
+
function clone(value) {
|
|
61
|
+
try {
|
|
62
|
+
return JSON.parse(JSON.stringify(value));
|
|
63
|
+
} catch {
|
|
64
|
+
return value;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function ensureOverlay(doc) {
|
|
68
|
+
if (highlightOverlay && highlightOverlay.ownerDocument === doc) return highlightOverlay;
|
|
69
|
+
highlightOverlay = doc.createElement("div");
|
|
70
|
+
highlightOverlay.id = "__simulator-highlight";
|
|
71
|
+
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;box-sizing:border-box;";
|
|
72
|
+
doc.body.appendChild(highlightOverlay);
|
|
73
|
+
return highlightOverlay;
|
|
74
|
+
}
|
|
75
|
+
function highlightElement(sid) {
|
|
76
|
+
if (!sid) return null;
|
|
77
|
+
const iframe = getActivePageIframe();
|
|
78
|
+
if (!iframe?.contentDocument) return null;
|
|
79
|
+
const doc = iframe.contentDocument;
|
|
80
|
+
const el = findElementBySid(doc, sid);
|
|
81
|
+
if (!el) return null;
|
|
82
|
+
const rect = el.getBoundingClientRect();
|
|
83
|
+
const overlay = ensureOverlay(doc);
|
|
84
|
+
overlay.style.left = `${rect.left}px`;
|
|
85
|
+
overlay.style.top = `${rect.top}px`;
|
|
86
|
+
overlay.style.width = `${rect.width}px`;
|
|
87
|
+
overlay.style.height = `${rect.height}px`;
|
|
88
|
+
overlay.style.display = "block";
|
|
89
|
+
const style = el.ownerDocument.defaultView?.getComputedStyle(el);
|
|
90
|
+
if (!style) return null;
|
|
91
|
+
return {
|
|
92
|
+
sid,
|
|
93
|
+
rect: { x: rect.x, y: rect.y, width: rect.width, height: rect.height },
|
|
94
|
+
style: {
|
|
95
|
+
display: style.display,
|
|
96
|
+
position: style.position,
|
|
97
|
+
boxSizing: style.boxSizing,
|
|
98
|
+
margin: style.margin,
|
|
99
|
+
padding: style.padding,
|
|
100
|
+
color: style.color,
|
|
101
|
+
backgroundColor: style.backgroundColor,
|
|
102
|
+
fontSize: style.fontSize
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
function unhighlightElement() {
|
|
107
|
+
if (highlightOverlay) highlightOverlay.style.display = "none";
|
|
108
|
+
}
|
|
109
|
+
function buildApi() {
|
|
110
|
+
return {
|
|
111
|
+
getAppdata: () => clone(state.appdata.data),
|
|
112
|
+
getAppdataSnapshot: () => clone(state.appdata),
|
|
113
|
+
getAppdataGen: () => state.appdata.gen,
|
|
114
|
+
getStorageSnapshot: () => clone(state.storage),
|
|
115
|
+
getStorageGen: () => state.storage.gen,
|
|
116
|
+
getWxml: () => clone(state.wxml.data),
|
|
117
|
+
getWxmlSnapshot: () => clone(state.wxml),
|
|
118
|
+
getWxmlGen: () => state.wxml.gen,
|
|
119
|
+
refresh: (type) => state.refreshHandler?.(type),
|
|
120
|
+
highlightElement,
|
|
121
|
+
unhighlightElement
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
function setAppDataSnapshot(data) {
|
|
125
|
+
state.appdata = {
|
|
126
|
+
gen: state.appdata.gen + 1,
|
|
127
|
+
ready: true,
|
|
128
|
+
data: clone(data)
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
function clearAppDataSnapshot() {
|
|
132
|
+
state.appdata = {
|
|
133
|
+
gen: state.appdata.gen + 1,
|
|
134
|
+
ready: true,
|
|
135
|
+
data: {}
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
function clearStorageSnapshot() {
|
|
139
|
+
state.storage = {
|
|
140
|
+
gen: state.storage.gen + 1,
|
|
141
|
+
ready: false,
|
|
142
|
+
namespace: null,
|
|
143
|
+
data: {}
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
function clearWxmlSnapshot() {
|
|
147
|
+
state.wxml = {
|
|
148
|
+
gen: state.wxml.gen + 1,
|
|
149
|
+
ready: false,
|
|
150
|
+
data: null
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
function resetBridgeState() {
|
|
154
|
+
clearAppDataSnapshot();
|
|
155
|
+
clearStorageSnapshot();
|
|
156
|
+
clearWxmlSnapshot();
|
|
157
|
+
unhighlightElement();
|
|
158
|
+
state.refreshHandler = null;
|
|
159
|
+
}
|
|
160
|
+
function installSimulatorBridge() {
|
|
161
|
+
if (!exposedApi) {
|
|
162
|
+
exposedApi = buildApi();
|
|
163
|
+
}
|
|
164
|
+
const dispose = exposeOnMainWorld("__simulatorData", exposedApi);
|
|
165
|
+
return () => {
|
|
166
|
+
resetBridgeState();
|
|
167
|
+
dispose();
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// src/preload/runtime/custom-apis.ts
|
|
172
|
+
var import_electron2 = require("electron");
|
|
173
|
+
|
|
174
|
+
// src/shared/ipc-channels.ts
|
|
175
|
+
var SimulatorChannel = {
|
|
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",
|
|
188
|
+
Detach: "simulator:detach",
|
|
189
|
+
Resize: "simulator:resize",
|
|
190
|
+
SetVisible: "simulator:setVisible",
|
|
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"
|
|
196
|
+
};
|
|
197
|
+
var SimulatorCustomApiBridgeChannel = {
|
|
198
|
+
Request: "simulator:custom-apis:bridge-request",
|
|
199
|
+
Response: "simulator:custom-apis:bridge-response"
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
// src/preload/runtime/custom-apis.ts
|
|
203
|
+
var LIST_RETRY_INTERVAL_MS = 150;
|
|
204
|
+
var LIST_RETRY_CEILING_MS = 2500;
|
|
205
|
+
function buildBridge() {
|
|
206
|
+
let nextId = 1;
|
|
207
|
+
const pending = /* @__PURE__ */ new Map();
|
|
208
|
+
const sendRequest = (req) => {
|
|
209
|
+
import_electron2.ipcRenderer.send(SimulatorCustomApiBridgeChannel.Request, req);
|
|
210
|
+
};
|
|
211
|
+
import_electron2.ipcRenderer.on(SimulatorCustomApiBridgeChannel.Response, (_event, payload) => {
|
|
212
|
+
const entry = pending.get(payload.id);
|
|
213
|
+
if (!entry) return;
|
|
214
|
+
pending.delete(payload.id);
|
|
215
|
+
if ("error" in payload) {
|
|
216
|
+
entry.reject(new Error(payload.error));
|
|
217
|
+
} else {
|
|
218
|
+
entry.resolve(payload.result);
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
const send = (req) => {
|
|
222
|
+
return new Promise((resolve, reject) => {
|
|
223
|
+
pending.set(req.id, {
|
|
224
|
+
resolve: (value) => resolve(value),
|
|
225
|
+
reject
|
|
226
|
+
});
|
|
227
|
+
sendRequest(req);
|
|
228
|
+
});
|
|
229
|
+
};
|
|
230
|
+
const listWithRetry = () => {
|
|
231
|
+
return new Promise((resolve, reject) => {
|
|
232
|
+
const attemptIds = /* @__PURE__ */ new Set();
|
|
233
|
+
const state2 = { settled: false };
|
|
234
|
+
const cleanup = () => {
|
|
235
|
+
state2.settled = true;
|
|
236
|
+
if (state2.retryTimer) clearInterval(state2.retryTimer);
|
|
237
|
+
if (state2.ceilingTimer) clearTimeout(state2.ceilingTimer);
|
|
238
|
+
for (const id of attemptIds) pending.delete(id);
|
|
239
|
+
attemptIds.clear();
|
|
240
|
+
};
|
|
241
|
+
const attempt = () => {
|
|
242
|
+
if (state2.settled) return;
|
|
243
|
+
const id = nextId++;
|
|
244
|
+
attemptIds.add(id);
|
|
245
|
+
pending.set(id, {
|
|
246
|
+
resolve: (value) => {
|
|
247
|
+
if (state2.settled) return;
|
|
248
|
+
cleanup();
|
|
249
|
+
resolve(value);
|
|
250
|
+
},
|
|
251
|
+
reject: (reason) => {
|
|
252
|
+
if (state2.settled) return;
|
|
253
|
+
cleanup();
|
|
254
|
+
reject(reason);
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
sendRequest({ id, op: "list" });
|
|
258
|
+
};
|
|
259
|
+
state2.retryTimer = setInterval(attempt, LIST_RETRY_INTERVAL_MS);
|
|
260
|
+
state2.ceilingTimer = setTimeout(() => {
|
|
261
|
+
if (state2.settled) return;
|
|
262
|
+
cleanup();
|
|
263
|
+
reject(new Error("custom-apis bridge list() got no response from the host renderer"));
|
|
264
|
+
}, LIST_RETRY_CEILING_MS);
|
|
265
|
+
attempt();
|
|
266
|
+
});
|
|
267
|
+
};
|
|
268
|
+
return {
|
|
269
|
+
list: listWithRetry,
|
|
270
|
+
invoke: (name, params) => send({ id: nextId++, op: "invoke", name, params })
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
function installCustomApisBridge() {
|
|
274
|
+
const bridge = buildBridge();
|
|
275
|
+
return exposeOnMainWorld("__diminaCustomApis", bridge);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// src/preload/runtime/temp-files.ts
|
|
279
|
+
var import_electron3 = require("electron");
|
|
280
|
+
|
|
281
|
+
// src/simulator/temp-files.ts
|
|
282
|
+
var activeSink = null;
|
|
283
|
+
function setTempFileSink(sink) {
|
|
284
|
+
activeSink = sink;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// src/preload/runtime/temp-files.ts
|
|
288
|
+
function installTempFileBridge() {
|
|
289
|
+
setTempFileSink({
|
|
290
|
+
write(path, blob) {
|
|
291
|
+
blob.arrayBuffer().then((bytes) => {
|
|
292
|
+
import_electron3.ipcRenderer.send("simulator:temp-file:write", {
|
|
293
|
+
path,
|
|
294
|
+
mime: blob.type,
|
|
295
|
+
bytes
|
|
296
|
+
});
|
|
297
|
+
}).catch(() => {
|
|
298
|
+
});
|
|
299
|
+
},
|
|
300
|
+
revoke(path) {
|
|
301
|
+
import_electron3.ipcRenderer.send("simulator:temp-file:revoke", { path });
|
|
302
|
+
},
|
|
303
|
+
revokeAll() {
|
|
304
|
+
import_electron3.ipcRenderer.send("simulator:temp-file:revoke-all");
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// src/preload/runtime/host.ts
|
|
310
|
+
var import_electron4 = require("electron");
|
|
311
|
+
function sendToHost(channel, data) {
|
|
312
|
+
import_electron4.ipcRenderer.sendToHost(channel, data);
|
|
313
|
+
}
|
|
314
|
+
function safeSerialize(val) {
|
|
315
|
+
if (val === null || val === void 0) return val;
|
|
316
|
+
if (typeof val === "function") return `[Function: ${val.name || "anonymous"}]`;
|
|
317
|
+
if (typeof val !== "object") return val;
|
|
318
|
+
if (val instanceof Error) return { __isError: true, message: val.message, stack: val.stack };
|
|
319
|
+
try {
|
|
320
|
+
return structuredClone(val);
|
|
321
|
+
} catch {
|
|
322
|
+
}
|
|
323
|
+
try {
|
|
324
|
+
return JSON.parse(JSON.stringify(val));
|
|
325
|
+
} catch {
|
|
326
|
+
}
|
|
327
|
+
return String(val);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
// src/preload/instrumentation/console.ts
|
|
331
|
+
function installConsoleInstrumentation() {
|
|
332
|
+
const consoleRef = console;
|
|
333
|
+
const originals = /* @__PURE__ */ new Map();
|
|
334
|
+
const levels = ["log", "warn", "error", "info", "debug"];
|
|
335
|
+
for (const level of levels) {
|
|
336
|
+
const original = consoleRef[level]?.bind(console);
|
|
337
|
+
if (!original) continue;
|
|
338
|
+
originals.set(level, original);
|
|
339
|
+
consoleRef[level] = (...args) => {
|
|
340
|
+
original(...args);
|
|
341
|
+
sendToHost(SimulatorChannel.Console, {
|
|
342
|
+
source: "container",
|
|
343
|
+
level,
|
|
344
|
+
args: args.map(safeSerialize),
|
|
345
|
+
ts: Date.now()
|
|
346
|
+
});
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
const handleError = (event) => {
|
|
350
|
+
sendToHost(SimulatorChannel.Console, {
|
|
351
|
+
source: "container",
|
|
352
|
+
level: "error",
|
|
353
|
+
args: [{
|
|
354
|
+
message: event.message,
|
|
355
|
+
source: event.filename,
|
|
356
|
+
lineno: event.lineno,
|
|
357
|
+
colno: event.colno,
|
|
358
|
+
stack: event.error?.stack
|
|
359
|
+
}],
|
|
360
|
+
ts: Date.now()
|
|
361
|
+
});
|
|
362
|
+
};
|
|
363
|
+
const handleRejection = (event) => {
|
|
364
|
+
sendToHost(SimulatorChannel.Console, {
|
|
365
|
+
source: "container",
|
|
366
|
+
level: "error",
|
|
367
|
+
args: [{ message: "Unhandled Promise Rejection", reason: String(event.reason) }],
|
|
368
|
+
ts: Date.now()
|
|
369
|
+
});
|
|
370
|
+
};
|
|
371
|
+
window.addEventListener("error", handleError);
|
|
372
|
+
window.addEventListener("unhandledrejection", handleRejection);
|
|
373
|
+
return () => {
|
|
374
|
+
for (const [level, original] of originals) {
|
|
375
|
+
consoleRef[level] = original;
|
|
376
|
+
}
|
|
377
|
+
window.removeEventListener("error", handleError);
|
|
378
|
+
window.removeEventListener("unhandledrejection", handleRejection);
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
// src/shared/appdata-accumulator.ts
|
|
383
|
+
function decodeWorkerMessage(message) {
|
|
384
|
+
let payload = message;
|
|
385
|
+
if (typeof payload === "string") {
|
|
386
|
+
try {
|
|
387
|
+
payload = JSON.parse(payload);
|
|
388
|
+
} catch {
|
|
389
|
+
return null;
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
if (!payload || typeof payload !== "object") return null;
|
|
393
|
+
const record = payload;
|
|
394
|
+
if (record.type === "ub") {
|
|
395
|
+
const body = record.body;
|
|
396
|
+
if (!body || typeof body !== "object") return null;
|
|
397
|
+
if (typeof body.bridgeId !== "string" || !Array.isArray(body.updates)) return null;
|
|
398
|
+
const out = [];
|
|
399
|
+
for (const u of body.updates) {
|
|
400
|
+
if (!u || typeof u.moduleId !== "string") continue;
|
|
401
|
+
if (!u.moduleId.startsWith("page_")) continue;
|
|
402
|
+
out.push({ mode: "patch", bridgeId: body.bridgeId, moduleId: u.moduleId, data: u.data });
|
|
403
|
+
}
|
|
404
|
+
return out.length > 0 ? out : null;
|
|
405
|
+
}
|
|
406
|
+
if (typeof record.type === "string" && record.type.startsWith("page_")) {
|
|
407
|
+
const body = record.body;
|
|
408
|
+
if (!body || typeof body !== "object") return null;
|
|
409
|
+
if (typeof body.bridgeId !== "string" || typeof body.path !== "string") return null;
|
|
410
|
+
if (!body.data || typeof body.data !== "object") return null;
|
|
411
|
+
return [{
|
|
412
|
+
mode: "init",
|
|
413
|
+
bridgeId: body.bridgeId,
|
|
414
|
+
moduleId: record.type,
|
|
415
|
+
componentPath: body.path,
|
|
416
|
+
data: body.data
|
|
417
|
+
}];
|
|
418
|
+
}
|
|
419
|
+
return null;
|
|
420
|
+
}
|
|
421
|
+
function decodeOutgoingMessage(message) {
|
|
422
|
+
let payload = message;
|
|
423
|
+
if (typeof payload === "string") {
|
|
424
|
+
try {
|
|
425
|
+
payload = JSON.parse(payload);
|
|
426
|
+
} catch {
|
|
427
|
+
return null;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
if (!payload || typeof payload !== "object") return null;
|
|
431
|
+
const r = payload;
|
|
432
|
+
if (typeof r.type !== "string") return null;
|
|
433
|
+
return {
|
|
434
|
+
type: r.type,
|
|
435
|
+
bridgeId: typeof r.body?.bridgeId === "string" ? r.body.bridgeId : void 0
|
|
436
|
+
};
|
|
437
|
+
}
|
|
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;
|
|
466
|
+
}
|
|
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() {
|
|
479
|
+
const bridges = [];
|
|
480
|
+
for (const id of this.bridgeOrder) {
|
|
481
|
+
bridges.push({ id, pagePath: this.bridgePagePath.get(id) ?? null });
|
|
482
|
+
}
|
|
483
|
+
const entries = {};
|
|
484
|
+
for (const [key, entry] of this.cache) {
|
|
485
|
+
const slash = key.indexOf("/");
|
|
486
|
+
if (slash < 0) continue;
|
|
487
|
+
const bridgeId = key.slice(0, slash);
|
|
488
|
+
const moduleId = key.slice(slash + 1);
|
|
489
|
+
if (!entries[bridgeId]) entries[bridgeId] = {};
|
|
490
|
+
const displayKey = entry.componentPath ?? moduleId;
|
|
491
|
+
entries[bridgeId][displayKey] = entry.data;
|
|
492
|
+
}
|
|
493
|
+
return { bridges, entries };
|
|
494
|
+
}
|
|
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);
|
|
508
|
+
}
|
|
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());
|
|
534
|
+
}
|
|
535
|
+
function clearBridge(bridgeId) {
|
|
536
|
+
accumulator.clearBridge(bridgeId);
|
|
537
|
+
publishSnapshot();
|
|
538
|
+
emit?.();
|
|
539
|
+
}
|
|
540
|
+
function applyAppData(body) {
|
|
541
|
+
if (!accumulator.apply(body)) return;
|
|
542
|
+
publishSnapshot();
|
|
543
|
+
emit?.();
|
|
544
|
+
}
|
|
545
|
+
function instrumentPostMessage(worker) {
|
|
546
|
+
const orig = worker.postMessage.bind(worker);
|
|
547
|
+
worker.postMessage = function(msg, ...rest) {
|
|
548
|
+
const decoded = decodeOutgoingMessage(msg);
|
|
549
|
+
if (decoded?.type === "pageUnload" && decoded.bridgeId) {
|
|
550
|
+
clearBridge(decoded.bridgeId);
|
|
551
|
+
}
|
|
552
|
+
return orig(msg, ...rest);
|
|
553
|
+
};
|
|
554
|
+
}
|
|
555
|
+
function createInstrumentedWorker(Original) {
|
|
556
|
+
function InstrumentedWorker(scriptURL, options) {
|
|
557
|
+
const resolvedScriptURL = scriptURL instanceof URL ? scriptURL : new URL(scriptURL, window.location.href);
|
|
558
|
+
const worker = Reflect.construct(
|
|
559
|
+
Original,
|
|
560
|
+
[resolvedScriptURL, options],
|
|
561
|
+
new.target ?? InstrumentedWorker
|
|
562
|
+
);
|
|
563
|
+
instrumentPostMessage(worker);
|
|
564
|
+
worker.addEventListener("message", (event) => {
|
|
565
|
+
const entries = decodeWorkerMessage(event.data);
|
|
566
|
+
if (!entries) return;
|
|
567
|
+
for (const entry of entries) {
|
|
568
|
+
const hookBody = {
|
|
569
|
+
bridgeId: entry.bridgeId,
|
|
570
|
+
moduleId: entry.moduleId,
|
|
571
|
+
data: entry.data,
|
|
572
|
+
mode: entry.mode
|
|
573
|
+
};
|
|
574
|
+
if (entry.mode === "init") hookBody.componentPath = entry.componentPath;
|
|
575
|
+
window.__simulatorHook?.appData(hookBody);
|
|
576
|
+
}
|
|
577
|
+
});
|
|
578
|
+
return worker;
|
|
579
|
+
}
|
|
580
|
+
Object.setPrototypeOf(InstrumentedWorker, Original);
|
|
581
|
+
Object.defineProperty(InstrumentedWorker, "prototype", {
|
|
582
|
+
value: Original.prototype
|
|
583
|
+
});
|
|
584
|
+
return InstrumentedWorker;
|
|
585
|
+
}
|
|
586
|
+
return {
|
|
587
|
+
id: "appdata",
|
|
588
|
+
snapshot: () => accumulator.snapshot(),
|
|
589
|
+
start(onChange) {
|
|
590
|
+
if (installed) return;
|
|
591
|
+
installed = true;
|
|
592
|
+
emit = onChange;
|
|
593
|
+
originalHook = window.__simulatorHook;
|
|
594
|
+
originalDescriptor = Object.getOwnPropertyDescriptor(window, "Worker");
|
|
595
|
+
OriginalWorker = window.Worker;
|
|
596
|
+
window.__simulatorHook = {
|
|
597
|
+
appData: (body) => applyAppData(body)
|
|
598
|
+
};
|
|
599
|
+
Object.defineProperty(window, "Worker", {
|
|
600
|
+
configurable: true,
|
|
601
|
+
writable: true,
|
|
602
|
+
value: createInstrumentedWorker(OriginalWorker)
|
|
603
|
+
});
|
|
604
|
+
},
|
|
605
|
+
dispose() {
|
|
606
|
+
if (!installed) return;
|
|
607
|
+
installed = false;
|
|
608
|
+
if (originalDescriptor) {
|
|
609
|
+
Object.defineProperty(window, "Worker", originalDescriptor);
|
|
610
|
+
} else if (OriginalWorker) {
|
|
611
|
+
window.Worker = OriginalWorker;
|
|
612
|
+
}
|
|
613
|
+
if (originalHook) {
|
|
614
|
+
window.__simulatorHook = originalHook;
|
|
615
|
+
} else {
|
|
616
|
+
delete window.__simulatorHook;
|
|
617
|
+
}
|
|
618
|
+
originalDescriptor = void 0;
|
|
619
|
+
OriginalWorker = void 0;
|
|
620
|
+
originalHook = void 0;
|
|
621
|
+
accumulator.clear();
|
|
622
|
+
clearAppDataSnapshot();
|
|
623
|
+
emit = null;
|
|
624
|
+
}
|
|
625
|
+
};
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
// src/preload/shared/api-compat.ts
|
|
629
|
+
function call(fn, payload) {
|
|
630
|
+
try {
|
|
631
|
+
fn?.(payload);
|
|
632
|
+
} catch {
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
function buildWindowInfo() {
|
|
636
|
+
const width = window.innerWidth || document.documentElement.clientWidth || 375;
|
|
637
|
+
const height = window.innerHeight || document.documentElement.clientHeight || 812;
|
|
638
|
+
const pixelRatio = window.devicePixelRatio || 2;
|
|
639
|
+
const statusBarHeight = 0;
|
|
640
|
+
return {
|
|
641
|
+
pixelRatio,
|
|
642
|
+
screenWidth: width,
|
|
643
|
+
screenHeight: height,
|
|
644
|
+
windowWidth: width,
|
|
645
|
+
windowHeight: height,
|
|
646
|
+
statusBarHeight,
|
|
647
|
+
safeArea: {
|
|
648
|
+
width,
|
|
649
|
+
height,
|
|
650
|
+
top: statusBarHeight,
|
|
651
|
+
bottom: height,
|
|
652
|
+
left: 0,
|
|
653
|
+
right: width
|
|
654
|
+
}
|
|
655
|
+
};
|
|
656
|
+
}
|
|
657
|
+
function makeStorageKey(key) {
|
|
658
|
+
return `dimina:${key}`;
|
|
659
|
+
}
|
|
660
|
+
function ensureWxApi(wx) {
|
|
661
|
+
if (typeof wx.canIUse !== "function") {
|
|
662
|
+
wx.canIUse = (_schema) => true;
|
|
663
|
+
}
|
|
664
|
+
if (typeof wx.getWindowInfo !== "function") {
|
|
665
|
+
wx.getWindowInfo = (opts = {}) => {
|
|
666
|
+
const info = buildWindowInfo();
|
|
667
|
+
call(opts.success, info);
|
|
668
|
+
call(opts.complete, void 0);
|
|
669
|
+
return info;
|
|
670
|
+
};
|
|
671
|
+
}
|
|
672
|
+
if (typeof wx.getSystemSetting !== "function") {
|
|
673
|
+
wx.getSystemSetting = (opts = {}) => {
|
|
674
|
+
const info = {
|
|
675
|
+
bluetoothEnabled: false,
|
|
676
|
+
locationEnabled: true,
|
|
677
|
+
wifiEnabled: true,
|
|
678
|
+
deviceOrientation: "portrait"
|
|
679
|
+
};
|
|
680
|
+
call(opts.success, info);
|
|
681
|
+
call(opts.complete, void 0);
|
|
682
|
+
return info;
|
|
683
|
+
};
|
|
684
|
+
}
|
|
685
|
+
if (typeof wx.getSystemInfoSync !== "function") {
|
|
686
|
+
wx.getSystemInfoSync = () => ({
|
|
687
|
+
brand: "simulator",
|
|
688
|
+
model: "web",
|
|
689
|
+
platform: "simulator",
|
|
690
|
+
system: "web",
|
|
691
|
+
language: "zh_CN",
|
|
692
|
+
SDKVersion: "3.0.0",
|
|
693
|
+
...buildWindowInfo()
|
|
694
|
+
});
|
|
695
|
+
}
|
|
696
|
+
if (typeof wx.setStorageSync !== "function") {
|
|
697
|
+
wx.setStorageSync = (key, data) => {
|
|
698
|
+
const value = typeof data === "string" ? data : JSON.stringify(data);
|
|
699
|
+
localStorage.setItem(makeStorageKey(String(key)), value);
|
|
700
|
+
};
|
|
701
|
+
}
|
|
702
|
+
if (typeof wx.getStorageSync !== "function") {
|
|
703
|
+
wx.getStorageSync = (key) => {
|
|
704
|
+
const raw = localStorage.getItem(makeStorageKey(String(key)));
|
|
705
|
+
if (raw == null) return "";
|
|
706
|
+
try {
|
|
707
|
+
return JSON.parse(raw);
|
|
708
|
+
} catch {
|
|
709
|
+
return raw;
|
|
710
|
+
}
|
|
711
|
+
};
|
|
712
|
+
}
|
|
713
|
+
if (typeof wx.removeStorageSync !== "function") {
|
|
714
|
+
wx.removeStorageSync = (key) => {
|
|
715
|
+
localStorage.removeItem(makeStorageKey(String(key)));
|
|
716
|
+
};
|
|
717
|
+
}
|
|
718
|
+
if (typeof wx.clearStorageSync !== "function") {
|
|
719
|
+
wx.clearStorageSync = () => {
|
|
720
|
+
const prefix = "dimina:";
|
|
721
|
+
const keys = [];
|
|
722
|
+
for (let i = 0; i < localStorage.length; i++) {
|
|
723
|
+
const key = localStorage.key(i);
|
|
724
|
+
if (key?.startsWith(prefix)) keys.push(key);
|
|
725
|
+
}
|
|
726
|
+
keys.forEach((key) => localStorage.removeItem(key));
|
|
727
|
+
};
|
|
728
|
+
}
|
|
729
|
+
if (typeof wx.getStorageInfoSync !== "function") {
|
|
730
|
+
wx.getStorageInfoSync = () => {
|
|
731
|
+
const prefix = "dimina:";
|
|
732
|
+
const keys = [];
|
|
733
|
+
let currentSize = 0;
|
|
734
|
+
for (let i = 0; i < localStorage.length; i++) {
|
|
735
|
+
const fullKey = localStorage.key(i);
|
|
736
|
+
if (!fullKey?.startsWith(prefix)) continue;
|
|
737
|
+
keys.push(fullKey.slice(prefix.length));
|
|
738
|
+
currentSize += (localStorage.getItem(fullKey) || "").length * 2;
|
|
739
|
+
}
|
|
740
|
+
return { keys, currentSize, limitSize: 10 * 1024 * 1024 };
|
|
741
|
+
};
|
|
742
|
+
}
|
|
743
|
+
if (typeof wx.request !== "function") {
|
|
744
|
+
wx.request = (opts) => {
|
|
745
|
+
const controller = new AbortController();
|
|
746
|
+
const method = (opts.method || "GET").toUpperCase();
|
|
747
|
+
let requestUrl = opts.url;
|
|
748
|
+
const init = {
|
|
749
|
+
method,
|
|
750
|
+
headers: { "Content-Type": "application/json", ...opts.header || {} },
|
|
751
|
+
signal: controller.signal
|
|
752
|
+
};
|
|
753
|
+
if (method === "GET" && opts.data && typeof opts.data === "object") {
|
|
754
|
+
const url = new URL(requestUrl, window.location.href);
|
|
755
|
+
Object.entries(opts.data).forEach(([key, value]) => {
|
|
756
|
+
url.searchParams.append(key, String(value));
|
|
757
|
+
});
|
|
758
|
+
requestUrl = url.toString();
|
|
759
|
+
} else if (opts.data != null) {
|
|
760
|
+
init.body = typeof opts.data === "string" ? opts.data : JSON.stringify(opts.data);
|
|
761
|
+
}
|
|
762
|
+
const timeoutId = Number(opts.timeout) > 0 ? window.setTimeout(() => controller.abort(), Number(opts.timeout)) : null;
|
|
763
|
+
fetch(requestUrl, init).then(async (response) => {
|
|
764
|
+
const headers = Object.fromEntries(response.headers.entries());
|
|
765
|
+
let data;
|
|
766
|
+
if (opts.dataType === "arraybuffer") data = await response.arrayBuffer();
|
|
767
|
+
else {
|
|
768
|
+
const text = await response.text();
|
|
769
|
+
if (opts.dataType === "text") data = text;
|
|
770
|
+
else {
|
|
771
|
+
try {
|
|
772
|
+
data = JSON.parse(text);
|
|
773
|
+
} catch {
|
|
774
|
+
data = text;
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
call(opts.success, { data, statusCode: response.status, header: headers, errMsg: "request:ok" });
|
|
779
|
+
}).catch((error) => {
|
|
780
|
+
call(opts.fail, { errMsg: `request:fail ${error instanceof Error ? error.message : String(error)}` });
|
|
781
|
+
}).finally(() => {
|
|
782
|
+
if (timeoutId != null) window.clearTimeout(timeoutId);
|
|
783
|
+
call(opts.complete, void 0);
|
|
784
|
+
});
|
|
785
|
+
return {
|
|
786
|
+
abort: () => controller.abort()
|
|
787
|
+
};
|
|
788
|
+
};
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
function setupApiCompatHook() {
|
|
792
|
+
const apply = () => {
|
|
793
|
+
const target = window;
|
|
794
|
+
if (!target.wx || typeof target.wx !== "object") {
|
|
795
|
+
target.wx = {};
|
|
796
|
+
}
|
|
797
|
+
const wx = target.wx;
|
|
798
|
+
ensureWxApi(wx);
|
|
799
|
+
return true;
|
|
800
|
+
};
|
|
801
|
+
if (apply()) return;
|
|
802
|
+
const timer = window.setInterval(() => {
|
|
803
|
+
if (apply()) window.clearInterval(timer);
|
|
804
|
+
}, 200);
|
|
805
|
+
}
|
|
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
|
+
|
|
916
|
+
// src/preload/windows/simulator.ts
|
|
917
|
+
setupApiCompatHook();
|
|
918
|
+
installSimulatorBridge();
|
|
919
|
+
installCustomApisBridge();
|
|
920
|
+
installTempFileBridge();
|
|
921
|
+
installConsoleInstrumentation();
|
|
922
|
+
installNativeHostBridge();
|
|
923
|
+
createAppDataSource().start(() => {
|
|
924
|
+
});
|
|
925
|
+
//# sourceMappingURL=simulator.cjs.map
|