@skillbuilder/miniapp-simulator 0.0.0-beta-20261023084421

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 (220) hide show
  1. package/README.md +214 -0
  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 +855 -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 +197 -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 +45 -0
  27. package/docs/remote-architecture.md +403 -0
  28. package/docs/remote-load-observability.md +268 -0
  29. package/docs/remote-usage.md +371 -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/lib/business-line-CMb3ehRn.mjs +15 -0
  36. package/lib/client-BZtD2VtP.mjs +772 -0
  37. package/lib/index-BW85h7kT.mjs +505 -0
  38. package/lib/index.js +10686 -0
  39. package/lib/preload/webview-preload.js +37 -0
  40. package/lib/remote-client.js +11 -0
  41. package/lib/types/business-line.d.ts +7 -0
  42. package/lib/types/capabilities/constants.d.ts +28 -0
  43. package/lib/types/capabilities/csp-snippet.d.ts +32 -0
  44. package/lib/types/capabilities/launch-options.d.ts +7 -0
  45. package/lib/types/capabilities/performance-policy.d.ts +5 -0
  46. package/lib/types/capabilities/security-head-snippet.d.ts +20 -0
  47. package/lib/types/capabilities/security.d.ts +25 -0
  48. package/lib/types/capabilities/style-snippet.d.ts +2 -0
  49. package/lib/types/core/controllers/game-playtest.d.ts +9 -0
  50. package/lib/types/core/controllers/gesture.d.ts +8 -0
  51. package/lib/types/core/controllers/host-api.d.ts +19 -0
  52. package/lib/types/core/controllers/index.d.ts +11 -0
  53. package/lib/types/core/controllers/inspector.d.ts +20 -0
  54. package/lib/types/core/controllers/note-preview.d.ts +9 -0
  55. package/lib/types/core/controllers/permission-sheet.d.ts +7 -0
  56. package/lib/types/core/controllers/widget-cover.d.ts +12 -0
  57. package/lib/types/core/lifecycle.d.ts +7 -0
  58. package/lib/types/core/options.d.ts +33 -0
  59. package/lib/types/core/simulator.d.ts +9 -0
  60. package/lib/types/errors.d.ts +11 -0
  61. package/lib/types/event-bus.d.ts +15 -0
  62. package/lib/types/gesture/host-bus.d.ts +113 -0
  63. package/lib/types/gesture/index.d.ts +27 -0
  64. package/lib/types/gesture/plugins/double-tap.d.ts +10 -0
  65. package/lib/types/gesture/plugins/index.d.ts +27 -0
  66. package/lib/types/gesture/plugins/long-press.d.ts +13 -0
  67. package/lib/types/gesture/plugins/multi-touch-hint.d.ts +11 -0
  68. package/lib/types/gesture/plugins/multi-touch-switch.d.ts +18 -0
  69. package/lib/types/gesture/plugins/selection-disabler.d.ts +11 -0
  70. package/lib/types/gesture/plugins/tap.d.ts +11 -0
  71. package/lib/types/gesture/plugins/touch-emitter.d.ts +11 -0
  72. package/lib/types/gesture/plugins/wheel-scroll.d.ts +11 -0
  73. package/lib/types/gesture/receiver-runtime.d.ts +10 -0
  74. package/lib/types/gesture/receiver-runtime.impl.d.ts +6 -0
  75. package/lib/types/gesture/touch-cursor.d.ts +78 -0
  76. package/lib/types/gesture/touch-dot.d.ts +12 -0
  77. package/lib/types/gesture/types.d.ts +206 -0
  78. package/lib/types/host/shadow-host.d.ts +40 -0
  79. package/lib/types/index.d.ts +49 -0
  80. package/lib/types/injection/guest-log-mark.d.ts +7 -0
  81. package/lib/types/injection/head-builder.d.ts +4 -0
  82. package/lib/types/injection/index.d.ts +19 -0
  83. package/lib/types/injection/modules/console-forward.d.ts +2 -0
  84. package/lib/types/injection/modules/gesture.d.ts +6 -0
  85. package/lib/types/injection/modules/inspector-guest-runtime.d.ts +5 -0
  86. package/lib/types/injection/modules/inspector-pause-runtime.d.ts +6 -0
  87. package/lib/types/injection/modules/inspector.d.ts +8 -0
  88. package/lib/types/injection/modules/jsapi-channel.d.ts +9 -0
  89. package/lib/types/injection/modules/jsapi.d.ts +22 -0
  90. package/lib/types/injection/modules/render-done.d.ts +2 -0
  91. package/lib/types/injection/modules/resource-guard.d.ts +7 -0
  92. package/lib/types/injection/modules/scroll-containment.d.ts +3 -0
  93. package/lib/types/injection/modules/security.d.ts +3 -0
  94. package/lib/types/injection/modules/widget-snapshot.d.ts +13 -0
  95. package/lib/types/injection/preload-builder.d.ts +41 -0
  96. package/lib/types/injection/registry.d.ts +20 -0
  97. package/lib/types/injection/types.d.ts +43 -0
  98. package/lib/types/inspector/host-inspector.d.ts +108 -0
  99. package/lib/types/inspector/index.d.ts +8 -0
  100. package/lib/types/inspector/selector.d.ts +18 -0
  101. package/lib/types/native-ui/devtools/CapabilitiesView.d.ts +18 -0
  102. package/lib/types/native-ui/devtools/DevtoolsPanel.d.ts +24 -0
  103. package/lib/types/native-ui/devtools/LogsView.d.ts +17 -0
  104. package/lib/types/native-ui/devtools/dom.d.ts +40 -0
  105. package/lib/types/native-ui/devtools/index.d.ts +19 -0
  106. package/lib/types/native-ui/devtools/log-entry.d.ts +8 -0
  107. package/lib/types/native-ui/devtools/shortcut.d.ts +12 -0
  108. package/lib/types/native-ui/devtools/tokens.d.ts +14 -0
  109. package/lib/types/native-ui/devtools/types.d.ts +51 -0
  110. package/lib/types/native-ui/index.d.ts +17 -0
  111. package/lib/types/native-ui/note-publish/defaults.d.ts +40 -0
  112. package/lib/types/native-ui/note-publish/index.d.ts +2 -0
  113. package/lib/types/native-ui/note-publish/miniapp-note-publish.d.ts +15 -0
  114. package/lib/types/native-ui/note-publish/note-publish-host.d.ts +15 -0
  115. package/lib/types/native-ui/note-publish/view-data.d.ts +21 -0
  116. package/lib/types/native-ui/permission-sheet/defaults.d.ts +12 -0
  117. package/lib/types/native-ui/permission-sheet/index.d.ts +4 -0
  118. package/lib/types/native-ui/permission-sheet/miniapp-permission-sheet.d.ts +19 -0
  119. package/lib/types/native-ui/permission-sheet/permission-sheet-host.d.ts +23 -0
  120. package/lib/types/native-ui/permission-sheet/types.d.ts +8 -0
  121. package/lib/types/native-ui/rednote-preview/chrome-tone.d.ts +44 -0
  122. package/lib/types/native-ui/rednote-preview/defaults.d.ts +30 -0
  123. package/lib/types/native-ui/rednote-preview/half-sheet-drag.d.ts +61 -0
  124. package/lib/types/native-ui/rednote-preview/index.d.ts +2 -0
  125. package/lib/types/native-ui/rednote-preview/register.d.ts +7 -0
  126. package/lib/types/native-ui/rednote-preview/styles.d.ts +4 -0
  127. package/lib/types/native-ui/rednote-preview/xhs-note-detail-shell.d.ts +70 -0
  128. package/lib/types/native-ui/rednote-preview/xhs-note-half-sheet.d.ts +100 -0
  129. package/lib/types/native-ui/rednote-preview/xhs-profile-shell.d.ts +31 -0
  130. package/lib/types/native-ui/toast/frame-toast-host.d.ts +18 -0
  131. package/lib/types/native-ui/toast/index.d.ts +19 -0
  132. package/lib/types/presets.d.ts +11 -0
  133. package/lib/types/remote/client.d.ts +89 -0
  134. package/lib/types/remote/jsapi-config.d.ts +9 -0
  135. package/lib/types/remote/load-timing.d.ts +46 -0
  136. package/lib/types/remote/protocol.d.ts +160 -0
  137. package/lib/types/remote/review-launch.d.ts +6 -0
  138. package/lib/types/remote/runtime-entry.d.ts +1 -0
  139. package/lib/types/remote/runtime.d.ts +14 -0
  140. package/lib/types/remote/simulator-prompt.d.ts +9 -0
  141. package/lib/types/remote/widget-snapshot-guest-runtime.d.ts +1 -0
  142. package/lib/types/remote-client.d.ts +5 -0
  143. package/lib/types/renderer/base.d.ts +8 -0
  144. package/lib/types/renderer/content-host/iframe-content-host.d.ts +83 -0
  145. package/lib/types/renderer/content-host/index.d.ts +3 -0
  146. package/lib/types/renderer/content-host/types.d.ts +89 -0
  147. package/lib/types/renderer/content-host/webview-content-host.d.ts +53 -0
  148. package/lib/types/renderer/iframe.d.ts +93 -0
  149. package/lib/types/renderer/index.d.ts +2 -0
  150. package/lib/types/renderer/rednote-shell.d.ts +73 -0
  151. package/lib/types/renderer/webview.d.ts +59 -0
  152. package/lib/types/runtime/context.d.ts +31 -0
  153. package/lib/types/runtime/jsapi-modules/context.d.ts +19 -0
  154. package/lib/types/runtime/jsapi-modules/filesystem.d.ts +19 -0
  155. package/lib/types/runtime/jsapi-modules/index.d.ts +9 -0
  156. package/lib/types/runtime/jsapi-modules/interaction.d.ts +4 -0
  157. package/lib/types/runtime/jsapi-modules/location.d.ts +3 -0
  158. package/lib/types/runtime/jsapi-modules/media.d.ts +13 -0
  159. package/lib/types/runtime/jsapi-modules/network.d.ts +3 -0
  160. package/lib/types/runtime/jsapi-modules/storage.d.ts +26 -0
  161. package/lib/types/runtime/jsapi-modules/system.d.ts +4 -0
  162. package/lib/types/runtime/jsapi-modules/types.d.ts +21 -0
  163. package/lib/types/runtime/jsapi-modules/window-info.d.ts +43 -0
  164. package/lib/types/runtime/request/host-request.d.ts +13 -0
  165. package/lib/types/runtime/request/request-manager-frame.d.ts +29 -0
  166. package/lib/types/runtime/request/request-runtime.d.ts +26 -0
  167. package/lib/types/runtime/request/request-types.d.ts +26 -0
  168. package/lib/types/runtime/request/sse-text-framer.d.ts +16 -0
  169. package/lib/types/seal-config.d.ts +134 -0
  170. package/lib/types/sw/index.d.ts +9 -0
  171. package/lib/types/sw/parse-raw.d.ts +34 -0
  172. package/lib/types/sw/protocol.d.ts +17 -0
  173. package/lib/types/sw/served-entry.d.ts +9 -0
  174. package/lib/types/sw/service-worker-content-host.d.ts +11 -0
  175. package/lib/types/sw/service-worker-host.d.ts +73 -0
  176. package/lib/types/sw/service-worker-renderer.d.ts +10 -0
  177. package/lib/types/sw/worker/fs-codec.d.ts +23 -0
  178. package/lib/types/sw/worker/fs-ops.d.ts +22 -0
  179. package/lib/types/sw/worker/fs-store.d.ts +29 -0
  180. package/lib/types/sw/worker/globals.d.ts +49 -0
  181. package/lib/types/sw/worker/main.d.ts +6 -0
  182. package/lib/types/sw/worker/mime.d.ts +2 -0
  183. package/lib/types/sw/worker/mount-store.d.ts +43 -0
  184. package/lib/types/sw/worker/paths.d.ts +4 -0
  185. package/lib/types/sw/worker/serve.d.ts +13 -0
  186. package/lib/types/tracker/constants.d.ts +14 -0
  187. package/lib/types/tracker/default-tracker.d.ts +19 -0
  188. package/lib/types/tracker/index.d.ts +70 -0
  189. package/lib/types/transport/bridge-protocol.d.ts +78 -0
  190. package/lib/types/transport/iframe-transport.d.ts +39 -0
  191. package/lib/types/transport/index.d.ts +14 -0
  192. package/lib/types/transport/jsapi-bridge-messages.d.ts +36 -0
  193. package/lib/types/transport/types.d.ts +48 -0
  194. package/lib/types/transport/webview-transport.d.ts +52 -0
  195. package/lib/types/types/events.d.ts +130 -0
  196. package/lib/types/types/index.d.ts +11 -0
  197. package/lib/types/types/inspector.d.ts +172 -0
  198. package/lib/types/types/jsapi.d.ts +18 -0
  199. package/lib/types/types/options.d.ts +844 -0
  200. package/lib/types/types/renderer.d.ts +145 -0
  201. package/lib/types/utils/ancestor-scroll.d.ts +11 -0
  202. package/lib/types/utils/error-svg.d.ts +12 -0
  203. package/lib/types/utils/frameless-shell.d.ts +114 -0
  204. package/lib/types/utils/miniapp-chrome-svg.d.ts +47 -0
  205. package/lib/types/utils/package-constants.d.ts +8 -0
  206. package/lib/types/utils/screenshot.d.ts +14 -0
  207. package/lib/types/utils/simulator-pc-guard.d.ts +10 -0
  208. package/lib/types/utils/stage-fit.d.ts +6 -0
  209. package/lib/types/utils/touch-emulate.d.ts +26 -0
  210. package/lib/types/utils/zip-entry.d.ts +13 -0
  211. package/lib/types/workbench/index.d.ts +63 -0
  212. package/lib/types/workbench/preview-transition.d.ts +8 -0
  213. package/lib/types/workbench/server/artifact.d.ts +8 -0
  214. package/lib/types/workbench/server/index.d.ts +19 -0
  215. package/lib/types/workbench/server/watch.d.ts +6 -0
  216. package/lib/types/workbench/view.d.ts +36 -0
  217. package/lib/workbench-server.mjs +183 -0
  218. package/lib/workbench.js +1404 -0
  219. package/package.json +63 -0
  220. package/scripts/mock-cli-dev.mjs +52 -0
