@dimina-kit/devtools 0.3.2-dev.20260601115343 → 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 +49 -59
- package/dist/main/api.d.ts +1 -2
- package/dist/main/api.js +5 -1
- package/dist/main/app/app.d.ts +15 -5
- package/dist/main/app/app.js +242 -122
- 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 +5812 -1729
- 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 +1 -1
- 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 +9 -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 +1 -1
- package/dist/main/ipc/views.js +40 -2
- 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 +22 -0
- package/dist/main/services/layout/index.js +25 -0
- 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/index.d.ts +1 -1
- package/dist/main/services/simulator-temp-files/index.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/toolbar/toolbar-store.d.ts +3 -3
- package/dist/main/services/toolbar/toolbar-store.js +1 -18
- 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 +125 -0
- package/dist/main/services/views/view-manager.js +839 -4
- package/dist/main/services/workbench-context.d.ts +67 -7
- package/dist/main/services/workbench-context.js +6 -1
- package/dist/main/services/workspace/workspace-service.js +7 -13
- package/dist/main/utils/ipc-registry.d.ts +1 -1
- package/dist/main/utils/ipc-registry.js +21 -4
- 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 +30 -12
- 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 +1935 -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 +244 -574
- 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/index-CcJKzatF.js +50 -0
- package/dist/renderer/assets/{input-CCYS8Ave.js → input-QGx6FFX1.js} +2 -2
- package/dist/renderer/assets/ipc-transport-BT4QYQqu.css +1 -0
- package/dist/renderer/assets/{ipc-transport-Bn4KXvhu.js → ipc-transport-DvZvwK-Z.js} +2 -2
- package/dist/renderer/assets/{popover-CH4rwpdt.js → popover-BOH1If1J.js} +2 -2
- package/dist/renderer/assets/select-C7JQ8G5N.js +2 -0
- package/dist/renderer/assets/{settings-CMTB-t0x.js → settings-DpAbTJyF.js} +2 -2
- package/dist/renderer/assets/{settings-api-Csdngf9Z.js → settings-api-RD2IZF53.js} +2 -2
- package/dist/renderer/assets/{workbenchSettings-CODFCzOg.js → workbenchSettings-CNJX4Qna.js} +2 -2
- package/dist/renderer/entries/main/index.html +5 -5
- package/dist/renderer/entries/popover/index.html +5 -5
- package/dist/renderer/entries/settings/index.html +5 -5
- package/dist/renderer/entries/workbench-settings/index.html +4 -4
- 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/ipc-channels.d.ts +84 -1
- package/dist/shared/ipc-channels.js +90 -10
- package/dist/shared/ipc-schemas.d.ts +59 -2
- package/dist/shared/ipc-schemas.js +64 -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 -39
- 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 +8 -9
- package/dist/main/utils/disposable.d.ts +0 -18
- package/dist/main/utils/disposable.js +0 -67
- package/dist/renderer/assets/index-BDMxXUfn.js +0 -50
- package/dist/renderer/assets/ipc-transport-Cu7tubyg.css +0 -1
- package/dist/renderer/assets/select-Ct4-sijm.js +0 -2
- package/dist/simulator/assets/simulator-B4e3c6_O.js +0 -9
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, viewport-fit=cover" />
|
|
6
|
+
<title>Dimina Render Host</title>
|
|
7
|
+
<!--
|
|
8
|
+
Base render stylesheet (reset + `:root { font-size: clamp(.4px,.13333vw,2px) }`
|
|
9
|
+
rpx→rem scale + .dd-* component defaults). dimina's compiled WXSS emits `rem`
|
|
10
|
+
units relative to this root font-size; without it the UA default (16px) inflates
|
|
11
|
+
every page ~30x. Upstream the container package's pageFrame loads this; the
|
|
12
|
+
native-host render-host must load it too. build-native-host.mjs vendors it to
|
|
13
|
+
../native-host/container/ and rewrites this href (mirrors common.js/render.js).
|
|
14
|
+
-->
|
|
15
|
+
<link rel="stylesheet" href="../native-host/container/pageFrame.css" />
|
|
16
|
+
<script>
|
|
17
|
+
if (typeof globalThis.process === 'undefined') {
|
|
18
|
+
globalThis.process = { env: { NODE_ENV: 'production' } };
|
|
19
|
+
}
|
|
20
|
+
</script>
|
|
21
|
+
<script type="module">
|
|
22
|
+
import { modDefine, modRequire } from '../native-host/common/common.js'
|
|
23
|
+
window.modDefine = modDefine
|
|
24
|
+
window.modRequire = modRequire
|
|
25
|
+
await import('../native-host/render/render.js')
|
|
26
|
+
</script>
|
|
27
|
+
</head>
|
|
28
|
+
<body></body>
|
|
29
|
+
</html>
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
const { ipcRenderer } = require('electron')
|
|
2
|
+
|
|
3
|
+
const CHANNELS = {
|
|
4
|
+
RENDER_INVOKE: 'dmb:render:invoke',
|
|
5
|
+
RENDER_PUBLISH: 'dmb:render:publish',
|
|
6
|
+
TO_RENDER: 'dmb:to-render',
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const params = new URLSearchParams(globalThis.location && globalThis.location.search || '')
|
|
10
|
+
const bridgeId = params.get('bridgeId')
|
|
11
|
+
const pagePath = params.get('pagePath') || 'pages/index/index'
|
|
12
|
+
const pendingMessages = []
|
|
13
|
+
let onMessageFn = null
|
|
14
|
+
let drainScheduled = false
|
|
15
|
+
|
|
16
|
+
if (!bridgeId) {
|
|
17
|
+
throw new Error('[render-host] missing bridgeId in URL query')
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function reportError(stage, error) {
|
|
21
|
+
const message = error && error.stack ? error.stack : String(error)
|
|
22
|
+
console.error(`[render-host] ${stage}`, error)
|
|
23
|
+
ipcRenderer.send(CHANNELS.RENDER_INVOKE, {
|
|
24
|
+
bridgeId,
|
|
25
|
+
msg: {
|
|
26
|
+
type: 'componentError',
|
|
27
|
+
target: 'container',
|
|
28
|
+
body: { bridgeId, stage, message },
|
|
29
|
+
},
|
|
30
|
+
})
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function parseMessage(rawMsg) {
|
|
34
|
+
return typeof rawMsg === 'string' ? JSON.parse(rawMsg) : rawMsg
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function deliver(msg) {
|
|
38
|
+
if (!onMessageFn) {
|
|
39
|
+
pendingMessages.push(msg)
|
|
40
|
+
return
|
|
41
|
+
}
|
|
42
|
+
try {
|
|
43
|
+
onMessageFn(msg)
|
|
44
|
+
} catch (error) {
|
|
45
|
+
reportError('onMessage', error)
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function scheduleDrain() {
|
|
50
|
+
if (drainScheduled) return
|
|
51
|
+
drainScheduled = true
|
|
52
|
+
queueMicrotask(() => {
|
|
53
|
+
drainScheduled = false
|
|
54
|
+
while (onMessageFn && pendingMessages.length > 0) {
|
|
55
|
+
deliver(pendingMessages.shift())
|
|
56
|
+
}
|
|
57
|
+
})
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
Object.defineProperty(globalThis, 'DiminaRenderBridge', {
|
|
61
|
+
value: {
|
|
62
|
+
get onMessage() {
|
|
63
|
+
return onMessageFn
|
|
64
|
+
},
|
|
65
|
+
set onMessage(handler) {
|
|
66
|
+
onMessageFn = typeof handler === 'function' ? handler : null
|
|
67
|
+
scheduleDrain()
|
|
68
|
+
},
|
|
69
|
+
invoke(rawMsg) {
|
|
70
|
+
ipcRenderer.send(CHANNELS.RENDER_INVOKE, { bridgeId, msg: parseMessage(rawMsg) })
|
|
71
|
+
},
|
|
72
|
+
publish(rawMsg) {
|
|
73
|
+
ipcRenderer.send(CHANNELS.RENDER_PUBLISH, { bridgeId, msg: parseMessage(rawMsg) })
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
writable: false,
|
|
77
|
+
configurable: false,
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
ipcRenderer.on(CHANNELS.TO_RENDER, (_event, payload) => {
|
|
81
|
+
deliver(payload && payload.msg)
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
globalThis.addEventListener('DOMContentLoaded', () => {
|
|
85
|
+
ipcRenderer.send(CHANNELS.RENDER_INVOKE, {
|
|
86
|
+
bridgeId,
|
|
87
|
+
msg: {
|
|
88
|
+
type: 'renderHostReady',
|
|
89
|
+
target: 'container',
|
|
90
|
+
body: { bridgeId, pagePath },
|
|
91
|
+
},
|
|
92
|
+
})
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
// ── Console capture (native-host) ───────────────────────────────────────────
|
|
96
|
+
// This preload runs with contextIsolation effectively off (it defines globals on
|
|
97
|
+
// globalThis the page reads), so patching `console` here captures the render
|
|
98
|
+
// guest's own console output. Each entry is forwarded to main as a `consoleLog`
|
|
99
|
+
// container message (source:'render') — bridge-router routes it to ctx.guestConsole
|
|
100
|
+
// → automation rebroadcasts it as App.logAdded. Mirrors the shape used by
|
|
101
|
+
// src/preload/instrumentation/console.ts + runtime/host.ts safeSerialize.
|
|
102
|
+
|
|
103
|
+
function safeSerializeArg(val) {
|
|
104
|
+
if (val === null || val === undefined) return val
|
|
105
|
+
if (typeof val === 'function') return `[Function: ${val.name || 'anonymous'}]`
|
|
106
|
+
if (typeof val !== 'object') return val
|
|
107
|
+
if (val instanceof Error) return { __isError: true, message: val.message, stack: val.stack }
|
|
108
|
+
try {
|
|
109
|
+
return structuredClone(val)
|
|
110
|
+
} catch (_) { /* DOM nodes / proxies can't be structuredCloned */ }
|
|
111
|
+
try {
|
|
112
|
+
return JSON.parse(JSON.stringify(val))
|
|
113
|
+
} catch (_) { /* circular / non-serializable */ }
|
|
114
|
+
return String(val)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function emitConsoleLog(level, args) {
|
|
118
|
+
try {
|
|
119
|
+
globalThis.DiminaRenderBridge.invoke({
|
|
120
|
+
type: 'consoleLog',
|
|
121
|
+
target: 'container',
|
|
122
|
+
body: {
|
|
123
|
+
bridgeId,
|
|
124
|
+
source: 'render',
|
|
125
|
+
level,
|
|
126
|
+
args: args.map(safeSerializeArg),
|
|
127
|
+
ts: Date.now(),
|
|
128
|
+
},
|
|
129
|
+
})
|
|
130
|
+
} catch (_) { /* never let console capture break the guest */ }
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
;['log', 'warn', 'error', 'info', 'debug'].forEach((level) => {
|
|
134
|
+
const original = typeof console[level] === 'function' ? console[level].bind(console) : null
|
|
135
|
+
if (!original) return
|
|
136
|
+
console[level] = (...args) => {
|
|
137
|
+
original(...args)
|
|
138
|
+
emitConsoleLog(level, args)
|
|
139
|
+
}
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
globalThis.addEventListener('error', (event) => {
|
|
143
|
+
emitConsoleLog('error', [{
|
|
144
|
+
message: event.message,
|
|
145
|
+
source: event.filename,
|
|
146
|
+
lineno: event.lineno,
|
|
147
|
+
colno: event.colno,
|
|
148
|
+
stack: event.error && event.error.stack,
|
|
149
|
+
}])
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
globalThis.addEventListener('unhandledrejection', (event) => {
|
|
153
|
+
emitConsoleLog('error', [{ message: 'Unhandled Promise Rejection', reason: String(event.reason) }])
|
|
154
|
+
})
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
(() => {
|
|
3
|
+
// src/preload/shared/sid-registry.ts
|
|
4
|
+
var SYNTHETIC_SID_PREFIX = "devtools-";
|
|
5
|
+
var syntheticSidByEl = /* @__PURE__ */ new WeakMap();
|
|
6
|
+
var elBySyntheticSid = /* @__PURE__ */ new Map();
|
|
7
|
+
var nextSyntheticSid = 1;
|
|
8
|
+
function registerSyntheticSid(el) {
|
|
9
|
+
const existing = syntheticSidByEl.get(el);
|
|
10
|
+
if (existing) return existing;
|
|
11
|
+
const synthetic = `${SYNTHETIC_SID_PREFIX}${nextSyntheticSid++}`;
|
|
12
|
+
syntheticSidByEl.set(el, synthetic);
|
|
13
|
+
elBySyntheticSid.set(synthetic, new WeakRef(el));
|
|
14
|
+
return synthetic;
|
|
15
|
+
}
|
|
16
|
+
function findElementBySid(doc, sid) {
|
|
17
|
+
if (sid.startsWith(SYNTHETIC_SID_PREFIX)) {
|
|
18
|
+
const ref = elBySyntheticSid.get(sid);
|
|
19
|
+
if (!ref) return null;
|
|
20
|
+
const el = ref.deref();
|
|
21
|
+
if (!el || !el.isConnected) {
|
|
22
|
+
elBySyntheticSid.delete(sid);
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
if (el.ownerDocument !== doc) return null;
|
|
26
|
+
return el;
|
|
27
|
+
}
|
|
28
|
+
return doc.querySelector(`[data-sid="${CSS.escape(sid)}"]`);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// src/preload/instrumentation/wxml-extract.ts
|
|
32
|
+
var INTERNAL_CLASSES = /* @__PURE__ */ new Set([
|
|
33
|
+
"dd-swiper-wrapper",
|
|
34
|
+
"dd-swiper-slides",
|
|
35
|
+
"dd-swiper-slide-frame",
|
|
36
|
+
"dd-swiper-dots",
|
|
37
|
+
"dd-picker-overlay",
|
|
38
|
+
"dd-picker-container",
|
|
39
|
+
"dd-picker-header",
|
|
40
|
+
"dd-picker-body"
|
|
41
|
+
]);
|
|
42
|
+
var FRAMEWORK_TEMPLATE_RE = /^(taro_tmpl|tmpl_\d+)/;
|
|
43
|
+
function resolveTemplateNameFromParent(instance) {
|
|
44
|
+
const parent = instance.parent;
|
|
45
|
+
if (!parent) return null;
|
|
46
|
+
const parentType = parent.type;
|
|
47
|
+
const components = parentType?.components;
|
|
48
|
+
if (components) {
|
|
49
|
+
for (const [regName, comp] of Object.entries(components)) {
|
|
50
|
+
if (comp === instance.type) return regName.startsWith("dd-") ? regName.slice(3) : regName;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const appComponents = instance.appContext?.components;
|
|
54
|
+
if (!appComponents) return null;
|
|
55
|
+
for (const [regName, comp] of Object.entries(appComponents)) {
|
|
56
|
+
if (comp === instance.type) return regName.startsWith("dd-") ? regName.slice(3) : regName;
|
|
57
|
+
}
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
function pascalToKebab(name) {
|
|
61
|
+
return name.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
|
|
62
|
+
}
|
|
63
|
+
function resolvePagePath(instance) {
|
|
64
|
+
const proxy = instance.proxy;
|
|
65
|
+
if (proxy?.__page__ !== true) return null;
|
|
66
|
+
const provides = instance.provides;
|
|
67
|
+
const path = provides?.path;
|
|
68
|
+
if (typeof path !== "string" || !path) return null;
|
|
69
|
+
return path.startsWith("/") ? path.slice(1) : path;
|
|
70
|
+
}
|
|
71
|
+
function resolveTagName(instance) {
|
|
72
|
+
const type = instance.type;
|
|
73
|
+
if (!type) return "unknown";
|
|
74
|
+
const pagePath = resolvePagePath(instance);
|
|
75
|
+
if (pagePath) return pagePath;
|
|
76
|
+
if (typeof type.__tagName === "string") return type.__tagName;
|
|
77
|
+
const name = type.__name || type.name;
|
|
78
|
+
if (!name) {
|
|
79
|
+
if (type.__scopeId && type.components) return "page";
|
|
80
|
+
if (type.__scopeId) return resolveTemplateNameFromParent(instance) || "template";
|
|
81
|
+
return "unknown";
|
|
82
|
+
}
|
|
83
|
+
if (name === "dd-page") return "page";
|
|
84
|
+
if (name.startsWith("dd-")) return name.slice(3);
|
|
85
|
+
if (name.startsWith("Dd") && name.length > 2) return pascalToKebab(name.slice(2));
|
|
86
|
+
if (/^[A-Z]/.test(name)) return pascalToKebab(name);
|
|
87
|
+
return name;
|
|
88
|
+
}
|
|
89
|
+
function extractProps(instance) {
|
|
90
|
+
const out = {};
|
|
91
|
+
for (const raw of [instance.props, instance.attrs]) {
|
|
92
|
+
if (!raw) continue;
|
|
93
|
+
for (const [k, v] of Object.entries(raw)) {
|
|
94
|
+
if (typeof v === "function" || v === void 0) continue;
|
|
95
|
+
if (k === "data" || k.startsWith("__")) continue;
|
|
96
|
+
if (typeof v === "boolean" && !v) continue;
|
|
97
|
+
if (k === "class" && typeof v === "string") {
|
|
98
|
+
const cleaned = v.split(/\s+/).filter((c) => !c.startsWith("dd-")).join(" ");
|
|
99
|
+
if (cleaned) out[k] = cleaned;
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
out[k] = typeof v === "object" ? JSON.stringify(v) : String(v);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return out;
|
|
106
|
+
}
|
|
107
|
+
function isInternalElement(vnode) {
|
|
108
|
+
const props = vnode.props;
|
|
109
|
+
if (!props) return false;
|
|
110
|
+
const cls = String(props.class || "");
|
|
111
|
+
return cls.split(/\s+/).some((c) => INTERNAL_CLASSES.has(c));
|
|
112
|
+
}
|
|
113
|
+
function getElementSid(instance) {
|
|
114
|
+
const subTree = instance.subTree;
|
|
115
|
+
const el = subTree?.el;
|
|
116
|
+
if (!el?.getAttribute) return void 0;
|
|
117
|
+
const sid = el.getAttribute("data-sid");
|
|
118
|
+
if (sid) return sid;
|
|
119
|
+
return registerSyntheticSid(el);
|
|
120
|
+
}
|
|
121
|
+
function isTransparentComponent(instance, tagName) {
|
|
122
|
+
if (tagName === "unknown") return true;
|
|
123
|
+
if (tagName === "template") {
|
|
124
|
+
const props = instance.props;
|
|
125
|
+
const is = props?.is;
|
|
126
|
+
if (is && FRAMEWORK_TEMPLATE_RE.test(is)) return true;
|
|
127
|
+
if (!is) {
|
|
128
|
+
const type = instance.type;
|
|
129
|
+
if (type?.__scopeId && !type.components) return true;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
function isCommentVNode(vnode) {
|
|
135
|
+
const type = vnode.type;
|
|
136
|
+
if (typeof type !== "symbol") return false;
|
|
137
|
+
const desc = type.description;
|
|
138
|
+
if (desc === "Comment" || desc === "v-cmt") return true;
|
|
139
|
+
const children = typeof vnode.children === "string" ? vnode.children : "";
|
|
140
|
+
return /^v-(if|else|else-if|for)$/.test(children);
|
|
141
|
+
}
|
|
142
|
+
function extractChildrenFromVNode(vnode, depth) {
|
|
143
|
+
if (!vnode || depth > 50) return [];
|
|
144
|
+
if (isCommentVNode(vnode)) return [];
|
|
145
|
+
if (vnode.component) {
|
|
146
|
+
const result2 = walkInstance(vnode.component, depth + 1);
|
|
147
|
+
return result2 ? Array.isArray(result2) ? result2 : [result2] : [];
|
|
148
|
+
}
|
|
149
|
+
if (vnode.suspense) {
|
|
150
|
+
const suspense = vnode.suspense;
|
|
151
|
+
const activeBranch = suspense.activeBranch;
|
|
152
|
+
return activeBranch ? extractChildrenFromVNode(activeBranch, depth + 1) : [];
|
|
153
|
+
}
|
|
154
|
+
if (typeof vnode.children === "string" && vnode.children.trim()) {
|
|
155
|
+
const vnodeType = vnode.type;
|
|
156
|
+
if (typeof vnodeType === "symbol" || typeof vnodeType === "string") {
|
|
157
|
+
return [{ tagName: "#text", attrs: {}, children: [], text: vnode.children.trim() }];
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
const kids = vnode.children;
|
|
161
|
+
if (!Array.isArray(kids)) return [];
|
|
162
|
+
const result = [];
|
|
163
|
+
for (const child of kids) {
|
|
164
|
+
if (!child) continue;
|
|
165
|
+
if (typeof child === "string") {
|
|
166
|
+
const trimmed = child.trim();
|
|
167
|
+
if (trimmed) result.push({ tagName: "#text", attrs: {}, children: [], text: trimmed });
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
if (typeof child !== "object") continue;
|
|
171
|
+
const c = child;
|
|
172
|
+
if (c.component) {
|
|
173
|
+
const walked = walkInstance(c.component, depth + 1);
|
|
174
|
+
if (walked) result.push(...Array.isArray(walked) ? walked : [walked]);
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
if (typeof c.type === "symbol") {
|
|
178
|
+
result.push(...extractChildrenFromVNode(c, depth + 1));
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
if (typeof c.type === "string") {
|
|
182
|
+
if (isInternalElement(c)) {
|
|
183
|
+
result.push(...extractChildrenFromVNode(c, depth + 1));
|
|
184
|
+
} else if (typeof c.children === "string" && c.children.trim()) {
|
|
185
|
+
result.push({ tagName: "#text", attrs: {}, children: [], text: c.children.trim() });
|
|
186
|
+
} else {
|
|
187
|
+
result.push(...extractChildrenFromVNode(c, depth + 1));
|
|
188
|
+
}
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
result.push(...extractChildrenFromVNode(c, depth + 1));
|
|
192
|
+
}
|
|
193
|
+
return result;
|
|
194
|
+
}
|
|
195
|
+
function unwrapCustomComponent(node) {
|
|
196
|
+
if (node.tagName !== "wrapper") return node;
|
|
197
|
+
const path = node.attrs?.name;
|
|
198
|
+
if (typeof path !== "string" || !path.startsWith("/")) return node;
|
|
199
|
+
const stripped = path.replace(/^\//, "");
|
|
200
|
+
const withoutIndex = stripped.endsWith("/index") ? stripped.slice(0, -"/index".length) : stripped;
|
|
201
|
+
const recovered = withoutIndex || stripped;
|
|
202
|
+
if (!recovered || recovered === "index") return node;
|
|
203
|
+
const nextAttrs = {};
|
|
204
|
+
for (const [k, v] of Object.entries(node.attrs)) {
|
|
205
|
+
if (k === "name") continue;
|
|
206
|
+
nextAttrs[k] = v;
|
|
207
|
+
}
|
|
208
|
+
return { ...node, tagName: recovered, attrs: nextAttrs };
|
|
209
|
+
}
|
|
210
|
+
function wrapInShadowRoot(node) {
|
|
211
|
+
if (!node.tagName.includes("/")) return node;
|
|
212
|
+
if (node.children.length === 0) return node;
|
|
213
|
+
if (node.children[0]?.tagName === "#shadow-root") return node;
|
|
214
|
+
return {
|
|
215
|
+
...node,
|
|
216
|
+
children: [{ tagName: "#shadow-root", attrs: {}, children: node.children }]
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
function walkInstance(instance, depth) {
|
|
220
|
+
if (depth > 50) return null;
|
|
221
|
+
const tagName = resolveTagName(instance);
|
|
222
|
+
const children = extractChildrenFromVNode(instance.subTree, depth);
|
|
223
|
+
if (isTransparentComponent(instance, tagName)) return children.length > 0 ? children : null;
|
|
224
|
+
const node = { tagName, attrs: extractProps(instance), children };
|
|
225
|
+
const sid = getElementSid(instance);
|
|
226
|
+
if (sid) node.sid = sid;
|
|
227
|
+
return wrapInShadowRoot(unwrapCustomComponent(node));
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// src/render-host/render-inspect.ts
|
|
231
|
+
var g = globalThis;
|
|
232
|
+
if (!g.__diminaRenderInspect) {
|
|
233
|
+
const getVueApp = () => {
|
|
234
|
+
try {
|
|
235
|
+
const body = document.body;
|
|
236
|
+
const app = body?.__vue_app__;
|
|
237
|
+
if (!app) return null;
|
|
238
|
+
if (app._instance) return app._instance;
|
|
239
|
+
const container = app._container;
|
|
240
|
+
const vnode = container?._vnode;
|
|
241
|
+
return vnode?.component ?? null;
|
|
242
|
+
} catch {
|
|
243
|
+
return null;
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
const getWxml = () => {
|
|
247
|
+
const instance = getVueApp();
|
|
248
|
+
if (!instance) return null;
|
|
249
|
+
const tree = walkInstance(instance, 0);
|
|
250
|
+
if (!tree) return null;
|
|
251
|
+
return Array.isArray(tree) ? { tagName: "#fragment", attrs: {}, children: tree } : tree;
|
|
252
|
+
};
|
|
253
|
+
let overlay = null;
|
|
254
|
+
const ensureOverlay = () => {
|
|
255
|
+
if (overlay && overlay.ownerDocument === document) return overlay;
|
|
256
|
+
overlay = document.createElement("div");
|
|
257
|
+
overlay.id = "__simulator-highlight";
|
|
258
|
+
overlay.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;";
|
|
259
|
+
document.body.appendChild(overlay);
|
|
260
|
+
return overlay;
|
|
261
|
+
};
|
|
262
|
+
const highlightElement = (sid) => {
|
|
263
|
+
if (!sid) return null;
|
|
264
|
+
const el = findElementBySid(document, sid);
|
|
265
|
+
if (!el) return null;
|
|
266
|
+
const rect = el.getBoundingClientRect();
|
|
267
|
+
const box = ensureOverlay();
|
|
268
|
+
box.style.left = `${rect.left}px`;
|
|
269
|
+
box.style.top = `${rect.top}px`;
|
|
270
|
+
box.style.width = `${rect.width}px`;
|
|
271
|
+
box.style.height = `${rect.height}px`;
|
|
272
|
+
box.style.display = "block";
|
|
273
|
+
const style = el.ownerDocument.defaultView?.getComputedStyle(el);
|
|
274
|
+
if (!style) return null;
|
|
275
|
+
return {
|
|
276
|
+
sid,
|
|
277
|
+
rect: { x: rect.x, y: rect.y, width: rect.width, height: rect.height },
|
|
278
|
+
style: {
|
|
279
|
+
display: style.display,
|
|
280
|
+
position: style.position,
|
|
281
|
+
boxSizing: style.boxSizing,
|
|
282
|
+
margin: style.margin,
|
|
283
|
+
padding: style.padding,
|
|
284
|
+
color: style.color,
|
|
285
|
+
backgroundColor: style.backgroundColor,
|
|
286
|
+
fontSize: style.fontSize
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
};
|
|
290
|
+
const unhighlightElement = () => {
|
|
291
|
+
if (overlay) overlay.style.display = "none";
|
|
292
|
+
};
|
|
293
|
+
g.__diminaRenderInspect = { getWxml, highlightElement, unhighlightElement };
|
|
294
|
+
}
|
|
295
|
+
})();
|