@skillbuilder/miniapp-simulator 0.0.0-stage → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (231) hide show
  1. package/README.md +263 -2
  2. package/assets/phones/Nexus-5X.png +0 -0
  3. package/assets/phones/iPhone-14ProMax.png +0 -0
  4. package/assets/rednote-preview/cover/homebar-1439.jpg +0 -0
  5. package/assets/rednote-preview/cover/homebar-1679.jpg +0 -0
  6. package/assets/rednote-preview/cover/homebar-1919.jpg +0 -0
  7. package/assets/rednote-preview/cover/homebar-2284.jpg +0 -0
  8. package/assets/rednote-preview/cover/homebar-2285.jpg +0 -0
  9. package/assets/rednote-preview/cover/like.png +0 -0
  10. package/assets/rednote-preview/cover/play.png +0 -0
  11. package/assets/rednote-preview/cover/topbar-1439.jpg +0 -0
  12. package/assets/rednote-preview/cover/topbar-1679.jpg +0 -0
  13. package/assets/rednote-preview/cover/topbar-1919.jpg +0 -0
  14. package/assets/rednote-preview/cover/topbar-2284.jpg +0 -0
  15. package/assets/rednote-preview/cover/topbar-2285.jpg +0 -0
  16. package/assets/workbench/index.html +77 -0
  17. package/dist/sw/miniapp-simulator-service-worker.js +971 -0
  18. package/dist/sw/miniapp-simulator-service-worker.min.js +1 -0
  19. package/docs/consumer-guide.md +143 -0
  20. package/docs/electron-review.md +21 -0
  21. package/docs/external-cli-workbench.md +195 -0
  22. package/docs/file-system-design.md +334 -0
  23. package/docs/host-external-api.md +235 -0
  24. package/docs/iframe-service-worker.md +190 -0
  25. package/docs/local-dev.md +106 -0
  26. package/docs/npm-integration-verification.md +35 -0
  27. package/docs/remote-architecture.md +408 -0
  28. package/docs/remote-load-observability.md +268 -0
  29. package/docs/remote-usage.md +376 -0
  30. package/docs/request-design.md +247 -0
  31. package/docs/sdk-usage.md +260 -0
  32. package/docs/server-playground-https-debugging.md +150 -0
  33. package/docs/storage-api-design.md +275 -0
  34. package/docs/tracker.md +339 -0
  35. package/docs/worker-runtime.md +62 -0
  36. package/lib/client-BlQ9j4FW.mjs +775 -0
  37. package/lib/index-DI2oETZ_.mjs +574 -0
  38. package/lib/index.js +10831 -0
  39. package/lib/options-B34ipLmF.mjs +15 -0
  40. package/lib/preload/webview-preload.js +37 -0
  41. package/lib/remote-client.js +11 -0
  42. package/lib/types/business-line.d.ts +7 -0
  43. package/lib/types/capabilities/constants.d.ts +29 -0
  44. package/lib/types/capabilities/csp-snippet.d.ts +34 -0
  45. package/lib/types/capabilities/launch-options.d.ts +7 -0
  46. package/lib/types/capabilities/performance-policy.d.ts +5 -0
  47. package/lib/types/capabilities/security-head-snippet.d.ts +21 -0
  48. package/lib/types/capabilities/security.d.ts +25 -0
  49. package/lib/types/capabilities/style-snippet.d.ts +2 -0
  50. package/lib/types/core/controllers/game-playtest.d.ts +9 -0
  51. package/lib/types/core/controllers/gesture.d.ts +8 -0
  52. package/lib/types/core/controllers/host-api.d.ts +19 -0
  53. package/lib/types/core/controllers/index.d.ts +11 -0
  54. package/lib/types/core/controllers/inspector.d.ts +20 -0
  55. package/lib/types/core/controllers/note-preview.d.ts +9 -0
  56. package/lib/types/core/controllers/permission-sheet.d.ts +7 -0
  57. package/lib/types/core/controllers/widget-cover.d.ts +12 -0
  58. package/lib/types/core/lifecycle.d.ts +7 -0
  59. package/lib/types/core/options.d.ts +33 -0
  60. package/lib/types/core/simulator.d.ts +9 -0
  61. package/lib/types/errors.d.ts +11 -0
  62. package/lib/types/event-bus.d.ts +15 -0
  63. package/lib/types/gesture/host-bus.d.ts +113 -0
  64. package/lib/types/gesture/index.d.ts +27 -0
  65. package/lib/types/gesture/plugins/double-tap.d.ts +10 -0
  66. package/lib/types/gesture/plugins/index.d.ts +27 -0
  67. package/lib/types/gesture/plugins/long-press.d.ts +13 -0
  68. package/lib/types/gesture/plugins/multi-touch-hint.d.ts +11 -0
  69. package/lib/types/gesture/plugins/multi-touch-switch.d.ts +18 -0
  70. package/lib/types/gesture/plugins/selection-disabler.d.ts +11 -0
  71. package/lib/types/gesture/plugins/tap.d.ts +11 -0
  72. package/lib/types/gesture/plugins/touch-emitter.d.ts +11 -0
  73. package/lib/types/gesture/plugins/wheel-scroll.d.ts +11 -0
  74. package/lib/types/gesture/receiver-runtime.d.ts +10 -0
  75. package/lib/types/gesture/receiver-runtime.impl.d.ts +6 -0
  76. package/lib/types/gesture/touch-cursor.d.ts +78 -0
  77. package/lib/types/gesture/touch-dot.d.ts +12 -0
  78. package/lib/types/gesture/types.d.ts +206 -0
  79. package/lib/types/host/shadow-host.d.ts +40 -0
  80. package/lib/types/index.d.ts +56 -0
  81. package/lib/types/injection/guest-log-mark.d.ts +7 -0
  82. package/lib/types/injection/head-builder.d.ts +4 -0
  83. package/lib/types/injection/index.d.ts +19 -0
  84. package/lib/types/injection/modules/console-forward.d.ts +2 -0
  85. package/lib/types/injection/modules/gesture.d.ts +6 -0
  86. package/lib/types/injection/modules/inspector-guest-runtime.d.ts +5 -0
  87. package/lib/types/injection/modules/inspector-pause-runtime.d.ts +6 -0
  88. package/lib/types/injection/modules/inspector.d.ts +8 -0
  89. package/lib/types/injection/modules/jsapi-channel.d.ts +9 -0
  90. package/lib/types/injection/modules/jsapi.d.ts +22 -0
  91. package/lib/types/injection/modules/render-done.d.ts +2 -0
  92. package/lib/types/injection/modules/resource-guard.d.ts +7 -0
  93. package/lib/types/injection/modules/scroll-containment.d.ts +3 -0
  94. package/lib/types/injection/modules/security.d.ts +3 -0
  95. package/lib/types/injection/modules/widget-snapshot.d.ts +13 -0
  96. package/lib/types/injection/preload-builder.d.ts +41 -0
  97. package/lib/types/injection/registry.d.ts +20 -0
  98. package/lib/types/injection/types.d.ts +45 -0
  99. package/lib/types/inspector/host-inspector.d.ts +108 -0
  100. package/lib/types/inspector/index.d.ts +8 -0
  101. package/lib/types/inspector/selector.d.ts +18 -0
  102. package/lib/types/native-ui/devtools/CapabilitiesView.d.ts +18 -0
  103. package/lib/types/native-ui/devtools/DevtoolsPanel.d.ts +24 -0
  104. package/lib/types/native-ui/devtools/LogsView.d.ts +17 -0
  105. package/lib/types/native-ui/devtools/dom.d.ts +40 -0
  106. package/lib/types/native-ui/devtools/index.d.ts +19 -0
  107. package/lib/types/native-ui/devtools/log-entry.d.ts +8 -0
  108. package/lib/types/native-ui/devtools/shortcut.d.ts +12 -0
  109. package/lib/types/native-ui/devtools/tokens.d.ts +14 -0
  110. package/lib/types/native-ui/devtools/types.d.ts +51 -0
  111. package/lib/types/native-ui/index.d.ts +17 -0
  112. package/lib/types/native-ui/note-publish/defaults.d.ts +40 -0
  113. package/lib/types/native-ui/note-publish/index.d.ts +2 -0
  114. package/lib/types/native-ui/note-publish/miniapp-note-publish.d.ts +15 -0
  115. package/lib/types/native-ui/note-publish/note-publish-host.d.ts +15 -0
  116. package/lib/types/native-ui/note-publish/view-data.d.ts +21 -0
  117. package/lib/types/native-ui/permission-sheet/defaults.d.ts +12 -0
  118. package/lib/types/native-ui/permission-sheet/index.d.ts +4 -0
  119. package/lib/types/native-ui/permission-sheet/miniapp-permission-sheet.d.ts +19 -0
  120. package/lib/types/native-ui/permission-sheet/permission-sheet-host.d.ts +23 -0
  121. package/lib/types/native-ui/permission-sheet/types.d.ts +8 -0
  122. package/lib/types/native-ui/phone-vibration.d.ts +10 -0
  123. package/lib/types/native-ui/rednote-preview/chrome-tone.d.ts +44 -0
  124. package/lib/types/native-ui/rednote-preview/defaults.d.ts +30 -0
  125. package/lib/types/native-ui/rednote-preview/half-sheet-drag.d.ts +61 -0
  126. package/lib/types/native-ui/rednote-preview/index.d.ts +2 -0
  127. package/lib/types/native-ui/rednote-preview/register.d.ts +7 -0
  128. package/lib/types/native-ui/rednote-preview/styles.d.ts +4 -0
  129. package/lib/types/native-ui/rednote-preview/xhs-note-detail-shell.d.ts +70 -0
  130. package/lib/types/native-ui/rednote-preview/xhs-note-half-sheet.d.ts +100 -0
  131. package/lib/types/native-ui/rednote-preview/xhs-profile-shell.d.ts +31 -0
  132. package/lib/types/native-ui/toast/frame-toast-host.d.ts +18 -0
  133. package/lib/types/native-ui/toast/index.d.ts +19 -0
  134. package/lib/types/presets.d.ts +11 -0
  135. package/lib/types/remote/client.d.ts +89 -0
  136. package/lib/types/remote/jsapi-config.d.ts +9 -0
  137. package/lib/types/remote/load-timing.d.ts +46 -0
  138. package/lib/types/remote/protocol.d.ts +165 -0
  139. package/lib/types/remote/review-launch.d.ts +6 -0
  140. package/lib/types/remote/runtime-entry.d.ts +1 -0
  141. package/lib/types/remote/runtime.d.ts +14 -0
  142. package/lib/types/remote/simulator-prompt.d.ts +9 -0
  143. package/lib/types/remote/widget-snapshot-guest-runtime.d.ts +1 -0
  144. package/lib/types/remote-client.d.ts +5 -0
  145. package/lib/types/renderer/base.d.ts +8 -0
  146. package/lib/types/renderer/content-host/iframe-content-host.d.ts +84 -0
  147. package/lib/types/renderer/content-host/index.d.ts +3 -0
  148. package/lib/types/renderer/content-host/types.d.ts +89 -0
  149. package/lib/types/renderer/content-host/webview-content-host.d.ts +53 -0
  150. package/lib/types/renderer/iframe.d.ts +93 -0
  151. package/lib/types/renderer/index.d.ts +2 -0
  152. package/lib/types/renderer/rednote-shell.d.ts +73 -0
  153. package/lib/types/renderer/webview.d.ts +59 -0
  154. package/lib/types/runtime/context.d.ts +31 -0
  155. package/lib/types/runtime/jsapi-alert.d.ts +3 -0
  156. package/lib/types/runtime/jsapi-modules/context.d.ts +21 -0
  157. package/lib/types/runtime/jsapi-modules/filesystem.d.ts +19 -0
  158. package/lib/types/runtime/jsapi-modules/index.d.ts +9 -0
  159. package/lib/types/runtime/jsapi-modules/interaction.d.ts +4 -0
  160. package/lib/types/runtime/jsapi-modules/location.d.ts +3 -0
  161. package/lib/types/runtime/jsapi-modules/media.d.ts +13 -0
  162. package/lib/types/runtime/jsapi-modules/network.d.ts +3 -0
  163. package/lib/types/runtime/jsapi-modules/storage.d.ts +26 -0
  164. package/lib/types/runtime/jsapi-modules/system.d.ts +4 -0
  165. package/lib/types/runtime/jsapi-modules/types.d.ts +21 -0
  166. package/lib/types/runtime/jsapi-modules/window-info.d.ts +43 -0
  167. package/lib/types/runtime/request/host-request.d.ts +13 -0
  168. package/lib/types/runtime/request/request-manager-frame.d.ts +29 -0
  169. package/lib/types/runtime/request/request-runtime.d.ts +26 -0
  170. package/lib/types/runtime/request/request-types.d.ts +26 -0
  171. package/lib/types/runtime/request/sse-text-framer.d.ts +16 -0
  172. package/lib/types/seal-config.d.ts +134 -0
  173. package/lib/types/sw/index.d.ts +9 -0
  174. package/lib/types/sw/parse-raw.d.ts +34 -0
  175. package/lib/types/sw/protocol.d.ts +19 -0
  176. package/lib/types/sw/served-entry.d.ts +9 -0
  177. package/lib/types/sw/service-worker-content-host.d.ts +11 -0
  178. package/lib/types/sw/service-worker-host.d.ts +74 -0
  179. package/lib/types/sw/service-worker-renderer.d.ts +10 -0
  180. package/lib/types/sw/worker/fs-codec.d.ts +23 -0
  181. package/lib/types/sw/worker/fs-ops.d.ts +22 -0
  182. package/lib/types/sw/worker/fs-store.d.ts +29 -0
  183. package/lib/types/sw/worker/globals.d.ts +50 -0
  184. package/lib/types/sw/worker/main.d.ts +6 -0
  185. package/lib/types/sw/worker/mime.d.ts +2 -0
  186. package/lib/types/sw/worker/mount-store.d.ts +48 -0
  187. package/lib/types/sw/worker/paths.d.ts +4 -0
  188. package/lib/types/sw/worker/serve.d.ts +13 -0
  189. package/lib/types/tracker/constants.d.ts +14 -0
  190. package/lib/types/tracker/default-tracker.d.ts +19 -0
  191. package/lib/types/tracker/index.d.ts +70 -0
  192. package/lib/types/transport/bridge-protocol.d.ts +78 -0
  193. package/lib/types/transport/iframe-transport.d.ts +39 -0
  194. package/lib/types/transport/index.d.ts +14 -0
  195. package/lib/types/transport/jsapi-bridge-messages.d.ts +36 -0
  196. package/lib/types/transport/types.d.ts +48 -0
  197. package/lib/types/transport/webview-transport.d.ts +52 -0
  198. package/lib/types/types/events.d.ts +130 -0
  199. package/lib/types/types/index.d.ts +11 -0
  200. package/lib/types/types/inspector.d.ts +172 -0
  201. package/lib/types/types/jsapi.d.ts +18 -0
  202. package/lib/types/types/options.d.ts +851 -0
  203. package/lib/types/types/renderer.d.ts +145 -0
  204. package/lib/types/utils/ancestor-scroll.d.ts +11 -0
  205. package/lib/types/utils/error-svg.d.ts +12 -0
  206. package/lib/types/utils/frameless-shell.d.ts +114 -0
  207. package/lib/types/utils/miniapp-chrome-svg.d.ts +47 -0
  208. package/lib/types/utils/package-constants.d.ts +8 -0
  209. package/lib/types/utils/screenshot.d.ts +14 -0
  210. package/lib/types/utils/simulator-pc-guard.d.ts +10 -0
  211. package/lib/types/utils/stage-fit.d.ts +6 -0
  212. package/lib/types/utils/touch-emulate.d.ts +26 -0
  213. package/lib/types/utils/zip-entry.d.ts +13 -0
  214. package/lib/types/workbench/index.d.ts +63 -0
  215. package/lib/types/workbench/preview-transition.d.ts +8 -0
  216. package/lib/types/workbench/server/artifact.d.ts +8 -0
  217. package/lib/types/workbench/server/index.d.ts +19 -0
  218. package/lib/types/workbench/server/watch.d.ts +6 -0
  219. package/lib/types/workbench/view.d.ts +36 -0
  220. package/lib/types/worker/adapters/csp-policy.d.ts +7 -0
  221. package/lib/types/worker/adapters/host-lifecycle.d.ts +5 -0
  222. package/lib/types/worker/adapters/mount-recovery.d.ts +2 -0
  223. package/lib/types/worker/adapters/package-policy.d.ts +12 -0
  224. package/lib/types/worker/adapters/page-lifecycle.d.ts +1 -0
  225. package/lib/types/worker/adapters/protocol.d.ts +49 -0
  226. package/lib/types/worker/adapters/scripts.d.ts +2 -0
  227. package/lib/types/worker/adapters/service-worker.d.ts +2 -0
  228. package/lib/workbench-server.mjs +183 -0
  229. package/lib/workbench.js +1404 -0
  230. package/package.json +61 -4
  231. package/scripts/mock-cli-dev.mjs +52 -0
@@ -0,0 +1,775 @@
1
+ import { c as he, r as ye, v as we, o as ve, e as ge } from "./index-DI2oETZ_.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
+ };