@dimina-kit/devtools 0.4.0-dev.20260618090552 → 0.4.0-dev.20260624040247
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 +5 -1
- package/dist/main/app/app.js +14 -2
- package/dist/main/index.bundle.js +347 -99
- package/dist/main/ipc/bridge-router.js +13 -8
- package/dist/main/ipc/projects.js +1 -1
- package/dist/main/ipc/simulator.js +1 -1
- package/dist/main/runtime/miniapp-runtime.d.ts +3 -3
- package/dist/main/services/elements-forward/index.js +5 -5
- package/dist/main/services/network-forward/index.d.ts +5 -6
- package/dist/main/services/network-forward/index.js +9 -10
- package/dist/main/services/notifications/renderer-notifier.d.ts +3 -4
- package/dist/main/services/projects/index.js +1 -1
- package/dist/main/services/service-console/console-api.d.ts +5 -6
- package/dist/main/services/service-console/console-api.js +5 -6
- package/dist/main/services/service-host-pool/pool.d.ts +2 -3
- package/dist/main/services/simulator-storage/index.d.ts +2 -4
- package/dist/main/services/simulator-storage/index.js +2 -4
- package/dist/main/services/simulator-temp-files/index.js +2 -2
- package/dist/main/services/views/host-toolbar-session-runtime.d.ts +4 -4
- package/dist/main/services/views/host-toolbar-session-runtime.js +4 -4
- package/dist/main/services/views/view-manager.d.ts +17 -1
- package/dist/main/services/views/view-manager.js +67 -41
- package/dist/main/services/workspace/workspace-service.js +11 -0
- package/dist/main/windows/service-host-window/create.d.ts +1 -0
- package/dist/main/windows/service-host-window/create.js +1 -0
- package/dist/preload/runtime/host-toolbar-port.d.ts +1 -1
- package/dist/preload/runtime/host-toolbar-port.js +1 -1
- package/dist/preload/runtime/host-toolbar-runtime.d.ts +8 -7
- package/dist/preload/runtime/host-toolbar-runtime.js +8 -7
- package/dist/preload/windows/host-toolbar-runtime.cjs.map +2 -2
- package/dist/preload/windows/main.cjs.map +2 -2
- package/dist/preload/windows/simulator.cjs +1 -1
- package/dist/preload/windows/simulator.cjs.map +1 -1
- package/dist/preload/windows/simulator.js +1 -1
- package/dist/renderer/assets/index-PtsdWlGu.js +50 -0
- package/dist/renderer/entries/main/index.html +1 -1
- package/dist/shared/appdata-accumulator.d.ts +2 -2
- package/dist/shared/appdata-accumulator.js +3 -3
- package/dist/shared/constants.d.ts +1 -1
- package/dist/shared/constants.js +1 -1
- package/dist/shared/ipc-channels.d.ts +3 -3
- package/dist/shared/ipc-channels.js +3 -3
- package/dist/shared/open-in-editor.d.ts +20 -1
- package/dist/shared/open-in-editor.js +246 -3
- package/dist/shared/vpath.d.ts +2 -2
- package/dist/shared/vpath.js +2 -2
- package/dist/simulator/assets/{device-shell-BWX7Yopg.js → device-shell-TtcSXwhb.js} +2 -2
- package/dist/simulator/assets/{simulator-sf-D0mhw.js → simulator-CtyXt_4V.js} +3 -3
- package/dist/simulator/simulator.html +1 -1
- package/package.json +8 -6
- package/dist/renderer/assets/index-DmgWoK8N.js +0 -50
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
overflow: hidden;
|
|
29
29
|
}
|
|
30
30
|
</style>
|
|
31
|
-
<script type="module" crossorigin src="../../assets/index-
|
|
31
|
+
<script type="module" crossorigin src="../../assets/index-PtsdWlGu.js"></script>
|
|
32
32
|
<link rel="modulepreload" crossorigin href="../../assets/chunk-DPI0Y_ll.js">
|
|
33
33
|
<link rel="modulepreload" crossorigin href="../../assets/ipc-transport-DSBmaWpJ.js">
|
|
34
34
|
<link rel="modulepreload" crossorigin href="../../assets/editor.api2-BTaYmRq7.js">
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* Default (dimina-fe) path: the simulator preload sniffs these as Worker
|
|
12
12
|
* `message` events (app-data.ts). Native-host path: they flow service→render
|
|
13
13
|
* through bridge-router (SERVICE_PUBLISH). Both feed this one accumulator so the
|
|
14
|
-
* decode/merge/page-only/
|
|
14
|
+
* decode/merge/page-only/init-gate policy can't drift between modes.
|
|
15
15
|
*/
|
|
16
16
|
/**
|
|
17
17
|
* The AppData snapshot — the full, cumulative panel state.
|
|
@@ -74,7 +74,7 @@ export declare class AppDataAccumulator {
|
|
|
74
74
|
private recordBridge;
|
|
75
75
|
/**
|
|
76
76
|
* Apply one entry. Returns true if it was accepted (a mutation worth
|
|
77
|
-
* republishing), false if dropped (missing ids, or the
|
|
77
|
+
* republishing), false if dropped (missing ids, or the init-gate).
|
|
78
78
|
*/
|
|
79
79
|
apply(input: AppDataInput): boolean;
|
|
80
80
|
/** Evict every entry for a bridge (page teardown). */
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* Default (dimina-fe) path: the simulator preload sniffs these as Worker
|
|
12
12
|
* `message` events (app-data.ts). Native-host path: they flow service→render
|
|
13
13
|
* through bridge-router (SERVICE_PUBLISH). Both feed this one accumulator so the
|
|
14
|
-
* decode/merge/page-only/
|
|
14
|
+
* decode/merge/page-only/init-gate policy can't drift between modes.
|
|
15
15
|
*/
|
|
16
16
|
/**
|
|
17
17
|
* Decode a service→render message into AppData entries, or null when it is not
|
|
@@ -116,12 +116,12 @@ export class AppDataAccumulator {
|
|
|
116
116
|
}
|
|
117
117
|
/**
|
|
118
118
|
* Apply one entry. Returns true if it was accepted (a mutation worth
|
|
119
|
-
* republishing), false if dropped (missing ids, or the
|
|
119
|
+
* republishing), false if dropped (missing ids, or the init-gate).
|
|
120
120
|
*/
|
|
121
121
|
apply(input) {
|
|
122
122
|
if (!input.bridgeId || !input.moduleId)
|
|
123
123
|
return false;
|
|
124
|
-
//
|
|
124
|
+
// Drop ub patches whose bridge has never been initialised. dimina
|
|
125
125
|
// dispatches pageUnload → onUnload, whose setData produces a late `ub`
|
|
126
126
|
// arriving AFTER clearBridge; without this gate it would resurrect the
|
|
127
127
|
// unloaded bridge as a ghost tab.
|
|
@@ -18,7 +18,7 @@ export declare const HEADER_H = 40;
|
|
|
18
18
|
* defaultSession renderer; its guard activates the height advertiser only when
|
|
19
19
|
* `process.argv` carries this marker AND `process.isMainFrame` is true (the
|
|
20
20
|
* marker is process-level, so subframes of the toolbar window see it too —
|
|
21
|
-
* both guard wings are required
|
|
21
|
+
* both guard wings are required).
|
|
22
22
|
*/
|
|
23
23
|
export declare const HOST_TOOLBAR_RUNTIME_MARKER = "--dimina-host-toolbar";
|
|
24
24
|
//# sourceMappingURL=constants.d.ts.map
|
package/dist/shared/constants.js
CHANGED
|
@@ -18,7 +18,7 @@ export const HEADER_H = 40;
|
|
|
18
18
|
* defaultSession renderer; its guard activates the height advertiser only when
|
|
19
19
|
* `process.argv` carries this marker AND `process.isMainFrame` is true (the
|
|
20
20
|
* marker is process-level, so subframes of the toolbar window see it too —
|
|
21
|
-
* both guard wings are required
|
|
21
|
+
* both guard wings are required).
|
|
22
22
|
*/
|
|
23
23
|
export const HOST_TOOLBAR_RUNTIME_MARKER = '--dimina-host-toolbar';
|
|
24
24
|
//# sourceMappingURL=constants.js.map
|
|
@@ -174,11 +174,11 @@ export declare const ProjectsChannel: {
|
|
|
174
174
|
readonly List: "projects:list";
|
|
175
175
|
readonly Add: "projects:add";
|
|
176
176
|
readonly Remove: "projects:remove";
|
|
177
|
-
/**
|
|
177
|
+
/** Merged + sanitized template catalog for the create-project dialog. */
|
|
178
178
|
readonly ListTemplates: "projects:listTemplates";
|
|
179
|
-
/**
|
|
179
|
+
/** Host-supplied create-project dialog hook (returns input or null). */
|
|
180
180
|
readonly OpenCreateDialog: "projects:openCreateDialog";
|
|
181
|
-
/**
|
|
181
|
+
/** Server-side scaffold + register (delegates to create-project-service). */
|
|
182
182
|
readonly Create: "projects:create";
|
|
183
183
|
/** Default values used to pre-fill the create-project dialog (baseDir). */
|
|
184
184
|
readonly GetCreateDefaults: "projects:getCreateDefaults";
|
|
@@ -161,11 +161,11 @@ export const ProjectsChannel = {
|
|
|
161
161
|
List: 'projects:list',
|
|
162
162
|
Add: 'projects:add',
|
|
163
163
|
Remove: 'projects:remove',
|
|
164
|
-
/**
|
|
164
|
+
/** Merged + sanitized template catalog for the create-project dialog. */
|
|
165
165
|
ListTemplates: 'projects:listTemplates',
|
|
166
|
-
/**
|
|
166
|
+
/** Host-supplied create-project dialog hook (returns input or null). */
|
|
167
167
|
OpenCreateDialog: 'projects:openCreateDialog',
|
|
168
|
-
/**
|
|
168
|
+
/** Server-side scaffold + register (delegates to create-project-service). */
|
|
169
169
|
Create: 'projects:create',
|
|
170
170
|
/** Default values used to pre-fill the create-project dialog (baseDir). */
|
|
171
171
|
GetCreateDefaults: 'projects:getCreateDefaults',
|
|
@@ -32,6 +32,15 @@ export interface OpenInEditorRequest {
|
|
|
32
32
|
/** 0-based column as reported by DevTools (may be undefined). */
|
|
33
33
|
column?: number;
|
|
34
34
|
}
|
|
35
|
+
export interface ProjectSourceContext {
|
|
36
|
+
/** Absolute project root on disk. */
|
|
37
|
+
projectRoot: string;
|
|
38
|
+
/** Resource server base URL used by the compiled miniapp. */
|
|
39
|
+
resourceBaseUrl: string;
|
|
40
|
+
appId: string;
|
|
41
|
+
/** Compiler output package root (`main` for the primary package). */
|
|
42
|
+
outputRoot: string;
|
|
43
|
+
}
|
|
35
44
|
/**
|
|
36
45
|
* Encode an open-in-editor request as a sentinel URL the DevTools front-end can
|
|
37
46
|
* hand to `InspectorFrontendHost.openInNewTab(...)`. All fields ride in the
|
|
@@ -67,5 +76,15 @@ export declare function decodeOpenInEditorUrl(raw: string): OpenInEditorRequest
|
|
|
67
76
|
* @returns the project-relative POSIX path, or null when the URL is not a
|
|
68
77
|
* mappable dev-server source.
|
|
69
78
|
*/
|
|
70
|
-
export declare function resourceUrlToProjectRelativePath(resourceUrl: string,
|
|
79
|
+
export declare function resourceUrlToProjectRelativePath(resourceUrl: string, expectedOriginOrContext?: string | ProjectSourceContext): string | null;
|
|
80
|
+
/** Read the project/source routing metadata carried by a service-host spawn URL. */
|
|
81
|
+
export declare function projectSourceContextFromServiceHostUrl(serviceHostUrl: string, activeProjectRoot?: string): ProjectSourceContext | null;
|
|
82
|
+
/**
|
|
83
|
+
* Build the DevTools-front-end glue for project source links.
|
|
84
|
+
*
|
|
85
|
+
* It keeps the existing `setOpenResourceHandler` transport, but only forwards
|
|
86
|
+
* locations that map to the active project. A DOM observer expands Chromium's
|
|
87
|
+
* basename-only console labels to project-relative paths.
|
|
88
|
+
*/
|
|
89
|
+
export declare function buildDevtoolsProjectSourceLinksScript(context: ProjectSourceContext): string;
|
|
71
90
|
//# sourceMappingURL=open-in-editor.d.ts.map
|
|
@@ -96,9 +96,12 @@ export function decodeOpenInEditorUrl(raw) {
|
|
|
96
96
|
* @returns the project-relative POSIX path, or null when the URL is not a
|
|
97
97
|
* mappable dev-server source.
|
|
98
98
|
*/
|
|
99
|
-
export function resourceUrlToProjectRelativePath(resourceUrl,
|
|
99
|
+
export function resourceUrlToProjectRelativePath(resourceUrl, expectedOriginOrContext) {
|
|
100
100
|
if (typeof resourceUrl !== 'string' || !resourceUrl)
|
|
101
101
|
return null;
|
|
102
|
+
if (expectedOriginOrContext && typeof expectedOriginOrContext === 'object') {
|
|
103
|
+
return projectAwareResourcePath(resourceUrl, expectedOriginOrContext);
|
|
104
|
+
}
|
|
102
105
|
let resource;
|
|
103
106
|
try {
|
|
104
107
|
resource = new URL(resourceUrl);
|
|
@@ -110,10 +113,10 @@ export function resourceUrlToProjectRelativePath(resourceUrl, expectedOrigin) {
|
|
|
110
113
|
// `webpack://`, `node:`, `data:` are framework/runtime frames with no file.
|
|
111
114
|
if (resource.protocol !== 'http:' && resource.protocol !== 'https:')
|
|
112
115
|
return null;
|
|
113
|
-
if (
|
|
116
|
+
if (expectedOriginOrContext) {
|
|
114
117
|
let base;
|
|
115
118
|
try {
|
|
116
|
-
base = new URL(
|
|
119
|
+
base = new URL(expectedOriginOrContext);
|
|
117
120
|
}
|
|
118
121
|
catch {
|
|
119
122
|
return null;
|
|
@@ -135,4 +138,244 @@ export function resourceUrlToProjectRelativePath(resourceUrl, expectedOrigin) {
|
|
|
135
138
|
return null;
|
|
136
139
|
return segments.slice(1).join('/');
|
|
137
140
|
}
|
|
141
|
+
function decodePathname(pathname) {
|
|
142
|
+
return pathname.split('/').map((segment) => {
|
|
143
|
+
try {
|
|
144
|
+
return decodeURIComponent(segment);
|
|
145
|
+
}
|
|
146
|
+
catch {
|
|
147
|
+
return segment;
|
|
148
|
+
}
|
|
149
|
+
}).join('/');
|
|
150
|
+
}
|
|
151
|
+
function normalizeSlashPath(value) {
|
|
152
|
+
return decodePathname(value.replace(/\\/g, '/')).replace(/\/+/g, '/');
|
|
153
|
+
}
|
|
154
|
+
function safeRelativePath(segments) {
|
|
155
|
+
if (segments.length === 0 || segments.some((segment) => !segment || segment === '.' || segment === '..')) {
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
return segments.join('/');
|
|
159
|
+
}
|
|
160
|
+
function projectAwareResourcePath(resourceUrl, context) {
|
|
161
|
+
let base;
|
|
162
|
+
try {
|
|
163
|
+
base = new URL(context.resourceBaseUrl);
|
|
164
|
+
}
|
|
165
|
+
catch {
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
168
|
+
const projectRoot = normalizeSlashPath(context.projectRoot).replace(/\/$/, '');
|
|
169
|
+
const raw = resourceUrl.trim();
|
|
170
|
+
if (!raw)
|
|
171
|
+
return null;
|
|
172
|
+
// Chromium may hand the open-resource hook a raw absolute filesystem path.
|
|
173
|
+
const normalizedRaw = normalizeSlashPath(raw);
|
|
174
|
+
if (projectRoot && (normalizedRaw === projectRoot || normalizedRaw.startsWith(`${projectRoot}/`))) {
|
|
175
|
+
const relative = normalizedRaw.slice(projectRoot.length).replace(/^\/+/, '');
|
|
176
|
+
return safeRelativePath(relative.split('/').filter(Boolean));
|
|
177
|
+
}
|
|
178
|
+
// Sourcemap sources commonly use virtual root paths such as `/pages/x.js`.
|
|
179
|
+
// Real host filesystem paths use well-known absolute roots; when they are
|
|
180
|
+
// outside the active project they are runtime/devtools frames, not sources.
|
|
181
|
+
if (/^\/(?:Volumes|Users|home|private|tmp|var|opt|Applications)\//.test(normalizedRaw)) {
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
// Reject relative runtime labels such as `service.js` or
|
|
185
|
+
// `electron/js2c/renderer_init`; project source locations must be an
|
|
186
|
+
// absolute URL/path so they can be scoped to the active project.
|
|
187
|
+
if (!raw.startsWith('/') && !/^[a-z][a-z0-9+.-]*:/i.test(raw))
|
|
188
|
+
return null;
|
|
189
|
+
let resource;
|
|
190
|
+
try {
|
|
191
|
+
resource = raw.startsWith('/') && !raw.startsWith('//')
|
|
192
|
+
? new URL(raw, base.origin)
|
|
193
|
+
: new URL(raw);
|
|
194
|
+
}
|
|
195
|
+
catch {
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
if (resource.protocol === 'file:') {
|
|
199
|
+
const filePath = normalizeSlashPath(resource.pathname);
|
|
200
|
+
if (!projectRoot || (filePath !== projectRoot && !filePath.startsWith(`${projectRoot}/`)))
|
|
201
|
+
return null;
|
|
202
|
+
return safeRelativePath(filePath.slice(projectRoot.length).replace(/^\/+/, '').split('/').filter(Boolean));
|
|
203
|
+
}
|
|
204
|
+
if (resource.protocol !== 'http:' && resource.protocol !== 'https:')
|
|
205
|
+
return null;
|
|
206
|
+
if (resource.origin !== base.origin)
|
|
207
|
+
return null;
|
|
208
|
+
let segments = decodePathname(resource.pathname).split('/').filter(Boolean);
|
|
209
|
+
if (context.appId && segments[0] === context.appId) {
|
|
210
|
+
segments = segments.slice(1);
|
|
211
|
+
if (context.outputRoot && segments[0] === context.outputRoot)
|
|
212
|
+
segments = segments.slice(1);
|
|
213
|
+
}
|
|
214
|
+
return safeRelativePath(segments);
|
|
215
|
+
}
|
|
216
|
+
/** Read the project/source routing metadata carried by a service-host spawn URL. */
|
|
217
|
+
export function projectSourceContextFromServiceHostUrl(serviceHostUrl, activeProjectRoot) {
|
|
218
|
+
let url;
|
|
219
|
+
try {
|
|
220
|
+
url = new URL(serviceHostUrl);
|
|
221
|
+
}
|
|
222
|
+
catch {
|
|
223
|
+
return null;
|
|
224
|
+
}
|
|
225
|
+
const projectRoot = url.searchParams.get('pkgRoot') || '';
|
|
226
|
+
const resourceBaseUrl = url.searchParams.get('resourceBaseUrl') ?? '';
|
|
227
|
+
const appId = url.searchParams.get('appId') ?? '';
|
|
228
|
+
const outputRoot = url.searchParams.get('root') ?? 'main';
|
|
229
|
+
if (!projectRoot || !resourceBaseUrl || !appId)
|
|
230
|
+
return null;
|
|
231
|
+
if (activeProjectRoot) {
|
|
232
|
+
const authoritativeRoot = normalizeSlashPath(projectRoot).replace(/\/+$/, '');
|
|
233
|
+
const currentRoot = normalizeSlashPath(activeProjectRoot).replace(/\/+$/, '');
|
|
234
|
+
if (!authoritativeRoot || authoritativeRoot !== currentRoot)
|
|
235
|
+
return null;
|
|
236
|
+
}
|
|
237
|
+
try {
|
|
238
|
+
new URL(resourceBaseUrl);
|
|
239
|
+
}
|
|
240
|
+
catch {
|
|
241
|
+
return null;
|
|
242
|
+
}
|
|
243
|
+
return { projectRoot, resourceBaseUrl, appId, outputRoot };
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Build the DevTools-front-end glue for project source links.
|
|
247
|
+
*
|
|
248
|
+
* It keeps the existing `setOpenResourceHandler` transport, but only forwards
|
|
249
|
+
* locations that map to the active project. A DOM observer expands Chromium's
|
|
250
|
+
* basename-only console labels to project-relative paths.
|
|
251
|
+
*/
|
|
252
|
+
export function buildDevtoolsProjectSourceLinksScript(context) {
|
|
253
|
+
const config = JSON.stringify(context);
|
|
254
|
+
const scheme = JSON.stringify(OPEN_IN_EDITOR_SCHEME);
|
|
255
|
+
return `
|
|
256
|
+
(function() {
|
|
257
|
+
try {
|
|
258
|
+
const stateKey = '__diminaProjectSourceLinksState__'
|
|
259
|
+
const previousState = globalThis[stateKey]
|
|
260
|
+
if (previousState && typeof previousState.dispose === 'function') {
|
|
261
|
+
try { previousState.dispose() } catch (_) {}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const cfg = ${config}
|
|
265
|
+
const diminaProjectSourcePath = ${projectAwareResourcePath.toString()}
|
|
266
|
+
const decodePathname = ${decodePathname.toString()}
|
|
267
|
+
const normalizeSlashPath = ${normalizeSlashPath.toString()}
|
|
268
|
+
const safeRelativePath = ${safeRelativePath.toString()}
|
|
269
|
+
const observedRoots = new Set()
|
|
270
|
+
const observers = []
|
|
271
|
+
let timer = null
|
|
272
|
+
const state = {
|
|
273
|
+
dispose() {
|
|
274
|
+
if (timer !== null) {
|
|
275
|
+
clearInterval(timer)
|
|
276
|
+
timer = null
|
|
277
|
+
}
|
|
278
|
+
for (const observer of observers.splice(0)) {
|
|
279
|
+
try { observer.disconnect() } catch (_) {}
|
|
280
|
+
}
|
|
281
|
+
observedRoots.clear()
|
|
282
|
+
},
|
|
283
|
+
}
|
|
284
|
+
globalThis[stateKey] = state
|
|
285
|
+
|
|
286
|
+
function splitLocation(value) {
|
|
287
|
+
const raw = String(value || '')
|
|
288
|
+
const match = raw.match(/^(.*?)(?::(\\d+))(?::(\\d+))?$/)
|
|
289
|
+
return match
|
|
290
|
+
? { url: match[1], suffix: ':' + match[2] + (match[3] ? ':' + match[3] : '') }
|
|
291
|
+
: { url: raw, suffix: '' }
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
function rewriteLink(link) {
|
|
295
|
+
if (!link || link.dataset.diminaProjectSourcePath) return
|
|
296
|
+
const candidates = [
|
|
297
|
+
link.getAttribute && link.getAttribute('title'),
|
|
298
|
+
link.getAttribute && link.getAttribute('href'),
|
|
299
|
+
link.getAttribute && link.getAttribute('data-url'),
|
|
300
|
+
]
|
|
301
|
+
for (const candidate of candidates) {
|
|
302
|
+
if (!candidate) continue
|
|
303
|
+
const location = splitLocation(candidate)
|
|
304
|
+
const relative = diminaProjectSourcePath(location.url, cfg)
|
|
305
|
+
if (!relative) continue
|
|
306
|
+
const textSuffix = location.suffix || ((String(link.textContent || '').match(/(:\\d+(?::\\d+)?)$/) || [])[1] || '')
|
|
307
|
+
link.textContent = relative + textSuffix
|
|
308
|
+
link.dataset.diminaProjectSourcePath = relative
|
|
309
|
+
return
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
function observeRoot(root) {
|
|
314
|
+
if (!root || !root.querySelectorAll || observedRoots.has(root)) return
|
|
315
|
+
observedRoots.add(root)
|
|
316
|
+
|
|
317
|
+
const observer = new MutationObserver((records) => {
|
|
318
|
+
for (const record of records) {
|
|
319
|
+
if (record.type === 'attributes') rewriteLink(record.target)
|
|
320
|
+
for (const node of record.addedNodes || []) visitNode(node)
|
|
321
|
+
}
|
|
322
|
+
})
|
|
323
|
+
observer.observe(root, {
|
|
324
|
+
subtree: true,
|
|
325
|
+
childList: true,
|
|
326
|
+
attributes: true,
|
|
327
|
+
attributeFilter: ['title', 'href', 'data-url'],
|
|
328
|
+
})
|
|
329
|
+
observers.push(observer)
|
|
330
|
+
|
|
331
|
+
for (const link of root.querySelectorAll('.devtools-link')) rewriteLink(link)
|
|
332
|
+
for (const element of root.querySelectorAll('*')) {
|
|
333
|
+
if (element.shadowRoot) observeRoot(element.shadowRoot)
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
function visitNode(node) {
|
|
338
|
+
if (!node) return
|
|
339
|
+
if (node.matches && node.matches('.devtools-link')) rewriteLink(node)
|
|
340
|
+
if (node.shadowRoot) observeRoot(node.shadowRoot)
|
|
341
|
+
if (!node.querySelectorAll) return
|
|
342
|
+
for (const link of node.querySelectorAll('.devtools-link')) rewriteLink(link)
|
|
343
|
+
for (const element of node.querySelectorAll('*')) {
|
|
344
|
+
if (element.shadowRoot) observeRoot(element.shadowRoot)
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
observeRoot(document)
|
|
349
|
+
|
|
350
|
+
let tries = 0
|
|
351
|
+
timer = setInterval(() => {
|
|
352
|
+
tries++
|
|
353
|
+
try {
|
|
354
|
+
const Host = globalThis.Host
|
|
355
|
+
const host = Host && Host.InspectorFrontendHost
|
|
356
|
+
if (host && typeof host.setOpenResourceHandler === 'function'
|
|
357
|
+
&& typeof host.openInNewTab === 'function') {
|
|
358
|
+
host.setOpenResourceHandler((url, lineNumber, columnNumber) => {
|
|
359
|
+
try {
|
|
360
|
+
if (!diminaProjectSourcePath(String(url), cfg)) return
|
|
361
|
+
const p = new URLSearchParams()
|
|
362
|
+
p.set('u', String(url))
|
|
363
|
+
if (typeof lineNumber === 'number') p.set('l', String(lineNumber))
|
|
364
|
+
if (typeof columnNumber === 'number') p.set('c', String(columnNumber))
|
|
365
|
+
host.openInNewTab(${scheme} + ':?' + p.toString())
|
|
366
|
+
} catch (_) {}
|
|
367
|
+
})
|
|
368
|
+
clearInterval(timer)
|
|
369
|
+
timer = null
|
|
370
|
+
}
|
|
371
|
+
} catch (_) {}
|
|
372
|
+
if (tries > 80 && timer !== null) {
|
|
373
|
+
clearInterval(timer)
|
|
374
|
+
timer = null
|
|
375
|
+
}
|
|
376
|
+
}, 50)
|
|
377
|
+
} catch (_) {}
|
|
378
|
+
})()
|
|
379
|
+
`;
|
|
380
|
+
}
|
|
138
381
|
//# sourceMappingURL=open-in-editor.js.map
|
package/dist/shared/vpath.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* vpath resolver.
|
|
3
3
|
*
|
|
4
4
|
* Spec: `docs/file-system.md` §3.3 — single resolver shared by every FSM
|
|
5
|
-
* entry, the renderer-side temp store, and
|
|
5
|
+
* entry, the renderer-side temp store, and the main-process
|
|
6
6
|
* protocol.handle / disk reader.
|
|
7
7
|
*
|
|
8
8
|
* resolveVPath(url): { kind, writable, realPath? } | null
|
package/dist/shared/vpath.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* vpath resolver.
|
|
3
3
|
*
|
|
4
4
|
* Spec: `docs/file-system.md` §3.3 — single resolver shared by every FSM
|
|
5
|
-
* entry, the renderer-side temp store, and
|
|
5
|
+
* entry, the renderer-side temp store, and the main-process
|
|
6
6
|
* protocol.handle / disk reader.
|
|
7
7
|
*
|
|
8
8
|
* resolveVPath(url): { kind, writable, realPath? } | null
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{n as e,t}from"./jsx-runtime-P6ZegaOf.js";import{t as n}from"./bridge-channels-BUQ5AbvJ.js";var r=e(),i=new Set([`audioListen`]);function a(e){return i.has(e)}function o(e,t,n,r){let i=e.apiRegistry[t];if(!i)return r({ok:!1,errMsg:`${t}:fail no handler`}),Promise.resolve();let o=a(t)||(n&&typeof n==`object`&&!Array.isArray(n)?n.keep===!0:!1);return new Promise(a=>{let s=!1,c=e=>{if(s){o&&e.ok&&r({...e,keep:!0});return}s=!0,r(o&&e.ok?{...e,keep:!0}:e),a()},l=Symbol(`sim-cb-success`),u=Symbol(`sim-cb-fail`),d=Symbol(`sim-cb-complete`),f=Object.create(e);f.createCallbackFunction=e=>{if(e!=null)return(...n)=>{let r=n[0];e===l?c({ok:!0,result:r}):e===u&&c({ok:!1,errMsg:r&&typeof r==`object`&&`errMsg`in r?String(r.errMsg):`${t}:fail`,result:r})}};let p=n&&typeof n==`object`&&!Array.isArray(n)?{...n}:{},m=p.success!==void 0&&p.success!==null,h=p.fail!==void 0&&p.fail!==null,g=p.complete!==void 0&&p.complete!==null;p.success=l,p.fail=u,g&&(p.complete=d);try{let e=i.call(f,p);if(e&&typeof e.then==`function`){Promise.resolve(e).then(e=>c({ok:!0,result:e}),e=>{c({ok:!1,errMsg:`${t}:fail ${e instanceof Error?e.message:String(e)}`})});return}!m&&!h&&(o?a():c({ok:!0,result:e}))}catch(e){c({ok:!1,errMsg:`${t}:fail ${e instanceof Error?e.message:String(e)}`})}})}var s=t();function c({platform:e,statusBarHeight:t,textStyle:n}){let r=e===`ios`?87:95,i=t+(e===`ios`?4:6),a=e===`ios`?7:10;return(0,s.jsxs)(`div`,{className:`menu-capsule menu-capsule--${n}`,style:{width:r,height:32,top:i,right:a},"aria-hidden":`true`,children:[(0,s.jsxs)(`div`,{className:`menu-capsule__more`,children:[(0,s.jsx)(`span`,{}),(0,s.jsx)(`span`,{}),(0,s.jsx)(`span`,{})]}),(0,s.jsx)(`div`,{className:`menu-capsule__divider`}),(0,s.jsx)(`div`,{className:`menu-capsule__close`,children:(0,s.jsx)(`svg`,{viewBox:`0 0 16 16`,width:`12`,height:`12`,"aria-hidden":`true`,children:(0,s.jsx)(`path`,{d:`M4 4l8 8M12 4l-8 8`,stroke:`currentColor`,strokeWidth:`1.5`,fill:`none`,strokeLinecap:`round`})})})]})}var l={linear:`linear`,easeIn:`ease-in`,easeOut:`ease-out`,easeInOut:`ease-in-out`};function u({state:e,stackDepth:t,platform:n,statusBarHeight:i,navBarHeight:a,onBack:o,onHome:u}){let d=(0,r.useMemo)(()=>{if(!e.colorAnimation||e.colorAnimation.durationMs<=0)return;let t=l[e.colorAnimation.timingFunc]??`linear`;return`background-color ${e.colorAnimation.durationMs}ms ${t}, color ${e.colorAnimation.durationMs}ms ${t}`},[e.colorAnimation]),f=e.style===`custom`,p=t>1,m=!p&&e.homeButtonVisible,h=n===`ios`?`center`:`left`,g={backgroundColor:e.backgroundColor,color:e.textStyle===`white`?`#ffffff`:`#000000`,height:i+a,paddingTop:i,transition:d};return(0,s.jsxs)(`header`,{className:`nav-bar nav-bar--${n} nav-bar--${e.textStyle}${f?` nav-bar--custom`:``}`,style:g,"aria-hidden":f,children:[!f&&(0,s.jsxs)(`div`,{className:`nav-bar__row`,style:{height:a,justifyContent:h===`center`?`center`:`flex-start`},children:[(p||m)&&(0,s.jsxs)(`div`,{className:`nav-bar__leading`,children:[p&&(0,s.jsx)(`button`,{type:`button`,className:`nav-bar__back`,"aria-label":`Back`,onClick:o,children:(0,s.jsx)(`svg`,{viewBox:`0 0 24 24`,width:`24`,height:`24`,"aria-hidden":`true`,children:(0,s.jsx)(`path`,{d:`M15 18l-6-6 6-6`,stroke:`currentColor`,strokeWidth:`2`,fill:`none`,strokeLinecap:`round`,strokeLinejoin:`round`})})}),m&&(0,s.jsx)(`button`,{type:`button`,className:`nav-bar__home`,"aria-label":`Home`,onClick:u,children:(0,s.jsx)(`svg`,{viewBox:`0 0 24 24`,width:`22`,height:`22`,"aria-hidden":`true`,children:(0,s.jsx)(`path`,{d:`M3 12l9-9 9 9M5 10v10h14V10`,stroke:`currentColor`,strokeWidth:`2`,fill:`none`,strokeLinecap:`round`,strokeLinejoin:`round`})})})]}),(0,s.jsxs)(`div`,{className:`nav-bar__title nav-bar__title--${h}`,style:{color:e.textStyle===`white`?`#ffffff`:`#000000`},children:[e.loading&&(0,s.jsx)(`span`,{className:`nav-bar__spinner`,"aria-hidden":`true`}),(0,s.jsx)(`span`,{className:`nav-bar__title-text`,children:e.title})]})]}),(0,s.jsx)(c,{platform:n,statusBarHeight:i,textStyle:e.textStyle})]})}function d(e){return{title:e?.title??``,backgroundColor:e?.backgroundColor??`#000000`,textStyle:e?.textStyle??`white`,style:e?.style??`default`,loading:e?.loading??!1,homeButtonVisible:e?.homeButtonVisible??!1,colorAnimation:e?.colorAnimation}}function f(e){switch(e){case`notch`:return{width:164,height:30,top:0,bottomOnly:!0};case`dynamic-island`:return{width:124,height:36,top:11,bottomOnly:!1};default:return null}}function p({height:e,notchType:t,textStyle:n}){let r=f(t);return(0,s.jsxs)(`div`,{className:`device-statusbar`,style:{height:e,color:n===`black`?`#000000`:`#ffffff`},"aria-hidden":`true`,children:[(0,s.jsx)(`span`,{className:`device-statusbar__time`,children:`9:41`}),r&&(0,s.jsx)(`div`,{className:`device-statusbar__notch`,style:{width:r.width,height:r.height,top:r.top,borderRadius:r.bottomOnly?`0 0 ${Math.round(r.height*.6)}px ${Math.round(r.height*.6)}px`:`${r.height/2}px`}}),(0,s.jsxs)(`div`,{className:`device-statusbar__icons`,children:[(0,s.jsx)(`span`,{className:`device-statusbar__signal`}),(0,s.jsx)(`span`,{className:`device-statusbar__wifi`}),(0,s.jsx)(`span`,{className:`device-statusbar__battery`})]})]})}function m({state:e,currentPath:t,resourceBaseUrl:n,appId:r,onSwitch:i,bottomInset:a=0}){if(!e.config||!e.visible)return null;let{color:o,selectedColor:c,backgroundColor:l,borderStyle:u,list:d}=e.config,f=o||`#999999`,p=c||`#1890ff`;return(0,s.jsx)(`div`,{className:`dmb-tab-bar`,style:{backgroundColor:l||`#ffffff`,borderTopColor:u===`white`?`#ffffff`:`#e0e0e0`,paddingBottom:a},role:`tablist`,"aria-label":`TabBar`,children:d.map((a,o)=>{let c=h(a.pagePath),l=c===t,u=g(l?a.selectedIconPath??a.iconPath:a.iconPath,n,r),d=e.badges[o]??``,m=e.redDots[o]??!1;return(0,s.jsxs)(`button`,{type:`button`,className:`dmb-tab-bar__item${l?` is-selected`:``}`,role:`tab`,"aria-selected":l,onClick:()=>i(c),children:[u&&(0,s.jsx)(`span`,{className:`dmb-tab-bar__icon-slot`,children:(0,s.jsx)(`img`,{className:`dmb-tab-bar__icon`,src:u,alt:``,onError:e=>{e.currentTarget.style.display=`none`}})}),(0,s.jsx)(`span`,{className:`dmb-tab-bar__text`,style:{color:l?p:f},children:a.text||``}),d&&(0,s.jsx)(`span`,{className:`dmb-tab-bar__badge`,children:d}),!d&&m&&(0,s.jsx)(`span`,{className:`dmb-tab-bar__red-dot`})]},`${c}-${o}`)})})}function h(e){return e?e.replace(/^\/+/,``):``}function g(e,t,n){if(!e)return null;let r=e.trim();if(!r)return null;if(/^(?:data:|blob:|https?:|\/\/)/i.test(r))return r;if(!t)return null;let i=r.replace(/^\/+/,``).replace(/^\.\//,``);return i.startsWith(`${n}/`)?_(t,i.slice(n.length+1)):_(t,i)}function _(e,t){return`${e.endsWith(`/`)?e:`${e}/`}${t.replace(/^\/+/,``)}`}function v(e){if(!e)return{config:null,visible:!1,badges:[],redDots:[]};let t=e.list.length;return{config:y(e),visible:!0,badges:Array.from({length:t},()=>``),redDots:Array.from({length:t},()=>!1)}}function y(e){return{...e,list:e.list.map(e=>({...e}))}}function b(e,t){switch(t.kind){case`reset`:return{state:v(t.config),ok:!0,errMsg:`reset:ok`};case`visibility`:return{state:{...e,visible:t.visible},ok:!0,errMsg:t.visible?`showTabBar:ok`:`hideTabBar:ok`};case`apply`:return x(e,t.name,t.params)}}function x(e,t,n){if(!e.config)return{state:e,ok:!1,errMsg:`${t}:fail tabBar not configured`};switch(t){case`setTabBarStyle`:return S(e,n);case`setTabBarItem`:return C(e,n);case`showTabBar`:return{state:{...e,visible:!0},ok:!0,errMsg:`showTabBar:ok`};case`hideTabBar`:return{state:{...e,visible:!1},ok:!0,errMsg:`hideTabBar:ok`};case`setTabBarBadge`:return w(e,n);case`removeTabBarBadge`:return T(e,n);case`showTabBarRedDot`:return E(e,n,!0);case`hideTabBarRedDot`:return E(e,n,!1)}}function S(e,t){if(!e.config)return{state:e,ok:!1,errMsg:`setTabBarStyle:fail tabBar not configured`};let n={...e.config},r=(e,t)=>{let r=O(t);r&&(n[e]=r)};return r(`color`,t.color),r(`selectedColor`,t.selectedColor),r(`backgroundColor`,t.backgroundColor),(t.borderStyle===`black`||t.borderStyle===`white`)&&(n.borderStyle=t.borderStyle),{state:{...e,config:n},ok:!0,errMsg:`setTabBarStyle:ok`}}function C(e,t){let n=D(e,t);if(n.err)return{state:e,ok:!1,errMsg:`setTabBarItem:fail ${n.err}`};if(!e.config)return{state:e,ok:!1,errMsg:`setTabBarItem:fail tabBar not configured`};let r=e.config.list[n.index],i={...r,text:typeof t.text==`string`?t.text:r.text,iconPath:typeof t.iconPath==`string`?t.iconPath:r.iconPath,selectedIconPath:typeof t.selectedIconPath==`string`?t.selectedIconPath:r.selectedIconPath},a=[...e.config.list];return a[n.index]=i,{state:{...e,config:{...e.config,list:a}},ok:!0,errMsg:`setTabBarItem:ok`}}function w(e,t){let n=D(e,t);if(n.err)return{state:e,ok:!1,errMsg:`setTabBarBadge:fail ${n.err}`};let r=[...e.badges];r[n.index]=String(t.text??``);let i=[...e.redDots];return i[n.index]=!1,{state:{...e,badges:r,redDots:i},ok:!0,errMsg:`setTabBarBadge:ok`}}function T(e,t){let n=D(e,t);if(n.err)return{state:e,ok:!1,errMsg:`removeTabBarBadge:fail ${n.err}`};let r=[...e.badges];return r[n.index]=``,{state:{...e,badges:r},ok:!0,errMsg:`removeTabBarBadge:ok`}}function E(e,t,n){let r=D(e,t);if(r.err)return{state:e,ok:!1,errMsg:`${n?`showTabBarRedDot`:`hideTabBarRedDot`}:fail ${r.err}`};let i=[...e.redDots];i[r.index]=n;let a=[...e.badges];return n&&(a[r.index]=``),{state:{...e,redDots:i,badges:a},ok:!0,errMsg:`${n?`showTabBarRedDot`:`hideTabBarRedDot`}:ok`}}function D(e,t){let n=e.config?.list??[],r=t.index,i=Number(r);return n.length?r==null||!Number.isInteger(i)||i<0||i>=n.length?{index:-1,err:`invalid index ${r}`}:{index:i,err:null}:{index:-1,err:`tabBar not configured`}}function O(e){if(typeof e!=`string`)return null;let t=e.trim();return!t||t.length>64?null:/[<>"';{}()\\]/.test(t)?/^(?:rgb|rgba|hsl|hsla)\(\s*[\d.,%\s/-]+\)$/i.test(t)?t:null:t}function k(e){return e?e.replace(/^\/+/,``):``}function A(e){let[t,n]=(typeof e==`string`?e:``).split(`?`),r={};if(n)for(let e of n.split(`&`)){if(!e)continue;let t=e.indexOf(`=`),n=t>=0?e.slice(0,t):e,i=t>=0?e.slice(t+1):``;n&&(r[decodeURIComponent(n)]=decodeURIComponent(i))}return{pagePath:k(t),query:r}}function j(e){let t={};return e.isTab&&(t[e.pagePath]=[e]),{stack:[e],tabStacks:t,currentTabPath:e.isTab?e.pagePath:null}}function M(e){return e.currentTabPath?{...e.tabStacks,[e.currentTabPath]:[...e.stack]}:e.tabStacks}function N(e,t){let n=e.stack[e.stack.length-1],r=[...e.stack,t];return{next:{...e,stack:r,tabStacks:e.currentTabPath?{...e.tabStacks,[e.currentTabPath]:r}:e.tabStacks},effects:n?[{kind:`lifecycle`,bridgeId:n.bridgeId,event:`pageHide`}]:[]}}function P(e,t){if(e.stack.length<=1)return{error:`no page to back`};let n=Math.min(Math.max(1,Number.isFinite(t)?t:1),e.stack.length-1),r=e.stack.slice(e.stack.length-n),i=e.stack.slice(0,e.stack.length-n),a=i[i.length-1],o={...e,stack:i,tabStacks:e.currentTabPath?{...e.tabStacks,[e.currentTabPath]:i}:e.tabStacks,currentTabPath:a.isTab?a.pagePath:e.currentTabPath},s=[];for(let e of r)s.push({kind:`lifecycle`,bridgeId:e.bridgeId,event:`pageUnload`}),s.push({kind:`closePage`,bridgeId:e.bridgeId});return s.push({kind:`lifecycle`,bridgeId:a.bridgeId,event:`pageShow`}),{next:o,effects:s}}function F(e,t){let n=e.stack[e.stack.length-1],r=[...e.stack.slice(0,e.stack.length-1),t],i={...e,stack:r,tabStacks:e.currentTabPath?{...e.tabStacks,[e.currentTabPath]:r}:e.tabStacks},a=[];return n&&(a.push({kind:`lifecycle`,bridgeId:n.bridgeId,event:`pageUnload`}),a.push({kind:`closePage`,bridgeId:n.bridgeId})),{next:i,effects:a}}function I(e,t){let n=new Set;for(let t of e.stack)n.add(t.bridgeId);for(let t of Object.values(e.tabStacks))for(let e of t)n.add(e.bridgeId);n.delete(t.bridgeId);let r=t.isTab?{[t.pagePath]:[t]}:{},i={stack:[t],tabStacks:r,currentTabPath:t.isTab?t.pagePath:null},a=[];for(let e of n)a.push({kind:`lifecycle`,bridgeId:e,event:`pageUnload`}),a.push({kind:`closePage`,bridgeId:e});return{next:i,effects:a}}function L(e,t,n){let r=e.stack[e.stack.length-1],i=M(e),a,o=i[t];if(o&&o.length>0)a=o;else if(n)a=[n];else throw Error(`[page-stack] switchTab to ${t} requires either a cached substack or a freshly-opened entry`);let s={...e,stack:a,tabStacks:{...i,[t]:a},currentTabPath:t},c=a[a.length-1],l=[];return r&&r.bridgeId!==c.bridgeId&&l.push({kind:`lifecycle`,bridgeId:r.bridgeId,event:`pageHide`}),n||l.push({kind:`lifecycle`,bridgeId:c.bridgeId,event:`pageShow`}),{next:s,effects:l}}function R(e){let t=new Map,n=e.stack[e.stack.length-1]?.bridgeId;for(let r of e.stack)t.set(r.bridgeId,{entry:r,visible:r.bridgeId===n});for(let n of Object.values(e.tabStacks))for(let e of n)t.has(e.bridgeId)||t.set(e.bridgeId,{entry:e,visible:!1});return Array.from(t.values())}function z(e,t){let n=e.navigationBarBackgroundColor??`#ffffff`,r=e.navigationBarTextStyle??`black`,i=e.navigationStyle??`default`;return d({title:e.navigationBarTitleText??t,backgroundColor:n,textStyle:r,style:i,homeButtonVisible:e.homeButton===!0})}function B(e,t,n){switch(t){case`setNavigationBarTitle`:return{...e,title:typeof n.title==`string`?n.title:e.title};case`setNavigationBarColor`:return H(e,n);case`showNavigationBarLoading`:return{...e,loading:!0};case`hideNavigationBarLoading`:return{...e,loading:!1};case`hideHomeButton`:return{...e,homeButtonVisible:!1};default:return e}}var V=[`linear`,`easeIn`,`easeOut`,`easeInOut`];function H(e,t){let n=typeof t.frontColor==`string`?t.frontColor.toLowerCase():void 0,r=n===`#ffffff`?`white`:n===`#000000`?`black`:e.textStyle,i=typeof t.backgroundColor==`string`?t.backgroundColor:e.backgroundColor,a=(()=>{let e=t.animation;if(!e||typeof e!=`object`)return;let n=e,r=typeof n.duration==`number`&&Number.isFinite(n.duration)?Math.max(0,n.duration):0,i=typeof n.timingFunc==`string`?n.timingFunc:`linear`;return{durationMs:r,timingFunc:V.includes(i)?i:`linear`}})();return{...e,textStyle:r,backgroundColor:i,colorAnimation:a}}function U(e,t,n){let r=e=>e.bridgeId===t?{...e,navBar:n(e.navBar)}:e,i=e.stack.map(r),a={};for(let[t,n]of Object.entries(e.tabStacks))a[t]=n.map(r);return{...e,stack:i,tabStacks:a}}var W=44,G=24,K=44;function q({miniApp:e,bridgeId:t,platform:i=`ios`}){let[a,c]=(0,r.useState)(()=>e.getInitialDevice());(0,r.useEffect)(()=>e.onSimulatorEvent(n.DEVICE_CHANGE,c),[e]);let l=a?.safeAreaInsets.top??(i===`ios`?W:G),d=a?.safeAreaInsets.bottom??0,f=a?.notchType??`none`,h=(0,r.useMemo)(()=>e.getRenderPreloadUrl(),[e]),g=(0,r.useMemo)(()=>e.getTabBarConfig(),[e]),_=(0,r.useMemo)(()=>({bridgeId:t,pagePath:k(e.pagePath),query:{...e.query},isTab:!!e.getTabBarConfig()?.list.some(t=>k(t.pagePath)===k(e.pagePath)),windowConfig:e.rootWindowConfig??{},navBar:z(e.rootWindowConfig??{},e.appId)}),[e,t]),[{shell:y,tabBar:x},S]=(0,r.useState)(()=>({shell:j(_),tabBar:v(g)})),C=(0,r.useRef)({shell:y,tabBar:x});(0,r.useEffect)(()=>{C.current={shell:y,tabBar:x}},[y,x]);let w=(0,r.useCallback)(t=>{for(let n of t)n.kind===`lifecycle`?e.notifyLifecycle(n.bridgeId,n.event):n.kind===`closePage`&&e.closePage(n.bridgeId)},[e]);(0,r.useEffect)(()=>e.onSimulatorEvent(n.NAV_BAR,e=>{S(t=>({...t,shell:U(t.shell,e.bridgeId,t=>B(t,e.name,e.params))}))}),[e]),(0,r.useEffect)(()=>e.onSimulatorEvent(n.TAB_ACTION,t=>{let n=b(C.current.tabBar,{kind:`apply`,name:t.name,params:t.params});S(e=>({...e,tabBar:n.state})),e.notifyNavCallback({ok:n.ok,errMsg:n.errMsg,callbacks:t.callbacks})}),[e]);let T=(0,r.useCallback)(async t=>{let n=(n,r)=>e.notifyNavCallback({ok:n,errMsg:r,callbacks:t.callbacks});try{switch(t.name){case`navigateTo`:await J(e,C,S,w,t,n);break;case`navigateBack`:Y(C,S,w,t,n);break;case`redirectTo`:await X(e,C,S,w,t,n);break;case`reLaunch`:await Z(e,C,S,w,t,n);break;case`switchTab`:await Q(e,C,S,w,t,n);break}}catch(e){n(!1,`${t.name}:fail ${e instanceof Error?e.message:String(e)}`)}},[e,w]);(0,r.useEffect)(()=>e.onSimulatorEvent(n.NAV_ACTION,e=>{T(e)}),[T,e]),(0,r.useEffect)(()=>e.onSimulatorEvent(n.API_CALL,t=>{o(e,t.name,t.params,n=>{e.notifyApiResponse({requestId:t.requestId,ok:n.ok,result:n.result,errMsg:n.errMsg,keep:n.keep})})}),[e]);let E=(0,r.useCallback)(()=>{if(C.current.shell.stack.length<=1)return;let t=C.current.shell.stack;T({appSessionId:e.appSessionId??``,bridgeId:t[t.length-1].bridgeId,name:`navigateBack`,params:{delta:1},callbacks:{}})},[e,T]),D=(0,r.useCallback)(t=>{let n=C.current.shell;t===n.currentTabPath&&n.stack.length===1||T({appSessionId:e.appSessionId??``,bridgeId:n.stack[n.stack.length-1].bridgeId,name:`switchTab`,params:{url:`/${t}`},callbacks:{}})},[e,T]),O=y.stack[y.stack.length-1],A=R(y);return(0,r.useEffect)(()=>{e.notifyActivePage(O.bridgeId)},[e,O.bridgeId]),(0,r.useEffect)(()=>{e.notifyPageStack(y.stack.map(e=>({pagePath:e.pagePath,query:e.query})))},[e,y.stack]),(0,s.jsx)(`main`,{className:`device-shell-root`,children:(0,s.jsxs)(`section`,{className:`device-shell`,"aria-label":`Dimina simulator`,style:a?{width:a.screenWidth,height:a.screenHeight}:void 0,children:[(0,s.jsx)(p,{height:l,notchType:f,textStyle:O.navBar.textStyle}),(0,s.jsx)(u,{state:O.navBar,stackDepth:y.stack.length,platform:i,statusBarHeight:l,navBarHeight:K,onBack:E}),(0,s.jsx)(`div`,{className:`device-shell__viewport`,children:A.map(({entry:t,visible:n})=>(0,s.jsx)(`webview`,{className:`device-shell__webview`,src:e.createRenderHostUrl(t.bridgeId,t.pagePath,t.isTab),preload:h,allowpopups:`true`,style:{display:n?`flex`:`none`,zIndex:n?100:1}},t.bridgeId))}),O.isTab&&(0,s.jsx)(m,{state:x,currentPath:y.currentTabPath,resourceBaseUrl:e.resourceBaseUrl,appId:e.appId,onSwitch:D,bottomInset:d}),d>0&&(0,s.jsx)(`div`,{className:`device-shell__home-indicator`,style:{height:d},"aria-hidden":`true`})]})})}async function J(e,t,n,r,i,a){let{pagePath:o,query:s}=A(i.params.url);if(!o){a(!1,`navigateTo:fail invalid url`);return}if(e.getTabBarConfig()?.list.some(e=>k(e.pagePath)===o)){a(!1,`navigateTo:fail can not navigateTo a tabbar page`);return}let c=await e.openPage(o,s),l={bridgeId:c.bridgeId,pagePath:c.pagePath,query:s,isTab:c.isTab,windowConfig:c.windowConfig,navBar:z(c.windowConfig,e.appId)},{next:u,effects:d}=N(t.current.shell,l);n(e=>({...e,shell:u})),r(d),a(!0,`navigateTo:ok`)}function Y(e,t,n,r,i){let a=r.params.delta,o=Number.isFinite(Number(a))?Number(a):1,s=P(e.current.shell,o);if(`error`in s){i(!1,`navigateBack:fail ${s.error}`);return}t(e=>({...e,shell:s.next})),n(s.effects),i(!0,`navigateBack:ok`)}async function X(e,t,n,r,i,a){let{pagePath:o,query:s}=A(i.params.url);if(!o){a(!1,`redirectTo:fail invalid url`);return}if(e.getTabBarConfig()?.list.some(e=>k(e.pagePath)===o)){a(!1,`redirectTo:fail can not redirectTo a tabbar page`);return}let c=await e.openPage(o,s),l={bridgeId:c.bridgeId,pagePath:c.pagePath,query:s,isTab:c.isTab,windowConfig:c.windowConfig,navBar:z(c.windowConfig,e.appId)},{next:u,effects:d}=F(t.current.shell,l);n(e=>({...e,shell:u})),r(d),a(!0,`redirectTo:ok`)}async function Z(e,t,n,r,i,a){let{pagePath:o,query:s}=A(i.params.url);if(!o){a(!1,`reLaunch:fail invalid url`);return}let c=await e.openPage(o,s),l={bridgeId:c.bridgeId,pagePath:c.pagePath,query:s,isTab:c.isTab,windowConfig:c.windowConfig,navBar:z(c.windowConfig,e.appId)},{next:u,effects:d}=I(t.current.shell,l);n(e=>({...e,shell:u})),r(d),a(!0,`reLaunch:ok`)}async function Q(e,t,n,r,i,a){let{pagePath:o}=A(i.params.url);if(!o){a(!1,`switchTab:fail invalid url`);return}if(!e.getTabBarConfig()?.list.some(e=>k(e.pagePath)===o)){a(!1,`switchTab:fail not a tabBar page: ${o}`);return}let s=t.current.shell.tabStacks[o],c=null;if(!s||s.length===0){let t=await e.openPage(o,{});c={bridgeId:t.bridgeId,pagePath:t.pagePath,query:{},isTab:!0,windowConfig:t.windowConfig,navBar:z(t.windowConfig,e.appId)}}let{next:l,effects:u}=L(t.current.shell,o,c);n(e=>({...e,shell:l})),r(u),a(!0,`switchTab:ok`)}export{q as DeviceShell};
|
|
2
|
-
//# sourceMappingURL=device-shell-
|
|
1
|
+
import{n as e,t}from"./jsx-runtime-P6ZegaOf.js";import{t as n}from"./bridge-channels-BUQ5AbvJ.js";var r=e(),i=new Set([`audioListen`]);function a(e){return i.has(e)}function o(e,t,n,r){let i=e.apiRegistry[t];if(!i)return r({ok:!1,errMsg:`${t}:fail no handler`}),Promise.resolve();let o=a(t)||(n&&typeof n==`object`&&!Array.isArray(n)?n.keep===!0:!1);return new Promise(a=>{let s=!1,c=e=>{if(s){o&&e.ok&&r({...e,keep:!0});return}s=!0,r(o&&e.ok?{...e,keep:!0}:e),a()},l=Symbol(`sim-cb-success`),u=Symbol(`sim-cb-fail`),d=Symbol(`sim-cb-complete`),f=Object.create(e);f.createCallbackFunction=e=>{if(e!=null)return(...n)=>{let r=n[0];e===l?c({ok:!0,result:r}):e===u&&c({ok:!1,errMsg:r&&typeof r==`object`&&`errMsg`in r?String(r.errMsg):`${t}:fail`,result:r})}};let p=n&&typeof n==`object`&&!Array.isArray(n)?{...n}:{},m=p.success!==void 0&&p.success!==null,h=p.fail!==void 0&&p.fail!==null,g=p.complete!==void 0&&p.complete!==null;p.success=l,p.fail=u,g&&(p.complete=d);try{let e=i.call(f,p);if(e&&typeof e.then==`function`){Promise.resolve(e).then(e=>c({ok:!0,result:e}),e=>{c({ok:!1,errMsg:`${t}:fail ${e instanceof Error?e.message:String(e)}`})});return}!m&&!h&&(o?a():c({ok:!0,result:e}))}catch(e){c({ok:!1,errMsg:`${t}:fail ${e instanceof Error?e.message:String(e)}`})}})}var s=t();function c({platform:e,statusBarHeight:t,textStyle:n}){let r=e===`ios`?87:95,i=t+(e===`ios`?4:6),a=e===`ios`?7:10;return(0,s.jsxs)(`div`,{className:`menu-capsule menu-capsule--${n}`,style:{width:r,height:32,top:i,right:a},"aria-hidden":`true`,children:[(0,s.jsxs)(`div`,{className:`menu-capsule__more`,children:[(0,s.jsx)(`span`,{}),(0,s.jsx)(`span`,{}),(0,s.jsx)(`span`,{})]}),(0,s.jsx)(`div`,{className:`menu-capsule__divider`}),(0,s.jsx)(`div`,{className:`menu-capsule__close`,children:(0,s.jsx)(`svg`,{viewBox:`0 0 16 16`,width:`12`,height:`12`,"aria-hidden":`true`,children:(0,s.jsx)(`path`,{d:`M4 4l8 8M12 4l-8 8`,stroke:`currentColor`,strokeWidth:`1.5`,fill:`none`,strokeLinecap:`round`})})})]})}var l={linear:`linear`,easeIn:`ease-in`,easeOut:`ease-out`,easeInOut:`ease-in-out`};function u({state:e,stackDepth:t,platform:n,statusBarHeight:i,navBarHeight:a,onBack:o,onHome:u}){let d=(0,r.useMemo)(()=>{if(!e.colorAnimation||e.colorAnimation.durationMs<=0)return;let t=l[e.colorAnimation.timingFunc]??`linear`;return`background-color ${e.colorAnimation.durationMs}ms ${t}, color ${e.colorAnimation.durationMs}ms ${t}`},[e.colorAnimation]),f=e.style===`custom`,p=t>1,m=!p&&e.homeButtonVisible,h=n===`ios`?`center`:`left`,g={backgroundColor:e.backgroundColor,color:e.textStyle===`white`?`#ffffff`:`#000000`,height:i+a,paddingTop:i,transition:d};return(0,s.jsxs)(`header`,{className:`nav-bar nav-bar--${n} nav-bar--${e.textStyle}${f?` nav-bar--custom`:``}`,style:g,"aria-hidden":f,children:[!f&&(0,s.jsxs)(`div`,{className:`nav-bar__row`,style:{height:a,justifyContent:h===`center`?`center`:`flex-start`},children:[(p||m)&&(0,s.jsxs)(`div`,{className:`nav-bar__leading`,children:[p&&(0,s.jsx)(`button`,{type:`button`,className:`nav-bar__back`,"aria-label":`Back`,onClick:o,children:(0,s.jsx)(`svg`,{viewBox:`0 0 24 24`,width:`24`,height:`24`,"aria-hidden":`true`,children:(0,s.jsx)(`path`,{d:`M15 18l-6-6 6-6`,stroke:`currentColor`,strokeWidth:`2`,fill:`none`,strokeLinecap:`round`,strokeLinejoin:`round`})})}),m&&(0,s.jsx)(`button`,{type:`button`,className:`nav-bar__home`,"aria-label":`Home`,onClick:u,children:(0,s.jsx)(`svg`,{viewBox:`0 0 24 24`,width:`22`,height:`22`,"aria-hidden":`true`,children:(0,s.jsx)(`path`,{d:`M3 12l9-9 9 9M5 10v10h14V10`,stroke:`currentColor`,strokeWidth:`2`,fill:`none`,strokeLinecap:`round`,strokeLinejoin:`round`})})})]}),(0,s.jsxs)(`div`,{className:`nav-bar__title nav-bar__title--${h}`,style:{color:e.textStyle===`white`?`#ffffff`:`#000000`},children:[e.loading&&(0,s.jsx)(`span`,{className:`nav-bar__spinner`,"aria-hidden":`true`}),(0,s.jsx)(`span`,{className:`nav-bar__title-text`,children:e.title})]})]}),(0,s.jsx)(c,{platform:n,statusBarHeight:i,textStyle:e.textStyle})]})}function d(e){return{title:e?.title??``,backgroundColor:e?.backgroundColor??`#000000`,textStyle:e?.textStyle??`white`,style:e?.style??`default`,loading:e?.loading??!1,homeButtonVisible:e?.homeButtonVisible??!1,colorAnimation:e?.colorAnimation}}function f(e){switch(e){case`notch`:return{width:164,height:30,top:0,bottomOnly:!0};case`dynamic-island`:return{width:124,height:36,top:11,bottomOnly:!1};default:return null}}function p({height:e,notchType:t,textStyle:n}){let r=f(t);return(0,s.jsxs)(`div`,{className:`device-statusbar`,style:{height:e,color:n===`black`?`#000000`:`#ffffff`},"aria-hidden":`true`,children:[(0,s.jsx)(`span`,{className:`device-statusbar__time`,children:`9:41`}),r&&(0,s.jsx)(`div`,{className:`device-statusbar__notch`,style:{width:r.width,height:r.height,top:r.top,borderRadius:r.bottomOnly?`0 0 ${Math.round(r.height*.6)}px ${Math.round(r.height*.6)}px`:`${r.height/2}px`}}),(0,s.jsxs)(`div`,{className:`device-statusbar__icons`,children:[(0,s.jsx)(`span`,{className:`device-statusbar__signal`}),(0,s.jsx)(`span`,{className:`device-statusbar__wifi`}),(0,s.jsx)(`span`,{className:`device-statusbar__battery`})]})]})}function m({state:e,currentPath:t,resourceBaseUrl:n,appId:r,onSwitch:i,bottomInset:a=0}){if(!e.config||!e.visible)return null;let{color:o,selectedColor:c,backgroundColor:l,borderStyle:u,list:d}=e.config,f=o||`#999999`,p=c||`#1890ff`;return(0,s.jsx)(`div`,{className:`dmb-tab-bar`,style:{backgroundColor:l||`#ffffff`,borderTopColor:u===`white`?`#ffffff`:`#e0e0e0`,paddingBottom:a},role:`tablist`,"aria-label":`TabBar`,children:d.map((a,o)=>{let c=h(a.pagePath),l=c===t,u=g(l?a.selectedIconPath??a.iconPath:a.iconPath,n,r),d=e.badges[o]??``,m=e.redDots[o]??!1;return(0,s.jsxs)(`button`,{type:`button`,className:`dmb-tab-bar__item${l?` is-selected`:``}`,role:`tab`,"aria-selected":l,onClick:()=>i(c),children:[u&&(0,s.jsx)(`span`,{className:`dmb-tab-bar__icon-slot`,children:(0,s.jsx)(`img`,{className:`dmb-tab-bar__icon`,src:u,alt:``,onError:e=>{e.currentTarget.style.display=`none`}})}),(0,s.jsx)(`span`,{className:`dmb-tab-bar__text`,style:{color:l?p:f},children:a.text||``}),d&&(0,s.jsx)(`span`,{className:`dmb-tab-bar__badge`,children:d}),!d&&m&&(0,s.jsx)(`span`,{className:`dmb-tab-bar__red-dot`})]},`${c}-${o}`)})})}function h(e){return e?e.replace(/^\/+/,``):``}function g(e,t,n){if(!e)return null;let r=e.trim();if(!r)return null;if(/^(?:data:|blob:|https?:|\/\/)/i.test(r))return r;if(!t)return null;let i=r.replace(/^\/+/,``).replace(/^\.\//,``);return i.startsWith(`${n}/`)?_(t,i.slice(n.length+1)):_(t,i)}function _(e,t){return`${e.endsWith(`/`)?e:`${e}/`}${t.replace(/^\/+/,``)}`}function v(e){if(!e)return{config:null,visible:!1,badges:[],redDots:[]};let t=e.list.length;return{config:y(e),visible:!0,badges:Array.from({length:t},()=>``),redDots:Array.from({length:t},()=>!1)}}function y(e){return{...e,list:e.list.map(e=>({...e}))}}function b(e,t){switch(t.kind){case`reset`:return{state:v(t.config),ok:!0,errMsg:`reset:ok`};case`visibility`:return{state:{...e,visible:t.visible},ok:!0,errMsg:t.visible?`showTabBar:ok`:`hideTabBar:ok`};case`apply`:return x(e,t.name,t.params)}}function x(e,t,n){if(!e.config)return{state:e,ok:!1,errMsg:`${t}:fail tabBar not configured`};switch(t){case`setTabBarStyle`:return S(e,n);case`setTabBarItem`:return C(e,n);case`showTabBar`:return{state:{...e,visible:!0},ok:!0,errMsg:`showTabBar:ok`};case`hideTabBar`:return{state:{...e,visible:!1},ok:!0,errMsg:`hideTabBar:ok`};case`setTabBarBadge`:return w(e,n);case`removeTabBarBadge`:return T(e,n);case`showTabBarRedDot`:return E(e,n,!0);case`hideTabBarRedDot`:return E(e,n,!1)}}function S(e,t){if(!e.config)return{state:e,ok:!1,errMsg:`setTabBarStyle:fail tabBar not configured`};let n={...e.config},r=(e,t)=>{let r=O(t);r&&(n[e]=r)};return r(`color`,t.color),r(`selectedColor`,t.selectedColor),r(`backgroundColor`,t.backgroundColor),(t.borderStyle===`black`||t.borderStyle===`white`)&&(n.borderStyle=t.borderStyle),{state:{...e,config:n},ok:!0,errMsg:`setTabBarStyle:ok`}}function C(e,t){let n=D(e,t);if(n.err)return{state:e,ok:!1,errMsg:`setTabBarItem:fail ${n.err}`};if(!e.config)return{state:e,ok:!1,errMsg:`setTabBarItem:fail tabBar not configured`};let r=e.config.list[n.index],i={...r,text:typeof t.text==`string`?t.text:r.text,iconPath:typeof t.iconPath==`string`?t.iconPath:r.iconPath,selectedIconPath:typeof t.selectedIconPath==`string`?t.selectedIconPath:r.selectedIconPath},a=[...e.config.list];return a[n.index]=i,{state:{...e,config:{...e.config,list:a}},ok:!0,errMsg:`setTabBarItem:ok`}}function w(e,t){let n=D(e,t);if(n.err)return{state:e,ok:!1,errMsg:`setTabBarBadge:fail ${n.err}`};let r=[...e.badges];r[n.index]=String(t.text??``);let i=[...e.redDots];return i[n.index]=!1,{state:{...e,badges:r,redDots:i},ok:!0,errMsg:`setTabBarBadge:ok`}}function T(e,t){let n=D(e,t);if(n.err)return{state:e,ok:!1,errMsg:`removeTabBarBadge:fail ${n.err}`};let r=[...e.badges];return r[n.index]=``,{state:{...e,badges:r},ok:!0,errMsg:`removeTabBarBadge:ok`}}function E(e,t,n){let r=D(e,t);if(r.err)return{state:e,ok:!1,errMsg:`${n?`showTabBarRedDot`:`hideTabBarRedDot`}:fail ${r.err}`};let i=[...e.redDots];i[r.index]=n;let a=[...e.badges];return n&&(a[r.index]=``),{state:{...e,redDots:i,badges:a},ok:!0,errMsg:`${n?`showTabBarRedDot`:`hideTabBarRedDot`}:ok`}}function D(e,t){let n=e.config?.list??[],r=t.index,i=Number(r);return n.length?r==null||!Number.isInteger(i)||i<0||i>=n.length?{index:-1,err:`invalid index ${r}`}:{index:i,err:null}:{index:-1,err:`tabBar not configured`}}function O(e){if(typeof e!=`string`)return null;let t=e.trim();return!t||t.length>64?null:/[<>"';{}()\\]/.test(t)?/^(?:rgb|rgba|hsl|hsla)\(\s*[\d.,%\s/-]+\)$/i.test(t)?t:null:t}function k(e){return e?e.replace(/^\/+/,``):``}function A(e){let[t,n]=(typeof e==`string`?e:``).split(`?`),r={};if(n)for(let e of n.split(`&`)){if(!e)continue;let t=e.indexOf(`=`),n=t>=0?e.slice(0,t):e,i=t>=0?e.slice(t+1):``;n&&(r[decodeURIComponent(n)]=decodeURIComponent(i))}return{pagePath:k(t),query:r}}function j(e){let t={};return e.isTab&&(t[e.pagePath]=[e]),{stack:[e],tabStacks:t,currentTabPath:e.isTab?e.pagePath:null}}function M(e){return e.currentTabPath?{...e.tabStacks,[e.currentTabPath]:[...e.stack]}:e.tabStacks}function N(e,t){let n=e.stack[e.stack.length-1],r=[...e.stack,t];return{next:{...e,stack:r,tabStacks:e.currentTabPath?{...e.tabStacks,[e.currentTabPath]:r}:e.tabStacks},effects:n?[{kind:`lifecycle`,bridgeId:n.bridgeId,event:`pageHide`}]:[]}}function P(e,t){if(e.stack.length<=1)return{error:`no page to back`};let n=Math.min(Math.max(1,Number.isFinite(t)?t:1),e.stack.length-1),r=e.stack.slice(e.stack.length-n),i=e.stack.slice(0,e.stack.length-n),a=i[i.length-1],o={...e,stack:i,tabStacks:e.currentTabPath?{...e.tabStacks,[e.currentTabPath]:i}:e.tabStacks,currentTabPath:a.isTab?a.pagePath:e.currentTabPath},s=[];for(let e of r)s.push({kind:`lifecycle`,bridgeId:e.bridgeId,event:`pageUnload`}),s.push({kind:`closePage`,bridgeId:e.bridgeId});return s.push({kind:`lifecycle`,bridgeId:a.bridgeId,event:`pageShow`}),{next:o,effects:s}}function F(e,t){let n=e.stack[e.stack.length-1],r=[...e.stack.slice(0,e.stack.length-1),t],i={...e,stack:r,tabStacks:e.currentTabPath?{...e.tabStacks,[e.currentTabPath]:r}:e.tabStacks},a=[];return n&&(a.push({kind:`lifecycle`,bridgeId:n.bridgeId,event:`pageUnload`}),a.push({kind:`closePage`,bridgeId:n.bridgeId})),{next:i,effects:a}}function I(e,t){let n=new Set;for(let t of e.stack)n.add(t.bridgeId);for(let t of Object.values(e.tabStacks))for(let e of t)n.add(e.bridgeId);n.delete(t.bridgeId);let r=t.isTab?{[t.pagePath]:[t]}:{},i={stack:[t],tabStacks:r,currentTabPath:t.isTab?t.pagePath:null},a=[];for(let e of n)a.push({kind:`lifecycle`,bridgeId:e,event:`pageUnload`}),a.push({kind:`closePage`,bridgeId:e});return{next:i,effects:a}}function L(e,t,n){let r=e.stack[e.stack.length-1],i=M(e),a,o=i[t];if(o&&o.length>0)a=o;else if(n)a=[n];else throw Error(`[page-stack] switchTab to ${t} requires either a cached substack or a freshly-opened entry`);let s={...e,stack:a,tabStacks:{...i,[t]:a},currentTabPath:t},c=a[a.length-1],l=[];return r&&r.bridgeId!==c.bridgeId&&l.push({kind:`lifecycle`,bridgeId:r.bridgeId,event:`pageHide`}),n||l.push({kind:`lifecycle`,bridgeId:c.bridgeId,event:`pageShow`}),{next:s,effects:l}}function R(e){let t=new Map,n=e.stack[e.stack.length-1]?.bridgeId,r=e=>{t.has(e.bridgeId)||t.set(e.bridgeId,{entry:e,visible:e.bridgeId===n})};for(let t of Object.values(e.tabStacks))for(let e of t)r(e);for(let t of e.stack)r(t);return Array.from(t.values())}function z(e,t){let n=e.navigationBarBackgroundColor??`#ffffff`,r=e.navigationBarTextStyle??`black`,i=e.navigationStyle??`default`;return d({title:e.navigationBarTitleText??t,backgroundColor:n,textStyle:r,style:i,homeButtonVisible:e.homeButton===!0})}function B(e,t,n){switch(t){case`setNavigationBarTitle`:return{...e,title:typeof n.title==`string`?n.title:e.title};case`setNavigationBarColor`:return H(e,n);case`showNavigationBarLoading`:return{...e,loading:!0};case`hideNavigationBarLoading`:return{...e,loading:!1};case`hideHomeButton`:return{...e,homeButtonVisible:!1};default:return e}}var V=[`linear`,`easeIn`,`easeOut`,`easeInOut`];function H(e,t){let n=typeof t.frontColor==`string`?t.frontColor.toLowerCase():void 0,r=n===`#ffffff`?`white`:n===`#000000`?`black`:e.textStyle,i=typeof t.backgroundColor==`string`?t.backgroundColor:e.backgroundColor,a=(()=>{let e=t.animation;if(!e||typeof e!=`object`)return;let n=e,r=typeof n.duration==`number`&&Number.isFinite(n.duration)?Math.max(0,n.duration):0,i=typeof n.timingFunc==`string`?n.timingFunc:`linear`;return{durationMs:r,timingFunc:V.includes(i)?i:`linear`}})();return{...e,textStyle:r,backgroundColor:i,colorAnimation:a}}function U(e,t,n){let r=e=>e.bridgeId===t?{...e,navBar:n(e.navBar)}:e,i=e.stack.map(r),a={};for(let[t,n]of Object.entries(e.tabStacks))a[t]=n.map(r);return{...e,stack:i,tabStacks:a}}var W=44,G=24,K=44;function q({miniApp:e,bridgeId:t,platform:i=`ios`}){let[a,c]=(0,r.useState)(()=>e.getInitialDevice());(0,r.useEffect)(()=>e.onSimulatorEvent(n.DEVICE_CHANGE,c),[e]);let l=a?.safeAreaInsets.top??(i===`ios`?W:G),d=a?.safeAreaInsets.bottom??0,f=a?.notchType??`none`,h=(0,r.useMemo)(()=>e.getRenderPreloadUrl(),[e]),g=(0,r.useMemo)(()=>e.getTabBarConfig(),[e]),_=(0,r.useMemo)(()=>({bridgeId:t,pagePath:k(e.pagePath),query:{...e.query},isTab:!!e.getTabBarConfig()?.list.some(t=>k(t.pagePath)===k(e.pagePath)),windowConfig:e.rootWindowConfig??{},navBar:z(e.rootWindowConfig??{},e.appId)}),[e,t]),[{shell:y,tabBar:x},S]=(0,r.useState)(()=>({shell:j(_),tabBar:v(g)})),C=(0,r.useRef)({shell:y,tabBar:x});(0,r.useEffect)(()=>{C.current={shell:y,tabBar:x}},[y,x]);let w=(0,r.useCallback)(t=>{for(let n of t)n.kind===`lifecycle`?e.notifyLifecycle(n.bridgeId,n.event):n.kind===`closePage`&&e.closePage(n.bridgeId)},[e]);(0,r.useEffect)(()=>e.onSimulatorEvent(n.NAV_BAR,e=>{S(t=>({...t,shell:U(t.shell,e.bridgeId,t=>B(t,e.name,e.params))}))}),[e]),(0,r.useEffect)(()=>e.onSimulatorEvent(n.TAB_ACTION,t=>{let n=b(C.current.tabBar,{kind:`apply`,name:t.name,params:t.params});S(e=>({...e,tabBar:n.state})),e.notifyNavCallback({ok:n.ok,errMsg:n.errMsg,callbacks:t.callbacks})}),[e]);let T=(0,r.useCallback)(async t=>{let n=(n,r)=>e.notifyNavCallback({ok:n,errMsg:r,callbacks:t.callbacks});try{switch(t.name){case`navigateTo`:await J(e,C,S,w,t,n);break;case`navigateBack`:Y(C,S,w,t,n);break;case`redirectTo`:await X(e,C,S,w,t,n);break;case`reLaunch`:await Z(e,C,S,w,t,n);break;case`switchTab`:await Q(e,C,S,w,t,n);break}}catch(e){n(!1,`${t.name}:fail ${e instanceof Error?e.message:String(e)}`)}},[e,w]);(0,r.useEffect)(()=>e.onSimulatorEvent(n.NAV_ACTION,e=>{T(e)}),[T,e]),(0,r.useEffect)(()=>e.onSimulatorEvent(n.API_CALL,t=>{o(e,t.name,t.params,n=>{e.notifyApiResponse({requestId:t.requestId,ok:n.ok,result:n.result,errMsg:n.errMsg,keep:n.keep})})}),[e]);let E=(0,r.useCallback)(()=>{if(C.current.shell.stack.length<=1)return;let t=C.current.shell.stack;T({appSessionId:e.appSessionId??``,bridgeId:t[t.length-1].bridgeId,name:`navigateBack`,params:{delta:1},callbacks:{}})},[e,T]),D=(0,r.useCallback)(t=>{let n=C.current.shell;t===n.currentTabPath&&n.stack.length===1||T({appSessionId:e.appSessionId??``,bridgeId:n.stack[n.stack.length-1].bridgeId,name:`switchTab`,params:{url:`/${t}`},callbacks:{}})},[e,T]),O=y.stack[y.stack.length-1],A=R(y);return(0,r.useEffect)(()=>{e.notifyActivePage(O.bridgeId)},[e,O.bridgeId]),(0,r.useEffect)(()=>{e.notifyPageStack(y.stack.map(e=>({pagePath:e.pagePath,query:e.query})))},[e,y.stack]),(0,s.jsx)(`main`,{className:`device-shell-root`,children:(0,s.jsxs)(`section`,{className:`device-shell`,"aria-label":`Dimina simulator`,style:a?{width:a.screenWidth,height:a.screenHeight}:void 0,children:[(0,s.jsx)(p,{height:l,notchType:f,textStyle:O.navBar.textStyle}),(0,s.jsx)(u,{state:O.navBar,stackDepth:y.stack.length,platform:i,statusBarHeight:l,navBarHeight:K,onBack:E}),(0,s.jsx)(`div`,{className:`device-shell__viewport`,children:A.map(({entry:t,visible:n})=>(0,s.jsx)(`webview`,{className:`device-shell__webview`,src:e.createRenderHostUrl(t.bridgeId,t.pagePath,t.isTab),preload:h,allowpopups:`true`,style:{display:n?`flex`:`none`,zIndex:n?100:1}},t.bridgeId))}),O.isTab&&(0,s.jsx)(m,{state:x,currentPath:y.currentTabPath,resourceBaseUrl:e.resourceBaseUrl,appId:e.appId,onSwitch:D,bottomInset:d}),d>0&&(0,s.jsx)(`div`,{className:`device-shell__home-indicator`,style:{height:d},"aria-hidden":`true`})]})})}async function J(e,t,n,r,i,a){let{pagePath:o,query:s}=A(i.params.url);if(!o){a(!1,`navigateTo:fail invalid url`);return}if(e.getTabBarConfig()?.list.some(e=>k(e.pagePath)===o)){a(!1,`navigateTo:fail can not navigateTo a tabbar page`);return}let c=await e.openPage(o,s),l={bridgeId:c.bridgeId,pagePath:c.pagePath,query:s,isTab:c.isTab,windowConfig:c.windowConfig,navBar:z(c.windowConfig,e.appId)},{next:u,effects:d}=N(t.current.shell,l);n(e=>({...e,shell:u})),r(d),a(!0,`navigateTo:ok`)}function Y(e,t,n,r,i){let a=r.params.delta,o=Number.isFinite(Number(a))?Number(a):1,s=P(e.current.shell,o);if(`error`in s){i(!1,`navigateBack:fail ${s.error}`);return}t(e=>({...e,shell:s.next})),n(s.effects),i(!0,`navigateBack:ok`)}async function X(e,t,n,r,i,a){let{pagePath:o,query:s}=A(i.params.url);if(!o){a(!1,`redirectTo:fail invalid url`);return}if(e.getTabBarConfig()?.list.some(e=>k(e.pagePath)===o)){a(!1,`redirectTo:fail can not redirectTo a tabbar page`);return}let c=await e.openPage(o,s),l={bridgeId:c.bridgeId,pagePath:c.pagePath,query:s,isTab:c.isTab,windowConfig:c.windowConfig,navBar:z(c.windowConfig,e.appId)},{next:u,effects:d}=F(t.current.shell,l);n(e=>({...e,shell:u})),r(d),a(!0,`redirectTo:ok`)}async function Z(e,t,n,r,i,a){let{pagePath:o,query:s}=A(i.params.url);if(!o){a(!1,`reLaunch:fail invalid url`);return}let c=await e.openPage(o,s),l={bridgeId:c.bridgeId,pagePath:c.pagePath,query:s,isTab:c.isTab,windowConfig:c.windowConfig,navBar:z(c.windowConfig,e.appId)},{next:u,effects:d}=I(t.current.shell,l);n(e=>({...e,shell:u})),r(d),a(!0,`reLaunch:ok`)}async function Q(e,t,n,r,i,a){let{pagePath:o}=A(i.params.url);if(!o){a(!1,`switchTab:fail invalid url`);return}if(!e.getTabBarConfig()?.list.some(e=>k(e.pagePath)===o)){a(!1,`switchTab:fail not a tabBar page: ${o}`);return}let s=t.current.shell.tabStacks[o],c=null;if(!s||s.length===0){let t=await e.openPage(o,{});c={bridgeId:t.bridgeId,pagePath:t.pagePath,query:{},isTab:!0,windowConfig:t.windowConfig,navBar:z(t.windowConfig,e.appId)}}let{next:l,effects:u}=L(t.current.shell,o,c);n(e=>({...e,shell:l})),r(u),a(!0,`switchTab:ok`)}export{q as DeviceShell};
|
|
2
|
+
//# sourceMappingURL=device-shell-TtcSXwhb.js.map
|