@@ -0,0 +1,772 @@
1
+ import { c as me, r as he, v as ye, e as we } from "./index-BW85h7kT.mjs";
2
+ const Y = {
3
+ report() {
4
+ },
5
+ flush() {
6
+ }
7
+ };
8
+ function ve(t) {
9
+ if (!t.enabled) return Y;
10
+ let s;
11
+ try {
12
+ const n = { business_line: t.businessLine };
13
+ s = me({
14
+ endpoint: he(n),
15
+ region: "cn",
16
+ resolveUserId: t.resolveUserId ?? (() => Promise.resolve(""))
17
+ });
18
+ } catch {
19
+ return Y;
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: ye,
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 ee(t, s, n, i = {}) {
66
+ try {
67
+ const a = ge(n);
68
+ if (!a) {
69
+ Object.keys(i).length > 0 && t.report(s, i);
70
+ return;
71
+ }
72
+ const { duration: d, ...y } = be(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 ge(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 be(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 Ie = 7, Ee = {
102
+ version: Ie
103
+ }, _ = Ee.version, Se = "miniapp-simulator:connect", je = "inspectorPauseRuntime", _e = 3e4, K = 2, qe = 100;
104
+ function Be(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 = Me(t.gateway), n = $e(t.mount), i = Le([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 ?? _e, y = /* @__PURE__ */ new Map(), $ = le(t.options), p = new Map(Object.entries(t.hostApi ?? {})), m = /* @__PURE__ */ new Map(), q = /* @__PURE__ */ new Map();
110
+ let k = 0, S = Q(), w, P, z, M, R = !1, A = !1, D = "single", g = null, b = !1;
111
+ const U = I();
112
+ let F = U, V = U, j, B;
113
+ const f = ve({
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, O;
121
+ const oe = new Promise((e, r) => {
122
+ x = e, O = r;
123
+ });
124
+ let N;
125
+ function T() {
126
+ N !== void 0 && (window.clearTimeout(N), N = void 0);
127
+ }
128
+ function ne() {
129
+ T(), N = 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(U)
134
+ }), f.flush(), M(e), O(e);
135
+ }, d);
136
+ }
137
+ fe();
138
+ function se(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 ie(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 ae(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 we(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 ce(e) {
249
+ m.get(e.requestId)?.abort();
250
+ }
251
+ function ue(e) {
252
+ e.event === "inspectorChange" && (A = !!e.payload?.enabled), G(e.event, e.payload);
253
+ }
254
+ function W(e, r) {
255
+ let o = y.get(e);
256
+ o || (o = /* @__PURE__ */ new Set(), y.set(e, o)), o.add(r);
257
+ }
258
+ function le(e) {
259
+ if (!e) return {};
260
+ const { onRouterChange: r, onScreenShot: o, ...l } = e;
261
+ return r && W(
262
+ "routerChange",
263
+ (u) => r(u)
264
+ ), o && W("screenShot", (u) => o(u)), l;
265
+ }
266
+ a.onload = () => {
267
+ g && ee(f, "runtime_document", g.href, {
268
+ result: "success",
269
+ duration: h(F)
270
+ }), de();
271
+ };
272
+ async function de() {
273
+ if (R || !g) return;
274
+ const e = w, r = S, o = await Ae(p);
275
+ if (B = o, R || !g || e !== w) return;
276
+ const l = {
277
+ type: Se,
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: Z(p),
286
+ hostApiStubs: X(p),
287
+ options: $
288
+ };
289
+ V = 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 ? G("error", {
300
+ code: "LOAD_FAILED",
301
+ message: e.message,
302
+ url: g?.href,
303
+ cause: e
304
+ }) : (b = !0, T(), O(e));
305
+ }, Te(i, f).then(
306
+ (e) => {
307
+ R || (g = e, F = I(), ne(), 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(U),
314
+ message: r.message.slice(0, 512)
315
+ }), f.flush(), M(r), O(r);
316
+ }
317
+ );
318
+ async function c(e, ...r) {
319
+ return H(`${S}-${++k}`, e, ...r);
320
+ }
321
+ async function H(e, r, ...o) {
322
+ if (R) throw new Error("remote simulator has been destroyed");
323
+ await P;
324
+ const l = Ne(o);
325
+ return new Promise((u, v) => {
326
+ const J = I(), pe = window.setTimeout(() => {
327
+ q.delete(e), f.report("remote_request", {
328
+ type: r,
329
+ request_id: e,
330
+ result: "timeout",
331
+ duration: h(J)
332
+ }), v(new Error(`remote simulator ${r} timed out after ${d}ms`));
333
+ }, d);
334
+ q.set(e, { resolve: u, reject: v, timer: pe, method: r, startedAt: J }), w.port1.postMessage({ type: "request", requestId: e, method: r, args: o }, l);
335
+ });
336
+ }
337
+ return {
338
+ iframe: a,
339
+ ready: oe,
340
+ load: () => c("load"),
341
+ async loadZip(e, r) {
342
+ const o = `${S}-${++k}`, l = I();
343
+ try {
344
+ const u = await re(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
+ }), H(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: L(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 Ce(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: Pe(u)
376
+ }), H(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: L(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
+ D = e, c("inspector.setSelectionMode", e);
441
+ },
442
+ getSelectionMode: () => D,
443
+ getSceneTree: () => c("inspector.getSceneTree"),
444
+ selectByRef: (e) => c("inspector.selectByRef", e)
445
+ },
446
+ hostApi: {
447
+ set(e, r) {
448
+ p.set(e, r), C();
449
+ },
450
+ registerAll(e) {
451
+ for (const [r, o] of Object.entries(e)) p.set(r, o);
452
+ C();
453
+ },
454
+ remove(e) {
455
+ p.delete(e), C();
456
+ },
457
+ clear() {
458
+ p.clear(), C();
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, T(), Fe(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 C() {
482
+ return c("hostApi.sync", Z(p), X(p));
483
+ }
484
+ function fe() {
485
+ for (const r of m.values()) r.abort();
486
+ m.clear(), w && (w.port1.close(), S = Q()), k = 0, w = new MessageChannel(), P = new Promise((r, o) => {
487
+ z = r, M = o;
488
+ }), P.catch(() => {
489
+ });
490
+ const e = w;
491
+ e.port1.onmessage = (r) => {
492
+ if (e !== w) return;
493
+ const o = r.data;
494
+ if (o?.type === "ready") {
495
+ if (o.protocolVersion !== _) {
496
+ const l = new Error(
497
+ `unsupported remote simulator protocol: ${o.protocolVersion} (client=${_})`
498
+ );
499
+ f.report("runtime_handshake", {
500
+ result: "protocol_mismatch",
501
+ duration: h(V),
502
+ runtime_version: o.runtimeVersion
503
+ }), f.flush(), M(l), b || (b = !0, T(), O(l));
504
+ return;
505
+ }
506
+ j = o.runtimeVersion, f.report("runtime_handshake", {
507
+ result: "success",
508
+ duration: h(V),
509
+ runtime_version: j
510
+ }), f.report("client_ready", {
511
+ result: "success",
512
+ duration: h(U),
513
+ runtime_version: j
514
+ }), z(o), b || (b = !0, T(), x(o));
515
+ return;
516
+ }
517
+ if (o?.type === "response") {
518
+ se(o);
519
+ return;
520
+ }
521
+ if (o?.type === "host-api-request") {
522
+ ie(o, e.port1);
523
+ return;
524
+ }
525
+ if (o?.type === "host-request") {
526
+ ae(o, e.port1);
527
+ return;
528
+ }
529
+ if (o?.type === "host-request-abort") {
530
+ ce(o);
531
+ return;
532
+ }
533
+ o?.type === "event" && ue(o);
534
+ }, e.port1.start();
535
+ }
536
+ function G(e, r) {
537
+ for (const o of [e, "*"])
538
+ for (const l of y.get(o) ?? []) l(r);
539
+ }
540
+ }
541
+ function Me(t) {
542
+ if (!t) return;
543
+ const s = {};
544
+ for (const [n, i] of Object.entries(t)) {
545
+ if (typeof i != "string" || !i.trim())
546
+ throw new Error(`remote simulator gateway.${n} must be a non-empty HTTPS URL`);
547
+ const a = i.trim().replace(/\/+$/, "");
548
+ let d;
549
+ try {
550
+ d = new URL(a);
551
+ } catch {
552
+ throw new Error(`remote simulator gateway.${n} must be an absolute HTTPS URL`);
553
+ }
554
+ if (!Re(d))
555
+ throw new Error(
556
+ `remote simulator gateway.${n} must use HTTPS (HTTP is allowed only for loopback development)`
557
+ );
558
+ s[n] = a;
559
+ }
560
+ if (!s.edith)
561
+ throw new Error("remote simulator gateway.edith is required");
562
+ if (!s.www)
563
+ throw new Error("remote simulator gateway.www is required");
564
+ return s;
565
+ }
566
+ function Re(t) {
567
+ return t.protocol === "https:" ? !0 : t.protocol === "http:" && (t.hostname === "localhost" || t.hostname === "127.0.0.1" || t.hostname === "[::1]");
568
+ }
569
+ function Z(t) {
570
+ return [...t].filter(([, s]) => typeof s == "function").map(([s]) => s);
571
+ }
572
+ async function Ae(t) {
573
+ const s = t.get("getUserInfo");
574
+ if (typeof s == "function")
575
+ try {
576
+ const n = await s({
577
+ event: "getUserInfo",
578
+ message: {},
579
+ callbackId: ""
580
+ });
581
+ return n && typeof n == "object" ? n : void 0;
582
+ } catch {
583
+ return;
584
+ }
585
+ }
586
+ function X(t) {
587
+ return Object.fromEntries(
588
+ [...t].filter((s) => {
589
+ const n = s[1];
590
+ return typeof n != "function" && typeof n.toast == "string";
591
+ })
592
+ );
593
+ }
594
+ class E extends Error {
595
+ constructor(s, n, i, a) {
596
+ super(s), this.kind = n, this.retryable = i, this.status = a, this.name = "ManifestRequestError";
597
+ }
598
+ }
599
+ async function Te(t, s) {
600
+ const n = [], i = new Set(t.map((a) => a.href));
601
+ for (let a = 1; a <= K; a += 1) {
602
+ for (const [d, y] of t.entries()) {
603
+ if (a > 1 && !i.has(y.href)) continue;
604
+ const $ = I();
605
+ try {
606
+ const p = await ke(y), m = te(y);
607
+ return ee(s, "runtime_manifest", m.href, {
608
+ result: "success",
609
+ duration: h($),
610
+ type: d === 0 ? "primary" : "fallback",
611
+ count: a
612
+ }), p;
613
+ } catch (p) {
614
+ const m = Ue(p);
615
+ s.report("runtime_manifest", {
616
+ result: "fail",
617
+ duration: h($),
618
+ type: d === 0 ? "primary" : "fallback",
619
+ count: a,
620
+ ...m.status === void 0 ? { error_name: m.kind } : { code: m.status },
621
+ message: m.message.slice(0, 512)
622
+ }), n.push(`${y.href} attempt ${a}: ${m.message}`), m.retryable || i.delete(y.href);
623
+ }
624
+ }
625
+ if (a >= K || i.size === 0) break;
626
+ await Oe();
627
+ }
628
+ throw new Error(`remote simulator services unavailable: ${n.join("; ")}`);
629
+ }
630
+ async function ke(t) {
631
+ const s = te(t);
632
+ s.searchParams.set("protocolVersion", String(_));
633
+ let n;
634
+ try {
635
+ n = await fetch(s, {
636
+ method: "GET",
637
+ credentials: "omit",
638
+ cache: "no-store"
639
+ });
640
+ } catch (d) {
641
+ throw new E(
642
+ `remote simulator manifest network error: ${L(d)}`,
643
+ "MANIFEST_NETWORK_ERROR",
644
+ !0
645
+ );
646
+ }
647
+ if (!n.ok)
648
+ throw new E(
649
+ `remote simulator manifest request failed: HTTP ${n.status}`,
650
+ "MANIFEST_HTTP_ERROR",
651
+ !0,
652
+ n.status
653
+ );
654
+ let i;
655
+ try {
656
+ i = await n.json();
657
+ } catch (d) {
658
+ throw new E(
659
+ `remote simulator manifest JSON is invalid: ${L(d)}`,
660
+ "MANIFEST_INVALID_JSON",
661
+ !0
662
+ );
663
+ }
664
+ if (typeof i.buildId != "string" || !i.buildId || typeof i.documentUrl != "string" || !i.documentUrl)
665
+ throw new E(
666
+ "remote simulator manifest response is invalid",
667
+ "MANIFEST_INVALID_RESPONSE",
668
+ !1
669
+ );
670
+ if (i.protocolVersion !== _)
671
+ throw new E(
672
+ `unsupported remote simulator protocol: ${String(i.protocolVersion)} (client=${_})`,
673
+ "MANIFEST_PROTOCOL_MISMATCH",
674
+ !1
675
+ );
676
+ const a = new URL(i.documentUrl, s);
677
+ if (a.origin !== t.origin)
678
+ throw new E(
679
+ `remote simulator document origin mismatch: ${a.origin} (service=${t.origin})`,
680
+ "MANIFEST_ORIGIN_MISMATCH",
681
+ !1
682
+ );
683
+ return a;
684
+ }
685
+ function Ue(t) {
686
+ return t instanceof E ? t : new E(L(t), "MANIFEST_UNKNOWN_ERROR", !1);
687
+ }
688
+ function Oe() {
689
+ return new Promise((t) => window.setTimeout(t, qe));
690
+ }
691
+ function te(t) {
692
+ const s = t.href.endsWith("/") ? t : new URL(`${t.href}/`), n = new URL("runtime-manifest", s);
693
+ return n.searchParams.set("protocolVersion", String(_)), n;
694
+ }
695
+ function Le(t) {
696
+ const s = /* @__PURE__ */ new Set(), n = [];
697
+ for (const i of t) {
698
+ const a = new URL(i, window.location.href), d = a.href.endsWith("/") ? a : new URL(`${a.href}/`);
699
+ s.has(d.href) || (s.add(d.href), n.push(d));
700
+ }
701
+ return n;
702
+ }
703
+ function L(t) {
704
+ return t instanceof Error ? t.message : String(t);
705
+ }
706
+ function $e(t) {
707
+ const s = typeof t == "string" ? document.querySelector(t) : t;
708
+ if (!s) throw new Error("remote simulator mount element not found");
709
+ return s;
710
+ }
711
+ function re(t) {
712
+ if (t instanceof Blob) return t;
713
+ const s = t instanceof ArrayBuffer ? t : Uint8Array.from(t).buffer;
714
+ return new Blob([s]);
715
+ }
716
+ function Ne(t) {
717
+ const s = /* @__PURE__ */ new Set(), n = (i) => {
718
+ if (i instanceof ArrayBuffer) {
719
+ s.add(i);
720
+ return;
721
+ }
722
+ if (ArrayBuffer.isView(i)) {
723
+ s.add(i.buffer);
724
+ return;
725
+ }
726
+ if (!(!i || typeof i != "object")) {
727
+ if (Array.isArray(i)) {
728
+ i.forEach(n);
729
+ return;
730
+ }
731
+ Object.values(i).forEach(n);
732
+ }
733
+ };
734
+ return n(t), [...s];
735
+ }
736
+ async function Ce(t) {
737
+ return Object.fromEntries(
738
+ await Promise.all(
739
+ Object.entries(t).map(async ([s, n]) => [
740
+ s,
741
+ typeof n == "string" ? n : await re(n).arrayBuffer()
742
+ ])
743
+ )
744
+ );
745
+ }
746
+ function Pe(t) {
747
+ try {
748
+ const s = new TextEncoder();
749
+ 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);
750
+ } catch {
751
+ return;
752
+ }
753
+ }
754
+ function Fe(t, s, n, i) {
755
+ try {
756
+ t.postMessage({
757
+ type: "request",
758
+ requestId: `${s}-${n}`,
759
+ method: "destroy",
760
+ args: [i]
761
+ });
762
+ } catch {
763
+ }
764
+ }
765
+ function Q() {
766
+ return typeof crypto.randomUUID == "function" ? crypto.randomUUID() : `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
767
+ }
768
+ export {
769
+ je as R,
770
+ _ as a,
771
+ Be as c
772
+ };