@dimina-kit/devtools 0.3.2-dev.20260601115343 → 0.3.2-dev.20260610114009

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 (189) hide show
  1. package/README.md +49 -59
  2. package/dist/main/api.d.ts +1 -2
  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 +249 -122
  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 +6071 -1863
  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 +1333 -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 +1 -1
  19. package/dist/main/ipc/projects.d.ts +1 -1
  20. package/dist/main/ipc/session.d.ts +1 -1
  21. package/dist/main/ipc/settings.d.ts +1 -1
  22. package/dist/main/ipc/simulator-module.d.ts +6 -0
  23. package/dist/main/ipc/simulator-module.js +9 -1
  24. package/dist/main/ipc/simulator.d.ts +2 -2
  25. package/dist/main/ipc/simulator.js +29 -5
  26. package/dist/main/ipc/toolbar.d.ts +1 -1
  27. package/dist/main/ipc/views.d.ts +1 -1
  28. package/dist/main/ipc/views.js +40 -2
  29. package/dist/main/runtime/devtools-backend.d.ts +17 -0
  30. package/dist/main/runtime/devtools-backend.js +49 -0
  31. package/dist/main/runtime/miniapp-runtime.d.ts +39 -0
  32. package/dist/main/runtime/miniapp-runtime.js +17 -0
  33. package/dist/main/services/automation/exec.d.ts +27 -2
  34. package/dist/main/services/automation/exec.js +37 -3
  35. package/dist/main/services/automation/handlers/app.js +127 -11
  36. package/dist/main/services/automation/handlers/page.js +36 -19
  37. package/dist/main/services/automation/index.js +40 -13
  38. package/dist/main/services/automation/wait-active-page.d.ts +56 -0
  39. package/dist/main/services/automation/wait-active-page.js +71 -0
  40. package/dist/main/services/console-forward/index.d.ts +36 -0
  41. package/dist/main/services/console-forward/index.js +81 -0
  42. package/dist/main/services/dimina-resource-server.d.ts +7 -0
  43. package/dist/main/services/dimina-resource-server.js +99 -0
  44. package/dist/main/services/elements-forward/index.d.ts +66 -0
  45. package/dist/main/services/elements-forward/index.js +583 -0
  46. package/dist/main/services/layout/index.d.ts +22 -0
  47. package/dist/main/services/layout/index.js +25 -0
  48. package/dist/main/services/mcp/index.d.ts +1 -0
  49. package/dist/main/services/mcp/index.js +3 -0
  50. package/dist/main/services/mcp/server.d.ts +1 -1
  51. package/dist/main/services/mcp/server.js +1 -1
  52. package/dist/main/services/mcp/target-manager.d.ts +35 -0
  53. package/dist/main/services/mcp/target-manager.js +63 -1
  54. package/dist/main/services/mcp/tools/context-tools.js +15 -1
  55. package/dist/main/services/module.d.ts +1 -1
  56. package/dist/main/services/network-forward/index.d.ts +190 -0
  57. package/dist/main/services/network-forward/index.js +765 -0
  58. package/dist/main/services/notifications/renderer-notifier.d.ts +11 -0
  59. package/dist/main/services/notifications/renderer-notifier.js +7 -1
  60. package/dist/main/services/render-inspect/index.d.ts +41 -0
  61. package/dist/main/services/render-inspect/index.js +88 -0
  62. package/dist/main/services/safe-area/index.d.ts +17 -0
  63. package/dist/main/services/safe-area/index.js +59 -0
  64. package/dist/main/services/service-host-pool/pool.d.ts +197 -0
  65. package/dist/main/services/service-host-pool/pool.js +364 -0
  66. package/dist/main/services/simulator/custom-apis.d.ts +34 -0
  67. package/dist/main/services/simulator/custom-apis.js +22 -0
  68. package/dist/main/services/simulator-appdata/index.d.ts +35 -0
  69. package/dist/main/services/simulator-appdata/index.js +71 -0
  70. package/dist/main/services/simulator-current-page/index.d.ts +24 -0
  71. package/dist/main/services/simulator-current-page/index.js +19 -0
  72. package/dist/main/services/simulator-storage/index.d.ts +37 -2
  73. package/dist/main/services/simulator-storage/index.js +209 -32
  74. package/dist/main/services/simulator-storage/service-storage-ops.d.ts +40 -0
  75. package/dist/main/services/simulator-storage/service-storage-ops.js +67 -0
  76. package/dist/main/services/simulator-temp-files/index.d.ts +1 -1
  77. package/dist/main/services/simulator-temp-files/index.js +39 -17
  78. package/dist/main/services/simulator-wxml/index.d.ts +29 -0
  79. package/dist/main/services/simulator-wxml/index.js +28 -0
  80. package/dist/main/services/toolbar/toolbar-store.d.ts +3 -3
  81. package/dist/main/services/toolbar/toolbar-store.js +1 -18
  82. package/dist/main/services/views/devtools-tabs.d.ts +47 -0
  83. package/dist/main/services/views/devtools-tabs.js +95 -0
  84. package/dist/main/services/views/miniapp-partition.d.ts +80 -0
  85. package/dist/main/services/views/miniapp-partition.js +138 -0
  86. package/dist/main/services/views/simulator-session-policy.d.ts +28 -0
  87. package/dist/main/services/views/simulator-session-policy.js +82 -0
  88. package/dist/main/services/views/view-manager.d.ts +125 -0
  89. package/dist/main/services/views/view-manager.js +852 -4
  90. package/dist/main/services/workbench-context.d.ts +67 -7
  91. package/dist/main/services/workbench-context.js +6 -1
  92. package/dist/main/services/workspace/workspace-service.js +7 -13
  93. package/dist/main/utils/ipc-registry.d.ts +1 -1
  94. package/dist/main/utils/ipc-registry.js +21 -4
  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 +6 -80
  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 +67 -0
  106. package/dist/main/windows/service-host-window/create.js +138 -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 +30 -12
  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 +1935 -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 +244 -574
  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/index-CcJKzatF.js +50 -0
  143. package/dist/renderer/assets/{input-CCYS8Ave.js → input-QGx6FFX1.js} +2 -2
  144. package/dist/renderer/assets/ipc-transport-BT4QYQqu.css +1 -0
  145. package/dist/renderer/assets/{ipc-transport-Bn4KXvhu.js → ipc-transport-DvZvwK-Z.js} +2 -2
  146. package/dist/renderer/assets/{popover-CH4rwpdt.js → popover-BOH1If1J.js} +2 -2
  147. package/dist/renderer/assets/select-C7JQ8G5N.js +2 -0
  148. package/dist/renderer/assets/{settings-CMTB-t0x.js → settings-DpAbTJyF.js} +2 -2
  149. package/dist/renderer/assets/{settings-api-Csdngf9Z.js → settings-api-RD2IZF53.js} +2 -2
  150. package/dist/renderer/assets/{workbenchSettings-CODFCzOg.js → workbenchSettings-CNJX4Qna.js} +2 -2
  151. package/dist/renderer/entries/main/index.html +5 -5
  152. package/dist/renderer/entries/popover/index.html +5 -5
  153. package/dist/renderer/entries/settings/index.html +5 -5
  154. package/dist/renderer/entries/workbench-settings/index.html +4 -4
  155. package/dist/service-host/preload.cjs +254 -0
  156. package/dist/service-host/service.html +10 -0
  157. package/dist/service-host/sourcemap-rewrite.cjs +58 -0
  158. package/dist/service-host/sync-api-patch.js +20 -0
  159. package/dist/service-host/sync-impls/menu-button-geometry.js +8 -0
  160. package/dist/service-host/sync-impls/menu-button.js +16 -0
  161. package/dist/service-host/sync-impls/storage.js +50 -0
  162. package/dist/service-host/sync-impls/system-info.js +54 -0
  163. package/dist/shared/appdata-accumulator.d.ts +95 -0
  164. package/dist/shared/appdata-accumulator.js +213 -0
  165. package/dist/shared/bridge-channels.d.ts +378 -0
  166. package/dist/shared/bridge-channels.js +81 -0
  167. package/dist/shared/ipc-channels.d.ts +84 -1
  168. package/dist/shared/ipc-channels.js +90 -10
  169. package/dist/shared/ipc-schemas.d.ts +59 -2
  170. package/dist/shared/ipc-schemas.js +64 -3
  171. package/dist/shared/open-in-editor.d.ts +71 -0
  172. package/dist/shared/open-in-editor.js +138 -0
  173. package/dist/shared/simulator-api-metadata.d.ts +21 -0
  174. package/dist/shared/simulator-api-metadata.js +23 -0
  175. package/dist/shared/types.d.ts +2 -39
  176. package/dist/simulator/assets/device-shell-DsdcNEkt.css +1 -0
  177. package/dist/simulator/assets/device-shell-fH2cI-3q.js +2 -0
  178. package/dist/simulator/assets/jsx-runtime-P6ZegaOf.js +2 -0
  179. package/dist/simulator/assets/simulator-DHylZf9Z.js +10 -0
  180. package/dist/simulator/assets/simulator-mini-app-BDNu5n26.js +2 -0
  181. package/dist/simulator/device-shell/menu-button-geometry.js +8 -0
  182. package/dist/simulator/simulator.html +2 -112
  183. package/package.json +12 -12
  184. package/dist/main/utils/disposable.d.ts +0 -18
  185. package/dist/main/utils/disposable.js +0 -67
  186. package/dist/renderer/assets/index-BDMxXUfn.js +0 -50
  187. package/dist/renderer/assets/ipc-transport-Cu7tubyg.css +0 -1
  188. package/dist/renderer/assets/select-Ct4-sijm.js +0 -2
  189. package/dist/simulator/assets/simulator-B4e3c6_O.js +0 -9
