@skillbuilder/miniapp-simulator 0.2.2 → 0.2.7
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/docs/assets/audit-auto-stop-config-2026-10-21.jpg +0 -0
- package/docs/assets/audit-balanced-panel-2026-10-16.jpg +0 -0
- package/docs/assets/audit-lcp-input-2026-10-20.jpg +0 -0
- package/docs/assets/audit-paint-game3d-2026-10-16.jpg +0 -0
- package/docs/assets/audit-paint-webgl-2026-10-16.jpg +0 -0
- package/docs/assets/audit-paint-webgl-apm-excerpt-2026-10-16.json +397 -0
- package/docs/assets/audit-poetry-2026-10-16.jpg +0 -0
- package/docs/assets/audit-remaining-results-2026-10-16.json +2749 -0
- package/docs/assets/miniapp-audit-risk-review-2026-10-13.png +0 -0
- package/docs/assets/miniapp-audit-runtime-hung-2026-10-13.png +0 -0
- package/docs/audit-data-collection.codex.md +105 -0
- package/docs/audit-local-validation.codex.md +165 -0
- package/docs/audit-score-design.codex.md +222 -0
- package/docs/audit-score-design.md +832 -0
- package/docs/audit-score-tech-plan.md +450 -0
- package/docs/audit-tech-design.codex.md +485 -0
- package/docs/electron-review.md +223 -12
- package/docs/quality-evaluation-redoc.xml +163 -0
- package/docs/tracker.md +3 -2
- package/lib/client-BjYHK9LR.mjs +1220 -0
- package/lib/{index-D5AYVv8s.mjs → index-CqClPZVv.mjs} +230 -184
- package/lib/index.js +2204 -1999
- package/lib/remote-client.js +2 -2
- package/lib/types/host/shadow-host.d.ts +10 -0
- package/lib/types/injection/registry.d.ts +5 -0
- package/lib/types/remote/audit-controller.d.ts +61 -0
- package/lib/types/remote/audit-leave-monitor.d.ts +12 -0
- package/lib/types/remote/audit-package-sources.d.ts +9 -0
- package/lib/types/remote/audit-telemetry.d.ts +36 -0
- package/lib/types/remote/audit-watchdog.d.ts +14 -0
- package/lib/types/remote/client.d.ts +25 -1
- package/lib/types/remote/load-timing.d.ts +5 -0
- package/lib/types/remote/protocol.d.ts +162 -1
- package/lib/types/remote/runtime.d.ts +2 -0
- package/lib/types/remote-client.d.ts +2 -2
- package/lib/types/runtime/jsapi-modules/interaction.d.ts +1 -1
- package/lib/types/runtime/jsapi-modules/local-media.d.ts +4 -0
- package/lib/types/runtime/jsapi-modules/media.d.ts +1 -1
- package/lib/types/runtime/jsapi-modules/note-publish-media.d.ts +9 -0
- package/lib/types/sw/service-worker-host.d.ts +15 -0
- package/lib/types/tracker/constants.d.ts +1 -1
- package/lib/types/tracker/default-tracker.d.ts +9 -1
- package/lib/types/types/options.d.ts +24 -0
- package/lib/workbench.js +1 -1
- package/package.json +1 -1
- package/lib/client-_vNHVHSm.mjs +0 -775
package/lib/client-_vNHVHSm.mjs
DELETED
|
@@ -1,775 +0,0 @@
|
|
|
1
|
-
import { c as he, r as ye, v as we, o as ve, e as ge } from "./index-D5AYVv8s.mjs";
|
|
2
|
-
const K = {
|
|
3
|
-
report() {
|
|
4
|
-
},
|
|
5
|
-
flush() {
|
|
6
|
-
}
|
|
7
|
-
};
|
|
8
|
-
function be(t) {
|
|
9
|
-
if (!t.enabled) return K;
|
|
10
|
-
let s;
|
|
11
|
-
try {
|
|
12
|
-
const n = { business_line: t.businessLine };
|
|
13
|
-
s = he({
|
|
14
|
-
endpoint: ye(n),
|
|
15
|
-
region: "cn",
|
|
16
|
-
resolveUserId: t.resolveUserId ?? (() => Promise.resolve(""))
|
|
17
|
-
});
|
|
18
|
-
} catch {
|
|
19
|
-
return K;
|
|
20
|
-
}
|
|
21
|
-
return {
|
|
22
|
-
report(n, i = {}) {
|
|
23
|
-
try {
|
|
24
|
-
s.sendCustomPoint({
|
|
25
|
-
name: "simulator_load_stage",
|
|
26
|
-
timestamp: Date.now(),
|
|
27
|
-
payload: {
|
|
28
|
-
business_line: t.businessLine,
|
|
29
|
-
sdk_version: we,
|
|
30
|
-
renderer: "iframe-service-worker",
|
|
31
|
-
app_id: t.appId,
|
|
32
|
-
session_id: t.sessionId,
|
|
33
|
-
runtime_version: t.runtimeVersion,
|
|
34
|
-
stage: n,
|
|
35
|
-
...i
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
} catch {
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
flush() {
|
|
42
|
-
const n = () => {
|
|
43
|
-
try {
|
|
44
|
-
s.flush();
|
|
45
|
-
} catch {
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
try {
|
|
49
|
-
typeof queueMicrotask == "function" ? queueMicrotask(n) : setTimeout(n, 0);
|
|
50
|
-
} catch {
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
function I() {
|
|
56
|
-
try {
|
|
57
|
-
return typeof performance < "u" && typeof performance.now == "function" ? performance.now() : Date.now();
|
|
58
|
-
} catch {
|
|
59
|
-
return Date.now();
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
function h(t) {
|
|
63
|
-
return Math.max(0, Math.round(I() - t));
|
|
64
|
-
}
|
|
65
|
-
function te(t, s, n, i = {}) {
|
|
66
|
-
try {
|
|
67
|
-
const a = Ie(n);
|
|
68
|
-
if (!a) {
|
|
69
|
-
Object.keys(i).length > 0 && t.report(s, i);
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
const { duration: d, ...y } = Ee(a);
|
|
73
|
-
t.report(s, {
|
|
74
|
-
result: "success",
|
|
75
|
-
duration: y.network_duration,
|
|
76
|
-
...i,
|
|
77
|
-
...y
|
|
78
|
-
}), t.report(`${s}_download`, {
|
|
79
|
-
result: "success",
|
|
80
|
-
duration: d
|
|
81
|
-
});
|
|
82
|
-
} catch {
|
|
83
|
-
Object.keys(i).length > 0 && t.report(s, i);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
function Ie(t) {
|
|
87
|
-
if (typeof performance > "u" || !performance.getEntriesByName) return;
|
|
88
|
-
const s = typeof window > "u" ? t : new URL(t, window.location.href).href, n = performance.getEntriesByName(s, "resource");
|
|
89
|
-
return n[n.length - 1];
|
|
90
|
-
}
|
|
91
|
-
function Ee(t) {
|
|
92
|
-
return {
|
|
93
|
-
network_duration: Math.round(t.duration),
|
|
94
|
-
dns_duration: Math.round(t.domainLookupEnd - t.domainLookupStart),
|
|
95
|
-
connect_duration: Math.round(t.connectEnd - t.connectStart),
|
|
96
|
-
ttfb_duration: Math.round(t.responseStart - t.requestStart),
|
|
97
|
-
duration: Math.round(t.responseEnd - t.responseStart),
|
|
98
|
-
bytes: t.transferSize
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
const Se = 7, _e = {
|
|
102
|
-
version: Se
|
|
103
|
-
}, _ = _e.version, qe = "miniapp-simulator:connect", Be = "inspectorPauseRuntime", Me = 3e4, Z = 2, Re = 100;
|
|
104
|
-
function ze(t) {
|
|
105
|
-
if (!t.appId.trim()) throw new Error("remote simulator appId is required");
|
|
106
|
-
if (!t.businessLine.trim()) throw new Error("remote simulator businessLine is required");
|
|
107
|
-
const s = Ae(t.gateway), n = Ce(t.mount), i = Ne([t.serviceUrl, ...t.fallbackServiceUrls ?? []]), a = document.createElement("iframe");
|
|
108
|
-
a.className = t.className ?? "", a.allow = t.iframeAllow ?? "camera; microphone; autoplay; geolocation", a.referrerPolicy = "no-referrer", a.style.display = "block", a.style.width = "100%", a.style.height = "100%", a.style.border = "0";
|
|
109
|
-
const d = t.timeout ?? Me, y = /* @__PURE__ */ new Map(), N = de(t.options), p = new Map(Object.entries(t.hostApi ?? {})), m = /* @__PURE__ */ new Map(), q = /* @__PURE__ */ new Map();
|
|
110
|
-
let k = 0, S = ee(), w, V, D, M, R = !1, U, A = !1, W = "single", g = null, b = !1;
|
|
111
|
-
const O = I();
|
|
112
|
-
let F = O, j = O, H, B;
|
|
113
|
-
const f = be({
|
|
114
|
-
enabled: t.tracker !== !1,
|
|
115
|
-
businessLine: t.businessLine,
|
|
116
|
-
appId: t.appId,
|
|
117
|
-
sessionId: S,
|
|
118
|
-
resolveUserId: () => Promise.resolve(typeof B?.userId == "string" ? B.userId : "")
|
|
119
|
-
});
|
|
120
|
-
let x, L;
|
|
121
|
-
const ne = new Promise((e, r) => {
|
|
122
|
-
x = e, L = r;
|
|
123
|
-
});
|
|
124
|
-
let C;
|
|
125
|
-
function T() {
|
|
126
|
-
C !== void 0 && (window.clearTimeout(C), C = void 0);
|
|
127
|
-
}
|
|
128
|
-
function se() {
|
|
129
|
-
T(), C = window.setTimeout(() => {
|
|
130
|
-
const e = new Error(`remote simulator timed out after ${d}ms`);
|
|
131
|
-
b = !0, f.report("client_ready", {
|
|
132
|
-
result: "timeout",
|
|
133
|
-
duration: h(O)
|
|
134
|
-
}), f.flush(), M(e), L(e);
|
|
135
|
-
}, d);
|
|
136
|
-
}
|
|
137
|
-
pe();
|
|
138
|
-
function ie(e) {
|
|
139
|
-
const r = q.get(e.requestId);
|
|
140
|
-
if (r)
|
|
141
|
-
if (q.delete(e.requestId), window.clearTimeout(r.timer), e.ok)
|
|
142
|
-
f.report("remote_request", {
|
|
143
|
-
type: r.method,
|
|
144
|
-
request_id: e.requestId,
|
|
145
|
-
result: "success",
|
|
146
|
-
duration: h(r.startedAt)
|
|
147
|
-
}), r.resolve(e.result);
|
|
148
|
-
else {
|
|
149
|
-
const o = new Error(
|
|
150
|
-
e.error?.message ?? "remote simulator request failed"
|
|
151
|
-
);
|
|
152
|
-
e.error?.code && (o.code = e.error.code), f.report("remote_request", {
|
|
153
|
-
type: r.method,
|
|
154
|
-
request_id: e.requestId,
|
|
155
|
-
result: "fail",
|
|
156
|
-
duration: h(r.startedAt),
|
|
157
|
-
error_name: e.error?.code,
|
|
158
|
-
message: o.message.slice(0, 512)
|
|
159
|
-
}), r.reject(o);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
async function ae(e, r) {
|
|
163
|
-
const o = p.get(e.event);
|
|
164
|
-
if (typeof o != "function") {
|
|
165
|
-
r.postMessage({
|
|
166
|
-
type: "host-api-response",
|
|
167
|
-
requestId: e.requestId,
|
|
168
|
-
ok: !1,
|
|
169
|
-
error: { message: `hostApi handler is unavailable: ${e.event}` }
|
|
170
|
-
});
|
|
171
|
-
return;
|
|
172
|
-
}
|
|
173
|
-
try {
|
|
174
|
-
const l = await o(e.request);
|
|
175
|
-
r.postMessage({
|
|
176
|
-
type: "host-api-response",
|
|
177
|
-
requestId: e.requestId,
|
|
178
|
-
ok: !0,
|
|
179
|
-
result: l
|
|
180
|
-
});
|
|
181
|
-
} catch (l) {
|
|
182
|
-
const u = l;
|
|
183
|
-
r.postMessage({
|
|
184
|
-
type: "host-api-response",
|
|
185
|
-
requestId: e.requestId,
|
|
186
|
-
ok: !1,
|
|
187
|
-
error: {
|
|
188
|
-
message: u instanceof Error ? u.message : String(l),
|
|
189
|
-
code: u?.code
|
|
190
|
-
}
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
async function ce(e, r) {
|
|
195
|
-
const o = p.get("request");
|
|
196
|
-
if (typeof o != "function") {
|
|
197
|
-
r.postMessage({
|
|
198
|
-
type: "host-request-response",
|
|
199
|
-
requestId: e.requestId,
|
|
200
|
-
ok: !1,
|
|
201
|
-
error: { message: "host request implementation is unavailable" }
|
|
202
|
-
});
|
|
203
|
-
return;
|
|
204
|
-
}
|
|
205
|
-
const l = new AbortController();
|
|
206
|
-
m.set(e.requestId, l);
|
|
207
|
-
try {
|
|
208
|
-
const u = await ge(o, e.options, {
|
|
209
|
-
signal: l.signal,
|
|
210
|
-
onHeaders(v) {
|
|
211
|
-
r.postMessage({
|
|
212
|
-
type: "host-request-event",
|
|
213
|
-
requestId: e.requestId,
|
|
214
|
-
event: "headers",
|
|
215
|
-
payload: v
|
|
216
|
-
});
|
|
217
|
-
},
|
|
218
|
-
onChunk(v) {
|
|
219
|
-
r.postMessage({
|
|
220
|
-
type: "host-request-event",
|
|
221
|
-
requestId: e.requestId,
|
|
222
|
-
event: "chunk",
|
|
223
|
-
payload: v
|
|
224
|
-
});
|
|
225
|
-
}
|
|
226
|
-
});
|
|
227
|
-
r.postMessage({
|
|
228
|
-
type: "host-request-response",
|
|
229
|
-
requestId: e.requestId,
|
|
230
|
-
ok: !0,
|
|
231
|
-
result: u
|
|
232
|
-
});
|
|
233
|
-
} catch (u) {
|
|
234
|
-
const v = u;
|
|
235
|
-
r.postMessage({
|
|
236
|
-
type: "host-request-response",
|
|
237
|
-
requestId: e.requestId,
|
|
238
|
-
ok: !1,
|
|
239
|
-
error: {
|
|
240
|
-
message: v instanceof Error ? v.message : String(u),
|
|
241
|
-
code: v?.code
|
|
242
|
-
}
|
|
243
|
-
});
|
|
244
|
-
} finally {
|
|
245
|
-
m.delete(e.requestId);
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
function ue(e) {
|
|
249
|
-
m.get(e.requestId)?.abort();
|
|
250
|
-
}
|
|
251
|
-
function le(e) {
|
|
252
|
-
e.event === "inspectorChange" && (A = !!e.payload?.enabled), J(e.event, e.payload);
|
|
253
|
-
}
|
|
254
|
-
function G(e, r) {
|
|
255
|
-
let o = y.get(e);
|
|
256
|
-
o || (o = /* @__PURE__ */ new Set(), y.set(e, o)), o.add(r);
|
|
257
|
-
}
|
|
258
|
-
function de(e) {
|
|
259
|
-
if (!e) return {};
|
|
260
|
-
const { onRouterChange: r, onScreenShot: o, ...l } = e;
|
|
261
|
-
return r && G(
|
|
262
|
-
"routerChange",
|
|
263
|
-
(u) => r(u)
|
|
264
|
-
), o && G("screenShot", (u) => o(u)), l;
|
|
265
|
-
}
|
|
266
|
-
a.onload = () => {
|
|
267
|
-
g && te(f, "runtime_document", g.href, {
|
|
268
|
-
result: "success",
|
|
269
|
-
duration: h(F)
|
|
270
|
-
}), fe();
|
|
271
|
-
};
|
|
272
|
-
async function fe() {
|
|
273
|
-
if (R || !g) return;
|
|
274
|
-
const e = w, r = S, o = await ke(p);
|
|
275
|
-
if (B = o, R || !g || e !== w) return;
|
|
276
|
-
const l = {
|
|
277
|
-
type: qe,
|
|
278
|
-
protocolVersion: _,
|
|
279
|
-
sessionId: r,
|
|
280
|
-
appId: t.appId,
|
|
281
|
-
businessLine: t.businessLine,
|
|
282
|
-
tracker: t.tracker !== !1,
|
|
283
|
-
gateway: s,
|
|
284
|
-
userInfo: o,
|
|
285
|
-
hostApiMethods: X(p),
|
|
286
|
-
hostApiStubs: Q(p),
|
|
287
|
-
options: N
|
|
288
|
-
};
|
|
289
|
-
j = I(), a.contentWindow?.postMessage(l, g.origin, [e.port2]);
|
|
290
|
-
}
|
|
291
|
-
a.onerror = () => {
|
|
292
|
-
const e = new Error(
|
|
293
|
-
`remote simulator failed to load: ${g?.href ?? i[0]}`
|
|
294
|
-
);
|
|
295
|
-
f.report("runtime_document", {
|
|
296
|
-
result: "fail",
|
|
297
|
-
duration: h(F),
|
|
298
|
-
message: e.message.slice(0, 512)
|
|
299
|
-
}), f.flush(), M(e), b ? J("error", {
|
|
300
|
-
code: "LOAD_FAILED",
|
|
301
|
-
message: e.message,
|
|
302
|
-
url: g?.href,
|
|
303
|
-
cause: e
|
|
304
|
-
}) : (b = !0, T(), L(e));
|
|
305
|
-
}, Ue(i, f).then(
|
|
306
|
-
(e) => {
|
|
307
|
-
R || (g = e, F = I(), se(), a.src = e.href, n.appendChild(a));
|
|
308
|
-
},
|
|
309
|
-
(e) => {
|
|
310
|
-
const r = e instanceof Error ? e : new Error(String(e));
|
|
311
|
-
b = !0, T(), f.report("client_ready", {
|
|
312
|
-
result: "fail",
|
|
313
|
-
duration: h(O),
|
|
314
|
-
message: r.message.slice(0, 512)
|
|
315
|
-
}), f.flush(), M(r), L(r);
|
|
316
|
-
}
|
|
317
|
-
);
|
|
318
|
-
async function c(e, ...r) {
|
|
319
|
-
return z(`${S}-${++k}`, e, ...r);
|
|
320
|
-
}
|
|
321
|
-
async function z(e, r, ...o) {
|
|
322
|
-
if (R) throw new Error("remote simulator has been destroyed");
|
|
323
|
-
await V;
|
|
324
|
-
const l = Pe(o);
|
|
325
|
-
return new Promise((u, v) => {
|
|
326
|
-
const Y = I(), me = window.setTimeout(() => {
|
|
327
|
-
q.delete(e), f.report("remote_request", {
|
|
328
|
-
type: r,
|
|
329
|
-
request_id: e,
|
|
330
|
-
result: "timeout",
|
|
331
|
-
duration: h(Y)
|
|
332
|
-
}), v(new Error(`remote simulator ${r} timed out after ${d}ms`));
|
|
333
|
-
}, d);
|
|
334
|
-
q.set(e, { resolve: u, reject: v, timer: me, method: r, startedAt: Y }), w.port1.postMessage({ type: "request", requestId: e, method: r, args: o }, l);
|
|
335
|
-
});
|
|
336
|
-
}
|
|
337
|
-
return {
|
|
338
|
-
iframe: a,
|
|
339
|
-
ready: ne,
|
|
340
|
-
load: () => c("load"),
|
|
341
|
-
async loadZip(e, r) {
|
|
342
|
-
const o = `${S}-${++k}`, l = I();
|
|
343
|
-
try {
|
|
344
|
-
const u = await oe(e).arrayBuffer();
|
|
345
|
-
return f.report("package_materialize", {
|
|
346
|
-
request_id: o,
|
|
347
|
-
result: "success",
|
|
348
|
-
duration: h(l),
|
|
349
|
-
bytes: u.byteLength,
|
|
350
|
-
type: "zip"
|
|
351
|
-
}), z(o, "loadZip", {
|
|
352
|
-
buffer: u,
|
|
353
|
-
options: r
|
|
354
|
-
});
|
|
355
|
-
} catch (u) {
|
|
356
|
-
throw f.report("package_materialize", {
|
|
357
|
-
request_id: o,
|
|
358
|
-
result: "fail",
|
|
359
|
-
duration: h(l),
|
|
360
|
-
type: "zip",
|
|
361
|
-
message: $(u).slice(0, 512)
|
|
362
|
-
}), u;
|
|
363
|
-
}
|
|
364
|
-
},
|
|
365
|
-
loadFiles: async (e, r) => {
|
|
366
|
-
const o = `${S}-${++k}`, l = I();
|
|
367
|
-
try {
|
|
368
|
-
const u = await Ve(e);
|
|
369
|
-
return f.report("package_materialize", {
|
|
370
|
-
request_id: o,
|
|
371
|
-
result: "success",
|
|
372
|
-
duration: h(l),
|
|
373
|
-
type: "files",
|
|
374
|
-
count: Object.keys(u).length,
|
|
375
|
-
bytes: Fe(u)
|
|
376
|
-
}), z(o, "loadFiles", {
|
|
377
|
-
files: u,
|
|
378
|
-
options: r
|
|
379
|
-
});
|
|
380
|
-
} catch (u) {
|
|
381
|
-
throw f.report("package_materialize", {
|
|
382
|
-
request_id: o,
|
|
383
|
-
result: "fail",
|
|
384
|
-
duration: h(l),
|
|
385
|
-
type: "files",
|
|
386
|
-
message: $(u).slice(0, 512)
|
|
387
|
-
}), u;
|
|
388
|
-
}
|
|
389
|
-
},
|
|
390
|
-
loadApp: (e, r) => c("loadApp", e, r),
|
|
391
|
-
unload: () => void c("unload"),
|
|
392
|
-
reload: () => c("reload"),
|
|
393
|
-
capture: (e) => c("capture", e),
|
|
394
|
-
setViewport: (e) => {
|
|
395
|
-
c("setViewport", e);
|
|
396
|
-
},
|
|
397
|
-
switchContentMode: (e) => c("switchContentMode", e),
|
|
398
|
-
switchPhoneFrame: (e) => c("switchPhoneFrame", e),
|
|
399
|
-
permissionSheet: {
|
|
400
|
-
show: (e) => c("permissionSheet.show", e),
|
|
401
|
-
hide: () => {
|
|
402
|
-
c("permissionSheet.hide");
|
|
403
|
-
}
|
|
404
|
-
},
|
|
405
|
-
notePreview: {
|
|
406
|
-
update: (e) => {
|
|
407
|
-
c("notePreview.update", e);
|
|
408
|
-
},
|
|
409
|
-
updateUser: (e) => {
|
|
410
|
-
c("notePreview.updateUser", e);
|
|
411
|
-
},
|
|
412
|
-
updateAppCard: (e) => {
|
|
413
|
-
c("notePreview.updateAppCard", e);
|
|
414
|
-
}
|
|
415
|
-
},
|
|
416
|
-
widgetCover: {
|
|
417
|
-
update: (e) => {
|
|
418
|
-
c("widgetCover.update", e);
|
|
419
|
-
}
|
|
420
|
-
},
|
|
421
|
-
redirectTo: (e, r) => c("router.redirectTo", e, r),
|
|
422
|
-
getCurrentRoute: () => c("router.getRoute"),
|
|
423
|
-
screenShot: () => c("screenShot"),
|
|
424
|
-
setAutoScreenShot: (e) => c("setAutoScreenShot", e),
|
|
425
|
-
inspector: {
|
|
426
|
-
enable: () => {
|
|
427
|
-
A = !0, c("inspector.enable");
|
|
428
|
-
},
|
|
429
|
-
disable: () => {
|
|
430
|
-
A = !1, c("inspector.disable");
|
|
431
|
-
},
|
|
432
|
-
toggle: () => {
|
|
433
|
-
A = !A, c("inspector.toggle");
|
|
434
|
-
},
|
|
435
|
-
isEnabled: () => A,
|
|
436
|
-
clear: () => {
|
|
437
|
-
c("inspector.clear");
|
|
438
|
-
},
|
|
439
|
-
setSelectionMode: (e) => {
|
|
440
|
-
W = e, c("inspector.setSelectionMode", e);
|
|
441
|
-
},
|
|
442
|
-
getSelectionMode: () => W,
|
|
443
|
-
getSceneTree: () => c("inspector.getSceneTree"),
|
|
444
|
-
selectByRef: (e) => c("inspector.selectByRef", e)
|
|
445
|
-
},
|
|
446
|
-
hostApi: {
|
|
447
|
-
set(e, r) {
|
|
448
|
-
p.set(e, r), P();
|
|
449
|
-
},
|
|
450
|
-
registerAll(e) {
|
|
451
|
-
for (const [r, o] of Object.entries(e)) p.set(r, o);
|
|
452
|
-
P();
|
|
453
|
-
},
|
|
454
|
-
remove(e) {
|
|
455
|
-
p.delete(e), P();
|
|
456
|
-
},
|
|
457
|
-
clear() {
|
|
458
|
-
p.clear(), P();
|
|
459
|
-
},
|
|
460
|
-
has: (e) => p.has(e),
|
|
461
|
-
emit: (e, r) => {
|
|
462
|
-
c("hostApi.emit", e, r);
|
|
463
|
-
}
|
|
464
|
-
},
|
|
465
|
-
invoke: c,
|
|
466
|
-
on(e, r) {
|
|
467
|
-
let o = y.get(e);
|
|
468
|
-
return o || (o = /* @__PURE__ */ new Set(), y.set(e, o)), o.add(r), () => o?.delete(r);
|
|
469
|
-
},
|
|
470
|
-
destroy(e) {
|
|
471
|
-
if (!R) {
|
|
472
|
-
R = !0, U?.(), T(), je(w.port1, S, ++k, e), M(new Error("remote simulator has been destroyed"));
|
|
473
|
-
for (const r of q.values())
|
|
474
|
-
window.clearTimeout(r.timer), r.reject(new Error("remote simulator has been destroyed"));
|
|
475
|
-
q.clear();
|
|
476
|
-
for (const r of m.values()) r.abort();
|
|
477
|
-
m.clear(), w.port1.close(), f.flush(), a.remove(), y.clear();
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
};
|
|
481
|
-
function P() {
|
|
482
|
-
return c("hostApi.sync", X(p), Q(p));
|
|
483
|
-
}
|
|
484
|
-
function pe() {
|
|
485
|
-
U?.(), U = void 0;
|
|
486
|
-
for (const r of m.values()) r.abort();
|
|
487
|
-
m.clear(), w && (w.port1.close(), S = ee()), k = 0, w = new MessageChannel(), V = new Promise((r, o) => {
|
|
488
|
-
D = r, M = o;
|
|
489
|
-
}), V.catch(() => {
|
|
490
|
-
});
|
|
491
|
-
const e = w;
|
|
492
|
-
e.port1.onmessage = (r) => {
|
|
493
|
-
if (e !== w) return;
|
|
494
|
-
const o = r.data;
|
|
495
|
-
if (o?.type === "ready") {
|
|
496
|
-
if (o.protocolVersion !== _) {
|
|
497
|
-
const l = new Error(
|
|
498
|
-
`unsupported remote simulator protocol: ${o.protocolVersion} (client=${_})`
|
|
499
|
-
);
|
|
500
|
-
f.report("runtime_handshake", {
|
|
501
|
-
result: "protocol_mismatch",
|
|
502
|
-
duration: h(j),
|
|
503
|
-
runtime_version: o.runtimeVersion
|
|
504
|
-
}), f.flush(), M(l), b || (b = !0, T(), L(l));
|
|
505
|
-
return;
|
|
506
|
-
}
|
|
507
|
-
H = o.runtimeVersion, U?.(), U = ve(a, (l) => {
|
|
508
|
-
e.port1.postMessage({ type: "worker-visibility", visible: l });
|
|
509
|
-
}), f.report("runtime_handshake", {
|
|
510
|
-
result: "success",
|
|
511
|
-
duration: h(j),
|
|
512
|
-
runtime_version: H
|
|
513
|
-
}), f.report("client_ready", {
|
|
514
|
-
result: "success",
|
|
515
|
-
duration: h(O),
|
|
516
|
-
runtime_version: H
|
|
517
|
-
}), D(o), b || (b = !0, T(), x(o));
|
|
518
|
-
return;
|
|
519
|
-
}
|
|
520
|
-
if (o?.type === "response") {
|
|
521
|
-
ie(o);
|
|
522
|
-
return;
|
|
523
|
-
}
|
|
524
|
-
if (o?.type === "host-api-request") {
|
|
525
|
-
ae(o, e.port1);
|
|
526
|
-
return;
|
|
527
|
-
}
|
|
528
|
-
if (o?.type === "host-request") {
|
|
529
|
-
ce(o, e.port1);
|
|
530
|
-
return;
|
|
531
|
-
}
|
|
532
|
-
if (o?.type === "host-request-abort") {
|
|
533
|
-
ue(o);
|
|
534
|
-
return;
|
|
535
|
-
}
|
|
536
|
-
o?.type === "event" && le(o);
|
|
537
|
-
}, e.port1.start();
|
|
538
|
-
}
|
|
539
|
-
function J(e, r) {
|
|
540
|
-
for (const o of [e, "*"])
|
|
541
|
-
for (const l of y.get(o) ?? []) l(r);
|
|
542
|
-
}
|
|
543
|
-
}
|
|
544
|
-
function Ae(t) {
|
|
545
|
-
if (!t) return;
|
|
546
|
-
const s = {};
|
|
547
|
-
for (const [n, i] of Object.entries(t)) {
|
|
548
|
-
if (typeof i != "string" || !i.trim())
|
|
549
|
-
throw new Error(`remote simulator gateway.${n} must be a non-empty HTTPS URL`);
|
|
550
|
-
const a = i.trim().replace(/\/+$/, "");
|
|
551
|
-
let d;
|
|
552
|
-
try {
|
|
553
|
-
d = new URL(a);
|
|
554
|
-
} catch {
|
|
555
|
-
throw new Error(`remote simulator gateway.${n} must be an absolute HTTPS URL`);
|
|
556
|
-
}
|
|
557
|
-
if (!Te(d))
|
|
558
|
-
throw new Error(
|
|
559
|
-
`remote simulator gateway.${n} must use HTTPS (HTTP is allowed only for loopback development)`
|
|
560
|
-
);
|
|
561
|
-
s[n] = a;
|
|
562
|
-
}
|
|
563
|
-
if (!s.edith)
|
|
564
|
-
throw new Error("remote simulator gateway.edith is required");
|
|
565
|
-
if (!s.www)
|
|
566
|
-
throw new Error("remote simulator gateway.www is required");
|
|
567
|
-
return s;
|
|
568
|
-
}
|
|
569
|
-
function Te(t) {
|
|
570
|
-
return t.protocol === "https:" ? !0 : t.protocol === "http:" && (t.hostname === "localhost" || t.hostname === "127.0.0.1" || t.hostname === "[::1]");
|
|
571
|
-
}
|
|
572
|
-
function X(t) {
|
|
573
|
-
return [...t].filter(([, s]) => typeof s == "function").map(([s]) => s);
|
|
574
|
-
}
|
|
575
|
-
async function ke(t) {
|
|
576
|
-
const s = t.get("getUserInfo");
|
|
577
|
-
if (typeof s == "function")
|
|
578
|
-
try {
|
|
579
|
-
const n = await s({
|
|
580
|
-
event: "getUserInfo",
|
|
581
|
-
message: {},
|
|
582
|
-
callbackId: ""
|
|
583
|
-
});
|
|
584
|
-
return n && typeof n == "object" ? n : void 0;
|
|
585
|
-
} catch {
|
|
586
|
-
return;
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
|
-
function Q(t) {
|
|
590
|
-
return Object.fromEntries(
|
|
591
|
-
[...t].filter((s) => {
|
|
592
|
-
const n = s[1];
|
|
593
|
-
return typeof n != "function" && typeof n.toast == "string";
|
|
594
|
-
})
|
|
595
|
-
);
|
|
596
|
-
}
|
|
597
|
-
class E extends Error {
|
|
598
|
-
constructor(s, n, i, a) {
|
|
599
|
-
super(s), this.kind = n, this.retryable = i, this.status = a, this.name = "ManifestRequestError";
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
|
-
async function Ue(t, s) {
|
|
603
|
-
const n = [], i = new Set(t.map((a) => a.href));
|
|
604
|
-
for (let a = 1; a <= Z; a += 1) {
|
|
605
|
-
for (const [d, y] of t.entries()) {
|
|
606
|
-
if (a > 1 && !i.has(y.href)) continue;
|
|
607
|
-
const N = I();
|
|
608
|
-
try {
|
|
609
|
-
const p = await Oe(y), m = re(y);
|
|
610
|
-
return te(s, "runtime_manifest", m.href, {
|
|
611
|
-
result: "success",
|
|
612
|
-
duration: h(N),
|
|
613
|
-
type: d === 0 ? "primary" : "fallback",
|
|
614
|
-
count: a
|
|
615
|
-
}), p;
|
|
616
|
-
} catch (p) {
|
|
617
|
-
const m = Le(p);
|
|
618
|
-
s.report("runtime_manifest", {
|
|
619
|
-
result: "fail",
|
|
620
|
-
duration: h(N),
|
|
621
|
-
type: d === 0 ? "primary" : "fallback",
|
|
622
|
-
count: a,
|
|
623
|
-
...m.status === void 0 ? { error_name: m.kind } : { code: m.status },
|
|
624
|
-
message: m.message.slice(0, 512)
|
|
625
|
-
}), n.push(`${y.href} attempt ${a}: ${m.message}`), m.retryable || i.delete(y.href);
|
|
626
|
-
}
|
|
627
|
-
}
|
|
628
|
-
if (a >= Z || i.size === 0) break;
|
|
629
|
-
await $e();
|
|
630
|
-
}
|
|
631
|
-
throw new Error(`remote simulator services unavailable: ${n.join("; ")}`);
|
|
632
|
-
}
|
|
633
|
-
async function Oe(t) {
|
|
634
|
-
const s = re(t);
|
|
635
|
-
s.searchParams.set("protocolVersion", String(_));
|
|
636
|
-
let n;
|
|
637
|
-
try {
|
|
638
|
-
n = await fetch(s, {
|
|
639
|
-
method: "GET",
|
|
640
|
-
credentials: "omit",
|
|
641
|
-
cache: "no-store"
|
|
642
|
-
});
|
|
643
|
-
} catch (d) {
|
|
644
|
-
throw new E(
|
|
645
|
-
`remote simulator manifest network error: ${$(d)}`,
|
|
646
|
-
"MANIFEST_NETWORK_ERROR",
|
|
647
|
-
!0
|
|
648
|
-
);
|
|
649
|
-
}
|
|
650
|
-
if (!n.ok)
|
|
651
|
-
throw new E(
|
|
652
|
-
`remote simulator manifest request failed: HTTP ${n.status}`,
|
|
653
|
-
"MANIFEST_HTTP_ERROR",
|
|
654
|
-
!0,
|
|
655
|
-
n.status
|
|
656
|
-
);
|
|
657
|
-
let i;
|
|
658
|
-
try {
|
|
659
|
-
i = await n.json();
|
|
660
|
-
} catch (d) {
|
|
661
|
-
throw new E(
|
|
662
|
-
`remote simulator manifest JSON is invalid: ${$(d)}`,
|
|
663
|
-
"MANIFEST_INVALID_JSON",
|
|
664
|
-
!0
|
|
665
|
-
);
|
|
666
|
-
}
|
|
667
|
-
if (typeof i.buildId != "string" || !i.buildId || typeof i.documentUrl != "string" || !i.documentUrl)
|
|
668
|
-
throw new E(
|
|
669
|
-
"remote simulator manifest response is invalid",
|
|
670
|
-
"MANIFEST_INVALID_RESPONSE",
|
|
671
|
-
!1
|
|
672
|
-
);
|
|
673
|
-
if (i.protocolVersion !== _)
|
|
674
|
-
throw new E(
|
|
675
|
-
`unsupported remote simulator protocol: ${String(i.protocolVersion)} (client=${_})`,
|
|
676
|
-
"MANIFEST_PROTOCOL_MISMATCH",
|
|
677
|
-
!1
|
|
678
|
-
);
|
|
679
|
-
const a = new URL(i.documentUrl, s);
|
|
680
|
-
if (a.origin !== t.origin)
|
|
681
|
-
throw new E(
|
|
682
|
-
`remote simulator document origin mismatch: ${a.origin} (service=${t.origin})`,
|
|
683
|
-
"MANIFEST_ORIGIN_MISMATCH",
|
|
684
|
-
!1
|
|
685
|
-
);
|
|
686
|
-
return a;
|
|
687
|
-
}
|
|
688
|
-
function Le(t) {
|
|
689
|
-
return t instanceof E ? t : new E($(t), "MANIFEST_UNKNOWN_ERROR", !1);
|
|
690
|
-
}
|
|
691
|
-
function $e() {
|
|
692
|
-
return new Promise((t) => window.setTimeout(t, Re));
|
|
693
|
-
}
|
|
694
|
-
function re(t) {
|
|
695
|
-
const s = t.href.endsWith("/") ? t : new URL(`${t.href}/`), n = new URL("runtime-manifest", s);
|
|
696
|
-
return n.searchParams.set("protocolVersion", String(_)), n;
|
|
697
|
-
}
|
|
698
|
-
function Ne(t) {
|
|
699
|
-
const s = /* @__PURE__ */ new Set(), n = [];
|
|
700
|
-
for (const i of t) {
|
|
701
|
-
const a = new URL(i, window.location.href), d = a.href.endsWith("/") ? a : new URL(`${a.href}/`);
|
|
702
|
-
s.has(d.href) || (s.add(d.href), n.push(d));
|
|
703
|
-
}
|
|
704
|
-
return n;
|
|
705
|
-
}
|
|
706
|
-
function $(t) {
|
|
707
|
-
return t instanceof Error ? t.message : String(t);
|
|
708
|
-
}
|
|
709
|
-
function Ce(t) {
|
|
710
|
-
const s = typeof t == "string" ? document.querySelector(t) : t;
|
|
711
|
-
if (!s) throw new Error("remote simulator mount element not found");
|
|
712
|
-
return s;
|
|
713
|
-
}
|
|
714
|
-
function oe(t) {
|
|
715
|
-
if (t instanceof Blob) return t;
|
|
716
|
-
const s = t instanceof ArrayBuffer ? t : Uint8Array.from(t).buffer;
|
|
717
|
-
return new Blob([s]);
|
|
718
|
-
}
|
|
719
|
-
function Pe(t) {
|
|
720
|
-
const s = /* @__PURE__ */ new Set(), n = (i) => {
|
|
721
|
-
if (i instanceof ArrayBuffer) {
|
|
722
|
-
s.add(i);
|
|
723
|
-
return;
|
|
724
|
-
}
|
|
725
|
-
if (ArrayBuffer.isView(i)) {
|
|
726
|
-
s.add(i.buffer);
|
|
727
|
-
return;
|
|
728
|
-
}
|
|
729
|
-
if (!(!i || typeof i != "object")) {
|
|
730
|
-
if (Array.isArray(i)) {
|
|
731
|
-
i.forEach(n);
|
|
732
|
-
return;
|
|
733
|
-
}
|
|
734
|
-
Object.values(i).forEach(n);
|
|
735
|
-
}
|
|
736
|
-
};
|
|
737
|
-
return n(t), [...s];
|
|
738
|
-
}
|
|
739
|
-
async function Ve(t) {
|
|
740
|
-
return Object.fromEntries(
|
|
741
|
-
await Promise.all(
|
|
742
|
-
Object.entries(t).map(async ([s, n]) => [
|
|
743
|
-
s,
|
|
744
|
-
typeof n == "string" ? n : await oe(n).arrayBuffer()
|
|
745
|
-
])
|
|
746
|
-
)
|
|
747
|
-
);
|
|
748
|
-
}
|
|
749
|
-
function Fe(t) {
|
|
750
|
-
try {
|
|
751
|
-
const s = new TextEncoder();
|
|
752
|
-
return Object.values(t).reduce((n, i) => typeof i == "string" ? n + s.encode(i).byteLength : i instanceof ArrayBuffer || ArrayBuffer.isView(i) ? n + i.byteLength : n, 0);
|
|
753
|
-
} catch {
|
|
754
|
-
return;
|
|
755
|
-
}
|
|
756
|
-
}
|
|
757
|
-
function je(t, s, n, i) {
|
|
758
|
-
try {
|
|
759
|
-
t.postMessage({
|
|
760
|
-
type: "request",
|
|
761
|
-
requestId: `${s}-${n}`,
|
|
762
|
-
method: "destroy",
|
|
763
|
-
args: [i]
|
|
764
|
-
});
|
|
765
|
-
} catch {
|
|
766
|
-
}
|
|
767
|
-
}
|
|
768
|
-
function ee() {
|
|
769
|
-
return typeof crypto.randomUUID == "function" ? crypto.randomUUID() : `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
|
|
770
|
-
}
|
|
771
|
-
export {
|
|
772
|
-
Be as R,
|
|
773
|
-
_ as a,
|
|
774
|
-
ze as c
|
|
775
|
-
};
|