@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.
@@ -1,24 +1,24 @@
1
- const h = self, pe = "index.html", me = "default-src 'none'; script-src 'none'; connect-src 'none'; worker-src 'none'; child-src 'none'", ge = {
2
- workerCsp: me
3
- }, G = ge.workerCsp, ye = ["default-src", "script-src", "connect-src", "worker-src", "child-src"];
4
- function Z(e) {
1
+ const p = self, Ie = "index.html", Ce = "default-src 'none'; script-src 'none'; connect-src 'none'; worker-src 'none'; child-src 'none'", Te = {
2
+ workerCsp: Ce
3
+ }, ee = Te.workerCsp, Ue = ["default-src", "script-src", "connect-src", "worker-src", "child-src"];
4
+ function ue(e) {
5
5
  if (!e || typeof e != "object" || Array.isArray(e)) return;
6
6
  const t = {};
7
7
  for (const [n, r] of Object.entries(e)) {
8
- if (!ye.includes(n) || typeof r != "string" || !r.trim() || /[;,]|[^\x20-\x7e]/u.test(r))
8
+ if (!Ue.includes(n) || typeof r != "string" || !r.trim() || /[;,]|[^\x20-\x7e]/u.test(r))
9
9
  return;
10
10
  t[n] = r.trim();
11
11
  }
12
12
  return Object.keys(t).length ? t : void 0;
13
13
  }
14
- function we(e) {
15
- const t = Z(e);
16
- return t ? G.split("; ").map((n) => {
14
+ function Pe(e) {
15
+ const t = ue(e);
16
+ return t ? ee.split("; ").map((n) => {
17
17
  const r = n.slice(0, n.indexOf(" "));
18
18
  return t[r] === void 0 ? n : `${r} ${t[r]}`;
19
- }).join("; ") : G;
19
+ }).join("; ") : ee;
20
20
  }
21
- const be = {
21
+ const Le = {
22
22
  html: "text/html; charset=utf-8",
23
23
  htm: "text/html; charset=utf-8",
24
24
  js: "text/javascript; charset=utf-8",
@@ -32,7 +32,7 @@ const be = {
32
32
  svg: "image/svg+xml",
33
33
  wasm: "application/wasm",
34
34
  map: "application/json; charset=utf-8"
35
- }, _e = {
35
+ }, ke = {
36
36
  png: "image/png",
37
37
  jpg: "image/jpeg",
38
38
  jpeg: "image/jpeg",
@@ -51,20 +51,21 @@ const be = {
51
51
  ogg: "video/ogg",
52
52
  mp3: "audio/mpeg",
53
53
  wav: "audio/wav",
54
+ aac: "audio/aac",
54
55
  m4a: "audio/mp4"
55
56
  };
56
- function Re(e) {
57
+ function Me(e) {
57
58
  const t = e.split(".").pop()?.toLowerCase() ?? "";
58
- return be[t] ?? _e[t] ?? "application/octet-stream";
59
+ return Le[t] ?? ke[t] ?? "application/octet-stream";
59
60
  }
60
- function b(e) {
61
+ function S(e) {
61
62
  try {
62
63
  return decodeURIComponent(e);
63
64
  } catch {
64
65
  return null;
65
66
  }
66
67
  }
67
- function W(e) {
68
+ function q(e) {
68
69
  const t = [];
69
70
  for (const n of e.replace(/\\/g, "/").split("/"))
70
71
  if (!(n === "" || n === ".")) {
@@ -73,16 +74,16 @@ function W(e) {
73
74
  }
74
75
  return t.join("/");
75
76
  }
76
- const g = /* @__PURE__ */ new Map(), Y = 16;
77
- function ve(e) {
78
- if (!g.has(e.id) && g.size >= Y) {
79
- const r = new Error(`too many active simulator mounts (max ${Y})`);
77
+ const x = /* @__PURE__ */ new Map(), te = 16;
78
+ function Fe(e) {
79
+ if (!x.has(e.id) && x.size >= te) {
80
+ const r = new Error(`too many active simulator mounts (max ${te})`);
80
81
  throw r.code = "ERR_MOUNT_LIMIT", r;
81
82
  }
82
83
  const t = /* @__PURE__ */ new Map();
83
84
  for (const [r, i] of Object.entries(e.files)) {
84
- const s = W(r);
85
- s && t.set(s, { bytes: i, mime: Re(s) });
85
+ const s = q(r);
86
+ s && t.set(s, { bytes: i, mime: Me(s) });
86
87
  }
87
88
  let n;
88
89
  if (e.worker) {
@@ -90,10 +91,15 @@ function ve(e) {
90
91
  throw new TypeError("Invalid package Worker mount policy");
91
92
  n = {
92
93
  sessionId: e.id,
93
- csp: Z(e.worker.csp)
94
+ csp: ue(e.worker.csp)
94
95
  };
95
96
  }
96
- return g.set(e.id, {
97
+ return Y(e.id), x.set(e.id, {
98
+ offloaded: e.offloaded && {
99
+ id: e.id,
100
+ resources: e.offloaded,
101
+ lifetime: new AbortController()
102
+ },
97
103
  worker: n,
98
104
  workerResponses: /* @__PURE__ */ new Map(),
99
105
  files: t,
@@ -104,45 +110,45 @@ function ve(e) {
104
110
  ownerClientId: e.ownerClientId ?? ""
105
111
  }), t.size;
106
112
  }
107
- function xe(e) {
108
- g.delete(e);
113
+ function Y(e) {
114
+ x.get(e)?.offloaded?.lifetime.abort(), x.delete(e);
109
115
  }
110
- function Ee(e) {
116
+ function Oe(e) {
111
117
  let t = 0;
112
- for (const [n, r] of g)
113
- !r.ownerClientId || e.has(r.ownerClientId) || (g.delete(n), t += 1);
118
+ for (const [n, r] of x)
119
+ !r.ownerClientId || e.has(r.ownerClientId) || (Y(n), t += 1);
114
120
  return t;
115
121
  }
116
- function P(e) {
122
+ function T(e) {
117
123
  let t;
118
124
  try {
119
125
  t = new URL(e).pathname;
120
126
  } catch {
121
127
  return null;
122
128
  }
123
- for (const [n, r] of g) {
129
+ for (const [n, r] of x) {
124
130
  const i = `/${n}/`, s = t.indexOf(i);
125
131
  if (s === -1) continue;
126
- let a = b(t.slice(s + i.length));
127
- if (a === null) return null;
128
- (a === "" || a.endsWith("/")) && (a += pe);
129
- const o = W(a);
130
- return o ? { app: r, filePath: o } : null;
132
+ let o = S(t.slice(s + i.length));
133
+ if (o === null) return null;
134
+ (o === "" || o.endsWith("/")) && (o += Ie);
135
+ const a = q(o);
136
+ return a ? { app: r, filePath: a } : null;
131
137
  }
132
138
  return null;
133
139
  }
134
- function Q(e) {
140
+ function K(e) {
135
141
  let t;
136
142
  try {
137
143
  t = new URL(e).pathname;
138
144
  } catch {
139
145
  return null;
140
146
  }
141
- for (const [n, r] of g)
147
+ for (const [n, r] of x)
142
148
  if (t.includes(`/${n}/`)) return r;
143
149
  return null;
144
150
  }
145
- const Se = 5, Pe = "miniapp:restore-worker-mount", De = [
151
+ const Be = 6, We = "miniapp:offloaded-resource-url", Ne = "miniapp:restore-worker-mount", $e = [
146
152
  "fsWriteTempFile",
147
153
  "fsSaveFile",
148
154
  "fsWriteFile",
@@ -153,88 +159,88 @@ const Se = 5, Pe = "miniapp:restore-worker-mount", De = [
153
159
  "fsUnlink",
154
160
  "fsMkdir",
155
161
  "fsGetStorageInfo"
156
- ], F = /* @__PURE__ */ new Map();
157
- async function Ie(e, t) {
158
- const n = new URL(h.registration.scope), r = new URL(e.url);
162
+ ], W = /* @__PURE__ */ new Map();
163
+ async function je(e, t) {
164
+ const n = new URL(p.registration.scope), r = new URL(e.url);
159
165
  if (r.origin !== n.origin || !r.pathname.startsWith(n.pathname)) return;
160
166
  const i = r.pathname.slice(n.pathname.length), s = i.indexOf("/");
161
167
  if (s < 1) return;
162
- const a = i.slice(0, s);
163
- if (!/^[a-zA-Z0-9_-]{1,128}$/.test(a)) return;
164
- const o = await h.clients.get(t);
165
- if (!o) return;
166
- const c = new URL(o.url);
167
- if (c.origin !== n.origin || !c.pathname.startsWith(`${n.pathname}${a}/`))
168
+ const o = i.slice(0, s);
169
+ if (!/^[a-zA-Z0-9_-]{1,128}$/.test(o)) return;
170
+ const a = await p.clients.get(t);
171
+ if (!a) return;
172
+ const c = new URL(a.url);
173
+ if (c.origin !== n.origin || !c.pathname.startsWith(`${n.pathname}${o}/`))
168
174
  return;
169
- let u = F.get(a);
170
- u || (u = Te(a, n.origin).finally(() => F.delete(a)), F.set(a, u)), await u;
175
+ let f = W.get(o);
176
+ f || (f = He(o, n.origin).finally(() => W.delete(o)), W.set(o, f)), await f;
171
177
  }
172
- async function Te(e, t) {
173
- const n = (await h.clients.matchAll({ type: "window", includeUncontrolled: !0 })).filter(
178
+ async function He(e, t) {
179
+ const n = (await p.clients.matchAll({ type: "window", includeUncontrolled: !0 })).filter(
174
180
  (r) => new URL(r.url).origin === t
175
181
  );
176
182
  n.length && await new Promise((r) => {
177
183
  const i = [];
178
- let s = n.length, a = !1;
179
- const o = () => {
180
- if (!a) {
181
- a = !0, clearTimeout(c);
182
- for (const u of i) u.close();
184
+ let s = n.length, o = !1;
185
+ const a = () => {
186
+ if (!o) {
187
+ o = !0, clearTimeout(c);
188
+ for (const f of i) f.close();
183
189
  r();
184
190
  }
185
- }, c = setTimeout(o, 5e3);
186
- for (const u of n) {
187
- const f = new MessageChannel();
188
- i.push(f.port1), f.port1.onmessage = ({ data: d }) => {
189
- (d?.ok === !0 || --s === 0) && o();
191
+ }, c = setTimeout(a, 5e3);
192
+ for (const f of n) {
193
+ const l = new MessageChannel();
194
+ i.push(l.port1), l.port1.onmessage = ({ data: u }) => {
195
+ (u?.ok === !0 || --s === 0) && a();
190
196
  };
191
197
  try {
192
- u.postMessage({ type: Pe, id: e }, [f.port2]);
198
+ f.postMessage({ type: Ne, id: e }, [l.port2]);
193
199
  } catch {
194
- f.port2.close(), --s === 0 && o();
200
+ l.port2.close(), --s === 0 && a();
195
201
  }
196
202
  }
197
203
  });
198
204
  }
199
- async function ke(e, t) {
205
+ async function ze(e, t) {
200
206
  const n = () => new Response("Worker entry denied", {
201
207
  status: 403,
202
208
  headers: { "Content-Type": "text/plain; charset=utf-8", "Cache-Control": "no-store" }
203
209
  });
204
210
  if (e.method !== "GET" || e.destination !== "worker" || !t) return n();
205
- let r = P(e.url);
211
+ let r = T(e.url);
206
212
  if (!r)
207
213
  try {
208
- await Ie(e, t), r = P(e.url);
214
+ await je(e, t), r = T(e.url);
209
215
  } catch {
210
216
  return n();
211
217
  }
212
218
  if (!r?.app.worker) return n();
213
- const { app: i, filePath: s } = r, a = i.worker, o = new URL(h.registration.scope), c = new URL(e.url);
214
- if (c.origin !== o.origin || !c.pathname.startsWith(`${o.pathname}${a.sessionId}/`))
219
+ const { app: i, filePath: s } = r, o = i.worker, a = new URL(p.registration.scope), c = new URL(e.url);
220
+ if (c.origin !== a.origin || !c.pathname.startsWith(`${a.pathname}${o.sessionId}/`))
215
221
  return n();
216
222
  try {
217
- const u = await h.clients.get(t);
218
- if (!u || Q(u.url) !== i || P(e.url)?.app !== i)
223
+ const f = await p.clients.get(t);
224
+ if (!f || K(f.url) !== i || T(e.url)?.app !== i)
219
225
  return n();
220
- const f = i.workerResponses.get(s);
221
- if (f) return f.clone();
222
- const d = i.files.get(s);
223
- if (!d) return n();
224
- const y = new Response(d.bytes, {
226
+ const l = i.workerResponses.get(s);
227
+ if (l) return l.clone();
228
+ const u = i.files.get(s);
229
+ if (!u) return n();
230
+ const h = new Response(u.bytes, {
225
231
  headers: {
226
232
  "Content-Type": "text/javascript; charset=utf-8",
227
233
  "Cache-Control": "no-store",
228
234
  "X-Content-Type-Options": "nosniff",
229
- "Content-Security-Policy": we(a.csp)
235
+ "Content-Security-Policy": Pe(o.csp)
230
236
  }
231
237
  });
232
- return i.workerResponses.set(s, y), y.clone();
238
+ return i.workerResponses.set(s, h), h.clone();
233
239
  } catch {
234
240
  return n();
235
241
  }
236
242
  }
237
- const Ce = {
243
+ const Ge = {
238
244
  "image/png": "png",
239
245
  "image/jpeg": "jpg",
240
246
  "image/webp": "webp",
@@ -243,24 +249,24 @@ const Ce = {
243
249
  "video/quicktime": "mov",
244
250
  "video/webm": "webm"
245
251
  };
246
- function J(e) {
252
+ function le(e) {
247
253
  const t = new Uint8Array(e);
248
- if (U(t, [137, 80, 78, 71, 13, 10, 26, 10]))
254
+ if (N(t, [137, 80, 78, 71, 13, 10, 26, 10]))
249
255
  return "image/png";
250
- if (U(t, [255, 216, 255])) return "image/jpeg";
251
- if (x(t, 0, "GIF87a") || x(t, 0, "GIF89a")) return "image/gif";
252
- if (x(t, 0, "RIFF") && x(t, 8, "WEBP")) return "image/webp";
253
- if (x(t, 4, "ftyp"))
254
- return ee(t, 8, 12) === "qt " ? "video/quicktime" : "video/mp4";
255
- if (U(t, [26, 69, 223, 163])) return "video/webm";
256
- }
257
- function Me(e) {
256
+ if (N(t, [255, 216, 255])) return "image/jpeg";
257
+ if (C(t, 0, "GIF87a") || C(t, 0, "GIF89a")) return "image/gif";
258
+ if (C(t, 0, "RIFF") && C(t, 8, "WEBP")) return "image/webp";
259
+ if (C(t, 4, "ftyp"))
260
+ return de(t, 8, 12) === "qt " ? "video/quicktime" : "video/mp4";
261
+ if (N(t, [26, 69, 223, 163])) return "video/webm";
262
+ }
263
+ function Ve(e) {
258
264
  if (typeof e != "string" || e.length === 0)
259
265
  return { error: "data is required", code: "ERR_INVALID_ARGS" };
260
266
  const t = /^data:([^;,]+);base64,(.*)$/s.exec(e);
261
267
  if (!t)
262
268
  return { error: "only base64 data: URI is accepted", code: "ERR_INVALID_ARGS" };
263
- const n = t[1].toLowerCase(), r = Ce[n];
269
+ const n = t[1].toLowerCase(), r = Ge[n];
264
270
  if (!r)
265
271
  return { error: `unsupported mime "${n}"`, code: "ERR_UNSUPPORTED_MIME" };
266
272
  let i;
@@ -270,50 +276,50 @@ function Me(e) {
270
276
  return { error: "invalid base64 data", code: "ERR_INVALID_ARGS" };
271
277
  }
272
278
  const s = new Uint8Array(i.length);
273
- for (let a = 0; a < i.length; a++) s[a] = i.charCodeAt(a);
279
+ for (let o = 0; o < i.length; o++) s[o] = i.charCodeAt(o);
274
280
  return { bytes: s.buffer, mime: n, ext: r };
275
281
  }
276
- function U(e, t) {
282
+ function N(e, t) {
277
283
  return t.every((n, r) => e[r] === n);
278
284
  }
279
- function x(e, t, n) {
280
- return ee(e, t, t + n.length) === n;
285
+ function C(e, t, n) {
286
+ return de(e, t, t + n.length) === n;
281
287
  }
282
- function ee(e, t, n) {
288
+ function de(e, t, n) {
283
289
  if (e.length < n) return "";
284
290
  let r = "";
285
291
  for (let i = t; i < n; i++) r += String.fromCharCode(e[i]);
286
292
  return r;
287
293
  }
288
- const Fe = "miniapp-simulator-fs", Ue = 1, p = "files";
289
- let _ = null;
290
- function R() {
291
- return _ || (_ = new Promise((e, t) => {
292
- const n = indexedDB.open(Fe, Ue);
294
+ const qe = "miniapp-simulator-fs", Ye = 1, g = "files";
295
+ let D = null;
296
+ function A() {
297
+ return D || (D = new Promise((e, t) => {
298
+ const n = indexedDB.open(qe, Ye);
293
299
  n.onupgradeneeded = () => {
294
300
  const r = n.result;
295
- if (!r.objectStoreNames.contains(p)) {
296
- const i = r.createObjectStore(p, { keyPath: ["scope", "path"] });
301
+ if (!r.objectStoreNames.contains(g)) {
302
+ const i = r.createObjectStore(g, { keyPath: ["scope", "path"] });
297
303
  i.createIndex("by_scope", "scope", { unique: !1 }), i.createIndex("by_createdAt", "createdAt", { unique: !1 });
298
304
  }
299
305
  }, n.onsuccess = () => e(n.result), n.onerror = () => {
300
- _ = null, t(n.error ?? new Error("indexedDB open failed"));
306
+ D = null, t(n.error ?? new Error("indexedDB open failed"));
301
307
  }, n.onblocked = () => {
302
- _ = null, t(new Error("indexedDB open blocked"));
308
+ D = null, t(new Error("indexedDB open blocked"));
303
309
  };
304
- }), _);
310
+ }), D);
305
311
  }
306
- function te(e) {
312
+ function he(e) {
307
313
  return new Promise((t, n) => {
308
314
  e.onsuccess = () => t(e.result), e.onerror = () => n(e.error ?? new Error("indexedDB request failed"));
309
315
  });
310
316
  }
311
- function T(e) {
317
+ function M(e) {
312
318
  return new Promise((t, n) => {
313
319
  e.oncomplete = () => t(), e.onerror = () => n(e.error ?? new Error("indexedDB transaction failed")), e.onabort = () => n(e.error ?? new Error("indexedDB transaction aborted"));
314
320
  });
315
321
  }
316
- function N(e, t, n, r, i) {
322
+ function X(e, t, n, r, i) {
317
323
  const s = Date.now();
318
324
  return {
319
325
  scope: e,
@@ -325,16 +331,16 @@ function N(e, t, n, r, i) {
325
331
  lastModified: s
326
332
  };
327
333
  }
328
- async function ne(e, t, n, r = "application/octet-stream") {
329
- const s = (await R()).transaction(p, "readwrite");
330
- s.objectStore(p).put(N(e, t, n, r, !1)), await T(s);
334
+ async function pe(e, t, n, r = "application/octet-stream") {
335
+ const s = (await A()).transaction(g, "readwrite");
336
+ s.objectStore(g).put(X(e, t, n, r, !1)), await M(s);
331
337
  }
332
- async function A(e, t) {
333
- const r = (await R()).transaction(p, "readwrite");
334
- r.objectStore(p).put(N(e, t, new ArrayBuffer(0), "application/x-directory", !0)), await T(r);
338
+ async function j(e, t) {
339
+ const r = (await A()).transaction(g, "readwrite");
340
+ r.objectStore(g).put(X(e, t, new ArrayBuffer(0), "application/x-directory", !0)), await M(r);
335
341
  }
336
- async function S(e, t) {
337
- const r = (await R()).transaction(p, "readonly").objectStore(p), i = await te(r.get([e, t]));
342
+ async function P(e, t) {
343
+ const r = (await A()).transaction(g, "readonly").objectStore(g), i = await he(r.get([e, t]));
338
344
  return i ? {
339
345
  path: i.path,
340
346
  bytes: await i.bytes.arrayBuffer(),
@@ -343,10 +349,10 @@ async function S(e, t) {
343
349
  lastModified: i.lastModified ?? i.createdAt ?? 0
344
350
  } : null;
345
351
  }
346
- async function v(e) {
347
- const t = await R();
348
- return (await te(
349
- t.transaction(p, "readonly").objectStore(p).index("by_scope").getAll(e)
352
+ async function I(e) {
353
+ const t = await A();
354
+ return (await he(
355
+ t.transaction(g, "readonly").objectStore(g).index("by_scope").getAll(e)
350
356
  )).map((r) => ({
351
357
  path: r.path,
352
358
  mime: r.mime,
@@ -355,34 +361,362 @@ async function v(e) {
355
361
  lastModified: r.lastModified ?? r.createdAt ?? 0
356
362
  }));
357
363
  }
358
- async function Ae(e, t) {
359
- const r = (await R()).transaction(p, "readwrite");
360
- r.objectStore(p).delete([e, t]), await T(r);
364
+ async function Ke(e, t) {
365
+ const r = (await A()).transaction(g, "readwrite");
366
+ r.objectStore(g).delete([e, t]), await M(r);
367
+ }
368
+ async function Xe(e, t, n, r) {
369
+ const s = (await A()).transaction(g, "readwrite"), o = s.objectStore(g);
370
+ o.put(X(e, n, r.bytes, r.mime, !1)), o.delete([e, t]), await M(s);
371
+ }
372
+ /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
373
+ function Ze(e) {
374
+ return e instanceof Uint8Array || ArrayBuffer.isView(e) && e.constructor.name === "Uint8Array";
375
+ }
376
+ function F(e, ...t) {
377
+ if (!Ze(e))
378
+ throw new Error("Uint8Array expected");
379
+ if (t.length > 0 && !t.includes(e.length))
380
+ throw new Error("Uint8Array expected of length " + t + ", got length=" + e.length);
381
+ }
382
+ function ne(e, t = !0) {
383
+ if (e.destroyed)
384
+ throw new Error("Hash instance has been destroyed");
385
+ if (t && e.finished)
386
+ throw new Error("Hash#digest() has already been called");
387
+ }
388
+ function Qe(e, t) {
389
+ F(e);
390
+ const n = t.outputLen;
391
+ if (e.length < n)
392
+ throw new Error("digestInto() expects output buffer of length at least " + n);
393
+ }
394
+ function H(...e) {
395
+ for (let t = 0; t < e.length; t++)
396
+ e[t].fill(0);
397
+ }
398
+ function $(e) {
399
+ return new DataView(e.buffer, e.byteOffset, e.byteLength);
400
+ }
401
+ function w(e, t) {
402
+ return e << 32 - t | e >>> t;
403
+ }
404
+ const Je = /* @ts-ignore */ typeof Uint8Array.from([]).toHex == "function" && typeof Uint8Array.fromHex == "function", et = /* @__PURE__ */ Array.from({ length: 256 }, (e, t) => t.toString(16).padStart(2, "0"));
405
+ function tt(e) {
406
+ if (F(e), Je)
407
+ return e.toHex();
408
+ let t = "";
409
+ for (let n = 0; n < e.length; n++)
410
+ t += et[e[n]];
411
+ return t;
412
+ }
413
+ function nt(e) {
414
+ if (typeof e != "string")
415
+ throw new Error("string expected");
416
+ return new Uint8Array(new TextEncoder().encode(e));
417
+ }
418
+ function ge(e) {
419
+ return typeof e == "string" && (e = nt(e)), F(e), e;
420
+ }
421
+ class rt {
422
+ }
423
+ function it(e) {
424
+ const t = (r) => e().update(ge(r)).digest(), n = e();
425
+ return t.outputLen = n.outputLen, t.blockLen = n.blockLen, t.create = () => e(), t;
426
+ }
427
+ function st(e, t, n, r) {
428
+ if (typeof e.setBigUint64 == "function")
429
+ return e.setBigUint64(t, n, r);
430
+ const i = BigInt(32), s = BigInt(4294967295), o = Number(n >> i & s), a = Number(n & s), c = r ? 4 : 0, f = r ? 0 : 4;
431
+ e.setUint32(t + c, o, r), e.setUint32(t + f, a, r);
432
+ }
433
+ function ot(e, t, n) {
434
+ return e & t ^ ~e & n;
435
+ }
436
+ function at(e, t, n) {
437
+ return e & t ^ e & n ^ t & n;
438
+ }
439
+ class ct extends rt {
440
+ constructor(t, n, r, i) {
441
+ super(), this.finished = !1, this.length = 0, this.pos = 0, this.destroyed = !1, this.blockLen = t, this.outputLen = n, this.padOffset = r, this.isLE = i, this.buffer = new Uint8Array(t), this.view = $(this.buffer);
442
+ }
443
+ update(t) {
444
+ ne(this), t = ge(t), F(t);
445
+ const { view: n, buffer: r, blockLen: i } = this, s = t.length;
446
+ for (let o = 0; o < s; ) {
447
+ const a = Math.min(i - this.pos, s - o);
448
+ if (a === i) {
449
+ const c = $(t);
450
+ for (; i <= s - o; o += i)
451
+ this.process(c, o);
452
+ continue;
453
+ }
454
+ r.set(t.subarray(o, o + a), this.pos), this.pos += a, o += a, this.pos === i && (this.process(n, 0), this.pos = 0);
455
+ }
456
+ return this.length += t.length, this.roundClean(), this;
457
+ }
458
+ digestInto(t) {
459
+ ne(this), Qe(t, this), this.finished = !0;
460
+ const { buffer: n, view: r, blockLen: i, isLE: s } = this;
461
+ let { pos: o } = this;
462
+ n[o++] = 128, H(this.buffer.subarray(o)), this.padOffset > i - o && (this.process(r, 0), o = 0);
463
+ for (let u = o; u < i; u++)
464
+ n[u] = 0;
465
+ st(r, i - 8, BigInt(this.length * 8), s), this.process(r, 0);
466
+ const a = $(t), c = this.outputLen;
467
+ if (c % 4)
468
+ throw new Error("_sha2: outputLen should be aligned to 32bit");
469
+ const f = c / 4, l = this.get();
470
+ if (f > l.length)
471
+ throw new Error("_sha2: outputLen bigger than state");
472
+ for (let u = 0; u < f; u++)
473
+ a.setUint32(4 * u, l[u], s);
474
+ }
475
+ digest() {
476
+ const { buffer: t, outputLen: n } = this;
477
+ this.digestInto(t);
478
+ const r = t.slice(0, n);
479
+ return this.destroy(), r;
480
+ }
481
+ _cloneInto(t) {
482
+ t || (t = new this.constructor()), t.set(...this.get());
483
+ const { blockLen: n, buffer: r, length: i, finished: s, destroyed: o, pos: a } = this;
484
+ return t.destroyed = o, t.finished = s, t.length = i, t.pos = a, i % n && t.buffer.set(r), t;
485
+ }
486
+ clone() {
487
+ return this._cloneInto();
488
+ }
489
+ }
490
+ const R = /* @__PURE__ */ Uint32Array.from([
491
+ 1779033703,
492
+ 3144134277,
493
+ 1013904242,
494
+ 2773480762,
495
+ 1359893119,
496
+ 2600822924,
497
+ 528734635,
498
+ 1541459225
499
+ ]), ft = /* @__PURE__ */ Uint32Array.from([
500
+ 1116352408,
501
+ 1899447441,
502
+ 3049323471,
503
+ 3921009573,
504
+ 961987163,
505
+ 1508970993,
506
+ 2453635748,
507
+ 2870763221,
508
+ 3624381080,
509
+ 310598401,
510
+ 607225278,
511
+ 1426881987,
512
+ 1925078388,
513
+ 2162078206,
514
+ 2614888103,
515
+ 3248222580,
516
+ 3835390401,
517
+ 4022224774,
518
+ 264347078,
519
+ 604807628,
520
+ 770255983,
521
+ 1249150122,
522
+ 1555081692,
523
+ 1996064986,
524
+ 2554220882,
525
+ 2821834349,
526
+ 2952996808,
527
+ 3210313671,
528
+ 3336571891,
529
+ 3584528711,
530
+ 113926993,
531
+ 338241895,
532
+ 666307205,
533
+ 773529912,
534
+ 1294757372,
535
+ 1396182291,
536
+ 1695183700,
537
+ 1986661051,
538
+ 2177026350,
539
+ 2456956037,
540
+ 2730485921,
541
+ 2820302411,
542
+ 3259730800,
543
+ 3345764771,
544
+ 3516065817,
545
+ 3600352804,
546
+ 4094571909,
547
+ 275423344,
548
+ 430227734,
549
+ 506948616,
550
+ 659060556,
551
+ 883997877,
552
+ 958139571,
553
+ 1322822218,
554
+ 1537002063,
555
+ 1747873779,
556
+ 1955562222,
557
+ 2024104815,
558
+ 2227730452,
559
+ 2361852424,
560
+ 2428436474,
561
+ 2756734187,
562
+ 3204031479,
563
+ 3329325298
564
+ ]), E = /* @__PURE__ */ new Uint32Array(64);
565
+ class ut extends ct {
566
+ constructor(t = 32) {
567
+ super(64, t, 8, !1), this.A = R[0] | 0, this.B = R[1] | 0, this.C = R[2] | 0, this.D = R[3] | 0, this.E = R[4] | 0, this.F = R[5] | 0, this.G = R[6] | 0, this.H = R[7] | 0;
568
+ }
569
+ get() {
570
+ const { A: t, B: n, C: r, D: i, E: s, F: o, G: a, H: c } = this;
571
+ return [t, n, r, i, s, o, a, c];
572
+ }
573
+ // prettier-ignore
574
+ set(t, n, r, i, s, o, a, c) {
575
+ this.A = t | 0, this.B = n | 0, this.C = r | 0, this.D = i | 0, this.E = s | 0, this.F = o | 0, this.G = a | 0, this.H = c | 0;
576
+ }
577
+ process(t, n) {
578
+ for (let u = 0; u < 16; u++, n += 4)
579
+ E[u] = t.getUint32(n, !1);
580
+ for (let u = 16; u < 64; u++) {
581
+ const h = E[u - 15], m = E[u - 2], _ = w(h, 7) ^ w(h, 18) ^ h >>> 3, y = w(m, 17) ^ w(m, 19) ^ m >>> 10;
582
+ E[u] = y + E[u - 7] + _ + E[u - 16] | 0;
583
+ }
584
+ let { A: r, B: i, C: s, D: o, E: a, F: c, G: f, H: l } = this;
585
+ for (let u = 0; u < 64; u++) {
586
+ const h = w(a, 6) ^ w(a, 11) ^ w(a, 25), m = l + h + ot(a, c, f) + ft[u] + E[u] | 0, y = (w(r, 2) ^ w(r, 13) ^ w(r, 22)) + at(r, i, s) | 0;
587
+ l = f, f = c, c = a, a = o + m | 0, o = s, s = i, i = r, r = m + y | 0;
588
+ }
589
+ r = r + this.A | 0, i = i + this.B | 0, s = s + this.C | 0, o = o + this.D | 0, a = a + this.E | 0, c = c + this.F | 0, f = f + this.G | 0, l = l + this.H | 0, this.set(r, i, s, o, a, c, f, l);
590
+ }
591
+ roundClean() {
592
+ H(E);
593
+ }
594
+ destroy() {
595
+ this.set(0, 0, 0, 0, 0, 0, 0, 0), H(this.buffer);
596
+ }
597
+ }
598
+ const lt = /* @__PURE__ */ it(() => new ut()), dt = lt;
599
+ async function re(e, t, n, r) {
600
+ const i = await p.clients.get(e.ownerClientId);
601
+ if (!i || !e.offloaded) throw new Error("资源会话已关闭");
602
+ n.throwIfAborted();
603
+ const { port1: s, port2: o } = new MessageChannel();
604
+ return new Promise((a, c) => {
605
+ const f = () => {
606
+ clearTimeout(u), s.close(), n.removeEventListener("abort", l);
607
+ }, l = () => {
608
+ f(), c(new Error("未取得资源地址"));
609
+ }, u = setTimeout(l, 5e3);
610
+ n.addEventListener("abort", l, { once: !0 }), s.onmessage = ({ data: h }) => {
611
+ f(), typeof h?.url == "string" ? a(h.url) : c(new Error("资源地址不可用"));
612
+ }, i.postMessage({ type: We, id: e.offloaded.id, path: t, rejectedUrl: r }, [
613
+ o
614
+ ]);
615
+ });
616
+ }
617
+ function ht(e, t) {
618
+ const n = /^bytes=(\d*)-(\d*)$/i.exec(e ?? "");
619
+ if (!n || !(n[1] || n[2])) return;
620
+ const r = n[1] ? Number(n[1]) : Math.max(0, t - Number(n[2])), i = n[1] && n[2] ? Math.min(Number(n[2]), t - 1) : t - 1;
621
+ return { start: r, end: i };
622
+ }
623
+ function pt(e, t, n) {
624
+ const r = n ? dt.create() : void 0;
625
+ let i = 0;
626
+ return e.pipeThrough(
627
+ new TransformStream({
628
+ transform(s, o) {
629
+ if (i += s.byteLength, i > t) throw new Error("资源长度超过清单");
630
+ r?.update(s), o.enqueue(s);
631
+ },
632
+ flush() {
633
+ if (i !== t || r && tt(r.digest()) !== n)
634
+ throw new Error("资源校验失败");
635
+ }
636
+ })
637
+ );
361
638
  }
362
- async function Le(e, t, n, r) {
363
- const s = (await R()).transaction(p, "readwrite"), a = s.objectStore(p);
364
- a.put(N(e, n, r.bytes, r.mime, !1)), a.delete([e, t]), await T(s);
639
+ async function gt(e, t, n, r) {
640
+ if (r.destination === "document" || r.destination === "iframe" || r.destination === "script" || r.destination === "object" || r.destination === "embed")
641
+ return new Response(null, { status: 403 });
642
+ const i = AbortSignal.any([e.offloaded.lifetime.signal, r.signal]), s = r.method === "GET" ? ht(r.headers.get("Range"), n.size) : void 0, o = () => new Response(null, { status: 416, headers: { "Content-Range": `bytes */${n.size}` } });
643
+ if (s && (s.start > s.end || s.start >= n.size)) return o();
644
+ const a = (f) => fetch(f, {
645
+ method: r.method,
646
+ credentials: "omit",
647
+ redirect: "error",
648
+ referrerPolicy: "no-referrer",
649
+ headers: s ? { Range: `bytes=${s.start}-${s.end}` } : void 0,
650
+ signal: i
651
+ });
652
+ let c;
653
+ try {
654
+ const f = await re(e, t, i);
655
+ if (c = await a(f), c.status === 403) {
656
+ await c.body?.cancel();
657
+ let y;
658
+ try {
659
+ y = await re(e, t, i, f);
660
+ } catch {
661
+ return new Response(null, { status: 403 });
662
+ }
663
+ c = await a(y);
664
+ }
665
+ if (c.status !== 200 && c.status !== 206)
666
+ return await c.body?.cancel(), c.status === 416 ? o() : new Response(null, { status: c.status });
667
+ const l = new Headers({
668
+ "Content-Type": n.mimeType,
669
+ "Accept-Ranges": "bytes",
670
+ "X-Content-Type-Options": "nosniff",
671
+ "Content-Security-Policy": "default-src 'none'; sandbox"
672
+ });
673
+ let u = n.size;
674
+ if (c.status === 206) {
675
+ const y = s && `bytes ${s.start}-${s.end}/${n.size}`;
676
+ if (!y || c.headers.get("Content-Range") !== y)
677
+ throw new Error("无效资源区间");
678
+ l.set("Content-Range", y), u = s.end - s.start + 1;
679
+ }
680
+ if (l.set("Content-Length", String(u)), r.method === "HEAD") return new Response(null, { headers: l });
681
+ if (!c.body) throw new Error("缺少资源正文");
682
+ const h = u === n.size, m = pt(c.body, u, h ? n.sha256 : void 0), _ = h && u <= 1024 * 1024 ? await new Response(m).arrayBuffer() : m;
683
+ return new Response(_, { status: c.status, headers: l });
684
+ } catch {
685
+ return c?.body && !c.body.locked && await c.body.cancel().catch(() => {
686
+ }), new Response(null, { status: 502 });
687
+ }
365
688
  }
366
- function Oe(e, t, n) {
367
- if (e.files.has(t)) return L(e, t);
689
+ function me(e, t, n) {
690
+ if (e.files.has(t)) {
691
+ const i = z(e, t);
692
+ return n.method === "HEAD" ? new Response(null, i) : i;
693
+ }
694
+ const r = e.offloaded?.resources.get(t);
695
+ if (r) return gt(e, t, r, n);
368
696
  if (e.remoteBase) {
369
- const r = new URL(t, e.remoteBase);
370
- return r.search = new URL(n.url).search, ie(r.href);
697
+ const i = new URL(t, e.remoteBase);
698
+ return i.search = new URL(n.url).search, we(i.href);
371
699
  }
372
- return L(e, t);
700
+ return z(e, t);
373
701
  }
374
- async function Be(e, t) {
702
+ async function ie(e, t) {
375
703
  try {
376
- const n = await h.clients.get(e);
704
+ const n = await p.clients.get(e);
377
705
  if (n) {
378
- const r = Q(n.url);
706
+ const r = K(n.url);
379
707
  if (r) {
380
- const i = new URL(t.url), s = b(i.pathname), a = s === null ? "" : W(s);
381
- if (a && r.files.has(a))
382
- return L(r, a);
708
+ const i = new URL(t.url);
709
+ if (r.offloaded && i.origin !== new URL(p.registration.scope).origin)
710
+ return fetch(t);
711
+ const s = S(i.pathname), o = s === null ? "" : q(s);
712
+ if (r.offloaded && o.startsWith("assets/"))
713
+ return me(r, o, t);
714
+ if (t.method === "HEAD") return fetch(t);
715
+ if (o && r.files.has(o))
716
+ return z(r, o);
383
717
  if (r.remoteBase) {
384
- const o = new URL(i.pathname + i.search, new URL(r.remoteBase).origin);
385
- return ie(o.href);
718
+ const a = new URL(i.pathname + i.search, new URL(r.remoteBase).origin);
719
+ return we(a.href);
386
720
  }
387
721
  }
388
722
  }
@@ -390,7 +724,7 @@ async function Be(e, t) {
390
724
  }
391
725
  return fetch(t);
392
726
  }
393
- function re(e, t) {
727
+ function ye(e, t) {
394
728
  return new Response(e, {
395
729
  status: 200,
396
730
  headers: {
@@ -402,7 +736,7 @@ function re(e, t) {
402
736
  }
403
737
  });
404
738
  }
405
- function L(e, t) {
739
+ function z(e, t) {
406
740
  const n = e.files.get(t);
407
741
  if (!n)
408
742
  return new Response(`Not Found: ${t}`, {
@@ -410,7 +744,7 @@ function L(e, t) {
410
744
  headers: { "Content-Type": "text/plain; charset=utf-8" }
411
745
  });
412
746
  if (n.mime.startsWith("text/html")) {
413
- const r = We(new TextDecoder("utf-8").decode(n.bytes), e.injectHead), i = {
747
+ const r = mt(new TextDecoder("utf-8").decode(n.bytes), e.injectHead), i = {
414
748
  "Content-Type": "text/html; charset=utf-8",
415
749
  "Cache-Control": "no-store",
416
750
  // 与 Runtime 文档取同一值:guest 与 Runtime 同 origin,agent cluster 归属按 origin
@@ -419,9 +753,9 @@ function L(e, t) {
419
753
  };
420
754
  return e.csp && (i["Content-Security-Policy"] = e.csp), new Response(r, { status: 200, headers: i });
421
755
  }
422
- return re(n.bytes, n.mime);
756
+ return ye(n.bytes, n.mime);
423
757
  }
424
- async function ie(e) {
758
+ async function we(e) {
425
759
  try {
426
760
  return await fetch(e, { method: "GET", credentials: "omit" });
427
761
  } catch {
@@ -431,7 +765,7 @@ async function ie(e) {
431
765
  });
432
766
  }
433
767
  }
434
- function We(e, t) {
768
+ function mt(e, t) {
435
769
  if (!t) return e;
436
770
  const n = /<head\b[^>]*>/i.exec(e);
437
771
  if (n) {
@@ -445,21 +779,21 @@ function We(e, t) {
445
779
  }
446
780
  return `<head>${t}</head>${e}`;
447
781
  }
448
- const se = 50 * 1024 * 1024, D = 2 * 1024 * 1024, O = 2 * 1024 * 1024, Ne = 200 * 1024 * 1024, je = 4, $e = 255, K = 1e3, j = /* @__PURE__ */ new Set(["tmp", "usr"]), k = /* @__PURE__ */ new Set(["usr"]), qe = /^[A-Za-z0-9._-]{1,64}$/, I = /* @__PURE__ */ new Map();
449
- let H = Promise.resolve();
450
- function C(e) {
451
- const t = H.then(e, e);
452
- return H = t.then(
782
+ const be = 50 * 1024 * 1024, L = 2 * 1024 * 1024, G = 2 * 1024 * 1024, yt = 200 * 1024 * 1024, wt = 4, bt = 255, se = 1e3, Z = /* @__PURE__ */ new Set(["tmp", "usr"]), O = /* @__PURE__ */ new Set(["usr"]), xt = /^[A-Za-z0-9._-]{1,64}$/, k = /* @__PURE__ */ new Map();
783
+ let oe = Promise.resolve();
784
+ function B(e) {
785
+ const t = oe.then(e, e);
786
+ return oe = t.then(
453
787
  () => {
454
788
  },
455
789
  () => {
456
790
  }
457
791
  ), t;
458
792
  }
459
- function ze(e) {
460
- I.delete(e);
793
+ function _t(e) {
794
+ k.delete(e);
461
795
  }
462
- async function Ge(e) {
796
+ async function Rt(e) {
463
797
  const t = (n) => ({
464
798
  type: "FS_ACK",
465
799
  op: e.op,
@@ -467,38 +801,38 @@ async function Ge(e) {
467
801
  reqId: e.reqId,
468
802
  ...n
469
803
  });
470
- if (!g.has(e.id))
804
+ if (!x.has(e.id))
471
805
  return t({ ok: !1, error: "simulator not ready", code: "ERR_NOT_MOUNTED" });
472
806
  try {
473
- const n = await Ye(e);
807
+ const n = await Et(e);
474
808
  return t(n);
475
809
  } catch {
476
810
  return t({ ok: !1, code: 50101, error: "storage io error" });
477
811
  }
478
812
  }
479
- async function Ye(e) {
813
+ async function Et(e) {
480
814
  const t = e.fsScope || e.id;
481
815
  switch (e.op) {
482
816
  case "fsWriteTempFile":
483
- return Ke(t, e);
817
+ return vt(t, e);
484
818
  case "fsSaveFile":
485
- return He(t, e);
819
+ return St(t, e);
486
820
  case "fsWriteFile":
487
- return V(t, e, !1);
821
+ return ae(t, e, !1);
488
822
  case "fsAppendFile":
489
- return V(t, e, !0);
823
+ return ae(t, e, !0);
490
824
  case "fsReadFile":
491
- return Ve(t, e);
825
+ return Dt(t, e);
492
826
  case "fsReadDir":
493
- return Xe(t, e);
827
+ return At(t, e);
494
828
  case "fsStatFile":
495
- return Ze(t, e);
829
+ return It(t, e);
496
830
  case "fsUnlink":
497
- return Qe(t, e);
831
+ return Ct(t, e);
498
832
  case "fsMkdir":
499
- return Je(t, e);
833
+ return Tt(t, e);
500
834
  case "fsGetStorageInfo":
501
- return et(t);
835
+ return Ut(t);
502
836
  default:
503
837
  return {
504
838
  ok: !1,
@@ -507,140 +841,140 @@ async function Ye(e) {
507
841
  };
508
842
  }
509
843
  }
510
- async function Ke(e, t) {
511
- const n = Me(t.data);
844
+ async function vt(e, t) {
845
+ const n = Ve(t.data);
512
846
  if ("error" in n) return { ok: !1, error: n.error, code: n.code };
513
- const r = `tmp/${de()}.${n.ext}`;
514
- return await ne(e, r, n.bytes, n.mime), { ok: !0, result: { path: r, url: he(e, r) } };
847
+ const r = `tmp/${De()}.${n.ext}`;
848
+ return await pe(e, r, n.bytes, n.mime), { ok: !0, result: { path: r, url: Ae(e, r) } };
515
849
  }
516
- async function He(e, t) {
517
- const n = m(t.tempFilePath, "tempFilePath");
850
+ async function St(e, t) {
851
+ const n = b(t.tempFilePath, "tempFilePath");
518
852
  if (n) return n;
519
853
  if (t.filePath !== void 0 && t.filePath !== null) {
520
- const s = m(t.filePath, "filePath");
854
+ const s = b(t.filePath, "filePath");
521
855
  if (s) return s;
522
856
  }
523
- const r = w(t.tempFilePath, e, /* @__PURE__ */ new Set(["tmp"]), !1);
524
- if ("code" in r) return l(r);
525
- const i = t.filePath === void 0 || t.filePath === null ? it(r.path) : w(t.filePath, e, k, !1);
526
- return "code" in i ? l(i) : C(async () => {
527
- const s = await S(e, r.path);
528
- if (!s) return l({ code: 50202, message: "file not found; reason=not_found" });
529
- if (s.isDir) return l({ code: 50205, message: "not a file" });
530
- const a = await v(e), o = q(a);
531
- if (o.has(i.path))
532
- return l({ code: 50204, message: "file already exists" });
533
- const c = ue(i.path, o);
534
- if ("code" in c) return l(c);
535
- const u = ae(t.id, a, s.bytes.byteLength, 0);
536
- return u ? l(u) : (await le(e, c.missing), await Le(e, r.path, i.path, s), ce(t.id, s.bytes.byteLength), { ok: !0, result: { savedFilePath: he(e, i.path) } });
857
+ const r = v(t.tempFilePath, e, /* @__PURE__ */ new Set(["tmp"]), !1);
858
+ if ("code" in r) return d(r);
859
+ const i = t.filePath === void 0 || t.filePath === null ? Mt(r.path) : v(t.filePath, e, O, !1);
860
+ return "code" in i ? d(i) : B(async () => {
861
+ const s = await P(e, r.path);
862
+ if (!s) return d({ code: 50202, message: "file not found; reason=not_found" });
863
+ if (s.isDir) return d({ code: 50205, message: "not a file" });
864
+ const o = await I(e), a = J(o);
865
+ if (a.has(i.path))
866
+ return d({ code: 50204, message: "file already exists" });
867
+ const c = Ee(i.path, a);
868
+ if ("code" in c) return d(c);
869
+ const f = _e(t.id, o, s.bytes.byteLength, 0);
870
+ return f ? d(f) : (await ve(e, c.missing), await Xe(e, r.path, i.path, s), Re(t.id, s.bytes.byteLength), { ok: !0, result: { savedFilePath: Ae(e, i.path) } });
537
871
  });
538
872
  }
539
- async function V(e, t, n) {
540
- const r = m(t.filePath, "filePath");
873
+ async function ae(e, t, n) {
874
+ const r = b(t.filePath, "filePath");
541
875
  if (r) return r;
542
- const i = oe(t.data, "data", !0);
876
+ const i = xe(t.data, "data", !0);
543
877
  if (i) return i;
544
- const s = m(t.encoding, "encoding");
878
+ const s = b(t.encoding, "encoding");
545
879
  if (s) return s;
546
- const a = w(t.filePath, e, k, !1);
547
- if ("code" in a) return l(a);
880
+ const o = v(t.filePath, e, O, !1);
881
+ if ("code" in o) return d(o);
548
882
  if (t.encoding !== "base64" && t.encoding !== "utf8")
549
- return l({ code: 10001, message: "invalid parameter; reason=encoding_unsupported" });
550
- const o = nt(t.data, t.encoding);
551
- return "code" in o ? l(o) : o.bytes.byteLength > D ? l({
883
+ return d({ code: 10001, message: "invalid parameter; reason=encoding_unsupported" });
884
+ const a = Lt(t.data, t.encoding);
885
+ return "code" in a ? d(a) : a.bytes.byteLength > L ? d({
552
886
  code: 50201,
553
887
  message: "storage quota exceeded; reason=single_over_limit"
554
- }) : C(async () => {
555
- const c = await v(e), u = q(c), f = await S(e, a.path);
556
- if (f?.isDir) return l({ code: 50205, message: "not a file" });
557
- const d = ue(a.path, u);
558
- if ("code" in d) return l(d);
559
- const y = n ? 0 : f?.bytes.byteLength ?? 0, z = ae(
888
+ }) : B(async () => {
889
+ const c = await I(e), f = J(c), l = await P(e, o.path);
890
+ if (l?.isDir) return d({ code: 50205, message: "not a file" });
891
+ const u = Ee(o.path, f);
892
+ if ("code" in u) return d(u);
893
+ const h = n ? 0 : l?.bytes.byteLength ?? 0, m = _e(
560
894
  t.id,
561
895
  c,
562
- o.bytes.byteLength,
563
- y
896
+ a.bytes.byteLength,
897
+ h
564
898
  );
565
- if (z) return l(z);
566
- await le(e, d.missing);
567
- let M = o.bytes;
568
- return n && f && (M = st(f.bytes, o.bytes)), await ne(e, a.path, M, at(M, t.encoding)), ce(t.id, o.bytes.byteLength), { ok: !0, result: { writtenBytes: o.bytes.byteLength } };
899
+ if (m) return d(m);
900
+ await ve(e, u.missing);
901
+ let _ = a.bytes;
902
+ return n && l && (_ = Ft(l.bytes, a.bytes)), await pe(e, o.path, _, Bt(_, t.encoding)), Re(t.id, a.bytes.byteLength), { ok: !0, result: { writtenBytes: a.bytes.byteLength } };
569
903
  });
570
904
  }
571
- async function Ve(e, t) {
572
- const n = m(t.filePath, "filePath");
905
+ async function Dt(e, t) {
906
+ const n = b(t.filePath, "filePath");
573
907
  if (n) return n;
574
- const r = m(t.encoding, "encoding");
908
+ const r = b(t.encoding, "encoding");
575
909
  if (r) return r;
576
- const i = X(t.position, "position");
910
+ const i = ce(t.position, "position");
577
911
  if (i) return i;
578
- const s = X(t.length, "length");
912
+ const s = ce(t.length, "length");
579
913
  if (s) return s;
580
- const a = w(t.filePath, e, j, !1);
581
- if ("code" in a) return l(a);
914
+ const o = v(t.filePath, e, Z, !1);
915
+ if ("code" in o) return d(o);
582
916
  if (t.encoding !== "base64" && t.encoding !== "utf8")
583
- return l({ code: 10001, message: "invalid parameter; reason=encoding_unsupported" });
584
- const o = t.position === void 0 ? 0 : t.position, c = t.length === void 0 ? O : t.length;
585
- if (!Number.isSafeInteger(o) || o < 0 || !Number.isSafeInteger(c) || c < 0 || c > O)
586
- return l({ code: 10001, message: "invalid parameter; reason=range_invalid" });
587
- const u = await S(e, a.path);
588
- if (!u) return l({ code: 50202, message: "file not found" });
589
- if (u.isDir) return l({ code: 50205, message: "not a file" });
590
- const f = Math.min(u.bytes.byteLength, o + c), d = o >= u.bytes.byteLength ? new ArrayBuffer(0) : u.bytes.slice(o, f);
591
- let y;
917
+ return d({ code: 10001, message: "invalid parameter; reason=encoding_unsupported" });
918
+ const a = t.position === void 0 ? 0 : t.position, c = t.length === void 0 ? G : t.length;
919
+ if (!Number.isSafeInteger(a) || a < 0 || !Number.isSafeInteger(c) || c < 0 || c > G)
920
+ return d({ code: 10001, message: "invalid parameter; reason=range_invalid" });
921
+ const f = await P(e, o.path);
922
+ if (!f) return d({ code: 50202, message: "file not found" });
923
+ if (f.isDir) return d({ code: 50205, message: "not a file" });
924
+ const l = Math.min(f.bytes.byteLength, a + c), u = a >= f.bytes.byteLength ? new ArrayBuffer(0) : f.bytes.slice(a, l);
925
+ let h;
592
926
  if (t.encoding === "base64")
593
- y = ot(d);
927
+ h = Ot(u);
594
928
  else
595
929
  try {
596
- y = new TextDecoder("utf-8", { fatal: !0 }).decode(d);
930
+ h = new TextDecoder("utf-8", { fatal: !0 }).decode(u);
597
931
  } catch {
598
- return l({ code: 10001, message: "invalid parameter; reason=decode_failed" });
932
+ return d({ code: 10001, message: "invalid parameter; reason=decode_failed" });
599
933
  }
600
934
  return {
601
935
  ok: !0,
602
936
  result: {
603
- data: y,
604
- bytesRead: d.byteLength,
605
- eof: o + d.byteLength >= u.bytes.byteLength
937
+ data: h,
938
+ bytesRead: u.byteLength,
939
+ eof: a + u.byteLength >= f.bytes.byteLength
606
940
  }
607
941
  };
608
942
  }
609
- async function Xe(e, t) {
610
- const n = m(t.dirPath, "dirPath");
943
+ async function At(e, t) {
944
+ const n = b(t.dirPath, "dirPath");
611
945
  if (n) return n;
612
- const r = w(t.dirPath, e, j, !0);
613
- if ("code" in r) return l(r);
614
- const i = await v(e);
946
+ const r = v(t.dirPath, e, Z, !0);
947
+ if ("code" in r) return d(r);
948
+ const i = await I(e);
615
949
  if (r.relativePath) {
616
- const o = i.find((c) => c.path === r.path);
617
- if (!o) return l({ code: 50202, message: "file not found" });
618
- if (!o.isDir) return l({ code: 50206, message: "not a directory" });
619
- }
620
- const s = `${r.path}/`, a = i.filter((o) => {
621
- if (!o.path.startsWith(s)) return !1;
622
- const c = o.path.slice(s.length);
623
- return c.length > 0 && !c.includes("/") && !E(o.path);
624
- }).sort((o, c) => o.path.localeCompare(c.path));
950
+ const a = i.find((c) => c.path === r.path);
951
+ if (!a) return d({ code: 50202, message: "file not found" });
952
+ if (!a.isDir) return d({ code: 50206, message: "not a directory" });
953
+ }
954
+ const s = `${r.path}/`, o = i.filter((a) => {
955
+ if (!a.path.startsWith(s)) return !1;
956
+ const c = a.path.slice(s.length);
957
+ return c.length > 0 && !c.includes("/") && !U(a.path);
958
+ }).sort((a, c) => a.path.localeCompare(c.path));
625
959
  return {
626
960
  ok: !0,
627
961
  result: {
628
- files: a.slice(0, K).map((o) => ({
629
- name: o.path.slice(s.length),
630
- size: o.isDir ? 0 : o.size,
631
- lastModified: o.lastModified,
632
- isDir: o.isDir
962
+ files: o.slice(0, se).map((a) => ({
963
+ name: a.path.slice(s.length),
964
+ size: a.isDir ? 0 : a.size,
965
+ lastModified: a.lastModified,
966
+ isDir: a.isDir
633
967
  })),
634
- truncated: a.length > K
968
+ truncated: o.length > se
635
969
  }
636
970
  };
637
971
  }
638
- async function Ze(e, t) {
639
- const n = m(t.filePath, "filePath");
972
+ async function It(e, t) {
973
+ const n = b(t.filePath, "filePath");
640
974
  if (n) return n;
641
- const r = w(t.filePath, e, j, !1);
642
- if ("code" in r) return l(r);
643
- const i = (await v(e)).find((s) => s.path === r.path);
975
+ const r = v(t.filePath, e, Z, !1);
976
+ if ("code" in r) return d(r);
977
+ const i = (await I(e)).find((s) => s.path === r.path);
644
978
  return i ? {
645
979
  ok: !0,
646
980
  result: {
@@ -648,100 +982,100 @@ async function Ze(e, t) {
648
982
  lastModified: i.lastModified,
649
983
  isDir: i.isDir
650
984
  }
651
- } : l({ code: 50202, message: "file not found" });
985
+ } : d({ code: 50202, message: "file not found" });
652
986
  }
653
- async function Qe(e, t) {
654
- const n = m(t.filePath, "filePath");
987
+ async function Ct(e, t) {
988
+ const n = b(t.filePath, "filePath");
655
989
  if (n) return n;
656
- const r = w(t.filePath, e, k, !1);
657
- return "code" in r ? l(r) : C(async () => {
658
- const i = await S(e, r.path);
659
- return i ? i.isDir ? l({ code: 50205, message: "not a file" }) : (await Ae(e, r.path), { ok: !0, result: {} }) : l({ code: 50202, message: "file not found" });
990
+ const r = v(t.filePath, e, O, !1);
991
+ return "code" in r ? d(r) : B(async () => {
992
+ const i = await P(e, r.path);
993
+ return i ? i.isDir ? d({ code: 50205, message: "not a file" }) : (await Ke(e, r.path), { ok: !0, result: {} }) : d({ code: 50202, message: "file not found" });
660
994
  });
661
995
  }
662
- async function Je(e, t) {
663
- const n = m(t.dirPath, "dirPath");
996
+ async function Tt(e, t) {
997
+ const n = b(t.dirPath, "dirPath");
664
998
  if (n) return n;
665
999
  if (t.recursive !== void 0 && typeof t.recursive != "boolean")
666
- return $("recursive");
667
- const r = w(t.dirPath, e, k, !1);
668
- if ("code" in r) return l(r);
1000
+ return Q("recursive");
1001
+ const r = v(t.dirPath, e, O, !1);
1002
+ if ("code" in r) return d(r);
669
1003
  const i = t.recursive === !0;
670
- return C(async () => {
671
- const s = await v(e), a = q(s), o = a.get(r.path);
672
- if (o)
673
- return o.isDir ? i ? { ok: !0, result: {} } : l({ code: 50204, message: "file already exists" }) : l({ code: 50205, message: "not a file" });
674
- const c = fe(r.path);
675
- for (const u of c) {
676
- const f = a.get(u);
677
- if (f && !f.isDir)
678
- return l({ code: 50205, message: "not a file" });
679
- if (!f && !i)
680
- return l({ code: 50202, message: "file not found" });
1004
+ return B(async () => {
1005
+ const s = await I(e), o = J(s), a = o.get(r.path);
1006
+ if (a)
1007
+ return a.isDir ? i ? { ok: !0, result: {} } : d({ code: 50204, message: "file already exists" }) : d({ code: 50205, message: "not a file" });
1008
+ const c = Se(r.path);
1009
+ for (const f of c) {
1010
+ const l = o.get(f);
1011
+ if (l && !l.isDir)
1012
+ return d({ code: 50205, message: "not a file" });
1013
+ if (!l && !i)
1014
+ return d({ code: 50202, message: "file not found" });
681
1015
  }
682
1016
  if (i)
683
- for (const u of c)
684
- a.has(u) || await A(e, u);
685
- return await A(e, r.path), { ok: !0, result: {} };
1017
+ for (const f of c)
1018
+ o.has(f) || await j(e, f);
1019
+ return await j(e, r.path), { ok: !0, result: {} };
686
1020
  });
687
1021
  }
688
- async function et(e) {
689
- const t = await v(e), n = t.filter(
690
- (i) => !i.isDir && i.path.startsWith("usr/") && !E(i.path)
1022
+ async function Ut(e) {
1023
+ const t = await I(e), n = t.filter(
1024
+ (i) => !i.isDir && i.path.startsWith("usr/") && !U(i.path)
691
1025
  ), r = t.filter(
692
- (i) => !i.isDir && i.path.startsWith("tmp/") && !E(i.path)
1026
+ (i) => !i.isDir && i.path.startsWith("tmp/") && !U(i.path)
693
1027
  );
694
1028
  return {
695
1029
  ok: !0,
696
1030
  result: {
697
- usedBytes: B(n),
698
- limitBytes: se,
1031
+ usedBytes: V(n),
1032
+ limitBytes: be,
699
1033
  fileCount: n.length,
700
- tmpUsedBytes: B(r),
701
- writeChunkMaxBytes: D,
702
- readChunkMaxBytes: O
1034
+ tmpUsedBytes: V(r),
1035
+ writeChunkMaxBytes: L,
1036
+ readChunkMaxBytes: G
703
1037
  }
704
1038
  };
705
1039
  }
706
- function m(e, t) {
707
- return oe(e, t, !1);
1040
+ function b(e, t) {
1041
+ return xe(e, t, !1);
708
1042
  }
709
- function oe(e, t, n) {
1043
+ function xe(e, t, n) {
710
1044
  if (!(typeof e == "string" && (n || e.length > 0)))
711
- return $(t);
1045
+ return Q(t);
712
1046
  }
713
- function X(e, t) {
1047
+ function ce(e, t) {
714
1048
  if (!(e === void 0 || typeof e == "number"))
715
- return $(t);
1049
+ return Q(t);
716
1050
  }
717
- function $(e) {
1051
+ function Q(e) {
718
1052
  return { ok: !1, code: 10001, error: `invalid parameter; param=${e}` };
719
1053
  }
720
- function l(e) {
1054
+ function d(e) {
721
1055
  return { ok: !1, code: e.code, error: e.message };
722
1056
  }
723
- function w(e, t, n, r) {
724
- const i = tt(e, t);
1057
+ function v(e, t, n, r) {
1058
+ const i = Pt(e, t);
725
1059
  if (i === null)
726
1060
  return { code: 50203, message: "invalid path; reason=dir_not_allowed" };
727
1061
  if (i === "__DECODE_ERROR__")
728
1062
  return { code: 50203, message: "invalid path; reason=traversal" };
729
- const s = i.indexOf("/"), o = (s === -1 ? i : i.slice(0, s)).toLowerCase(), c = s === -1 ? "" : i.slice(s + 1);
730
- if (!n.has(o) || !r && c.length === 0)
1063
+ const s = i.indexOf("/"), a = (s === -1 ? i : i.slice(0, s)).toLowerCase(), c = s === -1 ? "" : i.slice(s + 1);
1064
+ if (!n.has(a) || !r && c.length === 0)
731
1065
  return { code: 50203, message: "invalid path; reason=dir_not_allowed" };
732
1066
  if (i.includes("\0") || i.includes("\\") || c.split("/").includes(".."))
733
1067
  return { code: 50203, message: "invalid path; reason=traversal" };
734
- if (new TextEncoder().encode(c).byteLength > $e)
1068
+ if (new TextEncoder().encode(c).byteLength > bt)
735
1069
  return { code: 50203, message: "invalid path; reason=name_too_long" };
736
- const u = c ? c.split("/") : [];
737
- return u.length > je ? { code: 50203, message: "invalid path; reason=depth_exceeded" } : u.some((f) => f === "." || !qe.test(f)) ? { code: 50203, message: "invalid path; reason=name_invalid" } : u.some((f) => f.startsWith("__xhs")) ? { code: 50203, message: "invalid path; reason=reserved_name" } : {
738
- dir: o,
1070
+ const f = c ? c.split("/") : [];
1071
+ return f.length > wt ? { code: 50203, message: "invalid path; reason=depth_exceeded" } : f.some((l) => l === "." || !xt.test(l)) ? { code: 50203, message: "invalid path; reason=name_invalid" } : f.some((l) => l.startsWith("__xhs")) ? { code: 50203, message: "invalid path; reason=reserved_name" } : {
1072
+ dir: a,
739
1073
  relativePath: c,
740
- path: c ? `${o}/${c}` : o
1074
+ path: c ? `${a}/${c}` : a
741
1075
  };
742
1076
  }
743
- function tt(e, t) {
744
- const n = b(e);
1077
+ function Pt(e, t) {
1078
+ const n = S(e);
745
1079
  if (n === null) return "__DECODE_ERROR__";
746
1080
  const r = n.split(/[?#]/, 1)[0];
747
1081
  if (r.includes("\0") || r.includes("\\") || r.split("/").includes(".."))
@@ -750,28 +1084,28 @@ function tt(e, t) {
750
1084
  if (e.startsWith("xhsfile://"))
751
1085
  i = e.slice(10).split(/[?#]/, 1)[0];
752
1086
  else {
753
- let a;
1087
+ let o;
754
1088
  try {
755
- a = new URL(e);
1089
+ o = new URL(e);
756
1090
  } catch {
757
1091
  return null;
758
1092
  }
759
- if (a.protocol !== "http:" && a.protocol !== "https:") return null;
760
- const o = "/_xhsfile_/", c = a.pathname.indexOf(o);
1093
+ if (o.protocol !== "http:" && o.protocol !== "https:") return null;
1094
+ const a = "/_xhsfile_/", c = o.pathname.indexOf(a);
761
1095
  if (c === -1) return null;
762
- const u = a.pathname.slice(c + o.length), f = u.indexOf("/");
763
- if (f <= 0 || b(u.slice(0, f)) !== t) return null;
764
- i = u.slice(f + 1);
1096
+ const f = o.pathname.slice(c + a.length), l = f.indexOf("/");
1097
+ if (l <= 0 || S(f.slice(0, l)) !== t) return null;
1098
+ i = f.slice(l + 1);
765
1099
  }
766
- const s = b(i);
1100
+ const s = S(i);
767
1101
  return s === null ? "__DECODE_ERROR__" : s;
768
1102
  }
769
- function nt(e, t) {
1103
+ function Lt(e, t) {
770
1104
  if (t === "utf8")
771
- return e.length > D ? { code: 50201, message: "storage quota exceeded; reason=single_over_limit" } : { bytes: new TextEncoder().encode(e).buffer };
772
- if (e.length > Math.ceil(D * 4 / 3) + 4)
1105
+ return e.length > L ? { code: 50201, message: "storage quota exceeded; reason=single_over_limit" } : { bytes: new TextEncoder().encode(e).buffer };
1106
+ if (e.length > Math.ceil(L * 4 / 3) + 4)
773
1107
  return { code: 50201, message: "storage quota exceeded; reason=single_over_limit" };
774
- if (!rt(e))
1108
+ if (!kt(e))
775
1109
  return { code: 10001, message: "invalid parameter; reason=decode_failed" };
776
1110
  try {
777
1111
  const n = atob(e), r = new Uint8Array(n.length);
@@ -781,78 +1115,78 @@ function nt(e, t) {
781
1115
  return { code: 10001, message: "invalid parameter; reason=decode_failed" };
782
1116
  }
783
1117
  }
784
- function rt(e) {
1118
+ function kt(e) {
785
1119
  return e.length % 4 !== 0 ? !1 : /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(e);
786
1120
  }
787
- function ae(e, t, n, r) {
788
- if ((I.get(e) ?? 0) + n > Ne)
1121
+ function _e(e, t, n, r) {
1122
+ if ((k.get(e) ?? 0) + n > yt)
789
1123
  return { code: 50201, message: "storage quota exceeded; reason=session_limit" };
790
- if (B(
1124
+ if (V(
791
1125
  t.filter(
792
- (s) => !s.isDir && s.path.startsWith("usr/") && !E(s.path)
1126
+ (s) => !s.isDir && s.path.startsWith("usr/") && !U(s.path)
793
1127
  )
794
- ) - r + n > se)
1128
+ ) - r + n > be)
795
1129
  return { code: 50201, message: "storage quota exceeded; reason=total_over_limit" };
796
1130
  }
797
- function ce(e, t) {
798
- I.set(e, (I.get(e) ?? 0) + t);
1131
+ function Re(e, t) {
1132
+ k.set(e, (k.get(e) ?? 0) + t);
799
1133
  }
800
- function q(e) {
1134
+ function J(e) {
801
1135
  return new Map(e.map((t) => [t.path, t]));
802
1136
  }
803
- function ue(e, t) {
1137
+ function Ee(e, t) {
804
1138
  const n = [];
805
- for (const r of fe(e)) {
1139
+ for (const r of Se(e)) {
806
1140
  const i = t.get(r);
807
1141
  if (i && !i.isDir) return { code: 50205, message: "not a file" };
808
1142
  i || n.push(r);
809
1143
  }
810
1144
  return { missing: n };
811
1145
  }
812
- async function le(e, t) {
813
- for (const n of t) await A(e, n);
1146
+ async function ve(e, t) {
1147
+ for (const n of t) await j(e, n);
814
1148
  }
815
- function fe(e) {
1149
+ function Se(e) {
816
1150
  const t = e.split("/"), n = [];
817
1151
  for (let r = 2; r < t.length; r++)
818
1152
  n.push(t.slice(0, r).join("/"));
819
1153
  return n;
820
1154
  }
821
- function it(e) {
822
- const t = e.slice(e.lastIndexOf("/") + 1), n = t.lastIndexOf("."), r = n > 0 ? t.slice(n) : "", i = `${de()}${r}`;
1155
+ function Mt(e) {
1156
+ const t = e.slice(e.lastIndexOf("/") + 1), n = t.lastIndexOf("."), r = n > 0 ? t.slice(n) : "", i = `${De()}${r}`;
823
1157
  return { dir: "usr", relativePath: i, path: `usr/${i}` };
824
1158
  }
825
- function st(e, t) {
1159
+ function Ft(e, t) {
826
1160
  const n = new Uint8Array(e.byteLength + t.byteLength);
827
1161
  return n.set(new Uint8Array(e), 0), n.set(new Uint8Array(t), e.byteLength), n.buffer;
828
1162
  }
829
- function ot(e) {
1163
+ function Ot(e) {
830
1164
  const t = new Uint8Array(e), n = 32768;
831
1165
  let r = "";
832
1166
  for (let i = 0; i < t.length; i += n)
833
1167
  r += String.fromCharCode(...t.subarray(i, i + n));
834
1168
  return btoa(r);
835
1169
  }
836
- function at(e, t) {
837
- return J(e) ?? (t === "utf8" ? "text/plain; charset=utf-8" : "application/octet-stream");
1170
+ function Bt(e, t) {
1171
+ return le(e) ?? (t === "utf8" ? "text/plain; charset=utf-8" : "application/octet-stream");
838
1172
  }
839
- function B(e) {
1173
+ function V(e) {
840
1174
  return e.reduce((t, n) => t + n.size, 0);
841
1175
  }
842
- function E(e) {
1176
+ function U(e) {
843
1177
  return e.split("/").some((t) => t.startsWith("__xhs"));
844
1178
  }
845
- function de() {
1179
+ function De() {
846
1180
  if (typeof crypto < "u" && typeof crypto.randomUUID == "function")
847
1181
  return crypto.randomUUID().replace(/-/g, "");
848
1182
  let e = "";
849
1183
  for (let t = 0; t < 32; t++) e += Math.floor(Math.random() * 16).toString(16);
850
1184
  return e;
851
1185
  }
852
- function he(e, t) {
853
- return `${h.registration.scope}_xhsfile_/${encodeURIComponent(e)}/${t}`;
1186
+ function Ae(e, t) {
1187
+ return `${p.registration.scope}_xhsfile_/${encodeURIComponent(e)}/${t}`;
854
1188
  }
855
- function ct(e) {
1189
+ function Wt(e) {
856
1190
  let t;
857
1191
  try {
858
1192
  t = new URL(e).pathname;
@@ -863,15 +1197,15 @@ function ct(e) {
863
1197
  if (r === -1) return null;
864
1198
  const i = t.slice(r + n.length), s = i.indexOf("/");
865
1199
  if (s <= 0) return null;
866
- const a = b(i.slice(0, s)), o = b(i.slice(s + 1));
867
- return !a || !o || o.includes("\0") || o.includes("\\") || o.split("/").includes("..") ? null : { scope: a, path: o };
1200
+ const o = S(i.slice(0, s)), a = S(i.slice(s + 1));
1201
+ return !o || !a || a.includes("\0") || a.includes("\\") || a.split("/").includes("..") ? null : { scope: o, path: a };
868
1202
  }
869
- async function ut(e, t) {
1203
+ async function Nt(e, t) {
870
1204
  try {
871
- const n = await S(e, t);
872
- if (n && !n.isDir && !E(t)) {
873
- const r = J(n.bytes);
874
- if (r) return re(n.bytes, r);
1205
+ const n = await P(e, t);
1206
+ if (n && !n.isDir && !U(t)) {
1207
+ const r = le(n.bytes);
1208
+ if (r) return ye(n.bytes, r);
875
1209
  }
876
1210
  } catch {
877
1211
  }
@@ -880,25 +1214,25 @@ async function ut(e, t) {
880
1214
  headers: { "Content-Type": "text/plain; charset=utf-8" }
881
1215
  });
882
1216
  }
883
- h.addEventListener("install", () => {
884
- h.skipWaiting();
1217
+ p.addEventListener("install", () => {
1218
+ p.skipWaiting();
885
1219
  });
886
- h.addEventListener("activate", (e) => {
887
- e.waitUntil(h.clients.claim());
1220
+ p.addEventListener("activate", (e) => {
1221
+ e.waitUntil(p.clients.claim());
888
1222
  });
889
- h.addEventListener("message", (e) => {
1223
+ p.addEventListener("message", (e) => {
890
1224
  const t = e.data;
891
1225
  if (!t || typeof t.type != "string") return;
892
1226
  const n = (r) => e.ports?.[0]?.postMessage(r);
893
1227
  if (t.type === "MOUNT") {
894
- const r = lt(t, ft(e.source)).then(
1228
+ const r = $t(t, jt(e.source)).then(
895
1229
  (i) => n({
896
1230
  type: "MOUNT_ACK",
897
1231
  id: t.id,
898
1232
  ok: !0,
899
1233
  count: i,
900
- swVersion: Se,
901
- fsOps: De
1234
+ swVersion: Be,
1235
+ fsOps: $e
902
1236
  }),
903
1237
  (i) => {
904
1238
  const s = i;
@@ -915,7 +1249,7 @@ h.addEventListener("message", (e) => {
915
1249
  return;
916
1250
  }
917
1251
  if (t.type === "FS") {
918
- const r = t, i = Ge(r).then(
1252
+ const r = t, i = Rt(r).then(
919
1253
  n,
920
1254
  (s) => (
921
1255
  // handleFsOp 内部已对已知错误 resolve 出准确 code;走到这里只可能是未预期的运行时异常,
@@ -934,37 +1268,53 @@ h.addEventListener("message", (e) => {
934
1268
  e.waitUntil?.(i);
935
1269
  return;
936
1270
  }
937
- t.type === "UNMOUNT" && (ze(t.id), xe(t.id));
1271
+ t.type === "UNMOUNT" && (_t(t.id), Y(t.id));
938
1272
  });
939
- h.addEventListener("fetch", (e) => {
1273
+ p.addEventListener("fetch", (e) => {
940
1274
  if (e.request.destination === "worker" || e.request.destination === "sharedworker") {
941
- e.respondWith(ke(e.request, e.clientId));
1275
+ e.respondWith(ze(e.request, e.clientId));
1276
+ return;
1277
+ }
1278
+ if (e.request.method === "HEAD") {
1279
+ const i = T(e.request.url);
1280
+ i?.app.offloaded ? e.respondWith(fe(i, e.request, e.clientId)) : !i && e.clientId && e.respondWith(ie(e.clientId, e.request));
942
1281
  return;
943
1282
  }
944
1283
  if (e.request.method !== "GET") return;
945
- const t = ct(e.request.url);
1284
+ const t = Wt(e.request.url);
946
1285
  if (t) {
947
- e.respondWith(ut(t.scope, t.path));
1286
+ e.respondWith(Nt(t.scope, t.path));
948
1287
  return;
949
1288
  }
950
- const n = P(e.request.url);
1289
+ const n = T(e.request.url);
951
1290
  if (n) {
952
- e.respondWith(Oe(n.app, n.filePath, e.request));
1291
+ e.respondWith(fe(n, e.request, e.clientId));
953
1292
  return;
954
1293
  }
955
1294
  const r = e.clientId || e.resultingClientId;
956
- r && e.respondWith(Be(r, e.request));
1295
+ r && e.respondWith(ie(r, e.request));
957
1296
  });
958
- async function lt(e, t) {
1297
+ async function fe(e, t, n) {
1298
+ const { app: r, filePath: i } = e;
1299
+ if (r.offloaded && new URL(t.url).origin !== new URL(p.registration.scope).origin)
1300
+ return fetch(t);
1301
+ if (r.offloaded?.resources.has(i) && !r.files.has(i)) {
1302
+ const s = n && await p.clients.get(n);
1303
+ if (!s || K(s.url) !== r)
1304
+ return new Response(null, { status: 403 });
1305
+ }
1306
+ return me(r, i, t);
1307
+ }
1308
+ async function $t(e, t) {
959
1309
  if (t)
960
1310
  try {
961
- const n = await h.clients.matchAll({ type: "window", includeUncontrolled: !0 });
962
- Ee(new Set(n.map((r) => r.id)));
1311
+ const n = await p.clients.matchAll({ type: "window", includeUncontrolled: !0 });
1312
+ Oe(new Set(n.map((r) => r.id)));
963
1313
  } catch {
964
1314
  }
965
- return ve({ ...e, ownerClientId: t });
1315
+ return Fe({ ...e, ownerClientId: t });
966
1316
  }
967
- function ft(e) {
1317
+ function jt(e) {
968
1318
  if (!e || typeof e != "object" || !("id" in e)) return "";
969
1319
  const t = e.id;
970
1320
  return typeof t == "string" ? t : "";