@@ -0,0 +1,213 @@
1
+ /**
2
+ * Framework-agnostic AppData accumulator.
3
+ *
4
+ * The dimina runtime emits two service→render messages relevant to the AppData
5
+ * panel, identical in shape on BOTH container paths:
6
+ * • update batches `{type:'ub', body:{bridgeId, updates:[{moduleId,data}]}}`
7
+ * — each `data` is a partial setData patch.
8
+ * • instance init: `type === 'page_*'`, body `{bridgeId, path, data}` with the
9
+ * COMPLETE initial state.
10
+ *
11
+ * Default (dimina-fe) path: the simulator preload sniffs these as Worker
12
+ * `message` events (app-data.ts). Native-host path: they flow service→render
13
+ * through bridge-router (SERVICE_PUBLISH). Both feed this one accumulator so the
14
+ * decode/merge/page-only/R6 policy can't drift between modes.
15
+ */
16
+ /**
17
+ * Decode a service→render message into AppData entries, or null when it is not
18
+ * AppData-relevant. Policy: surface PAGE entries only — component entries are
19
+ * dropped (they sometimes flow on a bridge id distinct from their owning page's
20
+ * and never receive pageUnload, which would manifest as ghost tabs).
21
+ */
22
+ export function decodeWorkerMessage(message) {
23
+ let payload = message;
24
+ if (typeof payload === 'string') {
25
+ try {
26
+ payload = JSON.parse(payload);
27
+ }
28
+ catch {
29
+ return null;
30
+ }
31
+ }
32
+ if (!payload || typeof payload !== 'object')
33
+ return null;
34
+ const record = payload;
35
+ if (record.type === 'ub') {
36
+ const body = record.body;
37
+ if (!body || typeof body !== 'object')
38
+ return null;
39
+ if (typeof body.bridgeId !== 'string' || !Array.isArray(body.updates))
40
+ return null;
41
+ const out = [];
42
+ for (const u of body.updates) {
43
+ if (!u || typeof u.moduleId !== 'string')
44
+ continue;
45
+ if (!u.moduleId.startsWith('page_'))
46
+ continue;
47
+ out.push({ mode: 'patch', bridgeId: body.bridgeId, moduleId: u.moduleId, data: u.data });
48
+ }
49
+ return out.length > 0 ? out : null;
50
+ }
51
+ if (typeof record.type === 'string' && record.type.startsWith('page_')) {
52
+ const body = record.body;
53
+ if (!body || typeof body !== 'object')
54
+ return null;
55
+ if (typeof body.bridgeId !== 'string' || typeof body.path !== 'string')
56
+ return null;
57
+ if (!body.data || typeof body.data !== 'object')
58
+ return null;
59
+ return [{
60
+ mode: 'init',
61
+ bridgeId: body.bridgeId,
62
+ moduleId: record.type,
63
+ componentPath: body.path,
64
+ data: body.data,
65
+ }];
66
+ }
67
+ return null;
68
+ }
69
+ /** main→worker direction: container signals page teardown so cache can evict. */
70
+ export function decodeOutgoingMessage(message) {
71
+ let payload = message;
72
+ if (typeof payload === 'string') {
73
+ try {
74
+ payload = JSON.parse(payload);
75
+ }
76
+ catch {
77
+ return null;
78
+ }
79
+ }
80
+ if (!payload || typeof payload !== 'object')
81
+ return null;
82
+ const r = payload;
83
+ if (typeof r.type !== 'string')
84
+ return null;
85
+ return {
86
+ type: r.type,
87
+ bridgeId: typeof r.body?.bridgeId === 'string' ? r.body.bridgeId : undefined,
88
+ };
89
+ }
90
+ /** Convert a decoded entry to the normalized accumulator input. */
91
+ export function decodedToInput(entry) {
92
+ const input = {
93
+ bridgeId: entry.bridgeId,
94
+ moduleId: entry.moduleId,
95
+ data: entry.data,
96
+ mode: entry.mode,
97
+ };
98
+ if (entry.mode === 'init')
99
+ input.componentPath = entry.componentPath;
100
+ return input;
101
+ }
102
+ /**
103
+ * Cumulative per-(bridgeId, moduleId) setData state. Pure data structure — no
104
+ * Worker / IPC / DOM. Callers own transport (publish/emit) and the automation
105
+ * mirror.
106
+ */
107
+ export class AppDataAccumulator {
108
+ cache = new Map();
109
+ // Bridges in insertion order — drives the `bridges` array (stable tab order).
110
+ bridgeOrder = [];
111
+ // Page path per bridge: set from `page_*` init's body.path (the page route).
112
+ bridgePagePath = new Map();
113
+ recordBridge(bridgeId) {
114
+ if (!this.bridgeOrder.includes(bridgeId))
115
+ this.bridgeOrder.push(bridgeId);
116
+ }
117
+ /**
118
+ * Apply one entry. Returns true if it was accepted (a mutation worth
119
+ * republishing), false if dropped (missing ids, or the R6 gate).
120
+ */
121
+ apply(input) {
122
+ if (!input.bridgeId || !input.moduleId)
123
+ return false;
124
+ // R6: drop ub patches whose bridge has never been initialised. dimina
125
+ // dispatches pageUnload → onUnload, whose setData produces a late `ub`
126
+ // arriving AFTER clearBridge; without this gate it would resurrect the
127
+ // unloaded bridge as a ghost tab.
128
+ if (input.mode !== 'init' && !this.bridgePagePath.has(input.bridgeId))
129
+ return false;
130
+ const key = `${input.bridgeId}/${input.moduleId}`;
131
+ const prev = this.cache.get(key);
132
+ const incoming = input.data && typeof input.data === 'object'
133
+ ? input.data
134
+ : {};
135
+ // init = full-state replace; patch = merge into previous (setData semantics)
136
+ const merged = input.mode === 'init'
137
+ ? { ...incoming }
138
+ : { ...(prev?.data ?? {}), ...incoming };
139
+ const componentPath = input.componentPath ?? prev?.componentPath;
140
+ const next = componentPath !== undefined
141
+ ? { componentPath, data: merged }
142
+ : { data: merged };
143
+ this.cache.set(key, next);
144
+ this.recordBridge(input.bridgeId);
145
+ if (input.mode === 'init' && input.moduleId.startsWith('page_') && input.componentPath) {
146
+ this.bridgePagePath.set(input.bridgeId, input.componentPath);
147
+ }
148
+ return true;
149
+ }
150
+ /** Evict every entry for a bridge (page teardown). */
151
+ clearBridge(bridgeId) {
152
+ const prefix = `${bridgeId}/`;
153
+ for (const key of [...this.cache.keys()]) {
154
+ if (key.startsWith(prefix))
155
+ this.cache.delete(key);
156
+ }
157
+ const idx = this.bridgeOrder.indexOf(bridgeId);
158
+ if (idx >= 0)
159
+ this.bridgeOrder.splice(idx, 1);
160
+ this.bridgePagePath.delete(bridgeId);
161
+ }
162
+ /** The full cumulative snapshot for the panel. */
163
+ snapshot() {
164
+ const bridges = [];
165
+ for (const id of this.bridgeOrder) {
166
+ bridges.push({ id, pagePath: this.bridgePagePath.get(id) ?? null });
167
+ }
168
+ const entries = {};
169
+ for (const [key, entry] of this.cache) {
170
+ const slash = key.indexOf('/');
171
+ if (slash < 0)
172
+ continue;
173
+ const bridgeId = key.slice(0, slash);
174
+ const moduleId = key.slice(slash + 1);
175
+ if (!entries[bridgeId])
176
+ entries[bridgeId] = {};
177
+ const displayKey = entry.componentPath ?? moduleId;
178
+ entries[bridgeId][displayKey] = entry.data;
179
+ }
180
+ return { bridges, entries };
181
+ }
182
+ /**
183
+ * The current reactive page state for a bridge: shallow-merge of `entry.data`
184
+ * across every cache entry whose key starts with `${bridgeId}/`, in insertion
185
+ * order (later entries win on key conflicts). `{}` when no entries match
186
+ * (unknown bridge / after clearBridge). Pure, no side effects.
187
+ */
188
+ pageData(bridgeId) {
189
+ const merged = {};
190
+ for (const [key, entry] of this.cache) {
191
+ const slash = key.indexOf('/');
192
+ if (slash < 0)
193
+ continue;
194
+ if (key.slice(0, slash) !== bridgeId)
195
+ continue;
196
+ Object.assign(merged, entry.data);
197
+ }
198
+ return merged;
199
+ }
200
+ /** Flat `key → data` map for the `__simulatorData.getAppdata()` mirror. */
201
+ flat() {
202
+ const data = {};
203
+ for (const [key, entry] of this.cache)
204
+ data[key] = entry.data;
205
+ return data;
206
+ }
207
+ clear() {
208
+ this.cache.clear();
209
+ this.bridgeOrder.length = 0;
210
+ this.bridgePagePath.clear();
211
+ }
212
+ }
213
+ //# sourceMappingURL=appdata-accumulator.js.map
@@ -0,0 +1,378 @@
1
+ import type { NativeDeviceInfo } from './ipc-channels.js';
2
+ export declare const BRIDGE_CHANNELS: {
3
+ readonly SPAWN: "dmb:spawn";
4
+ readonly DISPOSE: "dmb:dispose";
5
+ readonly PAGE_OPEN: "dmb:page:open";
6
+ readonly PAGE_CLOSE: "dmb:page:close";
7
+ readonly PAGE_LIFECYCLE: "dmb:page:lifecycle";
8
+ readonly NAV_CALLBACK: "dmb:nav:callback";
9
+ readonly SERVICE_INVOKE: "dmb:service:invoke";
10
+ readonly SERVICE_PUBLISH: "dmb:service:publish";
11
+ readonly RENDER_INVOKE: "dmb:render:invoke";
12
+ readonly RENDER_PUBLISH: "dmb:render:publish";
13
+ readonly TO_SERVICE: "dmb:to-service";
14
+ readonly TO_RENDER: "dmb:to-render";
15
+ readonly SIMULATOR_API: "dmb:simulator-api";
16
+ /** simulator → main: ack of an API_CALL request (carries success/fail args). */
17
+ readonly API_RESPONSE: "dmb:api:response";
18
+ /**
19
+ * simulator webview preload → main (sendSync): "is native-host mode on?".
20
+ * The guest preload can't read the launch `process.env`, so it asks main
21
+ * (which can) at install time. Reply is `e.returnValue = boolean`.
22
+ */
23
+ readonly NATIVE_HOST_ENABLED: "dmb:native-host-enabled";
24
+ /**
25
+ * simulator (DeviceShell) → main: the visible top-of-stack page bridgeId.
26
+ * Main has no z-order concept — the active page lives only in DeviceShell's
27
+ * ShellState — so devtools panels / automation that must target "the current
28
+ * page's render webContents" resolve it through this signal. Fire-and-forget.
29
+ */
30
+ readonly ACTIVE_PAGE: "dmb:active-page";
31
+ /**
32
+ * simulator (DeviceShell) → main: the FULL ordered page stack (bottom→top)
33
+ * whenever it changes. Main has no stack of its own (it only learns the
34
+ * active bridgeId via ACTIVE_PAGE), so automation's `App.getPageStack` needs
35
+ * this to report multi-page stacks. Fire-and-forget.
36
+ */
37
+ readonly PAGE_STACK: "dmb:page-stack";
38
+ };
39
+ export declare const SIMULATOR_EVENTS: {
40
+ readonly DOM_READY: "simulator:dom-ready";
41
+ readonly NAV_BAR: "simulator:navigation-bar";
42
+ readonly NAV_ACTION: "simulator:nav-action";
43
+ readonly TAB_ACTION: "simulator:tab-action";
44
+ /** main → simulator: invoke a wx.* API on the simulator-resident MiniApp. */
45
+ readonly API_CALL: "simulator:api-call";
46
+ /**
47
+ * main → simulator: the renderer toolbar picked a different device. Carries a
48
+ * NativeDeviceInfo; DeviceShell resizes the bezel + re-renders status bar /
49
+ * notch. The race-free INITIAL device rides NativeHostConfig.device (read
50
+ * synchronously at preload bridge-install); this event covers live changes.
51
+ */
52
+ readonly DEVICE_CHANGE: "simulator:device-change";
53
+ };
54
+ export declare const CHANNELS: {
55
+ readonly SPAWN: "dmb:spawn";
56
+ readonly DISPOSE: "dmb:dispose";
57
+ readonly PAGE_OPEN: "dmb:page:open";
58
+ readonly PAGE_CLOSE: "dmb:page:close";
59
+ readonly PAGE_LIFECYCLE: "dmb:page:lifecycle";
60
+ readonly NAV_CALLBACK: "dmb:nav:callback";
61
+ readonly SERVICE_INVOKE: "dmb:service:invoke";
62
+ readonly SERVICE_PUBLISH: "dmb:service:publish";
63
+ readonly RENDER_INVOKE: "dmb:render:invoke";
64
+ readonly RENDER_PUBLISH: "dmb:render:publish";
65
+ readonly TO_SERVICE: "dmb:to-service";
66
+ readonly TO_RENDER: "dmb:to-render";
67
+ readonly SIMULATOR_API: "dmb:simulator-api";
68
+ /** simulator → main: ack of an API_CALL request (carries success/fail args). */
69
+ readonly API_RESPONSE: "dmb:api:response";
70
+ /**
71
+ * simulator webview preload → main (sendSync): "is native-host mode on?".
72
+ * The guest preload can't read the launch `process.env`, so it asks main
73
+ * (which can) at install time. Reply is `e.returnValue = boolean`.
74
+ */
75
+ readonly NATIVE_HOST_ENABLED: "dmb:native-host-enabled";
76
+ /**
77
+ * simulator (DeviceShell) → main: the visible top-of-stack page bridgeId.
78
+ * Main has no z-order concept — the active page lives only in DeviceShell's
79
+ * ShellState — so devtools panels / automation that must target "the current
80
+ * page's render webContents" resolve it through this signal. Fire-and-forget.
81
+ */
82
+ readonly ACTIVE_PAGE: "dmb:active-page";
83
+ /**
84
+ * simulator (DeviceShell) → main: the FULL ordered page stack (bottom→top)
85
+ * whenever it changes. Main has no stack of its own (it only learns the
86
+ * active bridgeId via ACTIVE_PAGE), so automation's `App.getPageStack` needs
87
+ * this to report multi-page stacks. Fire-and-forget.
88
+ */
89
+ readonly PAGE_STACK: "dmb:page-stack";
90
+ };
91
+ /**
92
+ * Reply to a `NATIVE_HOST_ENABLED` sendSync. Main supplies the render-host
93
+ * file:// URLs (computed with node:path/url, which the simulator webview's
94
+ * preload lacks) so the preload can build the native-host bridge.
95
+ */
96
+ export interface NativeHostConfig {
97
+ enabled: boolean;
98
+ renderHostHtmlUrl: string;
99
+ renderPreloadUrl: string;
100
+ /**
101
+ * The currently-selected device, if the renderer already pushed it before the
102
+ * simulator WCV's preload installed (it does — SetDeviceInfo precedes
103
+ * AttachNative). DeviceShell reads this as its initial device so it never
104
+ * mounts with the wrong bezel size while waiting for the first DEVICE_CHANGE.
105
+ * Absent only on the pre-spawn default path.
106
+ */
107
+ device?: NativeDeviceInfo;
108
+ }
109
+ export type BridgeChannel = typeof BRIDGE_CHANNELS[keyof typeof BRIDGE_CHANNELS];
110
+ export type BridgeTarget = 'service' | 'render' | 'container';
111
+ export type BridgeMessageType = 'loadResource' | 'serviceResourceLoaded' | 'renderResourceLoaded' | 'resourceLoaded' | 'firstRender' | 'appShow' | 'appHide' | 'stackShow' | 'stackHide' | 'pageShow' | 'pageHide' | 'pageReady' | 'pageUnload' | 'pageScroll' | 'pageResize' | 'pageRouteDone' | 'mC' | 'mR' | 'mU' | 't' | 'u' | 'ub' | 'triggerCallback' | 'invokeAPI' | 'h5SdkAction' | 'componentError' | 'domReady' | 'print' | 'renderHostReady' | 'serviceHostError' | string;
112
+ export interface MessageEnvelope<TBody extends Record<string, unknown> = Record<string, unknown>> {
113
+ type: BridgeMessageType;
114
+ target: BridgeTarget;
115
+ body: TBody;
116
+ }
117
+ export interface HostEnvSnapshot {
118
+ brand: string;
119
+ model: string;
120
+ platform: string;
121
+ system: string;
122
+ version: string;
123
+ SDKVersion: string;
124
+ pixelRatio: number;
125
+ screenWidth: number;
126
+ screenHeight: number;
127
+ windowWidth: number;
128
+ windowHeight: number;
129
+ statusBarHeight: number;
130
+ language: string;
131
+ theme: string;
132
+ [key: string]: unknown;
133
+ }
134
+ /**
135
+ * Map the renderer's logical device metrics onto the subset of a
136
+ * HostEnvSnapshot the service-host window's `getSystemInfoSync` consumes.
137
+ * `windowHeight` excludes the status bar (the page area); `windowWidth` has no
138
+ * horizontal chrome. Zoom is intentionally absent — it is a display scale, not
139
+ * a logical-size change.
140
+ *
141
+ * Single source of truth for the device→host-env mapping, shared by the live
142
+ * `SetDeviceInfo` IPC path (main/ipc/simulator.ts) and the per-spawn host-env
143
+ * seeding (main/ipc/bridge-router.ts). Keeping them identical guarantees a
144
+ * service-host RESPAWN after a device change reports the same dims the live
145
+ * update pushed — otherwise a respawn would silently revert to the boot device.
146
+ */
147
+ export declare function deviceInfoToHostEnv(d: NativeDeviceInfo): Partial<HostEnvSnapshot>;
148
+ /**
149
+ * Subset of WeChat page `window` config plus tabBar list, parsed from
150
+ * `app-config.json` (`{app:{window,tabBar,pages,entryPagePath}, modules:{[pagePath]:{window}}}`).
151
+ * Mirrors mergePageConfig in dimina-fe: page-level keys override app-level.
152
+ */
153
+ export interface PageWindowConfig {
154
+ navigationBarTitleText?: string;
155
+ navigationBarBackgroundColor?: string;
156
+ navigationBarTextStyle?: 'black' | 'white';
157
+ navigationStyle?: 'default' | 'custom';
158
+ homeButton?: boolean;
159
+ backgroundColor?: string;
160
+ backgroundTextStyle?: 'dark' | 'light';
161
+ enablePullDownRefresh?: boolean;
162
+ disableScroll?: boolean;
163
+ [key: string]: unknown;
164
+ }
165
+ export interface TabBarItem {
166
+ pagePath: string;
167
+ text?: string;
168
+ iconPath?: string;
169
+ selectedIconPath?: string;
170
+ }
171
+ export interface TabBarConfig {
172
+ color?: string;
173
+ selectedColor?: string;
174
+ backgroundColor?: string;
175
+ borderStyle?: 'black' | 'white';
176
+ position?: 'bottom' | 'top';
177
+ custom?: boolean;
178
+ list: TabBarItem[];
179
+ }
180
+ export interface AppManifest {
181
+ entryPagePath: string;
182
+ pages: string[];
183
+ tabBar?: TabBarConfig;
184
+ }
185
+ export interface SpawnRequest {
186
+ simulatorWcId?: number;
187
+ appId: string;
188
+ bridgeId?: string;
189
+ pagePath?: string;
190
+ scene?: number;
191
+ query?: Record<string, unknown>;
192
+ apiNamespaces?: string[];
193
+ hostEnvSnapshot?: Partial<HostEnvSnapshot>;
194
+ pkgRoot?: string;
195
+ root?: string;
196
+ /**
197
+ * Base URL of the dev server that serves the compiled mini-app, i.e. the
198
+ * SAME origin the simulator page was loaded from (`http://localhost:<port>/`).
199
+ * The dev server statically serves `<appId>/<root>/…` (app-config.json,
200
+ * logic.js, page bundles, styles) — exactly what the default dimina-fe
201
+ * `<webview>` fetches. The native-host render + service hosts source every
202
+ * resource from here, so we don't need a second resource server or a local
203
+ * compiled-output path. Trailing slash expected.
204
+ */
205
+ resourceBaseUrl?: string;
206
+ }
207
+ export interface SpawnResult {
208
+ appSessionId: string;
209
+ bridgeId: string;
210
+ pagePath: string;
211
+ serviceWcId: number;
212
+ resourceBaseUrl: string;
213
+ manifest: AppManifest;
214
+ rootWindowConfig: PageWindowConfig;
215
+ }
216
+ export interface PageOpenRequest {
217
+ appSessionId: string;
218
+ pagePath: string;
219
+ query?: Record<string, unknown>;
220
+ bridgeId?: string;
221
+ }
222
+ export interface PageOpenResult {
223
+ bridgeId: string;
224
+ pagePath: string;
225
+ windowConfig: PageWindowConfig;
226
+ isTab: boolean;
227
+ }
228
+ export interface PageClosePayload {
229
+ bridgeId: string;
230
+ }
231
+ export interface DisposePayload {
232
+ /** AppSession root bridgeId (legacy) or any page bridgeId. */
233
+ bridgeId: string;
234
+ }
235
+ export type PageLifecycleEvent = 'pageShow' | 'pageHide' | 'pageUnload' | 'stackShow' | 'stackHide' | 'appShow' | 'appHide';
236
+ export interface PageLifecyclePayload {
237
+ appSessionId: string;
238
+ bridgeId: string;
239
+ event: PageLifecycleEvent;
240
+ }
241
+ /**
242
+ * Sent by simulator after a routing action (navigateTo etc.) completes so the
243
+ * main process can call sendCallback() against the original service-issued
244
+ * success/fail/complete ids.
245
+ */
246
+ export interface NavCallbackPayload {
247
+ appSessionId: string;
248
+ ok: boolean;
249
+ errMsg: string;
250
+ callbacks: {
251
+ success?: unknown;
252
+ fail?: unknown;
253
+ complete?: unknown;
254
+ };
255
+ }
256
+ export interface ServiceInvokePayload {
257
+ bridgeId: string;
258
+ msg: MessageEnvelope;
259
+ }
260
+ export interface ServicePublishPayload {
261
+ bridgeId: string;
262
+ targetBridgeId?: string;
263
+ msg: MessageEnvelope;
264
+ }
265
+ /**
266
+ * `dmb:active-page` — simulator (DeviceShell) → main. Records which page is the
267
+ * visible top-of-stack so main-side services (WXML/element-inspect, automation)
268
+ * can resolve "the active page's render webContents" by bridgeId.
269
+ */
270
+ export interface ActivePagePayload {
271
+ appSessionId: string;
272
+ bridgeId: string;
273
+ }
274
+ /**
275
+ * `dmb:page-stack` — simulator (DeviceShell) → main. The full ordered page
276
+ * stack (bottom→top) so `App.getPageStack` can report multi-page stacks.
277
+ */
278
+ export interface PageStackEntry {
279
+ pagePath: string;
280
+ query: Record<string, unknown>;
281
+ }
282
+ export interface PageStackPayload {
283
+ appSessionId: string;
284
+ stack: PageStackEntry[];
285
+ }
286
+ export interface RenderInvokePayload {
287
+ bridgeId: string;
288
+ msg: MessageEnvelope;
289
+ }
290
+ export interface RenderPublishPayload {
291
+ bridgeId: string;
292
+ msg: MessageEnvelope;
293
+ }
294
+ export interface ToServicePayload {
295
+ msg: MessageEnvelope;
296
+ }
297
+ export interface ToRenderPayload {
298
+ msg: MessageEnvelope;
299
+ }
300
+ export interface SimulatorApiInvokePayload {
301
+ bridgeId: string;
302
+ name: string;
303
+ params: unknown;
304
+ }
305
+ /**
306
+ * `simulator:nav-action` — main → simulator window, carries router/tabBar
307
+ * intentions. Simulator owns the visual stack state and decides whether to
308
+ * push/pop webviews; it then calls back PAGE_LIFECYCLE + NAV_CALLBACK.
309
+ */
310
+ export interface NavActionPayload {
311
+ appSessionId: string;
312
+ bridgeId: string;
313
+ name: 'navigateTo' | 'navigateBack' | 'redirectTo' | 'reLaunch' | 'switchTab';
314
+ params: Record<string, unknown>;
315
+ callbacks: {
316
+ success?: unknown;
317
+ fail?: unknown;
318
+ complete?: unknown;
319
+ };
320
+ }
321
+ /**
322
+ * `simulator:api-call` — main → simulator. Fallback path used when an
323
+ * invokeAPI name is not registered in the main-process `ctx.simulatorApis`
324
+ * registry: the simulator-resident MiniApp owns the wx.* handler (it can
325
+ * read DOM, open file pickers, etc.), so we forward the call there and wait
326
+ * for an `API_RESPONSE` ack.
327
+ */
328
+ export interface ApiCallPayload {
329
+ appSessionId: string;
330
+ bridgeId: string;
331
+ requestId: string;
332
+ name: string;
333
+ params: Record<string, unknown>;
334
+ callbacks: {
335
+ success?: unknown;
336
+ fail?: unknown;
337
+ complete?: unknown;
338
+ };
339
+ }
340
+ /**
341
+ * `dmb:api:response` — simulator → main. Ack for an `API_CALL`. Main looks
342
+ * up `requestId` in its pending map and fires the original service-side
343
+ * success/fail/complete callbacks accordingly.
344
+ */
345
+ export interface ApiResponsePayload {
346
+ appSessionId: string;
347
+ requestId: string;
348
+ ok: boolean;
349
+ /** Argument the simulator-side success/fail callback was invoked with. */
350
+ result?: unknown;
351
+ errMsg?: string;
352
+ /**
353
+ * Persistent-subscription marker (`keep: true` APIs, e.g.
354
+ * `audioListen`). When set, this response is one of potentially many
355
+ * fires of the same subscription: main re-fires the service-side success
356
+ * callback but keeps the pendingApiCall alive (does not delete it or fire
357
+ * `complete`) so subsequent fires of the same `requestId` are delivered.
358
+ * Cleanup happens on page/app teardown instead.
359
+ */
360
+ keep?: boolean;
361
+ }
362
+ /**
363
+ * `simulator:tab-action` — main → simulator window, carries dynamic TabBar
364
+ * API calls. Simulator updates TabBar React state and acknowledges via
365
+ * NAV_CALLBACK so the service-side wx.* callback fires.
366
+ */
367
+ export interface TabActionPayload {
368
+ appSessionId: string;
369
+ bridgeId: string;
370
+ name: 'setTabBarStyle' | 'setTabBarItem' | 'showTabBar' | 'hideTabBar' | 'setTabBarBadge' | 'removeTabBarBadge' | 'showTabBarRedDot' | 'hideTabBarRedDot';
371
+ params: Record<string, unknown>;
372
+ callbacks: {
373
+ success?: unknown;
374
+ fail?: unknown;
375
+ complete?: unknown;
376
+ };
377
+ }
378
+ //# sourceMappingURL=bridge-channels.d.ts.map
@@ -0,0 +1,81 @@
1
+ export const BRIDGE_CHANNELS = {
2
+ SPAWN: 'dmb:spawn',
3
+ DISPOSE: 'dmb:dispose',
4
+ PAGE_OPEN: 'dmb:page:open',
5
+ PAGE_CLOSE: 'dmb:page:close',
6
+ PAGE_LIFECYCLE: 'dmb:page:lifecycle',
7
+ NAV_CALLBACK: 'dmb:nav:callback',
8
+ SERVICE_INVOKE: 'dmb:service:invoke',
9
+ SERVICE_PUBLISH: 'dmb:service:publish',
10
+ RENDER_INVOKE: 'dmb:render:invoke',
11
+ RENDER_PUBLISH: 'dmb:render:publish',
12
+ TO_SERVICE: 'dmb:to-service',
13
+ TO_RENDER: 'dmb:to-render',
14
+ SIMULATOR_API: 'dmb:simulator-api',
15
+ /** simulator → main: ack of an API_CALL request (carries success/fail args). */
16
+ API_RESPONSE: 'dmb:api:response',
17
+ /**
18
+ * simulator webview preload → main (sendSync): "is native-host mode on?".
19
+ * The guest preload can't read the launch `process.env`, so it asks main
20
+ * (which can) at install time. Reply is `e.returnValue = boolean`.
21
+ */
22
+ NATIVE_HOST_ENABLED: 'dmb:native-host-enabled',
23
+ /**
24
+ * simulator (DeviceShell) → main: the visible top-of-stack page bridgeId.
25
+ * Main has no z-order concept — the active page lives only in DeviceShell's
26
+ * ShellState — so devtools panels / automation that must target "the current
27
+ * page's render webContents" resolve it through this signal. Fire-and-forget.
28
+ */
29
+ ACTIVE_PAGE: 'dmb:active-page',
30
+ /**
31
+ * simulator (DeviceShell) → main: the FULL ordered page stack (bottom→top)
32
+ * whenever it changes. Main has no stack of its own (it only learns the
33
+ * active bridgeId via ACTIVE_PAGE), so automation's `App.getPageStack` needs
34
+ * this to report multi-page stacks. Fire-and-forget.
35
+ */
36
+ PAGE_STACK: 'dmb:page-stack',
37
+ };
38
+ export const SIMULATOR_EVENTS = {
39
+ DOM_READY: 'simulator:dom-ready',
40
+ NAV_BAR: 'simulator:navigation-bar',
41
+ NAV_ACTION: 'simulator:nav-action',
42
+ TAB_ACTION: 'simulator:tab-action',
43
+ /** main → simulator: invoke a wx.* API on the simulator-resident MiniApp. */
44
+ API_CALL: 'simulator:api-call',
45
+ /**
46
+ * main → simulator: the renderer toolbar picked a different device. Carries a
47
+ * NativeDeviceInfo; DeviceShell resizes the bezel + re-renders status bar /
48
+ * notch. The race-free INITIAL device rides NativeHostConfig.device (read
49
+ * synchronously at preload bridge-install); this event covers live changes.
50
+ */
51
+ DEVICE_CHANGE: 'simulator:device-change',
52
+ };
53
+ export const CHANNELS = BRIDGE_CHANNELS;
54
+ /**
55
+ * Map the renderer's logical device metrics onto the subset of a
56
+ * HostEnvSnapshot the service-host window's `getSystemInfoSync` consumes.
57
+ * `windowHeight` excludes the status bar (the page area); `windowWidth` has no
58
+ * horizontal chrome. Zoom is intentionally absent — it is a display scale, not
59
+ * a logical-size change.
60
+ *
61
+ * Single source of truth for the device→host-env mapping, shared by the live
62
+ * `SetDeviceInfo` IPC path (main/ipc/simulator.ts) and the per-spawn host-env
63
+ * seeding (main/ipc/bridge-router.ts). Keeping them identical guarantees a
64
+ * service-host RESPAWN after a device change reports the same dims the live
65
+ * update pushed — otherwise a respawn would silently revert to the boot device.
66
+ */
67
+ export function deviceInfoToHostEnv(d) {
68
+ return {
69
+ brand: d.brand,
70
+ model: d.model,
71
+ system: d.system,
72
+ platform: d.platform,
73
+ pixelRatio: d.pixelRatio,
74
+ screenWidth: d.screenWidth,
75
+ screenHeight: d.screenHeight,
76
+ windowWidth: d.screenWidth,
77
+ windowHeight: Math.max(0, d.screenHeight - d.statusBarHeight),
78
+ statusBarHeight: d.statusBarHeight,
79
+ };
80
+ }
81
+ //# sourceMappingURL=bridge-channels.js.map