@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.
- package/README.md +214 -0
- package/assets/phones/Nexus-5X.png +0 -0
- package/assets/phones/iPhone-14ProMax.png +0 -0
- package/assets/rednote-preview/cover/homebar-1439.jpg +0 -0
- package/assets/rednote-preview/cover/homebar-1679.jpg +0 -0
- package/assets/rednote-preview/cover/homebar-1919.jpg +0 -0
- package/assets/rednote-preview/cover/homebar-2284.jpg +0 -0
- package/assets/rednote-preview/cover/homebar-2285.jpg +0 -0
- package/assets/rednote-preview/cover/like.png +0 -0
- package/assets/rednote-preview/cover/play.png +0 -0
- package/assets/rednote-preview/cover/topbar-1439.jpg +0 -0
- package/assets/rednote-preview/cover/topbar-1679.jpg +0 -0
- package/assets/rednote-preview/cover/topbar-1919.jpg +0 -0
- package/assets/rednote-preview/cover/topbar-2284.jpg +0 -0
- package/assets/rednote-preview/cover/topbar-2285.jpg +0 -0
- package/assets/workbench/index.html +77 -0
- package/dist/sw/miniapp-simulator-service-worker.js +855 -0
- package/dist/sw/miniapp-simulator-service-worker.min.js +1 -0
- package/docs/consumer-guide.md +143 -0
- package/docs/electron-review.md +21 -0
- package/docs/external-cli-workbench.md +197 -0
- package/docs/file-system-design.md +334 -0
- package/docs/host-external-api.md +235 -0
- package/docs/iframe-service-worker.md +190 -0
- package/docs/local-dev.md +106 -0
- package/docs/npm-integration-verification.md +45 -0
- package/docs/remote-architecture.md +403 -0
- package/docs/remote-load-observability.md +268 -0
- package/docs/remote-usage.md +371 -0
- package/docs/request-design.md +247 -0
- package/docs/sdk-usage.md +260 -0
- package/docs/server-playground-https-debugging.md +150 -0
- package/docs/storage-api-design.md +275 -0
- package/docs/tracker.md +339 -0
- package/lib/business-line-CMb3ehRn.mjs +15 -0
- package/lib/client-BZtD2VtP.mjs +772 -0
- package/lib/index-BW85h7kT.mjs +505 -0
- package/lib/index.js +10686 -0
- package/lib/preload/webview-preload.js +37 -0
- package/lib/remote-client.js +11 -0
- package/lib/types/business-line.d.ts +7 -0
- package/lib/types/capabilities/constants.d.ts +28 -0
- package/lib/types/capabilities/csp-snippet.d.ts +32 -0
- package/lib/types/capabilities/launch-options.d.ts +7 -0
- package/lib/types/capabilities/performance-policy.d.ts +5 -0
- package/lib/types/capabilities/security-head-snippet.d.ts +20 -0
- package/lib/types/capabilities/security.d.ts +25 -0
- package/lib/types/capabilities/style-snippet.d.ts +2 -0
- package/lib/types/core/controllers/game-playtest.d.ts +9 -0
- package/lib/types/core/controllers/gesture.d.ts +8 -0
- package/lib/types/core/controllers/host-api.d.ts +19 -0
- package/lib/types/core/controllers/index.d.ts +11 -0
- package/lib/types/core/controllers/inspector.d.ts +20 -0
- package/lib/types/core/controllers/note-preview.d.ts +9 -0
- package/lib/types/core/controllers/permission-sheet.d.ts +7 -0
- package/lib/types/core/controllers/widget-cover.d.ts +12 -0
- package/lib/types/core/lifecycle.d.ts +7 -0
- package/lib/types/core/options.d.ts +33 -0
- package/lib/types/core/simulator.d.ts +9 -0
- package/lib/types/errors.d.ts +11 -0
- package/lib/types/event-bus.d.ts +15 -0
- package/lib/types/gesture/host-bus.d.ts +113 -0
- package/lib/types/gesture/index.d.ts +27 -0
- package/lib/types/gesture/plugins/double-tap.d.ts +10 -0
- package/lib/types/gesture/plugins/index.d.ts +27 -0
- package/lib/types/gesture/plugins/long-press.d.ts +13 -0
- package/lib/types/gesture/plugins/multi-touch-hint.d.ts +11 -0
- package/lib/types/gesture/plugins/multi-touch-switch.d.ts +18 -0
- package/lib/types/gesture/plugins/selection-disabler.d.ts +11 -0
- package/lib/types/gesture/plugins/tap.d.ts +11 -0
- package/lib/types/gesture/plugins/touch-emitter.d.ts +11 -0
- package/lib/types/gesture/plugins/wheel-scroll.d.ts +11 -0
- package/lib/types/gesture/receiver-runtime.d.ts +10 -0
- package/lib/types/gesture/receiver-runtime.impl.d.ts +6 -0
- package/lib/types/gesture/touch-cursor.d.ts +78 -0
- package/lib/types/gesture/touch-dot.d.ts +12 -0
- package/lib/types/gesture/types.d.ts +206 -0
- package/lib/types/host/shadow-host.d.ts +40 -0
- package/lib/types/index.d.ts +49 -0
- package/lib/types/injection/guest-log-mark.d.ts +7 -0
- package/lib/types/injection/head-builder.d.ts +4 -0
- package/lib/types/injection/index.d.ts +19 -0
- package/lib/types/injection/modules/console-forward.d.ts +2 -0
- package/lib/types/injection/modules/gesture.d.ts +6 -0
- package/lib/types/injection/modules/inspector-guest-runtime.d.ts +5 -0
- package/lib/types/injection/modules/inspector-pause-runtime.d.ts +6 -0
- package/lib/types/injection/modules/inspector.d.ts +8 -0
- package/lib/types/injection/modules/jsapi-channel.d.ts +9 -0
- package/lib/types/injection/modules/jsapi.d.ts +22 -0
- package/lib/types/injection/modules/render-done.d.ts +2 -0
- package/lib/types/injection/modules/resource-guard.d.ts +7 -0
- package/lib/types/injection/modules/scroll-containment.d.ts +3 -0
- package/lib/types/injection/modules/security.d.ts +3 -0
- package/lib/types/injection/modules/widget-snapshot.d.ts +13 -0
- package/lib/types/injection/preload-builder.d.ts +41 -0
- package/lib/types/injection/registry.d.ts +20 -0
- package/lib/types/injection/types.d.ts +43 -0
- package/lib/types/inspector/host-inspector.d.ts +108 -0
- package/lib/types/inspector/index.d.ts +8 -0
- package/lib/types/inspector/selector.d.ts +18 -0
- package/lib/types/native-ui/devtools/CapabilitiesView.d.ts +18 -0
- package/lib/types/native-ui/devtools/DevtoolsPanel.d.ts +24 -0
- package/lib/types/native-ui/devtools/LogsView.d.ts +17 -0
- package/lib/types/native-ui/devtools/dom.d.ts +40 -0
- package/lib/types/native-ui/devtools/index.d.ts +19 -0
- package/lib/types/native-ui/devtools/log-entry.d.ts +8 -0
- package/lib/types/native-ui/devtools/shortcut.d.ts +12 -0
- package/lib/types/native-ui/devtools/tokens.d.ts +14 -0
- package/lib/types/native-ui/devtools/types.d.ts +51 -0
- package/lib/types/native-ui/index.d.ts +17 -0
- package/lib/types/native-ui/note-publish/defaults.d.ts +40 -0
- package/lib/types/native-ui/note-publish/index.d.ts +2 -0
- package/lib/types/native-ui/note-publish/miniapp-note-publish.d.ts +15 -0
- package/lib/types/native-ui/note-publish/note-publish-host.d.ts +15 -0
- package/lib/types/native-ui/note-publish/view-data.d.ts +21 -0
- package/lib/types/native-ui/permission-sheet/defaults.d.ts +12 -0
- package/lib/types/native-ui/permission-sheet/index.d.ts +4 -0
- package/lib/types/native-ui/permission-sheet/miniapp-permission-sheet.d.ts +19 -0
- package/lib/types/native-ui/permission-sheet/permission-sheet-host.d.ts +23 -0
- package/lib/types/native-ui/permission-sheet/types.d.ts +8 -0
- package/lib/types/native-ui/rednote-preview/chrome-tone.d.ts +44 -0
- package/lib/types/native-ui/rednote-preview/defaults.d.ts +30 -0
- package/lib/types/native-ui/rednote-preview/half-sheet-drag.d.ts +61 -0
- package/lib/types/native-ui/rednote-preview/index.d.ts +2 -0
- package/lib/types/native-ui/rednote-preview/register.d.ts +7 -0
- package/lib/types/native-ui/rednote-preview/styles.d.ts +4 -0
- package/lib/types/native-ui/rednote-preview/xhs-note-detail-shell.d.ts +70 -0
- package/lib/types/native-ui/rednote-preview/xhs-note-half-sheet.d.ts +100 -0
- package/lib/types/native-ui/rednote-preview/xhs-profile-shell.d.ts +31 -0
- package/lib/types/native-ui/toast/frame-toast-host.d.ts +18 -0
- package/lib/types/native-ui/toast/index.d.ts +19 -0
- package/lib/types/presets.d.ts +11 -0
- package/lib/types/remote/client.d.ts +89 -0
- package/lib/types/remote/jsapi-config.d.ts +9 -0
- package/lib/types/remote/load-timing.d.ts +46 -0
- package/lib/types/remote/protocol.d.ts +160 -0
- package/lib/types/remote/review-launch.d.ts +6 -0
- package/lib/types/remote/runtime-entry.d.ts +1 -0
- package/lib/types/remote/runtime.d.ts +14 -0
- package/lib/types/remote/simulator-prompt.d.ts +9 -0
- package/lib/types/remote/widget-snapshot-guest-runtime.d.ts +1 -0
- package/lib/types/remote-client.d.ts +5 -0
- package/lib/types/renderer/base.d.ts +8 -0
- package/lib/types/renderer/content-host/iframe-content-host.d.ts +83 -0
- package/lib/types/renderer/content-host/index.d.ts +3 -0
- package/lib/types/renderer/content-host/types.d.ts +89 -0
- package/lib/types/renderer/content-host/webview-content-host.d.ts +53 -0
- package/lib/types/renderer/iframe.d.ts +93 -0
- package/lib/types/renderer/index.d.ts +2 -0
- package/lib/types/renderer/rednote-shell.d.ts +73 -0
- package/lib/types/renderer/webview.d.ts +59 -0
- package/lib/types/runtime/context.d.ts +31 -0
- package/lib/types/runtime/jsapi-modules/context.d.ts +19 -0
- package/lib/types/runtime/jsapi-modules/filesystem.d.ts +19 -0
- package/lib/types/runtime/jsapi-modules/index.d.ts +9 -0
- package/lib/types/runtime/jsapi-modules/interaction.d.ts +4 -0
- package/lib/types/runtime/jsapi-modules/location.d.ts +3 -0
- package/lib/types/runtime/jsapi-modules/media.d.ts +13 -0
- package/lib/types/runtime/jsapi-modules/network.d.ts +3 -0
- package/lib/types/runtime/jsapi-modules/storage.d.ts +26 -0
- package/lib/types/runtime/jsapi-modules/system.d.ts +4 -0
- package/lib/types/runtime/jsapi-modules/types.d.ts +21 -0
- package/lib/types/runtime/jsapi-modules/window-info.d.ts +43 -0
- package/lib/types/runtime/request/host-request.d.ts +13 -0
- package/lib/types/runtime/request/request-manager-frame.d.ts +29 -0
- package/lib/types/runtime/request/request-runtime.d.ts +26 -0
- package/lib/types/runtime/request/request-types.d.ts +26 -0
- package/lib/types/runtime/request/sse-text-framer.d.ts +16 -0
- package/lib/types/seal-config.d.ts +134 -0
- package/lib/types/sw/index.d.ts +9 -0
- package/lib/types/sw/parse-raw.d.ts +34 -0
- package/lib/types/sw/protocol.d.ts +17 -0
- package/lib/types/sw/served-entry.d.ts +9 -0
- package/lib/types/sw/service-worker-content-host.d.ts +11 -0
- package/lib/types/sw/service-worker-host.d.ts +73 -0
- package/lib/types/sw/service-worker-renderer.d.ts +10 -0
- package/lib/types/sw/worker/fs-codec.d.ts +23 -0
- package/lib/types/sw/worker/fs-ops.d.ts +22 -0
- package/lib/types/sw/worker/fs-store.d.ts +29 -0
- package/lib/types/sw/worker/globals.d.ts +49 -0
- package/lib/types/sw/worker/main.d.ts +6 -0
- package/lib/types/sw/worker/mime.d.ts +2 -0
- package/lib/types/sw/worker/mount-store.d.ts +43 -0
- package/lib/types/sw/worker/paths.d.ts +4 -0
- package/lib/types/sw/worker/serve.d.ts +13 -0
- package/lib/types/tracker/constants.d.ts +14 -0
- package/lib/types/tracker/default-tracker.d.ts +19 -0
- package/lib/types/tracker/index.d.ts +70 -0
- package/lib/types/transport/bridge-protocol.d.ts +78 -0
- package/lib/types/transport/iframe-transport.d.ts +39 -0
- package/lib/types/transport/index.d.ts +14 -0
- package/lib/types/transport/jsapi-bridge-messages.d.ts +36 -0
- package/lib/types/transport/types.d.ts +48 -0
- package/lib/types/transport/webview-transport.d.ts +52 -0
- package/lib/types/types/events.d.ts +130 -0
- package/lib/types/types/index.d.ts +11 -0
- package/lib/types/types/inspector.d.ts +172 -0
- package/lib/types/types/jsapi.d.ts +18 -0
- package/lib/types/types/options.d.ts +844 -0
- package/lib/types/types/renderer.d.ts +145 -0
- package/lib/types/utils/ancestor-scroll.d.ts +11 -0
- package/lib/types/utils/error-svg.d.ts +12 -0
- package/lib/types/utils/frameless-shell.d.ts +114 -0
- package/lib/types/utils/miniapp-chrome-svg.d.ts +47 -0
- package/lib/types/utils/package-constants.d.ts +8 -0
- package/lib/types/utils/screenshot.d.ts +14 -0
- package/lib/types/utils/simulator-pc-guard.d.ts +10 -0
- package/lib/types/utils/stage-fit.d.ts +6 -0
- package/lib/types/utils/touch-emulate.d.ts +26 -0
- package/lib/types/utils/zip-entry.d.ts +13 -0
- package/lib/types/workbench/index.d.ts +63 -0
- package/lib/types/workbench/preview-transition.d.ts +8 -0
- package/lib/types/workbench/server/artifact.d.ts +8 -0
- package/lib/types/workbench/server/index.d.ts +19 -0
- package/lib/types/workbench/server/watch.d.ts +6 -0
- package/lib/types/workbench/view.d.ts +36 -0
- package/lib/workbench-server.mjs +183 -0
- package/lib/workbench.js +1404 -0
- package/package.json +63 -0
- package/scripts/mock-cli-dev.mjs +52 -0
|
@@ -0,0 +1,505 @@
|
|
|
1
|
+
const T = "0.1.10";
|
|
2
|
+
var d = /* @__PURE__ */ ((e) => (e[e.INVALID_PARAM = 10001] = "INVALID_PARAM", e[e.API_UNAVAILABLE = 10002] = "API_UNAVAILABLE", e[e.URL_SCHEME_NOT_ALLOWED = 10003] = "URL_SCHEME_NOT_ALLOWED", e[e.REQUEST_TIMEOUT = 10101] = "REQUEST_TIMEOUT", e[e.REQUEST_ABORTED = 10102] = "REQUEST_ABORTED", e[e.REQUEST_FAILED = 15201] = "REQUEST_FAILED", e[e.STORAGE_IO_ERROR = 50101] = "STORAGE_IO_ERROR", e[e.STORAGE_QUOTA_EXCEEDED = 50201] = "STORAGE_QUOTA_EXCEEDED", e[e.FILE_NOT_FOUND = 50202] = "FILE_NOT_FOUND", e[e.PATH_INVALID = 50203] = "PATH_INVALID", e[e.FILE_ALREADY_EXISTS = 50204] = "FILE_ALREADY_EXISTS", e[e.NOT_A_FILE = 50205] = "NOT_A_FILE", e[e.NOT_A_DIRECTORY = 50206] = "NOT_A_DIRECTORY", e))(d || {});
|
|
3
|
+
function f(e, t) {
|
|
4
|
+
return Object.assign(new Error(t), { code: e });
|
|
5
|
+
}
|
|
6
|
+
class v {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.buffer = "";
|
|
9
|
+
}
|
|
10
|
+
push(t) {
|
|
11
|
+
return t && (this.buffer += t), this.drain(!1);
|
|
12
|
+
}
|
|
13
|
+
/** SSE 末尾没有空行时属于未完成帧,不向调用方发送。 */
|
|
14
|
+
finish() {
|
|
15
|
+
const t = this.drain(!0);
|
|
16
|
+
return this.buffer = "", t;
|
|
17
|
+
}
|
|
18
|
+
drain(t) {
|
|
19
|
+
const n = [];
|
|
20
|
+
let r = 0, s = 0, o = 0;
|
|
21
|
+
for (; o < this.buffer.length; ) {
|
|
22
|
+
const i = this.buffer[o];
|
|
23
|
+
if (i !== "\r" && i !== `
|
|
24
|
+
`) {
|
|
25
|
+
o += 1;
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
let a = o + 1;
|
|
29
|
+
if (i === "\r") {
|
|
30
|
+
if (a === this.buffer.length && !t) break;
|
|
31
|
+
this.buffer[a] === `
|
|
32
|
+
` && (a += 1);
|
|
33
|
+
}
|
|
34
|
+
o === s && (n.push(this.buffer.slice(r, a)), r = a), s = a, o = a;
|
|
35
|
+
}
|
|
36
|
+
return r > 0 && (this.buffer = this.buffer.slice(r)), n;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function z() {
|
|
40
|
+
let e = "";
|
|
41
|
+
const t = (n) => {
|
|
42
|
+
const r = [];
|
|
43
|
+
let s = 0, o = 0, i = 0;
|
|
44
|
+
for (; i < e.length; ) {
|
|
45
|
+
const a = e[i];
|
|
46
|
+
if (a !== "\r" && a !== `
|
|
47
|
+
`) {
|
|
48
|
+
i += 1;
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
let c = i + 1;
|
|
52
|
+
if (a === "\r") {
|
|
53
|
+
if (c === e.length && !n) break;
|
|
54
|
+
e[c] === `
|
|
55
|
+
` && (c += 1);
|
|
56
|
+
}
|
|
57
|
+
i === o && (r.push(e.slice(s, c)), s = c), o = c, i = c;
|
|
58
|
+
}
|
|
59
|
+
return s > 0 && (e = e.slice(s)), r;
|
|
60
|
+
};
|
|
61
|
+
return {
|
|
62
|
+
push(n) {
|
|
63
|
+
return n && (e += n), t(!1);
|
|
64
|
+
},
|
|
65
|
+
finish() {
|
|
66
|
+
const n = t(!0);
|
|
67
|
+
return e = "", n;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
function I(e) {
|
|
72
|
+
return e?.toLowerCase().includes("text/event-stream") ?? !1;
|
|
73
|
+
}
|
|
74
|
+
const E = /* @__PURE__ */ new WeakMap();
|
|
75
|
+
async function W(e, t, n) {
|
|
76
|
+
L(t.data);
|
|
77
|
+
const r = E.get(e);
|
|
78
|
+
if (r) return r(t, n);
|
|
79
|
+
const s = await e(S(t, n.signal));
|
|
80
|
+
if (n.signal.aborted)
|
|
81
|
+
throw f(d.REQUEST_ABORTED, "request aborted");
|
|
82
|
+
O(s);
|
|
83
|
+
const o = U(s.header);
|
|
84
|
+
return n.onHeaders({ taskId: t.taskId, statusCode: s.statusCode, header: o }), t.enableChunked && I(o["content-type"]) && (typeof s.data == "string" || D(s.data)) ? (await x(s.data, t.taskId, n), { taskId: t.taskId, statusCode: s.statusCode, data: "", header: o }) : {
|
|
85
|
+
taskId: t.taskId,
|
|
86
|
+
statusCode: s.statusCode,
|
|
87
|
+
data: await N(s.data, t),
|
|
88
|
+
header: o
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function S(e, t) {
|
|
92
|
+
const n = e.data, r = { ...e.header }, s = e.method.toUpperCase();
|
|
93
|
+
return s === "GET" || s === "HEAD" ? {
|
|
94
|
+
url: w(e.url, b(n)),
|
|
95
|
+
method: e.method,
|
|
96
|
+
header: r,
|
|
97
|
+
responseType: e.responseType,
|
|
98
|
+
enableChunked: e.enableChunked,
|
|
99
|
+
signal: t
|
|
100
|
+
} : {
|
|
101
|
+
url: e.url,
|
|
102
|
+
method: e.method,
|
|
103
|
+
header: r,
|
|
104
|
+
data: R(n, r),
|
|
105
|
+
responseType: e.responseType,
|
|
106
|
+
enableChunked: e.enableChunked,
|
|
107
|
+
signal: t
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
function w(e, t) {
|
|
111
|
+
if (!t) return e;
|
|
112
|
+
const n = e.indexOf("#"), r = n >= 0 ? e.slice(n) : "", s = n >= 0 ? e.slice(0, n) : e;
|
|
113
|
+
return `${s}${s.includes("?") ? "&" : "?"}${t}${r}`;
|
|
114
|
+
}
|
|
115
|
+
function b(e) {
|
|
116
|
+
return e == null ? "" : typeof e == "string" ? e : typeof e != "object" || Array.isArray(e) ? String(e) : Object.entries(e).map(([t, n]) => `${encodeURIComponent(t)}=${encodeURIComponent(String(n))}`).join("&");
|
|
117
|
+
}
|
|
118
|
+
function R(e, t) {
|
|
119
|
+
if (e == null || typeof e == "string") return e;
|
|
120
|
+
let n = p(t, "content-type");
|
|
121
|
+
return n || (n = "application/json", t["content-type"] = n), n.toLowerCase().includes("application/json") ? JSON.stringify(e) : n.toLowerCase().includes("application/x-www-form-urlencoded") ? b(e) : String(e);
|
|
122
|
+
}
|
|
123
|
+
function p(e, t) {
|
|
124
|
+
const n = Object.keys(e).find((r) => r.toLowerCase() === t);
|
|
125
|
+
return n ? String(e[n]) : void 0;
|
|
126
|
+
}
|
|
127
|
+
function L(e) {
|
|
128
|
+
if (!(!(e instanceof ArrayBuffer) && !ArrayBuffer.isView(e)))
|
|
129
|
+
throw f(
|
|
130
|
+
d.INVALID_PARAM,
|
|
131
|
+
"request data does not support ArrayBuffer"
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
function O(e) {
|
|
135
|
+
if (!e || typeof e != "object" || typeof e.statusCode != "number")
|
|
136
|
+
throw f(
|
|
137
|
+
d.REQUEST_FAILED,
|
|
138
|
+
"host request adapter returned an invalid response"
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
function D(e) {
|
|
142
|
+
return !!(e && typeof e == "object" && "getReader" in e);
|
|
143
|
+
}
|
|
144
|
+
async function x(e, t, n) {
|
|
145
|
+
const r = new v(), s = (c) => {
|
|
146
|
+
for (const u of r.push(c)) n.onChunk({ taskId: t, chunk: u });
|
|
147
|
+
};
|
|
148
|
+
if (typeof e == "string") {
|
|
149
|
+
s(e);
|
|
150
|
+
for (const c of r.finish()) n.onChunk({ taskId: t, chunk: c });
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
const o = e.getReader(), i = new TextDecoder(), a = () => void o.cancel().catch(() => {
|
|
154
|
+
});
|
|
155
|
+
n.signal.addEventListener("abort", a, { once: !0 });
|
|
156
|
+
try {
|
|
157
|
+
for (; ; ) {
|
|
158
|
+
if (n.signal.aborted) return;
|
|
159
|
+
const u = await o.read();
|
|
160
|
+
if (u.done) break;
|
|
161
|
+
const l = typeof u.value == "string" ? u.value : i.decode(u.value, { stream: !0 });
|
|
162
|
+
l && s(l);
|
|
163
|
+
}
|
|
164
|
+
const c = i.decode();
|
|
165
|
+
c && s(c);
|
|
166
|
+
for (const u of r.finish()) n.onChunk({ taskId: t, chunk: u });
|
|
167
|
+
} finally {
|
|
168
|
+
n.signal.removeEventListener("abort", a), o.releaseLock();
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
function U(e) {
|
|
172
|
+
const t = {};
|
|
173
|
+
for (const [n, r] of Object.entries(e ?? {}))
|
|
174
|
+
n.toLowerCase() !== "set-cookie" && (t[n.toLowerCase()] = String(r));
|
|
175
|
+
return t;
|
|
176
|
+
}
|
|
177
|
+
async function N(e, t) {
|
|
178
|
+
if (e instanceof ArrayBuffer || ArrayBuffer.isView(e))
|
|
179
|
+
throw f(
|
|
180
|
+
d.REQUEST_FAILED,
|
|
181
|
+
"request response does not support ArrayBuffer"
|
|
182
|
+
);
|
|
183
|
+
if (t.dataType === "json" && typeof e == "string")
|
|
184
|
+
try {
|
|
185
|
+
return JSON.parse(e);
|
|
186
|
+
} catch {
|
|
187
|
+
return e;
|
|
188
|
+
}
|
|
189
|
+
return e;
|
|
190
|
+
}
|
|
191
|
+
const B = "miniapp_simulator_event", P = "skillbuilder-miniapp", A = {
|
|
192
|
+
cn: {
|
|
193
|
+
production: "https://apm-fe.xiaohongshu.com/api/data",
|
|
194
|
+
development: "https://apm-fe-test.xiaohongshu.com/api/data"
|
|
195
|
+
},
|
|
196
|
+
sg: {
|
|
197
|
+
production: "https://apm-fe.rnote.com/api/data",
|
|
198
|
+
development: "https://apm-fe.rnote.com/api/data"
|
|
199
|
+
}
|
|
200
|
+
}, F = 10, j = 1e4;
|
|
201
|
+
function _() {
|
|
202
|
+
return typeof crypto < "u" && typeof crypto.randomUUID == "function" ? crypto.randomUUID() : `${Date.now().toString(16)}-${Math.random().toString(16).slice(2)}`;
|
|
203
|
+
}
|
|
204
|
+
function C(e, t) {
|
|
205
|
+
const n = typeof window < "u";
|
|
206
|
+
return {
|
|
207
|
+
clientTime: Date.now(),
|
|
208
|
+
context_sdkSessionId: t.sessionId,
|
|
209
|
+
context_pageSessionId: t.pageSessionId,
|
|
210
|
+
context_sdkSeqId: t.seqId,
|
|
211
|
+
context_nameTracker: "wapT",
|
|
212
|
+
context_platform: "PC",
|
|
213
|
+
context_accountGeographicZone: t.region,
|
|
214
|
+
context_appVersion: "discovery-0.0.0",
|
|
215
|
+
context_osVersion: "unknown",
|
|
216
|
+
context_deviceModel: "",
|
|
217
|
+
context_deviceId: "",
|
|
218
|
+
context_package: "",
|
|
219
|
+
context_networkType: "unknow",
|
|
220
|
+
context_networkQuality: "UNKNOWN",
|
|
221
|
+
context_matchedPath: n ? window.location.pathname : "",
|
|
222
|
+
context_route: n ? window.location.href : "",
|
|
223
|
+
context_userAgent: typeof navigator < "u" ? navigator.userAgent : "",
|
|
224
|
+
context_artifactName: P,
|
|
225
|
+
context_artifactVersion: T,
|
|
226
|
+
context_deviceLevel: "unknown",
|
|
227
|
+
context_feSdkVersion: "1.3.13",
|
|
228
|
+
context_userId: t.userId,
|
|
229
|
+
measurement_name: B,
|
|
230
|
+
measurement_data: {
|
|
231
|
+
event_name: e.name,
|
|
232
|
+
timestamp: e.timestamp,
|
|
233
|
+
...e.payload
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
function H(e, t) {
|
|
238
|
+
if (!(typeof fetch != "function" || t.length === 0))
|
|
239
|
+
try {
|
|
240
|
+
const n = {
|
|
241
|
+
method: "POST",
|
|
242
|
+
headers: {
|
|
243
|
+
"content-type": "application/json",
|
|
244
|
+
"Biz-Type": "apm_fe",
|
|
245
|
+
Batch: "true"
|
|
246
|
+
},
|
|
247
|
+
body: JSON.stringify(t)
|
|
248
|
+
};
|
|
249
|
+
typeof navigator < "u" && "sendBeacon" in navigator && (n.keepalive = !0), Promise.resolve(fetch(e, n)).catch(() => {
|
|
250
|
+
});
|
|
251
|
+
} catch {
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
function q(e) {
|
|
255
|
+
if (typeof console > "u") return;
|
|
256
|
+
const t = e.measurement_name ?? "apm";
|
|
257
|
+
console.groupCollapsed(`[apm] ${t}`), console.log(e), console.groupEnd();
|
|
258
|
+
}
|
|
259
|
+
function V(e) {
|
|
260
|
+
const t = e.debug === !0, n = _(), r = _();
|
|
261
|
+
let s = 0, o = [], i = null, a = 0, c = !1;
|
|
262
|
+
const u = () => {
|
|
263
|
+
if (c = !1, i !== null && (clearTimeout(i), i = null), o.length === 0) return;
|
|
264
|
+
const h = o;
|
|
265
|
+
o = [], H(e.endpoint, h);
|
|
266
|
+
}, l = () => {
|
|
267
|
+
if (i !== null && (clearTimeout(i), i = null), a > 0) {
|
|
268
|
+
c = !0;
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
u();
|
|
272
|
+
}, g = () => {
|
|
273
|
+
i === null && (i = setTimeout(l, j));
|
|
274
|
+
};
|
|
275
|
+
return {
|
|
276
|
+
sendCustomPoint(h) {
|
|
277
|
+
const y = s++;
|
|
278
|
+
a += 1, Promise.resolve().then(() => e.resolveUserId()).catch(() => "").then((k) => {
|
|
279
|
+
try {
|
|
280
|
+
const m = C(h, {
|
|
281
|
+
sessionId: n,
|
|
282
|
+
pageSessionId: r,
|
|
283
|
+
seqId: y,
|
|
284
|
+
userId: k,
|
|
285
|
+
region: e.region
|
|
286
|
+
});
|
|
287
|
+
if (t) {
|
|
288
|
+
q(m);
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
o.push(m), o.length >= F ? setTimeout(() => l()) : g();
|
|
292
|
+
} catch {
|
|
293
|
+
}
|
|
294
|
+
}).finally(() => {
|
|
295
|
+
a -= 1, a === 0 && c && u();
|
|
296
|
+
});
|
|
297
|
+
},
|
|
298
|
+
flush: l
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
function Q(e) {
|
|
302
|
+
const t = e.region ?? "cn";
|
|
303
|
+
if (e.endpoint) return e.endpoint;
|
|
304
|
+
const n = $();
|
|
305
|
+
return A[t][n];
|
|
306
|
+
}
|
|
307
|
+
function $() {
|
|
308
|
+
if (typeof window > "u") return "production";
|
|
309
|
+
const e = window.location.hostname.toLowerCase();
|
|
310
|
+
return e === "localhost" || e === "127.0.0.1" || e === "0.0.0.0" || e.includes(".sit.") || // hostname.includes(".beta.") ||
|
|
311
|
+
e.startsWith("local.") ? "development" : "production";
|
|
312
|
+
}
|
|
313
|
+
function G(e, t) {
|
|
314
|
+
if (e === !1) return null;
|
|
315
|
+
try {
|
|
316
|
+
const n = e.region ?? "cn", r = V({
|
|
317
|
+
endpoint: Q(e),
|
|
318
|
+
region: n,
|
|
319
|
+
resolveUserId: t ?? (() => Promise.resolve("")),
|
|
320
|
+
debug: e.debug
|
|
321
|
+
});
|
|
322
|
+
return { send: (s) => r.sendCustomPoint(s), flush: () => r.flush() };
|
|
323
|
+
} catch {
|
|
324
|
+
return null;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
class X {
|
|
328
|
+
constructor(t, n, r, s) {
|
|
329
|
+
this.resolveContext = s, this.unsubscribers = [], this.common = {
|
|
330
|
+
business_line: "",
|
|
331
|
+
sdk_version: "",
|
|
332
|
+
content_mode: "",
|
|
333
|
+
renderer: ""
|
|
334
|
+
};
|
|
335
|
+
const o = G(t, r);
|
|
336
|
+
if (!o) {
|
|
337
|
+
this.send = () => {
|
|
338
|
+
}, this.flush = () => {
|
|
339
|
+
};
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
this.send = o.send, this.flush = o.flush, this.common = {
|
|
343
|
+
...this.common,
|
|
344
|
+
...t === !1 ? {} : t.context,
|
|
345
|
+
business_line: t === !1 ? "" : t.business_line ?? "unknown"
|
|
346
|
+
}, this.bindEvents(n), this.bindFlushOnHidden();
|
|
347
|
+
}
|
|
348
|
+
/** 页面隐藏时立即冲刷缓冲,避免关闭前丢数据 */
|
|
349
|
+
bindFlushOnHidden() {
|
|
350
|
+
if (typeof document > "u") return;
|
|
351
|
+
const t = () => {
|
|
352
|
+
document.visibilityState === "hidden" && this.flush();
|
|
353
|
+
};
|
|
354
|
+
document.addEventListener("visibilitychange", t), this.unsubscribers.push(() => document.removeEventListener("visibilitychange", t));
|
|
355
|
+
}
|
|
356
|
+
bindEvents(t) {
|
|
357
|
+
this.unsubscribers.push(
|
|
358
|
+
t.on("beforeLoad", (n) => {
|
|
359
|
+
n.url && this.track("simulator_before_load", {
|
|
360
|
+
url: n.url,
|
|
361
|
+
source: n.source
|
|
362
|
+
});
|
|
363
|
+
})
|
|
364
|
+
), this.unsubscribers.push(
|
|
365
|
+
t.on("ready", () => {
|
|
366
|
+
this.track("simulator_ready", {});
|
|
367
|
+
})
|
|
368
|
+
), this.unsubscribers.push(
|
|
369
|
+
t.on("load", (n) => {
|
|
370
|
+
n.url && this.track("simulator_load", { url: n.url, duration: n.duration });
|
|
371
|
+
})
|
|
372
|
+
), this.unsubscribers.push(
|
|
373
|
+
t.on("error", (n) => {
|
|
374
|
+
this.track("simulator_load_error", {
|
|
375
|
+
url: n.url,
|
|
376
|
+
error_name: n.code,
|
|
377
|
+
message: n.message
|
|
378
|
+
});
|
|
379
|
+
})
|
|
380
|
+
), this.unsubscribers.push(
|
|
381
|
+
t.on("renderDone", (n) => {
|
|
382
|
+
n.url && this.track("simulator_render_done", { url: n.url, duration: n.duration });
|
|
383
|
+
})
|
|
384
|
+
), this.unsubscribers.push(
|
|
385
|
+
t.on("navigation", (n) => {
|
|
386
|
+
n.blocked && this.track("simulator_navigation_blocked", { source: n.from, url: n.to });
|
|
387
|
+
})
|
|
388
|
+
), this.unsubscribers.push(
|
|
389
|
+
t.on("guestError", (n) => {
|
|
390
|
+
this.track("simulator_guest_error", {
|
|
391
|
+
type: n.type,
|
|
392
|
+
error_name: n.name,
|
|
393
|
+
message: n.message?.slice(0, 1024),
|
|
394
|
+
stack: n.stack?.slice(0, 1024),
|
|
395
|
+
source: n.source,
|
|
396
|
+
url: n.url,
|
|
397
|
+
disposition: n.disposition,
|
|
398
|
+
effective_directive: n.effective_directive,
|
|
399
|
+
violated_directive: n.violated_directive,
|
|
400
|
+
blocked_uri: n.blocked_uri,
|
|
401
|
+
source_file: n.source_file,
|
|
402
|
+
line_number: n.line_number,
|
|
403
|
+
column_number: n.column_number,
|
|
404
|
+
original_policy: n.original_policy,
|
|
405
|
+
error_code: n.code,
|
|
406
|
+
request_id: n.request_id,
|
|
407
|
+
model: n.model,
|
|
408
|
+
operation: n.operation,
|
|
409
|
+
error_details: n.details
|
|
410
|
+
});
|
|
411
|
+
})
|
|
412
|
+
), this.unsubscribers.push(
|
|
413
|
+
t.on("destroy", (n) => {
|
|
414
|
+
this.track("simulator_destroy", { message: n.reason ?? "" });
|
|
415
|
+
})
|
|
416
|
+
);
|
|
417
|
+
}
|
|
418
|
+
/** 初始化公共字段并上报 simulator_init */
|
|
419
|
+
trackInit(t) {
|
|
420
|
+
this.common = {
|
|
421
|
+
...this.common,
|
|
422
|
+
sdk_version: t.sdkVersion,
|
|
423
|
+
content_mode: t.contentMode,
|
|
424
|
+
renderer: t.renderer
|
|
425
|
+
}, this.track("simulator_init", { url: t.appUrl });
|
|
426
|
+
}
|
|
427
|
+
/** 上报 reload 事件 */
|
|
428
|
+
trackReload(t) {
|
|
429
|
+
this.track("simulator_reload", { url: t });
|
|
430
|
+
}
|
|
431
|
+
/** srcdoc 注入完成 */
|
|
432
|
+
trackInjectDone(t) {
|
|
433
|
+
this.track("simulator_inject_done", {
|
|
434
|
+
url: t.url,
|
|
435
|
+
result: t.injected ? "injected" : "fallback",
|
|
436
|
+
duration: t.duration
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
/** 权限弹窗操作结果 */
|
|
440
|
+
trackPermissionResult(t) {
|
|
441
|
+
this.track("simulator_permission_result", t);
|
|
442
|
+
}
|
|
443
|
+
/** zip/files 解析完成 */
|
|
444
|
+
trackParseDone(t) {
|
|
445
|
+
this.track("simulator_parse_done", t);
|
|
446
|
+
}
|
|
447
|
+
/** SW 注册 + 激活结果(renderer: iframe-service-worker);scope 复用 url 字段 */
|
|
448
|
+
trackSwRegister(t) {
|
|
449
|
+
this.track("simulator_sw_register", t);
|
|
450
|
+
}
|
|
451
|
+
/** SW MOUNT(文件表挂载 + ACK)结果 */
|
|
452
|
+
trackSwMount(t) {
|
|
453
|
+
this.track("simulator_sw_mount", t);
|
|
454
|
+
}
|
|
455
|
+
/** 远程加载内部阶段;stage 保持低基数枚举,扩展字段只承载耗时与结果。 */
|
|
456
|
+
trackLoadStage(t, n) {
|
|
457
|
+
this.track("simulator_load_stage", { stage: t, ...n });
|
|
458
|
+
}
|
|
459
|
+
/** bridge 调用完成回调 */
|
|
460
|
+
handleBridgeInvoke(t) {
|
|
461
|
+
if (t.event === "reportTracker") return;
|
|
462
|
+
const n = {
|
|
463
|
+
name: t.event,
|
|
464
|
+
result: t.success ? "success" : "fail"
|
|
465
|
+
};
|
|
466
|
+
t.success ? n.duration = t.duration : n.message = t.error, this.track("bridge_invoke", n);
|
|
467
|
+
}
|
|
468
|
+
/** 发送打点:自动合入公共字段 */
|
|
469
|
+
track(t, n) {
|
|
470
|
+
try {
|
|
471
|
+
let r = {};
|
|
472
|
+
try {
|
|
473
|
+
r = this.resolveContext?.() ?? {};
|
|
474
|
+
} catch {
|
|
475
|
+
}
|
|
476
|
+
this.send({
|
|
477
|
+
name: t,
|
|
478
|
+
payload: { ...this.common, ...n, ...r },
|
|
479
|
+
timestamp: Date.now()
|
|
480
|
+
});
|
|
481
|
+
} catch {
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
destroy() {
|
|
485
|
+
queueMicrotask(() => this.flush());
|
|
486
|
+
for (const t of this.unsubscribers)
|
|
487
|
+
t();
|
|
488
|
+
this.unsubscribers.length = 0;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
function M(e) {
|
|
492
|
+
return !(e === void 0 || e === !1);
|
|
493
|
+
}
|
|
494
|
+
export {
|
|
495
|
+
d as M,
|
|
496
|
+
f as a,
|
|
497
|
+
z as b,
|
|
498
|
+
V as c,
|
|
499
|
+
M as d,
|
|
500
|
+
W as e,
|
|
501
|
+
X as f,
|
|
502
|
+
I as i,
|
|
503
|
+
Q as r,
|
|
504
|
+
T as v
|
|
505
|
+
};
|