@skillbuilder/miniapp-simulator 0.2.8 → 0.2.9

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/lib/index.js CHANGED
@@ -2,15 +2,15 @@ var or = (n) => {
2
2
  throw TypeError(n);
3
3
  };
4
4
  var sn = (n, e, t) => e.has(n) || or("Cannot " + t);
5
- var v = (n, e, t) => (sn(n, e, "read from private field"), t ? t.call(n) : e.get(n)), D = (n, e, t) => e.has(n) ? or("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(n) : e.set(n, t), _ = (n, e, t, r) => (sn(n, e, "write to private field"), r ? r.call(n, t) : e.set(n, t), t), oe = (n, e, t) => (sn(n, e, "access private method"), t);
6
- import { a as ar, M as T, b as U, i as ei, d as ti, e as ni, f as ri, g as si, v as ii } from "./index-BSj1bmle.mjs";
5
+ var y = (n, e, t) => (sn(n, e, "read from private field"), t ? t.call(n) : e.get(n)), U = (n, e, t) => e.has(n) ? or("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(n) : e.set(n, t), _ = (n, e, t, r) => (sn(n, e, "write to private field"), r ? r.call(n, t) : e.set(n, t), t), oe = (n, e, t) => (sn(n, e, "access private method"), t);
6
+ import { a as ar, M as F, b as Y, i as ei, d as ti, e as ni, f as ri, g as si, v as ii } from "./index-DwepISqo.mjs";
7
7
  import { B as oi, M as Je } from "./options-B34ipLmF.mjs";
8
8
  const ai = "minitool-worker-runtime", li = "0.1.0", ci = 1, di = "default-src 'none'; script-src 'none'; connect-src 'none'; worker-src 'none'; child-src 'none'", Nn = {
9
9
  name: ai,
10
10
  version: li,
11
11
  protocolVersion: ci,
12
12
  workerCsp: di
13
- }, ui = Nn, hi = Nn.protocolVersion, wu = Nn.workerCsp, B = {
13
+ }, ui = Nn, hi = Nn.protocolVersion, Cu = Nn.workerCsp, R = {
14
14
  /** 相机:getUserMedia({ video: true });seal 不直接拦截,由宿主层控制。 */
15
15
  Camera: "camera",
16
16
  /** 麦克风:getUserMedia({ audio: true });seal 不直接拦截,由宿主层控制。 */
@@ -62,167 +62,167 @@ const ai = "minitool-worker-runtime", li = "0.1.0", ci = 1, di = "default-src 'n
62
62
  /** 系统输入对话框:window.prompt。 */
63
63
  WindowPrompt: "window-prompt"
64
64
  }, pi = "__MINI_APP_SEAL_CONFIG__", ns = [
65
- B.Camera,
66
- B.Microphone,
67
- B.PhotoLibrary
65
+ R.Camera,
66
+ R.Microphone,
67
+ R.PhotoLibrary
68
68
  ];
69
- B.Geolocation, B.Clipboard, B.Clipboard, B.PersistentStorage, B.GenericSensor, B.GenericSensor, B.GenericSensor, B.GenericSensor, B.Camera, B.Microphone, B.Bluetooth, B.StorageAccess, B.Credentials, B.Credentials;
69
+ R.Geolocation, R.Clipboard, R.Clipboard, R.PersistentStorage, R.GenericSensor, R.GenericSensor, R.GenericSensor, R.GenericSensor, R.Camera, R.Microphone, R.Bluetooth, R.StorageAccess, R.Credentials, R.Credentials;
70
70
  const nn = [
71
71
  {
72
- value: B.Camera,
72
+ value: R.Camera,
73
73
  controlledBy: "host",
74
74
  description: "相机:getUserMedia({ video: true })",
75
75
  permissionNames: ["camera"]
76
76
  },
77
77
  {
78
- value: B.Microphone,
78
+ value: R.Microphone,
79
79
  controlledBy: "host",
80
80
  description: "麦克风:getUserMedia({ audio: true })",
81
81
  permissionNames: ["microphone"]
82
82
  },
83
83
  {
84
- value: B.PhotoLibrary,
84
+ value: R.PhotoLibrary,
85
85
  controlledBy: "host",
86
86
  description: "相册 / 文件选择:input[type=file]",
87
87
  permissionNames: []
88
88
  },
89
89
  {
90
- value: B.Geolocation,
90
+ value: R.Geolocation,
91
91
  controlledBy: "seal",
92
92
  description: "定位:navigator.geolocation",
93
93
  permissionNames: ["geolocation"]
94
94
  },
95
95
  {
96
- value: B.Clipboard,
96
+ value: R.Clipboard,
97
97
  controlledBy: "seal",
98
98
  description: "剪贴板:navigator.clipboard + execCommand copy/cut/paste",
99
99
  permissionNames: ["clipboard-read", "clipboard-write"]
100
100
  },
101
101
  {
102
- value: B.Bluetooth,
102
+ value: R.Bluetooth,
103
103
  controlledBy: "seal",
104
104
  description: "蓝牙:navigator.bluetooth",
105
105
  permissionNames: ["bluetooth"]
106
106
  },
107
107
  {
108
- value: B.Usb,
108
+ value: R.Usb,
109
109
  controlledBy: "seal",
110
110
  description: "USB:navigator.usb",
111
111
  permissionNames: []
112
112
  },
113
113
  {
114
- value: B.Hid,
114
+ value: R.Hid,
115
115
  controlledBy: "seal",
116
116
  description: "HID:navigator.hid",
117
117
  permissionNames: []
118
118
  },
119
119
  {
120
- value: B.Serial,
120
+ value: R.Serial,
121
121
  controlledBy: "seal",
122
122
  description: "串口:navigator.serial",
123
123
  permissionNames: []
124
124
  },
125
125
  {
126
- value: B.GenericSensor,
126
+ value: R.GenericSensor,
127
127
  controlledBy: "seal",
128
128
  description: "Generic Sensor:Accelerometer / Gyroscope / Magnetometer 等",
129
129
  permissionNames: ["accelerometer", "gyroscope", "magnetometer", "ambient-light-sensor"]
130
130
  },
131
131
  {
132
- value: B.DeviceMotion,
132
+ value: R.DeviceMotion,
133
133
  controlledBy: "seal",
134
134
  description: "设备运动:DeviceMotionEvent + addEventListener('devicemotion')",
135
135
  permissionNames: []
136
136
  },
137
137
  {
138
- value: B.DeviceOrientation,
138
+ value: R.DeviceOrientation,
139
139
  controlledBy: "seal",
140
140
  description: "设备方向:DeviceOrientationEvent + addEventListener('deviceorientation')",
141
141
  permissionNames: []
142
142
  },
143
143
  {
144
- value: B.Webrtc,
144
+ value: R.Webrtc,
145
145
  controlledBy: "seal",
146
146
  description: "WebRTC 直连:RTCPeerConnection / RTCDataChannel",
147
147
  permissionNames: []
148
148
  },
149
149
  {
150
- value: B.ScreenShare,
150
+ value: R.ScreenShare,
151
151
  controlledBy: "seal",
152
152
  description: "屏幕共享:mediaDevices.getDisplayMedia",
153
153
  permissionNames: []
154
154
  },
155
155
  {
156
- value: B.MediaDeviceEnumeration,
156
+ value: R.MediaDeviceEnumeration,
157
157
  controlledBy: "seal",
158
158
  description: "媒体设备枚举:mediaDevices.enumerateDevices",
159
159
  permissionNames: []
160
160
  },
161
161
  {
162
- value: B.Battery,
162
+ value: R.Battery,
163
163
  controlledBy: "seal",
164
164
  description: "电池:navigator.getBattery",
165
165
  permissionNames: []
166
166
  },
167
167
  {
168
- value: B.Connection,
168
+ value: R.Connection,
169
169
  controlledBy: "seal",
170
170
  description: "网络信息:navigator.connection",
171
171
  permissionNames: []
172
172
  },
173
173
  {
174
- value: B.PersistentStorage,
174
+ value: R.PersistentStorage,
175
175
  controlledBy: "seal",
176
176
  description: "持久化存储:navigator.storage.persist",
177
177
  permissionNames: ["persistent-storage"]
178
178
  },
179
179
  {
180
- value: B.StorageAccess,
180
+ value: R.StorageAccess,
181
181
  controlledBy: "seal",
182
182
  description: "跨域存储访问:document.requestStorageAccess",
183
183
  permissionNames: ["storage-access"]
184
184
  },
185
185
  {
186
- value: B.Credentials,
186
+ value: R.Credentials,
187
187
  controlledBy: "seal",
188
188
  description: "凭据 / WebAuthn:navigator.credentials",
189
189
  permissionNames: ["publickey-credentials-get", "publickey-credentials-create"]
190
190
  },
191
191
  {
192
- value: B.Locks,
192
+ value: R.Locks,
193
193
  controlledBy: "seal",
194
194
  description: "Web Locks:navigator.locks",
195
195
  permissionNames: []
196
196
  },
197
197
  {
198
- value: B.Fullscreen,
198
+ value: R.Fullscreen,
199
199
  controlledBy: "seal",
200
200
  description: "全屏:Element.requestFullscreen 及前缀实现",
201
201
  permissionNames: []
202
202
  },
203
203
  {
204
- value: B.InputCapture,
204
+ value: R.InputCapture,
205
205
  controlledBy: "seal",
206
206
  description: "input[capture] 直调相机:DOM 扫除 + MutationObserver",
207
207
  permissionNames: []
208
208
  },
209
209
  {
210
- value: B.WindowOpen,
210
+ value: R.WindowOpen,
211
211
  controlledBy: "seal",
212
212
  description: "弹出新窗口:window.open",
213
213
  permissionNames: []
214
214
  },
215
215
  {
216
- value: B.WindowPrompt,
216
+ value: R.WindowPrompt,
217
217
  controlledBy: "seal",
218
218
  description: "系统输入对话框:window.prompt",
219
219
  permissionNames: []
220
220
  }
221
- ], rs = nn.map((n) => n.value), Cu = nn.filter((n) => n.controlledBy === "seal").map((n) => n.value), Su = nn.filter((n) => n.controlledBy === "host").map((n) => n.value), Ai = new Set(rs);
221
+ ], rs = nn.map((n) => n.value), Su = nn.filter((n) => n.controlledBy === "seal").map((n) => n.value), Eu = nn.filter((n) => n.controlledBy === "host").map((n) => n.value), Ai = new Set(rs);
222
222
  function fi(n) {
223
223
  return typeof n == "string" && Ai.has(n);
224
224
  }
225
- function Eu(n) {
225
+ function xu(n) {
226
226
  if (!Array.isArray(n)) return [];
227
227
  const e = [], t = /* @__PURE__ */ new Set();
228
228
  for (const r of n)
@@ -275,13 +275,13 @@ function vi(n) {
275
275
  }
276
276
  return e.join(", ");
277
277
  }
278
- class te extends Error {
278
+ class ne extends Error {
279
279
  constructor(e, t, r) {
280
280
  super(t), this.name = "MiniAppSimulatorError", this.code = e, this.url = r?.url, this.cause = r?.cause;
281
281
  }
282
282
  }
283
283
  function lr(n, e) {
284
- return n instanceof te ? n : n instanceof Error ? new te(e, n.message, { cause: n }) : new te(e, String(n), { cause: n });
284
+ return n instanceof ne ? n : n instanceof Error ? new ne(e, n.message, { cause: n }) : new ne(e, String(n), { cause: n });
285
285
  }
286
286
  class is {
287
287
  constructor() {
@@ -391,8 +391,8 @@ function xi(n, e = {}) {
391
391
  let a = null, l = i;
392
392
  if (t) {
393
393
  a = i.attachShadow({ mode: "open" });
394
- const S = document.createElement("style");
395
- S.textContent = Si, a.appendChild(S), l = a;
394
+ const E = document.createElement("style");
395
+ E.textContent = Si, a.appendChild(E), l = a;
396
396
  }
397
397
  const d = document.createElement("div");
398
398
  d.className = os, t || Object.assign(d.style, {
@@ -400,12 +400,12 @@ function xi(n, e = {}) {
400
400
  inset: "0",
401
401
  overflow: "hidden"
402
402
  }), l.appendChild(d);
403
- const h = document.createElement("div");
404
- h.className = Ci, h.style.position = "relative", d.appendChild(h);
405
- const A = document.createElement("div");
406
- A.setAttribute("data-mini-app-device", ""), A.dataset.miniAppScreenRotation = "0", A.style.transformOrigin = "0 0", h.appendChild(A);
407
403
  const u = document.createElement("div");
408
- u.className = Sn, t || Object.assign(u.style, {
404
+ u.className = Ci, u.style.position = "relative", d.appendChild(u);
405
+ const A = document.createElement("div");
406
+ A.setAttribute("data-mini-app-device", ""), A.dataset.miniAppScreenRotation = "0", A.style.transformOrigin = "0 0", u.appendChild(A);
407
+ const h = document.createElement("div");
408
+ h.className = Sn, t || Object.assign(h.style, {
409
409
  position: "absolute",
410
410
  top: "0",
411
411
  right: "0",
@@ -413,89 +413,106 @@ function xi(n, e = {}) {
413
413
  width: "0px",
414
414
  overflow: "hidden",
415
415
  display: "none"
416
- }), l.appendChild(u);
417
- let m = 0, w = 0, b = !1, f = 0;
418
- const y = () => {
419
- const S = h.offsetWidth, R = h.offsetHeight, V = S > R, Z = b && !V ? 128 : 0, Y = b && V ? 60 : 0;
420
- if (d.dataset.miniAppStageAlign = b ? "top" : "center", b && V) {
421
- const M = m > 0, fe = M ? 12 : 0, ne = M ? Math.min(180, i.clientHeight * 0.4) : 0, re = Math.max(
416
+ }), l.appendChild(h);
417
+ let m = 0, v = 0, b = !1, f = 0;
418
+ const w = (E, k) => {
419
+ const N = E > k, Z = b && !N ? 128 : 0, G = b && N ? 60 : 0;
420
+ if (b && N) {
421
+ const de = m > 0, te = de ? 12 : 0, re = de ? Math.min(180, i.clientHeight * 0.4) : 0, C = Math.max(
422
422
  0,
423
- i.clientHeight - Y - fe - ne
424
- ), C = S > 0 ? i.clientWidth * R / S : 0, W = M ? Math.floor(Math.min(C, re)) : Math.max(0, i.clientHeight - Y);
425
- Object.assign(d.style, {
426
- left: "0px",
427
- right: "0px",
428
- bottom: `${i.clientHeight - W}px`
429
- }), Object.assign(u.style, {
430
- top: `${W + Y + fe}px`,
431
- right: "0px",
432
- width: `${M ? i.clientWidth : 0}px`
433
- });
434
- return;
423
+ i.clientHeight - G - te - re
424
+ ), T = E > 0 ? i.clientWidth * k / E : 0, M = de ? Math.floor(Math.min(T, C)) : Math.max(0, i.clientHeight - G);
425
+ return {
426
+ left: 0,
427
+ right: 0,
428
+ bottom: i.clientHeight - M,
429
+ panelTop: M + G + te,
430
+ panelRight: 0,
431
+ panelWidth: de ? i.clientWidth : 0
432
+ };
435
433
  }
436
- const Q = R > 0 ? Math.max(0, i.clientHeight - Y) * S / R : i.clientWidth, $ = m > 0 ? Math.max(
434
+ const $ = k > 0 ? Math.max(0, i.clientHeight - G) * E / k : i.clientWidth, D = m > 0 ? Math.max(
437
435
  m,
438
436
  Math.min(
439
- w,
437
+ v,
440
438
  i.clientWidth / 3,
441
- i.clientWidth - Q - 32
439
+ i.clientWidth - $ - 32
442
440
  )
443
- ) : 0, X = Math.floor(
444
- b ? Math.min($, Math.max(0, i.clientWidth - Z - 80)) : $
441
+ ) : 0, I = Math.floor(
442
+ b ? Math.min(D, Math.max(0, i.clientWidth - Z - 80)) : D
445
443
  ), P = m > 0 ? Math.max(
446
444
  0,
447
445
  Math.floor(
448
- (i.clientWidth - Z - X - Q - 32) / 2
446
+ (i.clientWidth - Z - I - $ - 32) / 2
449
447
  )
450
448
  ) : 0;
451
- Object.assign(d.style, {
452
- left: `${P + Z}px`,
453
- right: `${P + X}px`,
454
- bottom: "0px"
455
- }), Object.assign(u.style, {
456
- top: "0px",
457
- right: `${P}px`,
458
- width: `${X}px`
449
+ return {
450
+ left: P + Z,
451
+ right: P + I,
452
+ bottom: 0,
453
+ panelTop: 0,
454
+ panelRight: P,
455
+ panelWidth: I
456
+ };
457
+ }, S = () => {
458
+ const E = w(u.offsetWidth, u.offsetHeight);
459
+ d.dataset.miniAppStageAlign = b ? "top" : "center", Object.assign(d.style, {
460
+ left: `${E.left}px`,
461
+ right: `${E.right}px`,
462
+ bottom: `${E.bottom}px`
463
+ }), Object.assign(h.style, {
464
+ top: `${E.panelTop}px`,
465
+ right: `${E.panelRight}px`,
466
+ width: `${E.panelWidth}px`
459
467
  });
460
- }, x = () => {
461
- const S = A.offsetWidth, R = A.offsetHeight, V = f % 180 !== 0;
462
- h.style.width = `${V ? R : S}px`, h.style.height = `${V ? S : R}px`, A.style.transformOrigin = "0 0";
468
+ }, L = () => {
469
+ const E = A.offsetWidth, k = A.offsetHeight, N = f % 180 !== 0;
470
+ u.style.width = `${N ? k : E}px`, u.style.height = `${N ? E : k}px`, A.style.transformOrigin = "0 0";
463
471
  const Z = {
464
472
  0: "",
465
- [-90]: `translateY(${S}px) rotate(-90deg)`,
466
- [-180]: `translate(${S}px, ${R}px) rotate(-180deg)`,
467
- [-270]: `translateX(${R}px) rotate(-270deg)`
473
+ [-90]: `translateY(${E}px) rotate(-90deg)`,
474
+ [-180]: `translate(${E}px, ${k}px) rotate(-180deg)`,
475
+ [-270]: `translateX(${k}px) rotate(-270deg)`
468
476
  };
469
- A.style.transform = Z[f], y();
477
+ A.style.transform = Z[f], S();
470
478
  };
471
- let q = 0;
472
- const k = new ResizeObserver(() => {
473
- q || (q = requestAnimationFrame(() => {
474
- q = 0, x();
479
+ let V = 0;
480
+ const B = new ResizeObserver(() => {
481
+ V || (V = requestAnimationFrame(() => {
482
+ V = 0, L();
475
483
  }));
476
484
  });
477
- return k.observe(i), k.observe(h), k.observe(A), {
485
+ return B.observe(i), B.observe(u), B.observe(A), {
478
486
  root: n,
479
487
  host: i,
480
488
  shadowRoot: a,
481
489
  bounds: d,
482
- stage: h,
490
+ stage: u,
483
491
  device: A,
484
492
  overlayRoot: a ?? i,
485
- sidePanel: u,
486
- setDesktopControls(S) {
487
- b = S, S || (f = 0), A.dataset.miniAppScreenRotation = String(f), x();
493
+ sidePanel: h,
494
+ getQuarterTurnBounds(E) {
495
+ if (E !== d)
496
+ return { width: E.clientWidth, height: E.clientHeight };
497
+ const k = w(u.offsetHeight, u.offsetWidth);
498
+ return {
499
+ width: Math.max(0, i.clientWidth - k.left - k.right),
500
+ height: Math.max(0, i.clientHeight - k.bottom)
501
+ };
502
+ },
503
+ setDesktopControls(E) {
504
+ b = E, E || (f = 0), A.dataset.miniAppScreenRotation = String(f), L();
488
505
  },
489
- rotateScreen(S) {
490
- b && (f = S === "clockwise" ? f === 0 ? -270 : f + 90 : f === -270 ? 0 : f - 90, A.dataset.miniAppScreenRotation = String(f), x());
506
+ rotateScreen(E) {
507
+ b && (f = E === "clockwise" ? f === 0 ? -270 : f + 90 : f === -270 ? 0 : f - 90, A.dataset.miniAppScreenRotation = String(f), L());
491
508
  },
492
- syncDeviceLayout: x,
493
- setSidePanelWidth(S, R = S) {
494
- const V = S > 0;
495
- m = Math.max(0, S), w = Math.max(m, R), y(), u.dataset.open = String(V), t || (u.style.display = V ? "block" : "none");
509
+ syncDeviceLayout: L,
510
+ setSidePanelWidth(E, k = E) {
511
+ const N = E > 0;
512
+ m = Math.max(0, E), v = Math.max(m, k), S(), h.dataset.open = String(N), t || (h.style.display = N ? "block" : "none");
496
513
  },
497
514
  destroy() {
498
- k.disconnect(), cancelAnimationFrame(q), o(), i.remove(), r && (n.style.position = s);
515
+ B.disconnect(), cancelAnimationFrame(V), o(), i.remove(), r && (n.style.position = s);
499
516
  }
500
517
  };
501
518
  }
@@ -553,11 +570,11 @@ async function Vi(n, e) {
553
570
  a && r.push(Wi(o.id, a));
554
571
  }
555
572
  }
556
- const s = e.scriptNonce ? ` nonce="${e.scriptNonce}"` : "", i = r.length ? `<script${s}>${Li(r.join(`
573
+ const s = e.scriptNonce ? ` nonce="${e.scriptNonce}"` : "", i = r.length ? `<script${s}>${Ii(r.join(`
557
574
  `))}<\/script>` : "";
558
575
  return t.join("") + i;
559
576
  }
560
- const Ii = `var __miniAppSdkConsole = (function(){
577
+ const Li = `var __miniAppSdkConsole = (function(){
561
578
  var mark = ${JSON.stringify(`${En} `)};
562
579
  var levels = ["log","info","warn","error","debug"];
563
580
  var overrides = {};
@@ -578,9 +595,9 @@ const Ii = `var __miniAppSdkConsole = (function(){
578
595
  }
579
596
  });
580
597
  })();`;
581
- function Li(n) {
598
+ function Ii(n) {
582
599
  return `(function(){
583
- ${Ii}
600
+ ${Li}
584
601
  (function(console){
585
602
  ${n}
586
603
  })(__miniAppSdkConsole);
@@ -1020,19 +1037,19 @@ class ds {
1020
1037
  const o = e.toX, a = e.toY;
1021
1038
  if (typeof o != "number" || typeof a != "number" || !Number.isFinite(o) || !Number.isFinite(a))
1022
1039
  throw new Error("swipe 需要有限的 toX 与 toY");
1023
- const l = { x: o, y: a }, d = Math.hypot(l.x - t.x, l.y - t.y), h = Math.max(60, Math.min(5e3, Math.round(e.duration ?? 180))), A = Math.max(
1040
+ const l = { x: o, y: a }, d = Math.hypot(l.x - t.x, l.y - t.y), u = Math.max(60, Math.min(5e3, Math.round(e.duration ?? 180))), A = Math.max(
1024
1041
  3,
1025
- Math.min(300, Math.ceil(Math.max(d / 24, h / 16)))
1042
+ Math.min(300, Math.ceil(Math.max(d / 24, u / 16)))
1026
1043
  );
1027
1044
  s();
1028
- for (let u = 1; u < A; u += 1) {
1029
- const m = u / A, w = this.toHostCoords(
1045
+ for (let h = 1; h < A; h += 1) {
1046
+ const m = h / A, v = this.toHostCoords(
1030
1047
  t.x + (l.x - t.x) * m,
1031
1048
  t.y + (l.y - t.y) * m
1032
1049
  );
1033
- this.onMouseMoveDragging(this.syntheticMouseEvent("mousemove", w.x, w.y, 0, 1)), await an(h / A);
1050
+ this.onMouseMoveDragging(this.syntheticMouseEvent("mousemove", v.x, v.y, 0, 1)), await an(u / A);
1034
1051
  }
1035
- return i(this.toHostCoords(l.x, l.y)), { action: e.action, from: t, to: l, segments: A, durationMs: h };
1052
+ return i(this.toHostCoords(l.x, l.y)), { action: e.action, from: t, to: l, segments: A, durationMs: u };
1036
1053
  }
1037
1054
  }
1038
1055
  } finally {
@@ -1560,6 +1577,7 @@ const Pi = `/* AUTO-GENERATED from receiver-runtime.impl.ts by scripts/gen-recei
1560
1577
  }
1561
1578
  let touchTarget = null;
1562
1579
  let touchFocusedEditable = null;
1580
+ let releasedTouch;
1563
1581
  const touchTargets = /* @__PURE__ */ new Map();
1564
1582
  const activeTouches = /* @__PURE__ */ new Map();
1565
1583
  let lastScrollPoint = null;
@@ -1728,6 +1746,7 @@ const Pi = `/* AUTO-GENERATED from receiver-runtime.impl.ts by scripts/gen-recei
1728
1746
  const firstTouch = changedTouches[0] || touches[0];
1729
1747
  const x = firstTouch ? firstTouch.clientX : 0;
1730
1748
  const y = firstTouch ? firstTouch.clientY : 0;
1749
+ releasedTouch = eventName === "touchend" && !touches.length ? changedTouches[0] : void 0;
1731
1750
  const pointerPrevented = dispatchPointerEvents(eventName, changedTouches, modifiers);
1732
1751
  let touchPrevented = false;
1733
1752
  const targets = new Set(changedTouches.map((point) => point.target));
@@ -1875,7 +1894,10 @@ const Pi = `/* AUTO-GENERATED from receiver-runtime.impl.ts by scripts/gen-recei
1875
1894
  function handleTap(msg) {
1876
1895
  const focusedOnPress = touchFocusedEditable;
1877
1896
  touchFocusedEditable = null;
1878
- if (!msg.point) return;
1897
+ const release = releasedTouch;
1898
+ releasedTouch = void 0;
1899
+ const point = msg.point;
1900
+ if (!point) return;
1879
1901
  const previousClickTarget = lastClickTarget;
1880
1902
  lastClickTarget = null;
1881
1903
  doubleClickTarget = null;
@@ -1883,24 +1905,25 @@ const Pi = `/* AUTO-GENERATED from receiver-runtime.impl.ts by scripts/gen-recei
1883
1905
  suppressSyntheticClick = false;
1884
1906
  return;
1885
1907
  }
1886
- const target = elementAt(msg.point.clientX, msg.point.clientY);
1908
+ const followsRelease = release && release.identifier === (point.identifier ?? 1) && release.clientX === point.clientX && release.clientY === point.clientY;
1909
+ const target = followsRelease ? release.target : elementAt(point.clientX, point.clientY);
1910
+ if (!target?.isConnected) return;
1887
1911
  const selectEl = findSelectTarget(target);
1888
1912
  if (selectEl) {
1889
1913
  openSelectPicker(selectEl);
1890
1914
  return;
1891
1915
  }
1892
- dispatchSyntheticClick(target, msg.point, msg.modifiers || NO_MODIFIERS);
1916
+ dispatchSyntheticClick(target, point, msg.modifiers || NO_MODIFIERS);
1893
1917
  if (findEditableTarget(target) !== focusedOnPress) focusEditableIfNeeded(target);
1894
1918
  lastClickTarget = target;
1895
1919
  if (previousClickTarget === target) doubleClickTarget = target;
1896
1920
  }
1897
1921
  function handleDoubleClick(msg) {
1898
1922
  if (!msg.point) return;
1899
- const target = elementAt(msg.point.clientX, msg.point.clientY);
1900
- const allowed = doubleClickTarget === target;
1923
+ const target = doubleClickTarget;
1901
1924
  lastClickTarget = null;
1902
1925
  doubleClickTarget = null;
1903
- if (!allowed) return;
1926
+ if (!target?.isConnected) return;
1904
1927
  const mods = msg.modifiers || NO_MODIFIERS;
1905
1928
  const init = {
1906
1929
  bubbles: true,
@@ -2158,15 +2181,15 @@ function Oi() {
2158
2181
  install(e) {
2159
2182
  const t = new Yn(e);
2160
2183
  let r = !1, s = { x: 1, y: 0 }, i = null;
2161
- const o = (d, h = e.state.isMultiTouch ? e.state.multiTouchBase : null) => {
2162
- i = h;
2163
- let A = d.iframeX, u = d.iframeY;
2164
- if (h) {
2165
- const m = A - h.iframeX, w = u - h.iframeY, b = Math.hypot(m, w);
2166
- b > 0 && (s = { x: m / b, y: w / b }), b < 8 && (A = h.iframeX + s.x * 8, u = h.iframeY + s.y * 8), t.update(
2184
+ const o = (d, u = e.state.isMultiTouch ? e.state.multiTouchBase : null) => {
2185
+ i = u;
2186
+ let A = d.iframeX, h = d.iframeY;
2187
+ if (u) {
2188
+ const m = A - u.iframeX, v = h - u.iframeY, b = Math.hypot(m, v);
2189
+ b > 0 && (s = { x: m / b, y: v / b }), b < 8 && (A = u.iframeX + s.x * 8, h = u.iframeY + s.y * 8), t.update(
2167
2190
  [
2168
- vt(e.iframe, d, 1, A, u),
2169
- vt(e.iframe, d, 2, 2 * h.iframeX - A, 2 * h.iframeY - u)
2191
+ vt(e.iframe, d, 1, A, h),
2192
+ vt(e.iframe, d, 2, 2 * u.iframeX - A, 2 * u.iframeY - h)
2170
2193
  ],
2171
2194
  d.modifiers
2172
2195
  );
@@ -2207,15 +2230,15 @@ function Gn(n) {
2207
2230
  return {
2208
2231
  name: e,
2209
2232
  install(s) {
2210
- const i = (a, l, d, h) => {
2233
+ const i = (a, l, d, u) => {
2211
2234
  if (s.state.isMultiTouch) return;
2212
2235
  s.state.isMultiTouch = !0, s.state.multiTouchMode = r;
2213
- const A = r === "mirror" ? -75 : d < s.iframe.offsetWidth / 2 ? 100 : -100, u = r === "mirror" ? 75 : 0, m = Math.max(0, Math.min(s.iframe.offsetWidth - 1, d + A)), w = Math.max(0, Math.min(s.iframe.offsetHeight - 1, h + u)), b = (d + m) / 2, f = (h + w) / 2, y = we(s.iframe, b, f);
2236
+ const A = r === "mirror" ? -75 : d < s.iframe.offsetWidth / 2 ? 100 : -100, h = r === "mirror" ? 75 : 0, m = Math.max(0, Math.min(s.iframe.offsetWidth - 1, d + A)), v = Math.max(0, Math.min(s.iframe.offsetHeight - 1, u + h)), b = (d + m) / 2, f = (u + v) / 2, w = we(s.iframe, b, f);
2214
2237
  s.state.multiTouchBase = {
2215
2238
  iframeX: b,
2216
2239
  iframeY: f,
2217
- hostX: y.x,
2218
- hostY: y.y
2240
+ hostX: w.x,
2241
+ hostY: w.y
2219
2242
  }, s.state.pressStartPoint = null, s.emit("multitouch:enter", { mode: r, hostX: a, hostY: l });
2220
2243
  }, o = () => {
2221
2244
  !s.state.isMultiTouch || s.state.multiTouchMode !== r || (s.state.isMultiTouch = !1, s.state.multiTouchMode = null, s.state.multiTouchBase = null, s.emit("multitouch:leave", { mode: r }));
@@ -2380,9 +2403,9 @@ function ro() {
2380
2403
  const t = new Yn(e);
2381
2404
  let r = null, s = null, i = 50, o = 50, a, l = !1;
2382
2405
  const d = (f = !1) => {
2383
- const y = a;
2384
- a = void 0, y?.(), s = null, r && (t.finish(f), r = null, e.state.isMultiTouch = !1, e.state.multiTouchMode = null, e.state.multiTouchBase = null, e.emit("multitouch:leave", { mode: "pinch" }));
2385
- }, h = () => {
2406
+ const w = a;
2407
+ a = void 0, w?.(), s = null, r && (t.finish(f), r = null, e.state.isMultiTouch = !1, e.state.multiTouchMode = null, e.state.multiTouchBase = null, e.emit("multitouch:leave", { mode: "pinch" }));
2408
+ }, u = () => {
2386
2409
  r && t.update(
2387
2410
  [
2388
2411
  vt(e.iframe, r, 1, r.iframeX - i, r.iframeY),
@@ -2390,55 +2413,55 @@ function ro() {
2390
2413
  ],
2391
2414
  dr
2392
2415
  );
2393
- }, A = (f, y) => {
2394
- if (!(e.state.isPressed || !Number.isFinite(y) || y <= 0)) {
2416
+ }, A = (f, w) => {
2417
+ if (!(e.state.isPressed || !Number.isFinite(w) || w <= 0)) {
2395
2418
  if (!r) {
2396
- const x = e.iframe.offsetWidth;
2397
- i = Math.min(50, Math.max(1, (x - 2) / 2));
2398
- const q = Math.max(i + 1, Math.min(x - i - 1, f.iframeX)), k = we(e.iframe, q, f.iframeY), S = we(e.iframe, f.iframeX, f.iframeY);
2419
+ const S = e.iframe.offsetWidth;
2420
+ i = Math.min(50, Math.max(1, (S - 2) / 2));
2421
+ const L = Math.max(i + 1, Math.min(S - i - 1, f.iframeX)), V = we(e.iframe, L, f.iframeY), B = we(e.iframe, f.iframeX, f.iframeY);
2399
2422
  r = {
2400
2423
  ...f,
2401
- iframeX: q,
2402
- hostX: k.x,
2403
- hostY: k.y,
2404
- screenX: f.screenX + k.x - S.x,
2405
- screenY: f.screenY + k.y - S.y
2406
- }, o = Math.max(50, x * 4), e.state.isMultiTouch = !0, e.state.multiTouchMode = "pinch", e.emit("multitouch:enter", { mode: "pinch" }), h();
2424
+ iframeX: L,
2425
+ hostX: V.x,
2426
+ hostY: V.y,
2427
+ screenX: f.screenX + V.x - B.x,
2428
+ screenY: f.screenY + V.y - B.y
2429
+ }, o = Math.max(50, S * 4), e.state.isMultiTouch = !0, e.state.multiTouchMode = "pinch", e.emit("multitouch:enter", { mode: "pinch" }), u();
2407
2430
  }
2408
- i = Math.max(Math.min(8, o), Math.min(o, i * y)), h();
2431
+ i = Math.max(Math.min(8, o), Math.min(o, i * w)), u();
2409
2432
  }
2410
- }, u = (f) => {
2411
- const y = f;
2412
- if (!Number.isFinite(y.scale) || y.scale <= 0 || f.type !== "gesturestart" && !l) return;
2433
+ }, h = (f) => {
2434
+ const w = f;
2435
+ if (!Number.isFinite(w.scale) || w.scale <= 0 || f.type !== "gesturestart" && !l) return;
2413
2436
  f.type === "gesturestart" && (l = !0), f.preventDefault();
2414
- const x = e.iframe.getBoundingClientRect(), q = y.clientX ?? x.left + x.width / 2, k = y.clientY ?? x.top + x.height / 2, S = Pe(e.iframe, q, k), R = {
2437
+ const S = e.iframe.getBoundingClientRect(), L = w.clientX ?? S.left + S.width / 2, V = w.clientY ?? S.top + S.height / 2, B = Pe(e.iframe, L, V), E = {
2415
2438
  kind: "wheel",
2416
- hostX: q,
2417
- hostY: k,
2418
- iframeX: S.x,
2419
- iframeY: S.y,
2420
- screenX: y.screenX ?? window.screenX + q,
2421
- screenY: y.screenY ?? window.screenY + k,
2439
+ hostX: L,
2440
+ hostY: V,
2441
+ iframeX: B.x,
2442
+ iframeY: B.y,
2443
+ screenX: w.screenX ?? window.screenX + L,
2444
+ screenY: w.screenY ?? window.screenY + V,
2422
2445
  modifiers: dr,
2423
2446
  button: 0,
2424
2447
  timestamp: performance.now(),
2425
2448
  raw: null
2426
- }, V = y.scale, Z = f.type === "gesturestart";
2449
+ }, k = w.scale, N = f.type === "gesturestart";
2427
2450
  e.orderInput(() => {
2428
- e.state.isPressed || (Z && d(), a?.(), a = void 0, A(R, V / (s ?? V)), s = V);
2429
- }, performance.timeOrigin + R.timestamp);
2451
+ e.state.isPressed || (N && d(), a?.(), a = void 0, A(E, k / (s ?? k)), s = k);
2452
+ }, performance.timeOrigin + E.timestamp);
2430
2453
  }, m = (f) => {
2431
2454
  l && (l = !1, f.preventDefault(), e.orderInput(() => d(), void 0, { cleanupOnly: !0 }));
2432
- }, w = () => {
2455
+ }, v = () => {
2433
2456
  e.orderInput(() => {
2434
2457
  e.state.isPressed || d(!0);
2435
2458
  });
2436
2459
  };
2437
- e.overlay.addEventListener("gesturestart", u, {
2460
+ e.overlay.addEventListener("gesturestart", h, {
2438
2461
  passive: !1
2439
- }), window.addEventListener("gesturechange", u, {
2462
+ }), window.addEventListener("gesturechange", h, {
2440
2463
  passive: !1
2441
- }), window.addEventListener("gestureend", m, { passive: !1 }), e.overlay.addEventListener("mouseleave", w);
2464
+ }), window.addEventListener("gestureend", m, { passive: !1 }), e.overlay.addEventListener("mouseleave", v);
2442
2465
  const b = [
2443
2466
  // 必须先于鼠标模式插件注册:新鼠标序列开始前抬起滚轮触点。
2444
2467
  e.on("down", () => d()),
@@ -2454,8 +2477,8 @@ function ro() {
2454
2477
  return;
2455
2478
  }
2456
2479
  if (s !== null) return;
2457
- const y = f.wheelDeltaMode === 1 ? 16 : f.wheelDeltaMode === 2 ? e.iframe.offsetHeight : 1, q = ((f.raw?.type === "wheel" ? f.raw : void 0)?.deltaY ?? f.wheelDeltaY ?? 0) * y;
2458
- !Number.isFinite(q) || q === 0 || (A(f, Math.exp(-Math.max(-100, Math.min(100, q)) * no)), a?.(), a = e.scheduleInput(() => d(), e.inputTime() + to, {
2480
+ const w = f.wheelDeltaMode === 1 ? 16 : f.wheelDeltaMode === 2 ? e.iframe.offsetHeight : 1, L = ((f.raw?.type === "wheel" ? f.raw : void 0)?.deltaY ?? f.wheelDeltaY ?? 0) * w;
2481
+ !Number.isFinite(L) || L === 0 || (A(f, Math.exp(-Math.max(-100, Math.min(100, L)) * no)), a?.(), a = e.scheduleInput(() => d(), e.inputTime() + to, {
2459
2482
  cleanupOnly: !0
2460
2483
  }));
2461
2484
  },
@@ -2467,7 +2490,7 @@ function ro() {
2467
2490
  n = () => {
2468
2491
  l = !1, d(!0);
2469
2492
  for (const f of b) f();
2470
- e.overlay.removeEventListener("gesturestart", u), window.removeEventListener("gesturechange", u), window.removeEventListener("gestureend", m), e.overlay.removeEventListener("mouseleave", w);
2493
+ e.overlay.removeEventListener("gesturestart", h), window.removeEventListener("gesturechange", h), window.removeEventListener("gestureend", m), e.overlay.removeEventListener("mouseleave", v);
2471
2494
  };
2472
2495
  },
2473
2496
  uninstall() {
@@ -2558,7 +2581,7 @@ const us = `
2558
2581
  [data-mini-app-keyboard-ui] [data-mini-app-keyboard-panel] small {flex:1;color:#a6b4c9;font-size:11px}
2559
2582
  [data-mini-app-keyboard-ui] [data-mini-app-keyboard-panel] p {margin:8px 0;color:#c2cddd;font-size:12px}
2560
2583
  [data-mini-app-keyboard-ui] [data-mapping-notice] {padding:8px;background:#253650;border-radius:6px}
2561
- `, de = 12, ao = 16;
2584
+ `, ue = 12, ao = 16;
2562
2585
  function Tt(n) {
2563
2586
  return {
2564
2587
  ArrowUp: "↑",
@@ -2575,110 +2598,110 @@ function lo(n) {
2575
2598
  o.textContent = us;
2576
2599
  const a = s.createElement("div");
2577
2600
  a.setAttribute("data-mini-app-keyboard-panel", ""), a.setAttribute("role", "dialog"), a.setAttribute("aria-label", "键位映射"), a.hidden = !0;
2578
- let l, d = !1, h = null, A = null;
2579
- const u = /* @__PURE__ */ new Set(), m = /* @__PURE__ */ new Map();
2580
- let w = 0, b, f = 0, y;
2581
- const x = (p = i.performance.timeOrigin + i.performance.now()) => ({
2601
+ let l, d = !1, u = null, A = null;
2602
+ const h = /* @__PURE__ */ new Set(), m = /* @__PURE__ */ new Map();
2603
+ let v = 0, b, f = 0, w;
2604
+ const S = (p = i.performance.timeOrigin + i.performance.now()) => ({
2582
2605
  issuedAt: p,
2583
2606
  sequence: ++f
2584
- }), q = () => {
2585
- i.cancelAnimationFrame(w), i.clearTimeout(b), w = 0, b = void 0;
2586
- }, k = () => {
2587
- const p = /* @__PURE__ */ new Set([...u, ...m.keys()]);
2588
- u.clear(), m.clear(), q();
2589
- for (const I of p)
2590
- t({ type: "key", eventName: "cancel", code: I, repeat: !1, ...x() });
2591
- }, S = () => {
2607
+ }), L = () => {
2608
+ i.cancelAnimationFrame(v), i.clearTimeout(b), v = 0, b = void 0;
2609
+ }, V = () => {
2610
+ const p = /* @__PURE__ */ new Set([...h, ...m.keys()]);
2611
+ h.clear(), m.clear(), L();
2612
+ for (const W of p)
2613
+ t({ type: "key", eventName: "cancel", code: W, repeat: !1, ...S() });
2614
+ }, B = () => {
2592
2615
  const p = i.performance.timeOrigin + i.performance.now();
2593
- for (const E of u) m.set(E, p);
2594
- if (u.clear(), w || !m.size) return;
2595
- const I = () => {
2596
- q();
2597
- const E = [...m];
2616
+ for (const x of h) m.set(x, p);
2617
+ if (h.clear(), v || !m.size) return;
2618
+ const W = () => {
2619
+ L();
2620
+ const x = [...m];
2598
2621
  m.clear();
2599
- for (const [G, J] of E)
2600
- t({ type: "key", eventName: "focusout", code: G, repeat: !1, ...x(J) });
2622
+ for (const [H, J] of x)
2623
+ t({ type: "key", eventName: "focusout", code: H, repeat: !1, ...S(J) });
2601
2624
  };
2602
- w = i.requestAnimationFrame(I), b = i.setTimeout(I, 50);
2603
- }, R = /* @__PURE__ */ new Map(), V = /* @__PURE__ */ new WeakMap(), Z = /* @__PURE__ */ new WeakMap(), Y = (p) => {
2625
+ v = i.requestAnimationFrame(W), b = i.setTimeout(W, 50);
2626
+ }, E = /* @__PURE__ */ new Map(), k = /* @__PURE__ */ new WeakMap(), N = /* @__PURE__ */ new WeakMap(), Z = (p) => {
2604
2627
  !d && l?.available && l.open && t(p);
2605
- }, Q = (p, I) => {
2606
- const E = s.createElement("button");
2607
- return E.type = "button", E.textContent = p, V.set(E, I), E;
2628
+ }, G = (p, W) => {
2629
+ const x = s.createElement("button");
2630
+ return x.type = "button", x.textContent = p, k.set(x, W), x;
2608
2631
  }, $ = s.createElement("div");
2609
2632
  $.setAttribute("data-mini-app-keyboard-panel-handle", "");
2610
- const X = s.createElement("label");
2611
- X.style.cssText = "display:flex;gap:6px;align-items:center;margin:0;font-weight:600;white-space:nowrap;cursor:pointer";
2612
- const P = s.createElement("input");
2613
- P.type = "checkbox", X.append(P, s.createTextNode("启用按键映射"));
2614
- const M = s.createElement("span");
2615
- M.textContent = "拖动移动";
2616
- const fe = Q("×", { type: "close" });
2617
- fe.setAttribute("aria-label", "关闭按键映射"), $.append(X, M, fe);
2618
- const ne = s.createElement("p");
2619
- ne.textContent = "选择画面中的区域,再按一个键绑定。各按键可同时按住、分别松开,鼠标也可同时操作。";
2620
- const re = s.createElement("div"), C = Q("添加映射", { type: "add" }), W = Q("取消选择", { type: "cancel" }), N = s.createElement("p");
2621
- N.setAttribute("role", "status"), N.setAttribute("data-mapping-notice", ""), a.append($, ne, re, C, W, N), e.append(o, a);
2633
+ const D = s.createElement("label");
2634
+ D.style.cssText = "display:flex;gap:6px;align-items:center;margin:0;font-weight:600;white-space:nowrap;cursor:pointer";
2635
+ const I = s.createElement("input");
2636
+ I.type = "checkbox", D.append(I, s.createTextNode("启用按键映射"));
2637
+ const P = s.createElement("span");
2638
+ P.textContent = "拖动移动";
2639
+ const de = G("×", { type: "close" });
2640
+ de.setAttribute("aria-label", "关闭按键映射"), $.append(D, P, de);
2641
+ const te = s.createElement("p");
2642
+ te.textContent = "选择画面中的区域,再按一个键绑定。各按键可同时按住、分别松开,鼠标也可同时操作。";
2643
+ const re = s.createElement("div"), C = G("添加映射", { type: "add" }), T = G("取消选择", { type: "cancel" }), M = s.createElement("p");
2644
+ M.setAttribute("role", "status"), M.setAttribute("data-mapping-notice", ""), a.append($, te, re, C, T, M), e.append(o, a);
2622
2645
  const se = (p) => {
2623
- const I = s.createElement("div");
2624
- I.setAttribute("data-key-code", p);
2625
- const E = Q(Tt(p), { type: "rebind", code: p });
2626
- E.setAttribute("data-key-label", ""), E.setAttribute("aria-label", `更换 ${Tt(p)} 按键`);
2627
- const G = s.createElement("small"), J = Q("重选区域", { type: "pick", code: p }), Te = Q("删除", { type: "remove", code: p });
2646
+ const W = s.createElement("div");
2647
+ W.setAttribute("data-key-code", p);
2648
+ const x = G(Tt(p), { type: "rebind", code: p });
2649
+ x.setAttribute("data-key-label", ""), x.setAttribute("aria-label", `更换 ${Tt(p)} 按键`);
2650
+ const H = s.createElement("small"), J = G("重选区域", { type: "pick", code: p }), Te = G("删除", { type: "remove", code: p });
2628
2651
  Te.setAttribute("aria-label", `删除 ${Tt(p)} 映射`);
2629
2652
  const Ee = s.createElement("select");
2630
2653
  Ee.setAttribute("aria-label", `操作方式 ${Tt(p)}`);
2631
- for (const [pe, qt] of [
2654
+ for (const [Ae, qt] of [
2632
2655
  ["hold", "按住区域"],
2633
2656
  ["drag", "拖动并保持"]
2634
2657
  ]) {
2635
2658
  const Qe = s.createElement("option");
2636
- Qe.value = pe, Qe.textContent = qt, Ee.appendChild(Qe);
2637
- }
2638
- Z.set(Ee, p);
2639
- const xe = Q("选终点", { type: "destination", code: p });
2640
- return I.append(E, G, J, Te, Ee, xe), { element: I, status: G, mode: Ee, destination: xe };
2641
- }, qe = (p, I, E) => ({
2642
- x: Math.max(de, Math.min(p.x, i.innerWidth - I - de)),
2643
- y: Math.max(de, Math.min(p.y, i.innerHeight - E - de))
2659
+ Qe.value = Ae, Qe.textContent = qt, Ee.appendChild(Qe);
2660
+ }
2661
+ N.set(Ee, p);
2662
+ const xe = G("选终点", { type: "destination", code: p });
2663
+ return W.append(x, H, J, Te, Ee, xe), { element: W, status: H, mode: Ee, destination: xe };
2664
+ }, qe = (p, W, x) => ({
2665
+ x: Math.max(ue, Math.min(p.x, i.innerWidth - W - ue)),
2666
+ y: Math.max(ue, Math.min(p.y, i.innerHeight - x - ue))
2644
2667
  }), ge = () => {
2645
2668
  if (d || a.hidden) return;
2646
- a.style.maxHeight = `${Math.max(0, i.innerHeight - de * 2)}px`;
2647
- const p = a.offsetWidth, I = a.offsetHeight;
2648
- let E = h;
2649
- if (!E) {
2650
- const J = r(), Te = J.right + de + p <= i.innerWidth - de, Ee = J.left - de - p >= de;
2651
- E = qe(
2669
+ a.style.maxHeight = `${Math.max(0, i.innerHeight - ue * 2)}px`;
2670
+ const p = a.offsetWidth, W = a.offsetHeight;
2671
+ let x = u;
2672
+ if (!x) {
2673
+ const J = r(), Te = J.right + ue + p <= i.innerWidth - ue, Ee = J.left - ue - p >= ue;
2674
+ x = qe(
2652
2675
  {
2653
- x: Te ? J.right + de : Ee ? J.left - de - p : i.innerWidth - p - de,
2676
+ x: Te ? J.right + ue : Ee ? J.left - ue - p : i.innerWidth - p - ue,
2654
2677
  y: J.top
2655
2678
  },
2656
2679
  p,
2657
- I
2680
+ W
2658
2681
  );
2659
2682
  const xe = e.querySelector("[data-mini-app-desktop-toolbar]");
2660
2683
  if (xe && !xe.hidden) {
2661
- const pe = xe.getBoundingClientRect();
2662
- E.x < pe.right && E.x + p > pe.left && E.y < pe.bottom && E.y + I > pe.top && (E = { x: E.x, y: pe.bottom + de });
2684
+ const Ae = xe.getBoundingClientRect();
2685
+ x.x < Ae.right && x.x + p > Ae.left && x.y < Ae.bottom && x.y + W > Ae.top && (x = { x: x.x, y: Ae.bottom + ue });
2663
2686
  }
2664
2687
  }
2665
- const G = qe(E, p, I);
2666
- h && (h = G), a.style.left = `${G.x}px`, a.style.top = `${G.y}px`;
2688
+ const H = qe(x, p, W);
2689
+ u && (u = H), a.style.left = `${H.x}px`, a.style.top = `${H.y}px`;
2667
2690
  }, Be = () => {
2668
2691
  if (!A) return;
2669
2692
  const { pointerId: p } = A;
2670
2693
  A = null, a.hasPointerCapture(p) && a.releasePointerCapture(p);
2671
2694
  }, Ue = (p) => {
2672
- const I = p.target;
2673
- if (p.button !== 0 || I?.nodeType !== 1 || !$.contains(I) || I.closest("button,input,label,select,textarea,[contenteditable]"))
2695
+ const W = p.target;
2696
+ if (p.button !== 0 || W?.nodeType !== 1 || !$.contains(W) || W.closest("button,input,label,select,textarea,[contenteditable]"))
2674
2697
  return;
2675
- const E = a.getBoundingClientRect();
2698
+ const x = a.getBoundingClientRect();
2676
2699
  A = {
2677
2700
  pointerId: p.pointerId,
2678
2701
  x: p.clientX,
2679
2702
  y: p.clientY,
2680
- left: E.left,
2681
- top: E.top
2703
+ left: x.left,
2704
+ top: x.top
2682
2705
  };
2683
2706
  try {
2684
2707
  a.setPointerCapture(p.pointerId);
@@ -2688,69 +2711,69 @@ function lo(n) {
2688
2711
  }
2689
2712
  p.preventDefault();
2690
2713
  }, Ce = (p) => {
2691
- !A || p.pointerId !== A.pointerId || (h = {
2714
+ !A || p.pointerId !== A.pointerId || (u = {
2692
2715
  x: A.left + p.clientX - A.x,
2693
2716
  y: A.top + p.clientY - A.y
2694
2717
  }, ge(), p.preventDefault());
2695
2718
  }, z = (p) => {
2696
2719
  A?.pointerId === p.pointerId && Be();
2697
2720
  }, Se = () => {
2698
- Be(), S();
2721
+ Be(), B();
2699
2722
  }, it = () => {
2700
- s.hidden && (Be(), k());
2701
- }, Ye = (p, I) => {
2723
+ s.hidden && (Be(), V());
2724
+ }, Ye = (p, W) => {
2702
2725
  if (!p || !("nodeType" in p) || p.nodeType !== 1) return !1;
2703
- const E = p;
2704
- if (E.isContentEditable || E.closest("textarea,select,[contenteditable]"))
2726
+ const x = p;
2727
+ if (x.isContentEditable || x.closest("textarea,select,[contenteditable]"))
2705
2728
  return !0;
2706
- const G = E.closest("input");
2707
- return G && !/^(checkbox|radio|button|submit|reset)$/.test(G.type) ? !0 : I === "Space" && !!E.closest("button,input");
2729
+ const H = x.closest("input");
2730
+ return H && !/^(checkbox|radio|button|submit|reset)$/.test(H.type) ? !0 : W === "Space" && !!x.closest("button,input");
2708
2731
  }, j = (p) => {
2709
- !l?.available || !l.open || l.busy || !P.checked || p.isComposing || p.ctrlKey || p.metaKey || p.altKey || p.shiftKey || Ye(p.target, p.code) || !l.bindings.some((I) => I.code === p.code) || p.repeat && !u.has(p.code) || (p.preventDefault(), p.stopPropagation(), m.delete(p.code), u.add(p.code), Y({ type: "key", eventName: "keydown", code: p.code, repeat: p.repeat, ...x() }));
2732
+ !l?.available || !l.open || l.busy || !I.checked || p.isComposing || p.ctrlKey || p.metaKey || p.altKey || p.shiftKey || Ye(p.target, p.code) || !l.bindings.some((W) => W.code === p.code) || p.repeat && !h.has(p.code) || (p.preventDefault(), p.stopPropagation(), m.delete(p.code), h.add(p.code), Z({ type: "key", eventName: "keydown", code: p.code, repeat: p.repeat, ...S() }));
2710
2733
  }, Ge = (p) => {
2711
- const I = u.delete(p.code), E = m.delete(p.code);
2712
- !I && !E || (p.preventDefault(), p.stopPropagation(), Y({ type: "key", eventName: "keyup", code: p.code, repeat: !1, ...x() }));
2713
- }, H = (p) => {
2714
- const I = p.relatedTarget;
2715
- (!I || !("nodeType" in I) || !a.contains(I) || Ye(I)) && S();
2734
+ const W = h.delete(p.code), x = m.delete(p.code);
2735
+ !W && !x || (p.preventDefault(), p.stopPropagation(), Z({ type: "key", eventName: "keyup", code: p.code, repeat: !1, ...S() }));
2736
+ }, Q = (p) => {
2737
+ const W = p.relatedTarget;
2738
+ (!W || !("nodeType" in W) || !a.contains(W) || Ye(W)) && B();
2716
2739
  }, ot = (p) => {
2717
- const I = p.target;
2718
- if (I?.nodeType !== 1) return;
2719
- const E = I.closest("button");
2720
- if (!E || E.disabled) return;
2721
- const G = V.get(E);
2722
- G && (k(), Y(G));
2740
+ const W = p.target;
2741
+ if (W?.nodeType !== 1) return;
2742
+ const x = W.closest("button");
2743
+ if (!x || x.disabled) return;
2744
+ const H = k.get(x);
2745
+ H && (V(), Z(H));
2723
2746
  }, He = (p) => {
2724
- if (p.target === P) {
2725
- const G = P.checked;
2726
- y = G, P.focus({ preventScroll: !0 }), k(), Y({ type: "enable", enabled: G, ...x() });
2747
+ if (p.target === I) {
2748
+ const H = I.checked;
2749
+ w = H, I.focus({ preventScroll: !0 }), V(), Z({ type: "enable", enabled: H, ...S() });
2727
2750
  return;
2728
2751
  }
2729
- const I = p.target, E = Z.get(I);
2730
- E && (I.value === "hold" || I.value === "drag") && (k(), Y({ type: "mode", code: E, mode: I.value }));
2752
+ const W = p.target, x = N.get(W);
2753
+ x && (W.value === "hold" || W.value === "drag") && (V(), Z({ type: "mode", code: x, mode: W.value }));
2731
2754
  }, at = (p) => p.stopPropagation();
2732
- a.addEventListener("keydown", j), a.addEventListener("focusout", H), i.addEventListener("keyup", Ge, !0), a.addEventListener("click", ot), a.addEventListener("change", He), a.addEventListener("pointerdown", Ue), a.addEventListener("pointermove", Ce), a.addEventListener("pointerup", z), a.addEventListener("pointercancel", z), a.addEventListener("lostpointercapture", z);
2755
+ a.addEventListener("keydown", j), a.addEventListener("focusout", Q), i.addEventListener("keyup", Ge, !0), a.addEventListener("click", ot), a.addEventListener("change", He), a.addEventListener("pointerdown", Ue), a.addEventListener("pointermove", Ce), a.addEventListener("pointerup", z), a.addEventListener("pointercancel", z), a.addEventListener("lostpointercapture", z);
2733
2756
  for (const p of ["pointerdown", "mousedown", "click", "wheel"])
2734
2757
  a.addEventListener(p, at);
2735
2758
  return i.addEventListener("resize", ge), i.addEventListener("blur", Se), s.addEventListener("scroll", ge, !0), s.addEventListener("visibilitychange", it), {
2736
2759
  update(p) {
2737
2760
  if (d) return;
2738
2761
  l = p, a.hidden = !p.open || !p.available, a.hidden && Be();
2739
- const I = new Set(p.bindings.map((E) => E.code));
2740
- y === p.enabled && (y = void 0), P.checked = y ?? p.enabled, (a.hidden || p.busy || !P.checked || [...u].some((E) => !I.has(E))) && k();
2741
- for (const [E, G] of R)
2742
- I.has(E) || (G.element.remove(), R.delete(E));
2743
- p.bindings.forEach((E, G) => {
2744
- let J = R.get(E.code);
2745
- J || (J = se(E.code), R.set(E.code, J)), J.status.textContent = E.isRegion ? "区域中心" : "指定位置", J.mode.value !== E.mode && (J.mode.value = E.mode), J.destination.hidden = E.mode !== "drag", re.children[G] !== J.element && re.insertBefore(J.element, re.children[G] ?? null);
2746
- }), C.disabled = p.busy || p.bindings.length >= ao, W.hidden = !p.busy, N.textContent = p.notice || "短按可点击,按住保持触点。方向盘、摇杆可选择“拖动并保持”。界面布局变化后请检查映射区域。", ge();
2762
+ const W = new Set(p.bindings.map((x) => x.code));
2763
+ w === p.enabled && (w = void 0), I.checked = w ?? p.enabled, (a.hidden || p.busy || !I.checked || [...h].some((x) => !W.has(x))) && V();
2764
+ for (const [x, H] of E)
2765
+ W.has(x) || (H.element.remove(), E.delete(x));
2766
+ p.bindings.forEach((x, H) => {
2767
+ let J = E.get(x.code);
2768
+ J || (J = se(x.code), E.set(x.code, J)), J.status.textContent = x.isRegion ? "区域中心" : "指定位置", J.mode.value !== x.mode && (J.mode.value = x.mode), J.destination.hidden = x.mode !== "drag", re.children[H] !== J.element && re.insertBefore(J.element, re.children[H] ?? null);
2769
+ }), C.disabled = p.busy || p.bindings.length >= ao, T.hidden = !p.busy, M.textContent = p.notice || "短按可点击,按住保持触点。方向盘、摇杆可选择“拖动并保持”。界面布局变化后请检查映射区域。", ge();
2747
2770
  },
2748
2771
  dispose() {
2749
2772
  if (!d) {
2750
- k(), d = !0, Be(), a.removeEventListener("keydown", j), a.removeEventListener("focusout", H), i.removeEventListener("keyup", Ge, !0), a.removeEventListener("click", ot), a.removeEventListener("change", He), a.removeEventListener("pointerdown", Ue), a.removeEventListener("pointermove", Ce), a.removeEventListener("pointerup", z), a.removeEventListener("pointercancel", z), a.removeEventListener("lostpointercapture", z);
2773
+ V(), d = !0, Be(), a.removeEventListener("keydown", j), a.removeEventListener("focusout", Q), i.removeEventListener("keyup", Ge, !0), a.removeEventListener("click", ot), a.removeEventListener("change", He), a.removeEventListener("pointerdown", Ue), a.removeEventListener("pointermove", Ce), a.removeEventListener("pointerup", z), a.removeEventListener("pointercancel", z), a.removeEventListener("lostpointercapture", z);
2751
2774
  for (const p of ["pointerdown", "mousedown", "click", "wheel"])
2752
2775
  a.removeEventListener(p, at);
2753
- i.removeEventListener("resize", ge), i.removeEventListener("blur", Se), s.removeEventListener("scroll", ge, !0), s.removeEventListener("visibilitychange", it), R.clear(), a.remove(), o.remove();
2776
+ i.removeEventListener("resize", ge), i.removeEventListener("blur", Se), s.removeEventListener("scroll", ge, !0), s.removeEventListener("visibilitychange", it), E.clear(), a.remove(), o.remove();
2754
2777
  }
2755
2778
  }
2756
2779
  };
@@ -2797,45 +2820,45 @@ function ho(n) {
2797
2820
  install(t) {
2798
2821
  const r = new Yn(t), s = [], i = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Map();
2799
2822
  let l = 0;
2800
- const d = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new Map(), A = /* @__PURE__ */ new Map(), u = /* @__PURE__ */ new Map();
2801
- let m = 100, w = !1, b = !0, f = !1, y = !1, x = null, q = null, k = null, S = !1, R = null, V = "", Z = 0, Y = 0, Q = { issuedAt: 0, sequence: 0, source: "host" };
2802
- const $ = () => t.inputTime(), X = () => ({
2823
+ const d = /* @__PURE__ */ new Map(), u = /* @__PURE__ */ new Map(), A = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new Map();
2824
+ let m = 100, v = !1, b = !0, f = !1, w = !1, S = null, L = null, V = null, B = !1, E = null, k = "", N = 0, Z = 0, G = { issuedAt: 0, sequence: 0, source: "host" };
2825
+ const $ = () => t.inputTime(), D = () => ({
2803
2826
  issuedAt: $(),
2804
- sequence: ++Z,
2827
+ sequence: ++N,
2805
2828
  source: "host"
2806
- }), P = (c, g, L = $()) => {
2807
- const K = l, F = a.get(c) ?? 0;
2829
+ }), I = (c, g, q = $()) => {
2830
+ const X = l, K = a.get(c) ?? 0;
2808
2831
  t.orderInput(() => {
2809
- K === l && F === (a.get(c) ?? 0) && g();
2810
- }, L);
2811
- }, M = document.createElement("div");
2812
- M.setAttribute("data-mini-app-keyboard-ui", ""), M.style.cssText = "position:absolute;z-index:2147483000;cursor:default;font:12px/1.5 system-ui,sans-serif;color:#e5e7eb;box-sizing:border-box";
2813
- const fe = document.createElement("style");
2814
- fe.textContent = us;
2815
- const ne = document.createElement("div");
2816
- ne.setAttribute("data-mini-app-desktop-toolbar", ""), ne.style.cssText = "display:flex;gap:6px;white-space:nowrap;width:max-content";
2832
+ X === l && K === (a.get(c) ?? 0) && g();
2833
+ }, q);
2834
+ }, P = document.createElement("div");
2835
+ P.setAttribute("data-mini-app-keyboard-ui", ""), P.style.cssText = "position:absolute;z-index:2147483000;cursor:default;font:12px/1.5 system-ui,sans-serif;color:#e5e7eb;box-sizing:border-box";
2836
+ const de = document.createElement("style");
2837
+ de.textContent = us;
2838
+ const te = document.createElement("div");
2839
+ te.setAttribute("data-mini-app-desktop-toolbar", ""), te.style.cssText = "display:flex;gap:6px;white-space:nowrap;width:max-content";
2817
2840
  const re = document.createElement("button");
2818
2841
  re.type = "button", re.setAttribute("data-mini-app-keyboard-toggle", ""), re.setAttribute("aria-label", "键位映射");
2819
2842
  const C = document.createElement("button");
2820
2843
  C.type = "button", C.setAttribute("data-mini-app-rotate", ""), C.textContent = "逆时针旋转 90°", C.setAttribute("aria-label", "逆时针旋转 90°"), C.title = "将整台手机逆时针旋转 90°", C.hidden = !t.rotateScreen;
2821
- const W = document.createElement("button");
2822
- W.type = "button", W.setAttribute("data-mini-app-rotate-clockwise", ""), W.textContent = "顺时针旋转 90°", W.setAttribute("aria-label", "顺时针旋转 90°"), W.title = "将整台手机顺时针旋转 90°", W.hidden = !t.rotateScreen, ne.append(re, C, W), M.append(fe, ne), document.body.appendChild(M);
2823
- const N = document.createElement("div");
2824
- N.style.cssText = "position:absolute;inset:0;pointer-events:none;z-index:4", t.overlay.appendChild(N);
2844
+ const T = document.createElement("button");
2845
+ T.type = "button", T.setAttribute("data-mini-app-rotate-clockwise", ""), T.textContent = "顺时针旋转 90°", T.setAttribute("aria-label", "顺时针旋转 90°"), T.title = "将整台手机顺时针旋转 90°", T.hidden = !t.rotateScreen, te.append(re, C, T), P.append(de, te), document.body.appendChild(P);
2846
+ const M = document.createElement("div");
2847
+ M.style.cssText = "position:absolute;inset:0;pointer-events:none;z-index:4", t.overlay.appendChild(M);
2825
2848
  let se = t.iframe;
2826
2849
  for (; se && !se.hasAttribute("data-mini-app-device"); )
2827
2850
  se = hr(se);
2828
2851
  let qe;
2829
2852
  const ge = () => {
2830
- const c = (se ?? t.iframe).getBoundingClientRect(), g = c.width > c.height, L = 12;
2831
- ne.style.flexDirection = g ? "row" : "column";
2832
- const K = !se && c.left < ne.offsetWidth + L, F = g ? c.left + (c.width - ne.offsetWidth) / 2 : K ? c.right + L : c.left - ne.offsetWidth - L, O = g ? c.bottom + L : K ? c.top : c.top + (c.height - ne.offsetHeight) / 2;
2833
- M.style.left = `${F + window.scrollX}px`, M.style.top = `${O + window.scrollY}px`, qe?.update({
2834
- open: y,
2853
+ const c = (se ?? t.iframe).getBoundingClientRect(), g = c.width > c.height, q = 12;
2854
+ te.style.flexDirection = g ? "row" : "column";
2855
+ const X = !se && c.left < te.offsetWidth + q, K = g ? c.left + (c.width - te.offsetWidth) / 2 : X ? c.right + q : c.left - te.offsetWidth - q, O = g ? c.bottom + q : X ? c.top : c.top + (c.height - te.offsetHeight) / 2;
2856
+ P.style.left = `${K + window.scrollX}px`, P.style.top = `${O + window.scrollY}px`, qe?.update({
2857
+ open: w,
2835
2858
  available: b,
2836
- enabled: w,
2837
- busy: !!x || S,
2838
- notice: V,
2859
+ enabled: v,
2860
+ busy: !!S || B,
2861
+ notice: k,
2839
2862
  bindings: s.map((ee) => ({
2840
2863
  code: ee.code,
2841
2864
  mode: ee.mode,
@@ -2846,96 +2869,96 @@ function ho(n) {
2846
2869
  });
2847
2870
  }, Be = () => t.send({
2848
2871
  type: "mini-app:keyboard-capture",
2849
- codes: w && b && !x && !S ? s.filter((c) => c.mode === "hold" || c.destination).map((c) => c.code) : []
2850
- }), Ue = (c, g, L, K) => {
2851
- const F = document.createElement("div");
2852
- F.style.cssText = `position:absolute;left:${c.x * 100}%;top:${c.y * 100}%;width:${c.width * 100}%;height:${c.height * 100}%;box-sizing:border-box;border:1px dashed ${L ? "#fb923c" : "#93c5fd"};background:${L ? "#fb923c28" : "#60a5fa18"}`, K && F.setAttribute("data-key-touch-region", K);
2872
+ codes: v && b && !S && !B ? s.filter((c) => c.mode === "hold" || c.destination).map((c) => c.code) : []
2873
+ }), Ue = (c, g, q, X) => {
2874
+ const K = document.createElement("div");
2875
+ K.style.cssText = `position:absolute;left:${c.x * 100}%;top:${c.y * 100}%;width:${c.width * 100}%;height:${c.height * 100}%;box-sizing:border-box;border:1px dashed ${q ? "#fb923c" : "#93c5fd"};background:${q ? "#fb923c28" : "#60a5fa18"}`, X && K.setAttribute("data-key-touch-region", X);
2853
2876
  const O = document.createElement("span");
2854
- O.textContent = g, K && O.setAttribute("data-key-touch-marker", K), O.setAttribute("data-pressed", String(L)), O.style.cssText = `position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);display:grid;place-items:center;white-space:nowrap;min-width:26px;height:26px;padding:0 3px;box-sizing:border-box;border:2px solid #fff;border-radius:50%;font:600 12px system-ui;color:white;background:${L ? "#ea580c" : "#334155b3"};box-shadow:0 1px 5px #0006`, F.appendChild(O), N.appendChild(F);
2877
+ O.textContent = g, X && O.setAttribute("data-key-touch-marker", X), O.setAttribute("data-pressed", String(q)), O.style.cssText = `position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);display:grid;place-items:center;white-space:nowrap;min-width:26px;height:26px;padding:0 3px;box-sizing:border-box;border:2px solid #fff;border-radius:50%;font:600 12px system-ui;color:white;background:${q ? "#ea580c" : "#334155b3"};box-shadow:0 1px 5px #0006`, K.appendChild(O), M.appendChild(K);
2855
2878
  }, Ce = () => {
2856
- if (N.replaceChildren(), !(!b || !w && !y)) {
2879
+ if (M.replaceChildren(), !(!b || !v && !w)) {
2857
2880
  for (const c of s) {
2858
- const g = Ft(c.region), L = s.filter((K) => {
2859
- const F = Ft(K.region);
2860
- return Math.abs(F.x - g.x) < 1e-4 && Math.abs(F.y - g.y) < 1e-4;
2881
+ const g = Ft(c.region), q = s.filter((X) => {
2882
+ const K = Ft(X.region);
2883
+ return Math.abs(K.x - g.x) < 1e-4 && Math.abs(K.y - g.y) < 1e-4;
2861
2884
  });
2862
2885
  if (Ue(
2863
2886
  c.region,
2864
- L.map((K) => ln(K.code)).join("/"),
2865
- L.some((K) => i.has(K.code)),
2887
+ q.map((X) => ln(X.code)).join("/"),
2888
+ q.some((X) => i.has(X.code)),
2866
2889
  c.code
2867
2890
  ), c.mode === "drag" && c.destination) {
2868
- const K = Ft(c.region), F = document.createElementNS("http://www.w3.org/2000/svg", "svg");
2869
- F.setAttribute("viewBox", "0 0 100 100"), F.setAttribute("preserveAspectRatio", "none"), F.style.cssText = "position:absolute;inset:0;width:100%;height:100%;overflow:visible";
2870
- const O = document.createElementNS(F.namespaceURI, "line");
2891
+ const X = Ft(c.region), K = document.createElementNS("http://www.w3.org/2000/svg", "svg");
2892
+ K.setAttribute("viewBox", "0 0 100 100"), K.setAttribute("preserveAspectRatio", "none"), K.style.cssText = "position:absolute;inset:0;width:100%;height:100%;overflow:visible";
2893
+ const O = document.createElementNS(K.namespaceURI, "line");
2871
2894
  for (const [ee, ze] of Object.entries({
2872
- x1: K.x * 100,
2873
- y1: K.y * 100,
2895
+ x1: X.x * 100,
2896
+ y1: X.y * 100,
2874
2897
  x2: c.destination.x * 100,
2875
2898
  y2: c.destination.y * 100
2876
2899
  }))
2877
2900
  O.setAttribute(ee, String(ze));
2878
- O.setAttribute("stroke", "#93c5fd"), O.setAttribute("stroke-width", "1.5"), O.setAttribute("vector-effect", "non-scaling-stroke"), F.appendChild(O), N.appendChild(F), Ue(
2901
+ O.setAttribute("stroke", "#93c5fd"), O.setAttribute("stroke-width", "1.5"), O.setAttribute("vector-effect", "non-scaling-stroke"), K.appendChild(O), M.appendChild(K), Ue(
2879
2902
  { ...c.destination, width: 0, height: 0 },
2880
2903
  `${ln(c.code)}→`,
2881
2904
  i.has(c.code)
2882
2905
  );
2883
2906
  }
2884
2907
  }
2885
- k && Ue(k, "?", !1);
2908
+ V && Ue(V, "?", !1);
2886
2909
  }
2887
- }, z = (c = X()) => {
2888
- c.source === "host" && (l += 1), o.clear(), Q = c;
2910
+ }, z = (c = D()) => {
2911
+ c.source === "host" && (l += 1), o.clear(), G = c;
2889
2912
  for (const g of A.values()) cancelAnimationFrame(g);
2890
- A.clear(), u.clear(), i.clear(), d.clear(), r.finish(!0), Be(), Ce();
2891
- }, Se = (c, g = !1, L = X()) => {
2913
+ A.clear(), h.clear(), i.clear(), d.clear(), r.finish(!0), Be(), Ce();
2914
+ }, Se = (c, g = !1, q = D()) => {
2892
2915
  if (!ur.test(c)) return !1;
2893
- const K = h.get(c);
2894
- (!K || ct(L, K) >= 0) && h.set(c, L);
2895
- const F = d.get(c);
2896
- if (F && ct(L, F) < 0) return !1;
2897
- g && (L.source === "host" && a.set(c, (a.get(c) ?? 0) + 1), o.delete(c));
2916
+ const X = u.get(c);
2917
+ (!X || ct(q, X) >= 0) && u.set(c, q);
2918
+ const K = d.get(c);
2919
+ if (K && ct(q, K) < 0) return !1;
2920
+ g && (q.source === "host" && a.set(c, (a.get(c) ?? 0) + 1), o.delete(c));
2898
2921
  const O = i.get(c);
2899
2922
  if (!O) return !1;
2900
2923
  cancelAnimationFrame(A.get(c) ?? 0), A.delete(c);
2901
- const ee = u.get(c);
2902
- return u.delete(c), i.delete(c), d.delete(c), r.update(Array.from(i.values()), Rt), !g && ee !== void 0 && L.issuedAt - ee <= 500 && t.send({ type: "mini-app:tap", point: O, modifiers: Rt }), Ce(), !0;
2924
+ const ee = h.get(c);
2925
+ return h.delete(c), i.delete(c), d.delete(c), r.update(Array.from(i.values()), Rt), !g && ee !== void 0 && q.issuedAt - ee <= 500 && t.send({ type: "mini-app:tap", point: O, modifiers: Rt }), Ce(), !0;
2903
2926
  }, it = (c, g) => {
2904
- const L = g.x * t.iframe.offsetWidth, K = g.y * t.iframe.offsetHeight, F = we(t.iframe, L, K);
2927
+ const q = g.x * t.iframe.offsetWidth, X = g.y * t.iframe.offsetHeight, K = we(t.iframe, q, X);
2905
2928
  return {
2906
2929
  identifier: c.identifier,
2907
- clientX: L,
2908
- clientY: K,
2909
- pageX: L,
2910
- pageY: K,
2911
- screenX: window.screenX + F.x,
2912
- screenY: window.screenY + F.y
2930
+ clientX: q,
2931
+ clientY: X,
2932
+ pageX: q,
2933
+ pageY: X,
2934
+ screenX: window.screenX + K.x,
2935
+ screenY: window.screenY + K.y
2913
2936
  };
2914
- }, Ye = (c, g, L = X()) => {
2915
- const K = h.get(c);
2916
- if (ct(L, Q) <= 0 || K && ct(L, K) <= 0)
2937
+ }, Ye = (c, g, q = D()) => {
2938
+ const X = u.get(c);
2939
+ if (ct(q, G) <= 0 || X && ct(q, X) <= 0)
2917
2940
  return !1;
2918
2941
  if (i.has(c)) {
2919
- if (g || ct(L, d.get(c)) <= 0) return !0;
2920
- Se(c, !1, L);
2942
+ if (g || ct(q, d.get(c)) <= 0) return !0;
2943
+ Se(c, !1, q);
2921
2944
  }
2922
- if (g || !w || !b || x || S) return !1;
2923
- const F = s.find((ze) => ze.code === c);
2924
- if (!F || F.mode === "drag" && !F.destination) return !1;
2945
+ if (g || !v || !b || S || B) return !1;
2946
+ const K = s.find((ze) => ze.code === c);
2947
+ if (!K || K.mode === "drag" && !K.destination) return !1;
2925
2948
  const O = t.iframe.getBoundingClientRect();
2926
2949
  if (!O.width || !O.height) return !1;
2927
- const ee = Ft(F.region);
2928
- if (F.mode === "hold" && u.set(c, L.issuedAt), i.set(c, it(F, ee)), d.set(c, L), r.update(Array.from(i.values()), Rt), F.mode === "drag" && F.destination) {
2929
- const ze = F.destination, sr = () => {
2950
+ const ee = Ft(K.region);
2951
+ if (K.mode === "hold" && h.set(c, q.issuedAt), i.set(c, it(K, ee)), d.set(c, q), r.update(Array.from(i.values()), Rt), K.mode === "drag" && K.destination) {
2952
+ const ze = K.destination, sr = () => {
2930
2953
  const ir = performance.timeOrigin + performance.now();
2931
- P(
2954
+ I(
2932
2955
  c,
2933
2956
  () => {
2934
- if (!i.has(c) || d.get(c) !== L) return;
2935
- const rn = Math.min(1, Math.max(0, (ir - L.issuedAt) / 120));
2957
+ if (!i.has(c) || d.get(c) !== q) return;
2958
+ const rn = Math.min(1, Math.max(0, (ir - q.issuedAt) / 120));
2936
2959
  i.set(
2937
2960
  c,
2938
- it(F, {
2961
+ it(K, {
2939
2962
  x: ee.x + (ze.x - ee.x) * rn,
2940
2963
  y: ee.y + (ze.y - ee.y) * rn
2941
2964
  })
@@ -2948,49 +2971,49 @@ function ho(n) {
2948
2971
  }
2949
2972
  return Ce(), !0;
2950
2973
  }, j = () => {
2951
- x = null, q = null, k = null, S = !1, R = null, t.overlay.style.cursor = "default";
2974
+ S = null, L = null, V = null, B = !1, E = null, t.overlay.style.cursor = "default";
2952
2975
  }, Ge = (c, g = "region") => {
2953
- z(), j(), x = { binding: c, kind: g }, V = g === "destination" ? "点击拖动终点。按键按下后从区域中心拖到此处,保持到松开。" : "点击一个位置,或拖动框选区域。Esc 取消。", t.overlay.style.cursor = "crosshair", H(), t.overlay.focus({ preventScroll: !0 });
2954
- }, H = () => {
2955
- re.textContent = w ? "⌨ 键位 · 开" : "⌨ 键位", re.setAttribute("aria-expanded", String(y)), Ce(), Be(), ge();
2976
+ z(), j(), S = { binding: c, kind: g }, k = g === "destination" ? "点击拖动终点。按键按下后从区域中心拖到此处,保持到松开。" : "点击一个位置,或拖动框选区域。Esc 取消。", t.overlay.style.cursor = "crosshair", Q(), t.overlay.focus({ preventScroll: !0 });
2977
+ }, Q = () => {
2978
+ re.textContent = v ? "⌨ 键位 · 开" : "⌨ 键位", re.setAttribute("aria-expanded", String(w)), Ce(), Be(), ge();
2956
2979
  }, ot = (c) => {
2957
2980
  if (c.type === "key" || c.type === "enable") {
2958
- if (c.sequence <= Y) return;
2959
- Y = c.sequence;
2981
+ if (c.sequence <= Z) return;
2982
+ Z = c.sequence;
2960
2983
  }
2961
2984
  if (c.type === "key") {
2962
- const L = {
2985
+ const q = {
2963
2986
  issuedAt: c.issuedAt,
2964
2987
  sequence: c.sequence,
2965
2988
  source: "panel"
2966
2989
  };
2967
2990
  if (c.eventName === "keydown") {
2968
- if (!y || !b || !w || x || S) return;
2969
- P(
2991
+ if (!w || !b || !v || S || B) return;
2992
+ I(
2970
2993
  c.code,
2971
- () => Ye(c.code, c.repeat, L),
2972
- L.issuedAt
2994
+ () => Ye(c.code, c.repeat, q),
2995
+ q.issuedAt
2973
2996
  );
2974
2997
  } else
2975
- P(
2998
+ I(
2976
2999
  c.code,
2977
3000
  () => {
2978
- const K = d.get(c.code);
2979
- K && K.source !== "panel" || c.eventName === "focusout" && document.hasFocus() && (Kt(t.overlay) || Kt(t.iframe)) || Se(c.code, c.eventName !== "keyup", L);
3001
+ const X = d.get(c.code);
3002
+ X && X.source !== "panel" || c.eventName === "focusout" && document.hasFocus() && (Kt(t.overlay) || Kt(t.iframe)) || Se(c.code, c.eventName !== "keyup", q);
2980
3003
  },
2981
- L.issuedAt
3004
+ q.issuedAt
2982
3005
  );
2983
3006
  return;
2984
3007
  }
2985
3008
  if (c.type === "outside") {
2986
- f = !1, z(), j(), V = "", H();
3009
+ f = !1, z(), j(), k = "", Q();
2987
3010
  return;
2988
3011
  }
2989
- if (!y || !b) return;
2990
- const g = "code" in c ? s.find((L) => L.code === c.code) : void 0;
3012
+ if (!w || !b) return;
3013
+ const g = "code" in c ? s.find((q) => q.code === c.code) : void 0;
2991
3014
  switch (c.type) {
2992
3015
  case "add":
2993
- s.length < co && !x && !S && Ge();
3016
+ s.length < co && !S && !B && Ge();
2994
3017
  break;
2995
3018
  case "pick":
2996
3019
  case "destination":
@@ -2998,38 +3021,38 @@ function ho(n) {
2998
3021
  break;
2999
3022
  case "rebind":
3000
3023
  if (!g) break;
3001
- z(), j(), R = g, S = !0, V = "按下要使用的字母、数字、方向键或空格。Esc 取消。", H(), t.overlay.focus({ preventScroll: !0 });
3024
+ z(), j(), E = g, B = !0, k = "按下要使用的字母、数字、方向键或空格。Esc 取消。", Q(), t.overlay.focus({ preventScroll: !0 });
3002
3025
  break;
3003
3026
  case "remove":
3004
3027
  if (!g) break;
3005
- Se(g.code, !0), (x?.binding === g || R === g) && j(), s.splice(s.indexOf(g), 1), H();
3028
+ Se(g.code, !0), (S?.binding === g || E === g) && j(), s.splice(s.indexOf(g), 1), Q();
3006
3029
  break;
3007
3030
  case "mode":
3008
3031
  if (!g || c.mode !== "hold" && c.mode !== "drag") break;
3009
- Se(g.code, !0), g.mode = c.mode, g.mode === "drag" && !g.destination ? Ge(g, "destination") : H();
3032
+ Se(g.code, !0), g.mode = c.mode, g.mode === "drag" && !g.destination ? Ge(g, "destination") : Q();
3010
3033
  break;
3011
3034
  case "enable":
3012
- z({ issuedAt: c.issuedAt, sequence: c.sequence, source: "panel" }), w = c.enabled, H();
3035
+ z({ issuedAt: c.issuedAt, sequence: c.sequence, source: "panel" }), v = c.enabled, Q();
3013
3036
  break;
3014
3037
  case "cancel":
3015
- j(), V = "", H();
3038
+ j(), k = "", Q();
3016
3039
  break;
3017
3040
  case "close":
3018
- j(), y = !1, f = !0, H(), t.focusGuest();
3041
+ j(), w = !1, f = !0, Q(), t.focusGuest();
3019
3042
  break;
3020
3043
  }
3021
3044
  };
3022
3045
  re.addEventListener("click", () => {
3023
- z(), j(), y = !y, V = "", H(), y || (f = !0, t.focusGuest());
3046
+ z(), j(), w = !w, k = "", Q(), w || (f = !0, t.focusGuest());
3024
3047
  });
3025
3048
  for (const [c, g] of [
3026
3049
  [C, "counterclockwise"],
3027
- [W, "clockwise"]
3050
+ [T, "clockwise"]
3028
3051
  ])
3029
3052
  c.addEventListener("click", () => {
3030
- z(), j(), t.rotateScreen?.(g), f = !0, H(), t.focusGuest();
3053
+ z(), j(), t.rotateScreen?.(g), f = !0, Q(), t.focusGuest();
3031
3054
  });
3032
- M.addEventListener("mousedown", (c) => c.stopPropagation()), M.addEventListener("wheel", (c) => c.stopPropagation());
3055
+ P.addEventListener("mousedown", (c) => c.stopPropagation()), P.addEventListener("wheel", (c) => c.stopPropagation());
3033
3056
  const He = (c) => {
3034
3057
  const g = Pe(t.iframe, c.clientX, c.clientY);
3035
3058
  return {
@@ -3037,66 +3060,66 @@ function ho(n) {
3037
3060
  y: Math.max(0, Math.min(0.9999, g.y / t.iframe.offsetHeight))
3038
3061
  };
3039
3062
  }, at = (c) => {
3040
- f = !0, !(!x && !S) && (c.preventDefault(), c.stopImmediatePropagation(), !(!x || c.button !== 0) && (q = He(c), k = { ...q, width: 0, height: 0 }, Ce()));
3063
+ f = !0, !(!S && !B) && (c.preventDefault(), c.stopImmediatePropagation(), !(!S || c.button !== 0) && (L = He(c), V = { ...L, width: 0, height: 0 }, Ce()));
3041
3064
  }, p = (c) => {
3042
- if (!x || !q) return;
3065
+ if (!S || !L) return;
3043
3066
  c.preventDefault(), c.stopImmediatePropagation();
3044
3067
  const g = He(c);
3045
- k = {
3046
- x: Math.min(q.x, g.x),
3047
- y: Math.min(q.y, g.y),
3048
- width: Math.abs(g.x - q.x),
3049
- height: Math.abs(g.y - q.y)
3068
+ V = {
3069
+ x: Math.min(L.x, g.x),
3070
+ y: Math.min(L.y, g.y),
3071
+ width: Math.abs(g.x - L.x),
3072
+ height: Math.abs(g.y - L.y)
3050
3073
  }, Ce();
3051
- }, I = (c) => {
3052
- if (!x || !q || c.button !== 0) return;
3074
+ }, W = (c) => {
3075
+ if (!S || !L || c.button !== 0) return;
3053
3076
  c.preventDefault(), c.stopImmediatePropagation(), p(c);
3054
- const g = x;
3055
- g.kind === "destination" && g.binding ? (g.binding.destination = He(c), j(), V = "拖动终点已设置。") : g.binding ? (g.binding.region = k, j(), V = "区域已更新。") : (x = null, q = null, S = !0, V = "区域已选好。请按一个字母、数字、方向键或空格绑定。Esc 取消。"), H(), t.overlay.focus({ preventScroll: !0 });
3056
- }, E = (c) => {
3077
+ const g = S;
3078
+ g.kind === "destination" && g.binding ? (g.binding.destination = He(c), j(), k = "拖动终点已设置。") : g.binding ? (g.binding.region = V, j(), k = "区域已更新。") : (S = null, L = null, B = !0, k = "区域已选好。请按一个字母、数字、方向键或空格绑定。Esc 取消。"), Q(), t.overlay.focus({ preventScroll: !0 });
3079
+ }, x = (c) => {
3057
3080
  const g = c.composedPath();
3058
- if (g.includes(M) && g.some(
3081
+ if (g.includes(P) && g.some(
3059
3082
  (O) => O instanceof HTMLElement && O.hasAttribute("data-mini-app-keyboard-panel")
3060
3083
  ) && c.code !== "Escape") return;
3061
3084
  if (c.type === "keyup") {
3062
3085
  const O = o.delete(c.code) || i.has(c.code);
3063
3086
  if (O && (c.preventDefault(), c.stopPropagation()), O || s.some((ee) => ee.code === c.code)) {
3064
- const ee = X();
3065
- P(c.code, () => Se(c.code, !1, ee), ee.issuedAt);
3087
+ const ee = D();
3088
+ I(c.code, () => Se(c.code, !1, ee), ee.issuedAt);
3066
3089
  }
3067
3090
  return;
3068
3091
  }
3069
- if (y && c.code === "Escape" && (g.includes(M) || g.includes(t.overlay))) {
3070
- c.preventDefault(), c.stopImmediatePropagation(), x || S ? (j(), V = "") : y = !1, f = !0, H(), y ? t.overlay.focus({ preventScroll: !0 }) : t.focusGuest();
3092
+ if (w && c.code === "Escape" && (g.includes(P) || g.includes(t.overlay))) {
3093
+ c.preventDefault(), c.stopImmediatePropagation(), S || B ? (j(), k = "") : w = !1, f = !0, Q(), w ? t.overlay.focus({ preventScroll: !0 }) : t.focusGuest();
3071
3094
  return;
3072
3095
  }
3073
3096
  if (c.isComposing || c.ctrlKey || c.metaKey || c.altKey || c.shiftKey)
3074
3097
  return;
3075
- if (y && S) {
3098
+ if (w && B) {
3076
3099
  if (c.preventDefault(), c.stopPropagation(), c.repeat || !ur.test(c.code)) return;
3077
- if (s.some((O) => O !== R && O.code === c.code)) {
3078
- V = "这个按键已有映射,请选择其他按键。", H();
3100
+ if (s.some((O) => O !== E && O.code === c.code)) {
3101
+ k = "这个按键已有映射,请选择其他按键。", Q();
3079
3102
  return;
3080
3103
  }
3081
- R ? R.code = c.code : k && s.push({
3104
+ E ? E.code = c.code : V && s.push({
3082
3105
  code: c.code,
3083
3106
  identifier: m++,
3084
- region: k,
3107
+ region: V,
3085
3108
  mode: "hold"
3086
- }), j(), V = `已绑定 ${ln(c.code)}。`, H();
3109
+ }), j(), k = `已绑定 ${ln(c.code)}。`, Q();
3087
3110
  return;
3088
3111
  }
3089
- if (!f || uo(g) || g.includes(M)) return;
3090
- const K = s.find((O) => O.code === c.code);
3091
- if (!w || !b || x || S || !K || K.mode === "drag" && !K.destination || c.repeat && !o.has(c.code) && !i.has(c.code)) return;
3112
+ if (!f || uo(g) || g.includes(P)) return;
3113
+ const X = s.find((O) => O.code === c.code);
3114
+ if (!v || !b || S || B || !X || X.mode === "drag" && !X.destination || c.repeat && !o.has(c.code) && !i.has(c.code)) return;
3092
3115
  c.preventDefault(), c.stopPropagation(), o.add(c.code);
3093
- const F = X();
3094
- P(c.code, () => Ye(c.code, c.repeat, F), F.issuedAt);
3095
- }, G = (c) => {
3096
- c.composedPath().includes(t.overlay) || c.composedPath().includes(M) || (f = !1, z(), (x || S) && (j(), V = "", H()));
3116
+ const K = D();
3117
+ I(c.code, () => Ye(c.code, c.repeat, K), K.issuedAt);
3118
+ }, H = (c) => {
3119
+ c.composedPath().includes(t.overlay) || c.composedPath().includes(P) || (f = !1, z(), (S || B) && (j(), k = "", Q()));
3097
3120
  }, J = (c) => {
3098
3121
  const g = c.composedPath();
3099
- if (g.includes(M)) {
3122
+ if (g.includes(P)) {
3100
3123
  f = !1, z();
3101
3124
  return;
3102
3125
  }
@@ -3104,39 +3127,39 @@ function ho(n) {
3104
3127
  f = !0;
3105
3128
  return;
3106
3129
  }
3107
- g.includes(t.iframe) || (f = !1, z(), (x || S) && (j(), V = "", H()));
3130
+ g.includes(t.iframe) || (f = !1, z(), (S || B) && (j(), k = "", Q()));
3108
3131
  }, Te = () => {
3109
- z(), j(), H();
3132
+ z(), j(), Q();
3110
3133
  }, Ee = [
3111
3134
  t.on("blur", () => {
3112
- f = !1, z(), (!n || !y) && j(), H();
3135
+ f = !1, z(), (!n || !w) && j(), Q();
3113
3136
  }),
3114
- t.hook("touch:multiple", () => u.clear()),
3137
+ t.hook("touch:multiple", () => h.clear()),
3115
3138
  t.hook("iframe:ready", () => {
3116
- f = !1, z(), j(), H();
3139
+ f = !1, z(), j(), Q();
3117
3140
  }),
3118
3141
  t.hook("interaction:change", (...c) => {
3119
- b = c[0] === !0, b || (f = !1, y = !1, z(), j()), M.hidden = !b, H();
3142
+ b = c[0] === !0, b || (f = !1, w = !1, z(), j()), P.hidden = !b, Q();
3120
3143
  }),
3121
3144
  t.hook("guest:message", (...c) => {
3122
3145
  const g = c[0];
3123
3146
  if ((g?.type === "mini-app:keyboard" || g?.type === "mini-app:keyboard-cancel" || g?.type === "mini-app:focus-editable") && typeof g.issuedAt == "number" && Number.isFinite(g.issuedAt) && typeof g.sequence == "number" && Number.isSafeInteger(g.sequence)) {
3124
- const L = {
3147
+ const q = {
3125
3148
  issuedAt: g.issuedAt,
3126
3149
  sequence: g.sequence,
3127
3150
  source: "guest"
3128
3151
  };
3129
- g.type === "mini-app:keyboard-cancel" || g.type === "mini-app:focus-editable" ? z(L) : typeof g.code == "string" && (g.eventName === "keyup" ? Se(g.code, !1, L) : g.eventName === "keydown" && document.hasFocus() && (Kt(t.overlay) || Kt(t.iframe)) && Ye(g.code, g.repeat === !0, L));
3152
+ g.type === "mini-app:keyboard-cancel" || g.type === "mini-app:focus-editable" ? z(q) : typeof g.code == "string" && (g.eventName === "keyup" ? Se(g.code, !1, q) : g.eventName === "keydown" && document.hasFocus() && (Kt(t.overlay) || Kt(t.iframe)) && Ye(g.code, g.repeat === !0, q));
3130
3153
  }
3131
3154
  })
3132
3155
  ];
3133
- t.overlay.addEventListener("mousedown", at, !0), window.addEventListener("mousemove", p, !0), window.addEventListener("mouseup", I, !0), window.addEventListener("keydown", E, !0), window.addEventListener("keyup", E, !0), document.addEventListener("mousedown", G, !0), document.addEventListener("focusin", J, !0), window.addEventListener("resize", Te), document.addEventListener("scroll", ge, !0);
3156
+ t.overlay.addEventListener("mousedown", at, !0), window.addEventListener("mousemove", p, !0), window.addEventListener("mouseup", W, !0), window.addEventListener("keydown", x, !0), window.addEventListener("keyup", x, !0), document.addEventListener("mousedown", H, !0), document.addEventListener("focusin", J, !0), window.addEventListener("resize", Te), document.addEventListener("scroll", ge, !0);
3134
3157
  const xe = new ResizeObserver(Te);
3135
3158
  xe.observe(t.iframe);
3136
- let pe = 0;
3159
+ let Ae = 0;
3137
3160
  const qt = () => {
3138
- pe || (pe = requestAnimationFrame(() => {
3139
- pe = 0, ge();
3161
+ Ae || (Ae = requestAnimationFrame(() => {
3162
+ Ae = 0, ge();
3140
3163
  }));
3141
3164
  }, Qe = new ResizeObserver(qt), rr = new MutationObserver(qt);
3142
3165
  let lt = t.iframe;
@@ -3146,13 +3169,13 @@ function ho(n) {
3146
3169
  attributeFilter: ["style", "class", "data-mini-app-screen-rotation"]
3147
3170
  }), lt = hr(lt);
3148
3171
  qe = n ? n.mount(ot) : lo({
3149
- root: M,
3172
+ root: P,
3150
3173
  onCommand: ot,
3151
3174
  getAnchor: () => (se ?? t.iframe).getBoundingClientRect()
3152
- }), H(), e = () => {
3153
- w = !1, z(), j();
3175
+ }), Q(), e = () => {
3176
+ v = !1, z(), j();
3154
3177
  for (const c of Ee) c();
3155
- t.overlay.removeEventListener("mousedown", at, !0), window.removeEventListener("mousemove", p, !0), window.removeEventListener("mouseup", I, !0), window.removeEventListener("keydown", E, !0), window.removeEventListener("keyup", E, !0), document.removeEventListener("mousedown", G, !0), document.removeEventListener("focusin", J, !0), window.removeEventListener("resize", Te), document.removeEventListener("scroll", ge, !0), xe.disconnect(), Qe.disconnect(), rr.disconnect(), cancelAnimationFrame(pe), qe?.dispose(), qe = void 0, M.remove(), N.remove();
3178
+ t.overlay.removeEventListener("mousedown", at, !0), window.removeEventListener("mousemove", p, !0), window.removeEventListener("mouseup", W, !0), window.removeEventListener("keydown", x, !0), window.removeEventListener("keyup", x, !0), document.removeEventListener("mousedown", H, !0), document.removeEventListener("focusin", J, !0), window.removeEventListener("resize", Te), document.removeEventListener("scroll", ge, !0), xe.disconnect(), Qe.disconnect(), rr.disconnect(), cancelAnimationFrame(Ae), qe?.dispose(), qe = void 0, P.remove(), M.remove();
3156
3179
  };
3157
3180
  },
3158
3181
  uninstall() {
@@ -3307,10 +3330,10 @@ async function mo(n, e, t, r) {
3307
3330
  "[sim-dbg] materializeTempFile 无可用落盘途径:既无 __miniAppSimulatorHostFs 也无 require",
3308
3331
  { subdir: e, prefix: t }
3309
3332
  ), null;
3310
- const o = i("fs"), a = i("path"), l = i("os"), d = i("crypto"), h = a.join(l.tmpdir(), e);
3311
- o.mkdirSync(h, { recursive: !0 });
3312
- const A = d.createHash("sha1").update(n).digest("hex").slice(0, 16), u = a.join(h, `${t}-${A}.${r}`);
3313
- return o.existsSync(u) || o.writeFileSync(u, n, "utf8"), `file://${u}`;
3333
+ const o = i("fs"), a = i("path"), l = i("os"), d = i("crypto"), u = a.join(l.tmpdir(), e);
3334
+ o.mkdirSync(u, { recursive: !0 });
3335
+ const A = d.createHash("sha1").update(n).digest("hex").slice(0, 16), h = a.join(u, `${t}-${A}.${r}`);
3336
+ return o.existsSync(h) || o.writeFileSync(h, n, "utf8"), `file://${h}`;
3314
3337
  }
3315
3338
  const pr = `(function(){
3316
3339
  function d(){
@@ -3432,9 +3455,9 @@ const ft = {
3432
3455
  }
3433
3456
  }
3434
3457
  })();
3435
- `, ko = '/*! xhs-script-version=0.4.3 */\n!function(e){"function"==typeof define&&define.amd?define(e):e()}(function(){"use strict";var e=Object.defineProperty,t=Object.defineProperties,r=Object.getOwnPropertyDescriptors,n=Object.getOwnPropertySymbols,o=Object.prototype.hasOwnProperty,s=Object.prototype.propertyIsEnumerable,i=(t,r,n)=>r in t?e(t,r,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[r]=n,a=(e,t)=>{for(var r in t||(t={}))o.call(t,r)&&i(e,r,t[r]);if(n)for(var r of n(t))s.call(t,r)&&i(e,r,t[r]);return e},c=(e,n)=>t(e,r(n)),l=(e,t)=>{var r={};for(var i in e)o.call(e,i)&&t.indexOf(i)<0&&(r[i]=e[i]);if(null!=e&&n)for(var i of n(e))t.indexOf(i)<0&&s.call(e,i)&&(r[i]=e[i]);return r};function u(){return"undefined"==typeof window?void 0:window}let d,f,p=!1;const m=new WeakMap;function g(e){p||(!function(e){var t;if(d)return d;const r=[null==(t=e.webkit)?void 0:t.messageHandlers,e].find(e=>{var t;return"function"==typeof(null==(t=null==e?void 0:e.xhsInvoke)?void 0:t.postMessage)}),n=null==r?void 0:r.xhsInvoke;if(!n)throw new Error("xhsInvoke unavailable");if(!Reflect.defineProperty(r,"xhsInvoke",{value:void 0,writable:!1,configurable:!1,enumerable:!1})||void 0!==r.xhsInvoke)throw new Error("Failed to hide xhsInvoke");f=r,d=n}(e),null!=e.XHS_SDK_CALLBACKS||(e.XHS_SDK_CALLBACKS={}),null!=e.XHS_SDK_CALLBACKS_ID||(e.XHS_SDK_CALLBACKS_ID=0),m.set(e,new Map),e.XHS_SDK_INVOKE_CALLBACKS=(t,r)=>{var n,o;const s=null==(n=e.XHS_SDK_CALLBACKS)?void 0:n[r];if(!s)return;null==(o=e.XHS_SDK_CALLBACKS)||delete o[r];const i=function(e){if("string"!=typeof e)return null!=e?e:{code:-1,msg:"empty bridge result"};try{const t=JSON.parse(e);return t&&"object"==typeof t?t:{code:-1,msg:"invalid bridge result"}}catch(t){return{code:-1,msg:e||"invalid bridge result"}}}(t);0===i.code?function(e,t){var r,n,o;const s=t&&"object"==typeof t&&!Array.isArray(t)?c(a({},t),{errMsg:`${e.api}:ok`}):void 0===t?{errMsg:`${e.api}:ok`}:{data:t,errMsg:`${e.api}:ok`};null==(r=e.resolve)||r.call(e,s);try{null==(n=e.success)||n.call(e,s)}finally{null==(o=e.complete)||o.call(e,s)}}(s,i.data):function(e,t){var r,n,o;null==(r=e.reject)||r.call(e,t);try{null==(n=e.fail)||n.call(e,t)}finally{null==(o=e.complete)||o.call(e,t)}}(s,{errMsg:`${s.api}:fail${i.msg?` ${i.msg}`:""}`,errCode:i.code})},e.XHS_SDK_EVENTS_CALLBACKS=t=>{var r;const n=function(e){let t;if("string"==typeof e)try{t=JSON.parse(e)}catch(e){return}else t=e;return"events"===(null==t?void 0:t.type)&&"string"==typeof t.method?t:void 0}(t);if(!n)return;const o=null==(r=m.get(e))?void 0:r.get(n.method);if(o)for(const e of[...o])e(n)},p=!0)}function h(e,t,r=u()){var n;if(!r)throw new Error("window is unavailable");if(!e||"function"!=typeof t)throw new TypeError("invalid event subscription");const o=m.get(r);if(!o)throw new Error("bridge is not initialized");const s=t,i=null!=(n=o.get(e))?n:new Set;return i.add(s),o.set(e,i),{remove(){const t=o.get(e);null==t||t.delete(s),0===(null==t?void 0:t.size)&&o.delete(e)}}}function v(e,t={},r={}){const{target:n,validate:o,prepareRequest:s}=r,i=t,{success:a,fail:c,complete:p}=i,m=l(i,["success","fail","complete"]);w("success",a),w("fail",c),w("complete",p);const g=!(a||c||p);let h=m;try{null==o||o(h),s&&(h=s(h))}catch(t){return y(e,t,g,c,p)}const v=null!=n?n:u();if(!v)return y(e,new Error("window is unavailable"),g,c,p);let _,S;const k=new Promise((e,t)=>{_=e,S=t}),C="xhs_"+ ++v.XHS_SDK_CALLBACKS_ID;v.XHS_SDK_CALLBACKS[C]=g?{api:e,resolve:_,reject:S}:{api:e,success:a,fail:c,complete:p};try{!function(e){if(!d||!f||void 0!==f.xhsInvoke)throw new Error("xhsInvoke bridge is unavailable");d.postMessage(e)}(JSON.stringify({event:e,message:h,callbackId:C}))}catch(t){delete v.XHS_SDK_CALLBACKS[C];const r=b(e,t);return g?(null==S||S(r),k):(null==c||c(r),void(null==p||p(r)))}return g?k:void 0}function y(e,t,r,n,o){const s=b(e,t);if(r)return Promise.reject(s);null==n||n(s),null==o||o(s)}function b(e,t){const r=t instanceof Error?t.message:String(t),n=t&&"object"==typeof t&&"code"in t&&"number"==typeof t.code?t.code:void 0;return a({errMsg:`${e}:fail ${r}`},void 0===n?{}:{errCode:n})}function w(e,t){if(void 0!==t&&"function"!=typeof t)throw new TypeError(`${e} must be a function`)}const _="__xhsErrorMonitorInstalled__";function S(e,t){try{const r=v("reportTracker",{eventName:"minitool_error",data:t},{target:e});r&&r.catch(()=>{})}catch(e){}}function k(e){return e instanceof Error?e.message:String(e&&"object"==typeof e&&"message"in e?e.message:e)}function C(e){return e instanceof Error?e.name||"Error":e&&"object"==typeof e&&"name"in e&&String(e.name)||"Error"}function E(e){const t=e instanceof Error?e.stack:null==e?void 0:e.stack;return t?String(t).slice(0,512):""}class A{constructor(){this.aborted=!1,this.listeners=new Set}addEventListener(e,t,r){"abort"===e&&t&&this.listeners.add(t)}removeEventListener(e,t){"abort"===e&&t&&this.listeners.delete(t)}abort(e){if(this.aborted)return;this.aborted=!0,this.reason=e;const t={type:"abort",target:this,currentTarget:this},r=[...this.listeners];this.listeners.clear();for(const e of r)"function"==typeof e?e.call(this,t):e.handleEvent(t)}}const q=Object.freeze({default:"/api/sns/v1/creator/red_app/chat/completions",creator:"/api/sns/v1/creator/red_app/creator/chat/completions",mars:"/api/sns/v1/creator/red_app/mars/chat/completions"});function j(e,t){return`${e.replace(/\\/+$/,"")}/${t.replace(/^\\/+/,"")}`}const O=-104001;class I extends Error{constructor(e){super(e.message),this.name="AIError",this.code=e.code,this.requestId=e.requestId,this.details=e.details}}function T(e){if(e instanceof I)return e;const t=function(e){return x(e)&&"number"==typeof e.errCode?e.errCode:void 0}(e);return new I({code:O,message:L(e),details:void 0===t?void 0:{bridgeCode:t}})}function L(e){if(e instanceof Error)return e.message;if(x(e)){if("string"==typeof e.errMsg)return e.errMsg;if("string"==typeof e.message)return e.message}return"string"==typeof e?e:"AI request failed"}function x(e){return null!==e&&"object"==typeof e}const $=[239,187,191];const N=Symbol.for("Symbol.asyncIterator"),R="symbol"==typeof Symbol.asyncIterator?Symbol.asyncIterator:N;function P(e){const t=e;if("function"==typeof e[R])return t;const r=()=>{const t=e.getReader();let r=!1;const n=()=>{r||(r=!0,t.releaseLock())},o={async next(){try{const e=await t.read();return e.done&&n(),e}catch(e){throw n(),e}},async return(){try{await t.cancel()}finally{n()}return{done:!0,value:void 0}}};return Object.defineProperty(o,R,{value:()=>o}),o};return Object.defineProperty(e,R,{configurable:!0,value:r}),R!==N&&Object.defineProperty(e,N,{configurable:!0,value:r}),t}function M(e){const t=function(e){if("getReader"in e){const t=e.getReader();let r=!1;const n=()=>{r||(r=!0,t.releaseLock())};return new ReadableStream({async pull(e){try{const r=await t.read();r.done?(n(),e.close()):e.enqueue(r.value)}catch(t){n(),e.error(t)}},async cancel(e){var r;try{await(null==(r=t.cancel)?void 0:r.call(t,e))}finally{n()}}})}const t=e[R].call(e);return new ReadableStream({async pull(e){const r=await t.next();r.done?e.close():e.enqueue(r.value)},async cancel(e){var r;await(null==(r=t.return)?void 0:r.call(t,e))}})}(e).getReader();let r,n=!1,o=!1;const s=()=>{o||(o=!0,t.releaseLock())};return P(new ReadableStream({start(e){r=function(e){let t,r,n,o,s,i,a;return c(),{feed:function(e){r=r?r+e:e,t&&function(e){return $.every((t,r)=>e.charCodeAt(r)===t)}(r)&&(r=r.slice($.length)),t=!1;const{length:s}=r;let i=0,a=!1;for(;i<s;){a&&("\\n"===r[i]&&(i+=1),a=!1);let e,t=-1,c=o;for(let o=n;t<0&&o<s;o++)e=r[o],":"===e&&c<0?c=o-i:"\\r"===e?(a=!0,t=o-i):"\\n"===e&&(t=o-i);if(t<0){n=s-i,o=c;break}n=0,o=-1,l(r,i,c,t),i+=t+1}i===s?r="":i>0&&(r=r.slice(i))},reset:c};function c(){t=!0,r="",n=0,o=-1,s=void 0,i=void 0,a=""}function l(t,r,n,o){if(0===o)return a.length>0&&(e({type:"event",id:s,event:i||void 0,data:a.slice(0,-1)}),a="",s=void 0),void(i=void 0);const c=n<0,l=t.slice(r,r+(c?o:n));let u=0;u=c?o:" "===t[r+n+1]?n+2:n+1;const d=r+u,f=o-u,p=t.slice(d,d+f).toString();if("data"===l)a+=p?`${p}\\n`:"\\n";else if("event"===l)i=p;else if("id"!==l||p.includes("\\0")){if("retry"===l){const t=Number.parseInt(p,10);Number.isNaN(t)||e({type:"reconnect-interval",value:t})}}else s=p}}(t=>{if("event"===t.type&&"[DONE]"!==t.data)try{const r=JSON.parse(t.data);if(!r||"object"!=typeof r||Array.isArray(r))throw new TypeError("SSE data must be a JSON object");e.enqueue(r)}catch(e){throw new I({code:O,message:"AI chat gateway returned invalid SSE data",details:{cause:e instanceof Error?e.message:String(e)}})}}),(async()=>{try{for(;!n;){const o=await t.read();if(o.done)return n=!0,s(),void e.close();const i=o.value;i&&r.feed(i)}}catch(r){if(n)return;n=!0;try{await t.cancel(r)}catch(e){}finally{s()}e.error(r)}})()},async cancel(e){if(!n){n=!0;try{await t.cancel(e)}finally{s()}}}}))}class D{constructor(e,t,r){this.req=e,this.getBaseUrl=t,this.getSubUrl=r}}const K="x-minitool-appid",B=Object.freeze({max_output_tokens:1024,temperature:1});function F(e,t,r,n){var o,s;return function(e){z(e)||H("request");Array.isArray(e.messages)||H("messages");e.messages.forEach((e,t)=>{var r;z(e)||H(`messages[${t}]`),"string"==typeof(r=e.content)||"object"==typeof r&&null!==r||H(`messages[${t}].content`)}),U(e.max_output_tokens)||H("max_output_tokens");U(e.temperature)||H("temperature");U(e.top_p)||H("top_p");t=e.stop,void 0===t||"string"==typeof t||Array.isArray(t)&&t.every(e=>"string"==typeof e)||H("stop");var t;J(e.response_format)||H("response_format");J(e.thinking)||H("thinking");(function(e){return void 0===e||"string"==typeof e})(e.reasoning_effort)||H("reasoning_effort")}(t),c(a(a({},t),n?{app_id:n}:{}),{model:e,max_output_tokens:null!=(o=t.max_output_tokens)?o:B.max_output_tokens,temperature:null!=(s=t.temperature)?s:B.temperature,stream:r})}function H(e){throw new I({code:104001,message:`请求参数不合法:${e}`})}function U(e){return void 0===e||"number"==typeof e&&Number.isFinite(e)&&e>=0}function J(e){return void 0===e||z(e)}function z(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)}function G(e){var t,r,n;return c(a({},e),{prompt_tokens:null!=(t=null==e?void 0:e.prompt_tokens)?t:0,completion_tokens:null!=(r=null==e?void 0:e.completion_tokens)?r:0,total_tokens:null!=(n=null==e?void 0:e.total_tokens)?n:0})}function X(e){if(!Y(e))return;const t=W(e);return t||(Y(e.data)?W(e.data):void 0)}function W(e){var t,r;const n=void 0!==e.code&&0!==e.code;if(!1===e.success||n){const r=n&&void 0!==e.code?e.code:O;return new I({code:r,message:null!=(t=e.msg)?t:"AI chat request failed",requestId:e.request_id})}if(e.error)return new I({code:O,message:null!=(r=e.error.message)?r:"AI chat request failed",requestId:e.request_id,details:a(a({},void 0===e.error.code?{}:{providerCode:e.error.code}),void 0===e.error.retriable?{}:{retriable:e.error.retriable})})}function V(e,t){const r=X(e.data);if(r)throw r;if(void 0!==e.statusCode&&e.statusCode>=400)throw new I({code:O,message:`AI request failed with status ${e.statusCode}`,details:{statusCode:e.statusCode}});if(!e.data)throw new I({code:O,message:t});return e.data}function Y(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)}function Q(e){var t,r;const n=function(){if("function"==typeof AbortController)return new AbortController;const e=new A;return{signal:e,abort:t=>e.abort(t)}}();let o=!1;const s=()=>{var t;return n.abort(null==(t=null==e?void 0:e.signal)?void 0:t.reason)};(null==(t=null==e?void 0:e.signal)?void 0:t.aborted)?s():null==(r=null==e?void 0:e.signal)||r.addEventListener("abort",s,{once:!0});const i=void 0!==(null==e?void 0:e.timeoutMs)&&e.timeoutMs>0?setTimeout(()=>{o=!0,n.abort("timeout")},e.timeoutMs):void 0;return{controller:n,get timedOut(){return o},cleanup(){var t;void 0!==i&&clearTimeout(i),null==(t=null==e?void 0:e.signal)||t.removeEventListener("abort",s)}}}function Z(e,t){return t.timedOut?new I({code:O,message:"AI request timed out"}):t.controller.signal.aborted?new I({code:O,message:"AI request was aborted"}):T(e)}function ee(e,t=0){var r,n,o,s,i;const l=null!=(r=null==e?void 0:e.message)?r:{};return c(a({},e),{index:null!=(n=null==e?void 0:e.index)?n:t,message:c(a({},l),{role:null!=(o=l.role)?o:"assistant",content:null!=(s=l.content)?s:""}),finish_reason:null!=(i=null==e?void 0:e.finish_reason)?i:void 0})}class te extends D{constructor(e,t,r,n,o=()=>"/chat/completions",s){super(e,t,o),this.modelName=r,this.getAppId=n,this.onError=s}reportError(e,t){if(this.onError)try{Promise.resolve(this.onError(e,{model:this.modelName,operation:t})).catch(()=>{})}catch(e){}}requestOptions(e,t,r,n){var o;const s=null==(o=this.getAppId)?void 0:o.call(this),i=F(this.modelName,e,t,s);return{url:j(this.getBaseUrl(),this.getSubUrl()),method:"post",headers:a(a({"Content-Type":"application/json"},null==n?void 0:n.headers),s?{[K]:s}:{}),data:i,responseType:t?"stream":"json",stream:t,signal:r}}async doGenerate(e,t){var r;const n=Q(t);try{const o=await this.req.post(this.requestOptions(e,!1,n.controller.signal,t)),s=function(e){var t;if(!("code"in e||"success"in e||"msg"in e)||null===e.data||"object"!=typeof e.data||Array.isArray(e.data))return e;const r=e.data;return c(a({},r),{request_id:null!=(t=r.request_id)?t:e.request_id})}(V(o,"AI response is empty"));return function(e,t,r){var n,o,s;const i=(null==(n=e.choices)?void 0:n.length)?e.choices.map(ee):[ee(void 0)];return c(a({},e),{request_id:null!=(s=null!=(o=e.request_id)?o:e.id)?s:t,model:r,choices:i,usage:G(e.usage)})}(s,null!=(r=null==t?void 0:t.idempotencyKey)?r:this.modelName,this.modelName)}catch(e){const t=Z(e,n);throw this.reportError(t,"generateText"),t}finally{n.cleanup()}}async doStream(e,t){var r;const n=Q(t),o=null!=(r=null==t?void 0:t.idempotencyKey)?r:`chat_${Date.now().toString(36)}`,s=function(){let e,t;return{promise:new Promise((r,n)=>{e=r,t=n}),resolve:e,reject:t}}();s.promise.catch(()=>{});let i=n.controller.signal.aborted;const u=P(new ReadableStream({start:r=>{if(i){const e=new I({code:O,message:"AI request was aborted"});return r.error(e),s.reject(e),void n.cleanup()}(async()=>{var u,d,f;let p,m=0;const g={},h=new Map;try{const v=await this.req.post(this.requestOptions(e,!0,n.controller.signal,t));if(i)return;const y=M(V(v,"AI stream is empty")).getReader();let b=!1;try{for(;;){const e=await y.read();if(e.done){b=!0;break}const t=e.value;if(i)return;const n=X(t);if(n)throw n;t.usage&&(p=t.usage);const s=t,{choices:v,usage:w}=s,_=l(s,["choices","usage"]);Object.assign(g,_);const S=(null!=(u=t.choices)?u:[]).map((e,t)=>{var r,n,o,s;const i=null!=(r=e.index)?r:t,u=null!=(n=e.delta)?n:{},d=null!=(o=h.get(i))?o:{fields:{},content:"",reasoning_content:""},f=e,{delta:p,message:g}=f,v=l(f,["delta","message"]);return Object.assign(d.fields,v),u.content&&(d.content+=u.content),u.reasoning_content&&(d.reasoning_content+=u.reasoning_content),e.finish_reason&&(d.finish_reason=e.finish_reason),h.set(i,d),c(a({},e),{index:i,delta:a(a({},u),0===m&&void 0===u.role?{role:"assistant"}:{}),finish_reason:null!=(s=e.finish_reason)?s:void 0})});m+=1,r.enqueue(c(a({},t),{request_id:null!=(f=null!=(d=t.request_id)?d:t.id)?f:o,model:this.modelName,seq:m,choices:S}))}}finally{b||await y.cancel().catch(()=>{}),y.releaseLock()}if(i)return;r.close();const w=[...h.entries()].map(([e,t])=>c(a({},t.fields),{index:e,message:a({role:"assistant",content:t.content},t.reasoning_content?{reasoning_content:t.reasoning_content}:{}),finish_reason:t.finish_reason}));s.resolve(c(a({},g),{request_id:"string"==typeof g.request_id?g.request_id:"string"==typeof g.id?g.id:o,model:this.modelName,choices:w,usage:G(p)}))}catch(e){if(i)return;const t=Z(e,n);this.reportError(t,"streamText"),r.error(t),s.reject(t)}finally{n.cleanup()}})()},cancel:e=>{i||(i=!0,n.controller.abort(e),n.cleanup(),s.reject(new I({code:O,message:"AI stream was canceled by consumer"})))}}));return Object.defineProperties(u,{request_id:{enumerable:!0,value:o},result:{enumerable:!0,value:s.promise}}),u}}const re=new WeakMap;function ne(e){const t=re.get(e);if(!t)throw new Error("AI model is not initialized");return t}class oe{constructor(e){this.generateText=async(e,t)=>ne(this).doGenerate(e,t),this.streamText=async(e,t)=>ne(this).doStream(e,t),re.set(this,e)}}const se=new WeakMap;class ie{constructor(e,t,r,n,o){this.createModel=e=>{const{request:t,getBaseUrl:r,getAppId:n,getSubUrl:o,onError:s}=function(e){const t=se.get(e);if(!t)throw new Error("AI is not initialized");return t}(this);return new oe(new te(t,r,e,n,o,s))},se.set(this,{request:e,getBaseUrl:t,getAppId:r,getSubUrl:n,onError:o})}}const ae="https://edith.xiaohongshu.com";function ce({getAppId:e,getGateway:t,getBusinessLine:r,onError:n,request:o}){if(!o)throw new Error("`request` is required!");return new ie(o,()=>{var e;return function(e){if("string"!=typeof e||!e.trim())throw new Error("`gateway` must be a non-empty HTTPS URL");const t=e.trim();let r;try{r=new URL(t)}catch(e){throw new Error("`gateway` must be an absolute HTTPS URL")}if(n=r,"https:"!==n.protocol&&("http:"!==n.protocol||"localhost"!==n.hostname&&"127.0.0.1"!==n.hostname&&"[::1]"!==n.hostname))throw new Error("`gateway` must use HTTPS (HTTP is allowed only for loopback development)");var n;return t.replace(/\\/+$/,"")}(null!=(e=null==t?void 0:t())?e:ae)},()=>{return(null==(t=null==e?void 0:e())?void 0:t.trim())||void 0;var t},()=>function(e){switch(null==e?void 0:e.trim()){case"creator":return q.creator;case"mars":return q.mars;default:return q.default}}(null==r?void 0:r()),n)}function le(e){var t;const r=null==(t=null==e?void 0:e.$xhs)?void 0:t.launchOptions;return!r||"object"!=typeof r||Array.isArray(r)?{}:r}function ue(e){return(t={})=>v("getLaunchOptions",t,{target:e})}const de=10001;let fe=0;class pe{constructor(e){this.target=e,this.id=(fe+=1,`xhs_request_${Date.now().toString(36)}_${fe.toString(36)}`),this.chunkCallbacks=new Set,this.headersCallbacks=new Set,this.terminal=!1}get isSettled(){return this.terminal}abort(){this.terminal||(this.terminal=!0,this.dispose(),Promise.resolve(v("abortRequest",{taskId:this.id},{target:this.target})).catch(()=>{}))}onChunkReceived(e){this.terminal||"function"!=typeof e||(this.chunkCallbacks.add(e),this.chunkSubscription||(this.chunkSubscription=h("onEventStream",({payload:e})=>{if(!this.terminal&&(null==e?void 0:e.taskId)===this.id&&"string"==typeof e.chunk)for(const t of[...this.chunkCallbacks])t({data:e.chunk})},this.target)))}offChunkReceived(e){var t;e?this.chunkCallbacks.delete(e):this.chunkCallbacks.clear(),0===this.chunkCallbacks.size&&(null==(t=this.chunkSubscription)||t.remove(),this.chunkSubscription=void 0)}onHeadersReceived(e){this.terminal||"function"!=typeof e||(this.headersCallbacks.add(e),this.headersSubscription||(this.headersSubscription=h("onHeadersReceivedRequest",({payload:e})=>{if(this.terminal||(null==e?void 0:e.taskId)!==this.id)return;const t=e,{taskId:r}=t,n=l(t,["taskId"]);for(const e of[...this.headersCallbacks])e(n)},this.target)))}offHeadersReceived(e){var t;e?this.headersCallbacks.delete(e):this.headersCallbacks.clear(),0===this.headersCallbacks.size&&(null==(t=this.headersSubscription)||t.remove(),this.headersSubscription=void 0)}settle(){this.terminal||(this.terminal=!0,this.dispose())}dispose(){var e,t;null==(e=this.chunkSubscription)||e.remove(),null==(t=this.headersSubscription)||t.remove(),this.chunkSubscription=void 0,this.headersSubscription=void 0,this.chunkCallbacks.clear(),this.headersCallbacks.clear()}}function me(e,t){return function(r){var n,o,s,i,a;const c=new pe(e);if((l=r.data)instanceof ArrayBuffer||ArrayBuffer.isView(l))return function(e,t,r){ge(e,t,r,"request data does not support ArrayBuffer")}(t,c,r),c;var l;if(void 0!==r.responseType&&"text"!==r.responseType)return function(e,t,r){ge(e,t,r,"request responseType only supports text")}(t,c,r),c;const u={taskId:c.id,url:r.url,method:null!=(n=r.method)?n:"GET",header:r.header,data:r.data,dataType:null!=(o=r.dataType)?o:"json",responseType:null!=(s=r.responseType)?s:"text",timeout:null!=(i=r.timeout)?i:6e4,enableChunked:null!=(a=r.enableChunked)&&a,success(e){var t;null==(t=r.success)||t.call(r,e)},fail(e){var t;null==(t=r.fail)||t.call(r,e)},complete(e){var t;c.settle(),null==(t=r.complete)||t.call(r,e)}};return setTimeout(()=>{c.isSettled||v(t,u,{target:e})},0),c}}function ge(e,t,r,n){const o={errMsg:`${e}:fail ${n}`,errCode:de};setTimeout(()=>{var e,n;if(!t.isSettled){t.settle();try{null==(e=r.fail)||e.call(r,o)}finally{null==(n=r.complete)||n.call(r,o)}}},0)}function he(e){return me(e,"request")}function ve(e){return me(e,"xhsRequest")}function ye(e,t,r){const n="stream"===t.responseType||!0===t.stream;return new Promise((o,s)=>{let i,a,c=!1,l=!1;const u=n?new ReadableStream({start(e){a=e},cancel(){g(_e())}}):void 0,d=t.signal,f=()=>g(_e()),p=()=>!c&&(c=!0,null==d||d.removeEventListener("abort",f),!0),m=e=>{if(!p())return;const t=function(e){if(e instanceof Error)return e;if(function(e){return Boolean(e&&"object"==typeof e&&"errMsg"in e)}(e)){const t=new Error(e.errMsg);return t.name="XhsBridgeError",void 0!==e.errCode&&(t.errCode=e.errCode),t}return new Error(String(e))}(e);l?null==a||a.error(t):s(t)},g=e=>{null==i||i.abort(),m(e)},h=e=>{l||(l=!0,o(e))};i=e({url:t.url,method:we(r),header:t.headers,data:t.data,dataType:n?"text":"json",responseType:"text",enableChunked:n,success(e){if(!c)return u?(h(be(e,u)),void(p()&&(null==a||a.close()))):void(p()&&h(function(e){return{statusCode:e.statusCode,headers:e.header,data:e.data}}(e)))},fail:m}),u&&(i.onHeadersReceived(e=>{h(be(e,u))}),i.onChunkReceived(({data:e})=>{c||null==a||a.enqueue(e)})),(null==d?void 0:d.aborted)?f():null==d||d.addEventListener("abort",f,{once:!0})})}function be(e,t){return{statusCode:e.statusCode,headers:e.header,data:t}}function we(e){return"get"===e?"GET":"POST"}function _e(){const e=new Error("request was aborted");return e.name="AbortError",e}function Se(e){return ce({getAppId:()=>{var t;return ke(null==(t=le(e).miniToolEnv)?void 0:t.appId)},getGateway:()=>{var t,r;return ke(null==(r=null==(t=le(e).miniToolEnv)?void 0:t.gateways)?void 0:r.edith)},getBusinessLine:()=>{var t;return ke(null==(t=le(e).miniToolEnv)?void 0:t.businessLine)},onError:(t,r)=>{var n;S(e,{type:"ai",name:r.model,message:t.message.slice(0,512),stack:null==(n=t.stack)?void 0:n.slice(0,512),code:t.code,request_id:t.requestId,details:t.details,model:r.model,operation:r.operation})},request:(t=ve(e),{get:e=>ye(t,e,"get"),post:e=>ye(t,e,"post")})});var t}function ke(e){if("string"!=typeof e)return;return e.trim()||void 0}const Ce="INVALID_ARGUMENT",Ee="NETWORK_ERROR",Ae="BAD_RESPONSE",qe="SERVER_ERROR";class je extends Error{constructor(e,t,r={}){super(t),this.name="CloudServiceError",this.code=e,void 0!==r.errCode&&(this.errCode=r.errCode),void 0!==r.details&&(this.details=r.details)}}function Oe(e,t,r,n,o={}){var s;const i=null!=(s=o.errCode)?s:t===Ce?de:void 0;throw S(n,{type:"jsapi",name:"CloudServiceError",message:`${e}: ${r}`.slice(0,512),details:a({api:e,code:t,errCode:i},o.details)}),new je(t,`${e}:fail ${r}`,c(a({},o),{errCode:i}))}const Ie={all:"ALL",month:"MONTH",week:"WEEK",day:"DAY"};function Te(e,t,r,n){t||Oe(e,Ce,r,n)}function Le(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function xe(e,t,r){return Te(e,"string"==typeof t&&t.trim().length>0,"collection must be a non-empty string",r),t.trim()}function $e(e,t,r){return void 0===t?1:(Te(e,"number"==typeof t&&Number.isInteger(t)&&t>=1&&t<=5,"board must be an integer between 1 and 5",r),t)}function Ne(e,t,r){return void 0===t?Ie.all:(Te(e,"string"==typeof t&&t in Ie,"period must be \'all\', \'month\', \'week\' or \'day\'",r),Ie[t])}function Re(e,t,r){return Te(e,"number"==typeof t&&Number.isFinite(t),"score must be a finite number",r),t}function Pe(e,t,r){Te(e,Array.isArray(t)&&t.length>0,"ids must be a non-empty array",r);const n=t,o=new Set;return n.map(t=>{Te(e,"string"==typeof t&&t.trim().length>0,"ids must contain non-empty strings",r);const n=t.trim();return Te(e,!o.has(n),`ids must not contain duplicates: ${n}`,r),o.add(n),n})}const Me=["success","fail","complete"];function De(e,t,r){!function(e){for(const t of Me){const r=null==e?void 0:e[t];if(void 0!==r&&"function"!=typeof r)throw new TypeError(`${t} must be a function`)}}(r);const{success:n,fail:o,complete:s}=null!=r?r:{};if(!(n||o||s))return t().then(t=>Ke(e,t),t=>{throw Be(e,t)});t().then(t=>{const r=Ke(e,t);try{null==n||n(r)}finally{null==s||s(r)}},t=>{const r=Be(e,t);try{null==o||o(r)}finally{null==s||s(r)}})}function Ke(e,t){return Le(t)?c(a({},t),{errMsg:`${e}:ok`}):{data:t,errMsg:`${e}:ok`}}function Be(e,t){if(t instanceof je){const e={errMsg:t.message};return void 0!==t.errCode&&(e.errCode=t.errCode),e}const r=t instanceof Error&&t.message?t.message:"";return{errMsg:r?`${e}:fail ${r}`:`${e}:fail`}}function Fe(e){var t,r,n;return null!=(n=Ue(null==(r=null==(t=le(e).miniToolEnv)?void 0:t.gateways)?void 0:r.edith))?n:ae}function He(e){var t;return Ue(null==(t=le(e).miniToolEnv)?void 0:t.businessLine)}function Ue(e){if("string"==typeof e)return e.trim()||void 0}const Je=Object.freeze({default:Object.freeze({batchCreate:"/api/sns/v1/creator/red_app/batch_create",batchUpdate:"/api/sns/v1/creator/red_app/batch_update",query:"/api/sns/v1/creator/red_app/query",batchDelete:"/api/sns/v1/creator/red_app/batch_delete",submitScore:"/api/sns/v1/creator/red_app/submit_score",queryTop100:"/api/sns/v1/creator/red_app/query_top_100",querySelfRank:"/api/sns/v1/creator/red_app/query_self_rank"}),creator:Object.freeze({batchCreate:"/api/sns/v1/creator/red_app/creator/batch_create",batchUpdate:"/api/sns/v1/creator/red_app/creator/batch_update",query:"/api/sns/v1/creator/red_app/creator/query",batchDelete:"/api/sns/v1/creator/red_app/creator/batch_delete",submitScore:"/api/sns/v1/creator/red_app/creator/submit_score",queryTop100:"/api/sns/v1/creator/red_app/creator/query_top_100",querySelfRank:"/api/sns/v1/creator/red_app/creator/query_self_rank"}),mars:Object.freeze({batchCreate:"/api/sns/v1/creator/red_app/mars/batch_create",batchUpdate:"/api/sns/v1/creator/red_app/mars/batch_update",query:"/api/sns/v1/creator/red_app/mars/query",batchDelete:"/api/sns/v1/creator/red_app/mars/batch_delete",submitScore:"/api/sns/v1/creator/red_app/mars/submit_score",queryTop100:"/api/sns/v1/creator/red_app/mars/query_top_100",querySelfRank:"/api/sns/v1/creator/red_app/mars/query_self_rank"})});function ze(e,t){switch(null==e?void 0:e.trim()){case"creator":return Je.creator[t];case"mars":return Je.mars[t];default:return Je.default[t]}}function Ge(e){const t=ve(e);return{post(r,n,o){const s=function(e){var t;return Ue(null==(t=le(e).miniToolEnv)?void 0:t.appId)}(e);s||Oe(r,Ce,"appId is unavailable: launchOptions.miniToolEnv.appId is missing",e);const i=a({request_context:{env:"prod",app_id:s}},o);return new Promise((o,s)=>{t({url:j(Fe(e),ze(He(e),n)),method:"POST",header:{"Content-Type":"application/json"},data:i,dataType:"json",success(t){try{o(function(e,t,r,n){var o;const s=Xe(t),i=s?Xe(s.data):void 0,a=i?Xe(i.result):void 0;if(!s||!i||!a){Oe(e,!1===(null==s?void 0:s.success)||void 0!==r&&(r<200||r>=300)?Ee:Ae,null!=(o=We(null==s?void 0:s.msg))?o:`unexpected response (statusCode=${r})`,n,{details:{statusCode:r,gatewayCode:null==s?void 0:s.code,body:Ve(t)}})}const c="number"==typeof a.code?a.code:!0===a.success?0:void 0,l=We(a.message);void 0===c&&Oe(e,qe,null!=l?l:"response is missing a numeric result code",n,{details:{statusCode:r}});if(0!==c&&2003!==c)throw new je(String(c),`${e}:fail ${null!=l?l:String(c)}`,{errCode:c});return i}(r,t.data,t.statusCode,e))}catch(e){s(e)}},fail(t){try{Oe(r,Ee,t.errMsg||"request failed",e,{errCode:t.errCode,details:{errCode:t.errCode}})}catch(e){s(e)}}})})}}}function Xe(e){if("string"==typeof e)try{return Xe(JSON.parse(e))}catch(e){return}if("object"==typeof e&&null!==e&&!Array.isArray(e))return e}function We(e){return"string"==typeof e&&e?e:void 0}function Ve(e){try{return("string"==typeof e?e:JSON.stringify(e)||"").slice(0,256)}catch(e){return""}}const Ye="DESC",Qe="addCloudStorage",Ze="updateCloudStorage",et="queryCloudStorage",tt="removeCloudStorage";function rt(e){const t=Ge(e);return{addCloudStorage:r=>De(Qe,()=>async function(e,t,r){const n=nt(Qe,t,r),o=xe(Qe,n.collection,r),s=ot(Qe,n.items,r),i=s.map((e,t)=>(Te(Qe,Le(e.content),`items[${t}].content must be an object`,r),{content_json:JSON.stringify(e.content)})),a=await e.post(Qe,"batchCreate",{collection:o,items:i});return st(Qe,a,i.map(()=>{}),r)}(t,r,e),r),updateCloudStorage:r=>De(Ze,()=>async function(e,t,r){const n=nt(Ze,t,r),o=xe(Ze,n.collection,r),s=ot(Ze,n.items,r),i=new Set,a=s.map((e,t)=>{Te(Ze,"string"==typeof e.id&&e.id.trim().length>0,`items[${t}].id must be a non-empty string`,r);const n=e.id.trim();return Te(Ze,!i.has(n),`items must not repeat id: ${n}`,r),i.add(n),Te(Ze,Le(e.content),`items[${t}].content must be an object`,r),{id:n,content_json:JSON.stringify(e.content)}}),c=await e.post(Ze,"batchUpdate",{collection:o,items:a});return st(Ze,c,a.map(e=>e.id),r)}(t,r,e),r),queryCloudStorage:(r={})=>De(et,()=>async function(e,t,r){var n,o;const s=nt(et,t,r),i=function(e,t){var r;const n=void 0!==e.ids,o=void 0!==e.collection;if(n)return{mode:"BY_IDS",collection:xe(et,e.collection,t),ids:Pe(et,e.ids,t)};const s=null!=(r=function(e,t,r){if(void 0!==t)return Te(e,"number"==typeof t&&Number.isInteger(t)&&t>0,"limit must be a positive integer",r),t}(et,e.limit,t))?r:20,i=function(e,t,r){if(null!=t)return Te(e,"string"==typeof t&&t.length>0,"cursor must be a non-empty string",r),t}(et,e.cursor,t);if(o)return a({mode:"COLLECTION",collection:xe(et,e.collection,t),sort_by:Ye,limit:s},void 0===i?{}:{cursor:i});return a({mode:"APP_ALL",limit:s},void 0===i?{}:{cursor:i})}(s,r),c=await e.post(et,"query",i),l=Le(c)&&Le(c.data)?c.data:void 0;l&&Array.isArray(l.items)||Oe(et,Ae,"response is missing data.data.items",r);const u={items:l.items.map(e=>function(e,t,r){const n=Le(t)?t:void 0;n&&"string"==typeof n.id&&"string"==typeof n.content_json||Oe(e,Ae,"record is missing id or content_json",r);let o;try{o=JSON.parse(n.content_json)}catch(e){o=void 0}Le(o)||Oe(e,Ae,"record.content_json is not a JSON object",r);return{id:n.id,collection:"string"==typeof n.collection?n.collection:"",content:o}}(et,e,r))};("next_cursor"in l||"nextCursor"in l)&&(u.nextCursor="string"==typeof(d=null!=(n=l.next_cursor)?n:l.nextCursor)&&d?d:null);var d;("has_more"in l||"hasMore"in l)&&(u.hasMore=!0===(null!=(o=l.has_more)?o:l.hasMore));return u}(t,r,e),r),removeCloudStorage:r=>De(tt,()=>async function(e,t,r){const n=nt(tt,t,r),o=Pe(tt,n.ids,r),s=await e.post(tt,"batchDelete",{collection:xe(tt,n.collection,r),ids:o});return st(tt,s,o,r)}(t,r,e),r)}}function nt(e,t,r){return Te(e,Le(t),"options must be an object",r),t}function ot(e,t,r){return Te(e,Array.isArray(t)&&t.length>0,"items must be a non-empty array",r),t.map((t,n)=>(Te(e,Le(t),`items[${n}] must be an object`,r),t))}function st(e,t,r,n){const o=function(e,t,r){const n=Le(t)?t:void 0;return n&&Array.isArray(n.results)||Oe(e,Ae,"response is missing data.results",r),n.results.map((t,n)=>(Te(e,Le(t),`data.results[${n}] must be an object`,r),t))}(e,t,n);o.length!==r.length&&Oe(e,Ae,`data.results length ${o.length} does not match request items ${r.length}`,n);const s=new Map;for(const e of o)for(const t of[e.item_id,e.id])"string"==typeof t&&t&&s.set(t,e);return r.map((t,r)=>{var i;const a=null!=(i=void 0!==t?s.get(t):void 0)?i:o[r];return function(e,t,r,n){const{id:o,status:s}=t;"string"!=typeof s&&Oe(e,Ae,"per-item result is missing status",n);return{id:"string"==typeof o?o:"string"==typeof r?r:"",status:s}}(e,a,t,n)})}function it(e){return(t={})=>v("followAuthor",t,{target:e})}function at(e){return(t={})=>v("getFollowStatus",t,{target:e})}class ct extends Error{constructor(e){super(e),this.code=de,this.name="JsApiParamError"}}function lt(e,t,r,n){t||function(e,t,r){throw S(r,{type:"jsapi",name:"JsApiParamError",message:t,code:de,details:{api:e}}),new ct(t)}(e,r,n)}function ut(e){return(t={})=>v("getLocation",t,{target:e,validate:t=>function(e,t){const{type:r}=e;lt("getLocation",void 0===r||"wgs84"===r||"gcj02"===r,\'type must be "wgs84" or "gcj02"\',t)}(t,e)})}function dt(e){return(t={})=>v("getWindowInfo",t,{target:e})}const ft=["game","ui","normal"],pt="startGyroscope";function mt(e){return(t={})=>v(pt,t,{target:e,validate:t=>function(e,t){const{interval:r}=e;lt(pt,void 0===r||ft.includes(r),\'interval must be "game", "ui" or "normal"\',t)}(t,e)})}function gt(e){return(t={})=>v("stopGyroscope",t,{target:e})}const ht=new WeakMap;function vt(e){let t=ht.get(e);return t||(t={callbacks:new Set},ht.set(e,t)),t}function yt(e){return t=>{if("function"!=typeof t)throw new TypeError("onGyroscopeChange callback must be a function");const r=null!=e?e:u();if(!r)throw new Error("window is unavailable");const n=vt(r);if(n.callbacks.has(t))return;if(n.callbacks.add(t),n.subscription)return;n.subscription=h("onGyroscopeChange",({payload:e})=>{for(const t of[...n.callbacks])try{t(e)}catch(e){}},r)}}function bt(e){return t=>{var r;if(void 0!==t&&"function"!=typeof t)throw new TypeError("offGyroscopeChange callback must be a function");const n=null!=e?e:u();if(!n)throw new Error("window is unavailable");const o=vt(n);t?o.callbacks.delete(t):o.callbacks.clear(),o.callbacks.size>0||(null==(r=o.subscription)||r.remove(),o.subscription=void 0)}}function wt(e){return t=>v("interactionOpenApi",t,{target:e})}const _t="submitScore",St="getRankList",kt="getMyRank";function Ct(e){const t=Ge(e);return{submitScore:r=>De(_t,()=>async function(e,t,r){var n;const o=Et(_t,t,r),s=await e.post(_t,"submitScore",{rank_code:$e(_t,o.board,r),score:Re(_t,o.score,r)}),i=At(_t,s,r),a=qt(null!=(n=i.bestScore)?n:i.best_score);void 0===a&&Oe(_t,Ae,"response is missing data.data.bestScore",r);return{score:a}}(t,r,e),r),getRankList:(r={})=>De(St,()=>async function(e,t,r){const n=Et(St,t,r),o=await e.post(St,"queryTop100",{rank_code:$e(St,n.board,r),rank_type:Ne(St,n.period,r),limit:100}),s=At(St,o,r);Array.isArray(s.items)||Oe(St,Ae,"response is missing data.data.items",r);return s.items.map((e,t)=>{var n;Te(St,Le(e),`data.items[${t}] is malformed`,r);const o=e,s=qt(o.score);return"number"==typeof o.rank&&void 0!==s||Oe(St,Ae,`data.items[${t}] is missing rank or score`,r),{rank:o.rank,score:s,nickname:jt(o.nickname),avatar:jt(null!=(n=o.avatar_url)?n:o.avatarUrl)}})}(t,r,e),r),getMyRank:(r={})=>De(kt,()=>async function(e,t,r){var n;const o=Et(kt,t,r),s=await e.post(kt,"querySelfRank",{rank_code:$e(kt,o.board,r),rank_type:Ne(kt,o.period,r)}),i=At(kt,s,r),a=void 0!==i.self_rank?i.self_rank:i.self,c=Le(a)?a:void 0;c&&"string"==typeof c.status||Oe(kt,Ae,"response is missing data.data.self_rank.status",r);return{status:c.status,rank:Ot(c.rank),score:null!=(n=qt(c.score))?n:null}}(t,r,e),r)}}function Et(e,t,r){return Te(e,Le(t),"options must be an object",r),t}function At(e,t,r){const n=Le(t)?t.data:void 0;return Le(n)||Oe(e,Ae,"response is missing data.data",r),n}function qt(e){if("number"==typeof e)return Number.isFinite(e)?e:void 0;if("string"==typeof e&&""!==e.trim()){const t=Number(e);return Number.isFinite(t)?t:void 0}}function jt(e){return"string"==typeof e&&e?e:null}function Ot(e){return"number"==typeof e&&Number.isFinite(e)?e:null}function It(e){return t=>v("openRedPage",t,{target:e})}function Tt(e){return c(a({},e),{mediaInfo:JSON.stringify(e.mediaInfo||{})})}function Lt(e){return t=>v("postNote",t,{target:e,prepareRequest:Tt})}function xt(e){return t=>v("saveImageToPhotosAlbum",t,{target:e})}function $t(e){return(t={})=>v("clearStorage",t,{target:e})}function Nt(e){return t=>v("getStorage",t,{target:e})}function Rt(e){return(t={})=>v("getStorageInfo",t,{target:e})}function Pt(e){return t=>v("removeStorage",t,{target:e})}function Mt(e){return t=>v("setStorage",t,{target:e})}const Dt=["heavy","medium","light"],Kt="vibrateShort";function Bt(e){return t=>v(Kt,t,{target:e,validate:t=>function(e,t){const{type:r}=e;lt(Kt,Dt.includes(r),\'type must be "heavy", "medium" or "light"\',t)}(t,e)})}function Ft(e){return(t={})=>v("vibrateLong",t,{target:e})}function Ht(e){return t=>v("writeTempFile",t,{target:e})}const Ut="xhsOpenSiteLocation",Jt=["poi-detail","poi-list","path","navigation"];function zt(e){if(!e||"object"!=typeof e)return!1;const t=e;return"string"==typeof t.id&&t.id.length>0&&"number"==typeof t.latitude&&"number"==typeof t.longitude}function Gt(e){return t=>v("xhsOpenSiteLocation",t,{target:e,validate:t=>function(e,t){const{scene:r}=e;switch(lt(Ut,void 0!==r&&Jt.includes(r),\'scene must be "poi-detail" | "poi-list" | "path" | "navigation"\',t),r){case"poi-detail":lt(Ut,"string"==typeof e.id&&e.id.length>0,\'"poi-detail" requires a non-empty id\',t);break;case"poi-list":lt(Ut,Array.isArray(e.pois)&&e.pois.length>0,\'"poi-list" requires a non-empty pois array\',t);break;case"path":lt(Ut,zt(e.origin),\'"path" requires a valid origin { latitude, longitude, id }\',t),lt(Ut,zt(e.destination),\'"path" requires a valid destination { latitude, longitude, id }\',t);break;case"navigation":lt(Ut,zt(e.destination),\'"navigation" requires a valid destination { latitude, longitude, id }\',t)}}(t,e)})}function Xt(e){return c(a(a(a(a({},rt(e)),function(e){return{saveFile:t=>v("saveFile",t,{target:e}),writeFile:t=>v("writeFile",t,{target:e}),appendFile:t=>v("appendFile",t,{target:e}),readFile:t=>v("readFile",t,{target:e}),readDir:t=>v("readDir",t,{target:e}),statFile:t=>v("statFile",t,{target:e}),unlink:t=>v("unlink",t,{target:e}),mkdir:t=>v("mkdir",t,{target:e}),getFileStorageInfo:(t={})=>v("getFileStorageInfo",t,{target:e})}}(e)),Ct(e)),function(e){return{clearStorage:$t(e),getStorage:Nt(e),getStorageInfo:Rt(e),removeStorage:Pt(e),setStorage:Mt(e)}}(e)),{followAuthor:it(e),getFollowStatus:at(e),getLaunchOptions:ue(e),getLocation:ut(e),getWindowInfo:dt(e),interactionOpenApi:wt(e),offGyroscopeChange:bt(e),onGyroscopeChange:yt(e),postNote:Lt(e),request:he(e),saveImageToPhotosAlbum:xt(e),startGyroscope:mt(e),stopGyroscope:gt(e),openRedPage:It(e),vibrateLong:Ft(e),vibrateShort:Bt(e),xhsOpenSiteLocation:Gt(e),writeTempFile:Ht(e)})}function Wt(e){throw Object.assign(new Error(`invalid parameter; param=${e}`),{code:10001})}function Vt(e){throw Object.assign(new Error(`payload too large; param=${e}`),{code:10002})}function Yt(e,t,r=0,n=new Set){if(null===e||"string"==typeof e||"boolean"==typeof e)return;if("number"==typeof e)return void(Number.isFinite(e)||Wt(t));"object"!=typeof e&&Wt(t),n.has(e)&&Wt(t),r>5&&Vt(t);const o=Array.isArray(e),s=Object.getPrototypeOf(e);o||null===s||null===Object.getPrototypeOf(s)||Wt(t);for(let r=e;null!==r;r=Object.getPrototypeOf(r)){const e=Object.getOwnPropertyDescriptor(r,"toJSON");if(e){"value"in e&&"function"!=typeof e.value||Wt(t);break}}n.add(e);const i=Object.keys(e);o&&i.length!==e.length&&Wt(t);for(const s of Reflect.ownKeys(e)){const i=Object.getOwnPropertyDescriptor(e,s);i.enumerable&&("string"==typeof s&&"value"in i||Wt(t),o&&(!/^(0|[1-9]\\d*)$/.test(s)||Number(s)>=e.length)&&Wt(t),Yt(i.value,`${t}.${s}`,r+1,n))}n.delete(e)}function Qt(e,t,r){const n=JSON.stringify(e);(new TextEncoder).encode(n).byteLength>t&&Vt(r)}function Zt(e){const t=e,{success:r,complete:n,fail:o}=t,s=l(t,["success","complete","fail"]);if(Yt(s,"message"),"params"in s&&Qt(s.params,4096,"params"),s.index&&"object"==typeof s.index)for(const[e,t]of Object.entries(s.index))"string"==typeof t&&[...t].length>256&&Vt(`index.${e}`);return Qt(s,8192,"message"),s}function er(e){return t=>v("reportUba",t,{target:e,prepareRequest:Zt})}const tr=Symbol.for("xhs.internal");"undefined"!=typeof window&&(function(e={}){var t;const r=null!=(t=e.target)?t:u();if(!r)throw new Error("window is unavailable");if(g(r),!r.xhs||e.force){const e=Object.freeze({AI:Se(r),config:()=>{},get launchOptions(){return le(r)},miniTool:Object.freeze(c(a(a({},Xt(r)),{}),{version:"0.4.3"}))});r.xhs=e}!function(e){Object.prototype.hasOwnProperty.call(e,tr)||Object.defineProperty(e,tr,{get:()=>Object.freeze({reportUba:er(e)}),set(e){},configurable:!1,enumerable:!1})}(r)}({target:window}),function(e={}){var t,r;const n=null!=(t=e.target)?t:"undefined"==typeof window?void 0:window;if(!n)return;const o=n,s=n;if(s[_])return;s[_]=!0;const i=new Set;function a(e){try{const t=JSON.stringify(e);if(i.has(t))return;i.add(t),S(o,e)}catch(e){}}n.addEventListener("error",e=>{var t;try{const r=e,o=r.target;if(o&&o!==n&&o.tagName)return void a({type:"error",name:"ResourceError",message:`${o.tagName} 资源加载失败`,source:String(o.tagName).toLowerCase(),url:String(o.src||o.href||"")});const s=null!=(t=r.error)?t:{};a({type:"error",name:s.name||"Error",message:(r.message||String(s.message||"")).slice(0,512),source:`${r.filename||""}:${r.lineno||0}:${r.colno||0}`,url:r.filename||"",stack:s.stack?String(s.stack).slice(0,512):""})}catch(e){}},!0),n.addEventListener("unhandledrejection",e=>{try{const t=e.reason;let r="UnhandledRejection",n="",o="";if(t&&"object"==typeof t){const e=t;r=e.name||r,n=e.message||String(t),o=e.stack?String(e.stack).slice(0,512):""}else n=String(t);a({type:"unhandledrejection",name:r,message:n.slice(0,512),stack:o})}catch(e){}}),null==(r=n.document)||r.addEventListener("securitypolicyviolation",e=>{try{a({type:"securitypolicyviolation",name:"CSPViolation",disposition:e.disposition||"",effective_directive:e.effectiveDirective||"",violated_directive:e.violatedDirective||"",blocked_uri:e.blockedURI||"",source_file:e.sourceFile||"",line_number:e.lineNumber||0,column_number:e.columnNumber||0,original_policy:e.originalPolicy||""})}catch(e){}});try{const e=n,t=e.fetch;"function"==typeof t&&(e.fetch=function(e,r){const n=function(e){try{return"string"==typeof e?e:String(e&&"object"==typeof e&&"url"in e?e.url:e)}catch(e){return""}}(e);return t.call(this,e,r).then(e=>e,e=>{throw a({type:"fetch",name:C(e),message:(k(e)||"fetch failed").slice(0,512),url:n,stack:E(e)}),e})})}catch(e){}}({target:window}))});', Vo = ko, Io = /<meta[^>]+name=["']x-miniapp-jsapi-mode["'][^>]+content=["']external["'][^>]*>/i, Lo = /<script[^>]+src=["'][^"']*miniapp-js-api[^"']*\.umd[^"']*["']/i;
3458
+ `, ko = '/*! xhs-script-version=0.4.3 */\n!function(e){"function"==typeof define&&define.amd?define(e):e()}(function(){"use strict";var e=Object.defineProperty,t=Object.defineProperties,r=Object.getOwnPropertyDescriptors,n=Object.getOwnPropertySymbols,o=Object.prototype.hasOwnProperty,s=Object.prototype.propertyIsEnumerable,i=(t,r,n)=>r in t?e(t,r,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[r]=n,a=(e,t)=>{for(var r in t||(t={}))o.call(t,r)&&i(e,r,t[r]);if(n)for(var r of n(t))s.call(t,r)&&i(e,r,t[r]);return e},c=(e,n)=>t(e,r(n)),l=(e,t)=>{var r={};for(var i in e)o.call(e,i)&&t.indexOf(i)<0&&(r[i]=e[i]);if(null!=e&&n)for(var i of n(e))t.indexOf(i)<0&&s.call(e,i)&&(r[i]=e[i]);return r};function u(){return"undefined"==typeof window?void 0:window}let d,f,p=!1;const m=new WeakMap;function g(e){p||(!function(e){var t;if(d)return d;const r=[null==(t=e.webkit)?void 0:t.messageHandlers,e].find(e=>{var t;return"function"==typeof(null==(t=null==e?void 0:e.xhsInvoke)?void 0:t.postMessage)}),n=null==r?void 0:r.xhsInvoke;if(!n)throw new Error("xhsInvoke unavailable");if(!Reflect.defineProperty(r,"xhsInvoke",{value:void 0,writable:!1,configurable:!1,enumerable:!1})||void 0!==r.xhsInvoke)throw new Error("Failed to hide xhsInvoke");f=r,d=n}(e),null!=e.XHS_SDK_CALLBACKS||(e.XHS_SDK_CALLBACKS={}),null!=e.XHS_SDK_CALLBACKS_ID||(e.XHS_SDK_CALLBACKS_ID=0),m.set(e,new Map),e.XHS_SDK_INVOKE_CALLBACKS=(t,r)=>{var n,o;const s=null==(n=e.XHS_SDK_CALLBACKS)?void 0:n[r];if(!s)return;null==(o=e.XHS_SDK_CALLBACKS)||delete o[r];const i=function(e){if("string"!=typeof e)return null!=e?e:{code:-1,msg:"empty bridge result"};try{const t=JSON.parse(e);return t&&"object"==typeof t?t:{code:-1,msg:"invalid bridge result"}}catch(t){return{code:-1,msg:e||"invalid bridge result"}}}(t);0===i.code?function(e,t){var r,n,o;const s=t&&"object"==typeof t&&!Array.isArray(t)?c(a({},t),{errMsg:`${e.api}:ok`}):void 0===t?{errMsg:`${e.api}:ok`}:{data:t,errMsg:`${e.api}:ok`};null==(r=e.resolve)||r.call(e,s);try{null==(n=e.success)||n.call(e,s)}finally{null==(o=e.complete)||o.call(e,s)}}(s,i.data):function(e,t){var r,n,o;null==(r=e.reject)||r.call(e,t);try{null==(n=e.fail)||n.call(e,t)}finally{null==(o=e.complete)||o.call(e,t)}}(s,{errMsg:`${s.api}:fail${i.msg?` ${i.msg}`:""}`,errCode:i.code})},e.XHS_SDK_EVENTS_CALLBACKS=t=>{var r;const n=function(e){let t;if("string"==typeof e)try{t=JSON.parse(e)}catch(e){return}else t=e;return"events"===(null==t?void 0:t.type)&&"string"==typeof t.method?t:void 0}(t);if(!n)return;const o=null==(r=m.get(e))?void 0:r.get(n.method);if(o)for(const e of[...o])e(n)},p=!0)}function h(e,t,r=u()){var n;if(!r)throw new Error("window is unavailable");if(!e||"function"!=typeof t)throw new TypeError("invalid event subscription");const o=m.get(r);if(!o)throw new Error("bridge is not initialized");const s=t,i=null!=(n=o.get(e))?n:new Set;return i.add(s),o.set(e,i),{remove(){const t=o.get(e);null==t||t.delete(s),0===(null==t?void 0:t.size)&&o.delete(e)}}}function v(e,t={},r={}){const{target:n,validate:o,prepareRequest:s}=r,i=t,{success:a,fail:c,complete:p}=i,m=l(i,["success","fail","complete"]);w("success",a),w("fail",c),w("complete",p);const g=!(a||c||p);let h=m;try{null==o||o(h),s&&(h=s(h))}catch(t){return y(e,t,g,c,p)}const v=null!=n?n:u();if(!v)return y(e,new Error("window is unavailable"),g,c,p);let _,S;const k=new Promise((e,t)=>{_=e,S=t}),C="xhs_"+ ++v.XHS_SDK_CALLBACKS_ID;v.XHS_SDK_CALLBACKS[C]=g?{api:e,resolve:_,reject:S}:{api:e,success:a,fail:c,complete:p};try{!function(e){if(!d||!f||void 0!==f.xhsInvoke)throw new Error("xhsInvoke bridge is unavailable");d.postMessage(e)}(JSON.stringify({event:e,message:h,callbackId:C}))}catch(t){delete v.XHS_SDK_CALLBACKS[C];const r=b(e,t);return g?(null==S||S(r),k):(null==c||c(r),void(null==p||p(r)))}return g?k:void 0}function y(e,t,r,n,o){const s=b(e,t);if(r)return Promise.reject(s);null==n||n(s),null==o||o(s)}function b(e,t){const r=t instanceof Error?t.message:String(t),n=t&&"object"==typeof t&&"code"in t&&"number"==typeof t.code?t.code:void 0;return a({errMsg:`${e}:fail ${r}`},void 0===n?{}:{errCode:n})}function w(e,t){if(void 0!==t&&"function"!=typeof t)throw new TypeError(`${e} must be a function`)}const _="__xhsErrorMonitorInstalled__";function S(e,t){try{const r=v("reportTracker",{eventName:"minitool_error",data:t},{target:e});r&&r.catch(()=>{})}catch(e){}}function k(e){return e instanceof Error?e.message:String(e&&"object"==typeof e&&"message"in e?e.message:e)}function C(e){return e instanceof Error?e.name||"Error":e&&"object"==typeof e&&"name"in e&&String(e.name)||"Error"}function E(e){const t=e instanceof Error?e.stack:null==e?void 0:e.stack;return t?String(t).slice(0,512):""}class A{constructor(){this.aborted=!1,this.listeners=new Set}addEventListener(e,t,r){"abort"===e&&t&&this.listeners.add(t)}removeEventListener(e,t){"abort"===e&&t&&this.listeners.delete(t)}abort(e){if(this.aborted)return;this.aborted=!0,this.reason=e;const t={type:"abort",target:this,currentTarget:this},r=[...this.listeners];this.listeners.clear();for(const e of r)"function"==typeof e?e.call(this,t):e.handleEvent(t)}}const q=Object.freeze({default:"/api/sns/v1/creator/red_app/chat/completions",creator:"/api/sns/v1/creator/red_app/creator/chat/completions",mars:"/api/sns/v1/creator/red_app/mars/chat/completions"});function j(e,t){return`${e.replace(/\\/+$/,"")}/${t.replace(/^\\/+/,"")}`}const O=-104001;class I extends Error{constructor(e){super(e.message),this.name="AIError",this.code=e.code,this.requestId=e.requestId,this.details=e.details}}function T(e){if(e instanceof I)return e;const t=function(e){return x(e)&&"number"==typeof e.errCode?e.errCode:void 0}(e);return new I({code:O,message:L(e),details:void 0===t?void 0:{bridgeCode:t}})}function L(e){if(e instanceof Error)return e.message;if(x(e)){if("string"==typeof e.errMsg)return e.errMsg;if("string"==typeof e.message)return e.message}return"string"==typeof e?e:"AI request failed"}function x(e){return null!==e&&"object"==typeof e}const $=[239,187,191];const N=Symbol.for("Symbol.asyncIterator"),R="symbol"==typeof Symbol.asyncIterator?Symbol.asyncIterator:N;function P(e){const t=e;if("function"==typeof e[R])return t;const r=()=>{const t=e.getReader();let r=!1;const n=()=>{r||(r=!0,t.releaseLock())},o={async next(){try{const e=await t.read();return e.done&&n(),e}catch(e){throw n(),e}},async return(){try{await t.cancel()}finally{n()}return{done:!0,value:void 0}}};return Object.defineProperty(o,R,{value:()=>o}),o};return Object.defineProperty(e,R,{configurable:!0,value:r}),R!==N&&Object.defineProperty(e,N,{configurable:!0,value:r}),t}function M(e){const t=function(e){if("getReader"in e){const t=e.getReader();let r=!1;const n=()=>{r||(r=!0,t.releaseLock())};return new ReadableStream({async pull(e){try{const r=await t.read();r.done?(n(),e.close()):e.enqueue(r.value)}catch(t){n(),e.error(t)}},async cancel(e){var r;try{await(null==(r=t.cancel)?void 0:r.call(t,e))}finally{n()}}})}const t=e[R].call(e);return new ReadableStream({async pull(e){const r=await t.next();r.done?e.close():e.enqueue(r.value)},async cancel(e){var r;await(null==(r=t.return)?void 0:r.call(t,e))}})}(e).getReader();let r,n=!1,o=!1;const s=()=>{o||(o=!0,t.releaseLock())};return P(new ReadableStream({start(e){r=function(e){let t,r,n,o,s,i,a;return c(),{feed:function(e){r=r?r+e:e,t&&function(e){return $.every((t,r)=>e.charCodeAt(r)===t)}(r)&&(r=r.slice($.length)),t=!1;const{length:s}=r;let i=0,a=!1;for(;i<s;){a&&("\\n"===r[i]&&(i+=1),a=!1);let e,t=-1,c=o;for(let o=n;t<0&&o<s;o++)e=r[o],":"===e&&c<0?c=o-i:"\\r"===e?(a=!0,t=o-i):"\\n"===e&&(t=o-i);if(t<0){n=s-i,o=c;break}n=0,o=-1,l(r,i,c,t),i+=t+1}i===s?r="":i>0&&(r=r.slice(i))},reset:c};function c(){t=!0,r="",n=0,o=-1,s=void 0,i=void 0,a=""}function l(t,r,n,o){if(0===o)return a.length>0&&(e({type:"event",id:s,event:i||void 0,data:a.slice(0,-1)}),a="",s=void 0),void(i=void 0);const c=n<0,l=t.slice(r,r+(c?o:n));let u=0;u=c?o:" "===t[r+n+1]?n+2:n+1;const d=r+u,f=o-u,p=t.slice(d,d+f).toString();if("data"===l)a+=p?`${p}\\n`:"\\n";else if("event"===l)i=p;else if("id"!==l||p.includes("\\0")){if("retry"===l){const t=Number.parseInt(p,10);Number.isNaN(t)||e({type:"reconnect-interval",value:t})}}else s=p}}(t=>{if("event"===t.type&&"[DONE]"!==t.data)try{const r=JSON.parse(t.data);if(!r||"object"!=typeof r||Array.isArray(r))throw new TypeError("SSE data must be a JSON object");e.enqueue(r)}catch(e){throw new I({code:O,message:"AI chat gateway returned invalid SSE data",details:{cause:e instanceof Error?e.message:String(e)}})}}),(async()=>{try{for(;!n;){const o=await t.read();if(o.done)return n=!0,s(),void e.close();const i=o.value;i&&r.feed(i)}}catch(r){if(n)return;n=!0;try{await t.cancel(r)}catch(e){}finally{s()}e.error(r)}})()},async cancel(e){if(!n){n=!0;try{await t.cancel(e)}finally{s()}}}}))}class D{constructor(e,t,r){this.req=e,this.getBaseUrl=t,this.getSubUrl=r}}const K="x-minitool-appid",B=Object.freeze({max_output_tokens:1024,temperature:1});function F(e,t,r,n){var o,s;return function(e){z(e)||H("request");Array.isArray(e.messages)||H("messages");e.messages.forEach((e,t)=>{var r;z(e)||H(`messages[${t}]`),"string"==typeof(r=e.content)||"object"==typeof r&&null!==r||H(`messages[${t}].content`)}),U(e.max_output_tokens)||H("max_output_tokens");U(e.temperature)||H("temperature");U(e.top_p)||H("top_p");t=e.stop,void 0===t||"string"==typeof t||Array.isArray(t)&&t.every(e=>"string"==typeof e)||H("stop");var t;J(e.response_format)||H("response_format");J(e.thinking)||H("thinking");(function(e){return void 0===e||"string"==typeof e})(e.reasoning_effort)||H("reasoning_effort")}(t),c(a(a({},t),n?{app_id:n}:{}),{model:e,max_output_tokens:null!=(o=t.max_output_tokens)?o:B.max_output_tokens,temperature:null!=(s=t.temperature)?s:B.temperature,stream:r})}function H(e){throw new I({code:104001,message:`请求参数不合法:${e}`})}function U(e){return void 0===e||"number"==typeof e&&Number.isFinite(e)&&e>=0}function J(e){return void 0===e||z(e)}function z(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)}function G(e){var t,r,n;return c(a({},e),{prompt_tokens:null!=(t=null==e?void 0:e.prompt_tokens)?t:0,completion_tokens:null!=(r=null==e?void 0:e.completion_tokens)?r:0,total_tokens:null!=(n=null==e?void 0:e.total_tokens)?n:0})}function X(e){if(!Y(e))return;const t=W(e);return t||(Y(e.data)?W(e.data):void 0)}function W(e){var t,r;const n=void 0!==e.code&&0!==e.code;if(!1===e.success||n){const r=n&&void 0!==e.code?e.code:O;return new I({code:r,message:null!=(t=e.msg)?t:"AI chat request failed",requestId:e.request_id})}if(e.error)return new I({code:O,message:null!=(r=e.error.message)?r:"AI chat request failed",requestId:e.request_id,details:a(a({},void 0===e.error.code?{}:{providerCode:e.error.code}),void 0===e.error.retriable?{}:{retriable:e.error.retriable})})}function V(e,t){const r=X(e.data);if(r)throw r;if(void 0!==e.statusCode&&e.statusCode>=400)throw new I({code:O,message:`AI request failed with status ${e.statusCode}`,details:{statusCode:e.statusCode}});if(!e.data)throw new I({code:O,message:t});return e.data}function Y(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)}function Q(e){var t,r;const n=function(){if("function"==typeof AbortController)return new AbortController;const e=new A;return{signal:e,abort:t=>e.abort(t)}}();let o=!1;const s=()=>{var t;return n.abort(null==(t=null==e?void 0:e.signal)?void 0:t.reason)};(null==(t=null==e?void 0:e.signal)?void 0:t.aborted)?s():null==(r=null==e?void 0:e.signal)||r.addEventListener("abort",s,{once:!0});const i=void 0!==(null==e?void 0:e.timeoutMs)&&e.timeoutMs>0?setTimeout(()=>{o=!0,n.abort("timeout")},e.timeoutMs):void 0;return{controller:n,get timedOut(){return o},cleanup(){var t;void 0!==i&&clearTimeout(i),null==(t=null==e?void 0:e.signal)||t.removeEventListener("abort",s)}}}function Z(e,t){return t.timedOut?new I({code:O,message:"AI request timed out"}):t.controller.signal.aborted?new I({code:O,message:"AI request was aborted"}):T(e)}function ee(e,t=0){var r,n,o,s,i;const l=null!=(r=null==e?void 0:e.message)?r:{};return c(a({},e),{index:null!=(n=null==e?void 0:e.index)?n:t,message:c(a({},l),{role:null!=(o=l.role)?o:"assistant",content:null!=(s=l.content)?s:""}),finish_reason:null!=(i=null==e?void 0:e.finish_reason)?i:void 0})}class te extends D{constructor(e,t,r,n,o=()=>"/chat/completions",s){super(e,t,o),this.modelName=r,this.getAppId=n,this.onError=s}reportError(e,t){if(this.onError)try{Promise.resolve(this.onError(e,{model:this.modelName,operation:t})).catch(()=>{})}catch(e){}}requestOptions(e,t,r,n){var o;const s=null==(o=this.getAppId)?void 0:o.call(this),i=F(this.modelName,e,t,s);return{url:j(this.getBaseUrl(),this.getSubUrl()),method:"post",headers:a(a({"Content-Type":"application/json"},null==n?void 0:n.headers),s?{[K]:s}:{}),data:i,responseType:t?"stream":"json",stream:t,signal:r}}async doGenerate(e,t){var r;const n=Q(t);try{const o=await this.req.post(this.requestOptions(e,!1,n.controller.signal,t)),s=function(e){var t;if(!("code"in e||"success"in e||"msg"in e)||null===e.data||"object"!=typeof e.data||Array.isArray(e.data))return e;const r=e.data;return c(a({},r),{request_id:null!=(t=r.request_id)?t:e.request_id})}(V(o,"AI response is empty"));return function(e,t,r){var n,o,s;const i=(null==(n=e.choices)?void 0:n.length)?e.choices.map(ee):[ee(void 0)];return c(a({},e),{request_id:null!=(s=null!=(o=e.request_id)?o:e.id)?s:t,model:r,choices:i,usage:G(e.usage)})}(s,null!=(r=null==t?void 0:t.idempotencyKey)?r:this.modelName,this.modelName)}catch(e){const t=Z(e,n);throw this.reportError(t,"generateText"),t}finally{n.cleanup()}}async doStream(e,t){var r;const n=Q(t),o=null!=(r=null==t?void 0:t.idempotencyKey)?r:`chat_${Date.now().toString(36)}`,s=function(){let e,t;return{promise:new Promise((r,n)=>{e=r,t=n}),resolve:e,reject:t}}();s.promise.catch(()=>{});let i=n.controller.signal.aborted;const u=P(new ReadableStream({start:r=>{if(i){const e=new I({code:O,message:"AI request was aborted"});return r.error(e),s.reject(e),void n.cleanup()}(async()=>{var u,d,f;let p,m=0;const g={},h=new Map;try{const v=await this.req.post(this.requestOptions(e,!0,n.controller.signal,t));if(i)return;const y=M(V(v,"AI stream is empty")).getReader();let b=!1;try{for(;;){const e=await y.read();if(e.done){b=!0;break}const t=e.value;if(i)return;const n=X(t);if(n)throw n;t.usage&&(p=t.usage);const s=t,{choices:v,usage:w}=s,_=l(s,["choices","usage"]);Object.assign(g,_);const S=(null!=(u=t.choices)?u:[]).map((e,t)=>{var r,n,o,s;const i=null!=(r=e.index)?r:t,u=null!=(n=e.delta)?n:{},d=null!=(o=h.get(i))?o:{fields:{},content:"",reasoning_content:""},f=e,{delta:p,message:g}=f,v=l(f,["delta","message"]);return Object.assign(d.fields,v),u.content&&(d.content+=u.content),u.reasoning_content&&(d.reasoning_content+=u.reasoning_content),e.finish_reason&&(d.finish_reason=e.finish_reason),h.set(i,d),c(a({},e),{index:i,delta:a(a({},u),0===m&&void 0===u.role?{role:"assistant"}:{}),finish_reason:null!=(s=e.finish_reason)?s:void 0})});m+=1,r.enqueue(c(a({},t),{request_id:null!=(f=null!=(d=t.request_id)?d:t.id)?f:o,model:this.modelName,seq:m,choices:S}))}}finally{b||await y.cancel().catch(()=>{}),y.releaseLock()}if(i)return;r.close();const w=[...h.entries()].map(([e,t])=>c(a({},t.fields),{index:e,message:a({role:"assistant",content:t.content},t.reasoning_content?{reasoning_content:t.reasoning_content}:{}),finish_reason:t.finish_reason}));s.resolve(c(a({},g),{request_id:"string"==typeof g.request_id?g.request_id:"string"==typeof g.id?g.id:o,model:this.modelName,choices:w,usage:G(p)}))}catch(e){if(i)return;const t=Z(e,n);this.reportError(t,"streamText"),r.error(t),s.reject(t)}finally{n.cleanup()}})()},cancel:e=>{i||(i=!0,n.controller.abort(e),n.cleanup(),s.reject(new I({code:O,message:"AI stream was canceled by consumer"})))}}));return Object.defineProperties(u,{request_id:{enumerable:!0,value:o},result:{enumerable:!0,value:s.promise}}),u}}const re=new WeakMap;function ne(e){const t=re.get(e);if(!t)throw new Error("AI model is not initialized");return t}class oe{constructor(e){this.generateText=async(e,t)=>ne(this).doGenerate(e,t),this.streamText=async(e,t)=>ne(this).doStream(e,t),re.set(this,e)}}const se=new WeakMap;class ie{constructor(e,t,r,n,o){this.createModel=e=>{const{request:t,getBaseUrl:r,getAppId:n,getSubUrl:o,onError:s}=function(e){const t=se.get(e);if(!t)throw new Error("AI is not initialized");return t}(this);return new oe(new te(t,r,e,n,o,s))},se.set(this,{request:e,getBaseUrl:t,getAppId:r,getSubUrl:n,onError:o})}}const ae="https://edith.xiaohongshu.com";function ce({getAppId:e,getGateway:t,getBusinessLine:r,onError:n,request:o}){if(!o)throw new Error("`request` is required!");return new ie(o,()=>{var e;return function(e){if("string"!=typeof e||!e.trim())throw new Error("`gateway` must be a non-empty HTTPS URL");const t=e.trim();let r;try{r=new URL(t)}catch(e){throw new Error("`gateway` must be an absolute HTTPS URL")}if(n=r,"https:"!==n.protocol&&("http:"!==n.protocol||"localhost"!==n.hostname&&"127.0.0.1"!==n.hostname&&"[::1]"!==n.hostname))throw new Error("`gateway` must use HTTPS (HTTP is allowed only for loopback development)");var n;return t.replace(/\\/+$/,"")}(null!=(e=null==t?void 0:t())?e:ae)},()=>{return(null==(t=null==e?void 0:e())?void 0:t.trim())||void 0;var t},()=>function(e){switch(null==e?void 0:e.trim()){case"creator":return q.creator;case"mars":return q.mars;default:return q.default}}(null==r?void 0:r()),n)}function le(e){var t;const r=null==(t=null==e?void 0:e.$xhs)?void 0:t.launchOptions;return!r||"object"!=typeof r||Array.isArray(r)?{}:r}function ue(e){return(t={})=>v("getLaunchOptions",t,{target:e})}const de=10001;let fe=0;class pe{constructor(e){this.target=e,this.id=(fe+=1,`xhs_request_${Date.now().toString(36)}_${fe.toString(36)}`),this.chunkCallbacks=new Set,this.headersCallbacks=new Set,this.terminal=!1}get isSettled(){return this.terminal}abort(){this.terminal||(this.terminal=!0,this.dispose(),Promise.resolve(v("abortRequest",{taskId:this.id},{target:this.target})).catch(()=>{}))}onChunkReceived(e){this.terminal||"function"!=typeof e||(this.chunkCallbacks.add(e),this.chunkSubscription||(this.chunkSubscription=h("onEventStream",({payload:e})=>{if(!this.terminal&&(null==e?void 0:e.taskId)===this.id&&"string"==typeof e.chunk)for(const t of[...this.chunkCallbacks])t({data:e.chunk})},this.target)))}offChunkReceived(e){var t;e?this.chunkCallbacks.delete(e):this.chunkCallbacks.clear(),0===this.chunkCallbacks.size&&(null==(t=this.chunkSubscription)||t.remove(),this.chunkSubscription=void 0)}onHeadersReceived(e){this.terminal||"function"!=typeof e||(this.headersCallbacks.add(e),this.headersSubscription||(this.headersSubscription=h("onHeadersReceivedRequest",({payload:e})=>{if(this.terminal||(null==e?void 0:e.taskId)!==this.id)return;const t=e,{taskId:r}=t,n=l(t,["taskId"]);for(const e of[...this.headersCallbacks])e(n)},this.target)))}offHeadersReceived(e){var t;e?this.headersCallbacks.delete(e):this.headersCallbacks.clear(),0===this.headersCallbacks.size&&(null==(t=this.headersSubscription)||t.remove(),this.headersSubscription=void 0)}settle(){this.terminal||(this.terminal=!0,this.dispose())}dispose(){var e,t;null==(e=this.chunkSubscription)||e.remove(),null==(t=this.headersSubscription)||t.remove(),this.chunkSubscription=void 0,this.headersSubscription=void 0,this.chunkCallbacks.clear(),this.headersCallbacks.clear()}}function me(e,t){return function(r){var n,o,s,i,a;const c=new pe(e);if((l=r.data)instanceof ArrayBuffer||ArrayBuffer.isView(l))return function(e,t,r){ge(e,t,r,"request data does not support ArrayBuffer")}(t,c,r),c;var l;if(void 0!==r.responseType&&"text"!==r.responseType)return function(e,t,r){ge(e,t,r,"request responseType only supports text")}(t,c,r),c;const u={taskId:c.id,url:r.url,method:null!=(n=r.method)?n:"GET",header:r.header,data:r.data,dataType:null!=(o=r.dataType)?o:"json",responseType:null!=(s=r.responseType)?s:"text",timeout:null!=(i=r.timeout)?i:6e4,enableChunked:null!=(a=r.enableChunked)&&a,success(e){var t;null==(t=r.success)||t.call(r,e)},fail(e){var t;null==(t=r.fail)||t.call(r,e)},complete(e){var t;c.settle(),null==(t=r.complete)||t.call(r,e)}};return setTimeout(()=>{c.isSettled||v(t,u,{target:e})},0),c}}function ge(e,t,r,n){const o={errMsg:`${e}:fail ${n}`,errCode:de};setTimeout(()=>{var e,n;if(!t.isSettled){t.settle();try{null==(e=r.fail)||e.call(r,o)}finally{null==(n=r.complete)||n.call(r,o)}}},0)}function he(e){return me(e,"request")}function ve(e){return me(e,"xhsRequest")}function ye(e,t,r){const n="stream"===t.responseType||!0===t.stream;return new Promise((o,s)=>{let i,a,c=!1,l=!1;const u=n?new ReadableStream({start(e){a=e},cancel(){g(_e())}}):void 0,d=t.signal,f=()=>g(_e()),p=()=>!c&&(c=!0,null==d||d.removeEventListener("abort",f),!0),m=e=>{if(!p())return;const t=function(e){if(e instanceof Error)return e;if(function(e){return Boolean(e&&"object"==typeof e&&"errMsg"in e)}(e)){const t=new Error(e.errMsg);return t.name="XhsBridgeError",void 0!==e.errCode&&(t.errCode=e.errCode),t}return new Error(String(e))}(e);l?null==a||a.error(t):s(t)},g=e=>{null==i||i.abort(),m(e)},h=e=>{l||(l=!0,o(e))};i=e({url:t.url,method:we(r),header:t.headers,data:t.data,dataType:n?"text":"json",responseType:"text",enableChunked:n,success(e){if(!c)return u?(h(be(e,u)),void(p()&&(null==a||a.close()))):void(p()&&h(function(e){return{statusCode:e.statusCode,headers:e.header,data:e.data}}(e)))},fail:m}),u&&(i.onHeadersReceived(e=>{h(be(e,u))}),i.onChunkReceived(({data:e})=>{c||null==a||a.enqueue(e)})),(null==d?void 0:d.aborted)?f():null==d||d.addEventListener("abort",f,{once:!0})})}function be(e,t){return{statusCode:e.statusCode,headers:e.header,data:t}}function we(e){return"get"===e?"GET":"POST"}function _e(){const e=new Error("request was aborted");return e.name="AbortError",e}function Se(e){return ce({getAppId:()=>{var t;return ke(null==(t=le(e).miniToolEnv)?void 0:t.appId)},getGateway:()=>{var t,r;return ke(null==(r=null==(t=le(e).miniToolEnv)?void 0:t.gateways)?void 0:r.edith)},getBusinessLine:()=>{var t;return ke(null==(t=le(e).miniToolEnv)?void 0:t.businessLine)},onError:(t,r)=>{var n;S(e,{type:"ai",name:r.model,message:t.message.slice(0,512),stack:null==(n=t.stack)?void 0:n.slice(0,512),code:t.code,request_id:t.requestId,details:t.details,model:r.model,operation:r.operation})},request:(t=ve(e),{get:e=>ye(t,e,"get"),post:e=>ye(t,e,"post")})});var t}function ke(e){if("string"!=typeof e)return;return e.trim()||void 0}const Ce="INVALID_ARGUMENT",Ee="NETWORK_ERROR",Ae="BAD_RESPONSE",qe="SERVER_ERROR";class je extends Error{constructor(e,t,r={}){super(t),this.name="CloudServiceError",this.code=e,void 0!==r.errCode&&(this.errCode=r.errCode),void 0!==r.details&&(this.details=r.details)}}function Oe(e,t,r,n,o={}){var s;const i=null!=(s=o.errCode)?s:t===Ce?de:void 0;throw S(n,{type:"jsapi",name:"CloudServiceError",message:`${e}: ${r}`.slice(0,512),details:a({api:e,code:t,errCode:i},o.details)}),new je(t,`${e}:fail ${r}`,c(a({},o),{errCode:i}))}const Ie={all:"ALL",month:"MONTH",week:"WEEK",day:"DAY"};function Te(e,t,r,n){t||Oe(e,Ce,r,n)}function Le(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function xe(e,t,r){return Te(e,"string"==typeof t&&t.trim().length>0,"collection must be a non-empty string",r),t.trim()}function $e(e,t,r){return void 0===t?1:(Te(e,"number"==typeof t&&Number.isInteger(t)&&t>=1&&t<=5,"board must be an integer between 1 and 5",r),t)}function Ne(e,t,r){return void 0===t?Ie.all:(Te(e,"string"==typeof t&&t in Ie,"period must be \'all\', \'month\', \'week\' or \'day\'",r),Ie[t])}function Re(e,t,r){return Te(e,"number"==typeof t&&Number.isFinite(t),"score must be a finite number",r),t}function Pe(e,t,r){Te(e,Array.isArray(t)&&t.length>0,"ids must be a non-empty array",r);const n=t,o=new Set;return n.map(t=>{Te(e,"string"==typeof t&&t.trim().length>0,"ids must contain non-empty strings",r);const n=t.trim();return Te(e,!o.has(n),`ids must not contain duplicates: ${n}`,r),o.add(n),n})}const Me=["success","fail","complete"];function De(e,t,r){!function(e){for(const t of Me){const r=null==e?void 0:e[t];if(void 0!==r&&"function"!=typeof r)throw new TypeError(`${t} must be a function`)}}(r);const{success:n,fail:o,complete:s}=null!=r?r:{};if(!(n||o||s))return t().then(t=>Ke(e,t),t=>{throw Be(e,t)});t().then(t=>{const r=Ke(e,t);try{null==n||n(r)}finally{null==s||s(r)}},t=>{const r=Be(e,t);try{null==o||o(r)}finally{null==s||s(r)}})}function Ke(e,t){return Le(t)?c(a({},t),{errMsg:`${e}:ok`}):{data:t,errMsg:`${e}:ok`}}function Be(e,t){if(t instanceof je){const e={errMsg:t.message};return void 0!==t.errCode&&(e.errCode=t.errCode),e}const r=t instanceof Error&&t.message?t.message:"";return{errMsg:r?`${e}:fail ${r}`:`${e}:fail`}}function Fe(e){var t,r,n;return null!=(n=Ue(null==(r=null==(t=le(e).miniToolEnv)?void 0:t.gateways)?void 0:r.edith))?n:ae}function He(e){var t;return Ue(null==(t=le(e).miniToolEnv)?void 0:t.businessLine)}function Ue(e){if("string"==typeof e)return e.trim()||void 0}const Je=Object.freeze({default:Object.freeze({batchCreate:"/api/sns/v1/creator/red_app/batch_create",batchUpdate:"/api/sns/v1/creator/red_app/batch_update",query:"/api/sns/v1/creator/red_app/query",batchDelete:"/api/sns/v1/creator/red_app/batch_delete",submitScore:"/api/sns/v1/creator/red_app/submit_score",queryTop100:"/api/sns/v1/creator/red_app/query_top_100",querySelfRank:"/api/sns/v1/creator/red_app/query_self_rank"}),creator:Object.freeze({batchCreate:"/api/sns/v1/creator/red_app/creator/batch_create",batchUpdate:"/api/sns/v1/creator/red_app/creator/batch_update",query:"/api/sns/v1/creator/red_app/creator/query",batchDelete:"/api/sns/v1/creator/red_app/creator/batch_delete",submitScore:"/api/sns/v1/creator/red_app/creator/submit_score",queryTop100:"/api/sns/v1/creator/red_app/creator/query_top_100",querySelfRank:"/api/sns/v1/creator/red_app/creator/query_self_rank"}),mars:Object.freeze({batchCreate:"/api/sns/v1/creator/red_app/mars/batch_create",batchUpdate:"/api/sns/v1/creator/red_app/mars/batch_update",query:"/api/sns/v1/creator/red_app/mars/query",batchDelete:"/api/sns/v1/creator/red_app/mars/batch_delete",submitScore:"/api/sns/v1/creator/red_app/mars/submit_score",queryTop100:"/api/sns/v1/creator/red_app/mars/query_top_100",querySelfRank:"/api/sns/v1/creator/red_app/mars/query_self_rank"})});function ze(e,t){switch(null==e?void 0:e.trim()){case"creator":return Je.creator[t];case"mars":return Je.mars[t];default:return Je.default[t]}}function Ge(e){const t=ve(e);return{post(r,n,o){const s=function(e){var t;return Ue(null==(t=le(e).miniToolEnv)?void 0:t.appId)}(e);s||Oe(r,Ce,"appId is unavailable: launchOptions.miniToolEnv.appId is missing",e);const i=a({request_context:{env:"prod",app_id:s}},o);return new Promise((o,s)=>{t({url:j(Fe(e),ze(He(e),n)),method:"POST",header:{"Content-Type":"application/json"},data:i,dataType:"json",success(t){try{o(function(e,t,r,n){var o;const s=Xe(t),i=s?Xe(s.data):void 0,a=i?Xe(i.result):void 0;if(!s||!i||!a){Oe(e,!1===(null==s?void 0:s.success)||void 0!==r&&(r<200||r>=300)?Ee:Ae,null!=(o=We(null==s?void 0:s.msg))?o:`unexpected response (statusCode=${r})`,n,{details:{statusCode:r,gatewayCode:null==s?void 0:s.code,body:Ve(t)}})}const c="number"==typeof a.code?a.code:!0===a.success?0:void 0,l=We(a.message);void 0===c&&Oe(e,qe,null!=l?l:"response is missing a numeric result code",n,{details:{statusCode:r}});if(0!==c&&2003!==c)throw new je(String(c),`${e}:fail ${null!=l?l:String(c)}`,{errCode:c});return i}(r,t.data,t.statusCode,e))}catch(e){s(e)}},fail(t){try{Oe(r,Ee,t.errMsg||"request failed",e,{errCode:t.errCode,details:{errCode:t.errCode}})}catch(e){s(e)}}})})}}}function Xe(e){if("string"==typeof e)try{return Xe(JSON.parse(e))}catch(e){return}if("object"==typeof e&&null!==e&&!Array.isArray(e))return e}function We(e){return"string"==typeof e&&e?e:void 0}function Ve(e){try{return("string"==typeof e?e:JSON.stringify(e)||"").slice(0,256)}catch(e){return""}}const Ye="DESC",Qe="addCloudStorage",Ze="updateCloudStorage",et="queryCloudStorage",tt="removeCloudStorage";function rt(e){const t=Ge(e);return{addCloudStorage:r=>De(Qe,()=>async function(e,t,r){const n=nt(Qe,t,r),o=xe(Qe,n.collection,r),s=ot(Qe,n.items,r),i=s.map((e,t)=>(Te(Qe,Le(e.content),`items[${t}].content must be an object`,r),{content_json:JSON.stringify(e.content)})),a=await e.post(Qe,"batchCreate",{collection:o,items:i});return st(Qe,a,i.map(()=>{}),r)}(t,r,e),r),updateCloudStorage:r=>De(Ze,()=>async function(e,t,r){const n=nt(Ze,t,r),o=xe(Ze,n.collection,r),s=ot(Ze,n.items,r),i=new Set,a=s.map((e,t)=>{Te(Ze,"string"==typeof e.id&&e.id.trim().length>0,`items[${t}].id must be a non-empty string`,r);const n=e.id.trim();return Te(Ze,!i.has(n),`items must not repeat id: ${n}`,r),i.add(n),Te(Ze,Le(e.content),`items[${t}].content must be an object`,r),{id:n,content_json:JSON.stringify(e.content)}}),c=await e.post(Ze,"batchUpdate",{collection:o,items:a});return st(Ze,c,a.map(e=>e.id),r)}(t,r,e),r),queryCloudStorage:(r={})=>De(et,()=>async function(e,t,r){var n,o;const s=nt(et,t,r),i=function(e,t){var r;const n=void 0!==e.ids,o=void 0!==e.collection;if(n)return{mode:"BY_IDS",collection:xe(et,e.collection,t),ids:Pe(et,e.ids,t)};const s=null!=(r=function(e,t,r){if(void 0!==t)return Te(e,"number"==typeof t&&Number.isInteger(t)&&t>0,"limit must be a positive integer",r),t}(et,e.limit,t))?r:20,i=function(e,t,r){if(null!=t)return Te(e,"string"==typeof t&&t.length>0,"cursor must be a non-empty string",r),t}(et,e.cursor,t);if(o)return a({mode:"COLLECTION",collection:xe(et,e.collection,t),sort_by:Ye,limit:s},void 0===i?{}:{cursor:i});return a({mode:"APP_ALL",limit:s},void 0===i?{}:{cursor:i})}(s,r),c=await e.post(et,"query",i),l=Le(c)&&Le(c.data)?c.data:void 0;l&&Array.isArray(l.items)||Oe(et,Ae,"response is missing data.data.items",r);const u={items:l.items.map(e=>function(e,t,r){const n=Le(t)?t:void 0;n&&"string"==typeof n.id&&"string"==typeof n.content_json||Oe(e,Ae,"record is missing id or content_json",r);let o;try{o=JSON.parse(n.content_json)}catch(e){o=void 0}Le(o)||Oe(e,Ae,"record.content_json is not a JSON object",r);return{id:n.id,collection:"string"==typeof n.collection?n.collection:"",content:o}}(et,e,r))};("next_cursor"in l||"nextCursor"in l)&&(u.nextCursor="string"==typeof(d=null!=(n=l.next_cursor)?n:l.nextCursor)&&d?d:null);var d;("has_more"in l||"hasMore"in l)&&(u.hasMore=!0===(null!=(o=l.has_more)?o:l.hasMore));return u}(t,r,e),r),removeCloudStorage:r=>De(tt,()=>async function(e,t,r){const n=nt(tt,t,r),o=Pe(tt,n.ids,r),s=await e.post(tt,"batchDelete",{collection:xe(tt,n.collection,r),ids:o});return st(tt,s,o,r)}(t,r,e),r)}}function nt(e,t,r){return Te(e,Le(t),"options must be an object",r),t}function ot(e,t,r){return Te(e,Array.isArray(t)&&t.length>0,"items must be a non-empty array",r),t.map((t,n)=>(Te(e,Le(t),`items[${n}] must be an object`,r),t))}function st(e,t,r,n){const o=function(e,t,r){const n=Le(t)?t:void 0;return n&&Array.isArray(n.results)||Oe(e,Ae,"response is missing data.results",r),n.results.map((t,n)=>(Te(e,Le(t),`data.results[${n}] must be an object`,r),t))}(e,t,n);o.length!==r.length&&Oe(e,Ae,`data.results length ${o.length} does not match request items ${r.length}`,n);const s=new Map;for(const e of o)for(const t of[e.item_id,e.id])"string"==typeof t&&t&&s.set(t,e);return r.map((t,r)=>{var i;const a=null!=(i=void 0!==t?s.get(t):void 0)?i:o[r];return function(e,t,r,n){const{id:o,status:s}=t;"string"!=typeof s&&Oe(e,Ae,"per-item result is missing status",n);return{id:"string"==typeof o?o:"string"==typeof r?r:"",status:s}}(e,a,t,n)})}function it(e){return(t={})=>v("followAuthor",t,{target:e})}function at(e){return(t={})=>v("getFollowStatus",t,{target:e})}class ct extends Error{constructor(e){super(e),this.code=de,this.name="JsApiParamError"}}function lt(e,t,r,n){t||function(e,t,r){throw S(r,{type:"jsapi",name:"JsApiParamError",message:t,code:de,details:{api:e}}),new ct(t)}(e,r,n)}function ut(e){return(t={})=>v("getLocation",t,{target:e,validate:t=>function(e,t){const{type:r}=e;lt("getLocation",void 0===r||"wgs84"===r||"gcj02"===r,\'type must be "wgs84" or "gcj02"\',t)}(t,e)})}function dt(e){return(t={})=>v("getWindowInfo",t,{target:e})}const ft=["game","ui","normal"],pt="startGyroscope";function mt(e){return(t={})=>v(pt,t,{target:e,validate:t=>function(e,t){const{interval:r}=e;lt(pt,void 0===r||ft.includes(r),\'interval must be "game", "ui" or "normal"\',t)}(t,e)})}function gt(e){return(t={})=>v("stopGyroscope",t,{target:e})}const ht=new WeakMap;function vt(e){let t=ht.get(e);return t||(t={callbacks:new Set},ht.set(e,t)),t}function yt(e){return t=>{if("function"!=typeof t)throw new TypeError("onGyroscopeChange callback must be a function");const r=null!=e?e:u();if(!r)throw new Error("window is unavailable");const n=vt(r);if(n.callbacks.has(t))return;if(n.callbacks.add(t),n.subscription)return;n.subscription=h("onGyroscopeChange",({payload:e})=>{for(const t of[...n.callbacks])try{t(e)}catch(e){}},r)}}function bt(e){return t=>{var r;if(void 0!==t&&"function"!=typeof t)throw new TypeError("offGyroscopeChange callback must be a function");const n=null!=e?e:u();if(!n)throw new Error("window is unavailable");const o=vt(n);t?o.callbacks.delete(t):o.callbacks.clear(),o.callbacks.size>0||(null==(r=o.subscription)||r.remove(),o.subscription=void 0)}}function wt(e){return t=>v("interactionOpenApi",t,{target:e})}const _t="submitScore",St="getRankList",kt="getMyRank";function Ct(e){const t=Ge(e);return{submitScore:r=>De(_t,()=>async function(e,t,r){var n;const o=Et(_t,t,r),s=await e.post(_t,"submitScore",{rank_code:$e(_t,o.board,r),score:Re(_t,o.score,r)}),i=At(_t,s,r),a=qt(null!=(n=i.bestScore)?n:i.best_score);void 0===a&&Oe(_t,Ae,"response is missing data.data.bestScore",r);return{score:a}}(t,r,e),r),getRankList:(r={})=>De(St,()=>async function(e,t,r){const n=Et(St,t,r),o=await e.post(St,"queryTop100",{rank_code:$e(St,n.board,r),rank_type:Ne(St,n.period,r),limit:100}),s=At(St,o,r);Array.isArray(s.items)||Oe(St,Ae,"response is missing data.data.items",r);return s.items.map((e,t)=>{var n;Te(St,Le(e),`data.items[${t}] is malformed`,r);const o=e,s=qt(o.score);return"number"==typeof o.rank&&void 0!==s||Oe(St,Ae,`data.items[${t}] is missing rank or score`,r),{rank:o.rank,score:s,nickname:jt(o.nickname),avatar:jt(null!=(n=o.avatar_url)?n:o.avatarUrl)}})}(t,r,e),r),getMyRank:(r={})=>De(kt,()=>async function(e,t,r){var n;const o=Et(kt,t,r),s=await e.post(kt,"querySelfRank",{rank_code:$e(kt,o.board,r),rank_type:Ne(kt,o.period,r)}),i=At(kt,s,r),a=void 0!==i.self_rank?i.self_rank:i.self,c=Le(a)?a:void 0;c&&"string"==typeof c.status||Oe(kt,Ae,"response is missing data.data.self_rank.status",r);return{status:c.status,rank:Ot(c.rank),score:null!=(n=qt(c.score))?n:null}}(t,r,e),r)}}function Et(e,t,r){return Te(e,Le(t),"options must be an object",r),t}function At(e,t,r){const n=Le(t)?t.data:void 0;return Le(n)||Oe(e,Ae,"response is missing data.data",r),n}function qt(e){if("number"==typeof e)return Number.isFinite(e)?e:void 0;if("string"==typeof e&&""!==e.trim()){const t=Number(e);return Number.isFinite(t)?t:void 0}}function jt(e){return"string"==typeof e&&e?e:null}function Ot(e){return"number"==typeof e&&Number.isFinite(e)?e:null}function It(e){return t=>v("openRedPage",t,{target:e})}function Tt(e){return c(a({},e),{mediaInfo:JSON.stringify(e.mediaInfo||{})})}function Lt(e){return t=>v("postNote",t,{target:e,prepareRequest:Tt})}function xt(e){return t=>v("saveImageToPhotosAlbum",t,{target:e})}function $t(e){return(t={})=>v("clearStorage",t,{target:e})}function Nt(e){return t=>v("getStorage",t,{target:e})}function Rt(e){return(t={})=>v("getStorageInfo",t,{target:e})}function Pt(e){return t=>v("removeStorage",t,{target:e})}function Mt(e){return t=>v("setStorage",t,{target:e})}const Dt=["heavy","medium","light"],Kt="vibrateShort";function Bt(e){return t=>v(Kt,t,{target:e,validate:t=>function(e,t){const{type:r}=e;lt(Kt,Dt.includes(r),\'type must be "heavy", "medium" or "light"\',t)}(t,e)})}function Ft(e){return(t={})=>v("vibrateLong",t,{target:e})}function Ht(e){return t=>v("writeTempFile",t,{target:e})}const Ut="xhsOpenSiteLocation",Jt=["poi-detail","poi-list","path","navigation"];function zt(e){if(!e||"object"!=typeof e)return!1;const t=e;return"string"==typeof t.id&&t.id.length>0&&"number"==typeof t.latitude&&"number"==typeof t.longitude}function Gt(e){return t=>v("xhsOpenSiteLocation",t,{target:e,validate:t=>function(e,t){const{scene:r}=e;switch(lt(Ut,void 0!==r&&Jt.includes(r),\'scene must be "poi-detail" | "poi-list" | "path" | "navigation"\',t),r){case"poi-detail":lt(Ut,"string"==typeof e.id&&e.id.length>0,\'"poi-detail" requires a non-empty id\',t);break;case"poi-list":lt(Ut,Array.isArray(e.pois)&&e.pois.length>0,\'"poi-list" requires a non-empty pois array\',t);break;case"path":lt(Ut,zt(e.origin),\'"path" requires a valid origin { latitude, longitude, id }\',t),lt(Ut,zt(e.destination),\'"path" requires a valid destination { latitude, longitude, id }\',t);break;case"navigation":lt(Ut,zt(e.destination),\'"navigation" requires a valid destination { latitude, longitude, id }\',t)}}(t,e)})}function Xt(e){return c(a(a(a(a({},rt(e)),function(e){return{saveFile:t=>v("saveFile",t,{target:e}),writeFile:t=>v("writeFile",t,{target:e}),appendFile:t=>v("appendFile",t,{target:e}),readFile:t=>v("readFile",t,{target:e}),readDir:t=>v("readDir",t,{target:e}),statFile:t=>v("statFile",t,{target:e}),unlink:t=>v("unlink",t,{target:e}),mkdir:t=>v("mkdir",t,{target:e}),getFileStorageInfo:(t={})=>v("getFileStorageInfo",t,{target:e})}}(e)),Ct(e)),function(e){return{clearStorage:$t(e),getStorage:Nt(e),getStorageInfo:Rt(e),removeStorage:Pt(e),setStorage:Mt(e)}}(e)),{followAuthor:it(e),getFollowStatus:at(e),getLaunchOptions:ue(e),getLocation:ut(e),getWindowInfo:dt(e),interactionOpenApi:wt(e),offGyroscopeChange:bt(e),onGyroscopeChange:yt(e),postNote:Lt(e),request:he(e),saveImageToPhotosAlbum:xt(e),startGyroscope:mt(e),stopGyroscope:gt(e),openRedPage:It(e),vibrateLong:Ft(e),vibrateShort:Bt(e),xhsOpenSiteLocation:Gt(e),writeTempFile:Ht(e)})}function Wt(e){throw Object.assign(new Error(`invalid parameter; param=${e}`),{code:10001})}function Vt(e){throw Object.assign(new Error(`payload too large; param=${e}`),{code:10002})}function Yt(e,t,r=0,n=new Set){if(null===e||"string"==typeof e||"boolean"==typeof e)return;if("number"==typeof e)return void(Number.isFinite(e)||Wt(t));"object"!=typeof e&&Wt(t),n.has(e)&&Wt(t),r>5&&Vt(t);const o=Array.isArray(e),s=Object.getPrototypeOf(e);o||null===s||null===Object.getPrototypeOf(s)||Wt(t);for(let r=e;null!==r;r=Object.getPrototypeOf(r)){const e=Object.getOwnPropertyDescriptor(r,"toJSON");if(e){"value"in e&&"function"!=typeof e.value||Wt(t);break}}n.add(e);const i=Object.keys(e);o&&i.length!==e.length&&Wt(t);for(const s of Reflect.ownKeys(e)){const i=Object.getOwnPropertyDescriptor(e,s);i.enumerable&&("string"==typeof s&&"value"in i||Wt(t),o&&(!/^(0|[1-9]\\d*)$/.test(s)||Number(s)>=e.length)&&Wt(t),Yt(i.value,`${t}.${s}`,r+1,n))}n.delete(e)}function Qt(e,t,r){const n=JSON.stringify(e);(new TextEncoder).encode(n).byteLength>t&&Vt(r)}function Zt(e){const t=e,{success:r,complete:n,fail:o}=t,s=l(t,["success","complete","fail"]);if(Yt(s,"message"),"params"in s&&Qt(s.params,4096,"params"),s.index&&"object"==typeof s.index)for(const[e,t]of Object.entries(s.index))"string"==typeof t&&[...t].length>256&&Vt(`index.${e}`);return Qt(s,8192,"message"),s}function er(e){return t=>v("reportUba",t,{target:e,prepareRequest:Zt})}const tr=Symbol.for("xhs.internal");"undefined"!=typeof window&&(function(e={}){var t;const r=null!=(t=e.target)?t:u();if(!r)throw new Error("window is unavailable");if(g(r),!r.xhs||e.force){const e=Object.freeze({AI:Se(r),config:()=>{},get launchOptions(){return le(r)},miniTool:Object.freeze(c(a(a({},Xt(r)),{}),{version:"0.4.3"}))});r.xhs=e}!function(e){Object.prototype.hasOwnProperty.call(e,tr)||Object.defineProperty(e,tr,{get:()=>Object.freeze({reportUba:er(e)}),set(e){},configurable:!1,enumerable:!1})}(r)}({target:window}),function(e={}){var t,r;const n=null!=(t=e.target)?t:"undefined"==typeof window?void 0:window;if(!n)return;const o=n,s=n;if(s[_])return;s[_]=!0;const i=new Set;function a(e){try{const t=JSON.stringify(e);if(i.has(t))return;i.add(t),S(o,e)}catch(e){}}n.addEventListener("error",e=>{var t;try{const r=e,o=r.target;if(o&&o!==n&&o.tagName)return void a({type:"error",name:"ResourceError",message:`${o.tagName} 资源加载失败`,source:String(o.tagName).toLowerCase(),url:String(o.src||o.href||"")});const s=null!=(t=r.error)?t:{};a({type:"error",name:s.name||"Error",message:(r.message||String(s.message||"")).slice(0,512),source:`${r.filename||""}:${r.lineno||0}:${r.colno||0}`,url:r.filename||"",stack:s.stack?String(s.stack).slice(0,512):""})}catch(e){}},!0),n.addEventListener("unhandledrejection",e=>{try{const t=e.reason;let r="UnhandledRejection",n="",o="";if(t&&"object"==typeof t){const e=t;r=e.name||r,n=e.message||String(t),o=e.stack?String(e.stack).slice(0,512):""}else n=String(t);a({type:"unhandledrejection",name:r,message:n.slice(0,512),stack:o})}catch(e){}}),null==(r=n.document)||r.addEventListener("securitypolicyviolation",e=>{try{a({type:"securitypolicyviolation",name:"CSPViolation",disposition:e.disposition||"",effective_directive:e.effectiveDirective||"",violated_directive:e.violatedDirective||"",blocked_uri:e.blockedURI||"",source_file:e.sourceFile||"",line_number:e.lineNumber||0,column_number:e.columnNumber||0,original_policy:e.originalPolicy||""})}catch(e){}});try{const e=n,t=e.fetch;"function"==typeof t&&(e.fetch=function(e,r){const n=function(e){try{return"string"==typeof e?e:String(e&&"object"==typeof e&&"url"in e?e.url:e)}catch(e){return""}}(e);return t.call(this,e,r).then(e=>e,e=>{throw a({type:"fetch",name:C(e),message:(k(e)||"fetch failed").slice(0,512),url:n,stack:E(e)}),e})})}catch(e){}}({target:window}))});', Vo = ko, Lo = /<meta[^>]+name=["']x-miniapp-jsapi-mode["'][^>]+content=["']external["'][^>]*>/i, Io = /<script[^>]+src=["'][^"']*miniapp-js-api[^"']*\.umd[^"']*["']/i;
3436
3459
  function Wo(n) {
3437
- return !!(Io.test(n) || Lo.test(n));
3460
+ return !!(Lo.test(n) || Io.test(n));
3438
3461
  }
3439
3462
  function Gt(n) {
3440
3463
  return So(
@@ -4377,7 +4400,7 @@ function ia(n) {
4377
4400
  function bs(n) {
4378
4401
  return n instanceof Hn ? n.value : Array.isArray(n) ? n.map(bs).join("") : ia(n);
4379
4402
  }
4380
- function he(n, ...e) {
4403
+ function pe(n, ...e) {
4381
4404
  let t = n[0];
4382
4405
  for (let r = 0; r < e.length; r += 1)
4383
4406
  t += bs(e[r]) + n[r + 1];
@@ -4412,23 +4435,23 @@ function Qn(n, e) {
4412
4435
  function zn(n, e) {
4413
4436
  typeof customElements > "u" || customElements.get(n) || customElements.define(n, e);
4414
4437
  }
4415
- var Fe, It;
4438
+ var Fe, Lt;
4416
4439
  class aa {
4417
4440
  constructor(e) {
4418
- D(this, Fe, !1);
4419
- D(this, It, 0);
4441
+ U(this, Fe, !1);
4442
+ U(this, Lt, 0);
4420
4443
  this.render = e;
4421
4444
  }
4422
4445
  schedule() {
4423
- v(this, Fe) || (_(this, Fe, !0), _(this, It, requestAnimationFrame(() => {
4446
+ y(this, Fe) || (_(this, Fe, !0), _(this, Lt, requestAnimationFrame(() => {
4424
4447
  _(this, Fe, !1), this.render();
4425
4448
  })));
4426
4449
  }
4427
4450
  flushCancel() {
4428
- v(this, Fe) && cancelAnimationFrame(v(this, It)), _(this, Fe, !1);
4451
+ y(this, Fe) && cancelAnimationFrame(y(this, Lt)), _(this, Fe, !1);
4429
4452
  }
4430
4453
  }
4431
- Fe = new WeakMap(), It = new WeakMap();
4454
+ Fe = new WeakMap(), Lt = new WeakMap();
4432
4455
  const la = 420, jn = `
4433
4456
  :host {
4434
4457
  --dt-width: ${la}px;
@@ -4623,49 +4646,49 @@ const la = 420, jn = `
4623
4646
  color: #ffb3bd;
4624
4647
  }
4625
4648
  `;
4626
- var Me, ke, Lt, Ne, nt, Ae, gt, jt, kn, ws;
4649
+ var Me, ke, It, Ne, nt, fe, gt, jt, kn, ws;
4627
4650
  class ua extends HTMLElement {
4628
4651
  constructor() {
4629
4652
  super();
4630
- D(this, Ae);
4631
- D(this, Me);
4632
- D(this, ke);
4633
- D(this, Lt, new aa(() => oe(this, Ae, ws).call(this)));
4634
- D(this, Ne, null);
4635
- D(this, nt, !1);
4636
- D(this, jt, (t) => {
4653
+ U(this, fe);
4654
+ U(this, Me);
4655
+ U(this, ke);
4656
+ U(this, It, new aa(() => oe(this, fe, ws).call(this)));
4657
+ U(this, Ne, null);
4658
+ U(this, nt, !1);
4659
+ U(this, jt, (t) => {
4637
4660
  const r = t.target?.closest(
4638
4661
  "[data-cap],[data-act]"
4639
4662
  );
4640
- if (!(!r || v(this, nt) || !v(this, Ne))) {
4663
+ if (!(!r || y(this, nt) || !y(this, Ne))) {
4641
4664
  if (r.dataset.cap) {
4642
- const s = new Set(v(this, Ne).allow), i = r.dataset.cap;
4643
- s.has(i) ? s.delete(i) : s.add(i), oe(this, Ae, gt).call(this, [...s]);
4665
+ const s = new Set(y(this, Ne).allow), i = r.dataset.cap;
4666
+ s.has(i) ? s.delete(i) : s.add(i), oe(this, fe, gt).call(this, [...s]);
4644
4667
  return;
4645
4668
  }
4646
4669
  switch (r.dataset.act) {
4647
4670
  case "reset":
4648
- oe(this, Ae, gt).call(this, [...ns]);
4671
+ oe(this, fe, gt).call(this, [...ns]);
4649
4672
  break;
4650
4673
  case "allow-all":
4651
- oe(this, Ae, gt).call(this, [...rs]);
4674
+ oe(this, fe, gt).call(this, [...rs]);
4652
4675
  break;
4653
4676
  case "seal-all":
4654
- oe(this, Ae, gt).call(this, []);
4677
+ oe(this, fe, gt).call(this, []);
4655
4678
  break;
4656
4679
  }
4657
4680
  }
4658
4681
  });
4659
- _(this, Me, this.attachShadow({ mode: "open" })), Qn(v(this, Me), [jn, Jn, da]), _(this, ke, document.createElement("div")), v(this, ke).className = "dt-content", v(this, Me).append(v(this, ke)), v(this, Me).addEventListener("click", v(this, jt));
4682
+ _(this, Me, this.attachShadow({ mode: "open" })), Qn(y(this, Me), [jn, Jn, da]), _(this, ke, document.createElement("div")), y(this, ke).className = "dt-content", y(this, Me).append(y(this, ke)), y(this, Me).addEventListener("click", y(this, jt));
4660
4683
  }
4661
4684
  set snapshot(t) {
4662
- _(this, Ne, t), v(this, Lt).schedule();
4685
+ _(this, Ne, t), y(this, It).schedule();
4663
4686
  }
4664
4687
  set applying(t) {
4665
- _(this, nt, t), v(this, Lt).schedule();
4688
+ _(this, nt, t), y(this, It).schedule();
4666
4689
  }
4667
4690
  }
4668
- Me = new WeakMap(), ke = new WeakMap(), Lt = new WeakMap(), Ne = new WeakMap(), nt = new WeakMap(), Ae = new WeakSet(), gt = function(t) {
4691
+ Me = new WeakMap(), ke = new WeakMap(), It = new WeakMap(), Ne = new WeakMap(), nt = new WeakMap(), fe = new WeakSet(), gt = function(t) {
4669
4692
  this.dispatchEvent(
4670
4693
  new CustomEvent(vs, {
4671
4694
  detail: { allow: t },
@@ -4679,17 +4702,17 @@ Me = new WeakMap(), ke = new WeakMap(), Lt = new WeakMap(), Ne = new WeakMap(),
4679
4702
  ["模式", t.contentMode],
4680
4703
  ["视口", `${t.viewport.width}×${t.viewport.height}`],
4681
4704
  ["白名单来源", t.custom ? "自定义 sealAllow" : "默认 DEFAULT_ALLOW"]
4682
- ].map(([i, o]) => he`<span>${i} <b>${o}</b></span>`);
4683
- return he`<div class="cap-meta">${s}</div>`;
4705
+ ].map(([i, o]) => pe`<span>${i} <b>${o}</b></span>`);
4706
+ return pe`<div class="cap-meta">${s}</div>`;
4684
4707
  }, ws = function() {
4685
- const t = v(this, Ne);
4708
+ const t = y(this, Ne);
4686
4709
  if (!t) {
4687
- v(this, ke).innerHTML = "";
4710
+ y(this, ke).innerHTML = "";
4688
4711
  return;
4689
4712
  }
4690
- if (v(this, nt)) {
4691
- v(this, ke).innerHTML = et(
4692
- he`${oe(this, Ae, kn).call(this, t)}<div class="dt-empty">正在应用新能力配置并重新加载小应用…</div>`
4713
+ if (y(this, nt)) {
4714
+ y(this, ke).innerHTML = et(
4715
+ pe`${oe(this, fe, kn).call(this, t)}<div class="dt-empty">正在应用新能力配置并重新加载小应用…</div>`
4693
4716
  );
4694
4717
  return;
4695
4718
  }
@@ -4697,21 +4720,21 @@ Me = new WeakMap(), ke = new WeakMap(), Lt = new WeakMap(), Ne = new WeakMap(),
4697
4720
  const a = nn.filter((d) => d.controlledBy === o);
4698
4721
  if (a.length === 0) return sa("");
4699
4722
  const l = a.map((d) => {
4700
- const h = r.has(d.value), A = d.controlledBy === "host" ? he`<span class="badge badge-host">宿主控制</span>` : h ? he`<span class="badge badge-allow">放行</span>` : he`<span class="badge badge-sealed">已封印</span>`;
4701
- return he`
4723
+ const u = r.has(d.value), A = d.controlledBy === "host" ? pe`<span class="badge badge-host">宿主控制</span>` : u ? pe`<span class="badge badge-allow">放行</span>` : pe`<span class="badge badge-sealed">已封印</span>`;
4724
+ return pe`
4702
4725
  <div class="cap-row">
4703
4726
  <div class="cap-info">
4704
4727
  <div class="cap-name"><span>${d.value}</span>${A}</div>
4705
4728
  <div class="cap-desc">${d.description}</div>
4706
4729
  </div>
4707
- <button class="switch" type="button" role="switch" aria-checked="${h ? "true" : "false"}"
4730
+ <button class="switch" type="button" role="switch" aria-checked="${u ? "true" : "false"}"
4708
4731
  data-cap="${d.value}" aria-label="toggle ${d.value}"></button>
4709
4732
  </div>`;
4710
4733
  });
4711
- return he`<div class="cap-group">${ca[o]}</div>${l}`;
4734
+ return pe`<div class="cap-group">${ca[o]}</div>${l}`;
4712
4735
  });
4713
- v(this, ke).innerHTML = et(he`
4714
- ${oe(this, Ae, kn).call(this, t)}
4736
+ y(this, ke).innerHTML = et(pe`
4737
+ ${oe(this, fe, kn).call(this, t)}
4715
4738
  <div class="dt-scroll">
4716
4739
  ${i}
4717
4740
  <div class="cap-note">
@@ -4825,7 +4848,7 @@ const Cs = "miniapp-devtools-logs", un = 600, ga = `
4825
4848
  .log.lvl-ok .log-tag { color: var(--dt-ok); }
4826
4849
  `;
4827
4850
  function br(n) {
4828
- return he`
4851
+ return pe`
4829
4852
  <div class="log lvl-${n.level}">
4830
4853
  <span class="log-time">${fa(n.timestamp)}</span>
4831
4854
  <span class="log-tag">${n.event}</span>
@@ -4837,56 +4860,56 @@ var Ke, Ve, rt, me, be, Oe, We, Vn, Zt, Jt, _t;
4837
4860
  class ba extends HTMLElement {
4838
4861
  constructor() {
4839
4862
  super();
4840
- D(this, We);
4841
- D(this, Ke);
4842
- D(this, Ve, []);
4843
- D(this, rt, "");
4844
- D(this, me, !1);
4845
- D(this, be, null);
4846
- D(this, Oe, null);
4847
- D(this, Jt, (t) => {
4863
+ U(this, We);
4864
+ U(this, Ke);
4865
+ U(this, Ve, []);
4866
+ U(this, rt, "");
4867
+ U(this, me, !1);
4868
+ U(this, be, null);
4869
+ U(this, Oe, null);
4870
+ U(this, Jt, (t) => {
4848
4871
  const r = t.target;
4849
4872
  r?.dataset?.role === "filter" && (_(this, rt, r.value.trim().toLowerCase()), oe(this, We, Zt).call(this));
4850
4873
  });
4851
- D(this, _t, (t) => {
4874
+ U(this, _t, (t) => {
4852
4875
  const r = t.target?.closest("[data-act]");
4853
- r && (r.dataset.act === "clear" ? this.clear() : r.dataset.act === "pause" && (_(this, me, !v(this, me)), v(this, Oe)?.setAttribute("aria-pressed", String(v(this, me))), v(this, Oe) && (v(this, Oe).textContent = v(this, me) ? "恢复滚动" : "暂停滚动"), !v(this, me) && v(this, be) && (v(this, be).scrollTop = v(this, be).scrollHeight)));
4876
+ r && (r.dataset.act === "clear" ? this.clear() : r.dataset.act === "pause" && (_(this, me, !y(this, me)), y(this, Oe)?.setAttribute("aria-pressed", String(y(this, me))), y(this, Oe) && (y(this, Oe).textContent = y(this, me) ? "恢复滚动" : "暂停滚动"), !y(this, me) && y(this, be) && (y(this, be).scrollTop = y(this, be).scrollHeight)));
4854
4877
  });
4855
- _(this, Ke, this.attachShadow({ mode: "open" })), Qn(v(this, Ke), [jn, Jn, ga]);
4878
+ _(this, Ke, this.attachShadow({ mode: "open" })), Qn(y(this, Ke), [jn, Jn, ga]);
4856
4879
  }
4857
4880
  connectedCallback() {
4858
- if (v(this, be)) return;
4881
+ if (y(this, be)) return;
4859
4882
  const t = document.createElement("div");
4860
- t.className = "dt-content", t.innerHTML = et(he`
4883
+ t.className = "dt-content", t.innerHTML = et(pe`
4861
4884
  <div class="dt-toolbar">
4862
4885
  <input class="dt-input" type="text" data-role="filter" placeholder="过滤日志…" />
4863
4886
  <button class="dt-btn" type="button" data-act="pause" aria-pressed="false">暂停滚动</button>
4864
4887
  <button class="dt-btn" type="button" data-act="clear">清空</button>
4865
4888
  </div>
4866
4889
  <div class="dt-scroll" data-role="list"></div>
4867
- `), v(this, Ke).append(t), _(this, be, t.querySelector('[data-role="list"]')), _(this, Oe, t.querySelector('[data-act="pause"]')), v(this, Ke).addEventListener("click", v(this, _t)), v(this, Ke).addEventListener("input", v(this, Jt)), oe(this, We, Zt).call(this);
4890
+ `), y(this, Ke).append(t), _(this, be, t.querySelector('[data-role="list"]')), _(this, Oe, t.querySelector('[data-act="pause"]')), y(this, Ke).addEventListener("click", y(this, _t)), y(this, Ke).addEventListener("input", y(this, Jt)), oe(this, We, Zt).call(this);
4868
4891
  }
4869
4892
  /** 灌入一条模拟器事件 */
4870
4893
  push(t, r) {
4871
4894
  const s = pa(t, r);
4872
- v(this, Ve).push(s), v(this, Ve).length > un && v(this, Ve).splice(0, v(this, Ve).length - un);
4873
- const i = v(this, be);
4895
+ y(this, Ve).push(s), y(this, Ve).length > un && y(this, Ve).splice(0, y(this, Ve).length - un);
4896
+ const i = y(this, be);
4874
4897
  if (!(!i || !oe(this, We, Vn).call(this, s))) {
4875
4898
  for (i.querySelector(".dt-empty") && (i.innerHTML = ""), i.insertAdjacentHTML("beforeend", et(br(s))); i.childElementCount > un; ) i.firstElementChild?.remove();
4876
- v(this, me) || (i.scrollTop = i.scrollHeight);
4899
+ y(this, me) || (i.scrollTop = i.scrollHeight);
4877
4900
  }
4878
4901
  }
4879
4902
  clear() {
4880
- v(this, Ve).length = 0, oe(this, We, Zt).call(this);
4903
+ y(this, Ve).length = 0, oe(this, We, Zt).call(this);
4881
4904
  }
4882
4905
  }
4883
4906
  Ke = new WeakMap(), Ve = new WeakMap(), rt = new WeakMap(), me = new WeakMap(), be = new WeakMap(), Oe = new WeakMap(), We = new WeakSet(), Vn = function(t) {
4884
- return v(this, rt) ? `${t.event} ${t.message}`.toLowerCase().includes(v(this, rt)) : !0;
4907
+ return y(this, rt) ? `${t.event} ${t.message}`.toLowerCase().includes(y(this, rt)) : !0;
4885
4908
  }, Zt = function() {
4886
- const t = v(this, be);
4909
+ const t = y(this, be);
4887
4910
  if (!t) return;
4888
- const r = v(this, Ve).filter((s) => oe(this, We, Vn).call(this, s));
4889
- t.innerHTML = r.length ? et(he`${r.map(br)}`) : ma, v(this, me) || (t.scrollTop = t.scrollHeight);
4911
+ const r = y(this, Ve).filter((s) => oe(this, We, Vn).call(this, s));
4912
+ t.innerHTML = r.length ? et(pe`${r.map(br)}`) : ma, y(this, me) || (t.scrollTop = t.scrollHeight);
4890
4913
  }, Jt = new WeakMap(), _t = new WeakMap();
4891
4914
  function ya() {
4892
4915
  zn(Cs, ba);
@@ -4963,32 +4986,32 @@ const Ss = "miniapp-devtools", va = `
4963
4986
  .body > * { flex: 1 1 auto; min-width: 0; }
4964
4987
  .body > [hidden] { display: none !important; }
4965
4988
  `;
4966
- var Ie, ye, st, ve, Xe, Wt, $t, Es, en, tn;
4989
+ var Le, ye, st, ve, Xe, Wt, $t, Es, en, tn;
4967
4990
  class wa extends HTMLElement {
4968
4991
  constructor() {
4969
4992
  super();
4970
- D(this, $t);
4971
- D(this, Ie);
4972
- D(this, ye, null);
4973
- D(this, st, null);
4974
- D(this, ve);
4975
- D(this, Xe);
4976
- D(this, Wt, "capabilities");
4977
- D(this, en, (t) => {
4993
+ U(this, $t);
4994
+ U(this, Le);
4995
+ U(this, ye, null);
4996
+ U(this, st, null);
4997
+ U(this, ve);
4998
+ U(this, Xe);
4999
+ U(this, Wt, "capabilities");
5000
+ U(this, en, (t) => {
4978
5001
  const r = t.target?.closest(
4979
5002
  "[data-act],[data-tab]"
4980
5003
  );
4981
5004
  r && (r.dataset.act === "close" ? this.close() : r.dataset.tab && oe(this, $t, Es).call(this, r.dataset.tab));
4982
5005
  });
4983
- D(this, tn, (t) => {
4984
- const r = v(this, ye);
5006
+ U(this, tn, (t) => {
5007
+ const r = y(this, ye);
4985
5008
  if (!r) return;
4986
5009
  const { allow: s } = t.detail;
4987
- v(this, ve).applying = !0, Promise.resolve(r.onApplyCapabilities(s)).finally(() => {
4988
- v(this, ve).applying = !1, this.refresh();
5010
+ y(this, ve).applying = !0, Promise.resolve(r.onApplyCapabilities(s)).finally(() => {
5011
+ y(this, ve).applying = !1, this.refresh();
4989
5012
  });
4990
5013
  });
4991
- _(this, Ie, this.attachShadow({ mode: "open" })), Qn(v(this, Ie), [jn, Jn, va]), v(this, Ie).innerHTML = et(he`
5014
+ _(this, Le, this.attachShadow({ mode: "open" })), Qn(y(this, Le), [jn, Jn, va]), y(this, Le).innerHTML = et(pe`
4992
5015
  <div class="header">
4993
5016
  <div class="title"><span class="dot"></span>MiniApp DevTools</div>
4994
5017
  <span class="kbd">⇧⌘U</span>
@@ -4999,36 +5022,36 @@ class wa extends HTMLElement {
4999
5022
  <button class="tab" type="button" role="tab" data-tab="logs" aria-selected="false">运行日志</button>
5000
5023
  </div>
5001
5024
  <div class="body"></div>
5002
- `), _(this, ve, document.createElement(ys)), _(this, Xe, document.createElement(Cs)), v(this, Xe).hidden = !0, v(this, Ie).querySelector(".body").append(v(this, ve), v(this, Xe)), v(this, Ie).addEventListener("click", v(this, en)), v(this, ve).addEventListener(vs, v(this, tn));
5025
+ `), _(this, ve, document.createElement(ys)), _(this, Xe, document.createElement(Cs)), y(this, Xe).hidden = !0, y(this, Le).querySelector(".body").append(y(this, ve), y(this, Xe)), y(this, Le).addEventListener("click", y(this, en)), y(this, ve).addEventListener(vs, y(this, tn));
5003
5026
  }
5004
5027
  /** 注入模拟器侧回调(创建后立即调用) */
5005
5028
  bind(t) {
5006
5029
  _(this, ye, t), _(this, st, t.subscribe((r, s) => {
5007
- v(this, Xe).push(r, s);
5030
+ y(this, Xe).push(r, s);
5008
5031
  }));
5009
5032
  }
5010
5033
  get isOpen() {
5011
5034
  return this.hasAttribute("open");
5012
5035
  }
5013
5036
  open() {
5014
- this.isOpen || (this.refresh(), this.setAttribute("open", ""), v(this, ye)?.onOpenChange?.(!0));
5037
+ this.isOpen || (this.refresh(), this.setAttribute("open", ""), y(this, ye)?.onOpenChange?.(!0));
5015
5038
  }
5016
5039
  close() {
5017
- this.isOpen && (this.removeAttribute("open"), v(this, ye)?.onOpenChange?.(!1));
5040
+ this.isOpen && (this.removeAttribute("open"), y(this, ye)?.onOpenChange?.(!1));
5018
5041
  }
5019
5042
  toggle() {
5020
5043
  this.isOpen ? this.close() : this.open();
5021
5044
  }
5022
5045
  refresh() {
5023
- v(this, ye) && (v(this, ve).snapshot = v(this, ye).getSnapshot());
5046
+ y(this, ye) && (y(this, ve).snapshot = y(this, ye).getSnapshot());
5024
5047
  }
5025
5048
  dispose() {
5026
5049
  var t;
5027
- (t = v(this, st)) == null || t.call(this), _(this, st, null), _(this, ye, null), this.remove();
5050
+ (t = y(this, st)) == null || t.call(this), _(this, st, null), _(this, ye, null), this.remove();
5028
5051
  }
5029
5052
  }
5030
- Ie = new WeakMap(), ye = new WeakMap(), st = new WeakMap(), ve = new WeakMap(), Xe = new WeakMap(), Wt = new WeakMap(), $t = new WeakSet(), Es = function(t) {
5031
- t !== v(this, Wt) && (_(this, Wt, t), v(this, ve).hidden = t !== "capabilities", v(this, Xe).hidden = t !== "logs", v(this, Ie).querySelectorAll(".tab").forEach((r) => {
5053
+ Le = new WeakMap(), ye = new WeakMap(), st = new WeakMap(), ve = new WeakMap(), Xe = new WeakMap(), Wt = new WeakMap(), $t = new WeakSet(), Es = function(t) {
5054
+ t !== y(this, Wt) && (_(this, Wt, t), y(this, ve).hidden = t !== "capabilities", y(this, Xe).hidden = t !== "logs", y(this, Le).querySelectorAll(".tab").forEach((r) => {
5032
5055
  r.setAttribute("aria-selected", String(r.dataset.tab === t));
5033
5056
  }));
5034
5057
  }, en = new WeakMap(), tn = new WeakMap();
@@ -5063,7 +5086,7 @@ function xa(n) {
5063
5086
  };
5064
5087
  }
5065
5088
  const ka = { light: 1, medium: 2, heavy: 4 }, Va = 100;
5066
- class Ia {
5089
+ class La {
5067
5090
  constructor(e) {
5068
5091
  this.stage = e, this.animation = null, this.lastStartedAt = Number.NEGATIVE_INFINITY;
5069
5092
  }
@@ -5086,7 +5109,7 @@ class Ia {
5086
5109
  this.animation?.cancel(), this.animation = null, this.lastStartedAt = Number.NEGATIVE_INFINITY;
5087
5110
  }
5088
5111
  }
5089
- const wt = "designable-miniapp-frame-toast", yr = "designable-miniapp-frame-toast-style", La = `
5112
+ const wt = "designable-miniapp-frame-toast", yr = "designable-miniapp-frame-toast-style", Ia = `
5090
5113
  .${wt} {
5091
5114
  position: absolute;
5092
5115
  inset: 0;
@@ -5125,7 +5148,7 @@ class xs {
5125
5148
  if (this.container) return this.container;
5126
5149
  if (!this.mountEl.querySelector(`#${yr}`)) {
5127
5150
  const t = document.createElement("style");
5128
- t.id = yr, t.textContent = La, this.mountEl.appendChild(t);
5151
+ t.id = yr, t.textContent = Ia, this.mountEl.appendChild(t);
5129
5152
  }
5130
5153
  const e = document.createElement("div");
5131
5154
  return e.id = wt, e.className = wt, this.mountEl.appendChild(e), this.container = e, e;
@@ -5475,11 +5498,11 @@ function Na(n, e) {
5475
5498
  const t = Xa();
5476
5499
  let r, s, i, o;
5477
5500
  if (t !== void 0) {
5478
- const h = Pa(t);
5479
- r = h.id, s = h.borderRadius, i = h.borderWidth, o = h.shellHeight;
5501
+ const u = Pa(t);
5502
+ r = u.id, s = u.borderRadius, i = u.borderWidth, o = u.shellHeight;
5480
5503
  } else {
5481
- const h = Ma(n.width);
5482
- r = h.tierId, s = h.borderRadius, i = h.borderWidth, o = h.shellHeight;
5504
+ const u = Ma(n.width);
5505
+ r = u.tierId, s = u.borderRadius, i = u.borderWidth, o = u.shellHeight;
5483
5506
  }
5484
5507
  const a = n.height / o, l = Ze(s * a), d = Ze(i * a);
5485
5508
  return {
@@ -5499,10 +5522,10 @@ function $n(n, e) {
5499
5522
  const t = Math.max(0, e.borderRadius - e.borderWidth);
5500
5523
  n.style.borderRadius = `${Ze(t)}px`, n.style.webkitMaskImage = "-webkit-radial-gradient(white, black)", n.style.maskImage = "radial-gradient(white, black)", n.style.flex = "1", n.style.minHeight = "0", n.style.minWidth = "0";
5501
5524
  }
5502
- function In(n) {
5525
+ function Ln(n) {
5503
5526
  n.style.border = "", n.style.borderRadius = "", n.style.boxSizing = "", n.style.display = "", n.style.flexDirection = "", n.style.background = "";
5504
5527
  }
5505
- function Ln(n) {
5528
+ function In(n) {
5506
5529
  n.style.borderRadius = "", n.style.webkitMaskImage = "", n.style.maskImage = "", n.style.flex = "", n.style.minHeight = "", n.style.minWidth = "";
5507
5530
  }
5508
5531
  function Vs(n, e, t) {
@@ -5514,7 +5537,7 @@ function Vs(n, e, t) {
5514
5537
  };
5515
5538
  return window.addEventListener("resize", r), () => window.removeEventListener("resize", r);
5516
5539
  }
5517
- class Is {
5540
+ class Ls {
5518
5541
  constructor() {
5519
5542
  this.events = new is();
5520
5543
  }
@@ -5548,14 +5571,14 @@ function Da(n) {
5548
5571
  }
5549
5572
  return e;
5550
5573
  }
5551
- function Ls(n, e) {
5574
+ function Is(n, e) {
5552
5575
  const t = (e.defaultView ?? window).CSS;
5553
5576
  return t && typeof t.escape == "function" ? t.escape(n) : n.replace(/[^a-zA-Z0-9_-]/g, (r) => `\\${r}`);
5554
5577
  }
5555
5578
  function Ws(n, e) {
5556
5579
  if (!n.id) return !1;
5557
5580
  try {
5558
- return e.querySelectorAll(`#${Ls(n.id, e)}`).length === 1;
5581
+ return e.querySelectorAll(`#${Is(n.id, e)}`).length === 1;
5559
5582
  } catch {
5560
5583
  return !1;
5561
5584
  }
@@ -5565,7 +5588,7 @@ function Ua(n) {
5565
5588
  let r = n;
5566
5589
  for (; r && r.nodeType === 1 && r !== e.documentElement; ) {
5567
5590
  if (Ws(r, e)) {
5568
- t.unshift(`#${Ls(r.id, e)}`);
5591
+ t.unshift(`#${Is(r.id, e)}`);
5569
5592
  break;
5570
5593
  }
5571
5594
  let s = r.tagName.toLowerCase();
@@ -5667,8 +5690,8 @@ class rl {
5667
5690
  i === "hover" ? this.onLeave() : this.clear();
5668
5691
  return;
5669
5692
  }
5670
- const h = this.selectionRect(d);
5671
- i === "hover" ? (this.placeRect(this.hoverBox, h, this.hoverShown), this.hoverShown = !0, this.opts.onHover(d)) : i === "pick" && this.select(d, h);
5693
+ const u = this.selectionRect(d);
5694
+ i === "hover" ? (this.placeRect(this.hoverBox, u, this.hoverShown), this.hoverShown = !0, this.opts.onHover(d)) : i === "pick" && this.select(d, u);
5672
5695
  }, this.opts = e, window.addEventListener("message", this.onGuestMessage), this.opts.element.addEventListener?.("load", this.onFrameLoad);
5673
5696
  }
5674
5697
  get isEnabled() {
@@ -6102,12 +6125,12 @@ class il {
6102
6125
  }
6103
6126
  const d = Math.round(performance.now() - r);
6104
6127
  this.ctx.emit("load", { url: e, duration: d });
6105
- const h = ol(o, d);
6106
- h && this.ctx.emit("performance", h), window.setTimeout(() => this.emitRenderDone(e), 120), s();
6128
+ const u = ol(o, d);
6129
+ u && this.ctx.emit("performance", u), window.setTimeout(() => this.emitRenderDone(e), 120), s();
6107
6130
  }, o.onerror = (d) => {
6108
6131
  l();
6109
- const h = new Error(`Iframe load failed: ${e}`);
6110
- this.ctx.emit("error", { code: "LOAD_FAILED", message: h.message, url: e, cause: d }), i(h);
6132
+ const u = new Error(`Iframe load failed: ${e}`);
6133
+ this.ctx.emit("error", { code: "LOAD_FAILED", message: u.message, url: e, cause: d }), i(u);
6111
6134
  }, o.removeAttribute("srcdoc"), o.src = e;
6112
6135
  });
6113
6136
  }
@@ -6390,18 +6413,18 @@ class ll {
6390
6413
  const A = new Error(`Webview load timeout: ${e}`);
6391
6414
  this.ctx.emit("error", { code: "LOAD_TIMEOUT", message: A.message, url: e, cause: A }), o(A);
6392
6415
  }, this.ctx.rendererContext.timeout), l = () => {
6393
- window.clearTimeout(a), t.removeEventListener("did-finish-load", d), t.removeEventListener("did-fail-load", h);
6416
+ window.clearTimeout(a), t.removeEventListener("did-finish-load", d), t.removeEventListener("did-fail-load", u);
6394
6417
  }, d = () => {
6395
6418
  l(), this.gestureBus?.notifyIframeReady();
6396
6419
  const A = Math.round(performance.now() - r);
6397
6420
  this.ctx.emit("load", { url: e, duration: A }), this.ctx.emit("renderDone", { url: e, duration: A }), i();
6398
- }, h = (A) => {
6399
- const u = A;
6421
+ }, u = (A) => {
6422
+ const h = A;
6400
6423
  l();
6401
- const m = u.errorDescription || `Webview load failed: ${e}`, w = new Error(m);
6402
- this.ctx.emit("error", { code: "LOAD_FAILED", message: m, url: e, cause: A }), o(w);
6424
+ const m = h.errorDescription || `Webview load failed: ${e}`, v = new Error(m);
6425
+ this.ctx.emit("error", { code: "LOAD_FAILED", message: m, url: e, cause: A }), o(v);
6403
6426
  };
6404
- t.addEventListener("did-finish-load", d), t.addEventListener("did-fail-load", h), t.src = s;
6427
+ t.addEventListener("did-finish-load", d), t.addEventListener("did-fail-load", u), t.src = s;
6405
6428
  });
6406
6429
  }
6407
6430
  reload(e) {
@@ -6570,7 +6593,7 @@ function Vl(n) {
6570
6593
  const t = Number(e[1]), r = Number(e[2]), s = Number(e[3]), i = e[4] != null ? Number(e[4]) : 1;
6571
6594
  return [t, r, s, i].every(Number.isFinite) ? { r: t, g: r, b: s, a: i } : null;
6572
6595
  }
6573
- function Il(n, e) {
6596
+ function Ll(n, e) {
6574
6597
  let t = n;
6575
6598
  for (; t; ) {
6576
6599
  const r = Vl(e.getComputedStyle(t).backgroundColor);
@@ -6580,7 +6603,7 @@ function Il(n, e) {
6580
6603
  }
6581
6604
  return { r: 255, g: 255, b: 255 };
6582
6605
  }
6583
- const Ll = [8, 24, 48], Wl = [0.16, 0.5, 0.84];
6606
+ const Il = [8, 24, 48], Wl = [0.16, 0.5, 0.84];
6584
6607
  function ql(n) {
6585
6608
  let e = null, t = null;
6586
6609
  try {
@@ -6594,15 +6617,15 @@ function ql(n) {
6594
6617
  let s = 0, i = 0;
6595
6618
  for (const o of Wl) {
6596
6619
  const a = Math.round(r * o);
6597
- for (const l of Ll) {
6620
+ for (const l of Il) {
6598
6621
  let d = null;
6599
6622
  try {
6600
6623
  d = e.elementFromPoint(a, l);
6601
6624
  } catch {
6602
6625
  d = null;
6603
6626
  }
6604
- const h = Il(d ?? e.body ?? e.documentElement, t);
6605
- s += xl(h), i += 1;
6627
+ const u = Ll(d ?? e.body ?? e.documentElement, t);
6628
+ s += xl(u), i += 1;
6606
6629
  }
6607
6630
  }
6608
6631
  return i ? kl(s / i) : null;
@@ -6672,7 +6695,7 @@ const Et = 44, tr = `
6672
6695
  function bt(n, e, t) {
6673
6696
  return Math.min(t, Math.max(e, n));
6674
6697
  }
6675
- function Ir(n) {
6698
+ function Lr(n) {
6676
6699
  const e = bt(n.halfHeightRatio, 0.5, 0.95), t = Ms - e;
6677
6700
  return {
6678
6701
  expand: n.expandThresholdRatio ?? e + t * 0.55,
@@ -6684,76 +6707,76 @@ function Ir(n) {
6684
6707
  }
6685
6708
  function Ml(n) {
6686
6709
  const { sheet: e, handle: t, getBoundsHeight: r, fullScreenDragZone: s, onStateChange: i } = n;
6687
- let o = bt(n.halfHeightRatio, 0.5, 0.95), a = Ir({ ...n, halfHeightRatio: o }), l = n.initialState ?? "half", d = !1, h = null, A = 0, u = 0, m = 0, w = 1, b = 0, f = 0;
6688
- const y = () => {
6710
+ let o = bt(n.halfHeightRatio, 0.5, 0.95), a = Lr({ ...n, halfHeightRatio: o }), l = n.initialState ?? "half", d = !1, u = null, A = 0, h = 0, m = 0, v = 1, b = 0, f = 0;
6711
+ const w = () => {
6689
6712
  const C = n.getViewportHeight?.() ?? r();
6690
6713
  return bt(C * o, 0, r());
6691
- }, x = (C) => {
6714
+ }, S = (C) => {
6692
6715
  e.style.transition = C ? `height ${a.transitionMs}ms cubic-bezier(0.32, 0.72, 0, 1)` : "";
6693
- }, q = () => {
6716
+ }, L = () => {
6694
6717
  e.dataset.snapState = l, e.classList.toggle("sheet--full", l === "full"), e.classList.toggle("sheet--half", l === "half"), e.classList.toggle("sheet--closed", l === "closed");
6695
- }, k = (C, W) => {
6696
- x(W), e.style.height = `${C}px`, f = C, q();
6697
- }, S = (C) => {
6698
- const W = r();
6699
- return W ? C / W : l === "full" ? Ms : o;
6700
- }, R = (C) => {
6701
- const W = S(C);
6718
+ }, V = (C, T) => {
6719
+ S(T), e.style.height = `${C}px`, f = C, L();
6720
+ }, B = (C) => {
6721
+ const T = r();
6722
+ return T ? C / T : l === "full" ? Ms : o;
6723
+ }, E = (C) => {
6724
+ const T = B(C);
6702
6725
  if (l === "full")
6703
- return W <= a.collapse ? "half" : "full";
6704
- if (W >= a.expand) return "full";
6705
- const N = y();
6706
- if (N > 0) {
6707
- if ((N - C) / N >= Xl) return "closed";
6708
- } else if (W <= a.close)
6726
+ return T <= a.collapse ? "half" : "full";
6727
+ if (T >= a.expand) return "full";
6728
+ const M = w();
6729
+ if (M > 0) {
6730
+ if ((M - C) / M >= Xl) return "closed";
6731
+ } else if (T <= a.close)
6709
6732
  return "closed";
6710
6733
  return "half";
6711
- }, V = (C, W = !0) => {
6734
+ }, k = (C, T = !0) => {
6712
6735
  l = C;
6713
- const N = l === "closed" ? 0 : l === "full" ? r() : y();
6714
- k(N, W), i?.(l);
6715
- }, Z = (C, W, N) => W >= C.left && W <= C.right && N >= C.top && N <= C.bottom, Y = (C, W, N) => {
6736
+ const M = l === "closed" ? 0 : l === "full" ? r() : w();
6737
+ V(M, T), i?.(l);
6738
+ }, N = (C, T, M) => T >= C.left && T <= C.right && M >= C.top && M <= C.bottom, Z = (C, T, M) => {
6716
6739
  if (C === t || C instanceof Node && t.contains(C)) return !0;
6717
6740
  const se = t.getBoundingClientRect();
6718
- return Z(se, W, N);
6719
- }, Q = (C, W) => s ? Z(s.getBoundingClientRect(), C, W) : !1, $ = (C, W, N) => n.locked || l === "closed" ? !1 : l === "half" ? Y(C, W, N) : s ? Q(W, N) : e.getBoundingClientRect().height <= 0 ? Y(C, W, N) : Pe(e, W, N).y / e.offsetHeight <= a.topZone || Y(C, W, N);
6720
- let X = null, P = null;
6721
- const M = () => {
6722
- X && (window.removeEventListener("pointermove", X), X = null), P && (window.removeEventListener("pointerup", P), window.removeEventListener("pointercancel", P), P = null);
6723
- }, fe = (C) => {
6741
+ return N(se, T, M);
6742
+ }, G = (C, T) => s ? N(s.getBoundingClientRect(), C, T) : !1, $ = (C, T, M) => n.locked || l === "closed" ? !1 : l === "half" ? Z(C, T, M) : s ? G(T, M) : e.getBoundingClientRect().height <= 0 ? Z(C, T, M) : Pe(e, T, M).y / e.offsetHeight <= a.topZone || Z(C, T, M);
6743
+ let D = null, I = null;
6744
+ const P = () => {
6745
+ D && (window.removeEventListener("pointermove", D), D = null), I && (window.removeEventListener("pointerup", I), window.removeEventListener("pointercancel", I), I = null);
6746
+ }, de = (C) => {
6724
6747
  if (!(C.button !== 0 || d) && $(C.target, C.clientX, C.clientY)) {
6725
- d = !0, h = C.pointerId, A = C.clientX, u = C.clientY, m = xn(e, 1, 0).y, w = xn(e, 0, 1).y, b = f, x(!1);
6748
+ d = !0, u = C.pointerId, A = C.clientX, h = C.clientY, m = xn(e, 1, 0).y, v = xn(e, 0, 1).y, b = f, S(!1);
6726
6749
  try {
6727
6750
  e.setPointerCapture(C.pointerId);
6728
6751
  } catch {
6729
6752
  }
6730
- e.classList.add("sheet--dragging"), X = (W) => ne(W), P = (W) => re(W), window.addEventListener("pointermove", X), window.addEventListener("pointerup", P), window.addEventListener("pointercancel", P), C.preventDefault(), C.stopPropagation();
6753
+ e.classList.add("sheet--dragging"), D = (T) => te(T), I = (T) => re(T), window.addEventListener("pointermove", D), window.addEventListener("pointerup", I), window.addEventListener("pointercancel", I), C.preventDefault(), C.stopPropagation();
6731
6754
  }
6732
- }, ne = (C) => {
6733
- if (!d || h !== null && C.pointerId !== h) return;
6734
- const W = r(), N = (C.clientX - A) * m + (C.clientY - u) * w, se = bt(b - N, 0, W);
6735
- k(se, !1);
6755
+ }, te = (C) => {
6756
+ if (!d || u !== null && C.pointerId !== u) return;
6757
+ const T = r(), M = (C.clientX - A) * m + (C.clientY - h) * v, se = bt(b - M, 0, T);
6758
+ V(se, !1);
6736
6759
  }, re = (C) => {
6737
- if (!(!d || h !== null && C.pointerId !== h)) {
6738
- d = !1, h = null, M(), e.classList.remove("sheet--dragging");
6760
+ if (!(!d || u !== null && C.pointerId !== u)) {
6761
+ d = !1, u = null, P(), e.classList.remove("sheet--dragging");
6739
6762
  try {
6740
6763
  e.hasPointerCapture(C.pointerId) && e.releasePointerCapture(C.pointerId);
6741
6764
  } catch {
6742
6765
  }
6743
- V(R(f), !0);
6766
+ k(E(f), !0);
6744
6767
  }
6745
6768
  };
6746
- return e.addEventListener("pointerdown", fe), V(l, !1), {
6769
+ return e.addEventListener("pointerdown", de), k(l, !1), {
6747
6770
  getState: () => l,
6748
6771
  setHalfHeightRatio(C) {
6749
- o = bt(C, 0.5, 0.95), a = Ir({ ...n, halfHeightRatio: o }), V(l, !1);
6772
+ o = bt(C, 0.5, 0.95), a = Lr({ ...n, halfHeightRatio: o }), k(l, !1);
6750
6773
  },
6751
- snapTo: V,
6774
+ snapTo: k,
6752
6775
  refresh() {
6753
- V(l, !1);
6776
+ k(l, !1);
6754
6777
  },
6755
6778
  destroy() {
6756
- M(), e.removeEventListener("pointerdown", fe);
6779
+ P(), e.removeEventListener("pointerdown", de);
6757
6780
  }
6758
6781
  };
6759
6782
  }
@@ -7850,9 +7873,9 @@ class Zl extends HTMLElement {
7850
7873
  if (!l) return;
7851
7874
  l.innerHTML = "", this._halfSheet = document.createElement(qn), this._halfSheet.setAttribute("launch-mode", this._launchMode), this._halfSheet.setAttribute("height-ratio", String(this._sheetOptions.heightRatio)), this._halfSheet.setPlaceholderText(this._sheetOptions.placeholderText);
7852
7875
  const d = this.shadowRoot.querySelector(".shell");
7853
- let h = "closed";
7876
+ let u = "closed";
7854
7877
  this._halfSheet.onSnapStateChange = (A) => {
7855
- d?.classList.toggle("sheet-open", A !== "closed"), d?.classList.toggle("sheet-full", A === "full"), A === "closed" ? h !== "closed" && this.onContentClose?.() : h === "closed" && this.onContentOpen?.(), h = A;
7878
+ d?.classList.toggle("sheet-open", A !== "closed"), d?.classList.toggle("sheet-full", A === "full"), A === "closed" ? u !== "closed" && this.onContentClose?.() : u === "closed" && this.onContentOpen?.(), u = A;
7856
7879
  }, this._halfSheet.onChromeToneChange = (A) => {
7857
7880
  d && (d.dataset.chromeTone = A);
7858
7881
  }, l.appendChild(this._halfSheet);
@@ -7898,7 +7921,7 @@ class Zl extends HTMLElement {
7898
7921
  const i = e.querySelector(".gallery__track");
7899
7922
  i && (i.style.transform = `translateX(-${t * 100}%)`);
7900
7923
  const o = e.querySelector(".gallery__badge-num");
7901
- o && (o.textContent = `${Math.min(t + 1, Dt)}/${Dt}`), e.querySelectorAll(".gallery-dots span").forEach((h, A) => h.classList.toggle("is-active", A === t));
7924
+ o && (o.textContent = `${Math.min(t + 1, Dt)}/${Dt}`), e.querySelectorAll(".gallery-dots span").forEach((u, A) => u.classList.toggle("is-active", A === t));
7902
7925
  const l = e.querySelector(".gallery__arrow--prev"), d = e.querySelector(".gallery__arrow--next");
7903
7926
  l && (l.disabled = t === 0), d && (d.disabled = r);
7904
7927
  }
@@ -8431,7 +8454,7 @@ class Ql extends HTMLElement {
8431
8454
  const i = t?.user, o = r?.cover ?? "", a = !!o, l = r?.title || (a ? Qt : "小工具名称");
8432
8455
  s.innerHTML = `
8433
8456
  <div class="card__cover">
8434
- ${a ? `<img src="${Lr(o)}" alt="" referrerpolicy="no-referrer" />` : '<span class="card__cover-placeholder">暂未上传封面</span>'}
8457
+ ${a ? `<img src="${Ir(o)}" alt="" referrerpolicy="no-referrer" />` : '<span class="card__cover-placeholder">暂未上传封面</span>'}
8435
8458
  <button type="button" class="card__type card__type--action" aria-label="打开小工具">
8436
8459
  <img src="${Xs}" alt="" referrerpolicy="no-referrer" />
8437
8460
  </button>
@@ -8439,7 +8462,7 @@ class Ql extends HTMLElement {
8439
8462
  <div class="card__body">
8440
8463
  <div class="card__title">${Rn(l)}</div>
8441
8464
  <div class="card__author">
8442
- ${i?.avatar ? `<img src="${Lr(i.avatar)}" alt="" referrerpolicy="no-referrer" />` : '<span class="card__author-ph-avatar" aria-hidden="true"></span>'}
8465
+ ${i?.avatar ? `<img src="${Ir(i.avatar)}" alt="" referrerpolicy="no-referrer" />` : '<span class="card__author-ph-avatar" aria-hidden="true"></span>'}
8443
8466
  ${i?.nickname ? `<div class="card__author-text">
8444
8467
  <span class="card__author-name">${Rn(i.nickname)}</span>
8445
8468
  <span class="card__author-time">刚刚</span>
@@ -8496,7 +8519,7 @@ function zl() {
8496
8519
  function Rn(n) {
8497
8520
  return n.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
8498
8521
  }
8499
- function Lr(n) {
8522
+ function Ir(n) {
8500
8523
  return Rn(n).replace(/'/g, "&#39;");
8501
8524
  }
8502
8525
  function jl() {
@@ -8576,7 +8599,7 @@ class Os {
8576
8599
  this.detailShell?.remove(), this.detailShell = null, this.profileShell?.remove(), this.profileShell = null;
8577
8600
  }
8578
8601
  }
8579
- class _l extends Is {
8602
+ class _l extends Ls {
8580
8603
  constructor(e) {
8581
8604
  super(), this.frame = null, this.overlay = null, this.container = null, this.contentRoot = null, this.rednoteShell = null, this.contentHost = null, this.currentUrl = "", this.desiredZoom = 1, this.bridge = null, this.frameToastHost = null, this.detachFramelessShellWindowSync = null, this.detachContentPcGuard = null, this.forwardEmit = (t, r) => {
8582
8605
  this.emit(t, r);
@@ -8679,7 +8702,7 @@ class _l extends Is {
8679
8702
  this.viewport = e;
8680
8703
  const t = this.context.phoneFrame;
8681
8704
  if (t) {
8682
- In(this.container), Ln(this.contentRoot), this.container.style.position = "relative", this.container.style.width = `${t.width}px`, this.container.style.height = `${t.height}px`, this.frame && (this.frame.style.left = `${t.screen.x}px`, this.frame.style.top = `${t.screen.y}px`, this.frame.style.width = `${t.screen.width}px`, this.frame.style.height = `${t.screen.height}px`);
8705
+ Ln(this.container), In(this.contentRoot), this.container.style.position = "relative", this.container.style.width = `${t.width}px`, this.container.style.height = `${t.height}px`, this.frame && (this.frame.style.left = `${t.screen.x}px`, this.frame.style.top = `${t.screen.y}px`, this.frame.style.width = `${t.screen.width}px`, this.frame.style.height = `${t.screen.height}px`);
8683
8706
  const r = t.screen.width / e.width, s = t.screen.height / e.height;
8684
8707
  this.contentRoot.style.width = `${e.width}px`, this.contentRoot.style.height = `${e.height}px`, this.contentRoot.style.transformOrigin = "top left", this.contentRoot.style.transform = `scale(${r}, ${s})`;
8685
8708
  } else {
@@ -8747,7 +8770,7 @@ function tc(n) {
8747
8770
  } catch {
8748
8771
  }
8749
8772
  }
8750
- function xu() {
8773
+ function ku() {
8751
8774
  return Zs;
8752
8775
  }
8753
8776
  const nc = 6e4;
@@ -8837,12 +8860,12 @@ function lc(n) {
8837
8860
  return n;
8838
8861
  }
8839
8862
  const e = new Error("storage io error");
8840
- return e.code = T.STORAGE_IO_ERROR, e;
8863
+ return e.code = F.STORAGE_IO_ERROR, e;
8841
8864
  }
8842
8865
  function cc(n) {
8843
8866
  return {
8844
- title: Le(n.title),
8845
- content: Le(n.content),
8867
+ title: Ie(n.title),
8868
+ content: Ie(n.content),
8846
8869
  pageType: typeof n.pageType == "string" ? n.pageType : void 0,
8847
8870
  tags: uc(n.tags),
8848
8871
  media: dc(n.mediaInfo)
@@ -8853,26 +8876,26 @@ function dc(n) {
8853
8876
  if (!e) return [];
8854
8877
  const t = [];
8855
8878
  for (const s of qr(e.image_resources)) {
8856
- const i = Le(Pt(s)?.url);
8879
+ const i = Ie(Pt(s)?.url);
8857
8880
  i && t.push({ type: "image", url: i });
8858
8881
  }
8859
8882
  const r = Pt(e.video_resources);
8860
8883
  if (r) {
8861
- const s = Le(r.video_url), i = Le(r.cover_url);
8884
+ const s = Ie(r.video_url), i = Ie(r.cover_url);
8862
8885
  s && t.push({ type: "video", url: s, ...i ? { cover: i } : {} });
8863
8886
  }
8864
8887
  for (const s of qr(e.live_photo_resources)) {
8865
- const i = Pt(s), o = Le(i?.video_url), a = Le(i?.url);
8888
+ const i = Pt(s), o = Ie(i?.video_url), a = Ie(i?.url);
8866
8889
  o && a && t.push({ type: "live_photo", url: o, cover: a });
8867
8890
  }
8868
8891
  return t;
8869
8892
  }
8870
8893
  function uc(n) {
8871
- if (Array.isArray(n)) return n.map(Le).filter(Boolean);
8872
- const e = Le(n);
8894
+ if (Array.isArray(n)) return n.map(Ie).filter(Boolean);
8895
+ const e = Ie(n);
8873
8896
  return e ? e.split(/[\s,,、#]+/).map((t) => t.trim()).filter(Boolean) : [];
8874
8897
  }
8875
- function Le(n) {
8898
+ function Ie(n) {
8876
8899
  return typeof n == "string" ? n : "";
8877
8900
  }
8878
8901
  function qr(n) {
@@ -9016,15 +9039,15 @@ async function Gs(n, e) {
9016
9039
  if (t.push(a.buffer), r += a.byteLength, i.eof) break;
9017
9040
  }
9018
9041
  } catch {
9019
- throw U(
9020
- T.FILE_NOT_FOUND,
9042
+ throw Y(
9043
+ F.FILE_NOT_FOUND,
9021
9044
  "media file could not be read"
9022
9045
  );
9023
9046
  }
9024
9047
  const s = Us(t[0]);
9025
9048
  if (!s)
9026
- throw U(
9027
- T.INVALID_PARAM,
9049
+ throw Y(
9050
+ F.INVALID_PARAM,
9028
9051
  "filePath must reference supported media"
9029
9052
  );
9030
9053
  return new Blob(t, { type: s });
@@ -9041,8 +9064,8 @@ function bc(n) {
9041
9064
  if (!/^https?:$/.test(s.protocol) || !s.pathname.includes(nr))
9042
9065
  return r;
9043
9066
  if (s.origin !== new URL(n.loadedUrl).origin)
9044
- throw U(
9045
- T.URL_SCHEME_NOT_ALLOWED,
9067
+ throw Y(
9068
+ F.URL_SCHEME_NOT_ALLOWED,
9046
9069
  "media file must belong to the simulator origin"
9047
9070
  );
9048
9071
  const i = e.get(s.href);
@@ -9101,8 +9124,8 @@ function yc(n) {
9101
9124
  handler: (e) => {
9102
9125
  const { type: t } = e.message;
9103
9126
  if (t !== "light" && t !== "medium" && t !== "heavy")
9104
- throw U(
9105
- T.INVALID_PARAM,
9127
+ throw Y(
9128
+ F.INVALID_PARAM,
9106
9129
  'type must be "heavy", "medium" or "light"'
9107
9130
  );
9108
9131
  return n.vibrate(t), {};
@@ -9164,13 +9187,13 @@ function Vc() {
9164
9187
  name: "location",
9165
9188
  handlers: {
9166
9189
  getLocation: {
9167
- handler: Ic(),
9190
+ handler: Lc(),
9168
9191
  hostOverride: "function-only"
9169
9192
  }
9170
9193
  }
9171
9194
  };
9172
9195
  }
9173
- function Ic() {
9196
+ function Lc() {
9174
9197
  return async (n) => {
9175
9198
  const { type: e } = n.message;
9176
9199
  if (e !== void 0 && e !== "wgs84" && e !== "gcj02")
@@ -9186,7 +9209,7 @@ function Ic() {
9186
9209
  };
9187
9210
  };
9188
9211
  }
9189
- const Lc = /^data:image\/[a-z0-9.+-]+;base64,/i, Wc = /^https?:\/\//i;
9212
+ const Ic = /^data:image\/[a-z0-9.+-]+;base64,/i, Wc = /^https?:\/\//i;
9190
9213
  function qc(n) {
9191
9214
  return {
9192
9215
  name: "media",
@@ -9207,14 +9230,14 @@ function Bc(n) {
9207
9230
  }
9208
9231
  function Tc(n) {
9209
9232
  if (typeof n != "string" || !n.trim())
9210
- throw U(T.INVALID_PARAM, "filePath is required");
9233
+ throw Y(F.INVALID_PARAM, "filePath is required");
9211
9234
  return n.trim();
9212
9235
  }
9213
9236
  function Rc(n, e) {
9214
9237
  if (n.startsWith("data:")) {
9215
- if (!Lc.test(n))
9216
- throw U(
9217
- T.INVALID_PARAM,
9238
+ if (!Ic.test(n))
9239
+ throw Y(
9240
+ F.INVALID_PARAM,
9218
9241
  "filePath must be a base64 image data URI"
9219
9242
  );
9220
9243
  return n;
@@ -9223,13 +9246,13 @@ function Rc(n, e) {
9223
9246
  try {
9224
9247
  r = new URL(e), t = new URL(n, r);
9225
9248
  } catch {
9226
- throw U(T.PATH_INVALID, "filePath is invalid");
9249
+ throw Y(F.PATH_INVALID, "filePath is invalid");
9227
9250
  }
9228
9251
  if (t.protocol !== "http:" && t.protocol !== "https:")
9229
- throw U(T.PATH_INVALID, "filePath is invalid");
9252
+ throw Y(F.PATH_INVALID, "filePath is invalid");
9230
9253
  if (t.origin !== r.origin || Wc.test(n) && !t.pathname.includes(nr))
9231
- throw U(
9232
- T.URL_SCHEME_NOT_ALLOWED,
9254
+ throw Y(
9255
+ F.URL_SCHEME_NOT_ALLOWED,
9233
9256
  "network image URLs are not supported"
9234
9257
  );
9235
9258
  return t.href;
@@ -9262,14 +9285,14 @@ async function Fc(n, e, t) {
9262
9285
  return s;
9263
9286
  }
9264
9287
  function Fr() {
9265
- return U(
9266
- T.FILE_NOT_FOUND,
9288
+ return Y(
9289
+ F.FILE_NOT_FOUND,
9267
9290
  "image file could not be read"
9268
9291
  );
9269
9292
  }
9270
9293
  function Mt() {
9271
- return U(
9272
- T.INVALID_PARAM,
9294
+ return Y(
9295
+ F.INVALID_PARAM,
9273
9296
  "filePath must reference an image"
9274
9297
  );
9275
9298
  }
@@ -9401,23 +9424,23 @@ function Qc(n) {
9401
9424
  };
9402
9425
  return {
9403
9426
  setStorage: (i) => s(async () => {
9404
- const o = mn(i), a = zc(i), l = Nr(i), d = jc(a), h = new TextEncoder().encode(d).byteLength;
9405
- if (h > Mr)
9427
+ const o = mn(i), a = zc(i), l = Nr(i), d = jc(a), u = new TextEncoder().encode(d).byteLength;
9428
+ if (u > Mr)
9406
9429
  throw Or(
9407
- T.STORAGE_QUOTA_EXCEEDED,
9430
+ F.STORAGE_QUOTA_EXCEEDED,
9408
9431
  `data exceeds the ${Mr / zt}MB storage limit`
9409
9432
  );
9410
- const A = await t.list(e), u = A.reduce((w, b) => w + b.sizeBytes, 0), m = A.find((w) => w.key === o)?.sizeBytes ?? 0;
9411
- if (u - m + h > gn)
9433
+ const A = await t.list(e), h = A.reduce((v, b) => v + b.sizeBytes, 0), m = A.find((v) => v.key === o)?.sizeBytes ?? 0;
9434
+ if (h - m + u > gn)
9412
9435
  throw Or(
9413
- T.STORAGE_QUOTA_EXCEEDED,
9436
+ F.STORAGE_QUOTA_EXCEEDED,
9414
9437
  `storage exceeds the ${gn / zt}MB limit`
9415
9438
  );
9416
9439
  return await t.put({
9417
9440
  scope: e,
9418
9441
  key: o,
9419
9442
  data: JSON.parse(d),
9420
- sizeBytes: h,
9443
+ sizeBytes: u,
9421
9444
  encrypted: l
9422
9445
  }), {};
9423
9446
  }),
@@ -9468,7 +9491,7 @@ function jc(n) {
9468
9491
  }
9469
9492
  function kt(n) {
9470
9493
  const e = new TypeError(n);
9471
- return e.code = T.INVALID_PARAM, e;
9494
+ return e.code = F.INVALID_PARAM, e;
9472
9495
  }
9473
9496
  function Or(n, e) {
9474
9497
  const t = new Error(e);
@@ -9533,8 +9556,8 @@ function _c(n, e, t) {
9533
9556
  throw new Error(`duplicate simulator jsapi handler: ${i}`);
9534
9557
  r.add(i);
9535
9558
  const a = o.hostOverride ?? "allow", l = a === "forbid" ? o.handler : (d) => {
9536
- const h = t.hostApiMap[d.event];
9537
- return !h || a === "function-only" && typeof h != "function" ? o.handler(d) : t.runHostEntry(h, d);
9559
+ const u = t.hostApiMap[d.event];
9560
+ return !u || a === "function-only" && typeof u != "function" ? o.handler(d) : t.runHostEntry(u, d);
9538
9561
  };
9539
9562
  n.handle(i, l);
9540
9563
  }
@@ -9570,8 +9593,8 @@ class $c {
9570
9593
  return;
9571
9594
  }
9572
9595
  s.type === "error" && i.reject(
9573
- U(
9574
- s.code ?? T.REQUEST_FAILED,
9596
+ Y(
9597
+ s.code ?? F.REQUEST_FAILED,
9575
9598
  s.message ?? "request failed"
9576
9599
  )
9577
9600
  );
@@ -9584,15 +9607,15 @@ class $c {
9584
9607
  }
9585
9608
  async execute(e) {
9586
9609
  if (this.destroyed)
9587
- throw U(
9588
- T.REQUEST_ABORTED,
9610
+ throw Y(
9611
+ F.REQUEST_ABORTED,
9589
9612
  "request manager destroyed"
9590
9613
  );
9591
9614
  if (this.pending.has(e.taskId))
9592
- throw U(T.INVALID_PARAM, "duplicate taskId");
9615
+ throw Y(F.INVALID_PARAM, "duplicate taskId");
9593
9616
  if (await this.ready, this.destroyed)
9594
- throw U(
9595
- T.REQUEST_ABORTED,
9617
+ throw Y(
9618
+ F.REQUEST_ABORTED,
9596
9619
  "request manager destroyed"
9597
9620
  );
9598
9621
  return new Promise((t, r) => {
@@ -9616,7 +9639,7 @@ class $c {
9616
9639
  this.destroyed = !0, window.removeEventListener("message", this.handleMessage);
9617
9640
  for (const e of this.pending.values())
9618
9641
  e.reject(
9619
- U(T.REQUEST_ABORTED, "request manager destroyed")
9642
+ Y(F.REQUEST_ABORTED, "request manager destroyed")
9620
9643
  );
9621
9644
  this.pending.clear(), this.iframe.remove();
9622
9645
  }
@@ -9624,22 +9647,22 @@ class $c {
9624
9647
  }
9625
9648
  function ed() {
9626
9649
  const n = {
9627
- urlSchemeNotAllowed: T.URL_SCHEME_NOT_ALLOWED,
9628
- timeout: T.REQUEST_TIMEOUT,
9629
- aborted: T.REQUEST_ABORTED,
9630
- failed: T.REQUEST_FAILED
9650
+ urlSchemeNotAllowed: F.URL_SCHEME_NOT_ALLOWED,
9651
+ timeout: F.REQUEST_TIMEOUT,
9652
+ aborted: F.REQUEST_ABORTED,
9653
+ failed: F.REQUEST_FAILED
9631
9654
  }, t = `<!doctype html><html><head><meta charset="UTF-8"><meta name="referrer" content="no-referrer"><meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'unsafe-inline'; connect-src https: http: ws: wss:; base-uri 'none'; form-action 'none'"></head><body><script>${`(${td.toString()})(${JSON.stringify(n)},${ei.toString()},${ti.toString()});`.replace(/<\/script/gi, "<\\/script")}<\/script></body></html>`;
9632
9655
  return `data:text/html;charset=utf-8,${encodeURIComponent(t)}`;
9633
9656
  }
9634
9657
  function td(n, e, t) {
9635
- const r = "mini-app:request-manager", s = /* @__PURE__ */ new Map(), i = (u) => {
9636
- parent.postMessage({ channel: r, ...u }, "*");
9637
- }, o = (u) => {
9658
+ const r = "mini-app:request-manager", s = /* @__PURE__ */ new Map(), i = (h) => {
9659
+ parent.postMessage({ channel: r, ...h }, "*");
9660
+ }, o = (h) => {
9638
9661
  const m = {};
9639
- return u.forEach((w, b) => {
9640
- b.toLowerCase() !== "set-cookie" && (m[b.toLowerCase()] = w);
9662
+ return h.forEach((v, b) => {
9663
+ b.toLowerCase() !== "set-cookie" && (m[b.toLowerCase()] = v);
9641
9664
  }), m;
9642
- }, a = (u) => {
9665
+ }, a = (h) => {
9643
9666
  const m = /* @__PURE__ */ new Set([
9644
9667
  "cookie",
9645
9668
  "referer",
@@ -9647,123 +9670,123 @@ function td(n, e, t) {
9647
9670
  "user-agent",
9648
9671
  "host",
9649
9672
  "content-length"
9650
- ]), w = new Headers();
9651
- for (const [b, f] of Object.entries(u ?? {}))
9652
- m.has(b.toLowerCase()) || w.set(b, String(f));
9653
- return w;
9654
- }, l = (u) => u == null ? "" : typeof u == "string" ? u : typeof u != "object" || Array.isArray(u) ? String(u) : Object.entries(u).map(([m, w]) => `${encodeURIComponent(m)}=${encodeURIComponent(String(w))}`).join("&"), d = (u, m) => {
9655
- const w = l(m);
9656
- w && (u.search += `${u.search ? "&" : ""}${w}`);
9657
- }, h = (u, m) => {
9658
- if (u == null) return;
9659
- if (typeof u == "string") return u;
9660
- const w = m.get("content-type")?.toLowerCase() ?? "";
9661
- return w.includes("application/x-www-form-urlencoded") ? l(u) : w ? w.includes("application/json") ? JSON.stringify(u) : String(u) : (m.set("content-type", "application/json"), JSON.stringify(u));
9662
- }, A = async (u) => {
9663
- const m = new AbortController(), w = {
9673
+ ]), v = new Headers();
9674
+ for (const [b, f] of Object.entries(h ?? {}))
9675
+ m.has(b.toLowerCase()) || v.set(b, String(f));
9676
+ return v;
9677
+ }, l = (h) => h == null ? "" : typeof h == "string" ? h : typeof h != "object" || Array.isArray(h) ? String(h) : Object.entries(h).map(([m, v]) => `${encodeURIComponent(m)}=${encodeURIComponent(String(v))}`).join("&"), d = (h, m) => {
9678
+ const v = l(m);
9679
+ v && (h.search += `${h.search ? "&" : ""}${v}`);
9680
+ }, u = (h, m) => {
9681
+ if (h == null) return;
9682
+ if (typeof h == "string") return h;
9683
+ const v = m.get("content-type")?.toLowerCase() ?? "";
9684
+ return v.includes("application/x-www-form-urlencoded") ? l(h) : v ? v.includes("application/json") ? JSON.stringify(h) : String(h) : (m.set("content-type", "application/json"), JSON.stringify(h));
9685
+ }, A = async (h) => {
9686
+ const m = new AbortController(), v = {
9664
9687
  controller: m
9665
9688
  };
9666
- s.set(u.taskId, w);
9689
+ s.set(h.taskId, v);
9667
9690
  try {
9668
- const b = new URL(u.url);
9691
+ const b = new URL(h.url);
9669
9692
  if (b.protocol !== "https:" && b.protocol !== "http:")
9670
9693
  throw Object.assign(new Error("request scheme is not allowed"), {
9671
9694
  code: n.urlSchemeNotAllowed
9672
9695
  });
9673
- const f = u.method.toUpperCase(), y = a(u.header), x = u.data;
9674
- (f === "GET" || f === "HEAD") && d(b, x);
9675
- const q = Number(u.timeout);
9676
- Number.isFinite(q) && q > 0 && (w.timer = window.setTimeout(() => {
9677
- w.abortReason = "timeout", m.abort();
9678
- }, q));
9679
- const k = await fetch(b.href, {
9696
+ const f = h.method.toUpperCase(), w = a(h.header), S = h.data;
9697
+ (f === "GET" || f === "HEAD") && d(b, S);
9698
+ const L = Number(h.timeout);
9699
+ Number.isFinite(L) && L > 0 && (v.timer = window.setTimeout(() => {
9700
+ v.abortReason = "timeout", m.abort();
9701
+ }, L));
9702
+ const V = await fetch(b.href, {
9680
9703
  method: f,
9681
- headers: y,
9682
- body: f === "GET" || f === "HEAD" ? void 0 : h(x, y),
9704
+ headers: w,
9705
+ body: f === "GET" || f === "HEAD" ? void 0 : u(S, w),
9683
9706
  credentials: "omit",
9684
9707
  redirect: "follow",
9685
9708
  signal: m.signal
9686
- }).catch((Z) => {
9687
- throw Z instanceof TypeError && !m.signal.aborted ? new Error(
9688
- `${Z.message || "request failed"}; possible CORS or network/security policy failure. Simulator requests use Origin: null. Check the server's Access-Control-Allow-Origin response header and browser DevTools Console/Network for details.`
9689
- ) : Z;
9690
- }), S = o(k.headers);
9709
+ }).catch((N) => {
9710
+ throw N instanceof TypeError && !m.signal.aborted ? new Error(
9711
+ `${N.message || "request failed"}; possible CORS or network/security policy failure. Simulator requests use Origin: null. Check the server's Access-Control-Allow-Origin response header and browser DevTools Console/Network for details.`
9712
+ ) : N;
9713
+ }), B = o(V.headers);
9691
9714
  if (i({
9692
9715
  type: "headers",
9693
- taskId: u.taskId,
9694
- statusCode: k.status,
9695
- header: S
9696
- }), u.enableChunked && e(k.headers.get("content-type")) && k.body) {
9697
- const Z = k.body.getReader(), Y = new TextDecoder(), Q = t(), $ = (P) => {
9698
- for (const M of Q.push(P))
9699
- i({ type: "chunk", taskId: u.taskId, data: M });
9716
+ taskId: h.taskId,
9717
+ statusCode: V.status,
9718
+ header: B
9719
+ }), h.enableChunked && e(V.headers.get("content-type")) && V.body) {
9720
+ const N = V.body.getReader(), Z = new TextDecoder(), G = t(), $ = (I) => {
9721
+ for (const P of G.push(I))
9722
+ i({ type: "chunk", taskId: h.taskId, data: P });
9700
9723
  };
9701
9724
  for (; ; ) {
9702
- const P = await Z.read();
9703
- if (P.done) break;
9704
- const M = Y.decode(P.value, { stream: !0 });
9705
- M && $(M);
9706
- }
9707
- const X = Y.decode();
9708
- X && $(X);
9709
- for (const P of Q.finish())
9710
- i({ type: "chunk", taskId: u.taskId, data: P });
9725
+ const I = await N.read();
9726
+ if (I.done) break;
9727
+ const P = Z.decode(I.value, { stream: !0 });
9728
+ P && $(P);
9729
+ }
9730
+ const D = Z.decode();
9731
+ D && $(D);
9732
+ for (const I of G.finish())
9733
+ i({ type: "chunk", taskId: h.taskId, data: I });
9711
9734
  i({
9712
9735
  type: "result",
9713
- taskId: u.taskId,
9736
+ taskId: h.taskId,
9714
9737
  data: {
9715
- taskId: u.taskId,
9716
- statusCode: k.status,
9738
+ taskId: h.taskId,
9739
+ statusCode: V.status,
9717
9740
  data: "",
9718
- header: S
9741
+ header: B
9719
9742
  }
9720
9743
  });
9721
9744
  return;
9722
9745
  }
9723
- let R;
9724
- const V = await k.text();
9725
- if (u.dataType === "json")
9746
+ let E;
9747
+ const k = await V.text();
9748
+ if (h.dataType === "json")
9726
9749
  try {
9727
- R = JSON.parse(V);
9750
+ E = JSON.parse(k);
9728
9751
  } catch {
9729
- R = V;
9752
+ E = k;
9730
9753
  }
9731
9754
  else
9732
- R = V;
9755
+ E = k;
9733
9756
  i({
9734
9757
  type: "result",
9735
- taskId: u.taskId,
9758
+ taskId: h.taskId,
9736
9759
  data: {
9737
- taskId: u.taskId,
9738
- statusCode: k.status,
9739
- data: R,
9740
- header: S
9760
+ taskId: h.taskId,
9761
+ statusCode: V.status,
9762
+ data: E,
9763
+ header: B
9741
9764
  }
9742
9765
  });
9743
9766
  } catch (b) {
9744
- const f = b, y = s.get(u.taskId), x = y?.abortReason === "cancel" ? n.aborted : y?.abortReason === "timeout" ? n.timeout : f.code ?? n.failed;
9767
+ const f = b, w = s.get(h.taskId), S = w?.abortReason === "cancel" ? n.aborted : w?.abortReason === "timeout" ? n.timeout : f.code ?? n.failed;
9745
9768
  i({
9746
9769
  type: "error",
9747
- taskId: u.taskId,
9748
- code: x,
9770
+ taskId: h.taskId,
9771
+ code: S,
9749
9772
  message: f.message || "request failed"
9750
9773
  });
9751
9774
  } finally {
9752
- const b = s.get(u.taskId);
9753
- b?.timer !== void 0 && window.clearTimeout(b.timer), s.delete(u.taskId);
9775
+ const b = s.get(h.taskId);
9776
+ b?.timer !== void 0 && window.clearTimeout(b.timer), s.delete(h.taskId);
9754
9777
  }
9755
9778
  };
9756
- addEventListener("message", (u) => {
9757
- if (u.source !== parent) return;
9758
- const m = u.data;
9779
+ addEventListener("message", (h) => {
9780
+ if (h.source !== parent) return;
9781
+ const m = h.data;
9759
9782
  if (m?.channel === r) {
9760
9783
  if (m.type === "request" && m.request) {
9761
9784
  A(m.request);
9762
9785
  return;
9763
9786
  }
9764
9787
  if (m.type === "abort" && typeof m.taskId == "string") {
9765
- const w = s.get(m.taskId);
9766
- w && (w.abortReason = "cancel", w.controller.abort());
9788
+ const v = s.get(m.taskId);
9789
+ v && (v.abortReason = "cancel", v.controller.abort());
9767
9790
  }
9768
9791
  }
9769
9792
  }), i({ type: "ready" });
@@ -9778,27 +9801,27 @@ class nd {
9778
9801
  async executeInternal(e) {
9779
9802
  const t = Zr(e), r = this.options.getHostRequest();
9780
9803
  if (!r)
9781
- throw U(
9782
- T.API_UNAVAILABLE,
9804
+ throw Y(
9805
+ F.API_UNAVAILABLE,
9783
9806
  "host request adapter is unavailable"
9784
9807
  );
9785
9808
  if (this.hostRequests.has(t.taskId))
9786
- throw U(T.INVALID_PARAM, "duplicate taskId");
9809
+ throw Y(F.INVALID_PARAM, "duplicate taskId");
9787
9810
  const s = new AbortController(), i = {
9788
9811
  controller: s,
9789
- abortCode: T.REQUEST_ABORTED
9812
+ abortCode: F.REQUEST_ABORTED
9790
9813
  };
9791
9814
  this.hostRequests.set(t.taskId, i), i.timer = window.setTimeout(() => {
9792
- i.abortCode = T.REQUEST_TIMEOUT, s.abort();
9815
+ i.abortCode = F.REQUEST_TIMEOUT, s.abort();
9793
9816
  }, t.timeout);
9794
9817
  const o = new Promise((a, l) => {
9795
9818
  s.signal.addEventListener(
9796
9819
  "abort",
9797
9820
  () => {
9798
9821
  l(
9799
- U(
9822
+ Y(
9800
9823
  i.abortCode,
9801
- i.abortCode === T.REQUEST_TIMEOUT ? "request timeout" : "request aborted"
9824
+ i.abortCode === F.REQUEST_TIMEOUT ? "request timeout" : "request aborted"
9802
9825
  )
9803
9826
  );
9804
9827
  },
@@ -9817,8 +9840,8 @@ class nd {
9817
9840
  } catch (a) {
9818
9841
  if (s.signal.aborted) throw a;
9819
9842
  const l = a;
9820
- throw U(
9821
- typeof l.code == "number" ? l.code : T.REQUEST_FAILED,
9843
+ throw Y(
9844
+ typeof l.code == "number" ? l.code : F.REQUEST_FAILED,
9822
9845
  l.message || "host request failed"
9823
9846
  );
9824
9847
  } finally {
@@ -9829,12 +9852,12 @@ class nd {
9829
9852
  const t = Hs(e.message.taskId);
9830
9853
  this.isolatedRequest?.abort(t);
9831
9854
  const r = this.hostRequests.get(t);
9832
- return r && (r.abortCode = T.REQUEST_ABORTED, r.controller.abort()), { taskId: t };
9855
+ return r && (r.abortCode = F.REQUEST_ABORTED, r.controller.abort()), { taskId: t };
9833
9856
  }
9834
9857
  abortAll() {
9835
9858
  this.isolatedRequest?.abortAll();
9836
9859
  for (const e of this.hostRequests.values())
9837
- e.abortCode = T.REQUEST_ABORTED, e.controller.abort();
9860
+ e.abortCode = F.REQUEST_ABORTED, e.controller.abort();
9838
9861
  }
9839
9862
  destroy() {
9840
9863
  this.abortAll(), this.isolatedRequest?.destroy(), this.isolatedRequest = null;
@@ -9850,38 +9873,38 @@ class nd {
9850
9873
  }
9851
9874
  function Hs(n) {
9852
9875
  if (typeof n != "string" || !n || n.length > 128)
9853
- throw U(T.INVALID_PARAM, "taskId is required");
9876
+ throw Y(F.INVALID_PARAM, "taskId is required");
9854
9877
  return n;
9855
9878
  }
9856
9879
  function Zr(n) {
9857
9880
  const e = n.message, t = Hs(e.taskId);
9858
9881
  if (typeof e.url != "string" || !e.url)
9859
- throw U(T.INVALID_PARAM, "request url is required");
9882
+ throw Y(F.INVALID_PARAM, "request url is required");
9860
9883
  const r = String(e.method ?? "GET").toUpperCase();
9861
9884
  if (!["GET", "POST", "PUT", "DELETE", "HEAD", "OPTIONS"].includes(r))
9862
- throw U(
9863
- T.INVALID_PARAM,
9885
+ throw Y(
9886
+ F.INVALID_PARAM,
9864
9887
  "request method is not supported"
9865
9888
  );
9866
9889
  const s = Number(e.timeout ?? 6e4);
9867
9890
  if (!Number.isFinite(s) || s <= 0)
9868
- throw U(
9869
- T.INVALID_PARAM,
9891
+ throw Y(
9892
+ F.INVALID_PARAM,
9870
9893
  "request timeout must be greater than zero"
9871
9894
  );
9872
9895
  if (e.data instanceof ArrayBuffer || ArrayBuffer.isView(e.data))
9873
- throw U(
9874
- T.INVALID_PARAM,
9896
+ throw Y(
9897
+ F.INVALID_PARAM,
9875
9898
  "request data does not support ArrayBuffer"
9876
9899
  );
9877
9900
  if (e.dataEncoding !== void 0)
9878
- throw U(
9879
- T.INVALID_PARAM,
9901
+ throw Y(
9902
+ F.INVALID_PARAM,
9880
9903
  "request dataEncoding is not supported"
9881
9904
  );
9882
9905
  if (e.responseType !== void 0 && e.responseType !== "text")
9883
- throw U(
9884
- T.INVALID_PARAM,
9906
+ throw Y(
9907
+ F.INVALID_PARAM,
9885
9908
  "request responseType only supports text"
9886
9909
  );
9887
9910
  return {
@@ -9896,13 +9919,13 @@ function Zr(n) {
9896
9919
  enableChunked: e.enableChunked === !0
9897
9920
  };
9898
9921
  }
9899
- const Dr = 5, rd = "miniapp:restore-worker-mount", Qs = "/miniapp-simulator/", sd = 5e3, id = 3e4;
9922
+ const Dr = 6, rd = "miniapp:offloaded-resource-url", sd = "miniapp:restore-worker-mount", Qs = "/miniapp-simulator/", id = 5e3, od = 3e4;
9900
9923
  function Ur() {
9901
9924
  return typeof navigator < "u" && "serviceWorker" in navigator && typeof window < "u" && window.isSecureContext === !0;
9902
9925
  }
9903
9926
  const $e = /* @__PURE__ */ new Map();
9904
9927
  let Yr = !1;
9905
- function od() {
9928
+ function ad() {
9906
9929
  Yr || typeof window > "u" || (Yr = !0, window.addEventListener("pagehide", () => {
9907
9930
  for (const [n, e] of $e)
9908
9931
  try {
@@ -9916,10 +9939,19 @@ const Re = class Re {
9916
9939
  constructor(e, t, r, s, i) {
9917
9940
  this.sw = e, this.scope = t, this.mountTimeout = r, this.registration = s, this.scriptUrl = i, this.mountSnapshots = /* @__PURE__ */ new Map(), this.supportedFsOps = /* @__PURE__ */ new Set(), navigator.serviceWorker.addEventListener?.("message", (o) => {
9918
9941
  const a = o.data, l = o.ports[0];
9919
- if (!o.isTrusted || o.source !== this.sw || a?.type !== rd || typeof a.id != "string" || !l)
9942
+ if (!o.isTrusted || o.source !== this.sw || !a || typeof a.id != "string" || !l)
9943
+ return;
9944
+ if (a.type === rd) {
9945
+ const u = this.mountSnapshots.get(a.id)?.offloaded, A = (h) => {
9946
+ l.postMessage({ url: h }), l.close();
9947
+ };
9948
+ if (!u || typeof a.path != "string") return A();
9949
+ u.resolve(a.path, a.rejectedUrl).then(A, () => A());
9920
9950
  return;
9921
- const d = (h) => {
9922
- l.postMessage({ ok: h }), l.close();
9951
+ }
9952
+ if (a.type !== sd) return;
9953
+ const d = (u) => {
9954
+ l.postMessage({ ok: u }), l.close();
9923
9955
  };
9924
9956
  if (!this.mountSnapshots.get(a.id)?.worker) {
9925
9957
  d(!1);
@@ -9937,8 +9969,8 @@ const Re = class Re {
9937
9969
  return new URL(r, new URL(this.scope, window.location.origin)).href;
9938
9970
  }
9939
9971
  /** 单例获取(固定 scope 幂等注册并等待 SW 激活)。 */
9940
- static acquire(e, t = sd, r = Qs) {
9941
- const s = ad(r), i = `${s}::${new URL(e, window.location.href).href}`;
9972
+ static acquire(e, t = id, r = Qs) {
9973
+ const s = ld(r), i = `${s}::${new URL(e, window.location.href).href}`;
9942
9974
  let o = Re.instances.get(i);
9943
9975
  return o || (o = Re.create(e, t, s).catch((a) => {
9944
9976
  throw Re.instances.delete(i), a;
@@ -9955,14 +9987,14 @@ const Re = class Re {
9955
9987
  console.warn("Service Worker update check failed:", o);
9956
9988
  }
9957
9989
  const i = await Gr(s);
9958
- return od(), new Re(i, r, t, s, e);
9990
+ return ad(), new Re(i, r, t, s, e);
9959
9991
  }
9960
9992
  /**
9961
9993
  * 挂载一个预览实例,返回可直连的同源虚拟 URL(`<scope><id>/<entryPath>`)。
9962
9994
  * SW 在返回 HTML 时按 `injectHead` 改写 `<head>`、按 `csp` 下发响应头。
9963
9995
  */
9964
9996
  async mount(e) {
9965
- const t = dd(e);
9997
+ const t = ud(e);
9966
9998
  try {
9967
9999
  await this.sendMount(e, e.rawFiles);
9968
10000
  } catch (r) {
@@ -10001,16 +10033,16 @@ const Re = class Re {
10001
10033
  try {
10002
10034
  return await this.sendFsRequest(e, t, r);
10003
10035
  } catch (s) {
10004
- if (!ld(s, "ERR_NOT_MOUNTED") || !this.mountSnapshots.has(e))
10036
+ if (!cd(s, "ERR_NOT_MOUNTED") || !this.mountSnapshots.has(e))
10005
10037
  throw s;
10006
10038
  return await this.restoreMount(e), this.sendFsRequest(e, t, r);
10007
10039
  }
10008
10040
  }
10009
10041
  async sendFsRequest(e, t, r) {
10010
- const s = cd(), i = await this.postWithAck(
10042
+ const s = dd(), i = await this.postWithAck(
10011
10043
  { type: "FS", op: t, id: e, reqId: s, ...r },
10012
10044
  [],
10013
- id
10045
+ od
10014
10046
  );
10015
10047
  if (i.type !== "FS_ACK" || i.id !== e || i.op !== t || i.reqId !== s)
10016
10048
  throw new Error("invalid service worker file system response");
@@ -10035,8 +10067,8 @@ const Re = class Re {
10035
10067
  s(d);
10036
10068
  return;
10037
10069
  }
10038
- const h = new Error(d?.error ?? "operation failed");
10039
- d?.code && (h.code = d.code), i(h);
10070
+ const u = new Error(d?.error ?? "operation failed");
10071
+ d?.code && (u.code = d.code), i(u);
10040
10072
  }, this.sw.postMessage(e, [o.port2, ...t]);
10041
10073
  });
10042
10074
  }
@@ -10051,7 +10083,8 @@ const Re = class Re {
10051
10083
  csp: e.csp,
10052
10084
  remoteBase: e.remoteBase,
10053
10085
  fsScope: e.fsScope,
10054
- worker: e.worker
10086
+ worker: e.worker,
10087
+ offloaded: e.offloaded?.manifest.resources
10055
10088
  },
10056
10089
  r
10057
10090
  );
@@ -10099,23 +10132,23 @@ const Re = class Re {
10099
10132
  };
10100
10133
  Re.instances = /* @__PURE__ */ new Map();
10101
10134
  let Fn = Re;
10102
- function ad(n) {
10135
+ function ld(n) {
10103
10136
  const e = new URL(n || Qs, window.location.origin);
10104
10137
  if (e.origin !== window.location.origin)
10105
10138
  throw new Error("service worker scope must be same-origin");
10106
10139
  return e.pathname.endsWith("/") ? e.pathname : `${e.pathname}/`;
10107
10140
  }
10108
- function ld(n, e) {
10141
+ function cd(n, e) {
10109
10142
  return n instanceof Error && n.code === e;
10110
10143
  }
10111
- function cd() {
10144
+ function dd() {
10112
10145
  if (typeof crypto < "u" && typeof crypto.randomUUID == "function")
10113
10146
  return crypto.randomUUID().replace(/-/g, "");
10114
10147
  let n = "";
10115
10148
  for (let e = 0; e < 32; e++) n += Math.floor(Math.random() * 16).toString(16);
10116
10149
  return n;
10117
10150
  }
10118
- function dd(n) {
10151
+ function ud(n) {
10119
10152
  return {
10120
10153
  ...n,
10121
10154
  rawFiles: Ut(n.rawFiles),
@@ -10153,102 +10186,102 @@ function zs(n, e) {
10153
10186
  const t = e ?? Vt;
10154
10187
  return t.includes("/") ? null : n.includes(t) ? t : null;
10155
10188
  }
10156
- const ud = /\.(png|jpe?g|gif|svg|webp|ico|bmp|woff2?|ttf|otf|eot|mp4|m4v|webm|ogv|mov|mp3|m4a|aac|wav|flac|oga|ogg|opus)$/i, hd = /\.(?:js|mjs|cjs|jsx|ts|mts|cts|tsx)$/i, pd = {
10189
+ const hd = /\.(png|jpe?g|gif|svg|webp|ico|bmp|woff2?|ttf|otf|eot|mp4|m4v|webm|ogv|mov|mp3|m4a|aac|wav|flac|oga|ogg|opus)$/i, pd = /\.(?:js|mjs|cjs|jsx|ts|mts|cts|tsx)$/i, Ad = {
10157
10190
  maxZipBytes: 50 * 1024 * 1024,
10158
10191
  maxSingleFileBytes: 15 * 1024 * 1024,
10159
10192
  maxScriptBytes: 15 * 1024 * 1024
10160
10193
  };
10161
10194
  function js(n) {
10162
- return n === !1 ? null : { ...pd, ...n };
10195
+ return n === !1 ? null : { ...Ad, ...n };
10163
10196
  }
10164
10197
  function Kn(n) {
10165
- throw new te("PACKAGE_LIMIT_EXCEEDED", `小应用包超过安全上限:${n}`);
10198
+ throw new ne("PACKAGE_LIMIT_EXCEEDED", `小应用包超过安全上限:${n}`);
10166
10199
  }
10167
10200
  function Xn(n, e, t) {
10168
- t && (hd.test(n) && e > t.maxScriptBytes && Kn(`${n} 为 ${e} bytes,脚本上限为 ${t.maxScriptBytes} bytes`), e > t.maxSingleFileBytes && Kn(`${n} 为 ${e} bytes,单文件上限为 ${t.maxSingleFileBytes} bytes`));
10201
+ t && (pd.test(n) && e > t.maxScriptBytes && Kn(`${n} 为 ${e} bytes,脚本上限为 ${t.maxScriptBytes} bytes`), e > t.maxSingleFileBytes && Kn(`${n} 为 ${e} bytes,单文件上限为 ${t.maxSingleFileBytes} bytes`));
10169
10202
  }
10170
- function Ad(n) {
10203
+ function fd(n) {
10171
10204
  return n instanceof ArrayBuffer || n instanceof Uint8Array ? n.byteLength : n.size;
10172
10205
  }
10173
- function fd(n) {
10206
+ function gd(n) {
10174
10207
  if (n && typeof n.loadAsync == "function") return n;
10175
10208
  const e = typeof globalThis < "u" ? globalThis : void 0;
10176
10209
  if (e?.JSZip && typeof e.JSZip.loadAsync == "function") return e.JSZip;
10177
- throw new te(
10210
+ throw new ne(
10178
10211
  "ZIP_LOAD_FAILED",
10179
10212
  "JSZip 不可用:请通过 loadZip(source, { jszip }) 传入 JSZip,或在全局挂载 window.JSZip(CDN/UMD)"
10180
10213
  );
10181
10214
  }
10182
- async function gd(n, e = {}) {
10183
- const t = js(e.limits), r = Ad(n);
10215
+ async function md(n, e = {}) {
10216
+ const t = js(e.limits), r = fd(n);
10184
10217
  t && r > t.maxZipBytes && Kn(`压缩包为 ${r} bytes,压缩包上限为 ${t.maxZipBytes} bytes`);
10185
- const s = fd(e.jszip);
10218
+ const s = gd(e.jszip);
10186
10219
  let i;
10187
10220
  try {
10188
10221
  i = await s.loadAsync(n);
10189
10222
  } catch (b) {
10190
- throw new te("ZIP_LOAD_FAILED", "ZIP 解压失败", { cause: b });
10223
+ throw new ne("ZIP_LOAD_FAILED", "ZIP 解压失败", { cause: b });
10191
10224
  }
10192
10225
  const o = [];
10193
10226
  i.forEach((b, f) => {
10194
10227
  if (f.dir) return;
10195
- const y = Yt(b);
10196
- y && o.push({ path: y, entry: f });
10228
+ const w = Yt(b);
10229
+ w && o.push({ path: w, entry: f });
10197
10230
  });
10198
10231
  for (const { path: b, entry: f } of o) {
10199
- const y = f._data?.uncompressedSize;
10200
- typeof y == "number" && Xn(b, y, t);
10232
+ const w = f._data?.uncompressedSize;
10233
+ typeof w == "number" && Xn(b, w, t);
10201
10234
  }
10202
10235
  const a = e.entry ? Yt(e.entry) ?? e.entry : void 0, l = zs(
10203
10236
  o.map((b) => b.path),
10204
10237
  a
10205
10238
  );
10206
10239
  if (!l)
10207
- throw new te(
10240
+ throw new ne(
10208
10241
  "ZIP_NO_ENTRY",
10209
10242
  `入口文件「${e.entry ?? Vt}」必须位于 zip 根目录(不支持放在子目录)`
10210
10243
  );
10211
10244
  if (!new Map(o.map((b) => [b.path, b.entry])).get(l))
10212
- throw new te("ZIP_NO_ENTRY", `ZIP 包内未找到入口文件「${l}」`);
10213
- const A = {}, u = [];
10245
+ throw new ne("ZIP_NO_ENTRY", `ZIP 包内未找到入口文件「${l}」`);
10246
+ const A = {}, h = [];
10214
10247
  for (const { path: b, entry: f } of o) {
10215
- const y = await f.async("arraybuffer");
10216
- Xn(b, y.byteLength, t), u.push({ path: b, size: y.byteLength }), A[b] = y;
10248
+ const w = await f.async("arraybuffer");
10249
+ Xn(b, w.byteLength, t), h.push({ path: b, size: w.byteLength }), A[b] = w;
10217
10250
  }
10218
10251
  const m = A[l];
10219
10252
  if (!m)
10220
- throw new te("ZIP_NO_ENTRY", `ZIP 包内未找到入口文件「${l}」`);
10221
- const w = new TextDecoder("utf-8").decode(new Uint8Array(m));
10253
+ throw new ne("ZIP_NO_ENTRY", `ZIP 包内未找到入口文件「${l}」`);
10254
+ const v = new TextDecoder("utf-8").decode(new Uint8Array(m));
10222
10255
  return {
10223
10256
  entryPath: l,
10224
- entryHtml: w,
10257
+ entryHtml: v,
10225
10258
  rawFiles: A,
10226
- files: u
10259
+ files: h
10227
10260
  };
10228
10261
  }
10229
- function md(n, e = {}) {
10230
- const t = bd(n), r = js(e.limits), s = e.entry ? Yt(e.entry) ?? e.entry : void 0, i = zs([...t.keys()], s);
10262
+ function bd(n, e = {}) {
10263
+ const t = yd(n), r = js(e.limits), s = e.entry ? Yt(e.entry) ?? e.entry : void 0, i = zs([...t.keys()], s);
10231
10264
  if (!i)
10232
- throw new te(
10265
+ throw new ne(
10233
10266
  "FILES_NO_ENTRY",
10234
10267
  `入口文件「${e.entry ?? Vt}」必须位于文件表根目录(不支持放在子目录)`
10235
10268
  );
10236
10269
  const o = t.get(i);
10237
10270
  if (o === void 0)
10238
- throw new te("FILES_NO_ENTRY", `文件表中未找到入口文件「${i}」`);
10271
+ throw new ne("FILES_NO_ENTRY", `文件表中未找到入口文件「${i}」`);
10239
10272
  const a = {}, l = [];
10240
- for (const [d, h] of t) {
10241
- const A = wd(d, h);
10273
+ for (const [d, u] of t) {
10274
+ const A = Cd(d, u);
10242
10275
  Xn(d, A.byteLength, r), l.push({ path: d, size: A.byteLength }), a[d] = A;
10243
10276
  }
10244
10277
  return {
10245
10278
  entryPath: i,
10246
- entryHtml: yd(o),
10279
+ entryHtml: vd(o),
10247
10280
  rawFiles: a,
10248
10281
  files: l
10249
10282
  };
10250
10283
  }
10251
- function bd(n) {
10284
+ function yd(n) {
10252
10285
  const e = /* @__PURE__ */ new Map();
10253
10286
  for (const [t, r] of Object.entries(n)) {
10254
10287
  const s = Yt(t);
@@ -10259,15 +10292,15 @@ function bd(n) {
10259
10292
  function Js(n) {
10260
10293
  return n instanceof Uint8Array ? n : new Uint8Array(n);
10261
10294
  }
10262
- function yd(n) {
10295
+ function vd(n) {
10263
10296
  return typeof n == "string" ? n : new TextDecoder("utf-8").decode(Js(n));
10264
10297
  }
10265
- function vd(n) {
10298
+ function wd(n) {
10266
10299
  return n.byteOffset === 0 && n.byteLength === n.buffer.byteLength ? n.buffer : n.slice().buffer;
10267
10300
  }
10268
- function wd(n, e) {
10269
- if (typeof e != "string") return vd(Js(e));
10270
- if (ud.test(n)) {
10301
+ function Cd(n, e) {
10302
+ if (typeof e != "string") return wd(Js(e));
10303
+ if (hd.test(n)) {
10271
10304
  if (e.startsWith("data:")) {
10272
10305
  const r = e.indexOf(","), s = e.slice(0, r), i = e.slice(r + 1);
10273
10306
  return /;base64/i.test(s) ? Hr(i) : new TextEncoder().encode(decodeURIComponent(i)).buffer;
@@ -10283,7 +10316,7 @@ function Hr(n) {
10283
10316
  return t.buffer;
10284
10317
  }
10285
10318
  async function yn(n, e, t, r, s, i, o, a, l, d) {
10286
- const h = Oo(), u = await Vi(e, {
10319
+ const u = Oo(), h = await Vi(e, {
10287
10320
  workerGuard: d,
10288
10321
  rendererType: "iframe",
10289
10322
  options: n,
@@ -10292,7 +10325,7 @@ async function yn(n, e, t, r, s, i, o, a, l, d) {
10292
10325
  gateways: a,
10293
10326
  businessLine: l,
10294
10327
  rawHtml: r,
10295
- scriptNonce: h,
10328
+ scriptNonce: u,
10296
10329
  cspAsHeader: !0
10297
10330
  }), m = fs({
10298
10331
  workerEnabled: d?.enabled,
@@ -10300,11 +10333,11 @@ async function yn(n, e, t, r, s, i, o, a, l, d) {
10300
10333
  appUrl: t,
10301
10334
  extraOrigins: s,
10302
10335
  frameAncestors: i,
10303
- scriptNonce: h
10336
+ scriptNonce: u
10304
10337
  });
10305
- return { head: u, csp: m };
10338
+ return { head: h, csp: m };
10306
10339
  }
10307
- class Cd extends il {
10340
+ class Sd extends il {
10308
10341
  async load(e) {
10309
10342
  try {
10310
10343
  await this.ctx.rendererContext.restoreServiceWorkerMount?.(e);
@@ -10332,21 +10365,21 @@ const le = {
10332
10365
  livePhoto: "实况",
10333
10366
  saveDraft: "存草稿",
10334
10367
  publish: "发布笔记"
10335
- }, ue = "https://fe-platform.xhscdn.com/platform", ce = {
10336
- navBar: `${ue}/104101l0323g0lkiknu0m277180ac7t8006ptl0akiev06.png`,
10337
- statusLevels: `${ue}/104101l0323g0lkih7a06277180ac7t8006ptl0b0qgdka.png`,
10338
- homeIndicator: `${ue}/104101l0323g0lkipga06277180ac7t8006ptl0dehcmn4.png`,
10339
- voice: `${ue}/104101l0323g0lki10206277180ac7t8006ptl0br01bmu.png`,
10340
- location: `${ue}/104101l0323g0lkiknk0m277180ac7t8006ptl0e7n5ldm.png`,
10341
- visibility: `${ue}/104101l0323g0lkiknk06277180ac7t8006ptl0e1f6908.png`,
10342
- addComponent: `${ue}/104101l0323g0lki07k06277180ac7t8006ptl0ck0o7v8.png`,
10343
- setting: `${ue}/104101l0323g0lki07u06277180ac7t8006ptl09f764ic.png`,
10344
- chevron: `${ue}/104101l0323g0lkij7a06277180ac7t8006ptl0aholfs6.png`,
10345
- topic: `${ue}/104101l0323g0lkiqna06277180ac7t8006ptl0ckpb7vo.png`,
10346
- mention: `${ue}/104101l0323g0lki1nu76277180ac7t8006ptl0e2eecng.png`,
10347
- vote: `${ue}/104101l0323g0lki07k0m277180ac7t8006ptl0bpvoc3i.png`,
10348
- videoBadge: `${ue}/104101l0323g0ofcn0206277180ac7t8006ptl0ctk6mds.png`
10349
- }, Sd = {
10368
+ }, he = "https://fe-platform.xhscdn.com/platform", ce = {
10369
+ navBar: `${he}/104101l0323g0lkiknu0m277180ac7t8006ptl0akiev06.png`,
10370
+ statusLevels: `${he}/104101l0323g0lkih7a06277180ac7t8006ptl0b0qgdka.png`,
10371
+ homeIndicator: `${he}/104101l0323g0lkipga06277180ac7t8006ptl0dehcmn4.png`,
10372
+ voice: `${he}/104101l0323g0lki10206277180ac7t8006ptl0br01bmu.png`,
10373
+ location: `${he}/104101l0323g0lkiknk0m277180ac7t8006ptl0e7n5ldm.png`,
10374
+ visibility: `${he}/104101l0323g0lkiknk06277180ac7t8006ptl0e1f6908.png`,
10375
+ addComponent: `${he}/104101l0323g0lki07k06277180ac7t8006ptl0ck0o7v8.png`,
10376
+ setting: `${he}/104101l0323g0lki07u06277180ac7t8006ptl09f764ic.png`,
10377
+ chevron: `${he}/104101l0323g0lkij7a06277180ac7t8006ptl0aholfs6.png`,
10378
+ topic: `${he}/104101l0323g0lkiqna06277180ac7t8006ptl0ckpb7vo.png`,
10379
+ mention: `${he}/104101l0323g0lki1nu76277180ac7t8006ptl0e2eecng.png`,
10380
+ vote: `${he}/104101l0323g0lki07k0m277180ac7t8006ptl0bpvoc3i.png`,
10381
+ videoBadge: `${he}/104101l0323g0ofcn0206277180ac7t8006ptl0ctk6mds.png`
10382
+ }, Ed = {
10350
10383
  red: "#FF2442",
10351
10384
  title: "rgba(0, 0, 0, 0.8)",
10352
10385
  placeholder: "rgba(0, 0, 0, 0.27)",
@@ -10356,7 +10389,7 @@ const le = {
10356
10389
  chooseCoverBg: "rgba(0, 0, 0, 0.65)",
10357
10390
  chooseCoverBorder: "rgba(255, 255, 255, 0.3)"
10358
10391
  }, Pn = "miniapp-note-publish";
10359
- class Ed extends HTMLElement {
10392
+ class xd extends HTMLElement {
10360
10393
  constructor() {
10361
10394
  super(...arguments), this._panelEl = null, this._resolve = null;
10362
10395
  }
@@ -10387,11 +10420,11 @@ class Ed extends HTMLElement {
10387
10420
  const t = this.shadowRoot?.querySelector(".scroll");
10388
10421
  if (!t) return;
10389
10422
  const r = e.title ? `<div class="title title--filled">${vn(e.title)}</div>` : `<div class="title">${le.titlePlaceholder}</div>`, s = e.content ? `<div class="content content--filled">${vn(e.content)}</div>` : `<div class="content"><span>${le.contentPlaceholder}</span><img class="voice" src="${ce.voice}" alt=""></div>`, i = e.tags.length ? `<div class="tags">${e.tags.map((o) => `<span class="tag">#${vn(o)}</span>`).join("")}</div>` : "";
10390
- t.innerHTML = xd(e.media) + r + s + i;
10423
+ t.innerHTML = kd(e.media) + r + s + i;
10391
10424
  }
10392
10425
  render() {
10393
10426
  if (!this.shadowRoot) return;
10394
- const e = Sd;
10427
+ const e = Ed;
10395
10428
  this.shadowRoot.innerHTML = `
10396
10429
  <style>
10397
10430
  :host {
@@ -10568,10 +10601,10 @@ class Ed extends HTMLElement {
10568
10601
  function Nt(n, e) {
10569
10602
  return `<div class="row"><img class="ricon" src="${n}" alt=""><span class="label">${e}</span><img class="chevron" src="${ce.chevron}" alt=""></div>`;
10570
10603
  }
10571
- function xd(n) {
10572
- return n.length ? n.length === 1 && n[0].type !== "image" ? `<div class="media">${kd(n[0])}</div>` : `<div class="media">${n.map((t) => t.type === "image" ? `<div class="cell"><img src="${t.url}" alt=""></div>` : t.type === "live_photo" ? `<div class="cell"><img src="${t.cover}" alt=""><span class="badge">${le.livePhoto}</span></div>` : `<div class="cell">${t.cover ? `<img src="${t.cover}" alt="">` : `<video src="${t.url}" muted playsinline></video>`}<span class="badge"><img src="${ce.videoBadge}" alt=""></span></div>`).join("")}</div>` : "";
10573
- }
10574
10604
  function kd(n) {
10605
+ return n.length ? n.length === 1 && n[0].type !== "image" ? `<div class="media">${Vd(n[0])}</div>` : `<div class="media">${n.map((t) => t.type === "image" ? `<div class="cell"><img src="${t.url}" alt=""></div>` : t.type === "live_photo" ? `<div class="cell"><img src="${t.cover}" alt=""><span class="badge">${le.livePhoto}</span></div>` : `<div class="cell">${t.cover ? `<img src="${t.cover}" alt="">` : `<video src="${t.url}" muted playsinline></video>`}<span class="badge"><img src="${ce.videoBadge}" alt=""></span></div>`).join("")}</div>` : "";
10606
+ }
10607
+ function Vd(n) {
10575
10608
  if (n.type === "image") return "";
10576
10609
  const e = n.type === "live_photo" ? `<span class="badge">${le.livePhoto}</span>` : `<span class="badge"><img src="${ce.videoBadge}" alt=""></span>`;
10577
10610
  return `<div class="cover">${n.type === "live_photo" ? `<img src="${n.cover}" alt="">` : n.cover ? `<img src="${n.cover}" alt="">` : `<video src="${n.url}" muted playsinline></video>`}${e}<span class="choose-cover">${le.chooseCover}</span></div>`;
@@ -10581,14 +10614,14 @@ function vn(n) {
10581
10614
  }
10582
10615
  let Qr = !1;
10583
10616
  function _s() {
10584
- Qr || typeof customElements > "u" || (customElements.get(Pn) || customElements.define(Pn, Ed), Qr = !0);
10617
+ Qr || typeof customElements > "u" || (customElements.get(Pn) || customElements.define(Pn, xd), Qr = !0);
10585
10618
  }
10586
- function Vd() {
10619
+ function Ld() {
10587
10620
  return _s(), document.createElement(Pn);
10588
10621
  }
10589
10622
  class Id {
10590
10623
  constructor(e, t = {}) {
10591
- this.mountEl = e, this.options = t, this.page = Vd(), this.mounted = !1, _s();
10624
+ this.mountEl = e, this.options = t, this.page = Ld(), this.mounted = !1, _s();
10592
10625
  }
10593
10626
  mount() {
10594
10627
  this.mounted || (this.mountEl.appendChild(this.page), this.mounted = !0);
@@ -10605,7 +10638,7 @@ class Id {
10605
10638
  this.hide(), this.page.remove(), this.mounted = !1;
10606
10639
  }
10607
10640
  }
10608
- const Ld = {
10641
+ const Wd = {
10609
10642
  album: {
10610
10643
  kind: "album",
10611
10644
  title: "你的相册照片与视频",
@@ -10621,16 +10654,16 @@ const Ld = {
10621
10654
  title: "设备麦克风",
10622
10655
  description: "用于录制音频,供小工具实时识别或处理"
10623
10656
  }
10624
- }, Wd = [
10657
+ }, qd = [
10625
10658
  "album",
10626
10659
  "camera",
10627
10660
  "microphone"
10628
- ], qd = "小工具申请使用以下权限", Bd = "取消", Td = "同意授权";
10629
- function Rd(n) {
10630
- return n.map((e) => Ld[e]);
10661
+ ], Bd = "小工具申请使用以下权限", Td = "取消", Rd = "同意授权";
10662
+ function Fd(n) {
10663
+ return n.map((e) => Wd[e]);
10631
10664
  }
10632
10665
  const Mn = "miniapp-permission-sheet";
10633
- class Fd extends HTMLElement {
10666
+ class Kd extends HTMLElement {
10634
10667
  constructor() {
10635
10668
  super(...arguments), this._backdropEl = null, this._panelEl = null, this._listEl = null, this._resolve = null;
10636
10669
  }
@@ -10803,11 +10836,11 @@ class Fd extends HTMLElement {
10803
10836
  </style>
10804
10837
  <div class="backdrop" part="backdrop"></div>
10805
10838
  <div class="panel" part="panel">
10806
- <h2 class="title">${At(qd)}</h2>
10839
+ <h2 class="title">${At(Bd)}</h2>
10807
10840
  <ul class="list"></ul>
10808
10841
  <div class="actions">
10809
- <button type="button" class="btn btn-cancel">${At(Bd)}</button>
10810
- <button type="button" class="btn btn-grant">${At(Td)}</button>
10842
+ <button type="button" class="btn btn-cancel">${At(Td)}</button>
10843
+ <button type="button" class="btn btn-grant">${At(Rd)}</button>
10811
10844
  </div>
10812
10845
  </div>
10813
10846
  `, this._backdropEl = this.shadowRoot.querySelector(".backdrop"), this._panelEl = this.shadowRoot.querySelector(".panel"), this._listEl = this.shadowRoot.querySelector(".list"), this.shadowRoot.querySelector(".btn-cancel")?.addEventListener("click", () => {
@@ -10824,22 +10857,22 @@ function At(n) {
10824
10857
  }
10825
10858
  let zr = !1;
10826
10859
  function $s() {
10827
- zr || typeof customElements > "u" || (customElements.get(Mn) || customElements.define(Mn, Fd), zr = !0);
10860
+ zr || typeof customElements > "u" || (customElements.get(Mn) || customElements.define(Mn, Kd), zr = !0);
10828
10861
  }
10829
- function Kd() {
10862
+ function Xd() {
10830
10863
  return $s(), document.createElement(Mn);
10831
10864
  }
10832
- class Xd {
10865
+ class Pd {
10833
10866
  constructor(e, t = {}) {
10834
- this.mountEl = e, this.options = t, this.sheet = Kd(), this.mounted = !1, $s();
10867
+ this.mountEl = e, this.options = t, this.sheet = Xd(), this.mounted = !1, $s();
10835
10868
  }
10836
10869
  mount() {
10837
10870
  this.mounted || (this.mountEl.appendChild(this.sheet), this.mounted = !0);
10838
10871
  }
10839
10872
  show(e = {}) {
10840
10873
  this.mount();
10841
- const t = e.kinds ?? [...Wd];
10842
- return this.options.onOpenChange?.(!0), this.sheet.present(Rd(t)).finally(() => {
10874
+ const t = e.kinds ?? [...qd];
10875
+ return this.options.onOpenChange?.(!0), this.sheet.present(Fd(t)).finally(() => {
10843
10876
  this.options.onOpenChange?.(!1);
10844
10877
  });
10845
10878
  }
@@ -10850,7 +10883,7 @@ class Xd {
10850
10883
  this.hide(), this.sheet.remove(), this.mounted = !1;
10851
10884
  }
10852
10885
  }
10853
- class Pd extends Is {
10886
+ class Md extends Ls {
10854
10887
  constructor(e) {
10855
10888
  super(), this.frame = null, this.overlay = null, this.container = null, this.contentRoot = null, this.rednoteShell = null, this.contentHost = null, this.currentUrl = "", this.bridge = null, this.permissionSheetHost = null, this.notePublishHost = null, this.frameToastHost = null, this.detachFramelessShellWindowSync = null, this.detachContentPcGuard = null, this.forwardEmit = (t, r) => {
10856
10889
  this.emit(t, r);
@@ -10893,7 +10926,7 @@ class Pd extends Is {
10893
10926
  };
10894
10927
  this.contentHost = this.createContentHost(s), r.appendChild(this.contentHost.element), this.contentHost.afterAttached();
10895
10928
  }
10896
- this.permissionSheetHost = new Xd(this.contentRoot, {
10929
+ this.permissionSheetHost = new Pd(this.contentRoot, {
10897
10930
  onOpenChange: (s) => {
10898
10931
  this.contentHost?.setGestureOverlayInteractionEnabled?.(!s);
10899
10932
  }
@@ -11016,9 +11049,9 @@ class Pd extends Is {
11016
11049
  this.viewport = e;
11017
11050
  const t = this.context.phoneFrame;
11018
11051
  if (this.chromeless && !t)
11019
- In(this.container), Ln(this.contentRoot), this.container.style.position = "relative", this.container.style.width = `${e.width}px`, this.container.style.height = `${e.height}px`, this.contentRoot.style.width = `${e.width}px`, this.contentRoot.style.height = `${e.height}px`, this.contentRoot.style.borderRadius = "", this.contentRoot.style.transform = "", this.contentRoot.style.transformOrigin = "";
11052
+ Ln(this.container), In(this.contentRoot), this.container.style.position = "relative", this.container.style.width = `${e.width}px`, this.container.style.height = `${e.height}px`, this.contentRoot.style.width = `${e.width}px`, this.contentRoot.style.height = `${e.height}px`, this.contentRoot.style.borderRadius = "", this.contentRoot.style.transform = "", this.contentRoot.style.transformOrigin = "";
11020
11053
  else if (t) {
11021
- In(this.container), Ln(this.contentRoot), this.container.style.position = "relative", this.container.style.width = `${t.width}px`, this.container.style.height = `${t.height}px`, this.frame && (this.frame.style.left = `${t.screen.x}px`, this.frame.style.top = `${t.screen.y}px`, this.frame.style.width = `${t.screen.width}px`, this.frame.style.height = `${t.screen.height}px`);
11054
+ Ln(this.container), In(this.contentRoot), this.container.style.position = "relative", this.container.style.width = `${t.width}px`, this.container.style.height = `${t.height}px`, this.frame && (this.frame.style.left = `${t.screen.x}px`, this.frame.style.top = `${t.screen.y}px`, this.frame.style.width = `${t.screen.width}px`, this.frame.style.height = `${t.screen.height}px`);
11022
11055
  const r = t.screen.width / e.width, s = t.screen.height / e.height;
11023
11056
  this.contentRoot.style.width = `${e.width}px`, this.contentRoot.style.height = `${e.height}px`, this.contentRoot.style.transformOrigin = "top left", this.contentRoot.style.transform = `scale(${r}, ${s})`;
11024
11057
  } else {
@@ -11068,27 +11101,27 @@ class Pd extends Is {
11068
11101
  return t ? (this.frame = document.createElement("div"), this.frame.style.position = "absolute", this.frame.style.overflow = "hidden", this.frame.style.borderRadius = `${t.screen.cornerRadius ?? 42}px`, this.frame.style.background = "#fff", e.appendChild(this.frame), this.overlay = document.createElement("div"), this.overlay.style.position = "absolute", this.overlay.style.inset = "0", this.overlay.style.backgroundImage = `url("${t.imageUrl}")`, this.overlay.style.backgroundRepeat = "no-repeat", this.overlay.style.backgroundSize = "100% 100%", this.overlay.style.pointerEvents = "none", this.overlay.style.zIndex = "1", e.appendChild(this.overlay), this.frame) : e;
11069
11102
  }
11070
11103
  }
11071
- class Md extends Pd {
11104
+ class Nd extends Md {
11072
11105
  createContentHost(e) {
11073
- return new Cd(e);
11106
+ return new Sd(e);
11074
11107
  }
11075
11108
  }
11076
- function Nd(n) {
11109
+ function Od(n) {
11077
11110
  return new Promise((e, t) => {
11078
11111
  const r = new FileReader();
11079
11112
  r.onload = () => e(String(r.result)), r.onerror = () => t(r.error ?? new Error("failed to read captured blob")), r.readAsDataURL(n);
11080
11113
  });
11081
11114
  }
11082
- function Od(n) {
11115
+ function Zd(n) {
11083
11116
  return new Promise((e) => {
11084
11117
  const t = new Image();
11085
11118
  t.onload = () => e({ width: t.width, height: t.height }), t.onerror = () => e(null), t.src = n;
11086
11119
  });
11087
11120
  }
11088
- async function Zd(n, e) {
11121
+ async function Dd(n, e) {
11089
11122
  try {
11090
- const t = await Nd(n);
11091
- return await Dd(t, e);
11123
+ const t = await Od(n);
11124
+ return await Ud(t, e);
11092
11125
  } catch (t) {
11093
11126
  return {
11094
11127
  success: !1,
@@ -11097,8 +11130,8 @@ async function Zd(n, e) {
11097
11130
  };
11098
11131
  }
11099
11132
  }
11100
- async function Dd(n, e) {
11101
- const t = await Od(n);
11133
+ async function Ud(n, e) {
11134
+ const t = await Zd(n);
11102
11135
  return t ? {
11103
11136
  success: !0,
11104
11137
  base64: n,
@@ -11111,8 +11144,8 @@ async function Dd(n, e) {
11111
11144
  reason: "截图内容解码失败,无法生成图片"
11112
11145
  };
11113
11146
  }
11114
- const Ud = '<svg width="12" height="12" viewBox="0 0 12 12" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1 6h10M1 6l2.5-2.5M1 6l2.5 2.5M11 6l-2.5-2.5M11 6l-2.5 2.5" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"/></svg>', Yd = `<span style="display:inline-flex;align-items:center;justify-content:center;transform:rotate(-45deg);transform-origin:center">${Ud}</span>`;
11115
- function Gd(n) {
11147
+ const Yd = '<svg width="12" height="12" viewBox="0 0 12 12" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1 6h10M1 6l2.5-2.5M1 6l2.5 2.5M11 6l-2.5-2.5M11 6l-2.5 2.5" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"/></svg>', Gd = `<span style="display:inline-flex;align-items:center;justify-content:center;transform:rotate(-45deg);transform-origin:center">${Yd}</span>`;
11148
+ function Hd(n) {
11116
11149
  n.className = "miniapp-simulator-resize-handle", Object.assign(n.style, {
11117
11150
  position: "absolute",
11118
11151
  width: "22px",
@@ -11133,10 +11166,10 @@ function Gd(n) {
11133
11166
  transition: "background 0.15s"
11134
11167
  });
11135
11168
  }
11136
- function Hd(n, e) {
11137
- const t = e.bounds;
11138
- let r = e.scaleMultiplier;
11139
- const s = {
11169
+ function Qd(n, e, t) {
11170
+ const r = e.bounds;
11171
+ let s = e.scaleMultiplier;
11172
+ const i = {
11140
11173
  position: n.style.position,
11141
11174
  left: n.style.left,
11142
11175
  top: n.style.top,
@@ -11144,42 +11177,50 @@ function Hd(n, e) {
11144
11177
  transformOrigin: n.style.transformOrigin
11145
11178
  };
11146
11179
  getComputedStyle(n).position === "static" && (n.style.position = "absolute"), n.style.left = "50%", e.centerInBounds ? (n.style.top = "50%", n.style.transformOrigin = "center center") : (n.style.top = `${e.contentTop}px`, n.style.transformOrigin = "top center");
11147
- const o = e.resizeHandle ? document.createElement("div") : null;
11148
- o && (Gd(o), o.innerHTML = Yd, o.title = "左右拖拽调整大小", t.appendChild(o));
11149
- let a = !1, l = 0, d = r;
11150
- const h = (y, x, q, k, S, R, V) => {
11151
- if (!o) return;
11152
- const Z = 22, Y = 4, Q = y / 2 + q * S / 2, $ = R ? x / 2 - k * S / 2 + e.handleTop : e.handleTop + (V ? e.padding.top : 0), X = Math.min(Q - Y - Z, y - Z - 4);
11153
- o.style.left = `${Math.max(0, X)}px`, o.style.top = `${Math.max(0, $)}px`;
11154
- }, A = () => {
11155
- const y = n.offsetWidth, x = n.offsetHeight;
11156
- if (!y || !x) return;
11157
- const { top: q, right: k, bottom: S, left: R } = e.padding, V = t.dataset.miniAppStageAlign === "top", Z = e.centerInBounds && !V, Y = Math.max(0, t.clientWidth - R - k), Q = Math.max(0, t.clientHeight - q - S);
11158
- if (Y === 0 || Q === 0) return;
11159
- const $ = Math.min(Y / y, Q / x);
11160
- let X = $ * r;
11161
- e.capToBounds && (X = Math.min(X, $)), X = Math.min(X, e.maxScale), X = Math.max(X, e.minScale), n.style.position = "absolute", n.style.left = "50%", n.style.top = Z ? "50%" : `${V ? q : e.contentTop}px`, n.style.transformOrigin = Z ? "center center" : "top center", n.style.transform = Z ? `translate(-50%, -50%) scale(${X})` : `translateX(-50%) scale(${X})`, h(t.clientWidth, t.clientHeight, y, x, X, Z, V);
11162
- }, u = () => {
11163
- A();
11164
- }, m = new ResizeObserver(u);
11165
- m.observe(n), m.observe(t), window.addEventListener("resize", u);
11166
- const w = (y) => {
11180
+ const a = e.resizeHandle ? document.createElement("div") : null;
11181
+ a && (Hd(a), a.innerHTML = Gd, a.title = "左右拖拽调整大小", r.appendChild(a));
11182
+ let l = !1, d = 0, u = s;
11183
+ const A = (S, L, V, B, E, k, N) => {
11167
11184
  if (!a) return;
11168
- const x = y.clientX - l;
11169
- r = Math.min(
11185
+ const Z = 22, G = 4, $ = S / 2 + V * E / 2, D = k ? L / 2 - B * E / 2 + e.handleTop : e.handleTop + (N ? e.padding.top : 0), I = Math.min($ - G - Z, S - Z - 4);
11186
+ a.style.left = `${Math.max(0, I)}px`, a.style.top = `${Math.max(0, D)}px`;
11187
+ }, h = () => {
11188
+ const S = n.offsetWidth, L = n.offsetHeight;
11189
+ if (!S || !L) return;
11190
+ const { top: V, right: B, bottom: E, left: k } = e.padding, N = r.dataset.miniAppStageAlign === "top", Z = e.centerInBounds && !N, G = Math.max(0, r.clientWidth - k - B), $ = Math.max(0, r.clientHeight - V - E);
11191
+ if (G === 0 || $ === 0) return;
11192
+ let D = Math.min(G / S, $ / L);
11193
+ if (t) {
11194
+ const P = t.getQuarterTurnBounds(r);
11195
+ D = Math.min(
11196
+ D,
11197
+ (P.width - k - B) / L,
11198
+ (P.height - V - E) / S
11199
+ );
11200
+ }
11201
+ let I = D * s;
11202
+ e.capToBounds && (I = Math.min(I, D)), I = Math.min(I, e.maxScale), I = Math.max(I, e.minScale), n.style.position = "absolute", n.style.left = "50%", n.style.top = Z ? "50%" : `${N ? V : e.contentTop}px`, n.style.transformOrigin = Z ? "center center" : "top center", n.style.transform = Z ? `translate(-50%, -50%) scale(${I})` : `translateX(-50%) scale(${I})`, A(r.clientWidth, r.clientHeight, S, L, I, Z, N);
11203
+ }, m = () => {
11204
+ h();
11205
+ }, v = new ResizeObserver(m);
11206
+ v.observe(n), v.observe(r), t && v.observe(t.host), window.addEventListener("resize", m);
11207
+ const b = (S) => {
11208
+ if (!l) return;
11209
+ const L = S.clientX - d;
11210
+ s = Math.min(
11170
11211
  e.maxScaleMultiplier,
11171
- Math.max(e.minScaleMultiplier, d + x * e.dragSensitivity)
11172
- ), A();
11173
- }, b = () => {
11174
- a && (a = !1, o && (o.style.background = "rgba(0, 0, 0, 0.32)"));
11175
- }, f = (y) => {
11176
- !o || y.button !== 0 || (a = !0, l = y.clientX, d = r, o.style.background = "rgba(0, 0, 0, 0.72)", y.preventDefault(), y.stopPropagation());
11212
+ Math.max(e.minScaleMultiplier, u + L * e.dragSensitivity)
11213
+ ), h();
11214
+ }, f = () => {
11215
+ l && (l = !1, a && (a.style.background = "rgba(0, 0, 0, 0.32)"));
11216
+ }, w = (S) => {
11217
+ !a || S.button !== 0 || (l = !0, d = S.clientX, u = s, a.style.background = "rgba(0, 0, 0, 0.72)", S.preventDefault(), S.stopPropagation());
11177
11218
  };
11178
- return o && (o.addEventListener("mousedown", f), window.addEventListener("mousemove", w, !0), window.addEventListener("mouseup", b, !0)), requestAnimationFrame(A), () => {
11179
- m.disconnect(), window.removeEventListener("resize", u), window.removeEventListener("mousemove", w, !0), window.removeEventListener("mouseup", b, !0), o && (o.removeEventListener("mousedown", f), o.remove()), n.style.position = s.position, n.style.left = s.left, n.style.top = s.top, n.style.transform = s.transform, n.style.transformOrigin = s.transformOrigin;
11219
+ return a && (a.addEventListener("mousedown", w), window.addEventListener("mousemove", b, !0), window.addEventListener("mouseup", f, !0)), requestAnimationFrame(h), () => {
11220
+ v.disconnect(), window.removeEventListener("resize", m), window.removeEventListener("mousemove", b, !0), window.removeEventListener("mouseup", f, !0), a && (a.removeEventListener("mousedown", w), a.remove()), n.style.position = i.position, n.style.left = i.left, n.style.top = i.top, n.style.transform = i.transform, n.style.transformOrigin = i.transformOrigin;
11180
11221
  };
11181
11222
  }
11182
- function Qd(n, e) {
11223
+ function zd(n, e) {
11183
11224
  if (n?.enabled === !0)
11184
11225
  return {
11185
11226
  protocolVersion: hi,
@@ -11187,7 +11228,7 @@ function Qd(n, e) {
11187
11228
  enabled: !0
11188
11229
  };
11189
11230
  }
11190
- function zd(n) {
11231
+ function jd(n) {
11191
11232
  const { hostApiMap: e, getRenderer: t } = n;
11192
11233
  return {
11193
11234
  set: (r, s) => {
@@ -11208,7 +11249,7 @@ function zd(n) {
11208
11249
  }
11209
11250
  };
11210
11251
  }
11211
- function jd(n) {
11252
+ function Jd(n) {
11212
11253
  const { gesturePlugins: e, getRenderer: t } = n;
11213
11254
  return {
11214
11255
  dispatch: (r) => {
@@ -11229,7 +11270,7 @@ function jd(n) {
11229
11270
  }
11230
11271
  };
11231
11272
  }
11232
- function Jd(n) {
11273
+ function _d(n) {
11233
11274
  const e = (t, r) => {
11234
11275
  const s = n.getRenderer();
11235
11276
  return s?.invokeGamePlaytest ? s.invokeGamePlaytest(t, r) : Promise.reject(new Error("Current renderer does not support game playtest"));
@@ -11243,7 +11284,7 @@ function Jd(n) {
11243
11284
  isAvailable: async () => await e("isAvailable") === !0
11244
11285
  };
11245
11286
  }
11246
- function _d(n) {
11287
+ function $d(n) {
11247
11288
  const { getRenderer: e, isEnabled: t, setEnabled: r, getSelectionMode: s, setSelectionMode: i, emitChange: o } = n, a = {
11248
11289
  enable() {
11249
11290
  t() || (r(!0), e()?.enableInspector?.(), o(!0));
@@ -11269,7 +11310,7 @@ function _d(n) {
11269
11310
  };
11270
11311
  return a;
11271
11312
  }
11272
- function $d(n) {
11313
+ function eu(n) {
11273
11314
  const { getRenderer: e } = n;
11274
11315
  return {
11275
11316
  show: async (t) => {
@@ -11284,7 +11325,7 @@ function $d(n) {
11284
11325
  }
11285
11326
  };
11286
11327
  }
11287
- function eu(n) {
11328
+ function tu(n) {
11288
11329
  const { getOptions: e, setOptions: t, syncRednote: r } = n, s = (i) => {
11289
11330
  const o = e();
11290
11331
  t({
@@ -11307,7 +11348,7 @@ function eu(n) {
11307
11348
  }
11308
11349
  };
11309
11350
  }
11310
- function tu(n) {
11351
+ function nu(n) {
11311
11352
  const { getOptions: e, setOptions: t, syncWidgetCover: r } = n;
11312
11353
  return {
11313
11354
  update: (i) => {
@@ -11319,14 +11360,14 @@ function tu(n) {
11319
11360
  }
11320
11361
  };
11321
11362
  }
11322
- const nu = {
11363
+ const ru = {
11323
11364
  idle: ["loading", "destroyed"],
11324
11365
  loading: ["ready", "error", "destroyed"],
11325
11366
  ready: ["loading", "destroyed"],
11326
11367
  error: ["loading", "destroyed"],
11327
11368
  destroyed: []
11328
11369
  };
11329
- class ru {
11370
+ class su {
11330
11371
  constructor() {
11331
11372
  this.current = "idle";
11332
11373
  }
@@ -11335,8 +11376,8 @@ class ru {
11335
11376
  }
11336
11377
  transitionTo(e) {
11337
11378
  if (this.current !== e) {
11338
- if (!nu[this.current].includes(e))
11339
- throw new te(
11379
+ if (!ru[this.current].includes(e))
11380
+ throw new ne(
11340
11381
  this.current === "destroyed" ? "DESTROYED" : "RENDERER_ERROR",
11341
11382
  `Invalid simulator state transition: ${this.current} -> ${e}`
11342
11383
  );
@@ -11345,22 +11386,22 @@ class ru {
11345
11386
  }
11346
11387
  assertActive() {
11347
11388
  if (this.current === "destroyed")
11348
- throw new te("DESTROYED", "Mini app simulator has been destroyed");
11389
+ throw new ne("DESTROYED", "Mini app simulator has been destroyed");
11349
11390
  }
11350
11391
  }
11351
11392
  const jr = {
11352
11393
  maxHeapUsedBytes: 1 * 1024 * 1024 * 1024,
11353
11394
  heapSampleIntervalMs: 1e3
11354
- }, su = { width: 390, height: 844 }, Jr = {
11395
+ }, iu = { width: 390, height: 844 }, Jr = {
11355
11396
  "iphone-15-pro": { width: 390, height: 844 },
11356
11397
  "iphone-15-pro-max": { width: 430, height: 932 },
11357
11398
  "ipad-pro": { width: 768, height: 1024 },
11358
11399
  pc: { width: 1280, height: 720 }
11359
11400
  };
11360
- function iu(n, e) {
11361
- return e || (n && Jr[n] ? Jr[n] : su);
11401
+ function ou(n, e) {
11402
+ return e || (n && Jr[n] ? Jr[n] : iu);
11362
11403
  }
11363
- const ou = {
11404
+ const au = {
11364
11405
  "iphone-14-pro-max": {
11365
11406
  id: "iphone-14-pro-max",
11366
11407
  name: "iPhone 14 Pro Max",
@@ -11390,22 +11431,22 @@ const ou = {
11390
11431
  }
11391
11432
  }
11392
11433
  };
11393
- function au(n) {
11434
+ function lu(n) {
11394
11435
  if (n)
11395
- return typeof n != "string" ? n : ou[n];
11436
+ return typeof n != "string" ? n : au[n];
11396
11437
  }
11397
- const lu = ["default-src", "script-src", "connect-src", "worker-src", "child-src"];
11398
- function cu(n) {
11438
+ const cu = ["default-src", "script-src", "connect-src", "worker-src", "child-src"];
11439
+ function du(n) {
11399
11440
  if (!n || typeof n != "object" || Array.isArray(n)) return;
11400
11441
  const e = {};
11401
11442
  for (const [t, r] of Object.entries(n)) {
11402
- if (!lu.includes(t) || typeof r != "string" || !r.trim() || /[;,]|[^\x20-\x7e]/u.test(r))
11443
+ if (!cu.includes(t) || typeof r != "string" || !r.trim() || /[;,]|[^\x20-\x7e]/u.test(r))
11403
11444
  return;
11404
11445
  e[t] = r.trim();
11405
11446
  }
11406
11447
  return Object.keys(e).length ? e : void 0;
11407
11448
  }
11408
- function du(n, e) {
11449
+ function uu(n, e) {
11409
11450
  if (e === !1) return !1;
11410
11451
  const t = e === !0 || e === void 0 ? {} : e, r = t.bounds ?? n;
11411
11452
  if (!r) return !1;
@@ -11432,7 +11473,7 @@ function du(n, e) {
11432
11473
  capToBounds: t.capToBounds ?? !s
11433
11474
  };
11434
11475
  }
11435
- function uu(n) {
11476
+ function hu(n) {
11436
11477
  const e = { ...Fo, ...n?.sandbox ?? {} }, t = { ...Ko, ...n?.iframeAllow ?? {} }, r = {
11437
11478
  ...Xo,
11438
11479
  ...n?.permissionsPolicy ?? {}
@@ -11447,11 +11488,11 @@ function uu(n) {
11447
11488
  permissionsPolicy: r,
11448
11489
  cspDirectives: s,
11449
11490
  sealAllow: n?.sealAllow,
11450
- workerCsp: cu(n?.workerCsp),
11491
+ workerCsp: du(n?.workerCsp),
11451
11492
  worker: n?.worker ? { enabled: n.worker.enabled } : void 0
11452
11493
  };
11453
11494
  }
11454
- function hu(n, e) {
11495
+ function pu(n, e) {
11455
11496
  if (!e) return n;
11456
11497
  const t = e.cspDirectives ? Object.fromEntries(
11457
11498
  Object.keys(St).map((r) => [
@@ -11468,7 +11509,7 @@ function hu(n, e) {
11468
11509
  cspDirectives: t
11469
11510
  };
11470
11511
  }
11471
- function pu(n) {
11512
+ function Au(n) {
11472
11513
  return {
11473
11514
  heightRatio: n?.heightRatio ?? er,
11474
11515
  placeholderText: n?.placeholderText ?? Ht
@@ -11486,11 +11527,11 @@ function _r(n, e) {
11486
11527
  // 个人页用户信息为内部数据:hostApi getUserInfo 拉取后写入(无对外构造入口)
11487
11528
  profilePreview: {},
11488
11529
  widgetCover: { ...n.widgetCover },
11489
- rednoteDetail: pu(n.rednoteDetail),
11530
+ rednoteDetail: Au(n.rednoteDetail),
11490
11531
  renderer: n.renderer ?? "iframe-service-worker",
11491
- viewport: iu(n.device, n.viewport),
11532
+ viewport: ou(n.device, n.viewport),
11492
11533
  // 默认无贴图外壳(frameless);需要 iPhone / Nexus 贴图壳时显式传 phoneFrame
11493
- phoneFrame: au(n.phoneFrame === void 0 ? !1 : n.phoneFrame),
11534
+ phoneFrame: lu(n.phoneFrame === void 0 ? !1 : n.phoneFrame),
11494
11535
  query: n.query ?? {},
11495
11536
  review: {
11496
11537
  collectConsole: n.review?.collectConsole ?? !1,
@@ -11513,12 +11554,12 @@ function _r(n, e) {
11513
11554
  // webview 与 iframe 共用同一套 bounds + transform 缩放(对齐 mp-simulator layout 的 auto scale)。
11514
11555
  // 内部 guest 须保持逻辑视口像素尺寸(见 webview.resize 对 webview 的明确 width/height),
11515
11556
  // 避免 shadow iframe 在百分比高度下塌成 150px;外层 stage 的 scale 只负责装入容器。
11516
- stageFit: du(e.stageFitBounds, n.stageFit ?? !0),
11517
- jsapi: Au(n.jsapi),
11518
- security: uu(n.security)
11557
+ stageFit: uu(e.stageFitBounds, n.stageFit ?? !0),
11558
+ jsapi: fu(n.jsapi),
11559
+ security: hu(n.security)
11519
11560
  };
11520
11561
  }
11521
- function Au(n) {
11562
+ function fu(n) {
11522
11563
  if (n === !1)
11523
11564
  return {
11524
11565
  enabled: !1,
@@ -11552,11 +11593,11 @@ const es = {
11552
11593
  onNetwork: "network",
11553
11594
  onDestroy: "destroy"
11554
11595
  };
11555
- class fu {
11596
+ class gu {
11556
11597
  constructor(e, t = {}) {
11557
- if (this.runtimeOptions = t, this.lifecycle = new ru(), this.events = new is(), this.injection = new ki(), this.renderer = null, this.loadGeneration = 0, this.loadedUrl = "", this.loadSource = "load", this.swHost = null, this.swMountedId = null, this.swInjectionContext = null, this.userDataPath = null, this.serviceWorkerUnavailable = !1, this.detachStageFit = null, this.hostApiMap = {}, this.showJsApiAlert = rc(this.runtimeOptions.businessLine), this.gesturePlugins = /* @__PURE__ */ new Map(), this.inspectorEnabled = !1, this.inspectorSelectionMode = "single", this.tracker = null, this.devtoolsPanel = null, this.detachDevtoolsShortcut = null, this.currentRoute = "note", this.activePage = "note", this.shadowHost = xi(Ei(e.mount), {
11598
+ if (this.runtimeOptions = t, this.lifecycle = new su(), this.events = new is(), this.injection = new ki(), this.renderer = null, this.loadGeneration = 0, this.loadedUrl = "", this.loadSource = "load", this.swHost = null, this.swMountedId = null, this.swInjectionContext = null, this.userDataPath = null, this.serviceWorkerUnavailable = !1, this.detachStageFit = null, this.hostApiMap = {}, this.showJsApiAlert = rc(this.runtimeOptions.businessLine), this.gesturePlugins = /* @__PURE__ */ new Map(), this.inspectorEnabled = !1, this.inspectorSelectionMode = "single", this.tracker = null, this.devtoolsPanel = null, this.detachDevtoolsShortcut = null, this.currentRoute = "note", this.activePage = "note", this.shadowHost = xi(Ei(e.mount), {
11558
11599
  shadow: e.shadow
11559
- }), this.phoneVibration = new Ia(this.shadowHost.stage), this.requestRuntime = new nd({
11600
+ }), this.phoneVibration = new La(this.shadowHost.stage), this.requestRuntime = new nd({
11560
11601
  mount: this.shadowHost.stage,
11561
11602
  requestManagerFrameUrl: t.requestManagerFrameUrl,
11562
11603
  getHostRequest: () => {
@@ -11573,13 +11614,13 @@ class fu {
11573
11614
  ]), tc({
11574
11615
  renderer: this.options.renderer,
11575
11616
  environment: ec()
11576
- }), this.injection.register(jo), this.injection.register($o), this.injection.register(ta), this.injection.register(ea), this.injection.register(Ho), this.injection.register(qo), this.injection.register(_o), this.injection.register(bo), this.injection.register(ra), Object.assign(this.hostApiMap, e.hostApi ?? {}), this.hostApi = zd({
11617
+ }), this.injection.register(jo), this.injection.register($o), this.injection.register(ta), this.injection.register(ea), this.injection.register(Ho), this.injection.register(qo), this.injection.register(_o), this.injection.register(bo), this.injection.register(ra), Object.assign(this.hostApiMap, e.hostApi ?? {}), this.hostApi = jd({
11577
11618
  hostApiMap: this.hostApiMap,
11578
11619
  getRenderer: () => this.renderer
11579
- }), this.gesture = jd({
11620
+ }), this.gesture = Jd({
11580
11621
  gesturePlugins: this.gesturePlugins,
11581
11622
  getRenderer: () => this.renderer
11582
- }), this.gamePlaytest = Jd({ getRenderer: () => this.renderer }), this.inspector = _d({
11623
+ }), this.gamePlaytest = _d({ getRenderer: () => this.renderer }), this.inspector = $d({
11583
11624
  getRenderer: () => this.renderer,
11584
11625
  isEnabled: () => this.inspectorEnabled,
11585
11626
  setEnabled: (r) => {
@@ -11590,19 +11631,19 @@ class fu {
11590
11631
  this.inspectorSelectionMode = r;
11591
11632
  },
11592
11633
  emitChange: (r) => this.events.emit("inspectorChange", { enabled: r })
11593
- }), this.notePreview = eu({
11634
+ }), this.notePreview = tu({
11594
11635
  getOptions: () => this.options,
11595
11636
  setOptions: (r) => {
11596
11637
  this.options = r;
11597
11638
  },
11598
11639
  syncRednote: () => this.syncRendererRednoteContext()
11599
- }), this.widgetCover = tu({
11640
+ }), this.widgetCover = nu({
11600
11641
  getOptions: () => this.options,
11601
11642
  setOptions: (r) => {
11602
11643
  this.options = r;
11603
11644
  },
11604
11645
  syncWidgetCover: () => this.syncRendererWidgetCover()
11605
- }), this.permissionSheet = $d({
11646
+ }), this.permissionSheet = eu({
11606
11647
  getRenderer: () => this.renderer,
11607
11648
  onResult: (r, s) => {
11608
11649
  this.tracker?.trackPermissionResult({ type: r, result: s });
@@ -11722,11 +11763,11 @@ class fu {
11722
11763
  onRenderDone: a,
11723
11764
  onError: l,
11724
11765
  onNavigation: d,
11725
- onConsole: h,
11766
+ onConsole: u,
11726
11767
  onNetwork: A,
11727
- onDestroy: u,
11768
+ onDestroy: h,
11728
11769
  hostApi: m,
11729
- onEvent: w,
11770
+ onEvent: v,
11730
11771
  tracker: b,
11731
11772
  ...f
11732
11773
  } = e;
@@ -11754,7 +11795,7 @@ class fu {
11754
11795
  ...this.options,
11755
11796
  ...e,
11756
11797
  notePreview: e.notePreview ? { ...this.options.notePreview, ...e.notePreview } : this.options.notePreview,
11757
- security: hu(this.options.security, e.security),
11798
+ security: pu(this.options.security, e.security),
11758
11799
  review: { ...this.options.review, ...e.review }
11759
11800
  };
11760
11801
  return _r(t, this.normalizeContext());
@@ -11828,7 +11869,7 @@ class fu {
11828
11869
  }
11829
11870
  async redirectTo(e, t) {
11830
11871
  if (this.lifecycle.assertActive(), e !== "note" && e !== "minitool" && e !== "profile")
11831
- throw new te("INVALID_ROUTE", `Unsupported route: ${String(e)}`);
11872
+ throw new ne("INVALID_ROUTE", `Unsupported route: ${String(e)}`);
11832
11873
  if (e === "minitool") {
11833
11874
  this.currentRoute !== "minitool" && (this.renderer?.openContent?.(t?.sheetMode ?? "full"), this.setRoute("minitool"));
11834
11875
  return;
@@ -11859,7 +11900,11 @@ class fu {
11859
11900
  ), this.registerBuiltinBridgeHandlers(), this.renderer?.useGesturePlugin)
11860
11901
  for (const i of this.gesturePlugins.values())
11861
11902
  this.renderer.useGesturePlugin(i);
11862
- if (this.renderer?.setInspectorSelectionMode?.(this.inspectorSelectionMode), this.inspectorEnabled && this.renderer?.enableInspector?.(), this.activePage !== "note" && this.renderer?.setActivePage?.(this.activePage), this.options.stageFit && (this.detachStageFit = Hd(this.shadowHost.stage, this.options.stageFit)), await this.tryResolveHostUserInfo(), !this.isCurrentLoad(e) || this.renderer !== t || (await this.maybeMountRemoteViaServiceWorker(), !this.isCurrentLoad(e) || this.renderer !== t) || (this.tracker?.trackLoadStage("renderer_setup", {
11903
+ if (this.renderer?.setInspectorSelectionMode?.(this.inspectorSelectionMode), this.inspectorEnabled && this.renderer?.enableInspector?.(), this.activePage !== "note" && this.renderer?.setActivePage?.(this.activePage), this.options.stageFit && (this.detachStageFit = Qd(
11904
+ this.shadowHost.stage,
11905
+ this.options.stageFit,
11906
+ this.options.desktopControls && this.options.touchEmulation ? this.shadowHost : void 0
11907
+ )), await this.tryResolveHostUserInfo(), !this.isCurrentLoad(e) || this.renderer !== t || (await this.maybeMountRemoteViaServiceWorker(), !this.isCurrentLoad(e) || this.renderer !== t) || (this.tracker?.trackLoadStage("renderer_setup", {
11863
11908
  result: "success",
11864
11909
  duration: Date.now() - r
11865
11910
  }), s = !0, this.loadedUrl = this.resolveLoadUrl(), this.events.emit("ready", {
@@ -11984,7 +12029,7 @@ class fu {
11984
12029
  }
11985
12030
  async loadZip(e, t) {
11986
12031
  this.lifecycle.assertActive(), this.assertServiceWorkerLoader(), this.assertServiceWorkerUsable();
11987
- const r = ++this.loadGeneration, s = Date.now(), i = await gd(e, {
12032
+ const r = ++this.loadGeneration, s = Date.now(), i = await md(e, {
11988
12033
  jszip: t?.jszip,
11989
12034
  entry: t?.entry,
11990
12035
  limits: t?.limits
@@ -11996,15 +12041,15 @@ class fu {
11996
12041
  entry: i.entryPath
11997
12042
  }), this.isCurrentLoad(r) && (this.interruptCurrentGuest(), t?.query && (this.options = this.mergeOptions({ query: { ...this.options.query, ...t.query } })), await this.loadViaServiceWorker(i, "load-zip", r)), this.toLoadMeta(i);
11998
12043
  }
11999
- async loadFiles(e, t) {
12044
+ async loadFiles(e, t, r) {
12000
12045
  this.lifecycle.assertActive(), this.assertServiceWorkerLoader(), this.assertServiceWorkerUsable();
12001
- const r = ++this.loadGeneration, s = Date.now(), i = md(e, { entry: t?.entry, limits: t?.limits });
12046
+ const s = ++this.loadGeneration, i = Date.now(), o = bd(e, { entry: t?.entry, limits: t?.limits });
12002
12047
  return this.tracker?.trackParseDone({
12003
12048
  type: "files",
12004
- duration: Date.now() - s,
12005
- count: i.files.length,
12006
- entry: i.entryPath
12007
- }), this.isCurrentLoad(r) && (this.interruptCurrentGuest(), t?.query && (this.options = this.mergeOptions({ query: { ...this.options.query, ...t.query } })), await this.loadViaServiceWorker(i, "load-files", r)), this.toLoadMeta(i);
12049
+ duration: Date.now() - i,
12050
+ count: o.files.length,
12051
+ entry: o.entryPath
12052
+ }), this.isCurrentLoad(s) && (this.loadedUrl && this.interruptCurrentGuest(), t?.query && (this.options = this.mergeOptions({ query: { ...this.options.query, ...t.query } })), await this.loadViaServiceWorker(o, "load-files", s, r)), this.toLoadMeta(o);
12008
12053
  }
12009
12054
  /**
12010
12055
  * loadZip / loadFiles 走 `iframe-service-worker`(Web 运行时):把包文件挂载给
@@ -12012,7 +12057,7 @@ class fu {
12012
12057
  */
12013
12058
  assertServiceWorkerLoader() {
12014
12059
  if (this.options.renderer !== "iframe-service-worker")
12015
- throw new te(
12060
+ throw new ne(
12016
12061
  "LOADER_UNSUPPORTED",
12017
12062
  `loadZip/loadFiles 需要 renderer: "iframe-service-worker";当前 renderer="${this.options.renderer}"`
12018
12063
  );
@@ -12053,63 +12098,64 @@ class fu {
12053
12098
  }
12054
12099
  }
12055
12100
  /** SW 路径:算注入载荷 → 挂载原始文件到 SW → 以同源虚拟 URL 直连(SW 改写 HTML + 下发 CSP)。 */
12056
- async loadViaServiceWorker(e, t, r) {
12057
- const s = this.options.serviceWorker;
12058
- if (!s?.scriptUrl) throw new Error("serviceWorker.scriptUrl is required");
12059
- const i = await this.acquireServiceWorkerHost(s.scriptUrl, s.mountTimeout);
12101
+ async loadViaServiceWorker(e, t, r, s) {
12102
+ const i = this.options.serviceWorker;
12103
+ if (!i?.scriptUrl) throw new Error("serviceWorker.scriptUrl is required");
12104
+ const o = await this.acquireServiceWorkerHost(i.scriptUrl, i.mountTimeout);
12060
12105
  if (!this.isCurrentLoad(r)) return;
12061
- this.unmountServiceWorkerContent(), this.swHost = i;
12062
- const o = Cn(), a = this.options.appId || o, l = i.fileUrl(a, "usr"), d = `${i.scope}${o}/${e.entryPath}`, h = Qd(this.options.security.worker, o), A = Date.now(), { head: u, csp: m } = await yn(
12106
+ this.unmountServiceWorkerContent(), this.swHost = o;
12107
+ const a = Cn(), l = this.options.appId || a, d = o.fileUrl(l, "usr"), u = `${o.scope}${a}/${e.entryPath}`, A = zd(this.options.security.worker, a), h = Date.now(), { head: m, csp: v } = await yn(
12063
12108
  this.options,
12064
12109
  this.injection,
12065
- d,
12110
+ u,
12066
12111
  e.entryHtml,
12067
12112
  void 0,
12068
- wn(s),
12069
- l,
12113
+ wn(i),
12114
+ d,
12070
12115
  this.runtimeOptions.gateways,
12071
12116
  this.runtimeOptions.businessLine,
12072
- h
12117
+ A
12073
12118
  );
12074
12119
  this.tracker?.trackLoadStage("injection_build", {
12075
12120
  result: "success",
12076
- duration: Date.now() - A,
12121
+ duration: Date.now() - h,
12077
12122
  count: e.files.length
12078
12123
  });
12079
- const w = Date.now();
12080
- let b;
12124
+ const b = Date.now();
12125
+ let f;
12081
12126
  try {
12082
- b = await i.mount({
12083
- id: o,
12127
+ f = await o.mount({
12128
+ id: a,
12084
12129
  entryPath: e.entryPath,
12085
12130
  rawFiles: e.rawFiles,
12086
- injectHead: u,
12087
- csp: m,
12088
- fsScope: a,
12089
- worker: h ? { sessionId: o, csp: this.options.security.workerCsp } : void 0
12131
+ offloaded: s,
12132
+ injectHead: m,
12133
+ csp: v,
12134
+ fsScope: l,
12135
+ worker: A ? { sessionId: a, csp: this.options.security.workerCsp } : void 0
12090
12136
  });
12091
- } catch (f) {
12137
+ } catch (w) {
12092
12138
  throw this.tracker?.trackSwMount({
12093
12139
  result: "fail",
12094
- duration: Date.now() - w,
12140
+ duration: Date.now() - b,
12095
12141
  count: e.files.length,
12096
- message: f instanceof Error ? f.message : String(f)
12097
- }), f;
12142
+ message: w instanceof Error ? w.message : String(w)
12143
+ }), w;
12098
12144
  }
12099
12145
  if (!this.isCurrentLoad(r)) {
12100
- i.unmount(o);
12146
+ o.unmount(a);
12101
12147
  return;
12102
12148
  }
12103
12149
  this.tracker?.trackSwMount({
12104
12150
  result: "success",
12105
- duration: Date.now() - w,
12151
+ duration: Date.now() - b,
12106
12152
  count: e.files.length,
12107
12153
  entry: e.entryPath
12108
- }), this.swMountedId = o, this.userDataPath = l, this.options = this.mergeOptions({ appUrl: b }), this.swInjectionContext = { virtualUrl: d, rawHtml: e.entryHtml, userDataPath: l }, this.loadSource = t, await this.loadCurrent(r);
12154
+ }), this.swMountedId = a, this.userDataPath = d, this.options = this.mergeOptions({ appUrl: f }), this.swInjectionContext = { virtualUrl: u, rawHtml: e.entryHtml, userDataPath: d }, this.loadSource = t, await this.loadCurrent(r);
12109
12155
  }
12110
12156
  /** 是否对当前远程 appUrl 启用 SW 代理:SW 渲染器 + 配了 scriptUrl + 环境支持 + 未注册失败 + appUrl 为跨域 http(s)。 */
12111
12157
  shouldProxyRemoteViaServiceWorker() {
12112
- return !this.serviceWorkerUnavailable && this.options.renderer === "iframe-service-worker" && !!this.options.serviceWorker?.scriptUrl && Ur() && !this.isCurrentServiceWorkerMountUrl(this.options.appUrl) && gu(this.options.appUrl);
12158
+ return !this.serviceWorkerUnavailable && this.options.renderer === "iframe-service-worker" && !!this.options.serviceWorker?.scriptUrl && Ur() && !this.isCurrentServiceWorkerMountUrl(this.options.appUrl) && mu(this.options.appUrl);
12113
12159
  }
12114
12160
  /** load() 内调用:远程 appUrl 满足条件时挂进 SW 走同源代理;失败经 error 事件暴露并抛出。 */
12115
12161
  async maybeMountRemoteViaServiceWorker() {
@@ -12123,7 +12169,7 @@ class fu {
12123
12169
  async mountRemoteViaServiceWorker(e) {
12124
12170
  const t = this.options.serviceWorker;
12125
12171
  if (!t?.scriptUrl) throw new Error("serviceWorker.scriptUrl is required");
12126
- const r = $r(e, this.options.query), s = new URL(".", r).href, i = mu(r), o = Date.now(), a = await fetch(r, { method: "GET", credentials: "omit", cache: "no-store" });
12172
+ const r = $r(e, this.options.query), s = new URL(".", r).href, i = bu(r), o = Date.now(), a = await fetch(r, { method: "GET", credentials: "omit", cache: "no-store" });
12127
12173
  if (!a.ok) throw new Error(`远程入口请求失败:HTTP ${a.status}`);
12128
12174
  const l = await a.text();
12129
12175
  this.tracker?.trackParseDone({
@@ -12134,14 +12180,14 @@ class fu {
12134
12180
  });
12135
12181
  const d = await this.acquireServiceWorkerHost(t.scriptUrl, t.mountTimeout);
12136
12182
  this.unmountServiceWorkerContent(), this.swHost = d;
12137
- const h = Cn(), A = this.options.appId || h, u = d.fileUrl(A, "usr"), m = `${d.scope}${h}/${i}`, w = new URL(r).origin, b = Date.now(), { head: f, csp: y } = await yn(
12183
+ const u = Cn(), A = this.options.appId || u, h = d.fileUrl(A, "usr"), m = `${d.scope}${u}/${i}`, v = new URL(r).origin, b = Date.now(), { head: f, csp: w } = await yn(
12138
12184
  this.options,
12139
12185
  this.injection,
12140
12186
  m,
12141
12187
  l,
12142
- [w],
12188
+ [v],
12143
12189
  wn(t),
12144
- u,
12190
+ h,
12145
12191
  this.runtimeOptions.gateways,
12146
12192
  this.runtimeOptions.businessLine
12147
12193
  );
@@ -12150,36 +12196,36 @@ class fu {
12150
12196
  duration: Date.now() - b,
12151
12197
  count: 1
12152
12198
  });
12153
- const x = new TextEncoder().encode(l).buffer, q = Date.now();
12154
- let k;
12199
+ const S = new TextEncoder().encode(l).buffer, L = Date.now();
12200
+ let V;
12155
12201
  try {
12156
- k = await d.mount({
12157
- id: h,
12202
+ V = await d.mount({
12203
+ id: u,
12158
12204
  entryPath: i,
12159
- rawFiles: { [i]: x },
12205
+ rawFiles: { [i]: S },
12160
12206
  injectHead: f,
12161
- csp: y,
12207
+ csp: w,
12162
12208
  remoteBase: s,
12163
12209
  fsScope: A
12164
12210
  });
12165
- } catch (S) {
12211
+ } catch (B) {
12166
12212
  throw this.tracker?.trackSwMount({
12167
12213
  result: "fail",
12168
- duration: Date.now() - q,
12214
+ duration: Date.now() - L,
12169
12215
  count: 1,
12170
- message: S instanceof Error ? S.message : String(S)
12171
- }), S;
12216
+ message: B instanceof Error ? B.message : String(B)
12217
+ }), B;
12172
12218
  }
12173
12219
  this.tracker?.trackSwMount({
12174
12220
  result: "success",
12175
- duration: Date.now() - q,
12221
+ duration: Date.now() - L,
12176
12222
  count: 1,
12177
12223
  entry: i
12178
- }), this.swMountedId = h, this.userDataPath = u, this.options = this.mergeOptions({ appUrl: k }), this.swInjectionContext = {
12224
+ }), this.swMountedId = u, this.userDataPath = h, this.options = this.mergeOptions({ appUrl: V }), this.swInjectionContext = {
12179
12225
  virtualUrl: m,
12180
12226
  rawHtml: l,
12181
- extraOrigins: [w],
12182
- userDataPath: u
12227
+ extraOrigins: [v],
12228
+ userDataPath: h
12183
12229
  };
12184
12230
  }
12185
12231
  async setTouchEmulation(e) {
@@ -12291,7 +12337,7 @@ class fu {
12291
12337
  }
12292
12338
  async capture() {
12293
12339
  if (this.lifecycle.assertActive(), !this.renderer?.capture)
12294
- throw new te(
12340
+ throw new ne(
12295
12341
  "CAPTURE_UNSUPPORTED",
12296
12342
  "Current renderer does not support capture"
12297
12343
  );
@@ -12311,7 +12357,7 @@ class fu {
12311
12357
  if (!this.renderer?.capture)
12312
12358
  return e(Je.unsupported, "当前渲染器不支持截图");
12313
12359
  try {
12314
- const t = await this.renderer.capture(), r = await Zd(t, "manual");
12360
+ const t = await this.renderer.capture(), r = await Dd(t, "manual");
12315
12361
  return this.events.emit("screenShot", r), r;
12316
12362
  } catch (t) {
12317
12363
  const r = t instanceof Error ? t.message : String(t), s = /timeout/i.test(r) ? Je.timeout : Je.renderFailed;
@@ -12365,10 +12411,10 @@ class fu {
12365
12411
  restoreServiceWorkerMount: (s) => this.restoreServiceWorkerMount(s)
12366
12412
  };
12367
12413
  if (e === "iframe-service-worker")
12368
- return new Md(r);
12414
+ return new Nd(r);
12369
12415
  if (e === "webview")
12370
12416
  return new _l(r);
12371
- throw new te("UNSUPPORTED_RENDERER", `Unsupported renderer: ${e}`);
12417
+ throw new ne("UNSUPPORTED_RENDERER", `Unsupported renderer: ${e}`);
12372
12418
  }
12373
12419
  bindRendererEvents(e) {
12374
12420
  e.on("load", (t) => this.events.emit("load", t)), e.on("renderDone", (t) => this.events.emit("renderDone", t)), e.on("error", (t) => this.events.emit("error", t)), e.on("navigation", (t) => this.events.emit("navigation", t)), e.on("console", (t) => this.events.emit("console", t)), e.on("guestError", (t) => this.events.emit("guestError", t)), e.on("network", (t) => this.events.emit("network", t)), e.on("performance", (t) => this.events.emit("performance", t)), e.on("capture", (t) => this.events.emit("capture", t)), e.on("elementHovered", (t) => this.events.emit("elementHovered", t)), e.on("elementSelected", (t) => this.events.emit("elementSelected", t)), e.on(
@@ -12392,13 +12438,13 @@ function ts(n, e, t) {
12392
12438
  function wn(n) {
12393
12439
  return n.frameAncestors?.length ? [...new Set(n.frameAncestors)] : void 0;
12394
12440
  }
12395
- function ku(n) {
12396
- return new fu(n);
12441
+ function Vu(n) {
12442
+ return new gu(n);
12397
12443
  }
12398
12444
  function Cn() {
12399
12445
  return typeof crypto < "u" && typeof crypto.randomUUID == "function" ? crypto.randomUUID() : `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
12400
12446
  }
12401
- function gu(n) {
12447
+ function mu(n) {
12402
12448
  if (!n || typeof window > "u") return !1;
12403
12449
  try {
12404
12450
  const e = new URL(n, window.location.href);
@@ -12407,32 +12453,32 @@ function gu(n) {
12407
12453
  return !1;
12408
12454
  }
12409
12455
  }
12410
- function mu(n) {
12456
+ function bu(n) {
12411
12457
  try {
12412
12458
  return (new URL(n).pathname.split("/").pop() ?? "") || Vt;
12413
12459
  } catch {
12414
12460
  return Vt;
12415
12461
  }
12416
12462
  }
12417
- const Vu = Object.freeze(ui);
12463
+ const Lu = Object.freeze(ui);
12418
12464
  export {
12419
12465
  rs as ALL_MINI_APP_CAPABILITIES,
12420
12466
  oi as BusinessLine,
12421
- Su as HOST_CONTROLLED_CAPABILITIES,
12467
+ Eu as HOST_CONTROLLED_CAPABILITIES,
12422
12468
  Je as MINIAPP_SCREENSHOT_ERROR_CODE,
12423
12469
  nn as MINI_APP_CAPABILITIES,
12424
- B as MiniAppCapability,
12425
- T as MiniAppJsApiErrorCode,
12426
- te as MiniAppSimulatorError,
12427
- Cu as SEAL_CONTROLLED_CAPABILITIES,
12428
- wu as WORKER_CONTENT_SECURITY_POLICY,
12429
- Vu as WORKER_RUNTIME_METADATA,
12470
+ R as MiniAppCapability,
12471
+ F as MiniAppJsApiErrorCode,
12472
+ ne as MiniAppSimulatorError,
12473
+ Su as SEAL_CONTROLLED_CAPABILITIES,
12474
+ Cu as WORKER_CONTENT_SECURITY_POLICY,
12475
+ Lu as WORKER_RUNTIME_METADATA,
12430
12476
  hi as WORKER_RUNTIME_PROTOCOL_VERSION,
12431
12477
  Sr as buildElementSelection,
12432
12478
  Ua as computeSelector,
12433
- ku as createMiniAppSimulator,
12479
+ Vu as createMiniAppSimulator,
12434
12480
  ec as detectEnvironment,
12435
- xu as getSimulatorContext,
12481
+ ku as getSimulatorContext,
12436
12482
  fi as isMiniAppCapability,
12437
- Eu as sanitizeCapabilityList
12483
+ xu as sanitizeCapabilityList
12438
12484
  };